@sixb/app 0.1.14 → 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 (70) hide show
  1. package/dist/{chunk-vtp6nk44.js → chunk-736c9akn.js} +1 -1
  2. package/dist/{chunk-1rhht9y0.js → chunk-n0cxwvej.js} +1 -1
  3. package/dist/{chunk-0yb22w6m.js → chunk-qh1panvd.js} +1 -1
  4. package/dist/{chunk-aes17xmx.js → chunk-twjs2sb9.js} +3928 -3717
  5. package/dist/{chunk-aes17xmx.js.map → chunk-twjs2sb9.js.map} +46 -42
  6. package/dist/index.js +15 -6
  7. package/dist/index.js.map +6 -6
  8. package/dist/pages.js +60 -44
  9. package/dist/pages.js.map +8 -8
  10. package/dist/server.js +12 -6
  11. package/dist/server.js.map +3 -3
  12. package/package.json +3 -3
  13. package/src/agent/agent-chat.tsx +4 -22
  14. package/src/agent/agent-panel.tsx +4 -0
  15. package/src/agent/agent-surface.tsx +4 -0
  16. package/src/agent/agent.css +33 -3
  17. package/src/agent/approvals.ts +4 -5
  18. package/src/agent/artifact-panel.tsx +113 -37
  19. package/src/agent/components/activity-status.tsx +1 -1
  20. package/src/agent/components/agent-threads.tsx +377 -0
  21. package/src/agent/components/approval-card.tsx +336 -327
  22. package/src/agent/components/approval-mode-chip.tsx +38 -145
  23. package/src/agent/components/auto-model-chip.tsx +103 -167
  24. package/src/agent/components/composer-menu.tsx +185 -0
  25. package/src/agent/components/composer.tsx +38 -43
  26. package/src/agent/components/context-chips.tsx +1 -1
  27. package/src/agent/components/conversation-panel.tsx +16 -36
  28. package/src/agent/components/file-attachment-card.tsx +5 -2
  29. package/src/agent/components/message-parts.tsx +27 -11
  30. package/src/agent/components/message-view.tsx +182 -68
  31. package/src/agent/components/model-controls.tsx +133 -125
  32. package/src/agent/components/model-picker-row.tsx +38 -17
  33. package/src/agent/components/participant-input.tsx +159 -31
  34. package/src/agent/components/reasoning-effort-slider.tsx +27 -27
  35. package/src/agent/components/shared-thread-notice.tsx +1 -1
  36. package/src/agent/components/thread-people.tsx +45 -15
  37. package/src/agent/components/threads-button.tsx +70 -0
  38. package/src/agent/components/transcript.tsx +30 -1
  39. package/src/agent/conversation.ts +25 -1
  40. package/src/agent/delegation/child-card.tsx +187 -247
  41. package/src/agent/delegation/child-cards.tsx +4 -7
  42. package/src/agent/delegation/child-group.tsx +179 -98
  43. package/src/agent/delegation/child-parts.tsx +71 -106
  44. package/src/agent/delegation/child-work.tsx +6 -52
  45. package/src/agent/delegation/interpret.ts +0 -28
  46. package/src/agent/delegation/model.ts +115 -39
  47. package/src/agent/hooks/use-agent-conversation.ts +7 -92
  48. package/src/agent/hooks/use-people-suggestions.ts +90 -0
  49. package/src/agent/hooks/use-thread-lists.ts +77 -0
  50. package/src/agent/i18n/en.ts +96 -83
  51. package/src/agent/i18n/fr.ts +105 -100
  52. package/src/agent/react-router.tsx +48 -5
  53. package/src/agent/run-presentation.ts +6 -2
  54. package/src/agent/thread-navigation.ts +16 -0
  55. package/src/agent/thread-pages.ts +24 -0
  56. package/src/artifacts/person-avatar.tsx +1 -1
  57. package/src/createCustomApp.ts +13 -6
  58. package/src/index.ts +7 -3
  59. package/src/pages/home.tsx +3 -1
  60. package/src/pages/observability/ai-usage/calls.tsx +2 -1
  61. package/src/pages/settings/memory-history.tsx +2 -1
  62. package/src/pages/settings/messages.ts +2 -3
  63. package/src/pages/values.tsx +23 -1
  64. package/src/pages.ts +5 -1
  65. package/src/shell/agent-dock.tsx +4 -2
  66. package/src/agent/agents-page.ts +0 -7
  67. package/src/agent/components/agent-thread-switcher.tsx +0 -519
  68. /package/dist/{chunk-vtp6nk44.js.map → chunk-736c9akn.js.map} +0 -0
  69. /package/dist/{chunk-1rhht9y0.js.map → chunk-n0cxwvej.js.map} +0 -0
  70. /package/dist/{chunk-0yb22w6m.js.map → chunk-qh1panvd.js.map} +0 -0
@@ -1,6 +1,5 @@
1
1
  import { Spinner } from "@sixb/ui/components"
2
- import { cn } from "@sixb/ui/lib/utils"
3
- import { Fragment, memo, type ReactNode, useEffect, useLayoutEffect, useMemo, useRef } from "react"
2
+ import { Fragment, memo, type ReactNode, useEffect, useMemo, useRef } from "react"
4
3
  import { childFileSource, messageFileSource } from "../../artifacts/file-source"
5
4
  import { FileAttachmentCard } from "../components/file-attachment-card"
6
5
  import { AssistantBody } from "../components/message-parts"
@@ -116,16 +115,11 @@ export function ChildWork({
116
115
  } else if (atWork && live?.runId === run.id && live.parts.length > 0) {
117
116
  body = <AssistantBody parts={live.parts} live={live.active} nested />
118
117
  } else if (atWork) {
119
- // An observer reads no stream: a run's steps come once it ended.
120
- body = (
121
- <p className="text-[13px] text-muted-foreground shimmer motion-reduce:animate-none">
122
- {observed
123
- ? labels.stepsLater
124
- : run.status === "queued"
125
- ? labels.states.starting
126
- : labels.states.working}
127
- </p>
128
- )
118
+ // Its status says it works; until its first step, nothing more to say. An observer reads
119
+ // no stream: a run's steps come once it ended.
120
+ body = observed ? (
121
+ <p className="text-[13px] text-muted-foreground">{labels.stepsLater}</p>
122
+ ) : null
129
123
  } else if (messages.isError) {
130
124
  body = <p className="text-[13px] text-muted-foreground">{labels.loadFailed}</p>
131
125
  } else if (messages.isLoading || messages.isFetching) {
@@ -202,43 +196,3 @@ const RunWork = memo(function RunWork({
202
196
  </>
203
197
  )
204
198
  })
205
-
206
- /**
207
- * A scrolling box that follows new content while its reader is at its end, and stays where they
208
- * scrolled otherwise.
209
- */
210
- export function FollowingScroll({
211
- follow,
212
- live,
213
- className,
214
- children,
215
- }: {
216
- /** Changes when the content grows. */
217
- readonly follow: string
218
- /** The content is still growing: it opens at its end. Otherwise at its start. */
219
- readonly live: boolean
220
- readonly className?: string
221
- readonly children: ReactNode
222
- }) {
223
- const box = useRef<HTMLDivElement>(null)
224
- const atEnd = useRef(live)
225
-
226
- // biome-ignore lint/correctness/useExhaustiveDependencies: `follow` is the trigger
227
- useLayoutEffect(() => {
228
- const element = box.current
229
- if (element && atEnd.current) element.scrollTop = element.scrollHeight
230
- }, [follow])
231
-
232
- return (
233
- <div
234
- ref={box}
235
- onScroll={(event) => {
236
- const element = event.currentTarget
237
- atEnd.current = element.scrollHeight - element.scrollTop - element.clientHeight < 48
238
- }}
239
- className={cn("scrollbar-thin overflow-y-auto overscroll-contain", className)}
240
- >
241
- {children}
242
- </div>
243
- )
244
- }
@@ -260,34 +260,6 @@ export function workedMs(view: AgentChild, now: number): number {
260
260
  }, 0)
261
261
  }
262
262
 
263
- /**
264
- * What children spent together, in the currency the first of them was priced in; nothing until a
265
- * call was priced.
266
- */
267
- export function childrenCost(
268
- views: readonly (AgentChild | undefined)[],
269
- locale: string
270
- ): string | null {
271
- const amounts = views.flatMap((view) => view?.cost?.amounts ?? [])
272
- const currency = amounts[0]?.currency
273
- if (!currency) return null
274
-
275
- const nanos = amounts
276
- .filter((amount) => amount.currency === currency)
277
- .reduce((total, amount) => total + BigInt(amount.amountNanos), 0n)
278
- const value = Number(nanos) / 1_000_000_000
279
- const format = (figure: number) =>
280
- new Intl.NumberFormat(locale, {
281
- style: "currency",
282
- currency,
283
- minimumFractionDigits: 2,
284
- maximumFractionDigits: 2,
285
- }).format(figure)
286
-
287
- if (value > 0 && value < 0.01) return `< ${format(0.01)}`
288
- return format(value)
289
- }
290
-
291
263
  /**
292
264
  * A child's name, from the key the Agent spawned it with: "supplier-terms" reads "Supplier terms",
293
265
  * "checkINV4490" reads "Check INV4490". The key's own capitals stay.
@@ -5,6 +5,7 @@ import {
5
5
  type AgentChild,
6
6
  type ChildState,
7
7
  childState,
8
+ childTitle,
8
9
  isActive,
9
10
  liveQuestion,
10
11
  type SpawnedChild,
@@ -101,51 +102,126 @@ export function isSettled(state: ChildState): boolean {
101
102
  )
102
103
  }
103
104
 
104
- /** One part of a group's summary: how many stand where, and whether the reader must act. */
105
- export interface SummaryPart {
106
- readonly text: string
107
- readonly urgent: boolean
105
+ /** One clause of a reply's line: some sub-agents by name, and how they stand. */
106
+ export interface LineClause {
107
+ readonly names: string
108
+ readonly verb: string
109
+ /** `urgent`: the reader is the one to act. `live`: still at work. */
110
+ readonly tone: "urgent" | "live" | "quiet"
108
111
  }
109
112
 
110
- /** How a group's children stand, in the order a reader cares: what waits on them first. */
111
- export function groupSummary(
113
+ /**
114
+ * A reply's sub-agents as a sentence, its clauses in the order a reader cares about: what waits
115
+ * on them, what is at work, then how the rest ended. "Terms needs your approval · History is
116
+ * working", "Terms, History and Disputes finished".
117
+ */
118
+ export function lineClauses(
112
119
  models: readonly ChildModel[],
113
120
  messages: AgentMessages
114
- ): SummaryPart[] {
115
- const labels = messages.delegation
116
- const count = (test: (model: ChildModel) => boolean) => models.filter(test).length
117
- const waiting = (model: ChildModel) =>
118
- (model.state === "approval" || model.state === "answer") && !model.needsReader
119
-
120
- const forYou = count((model) => model.needsReader)
121
- const others = models.filter(waiting)
122
- const names = new Set(
123
- others.map((model) => (model.waitingOn.kind === "person" ? model.waitingOn.name : ""))
124
- )
125
- const [name] = names
126
- const working = count((model) => isActive(model.state))
127
- const later = count((model) => model.state === "resume")
128
- const done = count((model) => model.state === "done")
129
- const failed = count((model) => model.state === "failed")
130
- const stopped = count((model) => model.state === "stopped" || model.state === "ended")
121
+ ): readonly LineClause[] {
122
+ const labels = messages.delegation.line
123
+ const clause = (
124
+ test: (model: ChildModel) => boolean,
125
+ verb: (agents: number) => string,
126
+ tone: LineClause["tone"]
127
+ ): LineClause | null => {
128
+ const named = models.filter(test).map((model) => shortName(childTitle(model.child.key)))
129
+ return named.length > 0 ? { names: labels.names(named), verb: verb(named.length), tone } : null
130
+ }
131
+ const person = personWaitedOn(models)
132
+ const urgent = [
133
+ clause((model) => model.needsReader && model.state === "approval", labels.approval, "urgent"),
134
+ clause((model) => model.needsReader && model.state === "answer", labels.answer, "urgent"),
135
+ ]
136
+
137
+ // Many, or long-named, read as a count: names would turn the line into a paragraph. Whoever
138
+ // waits on the reader is still named.
139
+ // A lone agent is always named, its name shortened if it must be.
140
+ if (
141
+ models.length > NAMED_AGENTS ||
142
+ (models.length > 1 && models.some((model) => !named(model)))
143
+ ) {
144
+ const counts = messages.delegation
145
+ const counted = (
146
+ test: (model: ChildModel) => boolean,
147
+ verb: (agents: number) => string,
148
+ tone: LineClause["tone"]
149
+ ): LineClause | null => {
150
+ const agents = models.filter(test).length
151
+ return agents > 0 ? { names: "", verb: verb(agents), tone } : null
152
+ }
153
+ return [
154
+ { names: counts.count(models.length), verb: "", tone: "quiet" as const },
155
+ ...urgent,
156
+ counted(
157
+ waitingOther,
158
+ person ? (agents) => counts.waitingOn(agents, person) : counts.waitingOthers,
159
+ "quiet"
160
+ ),
161
+ counted((model) => isActive(model.state), counts.working, "live"),
162
+ counted((model) => model.state === "resume", counts.later, "quiet"),
163
+ counted((model) => model.state === "done", counts.done, "quiet"),
164
+ counted((model) => model.state === "failed", counts.failed, "quiet"),
165
+ counted(
166
+ (model) => model.state === "stopped" || model.state === "ended",
167
+ counts.stopped,
168
+ "quiet"
169
+ ),
170
+ ].filter((part): part is LineClause => part !== null)
171
+ }
131
172
 
132
173
  return [
133
- forYou > 0 ? { text: labels.waitingYou(forYou), urgent: true } : null,
134
- others.length > 0
135
- ? {
136
- text:
137
- names.size === 1 && name
138
- ? labels.waitingOn(others.length, name)
139
- : labels.waitingOthers(others.length),
140
- urgent: false,
141
- }
142
- : null,
143
- working > 0 ? { text: labels.working(working), urgent: false } : null,
144
- later > 0 ? { text: labels.later(later), urgent: false } : null,
145
- done > 0 ? { text: labels.done(done), urgent: false } : null,
146
- failed > 0 ? { text: labels.failed(failed), urgent: false } : null,
147
- stopped > 0 ? { text: labels.stopped(stopped), urgent: false } : null,
148
- ].filter((part): part is SummaryPart => part !== null)
174
+ ...urgent,
175
+ clause(
176
+ waitingOther,
177
+ person ? (agents) => labels.waitingOn(agents, person) : labels.waiting,
178
+ "quiet"
179
+ ),
180
+ clause((model) => model.state === "asking", labels.asking, "live"),
181
+ clause((model) => model.state === "working", labels.working, "live"),
182
+ clause((model) => model.state === "starting", labels.starting, "live"),
183
+ clause((model) => model.state === "resume", labels.later, "quiet"),
184
+ clause((model) => model.state === "done", labels.done, "quiet"),
185
+ clause((model) => model.state === "failed", labels.failed, "quiet"),
186
+ clause(
187
+ (model) => model.state === "stopped" || model.state === "ended",
188
+ labels.stopped,
189
+ "quiet"
190
+ ),
191
+ ].filter((part): part is LineClause => part !== null)
192
+ }
193
+
194
+ /** Waiting on someone, but not on the reader: their approval or their answer. */
195
+ function waitingOther(model: ChildModel): boolean {
196
+ return (model.state === "approval" || model.state === "answer") && !model.needsReader
197
+ }
198
+
199
+ /** The one person the others wait on, when it is one person. */
200
+ function personWaitedOn(models: readonly ChildModel[]): string | null {
201
+ const people = new Set(
202
+ models
203
+ .filter(waitingOther)
204
+ .map((model) => (model.waitingOn.kind === "person" ? model.waitingOn.name : ""))
205
+ )
206
+ const [person] = people
207
+ return people.size === 1 && person ? person : null
208
+ }
209
+
210
+ /** The longest a name reads in the line before it is cut at a word; its thread shows it whole. */
211
+ const LINE_NAME_LENGTH = 28
212
+
213
+ /** Up to this many sub-agents, with short names, the line names each; past it, it counts them. */
214
+ const NAMED_AGENTS = 3
215
+
216
+ function named(model: ChildModel): boolean {
217
+ return childTitle(model.child.key).length <= 20
218
+ }
219
+
220
+ function shortName(name: string): string {
221
+ if (name.length <= LINE_NAME_LENGTH) return name
222
+ const cut = name.slice(0, LINE_NAME_LENGTH)
223
+ const word = cut.lastIndexOf(" ")
224
+ return `${(word > LINE_NAME_LENGTH / 2 ? cut.slice(0, word) : cut).replace(/[\s,.:;-]+$/, "")}…`
149
225
  }
150
226
 
151
227
  /** What `wait_agent` last said of any of the child's runs. */
@@ -8,7 +8,6 @@ import {
8
8
  getAgentPreferencesQueryKey,
9
9
  getAgentThreadOptions,
10
10
  getAgentThreadQueryKey,
11
- listAgentApprovalsOptions,
12
11
  listAgentApprovalsQueryKey,
13
12
  listAgentThreadApprovalsOptions,
14
13
  listAgentThreadApprovalsQueryKey,
@@ -16,7 +15,6 @@ import {
16
15
  listAgentThreadMessagesQueryKey,
17
16
  listAgentThreadRunsOptions,
18
17
  listAgentThreadRunsQueryKey,
19
- listAgentThreadsInfiniteOptions,
20
18
  listAgentThreadsQueryKey,
21
19
  listModelsOptions,
22
20
  postAgentThreadMessageMutation,
@@ -27,7 +25,7 @@ import {
27
25
  useAgentActivityStream,
28
26
  } from "@sixb/client/hooks"
29
27
  import { MODEL_REASONING_LEVELS, type ModelReasoningLevel } from "@sixb/core/models"
30
- import { useInfiniteQuery, useMutation, useQuery, useQueryClient } from "@tanstack/react-query"
28
+ import { useMutation, useQuery, useQueryClient } from "@tanstack/react-query"
31
29
  import { useEffect, useMemo, useRef, useState } from "react"
32
30
  import { useCurrentUser } from "../../session"
33
31
  import {
@@ -75,8 +73,8 @@ import {
75
73
  threadOwner,
76
74
  userPrincipal,
77
75
  } from "../sharing"
78
- import { THREAD_PAGE_SIZE } from "../thread-navigation"
79
76
  import type { AgentContextEntryInput, AgentFileRef, AgentRun, LanguageModel } from "../types"
77
+ import { useAgentThreadLists } from "./use-thread-lists"
80
78
  import { useThreadStream } from "./use-thread-stream"
81
79
 
82
80
  interface PendingSend {
@@ -91,24 +89,9 @@ interface PendingSend {
91
89
  /** Keys of the messages the reader sends, so each keeps its key once it is saved. */
92
90
  let sentMessageCount = 0
93
91
 
94
- const THREAD_LIST_QUERY = {
95
- limit: String(THREAD_PAGE_SIZE),
96
- order: "desc" as const,
97
- }
98
-
99
92
  /** Enough of a thread's held calls for every card: a turn holds a few, and a thread few turns. */
100
93
  const THREAD_APPROVALS_QUERY = { limit: "200" }
101
94
 
102
- /** The calls waiting for the reader across threads, for the thread list. */
103
- const PENDING_APPROVALS_QUERY = { status: "pending" as const, limit: "200" }
104
-
105
- /** The conversations others shared with the reader: one page, newest first. */
106
- const SHARED_THREAD_LIST_QUERY = {
107
- sharedWithMe: "true" as const,
108
- limit: String(THREAD_PAGE_SIZE),
109
- order: "desc" as const,
110
- }
111
-
112
95
  const MODEL_PREFERENCE_KEY = "sixb.agent-ui.model-preference"
113
96
  const MODEL_PINS_KEY = "sixb.agent-ui.model-pins"
114
97
  /** Pins kept per browser, the most recently chosen last; older ones fall back to Auto. */
@@ -149,9 +132,7 @@ export type ConversationComposerProps = Pick<
149
132
  | "draftContext"
150
133
  | "draftNonce"
151
134
  | "approvalMode"
152
- | "defaultApprovalMode"
153
135
  | "onApprovalModeChange"
154
- | "onMakeApprovalModeDefault"
155
136
  | "awaitingApproval"
156
137
  >
157
138
 
@@ -218,37 +199,8 @@ export function useAgentConversation({ threadId, onThreadCreated }: UseAgentConv
218
199
  // The project activity feed is primary. Poll only as a focus-aware recovery path while the
219
200
  // socket is unavailable, rather than opening one connection per background thread.
220
201
  const recoveryPollMs = !activityStream.connected || activityStream.error ? 10_000 : false
221
- const threadsQuery = useInfiniteQuery({
222
- ...listAgentThreadsInfiniteOptions({ query: THREAD_LIST_QUERY }),
223
- initialPageParam: { query: THREAD_LIST_QUERY },
224
- getNextPageParam: (lastPage, pages) => {
225
- if (!lastPage.hasMore) return undefined
226
-
227
- return {
228
- query: {
229
- ...THREAD_LIST_QUERY,
230
- offset: String(pages.length * THREAD_PAGE_SIZE),
231
- },
232
- }
233
- },
234
- refetchInterval: recoveryPollMs,
235
- })
236
- // Nothing announces a new share or a removal: read the list again when the reader comes back.
237
- const sharedThreadsQuery = useInfiniteQuery({
238
- ...listAgentThreadsInfiniteOptions({ query: SHARED_THREAD_LIST_QUERY }),
239
- initialPageParam: { query: SHARED_THREAD_LIST_QUERY },
240
- getNextPageParam: (lastPage, pages) => {
241
- if (!lastPage.hasMore) return undefined
242
-
243
- return {
244
- query: {
245
- ...SHARED_THREAD_LIST_QUERY,
246
- offset: String(pages.length * THREAD_PAGE_SIZE),
247
- },
248
- }
249
- },
202
+ const { threads, sharedThreads, waitingThreadIds } = useAgentThreadLists({
250
203
  refetchInterval: recoveryPollMs,
251
- refetchOnWindowFocus: true,
252
204
  })
253
205
  const currentAgent = agentQuery.data
254
206
  const models = useMemo(() => modelsQuery.data?.language ?? [], [modelsQuery.data])
@@ -265,16 +217,6 @@ export function useAgentConversation({ threadId, onThreadCreated }: UseAgentConv
265
217
  )
266
218
  const selectedModel = modelSelection.model
267
219
  const selectedReasoning = modelSelection.reasoning
268
- const threads = useMemo(
269
- () => threadsQuery.data?.pages.flatMap((page) => page.threads) ?? [],
270
- [threadsQuery.data]
271
- )
272
-
273
- const sharedThreads = useMemo(
274
- () => sharedThreadsQuery.data?.pages.flatMap((page) => page.threads) ?? [],
275
- [sharedThreadsQuery.data]
276
- )
277
-
278
220
  const threadQuery = useQuery({
279
221
  ...getAgentThreadOptions({ path: { threadId: threadId ?? "" } }),
280
222
  enabled: threadId !== null,
@@ -346,19 +288,6 @@ export function useAgentConversation({ threadId, onThreadCreated }: UseAgentConv
346
288
  )
347
289
  return pending.length === 0 ? read : [...read, ...pending]
348
290
  }, [threadId, approvalsQuery.data, pendingHereQuery.data])
349
- const pendingApprovalsQuery = useQuery({
350
- ...listAgentApprovalsOptions({ query: PENDING_APPROVALS_QUERY }),
351
- refetchInterval: recoveryPollMs,
352
- retry: false,
353
- })
354
- /** The threads where a call waits for the reader. */
355
- const waitingThreadIds = useMemo(
356
- () =>
357
- new Set(
358
- (pendingApprovalsQuery.data?.approvals ?? []).map((approval) => approval.threadId)
359
- ) as ReadonlySet<string>,
360
- [pendingApprovalsQuery.data]
361
- )
362
291
 
363
292
  const [pendingSend, setPendingSend] = useState<PendingSend | null>(null)
364
293
  const [pendingUser, setPendingUser] = useState<PendingUserMessage | null>(null)
@@ -668,9 +597,11 @@ export function useAgentConversation({ threadId, onThreadCreated }: UseAgentConv
668
597
  /**
669
598
  * What the reader's next turns here may change without asking. In a thread it is kept as their
670
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.
671
601
  */
672
602
  const setApprovalMode = (mode: AgentApprovalMode) => {
673
603
  setChosenApprovalMode({ threadId, mode })
604
+ if (mode !== defaultApprovalMode) setDefaultApprovalMode(mode)
674
605
  if (threadId === null) return
675
606
 
676
607
  // Saves run one after the other: until the last choice is saved, the chip keeps showing it.
@@ -831,8 +762,6 @@ export function useAgentConversation({ threadId, onThreadCreated }: UseAgentConv
831
762
  return () => window.removeEventListener("storage", follow)
832
763
  }, [])
833
764
 
834
- const agentThreads = threads.filter((entry) => entry.id !== threadId)
835
-
836
765
  const sandboxRecovery =
837
766
  thread?.sandboxState &&
838
767
  !isRunning &&
@@ -881,6 +810,7 @@ export function useAgentConversation({ threadId, onThreadCreated }: UseAgentConv
881
810
  isRunning,
882
811
  sandboxRecovery: Boolean(sandboxRecovery),
883
812
  messages: savedMessages,
813
+ latestRun,
884
814
  })
885
815
 
886
816
  const reader = user
@@ -893,6 +823,7 @@ export function useAgentConversation({ threadId, onThreadCreated }: UseAgentConv
893
823
  reader,
894
824
  pending: pendingUser && pendingUser.threadId === threadId ? pendingUser : null,
895
825
  sentKeys,
826
+ runs,
896
827
  live,
897
828
  presentation,
898
829
  })
@@ -1030,9 +961,7 @@ export function useAgentConversation({ threadId, onThreadCreated }: UseAgentConv
1030
961
  draftContext: draftReseed.context,
1031
962
  draftNonce: draftReseed.nonce,
1032
963
  approvalMode,
1033
- defaultApprovalMode,
1034
964
  onApprovalModeChange: setApprovalMode,
1035
- onMakeApprovalModeDefault: setDefaultApprovalMode,
1036
965
  awaitingApproval,
1037
966
  }
1038
967
 
@@ -1067,25 +996,11 @@ export function useAgentConversation({ threadId, onThreadCreated }: UseAgentConv
1067
996
  selectReasoning,
1068
997
  resetReasoning,
1069
998
  resetModelSelection,
1070
- threads,
1071
999
  /** Threads with a run in progress, counting this one while its run starts. */
1072
1000
  runningThreadCount,
1073
- threadsError: threadsQuery.isError,
1074
- threadsHasMore: threadsQuery.hasNextPage,
1075
- threadsLoadingMore: threadsQuery.isFetchingNextPage,
1076
- threadsLoadMoreError: threadsQuery.isFetchNextPageError,
1077
- loadMoreThreads: () => threadsQuery.fetchNextPage(),
1078
1001
  threadUnavailable,
1079
1002
  currentAgent,
1080
1003
  currentThread: thread,
1081
- agentThreads,
1082
- sharedThreads,
1083
- sharedThreadsTotal: sharedThreadsQuery.data?.pages[0]?.total ?? 0,
1084
- sharedThreadsError: sharedThreadsQuery.isError,
1085
- sharedThreadsHasMore: sharedThreadsQuery.hasNextPage,
1086
- sharedThreadsLoadingMore: sharedThreadsQuery.isFetchingNextPage,
1087
- sharedThreadsLoadMoreError: sharedThreadsQuery.isFetchNextPageError,
1088
- loadMoreSharedThreads: () => sharedThreadsQuery.fetchNextPage(),
1089
1004
  access,
1090
1005
  user,
1091
1006
  removedFromThread,
@@ -0,0 +1,90 @@
1
+ import { listUsersOptions } from "@sixb/client/hooks"
2
+ import { keepPreviousData, useQuery } from "@tanstack/react-query"
3
+ import { useMemo } from "react"
4
+ import { useAgentThreadLists } from "./use-thread-lists"
5
+
6
+ /** Someone the share field can suggest: a member, with their email when the directory gave it. */
7
+ export interface PersonSuggestion {
8
+ readonly id: string
9
+ readonly name: string
10
+ readonly email?: string
11
+ }
12
+
13
+ /** The most the field lists at once. */
14
+ const SUGGESTIONS = 6
15
+
16
+ /**
17
+ * Who the share field suggests for what the owner typed. The people they already share threads
18
+ * with come first: they reveal no one new. With `can.view(project.users)`, any member whose name
19
+ * or email matches follows; without it, the directory is skipped and a typed email still works.
20
+ * Before anything is typed, only those people show.
21
+ */
22
+ export function usePeopleSuggestions(input: {
23
+ readonly text: string
24
+ /** User ids not to suggest: the reader, whoever is in the thread, and whoever is picked. */
25
+ readonly exclude: ReadonlySet<string>
26
+ }) {
27
+ const query = input.text.trim().toLowerCase()
28
+
29
+ // Whether the reader may read the directory, asked once: the field's wording follows it.
30
+ const directory = useQuery({
31
+ ...listUsersOptions({ query: { limit: 1 } }),
32
+ retry: false,
33
+ staleTime: 5 * 60_000,
34
+ })
35
+ const canSearch = directory.isSuccess
36
+ const matches = useQuery({
37
+ ...listUsersOptions({ query: { search: query, limit: SUGGESTIONS } }),
38
+ enabled: canSearch && query.length > 0,
39
+ placeholderData: keepPreviousData,
40
+ staleTime: 30_000,
41
+ })
42
+
43
+ const { threads, sharedThreads } = useAgentThreadLists({})
44
+ const known = useMemo(() => {
45
+ const people = new Map<string, PersonSuggestion>()
46
+ const add = (principal: { readonly type: string; readonly id: string }, name?: string) => {
47
+ if (principal.type !== "user" || people.has(principal.id)) return
48
+ people.set(principal.id, { id: principal.id, name: name ?? principal.id })
49
+ }
50
+ // Newest first, as the lists come: whoever the reader worked with lately leads.
51
+ for (const thread of [...sharedThreads, ...threads].sort(byRecency)) {
52
+ add(thread.ownerPrincipal, thread.owner.displayName)
53
+ for (const participant of thread.participants) {
54
+ add(participant.principal, participant.principal.displayName)
55
+ }
56
+ }
57
+ return [...people.values()]
58
+ }, [threads, sharedThreads])
59
+
60
+ const suggestions = useMemo(() => {
61
+ const picked = new Map<string, PersonSuggestion>()
62
+ const offer = (person: PersonSuggestion) => {
63
+ if (input.exclude.has(person.id) || picked.has(person.id)) return
64
+ picked.set(person.id, person)
65
+ }
66
+
67
+ for (const person of known) {
68
+ if (!query || person.name.toLowerCase().includes(query)) offer(person)
69
+ }
70
+ if (query && canSearch) {
71
+ for (const user of matches.data?.users ?? []) {
72
+ if (user.status !== "active") continue
73
+ const earlier = picked.get(user.id)
74
+ // Someone from a thread keeps their place, and gains the email the directory knows.
75
+ if (earlier) picked.set(user.id, { ...earlier, email: user.email })
76
+ else offer({ id: user.id, name: user.displayName ?? user.email, email: user.email })
77
+ }
78
+ }
79
+ return [...picked.values()].slice(0, SUGGESTIONS)
80
+ }, [known, matches.data, query, canSearch, input.exclude])
81
+
82
+ return { suggestions, canSearch }
83
+ }
84
+
85
+ function byRecency(
86
+ a: { readonly lastMessageAt?: string | null; readonly updatedAt: string },
87
+ b: { readonly lastMessageAt?: string | null; readonly updatedAt: string }
88
+ ): number {
89
+ return (b.lastMessageAt ?? b.updatedAt).localeCompare(a.lastMessageAt ?? a.updatedAt)
90
+ }
@@ -0,0 +1,77 @@
1
+ import { listAgentApprovalsOptions, listAgentThreadsInfiniteOptions } from "@sixb/client/hooks"
2
+ import { useInfiniteQuery, useQuery } from "@tanstack/react-query"
3
+ import { useMemo } from "react"
4
+ import { THREAD_PAGE_SIZE } from "../thread-navigation"
5
+
6
+ const THREAD_LIST_QUERY = {
7
+ limit: String(THREAD_PAGE_SIZE),
8
+ order: "desc" as const,
9
+ }
10
+
11
+ /** The threads others shared with the reader: one page, newest first. */
12
+ const SHARED_THREAD_LIST_QUERY = {
13
+ sharedWithMe: "true" as const,
14
+ limit: String(THREAD_PAGE_SIZE),
15
+ order: "desc" as const,
16
+ }
17
+
18
+ /** The calls waiting for the reader across threads, for the thread list. */
19
+ const PENDING_APPROVALS_QUERY = { status: "pending" as const, limit: "200" }
20
+
21
+ /**
22
+ * The reader's threads, the ones shared with them, and those where a call waits for them: what a
23
+ * thread's header counts and the threads page lists. One read for both, so opening the page from a
24
+ * thread shows what the thread already had.
25
+ */
26
+ export function useAgentThreadLists(options: {
27
+ /** How often to read again while nothing announces changes; off by default. */
28
+ readonly refetchInterval?: number | false
29
+ }) {
30
+ const refetchInterval = options.refetchInterval ?? false
31
+ const threadsQuery = useInfiniteQuery({
32
+ ...listAgentThreadsInfiniteOptions({ query: THREAD_LIST_QUERY }),
33
+ initialPageParam: { query: THREAD_LIST_QUERY },
34
+ getNextPageParam: nextPage(THREAD_LIST_QUERY),
35
+ refetchInterval,
36
+ })
37
+ // Nothing announces a new share or a removal: read the list again when the reader comes back.
38
+ const sharedThreadsQuery = useInfiniteQuery({
39
+ ...listAgentThreadsInfiniteOptions({ query: SHARED_THREAD_LIST_QUERY }),
40
+ initialPageParam: { query: SHARED_THREAD_LIST_QUERY },
41
+ getNextPageParam: nextPage(SHARED_THREAD_LIST_QUERY),
42
+ refetchInterval,
43
+ refetchOnWindowFocus: true,
44
+ })
45
+ const pendingApprovalsQuery = useQuery({
46
+ ...listAgentApprovalsOptions({ query: PENDING_APPROVALS_QUERY }),
47
+ refetchInterval,
48
+ retry: false,
49
+ })
50
+
51
+ const threads = useMemo(
52
+ () => threadsQuery.data?.pages.flatMap((page) => page.threads) ?? [],
53
+ [threadsQuery.data]
54
+ )
55
+ const sharedThreads = useMemo(
56
+ () => sharedThreadsQuery.data?.pages.flatMap((page) => page.threads) ?? [],
57
+ [sharedThreadsQuery.data]
58
+ )
59
+ /** The threads where a call waits for the reader. */
60
+ const waitingThreadIds = useMemo(
61
+ () =>
62
+ new Set(
63
+ (pendingApprovalsQuery.data?.approvals ?? []).map((approval) => approval.threadId)
64
+ ) as ReadonlySet<string>,
65
+ [pendingApprovalsQuery.data]
66
+ )
67
+
68
+ return { threadsQuery, sharedThreadsQuery, threads, sharedThreads, waitingThreadIds }
69
+ }
70
+
71
+ /** The page after those read so far, while the server says there are more. */
72
+ function nextPage<Query extends object>(query: Query) {
73
+ return (lastPage: { readonly hasMore: boolean }, pages: readonly unknown[]) =>
74
+ lastPage.hasMore
75
+ ? { query: { ...query, offset: String(pages.length * THREAD_PAGE_SIZE) } }
76
+ : undefined
77
+ }