@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
@@ -1,35 +1,51 @@
1
1
  import "reflect-metadata";
2
- import scarf_client_default from "./scarf-client.mjs";
2
+ import { __toESM } from "../../../_virtual/_rolldown/runtime.mjs";
3
+ import { require_package } from "../../../package.mjs";
4
+ import { lambdaClient, parseAndWarnTelemetryId } from "@copilotkit/shared";
3
5
 
4
6
  //#region src/v2/runtime/telemetry/telemetry-client.ts
5
- function isTelemetryDisabled() {
7
+ var import_package = /* @__PURE__ */ __toESM(require_package());
8
+ function isTelemetryDisabled$1() {
6
9
  return process.env.COPILOTKIT_TELEMETRY_DISABLED === "true" || process.env.COPILOTKIT_TELEMETRY_DISABLED === "1" || process.env.DO_NOT_TRACK === "true" || process.env.DO_NOT_TRACK === "1";
7
10
  }
8
- var TelemetryClient = class {
11
+ var TelemetryClient$1 = class {
9
12
  constructor({ telemetryDisabled, sampleRate } = {}) {
10
13
  this.telemetryDisabled = false;
11
14
  this.sampleRate = .05;
12
- this.telemetryDisabled = telemetryDisabled ?? isTelemetryDisabled();
15
+ this.licenseToken = null;
16
+ this.telemetryId = null;
17
+ this.telemetryDisabled = telemetryDisabled ?? isTelemetryDisabled$1();
13
18
  this.setSampleRate(sampleRate);
14
19
  }
15
20
  shouldSendEvent() {
16
- if (this.telemetryDisabled) return false;
21
+ if (this.sampleRate >= 1) return true;
17
22
  return Math.random() < this.sampleRate;
18
23
  }
19
- async capture(event, _properties) {
20
- if (!this.shouldSendEvent()) return;
21
- await scarf_client_default.logEvent({ event });
24
+ setLicenseToken(licenseToken) {
25
+ this.licenseToken = licenseToken;
26
+ this.telemetryId = parseAndWarnTelemetryId(licenseToken);
27
+ }
28
+ async capture(event, properties) {
29
+ if (this.telemetryDisabled) return;
30
+ if (!this.telemetryId && !this.shouldSendEvent()) return;
31
+ await lambdaClient.send({
32
+ event,
33
+ properties,
34
+ packageName: import_package.name,
35
+ packageVersion: import_package.version,
36
+ licenseToken: this.licenseToken ?? void 0
37
+ });
22
38
  }
23
39
  setSampleRate(sampleRate) {
24
40
  let _sampleRate;
25
41
  _sampleRate = sampleRate ?? .05;
26
42
  if (process.env.COPILOTKIT_TELEMETRY_SAMPLE_RATE) _sampleRate = parseFloat(process.env.COPILOTKIT_TELEMETRY_SAMPLE_RATE);
27
- if (_sampleRate < 0 || _sampleRate > 1) throw new Error("Sample rate must be between 0 and 1");
43
+ if (Number.isNaN(_sampleRate) || _sampleRate < 0 || _sampleRate > 1) throw new Error("Sample rate must be between 0 and 1");
28
44
  this.sampleRate = _sampleRate;
29
45
  }
30
46
  };
31
- const telemetry = new TelemetryClient();
47
+ const telemetry = new TelemetryClient$1();
32
48
 
33
49
  //#endregion
34
- export { telemetry as default, isTelemetryDisabled };
50
+ export { telemetry as default, isTelemetryDisabled$1 as isTelemetryDisabled };
35
51
  //# sourceMappingURL=telemetry-client.mjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"telemetry-client.mjs","names":["scarfClient"],"sources":["../../../../src/v2/runtime/telemetry/telemetry-client.ts"],"sourcesContent":["import { AnalyticsEvents } from \"./events\";\nimport scarfClient from \"./scarf-client\";\n\nexport function isTelemetryDisabled(): boolean {\n return (\n (process.env as Record<string, string | undefined>)\n .COPILOTKIT_TELEMETRY_DISABLED === \"true\" ||\n (process.env as Record<string, string | undefined>)\n .COPILOTKIT_TELEMETRY_DISABLED === \"1\" ||\n (process.env as Record<string, string | undefined>).DO_NOT_TRACK ===\n \"true\" ||\n (process.env as Record<string, string | undefined>).DO_NOT_TRACK === \"1\"\n );\n}\n\nexport class TelemetryClient {\n private telemetryDisabled: boolean = false;\n private sampleRate: number = 0.05;\n\n constructor({\n telemetryDisabled,\n sampleRate,\n }: {\n telemetryDisabled?: boolean;\n sampleRate?: number;\n } = {}) {\n this.telemetryDisabled = telemetryDisabled ?? isTelemetryDisabled();\n this.setSampleRate(sampleRate);\n }\n\n private shouldSendEvent() {\n if (this.telemetryDisabled) {\n return false;\n }\n const randomNumber = Math.random();\n return randomNumber < this.sampleRate;\n }\n\n async capture<K extends keyof AnalyticsEvents>(\n event: K,\n _properties: AnalyticsEvents[K],\n ) {\n if (!this.shouldSendEvent()) {\n return;\n }\n\n await scarfClient.logEvent({\n event,\n });\n }\n\n private setSampleRate(sampleRate: number | undefined) {\n let _sampleRate: number;\n\n _sampleRate = sampleRate ?? 0.05;\n\n if (process.env.COPILOTKIT_TELEMETRY_SAMPLE_RATE) {\n _sampleRate = parseFloat(process.env.COPILOTKIT_TELEMETRY_SAMPLE_RATE);\n }\n\n if (_sampleRate < 0 || _sampleRate > 1) {\n throw new Error(\"Sample rate must be between 0 and 1\");\n }\n\n this.sampleRate = _sampleRate;\n }\n}\n\nconst telemetry = new TelemetryClient();\nexport default telemetry;\n"],"mappings":";;;;AAGA,SAAgB,sBAA+B;AAC7C,QACG,QAAQ,IACN,kCAAkC,UACpC,QAAQ,IACN,kCAAkC,OACpC,QAAQ,IAA2C,iBAClD,UACD,QAAQ,IAA2C,iBAAiB;;AAIzE,IAAa,kBAAb,MAA6B;CAI3B,YAAY,EACV,mBACA,eAIE,EAAE,EAAE;2BAT6B;oBACR;AAS3B,OAAK,oBAAoB,qBAAqB,qBAAqB;AACnE,OAAK,cAAc,WAAW;;CAGhC,AAAQ,kBAAkB;AACxB,MAAI,KAAK,kBACP,QAAO;AAGT,SADqB,KAAK,QAAQ,GACZ,KAAK;;CAG7B,MAAM,QACJ,OACA,aACA;AACA,MAAI,CAAC,KAAK,iBAAiB,CACzB;AAGF,QAAMA,qBAAY,SAAS,EACzB,OACD,CAAC;;CAGJ,AAAQ,cAAc,YAAgC;EACpD,IAAI;AAEJ,gBAAc,cAAc;AAE5B,MAAI,QAAQ,IAAI,iCACd,eAAc,WAAW,QAAQ,IAAI,iCAAiC;AAGxE,MAAI,cAAc,KAAK,cAAc,EACnC,OAAM,IAAI,MAAM,sCAAsC;AAGxD,OAAK,aAAa;;;AAItB,MAAM,YAAY,IAAI,iBAAiB"}
1
+ {"version":3,"file":"telemetry-client.mjs","names":["isTelemetryDisabled","TelemetryClient","packageJson"],"sources":["../../../../src/v2/runtime/telemetry/telemetry-client.ts"],"sourcesContent":["import type { AnalyticsEvents } from \"./events\";\nimport { lambdaClient, parseAndWarnTelemetryId } from \"@copilotkit/shared\";\nimport * as packageJson from \"../../../../package.json\";\n\nexport function isTelemetryDisabled(): boolean {\n return (\n (process.env as Record<string, string | undefined>)\n .COPILOTKIT_TELEMETRY_DISABLED === \"true\" ||\n (process.env as Record<string, string | undefined>)\n .COPILOTKIT_TELEMETRY_DISABLED === \"1\" ||\n (process.env as Record<string, string | undefined>).DO_NOT_TRACK ===\n \"true\" ||\n (process.env as Record<string, string | undefined>).DO_NOT_TRACK === \"1\"\n );\n}\n\nexport class TelemetryClient {\n private telemetryDisabled: boolean = false;\n // Client-side sampling rate for anonymous events. Identified callers\n // (license token with telemetry_id) bypass the gate. Default 0.05\n // caps anonymous OSS-runtime egress; identified customers send at\n // full fidelity. Override via COPILOTKIT_TELEMETRY_SAMPLE_RATE.\n private sampleRate: number = 0.05;\n // EIP / Intelligence license token (Ed25519-signed JWT). The lambda\n // client decodes its payload to read telemetry_id for the\n // X-CopilotKit-Telemetry-Id header. Set once at runtime construction\n // via setLicenseToken; absent values produce anonymous sends.\n private licenseToken: string | null = null;\n // Parsed telemetry_id from the license-token JWT payload. Cached at\n // setLicenseToken time so `capture()` can branch on identified vs\n // anonymous without re-parsing per event. Null when the token is\n // absent or yielded no telemetry_id.\n private telemetryId: string | null = null;\n\n constructor({\n telemetryDisabled,\n sampleRate,\n }: {\n telemetryDisabled?: boolean;\n sampleRate?: number;\n } = {}) {\n this.telemetryDisabled = telemetryDisabled ?? isTelemetryDisabled();\n this.setSampleRate(sampleRate);\n }\n\n private shouldSendEvent() {\n if (this.sampleRate >= 1) return true;\n return Math.random() < this.sampleRate;\n }\n\n setLicenseToken(licenseToken: string) {\n this.licenseToken = licenseToken;\n this.telemetryId = parseAndWarnTelemetryId(licenseToken);\n }\n\n async capture<K extends keyof AnalyticsEvents>(\n event: K,\n properties: AnalyticsEvents[K],\n ) {\n if (this.telemetryDisabled) return;\n // Anonymous callers are gated by sampleRate; identified callers\n // (telemetry_id present) bypass the gate and always send.\n if (!this.telemetryId && !this.shouldSendEvent()) return;\n\n await lambdaClient.send({\n event,\n properties: properties as Record<string, unknown>,\n packageName: packageJson.name,\n packageVersion: packageJson.version,\n licenseToken: this.licenseToken ?? undefined,\n });\n }\n\n private setSampleRate(sampleRate: number | undefined) {\n let _sampleRate: number;\n\n _sampleRate = sampleRate ?? 0.05;\n\n if (process.env.COPILOTKIT_TELEMETRY_SAMPLE_RATE) {\n _sampleRate = parseFloat(process.env.COPILOTKIT_TELEMETRY_SAMPLE_RATE);\n }\n\n // Number.isNaN guards against parseFloat(\"nonsense\") slipping past the\n // range check (all NaN comparisons are false), which would silently\n // drop every anonymous event with no signal.\n if (Number.isNaN(_sampleRate) || _sampleRate < 0 || _sampleRate > 1) {\n throw new Error(\"Sample rate must be between 0 and 1\");\n }\n\n this.sampleRate = _sampleRate;\n }\n}\n\nconst telemetry = new TelemetryClient();\nexport default telemetry;\n"],"mappings":";;;;;;;AAIA,SAAgBA,wBAA+B;AAC7C,QACG,QAAQ,IACN,kCAAkC,UACpC,QAAQ,IACN,kCAAkC,OACpC,QAAQ,IAA2C,iBAClD,UACD,QAAQ,IAA2C,iBAAiB;;AAIzE,IAAaC,oBAAb,MAA6B;CAkB3B,YAAY,EACV,mBACA,eAIE,EAAE,EAAE;2BAvB6B;oBAKR;sBAKS;qBAKD;AASnC,OAAK,oBAAoB,qBAAqBD,uBAAqB;AACnE,OAAK,cAAc,WAAW;;CAGhC,AAAQ,kBAAkB;AACxB,MAAI,KAAK,cAAc,EAAG,QAAO;AACjC,SAAO,KAAK,QAAQ,GAAG,KAAK;;CAG9B,gBAAgB,cAAsB;AACpC,OAAK,eAAe;AACpB,OAAK,cAAc,wBAAwB,aAAa;;CAG1D,MAAM,QACJ,OACA,YACA;AACA,MAAI,KAAK,kBAAmB;AAG5B,MAAI,CAAC,KAAK,eAAe,CAAC,KAAK,iBAAiB,CAAE;AAElD,QAAM,aAAa,KAAK;GACtB;GACY;GACZ,aAAaE,eAAY;GACzB,gBAAgBA,eAAY;GAC5B,cAAc,KAAK,gBAAgB;GACpC,CAAC;;CAGJ,AAAQ,cAAc,YAAgC;EACpD,IAAI;AAEJ,gBAAc,cAAc;AAE5B,MAAI,QAAQ,IAAI,iCACd,eAAc,WAAW,QAAQ,IAAI,iCAAiC;AAMxE,MAAI,OAAO,MAAM,YAAY,IAAI,cAAc,KAAK,cAAc,EAChE,OAAM,IAAI,MAAM,sCAAsC;AAGxD,OAAK,aAAa;;;AAItB,MAAM,YAAY,IAAID,mBAAiB"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@copilotkit/runtime",
3
- "version": "1.57.2",
3
+ "version": "1.57.4",
4
4
  "private": false,
5
5
  "keywords": [
6
6
  "ai",
@@ -12,6 +12,7 @@
12
12
  "nextjs",
13
13
  "nodejs",
14
14
  "react",
15
+ "tanstack-intent",
15
16
  "textarea"
16
17
  ],
17
18
  "homepage": "https://github.com/CopilotKit/CopilotKit",
@@ -20,6 +21,10 @@
20
21
  "type": "git",
21
22
  "url": "https://github.com/CopilotKit/CopilotKit.git"
22
23
  },
24
+ "files": [
25
+ "dist",
26
+ "skills"
27
+ ],
23
28
  "sideEffects": [
24
29
  "./dist/index.mjs",
25
30
  "./dist/index.cjs",
@@ -29,22 +34,6 @@
29
34
  "main": "./dist/index.cjs",
30
35
  "module": "./dist/index.mjs",
31
36
  "types": "./dist/index.d.cts",
32
- "typesVersions": {
33
- "*": {
34
- "v2": [
35
- "./dist/v2/index.d.cts"
36
- ],
37
- "v2/express": [
38
- "./dist/v2/express.d.cts"
39
- ],
40
- "v2/hono": [
41
- "./dist/v2/hono.d.cts"
42
- ],
43
- "v2/node": [
44
- "./dist/v2/node.d.cts"
45
- ]
46
- }
47
- },
48
37
  "exports": {
49
38
  ".": {
50
39
  "import": "./dist/index.mjs",
@@ -115,11 +104,12 @@
115
104
  "uuid": "^10.0.0",
116
105
  "ws": "^8.18.0",
117
106
  "zod": "^3.23.3",
118
- "@copilotkit/shared": "1.57.2"
107
+ "@copilotkit/shared": "1.57.4"
119
108
  },
120
109
  "devDependencies": {
121
110
  "@copilotkit/aimock": "latest",
122
111
  "@swc/core": "1.5.28",
112
+ "@tanstack/intent": "^0.0.29",
123
113
  "@types/cors": "^2.8.17",
124
114
  "@types/express": "^4.17.21",
125
115
  "@types/node": "^18.11.17",
@@ -0,0 +1,98 @@
1
+ ---
2
+ name: runtime
3
+ description: >
4
+ @copilotkit/runtime — mount a fetch-native CopilotRuntime on any JS server, wire
5
+ middleware, pick an AgentRunner, instantiate BuiltInAgent (Factory Mode with TanStack AI
6
+ is the preferred default) or plug in any of 12 external agent frameworks (Mastra,
7
+ LangGraph, CrewAI Crews/Flows, PydanticAI, ADK, LlamaIndex, Agno, AWS Strands, MS Agent
8
+ Framework, AG2, A2A), enable Intelligence mode for durable threads + websocket,
9
+ register server-side tools via defineTool, and wire voice transcription. Uses the
10
+ fetch-based createCopilotRuntimeHandler primitive — the Express/Hono adapters are
11
+ discouraged. Load the reference under references/ that matches your task.
12
+ type: core
13
+ library: copilotkit
14
+ library_version: "1.56.2"
15
+ requires: []
16
+ sources:
17
+ - "CopilotKit/CopilotKit:packages/runtime/src/v2/runtime/core/fetch-handler.ts"
18
+ - "CopilotKit/CopilotKit:packages/runtime/src/v2/runtime/core/runtime.ts"
19
+ - "CopilotKit/CopilotKit:packages/runtime/src/v2/runtime/core/hooks.ts"
20
+ - "CopilotKit/CopilotKit:packages/runtime/src/v2/runtime/core/middleware.ts"
21
+ - "CopilotKit/CopilotKit:packages/runtime/src/v2/runtime/runner/agent-runner.ts"
22
+ - "CopilotKit/CopilotKit:packages/runtime/src/v2/runtime/runner/in-memory.ts"
23
+ - "CopilotKit/CopilotKit:packages/runtime/src/v2/runtime/runner/intelligence.ts"
24
+ - "CopilotKit/CopilotKit:packages/runtime/src/v2/runtime/intelligence-platform/client.ts"
25
+ - "CopilotKit/CopilotKit:packages/runtime/src/v2/runtime/transcription-service/transcription-service.ts"
26
+ - "CopilotKit/CopilotKit:packages/runtime/src/v2/runtime/handlers/handle-transcribe.ts"
27
+ - "CopilotKit/CopilotKit:packages/runtime/src/agent/index.ts"
28
+ - "CopilotKit/CopilotKit:packages/runtime/src/agent/converters/tanstack.ts"
29
+ - "CopilotKit/CopilotKit:packages/sqlite-runner/src/sqlite-runner.ts"
30
+ - "CopilotKit/CopilotKit:packages/shared/src/transcription-errors.ts"
31
+ ---
32
+
33
+ # CopilotKit Runtime
34
+
35
+ `@copilotkit/runtime` is the server half of CopilotKit: it accepts AG-UI protocol
36
+ requests, dispatches them to an `AbstractAgent` (built-in or external), runs the
37
+ stream through an `AgentRunner`, and responds as Server-Sent Events.
38
+
39
+ This SKILL.md is the **index**. Read the reference under `references/` that matches
40
+ your task — do not try to absorb the whole package from this file.
41
+
42
+ ## Mental Model — the three dictionaries you hand to `CopilotRuntime`
43
+
44
+ ```ts
45
+ new CopilotRuntime({
46
+ agents, // Record<string, AbstractAgent> — see wiring-external-agents or built-in-agent
47
+ runner, // AgentRunner (optional) — see agent-runners
48
+ intelligence, // CopilotKitIntelligence (optional) — see intelligence-mode (auto-wires runner)
49
+ mcpApps, // McpAppsConfig (optional) — see wiring-mcp-apps-middleware
50
+ a2ui, // A2UIConfig (optional) — see packages/a2ui-renderer skill
51
+ hooks, // { onRequest, onBeforeHandler } — see middleware
52
+ beforeRequestMiddleware,
53
+ afterRequestMiddleware, // legacy — see middleware
54
+ transcription, // TranscriptionService (optional) — see transcription
55
+ });
56
+ ```
57
+
58
+ You then mount it:
59
+
60
+ ```ts
61
+ import { createCopilotRuntimeHandler } from "@copilotkit/runtime/v2";
62
+ const handler = createCopilotRuntimeHandler({
63
+ runtime,
64
+ basePath: "/api/copilotkit",
65
+ });
66
+ export default { fetch: handler };
67
+ ```
68
+
69
+ ## When to load which reference
70
+
71
+ | Task | Reference |
72
+ | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
73
+ | Mounting on any fetch-native server (Cloudflare Workers, Bun, Deno, Vercel Edge, Next.js App Router, React Router v7, TanStack Start) or delegating from Express/Node | `references/setup-endpoint.md` |
74
+ | Auth / logging / rate-limit / request-scoped guards via `hooks.onRequest` / `hooks.onBeforeHandler` (preferred) or legacy `beforeRequestMiddleware` / `afterRequestMiddleware` | `references/middleware.md` |
75
+ | Choosing between `InMemoryAgentRunner`, `SqliteAgentRunner`, or a custom subclass — including thread-locking semantics and the runner/Intelligence mutual exclusion | `references/agent-runners.md` (+ `-in-memory.md`, `-sqlite.md`, `-custom.md` for backend-specific detail) |
76
+ | Enabling durable threads + realtime websocket via CopilotKit Cloud (Intelligence is **Cloud-only**, not self-hostable) | `references/intelligence-mode.md` |
77
+ | Voice transcription — implementing a `TranscriptionService` subclass for the `/transcribe` endpoint | `references/transcription.md` |
78
+ | Instantiating `BuiltInAgent` — Simple Mode (classic) or Factory Mode with TanStack AI (preferred AG-UI-compliant default), AI SDK, or custom factory | `references/built-in-agent.md` (+ `-factory-modes.md`, `-helper-utilities.md`, `-model-identifiers.md`) |
79
+ | Defining server-side tools via `defineTool` for `BuiltInAgent.config.tools` (Simple Mode only) | `references/server-side-tools.md` |
80
+ | Wiring an external agent framework into `CopilotRuntime({ agents })` | `references/wiring-external-agents.md` (index) + per-framework refs (`wiring-mastra.md`, `wiring-langgraph.md`, `wiring-crewai-crews.md`, `wiring-crewai-flows.md`, `wiring-pydantic-ai.md`, `wiring-adk.md`, `wiring-llamaindex.md`, `wiring-agno.md`, `wiring-aws-strands.md`, `wiring-ms-agent-framework.md`, `wiring-ag2.md`, `wiring-a2a.md`) |
81
+ | Wiring MCP Apps (runtime-level middleware, not an agent) | `references/wiring-mcp-apps-middleware.md` |
82
+
83
+ ## Invariants and gotchas (load-once, before any reference)
84
+
85
+ - `createCopilotRuntimeHandler` is the canonical primitive. `createCopilotExpressHandler` / `createCopilotHonoHandler` exist but are **avoid at all costs** — delegate from Express/Hono routes to the fetch primitive instead.
86
+ - `publicLicenseKey` is the canonical provider-side field. `publicApiKey` is a **deprecated alias** — expect to see it in legacy code, emit the canonical name in new code.
87
+ - Intelligence mode auto-wires `IntelligenceAgentRunner`. Passing both `runner` and `intelligence` to `CopilotRuntime` is rejected at construction.
88
+ - Intelligence mode targets CopilotKit Cloud (`api.cloud.copilotkit.ai`) and is **not self-hostable**.
89
+ - `hooks.onRequest` runs **before** `beforeRequestMiddleware` (hook-based middleware wins for Response short-circuits). `beforeRequestMiddleware` runs **after** `hooks.onRequest` (see `fetch-handler.ts:136-147`).
90
+ - `identifyUser` (Intelligence) does **not** forward thrown `Response` objects — convert to 500. Gate auth rejection in `hooks.onRequest`, which does forward Responses.
91
+ - `agents__unsafe_dev_only` and `selfManagedAgents` are dev-only aliases of each other; do not reach for them in production. Either signals that the SPA is in dev mode.
92
+
93
+ ## Reading order for a first-time reader
94
+
95
+ 1. `setup-endpoint` — the primitive.
96
+ 2. `built-in-agent` **or** pick one from `wiring-external-agents` — the agent.
97
+ 3. `agent-runners` — production persistence choice.
98
+ 4. Optional: `middleware`, `intelligence-mode`, `server-side-tools`, `transcription`.
@@ -0,0 +1,161 @@
1
+ Custom AgentRunner — subclass the abstract `AgentRunner` to back thread state with Redis,
2
+ Postgres, Durable Objects, or anything else you own.
3
+
4
+ ## The abstract contract
5
+
6
+ ```typescript
7
+ // packages/runtime/src/v2/runtime/runner/agent-runner.ts
8
+ import {
9
+ AbstractAgent,
10
+ BaseEvent,
11
+ Message,
12
+ RunAgentInput,
13
+ } from "@ag-ui/client";
14
+ import { Observable } from "rxjs";
15
+
16
+ export interface AgentRunnerRunRequest {
17
+ threadId: string;
18
+ agent: AbstractAgent;
19
+ input: RunAgentInput;
20
+ joinCode?: string;
21
+ persistedInputMessages?: Message[];
22
+ }
23
+ export interface AgentRunnerConnectRequest {
24
+ threadId: string;
25
+ headers?: Record<string, string>;
26
+ joinCode?: string;
27
+ }
28
+ export interface AgentRunnerIsRunningRequest {
29
+ threadId: string;
30
+ }
31
+ export interface AgentRunnerStopRequest {
32
+ threadId: string;
33
+ }
34
+
35
+ export abstract class AgentRunner {
36
+ abstract run(request: AgentRunnerRunRequest): Observable<BaseEvent>;
37
+ abstract connect(request: AgentRunnerConnectRequest): Observable<BaseEvent>;
38
+ abstract isRunning(request: AgentRunnerIsRunningRequest): Promise<boolean>;
39
+ abstract stop(request: AgentRunnerStopRequest): Promise<boolean | undefined>;
40
+ }
41
+ ```
42
+
43
+ ## Redis-backed skeleton (for reference)
44
+
45
+ ```typescript
46
+ import { AgentRunner } from "@copilotkit/runtime/v2";
47
+ import type {
48
+ AgentRunnerRunRequest,
49
+ AgentRunnerConnectRequest,
50
+ AgentRunnerIsRunningRequest,
51
+ AgentRunnerStopRequest,
52
+ } from "@copilotkit/runtime/v2";
53
+ import { Observable, ReplaySubject } from "rxjs";
54
+ import type { BaseEvent } from "@ag-ui/client";
55
+ import { Redis } from "ioredis";
56
+
57
+ const RUNNING_KEY = (t: string) => `copilotkit:running:${t}`;
58
+ const STREAM_KEY = (t: string) => `copilotkit:stream:${t}`;
59
+
60
+ export class RedisAgentRunner extends AgentRunner {
61
+ constructor(private redis: Redis) {
62
+ super();
63
+ }
64
+
65
+ run(request: AgentRunnerRunRequest): Observable<BaseEvent> {
66
+ const { threadId, agent, input } = request;
67
+ const subject = new ReplaySubject<BaseEvent>();
68
+
69
+ (async () => {
70
+ // NX guard — return 409-equivalent if another instance is running this thread
71
+ const acquired = await this.redis.set(
72
+ RUNNING_KEY(threadId),
73
+ "1",
74
+ "EX",
75
+ 600,
76
+ "NX",
77
+ );
78
+ if (!acquired) {
79
+ subject.error(new Error("Thread already running"));
80
+ return;
81
+ }
82
+
83
+ const sub = agent.run(input).subscribe({
84
+ next: async (event) => {
85
+ subject.next(event);
86
+ await this.redis.xadd(
87
+ STREAM_KEY(threadId),
88
+ "*",
89
+ "event",
90
+ JSON.stringify(event),
91
+ );
92
+ },
93
+ error: async (err) => {
94
+ subject.error(err);
95
+ await this.redis.del(RUNNING_KEY(threadId));
96
+ },
97
+ complete: async () => {
98
+ subject.complete();
99
+ await this.redis.del(RUNNING_KEY(threadId));
100
+ },
101
+ });
102
+
103
+ // stop hook
104
+ this.stopHandlers.set(threadId, () => sub.unsubscribe());
105
+ })();
106
+
107
+ return subject.asObservable();
108
+ }
109
+
110
+ connect(request: AgentRunnerConnectRequest): Observable<BaseEvent> {
111
+ const subject = new ReplaySubject<BaseEvent>();
112
+ (async () => {
113
+ const entries = await this.redis.xrange(
114
+ STREAM_KEY(request.threadId),
115
+ "-",
116
+ "+",
117
+ );
118
+ for (const [, fields] of entries) {
119
+ const eventStr = fields[1];
120
+ if (eventStr) subject.next(JSON.parse(eventStr));
121
+ }
122
+ subject.complete();
123
+ })();
124
+ return subject.asObservable();
125
+ }
126
+
127
+ async isRunning(request: AgentRunnerIsRunningRequest): Promise<boolean> {
128
+ return (await this.redis.exists(RUNNING_KEY(request.threadId))) === 1;
129
+ }
130
+
131
+ async stop(request: AgentRunnerStopRequest): Promise<boolean | undefined> {
132
+ const stop = this.stopHandlers.get(request.threadId);
133
+ if (stop) {
134
+ stop();
135
+ this.stopHandlers.delete(request.threadId);
136
+ }
137
+ await this.redis.del(RUNNING_KEY(request.threadId));
138
+ return true;
139
+ }
140
+
141
+ private stopHandlers = new Map<string, () => void>();
142
+ }
143
+ ```
144
+
145
+ ## Contract gotchas
146
+
147
+ - `run()` must throw `Error("Thread already running")` (or let a distributed lock return a
148
+ non-acquired state) when a run is already active. Intelligence mode surfaces the 409 to
149
+ the client as the typed `agent_thread_locked` error code; SSE mode (direct runner use)
150
+ only emits a generic 500 response with the error message — so clients cannot depend on
151
+ the typed code there, and should additionally guard with a busy flag on submit.
152
+ - `connect()` must replay historic events so late clients can catch up on an active run.
153
+ - `stop()` is optional to implement in the sense that returning `undefined` is allowed, but
154
+ surface cancellations through `abortController.abort()` to the underlying agent if you can.
155
+ - The runner does not persist user messages on its own — that is the Intelligence platform's
156
+ job. A custom runner that persists only its own event stream is still a drop-in replacement
157
+ for `InMemoryAgentRunner` / `SqliteAgentRunner`.
158
+
159
+ Source: `packages/runtime/src/v2/runtime/runner/agent-runner.ts`,
160
+ `packages/runtime/src/v2/runtime/runner/in-memory.ts`,
161
+ `packages/sqlite-runner/src/sqlite-runner.ts`.
@@ -0,0 +1,64 @@
1
+ InMemoryAgentRunner — default ephemeral runner. Keyed on a `globalThis` Symbol so thread state survives hot-module reloads during development.
2
+
3
+ ## Store layout
4
+
5
+ ```typescript
6
+ // packages/runtime/src/v2/runtime/runner/in-memory.ts
7
+ const GLOBAL_STORE_KEY = Symbol.for("@copilotkit/runtime/in-memory-store");
8
+
9
+ interface GlobalStoreData {
10
+ stores: Map<string, InMemoryEventStore>; // per-threadId
11
+ historicRunsBackup: Map<string, HistoricRun[]>; // restored after HMR
12
+ }
13
+ ```
14
+
15
+ One `InMemoryEventStore` per `threadId`. Each store tracks:
16
+
17
+ - `subject: ReplaySubject<BaseEvent> | null` — current consumers
18
+ - `isRunning: boolean` — gate for the `"Thread already running"` throw
19
+ - `currentRunId: string | null`
20
+ - `historicRuns: HistoricRun[]` — completed runs (backed up across HMR)
21
+ - `agent: AbstractAgent | null` — the instance that owns the active run
22
+ - `runSubject`, `currentEvents`, `stopRequested`
23
+
24
+ ## Lifecycle
25
+
26
+ 1. `run({ threadId, agent, input })` — if `store.isRunning` throw `Error("Thread already running")`. Otherwise create a `ReplaySubject`, subscribe to `agent.run(input)`, push events into the subject, track them in `currentEvents`, mark the store `isRunning`.
27
+ 2. On `RunFinishedEvent` / `RunErrorEvent`: finalize the run, push its events into `historicRuns`, clear `isRunning`, `currentRunId`, `agent`.
28
+ 3. `connect({ threadId })` — returns a `ReplaySubject` that replays the active run events or (if no active run) the most recent historic run.
29
+ 4. `stop({ threadId })` — sets `stopRequested = true`; the active subscription checks the flag on each event and tears down.
30
+
31
+ ## Hot reload (development)
32
+
33
+ In dev, bundlers replace modules. `GLOBAL_STORE_KEY` uses `Symbol.for(...)` so the same well-known symbol is reused across module instances — `globalThis[KEY]` survives. On module re-evaluation, if the `stores` map is empty but `historicRunsBackup` still has entries, the runner rehydrates historic-only stores from the backup (active runs are lost, historic runs come back).
34
+
35
+ ## When NOT to use
36
+
37
+ - Multi-instance production deploys — each process has its own store.
38
+ - Long-lived servers — restart wipes active threads (historic runs are only preserved in the HMR-dev backup, not across process exit).
39
+ - Load-balanced serverless with cold starts — new workers see empty stores.
40
+
41
+ ## When it is OK
42
+
43
+ - Local development.
44
+ - Single-instance preview environments.
45
+ - Tests (each `new InMemoryAgentRunner()` still shares the globalThis store — pass a fresh threadId per test, or clear the captured store in place between tests). Do NOT `delete globalThis[Symbol.for("@copilotkit/runtime/in-memory-store")]`: `in-memory.ts:98` captures `GLOBAL_STORE = getGlobalStore()` as a module-level const referencing the inner `stores` Map, so replacing `globalThis[KEY]` creates a new object that the module no longer consults. Mutate the existing maps in place:
46
+
47
+ ```ts
48
+ // test setup
49
+ const storeKey = Symbol.for("@copilotkit/runtime/in-memory-store");
50
+ const data = (globalThis as any)[storeKey] as
51
+ | {
52
+ stores: Map<string, unknown>;
53
+ historicRunsBackup: Map<string, unknown>;
54
+ }
55
+ | undefined;
56
+ if (data) {
57
+ data.stores.clear();
58
+ data.historicRunsBackup.clear();
59
+ }
60
+ ```
61
+
62
+ The runtime does not yet expose an official reset helper — a `__TEST_ONLY_clearGlobalStore` export would be a reasonable follow-up.
63
+
64
+ Source: `packages/runtime/src/v2/runtime/runner/in-memory.ts`.
@@ -0,0 +1,90 @@
1
+ SqliteAgentRunner — file-backed agent runner in `@copilotkit/sqlite-runner`. Uses `better-sqlite3` as a required peer dep.
2
+
3
+ ## Install
4
+
5
+ ```bash
6
+ pnpm add @copilotkit/sqlite-runner better-sqlite3
7
+ ```
8
+
9
+ If `better-sqlite3` is missing, the `import` of `@copilotkit/sqlite-runner` itself fails
10
+ at module load (`Cannot find module 'better-sqlite3'`). The runner's constructor has a
11
+ friendlier multi-line install hint as a fallback, but you will see the bare resolution
12
+ error first — install the peer before the runner import resolves.
13
+
14
+ ## Configure
15
+
16
+ ```typescript
17
+ import { CopilotRuntime } from "@copilotkit/runtime/v2";
18
+ import { SqliteAgentRunner } from "@copilotkit/sqlite-runner";
19
+
20
+ const runtime = new CopilotRuntime({
21
+ agents: {
22
+ /* ... */
23
+ } as any,
24
+ runner: new SqliteAgentRunner({
25
+ dbPath: "./data/threads.db", // REQUIRED — default is ":memory:"
26
+ }),
27
+ });
28
+ ```
29
+
30
+ `dbPath: ":memory:"` is the default if omitted — that reverts to an in-memory store and
31
+ loses data at restart. Always set a file path in production.
32
+
33
+ ## Schema
34
+
35
+ Three tables are created on first use (`packages/sqlite-runner/src/sqlite-runner.ts:75-109`):
36
+
37
+ ```sql
38
+ CREATE TABLE IF NOT EXISTS agent_runs (
39
+ id INTEGER PRIMARY KEY AUTOINCREMENT,
40
+ thread_id TEXT NOT NULL,
41
+ run_id TEXT NOT NULL UNIQUE,
42
+ parent_run_id TEXT,
43
+ events TEXT NOT NULL, -- JSON-encoded BaseEvent[]
44
+ input TEXT NOT NULL, -- JSON-encoded RunAgentInput
45
+ created_at INTEGER NOT NULL,
46
+ version INTEGER NOT NULL
47
+ );
48
+ CREATE TABLE IF NOT EXISTS run_state (
49
+ thread_id TEXT PRIMARY KEY,
50
+ is_running INTEGER DEFAULT 0,
51
+ current_run_id TEXT,
52
+ updated_at INTEGER NOT NULL
53
+ );
54
+ CREATE TABLE IF NOT EXISTS schema_version (
55
+ version INTEGER PRIMARY KEY,
56
+ applied_at INTEGER NOT NULL
57
+ );
58
+ CREATE INDEX IF NOT EXISTS idx_thread_id ON agent_runs(thread_id);
59
+ CREATE INDEX IF NOT EXISTS idx_parent_run_id ON agent_runs(parent_run_id);
60
+ ```
61
+
62
+ `agent_runs` is append-only — one row per completed run, full event log in the `events`
63
+ column. `run_state` gates concurrent runs (the `"Thread already running"` check).
64
+ `schema_version` tracks applied migrations so future releases can upgrade existing
65
+ databases in place.
66
+
67
+ ## Retention
68
+
69
+ There is no automatic retention. If you need bounded history, add a periodic purge:
70
+
71
+ ```typescript
72
+ import Database from "better-sqlite3";
73
+
74
+ const db = new Database("./data/threads.db");
75
+ setInterval(
76
+ () => {
77
+ const cutoff = Date.now() - 30 * 24 * 60 * 60 * 1000; // 30 days
78
+ db.prepare("DELETE FROM agent_runs WHERE created_at < ?").run(cutoff);
79
+ },
80
+ 60 * 60 * 1000,
81
+ );
82
+ ```
83
+
84
+ ## When NOT to use
85
+
86
+ - Multi-instance deploys without shared storage — each instance would have its own DB file.
87
+ Either put the DB on a shared volume (EFS, persistent disk) with a single writer, or
88
+ choose Intelligence mode or a custom Redis/Postgres runner.
89
+
90
+ Source: `packages/sqlite-runner/src/sqlite-runner.ts`.