mirror of
https://github.com/CopilotKit/CopilotKit.git
synced 2026-09-14 16:26:20 +08:00
314f1ca55d
CopilotKitIntelligence resolves apiUrl/wsUrl to the managed hosts when they are omitted, and its own docstring says leaving both unset is always correct against the managed service. Every starter's runtime route supplied `?? "http://localhost:4201"` instead, so a managed reader who copied the block got a runtime aimed at a local stack that is not running -- the failure the starter's own .env.example warns about two files away. Replace the fallbacks with the conditional spread these same starters already use in channel-host.mts, so a self-hosted override still works and the managed default applies when it is absent. Three .env.example files also set the values uncommented, two of them directly under a comment telling the reader to leave them unset; comment those out to match the other nineteen starters. Guard both shapes in validate-intelligence-env-names.ts, which already polices the canonical Intelligence key name and hosts and runs unfiltered on every PR. The rule is the pattern rather than the literal, so a staging host substituted for localhost fails the same way. Local e2e harnesses and demo stacks that genuinely target a local deployment are allowlisted with their reasons. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
57 lines
2.0 KiB
TypeScript
57 lines
2.0 KiB
TypeScript
import "dotenv/config";
|
|
import { createServer } from "node:http";
|
|
import {
|
|
CopilotRuntime,
|
|
CopilotKitIntelligence,
|
|
InMemoryAgentRunner,
|
|
} from "@copilotkit/runtime/v2";
|
|
import { createCopilotNodeListener } from "@copilotkit/runtime/v2/node";
|
|
import { HttpAgent } from "@ag-ui/client";
|
|
|
|
const runtime = new CopilotRuntime({
|
|
agents: {
|
|
default: new HttpAgent({
|
|
url: process.env.AGENT_URL || "http://localhost:8000/",
|
|
}),
|
|
},
|
|
// --- copilotkit:intelligence (remove this block to opt out) ---
|
|
...(process.env.COPILOTKIT_LICENSE_TOKEN
|
|
? {
|
|
intelligence: new CopilotKitIntelligence({
|
|
apiKey: process.env.INTELLIGENCE_API_KEY ?? "",
|
|
...(process.env.INTELLIGENCE_API_URL
|
|
? { apiUrl: process.env.INTELLIGENCE_API_URL }
|
|
: {}),
|
|
...(process.env.INTELLIGENCE_GATEWAY_WS_URL
|
|
? { wsUrl: process.env.INTELLIGENCE_GATEWAY_WS_URL }
|
|
: {}),
|
|
}),
|
|
// Demo stub — replace with your real auth-derived user identity before any
|
|
// multi-user deployment, or all users share one thread history. The id
|
|
// must correspond to a user that exists in CopilotKit Intelligence;
|
|
// an unknown id (like this literal) can make thread operations fail.
|
|
identifyUser: () => ({ id: "demo-user", name: "Demo User" }),
|
|
licenseToken: process.env.COPILOTKIT_LICENSE_TOKEN,
|
|
}
|
|
: { runner: new InMemoryAgentRunner() }),
|
|
// --- /copilotkit:intelligence ---
|
|
});
|
|
|
|
// Fixed to 8200 to match the hardcoded runtimeUrl in app.config.ts. We do NOT
|
|
// read process.env.PORT here: the Python ADK agent (launched from the same
|
|
// `npm run dev` and sharing this `.env`) reads PORT (default 8000), so binding
|
|
// the runtime to PORT too would collide the two processes on one port.
|
|
const port = 8200;
|
|
|
|
createServer(
|
|
createCopilotNodeListener({
|
|
runtime,
|
|
basePath: "/api/copilotkit",
|
|
cors: true,
|
|
}),
|
|
).listen(port, () => {
|
|
console.log(
|
|
`Copilot Runtime listening at http://localhost:${port}/api/copilotkit`,
|
|
);
|
|
});
|