mirror of
https://github.com/CopilotKit/CopilotKit.git
synced 2026-09-14 16:26:20 +08:00
3f1259d060
Fixes #2903 ## The Bug Azure OpenAI users get `AI_LoadAPIKeyError: OpenAI API key is missing` despite passing a properly configured `OpenAI` instance to `OpenAIAdapter`, exactly as shown in the docs. **Root cause**: `CopilotRuntime.handleServiceAdapter()` discards the adapter's configured OpenAI instance and constructs a plain string `"openai/gpt-4o"` to pass to `BuiltInAgent`. The agent's `resolveModel()` then creates a *brand new* OpenAI provider using only `OPENAI_API_KEY`, losing all Azure configuration (baseURL, api-key header, api-version query param). The V1 adapter's `process()` method — which correctly uses the custom OpenAI instance — is dead code. It's never called. Only `.provider` and `.model` strings are extracted. ``` User configures Azure OpenAI instance → OpenAIAdapter stores it → CopilotRuntime extracts only "openai"/"gpt-4o" strings → BuiltInAgent.resolveModel("openai/gpt-4o") → createOpenAI({ apiKey: OPENAI_API_KEY }) → 💥 API key missing / wrong endpoint ``` ## Workaround Until this is merged, users can bypass the broken adapter entirely by using `BuiltInAgent` directly with the Vercel AI SDK Azure provider: ```typescript import { createAzure } from "@ai-sdk/azure"; import { CopilotRuntime, copilotRuntimeNodeHttpEndpoint } from "@copilotkit/runtime"; import { BuiltInAgent } from "@copilotkitnext/agent"; const azure = createAzure({ resourceName: process.env.AZURE_RESOURCE_NAME, apiKey: process.env.AZURE_API_KEY, }); const runtime = new CopilotRuntime({ agents: { default: new BuiltInAgent({ model: azure("your-deployment-name"), }), }, }); // Then use copilotRuntimeNodeHttpEndpoint as usual — no serviceAdapter needed ``` This works because `BuiltInAgent` already accepts `LanguageModel` instances and `resolveModel()` passes them straight through. ## The Fix Add an optional `getLanguageModel()` method to `CopilotServiceAdapter`. Adapters that accept custom SDK instances (OpenAI, Anthropic, Groq) now implement this to produce a pre-configured Vercel AI SDK `LanguageModel` that carries the full provider configuration. `CopilotRuntime` prefers this over the string format when creating `BuiltInAgent`. **Backward compatible**: `getLanguageModel()` is optional on the interface, so existing custom adapters continue to work unchanged. | File | Change | |------|--------| | `service-adapter.ts` | Add optional `getLanguageModel()` to `CopilotServiceAdapter` interface | | `openai-adapter.ts` | Implement `getLanguageModel()` using `createOpenAI` with the configured instance's `baseURL`/`apiKey` | | `anthropic-adapter.ts` | Implement `getLanguageModel()` using `createAnthropic` | | `groq-adapter.ts` | Implement `getLanguageModel()` using `createOpenAI` (Groq is OpenAI-compatible) | | `copilot-runtime.ts` | Prefer `serviceAdapter.getLanguageModel()` over string model when creating `BuiltInAgent` | | `package.json` | Add `ai`, `@ai-sdk/openai`, `@ai-sdk/anthropic` dependencies | ## Test plan - [x] V2 agent tests pass (101/101) - [x] V1 runtime build succeeds with no type errors - [x] V1 runtime tests: same pass/fail as `main` (pre-existing failures unrelated to this change) - [ ] Manual: configure Azure OpenAI via `OpenAIAdapter` without `OPENAI_API_KEY` — should work without `AI_LoadAPIKeyError` - [ ] Manual: standard OpenAI via `OpenAIAdapter` with `OPENAI_API_KEY` — should continue working 🤖 Generated with [Claude Code](https://claude.com/claude-code)
144 lines
3.5 KiB
JSON
144 lines
3.5 KiB
JSON
{
|
|
"name": "@copilotkit/runtime",
|
|
"private": false,
|
|
"homepage": "https://github.com/CopilotKit/CopilotKit",
|
|
"repository": {
|
|
"type": "git",
|
|
"url": "https://github.com/CopilotKit/CopilotKit.git"
|
|
},
|
|
"publishConfig": {
|
|
"access": "public"
|
|
},
|
|
"version": "1.52.0",
|
|
"sideEffects": [
|
|
"./dist/index.mjs",
|
|
"./dist/index.cjs",
|
|
"./dist/v2/index.mjs",
|
|
"./dist/v2/index.cjs"
|
|
],
|
|
"main": "./dist/index.cjs",
|
|
"module": "./dist/index.mjs",
|
|
"exports": {
|
|
".": {
|
|
"import": "./dist/index.mjs",
|
|
"require": "./dist/index.cjs"
|
|
},
|
|
"./langgraph": {
|
|
"import": "./dist/langgraph.mjs",
|
|
"require": "./dist/langgraph.cjs"
|
|
},
|
|
"./v2": {
|
|
"import": "./dist/v2/index.mjs",
|
|
"require": "./dist/v2/index.cjs"
|
|
},
|
|
"./package.json": "./package.json"
|
|
},
|
|
"types": "./dist/index.d.cts",
|
|
"license": "MIT",
|
|
"scripts": {
|
|
"build": "pnpm run generate-graphql-schema && tsdown",
|
|
"dev": "tsdown --watch",
|
|
"test": "vitest run",
|
|
"test:watch": "vitest",
|
|
"check-types": "tsc --noEmit",
|
|
"generate-graphql-schema": "rm -rf __snapshots__ && ts-node ./scripts/generate-gql-schema.ts",
|
|
"link:global": "pnpm link --global",
|
|
"unlink:global": "pnpm unlink --global",
|
|
"publint": "publint .",
|
|
"attw": "attw --pack . --profile node16"
|
|
},
|
|
"devDependencies": {
|
|
"@swc/core": "1.5.28",
|
|
"@types/node": "^18.11.17",
|
|
"@whatwg-node/server": "^0.9.34",
|
|
"eslint": "^8.56.0",
|
|
"eslint-config-custom": "workspace:*",
|
|
"nodemon": "^3.1.3",
|
|
"ts-node": "^10.9.2",
|
|
"tsconfig": "workspace:*",
|
|
"tsdown": "^0.20.3",
|
|
"typescript": "^5.2.3",
|
|
"vitest": "^3.2.4"
|
|
},
|
|
"dependencies": {
|
|
"@ag-ui/client": "^0.0.45",
|
|
"@ag-ui/core": "^0.0.45",
|
|
"@ag-ui/langgraph": "^0.0.24",
|
|
"@ai-sdk/anthropic": "^2.0.22",
|
|
"@ai-sdk/openai": "^2.0.42",
|
|
"@copilotkit/shared": "workspace:*",
|
|
"@copilotkitnext/agent": "workspace:*",
|
|
"@copilotkitnext/runtime": "workspace:*",
|
|
"@graphql-yoga/plugin-defer-stream": "^3.3.1",
|
|
"@hono/node-server": "^1.13.5",
|
|
"@scarf/scarf": "^1.3.0",
|
|
"class-transformer": "^0.5.1",
|
|
"class-validator": "^0.14.1",
|
|
"graphql": "^16.8.1",
|
|
"graphql-scalars": "^1.23.0",
|
|
"graphql-yoga": "^5.3.1",
|
|
"ai": "^5.0.92",
|
|
"hono": "^4.11.4",
|
|
"openai": "^4.85.1",
|
|
"partial-json": "^0.1.7",
|
|
"pino": "^9.2.0",
|
|
"pino-pretty": "^11.2.1",
|
|
"reflect-metadata": "^0.2.2",
|
|
"rxjs": "7.8.1",
|
|
"type-graphql": "2.0.0-rc.1",
|
|
"zod": "^3.23.3"
|
|
},
|
|
"peerDependencies": {
|
|
"@anthropic-ai/sdk": "^0.57.0",
|
|
"@langchain/aws": ">=0.1.9",
|
|
"@langchain/core": ">=0.3.66",
|
|
"@langchain/community": ">=0.3.58",
|
|
"@langchain/google-gauth": ">=0.1.0",
|
|
"@langchain/langgraph-sdk": ">=0.1.2",
|
|
"@langchain/openai": ">=0.4.2",
|
|
"groq-sdk": ">=0.3.0 <1.0.0",
|
|
"langchain": ">=0.3.3",
|
|
"openai": "^4.85.1"
|
|
},
|
|
"peerDependenciesMeta": {
|
|
"@anthropic-ai/sdk": {
|
|
"optional": true
|
|
},
|
|
"@langchain/aws": {
|
|
"optional": true
|
|
},
|
|
"@langchain/community": {
|
|
"optional": true
|
|
},
|
|
"@langchain/google-gauth": {
|
|
"optional": true
|
|
},
|
|
"@langchain/langgraph-sdk": {
|
|
"optional": true
|
|
},
|
|
"@langchain/openai": {
|
|
"optional": true
|
|
},
|
|
"groq-sdk": {
|
|
"optional": true
|
|
},
|
|
"langchain": {
|
|
"optional": true
|
|
},
|
|
"openai": {
|
|
"optional": true
|
|
}
|
|
},
|
|
"keywords": [
|
|
"copilotkit",
|
|
"copilot",
|
|
"react",
|
|
"nextjs",
|
|
"nodejs",
|
|
"ai",
|
|
"assistant",
|
|
"javascript",
|
|
"automation",
|
|
"textarea"
|
|
]
|
|
} |