@sixb/app 0.1.13 → 0.1.14
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 +6 -0
- package/dist/agent/activity-label.d.ts.map +1 -1
- package/dist/agent/agent-chat.d.ts +1 -1
- package/dist/agent/agent-chat.d.ts.map +1 -1
- package/dist/agent/agent-context-provider.d.ts +1 -0
- package/dist/agent/agent-context-provider.d.ts.map +1 -1
- package/dist/agent/approvals.d.ts +110 -0
- package/dist/agent/approvals.d.ts.map +1 -0
- package/dist/agent/artifact-panel.d.ts +11 -7
- package/dist/agent/artifact-panel.d.ts.map +1 -1
- package/dist/agent/bash/bash-tool-view.d.ts +13 -0
- package/dist/agent/bash/bash-tool-view.d.ts.map +1 -1
- package/dist/agent/bash/interpret.d.ts +46 -2
- package/dist/agent/bash/interpret.d.ts.map +1 -1
- package/dist/agent/bash/model-media-view.d.ts +14 -0
- package/dist/agent/bash/model-media-view.d.ts.map +1 -0
- package/dist/agent/bash/shell.d.ts.map +1 -1
- package/dist/agent/components/agent-message-body.d.ts +21 -0
- package/dist/agent/components/agent-message-body.d.ts.map +1 -0
- package/dist/agent/components/agent-thread-switcher.d.ts +22 -1
- package/dist/agent/components/agent-thread-switcher.d.ts.map +1 -1
- package/dist/agent/components/approval-card.d.ts +17 -0
- package/dist/agent/components/approval-card.d.ts.map +1 -0
- package/dist/agent/components/approval-mode-chip.d.ts +17 -0
- package/dist/agent/components/approval-mode-chip.d.ts.map +1 -0
- package/dist/agent/components/auto-model-chip.d.ts +24 -0
- package/dist/agent/components/auto-model-chip.d.ts.map +1 -0
- package/dist/agent/components/composer.d.ts +21 -2
- package/dist/agent/components/composer.d.ts.map +1 -1
- package/dist/agent/components/context-chips.d.ts +4 -2
- package/dist/agent/components/context-chips.d.ts.map +1 -1
- package/dist/agent/components/conversation-panel.d.ts +13 -55
- package/dist/agent/components/conversation-panel.d.ts.map +1 -1
- package/dist/agent/components/message-parts.d.ts +17 -3
- package/dist/agent/components/message-parts.d.ts.map +1 -1
- package/dist/agent/components/message-view.d.ts +19 -21
- package/dist/agent/components/message-view.d.ts.map +1 -1
- package/dist/agent/components/model-controls.d.ts +8 -2
- package/dist/agent/components/model-controls.d.ts.map +1 -1
- package/dist/agent/components/model-picker-row.d.ts +5 -1
- package/dist/agent/components/model-picker-row.d.ts.map +1 -1
- package/dist/agent/components/participant-input.d.ts +29 -0
- package/dist/agent/components/participant-input.d.ts.map +1 -0
- package/dist/agent/components/provider-logo.d.ts +5 -4
- package/dist/agent/components/provider-logo.d.ts.map +1 -1
- package/dist/agent/components/reasoning-effort-slider.d.ts +8 -7
- package/dist/agent/components/reasoning-effort-slider.d.ts.map +1 -1
- package/dist/agent/components/sandbox-recovery.d.ts +8 -2
- package/dist/agent/components/sandbox-recovery.d.ts.map +1 -1
- package/dist/agent/components/shared-thread-notice.d.ts +10 -0
- package/dist/agent/components/shared-thread-notice.d.ts.map +1 -0
- package/dist/agent/components/thread-artifacts-menu.d.ts +8 -2
- package/dist/agent/components/thread-artifacts-menu.d.ts.map +1 -1
- package/dist/agent/components/thread-people.d.ts +24 -0
- package/dist/agent/components/thread-people.d.ts.map +1 -0
- package/dist/agent/components/transcript.d.ts +22 -29
- package/dist/agent/components/transcript.d.ts.map +1 -1
- package/dist/agent/conversation.d.ts +201 -0
- package/dist/agent/conversation.d.ts.map +1 -0
- package/dist/agent/delegation/child-card.d.ts +19 -0
- package/dist/agent/delegation/child-card.d.ts.map +1 -0
- package/dist/agent/delegation/child-cards.d.ts +9 -0
- package/dist/agent/delegation/child-cards.d.ts.map +1 -0
- package/dist/agent/delegation/child-group.d.ts +14 -0
- package/dist/agent/delegation/child-group.d.ts.map +1 -0
- package/dist/agent/delegation/child-parts.d.ts +50 -0
- package/dist/agent/delegation/child-parts.d.ts.map +1 -0
- package/dist/agent/delegation/child-work.d.ts +31 -0
- package/dist/agent/delegation/child-work.d.ts.map +1 -0
- package/dist/agent/delegation/context.d.ts +22 -0
- package/dist/agent/delegation/context.d.ts.map +1 -0
- package/dist/agent/delegation/interpret.d.ts +104 -0
- package/dist/agent/delegation/interpret.d.ts.map +1 -0
- package/dist/agent/delegation/model.d.ts +52 -0
- package/dist/agent/delegation/model.d.ts.map +1 -0
- package/dist/agent/delegation/use-children.d.ts +1007 -0
- package/dist/agent/delegation/use-children.d.ts.map +1 -0
- package/dist/agent/hooks/use-agent-conversation.d.ts +692 -131
- package/dist/agent/hooks/use-agent-conversation.d.ts.map +1 -1
- package/dist/agent/hooks/use-thread-sharing.d.ts +35 -0
- package/dist/agent/hooks/use-thread-sharing.d.ts.map +1 -0
- package/dist/agent/i18n/en.d.ts +313 -0
- package/dist/agent/i18n/en.d.ts.map +1 -1
- package/dist/agent/i18n/fr.d.ts.map +1 -1
- package/dist/agent/i18n/index.d.ts +608 -0
- package/dist/agent/i18n/index.d.ts.map +1 -1
- package/dist/agent/live-run.d.ts.map +1 -1
- package/dist/agent/memory-paths.d.ts +18 -0
- package/dist/agent/memory-paths.d.ts.map +1 -0
- package/dist/agent/message-agent/interpret.d.ts +21 -0
- package/dist/agent/message-agent/interpret.d.ts.map +1 -0
- package/dist/agent/message-authors.d.ts +56 -0
- package/dist/agent/message-authors.d.ts.map +1 -0
- package/dist/agent/model-selection.d.ts +10 -0
- package/dist/agent/model-selection.d.ts.map +1 -1
- package/dist/agent/observed-conversation.d.ts +26 -0
- package/dist/agent/observed-conversation.d.ts.map +1 -0
- package/dist/agent/observed-thread.d.ts +9 -0
- package/dist/agent/observed-thread.d.ts.map +1 -0
- package/dist/agent/parts.d.ts +5 -0
- package/dist/agent/parts.d.ts.map +1 -1
- package/dist/agent/publish-artifact/use-live-publishes.d.ts +5 -2
- package/dist/agent/publish-artifact/use-live-publishes.d.ts.map +1 -1
- package/dist/agent/read/interpret.d.ts +2 -0
- package/dist/agent/read/interpret.d.ts.map +1 -1
- package/dist/agent/run-presentation.d.ts +11 -0
- package/dist/agent/run-presentation.d.ts.map +1 -1
- package/dist/agent/sharing.d.ts +42 -0
- package/dist/agent/sharing.d.ts.map +1 -0
- package/dist/agent/tool-views/built-in.d.ts +5 -0
- package/dist/agent/tool-views/built-in.d.ts.map +1 -0
- package/dist/agent/tool-views/define.d.ts +79 -0
- package/dist/agent/tool-views/define.d.ts.map +1 -0
- package/dist/agent/tool-views/registry.d.ts +28 -0
- package/dist/agent/tool-views/registry.d.ts.map +1 -0
- package/dist/agent/utils/radio-group.d.ts +11 -0
- package/dist/agent/utils/radio-group.d.ts.map +1 -0
- package/dist/artifacts/card-details.d.ts.map +1 -1
- package/dist/artifacts/card-preview.d.ts.map +1 -1
- package/dist/artifacts/downloads.d.ts +26 -0
- package/dist/artifacts/downloads.d.ts.map +1 -0
- package/dist/artifacts/edit-session.d.ts +36 -0
- package/dist/artifacts/edit-session.d.ts.map +1 -0
- package/dist/artifacts/file-source.d.ts +27 -1
- package/dist/artifacts/file-source.d.ts.map +1 -1
- package/dist/artifacts/file-type-icon.d.ts +14 -0
- package/dist/artifacts/file-type-icon.d.ts.map +1 -0
- package/dist/artifacts/frame-embeds.d.ts +20 -0
- package/dist/artifacts/frame-embeds.d.ts.map +1 -0
- package/dist/artifacts/frame.d.ts +12 -1
- package/dist/artifacts/frame.d.ts.map +1 -1
- package/dist/artifacts/gallery.d.ts.map +1 -1
- package/dist/artifacts/history.d.ts +15 -0
- package/dist/artifacts/history.d.ts.map +1 -0
- package/dist/artifacts/kind-icon.d.ts +7 -0
- package/dist/artifacts/kind-icon.d.ts.map +1 -1
- package/dist/artifacts/messages.d.ts +518 -4
- package/dist/artifacts/messages.d.ts.map +1 -1
- package/dist/artifacts/page-queries.d.ts +22 -0
- package/dist/artifacts/page-queries.d.ts.map +1 -0
- package/dist/artifacts/page-state.d.ts +21 -0
- package/dist/artifacts/page-state.d.ts.map +1 -0
- package/dist/artifacts/people.d.ts +12 -0
- package/dist/artifacts/people.d.ts.map +1 -0
- package/dist/artifacts/person-avatar.d.ts +23 -0
- package/dist/artifacts/person-avatar.d.ts.map +1 -0
- package/dist/artifacts/publish-edit.d.ts +29 -0
- package/dist/artifacts/publish-edit.d.ts.map +1 -0
- package/dist/artifacts/queries.d.ts +77 -1
- package/dist/artifacts/queries.d.ts.map +1 -1
- package/dist/artifacts/references/references.d.ts.map +1 -1
- package/dist/artifacts/renderers/canvas/arrows.d.ts +21 -0
- package/dist/artifacts/renderers/canvas/arrows.d.ts.map +1 -0
- package/dist/artifacts/renderers/canvas/board.d.ts +54 -0
- package/dist/artifacts/renderers/canvas/board.d.ts.map +1 -0
- package/dist/artifacts/renderers/canvas/canvas.d.ts +27 -0
- package/dist/artifacts/renderers/canvas/canvas.d.ts.map +1 -0
- package/dist/artifacts/renderers/canvas/controls.d.ts +8 -0
- package/dist/artifacts/renderers/canvas/controls.d.ts.map +1 -0
- package/dist/artifacts/renderers/canvas/draft.d.ts +77 -0
- package/dist/artifacts/renderers/canvas/draft.d.ts.map +1 -0
- package/dist/artifacts/renderers/canvas/edit-mode.d.ts +55 -0
- package/dist/artifacts/renderers/canvas/edit-mode.d.ts.map +1 -0
- package/dist/artifacts/renderers/canvas/editing.d.ts +40 -0
- package/dist/artifacts/renderers/canvas/editing.d.ts.map +1 -0
- package/dist/artifacts/renderers/canvas/focus.d.ts +15 -0
- package/dist/artifacts/renderers/canvas/focus.d.ts.map +1 -0
- package/dist/artifacts/renderers/canvas/items.d.ts +13 -0
- package/dist/artifacts/renderers/canvas/items.d.ts.map +1 -0
- package/dist/artifacts/renderers/canvas/layout.d.ts +46 -0
- package/dist/artifacts/renderers/canvas/layout.d.ts.map +1 -0
- package/dist/artifacts/renderers/canvas/renderer.d.ts +13 -0
- package/dist/artifacts/renderers/canvas/renderer.d.ts.map +1 -0
- package/dist/artifacts/renderers/canvas/thumbnail.d.ts +10 -0
- package/dist/artifacts/renderers/canvas/thumbnail.d.ts.map +1 -0
- package/dist/artifacts/renderers/canvas/toolbar.d.ts +15 -0
- package/dist/artifacts/renderers/canvas/toolbar.d.ts.map +1 -0
- package/dist/artifacts/renderers/notice.d.ts.map +1 -1
- package/dist/artifacts/renderers/page.d.ts +34 -0
- package/dist/artifacts/renderers/page.d.ts.map +1 -0
- package/dist/artifacts/renderers/sheet/cell-editor.d.ts +21 -0
- package/dist/artifacts/renderers/sheet/cell-editor.d.ts.map +1 -0
- package/dist/artifacts/renderers/sheet/cells.d.ts +93 -0
- package/dist/artifacts/renderers/sheet/cells.d.ts.map +1 -0
- package/dist/artifacts/renderers/sheet/chart-data.d.ts +27 -7
- package/dist/artifacts/renderers/sheet/chart-data.d.ts.map +1 -1
- package/dist/artifacts/renderers/sheet/chart-icon.d.ts +5 -0
- package/dist/artifacts/renderers/sheet/chart-icon.d.ts.map +1 -0
- package/dist/artifacts/renderers/sheet/chart-locked.d.ts +9 -0
- package/dist/artifacts/renderers/sheet/chart-locked.d.ts.map +1 -0
- package/dist/artifacts/renderers/sheet/chart.d.ts +2 -1
- package/dist/artifacts/renderers/sheet/chart.d.ts.map +1 -1
- package/dist/artifacts/renderers/sheet/column-format.d.ts +28 -0
- package/dist/artifacts/renderers/sheet/column-format.d.ts.map +1 -0
- package/dist/artifacts/renderers/sheet/column-menu.d.ts +51 -0
- package/dist/artifacts/renderers/sheet/column-menu.d.ts.map +1 -0
- package/dist/artifacts/renderers/sheet/downloads.d.ts +10 -0
- package/dist/artifacts/renderers/sheet/downloads.d.ts.map +1 -0
- package/dist/artifacts/renderers/sheet/draft.d.ts +131 -0
- package/dist/artifacts/renderers/sheet/draft.d.ts.map +1 -0
- package/dist/artifacts/renderers/sheet/filter-panel.d.ts +20 -0
- package/dist/artifacts/renderers/sheet/filter-panel.d.ts.map +1 -0
- package/dist/artifacts/renderers/sheet/filter.d.ts +40 -0
- package/dist/artifacts/renderers/sheet/filter.d.ts.map +1 -0
- package/dist/artifacts/renderers/sheet/find-bar.d.ts +42 -0
- package/dist/artifacts/renderers/sheet/find-bar.d.ts.map +1 -0
- package/dist/artifacts/renderers/sheet/find.d.ts +18 -0
- package/dist/artifacts/renderers/sheet/find.d.ts.map +1 -0
- package/dist/artifacts/renderers/sheet/fit.d.ts +15 -0
- package/dist/artifacts/renderers/sheet/fit.d.ts.map +1 -0
- package/dist/artifacts/renderers/sheet/format.d.ts +14 -6
- package/dist/artifacts/renderers/sheet/format.d.ts.map +1 -1
- package/dist/artifacts/renderers/sheet/frame.d.ts +69 -0
- package/dist/artifacts/renderers/sheet/frame.d.ts.map +1 -0
- package/dist/artifacts/renderers/sheet/grid.d.ts +69 -6
- package/dist/artifacts/renderers/sheet/grid.d.ts.map +1 -1
- package/dist/artifacts/renderers/sheet/highlight.d.ts +32 -0
- package/dist/artifacts/renderers/sheet/highlight.d.ts.map +1 -0
- package/dist/artifacts/renderers/sheet/input.d.ts +30 -0
- package/dist/artifacts/renderers/sheet/input.d.ts.map +1 -0
- package/dist/artifacts/renderers/sheet/locked.d.ts +17 -0
- package/dist/artifacts/renderers/sheet/locked.d.ts.map +1 -0
- package/dist/artifacts/renderers/sheet/mini-chart.d.ts.map +1 -1
- package/dist/artifacts/renderers/sheet/model.d.ts +26 -4
- package/dist/artifacts/renderers/sheet/model.d.ts.map +1 -1
- package/dist/artifacts/renderers/sheet/selection.d.ts +30 -6
- package/dist/artifacts/renderers/sheet/selection.d.ts.map +1 -1
- package/dist/artifacts/renderers/sheet/sheet.d.ts +5 -5
- package/dist/artifacts/renderers/sheet/sheet.d.ts.map +1 -1
- package/dist/artifacts/renderers/sheet/totals.d.ts +16 -0
- package/dist/artifacts/renderers/sheet/totals.d.ts.map +1 -0
- package/dist/artifacts/renderers/sheet/view.d.ts +44 -0
- package/dist/artifacts/renderers/sheet/view.d.ts.map +1 -0
- package/dist/artifacts/renderers/sheet/workbook.d.ts +23 -3
- package/dist/artifacts/renderers/sheet/workbook.d.ts.map +1 -1
- package/dist/artifacts/renderers/sheet/xlsx.d.ts +18 -0
- package/dist/artifacts/renderers/sheet/xlsx.d.ts.map +1 -0
- package/dist/artifacts/renderers/sheet/zip.d.ts +12 -0
- package/dist/artifacts/renderers/sheet/zip.d.ts.map +1 -0
- package/dist/artifacts/renderers/slides/slides.d.ts.map +1 -1
- package/dist/artifacts/tones.d.ts +4 -0
- package/dist/artifacts/tones.d.ts.map +1 -0
- package/dist/artifacts/viewer.d.ts +2 -0
- package/dist/artifacts/viewer.d.ts.map +1 -1
- package/dist/auth.d.ts +6 -1
- package/dist/auth.d.ts.map +1 -1
- package/dist/chunk-0yb22w6m.js +1487 -0
- package/dist/chunk-0yb22w6m.js.map +18 -0
- package/dist/{chunk-c7gy61rx.js → chunk-1rhht9y0.js} +165 -4
- package/dist/chunk-1rhht9y0.js.map +10 -0
- package/dist/{chunk-gn3k23q5.js → chunk-53z5653y.js} +64 -3
- package/dist/chunk-53z5653y.js.map +11 -0
- package/dist/chunk-aes17xmx.js +29190 -0
- package/dist/chunk-aes17xmx.js.map +172 -0
- package/dist/{chunk-g3f4cm8x.js → chunk-k4epnkcr.js} +1 -1
- package/dist/{chunk-ng0hdnrq.js → chunk-sw3pyqgy.js} +3 -1
- package/dist/chunk-sw3pyqgy.js.map +10 -0
- package/dist/{chunk-3schcf10.js → chunk-vtp6nk44.js} +1 -1
- package/dist/codegen.d.ts.map +1 -1
- package/dist/createCustomApp.d.ts +1 -0
- package/dist/createCustomApp.d.ts.map +1 -1
- package/dist/index.d.ts +18 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +40 -7
- package/dist/index.js.map +3 -3
- package/dist/locale-messages.d.ts +1 -0
- package/dist/locale-messages.d.ts.map +1 -1
- package/dist/locale.d.ts +1 -0
- package/dist/locale.d.ts.map +1 -1
- package/dist/locale.js +1 -1
- package/dist/metadata.d.ts.map +1 -1
- package/dist/pages/observability/action-run.d.ts.map +1 -1
- package/dist/pages/observability/activity/messages.d.ts +14 -0
- package/dist/pages/observability/activity/messages.d.ts.map +1 -1
- package/dist/pages/observability/activity/thread.d.ts +6 -0
- package/dist/pages/observability/activity/thread.d.ts.map +1 -0
- package/dist/pages/observability/activity/timeline.d.ts.map +1 -1
- package/dist/pages/observability/ai-usage/calls.d.ts.map +1 -1
- package/dist/pages/observability/ai-usage/format.d.ts +16 -5
- package/dist/pages/observability/ai-usage/format.d.ts.map +1 -1
- package/dist/pages/observability/ai-usage/kinds.d.ts +40 -0
- package/dist/pages/observability/ai-usage/kinds.d.ts.map +1 -0
- package/dist/pages/observability/ai-usage/messages.d.ts +74 -12
- package/dist/pages/observability/ai-usage/messages.d.ts.map +1 -1
- package/dist/pages/observability/ai-usage/page.d.ts.map +1 -1
- package/dist/pages/observability/messages.d.ts +4 -0
- package/dist/pages/observability/messages.d.ts.map +1 -1
- package/dist/pages/ontology/actions.d.ts.map +1 -1
- package/dist/pages/ontology/components/action-button.d.ts +6 -0
- package/dist/pages/ontology/components/action-button.d.ts.map +1 -1
- package/dist/pages/ontology/components/user-picker.d.ts +37 -0
- package/dist/pages/ontology/components/user-picker.d.ts.map +1 -0
- package/dist/pages/ontology/workflows/run-input-form.d.ts.map +1 -1
- package/dist/pages/routes.d.ts +2 -0
- package/dist/pages/routes.d.ts.map +1 -1
- package/dist/pages/section-page.d.ts +13 -0
- package/dist/pages/section-page.d.ts.map +1 -1
- package/dist/pages/section-ui.d.ts.map +1 -1
- package/dist/pages/settings/controls.d.ts.map +1 -1
- package/dist/pages/settings/members.d.ts.map +1 -1
- package/dist/pages/settings/memory-contents.d.ts +30 -0
- package/dist/pages/settings/memory-contents.d.ts.map +1 -0
- package/dist/pages/settings/memory-entries.d.ts +42 -0
- package/dist/pages/settings/memory-entries.d.ts.map +1 -0
- package/dist/pages/settings/memory-files.d.ts +49 -0
- package/dist/pages/settings/memory-files.d.ts.map +1 -0
- package/dist/pages/settings/memory-history.d.ts +8 -0
- package/dist/pages/settings/memory-history.d.ts.map +1 -0
- package/dist/pages/settings/memory.d.ts +21 -0
- package/dist/pages/settings/memory.d.ts.map +1 -0
- package/dist/pages/settings/messages.d.ts +206 -0
- package/dist/pages/settings/messages.d.ts.map +1 -1
- package/dist/pages/settings/personal.d.ts +2 -2
- package/dist/pages/settings/personal.d.ts.map +1 -1
- package/dist/pages/settings/sessions.d.ts.map +1 -1
- package/dist/pages/values.d.ts +1 -0
- package/dist/pages/values.d.ts.map +1 -1
- package/dist/pages.d.ts +13 -16
- package/dist/pages.d.ts.map +1 -1
- package/dist/pages.js +6729 -4370
- package/dist/pages.js.map +32 -26
- package/dist/sections/catalog.d.ts.map +1 -1
- package/dist/sections/sections.d.ts.map +1 -1
- package/dist/server.js +68 -39
- package/dist/server.js.map +5 -5
- package/package.json +4 -4
- package/src/agent/activity-label.ts +17 -2
- package/src/agent/agent-chat.tsx +92 -104
- package/src/agent/agent-context-provider.tsx +1 -0
- package/src/agent/agent.css +82 -0
- package/src/agent/approvals.ts +268 -0
- package/src/agent/artifact-panel.tsx +22 -13
- package/src/agent/bash/bash-tool-view.tsx +98 -6
- package/src/agent/bash/interpret.ts +265 -3
- package/src/agent/bash/model-media-view.tsx +474 -0
- package/src/agent/bash/shell.ts +3 -2
- package/src/agent/components/agent-message-body.tsx +56 -0
- package/src/agent/components/agent-thread-switcher.tsx +216 -43
- package/src/agent/components/approval-card.tsx +840 -0
- package/src/agent/components/approval-mode-chip.tsx +227 -0
- package/src/agent/components/auto-model-chip.tsx +283 -0
- package/src/agent/components/composer.tsx +73 -3
- package/src/agent/components/context-chips.tsx +5 -6
- package/src/agent/components/conversation-panel.tsx +27 -149
- package/src/agent/components/message-parts.tsx +169 -54
- package/src/agent/components/message-view.tsx +114 -167
- package/src/agent/components/model-controls.tsx +29 -3
- package/src/agent/components/model-picker-row.tsx +22 -4
- package/src/agent/components/participant-input.tsx +165 -0
- package/src/agent/components/provider-logo.tsx +6 -1
- package/src/agent/components/reasoning-effort-slider.tsx +10 -8
- package/src/agent/components/sandbox-recovery.tsx +24 -5
- package/src/agent/components/shared-thread-notice.tsx +34 -0
- package/src/agent/components/thread-artifacts-menu.tsx +29 -12
- package/src/agent/components/thread-people.tsx +521 -0
- package/src/agent/components/transcript.tsx +314 -147
- package/src/agent/conversation.ts +634 -0
- package/src/agent/delegation/child-card.tsx +398 -0
- package/src/agent/delegation/child-cards.tsx +144 -0
- package/src/agent/delegation/child-group.tsx +150 -0
- package/src/agent/delegation/child-parts.tsx +321 -0
- package/src/agent/delegation/child-work.tsx +244 -0
- package/src/agent/delegation/context.ts +28 -0
- package/src/agent/delegation/interpret.ts +407 -0
- package/src/agent/delegation/model.ts +159 -0
- package/src/agent/delegation/use-children.ts +235 -0
- package/src/agent/hooks/use-agent-conversation.ts +856 -93
- package/src/agent/hooks/use-thread-sharing.ts +197 -0
- package/src/agent/i18n/en.ts +322 -0
- package/src/agent/i18n/fr.ts +334 -0
- package/src/agent/live-run.ts +23 -40
- package/src/agent/memory-paths.ts +41 -0
- package/src/agent/message-agent/interpret.ts +60 -0
- package/src/agent/message-authors.ts +115 -0
- package/src/agent/model-selection.ts +15 -0
- package/src/agent/observed-conversation.tsx +210 -0
- package/src/agent/observed-thread.ts +13 -0
- package/src/agent/parts.ts +23 -0
- package/src/agent/publish-artifact/use-live-publishes.ts +5 -2
- package/src/agent/read/interpret.ts +18 -0
- package/src/agent/read/read-tool-view.tsx +2 -2
- package/src/agent/run-presentation.ts +37 -1
- package/src/agent/sharing.ts +95 -0
- package/src/agent/tool-views/built-in.tsx +56 -0
- package/src/agent/tool-views/define.ts +150 -0
- package/src/agent/tool-views/registry.tsx +125 -0
- package/src/agent/utils/radio-group.ts +29 -0
- package/src/artifacts/artifacts.css +96 -0
- package/src/artifacts/card-details.ts +9 -1
- package/src/artifacts/card-preview.tsx +23 -12
- package/src/artifacts/downloads.tsx +130 -0
- package/src/artifacts/edit-session.tsx +115 -0
- package/src/artifacts/file-source.ts +94 -4
- package/src/artifacts/file-type-icon.tsx +114 -0
- package/src/artifacts/frame-embeds.tsx +113 -0
- package/src/artifacts/frame.tsx +143 -19
- package/src/artifacts/gallery.tsx +3 -0
- package/src/artifacts/history.ts +42 -0
- package/src/artifacts/kind-icon.tsx +31 -1
- package/src/artifacts/messages.ts +601 -16
- package/src/artifacts/page-queries.ts +80 -0
- package/src/artifacts/page-state.ts +211 -0
- package/src/artifacts/people.ts +19 -0
- package/src/artifacts/person-avatar.tsx +40 -0
- package/src/artifacts/publish-edit.ts +90 -0
- package/src/artifacts/queries.ts +242 -5
- package/src/artifacts/references/references.tsx +219 -18
- package/src/artifacts/renderers/canvas/arrows.tsx +134 -0
- package/src/artifacts/renderers/canvas/board.tsx +108 -0
- package/src/artifacts/renderers/canvas/canvas.tsx +195 -0
- package/src/artifacts/renderers/canvas/controls.tsx +75 -0
- package/src/artifacts/renderers/canvas/draft.ts +322 -0
- package/src/artifacts/renderers/canvas/edit-mode.tsx +301 -0
- package/src/artifacts/renderers/canvas/editing.tsx +187 -0
- package/src/artifacts/renderers/canvas/focus.tsx +128 -0
- package/src/artifacts/renderers/canvas/items.tsx +380 -0
- package/src/artifacts/renderers/canvas/layout.ts +132 -0
- package/src/artifacts/renderers/canvas/renderer.tsx +110 -0
- package/src/artifacts/renderers/canvas/thumbnail.tsx +144 -0
- package/src/artifacts/renderers/canvas/toolbar.tsx +316 -0
- package/src/artifacts/renderers/notice.tsx +3 -1
- package/src/artifacts/renderers/page.tsx +152 -0
- package/src/artifacts/renderers/sheet/cell-editor.tsx +125 -0
- package/src/artifacts/renderers/sheet/cells.tsx +462 -0
- package/src/artifacts/renderers/sheet/chart-data.ts +124 -14
- package/src/artifacts/renderers/sheet/chart-icon.ts +18 -0
- package/src/artifacts/renderers/sheet/chart-locked.tsx +30 -0
- package/src/artifacts/renderers/sheet/chart.tsx +153 -3
- package/src/artifacts/renderers/sheet/column-format.tsx +413 -0
- package/src/artifacts/renderers/sheet/column-menu.tsx +198 -0
- package/src/artifacts/renderers/sheet/downloads.tsx +88 -0
- package/src/artifacts/renderers/sheet/draft.ts +589 -0
- package/src/artifacts/renderers/sheet/filter-panel.tsx +255 -0
- package/src/artifacts/renderers/sheet/filter.ts +182 -0
- package/src/artifacts/renderers/sheet/find-bar.tsx +177 -0
- package/src/artifacts/renderers/sheet/find.ts +50 -0
- package/src/artifacts/renderers/sheet/fit.ts +54 -0
- package/src/artifacts/renderers/sheet/format.ts +48 -7
- package/src/artifacts/renderers/sheet/frame.tsx +531 -0
- package/src/artifacts/renderers/sheet/grid.tsx +1266 -287
- package/src/artifacts/renderers/sheet/highlight.ts +83 -0
- package/src/artifacts/renderers/sheet/input.ts +191 -0
- package/src/artifacts/renderers/sheet/locked.ts +112 -0
- package/src/artifacts/renderers/sheet/mini-chart.tsx +72 -4
- package/src/artifacts/renderers/sheet/model.ts +69 -8
- package/src/artifacts/renderers/sheet/selection.ts +136 -9
- package/src/artifacts/renderers/sheet/sheet.tsx +440 -264
- package/src/artifacts/renderers/sheet/totals.ts +54 -0
- package/src/artifacts/renderers/sheet/view.ts +96 -0
- package/src/artifacts/renderers/sheet/workbook.ts +107 -8
- package/src/artifacts/renderers/sheet/xlsx.ts +516 -0
- package/src/artifacts/renderers/sheet/zip.ts +108 -0
- package/src/artifacts/renderers/slides/slides.tsx +3 -55
- package/src/artifacts/tones.ts +14 -0
- package/src/artifacts/viewer.tsx +915 -96
- package/src/auth.ts +8 -2
- package/src/codegen.ts +29 -12
- package/src/createCustomApp.ts +59 -18
- package/src/index.ts +72 -2
- package/src/locale-messages.ts +2 -0
- package/src/metadata.ts +16 -3
- package/src/pages/observability/action-run.tsx +5 -1
- package/src/pages/observability/activity/messages.ts +16 -0
- package/src/pages/observability/activity/thread.tsx +150 -0
- package/src/pages/observability/activity/timeline.tsx +40 -3
- package/src/pages/observability/ai-usage/calls.tsx +61 -18
- package/src/pages/observability/ai-usage/format.ts +61 -8
- package/src/pages/observability/ai-usage/kinds.tsx +156 -0
- package/src/pages/observability/ai-usage/messages.ts +91 -14
- package/src/pages/observability/ai-usage/page.tsx +157 -48
- package/src/pages/observability/messages.ts +3 -0
- package/src/pages/ontology/actions.tsx +25 -4
- package/src/pages/ontology/components/action-button.tsx +53 -17
- package/src/pages/ontology/components/user-picker.tsx +161 -0
- package/src/pages/ontology/object-type.tsx +6 -0
- package/src/pages/ontology/workflows/run-input-form.tsx +12 -1
- package/src/pages/routes.ts +5 -0
- package/src/pages/section-page.tsx +27 -0
- package/src/pages/section-ui.tsx +3 -2
- package/src/pages/settings/controls.tsx +10 -2
- package/src/pages/settings/members.tsx +1 -5
- package/src/pages/settings/memory-contents.tsx +173 -0
- package/src/pages/settings/memory-entries.ts +112 -0
- package/src/pages/settings/memory-files.ts +195 -0
- package/src/pages/settings/memory-history.tsx +559 -0
- package/src/pages/settings/memory.tsx +993 -0
- package/src/pages/settings/messages.ts +232 -2
- package/src/pages/settings/personal.tsx +247 -27
- package/src/pages/settings/service-accounts.tsx +1 -1
- package/src/pages/settings/sessions.tsx +1 -4
- package/src/pages/values.tsx +65 -10
- package/src/pages.ts +16 -26
- package/src/sections/catalog.ts +18 -1
- package/src/sections/sections.tsx +2 -0
- package/dist/chunk-c7gy61rx.js.map +0 -10
- package/dist/chunk-gn3k23q5.js.map +0 -10
- package/dist/chunk-ng0hdnrq.js.map +0 -10
- package/dist/chunk-xxpdn63v.js +0 -15018
- package/dist/chunk-xxpdn63v.js.map +0 -105
- /package/dist/{chunk-g3f4cm8x.js.map → chunk-k4epnkcr.js.map} +0 -0
- /package/dist/{chunk-3schcf10.js.map → chunk-vtp6nk44.js.map} +0 -0
|
@@ -1,9 +1,17 @@
|
|
|
1
|
+
import { isSixbApiError, type ListAgentThreadApprovalsResponse } from "@sixb/client"
|
|
1
2
|
import {
|
|
2
3
|
cancelAgentRunMutation,
|
|
3
4
|
createAgentThreadMutation,
|
|
5
|
+
decideAgentApprovalMutation,
|
|
4
6
|
getAgentOptions,
|
|
7
|
+
getAgentPreferencesOptions,
|
|
8
|
+
getAgentPreferencesQueryKey,
|
|
5
9
|
getAgentThreadOptions,
|
|
6
10
|
getAgentThreadQueryKey,
|
|
11
|
+
listAgentApprovalsOptions,
|
|
12
|
+
listAgentApprovalsQueryKey,
|
|
13
|
+
listAgentThreadApprovalsOptions,
|
|
14
|
+
listAgentThreadApprovalsQueryKey,
|
|
7
15
|
listAgentThreadMessagesOptions,
|
|
8
16
|
listAgentThreadMessagesQueryKey,
|
|
9
17
|
listAgentThreadRunsOptions,
|
|
@@ -14,13 +22,34 @@ import {
|
|
|
14
22
|
postAgentThreadMessageMutation,
|
|
15
23
|
recreateAgentThreadSandboxMutation,
|
|
16
24
|
retryAgentRunMutation,
|
|
25
|
+
setAgentThreadApprovalModeMutation,
|
|
26
|
+
updateAgentPreferencesMutation,
|
|
17
27
|
useAgentActivityStream,
|
|
18
28
|
} from "@sixb/client/hooks"
|
|
19
29
|
import { MODEL_REASONING_LEVELS, type ModelReasoningLevel } from "@sixb/core/models"
|
|
20
30
|
import { useInfiniteQuery, useMutation, useQuery, useQueryClient } from "@tanstack/react-query"
|
|
21
|
-
import { useEffect, useMemo, useState } from "react"
|
|
31
|
+
import { useEffect, useMemo, useRef, useState } from "react"
|
|
32
|
+
import { useCurrentUser } from "../../session"
|
|
33
|
+
import {
|
|
34
|
+
type AgentApproval,
|
|
35
|
+
type AgentApprovalDecided,
|
|
36
|
+
type AgentApprovalDecision,
|
|
37
|
+
AgentApprovalDecisionError,
|
|
38
|
+
type AgentApprovalDecisionFailure,
|
|
39
|
+
type AgentApprovalMode,
|
|
40
|
+
isAwaitingApproval,
|
|
41
|
+
reportedApprovalOutcomes,
|
|
42
|
+
type TranscriptApprovals,
|
|
43
|
+
} from "../approvals"
|
|
44
|
+
import type { ComposerProps } from "../components/composer"
|
|
45
|
+
import type { SandboxRecoveryProps } from "../components/sandbox-recovery"
|
|
46
|
+
import type { TranscriptProps } from "../components/transcript"
|
|
47
|
+
import { conversationMessages, conversationTurn, type PendingUserMessage } from "../conversation"
|
|
48
|
+
import type { TranscriptDelegation } from "../delegation/context"
|
|
22
49
|
import { useAgentMessages } from "../i18n"
|
|
50
|
+
import { knownName } from "../message-authors"
|
|
23
51
|
import {
|
|
52
|
+
hasTiers,
|
|
24
53
|
type ModelPreference,
|
|
25
54
|
preferenceWithoutReasoning,
|
|
26
55
|
preferenceWithReasoning,
|
|
@@ -30,59 +59,165 @@ import { type RequesterSettings, sendWithRequesterSettings } from "../requester-
|
|
|
30
59
|
import {
|
|
31
60
|
EXTENDED_WAITING_STATUS_MS,
|
|
32
61
|
isActiveAgentRunStatus,
|
|
62
|
+
offersContinue,
|
|
33
63
|
presentActiveTurn,
|
|
34
64
|
selectActiveRunId,
|
|
35
65
|
shouldShowExtendedWaitingStatus,
|
|
36
66
|
} from "../run-presentation"
|
|
67
|
+
import {
|
|
68
|
+
canRetryRun,
|
|
69
|
+
canStopRun,
|
|
70
|
+
isShared,
|
|
71
|
+
personName,
|
|
72
|
+
requestedBySomeoneElse,
|
|
73
|
+
samePrincipal,
|
|
74
|
+
threadAccess,
|
|
75
|
+
threadOwner,
|
|
76
|
+
userPrincipal,
|
|
77
|
+
} from "../sharing"
|
|
37
78
|
import { THREAD_PAGE_SIZE } from "../thread-navigation"
|
|
38
79
|
import type { AgentContextEntryInput, AgentFileRef, AgentRun, LanguageModel } from "../types"
|
|
39
80
|
import { useThreadStream } from "./use-thread-stream"
|
|
40
81
|
|
|
41
82
|
interface PendingSend {
|
|
42
83
|
readonly run: AgentRun
|
|
84
|
+
/**
|
|
85
|
+
* Keep the turn's user message at the top while it answers. A resumed turn has none to show: it
|
|
86
|
+
* continues under the card that resumed it, where the reader already is.
|
|
87
|
+
*/
|
|
88
|
+
readonly anchor: boolean
|
|
43
89
|
}
|
|
44
90
|
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
readonly text: string
|
|
48
|
-
readonly attachments: readonly AgentFileRef[]
|
|
49
|
-
readonly context: readonly AgentContextEntryInput[]
|
|
50
|
-
messageId: string | null
|
|
51
|
-
}
|
|
91
|
+
/** Keys of the messages the reader sends, so each keeps its key once it is saved. */
|
|
92
|
+
let sentMessageCount = 0
|
|
52
93
|
|
|
53
94
|
const THREAD_LIST_QUERY = {
|
|
54
95
|
limit: String(THREAD_PAGE_SIZE),
|
|
55
96
|
order: "desc" as const,
|
|
56
97
|
}
|
|
57
98
|
|
|
99
|
+
/** Enough of a thread's held calls for every card: a turn holds a few, and a thread few turns. */
|
|
100
|
+
const THREAD_APPROVALS_QUERY = { limit: "200" }
|
|
101
|
+
|
|
102
|
+
/** The calls waiting for the reader across threads, for the thread list. */
|
|
103
|
+
const PENDING_APPROVALS_QUERY = { status: "pending" as const, limit: "200" }
|
|
104
|
+
|
|
105
|
+
/** The conversations others shared with the reader: one page, newest first. */
|
|
106
|
+
const SHARED_THREAD_LIST_QUERY = {
|
|
107
|
+
sharedWithMe: "true" as const,
|
|
108
|
+
limit: String(THREAD_PAGE_SIZE),
|
|
109
|
+
order: "desc" as const,
|
|
110
|
+
}
|
|
111
|
+
|
|
58
112
|
const MODEL_PREFERENCE_KEY = "sixb.agent-ui.model-preference"
|
|
113
|
+
const MODEL_PINS_KEY = "sixb.agent-ui.model-pins"
|
|
114
|
+
/** Pins kept per browser, the most recently chosen last; older ones fall back to Auto. */
|
|
115
|
+
const MAX_MODEL_PINS = 100
|
|
59
116
|
const REASONING_LEVELS = new Set<string>(MODEL_REASONING_LEVELS)
|
|
60
117
|
|
|
61
118
|
export interface UseAgentConversationInput {
|
|
119
|
+
/** The open thread, or null to start a new one with the next message. */
|
|
62
120
|
readonly threadId: string | null
|
|
63
|
-
|
|
121
|
+
/** The first message created a thread; show it from now on. */
|
|
64
122
|
readonly onThreadCreated: (threadId: string) => void
|
|
65
123
|
}
|
|
66
124
|
|
|
125
|
+
/** The parts of {@link ComposerProps} a conversation decides; the page adds the rest. */
|
|
126
|
+
export type ConversationComposerProps = Pick<
|
|
127
|
+
ComposerProps,
|
|
128
|
+
| "onSend"
|
|
129
|
+
| "error"
|
|
130
|
+
| "disabled"
|
|
131
|
+
| "pending"
|
|
132
|
+
| "running"
|
|
133
|
+
| "stopping"
|
|
134
|
+
| "onStop"
|
|
135
|
+
| "hint"
|
|
136
|
+
| "models"
|
|
137
|
+
| "selectedModel"
|
|
138
|
+
| "selectedReasoning"
|
|
139
|
+
| "modelsLoading"
|
|
140
|
+
| "modelsError"
|
|
141
|
+
| "onSelectModel"
|
|
142
|
+
| "onSelectReasoning"
|
|
143
|
+
| "onResetReasoning"
|
|
144
|
+
| "usingDefaultModel"
|
|
145
|
+
| "onResetModelSelection"
|
|
146
|
+
| "modelRouting"
|
|
147
|
+
| "draft"
|
|
148
|
+
| "draftAttachments"
|
|
149
|
+
| "draftContext"
|
|
150
|
+
| "draftNonce"
|
|
151
|
+
| "approvalMode"
|
|
152
|
+
| "defaultApprovalMode"
|
|
153
|
+
| "onApprovalModeChange"
|
|
154
|
+
| "onMakeApprovalModeDefault"
|
|
155
|
+
| "awaitingApproval"
|
|
156
|
+
>
|
|
157
|
+
|
|
67
158
|
export type AgentConversation = ReturnType<typeof useAgentConversation>
|
|
68
159
|
|
|
69
|
-
/**
|
|
70
|
-
export
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
160
|
+
/** Why a message, a retry or a stop did not go through, or the approval mode did not change. */
|
|
161
|
+
export type AgentConversationSendError =
|
|
162
|
+
/** Another answer holds the conversation; `someoneElse` when another person asked for it. */
|
|
163
|
+
| { readonly code: "busy"; readonly someoneElse: boolean }
|
|
164
|
+
/** The conversation's sandbox must be recovered before another answer. */
|
|
165
|
+
| { readonly code: "sandbox" }
|
|
166
|
+
| { readonly code: "send" | "retry" | "stop" | "approvalMode" }
|
|
167
|
+
|
|
168
|
+
/** The conversation's messages could not be read. */
|
|
169
|
+
export interface AgentConversationMessagesError {
|
|
170
|
+
readonly code: "load"
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
const MESSAGES_LOAD_ERROR: AgentConversationMessagesError = { code: "load" }
|
|
174
|
+
|
|
175
|
+
/**
|
|
176
|
+
* Everything one conversation with the project's agent needs: its threads, messages, turn and
|
|
177
|
+
* model choice, and the actions on them. Route-independent; the built-in chat and custom chats
|
|
178
|
+
* both render it, by spreading `transcriptProps` and `composerProps` or by drawing `messages` and
|
|
179
|
+
* `turn` themselves.
|
|
180
|
+
*/
|
|
181
|
+
export function useAgentConversation({ threadId, onThreadCreated }: UseAgentConversationInput) {
|
|
182
|
+
const agentMessages = useAgentMessages()
|
|
183
|
+
const labels = agentMessages.chat
|
|
76
184
|
const queryClient = useQueryClient()
|
|
185
|
+
const user = useCurrentUser()
|
|
77
186
|
const agentQuery = useQuery(getAgentOptions())
|
|
78
187
|
const modelsQuery = useQuery(listModelsOptions())
|
|
79
188
|
const refreshThreads = () =>
|
|
80
189
|
queryClient.invalidateQueries({ queryKey: listAgentThreadsQueryKey() })
|
|
190
|
+
const refreshApprovals = (threadId: string) =>
|
|
191
|
+
Promise.all([
|
|
192
|
+
queryClient.invalidateQueries({
|
|
193
|
+
queryKey: listAgentThreadApprovalsQueryKey({ path: { threadId } }),
|
|
194
|
+
}),
|
|
195
|
+
queryClient.invalidateQueries({ queryKey: listAgentApprovalsQueryKey() }),
|
|
196
|
+
])
|
|
81
197
|
const activityStream = useAgentActivityStream({
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
198
|
+
onActivity: (event) => {
|
|
199
|
+
// Someone else's turn in a shared conversation shows only through this feed: read the open
|
|
200
|
+
// thread again so its run is followed live. A run the view already follows streams itself.
|
|
201
|
+
if (event.threadId === threadId && event.runId !== activeRunId) {
|
|
202
|
+
void refreshThread(event.threadId)
|
|
203
|
+
return
|
|
204
|
+
}
|
|
205
|
+
|
|
206
|
+
void refreshThreads()
|
|
207
|
+
},
|
|
208
|
+
// A held call changed: its card, and the thread list's count of what waits for the reader. Its
|
|
209
|
+
// turn's runs follow from their own events.
|
|
210
|
+
onApprovalActivity: (event) => void refreshApprovals(event.threadId),
|
|
211
|
+
// On every (re)subscription: catch up with what changed while the socket was away.
|
|
212
|
+
onSubscribed: () => {
|
|
213
|
+
void queryClient.invalidateQueries({ queryKey: listAgentApprovalsQueryKey() })
|
|
214
|
+
void (threadId === null ? refreshThreads() : refreshThread(threadId))
|
|
215
|
+
},
|
|
85
216
|
})
|
|
217
|
+
|
|
218
|
+
// The project activity feed is primary. Poll only as a focus-aware recovery path while the
|
|
219
|
+
// socket is unavailable, rather than opening one connection per background thread.
|
|
220
|
+
const recoveryPollMs = !activityStream.connected || activityStream.error ? 10_000 : false
|
|
86
221
|
const threadsQuery = useInfiniteQuery({
|
|
87
222
|
...listAgentThreadsInfiniteOptions({ query: THREAD_LIST_QUERY }),
|
|
88
223
|
initialPageParam: { query: THREAD_LIST_QUERY },
|
|
@@ -96,15 +231,38 @@ export function useAgentConversation({
|
|
|
96
231
|
},
|
|
97
232
|
}
|
|
98
233
|
},
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
234
|
+
refetchInterval: recoveryPollMs,
|
|
235
|
+
})
|
|
236
|
+
// Nothing announces a new share or a removal: read the list again when the reader comes back.
|
|
237
|
+
const sharedThreadsQuery = useInfiniteQuery({
|
|
238
|
+
...listAgentThreadsInfiniteOptions({ query: SHARED_THREAD_LIST_QUERY }),
|
|
239
|
+
initialPageParam: { query: SHARED_THREAD_LIST_QUERY },
|
|
240
|
+
getNextPageParam: (lastPage, pages) => {
|
|
241
|
+
if (!lastPage.hasMore) return undefined
|
|
242
|
+
|
|
243
|
+
return {
|
|
244
|
+
query: {
|
|
245
|
+
...SHARED_THREAD_LIST_QUERY,
|
|
246
|
+
offset: String(pages.length * THREAD_PAGE_SIZE),
|
|
247
|
+
},
|
|
248
|
+
}
|
|
249
|
+
},
|
|
250
|
+
refetchInterval: recoveryPollMs,
|
|
251
|
+
refetchOnWindowFocus: true,
|
|
103
252
|
})
|
|
104
253
|
const currentAgent = agentQuery.data
|
|
105
254
|
const models = useMemo(() => modelsQuery.data?.language ?? [], [modelsQuery.data])
|
|
255
|
+
// With a list, the browser remembers one choice for every conversation. With tiers, each
|
|
256
|
+
// conversation starts on Auto and keeps the model pinned in it; a new one keeps its pin in
|
|
257
|
+
// memory until its first message creates the thread.
|
|
258
|
+
const tiered = hasTiers(models)
|
|
106
259
|
const [modelPreference, setModelPreference] = useState(readModelPreference)
|
|
107
|
-
const
|
|
260
|
+
const [modelPins, setModelPins] = useState(() => readModelPins() ?? {})
|
|
261
|
+
const [newThreadPin, setNewThreadPin] = useState<ModelPreference | null>(null)
|
|
262
|
+
const modelSelection = resolveModelSelection(
|
|
263
|
+
models,
|
|
264
|
+
tiered ? (threadId === null ? newThreadPin : (modelPins[threadId] ?? null)) : modelPreference
|
|
265
|
+
)
|
|
108
266
|
const selectedModel = modelSelection.model
|
|
109
267
|
const selectedReasoning = modelSelection.reasoning
|
|
110
268
|
const threads = useMemo(
|
|
@@ -112,15 +270,32 @@ export function useAgentConversation({
|
|
|
112
270
|
[threadsQuery.data]
|
|
113
271
|
)
|
|
114
272
|
|
|
273
|
+
const sharedThreads = useMemo(
|
|
274
|
+
() => sharedThreadsQuery.data?.pages.flatMap((page) => page.threads) ?? [],
|
|
275
|
+
[sharedThreadsQuery.data]
|
|
276
|
+
)
|
|
277
|
+
|
|
115
278
|
const threadQuery = useQuery({
|
|
116
279
|
...getAgentThreadOptions({ path: { threadId: threadId ?? "" } }),
|
|
117
280
|
enabled: threadId !== null,
|
|
281
|
+
refetchInterval: recoveryPollMs,
|
|
282
|
+
// A shared thread can lose its reader without an event: read it again when they come back.
|
|
283
|
+
refetchOnWindowFocus: (query) => isShared(query.state.data ?? null),
|
|
118
284
|
})
|
|
285
|
+
// A 404 after a read means the reader no longer reads it, such as a participant someone removed:
|
|
286
|
+
// the last copy the query keeps must not stand in for it.
|
|
287
|
+
const threadGone = isSixbApiError(threadQuery.error) && threadQuery.error.status === 404
|
|
119
288
|
const thread =
|
|
120
|
-
threadId !== null
|
|
121
|
-
? (threadQuery.data ??
|
|
289
|
+
threadId !== null && !threadGone
|
|
290
|
+
? (threadQuery.data ??
|
|
291
|
+
threads.find((candidate) => candidate.id === threadId) ??
|
|
292
|
+
sharedThreads.find((candidate) => candidate.id === threadId) ??
|
|
293
|
+
null)
|
|
122
294
|
: null
|
|
123
295
|
const threadUnavailable = threadId !== null && !threadQuery.isLoading && thread === null
|
|
296
|
+
const removedFromThread =
|
|
297
|
+
threadGone && threadQuery.data !== undefined && threadAccess(threadQuery.data, user) !== "owner"
|
|
298
|
+
const access = thread ? threadAccess(thread, user) : "owner"
|
|
124
299
|
|
|
125
300
|
const messagesQuery = useQuery({
|
|
126
301
|
...listAgentThreadMessagesOptions({
|
|
@@ -128,23 +303,70 @@ export function useAgentConversation({
|
|
|
128
303
|
query: { order: "asc" },
|
|
129
304
|
}),
|
|
130
305
|
enabled: threadId !== null,
|
|
306
|
+
refetchInterval: recoveryPollMs,
|
|
131
307
|
})
|
|
132
|
-
const
|
|
308
|
+
const savedMessages = useMemo(() => messagesQuery.data?.messages ?? [], [messagesQuery.data])
|
|
309
|
+
const approvalOutcomes = useMemo(() => reportedApprovalOutcomes(savedMessages), [savedMessages])
|
|
310
|
+
const authors = messagesQuery.data?.authors
|
|
133
311
|
const runsQuery = useQuery({
|
|
134
312
|
...listAgentThreadRunsOptions({
|
|
135
313
|
path: { threadId: threadId ?? "" },
|
|
136
314
|
query: { limit: "50", order: "desc" },
|
|
137
315
|
}),
|
|
138
316
|
enabled: threadId !== null,
|
|
317
|
+
refetchInterval: recoveryPollMs,
|
|
139
318
|
})
|
|
140
319
|
const runs = useMemo(() => runsQuery.data?.runs ?? [], [runsQuery.data])
|
|
141
320
|
const latestRun = runs[0] ?? null
|
|
142
321
|
|
|
143
|
-
const
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
322
|
+
const approvalsQuery = useQuery({
|
|
323
|
+
...listAgentThreadApprovalsOptions({
|
|
324
|
+
path: { threadId: threadId ?? "" },
|
|
325
|
+
query: THREAD_APPROVALS_QUERY,
|
|
326
|
+
}),
|
|
327
|
+
enabled: threadId !== null,
|
|
328
|
+
refetchInterval: recoveryPollMs,
|
|
329
|
+
})
|
|
330
|
+
// The list is oldest first: past one page, the calls still waiting are read on their own, so the
|
|
331
|
+
// newest always have their record.
|
|
332
|
+
const pendingHereQuery = useQuery({
|
|
333
|
+
...listAgentThreadApprovalsOptions({
|
|
334
|
+
path: { threadId: threadId ?? "" },
|
|
335
|
+
query: { ...THREAD_APPROVALS_QUERY, status: "pending" },
|
|
336
|
+
}),
|
|
337
|
+
enabled: threadId !== null && approvalsQuery.data?.hasMore === true,
|
|
338
|
+
refetchInterval: recoveryPollMs,
|
|
339
|
+
})
|
|
340
|
+
const approvals = useMemo(() => {
|
|
341
|
+
if (threadId === null) return []
|
|
342
|
+
const read = approvalsQuery.data?.approvals ?? []
|
|
343
|
+
const known = new Set(read.map((approval) => approval.id))
|
|
344
|
+
const pending = (pendingHereQuery.data?.approvals ?? []).filter(
|
|
345
|
+
(approval) => !known.has(approval.id)
|
|
346
|
+
)
|
|
347
|
+
return pending.length === 0 ? read : [...read, ...pending]
|
|
348
|
+
}, [threadId, approvalsQuery.data, pendingHereQuery.data])
|
|
349
|
+
const pendingApprovalsQuery = useQuery({
|
|
350
|
+
...listAgentApprovalsOptions({ query: PENDING_APPROVALS_QUERY }),
|
|
351
|
+
refetchInterval: recoveryPollMs,
|
|
352
|
+
retry: false,
|
|
353
|
+
})
|
|
354
|
+
/** The threads where a call waits for the reader. */
|
|
355
|
+
const waitingThreadIds = useMemo(
|
|
356
|
+
() =>
|
|
357
|
+
new Set(
|
|
358
|
+
(pendingApprovalsQuery.data?.approvals ?? []).map((approval) => approval.threadId)
|
|
359
|
+
) as ReadonlySet<string>,
|
|
360
|
+
[pendingApprovalsQuery.data]
|
|
147
361
|
)
|
|
362
|
+
|
|
363
|
+
const [pendingSend, setPendingSend] = useState<PendingSend | null>(null)
|
|
364
|
+
const [pendingUser, setPendingUser] = useState<PendingUserMessage | null>(null)
|
|
365
|
+
const [sentKeys, setSentKeys] = useState<ReadonlyMap<string, string>>(() => new Map())
|
|
366
|
+
const [sendError, setSendError] = useState<{
|
|
367
|
+
threadId: string | null
|
|
368
|
+
failure: TurnFailure
|
|
369
|
+
} | null>(null)
|
|
148
370
|
const [draftReseed, setDraftReseed] = useState<{
|
|
149
371
|
text: string
|
|
150
372
|
attachments: readonly AgentFileRef[]
|
|
@@ -152,6 +374,18 @@ export function useAgentConversation({
|
|
|
152
374
|
nonce: number
|
|
153
375
|
}>({ text: "", attachments: [], context: [], nonce: 0 })
|
|
154
376
|
const [stoppingRunId, setStoppingRunId] = useState<string | null>(null)
|
|
377
|
+
const stopRef = useRef<(approval: AgentApproval) => Promise<void>>(async () => {})
|
|
378
|
+
const decideRef = useRef<NonNullable<TranscriptApprovals["decide"]>>(async () => {
|
|
379
|
+
throw new AgentApprovalDecisionError("failed")
|
|
380
|
+
})
|
|
381
|
+
// The mode the chip shows while a new conversation has no thread to keep it in yet, or until the
|
|
382
|
+
// thread confirms a change.
|
|
383
|
+
const [chosenApprovalMode, setChosenApprovalMode] = useState<{
|
|
384
|
+
readonly threadId: string | null
|
|
385
|
+
readonly mode: AgentApprovalMode
|
|
386
|
+
} | null>(null)
|
|
387
|
+
/** The thread whose answer Continue is asking for, until the API accepts or refuses it. */
|
|
388
|
+
const [continuingThreadId, setContinuingThreadId] = useState<string | null>(null)
|
|
155
389
|
|
|
156
390
|
const pendingRun =
|
|
157
391
|
pendingSend && threadId !== null && pendingSend.run.threadId === threadId
|
|
@@ -164,7 +398,7 @@ export function useAgentConversation({
|
|
|
164
398
|
const { live, run: streamRun, reconnecting } = useThreadStream({ threadId, runId: activeRunId })
|
|
165
399
|
const finalizedMessageInDurable =
|
|
166
400
|
live.finalizedMessageId !== null &&
|
|
167
|
-
|
|
401
|
+
savedMessages.some((message) => message.id === live.finalizedMessageId)
|
|
168
402
|
|
|
169
403
|
useEffect(() => {
|
|
170
404
|
if (!pendingSend || pendingSend.run.id !== activeRunId) return
|
|
@@ -192,10 +426,13 @@ export function useAgentConversation({
|
|
|
192
426
|
setPendingUser(null)
|
|
193
427
|
return
|
|
194
428
|
}
|
|
195
|
-
if (
|
|
429
|
+
if (
|
|
430
|
+
pendingUser.messageId &&
|
|
431
|
+
savedMessages.some((message) => message.id === pendingUser.messageId)
|
|
432
|
+
) {
|
|
196
433
|
setPendingUser(null)
|
|
197
434
|
}
|
|
198
|
-
}, [pendingUser, threadId,
|
|
435
|
+
}, [pendingUser, threadId, savedMessages])
|
|
199
436
|
|
|
200
437
|
useEffect(() => {
|
|
201
438
|
setSendError((current) => (current && current.threadId === threadId ? current : null))
|
|
@@ -206,6 +443,26 @@ export function useAgentConversation({
|
|
|
206
443
|
const cancelRun = useMutation(cancelAgentRunMutation())
|
|
207
444
|
const retryRun = useMutation(retryAgentRunMutation())
|
|
208
445
|
const recreateSandbox = useMutation(recreateAgentThreadSandboxMutation())
|
|
446
|
+
const decideApproval = useMutation(decideAgentApprovalMutation())
|
|
447
|
+
// Each runs after the one before, so the last choice is the one the server keeps.
|
|
448
|
+
const saveThreadApprovalMode = useMutation({
|
|
449
|
+
...setAgentThreadApprovalModeMutation(),
|
|
450
|
+
scope: { id: "agent-thread-approval-mode" },
|
|
451
|
+
})
|
|
452
|
+
const savePreferences = useMutation({
|
|
453
|
+
...updateAgentPreferencesMutation(),
|
|
454
|
+
scope: { id: "agent-preferences" },
|
|
455
|
+
})
|
|
456
|
+
|
|
457
|
+
const preferencesQuery = useQuery({ ...getAgentPreferencesOptions(), retry: false })
|
|
458
|
+
const defaultApprovalMode = preferencesQuery.data?.approvalMode
|
|
459
|
+
const chosenHere =
|
|
460
|
+
chosenApprovalMode && chosenApprovalMode.threadId === threadId ? chosenApprovalMode.mode : null
|
|
461
|
+
// The thread read alone carries the reader's mode in it; a new conversation starts on their
|
|
462
|
+
// default. Unknown until either loads: the chip waits, and a message sent meanwhile carries no
|
|
463
|
+
// mode, so the server picks the reader's own instead of a default shown by mistake.
|
|
464
|
+
const approvalMode: AgentApprovalMode | undefined =
|
|
465
|
+
chosenHere ?? (threadId !== null ? threadQuery.data?.approvalMode : defaultApprovalMode)
|
|
209
466
|
|
|
210
467
|
const presentation = presentActiveTurn({
|
|
211
468
|
activeRunId,
|
|
@@ -213,7 +470,7 @@ export function useAgentConversation({
|
|
|
213
470
|
streamRun,
|
|
214
471
|
live,
|
|
215
472
|
runs,
|
|
216
|
-
messages,
|
|
473
|
+
messages: savedMessages,
|
|
217
474
|
messagesLoading: messagesQuery.isFetching,
|
|
218
475
|
})
|
|
219
476
|
const isRunning = presentation.kind === "responding"
|
|
@@ -225,15 +482,28 @@ export function useAgentConversation({
|
|
|
225
482
|
setStoppingRunId((current) => (current === activeRunId ? current : null))
|
|
226
483
|
}, [activeRunId])
|
|
227
484
|
|
|
485
|
+
// Who asked for the answer in flight decides whether a participant may stop it.
|
|
486
|
+
const activeRun =
|
|
487
|
+
[pendingRun, streamRun, ...runs].find((run) => run !== null && run.id === activeRunId) ?? null
|
|
488
|
+
|
|
228
489
|
const stop = () => {
|
|
229
|
-
if (threadId === null || activeRunId === null) return
|
|
490
|
+
if (threadId === null || activeRunId === null || !canStop) return
|
|
230
491
|
setStoppingRunId(activeRunId)
|
|
231
492
|
cancelRun.mutate(
|
|
232
493
|
{ path: { threadId }, body: { runId: activeRunId } },
|
|
233
|
-
{
|
|
494
|
+
{
|
|
495
|
+
onError: () => {
|
|
496
|
+
setStoppingRunId(null)
|
|
497
|
+
setSendError({ threadId, failure: "stop" })
|
|
498
|
+
void refreshThread(threadId)
|
|
499
|
+
},
|
|
500
|
+
}
|
|
234
501
|
)
|
|
235
502
|
}
|
|
236
503
|
|
|
504
|
+
// The turn runs in the mode the chip shows, whatever another device chose since.
|
|
505
|
+
const turnApprovalMode = approvalMode === undefined ? {} : { approvalMode }
|
|
506
|
+
|
|
237
507
|
const send = async (
|
|
238
508
|
text: string,
|
|
239
509
|
attachments: readonly AgentFileRef[],
|
|
@@ -242,17 +512,28 @@ export function useAgentConversation({
|
|
|
242
512
|
if (isRunning) return
|
|
243
513
|
setSendError(null)
|
|
244
514
|
const targetThreadId = threadId
|
|
515
|
+
const key = `sent:${++sentMessageCount}`
|
|
245
516
|
let createdThreadId: string | null = null
|
|
246
517
|
try {
|
|
247
518
|
if (targetThreadId !== null) {
|
|
248
|
-
setPendingUser({
|
|
519
|
+
setPendingUser({
|
|
520
|
+
key,
|
|
521
|
+
threadId: targetThreadId,
|
|
522
|
+
text,
|
|
523
|
+
attachments,
|
|
524
|
+
context,
|
|
525
|
+
messageId: null,
|
|
526
|
+
})
|
|
249
527
|
const response = await sendWithRequesterSettings((settings) =>
|
|
250
528
|
postMessage.mutateAsync({
|
|
251
529
|
path: { threadId: targetThreadId },
|
|
252
|
-
body:
|
|
530
|
+
body: {
|
|
531
|
+
...messageBody(text, attachments, context, modelSelection.request, settings),
|
|
532
|
+
...turnApprovalMode,
|
|
533
|
+
},
|
|
253
534
|
})
|
|
254
535
|
)
|
|
255
|
-
recordAcceptedSend(response.run)
|
|
536
|
+
recordAcceptedSend(response.run, key)
|
|
256
537
|
await Promise.all([
|
|
257
538
|
queryClient.invalidateQueries({
|
|
258
539
|
queryKey: listAgentThreadMessagesQueryKey({ path: { threadId: targetThreadId } }),
|
|
@@ -267,18 +548,36 @@ export function useAgentConversation({
|
|
|
267
548
|
body: { title: deriveTitle(text) },
|
|
268
549
|
})
|
|
269
550
|
createdThreadId = created.thread.id
|
|
270
|
-
setPendingUser({
|
|
551
|
+
setPendingUser({
|
|
552
|
+
key,
|
|
553
|
+
threadId: createdThreadId,
|
|
554
|
+
text,
|
|
555
|
+
attachments,
|
|
556
|
+
context,
|
|
557
|
+
messageId: null,
|
|
558
|
+
})
|
|
271
559
|
const newThreadId = createdThreadId
|
|
560
|
+
// A mode chosen before the thread existed is the reader's choice in it from now on.
|
|
561
|
+
if (chosenHere !== null && chosenHere !== defaultApprovalMode) {
|
|
562
|
+
keepThreadApprovalMode(newThreadId, chosenHere).catch(() =>
|
|
563
|
+
setSendError({ threadId: newThreadId, failure: "approvalMode" })
|
|
564
|
+
)
|
|
565
|
+
}
|
|
272
566
|
const response = await sendWithRequesterSettings((settings) =>
|
|
273
567
|
postMessage.mutateAsync({
|
|
274
568
|
path: { threadId: newThreadId },
|
|
275
|
-
body:
|
|
569
|
+
body: {
|
|
570
|
+
...messageBody(text, attachments, context, modelSelection.request, settings),
|
|
571
|
+
...turnApprovalMode,
|
|
572
|
+
},
|
|
276
573
|
})
|
|
277
574
|
)
|
|
278
|
-
recordAcceptedSend(response.run)
|
|
575
|
+
recordAcceptedSend(response.run, key)
|
|
576
|
+
// The next new conversation starts from the default again.
|
|
577
|
+
setChosenApprovalMode((current) => (current?.threadId === null ? null : current))
|
|
279
578
|
await queryClient.invalidateQueries({ queryKey: listAgentThreadsQueryKey() })
|
|
280
|
-
|
|
281
|
-
} catch {
|
|
579
|
+
showCreatedThread(createdThreadId)
|
|
580
|
+
} catch (error) {
|
|
282
581
|
// Restore the exact submitted snapshot. In particular, do not re-read ambient page context:
|
|
283
582
|
// navigation may have changed it while the request was in flight.
|
|
284
583
|
setPendingUser(null)
|
|
@@ -290,34 +589,51 @@ export function useAgentConversation({
|
|
|
290
589
|
}))
|
|
291
590
|
setSendError({
|
|
292
591
|
threadId: createdThreadId ?? targetThreadId,
|
|
293
|
-
|
|
592
|
+
failure: sendFailure(error),
|
|
294
593
|
})
|
|
295
|
-
if (createdThreadId)
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
}
|
|
301
|
-
void queryClient.invalidateQueries({ queryKey: listAgentThreadsQueryKey() })
|
|
594
|
+
if (createdThreadId) showCreatedThread(createdThreadId)
|
|
595
|
+
|
|
596
|
+
// A refusal can mean another turn holds the thread: read who asked for it, too.
|
|
597
|
+
if (targetThreadId !== null) void refreshThread(targetThreadId)
|
|
598
|
+
else void queryClient.invalidateQueries({ queryKey: listAgentThreadsQueryKey() })
|
|
302
599
|
}
|
|
303
600
|
}
|
|
304
601
|
|
|
305
|
-
|
|
306
|
-
|
|
602
|
+
// A model pinned before the thread existed stays pinned in it, from the moment it shows.
|
|
603
|
+
const showCreatedThread = (createdThreadId: string) => {
|
|
604
|
+
if (tiered && newThreadPin) pinModel(createdThreadId, newThreadPin)
|
|
605
|
+
onThreadCreated(createdThreadId)
|
|
606
|
+
}
|
|
607
|
+
|
|
608
|
+
// The saved message keeps the key the reader's pending copy had.
|
|
609
|
+
const recordAcceptedSend = (run: AgentRun, key: string) => {
|
|
610
|
+
setPendingSend({ run, anchor: true })
|
|
611
|
+
setSentKeys((current) => new Map(current).set(run.triggerMessageId, key))
|
|
307
612
|
setPendingUser((current) =>
|
|
308
|
-
current && current.
|
|
309
|
-
? { ...current, messageId: run.triggerMessageId }
|
|
310
|
-
: current
|
|
613
|
+
current && current.key === key ? { ...current, messageId: run.triggerMessageId } : current
|
|
311
614
|
)
|
|
312
615
|
}
|
|
313
616
|
|
|
314
|
-
|
|
315
|
-
|
|
617
|
+
/** Run again the turn that never answered. */
|
|
618
|
+
const retry = () => {
|
|
619
|
+
if (threadId === null || !canRetry) return
|
|
620
|
+
if (
|
|
621
|
+
presentation.kind !== "failed" &&
|
|
622
|
+
presentation.kind !== "timeout" &&
|
|
623
|
+
presentation.kind !== "interrupted"
|
|
624
|
+
) {
|
|
625
|
+
return
|
|
626
|
+
}
|
|
627
|
+
|
|
316
628
|
retryRun.mutate(
|
|
317
|
-
{ path: { threadId, runId:
|
|
629
|
+
{ path: { threadId, runId: presentation.run.id } },
|
|
318
630
|
{
|
|
319
631
|
onSuccess: (response) => {
|
|
320
|
-
setPendingSend({ run: response.run })
|
|
632
|
+
setPendingSend({ run: response.run, anchor: true })
|
|
633
|
+
void refreshThread(threadId)
|
|
634
|
+
},
|
|
635
|
+
onError: () => {
|
|
636
|
+
setSendError({ threadId, failure: "retry" })
|
|
321
637
|
void refreshThread(threadId)
|
|
322
638
|
},
|
|
323
639
|
}
|
|
@@ -336,26 +652,122 @@ export function useAgentConversation({
|
|
|
336
652
|
queryKey: getAgentThreadQueryKey({ path: { threadId } }),
|
|
337
653
|
}),
|
|
338
654
|
queryClient.invalidateQueries({ queryKey: listAgentThreadsQueryKey() }),
|
|
655
|
+
queryClient.invalidateQueries({
|
|
656
|
+
queryKey: listAgentThreadApprovalsQueryKey({ path: { threadId } }),
|
|
657
|
+
}),
|
|
339
658
|
])
|
|
340
659
|
|
|
660
|
+
const keepThreadApprovalMode = async (threadId: string, mode: AgentApprovalMode) => {
|
|
661
|
+
const updated = await saveThreadApprovalMode.mutateAsync({
|
|
662
|
+
path: { threadId },
|
|
663
|
+
body: { approvalMode: mode },
|
|
664
|
+
})
|
|
665
|
+
queryClient.setQueryData(getAgentThreadQueryKey({ path: { threadId } }), updated)
|
|
666
|
+
}
|
|
667
|
+
|
|
668
|
+
/**
|
|
669
|
+
* What the reader's next turns here may change without asking. In a thread it is kept as their
|
|
670
|
+
* own choice there, on every device; in a new conversation, until its first message makes one.
|
|
671
|
+
*/
|
|
672
|
+
const setApprovalMode = (mode: AgentApprovalMode) => {
|
|
673
|
+
setChosenApprovalMode({ threadId, mode })
|
|
674
|
+
if (threadId === null) return
|
|
675
|
+
|
|
676
|
+
// Saves run one after the other: until the last choice is saved, the chip keeps showing it.
|
|
677
|
+
const settle = () =>
|
|
678
|
+
setChosenApprovalMode((current) =>
|
|
679
|
+
current?.threadId === threadId && current.mode === mode ? null : current
|
|
680
|
+
)
|
|
681
|
+
keepThreadApprovalMode(threadId, mode)
|
|
682
|
+
.then(settle)
|
|
683
|
+
.catch(() => {
|
|
684
|
+
settle()
|
|
685
|
+
setSendError({ threadId, failure: "approvalMode" })
|
|
686
|
+
})
|
|
687
|
+
}
|
|
688
|
+
|
|
689
|
+
/** The reader's mode in conversations where they chose none, new ones included. */
|
|
690
|
+
const setDefaultApprovalMode = (mode: AgentApprovalMode) => {
|
|
691
|
+
savePreferences.mutate(
|
|
692
|
+
{ body: { approvalMode: mode } },
|
|
693
|
+
{
|
|
694
|
+
onSuccess: (preferences) => {
|
|
695
|
+
queryClient.setQueryData(getAgentPreferencesQueryKey(), preferences)
|
|
696
|
+
// The open thread follows the new default unless the reader chose a mode there.
|
|
697
|
+
if (threadId !== null) {
|
|
698
|
+
void queryClient.invalidateQueries({
|
|
699
|
+
queryKey: getAgentThreadQueryKey({ path: { threadId } }),
|
|
700
|
+
})
|
|
701
|
+
}
|
|
702
|
+
},
|
|
703
|
+
onError: () => setSendError({ threadId, failure: "approvalMode" }),
|
|
704
|
+
}
|
|
705
|
+
)
|
|
706
|
+
}
|
|
707
|
+
|
|
708
|
+
/**
|
|
709
|
+
* Approve or deny a held call as the reader, who must have asked for its turn. An approved call
|
|
710
|
+
* runs before this resolves, and the card shows how it ended; the decision that settles the
|
|
711
|
+
* turn's last call resumes it, and the conversation follows the new turn under the cards.
|
|
712
|
+
*/
|
|
713
|
+
const decide = async (
|
|
714
|
+
approval: AgentApproval,
|
|
715
|
+
decision: AgentApprovalDecision
|
|
716
|
+
): Promise<AgentApprovalDecided> => {
|
|
717
|
+
try {
|
|
718
|
+
const response = await decideApproval.mutateAsync({
|
|
719
|
+
path: { threadId: approval.threadId, approvalId: approval.id },
|
|
720
|
+
body: decision,
|
|
721
|
+
})
|
|
722
|
+
queryClient.setQueryData<ListAgentThreadApprovalsResponse>(
|
|
723
|
+
listAgentThreadApprovalsOptions({
|
|
724
|
+
path: { threadId: approval.threadId },
|
|
725
|
+
query: THREAD_APPROVALS_QUERY,
|
|
726
|
+
}).queryKey,
|
|
727
|
+
(current) =>
|
|
728
|
+
current && {
|
|
729
|
+
...current,
|
|
730
|
+
approvals: current.approvals.map((entry) =>
|
|
731
|
+
entry.id === response.approval.id ? response.approval : entry
|
|
732
|
+
),
|
|
733
|
+
}
|
|
734
|
+
)
|
|
735
|
+
if (response.run && response.run.threadId === threadId) {
|
|
736
|
+
setPendingSend({ run: response.run, anchor: false })
|
|
737
|
+
}
|
|
738
|
+
// "Always allow" raised the reader's mode here.
|
|
739
|
+
if (decision.always) setChosenApprovalMode(null)
|
|
740
|
+
return response
|
|
741
|
+
} catch (error) {
|
|
742
|
+
throw new AgentApprovalDecisionError(decisionFailure(error))
|
|
743
|
+
} finally {
|
|
744
|
+
void refreshThread(approval.threadId)
|
|
745
|
+
void queryClient.invalidateQueries({ queryKey: listAgentApprovalsQueryKey() })
|
|
746
|
+
}
|
|
747
|
+
}
|
|
748
|
+
|
|
341
749
|
// Sixb writes the continuation for the model, with the cut-short turn's model and reasoning; the
|
|
342
750
|
// transcript shows no message for it.
|
|
343
|
-
const
|
|
344
|
-
if (isRunning || threadId === null) return
|
|
751
|
+
const continueTurn = async () => {
|
|
752
|
+
if (isRunning || composerPending || threadId === null || !canContinue) return
|
|
345
753
|
setSendError(null)
|
|
754
|
+
setContinuingThreadId(threadId)
|
|
346
755
|
try {
|
|
347
756
|
const response = await sendWithRequesterSettings((settings) =>
|
|
348
757
|
postMessage.mutateAsync({ path: { threadId }, body: { continue: true, ...settings } })
|
|
349
758
|
)
|
|
350
|
-
|
|
759
|
+
setContinuingThreadId(null)
|
|
760
|
+
setPendingSend({ run: response.run, anchor: true })
|
|
351
761
|
await refreshThread(threadId)
|
|
352
|
-
} catch {
|
|
353
|
-
|
|
762
|
+
} catch (error) {
|
|
763
|
+
setContinuingThreadId(null)
|
|
764
|
+
setSendError({ threadId, failure: sendFailure(error) })
|
|
765
|
+
void refreshThread(threadId)
|
|
354
766
|
}
|
|
355
767
|
}
|
|
356
768
|
|
|
357
769
|
const handleRecreateSandbox = () => {
|
|
358
|
-
if (!thread?.sandboxState || isRunning) return
|
|
770
|
+
if (!thread?.sandboxState || isRunning || access !== "owner") return
|
|
359
771
|
recreateSandbox.mutate(
|
|
360
772
|
{
|
|
361
773
|
path: { threadId: thread.id },
|
|
@@ -384,21 +796,42 @@ export function useAgentConversation({
|
|
|
384
796
|
|
|
385
797
|
const resetReasoning = () => updateModelPreference(preferenceWithoutReasoning(modelSelection))
|
|
386
798
|
|
|
387
|
-
/** Follow the project defaults again, including later changes to them. */
|
|
799
|
+
/** Follow the project defaults again, including later changes to them; with tiers, Auto. */
|
|
388
800
|
const resetModelSelection = () => updateModelPreference(null)
|
|
389
801
|
|
|
390
802
|
const updateModelPreference = (preference: ModelPreference | null) => {
|
|
391
|
-
|
|
392
|
-
|
|
803
|
+
if (!tiered) {
|
|
804
|
+
setModelPreference(preference)
|
|
805
|
+
writeModelPreference(preference)
|
|
806
|
+
return
|
|
807
|
+
}
|
|
808
|
+
|
|
809
|
+
if (threadId === null) setNewThreadPin(preference)
|
|
810
|
+
else pinModel(threadId, preference)
|
|
811
|
+
}
|
|
812
|
+
|
|
813
|
+
// Start from the stored pins, so the ones another tab wrote since are kept.
|
|
814
|
+
const pinModel = (pinThreadId: string, pin: ModelPreference | null) => {
|
|
815
|
+
const pins = withModelPin(readModelPins() ?? modelPins, pinThreadId, pin)
|
|
816
|
+
setModelPins(pins)
|
|
817
|
+
writeModelPins(pins)
|
|
393
818
|
}
|
|
394
819
|
|
|
820
|
+
// Leaving a new conversation, or its first message creating the thread, ends its own pin.
|
|
821
|
+
useEffect(() => {
|
|
822
|
+
if (threadId !== null) setNewThreadPin(null)
|
|
823
|
+
}, [threadId])
|
|
824
|
+
|
|
825
|
+
// Another tab pinned a model, or went back to Auto.
|
|
826
|
+
useEffect(() => {
|
|
827
|
+
const follow = (event: StorageEvent) => {
|
|
828
|
+
if (event.key === MODEL_PINS_KEY) setModelPins(readModelPins() ?? {})
|
|
829
|
+
}
|
|
830
|
+
window.addEventListener("storage", follow)
|
|
831
|
+
return () => window.removeEventListener("storage", follow)
|
|
832
|
+
}, [])
|
|
833
|
+
|
|
395
834
|
const agentThreads = threads.filter((entry) => entry.id !== threadId)
|
|
396
|
-
const pendingUserForThread =
|
|
397
|
-
pendingUser &&
|
|
398
|
-
pendingUser.threadId === threadId &&
|
|
399
|
-
!(pendingUser.messageId && messages.some((message) => message.id === pendingUser.messageId))
|
|
400
|
-
? pendingUser
|
|
401
|
-
: null
|
|
402
835
|
|
|
403
836
|
const sandboxRecovery =
|
|
404
837
|
thread?.sandboxState &&
|
|
@@ -407,12 +840,215 @@ export function useAgentConversation({
|
|
|
407
840
|
? thread.sandboxState
|
|
408
841
|
: null
|
|
409
842
|
|
|
843
|
+
const listedThreads = [...threads, ...sharedThreads]
|
|
844
|
+
const runningThreadCount =
|
|
845
|
+
listedThreads.filter((entry) => entry.activeRunId !== null).length +
|
|
846
|
+
(threadId &&
|
|
847
|
+
isRunning &&
|
|
848
|
+
!listedThreads.some((entry) => entry.id === threadId && entry.activeRunId !== null)
|
|
849
|
+
? 1
|
|
850
|
+
: 0)
|
|
851
|
+
const anchorCurrentTurn = Boolean(
|
|
852
|
+
(pendingUser && pendingUser.threadId === threadId) || (pendingRun && pendingSend?.anchor)
|
|
853
|
+
)
|
|
854
|
+
const composerPending = postMessage.isPending || createThread.isPending
|
|
855
|
+
const currentSendError: AgentConversationSendError | null =
|
|
856
|
+
sendError && sendError.threadId === threadId
|
|
857
|
+
? sendError.failure === "busy"
|
|
858
|
+
? { code: "busy", someoneElse: requestedBySomeoneElse(activeRun, user) }
|
|
859
|
+
: { code: sendError.failure }
|
|
860
|
+
: null
|
|
861
|
+
const stopping = stoppingRunId !== null && stoppingRunId === activeRunId
|
|
862
|
+
const canStop = isRunning && canStopRun(activeRun, access, user)
|
|
863
|
+
|
|
864
|
+
// Someone else's answer holds a shared thread: the reader keeps typing, and sends once it ends.
|
|
865
|
+
const answeringFor =
|
|
866
|
+
isRunning && activeRun?.requestedBy && requestedBySomeoneElse(activeRun, user)
|
|
867
|
+
? activeRun.requestedBy
|
|
868
|
+
: null
|
|
869
|
+
const answeringForName = answeringFor ? knownName(answeringFor, thread, authors) : undefined
|
|
870
|
+
const answeringName = answeringFor ? (answeringForName ?? answeringFor.id) : null
|
|
871
|
+
|
|
872
|
+
// A turn that never answered can run again, by whoever asked for it, once the sandbox works.
|
|
873
|
+
const canRetry =
|
|
874
|
+
!sandboxRecovery &&
|
|
875
|
+
(presentation.kind === "failed" ||
|
|
876
|
+
((presentation.kind === "timeout" || presentation.kind === "interrupted") &&
|
|
877
|
+
!presentation.hasProgress)) &&
|
|
878
|
+
canRetryRun(presentation.run, user)
|
|
879
|
+
const canContinue = offersContinue({
|
|
880
|
+
presentation,
|
|
881
|
+
isRunning,
|
|
882
|
+
sandboxRecovery: Boolean(sandboxRecovery),
|
|
883
|
+
messages: savedMessages,
|
|
884
|
+
})
|
|
885
|
+
|
|
886
|
+
const reader = user
|
|
887
|
+
? { type: "user" as const, id: user.id, displayName: user.displayName }
|
|
888
|
+
: undefined
|
|
889
|
+
const messages = conversationMessages({
|
|
890
|
+
messages: savedMessages,
|
|
891
|
+
authors,
|
|
892
|
+
thread,
|
|
893
|
+
reader,
|
|
894
|
+
pending: pendingUser && pendingUser.threadId === threadId ? pendingUser : null,
|
|
895
|
+
sentKeys,
|
|
896
|
+
live,
|
|
897
|
+
presentation,
|
|
898
|
+
})
|
|
899
|
+
|
|
900
|
+
const turn = conversationTurn({
|
|
901
|
+
presentation,
|
|
902
|
+
activeRunId,
|
|
903
|
+
canStop,
|
|
904
|
+
canRetry,
|
|
905
|
+
canContinue,
|
|
906
|
+
stopping,
|
|
907
|
+
retrying: retryRun.isPending,
|
|
908
|
+
continuing: continuingThreadId !== null && continuingThreadId === threadId,
|
|
909
|
+
waitingLonger,
|
|
910
|
+
compacting: live.compacting,
|
|
911
|
+
reconnecting: live.active && reconnecting,
|
|
912
|
+
answeringFor: answeringFor
|
|
913
|
+
? {
|
|
914
|
+
type: answeringFor.type,
|
|
915
|
+
id: answeringFor.id,
|
|
916
|
+
...(answeringForName === undefined ? {} : { displayName: answeringForName }),
|
|
917
|
+
isReader: false,
|
|
918
|
+
}
|
|
919
|
+
: null,
|
|
920
|
+
})
|
|
921
|
+
|
|
922
|
+
/**
|
|
923
|
+
* Stop a turn paused on held calls, as Stop does a running one: its waiting calls are set aside,
|
|
924
|
+
* and it does not resume. The cards follow from the approval events.
|
|
925
|
+
*/
|
|
926
|
+
const stopWaiting = async (approval: AgentApproval) => {
|
|
927
|
+
try {
|
|
928
|
+
await cancelRun.mutateAsync({
|
|
929
|
+
path: { threadId: approval.threadId },
|
|
930
|
+
body: { runId: approval.runId },
|
|
931
|
+
})
|
|
932
|
+
} finally {
|
|
933
|
+
void refreshThread(approval.threadId)
|
|
934
|
+
void queryClient.invalidateQueries({ queryKey: listAgentApprovalsQueryKey() })
|
|
935
|
+
}
|
|
936
|
+
}
|
|
937
|
+
|
|
938
|
+
// Every card reads this: it changes with the approvals and the people, not with each stream chunk.
|
|
939
|
+
decideRef.current = decide
|
|
940
|
+
stopRef.current = stopWaiting
|
|
941
|
+
const approvalsLoaded = approvalsQuery.isSuccess
|
|
942
|
+
const transcriptApprovals = useMemo((): TranscriptApprovals => {
|
|
943
|
+
const me = userPrincipal(user)
|
|
944
|
+
return {
|
|
945
|
+
approvals,
|
|
946
|
+
loaded: approvalsLoaded,
|
|
947
|
+
// Without a signed-in user the app acts for the project, which asked for every turn.
|
|
948
|
+
canDecide: (approval) => me === null || samePrincipal(approval.requestedBy, me),
|
|
949
|
+
requesterName: (approval) =>
|
|
950
|
+
knownName(approval.requestedBy, thread, authors) ?? approval.requestedBy.id,
|
|
951
|
+
decide: (approval, decision) => decideRef.current(approval, decision),
|
|
952
|
+
// Whoever asked for the turn, or the thread's owner, as for a running answer.
|
|
953
|
+
canStop: (approval) =>
|
|
954
|
+
me === null ||
|
|
955
|
+
samePrincipal(approval.requestedBy, me) ||
|
|
956
|
+
(thread !== null && samePrincipal(thread.ownerPrincipal, me)),
|
|
957
|
+
stop: (approval) => stopRef.current(approval),
|
|
958
|
+
}
|
|
959
|
+
}, [approvals, approvalsLoaded, user, thread, authors])
|
|
960
|
+
// The newest turn paused on calls the reader decides: the composer says how to move on.
|
|
961
|
+
const awaitingApproval =
|
|
962
|
+
!isRunning &&
|
|
963
|
+
isAwaitingApproval(latestRun) &&
|
|
964
|
+
approvals.some(
|
|
965
|
+
(approval) =>
|
|
966
|
+
approval.status === "pending" &&
|
|
967
|
+
approval.runId === latestRun?.id &&
|
|
968
|
+
transcriptApprovals.canDecide(approval)
|
|
969
|
+
)
|
|
970
|
+
// Any message sets aside the calls still waiting in the thread, whoever asked for them: say so
|
|
971
|
+
// before someone else's request is lost to it.
|
|
972
|
+
const othersWaiting = isRunning
|
|
973
|
+
? undefined
|
|
974
|
+
: approvals.find(
|
|
975
|
+
(approval) => approval.status === "pending" && !transcriptApprovals.canDecide(approval)
|
|
976
|
+
)
|
|
977
|
+
|
|
978
|
+
// Whoever asked for the turn a sub-agent works under, or the thread's owner, stops it.
|
|
979
|
+
const transcriptDelegation = useMemo(
|
|
980
|
+
(): TranscriptDelegation => ({
|
|
981
|
+
canStop: (runId) => canStopRun(runs.find((run) => run.id === runId) ?? null, access, user),
|
|
982
|
+
}),
|
|
983
|
+
[runs, access, user]
|
|
984
|
+
)
|
|
985
|
+
|
|
986
|
+
const transcriptProps: TranscriptProps = {
|
|
987
|
+
threadId,
|
|
988
|
+
messages,
|
|
989
|
+
turn,
|
|
990
|
+
anchorCurrentTurn,
|
|
991
|
+
onRetry: canRetry ? retry : undefined,
|
|
992
|
+
onContinue: canContinue ? continueTurn : undefined,
|
|
993
|
+
approvals: transcriptApprovals,
|
|
994
|
+
approvalOutcomes,
|
|
995
|
+
delegation: transcriptDelegation,
|
|
996
|
+
}
|
|
997
|
+
|
|
998
|
+
const modelControlsProps = {
|
|
999
|
+
models,
|
|
1000
|
+
selectedModel,
|
|
1001
|
+
selectedReasoning,
|
|
1002
|
+
modelsLoading: modelsQuery.isLoading,
|
|
1003
|
+
modelsError: modelsQuery.isError,
|
|
1004
|
+
onSelectModel: selectModel,
|
|
1005
|
+
onSelectReasoning: selectReasoning,
|
|
1006
|
+
onResetReasoning: resetReasoning,
|
|
1007
|
+
usingDefaultModel: modelSelection.request === undefined,
|
|
1008
|
+
onResetModelSelection: resetModelSelection,
|
|
1009
|
+
modelRouting: modelsQuery.data?.languageRouting,
|
|
1010
|
+
}
|
|
1011
|
+
|
|
1012
|
+
const composerProps: ConversationComposerProps = {
|
|
1013
|
+
onSend: send,
|
|
1014
|
+
error: currentSendError
|
|
1015
|
+
? failureMessage(currentSendError, labels, agentMessages.approvalModes.saveFailed)
|
|
1016
|
+
: undefined,
|
|
1017
|
+
disabled: (isRunning && answeringName === null) || Boolean(sandboxRecovery),
|
|
1018
|
+
hint: answeringName
|
|
1019
|
+
? agentMessages.sharing.answering(answeringName)
|
|
1020
|
+
: othersWaiting
|
|
1021
|
+
? agentMessages.approvals.setsAside(transcriptApprovals.requesterName(othersWaiting))
|
|
1022
|
+
: undefined,
|
|
1023
|
+
pending: composerPending,
|
|
1024
|
+
running: isRunning,
|
|
1025
|
+
stopping,
|
|
1026
|
+
onStop: canStop ? stop : undefined,
|
|
1027
|
+
...modelControlsProps,
|
|
1028
|
+
draft: draftReseed.text,
|
|
1029
|
+
draftAttachments: draftReseed.attachments,
|
|
1030
|
+
draftContext: draftReseed.context,
|
|
1031
|
+
draftNonce: draftReseed.nonce,
|
|
1032
|
+
approvalMode,
|
|
1033
|
+
defaultApprovalMode,
|
|
1034
|
+
onApprovalModeChange: setApprovalMode,
|
|
1035
|
+
onMakeApprovalModeDefault: setDefaultApprovalMode,
|
|
1036
|
+
awaitingApproval,
|
|
1037
|
+
}
|
|
1038
|
+
|
|
1039
|
+
const sandboxRecoveryProps: SandboxRecoveryProps | null = sandboxRecovery
|
|
1040
|
+
? {
|
|
1041
|
+
pending: recreateSandbox.isPending,
|
|
1042
|
+
error: recreateSandbox.isError,
|
|
1043
|
+
onRecreate: handleRecreateSandbox,
|
|
1044
|
+
canRecreate: access === "owner",
|
|
1045
|
+
owner: thread ? personName(threadOwner(thread)) : "",
|
|
1046
|
+
}
|
|
1047
|
+
: null
|
|
1048
|
+
|
|
410
1049
|
return {
|
|
411
1050
|
agentLoading: agentQuery.isLoading,
|
|
412
1051
|
sandboxRecovery,
|
|
413
|
-
recreatingSandbox: recreateSandbox.isPending,
|
|
414
|
-
sandboxRecoveryError: recreateSandbox.isError,
|
|
415
|
-
recreateSandbox: handleRecreateSandbox,
|
|
416
1052
|
agentError: agentQuery.isError,
|
|
417
1053
|
models,
|
|
418
1054
|
modelsLoading: modelsQuery.isLoading,
|
|
@@ -420,11 +1056,20 @@ export function useAgentConversation({
|
|
|
420
1056
|
selectedModel,
|
|
421
1057
|
selectedReasoning,
|
|
422
1058
|
usingDefaultModel: modelSelection.request === undefined,
|
|
1059
|
+
/**
|
|
1060
|
+
* What the next message runs on: `"auto"` with tiers and no model pinned, as Sixb picks each
|
|
1061
|
+
* message's model; otherwise the selected model. `resetModelSelection` returns to Auto.
|
|
1062
|
+
*/
|
|
1063
|
+
modelChoice: modelSelection.auto ? ("auto" as const) : selectedModel,
|
|
1064
|
+
/** With tiers: a decision model picks each message's model on Auto; without one, `standard`. */
|
|
1065
|
+
modelRouting: modelsQuery.data?.languageRouting,
|
|
423
1066
|
selectModel,
|
|
424
1067
|
selectReasoning,
|
|
425
1068
|
resetReasoning,
|
|
426
1069
|
resetModelSelection,
|
|
427
1070
|
threads,
|
|
1071
|
+
/** Threads with a run in progress, counting this one while its run starts. */
|
|
1072
|
+
runningThreadCount,
|
|
428
1073
|
threadsError: threadsQuery.isError,
|
|
429
1074
|
threadsHasMore: threadsQuery.hasNextPage,
|
|
430
1075
|
threadsLoadingMore: threadsQuery.isFetchingNextPage,
|
|
@@ -434,25 +1079,103 @@ export function useAgentConversation({
|
|
|
434
1079
|
currentAgent,
|
|
435
1080
|
currentThread: thread,
|
|
436
1081
|
agentThreads,
|
|
1082
|
+
sharedThreads,
|
|
1083
|
+
sharedThreadsTotal: sharedThreadsQuery.data?.pages[0]?.total ?? 0,
|
|
1084
|
+
sharedThreadsError: sharedThreadsQuery.isError,
|
|
1085
|
+
sharedThreadsHasMore: sharedThreadsQuery.hasNextPage,
|
|
1086
|
+
sharedThreadsLoadingMore: sharedThreadsQuery.isFetchingNextPage,
|
|
1087
|
+
sharedThreadsLoadMoreError: sharedThreadsQuery.isFetchNextPageError,
|
|
1088
|
+
loadMoreSharedThreads: () => sharedThreadsQuery.fetchNextPage(),
|
|
1089
|
+
access,
|
|
1090
|
+
user,
|
|
1091
|
+
removedFromThread,
|
|
1092
|
+
/**
|
|
1093
|
+
* The conversation, oldest first: its saved messages, the one the reader just sent, and the
|
|
1094
|
+
* reply streaming in. Each keeps its `key` once saved.
|
|
1095
|
+
*/
|
|
437
1096
|
messages,
|
|
1097
|
+
/** The message page's authors, with their names. */
|
|
1098
|
+
authors,
|
|
438
1099
|
messagesLoading: threadId !== null && messagesQuery.isLoading,
|
|
439
|
-
messagesError: threadId !== null && messagesQuery.isError ?
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
anchorCurrentTurn: Boolean((pendingUser && pendingUser.threadId === threadId) || pendingRun),
|
|
444
|
-
isRunning,
|
|
445
|
-
waitingLonger,
|
|
446
|
-
presentation,
|
|
447
|
-
sendError: sendError && sendError.threadId === threadId ? sendError.message : null,
|
|
1100
|
+
messagesError: threadId !== null && messagesQuery.isError ? MESSAGES_LOAD_ERROR : null,
|
|
1101
|
+
/** The newest turn: answering, or how it ended, and what the reader may do with it. */
|
|
1102
|
+
turn,
|
|
1103
|
+
sendError: currentSendError,
|
|
448
1104
|
draftReseed,
|
|
449
|
-
composerPending
|
|
450
|
-
stopping: stoppingRunId !== null && stoppingRunId === activeRunId,
|
|
451
|
-
retrying: retryRun.isPending,
|
|
1105
|
+
composerPending,
|
|
452
1106
|
send,
|
|
1107
|
+
/** Stop the answer in flight, when `turn.canStop`. */
|
|
453
1108
|
stop,
|
|
1109
|
+
/** Run again the turn that never answered, when `turn.canRetry`. */
|
|
454
1110
|
retry,
|
|
455
|
-
|
|
1111
|
+
/** Finish the answer cut short, when `turn.canContinue`. */
|
|
1112
|
+
continue: continueTurn,
|
|
1113
|
+
/** The thread's held calls, oldest first; the transcript shows each as a card. */
|
|
1114
|
+
approvals,
|
|
1115
|
+
/** Whether the reader decides on a held call: only whoever asked for its turn does. */
|
|
1116
|
+
canDecide: transcriptApprovals.canDecide,
|
|
1117
|
+
/**
|
|
1118
|
+
* Approve or deny a held call. It resolves once decided, the approved call having run; it
|
|
1119
|
+
* rejects with an `AgentApprovalDecisionError` when nothing was decided.
|
|
1120
|
+
*/
|
|
1121
|
+
decide,
|
|
1122
|
+
/** What the reader's next turns may change without asking; unknown until it loads. */
|
|
1123
|
+
approvalMode,
|
|
1124
|
+
setApprovalMode,
|
|
1125
|
+
/** The threads where a call waits for the reader's decision. */
|
|
1126
|
+
waitingThreadIds,
|
|
1127
|
+
/** Spread into `<Transcript>`. */
|
|
1128
|
+
transcriptProps,
|
|
1129
|
+
/** Spread into `<Composer>`, then add the page's own props such as `placeholder`. */
|
|
1130
|
+
composerProps,
|
|
1131
|
+
/** Spread into `<SandboxRecovery>` while set: the composer stays disabled until it is resolved. */
|
|
1132
|
+
sandboxRecoveryProps,
|
|
1133
|
+
}
|
|
1134
|
+
}
|
|
1135
|
+
|
|
1136
|
+
/** Why a turn did not start or stop, or the mode did not change. */
|
|
1137
|
+
type TurnFailure = AgentConversationSendError["code"]
|
|
1138
|
+
|
|
1139
|
+
/** Why a decision did not go through. Once the call ran, the decision stands and never throws. */
|
|
1140
|
+
function decisionFailure(error: unknown): AgentApprovalDecisionFailure {
|
|
1141
|
+
if (!isSixbApiError(error)) return "failed"
|
|
1142
|
+
if (error.code === "approval_expired") return "expired"
|
|
1143
|
+
if (error.code === "approval_not_pending") return "decided"
|
|
1144
|
+
|
|
1145
|
+
return "failed"
|
|
1146
|
+
}
|
|
1147
|
+
|
|
1148
|
+
/** A message that did not go out: another answer holds the thread, the sandbox is away, or else. */
|
|
1149
|
+
function sendFailure(error: unknown): TurnFailure {
|
|
1150
|
+
if (!isSixbApiError(error) || error.status !== 409) return "send"
|
|
1151
|
+
if (error.code === "active_run_exists") return "busy"
|
|
1152
|
+
if (error.code === "sandbox_execution_unavailable") return "sandbox"
|
|
1153
|
+
|
|
1154
|
+
return "send"
|
|
1155
|
+
}
|
|
1156
|
+
|
|
1157
|
+
/**
|
|
1158
|
+
* Said once the thread is read again, so a busy thread names whose answer holds it when the reader
|
|
1159
|
+
* can tell.
|
|
1160
|
+
*/
|
|
1161
|
+
function failureMessage(
|
|
1162
|
+
failure: AgentConversationSendError,
|
|
1163
|
+
labels: ReturnType<typeof useAgentMessages>["chat"],
|
|
1164
|
+
approvalModeFailed: string
|
|
1165
|
+
): string {
|
|
1166
|
+
switch (failure.code) {
|
|
1167
|
+
case "busy":
|
|
1168
|
+
return failure.someoneElse ? labels.busyOther : labels.busy
|
|
1169
|
+
case "sandbox":
|
|
1170
|
+
return labels.sandboxUnavailable
|
|
1171
|
+
case "retry":
|
|
1172
|
+
return labels.retryFailed
|
|
1173
|
+
case "stop":
|
|
1174
|
+
return labels.stopFailed
|
|
1175
|
+
case "approvalMode":
|
|
1176
|
+
return approvalModeFailed
|
|
1177
|
+
default:
|
|
1178
|
+
return labels.sendFailed
|
|
456
1179
|
}
|
|
457
1180
|
}
|
|
458
1181
|
|
|
@@ -493,6 +1216,46 @@ function writeModelPreference(preference: ModelPreference | null): void {
|
|
|
493
1216
|
}
|
|
494
1217
|
}
|
|
495
1218
|
|
|
1219
|
+
/** The pins this browser stored, or null when it cannot store any. */
|
|
1220
|
+
function readModelPins(): Readonly<Record<string, ModelPreference>> | null {
|
|
1221
|
+
if (typeof window === "undefined") return null
|
|
1222
|
+
try {
|
|
1223
|
+
const value = JSON.parse(window.localStorage.getItem(MODEL_PINS_KEY) ?? "null") as unknown
|
|
1224
|
+
if (typeof value !== "object" || value === null || Array.isArray(value)) return {}
|
|
1225
|
+
|
|
1226
|
+
return Object.fromEntries(
|
|
1227
|
+
Object.entries(value).filter(
|
|
1228
|
+
(entry): entry is [string, ModelPreference] =>
|
|
1229
|
+
isModelPreference(entry[1]) && entry[1].model !== undefined
|
|
1230
|
+
)
|
|
1231
|
+
)
|
|
1232
|
+
} catch {
|
|
1233
|
+
return null
|
|
1234
|
+
}
|
|
1235
|
+
}
|
|
1236
|
+
|
|
1237
|
+
/** Set or clear one conversation's pin; a pin set again becomes the most recent. */
|
|
1238
|
+
function withModelPin(
|
|
1239
|
+
pins: Readonly<Record<string, ModelPreference>>,
|
|
1240
|
+
key: string,
|
|
1241
|
+
pin: ModelPreference | null
|
|
1242
|
+
): Readonly<Record<string, ModelPreference>> {
|
|
1243
|
+
const entries = Object.entries(pins).filter(([entry]) => entry !== key)
|
|
1244
|
+
if (pin !== null) entries.push([key, pin])
|
|
1245
|
+
|
|
1246
|
+
return Object.fromEntries(entries.slice(-MAX_MODEL_PINS))
|
|
1247
|
+
}
|
|
1248
|
+
|
|
1249
|
+
function writeModelPins(pins: Readonly<Record<string, ModelPreference>>): void {
|
|
1250
|
+
if (typeof window === "undefined") return
|
|
1251
|
+
try {
|
|
1252
|
+
if (Object.keys(pins).length === 0) window.localStorage.removeItem(MODEL_PINS_KEY)
|
|
1253
|
+
else window.localStorage.setItem(MODEL_PINS_KEY, JSON.stringify(pins))
|
|
1254
|
+
} catch {
|
|
1255
|
+
// Restricted browser contexts may disable storage; the in-memory pins still work.
|
|
1256
|
+
}
|
|
1257
|
+
}
|
|
1258
|
+
|
|
496
1259
|
function isModelPreference(value: unknown): value is ModelPreference {
|
|
497
1260
|
if (typeof value !== "object" || value === null) return false
|
|
498
1261
|
const candidate = value as {
|