@sixb/app 0.2.3 → 0.2.5
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/assets/connector-icons/README.md +1 -0
- package/assets/connector-icons/ctm.png +0 -0
- package/dist/agent/activity-label.d.ts.map +1 -1
- package/dist/agent/agent-chat.d.ts +3 -1
- package/dist/agent/agent-chat.d.ts.map +1 -1
- package/dist/agent/agent-panel.d.ts.map +1 -1
- package/dist/agent/artifact-panel.d.ts +3 -1
- package/dist/agent/artifact-panel.d.ts.map +1 -1
- package/dist/agent/background/background-tool-row.d.ts.map +1 -1
- package/dist/agent/background/interpret.d.ts +1 -1
- package/dist/agent/background/interpret.d.ts.map +1 -1
- package/dist/agent/components/composer-settings.d.ts +1 -1
- package/dist/agent/components/composer-settings.d.ts.map +1 -1
- package/dist/agent/components/composer.d.ts +22 -5
- package/dist/agent/components/composer.d.ts.map +1 -1
- package/dist/agent/components/context-meter.d.ts +1 -1
- package/dist/agent/components/context-meter.d.ts.map +1 -1
- package/dist/agent/components/conversation-panel.d.ts +8 -2
- package/dist/agent/components/conversation-panel.d.ts.map +1 -1
- package/dist/agent/components/message-parts.d.ts +2 -1
- package/dist/agent/components/message-parts.d.ts.map +1 -1
- package/dist/agent/components/message-view.d.ts.map +1 -1
- package/dist/agent/components/pending-messages.d.ts +20 -0
- package/dist/agent/components/pending-messages.d.ts.map +1 -0
- package/dist/agent/components/sandbox-recovery.d.ts +11 -2
- package/dist/agent/components/sandbox-recovery.d.ts.map +1 -1
- package/dist/agent/components/threads-button.d.ts +1 -1
- package/dist/agent/components/threads-button.d.ts.map +1 -1
- package/dist/agent/components/transcript.d.ts +5 -0
- package/dist/agent/components/transcript.d.ts.map +1 -1
- package/dist/agent/conversation.d.ts +3 -6
- package/dist/agent/conversation.d.ts.map +1 -1
- package/dist/agent/delegation/agent-exchange.d.ts +16 -0
- package/dist/agent/delegation/agent-exchange.d.ts.map +1 -0
- package/dist/agent/delegation/child-card.d.ts +3 -3
- package/dist/agent/delegation/child-card.d.ts.map +1 -1
- package/dist/agent/delegation/child-parts.d.ts +1 -10
- package/dist/agent/delegation/child-parts.d.ts.map +1 -1
- package/dist/agent/delegation/child-work.d.ts.map +1 -1
- package/dist/agent/delegation/interpret.d.ts +9 -10
- package/dist/agent/delegation/interpret.d.ts.map +1 -1
- package/dist/agent/delegation/use-children.d.ts.map +1 -1
- package/dist/agent/file-edits/file-edit-tool-view.d.ts +10 -0
- package/dist/agent/file-edits/file-edit-tool-view.d.ts.map +1 -0
- package/dist/agent/file-edits/interpret.d.ts +25 -0
- package/dist/agent/file-edits/interpret.d.ts.map +1 -0
- package/dist/agent/hooks/use-agent-conversation.d.ts +16 -4
- package/dist/agent/hooks/use-agent-conversation.d.ts.map +1 -1
- package/dist/agent/hooks/use-thread-lists.d.ts.map +1 -1
- package/dist/agent/hooks/use-thread-stream.d.ts.map +1 -1
- package/dist/agent/i18n/en.d.ts +114 -5
- 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 +190 -8
- package/dist/agent/i18n/index.d.ts.map +1 -1
- package/dist/agent/inbox-handoff.d.ts +10 -0
- package/dist/agent/inbox-handoff.d.ts.map +1 -0
- package/dist/agent/live-run.d.ts +8 -1
- package/dist/agent/live-run.d.ts.map +1 -1
- package/dist/agent/message-agent/interpret.d.ts +2 -2
- package/dist/agent/message-agent/interpret.d.ts.map +1 -1
- package/dist/agent/publish-artifact/interpret.d.ts +1 -1
- package/dist/agent/publish-artifact/interpret.d.ts.map +1 -1
- package/dist/agent/questions/interpret.d.ts +31 -0
- package/dist/agent/questions/interpret.d.ts.map +1 -0
- package/dist/agent/questions/question-card.d.ts +16 -0
- package/dist/agent/questions/question-card.d.ts.map +1 -0
- package/dist/agent/questions/question-composer.d.ts +15 -0
- package/dist/agent/questions/question-composer.d.ts.map +1 -0
- package/dist/agent/read/interpret.d.ts +8 -1
- package/dist/agent/read/interpret.d.ts.map +1 -1
- package/dist/agent/read/read-tool-view.d.ts.map +1 -1
- package/dist/agent/search/interpret.d.ts +101 -0
- package/dist/agent/search/interpret.d.ts.map +1 -0
- package/dist/agent/search/search-tool-view.d.ts +10 -0
- package/dist/agent/search/search-tool-view.d.ts.map +1 -0
- package/dist/agent/thread-state.d.ts +26 -0
- package/dist/agent/thread-state.d.ts.map +1 -0
- package/dist/agent/tool-views/built-in.d.ts.map +1 -1
- package/dist/agent/tool-views/registry.d.ts +5 -6
- package/dist/agent/tool-views/registry.d.ts.map +1 -1
- package/dist/agent/types.d.ts +5 -1
- package/dist/agent/types.d.ts.map +1 -1
- package/dist/agent/view-file/view-file-tool-view.d.ts +2 -1
- package/dist/agent/view-file/view-file-tool-view.d.ts.map +1 -1
- package/dist/agent/waits.d.ts +14 -0
- package/dist/agent/waits.d.ts.map +1 -0
- package/dist/artifacts/card-preview.d.ts.map +1 -1
- package/dist/artifacts/edit-session.d.ts +11 -1
- package/dist/artifacts/edit-session.d.ts.map +1 -1
- package/dist/artifacts/editor/block-handle.d.ts +20 -0
- package/dist/artifacts/editor/block-handle.d.ts.map +1 -0
- package/dist/artifacts/editor/blocks.d.ts +34 -0
- package/dist/artifacts/editor/blocks.d.ts.map +1 -0
- package/dist/artifacts/editor/callout-view.d.ts +7 -0
- package/dist/artifacts/editor/callout-view.d.ts.map +1 -0
- package/dist/artifacts/editor/document-editor.d.ts +30 -0
- package/dist/artifacts/editor/document-editor.d.ts.map +1 -0
- package/dist/artifacts/editor/figure-view.d.ts +12 -0
- package/dist/artifacts/editor/figure-view.d.ts.map +1 -0
- package/dist/artifacts/editor/find-blocks.d.ts +6 -0
- package/dist/artifacts/editor/find-blocks.d.ts.map +1 -0
- package/dist/artifacts/editor/markdown-document.d.ts +12 -0
- package/dist/artifacts/editor/markdown-document.d.ts.map +1 -0
- package/dist/artifacts/editor/messages.d.ts +4 -0
- package/dist/artifacts/editor/messages.d.ts.map +1 -0
- package/dist/artifacts/editor/schema.d.ts +21 -0
- package/dist/artifacts/editor/schema.d.ts.map +1 -0
- package/dist/artifacts/editor/selection-toolbar.d.ts +35 -0
- package/dist/artifacts/editor/selection-toolbar.d.ts.map +1 -0
- package/dist/artifacts/editor/slash-menu.d.ts +43 -0
- package/dist/artifacts/editor/slash-menu.d.ts.map +1 -0
- package/dist/artifacts/editor/upload.d.ts +12 -0
- package/dist/artifacts/editor/upload.d.ts.map +1 -0
- package/dist/artifacts/file-source.d.ts +5 -0
- package/dist/artifacts/file-source.d.ts.map +1 -1
- package/dist/artifacts/frame-editor/bundle.d.ts +7 -0
- package/dist/artifacts/frame-editor/bundle.d.ts.map +1 -0
- package/dist/artifacts/frame-editor/commands.d.ts +93 -0
- package/dist/artifacts/frame-editor/commands.d.ts.map +1 -0
- package/dist/artifacts/frame-editor/entry.d.ts +2 -0
- package/dist/artifacts/frame-editor/entry.d.ts.map +1 -0
- package/dist/artifacts/frame-editor/frame.d.ts +5 -0
- package/dist/artifacts/frame-editor/frame.d.ts.map +1 -0
- package/dist/artifacts/frame-editor/keys.d.ts +8 -0
- package/dist/artifacts/frame-editor/keys.d.ts.map +1 -0
- package/dist/artifacts/frame-editor/protocol.d.ts +186 -0
- package/dist/artifacts/frame-editor/protocol.d.ts.map +1 -0
- package/dist/artifacts/frame-editor/schema.d.ts +34 -0
- package/dist/artifacts/frame-editor/schema.d.ts.map +1 -0
- package/dist/artifacts/frame-editor/style.d.ts +2 -0
- package/dist/artifacts/frame-editor/style.d.ts.map +1 -0
- package/dist/artifacts/frame.d.ts +2 -2
- package/dist/artifacts/frame.d.ts.map +1 -1
- package/dist/artifacts/live/boards.d.ts +2 -0
- package/dist/artifacts/live/boards.d.ts.map +1 -1
- package/dist/artifacts/live/document.d.ts +32 -0
- package/dist/artifacts/live/document.d.ts.map +1 -0
- package/dist/artifacts/live/header.d.ts +4 -4
- package/dist/artifacts/live/header.d.ts.map +1 -1
- package/dist/artifacts/live/presence.d.ts.map +1 -1
- package/dist/artifacts/live/session.d.ts +2 -0
- package/dist/artifacts/live/session.d.ts.map +1 -1
- package/dist/artifacts/live/view.d.ts +4 -3
- package/dist/artifacts/live/view.d.ts.map +1 -1
- package/dist/artifacts/messages.d.ts +278 -2
- package/dist/artifacts/messages.d.ts.map +1 -1
- package/dist/artifacts/pdf.d.ts +8 -0
- package/dist/artifacts/pdf.d.ts.map +1 -0
- package/dist/artifacts/queries.d.ts +80 -0
- package/dist/artifacts/queries.d.ts.map +1 -1
- package/dist/artifacts/references/references.d.ts +3 -3
- package/dist/artifacts/references/references.d.ts.map +1 -1
- package/dist/artifacts/renderers/canvas/board-editor.d.ts +11 -4
- package/dist/artifacts/renderers/canvas/board-editor.d.ts.map +1 -1
- package/dist/artifacts/renderers/canvas/board.d.ts +14 -2
- package/dist/artifacts/renderers/canvas/board.d.ts.map +1 -1
- package/dist/artifacts/renderers/canvas/canvas.d.ts +4 -3
- package/dist/artifacts/renderers/canvas/canvas.d.ts.map +1 -1
- package/dist/artifacts/renderers/canvas/comment-pins.d.ts +4 -2
- package/dist/artifacts/renderers/canvas/comment-pins.d.ts.map +1 -1
- package/dist/artifacts/renderers/canvas/comments-panel.d.ts.map +1 -1
- package/dist/artifacts/renderers/canvas/comments.d.ts +2 -1
- package/dist/artifacts/renderers/canvas/comments.d.ts.map +1 -1
- package/dist/artifacts/renderers/canvas/controls.d.ts +15 -4
- package/dist/artifacts/renderers/canvas/controls.d.ts.map +1 -1
- package/dist/artifacts/renderers/canvas/focus.d.ts +19 -5
- package/dist/artifacts/renderers/canvas/focus.d.ts.map +1 -1
- package/dist/artifacts/renderers/canvas/gestures.d.ts +46 -0
- package/dist/artifacts/renderers/canvas/gestures.d.ts.map +1 -0
- package/dist/artifacts/renderers/canvas/page-resize.d.ts +21 -0
- package/dist/artifacts/renderers/canvas/page-resize.d.ts.map +1 -0
- package/dist/artifacts/renderers/canvas/page-size-controls.d.ts +21 -0
- package/dist/artifacts/renderers/canvas/page-size-controls.d.ts.map +1 -0
- package/dist/artifacts/renderers/canvas/page-size.d.ts +93 -0
- package/dist/artifacts/renderers/canvas/page-size.d.ts.map +1 -0
- package/dist/artifacts/renderers/canvas/page-zoom.d.ts +64 -0
- package/dist/artifacts/renderers/canvas/page-zoom.d.ts.map +1 -0
- package/dist/artifacts/renderers/canvas/shown-size.d.ts +26 -0
- package/dist/artifacts/renderers/canvas/shown-size.d.ts.map +1 -0
- package/dist/artifacts/renderers/designed-document.d.ts +28 -0
- package/dist/artifacts/renderers/designed-document.d.ts.map +1 -0
- package/dist/artifacts/renderers/document-tree.d.ts +2 -0
- package/dist/artifacts/renderers/document-tree.d.ts.map +1 -1
- package/dist/artifacts/renderers/document.d.ts +9 -1
- package/dist/artifacts/renderers/document.d.ts.map +1 -1
- package/dist/artifacts/renderers/live-frame.d.ts +145 -0
- package/dist/artifacts/renderers/live-frame.d.ts.map +1 -0
- package/dist/artifacts/renderers/page-editor.d.ts +16 -0
- package/dist/artifacts/renderers/page-editor.d.ts.map +1 -0
- package/dist/artifacts/renderers/page.d.ts +10 -1
- package/dist/artifacts/renderers/page.d.ts.map +1 -1
- package/dist/artifacts/viewer.d.ts.map +1 -1
- package/dist/{chunk-001c4gnk.js → chunk-4fex83k2.js} +19965 -13027
- package/dist/chunk-4fex83k2.js.map +239 -0
- package/dist/{chunk-5crvhjp2.js → chunk-4wm09prf.js} +1633 -1999
- package/dist/chunk-4wm09prf.js.map +27 -0
- package/dist/{chunk-fwb9mxwm.js → chunk-5sgac68y.js} +1 -1
- package/dist/{chunk-kes4ygmz.js → chunk-69qgh20f.js} +1 -1
- package/dist/chunk-y51c4tsz.js +11 -0
- package/dist/chunk-y51c4tsz.js.map +10 -0
- package/dist/index.d.ts +4 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +13 -6
- package/dist/index.js.map +5 -5
- package/dist/pages/console/data/messages.d.ts +6 -0
- package/dist/pages/console/data/messages.d.ts.map +1 -1
- package/dist/pages/console/data/shared.d.ts.map +1 -1
- package/dist/pages.js +12 -5
- package/dist/pages.js.map +6 -6
- package/dist/shell/search-command.d.ts.map +1 -1
- package/package.json +22 -5
- package/src/agent/activity-label.ts +9 -1
- package/src/agent/agent-chat.tsx +57 -37
- package/src/agent/agent-execution-trace.tsx +2 -2
- package/src/agent/agent-panel.tsx +6 -4
- package/src/agent/agent.css +254 -0
- package/src/agent/artifact-panel.tsx +77 -22
- package/src/agent/background/background-tool-row.tsx +24 -10
- package/src/agent/background/interpret.ts +60 -51
- package/src/agent/components/composer-settings.tsx +20 -10
- package/src/agent/components/composer.tsx +342 -104
- package/src/agent/components/context-meter.tsx +7 -3
- package/src/agent/components/conversation-panel.tsx +96 -37
- package/src/agent/components/message-parts.tsx +390 -64
- package/src/agent/components/message-view.tsx +12 -2
- package/src/agent/components/pending-messages.tsx +338 -0
- package/src/agent/components/sandbox-recovery.tsx +36 -17
- package/src/agent/components/threads-button.tsx +3 -2
- package/src/agent/components/transcript.tsx +92 -45
- package/src/agent/conversation.ts +203 -54
- package/src/agent/delegation/agent-exchange.tsx +53 -0
- package/src/agent/delegation/child-card.tsx +6 -40
- package/src/agent/delegation/child-parts.tsx +1 -84
- package/src/agent/delegation/child-work.tsx +19 -5
- package/src/agent/delegation/interpret.ts +64 -61
- package/src/agent/delegation/model.ts +1 -1
- package/src/agent/file-edits/file-edit-tool-view.tsx +126 -0
- package/src/agent/file-edits/interpret.ts +120 -0
- package/src/agent/hooks/use-agent-conversation.ts +360 -92
- package/src/agent/hooks/use-thread-stream.ts +10 -0
- package/src/agent/i18n/en.ts +134 -16
- package/src/agent/i18n/fr.ts +122 -16
- package/src/agent/inbox-handoff.ts +47 -0
- package/src/agent/live-run.ts +23 -2
- package/src/agent/message-agent/interpret.ts +4 -3
- package/src/agent/publish-artifact/interpret.ts +14 -5
- package/src/agent/publish-artifact/publish-artifact-tool-view.tsx +2 -2
- package/src/agent/questions/interpret.ts +90 -0
- package/src/agent/questions/question-card.tsx +57 -0
- package/src/agent/questions/question-composer.tsx +257 -0
- package/src/agent/react-router.tsx +2 -2
- package/src/agent/read/interpret.ts +34 -1
- package/src/agent/read/read-tool-view.tsx +20 -4
- package/src/agent/search/interpret.ts +367 -0
- package/src/agent/search/search-tool-view.tsx +235 -0
- package/src/agent/thread-state.ts +114 -0
- package/src/agent/tool-views/built-in.tsx +33 -6
- package/src/agent/tool-views/registry.tsx +28 -2
- package/src/agent/types.ts +7 -0
- package/src/agent/view-file/view-file-tool-view.tsx +33 -19
- package/src/agent/waits.ts +50 -0
- package/src/artifacts/artifacts.css +434 -0
- package/src/artifacts/card-preview.tsx +6 -1
- package/src/artifacts/edit-session.tsx +15 -1
- package/src/artifacts/editor/block-handle.tsx +278 -0
- package/src/artifacts/editor/blocks.ts +216 -0
- package/src/artifacts/editor/callout-view.tsx +31 -0
- package/src/artifacts/editor/document-editor.tsx +484 -0
- package/src/artifacts/editor/figure-view.tsx +66 -0
- package/src/artifacts/editor/find-blocks.ts +19 -0
- package/src/artifacts/editor/markdown-document.tsx +72 -0
- package/src/artifacts/editor/messages.ts +4 -0
- package/src/artifacts/editor/schema.ts +159 -0
- package/src/artifacts/editor/selection-toolbar.tsx +364 -0
- package/src/artifacts/editor/slash-menu.tsx +251 -0
- package/src/artifacts/editor/upload.ts +40 -0
- package/src/artifacts/file-source.ts +11 -0
- package/src/artifacts/frame-editor/bundle.ts +8 -0
- package/src/artifacts/frame-editor/commands.ts +565 -0
- package/src/artifacts/frame-editor/entry.ts +6 -0
- package/src/artifacts/frame-editor/frame.ts +847 -0
- package/src/artifacts/frame-editor/generated/editor.txt +149 -0
- package/src/artifacts/frame-editor/generated.d.ts +5 -0
- package/src/artifacts/frame-editor/keys.ts +323 -0
- package/src/artifacts/frame-editor/protocol.ts +151 -0
- package/src/artifacts/frame-editor/schema.ts +293 -0
- package/src/artifacts/frame-editor/style.ts +58 -0
- package/src/artifacts/frame.tsx +14 -5
- package/src/artifacts/live/boards.ts +46 -3
- package/src/artifacts/live/document.ts +89 -0
- package/src/artifacts/live/header.tsx +9 -14
- package/src/artifacts/live/presence.ts +5 -1
- package/src/artifacts/live/session.ts +4 -2
- package/src/artifacts/live/view.ts +14 -8
- package/src/artifacts/messages.ts +192 -2
- package/src/artifacts/pdf.ts +50 -0
- package/src/artifacts/references/references.tsx +46 -11
- package/src/artifacts/renderers/canvas/board-editor.tsx +44 -155
- package/src/artifacts/renderers/canvas/board.tsx +70 -8
- package/src/artifacts/renderers/canvas/canvas.tsx +66 -15
- package/src/artifacts/renderers/canvas/comment-pins.tsx +5 -0
- package/src/artifacts/renderers/canvas/comments-panel.tsx +58 -1
- package/src/artifacts/renderers/canvas/comments.ts +8 -4
- package/src/artifacts/renderers/canvas/controls.tsx +64 -30
- package/src/artifacts/renderers/canvas/focus.tsx +200 -56
- package/src/artifacts/renderers/canvas/gestures.ts +265 -0
- package/src/artifacts/renderers/canvas/page-resize.tsx +542 -0
- package/src/artifacts/renderers/canvas/page-size-controls.tsx +193 -0
- package/src/artifacts/renderers/canvas/page-size.ts +218 -0
- package/src/artifacts/renderers/canvas/page-zoom.ts +280 -0
- package/src/artifacts/renderers/canvas/shown-size.ts +105 -0
- package/src/artifacts/renderers/designed-document.tsx +277 -0
- package/src/artifacts/renderers/document-tree.ts +9 -0
- package/src/artifacts/renderers/document.tsx +13 -102
- package/src/artifacts/renderers/live-frame.ts +163 -0
- package/src/artifacts/renderers/page-editor.tsx +613 -0
- package/src/artifacts/renderers/page.tsx +21 -4
- package/src/artifacts/viewer.tsx +101 -41
- package/src/index.ts +8 -0
- package/src/pages/console/data/messages.ts +6 -0
- package/src/pages/console/data/projections.tsx +4 -0
- package/src/pages/console/data/shared.tsx +1 -0
- package/src/pages/console/ontology/lineage/trail.tsx +3 -0
- package/src/shell/search-command.tsx +2 -0
- package/dist/chunk-001c4gnk.js.map +0 -204
- package/dist/chunk-5crvhjp2.js.map +0 -28
- /package/dist/{chunk-fwb9mxwm.js.map → chunk-5sgac68y.js.map} +0 -0
- /package/dist/{chunk-kes4ygmz.js.map → chunk-69qgh20f.js.map} +0 -0
|
@@ -19,7 +19,7 @@ import {
|
|
|
19
19
|
import { useDictation } from "@sixb/ui/hooks"
|
|
20
20
|
import type { SpeechRecognizer } from "@sixb/ui/lib/speech"
|
|
21
21
|
import { cn } from "@sixb/ui/lib/utils"
|
|
22
|
-
import { useQuery } from "@tanstack/react-query"
|
|
22
|
+
import { useQuery, useQueryClient } from "@tanstack/react-query"
|
|
23
23
|
import {
|
|
24
24
|
AlertTriangle,
|
|
25
25
|
ArrowUp,
|
|
@@ -34,6 +34,7 @@ import {
|
|
|
34
34
|
import {
|
|
35
35
|
type ClipboardEvent,
|
|
36
36
|
type KeyboardEvent,
|
|
37
|
+
memo,
|
|
37
38
|
type ReactNode,
|
|
38
39
|
useCallback,
|
|
39
40
|
useEffect,
|
|
@@ -46,7 +47,8 @@ import { createPortal } from "react-dom"
|
|
|
46
47
|
import { type AgentApprovalMode, toggledApprovalMode } from "../approvals"
|
|
47
48
|
import type { NewThreadPlace } from "../hooks/use-new-thread-place"
|
|
48
49
|
import { useAgentMessages } from "../i18n"
|
|
49
|
-
import type
|
|
50
|
+
import { type ThreadStateStore, useThreadStateStore } from "../thread-state"
|
|
51
|
+
import type { AgentFileRef, AgentMessageDelivery, LanguageModel } from "../types"
|
|
50
52
|
import { agentContextLabel, mergeAgentContext } from "../utils/context-display"
|
|
51
53
|
import {
|
|
52
54
|
type AgentContextMention,
|
|
@@ -74,10 +76,16 @@ import { ContextPicker } from "./context-picker"
|
|
|
74
76
|
import { DictationBar } from "./dictation-bar"
|
|
75
77
|
|
|
76
78
|
export interface ComposerProps {
|
|
79
|
+
/**
|
|
80
|
+
* `delivery` says where the message goes while a turn runs: into it, behind it, or after stopping
|
|
81
|
+
* it. It is `auto` when nothing runs; passed on as `auto` or left out while a turn runs,
|
|
82
|
+
* `useAgentConversation` sends it where Enter would.
|
|
83
|
+
*/
|
|
77
84
|
readonly onSend: (
|
|
78
85
|
text: string,
|
|
79
86
|
attachments: readonly AgentFileRef[],
|
|
80
|
-
context: readonly AgentContextEntryInput[]
|
|
87
|
+
context: readonly AgentContextEntryInput[],
|
|
88
|
+
delivery?: AgentMessageDelivery
|
|
81
89
|
) => void
|
|
82
90
|
readonly disabled?: boolean
|
|
83
91
|
readonly pending?: boolean
|
|
@@ -89,6 +97,11 @@ export interface ComposerProps {
|
|
|
89
97
|
readonly running?: boolean
|
|
90
98
|
/** A stop has been requested and we're waiting for the run to end. */
|
|
91
99
|
readonly stopping?: boolean
|
|
100
|
+
/**
|
|
101
|
+
* The running turn is the reader's own, so a message sent into it steers it. Another person's
|
|
102
|
+
* turn takes no steer: the message queues for the reader's own turn instead.
|
|
103
|
+
*/
|
|
104
|
+
readonly steerable?: boolean
|
|
92
105
|
readonly onStop?: () => void
|
|
93
106
|
readonly models?: readonly LanguageModel[]
|
|
94
107
|
readonly selectedModel?: LanguageModel
|
|
@@ -111,6 +124,8 @@ export interface ComposerProps {
|
|
|
111
124
|
readonly hint?: string
|
|
112
125
|
/** A failed send, kept within the same width constraint as the input. */
|
|
113
126
|
readonly error?: string
|
|
127
|
+
/** Key under which unsent text, attachments, and explicit @ context persist per thread. */
|
|
128
|
+
readonly draftKey?: string
|
|
114
129
|
/**
|
|
115
130
|
* Text to restore into the input, e.g. after a failed send so the user does not lose it.
|
|
116
131
|
* Applied whenever `draftNonce` changes to a non-zero value, so re-sending the same text works.
|
|
@@ -120,11 +135,16 @@ export interface ComposerProps {
|
|
|
120
135
|
/** Exact context snapshot to restore after a failed send. */
|
|
121
136
|
readonly draftContext?: readonly AgentContextEntryInput[]
|
|
122
137
|
readonly draftNonce?: number
|
|
138
|
+
/**
|
|
139
|
+
* The `draftKey` the restored draft belongs to. Another conversation's input leaves it alone:
|
|
140
|
+
* it waits in its own conversation's stored draft.
|
|
141
|
+
*/
|
|
142
|
+
readonly draftReseedKey?: string
|
|
123
143
|
/**
|
|
124
144
|
* What an artifact hands the conversation, such as the comments the reader asks the Agent to
|
|
125
145
|
* act on, each time `nonce` changes to a non-zero value: its context joins the chips, replacing
|
|
126
|
-
* one of the same identity, and its words
|
|
127
|
-
* is sent.
|
|
146
|
+
* one of the same identity, and its words follow the reader's own on a line of their own.
|
|
147
|
+
* Nothing is sent.
|
|
128
148
|
*/
|
|
129
149
|
readonly insertion?: {
|
|
130
150
|
readonly text: string
|
|
@@ -188,7 +208,18 @@ type ComposerAttachment =
|
|
|
188
208
|
readonly sizeBytes: number
|
|
189
209
|
}
|
|
190
210
|
|
|
211
|
+
interface UnlandedAttachment {
|
|
212
|
+
readonly draftKey: string | undefined
|
|
213
|
+
readonly attachment: ComposerAttachment
|
|
214
|
+
}
|
|
215
|
+
|
|
191
216
|
const MAX_HEIGHT_PX = 200
|
|
217
|
+
const EMPTY_AMBIENT_CONTEXT: readonly AgentContextInput[] = []
|
|
218
|
+
|
|
219
|
+
/** The width as laid out, to the fraction of a pixel where the text breaks. */
|
|
220
|
+
function widthOf(element: Element | null): number {
|
|
221
|
+
return element?.getBoundingClientRect().width ?? 0
|
|
222
|
+
}
|
|
192
223
|
|
|
193
224
|
// The microphone and Cancel: round, quiet until hovered.
|
|
194
225
|
const ICON_BUTTON_CLASS_NAME = cn(
|
|
@@ -210,12 +241,13 @@ export function composerCanFocus({
|
|
|
210
241
|
return !disabled && !pending
|
|
211
242
|
}
|
|
212
243
|
|
|
213
|
-
export function Composer({
|
|
244
|
+
export const Composer = memo(function Composer({
|
|
214
245
|
onSend,
|
|
215
246
|
disabled,
|
|
216
247
|
pending,
|
|
217
248
|
running,
|
|
218
249
|
stopping,
|
|
250
|
+
steerable = true,
|
|
219
251
|
onStop,
|
|
220
252
|
models = [],
|
|
221
253
|
selectedModel,
|
|
@@ -232,19 +264,21 @@ export function Composer({
|
|
|
232
264
|
className,
|
|
233
265
|
hint,
|
|
234
266
|
error,
|
|
267
|
+
draftKey,
|
|
235
268
|
draft,
|
|
236
269
|
draftAttachments,
|
|
237
270
|
draftContext,
|
|
238
271
|
draftNonce,
|
|
272
|
+
draftReseedKey,
|
|
239
273
|
insertion,
|
|
240
274
|
onInserted,
|
|
241
|
-
ambientContext =
|
|
275
|
+
ambientContext = EMPTY_AMBIENT_CONTEXT,
|
|
242
276
|
compact = false,
|
|
243
277
|
approvalMode,
|
|
244
278
|
onApprovalModeChange,
|
|
245
279
|
awaitingApproval = false,
|
|
246
280
|
dictation,
|
|
247
|
-
commands = [],
|
|
281
|
+
commands: customCommands = [],
|
|
248
282
|
contextMeter,
|
|
249
283
|
newThreadPlace,
|
|
250
284
|
newThreadControls,
|
|
@@ -252,10 +286,15 @@ export function Composer({
|
|
|
252
286
|
const agentMessages = useAgentMessages()
|
|
253
287
|
const messages = agentMessages.composer
|
|
254
288
|
const unnamedContext = agentMessages.context.unnamed
|
|
255
|
-
const
|
|
256
|
-
const
|
|
289
|
+
const queryClient = useQueryClient()
|
|
290
|
+
const threadState = useThreadStateStore(queryClient)
|
|
291
|
+
const [loadedDraftKey, setLoadedDraftKey] = useState(draftKey)
|
|
292
|
+
const [value, setValue] = useState(() => readInitialDraftText(threadState, draftKey))
|
|
293
|
+
const [attachments, setAttachments] = useState<ComposerAttachment[]>(() =>
|
|
294
|
+
readInitialDraftAttachments(threadState, draftKey)
|
|
295
|
+
)
|
|
257
296
|
const [contextEntries, setContextEntries] = useState<AgentContextEntryInput[]>(() =>
|
|
258
|
-
|
|
297
|
+
readInitialDraftContext(threadState, draftKey, ambientContext)
|
|
259
298
|
)
|
|
260
299
|
const [mention, setMention] = useState<AgentContextMention | null>(null)
|
|
261
300
|
const [dismissedMention, setDismissedMention] = useState<string | null>(null)
|
|
@@ -271,11 +310,16 @@ export function Composer({
|
|
|
271
310
|
const rootRef = useRef<HTMLDivElement>(null)
|
|
272
311
|
const textareaRef = useRef<HTMLTextAreaElement>(null)
|
|
273
312
|
const sizerRef = useRef<HTMLSpanElement>(null)
|
|
274
|
-
|
|
275
|
-
const inlineWidthRef = useRef(0)
|
|
313
|
+
const spacerRef = useRef<HTMLSpanElement>(null)
|
|
276
314
|
const fileInputRef = useRef<HTMLInputElement>(null)
|
|
277
315
|
const dragDepthRef = useRef(0)
|
|
278
316
|
const uploadFile = useUploadFile()
|
|
317
|
+
// Each file that has not landed, still uploading or failed, and the conversation it was attached
|
|
318
|
+
// in. A stored draft keeps only landed files: these come back with their conversation, and one
|
|
319
|
+
// landing after the reader left joins that conversation's draft.
|
|
320
|
+
const unlandedRef = useRef(new Map<string, UnlandedAttachment>())
|
|
321
|
+
const draftKeyRef = useRef(draftKey)
|
|
322
|
+
draftKeyRef.current = draftKey
|
|
279
323
|
// The transcript is appended to the text as it was when dictation started, so the input stays
|
|
280
324
|
// read-only until it lands. Recording ends only when the reader stops it: no restarts. A
|
|
281
325
|
// composer disabled meanwhile, by someone else's turn, only keeps a new dictation from starting.
|
|
@@ -317,27 +361,82 @@ export function Composer({
|
|
|
317
361
|
}))
|
|
318
362
|
}, [ambientContext, contextSearch.data?.items, mention, unnamedContext])
|
|
319
363
|
|
|
364
|
+
if (loadedDraftKey !== draftKey) {
|
|
365
|
+
setLoadedDraftKey(draftKey)
|
|
366
|
+
setValue(readInitialDraftText(threadState, draftKey))
|
|
367
|
+
setAttachments([
|
|
368
|
+
...readInitialDraftAttachments(threadState, draftKey),
|
|
369
|
+
...unlandedAttachments(unlandedRef.current, draftKey),
|
|
370
|
+
])
|
|
371
|
+
setContextEntries(readInitialDraftContext(threadState, draftKey, ambientContext))
|
|
372
|
+
setMention(null)
|
|
373
|
+
setDismissedMention(null)
|
|
374
|
+
setDismissedCommand(null)
|
|
375
|
+
setActiveCommand(0)
|
|
376
|
+
}
|
|
377
|
+
|
|
320
378
|
const uploading = attachments.some((attachment) => attachment.status === "uploading")
|
|
321
|
-
const readyAttachments =
|
|
322
|
-
|
|
323
|
-
|
|
379
|
+
const readyAttachments = useMemo(() => readyAttachmentFiles(attachments), [attachments])
|
|
380
|
+
const explicitContext = useMemo(() => explicitEntries(contextEntries), [contextEntries])
|
|
381
|
+
|
|
382
|
+
useEffect(() => {
|
|
383
|
+
if (!draftKey || loadedDraftKey !== draftKey) return
|
|
384
|
+
threadState.writeDraft(draftKey, {
|
|
385
|
+
text: value,
|
|
386
|
+
attachments: readyAttachments,
|
|
387
|
+
explicitContext,
|
|
388
|
+
})
|
|
389
|
+
}, [threadState, draftKey, loadedDraftKey, value, readyAttachments, explicitContext])
|
|
324
390
|
const failedCount = attachments.filter((attachment) => attachment.status === "error").length
|
|
325
391
|
const canAttachFiles = !disabled && !pending
|
|
326
392
|
const showPermissions = approvalMode !== undefined && onApprovalModeChange !== undefined
|
|
327
393
|
const commandText = commandQuery(value)
|
|
394
|
+
const choosesModel = onSelectModel !== undefined && onSelectReasoning !== undefined
|
|
395
|
+
const changeApprovalMode = useCallback(
|
|
396
|
+
(mode: AgentApprovalMode) => {
|
|
397
|
+
onApprovalModeChange?.(mode)
|
|
398
|
+
setModeAnnouncement(
|
|
399
|
+
agentMessages.approvalModes.changed(agentMessages.approvalModes.modes[mode].label)
|
|
400
|
+
)
|
|
401
|
+
},
|
|
402
|
+
[onApprovalModeChange, agentMessages.approvalModes]
|
|
403
|
+
)
|
|
404
|
+
const availableCommands = useMemo(
|
|
405
|
+
(): readonly ComposerCommand[] => [
|
|
406
|
+
...builtInCommands({
|
|
407
|
+
models,
|
|
408
|
+
onSelectModel: choosesModel ? onSelectModel : undefined,
|
|
409
|
+
onResetModelSelection: choosesModel ? onResetModelSelection : undefined,
|
|
410
|
+
onApprovalModeChange: showPermissions ? changeApprovalMode : undefined,
|
|
411
|
+
messages: agentMessages.commands,
|
|
412
|
+
}),
|
|
413
|
+
...customCommands,
|
|
414
|
+
],
|
|
415
|
+
[
|
|
416
|
+
models,
|
|
417
|
+
choosesModel,
|
|
418
|
+
onSelectModel,
|
|
419
|
+
onResetModelSelection,
|
|
420
|
+
showPermissions,
|
|
421
|
+
changeApprovalMode,
|
|
422
|
+
agentMessages.commands,
|
|
423
|
+
customCommands,
|
|
424
|
+
]
|
|
425
|
+
)
|
|
328
426
|
const commandMatches =
|
|
329
427
|
commandText === null || dismissedCommand === value || voice.isActive
|
|
330
428
|
? []
|
|
331
|
-
: matchCommands(
|
|
429
|
+
: matchCommands(availableCommands, commandText).slice(0, 6)
|
|
332
430
|
const commandsOpen = commandMatches.length > 0
|
|
333
431
|
// Files alone are a message too.
|
|
432
|
+
// A message sent while a turn runs steers it, so the input stays usable: the reader corrects the
|
|
433
|
+
// answer they are watching rather than waiting for it.
|
|
334
434
|
const canSend =
|
|
335
435
|
(value.trim().length > 0 || readyAttachments.length > 0) &&
|
|
336
436
|
mention === null &&
|
|
337
437
|
!commandsOpen &&
|
|
338
438
|
!disabled &&
|
|
339
439
|
!pending &&
|
|
340
|
-
!running &&
|
|
341
440
|
!uploading &&
|
|
342
441
|
!voice.isActive &&
|
|
343
442
|
failedCount === 0
|
|
@@ -365,10 +464,20 @@ export function Composer({
|
|
|
365
464
|
|
|
366
465
|
// Reseed the input on demand (a failed send hands the text and already-uploaded attachments back).
|
|
367
466
|
// Keyed on the nonce so restoring the same draft twice still fires; ignored on mount (nonce 0) so
|
|
368
|
-
// it never clobbers a fresh draft.
|
|
467
|
+
// it never clobbers a fresh draft. One for another conversation goes to that one's stored draft.
|
|
369
468
|
// biome-ignore lint/correctness/useExhaustiveDependencies: reseed only when the nonce changes
|
|
370
469
|
useEffect(() => {
|
|
371
470
|
if (!draftNonce) return
|
|
471
|
+
|
|
472
|
+
if (draftReseedKey !== undefined && draftReseedKey !== draftKey) {
|
|
473
|
+
threadState.writeDraft(draftReseedKey, {
|
|
474
|
+
text: draft ?? "",
|
|
475
|
+
attachments: draftAttachments ?? [],
|
|
476
|
+
explicitContext: explicitEntries(draftContext ?? []),
|
|
477
|
+
})
|
|
478
|
+
return
|
|
479
|
+
}
|
|
480
|
+
|
|
372
481
|
setValue(draft ?? "")
|
|
373
482
|
setAttachments(
|
|
374
483
|
(draftAttachments ?? []).map((fileRef) => ({
|
|
@@ -391,7 +500,7 @@ export function Composer({
|
|
|
391
500
|
textareaRef.current?.focus()
|
|
392
501
|
}, [draftNonce])
|
|
393
502
|
|
|
394
|
-
// What an artifact hands the input: its context as a chip, its words
|
|
503
|
+
// What an artifact hands the input: its context as a chip, its words after the reader's, the
|
|
395
504
|
// caret after what the input holds.
|
|
396
505
|
// biome-ignore lint/correctness/useExhaustiveDependencies: added only when the nonce changes
|
|
397
506
|
useEffect(() => {
|
|
@@ -404,7 +513,7 @@ export function Composer({
|
|
|
404
513
|
{ context, origin: "explicit" },
|
|
405
514
|
])
|
|
406
515
|
}
|
|
407
|
-
setValue((current) => (current
|
|
516
|
+
setValue((current) => withInsertedText(current, text))
|
|
408
517
|
onInserted?.(insertion.nonce)
|
|
409
518
|
requestAnimationFrame(() => {
|
|
410
519
|
const input = textareaRef.current
|
|
@@ -414,6 +523,11 @@ export function Composer({
|
|
|
414
523
|
})
|
|
415
524
|
}, [insertion?.nonce])
|
|
416
525
|
|
|
526
|
+
// A dictation belongs to the conversation it started in: opening another one ends it, before
|
|
527
|
+
// its transcript can replace that conversation's draft.
|
|
528
|
+
// biome-ignore lint/correctness/useExhaustiveDependencies: ends only when the conversation changes
|
|
529
|
+
useLayoutEffect(() => () => voice.abort(), [draftKey])
|
|
530
|
+
|
|
417
531
|
// However a dictation ends, the focus returns to the input, the caret after any transcript.
|
|
418
532
|
useEffect(() => {
|
|
419
533
|
const wasDictating = wasDictatingRef.current
|
|
@@ -442,26 +556,47 @@ export function Composer({
|
|
|
442
556
|
}
|
|
443
557
|
}, [disabled, pending])
|
|
444
558
|
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
559
|
+
const placeholderText =
|
|
560
|
+
voice.status === "stopping"
|
|
561
|
+
? messages.dictationTranscribing
|
|
562
|
+
: voice.isActive
|
|
563
|
+
? messages.dictationListening
|
|
564
|
+
: awaitingApproval
|
|
565
|
+
? agentMessages.approvals.composerPlaceholder
|
|
566
|
+
: (placeholder ?? messages.placeholder)
|
|
567
|
+
|
|
568
|
+
// Text that no longer fits in one row beside the controls takes a row of its own, with the
|
|
569
|
+
// controls under it. The text is the draft or the placeholder, whichever is wider.
|
|
448
570
|
const expanded =
|
|
449
571
|
wraps ||
|
|
450
572
|
value.includes("\n") ||
|
|
451
573
|
attachments.length > 0 ||
|
|
452
574
|
contextEntries.length > 0 ||
|
|
453
575
|
(voice.isActive && value.trim().length > 0)
|
|
576
|
+
|
|
577
|
+
// Whether the text is wider than the room the controls leave it in their row. That room is the
|
|
578
|
+
// textarea's while it shares the row, and the spacer's, in its place beside `+`, once the text
|
|
579
|
+
// has a row of its own.
|
|
580
|
+
const textWraps = (textarea: HTMLTextAreaElement) => {
|
|
581
|
+
// The dictation bar holds the row, and a transcript already gets a row of its own.
|
|
582
|
+
if (voice.isActive) return false
|
|
583
|
+
|
|
584
|
+
// Not laid out, as in a hidden panel: there is nothing to measure yet.
|
|
585
|
+
if (!rootRef.current?.clientWidth) return wraps
|
|
586
|
+
|
|
587
|
+
const room = widthOf(expanded ? spacerRef.current : textarea)
|
|
588
|
+
return widthOf(sizerRef.current) > room
|
|
589
|
+
}
|
|
590
|
+
|
|
454
591
|
// Grow the textarea to fit its content, up to a max height where it starts scrolling.
|
|
455
592
|
// Keep overflow hidden until the content actually exceeds the cap so an empty input does not
|
|
456
593
|
// render a scrollbar in browsers configured to always show scroll bars.
|
|
457
594
|
const measure = () => {
|
|
458
595
|
const el = textareaRef.current
|
|
459
596
|
if (!el) return
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
sizer !== null && inlineWidthRef.current > 0 && sizer.offsetWidth > inlineWidthRef.current
|
|
464
|
-
)
|
|
597
|
+
|
|
598
|
+
setWraps(textWraps(el))
|
|
599
|
+
|
|
465
600
|
el.style.height = "auto"
|
|
466
601
|
el.style.overflowY = el.scrollHeight > MAX_HEIGHT_PX ? "auto" : "hidden"
|
|
467
602
|
el.style.height = `${Math.min(el.scrollHeight, MAX_HEIGHT_PX)}px`
|
|
@@ -469,34 +604,60 @@ export function Composer({
|
|
|
469
604
|
const measureRef = useRef(measure)
|
|
470
605
|
measureRef.current = measure
|
|
471
606
|
|
|
607
|
+
// Measured before paint whenever the text changes, or the models land and the settings chip
|
|
608
|
+
// names one, so the box never shows the wrong shape for a frame.
|
|
472
609
|
// biome-ignore lint/correctness/useExhaustiveDependencies: re-measure whenever the text changes
|
|
473
|
-
useLayoutEffect(measure, [
|
|
610
|
+
useLayoutEffect(measure, [
|
|
611
|
+
value,
|
|
612
|
+
placeholderText,
|
|
613
|
+
voice.isActive,
|
|
614
|
+
modelsLoading,
|
|
615
|
+
attachments.length,
|
|
616
|
+
contextEntries.length,
|
|
617
|
+
expanded,
|
|
618
|
+
])
|
|
474
619
|
|
|
475
|
-
// The
|
|
476
|
-
//
|
|
477
|
-
//
|
|
620
|
+
// The room changes without the text changing: a run starts or stops, a model is picked, or the
|
|
621
|
+
// window resizes.
|
|
622
|
+
// biome-ignore lint/correctness/useExhaustiveDependencies: the spacer is drawn anew once dictation ends
|
|
478
623
|
useEffect(() => {
|
|
479
624
|
const el = textareaRef.current
|
|
480
625
|
if (!el) return
|
|
481
|
-
|
|
626
|
+
|
|
627
|
+
const spacer = spacerRef.current
|
|
628
|
+
let textWidth = widthOf(el)
|
|
629
|
+
let spacerWidth = widthOf(spacer)
|
|
482
630
|
let frame = 0
|
|
483
631
|
// Measuring resizes the textarea, so it waits a frame rather than resize inside the callback.
|
|
484
632
|
const observer = new ResizeObserver(() => {
|
|
485
|
-
|
|
486
|
-
|
|
633
|
+
const nextTextWidth = widthOf(el)
|
|
634
|
+
const nextSpacerWidth = widthOf(spacer)
|
|
635
|
+
if (nextTextWidth === textWidth && nextSpacerWidth === spacerWidth) return
|
|
636
|
+
textWidth = nextTextWidth
|
|
637
|
+
spacerWidth = nextSpacerWidth
|
|
487
638
|
cancelAnimationFrame(frame)
|
|
488
639
|
frame = requestAnimationFrame(() => measureRef.current())
|
|
489
640
|
})
|
|
490
641
|
observer.observe(el)
|
|
642
|
+
if (spacer) observer.observe(spacer)
|
|
491
643
|
return () => {
|
|
492
644
|
observer.disconnect()
|
|
493
645
|
cancelAnimationFrame(frame)
|
|
494
646
|
}
|
|
495
|
-
}, [])
|
|
647
|
+
}, [voice.isActive])
|
|
648
|
+
|
|
649
|
+
// While a turn runs, a message goes somewhere: the send button does what Enter does. A file
|
|
650
|
+
// never goes into the answer in flight, which reads text at its next step: it goes after it.
|
|
651
|
+
const deliveryOf = (delivery: AgentMessageDelivery): AgentMessageDelivery => {
|
|
652
|
+
if (!running) return "auto"
|
|
653
|
+
const where = delivery === "auto" ? (steerable ? "steer" : "queue") : delivery
|
|
654
|
+
return where === "steer" && readyAttachments.length > 0 ? "queue" : where
|
|
655
|
+
}
|
|
496
656
|
|
|
497
|
-
const submit = () => {
|
|
657
|
+
const submit = (delivery: AgentMessageDelivery = "auto") => {
|
|
498
658
|
if (!canSend) return
|
|
499
|
-
onSend(value.trim(), readyAttachments, contextEntries)
|
|
659
|
+
onSend(value.trim(), readyAttachments, contextEntries, deliveryOf(delivery))
|
|
660
|
+
if (draftKey) threadState.clearDraft(draftKey)
|
|
500
661
|
setValue("")
|
|
501
662
|
voice.reset()
|
|
502
663
|
setAttachments([])
|
|
@@ -534,37 +695,51 @@ export function Composer({
|
|
|
534
695
|
mediaType: file.type || undefined,
|
|
535
696
|
sizeBytes: file.size,
|
|
536
697
|
}
|
|
698
|
+
unlandedRef.current.set(id, { draftKey: draftKeyRef.current, attachment: pendingAttachment })
|
|
537
699
|
setAttachments((current) => [...current, pendingAttachment])
|
|
538
700
|
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
|
|
701
|
+
const settle = (settled: ComposerAttachment) => {
|
|
702
|
+
const unlanded = unlandedRef.current.get(id)
|
|
703
|
+
// The reader removed it while it uploaded.
|
|
704
|
+
if (!unlanded) return
|
|
705
|
+
|
|
706
|
+
if (settled.status === "ready") unlandedRef.current.delete(id)
|
|
707
|
+
else unlandedRef.current.set(id, { ...unlanded, attachment: settled })
|
|
708
|
+
|
|
709
|
+
if (unlanded.draftKey === draftKeyRef.current) {
|
|
542
710
|
setAttachments((current) =>
|
|
543
|
-
current.map((attachment) =>
|
|
544
|
-
attachment.id === id
|
|
545
|
-
? { id, status: "ready", fileRef: fileRef as AgentFileRef }
|
|
546
|
-
: attachment
|
|
547
|
-
)
|
|
711
|
+
current.map((attachment) => (attachment.id === id ? settled : attachment))
|
|
548
712
|
)
|
|
549
|
-
|
|
713
|
+
return
|
|
714
|
+
}
|
|
715
|
+
|
|
716
|
+
// The reader opened another conversation meanwhile: the file joins the draft of the one
|
|
717
|
+
// it was attached in.
|
|
718
|
+
if (unlanded.draftKey && settled.status === "ready") {
|
|
719
|
+
const stored = threadState.readDraft(unlanded.draftKey)
|
|
720
|
+
threadState.writeDraft(unlanded.draftKey, {
|
|
721
|
+
text: stored?.text ?? "",
|
|
722
|
+
attachments: [...(stored?.attachments ?? []), settled.fileRef],
|
|
723
|
+
explicitContext: stored?.explicitContext ?? [],
|
|
724
|
+
})
|
|
725
|
+
}
|
|
726
|
+
}
|
|
727
|
+
|
|
728
|
+
uploadFile
|
|
729
|
+
.mutateAsync({ file, fileName: file.name })
|
|
730
|
+
.then((fileRef) => settle({ id, status: "ready", fileRef: fileRef as AgentFileRef }))
|
|
550
731
|
// The API explains failures to developers; the composer shows its own message.
|
|
551
|
-
.catch(() =>
|
|
552
|
-
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
|
|
559
|
-
|
|
560
|
-
sizeBytes: file.size,
|
|
561
|
-
}
|
|
562
|
-
: attachment
|
|
563
|
-
)
|
|
564
|
-
)
|
|
565
|
-
})
|
|
732
|
+
.catch(() =>
|
|
733
|
+
settle({
|
|
734
|
+
id,
|
|
735
|
+
status: "error",
|
|
736
|
+
fileName: file.name,
|
|
737
|
+
mediaType: file.type || undefined,
|
|
738
|
+
sizeBytes: file.size,
|
|
739
|
+
})
|
|
740
|
+
)
|
|
566
741
|
},
|
|
567
|
-
[uploadFile]
|
|
742
|
+
[uploadFile, threadState]
|
|
568
743
|
)
|
|
569
744
|
|
|
570
745
|
const handleFilesSelected = useCallback(
|
|
@@ -649,6 +824,7 @@ export function Composer({
|
|
|
649
824
|
}, [canAttachFiles, compact, handleFilesSelected])
|
|
650
825
|
|
|
651
826
|
const removeAttachment = (id: string) => {
|
|
827
|
+
unlandedRef.current.delete(id)
|
|
652
828
|
setAttachments((current) => current.filter((attachment) => attachment.id !== id))
|
|
653
829
|
}
|
|
654
830
|
|
|
@@ -709,28 +885,6 @@ export function Composer({
|
|
|
709
885
|
})
|
|
710
886
|
}
|
|
711
887
|
|
|
712
|
-
const changeApprovalMode = (mode: AgentApprovalMode) => {
|
|
713
|
-
onApprovalModeChange?.(mode)
|
|
714
|
-
setModeAnnouncement(
|
|
715
|
-
agentMessages.approvalModes.changed(agentMessages.approvalModes.modes[mode].label)
|
|
716
|
-
)
|
|
717
|
-
}
|
|
718
|
-
|
|
719
|
-
function allCommands(): readonly ComposerCommand[] {
|
|
720
|
-
const choosesModel = onSelectModel !== undefined && onSelectReasoning !== undefined
|
|
721
|
-
return [
|
|
722
|
-
...builtInCommands({
|
|
723
|
-
models,
|
|
724
|
-
onSelectModel: choosesModel ? onSelectModel : undefined,
|
|
725
|
-
onResetModelSelection: choosesModel ? onResetModelSelection : undefined,
|
|
726
|
-
// Called on Enter, long after the render that lists it.
|
|
727
|
-
onApprovalModeChange: showPermissions ? (mode) => changeApprovalMode(mode) : undefined,
|
|
728
|
-
messages: agentMessages.commands,
|
|
729
|
-
}),
|
|
730
|
-
...commands,
|
|
731
|
-
]
|
|
732
|
-
}
|
|
733
|
-
|
|
734
888
|
const runCommand = (command: ComposerCommand) => {
|
|
735
889
|
command.run()
|
|
736
890
|
setValue("")
|
|
@@ -846,6 +1000,27 @@ export function Composer({
|
|
|
846
1000
|
return
|
|
847
1001
|
}
|
|
848
1002
|
}
|
|
1003
|
+
// While a turn runs, Enter sends as always: a steer into the reader's own answer, a queued message
|
|
1004
|
+
// behind another's. Tab queues a draft for the next turn instead, and the modifier sends it now.
|
|
1005
|
+
// An empty composer leaves Tab to move focus.
|
|
1006
|
+
if (running) {
|
|
1007
|
+
if (event.key === "Tab" && canSend && !event.shiftKey && !event.metaKey && !event.ctrlKey) {
|
|
1008
|
+
event.preventDefault()
|
|
1009
|
+
submit("queue")
|
|
1010
|
+
return
|
|
1011
|
+
}
|
|
1012
|
+
if (event.key === "Enter" && (event.metaKey || event.ctrlKey)) {
|
|
1013
|
+
event.preventDefault()
|
|
1014
|
+
submit(steerable ? "send_now" : "queue")
|
|
1015
|
+
return
|
|
1016
|
+
}
|
|
1017
|
+
if (event.key === "Enter" && !event.shiftKey) {
|
|
1018
|
+
event.preventDefault()
|
|
1019
|
+
submit(steerable ? "steer" : "queue")
|
|
1020
|
+
return
|
|
1021
|
+
}
|
|
1022
|
+
return
|
|
1023
|
+
}
|
|
849
1024
|
if (event.key !== "Enter") return
|
|
850
1025
|
if (event.shiftKey) return
|
|
851
1026
|
event.preventDefault()
|
|
@@ -909,8 +1084,9 @@ export function Composer({
|
|
|
909
1084
|
onRun={runCommand}
|
|
910
1085
|
/>
|
|
911
1086
|
{/*
|
|
912
|
-
One row while the
|
|
913
|
-
of its own and the controls sit under it. Attachments and context lead, on their own
|
|
1087
|
+
One row while the text fits beside the controls; once it doesn't, the text gets a row
|
|
1088
|
+
of its own and the controls sit under it. Attachments and context lead, on their own
|
|
1089
|
+
row.
|
|
914
1090
|
*/}
|
|
915
1091
|
<div
|
|
916
1092
|
data-dragging={draggingFiles || undefined}
|
|
@@ -920,16 +1096,22 @@ export function Composer({
|
|
|
920
1096
|
data-focus-on-tap=""
|
|
921
1097
|
className="group/composer sixb-composer-surface relative flex flex-wrap items-end gap-0.5 rounded-[30px] p-2.5 data-[expanded]:gap-y-1 data-[expanded]:rounded-[26px]"
|
|
922
1098
|
>
|
|
923
|
-
{/*
|
|
1099
|
+
{/*
|
|
1100
|
+
The text on one line, to tell when it stops fitting beside the controls: as wide as
|
|
1101
|
+
the draft or the placeholder, whichever is wider, so a box folded for its placeholder
|
|
1102
|
+
doesn't snap back into the row at the first letter typed.
|
|
1103
|
+
*/}
|
|
924
1104
|
<span
|
|
925
1105
|
aria-hidden="true"
|
|
926
1106
|
className="pointer-events-none invisible absolute inset-0 overflow-hidden"
|
|
927
1107
|
>
|
|
928
1108
|
<span
|
|
929
1109
|
ref={sizerRef}
|
|
930
|
-
|
|
1110
|
+
data-composer-sizer=""
|
|
1111
|
+
className="absolute grid whitespace-pre px-2 text-[16px] tracking-[-0.012em]"
|
|
931
1112
|
>
|
|
932
|
-
{value}
|
|
1113
|
+
<span>{value}</span>
|
|
1114
|
+
<span>{placeholderText}</span>
|
|
933
1115
|
</span>
|
|
934
1116
|
</span>
|
|
935
1117
|
{contextEntries.length > 0 || attachments.length > 0 ? (
|
|
@@ -965,12 +1147,14 @@ export function Composer({
|
|
|
965
1147
|
onAddFiles={canAttachFiles ? () => fileInputRef.current?.click() : undefined}
|
|
966
1148
|
onMention={() => insertAtCaret("@")}
|
|
967
1149
|
onCommand={
|
|
968
|
-
value.length === 0 &&
|
|
1150
|
+
value.length === 0 && availableCommands.length > 0
|
|
969
1151
|
? () => insertAtCaret("/")
|
|
970
1152
|
: undefined
|
|
971
1153
|
}
|
|
972
1154
|
/>
|
|
973
1155
|
<span
|
|
1156
|
+
ref={spacerRef}
|
|
1157
|
+
data-composer-spacer=""
|
|
974
1158
|
aria-hidden="true"
|
|
975
1159
|
className="hidden flex-1 group-data-[expanded]/composer:block"
|
|
976
1160
|
/>
|
|
@@ -995,15 +1179,7 @@ export function Composer({
|
|
|
995
1179
|
disabled={disabled}
|
|
996
1180
|
readOnly={voice.isActive}
|
|
997
1181
|
rows={1}
|
|
998
|
-
placeholder={
|
|
999
|
-
voice.status === "stopping"
|
|
1000
|
-
? messages.dictationTranscribing
|
|
1001
|
-
: voice.isActive
|
|
1002
|
-
? messages.dictationListening
|
|
1003
|
-
: awaitingApproval
|
|
1004
|
-
? agentMessages.approvals.composerPlaceholder
|
|
1005
|
-
: (placeholder ?? messages.placeholder)
|
|
1006
|
-
}
|
|
1182
|
+
placeholder={placeholderText}
|
|
1007
1183
|
aria-label={messages.message}
|
|
1008
1184
|
className={cn(
|
|
1009
1185
|
"max-h-[200px] min-h-10 min-w-0 flex-1 resize-none overflow-y-hidden rounded-none border-0 bg-transparent px-2 py-2 text-[16px] leading-6 tracking-[-0.012em] shadow-none placeholder:text-muted-foreground focus-visible:ring-0 md:text-[16px] dark:bg-transparent",
|
|
@@ -1050,7 +1226,8 @@ export function Composer({
|
|
|
1050
1226
|
)}
|
|
1051
1227
|
/>
|
|
1052
1228
|
) : null}
|
|
1053
|
-
{
|
|
1229
|
+
{/* Stop while there is nothing to send; a draft turns it back into send. */}
|
|
1230
|
+
{running && onStop && !hasDraft ? (
|
|
1054
1231
|
<button
|
|
1055
1232
|
type="button"
|
|
1056
1233
|
onClick={onStop}
|
|
@@ -1067,9 +1244,17 @@ export function Composer({
|
|
|
1067
1244
|
) : showSend ? (
|
|
1068
1245
|
<button
|
|
1069
1246
|
type="button"
|
|
1070
|
-
onClick={submit}
|
|
1247
|
+
onClick={() => submit()}
|
|
1071
1248
|
disabled={!canSend}
|
|
1072
1249
|
aria-label={messages.send}
|
|
1250
|
+
// While an answer runs, where the message goes.
|
|
1251
|
+
title={
|
|
1252
|
+
running
|
|
1253
|
+
? deliveryOf("auto") === "steer"
|
|
1254
|
+
? messages.steer
|
|
1255
|
+
: messages.queue
|
|
1256
|
+
: undefined
|
|
1257
|
+
}
|
|
1073
1258
|
className={SEND_BUTTON_CLASS_NAME}
|
|
1074
1259
|
>
|
|
1075
1260
|
{pending || uploading ? (
|
|
@@ -1119,7 +1304,7 @@ export function Composer({
|
|
|
1119
1304
|
</div>
|
|
1120
1305
|
</div>
|
|
1121
1306
|
)
|
|
1122
|
-
}
|
|
1307
|
+
})
|
|
1123
1308
|
|
|
1124
1309
|
function DropFilesOverlay({ compact }: { readonly compact: boolean }) {
|
|
1125
1310
|
const messages = useAgentMessages().composer
|
|
@@ -1265,3 +1450,56 @@ function contextLabel(label: string): { readonly label?: string } {
|
|
|
1265
1450
|
: trimmed,
|
|
1266
1451
|
}
|
|
1267
1452
|
}
|
|
1453
|
+
|
|
1454
|
+
/** A draft restored with its conversation keeps its words; the handed ones come after them, once. */
|
|
1455
|
+
function withInsertedText(current: string, text: string): string {
|
|
1456
|
+
if (!current.trim()) return text
|
|
1457
|
+
if (!text || current.includes(text)) return current
|
|
1458
|
+
return `${current.trimEnd()}\n${text}`
|
|
1459
|
+
}
|
|
1460
|
+
|
|
1461
|
+
function readInitialDraftText(store: ThreadStateStore, draftKey: string | undefined): string {
|
|
1462
|
+
return draftKey ? (store.readDraft(draftKey)?.text ?? "") : ""
|
|
1463
|
+
}
|
|
1464
|
+
|
|
1465
|
+
function readInitialDraftAttachments(
|
|
1466
|
+
store: ThreadStateStore,
|
|
1467
|
+
draftKey: string | undefined
|
|
1468
|
+
): ComposerAttachment[] {
|
|
1469
|
+
if (!draftKey) return []
|
|
1470
|
+
return (store.readDraft(draftKey)?.attachments ?? []).map((fileRef) => ({
|
|
1471
|
+
id: attachmentId(),
|
|
1472
|
+
status: "ready",
|
|
1473
|
+
fileRef,
|
|
1474
|
+
}))
|
|
1475
|
+
}
|
|
1476
|
+
|
|
1477
|
+
function unlandedAttachments(
|
|
1478
|
+
unlanded: ReadonlyMap<string, UnlandedAttachment>,
|
|
1479
|
+
draftKey: string | undefined
|
|
1480
|
+
): ComposerAttachment[] {
|
|
1481
|
+
return [...unlanded.values()].flatMap((entry) =>
|
|
1482
|
+
entry.draftKey === draftKey ? [entry.attachment] : []
|
|
1483
|
+
)
|
|
1484
|
+
}
|
|
1485
|
+
|
|
1486
|
+
function readInitialDraftContext(
|
|
1487
|
+
store: ThreadStateStore,
|
|
1488
|
+
draftKey: string | undefined,
|
|
1489
|
+
ambientContext: readonly AgentContextInput[]
|
|
1490
|
+
): AgentContextEntryInput[] {
|
|
1491
|
+
const explicit = draftKey ? (store.readDraft(draftKey)?.explicitContext ?? []) : []
|
|
1492
|
+
const explicitIds = new Set(explicit.map((entry) => agentContextIdentity(entry.context)))
|
|
1493
|
+
const ambient = ambientContext
|
|
1494
|
+
.filter((context) => !explicitIds.has(agentContextIdentity(context)))
|
|
1495
|
+
.map((context) => ({ context, origin: "ambient" as const }))
|
|
1496
|
+
return [...ambient, ...explicit]
|
|
1497
|
+
}
|
|
1498
|
+
|
|
1499
|
+
function readyAttachmentFiles(attachments: readonly ComposerAttachment[]): AgentFileRef[] {
|
|
1500
|
+
return attachments.flatMap((item) => (item.status === "ready" ? [item.fileRef] : []))
|
|
1501
|
+
}
|
|
1502
|
+
|
|
1503
|
+
function explicitEntries(entries: readonly AgentContextEntryInput[]): AgentContextEntryInput[] {
|
|
1504
|
+
return entries.filter((entry) => entry.origin === "explicit")
|
|
1505
|
+
}
|