@sixb/app 0.2.4 → 0.2.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (306) hide show
  1. package/assets/connector-icons/README.md +1 -0
  2. package/assets/connector-icons/ctm.png +0 -0
  3. package/dist/agent/activity-label.d.ts.map +1 -1
  4. package/dist/agent/agent-chat.d.ts +3 -1
  5. package/dist/agent/agent-chat.d.ts.map +1 -1
  6. package/dist/agent/agent-panel.d.ts.map +1 -1
  7. package/dist/agent/artifact-panel.d.ts +3 -1
  8. package/dist/agent/artifact-panel.d.ts.map +1 -1
  9. package/dist/agent/components/agent-threads.d.ts.map +1 -1
  10. package/dist/agent/components/composer-place.d.ts.map +1 -1
  11. package/dist/agent/components/composer-settings.d.ts +1 -1
  12. package/dist/agent/components/composer-settings.d.ts.map +1 -1
  13. package/dist/agent/components/composer.d.ts +22 -5
  14. package/dist/agent/components/composer.d.ts.map +1 -1
  15. package/dist/agent/components/computer-place.d.ts +24 -6
  16. package/dist/agent/components/computer-place.d.ts.map +1 -1
  17. package/dist/agent/components/context-meter.d.ts +1 -1
  18. package/dist/agent/components/context-meter.d.ts.map +1 -1
  19. package/dist/agent/components/conversation-panel.d.ts +5 -2
  20. package/dist/agent/components/conversation-panel.d.ts.map +1 -1
  21. package/dist/agent/components/message-parts.d.ts +2 -1
  22. package/dist/agent/components/message-parts.d.ts.map +1 -1
  23. package/dist/agent/components/message-view.d.ts +13 -3
  24. package/dist/agent/components/message-view.d.ts.map +1 -1
  25. package/dist/agent/components/pending-messages.d.ts +20 -0
  26. package/dist/agent/components/pending-messages.d.ts.map +1 -0
  27. package/dist/agent/components/sandbox-recovery.d.ts +11 -2
  28. package/dist/agent/components/sandbox-recovery.d.ts.map +1 -1
  29. package/dist/agent/components/threads-button.d.ts +1 -1
  30. package/dist/agent/components/threads-button.d.ts.map +1 -1
  31. package/dist/agent/components/transcript.d.ts +13 -0
  32. package/dist/agent/components/transcript.d.ts.map +1 -1
  33. package/dist/agent/conversation.d.ts +7 -6
  34. package/dist/agent/conversation.d.ts.map +1 -1
  35. package/dist/agent/delegation/interpret.d.ts +5 -0
  36. package/dist/agent/delegation/interpret.d.ts.map +1 -1
  37. package/dist/agent/delegation/use-children.d.ts.map +1 -1
  38. package/dist/agent/format.d.ts +7 -0
  39. package/dist/agent/format.d.ts.map +1 -1
  40. package/dist/agent/hooks/thread-queries.d.ts +1548 -0
  41. package/dist/agent/hooks/thread-queries.d.ts.map +1 -0
  42. package/dist/agent/hooks/use-agent-conversation.d.ts +51 -6
  43. package/dist/agent/hooks/use-agent-conversation.d.ts.map +1 -1
  44. package/dist/agent/hooks/use-thread-lists.d.ts +80 -3
  45. package/dist/agent/hooks/use-thread-lists.d.ts.map +1 -1
  46. package/dist/agent/hooks/use-thread-place.d.ts +49 -0
  47. package/dist/agent/hooks/use-thread-place.d.ts.map +1 -0
  48. package/dist/agent/hooks/use-thread-stream.d.ts.map +1 -1
  49. package/dist/agent/i18n/en.d.ts +107 -6
  50. package/dist/agent/i18n/en.d.ts.map +1 -1
  51. package/dist/agent/i18n/fr.d.ts.map +1 -1
  52. package/dist/agent/i18n/index.d.ts +180 -12
  53. package/dist/agent/i18n/index.d.ts.map +1 -1
  54. package/dist/agent/inbox-handoff.d.ts +10 -0
  55. package/dist/agent/inbox-handoff.d.ts.map +1 -0
  56. package/dist/agent/live-run.d.ts +8 -1
  57. package/dist/agent/live-run.d.ts.map +1 -1
  58. package/dist/agent/model-selection.d.ts +3 -2
  59. package/dist/agent/model-selection.d.ts.map +1 -1
  60. package/dist/agent/moves.d.ts +40 -0
  61. package/dist/agent/moves.d.ts.map +1 -0
  62. package/dist/agent/search/interpret.d.ts +101 -0
  63. package/dist/agent/search/interpret.d.ts.map +1 -0
  64. package/dist/agent/search/search-tool-view.d.ts +10 -0
  65. package/dist/agent/search/search-tool-view.d.ts.map +1 -0
  66. package/dist/agent/thread-reader-state.d.ts +30 -0
  67. package/dist/agent/thread-reader-state.d.ts.map +1 -0
  68. package/dist/agent/thread-state.d.ts +26 -0
  69. package/dist/agent/thread-state.d.ts.map +1 -0
  70. package/dist/agent/tool-views/built-in.d.ts.map +1 -1
  71. package/dist/agent/tool-views/registry.d.ts +5 -6
  72. package/dist/agent/tool-views/registry.d.ts.map +1 -1
  73. package/dist/agent/types.d.ts +9 -1
  74. package/dist/agent/types.d.ts.map +1 -1
  75. package/dist/agent/view-file/view-file-tool-view.d.ts +2 -1
  76. package/dist/agent/view-file/view-file-tool-view.d.ts.map +1 -1
  77. package/dist/artifacts/card-preview.d.ts.map +1 -1
  78. package/dist/artifacts/editor/block-handle.d.ts +20 -0
  79. package/dist/artifacts/editor/block-handle.d.ts.map +1 -0
  80. package/dist/artifacts/editor/blocks.d.ts +34 -0
  81. package/dist/artifacts/editor/blocks.d.ts.map +1 -0
  82. package/dist/artifacts/editor/callout-view.d.ts +7 -0
  83. package/dist/artifacts/editor/callout-view.d.ts.map +1 -0
  84. package/dist/artifacts/editor/document-editor.d.ts +30 -0
  85. package/dist/artifacts/editor/document-editor.d.ts.map +1 -0
  86. package/dist/artifacts/editor/figure-view.d.ts +12 -0
  87. package/dist/artifacts/editor/figure-view.d.ts.map +1 -0
  88. package/dist/artifacts/editor/find-blocks.d.ts +6 -0
  89. package/dist/artifacts/editor/find-blocks.d.ts.map +1 -0
  90. package/dist/artifacts/editor/markdown-document.d.ts +12 -0
  91. package/dist/artifacts/editor/markdown-document.d.ts.map +1 -0
  92. package/dist/artifacts/editor/messages.d.ts +4 -0
  93. package/dist/artifacts/editor/messages.d.ts.map +1 -0
  94. package/dist/artifacts/editor/schema.d.ts +21 -0
  95. package/dist/artifacts/editor/schema.d.ts.map +1 -0
  96. package/dist/artifacts/editor/selection-toolbar.d.ts +35 -0
  97. package/dist/artifacts/editor/selection-toolbar.d.ts.map +1 -0
  98. package/dist/artifacts/editor/slash-menu.d.ts +43 -0
  99. package/dist/artifacts/editor/slash-menu.d.ts.map +1 -0
  100. package/dist/artifacts/editor/upload.d.ts +12 -0
  101. package/dist/artifacts/editor/upload.d.ts.map +1 -0
  102. package/dist/artifacts/file-source.d.ts +5 -0
  103. package/dist/artifacts/file-source.d.ts.map +1 -1
  104. package/dist/artifacts/frame-editor/bundle.d.ts +7 -0
  105. package/dist/artifacts/frame-editor/bundle.d.ts.map +1 -0
  106. package/dist/artifacts/frame-editor/commands.d.ts +93 -0
  107. package/dist/artifacts/frame-editor/commands.d.ts.map +1 -0
  108. package/dist/artifacts/frame-editor/entry.d.ts +2 -0
  109. package/dist/artifacts/frame-editor/entry.d.ts.map +1 -0
  110. package/dist/artifacts/frame-editor/frame.d.ts +5 -0
  111. package/dist/artifacts/frame-editor/frame.d.ts.map +1 -0
  112. package/dist/artifacts/frame-editor/keys.d.ts +8 -0
  113. package/dist/artifacts/frame-editor/keys.d.ts.map +1 -0
  114. package/dist/artifacts/frame-editor/protocol.d.ts +186 -0
  115. package/dist/artifacts/frame-editor/protocol.d.ts.map +1 -0
  116. package/dist/artifacts/frame-editor/schema.d.ts +34 -0
  117. package/dist/artifacts/frame-editor/schema.d.ts.map +1 -0
  118. package/dist/artifacts/frame-editor/style.d.ts +2 -0
  119. package/dist/artifacts/frame-editor/style.d.ts.map +1 -0
  120. package/dist/artifacts/frame.d.ts +2 -2
  121. package/dist/artifacts/frame.d.ts.map +1 -1
  122. package/dist/artifacts/live/boards.d.ts +2 -0
  123. package/dist/artifacts/live/boards.d.ts.map +1 -1
  124. package/dist/artifacts/live/document.d.ts +32 -0
  125. package/dist/artifacts/live/document.d.ts.map +1 -0
  126. package/dist/artifacts/live/header.d.ts +4 -4
  127. package/dist/artifacts/live/header.d.ts.map +1 -1
  128. package/dist/artifacts/live/presence.d.ts.map +1 -1
  129. package/dist/artifacts/live/session.d.ts +2 -0
  130. package/dist/artifacts/live/session.d.ts.map +1 -1
  131. package/dist/artifacts/live/view.d.ts +4 -3
  132. package/dist/artifacts/live/view.d.ts.map +1 -1
  133. package/dist/artifacts/messages.d.ts +226 -2
  134. package/dist/artifacts/messages.d.ts.map +1 -1
  135. package/dist/artifacts/pdf.d.ts +8 -0
  136. package/dist/artifacts/pdf.d.ts.map +1 -0
  137. package/dist/artifacts/queries.d.ts +80 -0
  138. package/dist/artifacts/queries.d.ts.map +1 -1
  139. package/dist/artifacts/references/references.d.ts +3 -3
  140. package/dist/artifacts/references/references.d.ts.map +1 -1
  141. package/dist/artifacts/renderers/canvas/board-editor.d.ts.map +1 -1
  142. package/dist/artifacts/renderers/canvas/comment-pins.d.ts +4 -2
  143. package/dist/artifacts/renderers/canvas/comment-pins.d.ts.map +1 -1
  144. package/dist/artifacts/renderers/canvas/comments-panel.d.ts.map +1 -1
  145. package/dist/artifacts/renderers/canvas/comments.d.ts +2 -1
  146. package/dist/artifacts/renderers/canvas/comments.d.ts.map +1 -1
  147. package/dist/artifacts/renderers/designed-document.d.ts +28 -0
  148. package/dist/artifacts/renderers/designed-document.d.ts.map +1 -0
  149. package/dist/artifacts/renderers/document-tree.d.ts +2 -0
  150. package/dist/artifacts/renderers/document-tree.d.ts.map +1 -1
  151. package/dist/artifacts/renderers/document.d.ts +9 -1
  152. package/dist/artifacts/renderers/document.d.ts.map +1 -1
  153. package/dist/artifacts/renderers/live-frame.d.ts +145 -0
  154. package/dist/artifacts/renderers/live-frame.d.ts.map +1 -0
  155. package/dist/artifacts/renderers/page-editor.d.ts +16 -0
  156. package/dist/artifacts/renderers/page-editor.d.ts.map +1 -0
  157. package/dist/artifacts/renderers/page.d.ts +10 -1
  158. package/dist/artifacts/renderers/page.d.ts.map +1 -1
  159. package/dist/artifacts/viewer.d.ts.map +1 -1
  160. package/dist/{chunk-pxd07kvx.js → chunk-096d52h2.js} +1 -1
  161. package/dist/{chunk-yrcm1pbg.js → chunk-94d7enwc.js} +491 -2128
  162. package/dist/chunk-94d7enwc.js.map +27 -0
  163. package/dist/{chunk-970s5nkn.js → chunk-ezntd3yy.js} +1 -1
  164. package/dist/{chunk-kymx9y5e.js → chunk-qjw5r2vk.js} +12729 -5044
  165. package/dist/chunk-qjw5r2vk.js.map +242 -0
  166. package/dist/chunk-y51c4tsz.js +11 -0
  167. package/dist/chunk-y51c4tsz.js.map +10 -0
  168. package/dist/createCustomApp.d.ts +8 -1
  169. package/dist/createCustomApp.d.ts.map +1 -1
  170. package/dist/index.d.ts +4 -2
  171. package/dist/index.d.ts.map +1 -1
  172. package/dist/index.js +13 -6
  173. package/dist/index.js.map +5 -5
  174. package/dist/pages/console/data/accounts.d.ts +94 -0
  175. package/dist/pages/console/data/accounts.d.ts.map +1 -0
  176. package/dist/pages/console/data/connectors.d.ts.map +1 -1
  177. package/dist/pages/console/data/live-updates.d.ts.map +1 -1
  178. package/dist/pages/console/data/messages.d.ts +52 -0
  179. package/dist/pages/console/data/messages.d.ts.map +1 -1
  180. package/dist/pages/console/data/shared.d.ts.map +1 -1
  181. package/dist/pages/console/data/sync-button.d.ts.map +1 -1
  182. package/dist/pages/console/data/syncs.d.ts.map +1 -1
  183. package/dist/pages/settings/usage/breakdown.d.ts.map +1 -1
  184. package/dist/pages/settings/usage/page.d.ts +4 -1
  185. package/dist/pages/settings/usage/page.d.ts.map +1 -1
  186. package/dist/pages/settings/usage/spend-model.d.ts +43 -19
  187. package/dist/pages/settings/usage/spend-model.d.ts.map +1 -1
  188. package/dist/pages.js +23044 -22570
  189. package/dist/pages.js.map +17 -16
  190. package/dist/server.d.ts +1 -1
  191. package/dist/server.d.ts.map +1 -1
  192. package/dist/server.js +40 -3
  193. package/dist/server.js.map +3 -3
  194. package/dist/shell/search-command.d.ts.map +1 -1
  195. package/package.json +22 -5
  196. package/src/agent/activity-label.ts +3 -0
  197. package/src/agent/agent-chat.tsx +58 -39
  198. package/src/agent/agent-execution-trace.tsx +2 -2
  199. package/src/agent/agent-panel.tsx +6 -4
  200. package/src/agent/agent.css +254 -0
  201. package/src/agent/artifact-panel.tsx +77 -22
  202. package/src/agent/components/agent-threads.tsx +42 -2
  203. package/src/agent/components/composer-place.tsx +2 -7
  204. package/src/agent/components/composer-settings.tsx +20 -10
  205. package/src/agent/components/composer.tsx +342 -104
  206. package/src/agent/components/computer-place.tsx +415 -70
  207. package/src/agent/components/context-meter.tsx +7 -3
  208. package/src/agent/components/conversation-panel.tsx +99 -54
  209. package/src/agent/components/message-parts.tsx +367 -59
  210. package/src/agent/components/message-view.tsx +428 -9
  211. package/src/agent/components/pending-messages.tsx +342 -0
  212. package/src/agent/components/sandbox-recovery.tsx +36 -17
  213. package/src/agent/components/threads-button.tsx +3 -2
  214. package/src/agent/components/transcript.tsx +198 -38
  215. package/src/agent/conversation.ts +219 -55
  216. package/src/agent/delegation/interpret.ts +31 -7
  217. package/src/agent/format.ts +52 -0
  218. package/src/agent/hooks/thread-queries.ts +75 -0
  219. package/src/agent/hooks/use-agent-conversation.ts +801 -211
  220. package/src/agent/hooks/use-thread-lists.ts +72 -7
  221. package/src/agent/hooks/use-thread-place.ts +239 -0
  222. package/src/agent/hooks/use-thread-stream.ts +10 -0
  223. package/src/agent/i18n/en.ts +150 -27
  224. package/src/agent/i18n/fr.ts +148 -31
  225. package/src/agent/inbox-handoff.ts +47 -0
  226. package/src/agent/live-run.ts +61 -2
  227. package/src/agent/model-selection.ts +3 -2
  228. package/src/agent/moves.ts +174 -0
  229. package/src/agent/react-router.tsx +2 -2
  230. package/src/agent/search/interpret.ts +367 -0
  231. package/src/agent/search/search-tool-view.tsx +235 -0
  232. package/src/agent/thread-reader-state.ts +75 -0
  233. package/src/agent/thread-state.ts +114 -0
  234. package/src/agent/tool-views/built-in.tsx +16 -0
  235. package/src/agent/tool-views/registry.tsx +28 -2
  236. package/src/agent/types.ts +13 -0
  237. package/src/agent/view-file/view-file-tool-view.tsx +33 -19
  238. package/src/artifacts/artifacts.css +398 -0
  239. package/src/artifacts/card-preview.tsx +6 -1
  240. package/src/artifacts/editor/block-handle.tsx +278 -0
  241. package/src/artifacts/editor/blocks.ts +216 -0
  242. package/src/artifacts/editor/callout-view.tsx +31 -0
  243. package/src/artifacts/editor/document-editor.tsx +484 -0
  244. package/src/artifacts/editor/figure-view.tsx +66 -0
  245. package/src/artifacts/editor/find-blocks.ts +19 -0
  246. package/src/artifacts/editor/markdown-document.tsx +72 -0
  247. package/src/artifacts/editor/messages.ts +4 -0
  248. package/src/artifacts/editor/schema.ts +159 -0
  249. package/src/artifacts/editor/selection-toolbar.tsx +364 -0
  250. package/src/artifacts/editor/slash-menu.tsx +251 -0
  251. package/src/artifacts/editor/upload.ts +40 -0
  252. package/src/artifacts/file-source.ts +11 -0
  253. package/src/artifacts/frame-editor/bundle.ts +8 -0
  254. package/src/artifacts/frame-editor/commands.ts +565 -0
  255. package/src/artifacts/frame-editor/entry.ts +6 -0
  256. package/src/artifacts/frame-editor/frame.ts +847 -0
  257. package/src/artifacts/frame-editor/generated/editor.txt +149 -0
  258. package/src/artifacts/frame-editor/generated.d.ts +5 -0
  259. package/src/artifacts/frame-editor/keys.ts +323 -0
  260. package/src/artifacts/frame-editor/protocol.ts +151 -0
  261. package/src/artifacts/frame-editor/schema.ts +293 -0
  262. package/src/artifacts/frame-editor/style.ts +58 -0
  263. package/src/artifacts/frame.tsx +11 -3
  264. package/src/artifacts/live/boards.ts +46 -3
  265. package/src/artifacts/live/document.ts +89 -0
  266. package/src/artifacts/live/header.tsx +9 -14
  267. package/src/artifacts/live/presence.ts +5 -1
  268. package/src/artifacts/live/session.ts +9 -2
  269. package/src/artifacts/live/view.ts +14 -8
  270. package/src/artifacts/messages.ts +138 -2
  271. package/src/artifacts/pdf.ts +50 -0
  272. package/src/artifacts/references/references.tsx +46 -11
  273. package/src/artifacts/renderers/canvas/board-editor.tsx +11 -144
  274. package/src/artifacts/renderers/canvas/comment-pins.tsx +5 -0
  275. package/src/artifacts/renderers/canvas/comments-panel.tsx +58 -1
  276. package/src/artifacts/renderers/canvas/comments.ts +8 -4
  277. package/src/artifacts/renderers/designed-document.tsx +277 -0
  278. package/src/artifacts/renderers/document-tree.ts +9 -0
  279. package/src/artifacts/renderers/document.tsx +13 -102
  280. package/src/artifacts/renderers/live-frame.ts +163 -0
  281. package/src/artifacts/renderers/page-editor.tsx +613 -0
  282. package/src/artifacts/renderers/page.tsx +21 -4
  283. package/src/artifacts/viewer.tsx +87 -41
  284. package/src/createCustomApp.ts +57 -3
  285. package/src/index.ts +10 -0
  286. package/src/pages/console/data/accounts.tsx +509 -0
  287. package/src/pages/console/data/connectors.tsx +7 -15
  288. package/src/pages/console/data/live-updates.ts +2 -0
  289. package/src/pages/console/data/messages.ts +79 -0
  290. package/src/pages/console/data/projections.tsx +4 -0
  291. package/src/pages/console/data/shared.tsx +1 -0
  292. package/src/pages/console/data/sync-button.tsx +56 -16
  293. package/src/pages/console/data/syncs.tsx +66 -41
  294. package/src/pages/console/ontology/lineage/trail.tsx +3 -0
  295. package/src/pages/section-ui.tsx +1 -1
  296. package/src/pages/settings/usage/breakdown.tsx +5 -2
  297. package/src/pages/settings/usage/filter-menu.tsx +1 -1
  298. package/src/pages/settings/usage/page.tsx +32 -13
  299. package/src/pages/settings/usage/spend-chart.tsx +2 -2
  300. package/src/pages/settings/usage/spend-model.ts +118 -50
  301. package/src/server.ts +1 -0
  302. package/src/shell/search-command.tsx +2 -0
  303. package/dist/chunk-kymx9y5e.js.map +0 -211
  304. package/dist/chunk-yrcm1pbg.js.map +0 -34
  305. /package/dist/{chunk-pxd07kvx.js.map → chunk-096d52h2.js.map} +0 -0
  306. /package/dist/{chunk-970s5nkn.js.map → chunk-ezntd3yy.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 { AgentFileRef, LanguageModel } from "../types"
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 start an empty input, the reader's own kept. Nothing
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 [value, setValue] = useState("")
256
- const [attachments, setAttachments] = useState<ComposerAttachment[]>([])
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
- ambientContext.map((context) => ({ context, origin: "ambient" }))
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
- // The text's width in a single row, measured while it has one.
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 = attachments.flatMap((attachment) =>
322
- attachment.status === "ready" ? [attachment.fileRef] : []
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(allCommands(), commandText).slice(0, 6)
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 in an empty input, the
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.trim() ? current : text))
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
- // A draft that no longer fits in one row beside the controls takes a row of its own, with the
446
- // controls under it. The row's width is measured while the draft still has it, so the box only
447
- // folds back once the text fits there again.
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
- if (!expanded) inlineWidthRef.current = el.clientWidth
461
- const sizer = sizerRef.current
462
- setWraps(
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, [value, attachments.length, contextEntries.length, expanded])
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 row's width changes without the text changing: the model label settles after the first
476
- // render, or the window resizes. A height measured at the old width would keep a wrapped
477
- // placeholder's two lines.
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
- let width = el.clientWidth
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
- if (el.clientWidth === width) return
486
- width = el.clientWidth
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
- uploadFile
540
- .mutateAsync({ file, fileName: file.name })
541
- .then((fileRef) => {
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
- setAttachments((current) =>
553
- current.map((attachment) =>
554
- attachment.id === id
555
- ? {
556
- id,
557
- status: "error",
558
- fileName: file.name,
559
- mediaType: file.type || undefined,
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 draft fits beside the controls; once it doesn't, the draft gets a row
913
- of its own and the controls sit under it. Attachments and context lead, on their own row.
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
- {/* The draft on one line, to tell when it stops fitting there. */}
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
- className="absolute whitespace-pre px-2 text-[16px] tracking-[-0.012em]"
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 && allCommands().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
- {running && onStop ? (
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
+ }