@copilotkit/runtime 1.77.1 → 1.78.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (40) hide show
  1. package/README.md +16 -0
  2. package/dist/agent/index.cjs +84 -14
  3. package/dist/agent/index.cjs.map +1 -1
  4. package/dist/agent/index.d.cts +4 -3
  5. package/dist/agent/index.d.cts.map +1 -1
  6. package/dist/agent/index.d.mts +4 -3
  7. package/dist/agent/index.d.mts.map +1 -1
  8. package/dist/agent/index.mjs +84 -14
  9. package/dist/agent/index.mjs.map +1 -1
  10. package/dist/package.cjs +1 -1
  11. package/dist/package.mjs +1 -1
  12. package/dist/service-adapters/google/google-genai-adapter.cjs +2 -2
  13. package/dist/service-adapters/google/google-genai-adapter.cjs.map +1 -1
  14. package/dist/service-adapters/google/google-genai-adapter.mjs +2 -2
  15. package/dist/service-adapters/google/google-genai-adapter.mjs.map +1 -1
  16. package/dist/v2/runtime/core/package-info.cjs +1 -1
  17. package/dist/v2/runtime/core/package-info.mjs +1 -1
  18. package/dist/v2/runtime/handlers/handle-trajectory-connect.cjs +1 -1
  19. package/dist/v2/runtime/handlers/handle-trajectory-connect.cjs.map +1 -1
  20. package/dist/v2/runtime/handlers/handle-trajectory-connect.mjs +1 -1
  21. package/dist/v2/runtime/handlers/handle-trajectory-connect.mjs.map +1 -1
  22. package/dist/v2/runtime/intelligence-platform/client.cjs +73 -20
  23. package/dist/v2/runtime/intelligence-platform/client.cjs.map +1 -1
  24. package/dist/v2/runtime/intelligence-platform/client.d.cts.map +1 -1
  25. package/dist/v2/runtime/intelligence-platform/client.d.mts.map +1 -1
  26. package/dist/v2/runtime/intelligence-platform/client.mjs +73 -20
  27. package/dist/v2/runtime/intelligence-platform/client.mjs.map +1 -1
  28. package/dist/v2/runtime/intelligence-platform/trajectories.cjs +19 -3
  29. package/dist/v2/runtime/intelligence-platform/trajectories.cjs.map +1 -1
  30. package/dist/v2/runtime/intelligence-platform/trajectories.d.cts.map +1 -1
  31. package/dist/v2/runtime/intelligence-platform/trajectories.d.mts.map +1 -1
  32. package/dist/v2/runtime/intelligence-platform/trajectories.mjs +19 -3
  33. package/dist/v2/runtime/intelligence-platform/trajectories.mjs.map +1 -1
  34. package/dist/v2/runtime/runner/intelligence.cjs +1 -1
  35. package/dist/v2/runtime/runner/intelligence.cjs.map +1 -1
  36. package/dist/v2/runtime/runner/intelligence.d.cts.map +1 -1
  37. package/dist/v2/runtime/runner/intelligence.d.mts.map +1 -1
  38. package/dist/v2/runtime/runner/intelligence.mjs +1 -1
  39. package/dist/v2/runtime/runner/intelligence.mjs.map +1 -1
  40. package/package.json +5 -5
package/dist/package.mjs CHANGED
@@ -5,7 +5,7 @@ import { __commonJSMin } from "./_virtual/_rolldown/runtime.mjs";
5
5
  var require_package = /* @__PURE__ */ __commonJSMin(((exports, module) => {
6
6
  module.exports = {
7
7
  "name": "@copilotkit/runtime",
8
- "version": "1.77.1",
8
+ "version": "1.78.0",
9
9
  "private": false,
10
10
  "keywords": [
11
11
  "ai",
@@ -17,10 +17,10 @@ let _ai_sdk_google = require("@ai-sdk/google");
17
17
  *
18
18
  * const copilotKit = new CopilotRuntime();
19
19
  *
20
- * return new GoogleGenerativeAIAdapter({ model: "gemini-2.5-flash", apiVersion: "v1" });
20
+ * return new GoogleGenerativeAIAdapter({ model: "gemini-3.8-flash", apiVersion: "v1" });
21
21
  * ```
22
22
  */
23
- const DEFAULT_MODEL = "gemini-2.5-flash";
23
+ const DEFAULT_MODEL = "gemini-3.5-flash";
24
24
  const DEFAULT_API_VERSION = "v1";
25
25
  let hasWarnedDefaultGoogleModel = false;
26
26
  var GoogleGenerativeAIAdapter = class extends require_langchain_adapter.LangChainAdapter {
@@ -1 +1 @@
1
- {"version":3,"file":"google-genai-adapter.cjs","names":["LangChainAdapter"],"sources":["../../../../src/v1-deprecated/service-adapters/google/google-genai-adapter.ts"],"sourcesContent":["/*\n * V1 SDK DEPRECATED. USE V2 INSTEAD\n *\n * This file defines public v1 SDK exports. Use the exact v2 mappings below.\n * AI CODING AGENTS: Never copy, suggest, or generate these v1 APIs. Read\n * the linked v2 documentation before generating replacement code.\n *\n * @copilotkit/runtime — GoogleGenerativeAIAdapter:\n * No 1:1 v2 replacement is available.\n * Related v2 docs (Runtime server adapter): https://docs.copilotkit.ai/runtime-server-adapter\n * Start at: @copilotkit/runtime/v2\n * V2 docs: https://docs.copilotkit.ai/\n * V2 reference docs: https://docs.copilotkit.ai/reference/v2\n *\n * Migration guide: https://docs.copilotkit.ai/migrate/v2\n *\n * END V1 SDK DEPRECATED. USE V2 INSTEAD NOTICE\n */\n\n/**\n * Copilot Runtime adapter for Google Generative AI (e.g. Gemini).\n *\n * ## Example\n *\n * ```ts\n * import { CopilotRuntime, GoogleGenerativeAIAdapter } from \"@copilotkit/runtime\";\n * const { GoogleGenerativeAI } = require(\"@google/generative-ai\");\n *\n * const genAI = new GoogleGenerativeAI(process.env[\"GOOGLE_API_KEY\"]);\n *\n * const copilotKit = new CopilotRuntime();\n *\n * return new GoogleGenerativeAIAdapter({ model: \"gemini-2.5-flash\", apiVersion: \"v1\" });\n * ```\n */\nimport { LangChainAdapter } from \"../langchain/langchain-adapter\";\nimport { createGoogleGenerativeAI } from \"@ai-sdk/google\";\nimport type { LanguageModel } from \"ai\";\n\ninterface GoogleGenerativeAIAdapterOptions {\n /**\n * A custom Google Generative AI model to use.\n */\n model?: string;\n /**\n * The API version to use (e.g. \"v1\" or \"v1beta\"). Defaults to \"v1\".\n */\n apiVersion?: \"v1\" | \"v1beta\";\n /**\n * The API key to use.\n */\n apiKey?: string;\n}\n\nconst DEFAULT_MODEL = \"gemini-2.5-flash\";\nconst DEFAULT_API_VERSION: GoogleGenerativeAIAdapterOptions[\"apiVersion\"] =\n \"v1\";\nlet hasWarnedDefaultGoogleModel = false;\n\nexport class GoogleGenerativeAIAdapter extends LangChainAdapter {\n public provider = \"google\";\n private _apiKey?: string;\n private _apiVersion?: GoogleGenerativeAIAdapterOptions[\"apiVersion\"];\n public model: string = DEFAULT_MODEL;\n\n constructor(options?: GoogleGenerativeAIAdapterOptions) {\n if (\n !hasWarnedDefaultGoogleModel &&\n !options?.model &&\n !options?.apiVersion\n ) {\n console.warn(\n `You are using the GoogleGenerativeAIAdapter without explicitly setting a model or apiVersion. ` +\n `CopilotKit will default to apiVersion=\"v1\" and model=\"${DEFAULT_MODEL}\". ` +\n `To silence this warning, pass model and apiVersion when constructing the adapter.`,\n );\n hasWarnedDefaultGoogleModel = true;\n }\n\n super({\n chainFn: async ({ messages, tools, threadId }) => {\n // Lazy require for optional peer dependencies\n // eslint-disable-next-line @typescript-eslint/no-var-requires\n const { ChatGoogle } = require(\"@langchain/google-gauth\");\n // eslint-disable-next-line @typescript-eslint/no-var-requires\n const { AIMessage } = require(\"@langchain/core/messages\");\n\n // Filter out empty assistant messages to prevent Gemini validation errors\n // Gemini specifically rejects conversations containing AIMessages with empty content\n const filteredMessages = messages.filter((message) => {\n // Keep all non-AI messages (HumanMessage, SystemMessage, ToolMessage, etc.)\n if (!(message instanceof AIMessage)) {\n return true;\n }\n\n // For AIMessages, only keep those with non-empty content\n // Also keep AIMessages with tool_calls even if content is empty\n const aiMsg = message as any;\n return (\n (aiMsg.content && String(aiMsg.content).trim().length > 0) ||\n (aiMsg.tool_calls && aiMsg.tool_calls.length > 0)\n );\n });\n\n this.model = options?.model ?? DEFAULT_MODEL;\n const model = new ChatGoogle({\n apiKey: options?.apiKey ?? process.env.GOOGLE_API_KEY,\n modelName: this.model,\n apiVersion: options?.apiVersion ?? DEFAULT_API_VERSION,\n }).bindTools(tools);\n\n return model.stream(filteredMessages, {\n metadata: { conversation_id: threadId },\n });\n },\n });\n\n // `this.model` is otherwise only assigned inside the chain closure, which\n // does not run until a request arrives — so `getLanguageModel()` would\n // report the default model instead of the configured one.\n this._apiKey = options?.apiKey;\n this._apiVersion = options?.apiVersion;\n this.model = options?.model ?? DEFAULT_MODEL;\n }\n\n /**\n * Hands `BuiltInAgent` a model built from this adapter's own credentials.\n * Without it the runtime rebuilds a bare \"google/<model>\" string and the\n * provider falls back to environment variables, dropping the `apiKey`\n * passed to this constructor.\n */\n getLanguageModel(): LanguageModel {\n // `createGoogleGenerativeAI` has no `apiVersion` option, so the version is\n // carried on the base URL. Only when the caller asked for one: the\n // provider's own default is v1beta, and that has been the live default\n // ever since this method started routing around `process()`. Forcing the\n // adapter's documented \"v1\" here would strand models v1 does not serve.\n const provider = createGoogleGenerativeAI({\n apiKey: this._apiKey ?? process.env.GOOGLE_API_KEY,\n ...(this._apiVersion && {\n baseURL: `https://generativelanguage.googleapis.com/${this._apiVersion}`,\n }),\n });\n return provider(this.model);\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;AAsDA,MAAM,gBAAgB;AACtB,MAAM,sBACJ;AACF,IAAI,8BAA8B;AAElC,IAAa,4BAAb,cAA+CA,2CAAiB;CAM9D,YAAY,SAA4C;AACtD,MACE,CAAC,+BACD,CAAC,SAAS,SACV,CAAC,SAAS,YACV;AACA,WAAQ,KACN,uJAC2D,cAAc,sFAE1E;AACD,iCAA8B;;AAGhC,QAAM,EACJ,SAAS,OAAO,EAAE,UAAU,OAAO,eAAe;GAGhD,MAAM,EAAE,eAAe,QAAQ,0BAA0B;GAEzD,MAAM,EAAE,cAAc,QAAQ,2BAA2B;GAIzD,MAAM,mBAAmB,SAAS,QAAQ,YAAY;AAEpD,QAAI,EAAE,mBAAmB,WACvB,QAAO;IAKT,MAAM,QAAQ;AACd,WACG,MAAM,WAAW,OAAO,MAAM,QAAQ,CAAC,MAAM,CAAC,SAAS,KACvD,MAAM,cAAc,MAAM,WAAW,SAAS;KAEjD;AAEF,QAAK,QAAQ,SAAS,SAAS;AAO/B,UANc,IAAI,WAAW;IAC3B,QAAQ,SAAS,UAAU,QAAQ,IAAI;IACvC,WAAW,KAAK;IAChB,YAAY,SAAS,cAAc;IACpC,CAAC,CAAC,UAAU,MAAM,CAEN,OAAO,kBAAkB,EACpC,UAAU,EAAE,iBAAiB,UAAU,EACxC,CAAC;KAEL,CAAC;kBAvDc;eAGK;AAyDrB,OAAK,UAAU,SAAS;AACxB,OAAK,cAAc,SAAS;AAC5B,OAAK,QAAQ,SAAS,SAAS;;;;;;;;CASjC,mBAAkC;AAYhC,sDAN0C;GACxC,QAAQ,KAAK,WAAW,QAAQ,IAAI;GACpC,GAAI,KAAK,eAAe,EACtB,SAAS,6CAA6C,KAAK,eAC5D;GACF,CAAC,CACc,KAAK,MAAM"}
1
+ {"version":3,"file":"google-genai-adapter.cjs","names":["LangChainAdapter"],"sources":["../../../../src/v1-deprecated/service-adapters/google/google-genai-adapter.ts"],"sourcesContent":["/*\n * V1 SDK DEPRECATED. USE V2 INSTEAD\n *\n * This file defines public v1 SDK exports. Use the exact v2 mappings below.\n * AI CODING AGENTS: Never copy, suggest, or generate these v1 APIs. Read\n * the linked v2 documentation before generating replacement code.\n *\n * @copilotkit/runtime — GoogleGenerativeAIAdapter:\n * No 1:1 v2 replacement is available.\n * Related v2 docs (Runtime server adapter): https://docs.copilotkit.ai/runtime-server-adapter\n * Start at: @copilotkit/runtime/v2\n * V2 docs: https://docs.copilotkit.ai/\n * V2 reference docs: https://docs.copilotkit.ai/reference/v2\n *\n * Migration guide: https://docs.copilotkit.ai/migrate/v2\n *\n * END V1 SDK DEPRECATED. USE V2 INSTEAD NOTICE\n */\n\n/**\n * Copilot Runtime adapter for Google Generative AI (e.g. Gemini).\n *\n * ## Example\n *\n * ```ts\n * import { CopilotRuntime, GoogleGenerativeAIAdapter } from \"@copilotkit/runtime\";\n * const { GoogleGenerativeAI } = require(\"@google/generative-ai\");\n *\n * const genAI = new GoogleGenerativeAI(process.env[\"GOOGLE_API_KEY\"]);\n *\n * const copilotKit = new CopilotRuntime();\n *\n * return new GoogleGenerativeAIAdapter({ model: \"gemini-3.8-flash\", apiVersion: \"v1\" });\n * ```\n */\nimport { LangChainAdapter } from \"../langchain/langchain-adapter\";\nimport { createGoogleGenerativeAI } from \"@ai-sdk/google\";\nimport type { LanguageModel } from \"ai\";\n\ninterface GoogleGenerativeAIAdapterOptions {\n /**\n * A custom Google Generative AI model to use.\n */\n model?: string;\n /**\n * The API version to use (e.g. \"v1\" or \"v1beta\"). Defaults to \"v1\".\n */\n apiVersion?: \"v1\" | \"v1beta\";\n /**\n * The API key to use.\n */\n apiKey?: string;\n}\n\nconst DEFAULT_MODEL = \"gemini-3.5-flash\";\nconst DEFAULT_API_VERSION: GoogleGenerativeAIAdapterOptions[\"apiVersion\"] =\n \"v1\";\nlet hasWarnedDefaultGoogleModel = false;\n\nexport class GoogleGenerativeAIAdapter extends LangChainAdapter {\n public provider = \"google\";\n private _apiKey?: string;\n private _apiVersion?: GoogleGenerativeAIAdapterOptions[\"apiVersion\"];\n public model: string = DEFAULT_MODEL;\n\n constructor(options?: GoogleGenerativeAIAdapterOptions) {\n if (\n !hasWarnedDefaultGoogleModel &&\n !options?.model &&\n !options?.apiVersion\n ) {\n console.warn(\n `You are using the GoogleGenerativeAIAdapter without explicitly setting a model or apiVersion. ` +\n `CopilotKit will default to apiVersion=\"v1\" and model=\"${DEFAULT_MODEL}\". ` +\n `To silence this warning, pass model and apiVersion when constructing the adapter.`,\n );\n hasWarnedDefaultGoogleModel = true;\n }\n\n super({\n chainFn: async ({ messages, tools, threadId }) => {\n // Lazy require for optional peer dependencies\n // eslint-disable-next-line @typescript-eslint/no-var-requires\n const { ChatGoogle } = require(\"@langchain/google-gauth\");\n // eslint-disable-next-line @typescript-eslint/no-var-requires\n const { AIMessage } = require(\"@langchain/core/messages\");\n\n // Filter out empty assistant messages to prevent Gemini validation errors\n // Gemini specifically rejects conversations containing AIMessages with empty content\n const filteredMessages = messages.filter((message) => {\n // Keep all non-AI messages (HumanMessage, SystemMessage, ToolMessage, etc.)\n if (!(message instanceof AIMessage)) {\n return true;\n }\n\n // For AIMessages, only keep those with non-empty content\n // Also keep AIMessages with tool_calls even if content is empty\n const aiMsg = message as any;\n return (\n (aiMsg.content && String(aiMsg.content).trim().length > 0) ||\n (aiMsg.tool_calls && aiMsg.tool_calls.length > 0)\n );\n });\n\n this.model = options?.model ?? DEFAULT_MODEL;\n const model = new ChatGoogle({\n apiKey: options?.apiKey ?? process.env.GOOGLE_API_KEY,\n modelName: this.model,\n apiVersion: options?.apiVersion ?? DEFAULT_API_VERSION,\n }).bindTools(tools);\n\n return model.stream(filteredMessages, {\n metadata: { conversation_id: threadId },\n });\n },\n });\n\n // `this.model` is otherwise only assigned inside the chain closure, which\n // does not run until a request arrives — so `getLanguageModel()` would\n // report the default model instead of the configured one.\n this._apiKey = options?.apiKey;\n this._apiVersion = options?.apiVersion;\n this.model = options?.model ?? DEFAULT_MODEL;\n }\n\n /**\n * Hands `BuiltInAgent` a model built from this adapter's own credentials.\n * Without it the runtime rebuilds a bare \"google/<model>\" string and the\n * provider falls back to environment variables, dropping the `apiKey`\n * passed to this constructor.\n */\n getLanguageModel(): LanguageModel {\n // `createGoogleGenerativeAI` has no `apiVersion` option, so the version is\n // carried on the base URL. Only when the caller asked for one: the\n // provider's own default is v1beta, and that has been the live default\n // ever since this method started routing around `process()`. Forcing the\n // adapter's documented \"v1\" here would strand models v1 does not serve.\n const provider = createGoogleGenerativeAI({\n apiKey: this._apiKey ?? process.env.GOOGLE_API_KEY,\n ...(this._apiVersion && {\n baseURL: `https://generativelanguage.googleapis.com/${this._apiVersion}`,\n }),\n });\n return provider(this.model);\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;AAsDA,MAAM,gBAAgB;AACtB,MAAM,sBACJ;AACF,IAAI,8BAA8B;AAElC,IAAa,4BAAb,cAA+CA,2CAAiB;CAM9D,YAAY,SAA4C;AACtD,MACE,CAAC,+BACD,CAAC,SAAS,SACV,CAAC,SAAS,YACV;AACA,WAAQ,KACN,uJAC2D,cAAc,sFAE1E;AACD,iCAA8B;;AAGhC,QAAM,EACJ,SAAS,OAAO,EAAE,UAAU,OAAO,eAAe;GAGhD,MAAM,EAAE,eAAe,QAAQ,0BAA0B;GAEzD,MAAM,EAAE,cAAc,QAAQ,2BAA2B;GAIzD,MAAM,mBAAmB,SAAS,QAAQ,YAAY;AAEpD,QAAI,EAAE,mBAAmB,WACvB,QAAO;IAKT,MAAM,QAAQ;AACd,WACG,MAAM,WAAW,OAAO,MAAM,QAAQ,CAAC,MAAM,CAAC,SAAS,KACvD,MAAM,cAAc,MAAM,WAAW,SAAS;KAEjD;AAEF,QAAK,QAAQ,SAAS,SAAS;AAO/B,UANc,IAAI,WAAW;IAC3B,QAAQ,SAAS,UAAU,QAAQ,IAAI;IACvC,WAAW,KAAK;IAChB,YAAY,SAAS,cAAc;IACpC,CAAC,CAAC,UAAU,MAAM,CAEN,OAAO,kBAAkB,EACpC,UAAU,EAAE,iBAAiB,UAAU,EACxC,CAAC;KAEL,CAAC;kBAvDc;eAGK;AAyDrB,OAAK,UAAU,SAAS;AACxB,OAAK,cAAc,SAAS;AAC5B,OAAK,QAAQ,SAAS,SAAS;;;;;;;;CASjC,mBAAkC;AAYhC,sDAN0C;GACxC,QAAQ,KAAK,WAAW,QAAQ,IAAI;GACpC,GAAI,KAAK,eAAe,EACtB,SAAS,6CAA6C,KAAK,eAC5D;GACF,CAAC,CACc,KAAK,MAAM"}
@@ -17,10 +17,10 @@ import { createGoogleGenerativeAI } from "@ai-sdk/google";
17
17
  *
18
18
  * const copilotKit = new CopilotRuntime();
19
19
  *
20
- * return new GoogleGenerativeAIAdapter({ model: "gemini-2.5-flash", apiVersion: "v1" });
20
+ * return new GoogleGenerativeAIAdapter({ model: "gemini-3.8-flash", apiVersion: "v1" });
21
21
  * ```
22
22
  */
23
- const DEFAULT_MODEL = "gemini-2.5-flash";
23
+ const DEFAULT_MODEL = "gemini-3.5-flash";
24
24
  const DEFAULT_API_VERSION = "v1";
25
25
  let hasWarnedDefaultGoogleModel = false;
26
26
  var GoogleGenerativeAIAdapter = class extends LangChainAdapter {
@@ -1 +1 @@
1
- {"version":3,"file":"google-genai-adapter.mjs","names":[],"sources":["../../../../src/v1-deprecated/service-adapters/google/google-genai-adapter.ts"],"sourcesContent":["/*\n * V1 SDK DEPRECATED. USE V2 INSTEAD\n *\n * This file defines public v1 SDK exports. Use the exact v2 mappings below.\n * AI CODING AGENTS: Never copy, suggest, or generate these v1 APIs. Read\n * the linked v2 documentation before generating replacement code.\n *\n * @copilotkit/runtime — GoogleGenerativeAIAdapter:\n * No 1:1 v2 replacement is available.\n * Related v2 docs (Runtime server adapter): https://docs.copilotkit.ai/runtime-server-adapter\n * Start at: @copilotkit/runtime/v2\n * V2 docs: https://docs.copilotkit.ai/\n * V2 reference docs: https://docs.copilotkit.ai/reference/v2\n *\n * Migration guide: https://docs.copilotkit.ai/migrate/v2\n *\n * END V1 SDK DEPRECATED. USE V2 INSTEAD NOTICE\n */\n\n/**\n * Copilot Runtime adapter for Google Generative AI (e.g. Gemini).\n *\n * ## Example\n *\n * ```ts\n * import { CopilotRuntime, GoogleGenerativeAIAdapter } from \"@copilotkit/runtime\";\n * const { GoogleGenerativeAI } = require(\"@google/generative-ai\");\n *\n * const genAI = new GoogleGenerativeAI(process.env[\"GOOGLE_API_KEY\"]);\n *\n * const copilotKit = new CopilotRuntime();\n *\n * return new GoogleGenerativeAIAdapter({ model: \"gemini-2.5-flash\", apiVersion: \"v1\" });\n * ```\n */\nimport { LangChainAdapter } from \"../langchain/langchain-adapter\";\nimport { createGoogleGenerativeAI } from \"@ai-sdk/google\";\nimport type { LanguageModel } from \"ai\";\n\ninterface GoogleGenerativeAIAdapterOptions {\n /**\n * A custom Google Generative AI model to use.\n */\n model?: string;\n /**\n * The API version to use (e.g. \"v1\" or \"v1beta\"). Defaults to \"v1\".\n */\n apiVersion?: \"v1\" | \"v1beta\";\n /**\n * The API key to use.\n */\n apiKey?: string;\n}\n\nconst DEFAULT_MODEL = \"gemini-2.5-flash\";\nconst DEFAULT_API_VERSION: GoogleGenerativeAIAdapterOptions[\"apiVersion\"] =\n \"v1\";\nlet hasWarnedDefaultGoogleModel = false;\n\nexport class GoogleGenerativeAIAdapter extends LangChainAdapter {\n public provider = \"google\";\n private _apiKey?: string;\n private _apiVersion?: GoogleGenerativeAIAdapterOptions[\"apiVersion\"];\n public model: string = DEFAULT_MODEL;\n\n constructor(options?: GoogleGenerativeAIAdapterOptions) {\n if (\n !hasWarnedDefaultGoogleModel &&\n !options?.model &&\n !options?.apiVersion\n ) {\n console.warn(\n `You are using the GoogleGenerativeAIAdapter without explicitly setting a model or apiVersion. ` +\n `CopilotKit will default to apiVersion=\"v1\" and model=\"${DEFAULT_MODEL}\". ` +\n `To silence this warning, pass model and apiVersion when constructing the adapter.`,\n );\n hasWarnedDefaultGoogleModel = true;\n }\n\n super({\n chainFn: async ({ messages, tools, threadId }) => {\n // Lazy require for optional peer dependencies\n // eslint-disable-next-line @typescript-eslint/no-var-requires\n const { ChatGoogle } = require(\"@langchain/google-gauth\");\n // eslint-disable-next-line @typescript-eslint/no-var-requires\n const { AIMessage } = require(\"@langchain/core/messages\");\n\n // Filter out empty assistant messages to prevent Gemini validation errors\n // Gemini specifically rejects conversations containing AIMessages with empty content\n const filteredMessages = messages.filter((message) => {\n // Keep all non-AI messages (HumanMessage, SystemMessage, ToolMessage, etc.)\n if (!(message instanceof AIMessage)) {\n return true;\n }\n\n // For AIMessages, only keep those with non-empty content\n // Also keep AIMessages with tool_calls even if content is empty\n const aiMsg = message as any;\n return (\n (aiMsg.content && String(aiMsg.content).trim().length > 0) ||\n (aiMsg.tool_calls && aiMsg.tool_calls.length > 0)\n );\n });\n\n this.model = options?.model ?? DEFAULT_MODEL;\n const model = new ChatGoogle({\n apiKey: options?.apiKey ?? process.env.GOOGLE_API_KEY,\n modelName: this.model,\n apiVersion: options?.apiVersion ?? DEFAULT_API_VERSION,\n }).bindTools(tools);\n\n return model.stream(filteredMessages, {\n metadata: { conversation_id: threadId },\n });\n },\n });\n\n // `this.model` is otherwise only assigned inside the chain closure, which\n // does not run until a request arrives — so `getLanguageModel()` would\n // report the default model instead of the configured one.\n this._apiKey = options?.apiKey;\n this._apiVersion = options?.apiVersion;\n this.model = options?.model ?? DEFAULT_MODEL;\n }\n\n /**\n * Hands `BuiltInAgent` a model built from this adapter's own credentials.\n * Without it the runtime rebuilds a bare \"google/<model>\" string and the\n * provider falls back to environment variables, dropping the `apiKey`\n * passed to this constructor.\n */\n getLanguageModel(): LanguageModel {\n // `createGoogleGenerativeAI` has no `apiVersion` option, so the version is\n // carried on the base URL. Only when the caller asked for one: the\n // provider's own default is v1beta, and that has been the live default\n // ever since this method started routing around `process()`. Forcing the\n // adapter's documented \"v1\" here would strand models v1 does not serve.\n const provider = createGoogleGenerativeAI({\n apiKey: this._apiKey ?? process.env.GOOGLE_API_KEY,\n ...(this._apiVersion && {\n baseURL: `https://generativelanguage.googleapis.com/${this._apiVersion}`,\n }),\n });\n return provider(this.model);\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;AAsDA,MAAM,gBAAgB;AACtB,MAAM,sBACJ;AACF,IAAI,8BAA8B;AAElC,IAAa,4BAAb,cAA+C,iBAAiB;CAM9D,YAAY,SAA4C;AACtD,MACE,CAAC,+BACD,CAAC,SAAS,SACV,CAAC,SAAS,YACV;AACA,WAAQ,KACN,uJAC2D,cAAc,sFAE1E;AACD,iCAA8B;;AAGhC,QAAM,EACJ,SAAS,OAAO,EAAE,UAAU,OAAO,eAAe;GAGhD,MAAM,EAAE,yBAAuB,0BAA0B;GAEzD,MAAM,EAAE,wBAAsB,2BAA2B;GAIzD,MAAM,mBAAmB,SAAS,QAAQ,YAAY;AAEpD,QAAI,EAAE,mBAAmB,WACvB,QAAO;IAKT,MAAM,QAAQ;AACd,WACG,MAAM,WAAW,OAAO,MAAM,QAAQ,CAAC,MAAM,CAAC,SAAS,KACvD,MAAM,cAAc,MAAM,WAAW,SAAS;KAEjD;AAEF,QAAK,QAAQ,SAAS,SAAS;AAO/B,UANc,IAAI,WAAW;IAC3B,QAAQ,SAAS,UAAU,QAAQ,IAAI;IACvC,WAAW,KAAK;IAChB,YAAY,SAAS,cAAc;IACpC,CAAC,CAAC,UAAU,MAAM,CAEN,OAAO,kBAAkB,EACpC,UAAU,EAAE,iBAAiB,UAAU,EACxC,CAAC;KAEL,CAAC;kBAvDc;eAGK;AAyDrB,OAAK,UAAU,SAAS;AACxB,OAAK,cAAc,SAAS;AAC5B,OAAK,QAAQ,SAAS,SAAS;;;;;;;;CASjC,mBAAkC;AAYhC,SANiB,yBAAyB;GACxC,QAAQ,KAAK,WAAW,QAAQ,IAAI;GACpC,GAAI,KAAK,eAAe,EACtB,SAAS,6CAA6C,KAAK,eAC5D;GACF,CAAC,CACc,KAAK,MAAM"}
1
+ {"version":3,"file":"google-genai-adapter.mjs","names":[],"sources":["../../../../src/v1-deprecated/service-adapters/google/google-genai-adapter.ts"],"sourcesContent":["/*\n * V1 SDK DEPRECATED. USE V2 INSTEAD\n *\n * This file defines public v1 SDK exports. Use the exact v2 mappings below.\n * AI CODING AGENTS: Never copy, suggest, or generate these v1 APIs. Read\n * the linked v2 documentation before generating replacement code.\n *\n * @copilotkit/runtime — GoogleGenerativeAIAdapter:\n * No 1:1 v2 replacement is available.\n * Related v2 docs (Runtime server adapter): https://docs.copilotkit.ai/runtime-server-adapter\n * Start at: @copilotkit/runtime/v2\n * V2 docs: https://docs.copilotkit.ai/\n * V2 reference docs: https://docs.copilotkit.ai/reference/v2\n *\n * Migration guide: https://docs.copilotkit.ai/migrate/v2\n *\n * END V1 SDK DEPRECATED. USE V2 INSTEAD NOTICE\n */\n\n/**\n * Copilot Runtime adapter for Google Generative AI (e.g. Gemini).\n *\n * ## Example\n *\n * ```ts\n * import { CopilotRuntime, GoogleGenerativeAIAdapter } from \"@copilotkit/runtime\";\n * const { GoogleGenerativeAI } = require(\"@google/generative-ai\");\n *\n * const genAI = new GoogleGenerativeAI(process.env[\"GOOGLE_API_KEY\"]);\n *\n * const copilotKit = new CopilotRuntime();\n *\n * return new GoogleGenerativeAIAdapter({ model: \"gemini-3.8-flash\", apiVersion: \"v1\" });\n * ```\n */\nimport { LangChainAdapter } from \"../langchain/langchain-adapter\";\nimport { createGoogleGenerativeAI } from \"@ai-sdk/google\";\nimport type { LanguageModel } from \"ai\";\n\ninterface GoogleGenerativeAIAdapterOptions {\n /**\n * A custom Google Generative AI model to use.\n */\n model?: string;\n /**\n * The API version to use (e.g. \"v1\" or \"v1beta\"). Defaults to \"v1\".\n */\n apiVersion?: \"v1\" | \"v1beta\";\n /**\n * The API key to use.\n */\n apiKey?: string;\n}\n\nconst DEFAULT_MODEL = \"gemini-3.5-flash\";\nconst DEFAULT_API_VERSION: GoogleGenerativeAIAdapterOptions[\"apiVersion\"] =\n \"v1\";\nlet hasWarnedDefaultGoogleModel = false;\n\nexport class GoogleGenerativeAIAdapter extends LangChainAdapter {\n public provider = \"google\";\n private _apiKey?: string;\n private _apiVersion?: GoogleGenerativeAIAdapterOptions[\"apiVersion\"];\n public model: string = DEFAULT_MODEL;\n\n constructor(options?: GoogleGenerativeAIAdapterOptions) {\n if (\n !hasWarnedDefaultGoogleModel &&\n !options?.model &&\n !options?.apiVersion\n ) {\n console.warn(\n `You are using the GoogleGenerativeAIAdapter without explicitly setting a model or apiVersion. ` +\n `CopilotKit will default to apiVersion=\"v1\" and model=\"${DEFAULT_MODEL}\". ` +\n `To silence this warning, pass model and apiVersion when constructing the adapter.`,\n );\n hasWarnedDefaultGoogleModel = true;\n }\n\n super({\n chainFn: async ({ messages, tools, threadId }) => {\n // Lazy require for optional peer dependencies\n // eslint-disable-next-line @typescript-eslint/no-var-requires\n const { ChatGoogle } = require(\"@langchain/google-gauth\");\n // eslint-disable-next-line @typescript-eslint/no-var-requires\n const { AIMessage } = require(\"@langchain/core/messages\");\n\n // Filter out empty assistant messages to prevent Gemini validation errors\n // Gemini specifically rejects conversations containing AIMessages with empty content\n const filteredMessages = messages.filter((message) => {\n // Keep all non-AI messages (HumanMessage, SystemMessage, ToolMessage, etc.)\n if (!(message instanceof AIMessage)) {\n return true;\n }\n\n // For AIMessages, only keep those with non-empty content\n // Also keep AIMessages with tool_calls even if content is empty\n const aiMsg = message as any;\n return (\n (aiMsg.content && String(aiMsg.content).trim().length > 0) ||\n (aiMsg.tool_calls && aiMsg.tool_calls.length > 0)\n );\n });\n\n this.model = options?.model ?? DEFAULT_MODEL;\n const model = new ChatGoogle({\n apiKey: options?.apiKey ?? process.env.GOOGLE_API_KEY,\n modelName: this.model,\n apiVersion: options?.apiVersion ?? DEFAULT_API_VERSION,\n }).bindTools(tools);\n\n return model.stream(filteredMessages, {\n metadata: { conversation_id: threadId },\n });\n },\n });\n\n // `this.model` is otherwise only assigned inside the chain closure, which\n // does not run until a request arrives — so `getLanguageModel()` would\n // report the default model instead of the configured one.\n this._apiKey = options?.apiKey;\n this._apiVersion = options?.apiVersion;\n this.model = options?.model ?? DEFAULT_MODEL;\n }\n\n /**\n * Hands `BuiltInAgent` a model built from this adapter's own credentials.\n * Without it the runtime rebuilds a bare \"google/<model>\" string and the\n * provider falls back to environment variables, dropping the `apiKey`\n * passed to this constructor.\n */\n getLanguageModel(): LanguageModel {\n // `createGoogleGenerativeAI` has no `apiVersion` option, so the version is\n // carried on the base URL. Only when the caller asked for one: the\n // provider's own default is v1beta, and that has been the live default\n // ever since this method started routing around `process()`. Forcing the\n // adapter's documented \"v1\" here would strand models v1 does not serve.\n const provider = createGoogleGenerativeAI({\n apiKey: this._apiKey ?? process.env.GOOGLE_API_KEY,\n ...(this._apiVersion && {\n baseURL: `https://generativelanguage.googleapis.com/${this._apiVersion}`,\n }),\n });\n return provider(this.model);\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;AAsDA,MAAM,gBAAgB;AACtB,MAAM,sBACJ;AACF,IAAI,8BAA8B;AAElC,IAAa,4BAAb,cAA+C,iBAAiB;CAM9D,YAAY,SAA4C;AACtD,MACE,CAAC,+BACD,CAAC,SAAS,SACV,CAAC,SAAS,YACV;AACA,WAAQ,KACN,uJAC2D,cAAc,sFAE1E;AACD,iCAA8B;;AAGhC,QAAM,EACJ,SAAS,OAAO,EAAE,UAAU,OAAO,eAAe;GAGhD,MAAM,EAAE,yBAAuB,0BAA0B;GAEzD,MAAM,EAAE,wBAAsB,2BAA2B;GAIzD,MAAM,mBAAmB,SAAS,QAAQ,YAAY;AAEpD,QAAI,EAAE,mBAAmB,WACvB,QAAO;IAKT,MAAM,QAAQ;AACd,WACG,MAAM,WAAW,OAAO,MAAM,QAAQ,CAAC,MAAM,CAAC,SAAS,KACvD,MAAM,cAAc,MAAM,WAAW,SAAS;KAEjD;AAEF,QAAK,QAAQ,SAAS,SAAS;AAO/B,UANc,IAAI,WAAW;IAC3B,QAAQ,SAAS,UAAU,QAAQ,IAAI;IACvC,WAAW,KAAK;IAChB,YAAY,SAAS,cAAc;IACpC,CAAC,CAAC,UAAU,MAAM,CAEN,OAAO,kBAAkB,EACpC,UAAU,EAAE,iBAAiB,UAAU,EACxC,CAAC;KAEL,CAAC;kBAvDc;eAGK;AAyDrB,OAAK,UAAU,SAAS;AACxB,OAAK,cAAc,SAAS;AAC5B,OAAK,QAAQ,SAAS,SAAS;;;;;;;;CASjC,mBAAkC;AAYhC,SANiB,yBAAyB;GACxC,QAAQ,KAAK,WAAW,QAAQ,IAAI;GACpC,GAAI,KAAK,eAAe,EACtB,SAAS,6CAA6C,KAAK,eAC5D;GACF,CAAC,CACc,KAAK,MAAM"}
@@ -2,7 +2,7 @@ require("reflect-metadata");
2
2
 
3
3
  //#region src/v2/runtime/core/package-info.ts
4
4
  const RUNTIME_PACKAGE_NAME = "@copilotkit/runtime";
5
- const RUNTIME_PACKAGE_VERSION = "1.77.1";
5
+ const RUNTIME_PACKAGE_VERSION = "1.78.0";
6
6
 
7
7
  //#endregion
8
8
  exports.RUNTIME_PACKAGE_NAME = RUNTIME_PACKAGE_NAME;
@@ -1,7 +1,7 @@
1
1
  import "reflect-metadata";
2
2
  //#region src/v2/runtime/core/package-info.ts
3
3
  const RUNTIME_PACKAGE_NAME = "@copilotkit/runtime";
4
- const RUNTIME_PACKAGE_VERSION = "1.77.1";
4
+ const RUNTIME_PACKAGE_VERSION = "1.78.0";
5
5
 
6
6
  //#endregion
7
7
  export { RUNTIME_PACKAGE_NAME, RUNTIME_PACKAGE_VERSION };
@@ -15,7 +15,7 @@ function trajectoryErrorResponse(code, message, status) {
15
15
  }
16
16
  async function handleTrajectoryConnect({ runtime, request, trajectoryId }) {
17
17
  if (!require_trajectories.isValidTrajectoryId(trajectoryId)) return trajectoryErrorResponse("INVALID_REQUEST", "A valid trajectoryId is required", 400);
18
- if (!require_runtime.isIntelligenceRuntime(runtime)) return trajectoryErrorResponse("CONNECTION_FAILED", "Trajectory capture requires an Intelligence runtime", 503);
18
+ if (!require_runtime.isIntelligenceRuntime(runtime)) return trajectoryErrorResponse("INTELLIGENCE_RUNTIME_REQUIRED", "Trajectory capture requires an Intelligence runtime", 503);
19
19
  if (!runtime.identifyUser) return trajectoryErrorResponse("IDENTITY_REQUIRED", "Trajectory capture requires an identified user", 401);
20
20
  const user = await require_resolve_intelligence_user.resolveIntelligenceUser({
21
21
  runtime,
@@ -1 +1 @@
1
- {"version":3,"file":"handle-trajectory-connect.cjs","names":["isValidTrajectoryId","isIntelligenceRuntime","resolveIntelligenceUser","TrajectoryConnectionError"],"sources":["../../../../src/v2/runtime/handlers/handle-trajectory-connect.ts"],"sourcesContent":["import type { CopilotRuntimeLike } from \"../core/runtime\";\nimport { isIntelligenceRuntime } from \"../core/runtime\";\nimport {\n isValidTrajectoryId,\n TrajectoryConnectionError,\n} from \"../intelligence-platform/trajectories\";\nimport { resolveIntelligenceUser } from \"./shared/resolve-intelligence-user\";\n\nexport function trajectoryErrorResponse(\n code: string,\n message: string,\n status: number,\n): Response {\n return Response.json(\n { code, message },\n { status, headers: { \"Cache-Control\": \"no-store\" } },\n );\n}\n\nexport async function handleTrajectoryConnect({\n runtime,\n request,\n trajectoryId,\n}: {\n runtime: CopilotRuntimeLike;\n request: Request;\n trajectoryId: string;\n}): Promise<Response> {\n if (!isValidTrajectoryId(trajectoryId)) {\n return trajectoryErrorResponse(\n \"INVALID_REQUEST\",\n \"A valid trajectoryId is required\",\n 400,\n );\n }\n if (!isIntelligenceRuntime(runtime)) {\n return trajectoryErrorResponse(\n \"CONNECTION_FAILED\",\n \"Trajectory capture requires an Intelligence runtime\",\n 503,\n );\n }\n if (!runtime.identifyUser) {\n return trajectoryErrorResponse(\n \"IDENTITY_REQUIRED\",\n \"Trajectory capture requires an identified user\",\n 401,\n );\n }\n const user = await resolveIntelligenceUser({ runtime, request });\n if (user instanceof Response) {\n return trajectoryErrorResponse(\n \"IDENTITY_REQUIRED\",\n \"Trajectory capture requires an identified user\",\n 401,\n );\n }\n\n try {\n const grant = await runtime.intelligence.ɵconnectTrajectory({\n trajectoryId,\n user,\n signal: request.signal,\n });\n return Response.json(grant, {\n headers: { \"Cache-Control\": \"no-store\" },\n });\n } catch (error) {\n if (error instanceof TrajectoryConnectionError) {\n return trajectoryErrorResponse(error.code, error.message, error.status);\n }\n return trajectoryErrorResponse(\n \"CONNECTION_FAILED\",\n \"Could not connect to Intelligence\",\n 502,\n );\n }\n}\n"],"mappings":";;;;;;AAQA,SAAgB,wBACd,MACA,SACA,QACU;AACV,QAAO,SAAS,KACd;EAAE;EAAM;EAAS,EACjB;EAAE;EAAQ,SAAS,EAAE,iBAAiB,YAAY;EAAE,CACrD;;AAGH,eAAsB,wBAAwB,EAC5C,SACA,SACA,gBAKoB;AACpB,KAAI,CAACA,yCAAoB,aAAa,CACpC,QAAO,wBACL,mBACA,oCACA,IACD;AAEH,KAAI,CAACC,sCAAsB,QAAQ,CACjC,QAAO,wBACL,qBACA,uDACA,IACD;AAEH,KAAI,CAAC,QAAQ,aACX,QAAO,wBACL,qBACA,kDACA,IACD;CAEH,MAAM,OAAO,MAAMC,0DAAwB;EAAE;EAAS;EAAS,CAAC;AAChE,KAAI,gBAAgB,SAClB,QAAO,wBACL,qBACA,kDACA,IACD;AAGH,KAAI;EACF,MAAM,QAAQ,MAAM,QAAQ,aAAa,mBAAmB;GAC1D;GACA;GACA,QAAQ,QAAQ;GACjB,CAAC;AACF,SAAO,SAAS,KAAK,OAAO,EAC1B,SAAS,EAAE,iBAAiB,YAAY,EACzC,CAAC;UACK,OAAO;AACd,MAAI,iBAAiBC,+CACnB,QAAO,wBAAwB,MAAM,MAAM,MAAM,SAAS,MAAM,OAAO;AAEzE,SAAO,wBACL,qBACA,qCACA,IACD"}
1
+ {"version":3,"file":"handle-trajectory-connect.cjs","names":["isValidTrajectoryId","isIntelligenceRuntime","resolveIntelligenceUser","TrajectoryConnectionError"],"sources":["../../../../src/v2/runtime/handlers/handle-trajectory-connect.ts"],"sourcesContent":["import type { CopilotRuntimeLike } from \"../core/runtime\";\nimport { isIntelligenceRuntime } from \"../core/runtime\";\nimport {\n isValidTrajectoryId,\n TrajectoryConnectionError,\n} from \"../intelligence-platform/trajectories\";\nimport { resolveIntelligenceUser } from \"./shared/resolve-intelligence-user\";\n\nexport function trajectoryErrorResponse(\n code: string,\n message: string,\n status: number,\n): Response {\n return Response.json(\n { code, message },\n { status, headers: { \"Cache-Control\": \"no-store\" } },\n );\n}\n\nexport async function handleTrajectoryConnect({\n runtime,\n request,\n trajectoryId,\n}: {\n runtime: CopilotRuntimeLike;\n request: Request;\n trajectoryId: string;\n}): Promise<Response> {\n if (!isValidTrajectoryId(trajectoryId)) {\n return trajectoryErrorResponse(\n \"INVALID_REQUEST\",\n \"A valid trajectoryId is required\",\n 400,\n );\n }\n if (!isIntelligenceRuntime(runtime)) {\n return trajectoryErrorResponse(\n \"INTELLIGENCE_RUNTIME_REQUIRED\",\n \"Trajectory capture requires an Intelligence runtime\",\n 503,\n );\n }\n if (!runtime.identifyUser) {\n return trajectoryErrorResponse(\n \"IDENTITY_REQUIRED\",\n \"Trajectory capture requires an identified user\",\n 401,\n );\n }\n const user = await resolveIntelligenceUser({ runtime, request });\n if (user instanceof Response) {\n return trajectoryErrorResponse(\n \"IDENTITY_REQUIRED\",\n \"Trajectory capture requires an identified user\",\n 401,\n );\n }\n\n try {\n const grant = await runtime.intelligence.ɵconnectTrajectory({\n trajectoryId,\n user,\n signal: request.signal,\n });\n return Response.json(grant, {\n headers: { \"Cache-Control\": \"no-store\" },\n });\n } catch (error) {\n if (error instanceof TrajectoryConnectionError) {\n return trajectoryErrorResponse(error.code, error.message, error.status);\n }\n return trajectoryErrorResponse(\n \"CONNECTION_FAILED\",\n \"Could not connect to Intelligence\",\n 502,\n );\n }\n}\n"],"mappings":";;;;;;AAQA,SAAgB,wBACd,MACA,SACA,QACU;AACV,QAAO,SAAS,KACd;EAAE;EAAM;EAAS,EACjB;EAAE;EAAQ,SAAS,EAAE,iBAAiB,YAAY;EAAE,CACrD;;AAGH,eAAsB,wBAAwB,EAC5C,SACA,SACA,gBAKoB;AACpB,KAAI,CAACA,yCAAoB,aAAa,CACpC,QAAO,wBACL,mBACA,oCACA,IACD;AAEH,KAAI,CAACC,sCAAsB,QAAQ,CACjC,QAAO,wBACL,iCACA,uDACA,IACD;AAEH,KAAI,CAAC,QAAQ,aACX,QAAO,wBACL,qBACA,kDACA,IACD;CAEH,MAAM,OAAO,MAAMC,0DAAwB;EAAE;EAAS;EAAS,CAAC;AAChE,KAAI,gBAAgB,SAClB,QAAO,wBACL,qBACA,kDACA,IACD;AAGH,KAAI;EACF,MAAM,QAAQ,MAAM,QAAQ,aAAa,mBAAmB;GAC1D;GACA;GACA,QAAQ,QAAQ;GACjB,CAAC;AACF,SAAO,SAAS,KAAK,OAAO,EAC1B,SAAS,EAAE,iBAAiB,YAAY,EACzC,CAAC;UACK,OAAO;AACd,MAAI,iBAAiBC,+CACnB,QAAO,wBAAwB,MAAM,MAAM,MAAM,SAAS,MAAM,OAAO;AAEzE,SAAO,wBACL,qBACA,qCACA,IACD"}
@@ -15,7 +15,7 @@ function trajectoryErrorResponse(code, message, status) {
15
15
  }
16
16
  async function handleTrajectoryConnect({ runtime, request, trajectoryId }) {
17
17
  if (!isValidTrajectoryId(trajectoryId)) return trajectoryErrorResponse("INVALID_REQUEST", "A valid trajectoryId is required", 400);
18
- if (!isIntelligenceRuntime(runtime)) return trajectoryErrorResponse("CONNECTION_FAILED", "Trajectory capture requires an Intelligence runtime", 503);
18
+ if (!isIntelligenceRuntime(runtime)) return trajectoryErrorResponse("INTELLIGENCE_RUNTIME_REQUIRED", "Trajectory capture requires an Intelligence runtime", 503);
19
19
  if (!runtime.identifyUser) return trajectoryErrorResponse("IDENTITY_REQUIRED", "Trajectory capture requires an identified user", 401);
20
20
  const user = await resolveIntelligenceUser({
21
21
  runtime,
@@ -1 +1 @@
1
- {"version":3,"file":"handle-trajectory-connect.mjs","names":[],"sources":["../../../../src/v2/runtime/handlers/handle-trajectory-connect.ts"],"sourcesContent":["import type { CopilotRuntimeLike } from \"../core/runtime\";\nimport { isIntelligenceRuntime } from \"../core/runtime\";\nimport {\n isValidTrajectoryId,\n TrajectoryConnectionError,\n} from \"../intelligence-platform/trajectories\";\nimport { resolveIntelligenceUser } from \"./shared/resolve-intelligence-user\";\n\nexport function trajectoryErrorResponse(\n code: string,\n message: string,\n status: number,\n): Response {\n return Response.json(\n { code, message },\n { status, headers: { \"Cache-Control\": \"no-store\" } },\n );\n}\n\nexport async function handleTrajectoryConnect({\n runtime,\n request,\n trajectoryId,\n}: {\n runtime: CopilotRuntimeLike;\n request: Request;\n trajectoryId: string;\n}): Promise<Response> {\n if (!isValidTrajectoryId(trajectoryId)) {\n return trajectoryErrorResponse(\n \"INVALID_REQUEST\",\n \"A valid trajectoryId is required\",\n 400,\n );\n }\n if (!isIntelligenceRuntime(runtime)) {\n return trajectoryErrorResponse(\n \"CONNECTION_FAILED\",\n \"Trajectory capture requires an Intelligence runtime\",\n 503,\n );\n }\n if (!runtime.identifyUser) {\n return trajectoryErrorResponse(\n \"IDENTITY_REQUIRED\",\n \"Trajectory capture requires an identified user\",\n 401,\n );\n }\n const user = await resolveIntelligenceUser({ runtime, request });\n if (user instanceof Response) {\n return trajectoryErrorResponse(\n \"IDENTITY_REQUIRED\",\n \"Trajectory capture requires an identified user\",\n 401,\n );\n }\n\n try {\n const grant = await runtime.intelligence.ɵconnectTrajectory({\n trajectoryId,\n user,\n signal: request.signal,\n });\n return Response.json(grant, {\n headers: { \"Cache-Control\": \"no-store\" },\n });\n } catch (error) {\n if (error instanceof TrajectoryConnectionError) {\n return trajectoryErrorResponse(error.code, error.message, error.status);\n }\n return trajectoryErrorResponse(\n \"CONNECTION_FAILED\",\n \"Could not connect to Intelligence\",\n 502,\n );\n }\n}\n"],"mappings":";;;;;;AAQA,SAAgB,wBACd,MACA,SACA,QACU;AACV,QAAO,SAAS,KACd;EAAE;EAAM;EAAS,EACjB;EAAE;EAAQ,SAAS,EAAE,iBAAiB,YAAY;EAAE,CACrD;;AAGH,eAAsB,wBAAwB,EAC5C,SACA,SACA,gBAKoB;AACpB,KAAI,CAAC,oBAAoB,aAAa,CACpC,QAAO,wBACL,mBACA,oCACA,IACD;AAEH,KAAI,CAAC,sBAAsB,QAAQ,CACjC,QAAO,wBACL,qBACA,uDACA,IACD;AAEH,KAAI,CAAC,QAAQ,aACX,QAAO,wBACL,qBACA,kDACA,IACD;CAEH,MAAM,OAAO,MAAM,wBAAwB;EAAE;EAAS;EAAS,CAAC;AAChE,KAAI,gBAAgB,SAClB,QAAO,wBACL,qBACA,kDACA,IACD;AAGH,KAAI;EACF,MAAM,QAAQ,MAAM,QAAQ,aAAa,mBAAmB;GAC1D;GACA;GACA,QAAQ,QAAQ;GACjB,CAAC;AACF,SAAO,SAAS,KAAK,OAAO,EAC1B,SAAS,EAAE,iBAAiB,YAAY,EACzC,CAAC;UACK,OAAO;AACd,MAAI,iBAAiB,0BACnB,QAAO,wBAAwB,MAAM,MAAM,MAAM,SAAS,MAAM,OAAO;AAEzE,SAAO,wBACL,qBACA,qCACA,IACD"}
1
+ {"version":3,"file":"handle-trajectory-connect.mjs","names":[],"sources":["../../../../src/v2/runtime/handlers/handle-trajectory-connect.ts"],"sourcesContent":["import type { CopilotRuntimeLike } from \"../core/runtime\";\nimport { isIntelligenceRuntime } from \"../core/runtime\";\nimport {\n isValidTrajectoryId,\n TrajectoryConnectionError,\n} from \"../intelligence-platform/trajectories\";\nimport { resolveIntelligenceUser } from \"./shared/resolve-intelligence-user\";\n\nexport function trajectoryErrorResponse(\n code: string,\n message: string,\n status: number,\n): Response {\n return Response.json(\n { code, message },\n { status, headers: { \"Cache-Control\": \"no-store\" } },\n );\n}\n\nexport async function handleTrajectoryConnect({\n runtime,\n request,\n trajectoryId,\n}: {\n runtime: CopilotRuntimeLike;\n request: Request;\n trajectoryId: string;\n}): Promise<Response> {\n if (!isValidTrajectoryId(trajectoryId)) {\n return trajectoryErrorResponse(\n \"INVALID_REQUEST\",\n \"A valid trajectoryId is required\",\n 400,\n );\n }\n if (!isIntelligenceRuntime(runtime)) {\n return trajectoryErrorResponse(\n \"INTELLIGENCE_RUNTIME_REQUIRED\",\n \"Trajectory capture requires an Intelligence runtime\",\n 503,\n );\n }\n if (!runtime.identifyUser) {\n return trajectoryErrorResponse(\n \"IDENTITY_REQUIRED\",\n \"Trajectory capture requires an identified user\",\n 401,\n );\n }\n const user = await resolveIntelligenceUser({ runtime, request });\n if (user instanceof Response) {\n return trajectoryErrorResponse(\n \"IDENTITY_REQUIRED\",\n \"Trajectory capture requires an identified user\",\n 401,\n );\n }\n\n try {\n const grant = await runtime.intelligence.ɵconnectTrajectory({\n trajectoryId,\n user,\n signal: request.signal,\n });\n return Response.json(grant, {\n headers: { \"Cache-Control\": \"no-store\" },\n });\n } catch (error) {\n if (error instanceof TrajectoryConnectionError) {\n return trajectoryErrorResponse(error.code, error.message, error.status);\n }\n return trajectoryErrorResponse(\n \"CONNECTION_FAILED\",\n \"Could not connect to Intelligence\",\n 502,\n );\n }\n}\n"],"mappings":";;;;;;AAQA,SAAgB,wBACd,MACA,SACA,QACU;AACV,QAAO,SAAS,KACd;EAAE;EAAM;EAAS,EACjB;EAAE;EAAQ,SAAS,EAAE,iBAAiB,YAAY;EAAE,CACrD;;AAGH,eAAsB,wBAAwB,EAC5C,SACA,SACA,gBAKoB;AACpB,KAAI,CAAC,oBAAoB,aAAa,CACpC,QAAO,wBACL,mBACA,oCACA,IACD;AAEH,KAAI,CAAC,sBAAsB,QAAQ,CACjC,QAAO,wBACL,iCACA,uDACA,IACD;AAEH,KAAI,CAAC,QAAQ,aACX,QAAO,wBACL,qBACA,kDACA,IACD;CAEH,MAAM,OAAO,MAAM,wBAAwB;EAAE;EAAS;EAAS,CAAC;AAChE,KAAI,gBAAgB,SAClB,QAAO,wBACL,qBACA,kDACA,IACD;AAGH,KAAI;EACF,MAAM,QAAQ,MAAM,QAAQ,aAAa,mBAAmB;GAC1D;GACA;GACA,QAAQ,QAAQ;GACjB,CAAC;AACF,SAAO,SAAS,KAAK,OAAO,EAC1B,SAAS,EAAE,iBAAiB,YAAY,EACzC,CAAC;UACK,OAAO;AACd,MAAI,iBAAiB,0BACnB,QAAO,wBAAwB,MAAM,MAAM,MAAM,SAAS,MAAM,OAAO;AAEzE,SAAO,wBACL,qBACA,qCACA,IACD"}
@@ -121,6 +121,10 @@ const MANAGED_INTELLIGENCE_WS_URL = "wss://realtime.intelligence.copilotkit.ai";
121
121
  /** Maximum time spent on the optional Inspector metadata provider request. */
122
122
  const INSPECTOR_METADATA_REQUEST_TIMEOUT_MS = 5e3;
123
123
  const INSPECTOR_LEARNING_REQUEST_TIMEOUT_MS = 5e3;
124
+ /** A 404 the caller expects: a thread lookup made before the thread exists. */
125
+ const NOT_FOUND = new Set([404]);
126
+ /** A 409 the caller expects: another request created the thread first. */
127
+ const CONFLICT = new Set([409]);
124
128
  /**
125
129
  * Error thrown when a CopilotKit Intelligence HTTP request returns a non-2xx
126
130
  * status. Carries the HTTP {@link status} code so callers can branch on
@@ -646,24 +650,42 @@ var CopilotKitIntelligence = class {
646
650
  }
647
651
  /** Mint a browser capture grant using only the Runtime's project and user. */
648
652
  async ɵconnectTrajectory(params) {
649
- const response = await fetch(`${this.#apiUrl}/api/trajectories/join`, {
650
- method: "POST",
651
- headers: {
652
- Authorization: `Bearer ${this.#apiKey}`,
653
- "Content-Type": "application/json"
654
- },
655
- body: JSON.stringify({
656
- trajectoryId: params.trajectoryId,
657
- appUserId: params.user.id
658
- }),
659
- signal: params.signal,
660
- redirect: "error"
661
- });
653
+ let response;
654
+ try {
655
+ response = await fetch(`${this.#apiUrl}/api/trajectories/join`, {
656
+ method: "POST",
657
+ headers: {
658
+ Authorization: `Bearer ${this.#apiKey}`,
659
+ "Content-Type": "application/json"
660
+ },
661
+ body: JSON.stringify({
662
+ trajectoryId: params.trajectoryId,
663
+ appUserId: params.user.id
664
+ }),
665
+ signal: params.signal,
666
+ redirect: "error"
667
+ });
668
+ } catch (error) {
669
+ if (!params.signal?.aborted) _copilotkit_shared.logger.warn({
670
+ error: error instanceof Error ? error.name : typeof error,
671
+ causeCode: networkErrorCode(error instanceof Error ? error.cause : void 0),
672
+ host: urlHost(this.#apiUrl)
673
+ }, "Could not reach Intelligence to connect a Trajectory");
674
+ throw error;
675
+ }
662
676
  const payload = await response.json().catch(() => void 0);
663
677
  if (!response.ok) throw require_trajectories.trajectoryResponseError(payload, response.status, this.#apiKey);
664
678
  return require_trajectories.parseTrajectoryConnectionGrant(payload, params.trajectoryId, this.ɵgetClientWsUrl());
665
679
  }
666
- async #request(method, path, body, extraHeaders, signal) {
680
+ /**
681
+ * Sends one request to the platform and parses its JSON body.
682
+ *
683
+ * @param expectedStatuses - Non-2xx statuses the caller handles as a normal
684
+ * outcome, such as the 404 of a thread that does not exist yet. They are
685
+ * logged at debug instead of error, and still throw.
686
+ * @throws {@link PlatformRequestError} on every non-2xx response.
687
+ */
688
+ async #request(method, path, body, extraHeaders, signal, expectedStatuses) {
667
689
  const url = `${this.#apiUrl}${path}`;
668
690
  const headers = {
669
691
  Authorization: `Bearer ${this.#apiKey}`,
@@ -678,7 +700,11 @@ var CopilotKitIntelligence = class {
678
700
  });
679
701
  if (!response.ok) {
680
702
  const text = await response.text().catch(() => "");
681
- _copilotkit_shared.logger.error({
703
+ if (expectedStatuses?.has(response.status)) _copilotkit_shared.logger.debug({
704
+ status: response.status,
705
+ path
706
+ }, "Intelligence platform request returned an expected status");
707
+ else _copilotkit_shared.logger.error({
682
708
  status: response.status,
683
709
  body: text,
684
710
  path
@@ -837,13 +863,20 @@ var CopilotKitIntelligence = class {
837
863
  * same `threadId` already exists.
838
864
  */
839
865
  async createThread(params) {
866
+ return this.#createThread(params);
867
+ }
868
+ /**
869
+ * Creates a thread. {@link getOrCreateThread} passes 409 as expected,
870
+ * because there it means another request created the thread first.
871
+ */
872
+ async #createThread(params, expectedStatuses) {
840
873
  const response = await this.#request("POST", `/api/threads`, {
841
874
  threadId: params.threadId,
842
875
  userId: params.userId,
843
876
  agentId: params.agentId,
844
877
  ...params.name !== void 0 ? { name: params.name } : {},
845
878
  ...params.learningContainerId !== void 0 ? { learningContainerId: params.learningContainerId } : {}
846
- });
879
+ }, void 0, void 0, expectedStatuses);
847
880
  this.#invokeLifecycleCallback("onThreadCreated", response.thread);
848
881
  return response.thread;
849
882
  }
@@ -855,8 +888,15 @@ var CopilotKitIntelligence = class {
855
888
  * not exist.
856
889
  */
857
890
  async getThread(params) {
891
+ return this.#getThread(params);
892
+ }
893
+ /**
894
+ * Fetches a thread. {@link getOrCreateThread} passes 404 as expected,
895
+ * because there it means the thread is about to be created (PE-678).
896
+ */
897
+ async #getThread(params, expectedStatuses) {
858
898
  const qs = new URLSearchParams({ userId: params.userId }).toString();
859
- return (await this.#request("GET", `/api/threads/${encodeURIComponent(params.threadId)}?${qs}`)).thread;
899
+ return (await this.#request("GET", `/api/threads/${encodeURIComponent(params.threadId)}?${qs}`, void 0, void 0, void 0, expectedStatuses)).thread;
860
900
  }
861
901
  /**
862
902
  * Get an existing thread or create it if it does not exist.
@@ -876,10 +916,10 @@ var CopilotKitIntelligence = class {
876
916
  async getOrCreateThread(params) {
877
917
  try {
878
918
  return {
879
- thread: await this.getThread({
919
+ thread: await this.#getThread({
880
920
  threadId: params.threadId,
881
921
  userId: params.userId
882
- }),
922
+ }, NOT_FOUND),
883
923
  created: false
884
924
  };
885
925
  } catch (error) {
@@ -887,7 +927,7 @@ var CopilotKitIntelligence = class {
887
927
  }
888
928
  try {
889
929
  return {
890
- thread: await this.createThread(params),
930
+ thread: await this.#createThread(params, CONFLICT),
891
931
  created: true
892
932
  };
893
933
  } catch (error) {
@@ -1114,6 +1154,19 @@ function deriveRunnerWsUrl(wsUrl) {
1114
1154
  if (wsUrl.endsWith("/channels")) return `${wsUrl.slice(0, -9)}/runner`;
1115
1155
  return `${wsUrl}/runner`;
1116
1156
  }
1157
+ /** A system error code such as ECONNREFUSED, or undefined for anything else. */
1158
+ function networkErrorCode(cause) {
1159
+ const code = typeof cause === "object" && cause !== null && "code" in cause ? cause.code : void 0;
1160
+ return typeof code === "string" && /^[A-Z][A-Z0-9_]{0,63}$/.test(code) ? code : void 0;
1161
+ }
1162
+ /** The host of a URL without its credentials, path or query. */
1163
+ function urlHost(url) {
1164
+ try {
1165
+ return new URL(url).host;
1166
+ } catch {
1167
+ return;
1168
+ }
1169
+ }
1117
1170
  function deriveClientWsUrl(wsUrl) {
1118
1171
  if (wsUrl.endsWith("/client")) return wsUrl;
1119
1172
  if (wsUrl.endsWith("/runner")) return `${wsUrl.slice(0, -7)}/client`;