This repository has been archived by the owner on Mar 5, 2024. It is now read-only.
generated from t3-oss/create-t3-turbo
-
-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
50 changed files
with
4,581 additions
and
533 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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, | ||
}); | ||
} |
45 changes: 45 additions & 0 deletions
45
apps/nextjs/src/app/api/ap/v1/agent/tasks/[taskId]/artifacts/[artifactId]/route.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 }); | ||
} |
Oops, something went wrong.