@copilotkit/runtime 1.64.2-canary.perfall1 → 1.64.2

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 (79) hide show
  1. package/dist/package.cjs +1 -1
  2. package/dist/runtime/package.mjs +1 -1
  3. package/dist/v2/runtime/core/channel-activation-config.cjs +2 -1
  4. package/dist/v2/runtime/core/channel-activation-config.cjs.map +1 -1
  5. package/dist/v2/runtime/core/channel-activation-config.d.cts +7 -0
  6. package/dist/v2/runtime/core/channel-activation-config.d.cts.map +1 -1
  7. package/dist/v2/runtime/core/channel-activation-config.d.mts +7 -0
  8. package/dist/v2/runtime/core/channel-activation-config.d.mts.map +1 -1
  9. package/dist/v2/runtime/core/channel-activation-config.mjs +2 -1
  10. package/dist/v2/runtime/core/channel-activation-config.mjs.map +1 -1
  11. package/dist/v2/runtime/core/channel-manager.cjs +214 -18
  12. package/dist/v2/runtime/core/channel-manager.cjs.map +1 -1
  13. package/dist/v2/runtime/core/channel-manager.d.cts +6 -5
  14. package/dist/v2/runtime/core/channel-manager.d.cts.map +1 -1
  15. package/dist/v2/runtime/core/channel-manager.d.mts +6 -5
  16. package/dist/v2/runtime/core/channel-manager.d.mts.map +1 -1
  17. package/dist/v2/runtime/core/channel-manager.mjs +214 -18
  18. package/dist/v2/runtime/core/channel-manager.mjs.map +1 -1
  19. package/dist/v2/runtime/core/fetch-handler.cjs +4 -0
  20. package/dist/v2/runtime/core/fetch-handler.cjs.map +1 -1
  21. package/dist/v2/runtime/core/fetch-handler.d.cts +5 -0
  22. package/dist/v2/runtime/core/fetch-handler.d.cts.map +1 -1
  23. package/dist/v2/runtime/core/fetch-handler.d.mts +5 -0
  24. package/dist/v2/runtime/core/fetch-handler.d.mts.map +1 -1
  25. package/dist/v2/runtime/core/fetch-handler.mjs +4 -0
  26. package/dist/v2/runtime/core/fetch-handler.mjs.map +1 -1
  27. package/dist/v2/runtime/endpoints/auto-start-channels.cjs +47 -0
  28. package/dist/v2/runtime/endpoints/auto-start-channels.cjs.map +1 -0
  29. package/dist/v2/runtime/endpoints/auto-start-channels.mjs +46 -0
  30. package/dist/v2/runtime/endpoints/auto-start-channels.mjs.map +1 -0
  31. package/dist/v2/runtime/endpoints/express.cjs +2 -0
  32. package/dist/v2/runtime/endpoints/express.cjs.map +1 -1
  33. package/dist/v2/runtime/endpoints/express.d.cts +9 -8
  34. package/dist/v2/runtime/endpoints/express.d.cts.map +1 -1
  35. package/dist/v2/runtime/endpoints/express.d.mts +9 -8
  36. package/dist/v2/runtime/endpoints/express.d.mts.map +1 -1
  37. package/dist/v2/runtime/endpoints/express.mjs +2 -0
  38. package/dist/v2/runtime/endpoints/express.mjs.map +1 -1
  39. package/dist/v2/runtime/endpoints/hono.cjs.map +1 -1
  40. package/dist/v2/runtime/endpoints/hono.d.cts +14 -5
  41. package/dist/v2/runtime/endpoints/hono.d.cts.map +1 -1
  42. package/dist/v2/runtime/endpoints/hono.d.mts +14 -5
  43. package/dist/v2/runtime/endpoints/hono.d.mts.map +1 -1
  44. package/dist/v2/runtime/endpoints/hono.mjs.map +1 -1
  45. package/dist/v2/runtime/endpoints/node.cjs +2 -0
  46. package/dist/v2/runtime/endpoints/node.cjs.map +1 -1
  47. package/dist/v2/runtime/endpoints/node.d.cts +23 -13
  48. package/dist/v2/runtime/endpoints/node.d.cts.map +1 -1
  49. package/dist/v2/runtime/endpoints/node.d.mts +23 -13
  50. package/dist/v2/runtime/endpoints/node.d.mts.map +1 -1
  51. package/dist/v2/runtime/endpoints/node.mjs +2 -0
  52. package/dist/v2/runtime/endpoints/node.mjs.map +1 -1
  53. package/dist/v2/runtime/intelligence-platform/client.cjs +33 -2
  54. package/dist/v2/runtime/intelligence-platform/client.cjs.map +1 -1
  55. package/dist/v2/runtime/intelligence-platform/client.d.cts +14 -3
  56. package/dist/v2/runtime/intelligence-platform/client.d.cts.map +1 -1
  57. package/dist/v2/runtime/intelligence-platform/client.d.mts +14 -3
  58. package/dist/v2/runtime/intelligence-platform/client.d.mts.map +1 -1
  59. package/dist/v2/runtime/intelligence-platform/client.mjs +33 -2
  60. package/dist/v2/runtime/intelligence-platform/client.mjs.map +1 -1
  61. package/dist/v2/runtime/runner/agent-runner.cjs.map +1 -1
  62. package/dist/v2/runtime/runner/agent-runner.d.cts +4 -0
  63. package/dist/v2/runtime/runner/agent-runner.d.cts.map +1 -1
  64. package/dist/v2/runtime/runner/agent-runner.d.mts +4 -0
  65. package/dist/v2/runtime/runner/agent-runner.d.mts.map +1 -1
  66. package/dist/v2/runtime/runner/agent-runner.mjs.map +1 -1
  67. package/dist/v2/runtime/runner/in-memory.cjs +3 -5
  68. package/dist/v2/runtime/runner/in-memory.cjs.map +1 -1
  69. package/dist/v2/runtime/runner/in-memory.d.cts.map +1 -1
  70. package/dist/v2/runtime/runner/in-memory.d.mts.map +1 -1
  71. package/dist/v2/runtime/runner/in-memory.mjs +3 -5
  72. package/dist/v2/runtime/runner/in-memory.mjs.map +1 -1
  73. package/dist/v2/runtime/runner/intelligence.cjs +38 -31
  74. package/dist/v2/runtime/runner/intelligence.cjs.map +1 -1
  75. package/dist/v2/runtime/runner/intelligence.d.cts.map +1 -1
  76. package/dist/v2/runtime/runner/intelligence.d.mts.map +1 -1
  77. package/dist/v2/runtime/runner/intelligence.mjs +38 -31
  78. package/dist/v2/runtime/runner/intelligence.mjs.map +1 -1
  79. package/package.json +5 -5
package/dist/package.cjs CHANGED
@@ -5,7 +5,7 @@ const require_runtime = require('./_virtual/_rolldown/runtime.cjs');
5
5
  var require_package = /* @__PURE__ */ require_runtime.__commonJSMin(((exports, module) => {
6
6
  module.exports = {
7
7
  "name": "@copilotkit/runtime",
8
- "version": "1.64.2-canary.perfall1",
8
+ "version": "1.64.2",
9
9
  "private": false,
10
10
  "keywords": [
11
11
  "ai",
@@ -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.64.2-canary.perfall1",
8
+ "version": "1.64.2",
9
9
  "private": false,
10
10
  "keywords": [
11
11
  "ai",
@@ -72,7 +72,7 @@ function deriveChannelActivationConfig(args) {
72
72
  const { intelligence, channel, runtimeInstanceId } = args;
73
73
  if (!channel.name) throw new ChannelConfigError("Channel is missing a `name` — pass createChannel({ name }) to activate it.");
74
74
  const channelName = channel.name;
75
- const wsUrl = intelligence.ɵgetRunnerWsUrl();
75
+ const wsUrl = intelligence.ɵgetChannelsWsUrl();
76
76
  const apiUrl = intelligence.ɵgetApiUrl();
77
77
  const apiKey = intelligence.ɵgetRunnerAuthToken();
78
78
  const projectId = parseProjectIdFromApiKey(apiKey);
@@ -85,6 +85,7 @@ function deriveChannelActivationConfig(args) {
85
85
  channelName,
86
86
  adapter: trimmedProvider ? trimmedProvider : "slack",
87
87
  ...channel.showToolStatus !== void 0 ? { showToolStatus: channel.showToolStatus } : {},
88
+ ...channel.replyContinuation !== void 0 ? { replyContinuation: channel.replyContinuation } : {},
88
89
  runtimeInstanceId
89
90
  };
90
91
  }
@@ -1 +1 @@
1
- {"version":3,"file":"channel-activation-config.cjs","names":[],"sources":["../../../../src/v2/runtime/core/channel-activation-config.ts"],"sourcesContent":["import type { CopilotKitIntelligence } from \"../intelligence-platform\";\n// Type-only: @copilotkit/channels is pure-ESM, so a value import would break this\n// package's CJS output (see `runtime.ts` for the same constraint).\nimport type { Channel } from \"@copilotkit/channels\";\n\n/**\n * Error thrown when a Channel activation config cannot be derived — either the\n * Intelligence API key does not carry a project id in the expected\n * `cpk-{projectId}_...` format, or the {@link Channel} is missing a `name`.\n */\nexport class ChannelConfigError extends Error {\n constructor(message: string) {\n super(message);\n this.name = \"ChannelConfigError\";\n }\n}\n\n/**\n * Resolved configuration needed to activate a single Channel against a\n * running Intelligence runtime instance.\n */\nexport interface ChannelActivationConfig {\n /** Intelligence runner websocket URL the Channel connects to. */\n wsUrl: string;\n /** Intelligence API key used to authenticate the runner connection. */\n apiKey: string;\n /** Intelligence app-api HTTP base URL (`intelligence.ɵgetApiUrl()`), forwarded\n * to the transport so the managed realtime path enables file/history parity\n * (those are HTTP-only). Without it, Channels started by the normal runtime\n * handler run with no history and no file support (OSS-476). */\n apiUrl: string;\n /** Project id parsed from {@link apiKey}. */\n projectId: number;\n /** The Channel's declared name (`createChannel({ name })`). */\n channelName: string;\n /**\n * The managed provider this Channel declares to the Intelligence gateway on\n * join, resolved from the Channel's per-Channel `provider` (e.g. `\"slack\"` or\n * `\"teams\"`), defaulting to `\"slack\"`. Named `adapter` because that is the\n * field the gateway's join payload expects; the gateway resolves the actual\n * connection for the declared provider.\n */\n adapter: string;\n /**\n * Optional per-Channel override for visible managed tool-call progress.\n * Unset Slack routes default to hidden; other providers retain their existing\n * default.\n */\n showToolStatus?: boolean;\n /** Identifier for the runtime instance activating this Channel. */\n runtimeInstanceId: string;\n}\n\n/** Matches the `cpk-{projectId}_...` Intelligence API key format. */\nconst API_KEY_PROJECT_ID_PATTERN = /^cpk-(\\d+)_/;\n\n/**\n * Parse the project id embedded in an Intelligence API key.\n *\n * Intelligence API keys are formatted `cpk-{projectId}_{rest}` — this\n * extracts and numerically parses the `{projectId}` segment.\n *\n * @param apiKey - The Intelligence API key to parse.\n * @returns The parsed, strictly-positive, safe-integer project id.\n * @throws {ChannelConfigError} If `apiKey` does not match the expected\n * `cpk-{projectId}_...` format — a wrong/missing prefix or an absent project\n * id segment all fail the same match — or if the parsed project id is not a\n * strictly-positive safe integer.\n */\nexport function parseProjectIdFromApiKey(apiKey: string): number {\n const match = API_KEY_PROJECT_ID_PATTERN.exec(apiKey);\n if (!match) {\n // The whole API key is a `cpk-…` secret — everything after the fixed `cpk-`\n // namespace is sensitive, so a fixed-width slice (e.g. `apiKey.slice(0, 8)`)\n // would echo secret bytes for a `cpk-_short_long`-shaped key. This message is\n // logged and surfaced through `ready()`'s AggregateError, so echo NONE of the\n // key value; name only the expected format to aid diagnosis.\n throw new ChannelConfigError(\n `Could not parse a project id from the Intelligence API key — expected the ` +\n `\"cpk-{projectId}_...\" format (the key value is omitted here to avoid ` +\n `leaking secret material).`,\n );\n }\n const projectId = Number(match[1]);\n // Validate the parser's OWN output: `cpk-0_...` matches the pattern but a\n // non-positive project id would otherwise fail deep inside the launcher's\n // `assertValidChannelRealtimeScope` (which requires a positive projectId).\n // A very long digit run also matches `\\d+` but loses precision (or overflows\n // to Infinity) once coerced to `Number`, so it must be rejected too even\n // though it is `> 0` — `Number.isSafeInteger` catches both. This is the\n // parser guarding its own contract, not a channel-name replica, so it\n // belongs here. Reuse the same redaction: never echo the key value.\n if (!Number.isSafeInteger(projectId) || projectId <= 0) {\n throw new ChannelConfigError(\n `Parsed an invalid project id (${projectId}) from the Intelligence API ` +\n `key — the project id in \"cpk-{projectId}_...\" must be a positive safe ` +\n `integer (the key value is omitted here to avoid leaking secret material).`,\n );\n }\n return projectId;\n}\n\n/**\n * Derive the {@link ChannelActivationConfig} needed to activate `channel`\n * against the given Intelligence runtime configuration.\n *\n * @param args.intelligence - The Intelligence runtime client to pull the\n * runner websocket URL and auth token from.\n * @param args.channel - The Channel being activated. Must have a `name`; its\n * per-Channel `provider` selects the managed adapter declared to the gateway,\n * and `showToolStatus` optionally overrides managed tool-call visibility.\n * @param args.runtimeInstanceId - Identifier for the activating runtime\n * instance, passed through unchanged.\n * @returns The resolved {@link ChannelActivationConfig}.\n * @throws {ChannelConfigError} If the Intelligence API key does not carry a\n * parseable, strictly-positive project id, or if `channel.name` is\n * missing/empty.\n *\n * The managed provider is a PER-CHANNEL choice read from `channel.provider`, so\n * one runtime can activate a Slack-backed Channel and a Teams-backed Channel\n * side by side. When `channel.provider` is unset the config adapter defaults to\n * `\"slack\"` — an explicit, documented default, not a silent global. The SDK\n * only DECLARES this provider to the Intelligence gateway on join; the gateway\n * resolves the actual connection and is the authority on which providers it\n * accepts (it accepts only `\"slack\"` today — Teams gateway support is tracked\n * in OSS-450).\n *\n * The Channel-name FORMAT rules (lowercase kebab-case, 3–64 chars) and the\n * reserved-name rule are NOT re-checked here. Their single source of truth is\n * the `@copilotkit/channels-intelligence` launcher\n * (`assertValidChannelRealtimeScope` + `assertValidChannelNames`), which\n * validates them at activation; a malformed name surfaces as a logged `error`\n * status via {@link ChannelManager.ready} rather than an up-front throw. An\n * empty/missing name is still rejected here because that is this config's own\n * precondition (it has no name to forward at all), not a downstream replica.\n */\nexport function deriveChannelActivationConfig(args: {\n intelligence: CopilotKitIntelligence;\n channel: Channel;\n runtimeInstanceId: string;\n}): ChannelActivationConfig {\n const { intelligence, channel, runtimeInstanceId } = args;\n\n if (!channel.name) {\n throw new ChannelConfigError(\n \"Channel is missing a `name` — pass createChannel({ name }) to activate it.\",\n );\n }\n\n const channelName = channel.name;\n\n const wsUrl = intelligence.ɵgetRunnerWsUrl();\n const apiUrl = intelligence.ɵgetApiUrl();\n const apiKey = intelligence.ɵgetRunnerAuthToken();\n const projectId = parseProjectIdFromApiKey(apiKey);\n\n // Resolve the managed adapter declared to the gateway from the Channel's OWN\n // `provider` — a per-Channel choice, not a manager-wide default. When\n // `provider` is unset the adapter is the documented default `\"slack\"`; set\n // `createChannel({ provider: \"teams\" })` to declare Teams instead. The value\n // is trimmed so a padded runtime value (one that bypassed the typed union)\n // resolves to its bare provider rather than being forwarded with whitespace,\n // and a blank/whitespace-only provider falls back to `\"slack\"` (`??` alone\n // would keep `\"\"`).\n const trimmedProvider = channel.provider?.trim();\n\n return {\n wsUrl,\n apiUrl,\n apiKey,\n projectId,\n channelName,\n adapter: trimmedProvider ? trimmedProvider : \"slack\",\n ...(channel.showToolStatus !== undefined\n ? { showToolStatus: channel.showToolStatus }\n : {}),\n runtimeInstanceId,\n };\n}\n"],"mappings":";;;;;;;;AAUA,IAAa,qBAAb,cAAwC,MAAM;CAC5C,YAAY,SAAiB;AAC3B,QAAM,QAAQ;AACd,OAAK,OAAO;;;;AAyChB,MAAM,6BAA6B;;;;;;;;;;;;;;AAenC,SAAgB,yBAAyB,QAAwB;CAC/D,MAAM,QAAQ,2BAA2B,KAAK,OAAO;AACrD,KAAI,CAAC,MAMH,OAAM,IAAI,mBACR,6KAGD;CAEH,MAAM,YAAY,OAAO,MAAM,GAAG;AASlC,KAAI,CAAC,OAAO,cAAc,UAAU,IAAI,aAAa,EACnD,OAAM,IAAI,mBACR,iCAAiC,UAAU,6KAG5C;AAEH,QAAO;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAqCT,SAAgB,8BAA8B,MAIlB;CAC1B,MAAM,EAAE,cAAc,SAAS,sBAAsB;AAErD,KAAI,CAAC,QAAQ,KACX,OAAM,IAAI,mBACR,6EACD;CAGH,MAAM,cAAc,QAAQ;CAE5B,MAAM,QAAQ,aAAa,iBAAiB;CAC5C,MAAM,SAAS,aAAa,YAAY;CACxC,MAAM,SAAS,aAAa,qBAAqB;CACjD,MAAM,YAAY,yBAAyB,OAAO;CAUlD,MAAM,kBAAkB,QAAQ,UAAU,MAAM;AAEhD,QAAO;EACL;EACA;EACA;EACA;EACA;EACA,SAAS,kBAAkB,kBAAkB;EAC7C,GAAI,QAAQ,mBAAmB,SAC3B,EAAE,gBAAgB,QAAQ,gBAAgB,GAC1C,EAAE;EACN;EACD"}
1
+ {"version":3,"file":"channel-activation-config.cjs","names":[],"sources":["../../../../src/v2/runtime/core/channel-activation-config.ts"],"sourcesContent":["import type { CopilotKitIntelligence } from \"../intelligence-platform\";\n// Type-only: @copilotkit/channels is pure-ESM, so a value import would break this\n// package's CJS output (see `runtime.ts` for the same constraint).\nimport type { Channel, ReplyContinuationOptions } from \"@copilotkit/channels\";\n\n/**\n * Error thrown when a Channel activation config cannot be derived — either the\n * Intelligence API key does not carry a project id in the expected\n * `cpk-{projectId}_...` format, or the {@link Channel} is missing a `name`.\n */\nexport class ChannelConfigError extends Error {\n constructor(message: string) {\n super(message);\n this.name = \"ChannelConfigError\";\n }\n}\n\n/**\n * Resolved configuration needed to activate a single Channel against a\n * running Intelligence runtime instance.\n */\nexport interface ChannelActivationConfig {\n /** Intelligence runner websocket URL the Channel connects to. */\n wsUrl: string;\n /** Intelligence API key used to authenticate the runner connection. */\n apiKey: string;\n /** Intelligence app-api HTTP base URL (`intelligence.ɵgetApiUrl()`), forwarded\n * to the transport so the managed realtime path enables file/history parity\n * (those are HTTP-only). Without it, Channels started by the normal runtime\n * handler run with no history and no file support (OSS-476). */\n apiUrl: string;\n /** Project id parsed from {@link apiKey}. */\n projectId: number;\n /** The Channel's declared name (`createChannel({ name })`). */\n channelName: string;\n /**\n * The managed provider this Channel declares to the Intelligence gateway on\n * join, resolved from the Channel's per-Channel `provider` (e.g. `\"slack\"` or\n * `\"teams\"`), defaulting to `\"slack\"`. Named `adapter` because that is the\n * field the gateway's join payload expects; the gateway resolves the actual\n * connection for the declared provider.\n */\n adapter: string;\n /**\n * Optional per-Channel override for visible managed tool-call progress.\n * Unset Slack routes default to hidden; other providers retain their existing\n * default.\n */\n showToolStatus?: boolean;\n /**\n * Optional per-Channel tuning for splitting a long reply across continuation\n * messages. Unset leaves the provider renderer's defaults in place.\n */\n replyContinuation?: ReplyContinuationOptions;\n /** Identifier for the runtime instance activating this Channel. */\n runtimeInstanceId: string;\n}\n\n/** Matches the `cpk-{projectId}_...` Intelligence API key format. */\nconst API_KEY_PROJECT_ID_PATTERN = /^cpk-(\\d+)_/;\n\n/**\n * Parse the project id embedded in an Intelligence API key.\n *\n * Intelligence API keys are formatted `cpk-{projectId}_{rest}` — this\n * extracts and numerically parses the `{projectId}` segment.\n *\n * @param apiKey - The Intelligence API key to parse.\n * @returns The parsed, strictly-positive, safe-integer project id.\n * @throws {ChannelConfigError} If `apiKey` does not match the expected\n * `cpk-{projectId}_...` format — a wrong/missing prefix or an absent project\n * id segment all fail the same match — or if the parsed project id is not a\n * strictly-positive safe integer.\n */\nexport function parseProjectIdFromApiKey(apiKey: string): number {\n const match = API_KEY_PROJECT_ID_PATTERN.exec(apiKey);\n if (!match) {\n // The whole API key is a `cpk-…` secret — everything after the fixed `cpk-`\n // namespace is sensitive, so a fixed-width slice (e.g. `apiKey.slice(0, 8)`)\n // would echo secret bytes for a `cpk-_short_long`-shaped key. This message is\n // logged and surfaced through `ready()`'s AggregateError, so echo NONE of the\n // key value; name only the expected format to aid diagnosis.\n throw new ChannelConfigError(\n `Could not parse a project id from the Intelligence API key — expected the ` +\n `\"cpk-{projectId}_...\" format (the key value is omitted here to avoid ` +\n `leaking secret material).`,\n );\n }\n const projectId = Number(match[1]);\n // Validate the parser's OWN output: `cpk-0_...` matches the pattern but a\n // non-positive project id would otherwise fail deep inside the launcher's\n // `assertValidChannelRealtimeScope` (which requires a positive projectId).\n // A very long digit run also matches `\\d+` but loses precision (or overflows\n // to Infinity) once coerced to `Number`, so it must be rejected too even\n // though it is `> 0` — `Number.isSafeInteger` catches both. This is the\n // parser guarding its own contract, not a channel-name replica, so it\n // belongs here. Reuse the same redaction: never echo the key value.\n if (!Number.isSafeInteger(projectId) || projectId <= 0) {\n throw new ChannelConfigError(\n `Parsed an invalid project id (${projectId}) from the Intelligence API ` +\n `key — the project id in \"cpk-{projectId}_...\" must be a positive safe ` +\n `integer (the key value is omitted here to avoid leaking secret material).`,\n );\n }\n return projectId;\n}\n\n/**\n * Derive the {@link ChannelActivationConfig} needed to activate `channel`\n * against the given Intelligence runtime configuration.\n *\n * @param args.intelligence - The Intelligence runtime client to pull the\n * runner websocket URL and auth token from.\n * @param args.channel - The Channel being activated. Must have a `name`; its\n * per-Channel `provider` selects the managed adapter declared to the gateway,\n * and `showToolStatus` optionally overrides managed tool-call visibility.\n * @param args.runtimeInstanceId - Identifier for the activating runtime\n * instance, passed through unchanged.\n * @returns The resolved {@link ChannelActivationConfig}.\n * @throws {ChannelConfigError} If the Intelligence API key does not carry a\n * parseable, strictly-positive project id, or if `channel.name` is\n * missing/empty.\n *\n * The managed provider is a PER-CHANNEL choice read from `channel.provider`, so\n * one runtime can activate a Slack-backed Channel and a Teams-backed Channel\n * side by side. When `channel.provider` is unset the config adapter defaults to\n * `\"slack\"` — an explicit, documented default, not a silent global. The SDK\n * only DECLARES this provider to the Intelligence gateway on join; the gateway\n * resolves the actual connection and is the authority on which providers it\n * accepts (it accepts only `\"slack\"` today — Teams gateway support is tracked\n * in OSS-450).\n *\n * The Channel-name FORMAT rules (lowercase kebab-case, 3–64 chars) and the\n * reserved-name rule are NOT re-checked here. Their single source of truth is\n * the `@copilotkit/channels-intelligence` launcher\n * (`assertValidChannelRealtimeScope` + `assertValidChannelNames`), which\n * validates them at activation; a malformed name surfaces as a logged `error`\n * status via {@link ChannelManager.ready} rather than an up-front throw. An\n * empty/missing name is still rejected here because that is this config's own\n * precondition (it has no name to forward at all), not a downstream replica.\n */\nexport function deriveChannelActivationConfig(args: {\n intelligence: CopilotKitIntelligence;\n channel: Channel;\n runtimeInstanceId: string;\n}): ChannelActivationConfig {\n const { intelligence, channel, runtimeInstanceId } = args;\n\n if (!channel.name) {\n throw new ChannelConfigError(\n \"Channel is missing a `name` — pass createChannel({ name }) to activate it.\",\n );\n }\n\n const channelName = channel.name;\n\n const wsUrl = intelligence.ɵgetChannelsWsUrl();\n const apiUrl = intelligence.ɵgetApiUrl();\n const apiKey = intelligence.ɵgetRunnerAuthToken();\n const projectId = parseProjectIdFromApiKey(apiKey);\n\n // Resolve the managed adapter declared to the gateway from the Channel's OWN\n // `provider` — a per-Channel choice, not a manager-wide default. When\n // `provider` is unset the adapter is the documented default `\"slack\"`; set\n // `createChannel({ provider: \"teams\" })` to declare Teams instead. The value\n // is trimmed so a padded runtime value (one that bypassed the typed union)\n // resolves to its bare provider rather than being forwarded with whitespace,\n // and a blank/whitespace-only provider falls back to `\"slack\"` (`??` alone\n // would keep `\"\"`).\n const trimmedProvider = channel.provider?.trim();\n\n return {\n wsUrl,\n apiUrl,\n apiKey,\n projectId,\n channelName,\n adapter: trimmedProvider ? trimmedProvider : \"slack\",\n ...(channel.showToolStatus !== undefined\n ? { showToolStatus: channel.showToolStatus }\n : {}),\n ...(channel.replyContinuation !== undefined\n ? { replyContinuation: channel.replyContinuation }\n : {}),\n runtimeInstanceId,\n };\n}\n"],"mappings":";;;;;;;;AAUA,IAAa,qBAAb,cAAwC,MAAM;CAC5C,YAAY,SAAiB;AAC3B,QAAM,QAAQ;AACd,OAAK,OAAO;;;;AA8ChB,MAAM,6BAA6B;;;;;;;;;;;;;;AAenC,SAAgB,yBAAyB,QAAwB;CAC/D,MAAM,QAAQ,2BAA2B,KAAK,OAAO;AACrD,KAAI,CAAC,MAMH,OAAM,IAAI,mBACR,6KAGD;CAEH,MAAM,YAAY,OAAO,MAAM,GAAG;AASlC,KAAI,CAAC,OAAO,cAAc,UAAU,IAAI,aAAa,EACnD,OAAM,IAAI,mBACR,iCAAiC,UAAU,6KAG5C;AAEH,QAAO;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAqCT,SAAgB,8BAA8B,MAIlB;CAC1B,MAAM,EAAE,cAAc,SAAS,sBAAsB;AAErD,KAAI,CAAC,QAAQ,KACX,OAAM,IAAI,mBACR,6EACD;CAGH,MAAM,cAAc,QAAQ;CAE5B,MAAM,QAAQ,aAAa,mBAAmB;CAC9C,MAAM,SAAS,aAAa,YAAY;CACxC,MAAM,SAAS,aAAa,qBAAqB;CACjD,MAAM,YAAY,yBAAyB,OAAO;CAUlD,MAAM,kBAAkB,QAAQ,UAAU,MAAM;AAEhD,QAAO;EACL;EACA;EACA;EACA;EACA;EACA,SAAS,kBAAkB,kBAAkB;EAC7C,GAAI,QAAQ,mBAAmB,SAC3B,EAAE,gBAAgB,QAAQ,gBAAgB,GAC1C,EAAE;EACN,GAAI,QAAQ,sBAAsB,SAC9B,EAAE,mBAAmB,QAAQ,mBAAmB,GAChD,EAAE;EACN;EACD"}
@@ -1,4 +1,6 @@
1
1
  require("reflect-metadata");
2
+ import { index_d_exports } from "../../../channels/dist/index.cjs";
3
+
2
4
  //#region src/v2/runtime/core/channel-activation-config.d.ts
3
5
  /**
4
6
  * Resolved configuration needed to activate a single Channel against a
@@ -32,6 +34,11 @@ interface ChannelActivationConfig {
32
34
  * default.
33
35
  */
34
36
  showToolStatus?: boolean;
37
+ /**
38
+ * Optional per-Channel tuning for splitting a long reply across continuation
39
+ * messages. Unset leaves the provider renderer's defaults in place.
40
+ */
41
+ replyContinuation?: index_d_exports.ReplyContinuationOptions;
35
42
  /** Identifier for the runtime instance activating this Channel. */
36
43
  runtimeInstanceId: string;
37
44
  }
@@ -1 +1 @@
1
- {"version":3,"file":"channel-activation-config.d.cts","names":[],"sources":["../../../../src/v2/runtime/core/channel-activation-config.ts"],"mappings":";;;;;;UAqBiB,uBAAA;;EAEf,KAAA;;EAEA,MAAA;;;;;EAKA,MAAA;;EAEA,SAAA;;EAEA,WAAA;;;;;;;;EAQA,OAAA;;;;;;EAMA,cAAA;;EAEA,iBAAA;AAAA"}
1
+ {"version":3,"file":"channel-activation-config.d.cts","names":[],"sources":["../../../../src/v2/runtime/core/channel-activation-config.ts"],"mappings":";;;;;;;;UAqBiB,uBAAA;EAgCK;EA9BpB,KAAA;EAgCiB;EA9BjB,MAAA;;;;;EAKA,MAAA;;EAEA,SAAA;;EAEA,WAAA;;;;;;;;EAQA,OAAA;;;;;;EAMA,cAAA;;;;;EAKA,iBAAA,GAAoB,eAAA,CAAA,wBAAA;;EAEpB,iBAAA;AAAA"}
@@ -1,4 +1,6 @@
1
1
  import "reflect-metadata";
2
+ import { index_d_exports } from "../../../channels/dist/index.mjs";
3
+
2
4
  //#region src/v2/runtime/core/channel-activation-config.d.ts
3
5
  /**
4
6
  * Resolved configuration needed to activate a single Channel against a
@@ -32,6 +34,11 @@ interface ChannelActivationConfig {
32
34
  * default.
33
35
  */
34
36
  showToolStatus?: boolean;
37
+ /**
38
+ * Optional per-Channel tuning for splitting a long reply across continuation
39
+ * messages. Unset leaves the provider renderer's defaults in place.
40
+ */
41
+ replyContinuation?: index_d_exports.ReplyContinuationOptions;
35
42
  /** Identifier for the runtime instance activating this Channel. */
36
43
  runtimeInstanceId: string;
37
44
  }
@@ -1 +1 @@
1
- {"version":3,"file":"channel-activation-config.d.mts","names":[],"sources":["../../../../src/v2/runtime/core/channel-activation-config.ts"],"mappings":";;;;;;UAqBiB,uBAAA;;EAEf,KAAA;;EAEA,MAAA;;;;;EAKA,MAAA;;EAEA,SAAA;;EAEA,WAAA;;;;;;;;EAQA,OAAA;;;;;;EAMA,cAAA;;EAEA,iBAAA;AAAA"}
1
+ {"version":3,"file":"channel-activation-config.d.mts","names":[],"sources":["../../../../src/v2/runtime/core/channel-activation-config.ts"],"mappings":";;;;;;;;UAqBiB,uBAAA;EAgCK;EA9BpB,KAAA;EAgCiB;EA9BjB,MAAA;;;;;EAKA,MAAA;;EAEA,SAAA;;EAEA,WAAA;;;;;;;;EAQA,OAAA;;;;;;EAMA,cAAA;;;;;EAKA,iBAAA,GAAoB,eAAA,CAAA,wBAAA;;EAEpB,iBAAA;AAAA"}
@@ -71,7 +71,7 @@ function deriveChannelActivationConfig(args) {
71
71
  const { intelligence, channel, runtimeInstanceId } = args;
72
72
  if (!channel.name) throw new ChannelConfigError("Channel is missing a `name` — pass createChannel({ name }) to activate it.");
73
73
  const channelName = channel.name;
74
- const wsUrl = intelligence.ɵgetRunnerWsUrl();
74
+ const wsUrl = intelligence.ɵgetChannelsWsUrl();
75
75
  const apiUrl = intelligence.ɵgetApiUrl();
76
76
  const apiKey = intelligence.ɵgetRunnerAuthToken();
77
77
  const projectId = parseProjectIdFromApiKey(apiKey);
@@ -84,6 +84,7 @@ function deriveChannelActivationConfig(args) {
84
84
  channelName,
85
85
  adapter: trimmedProvider ? trimmedProvider : "slack",
86
86
  ...channel.showToolStatus !== void 0 ? { showToolStatus: channel.showToolStatus } : {},
87
+ ...channel.replyContinuation !== void 0 ? { replyContinuation: channel.replyContinuation } : {},
87
88
  runtimeInstanceId
88
89
  };
89
90
  }
@@ -1 +1 @@
1
- {"version":3,"file":"channel-activation-config.mjs","names":[],"sources":["../../../../src/v2/runtime/core/channel-activation-config.ts"],"sourcesContent":["import type { CopilotKitIntelligence } from \"../intelligence-platform\";\n// Type-only: @copilotkit/channels is pure-ESM, so a value import would break this\n// package's CJS output (see `runtime.ts` for the same constraint).\nimport type { Channel } from \"@copilotkit/channels\";\n\n/**\n * Error thrown when a Channel activation config cannot be derived — either the\n * Intelligence API key does not carry a project id in the expected\n * `cpk-{projectId}_...` format, or the {@link Channel} is missing a `name`.\n */\nexport class ChannelConfigError extends Error {\n constructor(message: string) {\n super(message);\n this.name = \"ChannelConfigError\";\n }\n}\n\n/**\n * Resolved configuration needed to activate a single Channel against a\n * running Intelligence runtime instance.\n */\nexport interface ChannelActivationConfig {\n /** Intelligence runner websocket URL the Channel connects to. */\n wsUrl: string;\n /** Intelligence API key used to authenticate the runner connection. */\n apiKey: string;\n /** Intelligence app-api HTTP base URL (`intelligence.ɵgetApiUrl()`), forwarded\n * to the transport so the managed realtime path enables file/history parity\n * (those are HTTP-only). Without it, Channels started by the normal runtime\n * handler run with no history and no file support (OSS-476). */\n apiUrl: string;\n /** Project id parsed from {@link apiKey}. */\n projectId: number;\n /** The Channel's declared name (`createChannel({ name })`). */\n channelName: string;\n /**\n * The managed provider this Channel declares to the Intelligence gateway on\n * join, resolved from the Channel's per-Channel `provider` (e.g. `\"slack\"` or\n * `\"teams\"`), defaulting to `\"slack\"`. Named `adapter` because that is the\n * field the gateway's join payload expects; the gateway resolves the actual\n * connection for the declared provider.\n */\n adapter: string;\n /**\n * Optional per-Channel override for visible managed tool-call progress.\n * Unset Slack routes default to hidden; other providers retain their existing\n * default.\n */\n showToolStatus?: boolean;\n /** Identifier for the runtime instance activating this Channel. */\n runtimeInstanceId: string;\n}\n\n/** Matches the `cpk-{projectId}_...` Intelligence API key format. */\nconst API_KEY_PROJECT_ID_PATTERN = /^cpk-(\\d+)_/;\n\n/**\n * Parse the project id embedded in an Intelligence API key.\n *\n * Intelligence API keys are formatted `cpk-{projectId}_{rest}` — this\n * extracts and numerically parses the `{projectId}` segment.\n *\n * @param apiKey - The Intelligence API key to parse.\n * @returns The parsed, strictly-positive, safe-integer project id.\n * @throws {ChannelConfigError} If `apiKey` does not match the expected\n * `cpk-{projectId}_...` format — a wrong/missing prefix or an absent project\n * id segment all fail the same match — or if the parsed project id is not a\n * strictly-positive safe integer.\n */\nexport function parseProjectIdFromApiKey(apiKey: string): number {\n const match = API_KEY_PROJECT_ID_PATTERN.exec(apiKey);\n if (!match) {\n // The whole API key is a `cpk-…` secret — everything after the fixed `cpk-`\n // namespace is sensitive, so a fixed-width slice (e.g. `apiKey.slice(0, 8)`)\n // would echo secret bytes for a `cpk-_short_long`-shaped key. This message is\n // logged and surfaced through `ready()`'s AggregateError, so echo NONE of the\n // key value; name only the expected format to aid diagnosis.\n throw new ChannelConfigError(\n `Could not parse a project id from the Intelligence API key — expected the ` +\n `\"cpk-{projectId}_...\" format (the key value is omitted here to avoid ` +\n `leaking secret material).`,\n );\n }\n const projectId = Number(match[1]);\n // Validate the parser's OWN output: `cpk-0_...` matches the pattern but a\n // non-positive project id would otherwise fail deep inside the launcher's\n // `assertValidChannelRealtimeScope` (which requires a positive projectId).\n // A very long digit run also matches `\\d+` but loses precision (or overflows\n // to Infinity) once coerced to `Number`, so it must be rejected too even\n // though it is `> 0` — `Number.isSafeInteger` catches both. This is the\n // parser guarding its own contract, not a channel-name replica, so it\n // belongs here. Reuse the same redaction: never echo the key value.\n if (!Number.isSafeInteger(projectId) || projectId <= 0) {\n throw new ChannelConfigError(\n `Parsed an invalid project id (${projectId}) from the Intelligence API ` +\n `key — the project id in \"cpk-{projectId}_...\" must be a positive safe ` +\n `integer (the key value is omitted here to avoid leaking secret material).`,\n );\n }\n return projectId;\n}\n\n/**\n * Derive the {@link ChannelActivationConfig} needed to activate `channel`\n * against the given Intelligence runtime configuration.\n *\n * @param args.intelligence - The Intelligence runtime client to pull the\n * runner websocket URL and auth token from.\n * @param args.channel - The Channel being activated. Must have a `name`; its\n * per-Channel `provider` selects the managed adapter declared to the gateway,\n * and `showToolStatus` optionally overrides managed tool-call visibility.\n * @param args.runtimeInstanceId - Identifier for the activating runtime\n * instance, passed through unchanged.\n * @returns The resolved {@link ChannelActivationConfig}.\n * @throws {ChannelConfigError} If the Intelligence API key does not carry a\n * parseable, strictly-positive project id, or if `channel.name` is\n * missing/empty.\n *\n * The managed provider is a PER-CHANNEL choice read from `channel.provider`, so\n * one runtime can activate a Slack-backed Channel and a Teams-backed Channel\n * side by side. When `channel.provider` is unset the config adapter defaults to\n * `\"slack\"` — an explicit, documented default, not a silent global. The SDK\n * only DECLARES this provider to the Intelligence gateway on join; the gateway\n * resolves the actual connection and is the authority on which providers it\n * accepts (it accepts only `\"slack\"` today — Teams gateway support is tracked\n * in OSS-450).\n *\n * The Channel-name FORMAT rules (lowercase kebab-case, 3–64 chars) and the\n * reserved-name rule are NOT re-checked here. Their single source of truth is\n * the `@copilotkit/channels-intelligence` launcher\n * (`assertValidChannelRealtimeScope` + `assertValidChannelNames`), which\n * validates them at activation; a malformed name surfaces as a logged `error`\n * status via {@link ChannelManager.ready} rather than an up-front throw. An\n * empty/missing name is still rejected here because that is this config's own\n * precondition (it has no name to forward at all), not a downstream replica.\n */\nexport function deriveChannelActivationConfig(args: {\n intelligence: CopilotKitIntelligence;\n channel: Channel;\n runtimeInstanceId: string;\n}): ChannelActivationConfig {\n const { intelligence, channel, runtimeInstanceId } = args;\n\n if (!channel.name) {\n throw new ChannelConfigError(\n \"Channel is missing a `name` — pass createChannel({ name }) to activate it.\",\n );\n }\n\n const channelName = channel.name;\n\n const wsUrl = intelligence.ɵgetRunnerWsUrl();\n const apiUrl = intelligence.ɵgetApiUrl();\n const apiKey = intelligence.ɵgetRunnerAuthToken();\n const projectId = parseProjectIdFromApiKey(apiKey);\n\n // Resolve the managed adapter declared to the gateway from the Channel's OWN\n // `provider` — a per-Channel choice, not a manager-wide default. When\n // `provider` is unset the adapter is the documented default `\"slack\"`; set\n // `createChannel({ provider: \"teams\" })` to declare Teams instead. The value\n // is trimmed so a padded runtime value (one that bypassed the typed union)\n // resolves to its bare provider rather than being forwarded with whitespace,\n // and a blank/whitespace-only provider falls back to `\"slack\"` (`??` alone\n // would keep `\"\"`).\n const trimmedProvider = channel.provider?.trim();\n\n return {\n wsUrl,\n apiUrl,\n apiKey,\n projectId,\n channelName,\n adapter: trimmedProvider ? trimmedProvider : \"slack\",\n ...(channel.showToolStatus !== undefined\n ? { showToolStatus: channel.showToolStatus }\n : {}),\n runtimeInstanceId,\n };\n}\n"],"mappings":";;;;;;;AAUA,IAAa,qBAAb,cAAwC,MAAM;CAC5C,YAAY,SAAiB;AAC3B,QAAM,QAAQ;AACd,OAAK,OAAO;;;;AAyChB,MAAM,6BAA6B;;;;;;;;;;;;;;AAenC,SAAgB,yBAAyB,QAAwB;CAC/D,MAAM,QAAQ,2BAA2B,KAAK,OAAO;AACrD,KAAI,CAAC,MAMH,OAAM,IAAI,mBACR,6KAGD;CAEH,MAAM,YAAY,OAAO,MAAM,GAAG;AASlC,KAAI,CAAC,OAAO,cAAc,UAAU,IAAI,aAAa,EACnD,OAAM,IAAI,mBACR,iCAAiC,UAAU,6KAG5C;AAEH,QAAO;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAqCT,SAAgB,8BAA8B,MAIlB;CAC1B,MAAM,EAAE,cAAc,SAAS,sBAAsB;AAErD,KAAI,CAAC,QAAQ,KACX,OAAM,IAAI,mBACR,6EACD;CAGH,MAAM,cAAc,QAAQ;CAE5B,MAAM,QAAQ,aAAa,iBAAiB;CAC5C,MAAM,SAAS,aAAa,YAAY;CACxC,MAAM,SAAS,aAAa,qBAAqB;CACjD,MAAM,YAAY,yBAAyB,OAAO;CAUlD,MAAM,kBAAkB,QAAQ,UAAU,MAAM;AAEhD,QAAO;EACL;EACA;EACA;EACA;EACA;EACA,SAAS,kBAAkB,kBAAkB;EAC7C,GAAI,QAAQ,mBAAmB,SAC3B,EAAE,gBAAgB,QAAQ,gBAAgB,GAC1C,EAAE;EACN;EACD"}
1
+ {"version":3,"file":"channel-activation-config.mjs","names":[],"sources":["../../../../src/v2/runtime/core/channel-activation-config.ts"],"sourcesContent":["import type { CopilotKitIntelligence } from \"../intelligence-platform\";\n// Type-only: @copilotkit/channels is pure-ESM, so a value import would break this\n// package's CJS output (see `runtime.ts` for the same constraint).\nimport type { Channel, ReplyContinuationOptions } from \"@copilotkit/channels\";\n\n/**\n * Error thrown when a Channel activation config cannot be derived — either the\n * Intelligence API key does not carry a project id in the expected\n * `cpk-{projectId}_...` format, or the {@link Channel} is missing a `name`.\n */\nexport class ChannelConfigError extends Error {\n constructor(message: string) {\n super(message);\n this.name = \"ChannelConfigError\";\n }\n}\n\n/**\n * Resolved configuration needed to activate a single Channel against a\n * running Intelligence runtime instance.\n */\nexport interface ChannelActivationConfig {\n /** Intelligence runner websocket URL the Channel connects to. */\n wsUrl: string;\n /** Intelligence API key used to authenticate the runner connection. */\n apiKey: string;\n /** Intelligence app-api HTTP base URL (`intelligence.ɵgetApiUrl()`), forwarded\n * to the transport so the managed realtime path enables file/history parity\n * (those are HTTP-only). Without it, Channels started by the normal runtime\n * handler run with no history and no file support (OSS-476). */\n apiUrl: string;\n /** Project id parsed from {@link apiKey}. */\n projectId: number;\n /** The Channel's declared name (`createChannel({ name })`). */\n channelName: string;\n /**\n * The managed provider this Channel declares to the Intelligence gateway on\n * join, resolved from the Channel's per-Channel `provider` (e.g. `\"slack\"` or\n * `\"teams\"`), defaulting to `\"slack\"`. Named `adapter` because that is the\n * field the gateway's join payload expects; the gateway resolves the actual\n * connection for the declared provider.\n */\n adapter: string;\n /**\n * Optional per-Channel override for visible managed tool-call progress.\n * Unset Slack routes default to hidden; other providers retain their existing\n * default.\n */\n showToolStatus?: boolean;\n /**\n * Optional per-Channel tuning for splitting a long reply across continuation\n * messages. Unset leaves the provider renderer's defaults in place.\n */\n replyContinuation?: ReplyContinuationOptions;\n /** Identifier for the runtime instance activating this Channel. */\n runtimeInstanceId: string;\n}\n\n/** Matches the `cpk-{projectId}_...` Intelligence API key format. */\nconst API_KEY_PROJECT_ID_PATTERN = /^cpk-(\\d+)_/;\n\n/**\n * Parse the project id embedded in an Intelligence API key.\n *\n * Intelligence API keys are formatted `cpk-{projectId}_{rest}` — this\n * extracts and numerically parses the `{projectId}` segment.\n *\n * @param apiKey - The Intelligence API key to parse.\n * @returns The parsed, strictly-positive, safe-integer project id.\n * @throws {ChannelConfigError} If `apiKey` does not match the expected\n * `cpk-{projectId}_...` format — a wrong/missing prefix or an absent project\n * id segment all fail the same match — or if the parsed project id is not a\n * strictly-positive safe integer.\n */\nexport function parseProjectIdFromApiKey(apiKey: string): number {\n const match = API_KEY_PROJECT_ID_PATTERN.exec(apiKey);\n if (!match) {\n // The whole API key is a `cpk-…` secret — everything after the fixed `cpk-`\n // namespace is sensitive, so a fixed-width slice (e.g. `apiKey.slice(0, 8)`)\n // would echo secret bytes for a `cpk-_short_long`-shaped key. This message is\n // logged and surfaced through `ready()`'s AggregateError, so echo NONE of the\n // key value; name only the expected format to aid diagnosis.\n throw new ChannelConfigError(\n `Could not parse a project id from the Intelligence API key — expected the ` +\n `\"cpk-{projectId}_...\" format (the key value is omitted here to avoid ` +\n `leaking secret material).`,\n );\n }\n const projectId = Number(match[1]);\n // Validate the parser's OWN output: `cpk-0_...` matches the pattern but a\n // non-positive project id would otherwise fail deep inside the launcher's\n // `assertValidChannelRealtimeScope` (which requires a positive projectId).\n // A very long digit run also matches `\\d+` but loses precision (or overflows\n // to Infinity) once coerced to `Number`, so it must be rejected too even\n // though it is `> 0` — `Number.isSafeInteger` catches both. This is the\n // parser guarding its own contract, not a channel-name replica, so it\n // belongs here. Reuse the same redaction: never echo the key value.\n if (!Number.isSafeInteger(projectId) || projectId <= 0) {\n throw new ChannelConfigError(\n `Parsed an invalid project id (${projectId}) from the Intelligence API ` +\n `key — the project id in \"cpk-{projectId}_...\" must be a positive safe ` +\n `integer (the key value is omitted here to avoid leaking secret material).`,\n );\n }\n return projectId;\n}\n\n/**\n * Derive the {@link ChannelActivationConfig} needed to activate `channel`\n * against the given Intelligence runtime configuration.\n *\n * @param args.intelligence - The Intelligence runtime client to pull the\n * runner websocket URL and auth token from.\n * @param args.channel - The Channel being activated. Must have a `name`; its\n * per-Channel `provider` selects the managed adapter declared to the gateway,\n * and `showToolStatus` optionally overrides managed tool-call visibility.\n * @param args.runtimeInstanceId - Identifier for the activating runtime\n * instance, passed through unchanged.\n * @returns The resolved {@link ChannelActivationConfig}.\n * @throws {ChannelConfigError} If the Intelligence API key does not carry a\n * parseable, strictly-positive project id, or if `channel.name` is\n * missing/empty.\n *\n * The managed provider is a PER-CHANNEL choice read from `channel.provider`, so\n * one runtime can activate a Slack-backed Channel and a Teams-backed Channel\n * side by side. When `channel.provider` is unset the config adapter defaults to\n * `\"slack\"` — an explicit, documented default, not a silent global. The SDK\n * only DECLARES this provider to the Intelligence gateway on join; the gateway\n * resolves the actual connection and is the authority on which providers it\n * accepts (it accepts only `\"slack\"` today — Teams gateway support is tracked\n * in OSS-450).\n *\n * The Channel-name FORMAT rules (lowercase kebab-case, 3–64 chars) and the\n * reserved-name rule are NOT re-checked here. Their single source of truth is\n * the `@copilotkit/channels-intelligence` launcher\n * (`assertValidChannelRealtimeScope` + `assertValidChannelNames`), which\n * validates them at activation; a malformed name surfaces as a logged `error`\n * status via {@link ChannelManager.ready} rather than an up-front throw. An\n * empty/missing name is still rejected here because that is this config's own\n * precondition (it has no name to forward at all), not a downstream replica.\n */\nexport function deriveChannelActivationConfig(args: {\n intelligence: CopilotKitIntelligence;\n channel: Channel;\n runtimeInstanceId: string;\n}): ChannelActivationConfig {\n const { intelligence, channel, runtimeInstanceId } = args;\n\n if (!channel.name) {\n throw new ChannelConfigError(\n \"Channel is missing a `name` — pass createChannel({ name }) to activate it.\",\n );\n }\n\n const channelName = channel.name;\n\n const wsUrl = intelligence.ɵgetChannelsWsUrl();\n const apiUrl = intelligence.ɵgetApiUrl();\n const apiKey = intelligence.ɵgetRunnerAuthToken();\n const projectId = parseProjectIdFromApiKey(apiKey);\n\n // Resolve the managed adapter declared to the gateway from the Channel's OWN\n // `provider` — a per-Channel choice, not a manager-wide default. When\n // `provider` is unset the adapter is the documented default `\"slack\"`; set\n // `createChannel({ provider: \"teams\" })` to declare Teams instead. The value\n // is trimmed so a padded runtime value (one that bypassed the typed union)\n // resolves to its bare provider rather than being forwarded with whitespace,\n // and a blank/whitespace-only provider falls back to `\"slack\"` (`??` alone\n // would keep `\"\"`).\n const trimmedProvider = channel.provider?.trim();\n\n return {\n wsUrl,\n apiUrl,\n apiKey,\n projectId,\n channelName,\n adapter: trimmedProvider ? trimmedProvider : \"slack\",\n ...(channel.showToolStatus !== undefined\n ? { showToolStatus: channel.showToolStatus }\n : {}),\n ...(channel.replyContinuation !== undefined\n ? { replyContinuation: channel.replyContinuation }\n : {}),\n runtimeInstanceId,\n };\n}\n"],"mappings":";;;;;;;AAUA,IAAa,qBAAb,cAAwC,MAAM;CAC5C,YAAY,SAAiB;AAC3B,QAAM,QAAQ;AACd,OAAK,OAAO;;;;AA8ChB,MAAM,6BAA6B;;;;;;;;;;;;;;AAenC,SAAgB,yBAAyB,QAAwB;CAC/D,MAAM,QAAQ,2BAA2B,KAAK,OAAO;AACrD,KAAI,CAAC,MAMH,OAAM,IAAI,mBACR,6KAGD;CAEH,MAAM,YAAY,OAAO,MAAM,GAAG;AASlC,KAAI,CAAC,OAAO,cAAc,UAAU,IAAI,aAAa,EACnD,OAAM,IAAI,mBACR,iCAAiC,UAAU,6KAG5C;AAEH,QAAO;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAqCT,SAAgB,8BAA8B,MAIlB;CAC1B,MAAM,EAAE,cAAc,SAAS,sBAAsB;AAErD,KAAI,CAAC,QAAQ,KACX,OAAM,IAAI,mBACR,6EACD;CAGH,MAAM,cAAc,QAAQ;CAE5B,MAAM,QAAQ,aAAa,mBAAmB;CAC9C,MAAM,SAAS,aAAa,YAAY;CACxC,MAAM,SAAS,aAAa,qBAAqB;CACjD,MAAM,YAAY,yBAAyB,OAAO;CAUlD,MAAM,kBAAkB,QAAQ,UAAU,MAAM;AAEhD,QAAO;EACL;EACA;EACA;EACA;EACA;EACA,SAAS,kBAAkB,kBAAkB;EAC7C,GAAI,QAAQ,mBAAmB,SAC3B,EAAE,gBAAgB,QAAQ,gBAAgB,GAC1C,EAAE;EACN,GAAI,QAAQ,sBAAsB,SAC9B,EAAE,mBAAmB,QAAQ,mBAAmB,GAChD,EAAE;EACN;EACD"}
@@ -1,7 +1,9 @@
1
1
  require("reflect-metadata");
2
2
  const require_runtime = require('../../../_virtual/_rolldown/runtime.cjs');
3
3
  const require_channel_activation_config = require('./channel-activation-config.cjs');
4
+ let rxjs = require("rxjs");
4
5
  let node_crypto = require("node:crypto");
6
+ let _ag_ui_client = require("@ag-ui/client");
5
7
 
6
8
  //#region src/v2/runtime/core/channel-manager.ts
7
9
  /**
@@ -46,7 +48,7 @@ const CHANNELS_INTELLIGENCE_SPECIFIER = "@copilotkit/channels-intelligence";
46
48
  * transport-level drop diagnostics are not silent in the managed path.
47
49
  * @returns The launcher's {@link ChannelsHandle}.
48
50
  */
49
- async function defaultActivateChannel(config, channel, importChannelsIntelligence = () => import(CHANNELS_INTELLIGENCE_SPECIFIER), log) {
51
+ async function defaultActivateChannel(config, channel, importChannelsIntelligence = () => import(CHANNELS_INTELLIGENCE_SPECIFIER), log, services) {
50
52
  let mod;
51
53
  try {
52
54
  mod = await importChannelsIntelligence();
@@ -54,6 +56,7 @@ async function defaultActivateChannel(config, channel, importChannelsIntelligenc
54
56
  if (isModuleNotFound(err)) throw new Error("Managed Channels require '@copilotkit/channels-intelligence' to be installed. Add it to your app's dependencies.", { cause: err });
55
57
  throw err;
56
58
  }
59
+ if (!services) throw new Error("Managed Channels require the runtime AgentRunner and Intelligence client");
57
60
  return mod.startChannelsOverRealtimeGateway([channel], {
58
61
  wsUrl: config.wsUrl,
59
62
  apiKey: config.apiKey,
@@ -64,10 +67,201 @@ async function defaultActivateChannel(config, channel, importChannelsIntelligenc
64
67
  runtimeInstanceId: config.runtimeInstanceId,
65
68
  adapter: config.adapter,
66
69
  ...config.showToolStatus !== void 0 ? { showToolStatus: config.showToolStatus } : {},
70
+ ...config.replyContinuation !== void 0 ? { replyContinuation: config.replyContinuation } : {},
67
71
  appApiBaseUrl: config.apiUrl,
68
- ...log ? { log } : {}
72
+ ...log ? { log } : {},
73
+ runCanonical: (args) => runCanonicalChannelAgent(services.runner, services.intelligence, services.lockTtlSeconds ?? 20, services.lockHeartbeatIntervalSeconds ?? 15, args, services.lockKeyPrefix),
74
+ loadHistory: async ({ deliveryId, threadId, appUserId }) => {
75
+ const history = await services.intelligence.getThreadMessages({
76
+ threadId,
77
+ userId: appUserId,
78
+ channelDeliveryId: deliveryId
79
+ });
80
+ return Promise.all(history.messages.map((message) => toAgentMessage(message, services.intelligence)));
81
+ }
69
82
  });
70
83
  }
84
+ /** One outer agent that lets the standard runner own the whole local tool loop. */
85
+ var ChannelOuterAgent = class extends _ag_ui_client.AbstractAgent {
86
+ constructor(inner, canonicalThreadId, executeLoop) {
87
+ super({
88
+ threadId: inner.threadId,
89
+ initialMessages: inner.messages,
90
+ initialState: inner.state,
91
+ ...inner.agentId ? { agentId: inner.agentId } : {}
92
+ });
93
+ this.inner = inner;
94
+ this.canonicalThreadId = canonicalThreadId;
95
+ this.executeLoop = executeLoop;
96
+ }
97
+ run() {
98
+ return rxjs.EMPTY;
99
+ }
100
+ async runAgent(parameters, subscriber) {
101
+ if (!parameters?.runId) throw new Error("Canonical Channel run requires a runId");
102
+ return {
103
+ result: await this.executeLoop(subscriber ?? {}, {
104
+ threadId: this.canonicalThreadId,
105
+ runId: parameters.runId
106
+ }),
107
+ newMessages: []
108
+ };
109
+ }
110
+ abortRun() {
111
+ this.inner.abortRun();
112
+ }
113
+ };
114
+ /** Drive one public Channel run through the runtime's existing AgentRunner. */
115
+ async function runCanonicalChannelAgent(runner, intelligence, lockTtlSeconds, lockHeartbeatIntervalSeconds, args, lockKeyPrefix) {
116
+ const lock = await intelligence.ɵacquireThreadLock({
117
+ threadId: args.threadId,
118
+ runId: args.runId,
119
+ userId: args.userId,
120
+ agentId: args.agentId,
121
+ channelDeliveryId: args.deliveryId,
122
+ ttlSeconds: lockTtlSeconds,
123
+ ...lockKeyPrefix !== void 0 ? { lockKeyPrefix } : {}
124
+ });
125
+ const canonicalThreadId = lock.threadId;
126
+ const canonicalRunId = lock.runId;
127
+ let result = {
128
+ iterations: 0,
129
+ interrupted: false
130
+ };
131
+ const outer = new ChannelOuterAgent(args.agent, canonicalThreadId, async (subscriber, canonicalRun) => {
132
+ result = await args.execute(subscriber, canonicalRun);
133
+ return result;
134
+ });
135
+ let stopPromise;
136
+ let heartbeatError;
137
+ let heartbeatTimer;
138
+ const stopCanonicalRun = () => {
139
+ stopPromise ??= Promise.resolve().then(() => runner.stop({
140
+ threadId: canonicalThreadId,
141
+ runId: canonicalRunId
142
+ })).catch(() => false);
143
+ };
144
+ const abortCanonicalRun = () => {
145
+ try {
146
+ args.agent.abortRun();
147
+ } catch {}
148
+ stopCanonicalRun();
149
+ };
150
+ args.signal?.addEventListener("abort", abortCanonicalRun, { once: true });
151
+ heartbeatTimer = setInterval(() => {
152
+ intelligence.ɵrenewThreadLock({
153
+ threadId: canonicalThreadId,
154
+ runId: canonicalRunId,
155
+ ttlSeconds: lockTtlSeconds,
156
+ ...lockKeyPrefix !== void 0 ? { lockKeyPrefix } : {}
157
+ }).catch((error) => {
158
+ if (heartbeatTimer === void 0) return;
159
+ clearInterval(heartbeatTimer);
160
+ heartbeatTimer = void 0;
161
+ heartbeatError = error;
162
+ try {
163
+ args.agent.abortRun();
164
+ } catch {}
165
+ stopCanonicalRun();
166
+ });
167
+ }, lockHeartbeatIntervalSeconds * 1e3);
168
+ heartbeatTimer.unref?.();
169
+ try {
170
+ await new Promise((resolve, reject) => {
171
+ let terminalError;
172
+ runner.run({
173
+ threadId: canonicalThreadId,
174
+ agent: outer,
175
+ input: {
176
+ threadId: canonicalThreadId,
177
+ runId: canonicalRunId,
178
+ messages: args.agent.messages,
179
+ state: args.agent.state,
180
+ tools: [...args.tools],
181
+ context: [...args.context],
182
+ forwardedProps: void 0
183
+ },
184
+ persistedInputMessages: args.persistedInputMessages
185
+ }).subscribe({
186
+ next: (event) => {
187
+ if (event.type !== _ag_ui_client.EventType.RUN_ERROR || terminalError) return;
188
+ const message = "message" in event && typeof event.message === "string" ? event.message : "Canonical Channel agent run failed";
189
+ terminalError = new Error(message);
190
+ terminalError.name = "ChannelCanonicalRunError";
191
+ if ("code" in event && typeof event.code === "string" && event.code.length > 0) terminalError.code = event.code;
192
+ },
193
+ error: reject,
194
+ complete: () => {
195
+ if (terminalError) reject(terminalError);
196
+ else resolve();
197
+ }
198
+ });
199
+ if (args.signal?.aborted) abortCanonicalRun();
200
+ });
201
+ } finally {
202
+ args.signal?.removeEventListener("abort", abortCanonicalRun);
203
+ if (heartbeatTimer !== void 0) {
204
+ clearInterval(heartbeatTimer);
205
+ heartbeatTimer = void 0;
206
+ }
207
+ await intelligence.ɵcleanupThreadLock({
208
+ threadId: canonicalThreadId,
209
+ runId: canonicalRunId
210
+ }).catch(() => void 0);
211
+ }
212
+ if (heartbeatError !== void 0) {
213
+ await stopPromise;
214
+ throw heartbeatError;
215
+ }
216
+ return result;
217
+ }
218
+ /** Convert canonical Intelligence history into AG-UI messages. */
219
+ async function toAgentMessage(message, intelligence) {
220
+ const content = await hydrateManagedContent(message.content, intelligence);
221
+ return {
222
+ id: message.id,
223
+ role: message.role,
224
+ content: content ?? "",
225
+ ...message.activityType ? { activityType: message.activityType } : {},
226
+ ...message.toolCalls ? { toolCalls: message.toolCalls.map((call) => ({
227
+ id: call.id,
228
+ type: "function",
229
+ function: {
230
+ name: call.name,
231
+ arguments: call.args
232
+ }
233
+ })) } : {},
234
+ ...message.toolCallId ? { toolCallId: message.toolCallId } : {}
235
+ };
236
+ }
237
+ /** Resolves managed asset references only at the authorized Runtime boundary. */
238
+ async function hydrateManagedContent(content, intelligence) {
239
+ if (Array.isArray(content)) return Promise.all(content.map(async (part) => {
240
+ if (typeof part !== "object" || part === null || !("source" in part) || typeof part.source !== "object" || part.source === null || !("value" in part.source) || typeof part.source.value !== "string" || !part.source.value.startsWith("cpki-asset://")) return part;
241
+ const assetId = part.source.value.slice(13);
242
+ const asset = await intelligence.ɵgetManagedChannelAsset(assetId);
243
+ return {
244
+ ...part,
245
+ source: {
246
+ type: "data",
247
+ value: Buffer.from(asset.bytes).toString("base64"),
248
+ mimeType: asset.mimeType ?? ("mimeType" in part.source && typeof part.source.mimeType === "string" ? part.source.mimeType : "application/octet-stream")
249
+ }
250
+ };
251
+ }));
252
+ if (typeof content === "object" && content !== null && "assetId" in content && typeof content.assetId === "string") {
253
+ const asset = await intelligence.ɵgetManagedChannelAsset(content.assetId);
254
+ return {
255
+ ...content,
256
+ source: {
257
+ type: "data",
258
+ value: Buffer.from(asset.bytes).toString("base64"),
259
+ mimeType: asset.mimeType ?? ("mimeType" in content && typeof content.mimeType === "string" ? content.mimeType : "application/octet-stream")
260
+ }
261
+ };
262
+ }
263
+ return content;
264
+ }
71
265
  /** Whether `err` signals a missing managed provider rather than a hard failure. */
72
266
  function isSetupRequired(err) {
73
267
  return err instanceof ChannelSetupRequiredError || typeof err === "object" && err !== null && err.code === "SETUP_REQUIRED";
@@ -129,15 +323,12 @@ function withTimeout(inner, timeoutMs, timeoutMessage) {
129
323
  * and {@link ready} rather than thrown.
130
324
  *
131
325
  * Reconnection is NOT handled here — it is delegated to the Phoenix connection
132
- * layer that backs the launcher. When a managed socket drops, Phoenix's `Socket`
133
- * auto-reconnects and auto-rejoins, re-sending the channel's join declaration;
134
- * the Intelligence gateway's `join/3` re-runs `record_heartbeat` (re-registering
135
- * the runtime's listener) and its `terminate/2` releases the dead socket's
136
- * leases (verified against Intelligence #511 `sdk_channel.ex`). So the transport
137
- * self-heals under the persistent adapter and a re-activation here would be both
138
- * redundant AND broken: re-invoking the engine on an already-started `Channel`
139
- * throws in `channel.addAdapter` (started=true). The manager therefore never
140
- * re-activates on a drop.
326
+ * layer that backs the launcher. When a managed control socket drops, Phoenix's
327
+ * `Socket` reconnects and rejoins with the same Runtime declaration. Active
328
+ * deliveries request fresh one-use join tokens through that control link. A
329
+ * re-activation here would be both redundant AND broken: re-invoking the engine
330
+ * on an already-started `Channel` throws in `channel.addAdapter` (started=true).
331
+ * The manager therefore never re-activates on a drop.
141
332
  *
142
333
  * It DOES, however, reflect real connection health through the session's
143
334
  * `onStateChange` observer so {@link ChannelManager.status} stays honest rather
@@ -152,9 +343,19 @@ var ChannelManager = class {
152
343
  this.activated = false;
153
344
  this.stopped = false;
154
345
  this.intelligence = args.intelligence;
346
+ this.runner = args.runner;
347
+ this.lockTtlSeconds = args.lockTtlSeconds ?? 20;
348
+ this.lockHeartbeatIntervalSeconds = args.lockHeartbeatIntervalSeconds ?? 15;
349
+ this.lockKeyPrefix = args.lockKeyPrefix;
155
350
  this.channels = args.channels;
156
351
  this.log = args.log;
157
- this.activateChannel = args.activateChannel ?? ((config, channel) => defaultActivateChannel(config, channel, void 0, this.log));
352
+ this.activateChannel = args.activateChannel ?? ((config, channel) => defaultActivateChannel(config, channel, void 0, this.log, this.runner ? {
353
+ runner: this.runner,
354
+ intelligence: this.intelligence,
355
+ lockTtlSeconds: this.lockTtlSeconds,
356
+ lockHeartbeatIntervalSeconds: this.lockHeartbeatIntervalSeconds,
357
+ ...this.lockKeyPrefix !== void 0 ? { lockKeyPrefix: this.lockKeyPrefix } : {}
358
+ } : void 0));
158
359
  this.mintRuntimeInstanceId = args.mintRuntimeInstanceId ?? (() => `rti_${(0, node_crypto.randomUUID)().replace(/-/g, "")}`);
159
360
  this.stopHandleTimeoutMs = args.stopHandleTimeoutMs ?? DEFAULT_STOP_HANDLE_TIMEOUT_MS;
160
361
  this.reconnectLogIntervalMs = args.reconnectLogIntervalMs ?? DEFAULT_RECONNECT_LOG_INTERVAL_MS;
@@ -415,8 +616,7 @@ var ChannelManager = class {
415
616
  *
416
617
  * - `reconnecting` → status `reconnecting` (dropped, Phoenix retrying);
417
618
  * - `online` → status `online` (rejoined, sendable again);
418
- * - `gave_up` → status `error` (dead after the bounded reconnect window);
419
- * - `fenced` → status `error` immediately (another activation superseded it).
619
+ * - `gave_up` → status `error` (dead after the bounded reconnect window).
420
620
  *
421
621
  * Makes NO re-activation — reconnection is delegated to the Phoenix connection
422
622
  * layer (see {@link ChannelManager}), which auto-rejoins under the persistent
@@ -445,10 +645,6 @@ var ChannelManager = class {
445
645
  } else if (state === "gave_up") {
446
646
  entry.status = "error";
447
647
  this.log?.(`channel "${name}" managed session gave up reconnecting after ${this.downFor(entry)}; marking error (still retrying — a successful rejoin restores online)${because}`);
448
- } else {
449
- entry.status = "error";
450
- this.clearReconnectLog(entry);
451
- this.log?.(`channel "${name}" managed session was generation-fenced by a replacement; marking error`);
452
648
  }
453
649
  });
454
650
  }