@copilotkit/runtime 1.67.1 → 1.68.1
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/agent/index.cjs +5 -0
- package/dist/agent/index.cjs.map +1 -1
- package/dist/agent/index.d.cts +2 -1
- package/dist/agent/index.d.cts.map +1 -1
- package/dist/agent/index.d.mts +2 -1
- package/dist/agent/index.d.mts.map +1 -1
- package/dist/agent/index.mjs +5 -0
- package/dist/agent/index.mjs.map +1 -1
- package/dist/lib/integrations/node-http/request-handler.cjs +1 -2
- package/dist/lib/integrations/node-http/request-handler.cjs.map +1 -1
- package/dist/lib/integrations/node-http/request-handler.mjs +1 -2
- package/dist/lib/integrations/node-http/request-handler.mjs.map +1 -1
- package/dist/lib/runtime/copilot-runtime.cjs +25 -4
- package/dist/lib/runtime/copilot-runtime.cjs.map +1 -1
- package/dist/lib/runtime/copilot-runtime.d.cts +14 -3
- package/dist/lib/runtime/copilot-runtime.d.cts.map +1 -1
- package/dist/lib/runtime/copilot-runtime.d.mts +14 -3
- package/dist/lib/runtime/copilot-runtime.d.mts.map +1 -1
- package/dist/lib/runtime/copilot-runtime.mjs +25 -4
- package/dist/lib/runtime/copilot-runtime.mjs.map +1 -1
- package/dist/package.cjs +2 -2
- package/dist/runtime/package.mjs +2 -2
- package/dist/v2/index.d.cts +2 -1
- package/dist/v2/index.d.mts +2 -1
- package/dist/v2/runtime/core/channel-manager.cjs +14 -2
- package/dist/v2/runtime/core/channel-manager.cjs.map +1 -1
- package/dist/v2/runtime/core/channel-manager.d.cts.map +1 -1
- package/dist/v2/runtime/core/channel-manager.d.mts +1 -0
- package/dist/v2/runtime/core/channel-manager.d.mts.map +1 -1
- package/dist/v2/runtime/core/channel-manager.mjs +14 -2
- package/dist/v2/runtime/core/channel-manager.mjs.map +1 -1
- package/dist/v2/runtime/core/fetch-handler.cjs +1 -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 +1 -0
- package/dist/v2/runtime/core/fetch-handler.mjs.map +1 -1
- package/dist/v2/runtime/core/learning.cjs +21 -0
- package/dist/v2/runtime/core/learning.cjs.map +1 -0
- package/dist/v2/runtime/core/learning.d.cts +27 -0
- package/dist/v2/runtime/core/learning.d.cts.map +1 -0
- package/dist/v2/runtime/core/learning.d.mts +27 -0
- package/dist/v2/runtime/core/learning.d.mts.map +1 -0
- package/dist/v2/runtime/core/learning.mjs +19 -0
- package/dist/v2/runtime/core/learning.mjs.map +1 -0
- package/dist/v2/runtime/core/runtime-error-reporter.cjs +72 -0
- package/dist/v2/runtime/core/runtime-error-reporter.cjs.map +1 -0
- package/dist/v2/runtime/core/runtime-error-reporter.mjs +67 -0
- package/dist/v2/runtime/core/runtime-error-reporter.mjs.map +1 -0
- package/dist/v2/runtime/core/runtime.cjs +11 -0
- package/dist/v2/runtime/core/runtime.cjs.map +1 -1
- package/dist/v2/runtime/core/runtime.d.cts +8 -0
- package/dist/v2/runtime/core/runtime.d.cts.map +1 -1
- package/dist/v2/runtime/core/runtime.d.mts +8 -0
- package/dist/v2/runtime/core/runtime.d.mts.map +1 -1
- package/dist/v2/runtime/core/runtime.mjs +11 -0
- package/dist/v2/runtime/core/runtime.mjs.map +1 -1
- package/dist/v2/runtime/handlers/handle-run.cjs +14 -2
- package/dist/v2/runtime/handlers/handle-run.cjs.map +1 -1
- package/dist/v2/runtime/handlers/handle-run.mjs +14 -2
- package/dist/v2/runtime/handlers/handle-run.mjs.map +1 -1
- package/dist/v2/runtime/handlers/intelligence/annotate.cjs +1 -1
- package/dist/v2/runtime/handlers/intelligence/annotate.cjs.map +1 -1
- package/dist/v2/runtime/handlers/intelligence/annotate.mjs +1 -1
- package/dist/v2/runtime/handlers/intelligence/annotate.mjs.map +1 -1
- package/dist/v2/runtime/handlers/intelligence/run.cjs +51 -8
- package/dist/v2/runtime/handlers/intelligence/run.cjs.map +1 -1
- package/dist/v2/runtime/handlers/intelligence/run.mjs +51 -8
- package/dist/v2/runtime/handlers/intelligence/run.mjs.map +1 -1
- package/dist/v2/runtime/handlers/shared/sse-response.cjs +24 -1
- package/dist/v2/runtime/handlers/shared/sse-response.cjs.map +1 -1
- package/dist/v2/runtime/handlers/shared/sse-response.mjs +24 -1
- package/dist/v2/runtime/handlers/shared/sse-response.mjs.map +1 -1
- package/dist/v2/runtime/handlers/sse/connect.cjs +1 -0
- package/dist/v2/runtime/handlers/sse/connect.cjs.map +1 -1
- package/dist/v2/runtime/handlers/sse/connect.mjs +1 -0
- package/dist/v2/runtime/handlers/sse/connect.mjs.map +1 -1
- package/dist/v2/runtime/handlers/sse/run.cjs +4 -1
- package/dist/v2/runtime/handlers/sse/run.cjs.map +1 -1
- package/dist/v2/runtime/handlers/sse/run.mjs +4 -1
- package/dist/v2/runtime/handlers/sse/run.mjs.map +1 -1
- package/dist/v2/runtime/index.d.cts +1 -0
- package/dist/v2/runtime/index.d.cts.map +1 -1
- package/dist/v2/runtime/index.d.mts +1 -0
- package/dist/v2/runtime/index.d.mts.map +1 -1
- package/dist/v2/runtime/intelligence-platform/client.cjs +6 -4
- package/dist/v2/runtime/intelligence-platform/client.cjs.map +1 -1
- package/dist/v2/runtime/intelligence-platform/client.d.cts +10 -7
- package/dist/v2/runtime/intelligence-platform/client.d.cts.map +1 -1
- package/dist/v2/runtime/intelligence-platform/client.d.mts +10 -7
- package/dist/v2/runtime/intelligence-platform/client.d.mts.map +1 -1
- package/dist/v2/runtime/intelligence-platform/client.mjs +6 -4
- 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 +1 -0
- package/dist/v2/runtime/runner/agent-runner.d.cts.map +1 -1
- package/dist/v2/runtime/runner/agent-runner.d.mts +1 -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/package.json +6 -6
- package/skills/runtime/SKILL.md +1 -1
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
import "reflect-metadata";
|
|
2
|
+
//#region src/v2/runtime/core/runtime-error-reporter.ts
|
|
3
|
+
const runtimeErrorReporterOption = Symbol("copilotkit.runtimeErrorReporter");
|
|
4
|
+
const SENSITIVE_REQUEST_HEADERS = new Set([
|
|
5
|
+
"authorization",
|
|
6
|
+
"proxy-authorization",
|
|
7
|
+
"cookie",
|
|
8
|
+
"set-cookie",
|
|
9
|
+
"x-api-key",
|
|
10
|
+
"api-key",
|
|
11
|
+
"x-copilotcloud-public-api-key"
|
|
12
|
+
]);
|
|
13
|
+
function sanitizeRequestHeaders(headers) {
|
|
14
|
+
const sanitized = {};
|
|
15
|
+
headers.forEach((value, key) => {
|
|
16
|
+
if (!SENSITIVE_REQUEST_HEADERS.has(key.toLowerCase())) sanitized[key] = value;
|
|
17
|
+
});
|
|
18
|
+
return sanitized;
|
|
19
|
+
}
|
|
20
|
+
function createRuntimeErrorReporter(handler) {
|
|
21
|
+
return { report({ request, error, operation, agentId, threadId, runId, phase, startTime }) {
|
|
22
|
+
if (!handler) return;
|
|
23
|
+
try {
|
|
24
|
+
const result = handler({
|
|
25
|
+
type: "error",
|
|
26
|
+
timestamp: Date.now(),
|
|
27
|
+
context: {
|
|
28
|
+
source: "runtime",
|
|
29
|
+
...threadId ? { threadId } : {},
|
|
30
|
+
...runId ? { runId } : {},
|
|
31
|
+
request: {
|
|
32
|
+
operation,
|
|
33
|
+
method: request.method,
|
|
34
|
+
url: request.url,
|
|
35
|
+
path: new URL(request.url).pathname,
|
|
36
|
+
headers: sanitizeRequestHeaders(request.headers),
|
|
37
|
+
startTime: startTime ?? Date.now()
|
|
38
|
+
},
|
|
39
|
+
...agentId ? { agent: { name: agentId } } : {},
|
|
40
|
+
...phase ? { metadata: { phase } } : {}
|
|
41
|
+
},
|
|
42
|
+
error
|
|
43
|
+
});
|
|
44
|
+
if (result && typeof result.catch === "function") result.catch((handlerError) => {
|
|
45
|
+
console.error("CopilotRuntime onError reporting failed:", handlerError);
|
|
46
|
+
});
|
|
47
|
+
} catch (handlerError) {
|
|
48
|
+
console.error("CopilotRuntime onError reporting failed:", handlerError);
|
|
49
|
+
}
|
|
50
|
+
} };
|
|
51
|
+
}
|
|
52
|
+
function getRuntimeErrorReporterFromOptions(options) {
|
|
53
|
+
return options[runtimeErrorReporterOption];
|
|
54
|
+
}
|
|
55
|
+
function attachRuntimeErrorReporter(runtime, reporter) {
|
|
56
|
+
Object.defineProperty(runtime, runtimeErrorReporterOption, {
|
|
57
|
+
configurable: true,
|
|
58
|
+
value: reporter
|
|
59
|
+
});
|
|
60
|
+
}
|
|
61
|
+
function getRuntimeErrorReporter(runtime) {
|
|
62
|
+
return runtime[runtimeErrorReporterOption];
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
//#endregion
|
|
66
|
+
export { attachRuntimeErrorReporter, createRuntimeErrorReporter, getRuntimeErrorReporter, getRuntimeErrorReporterFromOptions, runtimeErrorReporterOption };
|
|
67
|
+
//# sourceMappingURL=runtime-error-reporter.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"runtime-error-reporter.mjs","names":[],"sources":["../../../../src/v2/runtime/core/runtime-error-reporter.ts"],"sourcesContent":["import type {\n CopilotErrorEvent,\n CopilotErrorHandler,\n} from \"@copilotkit/shared\";\n\nimport type { CopilotRuntimeLike } from \"./runtime\";\n\nexport const runtimeErrorReporterOption = Symbol(\n \"copilotkit.runtimeErrorReporter\",\n);\n\nexport type RuntimeErrorPhase =\n | \"common\"\n | \"sse.factory\"\n | \"sse.subscription\"\n | \"intelligence.startup\"\n | \"intelligence.subscription\";\n\nexport interface RuntimeErrorReportParams {\n request: Request;\n error: unknown;\n operation: string;\n agentId?: string;\n threadId?: string;\n runId?: string;\n phase?: RuntimeErrorPhase;\n startTime?: number;\n}\n\nexport interface RuntimeErrorReporter {\n report(params: RuntimeErrorReportParams): void;\n}\n\nexport interface RuntimeErrorReporterOptions {\n [runtimeErrorReporterOption]?: RuntimeErrorReporter;\n}\n\nconst SENSITIVE_REQUEST_HEADERS = new Set([\n \"authorization\",\n \"proxy-authorization\",\n \"cookie\",\n \"set-cookie\",\n \"x-api-key\",\n \"api-key\",\n \"x-copilotcloud-public-api-key\",\n]);\n\nfunction sanitizeRequestHeaders(headers: Headers): Record<string, string> {\n const sanitized: Record<string, string> = {};\n headers.forEach((value, key) => {\n if (!SENSITIVE_REQUEST_HEADERS.has(key.toLowerCase())) {\n sanitized[key] = value;\n }\n });\n return sanitized;\n}\n\nexport function createRuntimeErrorReporter(\n handler?: CopilotErrorHandler,\n): RuntimeErrorReporter {\n return {\n report({\n request,\n error,\n operation,\n agentId,\n threadId,\n runId,\n phase,\n startTime,\n }) {\n if (!handler) return;\n\n try {\n const event: CopilotErrorEvent = {\n type: \"error\",\n timestamp: Date.now(),\n context: {\n source: \"runtime\",\n ...(threadId ? { threadId } : {}),\n ...(runId ? { runId } : {}),\n request: {\n operation,\n method: request.method,\n url: request.url,\n path: new URL(request.url).pathname,\n headers: sanitizeRequestHeaders(request.headers),\n startTime: startTime ?? Date.now(),\n },\n ...(agentId ? { agent: { name: agentId } } : {}),\n ...(phase ? { metadata: { phase } } : {}),\n },\n error,\n };\n\n const result = handler(event);\n if (result && typeof (result as Promise<void>).catch === \"function\") {\n void (result as Promise<void>).catch((handlerError) => {\n console.error(\n \"CopilotRuntime onError reporting failed:\",\n handlerError,\n );\n });\n }\n } catch (handlerError) {\n console.error(\"CopilotRuntime onError reporting failed:\", handlerError);\n }\n },\n };\n}\n\nexport function getRuntimeErrorReporterFromOptions(\n options: object,\n): RuntimeErrorReporter | undefined {\n return (options as RuntimeErrorReporterOptions)[runtimeErrorReporterOption];\n}\n\nexport function attachRuntimeErrorReporter(\n runtime: object,\n reporter: RuntimeErrorReporter,\n): void {\n Object.defineProperty(runtime, runtimeErrorReporterOption, {\n configurable: true,\n value: reporter,\n });\n}\n\nexport function getRuntimeErrorReporter(\n runtime: CopilotRuntimeLike,\n): RuntimeErrorReporter | undefined {\n return (runtime as CopilotRuntimeLike & RuntimeErrorReporterOptions)[\n runtimeErrorReporterOption\n ];\n}\n"],"mappings":";;AAOA,MAAa,6BAA6B,OACxC,kCACD;AA4BD,MAAM,4BAA4B,IAAI,IAAI;CACxC;CACA;CACA;CACA;CACA;CACA;CACA;CACD,CAAC;AAEF,SAAS,uBAAuB,SAA0C;CACxE,MAAM,YAAoC,EAAE;AAC5C,SAAQ,SAAS,OAAO,QAAQ;AAC9B,MAAI,CAAC,0BAA0B,IAAI,IAAI,aAAa,CAAC,CACnD,WAAU,OAAO;GAEnB;AACF,QAAO;;AAGT,SAAgB,2BACd,SACsB;AACtB,QAAO,EACL,OAAO,EACL,SACA,OACA,WACA,SACA,UACA,OACA,OACA,aACC;AACD,MAAI,CAAC,QAAS;AAEd,MAAI;GAsBF,MAAM,SAAS,QArBkB;IAC/B,MAAM;IACN,WAAW,KAAK,KAAK;IACrB,SAAS;KACP,QAAQ;KACR,GAAI,WAAW,EAAE,UAAU,GAAG,EAAE;KAChC,GAAI,QAAQ,EAAE,OAAO,GAAG,EAAE;KAC1B,SAAS;MACP;MACA,QAAQ,QAAQ;MAChB,KAAK,QAAQ;MACb,MAAM,IAAI,IAAI,QAAQ,IAAI,CAAC;MAC3B,SAAS,uBAAuB,QAAQ,QAAQ;MAChD,WAAW,aAAa,KAAK,KAAK;MACnC;KACD,GAAI,UAAU,EAAE,OAAO,EAAE,MAAM,SAAS,EAAE,GAAG,EAAE;KAC/C,GAAI,QAAQ,EAAE,UAAU,EAAE,OAAO,EAAE,GAAG,EAAE;KACzC;IACD;IACD,CAE4B;AAC7B,OAAI,UAAU,OAAQ,OAAyB,UAAU,WACvD,CAAM,OAAyB,OAAO,iBAAiB;AACrD,YAAQ,MACN,4CACA,aACD;KACD;WAEG,cAAc;AACrB,WAAQ,MAAM,4CAA4C,aAAa;;IAG5E;;AAGH,SAAgB,mCACd,SACkC;AAClC,QAAQ,QAAwC;;AAGlD,SAAgB,2BACd,SACA,UACM;AACN,QAAO,eAAe,SAAS,4BAA4B;EACzD,cAAc;EACd,OAAO;EACR,CAAC;;AAGJ,SAAgB,wBACd,SACkC;AAClC,QAAQ,QACN"}
|
|
@@ -8,6 +8,8 @@ const require_debug_event_bus = require('./debug-event-bus.cjs');
|
|
|
8
8
|
const require_in_memory = require('../runner/in-memory.cjs');
|
|
9
9
|
const require_intelligence = require('../runner/intelligence.cjs');
|
|
10
10
|
const require_telemetry_client = require('../telemetry/telemetry-client.cjs');
|
|
11
|
+
const require_runtime_error_reporter = require('./runtime-error-reporter.cjs');
|
|
12
|
+
const require_learning = require('./learning.cjs');
|
|
11
13
|
let _copilotkit_shared = require("@copilotkit/shared");
|
|
12
14
|
let _copilotkit_license_verifier = require("@copilotkit/license-verifier");
|
|
13
15
|
|
|
@@ -55,6 +57,7 @@ var CopilotSseRuntime = class extends BaseCopilotRuntime {
|
|
|
55
57
|
constructor(options) {
|
|
56
58
|
const channels = options.channels;
|
|
57
59
|
if (Array.isArray(channels) && channels.length > 0) throw new Error("`channels` requires the Intelligence runtime (pass `intelligence`); Intelligence Channels are not available in SSE mode.");
|
|
60
|
+
if (options.ɵlearning !== void 0) throw new Error("`ɵlearning` requires the Intelligence runtime (pass `intelligence`); Learning Containers are not available in SSE mode.");
|
|
58
61
|
super(options, options.runner ?? new require_in_memory.InMemoryAgentRunner());
|
|
59
62
|
this.intelligence = void 0;
|
|
60
63
|
this.mode = _copilotkit_shared.RUNTIME_MODE_SSE;
|
|
@@ -76,6 +79,8 @@ var CopilotIntelligenceRuntime = class CopilotIntelligenceRuntime extends BaseCo
|
|
|
76
79
|
if (!hasWebIdentity && !hasChannels) throw new Error("Intelligence Runtime requires web `identifyUser`, at least one Channel, or both surfaces");
|
|
77
80
|
if (rawOptions.memory !== void 0 && (typeof rawOptions.memory !== "object" || rawOptions.memory === null || typeof rawOptions.memory.access !== "function")) throw new Error("Intelligence Runtime `memory.access` must be a callback");
|
|
78
81
|
if (rawOptions.memory !== void 0 && !hasWebIdentity) throw new Error("Intelligence Runtime web `memory` requires `identifyUser`");
|
|
82
|
+
if (rawOptions.ɵlearning !== void 0 && (typeof rawOptions.ɵlearning !== "object" || rawOptions.ɵlearning === null || !(typeof rawOptions.ɵlearning.containerId === "string" || typeof rawOptions.ɵlearning.containerId === "function"))) throw new Error("Intelligence Runtime `ɵlearning.containerId` must be a stable ID or callback");
|
|
83
|
+
if (typeof rawOptions.ɵlearning?.containerId === "string") require_learning.assertStableLearningContainerId(rawOptions.ɵlearning.containerId);
|
|
79
84
|
super(options, new require_intelligence.IntelligenceAgentRunner({
|
|
80
85
|
url: options.intelligence.ɵgetRunnerWsUrl(),
|
|
81
86
|
authToken: options.intelligence.ɵgetRunnerAuthToken(),
|
|
@@ -84,6 +89,7 @@ var CopilotIntelligenceRuntime = class CopilotIntelligenceRuntime extends BaseCo
|
|
|
84
89
|
}));
|
|
85
90
|
this.mode = _copilotkit_shared.RUNTIME_MODE_INTELLIGENCE;
|
|
86
91
|
this.intelligence = options.intelligence;
|
|
92
|
+
this.learning = options.ɵlearning;
|
|
87
93
|
this.identifyUser = hasWebIdentity ? rawOptions.identifyUser : void 0;
|
|
88
94
|
this.generateThreadNames = options.generateThreadNames ?? true;
|
|
89
95
|
this.licenseChecker = (0, _copilotkit_license_verifier.createLicenseChecker)(this.resolvedLicenseToken);
|
|
@@ -124,6 +130,8 @@ function isA2UIEnabled(a2ui) {
|
|
|
124
130
|
var CopilotRuntimeShim = class {
|
|
125
131
|
constructor(options) {
|
|
126
132
|
this.delegate = hasIntelligenceOptions(options) ? new CopilotIntelligenceRuntime(options) : new CopilotSseRuntime(options);
|
|
133
|
+
const reporter = require_runtime_error_reporter.getRuntimeErrorReporterFromOptions(options);
|
|
134
|
+
if (reporter) require_runtime_error_reporter.attachRuntimeErrorReporter(this, reporter);
|
|
127
135
|
}
|
|
128
136
|
get agents() {
|
|
129
137
|
return this.delegate.agents;
|
|
@@ -170,6 +178,9 @@ var CopilotRuntimeShim = class {
|
|
|
170
178
|
get channels() {
|
|
171
179
|
return isIntelligenceRuntime(this.delegate) ? this.delegate.channels : void 0;
|
|
172
180
|
}
|
|
181
|
+
get learning() {
|
|
182
|
+
return isIntelligenceRuntime(this.delegate) ? this.delegate.learning : void 0;
|
|
183
|
+
}
|
|
173
184
|
get mode() {
|
|
174
185
|
return this.delegate.mode;
|
|
175
186
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"runtime.cjs","names":["pkg","DebugEventBus","resolveForwardHeadersPolicy","createLogger","InMemoryAgentRunner","RUNTIME_MODE_SSE","IntelligenceAgentRunner","RUNTIME_MODE_INTELLIGENCE"],"sources":["../../../../src/v2/runtime/core/runtime.ts"],"sourcesContent":["import type {\n MaybePromise,\n NonEmptyRecord,\n RuntimeMode,\n} from \"@copilotkit/shared\";\nimport {\n RUNTIME_MODE_SSE,\n RUNTIME_MODE_INTELLIGENCE,\n} from \"@copilotkit/shared\";\nimport { createLicenseChecker } from \"@copilotkit/license-verifier\";\nimport type { LicenseChecker } from \"@copilotkit/license-verifier\";\nimport { resolveDebugConfig } from \"@copilotkit/shared\";\nimport type { ResolvedDebugConfig, DebugConfig } from \"@copilotkit/shared\";\nimport { resolveForwardHeadersPolicy } from \"../handlers/header-utils\";\nimport type {\n ForwardHeadersConfig,\n ResolvedForwardHeadersPolicy,\n} from \"../handlers/header-utils\";\nimport type { AbstractAgent } from \"@ag-ui/client\";\nimport type { MCPClientConfig } from \"@ag-ui/mcp-apps-middleware\";\nimport type { A2UIMiddlewareConfig } from \"@ag-ui/a2ui-middleware\";\nimport pkg from \"../../../../package.json\";\nimport type {\n BeforeRequestMiddleware,\n AfterRequestMiddleware,\n} from \"./middleware\";\nimport { createLogger } from \"../../../lib/logger\";\nimport type { CopilotRuntimeLogger } from \"../../../lib/logger\";\nimport { logRuntimeTelemetryDisclosure } from \"../../../lib/telemetry-disclosure\";\nimport type { TranscriptionService } from \"../transcription-service/transcription-service\";\nimport { DebugEventBus } from \"./debug-event-bus\";\nimport type { AgentRunner } from \"../runner/agent-runner\";\nimport { InMemoryAgentRunner } from \"../runner/in-memory\";\nimport { IntelligenceAgentRunner } from \"../runner/intelligence\";\nimport type { CopilotKitIntelligence } from \"../intelligence-platform\";\n// Type-only: @copilotkit/channels-core is the pure-ESM type source, so a value import would break this\n// package's CJS output. The channels are validated + activated (wired to delivery\n// transports) by `startChannels` from @copilotkit/channels-intelligence, called\n// by the Channel-listener bootstrap — not here.\nimport type { Channel } from \"@copilotkit/channels-core\";\nimport telemetry from \"../telemetry/telemetry-client\";\n\nexport const VERSION = pkg.version;\n\ninterface BaseCopilotRuntimeMiddlewareOptions {\n /** If set, middleware only applies to these named agents. Applies to all agents if omitted. */\n agents?: string[];\n}\n\n/** Per-server tool policy belongs to the external middleware and is unsupported at its pinned 0.0.3 release. */\nexport type McpAppsServerConfig = MCPClientConfig & {\n /** Agent to bind this server to. If omitted, the server is available to all agents. */\n agentId?: string;\n};\n\nexport interface McpAppsConfig {\n /** List of MCP server configurations. */\n servers: McpAppsServerConfig[];\n}\n\nexport interface OpenGenerativeUIOptions extends BaseCopilotRuntimeMiddlewareOptions {}\n\nexport type OpenGenerativeUIConfig = boolean | OpenGenerativeUIOptions;\n\ninterface CopilotRuntimeMiddlewares {\n /**\n * Auto-apply A2UIMiddleware to agents at run time.\n * Pass an object to enable and customise behaviour, or omit to disable.\n */\n a2ui?: BaseCopilotRuntimeMiddlewareOptions &\n A2UIMiddlewareConfig & {\n /**\n * Explicit on/off switch. Omit (or set `true`) to enable; set `false`\n * to disable A2UI for this runtime while keeping the rest of the config\n * (e.g. a `schema`/`catalog`) in place. A bare `a2ui: {}` stays enabled\n * for backwards compatibility.\n */\n enabled?: boolean;\n };\n /** Auto-apply MCPAppsMiddleware to agents at run time. */\n mcpApps?: McpAppsConfig;\n /** Auto-apply OpenGenerativeUIMiddleware to agents at run time. */\n openGenerativeUI?: OpenGenerativeUIConfig;\n}\n\n/**\n * Context passed to agent factory functions for per-request agent resolution.\n */\nexport interface AgentFactoryContext {\n /** The incoming HTTP request. */\n request: Request;\n}\n\n/**\n * A function that dynamically creates agents on a per-request basis.\n * Useful for multi-tenant scenarios or request-scoped agent configuration.\n */\nexport type AgentsFactory = (\n ctx: AgentFactoryContext,\n) => MaybePromise<NonEmptyRecord<Record<string, AbstractAgent>>>;\n\n/**\n * Agents can be provided as:\n * - A static record of agents\n * - A Promise that resolves to a record of agents\n * - A factory function that receives request context and returns agents (or a Promise of agents)\n */\nexport type AgentsConfig =\n | MaybePromise<NonEmptyRecord<Record<string, AbstractAgent>>>\n | AgentsFactory;\n\n/**\n * Resolve an AgentsConfig value to a concrete record of agents.\n * If the config is a factory function, it is called with the given request context.\n * Otherwise it is awaited directly (static record or Promise).\n */\nexport async function resolveAgents(\n agents: AgentsConfig,\n request?: Request,\n): Promise<Record<string, AbstractAgent>> {\n if (typeof agents === \"function\") {\n if (!request) {\n throw new Error(\n \"Agent factory function requires a request context, but none was provided.\",\n );\n }\n return agents({ request });\n }\n return agents;\n}\n\ninterface BaseCopilotRuntimeOptions extends CopilotRuntimeMiddlewares {\n /**\n * Map of available agents, or a factory function for per-request agent resolution.\n *\n * Static record:\n * ```ts\n * agents: { support: new SupportAgent(), technical: new TechnicalAgent() }\n * ```\n *\n * Factory function (called per-request):\n * ```ts\n * agents: ({ request }) => {\n * const tenantId = request.headers.get(\"x-tenant-id\");\n * return { default: createAgentForTenant(tenantId) };\n * }\n * ```\n */\n agents: AgentsConfig;\n /** Optional transcription service for audio processing. */\n transcriptionService?: TranscriptionService;\n /** Optional *before* middleware – callback function or webhook URL. */\n beforeRequestMiddleware?: BeforeRequestMiddleware;\n /** Optional *after* middleware – callback function or webhook URL. */\n afterRequestMiddleware?: AfterRequestMiddleware;\n /** Signed license token for server-side feature verification. Falls back to COPILOTKIT_LICENSE_TOKEN env var. */\n licenseToken?: string;\n /** Enable debug logging for the event pipeline. */\n debug?: DebugConfig;\n /**\n * Policy controlling which inbound HTTP headers are forwarded onto the\n * outgoing agent call. By default a built-in denylist strips known\n * infrastructure/proxy/platform headers (`x-forwarded-*`, `x-real-ip`,\n * `x-vercel-*`, `x-copilotcloud-*`, etc.) while `authorization` and custom\n * `x-*` application headers continue to forward (#5712). Set\n * `{ useDefaultDenylist: false }` to restore the previous wide-open behavior.\n */\n forwardHeaders?: ForwardHeadersConfig;\n /**\n * Opt-in flag exposing the client-facing memory proxy routes\n * (`/memories`, `/memories/recall`, `/memories/subscribe`, `/memories/:id`).\n *\n * Defaults to `false` — a **secure default**. When off, every `/memories/*`\n * request 404s as if the route did not exist, so an un-opted-in deployment\n * reveals nothing about memory even when Intelligence is configured. This does\n * NOT affect the agent's own server-side memory tooling (`recall_memory` runs\n * via the Intelligence MCP path, separate from this client REST proxy).\n *\n * Flip to `true` to power a client memory inspector (e.g. the dev console's\n * Memory tab). Existing Intelligence deployments relying on the previously\n * always-on Learning tab must set this to restore it.\n *\n * @deprecated Configure `memory.access` on an Intelligence Runtime. That one\n * policy enables and limits both agent and browser Memory.\n */\n exposeMemoryRoutes?: boolean;\n}\n\nexport interface CopilotRuntimeUser {\n id: string;\n name: string;\n}\n\nexport type IdentifyUserCallback = (\n request: Request,\n) => MaybePromise<CopilotRuntimeUser>;\n\nexport type MemoryAccess = \"none\" | \"read\" | \"read-write\";\n\nexport interface MemoryGrant {\n readonly user: MemoryAccess;\n readonly project: MemoryAccess;\n}\n\nexport type MemoryConsumer = \"agent\" | \"client\";\n\nexport interface CopilotRuntimeMemoryConfig {\n /** Resolves immutable Memory access for one authenticated web request. */\n access(input: {\n readonly request: Request;\n readonly user: CopilotRuntimeUser;\n readonly consumer: MemoryConsumer;\n }): MaybePromise<MemoryGrant | null>;\n}\n\nexport interface CopilotSseRuntimeOptions extends BaseCopilotRuntimeOptions {\n /** The runner to use for running agents in SSE mode. */\n runner?: AgentRunner;\n intelligence?: undefined;\n generateThreadNames?: undefined;\n /** Intelligence Channels require the Intelligence runtime; not available in SSE mode. */\n channels?: undefined;\n}\n\ninterface CopilotIntelligenceRuntimeBaseOptions extends BaseCopilotRuntimeOptions {\n /** Configures Intelligence mode for durable threads and realtime events. */\n intelligence: CopilotKitIntelligence;\n /** Auto-generate short names for newly created threads. */\n generateThreadNames?: boolean;\n /** Max delay (ms) for WebSocket reconnect backoff. @default 10_000 */\n maxReconnectMs?: number;\n /** Max delay (ms) for channel rejoin backoff. @default 30_000 */\n maxRejoinMs?: number;\n /** Lock TTL in seconds. Clamped to a maximum of 3600 (1 hour). @default 20 */\n lockTtlSeconds?: number;\n /** Custom Redis key prefix for the thread lock. */\n lockKeyPrefix?: string;\n /** Interval in seconds at which the runtime renews the thread lock. Clamped to a maximum of 3000 (50 minutes). @default 15 */\n lockHeartbeatIntervalSeconds?: number;\n /**\n * Intelligence Channels declared by this runtime. Each is a\n * `createChannel({ name })` instance. Only available on the Intelligence runtime\n * path. Names are validated (required, lowercase kebab-case, unique) and wired\n * to delivery/egress transports when activated via `startChannels` from\n * `@copilotkit/channels-intelligence` — not at construction.\n */\n}\n\ntype NonEmptyChannels = readonly [Channel, ...Channel[]];\n\n/** Intelligence runtime options with web identity, Channels, or both. */\nexport type CopilotIntelligenceRuntimeOptions =\n CopilotIntelligenceRuntimeBaseOptions &\n (\n | {\n /** Resolves the authenticated user for web requests. */\n identifyUser: IdentifyUserCallback;\n /** Enables agent and browser Memory under one request policy. */\n memory?: CopilotRuntimeMemoryConfig;\n channels?: readonly Channel[];\n }\n | {\n /** Channels-only runtimes expose no functional web surface. */\n identifyUser?: undefined;\n memory?: undefined;\n channels: NonEmptyChannels;\n }\n );\n\nexport type CopilotRuntimeOptions =\n | CopilotSseRuntimeOptions\n | CopilotIntelligenceRuntimeOptions;\n\nexport interface CopilotRuntimeLike {\n agents: CopilotRuntimeOptions[\"agents\"];\n transcriptionService: CopilotRuntimeOptions[\"transcriptionService\"];\n beforeRequestMiddleware: CopilotRuntimeOptions[\"beforeRequestMiddleware\"];\n afterRequestMiddleware: CopilotRuntimeOptions[\"afterRequestMiddleware\"];\n runner: AgentRunner;\n a2ui: CopilotRuntimeOptions[\"a2ui\"];\n mcpApps: CopilotRuntimeOptions[\"mcpApps\"];\n openGenerativeUI: CopilotRuntimeOptions[\"openGenerativeUI\"];\n intelligence?: CopilotKitIntelligence;\n identifyUser?: IdentifyUserCallback;\n mode: RuntimeMode;\n licenseChecker?: LicenseChecker;\n debugEventBus?: DebugEventBus;\n debug: ResolvedDebugConfig;\n debugLogger?: CopilotRuntimeLogger;\n /**\n * Resolved inbound-header forwarding policy read by the /run and /connect call\n * sites. Optional on the published interface so an external `CopilotRuntimeLike`\n * implementor predating this field stays source-compatible (non-breaking minor\n * release). Concrete runtimes (`BaseCopilotRuntime`) always resolve and set it;\n * the call sites coalesce a missing value to the default resolved policy\n * (`resolveForwardHeadersPolicy(undefined)` — default-on denylist).\n */\n forwardHeadersPolicy?: ResolvedForwardHeadersPolicy;\n /**\n * Resolved opt-in flag for the client-facing memory proxy routes. Optional on\n * the published interface so an external `CopilotRuntimeLike` implementor\n * predating this field stays source-compatible; the dispatcher coalesces a\n * missing value to `false` (secure default — routes hidden). Concrete runtimes\n * (`BaseCopilotRuntime`) always resolve and set it.\n */\n exposeMemoryRoutes?: boolean;\n memory?: CopilotRuntimeMemoryConfig;\n}\n\nexport interface CopilotSseRuntimeLike extends CopilotRuntimeLike {\n intelligence?: undefined;\n mode: typeof RUNTIME_MODE_SSE;\n}\n\nexport interface CopilotIntelligenceRuntimeLike extends CopilotRuntimeLike {\n intelligence: CopilotKitIntelligence;\n identifyUser?: IdentifyUserCallback;\n generateThreadNames: boolean;\n lockTtlSeconds: number;\n lockKeyPrefix?: string;\n lockHeartbeatIntervalSeconds: number;\n channels: Channel[];\n mode: typeof RUNTIME_MODE_INTELLIGENCE;\n}\n\nabstract class BaseCopilotRuntime implements CopilotRuntimeLike {\n public agents: CopilotRuntimeOptions[\"agents\"];\n public transcriptionService: CopilotRuntimeOptions[\"transcriptionService\"];\n public beforeRequestMiddleware: CopilotRuntimeOptions[\"beforeRequestMiddleware\"];\n public afterRequestMiddleware: CopilotRuntimeOptions[\"afterRequestMiddleware\"];\n public runner: AgentRunner;\n public a2ui: CopilotRuntimeOptions[\"a2ui\"];\n public mcpApps: CopilotRuntimeOptions[\"mcpApps\"];\n public openGenerativeUI: CopilotRuntimeOptions[\"openGenerativeUI\"];\n public licenseChecker?: LicenseChecker;\n public readonly debugEventBus?: DebugEventBus;\n public debug: ResolvedDebugConfig;\n public debugLogger?: CopilotRuntimeLogger;\n public readonly forwardHeadersPolicy: ResolvedForwardHeadersPolicy;\n public readonly exposeMemoryRoutes: boolean;\n public readonly memory?: CopilotRuntimeMemoryConfig;\n\n /**\n * License token resolved once with the env fallback, so telemetry\n * attribution (below) and subclass feature gating\n * (CopilotIntelligenceRuntime's licenseChecker) read the exact same value\n * instead of each re-applying `?? COPILOTKIT_LICENSE_TOKEN`.\n */\n protected readonly resolvedLicenseToken?: string;\n\n abstract readonly intelligence?: CopilotKitIntelligence;\n abstract readonly mode: RuntimeMode;\n\n constructor(options: BaseCopilotRuntimeOptions, runner: AgentRunner) {\n logRuntimeTelemetryDisclosure();\n\n const {\n agents,\n transcriptionService,\n beforeRequestMiddleware,\n afterRequestMiddleware,\n a2ui,\n mcpApps,\n openGenerativeUI,\n } = options;\n\n this.agents = agents;\n this.transcriptionService = transcriptionService;\n this.beforeRequestMiddleware = beforeRequestMiddleware;\n this.afterRequestMiddleware = afterRequestMiddleware;\n this.a2ui = a2ui || undefined;\n this.mcpApps = mcpApps;\n this.openGenerativeUI = openGenerativeUI;\n this.runner = runner;\n\n // Resolve the license token once (matching the license-verifier's env\n // fallback) so telemetry attribution and subclass feature gating share\n // one value.\n this.resolvedLicenseToken =\n options.licenseToken ?? process.env.COPILOTKIT_LICENSE_TOKEN;\n\n // Attribute telemetry to the licensed customer for *every* runtime mode.\n // Done in the shared base (not the subclasses) so SSE and Intelligence\n // runtimes behave identically — previously only CopilotIntelligenceRuntime\n // set this, so self-hosted SSE users never got a telemetry_id on their\n // runtime events even with a license token configured.\n if (this.resolvedLicenseToken) {\n telemetry.setLicenseToken(this.resolvedLicenseToken);\n }\n\n if (process.env.NODE_ENV !== \"production\") {\n this.debugEventBus = new DebugEventBus();\n }\n // Resolve the inbound-header forwarding policy once (mirroring the\n // `debug` → `ResolvedDebugConfig` resolve-once above) so both the /run and\n // /connect call sites read the exact same resolved policy off the runtime\n // and can never diverge.\n this.forwardHeadersPolicy = resolveForwardHeadersPolicy(\n options.forwardHeaders,\n );\n // Secure default: the client-facing memory proxy routes stay hidden (404)\n // unless a deployment explicitly opts in.\n this.memory = (options as { memory?: CopilotRuntimeMemoryConfig }).memory;\n this.exposeMemoryRoutes =\n this.memory !== undefined || (options.exposeMemoryRoutes ?? false);\n this.debug = resolveDebugConfig(options.debug);\n if (this.debug.enabled) {\n this.debugLogger = createLogger({\n level: \"debug\",\n component: \"copilotkit-debug\",\n });\n }\n }\n}\n\nexport class CopilotSseRuntime\n extends BaseCopilotRuntime\n implements CopilotSseRuntimeLike\n{\n readonly intelligence = undefined;\n readonly mode = RUNTIME_MODE_SSE;\n\n constructor(options: CopilotSseRuntimeOptions) {\n // Runtime guard mirroring the discriminated-union type: the SSE runtime has\n // no Intelligence delivery path, so `channels` cannot be honored here. The\n // type forbids it, but a JS / `as any` caller passing `{ agents, channels }`\n // would otherwise land here and have `channels` silently dropped — fail\n // loud instead.\n const channels = (options as { channels?: unknown[] }).channels;\n if (Array.isArray(channels) && channels.length > 0) {\n throw new Error(\n \"`channels` requires the Intelligence runtime (pass `intelligence`); \" +\n \"Intelligence Channels are not available in SSE mode.\",\n );\n }\n super(options, options.runner ?? new InMemoryAgentRunner());\n }\n}\n\nexport class CopilotIntelligenceRuntime\n extends BaseCopilotRuntime\n implements CopilotIntelligenceRuntimeLike\n{\n readonly intelligence: CopilotKitIntelligence;\n readonly identifyUser?: IdentifyUserCallback;\n readonly generateThreadNames: boolean;\n readonly lockTtlSeconds: number;\n readonly lockKeyPrefix?: string;\n readonly lockHeartbeatIntervalSeconds: number;\n readonly channels: Channel[];\n readonly mode = RUNTIME_MODE_INTELLIGENCE;\n\n /** Maximum allowed lock TTL in seconds (1 hour). */\n static readonly MAX_LOCK_TTL_SECONDS = 3_600;\n /** Maximum allowed heartbeat interval in seconds (50 minutes). */\n static readonly MAX_HEARTBEAT_INTERVAL_SECONDS = 3_000;\n\n constructor(options: CopilotIntelligenceRuntimeOptions) {\n const rawOptions = options as CopilotIntelligenceRuntimeBaseOptions & {\n identifyUser?: unknown;\n channels?: unknown;\n memory?: unknown;\n };\n if (\n rawOptions.identifyUser !== undefined &&\n typeof rawOptions.identifyUser !== \"function\"\n ) {\n throw new Error(\"Intelligence Runtime `identifyUser` must be a callback\");\n }\n if (\n rawOptions.channels !== undefined &&\n !Array.isArray(rawOptions.channels)\n ) {\n throw new Error(\"Intelligence Runtime `channels` must be an array\");\n }\n const hasWebIdentity = typeof rawOptions.identifyUser === \"function\";\n const hasChannels =\n Array.isArray(rawOptions.channels) && rawOptions.channels.length > 0;\n if (!hasWebIdentity && !hasChannels) {\n throw new Error(\n \"Intelligence Runtime requires web `identifyUser`, at least one Channel, or both surfaces\",\n );\n }\n if (\n rawOptions.memory !== undefined &&\n (typeof rawOptions.memory !== \"object\" ||\n rawOptions.memory === null ||\n typeof (rawOptions.memory as { access?: unknown }).access !==\n \"function\")\n ) {\n throw new Error(\n \"Intelligence Runtime `memory.access` must be a callback\",\n );\n }\n if (rawOptions.memory !== undefined && !hasWebIdentity) {\n throw new Error(\n \"Intelligence Runtime web `memory` requires `identifyUser`\",\n );\n }\n super(\n options,\n new IntelligenceAgentRunner({\n url: options.intelligence.ɵgetRunnerWsUrl(),\n authToken: options.intelligence.ɵgetRunnerAuthToken(),\n maxReconnectMs: options.maxReconnectMs,\n maxRejoinMs: options.maxRejoinMs,\n }),\n );\n this.intelligence = options.intelligence;\n this.identifyUser = hasWebIdentity\n ? (rawOptions.identifyUser as IdentifyUserCallback)\n : undefined;\n this.generateThreadNames = options.generateThreadNames ?? true;\n // Telemetry attribution is handled by the base constructor for all modes;\n // here we only need the token for feature gating. Reuse the base-resolved\n // value so gating and attribution can never disagree.\n this.licenseChecker = createLicenseChecker(this.resolvedLicenseToken);\n this.lockTtlSeconds = Math.min(\n options.lockTtlSeconds ?? 20,\n CopilotIntelligenceRuntime.MAX_LOCK_TTL_SECONDS,\n );\n this.lockKeyPrefix = options.lockKeyPrefix;\n this.lockHeartbeatIntervalSeconds = Math.min(\n options.lockHeartbeatIntervalSeconds ?? 15,\n CopilotIntelligenceRuntime.MAX_HEARTBEAT_INTERVAL_SECONDS,\n );\n // Declared Intelligence Channels. Lowercase kebab-case name-shape validation\n // (`assertValidChannelNames`) lives in the channels-intelligence launcher —\n // it can't run here because it's a value import from the pure-ESM\n // `@copilotkit/channels-intelligence`, which this CJS package must not pull in.\n // Name UNIQUENESS across declared Channels is enforced by\n // `ChannelManager.activate()`, not the launcher: the managed path activates\n // one Channel per launcher call, so the launcher never sees the full set.\n // Fail fast on the most common misconfiguration (a missing name) right here\n // at construction, though, rather than only at activation.\n this.channels = [\n ...((rawOptions.channels as readonly Channel[] | undefined) ?? []),\n ];\n for (const c of this.channels) {\n if (!c || typeof c !== \"object\" || !c.name) {\n throw new Error(\n \"Intelligence Channel is missing a `name` — pass createChannel({ name }) for each Channel in `channels`\",\n );\n }\n }\n }\n}\n\nfunction hasIntelligenceOptions(\n options: CopilotRuntimeOptions,\n): options is CopilotIntelligenceRuntimeOptions {\n return \"intelligence\" in options && !!options.intelligence;\n}\n\nexport function isIntelligenceRuntime(\n runtime: CopilotRuntimeLike,\n): runtime is CopilotIntelligenceRuntimeLike {\n return runtime.mode === RUNTIME_MODE_INTELLIGENCE && !!runtime.intelligence;\n}\n\n/**\n * Single source of truth for \"is A2UI on for this runtime?\". Both the run path\n * (which applies `A2UIMiddleware`) and the `/info` response (which tells the\n * client whether to mount the A2UI renderer + catalog context) MUST go through\n * this, so they can never disagree — the divergence between them was the root\n * of CopilotKit/CopilotKit#5369.\n *\n * Backwards compatible: any config object is enabled (matching the historical\n * `!!runtime.a2ui`); only an explicit `enabled: false` turns it off.\n */\nexport function isA2UIEnabled(\n a2ui: CopilotRuntimeOptions[\"a2ui\"],\n): a2ui is NonNullable<CopilotRuntimeOptions[\"a2ui\"]> {\n return !!a2ui && a2ui.enabled !== false;\n}\n\n/**\n * Compile-time phantom brand marking a {@link CopilotRuntime} that was\n * constructed with at least one declared Intelligence Channel. It has no runtime\n * representation — the shim never sets this property; it exists purely so\n * `createCopilotRuntimeHandler` can tell, at the type level, that the resulting\n * handler will carry a non-optional `.channels` control surface.\n */\nexport interface RuntimeWithDeclaredChannels {\n /**\n * @internal Phantom brand key. Never present at runtime; do not read or set.\n */\n readonly __copilotkitChannelsDeclared: true;\n}\n\n/**\n * Instance shape of the {@link CopilotRuntime} compatibility shim. Extends\n * {@link CopilotRuntimeLike} with the Intelligence-only accessors the shim\n * surfaces (all `undefined` in SSE mode). Declared explicitly so the exported\n * `CopilotRuntime` name resolves as a type as well as a value.\n */\nexport interface CopilotRuntime extends CopilotRuntimeLike {\n /** Auto-generate short thread names; `undefined` in SSE mode. */\n generateThreadNames?: boolean;\n /** Thread lock TTL in seconds; `undefined` in SSE mode. */\n lockTtlSeconds?: number;\n /** Custom Redis key prefix for the thread lock; `undefined` in SSE mode. */\n lockKeyPrefix?: string;\n /** Thread lock heartbeat interval in seconds; `undefined` in SSE mode. */\n lockHeartbeatIntervalSeconds?: number;\n /** Declared Intelligence Channels; `undefined` in SSE mode. */\n channels?: Channel[];\n}\n\n/**\n * Constructor type for the {@link CopilotRuntime} compatibility shim.\n *\n * The first overload fires when the caller passes `intelligence` together with a\n * non-empty `channels` tuple: it returns a {@link RuntimeWithDeclaredChannels}-\n * branded runtime, which `createCopilotRuntimeHandler` maps to a handler whose\n * `.channels` is non-optional. Every other configuration (SSE, or Intelligence\n * without channels, or an empty `channels: []`) falls through to the second\n * overload and stays unbranded, so its handler keeps `.channels` optional.\n *\n * A class constructor cannot vary its return type across overloads (it is pinned\n * to the instance type), so the branding lives on this construct-signature\n * interface instead of on the class itself.\n */\nexport interface CopilotRuntimeConstructor {\n new (\n options: CopilotIntelligenceRuntimeBaseOptions &\n (\n | {\n identifyUser: IdentifyUserCallback;\n memory?: CopilotRuntimeMemoryConfig;\n channels: NonEmptyChannels;\n }\n | {\n identifyUser?: undefined;\n memory?: undefined;\n channels: NonEmptyChannels;\n }\n ),\n ): CopilotRuntime & RuntimeWithDeclaredChannels;\n new (options: CopilotRuntimeOptions): CopilotRuntime;\n}\n\n/**\n * Compatibility shim that preserves the legacy `CopilotRuntime` entrypoint.\n * New code should prefer `CopilotSseRuntime` or `CopilotIntelligenceRuntime`.\n *\n * Exported to consumers as the {@link CopilotRuntime} value (typed as\n * {@link CopilotRuntimeConstructor}) rather than as a class, so that the\n * channel-presence brand can flow from construction into the handler type.\n */\nclass CopilotRuntimeShim implements CopilotRuntime {\n private delegate: CopilotRuntimeLike;\n\n constructor(options: CopilotRuntimeOptions) {\n this.delegate = hasIntelligenceOptions(options)\n ? new CopilotIntelligenceRuntime(options)\n : new CopilotSseRuntime(options);\n }\n\n get agents(): CopilotRuntimeOptions[\"agents\"] {\n return this.delegate.agents;\n }\n\n get transcriptionService(): CopilotRuntimeOptions[\"transcriptionService\"] {\n return this.delegate.transcriptionService;\n }\n\n get beforeRequestMiddleware(): CopilotRuntimeOptions[\"beforeRequestMiddleware\"] {\n return this.delegate.beforeRequestMiddleware;\n }\n\n get afterRequestMiddleware(): CopilotRuntimeOptions[\"afterRequestMiddleware\"] {\n return this.delegate.afterRequestMiddleware;\n }\n\n get runner(): AgentRunner {\n return this.delegate.runner;\n }\n\n get a2ui(): CopilotRuntimeOptions[\"a2ui\"] {\n return this.delegate.a2ui;\n }\n\n get mcpApps(): CopilotRuntimeOptions[\"mcpApps\"] {\n return this.delegate.mcpApps;\n }\n\n get openGenerativeUI(): CopilotRuntimeOptions[\"openGenerativeUI\"] {\n return this.delegate.openGenerativeUI;\n }\n\n get intelligence(): CopilotKitIntelligence | undefined {\n return this.delegate.intelligence;\n }\n\n get generateThreadNames(): boolean | undefined {\n return isIntelligenceRuntime(this.delegate)\n ? this.delegate.generateThreadNames\n : undefined;\n }\n\n get identifyUser(): IdentifyUserCallback | undefined {\n return isIntelligenceRuntime(this.delegate)\n ? this.delegate.identifyUser\n : undefined;\n }\n\n get lockTtlSeconds(): number | undefined {\n return isIntelligenceRuntime(this.delegate)\n ? this.delegate.lockTtlSeconds\n : undefined;\n }\n\n get lockKeyPrefix(): string | undefined {\n return isIntelligenceRuntime(this.delegate)\n ? this.delegate.lockKeyPrefix\n : undefined;\n }\n\n get lockHeartbeatIntervalSeconds(): number | undefined {\n return isIntelligenceRuntime(this.delegate)\n ? this.delegate.lockHeartbeatIntervalSeconds\n : undefined;\n }\n\n get channels(): Channel[] | undefined {\n return isIntelligenceRuntime(this.delegate)\n ? this.delegate.channels\n : undefined;\n }\n\n get mode(): RuntimeMode {\n return this.delegate.mode;\n }\n\n get licenseChecker() {\n return this.delegate.licenseChecker;\n }\n\n get debugEventBus() {\n return this.delegate.debugEventBus;\n }\n\n get debug(): ResolvedDebugConfig {\n return this.delegate.debug;\n }\n\n get debugLogger(): CopilotRuntimeLogger | undefined {\n return this.delegate.debugLogger;\n }\n\n get forwardHeadersPolicy(): ResolvedForwardHeadersPolicy {\n return this.delegate.forwardHeadersPolicy;\n }\n\n get exposeMemoryRoutes(): boolean | undefined {\n return this.delegate.exposeMemoryRoutes;\n }\n\n get memory(): CopilotRuntimeMemoryConfig | undefined {\n return this.delegate.memory;\n }\n}\n\n/**\n * The public `CopilotRuntime` constructor. Backed by {@link CopilotRuntimeShim}\n * but typed as {@link CopilotRuntimeConstructor} so that constructing with a\n * non-empty `channels` array yields a {@link RuntimeWithDeclaredChannels}-branded\n * runtime type.\n *\n * The `as unknown as` cast is required (not dishonest widening): the brand is a\n * phantom, compile-time-only marker with no runtime representation, so the shim\n * instances legitimately do not carry the brand property. Behavior is identical\n * to the former `class CopilotRuntime` — this only refines the static type.\n */\nexport const CopilotRuntime: CopilotRuntimeConstructor =\n CopilotRuntimeShim as unknown as CopilotRuntimeConstructor;\n"],"mappings":";;;;;;;;;;;;;;;AA0CA,MAAa,UAAUA,uBAAI;;;;;;AA0E3B,eAAsB,cACpB,QACA,SACwC;AACxC,KAAI,OAAO,WAAW,YAAY;AAChC,MAAI,CAAC,QACH,OAAM,IAAI,MACR,4EACD;AAEH,SAAO,OAAO,EAAE,SAAS,CAAC;;AAE5B,QAAO;;AAqMT,IAAe,qBAAf,MAAgE;CA4B9D,YAAY,SAAoC,QAAqB;AACnE,8DAA+B;EAE/B,MAAM,EACJ,QACA,sBACA,yBACA,wBACA,MACA,SACA,qBACE;AAEJ,OAAK,SAAS;AACd,OAAK,uBAAuB;AAC5B,OAAK,0BAA0B;AAC/B,OAAK,yBAAyB;AAC9B,OAAK,OAAO,QAAQ;AACpB,OAAK,UAAU;AACf,OAAK,mBAAmB;AACxB,OAAK,SAAS;AAKd,OAAK,uBACH,QAAQ,gBAAgB,QAAQ,IAAI;AAOtC,MAAI,KAAK,qBACP,kCAAU,gBAAgB,KAAK,qBAAqB;AAGtD,MAAI,QAAQ,IAAI,aAAa,aAC3B,MAAK,gBAAgB,IAAIC,uCAAe;AAM1C,OAAK,uBAAuBC,iDAC1B,QAAQ,eACT;AAGD,OAAK,SAAU,QAAoD;AACnE,OAAK,qBACH,KAAK,WAAW,WAAc,QAAQ,sBAAsB;AAC9D,OAAK,mDAA2B,QAAQ,MAAM;AAC9C,MAAI,KAAK,MAAM,QACb,MAAK,cAAcC,4BAAa;GAC9B,OAAO;GACP,WAAW;GACZ,CAAC;;;AAKR,IAAa,oBAAb,cACU,mBAEV;CAIE,YAAY,SAAmC;EAM7C,MAAM,WAAY,QAAqC;AACvD,MAAI,M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,iBACd;;CAGN,IAAI,gBAAoC;AACtC,SAAO,sBAAsB,KAAK,SAAS,GACvC,KAAK,SAAS,gBACd;;CAGN,IAAI,+BAAmD;AACrD,SAAO,sBAAsB,KAAK,SAAS,GACvC,KAAK,SAAS,+BACd;;CAGN,IAAI,WAAkC;AACpC,SAAO,sBAAsB,KAAK,SAAS,GACvC,KAAK,SAAS,WACd;;CAGN,IAAI,OAAoB;AACtB,SAAO,KAAK,SAAS;;CAGvB,IAAI,iBAAiB;AACnB,SAAO,KAAK,SAAS;;CAGvB,IAAI,gBAAgB;AAClB,SAAO,KAAK,SAAS;;CAGvB,IAAI,QAA6B;AAC/B,SAAO,KAAK,SAAS;;CAGvB,IAAI,cAAgD;AAClD,SAAO,KAAK,SAAS;;CAGvB,IAAI,uBAAqD;AACvD,SAAO,KAAK,SAAS;;CAGvB,IAAI,qBAA0C;AAC5C,SAAO,KAAK,SAAS;;CAGvB,IAAI,SAAiD;AACnD,SAAO,KAAK,SAAS;;;;;;;;;;;;;;AAezB,MAAa,iBACX"}
|
|
1
|
+
{"version":3,"file":"runtime.cjs","names":["pkg","DebugEventBus","resolveForwardHeadersPolicy","createLogger","InMemoryAgentRunner","RUNTIME_MODE_SSE","IntelligenceAgentRunner","RUNTIME_MODE_INTELLIGENCE","getRuntimeErrorReporterFromOptions"],"sources":["../../../../src/v2/runtime/core/runtime.ts"],"sourcesContent":["import type {\n MaybePromise,\n NonEmptyRecord,\n RuntimeMode,\n} from \"@copilotkit/shared\";\nimport {\n RUNTIME_MODE_SSE,\n RUNTIME_MODE_INTELLIGENCE,\n} from \"@copilotkit/shared\";\nimport { createLicenseChecker } from \"@copilotkit/license-verifier\";\nimport type { LicenseChecker } from \"@copilotkit/license-verifier\";\nimport { resolveDebugConfig } from \"@copilotkit/shared\";\nimport type { ResolvedDebugConfig, DebugConfig } from \"@copilotkit/shared\";\nimport { resolveForwardHeadersPolicy } from \"../handlers/header-utils\";\nimport type {\n ForwardHeadersConfig,\n ResolvedForwardHeadersPolicy,\n} from \"../handlers/header-utils\";\nimport type { AbstractAgent } from \"@ag-ui/client\";\nimport type { MCPClientConfig } from \"@ag-ui/mcp-apps-middleware\";\nimport type { A2UIMiddlewareConfig } from \"@ag-ui/a2ui-middleware\";\nimport pkg from \"../../../../package.json\";\nimport type {\n BeforeRequestMiddleware,\n AfterRequestMiddleware,\n} from \"./middleware\";\nimport { createLogger } from \"../../../lib/logger\";\nimport type { CopilotRuntimeLogger } from \"../../../lib/logger\";\nimport { logRuntimeTelemetryDisclosure } from \"../../../lib/telemetry-disclosure\";\nimport type { TranscriptionService } from \"../transcription-service/transcription-service\";\nimport { DebugEventBus } from \"./debug-event-bus\";\nimport type { AgentRunner } from \"../runner/agent-runner\";\nimport { InMemoryAgentRunner } from \"../runner/in-memory\";\nimport { IntelligenceAgentRunner } from \"../runner/intelligence\";\nimport type { CopilotKitIntelligence } from \"../intelligence-platform\";\n// Type-only: @copilotkit/channels-core is the pure-ESM type source, so a value import would break this\n// package's CJS output. The channels are validated + activated (wired to delivery\n// transports) by `startChannels` from @copilotkit/channels-intelligence, called\n// by the Channel-listener bootstrap — not here.\nimport type { Channel } from \"@copilotkit/channels-core\";\nimport telemetry from \"../telemetry/telemetry-client\";\nimport {\n attachRuntimeErrorReporter,\n getRuntimeErrorReporterFromOptions,\n} from \"./runtime-error-reporter\";\nimport type { CopilotRuntimeLearningConfig } from \"./learning\";\nimport { assertStableLearningContainerId } from \"./learning\";\n\nexport type {\n CopilotRuntimeLearningConfig,\n CopilotRuntimeLearningContext,\n} from \"./learning\";\n\nexport const VERSION = pkg.version;\n\ninterface BaseCopilotRuntimeMiddlewareOptions {\n /** If set, middleware only applies to these named agents. Applies to all agents if omitted. */\n agents?: string[];\n}\n\n/** Per-server tool policy belongs to the external middleware and is unsupported at its pinned 0.0.3 release. */\nexport type McpAppsServerConfig = MCPClientConfig & {\n /** Agent to bind this server to. If omitted, the server is available to all agents. */\n agentId?: string;\n};\n\nexport interface McpAppsConfig {\n /** List of MCP server configurations. */\n servers: McpAppsServerConfig[];\n}\n\nexport interface OpenGenerativeUIOptions extends BaseCopilotRuntimeMiddlewareOptions {}\n\nexport type OpenGenerativeUIConfig = boolean | OpenGenerativeUIOptions;\n\ninterface CopilotRuntimeMiddlewares {\n /**\n * Auto-apply A2UIMiddleware to agents at run time.\n * Pass an object to enable and customise behaviour, or omit to disable.\n */\n a2ui?: BaseCopilotRuntimeMiddlewareOptions &\n A2UIMiddlewareConfig & {\n /**\n * Explicit on/off switch. Omit (or set `true`) to enable; set `false`\n * to disable A2UI for this runtime while keeping the rest of the config\n * (e.g. a `schema`/`catalog`) in place. A bare `a2ui: {}` stays enabled\n * for backwards compatibility.\n */\n enabled?: boolean;\n };\n /** Auto-apply MCPAppsMiddleware to agents at run time. */\n mcpApps?: McpAppsConfig;\n /** Auto-apply OpenGenerativeUIMiddleware to agents at run time. */\n openGenerativeUI?: OpenGenerativeUIConfig;\n}\n\n/**\n * Context passed to agent factory functions for per-request agent resolution.\n */\nexport interface AgentFactoryContext {\n /** The incoming HTTP request. */\n request: Request;\n}\n\n/**\n * A function that dynamically creates agents on a per-request basis.\n * Useful for multi-tenant scenarios or request-scoped agent configuration.\n */\nexport type AgentsFactory = (\n ctx: AgentFactoryContext,\n) => MaybePromise<NonEmptyRecord<Record<string, AbstractAgent>>>;\n\n/**\n * Agents can be provided as:\n * - A static record of agents\n * - A Promise that resolves to a record of agents\n * - A factory function that receives request context and returns agents (or a Promise of agents)\n */\nexport type AgentsConfig =\n | MaybePromise<NonEmptyRecord<Record<string, AbstractAgent>>>\n | AgentsFactory;\n\n/**\n * Resolve an AgentsConfig value to a concrete record of agents.\n * If the config is a factory function, it is called with the given request context.\n * Otherwise it is awaited directly (static record or Promise).\n */\nexport async function resolveAgents(\n agents: AgentsConfig,\n request?: Request,\n): Promise<Record<string, AbstractAgent>> {\n if (typeof agents === \"function\") {\n if (!request) {\n throw new Error(\n \"Agent factory function requires a request context, but none was provided.\",\n );\n }\n return agents({ request });\n }\n return agents;\n}\n\ninterface BaseCopilotRuntimeOptions extends CopilotRuntimeMiddlewares {\n /**\n * Map of available agents, or a factory function for per-request agent resolution.\n *\n * Static record:\n * ```ts\n * agents: { support: new SupportAgent(), technical: new TechnicalAgent() }\n * ```\n *\n * Factory function (called per-request):\n * ```ts\n * agents: ({ request }) => {\n * const tenantId = request.headers.get(\"x-tenant-id\");\n * return { default: createAgentForTenant(tenantId) };\n * }\n * ```\n */\n agents: AgentsConfig;\n /** Optional transcription service for audio processing. */\n transcriptionService?: TranscriptionService;\n /** Optional *before* middleware – callback function or webhook URL. */\n beforeRequestMiddleware?: BeforeRequestMiddleware;\n /** Optional *after* middleware – callback function or webhook URL. */\n afterRequestMiddleware?: AfterRequestMiddleware;\n /** Signed license token for server-side feature verification. Falls back to COPILOTKIT_LICENSE_TOKEN env var. */\n licenseToken?: string;\n /** Enable debug logging for the event pipeline. */\n debug?: DebugConfig;\n /**\n * Policy controlling which inbound HTTP headers are forwarded onto the\n * outgoing agent call. By default a built-in denylist strips known\n * infrastructure/proxy/platform headers (`x-forwarded-*`, `x-real-ip`,\n * `x-vercel-*`, `x-copilotcloud-*`, etc.) while `authorization` and custom\n * `x-*` application headers continue to forward (#5712). Set\n * `{ useDefaultDenylist: false }` to restore the previous wide-open behavior.\n */\n forwardHeaders?: ForwardHeadersConfig;\n /**\n * Opt-in flag exposing the client-facing memory proxy routes\n * (`/memories`, `/memories/recall`, `/memories/subscribe`, `/memories/:id`).\n *\n * Defaults to `false` — a **secure default**. When off, every `/memories/*`\n * request 404s as if the route did not exist, so an un-opted-in deployment\n * reveals nothing about memory even when Intelligence is configured. This does\n * NOT affect the agent's own server-side memory tooling (`recall_memory` runs\n * via the Intelligence MCP path, separate from this client REST proxy).\n *\n * Flip to `true` to power a client memory inspector (e.g. the dev console's\n * Memory tab). Existing Intelligence deployments relying on the previously\n * always-on Learning tab must set this to restore it.\n *\n * @deprecated Configure `memory.access` on an Intelligence Runtime. That one\n * policy enables and limits both agent and browser Memory.\n */\n exposeMemoryRoutes?: boolean;\n}\n\nexport interface CopilotRuntimeUser {\n id: string;\n name: string;\n}\n\nexport type IdentifyUserCallback = (\n request: Request,\n) => MaybePromise<CopilotRuntimeUser>;\n\nexport type MemoryAccess = \"none\" | \"read\" | \"read-write\";\n\nexport interface MemoryGrant {\n readonly user: MemoryAccess;\n readonly project: MemoryAccess;\n}\n\nexport type MemoryConsumer = \"agent\" | \"client\";\n\nexport interface CopilotRuntimeMemoryConfig {\n /** Resolves immutable Memory access for one authenticated web request. */\n access(input: {\n readonly request: Request;\n readonly user: CopilotRuntimeUser;\n readonly consumer: MemoryConsumer;\n }): MaybePromise<MemoryGrant | null>;\n}\n\nexport interface CopilotSseRuntimeOptions extends BaseCopilotRuntimeOptions {\n /** The runner to use for running agents in SSE mode. */\n runner?: AgentRunner;\n intelligence?: undefined;\n generateThreadNames?: undefined;\n /** Intelligence Channels require the Intelligence runtime; not available in SSE mode. */\n channels?: undefined;\n}\n\ninterface CopilotIntelligenceRuntimeBaseOptions extends BaseCopilotRuntimeOptions {\n /** Configures Intelligence mode for durable threads and realtime events. */\n intelligence: CopilotKitIntelligence;\n /** Chooses one stable Learning Container ID for each web or Channel run. */\n ɵlearning?: CopilotRuntimeLearningConfig;\n /** Auto-generate short names for newly created threads. */\n generateThreadNames?: boolean;\n /** Max delay (ms) for WebSocket reconnect backoff. @default 10_000 */\n maxReconnectMs?: number;\n /** Max delay (ms) for channel rejoin backoff. @default 30_000 */\n maxRejoinMs?: number;\n /** Lock TTL in seconds. Clamped to a maximum of 3600 (1 hour). @default 20 */\n lockTtlSeconds?: number;\n /** Custom Redis key prefix for the thread lock. */\n lockKeyPrefix?: string;\n /** Interval in seconds at which the runtime renews the thread lock. Clamped to a maximum of 3000 (50 minutes). @default 15 */\n lockHeartbeatIntervalSeconds?: number;\n /**\n * Intelligence Channels declared by this runtime. Each is a\n * `createChannel({ name })` instance. Only available on the Intelligence runtime\n * path. Names are validated (required, lowercase kebab-case, unique) and wired\n * to delivery/egress transports when activated via `startChannels` from\n * `@copilotkit/channels-intelligence` — not at construction.\n */\n}\n\ntype NonEmptyChannels = readonly [Channel, ...Channel[]];\n\n/** Intelligence runtime options with web identity, Channels, or both. */\nexport type CopilotIntelligenceRuntimeOptions =\n CopilotIntelligenceRuntimeBaseOptions &\n (\n | {\n /** Resolves the authenticated user for web requests. */\n identifyUser: IdentifyUserCallback;\n /** Enables agent and browser Memory under one request policy. */\n memory?: CopilotRuntimeMemoryConfig;\n channels?: readonly Channel[];\n }\n | {\n /** Channels-only runtimes expose no functional web surface. */\n identifyUser?: undefined;\n memory?: undefined;\n channels: NonEmptyChannels;\n }\n );\n\nexport type CopilotRuntimeOptions =\n | CopilotSseRuntimeOptions\n | CopilotIntelligenceRuntimeOptions;\n\nexport interface CopilotRuntimeLike {\n agents: CopilotRuntimeOptions[\"agents\"];\n transcriptionService: CopilotRuntimeOptions[\"transcriptionService\"];\n beforeRequestMiddleware: CopilotRuntimeOptions[\"beforeRequestMiddleware\"];\n afterRequestMiddleware: CopilotRuntimeOptions[\"afterRequestMiddleware\"];\n runner: AgentRunner;\n a2ui: CopilotRuntimeOptions[\"a2ui\"];\n mcpApps: CopilotRuntimeOptions[\"mcpApps\"];\n openGenerativeUI: CopilotRuntimeOptions[\"openGenerativeUI\"];\n intelligence?: CopilotKitIntelligence;\n identifyUser?: IdentifyUserCallback;\n mode: RuntimeMode;\n licenseChecker?: LicenseChecker;\n debugEventBus?: DebugEventBus;\n debug: ResolvedDebugConfig;\n debugLogger?: CopilotRuntimeLogger;\n /**\n * Resolved inbound-header forwarding policy read by the /run and /connect call\n * sites. Optional on the published interface so an external `CopilotRuntimeLike`\n * implementor predating this field stays source-compatible (non-breaking minor\n * release). Concrete runtimes (`BaseCopilotRuntime`) always resolve and set it;\n * the call sites coalesce a missing value to the default resolved policy\n * (`resolveForwardHeadersPolicy(undefined)` — default-on denylist).\n */\n forwardHeadersPolicy?: ResolvedForwardHeadersPolicy;\n /**\n * Resolved opt-in flag for the client-facing memory proxy routes. Optional on\n * the published interface so an external `CopilotRuntimeLike` implementor\n * predating this field stays source-compatible; the dispatcher coalesces a\n * missing value to `false` (secure default — routes hidden). Concrete runtimes\n * (`BaseCopilotRuntime`) always resolve and set it.\n */\n exposeMemoryRoutes?: boolean;\n memory?: CopilotRuntimeMemoryConfig;\n learning?: CopilotRuntimeLearningConfig;\n}\n\nexport interface CopilotSseRuntimeLike extends CopilotRuntimeLike {\n intelligence?: undefined;\n mode: typeof RUNTIME_MODE_SSE;\n}\n\nexport interface CopilotIntelligenceRuntimeLike extends CopilotRuntimeLike {\n intelligence: CopilotKitIntelligence;\n identifyUser?: IdentifyUserCallback;\n generateThreadNames: boolean;\n lockTtlSeconds: number;\n lockKeyPrefix?: string;\n lockHeartbeatIntervalSeconds: number;\n channels: Channel[];\n learning?: CopilotRuntimeLearningConfig;\n mode: typeof RUNTIME_MODE_INTELLIGENCE;\n}\n\nabstract class BaseCopilotRuntime implements CopilotRuntimeLike {\n public agents: CopilotRuntimeOptions[\"agents\"];\n public transcriptionService: CopilotRuntimeOptions[\"transcriptionService\"];\n public beforeRequestMiddleware: CopilotRuntimeOptions[\"beforeRequestMiddleware\"];\n public afterRequestMiddleware: CopilotRuntimeOptions[\"afterRequestMiddleware\"];\n public runner: AgentRunner;\n public a2ui: CopilotRuntimeOptions[\"a2ui\"];\n public mcpApps: CopilotRuntimeOptions[\"mcpApps\"];\n public openGenerativeUI: CopilotRuntimeOptions[\"openGenerativeUI\"];\n public licenseChecker?: LicenseChecker;\n public readonly debugEventBus?: DebugEventBus;\n public debug: ResolvedDebugConfig;\n public debugLogger?: CopilotRuntimeLogger;\n public readonly forwardHeadersPolicy: ResolvedForwardHeadersPolicy;\n public readonly exposeMemoryRoutes: boolean;\n public readonly memory?: CopilotRuntimeMemoryConfig;\n\n /**\n * License token resolved once with the env fallback, so telemetry\n * attribution (below) and subclass feature gating\n * (CopilotIntelligenceRuntime's licenseChecker) read the exact same value\n * instead of each re-applying `?? COPILOTKIT_LICENSE_TOKEN`.\n */\n protected readonly resolvedLicenseToken?: string;\n\n abstract readonly intelligence?: CopilotKitIntelligence;\n abstract readonly mode: RuntimeMode;\n\n constructor(options: BaseCopilotRuntimeOptions, runner: AgentRunner) {\n logRuntimeTelemetryDisclosure();\n\n const {\n agents,\n transcriptionService,\n beforeRequestMiddleware,\n afterRequestMiddleware,\n a2ui,\n mcpApps,\n openGenerativeUI,\n } = options;\n\n this.agents = agents;\n this.transcriptionService = transcriptionService;\n this.beforeRequestMiddleware = beforeRequestMiddleware;\n this.afterRequestMiddleware = afterRequestMiddleware;\n this.a2ui = a2ui || undefined;\n this.mcpApps = mcpApps;\n this.openGenerativeUI = openGenerativeUI;\n this.runner = runner;\n\n // Resolve the license token once (matching the license-verifier's env\n // fallback) so telemetry attribution and subclass feature gating share\n // one value.\n this.resolvedLicenseToken =\n options.licenseToken ?? process.env.COPILOTKIT_LICENSE_TOKEN;\n\n // Attribute telemetry to the licensed customer for *every* runtime mode.\n // Done in the shared base (not the subclasses) so SSE and Intelligence\n // runtimes behave identically — previously only CopilotIntelligenceRuntime\n // set this, so self-hosted SSE users never got a telemetry_id on their\n // runtime events even with a license token configured.\n if (this.resolvedLicenseToken) {\n telemetry.setLicenseToken(this.resolvedLicenseToken);\n }\n\n if (process.env.NODE_ENV !== \"production\") {\n this.debugEventBus = new DebugEventBus();\n }\n // Resolve the inbound-header forwarding policy once (mirroring the\n // `debug` → `ResolvedDebugConfig` resolve-once above) so both the /run and\n // /connect call sites read the exact same resolved policy off the runtime\n // and can never diverge.\n this.forwardHeadersPolicy = resolveForwardHeadersPolicy(\n options.forwardHeaders,\n );\n // Secure default: the client-facing memory proxy routes stay hidden (404)\n // unless a deployment explicitly opts in.\n this.memory = (options as { memory?: CopilotRuntimeMemoryConfig }).memory;\n this.exposeMemoryRoutes =\n this.memory !== undefined || (options.exposeMemoryRoutes ?? false);\n this.debug = resolveDebugConfig(options.debug);\n if (this.debug.enabled) {\n this.debugLogger = createLogger({\n level: \"debug\",\n component: \"copilotkit-debug\",\n });\n }\n }\n}\n\nexport class CopilotSseRuntime\n extends BaseCopilotRuntime\n implements CopilotSseRuntimeLike\n{\n readonly intelligence = undefined;\n readonly mode = RUNTIME_MODE_SSE;\n\n constructor(options: CopilotSseRuntimeOptions) {\n // Runtime guard mirroring the discriminated-union type: the SSE runtime has\n // no Intelligence delivery path, so `channels` cannot be honored here. The\n // type forbids it, but a JS / `as any` caller passing `{ agents, channels }`\n // would otherwise land here and have `channels` silently dropped — fail\n // loud instead.\n const channels = (options as { channels?: unknown[] }).channels;\n if (Array.isArray(channels) && channels.length > 0) {\n throw new Error(\n \"`channels` requires the Intelligence runtime (pass `intelligence`); \" +\n \"Intelligence Channels are not available in SSE mode.\",\n );\n }\n if ((options as { ɵlearning?: unknown }).ɵlearning !== undefined) {\n throw new Error(\n \"`ɵlearning` requires the Intelligence runtime (pass `intelligence`); \" +\n \"Learning Containers are not available in SSE mode.\",\n );\n }\n super(options, options.runner ?? new InMemoryAgentRunner());\n }\n}\n\nexport class CopilotIntelligenceRuntime\n extends BaseCopilotRuntime\n implements CopilotIntelligenceRuntimeLike\n{\n readonly intelligence: CopilotKitIntelligence;\n readonly identifyUser?: IdentifyUserCallback;\n readonly generateThreadNames: boolean;\n readonly lockTtlSeconds: number;\n readonly lockKeyPrefix?: string;\n readonly lockHeartbeatIntervalSeconds: number;\n readonly channels: Channel[];\n readonly learning?: CopilotRuntimeLearningConfig;\n readonly mode = RUNTIME_MODE_INTELLIGENCE;\n\n /** Maximum allowed lock TTL in seconds (1 hour). */\n static readonly MAX_LOCK_TTL_SECONDS = 3_600;\n /** Maximum allowed heartbeat interval in seconds (50 minutes). */\n static readonly MAX_HEARTBEAT_INTERVAL_SECONDS = 3_000;\n\n constructor(options: CopilotIntelligenceRuntimeOptions) {\n const rawOptions = options as CopilotIntelligenceRuntimeBaseOptions & {\n identifyUser?: unknown;\n channels?: unknown;\n memory?: unknown;\n ɵlearning?: unknown;\n };\n if (\n rawOptions.identifyUser !== undefined &&\n typeof rawOptions.identifyUser !== \"function\"\n ) {\n throw new Error(\"Intelligence Runtime `identifyUser` must be a callback\");\n }\n if (\n rawOptions.channels !== undefined &&\n !Array.isArray(rawOptions.channels)\n ) {\n throw new Error(\"Intelligence Runtime `channels` must be an array\");\n }\n const hasWebIdentity = typeof rawOptions.identifyUser === \"function\";\n const hasChannels =\n Array.isArray(rawOptions.channels) && rawOptions.channels.length > 0;\n if (!hasWebIdentity && !hasChannels) {\n throw new Error(\n \"Intelligence Runtime requires web `identifyUser`, at least one Channel, or both surfaces\",\n );\n }\n if (\n rawOptions.memory !== undefined &&\n (typeof rawOptions.memory !== \"object\" ||\n rawOptions.memory === null ||\n typeof (rawOptions.memory as { access?: unknown }).access !==\n \"function\")\n ) {\n throw new Error(\n \"Intelligence Runtime `memory.access` must be a callback\",\n );\n }\n if (rawOptions.memory !== undefined && !hasWebIdentity) {\n throw new Error(\n \"Intelligence Runtime web `memory` requires `identifyUser`\",\n );\n }\n if (\n rawOptions.ɵlearning !== undefined &&\n (typeof rawOptions.ɵlearning !== \"object\" ||\n rawOptions.ɵlearning === null ||\n !(\n typeof (rawOptions.ɵlearning as { containerId?: unknown })\n .containerId === \"string\" ||\n typeof (rawOptions.ɵlearning as { containerId?: unknown })\n .containerId === \"function\"\n ))\n ) {\n throw new Error(\n \"Intelligence Runtime `ɵlearning.containerId` must be a stable ID or callback\",\n );\n }\n if (\n typeof (rawOptions.ɵlearning as { containerId?: unknown } | undefined)\n ?.containerId === \"string\"\n ) {\n assertStableLearningContainerId(\n (rawOptions.ɵlearning as { containerId: string }).containerId,\n );\n }\n super(\n options,\n new IntelligenceAgentRunner({\n url: options.intelligence.ɵgetRunnerWsUrl(),\n authToken: options.intelligence.ɵgetRunnerAuthToken(),\n maxReconnectMs: options.maxReconnectMs,\n maxRejoinMs: options.maxRejoinMs,\n }),\n );\n this.intelligence = options.intelligence;\n this.learning = options.ɵlearning;\n this.identifyUser = hasWebIdentity\n ? (rawOptions.identifyUser as IdentifyUserCallback)\n : undefined;\n this.generateThreadNames = options.generateThreadNames ?? true;\n // Telemetry attribution is handled by the base constructor for all modes;\n // here we only need the token for feature gating. Reuse the base-resolved\n // value so gating and attribution can never disagree.\n this.licenseChecker = createLicenseChecker(this.resolvedLicenseToken);\n this.lockTtlSeconds = Math.min(\n options.lockTtlSeconds ?? 20,\n CopilotIntelligenceRuntime.MAX_LOCK_TTL_SECONDS,\n );\n this.lockKeyPrefix = options.lockKeyPrefix;\n this.lockHeartbeatIntervalSeconds = Math.min(\n options.lockHeartbeatIntervalSeconds ?? 15,\n CopilotIntelligenceRuntime.MAX_HEARTBEAT_INTERVAL_SECONDS,\n );\n // Declared Intelligence Channels. Lowercase kebab-case name-shape validation\n // (`assertValidChannelNames`) lives in the channels-intelligence launcher —\n // it can't run here because it's a value import from the pure-ESM\n // `@copilotkit/channels-intelligence`, which this CJS package must not pull in.\n // Name UNIQUENESS across declared Channels is enforced by\n // `ChannelManager.activate()`, not the launcher: the managed path activates\n // one Channel per launcher call, so the launcher never sees the full set.\n // Fail fast on the most common misconfiguration (a missing name) right here\n // at construction, though, rather than only at activation.\n this.channels = [\n ...((rawOptions.channels as readonly Channel[] | undefined) ?? []),\n ];\n for (const c of this.channels) {\n if (!c || typeof c !== \"object\" || !c.name) {\n throw new Error(\n \"Intelligence Channel is missing a `name` — pass createChannel({ name }) for each Channel in `channels`\",\n );\n }\n }\n }\n}\n\nfunction hasIntelligenceOptions(\n options: CopilotRuntimeOptions,\n): options is CopilotIntelligenceRuntimeOptions {\n return \"intelligence\" in options && !!options.intelligence;\n}\n\nexport function isIntelligenceRuntime(\n runtime: CopilotRuntimeLike,\n): runtime is CopilotIntelligenceRuntimeLike {\n return runtime.mode === RUNTIME_MODE_INTELLIGENCE && !!runtime.intelligence;\n}\n\n/**\n * Single source of truth for \"is A2UI on for this runtime?\". Both the run path\n * (which applies `A2UIMiddleware`) and the `/info` response (which tells the\n * client whether to mount the A2UI renderer + catalog context) MUST go through\n * this, so they can never disagree — the divergence between them was the root\n * of CopilotKit/CopilotKit#5369.\n *\n * Backwards compatible: any config object is enabled (matching the historical\n * `!!runtime.a2ui`); only an explicit `enabled: false` turns it off.\n */\nexport function isA2UIEnabled(\n a2ui: CopilotRuntimeOptions[\"a2ui\"],\n): a2ui is NonNullable<CopilotRuntimeOptions[\"a2ui\"]> {\n return !!a2ui && a2ui.enabled !== false;\n}\n\n/**\n * Compile-time phantom brand marking a {@link CopilotRuntime} that was\n * constructed with at least one declared Intelligence Channel. It has no runtime\n * representation — the shim never sets this property; it exists purely so\n * `createCopilotRuntimeHandler` can tell, at the type level, that the resulting\n * handler will carry a non-optional `.channels` control surface.\n */\nexport interface RuntimeWithDeclaredChannels {\n /**\n * @internal Phantom brand key. Never present at runtime; do not read or set.\n */\n readonly __copilotkitChannelsDeclared: true;\n}\n\n/**\n * Instance shape of the {@link CopilotRuntime} compatibility shim. Extends\n * {@link CopilotRuntimeLike} with the Intelligence-only accessors the shim\n * surfaces (all `undefined` in SSE mode). Declared explicitly so the exported\n * `CopilotRuntime` name resolves as a type as well as a value.\n */\nexport interface CopilotRuntime extends CopilotRuntimeLike {\n /** Auto-generate short thread names; `undefined` in SSE mode. */\n generateThreadNames?: boolean;\n /** Thread lock TTL in seconds; `undefined` in SSE mode. */\n lockTtlSeconds?: number;\n /** Custom Redis key prefix for the thread lock; `undefined` in SSE mode. */\n lockKeyPrefix?: string;\n /** Thread lock heartbeat interval in seconds; `undefined` in SSE mode. */\n lockHeartbeatIntervalSeconds?: number;\n /** Declared Intelligence Channels; `undefined` in SSE mode. */\n channels?: Channel[];\n /** Learning Container selector; `undefined` in SSE mode. */\n learning?: CopilotRuntimeLearningConfig;\n}\n\n/**\n * Constructor type for the {@link CopilotRuntime} compatibility shim.\n *\n * The first overload fires when the caller passes `intelligence` together with a\n * non-empty `channels` tuple: it returns a {@link RuntimeWithDeclaredChannels}-\n * branded runtime, which `createCopilotRuntimeHandler` maps to a handler whose\n * `.channels` is non-optional. Every other configuration (SSE, or Intelligence\n * without channels, or an empty `channels: []`) falls through to the second\n * overload and stays unbranded, so its handler keeps `.channels` optional.\n *\n * A class constructor cannot vary its return type across overloads (it is pinned\n * to the instance type), so the branding lives on this construct-signature\n * interface instead of on the class itself.\n */\nexport interface CopilotRuntimeConstructor {\n new (\n options: CopilotIntelligenceRuntimeBaseOptions &\n (\n | {\n identifyUser: IdentifyUserCallback;\n memory?: CopilotRuntimeMemoryConfig;\n channels: NonEmptyChannels;\n }\n | {\n identifyUser?: undefined;\n memory?: undefined;\n channels: NonEmptyChannels;\n }\n ),\n ): CopilotRuntime & RuntimeWithDeclaredChannels;\n new (options: CopilotRuntimeOptions): CopilotRuntime;\n}\n\n/**\n * Compatibility shim that preserves the legacy `CopilotRuntime` entrypoint.\n * New code should prefer `CopilotSseRuntime` or `CopilotIntelligenceRuntime`.\n *\n * Exported to consumers as the {@link CopilotRuntime} value (typed as\n * {@link CopilotRuntimeConstructor}) rather than as a class, so that the\n * channel-presence brand can flow from construction into the handler type.\n */\nclass CopilotRuntimeShim implements CopilotRuntime {\n private delegate: CopilotRuntimeLike;\n\n constructor(options: CopilotRuntimeOptions) {\n this.delegate = hasIntelligenceOptions(options)\n ? new CopilotIntelligenceRuntime(options)\n : new CopilotSseRuntime(options);\n\n const reporter = getRuntimeErrorReporterFromOptions(options);\n if (reporter) {\n attachRuntimeErrorReporter(this, reporter);\n }\n }\n\n get agents(): CopilotRuntimeOptions[\"agents\"] {\n return this.delegate.agents;\n }\n\n get transcriptionService(): CopilotRuntimeOptions[\"transcriptionService\"] {\n return this.delegate.transcriptionService;\n }\n\n get beforeRequestMiddleware(): CopilotRuntimeOptions[\"beforeRequestMiddleware\"] {\n return this.delegate.beforeRequestMiddleware;\n }\n\n get afterRequestMiddleware(): CopilotRuntimeOptions[\"afterRequestMiddleware\"] {\n return this.delegate.afterRequestMiddleware;\n }\n\n get runner(): AgentRunner {\n return this.delegate.runner;\n }\n\n get a2ui(): CopilotRuntimeOptions[\"a2ui\"] {\n return this.delegate.a2ui;\n }\n\n get mcpApps(): CopilotRuntimeOptions[\"mcpApps\"] {\n return this.delegate.mcpApps;\n }\n\n get openGenerativeUI(): CopilotRuntimeOptions[\"openGenerativeUI\"] {\n return this.delegate.openGenerativeUI;\n }\n\n get intelligence(): CopilotKitIntelligence | undefined {\n return this.delegate.intelligence;\n }\n\n get generateThreadNames(): boolean | undefined {\n return isIntelligenceRuntime(this.delegate)\n ? this.delegate.generateThreadNames\n : undefined;\n }\n\n get identifyUser(): IdentifyUserCallback | undefined {\n return isIntelligenceRuntime(this.delegate)\n ? this.delegate.identifyUser\n : undefined;\n }\n\n get lockTtlSeconds(): number | undefined {\n return isIntelligenceRuntime(this.delegate)\n ? this.delegate.lockTtlSeconds\n : undefined;\n }\n\n get lockKeyPrefix(): string | undefined {\n return isIntelligenceRuntime(this.delegate)\n ? this.delegate.lockKeyPrefix\n : undefined;\n }\n\n get lockHeartbeatIntervalSeconds(): number | undefined {\n return isIntelligenceRuntime(this.delegate)\n ? this.delegate.lockHeartbeatIntervalSeconds\n : undefined;\n }\n\n get channels(): Channel[] | undefined {\n return isIntelligenceRuntime(this.delegate)\n ? this.delegate.channels\n : undefined;\n }\n\n get learning(): CopilotRuntimeLearningConfig | undefined {\n return isIntelligenceRuntime(this.delegate)\n ? this.delegate.learning\n : undefined;\n }\n\n get mode(): RuntimeMode {\n return this.delegate.mode;\n }\n\n get licenseChecker() {\n return this.delegate.licenseChecker;\n }\n\n get debugEventBus() {\n return this.delegate.debugEventBus;\n }\n\n get debug(): ResolvedDebugConfig {\n return this.delegate.debug;\n }\n\n get debugLogger(): CopilotRuntimeLogger | undefined {\n return this.delegate.debugLogger;\n }\n\n get forwardHeadersPolicy(): ResolvedForwardHeadersPolicy {\n return this.delegate.forwardHeadersPolicy;\n }\n\n get exposeMemoryRoutes(): boolean | undefined {\n return this.delegate.exposeMemoryRoutes;\n }\n\n get memory(): CopilotRuntimeMemoryConfig | undefined {\n return this.delegate.memory;\n }\n}\n\n/**\n * The public `CopilotRuntime` constructor. Backed by {@link CopilotRuntimeShim}\n * but typed as {@link CopilotRuntimeConstructor} so that constructing with a\n * non-empty `channels` array yields a {@link RuntimeWithDeclaredChannels}-branded\n * runtime type.\n *\n * The `as unknown as` cast is required (not dishonest widening): the brand is a\n * phantom, compile-time-only marker with no runtime representation, so the shim\n * instances legitimately do not carry the brand property. Behavior is identical\n * to the former `class CopilotRuntime` — this only refines the static type.\n */\nexport const CopilotRuntime: CopilotRuntimeConstructor =\n CopilotRuntimeShim as unknown as CopilotRuntimeConstructor;\n"],"mappings":";;;;;;;;;;;;;;;;;AAqDA,MAAa,UAAUA,uBAAI;;;;;;AA0E3B,eAAsB,cACpB,QACA,SACwC;AACxC,KAAI,OAAO,WAAW,YAAY;AAChC,MAAI,CAAC,QACH,OAAM,IAAI,MACR,4EACD;AAEH,SAAO,OAAO,EAAE,SAAS,CAAC;;AAE5B,QAAO;;AAyMT,IAAe,qBAAf,MAAgE;CA4B9D,YAAY,SAAoC,QAAqB;AACnE,8DAA+B;EAE/B,MAAM,EACJ,QACA,sBACA,yBACA,wBACA,MACA,SACA,qBACE;AAEJ,OAAK,SAAS;AACd,OAAK,uBAAuB;AAC5B,OAAK,0BAA0B;AAC/B,OAAK,yBAAyB;AAC9B,OAAK,OAAO,QAAQ;AACpB,OAAK,UAAU;AACf,OAAK,mBAAmB;AACxB,OAAK,SAAS;AAKd,OAAK,uBACH,QAAQ,gBAAgB,QAAQ,IAAI;AAOtC,MAAI,KAAK,qBACP,kCAAU,gBAAgB,KAAK,qBAAqB;AAGtD,MAAI,QAAQ,IAAI,aAAa,aAC3B,MAAK,gBAAgB,IAAIC,uCAAe;AAM1C,OAAK,uBAAuBC,iDAC1B,QAAQ,eACT;AAGD,OAAK,SAAU,QAAoD;AACnE,OAAK,qBACH,KAAK,WAAW,WAAc,QAAQ,sBAAsB;AAC9D,OAAK,mDAA2B,QAAQ,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AAiD;AACnD,SAAO,KAAK,SAAS;;;;;;;;;;;;;;AAezB,MAAa,iBACX"}
|
|
@@ -6,6 +6,7 @@ import { TranscriptionService } from "../transcription-service/transcription-ser
|
|
|
6
6
|
import { DebugEventBus } from "./debug-event-bus.cjs";
|
|
7
7
|
import { AgentRunner } from "../runner/agent-runner.cjs";
|
|
8
8
|
import { CopilotKitIntelligence } from "../intelligence-platform/client.cjs";
|
|
9
|
+
import { CopilotRuntimeLearningConfig, CopilotRuntimeLearningContext } from "./learning.cjs";
|
|
9
10
|
import { DebugConfig, MaybePromise, NonEmptyRecord, RUNTIME_MODE_INTELLIGENCE, RUNTIME_MODE_SSE, ResolvedDebugConfig, RuntimeMode } from "@copilotkit/shared";
|
|
10
11
|
import { LicenseChecker } from "@copilotkit/license-verifier";
|
|
11
12
|
import { AbstractAgent } from "@ag-ui/client";
|
|
@@ -159,6 +160,8 @@ interface CopilotSseRuntimeOptions extends BaseCopilotRuntimeOptions {
|
|
|
159
160
|
interface CopilotIntelligenceRuntimeBaseOptions extends BaseCopilotRuntimeOptions {
|
|
160
161
|
/** Configures Intelligence mode for durable threads and realtime events. */
|
|
161
162
|
intelligence: CopilotKitIntelligence;
|
|
163
|
+
/** Chooses one stable Learning Container ID for each web or Channel run. */
|
|
164
|
+
ɵlearning?: CopilotRuntimeLearningConfig;
|
|
162
165
|
/** Auto-generate short names for newly created threads. */
|
|
163
166
|
generateThreadNames?: boolean;
|
|
164
167
|
/** Max delay (ms) for WebSocket reconnect backoff. @default 10_000 */
|
|
@@ -218,6 +221,7 @@ interface CopilotRuntimeLike {
|
|
|
218
221
|
*/
|
|
219
222
|
exposeMemoryRoutes?: boolean;
|
|
220
223
|
memory?: CopilotRuntimeMemoryConfig;
|
|
224
|
+
learning?: CopilotRuntimeLearningConfig;
|
|
221
225
|
}
|
|
222
226
|
interface CopilotSseRuntimeLike extends CopilotRuntimeLike {
|
|
223
227
|
intelligence?: undefined;
|
|
@@ -231,6 +235,7 @@ interface CopilotIntelligenceRuntimeLike extends CopilotRuntimeLike {
|
|
|
231
235
|
lockKeyPrefix?: string;
|
|
232
236
|
lockHeartbeatIntervalSeconds: number;
|
|
233
237
|
channels: Channel[];
|
|
238
|
+
learning?: CopilotRuntimeLearningConfig;
|
|
234
239
|
mode: typeof RUNTIME_MODE_INTELLIGENCE;
|
|
235
240
|
}
|
|
236
241
|
declare abstract class BaseCopilotRuntime implements CopilotRuntimeLike {
|
|
@@ -273,6 +278,7 @@ declare class CopilotIntelligenceRuntime extends BaseCopilotRuntime implements C
|
|
|
273
278
|
readonly lockKeyPrefix?: string;
|
|
274
279
|
readonly lockHeartbeatIntervalSeconds: number;
|
|
275
280
|
readonly channels: Channel[];
|
|
281
|
+
readonly learning?: CopilotRuntimeLearningConfig;
|
|
276
282
|
readonly mode: "intelligence";
|
|
277
283
|
/** Maximum allowed lock TTL in seconds (1 hour). */
|
|
278
284
|
static readonly MAX_LOCK_TTL_SECONDS = 3600;
|
|
@@ -322,6 +328,8 @@ interface CopilotRuntime extends CopilotRuntimeLike {
|
|
|
322
328
|
lockHeartbeatIntervalSeconds?: number;
|
|
323
329
|
/** Declared Intelligence Channels; `undefined` in SSE mode. */
|
|
324
330
|
channels?: Channel[];
|
|
331
|
+
/** Learning Container selector; `undefined` in SSE mode. */
|
|
332
|
+
learning?: CopilotRuntimeLearningConfig;
|
|
325
333
|
}
|
|
326
334
|
/**
|
|
327
335
|
* Constructor type for the {@link CopilotRuntime} compatibility shim.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"runtime.d.cts","names":[],"sources":["../../../../src/v2/runtime/core/runtime.ts"],"mappings":"
|
|
1
|
+
{"version":3,"file":"runtime.d.cts","names":[],"sources":["../../../../src/v2/runtime/core/runtime.ts"],"mappings":";;;;;;;;;;;;;;;;;cAqDa,OAAA;AAAA,UAEH,mCAAA;EAFwB;EAIhC,MAAA;AAAA;;KAIU,mBAAA,GAAsB,eAAA;EAJhC,uFAMA,OAAA;AAAA;AA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EAAA,SACA,4BAAA;EAAA,SACA,QAAA,EAAU,OAAA;EAAA,SACV,QAAA,GAAW,4BAAA;EAAA,SACX,IAAA;EArLD;EAAA,gBAwLQ,oBAAA;EAtLP;EAAA,gBAwLO,8BAAA;cAEJ,OAAA,EAAS,iCAAA;AAAA;AAAA,iBA0HP,qBAAA,CACd,OAAA,EAAS,kBAAA,GACR,OAAA,IAAW,8BAAA;;;;;;;;;;;iBAcE,aAAA,CACd,IAAA,EAAM,qBAAA,WACL,IAAA,IAAQ,WAAA,CAAY,qBAAA;;;;;;;;UAWN,2BAAA;EAlVf;;;EAAA,SAsVS,4BAAA;AAAA;;;;;;;UASM,cAAA,SAAuB,kBAAA;EAzVtC;EA2VA,mBAAA;EA1VA;EA4VA,cAAA;EA3VA;EA6VA,aAAA;EA5VA;EA8VA,4BAAA;EArVA;EAuVA,QAAA,GAAW,OAAA;EA/UX;EAiVA,QAAA,GAAW,4BAAA;AAAA;;;;;AA5Ub;;;;;;;;;;UA6ViB,yBAAA;EAAA,KAEb,OAAA,EAAS,qCAAA;IAGD,YAAA,EAAc,oBAAA;IACd,MAAA,GAAS,0BAAA;IACT,QAAA,EAAU,gBAAA;EAAA;IAGV,YAAA;IACA,MAAA;IACA,QAAA,EAAU,gBAAA;EAAA,KAGjB,cAAA,GAAiB,2BAAA;EAAA,KACf,OAAA,EAAS,qBAAA,GAAwB,cAAA;AAAA;;;;;;;;;;;;cAmJ3B,cAAA,EAAgB,yBAAA"}
|
|
@@ -7,6 +7,7 @@ import { DebugEventBus } from "./debug-event-bus.mjs";
|
|
|
7
7
|
import { AgentRunner } from "../runner/agent-runner.mjs";
|
|
8
8
|
import { CopilotKitIntelligence } from "../intelligence-platform/client.mjs";
|
|
9
9
|
import "../intelligence-platform/index.mjs";
|
|
10
|
+
import { CopilotRuntimeLearningConfig, CopilotRuntimeLearningContext } from "./learning.mjs";
|
|
10
11
|
import { DebugConfig, MaybePromise, NonEmptyRecord, RUNTIME_MODE_INTELLIGENCE, RUNTIME_MODE_SSE, ResolvedDebugConfig, RuntimeMode } from "@copilotkit/shared";
|
|
11
12
|
import { LicenseChecker } from "@copilotkit/license-verifier";
|
|
12
13
|
import { AbstractAgent } from "@ag-ui/client";
|
|
@@ -160,6 +161,8 @@ interface CopilotSseRuntimeOptions extends BaseCopilotRuntimeOptions {
|
|
|
160
161
|
interface CopilotIntelligenceRuntimeBaseOptions extends BaseCopilotRuntimeOptions {
|
|
161
162
|
/** Configures Intelligence mode for durable threads and realtime events. */
|
|
162
163
|
intelligence: CopilotKitIntelligence;
|
|
164
|
+
/** Chooses one stable Learning Container ID for each web or Channel run. */
|
|
165
|
+
ɵlearning?: CopilotRuntimeLearningConfig;
|
|
163
166
|
/** Auto-generate short names for newly created threads. */
|
|
164
167
|
generateThreadNames?: boolean;
|
|
165
168
|
/** Max delay (ms) for WebSocket reconnect backoff. @default 10_000 */
|
|
@@ -219,6 +222,7 @@ interface CopilotRuntimeLike {
|
|
|
219
222
|
*/
|
|
220
223
|
exposeMemoryRoutes?: boolean;
|
|
221
224
|
memory?: CopilotRuntimeMemoryConfig;
|
|
225
|
+
learning?: CopilotRuntimeLearningConfig;
|
|
222
226
|
}
|
|
223
227
|
interface CopilotSseRuntimeLike extends CopilotRuntimeLike {
|
|
224
228
|
intelligence?: undefined;
|
|
@@ -232,6 +236,7 @@ interface CopilotIntelligenceRuntimeLike extends CopilotRuntimeLike {
|
|
|
232
236
|
lockKeyPrefix?: string;
|
|
233
237
|
lockHeartbeatIntervalSeconds: number;
|
|
234
238
|
channels: Channel[];
|
|
239
|
+
learning?: CopilotRuntimeLearningConfig;
|
|
235
240
|
mode: typeof RUNTIME_MODE_INTELLIGENCE;
|
|
236
241
|
}
|
|
237
242
|
declare abstract class BaseCopilotRuntime implements CopilotRuntimeLike {
|
|
@@ -274,6 +279,7 @@ declare class CopilotIntelligenceRuntime extends BaseCopilotRuntime implements C
|
|
|
274
279
|
readonly lockKeyPrefix?: string;
|
|
275
280
|
readonly lockHeartbeatIntervalSeconds: number;
|
|
276
281
|
readonly channels: Channel[];
|
|
282
|
+
readonly learning?: CopilotRuntimeLearningConfig;
|
|
277
283
|
readonly mode: "intelligence";
|
|
278
284
|
/** Maximum allowed lock TTL in seconds (1 hour). */
|
|
279
285
|
static readonly MAX_LOCK_TTL_SECONDS = 3600;
|
|
@@ -323,6 +329,8 @@ interface CopilotRuntime extends CopilotRuntimeLike {
|
|
|
323
329
|
lockHeartbeatIntervalSeconds?: number;
|
|
324
330
|
/** Declared Intelligence Channels; `undefined` in SSE mode. */
|
|
325
331
|
channels?: Channel[];
|
|
332
|
+
/** Learning Container selector; `undefined` in SSE mode. */
|
|
333
|
+
learning?: CopilotRuntimeLearningConfig;
|
|
326
334
|
}
|
|
327
335
|
/**
|
|
328
336
|
* Constructor type for the {@link CopilotRuntime} compatibility shim.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"runtime.d.mts","names":[],"sources":["../../../../src/v2/runtime/core/runtime.ts"],"mappings":"
|
|
1
|
+
{"version":3,"file":"runtime.d.mts","names":[],"sources":["../../../../src/v2/runtime/core/runtime.ts"],"mappings":";;;;;;;;;;;;;;;;;;cAqDa,OAAA;AAAA,UAEH,mCAAA;;EAER,MAAA;AAAA;AAJiC;AAAA,KAQvB,mBAAA,GAAsB,eAAA;yFAEhC,OAAA;AAAA;AAAA,UAGe,aAAA;EALc;EAO7B,OAAA,EAAS,mBAAA;AAAA;AAAA,UAGM,uBAAA,SAAgC,mCAAA;AAAA,KAErC,sBAAA,aAAmC,uBAAA;AAAA,UAErC,yBAAA;EAPR;;AAGF;;EASE,IAAA,GAAO,mCAAA,GACL,oBAAA;IAVgF;;AAEpF;;;;IAeM,OAAA;EAAA;EAb6B;EAgBjC,OAAA,GAAU,aAAA;EAXH;EAaP,gBAAA,GAAmB,sBAAA;AAAA;;;;UAMJ,mBAAA;EAnBR;EAqBP,OAAA,EAAS,OAAA;AAAA;;;;;KAOC,aAAA,IACV,GAAA,EAAK,mBA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4BAAA;AAAA;;;;;;;UASM,cAAA,SAAuB,kBAAA;EA1VhC;EA4VN,mBAAA;EA3ViB;EA6VjB,cAAA;EA5VgB;EA8VhB,aAAA;EA7VO;EA+VP,4BAAA;EA9Vc;EAgWd,QAAA,GAAW,OAAA;EAvVY;EAyVvB,QAAA,GAAW,4BAAA;AAAA;;;;;;AA5Ub;;;;;;;;;UA6ViB,yBAAA;EAAA,KAEb,OAAA,EAAS,qCAAA;IAGD,YAAA,EAAc,oBAAA;IACd,MAAA,GAAS,0BAAA;IACT,QAAA,EAAU,gBAAA;EAAA;IAGV,YAAA;IACA,MAAA;IACA,QAAA,EAAU,gBAAA;EAAA,KAGjB,cAAA,GAAiB,2BAAA;EAAA,KACf,OAAA,EAAS,qBAAA,GAAwB,cAAA;AAAA;;;;;;;;;;;;cAmJ3B,cAAA,EAAgB,yBAAA"}
|
|
@@ -8,6 +8,8 @@ import { DebugEventBus } from "./debug-event-bus.mjs";
|
|
|
8
8
|
import { InMemoryAgentRunner } from "../runner/in-memory.mjs";
|
|
9
9
|
import { IntelligenceAgentRunner } from "../runner/intelligence.mjs";
|
|
10
10
|
import telemetry from "../telemetry/telemetry-client.mjs";
|
|
11
|
+
import { attachRuntimeErrorReporter, getRuntimeErrorReporterFromOptions } from "./runtime-error-reporter.mjs";
|
|
12
|
+
import { assertStableLearningContainerId } from "./learning.mjs";
|
|
11
13
|
import { RUNTIME_MODE_INTELLIGENCE, RUNTIME_MODE_SSE, resolveDebugConfig } from "@copilotkit/shared";
|
|
12
14
|
import { createLicenseChecker } from "@copilotkit/license-verifier";
|
|
13
15
|
|
|
@@ -55,6 +57,7 @@ var CopilotSseRuntime = class extends BaseCopilotRuntime {
|
|
|
55
57
|
constructor(options) {
|
|
56
58
|
const channels = options.channels;
|
|
57
59
|
if (Array.isArray(channels) && channels.length > 0) throw new Error("`channels` requires the Intelligence runtime (pass `intelligence`); Intelligence Channels are not available in SSE mode.");
|
|
60
|
+
if (options.ɵlearning !== void 0) throw new Error("`ɵlearning` requires the Intelligence runtime (pass `intelligence`); Learning Containers are not available in SSE mode.");
|
|
58
61
|
super(options, options.runner ?? new InMemoryAgentRunner());
|
|
59
62
|
this.intelligence = void 0;
|
|
60
63
|
this.mode = RUNTIME_MODE_SSE;
|
|
@@ -76,6 +79,8 @@ var CopilotIntelligenceRuntime = class CopilotIntelligenceRuntime extends BaseCo
|
|
|
76
79
|
if (!hasWebIdentity && !hasChannels) throw new Error("Intelligence Runtime requires web `identifyUser`, at least one Channel, or both surfaces");
|
|
77
80
|
if (rawOptions.memory !== void 0 && (typeof rawOptions.memory !== "object" || rawOptions.memory === null || typeof rawOptions.memory.access !== "function")) throw new Error("Intelligence Runtime `memory.access` must be a callback");
|
|
78
81
|
if (rawOptions.memory !== void 0 && !hasWebIdentity) throw new Error("Intelligence Runtime web `memory` requires `identifyUser`");
|
|
82
|
+
if (rawOptions.ɵlearning !== void 0 && (typeof rawOptions.ɵlearning !== "object" || rawOptions.ɵlearning === null || !(typeof rawOptions.ɵlearning.containerId === "string" || typeof rawOptions.ɵlearning.containerId === "function"))) throw new Error("Intelligence Runtime `ɵlearning.containerId` must be a stable ID or callback");
|
|
83
|
+
if (typeof rawOptions.ɵlearning?.containerId === "string") assertStableLearningContainerId(rawOptions.ɵlearning.containerId);
|
|
79
84
|
super(options, new IntelligenceAgentRunner({
|
|
80
85
|
url: options.intelligence.ɵgetRunnerWsUrl(),
|
|
81
86
|
authToken: options.intelligence.ɵgetRunnerAuthToken(),
|
|
@@ -84,6 +89,7 @@ var CopilotIntelligenceRuntime = class CopilotIntelligenceRuntime extends BaseCo
|
|
|
84
89
|
}));
|
|
85
90
|
this.mode = RUNTIME_MODE_INTELLIGENCE;
|
|
86
91
|
this.intelligence = options.intelligence;
|
|
92
|
+
this.learning = options.ɵlearning;
|
|
87
93
|
this.identifyUser = hasWebIdentity ? rawOptions.identifyUser : void 0;
|
|
88
94
|
this.generateThreadNames = options.generateThreadNames ?? true;
|
|
89
95
|
this.licenseChecker = createLicenseChecker(this.resolvedLicenseToken);
|
|
@@ -124,6 +130,8 @@ function isA2UIEnabled(a2ui) {
|
|
|
124
130
|
var CopilotRuntimeShim = class {
|
|
125
131
|
constructor(options) {
|
|
126
132
|
this.delegate = hasIntelligenceOptions(options) ? new CopilotIntelligenceRuntime(options) : new CopilotSseRuntime(options);
|
|
133
|
+
const reporter = getRuntimeErrorReporterFromOptions(options);
|
|
134
|
+
if (reporter) attachRuntimeErrorReporter(this, reporter);
|
|
127
135
|
}
|
|
128
136
|
get agents() {
|
|
129
137
|
return this.delegate.agents;
|
|
@@ -170,6 +178,9 @@ var CopilotRuntimeShim = class {
|
|
|
170
178
|
get channels() {
|
|
171
179
|
return isIntelligenceRuntime(this.delegate) ? this.delegate.channels : void 0;
|
|
172
180
|
}
|
|
181
|
+
get learning() {
|
|
182
|
+
return isIntelligenceRuntime(this.delegate) ? this.delegate.learning : void 0;
|
|
183
|
+
}
|
|
173
184
|
get mode() {
|
|
174
185
|
return this.delegate.mode;
|
|
175
186
|
}
|