@adonis-agora/agent 0.61.0 → 0.63.0

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 (664) hide show
  1. package/CHANGELOG.md +91 -0
  2. package/README.md +12 -7
  3. package/dist/configure.d.ts +7 -5
  4. package/dist/configure.d.ts.map +1 -1
  5. package/dist/configure.js +7 -5
  6. package/dist/configure.js.map +1 -1
  7. package/dist/providers/a2a_provider.d.ts +14 -0
  8. package/dist/providers/a2a_provider.d.ts.map +1 -0
  9. package/dist/providers/a2a_provider.js +136 -0
  10. package/dist/providers/a2a_provider.js.map +1 -0
  11. package/dist/providers/agent_provider.d.ts.map +1 -1
  12. package/dist/providers/agent_provider.js +81 -25
  13. package/dist/providers/agent_provider.js.map +1 -1
  14. package/dist/providers/mcp_provider.d.ts +3 -0
  15. package/dist/providers/mcp_provider.d.ts.map +1 -1
  16. package/dist/providers/mcp_provider.js +147 -62
  17. package/dist/providers/mcp_provider.js.map +1 -1
  18. package/dist/src/a2a/auth.d.ts +67 -0
  19. package/dist/src/a2a/auth.d.ts.map +1 -0
  20. package/dist/src/a2a/auth.js +47 -0
  21. package/dist/src/a2a/auth.js.map +1 -0
  22. package/dist/src/a2a/define_config.d.ts +74 -0
  23. package/dist/src/a2a/define_config.d.ts.map +1 -0
  24. package/dist/src/a2a/define_config.js +5 -0
  25. package/dist/src/a2a/define_config.js.map +1 -0
  26. package/dist/src/a2a/gate.d.ts +23 -0
  27. package/dist/src/a2a/gate.d.ts.map +1 -0
  28. package/dist/src/a2a/gate.js +56 -0
  29. package/dist/src/a2a/gate.js.map +1 -0
  30. package/dist/src/a2a/handler.d.ts +65 -0
  31. package/dist/src/a2a/handler.d.ts.map +1 -0
  32. package/dist/src/a2a/handler.js +322 -0
  33. package/dist/src/a2a/handler.js.map +1 -0
  34. package/dist/src/a2a/index.d.ts +15 -0
  35. package/dist/src/a2a/index.d.ts.map +1 -0
  36. package/dist/src/a2a/index.js +9 -0
  37. package/dist/src/a2a/index.js.map +1 -0
  38. package/dist/src/a2a/permission-tool.d.ts +17 -0
  39. package/dist/src/a2a/permission-tool.d.ts.map +1 -0
  40. package/dist/src/a2a/permission-tool.js +70 -0
  41. package/dist/src/a2a/permission-tool.js.map +1 -0
  42. package/dist/src/a2a/protocol.d.ts +100 -0
  43. package/dist/src/a2a/protocol.d.ts.map +1 -0
  44. package/dist/src/a2a/protocol.js +106 -0
  45. package/dist/src/a2a/protocol.js.map +1 -0
  46. package/dist/src/a2a/runtime.d.ts +6 -0
  47. package/dist/src/a2a/runtime.d.ts.map +1 -0
  48. package/dist/src/a2a/runtime.js +13 -0
  49. package/dist/src/a2a/runtime.js.map +1 -0
  50. package/dist/src/a2a/server_middleware.d.ts +13 -0
  51. package/dist/src/a2a/server_middleware.d.ts.map +1 -0
  52. package/dist/src/a2a/server_middleware.js +18 -0
  53. package/dist/src/a2a/server_middleware.js.map +1 -0
  54. package/dist/src/a2a/store.d.ts +79 -0
  55. package/dist/src/a2a/store.d.ts.map +1 -0
  56. package/dist/src/a2a/store.js +151 -0
  57. package/dist/src/a2a/store.js.map +1 -0
  58. package/dist/src/a2a/turn.d.ts +80 -0
  59. package/dist/src/a2a/turn.d.ts.map +1 -0
  60. package/dist/src/a2a/turn.js +211 -0
  61. package/dist/src/a2a/turn.js.map +1 -0
  62. package/dist/src/action-proposal-executor.d.ts +3 -0
  63. package/dist/src/action-proposal-executor.d.ts.map +1 -1
  64. package/dist/src/action-proposal-executor.js +10 -0
  65. package/dist/src/action-proposal-executor.js.map +1 -1
  66. package/dist/src/action-proposal-service.d.ts +7 -2
  67. package/dist/src/action-proposal-service.d.ts.map +1 -1
  68. package/dist/src/action-proposal-service.js +21 -16
  69. package/dist/src/action-proposal-service.js.map +1 -1
  70. package/dist/src/action-proposal-text.d.ts +42 -3
  71. package/dist/src/action-proposal-text.d.ts.map +1 -1
  72. package/dist/src/action-proposal-text.js +80 -12
  73. package/dist/src/action-proposal-text.js.map +1 -1
  74. package/dist/src/action-proposal-worker.d.ts +2 -1
  75. package/dist/src/action-proposal-worker.d.ts.map +1 -1
  76. package/dist/src/action-proposal-worker.js +9 -2
  77. package/dist/src/action-proposal-worker.js.map +1 -1
  78. package/dist/src/actor-resolver.d.ts +12 -4
  79. package/dist/src/actor-resolver.d.ts.map +1 -1
  80. package/dist/src/actor-resolver.js +24 -7
  81. package/dist/src/actor-resolver.js.map +1 -1
  82. package/dist/src/ag-ui/adapter.d.ts.map +1 -1
  83. package/dist/src/ag-ui/adapter.js +115 -17
  84. package/dist/src/ag-ui/adapter.js.map +1 -1
  85. package/dist/src/ag-ui/core/encoder.d.ts +106 -0
  86. package/dist/src/ag-ui/core/encoder.d.ts.map +1 -0
  87. package/dist/src/ag-ui/core/encoder.js +534 -0
  88. package/dist/src/ag-ui/core/encoder.js.map +1 -0
  89. package/dist/src/ag-ui/core/index.d.ts +12 -0
  90. package/dist/src/ag-ui/core/index.d.ts.map +1 -0
  91. package/dist/src/ag-ui/core/index.js +12 -0
  92. package/dist/src/ag-ui/core/index.js.map +1 -0
  93. package/dist/src/ag-ui/core/input.d.ts +92 -0
  94. package/dist/src/ag-ui/core/input.d.ts.map +1 -0
  95. package/dist/src/ag-ui/core/input.js +246 -0
  96. package/dist/src/ag-ui/core/input.js.map +1 -0
  97. package/dist/src/ag-ui/core/interrupt-id.d.ts +31 -0
  98. package/dist/src/ag-ui/core/interrupt-id.d.ts.map +1 -0
  99. package/dist/src/ag-ui/core/interrupt-id.js +48 -0
  100. package/dist/src/ag-ui/core/interrupt-id.js.map +1 -0
  101. package/dist/src/ag-ui/{proposal-decision.d.ts → core/proposal-decision.d.ts} +1 -1
  102. package/dist/src/ag-ui/core/proposal-decision.d.ts.map +1 -0
  103. package/dist/src/ag-ui/{proposal-decision.js → core/proposal-decision.js} +3 -6
  104. package/dist/src/ag-ui/core/proposal-decision.js.map +1 -0
  105. package/dist/src/ag-ui/core/stream.d.ts +49 -0
  106. package/dist/src/ag-ui/core/stream.d.ts.map +1 -0
  107. package/dist/src/ag-ui/core/stream.js +90 -0
  108. package/dist/src/ag-ui/core/stream.js.map +1 -0
  109. package/dist/src/ag-ui/core/types.d.ts +249 -0
  110. package/dist/src/ag-ui/core/types.d.ts.map +1 -0
  111. package/dist/src/ag-ui/core/types.js +35 -0
  112. package/dist/src/ag-ui/core/types.js.map +1 -0
  113. package/dist/src/ag-ui/encoder.d.ts +3 -4
  114. package/dist/src/ag-ui/encoder.d.ts.map +1 -1
  115. package/dist/src/ag-ui/encoder.js +10 -11
  116. package/dist/src/ag-ui/encoder.js.map +1 -1
  117. package/dist/src/ag-ui/frames.d.ts +8 -5
  118. package/dist/src/ag-ui/frames.d.ts.map +1 -1
  119. package/dist/src/ag-ui/frames.js +21 -7
  120. package/dist/src/ag-ui/frames.js.map +1 -1
  121. package/dist/src/ag-ui/index.d.ts +3 -5
  122. package/dist/src/ag-ui/index.d.ts.map +1 -1
  123. package/dist/src/ag-ui/index.js +3 -5
  124. package/dist/src/ag-ui/index.js.map +1 -1
  125. package/dist/src/ag-ui/stream.d.ts +3 -4
  126. package/dist/src/ag-ui/stream.d.ts.map +1 -1
  127. package/dist/src/ag-ui/stream.js +4 -5
  128. package/dist/src/ag-ui/stream.js.map +1 -1
  129. package/dist/src/agent-deps-factory.d.ts +3 -0
  130. package/dist/src/agent-deps-factory.d.ts.map +1 -1
  131. package/dist/src/agent-deps-factory.js +3 -0
  132. package/dist/src/agent-deps-factory.js.map +1 -1
  133. package/dist/src/agent-deps.d.ts +3 -0
  134. package/dist/src/agent-deps.d.ts.map +1 -1
  135. package/dist/src/agent-deps.js.map +1 -1
  136. package/dist/src/agent-loop.d.ts +4 -3
  137. package/dist/src/agent-loop.d.ts.map +1 -1
  138. package/dist/src/agent-loop.js +50 -25
  139. package/dist/src/agent-loop.js.map +1 -1
  140. package/dist/src/agent-service.d.ts +46 -4
  141. package/dist/src/agent-service.d.ts.map +1 -1
  142. package/dist/src/agent-service.js +87 -11
  143. package/dist/src/agent-service.js.map +1 -1
  144. package/dist/src/ai-sdk/ai-sdk-model.js +4 -1
  145. package/dist/src/ai-sdk/ai-sdk-model.js.map +1 -1
  146. package/dist/src/ai-tool-ref.d.ts +4 -0
  147. package/dist/src/ai-tool-ref.d.ts.map +1 -1
  148. package/dist/src/ai-tool-ref.js +10 -14
  149. package/dist/src/ai-tool-ref.js.map +1 -1
  150. package/dist/src/attachment-limits.d.ts +10 -0
  151. package/dist/src/attachment-limits.d.ts.map +1 -0
  152. package/dist/src/attachment-limits.js +13 -0
  153. package/dist/src/attachment-limits.js.map +1 -0
  154. package/dist/src/channels/adapters/evolution_api.d.ts +49 -0
  155. package/dist/src/channels/adapters/evolution_api.d.ts.map +1 -0
  156. package/dist/src/channels/adapters/evolution_api.js +241 -0
  157. package/dist/src/channels/adapters/evolution_api.js.map +1 -0
  158. package/dist/src/channels/adapters/telegram.d.ts +34 -0
  159. package/dist/src/channels/adapters/telegram.d.ts.map +1 -0
  160. package/dist/src/channels/adapters/telegram.js +196 -0
  161. package/dist/src/channels/adapters/telegram.js.map +1 -0
  162. package/dist/src/channels/adapters/whatsapp_cloud.d.ts +31 -0
  163. package/dist/src/channels/adapters/whatsapp_cloud.d.ts.map +1 -0
  164. package/dist/src/channels/adapters/whatsapp_cloud.js +177 -0
  165. package/dist/src/channels/adapters/whatsapp_cloud.js.map +1 -0
  166. package/dist/src/channels/handler.d.ts +167 -0
  167. package/dist/src/channels/handler.d.ts.map +1 -0
  168. package/dist/src/channels/handler.js +569 -0
  169. package/dist/src/channels/handler.js.map +1 -0
  170. package/dist/src/channels/http.d.ts +45 -0
  171. package/dist/src/channels/http.d.ts.map +1 -0
  172. package/dist/src/channels/http.js +147 -0
  173. package/dist/src/channels/http.js.map +1 -0
  174. package/dist/src/channels/index.d.ts +16 -0
  175. package/dist/src/channels/index.d.ts.map +1 -0
  176. package/dist/src/channels/index.js +15 -0
  177. package/dist/src/channels/index.js.map +1 -0
  178. package/dist/src/channels/markdown.d.ts +12 -0
  179. package/dist/src/channels/markdown.d.ts.map +1 -0
  180. package/dist/src/channels/markdown.js +120 -0
  181. package/dist/src/channels/markdown.js.map +1 -0
  182. package/dist/src/channels/questions.d.ts +43 -0
  183. package/dist/src/channels/questions.d.ts.map +1 -0
  184. package/dist/src/channels/questions.js +90 -0
  185. package/dist/src/channels/questions.js.map +1 -0
  186. package/dist/src/channels/split.d.ts +8 -0
  187. package/dist/src/channels/split.d.ts.map +1 -0
  188. package/dist/src/channels/split.js +45 -0
  189. package/dist/src/channels/split.js.map +1 -0
  190. package/dist/src/channels/store.d.ts +78 -0
  191. package/dist/src/channels/store.d.ts.map +1 -0
  192. package/dist/src/channels/store.js +151 -0
  193. package/dist/src/channels/store.js.map +1 -0
  194. package/dist/src/channels/types.d.ts +138 -0
  195. package/dist/src/channels/types.d.ts.map +1 -0
  196. package/dist/src/channels/types.js +7 -0
  197. package/dist/src/channels/types.js.map +1 -0
  198. package/dist/src/chat-queue-service.d.ts.map +1 -1
  199. package/dist/src/chat-queue-service.js +2 -0
  200. package/dist/src/chat-queue-service.js.map +1 -1
  201. package/dist/src/define_config.d.ts +61 -12
  202. package/dist/src/define_config.d.ts.map +1 -1
  203. package/dist/src/define_config.js.map +1 -1
  204. package/dist/src/engine.d.ts +77 -0
  205. package/dist/src/engine.d.ts.map +1 -0
  206. package/dist/src/engine.js +27 -0
  207. package/dist/src/engine.js.map +1 -0
  208. package/dist/src/genui/builtins.d.ts +73 -3
  209. package/dist/src/genui/builtins.d.ts.map +1 -1
  210. package/dist/src/genui/builtins.js +357 -3
  211. package/dist/src/genui/builtins.js.map +1 -1
  212. package/dist/src/genui/capabilities.d.ts +24 -0
  213. package/dist/src/genui/capabilities.d.ts.map +1 -0
  214. package/dist/src/genui/capabilities.js +81 -0
  215. package/dist/src/genui/capabilities.js.map +1 -0
  216. package/dist/src/genui/catalog.d.ts +86 -0
  217. package/dist/src/genui/catalog.d.ts.map +1 -0
  218. package/dist/src/genui/catalog.js +96 -0
  219. package/dist/src/genui/catalog.js.map +1 -0
  220. package/dist/src/genui/factory.d.ts +7 -14
  221. package/dist/src/genui/factory.d.ts.map +1 -1
  222. package/dist/src/genui/factory.js.map +1 -1
  223. package/dist/src/genui/index.d.ts +4 -12
  224. package/dist/src/genui/index.d.ts.map +1 -1
  225. package/dist/src/genui/index.js +5 -18
  226. package/dist/src/genui/index.js.map +1 -1
  227. package/dist/src/genui/public.d.ts +9 -0
  228. package/dist/src/genui/public.d.ts.map +1 -0
  229. package/dist/src/genui/public.js +9 -0
  230. package/dist/src/genui/public.js.map +1 -0
  231. package/dist/src/genui/registry.d.ts +65 -0
  232. package/dist/src/genui/registry.d.ts.map +1 -0
  233. package/dist/src/genui/registry.js +151 -0
  234. package/dist/src/genui/registry.js.map +1 -0
  235. package/dist/src/genui/schema.d.ts +71 -0
  236. package/dist/src/genui/schema.d.ts.map +1 -0
  237. package/dist/src/genui/schema.js +304 -0
  238. package/dist/src/genui/schema.js.map +1 -0
  239. package/dist/src/genui/text.d.ts +36 -0
  240. package/dist/src/genui/text.d.ts.map +1 -0
  241. package/dist/src/genui/text.js +157 -0
  242. package/dist/src/genui/text.js.map +1 -0
  243. package/dist/src/genui/tools.d.ts +92 -0
  244. package/dist/src/genui/tools.d.ts.map +1 -0
  245. package/dist/src/genui/tools.js +291 -0
  246. package/dist/src/genui/tools.js.map +1 -0
  247. package/dist/src/genui/tree.d.ts +56 -0
  248. package/dist/src/genui/tree.d.ts.map +1 -0
  249. package/dist/src/genui/tree.js +188 -0
  250. package/dist/src/genui/tree.js.map +1 -0
  251. package/dist/src/index.d.ts +6 -3
  252. package/dist/src/index.d.ts.map +1 -1
  253. package/dist/src/index.js +4 -2
  254. package/dist/src/index.js.map +1 -1
  255. package/dist/src/mcp/auth.d.ts +17 -1
  256. package/dist/src/mcp/auth.d.ts.map +1 -1
  257. package/dist/src/mcp/auth.js +14 -3
  258. package/dist/src/mcp/auth.js.map +1 -1
  259. package/dist/src/mcp/define_config.d.ts +81 -2
  260. package/dist/src/mcp/define_config.d.ts.map +1 -1
  261. package/dist/src/mcp/define_config.js.map +1 -1
  262. package/dist/src/mcp/index.d.ts +1 -1
  263. package/dist/src/mcp/index.d.ts.map +1 -1
  264. package/dist/src/mcp/index.js.map +1 -1
  265. package/dist/src/mcp/oauth-resource.d.ts +9 -0
  266. package/dist/src/mcp/oauth-resource.d.ts.map +1 -0
  267. package/dist/src/mcp/oauth-resource.js +16 -0
  268. package/dist/src/mcp/oauth-resource.js.map +1 -0
  269. package/dist/src/mcp/server.d.ts +5 -0
  270. package/dist/src/mcp/server.d.ts.map +1 -1
  271. package/dist/src/mcp/server.js +48 -16
  272. package/dist/src/mcp/server.js.map +1 -1
  273. package/dist/src/negotiated-tool-ui.d.ts.map +1 -1
  274. package/dist/src/negotiated-tool-ui.js +12 -8
  275. package/dist/src/negotiated-tool-ui.js.map +1 -1
  276. package/dist/src/opencode/client.d.ts +202 -0
  277. package/dist/src/opencode/client.d.ts.map +1 -0
  278. package/dist/src/opencode/client.js +2 -0
  279. package/dist/src/opencode/client.js.map +1 -0
  280. package/dist/src/opencode/durable/index.d.ts +33 -0
  281. package/dist/src/opencode/durable/index.d.ts.map +1 -0
  282. package/dist/src/opencode/durable/index.js +38 -0
  283. package/dist/src/opencode/durable/index.js.map +1 -0
  284. package/dist/src/opencode/durable/runner.d.ts +36 -0
  285. package/dist/src/opencode/durable/runner.d.ts.map +1 -0
  286. package/dist/src/opencode/durable/runner.js +88 -0
  287. package/dist/src/opencode/durable/runner.js.map +1 -0
  288. package/dist/src/opencode/durable/workflow.d.ts +40 -0
  289. package/dist/src/opencode/durable/workflow.d.ts.map +1 -0
  290. package/dist/src/opencode/durable/workflow.js +106 -0
  291. package/dist/src/opencode/durable/workflow.js.map +1 -0
  292. package/dist/src/opencode/engine.d.ts +48 -0
  293. package/dist/src/opencode/engine.d.ts.map +1 -0
  294. package/dist/src/opencode/engine.js +98 -0
  295. package/dist/src/opencode/engine.js.map +1 -0
  296. package/dist/src/opencode/event-hub.d.ts +23 -0
  297. package/dist/src/opencode/event-hub.d.ts.map +1 -0
  298. package/dist/src/opencode/event-hub.js +99 -0
  299. package/dist/src/opencode/event-hub.js.map +1 -0
  300. package/dist/src/opencode/forms.d.ts +19 -0
  301. package/dist/src/opencode/forms.d.ts.map +1 -0
  302. package/dist/src/opencode/forms.js +82 -0
  303. package/dist/src/opencode/forms.js.map +1 -0
  304. package/dist/src/opencode/host.d.ts +179 -0
  305. package/dist/src/opencode/host.d.ts.map +1 -0
  306. package/dist/src/opencode/host.js +34 -0
  307. package/dist/src/opencode/host.js.map +1 -0
  308. package/dist/src/opencode/index.d.ts +15 -0
  309. package/dist/src/opencode/index.d.ts.map +1 -0
  310. package/dist/src/opencode/index.js +9 -0
  311. package/dist/src/opencode/index.js.map +1 -0
  312. package/dist/src/opencode/log.d.ts +9 -0
  313. package/dist/src/opencode/log.d.ts.map +1 -0
  314. package/dist/src/opencode/log.js +15 -0
  315. package/dist/src/opencode/log.js.map +1 -0
  316. package/dist/src/opencode/mcp.d.ts +60 -0
  317. package/dist/src/opencode/mcp.d.ts.map +1 -0
  318. package/dist/src/opencode/mcp.js +258 -0
  319. package/dist/src/opencode/mcp.js.map +1 -0
  320. package/dist/src/opencode/runner.d.ts +40 -0
  321. package/dist/src/opencode/runner.d.ts.map +1 -0
  322. package/dist/src/opencode/runner.js +125 -0
  323. package/dist/src/opencode/runner.js.map +1 -0
  324. package/dist/src/opencode/turn.d.ts +167 -0
  325. package/dist/src/opencode/turn.d.ts.map +1 -0
  326. package/dist/src/opencode/turn.js +761 -0
  327. package/dist/src/opencode/turn.js.map +1 -0
  328. package/dist/src/opencode/turns.d.ts +247 -0
  329. package/dist/src/opencode/turns.d.ts.map +1 -0
  330. package/dist/src/opencode/turns.js +867 -0
  331. package/dist/src/opencode/turns.js.map +1 -0
  332. package/dist/src/personas.d.ts.map +1 -1
  333. package/dist/src/personas.js +4 -1
  334. package/dist/src/personas.js.map +1 -1
  335. package/dist/src/react/ag-ui.d.ts +4 -2
  336. package/dist/src/react/ag-ui.d.ts.map +1 -1
  337. package/dist/src/react/ag-ui.js +2 -2
  338. package/dist/src/react/ag-ui.js.map +1 -1
  339. package/dist/src/react/client.d.ts +1 -1
  340. package/dist/src/react/client.d.ts.map +1 -1
  341. package/dist/src/react/client.js +1 -1
  342. package/dist/src/react/client.js.map +1 -1
  343. package/dist/src/react/core/ag-ui-backend.d.ts +109 -0
  344. package/dist/src/react/core/ag-ui-backend.d.ts.map +1 -0
  345. package/dist/src/react/core/ag-ui-backend.js +574 -0
  346. package/dist/src/react/core/ag-ui-backend.js.map +1 -0
  347. package/dist/src/react/core/agent-chat-transport.d.ts +187 -0
  348. package/dist/src/react/core/agent-chat-transport.d.ts.map +1 -0
  349. package/dist/src/react/core/agent-chat-transport.js +817 -0
  350. package/dist/src/react/core/agent-chat-transport.js.map +1 -0
  351. package/dist/src/react/core/approvals/countdown.d.ts +22 -0
  352. package/dist/src/react/core/approvals/countdown.d.ts.map +1 -0
  353. package/dist/src/react/core/approvals/countdown.js +39 -0
  354. package/dist/src/react/core/approvals/countdown.js.map +1 -0
  355. package/dist/src/react/core/approvals/proposals.d.ts +15 -0
  356. package/dist/src/react/core/approvals/proposals.d.ts.map +1 -0
  357. package/dist/src/react/core/approvals/proposals.js +82 -0
  358. package/dist/src/react/core/approvals/proposals.js.map +1 -0
  359. package/dist/src/react/core/approvals/use-action-proposals.d.ts +10 -0
  360. package/dist/src/react/core/approvals/use-action-proposals.d.ts.map +1 -0
  361. package/dist/src/react/core/approvals/use-action-proposals.js +86 -0
  362. package/dist/src/react/core/approvals/use-action-proposals.js.map +1 -0
  363. package/dist/src/react/core/attachments/files.d.ts +39 -0
  364. package/dist/src/react/core/attachments/files.d.ts.map +1 -0
  365. package/dist/src/react/core/attachments/files.js +89 -0
  366. package/dist/src/react/core/attachments/files.js.map +1 -0
  367. package/dist/src/react/core/attachments/use-attachments.d.ts +106 -0
  368. package/dist/src/react/core/attachments/use-attachments.d.ts.map +1 -0
  369. package/dist/src/react/core/attachments/use-attachments.js +217 -0
  370. package/dist/src/react/core/attachments/use-attachments.js.map +1 -0
  371. package/dist/src/react/core/backend.d.ts +245 -0
  372. package/dist/src/react/core/backend.d.ts.map +1 -0
  373. package/dist/src/react/core/backend.js +21 -0
  374. package/dist/src/react/core/backend.js.map +1 -0
  375. package/dist/src/react/core/background-runs.d.ts +32 -0
  376. package/dist/src/react/core/background-runs.d.ts.map +1 -0
  377. package/dist/src/react/core/background-runs.js +47 -0
  378. package/dist/src/react/core/background-runs.js.map +1 -0
  379. package/dist/src/react/core/catalog/use-agents.d.ts +31 -0
  380. package/dist/src/react/core/catalog/use-agents.d.ts.map +1 -0
  381. package/dist/src/react/core/catalog/use-agents.js +28 -0
  382. package/dist/src/react/core/catalog/use-agents.js.map +1 -0
  383. package/dist/src/react/core/catalog/use-models.d.ts +41 -0
  384. package/dist/src/react/core/catalog/use-models.d.ts.map +1 -0
  385. package/dist/src/react/core/catalog/use-models.js +35 -0
  386. package/dist/src/react/core/catalog/use-models.js.map +1 -0
  387. package/dist/src/react/core/catalog/use-resource.d.ts +12 -0
  388. package/dist/src/react/core/catalog/use-resource.d.ts.map +1 -0
  389. package/dist/src/react/core/catalog/use-resource.js +41 -0
  390. package/dist/src/react/core/catalog/use-resource.js.map +1 -0
  391. package/dist/src/react/core/client-wire.d.ts +14 -0
  392. package/dist/src/react/core/client-wire.d.ts.map +1 -0
  393. package/dist/src/react/core/client-wire.js +2 -0
  394. package/dist/src/react/core/client-wire.js.map +1 -0
  395. package/dist/src/react/core/client.d.ts +222 -0
  396. package/dist/src/react/core/client.d.ts.map +1 -0
  397. package/dist/src/react/core/client.js +435 -0
  398. package/dist/src/react/core/client.js.map +1 -0
  399. package/dist/src/react/core/components/ambient-ui.d.ts +22 -0
  400. package/dist/src/react/core/components/ambient-ui.d.ts.map +1 -0
  401. package/dist/src/react/core/components/ambient-ui.js +30 -0
  402. package/dist/src/react/core/components/ambient-ui.js.map +1 -0
  403. package/dist/src/react/core/components/chat-input.d.ts +44 -0
  404. package/dist/src/react/core/components/chat-input.d.ts.map +1 -0
  405. package/dist/src/react/core/components/chat-input.js +69 -0
  406. package/dist/src/react/core/components/chat-input.js.map +1 -0
  407. package/dist/src/react/core/components/index.d.ts +7 -0
  408. package/dist/src/react/core/components/index.d.ts.map +1 -0
  409. package/dist/src/react/core/components/index.js +7 -0
  410. package/dist/src/react/core/components/index.js.map +1 -0
  411. package/dist/src/react/core/components/message-item.d.ts +101 -0
  412. package/dist/src/react/core/components/message-item.d.ts.map +1 -0
  413. package/dist/src/react/core/components/message-item.js +118 -0
  414. package/dist/src/react/core/components/message-item.js.map +1 -0
  415. package/dist/src/react/core/components/message-list.d.ts +85 -0
  416. package/dist/src/react/core/components/message-list.d.ts.map +1 -0
  417. package/dist/src/react/core/components/message-list.js +45 -0
  418. package/dist/src/react/core/components/message-list.js.map +1 -0
  419. package/dist/src/react/core/components/speech-languages.d.ts +22 -0
  420. package/dist/src/react/core/components/speech-languages.d.ts.map +1 -0
  421. package/dist/src/react/core/components/speech-languages.js +38 -0
  422. package/dist/src/react/core/components/speech-languages.js.map +1 -0
  423. package/dist/src/react/core/components/use-speech-recognition.d.ts +19 -0
  424. package/dist/src/react/core/components/use-speech-recognition.d.ts.map +1 -0
  425. package/dist/src/react/core/components/use-speech-recognition.js +92 -0
  426. package/dist/src/react/core/components/use-speech-recognition.js.map +1 -0
  427. package/dist/src/react/core/composer/index.d.ts +4 -0
  428. package/dist/src/react/core/composer/index.d.ts.map +1 -0
  429. package/dist/src/react/core/composer/index.js +4 -0
  430. package/dist/src/react/core/composer/index.js.map +1 -0
  431. package/dist/src/react/core/composer/model.d.ts +83 -0
  432. package/dist/src/react/core/composer/model.d.ts.map +1 -0
  433. package/dist/src/react/core/composer/model.js +53 -0
  434. package/dist/src/react/core/composer/model.js.map +1 -0
  435. package/dist/src/react/core/composer/skills-source.d.ts +29 -0
  436. package/dist/src/react/core/composer/skills-source.d.ts.map +1 -0
  437. package/dist/src/react/core/composer/skills-source.js +61 -0
  438. package/dist/src/react/core/composer/skills-source.js.map +1 -0
  439. package/dist/src/react/core/composer/use-composer-autocomplete.d.ts +78 -0
  440. package/dist/src/react/core/composer/use-composer-autocomplete.d.ts.map +1 -0
  441. package/dist/src/react/core/composer/use-composer-autocomplete.js +244 -0
  442. package/dist/src/react/core/composer/use-composer-autocomplete.js.map +1 -0
  443. package/dist/src/react/core/config/use-agent-config.d.ts +21 -0
  444. package/dist/src/react/core/config/use-agent-config.d.ts.map +1 -0
  445. package/dist/src/react/core/config/use-agent-config.js +57 -0
  446. package/dist/src/react/core/config/use-agent-config.js.map +1 -0
  447. package/dist/src/react/core/elicitation/answers.d.ts +22 -0
  448. package/dist/src/react/core/elicitation/answers.d.ts.map +1 -0
  449. package/dist/src/react/core/elicitation/answers.js +65 -0
  450. package/dist/src/react/core/elicitation/answers.js.map +1 -0
  451. package/dist/src/react/core/feedback/use-message-feedback.d.ts +32 -0
  452. package/dist/src/react/core/feedback/use-message-feedback.d.ts.map +1 -0
  453. package/dist/src/react/core/feedback/use-message-feedback.js +106 -0
  454. package/dist/src/react/core/feedback/use-message-feedback.js.map +1 -0
  455. package/dist/src/react/core/genui/generative-ui.d.ts +76 -0
  456. package/dist/src/react/core/genui/generative-ui.d.ts.map +1 -0
  457. package/dist/src/react/core/genui/generative-ui.js +210 -0
  458. package/dist/src/react/core/genui/generative-ui.js.map +1 -0
  459. package/dist/src/react/core/genui/index.d.ts +5 -0
  460. package/dist/src/react/core/genui/index.d.ts.map +1 -0
  461. package/dist/src/react/core/genui/index.js +5 -0
  462. package/dist/src/react/core/genui/index.js.map +1 -0
  463. package/dist/src/react/core/genui/json-render.d.ts +54 -0
  464. package/dist/src/react/core/genui/json-render.d.ts.map +1 -0
  465. package/dist/src/react/core/genui/json-render.js +64 -0
  466. package/dist/src/react/core/genui/json-render.js.map +1 -0
  467. package/dist/src/react/core/genui/playwright.d.ts +12 -0
  468. package/dist/src/react/core/genui/playwright.d.ts.map +1 -0
  469. package/dist/src/react/core/genui/playwright.js +141 -0
  470. package/dist/src/react/core/genui/playwright.js.map +1 -0
  471. package/dist/src/react/core/genui/react-registry.d.ts +22 -0
  472. package/dist/src/react/core/genui/react-registry.d.ts.map +1 -0
  473. package/dist/src/react/core/genui/react-registry.js +72 -0
  474. package/dist/src/react/core/genui/react-registry.js.map +1 -0
  475. package/dist/src/react/core/genui/server.d.ts +32 -0
  476. package/dist/src/react/core/genui/server.d.ts.map +1 -0
  477. package/dist/src/react/core/genui/server.js +66 -0
  478. package/dist/src/react/core/genui/server.js.map +1 -0
  479. package/dist/src/react/core/genui/types.d.ts +98 -0
  480. package/dist/src/react/core/genui/types.d.ts.map +1 -0
  481. package/dist/src/react/core/genui/types.js +3 -0
  482. package/dist/src/react/core/genui/types.js.map +1 -0
  483. package/dist/src/react/core/genui/use-generative-ui.d.ts +42 -0
  484. package/dist/src/react/core/genui/use-generative-ui.d.ts.map +1 -0
  485. package/dist/src/react/core/genui/use-generative-ui.js +186 -0
  486. package/dist/src/react/core/genui/use-generative-ui.js.map +1 -0
  487. package/dist/src/react/core/http-error.d.ts +33 -0
  488. package/dist/src/react/core/http-error.d.ts.map +1 -0
  489. package/dist/src/react/core/http-error.js +47 -0
  490. package/dist/src/react/core/http-error.js.map +1 -0
  491. package/dist/src/react/core/index.d.ts +35 -0
  492. package/dist/src/react/core/index.d.ts.map +1 -0
  493. package/dist/src/react/core/index.js +34 -0
  494. package/dist/src/react/core/index.js.map +1 -0
  495. package/dist/src/react/core/markdown/agent-markdown.d.ts +39 -0
  496. package/dist/src/react/core/markdown/agent-markdown.d.ts.map +1 -0
  497. package/dist/src/react/core/markdown/agent-markdown.js +22 -0
  498. package/dist/src/react/core/markdown/agent-markdown.js.map +1 -0
  499. package/dist/src/react/core/markdown/index.d.ts +2 -0
  500. package/dist/src/react/core/markdown/index.d.ts.map +1 -0
  501. package/dist/src/react/core/markdown/index.js +2 -0
  502. package/dist/src/react/core/markdown/index.js.map +1 -0
  503. package/dist/src/react/core/media/index.d.ts +64 -0
  504. package/dist/src/react/core/media/index.d.ts.map +1 -0
  505. package/dist/src/react/core/media/index.js +135 -0
  506. package/dist/src/react/core/media/index.js.map +1 -0
  507. package/dist/src/react/core/media/tus.d.ts +13 -0
  508. package/dist/src/react/core/media/tus.d.ts.map +1 -0
  509. package/dist/src/react/core/media/tus.js +59 -0
  510. package/dist/src/react/core/media/tus.js.map +1 -0
  511. package/dist/src/react/core/presentation/phrasing.d.ts +25 -0
  512. package/dist/src/react/core/presentation/phrasing.d.ts.map +1 -0
  513. package/dist/src/react/core/presentation/phrasing.js +58 -0
  514. package/dist/src/react/core/presentation/phrasing.js.map +1 -0
  515. package/dist/src/react/core/presentation/result-view.d.ts +43 -0
  516. package/dist/src/react/core/presentation/result-view.d.ts.map +1 -0
  517. package/dist/src/react/core/presentation/result-view.js +90 -0
  518. package/dist/src/react/core/presentation/result-view.js.map +1 -0
  519. package/dist/src/react/core/presentation/tool-activity.d.ts +106 -0
  520. package/dist/src/react/core/presentation/tool-activity.d.ts.map +1 -0
  521. package/dist/src/react/core/presentation/tool-activity.js +165 -0
  522. package/dist/src/react/core/presentation/tool-activity.js.map +1 -0
  523. package/dist/src/react/core/presentation/use-tool-catalog.d.ts +39 -0
  524. package/dist/src/react/core/presentation/use-tool-catalog.d.ts.map +1 -0
  525. package/dist/src/react/core/presentation/use-tool-catalog.js +77 -0
  526. package/dist/src/react/core/presentation/use-tool-catalog.js.map +1 -0
  527. package/dist/src/react/core/provider.d.ts +68 -0
  528. package/dist/src/react/core/provider.d.ts.map +1 -0
  529. package/dist/src/react/core/provider.js +61 -0
  530. package/dist/src/react/core/provider.js.map +1 -0
  531. package/dist/src/react/core/queue/model.d.ts +73 -0
  532. package/dist/src/react/core/queue/model.d.ts.map +1 -0
  533. package/dist/src/react/core/queue/model.js +2 -0
  534. package/dist/src/react/core/queue/model.js.map +1 -0
  535. package/dist/src/react/core/quota/use-quota.d.ts +35 -0
  536. package/dist/src/react/core/quota/use-quota.d.ts.map +1 -0
  537. package/dist/src/react/core/quota/use-quota.js +47 -0
  538. package/dist/src/react/core/quota/use-quota.js.map +1 -0
  539. package/dist/src/react/core/reasoning/timing.d.ts +38 -0
  540. package/dist/src/react/core/reasoning/timing.d.ts.map +1 -0
  541. package/dist/src/react/core/reasoning/timing.js +73 -0
  542. package/dist/src/react/core/reasoning/timing.js.map +1 -0
  543. package/dist/src/react/core/run-errors.d.ts +37 -0
  544. package/dist/src/react/core/run-errors.d.ts.map +1 -0
  545. package/dist/src/react/core/run-errors.js +37 -0
  546. package/dist/src/react/core/run-errors.js.map +1 -0
  547. package/dist/src/react/core/stored-message-to-ui-message.d.ts +4 -0
  548. package/dist/src/react/core/stored-message-to-ui-message.d.ts.map +1 -0
  549. package/dist/src/react/core/stored-message-to-ui-message.js +216 -0
  550. package/dist/src/react/core/stored-message-to-ui-message.js.map +1 -0
  551. package/dist/src/react/core/stored-thread-to-ui-messages.d.ts +82 -0
  552. package/dist/src/react/core/stored-thread-to-ui-messages.d.ts.map +1 -0
  553. package/dist/src/react/core/stored-thread-to-ui-messages.js +116 -0
  554. package/dist/src/react/core/stored-thread-to-ui-messages.js.map +1 -0
  555. package/dist/src/react/core/threads/threads-events.d.ts +22 -0
  556. package/dist/src/react/core/threads/threads-events.d.ts.map +1 -0
  557. package/dist/src/react/core/threads/threads-events.js +21 -0
  558. package/dist/src/react/core/threads/threads-events.js.map +1 -0
  559. package/dist/src/react/core/threads/use-threads.d.ts +31 -0
  560. package/dist/src/react/core/threads/use-threads.d.ts.map +1 -0
  561. package/dist/src/react/core/threads/use-threads.js +81 -0
  562. package/dist/src/react/core/threads/use-threads.js.map +1 -0
  563. package/dist/src/react/core/transcript/index.d.ts +4 -0
  564. package/dist/src/react/core/transcript/index.d.ts.map +1 -0
  565. package/dist/src/react/core/transcript/index.js +4 -0
  566. package/dist/src/react/core/transcript/index.js.map +1 -0
  567. package/dist/src/react/core/transcript/model.d.ts +399 -0
  568. package/dist/src/react/core/transcript/model.d.ts.map +1 -0
  569. package/dist/src/react/core/transcript/model.js +725 -0
  570. package/dist/src/react/core/transcript/model.js.map +1 -0
  571. package/dist/src/react/core/transcript/use-chat-transcript.d.ts +254 -0
  572. package/dist/src/react/core/transcript/use-chat-transcript.d.ts.map +1 -0
  573. package/dist/src/react/core/transcript/use-chat-transcript.js +572 -0
  574. package/dist/src/react/core/transcript/use-chat-transcript.js.map +1 -0
  575. package/dist/src/react/core/transcript/use-stick-to-bottom.d.ts +33 -0
  576. package/dist/src/react/core/transcript/use-stick-to-bottom.d.ts.map +1 -0
  577. package/dist/src/react/core/transcript/use-stick-to-bottom.js +48 -0
  578. package/dist/src/react/core/transcript/use-stick-to-bottom.js.map +1 -0
  579. package/dist/src/react/core/use-agent-chat.d.ts +341 -0
  580. package/dist/src/react/core/use-agent-chat.d.ts.map +1 -0
  581. package/dist/src/react/core/use-agent-chat.js +1118 -0
  582. package/dist/src/react/core/use-agent-chat.js.map +1 -0
  583. package/dist/src/react/genui/index.d.ts +1 -7
  584. package/dist/src/react/genui/index.d.ts.map +1 -1
  585. package/dist/src/react/genui/index.js +1 -7
  586. package/dist/src/react/genui/index.js.map +1 -1
  587. package/dist/src/react/genui/json-render.d.ts +1 -5
  588. package/dist/src/react/genui/json-render.d.ts.map +1 -1
  589. package/dist/src/react/genui/json-render.js +1 -5
  590. package/dist/src/react/genui/json-render.js.map +1 -1
  591. package/dist/src/react/genui/server.d.ts +2 -0
  592. package/dist/src/react/genui/server.d.ts.map +1 -0
  593. package/dist/src/react/genui/server.js +2 -0
  594. package/dist/src/react/genui/server.js.map +1 -0
  595. package/dist/src/react/genui/server_playwright.d.ts +2 -0
  596. package/dist/src/react/genui/server_playwright.d.ts.map +1 -0
  597. package/dist/src/react/genui/server_playwright.js +2 -0
  598. package/dist/src/react/genui/server_playwright.js.map +1 -0
  599. package/dist/src/react/index.d.ts +5 -7
  600. package/dist/src/react/index.d.ts.map +1 -1
  601. package/dist/src/react/index.js +5 -7
  602. package/dist/src/react/index.js.map +1 -1
  603. package/dist/src/react/markdown.d.ts +1 -6
  604. package/dist/src/react/markdown.d.ts.map +1 -1
  605. package/dist/src/react/markdown.js +1 -6
  606. package/dist/src/react/markdown.js.map +1 -1
  607. package/dist/src/react/media.d.ts +1 -17
  608. package/dist/src/react/media.d.ts.map +1 -1
  609. package/dist/src/react/media.js +1 -17
  610. package/dist/src/react/media.js.map +1 -1
  611. package/dist/src/refusal.d.ts +3 -0
  612. package/dist/src/refusal.d.ts.map +1 -0
  613. package/dist/src/refusal.js +3 -0
  614. package/dist/src/refusal.js.map +1 -0
  615. package/dist/src/spi/agent-runner.d.ts +6 -0
  616. package/dist/src/spi/agent-runner.d.ts.map +1 -1
  617. package/dist/src/spi/chat-queue.d.ts +4 -1
  618. package/dist/src/spi/chat-queue.d.ts.map +1 -1
  619. package/dist/src/spi/chat-queue.js.map +1 -1
  620. package/dist/src/spi/protocol-adapter.d.ts +3 -3
  621. package/dist/src/spi/roles-policy.d.ts +7 -0
  622. package/dist/src/spi/roles-policy.d.ts.map +1 -1
  623. package/dist/src/spi/tool.d.ts +18 -3
  624. package/dist/src/spi/tool.d.ts.map +1 -1
  625. package/dist/src/stores/lucid-schema.d.ts +24 -6
  626. package/dist/src/stores/lucid-schema.d.ts.map +1 -1
  627. package/dist/src/stores/lucid-schema.js +49 -6
  628. package/dist/src/stores/lucid-schema.js.map +1 -1
  629. package/dist/src/stores/lucid.d.ts +2 -0
  630. package/dist/src/stores/lucid.d.ts.map +1 -1
  631. package/dist/src/stores/lucid.js +7 -0
  632. package/dist/src/stores/lucid.js.map +1 -1
  633. package/dist/src/testing/chat-queue-store-contract.d.ts.map +1 -1
  634. package/dist/src/testing/chat-queue-store-contract.js +4 -0
  635. package/dist/src/testing/chat-queue-store-contract.js.map +1 -1
  636. package/dist/src/testing/in-memory-store.d.ts.map +1 -1
  637. package/dist/src/testing/in-memory-store.js +1 -0
  638. package/dist/src/testing/in-memory-store.js.map +1 -1
  639. package/dist/src/tool-discovery.d.ts +1 -1
  640. package/dist/src/tool-discovery.d.ts.map +1 -1
  641. package/dist/src/tool-discovery.js +5 -1
  642. package/dist/src/tool-discovery.js.map +1 -1
  643. package/dist/src/tool-registry.d.ts +3 -0
  644. package/dist/src/tool-registry.d.ts.map +1 -1
  645. package/dist/src/tool-registry.js +15 -3
  646. package/dist/src/tool-registry.js.map +1 -1
  647. package/dist/src/tool-result-presentation.d.ts +12 -0
  648. package/dist/src/tool-result-presentation.d.ts.map +1 -0
  649. package/dist/src/tool-result-presentation.js +44 -0
  650. package/dist/src/tool-result-presentation.js.map +1 -0
  651. package/dist/src/types.d.ts +20 -0
  652. package/dist/src/types.d.ts.map +1 -1
  653. package/dist/src/ui-capabilities.d.ts +1 -8
  654. package/dist/src/ui-capabilities.d.ts.map +1 -1
  655. package/dist/src/ui-capabilities.js +3 -24
  656. package/dist/src/ui-capabilities.js.map +1 -1
  657. package/package.json +128 -22
  658. package/skills/agent-governance/SKILL.md +12 -4
  659. package/skills/agent-personas-agents/SKILL.md +2 -1
  660. package/skills/agent-setup/SKILL.md +73 -14
  661. package/skills/agent-testing/SKILL.md +22 -0
  662. package/skills/agent-tools/SKILL.md +57 -9
  663. package/dist/src/ag-ui/proposal-decision.d.ts.map +0 -1
  664. package/dist/src/ag-ui/proposal-decision.js.map +0 -1
@@ -0,0 +1,725 @@
1
+ import { getToolName, isDataUIPart, isFileUIPart, isReasoningUIPart, isTextUIPart, isToolUIPart, } from 'ai';
2
+ import { readElicitationInput, validateElicitationAnswer, } from '../../../elicitation-input.js';
3
+ import { coerceAnswer } from '../elicitation/answers.js';
4
+ import { describeToolCall, groupToolActivity, } from '../presentation/tool-activity.js';
5
+ import { readReasoningMs } from '../reasoning/timing.js';
6
+ /**
7
+ * Walk a message's parts into renderable blocks, buffering consecutive tool parts into one run and
8
+ * consecutive files into one strip. A `data-ui` part becomes a `ui` block. A
9
+ * `data-approval-requested` part is metadata about a call — it is folded into that call's
10
+ * `approval` and takes no position of its own. Other `data-*` parts are dropped rather than guessed
11
+ * at, but they still terminate a tool run — their position in the transcript is meaningful even
12
+ * when their content is not modelled here.
13
+ */
14
+ export function buildTranscriptBlocks(message, options) {
15
+ const blocks = [];
16
+ let toolBuffer = [];
17
+ let retrievalBuffer = [];
18
+ let fileBuffer = [];
19
+ let toolCounter = 0;
20
+ let textCounter = 0;
21
+ let fileCounter = 0;
22
+ let reasoningCounter = 0;
23
+ let sourcesCounter = 0;
24
+ let elicitationCounter = 0;
25
+ const approvals = readApprovals(message.parts ?? []);
26
+ function flushTools() {
27
+ if (toolBuffer.length === 0) {
28
+ return;
29
+ }
30
+ const calls = toolBuffer.map((part) => buildToolCall(part, options.approval, approvalOf(approvals.get(part.toolCallId), part), options.toolCatalog));
31
+ const roots = nestToolCalls(calls);
32
+ blocks.push({
33
+ kind: 'tools',
34
+ key: `${message.id}-tools-${toolCounter++}`,
35
+ parts: toolBuffer,
36
+ calls,
37
+ roots,
38
+ activity: groupToolActivity(roots, {
39
+ ...(options.toolCatalog !== undefined ? { catalog: options.toolCatalog } : {}),
40
+ }),
41
+ });
42
+ toolBuffer = [];
43
+ }
44
+ function flushSources() {
45
+ if (retrievalBuffer.length === 0) {
46
+ return;
47
+ }
48
+ blocks.push(buildSourcesBlock(`${message.id}-sources-${sourcesCounter++}`, retrievalBuffer));
49
+ retrievalBuffer = [];
50
+ }
51
+ function flushFiles() {
52
+ if (fileBuffer.length === 0) {
53
+ return;
54
+ }
55
+ blocks.push({
56
+ kind: 'files',
57
+ key: `${message.id}-files-${fileCounter++}`,
58
+ files: fileBuffer.map((part) => ({
59
+ url: part.url,
60
+ mediaType: part.mediaType,
61
+ filename: part.filename ?? null,
62
+ isImage: part.mediaType.startsWith('image/'),
63
+ })),
64
+ });
65
+ fileBuffer = [];
66
+ }
67
+ function flushAll() {
68
+ flushTools();
69
+ flushSources();
70
+ flushFiles();
71
+ }
72
+ for (const part of message.parts ?? []) {
73
+ if (isToolUIPart(part)) {
74
+ const elicitation = options.elicitation;
75
+ if (elicitation !== undefined) {
76
+ const request = readElicitationRequest(part);
77
+ if (request !== null) {
78
+ flushAll();
79
+ blocks.push(buildElicitationBlock(`${message.id}-elicitation-${elicitationCounter++}`, part, request, elicitation));
80
+ continue;
81
+ }
82
+ }
83
+ if (options.sources === true && readPassages(part) !== null) {
84
+ flushTools();
85
+ retrievalBuffer.push(part);
86
+ continue;
87
+ }
88
+ flushSources();
89
+ flushFiles();
90
+ toolBuffer.push(part);
91
+ continue;
92
+ }
93
+ if (isFileUIPart(part)) {
94
+ flushTools();
95
+ flushSources();
96
+ fileBuffer.push(part);
97
+ continue;
98
+ }
99
+ if (part.type === APPROVAL_PART || part.type === SETTLED_PART) {
100
+ continue;
101
+ }
102
+ flushAll();
103
+ if (isDataUIPart(part)) {
104
+ const ui = part.type === UI_PART ? readUiComponent(part) : null;
105
+ if (ui !== null) {
106
+ blocks.push({ kind: 'ui', key: `${message.id}-ui-${ui.id}`, ...ui });
107
+ }
108
+ continue;
109
+ }
110
+ if (isTextUIPart(part)) {
111
+ blocks.push({
112
+ kind: 'text',
113
+ key: `${message.id}-text-${textCounter++}`,
114
+ text: part.text,
115
+ isStreaming: part.state === 'streaming',
116
+ });
117
+ continue;
118
+ }
119
+ if (isReasoningUIPart(part)) {
120
+ const key = `${message.id}-reasoning-${reasoningCounter++}`;
121
+ const isStreaming = part.state === 'streaming';
122
+ blocks.push({
123
+ kind: 'reasoning',
124
+ key,
125
+ text: part.text,
126
+ isStreaming,
127
+ durationMs: readReasoningMs(part),
128
+ isOpen: options.isReasoningOpen(key, isStreaming),
129
+ toggle: (open) => options.toggleReasoning(key, open),
130
+ });
131
+ }
132
+ }
133
+ flushAll();
134
+ return blocks;
135
+ }
136
+ /**
137
+ * Fold a run of retrieval parts into one provenance block. Sources keep the order the retriever
138
+ * returned them in — that order IS the ranking — and the query is taken from the first call that
139
+ * recorded one.
140
+ */
141
+ function buildSourcesBlock(key, parts) {
142
+ const byId = new Map();
143
+ let query = null;
144
+ let passageCount = 0;
145
+ for (const part of parts) {
146
+ query ??= readQuery(part);
147
+ for (const passage of readPassages(part) ?? []) {
148
+ passageCount++;
149
+ const id = passage.source ?? passage.id;
150
+ const existing = byId.get(id);
151
+ if (existing) {
152
+ existing.passageCount++;
153
+ existing.topScore = Math.max(existing.topScore, passage.score);
154
+ existing.passages.push(passage);
155
+ continue;
156
+ }
157
+ byId.set(id, {
158
+ id,
159
+ label: passage.source ?? passage.id,
160
+ passageCount: 1,
161
+ topScore: passage.score,
162
+ passages: [passage],
163
+ });
164
+ }
165
+ }
166
+ return { kind: 'sources', key, query, sources: [...byId.values()], passageCount };
167
+ }
168
+ /** A call whose output has landed one way or another is nobody's decision any more. */
169
+ function isSettled(state) {
170
+ return state === 'output-available' || state === 'output-error' || state === 'output-denied';
171
+ }
172
+ function toolKind(part) {
173
+ const metadata = part.toolMetadata;
174
+ return isRecord(metadata) && typeof metadata.toolKind === 'string'
175
+ ? metadata.toolKind
176
+ : undefined;
177
+ }
178
+ /**
179
+ * An `action` tool's input lands and then nothing follows: the loop waits on a person between the
180
+ * call and its execution. So a call classified `action` and stuck at `input-available` IS the
181
+ * pending approval — there is no separate frame that says so.
182
+ */
183
+ function isAwaitingApproval(part) {
184
+ if (part.state === 'approval-requested') {
185
+ return true;
186
+ }
187
+ if (part.state !== 'input-available') {
188
+ return false;
189
+ }
190
+ // A question set parks the same way and is persisted as an action, but it is settled by
191
+ // answering it, not by approving it.
192
+ return toolKind(part) === 'action' && readElicitationRequest(part) === null;
193
+ }
194
+ function toolParentId(part) {
195
+ const metadata = part.toolMetadata;
196
+ return isRecord(metadata) && typeof metadata.parentId === 'string' ? metadata.parentId : null;
197
+ }
198
+ /**
199
+ * Arrange a block's calls into a tree by `parentId`. A call whose parent is not in the block (or
200
+ * that names itself, or would close a cycle) stays a root, so nothing a runner sends is ever lost
201
+ * from the tree — at worst it is shown flat.
202
+ */
203
+ function nestToolCalls(calls) {
204
+ const byId = new Map(calls.map((call) => [call.toolCallId, call]));
205
+ const roots = [];
206
+ for (const call of calls) {
207
+ const parent = call.parentId !== null ? byId.get(call.parentId) : undefined;
208
+ if (parent === undefined || isAncestor(call, parent, byId)) {
209
+ roots.push(call);
210
+ continue;
211
+ }
212
+ parent.children.push(call);
213
+ }
214
+ return roots;
215
+ }
216
+ /** True when `candidate` is `call` itself or sits under it — attaching would close a cycle. */
217
+ function isAncestor(call, candidate, byId) {
218
+ const seen = new Set();
219
+ let current = candidate;
220
+ while (current !== undefined && !seen.has(current.toolCallId)) {
221
+ if (current.toolCallId === call.toolCallId) {
222
+ return true;
223
+ }
224
+ seen.add(current.toolCallId);
225
+ current = current.parentId !== null ? byId.get(current.parentId) : undefined;
226
+ }
227
+ return false;
228
+ }
229
+ function buildToolCall(part, options, approval, catalog) {
230
+ const toolCallId = part.toolCallId;
231
+ const awaiting = approval?.target?.kind === 'proposal'
232
+ ? approval.status === 'pending'
233
+ : isAwaitingApproval(part);
234
+ // Per decision, not per call: the two are never in flight together, and a surface that read one
235
+ // flag for both would report the refusal it is carrying out as an approval in progress.
236
+ const sending = awaiting ? (options?.submitting(toolCallId) ?? null) : null;
237
+ return {
238
+ part,
239
+ toolCallId,
240
+ name: getToolName(part),
241
+ toolKind: toolKind(part) ?? null,
242
+ parentId: toolParentId(part),
243
+ children: [],
244
+ approval,
245
+ description: proposalDescription(describeToolCall(part, catalog, approval?.confirmation === undefined ? {} : { confirmation: approval.confirmation }), approval),
246
+ isAwaitingApproval: awaiting,
247
+ approve: {
248
+ available: awaiting && options?.canApprove === true,
249
+ isSubmitting: sending === 'approve',
250
+ // Read by field, not passed through: `onClick={call.approve.run}` hands this a click event,
251
+ // and a host's handler must not receive that as its options.
252
+ run: (approveOptions) => approval?.target === undefined
253
+ ? approveOptions?.remember === true
254
+ ? options?.approve(toolCallId, { remember: true })
255
+ : options?.approve(toolCallId)
256
+ : options?.approve(toolCallId, approveOptions?.remember === true ? { remember: true } : undefined, approval.target),
257
+ },
258
+ reject: {
259
+ available: awaiting && options?.canReject === true,
260
+ isSubmitting: sending === 'reject',
261
+ run: () => approval?.target === undefined
262
+ ? options?.reject(toolCallId)
263
+ : options?.reject(toolCallId, approval.target),
264
+ },
265
+ error: options?.errorOf(toolCallId) ?? null,
266
+ errorCode: options?.errorCodeOf?.(toolCallId) ?? null,
267
+ };
268
+ }
269
+ /**
270
+ * The question set a tool call carries, or `null` for any other tool. Read from the call's INPUT
271
+ * and by shape rather than by tool name: the same set is authored by an agent's intake and by the
272
+ * model's own `ask`, it replays from the store under whatever name the row holds, and a client
273
+ * that learned to recognise one name would render only half of them.
274
+ */
275
+ function readElicitationRequest(part) {
276
+ const input = part.input;
277
+ if (!isRecord(input) || !Array.isArray(input.questions) || input.questions.length === 0) {
278
+ return null;
279
+ }
280
+ const questions = [];
281
+ for (const candidate of input.questions) {
282
+ if (!isRecord(candidate) ||
283
+ typeof candidate.id !== 'string' ||
284
+ typeof candidate.prompt !== 'string') {
285
+ return null;
286
+ }
287
+ // A typed question may carry no options; anything else is a pick and must offer some.
288
+ const input = readElicitationInput(candidate.input) ?? null;
289
+ const rawOptions = Array.isArray(candidate.options) ? candidate.options : [];
290
+ if (rawOptions.length === 0 && (input === null || input.type === 'select')) {
291
+ return null;
292
+ }
293
+ const options = [];
294
+ for (const option of rawOptions) {
295
+ if (!isRecord(option) ||
296
+ typeof option.value !== 'string' ||
297
+ typeof option.label !== 'string') {
298
+ return null;
299
+ }
300
+ options.push({
301
+ value: option.value,
302
+ label: option.label,
303
+ hotkey: typeof option.hotkey === 'string' ? option.hotkey : null,
304
+ });
305
+ }
306
+ questions.push({
307
+ id: candidate.id,
308
+ prompt: candidate.prompt,
309
+ description: typeof candidate.description === 'string' ? candidate.description : null,
310
+ input,
311
+ multiple: candidate.multiple === true,
312
+ allowFreeText: candidate.allowFreeText === true,
313
+ defaults: Array.isArray(candidate.defaults)
314
+ ? candidate.defaults.filter((value) => typeof value === 'string')
315
+ : [],
316
+ options,
317
+ });
318
+ }
319
+ return {
320
+ preamble: typeof input.preamble === 'string' ? input.preamble : null,
321
+ questions,
322
+ };
323
+ }
324
+ /** What the run recorded for a settled question set, or `null` when it settled as something else. */
325
+ function readElicitationOutcome(part) {
326
+ const output = part.output;
327
+ if (!isRecord(output) || !isRecord(output.answers) || typeof output.skipped !== 'boolean') {
328
+ return null;
329
+ }
330
+ const answers = {};
331
+ for (const [id, values] of Object.entries(output.answers)) {
332
+ answers[id] = Array.isArray(values)
333
+ ? values.filter((value) => typeof value === 'string')
334
+ : [];
335
+ }
336
+ return {
337
+ answers,
338
+ skipped: output.skipped,
339
+ defaulted: Array.isArray(output.defaulted)
340
+ ? output.defaulted.filter((id) => typeof id === 'string')
341
+ : [],
342
+ summary: typeof output.summary === 'string' ? output.summary : null,
343
+ answeredBy: typeof output.answeredBy === 'string' ? output.answeredBy : null,
344
+ answeredVia: typeof output.answeredVia === 'string' ? output.answeredVia : null,
345
+ };
346
+ }
347
+ function buildElicitationBlock(key, part, request, options) {
348
+ const toolCallId = part.toolCallId;
349
+ const isPending = !isSettled(part.state);
350
+ const outcome = isPending ? null : readElicitationOutcome(part);
351
+ const questions = request.questions.map((question, index) => {
352
+ const picked = isPending ? options.picked(toolCallId, question.id) : undefined;
353
+ const selected = picked ?? outcome?.answers[question.id] ?? question.defaults;
354
+ const pick = (values) => options.pick(toolCallId, question.id, values);
355
+ // The same rules the answer route applies, over the same question shape core reads.
356
+ const error = isPending
357
+ ? validateElicitationAnswer({
358
+ id: question.id,
359
+ prompt: question.prompt,
360
+ options: question.options.map(({ value, label }) => ({ value, label })),
361
+ ...(question.input !== null ? { input: question.input } : {}),
362
+ ...(question.multiple ? { multiple: true } : {}),
363
+ ...(question.allowFreeText ? { allowFreeText: true } : {}),
364
+ }, selected)
365
+ : null;
366
+ return {
367
+ id: question.id,
368
+ prompt: question.prompt,
369
+ description: question.description,
370
+ input: question.input,
371
+ multiple: question.multiple,
372
+ position: index + 1,
373
+ selected,
374
+ value: selected[0] ?? '',
375
+ error,
376
+ setValue: (raw) => {
377
+ if (isPending) {
378
+ pick(coerceAnswer(question, raw));
379
+ }
380
+ },
381
+ isPristine: isPending
382
+ ? picked === undefined
383
+ : (outcome?.defaulted.includes(question.id) ?? true),
384
+ options: question.options.map((option) => ({
385
+ value: option.value,
386
+ label: option.label,
387
+ hotkey: option.hotkey,
388
+ isSelected: selected.includes(option.value),
389
+ isDefault: question.defaults.includes(option.value),
390
+ select: () => {
391
+ if (!isPending) {
392
+ return;
393
+ }
394
+ if (!question.multiple) {
395
+ pick([option.value]);
396
+ return;
397
+ }
398
+ pick(selected.includes(option.value)
399
+ ? selected.filter((value) => value !== option.value)
400
+ : [...selected, option.value]);
401
+ },
402
+ })),
403
+ };
404
+ });
405
+ const sending = isPending ? options.submitting(toolCallId) : null;
406
+ return {
407
+ kind: 'elicitation',
408
+ key,
409
+ toolCallId,
410
+ preamble: request.preamble,
411
+ questions,
412
+ questionCount: questions.length,
413
+ isPending,
414
+ isValid: questions.every((question) => question.error === null),
415
+ outcome,
416
+ error: options.errorOf(toolCallId),
417
+ errorCode: options.errorCodeOf?.(toolCallId) ?? null,
418
+ answer: {
419
+ available: isPending && options.canAnswer,
420
+ isSubmitting: sending === 'answer',
421
+ run: () => options.answer(toolCallId),
422
+ },
423
+ skip: {
424
+ available: isPending && options.canSkip,
425
+ isSubmitting: sending === 'skip',
426
+ run: () => options.skip(toolCallId),
427
+ },
428
+ };
429
+ }
430
+ const UI_PART = 'data-ui';
431
+ const APPROVAL_PART = 'data-approval-requested';
432
+ const SETTLED_PART = 'data-approval-settled';
433
+ const SETTLED_STATUSES = ['approved', 'rejected', 'expired', 'superseded'];
434
+ /** The approval metadata on a message, by call id. The latest frame of each kind for a call wins. */
435
+ function readApprovals(parts) {
436
+ const out = new Map();
437
+ const entry = (id) => {
438
+ let found = out.get(id);
439
+ if (found === undefined) {
440
+ found = {
441
+ approver: null,
442
+ expiresAt: null,
443
+ reason: null,
444
+ status: null,
445
+ remember: false,
446
+ decidedBy: null,
447
+ decidedVia: null,
448
+ decisionReason: null,
449
+ };
450
+ out.set(id, found);
451
+ }
452
+ return found;
453
+ };
454
+ for (const part of parts) {
455
+ if (part.type !== APPROVAL_PART &&
456
+ part.type !== SETTLED_PART &&
457
+ part.type !== 'data-action-proposal') {
458
+ continue;
459
+ }
460
+ const data = part.data;
461
+ if (!isRecord(data) || typeof data.id !== 'string') {
462
+ continue;
463
+ }
464
+ const approval = entry(data.id);
465
+ if (part.type === APPROVAL_PART || part.type === 'data-action-proposal') {
466
+ if (isRecord(data.target) &&
467
+ data.target.kind === 'proposal' &&
468
+ typeof data.target.proposalId === 'string') {
469
+ approval.target = {
470
+ kind: 'proposal',
471
+ proposalId: data.target.proposalId,
472
+ ...(typeof data.target.threadId === 'string' ? { threadId: data.target.threadId } : {}),
473
+ };
474
+ }
475
+ if (part.type === 'data-action-proposal') {
476
+ if (typeof data.status === 'string' &&
477
+ ['pending', 'approved', 'rejected', 'expired', 'superseded'].includes(data.status))
478
+ approval.status =
479
+ data.status === 'pending'
480
+ ? null
481
+ : data.status;
482
+ if (data.executionStatus === null ||
483
+ data.executionStatus === 'queued' ||
484
+ data.executionStatus === 'executing' ||
485
+ data.executionStatus === 'succeeded' ||
486
+ data.executionStatus === 'failed')
487
+ approval.executionStatus = data.executionStatus;
488
+ approval.remember = data.remember === true;
489
+ approval.decidedBy = typeof data.decidedBy === 'string' ? data.decidedBy : null;
490
+ approval.decidedVia = typeof data.decidedVia === 'string' ? data.decidedVia : null;
491
+ }
492
+ if (typeof data.approver !== 'string') {
493
+ continue;
494
+ }
495
+ approval.approver = data.approver;
496
+ approval.expiresAt = typeof data.expiresAt === 'string' ? data.expiresAt : null;
497
+ if (isRecord(data.confirmation) &&
498
+ typeof data.confirmation.title === 'string' &&
499
+ typeof data.confirmation.verb === 'string' &&
500
+ (data.confirmation.detail === undefined || typeof data.confirmation.detail === 'string')) {
501
+ approval.confirmation = {
502
+ title: data.confirmation.title,
503
+ verb: data.confirmation.verb,
504
+ ...(typeof data.confirmation.detail === 'string'
505
+ ? { detail: data.confirmation.detail }
506
+ : {}),
507
+ };
508
+ }
509
+ approval.reason = typeof data.reason === 'string' ? data.reason : null;
510
+ continue;
511
+ }
512
+ if (typeof data.status !== 'string' || !SETTLED_STATUSES.includes(data.status)) {
513
+ continue;
514
+ }
515
+ approval.status = data.status;
516
+ if (approval.approver === null && typeof data.approver === 'string') {
517
+ approval.approver = data.approver;
518
+ }
519
+ approval.remember = data.remember === true;
520
+ approval.decidedBy = typeof data.decidedBy === 'string' ? data.decidedBy : null;
521
+ approval.decidedVia = typeof data.decidedVia === 'string' ? data.decidedVia : null;
522
+ approval.decisionReason = typeof data.reason === 'string' ? data.reason : null;
523
+ }
524
+ return out;
525
+ }
526
+ /**
527
+ * One call's approval: its parts, with the status completed from the call's own state when no
528
+ * settlement was streamed. `null` when nothing on the message says who decides.
529
+ */
530
+ function approvalOf(parts, call) {
531
+ if (parts === undefined || parts.approver === null) {
532
+ return null;
533
+ }
534
+ return {
535
+ approver: parts.approver,
536
+ ...(parts.target === undefined ? {} : { target: parts.target }),
537
+ ...(parts.executionStatus === undefined ? {} : { executionStatus: parts.executionStatus }),
538
+ ...(parts.confirmation !== undefined ? { confirmation: parts.confirmation } : {}),
539
+ expiresAt: parts.expiresAt,
540
+ reason: parts.reason,
541
+ status: parts.status ?? (parts.target?.kind === 'proposal' ? 'pending' : statusFromPart(call)),
542
+ remember: parts.remember,
543
+ decidedBy: parts.decidedBy,
544
+ decidedVia: parts.decidedVia,
545
+ decisionReason: parts.decisionReason,
546
+ };
547
+ }
548
+ function statusFromPart(call) {
549
+ if (call.state === 'output-denied') {
550
+ return 'rejected';
551
+ }
552
+ if (call.state === 'output-available' || call.state === 'output-error') {
553
+ return 'approved';
554
+ }
555
+ return 'pending';
556
+ }
557
+ /** A pushed component, or `null` when the part does not carry one this model can address. */
558
+ function readUiComponent(part) {
559
+ const data = part.data;
560
+ if (!isRecord(data) || typeof data.component !== 'string') {
561
+ return null;
562
+ }
563
+ const id = typeof data.id === 'string' ? data.id : part.id;
564
+ if (id === undefined) {
565
+ return null;
566
+ }
567
+ return {
568
+ id,
569
+ component: data.component,
570
+ props: isRecord(data.props) ? data.props : {},
571
+ version: typeof data.version === 'number' ? data.version : null,
572
+ ...(isRecord(data.componentVersions) &&
573
+ Object.values(data.componentVersions).every((version) => typeof version === 'number' && Number.isSafeInteger(version) && version > 0)
574
+ ? { componentVersions: { ...data.componentVersions } }
575
+ : {}),
576
+ ...(typeof data.fallbackText === 'string' ? { fallbackText: data.fallbackText } : {}),
577
+ toolCallId: typeof data.toolCallId === 'string' ? data.toolCallId : null,
578
+ };
579
+ }
580
+ function isRecord(value) {
581
+ return typeof value === 'object' && value !== null;
582
+ }
583
+ function readQuery(part) {
584
+ const input = part.input;
585
+ if (!isRecord(input) || typeof input.query !== 'string') {
586
+ return null;
587
+ }
588
+ return input.query;
589
+ }
590
+ /**
591
+ * The passages on a settled retrieval tool call, or `null` for any other tool. A call still in
592
+ * flight, or one whose output is not a non-empty list of `{ id, text }` passages, is not provenance
593
+ * yet and stays an ordinary tool part.
594
+ */
595
+ function readPassages(part) {
596
+ const output = part.output;
597
+ if (!isRecord(output) || !Array.isArray(output.passages) || output.passages.length === 0) {
598
+ return null;
599
+ }
600
+ const passages = [];
601
+ for (const candidate of output.passages) {
602
+ if (!isRecord(candidate) ||
603
+ typeof candidate.id !== 'string' ||
604
+ typeof candidate.text !== 'string') {
605
+ return null;
606
+ }
607
+ passages.push({
608
+ id: candidate.id,
609
+ text: candidate.text,
610
+ score: typeof candidate.score === 'number' ? candidate.score : 0,
611
+ ...(typeof candidate.source === 'string' ? { source: candidate.source } : {}),
612
+ ...(isRecord(candidate.metadata) ? { metadata: candidate.metadata } : {}),
613
+ });
614
+ }
615
+ return passages;
616
+ }
617
+ /** The message's prose, joined for the clipboard. Reasoning is excluded — it is not the answer. */
618
+ export function extractMessageText(parts) {
619
+ const out = [];
620
+ for (const part of parts ?? []) {
621
+ if (isTextUIPart(part)) {
622
+ out.push(part.text);
623
+ }
624
+ }
625
+ return out.join('\n\n').trim();
626
+ }
627
+ export function describeUsage(usage) {
628
+ const totalTokens = usage.inputTokens + usage.outputTokens;
629
+ return {
630
+ ...usage,
631
+ totalTokens,
632
+ costLabel: formatCostUsd(usage.costUsd),
633
+ tokensLabel: formatTokensShort(totalTokens),
634
+ };
635
+ }
636
+ /** `null` for an unparseable stamp, so a bad `created_at` renders nothing instead of "Invalid Date". */
637
+ export function describeTimestamp(createdAt) {
638
+ if (createdAt == null) {
639
+ return null;
640
+ }
641
+ const date = new Date(createdAt);
642
+ if (Number.isNaN(date.getTime())) {
643
+ return null;
644
+ }
645
+ return {
646
+ iso: createdAt,
647
+ date,
648
+ relative: formatRelativeTime(date),
649
+ absolute: date.toLocaleString(undefined, { dateStyle: 'medium', timeStyle: 'short' }),
650
+ };
651
+ }
652
+ const RELATIVE_TIME = new Intl.RelativeTimeFormat(undefined, { numeric: 'auto', style: 'narrow' });
653
+ const ONE_WEEK_MS = 7 * 24 * 60 * 60 * 1000;
654
+ /**
655
+ * "just now" within ±10s (server `created_at` can land a few ms ahead of the client clock), a
656
+ * relative phrase up to a week, then a calendar date. Uses Intl.RelativeTimeFormat — no date-fns.
657
+ */
658
+ export function formatRelativeTime(date) {
659
+ const diffMs = Date.now() - date.getTime();
660
+ if (Math.abs(diffMs) < 10_000) {
661
+ return 'just now';
662
+ }
663
+ if (diffMs > ONE_WEEK_MS) {
664
+ return date.toLocaleDateString(undefined, { month: 'short', day: 'numeric' });
665
+ }
666
+ const minutes = Math.round(-diffMs / 60_000);
667
+ if (Math.abs(minutes) < 60) {
668
+ return RELATIVE_TIME.format(minutes, 'minute');
669
+ }
670
+ const hours = Math.round(-diffMs / 3_600_000);
671
+ if (Math.abs(hours) < 24) {
672
+ return RELATIVE_TIME.format(hours, 'hour');
673
+ }
674
+ return RELATIVE_TIME.format(Math.round(-diffMs / 86_400_000), 'day');
675
+ }
676
+ function formatTokensShort(n) {
677
+ if (n < 1_000) {
678
+ return `${n} tokens`;
679
+ }
680
+ if (n < 10_000) {
681
+ return `${(n / 1_000).toFixed(1)}k tokens`;
682
+ }
683
+ return `${Math.round(n / 1_000)}k tokens`;
684
+ }
685
+ function formatCostUsd(cost) {
686
+ if (cost === null) {
687
+ return '—';
688
+ }
689
+ if (cost === 0) {
690
+ return '$0';
691
+ }
692
+ if (cost < 0.01) {
693
+ return `$${cost.toFixed(4)}`;
694
+ }
695
+ if (cost < 1) {
696
+ return `$${cost.toFixed(3)}`;
697
+ }
698
+ return `$${cost.toFixed(2)}`;
699
+ }
700
+ function proposalDescription(description, approval) {
701
+ if (approval?.target?.kind !== 'proposal')
702
+ return description;
703
+ const status = approval.status === 'pending'
704
+ ? 'awaiting-approval'
705
+ : approval.status === 'approved'
706
+ ? (approval.executionStatus ?? 'queued')
707
+ : 'denied';
708
+ const phrase = status === 'awaiting-approval'
709
+ ? 'Awaiting approval'
710
+ : status === 'queued'
711
+ ? 'Queued'
712
+ : status === 'executing'
713
+ ? 'Executing'
714
+ : status === 'succeeded'
715
+ ? 'Succeeded'
716
+ : status === 'failed'
717
+ ? 'Failed'
718
+ : approval.status === 'expired'
719
+ ? 'Expired'
720
+ : approval.status === 'superseded'
721
+ ? 'Replaced'
722
+ : 'Rejected';
723
+ return { ...description, status, phrase, result: null };
724
+ }
725
+ //# sourceMappingURL=model.js.map