Skip to content

Commit 05b9a4d

Browse files
committed
vnext demo runnign
1 parent baa67ea commit 05b9a4d

File tree

3 files changed

+90
-60
lines changed

3 files changed

+90
-60
lines changed

apps/dojo/package.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@
3535
"@copilotkit/shared": "1.10.6",
3636
"@copilotkitnext/react": "0.0.19-alpha.0",
3737
"@copilotkitnext/runtime": "0.0.19-alpha.0",
38+
"@copilotkitnext/agent": "0.0.19-alpha.0",
3839
"@mastra/client-js": "^0.15.2",
3940
"@mastra/core": "^0.20.2",
4041
"@mastra/dynamodb": "^0.15.6",
@@ -62,6 +63,7 @@
6263
"diff": "^7.0.0",
6364
"embla-carousel-react": "^8.6.0",
6465
"fast-json-patch": "^3.1.1",
66+
"hono": "^4.10.3",
6567
"lucide-react": "^0.477.0",
6668
"markdown-it": "^14.1.0",
6769
"markdown-it-ins": "^4.0.0",

apps/dojo/src/app/api/copilotkitnext/[integrationId]/[[...slug]]/route.ts

Lines changed: 23 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -5,18 +5,28 @@ import {
55
} from "@copilotkitnext/runtime";
66
import { handle } from "hono/vercel";
77
import type { NextRequest } from "next/server";
8+
import { BasicAgent } from "@copilotkitnext/agent";
89

910
type RouteParams = {
10-
params: {
11+
params: Promise<{
1112
integrationId: string;
1213
slug?: string[];
13-
};
14+
}>;
1415
};
1516

16-
function createHandler(integrationId: string) {
17+
const handlerCache = new Map<string, ReturnType<typeof handle>>();
18+
19+
function getHandler(integrationId: string) {
20+
const cached = handlerCache.get(integrationId);
21+
if (cached) {
22+
return cached;
23+
}
24+
1725
const runtime = new CopilotRuntime({
1826
agents: {
19-
default: null as any,
27+
default: new BasicAgent({
28+
model: "openai/gpt-4o",
29+
}),
2030
},
2131
runner: new InMemoryAgentRunner(),
2232
});
@@ -26,16 +36,19 @@ function createHandler(integrationId: string) {
2636
basePath: `/api/copilotkitnext/${integrationId}`,
2737
});
2838

29-
return handle(app);
39+
const handler = handle(app);
40+
handlerCache.set(integrationId, handler);
41+
return handler;
3042
}
3143

32-
export function GET(request: NextRequest, context: RouteParams) {
33-
const handler = createHandler(context.params.integrationId);
44+
export async function GET(request: NextRequest, context: RouteParams) {
45+
const { integrationId } = await context.params;
46+
const handler = getHandler(integrationId);
3447
return handler(request);
3548
}
3649

37-
export function POST(request: NextRequest, context: RouteParams) {
38-
const handler = createHandler(context.params.integrationId);
50+
export async function POST(request: NextRequest, context: RouteParams) {
51+
const { integrationId } = await context.params;
52+
const handler = getHandler(integrationId);
3953
return handler(request);
4054
}
41-

0 commit comments

Comments
 (0)