@copilotkit/runtime 1.64.2-canary.perfall1 → 1.64.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (79) hide show
  1. package/dist/package.cjs +1 -1
  2. package/dist/runtime/package.mjs +1 -1
  3. package/dist/v2/runtime/core/channel-activation-config.cjs +2 -1
  4. package/dist/v2/runtime/core/channel-activation-config.cjs.map +1 -1
  5. package/dist/v2/runtime/core/channel-activation-config.d.cts +7 -0
  6. package/dist/v2/runtime/core/channel-activation-config.d.cts.map +1 -1
  7. package/dist/v2/runtime/core/channel-activation-config.d.mts +7 -0
  8. package/dist/v2/runtime/core/channel-activation-config.d.mts.map +1 -1
  9. package/dist/v2/runtime/core/channel-activation-config.mjs +2 -1
  10. package/dist/v2/runtime/core/channel-activation-config.mjs.map +1 -1
  11. package/dist/v2/runtime/core/channel-manager.cjs +214 -18
  12. package/dist/v2/runtime/core/channel-manager.cjs.map +1 -1
  13. package/dist/v2/runtime/core/channel-manager.d.cts +6 -5
  14. package/dist/v2/runtime/core/channel-manager.d.cts.map +1 -1
  15. package/dist/v2/runtime/core/channel-manager.d.mts +6 -5
  16. package/dist/v2/runtime/core/channel-manager.d.mts.map +1 -1
  17. package/dist/v2/runtime/core/channel-manager.mjs +214 -18
  18. package/dist/v2/runtime/core/channel-manager.mjs.map +1 -1
  19. package/dist/v2/runtime/core/fetch-handler.cjs +4 -0
  20. package/dist/v2/runtime/core/fetch-handler.cjs.map +1 -1
  21. package/dist/v2/runtime/core/fetch-handler.d.cts +5 -0
  22. package/dist/v2/runtime/core/fetch-handler.d.cts.map +1 -1
  23. package/dist/v2/runtime/core/fetch-handler.d.mts +5 -0
  24. package/dist/v2/runtime/core/fetch-handler.d.mts.map +1 -1
  25. package/dist/v2/runtime/core/fetch-handler.mjs +4 -0
  26. package/dist/v2/runtime/core/fetch-handler.mjs.map +1 -1
  27. package/dist/v2/runtime/endpoints/auto-start-channels.cjs +47 -0
  28. package/dist/v2/runtime/endpoints/auto-start-channels.cjs.map +1 -0
  29. package/dist/v2/runtime/endpoints/auto-start-channels.mjs +46 -0
  30. package/dist/v2/runtime/endpoints/auto-start-channels.mjs.map +1 -0
  31. package/dist/v2/runtime/endpoints/express.cjs +2 -0
  32. package/dist/v2/runtime/endpoints/express.cjs.map +1 -1
  33. package/dist/v2/runtime/endpoints/express.d.cts +9 -8
  34. package/dist/v2/runtime/endpoints/express.d.cts.map +1 -1
  35. package/dist/v2/runtime/endpoints/express.d.mts +9 -8
  36. package/dist/v2/runtime/endpoints/express.d.mts.map +1 -1
  37. package/dist/v2/runtime/endpoints/express.mjs +2 -0
  38. package/dist/v2/runtime/endpoints/express.mjs.map +1 -1
  39. package/dist/v2/runtime/endpoints/hono.cjs.map +1 -1
  40. package/dist/v2/runtime/endpoints/hono.d.cts +14 -5
  41. package/dist/v2/runtime/endpoints/hono.d.cts.map +1 -1
  42. package/dist/v2/runtime/endpoints/hono.d.mts +14 -5
  43. package/dist/v2/runtime/endpoints/hono.d.mts.map +1 -1
  44. package/dist/v2/runtime/endpoints/hono.mjs.map +1 -1
  45. package/dist/v2/runtime/endpoints/node.cjs +2 -0
  46. package/dist/v2/runtime/endpoints/node.cjs.map +1 -1
  47. package/dist/v2/runtime/endpoints/node.d.cts +23 -13
  48. package/dist/v2/runtime/endpoints/node.d.cts.map +1 -1
  49. package/dist/v2/runtime/endpoints/node.d.mts +23 -13
  50. package/dist/v2/runtime/endpoints/node.d.mts.map +1 -1
  51. package/dist/v2/runtime/endpoints/node.mjs +2 -0
  52. package/dist/v2/runtime/endpoints/node.mjs.map +1 -1
  53. package/dist/v2/runtime/intelligence-platform/client.cjs +33 -2
  54. package/dist/v2/runtime/intelligence-platform/client.cjs.map +1 -1
  55. package/dist/v2/runtime/intelligence-platform/client.d.cts +14 -3
  56. package/dist/v2/runtime/intelligence-platform/client.d.cts.map +1 -1
  57. package/dist/v2/runtime/intelligence-platform/client.d.mts +14 -3
  58. package/dist/v2/runtime/intelligence-platform/client.d.mts.map +1 -1
  59. package/dist/v2/runtime/intelligence-platform/client.mjs +33 -2
  60. package/dist/v2/runtime/intelligence-platform/client.mjs.map +1 -1
  61. package/dist/v2/runtime/runner/agent-runner.cjs.map +1 -1
  62. package/dist/v2/runtime/runner/agent-runner.d.cts +4 -0
  63. package/dist/v2/runtime/runner/agent-runner.d.cts.map +1 -1
  64. package/dist/v2/runtime/runner/agent-runner.d.mts +4 -0
  65. package/dist/v2/runtime/runner/agent-runner.d.mts.map +1 -1
  66. package/dist/v2/runtime/runner/agent-runner.mjs.map +1 -1
  67. package/dist/v2/runtime/runner/in-memory.cjs +3 -5
  68. package/dist/v2/runtime/runner/in-memory.cjs.map +1 -1
  69. package/dist/v2/runtime/runner/in-memory.d.cts.map +1 -1
  70. package/dist/v2/runtime/runner/in-memory.d.mts.map +1 -1
  71. package/dist/v2/runtime/runner/in-memory.mjs +3 -5
  72. package/dist/v2/runtime/runner/in-memory.mjs.map +1 -1
  73. package/dist/v2/runtime/runner/intelligence.cjs +38 -31
  74. package/dist/v2/runtime/runner/intelligence.cjs.map +1 -1
  75. package/dist/v2/runtime/runner/intelligence.d.cts.map +1 -1
  76. package/dist/v2/runtime/runner/intelligence.d.mts.map +1 -1
  77. package/dist/v2/runtime/runner/intelligence.mjs +38 -31
  78. package/dist/v2/runtime/runner/intelligence.mjs.map +1 -1
  79. package/package.json +5 -5
@@ -8,12 +8,12 @@ import { CorsOptions } from "cors";
8
8
  //#region src/v2/runtime/endpoints/express.d.ts
9
9
  /**
10
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 start (`ready()`), observe, or stop managed
16
- * Channel activation without also standing up a Node listener.
11
+ * {@link ChannelsControl} surface. The Router object itself is request-scoped
12
+ * middleware, but an Express app can only run inside a long-running
13
+ * `http.Server` — so this wrapper is a lifecycle-owning host like
14
+ * `createCopilotNodeListener`: it STARTS activation of the runtime's declared
15
+ * managed Channels at creation, and `.channels` is here to observe (`ready()`)
16
+ * or tear down (`stop()`) that activation.
17
17
  */
18
18
  type CopilotExpressRouter = Router & {
19
19
  channels?: ChannelsControl;
@@ -40,8 +40,9 @@ interface CopilotExpressEndpointParams {
40
40
  hooks?: CopilotRuntimeHooks;
41
41
  /**
42
42
  * Whether the underlying handler builds the control surface for the runtime's
43
- * declared managed Channels. Defaults to `true`. Building it opens no
44
- * connection activation is deferred to the first `channels.ready()`. See
43
+ * declared managed Channels and, because Express is a long-running host,
44
+ * starts their activation at creation. Defaults to `true`. Set `false` to
45
+ * build no surface and open no socket (tests, short-lived scripts). See
45
46
  * `CopilotRuntimeHandlerOptions.activateChannels`.
46
47
  */
47
48
  activateChannels?: boolean;
@@ -1 +1 @@
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;EAajB;;;EARA,KAAA,GAAQ,mBAAA;EAc+B;AAsDzC;;;;;EA5DE,gBAAA;EAgEM;;;;EA1DN,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
+ {"version":3,"file":"express.d.cts","names":[],"sources":["../../../../src/v2/runtime/endpoints/express.ts"],"mappings":";;;;;;;;;;AA4BA;;;;;;;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;EAcjB;;;EATA,KAAA,GAAQ,mBAAA;EAe+B;AAsDzC;;;;;;EA5DE,gBAAA;EAiEA;;;;EA3DA,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"}
@@ -8,12 +8,12 @@ import { CorsOptions } from "cors";
8
8
  //#region src/v2/runtime/endpoints/express.d.ts
9
9
  /**
10
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 start (`ready()`), observe, or stop managed
16
- * Channel activation without also standing up a Node listener.
11
+ * {@link ChannelsControl} surface. The Router object itself is request-scoped
12
+ * middleware, but an Express app can only run inside a long-running
13
+ * `http.Server` — so this wrapper is a lifecycle-owning host like
14
+ * `createCopilotNodeListener`: it STARTS activation of the runtime's declared
15
+ * managed Channels at creation, and `.channels` is here to observe (`ready()`)
16
+ * or tear down (`stop()`) that activation.
17
17
  */
18
18
  type CopilotExpressRouter = Router & {
19
19
  channels?: ChannelsControl;
@@ -40,8 +40,9 @@ interface CopilotExpressEndpointParams {
40
40
  hooks?: CopilotRuntimeHooks;
41
41
  /**
42
42
  * Whether the underlying handler builds the control surface for the runtime's
43
- * declared managed Channels. Defaults to `true`. Building it opens no
44
- * connection activation is deferred to the first `channels.ready()`. See
43
+ * declared managed Channels and, because Express is a long-running host,
44
+ * starts their activation at creation. Defaults to `true`. Set `false` to
45
+ * build no surface and open no socket (tests, short-lived scripts). See
45
46
  * `CopilotRuntimeHandlerOptions.activateChannels`.
46
47
  */
47
48
  activateChannels?: boolean;
@@ -1 +1 @@
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;EAajB;;;EARA,KAAA,GAAQ,mBAAA;EAc+B;AAsDzC;;;;;EA5DE,gBAAA;EAgEM;;;;EA1DN,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
+ {"version":3,"file":"express.d.mts","names":[],"sources":["../../../../src/v2/runtime/endpoints/express.ts"],"mappings":";;;;;;;;;;AA4BA;;;;;;;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;EAcjB;;;EATA,KAAA,GAAQ,mBAAA;EAe+B;AAsDzC;;;;;;EA5DE,gBAAA;EAiEA;;;;EA3DA,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,6 +1,7 @@
1
1
  import "reflect-metadata";
2
2
  import { createCopilotRuntimeHandler } from "../core/fetch-handler.mjs";
3
3
  import { createExpressNodeHandler } from "./express-fetch-bridge.mjs";
4
+ import { autoStartChannels } from "./auto-start-channels.mjs";
4
5
  import express from "express";
5
6
  import cors from "cors";
6
7
 
@@ -48,6 +49,7 @@ function createCopilotExpressHandler({ runtime, basePath, mode = "multi-route",
48
49
  else router.all(new RegExp(`^${escapeRegExp(normalizedBase)}(\\/.*)?$`), expressHandler);
49
50
  const exposedRouter = router;
50
51
  exposedRouter.channels = handler.channels;
52
+ autoStartChannels(exposedRouter.channels);
51
53
  return exposedRouter;
52
54
  }
53
55
  function escapeRegExp(s) {
@@ -1 +1 @@
1
- {"version":3,"file":"express.mjs","names":[],"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 start (`ready()`), observe, or stop managed\n * Channel activation 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 builds the control surface for the runtime's\n * declared managed Channels. Defaults to `true`. Building it opens no\n * connection activation is deferred to the first `channels.ready()`. 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":";;;;;;;AAuHA,SAAgB,4BAA4B,EAC1C,SACA,UACA,OAAO,eACP,MAAM,aAAa,MACnB,OACA,kBACA,mBACqD;CACrD,MAAM,iBAAiB,kBAAkB,SAAS;CAElD,MAAM,UAAU,4BAA4B;EAC1C;EACA,UAAU;EACV;EACA,MAAM;EACN;EACA;EACA;EACD,CAAC;CAEF,MAAM,cAAc,yBAAyB,QAAQ;CAErD,MAAM,iBAAiB,OACrB,KACA,KACA,SACG;AACH,MAAI;AACF,SAAM,YAAY,KAAK,IAAI;WACpB,KAAK;AACZ,QAAK,IAAI;;;CAIb,MAAM,SAAS,QAAQ,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,IAAI,KAAK,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
+ {"version":3,"file":"express.mjs","names":[],"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 { autoStartChannels } from \"./auto-start-channels\";\nimport type { CopilotRuntimeHooks } from \"../core/hooks\";\n\n/**\n * An Express {@link Router} that may also carry an optional\n * {@link ChannelsControl} surface. The Router object itself is request-scoped\n * middleware, but an Express app can only run inside a long-running\n * `http.Server` — so this wrapper is a lifecycle-owning host like\n * `createCopilotNodeListener`: it STARTS activation of the runtime's declared\n * managed Channels at creation, and `.channels` is here to observe (`ready()`)\n * or tear down (`stop()`) that activation.\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 builds the control surface for the runtime's\n * declared managed Channels — and, because Express is a long-running host,\n * starts their activation at creation. Defaults to `true`. Set `false` to\n * build no surface and open no socket (tests, short-lived scripts). 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 autoStartChannels(exposedRouter.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":";;;;;;;;AAyHA,SAAgB,4BAA4B,EAC1C,SACA,UACA,OAAO,eACP,MAAM,aAAa,MACnB,OACA,kBACA,mBACqD;CACrD,MAAM,iBAAiB,kBAAkB,SAAS;CAElD,MAAM,UAAU,4BAA4B;EAC1C;EACA,UAAU;EACV;EACA,MAAM;EACN;EACA;EACA;EACD,CAAC;CAEF,MAAM,cAAc,yBAAyB,QAAQ;CAErD,MAAM,iBAAiB,OACrB,KACA,KACA,SACG;AACH,MAAI;AACF,SAAM,YAAY,KAAK,IAAI;WACpB,KAAK;AACZ,QAAK,IAAI;;;CAIb,MAAM,SAAS,QAAQ,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,IAAI,KAAK,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,mBAAkB,cAAc,SAAS;AACzC,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 +1 @@
1
- {"version":3,"file":"hono.cjs","names":["createCopilotRuntimeHandler","Hono"],"sources":["../../../../src/v2/runtime/endpoints/hono.ts"],"sourcesContent":["import { Hono } from \"hono\";\nimport type { CopilotRuntimeLike } from \"../core/runtime\";\nimport { createCopilotRuntimeHandler } from \"../core/fetch-handler\";\nimport type { CopilotCorsConfig } from \"../core/fetch-cors\";\nimport type { CopilotRuntimeHooks } from \"../core/hooks\";\nimport type {\n ActivateChannelEngine,\n ChannelsControl,\n} from \"../core/channel-manager\";\n\n/**\n * A Hono app that may also carry an optional {@link ChannelsControl} surface.\n * Hono's app object is request-scoped routing config, not a long-running\n * process owner Node (`createCopilotNodeListener`) is the lifecycle-owning\n * surface for `.channels`. It is attached here too, best-effort, for callers\n * that mount the Hono app directly and want to start (`ready()`), observe, or\n * stop managed Channel activation without also standing up a Node listener.\n */\nexport type CopilotHonoApp = Hono & { channels?: ChannelsControl };\n\n/**\n * CORS configuration for CopilotKit endpoints.\n * When using credentials (e.g., HTTP-only cookies), you must specify an explicit origin.\n */\nexport interface CopilotEndpointCorsConfig {\n /**\n * Allowed origin(s) for CORS. Can be:\n * - A string: exact origin (e.g., \"https://myapp.com\")\n * - An array: list of allowed origins\n * - A function: dynamic origin resolution\n *\n * Note: When credentials is true, origin cannot be \"*\"\n */\n origin:\n | string\n | string[]\n | ((origin: string, c: any) => string | undefined | null);\n /**\n * Whether to allow credentials (cookies, HTTP authentication).\n * When true, origin must be explicitly specified (not \"*\").\n */\n credentials?: boolean;\n}\n\ninterface CopilotEndpointParams {\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 * Optional CORS configuration. When not provided, defaults to allowing all origins without credentials.\n * To support HTTP-only cookies, provide cors config with credentials: true and explicit origin.\n */\n cors?: CopilotEndpointCorsConfig;\n /**\n * Lifecycle hooks for request processing.\n */\n hooks?: CopilotRuntimeHooks;\n\n /**\n * Whether the underlying handler builds the control surface for the runtime's\n * declared managed Channels. Defaults to `true`. Building it opens no\n * connection — activation is deferred to the first `channels.ready()`. 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/** @deprecated Use `createCopilotHonoHandler` instead. */\nexport const createCopilotEndpoint = createCopilotHonoHandler;\n\nexport function createCopilotHonoHandler({\n runtime,\n basePath,\n mode = \"multi-route\",\n cors: corsConfig,\n hooks,\n activateChannels,\n __channelEngine,\n}: CopilotEndpointParams): CopilotHonoApp {\n const handler = createCopilotRuntimeHandler({\n runtime,\n basePath,\n mode,\n cors: corsConfig ? toFetchCorsConfig(corsConfig) : true,\n hooks,\n activateChannels,\n __channelEngine,\n });\n\n const app = new Hono();\n\n const scopedApp: CopilotHonoApp = app\n .basePath(basePath)\n .all(\"*\", async (c) => handler(c.req.raw));\n scopedApp.channels = handler.channels;\n return scopedApp;\n}\n\n/**\n * Convert Hono-specific CORS config to the fetch handler's CopilotCorsConfig.\n */\nexport function toFetchCorsConfig(\n config: CopilotEndpointCorsConfig,\n): CopilotCorsConfig {\n const origin = config.origin;\n return {\n origin:\n typeof origin === \"function\"\n ? (reqOrigin: string) => origin(reqOrigin, undefined) ?? null\n : origin,\n credentials: config.credentials,\n };\n}\n"],"mappings":";;;;;;;AAgFA,MAAa,wBAAwB;AAErC,SAAgB,yBAAyB,EACvC,SACA,UACA,OAAO,eACP,MAAM,YACN,OACA,kBACA,mBACwC;CACxC,MAAM,UAAUA,kDAA4B;EAC1C;EACA;EACA;EACA,MAAM,aAAa,kBAAkB,WAAW,GAAG;EACnD;EACA;EACA;EACD,CAAC;CAIF,MAAM,YAFM,IAAIC,WAAM,CAGnB,SAAS,SAAS,CAClB,IAAI,KAAK,OAAO,MAAM,QAAQ,EAAE,IAAI,IAAI,CAAC;AAC5C,WAAU,WAAW,QAAQ;AAC7B,QAAO;;;;;AAMT,SAAgB,kBACd,QACmB;CACnB,MAAM,SAAS,OAAO;AACtB,QAAO;EACL,QACE,OAAO,WAAW,cACb,cAAsB,OAAO,WAAW,OAAU,IAAI,OACvD;EACN,aAAa,OAAO;EACrB"}
1
+ {"version":3,"file":"hono.cjs","names":["createCopilotRuntimeHandler","Hono"],"sources":["../../../../src/v2/runtime/endpoints/hono.ts"],"sourcesContent":["import { Hono } from \"hono\";\nimport type { CopilotRuntimeLike } from \"../core/runtime\";\nimport { createCopilotRuntimeHandler } from \"../core/fetch-handler\";\nimport type { CopilotCorsConfig } from \"../core/fetch-cors\";\nimport type { CopilotRuntimeHooks } from \"../core/hooks\";\nimport type {\n ActivateChannelEngine,\n ChannelsControl,\n} from \"../core/channel-manager\";\n\n/**\n * A Hono app that may also carry an optional {@link ChannelsControl} surface.\n *\n * Unlike the Node and Express wrappers which own a process and therefore START\n * managed-Channel activation at creation (OSS-641) — this wrapper stays LAZY:\n * activation is triggered by the first `app.channels.ready()` and never before.\n * A Hono app is multi-runtime and is our edge/serverless surface in practice:\n * every Next.js App Router route handler in `examples/showcases/*` builds one at\n * module scope, and those isolates freeze and recycle per request. Auto-starting\n * there would mint a competing listener for the same Channel on every cold\n * start, which is exactly what the lazy design exists to prevent (see the\n * `createCopilotRuntimeHandler` TSDoc).\n *\n * So on a LONG-RUNNING Hono host (`@hono/node-server`, Bun, Deno) calling\n * `await app.channels.ready()` once at startup is REQUIRED to connect declared\n * Channels; on an edge/serverless host do NOT call it.\n */\nexport type CopilotHonoApp = Hono & { channels?: ChannelsControl };\n\n/**\n * CORS configuration for CopilotKit endpoints.\n * When using credentials (e.g., HTTP-only cookies), you must specify an explicit origin.\n */\nexport interface CopilotEndpointCorsConfig {\n /**\n * Allowed origin(s) for CORS. Can be:\n * - A string: exact origin (e.g., \"https://myapp.com\")\n * - An array: list of allowed origins\n * - A function: dynamic origin resolution\n *\n * Note: When credentials is true, origin cannot be \"*\"\n */\n origin:\n | string\n | string[]\n | ((origin: string, c: any) => string | undefined | null);\n /**\n * Whether to allow credentials (cookies, HTTP authentication).\n * When true, origin must be explicitly specified (not \"*\").\n */\n credentials?: boolean;\n}\n\ninterface CopilotEndpointParams {\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 * Optional CORS configuration. When not provided, defaults to allowing all origins without credentials.\n * To support HTTP-only cookies, provide cors config with credentials: true and explicit origin.\n */\n cors?: CopilotEndpointCorsConfig;\n /**\n * Lifecycle hooks for request processing.\n */\n hooks?: CopilotRuntimeHooks;\n\n /**\n * Whether the underlying handler builds the control surface for the runtime's\n * declared managed Channels. Defaults to `true`. Building it opens no\n * connection — activation is deferred to the first `channels.ready()`. 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/** @deprecated Use `createCopilotHonoHandler` instead. */\nexport const createCopilotEndpoint = createCopilotHonoHandler;\n\nexport function createCopilotHonoHandler({\n runtime,\n basePath,\n mode = \"multi-route\",\n cors: corsConfig,\n hooks,\n activateChannels,\n __channelEngine,\n}: CopilotEndpointParams): CopilotHonoApp {\n const handler = createCopilotRuntimeHandler({\n runtime,\n basePath,\n mode,\n cors: corsConfig ? toFetchCorsConfig(corsConfig) : true,\n hooks,\n activateChannels,\n __channelEngine,\n });\n\n const app = new Hono();\n\n const scopedApp: CopilotHonoApp = app\n .basePath(basePath)\n .all(\"*\", async (c) => handler(c.req.raw));\n scopedApp.channels = handler.channels;\n return scopedApp;\n}\n\n/**\n * Convert Hono-specific CORS config to the fetch handler's CopilotCorsConfig.\n */\nexport function toFetchCorsConfig(\n config: CopilotEndpointCorsConfig,\n): CopilotCorsConfig {\n const origin = config.origin;\n return {\n origin:\n typeof origin === \"function\"\n ? (reqOrigin: string) => origin(reqOrigin, undefined) ?? null\n : origin,\n credentials: config.credentials,\n };\n}\n"],"mappings":";;;;;;;AAyFA,MAAa,wBAAwB;AAErC,SAAgB,yBAAyB,EACvC,SACA,UACA,OAAO,eACP,MAAM,YACN,OACA,kBACA,mBACwC;CACxC,MAAM,UAAUA,kDAA4B;EAC1C;EACA;EACA;EACA,MAAM,aAAa,kBAAkB,WAAW,GAAG;EACnD;EACA;EACA;EACD,CAAC;CAIF,MAAM,YAFM,IAAIC,WAAM,CAGnB,SAAS,SAAS,CAClB,IAAI,KAAK,OAAO,MAAM,QAAQ,EAAE,IAAI,IAAI,CAAC;AAC5C,WAAU,WAAW,QAAQ;AAC7B,QAAO;;;;;AAMT,SAAgB,kBACd,QACmB;CACnB,MAAM,SAAS,OAAO;AACtB,QAAO;EACL,QACE,OAAO,WAAW,cACb,cAAsB,OAAO,WAAW,OAAU,IAAI,OACvD;EACN,aAAa,OAAO;EACrB"}
@@ -8,11 +8,20 @@ import { Hono } from "hono";
8
8
  //#region src/v2/runtime/endpoints/hono.d.ts
9
9
  /**
10
10
  * A Hono app that may also carry an optional {@link ChannelsControl} surface.
11
- * Hono's app object is request-scoped routing config, not a long-running
12
- * process ownerNode (`createCopilotNodeListener`) is the lifecycle-owning
13
- * surface for `.channels`. It is attached here too, best-effort, for callers
14
- * that mount the Hono app directly and want to start (`ready()`), observe, or
15
- * stop managed Channel activation without also standing up a Node listener.
11
+ *
12
+ * Unlike the Node and Express wrappers which own a process and therefore START
13
+ * managed-Channel activation at creation (OSS-641) this wrapper stays LAZY:
14
+ * activation is triggered by the first `app.channels.ready()` and never before.
15
+ * A Hono app is multi-runtime and is our edge/serverless surface in practice:
16
+ * every Next.js App Router route handler in `examples/showcases/*` builds one at
17
+ * module scope, and those isolates freeze and recycle per request. Auto-starting
18
+ * there would mint a competing listener for the same Channel on every cold
19
+ * start, which is exactly what the lazy design exists to prevent (see the
20
+ * `createCopilotRuntimeHandler` TSDoc).
21
+ *
22
+ * So on a LONG-RUNNING Hono host (`@hono/node-server`, Bun, Deno) calling
23
+ * `await app.channels.ready()` once at startup is REQUIRED to connect declared
24
+ * Channels; on an edge/serverless host do NOT call it.
16
25
  */
17
26
  type CopilotHonoApp = Hono & {
18
27
  channels?: ChannelsControl;
@@ -1 +1 @@
1
- {"version":3,"file":"hono.d.cts","names":[],"sources":["../../../../src/v2/runtime/endpoints/hono.ts"],"mappings":";;;;;;;;;;AAkBA;;;;;;KAAY,cAAA,GAAiB,IAAA;EAAS,QAAA,GAAW,eAAA;AAAA;AAMjD;;;;AAAA,UAAiB,yBAAA;EAYT;;;;;AAMP;;;EATC,MAAA,wBAGM,MAAA,UAAgB,CAAA;EAuBf;;;;EAlBP,WAAA;AAAA;AAAA,UAGQ,qBAAA;EACR,OAAA,EAAS,kBAAA;EACT,QAAA;EAaA;;;;;EANA,IAAA;EAwBkB;;;AAGpB;EArBE,IAAA,GAAO,yBAAA;;;;EAIP,KAAA,GAAQ,mBAAA;EAmB8B;;;;;;EAXtC,gBAAA;EAiBA;;;;EAXA,eAAA,GAAkB,qBAAA;AAAA;;cAGP,qBAAA,SAAqB,wBAAA;AAAA,iBAElB,wBAAA,CAAA;EACd,OAAA;EACA,QAAA;EACA,IAAA;EACA,IAAA,EAAM,UAAA;EACN,KAAA;EACA,gBAAA;EACA;AAAA,GACC,qBAAA,GAAwB,cAAA;;;;iBAuBX,iBAAA,CACd,MAAA,EAAQ,yBAAA,GACP,iBAAA"}
1
+ {"version":3,"file":"hono.d.cts","names":[],"sources":["../../../../src/v2/runtime/endpoints/hono.ts"],"mappings":";;;;;;;;;;AA2BA;;;;;;;;;AAMA;;;;;;KANY,cAAA,GAAiB,IAAA;EAAS,QAAA,GAAW,eAAA;AAAA;;AAwBhD;;;UAlBgB,yBAAA;EAmCR;;;;;;;;EA1BP,MAAA,wBAGM,MAAA,UAAgB,CAAA;EAuBtB;;;;EAlBA,WAAA;AAAA;AAAA,UAGQ,qBAAA;EACR,OAAA,EAAS,kBAAA;EACT,QAAA;EAkCW;;;;;EA3BX,IAAA;EA6BsC;;;;EAvBtC,IAAA,GAAO,yBAAA;EA2BD;;;EAvBN,KAAA,GAAQ,mBAAA;EA2BP;;;;;;EAnBD,gBAAA;EAaA;;;;EAPA,eAAA,GAAkB,qBAAA;AAAA;;cAGP,qBAAA,SAAqB,wBAAA;AAAA,iBAElB,wBAAA,CAAA;EACd,OAAA;EACA,QAAA;EACA,IAAA;EACA,IAAA,EAAM,UAAA;EACN,KAAA;EACA,gBAAA;EACA;AAAA,GACC,qBAAA,GAAwB,cAAA;;;;iBAuBX,iBAAA,CACd,MAAA,EAAQ,yBAAA,GACP,iBAAA"}
@@ -8,11 +8,20 @@ import { Hono } from "hono";
8
8
  //#region src/v2/runtime/endpoints/hono.d.ts
9
9
  /**
10
10
  * A Hono app that may also carry an optional {@link ChannelsControl} surface.
11
- * Hono's app object is request-scoped routing config, not a long-running
12
- * process ownerNode (`createCopilotNodeListener`) is the lifecycle-owning
13
- * surface for `.channels`. It is attached here too, best-effort, for callers
14
- * that mount the Hono app directly and want to start (`ready()`), observe, or
15
- * stop managed Channel activation without also standing up a Node listener.
11
+ *
12
+ * Unlike the Node and Express wrappers which own a process and therefore START
13
+ * managed-Channel activation at creation (OSS-641) this wrapper stays LAZY:
14
+ * activation is triggered by the first `app.channels.ready()` and never before.
15
+ * A Hono app is multi-runtime and is our edge/serverless surface in practice:
16
+ * every Next.js App Router route handler in `examples/showcases/*` builds one at
17
+ * module scope, and those isolates freeze and recycle per request. Auto-starting
18
+ * there would mint a competing listener for the same Channel on every cold
19
+ * start, which is exactly what the lazy design exists to prevent (see the
20
+ * `createCopilotRuntimeHandler` TSDoc).
21
+ *
22
+ * So on a LONG-RUNNING Hono host (`@hono/node-server`, Bun, Deno) calling
23
+ * `await app.channels.ready()` once at startup is REQUIRED to connect declared
24
+ * Channels; on an edge/serverless host do NOT call it.
16
25
  */
17
26
  type CopilotHonoApp = Hono & {
18
27
  channels?: ChannelsControl;
@@ -1 +1 @@
1
- {"version":3,"file":"hono.d.mts","names":[],"sources":["../../../../src/v2/runtime/endpoints/hono.ts"],"mappings":";;;;;;;;;;AAkBA;;;;;;KAAY,cAAA,GAAiB,IAAA;EAAS,QAAA,GAAW,eAAA;AAAA;AAMjD;;;;AAAA,UAAiB,yBAAA;EAYT;;;;;AAMP;;;EATC,MAAA,wBAGM,MAAA,UAAgB,CAAA;EAuBf;;;;EAlBP,WAAA;AAAA;AAAA,UAGQ,qBAAA;EACR,OAAA,EAAS,kBAAA;EACT,QAAA;EAaA;;;;;EANA,IAAA;EAwBkB;;;AAGpB;EArBE,IAAA,GAAO,yBAAA;;;;EAIP,KAAA,GAAQ,mBAAA;EAmB8B;;;;;;EAXtC,gBAAA;EAiBA;;;;EAXA,eAAA,GAAkB,qBAAA;AAAA;;cAGP,qBAAA,SAAqB,wBAAA;AAAA,iBAElB,wBAAA,CAAA;EACd,OAAA;EACA,QAAA;EACA,IAAA;EACA,IAAA,EAAM,UAAA;EACN,KAAA;EACA,gBAAA;EACA;AAAA,GACC,qBAAA,GAAwB,cAAA;;;;iBAuBX,iBAAA,CACd,MAAA,EAAQ,yBAAA,GACP,iBAAA"}
1
+ {"version":3,"file":"hono.d.mts","names":[],"sources":["../../../../src/v2/runtime/endpoints/hono.ts"],"mappings":";;;;;;;;;;AA2BA;;;;;;;;;AAMA;;;;;;KANY,cAAA,GAAiB,IAAA;EAAS,QAAA,GAAW,eAAA;AAAA;;AAwBhD;;;UAlBgB,yBAAA;EAmCR;;;;;;;;EA1BP,MAAA,wBAGM,MAAA,UAAgB,CAAA;EAuBtB;;;;EAlBA,WAAA;AAAA;AAAA,UAGQ,qBAAA;EACR,OAAA,EAAS,kBAAA;EACT,QAAA;EAkCW;;;;;EA3BX,IAAA;EA6BsC;;;;EAvBtC,IAAA,GAAO,yBAAA;EA2BD;;;EAvBN,KAAA,GAAQ,mBAAA;EA2BP;;;;;;EAnBD,gBAAA;EAaA;;;;EAPA,eAAA,GAAkB,qBAAA;AAAA;;cAGP,qBAAA,SAAqB,wBAAA;AAAA,iBAElB,wBAAA,CAAA;EACd,OAAA;EACA,QAAA;EACA,IAAA;EACA,IAAA,EAAM,UAAA;EACN,KAAA;EACA,gBAAA;EACA;AAAA,GACC,qBAAA,GAAwB,cAAA;;;;iBAuBX,iBAAA,CACd,MAAA,EAAQ,yBAAA,GACP,iBAAA"}
@@ -1 +1 @@
1
- {"version":3,"file":"hono.mjs","names":[],"sources":["../../../../src/v2/runtime/endpoints/hono.ts"],"sourcesContent":["import { Hono } from \"hono\";\nimport type { CopilotRuntimeLike } from \"../core/runtime\";\nimport { createCopilotRuntimeHandler } from \"../core/fetch-handler\";\nimport type { CopilotCorsConfig } from \"../core/fetch-cors\";\nimport type { CopilotRuntimeHooks } from \"../core/hooks\";\nimport type {\n ActivateChannelEngine,\n ChannelsControl,\n} from \"../core/channel-manager\";\n\n/**\n * A Hono app that may also carry an optional {@link ChannelsControl} surface.\n * Hono's app object is request-scoped routing config, not a long-running\n * process owner Node (`createCopilotNodeListener`) is the lifecycle-owning\n * surface for `.channels`. It is attached here too, best-effort, for callers\n * that mount the Hono app directly and want to start (`ready()`), observe, or\n * stop managed Channel activation without also standing up a Node listener.\n */\nexport type CopilotHonoApp = Hono & { channels?: ChannelsControl };\n\n/**\n * CORS configuration for CopilotKit endpoints.\n * When using credentials (e.g., HTTP-only cookies), you must specify an explicit origin.\n */\nexport interface CopilotEndpointCorsConfig {\n /**\n * Allowed origin(s) for CORS. Can be:\n * - A string: exact origin (e.g., \"https://myapp.com\")\n * - An array: list of allowed origins\n * - A function: dynamic origin resolution\n *\n * Note: When credentials is true, origin cannot be \"*\"\n */\n origin:\n | string\n | string[]\n | ((origin: string, c: any) => string | undefined | null);\n /**\n * Whether to allow credentials (cookies, HTTP authentication).\n * When true, origin must be explicitly specified (not \"*\").\n */\n credentials?: boolean;\n}\n\ninterface CopilotEndpointParams {\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 * Optional CORS configuration. When not provided, defaults to allowing all origins without credentials.\n * To support HTTP-only cookies, provide cors config with credentials: true and explicit origin.\n */\n cors?: CopilotEndpointCorsConfig;\n /**\n * Lifecycle hooks for request processing.\n */\n hooks?: CopilotRuntimeHooks;\n\n /**\n * Whether the underlying handler builds the control surface for the runtime's\n * declared managed Channels. Defaults to `true`. Building it opens no\n * connection — activation is deferred to the first `channels.ready()`. 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/** @deprecated Use `createCopilotHonoHandler` instead. */\nexport const createCopilotEndpoint = createCopilotHonoHandler;\n\nexport function createCopilotHonoHandler({\n runtime,\n basePath,\n mode = \"multi-route\",\n cors: corsConfig,\n hooks,\n activateChannels,\n __channelEngine,\n}: CopilotEndpointParams): CopilotHonoApp {\n const handler = createCopilotRuntimeHandler({\n runtime,\n basePath,\n mode,\n cors: corsConfig ? toFetchCorsConfig(corsConfig) : true,\n hooks,\n activateChannels,\n __channelEngine,\n });\n\n const app = new Hono();\n\n const scopedApp: CopilotHonoApp = app\n .basePath(basePath)\n .all(\"*\", async (c) => handler(c.req.raw));\n scopedApp.channels = handler.channels;\n return scopedApp;\n}\n\n/**\n * Convert Hono-specific CORS config to the fetch handler's CopilotCorsConfig.\n */\nexport function toFetchCorsConfig(\n config: CopilotEndpointCorsConfig,\n): CopilotCorsConfig {\n const origin = config.origin;\n return {\n origin:\n typeof origin === \"function\"\n ? (reqOrigin: string) => origin(reqOrigin, undefined) ?? null\n : origin,\n credentials: config.credentials,\n };\n}\n"],"mappings":";;;;;;AAgFA,MAAa,wBAAwB;AAErC,SAAgB,yBAAyB,EACvC,SACA,UACA,OAAO,eACP,MAAM,YACN,OACA,kBACA,mBACwC;CACxC,MAAM,UAAU,4BAA4B;EAC1C;EACA;EACA;EACA,MAAM,aAAa,kBAAkB,WAAW,GAAG;EACnD;EACA;EACA;EACD,CAAC;CAIF,MAAM,YAFM,IAAI,MAAM,CAGnB,SAAS,SAAS,CAClB,IAAI,KAAK,OAAO,MAAM,QAAQ,EAAE,IAAI,IAAI,CAAC;AAC5C,WAAU,WAAW,QAAQ;AAC7B,QAAO;;;;;AAMT,SAAgB,kBACd,QACmB;CACnB,MAAM,SAAS,OAAO;AACtB,QAAO;EACL,QACE,OAAO,WAAW,cACb,cAAsB,OAAO,WAAW,OAAU,IAAI,OACvD;EACN,aAAa,OAAO;EACrB"}
1
+ {"version":3,"file":"hono.mjs","names":[],"sources":["../../../../src/v2/runtime/endpoints/hono.ts"],"sourcesContent":["import { Hono } from \"hono\";\nimport type { CopilotRuntimeLike } from \"../core/runtime\";\nimport { createCopilotRuntimeHandler } from \"../core/fetch-handler\";\nimport type { CopilotCorsConfig } from \"../core/fetch-cors\";\nimport type { CopilotRuntimeHooks } from \"../core/hooks\";\nimport type {\n ActivateChannelEngine,\n ChannelsControl,\n} from \"../core/channel-manager\";\n\n/**\n * A Hono app that may also carry an optional {@link ChannelsControl} surface.\n *\n * Unlike the Node and Express wrappers which own a process and therefore START\n * managed-Channel activation at creation (OSS-641) — this wrapper stays LAZY:\n * activation is triggered by the first `app.channels.ready()` and never before.\n * A Hono app is multi-runtime and is our edge/serverless surface in practice:\n * every Next.js App Router route handler in `examples/showcases/*` builds one at\n * module scope, and those isolates freeze and recycle per request. Auto-starting\n * there would mint a competing listener for the same Channel on every cold\n * start, which is exactly what the lazy design exists to prevent (see the\n * `createCopilotRuntimeHandler` TSDoc).\n *\n * So on a LONG-RUNNING Hono host (`@hono/node-server`, Bun, Deno) calling\n * `await app.channels.ready()` once at startup is REQUIRED to connect declared\n * Channels; on an edge/serverless host do NOT call it.\n */\nexport type CopilotHonoApp = Hono & { channels?: ChannelsControl };\n\n/**\n * CORS configuration for CopilotKit endpoints.\n * When using credentials (e.g., HTTP-only cookies), you must specify an explicit origin.\n */\nexport interface CopilotEndpointCorsConfig {\n /**\n * Allowed origin(s) for CORS. Can be:\n * - A string: exact origin (e.g., \"https://myapp.com\")\n * - An array: list of allowed origins\n * - A function: dynamic origin resolution\n *\n * Note: When credentials is true, origin cannot be \"*\"\n */\n origin:\n | string\n | string[]\n | ((origin: string, c: any) => string | undefined | null);\n /**\n * Whether to allow credentials (cookies, HTTP authentication).\n * When true, origin must be explicitly specified (not \"*\").\n */\n credentials?: boolean;\n}\n\ninterface CopilotEndpointParams {\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 * Optional CORS configuration. When not provided, defaults to allowing all origins without credentials.\n * To support HTTP-only cookies, provide cors config with credentials: true and explicit origin.\n */\n cors?: CopilotEndpointCorsConfig;\n /**\n * Lifecycle hooks for request processing.\n */\n hooks?: CopilotRuntimeHooks;\n\n /**\n * Whether the underlying handler builds the control surface for the runtime's\n * declared managed Channels. Defaults to `true`. Building it opens no\n * connection — activation is deferred to the first `channels.ready()`. 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/** @deprecated Use `createCopilotHonoHandler` instead. */\nexport const createCopilotEndpoint = createCopilotHonoHandler;\n\nexport function createCopilotHonoHandler({\n runtime,\n basePath,\n mode = \"multi-route\",\n cors: corsConfig,\n hooks,\n activateChannels,\n __channelEngine,\n}: CopilotEndpointParams): CopilotHonoApp {\n const handler = createCopilotRuntimeHandler({\n runtime,\n basePath,\n mode,\n cors: corsConfig ? toFetchCorsConfig(corsConfig) : true,\n hooks,\n activateChannels,\n __channelEngine,\n });\n\n const app = new Hono();\n\n const scopedApp: CopilotHonoApp = app\n .basePath(basePath)\n .all(\"*\", async (c) => handler(c.req.raw));\n scopedApp.channels = handler.channels;\n return scopedApp;\n}\n\n/**\n * Convert Hono-specific CORS config to the fetch handler's CopilotCorsConfig.\n */\nexport function toFetchCorsConfig(\n config: CopilotEndpointCorsConfig,\n): CopilotCorsConfig {\n const origin = config.origin;\n return {\n origin:\n typeof origin === \"function\"\n ? (reqOrigin: string) => origin(reqOrigin, undefined) ?? null\n : origin,\n credentials: config.credentials,\n };\n}\n"],"mappings":";;;;;;AAyFA,MAAa,wBAAwB;AAErC,SAAgB,yBAAyB,EACvC,SACA,UACA,OAAO,eACP,MAAM,YACN,OACA,kBACA,mBACwC;CACxC,MAAM,UAAU,4BAA4B;EAC1C;EACA;EACA;EACA,MAAM,aAAa,kBAAkB,WAAW,GAAG;EACnD;EACA;EACA;EACD,CAAC;CAIF,MAAM,YAFM,IAAI,MAAM,CAGnB,SAAS,SAAS,CAClB,IAAI,KAAK,OAAO,MAAM,QAAQ,EAAE,IAAI,IAAI,CAAC;AAC5C,WAAU,WAAW,QAAQ;AAC7B,QAAO;;;;;AAMT,SAAgB,kBACd,QACmB;CACnB,MAAM,SAAS,OAAO;AACtB,QAAO;EACL,QACE,OAAO,WAAW,cACb,cAAsB,OAAO,WAAW,OAAU,IAAI,OACvD;EACN,aAAa,OAAO;EACrB"}
@@ -1,12 +1,14 @@
1
1
  require("reflect-metadata");
2
2
  const require_fetch_handler = require('../core/fetch-handler.cjs');
3
3
  const require_node_fetch_handler = require('./node-fetch-handler.cjs');
4
+ const require_auto_start_channels = require('./auto-start-channels.cjs');
4
5
 
5
6
  //#region src/v2/runtime/endpoints/node.ts
6
7
  function createCopilotNodeListener(options) {
7
8
  const handler = require_fetch_handler.createCopilotRuntimeHandler(options);
8
9
  const listener = require_node_fetch_handler.createCopilotNodeHandler(handler);
9
10
  listener.channels = handler.channels;
11
+ require_auto_start_channels.autoStartChannels(listener.channels);
10
12
  return listener;
11
13
  }
12
14
 
@@ -1 +1 @@
1
- {"version":3,"file":"node.cjs","names":["createCopilotRuntimeHandler","createCopilotNodeHandler"],"sources":["../../../../src/v2/runtime/endpoints/node.ts"],"sourcesContent":["import { createCopilotRuntimeHandler } from \"../core/fetch-handler\";\nimport type { CopilotRuntimeHandlerOptions } from \"../core/fetch-handler\";\nimport type { RuntimeWithDeclaredChannels } from \"../core/runtime\";\nimport type { ChannelsControl } from \"../core/channel-manager\";\nimport { createCopilotNodeHandler } from \"./node-fetch-handler\";\nimport type { NodeFetchHandler } from \"./node-fetch-handler\";\n\n/**\n * A Node.js HTTP request listener that is also a callable object carrying an\n * optional {@link ChannelsControl} surface, mirroring\n * `CopilotRuntimeFetchHandler.channels`. Node is the long-running,\n * lifecycle-owning entry point for the runtime, so it is the surface that\n * exposes `.channels` for callers that need to start, observe, or stop managed\n * Channel activation.\n */\nexport type NodeCopilotListener = NodeFetchHandler & {\n channels?: ChannelsControl;\n};\n\n/**\n * A {@link NodeCopilotListener} whose {@link ChannelsControl} surface is\n * guaranteed present. Returned when the runtime was constructed with at least\n * one declared Intelligence Channel and activation was not opted out of, so the\n * documented `listener.channels.ready(...)` call type-checks without a `!` or a\n * `?.` under strict TypeScript — the Node mirror of\n * `CopilotRuntimeFetchHandlerWithChannels`.\n */\nexport type NodeCopilotListenerWithChannels = NodeFetchHandler & {\n /** Lifecycle control surface for the runtime's declared managed Channels. */\n channels: ChannelsControl;\n};\n\n/**\n * Convenience wrapper for creating a Node.js HTTP request listener\n * from CopilotKit runtime handler options.\n *\n * When the runtime declares managed Channels (and activation was not opted\n * out of via `activateChannels: false`), the returned listener exposes\n * `.channels` — the same {@link ChannelsControl} surface carried by the\n * underlying fetch handler.\n *\n * ## Managed Channels lifecycle\n *\n * Creating the listener opens NO connection. Activation — which opens the\n * persistent Realtime Gateway WebSocket and starts every direct adapter on the\n * declared Channels is LAZY: it is triggered by the first\n * `await listener.channels.ready()` and never before, neither at creation nor on\n * the first HTTP request. On a long-running host that call is REQUIRED, not\n * optional: without it the process serves HTTP but no Channel is ever connected.\n * `listener.channels.stop()` tears activation down. See the\n * `createCopilotRuntimeHandler` TSDoc for why activation is deferred\n * (serverless/edge safety).\n *\n * @example\n * ```typescript\n * import { createServer } from \"node:http\";\n * import { CopilotRuntime } from \"@copilotkit/runtime/v2\";\n * import { createCopilotNodeListener } from \"@copilotkit/runtime/v2/node\";\n *\n * const listener = createCopilotNodeListener({\n * runtime: new CopilotRuntime({ agents: { ... } }),\n * basePath: \"/api/copilotkit\",\n * cors: true,\n * });\n * createServer(listener).listen(3000);\n *\n * // Required to connect declared managed Channels. Bound it so one wedged\n * // adapter cannot hang startup forever.\n * await listener.channels.ready({ timeoutMs: 30_000 });\n * ```\n */\n/**\n * Overload: a runtime constructed with at least one declared Intelligence\n * Channel (a {@link RuntimeWithDeclaredChannels}-branded runtime), when\n * activation is not disabled, yields a listener with a **non-optional**\n * {@link ChannelsControl}. `activateChannels` is constrained to\n * `true | undefined` here so passing `activateChannels: false` (which leaves no\n * `.channels`) falls through to the optional-shape overload below rather than\n * dishonestly promising a control surface that will not exist. Mirrors the\n * `createCopilotRuntimeHandler` overload pair so the brand survives the wrapper.\n *\n * The brand comes from constructing the runtime with a literal non-empty\n * `channels` list (`readonly [Channel, ...Channel[]]`). A runtime built from a\n * dynamically-assembled `Channel[]` is not branded, so it falls to the\n * optional-shape overload and its call sites still need `?.`.\n */\nexport function createCopilotNodeListener(\n options: CopilotRuntimeHandlerOptions & {\n runtime: RuntimeWithDeclaredChannels;\n activateChannels?: true | undefined;\n },\n): NodeCopilotListenerWithChannels;\n/**\n * Overload: every other runtime (SSE, Intelligence without channels, or with\n * activation disabled) yields a listener whose `.channels` is optional.\n */\nexport function createCopilotNodeListener(\n options: CopilotRuntimeHandlerOptions,\n): NodeCopilotListener;\nexport function createCopilotNodeListener(\n options: CopilotRuntimeHandlerOptions,\n): NodeCopilotListener {\n const handler = createCopilotRuntimeHandler(options);\n const listener: NodeCopilotListener = createCopilotNodeHandler(handler);\n listener.channels = handler.channels;\n return listener;\n}\n"],"mappings":";;;;;AAmGA,SAAgB,0BACd,SACqB;CACrB,MAAM,UAAUA,kDAA4B,QAAQ;CACpD,MAAM,WAAgCC,oDAAyB,QAAQ;AACvE,UAAS,WAAW,QAAQ;AAC5B,QAAO"}
1
+ {"version":3,"file":"node.cjs","names":["createCopilotRuntimeHandler","createCopilotNodeHandler"],"sources":["../../../../src/v2/runtime/endpoints/node.ts"],"sourcesContent":["import { createCopilotRuntimeHandler } from \"../core/fetch-handler\";\nimport type { CopilotRuntimeHandlerOptions } from \"../core/fetch-handler\";\nimport type { RuntimeWithDeclaredChannels } from \"../core/runtime\";\nimport type { ChannelsControl } from \"../core/channel-manager\";\nimport { createCopilotNodeHandler } from \"./node-fetch-handler\";\nimport type { NodeFetchHandler } from \"./node-fetch-handler\";\nimport { autoStartChannels } from \"./auto-start-channels\";\n\n/**\n * A Node.js HTTP request listener that is also a callable object carrying an\n * optional {@link ChannelsControl} surface, mirroring\n * `CopilotRuntimeFetchHandler.channels`. Node is the long-running,\n * lifecycle-owning entry point for the runtime, so it is the surface that\n * exposes `.channels` for callers that need to observe or stop the managed\n * Channel activation the listener starts at creation.\n */\nexport type NodeCopilotListener = NodeFetchHandler & {\n channels?: ChannelsControl;\n};\n\n/**\n * A {@link NodeCopilotListener} whose {@link ChannelsControl} surface is\n * guaranteed present. Returned when the runtime was constructed with at least\n * one declared Intelligence Channel and activation was not opted out of, so the\n * documented `listener.channels.ready(...)` call type-checks without a `!` or a\n * `?.` under strict TypeScript — the Node mirror of\n * `CopilotRuntimeFetchHandlerWithChannels`.\n */\nexport type NodeCopilotListenerWithChannels = NodeFetchHandler & {\n /** Lifecycle control surface for the runtime's declared managed Channels. */\n channels: ChannelsControl;\n};\n\n/**\n * Convenience wrapper for creating a Node.js HTTP request listener\n * from CopilotKit runtime handler options.\n *\n * When the runtime declares managed Channels (and activation was not opted\n * out of via `activateChannels: false`), the returned listener exposes\n * `.channels` — the same {@link ChannelsControl} surface carried by the\n * underlying fetch handler.\n *\n * ## Managed Channels lifecycle\n *\n * Creating the listener STARTS activation — which opens the persistent Realtime\n * Gateway WebSocket and starts every direct adapter on the declared Channels.\n * Node owns its own process lifetime, so there is nothing to defer to and no\n * required incantation: a declared Channel connects because it was declared.\n * (The generic `createCopilotRuntimeHandler` is the opposite — it stays lazy for\n * serverless/edge safety; see its TSDoc.)\n *\n * `await listener.channels.ready()` is therefore OPTIONAL and purely\n * await-and-observe: it resolves once every declared Channel has settled to\n * `online`/`setup_required` and rejects with the activation failure, observing\n * the activation started at creation rather than triggering a second one. Await\n * it when startup should block on Channels being live (or should exit non-zero\n * when they are not); skip it and activation failures land in the logs instead.\n * `listener.channels.stop()` tears activation down.\n *\n * Pass `activateChannels: false` to build no control surface and open no socket\n * — the clean opt-out for a test or a short-lived script that mounts the\n * listener without wanting its Channels connected.\n *\n * @example\n * ```typescript\n * import { createServer } from \"node:http\";\n * import { CopilotRuntime } from \"@copilotkit/runtime/v2\";\n * import { createCopilotNodeListener } from \"@copilotkit/runtime/v2/node\";\n *\n * const listener = createCopilotNodeListener({\n * runtime: new CopilotRuntime({ agents: { ... } }),\n * basePath: \"/api/copilotkit\",\n * cors: true,\n * });\n * createServer(listener).listen(3000);\n * // Declared managed Channels are already connecting at this point.\n *\n * // Optional: block startup on them being live. Bound it so one wedged adapter\n * // cannot hang startup forever.\n * await listener.channels.ready({ timeoutMs: 30_000 });\n * ```\n */\n/**\n * Overload: a runtime constructed with at least one declared Intelligence\n * Channel (a {@link RuntimeWithDeclaredChannels}-branded runtime), when\n * activation is not disabled, yields a listener with a **non-optional**\n * {@link ChannelsControl}. `activateChannels` is constrained to\n * `true | undefined` here so passing `activateChannels: false` (which leaves no\n * `.channels`) falls through to the optional-shape overload below rather than\n * dishonestly promising a control surface that will not exist. Mirrors the\n * `createCopilotRuntimeHandler` overload pair so the brand survives the wrapper.\n *\n * The brand comes from constructing the runtime with a literal non-empty\n * `channels` list (`readonly [Channel, ...Channel[]]`). A runtime built from a\n * dynamically-assembled `Channel[]` is not branded, so it falls to the\n * optional-shape overload and its call sites still need `?.`.\n */\nexport function createCopilotNodeListener(\n options: CopilotRuntimeHandlerOptions & {\n runtime: RuntimeWithDeclaredChannels;\n activateChannels?: true | undefined;\n },\n): NodeCopilotListenerWithChannels;\n/**\n * Overload: every other runtime (SSE, Intelligence without channels, or with\n * activation disabled) yields a listener whose `.channels` is optional.\n */\nexport function createCopilotNodeListener(\n options: CopilotRuntimeHandlerOptions,\n): NodeCopilotListener;\nexport function createCopilotNodeListener(\n options: CopilotRuntimeHandlerOptions,\n): NodeCopilotListener {\n const handler = createCopilotRuntimeHandler(options);\n const listener: NodeCopilotListener = createCopilotNodeHandler(handler);\n listener.channels = handler.channels;\n autoStartChannels(listener.channels);\n return listener;\n}\n"],"mappings":";;;;;;AA8GA,SAAgB,0BACd,SACqB;CACrB,MAAM,UAAUA,kDAA4B,QAAQ;CACpD,MAAM,WAAgCC,oDAAyB,QAAQ;AACvE,UAAS,WAAW,QAAQ;AAC5B,+CAAkB,SAAS,SAAS;AACpC,QAAO"}
@@ -10,8 +10,8 @@ import { NodeFetchHandler } from "./node-fetch-handler.cjs";
10
10
  * optional {@link ChannelsControl} surface, mirroring
11
11
  * `CopilotRuntimeFetchHandler.channels`. Node is the long-running,
12
12
  * lifecycle-owning entry point for the runtime, so it is the surface that
13
- * exposes `.channels` for callers that need to start, observe, or stop managed
14
- * Channel activation.
13
+ * exposes `.channels` for callers that need to observe or stop the managed
14
+ * Channel activation the listener starts at creation.
15
15
  */
16
16
  type NodeCopilotListener = NodeFetchHandler & {
17
17
  channels?: ChannelsControl;
@@ -38,15 +38,24 @@ type NodeCopilotListenerWithChannels = NodeFetchHandler & {
38
38
  *
39
39
  * ## Managed Channels lifecycle
40
40
  *
41
- * Creating the listener opens NO connection. Activation — which opens the
42
- * persistent Realtime Gateway WebSocket and starts every direct adapter on the
43
- * declared Channels is LAZY: it is triggered by the first
44
- * `await listener.channels.ready()` and never before, neither at creation nor on
45
- * the first HTTP request. On a long-running host that call is REQUIRED, not
46
- * optional: without it the process serves HTTP but no Channel is ever connected.
47
- * `listener.channels.stop()` tears activation down. See the
48
- * `createCopilotRuntimeHandler` TSDoc for why activation is deferred
49
- * (serverless/edge safety).
41
+ * Creating the listener STARTS activation — which opens the persistent Realtime
42
+ * Gateway WebSocket and starts every direct adapter on the declared Channels.
43
+ * Node owns its own process lifetime, so there is nothing to defer to and no
44
+ * required incantation: a declared Channel connects because it was declared.
45
+ * (The generic `createCopilotRuntimeHandler` is the opposite it stays lazy for
46
+ * serverless/edge safety; see its TSDoc.)
47
+ *
48
+ * `await listener.channels.ready()` is therefore OPTIONAL and purely
49
+ * await-and-observe: it resolves once every declared Channel has settled to
50
+ * `online`/`setup_required` and rejects with the activation failure, observing
51
+ * the activation started at creation rather than triggering a second one. Await
52
+ * it when startup should block on Channels being live (or should exit non-zero
53
+ * when they are not); skip it and activation failures land in the logs instead.
54
+ * `listener.channels.stop()` tears activation down.
55
+ *
56
+ * Pass `activateChannels: false` to build no control surface and open no socket
57
+ * — the clean opt-out for a test or a short-lived script that mounts the
58
+ * listener without wanting its Channels connected.
50
59
  *
51
60
  * @example
52
61
  * ```typescript
@@ -60,9 +69,10 @@ type NodeCopilotListenerWithChannels = NodeFetchHandler & {
60
69
  * cors: true,
61
70
  * });
62
71
  * createServer(listener).listen(3000);
72
+ * // Declared managed Channels are already connecting at this point.
63
73
  *
64
- * // Required to connect declared managed Channels. Bound it so one wedged
65
- * // adapter cannot hang startup forever.
74
+ * // Optional: block startup on them being live. Bound it so one wedged adapter
75
+ * // cannot hang startup forever.
66
76
  * await listener.channels.ready({ timeoutMs: 30_000 });
67
77
  * ```
68
78
  */
@@ -1 +1 @@
1
- {"version":3,"file":"node.d.cts","names":[],"sources":["../../../../src/v2/runtime/endpoints/node.ts"],"mappings":";;;;;;;;;AAeA;;;;;;KAAY,mBAAA,GAAsB,gBAAA;EAChC,QAAA,GAAW,eAAA;AAAA;AAWb;;;;;;;;AAAA,KAAY,+BAAA,GAAkC,gBAAA;EA2D9B,6EAzDd,QAAA,EAAU,eAAA;AAAA;;;;;;;;;;;;;;AAmEZ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;iBAVgB,yBAAA,CACd,OAAA,EAAS,4BAAA;EACP,OAAA,EAAS,2BAAA;EACT,gBAAA;AAAA,IAED,+BAAA;;;;;iBAKa,yBAAA,CACd,OAAA,EAAS,4BAAA,GACR,mBAAA"}
1
+ {"version":3,"file":"node.d.cts","names":[],"sources":["../../../../src/v2/runtime/endpoints/node.ts"],"mappings":";;;;;;;;;AAgBA;;;;;;KAAY,mBAAA,GAAsB,gBAAA;EAChC,QAAA,GAAW,eAAA;AAAA;AAWb;;;;;;;;AAAA,KAAY,+BAAA,GAAkC,gBAAA;EAqE9B,6EAnEd,QAAA,EAAU,eAAA;AAAA;;;;;;;;;;;;;;AA6EZ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;iBAVgB,yBAAA,CACd,OAAA,EAAS,4BAAA;EACP,OAAA,EAAS,2BAAA;EACT,gBAAA;AAAA,IAED,+BAAA;;;;;iBAKa,yBAAA,CACd,OAAA,EAAS,4BAAA,GACR,mBAAA"}
@@ -10,8 +10,8 @@ import { NodeFetchHandler } from "./node-fetch-handler.mjs";
10
10
  * optional {@link ChannelsControl} surface, mirroring
11
11
  * `CopilotRuntimeFetchHandler.channels`. Node is the long-running,
12
12
  * lifecycle-owning entry point for the runtime, so it is the surface that
13
- * exposes `.channels` for callers that need to start, observe, or stop managed
14
- * Channel activation.
13
+ * exposes `.channels` for callers that need to observe or stop the managed
14
+ * Channel activation the listener starts at creation.
15
15
  */
16
16
  type NodeCopilotListener = NodeFetchHandler & {
17
17
  channels?: ChannelsControl;
@@ -38,15 +38,24 @@ type NodeCopilotListenerWithChannels = NodeFetchHandler & {
38
38
  *
39
39
  * ## Managed Channels lifecycle
40
40
  *
41
- * Creating the listener opens NO connection. Activation — which opens the
42
- * persistent Realtime Gateway WebSocket and starts every direct adapter on the
43
- * declared Channels is LAZY: it is triggered by the first
44
- * `await listener.channels.ready()` and never before, neither at creation nor on
45
- * the first HTTP request. On a long-running host that call is REQUIRED, not
46
- * optional: without it the process serves HTTP but no Channel is ever connected.
47
- * `listener.channels.stop()` tears activation down. See the
48
- * `createCopilotRuntimeHandler` TSDoc for why activation is deferred
49
- * (serverless/edge safety).
41
+ * Creating the listener STARTS activation — which opens the persistent Realtime
42
+ * Gateway WebSocket and starts every direct adapter on the declared Channels.
43
+ * Node owns its own process lifetime, so there is nothing to defer to and no
44
+ * required incantation: a declared Channel connects because it was declared.
45
+ * (The generic `createCopilotRuntimeHandler` is the opposite it stays lazy for
46
+ * serverless/edge safety; see its TSDoc.)
47
+ *
48
+ * `await listener.channels.ready()` is therefore OPTIONAL and purely
49
+ * await-and-observe: it resolves once every declared Channel has settled to
50
+ * `online`/`setup_required` and rejects with the activation failure, observing
51
+ * the activation started at creation rather than triggering a second one. Await
52
+ * it when startup should block on Channels being live (or should exit non-zero
53
+ * when they are not); skip it and activation failures land in the logs instead.
54
+ * `listener.channels.stop()` tears activation down.
55
+ *
56
+ * Pass `activateChannels: false` to build no control surface and open no socket
57
+ * — the clean opt-out for a test or a short-lived script that mounts the
58
+ * listener without wanting its Channels connected.
50
59
  *
51
60
  * @example
52
61
  * ```typescript
@@ -60,9 +69,10 @@ type NodeCopilotListenerWithChannels = NodeFetchHandler & {
60
69
  * cors: true,
61
70
  * });
62
71
  * createServer(listener).listen(3000);
72
+ * // Declared managed Channels are already connecting at this point.
63
73
  *
64
- * // Required to connect declared managed Channels. Bound it so one wedged
65
- * // adapter cannot hang startup forever.
74
+ * // Optional: block startup on them being live. Bound it so one wedged adapter
75
+ * // cannot hang startup forever.
66
76
  * await listener.channels.ready({ timeoutMs: 30_000 });
67
77
  * ```
68
78
  */
@@ -1 +1 @@
1
- {"version":3,"file":"node.d.mts","names":[],"sources":["../../../../src/v2/runtime/endpoints/node.ts"],"mappings":";;;;;;;;;AAeA;;;;;;KAAY,mBAAA,GAAsB,gBAAA;EAChC,QAAA,GAAW,eAAA;AAAA;AAWb;;;;;;;;AAAA,KAAY,+BAAA,GAAkC,gBAAA;EA2D9B,6EAzDd,QAAA,EAAU,eAAA;AAAA;;;;;;;;;;;;;;AAmEZ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;iBAVgB,yBAAA,CACd,OAAA,EAAS,4BAAA;EACP,OAAA,EAAS,2BAAA;EACT,gBAAA;AAAA,IAED,+BAAA;;;;;iBAKa,yBAAA,CACd,OAAA,EAAS,4BAAA,GACR,mBAAA"}
1
+ {"version":3,"file":"node.d.mts","names":[],"sources":["../../../../src/v2/runtime/endpoints/node.ts"],"mappings":";;;;;;;;;AAgBA;;;;;;KAAY,mBAAA,GAAsB,gBAAA;EAChC,QAAA,GAAW,eAAA;AAAA;AAWb;;;;;;;;AAAA,KAAY,+BAAA,GAAkC,gBAAA;EAqE9B,6EAnEd,QAAA,EAAU,eAAA;AAAA;;;;;;;;;;;;;;AA6EZ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;iBAVgB,yBAAA,CACd,OAAA,EAAS,4BAAA;EACP,OAAA,EAAS,2BAAA;EACT,gBAAA;AAAA,IAED,+BAAA;;;;;iBAKa,yBAAA,CACd,OAAA,EAAS,4BAAA,GACR,mBAAA"}
@@ -1,12 +1,14 @@
1
1
  import "reflect-metadata";
2
2
  import { createCopilotRuntimeHandler } from "../core/fetch-handler.mjs";
3
3
  import { createCopilotNodeHandler } from "./node-fetch-handler.mjs";
4
+ import { autoStartChannels } from "./auto-start-channels.mjs";
4
5
 
5
6
  //#region src/v2/runtime/endpoints/node.ts
6
7
  function createCopilotNodeListener(options) {
7
8
  const handler = createCopilotRuntimeHandler(options);
8
9
  const listener = createCopilotNodeHandler(handler);
9
10
  listener.channels = handler.channels;
11
+ autoStartChannels(listener.channels);
10
12
  return listener;
11
13
  }
12
14
 
@@ -1 +1 @@
1
- {"version":3,"file":"node.mjs","names":[],"sources":["../../../../src/v2/runtime/endpoints/node.ts"],"sourcesContent":["import { createCopilotRuntimeHandler } from \"../core/fetch-handler\";\nimport type { CopilotRuntimeHandlerOptions } from \"../core/fetch-handler\";\nimport type { RuntimeWithDeclaredChannels } from \"../core/runtime\";\nimport type { ChannelsControl } from \"../core/channel-manager\";\nimport { createCopilotNodeHandler } from \"./node-fetch-handler\";\nimport type { NodeFetchHandler } from \"./node-fetch-handler\";\n\n/**\n * A Node.js HTTP request listener that is also a callable object carrying an\n * optional {@link ChannelsControl} surface, mirroring\n * `CopilotRuntimeFetchHandler.channels`. Node is the long-running,\n * lifecycle-owning entry point for the runtime, so it is the surface that\n * exposes `.channels` for callers that need to start, observe, or stop managed\n * Channel activation.\n */\nexport type NodeCopilotListener = NodeFetchHandler & {\n channels?: ChannelsControl;\n};\n\n/**\n * A {@link NodeCopilotListener} whose {@link ChannelsControl} surface is\n * guaranteed present. Returned when the runtime was constructed with at least\n * one declared Intelligence Channel and activation was not opted out of, so the\n * documented `listener.channels.ready(...)` call type-checks without a `!` or a\n * `?.` under strict TypeScript — the Node mirror of\n * `CopilotRuntimeFetchHandlerWithChannels`.\n */\nexport type NodeCopilotListenerWithChannels = NodeFetchHandler & {\n /** Lifecycle control surface for the runtime's declared managed Channels. */\n channels: ChannelsControl;\n};\n\n/**\n * Convenience wrapper for creating a Node.js HTTP request listener\n * from CopilotKit runtime handler options.\n *\n * When the runtime declares managed Channels (and activation was not opted\n * out of via `activateChannels: false`), the returned listener exposes\n * `.channels` — the same {@link ChannelsControl} surface carried by the\n * underlying fetch handler.\n *\n * ## Managed Channels lifecycle\n *\n * Creating the listener opens NO connection. Activation — which opens the\n * persistent Realtime Gateway WebSocket and starts every direct adapter on the\n * declared Channels is LAZY: it is triggered by the first\n * `await listener.channels.ready()` and never before, neither at creation nor on\n * the first HTTP request. On a long-running host that call is REQUIRED, not\n * optional: without it the process serves HTTP but no Channel is ever connected.\n * `listener.channels.stop()` tears activation down. See the\n * `createCopilotRuntimeHandler` TSDoc for why activation is deferred\n * (serverless/edge safety).\n *\n * @example\n * ```typescript\n * import { createServer } from \"node:http\";\n * import { CopilotRuntime } from \"@copilotkit/runtime/v2\";\n * import { createCopilotNodeListener } from \"@copilotkit/runtime/v2/node\";\n *\n * const listener = createCopilotNodeListener({\n * runtime: new CopilotRuntime({ agents: { ... } }),\n * basePath: \"/api/copilotkit\",\n * cors: true,\n * });\n * createServer(listener).listen(3000);\n *\n * // Required to connect declared managed Channels. Bound it so one wedged\n * // adapter cannot hang startup forever.\n * await listener.channels.ready({ timeoutMs: 30_000 });\n * ```\n */\n/**\n * Overload: a runtime constructed with at least one declared Intelligence\n * Channel (a {@link RuntimeWithDeclaredChannels}-branded runtime), when\n * activation is not disabled, yields a listener with a **non-optional**\n * {@link ChannelsControl}. `activateChannels` is constrained to\n * `true | undefined` here so passing `activateChannels: false` (which leaves no\n * `.channels`) falls through to the optional-shape overload below rather than\n * dishonestly promising a control surface that will not exist. Mirrors the\n * `createCopilotRuntimeHandler` overload pair so the brand survives the wrapper.\n *\n * The brand comes from constructing the runtime with a literal non-empty\n * `channels` list (`readonly [Channel, ...Channel[]]`). A runtime built from a\n * dynamically-assembled `Channel[]` is not branded, so it falls to the\n * optional-shape overload and its call sites still need `?.`.\n */\nexport function createCopilotNodeListener(\n options: CopilotRuntimeHandlerOptions & {\n runtime: RuntimeWithDeclaredChannels;\n activateChannels?: true | undefined;\n },\n): NodeCopilotListenerWithChannels;\n/**\n * Overload: every other runtime (SSE, Intelligence without channels, or with\n * activation disabled) yields a listener whose `.channels` is optional.\n */\nexport function createCopilotNodeListener(\n options: CopilotRuntimeHandlerOptions,\n): NodeCopilotListener;\nexport function createCopilotNodeListener(\n options: CopilotRuntimeHandlerOptions,\n): NodeCopilotListener {\n const handler = createCopilotRuntimeHandler(options);\n const listener: NodeCopilotListener = createCopilotNodeHandler(handler);\n listener.channels = handler.channels;\n return listener;\n}\n"],"mappings":";;;;;AAmGA,SAAgB,0BACd,SACqB;CACrB,MAAM,UAAU,4BAA4B,QAAQ;CACpD,MAAM,WAAgC,yBAAyB,QAAQ;AACvE,UAAS,WAAW,QAAQ;AAC5B,QAAO"}
1
+ {"version":3,"file":"node.mjs","names":[],"sources":["../../../../src/v2/runtime/endpoints/node.ts"],"sourcesContent":["import { createCopilotRuntimeHandler } from \"../core/fetch-handler\";\nimport type { CopilotRuntimeHandlerOptions } from \"../core/fetch-handler\";\nimport type { RuntimeWithDeclaredChannels } from \"../core/runtime\";\nimport type { ChannelsControl } from \"../core/channel-manager\";\nimport { createCopilotNodeHandler } from \"./node-fetch-handler\";\nimport type { NodeFetchHandler } from \"./node-fetch-handler\";\nimport { autoStartChannels } from \"./auto-start-channels\";\n\n/**\n * A Node.js HTTP request listener that is also a callable object carrying an\n * optional {@link ChannelsControl} surface, mirroring\n * `CopilotRuntimeFetchHandler.channels`. Node is the long-running,\n * lifecycle-owning entry point for the runtime, so it is the surface that\n * exposes `.channels` for callers that need to observe or stop the managed\n * Channel activation the listener starts at creation.\n */\nexport type NodeCopilotListener = NodeFetchHandler & {\n channels?: ChannelsControl;\n};\n\n/**\n * A {@link NodeCopilotListener} whose {@link ChannelsControl} surface is\n * guaranteed present. Returned when the runtime was constructed with at least\n * one declared Intelligence Channel and activation was not opted out of, so the\n * documented `listener.channels.ready(...)` call type-checks without a `!` or a\n * `?.` under strict TypeScript — the Node mirror of\n * `CopilotRuntimeFetchHandlerWithChannels`.\n */\nexport type NodeCopilotListenerWithChannels = NodeFetchHandler & {\n /** Lifecycle control surface for the runtime's declared managed Channels. */\n channels: ChannelsControl;\n};\n\n/**\n * Convenience wrapper for creating a Node.js HTTP request listener\n * from CopilotKit runtime handler options.\n *\n * When the runtime declares managed Channels (and activation was not opted\n * out of via `activateChannels: false`), the returned listener exposes\n * `.channels` — the same {@link ChannelsControl} surface carried by the\n * underlying fetch handler.\n *\n * ## Managed Channels lifecycle\n *\n * Creating the listener STARTS activation — which opens the persistent Realtime\n * Gateway WebSocket and starts every direct adapter on the declared Channels.\n * Node owns its own process lifetime, so there is nothing to defer to and no\n * required incantation: a declared Channel connects because it was declared.\n * (The generic `createCopilotRuntimeHandler` is the opposite — it stays lazy for\n * serverless/edge safety; see its TSDoc.)\n *\n * `await listener.channels.ready()` is therefore OPTIONAL and purely\n * await-and-observe: it resolves once every declared Channel has settled to\n * `online`/`setup_required` and rejects with the activation failure, observing\n * the activation started at creation rather than triggering a second one. Await\n * it when startup should block on Channels being live (or should exit non-zero\n * when they are not); skip it and activation failures land in the logs instead.\n * `listener.channels.stop()` tears activation down.\n *\n * Pass `activateChannels: false` to build no control surface and open no socket\n * — the clean opt-out for a test or a short-lived script that mounts the\n * listener without wanting its Channels connected.\n *\n * @example\n * ```typescript\n * import { createServer } from \"node:http\";\n * import { CopilotRuntime } from \"@copilotkit/runtime/v2\";\n * import { createCopilotNodeListener } from \"@copilotkit/runtime/v2/node\";\n *\n * const listener = createCopilotNodeListener({\n * runtime: new CopilotRuntime({ agents: { ... } }),\n * basePath: \"/api/copilotkit\",\n * cors: true,\n * });\n * createServer(listener).listen(3000);\n * // Declared managed Channels are already connecting at this point.\n *\n * // Optional: block startup on them being live. Bound it so one wedged adapter\n * // cannot hang startup forever.\n * await listener.channels.ready({ timeoutMs: 30_000 });\n * ```\n */\n/**\n * Overload: a runtime constructed with at least one declared Intelligence\n * Channel (a {@link RuntimeWithDeclaredChannels}-branded runtime), when\n * activation is not disabled, yields a listener with a **non-optional**\n * {@link ChannelsControl}. `activateChannels` is constrained to\n * `true | undefined` here so passing `activateChannels: false` (which leaves no\n * `.channels`) falls through to the optional-shape overload below rather than\n * dishonestly promising a control surface that will not exist. Mirrors the\n * `createCopilotRuntimeHandler` overload pair so the brand survives the wrapper.\n *\n * The brand comes from constructing the runtime with a literal non-empty\n * `channels` list (`readonly [Channel, ...Channel[]]`). A runtime built from a\n * dynamically-assembled `Channel[]` is not branded, so it falls to the\n * optional-shape overload and its call sites still need `?.`.\n */\nexport function createCopilotNodeListener(\n options: CopilotRuntimeHandlerOptions & {\n runtime: RuntimeWithDeclaredChannels;\n activateChannels?: true | undefined;\n },\n): NodeCopilotListenerWithChannels;\n/**\n * Overload: every other runtime (SSE, Intelligence without channels, or with\n * activation disabled) yields a listener whose `.channels` is optional.\n */\nexport function createCopilotNodeListener(\n options: CopilotRuntimeHandlerOptions,\n): NodeCopilotListener;\nexport function createCopilotNodeListener(\n options: CopilotRuntimeHandlerOptions,\n): NodeCopilotListener {\n const handler = createCopilotRuntimeHandler(options);\n const listener: NodeCopilotListener = createCopilotNodeHandler(handler);\n listener.channels = handler.channels;\n autoStartChannels(listener.channels);\n return listener;\n}\n"],"mappings":";;;;;;AA8GA,SAAgB,0BACd,SACqB;CACrB,MAAM,UAAU,4BAA4B,QAAQ;CACpD,MAAM,WAAgC,yBAAyB,QAAQ;AACvE,UAAS,WAAW,QAAQ;AAC5B,mBAAkB,SAAS,SAAS;AACpC,QAAO"}
@@ -86,6 +86,7 @@ var CopilotKitIntelligence = class {
86
86
  #apiUrl;
87
87
  #runnerWsUrl;
88
88
  #clientWsUrl;
89
+ #channelsWsUrl;
89
90
  #apiKey;
90
91
  #enterpriseLearningEnabled;
91
92
  #threadCreatedListeners = /* @__PURE__ */ new Set();
@@ -99,6 +100,7 @@ var CopilotKitIntelligence = class {
99
100
  this.#apiUrl = (configuredApiUrl ?? MANAGED_INTELLIGENCE_API_URL).replace(/\/$/, "");
100
101
  this.#runnerWsUrl = deriveRunnerWsUrl(intelligenceWsUrl);
101
102
  this.#clientWsUrl = deriveClientWsUrl(intelligenceWsUrl);
103
+ this.#channelsWsUrl = deriveChannelsWsUrl(intelligenceWsUrl);
102
104
  this.#apiKey = config.apiKey;
103
105
  this.#enterpriseLearningEnabled = config.enableEnterpriseLearning ?? false;
104
106
  if (config.onThreadCreated) this.onThreadCreated(config.onThreadCreated);
@@ -169,6 +171,9 @@ var CopilotKitIntelligence = class {
169
171
  ɵgetClientWsUrl() {
170
172
  return this.#clientWsUrl;
171
173
  }
174
+ ɵgetChannelsWsUrl() {
175
+ return this.#channelsWsUrl;
176
+ }
172
177
  ɵgetRunnerAuthToken() {
173
178
  return this.#apiKey;
174
179
  }
@@ -421,7 +426,25 @@ var CopilotKitIntelligence = class {
421
426
  */
422
427
  async getThreadMessages(params) {
423
428
  const qs = new URLSearchParams({ userId: params.userId }).toString();
424
- return this.#request("GET", `/api/threads/${encodeURIComponent(params.threadId)}/messages?${qs}`);
429
+ return this.#request("GET", `/api/threads/${encodeURIComponent(params.threadId)}/messages?${qs}`, void 0, params.channelDeliveryId ? { "X-Cpki-Channel-Delivery-Id": params.channelDeliveryId } : void 0);
430
+ }
431
+ /** @internal Fetches one authorized managed Channel asset for history hydration. */
432
+ async ɵgetManagedChannelAsset(assetId) {
433
+ const path = `/api/channels/files/${encodeURIComponent(assetId)}`;
434
+ const response = await fetch(`${this.#apiUrl}${path}`, {
435
+ method: "GET",
436
+ headers: { Authorization: `Bearer ${this.#apiKey}` }
437
+ });
438
+ if (!response.ok) {
439
+ const text = await response.text().catch(() => "");
440
+ throw new PlatformRequestError(`Intelligence platform error ${response.status}: ${text || response.statusText}`, response.status);
441
+ }
442
+ const bytes = new Uint8Array(await response.arrayBuffer());
443
+ const mimeType = response.headers.get("content-type") ?? void 0;
444
+ return {
445
+ bytes,
446
+ ...mimeType ? { mimeType } : {}
447
+ };
425
448
  }
426
449
  /**
427
450
  * Fetch the persisted AG-UI event stream for a thread.
@@ -531,7 +554,7 @@ var CopilotKitIntelligence = class {
531
554
  agentId: params.agentId,
532
555
  ...params.lockKeyPrefix !== void 0 ? { lockKeyPrefix: params.lockKeyPrefix } : {},
533
556
  ...params.ttlSeconds !== void 0 ? { ttlSeconds: params.ttlSeconds } : {}
534
- });
557
+ }, params.channelDeliveryId ? { "X-Cpki-Channel-Delivery-Id": params.channelDeliveryId } : void 0);
535
558
  }
536
559
  async ɵcleanupThreadLock(params) {
537
560
  return this.#request("DELETE", `/api/threads/${encodeURIComponent(params.threadId)}/lock`, { runId: params.runId });
@@ -585,13 +608,21 @@ function normalizeIntelligenceWsUrl(wsUrl) {
585
608
  function deriveRunnerWsUrl(wsUrl) {
586
609
  if (wsUrl.endsWith("/runner")) return wsUrl;
587
610
  if (wsUrl.endsWith("/client")) return `${wsUrl.slice(0, -7)}/runner`;
611
+ if (wsUrl.endsWith("/channels")) return `${wsUrl.slice(0, -9)}/runner`;
588
612
  return `${wsUrl}/runner`;
589
613
  }
590
614
  function deriveClientWsUrl(wsUrl) {
591
615
  if (wsUrl.endsWith("/client")) return wsUrl;
592
616
  if (wsUrl.endsWith("/runner")) return `${wsUrl.slice(0, -7)}/client`;
617
+ if (wsUrl.endsWith("/channels")) return `${wsUrl.slice(0, -9)}/client`;
593
618
  return `${wsUrl}/client`;
594
619
  }
620
+ function deriveChannelsWsUrl(wsUrl) {
621
+ if (wsUrl.endsWith("/channels")) return wsUrl;
622
+ if (wsUrl.endsWith("/runner")) return `${wsUrl.slice(0, -7)}/channels`;
623
+ if (wsUrl.endsWith("/client")) return `${wsUrl.slice(0, -7)}/channels`;
624
+ return `${wsUrl}/channels`;
625
+ }
595
626
 
596
627
  //#endregion
597
628
  exports.CopilotKitIntelligence = CopilotKitIntelligence;