@kitn.ai/ui 0.25.1 → 0.26.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 (409) hide show
  1. package/README.md +5 -7
  2. package/dist/components/attachment-types.d.ts +46 -1
  3. package/dist/components/attachments.d.ts +31 -0
  4. package/dist/components/audio-visualizer/fit-scale.d.ts +50 -0
  5. package/dist/components/audio-visualizer/index.d.ts +15 -1
  6. package/dist/components/audio-visualizer/variant-bar.d.ts +24 -1
  7. package/dist/components/chat-thread.d.ts +3 -41
  8. package/dist/components/code-block.d.ts +22 -0
  9. package/dist/components/conversation-item.d.ts +54 -1
  10. package/dist/components/conversation-list.d.ts +65 -0
  11. package/dist/components/form.d.ts +42 -0
  12. package/dist/components/message.d.ts +7 -0
  13. package/dist/components/toast.d.ts +2 -1
  14. package/dist/components/voice-input.d.ts +8 -0
  15. package/dist/components/voice-output.d.ts +12 -1
  16. package/dist/components/workspace-shell.d.ts +87 -0
  17. package/dist/{create-tween-B5Y4Im8G.js → create-tween-BFT6c-Y8.js} +1 -1
  18. package/dist/{create-tween-4z1XYLkR.js → create-tween-CJNlzoaO.js} +1 -1
  19. package/dist/{create-tween-CUzOlaMS.js → create-tween-CQED4T0g.js} +1 -1
  20. package/dist/custom-elements.json +2931 -2572
  21. package/dist/diagnostics/hook.d.ts +81 -0
  22. package/dist/diagnostics/index.d.ts +7 -0
  23. package/dist/diagnostics/report-request.d.ts +61 -0
  24. package/dist/diagnostics.d.ts +5 -0
  25. package/dist/diagnostics.js +209 -0
  26. package/dist/elements/agent-card.js +1 -1
  27. package/dist/elements/artifact.js +1 -1
  28. package/dist/elements/attachments.js +1 -1
  29. package/dist/elements/audio-visualizer.js +1 -1
  30. package/dist/elements/autoloader.js +1 -1
  31. package/dist/elements/avatar.js +1 -1
  32. package/dist/elements/badge.js +1 -1
  33. package/dist/elements/button.js +1 -1
  34. package/dist/elements/card.js +1 -1
  35. package/dist/elements/cards.js +1 -1
  36. package/dist/elements/chain-of-thought.js +1 -1
  37. package/dist/elements/chat-scope-picker.js +1 -1
  38. package/dist/elements/chat-workspace.js +1 -1
  39. package/dist/elements/chat.js +1 -1
  40. package/dist/elements/checkpoint.js +1 -1
  41. package/dist/elements/choice.js +1 -1
  42. package/dist/elements/chunks/{Icon-b5A8hlHs.js → Icon--Y8vsFal.js} +1 -1
  43. package/dist/elements/chunks/action-icons-D9u3OzYW.js +1 -0
  44. package/dist/elements/chunks/arrow-left-CVh1TeN7.js +1 -0
  45. package/dist/elements/chunks/{artifact-BSuPYFHY.js → artifact-BkYcfIlZ.js} +1 -1
  46. package/dist/elements/chunks/attachments-DwfNlubq.js +1 -0
  47. package/dist/elements/chunks/audio-visualizer-D7lB6mvR.js +1 -0
  48. package/dist/elements/chunks/{badge-TIMiJFKc.js → badge-Q0-Cmwzz.js} +1 -1
  49. package/dist/elements/chunks/{button-B9okqG73.js → button-flUbeufF.js} +1 -1
  50. package/dist/elements/chunks/{card-renderer-CSoTL_e1.js → card-renderer-3Dyl-FpN.js} +1 -1
  51. package/dist/elements/chunks/check-B5kBPKeo.js +1 -0
  52. package/dist/elements/chunks/chevron-down-DZ1GS39h.js +1 -0
  53. package/dist/elements/chunks/chevron-right-CvP7OUd2.js +1 -0
  54. package/dist/elements/chunks/{choice-card-CGMc3kek.js → choice-card-D4QUIOWZ.js} +1 -1
  55. package/dist/elements/chunks/circle-CDf9g6MQ.js +1 -0
  56. package/dist/elements/chunks/circle-check-CA47Nqbz.js +1 -0
  57. package/dist/elements/chunks/{circle-x-mhH7pOK2.js → circle-x-CJ_HVbC8.js} +1 -1
  58. package/dist/elements/chunks/code-block-BdLiTitd.js +1 -0
  59. package/dist/elements/chunks/collapsible-BzbXpPzr.js +1 -0
  60. package/dist/elements/chunks/{composer-CZZmtYOT.js → composer-Byve-n8K.js} +2 -2
  61. package/dist/elements/chunks/{confirm-card-BWjf2-xo.js → confirm-card-B0flE3MN.js} +1 -1
  62. package/dist/elements/chunks/context-VLIL3sJ-.js +1 -0
  63. package/dist/elements/chunks/controllable-DTwTIlwp.js +1 -0
  64. package/dist/elements/chunks/conversation-item-BDztezOG.js +1 -0
  65. package/dist/elements/chunks/copy-Nf-kqxXH.js +1 -0
  66. package/dist/elements/chunks/{create-tween-CUrM6D_o.js → create-tween-c4Z8TDYz.js} +2 -2
  67. package/dist/elements/chunks/default-input-C2iLFq0b.js +1 -0
  68. package/dist/elements/chunks/define-wjHR1MkU.js +1 -0
  69. package/dist/elements/chunks/disclosure-CcNbyLy0.js +1 -0
  70. package/dist/elements/chunks/{download-DnCyWFJE.js → download-C4V7tBdb.js} +1 -1
  71. package/dist/elements/chunks/dropdown-BgWTthUx.js +1 -0
  72. package/dist/elements/chunks/{ellipsis-CVxqfsDZ.js → ellipsis-7gU33mL2.js} +1 -1
  73. package/dist/elements/chunks/embed-D3KewsIJ.js +1 -0
  74. package/dist/elements/chunks/{external-link-DG2sRdQL.js → external-link-CSOEsNlx.js} +1 -1
  75. package/dist/elements/chunks/{file-text-D0J9F6M7.js → file-text-D1G8khle.js} +1 -1
  76. package/dist/elements/chunks/{file-tree-yGWNK0Js.js → file-tree-zvB2i7P9.js} +1 -1
  77. package/dist/elements/chunks/{folder-NV1pi_ud.js → folder-WW2LGLid.js} +1 -1
  78. package/dist/elements/chunks/form-CQirdC4W.js +1 -0
  79. package/dist/elements/chunks/hover-card-CJJkfHTK.js +1 -0
  80. package/dist/elements/chunks/icon-Cfgmf4fa.js +1 -0
  81. package/dist/elements/chunks/{info-C8r5Q6cc.js → info-DX3YMOt6.js} +1 -1
  82. package/dist/elements/chunks/input-BtW9U6Sq.js +1 -0
  83. package/dist/elements/chunks/{kbd-OGJDUT-O.js → kbd-LGXwuT_V.js} +1 -1
  84. package/dist/elements/chunks/{link-BdsfLB7b.js → link-2My69BqT.js} +1 -1
  85. package/dist/elements/chunks/{link-preview-Cf5KOP-i.js → link-preview-OQ9IEq0f.js} +1 -1
  86. package/dist/elements/chunks/{loader-B5QzK_8_.js → loader-iOxc_Tu-.js} +1 -1
  87. package/dist/elements/chunks/{markdown-DbozyYqa.js → markdown-DgBFaGAz.js} +1 -1
  88. package/dist/elements/chunks/{message-DtXKPqiR.js → message-VMZohrXx.js} +1 -1
  89. package/dist/elements/chunks/message-circle-CpXMM-_n.js +1 -0
  90. package/dist/elements/chunks/message-square-DxcWtETQ.js +1 -0
  91. package/dist/elements/chunks/message-tZmV2A3p.js +1 -0
  92. package/dist/elements/chunks/{minimize-2-SegJ_oku.js → minimize-2-DPIUKTrT.js} +1 -1
  93. package/dist/elements/chunks/{model-switcher-D7JrFFHp.js → model-switcher-DsT8tFB0.js} +1 -1
  94. package/dist/elements/chunks/{overlay-CV7z2YuX.js → overlay-DuiwdXjm.js} +1 -1
  95. package/dist/elements/chunks/{paperclip-Bg0ITU3b.js → paperclip-CRZVp4z_.js} +1 -1
  96. package/dist/elements/chunks/{progress-bar-D1_rzt6N.js → progress-bar-DNy66e_E.js} +1 -1
  97. package/dist/elements/chunks/{prompt-suggestion-D5Sm8xF1.js → prompt-suggestion-Bn64Nl7L.js} +1 -1
  98. package/dist/elements/chunks/reasoning-Emn9N4-T.js +1 -0
  99. package/dist/elements/chunks/{resizable-Dpzjlvp4.js → resizable-D181b4fM.js} +1 -1
  100. package/dist/elements/chunks/{rotate-cw-DzVDJOA1.js → rotate-cw-CPWe37D9.js} +1 -1
  101. package/dist/elements/chunks/{scroll-area-93A1bbeG.js → scroll-area-ClZkZxIk.js} +1 -1
  102. package/dist/elements/chunks/scroll-button-DPE-t3x_.js +1 -0
  103. package/dist/elements/chunks/{separator-DH2r_ZSZ.js → separator-CeJHQqLW.js} +1 -1
  104. package/dist/elements/chunks/{settings-BFMOd6yB.js → settings-CqaHgJF9.js} +1 -1
  105. package/dist/elements/chunks/{settings-group-B3VZKIcz.js → settings-group-CjqjLCOn.js} +1 -1
  106. package/dist/elements/chunks/share-CyfnNEqp.js +1 -0
  107. package/dist/elements/chunks/{skeleton-N8BuWYmf.js → skeleton-D8akBnKS.js} +1 -1
  108. package/dist/elements/chunks/slots-DaNjX0rc.js +1 -0
  109. package/dist/elements/chunks/{source-w9V0NnBn.js → source-UWCvmVak.js} +1 -1
  110. package/dist/elements/chunks/{star-DHvACxtm.js → star-DoHFAikQ.js} +1 -1
  111. package/dist/elements/chunks/store-Cjq0qwYN.js +1 -0
  112. package/dist/elements/chunks/{tasks-card-lPxoodlA.js → tasks-card-CmZ5xh6v.js} +1 -1
  113. package/dist/elements/chunks/{text-shimmer-BY_rI3s5.js → text-shimmer-DYn09zrz.js} +1 -1
  114. package/dist/elements/chunks/textarea-skiGHURM.js +1 -0
  115. package/dist/elements/chunks/{thumbs-up-DQe0hvkZ.js → thumbs-up-DX2Ijk3H.js} +1 -1
  116. package/dist/elements/chunks/{toast-store-VUZZBhzH.js → toast-store-CFnQpThX.js} +1 -1
  117. package/dist/elements/chunks/{tool-C1YtxwPu.js → tool-DKQ2D1DP.js} +1 -1
  118. package/dist/elements/chunks/{tooltip-BqwnFWhn.js → tooltip-B0G99y8w.js} +1 -1
  119. package/dist/elements/chunks/{triangle-alert-B6or7F5u.js → triangle-alert-F9cyUEyy.js} +1 -1
  120. package/dist/elements/chunks/{use-card-resolution-DJg32jGH.js → use-card-resolution-DoA2f_EU.js} +1 -1
  121. package/dist/elements/chunks/{variant-aurora-QXTZPyST.js → variant-aurora-qt6Zct8M.js} +2 -2
  122. package/dist/elements/chunks/variant-custom-tJp22_BQ.js +1 -0
  123. package/dist/{variant-wave-BwzrHD1s.js → elements/chunks/variant-wave-CaQ5ti39.js} +2 -2
  124. package/dist/elements/chunks/x-B6UnOiLw.js +1 -0
  125. package/dist/elements/coachmark.js +1 -1
  126. package/dist/elements/code-block.js +1 -1
  127. package/dist/elements/command.js +1 -1
  128. package/dist/elements/compare.js +1 -1
  129. package/dist/elements/composer.js +1 -1
  130. package/dist/elements/confirm-card.js +1 -1
  131. package/dist/elements/context-meter.js +1 -1
  132. package/dist/elements/conversation-item.d.ts +1 -0
  133. package/dist/elements/conversation-item.js +1 -0
  134. package/dist/elements/conversation-list.js +1 -1
  135. package/dist/elements/default-input.d.ts +3 -3
  136. package/dist/elements/define.d.ts +27 -0
  137. package/dist/elements/diagnostic-events.d.ts +74 -0
  138. package/dist/elements/dialog.js +1 -1
  139. package/dist/elements/dock.d.ts +1 -0
  140. package/dist/elements/dock.js +149 -0
  141. package/dist/elements/dropdown.d.ts +1 -0
  142. package/dist/elements/dropdown.js +1 -0
  143. package/dist/elements/editable-label.js +1 -1
  144. package/dist/elements/element-diagnostics.d.ts +81 -0
  145. package/dist/elements/embed.js +1 -1
  146. package/dist/elements/empty.js +1 -1
  147. package/dist/elements/feedback-bar.js +1 -1
  148. package/dist/elements/file-tree.js +1 -1
  149. package/dist/elements/file-upload.js +1 -1
  150. package/dist/elements/form.js +1 -1
  151. package/dist/elements/hover-card.js +1 -1
  152. package/dist/elements/icon.js +1 -1
  153. package/dist/elements/image.js +1 -1
  154. package/dist/elements/input.js +1 -1
  155. package/dist/elements/kbd.js +1 -1
  156. package/dist/elements/link-preview.js +1 -1
  157. package/dist/elements/loader.js +1 -1
  158. package/dist/elements/markdown.js +1 -1
  159. package/dist/elements/menu.js +1 -1
  160. package/dist/elements/message-skills.js +1 -1
  161. package/dist/elements/message.js +1 -1
  162. package/dist/elements/model-switcher.js +1 -1
  163. package/dist/elements/nav.js +1 -1
  164. package/dist/elements/notice.js +1 -1
  165. package/dist/elements/pane-group.js +1 -1
  166. package/dist/elements/pane.js +1 -1
  167. package/dist/elements/popover.js +1 -1
  168. package/dist/elements/progress-bar.js +1 -1
  169. package/dist/elements/prompt-dock.js +1 -1
  170. package/dist/elements/prompt-input.js +1 -1
  171. package/dist/elements/prompt-suggestions.js +1 -1
  172. package/dist/elements/reasoning.js +1 -1
  173. package/dist/elements/register.d.ts +2 -0
  174. package/dist/elements/remote.js +1 -1
  175. package/dist/elements/resizable.js +1 -1
  176. package/dist/elements/response-stream.js +3 -3
  177. package/dist/elements/screen.js +1 -1
  178. package/dist/elements/scroll-area.js +1 -1
  179. package/dist/elements/scroll-button.js +1 -1
  180. package/dist/elements/search.js +1 -1
  181. package/dist/elements/segmented.js +1 -1
  182. package/dist/elements/separator.js +1 -1
  183. package/dist/elements/setting-item.js +1 -1
  184. package/dist/elements/settings-group.js +1 -1
  185. package/dist/elements/skeleton.js +1 -1
  186. package/dist/elements/slots.d.ts +35 -3
  187. package/dist/elements/source.js +1 -1
  188. package/dist/elements/status.js +1 -1
  189. package/dist/elements/switch.js +1 -1
  190. package/dist/elements/tabs.js +1 -1
  191. package/dist/elements/tasks.js +1 -1
  192. package/dist/elements/text-shimmer.js +1 -1
  193. package/dist/elements/thinking-bar.js +1 -1
  194. package/dist/elements/thread.js +1 -1
  195. package/dist/elements/toast.js +1 -1
  196. package/dist/elements/tool.js +1 -1
  197. package/dist/elements/tooltip.js +1 -1
  198. package/dist/elements/voice-input.js +1 -1
  199. package/dist/elements/voice-output.js +1 -1
  200. package/dist/elements.d.ts +232 -148
  201. package/dist/index.d.ts +2 -0
  202. package/dist/index.js +5456 -4931
  203. package/dist/index.server.js +4142 -3669
  204. package/dist/kai-provider.es.js +40 -40
  205. package/dist/kai.es.js +1 -1
  206. package/dist/llms/llms-full.txt +184 -69
  207. package/dist/llms/llms.txt +3 -3
  208. package/dist/mcp.es.js +2669 -546
  209. package/dist/primitives/use-resize-observer.d.ts +23 -0
  210. package/dist/primitives/use-speech-recognition.d.ts +8 -0
  211. package/dist/primitives/use-text-stream.d.ts +5 -0
  212. package/dist/react/index.d.ts +115 -266
  213. package/dist/react.js +247 -221
  214. package/dist/register-impl-DpE7icIb.js +293 -0
  215. package/dist/schemas/index.d.ts +1 -1
  216. package/dist/schemas/tool-defs.d.ts +35 -0
  217. package/dist/schemas.js +403 -310
  218. package/dist/{solid-BMuDmFo_.js → solid-BtdqNZI7.js} +8435 -7394
  219. package/dist/{solid-CGYNdLRR.js → solid-CnavwBye.js} +5987 -5035
  220. package/dist/solid.d.ts +5 -0
  221. package/dist/solid.js +210 -203
  222. package/dist/solid.server.js +210 -203
  223. package/dist/state/index.d.ts +4 -0
  224. package/dist/state/persistence.d.ts +51 -0
  225. package/dist/state/stream.d.ts +50 -0
  226. package/dist/state/threads.d.ts +71 -0
  227. package/dist/state.js +269 -169
  228. package/dist/types.d.ts +4 -2
  229. package/dist/ui/dock.d.ts +109 -0
  230. package/dist/ui/hover-card.d.ts +44 -0
  231. package/dist/{variant-aurora-DwSOfraQ.js → variant-aurora-B8II3-I1.js} +27 -27
  232. package/dist/{variant-aurora-wKvAQ5wp.js → variant-aurora-CMNWOSJR.js} +28 -28
  233. package/dist/{variant-aurora-XEkPT0_z.js → variant-aurora-CcuDMWwQ.js} +2 -2
  234. package/dist/{variant-custom-eFIg2XWQ.js → variant-custom-BdvYC7af.js} +40 -40
  235. package/dist/{variant-custom-BhS9wIpU.js → variant-custom-C714mqKl.js} +65 -65
  236. package/dist/variant-custom-L16JLLZy.js +1 -0
  237. package/dist/{elements/chunks/variant-wave-DDCwhLas.js → variant-wave-2S4La2Ka.js} +2 -2
  238. package/dist/{variant-wave-CbVsmgwT.js → variant-wave-D7ruiA1W.js} +25 -25
  239. package/dist/{variant-wave-CUWGx9Bn.js → variant-wave-ecwykeyL.js} +21 -21
  240. package/dist/wire/chunk.d.ts +47 -0
  241. package/dist/wire/diagnostics.d.ts +575 -0
  242. package/dist/wire/encode-probe.d.ts +70 -0
  243. package/dist/wire/encode.d.ts +24 -0
  244. package/dist/wire/index.d.ts +2 -0
  245. package/dist/wire/sse.d.ts +10 -2
  246. package/dist/wire.js +917 -480
  247. package/frameworks/react/index.tsx +132 -93
  248. package/llms-full.txt +184 -69
  249. package/llms.txt +3 -3
  250. package/package.json +27 -7
  251. package/src/agent-tooling/archetypes.ts +41 -9
  252. package/src/agent-tooling/catalog/README.md +676 -0
  253. package/src/agent-tooling/catalog/catalog-types.ts +231 -0
  254. package/src/agent-tooling/catalog/fabrications.ts +96 -0
  255. package/src/agent-tooling/catalog/invariants.ts +284 -0
  256. package/src/agent-tooling/catalog/labs-titles.ts +114 -0
  257. package/src/agent-tooling/catalog/scenarios.ts +87 -0
  258. package/src/agent-tooling/catalog/surfaces.ts +275 -0
  259. package/src/agent-tooling/integrations/anthropic.ts +7 -1
  260. package/src/agent-tooling/integrations/cloudflare.ts +43 -2
  261. package/src/agent-tooling/integrations/langgraph.ts +7 -1
  262. package/src/agent-tooling/integrations/mastra.ts +7 -1
  263. package/src/agent-tooling/integrations/mock.ts +92 -17
  264. package/src/agent-tooling/integrations/ollama.ts +7 -1
  265. package/src/agent-tooling/integrations/openai.ts +7 -1
  266. package/src/agent-tooling/integrations/openrouter.ts +7 -1
  267. package/src/agent-tooling/integrations/pi.ts +56 -1
  268. package/src/agent-tooling/integrations/vercel-ai-sdk.ts +7 -1
  269. package/src/agent-tooling/mcp/css-raw.d.ts +12 -0
  270. package/src/agent-tooling/mcp/manifest.ts +100 -1
  271. package/src/agent-tooling/mcp/server.ts +61 -5
  272. package/src/agent-tooling/mcp/tools/reference.ts +440 -4
  273. package/src/agent-tooling/mcp/tools/scaffold.ts +1834 -307
  274. package/src/agent-tooling/mcp/tools/theme.ts +146 -30
  275. package/src/agent-tooling/mcp/validate-args.ts +141 -0
  276. package/src/agent-tooling/registry.ts +19 -7
  277. package/src/agent-tooling/route-emit.ts +26 -2
  278. package/src/components/attachment-types.ts +47 -1
  279. package/src/components/attachments.tsx +169 -22
  280. package/src/components/audio-visualizer/fit-scale.ts +112 -0
  281. package/src/components/audio-visualizer/index.tsx +80 -3
  282. package/src/components/audio-visualizer/variant-aurora.tsx +10 -4
  283. package/src/components/audio-visualizer/variant-bar.tsx +38 -6
  284. package/src/components/audio-visualizer/variant-custom.tsx +8 -2
  285. package/src/components/audio-visualizer/variant-grid.tsx +16 -11
  286. package/src/components/audio-visualizer/variant-radial.tsx +15 -10
  287. package/src/components/audio-visualizer/variant-wave.tsx +7 -2
  288. package/src/components/chat-container.tsx +4 -1
  289. package/src/components/chat-thread.tsx +36 -7
  290. package/src/components/code-block.tsx +79 -3
  291. package/src/components/composer.tsx +8 -1
  292. package/src/components/conversation-item.tsx +114 -4
  293. package/src/components/conversation-list.tsx +212 -12
  294. package/src/components/embed.tsx +4 -0
  295. package/src/components/form.tsx +41 -14
  296. package/src/components/message.tsx +75 -5
  297. package/src/components/response-stream.tsx +13 -7
  298. package/src/components/screen.tsx +5 -0
  299. package/src/components/scroll-button.tsx +7 -0
  300. package/src/components/toast.tsx +11 -5
  301. package/src/components/voice-input.tsx +35 -3
  302. package/src/components/voice-output.tsx +46 -6
  303. package/src/components/workspace-shell.tsx +285 -0
  304. package/src/diagnostics/hook.ts +352 -0
  305. package/src/diagnostics/index.ts +82 -0
  306. package/src/diagnostics/report-request.ts +296 -0
  307. package/src/elements/attachments.tsx +6 -7
  308. package/src/elements/audio-visualizer.tsx +48 -4
  309. package/src/elements/chat-workspace.tsx +159 -287
  310. package/src/elements/chat.tsx +12 -9
  311. package/src/elements/code-block.tsx +19 -1
  312. package/src/elements/command.tsx +4 -1
  313. package/src/elements/compiled.css +1 -1
  314. package/src/elements/conversation-item.tsx +80 -0
  315. package/src/elements/conversation-list.tsx +60 -11
  316. package/src/elements/default-input.tsx +5 -5
  317. package/src/elements/define.tsx +168 -8
  318. package/src/elements/diagnostic-events.ts +114 -0
  319. package/src/elements/dialog.tsx +47 -0
  320. package/src/elements/disclosure.ts +34 -12
  321. package/src/elements/dock.tsx +204 -0
  322. package/src/elements/dropdown.tsx +123 -0
  323. package/src/elements/element-diagnostics.ts +392 -0
  324. package/src/elements/element-manifest.json +12 -0
  325. package/src/elements/element-meta.json +672 -439
  326. package/src/elements/element-nonscalar.json +170 -0
  327. package/src/elements/element-types.d.ts +232 -148
  328. package/src/elements/menu.tsx +13 -0
  329. package/src/elements/prompt-dock.tsx +2 -1
  330. package/src/elements/prompt-input.tsx +8 -8
  331. package/src/elements/register-impl.ts +46 -0
  332. package/src/elements/register.ts +28 -0
  333. package/src/elements/resizable.tsx +52 -25
  334. package/src/elements/scroll-button.tsx +5 -0
  335. package/src/elements/slots.ts +107 -12
  336. package/src/elements/styles.css +30 -6
  337. package/src/elements/thinking-bar.tsx +16 -7
  338. package/src/elements/toast.tsx +3 -0
  339. package/src/elements/tool.tsx +26 -5
  340. package/src/elements/voice-input.tsx +11 -2
  341. package/src/elements/voice-output.tsx +16 -3
  342. package/src/index.ts +2 -0
  343. package/src/primitives/use-resize-observer.ts +33 -0
  344. package/src/primitives/use-speech-recognition.ts +12 -1
  345. package/src/primitives/use-stick-to-bottom.ts +34 -2
  346. package/src/primitives/use-text-stream.ts +33 -2
  347. package/src/remote/provider-runtime.ts +6 -3
  348. package/src/schemas/index.ts +1 -0
  349. package/src/schemas/tool-defs.ts +297 -6
  350. package/src/solid.ts +5 -0
  351. package/src/state/index.ts +12 -0
  352. package/src/state/persistence.ts +180 -0
  353. package/src/state/stream.ts +71 -4
  354. package/src/state/threads.ts +142 -0
  355. package/src/types.ts +4 -2
  356. package/src/ui/dialog.tsx +6 -0
  357. package/src/ui/dock.tsx +445 -0
  358. package/src/ui/dropdown.tsx +67 -23
  359. package/src/ui/hover-card.tsx +156 -6
  360. package/src/ui/input.tsx +29 -10
  361. package/src/ui/resizable.tsx +11 -0
  362. package/src/wire/chunk.ts +47 -0
  363. package/src/wire/consume.ts +185 -26
  364. package/src/wire/diagnostics.ts +727 -0
  365. package/src/wire/encode-probe.ts +214 -0
  366. package/src/wire/encode.ts +267 -14
  367. package/src/wire/formats/anthropic.ts +8 -1
  368. package/src/wire/formats/openai.ts +5 -0
  369. package/src/wire/index.ts +22 -0
  370. package/src/wire/read.ts +250 -6
  371. package/src/wire/sse.ts +16 -3
  372. package/dist/elements/chunks/action-icons-DW9muWrY.js +0 -1
  373. package/dist/elements/chunks/arrow-left-iJVnQmxA.js +0 -1
  374. package/dist/elements/chunks/attachments-CL6TaqIb.js +0 -1
  375. package/dist/elements/chunks/audio-visualizer-BuUqQmaO.js +0 -1
  376. package/dist/elements/chunks/chat-thread-DxoKaStk.js +0 -1
  377. package/dist/elements/chunks/check-MdLzbxrm.js +0 -1
  378. package/dist/elements/chunks/chevron-down-MK7IzDqe.js +0 -1
  379. package/dist/elements/chunks/chevron-right-C5jXhmtV.js +0 -1
  380. package/dist/elements/chunks/circle-BG7VkPep.js +0 -1
  381. package/dist/elements/chunks/circle-check-GqvO2UBs.js +0 -1
  382. package/dist/elements/chunks/code-block-ClhQO9RW.js +0 -1
  383. package/dist/elements/chunks/collapsible-DBcBkFPh.js +0 -1
  384. package/dist/elements/chunks/context-hKjNqiyQ.js +0 -1
  385. package/dist/elements/chunks/conversation-list-CsGJjSKG.js +0 -1
  386. package/dist/elements/chunks/default-input-B1Mem5wu.js +0 -1
  387. package/dist/elements/chunks/define-B_tXMYRm.js +0 -1
  388. package/dist/elements/chunks/disclosure-DAoYOKew.js +0 -1
  389. package/dist/elements/chunks/dropdown-CmNna5lT.js +0 -1
  390. package/dist/elements/chunks/embed-CjAD2jSi.js +0 -1
  391. package/dist/elements/chunks/form-Cp8Y00Wn.js +0 -1
  392. package/dist/elements/chunks/hover-card-6KtXpLwT.js +0 -1
  393. package/dist/elements/chunks/icon-97R8SR2p.js +0 -1
  394. package/dist/elements/chunks/input-DrseEjhp.js +0 -1
  395. package/dist/elements/chunks/message-CE4k-qaj.js +0 -1
  396. package/dist/elements/chunks/message-square-C9ovmtOo.js +0 -1
  397. package/dist/elements/chunks/reasoning-BrxQfpfI.js +0 -1
  398. package/dist/elements/chunks/scroll-button-CrTo7wm4.js +0 -1
  399. package/dist/elements/chunks/share-DgNbkJKY.js +0 -1
  400. package/dist/elements/chunks/slots-CIw9RlAe.js +0 -1
  401. package/dist/elements/chunks/store-HIPGhNz9.js +0 -1
  402. package/dist/elements/chunks/textarea-DPfuhswM.js +0 -1
  403. package/dist/elements/chunks/variant-custom-D5ZlmziF.js +0 -1
  404. package/dist/elements/chunks/video-Bb86fVYI.js +0 -1
  405. package/dist/elements/chunks/x-BOhjBeOd.js +0 -1
  406. package/dist/primitives/card-validate-generator.testlib.d.ts +0 -20
  407. package/dist/register-impl-DGmGzrEM.js +0 -145
  408. package/dist/variant-custom-MkTNTycd.js +0 -1
  409. package/src/primitives/card-validate-generator.testlib.ts +0 -38
package/dist/wire.js CHANGED
@@ -1,13 +1,13 @@
1
- var H = Object.defineProperty;
2
- var z = (t, e, n) => e in t ? H(t, e, { enumerable: !0, configurable: !0, writable: !0, value: n }) : t[e] = n;
3
- var A = (t, e, n) => z(t, typeof e != "symbol" ? e + "" : e, n);
4
- async function* X(t) {
1
+ var mt = Object.defineProperty;
2
+ var xt = (t, e, n) => e in t ? mt(t, e, { enumerable: !0, configurable: !0, writable: !0, value: n }) : t[e] = n;
3
+ var S = (t, e, n) => xt(t, typeof e != "symbol" ? e + "" : e, n);
4
+ async function* kt(t) {
5
5
  const e = t.getReader();
6
6
  let n = !1;
7
7
  try {
8
8
  for (; ; ) {
9
- const { value: o, done: r } = await e.read();
10
- if (r) {
9
+ const { value: o, done: s } = await e.read();
10
+ if (s) {
11
11
  n = !0;
12
12
  return;
13
13
  }
@@ -18,18 +18,18 @@ async function* X(t) {
18
18
  }), e.releaseLock();
19
19
  }
20
20
  }
21
- function Q(t) {
22
- return typeof t.getReader == "function" ? X(t) : t;
21
+ function bt(t) {
22
+ return typeof t.getReader == "function" ? kt(t) : t;
23
23
  }
24
- async function* V(t) {
24
+ async function* wt(t) {
25
25
  const e = new TextDecoder();
26
26
  let n = "", o = [];
27
- const r = () => {
27
+ const s = () => {
28
28
  if (o.length === 0) return;
29
29
  const a = o.join(`
30
30
  `);
31
31
  return o = [], a;
32
- }, s = (a) => {
32
+ }, r = (a) => {
33
33
  const c = a.endsWith("\r") ? a.slice(0, -1) : a;
34
34
  if (c === "") return "boundary";
35
35
  if (c.startsWith(":")) return "skip";
@@ -39,72 +39,73 @@ async function* V(t) {
39
39
  }
40
40
  return "skip";
41
41
  };
42
- for await (const a of Q(t)) {
42
+ for await (const a of bt(t)) {
43
43
  n += typeof a == "string" ? a : e.decode(a, { stream: !0 });
44
44
  let c = n.indexOf(`
45
45
  `);
46
46
  for (; c !== -1; ) {
47
47
  const u = n.slice(0, c);
48
- if (n = n.slice(c + 1), s(u) === "boundary") {
49
- const d = r();
48
+ if (n = n.slice(c + 1), r(u) === "boundary") {
49
+ const d = s();
50
50
  d !== void 0 && (yield d);
51
51
  }
52
52
  c = n.indexOf(`
53
53
  `);
54
54
  }
55
55
  }
56
- n += e.decode(), n && s(n);
57
- const i = r();
56
+ n += e.decode(), n && r(n);
57
+ const i = s();
58
58
  i !== void 0 && (yield i);
59
59
  }
60
- async function* Z(t) {
61
- let e = !1;
62
- for await (const n of V(t))
63
- if (!e) {
64
- if (n === "[DONE]") {
65
- e = !0;
60
+ async function* vt(t, e) {
61
+ let n = !1;
62
+ for await (const o of wt(t))
63
+ if (!n) {
64
+ if (o === "[DONE]") {
65
+ n = !0;
66
66
  continue;
67
67
  }
68
68
  try {
69
- yield JSON.parse(n);
69
+ const s = JSON.parse(o);
70
+ e == null || e(o), yield s;
70
71
  } catch {
71
72
  }
72
73
  }
73
74
  }
74
- function $(t) {
75
+ function L(t) {
75
76
  const e = t.toLowerCase();
76
77
  return e ? e.includes("bash") || e.includes("command") || e.includes("shell") || e.includes("terminal") || e.includes("exec") ? "command" : e.includes("edit") || e.includes("write") || e.includes("patch") || e.includes("replace") || e.includes("delete") ? "file-change" : e.includes("search") || e.includes("grep") || e.includes("glob") || e.includes("find") ? "search" : e.includes("fetch") || e.includes("http") || e.includes("browse") || e.includes("crawl") ? "fetch" : e.includes("mcp") ? "mcp" : e.includes("image") || e.includes("screenshot") || e.includes("vision") ? "image" : "generic" : "generic";
77
78
  }
78
- function O(t) {
79
+ function C(t) {
79
80
  const e = /* @__PURE__ */ new WeakSet(), n = (o) => {
80
81
  if (o === null || typeof o != "object") return o;
81
82
  if (e.has(o)) return "[circular]";
82
83
  e.add(o);
83
- const r = o, s = Array.isArray(o) ? o.map(n) : Object.fromEntries(Object.keys(r).sort().map((i) => [i, n(r[i])]));
84
- return e.delete(o), s;
84
+ const s = o, r = Array.isArray(o) ? o.map(n) : Object.fromEntries(Object.keys(s).sort().map((i) => [i, n(s[i])]));
85
+ return e.delete(o), r;
85
86
  };
86
87
  return JSON.stringify(n(t)) ?? "";
87
88
  }
88
- function tt(t, e) {
89
+ function Tt(t, e) {
89
90
  const n = t[t.length - 1];
90
91
  return (n == null ? void 0 : n.type) === "text" ? [...t.slice(0, -1), { ...n, text: n.text + e }] : [...t, { type: "text", text: e }];
91
92
  }
92
- function et(t, e, n = {}) {
93
- const o = n.index ?? 0, r = n.streamId, s = t.findIndex(
94
- (c) => c.type === "reasoning" && (c.index ?? 0) === o && c.streamId === r
93
+ function _t(t, e, n = {}) {
94
+ const o = n.index ?? 0, s = n.streamId, r = t.findIndex(
95
+ (c) => c.type === "reasoning" && (c.index ?? 0) === o && c.streamId === s
95
96
  );
96
- if (s < 0)
97
- return [...t, { type: "reasoning", text: e, index: o, streamId: r, label: n.label, signature: n.signature, raw: n.raw }];
98
- const i = t[s], a = {
97
+ if (r < 0)
98
+ return [...t, { type: "reasoning", text: e, index: o, streamId: s, label: n.label, signature: n.signature, raw: n.raw }];
99
+ const i = t[r], a = {
99
100
  ...i,
100
101
  text: i.text + e,
101
102
  label: n.label ?? i.label,
102
103
  signature: n.signature ?? i.signature,
103
104
  raw: n.raw ?? i.raw
104
105
  };
105
- return rt(i, a) ? t : [...t.slice(0, s), a, ...t.slice(s + 1)];
106
+ return Ot(i, a) ? t : [...t.slice(0, r), a, ...t.slice(r + 1)];
106
107
  }
107
- const nt = [
108
+ const It = [
108
109
  "type",
109
110
  "text",
110
111
  "index",
@@ -112,7 +113,7 @@ const nt = [
112
113
  "label",
113
114
  "signature",
114
115
  "raw"
115
- ], ot = {
116
+ ], At = {
116
117
  type: (t, e) => t.type === e.type,
117
118
  text: (t, e) => t.text === e.text,
118
119
  index: (t, e) => t.index === e.index,
@@ -121,10 +122,10 @@ const nt = [
121
122
  signature: (t, e) => t.signature === e.signature,
122
123
  raw: (t, e) => t.raw === e.raw
123
124
  };
124
- function rt(t, e) {
125
- return nt.every((n) => ot[n](t, e));
125
+ function Ot(t, e) {
126
+ return It.every((n) => At[n](t, e));
126
127
  }
127
- function it(t, e, n) {
128
+ function St(t, e, n) {
128
129
  const o = t.findIndex((i) => i.type === "tool" && i.tool.toolCallId === e);
129
130
  if (o < 0) {
130
131
  const i = {
@@ -133,15 +134,15 @@ function it(t, e, n) {
133
134
  ...n,
134
135
  toolCallId: e
135
136
  };
136
- return i.kind = i.kind ?? $(i.type), [...t, { type: "tool", tool: i }];
137
+ return i.kind = i.kind ?? L(i.type), [...t, { type: "tool", tool: i }];
137
138
  }
138
- const r = t[o].tool, s = { ...r, ...n, toolCallId: e };
139
- return s.kind = st(r, n, s.type), s.raw === void 0 && r.raw !== void 0 && (s.raw = r.raw), ct(r, s) ? t : [...t.slice(0, o), { type: "tool", tool: s }, ...t.slice(o + 1)];
139
+ const s = t[o].tool, r = { ...s, ...n, toolCallId: e };
140
+ return r.kind = Rt(s, n, r.type), r.raw === void 0 && s.raw !== void 0 && (r.raw = s.raw), Ct(s, r) ? t : [...t.slice(0, o), { type: "tool", tool: r }, ...t.slice(o + 1)];
140
141
  }
141
- function st(t, e, n) {
142
- return e.kind !== void 0 ? e.kind : t.kind === void 0 || t.kind === $(t.type) ? $(n) : t.kind;
142
+ function Rt(t, e, n) {
143
+ return e.kind !== void 0 ? e.kind : t.kind === void 0 || t.kind === L(t.type) ? L(n) : t.kind;
143
144
  }
144
- const at = [
145
+ const Et = [
145
146
  "type",
146
147
  "state",
147
148
  "kind",
@@ -151,7 +152,7 @@ const at = [
151
152
  "raw",
152
153
  "input",
153
154
  "output"
154
- ], ut = {
155
+ ], $t = {
155
156
  type: (t, e) => t.type === e.type,
156
157
  state: (t, e) => t.state === e.state,
157
158
  kind: (t, e) => t.kind === e.kind,
@@ -159,13 +160,13 @@ const at = [
159
160
  errorText: (t, e) => t.errorText === e.errorText,
160
161
  rawInput: (t, e) => t.rawInput === e.rawInput,
161
162
  raw: (t, e) => t.raw === e.raw,
162
- input: (t, e) => t.input === e.input || O(t.input) === O(e.input),
163
- output: (t, e) => t.output === e.output || O(t.output) === O(e.output)
163
+ input: (t, e) => t.input === e.input || C(t.input) === C(e.input),
164
+ output: (t, e) => t.output === e.output || C(t.output) === C(e.output)
164
165
  };
165
- function ct(t, e) {
166
- return at.every((n) => ut[n](t, e));
166
+ function Ct(t, e) {
167
+ return Et.every((n) => $t[n](t, e));
167
168
  }
168
- const dt = {
169
+ const Ut = {
169
170
  // OpenAI chat completions
170
171
  stop: "stop",
171
172
  length: "length",
@@ -181,23 +182,73 @@ const dt = {
181
182
  refusal: "content-filter",
182
183
  pause_turn: "other"
183
184
  };
184
- function lt(t) {
185
+ function z(t) {
185
186
  if (t)
186
- return dt[t] ?? "other";
187
+ return Ut[t] ?? "other";
188
+ }
189
+ function rt(t, e) {
190
+ return {
191
+ streamId: t,
192
+ ...e.traceId !== void 0 ? { traceId: e.traceId } : {},
193
+ ...e.label !== void 0 ? { label: e.label } : {}
194
+ };
195
+ }
196
+ const j = Symbol.for("kai.wire.diagnostics.v1");
197
+ function q() {
198
+ return globalThis[j];
199
+ }
200
+ function it() {
201
+ const t = globalThis;
202
+ return t[j] ?? (t[j] = { subs: [], seq: 0, payload: !1 });
203
+ }
204
+ function $e(t) {
205
+ const e = it().subs;
206
+ e.push(t);
207
+ let n = !0;
208
+ return () => {
209
+ if (!n) return;
210
+ n = !1;
211
+ const o = e.indexOf(t);
212
+ o !== -1 && e.splice(o, 1);
213
+ };
187
214
  }
188
- const pt = (t) => ({
215
+ function A() {
216
+ const t = q();
217
+ return t !== void 0 && t.subs.length > 0;
218
+ }
219
+ function W() {
220
+ const t = q();
221
+ return t !== void 0 && t.payload;
222
+ }
223
+ function R(t) {
224
+ return W() ? { payload: t() } : {};
225
+ }
226
+ function O(t) {
227
+ const e = q();
228
+ if (e)
229
+ for (const n of [...e.subs])
230
+ try {
231
+ n(t);
232
+ } catch {
233
+ }
234
+ }
235
+ function at() {
236
+ const t = it();
237
+ return `wire-${++t.seq}`;
238
+ }
239
+ const Dt = (t) => ({
189
240
  index: t.index,
190
241
  id: t.id ?? `call_${t.index}`,
191
242
  name: t.name,
192
243
  argumentsText: t.argumentsText
193
- }), ft = (t) => ({
244
+ }), Pt = (t) => ({
194
245
  source: "custom.wire.tool_call",
195
246
  payload: { id: t.id ?? `call_${t.index}`, name: t.name, arguments: t.argumentsText }
196
247
  });
197
- function gt(t, e) {
248
+ function Nt(t, e) {
198
249
  return t.length <= e ? t : `${t.slice(0, e)}...`;
199
250
  }
200
- function ht(t) {
251
+ function jt(t) {
201
252
  const e = t.trim();
202
253
  if (e !== "")
203
254
  try {
@@ -207,18 +258,18 @@ function ht(t) {
207
258
  return;
208
259
  }
209
260
  }
210
- function yt(t, e = {}) {
261
+ function Lt(t, e = {}) {
211
262
  const n = /* @__PURE__ */ new Map(), o = (a) => {
212
- const c = a.id, u = a.argumentsText, d = ht(u);
263
+ const c = a.id, u = a.argumentsText, d = jt(u);
213
264
  if (d) {
214
- const l = O(d);
215
- if (l !== a.lastInputFp) {
216
- a.lastInputFp = l, t.upsertTool(c, { rawInput: u, input: d, state: "input-available" });
265
+ const g = C(d);
266
+ if (g !== a.lastInputFp) {
267
+ a.lastInputFp = g, t.upsertTool(c, { rawInput: u, input: d, state: "input-available" });
217
268
  return;
218
269
  }
219
270
  }
220
271
  t.upsertTool(c, { rawInput: u });
221
- }, r = (a) => {
272
+ }, s = (a) => {
222
273
  a.announced || (a.id ?? (a.id = `call_${a.index}`), a.announced = !0, t.upsertTool(a.id, { type: a.name || "unknown_tool", state: "input-streaming" }), a.argumentsText && o(a));
223
274
  };
224
275
  return { apply: (a) => {
@@ -232,79 +283,102 @@ function yt(t, e = {}) {
232
283
  announced: !1,
233
284
  lastInputFp: null,
234
285
  providerExecuted: !1
235
- }, n.set(c, u)), a.id && !u.id && (u.id = a.id), a.name && (u.name += a.name), u.id && u.name && r(u), typeof a.arguments == "string" && a.arguments !== "" && (u.argumentsText += a.arguments, u.announced && o(u)), (a.output !== void 0 || a.outputError !== void 0) && (r(u), u.providerExecuted = !0, a.outputError !== void 0 ? (u.outputError = a.outputError, t.upsertTool(u.id, { state: "output-error", errorText: a.outputError })) : (u.output = a.output, t.upsertTool(u.id, { state: "output-available", output: a.output })));
286
+ }, n.set(c, u)), a.id && !u.id && (u.id = a.id), a.name && (u.name += a.name), u.id && u.name && s(u), typeof a.arguments == "string" && a.arguments !== "" && (u.argumentsText += a.arguments, u.announced && o(u)), (a.output !== void 0 || a.outputError !== void 0) && (s(u), u.providerExecuted = !0, a.outputError !== void 0 ? (u.outputError = a.outputError, t.upsertTool(u.id, { state: "output-error", errorText: a.outputError })) : (u.output = a.output, t.upsertTool(u.id, { state: "output-available", output: a.output })));
236
287
  }, settle: (a, c) => [...n.values()].sort((u, d) => u.index - d.index).map((u) => {
237
- var m;
238
- r(u);
239
- const d = u.id, l = pt(u);
288
+ var h;
289
+ s(u);
290
+ const d = u.id, g = Dt(u);
240
291
  if (u.providerExecuted)
241
292
  return {
242
- ...l,
293
+ ...g,
243
294
  providerExecuted: !0,
244
295
  ...u.output !== void 0 ? { output: u.output } : {},
245
296
  ...u.outputError !== void 0 ? { error: u.outputError } : {}
246
297
  };
247
- const p = ft(u), h = u.name || "unknown_tool";
298
+ const f = Pt(u), p = u.name || "unknown_tool";
248
299
  if (c) {
249
- const y = `Stream failed before the tool call completed: ${c}`;
300
+ const m = `Stream failed before the tool call completed: ${c}`;
250
301
  return t.upsertTool(d, {
251
- type: h,
302
+ type: p,
252
303
  state: "output-error",
253
- errorText: y,
304
+ errorText: m,
254
305
  rawInput: u.argumentsText,
255
- raw: p
256
- }), { ...l, error: y };
306
+ raw: f
307
+ }), { ...g, error: m };
257
308
  }
258
309
  if (!u.name) {
259
- const y = "Tool call arrived with no function name; cannot dispatch it.";
260
- return t.upsertTool(d, { state: "output-error", errorText: y, raw: p }), { ...l, error: y };
310
+ const m = "Tool call arrived with no function name; cannot dispatch it.";
311
+ return t.upsertTool(d, { state: "output-error", errorText: m, raw: f }), { ...g, error: m };
261
312
  }
262
- const k = u.argumentsText.trim();
313
+ const l = u.argumentsText.trim();
263
314
  try {
264
- const y = k === "" ? {} : JSON.parse(k);
265
- if (y === null || typeof y != "object" || Array.isArray(y))
315
+ const m = l === "" ? {} : JSON.parse(l);
316
+ if (m === null || typeof m != "object" || Array.isArray(m))
266
317
  throw new Error("arguments must be a JSON object");
267
- const T = y;
318
+ const v = m;
268
319
  t.upsertTool(d, {
269
- type: h,
320
+ type: p,
270
321
  state: "input-available",
271
- input: T,
322
+ input: v,
272
323
  rawInput: u.argumentsText,
273
- raw: p
324
+ raw: f
274
325
  });
275
- const v = { ...l, input: T };
276
- return (m = e.onToolCallReady) == null || m.call(e, v), v;
277
- } catch (y) {
278
- const v = `Malformed tool arguments${a === "length" ? " (the stream hit the token limit mid-call)" : ""}: ${y.message}. Received ${k.length} chars: ${gt(k, 160)}`;
326
+ const k = { ...g, input: v };
327
+ return (h = e.onToolCallReady) == null || h.call(e, k), k;
328
+ } catch (m) {
329
+ const k = `Malformed tool arguments${a === "length" ? " (the stream hit the token limit mid-call)" : ""}: ${m.message}. Received ${l.length} chars: ${Nt(l, 160)}`;
279
330
  return t.upsertTool(d, {
280
- type: h,
331
+ type: p,
281
332
  state: "output-error",
282
- errorText: v,
333
+ errorText: k,
283
334
  rawInput: u.argumentsText,
284
- raw: p
285
- }), { ...l, error: v };
335
+ raw: f
336
+ }), { ...g, error: k };
286
337
  }
287
338
  }) };
288
339
  }
289
- function mt() {
290
- let t = [];
340
+ function Mt(t) {
341
+ let e = [];
342
+ const n = {}, o = (s, r, i, a) => {
343
+ if (e.length > r.length && (n[s] = (n[s] ?? 0) + (e.length - r.length)), !A()) return;
344
+ let c = e.length - 1;
345
+ for (let u = 0; u < e.length; u++)
346
+ if (r[u] !== e[u]) {
347
+ c = u;
348
+ break;
349
+ }
350
+ O({
351
+ type: "wire.part",
352
+ t: Date.now(),
353
+ ...t,
354
+ variant: s,
355
+ index: c,
356
+ ...i !== void 0 ? { chars: i } : {},
357
+ ...a ? R(a) : {}
358
+ });
359
+ };
291
360
  return {
292
- appendText(e) {
293
- t = tt(t, e);
361
+ appendText(s) {
362
+ const r = e;
363
+ e = Tt(e, s), o("text", r, s.length, () => ({ delta: s }));
294
364
  },
295
- appendReasoning(e, n) {
296
- t = et(t, e, { ...n, streamId: void 0 });
365
+ appendReasoning(s, r) {
366
+ const i = e;
367
+ e = _t(e, s, { ...r, streamId: void 0 }), o("reasoning", i, s.length, () => ({ delta: s }));
297
368
  },
298
- upsertTool(e, n) {
299
- t = it(t, e, n);
369
+ upsertTool(s, r) {
370
+ const i = e;
371
+ e = St(e, s, r), o("tool", i, void 0, () => ({ patch: r }));
300
372
  },
301
- addSource(e) {
302
- t = [...t, { type: "source", source: e }];
373
+ addSource(s) {
374
+ const r = e;
375
+ e = [...e, { type: "source", source: s }], o("source", r, void 0, () => ({ source: s }));
303
376
  },
304
- parts: () => t
377
+ parts: () => e,
378
+ partCounts: () => n
305
379
  };
306
380
  }
307
- function xt(t, e) {
381
+ function Ft(t, e) {
308
382
  return {
309
383
  appendText(n) {
310
384
  t.appendText(n), e.appendText(n);
@@ -316,61 +390,98 @@ function xt(t, e) {
316
390
  t.upsertTool(n, o), e.upsertTool(n, o);
317
391
  },
318
392
  addSource(n) {
319
- var o, r;
320
- (o = t.addSource) == null || o.call(t, n), (r = e.addSource) == null || r.call(e, n);
393
+ var o, s;
394
+ (o = t.addSource) == null || o.call(t, n), (s = e.addSource) == null || s.call(e, n);
321
395
  }
322
396
  };
323
397
  }
324
- let bt = 0;
325
- const kt = () => `wire-${++bt}`;
326
- async function wt(t, e, n = {}) {
327
- var v;
328
- const o = n.reasoningLabel ?? "Thinking", r = kt(), s = mt(), i = xt(e, s), a = yt(i, n);
329
- let c = "", u = "", d = 0, l = 0, p = null, h, k;
330
- const m = [];
331
- for await (const f of t) {
332
- if (l++, f.usage && (k = { ...k, ...f.usage }), f.error) {
333
- h = f.error, f.finishReason && (p = f.finishReason);
398
+ async function qt(t, e, n = {}) {
399
+ var H, Y;
400
+ const o = n.reasoningLabel ?? "Thinking", s = n.streamId ?? at(), r = rt(s, n), i = Date.now(), a = Mt(r), c = Ft(e, a), u = Lt(c, n);
401
+ let d = "", g = "", f = 0, p = 0, l = null, h, m;
402
+ const v = [];
403
+ for await (const y of t) {
404
+ if (p++, y.usage && (m = { ...m, ...y.usage }), y.error) {
405
+ h = y.error, y.finishReason && (l = y.finishReason);
334
406
  break;
335
407
  }
336
- if (f.text && (c += f.text, i.appendText(f.text)), f.reasoning !== void 0 || f.reasoningRaw !== void 0 || f.reasoningSignature !== void 0) {
337
- const _ = f.reasoning ?? "";
338
- u += _, _ !== "" && d++, i.appendReasoning(_, {
339
- index: f.reasoningIndex ?? 0,
408
+ if (y.text && (d += y.text, c.appendText(y.text)), y.reasoning !== void 0 || y.reasoningRaw !== void 0 || y.reasoningSignature !== void 0) {
409
+ const T = y.reasoning ?? "";
410
+ g += T, T !== "" && f++, c.appendReasoning(T, {
411
+ index: y.reasoningIndex ?? 0,
340
412
  // Namespaces the index to THIS stream, so a later round reading into the
341
413
  // same sink opens its own part instead of overwriting this one's `raw`.
342
- streamId: r,
414
+ streamId: s,
343
415
  label: o,
344
- ...f.reasoningRaw ? { raw: f.reasoningRaw } : {},
345
- ...f.reasoningSignature ? { signature: f.reasoningSignature } : {}
416
+ ...y.reasoningRaw ? { raw: y.reasoningRaw } : {},
417
+ ...y.reasoningSignature ? { signature: y.reasoningSignature } : {}
346
418
  });
347
419
  }
348
- if (f.toolCalls) for (const _ of f.toolCalls) a.apply(_);
349
- if (f.sources)
350
- for (const _ of f.sources)
351
- m.push(_), (v = i.addSource) == null || v.call(i, _);
352
- f.finishReason && (p = f.finishReason);
420
+ if (y.toolCalls) for (const T of y.toolCalls) u.apply(T);
421
+ if (y.sources)
422
+ for (const T of y.sources)
423
+ v.push(T), (H = c.addSource) == null || H.call(c, T);
424
+ y.finishReason && (l = y.finishReason);
353
425
  }
354
- l === 0 && !h && (h = {
426
+ const k = z(l) ?? (h ? "error" : void 0), $ = u.settle(k, h == null ? void 0 : h.message), P = Object.values(a.partCounts()).reduce((y, T) => y + T, 0);
427
+ !h && P === 0 && (h = p === 0 ? {
355
428
  code: "empty-stream",
356
429
  message: "The model stream produced no chunks. The response was 200 but nothing in its body parsed as a stream frame — check the endpoint really sent Content-Type: text/event-stream and that the request set stream: true. A route that forwards a provider error without its status lands here: the body is a JSON error, not SSE."
430
+ } : {
431
+ code: "empty-turn",
432
+ message: `The stream completed and ${p} chunk(s) were parsed, but none carried content this reader reads, so no message part was produced. If the endpoint streams a different dialect (or carries its payload in a field this format does not read), switch to the matching reader. A model that returned no content at all also lands here.`
357
433
  });
358
- const y = lt(p) ?? (h ? "error" : void 0), T = a.settle(y, h == null ? void 0 : h.message);
434
+ const N = z(l) ?? (h ? "error" : void 0);
435
+ if (A()) {
436
+ const y = (Y = n._frames) == null ? void 0 : Y.call(n);
437
+ O({
438
+ type: "wire.close",
439
+ t: Date.now(),
440
+ ...r,
441
+ ...y !== void 0 ? { frames: y } : {},
442
+ chunks: p,
443
+ parts: a.partCounts(),
444
+ finishReason: l,
445
+ ...N ? { stopReason: N } : {},
446
+ // The CODE only. A provider's error message can echo request content back,
447
+ // which is why it stays on `ModelTurn.error` and never on the event.
448
+ ...(h == null ? void 0 : h.code) !== void 0 ? { errorCode: h.code } : {},
449
+ ...m ? { usage: m } : {},
450
+ ms: Date.now() - i,
451
+ // The assembled turn: everything the sink was driven with, in one place,
452
+ // which is what a panel renders when someone asks "what did it actually
453
+ // say" -- plus the in-band error's own message.
454
+ //
455
+ // ALL THREE TERMINAL EVENTS TREAT PROVIDER MESSAGE TEXT IDENTICALLY:
456
+ // `wire.close`, `wire.failed` and `wire.interrupted` each keep it out of
457
+ // the metadata (where only `errorCode` travels, because a message can
458
+ // echo request content back) and each publish it under `payload`, which
459
+ // is the switch that accepts exactly that. A developer who armed payload
460
+ // is most often chasing the in-band error that explains an empty turn.
461
+ ...R(() => ({
462
+ text: d,
463
+ reasoning: g,
464
+ toolCalls: $,
465
+ sources: v,
466
+ ...(h == null ? void 0 : h.message) !== void 0 ? { message: h.message } : {}
467
+ }))
468
+ });
469
+ }
359
470
  return {
360
- parts: s.parts(),
361
- text: c,
362
- reasoning: u,
363
- toolCalls: T,
364
- sources: m,
365
- finishReason: p,
366
- reasoningChunks: d,
367
- chunks: l,
368
- ...y ? { stopReason: y } : {},
471
+ parts: a.parts(),
472
+ text: d,
473
+ reasoning: g,
474
+ toolCalls: $,
475
+ sources: v,
476
+ finishReason: l,
477
+ reasoningChunks: f,
478
+ chunks: p,
479
+ ...N ? { stopReason: N } : {},
369
480
  ...h ? { error: h } : {},
370
- ...k ? { usage: k } : {}
481
+ ...m ? { usage: m } : {}
371
482
  };
372
483
  }
373
- function x(t) {
484
+ function w(t) {
374
485
  return typeof t == "object" && t !== null && !Array.isArray(t);
375
486
  }
376
487
  function b(t) {
@@ -379,178 +490,180 @@ function b(t) {
379
490
  function I(t) {
380
491
  return typeof t == "number" ? t : void 0;
381
492
  }
382
- function Tt(t) {
383
- if (!x(t)) return;
493
+ function Wt(t) {
494
+ if (!w(t)) return;
384
495
  const e = {}, n = I(t.prompt_tokens);
385
496
  n !== void 0 && (e.inputTokens = n);
386
497
  const o = I(t.completion_tokens);
387
498
  o !== void 0 && (e.outputTokens = o);
388
- const r = I(t.total_tokens);
389
- r !== void 0 && (e.totalTokens = r);
390
- const s = t.completion_tokens_details;
391
- if (x(s)) {
392
- const c = I(s.reasoning_tokens);
499
+ const s = I(t.total_tokens);
500
+ s !== void 0 && (e.totalTokens = s);
501
+ const r = t.completion_tokens_details;
502
+ if (w(r)) {
503
+ const c = I(r.reasoning_tokens);
393
504
  c !== void 0 && (e.reasoningTokens = c);
394
505
  }
395
506
  const i = t.prompt_tokens_details;
396
- if (x(i)) {
507
+ if (w(i)) {
397
508
  const c = I(i.cached_tokens);
398
509
  c !== void 0 && (e.cachedInputTokens = c);
399
510
  }
400
511
  const a = I(t.cost);
401
512
  return a !== void 0 && (e.costUsd = a), Object.keys(e).length > 0 ? e : void 0;
402
513
  }
403
- function vt(t, e) {
404
- if (!x(t)) return;
405
- const n = x(t.function) ? t.function : void 0, o = { index: I(t.index) ?? e }, r = b(t.id);
406
- r && (o.id = r);
407
- const s = b(n == null ? void 0 : n.name);
408
- s && (o.name = s);
514
+ function Bt(t, e) {
515
+ if (!w(t)) return;
516
+ const n = w(t.function) ? t.function : void 0, o = { index: I(t.index) ?? e }, s = b(t.id);
517
+ s && (o.id = s);
518
+ const r = b(n == null ? void 0 : n.name);
519
+ r && (o.name = r);
409
520
  const i = b(n == null ? void 0 : n.arguments);
410
521
  return i !== void 0 && (o.arguments = i), o;
411
522
  }
412
- function _t(t) {
523
+ function Jt(t) {
413
524
  let e = "";
414
525
  for (const n of t) {
415
- if (!x(n)) continue;
526
+ if (!w(n)) continue;
416
527
  const o = b(n.text) ?? b(n.summary);
417
528
  o && (e += o);
418
529
  }
419
530
  return e;
420
531
  }
421
- function N(t, e) {
532
+ function Q(t, e) {
422
533
  for (const n of t)
423
- if (x(n) && n[e] !== void 0) return n[e];
534
+ if (w(n) && n[e] !== void 0) return n[e];
424
535
  }
425
- const It = ["reasoning", "reasoning_content"];
426
- function At(t) {
427
- for (const e of It) {
536
+ const Kt = ["reasoning", "reasoning_content"];
537
+ function Gt(t) {
538
+ for (const e of Kt) {
428
539
  const n = b(t[e]);
429
540
  if (n !== void 0 && n !== "") return n;
430
541
  }
431
542
  }
432
- function Rt(t, e) {
433
- const n = Array.isArray(t.reasoning_details) ? t.reasoning_details : void 0, o = At(t), r = n ? _t(n) : void 0, s = n !== void 0 && n.length > 0, i = o ?? r;
434
- if (i === void 0 && !s || (e.reasoning = i ?? "", !s)) return;
543
+ function Ht(t, e) {
544
+ const n = Array.isArray(t.reasoning_details) ? t.reasoning_details : void 0, o = Gt(t), s = n ? Jt(n) : void 0, r = n !== void 0 && n.length > 0, i = o ?? s;
545
+ if (i === void 0 && !r || (e.reasoning = i ?? "", !r)) return;
435
546
  e.reasoningRaw = { source: "openai.reasoning_details", payload: n };
436
- const a = I(N(n, "index"));
547
+ const a = I(Q(n, "index"));
437
548
  a !== void 0 && (e.reasoningIndex = a);
438
- const c = b(N(n, "signature"));
549
+ const c = b(Q(n, "signature"));
439
550
  c !== void 0 && (e.reasoningSignature = c);
440
551
  }
441
- function Ot(t) {
552
+ function Yt(t) {
442
553
  if (!Array.isArray(t.annotations)) return [];
443
554
  const e = [];
444
555
  for (const n of t.annotations) {
445
- if (!x(n)) continue;
446
- const o = x(n.url_citation) ? n.url_citation : void 0, r = b(o == null ? void 0 : o.url);
447
- if (!r) continue;
448
- const s = { url: r }, i = b(o == null ? void 0 : o.title);
449
- i && (s.title = i);
556
+ if (!w(n)) continue;
557
+ const o = w(n.url_citation) ? n.url_citation : void 0, s = b(o == null ? void 0 : o.url);
558
+ if (!s) continue;
559
+ const r = { url: s }, i = b(o == null ? void 0 : o.title);
560
+ i && (r.title = i);
450
561
  const a = b(o == null ? void 0 : o.content);
451
- a && (s.snippet = a), e.push(s);
562
+ a && (r.snippet = a), e.push(r);
452
563
  }
453
564
  return e;
454
565
  }
455
- function St(t) {
456
- if (!x(t)) return [];
566
+ function zt(t) {
567
+ if (!w(t)) return [];
457
568
  const e = {}, n = t.error;
458
- if (x(n)) {
459
- const i = b(n.message);
460
- if (i) {
461
- e.error = { message: i };
462
- const a = n.code;
463
- (typeof a == "string" || typeof a == "number") && (e.error.code = a);
569
+ if (w(n)) {
570
+ const a = b(n.message);
571
+ if (a) {
572
+ e.error = { message: a };
573
+ const c = n.code;
574
+ (typeof c == "string" || typeof c == "number") && (e.error.code = c);
464
575
  }
465
576
  }
466
- const o = Tt(t.usage);
467
- o && (e.usage = o);
468
- const r = Array.isArray(t.choices) ? t.choices : [], s = x(r[0]) ? r[0] : void 0;
469
- if (s) {
470
- const i = x(s.delta) ? s.delta : void 0;
471
- if (i) {
472
- const c = b(i.content);
473
- if (c && (e.text = c), Rt(i, e), Array.isArray(i.tool_calls) && i.tool_calls.length > 0) {
474
- const d = i.tool_calls.map((l, p) => vt(l, p)).filter((l) => l !== void 0);
475
- d.length > 0 && (e.toolCalls = d);
577
+ const o = b(t.model);
578
+ o && (e.model = o);
579
+ const s = Wt(t.usage);
580
+ s && (e.usage = s);
581
+ const r = Array.isArray(t.choices) ? t.choices : [], i = w(r[0]) ? r[0] : void 0;
582
+ if (i) {
583
+ const a = w(i.delta) ? i.delta : void 0;
584
+ if (a) {
585
+ const u = b(a.content);
586
+ if (u && (e.text = u), Ht(a, e), Array.isArray(a.tool_calls) && a.tool_calls.length > 0) {
587
+ const g = a.tool_calls.map((f, p) => Bt(f, p)).filter((f) => f !== void 0);
588
+ g.length > 0 && (e.toolCalls = g);
476
589
  }
477
- const u = Ot(i);
478
- u.length > 0 && (e.sources = u);
590
+ const d = Yt(a);
591
+ d.length > 0 && (e.sources = d);
479
592
  }
480
- const a = b(s.finish_reason);
481
- a && (e.finishReason = a);
593
+ const c = b(i.finish_reason);
594
+ c && (e.finishReason = c);
482
595
  }
483
596
  return Object.keys(e).length > 0 ? [e] : [];
484
597
  }
485
- const Et = {
598
+ const Qt = {
486
599
  id: "openai.chat-completions",
487
600
  open() {
488
- return { push: St };
601
+ return { push: zt };
489
602
  }
490
603
  };
491
- function w(t) {
604
+ function _(t) {
492
605
  return typeof t == "object" && t !== null && !Array.isArray(t);
493
606
  }
494
- function g(t) {
607
+ function x(t) {
495
608
  return typeof t == "string" ? t : void 0;
496
609
  }
497
- function R(t) {
610
+ function E(t) {
498
611
  return typeof t == "number" ? t : void 0;
499
612
  }
500
- function W(t) {
501
- if (!w(t)) return;
502
- const e = {}, n = R(t.input_tokens);
613
+ function ct(t) {
614
+ if (!_(t)) return;
615
+ const e = {}, n = E(t.input_tokens);
503
616
  n !== void 0 && (e.inputTokens = n);
504
- const o = R(t.output_tokens);
617
+ const o = E(t.output_tokens);
505
618
  o !== void 0 && (e.outputTokens = o);
506
- const r = R(t.cache_read_input_tokens);
507
- return r !== void 0 && (e.cachedInputTokens = r), Object.keys(e).length > 0 ? e : void 0;
619
+ const s = E(t.cache_read_input_tokens);
620
+ return s !== void 0 && (e.cachedInputTokens = s), Object.keys(e).length > 0 ? e : void 0;
508
621
  }
509
- function $t(t, e, n) {
510
- const o = R(t.index) ?? 0, r = t.content_block;
511
- if (!w(r)) return [];
512
- switch (g(r.type)) {
622
+ function Xt(t, e, n) {
623
+ const o = E(t.index) ?? 0, s = t.content_block;
624
+ if (!_(s)) return [];
625
+ switch (x(s.type)) {
513
626
  case "text": {
514
627
  e.set(o, { kind: "text", thinking: "" });
515
- const s = g(r.text);
516
- return s ? [{ text: s }] : [];
628
+ const r = x(s.text);
629
+ return r ? [{ text: r }] : [];
517
630
  }
518
631
  case "thinking": {
519
- const s = g(r.thinking) ?? "";
520
- return e.set(o, { kind: "thinking", thinking: s }), [{ reasoning: s, reasoningIndex: o }];
632
+ const r = x(s.thinking) ?? "";
633
+ return e.set(o, { kind: "thinking", thinking: r }), [{ reasoning: r, reasoningIndex: o }];
521
634
  }
522
635
  case "redacted_thinking":
523
636
  return e.set(o, { kind: "redacted_thinking", thinking: "" }), [
524
637
  {
525
638
  reasoning: "",
526
639
  reasoningIndex: o,
527
- reasoningRaw: { source: "anthropic.content_block", payload: r }
640
+ reasoningRaw: { source: "anthropic.content_block", payload: s }
528
641
  }
529
642
  ];
530
643
  case "tool_use":
531
644
  case "server_tool_use": {
532
- const s = g(r.id), i = g(r.name);
533
- return e.set(o, { kind: "tool_use", thinking: "" }), s && n.set(s, o), [{ toolCalls: [{ index: o, ...s ? { id: s } : {}, ...i ? { name: i } : {} }] }];
645
+ const r = x(s.id), i = x(s.name);
646
+ return e.set(o, { kind: "tool_use", thinking: "" }), r && n.set(r, o), [{ toolCalls: [{ index: o, ...r ? { id: r } : {}, ...i ? { name: i } : {} }] }];
534
647
  }
535
648
  case "web_search_tool_result": {
536
649
  e.set(o, { kind: "other", thinking: "" });
537
- const s = g(r.tool_use_id), i = s !== void 0 ? n.get(s) : void 0;
650
+ const r = x(s.tool_use_id), i = r !== void 0 ? n.get(r) : void 0;
538
651
  if (i === void 0) return [];
539
- const a = r.content;
540
- return w(a) && (g(a.type) ?? "").endsWith("_error") ? [
652
+ const a = s.content;
653
+ return _(a) && (x(a.type) ?? "").endsWith("_error") ? [
541
654
  {
542
655
  toolCalls: [
543
656
  {
544
657
  index: i,
545
- ...s ? { id: s } : {},
546
- outputError: g(a.error_code) ?? "web_search_tool_result_error"
658
+ ...r ? { id: r } : {},
659
+ outputError: x(a.error_code) ?? "web_search_tool_result_error"
547
660
  }
548
661
  ]
549
662
  }
550
663
  ] : [
551
664
  {
552
665
  toolCalls: [
553
- { index: i, ...s ? { id: s } : {}, output: { content: a } }
666
+ { index: i, ...r ? { id: r } : {}, output: { content: a } }
554
667
  ]
555
668
  }
556
669
  ];
@@ -559,61 +672,61 @@ function $t(t, e, n) {
559
672
  return e.set(o, { kind: "other", thinking: "" }), [];
560
673
  }
561
674
  }
562
- function Ct(t, e) {
563
- const n = R(t.index) ?? 0, o = t.delta;
564
- if (!w(o)) return [];
565
- switch (g(o.type)) {
675
+ function Vt(t, e) {
676
+ const n = E(t.index) ?? 0, o = t.delta;
677
+ if (!_(o)) return [];
678
+ switch (x(o.type)) {
566
679
  case "text_delta": {
567
- const r = g(o.text);
568
- return r ? [{ text: r }] : [];
680
+ const s = x(o.text);
681
+ return s ? [{ text: s }] : [];
569
682
  }
570
683
  case "thinking_delta": {
571
- const r = g(o.thinking) ?? "", s = e.get(n);
572
- return s && (s.thinking += r), [{ reasoning: r, reasoningIndex: n }];
684
+ const s = x(o.thinking) ?? "", r = e.get(n);
685
+ return r && (r.thinking += s), [{ reasoning: s, reasoningIndex: n }];
573
686
  }
574
687
  case "signature_delta": {
575
- const r = g(o.signature) ?? "", s = e.get(n);
576
- return s && (s.signature = (s.signature ?? "") + r), [{ reasoning: "", reasoningIndex: n, reasoningSignature: r }];
688
+ const s = x(o.signature) ?? "", r = e.get(n);
689
+ return r && (r.signature = (r.signature ?? "") + s), [{ reasoning: "", reasoningIndex: n, reasoningSignature: s }];
577
690
  }
578
691
  case "input_json_delta":
579
- return [{ toolCalls: [{ index: n, arguments: g(o.partial_json) ?? "" }] }];
692
+ return [{ toolCalls: [{ index: n, arguments: x(o.partial_json) ?? "" }] }];
580
693
  case "citations_delta": {
581
- const r = o.citation;
582
- if (!w(r)) return [];
583
- const s = {}, i = g(r.url);
584
- i && (s.url = i);
585
- const a = g(r.title);
586
- a && (s.title = a);
587
- const c = g(r.cited_text);
588
- return c && (s.snippet = c), Object.keys(s).length > 0 ? [{ sources: [s] }] : [];
694
+ const s = o.citation;
695
+ if (!_(s)) return [];
696
+ const r = {}, i = x(s.url);
697
+ i && (r.url = i);
698
+ const a = x(s.title);
699
+ a && (r.title = a);
700
+ const c = x(s.cited_text);
701
+ return c && (r.snippet = c), Object.keys(r).length > 0 ? [{ sources: [r] }] : [];
589
702
  }
590
703
  default:
591
704
  return [];
592
705
  }
593
706
  }
594
- function Ut(t, e) {
595
- const n = R(t.index) ?? 0, o = e.get(n);
707
+ function Zt(t, e) {
708
+ const n = E(t.index) ?? 0, o = e.get(n);
596
709
  if (!o || o.kind !== "thinking") return [];
597
- const r = { type: "thinking", thinking: o.thinking };
598
- return o.signature !== void 0 && (r.signature = o.signature), [
710
+ const s = { type: "thinking", thinking: o.thinking };
711
+ return o.signature !== void 0 && (s.signature = o.signature), [
599
712
  {
600
713
  reasoning: "",
601
714
  reasoningIndex: n,
602
- reasoningRaw: { source: "anthropic.content_block", payload: r }
715
+ reasoningRaw: { source: "anthropic.content_block", payload: s }
603
716
  }
604
717
  ];
605
718
  }
606
- function Ft(t) {
719
+ function te(t) {
607
720
  const e = {}, n = t.delta;
608
- if (w(n)) {
609
- const r = g(n.stop_reason);
610
- r && (e.finishReason = r);
721
+ if (_(n)) {
722
+ const s = x(n.stop_reason);
723
+ s && (e.finishReason = s);
611
724
  }
612
- const o = W(t.usage);
725
+ const o = ct(t.usage);
613
726
  return o && (e.usage = o), Object.keys(e).length > 0 ? [e] : [];
614
727
  }
615
- function Lt(t) {
616
- const e = t.error, n = w(e) ? g(e.message) : void 0, o = w(e) ? g(e.type) : void 0;
728
+ function ee(t) {
729
+ const e = t.error, n = _(e) ? x(e.message) : void 0, o = _(e) ? x(e.type) : void 0;
617
730
  return [
618
731
  {
619
732
  error: {
@@ -623,30 +736,32 @@ function Lt(t) {
623
736
  }
624
737
  ];
625
738
  }
626
- const Nt = {
739
+ const ne = {
627
740
  id: "anthropic.messages",
628
741
  open() {
629
742
  const t = /* @__PURE__ */ new Map(), e = /* @__PURE__ */ new Map();
630
743
  return {
631
744
  push(n) {
632
- if (!w(n)) return [];
633
- switch (g(n.type)) {
745
+ if (!_(n)) return [];
746
+ switch (x(n.type)) {
634
747
  case "message_start": {
635
748
  const o = n.message;
636
- if (!w(o)) return [];
637
- const r = W(o.usage);
638
- return r ? [{ usage: r }] : [];
749
+ if (!_(o)) return [];
750
+ const s = {}, r = ct(o.usage);
751
+ r && (s.usage = r);
752
+ const i = x(o.model);
753
+ return i && (s.model = i), Object.keys(s).length > 0 ? [s] : [];
639
754
  }
640
755
  case "content_block_start":
641
- return $t(n, t, e);
756
+ return Xt(n, t, e);
642
757
  case "content_block_delta":
643
- return Ct(n, t);
758
+ return Vt(n, t);
644
759
  case "content_block_stop":
645
- return Ut(n, t);
760
+ return Zt(n, t);
646
761
  case "message_delta":
647
- return Ft(n);
762
+ return te(n);
648
763
  case "error":
649
- return Lt(n);
764
+ return ee(n);
650
765
  default:
651
766
  return [];
652
767
  }
@@ -654,20 +769,42 @@ const Nt = {
654
769
  };
655
770
  }
656
771
  };
657
- class U extends Error {
658
- constructor(n, o, r, s) {
659
- super(Mt(n, o, r, s));
660
- A(this, "status");
661
- A(this, "statusText");
772
+ let X;
773
+ function ut(t) {
774
+ return X ?? (X = new TextEncoder()), X.encode(t).length;
775
+ }
776
+ function oe(t) {
777
+ return J(t) ? "response" : typeof t.getReader == "function" ? "stream" : "iterable";
778
+ }
779
+ function se(t) {
780
+ var s, r;
781
+ const e = {};
782
+ typeof t.status == "number" && (e.status = t.status);
783
+ const n = (r = (s = t.headers) == null ? void 0 : s.get) == null ? void 0 : r.call(s, "content-type");
784
+ typeof n == "string" && n !== "" && (e.contentType = n);
785
+ const o = typeof t.url == "string" ? t.url : "";
786
+ if (o !== "")
787
+ try {
788
+ const i = new URL(o);
789
+ e.url = `${i.origin}${i.pathname}`, e.hasQuery = i.search !== "";
790
+ } catch {
791
+ }
792
+ return e;
793
+ }
794
+ class B extends Error {
795
+ constructor(n, o, s, r) {
796
+ super(re(n, o, s, r));
797
+ S(this, "status");
798
+ S(this, "statusText");
662
799
  /** The response body parsed as JSON, or undefined when it was not JSON (an
663
800
  * HTML error page from a proxy, most often). */
664
- A(this, "body");
801
+ S(this, "body");
665
802
  /** The raw response body, always. */
666
- A(this, "bodyText");
667
- Object.setPrototypeOf(this, U.prototype), this.name = "WireError", this.status = n, this.statusText = o, this.bodyText = r, this.body = s;
803
+ S(this, "bodyText");
804
+ Object.setPrototypeOf(this, B.prototype), this.name = "WireError", this.status = n, this.statusText = o, this.bodyText = s, this.body = r;
668
805
  }
669
806
  }
670
- function jt(t) {
807
+ function M(t) {
671
808
  if (typeof t != "object" || t === null) return;
672
809
  const e = t.error;
673
810
  if (typeof e == "string") return e;
@@ -678,16 +815,30 @@ function jt(t) {
678
815
  const n = t.message;
679
816
  return typeof n == "string" ? n : void 0;
680
817
  }
681
- function Mt(t, e, n, o) {
682
- const r = `Model request failed: HTTP ${t}${e ? ` ${e}` : ""}`, s = jt(o);
683
- if (s) return `${r}: ${s}`;
818
+ function V(t) {
819
+ if (typeof t != "object" || t === null) return;
820
+ const e = t.error;
821
+ if (typeof e == "object" && e !== null) {
822
+ const o = e.code;
823
+ if (typeof o == "string" || typeof o == "number") return o;
824
+ }
825
+ const n = t.code;
826
+ return typeof n == "string" || typeof n == "number" ? n : void 0;
827
+ }
828
+ function re(t, e, n, o) {
829
+ const s = `Model request failed: HTTP ${t}${e ? ` ${e}` : ""}`, r = M(o);
830
+ if (r) return `${s}: ${r}`;
684
831
  const i = n.trim().slice(0, 200);
685
- return i ? `${r}: ${i}` : r;
832
+ return i ? `${s}: ${i}` : s;
686
833
  }
687
- function Pt(t) {
834
+ function ie(t) {
835
+ const e = t == null ? void 0 : t.name;
836
+ return typeof e == "string" && e !== "" ? e : void 0;
837
+ }
838
+ function J(t) {
688
839
  return typeof t == "object" && t !== null && "ok" in t && "status" in t && "body" in t;
689
840
  }
690
- async function Dt(t) {
841
+ async function ae(t) {
691
842
  const e = await t.text().catch(() => "");
692
843
  let n;
693
844
  try {
@@ -695,38 +846,122 @@ async function Dt(t) {
695
846
  } catch {
696
847
  n = void 0;
697
848
  }
698
- return new U(t.status, t.statusText, e, n);
849
+ return new B(t.status, t.statusText, e, n);
699
850
  }
700
- async function Wt(t) {
701
- if (!Pt(t)) return t;
702
- if (!t.ok) throw await Dt(t);
851
+ async function ce(t, e) {
852
+ if (!J(t)) return t;
853
+ if (!t.ok) {
854
+ const n = await ae(t);
855
+ throw A() && O({
856
+ type: "wire.failed",
857
+ t: Date.now(),
858
+ ...e,
859
+ status: n.status,
860
+ statusText: n.statusText,
861
+ bodyBytes: ut(n.bodyText),
862
+ // `wireErrorFrom` leaves `body` undefined when the text was empty or did
863
+ // not parse, so this is exactly "the body was JSON".
864
+ bodyIsJson: n.body !== void 0,
865
+ // The code travels; `bodyText` and the provider's message do NOT.
866
+ ...V(n.body) !== void 0 ? { providerCode: V(n.body) } : {},
867
+ // The message is the field that echoes request content back, which is
868
+ // precisely why it is here and not beside `providerCode`.
869
+ ...R(() => ({
870
+ bodyText: n.bodyText,
871
+ ...M(n.body) !== void 0 ? { message: M(n.body) } : {}
872
+ }))
873
+ }), n;
874
+ }
703
875
  if (!t.body)
704
876
  throw new Error(
705
877
  "The model response has no body to stream. Check that the request set stream: true and that nothing between you and the provider buffered it."
706
878
  );
707
879
  return t.body;
708
880
  }
709
- async function q(t, e, n) {
710
- const o = await Wt(t), r = n.format.open();
711
- async function* s() {
712
- for await (const i of Z(o))
713
- for (const a of r.push(i)) yield a;
881
+ async function dt(t, e, n) {
882
+ const o = n.streamId ?? at(), s = rt(o, n), r = await ce(t, s);
883
+ A() && O({
884
+ type: "wire.open",
885
+ t: Date.now(),
886
+ ...s,
887
+ format: n.format.id,
888
+ source: oe(t),
889
+ ...J(t) ? se(t) : {}
890
+ });
891
+ const i = n.format.open();
892
+ let a = 0, c = 0, u = "";
893
+ const d = (f) => {
894
+ u = f;
895
+ };
896
+ async function* g() {
897
+ for await (const f of vt(r, d)) {
898
+ a++;
899
+ const p = i.push(f);
900
+ if (A()) {
901
+ const l = /* @__PURE__ */ new Set();
902
+ let h;
903
+ for (const m of p) {
904
+ for (const v of Object.keys(m)) l.add(v);
905
+ m.model && (h = m.model);
906
+ }
907
+ O({
908
+ type: "wire.frame",
909
+ t: Date.now(),
910
+ ...s,
911
+ seq: a,
912
+ bytes: ut(u),
913
+ chunks: p.length,
914
+ fields: [...l],
915
+ ...h ? { model: h } : {},
916
+ ...R(() => ({ raw: u }))
917
+ });
918
+ }
919
+ for (const l of p)
920
+ c++, yield l;
921
+ }
922
+ }
923
+ try {
924
+ return await qt(g(), e, {
925
+ ...n,
926
+ streamId: o,
927
+ _frames: () => a
928
+ });
929
+ } catch (f) {
930
+ if (A()) {
931
+ const p = ie(f);
932
+ O({
933
+ type: "wire.interrupted",
934
+ t: Date.now(),
935
+ ...s,
936
+ frames: a,
937
+ chunks: c,
938
+ // Only a self-identifying abort is called one. Guessing would turn "the
939
+ // provider dropped the connection" into "your user navigated away", and
940
+ // those two have opposite fixes.
941
+ reason: p === "AbortError" ? "abort" : "error",
942
+ ...p !== void 0 ? { errorName: p } : {},
943
+ ...R(() => {
944
+ const l = f == null ? void 0 : f.message;
945
+ return typeof l == "string" ? { message: l } : {};
946
+ })
947
+ });
948
+ }
949
+ throw f;
714
950
  }
715
- return wt(s(), e, n);
716
951
  }
717
- function ue(t, e, n = {}) {
718
- return q(t, e, { ...n, format: Et });
952
+ function Ce(t, e, n = {}) {
953
+ return dt(t, e, { ...n, format: Qt });
719
954
  }
720
- function ce(t, e, n = {}) {
721
- return q(t, e, { ...n, format: Nt });
955
+ function Ue(t, e, n = {}) {
956
+ return dt(t, e, { ...n, format: ne });
722
957
  }
723
- function de(t, e, n) {
958
+ function De(t, e, n) {
724
959
  t.upsertTool(e, { state: "output-available", output: n });
725
960
  }
726
- function le(t, e, n) {
961
+ function Pe(t, e, n) {
727
962
  t.upsertTool(e, { state: "output-error", errorText: n });
728
963
  }
729
- function pe(t) {
964
+ function Ne(t) {
730
965
  let e = "";
731
966
  return {
732
967
  appendText(n) {
@@ -741,7 +976,7 @@ function pe(t) {
741
976
  buffered: () => e
742
977
  };
743
978
  }
744
- const C = [
979
+ const F = [
745
980
  { pattern: "image/jpeg", kind: "image" },
746
981
  { pattern: "image/png", kind: "image" },
747
982
  { pattern: "image/gif", kind: "image" },
@@ -752,56 +987,56 @@ const C = [
752
987
  { pattern: "application/xml", kind: "text" },
753
988
  { pattern: "application/x-yaml", kind: "text" },
754
989
  { pattern: "application/yaml", kind: "text" }
755
- ], J = "text/plain", qt = ["", "application/octet-stream"], F = (t) => t.trim().toLowerCase(), B = (t) => qt.includes(t === void 0 ? "" : F(t)), Jt = (t) => {
990
+ ], lt = "text/plain", ue = ["", "application/octet-stream"], K = (t) => t.trim().toLowerCase(), ft = (t) => ue.includes(t === void 0 ? "" : K(t)), de = (t) => {
756
991
  if (!t.startsWith(".")) return t;
757
992
  throw new Error(
758
993
  `\`accept\` entry "${t}" is a file extension, and this kit takes media types only. HTML's own accept attribute does take extensions, which is exactly why this throws rather than quietly matching nothing. Use a media type instead -- "text/*" covers source files, "image/*" images, "application/pdf" PDFs, and \`encodableMediaTypes()\` is the full set. You lose nothing by dropping the extension: a file the browser cannot name is decided by decoding its bytes, which is stronger than matching its name.`
759
994
  );
760
- }, Bt = (t) => (typeof t == "string" ? t.split(",") : t).map(F).filter((e) => e !== "").map(Jt), j = (t) => {
995
+ }, le = (t) => (typeof t == "string" ? t.split(",") : t).map(K).filter((e) => e !== "").map(de), Z = (t) => {
761
996
  const e = t.indexOf("/");
762
997
  return e === -1 ? [t, ""] : [t.slice(0, e), t.slice(e + 1)];
763
- }, S = (t, e) => {
764
- const [n, o] = j(t), [r, s] = j(e);
765
- return n !== "*" && n !== r ? !1 : o === "*" || o === s;
766
- }, Kt = (t, e) => {
767
- if (S(t, e)) return e;
768
- if (S(e, t)) return t;
998
+ }, U = (t, e) => {
999
+ const [n, o] = Z(t), [s, r] = Z(e);
1000
+ return n !== "*" && n !== s ? !1 : o === "*" || o === r;
1001
+ }, fe = (t, e) => {
1002
+ if (U(t, e)) return e;
1003
+ if (U(e, t)) return t;
769
1004
  };
770
- function fe() {
771
- return C.map((t) => t.pattern);
1005
+ function je() {
1006
+ return F.map((t) => t.pattern);
772
1007
  }
773
- function L(t = {}) {
774
- const e = t.accept === void 0 ? void 0 : Bt(t.accept), n = [];
775
- for (const o of C) {
1008
+ function G(t = {}) {
1009
+ const e = t.accept === void 0 ? void 0 : le(t.accept), n = [];
1010
+ for (const o of F) {
776
1011
  if (e === void 0) {
777
1012
  n.push({ ...o });
778
1013
  continue;
779
1014
  }
780
- for (const r of e) {
781
- const s = Kt(o.pattern, r);
782
- s !== void 0 && !n.some((i) => i.pattern === s) && n.push({ pattern: s, kind: o.kind });
1015
+ for (const s of e) {
1016
+ const r = fe(o.pattern, s);
1017
+ r !== void 0 && !n.some((i) => i.pattern === r) && n.push({ pattern: r, kind: o.kind });
783
1018
  }
784
1019
  }
785
1020
  return {
786
1021
  types: n.map((o) => o.pattern),
787
1022
  accept: n.map((o) => o.pattern).join(","),
788
1023
  decide(o) {
789
- const r = o === void 0 ? "" : F(o);
790
- if (B(r))
791
- return n.some((i) => S(i.pattern, J)) ? { status: "undetermined" } : (
1024
+ const s = o === void 0 ? "" : K(o);
1025
+ if (ft(s))
1026
+ return n.some((i) => U(i.pattern, lt)) ? { status: "undetermined" } : (
792
1027
  // `unsupported` rather than `filtered`, deliberately: `filtered`
793
1028
  // claims the kit COULD have encoded this file, and nobody has
794
1029
  // established what it is. Unread and unnamed, it is not a text
795
1030
  // file the filter excluded -- it is a file with no known type.
796
1031
  { status: "unsupported" }
797
1032
  );
798
- const s = n.find((i) => S(i.pattern, r));
799
- return s ? { status: "allowed", kind: s.kind } : C.some((i) => S(i.pattern, r)) ? { status: "filtered" } : { status: "unsupported" };
1033
+ const r = n.find((i) => U(i.pattern, s));
1034
+ return r ? { status: "allowed", kind: r.kind } : F.some((i) => U(i.pattern, s)) ? { status: "filtered" } : { status: "unsupported" };
800
1035
  }
801
1036
  };
802
1037
  }
803
- const Yt = L(), Gt = /^data:([^;,]*);base64,([\s\S]*)$/, Ht = /^([a-z][a-z0-9+.-]*):/i, M = (t) => t.map((e) => `"${e}"`).join(", ");
804
- function P(t) {
1038
+ const pe = G(), he = /^data:([^;,]*);base64,([\s\S]*)$/, ge = /^([a-z][a-z0-9+.-]*):/i, tt = (t) => t.map((e) => `"${e}"`).join(", ");
1039
+ function et(t) {
805
1040
  try {
806
1041
  const e = atob(t), n = new Uint8Array(e.length);
807
1042
  for (let o = 0; o < e.length; o++) n[o] = e.charCodeAt(o);
@@ -810,14 +1045,14 @@ function P(t) {
810
1045
  return { ok: !1 };
811
1046
  }
812
1047
  }
813
- const D = (t) => t.replace(/&/g, "&amp;").replace(/</g, "&lt;").replace(/>/g, "&gt;").replace(/"/g, "&quot;").replace(/\r/g, "&#13;").replace(/\n/g, "&#10;"), zt = /<(\/file\s*)>/gi;
814
- function K(t) {
815
- const e = D(t.filename ?? "attachment"), n = D(t.mediaType), o = t.text.replace(zt, "&lt;$1&gt;");
1048
+ const nt = (t) => t.replace(/&/g, "&amp;").replace(/</g, "&lt;").replace(/>/g, "&gt;").replace(/"/g, "&quot;").replace(/\r/g, "&#13;").replace(/\n/g, "&#10;"), ye = /<(\/file\s*)>/gi;
1049
+ function pt(t) {
1050
+ const e = nt(t.filename ?? "attachment"), n = nt(t.mediaType), o = t.text.replace(ye, "&lt;$1&gt;");
816
1051
  return `<file name="${e}" type="${n}">
817
1052
  ${o}
818
1053
  </file>`;
819
1054
  }
820
- function Xt(t, e = Yt) {
1055
+ function me(t, e = pe) {
821
1056
  var a, c, u;
822
1057
  if (t.type === "source-document") return { status: "kit-side" };
823
1058
  const n = t.url;
@@ -826,11 +1061,11 @@ function Xt(t, e = Yt) {
826
1061
  status: "unencodable",
827
1062
  reason: "it has no `url`, so there are no bytes and no address to send. Set `url` to a `data:` URI (read the File with FileReader.readAsDataURL before you stage it) or to an https URL the provider can fetch."
828
1063
  };
829
- let o, r;
830
- const s = Gt.exec(n);
831
- if (s) {
832
- const d = s[1].toLowerCase();
833
- r = B(d) ? ((a = t.mediaType) == null ? void 0 : a.toLowerCase()) ?? d : d, o = { type: "base64", mediaType: r, data: s[2], dataUri: n };
1064
+ let o, s;
1065
+ const r = he.exec(n);
1066
+ if (r) {
1067
+ const d = r[1].toLowerCase();
1068
+ s = ft(d) ? ((a = t.mediaType) == null ? void 0 : a.toLowerCase()) ?? d : d, o = { type: "base64", mediaType: s, data: r[2], dataUri: n };
834
1069
  } else if (/^https?:\/\//i.test(n)) {
835
1070
  const d = (c = t.mediaType) == null ? void 0 : c.toLowerCase();
836
1071
  if (d === void 0 || d === "")
@@ -838,7 +1073,7 @@ function Xt(t, e = Yt) {
838
1073
  status: "unencodable",
839
1074
  reason: `its \`url\` is remote ("${n}") but it has no \`mediaType\`, so there is no way to tell an image from a document without fetching it -- and this layer does no I/O. Set \`mediaType\` when you stage the attachment.`
840
1075
  };
841
- r = d, o = { type: "remote", url: n };
1076
+ s = d, o = { type: "remote", url: n };
842
1077
  } else {
843
1078
  if (n.startsWith("data:"))
844
1079
  return {
@@ -846,41 +1081,41 @@ function Xt(t, e = Yt) {
846
1081
  reason: "its `url` is a `data:` URI that is not base64-encoded with an explicit media type. Both APIs need `data:<media type>;base64,<data>`."
847
1082
  };
848
1083
  {
849
- const d = (u = Ht.exec(n)) == null ? void 0 : u[1].toLowerCase(), l = d === "blob" ? "a `blob:` URL resolves only inside the browser tab that created it, so a model can never fetch it. Read the File with FileReader.readAsDataURL and stage the `data:` URI instead, or upload it and stage the resulting https URL" : `a "${d ?? n}" URL is not something a provider can fetch. Use a \`data:\` URI or an https URL`;
850
- return { status: "unencodable", reason: `its \`url\` is "${n}": ${l}.` };
1084
+ const d = (u = ge.exec(n)) == null ? void 0 : u[1].toLowerCase(), g = d === "blob" ? "a `blob:` URL resolves only inside the browser tab that created it, so a model can never fetch it. Read the File with FileReader.readAsDataURL and stage the `data:` URI instead, or upload it and stage the resulting https URL" : `a "${d ?? n}" URL is not something a provider can fetch. Use a \`data:\` URI or an https URL`;
1085
+ return { status: "unencodable", reason: `its \`url\` is "${n}": ${g}.` };
851
1086
  }
852
1087
  }
853
- const i = e.decide(r);
1088
+ const i = e.decide(s);
854
1089
  if (i.status === "undetermined") {
855
1090
  if (o.type !== "base64")
856
1091
  return {
857
1092
  status: "unencodable",
858
- reason: `it is at a remote URL ("${o.url}") and its media type "${r}" says nothing about the bytes -- that is the label for "arbitrary binary", so it separates an image from a document not at all. Settling it by reading the bytes would need a fetch, and this layer does no I/O. Set \`mediaType\` to what the file actually is when you stage it.`
1093
+ reason: `it is at a remote URL ("${o.url}") and its media type "${s}" says nothing about the bytes -- that is the label for "arbitrary binary", so it separates an image from a document not at all. Settling it by reading the bytes would need a fetch, and this layer does no I/O. Set \`mediaType\` to what the file actually is when you stage it.`
859
1094
  };
860
- const d = P(o.data);
1095
+ const d = et(o.data);
861
1096
  return d.ok ? {
862
1097
  status: "encodable",
863
1098
  file: {
864
1099
  kind: "text",
865
- mediaType: J,
1100
+ mediaType: lt,
866
1101
  source: o,
867
1102
  filename: t.filename,
868
1103
  text: d.text
869
1104
  }
870
1105
  } : {
871
1106
  status: "unencodable",
872
- reason: `nothing names it -- ${r === "" ? "it carries no media type" : `its media type is "${r}"`}, so the only way to tell what it is was to read it -- and its bytes are not valid UTF-8, so it is binary of some unidentified kind. Neither API has an arbitrary-file block to carry that. Set \`mediaType\` if you know what it is, or hand the file to the model through a tool.`
1107
+ reason: `nothing names it -- ${s === "" ? "it carries no media type" : `its media type is "${s}"`}, so the only way to tell what it is was to read it -- and its bytes are not valid UTF-8, so it is binary of some unidentified kind. Neither API has an arbitrary-file block to carry that. Set \`mediaType\` if you know what it is, or hand the file to the model through a tool.`
873
1108
  };
874
1109
  }
875
1110
  if (i.status === "filtered")
876
1111
  return {
877
1112
  status: "unencodable",
878
- reason: `its media type "${r}" is one this kit can encode, but your \`accept\` filter excludes it. The types you allowed are: ${M(e.types)}. Widen \`accept\` to include it, or stop staging it.`
1113
+ reason: `its media type "${s}" is one this kit can encode, but your \`accept\` filter excludes it. The types you allowed are: ${tt(e.types)}. Widen \`accept\` to include it, or stop staging it.`
879
1114
  };
880
1115
  if (i.status === "unsupported")
881
1116
  return {
882
1117
  status: "unencodable",
883
- reason: `its media type "${r}" is not one either API accepts as message content. Supported: ${M(e.types)}. Extract the content yourself and send it as text, or hand it to the model through a tool.`
1118
+ reason: `its media type "${s}" is not one either API accepts as message content. Supported: ${tt(e.types)}. Extract the content yourself and send it as text, or hand it to the model through a tool.`
884
1119
  };
885
1120
  if (i.kind === "text") {
886
1121
  if (o.type !== "base64")
@@ -888,51 +1123,155 @@ function Xt(t, e = Yt) {
888
1123
  status: "unencodable",
889
1124
  reason: `it is a text file at a remote URL ("${o.url}"), and text has to ride as text CONTENT -- neither API has an arbitrary-file block to point at a URL with. Reading it here would put I/O in the encoder. Fetch it yourself and stage the \`data:\` URI, or paste the contents as a text part.`
890
1125
  };
891
- const d = P(o.data);
1126
+ const d = et(o.data);
892
1127
  return d.ok ? {
893
1128
  status: "encodable",
894
1129
  file: {
895
1130
  kind: "text",
896
- mediaType: r,
1131
+ mediaType: s,
897
1132
  source: o,
898
1133
  filename: t.filename,
899
1134
  text: d.text
900
1135
  }
901
1136
  } : {
902
1137
  status: "unencodable",
903
- reason: `its media type "${r}" says text, but its bytes are not valid UTF-8 -- so it is binary wearing a text label, and inlining it would send the model garbage. Send it under its real media type, or extract the text yourself.`
1138
+ reason: `its media type "${s}" says text, but its bytes are not valid UTF-8 -- so it is binary wearing a text label, and inlining it would send the model garbage. Send it under its real media type, or extract the text yourself.`
904
1139
  };
905
1140
  }
906
1141
  return {
907
1142
  status: "encodable",
908
- file: { kind: i.kind, mediaType: r, source: o, filename: t.filename }
1143
+ file: { kind: i.kind, mediaType: s, source: o, filename: t.filename }
909
1144
  };
910
1145
  }
911
- class E extends Error {
912
- constructor(n, o, r) {
1146
+ let ot;
1147
+ function xe(t) {
1148
+ try {
1149
+ return ot ?? (ot = new TextEncoder()), ot.encode(JSON.stringify(t)).length;
1150
+ } catch {
1151
+ return;
1152
+ }
1153
+ }
1154
+ function ke(t) {
1155
+ const e = t.replace(/\s/g, "");
1156
+ if (e === "") return 0;
1157
+ const n = e.endsWith("==") ? 2 : e.endsWith("=") ? 1 : 0;
1158
+ return Math.max(0, Math.floor(e.length * 3 / 4) - n);
1159
+ }
1160
+ function ht(t) {
1161
+ const e = {
1162
+ ...t.traceId !== void 0 ? { traceId: t.traceId } : {},
1163
+ ...t.label !== void 0 ? { label: t.label } : {}
1164
+ }, n = {}, o = {}, s = [], r = [], i = (a, c) => {
1165
+ a[c] = (a[c] ?? 0) + 1;
1166
+ };
1167
+ return {
1168
+ seen: (a) => i(n, a),
1169
+ encoded: (a) => i(o, a),
1170
+ dropped(a, c, u, d, g) {
1171
+ O({
1172
+ type: "encode.dropped",
1173
+ t: Date.now(),
1174
+ ...e,
1175
+ variant: a,
1176
+ count: 1,
1177
+ messageIndex: u,
1178
+ partIndex: d,
1179
+ reason: c,
1180
+ // The part itself, by reference and unread. This function does not know
1181
+ // what a part is and must not: knowing would mean discriminating one.
1182
+ ...R(() => ({ part: g }))
1183
+ });
1184
+ },
1185
+ attachment(a, c) {
1186
+ s.push(a), r.push(c !== void 0 ? { filename: c } : {});
1187
+ },
1188
+ finish(a, c, u) {
1189
+ const d = {};
1190
+ for (const f of u) i(d, f.role);
1191
+ const g = W() ? xe(u) : void 0;
1192
+ O({
1193
+ type: "encode.request",
1194
+ t: Date.now(),
1195
+ ...e,
1196
+ format: a,
1197
+ threadMessages: c,
1198
+ wireMessages: u.length,
1199
+ // Stated, not omitted: zero is the answer that tells a developer the
1200
+ // system prompt lives somewhere the kit cannot see.
1201
+ systemMessages: d.system ?? 0,
1202
+ byRole: d,
1203
+ partsIn: n,
1204
+ partsEncoded: o,
1205
+ attachments: s,
1206
+ ...g !== void 0 ? { bytes: g } : {},
1207
+ // The encoded body, and the filenames held back from the ledger above.
1208
+ ...R(() => ({
1209
+ body: u,
1210
+ ...r.length > 0 ? { attachments: r } : {}
1211
+ }))
1212
+ });
1213
+ }
1214
+ };
1215
+ }
1216
+ class D extends Error {
1217
+ constructor(n, o, s) {
913
1218
  super(n);
914
- A(this, "messageId");
915
- A(this, "partIndex");
916
- Object.setPrototypeOf(this, E.prototype), this.name = "WireEncodeError", this.messageId = o, this.partIndex = r;
1219
+ S(this, "messageId");
1220
+ S(this, "partIndex");
1221
+ Object.setPrototypeOf(this, D.prototype), this.name = "WireEncodeError", this.messageId = o, this.partIndex = s;
917
1222
  }
918
1223
  }
919
- const Qt = (t) => t.type === "text", Vt = (t) => t.filter(Qt).map((e) => e.text).join("");
920
- function Y(t, e, n, o, r, s) {
921
- const i = Xt(t.attachment, r);
922
- if (i.status === "kit-side") return null;
923
- const a = (u) => {
924
- if (o === "skip") return null;
925
- throw new E(
926
- `Cannot encode file part ${n} of message "${e}": ${u} Pass { onUnencodableFile: 'skip' } to drop it instead of failing.`,
1224
+ const be = (t) => t.type === "text", we = (t) => t.filter(be).map((e) => e.text).join("");
1225
+ function gt(t, e, n, o, s, r, i, a) {
1226
+ const c = me(t.attachment, s), u = t.attachment.mediaType, d = t.attachment.filename;
1227
+ if (c.status === "kit-side")
1228
+ return i == null || i.attachment(
1229
+ {
1230
+ ...u !== void 0 ? { mediaType: u } : {},
1231
+ encoded: !1,
1232
+ disposition: "skipped",
1233
+ reason: "it is a kit-side attachment (a source-document citation chip), not something the user staged to send."
1234
+ },
1235
+ d
1236
+ ), null;
1237
+ const g = (p, l) => {
1238
+ const h = (l == null ? void 0 : l.mediaType) ?? u;
1239
+ if (o === "skip")
1240
+ return i == null || i.attachment(
1241
+ {
1242
+ ...h !== void 0 ? { mediaType: h } : {},
1243
+ ...st(l),
1244
+ encoded: !1,
1245
+ disposition: "skipped",
1246
+ reason: p
1247
+ },
1248
+ d
1249
+ ), i == null || i.dropped("file", p, a, n, t), null;
1250
+ throw new D(
1251
+ `Cannot encode file part ${n} of message "${e}": ${p} Pass { onUnencodableFile: 'skip' } to drop it instead of failing.`,
927
1252
  e,
928
1253
  n
929
1254
  );
930
1255
  };
931
- if (i.status === "unencodable") return a(i.reason);
932
- const c = s(i.file);
933
- return c.ok ? c.block : a(c.reason);
1256
+ if (c.status === "unencodable") return g(c.reason);
1257
+ const f = r(c.file);
1258
+ return f.ok ? (i == null || i.attachment(
1259
+ {
1260
+ mediaType: c.file.mediaType,
1261
+ ...st(c.file),
1262
+ encoded: !0,
1263
+ // A text file rides as text CONTENT on both wires -- worth naming
1264
+ // separately, because it is how an attachment can be "sent" and still not
1265
+ // be a file as far as the model is concerned.
1266
+ disposition: c.file.kind === "text" ? "as-text" : "encoded"
1267
+ },
1268
+ d
1269
+ ), f.block) : g(f.reason, c.file);
934
1270
  }
935
- const Zt = (t) => t.kind === "text" ? { ok: !0, block: { type: "text", text: K(t) } } : t.kind === "image" ? { ok: !0, block: { type: "image_url", image_url: { url: t.source.type === "base64" ? t.source.dataUri : t.source.url } } } : t.source.type === "remote" ? {
1271
+ function st(t) {
1272
+ return W() ? (t == null ? void 0 : t.source.type) !== "base64" ? {} : { bytes: ke(t.source.data) } : {};
1273
+ }
1274
+ const ve = (t) => t.kind === "text" ? { ok: !0, block: { type: "text", text: pt(t) } } : t.kind === "image" ? { ok: !0, block: { type: "image_url", image_url: { url: t.source.type === "base64" ? t.source.dataUri : t.source.url } } } : t.source.type === "remote" ? {
936
1275
  ok: !1,
937
1276
  reason: `it is a PDF at a remote URL ("${t.source.url}"), and a chat-completions \`file\` content part carries only \`file_id\` or \`file_data\` -- this wire has no URL form for a document. Fetch it and stage it as a \`data:\` URI, or upload it through the Files API and send \`file_id\` yourself; fetching it HERE would put I/O in the encoder. The Anthropic wire does take a remote PDF, so toAnthropicMessages accepts this same message.`
938
1277
  } : {
@@ -944,190 +1283,288 @@ const Zt = (t) => t.kind === "text" ? { ok: !0, block: { type: "text", text: K(t
944
1283
  file_data: t.source.dataUri
945
1284
  }
946
1285
  }
947
- }, te = (t) => t.kind === "text" ? { ok: !0, block: { type: "text", text: K(t) } } : {
1286
+ }, Te = (t) => t.kind === "text" ? { ok: !0, block: { type: "text", text: pt(t) } } : {
948
1287
  ok: !0,
949
1288
  block: {
950
1289
  type: t.kind === "image" ? "image" : "document",
951
1290
  source: t.source.type === "base64" ? { type: "base64", media_type: t.source.mediaType, data: t.source.data } : { type: "url", url: t.source.url }
952
1291
  }
953
- }, G = (t) => typeof t.toolCallId == "string" && t.toolCallId !== "" && (t.output !== void 0 || t.errorText !== void 0);
954
- function ee(t) {
1292
+ }, yt = (t) => typeof t.toolCallId == "string" && t.toolCallId !== "" && (t.output !== void 0 || t.errorText !== void 0);
1293
+ function _e(t) {
955
1294
  return t.rawInput !== void 0 && t.rawInput !== "" ? t.rawInput : t.input !== void 0 ? JSON.stringify(t.input) : "{}";
956
1295
  }
957
- const ne = (t) => ({
1296
+ const Ie = (t) => ({
958
1297
  id: t.toolCallId,
959
1298
  type: "function",
960
- function: { name: t.type, arguments: ee(t) }
961
- }), oe = (t) => ({
1299
+ function: { name: t.type, arguments: _e(t) }
1300
+ }), Ae = (t) => ({
962
1301
  role: "tool",
963
1302
  tool_call_id: t.toolCallId,
964
1303
  name: t.type,
965
1304
  content: t.errorText ?? JSON.stringify(t.output)
966
- }), re = (t) => typeof t == "object" && t !== null && !Array.isArray(t);
967
- function ie(t) {
968
- var s;
969
- if (((s = t.raw) == null ? void 0 : s.source) !== "openai.reasoning_details") return;
1305
+ }), Oe = (t) => typeof t == "object" && t !== null && !Array.isArray(t);
1306
+ function Se(t) {
1307
+ var r;
1308
+ if (((r = t.raw) == null ? void 0 : r.source) !== "openai.reasoning_details") return;
970
1309
  const e = t.raw.payload;
971
1310
  if (!Array.isArray(e)) return;
972
- const n = e.filter(re), o = n.filter((i) => i.index === t.index), r = o.length > 0 ? o : n;
973
- return r[r.length - 1];
1311
+ const n = e.filter(Oe), o = n.filter((i) => i.index === t.index), s = o.length > 0 ? o : n;
1312
+ return s[s.length - 1];
974
1313
  }
975
- function se(t) {
976
- const e = ie(t);
1314
+ function Re(t) {
1315
+ const e = Se(t);
977
1316
  if (!e) return;
978
1317
  if (e.type === "reasoning.encrypted" || typeof e.data == "string") return e;
979
1318
  if (typeof t.signature != "string" || t.signature === "") return;
980
- const n = typeof e.type == "string" ? e.type : "reasoning.text", r = { type: n, [n === "reasoning.summary" ? "summary" : "text"]: t.text, signature: t.signature };
981
- return typeof e.format == "string" && (r.format = e.format), typeof e.id == "string" && (r.id = e.id), e.index !== void 0 && (r.index = e.index), r;
1319
+ const n = typeof e.type == "string" ? e.type : "reasoning.text", s = { type: n, [n === "reasoning.summary" ? "summary" : "text"]: t.text, signature: t.signature };
1320
+ return typeof e.format == "string" && (s.format = e.format), typeof e.id == "string" && (s.id = e.id), e.index !== void 0 && (s.index = e.index), s;
982
1321
  }
983
- function ge(t, e = {}) {
984
- const n = e.reasoning === "include", o = e.onUnencodableFile ?? "throw", r = L({ accept: e.accept }), s = [];
985
- for (const i of t) {
986
- if (i.role === "user") {
1322
+ function Le(t, e = {}) {
1323
+ const n = e.reasoning === "include", o = e.onUnencodableFile ?? "throw", s = G({ accept: e.accept }), r = [], i = A() ? ht(e) : void 0;
1324
+ if (i)
1325
+ for (const c of t) for (const u of c.parts) i.seen(u.type);
1326
+ let a = -1;
1327
+ for (const c of t) {
1328
+ if (a++, c.role === "user") {
987
1329
  const l = [];
988
- let p = "", h = !1;
989
- const k = () => {
990
- p !== "" && (l.push({ type: "text", text: p }), p = "");
1330
+ let h = "", m = !1;
1331
+ const v = () => {
1332
+ h !== "" && (l.push({ type: "text", text: h }), h = "");
991
1333
  };
992
- if (i.parts.forEach((m, y) => {
993
- if (m.type === "text") {
994
- p += m.text;
1334
+ if (c.parts.forEach((k, $) => {
1335
+ if (k.type === "text") {
1336
+ h += k.text, k.text !== "" && (i == null || i.encoded("text"));
995
1337
  return;
996
1338
  }
997
- if (m.type !== "file") return;
998
- const T = Y(m, i.id, y, o, r, Zt);
999
- T && (k(), l.push(T), h = !0);
1000
- }), k(), !h) {
1001
- const m = Vt(i.parts);
1002
- m !== "" && s.push({ role: "user", content: m });
1339
+ if (k.type !== "file") {
1340
+ i == null || i.dropped(
1341
+ k.type,
1342
+ "a USER turn carries authored content only: reasoning and tool parts are assistant-side, and cards and sources are kit-side UI with no OpenAI wire form.",
1343
+ a,
1344
+ $,
1345
+ k
1346
+ );
1347
+ return;
1348
+ }
1349
+ const P = gt(
1350
+ k,
1351
+ c.id,
1352
+ $,
1353
+ o,
1354
+ s,
1355
+ ve,
1356
+ i,
1357
+ a
1358
+ );
1359
+ P && (v(), l.push(P), i == null || i.encoded("file"), m = !0);
1360
+ }), v(), !m) {
1361
+ const k = we(c.parts);
1362
+ k !== "" && r.push({ role: "user", content: k });
1003
1363
  continue;
1004
1364
  }
1005
- s.push({ role: "user", content: l });
1365
+ r.push({ role: "user", content: l });
1006
1366
  continue;
1007
1367
  }
1008
- let a = "", c = [], u = [];
1009
- const d = () => {
1010
- if (!(a === "" && c.length === 0)) {
1011
- s.push({
1368
+ let u = "", d = [], g = [];
1369
+ const f = () => {
1370
+ if (!(u === "" && d.length === 0)) {
1371
+ r.push({
1012
1372
  role: "assistant",
1013
- content: a === "" ? null : a,
1014
- ...u.length > 0 ? { reasoning_details: u } : {},
1015
- ...c.length > 0 ? { tool_calls: c.map(ne) } : {}
1373
+ content: u === "" ? null : u,
1374
+ ...g.length > 0 ? { reasoning_details: g } : {},
1375
+ ...d.length > 0 ? { tool_calls: d.map(Ie) } : {}
1016
1376
  });
1017
- for (const l of c) s.push(oe(l));
1018
- a = "", c = [], u = [];
1377
+ for (const l of d) r.push(Ae(l));
1378
+ u = "", d = [], g = [];
1019
1379
  }
1020
1380
  };
1021
- for (const l of i.parts) {
1022
- if (l.type === "text") {
1023
- c.length > 0 && d(), a += l.text;
1381
+ let p = -1;
1382
+ for (const l of c.parts) {
1383
+ if (p++, l.type === "text") {
1384
+ d.length > 0 && f(), u += l.text, l.text !== "" && (i == null || i.encoded("text"));
1024
1385
  continue;
1025
1386
  }
1026
1387
  if (l.type === "reasoning") {
1027
- if (!n) continue;
1028
- c.length > 0 && d();
1029
- const p = se(l);
1030
- p && u.push(p);
1388
+ if (!n) {
1389
+ i == null || i.dropped(
1390
+ "reasoning",
1391
+ "reasoning is omitted by default, because omitting is measured-accepted everywhere and costs about 25% fewer prompt tokens per round. Pass { reasoning: 'include' } to send the model its own prior thinking back.",
1392
+ a,
1393
+ p,
1394
+ l
1395
+ );
1396
+ continue;
1397
+ }
1398
+ d.length > 0 && f();
1399
+ const h = Re(l);
1400
+ if (h) {
1401
+ g.push(h), i == null || i.encoded("reasoning");
1402
+ continue;
1403
+ }
1404
+ i == null || i.dropped(
1405
+ "reasoning",
1406
+ "it has no round-trippable `reasoning_details` carrier -- an opaque or signed block can be echoed back, but a part read from `reasoning_content` has neither, and re-sending an unverifiable block is the documented 400. The model does not see its own prior thinking on the next turn.",
1407
+ a,
1408
+ p,
1409
+ l
1410
+ );
1031
1411
  continue;
1032
1412
  }
1033
- l.type === "tool" && G(l.tool) && c.push(l.tool);
1413
+ if (l.type === "tool") {
1414
+ yt(l.tool) ? (d.push(l.tool), i == null || i.encoded("tool")) : i == null || i.dropped(
1415
+ "tool",
1416
+ "the call has no result yet (or no provider tool call id). Both APIs require every echoed tool call to have exactly one matching result, so a half-formed one is left off rather than sent.",
1417
+ a,
1418
+ p,
1419
+ l
1420
+ );
1421
+ continue;
1422
+ }
1423
+ i == null || i.dropped(
1424
+ l.type,
1425
+ "cards and sources are kit-side UI with no OpenAI wire form, and a `file` part on an ASSISTANT turn has none either -- the API takes image and document content on user turns only.",
1426
+ a,
1427
+ p,
1428
+ l
1429
+ );
1034
1430
  }
1035
- d();
1431
+ f();
1036
1432
  }
1037
- return s;
1433
+ return i == null || i.finish("openai", t.length, r), r;
1038
1434
  }
1039
- function he(t, e = {}) {
1040
- const n = e.onUnencodableFile ?? "throw", o = L({ accept: e.accept }), r = [], s = (i) => {
1041
- const a = r[r.length - 1];
1042
- (a == null ? void 0 : a.role) === "user" ? a.content = [...a.content, ...i] : r.push({ role: "user", content: i });
1435
+ function Me(t, e = {}) {
1436
+ const n = e.onUnencodableFile ?? "throw", o = G({ accept: e.accept }), s = [], r = A() ? ht(e) : void 0;
1437
+ if (r)
1438
+ for (const c of t) for (const u of c.parts) r.seen(u.type);
1439
+ const i = (c) => {
1440
+ const u = s[s.length - 1];
1441
+ (u == null ? void 0 : u.role) === "user" ? u.content = [...u.content, ...c] : s.push({ role: "user", content: c });
1043
1442
  };
1044
- for (const i of t) {
1045
- if (i.role === "user") {
1046
- const d = [];
1047
- i.parts.forEach((l, p) => {
1048
- if (l.type === "text") {
1049
- l.text !== "" && d.push({ type: "text", text: l.text });
1443
+ let a = -1;
1444
+ for (const c of t) {
1445
+ if (a++, c.role === "user") {
1446
+ const f = [];
1447
+ c.parts.forEach((p, l) => {
1448
+ if (p.type === "text") {
1449
+ p.text !== "" && (f.push({ type: "text", text: p.text }), r == null || r.encoded("text"));
1450
+ return;
1451
+ }
1452
+ if (p.type !== "file") {
1453
+ r == null || r.dropped(
1454
+ p.type,
1455
+ "a USER turn carries authored content only: reasoning and tool parts are assistant-side, and cards and sources are kit-side UI with no Anthropic wire form.",
1456
+ a,
1457
+ l,
1458
+ p
1459
+ );
1050
1460
  return;
1051
1461
  }
1052
- if (l.type !== "file") return;
1053
- const h = Y(l, i.id, p, n, o, te);
1054
- h && d.push(h);
1055
- }), d.length > 0 && s(d);
1462
+ const h = gt(
1463
+ p,
1464
+ c.id,
1465
+ l,
1466
+ n,
1467
+ o,
1468
+ Te,
1469
+ r,
1470
+ a
1471
+ );
1472
+ h && (f.push(h), r == null || r.encoded("file"));
1473
+ }), f.length > 0 && i(f);
1056
1474
  continue;
1057
1475
  }
1058
- let a = [], c = [];
1059
- const u = () => {
1060
- a.length > 0 && r.push({ role: "assistant", content: a }), c.length > 0 && s(c), a = [], c = [];
1476
+ let u = [], d = [];
1477
+ const g = () => {
1478
+ u.length > 0 && s.push({ role: "assistant", content: u }), d.length > 0 && i(d), u = [], d = [];
1061
1479
  };
1062
- i.parts.forEach((d, l) => {
1063
- switch (d.type) {
1480
+ c.parts.forEach((f, p) => {
1481
+ switch (f.type) {
1064
1482
  case "reasoning": {
1065
- if (!d.raw)
1066
- throw new E(
1067
- `Cannot encode reasoning part ${l} of message "${i.id}": it has no \`raw\` payload, and Anthropic requires a thinking block to be echoed back verbatim. Rebuilding one from text plus signature is the documented 400. Produce reasoning parts with readAnthropicStream, which attaches the provider's own block, and keep \`raw\` when you persist a message.`,
1068
- i.id,
1069
- l
1483
+ if (!f.raw)
1484
+ throw new D(
1485
+ `Cannot encode reasoning part ${p} of message "${c.id}": it has no \`raw\` payload, and Anthropic requires a thinking block to be echoed back verbatim. Rebuilding one from text plus signature is the documented 400. Produce reasoning parts with readAnthropicStream, which attaches the provider's own block, and keep \`raw\` when you persist a message.`,
1486
+ c.id,
1487
+ p
1070
1488
  );
1071
- if (!d.raw.source.startsWith("anthropic."))
1072
- throw new E(
1073
- `Cannot encode reasoning part ${l} of message "${i.id}": its \`raw\` came from "${d.raw.source}", not from the Anthropic Messages format. Only a payload tagged \`anthropic.\` can be echoed back verbatim. If you are talking to an Anthropic model through an OpenAI-compatible endpoint, use toOpenAIMessages.`,
1074
- i.id,
1075
- l
1489
+ if (!f.raw.source.startsWith("anthropic."))
1490
+ throw new D(
1491
+ `Cannot encode reasoning part ${p} of message "${c.id}": its \`raw\` came from "${f.raw.source}", not from the Anthropic Messages format. Only a payload tagged \`anthropic.\` can be echoed back verbatim. If you are talking to an Anthropic model through an OpenAI-compatible endpoint, use toOpenAIMessages.`,
1492
+ c.id,
1493
+ p
1076
1494
  );
1077
- c.length > 0 && u(), a.push(d.raw.payload);
1495
+ d.length > 0 && g(), u.push(f.raw.payload), r == null || r.encoded("reasoning");
1078
1496
  break;
1079
1497
  }
1080
1498
  case "text": {
1081
- if (d.text === "") break;
1082
- c.length > 0 && u(), a.push({ type: "text", text: d.text });
1499
+ if (f.text === "") break;
1500
+ d.length > 0 && g(), u.push({ type: "text", text: f.text }), r == null || r.encoded("text");
1083
1501
  break;
1084
1502
  }
1085
1503
  case "tool": {
1086
- const p = d.tool;
1087
- if (!G(p)) break;
1088
- a.push({
1504
+ const l = f.tool;
1505
+ if (!yt(l)) {
1506
+ r == null || r.dropped(
1507
+ "tool",
1508
+ "the call has no result yet (or no provider tool call id). Both APIs require every echoed tool call to have exactly one matching result, so a half-formed one is left off rather than sent.",
1509
+ a,
1510
+ p,
1511
+ f
1512
+ );
1513
+ break;
1514
+ }
1515
+ r == null || r.encoded("tool"), u.push({
1089
1516
  type: "tool_use",
1090
- id: p.toolCallId,
1091
- name: p.type,
1092
- input: p.input ?? {}
1093
- }), c.push(
1094
- p.errorText !== void 0 ? {
1517
+ id: l.toolCallId,
1518
+ name: l.type,
1519
+ input: l.input ?? {}
1520
+ }), d.push(
1521
+ l.errorText !== void 0 ? {
1095
1522
  type: "tool_result",
1096
- tool_use_id: p.toolCallId,
1523
+ tool_use_id: l.toolCallId,
1097
1524
  is_error: !0,
1098
- content: p.errorText
1525
+ content: l.errorText
1099
1526
  } : {
1100
1527
  type: "tool_result",
1101
- tool_use_id: p.toolCallId,
1102
- content: JSON.stringify(p.output)
1528
+ tool_use_id: l.toolCallId,
1529
+ content: JSON.stringify(l.output)
1103
1530
  }
1104
1531
  );
1105
1532
  break;
1106
1533
  }
1534
+ default:
1535
+ r == null || r.dropped(
1536
+ f.type,
1537
+ "cards and sources are kit-side UI, and a `file` part on an ASSISTANT turn has no Anthropic representation -- the API takes image and document content on user turns only.",
1538
+ a,
1539
+ p,
1540
+ f
1541
+ );
1542
+ break;
1107
1543
  }
1108
- }), u();
1544
+ }), g();
1109
1545
  }
1110
- return r;
1546
+ return r == null || r.finish("anthropic", t.length, s), s;
1111
1547
  }
1112
1548
  export {
1113
- E as WireEncodeError,
1114
- U as WireError,
1115
- Nt as anthropicMessagesFormat,
1116
- le as applyToolFailure,
1117
- de as applyToolOutput,
1118
- pe as bufferText,
1119
- wt as consumeModelStream,
1120
- yt as createToolCallAccumulator,
1121
- fe as encodableMediaTypes,
1122
- lt as normalizeStopReason,
1123
- Et as openaiChatFormat,
1124
- ce as readAnthropicStream,
1125
- q as readModelStream,
1126
- ue as readOpenAIStream,
1127
- X as readableToAsyncIterable,
1128
- L as resolveMediaPolicy,
1129
- V as sseDataFrames,
1130
- Z as sseJson,
1131
- he as toAnthropicMessages,
1132
- ge as toOpenAIMessages
1549
+ D as WireEncodeError,
1550
+ B as WireError,
1551
+ ne as anthropicMessagesFormat,
1552
+ Pe as applyToolFailure,
1553
+ De as applyToolOutput,
1554
+ Ne as bufferText,
1555
+ qt as consumeModelStream,
1556
+ Lt as createToolCallAccumulator,
1557
+ je as encodableMediaTypes,
1558
+ z as normalizeStopReason,
1559
+ Qt as openaiChatFormat,
1560
+ Ue as readAnthropicStream,
1561
+ dt as readModelStream,
1562
+ Ce as readOpenAIStream,
1563
+ kt as readableToAsyncIterable,
1564
+ G as resolveMediaPolicy,
1565
+ wt as sseDataFrames,
1566
+ vt as sseJson,
1567
+ $e as subscribeWireDiagnostics,
1568
+ Me as toAnthropicMessages,
1569
+ Le as toOpenAIMessages
1133
1570
  };