@copilotkit/runtime 1.77.2 → 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 (30) 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/intelligence-platform/client.cjs +37 -7
  19. package/dist/v2/runtime/intelligence-platform/client.cjs.map +1 -1
  20. package/dist/v2/runtime/intelligence-platform/client.d.cts.map +1 -1
  21. package/dist/v2/runtime/intelligence-platform/client.d.mts.map +1 -1
  22. package/dist/v2/runtime/intelligence-platform/client.mjs +37 -7
  23. package/dist/v2/runtime/intelligence-platform/client.mjs.map +1 -1
  24. package/dist/v2/runtime/runner/intelligence.cjs +1 -1
  25. package/dist/v2/runtime/runner/intelligence.cjs.map +1 -1
  26. package/dist/v2/runtime/runner/intelligence.d.cts.map +1 -1
  27. package/dist/v2/runtime/runner/intelligence.d.mts.map +1 -1
  28. package/dist/v2/runtime/runner/intelligence.mjs +1 -1
  29. package/dist/v2/runtime/runner/intelligence.mjs.map +1 -1
  30. package/package.json +3 -3
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.2",
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.2";
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.2";
4
+ const RUNTIME_PACKAGE_VERSION = "1.78.0";
5
5
 
6
6
  //#endregion
7
7
  export { RUNTIME_PACKAGE_NAME, RUNTIME_PACKAGE_VERSION };
@@ -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
@@ -673,7 +677,15 @@ var CopilotKitIntelligence = class {
673
677
  if (!response.ok) throw require_trajectories.trajectoryResponseError(payload, response.status, this.#apiKey);
674
678
  return require_trajectories.parseTrajectoryConnectionGrant(payload, params.trajectoryId, this.ɵgetClientWsUrl());
675
679
  }
676
- 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) {
677
689
  const url = `${this.#apiUrl}${path}`;
678
690
  const headers = {
679
691
  Authorization: `Bearer ${this.#apiKey}`,
@@ -688,7 +700,11 @@ var CopilotKitIntelligence = class {
688
700
  });
689
701
  if (!response.ok) {
690
702
  const text = await response.text().catch(() => "");
691
- _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({
692
708
  status: response.status,
693
709
  body: text,
694
710
  path
@@ -847,13 +863,20 @@ var CopilotKitIntelligence = class {
847
863
  * same `threadId` already exists.
848
864
  */
849
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) {
850
873
  const response = await this.#request("POST", `/api/threads`, {
851
874
  threadId: params.threadId,
852
875
  userId: params.userId,
853
876
  agentId: params.agentId,
854
877
  ...params.name !== void 0 ? { name: params.name } : {},
855
878
  ...params.learningContainerId !== void 0 ? { learningContainerId: params.learningContainerId } : {}
856
- });
879
+ }, void 0, void 0, expectedStatuses);
857
880
  this.#invokeLifecycleCallback("onThreadCreated", response.thread);
858
881
  return response.thread;
859
882
  }
@@ -865,8 +888,15 @@ var CopilotKitIntelligence = class {
865
888
  * not exist.
866
889
  */
867
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) {
868
898
  const qs = new URLSearchParams({ userId: params.userId }).toString();
869
- 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;
870
900
  }
871
901
  /**
872
902
  * Get an existing thread or create it if it does not exist.
@@ -886,10 +916,10 @@ var CopilotKitIntelligence = class {
886
916
  async getOrCreateThread(params) {
887
917
  try {
888
918
  return {
889
- thread: await this.getThread({
919
+ thread: await this.#getThread({
890
920
  threadId: params.threadId,
891
921
  userId: params.userId
892
- }),
922
+ }, NOT_FOUND),
893
923
  created: false
894
924
  };
895
925
  } catch (error) {
@@ -897,7 +927,7 @@ var CopilotKitIntelligence = class {
897
927
  }
898
928
  try {
899
929
  return {
900
- thread: await this.createThread(params),
930
+ thread: await this.#createThread(params, CONFLICT),
901
931
  created: true
902
932
  };
903
933
  } catch (error) {