@copilotkit/runtime 1.57.3 → 1.58.0-canary.thread-id-propagation

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 (346) hide show
  1. package/dist/lib/observability.d.cts +1 -1
  2. package/dist/lib/observability.d.cts.map +1 -1
  3. package/dist/lib/observability.d.mts +1 -1
  4. package/dist/lib/observability.d.mts.map +1 -1
  5. package/dist/lib/runtime/copilot-runtime.cjs +2 -0
  6. package/dist/lib/runtime/copilot-runtime.cjs.map +1 -1
  7. package/dist/lib/runtime/copilot-runtime.d.cts.map +1 -1
  8. package/dist/lib/runtime/copilot-runtime.d.mts.map +1 -1
  9. package/dist/lib/runtime/copilot-runtime.mjs +2 -0
  10. package/dist/lib/runtime/copilot-runtime.mjs.map +1 -1
  11. package/dist/package.cjs +5 -8
  12. package/dist/package.mjs +5 -8
  13. package/dist/v2/runtime/core/runtime.cjs +4 -1
  14. package/dist/v2/runtime/core/runtime.cjs.map +1 -1
  15. package/dist/v2/runtime/core/runtime.d.cts.map +1 -1
  16. package/dist/v2/runtime/core/runtime.d.mts.map +1 -1
  17. package/dist/v2/runtime/core/runtime.mjs +4 -1
  18. package/dist/v2/runtime/core/runtime.mjs.map +1 -1
  19. package/dist/v2/runtime/handlers/get-runtime-info.cjs +1 -1
  20. package/dist/v2/runtime/handlers/get-runtime-info.mjs +1 -1
  21. package/dist/v2/runtime/handlers/handle-connect.cjs +1 -1
  22. package/dist/v2/runtime/handlers/handle-connect.mjs +1 -1
  23. package/dist/v2/runtime/handlers/handle-run.cjs +1 -1
  24. package/dist/v2/runtime/handlers/handle-run.mjs +1 -1
  25. package/dist/v2/runtime/handlers/shared/agent-utils.cjs +1 -1
  26. package/dist/v2/runtime/handlers/shared/agent-utils.cjs.map +1 -1
  27. package/dist/v2/runtime/handlers/shared/agent-utils.mjs +1 -1
  28. package/dist/v2/runtime/handlers/shared/agent-utils.mjs.map +1 -1
  29. package/dist/v2/runtime/telemetry/telemetry-client.cjs +22 -6
  30. package/dist/v2/runtime/telemetry/telemetry-client.cjs.map +1 -1
  31. package/dist/v2/runtime/telemetry/telemetry-client.mjs +27 -11
  32. package/dist/v2/runtime/telemetry/telemetry-client.mjs.map +1 -1
  33. package/package.json +9 -19
  34. package/skills/runtime/SKILL.md +98 -0
  35. package/skills/runtime/references/agent-runners-custom.md +161 -0
  36. package/skills/runtime/references/agent-runners-in-memory.md +64 -0
  37. package/skills/runtime/references/agent-runners-sqlite.md +90 -0
  38. package/skills/runtime/references/agent-runners.md +304 -0
  39. package/skills/runtime/references/built-in-agent-factory-modes.md +232 -0
  40. package/skills/runtime/references/built-in-agent-helper-utilities.md +123 -0
  41. package/skills/runtime/references/built-in-agent-model-identifiers.md +59 -0
  42. package/skills/runtime/references/built-in-agent.md +523 -0
  43. package/skills/runtime/references/intelligence-mode.md +336 -0
  44. package/skills/runtime/references/middleware.md +376 -0
  45. package/skills/runtime/references/server-side-tools.md +414 -0
  46. package/skills/runtime/references/setup-endpoint.md +503 -0
  47. package/skills/runtime/references/transcription.md +287 -0
  48. package/skills/runtime/references/wiring-a2a.md +40 -0
  49. package/skills/runtime/references/wiring-adk.md +45 -0
  50. package/skills/runtime/references/wiring-ag2.md +41 -0
  51. package/skills/runtime/references/wiring-agno.md +39 -0
  52. package/skills/runtime/references/wiring-aws-strands.md +59 -0
  53. package/skills/runtime/references/wiring-crewai-crews.md +51 -0
  54. package/skills/runtime/references/wiring-crewai-flows.md +45 -0
  55. package/skills/runtime/references/wiring-external-agents.md +348 -0
  56. package/skills/runtime/references/wiring-langgraph.md +50 -0
  57. package/skills/runtime/references/wiring-llamaindex.md +39 -0
  58. package/skills/runtime/references/wiring-mastra.md +70 -0
  59. package/skills/runtime/references/wiring-mcp-apps-middleware.md +68 -0
  60. package/skills/runtime/references/wiring-ms-agent-framework.md +41 -0
  61. package/skills/runtime/references/wiring-pydantic-ai.md +45 -0
  62. package/CHANGELOG.md +0 -3624
  63. package/__snapshots__/schema/schema.graphql +0 -371
  64. package/dist/v2/runtime/telemetry/scarf-client.cjs +0 -32
  65. package/dist/v2/runtime/telemetry/scarf-client.cjs.map +0 -1
  66. package/dist/v2/runtime/telemetry/scarf-client.mjs +0 -32
  67. package/dist/v2/runtime/telemetry/scarf-client.mjs.map +0 -1
  68. package/scripts/generate-gql-schema.ts +0 -16
  69. package/src/agent/__tests__/agent-test-helpers.ts +0 -476
  70. package/src/agent/__tests__/agent.test.ts +0 -593
  71. package/src/agent/__tests__/ai-sdk-v6-compat.test.ts +0 -116
  72. package/src/agent/__tests__/basic-agent.test.ts +0 -1698
  73. package/src/agent/__tests__/capabilities.test.ts +0 -81
  74. package/src/agent/__tests__/config-tools-execution.test.ts +0 -516
  75. package/src/agent/__tests__/converter-aisdk.test.ts +0 -692
  76. package/src/agent/__tests__/converter-custom.test.ts +0 -319
  77. package/src/agent/__tests__/converter-tanstack-input.test.ts +0 -211
  78. package/src/agent/__tests__/converter-tanstack.test.ts +0 -594
  79. package/src/agent/__tests__/mcp-clients.test.ts +0 -246
  80. package/src/agent/__tests__/mcp-servers-integration.test.ts +0 -373
  81. package/src/agent/__tests__/multimodal-tanstack.test.ts +0 -284
  82. package/src/agent/__tests__/multimodal.test.ts +0 -176
  83. package/src/agent/__tests__/property-overrides.test.ts +0 -598
  84. package/src/agent/__tests__/provider-id-collision.test.ts +0 -195
  85. package/src/agent/__tests__/standard-schema-tools.test.ts +0 -313
  86. package/src/agent/__tests__/standard-schema-types.test.ts +0 -158
  87. package/src/agent/__tests__/state-tools.test.ts +0 -436
  88. package/src/agent/__tests__/test-helpers.ts +0 -197
  89. package/src/agent/__tests__/utils.test.ts +0 -536
  90. package/src/agent/__tests__/zod-regression.test.ts +0 -350
  91. package/src/agent/converters/aisdk.ts +0 -326
  92. package/src/agent/converters/index.ts +0 -7
  93. package/src/agent/converters/tanstack.ts +0 -451
  94. package/src/agent/index.ts +0 -1743
  95. package/src/agents/langgraph/__tests__/event-source.test.ts +0 -256
  96. package/src/agents/langgraph/event-source.ts +0 -365
  97. package/src/agents/langgraph/events.ts +0 -394
  98. package/src/graphql/inputs/action.input.ts +0 -16
  99. package/src/graphql/inputs/agent-session.input.ts +0 -13
  100. package/src/graphql/inputs/agent-state.input.ts +0 -13
  101. package/src/graphql/inputs/cloud-guardrails.input.ts +0 -16
  102. package/src/graphql/inputs/cloud.input.ts +0 -8
  103. package/src/graphql/inputs/context-property.input.ts +0 -10
  104. package/src/graphql/inputs/copilot-context.input.ts +0 -10
  105. package/src/graphql/inputs/custom-property.input.ts +0 -15
  106. package/src/graphql/inputs/extensions.input.ts +0 -21
  107. package/src/graphql/inputs/forwarded-parameters.input.ts +0 -22
  108. package/src/graphql/inputs/frontend.input.ts +0 -14
  109. package/src/graphql/inputs/generate-copilot-response.input.ts +0 -59
  110. package/src/graphql/inputs/load-agent-state.input.ts +0 -10
  111. package/src/graphql/inputs/message.input.ts +0 -110
  112. package/src/graphql/inputs/meta-event.input.ts +0 -18
  113. package/src/graphql/message-conversion/agui-to-gql.test.ts +0 -1384
  114. package/src/graphql/message-conversion/agui-to-gql.ts +0 -384
  115. package/src/graphql/message-conversion/gql-to-agui.test.ts +0 -1653
  116. package/src/graphql/message-conversion/gql-to-agui.ts +0 -297
  117. package/src/graphql/message-conversion/index.ts +0 -2
  118. package/src/graphql/message-conversion/roundtrip-conversion.test.ts +0 -561
  119. package/src/graphql/resolvers/__tests__/resolve-message-id.test.ts +0 -25
  120. package/src/graphql/resolvers/copilot.resolver.ts +0 -785
  121. package/src/graphql/resolvers/resolve-message-id.ts +0 -14
  122. package/src/graphql/resolvers/state.resolver.ts +0 -30
  123. package/src/graphql/types/agents-response.type.ts +0 -19
  124. package/src/graphql/types/base/index.ts +0 -10
  125. package/src/graphql/types/converted/index.ts +0 -183
  126. package/src/graphql/types/copilot-response.type.ts +0 -141
  127. package/src/graphql/types/enums.ts +0 -38
  128. package/src/graphql/types/extensions-response.type.ts +0 -23
  129. package/src/graphql/types/guardrails-result.type.ts +0 -20
  130. package/src/graphql/types/load-agent-state-response.type.ts +0 -17
  131. package/src/graphql/types/message-status.type.ts +0 -48
  132. package/src/graphql/types/meta-events.type.ts +0 -78
  133. package/src/graphql/types/response-status.type.ts +0 -77
  134. package/src/index.ts +0 -3
  135. package/src/langgraph.ts +0 -1
  136. package/src/lib/__tests__/telemetry-disclosure.test.ts +0 -55
  137. package/src/lib/cloud/index.ts +0 -4
  138. package/src/lib/error-messages.ts +0 -211
  139. package/src/lib/index.ts +0 -52
  140. package/src/lib/integrations/index.ts +0 -6
  141. package/src/lib/integrations/nest/index.ts +0 -21
  142. package/src/lib/integrations/nextjs/app-router.ts +0 -47
  143. package/src/lib/integrations/nextjs/pages-router.ts +0 -45
  144. package/src/lib/integrations/node-express/index.ts +0 -21
  145. package/src/lib/integrations/node-http/__tests__/request-duck-type.test.ts +0 -66
  146. package/src/lib/integrations/node-http/index.ts +0 -187
  147. package/src/lib/integrations/node-http/request-handler.ts +0 -128
  148. package/src/lib/integrations/shared.ts +0 -112
  149. package/src/lib/logger.ts +0 -31
  150. package/src/lib/observability.ts +0 -167
  151. package/src/lib/runtime/__tests__/copilot-runtime-error.test.ts +0 -183
  152. package/src/lib/runtime/__tests__/handle-service-adapter.test.ts +0 -108
  153. package/src/lib/runtime/__tests__/mcp-tools-utils.test.ts +0 -499
  154. package/src/lib/runtime/__tests__/on-after-request.test.ts +0 -122
  155. package/src/lib/runtime/__tests__/retry-utils.test.ts +0 -137
  156. package/src/lib/runtime/__tests__/v1-agent-factory.test.ts +0 -109
  157. package/src/lib/runtime/agent-integrations/langgraph/__tests__/dispatch-event-filtering.test.ts +0 -345
  158. package/src/lib/runtime/agent-integrations/langgraph/__tests__/run-message-filtering.test.ts +0 -156
  159. package/src/lib/runtime/agent-integrations/langgraph/agent.ts +0 -263
  160. package/src/lib/runtime/agent-integrations/langgraph/consts.ts +0 -37
  161. package/src/lib/runtime/agent-integrations/langgraph/index.ts +0 -2
  162. package/src/lib/runtime/copilot-runtime.ts +0 -863
  163. package/src/lib/runtime/mcp-tools-utils.ts +0 -313
  164. package/src/lib/runtime/retry-utils.ts +0 -141
  165. package/src/lib/runtime/telemetry-agent-runner.ts +0 -151
  166. package/src/lib/runtime/types.ts +0 -48
  167. package/src/lib/runtime/utils.ts +0 -93
  168. package/src/lib/streaming.ts +0 -220
  169. package/src/lib/telemetry-client.ts +0 -66
  170. package/src/lib/telemetry-disclosure.ts +0 -53
  171. package/src/service-adapters/anthropic/anthropic-adapter.ts +0 -532
  172. package/src/service-adapters/anthropic/utils.ts +0 -219
  173. package/src/service-adapters/bedrock/bedrock-adapter.ts +0 -73
  174. package/src/service-adapters/conversion.test.ts +0 -56
  175. package/src/service-adapters/conversion.ts +0 -69
  176. package/src/service-adapters/empty/empty-adapter.ts +0 -38
  177. package/src/service-adapters/events.ts +0 -337
  178. package/src/service-adapters/experimental/ollama/ollama-adapter.ts +0 -84
  179. package/src/service-adapters/google/google-genai-adapter.test.ts +0 -151
  180. package/src/service-adapters/google/google-genai-adapter.ts +0 -95
  181. package/src/service-adapters/groq/groq-adapter.ts +0 -229
  182. package/src/service-adapters/index.ts +0 -18
  183. package/src/service-adapters/langchain/langchain-adapter.ts +0 -113
  184. package/src/service-adapters/langchain/langserve.ts +0 -88
  185. package/src/service-adapters/langchain/types.ts +0 -20
  186. package/src/service-adapters/langchain/utils.ts +0 -330
  187. package/src/service-adapters/openai/__tests__/openai-v5-compat.test.ts +0 -177
  188. package/src/service-adapters/openai/openai-adapter.ts +0 -324
  189. package/src/service-adapters/openai/openai-assistant-adapter.ts +0 -385
  190. package/src/service-adapters/openai/utils.ts +0 -305
  191. package/src/service-adapters/service-adapter.ts +0 -50
  192. package/src/service-adapters/shared/error-utils.ts +0 -64
  193. package/src/service-adapters/shared/index.ts +0 -2
  194. package/src/service-adapters/shared/sdk-client-utils.ts +0 -19
  195. package/src/service-adapters/unify/unify-adapter.ts +0 -165
  196. package/src/utils/failed-response-status-reasons.ts +0 -70
  197. package/src/utils/index.ts +0 -1
  198. package/src/v2/express.ts +0 -1
  199. package/src/v2/hono.ts +0 -1
  200. package/src/v2/index.ts +0 -5
  201. package/src/v2/node.ts +0 -1
  202. package/src/v2/runtime/__tests__/agents-factory.test.ts +0 -136
  203. package/src/v2/runtime/__tests__/backward-compat.test.ts +0 -261
  204. package/src/v2/runtime/__tests__/code-review-fixes.test.ts +0 -500
  205. package/src/v2/runtime/__tests__/cors-credentials.test.ts +0 -320
  206. package/src/v2/runtime/__tests__/debug-sse-response.test.ts +0 -302
  207. package/src/v2/runtime/__tests__/express-adapter.test.ts +0 -188
  208. package/src/v2/runtime/__tests__/express-body-order.test.ts +0 -76
  209. package/src/v2/runtime/__tests__/express-fetch-bridge.test.ts +0 -344
  210. package/src/v2/runtime/__tests__/express-single-sse.test.ts +0 -122
  211. package/src/v2/runtime/__tests__/express-single-telemetry.integration.test.ts +0 -65
  212. package/src/v2/runtime/__tests__/express-telemetry.integration.test.ts +0 -101
  213. package/src/v2/runtime/__tests__/fetch-cors.test.ts +0 -205
  214. package/src/v2/runtime/__tests__/fetch-handler-validation.test.ts +0 -440
  215. package/src/v2/runtime/__tests__/fetch-handler.test.ts +0 -456
  216. package/src/v2/runtime/__tests__/fetch-router.test.ts +0 -276
  217. package/src/v2/runtime/__tests__/get-runtime-info.test.ts +0 -335
  218. package/src/v2/runtime/__tests__/handle-connect.test.ts +0 -585
  219. package/src/v2/runtime/__tests__/handle-run.test.ts +0 -1388
  220. package/src/v2/runtime/__tests__/handle-threads.test.ts +0 -930
  221. package/src/v2/runtime/__tests__/handle-transcribe.test.ts +0 -301
  222. package/src/v2/runtime/__tests__/header-utils.test.ts +0 -88
  223. package/src/v2/runtime/__tests__/hono-adapter.test.ts +0 -150
  224. package/src/v2/runtime/__tests__/hono-single-telemetry.integration.test.ts +0 -46
  225. package/src/v2/runtime/__tests__/hono-telemetry.integration.test.ts +0 -99
  226. package/src/v2/runtime/__tests__/hooks-edge-cases.test.ts +0 -457
  227. package/src/v2/runtime/__tests__/hooks.test.ts +0 -557
  228. package/src/v2/runtime/__tests__/in-process-agent-runner-messages.test.ts +0 -230
  229. package/src/v2/runtime/__tests__/in-process-agent-runner.test.ts +0 -1030
  230. package/src/v2/runtime/__tests__/integration/bun/bun-servers.integration.test.ts +0 -27
  231. package/src/v2/runtime/__tests__/integration/bun/elysia-multi.ts +0 -32
  232. package/src/v2/runtime/__tests__/integration/bun/elysia-single.ts +0 -33
  233. package/src/v2/runtime/__tests__/integration/bun/hono-bun-multi.ts +0 -25
  234. package/src/v2/runtime/__tests__/integration/bun/hono-bun-single.ts +0 -32
  235. package/src/v2/runtime/__tests__/integration/helpers/create-test-runtime.ts +0 -15
  236. package/src/v2/runtime/__tests__/integration/helpers/sse-reader.ts +0 -45
  237. package/src/v2/runtime/__tests__/integration/helpers/test-agent.ts +0 -58
  238. package/src/v2/runtime/__tests__/integration/node-servers.integration.test.ts +0 -58
  239. package/src/v2/runtime/__tests__/integration/servers/express-multi.ts +0 -35
  240. package/src/v2/runtime/__tests__/integration/servers/express-single.ts +0 -36
  241. package/src/v2/runtime/__tests__/integration/servers/fetch-direct.ts +0 -39
  242. package/src/v2/runtime/__tests__/integration/servers/hono-multi.ts +0 -30
  243. package/src/v2/runtime/__tests__/integration/servers/hono-single.ts +0 -37
  244. package/src/v2/runtime/__tests__/integration/servers/node-multi.ts +0 -45
  245. package/src/v2/runtime/__tests__/integration/servers/node-single.ts +0 -46
  246. package/src/v2/runtime/__tests__/integration/servers/types.ts +0 -18
  247. package/src/v2/runtime/__tests__/integration/suites/debug-events.suite.ts +0 -253
  248. package/src/v2/runtime/__tests__/integration/suites/multi-endpoint.suite.ts +0 -358
  249. package/src/v2/runtime/__tests__/integration/suites/single-endpoint.suite.ts +0 -363
  250. package/src/v2/runtime/__tests__/intelligence-run-telemetry.test.ts +0 -194
  251. package/src/v2/runtime/__tests__/mcp-apps-middleware-integration.test.ts +0 -275
  252. package/src/v2/runtime/__tests__/middleware-express.test.ts +0 -208
  253. package/src/v2/runtime/__tests__/middleware-single-express.test.ts +0 -213
  254. package/src/v2/runtime/__tests__/middleware-single.test.ts +0 -225
  255. package/src/v2/runtime/__tests__/middleware-sse-parser.test.ts +0 -237
  256. package/src/v2/runtime/__tests__/middleware.test.ts +0 -250
  257. package/src/v2/runtime/__tests__/node-fetch-handler.test.ts +0 -157
  258. package/src/v2/runtime/__tests__/open-generative-ui-middleware.e2e.test.ts +0 -728
  259. package/src/v2/runtime/__tests__/router-edge-cases.test.ts +0 -217
  260. package/src/v2/runtime/__tests__/routing-express.test.ts +0 -174
  261. package/src/v2/runtime/__tests__/routing-single-express.test.ts +0 -168
  262. package/src/v2/runtime/__tests__/routing-single.test.ts +0 -193
  263. package/src/v2/runtime/__tests__/routing.test.ts +0 -257
  264. package/src/v2/runtime/__tests__/runtime.test.ts +0 -234
  265. package/src/v2/runtime/__tests__/sse-response-telemetry.test.ts +0 -108
  266. package/src/v2/runtime/__tests__/telemetry.test.ts +0 -167
  267. package/src/v2/runtime/__tests__/thread-names.test.ts +0 -188
  268. package/src/v2/runtime/core/__tests__/debug-event-bus.test.ts +0 -156
  269. package/src/v2/runtime/core/debug-event-bus.ts +0 -45
  270. package/src/v2/runtime/core/fetch-cors.ts +0 -136
  271. package/src/v2/runtime/core/fetch-handler.ts +0 -492
  272. package/src/v2/runtime/core/fetch-router.ts +0 -203
  273. package/src/v2/runtime/core/hooks.ts +0 -160
  274. package/src/v2/runtime/core/middleware-sse-parser.ts +0 -210
  275. package/src/v2/runtime/core/middleware.ts +0 -115
  276. package/src/v2/runtime/core/runtime.ts +0 -432
  277. package/src/v2/runtime/endpoints/express-fetch-bridge.ts +0 -137
  278. package/src/v2/runtime/endpoints/express-single.ts +0 -54
  279. package/src/v2/runtime/endpoints/express.ts +0 -179
  280. package/src/v2/runtime/endpoints/hono-single.ts +0 -60
  281. package/src/v2/runtime/endpoints/hono.ts +0 -89
  282. package/src/v2/runtime/endpoints/index.ts +0 -4
  283. package/src/v2/runtime/endpoints/node-fetch-handler.ts +0 -48
  284. package/src/v2/runtime/endpoints/node.ts +0 -28
  285. package/src/v2/runtime/endpoints/single-route-helpers.ts +0 -125
  286. package/src/v2/runtime/express.ts +0 -2
  287. package/src/v2/runtime/handlers/__tests__/handle-debug-events.test.ts +0 -176
  288. package/src/v2/runtime/handlers/get-runtime-info.ts +0 -101
  289. package/src/v2/runtime/handlers/handle-connect.ts +0 -80
  290. package/src/v2/runtime/handlers/handle-debug-events.ts +0 -52
  291. package/src/v2/runtime/handlers/handle-run.ts +0 -111
  292. package/src/v2/runtime/handlers/handle-stop.ts +0 -77
  293. package/src/v2/runtime/handlers/handle-threads.ts +0 -11
  294. package/src/v2/runtime/handlers/handle-transcribe.ts +0 -269
  295. package/src/v2/runtime/handlers/header-utils.ts +0 -24
  296. package/src/v2/runtime/handlers/intelligence/connect.ts +0 -102
  297. package/src/v2/runtime/handlers/intelligence/run.ts +0 -351
  298. package/src/v2/runtime/handlers/intelligence/thread-names.ts +0 -246
  299. package/src/v2/runtime/handlers/intelligence/threads.ts +0 -420
  300. package/src/v2/runtime/handlers/shared/agent-utils.ts +0 -154
  301. package/src/v2/runtime/handlers/shared/intelligence-utils.ts +0 -41
  302. package/src/v2/runtime/handlers/shared/json-response.ts +0 -9
  303. package/src/v2/runtime/handlers/shared/resolve-intelligence-user.ts +0 -28
  304. package/src/v2/runtime/handlers/shared/sse-response.ts +0 -215
  305. package/src/v2/runtime/handlers/sse/__tests__/sse-connect-agent-id.test.ts +0 -71
  306. package/src/v2/runtime/handlers/sse/connect.ts +0 -30
  307. package/src/v2/runtime/handlers/sse/run.ts +0 -40
  308. package/src/v2/runtime/hono.ts +0 -2
  309. package/src/v2/runtime/index.ts +0 -51
  310. package/src/v2/runtime/intelligence-platform/__tests__/client.test.ts +0 -601
  311. package/src/v2/runtime/intelligence-platform/__tests__/intelligence-mcp-helper.test.ts +0 -246
  312. package/src/v2/runtime/intelligence-platform/client.ts +0 -818
  313. package/src/v2/runtime/intelligence-platform/index.ts +0 -10
  314. package/src/v2/runtime/node.ts +0 -6
  315. package/src/v2/runtime/open-generative-ui-middleware.ts +0 -373
  316. package/src/v2/runtime/runner/__tests__/finalize-events.test.ts +0 -109
  317. package/src/v2/runtime/runner/__tests__/in-memory-runner.e2e.test.ts +0 -775
  318. package/src/v2/runtime/runner/__tests__/in-memory-runner.test.ts +0 -777
  319. package/src/v2/runtime/runner/__tests__/intelligence-runner.test.ts +0 -1039
  320. package/src/v2/runtime/runner/agent-runner.ts +0 -35
  321. package/src/v2/runtime/runner/in-memory.ts +0 -467
  322. package/src/v2/runtime/runner/index.ts +0 -4
  323. package/src/v2/runtime/runner/intelligence.ts +0 -498
  324. package/src/v2/runtime/telemetry/__tests__/instance-created.test.ts +0 -96
  325. package/src/v2/runtime/telemetry/events.ts +0 -35
  326. package/src/v2/runtime/telemetry/index.ts +0 -7
  327. package/src/v2/runtime/telemetry/instance-created.ts +0 -44
  328. package/src/v2/runtime/telemetry/scarf-client.ts +0 -39
  329. package/src/v2/runtime/telemetry/telemetry-client.ts +0 -70
  330. package/src/v2/runtime/transcription-service/transcription-service.ts +0 -11
  331. package/tests/global.d.ts +0 -1
  332. package/tests/service-adapters/anthropic/allowlist-approach.test.ts +0 -259
  333. package/tests/service-adapters/anthropic/anthropic-adapter-language-model.test.ts +0 -101
  334. package/tests/service-adapters/anthropic/anthropic-adapter.test.ts +0 -645
  335. package/tests/service-adapters/anthropic/utils-token-trimming.test.ts +0 -301
  336. package/tests/service-adapters/groq/groq-adapter-language-model.test.ts +0 -102
  337. package/tests/service-adapters/openai/allowlist-approach.test.ts +0 -294
  338. package/tests/service-adapters/openai/openai-adapter-language-model.test.ts +0 -122
  339. package/tests/service-adapters/openai/openai-adapter.test.ts +0 -291
  340. package/tests/service-adapters/shared/sdk-client-utils.test.ts +0 -36
  341. package/tests/setup.vitest.ts +0 -8
  342. package/tests/tsconfig.json +0 -10
  343. package/tsconfig.json +0 -20
  344. package/tsdown.config.ts +0 -45
  345. package/typedoc.json +0 -4
  346. package/vitest.config.mjs +0 -13
@@ -1,351 +0,0 @@
1
- import type {
2
- AbstractAgent,
3
- BaseEvent,
4
- Message,
5
- RunAgentInput,
6
- } from "@ag-ui/client";
7
- import { EventType } from "@ag-ui/client";
8
- import type { CopilotIntelligenceRuntimeLike } from "../../core/runtime";
9
- import { generateThreadNameForNewThread } from "./thread-names";
10
- import { logger } from "@copilotkit/shared";
11
- import { telemetry } from "../../telemetry";
12
- import { resolveIntelligenceUser } from "../shared/resolve-intelligence-user";
13
- import { isHandlerResponse } from "../shared/json-response";
14
- import type { AgentRunnerRunRequest } from "../../runner/agent-runner";
15
- import type { Observable } from "rxjs";
16
-
17
- /**
18
- * Builds browser-facing realtime connection metadata owned by the runtime.
19
- */
20
- function buildRealtimeConnectionInfo(params: {
21
- clientUrl: string;
22
- threadId: string;
23
- }): { clientUrl: string; topic: string } {
24
- return {
25
- clientUrl: params.clientUrl,
26
- topic: `thread:${params.threadId}`,
27
- };
28
- }
29
-
30
- interface RunnerStartupBoundary {
31
- events: Observable<BaseEvent>;
32
- startup: Promise<void>;
33
- }
34
-
35
- interface RunnerWithStartupBoundary {
36
- runWithStartupBoundary(request: AgentRunnerRunRequest): RunnerStartupBoundary;
37
- }
38
-
39
- function hasRunnerStartupBoundary(
40
- runner: CopilotIntelligenceRuntimeLike["runner"],
41
- ): runner is CopilotIntelligenceRuntimeLike["runner"] &
42
- RunnerWithStartupBoundary {
43
- const candidate = runner as { runWithStartupBoundary?: unknown };
44
-
45
- return (
46
- typeof candidate.runWithStartupBoundary === "function" &&
47
- (Object.prototype.hasOwnProperty.call(runner, "runWithStartupBoundary") ||
48
- Object.prototype.hasOwnProperty.call(runner, "threads"))
49
- );
50
- }
51
-
52
- interface HandleIntelligenceRunParams {
53
- runtime: CopilotIntelligenceRuntimeLike;
54
- request: Request;
55
- agentId: string;
56
- agent: AbstractAgent;
57
- input: RunAgentInput;
58
- }
59
-
60
- export async function handleIntelligenceRun({
61
- runtime,
62
- request,
63
- agentId,
64
- agent,
65
- input,
66
- }: HandleIntelligenceRunParams): Promise<Response> {
67
- if (!runtime.intelligence) {
68
- return Response.json(
69
- {
70
- error: "Intelligence not configured",
71
- message: "Intelligence mode requires a CopilotKitIntelligence",
72
- },
73
- { status: 500 },
74
- );
75
- }
76
-
77
- const user = await resolveIntelligenceUser({ runtime, request });
78
- if (isHandlerResponse(user)) {
79
- return user;
80
- }
81
- const userId = user.id;
82
-
83
- try {
84
- const { thread, created } = await runtime.intelligence.getOrCreateThread({
85
- threadId: input.threadId,
86
- userId,
87
- agentId,
88
- });
89
-
90
- if (created && runtime.generateThreadNames && !thread.name?.trim()) {
91
- void generateThreadNameForNewThread({
92
- runtime,
93
- request,
94
- agentId,
95
- sourceInput: input,
96
- thread,
97
- userId,
98
- }).catch((nameError) => {
99
- logger.error("Failed to generate thread name:", nameError);
100
- });
101
- }
102
- } catch (error) {
103
- logger.error("Failed to get or create thread:", error);
104
- return Response.json(
105
- {
106
- error: "Failed to initialize thread",
107
- },
108
- { status: 502 },
109
- );
110
- }
111
-
112
- let canonicalThreadId = input.threadId;
113
- let canonicalRunId = input.runId;
114
- let joinToken: string | undefined;
115
- try {
116
- const lockResult = await runtime.intelligence.ɵacquireThreadLock({
117
- threadId: input.threadId,
118
- runId: input.runId,
119
- userId,
120
- agentId,
121
- ...(runtime.lockKeyPrefix !== undefined
122
- ? { lockKeyPrefix: runtime.lockKeyPrefix }
123
- : {}),
124
- ttlSeconds: runtime.lockTtlSeconds,
125
- });
126
- canonicalThreadId = lockResult.threadId;
127
- canonicalRunId = lockResult.runId;
128
- joinToken = lockResult.joinToken;
129
- } catch (error) {
130
- logger.error("Thread lock denied:", error);
131
- return Response.json(
132
- {
133
- error: "Thread lock denied",
134
- },
135
- { status: 409 },
136
- );
137
- }
138
-
139
- const cleanupLock = (reason: string): Promise<void> =>
140
- runtime.intelligence
141
- .ɵcleanupThreadLock({
142
- threadId: canonicalThreadId || input.threadId,
143
- runId: canonicalRunId || input.runId,
144
- })
145
- .catch((cleanupError) => {
146
- logger.error(
147
- { err: cleanupError, reason },
148
- "Failed to cleanup thread lock",
149
- );
150
- });
151
-
152
- if (!canonicalThreadId || !canonicalRunId || !joinToken) {
153
- await cleanupLock("malformed-lock-response");
154
- return Response.json(
155
- {
156
- error: "Run connection credentials not available",
157
- message:
158
- "Intelligence platform did not return canonical threadId, runId, and joinToken",
159
- },
160
- { status: 502 },
161
- );
162
- }
163
-
164
- // When Intelligence has `mcpServer: true`, hand the agent the per-request
165
- // bits it needs to attach the platform's MCP server: the resolved user-id,
166
- // the project Bearer (`apiKey`), and the MCP URL. These ride through
167
- // `forwardedProps.auth.copilotkitIntelligence` so the agent doesn't need a
168
- // typed reference to the Intelligence client. `BuiltInAgent` reads the
169
- // bag and builds a per-request MCP config with a closure-baked fetch;
170
- // non-BuiltInAgent agents naturally ignore the key. The `auth` namespace
171
- // is the convention for credentials that downstream redaction policies
172
- // strip before durable storage and FE replay.
173
- const upstreamAuth =
174
- (input.forwardedProps as { auth?: Record<string, unknown> } | undefined)
175
- ?.auth ?? {};
176
- const copilotkitIntelligenceAuth =
177
- runtime.intelligence.ɵisMcpServerEnabled?.()
178
- ? {
179
- copilotkitIntelligence: {
180
- userId,
181
- apiKey: runtime.intelligence.ɵgetApiKey(),
182
- mcpUrl: `${runtime.intelligence.ɵgetApiUrl()}/mcp`,
183
- },
184
- }
185
- : {};
186
- const mergedAuth = { ...upstreamAuth, ...copilotkitIntelligenceAuth };
187
-
188
- const canonicalInput: RunAgentInput = {
189
- ...input,
190
- threadId: canonicalThreadId,
191
- runId: canonicalRunId,
192
- forwardedProps: {
193
- ...input.forwardedProps,
194
- ...(Object.keys(mergedAuth).length > 0 ? { auth: mergedAuth } : {}),
195
- },
196
- };
197
-
198
- let persistedInputMessages: Message[] | undefined;
199
- if (Array.isArray(input.messages)) {
200
- try {
201
- const history = await runtime.intelligence.getThreadMessages({
202
- threadId: canonicalThreadId,
203
- });
204
- const historicMessageIds = new Set(
205
- history.messages.map((message) => message.id),
206
- );
207
- persistedInputMessages = input.messages.filter(
208
- (message) => !historicMessageIds.has(message.id),
209
- );
210
- } catch (error) {
211
- logger.error("Thread history lookup failed:", error);
212
- await cleanupLock("thread-history-lookup-failed");
213
- return Response.json(
214
- {
215
- error: "Thread history lookup failed",
216
- },
217
- { status: 502 },
218
- );
219
- }
220
- }
221
-
222
- telemetry.capture("oss.runtime.agent_execution_stream_started", {});
223
-
224
- // Start heartbeat timer to renew the thread lock.
225
- let heartbeatTimer: ReturnType<typeof setInterval> | undefined;
226
- heartbeatTimer = setInterval(() => {
227
- runtime.intelligence
228
- .ɵrenewThreadLock({
229
- threadId: canonicalThreadId,
230
- runId: canonicalRunId,
231
- ttlSeconds: runtime.lockTtlSeconds,
232
- ...(runtime.lockKeyPrefix !== undefined
233
- ? { lockKeyPrefix: runtime.lockKeyPrefix }
234
- : {}),
235
- })
236
- .catch((err) => {
237
- logger.error("Failed to renew thread lock:", err);
238
- clearHeartbeat();
239
- try {
240
- agent.abortRun();
241
- } catch (abortError) {
242
- logger.error(
243
- "Failed to abort agent after lock renewal failure:",
244
- abortError,
245
- );
246
- }
247
- });
248
- }, runtime.lockHeartbeatIntervalSeconds * 1_000);
249
-
250
- const clearHeartbeat = () => {
251
- if (heartbeatTimer !== undefined) {
252
- clearInterval(heartbeatTimer);
253
- heartbeatTimer = undefined;
254
- }
255
- };
256
-
257
- const runStarted = { current: false };
258
- let immediateStartupErrorMessage: string | undefined;
259
- let immediateStartupCleanup: Promise<void> | undefined;
260
-
261
- const runRequest: AgentRunnerRunRequest = {
262
- threadId: canonicalThreadId,
263
- agent,
264
- input: canonicalInput,
265
- ...(persistedInputMessages !== undefined ? { persistedInputMessages } : {}),
266
- };
267
-
268
- try {
269
- const runStart = hasRunnerStartupBoundary(runtime.runner)
270
- ? runtime.runner.runWithStartupBoundary(runRequest)
271
- : {
272
- events: runtime.runner.run(runRequest),
273
- startup: Promise.resolve(),
274
- };
275
-
276
- runStart.events.subscribe({
277
- next: (event: BaseEvent) => {
278
- if (event.type === EventType.RUN_STARTED) {
279
- runStarted.current = true;
280
- }
281
- if (event.type === EventType.RUN_ERROR && !runStarted.current) {
282
- clearHeartbeat();
283
- immediateStartupErrorMessage =
284
- "message" in event && typeof event.message === "string"
285
- ? event.message
286
- : "Runner failed before the run started";
287
- immediateStartupCleanup = cleanupLock("runner-start-failed");
288
- }
289
- },
290
- error: (error) => {
291
- clearHeartbeat();
292
- if (!runStarted.current) {
293
- immediateStartupErrorMessage =
294
- error instanceof Error ? error.message : String(error);
295
- immediateStartupCleanup = cleanupLock("runner-start-error");
296
- } else {
297
- cleanupLock("runner-error");
298
- }
299
- telemetry.capture("oss.runtime.agent_execution_stream_errored", {
300
- error: error instanceof Error ? error.message : String(error),
301
- });
302
- logger.error("Error running agent:", error);
303
- },
304
- complete: () => {
305
- clearHeartbeat();
306
- telemetry.capture("oss.runtime.agent_execution_stream_ended", {});
307
- },
308
- });
309
-
310
- await runStart.startup;
311
- } catch (error) {
312
- clearHeartbeat();
313
- await (immediateStartupCleanup ?? cleanupLock("runner-start-threw"));
314
- logger.error("Error starting agent runner:", error);
315
- return Response.json(
316
- {
317
- error: "Failed to start runner",
318
- message: error instanceof Error ? error.message : String(error),
319
- },
320
- { status: 502 },
321
- );
322
- }
323
-
324
- if (immediateStartupErrorMessage) {
325
- await immediateStartupCleanup;
326
- return Response.json(
327
- {
328
- error: "Failed to start runner",
329
- message: immediateStartupErrorMessage,
330
- },
331
- { status: 502 },
332
- );
333
- }
334
-
335
- // IntelligenceAgentRunner resolves this boundary after Phoenix channel join.
336
- // Other runner implementations fall back to construction/subscription errors.
337
- return Response.json(
338
- {
339
- threadId: canonicalThreadId,
340
- runId: canonicalRunId,
341
- joinToken,
342
- realtime: buildRealtimeConnectionInfo({
343
- clientUrl: runtime.intelligence.ɵgetClientWsUrl(),
344
- threadId: canonicalThreadId,
345
- }),
346
- },
347
- {
348
- headers: { "Cache-Control": "no-cache" },
349
- },
350
- );
351
- }
@@ -1,246 +0,0 @@
1
- import { AbstractAgent, Message, RunAgentInput } from "@ag-ui/client";
2
- import { logger } from "@copilotkit/shared";
3
- import { randomUUID } from "node:crypto";
4
- import { CopilotIntelligenceRuntimeLike } from "../../core/runtime";
5
- import {
6
- cloneAgentForRequest,
7
- configureAgentForRequest,
8
- } from "../shared/agent-utils";
9
- import { ThreadSummary } from "../../intelligence-platform";
10
- import { isHandlerResponse } from "../shared/json-response";
11
-
12
- const THREAD_NAME_SYSTEM_PROMPT = [
13
- "You generate short, specific conversation titles.",
14
- 'Return JSON only in this exact shape: {"title":"..."}',
15
- "The title must be 2 to 5 words.",
16
- "Use sentence case.",
17
- "No quotes.",
18
- "No emoji.",
19
- "No markdown characters or formatting.",
20
- "Do not use *, _, #, `, [, ], (, ), !, ~, >, or |.",
21
- "No trailing punctuation.",
22
- "No explanations.",
23
- "Do not call tools.",
24
- ].join("\n");
25
-
26
- const MAX_TITLE_LENGTH = 80;
27
- const MAX_TITLE_WORDS = 8;
28
- const MAX_TRANSCRIPT_MESSAGES = 8;
29
- const MAX_TITLE_GENERATION_ATTEMPTS = 3;
30
- const FALLBACK_THREAD_TITLE = "Untitled";
31
-
32
- interface GenerateThreadNameParams {
33
- runtime: CopilotIntelligenceRuntimeLike;
34
- request: Request;
35
- agentId: string;
36
- sourceInput: RunAgentInput;
37
- thread: ThreadSummary;
38
- userId: string;
39
- }
40
-
41
- export async function generateThreadNameForNewThread({
42
- runtime,
43
- request,
44
- agentId,
45
- sourceInput,
46
- thread,
47
- userId,
48
- }: GenerateThreadNameParams): Promise<void> {
49
- if (!runtime.generateThreadNames || hasThreadName(thread.name)) {
50
- return;
51
- }
52
-
53
- const prompt = buildThreadTitlePrompt(sourceInput.messages);
54
- if (!prompt) {
55
- return;
56
- }
57
-
58
- let generatedTitle: string | null = null;
59
-
60
- for (let attempt = 1; attempt <= MAX_TITLE_GENERATION_ATTEMPTS; attempt++) {
61
- try {
62
- generatedTitle = await runTitleGenerationAttempt({
63
- runtime,
64
- request,
65
- agentId,
66
- threadId: thread.id,
67
- prompt,
68
- });
69
-
70
- if (generatedTitle) {
71
- break;
72
- }
73
-
74
- logger.warn(
75
- { agentId, attempt, threadId: thread.id },
76
- "Thread name generation returned an empty or invalid title",
77
- );
78
- } catch (error) {
79
- logger.warn(
80
- { err: error, agentId, attempt, threadId: thread.id },
81
- "Thread name generation attempt failed",
82
- );
83
- }
84
- }
85
-
86
- await runtime.intelligence.updateThread({
87
- threadId: thread.id,
88
- userId,
89
- agentId,
90
- updates: { name: generatedTitle ?? FALLBACK_THREAD_TITLE },
91
- });
92
- }
93
-
94
- async function runTitleGenerationAttempt(params: {
95
- runtime: CopilotIntelligenceRuntimeLike;
96
- request: Request;
97
- agentId: string;
98
- threadId: string;
99
- prompt: string;
100
- }): Promise<string | null> {
101
- const { runtime, request, agentId, threadId, prompt } = params;
102
- const agent = await cloneAgentForRequest(runtime, agentId, request);
103
- if (isHandlerResponse(agent)) {
104
- logger.warn(
105
- { agentId, threadId },
106
- "Skipping thread naming because the agent could not be cloned",
107
- );
108
- return null;
109
- }
110
-
111
- configureAgentForRequest({
112
- runtime,
113
- request,
114
- agentId,
115
- agent,
116
- });
117
-
118
- const messages: Message[] = [
119
- {
120
- id: randomUUID(),
121
- role: "system",
122
- content: THREAD_NAME_SYSTEM_PROMPT,
123
- },
124
- {
125
- id: randomUUID(),
126
- role: "user",
127
- content: prompt,
128
- },
129
- ];
130
-
131
- agent.setMessages(messages);
132
- agent.setState({});
133
- agent.threadId = randomUUID();
134
- const { newMessages } = await agent.runAgent({
135
- messages,
136
- state: {},
137
- tools: [],
138
- context: [],
139
- forwardedProps: {},
140
- });
141
-
142
- const lastMessage = newMessages.at(-1);
143
- const titleContent = lastMessage
144
- ? stringifyMessageContent(lastMessage.content)
145
- : "";
146
-
147
- return normalizeGeneratedTitle(titleContent);
148
- }
149
-
150
- function buildThreadTitlePrompt(
151
- messages: Message[] | undefined,
152
- ): string | null {
153
- const transcript = (messages ?? [])
154
- .filter((message) =>
155
- ["user", "assistant", "system", "developer"].includes(message.role),
156
- )
157
- .map((message) => {
158
- const content = stringifyMessageContent(message.content);
159
- if (!content) {
160
- return null;
161
- }
162
-
163
- return `${message.role}: ${content}`;
164
- })
165
- .filter((message): message is string => !!message)
166
- .slice(-MAX_TRANSCRIPT_MESSAGES);
167
-
168
- if (transcript.length === 0) {
169
- return null;
170
- }
171
-
172
- return [
173
- "Generate a short title for this conversation.",
174
- "Conversation:",
175
- transcript.join("\n"),
176
- ].join("\n\n");
177
- }
178
-
179
- function stringifyMessageContent(content: Message["content"]): string {
180
- if (typeof content === "string") {
181
- return content.trim();
182
- }
183
-
184
- if (content == null) {
185
- return "";
186
- }
187
-
188
- try {
189
- return JSON.stringify(content).trim();
190
- } catch {
191
- return "";
192
- }
193
- }
194
-
195
- function normalizeGeneratedTitle(rawTitle: string): string | null {
196
- let candidate = rawTitle.trim();
197
- if (!candidate) {
198
- return null;
199
- }
200
-
201
- candidate = candidate
202
- .replace(/^```(?:json)?\s*/i, "")
203
- .replace(/\s*```$/, "")
204
- .trim();
205
-
206
- try {
207
- const parsed = JSON.parse(candidate) as { title?: unknown };
208
- if (typeof parsed.title === "string") {
209
- candidate = parsed.title;
210
- }
211
- } catch {
212
- // Fall back to using the raw text.
213
- }
214
-
215
- candidate = candidate
216
- .replace(/^["'`]+|["'`]+$/g, "")
217
- .replace(/[*_#[\]()!~>|]+/g, "")
218
- .replace(/[.!?,;:]+$/g, "")
219
- .replace(/\s+/g, " ")
220
- .trim();
221
-
222
- if (!candidate) {
223
- return null;
224
- }
225
-
226
- if (candidate.length > MAX_TITLE_LENGTH) {
227
- candidate = candidate.slice(0, MAX_TITLE_LENGTH).trim();
228
- }
229
-
230
- if (candidate.split(/\s+/).length > MAX_TITLE_WORDS) {
231
- return null;
232
- }
233
-
234
- return candidate;
235
- }
236
-
237
- function hasThreadName(name: string | null | undefined): boolean {
238
- return typeof name === "string" && name.trim().length > 0;
239
- }
240
-
241
- /** @internal Exported for testing only. */
242
- export const ɵnormalizeGeneratedTitle = normalizeGeneratedTitle;
243
- /** @internal Exported for testing only. */
244
- export const ɵbuildThreadTitlePrompt = buildThreadTitlePrompt;
245
- /** @internal Exported for testing only. */
246
- export const ɵhasThreadName = hasThreadName;