forked from CopilotKit/CopilotKit
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.ts
More file actions
56 lines (47 loc) · 1.49 KB
/
Copy pathindex.ts
File metadata and controls
56 lines (47 loc) · 1.49 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
53
54
55
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`);
});