@copilotkit/runtime 1.64.2-canary.1785346263 → 1.64.2-canary.1785375021
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.
- package/dist/package.cjs +1 -1
- package/dist/runtime/package.mjs +1 -1
- package/dist/v2/runtime/core/channel-activation-config.cjs +3 -1
- package/dist/v2/runtime/core/channel-activation-config.cjs.map +1 -1
- package/dist/v2/runtime/core/channel-activation-config.d.cts +6 -0
- package/dist/v2/runtime/core/channel-activation-config.d.cts.map +1 -1
- package/dist/v2/runtime/core/channel-activation-config.d.mts +6 -0
- package/dist/v2/runtime/core/channel-activation-config.d.mts.map +1 -1
- package/dist/v2/runtime/core/channel-activation-config.mjs +3 -1
- package/dist/v2/runtime/core/channel-activation-config.mjs.map +1 -1
- package/dist/v2/runtime/core/channel-manager.cjs +209 -6
- package/dist/v2/runtime/core/channel-manager.cjs.map +1 -1
- package/dist/v2/runtime/core/channel-manager.d.cts +6 -1
- package/dist/v2/runtime/core/channel-manager.d.cts.map +1 -1
- package/dist/v2/runtime/core/channel-manager.d.mts +6 -1
- package/dist/v2/runtime/core/channel-manager.d.mts.map +1 -1
- package/dist/v2/runtime/core/channel-manager.mjs +209 -6
- package/dist/v2/runtime/core/channel-manager.mjs.map +1 -1
- package/dist/v2/runtime/core/fetch-handler.cjs +15 -0
- package/dist/v2/runtime/core/fetch-handler.cjs.map +1 -1
- package/dist/v2/runtime/core/fetch-handler.d.cts.map +1 -1
- package/dist/v2/runtime/core/fetch-handler.d.mts.map +1 -1
- package/dist/v2/runtime/core/fetch-handler.mjs +16 -1
- package/dist/v2/runtime/core/fetch-handler.mjs.map +1 -1
- package/dist/v2/runtime/core/fetch-router.cjs +1 -0
- package/dist/v2/runtime/core/fetch-router.cjs.map +1 -1
- package/dist/v2/runtime/core/fetch-router.mjs +1 -0
- package/dist/v2/runtime/core/fetch-router.mjs.map +1 -1
- package/dist/v2/runtime/core/hooks.cjs.map +1 -1
- package/dist/v2/runtime/core/hooks.d.cts +2 -0
- package/dist/v2/runtime/core/hooks.d.cts.map +1 -1
- package/dist/v2/runtime/core/hooks.d.mts +2 -0
- package/dist/v2/runtime/core/hooks.d.mts.map +1 -1
- package/dist/v2/runtime/core/hooks.mjs.map +1 -1
- package/dist/v2/runtime/core/runtime.cjs +4 -0
- package/dist/v2/runtime/core/runtime.cjs.map +1 -1
- package/dist/v2/runtime/core/runtime.d.cts +24 -0
- package/dist/v2/runtime/core/runtime.d.cts.map +1 -1
- package/dist/v2/runtime/core/runtime.d.mts +24 -0
- package/dist/v2/runtime/core/runtime.d.mts.map +1 -1
- package/dist/v2/runtime/core/runtime.mjs +4 -0
- package/dist/v2/runtime/core/runtime.mjs.map +1 -1
- package/dist/v2/runtime/handlers/intelligence/memories.cjs +63 -1
- package/dist/v2/runtime/handlers/intelligence/memories.cjs.map +1 -1
- package/dist/v2/runtime/handlers/intelligence/memories.mjs +63 -2
- package/dist/v2/runtime/handlers/intelligence/memories.mjs.map +1 -1
- package/dist/v2/runtime/intelligence-platform/client.cjs +17 -1
- package/dist/v2/runtime/intelligence-platform/client.cjs.map +1 -1
- package/dist/v2/runtime/intelligence-platform/client.d.cts +31 -1
- package/dist/v2/runtime/intelligence-platform/client.d.cts.map +1 -1
- package/dist/v2/runtime/intelligence-platform/client.d.mts +31 -1
- package/dist/v2/runtime/intelligence-platform/client.d.mts.map +1 -1
- package/dist/v2/runtime/intelligence-platform/client.mjs +17 -1
- package/dist/v2/runtime/intelligence-platform/client.mjs.map +1 -1
- package/dist/v2/runtime/runner/agent-runner.cjs.map +1 -1
- package/dist/v2/runtime/runner/agent-runner.d.cts +2 -0
- package/dist/v2/runtime/runner/agent-runner.d.cts.map +1 -1
- package/dist/v2/runtime/runner/agent-runner.d.mts +2 -0
- package/dist/v2/runtime/runner/agent-runner.d.mts.map +1 -1
- package/dist/v2/runtime/runner/agent-runner.mjs.map +1 -1
- package/dist/v2/runtime/runner/in-memory.cjs +2 -5
- package/dist/v2/runtime/runner/in-memory.cjs.map +1 -1
- package/dist/v2/runtime/runner/in-memory.d.cts.map +1 -1
- package/dist/v2/runtime/runner/in-memory.d.mts.map +1 -1
- package/dist/v2/runtime/runner/in-memory.mjs +2 -5
- package/dist/v2/runtime/runner/in-memory.mjs.map +1 -1
- package/dist/v2/runtime/runner/intelligence.cjs +36 -31
- package/dist/v2/runtime/runner/intelligence.cjs.map +1 -1
- package/dist/v2/runtime/runner/intelligence.d.cts.map +1 -1
- package/dist/v2/runtime/runner/intelligence.d.mts.map +1 -1
- package/dist/v2/runtime/runner/intelligence.mjs +36 -31
- package/dist/v2/runtime/runner/intelligence.mjs.map +1 -1
- package/package.json +6 -6
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.
|
|
8
|
+
"version": "1.64.2-canary.1785375021",
|
|
9
9
|
"private": false,
|
|
10
10
|
"keywords": [
|
|
11
11
|
"ai",
|
package/dist/runtime/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.64.2-canary.
|
|
8
|
+
"version": "1.64.2-canary.1785375021",
|
|
9
9
|
"private": false,
|
|
10
10
|
"keywords": [
|
|
11
11
|
"ai",
|
|
@@ -41,7 +41,8 @@ function parseProjectIdFromApiKey(apiKey) {
|
|
|
41
41
|
* @param args.intelligence - The Intelligence runtime client to pull the
|
|
42
42
|
* runner websocket URL and auth token from.
|
|
43
43
|
* @param args.channel - The Channel being activated. Must have a `name`; its
|
|
44
|
-
* per-Channel `provider` selects the managed adapter declared to the gateway
|
|
44
|
+
* per-Channel `provider` selects the managed adapter declared to the gateway,
|
|
45
|
+
* and `showToolStatus` optionally overrides managed tool-call visibility.
|
|
45
46
|
* @param args.runtimeInstanceId - Identifier for the activating runtime
|
|
46
47
|
* instance, passed through unchanged.
|
|
47
48
|
* @returns The resolved {@link ChannelActivationConfig}.
|
|
@@ -83,6 +84,7 @@ function deriveChannelActivationConfig(args) {
|
|
|
83
84
|
projectId,
|
|
84
85
|
channelName,
|
|
85
86
|
adapter: trimmedProvider ? trimmedProvider : "slack",
|
|
87
|
+
...channel.showToolStatus !== void 0 ? { showToolStatus: channel.showToolStatus } : {},
|
|
86
88
|
runtimeInstanceId
|
|
87
89
|
};
|
|
88
90
|
}
|
|
@@ -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 /** 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 * @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 runtimeInstanceId,\n };\n}\n"],"mappings":";;;;;;;;AAUA,IAAa,qBAAb,cAAwC,MAAM;CAC5C,YAAY,SAAiB;AAC3B,QAAM,QAAQ;AACd,OAAK,OAAO;;;;
|
|
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"}
|
|
@@ -26,6 +26,12 @@ interface ChannelActivationConfig {
|
|
|
26
26
|
* connection for the declared provider.
|
|
27
27
|
*/
|
|
28
28
|
adapter: string;
|
|
29
|
+
/**
|
|
30
|
+
* Optional per-Channel override for visible managed tool-call progress.
|
|
31
|
+
* Unset Slack routes default to hidden; other providers retain their existing
|
|
32
|
+
* default.
|
|
33
|
+
*/
|
|
34
|
+
showToolStatus?: boolean;
|
|
29
35
|
/** Identifier for the runtime instance activating this Channel. */
|
|
30
36
|
runtimeInstanceId: string;
|
|
31
37
|
}
|
|
@@ -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;;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;;EAEf,KAAA;;EAEA,MAAA;;;;;EAKA,MAAA;;EAEA,SAAA;;EAEA,WAAA;;;;;;;;EAQA,OAAA;;;;;;EAMA,cAAA;;EAEA,iBAAA;AAAA"}
|
|
@@ -26,6 +26,12 @@ interface ChannelActivationConfig {
|
|
|
26
26
|
* connection for the declared provider.
|
|
27
27
|
*/
|
|
28
28
|
adapter: string;
|
|
29
|
+
/**
|
|
30
|
+
* Optional per-Channel override for visible managed tool-call progress.
|
|
31
|
+
* Unset Slack routes default to hidden; other providers retain their existing
|
|
32
|
+
* default.
|
|
33
|
+
*/
|
|
34
|
+
showToolStatus?: boolean;
|
|
29
35
|
/** Identifier for the runtime instance activating this Channel. */
|
|
30
36
|
runtimeInstanceId: string;
|
|
31
37
|
}
|
|
@@ -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;;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;;EAEf,KAAA;;EAEA,MAAA;;;;;EAKA,MAAA;;EAEA,SAAA;;EAEA,WAAA;;;;;;;;EAQA,OAAA;;;;;;EAMA,cAAA;;EAEA,iBAAA;AAAA"}
|
|
@@ -40,7 +40,8 @@ function parseProjectIdFromApiKey(apiKey) {
|
|
|
40
40
|
* @param args.intelligence - The Intelligence runtime client to pull the
|
|
41
41
|
* runner websocket URL and auth token from.
|
|
42
42
|
* @param args.channel - The Channel being activated. Must have a `name`; its
|
|
43
|
-
* per-Channel `provider` selects the managed adapter declared to the gateway
|
|
43
|
+
* per-Channel `provider` selects the managed adapter declared to the gateway,
|
|
44
|
+
* and `showToolStatus` optionally overrides managed tool-call visibility.
|
|
44
45
|
* @param args.runtimeInstanceId - Identifier for the activating runtime
|
|
45
46
|
* instance, passed through unchanged.
|
|
46
47
|
* @returns The resolved {@link ChannelActivationConfig}.
|
|
@@ -82,6 +83,7 @@ function deriveChannelActivationConfig(args) {
|
|
|
82
83
|
projectId,
|
|
83
84
|
channelName,
|
|
84
85
|
adapter: trimmedProvider ? trimmedProvider : "slack",
|
|
86
|
+
...channel.showToolStatus !== void 0 ? { showToolStatus: channel.showToolStatus } : {},
|
|
85
87
|
runtimeInstanceId
|
|
86
88
|
};
|
|
87
89
|
}
|
|
@@ -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 /** 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 * @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 runtimeInstanceId,\n };\n}\n"],"mappings":";;;;;;;AAUA,IAAa,qBAAb,cAAwC,MAAM;CAC5C,YAAY,SAAiB;AAC3B,QAAM,QAAQ;AACd,OAAK,OAAO;;;;
|
|
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,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,
|
|
@@ -63,10 +66,162 @@ async function defaultActivateChannel(config, channel, importChannelsIntelligenc
|
|
|
63
66
|
},
|
|
64
67
|
runtimeInstanceId: config.runtimeInstanceId,
|
|
65
68
|
adapter: config.adapter,
|
|
69
|
+
...config.showToolStatus !== void 0 ? { showToolStatus: config.showToolStatus } : {},
|
|
66
70
|
appApiBaseUrl: config.apiUrl,
|
|
67
|
-
...log ? { log } : {}
|
|
71
|
+
...log ? { log } : {},
|
|
72
|
+
runCanonical: (args) => runCanonicalChannelAgent(services.runner, services.intelligence, services.lockTtlSeconds ?? 20, services.lockHeartbeatIntervalSeconds ?? 15, args),
|
|
73
|
+
loadHistory: async ({ threadId, appUserId }) => {
|
|
74
|
+
return (await services.intelligence.getThreadMessages({
|
|
75
|
+
threadId,
|
|
76
|
+
userId: appUserId
|
|
77
|
+
})).messages.map(toAgentMessage);
|
|
78
|
+
}
|
|
68
79
|
});
|
|
69
80
|
}
|
|
81
|
+
/** One outer agent that lets the standard runner own the whole local tool loop. */
|
|
82
|
+
var ChannelOuterAgent = class extends _ag_ui_client.AbstractAgent {
|
|
83
|
+
constructor(inner, canonicalThreadId, executeLoop) {
|
|
84
|
+
super({
|
|
85
|
+
threadId: inner.threadId,
|
|
86
|
+
initialMessages: inner.messages,
|
|
87
|
+
initialState: inner.state,
|
|
88
|
+
...inner.agentId ? { agentId: inner.agentId } : {}
|
|
89
|
+
});
|
|
90
|
+
this.inner = inner;
|
|
91
|
+
this.canonicalThreadId = canonicalThreadId;
|
|
92
|
+
this.executeLoop = executeLoop;
|
|
93
|
+
}
|
|
94
|
+
run() {
|
|
95
|
+
return rxjs.EMPTY;
|
|
96
|
+
}
|
|
97
|
+
async runAgent(parameters, subscriber) {
|
|
98
|
+
if (!parameters?.runId) throw new Error("Canonical Channel run requires a runId");
|
|
99
|
+
return {
|
|
100
|
+
result: await this.executeLoop(subscriber ?? {}, {
|
|
101
|
+
threadId: this.canonicalThreadId,
|
|
102
|
+
runId: parameters.runId
|
|
103
|
+
}),
|
|
104
|
+
newMessages: []
|
|
105
|
+
};
|
|
106
|
+
}
|
|
107
|
+
abortRun() {
|
|
108
|
+
this.inner.abortRun();
|
|
109
|
+
}
|
|
110
|
+
};
|
|
111
|
+
/** Drive one public Channel run through the runtime's existing AgentRunner. */
|
|
112
|
+
async function runCanonicalChannelAgent(runner, intelligence, lockTtlSeconds, lockHeartbeatIntervalSeconds, args) {
|
|
113
|
+
if (args.abortSignal.aborted) throw channelRunCancellationError(args.abortSignal);
|
|
114
|
+
let result = {
|
|
115
|
+
iterations: 0,
|
|
116
|
+
interrupted: false
|
|
117
|
+
};
|
|
118
|
+
const outer = new ChannelOuterAgent(args.agent, args.threadId, async (subscriber, canonicalRun) => {
|
|
119
|
+
result = await args.execute(subscriber, canonicalRun);
|
|
120
|
+
return result;
|
|
121
|
+
});
|
|
122
|
+
let stopPromise;
|
|
123
|
+
let heartbeatError;
|
|
124
|
+
let heartbeatTimer;
|
|
125
|
+
const stopCanonicalRun = () => {
|
|
126
|
+
stopPromise ??= Promise.resolve().then(() => runner.stop({ threadId: args.threadId })).catch(() => false);
|
|
127
|
+
};
|
|
128
|
+
args.abortSignal.addEventListener("abort", stopCanonicalRun, { once: true });
|
|
129
|
+
heartbeatTimer = setInterval(() => {
|
|
130
|
+
intelligence.ɵrenewThreadLock({
|
|
131
|
+
threadId: args.threadId,
|
|
132
|
+
runId: args.runId,
|
|
133
|
+
ttlSeconds: lockTtlSeconds
|
|
134
|
+
}).catch((error) => {
|
|
135
|
+
if (heartbeatTimer === void 0) return;
|
|
136
|
+
clearInterval(heartbeatTimer);
|
|
137
|
+
heartbeatTimer = void 0;
|
|
138
|
+
heartbeatError = error;
|
|
139
|
+
try {
|
|
140
|
+
args.agent.abortRun();
|
|
141
|
+
} catch {}
|
|
142
|
+
stopCanonicalRun();
|
|
143
|
+
});
|
|
144
|
+
}, lockHeartbeatIntervalSeconds * 1e3);
|
|
145
|
+
heartbeatTimer.unref?.();
|
|
146
|
+
try {
|
|
147
|
+
if (args.abortSignal.aborted) stopCanonicalRun();
|
|
148
|
+
await new Promise((resolve, reject) => {
|
|
149
|
+
let terminalError;
|
|
150
|
+
runner.run({
|
|
151
|
+
threadId: args.threadId,
|
|
152
|
+
agent: outer,
|
|
153
|
+
input: {
|
|
154
|
+
threadId: args.threadId,
|
|
155
|
+
runId: args.runId,
|
|
156
|
+
messages: args.agent.messages,
|
|
157
|
+
state: args.agent.state,
|
|
158
|
+
tools: [...args.tools],
|
|
159
|
+
context: [...args.context],
|
|
160
|
+
forwardedProps: void 0
|
|
161
|
+
},
|
|
162
|
+
persistedInputMessages: args.persistedInputMessages,
|
|
163
|
+
authToken: args.runnerToken
|
|
164
|
+
}).subscribe({
|
|
165
|
+
next: (event) => {
|
|
166
|
+
if (event.type !== _ag_ui_client.EventType.RUN_ERROR || terminalError) return;
|
|
167
|
+
const message = "message" in event && typeof event.message === "string" ? event.message : "Canonical Channel agent run failed";
|
|
168
|
+
terminalError = new Error(message);
|
|
169
|
+
terminalError.name = "ChannelCanonicalRunError";
|
|
170
|
+
if ("code" in event && typeof event.code === "string" && event.code.length > 0) terminalError.code = event.code;
|
|
171
|
+
},
|
|
172
|
+
error: reject,
|
|
173
|
+
complete: () => {
|
|
174
|
+
if (terminalError) reject(terminalError);
|
|
175
|
+
else resolve();
|
|
176
|
+
}
|
|
177
|
+
});
|
|
178
|
+
});
|
|
179
|
+
} catch (error) {
|
|
180
|
+
if (args.abortSignal.aborted) {
|
|
181
|
+
await stopPromise;
|
|
182
|
+
throw channelRunCancellationError(args.abortSignal);
|
|
183
|
+
}
|
|
184
|
+
throw error;
|
|
185
|
+
} finally {
|
|
186
|
+
if (heartbeatTimer !== void 0) {
|
|
187
|
+
clearInterval(heartbeatTimer);
|
|
188
|
+
heartbeatTimer = void 0;
|
|
189
|
+
}
|
|
190
|
+
args.abortSignal.removeEventListener("abort", stopCanonicalRun);
|
|
191
|
+
}
|
|
192
|
+
if (heartbeatError !== void 0) {
|
|
193
|
+
await stopPromise;
|
|
194
|
+
throw heartbeatError;
|
|
195
|
+
}
|
|
196
|
+
if (args.abortSignal.aborted) {
|
|
197
|
+
await stopPromise;
|
|
198
|
+
throw channelRunCancellationError(args.abortSignal);
|
|
199
|
+
}
|
|
200
|
+
return result;
|
|
201
|
+
}
|
|
202
|
+
function channelRunCancellationError(signal) {
|
|
203
|
+
const reason = typeof signal.reason === "string" && signal.reason.length > 0 ? signal.reason : "channel_run_cancelled";
|
|
204
|
+
const error = new Error(reason);
|
|
205
|
+
error.name = "ChannelCanonicalRunCancelledError";
|
|
206
|
+
return error;
|
|
207
|
+
}
|
|
208
|
+
/** Convert canonical Intelligence history into AG-UI messages. */
|
|
209
|
+
function toAgentMessage(message) {
|
|
210
|
+
return {
|
|
211
|
+
id: message.id,
|
|
212
|
+
role: message.role,
|
|
213
|
+
content: message.content ?? "",
|
|
214
|
+
...message.toolCalls ? { toolCalls: message.toolCalls.map((call) => ({
|
|
215
|
+
id: call.id,
|
|
216
|
+
type: "function",
|
|
217
|
+
function: {
|
|
218
|
+
name: call.name,
|
|
219
|
+
arguments: call.args
|
|
220
|
+
}
|
|
221
|
+
})) } : {},
|
|
222
|
+
...message.toolCallId ? { toolCallId: message.toolCallId } : {}
|
|
223
|
+
};
|
|
224
|
+
}
|
|
70
225
|
/** Whether `err` signals a missing managed provider rather than a hard failure. */
|
|
71
226
|
function isSetupRequired(err) {
|
|
72
227
|
return err instanceof ChannelSetupRequiredError || typeof err === "object" && err !== null && err.code === "SETUP_REQUIRED";
|
|
@@ -84,6 +239,8 @@ function isModuleNotFound(err) {
|
|
|
84
239
|
}
|
|
85
240
|
/** Default deadline (ms) for a single `handle.stop()` during teardown. */
|
|
86
241
|
const DEFAULT_STOP_HANDLE_TIMEOUT_MS = 5e3;
|
|
242
|
+
/** Default cadence (ms) for the "still down" log while a session is dropped. */
|
|
243
|
+
const DEFAULT_RECONNECT_LOG_INTERVAL_MS = 3e4;
|
|
87
244
|
/**
|
|
88
245
|
* Reject with `timeoutMessage` after `timeoutMs` if `inner` has not settled,
|
|
89
246
|
* otherwise pass `inner` through. When `timeoutMs` is undefined, `inner` is
|
|
@@ -149,11 +306,20 @@ var ChannelManager = class {
|
|
|
149
306
|
this.activated = false;
|
|
150
307
|
this.stopped = false;
|
|
151
308
|
this.intelligence = args.intelligence;
|
|
309
|
+
this.runner = args.runner;
|
|
310
|
+
this.lockTtlSeconds = args.lockTtlSeconds ?? 20;
|
|
311
|
+
this.lockHeartbeatIntervalSeconds = args.lockHeartbeatIntervalSeconds ?? 15;
|
|
152
312
|
this.channels = args.channels;
|
|
153
313
|
this.log = args.log;
|
|
154
|
-
this.activateChannel = args.activateChannel ?? ((config, channel) => defaultActivateChannel(config, channel, void 0, this.log
|
|
314
|
+
this.activateChannel = args.activateChannel ?? ((config, channel) => defaultActivateChannel(config, channel, void 0, this.log, this.runner ? {
|
|
315
|
+
runner: this.runner,
|
|
316
|
+
intelligence: this.intelligence,
|
|
317
|
+
lockTtlSeconds: this.lockTtlSeconds,
|
|
318
|
+
lockHeartbeatIntervalSeconds: this.lockHeartbeatIntervalSeconds
|
|
319
|
+
} : void 0));
|
|
155
320
|
this.mintRuntimeInstanceId = args.mintRuntimeInstanceId ?? (() => `rti_${(0, node_crypto.randomUUID)().replace(/-/g, "")}`);
|
|
156
321
|
this.stopHandleTimeoutMs = args.stopHandleTimeoutMs ?? DEFAULT_STOP_HANDLE_TIMEOUT_MS;
|
|
322
|
+
this.reconnectLogIntervalMs = args.reconnectLogIntervalMs ?? DEFAULT_RECONNECT_LOG_INTERVAL_MS;
|
|
157
323
|
}
|
|
158
324
|
/**
|
|
159
325
|
* Start activation of every declared Channel (lazy + idempotent). Mints a
|
|
@@ -424,23 +590,59 @@ var ChannelManager = class {
|
|
|
424
590
|
* @param entry - The Channel's activation entry.
|
|
425
591
|
*/
|
|
426
592
|
registerConnectionObserver(name, entry) {
|
|
427
|
-
entry.handle?.onStateChange?.((state) => {
|
|
593
|
+
entry.handle?.onStateChange?.((state, detail) => {
|
|
428
594
|
if (this.stopped || entry.status === "stopped") return;
|
|
595
|
+
const cause = detail?.reason ?? detail?.code;
|
|
596
|
+
const because = cause !== void 0 ? ` — ${cause}` : "";
|
|
429
597
|
if (state === "reconnecting") {
|
|
430
598
|
entry.status = "reconnecting";
|
|
431
|
-
|
|
599
|
+
entry.downSince ??= Date.now();
|
|
600
|
+
this.log?.(`channel "${name}" managed session dropped; reconnecting (Phoenix auto-rejoin)${because}`);
|
|
601
|
+
this.startReconnectLog(name, entry);
|
|
432
602
|
} else if (state === "online") {
|
|
433
603
|
entry.status = "online";
|
|
604
|
+
this.clearReconnectLog(entry);
|
|
605
|
+
entry.downSince = void 0;
|
|
434
606
|
this.log?.(`channel "${name}" managed session back online`);
|
|
435
607
|
} else if (state === "gave_up") {
|
|
436
608
|
entry.status = "error";
|
|
437
|
-
this.log?.(`channel "${name}" managed session gave up reconnecting; marking error`);
|
|
609
|
+
this.log?.(`channel "${name}" managed session gave up reconnecting after ${this.downFor(entry)}; marking error (still retrying — a successful rejoin restores online)${because}`);
|
|
438
610
|
} else {
|
|
439
611
|
entry.status = "error";
|
|
612
|
+
this.clearReconnectLog(entry);
|
|
440
613
|
this.log?.(`channel "${name}" managed session was generation-fenced by a replacement; marking error`);
|
|
441
614
|
}
|
|
442
615
|
});
|
|
443
616
|
}
|
|
617
|
+
/** Rendered downtime for this outage episode (`"45s"`), or `"unknown"`. */
|
|
618
|
+
downFor(entry) {
|
|
619
|
+
return entry.downSince === void 0 ? "unknown" : `${Math.round((Date.now() - entry.downSince) / 1e3)}s`;
|
|
620
|
+
}
|
|
621
|
+
/**
|
|
622
|
+
* Repeat a "still down" line for as long as this outage lasts. Runs THROUGH
|
|
623
|
+
* `gave_up` on purpose: that transition is where the old behavior went quiet,
|
|
624
|
+
* and an operator watching a silent process cannot tell a dead bot from an
|
|
625
|
+
* idle one.
|
|
626
|
+
*/
|
|
627
|
+
startReconnectLog(name, entry) {
|
|
628
|
+
if (entry.reconnectLogTimer !== void 0) return;
|
|
629
|
+
const timer = setInterval(() => {
|
|
630
|
+
if (this.stopped || entry.status === "stopped") {
|
|
631
|
+
this.clearReconnectLog(entry);
|
|
632
|
+
return;
|
|
633
|
+
}
|
|
634
|
+
this.log?.(`channel "${name}" managed session still down after ${this.downFor(entry)}; Phoenix is retrying`);
|
|
635
|
+
}, this.reconnectLogIntervalMs);
|
|
636
|
+
timer.unref?.();
|
|
637
|
+
entry.reconnectLogTimer = timer;
|
|
638
|
+
}
|
|
639
|
+
/** Stop this entry's "still down" repeat, if one is running. */
|
|
640
|
+
clearReconnectLog(entry) {
|
|
641
|
+
if (entry.reconnectLogTimer !== void 0) {
|
|
642
|
+
clearInterval(entry.reconnectLogTimer);
|
|
643
|
+
entry.reconnectLogTimer = void 0;
|
|
644
|
+
}
|
|
645
|
+
}
|
|
444
646
|
/**
|
|
445
647
|
* Drive a single entry to its terminal `stopped` state, tearing down its
|
|
446
648
|
* handle AT MOST ONCE. Idempotent: it always sets `status = "stopped"`, and
|
|
@@ -478,6 +680,7 @@ var ChannelManager = class {
|
|
|
478
680
|
*/
|
|
479
681
|
async stopEntry(entry) {
|
|
480
682
|
entry.status = "stopped";
|
|
683
|
+
this.clearReconnectLog(entry);
|
|
481
684
|
if (entry.handle && !entry.handleStopped) {
|
|
482
685
|
entry.handleStopped = true;
|
|
483
686
|
const handle = entry.handle;
|