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
48 lines (43 loc) · 1.67 KB
/
Copy pathroute.ts
File metadata and controls
48 lines (43 loc) · 1.67 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
// Dedicated runtime for the declarative-json-render demo.
//
// The demo page (`src/app/demos/declarative-json-render/page.tsx`) swaps
// in `JsonRenderAssistantMessage` and renders an agent-emitted JSON spec
// via `@json-render/react` against a Zod-validated catalog (MetricCard,
// BarChart, PieChart). The MS Agent behind this endpoint (see
// `src/agents/byoc_json_render_agent.py`, mounted at `/byoc-json-render`
// in `agent_server.py`) emits that JSON envelope. The legacy
// `byoc_json_render` Python module name is retained (matches LGP's
// convention); only the slug, route, and frontend folder use the
// `declarative-` prefix.
import type { NextRequest } from "next/server";
import { NextResponse } from "next/server";
import {
CopilotRuntime,
ExperimentalEmptyAdapter,
copilotRuntimeNextJSAppRouterEndpoint,
} from "@copilotkit/runtime";
import { HttpAgent } from "@ag-ui/client";
const AGENT_URL = process.env.AGENT_URL || "http://localhost:8000";
const declarativeJsonRenderAgent = new HttpAgent({
url: `${AGENT_URL}/byoc-json-render`,
});
const runtime = new CopilotRuntime({
// @ts-ignore -- see hashbrown route
agents: { byoc_json_render: declarativeJsonRenderAgent },
});
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 },
);
}
};