@kitn.ai/ui 0.25.2 → 0.27.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.
- package/README.md +17 -6
- package/bin/mcp.js +16 -3
- package/bin/route.js +23 -0
- package/bin/route.test.js +58 -0
- package/dist/{elements/chunks/Icon-b5A8hlHs.js → Icon-BnFKqqtY.js} +1 -1
- package/dist/action-icons-CBskfBMz.js +1 -0
- package/dist/arrow-down-Br0qtpsz.js +1 -0
- package/dist/arrow-left-Dj7xgE12.js +1 -0
- package/dist/artifact-CvXEm1lS.js +1 -0
- package/dist/assets/dev-5XzXYR21.js +91 -0
- package/dist/attachments-C43ZegEq.js +1 -0
- package/dist/audio-visualizer-B-79y1Tj.js +1 -0
- package/dist/badge-BpUbq8c0.js +1 -0
- package/dist/bash-InADTalH.js +1 -6
- package/dist/bell-sn17Ip9v.js +1 -0
- package/dist/{elements/chunks/button-B9okqG73.js → button-BH6rN0U-.js} +1 -1
- package/dist/card-renderer-Cb1gQmth.js +1 -0
- package/dist/card-routing-DifQgS7n.js +1 -0
- package/dist/check-DPeeMUYx.js +1 -0
- package/dist/checkbox-Dc9Yov_B.js +1 -0
- package/dist/checkbox-group-B1kDLLYk.js +1 -0
- package/dist/chevron-down-CHSWk7ZT.js +1 -0
- package/dist/chevron-right-B7l_fMgx.js +1 -0
- package/dist/choice-card-BT3c1S8g.js +1 -0
- package/dist/circle-Bb0yOpqM.js +1 -0
- package/dist/circle-check-BGZpCiz7.js +1 -0
- package/dist/circle-x-wobWkoSx.js +1 -0
- package/dist/{elements/chunks/cn-CU7UAWzk.js → cn-DN5AWfiS.js} +1 -1
- package/dist/code-block-CUQ5mtv0.js +1 -0
- package/dist/collapsible-CPJbf6FM.js +1 -0
- package/dist/components/attachment-types.d.ts +53 -1
- package/dist/components/attachments.d.ts +31 -0
- package/dist/components/audio-visualizer/fit-scale.d.ts +50 -0
- package/dist/components/audio-visualizer/index.d.ts +15 -1
- package/dist/components/audio-visualizer/variant-bar.d.ts +24 -1
- package/dist/components/card-renderer.d.ts +13 -0
- package/dist/components/card.d.ts +4 -0
- package/dist/components/chat-thread.d.ts +49 -42
- package/dist/components/code-block.d.ts +22 -0
- package/dist/components/conversation-item.d.ts +66 -1
- package/dist/components/conversation-list.d.ts +77 -0
- package/dist/components/form-widgets.d.ts +67 -2
- package/dist/components/form.d.ts +89 -0
- package/dist/components/message.d.ts +29 -0
- package/dist/components/reasoning.d.ts +6 -0
- package/dist/components/scroll-button.d.ts +11 -0
- package/dist/components/thread.d.ts +5 -0
- package/dist/components/toast.d.ts +2 -1
- package/dist/components/tool-types.d.ts +9 -0
- package/dist/components/voice-input.d.ts +8 -0
- package/dist/components/voice-output.d.ts +12 -1
- package/dist/components/workspace-shell.d.ts +87 -0
- package/dist/composer-CjngLzal.js +106 -0
- package/dist/confirm-card-DCx_A4bU.js +1 -0
- package/dist/construct-cli.es.js +1169 -0
- package/dist/context-BY8V-Nlp.js +1 -0
- package/dist/controllable-D43BKmtX.js +1 -0
- package/dist/conversation-list-D4lLU_yS.js +1 -0
- package/dist/copy-B6DO4PqB.js +1 -0
- package/dist/core-AYMC6_lb.js +12 -5874
- package/dist/{create-tween-CUzOlaMS.js → create-tween-BPzaefTp.js} +1 -1
- package/dist/{create-tween-B5Y4Im8G.js → create-tween-CnMHviKB.js} +1 -1
- package/dist/{create-tween-4z1XYLkR.js → create-tween-D1aiGZZh.js} +1 -1
- package/dist/{elements/chunks/create-tween-CUrM6D_o.js → create-tween-DUSQUKpr.js} +2 -2
- package/dist/css-M7EaDHN_.js +1 -6
- package/dist/custom-elements.json +3468 -1927
- package/dist/default-input-CucQEOqH.js +1 -0
- package/dist/define-CGGX-7Vg.js +1 -0
- package/dist/define.d.ts +4 -0
- package/dist/define.js +510 -0
- package/dist/define.server.d.ts +5 -0
- package/dist/define.server.js +506 -0
- package/dist/diagnostics/hook.d.ts +81 -0
- package/dist/diagnostics/index.d.ts +7 -0
- package/dist/diagnostics/report-request.d.ts +61 -0
- package/dist/diagnostics.d.ts +5 -0
- package/dist/diagnostics.js +209 -0
- package/dist/disclosure-CbLtajUQ.js +1 -0
- package/dist/dropdown-BwhViJFd.js +1 -0
- package/dist/elements/agent-card.js +1 -1
- package/dist/elements/artifact.js +1 -1
- package/dist/elements/attachments.js +1 -1
- package/dist/elements/audio-visualizer.js +1 -1
- package/dist/elements/autoloader.js +1 -1
- package/dist/elements/avatar.js +1 -1
- package/dist/elements/badge.js +1 -1
- package/dist/elements/button.js +1 -1
- package/dist/elements/card.js +1 -1
- package/dist/elements/cards.js +1 -1
- package/dist/elements/chain-of-thought.js +1 -1
- package/dist/elements/chat-scope-picker.js +1 -1
- package/dist/elements/chat-workspace.js +1 -1
- package/dist/elements/chat.js +1 -1
- package/dist/elements/checkbox-group.d.ts +1 -0
- package/dist/elements/checkbox-group.js +1 -0
- package/dist/elements/checkbox.d.ts +1 -0
- package/dist/elements/checkbox.js +1 -0
- package/dist/elements/checkpoint.js +1 -1
- package/dist/elements/choice.js +1 -1
- package/dist/elements/coachmark.js +1 -1
- package/dist/elements/code-block.js +1 -1
- package/dist/elements/command.js +1 -1
- package/dist/elements/compare.js +1 -1
- package/dist/elements/composer.js +1 -1
- package/dist/elements/confirm-card.js +1 -1
- package/dist/elements/context-meter.js +1 -1
- package/dist/elements/conversation-item.d.ts +1 -0
- package/dist/elements/conversation-item.js +1 -0
- package/dist/elements/conversation-list.js +1 -1
- package/dist/elements/default-input.d.ts +3 -3
- package/dist/elements/define-entry.d.ts +12 -0
- package/dist/elements/define.d.ts +27 -0
- package/dist/elements/diagnostic-events.d.ts +74 -0
- package/dist/elements/dialog.js +1 -1
- package/dist/elements/dock.d.ts +1 -0
- package/dist/elements/dock.js +243 -0
- package/dist/elements/dropdown.d.ts +1 -0
- package/dist/elements/dropdown.js +1 -0
- package/dist/elements/editable-label.js +1 -1
- package/dist/elements/element-data-types.d.ts +37 -0
- package/dist/elements/element-diagnostics.d.ts +81 -0
- package/dist/elements/embed.js +1 -1
- package/dist/elements/empty.js +1 -1
- package/dist/elements/feedback-bar.js +1 -1
- package/dist/elements/file-tree.js +1 -1
- package/dist/elements/file-upload.js +1 -1
- package/dist/elements/form.js +1 -1
- package/dist/elements/hover-card.js +1 -1
- package/dist/elements/icon.js +1 -1
- package/dist/elements/image.js +1 -1
- package/dist/elements/input.js +1 -1
- package/dist/elements/kbd.js +1 -1
- package/dist/elements/link-preview.js +1 -1
- package/dist/elements/loader.js +1 -1
- package/dist/elements/markdown.js +1 -1
- package/dist/elements/menu.js +1 -1
- package/dist/elements/message-skills.js +1 -1
- package/dist/elements/message.js +1 -1
- package/dist/elements/model-switcher.js +1 -1
- package/dist/elements/nav.js +1 -1
- package/dist/elements/notice.js +1 -1
- package/dist/elements/pane-grid.d.ts +1 -0
- package/dist/elements/pane-grid.js +1 -0
- package/dist/elements/pane-group.js +1 -1
- package/dist/elements/pane.js +1 -1
- package/dist/elements/popover.js +1 -1
- package/dist/elements/progress-bar.js +1 -1
- package/dist/elements/prompt-dock.js +1 -1
- package/dist/elements/prompt-input.js +1 -1
- package/dist/elements/prompt-suggestions.js +1 -1
- package/dist/elements/radio-group.d.ts +1 -0
- package/dist/elements/radio-group.js +1 -0
- package/dist/elements/reasoning.js +1 -1
- package/dist/elements/register.d.ts +2 -0
- package/dist/elements/remote.js +1 -1
- package/dist/elements/resizable.js +1 -1
- package/dist/elements/response-stream.js +3 -3
- package/dist/elements/screen.js +1 -1
- package/dist/elements/scroll-area.js +1 -1
- package/dist/elements/scroll-button.js +1 -1
- package/dist/elements/search.js +1 -1
- package/dist/elements/segmented.js +1 -1
- package/dist/elements/select.d.ts +1 -0
- package/dist/elements/select.js +1 -0
- package/dist/elements/separator.js +1 -1
- package/dist/elements/setting-item.js +1 -1
- package/dist/elements/settings-group.js +1 -1
- package/dist/elements/skeleton.js +1 -1
- package/dist/elements/slider.d.ts +1 -0
- package/dist/elements/slider.js +1 -0
- package/dist/elements/slots.d.ts +36 -4
- package/dist/elements/source.js +1 -1
- package/dist/elements/status.js +1 -1
- package/dist/elements/switch.js +1 -1
- package/dist/elements/tabs.js +1 -1
- package/dist/elements/tasks.js +1 -1
- package/dist/elements/text-shimmer.js +1 -1
- package/dist/elements/thinking-bar.js +1 -1
- package/dist/elements/thread.js +1 -1
- package/dist/elements/toast.js +1 -1
- package/dist/elements/tool.js +1 -1
- package/dist/elements/tooltip.js +1 -1
- package/dist/elements/voice-input.js +1 -1
- package/dist/elements/voice-output.js +1 -1
- package/dist/elements.d.ts +589 -167
- package/dist/{elements/chunks/ellipsis-CVxqfsDZ.js → ellipsis-DFr4Vqr3.js} +1 -1
- package/dist/embed-5s_vU4J0.js +1 -0
- package/dist/engine-javascript-vq0WuIJl.js +14 -2516
- package/dist/{elements/chunks/external-link-DG2sRdQL.js → external-link-u9d85ORQ.js} +1 -1
- package/dist/file-text-CX7_x42o.js +1 -0
- package/dist/{elements/chunks/file-tree-yGWNK0Js.js → file-tree-D3kBjXI5.js} +1 -1
- package/dist/folder-V-YdIL8f.js +1 -0
- package/dist/form-BRNUMCN2.js +1 -0
- package/dist/github-dark-dimmed-DUshB20C.js +1 -4
- package/dist/github-light-JYsPkUQd.js +1 -4
- package/dist/hover-card-DaeiYrTA.js +1 -0
- package/dist/html-CPZ3oZQ7.js +1 -10
- package/dist/icon-BpixdZNq.js +1 -0
- package/dist/{elements/chunks/index-BCRhi84a.js → index-xu_pdcPi.js} +1 -1
- package/dist/index.d.ts +3 -1
- package/dist/index.js +8473 -6470
- package/dist/index.server.js +6495 -4958
- package/dist/info-8mFsIjS3.js +1 -0
- package/dist/input-d1Yuu-hz.js +1 -0
- package/dist/javascript-C25yR2R2.js +1 -6
- package/dist/json-DxJze_jm.js +1 -6
- package/dist/kai-provider.es.js +40 -40
- package/dist/kai.es.js +1 -1
- package/dist/kbd-961zMPFB.js +1 -0
- package/dist/link-DlZZBGaR.js +1 -0
- package/dist/{elements/chunks/link-preview-Cf5KOP-i.js → link-preview-DIIbV2Sd.js} +1 -1
- package/dist/loader-YQszHFaW.js +1 -0
- package/dist/{elements/chunks/markdown-DbozyYqa.js → markdown-CVk1MPsj.js} +1 -1
- package/dist/mcp.es.js +3873 -544
- package/dist/message-CwKVEdZg.js +1 -0
- package/dist/message-DS8lzHc1.js +1 -0
- package/dist/message-circle-Xf8Q-vZp.js +1 -0
- package/dist/message-square-Cxnwgkns.js +1 -0
- package/dist/{elements/chunks/minimize-2-SegJ_oku.js → minimize-2-UEZmP2QT.js} +1 -1
- package/dist/{elements/chunks/model-switcher-D7JrFFHp.js → model-switcher-Kk1jEQ5t.js} +1 -1
- package/dist/{elements/chunks/overlay-CV7z2YuX.js → overlay-C1od6LOz.js} +1 -1
- package/dist/panel-right-ryET0yyn.js +1 -0
- package/dist/paperclip-BDNoZFJP.js +1 -0
- package/dist/play-OFIvYXUQ.js +1 -0
- package/dist/primitives/card-data-types.d.ts +49 -0
- package/dist/primitives/card-routing.d.ts +1 -33
- package/dist/primitives/card-validate.d.ts +2 -2
- package/dist/primitives/chat-config.d.ts +29 -2
- package/dist/primitives/field-mask.d.ts +96 -0
- package/dist/primitives/field-semantics.d.ts +36 -0
- package/dist/primitives/input-mask.d.ts +46 -0
- package/dist/primitives/url-scheme-policy.d.ts +34 -0
- package/dist/primitives/use-resize-observer.d.ts +23 -0
- package/dist/primitives/use-speech-recognition.d.ts +8 -0
- package/dist/primitives/use-text-stream.d.ts +5 -0
- package/dist/progress-bar-BvYX0aoy.js +1 -0
- package/dist/prompt-suggestion-BRFu2lcu.js +1 -0
- package/dist/radio-DcL23cNJ.js +1 -0
- package/dist/react/index.d.ts +306 -283
- package/dist/react.js +309 -247
- package/dist/reasoning-Cackq4Rh.js +1 -0
- package/dist/register-impl-C7rENvPK.js +424 -0
- package/dist/{elements/chunks/resizable-Dpzjlvp4.js → resizable-Cp9HUYih.js} +1 -1
- package/dist/rotate-ccw-0DLRDHH5.js +1 -0
- package/dist/rotate-cw-DOB9IGcU.js +1 -0
- package/dist/schemas/form.schema.json +21 -1
- package/dist/schemas/index.d.ts +1 -1
- package/dist/schemas/tool-defs.d.ts +45 -0
- package/dist/schemas.js +398 -305
- package/dist/scroll-area-emVmWP4K.js +1 -0
- package/dist/scroll-button-CeP_gv1x.js +1 -0
- package/dist/select-CWmu00tS.js +1 -0
- package/dist/{elements/chunks/separator-DH2r_ZSZ.js → separator-CE6vly6z.js} +1 -1
- package/dist/{elements/chunks/settings-BFMOd6yB.js → settings-CE-78SvZ.js} +1 -1
- package/dist/{elements/chunks/settings-group-B3VZKIcz.js → settings-group-ZFWNxFQR.js} +1 -1
- package/dist/{elements/chunks/skeleton-N8BuWYmf.js → skeleton-BebdP4mf.js} +1 -1
- package/dist/slider-BAKRYUlz.js +1 -0
- package/dist/slots-DaNjX0rc.js +1 -0
- package/dist/{solid-BMuDmFo_.js → solid-BE5ui6sy.js} +10672 -8116
- package/dist/{solid-CGYNdLRR.js → solid-DFhsce3O.js} +8137 -6056
- package/dist/solid.d.ts +15 -0
- package/dist/solid.js +248 -235
- package/dist/solid.server.js +248 -235
- package/dist/source-B0FlguSx.js +1 -0
- package/dist/star-CBMZvLuN.js +1 -0
- package/dist/state/index.d.ts +5 -1
- package/dist/state/mock.d.ts +32 -2
- package/dist/state/persistence.d.ts +51 -0
- package/dist/state/stream.d.ts +50 -0
- package/dist/state/threads.d.ts +71 -0
- package/dist/state.js +297 -172
- package/dist/store-7eoadydQ.js +1 -0
- package/dist/svelte--5p79yCD.js +1 -15
- package/dist/switch-CViARZCy.js +1 -0
- package/dist/tasks-card-MjCcOhR_.js +1 -0
- package/dist/text-shimmer-DKlwRF2G.js +1 -0
- package/dist/textarea-3ay2Me2-.js +1 -0
- package/dist/theme.tokens.css +82 -13
- package/dist/{elements/chunks/thumbs-up-DQe0hvkZ.js → thumbs-up-DQcu2HMO.js} +1 -1
- package/dist/toast-store-C6yKOhbk.js +1 -0
- package/dist/{elements/chunks/tool-C1YtxwPu.js → tool-BCYNlfKy.js} +1 -1
- package/dist/{elements/chunks/tooltip-BqwnFWhn.js → tooltip-05zI4hjs.js} +1 -1
- package/dist/trash-2-BR1RxGky.js +1 -0
- package/dist/{elements/chunks/triangle-alert-B6or7F5u.js → triangle-alert-DHohDOCy.js} +1 -1
- package/dist/tsx-B8rCNbgL.js +1 -6
- package/dist/types.d.ts +4 -2
- package/dist/typescript-RycA9KXf.js +1 -6
- package/dist/ui/checkbox-group.d.ts +83 -0
- package/dist/ui/checkbox.d.ts +40 -0
- package/dist/ui/dock.d.ts +131 -0
- package/dist/ui/hover-card.d.ts +44 -0
- package/dist/ui/icon.d.ts +3 -0
- package/dist/ui/input.d.ts +48 -2
- package/dist/ui/radio.d.ts +85 -0
- package/dist/ui/select.d.ts +71 -0
- package/dist/ui/slider.d.ts +65 -0
- package/dist/ui/switch.d.ts +9 -2
- package/dist/upload-BbGW6A_u.js +1 -0
- package/dist/url-scheme-policy-DHpoTJwB.js +1 -0
- package/dist/use-card-resolution-CJW4grFa.js +1 -0
- package/dist/{variant-aurora-DwSOfraQ.js → variant-aurora-BUOVgPOB.js} +27 -27
- package/dist/{variant-aurora-wKvAQ5wp.js → variant-aurora-CUsUJvFI.js} +28 -28
- package/dist/{variant-aurora-XEkPT0_z.js → variant-aurora-CW2i4bfr.js} +2 -2
- package/dist/{elements/chunks/variant-aurora-QXTZPyST.js → variant-aurora-xiMPty8f.js} +2 -2
- package/dist/variant-custom-BQtOnmeO.js +1 -0
- package/dist/{variant-custom-BhS9wIpU.js → variant-custom-CAm9L-E5.js} +65 -65
- package/dist/{variant-custom-eFIg2XWQ.js → variant-custom-CAnzzppW.js} +40 -40
- package/dist/variant-custom-D91HjAKz.js +1 -0
- package/dist/{variant-wave-CUWGx9Bn.js → variant-wave-Ca1Ls4_y.js} +21 -21
- package/dist/{variant-wave-CbVsmgwT.js → variant-wave-CxX39DKd.js} +25 -25
- package/dist/{variant-wave-BwzrHD1s.js → variant-wave-DYyzIIZv.js} +2 -2
- package/dist/{elements/chunks/variant-wave-DDCwhLas.js → variant-wave-uY5crU_K.js} +2 -2
- package/dist/vue-BmIZj4XD.js +1 -33
- package/dist/wire/chunk.d.ts +47 -0
- package/dist/wire/diagnostics.d.ts +575 -0
- package/dist/wire/encode-probe.d.ts +70 -0
- package/dist/wire/encode.d.ts +24 -0
- package/dist/wire/index.d.ts +2 -0
- package/dist/wire/sse.d.ts +10 -2
- package/dist/wire.js +917 -480
- package/dist/x-C5m1JFgi.js +1 -0
- package/frameworks/react/index.tsx +325 -108
- package/llms-full.txt +1354 -82
- package/llms.txt +6 -3
- package/package.json +39 -6
- package/src/agent-tooling/archetypes.ts +41 -9
- package/src/agent-tooling/catalog/README.md +676 -0
- package/src/agent-tooling/catalog/catalog-types.ts +231 -0
- package/src/agent-tooling/catalog/fabrications.ts +96 -0
- package/src/agent-tooling/catalog/invariants.ts +284 -0
- package/src/agent-tooling/catalog/labs-titles.ts +114 -0
- package/src/agent-tooling/catalog/scenarios.ts +87 -0
- package/src/agent-tooling/catalog/surfaces.ts +347 -0
- package/src/agent-tooling/construct/cli-entry.ts +8 -0
- package/src/agent-tooling/construct/cli.ts +131 -0
- package/src/agent-tooling/construct/codegen.ts +1353 -0
- package/src/agent-tooling/construct/construct.v1.schema.json +250 -0
- package/src/agent-tooling/construct/dev.ts +148 -0
- package/src/agent-tooling/construct/fixtures/demo-widget.construct.json +7 -0
- package/src/agent-tooling/construct/fixtures/ops-console.construct.json +44 -0
- package/src/agent-tooling/construct/fixtures/owner-widget.construct.json +23 -0
- package/src/agent-tooling/construct/schema.ts +371 -0
- package/src/agent-tooling/integrations/anthropic.ts +7 -1
- package/src/agent-tooling/integrations/cloudflare.ts +43 -2
- package/src/agent-tooling/integrations/langgraph.ts +7 -1
- package/src/agent-tooling/integrations/mastra.ts +7 -1
- package/src/agent-tooling/integrations/mock.ts +92 -17
- package/src/agent-tooling/integrations/ollama.ts +7 -1
- package/src/agent-tooling/integrations/openai.ts +7 -1
- package/src/agent-tooling/integrations/openrouter.ts +7 -1
- package/src/agent-tooling/integrations/pi.ts +56 -1
- package/src/agent-tooling/integrations/vercel-ai-sdk.ts +7 -1
- package/src/agent-tooling/mcp/css-raw.d.ts +12 -0
- package/src/agent-tooling/mcp/manifest.ts +100 -1
- package/src/agent-tooling/mcp/server.ts +63 -6
- package/src/agent-tooling/mcp/tools/construct.ts +130 -0
- package/src/agent-tooling/mcp/tools/debug.ts +126 -4
- package/src/agent-tooling/mcp/tools/reference.ts +542 -5
- package/src/agent-tooling/mcp/tools/scaffold.ts +1834 -307
- package/src/agent-tooling/mcp/tools/theme.ts +146 -30
- package/src/agent-tooling/mcp/validate-args.ts +141 -0
- package/src/agent-tooling/recipes/composed-thread.ts +714 -0
- package/src/agent-tooling/recipes/index.ts +22 -0
- package/src/agent-tooling/recipes/types.ts +32 -0
- package/src/agent-tooling/registry.ts +24 -7
- package/src/agent-tooling/route-emit.ts +26 -2
- package/src/components/attachment-types.ts +54 -1
- package/src/components/attachments.tsx +169 -22
- package/src/components/audio-visualizer/fit-scale.ts +112 -0
- package/src/components/audio-visualizer/index.tsx +80 -3
- package/src/components/audio-visualizer/variant-aurora.tsx +10 -4
- package/src/components/audio-visualizer/variant-bar.tsx +38 -6
- package/src/components/audio-visualizer/variant-custom.tsx +8 -2
- package/src/components/audio-visualizer/variant-grid.tsx +16 -11
- package/src/components/audio-visualizer/variant-radial.tsx +15 -10
- package/src/components/audio-visualizer/variant-wave.tsx +7 -2
- package/src/components/card-renderer.tsx +39 -8
- package/src/components/card.tsx +10 -2
- package/src/components/chat-container.tsx +4 -1
- package/src/components/chat-scope-picker.tsx +2 -2
- package/src/components/chat-thread.tsx +105 -13
- package/src/components/choice-card.tsx +102 -37
- package/src/components/coachmark.tsx +1 -1
- package/src/components/code-block.tsx +81 -5
- package/src/components/composer.tsx +89 -8
- package/src/components/confirm-card.tsx +20 -4
- package/src/components/conversation-item.tsx +138 -4
- package/src/components/conversation-list.tsx +230 -15
- package/src/components/embed.tsx +4 -0
- package/src/components/empty.tsx +14 -3
- package/src/components/file-tree.tsx +5 -1
- package/src/components/form-widgets.tsx +257 -195
- package/src/components/form.tsx +336 -21
- package/src/components/loader.tsx +12 -5
- package/src/components/message-skills.tsx +1 -1
- package/src/components/message.tsx +142 -12
- package/src/components/prompt-input.tsx +7 -1
- package/src/components/prompt-suggestion.tsx +4 -1
- package/src/components/reasoning.tsx +30 -3
- package/src/components/response-compare.tsx +2 -2
- package/src/components/response-stream.tsx +13 -7
- package/src/components/screen.tsx +5 -0
- package/src/components/scroll-button.tsx +63 -4
- package/src/components/source.tsx +6 -1
- package/src/components/tasks-card.tsx +58 -16
- package/src/components/thread.tsx +10 -1
- package/src/components/toast.tsx +11 -5
- package/src/components/tool-types.ts +9 -0
- package/src/components/voice-input.tsx +35 -3
- package/src/components/voice-output.tsx +46 -6
- package/src/components/workspace-shell.tsx +285 -0
- package/src/diagnostics/hook.ts +352 -0
- package/src/diagnostics/index.ts +82 -0
- package/src/diagnostics/report-request.ts +296 -0
- package/src/elements/attachments.tsx +9 -8
- package/src/elements/audio-visualizer.tsx +48 -4
- package/src/elements/chat-workspace.tsx +159 -287
- package/src/elements/chat.tsx +31 -10
- package/src/elements/checkbox-group.tsx +164 -0
- package/src/elements/checkbox.tsx +134 -0
- package/src/elements/code-block.tsx +19 -1
- package/src/elements/command.tsx +4 -1
- package/src/elements/compiled.css +1 -1
- package/src/elements/composer.tsx +12 -1
- package/src/elements/conversation-item.tsx +120 -0
- package/src/elements/conversation-list.tsx +60 -11
- package/src/elements/default-input.tsx +5 -5
- package/src/elements/define-entry.ts +12 -0
- package/src/elements/define.tsx +168 -8
- package/src/elements/diagnostic-events.ts +114 -0
- package/src/elements/dialog.tsx +47 -0
- package/src/elements/disclosure.ts +34 -12
- package/src/elements/dock.tsx +215 -0
- package/src/elements/dropdown.tsx +123 -0
- package/src/elements/element-data-types.ts +40 -0
- package/src/elements/element-diagnostics.ts +392 -0
- package/src/elements/element-manifest.json +36 -0
- package/src/elements/element-meta.json +1483 -560
- package/src/elements/element-nonscalar.json +185 -0
- package/src/elements/element-types.d.ts +589 -167
- package/src/elements/feedback-bar.tsx +5 -0
- package/src/elements/icon-names.json +29 -0
- package/src/elements/input.tsx +312 -23
- package/src/elements/menu.tsx +13 -0
- package/src/elements/message.tsx +2 -0
- package/src/elements/pane-grid.tsx +111 -0
- package/src/elements/prompt-dock.tsx +2 -1
- package/src/elements/prompt-input.tsx +16 -10
- package/src/elements/radio-group.tsx +129 -0
- package/src/elements/register-impl.ts +52 -0
- package/src/elements/register.ts +28 -0
- package/src/elements/resizable.tsx +52 -25
- package/src/elements/scroll-button.tsx +59 -6
- package/src/elements/select.tsx +165 -0
- package/src/elements/slider.tsx +171 -0
- package/src/elements/slots.ts +108 -13
- package/src/elements/styles.css +119 -9
- package/src/elements/thinking-bar.tsx +16 -7
- package/src/elements/thread.tsx +2 -0
- package/src/elements/toast.tsx +17 -1
- package/src/elements/tool.tsx +26 -5
- package/src/elements/voice-input.tsx +11 -2
- package/src/elements/voice-output.tsx +16 -3
- package/src/index.ts +4 -1
- package/src/primitives/card-data-types.ts +49 -0
- package/src/primitives/card-host.tsx +4 -2
- package/src/primitives/card-routing.ts +7 -56
- package/src/primitives/card-schemas/form.schema.json +21 -1
- package/src/primitives/card-validate.ts +10 -2
- package/src/primitives/chat-config.tsx +33 -6
- package/src/primitives/field-mask.ts +256 -0
- package/src/primitives/field-semantics.ts +115 -0
- package/src/primitives/input-mask.ts +853 -0
- package/src/primitives/toast-store.ts +66 -4
- package/src/primitives/url-scheme-policy.ts +70 -0
- package/src/primitives/use-resize-observer.ts +33 -0
- package/src/primitives/use-speech-recognition.ts +12 -1
- package/src/primitives/use-stick-to-bottom.ts +34 -2
- package/src/primitives/use-text-stream.ts +33 -2
- package/src/remote/provider-runtime.ts +6 -3
- package/src/schemas/index.ts +1 -0
- package/src/schemas/tool-defs.ts +307 -6
- package/src/solid.ts +15 -0
- package/src/state/index.ts +13 -1
- package/src/state/mock.ts +92 -6
- package/src/state/persistence.ts +180 -0
- package/src/state/stream.ts +71 -4
- package/src/state/threads.ts +142 -0
- package/src/types.ts +4 -2
- package/src/ui/agent-card.tsx +2 -2
- package/src/ui/avatar.tsx +1 -1
- package/src/ui/checkbox-group.tsx +153 -0
- package/src/ui/checkbox.tsx +63 -0
- package/src/ui/dialog.tsx +6 -0
- package/src/ui/dock.tsx +584 -0
- package/src/ui/dropdown.tsx +67 -23
- package/src/ui/hover-card.tsx +156 -6
- package/src/ui/icon.tsx +53 -0
- package/src/ui/input.tsx +275 -16
- package/src/ui/kbd.tsx +1 -1
- package/src/ui/nav.tsx +1 -1
- package/src/ui/pane-group.tsx +2 -2
- package/src/ui/radio.tsx +150 -0
- package/src/ui/resizable.tsx +11 -0
- package/src/ui/select.tsx +168 -0
- package/src/ui/slider.tsx +178 -0
- package/src/ui/switch.tsx +49 -18
- package/src/utils/cn.ts +11 -5
- package/src/wire/chunk.ts +47 -0
- package/src/wire/consume.ts +185 -26
- package/src/wire/diagnostics.ts +727 -0
- package/src/wire/encode-probe.ts +214 -0
- package/src/wire/encode.ts +267 -14
- package/src/wire/formats/anthropic.ts +8 -1
- package/src/wire/formats/openai.ts +5 -0
- package/src/wire/index.ts +22 -0
- package/src/wire/read.ts +250 -6
- package/src/wire/sse.ts +16 -3
- package/theme.css +84 -13
- package/dist/elements/chunks/action-icons-DW9muWrY.js +0 -1
- package/dist/elements/chunks/arrow-left-iJVnQmxA.js +0 -1
- package/dist/elements/chunks/artifact-BSuPYFHY.js +0 -1
- package/dist/elements/chunks/attachments-CL6TaqIb.js +0 -1
- package/dist/elements/chunks/audio-visualizer-BuUqQmaO.js +0 -1
- package/dist/elements/chunks/badge-TIMiJFKc.js +0 -1
- package/dist/elements/chunks/bash-InADTalH.js +0 -1
- package/dist/elements/chunks/card-renderer-CSoTL_e1.js +0 -1
- package/dist/elements/chunks/card-routing-BK09BdmL.js +0 -1
- package/dist/elements/chunks/chat-thread-DxoKaStk.js +0 -1
- package/dist/elements/chunks/check-MdLzbxrm.js +0 -1
- package/dist/elements/chunks/chevron-down-MK7IzDqe.js +0 -1
- package/dist/elements/chunks/chevron-right-C5jXhmtV.js +0 -1
- package/dist/elements/chunks/choice-card-CGMc3kek.js +0 -1
- package/dist/elements/chunks/circle-BG7VkPep.js +0 -1
- package/dist/elements/chunks/circle-check-GqvO2UBs.js +0 -1
- package/dist/elements/chunks/circle-x-mhH7pOK2.js +0 -1
- package/dist/elements/chunks/code-block-ClhQO9RW.js +0 -1
- package/dist/elements/chunks/collapsible-DBcBkFPh.js +0 -1
- package/dist/elements/chunks/composer-CZZmtYOT.js +0 -69
- package/dist/elements/chunks/confirm-card-BWjf2-xo.js +0 -1
- package/dist/elements/chunks/context-hKjNqiyQ.js +0 -1
- package/dist/elements/chunks/conversation-list-CsGJjSKG.js +0 -1
- package/dist/elements/chunks/core-AYMC6_lb.js +0 -12
- package/dist/elements/chunks/css-M7EaDHN_.js +0 -1
- package/dist/elements/chunks/default-input-B1Mem5wu.js +0 -1
- package/dist/elements/chunks/define-B_tXMYRm.js +0 -1
- package/dist/elements/chunks/disclosure-DAoYOKew.js +0 -1
- package/dist/elements/chunks/download-DnCyWFJE.js +0 -1
- package/dist/elements/chunks/dropdown-CmNna5lT.js +0 -1
- package/dist/elements/chunks/embed-CjAD2jSi.js +0 -1
- package/dist/elements/chunks/engine-javascript-vq0WuIJl.js +0 -141
- package/dist/elements/chunks/file-text-D0J9F6M7.js +0 -1
- package/dist/elements/chunks/folder-NV1pi_ud.js +0 -1
- package/dist/elements/chunks/form-Cp8Y00Wn.js +0 -1
- package/dist/elements/chunks/github-dark-dimmed-DUshB20C.js +0 -1
- package/dist/elements/chunks/github-light-JYsPkUQd.js +0 -1
- package/dist/elements/chunks/hover-card-6KtXpLwT.js +0 -1
- package/dist/elements/chunks/html-CPZ3oZQ7.js +0 -1
- package/dist/elements/chunks/icon-97R8SR2p.js +0 -1
- package/dist/elements/chunks/info-C8r5Q6cc.js +0 -1
- package/dist/elements/chunks/input-DrseEjhp.js +0 -1
- package/dist/elements/chunks/javascript-C25yR2R2.js +0 -1
- package/dist/elements/chunks/json-DxJze_jm.js +0 -1
- package/dist/elements/chunks/kbd-OGJDUT-O.js +0 -1
- package/dist/elements/chunks/link-BdsfLB7b.js +0 -1
- package/dist/elements/chunks/loader-B5QzK_8_.js +0 -1
- package/dist/elements/chunks/message-CE4k-qaj.js +0 -1
- package/dist/elements/chunks/message-DtXKPqiR.js +0 -1
- package/dist/elements/chunks/message-square-C9ovmtOo.js +0 -1
- package/dist/elements/chunks/paperclip-Bg0ITU3b.js +0 -1
- package/dist/elements/chunks/progress-bar-D1_rzt6N.js +0 -1
- package/dist/elements/chunks/prompt-suggestion-D5Sm8xF1.js +0 -1
- package/dist/elements/chunks/reasoning-BrxQfpfI.js +0 -1
- package/dist/elements/chunks/rotate-cw-DzVDJOA1.js +0 -1
- package/dist/elements/chunks/scroll-area-93A1bbeG.js +0 -1
- package/dist/elements/chunks/scroll-button-CrTo7wm4.js +0 -1
- package/dist/elements/chunks/share-DgNbkJKY.js +0 -1
- package/dist/elements/chunks/slots-CIw9RlAe.js +0 -1
- package/dist/elements/chunks/source-w9V0NnBn.js +0 -1
- package/dist/elements/chunks/star-DHvACxtm.js +0 -1
- package/dist/elements/chunks/store-HIPGhNz9.js +0 -1
- package/dist/elements/chunks/svelte--5p79yCD.js +0 -1
- package/dist/elements/chunks/tasks-card-lPxoodlA.js +0 -1
- package/dist/elements/chunks/text-shimmer-BY_rI3s5.js +0 -1
- package/dist/elements/chunks/textarea-DPfuhswM.js +0 -1
- package/dist/elements/chunks/toast-store-VUZZBhzH.js +0 -1
- package/dist/elements/chunks/tsx-B8rCNbgL.js +0 -1
- package/dist/elements/chunks/typescript-RycA9KXf.js +0 -1
- package/dist/elements/chunks/use-card-resolution-DJg32jGH.js +0 -1
- package/dist/elements/chunks/variant-custom-D5ZlmziF.js +0 -1
- package/dist/elements/chunks/video-Bb86fVYI.js +0 -1
- package/dist/elements/chunks/vue-BmIZj4XD.js +0 -1
- package/dist/elements/chunks/x-BOhjBeOd.js +0 -1
- package/dist/llms/llms-full.txt +0 -2834
- package/dist/llms/llms.txt +0 -156
- package/dist/primitives/card-validate-generator.testlib.d.ts +0 -20
- package/dist/register-impl-DGmGzrEM.js +0 -145
- package/dist/ui/stat.d.ts +0 -16
- package/dist/variant-custom-MkTNTycd.js +0 -1
- package/src/primitives/card-validate-generator.testlib.ts +0 -38
- package/src/ui/stat.tsx +0 -41
- /package/dist/{elements/chunks/card-tags-D8lZ-C_U.js → card-tags-D8lZ-C_U.js} +0 -0
- /package/dist/{elements/chunks/link-preview-DNILK391.js → link-preview-DNILK391.js} +0 -0
package/dist/wire.js
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
|
-
var
|
|
2
|
-
var
|
|
3
|
-
var
|
|
4
|
-
async function*
|
|
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:
|
|
10
|
-
if (
|
|
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
|
|
22
|
-
return typeof t.getReader == "function" ?
|
|
21
|
+
function bt(t) {
|
|
22
|
+
return typeof t.getReader == "function" ? kt(t) : t;
|
|
23
23
|
}
|
|
24
|
-
async function*
|
|
24
|
+
async function* wt(t) {
|
|
25
25
|
const e = new TextDecoder();
|
|
26
26
|
let n = "", o = [];
|
|
27
|
-
const
|
|
27
|
+
const s = () => {
|
|
28
28
|
if (o.length === 0) return;
|
|
29
29
|
const a = o.join(`
|
|
30
30
|
`);
|
|
31
31
|
return o = [], a;
|
|
32
|
-
},
|
|
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
|
|
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),
|
|
49
|
-
const d =
|
|
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 &&
|
|
57
|
-
const i =
|
|
56
|
+
n += e.decode(), n && r(n);
|
|
57
|
+
const i = s();
|
|
58
58
|
i !== void 0 && (yield i);
|
|
59
59
|
}
|
|
60
|
-
async function*
|
|
61
|
-
let
|
|
62
|
-
for await (const
|
|
63
|
-
if (!
|
|
64
|
-
if (
|
|
65
|
-
|
|
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
|
-
|
|
69
|
+
const s = JSON.parse(o);
|
|
70
|
+
e == null || e(o), yield s;
|
|
70
71
|
} catch {
|
|
71
72
|
}
|
|
72
73
|
}
|
|
73
74
|
}
|
|
74
|
-
function
|
|
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
|
|
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
|
|
84
|
-
return e.delete(o),
|
|
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
|
|
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
|
|
93
|
-
const o = n.index ?? 0,
|
|
94
|
-
(c) => c.type === "reasoning" && (c.index ?? 0) === o && c.streamId ===
|
|
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 (
|
|
97
|
-
return [...t, { type: "reasoning", text: e, index: o, streamId:
|
|
98
|
-
const i = t[
|
|
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
|
|
106
|
+
return Ot(i, a) ? t : [...t.slice(0, r), a, ...t.slice(r + 1)];
|
|
106
107
|
}
|
|
107
|
-
const
|
|
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
|
-
],
|
|
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
|
|
125
|
-
return
|
|
125
|
+
function Ot(t, e) {
|
|
126
|
+
return It.every((n) => At[n](t, e));
|
|
126
127
|
}
|
|
127
|
-
function
|
|
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 ??
|
|
137
|
+
return i.kind = i.kind ?? L(i.type), [...t, { type: "tool", tool: i }];
|
|
137
138
|
}
|
|
138
|
-
const
|
|
139
|
-
return
|
|
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
|
|
142
|
-
return e.kind !== void 0 ? e.kind : t.kind === void 0 || 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
|
|
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
|
-
],
|
|
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 ||
|
|
163
|
-
output: (t, e) => t.output === 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
|
|
166
|
-
return
|
|
166
|
+
function Ct(t, e) {
|
|
167
|
+
return Et.every((n) => $t[n](t, e));
|
|
167
168
|
}
|
|
168
|
-
const
|
|
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
|
|
185
|
+
function z(t) {
|
|
185
186
|
if (t)
|
|
186
|
-
return
|
|
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
|
-
|
|
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
|
-
}),
|
|
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
|
|
248
|
+
function Nt(t, e) {
|
|
198
249
|
return t.length <= e ? t : `${t.slice(0, e)}...`;
|
|
199
250
|
}
|
|
200
|
-
function
|
|
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
|
|
261
|
+
function Lt(t, e = {}) {
|
|
211
262
|
const n = /* @__PURE__ */ new Map(), o = (a) => {
|
|
212
|
-
const c = a.id, u = a.argumentsText, d =
|
|
263
|
+
const c = a.id, u = a.argumentsText, d = jt(u);
|
|
213
264
|
if (d) {
|
|
214
|
-
const
|
|
215
|
-
if (
|
|
216
|
-
a.lastInputFp =
|
|
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
|
-
},
|
|
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 &&
|
|
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
|
|
238
|
-
|
|
239
|
-
const d = u.id,
|
|
288
|
+
var h;
|
|
289
|
+
s(u);
|
|
290
|
+
const d = u.id, g = Dt(u);
|
|
240
291
|
if (u.providerExecuted)
|
|
241
292
|
return {
|
|
242
|
-
...
|
|
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
|
|
298
|
+
const f = Pt(u), p = u.name || "unknown_tool";
|
|
248
299
|
if (c) {
|
|
249
|
-
const
|
|
300
|
+
const m = `Stream failed before the tool call completed: ${c}`;
|
|
250
301
|
return t.upsertTool(d, {
|
|
251
|
-
type:
|
|
302
|
+
type: p,
|
|
252
303
|
state: "output-error",
|
|
253
|
-
errorText:
|
|
304
|
+
errorText: m,
|
|
254
305
|
rawInput: u.argumentsText,
|
|
255
|
-
raw:
|
|
256
|
-
}), { ...
|
|
306
|
+
raw: f
|
|
307
|
+
}), { ...g, error: m };
|
|
257
308
|
}
|
|
258
309
|
if (!u.name) {
|
|
259
|
-
const
|
|
260
|
-
return t.upsertTool(d, { state: "output-error", errorText:
|
|
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
|
|
313
|
+
const l = u.argumentsText.trim();
|
|
263
314
|
try {
|
|
264
|
-
const
|
|
265
|
-
if (
|
|
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
|
|
318
|
+
const v = m;
|
|
268
319
|
t.upsertTool(d, {
|
|
269
|
-
type:
|
|
320
|
+
type: p,
|
|
270
321
|
state: "input-available",
|
|
271
|
-
input:
|
|
322
|
+
input: v,
|
|
272
323
|
rawInput: u.argumentsText,
|
|
273
|
-
raw:
|
|
324
|
+
raw: f
|
|
274
325
|
});
|
|
275
|
-
const
|
|
276
|
-
return (
|
|
277
|
-
} catch (
|
|
278
|
-
const
|
|
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:
|
|
331
|
+
type: p,
|
|
281
332
|
state: "output-error",
|
|
282
|
-
errorText:
|
|
333
|
+
errorText: k,
|
|
283
334
|
rawInput: u.argumentsText,
|
|
284
|
-
raw:
|
|
285
|
-
}), { ...
|
|
335
|
+
raw: f
|
|
336
|
+
}), { ...g, error: k };
|
|
286
337
|
}
|
|
287
338
|
}) };
|
|
288
339
|
}
|
|
289
|
-
function
|
|
290
|
-
let
|
|
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(
|
|
293
|
-
|
|
361
|
+
appendText(s) {
|
|
362
|
+
const r = e;
|
|
363
|
+
e = Tt(e, s), o("text", r, s.length, () => ({ delta: s }));
|
|
294
364
|
},
|
|
295
|
-
appendReasoning(
|
|
296
|
-
|
|
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(
|
|
299
|
-
|
|
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(
|
|
302
|
-
|
|
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: () =>
|
|
377
|
+
parts: () => e,
|
|
378
|
+
partCounts: () => n
|
|
305
379
|
};
|
|
306
380
|
}
|
|
307
|
-
function
|
|
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,
|
|
320
|
-
(o = t.addSource) == null || o.call(t, 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
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
const
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
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 (
|
|
337
|
-
const
|
|
338
|
-
|
|
339
|
-
index:
|
|
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:
|
|
414
|
+
streamId: s,
|
|
343
415
|
label: o,
|
|
344
|
-
...
|
|
345
|
-
...
|
|
416
|
+
...y.reasoningRaw ? { raw: y.reasoningRaw } : {},
|
|
417
|
+
...y.reasoningSignature ? { signature: y.reasoningSignature } : {}
|
|
346
418
|
});
|
|
347
419
|
}
|
|
348
|
-
if (
|
|
349
|
-
if (
|
|
350
|
-
for (const
|
|
351
|
-
|
|
352
|
-
|
|
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
|
|
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
|
|
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:
|
|
361
|
-
text:
|
|
362
|
-
reasoning:
|
|
363
|
-
toolCalls:
|
|
364
|
-
sources:
|
|
365
|
-
finishReason:
|
|
366
|
-
reasoningChunks:
|
|
367
|
-
chunks:
|
|
368
|
-
...
|
|
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
|
-
...
|
|
481
|
+
...m ? { usage: m } : {}
|
|
371
482
|
};
|
|
372
483
|
}
|
|
373
|
-
function
|
|
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
|
|
383
|
-
if (!
|
|
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
|
|
389
|
-
|
|
390
|
-
const
|
|
391
|
-
if (
|
|
392
|
-
const c = I(
|
|
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 (
|
|
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
|
|
404
|
-
if (!
|
|
405
|
-
const n =
|
|
406
|
-
|
|
407
|
-
const
|
|
408
|
-
|
|
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
|
|
523
|
+
function Jt(t) {
|
|
413
524
|
let e = "";
|
|
414
525
|
for (const n of t) {
|
|
415
|
-
if (!
|
|
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
|
|
532
|
+
function Q(t, e) {
|
|
422
533
|
for (const n of t)
|
|
423
|
-
if (
|
|
534
|
+
if (w(n) && n[e] !== void 0) return n[e];
|
|
424
535
|
}
|
|
425
|
-
const
|
|
426
|
-
function
|
|
427
|
-
for (const e of
|
|
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
|
|
433
|
-
const n = Array.isArray(t.reasoning_details) ? t.reasoning_details : void 0, o =
|
|
434
|
-
if (i === void 0 && !
|
|
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(
|
|
547
|
+
const a = I(Q(n, "index"));
|
|
437
548
|
a !== void 0 && (e.reasoningIndex = a);
|
|
438
|
-
const c = b(
|
|
549
|
+
const c = b(Q(n, "signature"));
|
|
439
550
|
c !== void 0 && (e.reasoningSignature = c);
|
|
440
551
|
}
|
|
441
|
-
function
|
|
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 (!
|
|
446
|
-
const o =
|
|
447
|
-
if (!
|
|
448
|
-
const
|
|
449
|
-
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 && (
|
|
562
|
+
a && (r.snippet = a), e.push(r);
|
|
452
563
|
}
|
|
453
564
|
return e;
|
|
454
565
|
}
|
|
455
|
-
function
|
|
456
|
-
if (!
|
|
566
|
+
function zt(t) {
|
|
567
|
+
if (!w(t)) return [];
|
|
457
568
|
const e = {}, n = t.error;
|
|
458
|
-
if (
|
|
459
|
-
const
|
|
460
|
-
if (
|
|
461
|
-
e.error = { message:
|
|
462
|
-
const
|
|
463
|
-
(typeof
|
|
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 =
|
|
467
|
-
o && (e.
|
|
468
|
-
const
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
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
|
|
478
|
-
|
|
590
|
+
const d = Yt(a);
|
|
591
|
+
d.length > 0 && (e.sources = d);
|
|
479
592
|
}
|
|
480
|
-
const
|
|
481
|
-
|
|
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
|
|
598
|
+
const Qt = {
|
|
486
599
|
id: "openai.chat-completions",
|
|
487
600
|
open() {
|
|
488
|
-
return { push:
|
|
601
|
+
return { push: zt };
|
|
489
602
|
}
|
|
490
603
|
};
|
|
491
|
-
function
|
|
604
|
+
function _(t) {
|
|
492
605
|
return typeof t == "object" && t !== null && !Array.isArray(t);
|
|
493
606
|
}
|
|
494
|
-
function
|
|
607
|
+
function x(t) {
|
|
495
608
|
return typeof t == "string" ? t : void 0;
|
|
496
609
|
}
|
|
497
|
-
function
|
|
610
|
+
function E(t) {
|
|
498
611
|
return typeof t == "number" ? t : void 0;
|
|
499
612
|
}
|
|
500
|
-
function
|
|
501
|
-
if (!
|
|
502
|
-
const e = {}, n =
|
|
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 =
|
|
617
|
+
const o = E(t.output_tokens);
|
|
505
618
|
o !== void 0 && (e.outputTokens = o);
|
|
506
|
-
const
|
|
507
|
-
return
|
|
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
|
|
510
|
-
const o =
|
|
511
|
-
if (!
|
|
512
|
-
switch (
|
|
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
|
|
516
|
-
return
|
|
628
|
+
const r = x(s.text);
|
|
629
|
+
return r ? [{ text: r }] : [];
|
|
517
630
|
}
|
|
518
631
|
case "thinking": {
|
|
519
|
-
const
|
|
520
|
-
return e.set(o, { kind: "thinking", thinking:
|
|
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:
|
|
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
|
|
533
|
-
return e.set(o, { kind: "tool_use", thinking: "" }),
|
|
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
|
|
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 =
|
|
540
|
-
return
|
|
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
|
-
...
|
|
546
|
-
outputError:
|
|
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, ...
|
|
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
|
|
563
|
-
const n =
|
|
564
|
-
if (!
|
|
565
|
-
switch (
|
|
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
|
|
568
|
-
return
|
|
680
|
+
const s = x(o.text);
|
|
681
|
+
return s ? [{ text: s }] : [];
|
|
569
682
|
}
|
|
570
683
|
case "thinking_delta": {
|
|
571
|
-
const
|
|
572
|
-
return
|
|
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
|
|
576
|
-
return
|
|
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:
|
|
692
|
+
return [{ toolCalls: [{ index: n, arguments: x(o.partial_json) ?? "" }] }];
|
|
580
693
|
case "citations_delta": {
|
|
581
|
-
const
|
|
582
|
-
if (!
|
|
583
|
-
const
|
|
584
|
-
i && (
|
|
585
|
-
const a =
|
|
586
|
-
a && (
|
|
587
|
-
const c =
|
|
588
|
-
return c && (
|
|
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
|
|
595
|
-
const 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
|
|
598
|
-
return o.signature !== void 0 && (
|
|
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:
|
|
715
|
+
reasoningRaw: { source: "anthropic.content_block", payload: s }
|
|
603
716
|
}
|
|
604
717
|
];
|
|
605
718
|
}
|
|
606
|
-
function
|
|
719
|
+
function te(t) {
|
|
607
720
|
const e = {}, n = t.delta;
|
|
608
|
-
if (
|
|
609
|
-
const
|
|
610
|
-
|
|
721
|
+
if (_(n)) {
|
|
722
|
+
const s = x(n.stop_reason);
|
|
723
|
+
s && (e.finishReason = s);
|
|
611
724
|
}
|
|
612
|
-
const o =
|
|
725
|
+
const o = ct(t.usage);
|
|
613
726
|
return o && (e.usage = o), Object.keys(e).length > 0 ? [e] : [];
|
|
614
727
|
}
|
|
615
|
-
function
|
|
616
|
-
const e = t.error, n =
|
|
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
|
|
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 (!
|
|
633
|
-
switch (
|
|
745
|
+
if (!_(n)) return [];
|
|
746
|
+
switch (x(n.type)) {
|
|
634
747
|
case "message_start": {
|
|
635
748
|
const o = n.message;
|
|
636
|
-
if (!
|
|
637
|
-
const r =
|
|
638
|
-
|
|
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
|
|
756
|
+
return Xt(n, t, e);
|
|
642
757
|
case "content_block_delta":
|
|
643
|
-
return
|
|
758
|
+
return Vt(n, t);
|
|
644
759
|
case "content_block_stop":
|
|
645
|
-
return
|
|
760
|
+
return Zt(n, t);
|
|
646
761
|
case "message_delta":
|
|
647
|
-
return
|
|
762
|
+
return te(n);
|
|
648
763
|
case "error":
|
|
649
|
-
return
|
|
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
|
-
|
|
658
|
-
|
|
659
|
-
|
|
660
|
-
|
|
661
|
-
|
|
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
|
-
|
|
801
|
+
S(this, "body");
|
|
665
802
|
/** The raw response body, always. */
|
|
666
|
-
|
|
667
|
-
Object.setPrototypeOf(this,
|
|
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
|
|
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
|
|
682
|
-
|
|
683
|
-
|
|
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 ? `${
|
|
832
|
+
return i ? `${s}: ${i}` : s;
|
|
686
833
|
}
|
|
687
|
-
function
|
|
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
|
|
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
|
|
849
|
+
return new B(t.status, t.statusText, e, n);
|
|
699
850
|
}
|
|
700
|
-
async function
|
|
701
|
-
if (!
|
|
702
|
-
if (!t.ok)
|
|
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
|
|
710
|
-
const o =
|
|
711
|
-
|
|
712
|
-
|
|
713
|
-
|
|
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
|
|
718
|
-
return
|
|
952
|
+
function Ce(t, e, n = {}) {
|
|
953
|
+
return dt(t, e, { ...n, format: Qt });
|
|
719
954
|
}
|
|
720
|
-
function
|
|
721
|
-
return
|
|
955
|
+
function Ue(t, e, n = {}) {
|
|
956
|
+
return dt(t, e, { ...n, format: ne });
|
|
722
957
|
}
|
|
723
|
-
function
|
|
958
|
+
function De(t, e, n) {
|
|
724
959
|
t.upsertTool(e, { state: "output-available", output: n });
|
|
725
960
|
}
|
|
726
|
-
function
|
|
961
|
+
function Pe(t, e, n) {
|
|
727
962
|
t.upsertTool(e, { state: "output-error", errorText: n });
|
|
728
963
|
}
|
|
729
|
-
function
|
|
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
|
|
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
|
-
],
|
|
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
|
-
},
|
|
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
|
-
},
|
|
764
|
-
const [n, o] =
|
|
765
|
-
return n !== "*" && n !==
|
|
766
|
-
},
|
|
767
|
-
if (
|
|
768
|
-
if (
|
|
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
|
|
771
|
-
return
|
|
1005
|
+
function je() {
|
|
1006
|
+
return F.map((t) => t.pattern);
|
|
772
1007
|
}
|
|
773
|
-
function
|
|
774
|
-
const e = t.accept === void 0 ? void 0 :
|
|
775
|
-
for (const o of
|
|
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
|
|
781
|
-
const
|
|
782
|
-
|
|
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
|
|
790
|
-
if (
|
|
791
|
-
return n.some((i) =>
|
|
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
|
|
799
|
-
return
|
|
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
|
|
804
|
-
function
|
|
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
|
|
814
|
-
function
|
|
815
|
-
const e =
|
|
1048
|
+
const nt = (t) => t.replace(/&/g, "&").replace(/</g, "<").replace(/>/g, ">").replace(/"/g, """).replace(/\r/g, " ").replace(/\n/g, " "), ye = /<(\/file\s*)>/gi;
|
|
1049
|
+
function pt(t) {
|
|
1050
|
+
const e = nt(t.filename ?? "attachment"), n = nt(t.mediaType), o = t.text.replace(ye, "<$1>");
|
|
816
1051
|
return `<file name="${e}" type="${n}">
|
|
817
1052
|
${o}
|
|
818
1053
|
</file>`;
|
|
819
1054
|
}
|
|
820
|
-
function
|
|
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,
|
|
830
|
-
const
|
|
831
|
-
if (
|
|
832
|
-
const d =
|
|
833
|
-
|
|
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
|
-
|
|
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 =
|
|
850
|
-
return { status: "unencodable", reason: `its \`url\` is "${n}": ${
|
|
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(
|
|
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 "${
|
|
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 =
|
|
1095
|
+
const d = et(o.data);
|
|
861
1096
|
return d.ok ? {
|
|
862
1097
|
status: "encodable",
|
|
863
1098
|
file: {
|
|
864
1099
|
kind: "text",
|
|
865
|
-
mediaType:
|
|
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 -- ${
|
|
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 "${
|
|
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 "${
|
|
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 =
|
|
1126
|
+
const d = et(o.data);
|
|
892
1127
|
return d.ok ? {
|
|
893
1128
|
status: "encodable",
|
|
894
1129
|
file: {
|
|
895
1130
|
kind: "text",
|
|
896
|
-
mediaType:
|
|
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 "${
|
|
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:
|
|
1143
|
+
file: { kind: i.kind, mediaType: s, source: o, filename: t.filename }
|
|
909
1144
|
};
|
|
910
1145
|
}
|
|
911
|
-
|
|
912
|
-
|
|
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
|
-
|
|
915
|
-
|
|
916
|
-
Object.setPrototypeOf(this,
|
|
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
|
|
920
|
-
function
|
|
921
|
-
const
|
|
922
|
-
if (
|
|
923
|
-
|
|
924
|
-
|
|
925
|
-
|
|
926
|
-
|
|
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 (
|
|
932
|
-
const
|
|
933
|
-
return
|
|
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
|
-
|
|
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
|
-
},
|
|
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
|
-
},
|
|
954
|
-
function
|
|
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
|
|
1296
|
+
const Ie = (t) => ({
|
|
958
1297
|
id: t.toolCallId,
|
|
959
1298
|
type: "function",
|
|
960
|
-
function: { name: t.type, arguments:
|
|
961
|
-
}),
|
|
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
|
-
}),
|
|
967
|
-
function
|
|
968
|
-
var
|
|
969
|
-
if (((
|
|
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(
|
|
973
|
-
return
|
|
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
|
|
976
|
-
const e =
|
|
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",
|
|
981
|
-
return typeof e.format == "string" && (
|
|
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
|
|
984
|
-
const n = e.reasoning === "include", o = e.onUnencodableFile ?? "throw",
|
|
985
|
-
|
|
986
|
-
|
|
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
|
|
989
|
-
const
|
|
990
|
-
|
|
1330
|
+
let h = "", m = !1;
|
|
1331
|
+
const v = () => {
|
|
1332
|
+
h !== "" && (l.push({ type: "text", text: h }), h = "");
|
|
991
1333
|
};
|
|
992
|
-
if (
|
|
993
|
-
if (
|
|
994
|
-
|
|
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 (
|
|
998
|
-
|
|
999
|
-
|
|
1000
|
-
|
|
1001
|
-
|
|
1002
|
-
|
|
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
|
-
|
|
1365
|
+
r.push({ role: "user", content: l });
|
|
1006
1366
|
continue;
|
|
1007
1367
|
}
|
|
1008
|
-
let
|
|
1009
|
-
const
|
|
1010
|
-
if (!(
|
|
1011
|
-
|
|
1368
|
+
let u = "", d = [], g = [];
|
|
1369
|
+
const f = () => {
|
|
1370
|
+
if (!(u === "" && d.length === 0)) {
|
|
1371
|
+
r.push({
|
|
1012
1372
|
role: "assistant",
|
|
1013
|
-
content:
|
|
1014
|
-
...
|
|
1015
|
-
...
|
|
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
|
|
1018
|
-
|
|
1377
|
+
for (const l of d) r.push(Ae(l));
|
|
1378
|
+
u = "", d = [], g = [];
|
|
1019
1379
|
}
|
|
1020
1380
|
};
|
|
1021
|
-
|
|
1022
|
-
|
|
1023
|
-
|
|
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)
|
|
1028
|
-
|
|
1029
|
-
|
|
1030
|
-
|
|
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"
|
|
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
|
-
|
|
1431
|
+
f();
|
|
1036
1432
|
}
|
|
1037
|
-
return
|
|
1433
|
+
return i == null || i.finish("openai", t.length, r), r;
|
|
1038
1434
|
}
|
|
1039
|
-
function
|
|
1040
|
-
const n = e.onUnencodableFile ?? "throw", o =
|
|
1041
|
-
|
|
1042
|
-
(
|
|
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
|
-
|
|
1045
|
-
|
|
1046
|
-
|
|
1047
|
-
|
|
1048
|
-
|
|
1049
|
-
|
|
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
|
-
|
|
1053
|
-
|
|
1054
|
-
|
|
1055
|
-
|
|
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
|
|
1059
|
-
const
|
|
1060
|
-
|
|
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
|
-
|
|
1063
|
-
switch (
|
|
1480
|
+
c.parts.forEach((f, p) => {
|
|
1481
|
+
switch (f.type) {
|
|
1064
1482
|
case "reasoning": {
|
|
1065
|
-
if (!
|
|
1066
|
-
throw new
|
|
1067
|
-
`Cannot encode reasoning part ${
|
|
1068
|
-
|
|
1069
|
-
|
|
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 (!
|
|
1072
|
-
throw new
|
|
1073
|
-
`Cannot encode reasoning part ${
|
|
1074
|
-
|
|
1075
|
-
|
|
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
|
-
|
|
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 (
|
|
1082
|
-
|
|
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
|
|
1087
|
-
if (!
|
|
1088
|
-
|
|
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:
|
|
1091
|
-
name:
|
|
1092
|
-
input:
|
|
1093
|
-
}),
|
|
1094
|
-
|
|
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:
|
|
1523
|
+
tool_use_id: l.toolCallId,
|
|
1097
1524
|
is_error: !0,
|
|
1098
|
-
content:
|
|
1525
|
+
content: l.errorText
|
|
1099
1526
|
} : {
|
|
1100
1527
|
type: "tool_result",
|
|
1101
|
-
tool_use_id:
|
|
1102
|
-
content: JSON.stringify(
|
|
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
|
-
}),
|
|
1544
|
+
}), g();
|
|
1109
1545
|
}
|
|
1110
|
-
return r;
|
|
1546
|
+
return r == null || r.finish("anthropic", t.length, s), s;
|
|
1111
1547
|
}
|
|
1112
1548
|
export {
|
|
1113
|
-
|
|
1114
|
-
|
|
1115
|
-
|
|
1116
|
-
|
|
1117
|
-
|
|
1118
|
-
|
|
1119
|
-
|
|
1120
|
-
|
|
1121
|
-
|
|
1122
|
-
|
|
1123
|
-
|
|
1124
|
-
|
|
1125
|
-
|
|
1126
|
-
|
|
1127
|
-
|
|
1128
|
-
|
|
1129
|
-
|
|
1130
|
-
|
|
1131
|
-
|
|
1132
|
-
|
|
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
|
};
|