chore: import upstream snapshot with attribution
This commit is contained in:
@@ -0,0 +1,2 @@
|
||||
OPENAI_API_KEY=your-openai-api-key
|
||||
PORT=4001
|
||||
@@ -0,0 +1,19 @@
|
||||
{
|
||||
"name": "@copilotkit/example-runtime-node",
|
||||
"version": "0.0.1",
|
||||
"private": true,
|
||||
"scripts": {
|
||||
"example-dev": "tsx watch src/index.ts",
|
||||
"example-build": "tsc",
|
||||
"example-start": "node dist/index.js"
|
||||
},
|
||||
"dependencies": {
|
||||
"@copilotkit/runtime": "workspace:^"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@copilotkit/typescript-config": "workspace:^",
|
||||
"@types/node": "^22.10.7",
|
||||
"tsx": "^4.19.2",
|
||||
"typescript": "^5.8.2"
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,56 @@
|
||||
import { createServer } from "node:http";
|
||||
import {
|
||||
CopilotRuntime,
|
||||
createCopilotRuntimeHandler,
|
||||
BuiltInAgent,
|
||||
} from "@copilotkit/runtime/v2";
|
||||
import { createCopilotNodeHandler } from "@copilotkit/runtime/v2/node";
|
||||
|
||||
const runtime = new CopilotRuntime({
|
||||
agents: {
|
||||
default: new BuiltInAgent({ model: "openai/gpt-5-mini" }),
|
||||
},
|
||||
});
|
||||
|
||||
const copilotHandler = createCopilotRuntimeHandler({
|
||||
runtime,
|
||||
basePath: "/api/copilotkit",
|
||||
cors: true,
|
||||
});
|
||||
|
||||
const copilotNodeHandler = createCopilotNodeHandler(copilotHandler);
|
||||
|
||||
const server = createServer(async (req, res) => {
|
||||
const url = new URL(req.url ?? "/", `http://${req.headers.host}`);
|
||||
|
||||
// CopilotKit endpoints
|
||||
if (url.pathname.startsWith("/api/copilotkit")) {
|
||||
return copilotNodeHandler(req, res);
|
||||
}
|
||||
|
||||
// Root
|
||||
if (url.pathname === "/") {
|
||||
res.writeHead(200, { "Content-Type": "application/json" });
|
||||
res.end(
|
||||
JSON.stringify({ status: "ok", message: "CopilotKit Node runtime" }),
|
||||
);
|
||||
return;
|
||||
}
|
||||
|
||||
// Health check
|
||||
if (url.pathname === "/health") {
|
||||
res.writeHead(200, { "Content-Type": "application/json" });
|
||||
res.end(JSON.stringify({ status: "healthy" }));
|
||||
return;
|
||||
}
|
||||
|
||||
// 404
|
||||
res.writeHead(404, { "Content-Type": "application/json" });
|
||||
res.end(JSON.stringify({ error: "Not found" }));
|
||||
});
|
||||
|
||||
const port = Number(process.env.PORT ?? 4001);
|
||||
server.listen(port, () => {
|
||||
console.log(`Node runtime listening on http://localhost:${port}`);
|
||||
console.log(` CopilotKit: http://localhost:${port}/api/copilotkit`);
|
||||
});
|
||||
@@ -0,0 +1,21 @@
|
||||
{
|
||||
"extends": "@copilotkit/typescript-config/base.json",
|
||||
"compilerOptions": {
|
||||
"rootDir": "src",
|
||||
"outDir": "dist",
|
||||
"module": "es2022",
|
||||
"target": "ES2022",
|
||||
"lib": ["ES2022"],
|
||||
"esModuleInterop": true,
|
||||
"forceConsistentCasingInFileNames": true,
|
||||
"strict": true,
|
||||
"skipLibCheck": true,
|
||||
"moduleResolution": "bundler",
|
||||
"resolveJsonModule": true,
|
||||
"declaration": true,
|
||||
"declarationMap": true,
|
||||
"sourceMap": true
|
||||
},
|
||||
"include": ["src/**/*"],
|
||||
"exclude": ["node_modules", "dist"]
|
||||
}
|
||||
Reference in New Issue
Block a user