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
53 lines (47 loc) · 1.26 KB
/
Copy pathindex.ts
File metadata and controls
53 lines (47 loc) · 1.26 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
import { serve } from "@hono/node-server";
import { Hono } from "hono";
import { cors } from "hono/cors";
import {
CopilotRuntime,
createCopilotEndpoint,
InMemoryAgentRunner,
} from "@copilotkit/runtime/v2";
import {
OpenAIAgent,
SlowToolCallStreamingAgent,
} from "@copilotkit/demo-agents";
const runtime = new CopilotRuntime({
agents: {
// @ts-ignore
default: new SlowToolCallStreamingAgent(),
// @ts-ignore
openai: new OpenAIAgent(),
},
runner: new InMemoryAgentRunner(),
});
// Create a main app with CORS enabled
const app = new Hono();
// Enable CORS for local dev (Angular demo at http://localhost:4200)
app.use(
"*",
cors({
origin: "http://localhost:4200",
allowMethods: ["GET", "POST", "OPTIONS", "PUT", "DELETE"],
allowHeaders: ["Content-Type", "Authorization", "X-Requested-With"],
exposeHeaders: ["Content-Type"],
credentials: true,
maxAge: 86400,
}),
);
// Create the CopilotKit endpoint
const copilotApp = createCopilotEndpoint({
runtime,
basePath: "/api/copilotkit",
});
// Mount the CopilotKit app
app.route("/", copilotApp);
const port = Number(process.env.PORT || 3001);
serve({ fetch: app.fetch, port });
console.log(
`CopilotKit runtime listening at http://localhost:${port}/api/copilotkit`,
);