@copilotkit/runtime 1.62.3 → 1.63.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (162) hide show
  1. package/dist/_virtual/_rolldown/runtime.mjs +15 -1
  2. package/dist/agent/converters/aisdk.d.cts +1 -1
  3. package/dist/agent/converters/tanstack.d.cts +1 -1
  4. package/dist/agent/index.d.cts +1 -1
  5. package/dist/channels/dist/index.d.cts +10 -0
  6. package/dist/channels/dist/index.d.cts.map +1 -0
  7. package/dist/channels/dist/index.d.mts +10 -0
  8. package/dist/channels/dist/index.d.mts.map +1 -0
  9. package/dist/graphql/inputs/action.input.d.cts +1 -1
  10. package/dist/graphql/inputs/agent-session.input.d.cts +1 -1
  11. package/dist/graphql/inputs/agent-state.input.d.cts +1 -1
  12. package/dist/graphql/inputs/extensions.input.d.cts +1 -1
  13. package/dist/graphql/inputs/forwarded-parameters.input.d.cts +1 -1
  14. package/dist/graphql/inputs/message.input.d.cts +1 -1
  15. package/dist/graphql/types/base/index.d.cts +1 -1
  16. package/dist/graphql/types/converted/index.d.cts +1 -1
  17. package/dist/graphql/types/copilot-response.type.d.cts +1 -1
  18. package/dist/graphql/types/enums.d.cts +1 -1
  19. package/dist/graphql/types/extensions-response.type.d.cts +1 -1
  20. package/dist/graphql/types/message-status.type.d.cts +1 -1
  21. package/dist/graphql/types/response-status.type.d.cts +1 -1
  22. package/dist/index.d.cts +1 -1
  23. package/dist/langgraph.d.cts +1 -1
  24. package/dist/lib/cloud/index.d.cts +1 -1
  25. package/dist/lib/index.d.cts +1 -1
  26. package/dist/lib/integrations/index.d.cts +1 -1
  27. package/dist/lib/integrations/nest/index.d.cts +1 -1
  28. package/dist/lib/integrations/nextjs/app-router.d.cts +1 -1
  29. package/dist/lib/integrations/nextjs/pages-router.d.cts +1 -1
  30. package/dist/lib/integrations/node-express/index.d.cts +1 -1
  31. package/dist/lib/integrations/node-http/index.d.cts +1 -1
  32. package/dist/lib/integrations/shared.d.cts +1 -1
  33. package/dist/lib/logger.d.cts +1 -1
  34. package/dist/lib/observability.d.cts +1 -1
  35. package/dist/lib/runtime/agent-integrations/langgraph/agent.d.cts +1 -1
  36. package/dist/lib/runtime/agent-integrations/langgraph/consts.d.cts +1 -1
  37. package/dist/lib/runtime/agent-integrations/langgraph/index.d.cts +1 -1
  38. package/dist/lib/runtime/copilot-runtime.d.cts +1 -1
  39. package/dist/lib/runtime/mcp-tools-utils.d.cts +1 -1
  40. package/dist/lib/runtime/telemetry-agent-runner.d.cts +1 -1
  41. package/dist/lib/runtime/types.d.cts +1 -1
  42. package/dist/lib/telemetry-client.mjs +1 -1
  43. package/dist/package.cjs +4 -1
  44. package/dist/{package.mjs → runtime/package.mjs} +5 -2
  45. package/dist/runtime/package.mjs.map +1 -0
  46. package/dist/service-adapters/anthropic/anthropic-adapter.d.cts +1 -1
  47. package/dist/service-adapters/bedrock/bedrock-adapter.d.cts +1 -1
  48. package/dist/service-adapters/empty/empty-adapter.d.cts +1 -1
  49. package/dist/service-adapters/events.d.cts +1 -1
  50. package/dist/service-adapters/experimental/ollama/ollama-adapter.d.cts +1 -1
  51. package/dist/service-adapters/google/google-genai-adapter.d.cts +1 -1
  52. package/dist/service-adapters/groq/groq-adapter.d.cts +1 -1
  53. package/dist/service-adapters/index.d.cts +1 -1
  54. package/dist/service-adapters/langchain/langchain-adapter.d.cts +1 -1
  55. package/dist/service-adapters/langchain/langserve.d.cts +1 -1
  56. package/dist/service-adapters/langchain/types.d.cts +1 -1
  57. package/dist/service-adapters/openai/openai-adapter.d.cts +1 -1
  58. package/dist/service-adapters/openai/openai-assistant-adapter.d.cts +1 -1
  59. package/dist/service-adapters/service-adapter.d.cts +1 -1
  60. package/dist/service-adapters/shared/error-utils.d.cts +1 -1
  61. package/dist/service-adapters/shared/sdk-client-utils.d.cts +1 -1
  62. package/dist/service-adapters/unify/unify-adapter.d.cts +1 -1
  63. package/dist/utils/failed-response-status-reasons.d.cts +1 -1
  64. package/dist/v2/express.d.cts +3 -3
  65. package/dist/v2/express.d.mts +2 -2
  66. package/dist/v2/hono.d.cts +3 -3
  67. package/dist/v2/hono.d.mts +2 -2
  68. package/dist/v2/index.d.cts +7 -6
  69. package/dist/v2/index.d.mts +6 -5
  70. package/dist/v2/node.d.cts +1 -1
  71. package/dist/v2/runtime/core/channel-activation-config.cjs +93 -0
  72. package/dist/v2/runtime/core/channel-activation-config.cjs.map +1 -0
  73. package/dist/v2/runtime/core/channel-activation-config.d.cts +34 -0
  74. package/dist/v2/runtime/core/channel-activation-config.d.cts.map +1 -0
  75. package/dist/v2/runtime/core/channel-activation-config.d.mts +34 -0
  76. package/dist/v2/runtime/core/channel-activation-config.d.mts.map +1 -0
  77. package/dist/v2/runtime/core/channel-activation-config.mjs +91 -0
  78. package/dist/v2/runtime/core/channel-activation-config.mjs.map +1 -0
  79. package/dist/v2/runtime/core/channel-manager.cjs +447 -0
  80. package/dist/v2/runtime/core/channel-manager.cjs.map +1 -0
  81. package/dist/v2/runtime/core/channel-manager.d.cts +90 -0
  82. package/dist/v2/runtime/core/channel-manager.d.cts.map +1 -0
  83. package/dist/v2/runtime/core/channel-manager.d.mts +90 -0
  84. package/dist/v2/runtime/core/channel-manager.d.mts.map +1 -0
  85. package/dist/v2/runtime/core/channel-manager.mjs +446 -0
  86. package/dist/v2/runtime/core/channel-manager.mjs.map +1 -0
  87. package/dist/v2/runtime/core/debug-event-bus.d.cts +1 -1
  88. package/dist/v2/runtime/core/fetch-cors.d.cts +1 -1
  89. package/dist/v2/runtime/core/fetch-handler.cjs +47 -1
  90. package/dist/v2/runtime/core/fetch-handler.cjs.map +1 -1
  91. package/dist/v2/runtime/core/fetch-handler.d.cts +60 -4
  92. package/dist/v2/runtime/core/fetch-handler.d.cts.map +1 -1
  93. package/dist/v2/runtime/core/fetch-handler.d.mts +59 -3
  94. package/dist/v2/runtime/core/fetch-handler.d.mts.map +1 -1
  95. package/dist/v2/runtime/core/fetch-handler.mjs +47 -1
  96. package/dist/v2/runtime/core/fetch-handler.mjs.map +1 -1
  97. package/dist/v2/runtime/core/hooks.d.cts +1 -1
  98. package/dist/v2/runtime/core/middleware-sse-parser.d.cts +1 -1
  99. package/dist/v2/runtime/core/middleware.d.cts +1 -1
  100. package/dist/v2/runtime/core/runtime.cjs +24 -1
  101. package/dist/v2/runtime/core/runtime.cjs.map +1 -1
  102. package/dist/v2/runtime/core/runtime.d.cts +75 -27
  103. package/dist/v2/runtime/core/runtime.d.cts.map +1 -1
  104. package/dist/v2/runtime/core/runtime.d.mts +74 -26
  105. package/dist/v2/runtime/core/runtime.d.mts.map +1 -1
  106. package/dist/v2/runtime/core/runtime.mjs +25 -2
  107. package/dist/v2/runtime/core/runtime.mjs.map +1 -1
  108. package/dist/v2/runtime/endpoints/express-single.d.cts +1 -1
  109. package/dist/v2/runtime/endpoints/express.cjs +10 -5
  110. package/dist/v2/runtime/endpoints/express.cjs.map +1 -1
  111. package/dist/v2/runtime/endpoints/express.d.cts +30 -4
  112. package/dist/v2/runtime/endpoints/express.d.cts.map +1 -1
  113. package/dist/v2/runtime/endpoints/express.d.mts +29 -3
  114. package/dist/v2/runtime/endpoints/express.d.mts.map +1 -1
  115. package/dist/v2/runtime/endpoints/express.mjs +10 -5
  116. package/dist/v2/runtime/endpoints/express.mjs.map +1 -1
  117. package/dist/v2/runtime/endpoints/hono-single.d.cts +1 -1
  118. package/dist/v2/runtime/endpoints/hono.cjs +7 -3
  119. package/dist/v2/runtime/endpoints/hono.cjs.map +1 -1
  120. package/dist/v2/runtime/endpoints/hono.d.cts +30 -16
  121. package/dist/v2/runtime/endpoints/hono.d.cts.map +1 -1
  122. package/dist/v2/runtime/endpoints/hono.d.mts +29 -15
  123. package/dist/v2/runtime/endpoints/hono.d.mts.map +1 -1
  124. package/dist/v2/runtime/endpoints/hono.mjs +7 -3
  125. package/dist/v2/runtime/endpoints/hono.mjs.map +1 -1
  126. package/dist/v2/runtime/endpoints/index.d.cts +3 -3
  127. package/dist/v2/runtime/endpoints/index.d.mts +2 -2
  128. package/dist/v2/runtime/endpoints/node-fetch-handler.d.cts +1 -1
  129. package/dist/v2/runtime/endpoints/node.cjs +12 -1
  130. package/dist/v2/runtime/endpoints/node.cjs.map +1 -1
  131. package/dist/v2/runtime/endpoints/node.d.cts +22 -2
  132. package/dist/v2/runtime/endpoints/node.d.cts.map +1 -1
  133. package/dist/v2/runtime/endpoints/node.d.mts +21 -1
  134. package/dist/v2/runtime/endpoints/node.d.mts.map +1 -1
  135. package/dist/v2/runtime/endpoints/node.mjs +12 -1
  136. package/dist/v2/runtime/endpoints/node.mjs.map +1 -1
  137. package/dist/v2/runtime/express.d.cts +2 -2
  138. package/dist/v2/runtime/express.d.mts +1 -1
  139. package/dist/v2/runtime/handlers/header-utils.d.cts +1 -1
  140. package/dist/v2/runtime/hono.d.cts +2 -2
  141. package/dist/v2/runtime/hono.d.mts +1 -1
  142. package/dist/v2/runtime/index.d.cts +6 -5
  143. package/dist/v2/runtime/index.d.cts.map +1 -1
  144. package/dist/v2/runtime/index.d.mts +5 -4
  145. package/dist/v2/runtime/index.d.mts.map +1 -1
  146. package/dist/v2/runtime/intelligence-platform/client.d.cts +1 -1
  147. package/dist/v2/runtime/node.d.cts +1 -1
  148. package/dist/v2/runtime/runner/agent-runner.d.cts +1 -1
  149. package/dist/v2/runtime/runner/in-memory.cjs +35 -19
  150. package/dist/v2/runtime/runner/in-memory.cjs.map +1 -1
  151. package/dist/v2/runtime/runner/in-memory.d.cts +13 -1
  152. package/dist/v2/runtime/runner/in-memory.d.cts.map +1 -1
  153. package/dist/v2/runtime/runner/in-memory.d.mts +12 -0
  154. package/dist/v2/runtime/runner/in-memory.d.mts.map +1 -1
  155. package/dist/v2/runtime/runner/in-memory.mjs +35 -19
  156. package/dist/v2/runtime/runner/in-memory.mjs.map +1 -1
  157. package/dist/v2/runtime/runner/index.d.cts +1 -1
  158. package/dist/v2/runtime/runner/intelligence.d.cts +1 -1
  159. package/dist/v2/runtime/telemetry/telemetry-client.mjs +1 -1
  160. package/dist/v2/runtime/transcription-service/transcription-service.d.cts +1 -1
  161. package/package.json +5 -2
  162. package/dist/package.mjs.map +0 -1
@@ -5,15 +5,19 @@ import { Hono } from "hono";
5
5
  //#region src/v2/runtime/endpoints/hono.ts
6
6
  /** @deprecated Use `createCopilotHonoHandler` instead. */
7
7
  const createCopilotEndpoint = createCopilotHonoHandler;
8
- function createCopilotHonoHandler({ runtime, basePath, mode = "multi-route", cors: corsConfig, hooks }) {
8
+ function createCopilotHonoHandler({ runtime, basePath, mode = "multi-route", cors: corsConfig, hooks, activateChannels, __channelEngine }) {
9
9
  const handler = createCopilotRuntimeHandler({
10
10
  runtime,
11
11
  basePath,
12
12
  mode,
13
13
  cors: corsConfig ? toFetchCorsConfig(corsConfig) : true,
14
- hooks
14
+ hooks,
15
+ activateChannels,
16
+ __channelEngine
15
17
  });
16
- return new Hono().basePath(basePath).all("*", async (c) => handler(c.req.raw));
18
+ const scopedApp = new Hono().basePath(basePath).all("*", async (c) => handler(c.req.raw));
19
+ scopedApp.channels = handler.channels;
20
+ return scopedApp;
17
21
  }
18
22
  /**
19
23
  * Convert Hono-specific CORS config to the fetch handler's CopilotCorsConfig.
@@ -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\";\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/** @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}: CopilotEndpointParams) {\n const handler = createCopilotRuntimeHandler({\n runtime,\n basePath,\n mode,\n cors: corsConfig ? toFetchCorsConfig(corsConfig) : true,\n hooks,\n });\n\n const app = new Hono();\n\n return app.basePath(basePath).all(\"*\", async (c) => handler(c.req.raw));\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":";;;;;;AAoDA,MAAa,wBAAwB;AAErC,SAAgB,yBAAyB,EACvC,SACA,UACA,OAAO,eACP,MAAM,YACN,SACwB;CACxB,MAAM,UAAU,4BAA4B;EAC1C;EACA;EACA;EACA,MAAM,aAAa,kBAAkB,WAAW,GAAG;EACnD;EACD,CAAC;AAIF,QAFY,IAAI,MAAM,CAEX,SAAS,SAAS,CAAC,IAAI,KAAK,OAAO,MAAM,QAAQ,EAAE,IAAI,IAAI,CAAC;;;;;AAMzE,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 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,5 +1,5 @@
1
-
2
- import { CopilotEndpointCorsConfig, createCopilotEndpoint, createCopilotHonoHandler, toFetchCorsConfig } from "./hono.cjs";
1
+ require("reflect-metadata");
2
+ import { CopilotEndpointCorsConfig, CopilotHonoApp, createCopilotEndpoint, createCopilotHonoHandler, toFetchCorsConfig } from "./hono.cjs";
3
3
  import { createCopilotEndpointSingleRoute } from "./hono-single.cjs";
4
- import { CopilotExpressEndpointParams, createCopilotExpressHandler } from "./express.cjs";
4
+ import { CopilotExpressEndpointParams, CopilotExpressRouter, createCopilotExpressHandler } from "./express.cjs";
5
5
  import { createCopilotEndpointSingleRouteExpress } from "./express-single.cjs";
@@ -1,5 +1,5 @@
1
1
  import "reflect-metadata";
2
- import { CopilotEndpointCorsConfig, createCopilotEndpoint, createCopilotHonoHandler, toFetchCorsConfig } from "./hono.mjs";
2
+ import { CopilotEndpointCorsConfig, CopilotHonoApp, createCopilotEndpoint, createCopilotHonoHandler, toFetchCorsConfig } from "./hono.mjs";
3
3
  import { createCopilotEndpointSingleRoute } from "./hono-single.mjs";
4
- import { CopilotExpressEndpointParams, createCopilotExpressHandler } from "./express.mjs";
4
+ import { CopilotExpressEndpointParams, CopilotExpressRouter, createCopilotExpressHandler } from "./express.mjs";
5
5
  import { createCopilotEndpointSingleRouteExpress } from "./express-single.mjs";
@@ -1,4 +1,4 @@
1
-
1
+ require("reflect-metadata");
2
2
  import { CopilotRuntimeFetchHandler } from "../core/fetch-handler.cjs";
3
3
  import { IncomingMessage, ServerResponse } from "node:http";
4
4
 
@@ -7,6 +7,11 @@ const require_node_fetch_handler = require('./node-fetch-handler.cjs');
7
7
  * Convenience wrapper for creating a Node.js HTTP request listener
8
8
  * from CopilotKit runtime handler options.
9
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
+ *
10
15
  * @example
11
16
  * ```typescript
12
17
  * import { createServer } from "node:http";
@@ -19,10 +24,16 @@ const require_node_fetch_handler = require('./node-fetch-handler.cjs');
19
24
  * cors: true,
20
25
  * });
21
26
  * createServer(listener).listen(3000);
27
+ *
28
+ * // Optional: observe/stop managed Channel activation.
29
+ * await listener.channels?.ready();
22
30
  * ```
23
31
  */
24
32
  function createCopilotNodeListener(options) {
25
- return require_node_fetch_handler.createCopilotNodeHandler(require_fetch_handler.createCopilotRuntimeHandler(options));
33
+ const handler = require_fetch_handler.createCopilotRuntimeHandler(options);
34
+ const listener = require_node_fetch_handler.createCopilotNodeHandler(handler);
35
+ listener.channels = handler.channels;
36
+ return listener;
26
37
  }
27
38
 
28
39
  //#endregion
@@ -1 +1 @@
1
- {"version":3,"file":"node.cjs","names":["createCopilotNodeHandler","createCopilotRuntimeHandler"],"sources":["../../../../src/v2/runtime/endpoints/node.ts"],"sourcesContent":["import { createCopilotRuntimeHandler } from \"../core/fetch-handler\";\nimport type { CopilotRuntimeHandlerOptions } from \"../core/fetch-handler\";\nimport { createCopilotNodeHandler } from \"./node-fetch-handler\";\nimport type { NodeFetchHandler } from \"./node-fetch-handler\";\n/**\n * Convenience wrapper for creating a Node.js HTTP request listener\n * from CopilotKit runtime handler options.\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 */\nexport function createCopilotNodeListener(\n options: CopilotRuntimeHandlerOptions,\n): NodeFetchHandler {\n const handler = createCopilotRuntimeHandler(options);\n return createCopilotNodeHandler(handler);\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;AAsBA,SAAgB,0BACd,SACkB;AAElB,QAAOA,oDADSC,kDAA4B,QAAQ,CACZ"}
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,12 +1,29 @@
1
-
1
+ require("reflect-metadata");
2
+ import { ChannelsControl } from "../core/channel-manager.cjs";
2
3
  import { CopilotRuntimeHandlerOptions } from "../core/fetch-handler.cjs";
3
4
  import { NodeFetchHandler } from "./node-fetch-handler.cjs";
4
5
 
5
6
  //#region src/v2/runtime/endpoints/node.d.ts
7
+ /**
8
+ * A Node.js HTTP request listener that is also a callable object carrying an
9
+ * optional {@link ChannelsControl} surface, mirroring
10
+ * `CopilotRuntimeFetchHandler.channels`. Node is the long-running,
11
+ * 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
+ * Channel activation.
14
+ */
15
+ type NodeCopilotListener = NodeFetchHandler & {
16
+ channels?: ChannelsControl;
17
+ };
6
18
  /**
7
19
  * Convenience wrapper for creating a Node.js HTTP request listener
8
20
  * from CopilotKit runtime handler options.
9
21
  *
22
+ * When the runtime declares managed Channels (and activation was not opted
23
+ * 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.
26
+ *
10
27
  * @example
11
28
  * ```typescript
12
29
  * import { createServer } from "node:http";
@@ -19,9 +36,12 @@ import { NodeFetchHandler } from "./node-fetch-handler.cjs";
19
36
  * cors: true,
20
37
  * });
21
38
  * createServer(listener).listen(3000);
39
+ *
40
+ * // Optional: observe/stop managed Channel activation.
41
+ * await listener.channels?.ready();
22
42
  * ```
23
43
  */
24
- declare function createCopilotNodeListener(options: CopilotRuntimeHandlerOptions): NodeFetchHandler;
44
+ declare function createCopilotNodeListener(options: CopilotRuntimeHandlerOptions): NodeCopilotListener;
25
45
  //#endregion
26
46
  export { createCopilotNodeListener };
27
47
  //# sourceMappingURL=node.d.cts.map
@@ -1 +1 @@
1
- {"version":3,"file":"node.d.cts","names":[],"sources":["../../../../src/v2/runtime/endpoints/node.ts"],"mappings":";;;;;;;AAsBA;;;;;;;;;;;;;;;;iBAAgB,yBAAA,CACd,OAAA,EAAS,4BAAA,GACR,gBAAA"}
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,12 +1,29 @@
1
1
  import "reflect-metadata";
2
+ import { ChannelsControl } from "../core/channel-manager.mjs";
2
3
  import { CopilotRuntimeHandlerOptions } from "../core/fetch-handler.mjs";
3
4
  import { NodeFetchHandler } from "./node-fetch-handler.mjs";
4
5
 
5
6
  //#region src/v2/runtime/endpoints/node.d.ts
7
+ /**
8
+ * A Node.js HTTP request listener that is also a callable object carrying an
9
+ * optional {@link ChannelsControl} surface, mirroring
10
+ * `CopilotRuntimeFetchHandler.channels`. Node is the long-running,
11
+ * 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
+ * Channel activation.
14
+ */
15
+ type NodeCopilotListener = NodeFetchHandler & {
16
+ channels?: ChannelsControl;
17
+ };
6
18
  /**
7
19
  * Convenience wrapper for creating a Node.js HTTP request listener
8
20
  * from CopilotKit runtime handler options.
9
21
  *
22
+ * When the runtime declares managed Channels (and activation was not opted
23
+ * 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.
26
+ *
10
27
  * @example
11
28
  * ```typescript
12
29
  * import { createServer } from "node:http";
@@ -19,9 +36,12 @@ import { NodeFetchHandler } from "./node-fetch-handler.mjs";
19
36
  * cors: true,
20
37
  * });
21
38
  * createServer(listener).listen(3000);
39
+ *
40
+ * // Optional: observe/stop managed Channel activation.
41
+ * await listener.channels?.ready();
22
42
  * ```
23
43
  */
24
- declare function createCopilotNodeListener(options: CopilotRuntimeHandlerOptions): NodeFetchHandler;
44
+ declare function createCopilotNodeListener(options: CopilotRuntimeHandlerOptions): NodeCopilotListener;
25
45
  //#endregion
26
46
  export { createCopilotNodeListener };
27
47
  //# sourceMappingURL=node.d.mts.map
@@ -1 +1 @@
1
- {"version":3,"file":"node.d.mts","names":[],"sources":["../../../../src/v2/runtime/endpoints/node.ts"],"mappings":";;;;;;;AAsBA;;;;;;;;;;;;;;;;iBAAgB,yBAAA,CACd,OAAA,EAAS,4BAAA,GACR,gBAAA"}
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"}
@@ -7,6 +7,11 @@ import { createCopilotNodeHandler } from "./node-fetch-handler.mjs";
7
7
  * Convenience wrapper for creating a Node.js HTTP request listener
8
8
  * from CopilotKit runtime handler options.
9
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
+ *
10
15
  * @example
11
16
  * ```typescript
12
17
  * import { createServer } from "node:http";
@@ -19,10 +24,16 @@ import { createCopilotNodeHandler } from "./node-fetch-handler.mjs";
19
24
  * cors: true,
20
25
  * });
21
26
  * createServer(listener).listen(3000);
27
+ *
28
+ * // Optional: observe/stop managed Channel activation.
29
+ * await listener.channels?.ready();
22
30
  * ```
23
31
  */
24
32
  function createCopilotNodeListener(options) {
25
- return createCopilotNodeHandler(createCopilotRuntimeHandler(options));
33
+ const handler = createCopilotRuntimeHandler(options);
34
+ const listener = createCopilotNodeHandler(handler);
35
+ listener.channels = handler.channels;
36
+ return listener;
26
37
  }
27
38
 
28
39
  //#endregion
@@ -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 { createCopilotNodeHandler } from \"./node-fetch-handler\";\nimport type { NodeFetchHandler } from \"./node-fetch-handler\";\n/**\n * Convenience wrapper for creating a Node.js HTTP request listener\n * from CopilotKit runtime handler options.\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 */\nexport function createCopilotNodeListener(\n options: CopilotRuntimeHandlerOptions,\n): NodeFetchHandler {\n const handler = createCopilotRuntimeHandler(options);\n return createCopilotNodeHandler(handler);\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;AAsBA,SAAgB,0BACd,SACkB;AAElB,QAAO,yBADS,4BAA4B,QAAQ,CACZ"}
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,3 +1,3 @@
1
-
2
- import { CopilotExpressEndpointParams, createCopilotExpressHandler } from "./endpoints/express.cjs";
1
+ require("reflect-metadata");
2
+ import { CopilotExpressEndpointParams, CopilotExpressRouter, createCopilotExpressHandler } from "./endpoints/express.cjs";
3
3
  import { createCopilotEndpointSingleRouteExpress } from "./endpoints/express-single.cjs";
@@ -1,3 +1,3 @@
1
1
  import "reflect-metadata";
2
- import { CopilotExpressEndpointParams, createCopilotExpressHandler } from "./endpoints/express.mjs";
2
+ import { CopilotExpressEndpointParams, CopilotExpressRouter, createCopilotExpressHandler } from "./endpoints/express.mjs";
3
3
  import { createCopilotEndpointSingleRouteExpress } from "./endpoints/express-single.mjs";
@@ -1,4 +1,4 @@
1
-
1
+ require("reflect-metadata");
2
2
  //#region src/v2/runtime/handlers/header-utils.d.ts
3
3
  /**
4
4
  * Fully-resolved inbound-header forwarding policy read by the call sites.
@@ -1,3 +1,3 @@
1
-
2
- import { CopilotEndpointCorsConfig, createCopilotEndpoint, createCopilotHonoHandler, toFetchCorsConfig } from "./endpoints/hono.cjs";
1
+ require("reflect-metadata");
2
+ import { CopilotEndpointCorsConfig, CopilotHonoApp, createCopilotEndpoint, createCopilotHonoHandler, toFetchCorsConfig } from "./endpoints/hono.cjs";
3
3
  import { createCopilotEndpointSingleRoute } from "./endpoints/hono-single.cjs";
@@ -1,3 +1,3 @@
1
1
  import "reflect-metadata";
2
- import { CopilotEndpointCorsConfig, createCopilotEndpoint, createCopilotHonoHandler, toFetchCorsConfig } from "./endpoints/hono.mjs";
2
+ import { CopilotEndpointCorsConfig, CopilotHonoApp, createCopilotEndpoint, createCopilotHonoHandler, toFetchCorsConfig } from "./endpoints/hono.mjs";
3
3
  import { createCopilotEndpointSingleRoute } from "./endpoints/hono-single.mjs";
@@ -1,19 +1,20 @@
1
-
1
+ require("reflect-metadata");
2
2
  import { TranscribeFileOptions, TranscriptionService } from "./transcription-service/transcription-service.cjs";
3
3
  import { AgentRunner, AgentRunnerConnectRequest, AgentRunnerIsRunningRequest, AgentRunnerRunRequest, AgentRunnerStopRequest, LocalThreadEndpointRecord, LocalThreadEndpointRunner, supportsLocalThreadEndpoints } from "./runner/agent-runner.cjs";
4
4
  import { CopilotKitIntelligence, CopilotKitIntelligenceConfig, CreateThreadRequest, ListThreadsResponse, SubscribeToThreadsRequest, SubscribeToThreadsResponse, ThreadSummary, UpdateThreadRequest } from "./intelligence-platform/client.cjs";
5
- import { AgentFactoryContext, AgentsConfig, AgentsFactory, CopilotIntelligenceRuntime, CopilotIntelligenceRuntimeLike, CopilotIntelligenceRuntimeOptions, CopilotRuntime, CopilotRuntimeLike, CopilotRuntimeOptions, CopilotRuntimeUser, CopilotSseRuntime, CopilotSseRuntimeLike, CopilotSseRuntimeOptions, IdentifyUserCallback, McpAppsConfig, McpAppsServerConfig, OpenGenerativeUIConfig, OpenGenerativeUIOptions, VERSION, isA2UIEnabled, isIntelligenceRuntime, resolveAgents } from "./core/runtime.cjs";
5
+ import { AgentFactoryContext, AgentsConfig, AgentsFactory, CopilotIntelligenceRuntime, CopilotIntelligenceRuntimeLike, CopilotIntelligenceRuntimeOptions, CopilotRuntime, CopilotRuntimeConstructor, CopilotRuntimeLike, CopilotRuntimeOptions, CopilotRuntimeUser, CopilotSseRuntime, CopilotSseRuntimeLike, CopilotSseRuntimeOptions, IdentifyUserCallback, McpAppsConfig, McpAppsServerConfig, OpenGenerativeUIConfig, OpenGenerativeUIOptions, RuntimeWithDeclaredChannels, VERSION, isA2UIEnabled, isIntelligenceRuntime, resolveAgents } from "./core/runtime.cjs";
6
6
  import { CopilotCorsConfig } from "./core/fetch-cors.cjs";
7
7
  import { CopilotRuntimeHooks, ErrorHookContext, HandlerHookContext, HookContext, ResponseHookContext, RouteInfo } from "./core/hooks.cjs";
8
- import { CopilotEndpointCorsConfig, createCopilotEndpoint, createCopilotHonoHandler, toFetchCorsConfig } from "./endpoints/hono.cjs";
8
+ import { ChannelStatus, ChannelsControl } from "./core/channel-manager.cjs";
9
+ import { CopilotEndpointCorsConfig, CopilotHonoApp, createCopilotEndpoint, createCopilotHonoHandler, toFetchCorsConfig } from "./endpoints/hono.cjs";
9
10
  import { createCopilotEndpointSingleRoute } from "./endpoints/hono-single.cjs";
10
- import { CopilotExpressEndpointParams, createCopilotExpressHandler } from "./endpoints/express.cjs";
11
+ import { CopilotExpressEndpointParams, CopilotExpressRouter, createCopilotExpressHandler } from "./endpoints/express.cjs";
11
12
  import { createCopilotEndpointSingleRouteExpress } from "./endpoints/express-single.cjs";
12
13
  import "./endpoints/index.cjs";
13
14
  import { InMemoryAgentRunner, InMemoryThread } from "./runner/in-memory.cjs";
14
15
  import { IntelligenceAgentRunner, IntelligenceAgentRunnerOptions, RunnerStartupBoundary } from "./runner/intelligence.cjs";
15
16
  import { finalizeRunEvents } from "./runner/index.cjs";
16
- import { CopilotRuntimeFetchHandler, CopilotRuntimeHandlerOptions, createCopilotRuntimeHandler } from "./core/fetch-handler.cjs";
17
+ import { CopilotRuntimeFetchHandler, CopilotRuntimeFetchHandlerWithChannels, CopilotRuntimeHandlerOptions, createCopilotRuntimeHandler } from "./core/fetch-handler.cjs";
17
18
  import { MCPClient, MCPTransport } from "@ai-sdk/mcp";
18
19
 
19
20
  //#region src/v2/runtime/index.d.ts
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.cts","names":[],"sources":["../../../src/v2/runtime/index.ts"],"mappings":";;;;;;;;;;;;;;;;;;;;KAgDY,wBAAA,IAA4B,MAAA;EACtC,OAAA,EAAS,OAAA;AAAA,MACL,OAAA,CAAQ,QAAA"}
1
+ {"version":3,"file":"index.d.cts","names":[],"sources":["../../../src/v2/runtime/index.ts"],"mappings":";;;;;;;;;;;;;;;;;;;;;KAqDY,wBAAA,IAA4B,MAAA;EACtC,OAAA,EAAS,OAAA;AAAA,MACL,OAAA,CAAQ,QAAA"}
@@ -2,18 +2,19 @@ import "reflect-metadata";
2
2
  import { TranscribeFileOptions, TranscriptionService } from "./transcription-service/transcription-service.mjs";
3
3
  import { AgentRunner, AgentRunnerConnectRequest, AgentRunnerIsRunningRequest, AgentRunnerRunRequest, AgentRunnerStopRequest, LocalThreadEndpointRecord, LocalThreadEndpointRunner, supportsLocalThreadEndpoints } from "./runner/agent-runner.mjs";
4
4
  import { CopilotKitIntelligence, CopilotKitIntelligenceConfig, CreateThreadRequest, ListThreadsResponse, SubscribeToThreadsRequest, SubscribeToThreadsResponse, ThreadSummary, UpdateThreadRequest } from "./intelligence-platform/client.mjs";
5
- import { AgentFactoryContext, AgentsConfig, AgentsFactory, CopilotIntelligenceRuntime, CopilotIntelligenceRuntimeLike, CopilotIntelligenceRuntimeOptions, CopilotRuntime, CopilotRuntimeLike, CopilotRuntimeOptions, CopilotRuntimeUser, CopilotSseRuntime, CopilotSseRuntimeLike, CopilotSseRuntimeOptions, IdentifyUserCallback, McpAppsConfig, McpAppsServerConfig, OpenGenerativeUIConfig, OpenGenerativeUIOptions, VERSION, isA2UIEnabled, isIntelligenceRuntime, resolveAgents } from "./core/runtime.mjs";
5
+ import { AgentFactoryContext, AgentsConfig, AgentsFactory, CopilotIntelligenceRuntime, CopilotIntelligenceRuntimeLike, CopilotIntelligenceRuntimeOptions, CopilotRuntime, CopilotRuntimeConstructor, CopilotRuntimeLike, CopilotRuntimeOptions, CopilotRuntimeUser, CopilotSseRuntime, CopilotSseRuntimeLike, CopilotSseRuntimeOptions, IdentifyUserCallback, McpAppsConfig, McpAppsServerConfig, OpenGenerativeUIConfig, OpenGenerativeUIOptions, RuntimeWithDeclaredChannels, VERSION, isA2UIEnabled, isIntelligenceRuntime, resolveAgents } from "./core/runtime.mjs";
6
6
  import { CopilotCorsConfig } from "./core/fetch-cors.mjs";
7
7
  import { CopilotRuntimeHooks, ErrorHookContext, HandlerHookContext, HookContext, ResponseHookContext, RouteInfo } from "./core/hooks.mjs";
8
- import { CopilotEndpointCorsConfig, createCopilotEndpoint, createCopilotHonoHandler, toFetchCorsConfig } from "./endpoints/hono.mjs";
8
+ import { ChannelStatus, ChannelsControl } from "./core/channel-manager.mjs";
9
+ import { CopilotEndpointCorsConfig, CopilotHonoApp, createCopilotEndpoint, createCopilotHonoHandler, toFetchCorsConfig } from "./endpoints/hono.mjs";
9
10
  import { createCopilotEndpointSingleRoute } from "./endpoints/hono-single.mjs";
10
- import { CopilotExpressEndpointParams, createCopilotExpressHandler } from "./endpoints/express.mjs";
11
+ import { CopilotExpressEndpointParams, CopilotExpressRouter, createCopilotExpressHandler } from "./endpoints/express.mjs";
11
12
  import { createCopilotEndpointSingleRouteExpress } from "./endpoints/express-single.mjs";
12
13
  import "./endpoints/index.mjs";
13
14
  import { InMemoryAgentRunner, InMemoryThread } from "./runner/in-memory.mjs";
14
15
  import { IntelligenceAgentRunner, IntelligenceAgentRunnerOptions, RunnerStartupBoundary } from "./runner/intelligence.mjs";
15
16
  import { finalizeRunEvents } from "./runner/index.mjs";
16
- import { CopilotRuntimeFetchHandler, CopilotRuntimeHandlerOptions, createCopilotRuntimeHandler } from "./core/fetch-handler.mjs";
17
+ import { CopilotRuntimeFetchHandler, CopilotRuntimeFetchHandlerWithChannels, CopilotRuntimeHandlerOptions, createCopilotRuntimeHandler } from "./core/fetch-handler.mjs";
17
18
  import { MCPClient, MCPTransport } from "@ai-sdk/mcp";
18
19
 
19
20
  //#region src/v2/runtime/index.d.ts
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.mts","names":[],"sources":["../../../src/v2/runtime/index.ts"],"mappings":";;;;;;;;;;;;;;;;;;;;KAgDY,wBAAA,IAA4B,MAAA;EACtC,OAAA,EAAS,OAAA;AAAA,MACL,OAAA,CAAQ,QAAA"}
1
+ {"version":3,"file":"index.d.mts","names":[],"sources":["../../../src/v2/runtime/index.ts"],"mappings":";;;;;;;;;;;;;;;;;;;;;KAqDY,wBAAA,IAA4B,MAAA;EACtC,OAAA,EAAS,OAAA;AAAA,MACL,OAAA,CAAQ,QAAA"}
@@ -1,4 +1,4 @@
1
-
1
+ require("reflect-metadata");
2
2
  //#region src/v2/runtime/intelligence-platform/client.d.ts
3
3
  /**
4
4
  * Client for the CopilotKit Intelligence Platform REST API.
@@ -1,3 +1,3 @@
1
-
1
+ require("reflect-metadata");
2
2
  import { NodeFetchHandler, createCopilotNodeHandler, createNodeFetchHandler } from "./endpoints/node-fetch-handler.cjs";
3
3
  import { createCopilotNodeListener } from "./endpoints/node.cjs";
@@ -1,4 +1,4 @@
1
-
1
+ require("reflect-metadata");
2
2
  import { Observable } from "rxjs";
3
3
  import { AbstractAgent, BaseEvent, Message, RunAgentInput } from "@ag-ui/client";
4
4
 
@@ -21,9 +21,10 @@ var InMemoryEventStore = class {
21
21
  };
22
22
  const GLOBAL_STORE = /* @__PURE__ */ new Map();
23
23
  var InMemoryAgentRunner = class extends require_agent_runner.AgentRunner {
24
- constructor(..._args) {
25
- super(..._args);
24
+ constructor(options) {
25
+ super();
26
26
  this.ɵsupportsLocalThreadEndpoints = true;
27
+ this.onConcurrentRun = options?.onConcurrentRun ?? "throw";
27
28
  }
28
29
  run(request) {
29
30
  let existingStore = GLOBAL_STORE.get(request.threadId);
@@ -32,7 +33,18 @@ var InMemoryAgentRunner = class extends require_agent_runner.AgentRunner {
32
33
  GLOBAL_STORE.set(request.threadId, existingStore);
33
34
  }
34
35
  const store = existingStore;
35
- if (store.isRunning) throw new Error("Thread already running");
36
+ if (store.isRunning) {
37
+ if (this.onConcurrentRun !== "supersede") throw new Error("Thread already running");
38
+ const priorAgent = store.agent;
39
+ store.stopRequested = true;
40
+ store.isRunning = false;
41
+ if (priorAgent) try {
42
+ priorAgent.abortRun();
43
+ } catch (error) {
44
+ console.error("Failed to abort superseded run", error);
45
+ }
46
+ store.stopRequested = false;
47
+ }
36
48
  store.isRunning = true;
37
49
  store.currentRunId = request.input.runId;
38
50
  store.agent = request.agent;
@@ -91,11 +103,11 @@ var InMemoryAgentRunner = class extends require_agent_runner.AgentRunner {
91
103
  runSubject.next(event);
92
104
  nextSubject.next(event);
93
105
  }
94
- if (store.currentRunId) {
106
+ if (store.currentRunId === request.input.runId) {
95
107
  const compactedEvents = (0, _ag_ui_client.compactEvents)(currentRunEvents);
96
108
  store.historicRuns.push({
97
109
  threadId: request.threadId,
98
- runId: store.currentRunId,
110
+ runId: request.input.runId,
99
111
  agentId: request.agent.agentId ?? "default",
100
112
  parentRunId,
101
113
  events: compactedEvents,
@@ -103,12 +115,14 @@ var InMemoryAgentRunner = class extends require_agent_runner.AgentRunner {
103
115
  createdAt: Date.now()
104
116
  });
105
117
  }
106
- store.currentEvents = null;
107
- store.currentRunId = null;
108
- store.agent = null;
109
- store.runSubject = null;
110
- store.stopRequested = false;
111
- store.isRunning = false;
118
+ if (store.currentRunId === request.input.runId) {
119
+ store.currentEvents = null;
120
+ store.currentRunId = null;
121
+ store.agent = null;
122
+ store.runSubject = null;
123
+ store.stopRequested = false;
124
+ store.isRunning = false;
125
+ }
112
126
  runSubject.complete();
113
127
  nextSubject.complete();
114
128
  } catch (error) {
@@ -121,11 +135,11 @@ var InMemoryAgentRunner = class extends require_agent_runner.AgentRunner {
121
135
  runSubject.next(event);
122
136
  nextSubject.next(event);
123
137
  }
124
- if (store.currentRunId && currentRunEvents.length > 0) {
138
+ if (store.currentRunId === request.input.runId && currentRunEvents.length > 0) {
125
139
  const compactedEvents = (0, _ag_ui_client.compactEvents)(currentRunEvents);
126
140
  store.historicRuns.push({
127
141
  threadId: request.threadId,
128
- runId: store.currentRunId,
142
+ runId: request.input.runId,
129
143
  agentId: request.agent.agentId ?? "default",
130
144
  parentRunId,
131
145
  events: compactedEvents,
@@ -133,12 +147,14 @@ var InMemoryAgentRunner = class extends require_agent_runner.AgentRunner {
133
147
  createdAt: Date.now()
134
148
  });
135
149
  }
136
- store.currentEvents = null;
137
- store.currentRunId = null;
138
- store.agent = null;
139
- store.runSubject = null;
140
- store.stopRequested = false;
141
- store.isRunning = false;
150
+ if (store.currentRunId === request.input.runId) {
151
+ store.currentEvents = null;
152
+ store.currentRunId = null;
153
+ store.agent = null;
154
+ store.runSubject = null;
155
+ store.stopRequested = false;
156
+ store.isRunning = false;
157
+ }
142
158
  runSubject.complete();
143
159
  nextSubject.complete();
144
160
  }
@@ -1 +1 @@
1
- {"version":3,"file":"in-memory.cjs","names":["AgentRunner","EventType","ReplaySubject"],"sources":["../../../../src/v2/runtime/runner/in-memory.ts"],"sourcesContent":["import type {\n AgentRunnerConnectRequest,\n AgentRunnerIsRunningRequest,\n AgentRunnerRunRequest,\n} from \"./agent-runner\";\nimport { AgentRunner } from \"./agent-runner\";\nimport type { AgentRunnerStopRequest } from \"./agent-runner\";\nimport type { Observable } from \"rxjs\";\nimport { ReplaySubject } from \"rxjs\";\nimport type {\n AbstractAgent,\n BaseEvent,\n Message,\n RunStartedEvent,\n StateSnapshotEvent,\n} from \"@ag-ui/client\";\nimport { EventType, compactEvents } from \"@ag-ui/client\";\nimport { finalizeRunEvents } from \"@copilotkit/shared\";\n\ninterface HistoricRun {\n threadId: string;\n runId: string;\n /** ID of the agent that executed this run. */\n agentId: string;\n parentRunId: string | null;\n events: BaseEvent[];\n /**\n * Snapshot of all messages (input + generated) at the end of this run.\n * Used by the local thread-messages fallback endpoint.\n */\n messages: Message[];\n createdAt: number;\n}\n\n/**\n * Lightweight thread summary returned by {@link InMemoryAgentRunner.listThreads}.\n * Shape matches the Intelligence platform's ThreadRecord so the same HTTP\n * response envelope can be used for both backends.\n */\nexport interface InMemoryThread {\n id: string;\n name: string | null;\n agentId: string;\n organizationId: \"\"; // always empty in in-memory mode\n createdById: \"\"; // always empty in in-memory mode\n archived: false; // always false in in-memory mode\n createdAt: string;\n updatedAt: string;\n}\n\nclass InMemoryEventStore {\n constructor(public threadId: string) {}\n\n /** The subject that current consumers subscribe to. */\n subject: ReplaySubject<BaseEvent> | null = null;\n\n /** True while a run is actively producing events. */\n isRunning = false;\n\n /** Current run ID */\n currentRunId: string | null = null;\n\n /** Historic completed runs */\n historicRuns: HistoricRun[] = [];\n\n /** Currently running agent instance (if any). */\n agent: AbstractAgent | null = null;\n\n /** Subject returned from run() while the run is active. */\n runSubject: ReplaySubject<BaseEvent> | null = null;\n\n /** True once stop() has been requested but the run has not yet finalized. */\n stopRequested = false;\n\n /** Reference to the events emitted in the current run. */\n currentEvents: BaseEvent[] | null = null;\n}\n\nconst GLOBAL_STORE = new Map<string, InMemoryEventStore>();\n\nexport class InMemoryAgentRunner extends AgentRunner {\n readonly ɵsupportsLocalThreadEndpoints = true;\n\n run(request: AgentRunnerRunRequest): Observable<BaseEvent> {\n let existingStore = GLOBAL_STORE.get(request.threadId);\n if (!existingStore) {\n existingStore = new InMemoryEventStore(request.threadId);\n GLOBAL_STORE.set(request.threadId, existingStore);\n }\n const store = existingStore; // Now store is const and non-null\n\n if (store.isRunning) {\n throw new Error(\"Thread already running\");\n }\n store.isRunning = true;\n store.currentRunId = request.input.runId;\n store.agent = request.agent;\n store.stopRequested = false;\n\n // Track seen message IDs and current run events for this run\n const seenMessageIds = new Set<string>();\n const currentRunEvents: BaseEvent[] = [];\n store.currentEvents = currentRunEvents;\n\n // Get all previously seen message IDs from historic runs\n const historicMessageIds = new Set<string>();\n for (const run of store.historicRuns) {\n for (const event of run.events) {\n if (\"messageId\" in event && typeof event.messageId === \"string\") {\n historicMessageIds.add(event.messageId);\n }\n if (event.type === EventType.RUN_STARTED) {\n const runStarted = event as RunStartedEvent;\n const messages = runStarted.input?.messages ?? [];\n for (const message of messages) {\n historicMessageIds.add(message.id);\n }\n }\n }\n }\n\n const nextSubject = new ReplaySubject<BaseEvent>(Infinity);\n const prevSubject = store.subject;\n\n // Update the store's subject immediately\n store.subject = nextSubject;\n\n // Create a subject for run() return value\n const runSubject = new ReplaySubject<BaseEvent>(Infinity);\n store.runSubject = runSubject;\n\n // Helper function to run the agent and handle errors\n const runAgent = async () => {\n // Get parent run ID for chaining\n const lastRun = store.historicRuns[store.historicRuns.length - 1];\n const parentRunId = lastRun?.runId ?? null;\n\n try {\n await request.agent.runAgent(request.input, {\n onEvent: ({ event }) => {\n let processedEvent: BaseEvent = event;\n if (event.type === EventType.RUN_STARTED) {\n const runStartedEvent = event as RunStartedEvent;\n if (!runStartedEvent.input) {\n const sanitizedMessages = request.input.messages\n ? request.input.messages.filter(\n (message) => !historicMessageIds.has(message.id),\n )\n : undefined;\n const updatedInput = {\n ...request.input,\n ...(sanitizedMessages !== undefined\n ? { messages: sanitizedMessages }\n : {}),\n };\n processedEvent = {\n ...runStartedEvent,\n input: updatedInput,\n } as RunStartedEvent;\n }\n }\n\n runSubject.next(processedEvent); // For run() return - only agent events\n nextSubject.next(processedEvent); // For connect() / store - all events\n currentRunEvents.push(processedEvent); // Accumulate for storage\n },\n onNewMessage: ({ message }) => {\n // Called for each new message\n if (!seenMessageIds.has(message.id)) {\n seenMessageIds.add(message.id);\n }\n },\n onRunStartedEvent: () => {\n // Mark any messages from the input as seen so they aren't emitted twice\n if (request.input.messages) {\n for (const message of request.input.messages) {\n if (!seenMessageIds.has(message.id)) {\n seenMessageIds.add(message.id);\n }\n }\n }\n },\n });\n\n const appendedEvents = finalizeRunEvents(currentRunEvents, {\n stopRequested: store.stopRequested,\n });\n for (const event of appendedEvents) {\n runSubject.next(event);\n nextSubject.next(event);\n }\n\n // Store the completed run in memory with ONLY its events\n if (store.currentRunId) {\n // Compact the events before storing (like SQLite does)\n const compactedEvents = compactEvents(currentRunEvents);\n\n store.historicRuns.push({\n threadId: request.threadId,\n runId: store.currentRunId,\n agentId: request.agent.agentId ?? \"default\",\n parentRunId,\n events: compactedEvents,\n // Snapshot all messages (input + generated) for the thread-messages endpoint\n messages: Array.isArray(request.agent.messages)\n ? [...request.agent.messages]\n : [],\n createdAt: Date.now(),\n });\n }\n\n // Complete the run\n store.currentEvents = null;\n store.currentRunId = null;\n store.agent = null;\n store.runSubject = null;\n store.stopRequested = false;\n store.isRunning = false;\n runSubject.complete();\n nextSubject.complete();\n } catch (error) {\n const interruptionMessage =\n error instanceof Error ? error.message : String(error);\n const appendedEvents = finalizeRunEvents(currentRunEvents, {\n stopRequested: store.stopRequested,\n interruptionMessage,\n });\n for (const event of appendedEvents) {\n runSubject.next(event);\n nextSubject.next(event);\n }\n\n // Store the run even if it failed (partial events)\n if (store.currentRunId && currentRunEvents.length > 0) {\n // Compact the events before storing (like SQLite does)\n const compactedEvents = compactEvents(currentRunEvents);\n store.historicRuns.push({\n threadId: request.threadId,\n runId: store.currentRunId,\n agentId: request.agent.agentId ?? \"default\",\n parentRunId,\n events: compactedEvents,\n messages: Array.isArray(request.agent.messages)\n ? [...request.agent.messages]\n : [],\n createdAt: Date.now(),\n });\n }\n\n // Complete the run\n store.currentEvents = null;\n store.currentRunId = null;\n store.agent = null;\n store.runSubject = null;\n store.stopRequested = false;\n store.isRunning = false;\n runSubject.complete();\n nextSubject.complete();\n }\n };\n\n // Bridge previous events if they exist\n if (prevSubject) {\n prevSubject.subscribe({\n next: (e) => nextSubject.next(e),\n error: (err) => nextSubject.error(err),\n complete: () => {\n // Don't complete nextSubject here - it needs to stay open for new events\n },\n });\n }\n\n // Start the agent execution immediately (not lazily)\n runAgent();\n\n // Return the run subject (only agent events, no injected messages)\n return runSubject.asObservable();\n }\n\n connect(request: AgentRunnerConnectRequest): Observable<BaseEvent> {\n const store = GLOBAL_STORE.get(request.threadId);\n const connectionSubject = new ReplaySubject<BaseEvent>(Infinity);\n\n if (!store) {\n // No store means no events\n connectionSubject.complete();\n return connectionSubject.asObservable();\n }\n\n // Collect all historic events from memory\n const allHistoricEvents: BaseEvent[] = [];\n for (const run of store.historicRuns) {\n allHistoricEvents.push(...run.events);\n }\n\n // Apply compaction to all historic events together (like SQLite)\n const compactedEvents = compactEvents(allHistoricEvents);\n\n // Emit compacted events and track message IDs\n const emittedMessageIds = new Set<string>();\n for (const event of compactedEvents) {\n connectionSubject.next(event);\n if (\"messageId\" in event && typeof event.messageId === \"string\") {\n emittedMessageIds.add(event.messageId);\n }\n }\n\n // Bridge active run to connection if exists\n if (store.subject && (store.isRunning || store.stopRequested)) {\n store.subject.subscribe({\n next: (event) => {\n // Skip message events that we've already emitted from historic\n if (\n \"messageId\" in event &&\n typeof event.messageId === \"string\" &&\n emittedMessageIds.has(event.messageId)\n ) {\n return;\n }\n connectionSubject.next(event);\n },\n complete: () => connectionSubject.complete(),\n error: (err) => connectionSubject.error(err),\n });\n } else {\n // No active run, complete after historic events\n connectionSubject.complete();\n }\n\n return connectionSubject.asObservable();\n }\n\n isRunning(request: AgentRunnerIsRunningRequest): Promise<boolean> {\n const store = GLOBAL_STORE.get(request.threadId);\n return Promise.resolve(store?.isRunning ?? false);\n }\n\n stop(request: AgentRunnerStopRequest): Promise<boolean | undefined> {\n const store = GLOBAL_STORE.get(request.threadId);\n if (!store || !store.isRunning) {\n return Promise.resolve(false);\n }\n if (store.stopRequested) {\n return Promise.resolve(false);\n }\n\n store.stopRequested = true;\n store.isRunning = false;\n\n const agent = store.agent;\n if (!agent) {\n store.stopRequested = false;\n store.isRunning = false;\n return Promise.resolve(false);\n }\n\n try {\n agent.abortRun();\n return Promise.resolve(true);\n } catch (error) {\n console.error(\"Failed to abort agent run\", error);\n store.stopRequested = false;\n store.isRunning = true;\n return Promise.resolve(false);\n }\n }\n\n /**\n * Returns a summary of every thread that has been run through this runner.\n *\n * This powers the local-dev fallback for `GET /threads` when the Intelligence\n * platform is not configured. Each entry mirrors the shape of a platform\n * `ThreadRecord` so the HTTP handler can use the same response envelope.\n */\n listThreads(): InMemoryThread[] {\n const threads: InMemoryThread[] = [];\n for (const [threadId, store] of GLOBAL_STORE) {\n if (store.historicRuns.length === 0) continue;\n const firstRun = store.historicRuns[0]!;\n const lastRun = store.historicRuns[store.historicRuns.length - 1]!;\n threads.push({\n id: threadId,\n name: null,\n agentId: lastRun.agentId,\n organizationId: \"\",\n createdById: \"\",\n archived: false,\n createdAt: new Date(firstRun.createdAt).toISOString(),\n updatedAt: new Date(lastRun.createdAt).toISOString(),\n });\n }\n // Most recently updated first\n return threads.sort(\n (a, b) =>\n new Date(b.updatedAt).getTime() - new Date(a.updatedAt).getTime(),\n );\n }\n\n /**\n * Returns all messages for a thread, using the snapshot captured at the end\n * of the most recent run.\n *\n * This powers the local-dev fallback for `GET /threads/:threadId/messages`\n * when the Intelligence platform is not configured. The returned `Message[]`\n * objects come directly from the ag-ui agent, so their shape is compatible\n * with the Intelligence platform's `ThreadMessage` type.\n */\n getThreadMessages(threadId: string): Message[] {\n const store = GLOBAL_STORE.get(threadId);\n if (!store || store.historicRuns.length === 0) return [];\n // The last run's snapshot has the complete conversation history\n return store.historicRuns[store.historicRuns.length - 1]!.messages;\n }\n\n /**\n * Returns all AG-UI events for a thread, compacted across historic runs.\n *\n * Powers the local-dev fallback for `GET /threads/:threadId/events` when the\n * Intelligence platform is not configured. The compaction logic matches\n * the connection-replay path in {@link connect}, so the stream a\n * late-joining inspector sees matches what this method returns.\n */\n getThreadEvents(threadId: string): BaseEvent[] {\n const store = GLOBAL_STORE.get(threadId);\n if (!store || store.historicRuns.length === 0) return [];\n const all: BaseEvent[] = [];\n for (const run of store.historicRuns) all.push(...run.events);\n return compactEvents(all);\n }\n\n /**\n * Returns the agent state snapshot for a thread.\n *\n * Derived from the last `STATE_SNAPSHOT` in the compacted event stream. The\n * AG-UI `compactEvents` helper consolidates STATE_DELTA events and produces\n * a single trailing STATE_SNAPSHOT when state changes exist, so this is a\n * faithful view of state at the end of the most recent run.\n *\n * Returns `null` when the thread has never emitted a STATE_SNAPSHOT.\n */\n getThreadState(threadId: string): Record<string, unknown> | null {\n const events = this.getThreadEvents(threadId);\n // Walk backwards — the last snapshot wins.\n for (let i = events.length - 1; i >= 0; i--) {\n const event = events[i]!;\n if (event.type === EventType.STATE_SNAPSHOT) {\n const snapshot = (event as StateSnapshotEvent).snapshot;\n if (snapshot && typeof snapshot === \"object\") {\n return snapshot as Record<string, unknown>;\n }\n return null;\n }\n }\n return null;\n }\n\n /**\n * Clears all in-memory thread history.\n *\n * Powers the local-dev fallback for `POST /threads/clear`, letting consumers\n * (e.g. the demo's Clear button) reset to an empty thread list without\n * restarting the runtime. Intentionally not exposed on the Intelligence\n * platform path: there, thread history lives in a real database and must\n * not be wiped this way.\n */\n clearThreads(): void {\n GLOBAL_STORE.clear();\n }\n}\n"],"mappings":";;;;;;;;AAkDA,IAAM,qBAAN,MAAyB;CACvB,YAAY,AAAO,UAAkB;EAAlB;iBAGwB;mBAG/B;sBAGkB;sBAGA,EAAE;eAGF;oBAGgB;uBAG9B;uBAGoB;;;AAGtC,MAAM,+BAAe,IAAI,KAAiC;AAE1D,IAAa,sBAAb,cAAyCA,iCAAY;;;uCACV;;CAEzC,IAAI,SAAuD;EACzD,IAAI,gBAAgB,aAAa,IAAI,QAAQ,SAAS;AACtD,MAAI,CAAC,eAAe;AAClB,mBAAgB,IAAI,mBAAmB,QAAQ,SAAS;AACxD,gBAAa,IAAI,QAAQ,UAAU,cAAc;;EAEnD,MAAM,QAAQ;AAEd,MAAI,MAAM,UACR,OAAM,IAAI,MAAM,yBAAyB;AAE3C,QAAM,YAAY;AAClB,QAAM,eAAe,QAAQ,MAAM;AACnC,QAAM,QAAQ,QAAQ;AACtB,QAAM,gBAAgB;EAGtB,MAAM,iCAAiB,IAAI,KAAa;EACxC,MAAM,mBAAgC,EAAE;AACxC,QAAM,gBAAgB;EAGtB,MAAM,qCAAqB,IAAI,KAAa;AAC5C,OAAK,MAAM,OAAO,MAAM,aACtB,MAAK,MAAM,SAAS,IAAI,QAAQ;AAC9B,OAAI,eAAe,SAAS,OAAO,MAAM,cAAc,SACrD,oBAAmB,IAAI,MAAM,UAAU;AAEzC,OAAI,MAAM,SAASC,wBAAU,aAAa;IAExC,MAAM,WADa,MACS,OAAO,YAAY,EAAE;AACjD,SAAK,MAAM,WAAW,SACpB,oBAAmB,IAAI,QAAQ,GAAG;;;EAM1C,MAAM,cAAc,IAAIC,mBAAyB,SAAS;EAC1D,MAAM,cAAc,MAAM;AAG1B,QAAM,UAAU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AAK,GAAG,KAAK;GAC3C,MAAM,QAAQ,OAAO;AACrB,OAAI,MAAM,SAASD,wBAAU,gBAAgB;IAC3C,MAAM,WAAY,MAA6B;AAC/C,QAAI,YAAY,OAAO,aAAa,SAClC,QAAO;AAET,WAAO;;;AAGX,SAAO;;;;;;;;;;;CAYT,eAAqB;AACnB,eAAa,OAAO"}
1
+ {"version":3,"file":"in-memory.cjs","names":["AgentRunner","EventType","ReplaySubject"],"sources":["../../../../src/v2/runtime/runner/in-memory.ts"],"sourcesContent":["import type {\n AgentRunnerConnectRequest,\n AgentRunnerIsRunningRequest,\n AgentRunnerRunRequest,\n} from \"./agent-runner\";\nimport { AgentRunner } from \"./agent-runner\";\nimport type { AgentRunnerStopRequest } from \"./agent-runner\";\nimport type { Observable } from \"rxjs\";\nimport { ReplaySubject } from \"rxjs\";\nimport type {\n AbstractAgent,\n BaseEvent,\n Message,\n RunStartedEvent,\n StateSnapshotEvent,\n} from \"@ag-ui/client\";\nimport { EventType, compactEvents } from \"@ag-ui/client\";\nimport { finalizeRunEvents } from \"@copilotkit/shared\";\n\ninterface HistoricRun {\n threadId: string;\n runId: string;\n /** ID of the agent that executed this run. */\n agentId: string;\n parentRunId: string | null;\n events: BaseEvent[];\n /**\n * Snapshot of all messages (input + generated) at the end of this run.\n * Used by the local thread-messages fallback endpoint.\n */\n messages: Message[];\n createdAt: number;\n}\n\n/**\n * Lightweight thread summary returned by {@link InMemoryAgentRunner.listThreads}.\n * Shape matches the Intelligence platform's ThreadRecord so the same HTTP\n * response envelope can be used for both backends.\n */\nexport interface InMemoryThread {\n id: string;\n name: string | null;\n agentId: string;\n organizationId: \"\"; // always empty in in-memory mode\n createdById: \"\"; // always empty in in-memory mode\n archived: false; // always false in in-memory mode\n createdAt: string;\n updatedAt: string;\n}\n\nclass InMemoryEventStore {\n constructor(public threadId: string) {}\n\n /** The subject that current consumers subscribe to. */\n subject: ReplaySubject<BaseEvent> | null = null;\n\n /** True while a run is actively producing events. */\n isRunning = false;\n\n /** Current run ID */\n currentRunId: string | null = null;\n\n /** Historic completed runs */\n historicRuns: HistoricRun[] = [];\n\n /** Currently running agent instance (if any). */\n agent: AbstractAgent | null = null;\n\n /** Subject returned from run() while the run is active. */\n runSubject: ReplaySubject<BaseEvent> | null = null;\n\n /** True once stop() has been requested but the run has not yet finalized. */\n stopRequested = false;\n\n /** Reference to the events emitted in the current run. */\n currentEvents: BaseEvent[] | null = null;\n}\n\nconst GLOBAL_STORE = new Map<string, InMemoryEventStore>();\n\nexport class InMemoryAgentRunner extends AgentRunner {\n readonly ɵsupportsLocalThreadEndpoints = true;\n\n /**\n * How to handle a `run()` for a thread that already has an in-flight run.\n * `\"throw\"` (default) preserves the historic behavior. `\"supersede\"` aborts\n * the prior run (mirroring `stop()`) and starts the new one — opted into by\n * the hosted-bot listener so a fast follow-up turn on the same thread cleanly\n * replaces a still-running (or wedged) prior turn instead of erroring with\n * \"Thread already running\".\n */\n private readonly onConcurrentRun: \"throw\" | \"supersede\";\n\n constructor(options?: { onConcurrentRun?: \"throw\" | \"supersede\" }) {\n super();\n this.onConcurrentRun = options?.onConcurrentRun ?? \"throw\";\n }\n\n run(request: AgentRunnerRunRequest): Observable<BaseEvent> {\n let existingStore = GLOBAL_STORE.get(request.threadId);\n if (!existingStore) {\n existingStore = new InMemoryEventStore(request.threadId);\n GLOBAL_STORE.set(request.threadId, existingStore);\n }\n const store = existingStore; // Now store is const and non-null\n\n if (store.isRunning) {\n if (this.onConcurrentRun !== \"supersede\") {\n throw new Error(\"Thread already running\");\n }\n // Supersede: abort the prior (possibly wedged) run so this one can start.\n // Mirrors stop(). The prior run's async finalization runs later and is\n // prevented from clobbering this run's state by the run-id guard below.\n const priorAgent = store.agent;\n store.stopRequested = true;\n store.isRunning = false;\n if (priorAgent) {\n try {\n priorAgent.abortRun();\n } catch (error) {\n console.error(\"Failed to abort superseded run\", error);\n }\n }\n store.stopRequested = false;\n }\n store.isRunning = true;\n store.currentRunId = request.input.runId;\n store.agent = request.agent;\n store.stopRequested = false;\n\n // Track seen message IDs and current run events for this run\n const seenMessageIds = new Set<string>();\n const currentRunEvents: BaseEvent[] = [];\n store.currentEvents = currentRunEvents;\n\n // Get all previously seen message IDs from historic runs\n const historicMessageIds = new Set<string>();\n for (const run of store.historicRuns) {\n for (const event of run.events) {\n if (\"messageId\" in event && typeof event.messageId === \"string\") {\n historicMessageIds.add(event.messageId);\n }\n if (event.type === EventType.RUN_STARTED) {\n const runStarted = event as RunStartedEvent;\n const messages = runStarted.input?.messages ?? [];\n for (const message of messages) {\n historicMessageIds.add(message.id);\n }\n }\n }\n }\n\n const nextSubject = new ReplaySubject<BaseEvent>(Infinity);\n const prevSubject = store.subject;\n\n // Update the store's subject immediately\n store.subject = nextSubject;\n\n // Create a subject for run() return value\n const runSubject = new ReplaySubject<BaseEvent>(Infinity);\n store.runSubject = runSubject;\n\n // Helper function to run the agent and handle errors\n const runAgent = async () => {\n // Get parent run ID for chaining\n const lastRun = store.historicRuns[store.historicRuns.length - 1];\n const parentRunId = lastRun?.runId ?? null;\n\n try {\n await request.agent.runAgent(request.input, {\n onEvent: ({ event }) => {\n let processedEvent: BaseEvent = event;\n if (event.type === EventType.RUN_STARTED) {\n const runStartedEvent = event as RunStartedEvent;\n if (!runStartedEvent.input) {\n const sanitizedMessages = request.input.messages\n ? request.input.messages.filter(\n (message) => !historicMessageIds.has(message.id),\n )\n : undefined;\n const updatedInput = {\n ...request.input,\n ...(sanitizedMessages !== undefined\n ? { messages: sanitizedMessages }\n : {}),\n };\n processedEvent = {\n ...runStartedEvent,\n input: updatedInput,\n } as RunStartedEvent;\n }\n }\n\n runSubject.next(processedEvent); // For run() return - only agent events\n nextSubject.next(processedEvent); // For connect() / store - all events\n currentRunEvents.push(processedEvent); // Accumulate for storage\n },\n onNewMessage: ({ message }) => {\n // Called for each new message\n if (!seenMessageIds.has(message.id)) {\n seenMessageIds.add(message.id);\n }\n },\n onRunStartedEvent: () => {\n // Mark any messages from the input as seen so they aren't emitted twice\n if (request.input.messages) {\n for (const message of request.input.messages) {\n if (!seenMessageIds.has(message.id)) {\n seenMessageIds.add(message.id);\n }\n }\n }\n },\n });\n\n const appendedEvents = finalizeRunEvents(currentRunEvents, {\n stopRequested: store.stopRequested,\n });\n for (const event of appendedEvents) {\n runSubject.next(event);\n nextSubject.next(event);\n }\n\n // Store the completed run in memory with ONLY its events. Guard on the\n // per-run id (not the shared `store.currentRunId`): a superseded run no\n // longer owns the store, so it must not push history — and never under\n // a newer run's id, which would corrupt the thread's history.\n if (store.currentRunId === request.input.runId) {\n // Compact the events before storing (like SQLite does)\n const compactedEvents = compactEvents(currentRunEvents);\n\n store.historicRuns.push({\n threadId: request.threadId,\n runId: request.input.runId,\n agentId: request.agent.agentId ?? \"default\",\n parentRunId,\n events: compactedEvents,\n // Snapshot all messages (input + generated) for the thread-messages endpoint\n messages: Array.isArray(request.agent.messages)\n ? [...request.agent.messages]\n : [],\n createdAt: Date.now(),\n });\n }\n\n // Complete the run. Guard the shared-store reset: if a newer run has\n // superseded this one (`currentRunId` changed), that run now owns the\n // store — don't clobber its state. Always complete THIS run's subjects.\n if (store.currentRunId === request.input.runId) {\n store.currentEvents = null;\n store.currentRunId = null;\n store.agent = null;\n store.runSubject = null;\n store.stopRequested = false;\n store.isRunning = false;\n }\n runSubject.complete();\n nextSubject.complete();\n } catch (error) {\n const interruptionMessage =\n error instanceof Error ? error.message : String(error);\n const appendedEvents = finalizeRunEvents(currentRunEvents, {\n stopRequested: store.stopRequested,\n interruptionMessage,\n });\n for (const event of appendedEvents) {\n runSubject.next(event);\n nextSubject.next(event);\n }\n\n // Store the run even if it failed (partial events). Same per-run guard:\n // a superseded run's error teardown must not push history under the\n // newer run's id (see success-path note).\n if (\n store.currentRunId === request.input.runId &&\n currentRunEvents.length > 0\n ) {\n // Compact the events before storing (like SQLite does)\n const compactedEvents = compactEvents(currentRunEvents);\n store.historicRuns.push({\n threadId: request.threadId,\n runId: request.input.runId,\n agentId: request.agent.agentId ?? \"default\",\n parentRunId,\n events: compactedEvents,\n messages: Array.isArray(request.agent.messages)\n ? [...request.agent.messages]\n : [],\n createdAt: Date.now(),\n });\n }\n\n // Complete the run (see success-path note). Same run-id guard so a\n // superseded run's error teardown can't reset the newer run's state.\n if (store.currentRunId === request.input.runId) {\n store.currentEvents = null;\n store.currentRunId = null;\n store.agent = null;\n store.runSubject = null;\n store.stopRequested = false;\n store.isRunning = false;\n }\n runSubject.complete();\n nextSubject.complete();\n }\n };\n\n // Bridge previous events if they exist\n if (prevSubject) {\n prevSubject.subscribe({\n next: (e) => nextSubject.next(e),\n error: (err) => nextSubject.error(err),\n complete: () => {\n // Don't complete nextSubject here - it needs to stay open for new events\n },\n });\n }\n\n // Start the agent execution immediately (not lazily)\n runAgent();\n\n // Return the run subject (only agent events, no injected messages)\n return runSubject.asObservable();\n }\n\n connect(request: AgentRunnerConnectRequest): Observable<BaseEvent> {\n const store = GLOBAL_STORE.get(request.threadId);\n const connectionSubject = new ReplaySubject<BaseEvent>(Infinity);\n\n if (!store) {\n // No store means no events\n connectionSubject.complete();\n return connectionSubject.asObservable();\n }\n\n // Collect all historic events from memory\n const allHistoricEvents: BaseEvent[] = [];\n for (const run of store.historicRuns) {\n allHistoricEvents.push(...run.events);\n }\n\n // Apply compaction to all historic events together (like SQLite)\n const compactedEvents = compactEvents(allHistoricEvents);\n\n // Emit compacted events and track message IDs\n const emittedMessageIds = new Set<string>();\n for (const event of compactedEvents) {\n connectionSubject.next(event);\n if (\"messageId\" in event && typeof event.messageId === \"string\") {\n emittedMessageIds.add(event.messageId);\n }\n }\n\n // Bridge active run to connection if exists\n if (store.subject && (store.isRunning || store.stopRequested)) {\n store.subject.subscribe({\n next: (event) => {\n // Skip message events that we've already emitted from historic\n if (\n \"messageId\" in event &&\n typeof event.messageId === \"string\" &&\n emittedMessageIds.has(event.messageId)\n ) {\n return;\n }\n connectionSubject.next(event);\n },\n complete: () => connectionSubject.complete(),\n error: (err) => connectionSubject.error(err),\n });\n } else {\n // No active run, complete after historic events\n connectionSubject.complete();\n }\n\n return connectionSubject.asObservable();\n }\n\n isRunning(request: AgentRunnerIsRunningRequest): Promise<boolean> {\n const store = GLOBAL_STORE.get(request.threadId);\n return Promise.resolve(store?.isRunning ?? false);\n }\n\n stop(request: AgentRunnerStopRequest): Promise<boolean | undefined> {\n const store = GLOBAL_STORE.get(request.threadId);\n if (!store || !store.isRunning) {\n return Promise.resolve(false);\n }\n if (store.stopRequested) {\n return Promise.resolve(false);\n }\n\n store.stopRequested = true;\n store.isRunning = false;\n\n const agent = store.agent;\n if (!agent) {\n store.stopRequested = false;\n store.isRunning = false;\n return Promise.resolve(false);\n }\n\n try {\n agent.abortRun();\n return Promise.resolve(true);\n } catch (error) {\n console.error(\"Failed to abort agent run\", error);\n store.stopRequested = false;\n store.isRunning = true;\n return Promise.resolve(false);\n }\n }\n\n /**\n * Returns a summary of every thread that has been run through this runner.\n *\n * This powers the local-dev fallback for `GET /threads` when the Intelligence\n * platform is not configured. Each entry mirrors the shape of a platform\n * `ThreadRecord` so the HTTP handler can use the same response envelope.\n */\n listThreads(): InMemoryThread[] {\n const threads: InMemoryThread[] = [];\n for (const [threadId, store] of GLOBAL_STORE) {\n if (store.historicRuns.length === 0) continue;\n const firstRun = store.historicRuns[0]!;\n const lastRun = store.historicRuns[store.historicRuns.length - 1]!;\n threads.push({\n id: threadId,\n name: null,\n agentId: lastRun.agentId,\n organizationId: \"\",\n createdById: \"\",\n archived: false,\n createdAt: new Date(firstRun.createdAt).toISOString(),\n updatedAt: new Date(lastRun.createdAt).toISOString(),\n });\n }\n // Most recently updated first\n return threads.sort(\n (a, b) =>\n new Date(b.updatedAt).getTime() - new Date(a.updatedAt).getTime(),\n );\n }\n\n /**\n * Returns all messages for a thread, using the snapshot captured at the end\n * of the most recent run.\n *\n * This powers the local-dev fallback for `GET /threads/:threadId/messages`\n * when the Intelligence platform is not configured. The returned `Message[]`\n * objects come directly from the ag-ui agent, so their shape is compatible\n * with the Intelligence platform's `ThreadMessage` type.\n */\n getThreadMessages(threadId: string): Message[] {\n const store = GLOBAL_STORE.get(threadId);\n if (!store || store.historicRuns.length === 0) return [];\n // The last run's snapshot has the complete conversation history\n return store.historicRuns[store.historicRuns.length - 1]!.messages;\n }\n\n /**\n * Returns all AG-UI events for a thread, compacted across historic runs.\n *\n * Powers the local-dev fallback for `GET /threads/:threadId/events` when the\n * Intelligence platform is not configured. The compaction logic matches\n * the connection-replay path in {@link connect}, so the stream a\n * late-joining inspector sees matches what this method returns.\n */\n getThreadEvents(threadId: string): BaseEvent[] {\n const store = GLOBAL_STORE.get(threadId);\n if (!store || store.historicRuns.length === 0) return [];\n const all: BaseEvent[] = [];\n for (const run of store.historicRuns) all.push(...run.events);\n return compactEvents(all);\n }\n\n /**\n * Returns the agent state snapshot for a thread.\n *\n * Derived from the last `STATE_SNAPSHOT` in the compacted event stream. The\n * AG-UI `compactEvents` helper consolidates STATE_DELTA events and produces\n * a single trailing STATE_SNAPSHOT when state changes exist, so this is a\n * faithful view of state at the end of the most recent run.\n *\n * Returns `null` when the thread has never emitted a STATE_SNAPSHOT.\n */\n getThreadState(threadId: string): Record<string, unknown> | null {\n const events = this.getThreadEvents(threadId);\n // Walk backwards — the last snapshot wins.\n for (let i = events.length - 1; i >= 0; i--) {\n const event = events[i]!;\n if (event.type === EventType.STATE_SNAPSHOT) {\n const snapshot = (event as StateSnapshotEvent).snapshot;\n if (snapshot && typeof snapshot === \"object\") {\n return snapshot as Record<string, unknown>;\n }\n return null;\n }\n }\n return null;\n }\n\n /**\n * Clears all in-memory thread history.\n *\n * Powers the local-dev fallback for `POST /threads/clear`, letting consumers\n * (e.g. the demo's Clear button) reset to an empty thread list without\n * restarting the runtime. Intentionally not exposed on the Intelligence\n * platform path: there, thread history lives in a real database and must\n * not be wiped this way.\n */\n clearThreads(): void {\n GLOBAL_STORE.clear();\n }\n}\n"],"mappings":";;;;;;;;AAkDA,IAAM,qBAAN,MAAyB;CACvB,YAAY,AAAO,UAAkB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