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
52 lines (47 loc) · 1.82 KB
/
Copy pathroute.ts
File metadata and controls
52 lines (47 loc) · 1.82 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
/**
* Dedicated runtime for the declarative-json-render demo.
*
* Splitting into its own endpoint (mirroring beautiful-chat +
* declarative-gen-ui) keeps the `byoc_json_render` graph isolated from
* the default multi-agent `/api/copilotkit` runtime. The frontend's
* demo page (src/app/demos/declarative-json-render/page.tsx) points
* `<CopilotKit runtimeUrl>` here. The Python module + langgraph graph
* ID retain the legacy `byoc_json_render` name; only the user-facing
* slug, route, and frontend folder were renamed.
*/
import { NextRequest, NextResponse } from "next/server";
import {
CopilotRuntime,
ExperimentalEmptyAdapter,
copilotRuntimeNextJSAppRouterEndpoint,
} from "@copilotkit/runtime";
import { LangGraphAgent } from "@copilotkit/runtime/langgraph";
const LANGGRAPH_URL =
process.env.LANGGRAPH_DEPLOYMENT_URL || "http://localhost:8123";
const byocJsonRenderAgent = new LangGraphAgent({
deploymentUrl: LANGGRAPH_URL,
graphId: "byoc_json_render",
langsmithApiKey: process.env.LANGSMITH_API_KEY || "",
});
const runtime = new CopilotRuntime({
// @ts-ignore -- same-shape mismatch as the other dedicated routes in this
// package; the LangGraphAgent satisfies the runtime's agent interface at
// runtime but the generics don't line up across the v1/v2 boundary.
agents: { byoc_json_render: byocJsonRenderAgent },
});
export const POST = async (req: NextRequest) => {
try {
const { handleRequest } = copilotRuntimeNextJSAppRouterEndpoint({
endpoint: "/api/copilotkit-declarative-json-render",
serviceAdapter: new ExperimentalEmptyAdapter(),
runtime,
});
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 },
);
}
};