chore: import upstream snapshot with attribution

This commit is contained in:
wehub-resource-sync
2026-07-13 12:58:18 +08:00
commit 6d5d58c1a9
18293 changed files with 3502153 additions and 0 deletions
+50
View File
@@ -0,0 +1,50 @@
# Angular Demo Server
Minimal Hono server for the Angular CopilotKit demo, matching the React demo behavior.
## Setup
1. Add your OpenAI API key to `.env`:
```
OPENAI_API_KEY=sk-...
```
2. Install dependencies (from repository root):
```bash
pnpm install
```
3. Start the server:
```bash
pnpm --filter @copilotkit/angular-demo-server dev
```
The server will be available at http://localhost:3001/api/copilotkit
## Testing
To verify the server is running:
```bash
curl http://localhost:3001/api/copilotkit/info
```
You should see JSON with agents and version information.
## Using with Angular Storybook
1. Start the demo server (Terminal A):
```bash
pnpm --filter @copilotkit/angular-demo-server dev
```
2. Start Angular Storybook (Terminal B):
```bash
pnpm --filter storybook-angular dev
```
3. Open http://localhost:6007 and navigate to "Live/CopilotChat"
@@ -0,0 +1,24 @@
{
"name": "@copilotkit/angular-demo-server",
"version": "0.0.0",
"private": true,
"type": "module",
"scripts": {
"build": "tsc -p tsconfig.json",
"dev": "tsx --env-file-if-exists ../demo/.env --env-file-if-exists .env src/index.ts",
"start": "tsx --env-file-if-exists ../demo/.env --env-file-if-exists .env src/index.ts"
},
"dependencies": {
"@ag-ui/langgraph": "^0.0.11",
"@ai-sdk/openai": "3.0.36",
"@copilotkit/demo-agents": "workspace:^",
"@copilotkit/runtime": "workspace:^",
"@hono/node-server": "^1.13.6",
"hono": "^4.11.4"
},
"devDependencies": {
"nodemon": "^3.1.7",
"tsx": "^4.19.2",
"typescript": "^5.6.3"
}
}
@@ -0,0 +1,144 @@
import { serve } from "@hono/node-server";
import { Hono } from "hono";
import { cors } from "hono/cors";
import {
BuiltInAgent,
CopilotRuntime,
createCopilotEndpoint,
InMemoryAgentRunner,
} from "@copilotkit/runtime/v2";
import type { BuiltInAgentClassicConfig } from "@copilotkit/runtime/v2";
import { createOpenAI } from "@ai-sdk/openai";
import { SlowToolCallStreamingAgent } from "@copilotkit/demo-agents";
const openRouterApiKey = process.env.OPENROUTER_API_KEY?.trim();
const openAIApiKey = process.env.OPENAI_API_KEY?.trim();
const OPENROUTER_BASE_URL = "https://openrouter.ai/api/v1";
const DEFAULT_OPENROUTER_MODEL = "anthropic/claude-sonnet-4.6";
const DEFAULT_OPENROUTER_MAX_OUTPUT_TOKENS = 16_384;
function determineOpenRouterModelId(): string {
const configuredModel = process.env.OPENROUTER_MODEL?.trim();
if (!configuredModel) {
return DEFAULT_OPENROUTER_MODEL;
}
if (configuredModel.includes("/")) {
return configuredModel;
}
return `openai/${configuredModel}`;
}
function determineMaxOutputTokens(): number | undefined {
if (!openRouterApiKey) {
return undefined;
}
const configuredLimit = Number(
process.env.OPENROUTER_MAX_OUTPUT_TOKENS?.trim(),
);
if (Number.isSafeInteger(configuredLimit) && configuredLimit > 0) {
return configuredLimit;
}
return DEFAULT_OPENROUTER_MAX_OUTPUT_TOKENS;
}
function determineModel(): BuiltInAgentClassicConfig["model"] {
if (openRouterApiKey) {
const openrouter = createOpenAI({
apiKey: openRouterApiKey,
baseURL: process.env.OPENROUTER_BASE_URL?.trim() || OPENROUTER_BASE_URL,
});
return openrouter(determineOpenRouterModelId());
}
if (openAIApiKey) {
return "openai/gpt-5.2";
}
if (process.env.ANTHROPIC_API_KEY?.trim()) {
return "anthropic/claude-3-7-sonnet-20250219";
}
if (process.env.GOOGLE_API_KEY?.trim()) {
return "google/gemini-2.5-pro";
}
return "openai/gpt-5.2";
}
const builtInAgent = new BuiltInAgent({
model: determineModel(),
maxOutputTokens: determineMaxOutputTokens(),
prompt:
"You are a helpful AI assistant. Use reasoning to answer the user's question. If you don't know the answer, say you don't know.",
providerOptions: {
...(openAIApiKey
? { openai: { reasoningEffort: "high", reasoningSummary: "detailed" } }
: {}),
...(!openAIApiKey &&
!openRouterApiKey &&
!!process.env.ANTHROPIC_API_KEY?.trim() && {
anthropic: { thinking: { type: "enabled", budgetTokens: 5000 } },
}),
},
});
const agents = {
default: builtInAgent,
"slow-tools": new SlowToolCallStreamingAgent(),
};
const runtime = new CopilotRuntime({
agents,
runner: new InMemoryAgentRunner(),
a2ui: {},
openGenerativeUI: true,
});
// 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",
"x-copilotcloud-public-api-key",
],
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);
const server = serve({ fetch: app.fetch, port });
server.on("error", (error: NodeJS.ErrnoException) => {
if (error.code === "EADDRINUSE") {
console.error(
`Port ${port} is already in use. Stop the existing process or set PORT to another value.`,
);
process.exit(1);
}
throw error;
});
console.log(
`CopilotKit runtime listening at http://localhost:${port}/api/copilotkit`,
);
@@ -0,0 +1,14 @@
{
"compilerOptions": {
"target": "ES2022",
"module": "NodeNext",
"moduleResolution": "NodeNext",
"strict": true,
"esModuleInterop": true,
"skipLibCheck": true,
"forceConsistentCasingInFileNames": true,
"resolveJsonModule": true,
"outDir": "dist"
},
"include": ["src"]
}