@copilotkit/runtime 1.62.2 → 1.63.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (217) hide show
  1. package/dist/_virtual/_rolldown/runtime.mjs +15 -1
  2. package/dist/agent/converters/aisdk.d.cts +1 -1
  3. package/dist/agent/converters/tanstack.d.cts +1 -1
  4. package/dist/agent/index.d.cts +1 -1
  5. package/dist/channels/dist/index.d.cts +10 -0
  6. package/dist/channels/dist/index.d.cts.map +1 -0
  7. package/dist/channels/dist/index.d.mts +10 -0
  8. package/dist/channels/dist/index.d.mts.map +1 -0
  9. package/dist/graphql/inputs/action.input.d.cts +1 -1
  10. package/dist/graphql/inputs/agent-session.input.d.cts +1 -1
  11. package/dist/graphql/inputs/agent-state.input.d.cts +1 -1
  12. package/dist/graphql/inputs/extensions.input.d.cts +1 -1
  13. package/dist/graphql/inputs/forwarded-parameters.input.d.cts +1 -1
  14. package/dist/graphql/inputs/message.input.d.cts +1 -1
  15. package/dist/graphql/types/base/index.d.cts +1 -1
  16. package/dist/graphql/types/converted/index.d.cts +1 -1
  17. package/dist/graphql/types/copilot-response.type.d.cts +1 -1
  18. package/dist/graphql/types/enums.d.cts +1 -1
  19. package/dist/graphql/types/extensions-response.type.d.cts +1 -1
  20. package/dist/graphql/types/message-status.type.d.cts +1 -1
  21. package/dist/graphql/types/response-status.type.d.cts +1 -1
  22. package/dist/index.d.cts +1 -1
  23. package/dist/langgraph.d.cts +1 -1
  24. package/dist/lib/cloud/index.d.cts +1 -1
  25. package/dist/lib/index.d.cts +1 -1
  26. package/dist/lib/integrations/index.d.cts +1 -1
  27. package/dist/lib/integrations/nest/index.d.cts +1 -1
  28. package/dist/lib/integrations/nextjs/app-router.d.cts +1 -1
  29. package/dist/lib/integrations/nextjs/pages-router.d.cts +1 -1
  30. package/dist/lib/integrations/node-express/index.d.cts +1 -1
  31. package/dist/lib/integrations/node-http/index.d.cts +1 -1
  32. package/dist/lib/integrations/shared.d.cts +1 -1
  33. package/dist/lib/logger.d.cts +1 -1
  34. package/dist/lib/observability.d.cts +1 -1
  35. package/dist/lib/runtime/agent-integrations/langgraph/agent.d.cts +1 -1
  36. package/dist/lib/runtime/agent-integrations/langgraph/consts.d.cts +1 -1
  37. package/dist/lib/runtime/agent-integrations/langgraph/index.d.cts +1 -1
  38. package/dist/lib/runtime/copilot-runtime.d.cts +1 -1
  39. package/dist/lib/runtime/mcp-tools-utils.d.cts +1 -1
  40. package/dist/lib/runtime/telemetry-agent-runner.d.cts +1 -1
  41. package/dist/lib/runtime/types.d.cts +1 -1
  42. package/dist/lib/telemetry-client.mjs +1 -1
  43. package/dist/package.cjs +5 -1
  44. package/dist/{package.mjs → runtime/package.mjs} +6 -2
  45. package/dist/runtime/package.mjs.map +1 -0
  46. package/dist/service-adapters/anthropic/anthropic-adapter.d.cts +1 -1
  47. package/dist/service-adapters/bedrock/bedrock-adapter.d.cts +1 -1
  48. package/dist/service-adapters/empty/empty-adapter.d.cts +1 -1
  49. package/dist/service-adapters/events.d.cts +1 -1
  50. package/dist/service-adapters/experimental/ollama/ollama-adapter.d.cts +1 -1
  51. package/dist/service-adapters/google/google-genai-adapter.d.cts +1 -1
  52. package/dist/service-adapters/groq/groq-adapter.d.cts +1 -1
  53. package/dist/service-adapters/index.d.cts +1 -1
  54. package/dist/service-adapters/langchain/langchain-adapter.d.cts +1 -1
  55. package/dist/service-adapters/langchain/langserve.d.cts +1 -1
  56. package/dist/service-adapters/langchain/types.d.cts +1 -1
  57. package/dist/service-adapters/openai/openai-adapter.d.cts +1 -1
  58. package/dist/service-adapters/openai/openai-assistant-adapter.d.cts +1 -1
  59. package/dist/service-adapters/service-adapter.d.cts +1 -1
  60. package/dist/service-adapters/shared/error-utils.d.cts +1 -1
  61. package/dist/service-adapters/shared/sdk-client-utils.d.cts +1 -1
  62. package/dist/service-adapters/unify/unify-adapter.d.cts +1 -1
  63. package/dist/utils/failed-response-status-reasons.d.cts +1 -1
  64. package/dist/v2/express.d.cts +3 -3
  65. package/dist/v2/express.d.mts +2 -2
  66. package/dist/v2/hono.d.cts +3 -3
  67. package/dist/v2/hono.d.mts +2 -2
  68. package/dist/v2/index.d.cts +7 -6
  69. package/dist/v2/index.d.mts +6 -5
  70. package/dist/v2/node.d.cts +1 -1
  71. package/dist/v2/runtime/core/channel-activation-config.cjs +93 -0
  72. package/dist/v2/runtime/core/channel-activation-config.cjs.map +1 -0
  73. package/dist/v2/runtime/core/channel-activation-config.d.cts +34 -0
  74. package/dist/v2/runtime/core/channel-activation-config.d.cts.map +1 -0
  75. package/dist/v2/runtime/core/channel-activation-config.d.mts +34 -0
  76. package/dist/v2/runtime/core/channel-activation-config.d.mts.map +1 -0
  77. package/dist/v2/runtime/core/channel-activation-config.mjs +91 -0
  78. package/dist/v2/runtime/core/channel-activation-config.mjs.map +1 -0
  79. package/dist/v2/runtime/core/channel-manager.cjs +444 -0
  80. package/dist/v2/runtime/core/channel-manager.cjs.map +1 -0
  81. package/dist/v2/runtime/core/channel-manager.d.cts +90 -0
  82. package/dist/v2/runtime/core/channel-manager.d.cts.map +1 -0
  83. package/dist/v2/runtime/core/channel-manager.d.mts +90 -0
  84. package/dist/v2/runtime/core/channel-manager.d.mts.map +1 -0
  85. package/dist/v2/runtime/core/channel-manager.mjs +443 -0
  86. package/dist/v2/runtime/core/channel-manager.mjs.map +1 -0
  87. package/dist/v2/runtime/core/debug-event-bus.d.cts +1 -1
  88. package/dist/v2/runtime/core/fetch-cors.d.cts +1 -1
  89. package/dist/v2/runtime/core/fetch-handler.cjs +98 -2
  90. package/dist/v2/runtime/core/fetch-handler.cjs.map +1 -1
  91. package/dist/v2/runtime/core/fetch-handler.d.cts +60 -4
  92. package/dist/v2/runtime/core/fetch-handler.d.cts.map +1 -1
  93. package/dist/v2/runtime/core/fetch-handler.d.mts +59 -3
  94. package/dist/v2/runtime/core/fetch-handler.d.mts.map +1 -1
  95. package/dist/v2/runtime/core/fetch-handler.mjs +98 -2
  96. package/dist/v2/runtime/core/fetch-handler.mjs.map +1 -1
  97. package/dist/v2/runtime/core/fetch-router.cjs +18 -0
  98. package/dist/v2/runtime/core/fetch-router.cjs.map +1 -1
  99. package/dist/v2/runtime/core/fetch-router.mjs +18 -0
  100. package/dist/v2/runtime/core/fetch-router.mjs.map +1 -1
  101. package/dist/v2/runtime/core/hooks.cjs.map +1 -1
  102. package/dist/v2/runtime/core/hooks.d.cts +11 -1
  103. package/dist/v2/runtime/core/hooks.d.cts.map +1 -1
  104. package/dist/v2/runtime/core/hooks.d.mts +10 -0
  105. package/dist/v2/runtime/core/hooks.d.mts.map +1 -1
  106. package/dist/v2/runtime/core/hooks.mjs.map +1 -1
  107. package/dist/v2/runtime/core/middleware-sse-parser.d.cts +1 -1
  108. package/dist/v2/runtime/core/middleware.d.cts +1 -1
  109. package/dist/v2/runtime/core/runtime.cjs +29 -1
  110. package/dist/v2/runtime/core/runtime.cjs.map +1 -1
  111. package/dist/v2/runtime/core/runtime.d.cts +95 -26
  112. package/dist/v2/runtime/core/runtime.d.cts.map +1 -1
  113. package/dist/v2/runtime/core/runtime.d.mts +94 -25
  114. package/dist/v2/runtime/core/runtime.d.mts.map +1 -1
  115. package/dist/v2/runtime/core/runtime.mjs +30 -2
  116. package/dist/v2/runtime/core/runtime.mjs.map +1 -1
  117. package/dist/v2/runtime/endpoints/express-single.d.cts +1 -1
  118. package/dist/v2/runtime/endpoints/express.cjs +10 -5
  119. package/dist/v2/runtime/endpoints/express.cjs.map +1 -1
  120. package/dist/v2/runtime/endpoints/express.d.cts +30 -4
  121. package/dist/v2/runtime/endpoints/express.d.cts.map +1 -1
  122. package/dist/v2/runtime/endpoints/express.d.mts +29 -3
  123. package/dist/v2/runtime/endpoints/express.d.mts.map +1 -1
  124. package/dist/v2/runtime/endpoints/express.mjs +10 -5
  125. package/dist/v2/runtime/endpoints/express.mjs.map +1 -1
  126. package/dist/v2/runtime/endpoints/hono-single.d.cts +1 -1
  127. package/dist/v2/runtime/endpoints/hono.cjs +7 -3
  128. package/dist/v2/runtime/endpoints/hono.cjs.map +1 -1
  129. package/dist/v2/runtime/endpoints/hono.d.cts +30 -16
  130. package/dist/v2/runtime/endpoints/hono.d.cts.map +1 -1
  131. package/dist/v2/runtime/endpoints/hono.d.mts +29 -15
  132. package/dist/v2/runtime/endpoints/hono.d.mts.map +1 -1
  133. package/dist/v2/runtime/endpoints/hono.mjs +7 -3
  134. package/dist/v2/runtime/endpoints/hono.mjs.map +1 -1
  135. package/dist/v2/runtime/endpoints/index.d.cts +3 -3
  136. package/dist/v2/runtime/endpoints/index.d.mts +2 -2
  137. package/dist/v2/runtime/endpoints/node-fetch-handler.d.cts +1 -1
  138. package/dist/v2/runtime/endpoints/node.cjs +12 -1
  139. package/dist/v2/runtime/endpoints/node.cjs.map +1 -1
  140. package/dist/v2/runtime/endpoints/node.d.cts +22 -2
  141. package/dist/v2/runtime/endpoints/node.d.cts.map +1 -1
  142. package/dist/v2/runtime/endpoints/node.d.mts +21 -1
  143. package/dist/v2/runtime/endpoints/node.d.mts.map +1 -1
  144. package/dist/v2/runtime/endpoints/node.mjs +12 -1
  145. package/dist/v2/runtime/endpoints/node.mjs.map +1 -1
  146. package/dist/v2/runtime/endpoints/single-route-helpers.cjs +1 -0
  147. package/dist/v2/runtime/endpoints/single-route-helpers.cjs.map +1 -1
  148. package/dist/v2/runtime/endpoints/single-route-helpers.mjs +1 -0
  149. package/dist/v2/runtime/endpoints/single-route-helpers.mjs.map +1 -1
  150. package/dist/v2/runtime/express.d.cts +2 -2
  151. package/dist/v2/runtime/express.d.mts +1 -1
  152. package/dist/v2/runtime/handlers/get-runtime-info.cjs +1 -0
  153. package/dist/v2/runtime/handlers/get-runtime-info.cjs.map +1 -1
  154. package/dist/v2/runtime/handlers/get-runtime-info.mjs +1 -0
  155. package/dist/v2/runtime/handlers/get-runtime-info.mjs.map +1 -1
  156. package/dist/v2/runtime/handlers/handle-connect.cjs +2 -1
  157. package/dist/v2/runtime/handlers/handle-connect.cjs.map +1 -1
  158. package/dist/v2/runtime/handlers/handle-connect.mjs +2 -1
  159. package/dist/v2/runtime/handlers/handle-connect.mjs.map +1 -1
  160. package/dist/v2/runtime/handlers/handle-suggest.cjs +83 -0
  161. package/dist/v2/runtime/handlers/handle-suggest.cjs.map +1 -0
  162. package/dist/v2/runtime/handlers/handle-suggest.mjs +82 -0
  163. package/dist/v2/runtime/handlers/handle-suggest.mjs.map +1 -0
  164. package/dist/v2/runtime/handlers/header-utils.cjs +169 -9
  165. package/dist/v2/runtime/handlers/header-utils.cjs.map +1 -1
  166. package/dist/v2/runtime/handlers/header-utils.d.cts +54 -0
  167. package/dist/v2/runtime/handlers/header-utils.d.cts.map +1 -0
  168. package/dist/v2/runtime/handlers/header-utils.d.mts +54 -0
  169. package/dist/v2/runtime/handlers/header-utils.d.mts.map +1 -0
  170. package/dist/v2/runtime/handlers/header-utils.mjs +168 -9
  171. package/dist/v2/runtime/handlers/header-utils.mjs.map +1 -1
  172. package/dist/v2/runtime/handlers/intelligence/memories.cjs +209 -0
  173. package/dist/v2/runtime/handlers/intelligence/memories.cjs.map +1 -0
  174. package/dist/v2/runtime/handlers/intelligence/memories.mjs +204 -0
  175. package/dist/v2/runtime/handlers/intelligence/memories.mjs.map +1 -0
  176. package/dist/v2/runtime/handlers/shared/agent-utils.cjs +18 -5
  177. package/dist/v2/runtime/handlers/shared/agent-utils.cjs.map +1 -1
  178. package/dist/v2/runtime/handlers/shared/agent-utils.mjs +18 -5
  179. package/dist/v2/runtime/handlers/shared/agent-utils.mjs.map +1 -1
  180. package/dist/v2/runtime/handlers/shared/sse-response.cjs +4 -4
  181. package/dist/v2/runtime/handlers/shared/sse-response.cjs.map +1 -1
  182. package/dist/v2/runtime/handlers/shared/sse-response.mjs +4 -4
  183. package/dist/v2/runtime/handlers/shared/sse-response.mjs.map +1 -1
  184. package/dist/v2/runtime/handlers/sse/connect.cjs +2 -2
  185. package/dist/v2/runtime/handlers/sse/connect.cjs.map +1 -1
  186. package/dist/v2/runtime/handlers/sse/connect.mjs +3 -3
  187. package/dist/v2/runtime/handlers/sse/connect.mjs.map +1 -1
  188. package/dist/v2/runtime/hono.d.cts +2 -2
  189. package/dist/v2/runtime/hono.d.mts +1 -1
  190. package/dist/v2/runtime/index.d.cts +6 -5
  191. package/dist/v2/runtime/index.d.cts.map +1 -1
  192. package/dist/v2/runtime/index.d.mts +5 -4
  193. package/dist/v2/runtime/index.d.mts.map +1 -1
  194. package/dist/v2/runtime/intelligence-platform/client.cjs +71 -2
  195. package/dist/v2/runtime/intelligence-platform/client.cjs.map +1 -1
  196. package/dist/v2/runtime/intelligence-platform/client.d.cts +113 -1
  197. package/dist/v2/runtime/intelligence-platform/client.d.cts.map +1 -1
  198. package/dist/v2/runtime/intelligence-platform/client.d.mts +112 -0
  199. package/dist/v2/runtime/intelligence-platform/client.d.mts.map +1 -1
  200. package/dist/v2/runtime/intelligence-platform/client.mjs +71 -2
  201. package/dist/v2/runtime/intelligence-platform/client.mjs.map +1 -1
  202. package/dist/v2/runtime/node.d.cts +1 -1
  203. package/dist/v2/runtime/runner/agent-runner.d.cts +1 -1
  204. package/dist/v2/runtime/runner/in-memory.cjs +35 -19
  205. package/dist/v2/runtime/runner/in-memory.cjs.map +1 -1
  206. package/dist/v2/runtime/runner/in-memory.d.cts +13 -1
  207. package/dist/v2/runtime/runner/in-memory.d.cts.map +1 -1
  208. package/dist/v2/runtime/runner/in-memory.d.mts +12 -0
  209. package/dist/v2/runtime/runner/in-memory.d.mts.map +1 -1
  210. package/dist/v2/runtime/runner/in-memory.mjs +35 -19
  211. package/dist/v2/runtime/runner/in-memory.mjs.map +1 -1
  212. package/dist/v2/runtime/runner/index.d.cts +1 -1
  213. package/dist/v2/runtime/runner/intelligence.d.cts +1 -1
  214. package/dist/v2/runtime/telemetry/telemetry-client.mjs +1 -1
  215. package/dist/v2/runtime/transcription-service/transcription-service.d.cts +1 -1
  216. package/package.json +9 -3
  217. package/dist/package.mjs.map +0 -1
@@ -1,4 +1,5 @@
1
1
  import "reflect-metadata";
2
+ import { ForwardHeadersConfig, ResolvedForwardHeadersPolicy } from "../handlers/header-utils.mjs";
2
3
  import { AfterRequestMiddleware, BeforeRequestMiddleware } from "./middleware.mjs";
3
4
  import { CopilotRuntimeLogger } from "../../../lib/logger.mjs";
4
5
  import { TranscriptionService } from "../transcription-service/transcription-service.mjs";
@@ -10,6 +11,7 @@ import { LicenseChecker } from "@copilotkit/license-verifier";
10
11
  import { AbstractAgent } from "@ag-ui/client";
11
12
  import { A2UIMiddlewareConfig } from "@ag-ui/a2ui-middleware";
12
13
  import { MCPClientConfig } from "@ag-ui/mcp-apps-middleware";
14
+ import { Channel } from "@copilotkit/channels-core";
13
15
 
14
16
  //#region src/v2/runtime/core/runtime.d.ts
15
17
  declare const VERSION: string;
@@ -98,6 +100,15 @@ interface BaseCopilotRuntimeOptions extends CopilotRuntimeMiddlewares {
98
100
  licenseToken?: string;
99
101
  /** Enable debug logging for the event pipeline. */
100
102
  debug?: DebugConfig;
103
+ /**
104
+ * Policy controlling which inbound HTTP headers are forwarded onto the
105
+ * outgoing agent call. By default a built-in denylist strips known
106
+ * infrastructure/proxy/platform headers (`x-forwarded-*`, `x-real-ip`,
107
+ * `x-vercel-*`, `x-copilotcloud-*`, etc.) while `authorization` and custom
108
+ * `x-*` application headers continue to forward (#5712). Set
109
+ * `{ useDefaultDenylist: false }` to restore the previous wide-open behavior.
110
+ */
111
+ forwardHeaders?: ForwardHeadersConfig;
101
112
  }
102
113
  interface CopilotRuntimeUser {
103
114
  id: string;
@@ -109,6 +120,8 @@ interface CopilotSseRuntimeOptions extends BaseCopilotRuntimeOptions {
109
120
  runner?: AgentRunner;
110
121
  intelligence?: undefined;
111
122
  generateThreadNames?: undefined;
123
+ /** Intelligence Channels require the Intelligence runtime; not available in SSE mode. */
124
+ channels?: undefined;
112
125
  }
113
126
  interface CopilotIntelligenceRuntimeOptions extends BaseCopilotRuntimeOptions {
114
127
  /** Configures Intelligence mode for durable threads and realtime events. */
@@ -127,6 +140,14 @@ interface CopilotIntelligenceRuntimeOptions extends BaseCopilotRuntimeOptions {
127
140
  lockKeyPrefix?: string;
128
141
  /** Interval in seconds at which the runtime renews the thread lock. Clamped to a maximum of 3000 (50 minutes). @default 15 */
129
142
  lockHeartbeatIntervalSeconds?: number;
143
+ /**
144
+ * Intelligence Channels declared by this runtime. Each is a
145
+ * `createChannel({ name })` instance. Only available on the Intelligence runtime
146
+ * path. Names are validated (required, lowercase kebab-case, unique) and wired
147
+ * to delivery/egress transports when activated via `startChannels` from
148
+ * `@copilotkit/channels-intelligence` — not at construction.
149
+ */
150
+ channels?: Channel[];
130
151
  }
131
152
  type CopilotRuntimeOptions = CopilotSseRuntimeOptions | CopilotIntelligenceRuntimeOptions;
132
153
  interface CopilotRuntimeLike {
@@ -145,6 +166,15 @@ interface CopilotRuntimeLike {
145
166
  debugEventBus?: DebugEventBus;
146
167
  debug: ResolvedDebugConfig;
147
168
  debugLogger?: CopilotRuntimeLogger;
169
+ /**
170
+ * Resolved inbound-header forwarding policy read by the /run and /connect call
171
+ * sites. Optional on the published interface so an external `CopilotRuntimeLike`
172
+ * implementor predating this field stays source-compatible (non-breaking minor
173
+ * release). Concrete runtimes (`BaseCopilotRuntime`) always resolve and set it;
174
+ * the call sites coalesce a missing value to the default resolved policy
175
+ * (`resolveForwardHeadersPolicy(undefined)` — default-on denylist).
176
+ */
177
+ forwardHeadersPolicy?: ResolvedForwardHeadersPolicy;
148
178
  }
149
179
  interface CopilotSseRuntimeLike extends CopilotRuntimeLike {
150
180
  intelligence?: undefined;
@@ -157,6 +187,7 @@ interface CopilotIntelligenceRuntimeLike extends CopilotRuntimeLike {
157
187
  lockTtlSeconds: number;
158
188
  lockKeyPrefix?: string;
159
189
  lockHeartbeatIntervalSeconds: number;
190
+ channels: Channel[];
160
191
  mode: typeof RUNTIME_MODE_INTELLIGENCE;
161
192
  }
162
193
  declare abstract class BaseCopilotRuntime implements CopilotRuntimeLike {
@@ -172,6 +203,7 @@ declare abstract class BaseCopilotRuntime implements CopilotRuntimeLike {
172
203
  readonly debugEventBus?: DebugEventBus;
173
204
  debug: ResolvedDebugConfig;
174
205
  debugLogger?: CopilotRuntimeLogger;
206
+ readonly forwardHeadersPolicy: ResolvedForwardHeadersPolicy;
175
207
  /**
176
208
  * License token resolved once with the env fallback, so telemetry
177
209
  * attribution (below) and subclass feature gating
@@ -195,6 +227,7 @@ declare class CopilotIntelligenceRuntime extends BaseCopilotRuntime implements C
195
227
  readonly lockTtlSeconds: number;
196
228
  readonly lockKeyPrefix?: string;
197
229
  readonly lockHeartbeatIntervalSeconds: number;
230
+ readonly channels: Channel[];
198
231
  readonly mode: "intelligence";
199
232
  /** Maximum allowed lock TTL in seconds (1 hour). */
200
233
  static readonly MAX_LOCK_TTL_SECONDS = 3600;
@@ -215,32 +248,68 @@ declare function isIntelligenceRuntime(runtime: CopilotRuntimeLike): runtime is
215
248
  */
216
249
  declare function isA2UIEnabled(a2ui: CopilotRuntimeOptions["a2ui"]): a2ui is NonNullable<CopilotRuntimeOptions["a2ui"]>;
217
250
  /**
218
- * Compatibility shim that preserves the legacy `CopilotRuntime` entrypoint.
219
- * New code should prefer `CopilotSseRuntime` or `CopilotIntelligenceRuntime`.
251
+ * Compile-time phantom brand marking a {@link CopilotRuntime} that was
252
+ * constructed with at least one declared Intelligence Channel. It has no runtime
253
+ * representation — the shim never sets this property; it exists purely so
254
+ * `createCopilotRuntimeHandler` can tell, at the type level, that the resulting
255
+ * handler will carry a non-optional `.channels` control surface.
220
256
  */
221
- declare class CopilotRuntime implements CopilotRuntimeLike {
222
- private delegate;
223
- constructor(options: CopilotRuntimeOptions);
224
- get agents(): CopilotRuntimeOptions["agents"];
225
- get transcriptionService(): CopilotRuntimeOptions["transcriptionService"];
226
- get beforeRequestMiddleware(): CopilotRuntimeOptions["beforeRequestMiddleware"];
227
- get afterRequestMiddleware(): CopilotRuntimeOptions["afterRequestMiddleware"];
228
- get runner(): AgentRunner;
229
- get a2ui(): CopilotRuntimeOptions["a2ui"];
230
- get mcpApps(): CopilotRuntimeOptions["mcpApps"];
231
- get openGenerativeUI(): CopilotRuntimeOptions["openGenerativeUI"];
232
- get intelligence(): CopilotKitIntelligence | undefined;
233
- get generateThreadNames(): boolean | undefined;
234
- get identifyUser(): IdentifyUserCallback | undefined;
235
- get lockTtlSeconds(): number | undefined;
236
- get lockKeyPrefix(): string | undefined;
237
- get lockHeartbeatIntervalSeconds(): number | undefined;
238
- get mode(): RuntimeMode;
239
- get licenseChecker(): LicenseChecker;
240
- get debugEventBus(): DebugEventBus;
241
- get debug(): ResolvedDebugConfig;
242
- get debugLogger(): CopilotRuntimeLogger | undefined;
257
+ interface RuntimeWithDeclaredChannels {
258
+ /**
259
+ * @internal Phantom brand key. Never present at runtime; do not read or set.
260
+ */
261
+ readonly __copilotkitChannelsDeclared: true;
243
262
  }
263
+ /**
264
+ * Instance shape of the {@link CopilotRuntime} compatibility shim. Extends
265
+ * {@link CopilotRuntimeLike} with the Intelligence-only accessors the shim
266
+ * surfaces (all `undefined` in SSE mode). Declared explicitly so the exported
267
+ * `CopilotRuntime` name resolves as a type as well as a value.
268
+ */
269
+ interface CopilotRuntime extends CopilotRuntimeLike {
270
+ /** Auto-generate short thread names; `undefined` in SSE mode. */
271
+ generateThreadNames?: boolean;
272
+ /** Thread lock TTL in seconds; `undefined` in SSE mode. */
273
+ lockTtlSeconds?: number;
274
+ /** Custom Redis key prefix for the thread lock; `undefined` in SSE mode. */
275
+ lockKeyPrefix?: string;
276
+ /** Thread lock heartbeat interval in seconds; `undefined` in SSE mode. */
277
+ lockHeartbeatIntervalSeconds?: number;
278
+ /** Declared Intelligence Channels; `undefined` in SSE mode. */
279
+ channels?: Channel[];
280
+ }
281
+ /**
282
+ * Constructor type for the {@link CopilotRuntime} compatibility shim.
283
+ *
284
+ * The first overload fires when the caller passes `intelligence` together with a
285
+ * non-empty `channels` tuple: it returns a {@link RuntimeWithDeclaredChannels}-
286
+ * branded runtime, which `createCopilotRuntimeHandler` maps to a handler whose
287
+ * `.channels` is non-optional. Every other configuration (SSE, or Intelligence
288
+ * without channels, or an empty `channels: []`) falls through to the second
289
+ * overload and stays unbranded, so its handler keeps `.channels` optional.
290
+ *
291
+ * A class constructor cannot vary its return type across overloads (it is pinned
292
+ * to the instance type), so the branding lives on this construct-signature
293
+ * interface instead of on the class itself.
294
+ */
295
+ interface CopilotRuntimeConstructor {
296
+ new (options: Omit<CopilotIntelligenceRuntimeOptions, "channels"> & {
297
+ channels: readonly [Channel, ...Channel[]];
298
+ }): CopilotRuntime & RuntimeWithDeclaredChannels;
299
+ new (options: CopilotRuntimeOptions): CopilotRuntime;
300
+ }
301
+ /**
302
+ * The public `CopilotRuntime` constructor. Backed by {@link CopilotRuntimeShim}
303
+ * but typed as {@link CopilotRuntimeConstructor} so that constructing with a
304
+ * non-empty `channels` array yields a {@link RuntimeWithDeclaredChannels}-branded
305
+ * runtime type.
306
+ *
307
+ * The `as unknown as` cast is required (not dishonest widening): the brand is a
308
+ * phantom, compile-time-only marker with no runtime representation, so the shim
309
+ * instances legitimately do not carry the brand property. Behavior is identical
310
+ * to the former `class CopilotRuntime` — this only refines the static type.
311
+ */
312
+ declare const CopilotRuntime: CopilotRuntimeConstructor;
244
313
  //#endregion
245
- export { AgentFactoryContext, AgentsConfig, AgentsFactory, CopilotIntelligenceRuntime, CopilotIntelligenceRuntimeLike, CopilotIntelligenceRuntimeOptions, CopilotRuntime, CopilotRuntimeLike, CopilotRuntimeOptions, CopilotRuntimeUser, CopilotSseRuntime, CopilotSseRuntimeLike, CopilotSseRuntimeOptions, IdentifyUserCallback, McpAppsConfig, McpAppsServerConfig, OpenGenerativeUIConfig, OpenGenerativeUIOptions, VERSION, isA2UIEnabled, isIntelligenceRuntime, resolveAgents };
314
+ export { AgentFactoryContext, AgentsConfig, AgentsFactory, CopilotIntelligenceRuntime, CopilotIntelligenceRuntimeLike, CopilotIntelligenceRuntimeOptions, CopilotRuntime, CopilotRuntimeConstructor, CopilotRuntimeLike, CopilotRuntimeOptions, CopilotRuntimeUser, CopilotSseRuntime, CopilotSseRuntimeLike, CopilotSseRuntimeOptions, IdentifyUserCallback, McpAppsConfig, McpAppsServerConfig, OpenGenerativeUIConfig, OpenGenerativeUIOptions, RuntimeWithDeclaredChannels, VERSION, isA2UIEnabled, isIntelligenceRuntime, resolveAgents };
246
315
  //# sourceMappingURL=runtime.d.mts.map
@@ -1 +1 @@
1
- {"version":3,"file":"runtime.d.mts","names":[],"sources":["../../../../src/v2/runtime/core/runtime.ts"],"mappings":";;;;;;;;;;;;;;cAgCa,OAAA;AAAA,UAEH,mCAAA;;EAER,MAAA;AAAA;AAAA,KAGU,mBAAA,GAAsB,eAAA;EALW,uFAO3C,OAAA;AAAA;AAAA,UAGe,aAAA;EALL;EAOV,OAAA,EAAS,mBAAA;AAAA;AAAA,UAGM,uBAAA,SAAgC,mCAAA;AAAA,KAErC,sBAAA,aAAmC,uBAAA;AAAA,UAErC,yBAAA;;;;AAJV;EASE,IAAA,GAAO,mCAAA,GACL,oBAAA;IAV6C;;;AAEjD;;;IAeM,OAAA;EAAA;EAbI;EAgBR,OAAA,GAAU,aAAA;;EAEV,gBAAA,GAAmB,sBAAA;AAAA;;;;UAMJ,mBAAA;EAnBf;EAqBA,OAAA,EAAS,OAAA;AAAA;;;;;KAOC,aAAA,IACV,GAAA,EAAK,mBAAA,KACF,YAAA,CAAa,cAAA,CAAe,MAAA,SAAe,aAAA;;;AAXhD;;;;KAmBY,YAAA,GACR,YAAA,CAAa,cAAA,CAAe,MAAA,SAAe,aAAA,MAC3C,aAAA;AAZJ;;;;;AAAA,iBAmBsB,aAAA,CACpB,MAAA,EAAQ,YAAA,EACR,OAAA,GAAU,OAAA,GACT,OAAA,CAAQ,MAAA,SAAe,aAAA;AAAA,UAYhB,yBAAA,SAAkC,yBAAA;EAhCvC;;;;;;;;;;;AAQL;;;;;EAyCE,MAAA,EAAQ,YAAA;EAxCN;EA0CF,oBAAA,GAAuB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AA;AAAA,cAiBV,0BAAA,SACH,kBAAA,YACG,8BAAA;EAAA,SAEF,YAAA,EAAc,sBAAA;EAAA,SACd,YAAA,EAAc,oBAAA;EAAA,SACd,mBAAA;EAAA,SACA,cAAA;EAAA,SACA,aAAA;EAAA,SACA,4BAAA;EAAA,SACA,QAAA,EAAU,OAAA;EAAA,SACV,IAAA;EAhKT;EAAA,gBAmKgB,oBAAA;EAlKhB;EAAA,gBAoKgB,8BAAA;cAEJ,OAAA,EAAS,iCAAA;AAAA;AAAA,iBAoDP,qBAAA,CACd,OAAA,EAAS,kBAAA,GACR,OAAA,IAAW,8BAAA;;;;;;;;;;;iBAcE,aAAA,CACd,IAAA,EAAM,qBAAA,WACL,IAAA,IAAQ,WAAA,CAAY,qBAAA;;;;;;;;UAWN,2BAAA;EA3Of;;;EAAA,SA+OS,4BAAA;AAAA;;;;AAlOX;;;UA2OiB,cAAA,SAAuB,kBAAA;EA3OO;EA6O7C,mBAAA;EA3OA;EA6OA,cAAA;EA7O6B;EA+O7B,aAAA;EA5Oe;EA8Of,4BAAA;;EAEA,QAAA,GAAW,OAAA;AAAA;;;;;;;;;;;;;;;UAiBI,yBAAA;EAAA,KAEb,OAAA,EAAS,IAAA,CAAK,iCAAA;IACZ,QAAA,YAAoB,OAAA,KAAY,OAAA;EAAA,IAEjC,cAAA,GAAiB,2BAAA;EAAA,KACf,OAAA,EAAS,qBAAA,GAAwB,cAAA;AAAA;AA9PvC;;;;;;;;;;;AAAA,cA8XY,cAAA,EAAgB,yBAAA"}
@@ -1,6 +1,7 @@
1
1
  import "reflect-metadata";
2
2
  import { __toESM } from "../../../_virtual/_rolldown/runtime.mjs";
3
- import { require_package } from "../../../package.mjs";
3
+ import { resolveForwardHeadersPolicy } from "../handlers/header-utils.mjs";
4
+ import { require_package } from "../../../runtime/package.mjs";
4
5
  import { createLogger } from "../../../lib/logger.mjs";
5
6
  import { logRuntimeTelemetryDisclosure } from "../../../lib/telemetry-disclosure.mjs";
6
7
  import { DebugEventBus } from "./debug-event-bus.mjs";
@@ -40,6 +41,7 @@ var BaseCopilotRuntime = class {
40
41
  this.resolvedLicenseToken = options.licenseToken ?? process.env.COPILOTKIT_LICENSE_TOKEN;
41
42
  if (this.resolvedLicenseToken) telemetry.setLicenseToken(this.resolvedLicenseToken);
42
43
  if (process.env.NODE_ENV !== "production") this.debugEventBus = new DebugEventBus();
44
+ this.forwardHeadersPolicy = resolveForwardHeadersPolicy(options.forwardHeaders);
43
45
  this.debug = resolveDebugConfig(options.debug);
44
46
  if (this.debug.enabled) this.debugLogger = createLogger({
45
47
  level: "debug",
@@ -49,6 +51,8 @@ var BaseCopilotRuntime = class {
49
51
  };
50
52
  var CopilotSseRuntime = class extends BaseCopilotRuntime {
51
53
  constructor(options) {
54
+ const channels = options.channels;
55
+ 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.");
52
56
  super(options, options.runner ?? new InMemoryAgentRunner());
53
57
  this.intelligence = void 0;
54
58
  this.mode = RUNTIME_MODE_SSE;
@@ -76,6 +80,8 @@ var CopilotIntelligenceRuntime = class CopilotIntelligenceRuntime extends BaseCo
76
80
  this.lockTtlSeconds = Math.min(options.lockTtlSeconds ?? 20, CopilotIntelligenceRuntime.MAX_LOCK_TTL_SECONDS);
77
81
  this.lockKeyPrefix = options.lockKeyPrefix;
78
82
  this.lockHeartbeatIntervalSeconds = Math.min(options.lockHeartbeatIntervalSeconds ?? 15, CopilotIntelligenceRuntime.MAX_HEARTBEAT_INTERVAL_SECONDS);
83
+ this.channels = options.channels ?? [];
84
+ for (const c of this.channels) if (!c.name) throw new Error("Intelligence Channel is missing a `name` — pass createChannel({ name }) for each Channel in `channels`");
79
85
  }
80
86
  };
81
87
  function hasIntelligenceOptions(options) {
@@ -100,8 +106,12 @@ function isA2UIEnabled(a2ui) {
100
106
  /**
101
107
  * Compatibility shim that preserves the legacy `CopilotRuntime` entrypoint.
102
108
  * New code should prefer `CopilotSseRuntime` or `CopilotIntelligenceRuntime`.
109
+ *
110
+ * Exported to consumers as the {@link CopilotRuntime} value (typed as
111
+ * {@link CopilotRuntimeConstructor}) rather than as a class, so that the
112
+ * channel-presence brand can flow from construction into the handler type.
103
113
  */
104
- var CopilotRuntime = class {
114
+ var CopilotRuntimeShim = class {
105
115
  constructor(options) {
106
116
  this.delegate = hasIntelligenceOptions(options) ? new CopilotIntelligenceRuntime(options) : new CopilotSseRuntime(options);
107
117
  }
@@ -147,6 +157,9 @@ var CopilotRuntime = class {
147
157
  get lockHeartbeatIntervalSeconds() {
148
158
  return isIntelligenceRuntime(this.delegate) ? this.delegate.lockHeartbeatIntervalSeconds : void 0;
149
159
  }
160
+ get channels() {
161
+ return isIntelligenceRuntime(this.delegate) ? this.delegate.channels : void 0;
162
+ }
150
163
  get mode() {
151
164
  return this.delegate.mode;
152
165
  }
@@ -162,7 +175,22 @@ var CopilotRuntime = class {
162
175
  get debugLogger() {
163
176
  return this.delegate.debugLogger;
164
177
  }
178
+ get forwardHeadersPolicy() {
179
+ return this.delegate.forwardHeadersPolicy;
180
+ }
165
181
  };
182
+ /**
183
+ * The public `CopilotRuntime` constructor. Backed by {@link CopilotRuntimeShim}
184
+ * but typed as {@link CopilotRuntimeConstructor} so that constructing with a
185
+ * non-empty `channels` array yields a {@link RuntimeWithDeclaredChannels}-branded
186
+ * runtime type.
187
+ *
188
+ * The `as unknown as` cast is required (not dishonest widening): the brand is a
189
+ * phantom, compile-time-only marker with no runtime representation, so the shim
190
+ * instances legitimately do not carry the brand property. Behavior is identical
191
+ * to the former `class CopilotRuntime` — this only refines the static type.
192
+ */
193
+ const CopilotRuntime = CopilotRuntimeShim;
166
194
 
167
195
  //#endregion
168
196
  export { CopilotIntelligenceRuntime, CopilotRuntime, CopilotSseRuntime, VERSION, isA2UIEnabled, isIntelligenceRuntime, resolveAgents };
@@ -1 +1 @@
1
- {"version":3,"file":"runtime.mjs","names":["pkg"],"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 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\";\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\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\nexport interface CopilotRuntimeUser {\n id: string;\n name: string;\n}\n\nexport type IdentifyUserCallback = (\n request: Request,\n) => MaybePromise<CopilotRuntimeUser>;\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}\n\nexport interface CopilotIntelligenceRuntimeOptions extends BaseCopilotRuntimeOptions {\n /** Configures Intelligence mode for durable threads and realtime events. */\n intelligence: CopilotKitIntelligence;\n /** Resolves the authenticated user for intelligence requests. */\n identifyUser: IdentifyUserCallback;\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\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\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 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\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 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 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 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 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 = options.identifyUser;\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 }\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 * Compatibility shim that preserves the legacy `CopilotRuntime` entrypoint.\n * New code should prefer `CopilotSseRuntime` or `CopilotIntelligenceRuntime`.\n */\nexport class CopilotRuntime implements CopilotRuntimeLike {\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 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"],"mappings":";;;;;;;;;;;;;;AAgCA,MAAa,UAAUA,uBAAI;;;;;;AAyE3B,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;;AAyGT,IAAe,qBAAf,MAAgE;CAyB9D,YAAY,SAAoC,QAAqB;AACnE,iCAA+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,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/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\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\nexport interface CopilotRuntimeUser {\n id: string;\n name: string;\n}\n\nexport type IdentifyUserCallback = (\n request: Request,\n) => MaybePromise<CopilotRuntimeUser>;\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\nexport interface CopilotIntelligenceRuntimeOptions extends BaseCopilotRuntimeOptions {\n /** Configures Intelligence mode for durable threads and realtime events. */\n intelligence: CopilotKitIntelligence;\n /** Resolves the authenticated user for intelligence requests. */\n identifyUser: IdentifyUserCallback;\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 channels?: Channel[];\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\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\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 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 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 = options.identifyUser;\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 = options.channels ?? [];\n for (const c of this.channels) {\n if (!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: Omit<CopilotIntelligenceRuntimeOptions, \"channels\"> & {\n channels: readonly [Channel, ...Channel[]];\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\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;;;;;;AAyE3B,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;;AAsIT,IAAe,qBAAf,MAAgE;CA0B9D,YAAY,SAAoC,QAAqB;AACnE,iCAA+B;EAE/B,MAAM,EACJ,QACA,sBACA,yBACA,wBACA,MACA,SACA,qBACE;AAEJ,OAAK,SAAS;AACd,OAAK,uBAAuB;A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AK,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;;;;;;;;;;;;;;AAezB,MAAa,iBACX"}
@@ -1,4 +1,4 @@
1
-
1
+ require("reflect-metadata");
2
2
  import { CopilotRuntimeLike } from "../core/runtime.cjs";
3
3
  import { CopilotRuntimeHooks } from "../core/hooks.cjs";
4
4
  import { Router } from "express";
@@ -8,15 +8,18 @@ let cors = require("cors");
8
8
  cors = require_runtime.__toESM(cors);
9
9
 
10
10
  //#region src/v2/runtime/endpoints/express.ts
11
- function createCopilotExpressHandler({ runtime, basePath, mode = "multi-route", cors: corsOption = true, hooks }) {
11
+ function createCopilotExpressHandler({ runtime, basePath, mode = "multi-route", cors: corsOption = true, hooks, activateChannels, __channelEngine }) {
12
12
  const normalizedBase = normalizeBasePath(basePath);
13
- const nodeHandler = require_express_fetch_bridge.createExpressNodeHandler(require_fetch_handler.createCopilotRuntimeHandler({
13
+ const handler = require_fetch_handler.createCopilotRuntimeHandler({
14
14
  runtime,
15
15
  basePath: normalizedBase,
16
16
  mode,
17
17
  cors: false,
18
- hooks
19
- }));
18
+ hooks,
19
+ activateChannels,
20
+ __channelEngine
21
+ });
22
+ const nodeHandler = require_express_fetch_bridge.createExpressNodeHandler(handler);
20
23
  const expressHandler = async (req, res, next) => {
21
24
  try {
22
25
  await nodeHandler(req, res);
@@ -46,7 +49,9 @@ function createCopilotExpressHandler({ runtime, basePath, mode = "multi-route",
46
49
  router.options(normalizedBase, expressHandler);
47
50
  } else if (normalizedBase === "/") router.all(/.*/, expressHandler);
48
51
  else router.all(new RegExp(`^${escapeRegExp(normalizedBase)}(\\/.*)?$`), expressHandler);
49
- return router;
52
+ const exposedRouter = router;
53
+ exposedRouter.channels = handler.channels;
54
+ return exposedRouter;
50
55
  }
51
56
  function escapeRegExp(s) {
52
57
  return s.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
@@ -1 +1 @@
1
- {"version":3,"file":"express.cjs","names":["createExpressNodeHandler","createCopilotRuntimeHandler"],"sources":["../../../../src/v2/runtime/endpoints/express.ts"],"sourcesContent":["import express from \"express\";\nimport type {\n Request as ExpressRequest,\n Response as ExpressResponse,\n NextFunction,\n Router,\n} from \"express\";\nimport cors from \"cors\";\nimport type { CorsOptions } from \"cors\";\nimport type { CopilotRuntimeLike } from \"../core/runtime\";\nimport { createCopilotRuntimeHandler } from \"../core/fetch-handler\";\nimport { createExpressNodeHandler } from \"./express-fetch-bridge\";\nimport type { CopilotRuntimeHooks } from \"../core/hooks\";\n\nexport interface CopilotExpressEndpointParams {\n runtime: CopilotRuntimeLike;\n basePath: string;\n\n /**\n * Endpoint mode.\n * - `\"multi-route\"` (default): separate routes for each operation\n * - `\"single-route\"`: single POST endpoint with JSON envelope dispatch\n */\n mode?: \"multi-route\" | \"single-route\";\n\n /**\n * CORS configuration for the Express router.\n * - `true` (default): permissive CORS (`origin: \"*\"`, all methods, all headers).\n * - `false`: no CORS middleware is applied — handle it yourself.\n * - object: passed directly to the Express `cors()` middleware.\n */\n cors?: boolean | CorsOptions;\n\n /**\n * Lifecycle hooks for request processing.\n */\n hooks?: CopilotRuntimeHooks;\n}\n\n/**\n * Creates an Express router that serves the CopilotKit runtime.\n *\n * In **multi-route** mode (default) the router exposes:\n * - `GET {basePath}/info` — runtime info\n * - `POST {basePath}/agent/:agentId/run` — start an agent run\n * - `POST {basePath}/agent/:agentId/connect` — connect to an agent run\n * - `POST {basePath}/agent/:agentId/stop/:threadId` — stop an agent run\n * - `POST {basePath}/transcribe` — transcribe audio\n *\n * In **single-route** mode a single `POST {basePath}` endpoint accepts a JSON\n * envelope `{ method, params, body }` and dispatches to the appropriate handler.\n *\n * @example\n * ```typescript\n * import express from \"express\";\n * import { CopilotRuntime } from \"@copilotkit/runtime/v2\";\n * import { createCopilotExpressHandler } from \"@copilotkit/runtime/v2/express\";\n *\n * const runtime = new CopilotRuntime({\n * agents: { default: new BuiltInAgent({ model: \"openai/gpt-4o-mini\" }) },\n * });\n *\n * const app = express();\n * app.use(createCopilotExpressHandler({\n * runtime,\n * basePath: \"/api/copilotkit\",\n * cors: true,\n * }));\n * app.listen(4000);\n * ```\n *\n * @example Single-route mode with lifecycle hooks\n * ```typescript\n * app.use(createCopilotExpressHandler({\n * runtime,\n * basePath: \"/api/copilotkit\",\n * mode: \"single-route\",\n * hooks: {\n * onRequest: ({ request }) => {\n * if (!request.headers.get(\"authorization\")) {\n * throw new Response(\"Unauthorized\", { status: 401 });\n * }\n * },\n * },\n * }));\n * ```\n */\n/** @deprecated Use `createCopilotExpressHandler` instead. */\nexport { createCopilotExpressHandler as createCopilotEndpointExpress };\n\nexport function createCopilotExpressHandler({\n runtime,\n basePath,\n mode = \"multi-route\",\n cors: corsOption = true,\n hooks,\n}: CopilotExpressEndpointParams): Router {\n const normalizedBase = normalizeBasePath(basePath);\n\n const handler = createCopilotRuntimeHandler({\n runtime,\n basePath: normalizedBase,\n mode,\n cors: false, // CORS is handled at the Express middleware layer\n hooks,\n });\n\n const nodeHandler = createExpressNodeHandler(handler);\n\n const expressHandler = async (\n req: ExpressRequest,\n res: ExpressResponse,\n next: NextFunction,\n ) => {\n try {\n await nodeHandler(req, res);\n } catch (err) {\n next(err);\n }\n };\n\n const router = express.Router();\n\n // CORS middleware\n if (corsOption) {\n const corsConfig: CorsOptions =\n corsOption === true\n ? {\n origin: \"*\",\n methods: [\n \"GET\",\n \"HEAD\",\n \"PUT\",\n \"POST\",\n \"DELETE\",\n \"PATCH\",\n \"OPTIONS\",\n ],\n allowedHeaders: [\"*\"],\n }\n : corsOption;\n router.use(cors(corsConfig));\n }\n\n // Route mounting\n if (mode === \"single-route\") {\n router.post(normalizedBase, expressHandler);\n router.options(normalizedBase, expressHandler);\n } else if (normalizedBase === \"/\") {\n router.all(/.*/, expressHandler);\n } else {\n router.all(\n new RegExp(`^${escapeRegExp(normalizedBase)}(\\\\/.*)?$`),\n expressHandler,\n );\n }\n\n return router;\n}\n\nfunction escapeRegExp(s: string): string {\n return s.replace(/[.*+?^${}()|[\\]\\\\]/g, \"\\\\$&\");\n}\n\nfunction normalizeBasePath(path: string): string {\n if (!path) {\n throw new Error(\"basePath must be provided for Express endpoint\");\n }\n\n if (!path.startsWith(\"/\")) {\n return `/${path}`;\n }\n\n if (path.length > 1 && path.endsWith(\"/\")) {\n return path.slice(0, -1);\n }\n\n return path;\n}\n"],"mappings":";;;;;;;;;;AA0FA,SAAgB,4BAA4B,EAC1C,SACA,UACA,OAAO,eACP,MAAM,aAAa,MACnB,SACuC;CACvC,MAAM,iBAAiB,kBAAkB,SAAS;CAUlD,MAAM,cAAcA,sDARJC,kDAA4B;EAC1C;EACA,UAAU;EACV;EACA,MAAM;EACN;EACD,CAAC,CAEmD;CAErD,MAAM,iBAAiB,OACrB,KACA,KACA,SACG;AACH,MAAI;AACF,SAAM,YAAY,KAAK,IAAI;WACpB,KAAK;AACZ,QAAK,IAAI;;;CAIb,MAAM,SAAS,gBAAQ,QAAQ;AAG/B,KAAI,YAAY;EACd,MAAM,aACJ,eAAe,OACX;GACE,QAAQ;GACR,SAAS;IACP;IACA;IACA;IACA;IACA;IACA;IACA;IACD;GACD,gBAAgB,CAAC,IAAI;GACtB,GACD;AACN,SAAO,sBAAS,WAAW,CAAC;;AAI9B,KAAI,SAAS,gBAAgB;AAC3B,SAAO,KAAK,gBAAgB,eAAe;AAC3C,SAAO,QAAQ,gBAAgB,eAAe;YACrC,mBAAmB,IAC5B,QAAO,IAAI,MAAM,eAAe;KAEhC,QAAO,IACL,IAAI,OAAO,IAAI,aAAa,eAAe,CAAC,WAAW,EACvD,eACD;AAGH,QAAO;;AAGT,SAAS,aAAa,GAAmB;AACvC,QAAO,EAAE,QAAQ,uBAAuB,OAAO;;AAGjD,SAAS,kBAAkB,MAAsB;AAC/C,KAAI,CAAC,KACH,OAAM,IAAI,MAAM,iDAAiD;AAGnE,KAAI,CAAC,KAAK,WAAW,IAAI,CACvB,QAAO,IAAI;AAGb,KAAI,KAAK,SAAS,KAAK,KAAK,SAAS,IAAI,CACvC,QAAO,KAAK,MAAM,GAAG,GAAG;AAG1B,QAAO"}
1
+ {"version":3,"file":"express.cjs","names":["createCopilotRuntimeHandler","createExpressNodeHandler"],"sources":["../../../../src/v2/runtime/endpoints/express.ts"],"sourcesContent":["import express from \"express\";\nimport type {\n Request as ExpressRequest,\n Response as ExpressResponse,\n NextFunction,\n Router,\n} from \"express\";\nimport cors from \"cors\";\nimport type { CorsOptions } from \"cors\";\nimport type { CopilotRuntimeLike } from \"../core/runtime\";\nimport { createCopilotRuntimeHandler } from \"../core/fetch-handler\";\nimport type {\n ActivateChannelEngine,\n ChannelsControl,\n} from \"../core/channel-manager\";\nimport { createExpressNodeHandler } from \"./express-fetch-bridge\";\nimport type { CopilotRuntimeHooks } from \"../core/hooks\";\n\n/**\n * An Express {@link Router} that may also carry an optional\n * {@link ChannelsControl} surface. Express's Router is a request-scoped\n * middleware object, not a long-running process owner — Node\n * (`createCopilotNodeListener`) is the lifecycle-owning surface for\n * `.channels`. It is attached here too, best-effort, for callers that mount\n * the router directly and want to observe/stop managed Channel activation\n * without also standing up a Node listener.\n */\nexport type CopilotExpressRouter = Router & { channels?: ChannelsControl };\n\nexport interface CopilotExpressEndpointParams {\n runtime: CopilotRuntimeLike;\n basePath: string;\n\n /**\n * Endpoint mode.\n * - `\"multi-route\"` (default): separate routes for each operation\n * - `\"single-route\"`: single POST endpoint with JSON envelope dispatch\n */\n mode?: \"multi-route\" | \"single-route\";\n\n /**\n * CORS configuration for the Express router.\n * - `true` (default): permissive CORS (`origin: \"*\"`, all methods, all headers).\n * - `false`: no CORS middleware is applied — handle it yourself.\n * - object: passed directly to the Express `cors()` middleware.\n */\n cors?: boolean | CorsOptions;\n\n /**\n * Lifecycle hooks for request processing.\n */\n hooks?: CopilotRuntimeHooks;\n\n /**\n * Whether the underlying handler activates the runtime's declared managed\n * Channels at creation time. Defaults to `true`. See\n * `CopilotRuntimeHandlerOptions.activateChannels`.\n */\n activateChannels?: boolean;\n\n /**\n * @internal Test seam: inject a fake Channel activation engine. Forwarded\n * to `createCopilotRuntimeHandler`. Not part of the public API.\n */\n __channelEngine?: ActivateChannelEngine;\n}\n\n/**\n * Creates an Express router that serves the CopilotKit runtime.\n *\n * In **multi-route** mode (default) the router exposes:\n * - `GET {basePath}/info` — runtime info\n * - `POST {basePath}/agent/:agentId/run` — start an agent run\n * - `POST {basePath}/agent/:agentId/connect` — connect to an agent run\n * - `POST {basePath}/agent/:agentId/stop/:threadId` — stop an agent run\n * - `POST {basePath}/transcribe` — transcribe audio\n *\n * In **single-route** mode a single `POST {basePath}` endpoint accepts a JSON\n * envelope `{ method, params, body }` and dispatches to the appropriate handler.\n *\n * @example\n * ```typescript\n * import express from \"express\";\n * import { CopilotRuntime } from \"@copilotkit/runtime/v2\";\n * import { createCopilotExpressHandler } from \"@copilotkit/runtime/v2/express\";\n *\n * const runtime = new CopilotRuntime({\n * agents: { default: new BuiltInAgent({ model: \"openai/gpt-4o-mini\" }) },\n * });\n *\n * const app = express();\n * app.use(createCopilotExpressHandler({\n * runtime,\n * basePath: \"/api/copilotkit\",\n * cors: true,\n * }));\n * app.listen(4000);\n * ```\n *\n * @example Single-route mode with lifecycle hooks\n * ```typescript\n * app.use(createCopilotExpressHandler({\n * runtime,\n * basePath: \"/api/copilotkit\",\n * mode: \"single-route\",\n * hooks: {\n * onRequest: ({ request }) => {\n * if (!request.headers.get(\"authorization\")) {\n * throw new Response(\"Unauthorized\", { status: 401 });\n * }\n * },\n * },\n * }));\n * ```\n */\n/** @deprecated Use `createCopilotExpressHandler` instead. */\nexport { createCopilotExpressHandler as createCopilotEndpointExpress };\n\nexport function createCopilotExpressHandler({\n runtime,\n basePath,\n mode = \"multi-route\",\n cors: corsOption = true,\n hooks,\n activateChannels,\n __channelEngine,\n}: CopilotExpressEndpointParams): CopilotExpressRouter {\n const normalizedBase = normalizeBasePath(basePath);\n\n const handler = createCopilotRuntimeHandler({\n runtime,\n basePath: normalizedBase,\n mode,\n cors: false, // CORS is handled at the Express middleware layer\n hooks,\n activateChannels,\n __channelEngine,\n });\n\n const nodeHandler = createExpressNodeHandler(handler);\n\n const expressHandler = async (\n req: ExpressRequest,\n res: ExpressResponse,\n next: NextFunction,\n ) => {\n try {\n await nodeHandler(req, res);\n } catch (err) {\n next(err);\n }\n };\n\n const router = express.Router();\n\n // CORS middleware\n if (corsOption) {\n const corsConfig: CorsOptions =\n corsOption === true\n ? {\n origin: \"*\",\n methods: [\n \"GET\",\n \"HEAD\",\n \"PUT\",\n \"POST\",\n \"DELETE\",\n \"PATCH\",\n \"OPTIONS\",\n ],\n allowedHeaders: [\"*\"],\n }\n : corsOption;\n router.use(cors(corsConfig));\n }\n\n // Route mounting\n if (mode === \"single-route\") {\n router.post(normalizedBase, expressHandler);\n router.options(normalizedBase, expressHandler);\n } else if (normalizedBase === \"/\") {\n router.all(/.*/, expressHandler);\n } else {\n router.all(\n new RegExp(`^${escapeRegExp(normalizedBase)}(\\\\/.*)?$`),\n expressHandler,\n );\n }\n\n const exposedRouter: CopilotExpressRouter = router;\n exposedRouter.channels = handler.channels;\n return exposedRouter;\n}\n\nfunction escapeRegExp(s: string): string {\n return s.replace(/[.*+?^${}()|[\\]\\\\]/g, \"\\\\$&\");\n}\n\nfunction normalizeBasePath(path: string): string {\n if (!path) {\n throw new Error(\"basePath must be provided for Express endpoint\");\n }\n\n if (!path.startsWith(\"/\")) {\n return `/${path}`;\n }\n\n if (path.length > 1 && path.endsWith(\"/\")) {\n return path.slice(0, -1);\n }\n\n return path;\n}\n"],"mappings":";;;;;;;;;;AAsHA,SAAgB,4BAA4B,EAC1C,SACA,UACA,OAAO,eACP,MAAM,aAAa,MACnB,OACA,kBACA,mBACqD;CACrD,MAAM,iBAAiB,kBAAkB,SAAS;CAElD,MAAM,UAAUA,kDAA4B;EAC1C;EACA,UAAU;EACV;EACA,MAAM;EACN;EACA;EACA;EACD,CAAC;CAEF,MAAM,cAAcC,sDAAyB,QAAQ;CAErD,MAAM,iBAAiB,OACrB,KACA,KACA,SACG;AACH,MAAI;AACF,SAAM,YAAY,KAAK,IAAI;WACpB,KAAK;AACZ,QAAK,IAAI;;;CAIb,MAAM,SAAS,gBAAQ,QAAQ;AAG/B,KAAI,YAAY;EACd,MAAM,aACJ,eAAe,OACX;GACE,QAAQ;GACR,SAAS;IACP;IACA;IACA;IACA;IACA;IACA;IACA;IACD;GACD,gBAAgB,CAAC,IAAI;GACtB,GACD;AACN,SAAO,sBAAS,WAAW,CAAC;;AAI9B,KAAI,SAAS,gBAAgB;AAC3B,SAAO,KAAK,gBAAgB,eAAe;AAC3C,SAAO,QAAQ,gBAAgB,eAAe;YACrC,mBAAmB,IAC5B,QAAO,IAAI,MAAM,eAAe;KAEhC,QAAO,IACL,IAAI,OAAO,IAAI,aAAa,eAAe,CAAC,WAAW,EACvD,eACD;CAGH,MAAM,gBAAsC;AAC5C,eAAc,WAAW,QAAQ;AACjC,QAAO;;AAGT,SAAS,aAAa,GAAmB;AACvC,QAAO,EAAE,QAAQ,uBAAuB,OAAO;;AAGjD,SAAS,kBAAkB,MAAsB;AAC/C,KAAI,CAAC,KACH,OAAM,IAAI,MAAM,iDAAiD;AAGnE,KAAI,CAAC,KAAK,WAAW,IAAI,CACvB,QAAO,IAAI;AAGb,KAAI,KAAK,SAAS,KAAK,KAAK,SAAS,IAAI,CACvC,QAAO,KAAK,MAAM,GAAG,GAAG;AAG1B,QAAO"}
@@ -1,10 +1,23 @@
1
-
1
+ require("reflect-metadata");
2
2
  import { CopilotRuntimeLike } from "../core/runtime.cjs";
3
3
  import { CopilotRuntimeHooks } from "../core/hooks.cjs";
4
+ import { ActivateChannelEngine, ChannelsControl } from "../core/channel-manager.cjs";
4
5
  import { Router } from "express";
5
6
  import { CorsOptions } from "cors";
6
7
 
7
8
  //#region src/v2/runtime/endpoints/express.d.ts
9
+ /**
10
+ * An Express {@link Router} that may also carry an optional
11
+ * {@link ChannelsControl} surface. Express's Router is a request-scoped
12
+ * middleware object, not a long-running process owner — Node
13
+ * (`createCopilotNodeListener`) is the lifecycle-owning surface for
14
+ * `.channels`. It is attached here too, best-effort, for callers that mount
15
+ * the router directly and want to observe/stop managed Channel activation
16
+ * without also standing up a Node listener.
17
+ */
18
+ type CopilotExpressRouter = Router & {
19
+ channels?: ChannelsControl;
20
+ };
8
21
  interface CopilotExpressEndpointParams {
9
22
  runtime: CopilotRuntimeLike;
10
23
  basePath: string;
@@ -25,14 +38,27 @@ interface CopilotExpressEndpointParams {
25
38
  * Lifecycle hooks for request processing.
26
39
  */
27
40
  hooks?: CopilotRuntimeHooks;
41
+ /**
42
+ * Whether the underlying handler activates the runtime's declared managed
43
+ * Channels at creation time. Defaults to `true`. See
44
+ * `CopilotRuntimeHandlerOptions.activateChannels`.
45
+ */
46
+ activateChannels?: boolean;
47
+ /**
48
+ * @internal Test seam: inject a fake Channel activation engine. Forwarded
49
+ * to `createCopilotRuntimeHandler`. Not part of the public API.
50
+ */
51
+ __channelEngine?: ActivateChannelEngine;
28
52
  }
29
53
  declare function createCopilotExpressHandler({
30
54
  runtime,
31
55
  basePath,
32
56
  mode,
33
57
  cors: corsOption,
34
- hooks
35
- }: CopilotExpressEndpointParams): Router;
58
+ hooks,
59
+ activateChannels,
60
+ __channelEngine
61
+ }: CopilotExpressEndpointParams): CopilotExpressRouter;
36
62
  //#endregion
37
- export { CopilotExpressEndpointParams, createCopilotExpressHandler };
63
+ export { CopilotExpressEndpointParams, CopilotExpressRouter, createCopilotExpressHandler };
38
64
  //# sourceMappingURL=express.d.cts.map
@@ -1 +1 @@
1
- {"version":3,"file":"express.d.cts","names":[],"sources":["../../../../src/v2/runtime/endpoints/express.ts"],"mappings":";;;;;;;UAciB,4BAAA;EACf,OAAA,EAAS,kBAAA;EACT,QAAA;EAF2C;;;;;EAS3C,IAAA;EAa2B;;;;;;EAL3B,IAAA,aAAiB,WAAA;EAKjB;;;EAAA,KAAA,GAAQ,mBAAA;AAAA;AAAA,iBAsDM,2BAAA,CAAA;EACd,OAAA;EACA,QAAA;EACA,IAAA;EACA,IAAA,EAAM,UAAA;EACN;AAAA,GACC,4BAAA,GAA+B,MAAA"}
1
+ {"version":3,"file":"express.d.cts","names":[],"sources":["../../../../src/v2/runtime/endpoints/express.ts"],"mappings":";;;;;;;;;;AA2BA;;;;;;;KAAY,oBAAA,GAAuB,MAAA;EAAW,QAAA,GAAW,eAAA;AAAA;AAAA,UAExC,4BAAA;EACf,OAAA,EAAS,kBAAA;EACT,QAAA;EAeiB;;;;;EARjB,IAAA;EARS;;;;;;EAgBT,IAAA,aAAiB,WAAA;EAYjB;;;EAPA,KAAA,GAAQ,mBAAA;EAa+B;AAsDzC;;;;EA5DE,gBAAA;EA+DA;;;;EAzDA,eAAA,GAAkB,qBAAA;AAAA;AAAA,iBAsDJ,2BAAA,CAAA;EACd,OAAA;EACA,QAAA;EACA,IAAA;EACA,IAAA,EAAM,UAAA;EACN,KAAA;EACA,gBAAA;EACA;AAAA,GACC,4BAAA,GAA+B,oBAAA"}
@@ -1,10 +1,23 @@
1
1
  import "reflect-metadata";
2
2
  import { CopilotRuntimeLike } from "../core/runtime.mjs";
3
3
  import { CopilotRuntimeHooks } from "../core/hooks.mjs";
4
+ import { ActivateChannelEngine, ChannelsControl } from "../core/channel-manager.mjs";
4
5
  import { Router } from "express";
5
6
  import { CorsOptions } from "cors";
6
7
 
7
8
  //#region src/v2/runtime/endpoints/express.d.ts
9
+ /**
10
+ * An Express {@link Router} that may also carry an optional
11
+ * {@link ChannelsControl} surface. Express's Router is a request-scoped
12
+ * middleware object, not a long-running process owner — Node
13
+ * (`createCopilotNodeListener`) is the lifecycle-owning surface for
14
+ * `.channels`. It is attached here too, best-effort, for callers that mount
15
+ * the router directly and want to observe/stop managed Channel activation
16
+ * without also standing up a Node listener.
17
+ */
18
+ type CopilotExpressRouter = Router & {
19
+ channels?: ChannelsControl;
20
+ };
8
21
  interface CopilotExpressEndpointParams {
9
22
  runtime: CopilotRuntimeLike;
10
23
  basePath: string;
@@ -25,14 +38,27 @@ interface CopilotExpressEndpointParams {
25
38
  * Lifecycle hooks for request processing.
26
39
  */
27
40
  hooks?: CopilotRuntimeHooks;
41
+ /**
42
+ * Whether the underlying handler activates the runtime's declared managed
43
+ * Channels at creation time. Defaults to `true`. See
44
+ * `CopilotRuntimeHandlerOptions.activateChannels`.
45
+ */
46
+ activateChannels?: boolean;
47
+ /**
48
+ * @internal Test seam: inject a fake Channel activation engine. Forwarded
49
+ * to `createCopilotRuntimeHandler`. Not part of the public API.
50
+ */
51
+ __channelEngine?: ActivateChannelEngine;
28
52
  }
29
53
  declare function createCopilotExpressHandler({
30
54
  runtime,
31
55
  basePath,
32
56
  mode,
33
57
  cors: corsOption,
34
- hooks
35
- }: CopilotExpressEndpointParams): Router;
58
+ hooks,
59
+ activateChannels,
60
+ __channelEngine
61
+ }: CopilotExpressEndpointParams): CopilotExpressRouter;
36
62
  //#endregion
37
- export { CopilotExpressEndpointParams, createCopilotExpressHandler };
63
+ export { CopilotExpressEndpointParams, CopilotExpressRouter, createCopilotExpressHandler };
38
64
  //# sourceMappingURL=express.d.mts.map
@@ -1 +1 @@
1
- {"version":3,"file":"express.d.mts","names":[],"sources":["../../../../src/v2/runtime/endpoints/express.ts"],"mappings":";;;;;;;UAciB,4BAAA;EACf,OAAA,EAAS,kBAAA;EACT,QAAA;EAF2C;;;;;EAS3C,IAAA;EAa2B;;;;;;EAL3B,IAAA,aAAiB,WAAA;EAKjB;;;EAAA,KAAA,GAAQ,mBAAA;AAAA;AAAA,iBAsDM,2BAAA,CAAA;EACd,OAAA;EACA,QAAA;EACA,IAAA;EACA,IAAA,EAAM,UAAA;EACN;AAAA,GACC,4BAAA,GAA+B,MAAA"}
1
+ {"version":3,"file":"express.d.mts","names":[],"sources":["../../../../src/v2/runtime/endpoints/express.ts"],"mappings":";;;;;;;;;;AA2BA;;;;;;;KAAY,oBAAA,GAAuB,MAAA;EAAW,QAAA,GAAW,eAAA;AAAA;AAAA,UAExC,4BAAA;EACf,OAAA,EAAS,kBAAA;EACT,QAAA;EAeiB;;;;;EARjB,IAAA;EARS;;;;;;EAgBT,IAAA,aAAiB,WAAA;EAYjB;;;EAPA,KAAA,GAAQ,mBAAA;EAa+B;AAsDzC;;;;EA5DE,gBAAA;EA+DA;;;;EAzDA,eAAA,GAAkB,qBAAA;AAAA;AAAA,iBAsDJ,2BAAA,CAAA;EACd,OAAA;EACA,QAAA;EACA,IAAA;EACA,IAAA,EAAM,UAAA;EACN,KAAA;EACA,gBAAA;EACA;AAAA,GACC,4BAAA,GAA+B,oBAAA"}