@schlessera/brain-ui-react 0.35.0 → 0.37.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 +82 -4
- package/dist/components/activity/activity-page.d.ts +17 -5
- package/dist/components/activity/activity-page.d.ts.map +1 -1
- package/dist/components/activity/activity-page.js +148 -50
- package/dist/components/activity/activity-page.js.map +1 -1
- package/dist/components/activity/activity-run-detail.d.ts +16 -1
- package/dist/components/activity/activity-run-detail.d.ts.map +1 -1
- package/dist/components/activity/activity-run-detail.js +47 -4
- package/dist/components/activity/activity-run-detail.js.map +1 -1
- package/dist/components/activity/activity-run-list.d.ts +7 -1
- package/dist/components/activity/activity-run-list.d.ts.map +1 -1
- package/dist/components/activity/activity-run-list.js +16 -8
- package/dist/components/activity/activity-run-list.js.map +1 -1
- package/dist/components/activity/activity-views.d.ts +63 -0
- package/dist/components/activity/activity-views.d.ts.map +1 -0
- package/dist/components/activity/activity-views.js +52 -0
- package/dist/components/activity/activity-views.js.map +1 -0
- package/dist/components/activity/approval-card.d.ts +29 -0
- package/dist/components/activity/approval-card.d.ts.map +1 -0
- package/dist/components/activity/approval-card.js +73 -0
- package/dist/components/activity/approval-card.js.map +1 -0
- package/dist/components/activity/digest-card.d.ts +3 -0
- package/dist/components/activity/digest-card.d.ts.map +1 -1
- package/dist/components/activity/digest-card.js +20 -16
- package/dist/components/activity/digest-card.js.map +1 -1
- package/dist/components/activity/digest-summary.d.ts +19 -0
- package/dist/components/activity/digest-summary.d.ts.map +1 -0
- package/dist/components/activity/digest-summary.js +20 -0
- package/dist/components/activity/digest-summary.js.map +1 -0
- package/dist/components/activity/push-switch.d.ts +25 -0
- package/dist/components/activity/push-switch.d.ts.map +1 -0
- package/dist/components/activity/push-switch.js +14 -0
- package/dist/components/activity/push-switch.js.map +1 -0
- package/dist/components/activity/push-toggle.d.ts +7 -0
- package/dist/components/activity/push-toggle.d.ts.map +1 -1
- package/dist/components/activity/push-toggle.js +72 -47
- package/dist/components/activity/push-toggle.js.map +1 -1
- package/dist/components/activity/span-bits.d.ts +11 -0
- package/dist/components/activity/span-bits.d.ts.map +1 -1
- package/dist/components/activity/span-bits.js +50 -7
- package/dist/components/activity/span-bits.js.map +1 -1
- package/dist/components/chat/ask-user-card.d.ts +76 -3
- package/dist/components/chat/ask-user-card.d.ts.map +1 -1
- package/dist/components/chat/ask-user-card.js +208 -149
- package/dist/components/chat/ask-user-card.js.map +1 -1
- package/dist/components/chat/ask-user-typed.d.ts +42 -0
- package/dist/components/chat/ask-user-typed.d.ts.map +1 -0
- package/dist/components/chat/ask-user-typed.js +60 -0
- package/dist/components/chat/ask-user-typed.js.map +1 -0
- package/dist/components/chat/brain-markdown-links.d.ts +2 -1
- package/dist/components/chat/brain-markdown-links.d.ts.map +1 -1
- package/dist/components/chat/brain-markdown-links.js +3 -4
- package/dist/components/chat/brain-markdown-links.js.map +1 -1
- package/dist/components/chat/brain-markdown.d.ts.map +1 -1
- package/dist/components/chat/brain-markdown.js +4 -2
- package/dist/components/chat/brain-markdown.js.map +1 -1
- package/dist/components/chat/chat-page.d.ts.map +1 -1
- package/dist/components/chat/chat-page.js +27 -11
- package/dist/components/chat/chat-page.js.map +1 -1
- package/dist/components/chat/composer-view.d.ts +75 -0
- package/dist/components/chat/composer-view.d.ts.map +1 -0
- package/dist/components/chat/composer-view.js +31 -0
- package/dist/components/chat/composer-view.js.map +1 -0
- package/dist/components/chat/composer.d.ts +4 -0
- package/dist/components/chat/composer.d.ts.map +1 -1
- package/dist/components/chat/composer.js +76 -59
- package/dist/components/chat/composer.js.map +1 -1
- package/dist/components/chat/markdown-content.d.ts +16 -1
- package/dist/components/chat/markdown-content.d.ts.map +1 -1
- package/dist/components/chat/markdown-content.js +47 -3
- package/dist/components/chat/markdown-content.js.map +1 -1
- package/dist/components/chat/mermaid-block.d.ts +4 -0
- package/dist/components/chat/mermaid-block.d.ts.map +1 -1
- package/dist/components/chat/mermaid-block.js +13 -5
- package/dist/components/chat/mermaid-block.js.map +1 -1
- package/dist/components/chat/mermaid-share.d.ts +2 -1
- package/dist/components/chat/mermaid-share.d.ts.map +1 -1
- package/dist/components/chat/mermaid-share.js +7 -8
- package/dist/components/chat/mermaid-share.js.map +1 -1
- package/dist/components/chat/mermaid-viewer.d.ts.map +1 -1
- package/dist/components/chat/mermaid-viewer.js +3 -1
- package/dist/components/chat/mermaid-viewer.js.map +1 -1
- package/dist/components/chat/message-bubble.d.ts +8 -1
- package/dist/components/chat/message-bubble.d.ts.map +1 -1
- package/dist/components/chat/message-bubble.js +53 -24
- package/dist/components/chat/message-bubble.js.map +1 -1
- package/dist/components/chat/message-share.d.ts +2 -1
- package/dist/components/chat/message-share.d.ts.map +1 -1
- package/dist/components/chat/message-share.js +6 -7
- package/dist/components/chat/message-share.js.map +1 -1
- package/dist/components/chat/renderers/bind.d.ts +39 -0
- package/dist/components/chat/renderers/bind.d.ts.map +1 -0
- package/dist/components/chat/renderers/bind.js +43 -0
- package/dist/components/chat/renderers/bind.js.map +1 -0
- package/dist/components/chat/renderers/brain-ui-tools.d.ts +3 -0
- package/dist/components/chat/renderers/brain-ui-tools.d.ts.map +1 -0
- package/dist/components/chat/renderers/brain-ui-tools.js +41 -0
- package/dist/components/chat/renderers/brain-ui-tools.js.map +1 -0
- package/dist/components/chat/renderers/claude-tools.d.ts.map +1 -1
- package/dist/components/chat/renderers/claude-tools.js +3 -2
- package/dist/components/chat/renderers/claude-tools.js.map +1 -1
- package/dist/components/chat/renderers/index.d.ts +10 -2
- package/dist/components/chat/renderers/index.d.ts.map +1 -1
- package/dist/components/chat/renderers/index.js +15 -10
- package/dist/components/chat/renderers/index.js.map +1 -1
- package/dist/components/chat/session-drawer.d.ts +4 -0
- package/dist/components/chat/session-drawer.d.ts.map +1 -1
- package/dist/components/chat/session-drawer.js +32 -32
- package/dist/components/chat/session-drawer.js.map +1 -1
- package/dist/components/chat/session-list.d.ts +41 -0
- package/dist/components/chat/session-list.d.ts.map +1 -0
- package/dist/components/chat/session-list.js +10 -0
- package/dist/components/chat/session-list.js.map +1 -0
- package/dist/components/chat/share-block.d.ts.map +1 -1
- package/dist/components/chat/share-block.js +12 -11
- package/dist/components/chat/share-block.js.map +1 -1
- package/dist/components/chat/share-card.js +2 -2
- package/dist/components/chat/share-card.js.map +1 -1
- package/dist/components/chat/subagent-view.js +1 -1
- package/dist/components/chat/subagent-view.js.map +1 -1
- package/dist/components/chat/tool-call-timeline.d.ts.map +1 -1
- package/dist/components/chat/tool-call-timeline.js +45 -14
- package/dist/components/chat/tool-call-timeline.js.map +1 -1
- package/dist/components/chat/tool-cards/block-card.d.ts +28 -0
- package/dist/components/chat/tool-cards/block-card.d.ts.map +1 -0
- package/dist/components/chat/tool-cards/block-card.js +103 -0
- package/dist/components/chat/tool-cards/block-card.js.map +1 -0
- package/dist/components/chat/tool-cards/image-mask-card.d.ts +70 -0
- package/dist/components/chat/tool-cards/image-mask-card.d.ts.map +1 -0
- package/dist/components/chat/tool-cards/image-mask-card.js +142 -0
- package/dist/components/chat/tool-cards/image-mask-card.js.map +1 -0
- package/dist/components/chat/tool-cards/location-card.d.ts +45 -0
- package/dist/components/chat/tool-cards/location-card.d.ts.map +1 -0
- package/dist/components/chat/tool-cards/location-card.js +128 -0
- package/dist/components/chat/tool-cards/location-card.js.map +1 -0
- package/dist/components/chat/tool-views.d.ts +19 -2
- package/dist/components/chat/tool-views.d.ts.map +1 -1
- package/dist/components/chat/tool-views.js +28 -22
- package/dist/components/chat/tool-views.js.map +1 -1
- package/dist/components/chat/transcript-turn.d.ts +45 -0
- package/dist/components/chat/transcript-turn.d.ts.map +1 -0
- package/dist/components/chat/transcript-turn.js +25 -0
- package/dist/components/chat/transcript-turn.js.map +1 -0
- package/dist/components/chat/use-chat-commands.d.ts.map +1 -1
- package/dist/components/chat/use-chat-commands.js +13 -16
- package/dist/components/chat/use-chat-commands.js.map +1 -1
- package/dist/components/chat/welcome-state.d.ts +7 -0
- package/dist/components/chat/welcome-state.d.ts.map +1 -1
- package/dist/components/chat/welcome-state.js +13 -5
- package/dist/components/chat/welcome-state.js.map +1 -1
- package/dist/components/connectivity/connection-gate.d.ts.map +1 -1
- package/dist/components/connectivity/connection-gate.js +27 -21
- package/dist/components/connectivity/connection-gate.js.map +1 -1
- package/dist/components/connectivity/login-form.d.ts +31 -0
- package/dist/components/connectivity/login-form.d.ts.map +1 -0
- package/dist/components/connectivity/login-form.js +19 -0
- package/dist/components/connectivity/login-form.js.map +1 -0
- package/dist/components/connectivity/login-screen.d.ts +5 -2
- package/dist/components/connectivity/login-screen.d.ts.map +1 -1
- package/dist/components/connectivity/login-screen.js +41 -31
- package/dist/components/connectivity/login-screen.js.map +1 -1
- package/dist/components/dev/share-harness.js +1 -1
- package/dist/components/dev/share-harness.js.map +1 -1
- package/dist/components/files/file-panel.d.ts +1 -1
- package/dist/components/files/file-panel.d.ts.map +1 -1
- package/dist/components/files/file-panel.js +74 -0
- package/dist/components/files/file-panel.js.map +1 -1
- package/dist/components/files/file-tree-view.d.ts +45 -0
- package/dist/components/files/file-tree-view.d.ts.map +1 -0
- package/dist/components/files/file-tree-view.js +51 -0
- package/dist/components/files/file-tree-view.js.map +1 -0
- package/dist/components/files/file-tree.d.ts +6 -0
- package/dist/components/files/file-tree.d.ts.map +1 -1
- package/dist/components/files/file-tree.js +39 -43
- package/dist/components/files/file-tree.js.map +1 -1
- package/dist/components/files/file-viewer-binary.d.ts.map +1 -1
- package/dist/components/files/file-viewer-binary.js +3 -2
- package/dist/components/files/file-viewer-binary.js.map +1 -1
- package/dist/components/files/file-viewer-frame.d.ts +36 -0
- package/dist/components/files/file-viewer-frame.d.ts.map +1 -0
- package/dist/components/files/file-viewer-frame.js +26 -0
- package/dist/components/files/file-viewer-frame.js.map +1 -0
- package/dist/components/files/file-viewer.d.ts +5 -0
- package/dist/components/files/file-viewer.d.ts.map +1 -1
- package/dist/components/files/file-viewer.js +26 -32
- package/dist/components/files/file-viewer.js.map +1 -1
- package/dist/components/files/frontmatter-chips.d.ts +18 -0
- package/dist/components/files/frontmatter-chips.d.ts.map +1 -0
- package/dist/components/files/frontmatter-chips.js +11 -0
- package/dist/components/files/frontmatter-chips.js.map +1 -0
- package/dist/components/files/frontmatter-panel.d.ts +5 -1
- package/dist/components/files/frontmatter-panel.d.ts.map +1 -1
- package/dist/components/files/frontmatter-panel.js +7 -6
- package/dist/components/files/frontmatter-panel.js.map +1 -1
- package/dist/components/files/staleness.d.ts +18 -0
- package/dist/components/files/staleness.d.ts.map +1 -0
- package/dist/components/files/staleness.js +27 -0
- package/dist/components/files/staleness.js.map +1 -0
- package/dist/components/graph/graph-canvas.d.ts.map +1 -1
- package/dist/components/graph/graph-canvas.js +24 -1
- package/dist/components/graph/graph-canvas.js.map +1 -1
- package/dist/components/graph/graph-controls-column.d.ts +14 -0
- package/dist/components/graph/graph-controls-column.d.ts.map +1 -0
- package/dist/components/graph/graph-controls-column.js +44 -0
- package/dist/components/graph/graph-controls-column.js.map +1 -0
- package/dist/components/graph/graph-controls.d.ts +20 -5
- package/dist/components/graph/graph-controls.d.ts.map +1 -1
- package/dist/components/graph/graph-controls.js +58 -37
- package/dist/components/graph/graph-controls.js.map +1 -1
- package/dist/components/graph/graph-form.d.ts +82 -0
- package/dist/components/graph/graph-form.d.ts.map +1 -0
- package/dist/components/graph/graph-form.js +69 -0
- package/dist/components/graph/graph-form.js.map +1 -0
- package/dist/components/graph/graph-maintenance.d.ts.map +1 -1
- package/dist/components/graph/graph-maintenance.js +6 -10
- package/dist/components/graph/graph-maintenance.js.map +1 -1
- package/dist/components/graph/graph-node-rail.d.ts +13 -0
- package/dist/components/graph/graph-node-rail.d.ts.map +1 -0
- package/dist/components/graph/graph-node-rail.js +92 -0
- package/dist/components/graph/graph-node-rail.js.map +1 -0
- package/dist/components/graph/graph-page.d.ts +7 -0
- package/dist/components/graph/graph-page.d.ts.map +1 -1
- package/dist/components/graph/graph-page.js +102 -12
- package/dist/components/graph/graph-page.js.map +1 -1
- package/dist/components/graph/graph-scene.d.ts.map +1 -1
- package/dist/components/graph/graph-scene.js +100 -24
- package/dist/components/graph/graph-scene.js.map +1 -1
- package/dist/components/graph/lib/graph-helpers.d.ts +42 -12
- package/dist/components/graph/lib/graph-helpers.d.ts.map +1 -1
- package/dist/components/graph/lib/graph-helpers.js +33 -41
- package/dist/components/graph/lib/graph-helpers.js.map +1 -1
- package/dist/components/graph/node-card.d.ts +28 -0
- package/dist/components/graph/node-card.d.ts.map +1 -0
- package/dist/components/graph/node-card.js +7 -0
- package/dist/components/graph/node-card.js.map +1 -0
- package/dist/components/graph/node-popover.d.ts +6 -2
- package/dist/components/graph/node-popover.d.ts.map +1 -1
- package/dist/components/graph/node-popover.js +13 -31
- package/dist/components/graph/node-popover.js.map +1 -1
- package/dist/components/graph/use-graph-theme.d.ts +32 -4
- package/dist/components/graph/use-graph-theme.d.ts.map +1 -1
- package/dist/components/graph/use-graph-theme.js +44 -32
- package/dist/components/graph/use-graph-theme.js.map +1 -1
- package/dist/components/graph/use-node-actions.d.ts +26 -0
- package/dist/components/graph/use-node-actions.d.ts.map +1 -0
- package/dist/components/graph/use-node-actions.js +54 -0
- package/dist/components/graph/use-node-actions.js.map +1 -0
- package/dist/components/images/image-share.d.ts +2 -1
- package/dist/components/images/image-share.d.ts.map +1 -1
- package/dist/components/images/image-share.js +3 -3
- package/dist/components/images/image-share.js.map +1 -1
- package/dist/components/images/image-viewer.d.ts.map +1 -1
- package/dist/components/images/image-viewer.js +3 -1
- package/dist/components/images/image-viewer.js.map +1 -1
- package/dist/components/images/mask-editor.d.ts.map +1 -1
- package/dist/components/images/mask-editor.js +7 -5
- package/dist/components/images/mask-editor.js.map +1 -1
- package/dist/components/layout/app-shell.d.ts.map +1 -1
- package/dist/components/layout/app-shell.js +4 -1
- package/dist/components/layout/app-shell.js.map +1 -1
- package/dist/components/layout/desktop-palette.d.ts +23 -0
- package/dist/components/layout/desktop-palette.d.ts.map +1 -0
- package/dist/components/layout/desktop-palette.js +132 -0
- package/dist/components/layout/desktop-palette.js.map +1 -0
- package/dist/components/layout/key-cap.d.ts +9 -0
- package/dist/components/layout/key-cap.d.ts.map +1 -0
- package/dist/components/layout/key-cap.js +10 -0
- package/dist/components/layout/key-cap.js.map +1 -0
- package/dist/components/layout/mobile-tab-bar.d.ts +13 -0
- package/dist/components/layout/mobile-tab-bar.d.ts.map +1 -1
- package/dist/components/layout/mobile-tab-bar.js +58 -47
- package/dist/components/layout/mobile-tab-bar.js.map +1 -1
- package/dist/components/layout/shortcut-switch.d.ts +13 -0
- package/dist/components/layout/shortcut-switch.d.ts.map +1 -0
- package/dist/components/layout/shortcut-switch.js +22 -0
- package/dist/components/layout/shortcut-switch.js.map +1 -0
- package/dist/components/layout/side-rail.d.ts +28 -0
- package/dist/components/layout/side-rail.d.ts.map +1 -1
- package/dist/components/layout/side-rail.js +72 -27
- package/dist/components/layout/side-rail.js.map +1 -1
- package/dist/components/layout/slide-panel.d.ts +25 -2
- package/dist/components/layout/slide-panel.d.ts.map +1 -1
- package/dist/components/layout/slide-panel.js +13 -4
- package/dist/components/layout/slide-panel.js.map +1 -1
- package/dist/components/layout/theme.d.ts +22 -0
- package/dist/components/layout/theme.d.ts.map +1 -0
- package/dist/components/layout/theme.js +44 -0
- package/dist/components/layout/theme.js.map +1 -0
- package/dist/components/quick-actions/add-form.d.ts +44 -0
- package/dist/components/quick-actions/add-form.d.ts.map +1 -0
- package/dist/components/quick-actions/add-form.js +32 -0
- package/dist/components/quick-actions/add-form.js.map +1 -0
- package/dist/components/quick-actions/add-modal.d.ts +7 -0
- package/dist/components/quick-actions/add-modal.d.ts.map +1 -1
- package/dist/components/quick-actions/add-modal.js +23 -20
- package/dist/components/quick-actions/add-modal.js.map +1 -1
- package/dist/components/quick-actions/search-modal.d.ts.map +1 -1
- package/dist/components/quick-actions/search-modal.js +8 -5
- package/dist/components/quick-actions/search-modal.js.map +1 -1
- package/dist/components/quick-actions/streaming-modal.d.ts +6 -0
- package/dist/components/quick-actions/streaming-modal.d.ts.map +1 -1
- package/dist/components/quick-actions/streaming-modal.js +53 -18
- package/dist/components/quick-actions/streaming-modal.js.map +1 -1
- package/dist/components/quick-actions/streaming-output.d.ts +38 -0
- package/dist/components/quick-actions/streaming-output.d.ts.map +1 -0
- package/dist/components/quick-actions/streaming-output.js +22 -0
- package/dist/components/quick-actions/streaming-output.js.map +1 -0
- package/dist/components/quick-actions/whatsup-modal.d.ts +5 -0
- package/dist/components/quick-actions/whatsup-modal.d.ts.map +1 -1
- package/dist/components/quick-actions/whatsup-modal.js +51 -10
- package/dist/components/quick-actions/whatsup-modal.js.map +1 -1
- package/dist/components/settings/devices-agents-tab.d.ts +6 -1
- package/dist/components/settings/devices-agents-tab.d.ts.map +1 -1
- package/dist/components/settings/devices-agents-tab.js +55 -20
- package/dist/components/settings/devices-agents-tab.js.map +1 -1
- package/dist/components/settings/models-list.d.ts +39 -0
- package/dist/components/settings/models-list.d.ts.map +1 -0
- package/dist/components/settings/models-list.js +72 -0
- package/dist/components/settings/models-list.js.map +1 -0
- package/dist/components/settings/models-tab.d.ts +4 -0
- package/dist/components/settings/models-tab.d.ts.map +1 -1
- package/dist/components/settings/models-tab.js +52 -102
- package/dist/components/settings/models-tab.js.map +1 -1
- package/dist/components/settings/one-time-agent-credential.js +1 -1
- package/dist/components/settings/one-time-agent-credential.js.map +1 -1
- package/dist/components/settings/passkey-list.d.ts +35 -0
- package/dist/components/settings/passkey-list.d.ts.map +1 -0
- package/dist/components/settings/passkey-list.js +34 -0
- package/dist/components/settings/passkey-list.js.map +1 -0
- package/dist/components/settings/passkey-tab.d.ts +3 -0
- package/dist/components/settings/passkey-tab.d.ts.map +1 -1
- package/dist/components/settings/passkey-tab.js +53 -45
- package/dist/components/settings/passkey-tab.js.map +1 -1
- package/dist/components/settings/pi-accounts-list.d.ts +27 -0
- package/dist/components/settings/pi-accounts-list.d.ts.map +1 -0
- package/dist/components/settings/pi-accounts-list.js +15 -0
- package/dist/components/settings/pi-accounts-list.js.map +1 -0
- package/dist/components/settings/pi-accounts.d.ts +3 -0
- package/dist/components/settings/pi-accounts.d.ts.map +1 -1
- package/dist/components/settings/pi-accounts.js +73 -55
- package/dist/components/settings/pi-accounts.js.map +1 -1
- package/dist/components/settings/principal-list.d.ts +37 -0
- package/dist/components/settings/principal-list.d.ts.map +1 -0
- package/dist/components/settings/principal-list.js +18 -0
- package/dist/components/settings/principal-list.js.map +1 -0
- package/dist/components/settings/settings-panel.d.ts +10 -3
- package/dist/components/settings/settings-panel.d.ts.map +1 -1
- package/dist/components/settings/settings-panel.js +71 -10
- package/dist/components/settings/settings-panel.js.map +1 -1
- package/dist/components/settings/skills-list.d.ts +53 -0
- package/dist/components/settings/skills-list.d.ts.map +1 -0
- package/dist/components/settings/skills-list.js +28 -0
- package/dist/components/settings/skills-list.js.map +1 -0
- package/dist/components/settings/skills-tab.d.ts.map +1 -1
- package/dist/components/settings/skills-tab.js +65 -38
- package/dist/components/settings/skills-tab.js.map +1 -1
- package/dist/components/settings/tool-permissions-list.d.ts +18 -0
- package/dist/components/settings/tool-permissions-list.d.ts.map +1 -0
- package/dist/components/settings/tool-permissions-list.js +6 -0
- package/dist/components/settings/tool-permissions-list.js.map +1 -0
- package/dist/components/settings/tool-permissions.d.ts +2 -1
- package/dist/components/settings/tool-permissions.d.ts.map +1 -1
- package/dist/components/settings/tool-permissions.js +33 -16
- package/dist/components/settings/tool-permissions.js.map +1 -1
- package/dist/components/settings/web-search-chain.d.ts +41 -0
- package/dist/components/settings/web-search-chain.d.ts.map +1 -0
- package/dist/components/settings/web-search-chain.js +47 -0
- package/dist/components/settings/web-search-chain.js.map +1 -0
- package/dist/components/settings/web-search-settings.d.ts +4 -7
- package/dist/components/settings/web-search-settings.d.ts.map +1 -1
- package/dist/components/settings/web-search-settings.js +54 -76
- package/dist/components/settings/web-search-settings.js.map +1 -1
- package/dist/components/share/share-menu.d.ts.map +1 -1
- package/dist/components/share/share-menu.js +24 -4
- package/dist/components/share/share-menu.js.map +1 -1
- package/dist/components/voice/dictation-sheet.js +3 -3
- package/dist/components/voice/dictation-sheet.js.map +1 -1
- package/dist/components/voice/mic-button.js +1 -1
- package/dist/components/voice/mic-button.js.map +1 -1
- package/dist/components/voice/review-card.js +1 -1
- package/dist/components/voice/review-card.js.map +1 -1
- package/dist/config.d.ts +5 -2
- package/dist/config.d.ts.map +1 -1
- package/dist/config.js +15 -5
- package/dist/config.js.map +1 -1
- package/dist/connection.d.ts +12 -0
- package/dist/connection.d.ts.map +1 -0
- package/dist/connection.js +421 -0
- package/dist/connection.js.map +1 -0
- package/dist/default-root.d.ts +3 -0
- package/dist/default-root.d.ts.map +1 -0
- package/dist/default-root.js +16 -0
- package/dist/default-root.js.map +1 -0
- package/dist/hooks/use-color-scheme.d.ts +14 -0
- package/dist/hooks/use-color-scheme.d.ts.map +1 -0
- package/dist/hooks/use-color-scheme.js +37 -0
- package/dist/hooks/use-color-scheme.js.map +1 -0
- package/dist/hooks/use-fine-pointer.d.ts +12 -0
- package/dist/hooks/use-fine-pointer.d.ts.map +1 -0
- package/dist/hooks/use-fine-pointer.js +15 -0
- package/dist/hooks/use-fine-pointer.js.map +1 -0
- package/dist/hooks/use-hash-routes.d.ts.map +1 -1
- package/dist/hooks/use-hash-routes.js +4 -2
- package/dist/hooks/use-hash-routes.js.map +1 -1
- package/dist/hooks/use-media-query.d.ts +9 -0
- package/dist/hooks/use-media-query.d.ts.map +1 -0
- package/dist/hooks/use-media-query.js +38 -0
- package/dist/hooks/use-media-query.js.map +1 -0
- package/dist/hooks/use-share-intake.d.ts.map +1 -1
- package/dist/hooks/use-share-intake.js +37 -12
- package/dist/hooks/use-share-intake.js.map +1 -1
- package/dist/hooks/use-vpn-status.d.ts.map +1 -1
- package/dist/hooks/use-vpn-status.js +17 -18
- package/dist/hooks/use-vpn-status.js.map +1 -1
- package/dist/hooks/use-websocket.d.ts +5 -24
- package/dist/hooks/use-websocket.d.ts.map +1 -1
- package/dist/hooks/use-websocket.js +11 -384
- package/dist/hooks/use-websocket.js.map +1 -1
- package/dist/hooks/websocket-handlers/activity.d.ts +2 -2
- package/dist/hooks/websocket-handlers/activity.d.ts.map +1 -1
- package/dist/hooks/websocket-handlers/activity.js +4 -5
- package/dist/hooks/websocket-handlers/activity.js.map +1 -1
- package/dist/hooks/websocket-handlers/chat.d.ts +1 -0
- package/dist/hooks/websocket-handlers/chat.d.ts.map +1 -1
- package/dist/hooks/websocket-handlers/chat.js +28 -6
- package/dist/hooks/websocket-handlers/chat.js.map +1 -1
- package/dist/hooks/websocket-handlers/connection.d.ts.map +1 -1
- package/dist/hooks/websocket-handlers/connection.js +4 -6
- package/dist/hooks/websocket-handlers/connection.js.map +1 -1
- package/dist/hooks/websocket-handlers/mask.d.ts +1 -1
- package/dist/hooks/websocket-handlers/mask.d.ts.map +1 -1
- package/dist/hooks/websocket-handlers/mask.js +2 -3
- package/dist/hooks/websocket-handlers/mask.js.map +1 -1
- package/dist/hooks/websocket-handlers/provider.d.ts.map +1 -1
- package/dist/hooks/websocket-handlers/provider.js +4 -6
- package/dist/hooks/websocket-handlers/provider.js.map +1 -1
- package/dist/hooks/websocket-handlers/types.d.ts +6 -2
- package/dist/hooks/websocket-handlers/types.d.ts.map +1 -1
- package/dist/index.d.ts +5 -3
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +6 -3
- package/dist/index.js.map +1 -1
- package/dist/lib/api-client.d.ts +289 -0
- package/dist/lib/api-client.d.ts.map +1 -1
- package/dist/lib/api-client.js +243 -224
- package/dist/lib/api-client.js.map +1 -1
- package/dist/lib/backend.d.ts +19 -2
- package/dist/lib/backend.d.ts.map +1 -1
- package/dist/lib/backend.js +15 -9
- package/dist/lib/backend.js.map +1 -1
- package/dist/lib/diff.d.ts +8 -10
- package/dist/lib/diff.d.ts.map +1 -1
- package/dist/lib/diff.js +26 -53
- package/dist/lib/diff.js.map +1 -1
- package/dist/lib/light-dark.d.ts +37 -0
- package/dist/lib/light-dark.d.ts.map +1 -0
- package/dist/lib/light-dark.js +83 -0
- package/dist/lib/light-dark.js.map +1 -0
- package/dist/lib/mermaid-theme.d.ts +7 -2
- package/dist/lib/mermaid-theme.d.ts.map +1 -1
- package/dist/lib/mermaid-theme.js +125 -203
- package/dist/lib/mermaid-theme.js.map +1 -1
- package/dist/lib/passkeys.d.ts +6 -3
- package/dist/lib/passkeys.d.ts.map +1 -1
- package/dist/lib/passkeys.js +10 -4
- package/dist/lib/passkeys.js.map +1 -1
- package/dist/lib/push-registration.d.ts +4 -1
- package/dist/lib/push-registration.d.ts.map +1 -1
- package/dist/lib/push-registration.js +20 -2
- package/dist/lib/push-registration.js.map +1 -1
- package/dist/lib/share-intake.d.ts +2 -1
- package/dist/lib/share-intake.d.ts.map +1 -1
- package/dist/lib/share-intake.js +3 -3
- package/dist/lib/share-intake.js.map +1 -1
- package/dist/lib/share.d.ts +4 -3
- package/dist/lib/share.d.ts.map +1 -1
- package/dist/lib/share.js +6 -7
- package/dist/lib/share.js.map +1 -1
- package/dist/lib/single-key.d.ts +30 -0
- package/dist/lib/single-key.d.ts.map +1 -0
- package/dist/lib/single-key.js +45 -0
- package/dist/lib/single-key.js.map +1 -0
- package/dist/lib/tool-names.d.ts +8 -6
- package/dist/lib/tool-names.d.ts.map +1 -1
- package/dist/lib/tool-names.js +17 -7
- package/dist/lib/tool-names.js.map +1 -1
- package/dist/root-context.d.ts +229 -0
- package/dist/root-context.d.ts.map +1 -0
- package/dist/root-context.js +33 -0
- package/dist/root-context.js.map +1 -0
- package/dist/root.d.ts +38 -0
- package/dist/root.d.ts.map +1 -0
- package/dist/root.js +47 -0
- package/dist/root.js.map +1 -0
- package/dist/stores/activity-state.d.ts +29 -0
- package/dist/stores/activity-state.d.ts.map +1 -0
- package/dist/stores/activity-state.js +282 -0
- package/dist/stores/activity-state.js.map +1 -0
- package/dist/stores/activity-store.d.ts +10 -41
- package/dist/stores/activity-store.d.ts.map +1 -1
- package/dist/stores/activity-store.js +9 -271
- package/dist/stores/activity-store.js.map +1 -1
- package/dist/stores/chat-state.d.ts +233 -0
- package/dist/stores/chat-state.d.ts.map +1 -0
- package/dist/stores/chat-state.js +477 -0
- package/dist/stores/chat-state.js.map +1 -0
- package/dist/stores/chat-store.d.ts +4 -162
- package/dist/stores/chat-store.d.ts.map +1 -1
- package/dist/stores/chat-store.js +7 -418
- package/dist/stores/chat-store.js.map +1 -1
- package/dist/stores/connection-state.d.ts +40 -0
- package/dist/stores/connection-state.d.ts.map +1 -0
- package/dist/stores/connection-state.js +30 -0
- package/dist/stores/connection-state.js.map +1 -0
- package/dist/stores/connection-store.d.ts +4 -40
- package/dist/stores/connection-store.d.ts.map +1 -1
- package/dist/stores/connection-store.js +7 -27
- package/dist/stores/connection-store.js.map +1 -1
- package/dist/stores/create-stores.d.ts +23 -0
- package/dist/stores/create-stores.d.ts.map +1 -0
- package/dist/stores/create-stores.js +28 -0
- package/dist/stores/create-stores.js.map +1 -0
- package/dist/stores/file-state.d.ts +53 -0
- package/dist/stores/file-state.d.ts.map +1 -0
- package/dist/stores/file-state.js +341 -0
- package/dist/stores/file-state.js.map +1 -0
- package/dist/stores/file-store.d.ts +4 -52
- package/dist/stores/file-store.d.ts.map +1 -1
- package/dist/stores/file-store.js +7 -336
- package/dist/stores/file-store.js.map +1 -1
- package/dist/stores/graph-state.d.ts +95 -0
- package/dist/stores/graph-state.d.ts.map +1 -0
- package/dist/stores/graph-state.js +252 -0
- package/dist/stores/graph-state.js.map +1 -0
- package/dist/stores/graph-store.d.ts +7 -83
- package/dist/stores/graph-store.d.ts.map +1 -1
- package/dist/stores/graph-store.js +8 -249
- package/dist/stores/graph-store.js.map +1 -1
- package/dist/stores/mask-state.d.ts +21 -0
- package/dist/stores/mask-state.d.ts.map +1 -0
- package/dist/stores/mask-state.js +9 -0
- package/dist/stores/mask-state.js.map +1 -0
- package/dist/stores/mask-store.d.ts +4 -21
- package/dist/stores/mask-store.d.ts.map +1 -1
- package/dist/stores/mask-store.js +7 -6
- package/dist/stores/mask-store.js.map +1 -1
- package/dist/stores/principal-state.d.ts +16 -0
- package/dist/stores/principal-state.d.ts.map +1 -0
- package/dist/stores/principal-state.js +31 -0
- package/dist/stores/principal-state.js.map +1 -0
- package/dist/stores/principal-store.d.ts +4 -15
- package/dist/stores/principal-store.d.ts.map +1 -1
- package/dist/stores/principal-store.js +7 -28
- package/dist/stores/principal-store.js.map +1 -1
- package/dist/stores/provider-state.d.ts +24 -0
- package/dist/stores/provider-state.d.ts.map +1 -0
- package/dist/stores/provider-state.js +68 -0
- package/dist/stores/provider-state.js.map +1 -0
- package/dist/stores/provider-store.d.ts +4 -23
- package/dist/stores/provider-store.d.ts.map +1 -1
- package/dist/stores/provider-store.js +7 -64
- package/dist/stores/provider-store.js.map +1 -1
- package/dist/stores/share-state.d.ts +29 -0
- package/dist/stores/share-state.d.ts.map +1 -0
- package/dist/stores/share-state.js +21 -0
- package/dist/stores/share-state.js.map +1 -0
- package/dist/stores/share-store.d.ts +4 -28
- package/dist/stores/share-store.d.ts.map +1 -1
- package/dist/stores/share-store.js +7 -18
- package/dist/stores/share-store.js.map +1 -1
- package/dist/stores/store-environment.d.ts +10 -0
- package/dist/stores/store-environment.d.ts.map +1 -0
- package/dist/stores/store-environment.js +2 -0
- package/dist/stores/store-environment.js.map +1 -0
- package/dist/stores/ui-state.d.ts +71 -0
- package/dist/stores/ui-state.d.ts.map +1 -0
- package/dist/stores/ui-state.js +58 -0
- package/dist/stores/ui-state.js.map +1 -0
- package/dist/stores/ui-store.d.ts +4 -45
- package/dist/stores/ui-store.d.ts.map +1 -1
- package/dist/stores/ui-store.js +7 -36
- package/dist/stores/ui-store.js.map +1 -1
- package/dist/styles.css +1 -1
- package/dist/theme.css +150 -97
- package/dist/voice/asr-clients.d.ts +2 -1
- package/dist/voice/asr-clients.d.ts.map +1 -1
- package/dist/voice/asr-clients.js +16 -17
- package/dist/voice/asr-clients.js.map +1 -1
- package/dist/voice/use-dictation.d.ts.map +1 -1
- package/dist/voice/use-dictation.js +12 -8
- package/dist/voice/use-dictation.js.map +1 -1
- package/dist/voice/voice-state.d.ts +25 -0
- package/dist/voice/voice-state.d.ts.map +1 -0
- package/dist/voice/voice-state.js +29 -0
- package/dist/voice/voice-state.js.map +1 -0
- package/dist/voice/voice-store.d.ts +4 -25
- package/dist/voice/voice-store.d.ts.map +1 -1
- package/dist/voice/voice-store.js +7 -26
- package/dist/voice/voice-store.js.map +1 -1
- package/package.json +3 -2
- package/src/components/activity/activity-page.tsx +341 -160
- package/src/components/activity/activity-run-detail.tsx +81 -47
- package/src/components/activity/activity-run-list.tsx +27 -59
- package/src/components/activity/activity-views.tsx +155 -0
- package/src/components/activity/approval-card.tsx +117 -0
- package/src/components/activity/digest-card.tsx +25 -61
- package/src/components/activity/digest-summary.tsx +52 -0
- package/src/components/activity/push-switch.tsx +62 -0
- package/src/components/activity/push-toggle.tsx +51 -81
- package/src/components/activity/span-bits.tsx +60 -7
- package/src/components/chat/ask-user-card.tsx +292 -356
- package/src/components/chat/ask-user-typed.ts +77 -0
- package/src/components/chat/brain-markdown-links.tsx +4 -4
- package/src/components/chat/brain-markdown.tsx +4 -2
- package/src/components/chat/chat-page.tsx +41 -11
- package/src/components/chat/composer-view.tsx +194 -0
- package/src/components/chat/composer.tsx +117 -296
- package/src/components/chat/markdown-content.tsx +53 -2
- package/src/components/chat/mermaid-block.tsx +13 -5
- package/src/components/chat/mermaid-share.ts +8 -7
- package/src/components/chat/mermaid-viewer.tsx +3 -1
- package/src/components/chat/message-bubble.tsx +78 -94
- package/src/components/chat/message-share.ts +7 -7
- package/src/components/chat/renderers/bind.tsx +94 -0
- package/src/components/chat/renderers/brain-ui-tools.tsx +56 -0
- package/src/components/chat/renderers/claude-tools.tsx +3 -2
- package/src/components/chat/renderers/index.ts +15 -10
- package/src/components/chat/session-drawer.tsx +41 -138
- package/src/components/chat/session-list.tsx +113 -0
- package/src/components/chat/share-block.tsx +16 -12
- package/src/components/chat/share-card.tsx +2 -2
- package/src/components/chat/subagent-view.tsx +4 -4
- package/src/components/chat/tool-call-timeline.tsx +75 -26
- package/src/components/chat/tool-cards/block-card.tsx +145 -0
- package/src/components/chat/tool-cards/image-mask-card.tsx +214 -0
- package/src/components/chat/tool-cards/location-card.tsx +159 -0
- package/src/components/chat/tool-views.tsx +30 -60
- package/src/components/chat/transcript-turn.tsx +108 -0
- package/src/components/chat/use-chat-commands.ts +14 -16
- package/src/components/chat/welcome-state.tsx +36 -91
- package/src/components/connectivity/connection-gate.tsx +32 -24
- package/src/components/connectivity/login-form.tsx +122 -0
- package/src/components/connectivity/login-screen.tsx +45 -100
- package/src/components/dev/share-harness.tsx +2 -2
- package/src/components/files/file-panel.tsx +168 -0
- package/src/components/files/file-tree-view.tsx +127 -0
- package/src/components/files/file-tree.tsx +55 -109
- package/src/components/files/file-viewer-binary.tsx +3 -2
- package/src/components/files/file-viewer-frame.tsx +113 -0
- package/src/components/files/file-viewer.tsx +40 -95
- package/src/components/files/frontmatter-chips.tsx +42 -0
- package/src/components/files/frontmatter-panel.tsx +6 -71
- package/src/components/files/staleness.ts +29 -0
- package/src/components/graph/graph-canvas.tsx +24 -1
- package/src/components/graph/graph-controls-column.tsx +92 -0
- package/src/components/graph/graph-controls.tsx +83 -127
- package/src/components/graph/graph-form.tsx +183 -0
- package/src/components/graph/graph-maintenance.tsx +9 -14
- package/src/components/graph/graph-node-rail.tsx +147 -0
- package/src/components/graph/graph-page.tsx +189 -49
- package/src/components/graph/graph-scene.tsx +200 -30
- package/src/components/graph/lib/graph-helpers.ts +65 -43
- package/src/components/graph/node-card.tsx +64 -0
- package/src/components/graph/node-popover.tsx +28 -117
- package/src/components/graph/use-graph-theme.ts +69 -32
- package/src/components/graph/use-node-actions.ts +56 -0
- package/src/components/images/image-share.ts +4 -2
- package/src/components/images/image-viewer.tsx +3 -1
- package/src/components/images/mask-editor.tsx +7 -4
- package/src/components/layout/app-shell.tsx +5 -1
- package/src/components/layout/desktop-palette.tsx +151 -0
- package/src/components/layout/key-cap.tsx +15 -0
- package/src/components/layout/mobile-tab-bar.tsx +80 -157
- package/src/components/layout/shortcut-switch.tsx +32 -0
- package/src/components/layout/side-rail.tsx +77 -150
- package/src/components/layout/slide-panel.tsx +49 -6
- package/src/components/layout/theme.tsx +67 -0
- package/src/components/quick-actions/add-form.tsx +196 -0
- package/src/components/quick-actions/add-modal.tsx +32 -153
- package/src/components/quick-actions/search-modal.tsx +15 -5
- package/src/components/quick-actions/streaming-modal.tsx +57 -72
- package/src/components/quick-actions/streaming-output.tsx +112 -0
- package/src/components/quick-actions/whatsup-modal.tsx +53 -59
- package/src/components/settings/devices-agents-tab.tsx +60 -152
- package/src/components/settings/models-list.tsx +299 -0
- package/src/components/settings/models-tab.tsx +63 -337
- package/src/components/settings/one-time-agent-credential.tsx +1 -1
- package/src/components/settings/passkey-list.tsx +201 -0
- package/src/components/settings/passkey-tab.tsx +53 -197
- package/src/components/settings/pi-accounts-list.tsx +128 -0
- package/src/components/settings/pi-accounts.tsx +71 -170
- package/src/components/settings/principal-list.tsx +172 -0
- package/src/components/settings/settings-panel.tsx +239 -25
- package/src/components/settings/skills-list.tsx +276 -0
- package/src/components/settings/skills-tab.tsx +82 -269
- package/src/components/settings/tool-permissions-list.tsx +54 -0
- package/src/components/settings/tool-permissions.tsx +27 -46
- package/src/components/settings/web-search-chain.tsx +300 -0
- package/src/components/settings/web-search-settings.tsx +58 -328
- package/src/components/share/share-menu.tsx +19 -4
- package/src/components/voice/dictation-sheet.tsx +5 -5
- package/src/components/voice/mic-button.tsx +1 -1
- package/src/components/voice/review-card.tsx +1 -1
- package/src/config.ts +21 -7
- package/src/connection.ts +443 -0
- package/src/default-root.ts +16 -0
- package/src/hooks/use-color-scheme.ts +36 -0
- package/src/hooks/use-fine-pointer.ts +15 -0
- package/src/hooks/use-hash-routes.ts +4 -2
- package/src/hooks/use-media-query.ts +35 -0
- package/src/hooks/use-share-intake.ts +32 -12
- package/src/hooks/use-vpn-status.ts +18 -17
- package/src/hooks/use-websocket.ts +12 -428
- package/src/hooks/websocket-handlers/activity.ts +4 -5
- package/src/hooks/websocket-handlers/chat.ts +28 -6
- package/src/hooks/websocket-handlers/connection.ts +4 -6
- package/src/hooks/websocket-handlers/mask.ts +2 -3
- package/src/hooks/websocket-handlers/provider.ts +4 -6
- package/src/hooks/websocket-handlers/types.ts +6 -2
- package/src/index.ts +7 -3
- package/src/lib/api-client.ts +426 -384
- package/src/lib/backend.ts +20 -10
- package/src/lib/diff.ts +28 -62
- package/src/lib/light-dark.ts +83 -0
- package/src/lib/mermaid-theme.ts +183 -214
- package/src/lib/passkeys.ts +12 -4
- package/src/lib/push-registration.ts +19 -2
- package/src/lib/share-intake.ts +6 -3
- package/src/lib/share.ts +7 -4
- package/src/lib/single-key.ts +47 -0
- package/src/lib/tool-names.ts +31 -8
- package/src/root-context.tsx +40 -0
- package/src/root.ts +83 -0
- package/src/stores/activity-state.ts +295 -0
- package/src/stores/activity-store.ts +11 -285
- package/src/stores/chat-state.ts +822 -0
- package/src/stores/chat-store.ts +11 -705
- package/src/stores/connection-state.ts +78 -0
- package/src/stores/connection-store.ts +11 -76
- package/src/stores/create-stores.ts +31 -0
- package/src/stores/file-state.ts +399 -0
- package/src/stores/file-store.ts +9 -390
- package/src/stores/graph-state.ts +368 -0
- package/src/stores/graph-store.ts +10 -355
- package/src/stores/mask-state.ts +30 -0
- package/src/stores/mask-store.ts +10 -27
- package/src/stores/principal-state.ts +42 -0
- package/src/stores/principal-store.ts +10 -37
- package/src/stores/provider-state.ts +103 -0
- package/src/stores/provider-store.ts +10 -95
- package/src/stores/share-state.ts +56 -0
- package/src/stores/share-store.ts +11 -54
- package/src/stores/store-environment.ts +10 -0
- package/src/stores/ui-state.ts +143 -0
- package/src/stores/ui-store.ts +11 -93
- package/src/styles.css +4 -1
- package/src/theme.css +150 -97
- package/src/voice/asr-clients.ts +17 -17
- package/src/voice/use-dictation.ts +11 -8
- package/src/voice/voice-state.ts +57 -0
- package/src/voice/voice-store.ts +11 -55
package/src/stores/chat-store.ts
CHANGED
|
@@ -1,705 +1,11 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
export interface ChatMessage {
|
|
14
|
-
id: string;
|
|
15
|
-
role: "user" | "assistant";
|
|
16
|
-
content: string;
|
|
17
|
-
thinking?: string;
|
|
18
|
-
toolCalls: ToolCall[];
|
|
19
|
-
/**
|
|
20
|
-
* Chronological thinking/text/tool segments, in arrival order. `content`,
|
|
21
|
-
* `thinking` and `toolCalls` remain the aggregated views (used for sharing
|
|
22
|
-
* and tool state); `parts` drives rendering order.
|
|
23
|
-
*/
|
|
24
|
-
parts: MessagePart[];
|
|
25
|
-
isStreaming: boolean;
|
|
26
|
-
timestamp: number;
|
|
27
|
-
source?: MessageSource;
|
|
28
|
-
/** AskUserQuestion exchanges raised during this assistant turn. */
|
|
29
|
-
askUserExchanges?: AskUserExchange[];
|
|
30
|
-
/**
|
|
31
|
-
* Image attachments on a user message. Live messages carry a local
|
|
32
|
-
* `previewUrl` (object URL, revoked on clear). History-loaded messages
|
|
33
|
-
* carry no data — only `attachmentCount` — since base64 is never replayed.
|
|
34
|
-
*/
|
|
35
|
-
attachments?: MessageAttachment[];
|
|
36
|
-
/** Attachment count for history-loaded messages without preview data. */
|
|
37
|
-
attachmentCount?: number;
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
export interface MessageAttachment {
|
|
41
|
-
previewUrl: string;
|
|
42
|
-
mediaType: string;
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
export interface ToolCall {
|
|
46
|
-
id: string;
|
|
47
|
-
name: string;
|
|
48
|
-
input: Record<string, unknown>;
|
|
49
|
-
inputJson: string;
|
|
50
|
-
output?: string;
|
|
51
|
-
isError?: boolean;
|
|
52
|
-
status: "streaming" | "pending_approval" | "approved" | "denied" | "complete";
|
|
53
|
-
/**
|
|
54
|
-
* What the pending approval is for: "tool" may be remembered via "Always
|
|
55
|
-
* allow"; "command" (a destructive-bash confirmation) is per-use only.
|
|
56
|
-
*/
|
|
57
|
-
approvalKind?: "tool" | "command";
|
|
58
|
-
/**
|
|
59
|
-
* Execution timing for the duration badge. `startedAt` is (re)stamped when
|
|
60
|
-
* the input finishes streaming or an approval is granted — so approval
|
|
61
|
-
* wait time doesn't inflate the reported duration. `endedAt` is stamped by
|
|
62
|
-
* the tool result. History-loaded messages carry no timing.
|
|
63
|
-
*/
|
|
64
|
-
startedAt?: number;
|
|
65
|
-
endedAt?: number;
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
export interface AskUserExchange {
|
|
69
|
-
requestId: string;
|
|
70
|
-
questions: AskUserQuestion[];
|
|
71
|
-
/** Filled in once the user submits. Keyed by question text. */
|
|
72
|
-
answers?: Record<string, string>;
|
|
73
|
-
annotations?: Record<string, AskUserAnnotation>;
|
|
74
|
-
cancelled?: boolean;
|
|
75
|
-
}
|
|
76
|
-
|
|
77
|
-
/**
|
|
78
|
-
* One session's live transcript state. Every session the user has viewed (or
|
|
79
|
-
* that bound from the draft) keeps its own buffer, so frames from a background
|
|
80
|
-
* session accumulate in THAT session's transcript instead of being discarded —
|
|
81
|
-
* the multi-session contract the old single-active-buffer store violated.
|
|
82
|
-
*/
|
|
83
|
-
export interface SessionChat {
|
|
84
|
-
messages: ChatMessage[];
|
|
85
|
-
isStreaming: boolean;
|
|
86
|
-
/**
|
|
87
|
-
* The currently-pending ask-user exchange in this session (no answers yet).
|
|
88
|
-
* Mirrors the same exchange that lives on the streaming assistant message;
|
|
89
|
-
* held here for fast lookup by hooks/components.
|
|
90
|
-
*/
|
|
91
|
-
askUser: AskUserExchange | null;
|
|
92
|
-
/** LRU stamp for buffer eviction. */
|
|
93
|
-
lastTouched: number;
|
|
94
|
-
}
|
|
95
|
-
|
|
96
|
-
/**
|
|
97
|
-
* Buffer key: a server sessionId, or null for the DRAFT buffer — the new
|
|
98
|
-
* conversation that has no server identity yet. `session_info` re-keys the
|
|
99
|
-
* draft onto its real sessionId via bindDraftSession().
|
|
100
|
-
*/
|
|
101
|
-
export type ChatKey = string | null;
|
|
102
|
-
|
|
103
|
-
/** Retained transcript buffers beyond the active one (LRU-evicted). */
|
|
104
|
-
const MAX_BUFFERS = 8;
|
|
105
|
-
|
|
106
|
-
interface ChatState {
|
|
107
|
-
/** Per-session transcript buffers, keyed by server sessionId. */
|
|
108
|
-
buffers: Record<string, SessionChat>;
|
|
109
|
-
/** The unbound new-conversation buffer, if one is in progress. */
|
|
110
|
-
draft: SessionChat | null;
|
|
111
|
-
/**
|
|
112
|
-
* Correlation id for the conversation the draft is currently starting.
|
|
113
|
-
*
|
|
114
|
-
* A client starting a conversation has no session id, so it used to adopt
|
|
115
|
-
* the FIRST `session_info` for an unknown session — which could be an older
|
|
116
|
-
* background turn's, or another client's, silently binding the user's draft
|
|
117
|
-
* to someone else's transcript. The id is sent on `chat_message` and echoed
|
|
118
|
-
* on `session_info`; adoption now requires a match. Null when no draft turn
|
|
119
|
-
* is in flight.
|
|
120
|
-
*/
|
|
121
|
-
pendingDraftId: string | null;
|
|
122
|
-
/** The session in view; null = the draft / new-chat view. */
|
|
123
|
-
activeSessionId: string | null;
|
|
124
|
-
|
|
125
|
-
/**
|
|
126
|
-
* Live run-state per session id, for the session-list badges. Maintained for
|
|
127
|
-
* every session frame regardless of whether a buffer exists. "idle" is the
|
|
128
|
-
* absence of a running/queued turn.
|
|
129
|
-
*/
|
|
130
|
-
runStates: Record<string, "streaming" | "queued" | "idle">;
|
|
131
|
-
/**
|
|
132
|
-
* Backend that owns each session, from `session_info` (or the session list
|
|
133
|
-
* for history sessions). Scopes tool-call renderer resolution per backend;
|
|
134
|
-
* absence falls back to the deployment default.
|
|
135
|
-
*/
|
|
136
|
-
backendIds: Record<string, string>;
|
|
137
|
-
/**
|
|
138
|
-
* Per-session note attached to a `queued` status — the host sends one once a
|
|
139
|
-
* session's follow-up queue grows heavy. Cleared when the session leaves the
|
|
140
|
-
* queued state, so a stale warning cannot outlive the queue it described.
|
|
141
|
-
*/
|
|
142
|
-
queueNotes: Record<string, string>;
|
|
143
|
-
|
|
144
|
-
// Buffer mutations (key: sessionId, or null for the draft)
|
|
145
|
-
addUserMessage: (
|
|
146
|
-
key: ChatKey,
|
|
147
|
-
text: string,
|
|
148
|
-
source?: MessageSource,
|
|
149
|
-
attachments?: MessageAttachment[]
|
|
150
|
-
) => void;
|
|
151
|
-
startAssistantMessage: (key: ChatKey) => void;
|
|
152
|
-
appendText: (key: ChatKey, text: string) => void;
|
|
153
|
-
appendThinking: (key: ChatKey, text: string) => void;
|
|
154
|
-
startToolCall: (key: ChatKey, toolUseId: string, toolName: string) => void;
|
|
155
|
-
appendToolInput: (key: ChatKey, partialJson: string) => void;
|
|
156
|
-
completeToolCall: (
|
|
157
|
-
key: ChatKey,
|
|
158
|
-
toolUseId: string,
|
|
159
|
-
toolName: string,
|
|
160
|
-
input: Record<string, unknown>
|
|
161
|
-
) => void;
|
|
162
|
-
requestToolApproval: (
|
|
163
|
-
key: ChatKey,
|
|
164
|
-
toolUseId: string,
|
|
165
|
-
toolName: string,
|
|
166
|
-
input: Record<string, unknown>,
|
|
167
|
-
description?: string,
|
|
168
|
-
kind?: "tool" | "command"
|
|
169
|
-
) => void;
|
|
170
|
-
resolveToolApproval: (key: ChatKey, toolUseId: string, approved: boolean) => void;
|
|
171
|
-
setToolResult: (key: ChatKey, toolUseId: string, output: string, isError: boolean) => void;
|
|
172
|
-
setAskUserRequest: (key: ChatKey, requestId: string, questions: AskUserQuestion[]) => void;
|
|
173
|
-
submitAskUserAnswers: (
|
|
174
|
-
key: ChatKey,
|
|
175
|
-
requestId: string,
|
|
176
|
-
answers: Record<string, string>,
|
|
177
|
-
annotations?: Record<string, AskUserAnnotation>
|
|
178
|
-
) => void;
|
|
179
|
-
cancelAskUser: (key: ChatKey, requestId: string) => void;
|
|
180
|
-
clearAskUser: (key: ChatKey) => void;
|
|
181
|
-
finishAssistantMessage: (key: ChatKey) => void;
|
|
182
|
-
setStreaming: (key: ChatKey, streaming: boolean) => void;
|
|
183
|
-
/** Replace a session's transcript (first replayed history chunk). Creates the buffer. */
|
|
184
|
-
setMessages: (key: ChatKey, messages: ChatMessage[]) => void;
|
|
185
|
-
/** Concatenate a continuation chunk of replayed history. Creates the buffer. */
|
|
186
|
-
appendMessages: (key: ChatKey, messages: ChatMessage[]) => void;
|
|
187
|
-
|
|
188
|
-
// Session lifecycle
|
|
189
|
-
/**
|
|
190
|
-
* Adopt the draft buffer as `sessionId` (the server just named the session).
|
|
191
|
-
* If the draft view is active, the view follows. No-op draft = empty buffer.
|
|
192
|
-
*/
|
|
193
|
-
bindDraftSession: (sessionId: string) => void;
|
|
194
|
-
/** Mint and remember the correlation id for a draft turn about to be sent. */
|
|
195
|
-
startDraftTurn: () => string;
|
|
196
|
-
/** Switch the view to a session (creating an empty buffer if none), or to the draft (null). */
|
|
197
|
-
setActiveSession: (sessionId: string | null) => void;
|
|
198
|
-
/** New chat: drop the draft, unbind the view, unpin the provider. */
|
|
199
|
-
clearMessages: () => void;
|
|
200
|
-
setRunState: (
|
|
201
|
-
sessionId: string,
|
|
202
|
-
state: "streaming" | "queued" | "idle",
|
|
203
|
-
note?: string
|
|
204
|
-
) => void;
|
|
205
|
-
/** Record which backend owns a session (idempotent). */
|
|
206
|
-
setSessionBackend: (sessionId: string, backendId: string) => void;
|
|
207
|
-
}
|
|
208
|
-
|
|
209
|
-
let messageCounter = 0;
|
|
210
|
-
function nextId() {
|
|
211
|
-
return `msg-${++messageCounter}-${Date.now()}`;
|
|
212
|
-
}
|
|
213
|
-
|
|
214
|
-
const SESSION_ID_KEY = "brain-sessionId";
|
|
215
|
-
|
|
216
|
-
/**
|
|
217
|
-
* Persist the active session id to localStorage when a DOM is present (the
|
|
218
|
-
* browser). A no-op in non-DOM environments (tests, SSR) so creating the store
|
|
219
|
-
* never throws on a missing `localStorage`.
|
|
220
|
-
*/
|
|
221
|
-
function persistSessionId(id: string | null) {
|
|
222
|
-
if (typeof localStorage === "undefined") return;
|
|
223
|
-
if (id) localStorage.setItem(SESSION_ID_KEY, id);
|
|
224
|
-
else localStorage.removeItem(SESSION_ID_KEY);
|
|
225
|
-
}
|
|
226
|
-
|
|
227
|
-
function readPersistedSessionId(): string | null {
|
|
228
|
-
if (typeof localStorage === "undefined") return null;
|
|
229
|
-
return localStorage.getItem(SESSION_ID_KEY);
|
|
230
|
-
}
|
|
231
|
-
|
|
232
|
-
function emptyChat(): SessionChat {
|
|
233
|
-
return { messages: [], isStreaming: false, askUser: null, lastTouched: Date.now() };
|
|
234
|
-
}
|
|
235
|
-
|
|
236
|
-
/** Frozen empty buffer for selectors when nothing is in view. */
|
|
237
|
-
const EMPTY_CHAT: SessionChat = Object.freeze({
|
|
238
|
-
messages: Object.freeze([]) as unknown as ChatMessage[],
|
|
239
|
-
isStreaming: false,
|
|
240
|
-
askUser: null,
|
|
241
|
-
lastTouched: 0,
|
|
242
|
-
});
|
|
243
|
-
|
|
244
|
-
/** The buffer currently in view (draft when no session is bound). */
|
|
245
|
-
export function activeChat(state: ChatState): SessionChat {
|
|
246
|
-
if (state.activeSessionId) return state.buffers[state.activeSessionId] ?? EMPTY_CHAT;
|
|
247
|
-
return state.draft ?? EMPTY_CHAT;
|
|
248
|
-
}
|
|
249
|
-
|
|
250
|
-
/** True when ANY buffer is streaming (service-worker busy check, etc.). */
|
|
251
|
-
export function anyStreaming(state: ChatState): boolean {
|
|
252
|
-
if (state.draft?.isStreaming) return true;
|
|
253
|
-
return Object.values(state.buffers).some((b) => b.isStreaming);
|
|
254
|
-
}
|
|
255
|
-
|
|
256
|
-
/** Append text to the last part if it has the same kind, else start a new part. */
|
|
257
|
-
function appendPart(
|
|
258
|
-
parts: MessagePart[],
|
|
259
|
-
kind: "thinking" | "text",
|
|
260
|
-
text: string
|
|
261
|
-
): MessagePart[] {
|
|
262
|
-
const last = parts[parts.length - 1];
|
|
263
|
-
if (last && last.kind === kind) {
|
|
264
|
-
return [...parts.slice(0, -1), { kind, text: last.text + text }];
|
|
265
|
-
}
|
|
266
|
-
return [...parts, { kind, text }];
|
|
267
|
-
}
|
|
268
|
-
|
|
269
|
-
/** Free object URLs held by live message previews before dropping them. */
|
|
270
|
-
function revokeAttachmentUrls(messages: ChatMessage[]) {
|
|
271
|
-
for (const m of messages) {
|
|
272
|
-
for (const a of m.attachments ?? []) {
|
|
273
|
-
if (a.previewUrl.startsWith("blob:")) URL.revokeObjectURL(a.previewUrl);
|
|
274
|
-
}
|
|
275
|
-
}
|
|
276
|
-
}
|
|
277
|
-
|
|
278
|
-
/** Evict least-recently-touched non-active buffers beyond MAX_BUFFERS. */
|
|
279
|
-
function evictStale(
|
|
280
|
-
buffers: Record<string, SessionChat>,
|
|
281
|
-
activeSessionId: string | null
|
|
282
|
-
): Record<string, SessionChat> {
|
|
283
|
-
const ids = Object.keys(buffers);
|
|
284
|
-
if (ids.length <= MAX_BUFFERS) return buffers;
|
|
285
|
-
const evictable = ids
|
|
286
|
-
.filter((id) => id !== activeSessionId && !buffers[id].isStreaming)
|
|
287
|
-
.sort((a, b) => buffers[a].lastTouched - buffers[b].lastTouched);
|
|
288
|
-
const next = { ...buffers };
|
|
289
|
-
for (const id of evictable.slice(0, ids.length - MAX_BUFFERS)) {
|
|
290
|
-
revokeAttachmentUrls(next[id].messages);
|
|
291
|
-
delete next[id];
|
|
292
|
-
}
|
|
293
|
-
return next;
|
|
294
|
-
}
|
|
295
|
-
|
|
296
|
-
export const useChatStore = create<ChatState>((set, get) => {
|
|
297
|
-
/**
|
|
298
|
-
* Immutably update one buffer. Draft mutations (key null) create the draft
|
|
299
|
-
* on demand; session mutations require an existing buffer — a frame for an
|
|
300
|
-
* evicted/never-opened session must not materialize a partial transcript
|
|
301
|
-
* (the view heals via session_resume instead).
|
|
302
|
-
*/
|
|
303
|
-
function mutateBuffer(
|
|
304
|
-
key: ChatKey,
|
|
305
|
-
fn: (chat: SessionChat) => Partial<SessionChat>,
|
|
306
|
-
createIfMissing = false
|
|
307
|
-
): void {
|
|
308
|
-
set((state) => {
|
|
309
|
-
if (key === null) {
|
|
310
|
-
const draft = state.draft ?? emptyChat();
|
|
311
|
-
return { draft: { ...draft, ...fn(draft), lastTouched: Date.now() } };
|
|
312
|
-
}
|
|
313
|
-
const existing = state.buffers[key] ?? (createIfMissing ? emptyChat() : undefined);
|
|
314
|
-
if (!existing) return state;
|
|
315
|
-
return {
|
|
316
|
-
buffers: {
|
|
317
|
-
...state.buffers,
|
|
318
|
-
[key]: { ...existing, ...fn(existing), lastTouched: Date.now() },
|
|
319
|
-
},
|
|
320
|
-
};
|
|
321
|
-
});
|
|
322
|
-
}
|
|
323
|
-
|
|
324
|
-
/** Update the last message of a buffer when it is an assistant message. */
|
|
325
|
-
function mutateLastAssistant(
|
|
326
|
-
key: ChatKey,
|
|
327
|
-
fn: (msg: ChatMessage) => ChatMessage,
|
|
328
|
-
extra?: (chat: SessionChat) => Partial<SessionChat>
|
|
329
|
-
): void {
|
|
330
|
-
mutateBuffer(key, (chat) => {
|
|
331
|
-
const msgs = [...chat.messages];
|
|
332
|
-
// The last ASSISTANT message, not the last message.
|
|
333
|
-
//
|
|
334
|
-
// A follow-up sent mid-stream appends a user message to the end of the
|
|
335
|
-
// buffer while the assistant is still streaming into the message before
|
|
336
|
-
// it. Indexing the end therefore aimed every subsequent delta at the
|
|
337
|
-
// user's own message, where `role === "assistant"` failed and the write
|
|
338
|
-
// was silently discarded — the turn kept running and its output stopped
|
|
339
|
-
// appearing. Scanning backwards costs nothing at these lengths and
|
|
340
|
-
// leaves single-message behaviour identical.
|
|
341
|
-
let index = -1;
|
|
342
|
-
for (let i = msgs.length - 1; i >= 0; i--) {
|
|
343
|
-
if (msgs[i].role === "assistant") {
|
|
344
|
-
index = i;
|
|
345
|
-
break;
|
|
346
|
-
}
|
|
347
|
-
}
|
|
348
|
-
let out: Partial<SessionChat> = {};
|
|
349
|
-
if (index !== -1) {
|
|
350
|
-
msgs[index] = fn(msgs[index]);
|
|
351
|
-
out = { messages: msgs };
|
|
352
|
-
}
|
|
353
|
-
return extra ? { ...out, ...extra(chat) } : out;
|
|
354
|
-
});
|
|
355
|
-
}
|
|
356
|
-
|
|
357
|
-
return {
|
|
358
|
-
buffers: {},
|
|
359
|
-
draft: null,
|
|
360
|
-
pendingDraftId: null,
|
|
361
|
-
// localStorage (not sessionStorage) so the active session id survives the
|
|
362
|
-
// PWA process being killed on mobile — that durability is what lets a cold
|
|
363
|
-
// relaunch re-request the full transcript instead of showing nothing.
|
|
364
|
-
activeSessionId: readPersistedSessionId(),
|
|
365
|
-
runStates: {},
|
|
366
|
-
queueNotes: {},
|
|
367
|
-
backendIds: {},
|
|
368
|
-
|
|
369
|
-
// createIfMissing: a user-initiated send must never be dropped, even when
|
|
370
|
-
// the active session's buffer hasn't been materialized yet (cold start
|
|
371
|
-
// racing the history replay).
|
|
372
|
-
addUserMessage: (key, text, source, attachments) =>
|
|
373
|
-
mutateBuffer(
|
|
374
|
-
key,
|
|
375
|
-
(chat) => ({
|
|
376
|
-
messages: [
|
|
377
|
-
...chat.messages,
|
|
378
|
-
{
|
|
379
|
-
id: nextId(),
|
|
380
|
-
role: "user",
|
|
381
|
-
content: text,
|
|
382
|
-
toolCalls: [],
|
|
383
|
-
parts: [],
|
|
384
|
-
isStreaming: false,
|
|
385
|
-
timestamp: Date.now(),
|
|
386
|
-
source: source ?? "typed",
|
|
387
|
-
...(attachments && attachments.length > 0
|
|
388
|
-
? { attachments, attachmentCount: attachments.length }
|
|
389
|
-
: {}),
|
|
390
|
-
},
|
|
391
|
-
],
|
|
392
|
-
}),
|
|
393
|
-
true
|
|
394
|
-
),
|
|
395
|
-
|
|
396
|
-
startAssistantMessage: (key) =>
|
|
397
|
-
mutateBuffer(key, (chat) => ({
|
|
398
|
-
messages: [
|
|
399
|
-
...chat.messages,
|
|
400
|
-
{
|
|
401
|
-
id: nextId(),
|
|
402
|
-
role: "assistant",
|
|
403
|
-
content: "",
|
|
404
|
-
thinking: "",
|
|
405
|
-
toolCalls: [],
|
|
406
|
-
parts: [],
|
|
407
|
-
isStreaming: true,
|
|
408
|
-
timestamp: Date.now(),
|
|
409
|
-
},
|
|
410
|
-
],
|
|
411
|
-
isStreaming: true,
|
|
412
|
-
})),
|
|
413
|
-
|
|
414
|
-
appendText: (key, text) =>
|
|
415
|
-
mutateLastAssistant(key, (last) => ({
|
|
416
|
-
...last,
|
|
417
|
-
content: last.content + text,
|
|
418
|
-
parts: appendPart(last.parts, "text", text),
|
|
419
|
-
})),
|
|
420
|
-
|
|
421
|
-
appendThinking: (key, text) =>
|
|
422
|
-
mutateLastAssistant(key, (last) => ({
|
|
423
|
-
...last,
|
|
424
|
-
thinking: (last.thinking || "") + text,
|
|
425
|
-
parts: appendPart(last.parts, "thinking", text),
|
|
426
|
-
})),
|
|
427
|
-
|
|
428
|
-
startToolCall: (key, toolUseId, toolName) =>
|
|
429
|
-
mutateLastAssistant(key, (last) => ({
|
|
430
|
-
...last,
|
|
431
|
-
parts: [...last.parts, { kind: "tool", toolIndex: last.toolCalls.length }],
|
|
432
|
-
toolCalls: [
|
|
433
|
-
...last.toolCalls,
|
|
434
|
-
{
|
|
435
|
-
id: toolUseId,
|
|
436
|
-
name: toolName,
|
|
437
|
-
input: {},
|
|
438
|
-
inputJson: "",
|
|
439
|
-
status: "streaming",
|
|
440
|
-
startedAt: Date.now(),
|
|
441
|
-
},
|
|
442
|
-
],
|
|
443
|
-
})),
|
|
444
|
-
|
|
445
|
-
appendToolInput: (key, partialJson) =>
|
|
446
|
-
mutateLastAssistant(key, (last) => {
|
|
447
|
-
if (last.toolCalls.length === 0) return last;
|
|
448
|
-
const tools = [...last.toolCalls];
|
|
449
|
-
const lastTool = tools[tools.length - 1];
|
|
450
|
-
tools[tools.length - 1] = {
|
|
451
|
-
...lastTool,
|
|
452
|
-
inputJson: lastTool.inputJson + partialJson,
|
|
453
|
-
};
|
|
454
|
-
return { ...last, toolCalls: tools };
|
|
455
|
-
}),
|
|
456
|
-
|
|
457
|
-
completeToolCall: (key, toolUseId, toolName, input) =>
|
|
458
|
-
mutateLastAssistant(key, (last) => ({
|
|
459
|
-
...last,
|
|
460
|
-
toolCalls: last.toolCalls.map((t) =>
|
|
461
|
-
t.id === toolUseId || (t.name === toolName && t.status === "streaming")
|
|
462
|
-
? {
|
|
463
|
-
...t,
|
|
464
|
-
id: toolUseId,
|
|
465
|
-
input,
|
|
466
|
-
status: "complete" as const,
|
|
467
|
-
// Input finished streaming — execution starts about now
|
|
468
|
-
startedAt: Date.now(),
|
|
469
|
-
}
|
|
470
|
-
: t
|
|
471
|
-
),
|
|
472
|
-
})),
|
|
473
|
-
|
|
474
|
-
requestToolApproval: (key, toolUseId, toolName, input, _description, kind) =>
|
|
475
|
-
mutateLastAssistant(key, (last) => {
|
|
476
|
-
// Check if tool call already exists (from streaming)
|
|
477
|
-
const existingIdx = last.toolCalls.findIndex(
|
|
478
|
-
(t) => t.id === toolUseId || (t.name === toolName && t.status === "streaming")
|
|
479
|
-
);
|
|
480
|
-
const tools = [...last.toolCalls];
|
|
481
|
-
const toolCall: ToolCall = {
|
|
482
|
-
id: toolUseId,
|
|
483
|
-
name: toolName,
|
|
484
|
-
input,
|
|
485
|
-
inputJson: JSON.stringify(input, null, 2),
|
|
486
|
-
status: "pending_approval",
|
|
487
|
-
...(kind ? { approvalKind: kind } : {}),
|
|
488
|
-
};
|
|
489
|
-
let parts = last.parts;
|
|
490
|
-
if (existingIdx >= 0) {
|
|
491
|
-
tools[existingIdx] = toolCall;
|
|
492
|
-
} else {
|
|
493
|
-
// Approval request for a tool that never streamed a start event —
|
|
494
|
-
// give it a chronological slot too.
|
|
495
|
-
parts = [...parts, { kind: "tool", toolIndex: tools.length }];
|
|
496
|
-
tools.push(toolCall);
|
|
497
|
-
}
|
|
498
|
-
return { ...last, toolCalls: tools, parts };
|
|
499
|
-
}),
|
|
500
|
-
|
|
501
|
-
resolveToolApproval: (key, toolUseId, approved) =>
|
|
502
|
-
mutateLastAssistant(key, (last) => ({
|
|
503
|
-
...last,
|
|
504
|
-
toolCalls: last.toolCalls.map((t) =>
|
|
505
|
-
t.id === toolUseId
|
|
506
|
-
? {
|
|
507
|
-
...t,
|
|
508
|
-
status: approved ? ("approved" as const) : ("denied" as const),
|
|
509
|
-
// Don't let approval wait time inflate the duration badge
|
|
510
|
-
...(approved ? { startedAt: Date.now() } : {}),
|
|
511
|
-
}
|
|
512
|
-
: t
|
|
513
|
-
),
|
|
514
|
-
})),
|
|
515
|
-
|
|
516
|
-
setToolResult: (key, toolUseId, output, isError) =>
|
|
517
|
-
mutateLastAssistant(key, (last) => ({
|
|
518
|
-
...last,
|
|
519
|
-
toolCalls: last.toolCalls.map((t) =>
|
|
520
|
-
t.id === toolUseId
|
|
521
|
-
? {
|
|
522
|
-
...t,
|
|
523
|
-
output,
|
|
524
|
-
isError,
|
|
525
|
-
status: "complete" as const,
|
|
526
|
-
endedAt: Date.now(),
|
|
527
|
-
}
|
|
528
|
-
: t
|
|
529
|
-
),
|
|
530
|
-
})),
|
|
531
|
-
|
|
532
|
-
setAskUserRequest: (key, requestId, questions) =>
|
|
533
|
-
mutateBuffer(key, (chat) => {
|
|
534
|
-
const exchange: AskUserExchange = { requestId, questions };
|
|
535
|
-
const msgs = [...chat.messages];
|
|
536
|
-
const lastIdx = msgs.length - 1;
|
|
537
|
-
const last = msgs[lastIdx];
|
|
538
|
-
if (last?.role === "assistant") {
|
|
539
|
-
msgs[lastIdx] = {
|
|
540
|
-
...last,
|
|
541
|
-
askUserExchanges: [...(last.askUserExchanges ?? []), exchange],
|
|
542
|
-
};
|
|
543
|
-
}
|
|
544
|
-
return { messages: msgs, askUser: exchange };
|
|
545
|
-
}),
|
|
546
|
-
|
|
547
|
-
submitAskUserAnswers: (key, requestId, answers, annotations) =>
|
|
548
|
-
mutateBuffer(key, (chat) => {
|
|
549
|
-
const update = (e: AskUserExchange): AskUserExchange =>
|
|
550
|
-
e.requestId === requestId ? { ...e, answers, annotations } : e;
|
|
551
|
-
const msgs = chat.messages.map((m) =>
|
|
552
|
-
m.askUserExchanges?.some((e) => e.requestId === requestId)
|
|
553
|
-
? { ...m, askUserExchanges: m.askUserExchanges.map(update) }
|
|
554
|
-
: m
|
|
555
|
-
);
|
|
556
|
-
const askUser =
|
|
557
|
-
chat.askUser?.requestId === requestId ? update(chat.askUser) : chat.askUser;
|
|
558
|
-
return { messages: msgs, askUser };
|
|
559
|
-
}),
|
|
560
|
-
|
|
561
|
-
cancelAskUser: (key, requestId) =>
|
|
562
|
-
mutateBuffer(key, (chat) => {
|
|
563
|
-
const update = (e: AskUserExchange): AskUserExchange =>
|
|
564
|
-
e.requestId === requestId ? { ...e, cancelled: true } : e;
|
|
565
|
-
const msgs = chat.messages.map((m) =>
|
|
566
|
-
m.askUserExchanges?.some((e) => e.requestId === requestId)
|
|
567
|
-
? { ...m, askUserExchanges: m.askUserExchanges.map(update) }
|
|
568
|
-
: m
|
|
569
|
-
);
|
|
570
|
-
const askUser =
|
|
571
|
-
chat.askUser?.requestId === requestId ? update(chat.askUser) : chat.askUser;
|
|
572
|
-
return { messages: msgs, askUser };
|
|
573
|
-
}),
|
|
574
|
-
|
|
575
|
-
clearAskUser: (key) => mutateBuffer(key, () => ({ askUser: null })),
|
|
576
|
-
|
|
577
|
-
finishAssistantMessage: (key) =>
|
|
578
|
-
mutateLastAssistant(
|
|
579
|
-
key,
|
|
580
|
-
(last) => ({ ...last, isStreaming: false }),
|
|
581
|
-
() => ({ isStreaming: false })
|
|
582
|
-
),
|
|
583
|
-
|
|
584
|
-
setStreaming: (key, streaming) => mutateBuffer(key, () => ({ isStreaming: streaming })),
|
|
585
|
-
|
|
586
|
-
setMessages: (key, messages) =>
|
|
587
|
-
set((state) => {
|
|
588
|
-
if (key === null) {
|
|
589
|
-
if (state.draft) revokeAttachmentUrls(state.draft.messages);
|
|
590
|
-
return {
|
|
591
|
-
draft: { ...emptyChat(), messages },
|
|
592
|
-
};
|
|
593
|
-
}
|
|
594
|
-
const existing = state.buffers[key];
|
|
595
|
-
if (existing) revokeAttachmentUrls(existing.messages);
|
|
596
|
-
const buffers = {
|
|
597
|
-
...state.buffers,
|
|
598
|
-
[key]: { ...emptyChat(), messages },
|
|
599
|
-
};
|
|
600
|
-
return { buffers: evictStale(buffers, state.activeSessionId) };
|
|
601
|
-
}),
|
|
602
|
-
|
|
603
|
-
appendMessages: (key, messages) =>
|
|
604
|
-
set((state) => {
|
|
605
|
-
if (key === null) {
|
|
606
|
-
const draft = state.draft ?? emptyChat();
|
|
607
|
-
return { draft: { ...draft, messages: [...draft.messages, ...messages] } };
|
|
608
|
-
}
|
|
609
|
-
const existing = state.buffers[key] ?? emptyChat();
|
|
610
|
-
return {
|
|
611
|
-
buffers: {
|
|
612
|
-
...state.buffers,
|
|
613
|
-
[key]: {
|
|
614
|
-
...existing,
|
|
615
|
-
messages: [...existing.messages, ...messages],
|
|
616
|
-
lastTouched: Date.now(),
|
|
617
|
-
},
|
|
618
|
-
},
|
|
619
|
-
};
|
|
620
|
-
}),
|
|
621
|
-
|
|
622
|
-
startDraftTurn: () => {
|
|
623
|
-
const id =
|
|
624
|
-
typeof crypto !== "undefined" && "randomUUID" in crypto
|
|
625
|
-
? crypto.randomUUID()
|
|
626
|
-
: `draft-${Date.now()}-${Math.random().toString(36).slice(2)}`;
|
|
627
|
-
set({ pendingDraftId: id });
|
|
628
|
-
return id;
|
|
629
|
-
},
|
|
630
|
-
|
|
631
|
-
bindDraftSession: (sessionId) =>
|
|
632
|
-
set((state) => {
|
|
633
|
-
const adopted = state.buffers[sessionId] ?? state.draft ?? emptyChat();
|
|
634
|
-
const buffers = evictStale(
|
|
635
|
-
{ ...state.buffers, [sessionId]: { ...adopted, lastTouched: Date.now() } },
|
|
636
|
-
sessionId
|
|
637
|
-
);
|
|
638
|
-
const followView = state.activeSessionId === null;
|
|
639
|
-
if (followView) persistSessionId(sessionId);
|
|
640
|
-
return {
|
|
641
|
-
buffers,
|
|
642
|
-
draft: null,
|
|
643
|
-
pendingDraftId: null,
|
|
644
|
-
...(followView ? { activeSessionId: sessionId } : {}),
|
|
645
|
-
};
|
|
646
|
-
}),
|
|
647
|
-
|
|
648
|
-
setActiveSession: (sessionId) =>
|
|
649
|
-
set((state) => {
|
|
650
|
-
persistSessionId(sessionId);
|
|
651
|
-
if (sessionId === null) return { activeSessionId: null };
|
|
652
|
-
const existing = state.buffers[sessionId];
|
|
653
|
-
const buffers = existing
|
|
654
|
-
? state.buffers
|
|
655
|
-
: evictStale({ ...state.buffers, [sessionId]: emptyChat() }, sessionId);
|
|
656
|
-
return { activeSessionId: sessionId, buffers };
|
|
657
|
-
}),
|
|
658
|
-
|
|
659
|
-
setRunState: (sessionId, runState, note) =>
|
|
660
|
-
set((state) => {
|
|
661
|
-
const noteChanged = (state.queueNotes[sessionId] ?? undefined) !== note;
|
|
662
|
-
if (state.runStates[sessionId] === runState && !noteChanged) return state;
|
|
663
|
-
|
|
664
|
-
const runStates = { ...state.runStates };
|
|
665
|
-
if (runState === "idle") delete runStates[sessionId];
|
|
666
|
-
else runStates[sessionId] = runState;
|
|
667
|
-
|
|
668
|
-
// The note belongs to the queued state; anything else ends it. A
|
|
669
|
-
// `queued` frame with no note also clears, so a queue that drained back
|
|
670
|
-
// under the warn mark stops claiming it is heavy.
|
|
671
|
-
const queueNotes = { ...state.queueNotes };
|
|
672
|
-
if (runState === "queued" && note) queueNotes[sessionId] = note;
|
|
673
|
-
else delete queueNotes[sessionId];
|
|
674
|
-
|
|
675
|
-
return { runStates, queueNotes };
|
|
676
|
-
}),
|
|
677
|
-
|
|
678
|
-
setSessionBackend: (sessionId, backendId) =>
|
|
679
|
-
set((state) =>
|
|
680
|
-
state.backendIds[sessionId] === backendId
|
|
681
|
-
? state
|
|
682
|
-
: { backendIds: { ...state.backendIds, [sessionId]: backendId } }
|
|
683
|
-
),
|
|
684
|
-
|
|
685
|
-
clearMessages: () => {
|
|
686
|
-
const state = get();
|
|
687
|
-
if (state.draft) revokeAttachmentUrls(state.draft.messages);
|
|
688
|
-
persistSessionId(null);
|
|
689
|
-
// Starting fresh: unpin the provider so the picker unlocks.
|
|
690
|
-
useProviderStore.getState().setPinned(null);
|
|
691
|
-
set({ draft: null, activeSessionId: null });
|
|
692
|
-
},
|
|
693
|
-
};
|
|
694
|
-
});
|
|
695
|
-
|
|
696
|
-
// Dev-only handle so browser automation / manual debugging can inject
|
|
697
|
-
// fixture messages without a live Claude session. Registered rather than
|
|
698
|
-
// installed: whether this is a development build is the shell's call
|
|
699
|
-
// (`configureBrainUi({ devTools: true })`), not something a component library
|
|
700
|
-
// infers from its bundler.
|
|
701
|
-
registerDevHandle(() => {
|
|
702
|
-
if (typeof window === "undefined") return;
|
|
703
|
-
(window as unknown as { __chatStore?: typeof useChatStore }).__chatStore =
|
|
704
|
-
useChatStore;
|
|
705
|
-
});
|
|
1
|
+
import { useRootStore } from "../root-context.js";
|
|
2
|
+
import { defaultRoot } from "../default-root.js";
|
|
3
|
+
export * from "./chat-state.js";
|
|
4
|
+
|
|
5
|
+
/** Hook reads the current provider. Statics address the default app only. */
|
|
6
|
+
export const useChatStore = Object.assign(
|
|
7
|
+
function useChatStore<T>(selector: (state: ReturnType<typeof defaultRoot.stores.chat.getState>) => T): T {
|
|
8
|
+
return useRootStore("chat", selector);
|
|
9
|
+
},
|
|
10
|
+
defaultRoot.stores.chat,
|
|
11
|
+
);
|