Repository navigation
Expand file tree
/
Copy pathroute.ts
More file actions
45 lines (36 loc) · 1.46 KB
/
Copy pathroute.ts
File metadata and controls
45 lines (36 loc) · 1.46 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
import {
CopilotRuntime,
ExperimentalEmptyAdapter,
copilotRuntimeNextJSAppRouterEndpoint,
} from "@copilotkit/runtime";
import { BuiltInAgent } from "@copilotkit/runtime/v2";
import { NextRequest } from "next/server";
// Use GPT-4 to avoid Anthropic API key issues (stable model)
const OPENROUTER_MODEL = "openai/gpt-4o";
// Create the agent - Frontend Tools are registered automatically from useFrontendTool
const agent = new BuiltInAgent({
model: OPENROUTER_MODEL,
prompt: `You are a helpful assistant with access to INTERACTIVE UI TOOLS.
CRITICAL: You MUST use tools to show visual information. NEVER just describe what would be shown.
INSTRUCTIONS:
- When user asks to "show", "display", or "see" workflows → Call get-workflow-status tool
- When user asks "what's running" or "status" → Call get-workflow-status tool
- ALWAYS prefer calling tools over text descriptions
- The tools will render beautiful interactive UI components automatically
Be concise in your text responses. Let the UI tools do the heavy lifting for visualization.`,
});
const serviceAdapter = new ExperimentalEmptyAdapter();
const runtime = new CopilotRuntime({
agents: {
default: agent,
// eslint-disable-next-line @typescript-eslint/no-explicit-any
} as any,
});
export const POST = async (req: NextRequest) => {
const { handleRequest } = copilotRuntimeNextJSAppRouterEndpoint({
runtime,
serviceAdapter,
endpoint: "/api/copilotkit",
});
return handleRequest(req);
};