Skip to content

Commit aea096f

Browse files
committed
add node server example and CORS header
1 parent 64a8c17 commit aea096f

File tree

3 files changed

+65
-0
lines changed

3 files changed

+65
-0
lines changed

apps/node/package.json

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
{
2+
"name": "@apps/node",
3+
"version": "0.0.1",
4+
"private": true,
5+
"scripts": {
6+
"dev": "tsx watch src/index.ts",
7+
"build": "tsc",
8+
"start": "node dist/index.js",
9+
"check-types": "tsc --noEmit"
10+
},
11+
"devDependencies": {
12+
"@types/node": "^22.10.7",
13+
"tsx": "^4.19.2",
14+
"typescript": "^5.8.2"
15+
},
16+
"dependencies": {
17+
"@copilotkitnext/agent": "workspace:^",
18+
"@copilotkitnext/runtime": "workspace:^",
19+
"@hono/node-server": "^1.13.6"
20+
}
21+
}

apps/node/src/index.ts

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
import { CopilotRuntime, createCopilotEndpoint, VERSION } from "@copilotkitnext/runtime";
2+
import { BasicAgent } from "@copilotkitnext/agent";
3+
import { serve } from "@hono/node-server";
4+
5+
// Example: Creating a runtime instance
6+
// Note: BasicAgent is used here to verify the import works
7+
// In practice, agents would be passed with proper AbstractAgent interface
8+
const runtime = new CopilotRuntime({
9+
agents: {
10+
default: new BasicAgent({
11+
model: "openai/gpt-4o-mini",
12+
maxSteps: 5,
13+
temperature: 0.7,
14+
}),
15+
},
16+
});
17+
18+
const endpoint = createCopilotEndpoint({ basePath: "/api/copilotkit", runtime });
19+
20+
serve({
21+
fetch: endpoint.fetch,
22+
port: 8787,
23+
});

apps/node/tsconfig.json

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
{
2+
"extends": "@copilotkitnext/typescript-config/base.json",
3+
"compilerOptions": {
4+
"rootDir": "src",
5+
"outDir": "dist",
6+
"module": "commonjs",
7+
"target": "ES2022",
8+
"lib": ["ES2022"],
9+
"esModuleInterop": true,
10+
"forceConsistentCasingInFileNames": true,
11+
"strict": true,
12+
"skipLibCheck": true,
13+
"moduleResolution": "node",
14+
"resolveJsonModule": true,
15+
"declaration": true,
16+
"declarationMap": true,
17+
"sourceMap": true
18+
},
19+
"include": ["src/**/*"],
20+
"exclude": ["node_modules", "dist"]
21+
}

0 commit comments

Comments
 (0)