@copilotkit/runtime 1.54.1 → 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 +113 -113
  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 +24 -7
  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,168 @@
1
+ import express from "express";
2
+ import request from "supertest";
3
+ import { describe, expect, it, vi } from "vitest";
4
+ import type { AbstractAgent } from "@ag-ui/client";
5
+ import { Observable, of } from "rxjs";
6
+
7
+ import { createCopilotEndpointSingleRouteExpress } from "../express";
8
+ import { CopilotRuntime } from "../runtime";
9
+
10
+ vi.mock("../handlers/handle-run", () => ({
11
+ handleRunAgent: vi
12
+ .fn()
13
+ .mockResolvedValue(new Response(null, { status: 200 })),
14
+ }));
15
+
16
+ vi.mock("../handlers/handle-connect", () => ({
17
+ handleConnectAgent: vi
18
+ .fn()
19
+ .mockResolvedValue(new Response(null, { status: 200 })),
20
+ }));
21
+
22
+ vi.mock("../handlers/handle-stop", () => ({
23
+ handleStopAgent: vi
24
+ .fn()
25
+ .mockResolvedValue(new Response(null, { status: 200 })),
26
+ }));
27
+
28
+ describe("CopilotEndpointSingleRouteExpress routing", () => {
29
+ const createMockRuntime = () => {
30
+ const createMockAgent = () => {
31
+ const agent: unknown = {
32
+ execute: async () => ({ events: [] }),
33
+ };
34
+ (agent as { clone: () => unknown }).clone = () => createMockAgent();
35
+ return agent as AbstractAgent;
36
+ };
37
+
38
+ const runner = {
39
+ run: () =>
40
+ new Observable((observer) => {
41
+ observer.next({});
42
+ observer.complete();
43
+ return () => undefined;
44
+ }),
45
+ connect: () => of({}),
46
+ stop: async () => true,
47
+ };
48
+
49
+ return new CopilotRuntime({
50
+ agents: {
51
+ default: createMockAgent(),
52
+ myAgent: createMockAgent(),
53
+ agent123: createMockAgent(),
54
+ "my-agent": createMockAgent(),
55
+ my_agent: createMockAgent(),
56
+ testAgent: createMockAgent(),
57
+ test: createMockAgent(),
58
+ "test%20agent": createMockAgent(),
59
+ "test agent": createMockAgent(),
60
+ },
61
+ runner,
62
+ });
63
+ };
64
+
65
+ const createApp = () => {
66
+ const runtime = createMockRuntime();
67
+ const app = express();
68
+ app.use(
69
+ createCopilotEndpointSingleRouteExpress({ runtime, basePath: "/rpc" }),
70
+ );
71
+ return { app, runtime };
72
+ };
73
+
74
+ const postRpc = (app: express.Express, payload: Record<string, unknown>) => {
75
+ return request(app)
76
+ .post("/rpc")
77
+ .set("Content-Type", "application/json")
78
+ .send(payload);
79
+ };
80
+
81
+ describe("agent/run method", () => {
82
+ it("accepts simple agent names", async () => {
83
+ const { app } = createApp();
84
+ const response = await postRpc(app, {
85
+ method: "agent/run",
86
+ params: { agentId: "myAgent" },
87
+ body: {
88
+ messages: [],
89
+ state: {},
90
+ threadId: "thread-1",
91
+ },
92
+ });
93
+
94
+ expect(response.status).not.toBe(404);
95
+ });
96
+
97
+ it("returns 400 when agentId missing", async () => {
98
+ const { app } = createApp();
99
+ const response = await postRpc(app, {
100
+ method: "agent/run",
101
+ body: {},
102
+ });
103
+
104
+ expect(response.status).toBe(400);
105
+ });
106
+ });
107
+
108
+ describe("agent/stop method", () => {
109
+ it("requires threadId", async () => {
110
+ const { app } = createApp();
111
+ const response = await postRpc(app, {
112
+ method: "agent/stop",
113
+ params: { agentId: "agent123" },
114
+ });
115
+
116
+ expect(response.status).toBe(400);
117
+ });
118
+ });
119
+
120
+ describe("info method", () => {
121
+ it("returns runtime info", async () => {
122
+ const { app } = createApp();
123
+ const response = await postRpc(app, { method: "info" });
124
+
125
+ expect(response.status).toBe(200);
126
+ expect(response.body).toHaveProperty("version");
127
+ });
128
+
129
+ it("handles query parameters", async () => {
130
+ const { app } = createApp();
131
+ const response = await request(app)
132
+ .post("/rpc?foo=bar")
133
+ .set("Content-Type", "application/json")
134
+ .send({ method: "info" });
135
+
136
+ expect(response.status).toBe(200);
137
+ });
138
+ });
139
+
140
+ describe("invalid inputs", () => {
141
+ it("returns 415 for non-JSON content", async () => {
142
+ const { app } = createApp();
143
+ const response = await request(app)
144
+ .post("/rpc")
145
+ .set("Content-Type", "text/plain")
146
+ .send("method=info");
147
+
148
+ expect(response.status).toBe(415);
149
+ });
150
+
151
+ it("returns 400 for unsupported method", async () => {
152
+ const { app } = createApp();
153
+ const response = await postRpc(app, { method: "unknown" });
154
+
155
+ expect(response.status).toBe(400);
156
+ });
157
+
158
+ it("returns 404 for unmatched path", async () => {
159
+ const { app } = createApp();
160
+ const response = await request(app)
161
+ .post("/other")
162
+ .set("Content-Type", "application/json")
163
+ .send({ method: "info" });
164
+
165
+ expect(response.status).toBe(404);
166
+ });
167
+ });
168
+ });
@@ -0,0 +1,193 @@
1
+ import { describe, it, expect } from "vitest";
2
+ import type { AbstractAgent } from "@ag-ui/client";
3
+
4
+ import { createCopilotEndpointSingleRoute } from "../endpoints";
5
+ import { CopilotRuntime } from "../runtime";
6
+
7
+ describe("CopilotEndpointSingleRoute routing", () => {
8
+ const createMockRuntime = () => {
9
+ const createMockAgent = () => {
10
+ const agent: unknown = {
11
+ execute: async () => ({ events: [] }),
12
+ };
13
+ (agent as { clone: () => unknown }).clone = () => createMockAgent();
14
+ return agent as AbstractAgent;
15
+ };
16
+
17
+ return new CopilotRuntime({
18
+ agents: {
19
+ default: createMockAgent(),
20
+ myAgent: createMockAgent(),
21
+ agent123: createMockAgent(),
22
+ "my-agent": createMockAgent(),
23
+ my_agent: createMockAgent(),
24
+ testAgent: createMockAgent(),
25
+ test: createMockAgent(),
26
+ "test%20agent": createMockAgent(),
27
+ "test agent": createMockAgent(),
28
+ },
29
+ });
30
+ };
31
+
32
+ const callEndpoint = async (body: Record<string, unknown>) => {
33
+ const runtime = createMockRuntime();
34
+ const endpoint = createCopilotEndpointSingleRoute({
35
+ runtime,
36
+ basePath: "/rpc",
37
+ });
38
+ const request = new Request("https://example.com/rpc", {
39
+ method: "POST",
40
+ headers: { "content-type": "application/json" },
41
+ body: JSON.stringify(body),
42
+ });
43
+
44
+ return endpoint.fetch(request);
45
+ };
46
+
47
+ describe("agent/run method", () => {
48
+ it("accepts simple agent names", async () => {
49
+ const response = await callEndpoint({
50
+ method: "agent/run",
51
+ params: { agentId: "myAgent" },
52
+ body: {},
53
+ });
54
+
55
+ expect(response.status).not.toBe(404);
56
+ });
57
+
58
+ it("accepts hyphenated agent names", async () => {
59
+ const response = await callEndpoint({
60
+ method: "agent/run",
61
+ params: { agentId: "my-agent" },
62
+ body: {},
63
+ });
64
+
65
+ expect(response.status).not.toBe(404);
66
+ });
67
+
68
+ it("accepts underscored agent names", async () => {
69
+ const response = await callEndpoint({
70
+ method: "agent/run",
71
+ params: { agentId: "my_agent" },
72
+ body: {},
73
+ });
74
+
75
+ expect(response.status).not.toBe(404);
76
+ });
77
+
78
+ it("returns 400 when agentId missing", async () => {
79
+ const response = await callEndpoint({
80
+ method: "agent/run",
81
+ body: {},
82
+ });
83
+
84
+ expect(response.status).toBe(400);
85
+ });
86
+ });
87
+
88
+ describe("agent/connect method", () => {
89
+ it("accepts standard agent id", async () => {
90
+ const response = await callEndpoint({
91
+ method: "agent/connect",
92
+ params: { agentId: "agent123" },
93
+ body: {},
94
+ });
95
+
96
+ expect(response.status).not.toBe(404);
97
+ });
98
+ });
99
+
100
+ describe("agent/stop method", () => {
101
+ it("requires threadId", async () => {
102
+ const response = await callEndpoint({
103
+ method: "agent/stop",
104
+ params: { agentId: "agent123" },
105
+ });
106
+
107
+ expect(response.status).toBe(400);
108
+ });
109
+
110
+ it("returns response when params provided", async () => {
111
+ const response = await callEndpoint({
112
+ method: "agent/stop",
113
+ params: { agentId: "agent123", threadId: "thread-1" },
114
+ });
115
+
116
+ expect(response.status).not.toBe(404);
117
+ });
118
+ });
119
+
120
+ describe("info method", () => {
121
+ it("returns runtime info for base path", async () => {
122
+ const response = await callEndpoint({ method: "info" });
123
+
124
+ expect(response.status).toBe(200);
125
+ const body = await response.json();
126
+ expect(body).toHaveProperty("version");
127
+ });
128
+
129
+ it("handles query parameters", async () => {
130
+ const runtime = createMockRuntime();
131
+ const endpoint = createCopilotEndpointSingleRoute({
132
+ runtime,
133
+ basePath: "/rpc",
134
+ });
135
+ const request = new Request("https://example.com/rpc?foo=bar", {
136
+ method: "POST",
137
+ headers: { "content-type": "application/json" },
138
+ body: JSON.stringify({ method: "info" }),
139
+ });
140
+
141
+ const response = await endpoint.fetch(request);
142
+ expect(response.status).toBe(200);
143
+ });
144
+ });
145
+
146
+ describe("transcribe method", () => {
147
+ it("returns non-404 even without multipart body", async () => {
148
+ const response = await callEndpoint({ method: "transcribe" });
149
+
150
+ expect(response.status).not.toBe(404);
151
+ });
152
+ });
153
+
154
+ describe("invalid inputs", () => {
155
+ it("returns 415 for non-JSON content", async () => {
156
+ const runtime = createMockRuntime();
157
+ const endpoint = createCopilotEndpointSingleRoute({
158
+ runtime,
159
+ basePath: "/rpc",
160
+ });
161
+ const request = new Request("https://example.com/rpc", {
162
+ method: "POST",
163
+ headers: { "content-type": "text/plain" },
164
+ body: "method=info",
165
+ });
166
+
167
+ const response = await endpoint.fetch(request);
168
+ expect(response.status).toBe(415);
169
+ });
170
+
171
+ it("returns 400 for unsupported method", async () => {
172
+ const response = await callEndpoint({ method: "unknown" });
173
+
174
+ expect(response.status).toBe(400);
175
+ });
176
+
177
+ it("returns 404 for unmatched path", async () => {
178
+ const runtime = createMockRuntime();
179
+ const endpoint = createCopilotEndpointSingleRoute({
180
+ runtime,
181
+ basePath: "/rpc",
182
+ });
183
+ const request = new Request("https://example.com/other", {
184
+ method: "POST",
185
+ headers: { "content-type": "application/json" },
186
+ body: JSON.stringify({ method: "info" }),
187
+ });
188
+
189
+ const response = await endpoint.fetch(request);
190
+ expect(response.status).toBe(404);
191
+ });
192
+ });
193
+ });
@@ -0,0 +1,257 @@
1
+ import { createCopilotEndpoint } from "../endpoints";
2
+ import { CopilotRuntime } from "../runtime";
3
+ import { describe, it, expect } from "vitest";
4
+ import type { AbstractAgent } from "@ag-ui/client";
5
+
6
+ describe("CopilotEndpoint routing", () => {
7
+ // Helper function to create a Request object with a given URL
8
+ const createRequest = (url: string, method: string = "GET"): Request => {
9
+ return new Request(url, { method });
10
+ };
11
+
12
+ // Create a mock runtime with a basic agent
13
+ const createMockRuntime = () => {
14
+ const createMockAgent = () => {
15
+ const agent: unknown = {
16
+ execute: async () => ({ events: [] }),
17
+ };
18
+ (agent as { clone: () => unknown }).clone = () => createMockAgent();
19
+ return agent as AbstractAgent;
20
+ };
21
+
22
+ return new CopilotRuntime({
23
+ agents: {
24
+ default: createMockAgent(),
25
+ myAgent: createMockAgent(),
26
+ agent123: createMockAgent(),
27
+ "my-agent": createMockAgent(),
28
+ my_agent: createMockAgent(),
29
+ testAgent: createMockAgent(),
30
+ test: createMockAgent(),
31
+ "test%20agent": createMockAgent(),
32
+ "test agent": createMockAgent(),
33
+ },
34
+ });
35
+ };
36
+
37
+ // Helper to test routing
38
+ const testRoute = async (
39
+ url: string,
40
+ method: string = "GET",
41
+ body?: unknown,
42
+ ) => {
43
+ const runtime = createMockRuntime();
44
+ const endpoint = createCopilotEndpoint({ runtime, basePath: "/" });
45
+ const requestInit: RequestInit = { method };
46
+ if (body) {
47
+ requestInit.body = JSON.stringify(body);
48
+ requestInit.headers = { "Content-Type": "application/json" };
49
+ }
50
+ const request = createRequest(url, method);
51
+ const response = await endpoint.fetch(request);
52
+ return response;
53
+ };
54
+
55
+ describe("RunAgent route pattern", () => {
56
+ it("should match agent run URL with simple agent name", async () => {
57
+ const response = await testRoute(
58
+ "https://example.com/agent/myAgent/run",
59
+ "POST",
60
+ {
61
+ agentId: "myAgent",
62
+ },
63
+ );
64
+
65
+ // Should not be 404
66
+ expect(response.status).not.toBe(404);
67
+ });
68
+
69
+ it("should match agent run URL with alphanumeric agent name", async () => {
70
+ const response = await testRoute(
71
+ "https://example.com/agent/agent123/run",
72
+ "POST",
73
+ {
74
+ agentId: "agent123",
75
+ },
76
+ );
77
+
78
+ expect(response.status).not.toBe(404);
79
+ });
80
+
81
+ it("should match agent run URL with hyphenated agent name", async () => {
82
+ const response = await testRoute(
83
+ "https://example.com/agent/my-agent/run",
84
+ "POST",
85
+ {
86
+ agentId: "my-agent",
87
+ },
88
+ );
89
+
90
+ expect(response.status).not.toBe(404);
91
+ });
92
+
93
+ it("should match agent run URL with underscored agent name", async () => {
94
+ const response = await testRoute(
95
+ "https://example.com/agent/my_agent/run",
96
+ "POST",
97
+ {
98
+ agentId: "my_agent",
99
+ },
100
+ );
101
+
102
+ expect(response.status).not.toBe(404);
103
+ });
104
+
105
+ it("should not match agent run URL with empty agent name", async () => {
106
+ const response = await testRoute(
107
+ "https://example.com/agent//run",
108
+ "POST",
109
+ );
110
+
111
+ expect(response.status).toBe(404);
112
+ const body = await response.json();
113
+ expect(body).toEqual({ error: "Not found" });
114
+ });
115
+
116
+ it("should not match partial agent run URL", async () => {
117
+ const response = await testRoute(
118
+ "https://example.com/agent/myAgent",
119
+ "POST",
120
+ );
121
+
122
+ expect(response.status).toBe(404);
123
+ });
124
+
125
+ it("should not match agent run URL with extra path segments", async () => {
126
+ const response = await testRoute(
127
+ "https://example.com/agent/myAgent/run/extra",
128
+ "POST",
129
+ );
130
+
131
+ expect(response.status).toBe(404);
132
+ });
133
+ });
134
+
135
+ describe("GetRuntimeInfo route pattern (/info endpoint)", () => {
136
+ it("should match simple info URL", async () => {
137
+ const response = await testRoute("https://example.com/info");
138
+
139
+ expect(response.status).toBe(200);
140
+ const body = await response.json();
141
+ expect(body).toHaveProperty("version");
142
+ });
143
+
144
+ it("should match info URL with query parameters", async () => {
145
+ const response = await testRoute("https://example.com/info?param=value");
146
+
147
+ expect(response.status).toBe(200);
148
+ });
149
+
150
+ it("should not match non-info URLs", async () => {
151
+ const response = await testRoute("https://example.com/agents");
152
+
153
+ expect(response.status).toBe(404);
154
+ });
155
+ });
156
+
157
+ describe("Transcribe route pattern (/transcribe endpoint)", () => {
158
+ it("should match simple transcribe URL", async () => {
159
+ // Transcribe expects POST method and audio data
160
+ const response = await testRoute(
161
+ "https://example.com/transcribe",
162
+ "POST",
163
+ {},
164
+ );
165
+
166
+ // It might return an error since we're not providing audio, but it shouldn't be 404
167
+ expect(response.status).not.toBe(404);
168
+ });
169
+
170
+ it("should match transcribe URL with query parameters", async () => {
171
+ const response = await testRoute(
172
+ "https://example.com/transcribe?format=json",
173
+ "POST",
174
+ {},
175
+ );
176
+
177
+ expect(response.status).not.toBe(404);
178
+ });
179
+
180
+ it("should not match transcribe URLs with extra path segments", async () => {
181
+ const response = await testRoute(
182
+ "https://example.com/transcribe/extra",
183
+ "POST",
184
+ );
185
+
186
+ expect(response.status).toBe(404);
187
+ });
188
+ });
189
+
190
+ describe("Unmatched routes (404 behavior)", () => {
191
+ it("should return 404 for root path", async () => {
192
+ const response = await testRoute("https://example.com/");
193
+
194
+ expect(response.status).toBe(404);
195
+ const body = await response.json();
196
+ expect(body).toEqual({ error: "Not found" });
197
+ });
198
+
199
+ it("should return 404 for unknown paths", async () => {
200
+ const response = await testRoute("https://example.com/unknown/path");
201
+
202
+ expect(response.status).toBe(404);
203
+ });
204
+
205
+ it("should return 404 for malformed agent paths", async () => {
206
+ const response = await testRoute("https://example.com/agent/run", "POST");
207
+
208
+ expect(response.status).toBe(404);
209
+ });
210
+
211
+ it("should return 404 for agents path", async () => {
212
+ const response = await testRoute("https://example.com/agents");
213
+
214
+ expect(response.status).toBe(404);
215
+ });
216
+ });
217
+
218
+ describe("Edge cases", () => {
219
+ it("should handle URLs with different domains", async () => {
220
+ const response = await testRoute(
221
+ "http://localhost:3000/agent/test/run",
222
+ "POST",
223
+ {
224
+ agentId: "test",
225
+ },
226
+ );
227
+
228
+ expect(response.status).not.toBe(404);
229
+ });
230
+
231
+ it("should handle URLs with ports for info endpoint", async () => {
232
+ const response = await testRoute("https://api.example.com:8080/info");
233
+
234
+ expect(response.status).toBe(200);
235
+ });
236
+
237
+ it("should handle URLs with ports for transcribe endpoint", async () => {
238
+ const response = await testRoute(
239
+ "https://api.example.com:8080/transcribe",
240
+ "POST",
241
+ {},
242
+ );
243
+
244
+ expect(response.status).not.toBe(404);
245
+ });
246
+
247
+ it("should handle URLs with special characters in agent names", async () => {
248
+ const response = await testRoute(
249
+ "https://example.com/agent/test%20agent/run",
250
+ "POST",
251
+ { agentId: "test%20agent" },
252
+ );
253
+
254
+ expect(response.status).not.toBe(404);
255
+ });
256
+ });
257
+ });