@copilotkit/runtime 1.56.2 → 1.56.4-canary.1777529757

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 (203) hide show
  1. package/dist/agent/converters/tanstack.cjs +121 -25
  2. package/dist/agent/converters/tanstack.cjs.map +1 -1
  3. package/dist/agent/converters/tanstack.d.cts.map +1 -1
  4. package/dist/agent/converters/tanstack.d.mts.map +1 -1
  5. package/dist/agent/converters/tanstack.mjs +121 -25
  6. package/dist/agent/converters/tanstack.mjs.map +1 -1
  7. package/dist/graphql/resolvers/copilot.resolver.cjs +2 -1
  8. package/dist/graphql/resolvers/copilot.resolver.cjs.map +1 -1
  9. package/dist/graphql/resolvers/copilot.resolver.mjs +2 -1
  10. package/dist/graphql/resolvers/copilot.resolver.mjs.map +1 -1
  11. package/dist/graphql/resolvers/resolve-message-id.cjs +19 -0
  12. package/dist/graphql/resolvers/resolve-message-id.cjs.map +1 -0
  13. package/dist/graphql/resolvers/resolve-message-id.mjs +18 -0
  14. package/dist/graphql/resolvers/resolve-message-id.mjs.map +1 -0
  15. package/dist/lib/runtime/agent-integrations/langgraph/agent.cjs +8 -1
  16. package/dist/lib/runtime/agent-integrations/langgraph/agent.cjs.map +1 -1
  17. package/dist/lib/runtime/agent-integrations/langgraph/agent.d.cts.map +1 -1
  18. package/dist/lib/runtime/agent-integrations/langgraph/agent.d.mts.map +1 -1
  19. package/dist/lib/runtime/agent-integrations/langgraph/agent.mjs +8 -1
  20. package/dist/lib/runtime/agent-integrations/langgraph/agent.mjs.map +1 -1
  21. package/dist/lib/runtime/copilot-runtime.cjs +4 -2
  22. package/dist/lib/runtime/copilot-runtime.cjs.map +1 -1
  23. package/dist/lib/runtime/copilot-runtime.d.cts.map +1 -1
  24. package/dist/lib/runtime/copilot-runtime.d.mts.map +1 -1
  25. package/dist/lib/runtime/copilot-runtime.mjs +4 -2
  26. package/dist/lib/runtime/copilot-runtime.mjs.map +1 -1
  27. package/dist/package.cjs +7 -7
  28. package/dist/package.mjs +7 -7
  29. package/dist/v2/index.d.cts +2 -2
  30. package/dist/v2/index.d.mts +2 -2
  31. package/dist/v2/runtime/core/debug-event-bus.cjs +36 -0
  32. package/dist/v2/runtime/core/debug-event-bus.cjs.map +1 -0
  33. package/dist/v2/runtime/core/debug-event-bus.d.cts +19 -0
  34. package/dist/v2/runtime/core/debug-event-bus.d.cts.map +1 -0
  35. package/dist/v2/runtime/core/debug-event-bus.d.mts +19 -0
  36. package/dist/v2/runtime/core/debug-event-bus.d.mts.map +1 -0
  37. package/dist/v2/runtime/core/debug-event-bus.mjs +35 -0
  38. package/dist/v2/runtime/core/debug-event-bus.mjs.map +1 -0
  39. package/dist/v2/runtime/core/fetch-handler.cjs +8 -0
  40. package/dist/v2/runtime/core/fetch-handler.cjs.map +1 -1
  41. package/dist/v2/runtime/core/fetch-handler.d.cts.map +1 -1
  42. package/dist/v2/runtime/core/fetch-handler.d.mts.map +1 -1
  43. package/dist/v2/runtime/core/fetch-handler.mjs +8 -0
  44. package/dist/v2/runtime/core/fetch-handler.mjs.map +1 -1
  45. package/dist/v2/runtime/core/fetch-router.cjs +1 -0
  46. package/dist/v2/runtime/core/fetch-router.cjs.map +1 -1
  47. package/dist/v2/runtime/core/fetch-router.mjs +1 -0
  48. package/dist/v2/runtime/core/fetch-router.mjs.map +1 -1
  49. package/dist/v2/runtime/core/hooks.cjs.map +1 -1
  50. package/dist/v2/runtime/core/hooks.d.cts +2 -0
  51. package/dist/v2/runtime/core/hooks.d.cts.map +1 -1
  52. package/dist/v2/runtime/core/hooks.d.mts +2 -0
  53. package/dist/v2/runtime/core/hooks.d.mts.map +1 -1
  54. package/dist/v2/runtime/core/hooks.mjs.map +1 -1
  55. package/dist/v2/runtime/core/runtime.cjs +5 -0
  56. package/dist/v2/runtime/core/runtime.cjs.map +1 -1
  57. package/dist/v2/runtime/core/runtime.d.cts +5 -0
  58. package/dist/v2/runtime/core/runtime.d.cts.map +1 -1
  59. package/dist/v2/runtime/core/runtime.d.mts +5 -1
  60. package/dist/v2/runtime/core/runtime.d.mts.map +1 -1
  61. package/dist/v2/runtime/core/runtime.mjs +5 -0
  62. package/dist/v2/runtime/core/runtime.mjs.map +1 -1
  63. package/dist/v2/runtime/endpoints/express.cjs +5 -5
  64. package/dist/v2/runtime/endpoints/express.cjs.map +1 -1
  65. package/dist/v2/runtime/endpoints/express.mjs +5 -5
  66. package/dist/v2/runtime/endpoints/express.mjs.map +1 -1
  67. package/dist/v2/runtime/handlers/handle-connect.cjs +3 -2
  68. package/dist/v2/runtime/handlers/handle-connect.cjs.map +1 -1
  69. package/dist/v2/runtime/handlers/handle-connect.mjs +3 -2
  70. package/dist/v2/runtime/handlers/handle-connect.mjs.map +1 -1
  71. package/dist/v2/runtime/handlers/handle-debug-events.cjs +33 -0
  72. package/dist/v2/runtime/handlers/handle-debug-events.cjs.map +1 -0
  73. package/dist/v2/runtime/handlers/handle-debug-events.mjs +32 -0
  74. package/dist/v2/runtime/handlers/handle-debug-events.mjs.map +1 -0
  75. package/dist/v2/runtime/handlers/handle-run.cjs +1 -0
  76. package/dist/v2/runtime/handlers/handle-run.cjs.map +1 -1
  77. package/dist/v2/runtime/handlers/handle-run.mjs +1 -0
  78. package/dist/v2/runtime/handlers/handle-run.mjs.map +1 -1
  79. package/dist/v2/runtime/handlers/intelligence/connect.cjs +24 -4
  80. package/dist/v2/runtime/handlers/intelligence/connect.cjs.map +1 -1
  81. package/dist/v2/runtime/handlers/intelligence/connect.mjs +25 -5
  82. package/dist/v2/runtime/handlers/intelligence/connect.mjs.map +1 -1
  83. package/dist/v2/runtime/handlers/intelligence/run.cjs +111 -26
  84. package/dist/v2/runtime/handlers/intelligence/run.cjs.map +1 -1
  85. package/dist/v2/runtime/handlers/intelligence/run.mjs +111 -26
  86. package/dist/v2/runtime/handlers/intelligence/run.mjs.map +1 -1
  87. package/dist/v2/runtime/handlers/shared/intelligence-utils.cjs +7 -3
  88. package/dist/v2/runtime/handlers/shared/intelligence-utils.cjs.map +1 -1
  89. package/dist/v2/runtime/handlers/shared/intelligence-utils.mjs +7 -3
  90. package/dist/v2/runtime/handlers/shared/intelligence-utils.mjs.map +1 -1
  91. package/dist/v2/runtime/handlers/shared/resolve-intelligence-user.cjs +5 -1
  92. package/dist/v2/runtime/handlers/shared/resolve-intelligence-user.cjs.map +1 -1
  93. package/dist/v2/runtime/handlers/shared/resolve-intelligence-user.mjs +5 -1
  94. package/dist/v2/runtime/handlers/shared/resolve-intelligence-user.mjs.map +1 -1
  95. package/dist/v2/runtime/handlers/shared/sse-response.cjs +21 -1
  96. package/dist/v2/runtime/handlers/shared/sse-response.cjs.map +1 -1
  97. package/dist/v2/runtime/handlers/shared/sse-response.mjs +21 -1
  98. package/dist/v2/runtime/handlers/shared/sse-response.mjs.map +1 -1
  99. package/dist/v2/runtime/handlers/sse/connect.cjs +3 -1
  100. package/dist/v2/runtime/handlers/sse/connect.cjs.map +1 -1
  101. package/dist/v2/runtime/handlers/sse/connect.mjs +3 -1
  102. package/dist/v2/runtime/handlers/sse/connect.mjs.map +1 -1
  103. package/dist/v2/runtime/handlers/sse/run.cjs +3 -1
  104. package/dist/v2/runtime/handlers/sse/run.cjs.map +1 -1
  105. package/dist/v2/runtime/handlers/sse/run.mjs +3 -1
  106. package/dist/v2/runtime/handlers/sse/run.mjs.map +1 -1
  107. package/dist/v2/runtime/index.d.cts +1 -1
  108. package/dist/v2/runtime/index.d.mts +1 -2
  109. package/dist/v2/runtime/index.d.mts.map +1 -1
  110. package/dist/v2/runtime/intelligence-platform/client.cjs +6 -8
  111. package/dist/v2/runtime/intelligence-platform/client.cjs.map +1 -1
  112. package/dist/v2/runtime/intelligence-platform/client.d.cts +16 -21
  113. package/dist/v2/runtime/intelligence-platform/client.d.cts.map +1 -1
  114. package/dist/v2/runtime/intelligence-platform/client.d.mts +16 -21
  115. package/dist/v2/runtime/intelligence-platform/client.d.mts.map +1 -1
  116. package/dist/v2/runtime/intelligence-platform/client.mjs +6 -8
  117. package/dist/v2/runtime/intelligence-platform/client.mjs.map +1 -1
  118. package/dist/v2/runtime/runner/agent-runner.cjs.map +1 -1
  119. package/dist/v2/runtime/runner/agent-runner.d.cts +0 -1
  120. package/dist/v2/runtime/runner/agent-runner.d.cts.map +1 -1
  121. package/dist/v2/runtime/runner/agent-runner.d.mts +0 -1
  122. package/dist/v2/runtime/runner/agent-runner.d.mts.map +1 -1
  123. package/dist/v2/runtime/runner/agent-runner.mjs.map +1 -1
  124. package/dist/v2/runtime/runner/index.d.cts +1 -1
  125. package/dist/v2/runtime/runner/index.d.mts +1 -1
  126. package/dist/v2/runtime/runner/intelligence.cjs +47 -10
  127. package/dist/v2/runtime/runner/intelligence.cjs.map +1 -1
  128. package/dist/v2/runtime/runner/intelligence.d.cts +8 -1
  129. package/dist/v2/runtime/runner/intelligence.d.cts.map +1 -1
  130. package/dist/v2/runtime/runner/intelligence.d.mts +8 -1
  131. package/dist/v2/runtime/runner/intelligence.d.mts.map +1 -1
  132. package/dist/v2/runtime/runner/intelligence.mjs +47 -10
  133. package/dist/v2/runtime/runner/intelligence.mjs.map +1 -1
  134. package/dist/v2/runtime/telemetry/instance-created.cjs +33 -0
  135. package/dist/v2/runtime/telemetry/instance-created.cjs.map +1 -0
  136. package/dist/v2/runtime/telemetry/instance-created.mjs +33 -0
  137. package/dist/v2/runtime/telemetry/instance-created.mjs.map +1 -0
  138. package/dist/v2/runtime/telemetry/telemetry-client.cjs +1 -38
  139. package/dist/v2/runtime/telemetry/telemetry-client.cjs.map +1 -1
  140. package/dist/v2/runtime/telemetry/telemetry-client.mjs +1 -37
  141. package/dist/v2/runtime/telemetry/telemetry-client.mjs.map +1 -1
  142. package/package.json +8 -8
  143. package/src/agent/__tests__/agent-test-helpers.ts +31 -1
  144. package/src/agent/__tests__/converter-tanstack.test.ts +280 -0
  145. package/src/agent/converters/tanstack.ts +167 -10
  146. package/src/agents/langgraph/__tests__/event-source.test.ts +256 -0
  147. package/src/graphql/resolvers/__tests__/resolve-message-id.test.ts +25 -0
  148. package/src/graphql/resolvers/copilot.resolver.ts +2 -1
  149. package/src/graphql/resolvers/resolve-message-id.ts +14 -0
  150. package/src/lib/runtime/__tests__/handle-service-adapter.test.ts +108 -0
  151. package/src/lib/runtime/__tests__/retry-utils.test.ts +137 -0
  152. package/src/lib/runtime/agent-integrations/langgraph/__tests__/dispatch-event-filtering.test.ts +190 -0
  153. package/src/lib/runtime/agent-integrations/langgraph/agent.ts +8 -1
  154. package/src/lib/runtime/copilot-runtime.ts +20 -4
  155. package/src/lib/runtime/retry-utils.ts +41 -1
  156. package/src/v2/runtime/__tests__/express-fetch-bridge.test.ts +1 -1
  157. package/src/v2/runtime/__tests__/express-single-telemetry.integration.test.ts +65 -0
  158. package/src/v2/runtime/__tests__/express-telemetry.integration.test.ts +101 -0
  159. package/src/v2/runtime/__tests__/fetch-router.test.ts +22 -0
  160. package/src/v2/runtime/__tests__/handle-connect.test.ts +183 -23
  161. package/src/v2/runtime/__tests__/handle-run.test.ts +411 -33
  162. package/src/v2/runtime/__tests__/handle-threads.test.ts +66 -4
  163. package/src/v2/runtime/__tests__/hono-single-telemetry.integration.test.ts +46 -0
  164. package/src/v2/runtime/__tests__/hono-telemetry.integration.test.ts +99 -0
  165. package/src/v2/runtime/__tests__/integration/node-servers.integration.test.ts +19 -0
  166. package/src/v2/runtime/__tests__/integration/suites/debug-events.suite.ts +253 -0
  167. package/src/v2/runtime/__tests__/intelligence-run-telemetry.test.ts +194 -0
  168. package/src/v2/runtime/__tests__/runtime.test.ts +3 -1
  169. package/src/v2/runtime/__tests__/sse-response-telemetry.test.ts +108 -0
  170. package/src/v2/runtime/__tests__/telemetry.test.ts +0 -61
  171. package/src/v2/runtime/core/__tests__/debug-event-bus.test.ts +156 -0
  172. package/src/v2/runtime/core/debug-event-bus.ts +45 -0
  173. package/src/v2/runtime/core/fetch-handler.ts +7 -0
  174. package/src/v2/runtime/core/fetch-router.ts +11 -0
  175. package/src/v2/runtime/core/hooks.ts +2 -1
  176. package/src/v2/runtime/core/runtime.ts +12 -0
  177. package/src/v2/runtime/endpoints/express.ts +9 -3
  178. package/src/v2/runtime/handlers/__tests__/handle-debug-events.test.ts +176 -0
  179. package/src/v2/runtime/handlers/handle-connect.ts +2 -1
  180. package/src/v2/runtime/handlers/handle-debug-events.ts +52 -0
  181. package/src/v2/runtime/handlers/handle-run.ts +1 -0
  182. package/src/v2/runtime/handlers/intelligence/connect.ts +48 -11
  183. package/src/v2/runtime/handlers/intelligence/run.ts +162 -21
  184. package/src/v2/runtime/handlers/shared/intelligence-utils.ts +21 -1
  185. package/src/v2/runtime/handlers/shared/resolve-intelligence-user.ts +4 -1
  186. package/src/v2/runtime/handlers/shared/sse-response.ts +46 -0
  187. package/src/v2/runtime/handlers/sse/__tests__/sse-connect-agent-id.test.ts +71 -0
  188. package/src/v2/runtime/handlers/sse/connect.ts +6 -0
  189. package/src/v2/runtime/handlers/sse/run.ts +4 -0
  190. package/src/v2/runtime/intelligence-platform/__tests__/client.test.ts +33 -37
  191. package/src/v2/runtime/intelligence-platform/client.ts +37 -40
  192. package/src/v2/runtime/runner/__tests__/intelligence-runner.test.ts +66 -8
  193. package/src/v2/runtime/runner/agent-runner.ts +0 -1
  194. package/src/v2/runtime/runner/intelligence.ts +74 -15
  195. package/src/v2/runtime/telemetry/__tests__/instance-created.test.ts +96 -0
  196. package/src/v2/runtime/telemetry/instance-created.ts +44 -0
  197. package/src/v2/runtime/telemetry/telemetry-client.ts +1 -57
  198. package/dist/v2/runtime/intelligence-platform/index.d.mts +0 -2
  199. package/dist/v2/runtime/telemetry/utils.cjs +0 -15
  200. package/dist/v2/runtime/telemetry/utils.cjs.map +0 -1
  201. package/dist/v2/runtime/telemetry/utils.mjs +0 -14
  202. package/dist/v2/runtime/telemetry/utils.mjs.map +0 -1
  203. package/src/v2/runtime/telemetry/utils.ts +0 -15
@@ -0,0 +1 @@
1
+ {"version":3,"file":"handle-debug-events.cjs","names":[],"sources":["../../../../src/v2/runtime/handlers/handle-debug-events.ts"],"sourcesContent":["import { CopilotRuntimeLike } from \"../core/runtime\";\nimport { DebugEventEnvelope } from \"@copilotkit/shared\";\n\ninterface HandleDebugEventsParams {\n runtime: CopilotRuntimeLike;\n request: Request;\n}\n\nexport function handleDebugEvents({\n runtime,\n request,\n}: HandleDebugEventsParams): Response {\n if (process.env.NODE_ENV === \"production\") {\n return new Response(\"Not Found\", { status: 404 });\n }\n\n if (!runtime.debugEventBus) {\n return new Response(\"Debug event bus not available\", { status: 503 });\n }\n\n const bus = runtime.debugEventBus;\n const encoder = new TextEncoder();\n const stream = new TransformStream();\n const writer = stream.writable.getWriter();\n\n // Send an SSE comment immediately to flush response headers to the client.\n // Without this, some frameworks buffer the response until actual data is written,\n // leaving the client stuck in \"connecting\" state.\n writer.write(encoder.encode(\": connected\\n\\n\")).catch(() => {});\n\n const unsubscribe = bus.subscribe((envelope: DebugEventEnvelope) => {\n if (request.signal.aborted) return;\n const line = `data: ${JSON.stringify(envelope)}\\n\\n`;\n writer.write(encoder.encode(line)).catch(() => {\n // Client disconnected, will be cleaned up by abort handler.\n });\n });\n\n request.signal.addEventListener(\"abort\", () => {\n unsubscribe();\n writer.close().catch(() => {});\n });\n\n return new Response(stream.readable, {\n status: 200,\n headers: {\n \"Content-Type\": \"text/event-stream\",\n \"Cache-Control\": \"no-cache\",\n Connection: \"keep-alive\",\n },\n });\n}\n"],"mappings":";;;AAQA,SAAgB,kBAAkB,EAChC,SACA,WACoC;AACpC,KAAI,QAAQ,IAAI,aAAa,aAC3B,QAAO,IAAI,SAAS,aAAa,EAAE,QAAQ,KAAK,CAAC;AAGnD,KAAI,CAAC,QAAQ,cACX,QAAO,IAAI,SAAS,iCAAiC,EAAE,QAAQ,KAAK,CAAC;CAGvE,MAAM,MAAM,QAAQ;CACpB,MAAM,UAAU,IAAI,aAAa;CACjC,MAAM,SAAS,IAAI,iBAAiB;CACpC,MAAM,SAAS,OAAO,SAAS,WAAW;AAK1C,QAAO,MAAM,QAAQ,OAAO,kBAAkB,CAAC,CAAC,YAAY,GAAG;CAE/D,MAAM,cAAc,IAAI,WAAW,aAAiC;AAClE,MAAI,QAAQ,OAAO,QAAS;EAC5B,MAAM,OAAO,SAAS,KAAK,UAAU,SAAS,CAAC;AAC/C,SAAO,MAAM,QAAQ,OAAO,KAAK,CAAC,CAAC,YAAY,GAE7C;GACF;AAEF,SAAQ,OAAO,iBAAiB,eAAe;AAC7C,eAAa;AACb,SAAO,OAAO,CAAC,YAAY,GAAG;GAC9B;AAEF,QAAO,IAAI,SAAS,OAAO,UAAU;EACnC,QAAQ;EACR,SAAS;GACP,gBAAgB;GAChB,iBAAiB;GACjB,YAAY;GACb;EACF,CAAC"}
@@ -0,0 +1,32 @@
1
+ import "reflect-metadata";
2
+ //#region src/v2/runtime/handlers/handle-debug-events.ts
3
+ function handleDebugEvents({ runtime, request }) {
4
+ if (process.env.NODE_ENV === "production") return new Response("Not Found", { status: 404 });
5
+ if (!runtime.debugEventBus) return new Response("Debug event bus not available", { status: 503 });
6
+ const bus = runtime.debugEventBus;
7
+ const encoder = new TextEncoder();
8
+ const stream = new TransformStream();
9
+ const writer = stream.writable.getWriter();
10
+ writer.write(encoder.encode(": connected\n\n")).catch(() => {});
11
+ const unsubscribe = bus.subscribe((envelope) => {
12
+ if (request.signal.aborted) return;
13
+ const line = `data: ${JSON.stringify(envelope)}\n\n`;
14
+ writer.write(encoder.encode(line)).catch(() => {});
15
+ });
16
+ request.signal.addEventListener("abort", () => {
17
+ unsubscribe();
18
+ writer.close().catch(() => {});
19
+ });
20
+ return new Response(stream.readable, {
21
+ status: 200,
22
+ headers: {
23
+ "Content-Type": "text/event-stream",
24
+ "Cache-Control": "no-cache",
25
+ Connection: "keep-alive"
26
+ }
27
+ });
28
+ }
29
+
30
+ //#endregion
31
+ export { handleDebugEvents };
32
+ //# sourceMappingURL=handle-debug-events.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"handle-debug-events.mjs","names":[],"sources":["../../../../src/v2/runtime/handlers/handle-debug-events.ts"],"sourcesContent":["import { CopilotRuntimeLike } from \"../core/runtime\";\nimport { DebugEventEnvelope } from \"@copilotkit/shared\";\n\ninterface HandleDebugEventsParams {\n runtime: CopilotRuntimeLike;\n request: Request;\n}\n\nexport function handleDebugEvents({\n runtime,\n request,\n}: HandleDebugEventsParams): Response {\n if (process.env.NODE_ENV === \"production\") {\n return new Response(\"Not Found\", { status: 404 });\n }\n\n if (!runtime.debugEventBus) {\n return new Response(\"Debug event bus not available\", { status: 503 });\n }\n\n const bus = runtime.debugEventBus;\n const encoder = new TextEncoder();\n const stream = new TransformStream();\n const writer = stream.writable.getWriter();\n\n // Send an SSE comment immediately to flush response headers to the client.\n // Without this, some frameworks buffer the response until actual data is written,\n // leaving the client stuck in \"connecting\" state.\n writer.write(encoder.encode(\": connected\\n\\n\")).catch(() => {});\n\n const unsubscribe = bus.subscribe((envelope: DebugEventEnvelope) => {\n if (request.signal.aborted) return;\n const line = `data: ${JSON.stringify(envelope)}\\n\\n`;\n writer.write(encoder.encode(line)).catch(() => {\n // Client disconnected, will be cleaned up by abort handler.\n });\n });\n\n request.signal.addEventListener(\"abort\", () => {\n unsubscribe();\n writer.close().catch(() => {});\n });\n\n return new Response(stream.readable, {\n status: 200,\n headers: {\n \"Content-Type\": \"text/event-stream\",\n \"Cache-Control\": \"no-cache\",\n Connection: \"keep-alive\",\n },\n });\n}\n"],"mappings":";;AAQA,SAAgB,kBAAkB,EAChC,SACA,WACoC;AACpC,KAAI,QAAQ,IAAI,aAAa,aAC3B,QAAO,IAAI,SAAS,aAAa,EAAE,QAAQ,KAAK,CAAC;AAGnD,KAAI,CAAC,QAAQ,cACX,QAAO,IAAI,SAAS,iCAAiC,EAAE,QAAQ,KAAK,CAAC;CAGvE,MAAM,MAAM,QAAQ;CACpB,MAAM,UAAU,IAAI,aAAa;CACjC,MAAM,SAAS,IAAI,iBAAiB;CACpC,MAAM,SAAS,OAAO,SAAS,WAAW;AAK1C,QAAO,MAAM,QAAQ,OAAO,kBAAkB,CAAC,CAAC,YAAY,GAAG;CAE/D,MAAM,cAAc,IAAI,WAAW,aAAiC;AAClE,MAAI,QAAQ,OAAO,QAAS;EAC5B,MAAM,OAAO,SAAS,KAAK,UAAU,SAAS,CAAC;AAC/C,SAAO,MAAM,QAAQ,OAAO,KAAK,CAAC,CAAC,YAAY,GAE7C;GACF;AAEF,SAAQ,OAAO,iBAAiB,eAAe;AAC7C,eAAa;AACb,SAAO,OAAO,CAAC,YAAY,GAAG;GAC9B;AAEF,QAAO,IAAI,SAAS,OAAO,UAAU;EACnC,QAAQ;EACR,SAAS;GACP,gBAAgB;GAChB,iBAAiB;GACjB,YAAY;GACb;EACF,CAAC"}
@@ -44,6 +44,7 @@ async function handleRunAgent({ runtime, request, agentId }) {
44
44
  request,
45
45
  agent,
46
46
  input,
47
+ agentId,
47
48
  debug: runtime.debug,
48
49
  logger: runtime.debugLogger
49
50
  });
@@ -1 +1 @@
1
- {"version":3,"file":"handle-run.cjs","names":["cloneAgentForRequest","parseRunRequest","isIntelligenceRuntime","handleIntelligenceRun","handleSseRun"],"sources":["../../../../src/v2/runtime/handlers/handle-run.ts"],"sourcesContent":["import { isIntelligenceRuntime } from \"../core/runtime\";\nimport { telemetry } from \"../telemetry\";\nimport {\n cloneAgentForRequest,\n configureAgentForRequest,\n parseRunRequest,\n RunAgentParameters,\n} from \"./shared/agent-utils\";\nimport { handleIntelligenceRun } from \"./intelligence/run\";\nimport { handleSseRun } from \"./sse/run\";\n\nexport async function handleRunAgent({\n runtime,\n request,\n agentId,\n}: RunAgentParameters) {\n telemetry.capture(\"oss.runtime.copilot_request_created\", {\n \"cloud.guardrails.enabled\": false,\n requestType: \"run\",\n \"cloud.api_key_provided\": !!request.headers.get(\n \"x-copilotcloud-public-api-key\",\n ),\n ...(request.headers.get(\"x-copilotcloud-public-api-key\")\n ? {\n \"cloud.public_api_key\": request.headers.get(\n \"x-copilotcloud-public-api-key\",\n )!,\n }\n : {}),\n });\n\n try {\n const agent = await cloneAgentForRequest(runtime, agentId, request);\n if (agent instanceof Response) {\n return agent;\n }\n\n configureAgentForRequest({ runtime, request, agentId, agent });\n\n if (\n runtime.licenseChecker &&\n !runtime.licenseChecker.checkFeature(\"agents\")\n ) {\n console.warn(\n '[CopilotKit Runtime] Warning: \"agents\" feature is not licensed. Visit copilotkit.ai/pricing',\n );\n }\n\n const input = await parseRunRequest(request);\n if (input instanceof Response) {\n return input;\n }\n\n agent.setMessages(input.messages);\n agent.setState(input.state);\n agent.threadId = input.threadId;\n\n if (runtime.debug?.lifecycle && runtime.debugLogger) {\n runtime.debugLogger.debug(\n { agentName: agentId, threadId: input.threadId },\n \"Agent run started\",\n );\n }\n\n if (isIntelligenceRuntime(runtime)) {\n return handleIntelligenceRun({\n runtime,\n request,\n agentId,\n agent,\n input,\n });\n }\n\n return handleSseRun({\n runtime,\n request,\n agent,\n input,\n debug: runtime.debug,\n logger: runtime.debugLogger,\n });\n } catch (error) {\n console.error(\"Error running agent:\", error);\n console.error(\n \"Error stack:\",\n error instanceof Error ? error.stack : \"No stack trace\",\n );\n console.error(\"Error details:\", {\n name: error instanceof Error ? error.name : \"Unknown\",\n message: error instanceof Error ? error.message : String(error),\n cause: error instanceof Error ? error.cause : undefined,\n });\n\n return new Response(\n JSON.stringify({\n error: \"Failed to run agent\",\n message: error instanceof Error ? error.message : \"Unknown error\",\n }),\n {\n status: 500,\n headers: { \"Content-Type\": \"application/json\" },\n },\n );\n }\n}\n"],"mappings":";;;;;;;;AAWA,eAAsB,eAAe,EACnC,SACA,SACA,WACqB;AACrB,kCAAU,QAAQ,uCAAuC;EACvD,4BAA4B;EAC5B,aAAa;EACb,0BAA0B,CAAC,CAAC,QAAQ,QAAQ,IAC1C,gCACD;EACD,GAAI,QAAQ,QAAQ,IAAI,gCAAgC,GACpD,EACE,wBAAwB,QAAQ,QAAQ,IACtC,gCACD,EACF,GACD,EAAE;EACP,CAAC;AAEF,KAAI;EACF,MAAM,QAAQ,MAAMA,yCAAqB,SAAS,SAAS,QAAQ;AACnE,MAAI,iBAAiB,SACnB,QAAO;AAGT,+CAAyB;GAAE;GAAS;GAAS;GAAS;GAAO,CAAC;AAE9D,MACE,QAAQ,kBACR,CAAC,QAAQ,eAAe,aAAa,SAAS,CAE9C,SAAQ,KACN,gGACD;EAGH,MAAM,QAAQ,MAAMC,oCAAgB,QAAQ;AAC5C,MAAI,iBAAiB,SACnB,QAAO;AAGT,QAAM,YAAY,MAAM,SAAS;AACjC,QAAM,SAAS,MAAM,MAAM;AAC3B,QAAM,WAAW,MAAM;AAEvB,MAAI,QAAQ,OAAO,aAAa,QAAQ,YACtC,SAAQ,YAAY,MAClB;GAAE,WAAW;GAAS,UAAU,MAAM;GAAU,EAChD,oBACD;AAGH,MAAIC,sCAAsB,QAAQ,CAChC,QAAOC,kCAAsB;GAC3B;GACA;GACA;GACA;GACA;GACD,CAAC;AAGJ,SAAOC,2BAAa;GAClB;GACA;GACA;GACA;GACA,OAAO,QAAQ;GACf,QAAQ,QAAQ;GACjB,CAAC;UACK,OAAO;AACd,UAAQ,MAAM,wBAAwB,MAAM;AAC5C,UAAQ,MACN,gBACA,iBAAiB,QAAQ,MAAM,QAAQ,iBACxC;AACD,UAAQ,MAAM,kBAAkB;GAC9B,MAAM,iBAAiB,QAAQ,MAAM,OAAO;GAC5C,SAAS,iBAAiB,QAAQ,MAAM,UAAU,OAAO,MAAM;GAC/D,OAAO,iBAAiB,QAAQ,MAAM,QAAQ;GAC/C,CAAC;AAEF,SAAO,IAAI,SACT,KAAK,UAAU;GACb,OAAO;GACP,SAAS,iBAAiB,QAAQ,MAAM,UAAU;GACnD,CAAC,EACF;GACE,QAAQ;GACR,SAAS,EAAE,gBAAgB,oBAAoB;GAChD,CACF"}
1
+ {"version":3,"file":"handle-run.cjs","names":["cloneAgentForRequest","parseRunRequest","isIntelligenceRuntime","handleIntelligenceRun","handleSseRun"],"sources":["../../../../src/v2/runtime/handlers/handle-run.ts"],"sourcesContent":["import { isIntelligenceRuntime } from \"../core/runtime\";\nimport { telemetry } from \"../telemetry\";\nimport {\n cloneAgentForRequest,\n configureAgentForRequest,\n parseRunRequest,\n RunAgentParameters,\n} from \"./shared/agent-utils\";\nimport { handleIntelligenceRun } from \"./intelligence/run\";\nimport { handleSseRun } from \"./sse/run\";\n\nexport async function handleRunAgent({\n runtime,\n request,\n agentId,\n}: RunAgentParameters) {\n telemetry.capture(\"oss.runtime.copilot_request_created\", {\n \"cloud.guardrails.enabled\": false,\n requestType: \"run\",\n \"cloud.api_key_provided\": !!request.headers.get(\n \"x-copilotcloud-public-api-key\",\n ),\n ...(request.headers.get(\"x-copilotcloud-public-api-key\")\n ? {\n \"cloud.public_api_key\": request.headers.get(\n \"x-copilotcloud-public-api-key\",\n )!,\n }\n : {}),\n });\n\n try {\n const agent = await cloneAgentForRequest(runtime, agentId, request);\n if (agent instanceof Response) {\n return agent;\n }\n\n configureAgentForRequest({ runtime, request, agentId, agent });\n\n if (\n runtime.licenseChecker &&\n !runtime.licenseChecker.checkFeature(\"agents\")\n ) {\n console.warn(\n '[CopilotKit Runtime] Warning: \"agents\" feature is not licensed. Visit copilotkit.ai/pricing',\n );\n }\n\n const input = await parseRunRequest(request);\n if (input instanceof Response) {\n return input;\n }\n\n agent.setMessages(input.messages);\n agent.setState(input.state);\n agent.threadId = input.threadId;\n\n if (runtime.debug?.lifecycle && runtime.debugLogger) {\n runtime.debugLogger.debug(\n { agentName: agentId, threadId: input.threadId },\n \"Agent run started\",\n );\n }\n\n if (isIntelligenceRuntime(runtime)) {\n return handleIntelligenceRun({\n runtime,\n request,\n agentId,\n agent,\n input,\n });\n }\n\n return handleSseRun({\n runtime,\n request,\n agent,\n input,\n agentId,\n debug: runtime.debug,\n logger: runtime.debugLogger,\n });\n } catch (error) {\n console.error(\"Error running agent:\", error);\n console.error(\n \"Error stack:\",\n error instanceof Error ? error.stack : \"No stack trace\",\n );\n console.error(\"Error details:\", {\n name: error instanceof Error ? error.name : \"Unknown\",\n message: error instanceof Error ? error.message : String(error),\n cause: error instanceof Error ? error.cause : undefined,\n });\n\n return new Response(\n JSON.stringify({\n error: \"Failed to run agent\",\n message: error instanceof Error ? error.message : \"Unknown error\",\n }),\n {\n status: 500,\n headers: { \"Content-Type\": \"application/json\" },\n },\n );\n }\n}\n"],"mappings":";;;;;;;;AAWA,eAAsB,eAAe,EACnC,SACA,SACA,WACqB;AACrB,kCAAU,QAAQ,uCAAuC;EACvD,4BAA4B;EAC5B,aAAa;EACb,0BAA0B,CAAC,CAAC,QAAQ,QAAQ,IAC1C,gCACD;EACD,GAAI,QAAQ,QAAQ,IAAI,gCAAgC,GACpD,EACE,wBAAwB,QAAQ,QAAQ,IACtC,gCACD,EACF,GACD,EAAE;EACP,CAAC;AAEF,KAAI;EACF,MAAM,QAAQ,MAAMA,yCAAqB,SAAS,SAAS,QAAQ;AACnE,MAAI,iBAAiB,SACnB,QAAO;AAGT,+CAAyB;GAAE;GAAS;GAAS;GAAS;GAAO,CAAC;AAE9D,MACE,QAAQ,kBACR,CAAC,QAAQ,eAAe,aAAa,SAAS,CAE9C,SAAQ,KACN,gGACD;EAGH,MAAM,QAAQ,MAAMC,oCAAgB,QAAQ;AAC5C,MAAI,iBAAiB,SACnB,QAAO;AAGT,QAAM,YAAY,MAAM,SAAS;AACjC,QAAM,SAAS,MAAM,MAAM;AAC3B,QAAM,WAAW,MAAM;AAEvB,MAAI,QAAQ,OAAO,aAAa,QAAQ,YACtC,SAAQ,YAAY,MAClB;GAAE,WAAW;GAAS,UAAU,MAAM;GAAU,EAChD,oBACD;AAGH,MAAIC,sCAAsB,QAAQ,CAChC,QAAOC,kCAAsB;GAC3B;GACA;GACA;GACA;GACA;GACD,CAAC;AAGJ,SAAOC,2BAAa;GAClB;GACA;GACA;GACA;GACA;GACA,OAAO,QAAQ;GACf,QAAQ,QAAQ;GACjB,CAAC;UACK,OAAO;AACd,UAAQ,MAAM,wBAAwB,MAAM;AAC5C,UAAQ,MACN,gBACA,iBAAiB,QAAQ,MAAM,QAAQ,iBACxC;AACD,UAAQ,MAAM,kBAAkB;GAC9B,MAAM,iBAAiB,QAAQ,MAAM,OAAO;GAC5C,SAAS,iBAAiB,QAAQ,MAAM,UAAU,OAAO,MAAM;GAC/D,OAAO,iBAAiB,QAAQ,MAAM,QAAQ;GAC/C,CAAC;AAEF,SAAO,IAAI,SACT,KAAK,UAAU;GACb,OAAO;GACP,SAAS,iBAAiB,QAAQ,MAAM,UAAU;GACnD,CAAC,EACF;GACE,QAAQ;GACR,SAAS,EAAE,gBAAgB,oBAAoB;GAChD,CACF"}
@@ -44,6 +44,7 @@ async function handleRunAgent({ runtime, request, agentId }) {
44
44
  request,
45
45
  agent,
46
46
  input,
47
+ agentId,
47
48
  debug: runtime.debug,
48
49
  logger: runtime.debugLogger
49
50
  });
@@ -1 +1 @@
1
- {"version":3,"file":"handle-run.mjs","names":[],"sources":["../../../../src/v2/runtime/handlers/handle-run.ts"],"sourcesContent":["import { isIntelligenceRuntime } from \"../core/runtime\";\nimport { telemetry } from \"../telemetry\";\nimport {\n cloneAgentForRequest,\n configureAgentForRequest,\n parseRunRequest,\n RunAgentParameters,\n} from \"./shared/agent-utils\";\nimport { handleIntelligenceRun } from \"./intelligence/run\";\nimport { handleSseRun } from \"./sse/run\";\n\nexport async function handleRunAgent({\n runtime,\n request,\n agentId,\n}: RunAgentParameters) {\n telemetry.capture(\"oss.runtime.copilot_request_created\", {\n \"cloud.guardrails.enabled\": false,\n requestType: \"run\",\n \"cloud.api_key_provided\": !!request.headers.get(\n \"x-copilotcloud-public-api-key\",\n ),\n ...(request.headers.get(\"x-copilotcloud-public-api-key\")\n ? {\n \"cloud.public_api_key\": request.headers.get(\n \"x-copilotcloud-public-api-key\",\n )!,\n }\n : {}),\n });\n\n try {\n const agent = await cloneAgentForRequest(runtime, agentId, request);\n if (agent instanceof Response) {\n return agent;\n }\n\n configureAgentForRequest({ runtime, request, agentId, agent });\n\n if (\n runtime.licenseChecker &&\n !runtime.licenseChecker.checkFeature(\"agents\")\n ) {\n console.warn(\n '[CopilotKit Runtime] Warning: \"agents\" feature is not licensed. Visit copilotkit.ai/pricing',\n );\n }\n\n const input = await parseRunRequest(request);\n if (input instanceof Response) {\n return input;\n }\n\n agent.setMessages(input.messages);\n agent.setState(input.state);\n agent.threadId = input.threadId;\n\n if (runtime.debug?.lifecycle && runtime.debugLogger) {\n runtime.debugLogger.debug(\n { agentName: agentId, threadId: input.threadId },\n \"Agent run started\",\n );\n }\n\n if (isIntelligenceRuntime(runtime)) {\n return handleIntelligenceRun({\n runtime,\n request,\n agentId,\n agent,\n input,\n });\n }\n\n return handleSseRun({\n runtime,\n request,\n agent,\n input,\n debug: runtime.debug,\n logger: runtime.debugLogger,\n });\n } catch (error) {\n console.error(\"Error running agent:\", error);\n console.error(\n \"Error stack:\",\n error instanceof Error ? error.stack : \"No stack trace\",\n );\n console.error(\"Error details:\", {\n name: error instanceof Error ? error.name : \"Unknown\",\n message: error instanceof Error ? error.message : String(error),\n cause: error instanceof Error ? error.cause : undefined,\n });\n\n return new Response(\n JSON.stringify({\n error: \"Failed to run agent\",\n message: error instanceof Error ? error.message : \"Unknown error\",\n }),\n {\n status: 500,\n headers: { \"Content-Type\": \"application/json\" },\n },\n );\n }\n}\n"],"mappings":";;;;;;;;AAWA,eAAsB,eAAe,EACnC,SACA,SACA,WACqB;AACrB,WAAU,QAAQ,uCAAuC;EACvD,4BAA4B;EAC5B,aAAa;EACb,0BAA0B,CAAC,CAAC,QAAQ,QAAQ,IAC1C,gCACD;EACD,GAAI,QAAQ,QAAQ,IAAI,gCAAgC,GACpD,EACE,wBAAwB,QAAQ,QAAQ,IACtC,gCACD,EACF,GACD,EAAE;EACP,CAAC;AAEF,KAAI;EACF,MAAM,QAAQ,MAAM,qBAAqB,SAAS,SAAS,QAAQ;AACnE,MAAI,iBAAiB,SACnB,QAAO;AAGT,2BAAyB;GAAE;GAAS;GAAS;GAAS;GAAO,CAAC;AAE9D,MACE,QAAQ,kBACR,CAAC,QAAQ,eAAe,aAAa,SAAS,CAE9C,SAAQ,KACN,gGACD;EAGH,MAAM,QAAQ,MAAM,gBAAgB,QAAQ;AAC5C,MAAI,iBAAiB,SACnB,QAAO;AAGT,QAAM,YAAY,MAAM,SAAS;AACjC,QAAM,SAAS,MAAM,MAAM;AAC3B,QAAM,WAAW,MAAM;AAEvB,MAAI,QAAQ,OAAO,aAAa,QAAQ,YACtC,SAAQ,YAAY,MAClB;GAAE,WAAW;GAAS,UAAU,MAAM;GAAU,EAChD,oBACD;AAGH,MAAI,sBAAsB,QAAQ,CAChC,QAAO,sBAAsB;GAC3B;GACA;GACA;GACA;GACA;GACD,CAAC;AAGJ,SAAO,aAAa;GAClB;GACA;GACA;GACA;GACA,OAAO,QAAQ;GACf,QAAQ,QAAQ;GACjB,CAAC;UACK,OAAO;AACd,UAAQ,MAAM,wBAAwB,MAAM;AAC5C,UAAQ,MACN,gBACA,iBAAiB,QAAQ,MAAM,QAAQ,iBACxC;AACD,UAAQ,MAAM,kBAAkB;GAC9B,MAAM,iBAAiB,QAAQ,MAAM,OAAO;GAC5C,SAAS,iBAAiB,QAAQ,MAAM,UAAU,OAAO,MAAM;GAC/D,OAAO,iBAAiB,QAAQ,MAAM,QAAQ;GAC/C,CAAC;AAEF,SAAO,IAAI,SACT,KAAK,UAAU;GACb,OAAO;GACP,SAAS,iBAAiB,QAAQ,MAAM,UAAU;GACnD,CAAC,EACF;GACE,QAAQ;GACR,SAAS,EAAE,gBAAgB,oBAAoB;GAChD,CACF"}
1
+ {"version":3,"file":"handle-run.mjs","names":[],"sources":["../../../../src/v2/runtime/handlers/handle-run.ts"],"sourcesContent":["import { isIntelligenceRuntime } from \"../core/runtime\";\nimport { telemetry } from \"../telemetry\";\nimport {\n cloneAgentForRequest,\n configureAgentForRequest,\n parseRunRequest,\n RunAgentParameters,\n} from \"./shared/agent-utils\";\nimport { handleIntelligenceRun } from \"./intelligence/run\";\nimport { handleSseRun } from \"./sse/run\";\n\nexport async function handleRunAgent({\n runtime,\n request,\n agentId,\n}: RunAgentParameters) {\n telemetry.capture(\"oss.runtime.copilot_request_created\", {\n \"cloud.guardrails.enabled\": false,\n requestType: \"run\",\n \"cloud.api_key_provided\": !!request.headers.get(\n \"x-copilotcloud-public-api-key\",\n ),\n ...(request.headers.get(\"x-copilotcloud-public-api-key\")\n ? {\n \"cloud.public_api_key\": request.headers.get(\n \"x-copilotcloud-public-api-key\",\n )!,\n }\n : {}),\n });\n\n try {\n const agent = await cloneAgentForRequest(runtime, agentId, request);\n if (agent instanceof Response) {\n return agent;\n }\n\n configureAgentForRequest({ runtime, request, agentId, agent });\n\n if (\n runtime.licenseChecker &&\n !runtime.licenseChecker.checkFeature(\"agents\")\n ) {\n console.warn(\n '[CopilotKit Runtime] Warning: \"agents\" feature is not licensed. Visit copilotkit.ai/pricing',\n );\n }\n\n const input = await parseRunRequest(request);\n if (input instanceof Response) {\n return input;\n }\n\n agent.setMessages(input.messages);\n agent.setState(input.state);\n agent.threadId = input.threadId;\n\n if (runtime.debug?.lifecycle && runtime.debugLogger) {\n runtime.debugLogger.debug(\n { agentName: agentId, threadId: input.threadId },\n \"Agent run started\",\n );\n }\n\n if (isIntelligenceRuntime(runtime)) {\n return handleIntelligenceRun({\n runtime,\n request,\n agentId,\n agent,\n input,\n });\n }\n\n return handleSseRun({\n runtime,\n request,\n agent,\n input,\n agentId,\n debug: runtime.debug,\n logger: runtime.debugLogger,\n });\n } catch (error) {\n console.error(\"Error running agent:\", error);\n console.error(\n \"Error stack:\",\n error instanceof Error ? error.stack : \"No stack trace\",\n );\n console.error(\"Error details:\", {\n name: error instanceof Error ? error.name : \"Unknown\",\n message: error instanceof Error ? error.message : String(error),\n cause: error instanceof Error ? error.cause : undefined,\n });\n\n return new Response(\n JSON.stringify({\n error: \"Failed to run agent\",\n message: error instanceof Error ? error.message : \"Unknown error\",\n }),\n {\n status: 500,\n headers: { \"Content-Type\": \"application/json\" },\n },\n );\n }\n}\n"],"mappings":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AAEF,SAAO,IAAI,SACT,KAAK,UAAU;GACb,OAAO;GACP,SAAS,iBAAiB,QAAQ,MAAM,UAAU;GACnD,CAAC,EACF;GACE,QAAQ;GACR,SAAS,EAAE,gBAAgB,oBAAoB;GAChD,CACF"}
@@ -4,7 +4,16 @@ const require_intelligence_utils = require('../shared/intelligence-utils.cjs');
4
4
  const require_resolve_intelligence_user = require('../shared/resolve-intelligence-user.cjs');
5
5
 
6
6
  //#region src/v2/runtime/handlers/intelligence/connect.ts
7
- async function handleIntelligenceConnect({ runtime, request, threadId, lastSeenEventId }) {
7
+ /**
8
+ * Builds browser-facing realtime connection metadata owned by the runtime.
9
+ */
10
+ function buildRealtimeConnectionInfo(params) {
11
+ return {
12
+ clientUrl: params.clientUrl,
13
+ topic: `thread:${params.threadId}`
14
+ };
15
+ }
16
+ async function handleIntelligenceConnect({ runtime, request, agentId, threadId }) {
8
17
  if (!runtime.intelligence) return Response.json({
9
18
  error: "Intelligence not configured",
10
19
  message: "Intelligence mode requires a CopilotKitIntelligence"
@@ -18,15 +27,26 @@ async function handleIntelligenceConnect({ runtime, request, threadId, lastSeenE
18
27
  const result = await runtime.intelligence.ɵconnectThread({
19
28
  threadId,
20
29
  userId: user.id,
21
- lastSeenEventId
30
+ agentId
22
31
  });
23
32
  if (result === null) return new Response(null, { status: 204 });
24
- return Response.json(result, { headers: {
33
+ return Response.json({
34
+ threadId: result.threadId,
35
+ joinToken: result.joinToken,
36
+ realtime: buildRealtimeConnectionInfo({
37
+ clientUrl: runtime.intelligence.ɵgetClientWsUrl(),
38
+ threadId: result.threadId
39
+ })
40
+ }, { headers: {
25
41
  "Cache-Control": "no-cache",
26
42
  Connection: "keep-alive"
27
43
  } });
28
44
  } catch (error) {
29
- if (require_intelligence_utils.isPlatformNotFoundError(error)) return new Response(null, { status: 204 });
45
+ const status = require_intelligence_utils.getPlatformErrorStatus(error);
46
+ if (status === 400 || status === 401 || status === 403 || status === 404 || status === 409) return Response.json({
47
+ error: "Connect request rejected",
48
+ message: error instanceof Error ? error.message : "Intelligence platform rejected the connect request"
49
+ }, { status });
30
50
  console.error("Connect plan not available:", error);
31
51
  return Response.json({ error: "Connect plan not available" }, { status: 404 });
32
52
  }
@@ -1 +1 @@
1
- {"version":3,"file":"connect.cjs","names":["resolveIntelligenceUser","isHandlerResponse","isPlatformNotFoundError"],"sources":["../../../../../src/v2/runtime/handlers/intelligence/connect.ts"],"sourcesContent":["import { CopilotIntelligenceRuntimeLike } from \"../../core/runtime\";\nimport { isPlatformNotFoundError } from \"../shared/intelligence-utils\";\nimport { resolveIntelligenceUser } from \"../shared/resolve-intelligence-user\";\nimport { isHandlerResponse } from \"../shared/json-response\";\n\ninterface HandleIntelligenceConnectParams {\n runtime: CopilotIntelligenceRuntimeLike;\n request: Request;\n threadId: string;\n lastSeenEventId: string | null;\n}\n\nexport async function handleIntelligenceConnect({\n runtime,\n request,\n threadId,\n lastSeenEventId,\n}: HandleIntelligenceConnectParams): Promise<Response> {\n if (!runtime.intelligence) {\n return Response.json(\n {\n error: \"Intelligence not configured\",\n message: \"Intelligence mode requires a CopilotKitIntelligence\",\n },\n { status: 500 },\n );\n }\n\n try {\n const user = await resolveIntelligenceUser({ runtime, request });\n if (isHandlerResponse(user)) {\n return user;\n }\n\n const result = await runtime.intelligence.ɵconnectThread({\n threadId,\n userId: user.id,\n lastSeenEventId,\n });\n\n if (result === null) {\n return new Response(null, {\n status: 204,\n });\n }\n\n return Response.json(result, {\n headers: { \"Cache-Control\": \"no-cache\", Connection: \"keep-alive\" },\n });\n } catch (error) {\n if (isPlatformNotFoundError(error)) {\n return new Response(null, {\n status: 204,\n });\n }\n\n console.error(\"Connect plan not available:\", error);\n return Response.json(\n {\n error: \"Connect plan not available\",\n },\n { status: 404 },\n );\n }\n}\n"],"mappings":";;;;;;AAYA,eAAsB,0BAA0B,EAC9C,SACA,SACA,UACA,mBACqD;AACrD,KAAI,CAAC,QAAQ,aACX,QAAO,SAAS,KACd;EACE,OAAO;EACP,SAAS;EACV,EACD,EAAE,QAAQ,KAAK,CAChB;AAGH,KAAI;EACF,MAAM,OAAO,MAAMA,0DAAwB;GAAE;GAAS;GAAS,CAAC;AAChE,MAAIC,wCAAkB,KAAK,CACzB,QAAO;EAGT,MAAM,SAAS,MAAM,QAAQ,aAAa,eAAe;GACvD;GACA,QAAQ,KAAK;GACb;GACD,CAAC;AAEF,MAAI,WAAW,KACb,QAAO,IAAI,SAAS,MAAM,EACxB,QAAQ,KACT,CAAC;AAGJ,SAAO,SAAS,KAAK,QAAQ,EAC3B,SAAS;GAAE,iBAAiB;GAAY,YAAY;GAAc,EACnE,CAAC;UACK,OAAO;AACd,MAAIC,mDAAwB,MAAM,CAChC,QAAO,IAAI,SAAS,MAAM,EACxB,QAAQ,KACT,CAAC;AAGJ,UAAQ,MAAM,+BAA+B,MAAM;AACnD,SAAO,SAAS,KACd,EACE,OAAO,8BACR,EACD,EAAE,QAAQ,KAAK,CAChB"}
1
+ {"version":3,"file":"connect.cjs","names":["resolveIntelligenceUser","isHandlerResponse","getPlatformErrorStatus"],"sources":["../../../../../src/v2/runtime/handlers/intelligence/connect.ts"],"sourcesContent":["import { CopilotIntelligenceRuntimeLike } from \"../../core/runtime\";\nimport { getPlatformErrorStatus } from \"../shared/intelligence-utils\";\nimport { resolveIntelligenceUser } from \"../shared/resolve-intelligence-user\";\nimport { isHandlerResponse } from \"../shared/json-response\";\n\n/**\n * Builds browser-facing realtime connection metadata owned by the runtime.\n */\nfunction buildRealtimeConnectionInfo(params: {\n clientUrl: string;\n threadId: string;\n}): { clientUrl: string; topic: string } {\n return {\n clientUrl: params.clientUrl,\n topic: `thread:${params.threadId}`,\n };\n}\n\ninterface HandleIntelligenceConnectParams {\n runtime: CopilotIntelligenceRuntimeLike;\n request: Request;\n agentId: string;\n threadId: string;\n}\n\nexport async function handleIntelligenceConnect({\n runtime,\n request,\n agentId,\n threadId,\n}: HandleIntelligenceConnectParams): Promise<Response> {\n if (!runtime.intelligence) {\n return Response.json(\n {\n error: \"Intelligence not configured\",\n message: \"Intelligence mode requires a CopilotKitIntelligence\",\n },\n { status: 500 },\n );\n }\n\n try {\n const user = await resolveIntelligenceUser({ runtime, request });\n if (isHandlerResponse(user)) {\n return user;\n }\n\n const result = await runtime.intelligence.ɵconnectThread({\n threadId,\n userId: user.id,\n agentId,\n });\n\n if (result === null) {\n return new Response(null, {\n status: 204,\n });\n }\n\n return Response.json(\n {\n threadId: result.threadId,\n joinToken: result.joinToken,\n realtime: buildRealtimeConnectionInfo({\n clientUrl: runtime.intelligence.ɵgetClientWsUrl(),\n threadId: result.threadId,\n }),\n },\n {\n headers: { \"Cache-Control\": \"no-cache\", Connection: \"keep-alive\" },\n },\n );\n } catch (error) {\n const status = getPlatformErrorStatus(error);\n if (\n status === 400 ||\n status === 401 ||\n status === 403 ||\n status === 404 ||\n status === 409\n ) {\n return Response.json(\n {\n error: \"Connect request rejected\",\n message:\n error instanceof Error\n ? error.message\n : \"Intelligence platform rejected the connect request\",\n },\n { status },\n );\n }\n\n console.error(\"Connect plan not available:\", error);\n return Response.json(\n {\n error: \"Connect plan not available\",\n },\n { status: 404 },\n );\n }\n}\n"],"mappings":";;;;;;;;;AAQA,SAAS,4BAA4B,QAGI;AACvC,QAAO;EACL,WAAW,OAAO;EAClB,OAAO,UAAU,OAAO;EACzB;;AAUH,eAAsB,0BAA0B,EAC9C,SACA,SACA,SACA,YACqD;AACrD,KAAI,CAAC,QAAQ,aACX,QAAO,SAAS,KACd;EACE,OAAO;EACP,SAAS;EACV,EACD,EAAE,QAAQ,KAAK,CAChB;AAGH,KAAI;EACF,MAAM,OAAO,MAAMA,0DAAwB;GAAE;GAAS;GAAS,CAAC;AAChE,MAAIC,wCAAkB,KAAK,CACzB,QAAO;EAGT,MAAM,SAAS,MAAM,QAAQ,aAAa,eAAe;GACvD;GACA,QAAQ,KAAK;GACb;GACD,CAAC;AAEF,MAAI,WAAW,KACb,QAAO,IAAI,SAAS,MAAM,EACxB,QAAQ,KACT,CAAC;AAGJ,SAAO,SAAS,KACd;GACE,UAAU,OAAO;GACjB,WAAW,OAAO;GAClB,UAAU,4BAA4B;IACpC,WAAW,QAAQ,aAAa,iBAAiB;IACjD,UAAU,OAAO;IAClB,CAAC;GACH,EACD,EACE,SAAS;GAAE,iBAAiB;GAAY,YAAY;GAAc,EACnE,CACF;UACM,OAAO;EACd,MAAM,SAASC,kDAAuB,MAAM;AAC5C,MACE,WAAW,OACX,WAAW,OACX,WAAW,OACX,WAAW,OACX,WAAW,IAEX,QAAO,SAAS,KACd;GACE,OAAO;GACP,SACE,iBAAiB,QACb,MAAM,UACN;GACP,EACD,EAAE,QAAQ,CACX;AAGH,UAAQ,MAAM,+BAA+B,MAAM;AACnD,SAAO,SAAS,KACd,EACE,OAAO,8BACR,EACD,EAAE,QAAQ,KAAK,CAChB"}
@@ -1,10 +1,19 @@
1
1
  import "reflect-metadata";
2
2
  import { isHandlerResponse } from "../shared/json-response.mjs";
3
- import { isPlatformNotFoundError } from "../shared/intelligence-utils.mjs";
3
+ import { getPlatformErrorStatus } from "../shared/intelligence-utils.mjs";
4
4
  import { resolveIntelligenceUser } from "../shared/resolve-intelligence-user.mjs";
5
5
 
6
6
  //#region src/v2/runtime/handlers/intelligence/connect.ts
7
- async function handleIntelligenceConnect({ runtime, request, threadId, lastSeenEventId }) {
7
+ /**
8
+ * Builds browser-facing realtime connection metadata owned by the runtime.
9
+ */
10
+ function buildRealtimeConnectionInfo(params) {
11
+ return {
12
+ clientUrl: params.clientUrl,
13
+ topic: `thread:${params.threadId}`
14
+ };
15
+ }
16
+ async function handleIntelligenceConnect({ runtime, request, agentId, threadId }) {
8
17
  if (!runtime.intelligence) return Response.json({
9
18
  error: "Intelligence not configured",
10
19
  message: "Intelligence mode requires a CopilotKitIntelligence"
@@ -18,15 +27,26 @@ async function handleIntelligenceConnect({ runtime, request, threadId, lastSeenE
18
27
  const result = await runtime.intelligence.ɵconnectThread({
19
28
  threadId,
20
29
  userId: user.id,
21
- lastSeenEventId
30
+ agentId
22
31
  });
23
32
  if (result === null) return new Response(null, { status: 204 });
24
- return Response.json(result, { headers: {
33
+ return Response.json({
34
+ threadId: result.threadId,
35
+ joinToken: result.joinToken,
36
+ realtime: buildRealtimeConnectionInfo({
37
+ clientUrl: runtime.intelligence.ɵgetClientWsUrl(),
38
+ threadId: result.threadId
39
+ })
40
+ }, { headers: {
25
41
  "Cache-Control": "no-cache",
26
42
  Connection: "keep-alive"
27
43
  } });
28
44
  } catch (error) {
29
- if (isPlatformNotFoundError(error)) return new Response(null, { status: 204 });
45
+ const status = getPlatformErrorStatus(error);
46
+ if (status === 400 || status === 401 || status === 403 || status === 404 || status === 409) return Response.json({
47
+ error: "Connect request rejected",
48
+ message: error instanceof Error ? error.message : "Intelligence platform rejected the connect request"
49
+ }, { status });
30
50
  console.error("Connect plan not available:", error);
31
51
  return Response.json({ error: "Connect plan not available" }, { status: 404 });
32
52
  }
@@ -1 +1 @@
1
- {"version":3,"file":"connect.mjs","names":[],"sources":["../../../../../src/v2/runtime/handlers/intelligence/connect.ts"],"sourcesContent":["import { CopilotIntelligenceRuntimeLike } from \"../../core/runtime\";\nimport { isPlatformNotFoundError } from \"../shared/intelligence-utils\";\nimport { resolveIntelligenceUser } from \"../shared/resolve-intelligence-user\";\nimport { isHandlerResponse } from \"../shared/json-response\";\n\ninterface HandleIntelligenceConnectParams {\n runtime: CopilotIntelligenceRuntimeLike;\n request: Request;\n threadId: string;\n lastSeenEventId: string | null;\n}\n\nexport async function handleIntelligenceConnect({\n runtime,\n request,\n threadId,\n lastSeenEventId,\n}: HandleIntelligenceConnectParams): Promise<Response> {\n if (!runtime.intelligence) {\n return Response.json(\n {\n error: \"Intelligence not configured\",\n message: \"Intelligence mode requires a CopilotKitIntelligence\",\n },\n { status: 500 },\n );\n }\n\n try {\n const user = await resolveIntelligenceUser({ runtime, request });\n if (isHandlerResponse(user)) {\n return user;\n }\n\n const result = await runtime.intelligence.ɵconnectThread({\n threadId,\n userId: user.id,\n lastSeenEventId,\n });\n\n if (result === null) {\n return new Response(null, {\n status: 204,\n });\n }\n\n return Response.json(result, {\n headers: { \"Cache-Control\": \"no-cache\", Connection: \"keep-alive\" },\n });\n } catch (error) {\n if (isPlatformNotFoundError(error)) {\n return new Response(null, {\n status: 204,\n });\n }\n\n console.error(\"Connect plan not available:\", error);\n return Response.json(\n {\n error: \"Connect plan not available\",\n },\n { status: 404 },\n );\n }\n}\n"],"mappings":";;;;;;AAYA,eAAsB,0BAA0B,EAC9C,SACA,SACA,UACA,mBACqD;AACrD,KAAI,CAAC,QAAQ,aACX,QAAO,SAAS,KACd;EACE,OAAO;EACP,SAAS;EACV,EACD,EAAE,QAAQ,KAAK,CAChB;AAGH,KAAI;EACF,MAAM,OAAO,MAAM,wBAAwB;GAAE;GAAS;GAAS,CAAC;AAChE,MAAI,kBAAkB,KAAK,CACzB,QAAO;EAGT,MAAM,SAAS,MAAM,QAAQ,aAAa,eAAe;GACvD;GACA,QAAQ,KAAK;GACb;GACD,CAAC;AAEF,MAAI,WAAW,KACb,QAAO,IAAI,SAAS,MAAM,EACxB,QAAQ,KACT,CAAC;AAGJ,SAAO,SAAS,KAAK,QAAQ,EAC3B,SAAS;GAAE,iBAAiB;GAAY,YAAY;GAAc,EACnE,CAAC;UACK,OAAO;AACd,MAAI,wBAAwB,MAAM,CAChC,QAAO,IAAI,SAAS,MAAM,EACxB,QAAQ,KACT,CAAC;AAGJ,UAAQ,MAAM,+BAA+B,MAAM;AACnD,SAAO,SAAS,KACd,EACE,OAAO,8BACR,EACD,EAAE,QAAQ,KAAK,CAChB"}
1
+ {"version":3,"file":"connect.mjs","names":[],"sources":["../../../../../src/v2/runtime/handlers/intelligence/connect.ts"],"sourcesContent":["import { CopilotIntelligenceRuntimeLike } from \"../../core/runtime\";\nimport { getPlatformErrorStatus } from \"../shared/intelligence-utils\";\nimport { resolveIntelligenceUser } from \"../shared/resolve-intelligence-user\";\nimport { isHandlerResponse } from \"../shared/json-response\";\n\n/**\n * Builds browser-facing realtime connection metadata owned by the runtime.\n */\nfunction buildRealtimeConnectionInfo(params: {\n clientUrl: string;\n threadId: string;\n}): { clientUrl: string; topic: string } {\n return {\n clientUrl: params.clientUrl,\n topic: `thread:${params.threadId}`,\n };\n}\n\ninterface HandleIntelligenceConnectParams {\n runtime: CopilotIntelligenceRuntimeLike;\n request: Request;\n agentId: string;\n threadId: string;\n}\n\nexport async function handleIntelligenceConnect({\n runtime,\n request,\n agentId,\n threadId,\n}: HandleIntelligenceConnectParams): Promise<Response> {\n if (!runtime.intelligence) {\n return Response.json(\n {\n error: \"Intelligence not configured\",\n message: \"Intelligence mode requires a CopilotKitIntelligence\",\n },\n { status: 500 },\n );\n }\n\n try {\n const user = await resolveIntelligenceUser({ runtime, request });\n if (isHandlerResponse(user)) {\n return user;\n }\n\n const result = await runtime.intelligence.ɵconnectThread({\n threadId,\n userId: user.id,\n agentId,\n });\n\n if (result === null) {\n return new Response(null, {\n status: 204,\n });\n }\n\n return Response.json(\n {\n threadId: result.threadId,\n joinToken: result.joinToken,\n realtime: buildRealtimeConnectionInfo({\n clientUrl: runtime.intelligence.ɵgetClientWsUrl(),\n threadId: result.threadId,\n }),\n },\n {\n headers: { \"Cache-Control\": \"no-cache\", Connection: \"keep-alive\" },\n },\n );\n } catch (error) {\n const status = getPlatformErrorStatus(error);\n if (\n status === 400 ||\n status === 401 ||\n status === 403 ||\n status === 404 ||\n status === 409\n ) {\n return Response.json(\n {\n error: \"Connect request rejected\",\n message:\n error instanceof Error\n ? error.message\n : \"Intelligence platform rejected the connect request\",\n },\n { status },\n );\n }\n\n console.error(\"Connect plan not available:\", error);\n return Response.json(\n {\n error: \"Connect plan not available\",\n },\n { status: 404 },\n );\n }\n}\n"],"mappings":";;;;;;;;;AAQA,SAAS,4BAA4B,QAGI;AACvC,QAAO;EACL,WAAW,OAAO;EAClB,OAAO,UAAU,OAAO;EACzB;;AAUH,eAAsB,0BAA0B,EAC9C,SACA,SACA,SACA,YACqD;AACrD,KAAI,CAAC,QAAQ,aACX,QAAO,SAAS,KACd;EACE,OAAO;EACP,SAAS;EACV,EACD,EAAE,QAAQ,KAAK,CAChB;AAGH,KAAI;EACF,MAAM,OAAO,MAAM,wBAAwB;GAAE;GAAS;GAAS,CAAC;AAChE,MAAI,kBAAkB,KAAK,CACzB,QAAO;EAGT,MAAM,SAAS,MAAM,QAAQ,aAAa,eAAe;GACvD;GACA,QAAQ,KAAK;GACb;GACD,CAAC;AAEF,MAAI,WAAW,KACb,QAAO,IAAI,SAAS,MAAM,EACxB,QAAQ,KACT,CAAC;AAGJ,SAAO,SAAS,KACd;GACE,UAAU,OAAO;GACjB,WAAW,OAAO;GAClB,UAAU,4BAA4B;IACpC,WAAW,QAAQ,aAAa,iBAAiB;IACjD,UAAU,OAAO;IAClB,CAAC;GACH,EACD,EACE,SAAS;GAAE,iBAAiB;GAAY,YAAY;GAAc,EACnE,CACF;UACM,OAAO;EACd,MAAM,SAAS,uBAAuB,MAAM;AAC5C,MACE,WAAW,OACX,WAAW,OACX,WAAW,OACX,WAAW,OACX,WAAW,IAEX,QAAO,SAAS,KACd;GACE,OAAO;GACP,SACE,iBAAiB,QACb,MAAM,UACN;GACP,EACD,EAAE,QAAQ,CACX;AAGH,UAAQ,MAAM,+BAA+B,MAAM;AACnD,SAAO,SAAS,KACd,EACE,OAAO,8BACR,EACD,EAAE,QAAQ,KAAK,CAChB"}
@@ -5,8 +5,21 @@ const require_json_response = require('../shared/json-response.cjs');
5
5
  const require_thread_names = require('./thread-names.cjs');
6
6
  const require_resolve_intelligence_user = require('../shared/resolve-intelligence-user.cjs');
7
7
  let _copilotkit_shared = require("@copilotkit/shared");
8
+ let _ag_ui_client = require("@ag-ui/client");
8
9
 
9
10
  //#region src/v2/runtime/handlers/intelligence/run.ts
11
+ /**
12
+ * Builds browser-facing realtime connection metadata owned by the runtime.
13
+ */
14
+ function buildRealtimeConnectionInfo(params) {
15
+ return {
16
+ clientUrl: params.clientUrl,
17
+ topic: `thread:${params.threadId}`
18
+ };
19
+ }
20
+ function hasRunnerStartupBoundary(runner) {
21
+ return typeof runner.runWithStartupBoundary === "function" && (Object.prototype.hasOwnProperty.call(runner, "runWithStartupBoundary") || Object.prototype.hasOwnProperty.call(runner, "threads"));
22
+ }
10
23
  async function handleIntelligenceRun({ runtime, request, agentId, agent, input }) {
11
24
  if (!runtime.intelligence) return Response.json({
12
25
  error: "Intelligence not configured",
@@ -38,45 +51,72 @@ async function handleIntelligenceRun({ runtime, request, agentId, agent, input }
38
51
  _copilotkit_shared.logger.error("Failed to get or create thread:", error);
39
52
  return Response.json({ error: "Failed to initialize thread" }, { status: 502 });
40
53
  }
41
- let joinCode;
54
+ let canonicalThreadId = input.threadId;
55
+ let canonicalRunId = input.runId;
42
56
  let joinToken;
43
57
  try {
44
58
  const lockResult = await runtime.intelligence.ɵacquireThreadLock({
45
59
  threadId: input.threadId,
46
60
  runId: input.runId,
47
61
  userId,
62
+ agentId,
48
63
  ...runtime.lockKeyPrefix !== void 0 ? { lockKeyPrefix: runtime.lockKeyPrefix } : {},
49
64
  ttlSeconds: runtime.lockTtlSeconds
50
65
  });
66
+ canonicalThreadId = lockResult.threadId;
67
+ canonicalRunId = lockResult.runId;
51
68
  joinToken = lockResult.joinToken;
52
- joinCode = lockResult.joinCode;
53
69
  } catch (error) {
54
70
  _copilotkit_shared.logger.error("Thread lock denied:", error);
55
71
  return Response.json({ error: "Thread lock denied" }, { status: 409 });
56
72
  }
57
- if (!joinToken) return Response.json({
58
- error: "Join token not available",
59
- message: "Intelligence platform did not return a join token"
60
- }, { status: 502 });
73
+ const cleanupLock = (reason) => runtime.intelligence.ɵcleanupThreadLock({
74
+ threadId: canonicalThreadId || input.threadId,
75
+ runId: canonicalRunId || input.runId
76
+ }).catch((cleanupError) => {
77
+ _copilotkit_shared.logger.error({
78
+ err: cleanupError,
79
+ reason
80
+ }, "Failed to cleanup thread lock");
81
+ });
82
+ if (!canonicalThreadId || !canonicalRunId || !joinToken) {
83
+ await cleanupLock("malformed-lock-response");
84
+ return Response.json({
85
+ error: "Run connection credentials not available",
86
+ message: "Intelligence platform did not return canonical threadId, runId, and joinToken"
87
+ }, { status: 502 });
88
+ }
89
+ const canonicalInput = {
90
+ ...input,
91
+ threadId: canonicalThreadId,
92
+ runId: canonicalRunId
93
+ };
61
94
  let persistedInputMessages;
62
95
  if (Array.isArray(input.messages)) try {
63
- const history = await runtime.intelligence.getThreadMessages({ threadId: input.threadId });
96
+ const history = await runtime.intelligence.getThreadMessages({ threadId: canonicalThreadId });
64
97
  const historicMessageIds = new Set(history.messages.map((message) => message.id));
65
98
  persistedInputMessages = input.messages.filter((message) => !historicMessageIds.has(message.id));
66
99
  } catch (error) {
67
100
  _copilotkit_shared.logger.error("Thread history lookup failed:", error);
101
+ await cleanupLock("thread-history-lookup-failed");
68
102
  return Response.json({ error: "Thread history lookup failed" }, { status: 502 });
69
103
  }
70
104
  require_telemetry_client.default.capture("oss.runtime.agent_execution_stream_started", {});
71
105
  let heartbeatTimer;
72
106
  heartbeatTimer = setInterval(() => {
73
107
  runtime.intelligence.ɵrenewThreadLock({
74
- threadId: input.threadId,
75
- runId: input.runId,
108
+ threadId: canonicalThreadId,
109
+ runId: canonicalRunId,
76
110
  ttlSeconds: runtime.lockTtlSeconds,
77
111
  ...runtime.lockKeyPrefix !== void 0 ? { lockKeyPrefix: runtime.lockKeyPrefix } : {}
78
112
  }).catch((err) => {
79
113
  _copilotkit_shared.logger.error("Failed to renew thread lock:", err);
114
+ clearHeartbeat();
115
+ try {
116
+ agent.abortRun();
117
+ } catch (abortError) {
118
+ _copilotkit_shared.logger.error("Failed to abort agent after lock renewal failure:", abortError);
119
+ }
80
120
  });
81
121
  }, runtime.lockHeartbeatIntervalSeconds * 1e3);
82
122
  const clearHeartbeat = () => {
@@ -85,24 +125,69 @@ async function handleIntelligenceRun({ runtime, request, agentId, agent, input }
85
125
  heartbeatTimer = void 0;
86
126
  }
87
127
  };
88
- runtime.runner.run({
89
- threadId: input.threadId,
128
+ const runStarted = { current: false };
129
+ let immediateStartupErrorMessage;
130
+ let immediateStartupCleanup;
131
+ const runRequest = {
132
+ threadId: canonicalThreadId,
90
133
  agent,
91
- input,
92
- ...persistedInputMessages !== void 0 ? { persistedInputMessages } : {},
93
- ...joinCode ? { joinCode } : {}
94
- }).subscribe({
95
- error: (error) => {
96
- clearHeartbeat();
97
- require_telemetry_client.default.capture("oss.runtime.agent_execution_stream_errored", { error: error instanceof Error ? error.message : String(error) });
98
- _copilotkit_shared.logger.error("Error running agent:", error);
99
- },
100
- complete: () => {
101
- clearHeartbeat();
102
- require_telemetry_client.default.capture("oss.runtime.agent_execution_stream_ended", {});
103
- }
104
- });
105
- return Response.json({ joinToken }, { headers: { "Cache-Control": "no-cache" } });
134
+ input: canonicalInput,
135
+ ...persistedInputMessages !== void 0 ? { persistedInputMessages } : {}
136
+ };
137
+ try {
138
+ const runStart = hasRunnerStartupBoundary(runtime.runner) ? runtime.runner.runWithStartupBoundary(runRequest) : {
139
+ events: runtime.runner.run(runRequest),
140
+ startup: Promise.resolve()
141
+ };
142
+ runStart.events.subscribe({
143
+ next: (event) => {
144
+ if (event.type === _ag_ui_client.EventType.RUN_STARTED) runStarted.current = true;
145
+ if (event.type === _ag_ui_client.EventType.RUN_ERROR && !runStarted.current) {
146
+ clearHeartbeat();
147
+ immediateStartupErrorMessage = "message" in event && typeof event.message === "string" ? event.message : "Runner failed before the run started";
148
+ immediateStartupCleanup = cleanupLock("runner-start-failed");
149
+ }
150
+ },
151
+ error: (error) => {
152
+ clearHeartbeat();
153
+ if (!runStarted.current) {
154
+ immediateStartupErrorMessage = error instanceof Error ? error.message : String(error);
155
+ immediateStartupCleanup = cleanupLock("runner-start-error");
156
+ } else cleanupLock("runner-error");
157
+ require_telemetry_client.default.capture("oss.runtime.agent_execution_stream_errored", { error: error instanceof Error ? error.message : String(error) });
158
+ _copilotkit_shared.logger.error("Error running agent:", error);
159
+ },
160
+ complete: () => {
161
+ clearHeartbeat();
162
+ require_telemetry_client.default.capture("oss.runtime.agent_execution_stream_ended", {});
163
+ }
164
+ });
165
+ await runStart.startup;
166
+ } catch (error) {
167
+ clearHeartbeat();
168
+ await (immediateStartupCleanup ?? cleanupLock("runner-start-threw"));
169
+ _copilotkit_shared.logger.error("Error starting agent runner:", error);
170
+ return Response.json({
171
+ error: "Failed to start runner",
172
+ message: error instanceof Error ? error.message : String(error)
173
+ }, { status: 502 });
174
+ }
175
+ if (immediateStartupErrorMessage) {
176
+ await immediateStartupCleanup;
177
+ return Response.json({
178
+ error: "Failed to start runner",
179
+ message: immediateStartupErrorMessage
180
+ }, { status: 502 });
181
+ }
182
+ return Response.json({
183
+ threadId: canonicalThreadId,
184
+ runId: canonicalRunId,
185
+ joinToken,
186
+ realtime: buildRealtimeConnectionInfo({
187
+ clientUrl: runtime.intelligence.ɵgetClientWsUrl(),
188
+ threadId: canonicalThreadId
189
+ })
190
+ }, { headers: { "Cache-Control": "no-cache" } });
106
191
  }
107
192
 
108
193
  //#endregion
@@ -1 +1 @@
1
- {"version":3,"file":"run.cjs","names":["resolveIntelligenceUser","isHandlerResponse","generateThreadNameForNewThread"],"sources":["../../../../../src/v2/runtime/handlers/intelligence/run.ts"],"sourcesContent":["import { AbstractAgent, Message, RunAgentInput } from \"@ag-ui/client\";\nimport { CopilotIntelligenceRuntimeLike } from \"../../core/runtime\";\nimport { generateThreadNameForNewThread } from \"./thread-names\";\nimport { logger } from \"@copilotkit/shared\";\nimport { telemetry } from \"../../telemetry\";\nimport { resolveIntelligenceUser } from \"../shared/resolve-intelligence-user\";\nimport { isHandlerResponse } from \"../shared/json-response\";\n\ninterface HandleIntelligenceRunParams {\n runtime: CopilotIntelligenceRuntimeLike;\n request: Request;\n agentId: string;\n agent: AbstractAgent;\n input: RunAgentInput;\n}\n\nexport async function handleIntelligenceRun({\n runtime,\n request,\n agentId,\n agent,\n input,\n}: HandleIntelligenceRunParams): Promise<Response> {\n if (!runtime.intelligence) {\n return Response.json(\n {\n error: \"Intelligence not configured\",\n message: \"Intelligence mode requires a CopilotKitIntelligence\",\n },\n { status: 500 },\n );\n }\n\n const user = await resolveIntelligenceUser({ runtime, request });\n if (isHandlerResponse(user)) {\n return user;\n }\n const userId = user.id;\n\n try {\n const { thread, created } = await runtime.intelligence.getOrCreateThread({\n threadId: input.threadId,\n userId,\n agentId,\n });\n\n if (created && runtime.generateThreadNames && !thread.name?.trim()) {\n void generateThreadNameForNewThread({\n runtime,\n request,\n agentId,\n sourceInput: input,\n thread,\n userId,\n }).catch((nameError) => {\n logger.error(\"Failed to generate thread name:\", nameError);\n });\n }\n } catch (error) {\n logger.error(\"Failed to get or create thread:\", error);\n return Response.json(\n {\n error: \"Failed to initialize thread\",\n },\n { status: 502 },\n );\n }\n\n let joinCode: string | undefined;\n let joinToken: string | undefined;\n try {\n const lockResult = await runtime.intelligence.ɵacquireThreadLock({\n threadId: input.threadId,\n runId: input.runId,\n userId,\n ...(runtime.lockKeyPrefix !== undefined\n ? { lockKeyPrefix: runtime.lockKeyPrefix }\n : {}),\n ttlSeconds: runtime.lockTtlSeconds,\n });\n joinToken = lockResult.joinToken;\n joinCode = lockResult.joinCode;\n } catch (error) {\n logger.error(\"Thread lock denied:\", error);\n return Response.json(\n {\n error: \"Thread lock denied\",\n },\n { status: 409 },\n );\n }\n\n if (!joinToken) {\n return Response.json(\n {\n error: \"Join token not available\",\n message: \"Intelligence platform did not return a join token\",\n },\n { status: 502 },\n );\n }\n\n let persistedInputMessages: Message[] | undefined;\n if (Array.isArray(input.messages)) {\n try {\n const history = await runtime.intelligence.getThreadMessages({\n threadId: input.threadId,\n });\n const historicMessageIds = new Set(\n history.messages.map((message) => message.id),\n );\n persistedInputMessages = input.messages.filter(\n (message) => !historicMessageIds.has(message.id),\n );\n } catch (error) {\n logger.error(\"Thread history lookup failed:\", error);\n return Response.json(\n {\n error: \"Thread history lookup failed\",\n },\n { status: 502 },\n );\n }\n }\n\n telemetry.capture(\"oss.runtime.agent_execution_stream_started\", {});\n\n // Start heartbeat timer to renew the thread lock.\n let heartbeatTimer: ReturnType<typeof setInterval> | undefined;\n heartbeatTimer = setInterval(() => {\n runtime.intelligence\n .ɵrenewThreadLock({\n threadId: input.threadId,\n runId: input.runId,\n ttlSeconds: runtime.lockTtlSeconds,\n ...(runtime.lockKeyPrefix !== undefined\n ? { lockKeyPrefix: runtime.lockKeyPrefix }\n : {}),\n })\n .catch((err) => {\n logger.error(\"Failed to renew thread lock:\", err);\n });\n }, runtime.lockHeartbeatIntervalSeconds * 1_000);\n\n const clearHeartbeat = () => {\n if (heartbeatTimer !== undefined) {\n clearInterval(heartbeatTimer);\n heartbeatTimer = undefined;\n }\n };\n\n runtime.runner\n .run({\n threadId: input.threadId,\n agent,\n input,\n ...(persistedInputMessages !== undefined\n ? { persistedInputMessages }\n : {}),\n ...(joinCode ? { joinCode } : {}),\n })\n .subscribe({\n error: (error) => {\n clearHeartbeat();\n telemetry.capture(\"oss.runtime.agent_execution_stream_errored\", {\n error: error instanceof Error ? error.message : String(error),\n });\n logger.error(\"Error running agent:\", error);\n },\n complete: () => {\n clearHeartbeat();\n telemetry.capture(\"oss.runtime.agent_execution_stream_ended\", {});\n },\n });\n\n return Response.json(\n { joinToken },\n {\n headers: { \"Cache-Control\": \"no-cache\" },\n },\n );\n}\n"],"mappings":";;;;;;;;;AAgBA,eAAsB,sBAAsB,EAC1C,SACA,SACA,SACA,OACA,SACiD;AACjD,KAAI,CAAC,QAAQ,aACX,QAAO,SAAS,KACd;EACE,OAAO;EACP,SAAS;EACV,EACD,EAAE,QAAQ,KAAK,CAChB;CAGH,MAAM,OAAO,MAAMA,0DAAwB;EAAE;EAAS;EAAS,CAAC;AAChE,KAAIC,wCAAkB,KAAK,CACzB,QAAO;CAET,MAAM,SAAS,KAAK;AAEpB,KAAI;EACF,MAAM,EAAE,QAAQ,YAAY,MAAM,QAAQ,aAAa,kBAAkB;GACvE,UAAU,MAAM;GAChB;GACA;GACD,CAAC;AAEF,MAAI,WAAW,QAAQ,uBA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,UAAQ,aACL,iBAAiB;GAChB,UAAU,MAAM;GAChB,OAAO,MAAM;GACb,YAAY,QAAQ;GACpB,GAAI,QAAQ,kBAAkB,SAC1B,EAAE,eAAe,QAAQ,eAAe,GACxC,EAAE;GACP,CAAC,CACD,OAAO,QAAQ;AACd,6BAAO,MAAM,gCAAgC,IAAI;IACjD;IACH,QAAQ,+BAA+B,IAAM;CAEhD,MAAM,uBAAuB;AAC3B,MAAI,mBAAmB,QAAW;AAChC,iBAAc,eAAe;AAC7B,oBAAiB;;;AAIrB,SAAQ,OACL,IAAI;EACH,UAAU,MAAM;EAChB;EACA;EACA,GAAI,2BAA2B,SAC3B,EAAE,wBAAwB,GAC1B,EAAE;EACN,GAAI,WAAW,EAAE,UAAU,GAAG,EAAE;EACjC,CAAC,CACD,UAAU;EACT,QAAQ,UAAU;AAChB,mBAAgB;AAChB,oCAAU,QAAQ,8CAA8C,EAC9D,OAAO,iBAAiB,QAAQ,MAAM,UAAU,OAAO,MAAM,EAC9D,CAAC;AACF,6BAAO,MAAM,wBAAwB,MAAM;;EAE7C,gBAAgB;AACd,mBAAgB;AAChB,oCAAU,QAAQ,4CAA4C,EAAE,CAAC;;EAEpE,CAAC;AAEJ,QAAO,SAAS,KACd,EAAE,WAAW,EACb,EACE,SAAS,EAAE,iBAAiB,YAAY,EACzC,CACF"}
1
+ {"version":3,"file":"run.cjs","names":["resolveIntelligenceUser","isHandlerResponse","generateThreadNameForNewThread","EventType"],"sources":["../../../../../src/v2/runtime/handlers/intelligence/run.ts"],"sourcesContent":["import {\n AbstractAgent,\n BaseEvent,\n EventType,\n Message,\n RunAgentInput,\n} from \"@ag-ui/client\";\nimport { CopilotIntelligenceRuntimeLike } from \"../../core/runtime\";\nimport { generateThreadNameForNewThread } from \"./thread-names\";\nimport { logger } from \"@copilotkit/shared\";\nimport { telemetry } from \"../../telemetry\";\nimport { resolveIntelligenceUser } from \"../shared/resolve-intelligence-user\";\nimport { isHandlerResponse } from \"../shared/json-response\";\nimport { AgentRunnerRunRequest } from \"../../runner/agent-runner\";\nimport { Observable } from \"rxjs\";\n\n/**\n * Builds browser-facing realtime connection metadata owned by the runtime.\n */\nfunction buildRealtimeConnectionInfo(params: {\n clientUrl: string;\n threadId: string;\n}): { clientUrl: string; topic: string } {\n return {\n clientUrl: params.clientUrl,\n topic: `thread:${params.threadId}`,\n };\n}\n\ninterface RunnerStartupBoundary {\n events: Observable<BaseEvent>;\n startup: Promise<void>;\n}\n\ninterface RunnerWithStartupBoundary {\n runWithStartupBoundary(request: AgentRunnerRunRequest): RunnerStartupBoundary;\n}\n\nfunction hasRunnerStartupBoundary(\n runner: CopilotIntelligenceRuntimeLike[\"runner\"],\n): runner is CopilotIntelligenceRuntimeLike[\"runner\"] &\n RunnerWithStartupBoundary {\n const candidate = runner as { runWithStartupBoundary?: unknown };\n\n return (\n typeof candidate.runWithStartupBoundary === \"function\" &&\n (Object.prototype.hasOwnProperty.call(runner, \"runWithStartupBoundary\") ||\n Object.prototype.hasOwnProperty.call(runner, \"threads\"))\n );\n}\n\ninterface HandleIntelligenceRunParams {\n runtime: CopilotIntelligenceRuntimeLike;\n request: Request;\n agentId: string;\n agent: AbstractAgent;\n input: RunAgentInput;\n}\n\nexport async function handleIntelligenceRun({\n runtime,\n request,\n agentId,\n agent,\n input,\n}: HandleIntelligenceRunParams): Promise<Response> {\n if (!runtime.intelligence) {\n return Response.json(\n {\n error: \"Intelligence not configured\",\n message: \"Intelligence mode requires a CopilotKitIntelligence\",\n },\n { status: 500 },\n );\n }\n\n const user = await resolveIntelligenceUser({ runtime, request });\n if (isHandlerResponse(user)) {\n return user;\n }\n const userId = user.id;\n\n try {\n const { thread, created } = await runtime.intelligence.getOrCreateThread({\n threadId: input.threadId,\n userId,\n agentId,\n });\n\n if (created && runtime.generateThreadNames && !thread.name?.trim()) {\n void generateThreadNameForNewThread({\n runtime,\n request,\n agentId,\n sourceInput: input,\n thread,\n userId,\n }).catch((nameError) => {\n logger.error(\"Failed to generate thread name:\", nameError);\n });\n }\n } catch (error) {\n logger.error(\"Failed to get or create thread:\", error);\n return Response.json(\n {\n error: \"Failed to initialize thread\",\n },\n { status: 502 },\n );\n }\n\n let canonicalThreadId = input.threadId;\n let canonicalRunId = input.runId;\n let joinToken: string | undefined;\n try {\n const lockResult = await runtime.intelligence.ɵacquireThreadLock({\n threadId: input.threadId,\n runId: input.runId,\n userId,\n agentId,\n ...(runtime.lockKeyPrefix !== undefined\n ? { lockKeyPrefix: runtime.lockKeyPrefix }\n : {}),\n ttlSeconds: runtime.lockTtlSeconds,\n });\n canonicalThreadId = lockResult.threadId;\n canonicalRunId = lockResult.runId;\n joinToken = lockResult.joinToken;\n } catch (error) {\n logger.error(\"Thread lock denied:\", error);\n return Response.json(\n {\n error: \"Thread lock denied\",\n },\n { status: 409 },\n );\n }\n\n const cleanupLock = (reason: string): Promise<void> =>\n runtime.intelligence\n .ɵcleanupThreadLock({\n threadId: canonicalThreadId || input.threadId,\n runId: canonicalRunId || input.runId,\n })\n .catch((cleanupError) => {\n logger.error(\n { err: cleanupError, reason },\n \"Failed to cleanup thread lock\",\n );\n });\n\n if (!canonicalThreadId || !canonicalRunId || !joinToken) {\n await cleanupLock(\"malformed-lock-response\");\n return Response.json(\n {\n error: \"Run connection credentials not available\",\n message:\n \"Intelligence platform did not return canonical threadId, runId, and joinToken\",\n },\n { status: 502 },\n );\n }\n\n const canonicalInput: RunAgentInput = {\n ...input,\n threadId: canonicalThreadId,\n runId: canonicalRunId,\n };\n\n let persistedInputMessages: Message[] | undefined;\n if (Array.isArray(input.messages)) {\n try {\n const history = await runtime.intelligence.getThreadMessages({\n threadId: canonicalThreadId,\n });\n const historicMessageIds = new Set(\n history.messages.map((message) => message.id),\n );\n persistedInputMessages = input.messages.filter(\n (message) => !historicMessageIds.has(message.id),\n );\n } catch (error) {\n logger.error(\"Thread history lookup failed:\", error);\n await cleanupLock(\"thread-history-lookup-failed\");\n return Response.json(\n {\n error: \"Thread history lookup failed\",\n },\n { status: 502 },\n );\n }\n }\n\n telemetry.capture(\"oss.runtime.agent_execution_stream_started\", {});\n\n // Start heartbeat timer to renew the thread lock.\n let heartbeatTimer: ReturnType<typeof setInterval> | undefined;\n heartbeatTimer = setInterval(() => {\n runtime.intelligence\n .ɵrenewThreadLock({\n threadId: canonicalThreadId,\n runId: canonicalRunId,\n ttlSeconds: runtime.lockTtlSeconds,\n ...(runtime.lockKeyPrefix !== undefined\n ? { lockKeyPrefix: runtime.lockKeyPrefix }\n : {}),\n })\n .catch((err) => {\n logger.error(\"Failed to renew thread lock:\", err);\n clearHeartbeat();\n try {\n agent.abortRun();\n } catch (abortError) {\n logger.error(\n \"Failed to abort agent after lock renewal failure:\",\n abortError,\n );\n }\n });\n }, runtime.lockHeartbeatIntervalSeconds * 1_000);\n\n const clearHeartbeat = () => {\n if (heartbeatTimer !== undefined) {\n clearInterval(heartbeatTimer);\n heartbeatTimer = undefined;\n }\n };\n\n const runStarted = { current: false };\n let immediateStartupErrorMessage: string | undefined;\n let immediateStartupCleanup: Promise<void> | undefined;\n\n const runRequest: AgentRunnerRunRequest = {\n threadId: canonicalThreadId,\n agent,\n input: canonicalInput,\n ...(persistedInputMessages !== undefined ? { persistedInputMessages } : {}),\n };\n\n try {\n const runStart = hasRunnerStartupBoundary(runtime.runner)\n ? runtime.runner.runWithStartupBoundary(runRequest)\n : {\n events: runtime.runner.run(runRequest),\n startup: Promise.resolve(),\n };\n\n runStart.events.subscribe({\n next: (event: BaseEvent) => {\n if (event.type === EventType.RUN_STARTED) {\n runStarted.current = true;\n }\n if (event.type === EventType.RUN_ERROR && !runStarted.current) {\n clearHeartbeat();\n immediateStartupErrorMessage =\n \"message\" in event && typeof event.message === \"string\"\n ? event.message\n : \"Runner failed before the run started\";\n immediateStartupCleanup = cleanupLock(\"runner-start-failed\");\n }\n },\n error: (error) => {\n clearHeartbeat();\n if (!runStarted.current) {\n immediateStartupErrorMessage =\n error instanceof Error ? error.message : String(error);\n immediateStartupCleanup = cleanupLock(\"runner-start-error\");\n } else {\n cleanupLock(\"runner-error\");\n }\n telemetry.capture(\"oss.runtime.agent_execution_stream_errored\", {\n error: error instanceof Error ? error.message : String(error),\n });\n logger.error(\"Error running agent:\", error);\n },\n complete: () => {\n clearHeartbeat();\n telemetry.capture(\"oss.runtime.agent_execution_stream_ended\", {});\n },\n });\n\n await runStart.startup;\n } catch (error) {\n clearHeartbeat();\n await (immediateStartupCleanup ?? cleanupLock(\"runner-start-threw\"));\n logger.error(\"Error starting agent runner:\", error);\n return Response.json(\n {\n error: \"Failed to start runner\",\n message: error instanceof Error ? error.message : String(error),\n },\n { status: 502 },\n );\n }\n\n if (immediateStartupErrorMessage) {\n await immediateStartupCleanup;\n return Response.json(\n {\n error: \"Failed to start runner\",\n message: immediateStartupErrorMessage,\n },\n { status: 502 },\n );\n }\n\n // IntelligenceAgentRunner resolves this boundary after Phoenix channel join.\n // Other runner implementations fall back to construction/subscription errors.\n return Response.json(\n {\n threadId: canonicalThreadId,\n runId: canonicalRunId,\n joinToken,\n realtime: buildRealtimeConnectionInfo({\n clientUrl: runtime.intelligence.ɵgetClientWsUrl(),\n threadId: canonicalThreadId,\n }),\n },\n {\n headers: { \"Cache-Control\": \"no-cache\" },\n },\n );\n}\n"],"mappings":";;;;;;;;;;;;;AAmBA,SAAS,4BAA4B,QAGI;AACvC,QAAO;EACL,WAAW,OAAO;EAClB,OAAO,UAAU,OAAO;EACzB;;AAYH,SAAS,yBACP,QAE0B;AAG1B,QACE,OAHgB,OAGC,2BAA2B,eAC3C,OAAO,UAAU,eAAe,KAAK,QAAQ,yBAAyB,IACrE,OAAO,UAAU,eAAe,KAAK,QAAQ,UAAU;;AAY7D,eAAsB,sBAAsB,EAC1C,SACA,SACA,SACA,OACA,SACiD;AACjD,KAAI,CAAC,QAAQ,aACX,QAAO,SAAS,KACd;EACE,OAAO;EACP,SAAS;EACV,EACD,EAAE,QAAQ,KAAK,CAChB;CAGH,MAAM,OAAO,MAAMA,0DAAwB;EAAE;EAAS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