@copilotkit/runtime 1.54.1-next.6 → 1.55.0-next.7

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 (337) hide show
  1. package/.eslintrc.js +4 -4
  2. package/CHANGELOG.md +117 -106
  3. package/dist/_virtual/_rolldown/runtime.mjs +25 -1
  4. package/dist/agent/index.cjs +643 -0
  5. package/dist/agent/index.cjs.map +1 -0
  6. package/dist/agent/index.d.cts +263 -0
  7. package/dist/agent/index.d.cts.map +1 -0
  8. package/dist/agent/index.d.mts +263 -0
  9. package/dist/agent/index.d.mts.map +1 -0
  10. package/dist/agent/index.mjs +635 -0
  11. package/dist/agent/index.mjs.map +1 -0
  12. package/dist/graphql/message-conversion/agui-to-gql.cjs.map +1 -1
  13. package/dist/graphql/message-conversion/agui-to-gql.mjs.map +1 -1
  14. package/dist/lib/integrations/nextjs/app-router.cjs +2 -2
  15. package/dist/lib/integrations/nextjs/app-router.cjs.map +1 -1
  16. package/dist/lib/integrations/nextjs/app-router.mjs +1 -1
  17. package/dist/lib/integrations/nextjs/app-router.mjs.map +1 -1
  18. package/dist/lib/integrations/node-http/index.cjs +2 -3
  19. package/dist/lib/integrations/node-http/index.cjs.map +1 -1
  20. package/dist/lib/integrations/node-http/index.mjs +1 -1
  21. package/dist/lib/integrations/node-http/index.mjs.map +1 -1
  22. package/dist/lib/runtime/agent-integrations/langgraph/agent.cjs +1 -1
  23. package/dist/lib/runtime/agent-integrations/langgraph/agent.d.cts +2 -2
  24. package/dist/lib/runtime/agent-integrations/langgraph/agent.d.cts.map +1 -1
  25. package/dist/lib/runtime/agent-integrations/langgraph/agent.d.mts +3 -3
  26. package/dist/lib/runtime/agent-integrations/langgraph/agent.d.mts.map +1 -1
  27. package/dist/lib/runtime/agent-integrations/langgraph/agent.mjs +1 -1
  28. package/dist/lib/runtime/copilot-runtime.cjs +7 -5
  29. package/dist/lib/runtime/copilot-runtime.cjs.map +1 -1
  30. package/dist/lib/runtime/copilot-runtime.d.cts +10 -8
  31. package/dist/lib/runtime/copilot-runtime.d.cts.map +1 -1
  32. package/dist/lib/runtime/copilot-runtime.d.mts +10 -8
  33. package/dist/lib/runtime/copilot-runtime.d.mts.map +1 -1
  34. package/dist/lib/runtime/copilot-runtime.mjs +7 -5
  35. package/dist/lib/runtime/copilot-runtime.mjs.map +1 -1
  36. package/dist/lib/runtime/telemetry-agent-runner.cjs +2 -2
  37. package/dist/lib/runtime/telemetry-agent-runner.cjs.map +1 -1
  38. package/dist/lib/runtime/telemetry-agent-runner.d.cts +2 -1
  39. package/dist/lib/runtime/telemetry-agent-runner.d.cts.map +1 -1
  40. package/dist/lib/runtime/telemetry-agent-runner.d.mts +2 -1
  41. package/dist/lib/runtime/telemetry-agent-runner.d.mts.map +1 -1
  42. package/dist/lib/runtime/telemetry-agent-runner.mjs +1 -1
  43. package/dist/lib/runtime/telemetry-agent-runner.mjs.map +1 -1
  44. package/dist/lib/telemetry-client.cjs +1 -1
  45. package/dist/lib/telemetry-client.mjs +1 -1
  46. package/dist/package.cjs +21 -4
  47. package/dist/package.mjs +21 -4
  48. package/dist/service-adapters/anthropic/anthropic-adapter.d.mts +1 -1
  49. package/dist/v2/index.cjs +41 -15
  50. package/dist/v2/index.d.cts +14 -2
  51. package/dist/v2/index.d.mts +14 -2
  52. package/dist/v2/index.mjs +13 -4
  53. package/dist/v2/runtime/endpoints/express-single.cjs +190 -0
  54. package/dist/v2/runtime/endpoints/express-single.cjs.map +1 -0
  55. package/dist/v2/runtime/endpoints/express-single.d.cts +16 -0
  56. package/dist/v2/runtime/endpoints/express-single.d.cts.map +1 -0
  57. package/dist/v2/runtime/endpoints/express-single.d.mts +16 -0
  58. package/dist/v2/runtime/endpoints/express-single.d.mts.map +1 -0
  59. package/dist/v2/runtime/endpoints/express-single.mjs +187 -0
  60. package/dist/v2/runtime/endpoints/express-single.mjs.map +1 -0
  61. package/dist/v2/runtime/endpoints/express-utils.cjs +119 -0
  62. package/dist/v2/runtime/endpoints/express-utils.cjs.map +1 -0
  63. package/dist/v2/runtime/endpoints/express-utils.mjs +117 -0
  64. package/dist/v2/runtime/endpoints/express-utils.mjs.map +1 -0
  65. package/dist/v2/runtime/endpoints/express.cjs +217 -0
  66. package/dist/v2/runtime/endpoints/express.cjs.map +1 -0
  67. package/dist/v2/runtime/endpoints/express.d.cts +16 -0
  68. package/dist/v2/runtime/endpoints/express.d.cts.map +1 -0
  69. package/dist/v2/runtime/endpoints/express.d.mts +16 -0
  70. package/dist/v2/runtime/endpoints/express.d.mts.map +1 -0
  71. package/dist/v2/runtime/endpoints/express.mjs +214 -0
  72. package/dist/v2/runtime/endpoints/express.mjs.map +1 -0
  73. package/dist/v2/runtime/endpoints/hono-single.cjs +141 -0
  74. package/dist/v2/runtime/endpoints/hono-single.cjs.map +1 -0
  75. package/dist/v2/runtime/endpoints/hono-single.d.cts +41 -0
  76. package/dist/v2/runtime/endpoints/hono-single.d.cts.map +1 -0
  77. package/dist/v2/runtime/endpoints/hono-single.d.mts +41 -0
  78. package/dist/v2/runtime/endpoints/hono-single.d.mts.map +1 -0
  79. package/dist/v2/runtime/endpoints/hono-single.mjs +140 -0
  80. package/dist/v2/runtime/endpoints/hono-single.mjs.map +1 -0
  81. package/dist/v2/runtime/endpoints/hono.cjs +248 -0
  82. package/dist/v2/runtime/endpoints/hono.cjs.map +1 -0
  83. package/dist/v2/runtime/endpoints/hono.d.cts +164 -0
  84. package/dist/v2/runtime/endpoints/hono.d.cts.map +1 -0
  85. package/dist/v2/runtime/endpoints/hono.d.mts +164 -0
  86. package/dist/v2/runtime/endpoints/hono.d.mts.map +1 -0
  87. package/dist/v2/runtime/endpoints/hono.mjs +247 -0
  88. package/dist/v2/runtime/endpoints/hono.mjs.map +1 -0
  89. package/dist/v2/runtime/endpoints/index.d.cts +5 -0
  90. package/dist/v2/runtime/endpoints/index.d.mts +5 -0
  91. package/dist/v2/runtime/endpoints/single-route-helpers.cjs +68 -0
  92. package/dist/v2/runtime/endpoints/single-route-helpers.cjs.map +1 -0
  93. package/dist/v2/runtime/endpoints/single-route-helpers.mjs +65 -0
  94. package/dist/v2/runtime/endpoints/single-route-helpers.mjs.map +1 -0
  95. package/dist/v2/runtime/handlers/get-runtime-info.cjs +51 -0
  96. package/dist/v2/runtime/handlers/get-runtime-info.cjs.map +1 -0
  97. package/dist/v2/runtime/handlers/get-runtime-info.mjs +51 -0
  98. package/dist/v2/runtime/handlers/get-runtime-info.mjs.map +1 -0
  99. package/dist/v2/runtime/handlers/handle-connect.cjs +49 -0
  100. package/dist/v2/runtime/handlers/handle-connect.cjs.map +1 -0
  101. package/dist/v2/runtime/handlers/handle-connect.mjs +49 -0
  102. package/dist/v2/runtime/handlers/handle-connect.mjs.map +1 -0
  103. package/dist/v2/runtime/handlers/handle-run.cjs +61 -0
  104. package/dist/v2/runtime/handlers/handle-run.cjs.map +1 -0
  105. package/dist/v2/runtime/handlers/handle-run.mjs +61 -0
  106. package/dist/v2/runtime/handlers/handle-run.mjs.map +1 -0
  107. package/dist/v2/runtime/handlers/handle-stop.cjs +47 -0
  108. package/dist/v2/runtime/handlers/handle-stop.cjs.map +1 -0
  109. package/dist/v2/runtime/handlers/handle-stop.mjs +46 -0
  110. package/dist/v2/runtime/handlers/handle-stop.mjs.map +1 -0
  111. package/dist/v2/runtime/handlers/handle-transcribe.cjs +112 -0
  112. package/dist/v2/runtime/handlers/handle-transcribe.cjs.map +1 -0
  113. package/dist/v2/runtime/handlers/handle-transcribe.mjs +111 -0
  114. package/dist/v2/runtime/handlers/handle-transcribe.mjs.map +1 -0
  115. package/dist/v2/runtime/handlers/header-utils.cjs +26 -0
  116. package/dist/v2/runtime/handlers/header-utils.cjs.map +1 -0
  117. package/dist/v2/runtime/handlers/header-utils.mjs +25 -0
  118. package/dist/v2/runtime/handlers/header-utils.mjs.map +1 -0
  119. package/dist/v2/runtime/handlers/intelligence/connect.cjs +37 -0
  120. package/dist/v2/runtime/handlers/intelligence/connect.cjs.map +1 -0
  121. package/dist/v2/runtime/handlers/intelligence/connect.mjs +37 -0
  122. package/dist/v2/runtime/handlers/intelligence/connect.mjs.map +1 -0
  123. package/dist/v2/runtime/handlers/intelligence/run.cjs +89 -0
  124. package/dist/v2/runtime/handlers/intelligence/run.cjs.map +1 -0
  125. package/dist/v2/runtime/handlers/intelligence/run.mjs +88 -0
  126. package/dist/v2/runtime/handlers/intelligence/run.mjs.map +1 -0
  127. package/dist/v2/runtime/handlers/intelligence/thread-names.cjs +146 -0
  128. package/dist/v2/runtime/handlers/intelligence/thread-names.cjs.map +1 -0
  129. package/dist/v2/runtime/handlers/intelligence/thread-names.mjs +145 -0
  130. package/dist/v2/runtime/handlers/intelligence/thread-names.mjs.map +1 -0
  131. package/dist/v2/runtime/handlers/intelligence/threads.cjs +159 -0
  132. package/dist/v2/runtime/handlers/intelligence/threads.cjs.map +1 -0
  133. package/dist/v2/runtime/handlers/intelligence/threads.mjs +154 -0
  134. package/dist/v2/runtime/handlers/intelligence/threads.mjs.map +1 -0
  135. package/dist/v2/runtime/handlers/shared/agent-utils.cjs +74 -0
  136. package/dist/v2/runtime/handlers/shared/agent-utils.cjs.map +1 -0
  137. package/dist/v2/runtime/handlers/shared/agent-utils.mjs +70 -0
  138. package/dist/v2/runtime/handlers/shared/agent-utils.mjs.map +1 -0
  139. package/dist/v2/runtime/handlers/shared/intelligence-utils.cjs +21 -0
  140. package/dist/v2/runtime/handlers/shared/intelligence-utils.cjs.map +1 -0
  141. package/dist/v2/runtime/handlers/shared/intelligence-utils.mjs +20 -0
  142. package/dist/v2/runtime/handlers/shared/intelligence-utils.mjs.map +1 -0
  143. package/dist/v2/runtime/handlers/shared/json-response.cjs +12 -0
  144. package/dist/v2/runtime/handlers/shared/json-response.cjs.map +1 -0
  145. package/dist/v2/runtime/handlers/shared/json-response.mjs +10 -0
  146. package/dist/v2/runtime/handlers/shared/json-response.mjs.map +1 -0
  147. package/dist/v2/runtime/handlers/shared/resolve-intelligence-user.cjs +20 -0
  148. package/dist/v2/runtime/handlers/shared/resolve-intelligence-user.cjs.map +1 -0
  149. package/dist/v2/runtime/handlers/shared/resolve-intelligence-user.mjs +20 -0
  150. package/dist/v2/runtime/handlers/shared/resolve-intelligence-user.mjs.map +1 -0
  151. package/dist/v2/runtime/handlers/shared/sse-response.cjs +69 -0
  152. package/dist/v2/runtime/handlers/shared/sse-response.cjs.map +1 -0
  153. package/dist/v2/runtime/handlers/shared/sse-response.mjs +68 -0
  154. package/dist/v2/runtime/handlers/shared/sse-response.mjs.map +1 -0
  155. package/dist/v2/runtime/handlers/sse/connect.cjs +18 -0
  156. package/dist/v2/runtime/handlers/sse/connect.cjs.map +1 -0
  157. package/dist/v2/runtime/handlers/sse/connect.mjs +18 -0
  158. package/dist/v2/runtime/handlers/sse/connect.mjs.map +1 -0
  159. package/dist/v2/runtime/handlers/sse/run.cjs +18 -0
  160. package/dist/v2/runtime/handlers/sse/run.cjs.map +1 -0
  161. package/dist/v2/runtime/handlers/sse/run.mjs +18 -0
  162. package/dist/v2/runtime/handlers/sse/run.mjs.map +1 -0
  163. package/dist/v2/runtime/index.d.cts +13 -0
  164. package/dist/v2/runtime/index.d.mts +14 -0
  165. package/dist/v2/runtime/intelligence-platform/client.cjs +333 -0
  166. package/dist/v2/runtime/intelligence-platform/client.cjs.map +1 -0
  167. package/dist/v2/runtime/intelligence-platform/client.d.cts +336 -0
  168. package/dist/v2/runtime/intelligence-platform/client.d.cts.map +1 -0
  169. package/dist/v2/runtime/intelligence-platform/client.d.mts +336 -0
  170. package/dist/v2/runtime/intelligence-platform/client.d.mts.map +1 -0
  171. package/dist/v2/runtime/intelligence-platform/client.mjs +331 -0
  172. package/dist/v2/runtime/intelligence-platform/client.mjs.map +1 -0
  173. package/dist/v2/runtime/intelligence-platform/index.d.mts +2 -0
  174. package/dist/v2/runtime/middleware-sse-parser.cjs +138 -0
  175. package/dist/v2/runtime/middleware-sse-parser.cjs.map +1 -0
  176. package/dist/v2/runtime/middleware-sse-parser.d.cts +22 -0
  177. package/dist/v2/runtime/middleware-sse-parser.d.cts.map +1 -0
  178. package/dist/v2/runtime/middleware-sse-parser.d.mts +22 -0
  179. package/dist/v2/runtime/middleware-sse-parser.d.mts.map +1 -0
  180. package/dist/v2/runtime/middleware-sse-parser.mjs +137 -0
  181. package/dist/v2/runtime/middleware-sse-parser.mjs.map +1 -0
  182. package/dist/v2/runtime/middleware.cjs +35 -0
  183. package/dist/v2/runtime/middleware.cjs.map +1 -0
  184. package/dist/v2/runtime/middleware.d.cts +32 -0
  185. package/dist/v2/runtime/middleware.d.cts.map +1 -0
  186. package/dist/v2/runtime/middleware.d.mts +32 -0
  187. package/dist/v2/runtime/middleware.d.mts.map +1 -0
  188. package/dist/v2/runtime/middleware.mjs +33 -0
  189. package/dist/v2/runtime/middleware.mjs.map +1 -0
  190. package/dist/v2/runtime/runner/agent-runner.cjs +8 -0
  191. package/dist/v2/runtime/runner/agent-runner.cjs.map +1 -0
  192. package/dist/v2/runtime/runner/agent-runner.d.cts +32 -0
  193. package/dist/v2/runtime/runner/agent-runner.d.cts.map +1 -0
  194. package/dist/v2/runtime/runner/agent-runner.d.mts +32 -0
  195. package/dist/v2/runtime/runner/agent-runner.d.mts.map +1 -0
  196. package/dist/v2/runtime/runner/agent-runner.mjs +7 -0
  197. package/dist/v2/runtime/runner/agent-runner.mjs.map +1 -0
  198. package/dist/v2/runtime/runner/in-memory.cjs +223 -0
  199. package/dist/v2/runtime/runner/in-memory.cjs.map +1 -0
  200. package/dist/v2/runtime/runner/in-memory.d.cts +15 -0
  201. package/dist/v2/runtime/runner/in-memory.d.cts.map +1 -0
  202. package/dist/v2/runtime/runner/in-memory.d.mts +15 -0
  203. package/dist/v2/runtime/runner/in-memory.d.mts.map +1 -0
  204. package/dist/v2/runtime/runner/in-memory.mjs +222 -0
  205. package/dist/v2/runtime/runner/in-memory.mjs.map +1 -0
  206. package/dist/v2/runtime/runner/index.d.cts +6 -0
  207. package/dist/v2/runtime/runner/index.d.mts +6 -0
  208. package/dist/v2/runtime/runner/index.mjs +7 -0
  209. package/dist/v2/runtime/runner/intelligence.cjs +246 -0
  210. package/dist/v2/runtime/runner/intelligence.cjs.map +1 -0
  211. package/dist/v2/runtime/runner/intelligence.d.cts +57 -0
  212. package/dist/v2/runtime/runner/intelligence.d.cts.map +1 -0
  213. package/dist/v2/runtime/runner/intelligence.d.mts +57 -0
  214. package/dist/v2/runtime/runner/intelligence.d.mts.map +1 -0
  215. package/dist/v2/runtime/runner/intelligence.mjs +245 -0
  216. package/dist/v2/runtime/runner/intelligence.mjs.map +1 -0
  217. package/dist/v2/runtime/runtime.cjs +101 -0
  218. package/dist/v2/runtime/runtime.cjs.map +1 -0
  219. package/dist/v2/runtime/runtime.d.cts +132 -0
  220. package/dist/v2/runtime/runtime.d.cts.map +1 -0
  221. package/dist/v2/runtime/runtime.d.mts +133 -0
  222. package/dist/v2/runtime/runtime.d.mts.map +1 -0
  223. package/dist/v2/runtime/runtime.mjs +97 -0
  224. package/dist/v2/runtime/runtime.mjs.map +1 -0
  225. package/dist/v2/runtime/telemetry/scarf-client.cjs +32 -0
  226. package/dist/v2/runtime/telemetry/scarf-client.cjs.map +1 -0
  227. package/dist/v2/runtime/telemetry/scarf-client.mjs +32 -0
  228. package/dist/v2/runtime/telemetry/scarf-client.mjs.map +1 -0
  229. package/dist/v2/runtime/telemetry/telemetry-client.cjs +35 -0
  230. package/dist/v2/runtime/telemetry/telemetry-client.cjs.map +1 -0
  231. package/dist/v2/runtime/telemetry/telemetry-client.mjs +35 -0
  232. package/dist/v2/runtime/telemetry/telemetry-client.mjs.map +1 -0
  233. package/dist/v2/runtime/transcription-service/transcription-service.cjs +8 -0
  234. package/dist/v2/runtime/transcription-service/transcription-service.cjs.map +1 -0
  235. package/dist/v2/runtime/transcription-service/transcription-service.d.cts +15 -0
  236. package/dist/v2/runtime/transcription-service/transcription-service.d.cts.map +1 -0
  237. package/dist/v2/runtime/transcription-service/transcription-service.d.mts +15 -0
  238. package/dist/v2/runtime/transcription-service/transcription-service.d.mts.map +1 -0
  239. package/dist/v2/runtime/transcription-service/transcription-service.mjs +7 -0
  240. package/dist/v2/runtime/transcription-service/transcription-service.mjs.map +1 -0
  241. package/package.json +22 -5
  242. package/src/agent/__tests__/ai-sdk-v6-compat.test.ts +116 -0
  243. package/src/agent/__tests__/basic-agent.test.ts +1248 -0
  244. package/src/agent/__tests__/config-tools-execution.test.ts +516 -0
  245. package/src/agent/__tests__/mcp-clients.test.ts +260 -0
  246. package/src/agent/__tests__/property-overrides.test.ts +598 -0
  247. package/src/agent/__tests__/standard-schema-tools.test.ts +313 -0
  248. package/src/agent/__tests__/standard-schema-types.test.ts +158 -0
  249. package/src/agent/__tests__/state-tools.test.ts +436 -0
  250. package/src/agent/__tests__/test-helpers.ts +178 -0
  251. package/src/agent/__tests__/utils.test.ts +536 -0
  252. package/src/agent/__tests__/zod-regression.test.ts +350 -0
  253. package/src/agent/index.ts +1305 -0
  254. package/src/graphql/message-conversion/agui-to-gql.test.ts +1 -1
  255. package/src/graphql/message-conversion/agui-to-gql.ts +1 -1
  256. package/src/graphql/message-conversion/gql-to-agui.ts +1 -1
  257. package/src/graphql/message-conversion/roundtrip-conversion.test.ts +1 -1
  258. package/src/lib/integrations/nextjs/app-router.ts +2 -2
  259. package/src/lib/integrations/node-http/index.ts +2 -2
  260. package/src/lib/runtime/copilot-runtime.ts +3 -5
  261. package/src/lib/runtime/telemetry-agent-runner.ts +1 -1
  262. package/src/service-adapters/conversion.test.ts +1 -1
  263. package/src/service-adapters/conversion.ts +1 -28
  264. package/src/v2/index.ts +5 -2
  265. package/src/v2/runtime/__tests__/cors-credentials.test.ts +320 -0
  266. package/src/v2/runtime/__tests__/express-abort-signal.test.ts +25 -0
  267. package/src/v2/runtime/__tests__/express-body-order.test.ts +76 -0
  268. package/src/v2/runtime/__tests__/express-single-sse.test.ts +122 -0
  269. package/src/v2/runtime/__tests__/get-runtime-info.test.ts +141 -0
  270. package/src/v2/runtime/__tests__/handle-connect.test.ts +423 -0
  271. package/src/v2/runtime/__tests__/handle-run.test.ts +910 -0
  272. package/src/v2/runtime/__tests__/handle-threads.test.ts +388 -0
  273. package/src/v2/runtime/__tests__/handle-transcribe.test.ts +301 -0
  274. package/src/v2/runtime/__tests__/header-utils.test.ts +88 -0
  275. package/src/v2/runtime/__tests__/in-process-agent-runner-messages.test.ts +230 -0
  276. package/src/v2/runtime/__tests__/in-process-agent-runner.test.ts +1030 -0
  277. package/src/v2/runtime/__tests__/middleware-express.test.ts +206 -0
  278. package/src/v2/runtime/__tests__/middleware-single-express.test.ts +211 -0
  279. package/src/v2/runtime/__tests__/middleware-single.test.ts +225 -0
  280. package/src/v2/runtime/__tests__/middleware-sse-parser.test.ts +187 -0
  281. package/src/v2/runtime/__tests__/middleware.test.ts +251 -0
  282. package/src/v2/runtime/__tests__/routing-express.test.ts +174 -0
  283. package/src/v2/runtime/__tests__/routing-single-express.test.ts +168 -0
  284. package/src/v2/runtime/__tests__/routing-single.test.ts +193 -0
  285. package/src/v2/runtime/__tests__/routing.test.ts +257 -0
  286. package/src/v2/runtime/__tests__/runtime.test.ts +123 -0
  287. package/src/v2/runtime/__tests__/telemetry.test.ts +167 -0
  288. package/src/v2/runtime/__tests__/thread-names.test.ts +188 -0
  289. package/src/v2/runtime/endpoints/express-single.ts +231 -0
  290. package/src/v2/runtime/endpoints/express-utils.ts +182 -0
  291. package/src/v2/runtime/endpoints/express.ts +275 -0
  292. package/src/v2/runtime/endpoints/hono-single.ts +212 -0
  293. package/src/v2/runtime/endpoints/hono.ts +314 -0
  294. package/src/v2/runtime/endpoints/index.ts +4 -0
  295. package/src/v2/runtime/endpoints/single-route-helpers.ts +125 -0
  296. package/src/v2/runtime/express.ts +2 -0
  297. package/src/v2/runtime/handler.ts +3 -0
  298. package/src/v2/runtime/handlers/get-runtime-info.ts +79 -0
  299. package/src/v2/runtime/handlers/handle-connect.ts +76 -0
  300. package/src/v2/runtime/handlers/handle-run.ts +89 -0
  301. package/src/v2/runtime/handlers/handle-stop.ts +76 -0
  302. package/src/v2/runtime/handlers/handle-threads.ts +7 -0
  303. package/src/v2/runtime/handlers/handle-transcribe.ts +256 -0
  304. package/src/v2/runtime/handlers/header-utils.ts +24 -0
  305. package/src/v2/runtime/handlers/intelligence/connect.ts +65 -0
  306. package/src/v2/runtime/handlers/intelligence/run.ts +152 -0
  307. package/src/v2/runtime/handlers/intelligence/thread-names.ts +246 -0
  308. package/src/v2/runtime/handlers/intelligence/threads.ts +233 -0
  309. package/src/v2/runtime/handlers/shared/agent-utils.ts +136 -0
  310. package/src/v2/runtime/handlers/shared/intelligence-utils.ts +21 -0
  311. package/src/v2/runtime/handlers/shared/json-response.ts +6 -0
  312. package/src/v2/runtime/handlers/shared/resolve-intelligence-user.ts +25 -0
  313. package/src/v2/runtime/handlers/shared/sse-response.ts +100 -0
  314. package/src/v2/runtime/handlers/sse/connect.ts +24 -0
  315. package/src/v2/runtime/handlers/sse/run.ts +27 -0
  316. package/src/v2/runtime/index.ts +20 -0
  317. package/src/v2/runtime/intelligence-platform/__tests__/client.test.ts +605 -0
  318. package/src/v2/runtime/intelligence-platform/client.ts +659 -0
  319. package/src/v2/runtime/intelligence-platform/index.ts +10 -0
  320. package/src/v2/runtime/middleware-sse-parser.ts +200 -0
  321. package/src/v2/runtime/middleware.ts +115 -0
  322. package/src/v2/runtime/runner/__tests__/finalize-events.test.ts +109 -0
  323. package/src/v2/runtime/runner/__tests__/in-memory-runner.e2e.test.ts +775 -0
  324. package/src/v2/runtime/runner/__tests__/in-memory-runner.test.ts +363 -0
  325. package/src/v2/runtime/runner/__tests__/intelligence-runner.test.ts +981 -0
  326. package/src/v2/runtime/runner/agent-runner.ts +36 -0
  327. package/src/v2/runtime/runner/in-memory.ts +381 -0
  328. package/src/v2/runtime/runner/index.ts +4 -0
  329. package/src/v2/runtime/runner/intelligence.ts +429 -0
  330. package/src/v2/runtime/runtime.ts +260 -0
  331. package/src/v2/runtime/telemetry/events.ts +35 -0
  332. package/src/v2/runtime/telemetry/index.ts +7 -0
  333. package/src/v2/runtime/telemetry/scarf-client.ts +39 -0
  334. package/src/v2/runtime/telemetry/telemetry-client.ts +70 -0
  335. package/src/v2/runtime/transcription-service/transcription-service.ts +11 -0
  336. package/tsconfig.json +9 -2
  337. package/tsdown.config.ts +1 -0
@@ -0,0 +1,164 @@
1
+
2
+ import { CopilotRuntimeLike } from "../runtime.cjs";
3
+ import * as hono_utils_http_status0 from "hono/utils/http-status";
4
+ import * as hono_hono_base0 from "hono/hono-base";
5
+
6
+ //#region src/v2/runtime/endpoints/hono.d.ts
7
+ /**
8
+ * CORS configuration for CopilotKit endpoints.
9
+ * When using credentials (e.g., HTTP-only cookies), you must specify an explicit origin.
10
+ */
11
+ interface CopilotEndpointCorsConfig {
12
+ /**
13
+ * Allowed origin(s) for CORS. Can be:
14
+ * - A string: exact origin (e.g., "https://myapp.com")
15
+ * - An array: list of allowed origins
16
+ * - A function: dynamic origin resolution
17
+ *
18
+ * Note: When credentials is true, origin cannot be "*"
19
+ */
20
+ origin: string | string[] | ((origin: string, c: any) => string | undefined | null);
21
+ /**
22
+ * Whether to allow credentials (cookies, HTTP authentication).
23
+ * When true, origin must be explicitly specified (not "*").
24
+ */
25
+ credentials?: boolean;
26
+ }
27
+ interface CopilotEndpointParams {
28
+ runtime: CopilotRuntimeLike;
29
+ basePath: string;
30
+ /**
31
+ * Optional CORS configuration. When not provided, defaults to allowing all origins without credentials.
32
+ * To support HTTP-only cookies, provide cors config with credentials: true and explicit origin.
33
+ */
34
+ cors?: CopilotEndpointCorsConfig;
35
+ }
36
+ type CopilotEndpointContext = {
37
+ Variables: {
38
+ modifiedRequest?: Request;
39
+ };
40
+ };
41
+ declare function createCopilotEndpoint({
42
+ runtime,
43
+ basePath,
44
+ cors: corsConfig
45
+ }: CopilotEndpointParams): hono_hono_base0.HonoBase<CopilotEndpointContext, {
46
+ [x: `${string}/agent/:agentId/run`]: {
47
+ $post: {
48
+ input: {
49
+ param: {
50
+ agentId: string;
51
+ };
52
+ };
53
+ output: {};
54
+ outputFormat: string;
55
+ status: hono_utils_http_status0.StatusCode;
56
+ };
57
+ };
58
+ } & {
59
+ [x: `${string}/agent/:agentId/connect`]: {
60
+ $post: {
61
+ input: {
62
+ param: {
63
+ agentId: string;
64
+ };
65
+ };
66
+ output: {};
67
+ outputFormat: string;
68
+ status: hono_utils_http_status0.StatusCode;
69
+ };
70
+ };
71
+ } & {
72
+ [x: `${string}/agent/:agentId/stop/:threadId`]: {
73
+ $post: {
74
+ input: {
75
+ param: {
76
+ agentId: string;
77
+ } & {
78
+ threadId: string;
79
+ };
80
+ };
81
+ output: {};
82
+ outputFormat: string;
83
+ status: hono_utils_http_status0.StatusCode;
84
+ };
85
+ };
86
+ } & {
87
+ [x: `${string}/info`]: {
88
+ $get: {
89
+ input: {};
90
+ output: {};
91
+ outputFormat: string;
92
+ status: hono_utils_http_status0.StatusCode;
93
+ };
94
+ };
95
+ } & {
96
+ [x: `${string}/transcribe`]: {
97
+ $post: {
98
+ input: {};
99
+ output: {};
100
+ outputFormat: string;
101
+ status: hono_utils_http_status0.StatusCode;
102
+ };
103
+ };
104
+ } & {
105
+ [x: `${string}/threads`]: {
106
+ $get: {
107
+ input: {};
108
+ output: {};
109
+ outputFormat: string;
110
+ status: hono_utils_http_status0.StatusCode;
111
+ };
112
+ };
113
+ } & {
114
+ [x: `${string}/threads/subscribe`]: {
115
+ $post: {
116
+ input: {};
117
+ output: {};
118
+ outputFormat: string;
119
+ status: hono_utils_http_status0.StatusCode;
120
+ };
121
+ };
122
+ } & {
123
+ [x: `${string}/threads/:threadId`]: {
124
+ $patch: {
125
+ input: {
126
+ param: {
127
+ threadId: string;
128
+ };
129
+ };
130
+ output: {};
131
+ outputFormat: string;
132
+ status: hono_utils_http_status0.StatusCode;
133
+ };
134
+ };
135
+ } & {
136
+ [x: `${string}/threads/:threadId/archive`]: {
137
+ $post: {
138
+ input: {
139
+ param: {
140
+ threadId: string;
141
+ };
142
+ };
143
+ output: {};
144
+ outputFormat: string;
145
+ status: hono_utils_http_status0.StatusCode;
146
+ };
147
+ };
148
+ } & {
149
+ [x: `${string}/threads/:threadId`]: {
150
+ $delete: {
151
+ input: {
152
+ param: {
153
+ threadId: string;
154
+ };
155
+ };
156
+ output: {};
157
+ outputFormat: string;
158
+ status: hono_utils_http_status0.StatusCode;
159
+ };
160
+ };
161
+ }, string, `${string}/threads/:threadId`>;
162
+ //#endregion
163
+ export { CopilotEndpointCorsConfig, createCopilotEndpoint };
164
+ //# sourceMappingURL=hono.d.cts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"hono.d.cts","names":[],"sources":["../../../../src/v2/runtime/endpoints/hono.ts"],"mappings":";;;;;;;;;;UA0BiB,yBAAA;EAAyB;;;;;;;;EASxC,MAAA,wBAGM,MAAA,UAAgB,CAAA;EAQd;;;;EAHR,WAAA;AAAA;AAAA,UAGQ,qBAAA;EACR,OAAA,EAAS,kBAAA;EACT,QAAA;EAKgC;;AAAA;;EAAhC,IAAA,GAAO,yBAAA;AAAA;AAAA,KAIJ,sBAAA;EACH,SAAA;IACE,eAAA,GAAkB,OAAA;EAAA;AAAA;AAAA,iBAIN,qBAAA,CAAA;EACd,OAAA;EACA,QAAA;EACA,IAAA,EAAM;AAAA,GACL,qBAAA,mBAAqB,QAAA,CAAA,sBAAA;EAAA;;;;;;;;;cAAA,uBAAA,CAAA,UAAA;IAAA;EAAA;AAAA;EAAA"}
@@ -0,0 +1,164 @@
1
+ import "reflect-metadata";
2
+ import { CopilotRuntimeLike } from "../runtime.mjs";
3
+ import * as hono_utils_http_status0 from "hono/utils/http-status";
4
+ import * as hono_hono_base0 from "hono/hono-base";
5
+
6
+ //#region src/v2/runtime/endpoints/hono.d.ts
7
+ /**
8
+ * CORS configuration for CopilotKit endpoints.
9
+ * When using credentials (e.g., HTTP-only cookies), you must specify an explicit origin.
10
+ */
11
+ interface CopilotEndpointCorsConfig {
12
+ /**
13
+ * Allowed origin(s) for CORS. Can be:
14
+ * - A string: exact origin (e.g., "https://myapp.com")
15
+ * - An array: list of allowed origins
16
+ * - A function: dynamic origin resolution
17
+ *
18
+ * Note: When credentials is true, origin cannot be "*"
19
+ */
20
+ origin: string | string[] | ((origin: string, c: any) => string | undefined | null);
21
+ /**
22
+ * Whether to allow credentials (cookies, HTTP authentication).
23
+ * When true, origin must be explicitly specified (not "*").
24
+ */
25
+ credentials?: boolean;
26
+ }
27
+ interface CopilotEndpointParams {
28
+ runtime: CopilotRuntimeLike;
29
+ basePath: string;
30
+ /**
31
+ * Optional CORS configuration. When not provided, defaults to allowing all origins without credentials.
32
+ * To support HTTP-only cookies, provide cors config with credentials: true and explicit origin.
33
+ */
34
+ cors?: CopilotEndpointCorsConfig;
35
+ }
36
+ type CopilotEndpointContext = {
37
+ Variables: {
38
+ modifiedRequest?: Request;
39
+ };
40
+ };
41
+ declare function createCopilotEndpoint({
42
+ runtime,
43
+ basePath,
44
+ cors: corsConfig
45
+ }: CopilotEndpointParams): hono_hono_base0.HonoBase<CopilotEndpointContext, {
46
+ [x: `${string}/agent/:agentId/run`]: {
47
+ $post: {
48
+ input: {
49
+ param: {
50
+ agentId: string;
51
+ };
52
+ };
53
+ output: {};
54
+ outputFormat: string;
55
+ status: hono_utils_http_status0.StatusCode;
56
+ };
57
+ };
58
+ } & {
59
+ [x: `${string}/agent/:agentId/connect`]: {
60
+ $post: {
61
+ input: {
62
+ param: {
63
+ agentId: string;
64
+ };
65
+ };
66
+ output: {};
67
+ outputFormat: string;
68
+ status: hono_utils_http_status0.StatusCode;
69
+ };
70
+ };
71
+ } & {
72
+ [x: `${string}/agent/:agentId/stop/:threadId`]: {
73
+ $post: {
74
+ input: {
75
+ param: {
76
+ agentId: string;
77
+ } & {
78
+ threadId: string;
79
+ };
80
+ };
81
+ output: {};
82
+ outputFormat: string;
83
+ status: hono_utils_http_status0.StatusCode;
84
+ };
85
+ };
86
+ } & {
87
+ [x: `${string}/info`]: {
88
+ $get: {
89
+ input: {};
90
+ output: {};
91
+ outputFormat: string;
92
+ status: hono_utils_http_status0.StatusCode;
93
+ };
94
+ };
95
+ } & {
96
+ [x: `${string}/transcribe`]: {
97
+ $post: {
98
+ input: {};
99
+ output: {};
100
+ outputFormat: string;
101
+ status: hono_utils_http_status0.StatusCode;
102
+ };
103
+ };
104
+ } & {
105
+ [x: `${string}/threads`]: {
106
+ $get: {
107
+ input: {};
108
+ output: {};
109
+ outputFormat: string;
110
+ status: hono_utils_http_status0.StatusCode;
111
+ };
112
+ };
113
+ } & {
114
+ [x: `${string}/threads/subscribe`]: {
115
+ $post: {
116
+ input: {};
117
+ output: {};
118
+ outputFormat: string;
119
+ status: hono_utils_http_status0.StatusCode;
120
+ };
121
+ };
122
+ } & {
123
+ [x: `${string}/threads/:threadId`]: {
124
+ $patch: {
125
+ input: {
126
+ param: {
127
+ threadId: string;
128
+ };
129
+ };
130
+ output: {};
131
+ outputFormat: string;
132
+ status: hono_utils_http_status0.StatusCode;
133
+ };
134
+ };
135
+ } & {
136
+ [x: `${string}/threads/:threadId/archive`]: {
137
+ $post: {
138
+ input: {
139
+ param: {
140
+ threadId: string;
141
+ };
142
+ };
143
+ output: {};
144
+ outputFormat: string;
145
+ status: hono_utils_http_status0.StatusCode;
146
+ };
147
+ };
148
+ } & {
149
+ [x: `${string}/threads/:threadId`]: {
150
+ $delete: {
151
+ input: {
152
+ param: {
153
+ threadId: string;
154
+ };
155
+ };
156
+ output: {};
157
+ outputFormat: string;
158
+ status: hono_utils_http_status0.StatusCode;
159
+ };
160
+ };
161
+ }, string, `${string}/threads/:threadId`>;
162
+ //#endregion
163
+ export { CopilotEndpointCorsConfig, createCopilotEndpoint };
164
+ //# sourceMappingURL=hono.d.mts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"hono.d.mts","names":[],"sources":["../../../../src/v2/runtime/endpoints/hono.ts"],"mappings":";;;;;;;;;;UA0BiB,yBAAA;EAAyB;;;;;;;;EASxC,MAAA,wBAGM,MAAA,UAAgB,CAAA;EAQd;;;;EAHR,WAAA;AAAA;AAAA,UAGQ,qBAAA;EACR,OAAA,EAAS,kBAAA;EACT,QAAA;EAKgC;;AAAA;;EAAhC,IAAA,GAAO,yBAAA;AAAA;AAAA,KAIJ,sBAAA;EACH,SAAA;IACE,eAAA,GAAkB,OAAA;EAAA;AAAA;AAAA,iBAIN,qBAAA,CAAA;EACd,OAAA;EACA,QAAA;EACA,IAAA,EAAM;AAAA,GACL,qBAAA,mBAAqB,QAAA,CAAA,sBAAA;EAAA;;;;;;;;;cAAA,uBAAA,CAAA,UAAA;IAAA;EAAA;AAAA;EAAA"}
@@ -0,0 +1,247 @@
1
+ import "reflect-metadata";
2
+ import telemetry from "../telemetry/telemetry-client.mjs";
3
+ import { handleRunAgent } from "../handlers/handle-run.mjs";
4
+ import { handleGetRuntimeInfo } from "../handlers/get-runtime-info.mjs";
5
+ import { handleTranscribe } from "../handlers/handle-transcribe.mjs";
6
+ import { callAfterRequestMiddleware, callBeforeRequestMiddleware } from "../middleware.mjs";
7
+ import { handleConnectAgent } from "../handlers/handle-connect.mjs";
8
+ import { handleStopAgent } from "../handlers/handle-stop.mjs";
9
+ import { handleArchiveThread, handleDeleteThread, handleListThreads, handleSubscribeToThreads, handleUpdateThread } from "../handlers/intelligence/threads.mjs";
10
+ import { getLicenseWarningHeader, logger } from "@copilotkit/shared";
11
+ import { Hono } from "hono";
12
+ import { cors } from "hono/cors";
13
+
14
+ //#region src/v2/runtime/endpoints/hono.ts
15
+ function createCopilotEndpoint({ runtime, basePath, cors: corsConfig }) {
16
+ const app = new Hono();
17
+ Promise.resolve(runtime.agents).then((agents) => {
18
+ telemetry.capture("oss.runtime.instance_created", {
19
+ actionsAmount: 0,
20
+ endpointTypes: [],
21
+ endpointsAmount: 0,
22
+ agentsAmount: Object.keys(agents).length,
23
+ "cloud.api_key_provided": false
24
+ });
25
+ }).catch(() => {});
26
+ return app.basePath(basePath).use("*", cors({
27
+ origin: corsConfig?.origin ?? "*",
28
+ allowMethods: [
29
+ "GET",
30
+ "HEAD",
31
+ "PUT",
32
+ "POST",
33
+ "DELETE",
34
+ "PATCH",
35
+ "OPTIONS"
36
+ ],
37
+ allowHeaders: ["*"],
38
+ credentials: corsConfig?.credentials ?? false
39
+ })).use("*", async (c, next) => {
40
+ const request = c.req.raw;
41
+ const path = c.req.path;
42
+ try {
43
+ const maybeModifiedRequest = await callBeforeRequestMiddleware({
44
+ runtime,
45
+ request,
46
+ path
47
+ });
48
+ if (maybeModifiedRequest) c.set("modifiedRequest", maybeModifiedRequest);
49
+ } catch (error) {
50
+ logger.error({
51
+ err: error,
52
+ url: request.url,
53
+ path
54
+ }, "Error running before request middleware");
55
+ if (error instanceof Response) return error;
56
+ throw error;
57
+ }
58
+ const warning = getLicenseWarningHeader(runtime.licenseChecker);
59
+ if (warning) c.header(warning.key, warning.value);
60
+ await next();
61
+ }).use("*", async (c, next) => {
62
+ await next();
63
+ const response = c.res.clone();
64
+ const path = c.req.path;
65
+ callAfterRequestMiddleware({
66
+ runtime,
67
+ response,
68
+ path
69
+ }).catch((error) => {
70
+ logger.error({
71
+ err: error,
72
+ url: c.req.url,
73
+ path
74
+ }, "Error running after request middleware");
75
+ });
76
+ }).post("/agent/:agentId/run", async (c) => {
77
+ const agentId = c.req.param("agentId");
78
+ const request = c.get("modifiedRequest") || c.req.raw;
79
+ try {
80
+ return await handleRunAgent({
81
+ runtime,
82
+ request,
83
+ agentId
84
+ });
85
+ } catch (error) {
86
+ logger.error({
87
+ err: error,
88
+ url: request.url,
89
+ path: c.req.path
90
+ }, "Error running request handler");
91
+ throw error;
92
+ }
93
+ }).post("/agent/:agentId/connect", async (c) => {
94
+ const agentId = c.req.param("agentId");
95
+ const request = c.get("modifiedRequest") || c.req.raw;
96
+ try {
97
+ return await handleConnectAgent({
98
+ runtime,
99
+ request,
100
+ agentId
101
+ });
102
+ } catch (error) {
103
+ logger.error({
104
+ err: error,
105
+ url: request.url,
106
+ path: c.req.path
107
+ }, "Error running request handler");
108
+ throw error;
109
+ }
110
+ }).post("/agent/:agentId/stop/:threadId", async (c) => {
111
+ const agentId = c.req.param("agentId");
112
+ const threadId = c.req.param("threadId");
113
+ const request = c.get("modifiedRequest") || c.req.raw;
114
+ try {
115
+ return await handleStopAgent({
116
+ runtime,
117
+ request,
118
+ agentId,
119
+ threadId
120
+ });
121
+ } catch (error) {
122
+ logger.error({
123
+ err: error,
124
+ url: request.url,
125
+ path: c.req.path
126
+ }, "Error running request handler");
127
+ throw error;
128
+ }
129
+ }).get("/info", async (c) => {
130
+ const request = c.get("modifiedRequest") || c.req.raw;
131
+ try {
132
+ return await handleGetRuntimeInfo({
133
+ runtime,
134
+ request
135
+ });
136
+ } catch (error) {
137
+ logger.error({
138
+ err: error,
139
+ url: request.url,
140
+ path: c.req.path
141
+ }, "Error running request handler");
142
+ throw error;
143
+ }
144
+ }).post("/transcribe", async (c) => {
145
+ const request = c.get("modifiedRequest") || c.req.raw;
146
+ try {
147
+ return await handleTranscribe({
148
+ runtime,
149
+ request
150
+ });
151
+ } catch (error) {
152
+ logger.error({
153
+ err: error,
154
+ url: request.url,
155
+ path: c.req.path
156
+ }, "Error running request handler");
157
+ throw error;
158
+ }
159
+ }).get("/threads", async (c) => {
160
+ const request = c.get("modifiedRequest") || c.req.raw;
161
+ try {
162
+ return await handleListThreads({
163
+ runtime,
164
+ request
165
+ });
166
+ } catch (error) {
167
+ logger.error({
168
+ err: error,
169
+ url: request.url,
170
+ path: c.req.path
171
+ }, "Error running request handler");
172
+ throw error;
173
+ }
174
+ }).post("/threads/subscribe", async (c) => {
175
+ const request = c.get("modifiedRequest") || c.req.raw;
176
+ try {
177
+ return await handleSubscribeToThreads({
178
+ runtime,
179
+ request
180
+ });
181
+ } catch (error) {
182
+ logger.error({
183
+ err: error,
184
+ url: request.url,
185
+ path: c.req.path
186
+ }, "Error running request handler");
187
+ throw error;
188
+ }
189
+ }).patch("/threads/:threadId", async (c) => {
190
+ const threadId = c.req.param("threadId");
191
+ const request = c.get("modifiedRequest") || c.req.raw;
192
+ try {
193
+ return await handleUpdateThread({
194
+ runtime,
195
+ request,
196
+ threadId
197
+ });
198
+ } catch (error) {
199
+ logger.error({
200
+ err: error,
201
+ url: request.url,
202
+ path: c.req.path
203
+ }, "Error running request handler");
204
+ throw error;
205
+ }
206
+ }).post("/threads/:threadId/archive", async (c) => {
207
+ const threadId = c.req.param("threadId");
208
+ const request = c.get("modifiedRequest") || c.req.raw;
209
+ try {
210
+ return await handleArchiveThread({
211
+ runtime,
212
+ request,
213
+ threadId
214
+ });
215
+ } catch (error) {
216
+ logger.error({
217
+ err: error,
218
+ url: request.url,
219
+ path: c.req.path
220
+ }, "Error running request handler");
221
+ throw error;
222
+ }
223
+ }).delete("/threads/:threadId", async (c) => {
224
+ const threadId = c.req.param("threadId");
225
+ const request = c.get("modifiedRequest") || c.req.raw;
226
+ try {
227
+ return await handleDeleteThread({
228
+ runtime,
229
+ request,
230
+ threadId
231
+ });
232
+ } catch (error) {
233
+ logger.error({
234
+ err: error,
235
+ url: request.url,
236
+ path: c.req.path
237
+ }, "Error running request handler");
238
+ throw error;
239
+ }
240
+ }).notFound((c) => {
241
+ return c.json({ error: "Not found" }, 404);
242
+ });
243
+ }
244
+
245
+ //#endregion
246
+ export { createCopilotEndpoint };
247
+ //# sourceMappingURL=hono.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"hono.mjs","names":[],"sources":["../../../../src/v2/runtime/endpoints/hono.ts"],"sourcesContent":["import { Hono } from \"hono\";\nimport { cors } from \"hono/cors\";\nimport { CopilotRuntimeLike } from \"../runtime\";\nimport { telemetry } from \"../telemetry\";\nimport { handleRunAgent } from \"../handlers/handle-run\";\nimport { handleGetRuntimeInfo } from \"../handlers/get-runtime-info\";\nimport { handleTranscribe } from \"../handlers/handle-transcribe\";\nimport { logger, getLicenseWarningHeader } from \"@copilotkit/shared\";\nimport {\n callBeforeRequestMiddleware,\n callAfterRequestMiddleware,\n} from \"../middleware\";\nimport { handleConnectAgent } from \"../handlers/handle-connect\";\nimport { handleStopAgent } from \"../handlers/handle-stop\";\nimport {\n handleListThreads,\n handleSubscribeToThreads,\n handleUpdateThread,\n handleArchiveThread,\n handleDeleteThread,\n} from \"../handlers/handle-threads\";\n\n/**\n * CORS configuration for CopilotKit endpoints.\n * When using credentials (e.g., HTTP-only cookies), you must specify an explicit origin.\n */\nexport interface CopilotEndpointCorsConfig {\n /**\n * Allowed origin(s) for CORS. Can be:\n * - A string: exact origin (e.g., \"https://myapp.com\")\n * - An array: list of allowed origins\n * - A function: dynamic origin resolution\n *\n * Note: When credentials is true, origin cannot be \"*\"\n */\n origin:\n | string\n | string[]\n | ((origin: string, c: any) => string | undefined | null);\n /**\n * Whether to allow credentials (cookies, HTTP authentication).\n * When true, origin must be explicitly specified (not \"*\").\n */\n credentials?: boolean;\n}\n\ninterface CopilotEndpointParams {\n runtime: CopilotRuntimeLike;\n basePath: string;\n /**\n * Optional CORS configuration. When not provided, defaults to allowing all origins without credentials.\n * To support HTTP-only cookies, provide cors config with credentials: true and explicit origin.\n */\n cors?: CopilotEndpointCorsConfig;\n}\n\n// Define the context variables type\ntype CopilotEndpointContext = {\n Variables: {\n modifiedRequest?: Request;\n };\n};\n\nexport function createCopilotEndpoint({\n runtime,\n basePath,\n cors: corsConfig,\n}: CopilotEndpointParams) {\n const app = new Hono<CopilotEndpointContext>();\n\n // Fire instance_created telemetry - resolve agents if needed\n Promise.resolve(runtime.agents)\n .then((agents) => {\n telemetry.capture(\"oss.runtime.instance_created\", {\n actionsAmount: 0,\n endpointTypes: [],\n endpointsAmount: 0,\n agentsAmount: Object.keys(agents).length,\n \"cloud.api_key_provided\": false,\n });\n })\n .catch(() => {\n // Silently fail - telemetry should not break the application\n });\n\n return app\n .basePath(basePath)\n .use(\n \"*\",\n cors({\n origin: corsConfig?.origin ?? \"*\",\n allowMethods: [\n \"GET\",\n \"HEAD\",\n \"PUT\",\n \"POST\",\n \"DELETE\",\n \"PATCH\",\n \"OPTIONS\",\n ],\n allowHeaders: [\"*\"],\n credentials: corsConfig?.credentials ?? false,\n }),\n )\n .use(\"*\", async (c, next) => {\n const request = c.req.raw;\n const path = c.req.path;\n\n try {\n const maybeModifiedRequest = await callBeforeRequestMiddleware({\n runtime,\n request,\n path,\n });\n if (maybeModifiedRequest) {\n c.set(\"modifiedRequest\", maybeModifiedRequest);\n }\n } catch (error) {\n logger.error(\n { err: error, url: request.url, path },\n \"Error running before request middleware\",\n );\n if (error instanceof Response) {\n return error;\n }\n throw error;\n }\n\n const warning = getLicenseWarningHeader(runtime.licenseChecker);\n if (warning) c.header(warning.key, warning.value);\n\n await next();\n })\n .use(\"*\", async (c, next) => {\n await next();\n\n const response = c.res.clone();\n const path = c.req.path;\n\n // Non-blocking after middleware\n callAfterRequestMiddleware({\n runtime,\n response,\n path,\n }).catch((error) => {\n logger.error(\n { err: error, url: c.req.url, path },\n \"Error running after request middleware\",\n );\n });\n })\n .post(\"/agent/:agentId/run\", async (c) => {\n const agentId = c.req.param(\"agentId\");\n const request = c.get(\"modifiedRequest\") || c.req.raw;\n\n try {\n return await handleRunAgent({\n runtime,\n request,\n agentId,\n });\n } catch (error) {\n logger.error(\n { err: error, url: request.url, path: c.req.path },\n \"Error running request handler\",\n );\n throw error;\n }\n })\n .post(\"/agent/:agentId/connect\", async (c) => {\n const agentId = c.req.param(\"agentId\");\n const request = c.get(\"modifiedRequest\") || c.req.raw;\n\n try {\n return await handleConnectAgent({\n runtime,\n request,\n agentId,\n });\n } catch (error) {\n logger.error(\n { err: error, url: request.url, path: c.req.path },\n \"Error running request handler\",\n );\n throw error;\n }\n })\n\n .post(\"/agent/:agentId/stop/:threadId\", async (c) => {\n const agentId = c.req.param(\"agentId\");\n const threadId = c.req.param(\"threadId\");\n const request = c.get(\"modifiedRequest\") || c.req.raw;\n\n try {\n return await handleStopAgent({\n runtime,\n request,\n agentId,\n threadId,\n });\n } catch (error) {\n logger.error(\n { err: error, url: request.url, path: c.req.path },\n \"Error running request handler\",\n );\n throw error;\n }\n })\n .get(\"/info\", async (c) => {\n const request = c.get(\"modifiedRequest\") || c.req.raw;\n\n try {\n return await handleGetRuntimeInfo({\n runtime,\n request,\n });\n } catch (error) {\n logger.error(\n { err: error, url: request.url, path: c.req.path },\n \"Error running request handler\",\n );\n throw error;\n }\n })\n .post(\"/transcribe\", async (c) => {\n const request = c.get(\"modifiedRequest\") || c.req.raw;\n\n try {\n return await handleTranscribe({\n runtime,\n request,\n });\n } catch (error) {\n logger.error(\n { err: error, url: request.url, path: c.req.path },\n \"Error running request handler\",\n );\n throw error;\n }\n })\n .get(\"/threads\", async (c) => {\n const request = c.get(\"modifiedRequest\") || c.req.raw;\n\n try {\n return await handleListThreads({ runtime, request });\n } catch (error) {\n logger.error(\n { err: error, url: request.url, path: c.req.path },\n \"Error running request handler\",\n );\n throw error;\n }\n })\n .post(\"/threads/subscribe\", async (c) => {\n const request = c.get(\"modifiedRequest\") || c.req.raw;\n\n try {\n return await handleSubscribeToThreads({ runtime, request });\n } catch (error) {\n logger.error(\n { err: error, url: request.url, path: c.req.path },\n \"Error running request handler\",\n );\n throw error;\n }\n })\n .patch(\"/threads/:threadId\", async (c) => {\n const threadId = c.req.param(\"threadId\");\n const request = c.get(\"modifiedRequest\") || c.req.raw;\n\n try {\n return await handleUpdateThread({ runtime, request, threadId });\n } catch (error) {\n logger.error(\n { err: error, url: request.url, path: c.req.path },\n \"Error running request handler\",\n );\n throw error;\n }\n })\n .post(\"/threads/:threadId/archive\", async (c) => {\n const threadId = c.req.param(\"threadId\");\n const request = c.get(\"modifiedRequest\") || c.req.raw;\n\n try {\n return await handleArchiveThread({ runtime, request, threadId });\n } catch (error) {\n logger.error(\n { err: error, url: request.url, path: c.req.path },\n \"Error running request handler\",\n );\n throw error;\n }\n })\n .delete(\"/threads/:threadId\", async (c) => {\n const threadId = c.req.param(\"threadId\");\n const request = c.get(\"modifiedRequest\") || c.req.raw;\n\n try {\n return await handleDeleteThread({ runtime, request, threadId });\n } catch (error) {\n logger.error(\n { err: error, url: request.url, path: c.req.path },\n \"Error running request handler\",\n );\n throw error;\n }\n })\n .notFound((c) => {\n return c.json({ error: \"Not found\" }, 404);\n });\n\n // return app;\n}\n"],"mappings":"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"}
@@ -0,0 +1,5 @@
1
+
2
+ import { CopilotEndpointCorsConfig, createCopilotEndpoint } from "./hono.cjs";
3
+ import { createCopilotEndpointSingleRoute } from "./hono-single.cjs";
4
+ import { createCopilotEndpointExpress } from "./express.cjs";
5
+ import { createCopilotEndpointSingleRouteExpress } from "./express-single.cjs";
@@ -0,0 +1,5 @@
1
+ import "reflect-metadata";
2
+ import { CopilotEndpointCorsConfig, createCopilotEndpoint } from "./hono.mjs";
3
+ import { createCopilotEndpointSingleRoute } from "./hono-single.mjs";
4
+ import { createCopilotEndpointExpress } from "./express.mjs";
5
+ import { createCopilotEndpointSingleRouteExpress } from "./express-single.mjs";
@@ -0,0 +1,68 @@
1
+ require("reflect-metadata");
2
+
3
+ //#region src/v2/runtime/endpoints/single-route-helpers.ts
4
+ const METHOD_NAMES = [
5
+ "agent/run",
6
+ "agent/connect",
7
+ "agent/stop",
8
+ "info",
9
+ "transcribe"
10
+ ];
11
+ async function parseMethodCall(request) {
12
+ if (!(request.headers.get("content-type") || "").includes("application/json")) throw createResponseError("Single-route endpoint expects JSON payloads", 415);
13
+ let jsonEnvelope;
14
+ try {
15
+ jsonEnvelope = await request.clone().json();
16
+ } catch (error) {
17
+ throw createResponseError("Invalid JSON payload", 400);
18
+ }
19
+ return {
20
+ method: validateMethod(jsonEnvelope.method),
21
+ params: jsonEnvelope.params,
22
+ body: jsonEnvelope.body
23
+ };
24
+ }
25
+ function expectString(params, key) {
26
+ const value = params?.[key];
27
+ if (typeof value === "string" && value.trim().length > 0) return value;
28
+ throw createResponseError(`Missing or invalid parameter '${key}'`, 400);
29
+ }
30
+ function createJsonRequest(base, body) {
31
+ if (body === void 0 || body === null) throw createResponseError("Missing request body for JSON handler", 400);
32
+ const headers = new Headers(base.headers);
33
+ headers.set("content-type", "application/json");
34
+ headers.delete("content-length");
35
+ const serializedBody = serializeJsonBody(body);
36
+ return new Request(base.url, {
37
+ method: "POST",
38
+ headers,
39
+ body: serializedBody,
40
+ signal: base.signal
41
+ });
42
+ }
43
+ function createResponseError(message, status) {
44
+ return new Response(JSON.stringify({
45
+ error: "invalid_request",
46
+ message
47
+ }), {
48
+ status,
49
+ headers: { "Content-Type": "application/json" }
50
+ });
51
+ }
52
+ function validateMethod(method) {
53
+ if (!method) throw createResponseError("Missing method field", 400);
54
+ if (METHOD_NAMES.includes(method)) return method;
55
+ throw createResponseError(`Unsupported method '${method}'`, 400);
56
+ }
57
+ function serializeJsonBody(body) {
58
+ if (typeof body === "string") return body;
59
+ if (body instanceof Blob || body instanceof ArrayBuffer || body instanceof Uint8Array) return body;
60
+ if (body instanceof FormData || body instanceof URLSearchParams) return body;
61
+ return JSON.stringify(body);
62
+ }
63
+
64
+ //#endregion
65
+ exports.createJsonRequest = createJsonRequest;
66
+ exports.expectString = expectString;
67
+ exports.parseMethodCall = parseMethodCall;
68
+ //# sourceMappingURL=single-route-helpers.cjs.map