@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 @@
1
+ {"version":3,"file":"header-utils.mjs","names":[],"sources":["../../../src/runtime/handlers/header-utils.ts"],"sourcesContent":["/**\n * Exact header names (lowercased) stripped from forwarding by default.\n *\n * These are infrastructure/proxy/platform artifacts that no legitimate agent\n * integration depends on receiving *forwarded from the inbound edge* — the\n * inbound request has already traversed a browser, CDN/edge, load balancer, and\n * hosting platform, each of which stamps its own `x-*` headers. Forwarding them\n * verbatim to an arbitrary configured agent URL leaks client topology and, in\n * the Copilot Cloud case, a platform credential (#5712).\n *\n * `x-amz-cf-id` and `x-copilotcloud-public-api-key` are also covered by the\n * `x-amz-` / `x-copilotcloud-` prefixes below; the exact entries are kept\n * intentionally as documentation anchors for the highest-severity headers\n * (notably the platform API key), not as drift/oversight.\n */\nexport const DEFAULT_DENY_HEADER_NAMES: ReadonlySet<string> = new Set([\n // Hop-by-hop / proxy topology\n \"x-forwarded-for\",\n \"x-forwarded-proto\",\n \"x-forwarded-host\",\n \"x-forwarded-port\",\n \"x-forwarded-server\",\n \"x-real-ip\",\n // Cloud / CDN tracing + infra\n \"x-amzn-trace-id\",\n \"x-amz-cf-id\",\n \"x-cloud-trace-context\",\n \"x-cache\",\n \"x-served-by\",\n \"x-request-id\",\n // CopilotKit platform credentials/identifiers\n \"x-copilotcloud-public-api-key\",\n]);\n\n/**\n * Header-name prefixes (lowercased) stripped from forwarding by default.\n *\n * Prefix matching covers the well-known platform/CDN families so a new member\n * of a family (e.g. a future `x-vercel-foo`) is denied without a constant edit.\n */\nexport const DEFAULT_DENY_HEADER_PREFIXES: readonly string[] = [\n \"x-amz-\", // AWS\n \"x-azure-\", // Azure Front Door\n \"x-fastly-\", // Fastly\n \"x-vercel-\", // Vercel\n \"x-middleware-\", // Next.js\n \"x-copilotcloud-\", // CopilotKit platform-internal\n];\n\n/**\n * Fully-resolved inbound-header forwarding policy read by the call sites.\n *\n * Distinct from the public `ForwardHeadersConfig` option an integrator passes:\n * the runtime resolves that option ONCE in its constructor into this shape\n * (lowercasing names/prefixes, defaulting `useDefaultDenylist`, building the\n * `allow` set) so the predicate stays branch-simple and the policy can never be\n * re-resolved divergently at a call site. See `resolveForwardHeadersPolicy`.\n */\nexport interface ResolvedForwardHeadersPolicy {\n /** When true, the built-in infra/platform denylist is active. */\n useDefaultDenylist: boolean;\n /** Extra exact names to strip (lowercased). */\n denyNames: ReadonlySet<string>;\n /** Extra prefixes to strip (lowercased). */\n denyPrefixes: readonly string[];\n /**\n * If set, allowlist mode: ONLY these (lowercased) names are candidates to\n * forward — and `denyNames` / `denyPrefixes` still subtract from them.\n */\n allow?: ReadonlySet<string>;\n}\n\n/**\n * Public, integrator-facing config for inbound-header forwarding. Resolved into\n * a {@link ResolvedForwardHeadersPolicy} by {@link resolveForwardHeadersPolicy}.\n */\nexport interface ForwardHeadersConfig {\n /** Strip the built-in infra/platform denylist. @default true */\n useDefaultDenylist?: boolean;\n /** Additional exact header names to strip (case-insensitive). */\n deny?: string[];\n /** Additional header-name prefixes to strip (case-insensitive). */\n denyPrefixes?: string[];\n /**\n * If set (with at least one non-empty entry), switch to allowlist mode: ONLY\n * these headers are candidates to forward, overriding the default `x-*` /\n * `authorization` eligibility (case-insensitive). `deny` / `denyPrefixes`\n * still apply and subtract from this set — a header listed in both `allow` and\n * `deny` is NOT forwarded.\n *\n * Footgun: in allowlist mode the built-in DEFAULT denylist (and\n * `useDefaultDenylist`) is BYPASSED — only your `allow` set, minus your own\n * `deny` / `denyPrefixes`, is forwarded. Do NOT allow-list protected/platform\n * headers (e.g. `x-copilotcloud-public-api-key`, `x-forwarded-*`) unless you\n * truly intend to forward them, since the default protection does not apply\n * here.\n */\n allow?: string[];\n}\n\n/**\n * Normalizes a public {@link ForwardHeadersConfig} (or `undefined`) into a\n * fully-resolved {@link ResolvedForwardHeadersPolicy}.\n *\n * - `useDefaultDenylist` defaults to `true` (the built-in denylist is active\n * on upgrade); pass `false` to restore the previous wide-open behavior.\n * - `deny` / `denyPrefixes` extend (do not replace) the defaults.\n * - `allow` activates allowlist mode only when it has at least one non-empty\n * entry after normalization.\n *\n * All names/prefixes are trimmed, lowercased, and stripped of empty/\n * whitespace-only entries before use. Trimming/lowercasing keeps matching a\n * plain set/prefix check against the lowercased inbound keys; dropping empties\n * is a safety guard: a stray `denyPrefixes: [\"\"]` would make `startsWith(\"\")`\n * true for every header (silently denying ALL forwarding). Because empties are\n * dropped BEFORE the allowlist-mode decision, an `allow: [\"\"]` / `allow: [\" \"]`\n * normalizes to an empty set and does NOT switch on allowlist mode — the runtime\n * stays in denylist mode. Allowlist mode activates only when `allow` has at\n * least one non-empty entry; these empty/whitespace-only entries are integrator\n * typos, not intent, so we filter them.\n */\nfunction normalizeHeaderEntries(entries: string[] | undefined): string[] {\n return (entries ?? [])\n .map((entry) => entry.trim().toLowerCase())\n .filter((entry) => entry.length > 0);\n}\n\nexport function resolveForwardHeadersPolicy(\n config: ForwardHeadersConfig | undefined,\n): ResolvedForwardHeadersPolicy {\n const denyNames = new Set<string>(normalizeHeaderEntries(config?.deny));\n const denyPrefixes = normalizeHeaderEntries(config?.denyPrefixes);\n const allowEntries = normalizeHeaderEntries(config?.allow);\n const allow =\n allowEntries.length > 0 ? new Set<string>(allowEntries) : undefined;\n\n return {\n useDefaultDenylist: config?.useDefaultDenylist ?? true,\n denyNames,\n denyPrefixes,\n allow,\n };\n}\n\n/**\n * True iff the (already-lowercased) header name matches the integrator's OWN\n * `deny` / `denyPrefixes`. This is the authoritative subtractive check: it is\n * consulted in BOTH allowlist and denylist mode. It deliberately does NOT\n * include the built-in {@link DEFAULT_DENY_HEADER_NAMES} /\n * {@link DEFAULT_DENY_HEADER_PREFIXES} — an explicit `allow` opts the integrator\n * back into a default-denied header on purpose, so only their own `deny`\n * subtracts from an allowlist.\n */\nfunction matchesIntegratorDeny(\n lower: string,\n policy: ResolvedForwardHeadersPolicy,\n): boolean {\n if (policy.denyNames.has(lower)) return true;\n return policy.denyPrefixes.some((prefix) => lower.startsWith(prefix));\n}\n\n/**\n * Determines if a header should be forwarded under the given resolved policy.\n *\n * The integrator's `deny` / `denyPrefixes` ALWAYS strip, including in allowlist\n * mode: `allow` selects the candidate set, `deny` removes from it. A header the\n * integrator lists in BOTH `allow` and `deny` is NOT forwarded — deny is\n * authoritative so a security-motivated `deny` can never be silently defeated\n * by an overlapping `allow` (the footgun this hardens against).\n *\n * Modes:\n * - Allowlist (`policy.allow` set): forward iff the name is in `allow` AND is\n * NOT matched by the integrator's `deny` / `denyPrefixes`. Nothing else\n * forwards — not even the usual `authorization` / `x-*` eligibility.\n * - Denylist (default): base eligibility is `authorization` or any `x-*`, then\n * the built-in denylist (when enabled) and the integrator's own\n * names/prefixes strip from that set.\n *\n * Note: the built-in default denylist applies ONLY in denylist mode; an\n * explicit `allow` is treated as the integrator deliberately opting back into\n * those headers, so only their OWN `deny` subtracts in allowlist mode.\n */\nexport function shouldForwardHeader(\n headerName: string,\n policy: ResolvedForwardHeadersPolicy,\n): boolean {\n const lower = headerName.toLowerCase();\n\n // Allowlist mode: forward iff explicitly allowed AND not subtracted by the\n // integrator's own deny/denyPrefixes. Nothing else forwards — not even the\n // usual `authorization` / `x-*` eligibility.\n if (policy.allow) {\n return policy.allow.has(lower) && !matchesIntegratorDeny(lower, policy);\n }\n\n // Base eligibility (unchanged): authorization + any x-*.\n const eligible = lower === \"authorization\" || lower.startsWith(\"x-\");\n if (!eligible) return false;\n\n // Built-in denylist (default-on): strip known infra/platform headers.\n if (policy.useDefaultDenylist) {\n if (DEFAULT_DENY_HEADER_NAMES.has(lower)) return false;\n if (\n DEFAULT_DENY_HEADER_PREFIXES.some((prefix) => lower.startsWith(prefix))\n ) {\n return false;\n }\n }\n\n // Integrator-supplied additions extend the denylist regardless of the default.\n if (matchesIntegratorDeny(lower, policy)) return false;\n\n return true;\n}\n\n/**\n * Extracts headers that should be forwarded from a Request object, applying the\n * resolved forwarding policy. Keys are normalized to the lowercased form the\n * `Headers` iterator yields.\n */\nexport function extractForwardableHeaders(\n request: Request,\n policy: ResolvedForwardHeadersPolicy,\n): Record<string, string> {\n const forwardableHeaders: Record<string, string> = {};\n request.headers.forEach((value, key) => {\n if (shouldForwardHeader(key, policy)) {\n forwardableHeaders[key] = value;\n }\n });\n return forwardableHeaders;\n}\n\n/**\n * Merges forwardable inbound request headers onto the headers a server\n * explicitly configured on an agent, letting the SERVER-CONFIGURED headers WIN\n * on collision — a server-set service-to-service token (e.g. an IAM bearer)\n * must never be silently overridden by a browser/edge/platform-injected inbound\n * header (#5712).\n *\n * The collision check is case-insensitive: `extractForwardableHeaders`\n * normalizes inbound keys to lowercase (`authorization`) while the server\n * typically configures canonical casing (`Authorization`). A plain object\n * spread would treat those as distinct keys and emit BOTH — which downstream\n * (undici) comma-joins into a single invalid \"multiple JWTs\" value. So we drop\n * any forwarded header the agent already sets, matched case-insensitively, and\n * let non-colliding inbound headers pass through unchanged.\n *\n * The same comma-join hazard exists if the SERVER CONFIG ITSELF contains two\n * case-variants of one header (e.g. both `Authorization` and `authorization`\n * in `agent.headers`). A plain `{ ...serverHeaders }` spread would keep both,\n * so we additionally collapse server-self case-collisions to a SINGLE entry,\n * FIRST-OCCURRENCE WINS: the first key seen (in `Object.keys` order) keeps its\n * exact casing and value, and any later case-variant of that name is dropped.\n * Server-wins-over-inbound and case-insensitive inbound suppression are\n * otherwise unchanged.\n *\n * Breadth (which inbound headers are eligible to forward at all) is decided by\n * `policy` upstream in `extractForwardableHeaders` → `shouldForwardHeader`; the\n * merge never re-widens or re-narrows the set.\n */\nexport function mergeForwardableHeaders(\n serverHeaders: Record<string, string> | undefined,\n request: Request,\n policy: ResolvedForwardHeadersPolicy,\n): Record<string, string> {\n const base = serverHeaders ?? {};\n const merged: Record<string, string> = {};\n const serverHeaderNames = new Set<string>();\n // Collapse server-self case-collisions: first occurrence wins, later\n // case-variants of the same name are dropped.\n for (const [name, value] of Object.entries(base)) {\n const lower = name.toLowerCase();\n if (serverHeaderNames.has(lower)) {\n continue;\n }\n serverHeaderNames.add(lower);\n merged[name] = value;\n }\n for (const [name, value] of Object.entries(\n extractForwardableHeaders(request, policy),\n )) {\n if (!serverHeaderNames.has(name.toLowerCase())) {\n merged[name] = value;\n }\n }\n return merged;\n}\n"],"mappings":";;;;;;;;;;;;;;;;AAeA,MAAa,4BAAiD,IAAI,IAAI;CAEpE;CACA;CACA;CACA;CACA;CACA;CAEA;CACA;CACA;CACA;CACA;CACA;CAEA;CACD,CAAC;;;;;;;AAQF,MAAa,+BAAkD;CAC7D;CACA;CACA;CACA;CACA;CACA;CACD;;;;;;;;;;;;;;;;;;;;;;AA0ED,SAAS,uBAAuB,SAAyC;AACvE,SAAQ,WAAW,EAAE,EAClB,KAAK,UAAU,MAAM,MAAM,CAAC,aAAa,CAAC,CAC1C,QAAQ,UAAU,MAAM,SAAS,EAAE;;AAGxC,SAAgB,4BACd,QAC8B;CAC9B,MAAM,YAAY,IAAI,IAAY,uBAAuB,QAAQ,KAAK,CAAC;CACvE,MAAM,eAAe,uBAAuB,QAAQ,aAAa;CACjE,MAAM,eAAe,uBAAuB,QAAQ,MAAM;CAC1D,MAAM,QACJ,aAAa,SAAS,IAAI,IAAI,IAAY,aAAa,GAAG;AAE5D,QAAO;EACL,oBAAoB,QAAQ,sBAAsB;EAClD;EACA;EACA;EACD;;;;;;;;;;;AAYH,SAAS,sBACP,OACA,QACS;AACT,KAAI,OAAO,UAAU,IAAI,MAAM,CAAE,QAAO;AACxC,QAAO,OAAO,aAAa,MAAM,WAAW,MAAM,WAAW,OAAO,CAAC;;;;;;;;;;;;;;;;;;;;;;;AAwBvE,SAAgB,oBACd,YACA,QACS;CACT,MAAM,QAAQ,WAAW,aAAa;AAKtC,KAAI,OAAO,MACT,QAAO,OAAO,MAAM,IAAI,MAAM,IAAI,CAAC,sBAAsB,OAAO,OAAO;AAKzE,KAAI,EADa,UAAU,mBAAmB,MAAM,WAAW,KAAK,EACrD,QAAO;AAGtB,KAAI,OAAO,oBAAoB;AAC7B,MAAI,0BAA0B,IAAI,MAAM,CAAE,QAAO;AACjD,MACE,6BAA6B,MAAM,WAAW,MAAM,WAAW,OAAO,CAAC,CAEvE,QAAO;;AAKX,KAAI,sBAAsB,OAAO,OAAO,CAAE,QAAO;AAEjD,QAAO;;;;;;;AAQT,SAAgB,0BACd,SACA,QACwB;CACxB,MAAM,qBAA6C,EAAE;AACrD,SAAQ,QAAQ,SAAS,OAAO,QAAQ;AACtC,MAAI,oBAAoB,KAAK,OAAO,CAClC,oBAAmB,OAAO;GAE5B;AACF,QAAO;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA+BT,SAAgB,wBACd,eACA,SACA,QACwB;CACxB,MAAM,OAAO,iBAAiB,EAAE;CAChC,MAAM,SAAiC,EAAE;CACzC,MAAM,oCAAoB,IAAI,KAAa;AAG3C,MAAK,MAAM,CAAC,MAAM,UAAU,OAAO,QAAQ,KAAK,EAAE;EAChD,MAAM,QAAQ,KAAK,aAAa;AAChC,MAAI,kBAAkB,IAAI,MAAM,CAC9B;AAEF,oBAAkB,IAAI,MAAM;AAC5B,SAAO,QAAQ;;AAEjB,MAAK,MAAM,CAAC,MAAM,UAAU,OAAO,QACjC,0BAA0B,SAAS,OAAO,CAC3C,CACC,KAAI,CAAC,kBAAkB,IAAI,KAAK,aAAa,CAAC,CAC5C,QAAO,QAAQ;AAGnB,QAAO"}
@@ -0,0 +1,83 @@
1
+ const require_runtime = require('../../../_virtual/_rolldown/runtime.cjs');
2
+ const require_json_response = require('../shared/json-response.cjs');
3
+ const require_client = require('../../intelligence-platform/client.cjs');
4
+ const require_resolve_intelligence_user = require('../shared/resolve-intelligence-user.cjs');
5
+ const require_runtime$1 = require('../../core/runtime.cjs');
6
+ let _copilotkit_shared = require("@copilotkit/shared");
7
+
8
+ //#region src/runtime/handlers/intelligence/annotate.ts
9
+ async function parseJsonBody(request) {
10
+ try {
11
+ return await request.json();
12
+ } catch (error) {
13
+ _copilotkit_shared.logger.error({ err: error }, "Malformed JSON in annotate body");
14
+ return require_json_response.errorResponse("Invalid request body", 400);
15
+ }
16
+ }
17
+ function requireIntelligenceRuntime(runtime) {
18
+ if (!require_runtime$1.isIntelligenceRuntime(runtime)) return require_json_response.errorResponse("Missing CopilotKitIntelligence configuration. annotate requires a CopilotKitIntelligence instance to be provided in CopilotRuntime options.", 422);
19
+ return runtime;
20
+ }
21
+ function isNonEmptyString(value) {
22
+ return typeof value === "string" && value.length > 0;
23
+ }
24
+ /**
25
+ * `POST /annotate` handler.
26
+ *
27
+ * Three-tier flow:
28
+ * recordAnnotation() (frontend lib; called by useLearnFromUserAction)
29
+ * → POST ${runtimeUrl}/annotate
30
+ * → this handler resolves the Intel user from BFF auth
31
+ * → intelligence.annotate(...)
32
+ * → PUT ${apiUrl}/connector/annotate/:clientEventId
33
+ *
34
+ * The frontend hook may auto-generate a UUID `clientEventId` per call
35
+ * so retries are idempotent end-to-end (the platform collapses to the
36
+ * original row).
37
+ */
38
+ async function handleAnnotate({ runtime, request }) {
39
+ const intelligenceRuntime = requireIntelligenceRuntime(runtime);
40
+ if (require_json_response.isHandlerResponse(intelligenceRuntime)) return intelligenceRuntime;
41
+ const body = await parseJsonBody(request);
42
+ if (require_json_response.isHandlerResponse(body)) return body;
43
+ const user = await require_resolve_intelligence_user.resolveIntelligenceUser({
44
+ runtime: intelligenceRuntime,
45
+ request
46
+ });
47
+ if (require_json_response.isHandlerResponse(user)) return user;
48
+ const parsed = parseAnnotateBody(body);
49
+ if (require_json_response.isHandlerResponse(parsed)) return parsed;
50
+ try {
51
+ const result = await intelligenceRuntime.intelligence.annotate({
52
+ userId: user.id,
53
+ threadId: parsed.threadId,
54
+ type: parsed.type,
55
+ payload: parsed.payload,
56
+ clientEventId: parsed.clientEventId,
57
+ occurredAt: parsed.occurredAt
58
+ });
59
+ return new Response(JSON.stringify(result), {
60
+ status: 200,
61
+ headers: { "Content-Type": "application/json" }
62
+ });
63
+ } catch (err) {
64
+ _copilotkit_shared.logger.error({ err }, "annotate: platform call failed");
65
+ if (err instanceof require_client.PlatformRequestError && err.status >= 400 && err.status < 500) return require_json_response.errorResponse(err.message, err.status);
66
+ return require_json_response.errorResponse("Failed to annotate", 502);
67
+ }
68
+ }
69
+ function parseAnnotateBody(body) {
70
+ if (!isNonEmptyString(body.threadId)) return require_json_response.errorResponse("Valid threadId is required", 400);
71
+ if (!isNonEmptyString(body.type)) return require_json_response.errorResponse("Valid type is required", 400);
72
+ return {
73
+ type: body.type,
74
+ payload: body.payload,
75
+ threadId: body.threadId,
76
+ clientEventId: isNonEmptyString(body.clientEventId) ? body.clientEventId : void 0,
77
+ occurredAt: isNonEmptyString(body.occurredAt) ? body.occurredAt : void 0
78
+ };
79
+ }
80
+
81
+ //#endregion
82
+ exports.handleAnnotate = handleAnnotate;
83
+ //# sourceMappingURL=annotate.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"annotate.cjs","names":["errorResponse","isIntelligenceRuntime","isHandlerResponse","resolveIntelligenceUser","PlatformRequestError"],"sources":["../../../../src/runtime/handlers/intelligence/annotate.ts"],"sourcesContent":["import { logger } from \"@copilotkit/shared\";\nimport type {\n CopilotIntelligenceRuntimeLike,\n CopilotRuntimeLike,\n} from \"../../core/runtime\";\nimport { isIntelligenceRuntime } from \"../../core/runtime\";\nimport { PlatformRequestError } from \"../../intelligence-platform/client\";\nimport { errorResponse, isHandlerResponse } from \"../shared/json-response\";\nimport { resolveIntelligenceUser } from \"../shared/resolve-intelligence-user\";\n\ninterface AnnotateHandlerParams {\n runtime: CopilotRuntimeLike;\n request: Request;\n}\n\ninterface AnnotateBody {\n /** Discriminator identifying the annotation type (e.g. `\"user_action\"`). */\n type: string;\n /** Type-specific payload. Shape varies by `type`. */\n payload?: unknown;\n /** The thread the annotation is associated with. */\n threadId: string;\n /** Caller-supplied idempotency key. Optional — platform auto-generates one when absent. */\n clientEventId?: string;\n /** ISO-8601 client-asserted timestamp. Defaults to server NOW() when absent. */\n occurredAt?: string;\n}\n\nasync function parseJsonBody(\n request: Request,\n): Promise<Record<string, unknown> | Response> {\n try {\n return (await request.json()) as Record<string, unknown>;\n } catch (error) {\n logger.error({ err: error }, \"Malformed JSON in annotate body\");\n return errorResponse(\"Invalid request body\", 400);\n }\n}\n\nfunction requireIntelligenceRuntime(\n runtime: CopilotRuntimeLike,\n): CopilotIntelligenceRuntimeLike | Response {\n if (!isIntelligenceRuntime(runtime)) {\n return errorResponse(\n \"Missing CopilotKitIntelligence configuration. annotate requires a CopilotKitIntelligence instance to be provided in CopilotRuntime options.\",\n 422,\n );\n }\n return runtime;\n}\n\nfunction isNonEmptyString(value: unknown): value is string {\n return typeof value === \"string\" && value.length > 0;\n}\n\n/**\n * `POST /annotate` handler.\n *\n * Three-tier flow:\n * recordAnnotation() (frontend lib; called by useLearnFromUserAction)\n * → POST ${runtimeUrl}/annotate\n * → this handler resolves the Intel user from BFF auth\n * → intelligence.annotate(...)\n * → PUT ${apiUrl}/connector/annotate/:clientEventId\n *\n * The frontend hook may auto-generate a UUID `clientEventId` per call\n * so retries are idempotent end-to-end (the platform collapses to the\n * original row).\n */\nexport async function handleAnnotate({\n runtime,\n request,\n}: AnnotateHandlerParams): Promise<Response> {\n const intelligenceRuntime = requireIntelligenceRuntime(runtime);\n if (isHandlerResponse(intelligenceRuntime)) return intelligenceRuntime;\n\n const body = await parseJsonBody(request);\n if (isHandlerResponse(body)) return body;\n\n const user = await resolveIntelligenceUser({\n runtime: intelligenceRuntime,\n request,\n });\n if (isHandlerResponse(user)) return user;\n\n const parsed = parseAnnotateBody(body);\n if (isHandlerResponse(parsed)) return parsed;\n\n try {\n const result = await intelligenceRuntime.intelligence.annotate({\n userId: user.id,\n threadId: parsed.threadId,\n type: parsed.type,\n payload: parsed.payload,\n clientEventId: parsed.clientEventId,\n occurredAt: parsed.occurredAt,\n });\n return new Response(JSON.stringify(result), {\n status: 200,\n headers: { \"Content-Type\": \"application/json\" },\n });\n } catch (err) {\n logger.error({ err }, \"annotate: platform call failed\");\n // Forward the platform's HTTP status when it's a client error\n // (4xx) so the SDK author sees an actionable response instead of\n // a generic 502. 5xx and non-platform errors collapse to 502\n // (\"Bad Gateway\") because the upstream is genuinely at fault.\n if (\n err instanceof PlatformRequestError &&\n err.status >= 400 &&\n err.status < 500\n ) {\n return errorResponse(err.message, err.status);\n }\n return errorResponse(\"Failed to annotate\", 502);\n }\n}\n\nfunction parseAnnotateBody(\n body: Record<string, unknown>,\n): AnnotateBody | Response {\n if (!isNonEmptyString(body.threadId)) {\n return errorResponse(\"Valid threadId is required\", 400);\n }\n if (!isNonEmptyString(body.type)) {\n return errorResponse(\"Valid type is required\", 400);\n }\n return {\n type: body.type,\n payload: body.payload,\n threadId: body.threadId,\n clientEventId: isNonEmptyString(body.clientEventId)\n ? body.clientEventId\n : undefined,\n occurredAt: isNonEmptyString(body.occurredAt) ? body.occurredAt : undefined,\n };\n}\n"],"mappings":";;;;;;;;AA4BA,eAAe,cACb,SAC6C;AAC7C,KAAI;AACF,SAAQ,MAAM,QAAQ,MAAM;UACrB,OAAO;AACd,4BAAO,MAAM,EAAE,KAAK,OAAO,EAAE,kCAAkC;AAC/D,SAAOA,oCAAc,wBAAwB,IAAI;;;AAIrD,SAAS,2BACP,SAC2C;AAC3C,KAAI,CAACC,wCAAsB,QAAQ,CACjC,QAAOD,oCACL,+IACA,IACD;AAEH,QAAO;;AAGT,SAAS,iBAAiB,OAAiC;AACzD,QAAO,OAAO,UAAU,YAAY,MAAM,SAAS;;;;;;;;;;;;;;;;AAiBrD,eAAsB,eAAe,EACnC,SACA,WAC2C;CAC3C,MAAM,sBAAsB,2BAA2B,QAAQ;AAC/D,KAAIE,wCAAkB,oBAAoB,CAAE,QAAO;CAEnD,MAAM,OAAO,MAAM,cAAc,QAAQ;AACzC,KAAIA,wCAAkB,KAAK,CAAE,QAAO;CAEpC,MAAM,OAAO,MAAMC,0DAAwB;EACzC,SAAS;EACT;EACD,CAAC;AACF,KAAID,wCAAkB,KAAK,CAAE,QAAO;CAEpC,MAAM,SAAS,kBAAkB,KAAK;AACtC,KAAIA,wCAAkB,OAAO,CAAE,QAAO;AAEtC,KAAI;EACF,MAAM,SAAS,MAAM,oBAAoB,aAAa,SAAS;GAC7D,QAAQ,KAAK;GACb,UAAU,OAAO;GACjB,MAAM,OAAO;GACb,SAAS,OAAO;GAChB,eAAe,OAAO;GACtB,YAAY,OAAO;GACpB,CAAC;AACF,SAAO,IAAI,SAAS,KAAK,UAAU,OAAO,EAAE;GAC1C,QAAQ;GACR,SAAS,EAAE,gBAAgB,oBAAoB;GAChD,CAAC;UACK,KAAK;AACZ,4BAAO,MAAM,EAAE,KAAK,EAAE,iCAAiC;AAKvD,MACE,eAAeE,uCACf,IAAI,UAAU,OACd,IAAI,SAAS,IAEb,QAAOJ,oCAAc,IAAI,SAAS,IAAI,OAAO;AAE/C,SAAOA,oCAAc,sBAAsB,IAAI;;;AAInD,SAAS,kBACP,MACyB;AACzB,KAAI,CAAC,iBAAiB,KAAK,SAAS,CAClC,QAAOA,oCAAc,8BAA8B,IAAI;AAEzD,KAAI,CAAC,iBAAiB,KAAK,KAAK,CAC9B,QAAOA,oCAAc,0BAA0B,IAAI;AAErD,QAAO;EACL,MAAM,KAAK;EACX,SAAS,KAAK;EACd,UAAU,KAAK;EACf,eAAe,iBAAiB,KAAK,cAAc,GAC/C,KAAK,gBACL;EACJ,YAAY,iBAAiB,KAAK,WAAW,GAAG,KAAK,aAAa;EACnE"}
@@ -0,0 +1,82 @@
1
+ import { errorResponse, isHandlerResponse } from "../shared/json-response.mjs";
2
+ import { PlatformRequestError } from "../../intelligence-platform/client.mjs";
3
+ import { resolveIntelligenceUser } from "../shared/resolve-intelligence-user.mjs";
4
+ import { isIntelligenceRuntime } from "../../core/runtime.mjs";
5
+ import { logger } from "@copilotkit/shared";
6
+
7
+ //#region src/runtime/handlers/intelligence/annotate.ts
8
+ async function parseJsonBody(request) {
9
+ try {
10
+ return await request.json();
11
+ } catch (error) {
12
+ logger.error({ err: error }, "Malformed JSON in annotate body");
13
+ return errorResponse("Invalid request body", 400);
14
+ }
15
+ }
16
+ function requireIntelligenceRuntime(runtime) {
17
+ if (!isIntelligenceRuntime(runtime)) return errorResponse("Missing CopilotKitIntelligence configuration. annotate requires a CopilotKitIntelligence instance to be provided in CopilotRuntime options.", 422);
18
+ return runtime;
19
+ }
20
+ function isNonEmptyString(value) {
21
+ return typeof value === "string" && value.length > 0;
22
+ }
23
+ /**
24
+ * `POST /annotate` handler.
25
+ *
26
+ * Three-tier flow:
27
+ * recordAnnotation() (frontend lib; called by useLearnFromUserAction)
28
+ * → POST ${runtimeUrl}/annotate
29
+ * → this handler resolves the Intel user from BFF auth
30
+ * → intelligence.annotate(...)
31
+ * → PUT ${apiUrl}/connector/annotate/:clientEventId
32
+ *
33
+ * The frontend hook may auto-generate a UUID `clientEventId` per call
34
+ * so retries are idempotent end-to-end (the platform collapses to the
35
+ * original row).
36
+ */
37
+ async function handleAnnotate({ runtime, request }) {
38
+ const intelligenceRuntime = requireIntelligenceRuntime(runtime);
39
+ if (isHandlerResponse(intelligenceRuntime)) return intelligenceRuntime;
40
+ const body = await parseJsonBody(request);
41
+ if (isHandlerResponse(body)) return body;
42
+ const user = await resolveIntelligenceUser({
43
+ runtime: intelligenceRuntime,
44
+ request
45
+ });
46
+ if (isHandlerResponse(user)) return user;
47
+ const parsed = parseAnnotateBody(body);
48
+ if (isHandlerResponse(parsed)) return parsed;
49
+ try {
50
+ const result = await intelligenceRuntime.intelligence.annotate({
51
+ userId: user.id,
52
+ threadId: parsed.threadId,
53
+ type: parsed.type,
54
+ payload: parsed.payload,
55
+ clientEventId: parsed.clientEventId,
56
+ occurredAt: parsed.occurredAt
57
+ });
58
+ return new Response(JSON.stringify(result), {
59
+ status: 200,
60
+ headers: { "Content-Type": "application/json" }
61
+ });
62
+ } catch (err) {
63
+ logger.error({ err }, "annotate: platform call failed");
64
+ if (err instanceof PlatformRequestError && err.status >= 400 && err.status < 500) return errorResponse(err.message, err.status);
65
+ return errorResponse("Failed to annotate", 502);
66
+ }
67
+ }
68
+ function parseAnnotateBody(body) {
69
+ if (!isNonEmptyString(body.threadId)) return errorResponse("Valid threadId is required", 400);
70
+ if (!isNonEmptyString(body.type)) return errorResponse("Valid type is required", 400);
71
+ return {
72
+ type: body.type,
73
+ payload: body.payload,
74
+ threadId: body.threadId,
75
+ clientEventId: isNonEmptyString(body.clientEventId) ? body.clientEventId : void 0,
76
+ occurredAt: isNonEmptyString(body.occurredAt) ? body.occurredAt : void 0
77
+ };
78
+ }
79
+
80
+ //#endregion
81
+ export { handleAnnotate };
82
+ //# sourceMappingURL=annotate.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"annotate.mjs","names":[],"sources":["../../../../src/runtime/handlers/intelligence/annotate.ts"],"sourcesContent":["import { logger } from \"@copilotkit/shared\";\nimport type {\n CopilotIntelligenceRuntimeLike,\n CopilotRuntimeLike,\n} from \"../../core/runtime\";\nimport { isIntelligenceRuntime } from \"../../core/runtime\";\nimport { PlatformRequestError } from \"../../intelligence-platform/client\";\nimport { errorResponse, isHandlerResponse } from \"../shared/json-response\";\nimport { resolveIntelligenceUser } from \"../shared/resolve-intelligence-user\";\n\ninterface AnnotateHandlerParams {\n runtime: CopilotRuntimeLike;\n request: Request;\n}\n\ninterface AnnotateBody {\n /** Discriminator identifying the annotation type (e.g. `\"user_action\"`). */\n type: string;\n /** Type-specific payload. Shape varies by `type`. */\n payload?: unknown;\n /** The thread the annotation is associated with. */\n threadId: string;\n /** Caller-supplied idempotency key. Optional — platform auto-generates one when absent. */\n clientEventId?: string;\n /** ISO-8601 client-asserted timestamp. Defaults to server NOW() when absent. */\n occurredAt?: string;\n}\n\nasync function parseJsonBody(\n request: Request,\n): Promise<Record<string, unknown> | Response> {\n try {\n return (await request.json()) as Record<string, unknown>;\n } catch (error) {\n logger.error({ err: error }, \"Malformed JSON in annotate body\");\n return errorResponse(\"Invalid request body\", 400);\n }\n}\n\nfunction requireIntelligenceRuntime(\n runtime: CopilotRuntimeLike,\n): CopilotIntelligenceRuntimeLike | Response {\n if (!isIntelligenceRuntime(runtime)) {\n return errorResponse(\n \"Missing CopilotKitIntelligence configuration. annotate requires a CopilotKitIntelligence instance to be provided in CopilotRuntime options.\",\n 422,\n );\n }\n return runtime;\n}\n\nfunction isNonEmptyString(value: unknown): value is string {\n return typeof value === \"string\" && value.length > 0;\n}\n\n/**\n * `POST /annotate` handler.\n *\n * Three-tier flow:\n * recordAnnotation() (frontend lib; called by useLearnFromUserAction)\n * → POST ${runtimeUrl}/annotate\n * → this handler resolves the Intel user from BFF auth\n * → intelligence.annotate(...)\n * → PUT ${apiUrl}/connector/annotate/:clientEventId\n *\n * The frontend hook may auto-generate a UUID `clientEventId` per call\n * so retries are idempotent end-to-end (the platform collapses to the\n * original row).\n */\nexport async function handleAnnotate({\n runtime,\n request,\n}: AnnotateHandlerParams): Promise<Response> {\n const intelligenceRuntime = requireIntelligenceRuntime(runtime);\n if (isHandlerResponse(intelligenceRuntime)) return intelligenceRuntime;\n\n const body = await parseJsonBody(request);\n if (isHandlerResponse(body)) return body;\n\n const user = await resolveIntelligenceUser({\n runtime: intelligenceRuntime,\n request,\n });\n if (isHandlerResponse(user)) return user;\n\n const parsed = parseAnnotateBody(body);\n if (isHandlerResponse(parsed)) return parsed;\n\n try {\n const result = await intelligenceRuntime.intelligence.annotate({\n userId: user.id,\n threadId: parsed.threadId,\n type: parsed.type,\n payload: parsed.payload,\n clientEventId: parsed.clientEventId,\n occurredAt: parsed.occurredAt,\n });\n return new Response(JSON.stringify(result), {\n status: 200,\n headers: { \"Content-Type\": \"application/json\" },\n });\n } catch (err) {\n logger.error({ err }, \"annotate: platform call failed\");\n // Forward the platform's HTTP status when it's a client error\n // (4xx) so the SDK author sees an actionable response instead of\n // a generic 502. 5xx and non-platform errors collapse to 502\n // (\"Bad Gateway\") because the upstream is genuinely at fault.\n if (\n err instanceof PlatformRequestError &&\n err.status >= 400 &&\n err.status < 500\n ) {\n return errorResponse(err.message, err.status);\n }\n return errorResponse(\"Failed to annotate\", 502);\n }\n}\n\nfunction parseAnnotateBody(\n body: Record<string, unknown>,\n): AnnotateBody | Response {\n if (!isNonEmptyString(body.threadId)) {\n return errorResponse(\"Valid threadId is required\", 400);\n }\n if (!isNonEmptyString(body.type)) {\n return errorResponse(\"Valid type is required\", 400);\n }\n return {\n type: body.type,\n payload: body.payload,\n threadId: body.threadId,\n clientEventId: isNonEmptyString(body.clientEventId)\n ? body.clientEventId\n : undefined,\n occurredAt: isNonEmptyString(body.occurredAt) ? body.occurredAt : undefined,\n };\n}\n"],"mappings":";;;;;;;AA4BA,eAAe,cACb,SAC6C;AAC7C,KAAI;AACF,SAAQ,MAAM,QAAQ,MAAM;UACrB,OAAO;AACd,SAAO,MAAM,EAAE,KAAK,OAAO,EAAE,kCAAkC;AAC/D,SAAO,cAAc,wBAAwB,IAAI;;;AAIrD,SAAS,2BACP,SAC2C;AAC3C,KAAI,CAAC,sBAAsB,QAAQ,CACjC,QAAO,cACL,+IACA,IACD;AAEH,QAAO;;AAGT,SAAS,iBAAiB,OAAiC;AACzD,QAAO,OAAO,UAAU,YAAY,MAAM,SAAS;;;;;;;;;;;;;;;;AAiBrD,eAAsB,eAAe,EACnC,SACA,WAC2C;CAC3C,MAAM,sBAAsB,2BAA2B,QAAQ;AAC/D,KAAI,kBAAkB,oBAAoB,CAAE,QAAO;CAEnD,MAAM,OAAO,MAAM,cAAc,QAAQ;AACzC,KAAI,kBAAkB,KAAK,CAAE,QAAO;CAEpC,MAAM,OAAO,MAAM,wBAAwB;EACzC,SAAS;EACT;EACD,CAAC;AACF,KAAI,kBAAkB,KAAK,CAAE,QAAO;CAEpC,MAAM,SAAS,kBAAkB,KAAK;AACtC,KAAI,kBAAkB,OAAO,CAAE,QAAO;AAEtC,KAAI;EACF,MAAM,SAAS,MAAM,oBAAoB,aAAa,SAAS;GAC7D,QAAQ,KAAK;GACb,UAAU,OAAO;GACjB,MAAM,OAAO;GACb,SAAS,OAAO;GAChB,eAAe,OAAO;GACtB,YAAY,OAAO;GACpB,CAAC;AACF,SAAO,IAAI,SAAS,KAAK,UAAU,OAAO,EAAE;GAC1C,QAAQ;GACR,SAAS,EAAE,gBAAgB,oBAAoB;GAChD,CAAC;UACK,KAAK;AACZ,SAAO,MAAM,EAAE,KAAK,EAAE,iCAAiC;AAKvD,MACE,eAAe,wBACf,IAAI,UAAU,OACd,IAAI,SAAS,IAEb,QAAO,cAAc,IAAI,SAAS,IAAI,OAAO;AAE/C,SAAO,cAAc,sBAAsB,IAAI;;;AAInD,SAAS,kBACP,MACyB;AACzB,KAAI,CAAC,iBAAiB,KAAK,SAAS,CAClC,QAAO,cAAc,8BAA8B,IAAI;AAEzD,KAAI,CAAC,iBAAiB,KAAK,KAAK,CAC9B,QAAO,cAAc,0BAA0B,IAAI;AAErD,QAAO;EACL,MAAM,KAAK;EACX,SAAS,KAAK;EACd,UAAU,KAAK;EACf,eAAe,iBAAiB,KAAK,cAAc,GAC/C,KAAK,gBACL;EACJ,YAAY,iBAAiB,KAAK,WAAW,GAAG,KAAK,aAAa;EACnE"}
@@ -0,0 +1,68 @@
1
+ const require_json_response = require('../shared/json-response.cjs');
2
+ const require_intelligence_utils = require('../shared/intelligence-utils.cjs');
3
+ const require_resolve_intelligence_user = require('../shared/resolve-intelligence-user.cjs');
4
+
5
+ //#region src/runtime/handlers/intelligence/connect.ts
6
+ /**
7
+ * Builds browser-facing realtime connection metadata owned by the runtime.
8
+ */
9
+ function buildRealtimeConnectionInfo(params) {
10
+ return {
11
+ clientUrl: params.clientUrl,
12
+ topic: `thread:${params.threadId}`
13
+ };
14
+ }
15
+ async function handleIntelligenceConnect({ runtime, request, agentId, threadId }) {
16
+ if (!runtime.intelligence) return Response.json({
17
+ error: "Intelligence not configured",
18
+ message: "Intelligence mode requires a CopilotKitIntelligence"
19
+ }, { status: 500 });
20
+ try {
21
+ const user = await require_resolve_intelligence_user.resolveIntelligenceUser({
22
+ runtime,
23
+ request
24
+ });
25
+ if (require_json_response.isHandlerResponse(user)) return user;
26
+ const result = await runtime.intelligence.ɵconnectThread({
27
+ threadId,
28
+ userId: user.id,
29
+ agentId
30
+ });
31
+ if (result === null) return new Response(null, { status: 204 });
32
+ return Response.json({
33
+ threadId: result.threadId,
34
+ joinToken: result.joinToken,
35
+ runId: result.runId,
36
+ realtime: buildRealtimeConnectionInfo({
37
+ clientUrl: runtime.intelligence.ɵgetClientWsUrl(),
38
+ threadId: result.threadId
39
+ })
40
+ }, { headers: {
41
+ "Cache-Control": "no-cache",
42
+ Connection: "keep-alive"
43
+ } });
44
+ } catch (error) {
45
+ const status = require_intelligence_utils.getPlatformErrorStatus(error);
46
+ const message = error instanceof Error ? error.message : "Connect request failed";
47
+ if (status === 400 || status === 401 || status === 403 || status === 404 || status === 409) return Response.json({
48
+ error: "Connect request rejected",
49
+ message: error instanceof Error ? error.message : "Intelligence platform rejected the connect request"
50
+ }, { status });
51
+ if (typeof status === "number") {
52
+ console.error(`Connect request failed with status ${status}:`, error);
53
+ return Response.json({
54
+ error: "Connect request failed",
55
+ message
56
+ }, { status });
57
+ }
58
+ console.error("Connect request could not reach Intelligence:", error);
59
+ return Response.json({
60
+ error: "Connect request failed",
61
+ message
62
+ }, { status: 502 });
63
+ }
64
+ }
65
+
66
+ //#endregion
67
+ exports.handleIntelligenceConnect = handleIntelligenceConnect;
68
+ //# sourceMappingURL=connect.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"connect.cjs","names":["resolveIntelligenceUser","isHandlerResponse","getPlatformErrorStatus"],"sources":["../../../../src/runtime/handlers/intelligence/connect.ts"],"sourcesContent":["import type { CopilotIntelligenceRuntimeLike } from \"../../core/runtime\";\nimport { getPlatformErrorStatus } from \"../shared/intelligence-utils\";\nimport { resolveIntelligenceUser } from \"../shared/resolve-intelligence-user\";\nimport { isHandlerResponse } from \"../shared/json-response\";\n\n/**\n * Builds browser-facing realtime connection metadata owned by the runtime.\n */\nfunction buildRealtimeConnectionInfo(params: {\n clientUrl: string;\n threadId: string;\n}): { clientUrl: string; topic: string } {\n return {\n clientUrl: params.clientUrl,\n topic: `thread:${params.threadId}`,\n };\n}\n\ninterface HandleIntelligenceConnectParams {\n runtime: CopilotIntelligenceRuntimeLike;\n request: Request;\n agentId: string;\n threadId: string;\n}\n\nexport async function handleIntelligenceConnect({\n runtime,\n request,\n agentId,\n threadId,\n}: HandleIntelligenceConnectParams): Promise<Response> {\n if (!runtime.intelligence) {\n return Response.json(\n {\n error: \"Intelligence not configured\",\n message: \"Intelligence mode requires a CopilotKitIntelligence\",\n },\n { status: 500 },\n );\n }\n\n try {\n const user = await resolveIntelligenceUser({ runtime, request });\n if (isHandlerResponse(user)) {\n return user;\n }\n\n const result = await runtime.intelligence.ɵconnectThread({\n threadId,\n userId: user.id,\n agentId,\n });\n\n if (result === null) {\n return new Response(null, {\n status: 204,\n });\n }\n\n return Response.json(\n {\n threadId: result.threadId,\n joinToken: result.joinToken,\n runId: result.runId,\n realtime: buildRealtimeConnectionInfo({\n clientUrl: runtime.intelligence.ɵgetClientWsUrl(),\n threadId: result.threadId,\n }),\n },\n {\n headers: { \"Cache-Control\": \"no-cache\", Connection: \"keep-alive\" },\n },\n );\n } catch (error) {\n const status = getPlatformErrorStatus(error);\n const message =\n error instanceof Error ? error.message : \"Connect request failed\";\n\n if (\n status === 400 ||\n status === 401 ||\n status === 403 ||\n status === 404 ||\n status === 409\n ) {\n return Response.json(\n {\n error: \"Connect request rejected\",\n message:\n error instanceof Error\n ? error.message\n : \"Intelligence platform rejected the connect request\",\n },\n { status },\n );\n }\n\n // The platform answered, but with a status we do not special-case above.\n // Pass it through rather than relabelling it: reporting a 503 as a 404 tells\n // the browser the thread does not exist, when the truth is that the platform\n // is temporarily unwell and the request is worth retrying.\n if (typeof status === \"number\") {\n console.error(`Connect request failed with status ${status}:`, error);\n return Response.json(\n { error: \"Connect request failed\", message },\n {\n status,\n },\n );\n }\n\n // No status at all, so this never reached the platform: a socket timeout, a\n // DNS failure, a connection reset, or a bug on our side. 502 says \"the thing\n // behind me is unreachable\", which is both true and actionable. It must not\n // be a 404, which asserts the thread does not exist and sends the caller off\n // to investigate the wrong thing entirely.\n console.error(\"Connect request could not reach Intelligence:\", error);\n return Response.json(\n {\n error: \"Connect request failed\",\n message,\n },\n { status: 502 },\n );\n }\n}\n"],"mappings":";;;;;;;;AAQA,SAAS,4BAA4B,QAGI;AACvC,QAAO;EACL,WAAW,OAAO;EAClB,OAAO,UAAU,OAAO;EACzB;;AAUH,eAAsB,0BAA0B,EAC9C,SACA,SACA,SACA,YACqD;AACrD,KAAI,CAAC,QAAQ,aACX,QAAO,SAAS,KACd;EACE,OAAO;EACP,SAAS;EACV,EACD,EAAE,QAAQ,KAAK,CAChB;AAGH,KAAI;EACF,MAAM,OAAO,MAAMA,0DAAwB;GAAE;GAAS;GAAS,CAAC;AAChE,MAAIC,wCAAkB,KAAK,CACzB,QAAO;EAGT,MAAM,SAAS,MAAM,QAAQ,aAAa,eAAe;GACvD;GACA,QAAQ,KAAK;GACb;GACD,CAAC;AAEF,MAAI,WAAW,KACb,QAAO,IAAI,SAAS,MAAM,EACxB,QAAQ,KACT,CAAC;AAGJ,SAAO,SAAS,KACd;GACE,UAAU,OAAO;GACjB,WAAW,OAAO;GAClB,OAAO,OAAO;GACd,UAAU,4BAA4B;IACpC,WAAW,QAAQ,aAAa,iBAAiB;IACjD,UAAU,OAAO;IAClB,CAAC;GACH,EACD,EACE,SAAS;GAAE,iBAAiB;GAAY,YAAY;GAAc,EACnE,CACF;UACM,OAAO;EACd,MAAM,SAASC,kDAAuB,MAAM;EAC5C,MAAM,UACJ,iBAAiB,QAAQ,MAAM,UAAU;AAE3C,MACE,WAAW,OACX,WAAW,OACX,WAAW,OACX,WAAW,OACX,WAAW,IAEX,QAAO,SAAS,KACd;GACE,OAAO;GACP,SACE,iBAAiB,QACb,MAAM,UACN;GACP,EACD,EAAE,QAAQ,CACX;AAOH,MAAI,OAAO,WAAW,UAAU;AAC9B,WAAQ,MAAM,sCAAsC,OAAO,IAAI,MAAM;AACrE,UAAO,SAAS,KACd;IAAE,OAAO;IAA0B;IAAS,EAC5C,EACE,QACD,CACF;;AAQH,UAAQ,MAAM,iDAAiD,MAAM;AACrE,SAAO,SAAS,KACd;GACE,OAAO;GACP;GACD,EACD,EAAE,QAAQ,KAAK,CAChB"}
@@ -0,0 +1,68 @@
1
+ import { isHandlerResponse } from "../shared/json-response.mjs";
2
+ import { getPlatformErrorStatus } from "../shared/intelligence-utils.mjs";
3
+ import { resolveIntelligenceUser } from "../shared/resolve-intelligence-user.mjs";
4
+
5
+ //#region src/runtime/handlers/intelligence/connect.ts
6
+ /**
7
+ * Builds browser-facing realtime connection metadata owned by the runtime.
8
+ */
9
+ function buildRealtimeConnectionInfo(params) {
10
+ return {
11
+ clientUrl: params.clientUrl,
12
+ topic: `thread:${params.threadId}`
13
+ };
14
+ }
15
+ async function handleIntelligenceConnect({ runtime, request, agentId, threadId }) {
16
+ if (!runtime.intelligence) return Response.json({
17
+ error: "Intelligence not configured",
18
+ message: "Intelligence mode requires a CopilotKitIntelligence"
19
+ }, { status: 500 });
20
+ try {
21
+ const user = await resolveIntelligenceUser({
22
+ runtime,
23
+ request
24
+ });
25
+ if (isHandlerResponse(user)) return user;
26
+ const result = await runtime.intelligence.ɵconnectThread({
27
+ threadId,
28
+ userId: user.id,
29
+ agentId
30
+ });
31
+ if (result === null) return new Response(null, { status: 204 });
32
+ return Response.json({
33
+ threadId: result.threadId,
34
+ joinToken: result.joinToken,
35
+ runId: result.runId,
36
+ realtime: buildRealtimeConnectionInfo({
37
+ clientUrl: runtime.intelligence.ɵgetClientWsUrl(),
38
+ threadId: result.threadId
39
+ })
40
+ }, { headers: {
41
+ "Cache-Control": "no-cache",
42
+ Connection: "keep-alive"
43
+ } });
44
+ } catch (error) {
45
+ const status = getPlatformErrorStatus(error);
46
+ const message = error instanceof Error ? error.message : "Connect request failed";
47
+ if (status === 400 || status === 401 || status === 403 || status === 404 || status === 409) return Response.json({
48
+ error: "Connect request rejected",
49
+ message: error instanceof Error ? error.message : "Intelligence platform rejected the connect request"
50
+ }, { status });
51
+ if (typeof status === "number") {
52
+ console.error(`Connect request failed with status ${status}:`, error);
53
+ return Response.json({
54
+ error: "Connect request failed",
55
+ message
56
+ }, { status });
57
+ }
58
+ console.error("Connect request could not reach Intelligence:", error);
59
+ return Response.json({
60
+ error: "Connect request failed",
61
+ message
62
+ }, { status: 502 });
63
+ }
64
+ }
65
+
66
+ //#endregion
67
+ export { handleIntelligenceConnect };
68
+ //# sourceMappingURL=connect.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"connect.mjs","names":[],"sources":["../../../../src/runtime/handlers/intelligence/connect.ts"],"sourcesContent":["import type { CopilotIntelligenceRuntimeLike } from \"../../core/runtime\";\nimport { getPlatformErrorStatus } from \"../shared/intelligence-utils\";\nimport { resolveIntelligenceUser } from \"../shared/resolve-intelligence-user\";\nimport { isHandlerResponse } from \"../shared/json-response\";\n\n/**\n * Builds browser-facing realtime connection metadata owned by the runtime.\n */\nfunction buildRealtimeConnectionInfo(params: {\n clientUrl: string;\n threadId: string;\n}): { clientUrl: string; topic: string } {\n return {\n clientUrl: params.clientUrl,\n topic: `thread:${params.threadId}`,\n };\n}\n\ninterface HandleIntelligenceConnectParams {\n runtime: CopilotIntelligenceRuntimeLike;\n request: Request;\n agentId: string;\n threadId: string;\n}\n\nexport async function handleIntelligenceConnect({\n runtime,\n request,\n agentId,\n threadId,\n}: HandleIntelligenceConnectParams): Promise<Response> {\n if (!runtime.intelligence) {\n return Response.json(\n {\n error: \"Intelligence not configured\",\n message: \"Intelligence mode requires a CopilotKitIntelligence\",\n },\n { status: 500 },\n );\n }\n\n try {\n const user = await resolveIntelligenceUser({ runtime, request });\n if (isHandlerResponse(user)) {\n return user;\n }\n\n const result = await runtime.intelligence.ɵconnectThread({\n threadId,\n userId: user.id,\n agentId,\n });\n\n if (result === null) {\n return new Response(null, {\n status: 204,\n });\n }\n\n return Response.json(\n {\n threadId: result.threadId,\n joinToken: result.joinToken,\n runId: result.runId,\n realtime: buildRealtimeConnectionInfo({\n clientUrl: runtime.intelligence.ɵgetClientWsUrl(),\n threadId: result.threadId,\n }),\n },\n {\n headers: { \"Cache-Control\": \"no-cache\", Connection: \"keep-alive\" },\n },\n );\n } catch (error) {\n const status = getPlatformErrorStatus(error);\n const message =\n error instanceof Error ? error.message : \"Connect request failed\";\n\n if (\n status === 400 ||\n status === 401 ||\n status === 403 ||\n status === 404 ||\n status === 409\n ) {\n return Response.json(\n {\n error: \"Connect request rejected\",\n message:\n error instanceof Error\n ? error.message\n : \"Intelligence platform rejected the connect request\",\n },\n { status },\n );\n }\n\n // The platform answered, but with a status we do not special-case above.\n // Pass it through rather than relabelling it: reporting a 503 as a 404 tells\n // the browser the thread does not exist, when the truth is that the platform\n // is temporarily unwell and the request is worth retrying.\n if (typeof status === \"number\") {\n console.error(`Connect request failed with status ${status}:`, error);\n return Response.json(\n { error: \"Connect request failed\", message },\n {\n status,\n },\n );\n }\n\n // No status at all, so this never reached the platform: a socket timeout, a\n // DNS failure, a connection reset, or a bug on our side. 502 says \"the thing\n // behind me is unreachable\", which is both true and actionable. It must not\n // be a 404, which asserts the thread does not exist and sends the caller off\n // to investigate the wrong thing entirely.\n console.error(\"Connect request could not reach Intelligence:\", error);\n return Response.json(\n {\n error: \"Connect request failed\",\n message,\n },\n { status: 502 },\n );\n }\n}\n"],"mappings":";;;;;;;;AAQA,SAAS,4BAA4B,QAGI;AACvC,QAAO;EACL,WAAW,OAAO;EAClB,OAAO,UAAU,OAAO;EACzB;;AAUH,eAAsB,0BAA0B,EAC9C,SACA,SACA,SACA,YACqD;AACrD,KAAI,CAAC,QAAQ,aACX,QAAO,SAAS,KACd;EACE,OAAO;EACP,SAAS;EACV,EACD,EAAE,QAAQ,KAAK,CAChB;AAGH,KAAI;EACF,MAAM,OAAO,MAAM,wBAAwB;GAAE;GAAS;GAAS,CAAC;AAChE,MAAI,kBAAkB,KAAK,CACzB,QAAO;EAGT,MAAM,SAAS,MAAM,QAAQ,aAAa,eAAe;GACvD;GACA,QAAQ,KAAK;GACb;GACD,CAAC;AAEF,MAAI,WAAW,KACb,QAAO,IAAI,SAAS,MAAM,EACxB,QAAQ,KACT,CAAC;AAGJ,SAAO,SAAS,KACd;GACE,UAAU,OAAO;GACjB,WAAW,OAAO;GAClB,OAAO,OAAO;GACd,UAAU,4BAA4B;IACpC,WAAW,QAAQ,aAAa,iBAAiB;IACjD,UAAU,OAAO;IAClB,CAAC;GACH,EACD,EACE,SAAS;GAAE,iBAAiB;GAAY,YAAY;GAAc,EACnE,CACF;UACM,OAAO;EACd,MAAM,SAAS,uBAAuB,MAAM;EAC5C,MAAM,UACJ,iBAAiB,QAAQ,MAAM,UAAU;AAE3C,MACE,WAAW,OACX,WAAW,OACX,WAAW,OACX,WAAW,OACX,WAAW,IAEX,QAAO,SAAS,KACd;GACE,OAAO;GACP,SACE,iBAAiB,QACb,MAAM,UACN;GACP,EACD,EAAE,QAAQ,CACX;AAOH,MAAI,OAAO,WAAW,UAAU;AAC9B,WAAQ,MAAM,sCAAsC,OAAO,IAAI,MAAM;AACrE,UAAO,SAAS,KACd;IAAE,OAAO;IAA0B;IAAS,EAC5C,EACE,QACD,CACF;;AAQH,UAAQ,MAAM,iDAAiD,MAAM;AACrE,SAAO,SAAS,KACd;GACE,OAAO;GACP;GACD,EACD,EAAE,QAAQ,KAAK,CAChB"}