@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
@@ -11,6 +11,7 @@ import { useQuery } from "@tanstack/react-query"
11
11
  import { ArrowUpRight, Bot, ChevronRight, GitBranch, Layers, Workflow, Zap } from "lucide-react"
12
12
  import { type ReactNode, useState } from "react"
13
13
  import { Link } from "react-router-dom"
14
+ import { threadPath } from "../../../agent/thread-navigation"
14
15
  import { actionRunHref, workflowRunHref } from "../../routes"
15
16
  import { PageSection, Panel, Pill, type Tone } from "../../section-ui"
16
17
  import { formatMoney } from "./format"
@@ -141,7 +142,7 @@ function groupLabel(group: Group, messages: AiUsageMessages["calls"]): string {
141
142
  function groupHref(group: Group): string | undefined {
142
143
  const source = group.attribution
143
144
  if (source?.kind === "agent") {
144
- return group.canOpenThread ? `/agents/${encodeURIComponent(source.threadId)}` : undefined
145
+ return group.canOpenThread ? threadPath(source.threadId) : undefined
145
146
  }
146
147
  if (source?.kind === "workflowAgent" || source?.kind === "workflow") {
147
148
  return workflowRunHref(source.workflowRunId)
@@ -19,6 +19,7 @@ import { keepPreviousData, useMutation, useQuery, useQueryClient } from "@tansta
19
19
  import { ChevronRight, History, Loader2, MessageSquare, RotateCcw } from "lucide-react"
20
20
  import { useMemo, useState } from "react"
21
21
  import { Link } from "react-router-dom"
22
+ import { threadPathFromLink } from "../../agent/thread-navigation"
22
23
  import { useCurrentUser } from "../../session"
23
24
  import { notify } from "../section-page"
24
25
  import {
@@ -192,7 +193,7 @@ function useChangeOrigin(): (revision: Revision) => {
192
193
  // Someone else's conversation would not open for this person.
193
194
  if (source) {
194
195
  return mine
195
- ? { label: messages.inYourConversation, conversation: source }
196
+ ? { label: messages.inYourConversation, conversation: threadPathFromLink(source) }
196
197
  : { label: messages.inTeammateConversation, conversation: null }
197
198
  }
198
199
  return { label: mine ? messages.editedByYou : messages.editedByTeammate, conversation: null }
@@ -81,7 +81,7 @@ export const en = {
81
81
  approvals: "When the agent changes things",
82
82
  approvalsDescription:
83
83
  "What the agent may do without asking you, in conversations where you haven't chosen a mode. Switch in any conversation from the chip under the message box.",
84
- approvalsShortcut: "Shift+Tab in an empty message switches between Manual and Accept edits.",
84
+ approvalsShortcut: "Shift+Tab in an empty message switches to the next mode.",
85
85
  approvalsSaved: "Saved. Conversations where you haven't chosen a mode use it.",
86
86
  approvalsSaveFailed: "Could not save your choice.",
87
87
  },
@@ -458,8 +458,7 @@ export const fr: Translation<SettingsMessages> = {
458
458
  approvals: "Quand l’agent modifie quelque chose",
459
459
  approvalsDescription:
460
460
  "Ce que l’agent peut faire sans vous demander, dans les conversations où vous n’avez pas choisi de mode. Changez-le dans n’importe quelle conversation depuis le bouton sous la zone de message.",
461
- approvalsShortcut:
462
- "Maj+Tab dans un message vide alterne entre Manuel et Modifications acceptées.",
461
+ approvalsShortcut: "Maj+Tab dans un message vide passe au mode suivant.",
463
462
  approvalsSaved: "Enregistré. Les conversations où vous n’avez pas choisi de mode l’utilisent.",
464
463
  approvalsSaveFailed: "Impossible d’enregistrer votre choix.",
465
464
  },
@@ -23,7 +23,15 @@ import {
23
23
  import { cn } from "@sixb/ui/lib/utils"
24
24
  import { useQuery } from "@tanstack/react-query"
25
25
  import { Box, Download, Eye, FileIcon, UserRound } from "lucide-react"
26
- import { type ReactNode, useLayoutEffect, useMemo, useRef, useState } from "react"
26
+ import {
27
+ createContext,
28
+ type ReactNode,
29
+ useContext,
30
+ useLayoutEffect,
31
+ useMemo,
32
+ useRef,
33
+ useState,
34
+ } from "react"
27
35
  import { Link } from "react-router-dom"
28
36
  import { objectHref } from "./routes"
29
37
  import { CopyButton } from "./section-ui"
@@ -503,6 +511,12 @@ function Field({
503
511
  )
504
512
  }
505
513
 
514
+ /**
515
+ * Whether an object reference links to its page. A view many people read, such as an agent's
516
+ * approval card, names the object without sending its readers to the page.
517
+ */
518
+ export const ObjectRefLinksContext = createContext(true)
519
+
506
520
  function Leaf({
507
521
  value,
508
522
  position,
@@ -515,8 +529,16 @@ function Leaf({
515
529
  readonly path: readonly string[]
516
530
  }) {
517
531
  const locale = useLocale()
532
+ const objectLinks = useContext(ObjectRefLinksContext)
518
533
  if (position.objectRef) {
519
534
  const { objectTypeId, primaryId } = position.objectRef
535
+ if (!objectLinks) {
536
+ return (
537
+ <span className="break-words">
538
+ {objectTypeId} <span className="text-muted-foreground">{primaryId}</span>
539
+ </span>
540
+ )
541
+ }
520
542
  return (
521
543
  <Link
522
544
  to={objectHref(objectTypeId, primaryId)}
package/src/pages.ts CHANGED
@@ -7,7 +7,11 @@
7
7
  * then keeps the whole graph of a module imported here for its own code: every app with a layout
8
8
  * would bundle every page.
9
9
  */
10
- export { AgentsPage } from "./agent/agents-page"
10
+ export {
11
+ AgentThreadRedirect,
12
+ ThreadPage,
13
+ ThreadsPage,
14
+ } from "./agent/thread-pages"
11
15
  export { AgentToolViewsProvider } from "./agent/tool-views/registry"
12
16
  export { ArtifactPage } from "./artifacts/artifact-page"
13
17
  export { ArtifactsPage } from "./artifacts/gallery"
@@ -2,6 +2,7 @@ import { getAgentOptions } from "@sixb/client/hooks"
2
2
  import { useQuery } from "@tanstack/react-query"
3
3
  import { useLocation, useNavigate } from "react-router-dom"
4
4
  import { AgentSurface } from "../agent/agent-surface"
5
+ import { THREADS_PATH, threadPath } from "../agent/thread-navigation"
5
6
  import { useAppMessages } from "../locale"
6
7
  import { useSectionsEnabled } from "../sections/sections"
7
8
 
@@ -17,7 +18,7 @@ export function AgentDock() {
17
18
  const enabled = useSectionsEnabled()
18
19
  const agent = useQuery({ ...getAgentOptions(), enabled, retry: false, staleTime: 5 * 60_000 })
19
20
  const conversationPage =
20
- pathname === "/" || pathname === "/agents" || pathname.startsWith("/agents/")
21
+ pathname === "/" || pathname === THREADS_PATH || pathname.startsWith(`${THREADS_PATH}/`)
21
22
  if (!enabled || !agent.data || conversationPage) return null
22
23
 
23
24
  return (
@@ -25,7 +26,8 @@ export function AgentDock() {
25
26
  title={messages.title}
26
27
  launcherLabel={messages.open}
27
28
  defaultMode="collapsed"
28
- onExpandThread={(threadId) => navigate(`/agents/${encodeURIComponent(threadId)}`)}
29
+ onExpandThread={(threadId) => navigate(threadPath(threadId))}
30
+ onOpenThreads={() => navigate(THREADS_PATH)}
29
31
  persistenceKey="sixb.app.agent-dock.v1"
30
32
  />
31
33
  )
@@ -1,7 +0,0 @@
1
- import { createElement } from "react"
2
- import { AgentChatPage, type AgentChatPageProps } from "./react-router"
3
-
4
- /** The framework's `/agents` routes: the project's conversations, full page. */
5
- export function AgentsPage(props: Omit<AgentChatPageProps, "routeBase">) {
6
- return createElement(AgentChatPage, { ...props, routeBase: "/agents" })
7
- }
@@ -1,519 +0,0 @@
1
- import {
2
- Button,
3
- Dialog,
4
- DialogClose,
5
- DialogContent,
6
- DialogDescription,
7
- DialogTitle,
8
- DialogTrigger,
9
- } from "@sixb/ui/components"
10
- import { useLocale } from "@sixb/ui/lib/i18n"
11
- import { cn } from "@sixb/ui/lib/utils"
12
- import { CirclePause, History, LoaderCircle, Plus, Search, X } from "lucide-react"
13
- import { type KeyboardEvent, type ReactNode, useMemo, useState } from "react"
14
- import { PersonAvatar } from "../../artifacts/person-avatar"
15
- import { formatRelativeTime, groupThreadsByDate } from "../format"
16
- import { useAgentMessages } from "../i18n"
17
- import { personName, threadOwner } from "../sharing"
18
- import { agentThreadTitle } from "../thread-navigation"
19
- import type { AgentThread } from "../types"
20
-
21
- /** The conversations other people shared with the reader, paged like their own. */
22
- export interface SharedThreadList {
23
- readonly threads: readonly AgentThread[]
24
- /** All of them, beyond the pages read so far. */
25
- readonly total: number
26
- readonly error?: string | null
27
- readonly hasMore?: boolean
28
- readonly loadingMore?: boolean
29
- readonly loadMoreError?: boolean
30
- readonly onLoadMore?: () => void
31
- }
32
-
33
- const NO_SHARED_THREADS: SharedThreadList = { threads: [], total: 0 }
34
- const NO_WAITING_THREADS: ReadonlySet<string> = new Set()
35
-
36
- export interface AgentThreadSwitcherProps {
37
- readonly agentName: string
38
- readonly currentThread: AgentThread | null
39
- readonly threads: readonly AgentThread[]
40
- /**
41
- * Conversations other people shared with the reader, listed apart from their own. Omitted
42
- * where nothing can be shared, without a signed-in user.
43
- */
44
- readonly sharedThreads?: SharedThreadList
45
- readonly runningThreadCount?: number
46
- /**
47
- * The threads where a call waits for the reader's approval: they open the list, each row says so,
48
- * and the button counts them.
49
- */
50
- readonly waitingThreadIds?: ReadonlySet<string>
51
- readonly threadsError?: string | null
52
- readonly hasMoreThreads?: boolean
53
- readonly loadingMoreThreads?: boolean
54
- readonly loadMoreThreadsError?: boolean
55
- readonly onLoadMoreThreads?: () => void
56
- readonly onSelectThread: (threadId: string) => void
57
- readonly onNewThread?: () => void
58
- }
59
-
60
- export function AgentThreadSwitcher({
61
- agentName,
62
- currentThread,
63
- threads,
64
- sharedThreads,
65
- runningThreadCount = 0,
66
- waitingThreadIds = NO_WAITING_THREADS,
67
- threadsError,
68
- hasMoreThreads,
69
- loadingMoreThreads,
70
- loadMoreThreadsError,
71
- onLoadMoreThreads,
72
- onSelectThread,
73
- onNewThread,
74
- }: AgentThreadSwitcherProps) {
75
- const agentMessages = useAgentMessages()
76
- const messages = agentMessages.threads
77
- const approvalMessages = agentMessages.approvals
78
- const shared = sharedThreads ?? NO_SHARED_THREADS
79
- const canShare = sharedThreads !== undefined
80
- const [open, setOpen] = useState(false)
81
- const [searchTerm, setSearchTerm] = useState("")
82
- const [filter, setFilter] = useState<"all" | "archived" | "shared">("all")
83
- const [snapshot, setSnapshot] = useState<{
84
- readonly own: readonly string[]
85
- readonly shared: readonly string[]
86
- }>({ own: [], shared: [] })
87
- const allThreads = useMemo(() => uniqueThreads(currentThread, threads), [currentThread, threads])
88
-
89
- // While open, rows keep the order they had when it opened, whatever activity moves meanwhile.
90
- const shownThreads = open ? inSnapshotOrder(allThreads, snapshot.own) : allThreads
91
- const shownShared = open ? inSnapshotOrder(shared.threads, snapshot.shared) : shared.threads
92
- const normalizedSearchTerm = searchTerm.trim().toLowerCase()
93
- const matchingThreads = useMemo(() => {
94
- const byState =
95
- filter === "archived"
96
- ? shownThreads.filter((thread) => thread.status === "archived")
97
- : filter === "shared"
98
- ? shownShared
99
- : shownThreads
100
- if (!normalizedSearchTerm) return byState
101
- return byState.filter((thread) =>
102
- agentThreadTitle(thread, messages).toLowerCase().includes(normalizedSearchTerm)
103
- )
104
- }, [filter, normalizedSearchTerm, shownThreads, shownShared, messages])
105
- const matchingIds = new Set(matchingThreads.map((thread) => thread.id))
106
- const currentVisible = currentThread && matchingIds.has(currentThread.id) ? currentThread : null
107
- // Waiting threads open the list, the reader's own and those shared with them alike.
108
- const waitingRows =
109
- filter === "archived"
110
- ? []
111
- : uniqueThreads(null, [...shownThreads, ...shownShared]).filter(
112
- (thread) =>
113
- waitingThreadIds.has(thread.id) &&
114
- thread.id !== currentVisible?.id &&
115
- (!normalizedSearchTerm ||
116
- agentThreadTitle(thread, messages).toLowerCase().includes(normalizedSearchTerm))
117
- )
118
- const waitingRowIds = new Set(waitingRows.map((thread) => thread.id))
119
- const groups = groupThreadsByDate(
120
- matchingThreads.filter(
121
- (thread) => thread.id !== currentVisible?.id && !waitingRowIds.has(thread.id)
122
- )
123
- )
124
- const archivedCount = shownThreads.filter((thread) => thread.status === "archived").length
125
- const currentTitle = agentThreadTitle(currentThread, messages)
126
- // The open conversation shows its own cards: the button counts the others that wait.
127
- const waitingElsewhere = [...waitingThreadIds].filter(
128
- (threadId) => threadId !== currentThread?.id
129
- ).length
130
- const waitingLabel =
131
- waitingElsewhere > 0 ? approvalMessages.waitingThreads(waitingElsewhere) : null
132
- const historyLabel = [
133
- runningThreadCount > 0
134
- ? messages.runningHistory(runningThreadCount, currentTitle)
135
- : messages.historyCurrent(currentTitle),
136
- waitingLabel,
137
- ]
138
- .filter(Boolean)
139
- .join(". ")
140
-
141
- // The list shown says its own errors and pages.
142
- const list =
143
- filter === "shared"
144
- ? {
145
- error: null,
146
- loadMoreError: shared.loadMoreError,
147
- hasMore: shared.hasMore,
148
- loadingMore: shared.loadingMore,
149
- onLoadMore: shared.onLoadMore,
150
- }
151
- : {
152
- error: threadsError,
153
- loadMoreError: loadMoreThreadsError,
154
- hasMore: hasMoreThreads,
155
- loadingMore: loadingMoreThreads,
156
- onLoadMore: onLoadMoreThreads,
157
- }
158
-
159
- function updateOpen(nextOpen: boolean) {
160
- setOpen(nextOpen)
161
- if (nextOpen) {
162
- setSnapshot({
163
- own: allThreads.map((thread) => thread.id),
164
- shared: shared.threads.map((thread) => thread.id),
165
- })
166
- } else {
167
- setSearchTerm("")
168
- setFilter("all")
169
- }
170
- }
171
-
172
- function selectThread(threadId: string) {
173
- updateOpen(false)
174
- onSelectThread(threadId)
175
- }
176
-
177
- function startThread() {
178
- updateOpen(false)
179
- onNewThread?.()
180
- }
181
-
182
- return (
183
- <Dialog open={open} onOpenChange={updateOpen}>
184
- <DialogTrigger asChild>
185
- <Button
186
- type="button"
187
- variant="ghost"
188
- size="icon-lg"
189
- aria-label={historyLabel}
190
- title={
191
- waitingLabel ??
192
- (runningThreadCount > 0 ? messages.running(runningThreadCount) : messages.history)
193
- }
194
- className="relative [&_svg]:size-5"
195
- >
196
- {waitingElsewhere > 0 ? (
197
- // Beside a running count, a dot: the spinner keeps its own number readable.
198
- <span
199
- data-waiting-approval-count={waitingElsewhere}
200
- aria-hidden="true"
201
- className={cn(
202
- "absolute rounded-full bg-amber-500 ring-2 ring-background",
203
- runningThreadCount > 0
204
- ? "top-1.5 right-1.5 size-2.5"
205
- : "top-1 right-1 flex h-4 min-w-4 items-center justify-center px-1 text-[9px] font-semibold leading-none text-white tabular-nums"
206
- )}
207
- >
208
- {runningThreadCount > 0 ? null : waitingElsewhere > 9 ? "9+" : waitingElsewhere}
209
- </span>
210
- ) : null}
211
- {runningThreadCount > 0 ? (
212
- <span
213
- data-active-thread-count={runningThreadCount}
214
- aria-hidden="true"
215
- className="relative grid size-5 shrink-0 place-items-center"
216
- >
217
- <LoaderCircle className="absolute inset-0 size-5 animate-spin [animation-duration:1.4s] motion-reduce:animate-none" />
218
- <span className="text-[8px] font-semibold leading-none tabular-nums">
219
- {runningThreadCount > 99 ? "99+" : runningThreadCount}
220
- </span>
221
- </span>
222
- ) : (
223
- <History />
224
- )}
225
- </Button>
226
- </DialogTrigger>
227
- <DialogContent
228
- showCloseButton={false}
229
- onKeyDown={moveThreadFocus}
230
- className="top-0 left-0 flex h-dvh w-screen max-w-none translate-x-0 translate-y-0 flex-col gap-0 overflow-hidden rounded-none border-0 p-0 sm:top-[50%] sm:left-[50%] sm:h-auto sm:max-h-[calc(100dvh-2rem)] sm:w-[min(calc(100vw-2rem),40rem)] sm:max-w-[40rem] sm:translate-x-[-50%] sm:translate-y-[-50%] sm:rounded-2xl sm:border"
231
- >
232
- <DialogDescription className="sr-only">{messages.description(agentName)}</DialogDescription>
233
-
234
- <div className="flex h-16 shrink-0 items-center gap-3 px-4 sm:px-5">
235
- <DialogTitle className="text-lg">{messages.title}</DialogTitle>
236
- {onNewThread ? (
237
- <Button type="button" size="sm" className="ml-auto gap-1.5" onClick={startThread}>
238
- <Plus />
239
- {messages.new}
240
- </Button>
241
- ) : null}
242
- <DialogClose asChild>
243
- <Button
244
- type="button"
245
- variant="ghost"
246
- size="icon-sm"
247
- aria-label={messages.close}
248
- className={cn(
249
- !onNewThread && "ml-auto",
250
- "text-muted-foreground hover:text-foreground"
251
- )}
252
- >
253
- <X />
254
- </Button>
255
- </DialogClose>
256
- </div>
257
-
258
- <div className="shrink-0 border-border/60 border-b px-4 pb-3 sm:px-5">
259
- <div className="flex h-10 items-center gap-2.5 rounded-lg border border-input bg-muted/20 px-3 text-muted-foreground transition-colors focus-within:border-foreground/25 focus-within:bg-background">
260
- <Search className="size-4 shrink-0" aria-hidden="true" />
261
- <input
262
- autoFocus
263
- value={searchTerm}
264
- onChange={(event) => setSearchTerm(event.target.value)}
265
- placeholder={messages.search}
266
- aria-label={messages.searchLabel(agentName)}
267
- className="h-full min-w-0 flex-1 bg-transparent text-sm text-foreground outline-none placeholder:text-muted-foreground"
268
- />
269
- </div>
270
- {archivedCount > 0 || canShare ? (
271
- <div className="mt-2.5 flex flex-wrap gap-1.5" aria-label={messages.filter}>
272
- <FilterButton
273
- label={messages.all}
274
- active={filter === "all"}
275
- onClick={() => setFilter("all")}
276
- />
277
- {canShare ? (
278
- <FilterButton
279
- label={messages.sharedFilter(Math.max(shared.total, shared.threads.length))}
280
- active={filter === "shared"}
281
- onClick={() => setFilter("shared")}
282
- />
283
- ) : null}
284
- {archivedCount > 0 ? (
285
- <FilterButton
286
- label={messages.archivedFilter(archivedCount)}
287
- active={filter === "archived"}
288
- onClick={() => setFilter("archived")}
289
- />
290
- ) : null}
291
- </div>
292
- ) : null}
293
- </div>
294
-
295
- <div className="min-h-0 flex-1 overflow-y-auto px-3 pt-3 pb-[max(1rem,env(safe-area-inset-bottom))] sm:max-h-[min(68dvh,36rem)] sm:flex-none sm:px-4 sm:pb-4">
296
- {currentVisible ? (
297
- <ThreadSwitcherSection label={messages.current}>
298
- <ThreadSwitcherRow
299
- thread={currentVisible}
300
- selected
301
- shared={filter === "shared"}
302
- waiting={waitingThreadIds.has(currentVisible.id)}
303
- onSelect={selectThread}
304
- />
305
- </ThreadSwitcherSection>
306
- ) : null}
307
-
308
- {waitingRows.length > 0 ? (
309
- <ThreadSwitcherSection label={approvalMessages.threadWaiting}>
310
- {waitingRows.map((thread) => (
311
- <ThreadSwitcherRow
312
- key={thread.id}
313
- thread={thread}
314
- selected={false}
315
- shared={!threads.some((own) => own.id === thread.id)}
316
- waiting
317
- onSelect={selectThread}
318
- />
319
- ))}
320
- </ThreadSwitcherSection>
321
- ) : null}
322
-
323
- {groups.map((group) => (
324
- <ThreadSwitcherSection key={group.key} label={messages[group.key]}>
325
- {group.threads.map((thread) => (
326
- <ThreadSwitcherRow
327
- key={thread.id}
328
- thread={thread}
329
- selected={thread.id === currentThread?.id}
330
- shared={filter === "shared"}
331
- waiting={waitingThreadIds.has(thread.id)}
332
- onSelect={selectThread}
333
- />
334
- ))}
335
- </ThreadSwitcherSection>
336
- ))}
337
-
338
- {list.error ? (
339
- <p role="alert" className="px-3 py-2 text-sm text-destructive">
340
- {list.error}
341
- </p>
342
- ) : null}
343
- {shared.error && filter !== "archived" ? (
344
- <p role="alert" className="px-3 py-2 text-sm text-destructive">
345
- {shared.error}
346
- </p>
347
- ) : null}
348
- {list.loadMoreError ? (
349
- <p role="alert" className="px-3 py-2 text-sm text-destructive">
350
- {messages.loadMoreFailed}
351
- </p>
352
- ) : null}
353
- {list.hasMore && list.onLoadMore ? (
354
- <Button
355
- variant="outline"
356
- size="sm"
357
- disabled={list.loadingMore}
358
- onClick={list.onLoadMore}
359
- >
360
- {list.loadingMore ? messages.loading : messages.loadMore}
361
- </Button>
362
- ) : null}
363
- {matchingThreads.length === 0 ? (
364
- <p className="px-3 py-10 text-center text-sm text-muted-foreground">
365
- {filter === "shared" && !normalizedSearchTerm ? messages.sharedEmpty : messages.empty}
366
- </p>
367
- ) : null}
368
- </div>
369
- </DialogContent>
370
- </Dialog>
371
- )
372
- }
373
-
374
- function FilterButton({
375
- label,
376
- active,
377
- onClick,
378
- }: {
379
- label: string
380
- active: boolean
381
- onClick: () => void
382
- }) {
383
- return (
384
- <button
385
- type="button"
386
- onClick={onClick}
387
- aria-pressed={active}
388
- className={cn(
389
- "h-7 rounded-full px-2.5 text-xs font-medium outline-none transition-colors focus-visible:ring-2 focus-visible:ring-ring/30",
390
- active
391
- ? "bg-foreground text-background"
392
- : "bg-muted/70 text-muted-foreground hover:text-foreground"
393
- )}
394
- >
395
- {label}
396
- </button>
397
- )
398
- }
399
-
400
- function ThreadSwitcherSection({ label, children }: { label: string; children: ReactNode }) {
401
- return (
402
- <section className="mt-4 first:mt-0" aria-label={label}>
403
- <p className="px-2 pb-1 text-[10px] font-semibold uppercase tracking-wider text-muted-foreground/80">
404
- {label}
405
- </p>
406
- <div className="space-y-0.5">{children}</div>
407
- </section>
408
- )
409
- }
410
-
411
- function ThreadSwitcherRow({
412
- thread,
413
- selected,
414
- shared = false,
415
- waiting = false,
416
- onSelect,
417
- }: {
418
- thread: AgentThread
419
- selected: boolean
420
- /** Someone else's conversation: the row names its owner. */
421
- shared?: boolean
422
- /** A call in it waits for the reader's approval. */
423
- waiting?: boolean
424
- onSelect: (threadId: string) => void
425
- }) {
426
- const agentMessages = useAgentMessages()
427
- const messages = agentMessages.threads
428
- const locale = useLocale()
429
- const title = agentThreadTitle(thread, messages)
430
- const relativeTime = formatRelativeTime(
431
- thread.lastMessageAt ?? thread.updatedAt,
432
- locale,
433
- agentMessages.time
434
- )
435
- const meta = thread.status === "archived" ? messages.archived : relativeTime
436
- const owner = personName(threadOwner(thread))
437
-
438
- return (
439
- <button
440
- type="button"
441
- data-thread-option=""
442
- onClick={() => onSelect(thread.id)}
443
- aria-current={selected ? "page" : undefined}
444
- aria-label={[
445
- title,
446
- selected ? messages.currentState : null,
447
- waiting ? agentMessages.approvals.threadWaiting : null,
448
- meta || null,
449
- ]
450
- .filter(Boolean)
451
- .join(", ")}
452
- className={cn(
453
- "group flex min-h-14 w-full items-center rounded-xl px-4 py-2.5 text-left outline-none transition-colors hover:bg-muted focus-visible:bg-muted focus-visible:ring-2 focus-visible:ring-ring/30",
454
- selected && "bg-muted/70"
455
- )}
456
- >
457
- {shared ? <PersonAvatar name={owner} className="mr-3" /> : null}
458
- <span className="min-w-0 flex-1">
459
- <span className="block truncate text-sm font-medium text-foreground">{title}</span>
460
- <span className="mt-0.5 block truncate text-[11px] text-muted-foreground">
461
- {waiting ? (
462
- <span className="mr-1 inline-flex items-center gap-1 font-medium text-amber-700 dark:text-amber-400">
463
- <CirclePause className="size-3" aria-hidden="true" />
464
- {agentMessages.approvals.threadWaiting}
465
- <span className="font-normal text-muted-foreground">·</span>
466
- </span>
467
- ) : null}
468
- {shared
469
- ? messages.sharedBy(owner, thread.messageCount)
470
- : messages.messages(thread.messageCount)}
471
- </span>
472
- </span>
473
- {meta ? (
474
- <span className="flex shrink-0 items-center gap-1.5 text-[11px] tabular-nums text-muted-foreground">
475
- {meta}
476
- </span>
477
- ) : null}
478
- </button>
479
- )
480
- }
481
-
482
- /** Threads in the order of a snapshot of their ids, with any new ones after it. */
483
- function inSnapshotOrder(
484
- threads: readonly AgentThread[],
485
- snapshot: readonly string[]
486
- ): readonly AgentThread[] {
487
- const byId = new Map(threads.map((thread) => [thread.id, thread]))
488
- const known = new Set(snapshot)
489
-
490
- return [
491
- ...snapshot.flatMap((threadId) => {
492
- const thread = byId.get(threadId)
493
- return thread ? [thread] : []
494
- }),
495
- ...threads.filter((thread) => !known.has(thread.id)),
496
- ]
497
- }
498
-
499
- function uniqueThreads(
500
- currentThread: AgentThread | null,
501
- threads: readonly AgentThread[]
502
- ): readonly AgentThread[] {
503
- const byId = new Map<string, AgentThread>()
504
- for (const thread of threads) byId.set(thread.id, thread)
505
- if (currentThread) byId.set(currentThread.id, currentThread)
506
- return [...byId.values()]
507
- }
508
-
509
- function moveThreadFocus(event: KeyboardEvent<HTMLDivElement>) {
510
- if (event.key !== "ArrowDown" && event.key !== "ArrowUp") return
511
- if (event.target instanceof HTMLInputElement) return
512
- const options = [...event.currentTarget.querySelectorAll<HTMLElement>("[data-thread-option]")]
513
- if (options.length === 0) return
514
- const currentIndex = options.indexOf(document.activeElement as HTMLElement)
515
- const delta = event.key === "ArrowDown" ? 1 : -1
516
- const nextIndex = currentIndex < 0 ? (delta > 0 ? 0 : options.length - 1) : currentIndex + delta
517
- options[(nextIndex + options.length) % options.length]?.focus()
518
- event.preventDefault()
519
- }