@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,1653 +0,0 @@
1
- import { vi } from "vitest";
2
- import * as gql from "../types/converted/index";
3
- import { MessageStatusCode } from "../types/message-status.type";
4
- import {
5
- gqlToAGUI,
6
- gqlTextMessageToAGUIMessage,
7
- gqlResultMessageToAGUIMessage,
8
- gqlImageMessageToAGUIMessage,
9
- gqlActionExecutionMessageToAGUIMessage,
10
- } from "./gql-to-agui";
11
- import { AIMessage } from "@copilotkit/shared";
12
-
13
- describe("message-conversion", () => {
14
- describe("gqlTextMessageToAGUIMessage", () => {
15
- test("should convert developer message", () => {
16
- const gqlMessage = new gql.TextMessage({
17
- id: "dev-message-id",
18
- content: "Hello from developer",
19
- role: gql.Role.developer,
20
- });
21
-
22
- const result = gqlTextMessageToAGUIMessage(gqlMessage);
23
-
24
- expect(result).toEqual({
25
- id: "dev-message-id",
26
- role: "developer",
27
- content: "Hello from developer",
28
- });
29
- });
30
-
31
- test("should convert system message", () => {
32
- const gqlMessage = new gql.TextMessage({
33
- id: "system-message-id",
34
- content: "System instruction",
35
- role: gql.Role.system,
36
- });
37
-
38
- const result = gqlTextMessageToAGUIMessage(gqlMessage);
39
-
40
- expect(result).toEqual({
41
- id: "system-message-id",
42
- role: "system",
43
- content: "System instruction",
44
- });
45
- });
46
-
47
- test("should convert assistant message", () => {
48
- const gqlMessage = new gql.TextMessage({
49
- id: "assistant-message-id",
50
- content: "Assistant response",
51
- role: gql.Role.assistant,
52
- });
53
-
54
- const result = gqlTextMessageToAGUIMessage(gqlMessage);
55
-
56
- expect(result).toEqual({
57
- id: "assistant-message-id",
58
- role: "assistant",
59
- content: "Assistant response",
60
- });
61
- });
62
-
63
- test("should throw error for unknown role", () => {
64
- const gqlMessage = new gql.TextMessage({
65
- id: "unknown-message-id",
66
- content: "Unknown message",
67
- role: "unknown" as any,
68
- });
69
-
70
- expect(() => gqlTextMessageToAGUIMessage(gqlMessage)).toThrow(
71
- "Unknown message role",
72
- );
73
- });
74
- });
75
-
76
- describe("gqlResultMessageToAGUIMessage", () => {
77
- test("should convert result message to tool message", () => {
78
- const gqlMessage = new gql.ResultMessage({
79
- id: "result-id",
80
- result: "Function result data",
81
- actionExecutionId: "action-exec-123",
82
- actionName: "testAction",
83
- });
84
-
85
- const result = gqlResultMessageToAGUIMessage(gqlMessage);
86
-
87
- expect(result).toEqual({
88
- id: "result-id",
89
- role: "tool",
90
- content: "Function result data",
91
- toolCallId: "action-exec-123",
92
- toolName: "testAction",
93
- });
94
- });
95
- });
96
-
97
- describe("gqlToAGUI", () => {
98
- test("should convert an array of text messages", () => {
99
- const gqlMessages = [
100
- new gql.TextMessage({
101
- id: "dev-1",
102
- content: "Hello",
103
- role: gql.Role.developer,
104
- }),
105
- new gql.TextMessage({
106
- id: "assistant-1",
107
- content: "Hi there",
108
- role: gql.Role.assistant,
109
- }),
110
- ];
111
-
112
- const result = gqlToAGUI(gqlMessages);
113
-
114
- expect(result).toHaveLength(2);
115
- expect(result[0]).toEqual({
116
- id: "dev-1",
117
- role: "developer",
118
- content: "Hello",
119
- });
120
- expect(result[1]).toEqual({
121
- id: "assistant-1",
122
- role: "assistant",
123
- content: "Hi there",
124
- });
125
- });
126
-
127
- test("should handle agent state messages", () => {
128
- const gqlMessages = [new gql.AgentStateMessage({ id: "agent-state-1" })];
129
-
130
- const result = gqlToAGUI(gqlMessages);
131
-
132
- expect(result).toHaveLength(1);
133
- expect(result[0]).toEqual({
134
- id: "agent-state-1",
135
- role: "assistant",
136
- });
137
- });
138
-
139
- // test("should throw error for unknown message type", () => {
140
- // // Create a message with unknown type
141
- // const unknownMessage = new gql.Message({ id: "unknown-1" });
142
- // // Override the type checking methods to simulate unknown type
143
- // unknownMessage.isTextMessage = () => false as any;
144
- // unknownMessage.isResultMessage = () => false as any;
145
- // unknownMessage.isActionExecutionMessage = () => false as any;
146
- // unknownMessage.isAgentStateMessage = () => false as any;
147
- // unknownMessage.isImageMessage = () => false as any;
148
-
149
- // expect(() => gqlToAGUI([unknownMessage])).toThrow("Unknown message type");
150
- // });
151
-
152
- test("should handle a mix of message types", () => {
153
- const gqlMessages = [
154
- new gql.TextMessage({
155
- id: "dev-1",
156
- content: "Run action",
157
- role: gql.Role.developer,
158
- }),
159
- new gql.TextMessage({
160
- id: "assistant-1",
161
- content: "I'll run the action",
162
- role: gql.Role.assistant,
163
- }),
164
- new gql.ResultMessage({
165
- id: "result-1",
166
- result: "Action result",
167
- actionExecutionId: "action-exec-1",
168
- actionName: "testAction",
169
- }),
170
- ];
171
-
172
- const result = gqlToAGUI(gqlMessages);
173
-
174
- expect(result).toHaveLength(3);
175
- expect(result[0]).toEqual({
176
- id: "dev-1",
177
- role: "developer",
178
- content: "Run action",
179
- });
180
- expect(result[1]).toEqual({
181
- id: "assistant-1",
182
- role: "assistant",
183
- content: "I'll run the action",
184
- });
185
- expect(result[2]).toEqual({
186
- id: "result-1",
187
- role: "tool",
188
- content: "Action result",
189
- toolCallId: "action-exec-1",
190
- toolName: "testAction",
191
- });
192
- });
193
-
194
- test("should handle action execution messages with parent messages", () => {
195
- const assistantMsg = new gql.TextMessage({
196
- id: "assistant-1",
197
- content: "I'll execute an action",
198
- role: gql.Role.assistant,
199
- });
200
-
201
- const actionExecMsg = new gql.ActionExecutionMessage({
202
- id: "action-1",
203
- name: "testAction",
204
- arguments: { param: "value" },
205
- parentMessageId: "assistant-1",
206
- });
207
-
208
- const result = gqlToAGUI([assistantMsg, actionExecMsg]);
209
-
210
- // Now we expect 2 messages: the original assistant message and the action execution message
211
- expect(result).toHaveLength(2);
212
- expect(result[0]).toEqual({
213
- id: "assistant-1",
214
- role: "assistant",
215
- content: "I'll execute an action",
216
- });
217
- expect(result[1]).toEqual({
218
- id: "action-1",
219
- role: "assistant",
220
- name: "testAction",
221
- toolCalls: [
222
- {
223
- id: "action-1",
224
- function: {
225
- name: "testAction",
226
- arguments: JSON.stringify({ param: "value" }),
227
- },
228
- type: "function",
229
- },
230
- ],
231
- });
232
- });
233
-
234
- test("should handle multiple action execution messages for the same parent", () => {
235
- const assistantMsg = new gql.TextMessage({
236
- id: "assistant-1",
237
- content: "I'll execute multiple actions",
238
- role: gql.Role.assistant,
239
- });
240
-
241
- const action1 = new gql.ActionExecutionMessage({
242
- id: "action-1",
243
- name: "firstAction",
244
- arguments: { param: "value1" },
245
- parentMessageId: "assistant-1",
246
- });
247
-
248
- const action2 = new gql.ActionExecutionMessage({
249
- id: "action-2",
250
- name: "secondAction",
251
- arguments: { param: "value2" },
252
- parentMessageId: "assistant-1",
253
- });
254
-
255
- const result = gqlToAGUI([assistantMsg, action1, action2]);
256
-
257
- // Now we expect 3 messages: the original assistant message and 2 separate action execution messages
258
- expect(result).toHaveLength(3);
259
- expect(result[0]).toEqual({
260
- id: "assistant-1",
261
- role: "assistant",
262
- content: "I'll execute multiple actions",
263
- });
264
- expect(result[1]).toEqual({
265
- id: "action-1",
266
- role: "assistant",
267
- name: "firstAction",
268
- toolCalls: [
269
- {
270
- id: "action-1",
271
- function: {
272
- name: "firstAction",
273
- arguments: JSON.stringify({ param: "value1" }),
274
- },
275
- type: "function",
276
- },
277
- ],
278
- });
279
- expect(result[2]).toEqual({
280
- id: "action-2",
281
- role: "assistant",
282
- name: "secondAction",
283
- toolCalls: [
284
- {
285
- id: "action-2",
286
- function: {
287
- name: "secondAction",
288
- arguments: JSON.stringify({ param: "value2" }),
289
- },
290
- type: "function",
291
- },
292
- ],
293
- });
294
- });
295
-
296
- test("should not add toolCalls to non-assistant messages", () => {
297
- const developerMsg = new gql.TextMessage({
298
- id: "dev-1",
299
- content: "Developer message",
300
- role: gql.Role.developer,
301
- });
302
-
303
- const actionExecMsg = new gql.ActionExecutionMessage({
304
- id: "action-1",
305
- name: "testAction",
306
- arguments: { param: "value" },
307
- parentMessageId: "dev-1", // This should be ignored since parent is not assistant
308
- });
309
-
310
- const result = gqlToAGUI([developerMsg, actionExecMsg]);
311
-
312
- // Now we expect 2 messages: the developer message and the action execution as assistant message
313
- expect(result).toHaveLength(2);
314
- expect(result[0]).toEqual({
315
- id: "dev-1",
316
- role: "developer",
317
- content: "Developer message",
318
- });
319
- // The action execution becomes its own assistant message regardless of parent
320
- expect(result[1]).toEqual({
321
- id: "action-1",
322
- role: "assistant",
323
- name: "testAction",
324
- toolCalls: [
325
- {
326
- id: "action-1",
327
- function: {
328
- name: "testAction",
329
- arguments: JSON.stringify({ param: "value" }),
330
- },
331
- type: "function",
332
- },
333
- ],
334
- });
335
- });
336
-
337
- test("should handle action execution messages without actions context", () => {
338
- const actionExecMsg = new gql.ActionExecutionMessage({
339
- id: "action-1",
340
- name: "testAction",
341
- arguments: { param: "value" },
342
- });
343
-
344
- const result = gqlToAGUI([actionExecMsg]);
345
-
346
- expect(result).toHaveLength(1);
347
- expect(result[0]).toEqual({
348
- id: "action-1",
349
- role: "assistant",
350
- name: "testAction",
351
- toolCalls: [
352
- {
353
- id: "action-1",
354
- function: {
355
- name: "testAction",
356
- arguments: JSON.stringify({ param: "value" }),
357
- },
358
- type: "function",
359
- },
360
- ],
361
- });
362
- // Should not have render functions without actions context
363
- expect(result[0]).not.toHaveProperty("render");
364
- expect(result[0]).not.toHaveProperty("renderAndWaitForResponse");
365
- });
366
-
367
- test("should handle action execution messages with actions context and render functions", () => {
368
- const actionExecMsg = new gql.ActionExecutionMessage({
369
- id: "action-1",
370
- name: "testAction",
371
- arguments: { param: "value" },
372
- status: { code: MessageStatusCode.Pending },
373
- });
374
-
375
- const mockRender = vi.fn();
376
- const mockRenderAndWaitForResponse = (props: any) =>
377
- "Test Render With Response";
378
-
379
- const actions = {
380
- testAction: {
381
- name: "testAction",
382
- render: mockRender,
383
- renderAndWaitForResponse: mockRenderAndWaitForResponse,
384
- },
385
- };
386
-
387
- const result = gqlToAGUI([actionExecMsg], actions);
388
-
389
- expect(result).toHaveLength(1);
390
- expect(result[0]).toMatchObject({
391
- id: "action-1",
392
- role: "assistant",
393
- name: "testAction",
394
- content: "",
395
- toolCalls: [
396
- {
397
- id: "action-1",
398
- function: {
399
- name: "testAction",
400
- arguments: JSON.stringify({ param: "value" }),
401
- },
402
- type: "function",
403
- },
404
- ],
405
- });
406
-
407
- // Should have generativeUI function
408
- expect(result[0]).toHaveProperty("generativeUI");
409
- expect(typeof (result[0] as any).generativeUI).toBe("function");
410
- });
411
-
412
- test("should provide correct status in generativeUI function props", () => {
413
- const actionExecMsg = new gql.ActionExecutionMessage({
414
- id: "action-1",
415
- name: "testAction",
416
- arguments: { param: "value" },
417
- status: { code: MessageStatusCode.Pending },
418
- });
419
-
420
- const mockRender = vi.fn();
421
- const actions = {
422
- testAction: {
423
- name: "testAction",
424
- render: mockRender,
425
- },
426
- };
427
-
428
- const result = gqlToAGUI([actionExecMsg], actions);
429
-
430
- // Call the generativeUI function
431
- (result[0] as any).generativeUI?.();
432
-
433
- expect(mockRender).toHaveBeenCalledWith({
434
- status: "inProgress",
435
- args: { param: "value" },
436
- result: undefined,
437
- respond: expect.any(Function),
438
- messageId: "action-1",
439
- // Regular actions should NOT have the name property
440
- });
441
- });
442
-
443
- test("should provide executing status when not pending", () => {
444
- const actionExecMsg = new gql.ActionExecutionMessage({
445
- id: "action-1",
446
- name: "testAction",
447
- arguments: { param: "value" },
448
- status: { code: MessageStatusCode.Success },
449
- });
450
-
451
- const mockRender = vi.fn();
452
- const actions = {
453
- testAction: {
454
- name: "testAction",
455
- render: mockRender,
456
- },
457
- };
458
-
459
- const result = gqlToAGUI([actionExecMsg], actions);
460
-
461
- // Call the generativeUI function
462
- (result[0] as any).generativeUI?.();
463
-
464
- expect(mockRender).toHaveBeenCalledWith({
465
- status: "executing",
466
- args: { param: "value" },
467
- result: undefined,
468
- respond: expect.any(Function),
469
- messageId: "action-1",
470
- // Regular actions should NOT have the name property
471
- });
472
- });
473
-
474
- test("should provide complete status when result is available", () => {
475
- const actionExecMsg = new gql.ActionExecutionMessage({
476
- id: "action-1",
477
- name: "testAction",
478
- arguments: { param: "value" },
479
- status: { code: MessageStatusCode.Success },
480
- });
481
-
482
- const resultMsg = new gql.ResultMessage({
483
- id: "result-1",
484
- result: "Action completed successfully",
485
- actionExecutionId: "action-1",
486
- actionName: "testAction",
487
- });
488
-
489
- const mockRender = vi.fn();
490
- const actions = {
491
- testAction: {
492
- name: "testAction",
493
- render: mockRender,
494
- },
495
- };
496
-
497
- const result = gqlToAGUI([actionExecMsg, resultMsg], actions);
498
-
499
- // Find the action execution message result (not the tool result)
500
- const actionMessage = result.find(
501
- (msg) => msg.role === "assistant" && "toolCalls" in msg,
502
- );
503
-
504
- // Call the generativeUI function
505
- (actionMessage as any)?.generativeUI?.();
506
-
507
- expect(mockRender).toHaveBeenCalledWith({
508
- status: "complete",
509
- args: { param: "value" },
510
- result: "Action completed successfully",
511
- respond: expect.any(Function),
512
- messageId: "action-1",
513
- // Regular actions should NOT have the name property
514
- });
515
- });
516
-
517
- test("should handle generativeUI function props override", () => {
518
- const actionExecMsg = new gql.ActionExecutionMessage({
519
- id: "action-1",
520
- name: "testAction",
521
- arguments: { param: "value" },
522
- status: { code: MessageStatusCode.Pending },
523
- });
524
-
525
- const mockRender = vi.fn();
526
- const actions = {
527
- testAction: {
528
- name: "testAction",
529
- render: mockRender,
530
- },
531
- };
532
-
533
- const result = gqlToAGUI([actionExecMsg], actions);
534
-
535
- // Call with custom props
536
- (result[0] as any).generativeUI?.({
537
- status: "custom",
538
- customProp: "test",
539
- respond: () => "custom respond",
540
- });
541
-
542
- expect(mockRender).toHaveBeenCalledWith({
543
- status: "custom",
544
- args: { param: "value" },
545
- result: undefined,
546
- respond: expect.any(Function),
547
- customProp: "test",
548
- messageId: "action-1",
549
- // Regular actions should NOT have the name property
550
- });
551
- });
552
-
553
- test("should handle missing render functions gracefully", () => {
554
- const actionExecMsg = new gql.ActionExecutionMessage({
555
- id: "action-1",
556
- name: "testAction",
557
- arguments: { param: "value" },
558
- });
559
-
560
- const actions = {
561
- testAction: {
562
- name: "testAction",
563
- // No render functions provided
564
- },
565
- };
566
-
567
- const result = gqlToAGUI([actionExecMsg], actions);
568
-
569
- expect(result[0]).toMatchObject({
570
- id: "action-1",
571
- role: "assistant",
572
- name: "testAction",
573
- content: "",
574
- toolCalls: [
575
- {
576
- id: "action-1",
577
- function: {
578
- name: "testAction",
579
- arguments: JSON.stringify({ param: "value" }),
580
- },
581
- type: "function",
582
- },
583
- ],
584
- });
585
-
586
- // Should have undefined generativeUI functions
587
- expect((result[0] as any).generativeUI).toBeUndefined();
588
- });
589
-
590
- test("should handle action not found in actions context", () => {
591
- const actionExecMsg = new gql.ActionExecutionMessage({
592
- id: "action-1",
593
- name: "unknownAction",
594
- arguments: { param: "value" },
595
- });
596
-
597
- const actions = {
598
- testAction: {
599
- name: "testAction",
600
- render: () => "Test",
601
- },
602
- };
603
-
604
- const result = gqlToAGUI([actionExecMsg], actions);
605
-
606
- expect(result).toHaveLength(1);
607
- expect(result[0]).toEqual({
608
- id: "action-1",
609
- role: "assistant",
610
- name: "unknownAction",
611
- toolCalls: [
612
- {
613
- id: "action-1",
614
- function: {
615
- name: "unknownAction",
616
- arguments: JSON.stringify({ param: "value" }),
617
- },
618
- type: "function",
619
- },
620
- ],
621
- });
622
-
623
- // Should not have generativeUI functions when action not found
624
- expect(result[0]).not.toHaveProperty("generativeUI");
625
- });
626
-
627
- test("should handle agent state messages with coAgentStateRenders", () => {
628
- const agentStateMsg = new gql.AgentStateMessage({
629
- id: "agent-state-1",
630
- agentName: "testAgent",
631
- state: { status: "running", data: "test data" },
632
- role: gql.Role.assistant,
633
- });
634
-
635
- const mockRender = vi.fn();
636
- const coAgentStateRenders = {
637
- testAgent: {
638
- name: "testAgent",
639
- render: mockRender,
640
- },
641
- };
642
-
643
- const result = gqlToAGUI([agentStateMsg], undefined, coAgentStateRenders);
644
-
645
- expect(result).toHaveLength(1);
646
- expect(result[0]).toEqual({
647
- id: "agent-state-1",
648
- role: "assistant",
649
- agentName: "testAgent",
650
- state: { status: "running", data: "test data" },
651
- generativeUI: expect.any(Function),
652
- });
653
-
654
- // Should have generativeUI function
655
- expect(result[0]).toHaveProperty("generativeUI");
656
- expect(typeof (result[0] as any).generativeUI).toBe("function");
657
-
658
- // Call the generativeUI function
659
- (result[0] as any).generativeUI?.();
660
-
661
- expect(mockRender).toHaveBeenCalledWith({
662
- state: { status: "running", data: "test data" },
663
- });
664
- });
665
-
666
- test("should handle agent state messages without coAgentStateRenders", () => {
667
- const agentStateMsg = new gql.AgentStateMessage({
668
- id: "agent-state-1",
669
- agentName: "testAgent",
670
- state: { status: "running", data: "test data" },
671
- role: gql.Role.assistant,
672
- });
673
-
674
- const result = gqlToAGUI([agentStateMsg]);
675
-
676
- expect(result).toHaveLength(1);
677
- expect(result[0]).toEqual({
678
- id: "agent-state-1",
679
- role: "assistant",
680
- agentName: "testAgent",
681
- state: { status: "running", data: "test data" },
682
- });
683
-
684
- // Should not have generativeUI functions without coAgentStateRenders
685
- expect(result[0]).not.toHaveProperty("generativeUI");
686
- });
687
-
688
- test("should handle agent state messages with agent not found in coAgentStateRenders", () => {
689
- const agentStateMsg = new gql.AgentStateMessage({
690
- id: "agent-state-1",
691
- agentName: "unknownAgent",
692
- state: { status: "running", data: "test data" },
693
- role: gql.Role.assistant,
694
- });
695
-
696
- const coAgentStateRenders = {
697
- testAgent: {
698
- name: "testAgent",
699
- render: () => "Test",
700
- },
701
- };
702
-
703
- const result = gqlToAGUI([agentStateMsg], undefined, coAgentStateRenders);
704
-
705
- expect(result).toHaveLength(1);
706
- expect(result[0]).toEqual({
707
- id: "agent-state-1",
708
- role: "assistant",
709
- agentName: "unknownAgent",
710
- state: { status: "running", data: "test data" },
711
- });
712
-
713
- // Should not have generativeUI functions when agent not found
714
- expect(result[0]).not.toHaveProperty("generativeUI");
715
- });
716
-
717
- test("should handle user role messages", () => {
718
- const userMsg = new gql.TextMessage({
719
- id: "user-1",
720
- content: "Hello from user",
721
- role: gql.Role.user,
722
- });
723
-
724
- const result = gqlToAGUI([userMsg]);
725
-
726
- expect(result).toHaveLength(1);
727
- expect(result[0]).toEqual({
728
- id: "user-1",
729
- role: "user",
730
- content: "Hello from user",
731
- });
732
- });
733
-
734
- test("should handle mixed message types including agent state messages", () => {
735
- const textMsg = new gql.TextMessage({
736
- id: "text-1",
737
- content: "Hello",
738
- role: gql.Role.assistant,
739
- });
740
-
741
- const agentStateMsg = new gql.AgentStateMessage({
742
- id: "agent-state-1",
743
- agentName: "testAgent",
744
- state: { status: "running" },
745
- role: gql.Role.assistant,
746
- });
747
-
748
- const mockRender = vi.fn();
749
- const coAgentStateRenders = {
750
- testAgent: {
751
- name: "testAgent",
752
- render: mockRender,
753
- },
754
- };
755
-
756
- const result = gqlToAGUI(
757
- [textMsg, agentStateMsg],
758
- undefined,
759
- coAgentStateRenders,
760
- );
761
-
762
- expect(result).toHaveLength(2);
763
- expect(result[0]).toEqual({
764
- id: "text-1",
765
- role: "assistant",
766
- content: "Hello",
767
- });
768
- expect(result[1]).toMatchObject({
769
- id: "agent-state-1",
770
- role: "assistant",
771
- agentName: "testAgent",
772
- state: { status: "running" },
773
- generativeUI: expect.any(Function),
774
- });
775
- expect(result[1]).toHaveProperty("generativeUI");
776
- });
777
- });
778
-
779
- describe("gqlImageMessageToAGUIMessage", () => {
780
- test("should throw error for invalid image format", () => {
781
- const invalidImageMsg = new gql.ImageMessage({
782
- id: "img-1",
783
- format: "bmp", // not in VALID_IMAGE_FORMATS
784
- bytes: "somebase64string",
785
- role: gql.Role.user,
786
- });
787
- expect(() => gqlImageMessageToAGUIMessage(invalidImageMsg)).toThrow(
788
- "Invalid image format",
789
- );
790
- });
791
-
792
- test("should throw error for empty image bytes", () => {
793
- const invalidImageMsg = new gql.ImageMessage({
794
- id: "img-2",
795
- format: "jpeg",
796
- bytes: "",
797
- role: gql.Role.user,
798
- });
799
- expect(() => gqlImageMessageToAGUIMessage(invalidImageMsg)).toThrow(
800
- "Image bytes must be a non-empty string",
801
- );
802
- });
803
-
804
- test("should convert valid image message", () => {
805
- const validImageMsg = new gql.ImageMessage({
806
- id: "img-3",
807
- format: "jpeg",
808
- bytes: "somebase64string",
809
- role: gql.Role.user,
810
- });
811
- const result = gqlImageMessageToAGUIMessage(validImageMsg);
812
- expect(result).toMatchObject({
813
- id: "img-3",
814
- role: "user",
815
- content: "",
816
- image: {
817
- format: "jpeg",
818
- bytes: "somebase64string",
819
- },
820
- });
821
- });
822
-
823
- test("should convert valid user image message", () => {
824
- const validImageMsg = new gql.ImageMessage({
825
- id: "img-user-1",
826
- format: "jpeg",
827
- bytes: "userbase64string",
828
- role: gql.Role.user,
829
- });
830
- const result = gqlImageMessageToAGUIMessage(validImageMsg);
831
- expect(result).toMatchObject({
832
- id: "img-user-1",
833
- role: "user",
834
- content: "",
835
- image: {
836
- format: "jpeg",
837
- bytes: "userbase64string",
838
- },
839
- });
840
- });
841
-
842
- test("should convert valid assistant image message", () => {
843
- const validImageMsg = new gql.ImageMessage({
844
- id: "img-assistant-1",
845
- format: "png",
846
- bytes: "assistantbase64string",
847
- role: gql.Role.assistant,
848
- });
849
- const result = gqlImageMessageToAGUIMessage(validImageMsg);
850
- expect(result).toMatchObject({
851
- id: "img-assistant-1",
852
- role: "assistant",
853
- content: "",
854
- image: {
855
- format: "png",
856
- bytes: "assistantbase64string",
857
- },
858
- });
859
- });
860
- });
861
-
862
- describe("Wild Card Actions", () => {
863
- test("should handle action execution with specific action", () => {
864
- const actions = {
865
- testAction: {
866
- name: "testAction",
867
- render: vi.fn((props) => `Rendered: ${props.args.test}`),
868
- },
869
- };
870
-
871
- const actionExecMsg = new gql.ActionExecutionMessage({
872
- id: "action-1",
873
- name: "testAction",
874
- arguments: { test: "value" },
875
- parentMessageId: "parent-1",
876
- });
877
-
878
- const result = gqlActionExecutionMessageToAGUIMessage(
879
- actionExecMsg,
880
- actions,
881
- );
882
-
883
- expect(result).toMatchObject({
884
- id: "action-1",
885
- role: "assistant",
886
- content: "",
887
- toolCalls: [
888
- {
889
- id: "action-1",
890
- function: {
891
- name: "testAction",
892
- arguments: '{"test":"value"}',
893
- },
894
- type: "function",
895
- },
896
- ],
897
- generativeUI: expect.any(Function),
898
- name: "testAction",
899
- });
900
- });
901
-
902
- test("should handle action execution with wild card action", () => {
903
- const actions = {
904
- "*": {
905
- name: "*",
906
- render: vi.fn((props) => `Wildcard rendered: ${props.args.test}`),
907
- },
908
- };
909
-
910
- const actionExecMsg = new gql.ActionExecutionMessage({
911
- id: "action-2",
912
- name: "unknownAction",
913
- arguments: { test: "wildcard-value" },
914
- parentMessageId: "parent-2",
915
- });
916
-
917
- const result = gqlActionExecutionMessageToAGUIMessage(
918
- actionExecMsg,
919
- actions,
920
- );
921
-
922
- expect(result).toMatchObject({
923
- id: "action-2",
924
- role: "assistant",
925
- content: "",
926
- toolCalls: [
927
- {
928
- id: "action-2",
929
- function: {
930
- name: "unknownAction",
931
- arguments: '{"test":"wildcard-value"}',
932
- },
933
- type: "function",
934
- },
935
- ],
936
- generativeUI: expect.any(Function),
937
- name: "unknownAction",
938
- });
939
- });
940
-
941
- test("should pass tool name to wildcard action render function", () => {
942
- const mockRender = vi.fn(
943
- (props) =>
944
- `Wildcard rendered: ${props.name} with args: ${JSON.stringify(props.args)}`,
945
- );
946
- const actions = {
947
- "*": {
948
- name: "*",
949
- render: mockRender,
950
- },
951
- };
952
-
953
- const actionExecMsg = new gql.ActionExecutionMessage({
954
- id: "action-wildcard-name",
955
- name: "testTool",
956
- arguments: { param: "value" },
957
- parentMessageId: "parent-wildcard-name",
958
- });
959
-
960
- const result = gqlActionExecutionMessageToAGUIMessage(
961
- actionExecMsg,
962
- actions,
963
- );
964
-
965
- // Call the generativeUI function to trigger the render
966
- (result as any).generativeUI?.();
967
-
968
- // Verify that the render function was called with the name property
969
- expect(mockRender).toHaveBeenCalledWith(
970
- expect.objectContaining({
971
- name: "testTool",
972
- args: { param: "value" },
973
- }),
974
- );
975
- });
976
-
977
- test("should pass tool name to regular action render function", () => {
978
- const mockRender = vi.fn(
979
- (props) => `Regular action rendered: ${JSON.stringify(props.args)}`,
980
- );
981
- const actions = {
982
- testAction: {
983
- name: "testAction",
984
- render: mockRender,
985
- },
986
- };
987
-
988
- const actionExecMsg = new gql.ActionExecutionMessage({
989
- id: "action-regular-name",
990
- name: "testAction",
991
- arguments: { param: "value" },
992
- parentMessageId: "parent-regular-name",
993
- });
994
-
995
- const result = gqlActionExecutionMessageToAGUIMessage(
996
- actionExecMsg,
997
- actions,
998
- );
999
-
1000
- // Call the generativeUI function to trigger the render
1001
- (result as any).generativeUI?.();
1002
-
1003
- // Verify that the render function was called with the correct props
1004
- // Regular actions should NOT have the name property
1005
- expect(mockRender).toHaveBeenCalledWith(
1006
- expect.objectContaining({
1007
- args: { param: "value" },
1008
- // name property should NOT be present for regular actions
1009
- }),
1010
- );
1011
-
1012
- // Verify that the name property is NOT present
1013
- const callArgs = mockRender.mock.calls[0][0];
1014
- expect(callArgs).not.toHaveProperty("name");
1015
- });
1016
-
1017
- test("should prioritize specific action over wild card action", () => {
1018
- const actions = {
1019
- specificAction: {
1020
- name: "specificAction",
1021
- render: vi.fn((props) => "Specific action rendered"),
1022
- },
1023
- "*": {
1024
- name: "*",
1025
- render: vi.fn((props) => "Wildcard action rendered"),
1026
- },
1027
- };
1028
-
1029
- const actionExecMsg = new gql.ActionExecutionMessage({
1030
- id: "action-3",
1031
- name: "specificAction",
1032
- arguments: { test: "value" },
1033
- parentMessageId: "parent-3",
1034
- });
1035
-
1036
- const result = gqlActionExecutionMessageToAGUIMessage(
1037
- actionExecMsg,
1038
- actions,
1039
- );
1040
-
1041
- expect(result).toMatchObject({
1042
- id: "action-3",
1043
- role: "assistant",
1044
- content: "",
1045
- toolCalls: [
1046
- {
1047
- id: "action-3",
1048
- function: {
1049
- name: "specificAction",
1050
- arguments: '{"test":"value"}',
1051
- },
1052
- type: "function",
1053
- },
1054
- ],
1055
- generativeUI: expect.any(Function),
1056
- name: "specificAction",
1057
- });
1058
- });
1059
-
1060
- test("should handle action execution without any matching actions", () => {
1061
- const actions = {
1062
- otherAction: {
1063
- name: "otherAction",
1064
- render: vi.fn(),
1065
- },
1066
- };
1067
-
1068
- const actionExecMsg = new gql.ActionExecutionMessage({
1069
- id: "action-4",
1070
- name: "unmatchedAction",
1071
- arguments: { test: "value" },
1072
- parentMessageId: "parent-4",
1073
- });
1074
-
1075
- const result = gqlActionExecutionMessageToAGUIMessage(
1076
- actionExecMsg,
1077
- actions,
1078
- );
1079
-
1080
- expect(result).toMatchObject({
1081
- id: "action-4",
1082
- role: "assistant",
1083
- toolCalls: [
1084
- {
1085
- id: "action-4",
1086
- function: {
1087
- name: "unmatchedAction",
1088
- arguments: '{"test":"value"}',
1089
- },
1090
- type: "function",
1091
- },
1092
- ],
1093
- name: "unmatchedAction",
1094
- });
1095
- expect(result).not.toHaveProperty("generativeUI");
1096
- });
1097
-
1098
- test("should handle action execution with no actions provided", () => {
1099
- const actionExecMsg = new gql.ActionExecutionMessage({
1100
- id: "action-5",
1101
- name: "anyAction",
1102
- arguments: { test: "value" },
1103
- parentMessageId: "parent-5",
1104
- });
1105
-
1106
- const result = gqlActionExecutionMessageToAGUIMessage(actionExecMsg);
1107
-
1108
- expect(result).toMatchObject({
1109
- id: "action-5",
1110
- role: "assistant",
1111
- toolCalls: [
1112
- {
1113
- id: "action-5",
1114
- function: {
1115
- name: "anyAction",
1116
- arguments: '{"test":"value"}',
1117
- },
1118
- type: "function",
1119
- },
1120
- ],
1121
- name: "anyAction",
1122
- });
1123
- expect(result).not.toHaveProperty("generativeUI");
1124
- });
1125
-
1126
- test("should handle action execution with completed result", () => {
1127
- const actions = {
1128
- "*": {
1129
- name: "*",
1130
- render: vi.fn((props) => `Result: ${props.result}`),
1131
- },
1132
- };
1133
-
1134
- const actionExecMsg = new gql.ActionExecutionMessage({
1135
- id: "action-6",
1136
- name: "testAction",
1137
- arguments: { test: "value" },
1138
- parentMessageId: "parent-6",
1139
- });
1140
-
1141
- const actionResults = new Map([["action-6", "completed result"]]);
1142
-
1143
- const result = gqlActionExecutionMessageToAGUIMessage(
1144
- actionExecMsg,
1145
- actions,
1146
- actionResults,
1147
- );
1148
-
1149
- expect(result).toMatchObject({
1150
- id: "action-6",
1151
- role: "assistant",
1152
- content: "",
1153
- toolCalls: [
1154
- {
1155
- id: "action-6",
1156
- function: {
1157
- name: "testAction",
1158
- arguments: '{"test":"value"}',
1159
- },
1160
- type: "function",
1161
- },
1162
- ],
1163
- generativeUI: expect.any(Function),
1164
- name: "testAction",
1165
- });
1166
- });
1167
-
1168
- test("should handle action execution with executing status", () => {
1169
- const actions = {
1170
- "*": {
1171
- name: "*",
1172
- render: vi.fn((props) => `Status: ${props.status}`),
1173
- },
1174
- };
1175
-
1176
- const actionExecMsg = new gql.ActionExecutionMessage({
1177
- id: "action-7",
1178
- name: "testAction",
1179
- arguments: { test: "value" },
1180
- parentMessageId: "parent-7",
1181
- status: { code: MessageStatusCode.Success },
1182
- });
1183
-
1184
- const result = gqlActionExecutionMessageToAGUIMessage(
1185
- actionExecMsg,
1186
- actions,
1187
- );
1188
-
1189
- expect(result).toMatchObject({
1190
- id: "action-7",
1191
- role: "assistant",
1192
- content: "",
1193
- toolCalls: [
1194
- {
1195
- id: "action-7",
1196
- function: {
1197
- name: "testAction",
1198
- arguments: '{"test":"value"}',
1199
- },
1200
- type: "function",
1201
- },
1202
- ],
1203
- generativeUI: expect.any(Function),
1204
- name: "testAction",
1205
- });
1206
- });
1207
-
1208
- test("should handle action execution with pending status", () => {
1209
- const actions = {
1210
- "*": {
1211
- name: "*",
1212
- render: vi.fn((props) => `Status: ${props.status}`),
1213
- },
1214
- };
1215
-
1216
- const actionExecMsg = new gql.ActionExecutionMessage({
1217
- id: "action-8",
1218
- name: "testAction",
1219
- arguments: { test: "value" },
1220
- parentMessageId: "parent-8",
1221
- status: { code: MessageStatusCode.Pending },
1222
- });
1223
-
1224
- const result = gqlActionExecutionMessageToAGUIMessage(
1225
- actionExecMsg,
1226
- actions,
1227
- );
1228
-
1229
- expect(result).toMatchObject({
1230
- id: "action-8",
1231
- role: "assistant",
1232
- content: "",
1233
- toolCalls: [
1234
- {
1235
- id: "action-8",
1236
- function: {
1237
- name: "testAction",
1238
- arguments: '{"test":"value"}',
1239
- },
1240
- type: "function",
1241
- },
1242
- ],
1243
- generativeUI: expect.any(Function),
1244
- name: "testAction",
1245
- });
1246
- });
1247
-
1248
- test("should handle action execution with failed status", () => {
1249
- const actions = {
1250
- "*": {
1251
- name: "*",
1252
- render: vi.fn((props) => `Status: ${props.status}`),
1253
- },
1254
- };
1255
-
1256
- const actionExecMsg = new gql.ActionExecutionMessage({
1257
- id: "action-9",
1258
- name: "testAction",
1259
- arguments: { test: "value" },
1260
- parentMessageId: "parent-9",
1261
- status: { code: MessageStatusCode.Failed },
1262
- });
1263
-
1264
- const result = gqlActionExecutionMessageToAGUIMessage(
1265
- actionExecMsg,
1266
- actions,
1267
- );
1268
-
1269
- expect(result).toMatchObject({
1270
- id: "action-9",
1271
- role: "assistant",
1272
- content: "",
1273
- toolCalls: [
1274
- {
1275
- id: "action-9",
1276
- function: {
1277
- name: "testAction",
1278
- arguments: '{"test":"value"}',
1279
- },
1280
- type: "function",
1281
- },
1282
- ],
1283
- generativeUI: expect.any(Function),
1284
- name: "testAction",
1285
- });
1286
- });
1287
-
1288
- test("should handle action execution with undefined status", () => {
1289
- const actions = {
1290
- "*": {
1291
- name: "*",
1292
- render: vi.fn((props) => `Status: ${props.status}`),
1293
- },
1294
- };
1295
-
1296
- const actionExecMsg = new gql.ActionExecutionMessage({
1297
- id: "action-10",
1298
- name: "testAction",
1299
- arguments: { test: "value" },
1300
- parentMessageId: "parent-10",
1301
- // No status field
1302
- });
1303
-
1304
- const result = gqlActionExecutionMessageToAGUIMessage(
1305
- actionExecMsg,
1306
- actions,
1307
- );
1308
-
1309
- expect(result).toMatchObject({
1310
- id: "action-10",
1311
- role: "assistant",
1312
- content: "",
1313
- toolCalls: [
1314
- {
1315
- id: "action-10",
1316
- function: {
1317
- name: "testAction",
1318
- arguments: '{"test":"value"}',
1319
- },
1320
- type: "function",
1321
- },
1322
- ],
1323
- generativeUI: expect.any(Function),
1324
- name: "testAction",
1325
- });
1326
- });
1327
-
1328
- test("should handle action execution with empty arguments", () => {
1329
- const actions = {
1330
- "*": {
1331
- name: "*",
1332
- render: vi.fn((props) => `Args: ${JSON.stringify(props.args)}`),
1333
- },
1334
- };
1335
-
1336
- const actionExecMsg = new gql.ActionExecutionMessage({
1337
- id: "action-11",
1338
- name: "testAction",
1339
- arguments: {},
1340
- parentMessageId: "parent-11",
1341
- });
1342
-
1343
- const result = gqlActionExecutionMessageToAGUIMessage(
1344
- actionExecMsg,
1345
- actions,
1346
- );
1347
-
1348
- expect(result).toMatchObject({
1349
- id: "action-11",
1350
- role: "assistant",
1351
- content: "",
1352
- toolCalls: [
1353
- {
1354
- id: "action-11",
1355
- function: {
1356
- name: "testAction",
1357
- arguments: "{}",
1358
- },
1359
- type: "function",
1360
- },
1361
- ],
1362
- generativeUI: expect.any(Function),
1363
- name: "testAction",
1364
- });
1365
- });
1366
-
1367
- test("should handle action execution with null arguments", () => {
1368
- const actions = {
1369
- "*": {
1370
- name: "*",
1371
- render: vi.fn((props) => `Args: ${JSON.stringify(props.args)}`),
1372
- },
1373
- };
1374
-
1375
- const actionExecMsg = new gql.ActionExecutionMessage({
1376
- id: "action-12",
1377
- name: "testAction",
1378
- arguments: null as any,
1379
- parentMessageId: "parent-12",
1380
- });
1381
-
1382
- const result = gqlActionExecutionMessageToAGUIMessage(
1383
- actionExecMsg,
1384
- actions,
1385
- );
1386
-
1387
- expect(result).toMatchObject({
1388
- id: "action-12",
1389
- role: "assistant",
1390
- content: "",
1391
- toolCalls: [
1392
- {
1393
- id: "action-12",
1394
- function: {
1395
- name: "testAction",
1396
- arguments: "null",
1397
- },
1398
- type: "function",
1399
- },
1400
- ],
1401
- generativeUI: expect.any(Function),
1402
- name: "testAction",
1403
- });
1404
- });
1405
-
1406
- test("should handle action execution with complex nested arguments", () => {
1407
- const actions = {
1408
- "*": {
1409
- name: "*",
1410
- render: vi.fn((props) => `Complex: ${JSON.stringify(props.args)}`),
1411
- },
1412
- };
1413
-
1414
- const complexArgs = {
1415
- nested: {
1416
- array: [1, 2, 3],
1417
- object: { key: "value" },
1418
- nullValue: null,
1419
- undefinedValue: undefined,
1420
- },
1421
- string: "test",
1422
- number: 42,
1423
- boolean: true,
1424
- };
1425
-
1426
- const actionExecMsg = new gql.ActionExecutionMessage({
1427
- id: "action-13",
1428
- name: "testAction",
1429
- arguments: complexArgs,
1430
- parentMessageId: "parent-13",
1431
- });
1432
-
1433
- const result = gqlActionExecutionMessageToAGUIMessage(
1434
- actionExecMsg,
1435
- actions,
1436
- );
1437
-
1438
- expect(result).toMatchObject({
1439
- id: "action-13",
1440
- role: "assistant",
1441
- content: "",
1442
- toolCalls: [
1443
- {
1444
- id: "action-13",
1445
- function: {
1446
- name: "testAction",
1447
- arguments: JSON.stringify(complexArgs),
1448
- },
1449
- type: "function",
1450
- },
1451
- ],
1452
- generativeUI: expect.any(Function),
1453
- name: "testAction",
1454
- });
1455
- });
1456
-
1457
- test("should handle multiple wild card actions (should use first one)", () => {
1458
- const actions = {
1459
- wildcard1: {
1460
- name: "*",
1461
- render: vi.fn((props) => "First wildcard"),
1462
- },
1463
- wildcard2: {
1464
- name: "*",
1465
- render: vi.fn((props) => "Second wildcard"),
1466
- },
1467
- };
1468
-
1469
- const actionExecMsg = new gql.ActionExecutionMessage({
1470
- id: "action-14",
1471
- name: "unknownAction",
1472
- arguments: { test: "value" },
1473
- parentMessageId: "parent-14",
1474
- });
1475
-
1476
- const result = gqlActionExecutionMessageToAGUIMessage(
1477
- actionExecMsg,
1478
- actions,
1479
- );
1480
-
1481
- expect(result).toMatchObject({
1482
- id: "action-14",
1483
- role: "assistant",
1484
- content: "",
1485
- toolCalls: [
1486
- {
1487
- id: "action-14",
1488
- function: {
1489
- name: "unknownAction",
1490
- arguments: '{"test":"value"}',
1491
- },
1492
- type: "function",
1493
- },
1494
- ],
1495
- generativeUI: expect.any(Function),
1496
- name: "unknownAction",
1497
- });
1498
- });
1499
-
1500
- test("should parse string results in generativeUI props", () => {
1501
- const actions = {
1502
- "*": {
1503
- name: "*",
1504
- render: vi.fn((props) => `Result: ${JSON.stringify(props.result)}`),
1505
- },
1506
- };
1507
-
1508
- const actionExecMsg = new gql.ActionExecutionMessage({
1509
- id: "action-string-result",
1510
- name: "stringResultAction",
1511
- arguments: { test: "value" },
1512
- parentMessageId: "parent-string",
1513
- });
1514
-
1515
- const actionResults = new Map<string, string>();
1516
- actionResults.set(
1517
- "action-string-result",
1518
- '{"parsed": true, "value": 42}',
1519
- );
1520
-
1521
- const result = gqlActionExecutionMessageToAGUIMessage(
1522
- actionExecMsg,
1523
- actions,
1524
- actionResults,
1525
- );
1526
-
1527
- expect((result as AIMessage).generativeUI).toBeDefined();
1528
- // Call the render function to test the result parsing
1529
- const renderResult = (result as AIMessage).generativeUI!({
1530
- result: '{"from": "props", "data": "test"}',
1531
- });
1532
-
1533
- // Verify the render function was called and the result was parsed
1534
- expect(actions["*"].render).toHaveBeenCalledWith(
1535
- expect.objectContaining({
1536
- result: { from: "props", data: "test" }, // Should be parsed from string
1537
- args: { test: "value" },
1538
- status: "complete",
1539
- messageId: "action-string-result",
1540
- }),
1541
- );
1542
- });
1543
-
1544
- test("should handle malformed JSON strings gracefully in results", () => {
1545
- const actions = {
1546
- "*": {
1547
- name: "*",
1548
- render: vi.fn((props) => `Result: ${JSON.stringify(props.result)}`),
1549
- },
1550
- };
1551
-
1552
- const actionExecMsg = new gql.ActionExecutionMessage({
1553
- id: "action-malformed",
1554
- name: "malformedAction",
1555
- arguments: { test: "value" },
1556
- parentMessageId: "parent-malformed",
1557
- });
1558
-
1559
- const actionResults = new Map<string, string>();
1560
- actionResults.set("action-malformed", "invalid json {");
1561
-
1562
- const result = gqlActionExecutionMessageToAGUIMessage(
1563
- actionExecMsg,
1564
- actions,
1565
- actionResults,
1566
- );
1567
-
1568
- expect((result as AIMessage).generativeUI).toBeDefined();
1569
- // Call the render function to test malformed JSON handling
1570
- const renderResult = (result as AIMessage).generativeUI!({
1571
- result: "invalid json {",
1572
- });
1573
-
1574
- // Verify the render function was called with the original string (unparsed)
1575
- expect(actions["*"].render).toHaveBeenCalledWith(
1576
- expect.objectContaining({
1577
- result: "invalid json {", // Should remain as string due to parse error
1578
- args: { test: "value" },
1579
- status: "complete",
1580
- messageId: "action-malformed",
1581
- }),
1582
- );
1583
- });
1584
-
1585
- test("should handle non-string results without parsing", () => {
1586
- const actions = {
1587
- "*": {
1588
- name: "*",
1589
- render: vi.fn((props) => `Result: ${JSON.stringify(props.result)}`),
1590
- },
1591
- };
1592
-
1593
- const actionExecMsg = new gql.ActionExecutionMessage({
1594
- id: "action-object-result",
1595
- name: "objectResultAction",
1596
- arguments: { test: "value" },
1597
- parentMessageId: "parent-object",
1598
- });
1599
-
1600
- const actionResults = new Map<string, string>();
1601
- actionResults.set("action-object-result", '{"already": "parsed"}');
1602
-
1603
- const result = gqlActionExecutionMessageToAGUIMessage(
1604
- actionExecMsg,
1605
- actions,
1606
- actionResults,
1607
- );
1608
-
1609
- expect((result as AIMessage).generativeUI).toBeDefined();
1610
- // Call the render function with an object result
1611
- const renderResult = (result as AIMessage).generativeUI!({
1612
- result: { from: "props", data: "object" },
1613
- });
1614
-
1615
- // Verify the render function was called with the object as-is
1616
- expect(actions["*"].render).toHaveBeenCalledWith(
1617
- expect.objectContaining({
1618
- result: { from: "props", data: "object" }, // Should remain as object
1619
- args: { test: "value" },
1620
- status: "complete",
1621
- messageId: "action-object-result",
1622
- }),
1623
- );
1624
- });
1625
-
1626
- test("should handle action execution arguments correctly with simplified conversion", () => {
1627
- const actionExecMsg = new gql.ActionExecutionMessage({
1628
- id: "action-simplified",
1629
- name: "simplifiedAction",
1630
- arguments: { complex: { nested: "value" }, array: [1, 2, 3] },
1631
- parentMessageId: "parent-simplified",
1632
- });
1633
-
1634
- const result = gqlActionExecutionMessageToAGUIMessage(actionExecMsg);
1635
-
1636
- expect(result).toMatchObject({
1637
- id: "action-simplified",
1638
- role: "assistant",
1639
- toolCalls: [
1640
- {
1641
- id: "action-simplified",
1642
- function: {
1643
- name: "simplifiedAction",
1644
- arguments: '{"complex":{"nested":"value"},"array":[1,2,3]}',
1645
- },
1646
- type: "function",
1647
- },
1648
- ],
1649
- name: "simplifiedAction",
1650
- });
1651
- });
1652
- });
1653
- });