@copilotkit/runtime 2.0.0-next.1 → 2.0.0-rc.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 (623) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +135 -1
  3. package/dist/_virtual/_rolldown/runtime.cjs +29 -0
  4. package/dist/_virtual/_rolldown/runtime.mjs +18 -0
  5. package/dist/agent/converters/aisdk.cjs +355 -0
  6. package/dist/agent/converters/aisdk.cjs.map +1 -0
  7. package/dist/agent/converters/aisdk.d.cts +22 -0
  8. package/dist/agent/converters/aisdk.d.cts.map +1 -0
  9. package/dist/agent/converters/aisdk.d.mts +22 -0
  10. package/dist/agent/converters/aisdk.d.mts.map +1 -0
  11. package/dist/agent/converters/aisdk.mjs +351 -0
  12. package/dist/agent/converters/aisdk.mjs.map +1 -0
  13. package/dist/agent/converters/index.d.mts +2 -0
  14. package/dist/agent/converters/tanstack.cjs +374 -0
  15. package/dist/agent/converters/tanstack.cjs.map +1 -0
  16. package/dist/agent/converters/tanstack.d.cts +83 -0
  17. package/dist/agent/converters/tanstack.d.cts.map +1 -0
  18. package/dist/agent/converters/tanstack.d.mts +83 -0
  19. package/dist/agent/converters/tanstack.d.mts.map +1 -0
  20. package/dist/agent/converters/tanstack.mjs +372 -0
  21. package/dist/agent/converters/tanstack.mjs.map +1 -0
  22. package/dist/agent/converters/usage.cjs +68 -0
  23. package/dist/agent/converters/usage.cjs.map +1 -0
  24. package/dist/agent/converters/usage.d.cts +19 -0
  25. package/dist/agent/converters/usage.d.cts.map +1 -0
  26. package/dist/agent/converters/usage.d.mts +19 -0
  27. package/dist/agent/converters/usage.d.mts.map +1 -0
  28. package/dist/agent/converters/usage.mjs +62 -0
  29. package/dist/agent/converters/usage.mjs.map +1 -0
  30. package/dist/agent/index.cjs +1328 -0
  31. package/dist/agent/index.cjs.map +1 -0
  32. package/dist/agent/index.d.cts +467 -0
  33. package/dist/agent/index.d.cts.map +1 -0
  34. package/dist/agent/index.d.mts +468 -0
  35. package/dist/agent/index.d.mts.map +1 -0
  36. package/dist/agent/index.mjs +1318 -0
  37. package/dist/agent/index.mjs.map +1 -0
  38. package/dist/agent/learned-skills.cjs +76 -0
  39. package/dist/agent/learned-skills.cjs.map +1 -0
  40. package/dist/agent/learned-skills.d.cts +15 -0
  41. package/dist/agent/learned-skills.d.cts.map +1 -0
  42. package/dist/agent/learned-skills.d.mts +15 -0
  43. package/dist/agent/learned-skills.d.mts.map +1 -0
  44. package/dist/agent/learned-skills.mjs +74 -0
  45. package/dist/agent/learned-skills.mjs.map +1 -0
  46. package/dist/agent/mcp-tool-names.cjs +82 -0
  47. package/dist/agent/mcp-tool-names.cjs.map +1 -0
  48. package/dist/agent/mcp-tool-names.mjs +80 -0
  49. package/dist/agent/mcp-tool-names.mjs.map +1 -0
  50. package/dist/agent/state-delta.cjs +321 -0
  51. package/dist/agent/state-delta.cjs.map +1 -0
  52. package/dist/agent/state-delta.mjs +320 -0
  53. package/dist/agent/state-delta.mjs.map +1 -0
  54. package/dist/agent/url-download.cjs +503 -0
  55. package/dist/agent/url-download.cjs.map +1 -0
  56. package/dist/agent/url-download.d.cts +79 -0
  57. package/dist/agent/url-download.d.cts.map +1 -0
  58. package/dist/agent/url-download.d.mts +79 -0
  59. package/dist/agent/url-download.d.mts.map +1 -0
  60. package/dist/agent/url-download.mjs +500 -0
  61. package/dist/agent/url-download.mjs.map +1 -0
  62. package/dist/index.cjs +75 -0
  63. package/dist/index.d.cts +24 -0
  64. package/dist/index.d.mts +24 -0
  65. package/dist/index.mjs +17 -5598
  66. package/dist/internal/learned-skills.cjs +21 -0
  67. package/dist/internal/learned-skills.d.cts +9 -0
  68. package/dist/internal/learned-skills.d.mts +9 -0
  69. package/dist/internal/learned-skills.mjs +9 -0
  70. package/dist/node.cjs +7 -0
  71. package/dist/node.d.cts +4 -0
  72. package/dist/node.d.mts +4 -0
  73. package/dist/node.mjs +4 -0
  74. package/dist/runtime/core/channel-activation-config.cjs +87 -0
  75. package/dist/runtime/core/channel-activation-config.cjs.map +1 -0
  76. package/dist/runtime/core/channel-activation-config.d.cts +39 -0
  77. package/dist/runtime/core/channel-activation-config.d.cts.map +1 -0
  78. package/dist/runtime/core/channel-activation-config.d.mts +39 -0
  79. package/dist/runtime/core/channel-activation-config.d.mts.map +1 -0
  80. package/dist/runtime/core/channel-activation-config.mjs +85 -0
  81. package/dist/runtime/core/channel-activation-config.mjs.map +1 -0
  82. package/dist/runtime/core/channel-manager.cjs +973 -0
  83. package/dist/runtime/core/channel-manager.cjs.map +1 -0
  84. package/dist/runtime/core/channel-manager.d.cts +166 -0
  85. package/dist/runtime/core/channel-manager.d.cts.map +1 -0
  86. package/dist/runtime/core/channel-manager.d.mts +167 -0
  87. package/dist/runtime/core/channel-manager.d.mts.map +1 -0
  88. package/dist/runtime/core/channel-manager.mjs +972 -0
  89. package/dist/runtime/core/channel-manager.mjs.map +1 -0
  90. package/dist/runtime/core/debug-event-bus.cjs +57 -0
  91. package/dist/runtime/core/debug-event-bus.cjs.map +1 -0
  92. package/dist/runtime/core/debug-event-bus.d.cts +18 -0
  93. package/dist/runtime/core/debug-event-bus.d.cts.map +1 -0
  94. package/dist/runtime/core/debug-event-bus.d.mts +18 -0
  95. package/dist/runtime/core/debug-event-bus.d.mts.map +1 -0
  96. package/dist/runtime/core/debug-event-bus.mjs +55 -0
  97. package/dist/runtime/core/debug-event-bus.mjs.map +1 -0
  98. package/dist/runtime/core/fetch-cors.cjs +71 -0
  99. package/dist/runtime/core/fetch-cors.cjs.map +1 -0
  100. package/dist/runtime/core/fetch-cors.d.cts +19 -0
  101. package/dist/runtime/core/fetch-cors.d.cts.map +1 -0
  102. package/dist/runtime/core/fetch-cors.d.mts +19 -0
  103. package/dist/runtime/core/fetch-cors.d.mts.map +1 -0
  104. package/dist/runtime/core/fetch-cors.mjs +69 -0
  105. package/dist/runtime/core/fetch-cors.mjs.map +1 -0
  106. package/dist/runtime/core/fetch-handler.cjs +539 -0
  107. package/dist/runtime/core/fetch-handler.cjs.map +1 -0
  108. package/dist/runtime/core/fetch-handler.d.cts +99 -0
  109. package/dist/runtime/core/fetch-handler.d.cts.map +1 -0
  110. package/dist/runtime/core/fetch-handler.d.mts +99 -0
  111. package/dist/runtime/core/fetch-handler.d.mts.map +1 -0
  112. package/dist/runtime/core/fetch-handler.mjs +538 -0
  113. package/dist/runtime/core/fetch-handler.mjs.map +1 -0
  114. package/dist/runtime/core/fetch-router.cjs +141 -0
  115. package/dist/runtime/core/fetch-router.cjs.map +1 -0
  116. package/dist/runtime/core/fetch-router.mjs +140 -0
  117. package/dist/runtime/core/fetch-router.mjs.map +1 -0
  118. package/dist/runtime/core/hooks.cjs +28 -0
  119. package/dist/runtime/core/hooks.cjs.map +1 -0
  120. package/dist/runtime/core/hooks.d.cts +121 -0
  121. package/dist/runtime/core/hooks.d.cts.map +1 -0
  122. package/dist/runtime/core/hooks.d.mts +121 -0
  123. package/dist/runtime/core/hooks.d.mts.map +1 -0
  124. package/dist/runtime/core/hooks.mjs +24 -0
  125. package/dist/runtime/core/hooks.mjs.map +1 -0
  126. package/dist/runtime/core/learning.cjs +61 -0
  127. package/dist/runtime/core/learning.cjs.map +1 -0
  128. package/dist/runtime/core/learning.d.cts +61 -0
  129. package/dist/runtime/core/learning.d.cts.map +1 -0
  130. package/dist/runtime/core/learning.d.mts +61 -0
  131. package/dist/runtime/core/learning.d.mts.map +1 -0
  132. package/dist/runtime/core/learning.mjs +56 -0
  133. package/dist/runtime/core/learning.mjs.map +1 -0
  134. package/dist/runtime/core/logger.cjs +21 -0
  135. package/dist/runtime/core/logger.cjs.map +1 -0
  136. package/dist/runtime/core/logger.d.cts +12 -0
  137. package/dist/runtime/core/logger.d.cts.map +1 -0
  138. package/dist/runtime/core/logger.d.mts +12 -0
  139. package/dist/runtime/core/logger.d.mts.map +1 -0
  140. package/dist/runtime/core/logger.mjs +18 -0
  141. package/dist/runtime/core/logger.mjs.map +1 -0
  142. package/dist/runtime/core/middleware-sse-parser.cjs +149 -0
  143. package/dist/runtime/core/middleware-sse-parser.cjs.map +1 -0
  144. package/dist/runtime/core/middleware-sse-parser.d.cts +21 -0
  145. package/dist/runtime/core/middleware-sse-parser.d.cts.map +1 -0
  146. package/dist/runtime/core/middleware-sse-parser.d.mts +21 -0
  147. package/dist/runtime/core/middleware-sse-parser.d.mts.map +1 -0
  148. package/dist/runtime/core/middleware-sse-parser.mjs +148 -0
  149. package/dist/runtime/core/middleware-sse-parser.mjs.map +1 -0
  150. package/dist/runtime/core/middleware.cjs +34 -0
  151. package/dist/runtime/core/middleware.cjs.map +1 -0
  152. package/dist/runtime/core/middleware.d.cts +31 -0
  153. package/dist/runtime/core/middleware.d.cts.map +1 -0
  154. package/dist/runtime/core/middleware.d.mts +31 -0
  155. package/dist/runtime/core/middleware.d.mts.map +1 -0
  156. package/dist/runtime/core/middleware.mjs +32 -0
  157. package/dist/runtime/core/middleware.mjs.map +1 -0
  158. package/dist/runtime/core/package-info.cjs +9 -0
  159. package/dist/runtime/core/package-info.cjs.map +1 -0
  160. package/dist/runtime/core/package-info.mjs +7 -0
  161. package/dist/runtime/core/package-info.mjs.map +1 -0
  162. package/dist/runtime/core/runtime-error-reporter.cjs +21 -0
  163. package/dist/runtime/core/runtime-error-reporter.cjs.map +1 -0
  164. package/dist/runtime/core/runtime-error-reporter.mjs +18 -0
  165. package/dist/runtime/core/runtime-error-reporter.mjs.map +1 -0
  166. package/dist/runtime/core/runtime.cjs +256 -0
  167. package/dist/runtime/core/runtime.cjs.map +1 -0
  168. package/dist/runtime/core/runtime.d.cts +481 -0
  169. package/dist/runtime/core/runtime.d.cts.map +1 -0
  170. package/dist/runtime/core/runtime.d.mts +481 -0
  171. package/dist/runtime/core/runtime.d.mts.map +1 -0
  172. package/dist/runtime/core/runtime.mjs +249 -0
  173. package/dist/runtime/core/runtime.mjs.map +1 -0
  174. package/dist/runtime/endpoints/auto-start-channels.cjs +46 -0
  175. package/dist/runtime/endpoints/auto-start-channels.cjs.map +1 -0
  176. package/dist/runtime/endpoints/auto-start-channels.mjs +45 -0
  177. package/dist/runtime/endpoints/auto-start-channels.mjs.map +1 -0
  178. package/dist/runtime/endpoints/node-fetch-handler.cjs +75 -0
  179. package/dist/runtime/endpoints/node-fetch-handler.cjs.map +1 -0
  180. package/dist/runtime/endpoints/node-fetch-handler.d.cts +11 -0
  181. package/dist/runtime/endpoints/node-fetch-handler.d.cts.map +1 -0
  182. package/dist/runtime/endpoints/node-fetch-handler.d.mts +11 -0
  183. package/dist/runtime/endpoints/node-fetch-handler.d.mts.map +1 -0
  184. package/dist/runtime/endpoints/node-fetch-handler.mjs +73 -0
  185. package/dist/runtime/endpoints/node-fetch-handler.mjs.map +1 -0
  186. package/dist/runtime/endpoints/node.cjs +16 -0
  187. package/dist/runtime/endpoints/node.cjs.map +1 -0
  188. package/dist/runtime/endpoints/node.d.cts +104 -0
  189. package/dist/runtime/endpoints/node.d.cts.map +1 -0
  190. package/dist/runtime/endpoints/node.d.mts +104 -0
  191. package/dist/runtime/endpoints/node.d.mts.map +1 -0
  192. package/dist/runtime/endpoints/node.mjs +16 -0
  193. package/dist/runtime/endpoints/node.mjs.map +1 -0
  194. package/dist/runtime/endpoints/single-route-helpers.cjs +130 -0
  195. package/dist/runtime/endpoints/single-route-helpers.cjs.map +1 -0
  196. package/dist/runtime/endpoints/single-route-helpers.mjs +125 -0
  197. package/dist/runtime/endpoints/single-route-helpers.mjs.map +1 -0
  198. package/dist/runtime/generative-ui/generative-ui-middleware.cjs +393 -0
  199. package/dist/runtime/generative-ui/generative-ui-middleware.cjs.map +1 -0
  200. package/dist/runtime/generative-ui/generative-ui-middleware.d.cts +20 -0
  201. package/dist/runtime/generative-ui/generative-ui-middleware.d.cts.map +1 -0
  202. package/dist/runtime/generative-ui/generative-ui-middleware.d.mts +20 -0
  203. package/dist/runtime/generative-ui/generative-ui-middleware.d.mts.map +1 -0
  204. package/dist/runtime/generative-ui/generative-ui-middleware.mjs +392 -0
  205. package/dist/runtime/generative-ui/generative-ui-middleware.mjs.map +1 -0
  206. package/dist/runtime/generative-ui/index.d.cts +2 -0
  207. package/dist/runtime/generative-ui/index.d.mts +2 -0
  208. package/dist/runtime/generative-ui/surface-writer.cjs +85 -0
  209. package/dist/runtime/generative-ui/surface-writer.cjs.map +1 -0
  210. package/dist/runtime/generative-ui/surface-writer.d.cts +32 -0
  211. package/dist/runtime/generative-ui/surface-writer.d.cts.map +1 -0
  212. package/dist/runtime/generative-ui/surface-writer.d.mts +32 -0
  213. package/dist/runtime/generative-ui/surface-writer.d.mts.map +1 -0
  214. package/dist/runtime/generative-ui/surface-writer.mjs +84 -0
  215. package/dist/runtime/generative-ui/surface-writer.mjs.map +1 -0
  216. package/dist/runtime/handlers/get-runtime-info.cjs +140 -0
  217. package/dist/runtime/handlers/get-runtime-info.cjs.map +1 -0
  218. package/dist/runtime/handlers/get-runtime-info.mjs +140 -0
  219. package/dist/runtime/handlers/get-runtime-info.mjs.map +1 -0
  220. package/dist/runtime/handlers/handle-connect.cjs +62 -0
  221. package/dist/runtime/handlers/handle-connect.cjs.map +1 -0
  222. package/dist/runtime/handlers/handle-connect.mjs +62 -0
  223. package/dist/runtime/handlers/handle-connect.mjs.map +1 -0
  224. package/dist/runtime/handlers/handle-debug-events.cjs +33 -0
  225. package/dist/runtime/handlers/handle-debug-events.cjs.map +1 -0
  226. package/dist/runtime/handlers/handle-debug-events.mjs +33 -0
  227. package/dist/runtime/handlers/handle-debug-events.mjs.map +1 -0
  228. package/dist/runtime/handlers/handle-inspector-learning.cjs +56 -0
  229. package/dist/runtime/handlers/handle-inspector-learning.cjs.map +1 -0
  230. package/dist/runtime/handlers/handle-inspector-learning.mjs +55 -0
  231. package/dist/runtime/handlers/handle-inspector-learning.mjs.map +1 -0
  232. package/dist/runtime/handlers/handle-inspector-metadata.cjs +36 -0
  233. package/dist/runtime/handlers/handle-inspector-metadata.cjs.map +1 -0
  234. package/dist/runtime/handlers/handle-inspector-metadata.mjs +35 -0
  235. package/dist/runtime/handlers/handle-inspector-metadata.mjs.map +1 -0
  236. package/dist/runtime/handlers/handle-run.cjs +111 -0
  237. package/dist/runtime/handlers/handle-run.cjs.map +1 -0
  238. package/dist/runtime/handlers/handle-run.mjs +110 -0
  239. package/dist/runtime/handlers/handle-run.mjs.map +1 -0
  240. package/dist/runtime/handlers/handle-stop.cjs +102 -0
  241. package/dist/runtime/handlers/handle-stop.cjs.map +1 -0
  242. package/dist/runtime/handlers/handle-stop.mjs +101 -0
  243. package/dist/runtime/handlers/handle-stop.mjs.map +1 -0
  244. package/dist/runtime/handlers/handle-suggest.cjs +83 -0
  245. package/dist/runtime/handlers/handle-suggest.cjs.map +1 -0
  246. package/dist/runtime/handlers/handle-suggest.mjs +82 -0
  247. package/dist/runtime/handlers/handle-suggest.mjs.map +1 -0
  248. package/dist/runtime/handlers/handle-trajectory-connect.cjs +40 -0
  249. package/dist/runtime/handlers/handle-trajectory-connect.cjs.map +1 -0
  250. package/dist/runtime/handlers/handle-trajectory-connect.mjs +39 -0
  251. package/dist/runtime/handlers/handle-trajectory-connect.mjs.map +1 -0
  252. package/dist/runtime/handlers/handle-transcribe.cjs +112 -0
  253. package/dist/runtime/handlers/handle-transcribe.cjs.map +1 -0
  254. package/dist/runtime/handlers/handle-transcribe.mjs +111 -0
  255. package/dist/runtime/handlers/handle-transcribe.mjs.map +1 -0
  256. package/dist/runtime/handlers/header-utils.cjs +185 -0
  257. package/dist/runtime/handlers/header-utils.cjs.map +1 -0
  258. package/dist/runtime/handlers/header-utils.d.cts +53 -0
  259. package/dist/runtime/handlers/header-utils.d.cts.map +1 -0
  260. package/dist/runtime/handlers/header-utils.d.mts +53 -0
  261. package/dist/runtime/handlers/header-utils.d.mts.map +1 -0
  262. package/dist/runtime/handlers/header-utils.mjs +183 -0
  263. package/dist/runtime/handlers/header-utils.mjs.map +1 -0
  264. package/dist/runtime/handlers/intelligence/annotate.cjs +83 -0
  265. package/dist/runtime/handlers/intelligence/annotate.cjs.map +1 -0
  266. package/dist/runtime/handlers/intelligence/annotate.mjs +82 -0
  267. package/dist/runtime/handlers/intelligence/annotate.mjs.map +1 -0
  268. package/dist/runtime/handlers/intelligence/connect.cjs +68 -0
  269. package/dist/runtime/handlers/intelligence/connect.cjs.map +1 -0
  270. package/dist/runtime/handlers/intelligence/connect.mjs +68 -0
  271. package/dist/runtime/handlers/intelligence/connect.mjs.map +1 -0
  272. package/dist/runtime/handlers/intelligence/memories.cjs +260 -0
  273. package/dist/runtime/handlers/intelligence/memories.cjs.map +1 -0
  274. package/dist/runtime/handlers/intelligence/memories.mjs +254 -0
  275. package/dist/runtime/handlers/intelligence/memories.mjs.map +1 -0
  276. package/dist/runtime/handlers/intelligence/run.cjs +283 -0
  277. package/dist/runtime/handlers/intelligence/run.cjs.map +1 -0
  278. package/dist/runtime/handlers/intelligence/run.mjs +282 -0
  279. package/dist/runtime/handlers/intelligence/run.mjs.map +1 -0
  280. package/dist/runtime/handlers/intelligence/thread-names.cjs +172 -0
  281. package/dist/runtime/handlers/intelligence/thread-names.cjs.map +1 -0
  282. package/dist/runtime/handlers/intelligence/thread-names.mjs +171 -0
  283. package/dist/runtime/handlers/intelligence/thread-names.mjs.map +1 -0
  284. package/dist/runtime/handlers/intelligence/threads.cjs +399 -0
  285. package/dist/runtime/handlers/intelligence/threads.cjs.map +1 -0
  286. package/dist/runtime/handlers/intelligence/threads.mjs +390 -0
  287. package/dist/runtime/handlers/intelligence/threads.mjs.map +1 -0
  288. package/dist/runtime/handlers/shared/agent-utils.cjs +267 -0
  289. package/dist/runtime/handlers/shared/agent-utils.cjs.map +1 -0
  290. package/dist/runtime/handlers/shared/agent-utils.mjs +262 -0
  291. package/dist/runtime/handlers/shared/agent-utils.mjs.map +1 -0
  292. package/dist/runtime/handlers/shared/cloud-telemetry.cjs +30 -0
  293. package/dist/runtime/handlers/shared/cloud-telemetry.cjs.map +1 -0
  294. package/dist/runtime/handlers/shared/cloud-telemetry.mjs +29 -0
  295. package/dist/runtime/handlers/shared/cloud-telemetry.mjs.map +1 -0
  296. package/dist/runtime/handlers/shared/describe-endpoint.cjs +25 -0
  297. package/dist/runtime/handlers/shared/describe-endpoint.cjs.map +1 -0
  298. package/dist/runtime/handlers/shared/describe-endpoint.mjs +24 -0
  299. package/dist/runtime/handlers/shared/describe-endpoint.mjs.map +1 -0
  300. package/dist/runtime/handlers/shared/intelligence-utils.cjs +24 -0
  301. package/dist/runtime/handlers/shared/intelligence-utils.cjs.map +1 -0
  302. package/dist/runtime/handlers/shared/intelligence-utils.mjs +23 -0
  303. package/dist/runtime/handlers/shared/intelligence-utils.mjs.map +1 -0
  304. package/dist/runtime/handlers/shared/json-response.cjs +14 -0
  305. package/dist/runtime/handlers/shared/json-response.cjs.map +1 -0
  306. package/dist/runtime/handlers/shared/json-response.mjs +12 -0
  307. package/dist/runtime/handlers/shared/json-response.mjs.map +1 -0
  308. package/dist/runtime/handlers/shared/mcp-apps-servers.cjs +22 -0
  309. package/dist/runtime/handlers/shared/mcp-apps-servers.cjs.map +1 -0
  310. package/dist/runtime/handlers/shared/mcp-apps-servers.mjs +22 -0
  311. package/dist/runtime/handlers/shared/mcp-apps-servers.mjs.map +1 -0
  312. package/dist/runtime/handlers/shared/memory-policy.cjs +78 -0
  313. package/dist/runtime/handlers/shared/memory-policy.cjs.map +1 -0
  314. package/dist/runtime/handlers/shared/memory-policy.mjs +77 -0
  315. package/dist/runtime/handlers/shared/memory-policy.mjs.map +1 -0
  316. package/dist/runtime/handlers/shared/platform-error.cjs +39 -0
  317. package/dist/runtime/handlers/shared/platform-error.cjs.map +1 -0
  318. package/dist/runtime/handlers/shared/platform-error.mjs +39 -0
  319. package/dist/runtime/handlers/shared/platform-error.mjs.map +1 -0
  320. package/dist/runtime/handlers/shared/resolve-intelligence-user.cjs +50 -0
  321. package/dist/runtime/handlers/shared/resolve-intelligence-user.cjs.map +1 -0
  322. package/dist/runtime/handlers/shared/resolve-intelligence-user.mjs +49 -0
  323. package/dist/runtime/handlers/shared/resolve-intelligence-user.mjs.map +1 -0
  324. package/dist/runtime/handlers/shared/sse-keep-alive.cjs +68 -0
  325. package/dist/runtime/handlers/shared/sse-keep-alive.cjs.map +1 -0
  326. package/dist/runtime/handlers/shared/sse-keep-alive.mjs +66 -0
  327. package/dist/runtime/handlers/shared/sse-keep-alive.mjs.map +1 -0
  328. package/dist/runtime/handlers/shared/sse-response.cjs +237 -0
  329. package/dist/runtime/handlers/shared/sse-response.cjs.map +1 -0
  330. package/dist/runtime/handlers/shared/sse-response.mjs +236 -0
  331. package/dist/runtime/handlers/shared/sse-response.mjs.map +1 -0
  332. package/dist/runtime/handlers/shared/thread-access.cjs +137 -0
  333. package/dist/runtime/handlers/shared/thread-access.cjs.map +1 -0
  334. package/dist/runtime/handlers/shared/thread-access.d.cts +28 -0
  335. package/dist/runtime/handlers/shared/thread-access.d.cts.map +1 -0
  336. package/dist/runtime/handlers/shared/thread-access.d.mts +28 -0
  337. package/dist/runtime/handlers/shared/thread-access.d.mts.map +1 -0
  338. package/dist/runtime/handlers/shared/thread-access.mjs +132 -0
  339. package/dist/runtime/handlers/shared/thread-access.mjs.map +1 -0
  340. package/dist/runtime/handlers/sse/connect.cjs +23 -0
  341. package/dist/runtime/handlers/sse/connect.cjs.map +1 -0
  342. package/dist/runtime/handlers/sse/connect.mjs +23 -0
  343. package/dist/runtime/handlers/sse/connect.mjs.map +1 -0
  344. package/dist/runtime/handlers/sse/run.cjs +44 -0
  345. package/dist/runtime/handlers/sse/run.cjs.map +1 -0
  346. package/dist/runtime/handlers/sse/run.mjs +44 -0
  347. package/dist/runtime/handlers/sse/run.mjs.map +1 -0
  348. package/dist/runtime/index.d.cts +29 -0
  349. package/dist/runtime/index.d.cts.map +1 -0
  350. package/dist/runtime/index.d.mts +29 -0
  351. package/dist/runtime/index.d.mts.map +1 -0
  352. package/dist/runtime/intelligence-platform/client.cjs +1338 -0
  353. package/dist/runtime/intelligence-platform/client.cjs.map +1 -0
  354. package/dist/runtime/intelligence-platform/client.d.cts +824 -0
  355. package/dist/runtime/intelligence-platform/client.d.cts.map +1 -0
  356. package/dist/runtime/intelligence-platform/client.d.mts +824 -0
  357. package/dist/runtime/intelligence-platform/client.d.mts.map +1 -0
  358. package/dist/runtime/intelligence-platform/client.mjs +1334 -0
  359. package/dist/runtime/intelligence-platform/client.mjs.map +1 -0
  360. package/dist/runtime/intelligence-platform/experimental.d.cts +26 -0
  361. package/dist/runtime/intelligence-platform/experimental.d.cts.map +1 -0
  362. package/dist/runtime/intelligence-platform/experimental.d.mts +26 -0
  363. package/dist/runtime/intelligence-platform/experimental.d.mts.map +1 -0
  364. package/dist/runtime/intelligence-platform/index.d.cts +3 -0
  365. package/dist/runtime/intelligence-platform/index.d.mts +3 -0
  366. package/dist/runtime/intelligence-platform/learned-skills.cjs +95 -0
  367. package/dist/runtime/intelligence-platform/learned-skills.cjs.map +1 -0
  368. package/dist/runtime/intelligence-platform/learned-skills.d.cts +43 -0
  369. package/dist/runtime/intelligence-platform/learned-skills.d.cts.map +1 -0
  370. package/dist/runtime/intelligence-platform/learned-skills.d.mts +43 -0
  371. package/dist/runtime/intelligence-platform/learned-skills.d.mts.map +1 -0
  372. package/dist/runtime/intelligence-platform/learned-skills.mjs +92 -0
  373. package/dist/runtime/intelligence-platform/learned-skills.mjs.map +1 -0
  374. package/dist/runtime/intelligence-platform/learning-management.cjs +203 -0
  375. package/dist/runtime/intelligence-platform/learning-management.cjs.map +1 -0
  376. package/dist/runtime/intelligence-platform/learning-management.d.cts +111 -0
  377. package/dist/runtime/intelligence-platform/learning-management.d.cts.map +1 -0
  378. package/dist/runtime/intelligence-platform/learning-management.d.mts +111 -0
  379. package/dist/runtime/intelligence-platform/learning-management.d.mts.map +1 -0
  380. package/dist/runtime/intelligence-platform/learning-management.mjs +193 -0
  381. package/dist/runtime/intelligence-platform/learning-management.mjs.map +1 -0
  382. package/dist/runtime/intelligence-platform/skill-registry/archive.cjs +131 -0
  383. package/dist/runtime/intelligence-platform/skill-registry/archive.cjs.map +1 -0
  384. package/dist/runtime/intelligence-platform/skill-registry/archive.d.cts +10 -0
  385. package/dist/runtime/intelligence-platform/skill-registry/archive.d.cts.map +1 -0
  386. package/dist/runtime/intelligence-platform/skill-registry/archive.d.mts +10 -0
  387. package/dist/runtime/intelligence-platform/skill-registry/archive.d.mts.map +1 -0
  388. package/dist/runtime/intelligence-platform/skill-registry/archive.mjs +127 -0
  389. package/dist/runtime/intelligence-platform/skill-registry/archive.mjs.map +1 -0
  390. package/dist/runtime/intelligence-platform/skill-registry/config.cjs +65 -0
  391. package/dist/runtime/intelligence-platform/skill-registry/config.cjs.map +1 -0
  392. package/dist/runtime/intelligence-platform/skill-registry/config.d.cts +47 -0
  393. package/dist/runtime/intelligence-platform/skill-registry/config.d.cts.map +1 -0
  394. package/dist/runtime/intelligence-platform/skill-registry/config.d.mts +47 -0
  395. package/dist/runtime/intelligence-platform/skill-registry/config.d.mts.map +1 -0
  396. package/dist/runtime/intelligence-platform/skill-registry/config.mjs +65 -0
  397. package/dist/runtime/intelligence-platform/skill-registry/config.mjs.map +1 -0
  398. package/dist/runtime/intelligence-platform/skill-registry/errors.cjs +10 -0
  399. package/dist/runtime/intelligence-platform/skill-registry/errors.cjs.map +1 -0
  400. package/dist/runtime/intelligence-platform/skill-registry/errors.d.cts +7 -0
  401. package/dist/runtime/intelligence-platform/skill-registry/errors.d.cts.map +1 -0
  402. package/dist/runtime/intelligence-platform/skill-registry/errors.d.mts +7 -0
  403. package/dist/runtime/intelligence-platform/skill-registry/errors.d.mts.map +1 -0
  404. package/dist/runtime/intelligence-platform/skill-registry/errors.mjs +10 -0
  405. package/dist/runtime/intelligence-platform/skill-registry/errors.mjs.map +1 -0
  406. package/dist/runtime/intelligence-platform/skill-registry/index.d.cts +7 -0
  407. package/dist/runtime/intelligence-platform/skill-registry/index.d.mts +7 -0
  408. package/dist/runtime/intelligence-platform/skill-registry/registry.cjs +247 -0
  409. package/dist/runtime/intelligence-platform/skill-registry/registry.cjs.map +1 -0
  410. package/dist/runtime/intelligence-platform/skill-registry/registry.d.cts +36 -0
  411. package/dist/runtime/intelligence-platform/skill-registry/registry.d.cts.map +1 -0
  412. package/dist/runtime/intelligence-platform/skill-registry/registry.d.mts +36 -0
  413. package/dist/runtime/intelligence-platform/skill-registry/registry.d.mts.map +1 -0
  414. package/dist/runtime/intelligence-platform/skill-registry/registry.mjs +246 -0
  415. package/dist/runtime/intelligence-platform/skill-registry/registry.mjs.map +1 -0
  416. package/dist/runtime/intelligence-platform/skill-registry/skill-content.cjs +41 -0
  417. package/dist/runtime/intelligence-platform/skill-registry/skill-content.cjs.map +1 -0
  418. package/dist/runtime/intelligence-platform/skill-registry/skill-content.d.cts +12 -0
  419. package/dist/runtime/intelligence-platform/skill-registry/skill-content.d.cts.map +1 -0
  420. package/dist/runtime/intelligence-platform/skill-registry/skill-content.d.mts +12 -0
  421. package/dist/runtime/intelligence-platform/skill-registry/skill-content.d.mts.map +1 -0
  422. package/dist/runtime/intelligence-platform/skill-registry/skill-content.mjs +38 -0
  423. package/dist/runtime/intelligence-platform/skill-registry/skill-content.mjs.map +1 -0
  424. package/dist/runtime/intelligence-platform/skill-registry/snapshot.cjs +92 -0
  425. package/dist/runtime/intelligence-platform/skill-registry/snapshot.cjs.map +1 -0
  426. package/dist/runtime/intelligence-platform/skill-registry/snapshot.d.cts +27 -0
  427. package/dist/runtime/intelligence-platform/skill-registry/snapshot.d.cts.map +1 -0
  428. package/dist/runtime/intelligence-platform/skill-registry/snapshot.d.mts +27 -0
  429. package/dist/runtime/intelligence-platform/skill-registry/snapshot.d.mts.map +1 -0
  430. package/dist/runtime/intelligence-platform/skill-registry/snapshot.mjs +91 -0
  431. package/dist/runtime/intelligence-platform/skill-registry/snapshot.mjs.map +1 -0
  432. package/dist/runtime/intelligence-platform/thread-lock-heartbeat.cjs +142 -0
  433. package/dist/runtime/intelligence-platform/thread-lock-heartbeat.cjs.map +1 -0
  434. package/dist/runtime/intelligence-platform/thread-lock-heartbeat.mjs +141 -0
  435. package/dist/runtime/intelligence-platform/thread-lock-heartbeat.mjs.map +1 -0
  436. package/dist/runtime/intelligence-platform/trajectories.cjs +95 -0
  437. package/dist/runtime/intelligence-platform/trajectories.cjs.map +1 -0
  438. package/dist/runtime/intelligence-platform/trajectories.d.cts +11 -0
  439. package/dist/runtime/intelligence-platform/trajectories.d.cts.map +1 -0
  440. package/dist/runtime/intelligence-platform/trajectories.d.mts +11 -0
  441. package/dist/runtime/intelligence-platform/trajectories.d.mts.map +1 -0
  442. package/dist/runtime/intelligence-platform/trajectories.mjs +91 -0
  443. package/dist/runtime/intelligence-platform/trajectories.mjs.map +1 -0
  444. package/dist/runtime/node.d.cts +2 -0
  445. package/dist/runtime/node.d.mts +2 -0
  446. package/dist/runtime/runner/agent-runner.cjs +82 -0
  447. package/dist/runtime/runner/agent-runner.cjs.map +1 -0
  448. package/dist/runtime/runner/agent-runner.d.cts +151 -0
  449. package/dist/runtime/runner/agent-runner.d.cts.map +1 -0
  450. package/dist/runtime/runner/agent-runner.d.mts +151 -0
  451. package/dist/runtime/runner/agent-runner.d.mts.map +1 -0
  452. package/dist/runtime/runner/agent-runner.mjs +73 -0
  453. package/dist/runtime/runner/agent-runner.mjs.map +1 -0
  454. package/dist/runtime/runner/in-memory.cjs +741 -0
  455. package/dist/runtime/runner/in-memory.cjs.map +1 -0
  456. package/dist/runtime/runner/in-memory.d.cts +427 -0
  457. package/dist/runtime/runner/in-memory.d.cts.map +1 -0
  458. package/dist/runtime/runner/in-memory.d.mts +427 -0
  459. package/dist/runtime/runner/in-memory.d.mts.map +1 -0
  460. package/dist/runtime/runner/in-memory.mjs +734 -0
  461. package/dist/runtime/runner/in-memory.mjs.map +1 -0
  462. package/dist/runtime/runner/index.d.cts +5 -0
  463. package/dist/runtime/runner/index.d.mts +5 -0
  464. package/dist/runtime/runner/index.mjs +6 -0
  465. package/dist/runtime/runner/intelligence.cjs +617 -0
  466. package/dist/runtime/runner/intelligence.cjs.map +1 -0
  467. package/dist/runtime/runner/intelligence.d.cts +104 -0
  468. package/dist/runtime/runner/intelligence.d.cts.map +1 -0
  469. package/dist/runtime/runner/intelligence.d.mts +104 -0
  470. package/dist/runtime/runner/intelligence.d.mts.map +1 -0
  471. package/dist/runtime/runner/intelligence.mjs +616 -0
  472. package/dist/runtime/runner/intelligence.mjs.map +1 -0
  473. package/dist/runtime/telemetry/disclosure.cjs +25 -0
  474. package/dist/runtime/telemetry/disclosure.cjs.map +1 -0
  475. package/dist/runtime/telemetry/disclosure.mjs +24 -0
  476. package/dist/runtime/telemetry/disclosure.mjs.map +1 -0
  477. package/dist/runtime/telemetry/events.d.cts +66 -0
  478. package/dist/runtime/telemetry/events.d.cts.map +1 -0
  479. package/dist/runtime/telemetry/events.d.mts +66 -0
  480. package/dist/runtime/telemetry/events.d.mts.map +1 -0
  481. package/dist/runtime/telemetry/instance-created.cjs +34 -0
  482. package/dist/runtime/telemetry/instance-created.cjs.map +1 -0
  483. package/dist/runtime/telemetry/instance-created.mjs +34 -0
  484. package/dist/runtime/telemetry/instance-created.mjs.map +1 -0
  485. package/dist/runtime/telemetry/telemetry-client.cjs +108 -0
  486. package/dist/runtime/telemetry/telemetry-client.cjs.map +1 -0
  487. package/dist/runtime/telemetry/telemetry-client.d.cts +10 -0
  488. package/dist/runtime/telemetry/telemetry-client.d.cts.map +1 -0
  489. package/dist/runtime/telemetry/telemetry-client.d.mts +10 -0
  490. package/dist/runtime/telemetry/telemetry-client.d.mts.map +1 -0
  491. package/dist/runtime/telemetry/telemetry-client.mjs +107 -0
  492. package/dist/runtime/telemetry/telemetry-client.mjs.map +1 -0
  493. package/dist/runtime/telemetry/telemetry-identity.cjs +12 -0
  494. package/dist/runtime/telemetry/telemetry-identity.cjs.map +1 -0
  495. package/dist/runtime/telemetry/telemetry-identity.mjs +11 -0
  496. package/dist/runtime/telemetry/telemetry-identity.mjs.map +1 -0
  497. package/dist/runtime/transcription-service/transcription-service.cjs +7 -0
  498. package/dist/runtime/transcription-service/transcription-service.cjs.map +1 -0
  499. package/dist/runtime/transcription-service/transcription-service.d.cts +14 -0
  500. package/dist/runtime/transcription-service/transcription-service.d.cts.map +1 -0
  501. package/dist/runtime/transcription-service/transcription-service.d.mts +14 -0
  502. package/dist/runtime/transcription-service/transcription-service.d.mts.map +1 -0
  503. package/dist/runtime/transcription-service/transcription-service.mjs +6 -0
  504. package/dist/runtime/transcription-service/transcription-service.mjs.map +1 -0
  505. package/package.json +104 -105
  506. package/.eslintrc.js +0 -7
  507. package/CHANGELOG.md +0 -2920
  508. package/__snapshots__/schema/schema.graphql +0 -371
  509. package/dist/index.d.ts +0 -1494
  510. package/dist/index.js +0 -5641
  511. package/dist/index.js.map +0 -1
  512. package/dist/index.mjs.map +0 -1
  513. package/dist/langgraph.d.ts +0 -284
  514. package/dist/langgraph.js +0 -211
  515. package/dist/langgraph.js.map +0 -1
  516. package/dist/langgraph.mjs +0 -206
  517. package/dist/langgraph.mjs.map +0 -1
  518. package/dist/v2/index.d.ts +0 -2
  519. package/dist/v2/index.js +0 -22
  520. package/dist/v2/index.js.map +0 -1
  521. package/dist/v2/index.mjs +0 -5
  522. package/dist/v2/index.mjs.map +0 -1
  523. package/jest.config.js +0 -10
  524. package/scripts/generate-gql-schema.ts +0 -13
  525. package/src/agents/langgraph/event-source.ts +0 -329
  526. package/src/agents/langgraph/events.ts +0 -377
  527. package/src/graphql/inputs/action.input.ts +0 -16
  528. package/src/graphql/inputs/agent-session.input.ts +0 -13
  529. package/src/graphql/inputs/agent-state.input.ts +0 -13
  530. package/src/graphql/inputs/cloud-guardrails.input.ts +0 -16
  531. package/src/graphql/inputs/cloud.input.ts +0 -8
  532. package/src/graphql/inputs/context-property.input.ts +0 -10
  533. package/src/graphql/inputs/copilot-context.input.ts +0 -10
  534. package/src/graphql/inputs/custom-property.input.ts +0 -15
  535. package/src/graphql/inputs/extensions.input.ts +0 -21
  536. package/src/graphql/inputs/forwarded-parameters.input.ts +0 -22
  537. package/src/graphql/inputs/frontend.input.ts +0 -14
  538. package/src/graphql/inputs/generate-copilot-response.input.ts +0 -59
  539. package/src/graphql/inputs/load-agent-state.input.ts +0 -10
  540. package/src/graphql/inputs/message.input.ts +0 -110
  541. package/src/graphql/inputs/meta-event.input.ts +0 -18
  542. package/src/graphql/message-conversion/agui-to-gql.test.ts +0 -1263
  543. package/src/graphql/message-conversion/agui-to-gql.ts +0 -333
  544. package/src/graphql/message-conversion/gql-to-agui.test.ts +0 -1580
  545. package/src/graphql/message-conversion/gql-to-agui.ts +0 -278
  546. package/src/graphql/message-conversion/index.ts +0 -2
  547. package/src/graphql/message-conversion/roundtrip-conversion.test.ts +0 -526
  548. package/src/graphql/resolvers/copilot.resolver.ts +0 -708
  549. package/src/graphql/resolvers/state.resolver.ts +0 -27
  550. package/src/graphql/types/agents-response.type.ts +0 -19
  551. package/src/graphql/types/base/index.ts +0 -10
  552. package/src/graphql/types/converted/index.ts +0 -176
  553. package/src/graphql/types/copilot-response.type.ts +0 -138
  554. package/src/graphql/types/enums.ts +0 -38
  555. package/src/graphql/types/extensions-response.type.ts +0 -23
  556. package/src/graphql/types/guardrails-result.type.ts +0 -20
  557. package/src/graphql/types/load-agent-state-response.type.ts +0 -17
  558. package/src/graphql/types/message-status.type.ts +0 -42
  559. package/src/graphql/types/meta-events.type.ts +0 -71
  560. package/src/graphql/types/response-status.type.ts +0 -66
  561. package/src/index.ts +0 -4
  562. package/src/langgraph.ts +0 -1
  563. package/src/lib/cloud/index.ts +0 -4
  564. package/src/lib/error-messages.ts +0 -200
  565. package/src/lib/index.ts +0 -52
  566. package/src/lib/integrations/index.ts +0 -6
  567. package/src/lib/integrations/nest/index.ts +0 -14
  568. package/src/lib/integrations/nextjs/app-router.ts +0 -38
  569. package/src/lib/integrations/nextjs/pages-router.ts +0 -39
  570. package/src/lib/integrations/node-express/index.ts +0 -14
  571. package/src/lib/integrations/node-http/index.ts +0 -143
  572. package/src/lib/integrations/node-http/request-handler.ts +0 -111
  573. package/src/lib/integrations/shared.ts +0 -161
  574. package/src/lib/logger.ts +0 -28
  575. package/src/lib/observability.ts +0 -160
  576. package/src/lib/runtime/__tests__/copilot-runtime-error.test.ts +0 -169
  577. package/src/lib/runtime/__tests__/mcp-tools-utils.test.ts +0 -464
  578. package/src/lib/runtime/agent-integrations/langgraph/agent.ts +0 -209
  579. package/src/lib/runtime/agent-integrations/langgraph/consts.ts +0 -34
  580. package/src/lib/runtime/agent-integrations/langgraph/index.ts +0 -2
  581. package/src/lib/runtime/copilot-runtime.ts +0 -710
  582. package/src/lib/runtime/mcp-tools-utils.ts +0 -254
  583. package/src/lib/runtime/retry-utils.ts +0 -96
  584. package/src/lib/runtime/telemetry-agent-runner.ts +0 -139
  585. package/src/lib/runtime/types.ts +0 -49
  586. package/src/lib/runtime/utils.ts +0 -87
  587. package/src/lib/streaming.ts +0 -202
  588. package/src/lib/telemetry-client.ts +0 -64
  589. package/src/service-adapters/anthropic/anthropic-adapter.ts +0 -452
  590. package/src/service-adapters/anthropic/utils.ts +0 -152
  591. package/src/service-adapters/bedrock/bedrock-adapter.ts +0 -73
  592. package/src/service-adapters/conversion.ts +0 -67
  593. package/src/service-adapters/empty/empty-adapter.ts +0 -38
  594. package/src/service-adapters/events.ts +0 -294
  595. package/src/service-adapters/experimental/ollama/ollama-adapter.ts +0 -84
  596. package/src/service-adapters/google/google-genai-adapter.test.ts +0 -104
  597. package/src/service-adapters/google/google-genai-adapter.ts +0 -88
  598. package/src/service-adapters/groq/groq-adapter.ts +0 -203
  599. package/src/service-adapters/index.ts +0 -18
  600. package/src/service-adapters/langchain/langchain-adapter.ts +0 -111
  601. package/src/service-adapters/langchain/langserve.ts +0 -88
  602. package/src/service-adapters/langchain/types.ts +0 -14
  603. package/src/service-adapters/langchain/utils.ts +0 -313
  604. package/src/service-adapters/openai/openai-adapter.ts +0 -283
  605. package/src/service-adapters/openai/openai-assistant-adapter.ts +0 -344
  606. package/src/service-adapters/openai/utils.ts +0 -199
  607. package/src/service-adapters/service-adapter.ts +0 -41
  608. package/src/service-adapters/shared/error-utils.ts +0 -61
  609. package/src/service-adapters/shared/index.ts +0 -1
  610. package/src/service-adapters/unify/unify-adapter.ts +0 -151
  611. package/src/utils/failed-response-status-reasons.ts +0 -70
  612. package/src/utils/index.ts +0 -1
  613. package/src/v2/index.ts +0 -3
  614. package/tests/global.d.ts +0 -13
  615. package/tests/service-adapters/anthropic/allowlist-approach.test.ts +0 -226
  616. package/tests/service-adapters/anthropic/anthropic-adapter.test.ts +0 -389
  617. package/tests/service-adapters/openai/allowlist-approach.test.ts +0 -238
  618. package/tests/service-adapters/openai/openai-adapter.test.ts +0 -301
  619. package/tests/setup.jest.ts +0 -21
  620. package/tests/tsconfig.json +0 -10
  621. package/tsconfig.json +0 -13
  622. package/tsup.config.ts +0 -20
  623. package/typedoc.json +0 -4
@@ -0,0 +1,73 @@
1
+ import { logger } from "@copilotkit/shared";
2
+ import { createHeaders, createRequest, sendResponse } from "@remix-run/node-fetch-server";
3
+
4
+ //#region src/runtime/endpoints/node-fetch-handler.ts
5
+ const METHODS_WITHOUT_BODY = new Set([
6
+ "GET",
7
+ "HEAD",
8
+ "OPTIONS"
9
+ ]);
10
+ function createCopilotNodeHandler(handler) {
11
+ return async (req, res) => {
12
+ try {
13
+ const method = (req.method ?? "GET").toUpperCase();
14
+ await sendResponse(res, await handler(!METHODS_WITHOUT_BODY.has(method) && hasPreParsedBody(req) ? buildPreParsedRequest(req, res) : createRequest(req, res)));
15
+ } catch (err) {
16
+ logger.error({ err }, "Error in Node fetch handler");
17
+ if (!res.headersSent) {
18
+ res.statusCode = 500;
19
+ res.end("Internal Server Error");
20
+ }
21
+ }
22
+ };
23
+ }
24
+ /** @deprecated Use `createCopilotNodeHandler` instead. */
25
+ const createNodeFetchHandler = createCopilotNodeHandler;
26
+ /**
27
+ * Build a Fetch Request from a Node IncomingMessage whose body stream has
28
+ * already been consumed by a body parser.
29
+ *
30
+ * The URL, headers and abort wiring match `createRequest` (the streaming path),
31
+ * so a request routes the same way whether or not a parser ran first. In
32
+ * particular the URL comes from `req.url`, which is what a mounting router
33
+ * matched against; `originalUrl` still carries the mount prefix and would miss
34
+ * the handler's `basePath`.
35
+ */
36
+ function buildPreParsedRequest(req, res) {
37
+ const method = (req.method ?? "GET").toUpperCase();
38
+ const headers = createHeaders(req);
39
+ const protocol = "encrypted" in req.socket && req.socket.encrypted ? "https:" : "http:";
40
+ const host = headers.get("host") ?? "localhost";
41
+ const url = new URL(req.url ?? "/", `${protocol}//${host}`);
42
+ const controller = new AbortController();
43
+ res.on("close", () => {
44
+ if (!res.writableFinished) controller.abort();
45
+ });
46
+ const init = {
47
+ method,
48
+ headers,
49
+ signal: controller.signal
50
+ };
51
+ const { body, contentType } = synthesizeBody(req.body);
52
+ if (contentType) headers.set("content-type", contentType);
53
+ headers.delete("content-length");
54
+ if (body !== void 0) init.body = body;
55
+ return new Request(url, init);
56
+ }
57
+ function hasPreParsedBody(req) {
58
+ if (req.body === void 0 || req.body === null) return false;
59
+ return Boolean(req.readableEnded);
60
+ }
61
+ function synthesizeBody(body) {
62
+ if (Buffer.isBuffer(body) || body instanceof Uint8Array) return { body };
63
+ if (typeof body === "string") return { body };
64
+ if (typeof body === "object" && body !== null) return {
65
+ body: JSON.stringify(body),
66
+ contentType: "application/json"
67
+ };
68
+ return {};
69
+ }
70
+
71
+ //#endregion
72
+ export { createCopilotNodeHandler, createNodeFetchHandler };
73
+ //# sourceMappingURL=node-fetch-handler.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"node-fetch-handler.mjs","names":[],"sources":["../../../src/runtime/endpoints/node-fetch-handler.ts"],"sourcesContent":["/**\n * Generic Node ↔ Fetch bridge for CopilotKit runtime.\n *\n * Wraps a `CopilotRuntimeFetchHandler` as a Node HTTP handler using\n * `@remix-run/node-fetch-server` for reliable streaming and conversion.\n *\n * When body-parsing middleware (Express `express.json()`, NestJS's default\n * parser, …) runs first, the Node request stream is already consumed and\n * `req.body` holds the parsed content. Reading the exhausted stream would hang,\n * so that case re-serialises `req.body` into the Fetch `Request` instead.\n *\n * @example\n * ```typescript\n * import { createServer } from \"node:http\";\n * import { createCopilotRuntimeHandler } from \"@copilotkit/runtime\";\n * import { createCopilotNodeHandler } from \"@copilotkit/runtime/node\";\n *\n * const handler = createCopilotRuntimeHandler({ runtime, basePath: \"/api/copilotkit\", cors: true });\n * const nodeHandler = createCopilotNodeHandler(handler);\n * createServer(nodeHandler).listen(3000);\n * ```\n */\n\nimport type { IncomingMessage, ServerResponse } from \"node:http\";\nimport {\n createHeaders,\n createRequest,\n sendResponse,\n} from \"@remix-run/node-fetch-server\";\nimport type { CopilotRuntimeFetchHandler } from \"../core/fetch-handler\";\nimport { logger } from \"@copilotkit/shared\";\n\nconst METHODS_WITHOUT_BODY = new Set([\"GET\", \"HEAD\", \"OPTIONS\"]);\n\nexport type NodeFetchHandler = (\n req: IncomingMessage,\n res: ServerResponse,\n) => Promise<void>;\n\nexport function createCopilotNodeHandler(\n handler: CopilotRuntimeFetchHandler,\n): NodeFetchHandler {\n return async (req: IncomingMessage, res: ServerResponse) => {\n try {\n const method = (req.method ?? \"GET\").toUpperCase();\n const fetchReq =\n !METHODS_WITHOUT_BODY.has(method) && hasPreParsedBody(req)\n ? buildPreParsedRequest(req, res)\n : createRequest(req, res);\n const fetchRes = await handler(fetchReq);\n await sendResponse(res, fetchRes);\n } catch (err: unknown) {\n logger.error({ err }, \"Error in Node fetch handler\");\n if (!res.headersSent) {\n res.statusCode = 500;\n res.end(\"Internal Server Error\");\n }\n }\n };\n}\n\n/** @deprecated Use `createCopilotNodeHandler` instead. */\nexport const createNodeFetchHandler = createCopilotNodeHandler;\n\n/**\n * Build a Fetch Request from a Node IncomingMessage whose body stream has\n * already been consumed by a body parser.\n *\n * The URL, headers and abort wiring match `createRequest` (the streaming path),\n * so a request routes the same way whether or not a parser ran first. In\n * particular the URL comes from `req.url`, which is what a mounting router\n * matched against; `originalUrl` still carries the mount prefix and would miss\n * the handler's `basePath`.\n */\nfunction buildPreParsedRequest(\n req: IncomingMessage & { body?: unknown },\n res: ServerResponse,\n): Request {\n const method = (req.method ?? \"GET\").toUpperCase();\n const headers = createHeaders(req);\n const protocol =\n \"encrypted\" in req.socket && req.socket.encrypted ? \"https:\" : \"http:\";\n const host = headers.get(\"host\") ?? \"localhost\";\n const url = new URL(req.url ?? \"/\", `${protocol}//${host}`);\n\n // Wire an AbortSignal so client disconnects propagate to the fetch handler\n const controller = new AbortController();\n res.on(\"close\", () => {\n if (!res.writableFinished) controller.abort();\n });\n\n const init: RequestInit = {\n method,\n headers,\n signal: controller.signal,\n };\n\n const { body, contentType } = synthesizeBody(req.body);\n if (contentType) {\n headers.set(\"content-type\", contentType);\n }\n headers.delete(\"content-length\");\n if (body !== undefined) {\n init.body = body;\n }\n\n return new Request(url, init);\n}\n\nfunction hasPreParsedBody(req: IncomingMessage & { body?: unknown }): boolean {\n if (req.body === undefined || req.body === null) return false;\n\n // Only `readableEnded` means \"a parser drained this stream to its end\".\n // `req.complete` and the private `_readableState.ended` are set by the HTTP\n // parser once the socket has all the bytes, whether or not anything read them.\n //\n // That distinction matters because `req.body` being set does not prove a parser\n // ran: body-parser 1.x (Express 4) assigns `req.body = req.body || {}` before\n // its own content-type checks, so a request it declines to parse — multipart\n // upload, text/plain — reaches us with `req.body === {}` and a full, unread\n // stream. Treating that as pre-parsed rebuilt the request from `{}` and\n // dropped the real payload.\n return Boolean(req.readableEnded);\n}\n\nfunction synthesizeBody(body: unknown): {\n body?: BodyInit;\n contentType?: string;\n} {\n if (Buffer.isBuffer(body) || body instanceof Uint8Array) {\n // Buffer/Uint8Array<ArrayBufferLike> are valid fetch bodies at runtime,\n // but the DOM lib's BodyInit only admits ArrayBuffer-backed views.\n return { body: body as BodyInit };\n }\n if (typeof body === \"string\") {\n return { body };\n }\n if (typeof body === \"object\" && body !== null) {\n return { body: JSON.stringify(body), contentType: \"application/json\" };\n }\n return {};\n}\n"],"mappings":";;;;AAgCA,MAAM,uBAAuB,IAAI,IAAI;CAAC;CAAO;CAAQ;CAAU,CAAC;AAOhE,SAAgB,yBACd,SACkB;AAClB,QAAO,OAAO,KAAsB,QAAwB;AAC1D,MAAI;GACF,MAAM,UAAU,IAAI,UAAU,OAAO,aAAa;AAMlD,SAAM,aAAa,KADF,MAAM,QAHrB,CAAC,qBAAqB,IAAI,OAAO,IAAI,iBAAiB,IAAI,GACtD,sBAAsB,KAAK,IAAI,GAC/B,cAAc,KAAK,IAAI,CACW,CACP;WAC1B,KAAc;AACrB,UAAO,MAAM,EAAE,KAAK,EAAE,8BAA8B;AACpD,OAAI,CAAC,IAAI,aAAa;AACpB,QAAI,aAAa;AACjB,QAAI,IAAI,wBAAwB;;;;;;AAOxC,MAAa,yBAAyB;;;;;;;;;;;AAYtC,SAAS,sBACP,KACA,KACS;CACT,MAAM,UAAU,IAAI,UAAU,OAAO,aAAa;CAClD,MAAM,UAAU,cAAc,IAAI;CAClC,MAAM,WACJ,eAAe,IAAI,UAAU,IAAI,OAAO,YAAY,WAAW;CACjE,MAAM,OAAO,QAAQ,IAAI,OAAO,IAAI;CACpC,MAAM,MAAM,IAAI,IAAI,IAAI,OAAO,KAAK,GAAG,SAAS,IAAI,OAAO;CAG3D,MAAM,aAAa,IAAI,iBAAiB;AACxC,KAAI,GAAG,eAAe;AACpB,MAAI,CAAC,IAAI,iBAAkB,YAAW,OAAO;GAC7C;CAEF,MAAM,OAAoB;EACxB;EACA;EACA,QAAQ,WAAW;EACpB;CAED,MAAM,EAAE,MAAM,gBAAgB,eAAe,IAAI,KAAK;AACtD,KAAI,YACF,SAAQ,IAAI,gBAAgB,YAAY;AAE1C,SAAQ,OAAO,iBAAiB;AAChC,KAAI,SAAS,OACX,MAAK,OAAO;AAGd,QAAO,IAAI,QAAQ,KAAK,KAAK;;AAG/B,SAAS,iBAAiB,KAAoD;AAC5E,KAAI,IAAI,SAAS,UAAa,IAAI,SAAS,KAAM,QAAO;AAYxD,QAAO,QAAQ,IAAI,cAAc;;AAGnC,SAAS,eAAe,MAGtB;AACA,KAAI,OAAO,SAAS,KAAK,IAAI,gBAAgB,WAG3C,QAAO,EAAQ,MAAkB;AAEnC,KAAI,OAAO,SAAS,SAClB,QAAO,EAAE,MAAM;AAEjB,KAAI,OAAO,SAAS,YAAY,SAAS,KACvC,QAAO;EAAE,MAAM,KAAK,UAAU,KAAK;EAAE,aAAa;EAAoB;AAExE,QAAO,EAAE"}
@@ -0,0 +1,16 @@
1
+ const require_fetch_handler = require('../core/fetch-handler.cjs');
2
+ const require_node_fetch_handler = require('./node-fetch-handler.cjs');
3
+ const require_auto_start_channels = require('./auto-start-channels.cjs');
4
+
5
+ //#region src/runtime/endpoints/node.ts
6
+ function createCopilotNodeListener(options) {
7
+ const handler = require_fetch_handler.createCopilotRuntimeHandler(options);
8
+ const listener = require_node_fetch_handler.createCopilotNodeHandler(handler);
9
+ listener.channels = handler.channels;
10
+ require_auto_start_channels.autoStartChannels(listener.channels);
11
+ return listener;
12
+ }
13
+
14
+ //#endregion
15
+ exports.createCopilotNodeListener = createCopilotNodeListener;
16
+ //# sourceMappingURL=node.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"node.cjs","names":["createCopilotRuntimeHandler","createCopilotNodeHandler"],"sources":["../../../src/runtime/endpoints/node.ts"],"sourcesContent":["import { createCopilotRuntimeHandler } from \"../core/fetch-handler\";\nimport type { CopilotRuntimeHandlerOptions } from \"../core/fetch-handler\";\nimport type { RuntimeWithDeclaredChannels } from \"../core/runtime\";\nimport type { ChannelsControl } from \"../core/channel-manager\";\nimport { createCopilotNodeHandler } from \"./node-fetch-handler\";\nimport type { NodeFetchHandler } from \"./node-fetch-handler\";\nimport { autoStartChannels } from \"./auto-start-channels\";\n\n/**\n * A Node.js HTTP request listener that is also a callable object carrying an\n * optional {@link ChannelsControl} surface, mirroring\n * `CopilotRuntimeFetchHandler.channels`. Node is the long-running,\n * lifecycle-owning entry point for the runtime, so it is the surface that\n * exposes `.channels` for callers that need to observe or stop the managed\n * Channel activation the listener starts at creation.\n */\nexport type NodeCopilotListener = NodeFetchHandler & {\n channels?: ChannelsControl;\n};\n\n/**\n * A {@link NodeCopilotListener} whose {@link ChannelsControl} surface is\n * guaranteed present. Returned when the runtime was constructed with at least\n * one declared Intelligence Channel and activation was not opted out of, so the\n * documented `listener.channels.ready(...)` call type-checks without a `!` or a\n * `?.` under strict TypeScript — the Node mirror of\n * `CopilotRuntimeFetchHandlerWithChannels`.\n */\nexport type NodeCopilotListenerWithChannels = NodeFetchHandler & {\n /** Lifecycle control surface for the runtime's declared managed Channels. */\n channels: ChannelsControl;\n};\n\n/**\n * Convenience wrapper for creating a Node.js HTTP request listener\n * from CopilotKit runtime handler options.\n *\n * When the runtime declares managed Channels (and activation was not opted\n * out of via `activateChannels: false`), the returned listener exposes\n * `.channels` — the same {@link ChannelsControl} surface carried by the\n * underlying fetch handler.\n *\n * ## Managed Channels lifecycle\n *\n * Creating the listener STARTS activation — which opens the persistent Realtime\n * Gateway WebSocket and starts every direct adapter on the declared Channels.\n * Node owns its own process lifetime, so there is nothing to defer to and no\n * required incantation: a declared Channel connects because it was declared.\n * (The generic `createCopilotRuntimeHandler` is the opposite — it stays lazy for\n * serverless/edge safety; see its TSDoc.)\n *\n * `await listener.channels.ready()` is therefore OPTIONAL and purely\n * await-and-observe: it resolves once every declared Channel has settled to\n * `online`/`setup_required` and rejects with the activation failure, observing\n * the activation started at creation rather than triggering a second one. Await\n * it when startup should block on Channels being live (or should exit non-zero\n * when they are not); skip it and activation failures land in the logs instead.\n * `listener.channels.stop()` tears activation down.\n *\n * Pass `activateChannels: false` to build no control surface and open no socket\n * — the clean opt-out for a test or a short-lived script that mounts the\n * listener without wanting its Channels connected.\n *\n * @example\n * ```typescript\n * import { createServer } from \"node:http\";\n * import { CopilotRuntime } from \"@copilotkit/runtime\";\n * import { createCopilotNodeListener } from \"@copilotkit/runtime/node\";\n *\n * const listener = createCopilotNodeListener({\n * runtime: new CopilotRuntime({ agents: { ... } }),\n * basePath: \"/api/copilotkit\",\n * cors: true,\n * });\n * createServer(listener).listen(3000);\n * // Declared managed Channels are already connecting at this point.\n *\n * // Optional: block startup on them being live. Bound it so one wedged adapter\n * // cannot hang startup forever.\n * await listener.channels.ready({ timeoutMs: 30_000 });\n * ```\n */\n/**\n * Overload: a runtime constructed with at least one declared Intelligence\n * Channel (a {@link RuntimeWithDeclaredChannels}-branded runtime), when\n * activation is not disabled, yields a listener with a **non-optional**\n * {@link ChannelsControl}. `activateChannels` is constrained to\n * `true | undefined` here so passing `activateChannels: false` (which leaves no\n * `.channels`) falls through to the optional-shape overload below rather than\n * dishonestly promising a control surface that will not exist. Mirrors the\n * `createCopilotRuntimeHandler` overload pair so the brand survives the wrapper.\n *\n * The brand comes from constructing the runtime with a literal non-empty\n * `channels` list (`readonly [Channel, ...Channel[]]`). A runtime built from a\n * dynamically-assembled `Channel[]` is not branded, so it falls to the\n * optional-shape overload and its call sites still need `?.`.\n */\nexport function createCopilotNodeListener(\n options: CopilotRuntimeHandlerOptions & {\n runtime: RuntimeWithDeclaredChannels;\n activateChannels?: true | undefined;\n },\n): NodeCopilotListenerWithChannels;\n/**\n * Overload: every other runtime (SSE, Intelligence without channels, or with\n * activation disabled) yields a listener whose `.channels` is optional.\n */\nexport function createCopilotNodeListener(\n options: CopilotRuntimeHandlerOptions,\n): NodeCopilotListener;\nexport function createCopilotNodeListener(\n options: CopilotRuntimeHandlerOptions,\n): NodeCopilotListener {\n const handler = createCopilotRuntimeHandler(options);\n const listener: NodeCopilotListener = createCopilotNodeHandler(handler);\n listener.channels = handler.channels;\n autoStartChannels(listener.channels);\n return listener;\n}\n"],"mappings":";;;;;AA8GA,SAAgB,0BACd,SACqB;CACrB,MAAM,UAAUA,kDAA4B,QAAQ;CACpD,MAAM,WAAgCC,oDAAyB,QAAQ;AACvE,UAAS,WAAW,QAAQ;AAC5B,+CAAkB,SAAS,SAAS;AACpC,QAAO"}
@@ -0,0 +1,104 @@
1
+ import { RuntimeWithDeclaredChannels } from "../core/runtime.cjs";
2
+ import { ChannelsControl } from "../core/channel-manager.cjs";
3
+ import { CopilotRuntimeHandlerOptions } from "../core/fetch-handler.cjs";
4
+ import { NodeFetchHandler } from "./node-fetch-handler.cjs";
5
+
6
+ //#region src/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 the managed
13
+ * Channel activation the listener starts at creation.
14
+ */
15
+ type NodeCopilotListener = NodeFetchHandler & {
16
+ channels?: ChannelsControl;
17
+ };
18
+ /**
19
+ * A {@link NodeCopilotListener} whose {@link ChannelsControl} surface is
20
+ * guaranteed present. Returned when the runtime was constructed with at least
21
+ * one declared Intelligence Channel and activation was not opted out of, so the
22
+ * documented `listener.channels.ready(...)` call type-checks without a `!` or a
23
+ * `?.` under strict TypeScript — the Node mirror of
24
+ * `CopilotRuntimeFetchHandlerWithChannels`.
25
+ */
26
+ type NodeCopilotListenerWithChannels = NodeFetchHandler & {
27
+ /** Lifecycle control surface for the runtime's declared managed Channels. */channels: ChannelsControl;
28
+ };
29
+ /**
30
+ * Convenience wrapper for creating a Node.js HTTP request listener
31
+ * from CopilotKit runtime handler options.
32
+ *
33
+ * When the runtime declares managed Channels (and activation was not opted
34
+ * out of via `activateChannels: false`), the returned listener exposes
35
+ * `.channels` — the same {@link ChannelsControl} surface carried by the
36
+ * underlying fetch handler.
37
+ *
38
+ * ## Managed Channels lifecycle
39
+ *
40
+ * Creating the listener STARTS activation — which opens the persistent Realtime
41
+ * Gateway WebSocket and starts every direct adapter on the declared Channels.
42
+ * Node owns its own process lifetime, so there is nothing to defer to and no
43
+ * required incantation: a declared Channel connects because it was declared.
44
+ * (The generic `createCopilotRuntimeHandler` is the opposite — it stays lazy for
45
+ * serverless/edge safety; see its TSDoc.)
46
+ *
47
+ * `await listener.channels.ready()` is therefore OPTIONAL and purely
48
+ * await-and-observe: it resolves once every declared Channel has settled to
49
+ * `online`/`setup_required` and rejects with the activation failure, observing
50
+ * the activation started at creation rather than triggering a second one. Await
51
+ * it when startup should block on Channels being live (or should exit non-zero
52
+ * when they are not); skip it and activation failures land in the logs instead.
53
+ * `listener.channels.stop()` tears activation down.
54
+ *
55
+ * Pass `activateChannels: false` to build no control surface and open no socket
56
+ * — the clean opt-out for a test or a short-lived script that mounts the
57
+ * listener without wanting its Channels connected.
58
+ *
59
+ * @example
60
+ * ```typescript
61
+ * import { createServer } from "node:http";
62
+ * import { CopilotRuntime } from "@copilotkit/runtime";
63
+ * import { createCopilotNodeListener } from "@copilotkit/runtime/node";
64
+ *
65
+ * const listener = createCopilotNodeListener({
66
+ * runtime: new CopilotRuntime({ agents: { ... } }),
67
+ * basePath: "/api/copilotkit",
68
+ * cors: true,
69
+ * });
70
+ * createServer(listener).listen(3000);
71
+ * // Declared managed Channels are already connecting at this point.
72
+ *
73
+ * // Optional: block startup on them being live. Bound it so one wedged adapter
74
+ * // cannot hang startup forever.
75
+ * await listener.channels.ready({ timeoutMs: 30_000 });
76
+ * ```
77
+ */
78
+ /**
79
+ * Overload: a runtime constructed with at least one declared Intelligence
80
+ * Channel (a {@link RuntimeWithDeclaredChannels}-branded runtime), when
81
+ * activation is not disabled, yields a listener with a **non-optional**
82
+ * {@link ChannelsControl}. `activateChannels` is constrained to
83
+ * `true | undefined` here so passing `activateChannels: false` (which leaves no
84
+ * `.channels`) falls through to the optional-shape overload below rather than
85
+ * dishonestly promising a control surface that will not exist. Mirrors the
86
+ * `createCopilotRuntimeHandler` overload pair so the brand survives the wrapper.
87
+ *
88
+ * The brand comes from constructing the runtime with a literal non-empty
89
+ * `channels` list (`readonly [Channel, ...Channel[]]`). A runtime built from a
90
+ * dynamically-assembled `Channel[]` is not branded, so it falls to the
91
+ * optional-shape overload and its call sites still need `?.`.
92
+ */
93
+ declare function createCopilotNodeListener(options: CopilotRuntimeHandlerOptions & {
94
+ runtime: RuntimeWithDeclaredChannels;
95
+ activateChannels?: true | undefined;
96
+ }): NodeCopilotListenerWithChannels;
97
+ /**
98
+ * Overload: every other runtime (SSE, Intelligence without channels, or with
99
+ * activation disabled) yields a listener whose `.channels` is optional.
100
+ */
101
+ declare function createCopilotNodeListener(options: CopilotRuntimeHandlerOptions): NodeCopilotListener;
102
+ //#endregion
103
+ export { NodeCopilotListener, NodeCopilotListenerWithChannels, createCopilotNodeListener };
104
+ //# sourceMappingURL=node.d.cts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"node.d.cts","names":[],"sources":["../../../src/runtime/endpoints/node.ts"],"mappings":";;;;;;;;AAgBA;;;;;;KAAY,mBAAA,GAAsB,gBAAA;EAChC,QAAA,GAAW,eAAA;AAAA;AAWb;;;;;;;;AAAA,KAAY,+BAAA,GAAkC,gBAAA;EAqE9B,6EAnEd,QAAA,EAAU,eAAA;AAAA;;;;;;;;;;;;;;AA6EZ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;iBAVgB,yBAAA,CACd,OAAA,EAAS,4BAAA;EACP,OAAA,EAAS,2BAAA;EACT,gBAAA;AAAA,IAED,+BAAA;;;;;iBAKa,yBAAA,CACd,OAAA,EAAS,4BAAA,GACR,mBAAA"}
@@ -0,0 +1,104 @@
1
+ import { RuntimeWithDeclaredChannels } from "../core/runtime.mjs";
2
+ import { ChannelsControl } from "../core/channel-manager.mjs";
3
+ import { CopilotRuntimeHandlerOptions } from "../core/fetch-handler.mjs";
4
+ import { NodeFetchHandler } from "./node-fetch-handler.mjs";
5
+
6
+ //#region src/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 the managed
13
+ * Channel activation the listener starts at creation.
14
+ */
15
+ type NodeCopilotListener = NodeFetchHandler & {
16
+ channels?: ChannelsControl;
17
+ };
18
+ /**
19
+ * A {@link NodeCopilotListener} whose {@link ChannelsControl} surface is
20
+ * guaranteed present. Returned when the runtime was constructed with at least
21
+ * one declared Intelligence Channel and activation was not opted out of, so the
22
+ * documented `listener.channels.ready(...)` call type-checks without a `!` or a
23
+ * `?.` under strict TypeScript — the Node mirror of
24
+ * `CopilotRuntimeFetchHandlerWithChannels`.
25
+ */
26
+ type NodeCopilotListenerWithChannels = NodeFetchHandler & {
27
+ /** Lifecycle control surface for the runtime's declared managed Channels. */channels: ChannelsControl;
28
+ };
29
+ /**
30
+ * Convenience wrapper for creating a Node.js HTTP request listener
31
+ * from CopilotKit runtime handler options.
32
+ *
33
+ * When the runtime declares managed Channels (and activation was not opted
34
+ * out of via `activateChannels: false`), the returned listener exposes
35
+ * `.channels` — the same {@link ChannelsControl} surface carried by the
36
+ * underlying fetch handler.
37
+ *
38
+ * ## Managed Channels lifecycle
39
+ *
40
+ * Creating the listener STARTS activation — which opens the persistent Realtime
41
+ * Gateway WebSocket and starts every direct adapter on the declared Channels.
42
+ * Node owns its own process lifetime, so there is nothing to defer to and no
43
+ * required incantation: a declared Channel connects because it was declared.
44
+ * (The generic `createCopilotRuntimeHandler` is the opposite — it stays lazy for
45
+ * serverless/edge safety; see its TSDoc.)
46
+ *
47
+ * `await listener.channels.ready()` is therefore OPTIONAL and purely
48
+ * await-and-observe: it resolves once every declared Channel has settled to
49
+ * `online`/`setup_required` and rejects with the activation failure, observing
50
+ * the activation started at creation rather than triggering a second one. Await
51
+ * it when startup should block on Channels being live (or should exit non-zero
52
+ * when they are not); skip it and activation failures land in the logs instead.
53
+ * `listener.channels.stop()` tears activation down.
54
+ *
55
+ * Pass `activateChannels: false` to build no control surface and open no socket
56
+ * — the clean opt-out for a test or a short-lived script that mounts the
57
+ * listener without wanting its Channels connected.
58
+ *
59
+ * @example
60
+ * ```typescript
61
+ * import { createServer } from "node:http";
62
+ * import { CopilotRuntime } from "@copilotkit/runtime";
63
+ * import { createCopilotNodeListener } from "@copilotkit/runtime/node";
64
+ *
65
+ * const listener = createCopilotNodeListener({
66
+ * runtime: new CopilotRuntime({ agents: { ... } }),
67
+ * basePath: "/api/copilotkit",
68
+ * cors: true,
69
+ * });
70
+ * createServer(listener).listen(3000);
71
+ * // Declared managed Channels are already connecting at this point.
72
+ *
73
+ * // Optional: block startup on them being live. Bound it so one wedged adapter
74
+ * // cannot hang startup forever.
75
+ * await listener.channels.ready({ timeoutMs: 30_000 });
76
+ * ```
77
+ */
78
+ /**
79
+ * Overload: a runtime constructed with at least one declared Intelligence
80
+ * Channel (a {@link RuntimeWithDeclaredChannels}-branded runtime), when
81
+ * activation is not disabled, yields a listener with a **non-optional**
82
+ * {@link ChannelsControl}. `activateChannels` is constrained to
83
+ * `true | undefined` here so passing `activateChannels: false` (which leaves no
84
+ * `.channels`) falls through to the optional-shape overload below rather than
85
+ * dishonestly promising a control surface that will not exist. Mirrors the
86
+ * `createCopilotRuntimeHandler` overload pair so the brand survives the wrapper.
87
+ *
88
+ * The brand comes from constructing the runtime with a literal non-empty
89
+ * `channels` list (`readonly [Channel, ...Channel[]]`). A runtime built from a
90
+ * dynamically-assembled `Channel[]` is not branded, so it falls to the
91
+ * optional-shape overload and its call sites still need `?.`.
92
+ */
93
+ declare function createCopilotNodeListener(options: CopilotRuntimeHandlerOptions & {
94
+ runtime: RuntimeWithDeclaredChannels;
95
+ activateChannels?: true | undefined;
96
+ }): NodeCopilotListenerWithChannels;
97
+ /**
98
+ * Overload: every other runtime (SSE, Intelligence without channels, or with
99
+ * activation disabled) yields a listener whose `.channels` is optional.
100
+ */
101
+ declare function createCopilotNodeListener(options: CopilotRuntimeHandlerOptions): NodeCopilotListener;
102
+ //#endregion
103
+ export { NodeCopilotListener, NodeCopilotListenerWithChannels, createCopilotNodeListener };
104
+ //# sourceMappingURL=node.d.mts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"node.d.mts","names":[],"sources":["../../../src/runtime/endpoints/node.ts"],"mappings":";;;;;;;;AAgBA;;;;;;KAAY,mBAAA,GAAsB,gBAAA;EAChC,QAAA,GAAW,eAAA;AAAA;AAWb;;;;;;;;AAAA,KAAY,+BAAA,GAAkC,gBAAA;EAqE9B,6EAnEd,QAAA,EAAU,eAAA;AAAA;;;;;;;;;;;;;;AA6EZ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;iBAVgB,yBAAA,CACd,OAAA,EAAS,4BAAA;EACP,OAAA,EAAS,2BAAA;EACT,gBAAA;AAAA,IAED,+BAAA;;;;;iBAKa,yBAAA,CACd,OAAA,EAAS,4BAAA,GACR,mBAAA"}
@@ -0,0 +1,16 @@
1
+ import { createCopilotRuntimeHandler } from "../core/fetch-handler.mjs";
2
+ import { createCopilotNodeHandler } from "./node-fetch-handler.mjs";
3
+ import { autoStartChannels } from "./auto-start-channels.mjs";
4
+
5
+ //#region src/runtime/endpoints/node.ts
6
+ function createCopilotNodeListener(options) {
7
+ const handler = createCopilotRuntimeHandler(options);
8
+ const listener = createCopilotNodeHandler(handler);
9
+ listener.channels = handler.channels;
10
+ autoStartChannels(listener.channels);
11
+ return listener;
12
+ }
13
+
14
+ //#endregion
15
+ export { createCopilotNodeListener };
16
+ //# sourceMappingURL=node.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"node.mjs","names":[],"sources":["../../../src/runtime/endpoints/node.ts"],"sourcesContent":["import { createCopilotRuntimeHandler } from \"../core/fetch-handler\";\nimport type { CopilotRuntimeHandlerOptions } from \"../core/fetch-handler\";\nimport type { RuntimeWithDeclaredChannels } from \"../core/runtime\";\nimport type { ChannelsControl } from \"../core/channel-manager\";\nimport { createCopilotNodeHandler } from \"./node-fetch-handler\";\nimport type { NodeFetchHandler } from \"./node-fetch-handler\";\nimport { autoStartChannels } from \"./auto-start-channels\";\n\n/**\n * A Node.js HTTP request listener that is also a callable object carrying an\n * optional {@link ChannelsControl} surface, mirroring\n * `CopilotRuntimeFetchHandler.channels`. Node is the long-running,\n * lifecycle-owning entry point for the runtime, so it is the surface that\n * exposes `.channels` for callers that need to observe or stop the managed\n * Channel activation the listener starts at creation.\n */\nexport type NodeCopilotListener = NodeFetchHandler & {\n channels?: ChannelsControl;\n};\n\n/**\n * A {@link NodeCopilotListener} whose {@link ChannelsControl} surface is\n * guaranteed present. Returned when the runtime was constructed with at least\n * one declared Intelligence Channel and activation was not opted out of, so the\n * documented `listener.channels.ready(...)` call type-checks without a `!` or a\n * `?.` under strict TypeScript — the Node mirror of\n * `CopilotRuntimeFetchHandlerWithChannels`.\n */\nexport type NodeCopilotListenerWithChannels = NodeFetchHandler & {\n /** Lifecycle control surface for the runtime's declared managed Channels. */\n channels: ChannelsControl;\n};\n\n/**\n * Convenience wrapper for creating a Node.js HTTP request listener\n * from CopilotKit runtime handler options.\n *\n * When the runtime declares managed Channels (and activation was not opted\n * out of via `activateChannels: false`), the returned listener exposes\n * `.channels` — the same {@link ChannelsControl} surface carried by the\n * underlying fetch handler.\n *\n * ## Managed Channels lifecycle\n *\n * Creating the listener STARTS activation — which opens the persistent Realtime\n * Gateway WebSocket and starts every direct adapter on the declared Channels.\n * Node owns its own process lifetime, so there is nothing to defer to and no\n * required incantation: a declared Channel connects because it was declared.\n * (The generic `createCopilotRuntimeHandler` is the opposite — it stays lazy for\n * serverless/edge safety; see its TSDoc.)\n *\n * `await listener.channels.ready()` is therefore OPTIONAL and purely\n * await-and-observe: it resolves once every declared Channel has settled to\n * `online`/`setup_required` and rejects with the activation failure, observing\n * the activation started at creation rather than triggering a second one. Await\n * it when startup should block on Channels being live (or should exit non-zero\n * when they are not); skip it and activation failures land in the logs instead.\n * `listener.channels.stop()` tears activation down.\n *\n * Pass `activateChannels: false` to build no control surface and open no socket\n * — the clean opt-out for a test or a short-lived script that mounts the\n * listener without wanting its Channels connected.\n *\n * @example\n * ```typescript\n * import { createServer } from \"node:http\";\n * import { CopilotRuntime } from \"@copilotkit/runtime\";\n * import { createCopilotNodeListener } from \"@copilotkit/runtime/node\";\n *\n * const listener = createCopilotNodeListener({\n * runtime: new CopilotRuntime({ agents: { ... } }),\n * basePath: \"/api/copilotkit\",\n * cors: true,\n * });\n * createServer(listener).listen(3000);\n * // Declared managed Channels are already connecting at this point.\n *\n * // Optional: block startup on them being live. Bound it so one wedged adapter\n * // cannot hang startup forever.\n * await listener.channels.ready({ timeoutMs: 30_000 });\n * ```\n */\n/**\n * Overload: a runtime constructed with at least one declared Intelligence\n * Channel (a {@link RuntimeWithDeclaredChannels}-branded runtime), when\n * activation is not disabled, yields a listener with a **non-optional**\n * {@link ChannelsControl}. `activateChannels` is constrained to\n * `true | undefined` here so passing `activateChannels: false` (which leaves no\n * `.channels`) falls through to the optional-shape overload below rather than\n * dishonestly promising a control surface that will not exist. Mirrors the\n * `createCopilotRuntimeHandler` overload pair so the brand survives the wrapper.\n *\n * The brand comes from constructing the runtime with a literal non-empty\n * `channels` list (`readonly [Channel, ...Channel[]]`). A runtime built from a\n * dynamically-assembled `Channel[]` is not branded, so it falls to the\n * optional-shape overload and its call sites still need `?.`.\n */\nexport function createCopilotNodeListener(\n options: CopilotRuntimeHandlerOptions & {\n runtime: RuntimeWithDeclaredChannels;\n activateChannels?: true | undefined;\n },\n): NodeCopilotListenerWithChannels;\n/**\n * Overload: every other runtime (SSE, Intelligence without channels, or with\n * activation disabled) yields a listener whose `.channels` is optional.\n */\nexport function createCopilotNodeListener(\n options: CopilotRuntimeHandlerOptions,\n): NodeCopilotListener;\nexport function createCopilotNodeListener(\n options: CopilotRuntimeHandlerOptions,\n): NodeCopilotListener {\n const handler = createCopilotRuntimeHandler(options);\n const listener: NodeCopilotListener = createCopilotNodeHandler(handler);\n listener.channels = handler.channels;\n autoStartChannels(listener.channels);\n return listener;\n}\n"],"mappings":";;;;;AA8GA,SAAgB,0BACd,SACqB;CACrB,MAAM,UAAU,4BAA4B,QAAQ;CACpD,MAAM,WAAgC,yBAAyB,QAAQ;AACvE,UAAS,WAAW,QAAQ;AAC5B,mBAAkB,SAAS,SAAS;AACpC,QAAO"}
@@ -0,0 +1,130 @@
1
+
2
+ //#region src/runtime/endpoints/single-route-helpers.ts
3
+ const METHOD_NAMES = [
4
+ "agent/run",
5
+ "agent/suggest",
6
+ "agent/connect",
7
+ "trajectory/connect",
8
+ "agent/stop",
9
+ "info",
10
+ "inspector/metadata",
11
+ "inspector/learning",
12
+ "transcribe",
13
+ "resource/request"
14
+ ];
15
+ /**
16
+ * Detect a single-route JSON envelope on a request the multi-route router
17
+ * could not match.
18
+ *
19
+ * A single-endpoint client (`useSingleEndpoint` on the frontend provider)
20
+ * POSTs `{ method, params, body }` at the base path. A multi-route runtime
21
+ * matches no route for that path and would otherwise answer a bare 404, giving
22
+ * the developer nothing to go on. Recognising the envelope here lets the
23
+ * handler name the actual cause instead.
24
+ *
25
+ * Deliberately conservative: it reports a method only for a POST carrying a
26
+ * JSON body whose `method` is one the single-route endpoint actually accepts.
27
+ * Anything else is a genuine 404 and must stay one.
28
+ *
29
+ * @returns The envelope's method name, or `null` if this is not an envelope.
30
+ */
31
+ async function detectSingleRouteEnvelope(request) {
32
+ if (request.method !== "POST") return null;
33
+ if (!(request.headers.get("content-type") || "").includes("application/json")) return null;
34
+ let envelope;
35
+ try {
36
+ envelope = await request.clone().json();
37
+ } catch {
38
+ return null;
39
+ }
40
+ if (typeof envelope !== "object" || envelope === null) return null;
41
+ const method = envelope.method;
42
+ if (typeof method !== "string") return null;
43
+ if (!METHOD_NAMES.includes(method)) return null;
44
+ return method;
45
+ }
46
+ async function parseMethodCall(request) {
47
+ if (!(request.headers.get("content-type") || "").includes("application/json")) throw createResponseError("Single-route endpoint expects JSON payloads", 415);
48
+ let jsonEnvelope;
49
+ try {
50
+ jsonEnvelope = await request.clone().json();
51
+ } catch {
52
+ throw createResponseError("Invalid JSON payload", 400);
53
+ }
54
+ return {
55
+ method: validateMethod(jsonEnvelope.method),
56
+ params: jsonEnvelope.params,
57
+ body: jsonEnvelope.body
58
+ };
59
+ }
60
+ function expectString(params, key) {
61
+ const value = params?.[key];
62
+ if (typeof value === "string" && value.trim().length > 0) return value;
63
+ throw createResponseError(`Missing or invalid parameter '${key}'`, 400);
64
+ }
65
+ function createJsonRequest(base, body) {
66
+ if (body === void 0 || body === null) throw createResponseError("Missing request body for JSON handler", 400);
67
+ const headers = new Headers(base.headers);
68
+ headers.set("content-type", "application/json");
69
+ headers.delete("content-length");
70
+ const serializedBody = serializeJsonBody(body);
71
+ return new Request(base.url, {
72
+ method: "POST",
73
+ headers,
74
+ body: serializedBody,
75
+ signal: base.signal
76
+ });
77
+ }
78
+ /**
79
+ * Rebuild a resource request carried inside the single-route JSON envelope.
80
+ *
81
+ * The resource path must stay relative to the mounted Runtime. This prevents
82
+ * the envelope from becoming an open HTTP proxy while preserving the method,
83
+ * query string, headers, and cancellation signal used by the REST handler.
84
+ */
85
+ function createResourceRequest(base, path, httpMethod, body) {
86
+ if (!path.startsWith("/") || path.startsWith("//")) throw createResponseError("Resource path must be Runtime-relative", 400);
87
+ const resourceUrl = new URL(path, "http://copilotkit.resource");
88
+ if (resourceUrl.origin !== "http://copilotkit.resource") throw createResponseError("Resource path must be Runtime-relative", 400);
89
+ const targetUrl = new URL(base.url);
90
+ targetUrl.pathname = `${targetUrl.pathname.replace(/\/$/, "")}${resourceUrl.pathname}`;
91
+ targetUrl.search = resourceUrl.search;
92
+ const method = httpMethod.toUpperCase();
93
+ const headers = new Headers(base.headers);
94
+ headers.delete("content-length");
95
+ const hasBody = method !== "GET" && method !== "HEAD" && body != null;
96
+ return new Request(targetUrl, {
97
+ method,
98
+ headers,
99
+ ...hasBody ? { body: serializeJsonBody(body) } : {},
100
+ signal: base.signal
101
+ });
102
+ }
103
+ function createResponseError(message, status) {
104
+ return new Response(JSON.stringify({
105
+ error: "invalid_request",
106
+ message
107
+ }), {
108
+ status,
109
+ headers: { "Content-Type": "application/json" }
110
+ });
111
+ }
112
+ function validateMethod(method) {
113
+ if (!method) throw createResponseError("Missing method field", 400);
114
+ if (METHOD_NAMES.includes(method)) return method;
115
+ throw createResponseError(`Unsupported method '${method}'`, 400);
116
+ }
117
+ function serializeJsonBody(body) {
118
+ if (typeof body === "string") return body;
119
+ if (body instanceof Blob || body instanceof ArrayBuffer || body instanceof Uint8Array) return body;
120
+ if (body instanceof FormData || body instanceof URLSearchParams) return body;
121
+ return JSON.stringify(body);
122
+ }
123
+
124
+ //#endregion
125
+ exports.createJsonRequest = createJsonRequest;
126
+ exports.createResourceRequest = createResourceRequest;
127
+ exports.detectSingleRouteEnvelope = detectSingleRouteEnvelope;
128
+ exports.expectString = expectString;
129
+ exports.parseMethodCall = parseMethodCall;
130
+ //# sourceMappingURL=single-route-helpers.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"single-route-helpers.cjs","names":[],"sources":["../../../src/runtime/endpoints/single-route-helpers.ts"],"sourcesContent":["const METHOD_NAMES = [\n \"agent/run\",\n \"agent/suggest\",\n \"agent/connect\",\n \"trajectory/connect\",\n \"agent/stop\",\n \"info\",\n \"inspector/metadata\",\n \"inspector/learning\",\n \"transcribe\",\n \"resource/request\",\n] as const;\n\nexport type EndpointMethod = (typeof METHOD_NAMES)[number];\n\ninterface JsonEnvelope {\n method?: string;\n params?: Record<string, unknown>;\n body?: unknown;\n}\n\nexport interface MethodCall {\n method: EndpointMethod;\n params?: Record<string, unknown>;\n body?: unknown;\n}\n\n/**\n * Detect a single-route JSON envelope on a request the multi-route router\n * could not match.\n *\n * A single-endpoint client (`useSingleEndpoint` on the frontend provider)\n * POSTs `{ method, params, body }` at the base path. A multi-route runtime\n * matches no route for that path and would otherwise answer a bare 404, giving\n * the developer nothing to go on. Recognising the envelope here lets the\n * handler name the actual cause instead.\n *\n * Deliberately conservative: it reports a method only for a POST carrying a\n * JSON body whose `method` is one the single-route endpoint actually accepts.\n * Anything else is a genuine 404 and must stay one.\n *\n * @returns The envelope's method name, or `null` if this is not an envelope.\n */\nexport async function detectSingleRouteEnvelope(\n request: Request,\n): Promise<EndpointMethod | null> {\n if (request.method !== \"POST\") return null;\n\n const contentType = request.headers.get(\"content-type\") || \"\";\n if (!contentType.includes(\"application/json\")) return null;\n\n let envelope: unknown;\n try {\n envelope = await request.clone().json();\n } catch {\n return null;\n }\n\n if (typeof envelope !== \"object\" || envelope === null) return null;\n\n const method = (envelope as JsonEnvelope).method;\n if (typeof method !== \"string\") return null;\n if (!(METHOD_NAMES as readonly string[]).includes(method)) return null;\n\n return method as EndpointMethod;\n}\n\nexport async function parseMethodCall(request: Request): Promise<MethodCall> {\n const contentType = request.headers.get(\"content-type\") || \"\";\n\n if (!contentType.includes(\"application/json\")) {\n throw createResponseError(\n \"Single-route endpoint expects JSON payloads\",\n 415,\n );\n }\n\n let jsonEnvelope: JsonEnvelope;\n try {\n jsonEnvelope = (await request.clone().json()) as JsonEnvelope;\n } catch {\n throw createResponseError(\"Invalid JSON payload\", 400);\n }\n\n const method = validateMethod(jsonEnvelope.method);\n\n return {\n method,\n params: jsonEnvelope.params,\n body: jsonEnvelope.body,\n };\n}\n\nexport function expectString(\n params: Record<string, unknown> | undefined,\n key: string,\n): string {\n const value = params?.[key];\n if (typeof value === \"string\" && value.trim().length > 0) {\n return value;\n }\n\n throw createResponseError(`Missing or invalid parameter '${key}'`, 400);\n}\n\nexport function createJsonRequest(base: Request, body: unknown): Request {\n if (body === undefined || body === null) {\n throw createResponseError(\"Missing request body for JSON handler\", 400);\n }\n\n const headers = new Headers(base.headers);\n headers.set(\"content-type\", \"application/json\");\n headers.delete(\"content-length\");\n\n const serializedBody = serializeJsonBody(body);\n\n return new Request(base.url, {\n method: \"POST\",\n headers,\n body: serializedBody,\n signal: base.signal,\n });\n}\n\n/**\n * Rebuild a resource request carried inside the single-route JSON envelope.\n *\n * The resource path must stay relative to the mounted Runtime. This prevents\n * the envelope from becoming an open HTTP proxy while preserving the method,\n * query string, headers, and cancellation signal used by the REST handler.\n */\nexport function createResourceRequest(\n base: Request,\n path: string,\n httpMethod: string,\n body: unknown,\n): Request {\n if (!path.startsWith(\"/\") || path.startsWith(\"//\")) {\n throw createResponseError(\"Resource path must be Runtime-relative\", 400);\n }\n\n const resourceUrl = new URL(path, \"http://copilotkit.resource\");\n if (resourceUrl.origin !== \"http://copilotkit.resource\") {\n throw createResponseError(\"Resource path must be Runtime-relative\", 400);\n }\n\n const targetUrl = new URL(base.url);\n targetUrl.pathname = `${targetUrl.pathname.replace(/\\/$/, \"\")}${resourceUrl.pathname}`;\n targetUrl.search = resourceUrl.search;\n\n const method = httpMethod.toUpperCase();\n const headers = new Headers(base.headers);\n headers.delete(\"content-length\");\n const hasBody = method !== \"GET\" && method !== \"HEAD\" && body != null;\n\n return new Request(targetUrl, {\n method,\n headers,\n ...(hasBody ? { body: serializeJsonBody(body) } : {}),\n signal: base.signal,\n });\n}\n\nexport function createResponseError(message: string, status: number): Response {\n return new Response(\n JSON.stringify({\n error: \"invalid_request\",\n message,\n }),\n {\n status,\n headers: {\n \"Content-Type\": \"application/json\",\n },\n },\n );\n}\n\nfunction validateMethod(method: string | undefined): EndpointMethod {\n if (!method) {\n throw createResponseError(\"Missing method field\", 400);\n }\n\n if ((METHOD_NAMES as readonly string[]).includes(method)) {\n return method as EndpointMethod;\n }\n\n throw createResponseError(`Unsupported method '${method}'`, 400);\n}\n\nfunction serializeJsonBody(body: unknown): BodyInit {\n if (typeof body === \"string\") {\n return body;\n }\n\n if (\n body instanceof Blob ||\n body instanceof ArrayBuffer ||\n body instanceof Uint8Array\n ) {\n // Uint8Array<ArrayBufferLike> is a valid fetch body at runtime, but the\n // DOM lib's BodyInit only admits ArrayBuffer-backed views.\n return body as BodyInit;\n }\n\n if (body instanceof FormData || body instanceof URLSearchParams) {\n return body;\n }\n\n return JSON.stringify(body);\n}\n"],"mappings":";;AAAA,MAAM,eAAe;CACnB;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACD;;;;;;;;;;;;;;;;;AAgCD,eAAsB,0BACpB,SACgC;AAChC,KAAI,QAAQ,WAAW,OAAQ,QAAO;AAGtC,KAAI,EADgB,QAAQ,QAAQ,IAAI,eAAe,IAAI,IAC1C,SAAS,mBAAmB,CAAE,QAAO;CAEtD,IAAI;AACJ,KAAI;AACF,aAAW,MAAM,QAAQ,OAAO,CAAC,MAAM;SACjC;AACN,SAAO;;AAGT,KAAI,OAAO,aAAa,YAAY,aAAa,KAAM,QAAO;CAE9D,MAAM,SAAU,SAA0B;AAC1C,KAAI,OAAO,WAAW,SAAU,QAAO;AACvC,KAAI,CAAE,aAAmC,SAAS,OAAO,CAAE,QAAO;AAElE,QAAO;;AAGT,eAAsB,gBAAgB,SAAuC;AAG3E,KAAI,EAFgB,QAAQ,QAAQ,IAAI,eAAe,IAAI,IAE1C,SAAS,mBAAmB,CAC3C,OAAM,oBACJ,+CACA,IACD;CAGH,IAAI;AACJ,KAAI;AACF,iBAAgB,MAAM,QAAQ,OAAO,CAAC,MAAM;SACtC;AACN,QAAM,oBAAoB,wBAAwB,IAAI;;AAKxD,QAAO;EACL,QAHa,eAAe,aAAa,OAAO;EAIhD,QAAQ,aAAa;EACrB,MAAM,aAAa;EACpB;;AAGH,SAAgB,aACd,QACA,KACQ;CACR,MAAM,QAAQ,SAAS;AACvB,KAAI,OAAO,UAAU,YAAY,MAAM,MAAM,CAAC,SAAS,EACrD,QAAO;AAGT,OAAM,oBAAoB,iCAAiC,IAAI,IAAI,IAAI;;AAGzE,SAAgB,kBAAkB,MAAe,MAAwB;AACvE,KAAI,SAAS,UAAa,SAAS,KACjC,OAAM,oBAAoB,yCAAyC,IAAI;CAGzE,MAAM,UAAU,IAAI,QAAQ,KAAK,QAAQ;AACzC,SAAQ,IAAI,gBAAgB,mBAAmB;AAC/C,SAAQ,OAAO,iBAAiB;CAEhC,MAAM,iBAAiB,kBAAkB,KAAK;AAE9C,QAAO,IAAI,QAAQ,KAAK,KAAK;EAC3B,QAAQ;EACR;EACA,MAAM;EACN,QAAQ,KAAK;EACd,CAAC;;;;;;;;;AAUJ,SAAgB,sBACd,MACA,MACA,YACA,MACS;AACT,KAAI,CAAC,KAAK,WAAW,IAAI,IAAI,KAAK,WAAW,KAAK,CAChD,OAAM,oBAAoB,0CAA0C,IAAI;CAG1E,MAAM,cAAc,IAAI,IAAI,MAAM,6BAA6B;AAC/D,KAAI,YAAY,WAAW,6BACzB,OAAM,oBAAoB,0CAA0C,IAAI;CAG1E,MAAM,YAAY,IAAI,IAAI,KAAK,IAAI;AACnC,WAAU,WAAW,GAAG,UAAU,SAAS,QAAQ,OAAO,GAAG,GAAG,YAAY;AAC5E,WAAU,SAAS,YAAY;CAE/B,MAAM,SAAS,WAAW,aAAa;CACvC,MAAM,UAAU,IAAI,QAAQ,KAAK,QAAQ;AACzC,SAAQ,OAAO,iBAAiB;CAChC,MAAM,UAAU,WAAW,SAAS,WAAW,UAAU,QAAQ;AAEjE,QAAO,IAAI,QAAQ,WAAW;EAC5B;EACA;EACA,GAAI,UAAU,EAAE,MAAM,kBAAkB,KAAK,EAAE,GAAG,EAAE;EACpD,QAAQ,KAAK;EACd,CAAC;;AAGJ,SAAgB,oBAAoB,SAAiB,QAA0B;AAC7E,QAAO,IAAI,SACT,KAAK,UAAU;EACb,OAAO;EACP;EACD,CAAC,EACF;EACE;EACA,SAAS,EACP,gBAAgB,oBACjB;EACF,CACF;;AAGH,SAAS,eAAe,QAA4C;AAClE,KAAI,CAAC,OACH,OAAM,oBAAoB,wBAAwB,IAAI;AAGxD,KAAK,aAAmC,SAAS,OAAO,CACtD,QAAO;AAGT,OAAM,oBAAoB,uBAAuB,OAAO,IAAI,IAAI;;AAGlE,SAAS,kBAAkB,MAAyB;AAClD,KAAI,OAAO,SAAS,SAClB,QAAO;AAGT,KACE,gBAAgB,QAChB,gBAAgB,eAChB,gBAAgB,WAIhB,QAAO;AAGT,KAAI,gBAAgB,YAAY,gBAAgB,gBAC9C,QAAO;AAGT,QAAO,KAAK,UAAU,KAAK"}
@@ -0,0 +1,125 @@
1
+ //#region src/runtime/endpoints/single-route-helpers.ts
2
+ const METHOD_NAMES = [
3
+ "agent/run",
4
+ "agent/suggest",
5
+ "agent/connect",
6
+ "trajectory/connect",
7
+ "agent/stop",
8
+ "info",
9
+ "inspector/metadata",
10
+ "inspector/learning",
11
+ "transcribe",
12
+ "resource/request"
13
+ ];
14
+ /**
15
+ * Detect a single-route JSON envelope on a request the multi-route router
16
+ * could not match.
17
+ *
18
+ * A single-endpoint client (`useSingleEndpoint` on the frontend provider)
19
+ * POSTs `{ method, params, body }` at the base path. A multi-route runtime
20
+ * matches no route for that path and would otherwise answer a bare 404, giving
21
+ * the developer nothing to go on. Recognising the envelope here lets the
22
+ * handler name the actual cause instead.
23
+ *
24
+ * Deliberately conservative: it reports a method only for a POST carrying a
25
+ * JSON body whose `method` is one the single-route endpoint actually accepts.
26
+ * Anything else is a genuine 404 and must stay one.
27
+ *
28
+ * @returns The envelope's method name, or `null` if this is not an envelope.
29
+ */
30
+ async function detectSingleRouteEnvelope(request) {
31
+ if (request.method !== "POST") return null;
32
+ if (!(request.headers.get("content-type") || "").includes("application/json")) return null;
33
+ let envelope;
34
+ try {
35
+ envelope = await request.clone().json();
36
+ } catch {
37
+ return null;
38
+ }
39
+ if (typeof envelope !== "object" || envelope === null) return null;
40
+ const method = envelope.method;
41
+ if (typeof method !== "string") return null;
42
+ if (!METHOD_NAMES.includes(method)) return null;
43
+ return method;
44
+ }
45
+ async function parseMethodCall(request) {
46
+ if (!(request.headers.get("content-type") || "").includes("application/json")) throw createResponseError("Single-route endpoint expects JSON payloads", 415);
47
+ let jsonEnvelope;
48
+ try {
49
+ jsonEnvelope = await request.clone().json();
50
+ } catch {
51
+ throw createResponseError("Invalid JSON payload", 400);
52
+ }
53
+ return {
54
+ method: validateMethod(jsonEnvelope.method),
55
+ params: jsonEnvelope.params,
56
+ body: jsonEnvelope.body
57
+ };
58
+ }
59
+ function expectString(params, key) {
60
+ const value = params?.[key];
61
+ if (typeof value === "string" && value.trim().length > 0) return value;
62
+ throw createResponseError(`Missing or invalid parameter '${key}'`, 400);
63
+ }
64
+ function createJsonRequest(base, body) {
65
+ if (body === void 0 || body === null) throw createResponseError("Missing request body for JSON handler", 400);
66
+ const headers = new Headers(base.headers);
67
+ headers.set("content-type", "application/json");
68
+ headers.delete("content-length");
69
+ const serializedBody = serializeJsonBody(body);
70
+ return new Request(base.url, {
71
+ method: "POST",
72
+ headers,
73
+ body: serializedBody,
74
+ signal: base.signal
75
+ });
76
+ }
77
+ /**
78
+ * Rebuild a resource request carried inside the single-route JSON envelope.
79
+ *
80
+ * The resource path must stay relative to the mounted Runtime. This prevents
81
+ * the envelope from becoming an open HTTP proxy while preserving the method,
82
+ * query string, headers, and cancellation signal used by the REST handler.
83
+ */
84
+ function createResourceRequest(base, path, httpMethod, body) {
85
+ if (!path.startsWith("/") || path.startsWith("//")) throw createResponseError("Resource path must be Runtime-relative", 400);
86
+ const resourceUrl = new URL(path, "http://copilotkit.resource");
87
+ if (resourceUrl.origin !== "http://copilotkit.resource") throw createResponseError("Resource path must be Runtime-relative", 400);
88
+ const targetUrl = new URL(base.url);
89
+ targetUrl.pathname = `${targetUrl.pathname.replace(/\/$/, "")}${resourceUrl.pathname}`;
90
+ targetUrl.search = resourceUrl.search;
91
+ const method = httpMethod.toUpperCase();
92
+ const headers = new Headers(base.headers);
93
+ headers.delete("content-length");
94
+ const hasBody = method !== "GET" && method !== "HEAD" && body != null;
95
+ return new Request(targetUrl, {
96
+ method,
97
+ headers,
98
+ ...hasBody ? { body: serializeJsonBody(body) } : {},
99
+ signal: base.signal
100
+ });
101
+ }
102
+ function createResponseError(message, status) {
103
+ return new Response(JSON.stringify({
104
+ error: "invalid_request",
105
+ message
106
+ }), {
107
+ status,
108
+ headers: { "Content-Type": "application/json" }
109
+ });
110
+ }
111
+ function validateMethod(method) {
112
+ if (!method) throw createResponseError("Missing method field", 400);
113
+ if (METHOD_NAMES.includes(method)) return method;
114
+ throw createResponseError(`Unsupported method '${method}'`, 400);
115
+ }
116
+ function serializeJsonBody(body) {
117
+ if (typeof body === "string") return body;
118
+ if (body instanceof Blob || body instanceof ArrayBuffer || body instanceof Uint8Array) return body;
119
+ if (body instanceof FormData || body instanceof URLSearchParams) return body;
120
+ return JSON.stringify(body);
121
+ }
122
+
123
+ //#endregion
124
+ export { createJsonRequest, createResourceRequest, detectSingleRouteEnvelope, expectString, parseMethodCall };
125
+ //# sourceMappingURL=single-route-helpers.mjs.map