Skip to content
This repository has been archived by the owner on Mar 5, 2024. It is now read-only.

Commit

Permalink
Merge branch 'agent-protocol'
Browse files Browse the repository at this point in the history
  • Loading branch information
jondwillis committed Nov 2, 2023
2 parents 87812af + 2d46f52 commit 5b22e62
Show file tree
Hide file tree
Showing 50 changed files with 4,581 additions and 533 deletions.
6 changes: 5 additions & 1 deletion .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -109,4 +109,8 @@ POSTGRES_URL_NON_POOLING=
# # see: https://js.langchain.com/docs/guides/evaluation/trajectory/
# # may be a value from 0 to 1, to set the minimum evaluation score, or false
# # defaults to false
# EXE_TRAJECTORY_EVALUATION=false
# EXE_TRAJECTORY_EVALUATION=false

# # Required: upload Artifacts to blob storage
# see: https://vercel.com/docs/storage/vercel-blob
BLOB_READ_WRITE_TOKEN=
1,967 changes: 1,967 additions & 0 deletions apps/nextjs/lib/AgentProtocol/openapi.json

Large diffs are not rendered by default.

187 changes: 187 additions & 0 deletions apps/nextjs/lib/AgentProtocol/types.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,187 @@
/**
* Input parameters for the task. Any value is allowed.
*/

import { type JsonValue } from "~/features/WaggleDance/types/types";

export type TaskInput = JsonValue;
/**
* Artifact that the task has produced. Any value is allowed.
*/
export type Artifact = {
artifact_id: string;
agent_created: boolean;
file_name: string;
relative_path: string | null;
created_at: string;
};
/**
* Input parameters for the task step. Any value is allowed.
*/

export type StepInput = JsonValue;
/**
* Output that the task step has produced. Any value is allowed.
*/

export type StepOutput = JsonValue;
export declare enum StepStatus {
CREATED = "created",
RUNNING = "running",
COMPLETED = "completed",
}
export interface Step {
/**
* The name of the task step
*/
name?: string;
/**
* Output of the task step
*/
output?: StepOutput;
/**
* A list of artifacts that the step has produced.
*/
artifacts?: Artifact[];
/**
* Whether this is the last step in the task.
*/
is_last?: boolean;
input?: StepInput;
/**
* The ID of the task this step belongs to.
*/
task_id: string;
/**
* The ID of the task step.
*/
step_id: string;
/**
* Current status of step
*/
status: StepStatus;
}
export interface StepRequestBody {
input?: StepInput;
}
export interface StepResult {
/**
* The name of the step
*/
name?: string;
/**
* Output of the step
*/
output?: StepOutput;
/**
* A list of artifacts that the step has produced.
*/
artifacts?: Artifact[];
/**
* Whether this is the last step in the task.
*/
is_last?: boolean;
}
export interface Task {
input?: TaskInput;
/**
* The ID of the task.
*/
task_id: string;
/**
* A list of artifacts that the task has produced.
*/
artifacts?: Artifact[];

additional_input?: object;
}
export interface TaskRequestBody {
input?: TaskInput;
additional_input?: object;
}

/**
* A function that handles a step in a task.
* Returns a step result.
*/

export type StepHandler = (input: StepInput | null) => Promise<StepResult>;
/**
* A function that handles a task.
* Returns a step handler.
*/
export type TaskHandler = (
taskId: string,

input: TaskInput | null,
) => Promise<StepHandler>;
/**
* A step result with default values.
* @returns StepResult
*/
export declare class StepResultWithDefaults implements StepResult {
output?: StepOutput;
artifacts?: Artifact[];
is_last?: boolean;
}
/**
* Creates a task for the agent.
* @param body TaskRequestBody | null
* @returns Promise<Task>
*/
export declare const createAgentTask: (
body: TaskRequestBody | null,
) => Promise<Task>;
/**
* Lists all tasks that have been created for the agent.
* @returns Promise<string[]>
*/
export declare const listAgentTaskIDs: () => Promise<string[]>;
/**
* Get details about a specified agent task.
* @param taskId string
* @returns
*/
export declare const getAgentTask: (taskId: string) => Promise<Task>;
/**
* Lists all steps for the specified task.
* @param taskId string
* @returns Promise<string[]>
*/
export declare const listAgentTaskSteps: (taskId: string) => Promise<string[]>;
/**
* Execute a step in the specified agent task.
* @param taskId string
* @param body StepRequestBody | null
* @returns Promise<Step>
*/
export declare const executeAgentTaskStep: (
taskId: string,
body: StepRequestBody | null,
) => Promise<Step>;
/**
* Get details about a specified task step.
* @param taskId string
* @param stepId string
* @returns Promise<Step>
*/
export declare const getAgentTaskStep: (
taskId: string,
stepId: string,
) => Promise<Step>;
export interface AgentConfig {
port: number;
workspace: string;
}
export declare class Agent {
taskHandler: TaskHandler;
config: AgentConfig;
constructor(taskHandler: TaskHandler, config: AgentConfig);
static handleTask(
_taskHandler: TaskHandler,
config: Partial<AgentConfig>,
): Agent;
start(port?: number): void;
}

// export default Agent;
21 changes: 11 additions & 10 deletions apps/nextjs/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
"@acme/auth": "^0.1.0",
"@acme/db": "^0.1.0",
"@acme/tailwind-config": "^0.1.0",
"@aws-sdk/client-s3": "^3.435.0",
"@aws-sdk/client-s3": "^3.438.0",
"@emotion/react": "^11.11.1",
"@emotion/styled": "^11.11.0",
"@fontsource/public-sans": "^5.0.15",
Expand All @@ -29,21 +29,22 @@
"@react-hook/resize-observer": "^1.2.6",
"@t3-oss/env-nextjs": "^0.7.1",
"@tanstack/react-query": "^4.36.1",
"@trpc/client": "^10.42.0",
"@trpc/next": "^10.42.0",
"@trpc/react-query": "^10.42.0",
"@trpc/server": "^10.42.0",
"@upstash/redis": "^1.23.4",
"@trpc/client": "^10.43.0",
"@trpc/next": "^10.43.0",
"@trpc/react-query": "^10.43.0",
"@trpc/server": "^10.43.0",
"@upstash/redis": "^1.24.2",
"@vercel/analytics": "^1.1.1",
"@vercel/blob": "^0.14.1",
"@vercel/edge-config": "^0.4.1",
"crypto-js": "^4.2.0",
"eventsource-parser": "^1.1.1",
"formidable": "^3.5.1",
"jsonrepair": "^3.2.4",
"langchain": "^0.0.172",
"langchain": "^0.0.176",
"mammoth": "^1.6.0",
"next": "^13.5.6",
"next-auth": "^4.24.3",
"next": "^14.0.1",
"next-auth": "^4.24.4",
"pdf-parse": "^1.1.1",
"playwright": "^1.39.0",
"react": "18.2.0",
Expand All @@ -65,7 +66,7 @@
"@types/d3-force": "^3.0.7",
"@types/formidable": "^3.4.4",
"@types/node": "^20.8.9",
"@types/react": "^18.2.32",
"@types/react": "^18.2.33",
"@types/react-dom": "^18.2.14",
"@types/uuid": "^9.0.6",
"autoprefixer": "^10.4.16",
Expand Down
17 changes: 17 additions & 0 deletions apps/nextjs/src/app/api/ap/route.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import { type NextRequest } from "next/server";

import AgentProtocolOpenAPISpec from "~/../lib/AgentProtocol/openapi.json";

export const dynamic = "force-static";

export function GET(req: NextRequest) {
const spec = AgentProtocolOpenAPISpec;

if (spec.servers[0]) {
spec.servers[0].url = req.nextUrl.origin;
}

return Response.json(spec, {
status: 200,
});
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
import { type NextRequest } from "next/server";
import { getServerSession } from "next-auth";

import { appRouter } from "@acme/api";
import { authOptions } from "@acme/auth";
import { prisma } from "@acme/db";

/**
* @api {get} /api/v1/agent/tasks/:taskId/artifacts/:artifactId Get Artifact
* @apiDescription Download a specified artifact.
* @apiName Download Agent Task Artifact
* @param {string} task_id
* @param {string} artifact_id
*/
export async function GET(
req: NextRequest,
{
params: { taskId, artifactId },
}: { params: { taskId: string; artifactId: string } },
) {
if (!taskId) {
return Response.json("task_id is required", { status: 400 });
}
if (!artifactId) {
return Response.json("artifact_id is required", { status: 400 });
}

const session = (await getServerSession(authOptions)) || null;
const caller = appRouter.createCaller({
session,
prisma,
origin: req.nextUrl.origin,
});

const artifact = await caller.result.byExecutionIdAndArtifactId({
executionId: taskId,
artifactId,
});

if (artifact?.artifactUrls[0]) {
return Response.redirect(artifact.artifactUrls[0]);
}

return Response.json({ error: "Artifact not found" }, { status: 404 });
}
Loading

0 comments on commit 5b22e62

Please sign in to comment.