forked from CopilotKit/CopilotKit
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathroute.ts
More file actions
54 lines (49 loc) · 2.03 KB
/
Copy pathroute.ts
File metadata and controls
54 lines (49 loc) · 2.03 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
// Dedicated runtime for the Multimodal Attachments demo.
//
// Why its own route? The backing MS Agent Framework agent (mounted at
// `/multimodal` on the Python agent server) runs a vision-capable model
// (gpt-4o-mini). Every other cell in this showcase uses the shared default
// agent. Registering the multimodal agent under the main `/api/copilotkit`
// runtime would mix concerns; a dedicated route keeps the vision capability
// scoped to exactly the cell that exercises it, matching the pattern used
// by the LangGraph showcase.
//
// The page at src/app/demos/multimodal/page.tsx points its `runtimeUrl` at
// this endpoint and sets `agent="multimodal-demo"` (the slug registered below).
import { NextRequest, NextResponse } from "next/server";
import {
CopilotRuntime,
ExperimentalEmptyAdapter,
copilotRuntimeNextJSAppRouterEndpoint,
} from "@copilotkit/runtime";
import { AbstractAgent, HttpAgent } from "@ag-ui/client";
const AGENT_URL = process.env.AGENT_URL || "http://localhost:8000";
function createMultimodalAgent() {
return new HttpAgent({ url: `${AGENT_URL}/multimodal` });
}
const agents: Record<string, AbstractAgent> = {
"multimodal-demo": createMultimodalAgent(),
// Alias for any internal component that calls `useAgent()` without args.
default: createMultimodalAgent(),
};
export const POST = async (req: NextRequest) => {
try {
const { handleRequest } = copilotRuntimeNextJSAppRouterEndpoint({
endpoint: "/api/copilotkit-multimodal",
serviceAdapter: new ExperimentalEmptyAdapter(),
runtime: new CopilotRuntime({
// @ts-ignore -- see main route.ts; published CopilotRuntime's `agents`
// type wraps Record in MaybePromise<NonEmptyRecord<...>> which rejects
// plain Records. Fixed in source, pending release.
agents,
}),
});
return await handleRequest(req);
} catch (error: unknown) {
const e = error as { message?: string; stack?: string };
return NextResponse.json(
{ error: e.message, stack: e.stack },
{ status: 500 },
);
}
};