@copilotkit/runtime 1.57.2 → 1.57.4

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 (342) hide show
  1. package/dist/lib/runtime/copilot-runtime.cjs +2 -0
  2. package/dist/lib/runtime/copilot-runtime.cjs.map +1 -1
  3. package/dist/lib/runtime/copilot-runtime.d.cts.map +1 -1
  4. package/dist/lib/runtime/copilot-runtime.d.mts.map +1 -1
  5. package/dist/lib/runtime/copilot-runtime.mjs +2 -0
  6. package/dist/lib/runtime/copilot-runtime.mjs.map +1 -1
  7. package/dist/package.cjs +52 -19
  8. package/dist/package.mjs +52 -19
  9. package/dist/v2/runtime/core/runtime.cjs +4 -1
  10. package/dist/v2/runtime/core/runtime.cjs.map +1 -1
  11. package/dist/v2/runtime/core/runtime.d.cts.map +1 -1
  12. package/dist/v2/runtime/core/runtime.d.mts.map +1 -1
  13. package/dist/v2/runtime/core/runtime.mjs +4 -1
  14. package/dist/v2/runtime/core/runtime.mjs.map +1 -1
  15. package/dist/v2/runtime/handlers/get-runtime-info.cjs +1 -1
  16. package/dist/v2/runtime/handlers/get-runtime-info.mjs +1 -1
  17. package/dist/v2/runtime/handlers/handle-connect.cjs +1 -1
  18. package/dist/v2/runtime/handlers/handle-connect.mjs +1 -1
  19. package/dist/v2/runtime/handlers/handle-run.cjs +1 -1
  20. package/dist/v2/runtime/handlers/handle-run.mjs +1 -1
  21. package/dist/v2/runtime/handlers/shared/agent-utils.cjs +1 -1
  22. package/dist/v2/runtime/handlers/shared/agent-utils.cjs.map +1 -1
  23. package/dist/v2/runtime/handlers/shared/agent-utils.mjs +1 -1
  24. package/dist/v2/runtime/handlers/shared/agent-utils.mjs.map +1 -1
  25. package/dist/v2/runtime/telemetry/telemetry-client.cjs +22 -6
  26. package/dist/v2/runtime/telemetry/telemetry-client.cjs.map +1 -1
  27. package/dist/v2/runtime/telemetry/telemetry-client.mjs +27 -11
  28. package/dist/v2/runtime/telemetry/telemetry-client.mjs.map +1 -1
  29. package/package.json +8 -18
  30. package/skills/runtime/SKILL.md +98 -0
  31. package/skills/runtime/references/agent-runners-custom.md +161 -0
  32. package/skills/runtime/references/agent-runners-in-memory.md +64 -0
  33. package/skills/runtime/references/agent-runners-sqlite.md +90 -0
  34. package/skills/runtime/references/agent-runners.md +304 -0
  35. package/skills/runtime/references/built-in-agent-factory-modes.md +232 -0
  36. package/skills/runtime/references/built-in-agent-helper-utilities.md +123 -0
  37. package/skills/runtime/references/built-in-agent-model-identifiers.md +59 -0
  38. package/skills/runtime/references/built-in-agent.md +523 -0
  39. package/skills/runtime/references/intelligence-mode.md +336 -0
  40. package/skills/runtime/references/middleware.md +376 -0
  41. package/skills/runtime/references/server-side-tools.md +414 -0
  42. package/skills/runtime/references/setup-endpoint.md +503 -0
  43. package/skills/runtime/references/transcription.md +287 -0
  44. package/skills/runtime/references/wiring-a2a.md +40 -0
  45. package/skills/runtime/references/wiring-adk.md +45 -0
  46. package/skills/runtime/references/wiring-ag2.md +41 -0
  47. package/skills/runtime/references/wiring-agno.md +39 -0
  48. package/skills/runtime/references/wiring-aws-strands.md +59 -0
  49. package/skills/runtime/references/wiring-crewai-crews.md +51 -0
  50. package/skills/runtime/references/wiring-crewai-flows.md +45 -0
  51. package/skills/runtime/references/wiring-external-agents.md +348 -0
  52. package/skills/runtime/references/wiring-langgraph.md +50 -0
  53. package/skills/runtime/references/wiring-llamaindex.md +39 -0
  54. package/skills/runtime/references/wiring-mastra.md +70 -0
  55. package/skills/runtime/references/wiring-mcp-apps-middleware.md +68 -0
  56. package/skills/runtime/references/wiring-ms-agent-framework.md +41 -0
  57. package/skills/runtime/references/wiring-pydantic-ai.md +45 -0
  58. package/CHANGELOG.md +0 -3624
  59. package/__snapshots__/schema/schema.graphql +0 -371
  60. package/dist/v2/runtime/telemetry/scarf-client.cjs +0 -32
  61. package/dist/v2/runtime/telemetry/scarf-client.cjs.map +0 -1
  62. package/dist/v2/runtime/telemetry/scarf-client.mjs +0 -32
  63. package/dist/v2/runtime/telemetry/scarf-client.mjs.map +0 -1
  64. package/scripts/generate-gql-schema.ts +0 -16
  65. package/src/agent/__tests__/agent-test-helpers.ts +0 -476
  66. package/src/agent/__tests__/agent.test.ts +0 -593
  67. package/src/agent/__tests__/ai-sdk-v6-compat.test.ts +0 -116
  68. package/src/agent/__tests__/basic-agent.test.ts +0 -1698
  69. package/src/agent/__tests__/capabilities.test.ts +0 -81
  70. package/src/agent/__tests__/config-tools-execution.test.ts +0 -516
  71. package/src/agent/__tests__/converter-aisdk.test.ts +0 -692
  72. package/src/agent/__tests__/converter-custom.test.ts +0 -319
  73. package/src/agent/__tests__/converter-tanstack-input.test.ts +0 -211
  74. package/src/agent/__tests__/converter-tanstack.test.ts +0 -594
  75. package/src/agent/__tests__/mcp-clients.test.ts +0 -246
  76. package/src/agent/__tests__/mcp-servers-integration.test.ts +0 -373
  77. package/src/agent/__tests__/multimodal-tanstack.test.ts +0 -284
  78. package/src/agent/__tests__/multimodal.test.ts +0 -176
  79. package/src/agent/__tests__/property-overrides.test.ts +0 -598
  80. package/src/agent/__tests__/provider-id-collision.test.ts +0 -195
  81. package/src/agent/__tests__/standard-schema-tools.test.ts +0 -313
  82. package/src/agent/__tests__/standard-schema-types.test.ts +0 -158
  83. package/src/agent/__tests__/state-tools.test.ts +0 -436
  84. package/src/agent/__tests__/test-helpers.ts +0 -197
  85. package/src/agent/__tests__/utils.test.ts +0 -536
  86. package/src/agent/__tests__/zod-regression.test.ts +0 -350
  87. package/src/agent/converters/aisdk.ts +0 -326
  88. package/src/agent/converters/index.ts +0 -7
  89. package/src/agent/converters/tanstack.ts +0 -451
  90. package/src/agent/index.ts +0 -1743
  91. package/src/agents/langgraph/__tests__/event-source.test.ts +0 -256
  92. package/src/agents/langgraph/event-source.ts +0 -365
  93. package/src/agents/langgraph/events.ts +0 -394
  94. package/src/graphql/inputs/action.input.ts +0 -16
  95. package/src/graphql/inputs/agent-session.input.ts +0 -13
  96. package/src/graphql/inputs/agent-state.input.ts +0 -13
  97. package/src/graphql/inputs/cloud-guardrails.input.ts +0 -16
  98. package/src/graphql/inputs/cloud.input.ts +0 -8
  99. package/src/graphql/inputs/context-property.input.ts +0 -10
  100. package/src/graphql/inputs/copilot-context.input.ts +0 -10
  101. package/src/graphql/inputs/custom-property.input.ts +0 -15
  102. package/src/graphql/inputs/extensions.input.ts +0 -21
  103. package/src/graphql/inputs/forwarded-parameters.input.ts +0 -22
  104. package/src/graphql/inputs/frontend.input.ts +0 -14
  105. package/src/graphql/inputs/generate-copilot-response.input.ts +0 -59
  106. package/src/graphql/inputs/load-agent-state.input.ts +0 -10
  107. package/src/graphql/inputs/message.input.ts +0 -110
  108. package/src/graphql/inputs/meta-event.input.ts +0 -18
  109. package/src/graphql/message-conversion/agui-to-gql.test.ts +0 -1384
  110. package/src/graphql/message-conversion/agui-to-gql.ts +0 -384
  111. package/src/graphql/message-conversion/gql-to-agui.test.ts +0 -1653
  112. package/src/graphql/message-conversion/gql-to-agui.ts +0 -297
  113. package/src/graphql/message-conversion/index.ts +0 -2
  114. package/src/graphql/message-conversion/roundtrip-conversion.test.ts +0 -561
  115. package/src/graphql/resolvers/__tests__/resolve-message-id.test.ts +0 -25
  116. package/src/graphql/resolvers/copilot.resolver.ts +0 -785
  117. package/src/graphql/resolvers/resolve-message-id.ts +0 -14
  118. package/src/graphql/resolvers/state.resolver.ts +0 -30
  119. package/src/graphql/types/agents-response.type.ts +0 -19
  120. package/src/graphql/types/base/index.ts +0 -10
  121. package/src/graphql/types/converted/index.ts +0 -183
  122. package/src/graphql/types/copilot-response.type.ts +0 -141
  123. package/src/graphql/types/enums.ts +0 -38
  124. package/src/graphql/types/extensions-response.type.ts +0 -23
  125. package/src/graphql/types/guardrails-result.type.ts +0 -20
  126. package/src/graphql/types/load-agent-state-response.type.ts +0 -17
  127. package/src/graphql/types/message-status.type.ts +0 -48
  128. package/src/graphql/types/meta-events.type.ts +0 -78
  129. package/src/graphql/types/response-status.type.ts +0 -77
  130. package/src/index.ts +0 -3
  131. package/src/langgraph.ts +0 -1
  132. package/src/lib/__tests__/telemetry-disclosure.test.ts +0 -55
  133. package/src/lib/cloud/index.ts +0 -4
  134. package/src/lib/error-messages.ts +0 -211
  135. package/src/lib/index.ts +0 -52
  136. package/src/lib/integrations/index.ts +0 -6
  137. package/src/lib/integrations/nest/index.ts +0 -21
  138. package/src/lib/integrations/nextjs/app-router.ts +0 -47
  139. package/src/lib/integrations/nextjs/pages-router.ts +0 -45
  140. package/src/lib/integrations/node-express/index.ts +0 -21
  141. package/src/lib/integrations/node-http/__tests__/request-duck-type.test.ts +0 -66
  142. package/src/lib/integrations/node-http/index.ts +0 -187
  143. package/src/lib/integrations/node-http/request-handler.ts +0 -128
  144. package/src/lib/integrations/shared.ts +0 -112
  145. package/src/lib/logger.ts +0 -31
  146. package/src/lib/observability.ts +0 -167
  147. package/src/lib/runtime/__tests__/copilot-runtime-error.test.ts +0 -183
  148. package/src/lib/runtime/__tests__/handle-service-adapter.test.ts +0 -108
  149. package/src/lib/runtime/__tests__/mcp-tools-utils.test.ts +0 -499
  150. package/src/lib/runtime/__tests__/on-after-request.test.ts +0 -122
  151. package/src/lib/runtime/__tests__/retry-utils.test.ts +0 -137
  152. package/src/lib/runtime/__tests__/v1-agent-factory.test.ts +0 -109
  153. package/src/lib/runtime/agent-integrations/langgraph/__tests__/dispatch-event-filtering.test.ts +0 -345
  154. package/src/lib/runtime/agent-integrations/langgraph/__tests__/run-message-filtering.test.ts +0 -156
  155. package/src/lib/runtime/agent-integrations/langgraph/agent.ts +0 -263
  156. package/src/lib/runtime/agent-integrations/langgraph/consts.ts +0 -37
  157. package/src/lib/runtime/agent-integrations/langgraph/index.ts +0 -2
  158. package/src/lib/runtime/copilot-runtime.ts +0 -863
  159. package/src/lib/runtime/mcp-tools-utils.ts +0 -313
  160. package/src/lib/runtime/retry-utils.ts +0 -141
  161. package/src/lib/runtime/telemetry-agent-runner.ts +0 -151
  162. package/src/lib/runtime/types.ts +0 -48
  163. package/src/lib/runtime/utils.ts +0 -93
  164. package/src/lib/streaming.ts +0 -220
  165. package/src/lib/telemetry-client.ts +0 -66
  166. package/src/lib/telemetry-disclosure.ts +0 -53
  167. package/src/service-adapters/anthropic/anthropic-adapter.ts +0 -532
  168. package/src/service-adapters/anthropic/utils.ts +0 -219
  169. package/src/service-adapters/bedrock/bedrock-adapter.ts +0 -73
  170. package/src/service-adapters/conversion.test.ts +0 -56
  171. package/src/service-adapters/conversion.ts +0 -69
  172. package/src/service-adapters/empty/empty-adapter.ts +0 -38
  173. package/src/service-adapters/events.ts +0 -337
  174. package/src/service-adapters/experimental/ollama/ollama-adapter.ts +0 -84
  175. package/src/service-adapters/google/google-genai-adapter.test.ts +0 -151
  176. package/src/service-adapters/google/google-genai-adapter.ts +0 -95
  177. package/src/service-adapters/groq/groq-adapter.ts +0 -229
  178. package/src/service-adapters/index.ts +0 -18
  179. package/src/service-adapters/langchain/langchain-adapter.ts +0 -113
  180. package/src/service-adapters/langchain/langserve.ts +0 -88
  181. package/src/service-adapters/langchain/types.ts +0 -20
  182. package/src/service-adapters/langchain/utils.ts +0 -330
  183. package/src/service-adapters/openai/__tests__/openai-v5-compat.test.ts +0 -177
  184. package/src/service-adapters/openai/openai-adapter.ts +0 -324
  185. package/src/service-adapters/openai/openai-assistant-adapter.ts +0 -385
  186. package/src/service-adapters/openai/utils.ts +0 -305
  187. package/src/service-adapters/service-adapter.ts +0 -50
  188. package/src/service-adapters/shared/error-utils.ts +0 -64
  189. package/src/service-adapters/shared/index.ts +0 -2
  190. package/src/service-adapters/shared/sdk-client-utils.ts +0 -19
  191. package/src/service-adapters/unify/unify-adapter.ts +0 -165
  192. package/src/utils/failed-response-status-reasons.ts +0 -70
  193. package/src/utils/index.ts +0 -1
  194. package/src/v2/express.ts +0 -1
  195. package/src/v2/hono.ts +0 -1
  196. package/src/v2/index.ts +0 -5
  197. package/src/v2/node.ts +0 -1
  198. package/src/v2/runtime/__tests__/agents-factory.test.ts +0 -136
  199. package/src/v2/runtime/__tests__/backward-compat.test.ts +0 -261
  200. package/src/v2/runtime/__tests__/code-review-fixes.test.ts +0 -500
  201. package/src/v2/runtime/__tests__/cors-credentials.test.ts +0 -320
  202. package/src/v2/runtime/__tests__/debug-sse-response.test.ts +0 -302
  203. package/src/v2/runtime/__tests__/express-adapter.test.ts +0 -188
  204. package/src/v2/runtime/__tests__/express-body-order.test.ts +0 -76
  205. package/src/v2/runtime/__tests__/express-fetch-bridge.test.ts +0 -344
  206. package/src/v2/runtime/__tests__/express-single-sse.test.ts +0 -122
  207. package/src/v2/runtime/__tests__/express-single-telemetry.integration.test.ts +0 -65
  208. package/src/v2/runtime/__tests__/express-telemetry.integration.test.ts +0 -101
  209. package/src/v2/runtime/__tests__/fetch-cors.test.ts +0 -205
  210. package/src/v2/runtime/__tests__/fetch-handler-validation.test.ts +0 -440
  211. package/src/v2/runtime/__tests__/fetch-handler.test.ts +0 -456
  212. package/src/v2/runtime/__tests__/fetch-router.test.ts +0 -276
  213. package/src/v2/runtime/__tests__/get-runtime-info.test.ts +0 -335
  214. package/src/v2/runtime/__tests__/handle-connect.test.ts +0 -585
  215. package/src/v2/runtime/__tests__/handle-run.test.ts +0 -1388
  216. package/src/v2/runtime/__tests__/handle-threads.test.ts +0 -930
  217. package/src/v2/runtime/__tests__/handle-transcribe.test.ts +0 -301
  218. package/src/v2/runtime/__tests__/header-utils.test.ts +0 -88
  219. package/src/v2/runtime/__tests__/hono-adapter.test.ts +0 -150
  220. package/src/v2/runtime/__tests__/hono-single-telemetry.integration.test.ts +0 -46
  221. package/src/v2/runtime/__tests__/hono-telemetry.integration.test.ts +0 -99
  222. package/src/v2/runtime/__tests__/hooks-edge-cases.test.ts +0 -457
  223. package/src/v2/runtime/__tests__/hooks.test.ts +0 -557
  224. package/src/v2/runtime/__tests__/in-process-agent-runner-messages.test.ts +0 -230
  225. package/src/v2/runtime/__tests__/in-process-agent-runner.test.ts +0 -1030
  226. package/src/v2/runtime/__tests__/integration/bun/bun-servers.integration.test.ts +0 -27
  227. package/src/v2/runtime/__tests__/integration/bun/elysia-multi.ts +0 -32
  228. package/src/v2/runtime/__tests__/integration/bun/elysia-single.ts +0 -33
  229. package/src/v2/runtime/__tests__/integration/bun/hono-bun-multi.ts +0 -25
  230. package/src/v2/runtime/__tests__/integration/bun/hono-bun-single.ts +0 -32
  231. package/src/v2/runtime/__tests__/integration/helpers/create-test-runtime.ts +0 -15
  232. package/src/v2/runtime/__tests__/integration/helpers/sse-reader.ts +0 -45
  233. package/src/v2/runtime/__tests__/integration/helpers/test-agent.ts +0 -58
  234. package/src/v2/runtime/__tests__/integration/node-servers.integration.test.ts +0 -58
  235. package/src/v2/runtime/__tests__/integration/servers/express-multi.ts +0 -35
  236. package/src/v2/runtime/__tests__/integration/servers/express-single.ts +0 -36
  237. package/src/v2/runtime/__tests__/integration/servers/fetch-direct.ts +0 -39
  238. package/src/v2/runtime/__tests__/integration/servers/hono-multi.ts +0 -30
  239. package/src/v2/runtime/__tests__/integration/servers/hono-single.ts +0 -37
  240. package/src/v2/runtime/__tests__/integration/servers/node-multi.ts +0 -45
  241. package/src/v2/runtime/__tests__/integration/servers/node-single.ts +0 -46
  242. package/src/v2/runtime/__tests__/integration/servers/types.ts +0 -18
  243. package/src/v2/runtime/__tests__/integration/suites/debug-events.suite.ts +0 -253
  244. package/src/v2/runtime/__tests__/integration/suites/multi-endpoint.suite.ts +0 -358
  245. package/src/v2/runtime/__tests__/integration/suites/single-endpoint.suite.ts +0 -363
  246. package/src/v2/runtime/__tests__/intelligence-run-telemetry.test.ts +0 -194
  247. package/src/v2/runtime/__tests__/mcp-apps-middleware-integration.test.ts +0 -275
  248. package/src/v2/runtime/__tests__/middleware-express.test.ts +0 -208
  249. package/src/v2/runtime/__tests__/middleware-single-express.test.ts +0 -213
  250. package/src/v2/runtime/__tests__/middleware-single.test.ts +0 -225
  251. package/src/v2/runtime/__tests__/middleware-sse-parser.test.ts +0 -237
  252. package/src/v2/runtime/__tests__/middleware.test.ts +0 -250
  253. package/src/v2/runtime/__tests__/node-fetch-handler.test.ts +0 -157
  254. package/src/v2/runtime/__tests__/open-generative-ui-middleware.e2e.test.ts +0 -728
  255. package/src/v2/runtime/__tests__/router-edge-cases.test.ts +0 -217
  256. package/src/v2/runtime/__tests__/routing-express.test.ts +0 -174
  257. package/src/v2/runtime/__tests__/routing-single-express.test.ts +0 -168
  258. package/src/v2/runtime/__tests__/routing-single.test.ts +0 -193
  259. package/src/v2/runtime/__tests__/routing.test.ts +0 -257
  260. package/src/v2/runtime/__tests__/runtime.test.ts +0 -234
  261. package/src/v2/runtime/__tests__/sse-response-telemetry.test.ts +0 -108
  262. package/src/v2/runtime/__tests__/telemetry.test.ts +0 -167
  263. package/src/v2/runtime/__tests__/thread-names.test.ts +0 -188
  264. package/src/v2/runtime/core/__tests__/debug-event-bus.test.ts +0 -156
  265. package/src/v2/runtime/core/debug-event-bus.ts +0 -45
  266. package/src/v2/runtime/core/fetch-cors.ts +0 -136
  267. package/src/v2/runtime/core/fetch-handler.ts +0 -492
  268. package/src/v2/runtime/core/fetch-router.ts +0 -203
  269. package/src/v2/runtime/core/hooks.ts +0 -160
  270. package/src/v2/runtime/core/middleware-sse-parser.ts +0 -210
  271. package/src/v2/runtime/core/middleware.ts +0 -115
  272. package/src/v2/runtime/core/runtime.ts +0 -432
  273. package/src/v2/runtime/endpoints/express-fetch-bridge.ts +0 -137
  274. package/src/v2/runtime/endpoints/express-single.ts +0 -54
  275. package/src/v2/runtime/endpoints/express.ts +0 -179
  276. package/src/v2/runtime/endpoints/hono-single.ts +0 -60
  277. package/src/v2/runtime/endpoints/hono.ts +0 -89
  278. package/src/v2/runtime/endpoints/index.ts +0 -4
  279. package/src/v2/runtime/endpoints/node-fetch-handler.ts +0 -48
  280. package/src/v2/runtime/endpoints/node.ts +0 -28
  281. package/src/v2/runtime/endpoints/single-route-helpers.ts +0 -125
  282. package/src/v2/runtime/express.ts +0 -2
  283. package/src/v2/runtime/handlers/__tests__/handle-debug-events.test.ts +0 -176
  284. package/src/v2/runtime/handlers/get-runtime-info.ts +0 -101
  285. package/src/v2/runtime/handlers/handle-connect.ts +0 -80
  286. package/src/v2/runtime/handlers/handle-debug-events.ts +0 -52
  287. package/src/v2/runtime/handlers/handle-run.ts +0 -111
  288. package/src/v2/runtime/handlers/handle-stop.ts +0 -77
  289. package/src/v2/runtime/handlers/handle-threads.ts +0 -11
  290. package/src/v2/runtime/handlers/handle-transcribe.ts +0 -269
  291. package/src/v2/runtime/handlers/header-utils.ts +0 -24
  292. package/src/v2/runtime/handlers/intelligence/connect.ts +0 -102
  293. package/src/v2/runtime/handlers/intelligence/run.ts +0 -351
  294. package/src/v2/runtime/handlers/intelligence/thread-names.ts +0 -246
  295. package/src/v2/runtime/handlers/intelligence/threads.ts +0 -420
  296. package/src/v2/runtime/handlers/shared/agent-utils.ts +0 -154
  297. package/src/v2/runtime/handlers/shared/intelligence-utils.ts +0 -41
  298. package/src/v2/runtime/handlers/shared/json-response.ts +0 -9
  299. package/src/v2/runtime/handlers/shared/resolve-intelligence-user.ts +0 -28
  300. package/src/v2/runtime/handlers/shared/sse-response.ts +0 -215
  301. package/src/v2/runtime/handlers/sse/__tests__/sse-connect-agent-id.test.ts +0 -71
  302. package/src/v2/runtime/handlers/sse/connect.ts +0 -30
  303. package/src/v2/runtime/handlers/sse/run.ts +0 -40
  304. package/src/v2/runtime/hono.ts +0 -2
  305. package/src/v2/runtime/index.ts +0 -51
  306. package/src/v2/runtime/intelligence-platform/__tests__/client.test.ts +0 -601
  307. package/src/v2/runtime/intelligence-platform/__tests__/intelligence-mcp-helper.test.ts +0 -246
  308. package/src/v2/runtime/intelligence-platform/client.ts +0 -818
  309. package/src/v2/runtime/intelligence-platform/index.ts +0 -10
  310. package/src/v2/runtime/node.ts +0 -6
  311. package/src/v2/runtime/open-generative-ui-middleware.ts +0 -373
  312. package/src/v2/runtime/runner/__tests__/finalize-events.test.ts +0 -109
  313. package/src/v2/runtime/runner/__tests__/in-memory-runner.e2e.test.ts +0 -775
  314. package/src/v2/runtime/runner/__tests__/in-memory-runner.test.ts +0 -777
  315. package/src/v2/runtime/runner/__tests__/intelligence-runner.test.ts +0 -1039
  316. package/src/v2/runtime/runner/agent-runner.ts +0 -35
  317. package/src/v2/runtime/runner/in-memory.ts +0 -467
  318. package/src/v2/runtime/runner/index.ts +0 -4
  319. package/src/v2/runtime/runner/intelligence.ts +0 -498
  320. package/src/v2/runtime/telemetry/__tests__/instance-created.test.ts +0 -96
  321. package/src/v2/runtime/telemetry/events.ts +0 -35
  322. package/src/v2/runtime/telemetry/index.ts +0 -7
  323. package/src/v2/runtime/telemetry/instance-created.ts +0 -44
  324. package/src/v2/runtime/telemetry/scarf-client.ts +0 -39
  325. package/src/v2/runtime/telemetry/telemetry-client.ts +0 -70
  326. package/src/v2/runtime/transcription-service/transcription-service.ts +0 -11
  327. package/tests/global.d.ts +0 -1
  328. package/tests/service-adapters/anthropic/allowlist-approach.test.ts +0 -259
  329. package/tests/service-adapters/anthropic/anthropic-adapter-language-model.test.ts +0 -101
  330. package/tests/service-adapters/anthropic/anthropic-adapter.test.ts +0 -645
  331. package/tests/service-adapters/anthropic/utils-token-trimming.test.ts +0 -301
  332. package/tests/service-adapters/groq/groq-adapter-language-model.test.ts +0 -102
  333. package/tests/service-adapters/openai/allowlist-approach.test.ts +0 -294
  334. package/tests/service-adapters/openai/openai-adapter-language-model.test.ts +0 -122
  335. package/tests/service-adapters/openai/openai-adapter.test.ts +0 -291
  336. package/tests/service-adapters/shared/sdk-client-utils.test.ts +0 -36
  337. package/tests/setup.vitest.ts +0 -8
  338. package/tests/tsconfig.json +0 -10
  339. package/tsconfig.json +0 -20
  340. package/tsdown.config.ts +0 -45
  341. package/typedoc.json +0 -4
  342. package/vitest.config.mjs +0 -13
@@ -0,0 +1,503 @@
1
+ # CopilotKit Runtime Endpoint
2
+
3
+ `createCopilotRuntimeHandler` is the strongly-preferred primitive. It returns a
4
+ `(Request) => Promise<Response>` that works in every fetch-native runtime and can be
5
+ delegated to from Express/Hono/Node. Avoid `createCopilotExpressHandler` and
6
+ `createCopilotHonoHandler` in new code.
7
+
8
+ ## Setup
9
+
10
+ Minimal runtime on any fetch server (Bun, Deno, Cloudflare Workers, Vercel Edge):
11
+
12
+ ```typescript
13
+ import {
14
+ CopilotRuntime,
15
+ createCopilotRuntimeHandler,
16
+ BuiltInAgent,
17
+ convertInputToTanStackAI,
18
+ } from "@copilotkit/runtime/v2";
19
+ import { chat } from "@tanstack/ai";
20
+ import { openaiText } from "@tanstack/ai-openai";
21
+
22
+ const runtime = new CopilotRuntime({
23
+ agents: {
24
+ default: new BuiltInAgent({
25
+ type: "tanstack",
26
+ factory: ({ input, abortController }) => {
27
+ const { messages, systemPrompts } = convertInputToTanStackAI(input);
28
+ return chat({
29
+ adapter: openaiText("gpt-4o"),
30
+ messages,
31
+ systemPrompts,
32
+ abortController,
33
+ });
34
+ },
35
+ }),
36
+ },
37
+ });
38
+
39
+ export const handler = createCopilotRuntimeHandler({
40
+ runtime,
41
+ basePath: "/api/copilotkit",
42
+ cors: true,
43
+ });
44
+
45
+ // Bun / Deno / Vercel Edge:
46
+ // Bun.serve({ fetch: handler });
47
+ // Deno.serve(handler);
48
+ // Cloudflare Workers:
49
+ // export default { fetch: handler };
50
+ ```
51
+
52
+ ## Core Patterns
53
+
54
+ ### React Router v7 framework mode
55
+
56
+ ```typescript
57
+ // app/routes/api.copilotkit.$.tsx
58
+ import type { Route } from "./+types/api.copilotkit.$";
59
+ import {
60
+ CopilotRuntime,
61
+ createCopilotRuntimeHandler,
62
+ BuiltInAgent,
63
+ convertInputToTanStackAI,
64
+ } from "@copilotkit/runtime/v2";
65
+ import { chat } from "@tanstack/ai";
66
+ import { openaiText } from "@tanstack/ai-openai";
67
+
68
+ const runtime = new CopilotRuntime({
69
+ agents: {
70
+ default: new BuiltInAgent({
71
+ type: "tanstack",
72
+ factory: ({ input, abortController }) => {
73
+ const { messages, systemPrompts } = convertInputToTanStackAI(input);
74
+ return chat({
75
+ adapter: openaiText("gpt-4o"),
76
+ messages,
77
+ systemPrompts,
78
+ abortController,
79
+ });
80
+ },
81
+ }),
82
+ },
83
+ });
84
+
85
+ const handler = createCopilotRuntimeHandler({
86
+ runtime,
87
+ basePath: "/api/copilotkit",
88
+ });
89
+
90
+ export async function loader({ request }: Route.LoaderArgs) {
91
+ return handler(request);
92
+ }
93
+ export async function action({ request }: Route.ActionArgs) {
94
+ return handler(request);
95
+ }
96
+ ```
97
+
98
+ ### Next.js App Router
99
+
100
+ ```typescript
101
+ // app/api/copilotkit/[...slug]/route.ts
102
+ import {
103
+ CopilotRuntime,
104
+ createCopilotRuntimeHandler,
105
+ BuiltInAgent,
106
+ convertInputToTanStackAI,
107
+ } from "@copilotkit/runtime/v2";
108
+ import { chat } from "@tanstack/ai";
109
+ import { openaiText } from "@tanstack/ai-openai";
110
+
111
+ const runtime = new CopilotRuntime({
112
+ agents: {
113
+ default: new BuiltInAgent({
114
+ type: "tanstack",
115
+ factory: ({ input, abortController }) => {
116
+ const { messages, systemPrompts } = convertInputToTanStackAI(input);
117
+ return chat({
118
+ adapter: openaiText("gpt-4o"),
119
+ messages,
120
+ systemPrompts,
121
+ abortController,
122
+ });
123
+ },
124
+ }),
125
+ },
126
+ });
127
+
128
+ const handler = createCopilotRuntimeHandler({
129
+ runtime,
130
+ basePath: "/api/copilotkit",
131
+ });
132
+
133
+ export const GET = handler;
134
+ export const POST = handler;
135
+ export const OPTIONS = handler;
136
+ ```
137
+
138
+ ### Cloudflare Workers with env-sourced keys
139
+
140
+ Workers don't expose `env` at module scope, so build the runtime + handler lazily on the
141
+ first request and cache them in module-scoped variables. `openaiText(model, config)` does
142
+ NOT accept an `apiKey` in its config (it auto-reads `OPENAI_API_KEY` from env) — for an
143
+ explicit key, use `createOpenaiChat(model, apiKey, config?)`.
144
+
145
+ ```typescript
146
+ // worker.ts
147
+ import {
148
+ CopilotRuntime,
149
+ createCopilotRuntimeHandler,
150
+ BuiltInAgent,
151
+ convertInputToTanStackAI,
152
+ } from "@copilotkit/runtime/v2";
153
+ import { chat } from "@tanstack/ai";
154
+ import { createOpenaiChat } from "@tanstack/ai-openai";
155
+
156
+ interface Env {
157
+ OPENAI_API_KEY: string;
158
+ }
159
+
160
+ type Handler = (request: Request) => Promise<Response>;
161
+ let handler: Handler | undefined;
162
+
163
+ function getHandler(env: Env): Handler {
164
+ if (handler) return handler;
165
+ const runtime = new CopilotRuntime({
166
+ agents: {
167
+ default: new BuiltInAgent({
168
+ type: "tanstack",
169
+ factory: ({ input, abortController }) => {
170
+ const { messages, systemPrompts } = convertInputToTanStackAI(input);
171
+ return chat({
172
+ adapter: createOpenaiChat("gpt-4o", env.OPENAI_API_KEY),
173
+ messages,
174
+ systemPrompts,
175
+ abortController,
176
+ });
177
+ },
178
+ }),
179
+ },
180
+ });
181
+ handler = createCopilotRuntimeHandler({
182
+ runtime,
183
+ basePath: "/api/copilotkit",
184
+ cors: true,
185
+ });
186
+ return handler;
187
+ }
188
+
189
+ export default {
190
+ fetch(request: Request, env: Env) {
191
+ return getHandler(env)(request);
192
+ },
193
+ };
194
+ ```
195
+
196
+ ### Delegate from Express / Hono to the fetch primitive
197
+
198
+ Do not use `createCopilotExpressHandler` / `createCopilotHonoHandler`.
199
+
200
+ ```typescript
201
+ // Express — requires Node 18.17+ for Readable.fromWeb + fetch body: req
202
+ import express from "express";
203
+ import { Readable } from "node:stream";
204
+ import type { ReadableStream as WebReadableStream } from "node:stream/web";
205
+ import {
206
+ CopilotRuntime,
207
+ createCopilotRuntimeHandler,
208
+ } from "@copilotkit/runtime/v2";
209
+
210
+ const app = express();
211
+ const runtime = new CopilotRuntime({
212
+ agents: {
213
+ /* ... */
214
+ } as any,
215
+ });
216
+ const handler = createCopilotRuntimeHandler({
217
+ runtime,
218
+ basePath: "/api/copilotkit",
219
+ });
220
+
221
+ app.all("/api/copilotkit/*", async (req, res) => {
222
+ const url = new URL(req.url, `http://${req.headers.host}`);
223
+ // `body: req` + `duplex: "half"` lets us stream the Node IncomingMessage
224
+ // into a Web Request without buffering (Node 18.17+).
225
+ const webReq = new Request(url, {
226
+ method: req.method,
227
+ headers: req.headers as any,
228
+ body: ["GET", "HEAD"].includes(req.method!) ? undefined : req,
229
+ duplex: "half",
230
+ } as any);
231
+ const webRes = await handler(webReq);
232
+ res.status(webRes.status);
233
+ webRes.headers.forEach((v, k) => res.setHeader(k, v));
234
+ // Stream the response body through — required for SSE on
235
+ // /agent/*/run and /agent/*/connect. Buffering via arrayBuffer()
236
+ // would collapse the stream and deliver all events at end-of-stream.
237
+ if (webRes.body) {
238
+ Readable.fromWeb(webRes.body as unknown as WebReadableStream).pipe(res);
239
+ } else {
240
+ res.end();
241
+ }
242
+ });
243
+
244
+ app.listen(3000);
245
+ ```
246
+
247
+ ```typescript
248
+ // Hono — already speaks Request/Response
249
+ import { Hono } from "hono";
250
+ import {
251
+ CopilotRuntime,
252
+ createCopilotRuntimeHandler,
253
+ } from "@copilotkit/runtime/v2";
254
+
255
+ const app = new Hono();
256
+ const runtime = new CopilotRuntime({
257
+ agents: {
258
+ /* ... */
259
+ } as any,
260
+ });
261
+ const handler = createCopilotRuntimeHandler({
262
+ runtime,
263
+ basePath: "/api/copilotkit",
264
+ });
265
+
266
+ app.all("/api/copilotkit/*", (c) => handler(c.req.raw));
267
+
268
+ export default app;
269
+ ```
270
+
271
+ ### Route table
272
+
273
+ Multi-route mode (default) exposes: `GET /info`, `POST /agent/:agentId/run`,
274
+ `GET /agent/:agentId/connect`, `POST /agent/:agentId/stop/:threadId`, `POST /transcribe`,
275
+ `GET/POST /threads`, `GET /threads/subscribe`, `PATCH /threads/:threadId`,
276
+ `POST /threads/:threadId/archive`, `DELETE /threads/:threadId`,
277
+ `GET /threads/:threadId/messages`. Thread routes are only wired when Intelligence mode
278
+ is configured.
279
+
280
+ Single-route mode exposes a single `POST basePath` that accepts
281
+ `{ method, params, body }` envelopes — use when behind a strict reverse proxy.
282
+
283
+ ## Common Mistakes
284
+
285
+ ### CRITICAL Using createCopilotExpressHandler / createCopilotHonoHandler in new code
286
+
287
+ Wrong:
288
+
289
+ ```typescript
290
+ import { createCopilotExpressHandler } from "@copilotkit/runtime/v2/express";
291
+ app.use(
292
+ "/api/copilotkit",
293
+ createCopilotExpressHandler({ runtime, basePath: "/api/copilotkit" }),
294
+ );
295
+ ```
296
+
297
+ Correct:
298
+
299
+ ```typescript
300
+ import { Readable } from "node:stream";
301
+ import type { ReadableStream as WebReadableStream } from "node:stream/web";
302
+ import { createCopilotRuntimeHandler } from "@copilotkit/runtime/v2";
303
+ const handler = createCopilotRuntimeHandler({
304
+ runtime,
305
+ basePath: "/api/copilotkit",
306
+ });
307
+ app.all("/api/copilotkit/*", async (req, res) => {
308
+ // Requires Node 18.17+ (Readable.fromWeb + duplex: "half")
309
+ const webReq = new Request(new URL(req.url, `http://${req.headers.host}`), {
310
+ method: req.method,
311
+ headers: req.headers as any,
312
+ body: ["GET", "HEAD"].includes(req.method!) ? undefined : req,
313
+ duplex: "half",
314
+ } as any);
315
+ const webRes = await handler(webReq);
316
+ res.status(webRes.status);
317
+ webRes.headers.forEach((v, k) => res.setHeader(k, v));
318
+ // Stream, don't buffer — /agent/*/run is SSE.
319
+ if (webRes.body) {
320
+ Readable.fromWeb(webRes.body as unknown as WebReadableStream).pipe(res);
321
+ } else {
322
+ res.end();
323
+ }
324
+ });
325
+ ```
326
+
327
+ The Express and Hono adapters are a discouraged surface — the maintainer flags them as
328
+ "avoid at all costs." They pull in heavier dependencies, add framework binding, and make
329
+ it harder to port. The fetch handler works from any Express/Hono route.
330
+
331
+ Source: `packages/runtime/src/v2/runtime/core/fetch-handler.ts:1-27`; maintainer Phase 4d.
332
+
333
+ ### CRITICAL Instantiating Express handler without basePath
334
+
335
+ Wrong:
336
+
337
+ ```typescript
338
+ app.use(createCopilotExpressHandler({ runtime }));
339
+ ```
340
+
341
+ Correct:
342
+
343
+ ```typescript
344
+ const handler = createCopilotRuntimeHandler({
345
+ runtime,
346
+ basePath: "/api/copilotkit",
347
+ });
348
+ app.all("/api/copilotkit/*", (req, res) => {
349
+ /* delegate as shown above */
350
+ });
351
+ ```
352
+
353
+ `normalizeBasePath` throws `"basePath must be provided for Express endpoint"` at mount time
354
+ and crashes the server.
355
+
356
+ Source: `packages/runtime/src/v2/runtime/endpoints/express.ts:161`.
357
+
358
+ ### HIGH Using framework adapter on Workers / Bun / Deno
359
+
360
+ Wrong:
361
+
362
+ ```typescript
363
+ // Cloudflare Worker
364
+ import { createCopilotHonoHandler } from "@copilotkit/runtime/v2/hono";
365
+ export default app;
366
+ ```
367
+
368
+ Correct:
369
+
370
+ ```typescript
371
+ import { createCopilotRuntimeHandler } from "@copilotkit/runtime/v2";
372
+ const handler = createCopilotRuntimeHandler({
373
+ runtime,
374
+ basePath: "/api/copilotkit",
375
+ });
376
+ export default { fetch: (req: Request) => handler(req) };
377
+ ```
378
+
379
+ Adapters bundle Node polyfills unnecessarily in fetch-native runtimes.
380
+
381
+ Source: `packages/runtime/src/v2/runtime/core/fetch-handler.ts:1-27`.
382
+
383
+ ### HIGH Returning a Response from beforeRequestMiddleware
384
+
385
+ Wrong:
386
+
387
+ ```typescript
388
+ new CopilotRuntime({
389
+ agents,
390
+ beforeRequestMiddleware: async () =>
391
+ new Response("Unauthorized", { status: 401 }),
392
+ });
393
+ ```
394
+
395
+ Correct:
396
+
397
+ ```typescript
398
+ const handler = createCopilotRuntimeHandler({
399
+ runtime,
400
+ basePath: "/api/copilotkit",
401
+ hooks: {
402
+ onRequest: ({ request }) => {
403
+ if (!request.headers.get("authorization")) {
404
+ throw new Response("Unauthorized", { status: 401 });
405
+ }
406
+ },
407
+ },
408
+ });
409
+ ```
410
+
411
+ Only `Request | void` returns are honored. Any other return is ignored. Responses must be
412
+ thrown.
413
+
414
+ Source: `packages/runtime/src/v2/runtime/core/fetch-handler.ts:148-156`.
415
+
416
+ ### MEDIUM Calling multi-route paths against a single-route handler
417
+
418
+ Wrong:
419
+
420
+ ```typescript
421
+ // handler = createCopilotRuntimeHandler({ mode: "single-route", ... })
422
+ fetch("/api/copilotkit/agent/x/run", {
423
+ method: "POST",
424
+ body: JSON.stringify(input),
425
+ });
426
+ ```
427
+
428
+ Correct:
429
+
430
+ ```typescript
431
+ fetch("/api/copilotkit", {
432
+ method: "POST",
433
+ body: JSON.stringify({
434
+ method: "agent/run",
435
+ params: { agentId: "x" },
436
+ body: input,
437
+ }),
438
+ });
439
+ // On the client, pair with <CopilotKitProvider useSingleEndpoint />.
440
+ ```
441
+
442
+ Single-route expects a POST envelope with `{ method, params, body }`; URL-pattern calls 404.
443
+
444
+ Source: `packages/runtime/src/v2/runtime/core/fetch-handler.ts:86-90,350-401`.
445
+
446
+ ### MEDIUM Double-layering CORS in Express
447
+
448
+ Wrong:
449
+
450
+ ```typescript
451
+ import cors from "cors";
452
+ app.use(cors());
453
+ app.use(
454
+ createCopilotExpressHandler({ runtime, basePath, cors: { origin: "..." } }),
455
+ );
456
+ ```
457
+
458
+ Correct:
459
+
460
+ ```typescript
461
+ // Pick one — handler's cors option OR your own cors(), not both:
462
+ const handler = createCopilotRuntimeHandler({
463
+ runtime,
464
+ basePath: "/api/copilotkit",
465
+ cors: { origin: "https://my.app" },
466
+ });
467
+ app.all("/api/copilotkit/*", (req, res) => {
468
+ /* delegate as above */
469
+ });
470
+ ```
471
+
472
+ Both layers add CORS headers and the duplicates break strict browser enforcement.
473
+
474
+ Source: `packages/runtime/src/v2/runtime/endpoints/express.ts:100-143`.
475
+
476
+ ### HIGH Mixing v1 and v2 import paths
477
+
478
+ Wrong:
479
+
480
+ ```typescript
481
+ import { CopilotRuntime } from "@copilotkit/runtime";
482
+ import { createCopilotRuntimeHandler } from "@copilotkit/runtime/v2";
483
+ ```
484
+
485
+ Correct:
486
+
487
+ ```typescript
488
+ import {
489
+ CopilotRuntime,
490
+ createCopilotRuntimeHandler,
491
+ } from "@copilotkit/runtime/v2";
492
+ ```
493
+
494
+ Both v1 and v2 APIs compile together but route through different implementations. Always
495
+ use the `/v2` subpath in v2 code.
496
+
497
+ Source: `packages/runtime/src/v2/index.ts`.
498
+
499
+ ## See also
500
+
501
+ - `copilotkit/middleware` — hook lifecycle into this handler
502
+ - `copilotkit/agent-runners` — pair with a persistent runner for production
503
+ - `copilotkit/intelligence-mode` — thread routes flip on when Intelligence is configured