@sixb/app 0.1.13 → 0.1.15

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