@sixb/app 0.2.4 → 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.
Files changed (247) 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/composer-settings.d.ts +1 -1
  10. package/dist/agent/components/composer-settings.d.ts.map +1 -1
  11. package/dist/agent/components/composer.d.ts +22 -5
  12. package/dist/agent/components/composer.d.ts.map +1 -1
  13. package/dist/agent/components/context-meter.d.ts +1 -1
  14. package/dist/agent/components/context-meter.d.ts.map +1 -1
  15. package/dist/agent/components/conversation-panel.d.ts +5 -2
  16. package/dist/agent/components/conversation-panel.d.ts.map +1 -1
  17. package/dist/agent/components/message-parts.d.ts +2 -1
  18. package/dist/agent/components/message-parts.d.ts.map +1 -1
  19. package/dist/agent/components/message-view.d.ts.map +1 -1
  20. package/dist/agent/components/pending-messages.d.ts +20 -0
  21. package/dist/agent/components/pending-messages.d.ts.map +1 -0
  22. package/dist/agent/components/sandbox-recovery.d.ts +11 -2
  23. package/dist/agent/components/sandbox-recovery.d.ts.map +1 -1
  24. package/dist/agent/components/threads-button.d.ts +1 -1
  25. package/dist/agent/components/threads-button.d.ts.map +1 -1
  26. package/dist/agent/components/transcript.d.ts.map +1 -1
  27. package/dist/agent/conversation.d.ts +3 -6
  28. package/dist/agent/conversation.d.ts.map +1 -1
  29. package/dist/agent/delegation/interpret.d.ts +5 -0
  30. package/dist/agent/delegation/interpret.d.ts.map +1 -1
  31. package/dist/agent/delegation/use-children.d.ts.map +1 -1
  32. package/dist/agent/hooks/use-agent-conversation.d.ts +10 -4
  33. package/dist/agent/hooks/use-agent-conversation.d.ts.map +1 -1
  34. package/dist/agent/hooks/use-thread-lists.d.ts.map +1 -1
  35. package/dist/agent/hooks/use-thread-stream.d.ts.map +1 -1
  36. package/dist/agent/i18n/en.d.ts +68 -0
  37. package/dist/agent/i18n/en.d.ts.map +1 -1
  38. package/dist/agent/i18n/fr.d.ts.map +1 -1
  39. package/dist/agent/i18n/index.d.ts +114 -0
  40. package/dist/agent/i18n/index.d.ts.map +1 -1
  41. package/dist/agent/inbox-handoff.d.ts +10 -0
  42. package/dist/agent/inbox-handoff.d.ts.map +1 -0
  43. package/dist/agent/live-run.d.ts +8 -1
  44. package/dist/agent/live-run.d.ts.map +1 -1
  45. package/dist/agent/search/interpret.d.ts +101 -0
  46. package/dist/agent/search/interpret.d.ts.map +1 -0
  47. package/dist/agent/search/search-tool-view.d.ts +10 -0
  48. package/dist/agent/search/search-tool-view.d.ts.map +1 -0
  49. package/dist/agent/thread-state.d.ts +26 -0
  50. package/dist/agent/thread-state.d.ts.map +1 -0
  51. package/dist/agent/tool-views/built-in.d.ts.map +1 -1
  52. package/dist/agent/tool-views/registry.d.ts +5 -6
  53. package/dist/agent/tool-views/registry.d.ts.map +1 -1
  54. package/dist/agent/types.d.ts +5 -1
  55. package/dist/agent/types.d.ts.map +1 -1
  56. package/dist/agent/view-file/view-file-tool-view.d.ts +2 -1
  57. package/dist/agent/view-file/view-file-tool-view.d.ts.map +1 -1
  58. package/dist/artifacts/card-preview.d.ts.map +1 -1
  59. package/dist/artifacts/editor/block-handle.d.ts +20 -0
  60. package/dist/artifacts/editor/block-handle.d.ts.map +1 -0
  61. package/dist/artifacts/editor/blocks.d.ts +34 -0
  62. package/dist/artifacts/editor/blocks.d.ts.map +1 -0
  63. package/dist/artifacts/editor/callout-view.d.ts +7 -0
  64. package/dist/artifacts/editor/callout-view.d.ts.map +1 -0
  65. package/dist/artifacts/editor/document-editor.d.ts +30 -0
  66. package/dist/artifacts/editor/document-editor.d.ts.map +1 -0
  67. package/dist/artifacts/editor/figure-view.d.ts +12 -0
  68. package/dist/artifacts/editor/figure-view.d.ts.map +1 -0
  69. package/dist/artifacts/editor/find-blocks.d.ts +6 -0
  70. package/dist/artifacts/editor/find-blocks.d.ts.map +1 -0
  71. package/dist/artifacts/editor/markdown-document.d.ts +12 -0
  72. package/dist/artifacts/editor/markdown-document.d.ts.map +1 -0
  73. package/dist/artifacts/editor/messages.d.ts +4 -0
  74. package/dist/artifacts/editor/messages.d.ts.map +1 -0
  75. package/dist/artifacts/editor/schema.d.ts +21 -0
  76. package/dist/artifacts/editor/schema.d.ts.map +1 -0
  77. package/dist/artifacts/editor/selection-toolbar.d.ts +35 -0
  78. package/dist/artifacts/editor/selection-toolbar.d.ts.map +1 -0
  79. package/dist/artifacts/editor/slash-menu.d.ts +43 -0
  80. package/dist/artifacts/editor/slash-menu.d.ts.map +1 -0
  81. package/dist/artifacts/editor/upload.d.ts +12 -0
  82. package/dist/artifacts/editor/upload.d.ts.map +1 -0
  83. package/dist/artifacts/file-source.d.ts +5 -0
  84. package/dist/artifacts/file-source.d.ts.map +1 -1
  85. package/dist/artifacts/frame-editor/bundle.d.ts +7 -0
  86. package/dist/artifacts/frame-editor/bundle.d.ts.map +1 -0
  87. package/dist/artifacts/frame-editor/commands.d.ts +93 -0
  88. package/dist/artifacts/frame-editor/commands.d.ts.map +1 -0
  89. package/dist/artifacts/frame-editor/entry.d.ts +2 -0
  90. package/dist/artifacts/frame-editor/entry.d.ts.map +1 -0
  91. package/dist/artifacts/frame-editor/frame.d.ts +5 -0
  92. package/dist/artifacts/frame-editor/frame.d.ts.map +1 -0
  93. package/dist/artifacts/frame-editor/keys.d.ts +8 -0
  94. package/dist/artifacts/frame-editor/keys.d.ts.map +1 -0
  95. package/dist/artifacts/frame-editor/protocol.d.ts +186 -0
  96. package/dist/artifacts/frame-editor/protocol.d.ts.map +1 -0
  97. package/dist/artifacts/frame-editor/schema.d.ts +34 -0
  98. package/dist/artifacts/frame-editor/schema.d.ts.map +1 -0
  99. package/dist/artifacts/frame-editor/style.d.ts +2 -0
  100. package/dist/artifacts/frame-editor/style.d.ts.map +1 -0
  101. package/dist/artifacts/frame.d.ts +2 -2
  102. package/dist/artifacts/frame.d.ts.map +1 -1
  103. package/dist/artifacts/live/boards.d.ts +2 -0
  104. package/dist/artifacts/live/boards.d.ts.map +1 -1
  105. package/dist/artifacts/live/document.d.ts +32 -0
  106. package/dist/artifacts/live/document.d.ts.map +1 -0
  107. package/dist/artifacts/live/header.d.ts +4 -4
  108. package/dist/artifacts/live/header.d.ts.map +1 -1
  109. package/dist/artifacts/live/presence.d.ts.map +1 -1
  110. package/dist/artifacts/live/session.d.ts +2 -0
  111. package/dist/artifacts/live/session.d.ts.map +1 -1
  112. package/dist/artifacts/live/view.d.ts +4 -3
  113. package/dist/artifacts/live/view.d.ts.map +1 -1
  114. package/dist/artifacts/messages.d.ts +226 -2
  115. package/dist/artifacts/messages.d.ts.map +1 -1
  116. package/dist/artifacts/pdf.d.ts +8 -0
  117. package/dist/artifacts/pdf.d.ts.map +1 -0
  118. package/dist/artifacts/queries.d.ts +80 -0
  119. package/dist/artifacts/queries.d.ts.map +1 -1
  120. package/dist/artifacts/references/references.d.ts +3 -3
  121. package/dist/artifacts/references/references.d.ts.map +1 -1
  122. package/dist/artifacts/renderers/canvas/board-editor.d.ts.map +1 -1
  123. package/dist/artifacts/renderers/canvas/comment-pins.d.ts +4 -2
  124. package/dist/artifacts/renderers/canvas/comment-pins.d.ts.map +1 -1
  125. package/dist/artifacts/renderers/canvas/comments-panel.d.ts.map +1 -1
  126. package/dist/artifacts/renderers/canvas/comments.d.ts +2 -1
  127. package/dist/artifacts/renderers/canvas/comments.d.ts.map +1 -1
  128. package/dist/artifacts/renderers/designed-document.d.ts +28 -0
  129. package/dist/artifacts/renderers/designed-document.d.ts.map +1 -0
  130. package/dist/artifacts/renderers/document-tree.d.ts +2 -0
  131. package/dist/artifacts/renderers/document-tree.d.ts.map +1 -1
  132. package/dist/artifacts/renderers/document.d.ts +9 -1
  133. package/dist/artifacts/renderers/document.d.ts.map +1 -1
  134. package/dist/artifacts/renderers/live-frame.d.ts +145 -0
  135. package/dist/artifacts/renderers/live-frame.d.ts.map +1 -0
  136. package/dist/artifacts/renderers/page-editor.d.ts +16 -0
  137. package/dist/artifacts/renderers/page-editor.d.ts.map +1 -0
  138. package/dist/artifacts/renderers/page.d.ts +10 -1
  139. package/dist/artifacts/renderers/page.d.ts.map +1 -1
  140. package/dist/artifacts/viewer.d.ts.map +1 -1
  141. package/dist/{chunk-kymx9y5e.js → chunk-4fex83k2.js} +10874 -4690
  142. package/dist/chunk-4fex83k2.js.map +239 -0
  143. package/dist/{chunk-yrcm1pbg.js → chunk-4wm09prf.js} +491 -2128
  144. package/dist/chunk-4wm09prf.js.map +27 -0
  145. package/dist/{chunk-pxd07kvx.js → chunk-5sgac68y.js} +1 -1
  146. package/dist/{chunk-970s5nkn.js → chunk-69qgh20f.js} +1 -1
  147. package/dist/chunk-y51c4tsz.js +11 -0
  148. package/dist/chunk-y51c4tsz.js.map +10 -0
  149. package/dist/index.d.ts +2 -1
  150. package/dist/index.d.ts.map +1 -1
  151. package/dist/index.js +11 -6
  152. package/dist/index.js.map +5 -5
  153. package/dist/pages/console/data/messages.d.ts +6 -0
  154. package/dist/pages/console/data/messages.d.ts.map +1 -1
  155. package/dist/pages/console/data/shared.d.ts.map +1 -1
  156. package/dist/pages.js +12 -5
  157. package/dist/pages.js.map +6 -6
  158. package/dist/shell/search-command.d.ts.map +1 -1
  159. package/package.json +22 -5
  160. package/src/agent/activity-label.ts +3 -0
  161. package/src/agent/agent-chat.tsx +56 -37
  162. package/src/agent/agent-execution-trace.tsx +2 -2
  163. package/src/agent/agent-panel.tsx +6 -4
  164. package/src/agent/agent.css +254 -0
  165. package/src/agent/artifact-panel.tsx +77 -22
  166. package/src/agent/components/composer-settings.tsx +20 -10
  167. package/src/agent/components/composer.tsx +342 -104
  168. package/src/agent/components/context-meter.tsx +7 -3
  169. package/src/agent/components/conversation-panel.tsx +69 -29
  170. package/src/agent/components/message-parts.tsx +367 -59
  171. package/src/agent/components/message-view.tsx +12 -2
  172. package/src/agent/components/pending-messages.tsx +338 -0
  173. package/src/agent/components/sandbox-recovery.tsx +36 -17
  174. package/src/agent/components/threads-button.tsx +3 -2
  175. package/src/agent/components/transcript.tsx +63 -34
  176. package/src/agent/conversation.ts +203 -54
  177. package/src/agent/delegation/interpret.ts +31 -7
  178. package/src/agent/hooks/use-agent-conversation.ts +348 -100
  179. package/src/agent/hooks/use-thread-stream.ts +10 -0
  180. package/src/agent/i18n/en.ts +87 -11
  181. package/src/agent/i18n/fr.ts +83 -12
  182. package/src/agent/inbox-handoff.ts +47 -0
  183. package/src/agent/live-run.ts +23 -2
  184. package/src/agent/react-router.tsx +2 -2
  185. package/src/agent/search/interpret.ts +367 -0
  186. package/src/agent/search/search-tool-view.tsx +235 -0
  187. package/src/agent/thread-state.ts +114 -0
  188. package/src/agent/tool-views/built-in.tsx +16 -0
  189. package/src/agent/tool-views/registry.tsx +28 -2
  190. package/src/agent/types.ts +7 -0
  191. package/src/agent/view-file/view-file-tool-view.tsx +33 -19
  192. package/src/artifacts/artifacts.css +398 -0
  193. package/src/artifacts/card-preview.tsx +6 -1
  194. package/src/artifacts/editor/block-handle.tsx +278 -0
  195. package/src/artifacts/editor/blocks.ts +216 -0
  196. package/src/artifacts/editor/callout-view.tsx +31 -0
  197. package/src/artifacts/editor/document-editor.tsx +484 -0
  198. package/src/artifacts/editor/figure-view.tsx +66 -0
  199. package/src/artifacts/editor/find-blocks.ts +19 -0
  200. package/src/artifacts/editor/markdown-document.tsx +72 -0
  201. package/src/artifacts/editor/messages.ts +4 -0
  202. package/src/artifacts/editor/schema.ts +159 -0
  203. package/src/artifacts/editor/selection-toolbar.tsx +364 -0
  204. package/src/artifacts/editor/slash-menu.tsx +251 -0
  205. package/src/artifacts/editor/upload.ts +40 -0
  206. package/src/artifacts/file-source.ts +11 -0
  207. package/src/artifacts/frame-editor/bundle.ts +8 -0
  208. package/src/artifacts/frame-editor/commands.ts +565 -0
  209. package/src/artifacts/frame-editor/entry.ts +6 -0
  210. package/src/artifacts/frame-editor/frame.ts +847 -0
  211. package/src/artifacts/frame-editor/generated/editor.txt +149 -0
  212. package/src/artifacts/frame-editor/generated.d.ts +5 -0
  213. package/src/artifacts/frame-editor/keys.ts +323 -0
  214. package/src/artifacts/frame-editor/protocol.ts +151 -0
  215. package/src/artifacts/frame-editor/schema.ts +293 -0
  216. package/src/artifacts/frame-editor/style.ts +58 -0
  217. package/src/artifacts/frame.tsx +11 -3
  218. package/src/artifacts/live/boards.ts +46 -3
  219. package/src/artifacts/live/document.ts +89 -0
  220. package/src/artifacts/live/header.tsx +9 -14
  221. package/src/artifacts/live/presence.ts +5 -1
  222. package/src/artifacts/live/session.ts +4 -2
  223. package/src/artifacts/live/view.ts +14 -8
  224. package/src/artifacts/messages.ts +138 -2
  225. package/src/artifacts/pdf.ts +50 -0
  226. package/src/artifacts/references/references.tsx +46 -11
  227. package/src/artifacts/renderers/canvas/board-editor.tsx +11 -144
  228. package/src/artifacts/renderers/canvas/comment-pins.tsx +5 -0
  229. package/src/artifacts/renderers/canvas/comments-panel.tsx +58 -1
  230. package/src/artifacts/renderers/canvas/comments.ts +8 -4
  231. package/src/artifacts/renderers/designed-document.tsx +277 -0
  232. package/src/artifacts/renderers/document-tree.ts +9 -0
  233. package/src/artifacts/renderers/document.tsx +13 -102
  234. package/src/artifacts/renderers/live-frame.ts +163 -0
  235. package/src/artifacts/renderers/page-editor.tsx +613 -0
  236. package/src/artifacts/renderers/page.tsx +21 -4
  237. package/src/artifacts/viewer.tsx +87 -41
  238. package/src/index.ts +6 -0
  239. package/src/pages/console/data/messages.ts +6 -0
  240. package/src/pages/console/data/projections.tsx +4 -0
  241. package/src/pages/console/data/shared.tsx +1 -0
  242. package/src/pages/console/ontology/lineage/trail.tsx +3 -0
  243. package/src/shell/search-command.tsx +2 -0
  244. package/dist/chunk-kymx9y5e.js.map +0 -211
  245. package/dist/chunk-yrcm1pbg.js.map +0 -34
  246. /package/dist/{chunk-pxd07kvx.js.map → chunk-5sgac68y.js.map} +0 -0
  247. /package/dist/{chunk-970s5nkn.js.map → chunk-69qgh20f.js.map} +0 -0
@@ -14,6 +14,7 @@ import {
14
14
  listAgentComputersQueryKey,
15
15
  listAgentThreadApprovalsOptions,
16
16
  listAgentThreadApprovalsQueryKey,
17
+ listAgentThreadInboxQueryKey,
17
18
  listAgentThreadMessagesOptions,
18
19
  listAgentThreadMessagesQueryKey,
19
20
  listAgentThreadRunsOptions,
@@ -23,6 +24,7 @@ import {
23
24
  moveAgentThreadToCloudMutation,
24
25
  postAgentThreadMessageMutation,
25
26
  recreateAgentThreadSandboxMutation,
27
+ restoreAgentThreadSandboxMutation,
26
28
  retryAgentRunMutation,
27
29
  setAgentThreadApprovalModeMutation,
28
30
  stopAgentBackgroundCommandMutation,
@@ -32,7 +34,7 @@ import {
32
34
  } from "@sixb/client/hooks"
33
35
  import { MODEL_REASONING_LEVELS, type ModelReasoningLevel } from "@sixb/core/models"
34
36
  import { useMutation, useQuery, useQueryClient } from "@tanstack/react-query"
35
- import { useEffect, useMemo, useRef, useState } from "react"
37
+ import { useCallback, useEffect, useMemo, useRef, useState } from "react"
36
38
  import { useCurrentUser } from "../../session"
37
39
  import {
38
40
  type AgentApproval,
@@ -48,9 +50,15 @@ import {
48
50
  import type { TranscriptBackground } from "../background/context"
49
51
  import type { ComposerProps } from "../components/composer"
50
52
  import { type ComputerOfflineNoticeProps, shownFolder } from "../components/computer-place"
53
+ import type { PendingMessagesProps } from "../components/pending-messages"
51
54
  import type { SandboxRecoveryProps } from "../components/sandbox-recovery"
52
55
  import type { TranscriptProps } from "../components/transcript"
53
- import { conversationMessages, conversationTurn, type PendingUserMessage } from "../conversation"
56
+ import {
57
+ type AgentConversationTurn,
58
+ conversationMessages,
59
+ conversationTurn,
60
+ type PendingUserMessage,
61
+ } from "../conversation"
54
62
  import type { TranscriptDelegation } from "../delegation/context"
55
63
  import { projectDictation } from "../dictation"
56
64
  import { useAgentMessages } from "../i18n"
@@ -89,6 +97,7 @@ import {
89
97
  import type {
90
98
  AgentContextEntryInput,
91
99
  AgentFileRef,
100
+ AgentMessageDelivery,
92
101
  AgentRun,
93
102
  AgentThreadSandboxParams,
94
103
  LanguageModel,
@@ -144,6 +153,7 @@ export type ConversationComposerProps = Pick<
144
153
  | "disabled"
145
154
  | "pending"
146
155
  | "running"
156
+ | "steerable"
147
157
  | "stopping"
148
158
  | "onStop"
149
159
  | "hint"
@@ -158,10 +168,12 @@ export type ConversationComposerProps = Pick<
158
168
  | "usingDefaultModel"
159
169
  | "onResetModelSelection"
160
170
  | "modelRouting"
171
+ | "draftKey"
161
172
  | "draft"
162
173
  | "draftAttachments"
163
174
  | "draftContext"
164
175
  | "draftNonce"
176
+ | "draftReseedKey"
165
177
  | "insertion"
166
178
  | "onInserted"
167
179
  | "approvalMode"
@@ -388,7 +400,9 @@ export function useAgentConversation({
388
400
  attachments: readonly AgentFileRef[]
389
401
  context: readonly AgentContextEntryInput[]
390
402
  nonce: number
391
- }>({ text: "", attachments: [], context: [], nonce: 0 })
403
+ /** The conversation the message was for, whichever one is open when it comes back. */
404
+ draftKey: string
405
+ }>({ text: "", attachments: [], context: [], nonce: 0, draftKey: "draft" })
392
406
  const [stoppingRunId, setStoppingRunId] = useState<string | null>(null)
393
407
  const stopRef = useRef<(approval: AgentApproval) => Promise<void>>(async () => {})
394
408
  const decideRef = useRef<NonNullable<TranscriptApprovals["decide"]>>(async () => {
@@ -402,6 +416,8 @@ export function useAgentConversation({
402
416
  } | null>(null)
403
417
  /** The thread whose answer Continue is asking for, until the API accepts or refuses it. */
404
418
  const [continuingThreadId, setContinuingThreadId] = useState<string | null>(null)
419
+ /** The thread whose sandbox its owner just resumed, until its cut-short turn runs again. */
420
+ const [resumedThreadId, setResumedThreadId] = useState<string | null>(null)
405
421
 
406
422
  const pendingRun =
407
423
  pendingSend && threadId !== null && pendingSend.run.threadId === threadId
@@ -412,6 +428,11 @@ export function useAgentConversation({
412
428
  ? selectActiveRunId({ pendingRun, threadActiveRunId: thread?.activeRunId ?? null, latestRun })
413
429
  : null
414
430
  const { live, run: streamRun, reconnecting } = useThreadStream({ threadId, runId: activeRunId })
431
+ // What the turn read as it answered leaves the tray: the transcript shows it where it was read.
432
+ const readMessageIds = useMemo(
433
+ () => new Set(live.inboxReads.flatMap((read) => read.messages.map((message) => message.id))),
434
+ [live.inboxReads]
435
+ )
415
436
  // A compaction that ended changed what the conversation weighs: measure it again.
416
437
  const wasCompactingRef = useRef(false)
417
438
  useEffect(() => {
@@ -470,6 +491,7 @@ export function useAgentConversation({
470
491
  const cancelRun = useMutation(cancelAgentRunMutation())
471
492
  const retryRun = useMutation(retryAgentRunMutation())
472
493
  const recreateSandbox = useMutation(recreateAgentThreadSandboxMutation())
494
+ const restoreSandbox = useMutation(restoreAgentThreadSandboxMutation())
473
495
  const moveToCloud = useMutation(moveAgentThreadToCloudMutation())
474
496
  const stopBackgroundCommand = useMutation(stopAgentBackgroundCommandMutation())
475
497
  const decideApproval = useMutation(decideAgentApprovalMutation())
@@ -536,38 +558,58 @@ export function useAgentConversation({
536
558
  const send = async (
537
559
  text: string,
538
560
  attachments: readonly AgentFileRef[],
539
- context: readonly AgentContextEntryInput[]
561
+ context: readonly AgentContextEntryInput[],
562
+ delivery: AgentMessageDelivery = "auto"
540
563
  ) => {
541
- if (isRunning) return
564
+ // A running turn takes the message as a steer, a queued turn, or one that stops it. A chat that
565
+ // does not say where it goes sends it where Enter would: into the reader's own answer, or after
566
+ // the answer in flight when it is someone else's or carries a file, which no step reads.
567
+ // The thread that a message starts is always a turn, whatever the composer said.
568
+ const where: AgentMessageDelivery =
569
+ isRunning && delivery === "auto"
570
+ ? attachments.length === 0 && !requestedBySomeoneElse(activeRun, user)
571
+ ? "steer"
572
+ : "queue"
573
+ : delivery
542
574
  setSendError(null)
543
575
  const targetThreadId = threadId
544
576
  const key = `sent:${++sentMessageCount}`
545
577
  let createdThreadId: string | null = null
546
578
  try {
547
579
  if (targetThreadId !== null) {
548
- setPendingUser({
549
- key,
550
- threadId: targetThreadId,
551
- text,
552
- attachments,
553
- context,
554
- messageId: null,
555
- })
580
+ // A message for the running turn waits in the inbox, which the tray shows: only one that
581
+ // starts a turn is the transcript's next message.
582
+ if (where === "auto") {
583
+ setPendingUser({
584
+ key,
585
+ threadId: targetThreadId,
586
+ text,
587
+ attachments,
588
+ context,
589
+ messageId: null,
590
+ })
591
+ }
556
592
  const response = await sendWithRequesterSettings((settings) =>
557
593
  postMessage.mutateAsync({
558
594
  path: { threadId: targetThreadId },
559
595
  body: {
560
596
  ...messageBody(text, attachments, context, modelSelection.request, settings),
561
597
  ...turnApprovalMode,
598
+ ...(where === "auto" ? {} : { delivery: where }),
562
599
  },
563
600
  })
564
601
  )
565
- recordAcceptedSend(response.run, key)
602
+ if (response.run) recordAcceptedSend(response.run, key)
566
603
  await Promise.all([
567
604
  queryClient.invalidateQueries({
568
605
  queryKey: listAgentThreadMessagesQueryKey({ path: { threadId: targetThreadId } }),
569
606
  }),
570
607
  queryClient.invalidateQueries({ queryKey: listAgentThreadsQueryKey() }),
608
+ // A message that waits beside the running turn is in the thread's inbox, not its
609
+ // transcript: the tray reads it from there.
610
+ queryClient.invalidateQueries({
611
+ queryKey: listAgentThreadInboxQueryKey({ path: { threadId: targetThreadId } }),
612
+ }),
571
613
  ])
572
614
  return
573
615
  }
@@ -582,7 +624,13 @@ export function useAgentConversation({
582
624
  }
583
625
  if (!place) {
584
626
  // They cancelled choosing a folder: nothing was sent, and their message goes back.
585
- setDraftReseed((current) => ({ text, attachments, context, nonce: current.nonce + 1 }))
627
+ setDraftReseed((current) => ({
628
+ text,
629
+ attachments,
630
+ context,
631
+ nonce: current.nonce + 1,
632
+ draftKey: "draft",
633
+ }))
586
634
  return
587
635
  }
588
636
  const title = deriveTitle(text, attachments)
@@ -614,7 +662,7 @@ export function useAgentConversation({
614
662
  },
615
663
  })
616
664
  )
617
- recordAcceptedSend(response.run, key)
665
+ if (response.run) recordAcceptedSend(response.run, key)
618
666
  // The next new conversation starts from the default again.
619
667
  setChosenApprovalMode((current) => (current?.threadId === null ? null : current))
620
668
  await queryClient.invalidateQueries({ queryKey: listAgentThreadsQueryKey() })
@@ -628,6 +676,7 @@ export function useAgentConversation({
628
676
  attachments,
629
677
  context,
630
678
  nonce: current.nonce + 1,
679
+ draftKey: createdThreadId ?? targetThreadId ?? "draft",
631
680
  }))
632
681
  setSendError({
633
682
  threadId: createdThreadId ?? targetThreadId,
@@ -702,6 +751,10 @@ export function useAgentConversation({
702
751
  queryClient.invalidateQueries({
703
752
  queryKey: getAgentThreadContextQueryKey({ path: { threadId } }),
704
753
  }),
754
+ // A turn that ended read its steers, or started what was queued behind it.
755
+ queryClient.invalidateQueries({
756
+ queryKey: listAgentThreadInboxQueryKey({ path: { threadId } }),
757
+ }),
705
758
  ])
706
759
 
707
760
  const keepThreadApprovalMode = async (threadId: string, mode: AgentApprovalMode) => {
@@ -807,8 +860,10 @@ export function useAgentConversation({
807
860
  postMessage.mutateAsync({ path: { threadId }, body: { continue: true, ...settings } })
808
861
  )
809
862
  setContinuingThreadId(null)
810
- watchRun(response.run)
811
- setPendingSend({ run: response.run, anchor: true })
863
+ if (response.run) {
864
+ watchRun(response.run)
865
+ setPendingSend({ run: response.run, anchor: true })
866
+ }
812
867
  await refreshThread(threadId)
813
868
  } catch (error) {
814
869
  setContinuingThreadId(null)
@@ -833,15 +888,18 @@ export function useAgentConversation({
833
888
  )
834
889
  }
835
890
 
836
- const handleRecreateSandbox = () => {
891
+ /** Recover the thread's sandbox as its owner chose: fresh, or as the failed save left it. */
892
+ const recoverSandbox = (recovery: typeof recreateSandbox | typeof restoreSandbox) => {
837
893
  if (!thread?.sandboxState || isRunning || access !== "owner") return
838
- recreateSandbox.mutate(
894
+ recovery.mutate(
839
895
  {
840
896
  path: { threadId: thread.id },
841
897
  body: { expectedSandboxName: thread.sandboxState.name },
842
898
  },
843
899
  {
844
900
  onSuccess: () => {
901
+ if (recovery === restoreSandbox) setResumedThreadId(thread.id)
902
+
845
903
  void queryClient.invalidateQueries({
846
904
  queryKey: getAgentThreadQueryKey({ path: { threadId: thread.id } }),
847
905
  })
@@ -950,6 +1008,22 @@ export function useAgentConversation({
950
1008
  latestRun,
951
1009
  })
952
1010
 
1011
+ // Resuming the sandbox picks the cut-short turn up again, once the thread reads ready: it goes
1012
+ // on where it stopped, or runs again when it had not got anywhere.
1013
+ // biome-ignore lint/correctness/useExhaustiveDependencies: Continue and Retry check their own state
1014
+ useEffect(() => {
1015
+ if (resumedThreadId === null) return
1016
+ if (resumedThreadId !== threadId) {
1017
+ setResumedThreadId(null)
1018
+ return
1019
+ }
1020
+ if (sandboxRecovery) return
1021
+
1022
+ setResumedThreadId(null)
1023
+ if (canContinue) void continueTurn()
1024
+ else if (canRetry) retry()
1025
+ }, [resumedThreadId, threadId, sandboxRecovery, canContinue, canRetry])
1026
+
953
1027
  const reader = user
954
1028
  ? { type: "user" as const, id: user.id, displayName: user.displayName }
955
1029
  : undefined
@@ -965,7 +1039,22 @@ export function useAgentConversation({
965
1039
  presentation,
966
1040
  })
967
1041
 
968
- const turn = conversationTurn({
1042
+ const answeringAuthor = useMemo(
1043
+ () =>
1044
+ answeringFor
1045
+ ? {
1046
+ type: answeringFor.type,
1047
+ id: answeringFor.id,
1048
+ ...(answeringForName === undefined ? {} : { displayName: answeringForName }),
1049
+ isReader: false,
1050
+ }
1051
+ : null,
1052
+ [answeringFor, answeringForName]
1053
+ )
1054
+ const continuingHere = continuingThreadId !== null && continuingThreadId === threadId
1055
+ const waitingForComputer = computerOffline ? (thread?.computer?.name ?? null) : null
1056
+ const streamReconnecting = live.active && reconnecting
1057
+ const nextTurn = conversationTurn({
969
1058
  presentation,
970
1059
  activeRunId,
971
1060
  canStop,
@@ -973,21 +1062,17 @@ export function useAgentConversation({
973
1062
  canContinue,
974
1063
  stopping,
975
1064
  retrying: retryRun.isPending,
976
- continuing: continuingThreadId !== null && continuingThreadId === threadId,
1065
+ continuing: continuingHere,
977
1066
  waitingLonger,
978
- waitingFor: computerOffline ? (thread?.computer?.name ?? null) : null,
1067
+ waitingFor: waitingForComputer,
979
1068
  compacting: live.compacting,
980
1069
  contextFull: live.contextFull,
981
- reconnecting: live.active && reconnecting,
982
- answeringFor: answeringFor
983
- ? {
984
- type: answeringFor.type,
985
- id: answeringFor.id,
986
- ...(answeringForName === undefined ? {} : { displayName: answeringForName }),
987
- isReader: false,
988
- }
989
- : null,
1070
+ reconnecting: streamReconnecting,
1071
+ answeringFor: answeringAuthor,
990
1072
  })
1073
+ const prevTurnRef = useRef(nextTurn)
1074
+ if (!sameTurn(prevTurnRef.current, nextTurn)) prevTurnRef.current = nextTurn
1075
+ const turn = prevTurnRef.current
991
1076
 
992
1077
  /**
993
1078
  * Stop a turn paused on held calls, as Stop does a running one: its waiting calls are set aside,
@@ -1105,76 +1190,217 @@ export function useAgentConversation({
1105
1190
  const [questionSetAside, setQuestionSetAside] = useState<string | null>(null)
1106
1191
  const asked = threadId !== null ? openQuestion(messages, turn) : null
1107
1192
  const asking = asked !== null && questionSetAside !== asked.messageKey ? asked : null
1108
- const questionProps: QuestionComposerProps | null = asking
1109
- ? {
1110
- questions: asking.questions,
1111
- onAnswer: (text) => void send(text, [], []),
1112
- onDismiss: () => setQuestionSetAside(asking.messageKey),
1113
- }
1114
- : null
1115
-
1116
- const transcriptProps: TranscriptProps = {
1117
- threadId,
1118
- messages,
1119
- moved,
1120
- turn,
1121
- anchorCurrentTurn,
1122
- onRetry: canRetry ? retry : undefined,
1123
- onContinue: canContinue ? continueTurn : undefined,
1124
- approvals: transcriptApprovals,
1125
- approvalOutcomes,
1126
- delegation: transcriptDelegation,
1127
- background: transcriptBackground,
1193
+ // Stable callbacks so streaming chunks never invalidate memoized Composer or Transcript controls.
1194
+ const actionsRef = useRef({
1195
+ send,
1196
+ stop,
1197
+ retry,
1198
+ continueTurn,
1199
+ selectModel,
1200
+ selectReasoning,
1201
+ resetReasoning,
1202
+ resetModelSelection,
1203
+ setApprovalMode,
1204
+ })
1205
+ actionsRef.current = {
1206
+ send,
1207
+ stop,
1208
+ retry,
1209
+ continueTurn,
1210
+ selectModel,
1211
+ selectReasoning,
1212
+ resetReasoning,
1213
+ resetModelSelection,
1214
+ setApprovalMode,
1128
1215
  }
1216
+ const stableSend = useCallback<ComposerProps["onSend"]>(
1217
+ (text, attachments, context, delivery) =>
1218
+ void actionsRef.current.send(text, attachments, context, delivery),
1219
+ []
1220
+ )
1221
+ const stableStop = useCallback(() => actionsRef.current.stop(), [])
1222
+ const stableRetry = useCallback(() => actionsRef.current.retry(), [])
1223
+ const stableContinue = useCallback(() => void actionsRef.current.continueTurn(), [])
1224
+ const stableSelectModel = useCallback(
1225
+ (model: LanguageModel) => actionsRef.current.selectModel(model),
1226
+ []
1227
+ )
1228
+ const stableSelectReasoning = useCallback(
1229
+ (reasoning: ModelReasoningLevel) => actionsRef.current.selectReasoning(reasoning),
1230
+ []
1231
+ )
1232
+ const stableResetReasoning = useCallback(() => actionsRef.current.resetReasoning(), [])
1233
+ const stableResetModelSelection = useCallback(() => actionsRef.current.resetModelSelection(), [])
1234
+ const stableSetApprovalMode = useCallback(
1235
+ (mode: AgentApprovalMode) => actionsRef.current.setApprovalMode(mode),
1236
+ []
1237
+ )
1238
+ const stableAnswerQuestion = useCallback(
1239
+ (text: string) => void actionsRef.current.send(text, [], []),
1240
+ []
1241
+ )
1129
1242
 
1130
- const modelControlsProps = {
1131
- models,
1132
- selectedModel,
1133
- selectedReasoning,
1134
- modelsLoading: modelsQuery.isLoading,
1135
- modelsError: modelsQuery.isError,
1136
- onSelectModel: selectModel,
1137
- onSelectReasoning: selectReasoning,
1138
- onResetReasoning: resetReasoning,
1139
- usingDefaultModel: modelSelection.request === undefined,
1140
- onResetModelSelection: resetModelSelection,
1141
- modelRouting: modelsQuery.data?.languageRouting,
1142
- }
1243
+ const askingKey = asking?.messageKey ?? null
1244
+ const dismissQuestion = useCallback(() => {
1245
+ if (askingKey) setQuestionSetAside(askingKey)
1246
+ }, [askingKey])
1143
1247
 
1144
- const composerProps: ConversationComposerProps = {
1145
- onSend: send,
1146
- ...(threadId === null && !newThreadSandbox && (newThreadPlace || newThreadPlaceWaiting)
1147
- ? { newThreadPlace: newThreadPlace ?? "waiting" }
1148
- : {}),
1149
- error: currentSendError
1150
- ? failureMessage(currentSendError, labels, agentMessages.approvalModes.saveFailed)
1151
- : undefined,
1152
- // Whoever's answer is in flight, the reader writes the next message, and sends it once it ends.
1153
- disabled: Boolean(sandboxRecovery),
1154
- hint: answeringName
1155
- ? agentMessages.sharing.answering(answeringName)
1156
- : othersWaiting
1157
- ? agentMessages.approvals.setsAside(transcriptApprovals.requesterName(othersWaiting))
1158
- : undefined,
1159
- pending: composerPending,
1160
- running: isRunning,
1161
- stopping,
1162
- onStop: canStop ? stop : undefined,
1163
- ...modelControlsProps,
1164
- draft: draftReseed.text,
1165
- draftAttachments: draftReseed.attachments,
1166
- draftContext: draftReseed.context,
1167
- draftNonce: draftReseed.nonce,
1168
- approvalMode,
1169
- onApprovalModeChange: setApprovalMode,
1170
- awaitingApproval,
1171
- dictation: projectDictation(modelsQuery.data),
1172
- contextMeter: {
1173
- context: threadId !== null ? contextQuery.data : undefined,
1174
- modelName: meteredModelName(models, contextQuery.data?.model),
1248
+ const questionProps: QuestionComposerProps | null = useMemo(
1249
+ () =>
1250
+ asking
1251
+ ? {
1252
+ questions: asking.questions,
1253
+ onAnswer: stableAnswerQuestion,
1254
+ onDismiss: dismissQuestion,
1255
+ }
1256
+ : null,
1257
+ [asking, stableAnswerQuestion, dismissQuestion]
1258
+ )
1259
+
1260
+ const movedAfterMessageId = moved?.afterMessageId ?? null
1261
+ const movedLabel = moved?.label ?? null
1262
+ const stableMoved = useMemo(
1263
+ () =>
1264
+ movedAfterMessageId && movedLabel
1265
+ ? { afterMessageId: movedAfterMessageId, label: movedLabel }
1266
+ : null,
1267
+ [movedAfterMessageId, movedLabel]
1268
+ )
1269
+
1270
+ const transcriptProps: TranscriptProps = useMemo(
1271
+ () => ({
1272
+ threadId,
1273
+ messages,
1274
+ moved: stableMoved,
1275
+ turn,
1276
+ anchorCurrentTurn,
1277
+ onRetry: canRetry ? stableRetry : undefined,
1278
+ onContinue: canContinue ? stableContinue : undefined,
1279
+ approvals: transcriptApprovals,
1280
+ approvalOutcomes,
1281
+ delegation: transcriptDelegation,
1282
+ background: transcriptBackground,
1283
+ }),
1284
+ [
1285
+ threadId,
1286
+ messages,
1287
+ stableMoved,
1288
+ turn,
1289
+ anchorCurrentTurn,
1290
+ canRetry,
1291
+ stableRetry,
1292
+ canContinue,
1293
+ stableContinue,
1294
+ transcriptApprovals,
1295
+ approvalOutcomes,
1296
+ transcriptDelegation,
1297
+ transcriptBackground,
1298
+ ]
1299
+ )
1300
+
1301
+ const meterContext = threadId !== null ? contextQuery.data : undefined
1302
+ const meterModelName = meteredModelName(models, contextQuery.data?.model)
1303
+ const contextMeter = useMemo(
1304
+ () => ({
1305
+ context: meterContext,
1306
+ modelName: meterModelName,
1175
1307
  condensing: live.compacting,
1176
- },
1177
- }
1308
+ }),
1309
+ [meterContext, meterModelName, live.compacting]
1310
+ )
1311
+
1312
+ const composerError = currentSendError
1313
+ ? failureMessage(currentSendError, labels, agentMessages.approvalModes.saveFailed)
1314
+ : undefined
1315
+ const composerHint = answeringName
1316
+ ? agentMessages.sharing.answering(answeringName)
1317
+ : othersWaiting
1318
+ ? agentMessages.approvals.setsAside(transcriptApprovals.requesterName(othersWaiting))
1319
+ : undefined
1320
+ const resolvedNewThreadPlace =
1321
+ threadId === null && !newThreadSandbox && (newThreadPlace || newThreadPlaceWaiting)
1322
+ ? (newThreadPlace ?? "waiting")
1323
+ : undefined
1324
+ const usingDefaultModel = modelSelection.request === undefined
1325
+ const modelRouting = modelsQuery.data?.languageRouting
1326
+ const dictationRecognizer = projectDictation(modelsQuery.data)
1327
+ const composerDisabled = Boolean(sandboxRecovery)
1328
+ const steerable = !requestedBySomeoneElse(activeRun, user)
1329
+
1330
+ const composerProps: ConversationComposerProps = useMemo(
1331
+ () => ({
1332
+ onSend: stableSend,
1333
+ ...(resolvedNewThreadPlace ? { newThreadPlace: resolvedNewThreadPlace } : {}),
1334
+ error: composerError,
1335
+ // Whoever's answer is in flight, the reader writes the next message.
1336
+ disabled: composerDisabled,
1337
+ hint: composerHint,
1338
+ pending: composerPending,
1339
+ running: isRunning,
1340
+ // Only the turn the reader asked for takes a steer; another person's takes a queued message.
1341
+ steerable,
1342
+ stopping,
1343
+ onStop: canStop ? stableStop : undefined,
1344
+ models,
1345
+ selectedModel,
1346
+ selectedReasoning,
1347
+ modelsLoading: modelsQuery.isLoading,
1348
+ modelsError: modelsQuery.isError,
1349
+ onSelectModel: stableSelectModel,
1350
+ onSelectReasoning: stableSelectReasoning,
1351
+ onResetReasoning: stableResetReasoning,
1352
+ usingDefaultModel,
1353
+ onResetModelSelection: stableResetModelSelection,
1354
+ modelRouting,
1355
+ draftKey: threadId ?? "draft",
1356
+ draft: draftReseed.text,
1357
+ draftAttachments: draftReseed.attachments,
1358
+ draftContext: draftReseed.context,
1359
+ draftNonce: draftReseed.nonce,
1360
+ draftReseedKey: draftReseed.draftKey,
1361
+ approvalMode,
1362
+ onApprovalModeChange: stableSetApprovalMode,
1363
+ awaitingApproval,
1364
+ dictation: dictationRecognizer,
1365
+ contextMeter,
1366
+ }),
1367
+ [
1368
+ stableSend,
1369
+ resolvedNewThreadPlace,
1370
+ composerError,
1371
+ composerDisabled,
1372
+ composerHint,
1373
+ composerPending,
1374
+ isRunning,
1375
+ steerable,
1376
+ stopping,
1377
+ canStop,
1378
+ stableStop,
1379
+ models,
1380
+ selectedModel,
1381
+ selectedReasoning,
1382
+ modelsQuery.isLoading,
1383
+ modelsQuery.isError,
1384
+ stableSelectModel,
1385
+ stableSelectReasoning,
1386
+ stableResetReasoning,
1387
+ usingDefaultModel,
1388
+ stableResetModelSelection,
1389
+ modelRouting,
1390
+ threadId,
1391
+ draftReseed,
1392
+ approvalMode,
1393
+ stableSetApprovalMode,
1394
+ awaitingApproval,
1395
+ dictationRecognizer,
1396
+ contextMeter,
1397
+ ]
1398
+ )
1399
+
1400
+ const pendingProps: PendingMessagesProps = useMemo(
1401
+ () => ({ threadId, steerable, read: readMessageIds }),
1402
+ [threadId, steerable, readMessageIds]
1403
+ )
1178
1404
 
1179
1405
  const movingThisThread = moveToCloud.variables?.path.threadId === thread?.id
1180
1406
  const computerNoticeProps: ComputerOfflineNoticeProps | null = computerOffline
@@ -1200,9 +1426,19 @@ export function useAgentConversation({
1200
1426
 
1201
1427
  const sandboxRecoveryProps: SandboxRecoveryProps | null = sandboxRecovery
1202
1428
  ? {
1203
- pending: recreateSandbox.isPending,
1429
+ pending: recreateSandbox.isPending || restoreSandbox.isPending,
1204
1430
  error: recreateSandbox.isError,
1205
- onRecreate: handleRecreateSandbox,
1431
+ onRecreate: () => recoverSandbox(recreateSandbox),
1432
+ // Only a workspace its run finished preparing has files to go on from.
1433
+ ...(sandboxRecovery.status !== "unavailable" && sandboxRecovery.initialized
1434
+ ? {
1435
+ restore: {
1436
+ pending: restoreSandbox.isPending,
1437
+ error: restoreSandbox.isError,
1438
+ onRestore: () => recoverSandbox(restoreSandbox),
1439
+ },
1440
+ }
1441
+ : {}),
1206
1442
  canRecreate: access === "owner",
1207
1443
  owner: thread ? personName(threadOwner(thread)) : "",
1208
1444
  }
@@ -1281,6 +1517,8 @@ export function useAgentConversation({
1281
1517
  * until the reader answers it or sets it aside.
1282
1518
  */
1283
1519
  questionProps,
1520
+ /** Spread into `<PendingMessages>`, above the composer: what waits beside the running turn. */
1521
+ pendingProps,
1284
1522
  /** Spread into `<SandboxRecovery>` while set: the composer stays disabled until it is resolved. */
1285
1523
  sandboxRecoveryProps,
1286
1524
  /** Where the reader's own conversation runs on their computer, for its badge. */
@@ -1472,3 +1710,13 @@ function useExtendedWaitingStatus(run: Pick<AgentRun, "status" | "createdAt"> |
1472
1710
 
1473
1711
  return visible
1474
1712
  }
1713
+
1714
+ function sameTurn(a: AgentConversationTurn, b: AgentConversationTurn): boolean {
1715
+ const keysA = Object.keys(a)
1716
+ const keysB = Object.keys(b)
1717
+ if (keysA.length !== keysB.length) return false
1718
+ for (const key of keysA) {
1719
+ if (!Object.is(Reflect.get(a, key), Reflect.get(b, key))) return false
1720
+ }
1721
+ return true
1722
+ }
@@ -3,6 +3,7 @@ import {
3
3
  getAgentRunQueryKey,
4
4
  getAgentThreadContextQueryKey,
5
5
  getAgentThreadQueryKey,
6
+ listAgentThreadInboxQueryKey,
6
7
  listAgentThreadMessagesQueryKey,
7
8
  listAgentThreadRunsQueryKey,
8
9
  listAgentThreadsQueryKey,
@@ -69,6 +70,15 @@ export function useThreadStream(options: UseThreadStreamOptions): UseThreadStrea
69
70
  })
70
71
  }, [live.finalizedMessageId, threadId, queryClient])
71
72
 
73
+ // A message the turn read is no longer the inbox's: the tray reads what still waits.
74
+ const reads = live.inboxReads.length
75
+ useEffect(() => {
76
+ if (reads === 0 || !threadId) return
77
+ void queryClient.invalidateQueries({
78
+ queryKey: listAgentThreadInboxQueryKey({ path: { threadId } }),
79
+ })
80
+ }, [reads, threadId, queryClient])
81
+
72
82
  // Refresh run/thread state once the run reaches a terminal status.
73
83
  const finishHandledRef = useRef<string | null>(null)
74
84
  useEffect(() => {