@copilotkit/runtime 1.63.2 → 1.64.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 (66) hide show
  1. package/dist/agent/index.cjs +19 -3
  2. package/dist/agent/index.cjs.map +1 -1
  3. package/dist/agent/index.d.cts +3 -1
  4. package/dist/agent/index.d.cts.map +1 -1
  5. package/dist/agent/index.d.mts +3 -1
  6. package/dist/agent/index.d.mts.map +1 -1
  7. package/dist/agent/index.mjs +19 -3
  8. package/dist/agent/index.mjs.map +1 -1
  9. package/dist/package.cjs +2 -2
  10. package/dist/runtime/package.mjs +2 -2
  11. package/dist/service-adapters/anthropic/anthropic-adapter.cjs +2 -2
  12. package/dist/service-adapters/anthropic/anthropic-adapter.cjs.map +1 -1
  13. package/dist/service-adapters/anthropic/anthropic-adapter.d.cts.map +1 -1
  14. package/dist/service-adapters/anthropic/anthropic-adapter.d.mts.map +1 -1
  15. package/dist/service-adapters/anthropic/anthropic-adapter.mjs +3 -3
  16. package/dist/service-adapters/anthropic/anthropic-adapter.mjs.map +1 -1
  17. package/dist/service-adapters/anthropic/utils.cjs +20 -0
  18. package/dist/service-adapters/anthropic/utils.cjs.map +1 -1
  19. package/dist/service-adapters/anthropic/utils.mjs +20 -1
  20. package/dist/service-adapters/anthropic/utils.mjs.map +1 -1
  21. package/dist/v2/node.d.cts +2 -2
  22. package/dist/v2/node.d.mts +2 -2
  23. package/dist/v2/runtime/core/channel-manager.cjs +125 -56
  24. package/dist/v2/runtime/core/channel-manager.cjs.map +1 -1
  25. package/dist/v2/runtime/core/channel-manager.d.cts +20 -9
  26. package/dist/v2/runtime/core/channel-manager.d.cts.map +1 -1
  27. package/dist/v2/runtime/core/channel-manager.d.mts +20 -9
  28. package/dist/v2/runtime/core/channel-manager.d.mts.map +1 -1
  29. package/dist/v2/runtime/core/channel-manager.mjs +125 -56
  30. package/dist/v2/runtime/core/channel-manager.mjs.map +1 -1
  31. package/dist/v2/runtime/endpoints/express.cjs.map +1 -1
  32. package/dist/v2/runtime/endpoints/express.d.cts +5 -4
  33. package/dist/v2/runtime/endpoints/express.d.cts.map +1 -1
  34. package/dist/v2/runtime/endpoints/express.d.mts +5 -4
  35. package/dist/v2/runtime/endpoints/express.d.mts.map +1 -1
  36. package/dist/v2/runtime/endpoints/express.mjs.map +1 -1
  37. package/dist/v2/runtime/endpoints/hono.cjs.map +1 -1
  38. package/dist/v2/runtime/endpoints/hono.d.cts +5 -4
  39. package/dist/v2/runtime/endpoints/hono.d.cts.map +1 -1
  40. package/dist/v2/runtime/endpoints/hono.d.mts +5 -4
  41. package/dist/v2/runtime/endpoints/hono.d.mts.map +1 -1
  42. package/dist/v2/runtime/endpoints/hono.mjs.map +1 -1
  43. package/dist/v2/runtime/endpoints/node.cjs +0 -26
  44. package/dist/v2/runtime/endpoints/node.cjs.map +1 -1
  45. package/dist/v2/runtime/endpoints/node.d.cts +54 -6
  46. package/dist/v2/runtime/endpoints/node.d.cts.map +1 -1
  47. package/dist/v2/runtime/endpoints/node.d.mts +54 -6
  48. package/dist/v2/runtime/endpoints/node.d.mts.map +1 -1
  49. package/dist/v2/runtime/endpoints/node.mjs +0 -26
  50. package/dist/v2/runtime/endpoints/node.mjs.map +1 -1
  51. package/dist/v2/runtime/intelligence-platform/client.cjs +73 -2
  52. package/dist/v2/runtime/intelligence-platform/client.cjs.map +1 -1
  53. package/dist/v2/runtime/intelligence-platform/client.d.cts +51 -25
  54. package/dist/v2/runtime/intelligence-platform/client.d.cts.map +1 -1
  55. package/dist/v2/runtime/intelligence-platform/client.d.mts +51 -25
  56. package/dist/v2/runtime/intelligence-platform/client.d.mts.map +1 -1
  57. package/dist/v2/runtime/intelligence-platform/client.mjs +73 -2
  58. package/dist/v2/runtime/intelligence-platform/client.mjs.map +1 -1
  59. package/dist/v2/runtime/node.d.cts +1 -1
  60. package/dist/v2/runtime/node.d.mts +1 -1
  61. package/dist/v2/runtime/open-generative-ui-middleware.cjs +4 -1
  62. package/dist/v2/runtime/open-generative-ui-middleware.cjs.map +1 -1
  63. package/dist/v2/runtime/open-generative-ui-middleware.mjs +4 -1
  64. package/dist/v2/runtime/open-generative-ui-middleware.mjs.map +1 -1
  65. package/package.json +7 -7
  66. package/skills/runtime/references/intelligence-mode.md +50 -17
@@ -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 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,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 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 +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 observe/stop managed Channel\n * 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 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/** @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":";;;;;;;AA+EA,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 * 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"}
@@ -11,8 +11,8 @@ import { Hono } from "hono";
11
11
  * Hono's app object is request-scoped routing config, not a long-running
12
12
  * process owner — Node (`createCopilotNodeListener`) is the lifecycle-owning
13
13
  * surface for `.channels`. It is attached here too, best-effort, for callers
14
- * that mount the Hono app directly and want to observe/stop managed Channel
15
- * activation without also standing up a Node listener.
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.
16
16
  */
17
17
  type CopilotHonoApp = Hono & {
18
18
  channels?: ChannelsControl;
@@ -56,8 +56,9 @@ interface CopilotEndpointParams {
56
56
  */
57
57
  hooks?: CopilotRuntimeHooks;
58
58
  /**
59
- * Whether the underlying handler activates the runtime's declared managed
60
- * Channels at creation time. Defaults to `true`. See
59
+ * Whether the underlying handler builds the control surface for the runtime's
60
+ * declared managed Channels. Defaults to `true`. Building it opens no
61
+ * connection — activation is deferred to the first `channels.ready()`. See
61
62
  * `CopilotRuntimeHandlerOptions.activateChannels`.
62
63
  */
63
64
  activateChannels?: boolean;
@@ -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;EAuBkB;;;AAGpB;EApBE,IAAA,GAAO,yBAAA;;;;EAIP,KAAA,GAAQ,mBAAA;EAkB8B;;;;;EAXtC,gBAAA;EAgBA;;;;EAVA,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":";;;;;;;;;;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"}
@@ -11,8 +11,8 @@ import { Hono } from "hono";
11
11
  * Hono's app object is request-scoped routing config, not a long-running
12
12
  * process owner — Node (`createCopilotNodeListener`) is the lifecycle-owning
13
13
  * surface for `.channels`. It is attached here too, best-effort, for callers
14
- * that mount the Hono app directly and want to observe/stop managed Channel
15
- * activation without also standing up a Node listener.
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.
16
16
  */
17
17
  type CopilotHonoApp = Hono & {
18
18
  channels?: ChannelsControl;
@@ -56,8 +56,9 @@ interface CopilotEndpointParams {
56
56
  */
57
57
  hooks?: CopilotRuntimeHooks;
58
58
  /**
59
- * Whether the underlying handler activates the runtime's declared managed
60
- * Channels at creation time. Defaults to `true`. See
59
+ * Whether the underlying handler builds the control surface for the runtime's
60
+ * declared managed Channels. Defaults to `true`. Building it opens no
61
+ * connection — activation is deferred to the first `channels.ready()`. See
61
62
  * `CopilotRuntimeHandlerOptions.activateChannels`.
62
63
  */
63
64
  activateChannels?: boolean;
@@ -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;EAuBkB;;;AAGpB;EApBE,IAAA,GAAO,yBAAA;;;;EAIP,KAAA,GAAQ,mBAAA;EAkB8B;;;;;EAXtC,gBAAA;EAgBA;;;;EAVA,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":";;;;;;;;;;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 +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 observe/stop managed Channel\n * 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 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/** @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":";;;;;;AA+EA,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 * 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"}
@@ -3,32 +3,6 @@ const require_fetch_handler = require('../core/fetch-handler.cjs');
3
3
  const require_node_fetch_handler = require('./node-fetch-handler.cjs');
4
4
 
5
5
  //#region src/v2/runtime/endpoints/node.ts
6
- /**
7
- * Convenience wrapper for creating a Node.js HTTP request listener
8
- * from CopilotKit runtime handler options.
9
- *
10
- * When the runtime declares managed Channels (and activation was not opted
11
- * out of via `activateChannels: false`), the returned listener exposes
12
- * `.channels` — the same {@link ChannelsControl} surface the underlying
13
- * fetch handler activates at creation time.
14
- *
15
- * @example
16
- * ```typescript
17
- * import { createServer } from "node:http";
18
- * import { CopilotRuntime } from "@copilotkit/runtime/v2";
19
- * import { createCopilotNodeListener } from "@copilotkit/runtime/v2/node";
20
- *
21
- * const listener = createCopilotNodeListener({
22
- * runtime: new CopilotRuntime({ agents: { ... } }),
23
- * basePath: "/api/copilotkit",
24
- * cors: true,
25
- * });
26
- * createServer(listener).listen(3000);
27
- *
28
- * // Optional: observe/stop managed Channel activation.
29
- * await listener.channels?.ready();
30
- * ```
31
- */
32
6
  function createCopilotNodeListener(options) {
33
7
  const handler = require_fetch_handler.createCopilotRuntimeHandler(options);
34
8
  const listener = require_node_fetch_handler.createCopilotNodeHandler(handler);
@@ -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 { 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 observe or stop managed\n * Channel activation.\n */\nexport type NodeCopilotListener = NodeFetchHandler & {\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 the underlying\n * fetch handler activates at creation time.\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 * // Optional: observe/stop managed Channel activation.\n * await listener.channels?.ready();\n * ```\n */\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":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA4CA,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\";\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,4 +1,5 @@
1
1
  require("reflect-metadata");
2
+ import { RuntimeWithDeclaredChannels } from "../core/runtime.cjs";
2
3
  import { ChannelsControl } from "../core/channel-manager.cjs";
3
4
  import { CopilotRuntimeHandlerOptions } from "../core/fetch-handler.cjs";
4
5
  import { NodeFetchHandler } from "./node-fetch-handler.cjs";
@@ -9,20 +10,43 @@ import { NodeFetchHandler } from "./node-fetch-handler.cjs";
9
10
  * optional {@link ChannelsControl} surface, mirroring
10
11
  * `CopilotRuntimeFetchHandler.channels`. Node is the long-running,
11
12
  * lifecycle-owning entry point for the runtime, so it is the surface that
12
- * exposes `.channels` for callers that need to observe or stop managed
13
+ * exposes `.channels` for callers that need to start, observe, or stop managed
13
14
  * Channel activation.
14
15
  */
15
16
  type NodeCopilotListener = NodeFetchHandler & {
16
17
  channels?: ChannelsControl;
17
18
  };
19
+ /**
20
+ * A {@link NodeCopilotListener} whose {@link ChannelsControl} surface is
21
+ * guaranteed present. Returned when the runtime was constructed with at least
22
+ * one declared Intelligence Channel and activation was not opted out of, so the
23
+ * documented `listener.channels.ready(...)` call type-checks without a `!` or a
24
+ * `?.` under strict TypeScript — the Node mirror of
25
+ * `CopilotRuntimeFetchHandlerWithChannels`.
26
+ */
27
+ type NodeCopilotListenerWithChannels = NodeFetchHandler & {
28
+ /** Lifecycle control surface for the runtime's declared managed Channels. */channels: ChannelsControl;
29
+ };
18
30
  /**
19
31
  * Convenience wrapper for creating a Node.js HTTP request listener
20
32
  * from CopilotKit runtime handler options.
21
33
  *
22
34
  * When the runtime declares managed Channels (and activation was not opted
23
35
  * out of via `activateChannels: false`), the returned listener exposes
24
- * `.channels` — the same {@link ChannelsControl} surface the underlying
25
- * fetch handler activates at creation time.
36
+ * `.channels` — the same {@link ChannelsControl} surface carried by the
37
+ * underlying fetch handler.
38
+ *
39
+ * ## Managed Channels lifecycle
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).
26
50
  *
27
51
  * @example
28
52
  * ```typescript
@@ -37,11 +61,35 @@ type NodeCopilotListener = NodeFetchHandler & {
37
61
  * });
38
62
  * createServer(listener).listen(3000);
39
63
  *
40
- * // Optional: observe/stop managed Channel activation.
41
- * await listener.channels?.ready();
64
+ * // Required to connect declared managed Channels. Bound it so one wedged
65
+ * // adapter cannot hang startup forever.
66
+ * await listener.channels.ready({ timeoutMs: 30_000 });
42
67
  * ```
43
68
  */
69
+ /**
70
+ * Overload: a runtime constructed with at least one declared Intelligence
71
+ * Channel (a {@link RuntimeWithDeclaredChannels}-branded runtime), when
72
+ * activation is not disabled, yields a listener with a **non-optional**
73
+ * {@link ChannelsControl}. `activateChannels` is constrained to
74
+ * `true | undefined` here so passing `activateChannels: false` (which leaves no
75
+ * `.channels`) falls through to the optional-shape overload below rather than
76
+ * dishonestly promising a control surface that will not exist. Mirrors the
77
+ * `createCopilotRuntimeHandler` overload pair so the brand survives the wrapper.
78
+ *
79
+ * The brand comes from constructing the runtime with a literal non-empty
80
+ * `channels` list (`readonly [Channel, ...Channel[]]`). A runtime built from a
81
+ * dynamically-assembled `Channel[]` is not branded, so it falls to the
82
+ * optional-shape overload and its call sites still need `?.`.
83
+ */
84
+ declare function createCopilotNodeListener(options: CopilotRuntimeHandlerOptions & {
85
+ runtime: RuntimeWithDeclaredChannels;
86
+ activateChannels?: true | undefined;
87
+ }): NodeCopilotListenerWithChannels;
88
+ /**
89
+ * Overload: every other runtime (SSE, Intelligence without channels, or with
90
+ * activation disabled) yields a listener whose `.channels` is optional.
91
+ */
44
92
  declare function createCopilotNodeListener(options: CopilotRuntimeHandlerOptions): NodeCopilotListener;
45
93
  //#endregion
46
- export { createCopilotNodeListener };
94
+ export { NodeCopilotListener, NodeCopilotListenerWithChannels, createCopilotNodeListener };
47
95
  //# sourceMappingURL=node.d.cts.map
@@ -1 +1 @@
1
- {"version":3,"file":"node.d.cts","names":[],"sources":["../../../../src/v2/runtime/endpoints/node.ts"],"mappings":";;;;;;;;AAcA;;;;;;KAAY,mBAAA,GAAsB,gBAAA;EAChC,QAAA,GAAW,eAAA;AAAA;AA6Bb;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,iBAAgB,yBAAA,CACd,OAAA,EAAS,4BAAA,GACR,mBAAA"}
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,4 +1,5 @@
1
1
  import "reflect-metadata";
2
+ import { RuntimeWithDeclaredChannels } from "../core/runtime.mjs";
2
3
  import { ChannelsControl } from "../core/channel-manager.mjs";
3
4
  import { CopilotRuntimeHandlerOptions } from "../core/fetch-handler.mjs";
4
5
  import { NodeFetchHandler } from "./node-fetch-handler.mjs";
@@ -9,20 +10,43 @@ import { NodeFetchHandler } from "./node-fetch-handler.mjs";
9
10
  * optional {@link ChannelsControl} surface, mirroring
10
11
  * `CopilotRuntimeFetchHandler.channels`. Node is the long-running,
11
12
  * lifecycle-owning entry point for the runtime, so it is the surface that
12
- * exposes `.channels` for callers that need to observe or stop managed
13
+ * exposes `.channels` for callers that need to start, observe, or stop managed
13
14
  * Channel activation.
14
15
  */
15
16
  type NodeCopilotListener = NodeFetchHandler & {
16
17
  channels?: ChannelsControl;
17
18
  };
19
+ /**
20
+ * A {@link NodeCopilotListener} whose {@link ChannelsControl} surface is
21
+ * guaranteed present. Returned when the runtime was constructed with at least
22
+ * one declared Intelligence Channel and activation was not opted out of, so the
23
+ * documented `listener.channels.ready(...)` call type-checks without a `!` or a
24
+ * `?.` under strict TypeScript — the Node mirror of
25
+ * `CopilotRuntimeFetchHandlerWithChannels`.
26
+ */
27
+ type NodeCopilotListenerWithChannels = NodeFetchHandler & {
28
+ /** Lifecycle control surface for the runtime's declared managed Channels. */channels: ChannelsControl;
29
+ };
18
30
  /**
19
31
  * Convenience wrapper for creating a Node.js HTTP request listener
20
32
  * from CopilotKit runtime handler options.
21
33
  *
22
34
  * When the runtime declares managed Channels (and activation was not opted
23
35
  * out of via `activateChannels: false`), the returned listener exposes
24
- * `.channels` — the same {@link ChannelsControl} surface the underlying
25
- * fetch handler activates at creation time.
36
+ * `.channels` — the same {@link ChannelsControl} surface carried by the
37
+ * underlying fetch handler.
38
+ *
39
+ * ## Managed Channels lifecycle
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).
26
50
  *
27
51
  * @example
28
52
  * ```typescript
@@ -37,11 +61,35 @@ type NodeCopilotListener = NodeFetchHandler & {
37
61
  * });
38
62
  * createServer(listener).listen(3000);
39
63
  *
40
- * // Optional: observe/stop managed Channel activation.
41
- * await listener.channels?.ready();
64
+ * // Required to connect declared managed Channels. Bound it so one wedged
65
+ * // adapter cannot hang startup forever.
66
+ * await listener.channels.ready({ timeoutMs: 30_000 });
42
67
  * ```
43
68
  */
69
+ /**
70
+ * Overload: a runtime constructed with at least one declared Intelligence
71
+ * Channel (a {@link RuntimeWithDeclaredChannels}-branded runtime), when
72
+ * activation is not disabled, yields a listener with a **non-optional**
73
+ * {@link ChannelsControl}. `activateChannels` is constrained to
74
+ * `true | undefined` here so passing `activateChannels: false` (which leaves no
75
+ * `.channels`) falls through to the optional-shape overload below rather than
76
+ * dishonestly promising a control surface that will not exist. Mirrors the
77
+ * `createCopilotRuntimeHandler` overload pair so the brand survives the wrapper.
78
+ *
79
+ * The brand comes from constructing the runtime with a literal non-empty
80
+ * `channels` list (`readonly [Channel, ...Channel[]]`). A runtime built from a
81
+ * dynamically-assembled `Channel[]` is not branded, so it falls to the
82
+ * optional-shape overload and its call sites still need `?.`.
83
+ */
84
+ declare function createCopilotNodeListener(options: CopilotRuntimeHandlerOptions & {
85
+ runtime: RuntimeWithDeclaredChannels;
86
+ activateChannels?: true | undefined;
87
+ }): NodeCopilotListenerWithChannels;
88
+ /**
89
+ * Overload: every other runtime (SSE, Intelligence without channels, or with
90
+ * activation disabled) yields a listener whose `.channels` is optional.
91
+ */
44
92
  declare function createCopilotNodeListener(options: CopilotRuntimeHandlerOptions): NodeCopilotListener;
45
93
  //#endregion
46
- export { createCopilotNodeListener };
94
+ export { NodeCopilotListener, NodeCopilotListenerWithChannels, createCopilotNodeListener };
47
95
  //# sourceMappingURL=node.d.mts.map
@@ -1 +1 @@
1
- {"version":3,"file":"node.d.mts","names":[],"sources":["../../../../src/v2/runtime/endpoints/node.ts"],"mappings":";;;;;;;;AAcA;;;;;;KAAY,mBAAA,GAAsB,gBAAA;EAChC,QAAA,GAAW,eAAA;AAAA;AA6Bb;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,iBAAgB,yBAAA,CACd,OAAA,EAAS,4BAAA,GACR,mBAAA"}
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"}
@@ -3,32 +3,6 @@ import { createCopilotRuntimeHandler } from "../core/fetch-handler.mjs";
3
3
  import { createCopilotNodeHandler } from "./node-fetch-handler.mjs";
4
4
 
5
5
  //#region src/v2/runtime/endpoints/node.ts
6
- /**
7
- * Convenience wrapper for creating a Node.js HTTP request listener
8
- * from CopilotKit runtime handler options.
9
- *
10
- * When the runtime declares managed Channels (and activation was not opted
11
- * out of via `activateChannels: false`), the returned listener exposes
12
- * `.channels` — the same {@link ChannelsControl} surface the underlying
13
- * fetch handler activates at creation time.
14
- *
15
- * @example
16
- * ```typescript
17
- * import { createServer } from "node:http";
18
- * import { CopilotRuntime } from "@copilotkit/runtime/v2";
19
- * import { createCopilotNodeListener } from "@copilotkit/runtime/v2/node";
20
- *
21
- * const listener = createCopilotNodeListener({
22
- * runtime: new CopilotRuntime({ agents: { ... } }),
23
- * basePath: "/api/copilotkit",
24
- * cors: true,
25
- * });
26
- * createServer(listener).listen(3000);
27
- *
28
- * // Optional: observe/stop managed Channel activation.
29
- * await listener.channels?.ready();
30
- * ```
31
- */
32
6
  function createCopilotNodeListener(options) {
33
7
  const handler = createCopilotRuntimeHandler(options);
34
8
  const listener = createCopilotNodeHandler(handler);
@@ -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 { 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 observe or stop managed\n * Channel activation.\n */\nexport type NodeCopilotListener = NodeFetchHandler & {\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 the underlying\n * fetch handler activates at creation time.\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 * // Optional: observe/stop managed Channel activation.\n * await listener.channels?.ready();\n * ```\n */\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":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA4CA,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\";\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"}
@@ -16,6 +16,19 @@ let crypto = require("crypto");
16
16
  */
17
17
  const INTELLIGENCE_USER_ID_HEADER = "x-cpki-user-id";
18
18
  /**
19
+ * REST base URL of CopilotKit's managed Intelligence platform — the default
20
+ * when {@link CopilotKitIntelligenceConfig.apiUrl} is omitted.
21
+ */
22
+ const MANAGED_INTELLIGENCE_API_URL = "https://api.intelligence.copilotkit.ai";
23
+ /**
24
+ * Websocket base URL of CopilotKit's managed Intelligence platform — the
25
+ * default when {@link CopilotKitIntelligenceConfig.wsUrl} is omitted.
26
+ *
27
+ * A different host from {@link MANAGED_INTELLIGENCE_API_URL}: the API and
28
+ * realtime planes are deployed separately.
29
+ */
30
+ const MANAGED_INTELLIGENCE_WS_URL = "wss://realtime.intelligence.copilotkit.ai";
31
+ /**
19
32
  * Error thrown when an Intelligence platform HTTP request returns a non-2xx
20
33
  * status. Carries the HTTP {@link status} code so callers can branch on
21
34
  * specific failures (e.g. 404 for "not found", 409 for "conflict") without
@@ -39,6 +52,36 @@ var PlatformRequestError = class extends Error {
39
52
  this.name = "PlatformRequestError";
40
53
  }
41
54
  };
55
+ /**
56
+ * Client for the CopilotKit Intelligence Platform REST API.
57
+ *
58
+ * Construct the client once and pass it to any consumers that need it
59
+ * (e.g. `CopilotRuntime`, `IntelligenceAgentRunner`):
60
+ *
61
+ * ```ts
62
+ * import { CopilotKitIntelligence, CopilotRuntime } from "@copilotkit/runtime";
63
+ *
64
+ * const intelligence = new CopilotKitIntelligence({
65
+ * apiKey: process.env.COPILOTKIT_API_KEY!,
66
+ * });
67
+ *
68
+ * const runtime = new CopilotRuntime({
69
+ * agents,
70
+ * intelligence,
71
+ * });
72
+ * ```
73
+ *
74
+ * `apiUrl` and `wsUrl` default to CopilotKit's managed Intelligence platform.
75
+ * Override both together to target a self-hosted or non-production deployment:
76
+ *
77
+ * ```ts
78
+ * const intelligence = new CopilotKitIntelligence({
79
+ * apiUrl: "https://intelligence.internal",
80
+ * wsUrl: "wss://realtime.intelligence.internal",
81
+ * apiKey: process.env.COPILOTKIT_API_KEY!,
82
+ * });
83
+ * ```
84
+ */
42
85
  var CopilotKitIntelligence = class {
43
86
  #apiUrl;
44
87
  #runnerWsUrl;
@@ -49,8 +92,11 @@ var CopilotKitIntelligence = class {
49
92
  #threadUpdatedListeners = /* @__PURE__ */ new Set();
50
93
  #threadDeletedListeners = /* @__PURE__ */ new Set();
51
94
  constructor(config) {
52
- const intelligenceWsUrl = normalizeIntelligenceWsUrl(config.wsUrl);
53
- this.#apiUrl = config.apiUrl.replace(/\/$/, "");
95
+ const configuredApiUrl = configuredUrl(config.apiUrl);
96
+ const configuredWsUrl = configuredUrl(config.wsUrl);
97
+ warnOnPartialHostOverride(configuredApiUrl, configuredWsUrl);
98
+ const intelligenceWsUrl = normalizeIntelligenceWsUrl(configuredWsUrl ?? MANAGED_INTELLIGENCE_WS_URL);
99
+ this.#apiUrl = (configuredApiUrl ?? MANAGED_INTELLIGENCE_API_URL).replace(/\/$/, "");
54
100
  this.#runnerWsUrl = deriveRunnerWsUrl(intelligenceWsUrl);
55
101
  this.#clientWsUrl = deriveClientWsUrl(intelligenceWsUrl);
56
102
  this.#apiKey = config.apiKey;
@@ -492,6 +538,31 @@ var CopilotKitIntelligence = class {
492
538
  }) ?? null;
493
539
  }
494
540
  };
541
+ /**
542
+ * Normalize a configured URL to "provided" or "not provided". A blank string
543
+ * counts as not provided: these URLs are typically wired from environment
544
+ * variables, and a declared-but-empty variable (`COPILOTKIT_INTELLIGENCE_URL=`,
545
+ * common in generated `.env` files and container configs) arrives as `""`. Left
546
+ * as-is it would produce host-relative requests instead of falling back to the
547
+ * managed platform.
548
+ */
549
+ function configuredUrl(url) {
550
+ const trimmed = url?.trim();
551
+ return trimmed ? trimmed : void 0;
552
+ }
553
+ /**
554
+ * Warn when exactly one of `apiUrl`/`wsUrl` is configured. The API and realtime
555
+ * planes are separate hosts, so a lone override silently leaves the other plane
556
+ * on CopilotKit's managed platform — a self-hosted API paired with the managed
557
+ * gateway (or vice versa), which fails as a hang rather than an error.
558
+ */
559
+ function warnOnPartialHostOverride(apiUrl, wsUrl) {
560
+ if (apiUrl && !wsUrl) {
561
+ _copilotkit_shared.logger.warn(`CopilotKitIntelligence: apiUrl is set to "${apiUrl}" but wsUrl is not, so wsUrl falls back to the managed default "${MANAGED_INTELLIGENCE_WS_URL}". The API and realtime planes are separate hosts — set both when pointing at a self-hosted deployment.`);
562
+ return;
563
+ }
564
+ if (wsUrl && !apiUrl) _copilotkit_shared.logger.warn(`CopilotKitIntelligence: wsUrl is set to "${wsUrl}" but apiUrl is not, so apiUrl falls back to the managed default "${MANAGED_INTELLIGENCE_API_URL}". The API and realtime planes are separate hosts — set both when pointing at a self-hosted deployment.`);
565
+ }
495
566
  function normalizeIntelligenceWsUrl(wsUrl) {
496
567
  return wsUrl.replace(/\/$/, "");
497
568
  }