@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.
- package/dist/{chunk-vtp6nk44.js → chunk-736c9akn.js} +1 -1
- package/dist/{chunk-1rhht9y0.js → chunk-n0cxwvej.js} +1 -1
- package/dist/{chunk-0yb22w6m.js → chunk-qh1panvd.js} +1 -1
- package/dist/{chunk-aes17xmx.js → chunk-twjs2sb9.js} +3928 -3717
- package/dist/{chunk-aes17xmx.js.map → chunk-twjs2sb9.js.map} +46 -42
- package/dist/index.js +15 -6
- package/dist/index.js.map +6 -6
- package/dist/pages.js +60 -44
- package/dist/pages.js.map +8 -8
- package/dist/server.js +12 -6
- package/dist/server.js.map +3 -3
- package/package.json +3 -3
- package/src/agent/agent-chat.tsx +4 -22
- package/src/agent/agent-panel.tsx +4 -0
- package/src/agent/agent-surface.tsx +4 -0
- package/src/agent/agent.css +33 -3
- package/src/agent/approvals.ts +4 -5
- package/src/agent/artifact-panel.tsx +113 -37
- package/src/agent/components/activity-status.tsx +1 -1
- package/src/agent/components/agent-threads.tsx +377 -0
- package/src/agent/components/approval-card.tsx +336 -327
- package/src/agent/components/approval-mode-chip.tsx +38 -145
- package/src/agent/components/auto-model-chip.tsx +103 -167
- package/src/agent/components/composer-menu.tsx +185 -0
- package/src/agent/components/composer.tsx +38 -43
- package/src/agent/components/context-chips.tsx +1 -1
- package/src/agent/components/conversation-panel.tsx +16 -36
- package/src/agent/components/file-attachment-card.tsx +5 -2
- package/src/agent/components/message-parts.tsx +27 -11
- package/src/agent/components/message-view.tsx +182 -68
- package/src/agent/components/model-controls.tsx +133 -125
- package/src/agent/components/model-picker-row.tsx +38 -17
- package/src/agent/components/participant-input.tsx +159 -31
- package/src/agent/components/reasoning-effort-slider.tsx +27 -27
- package/src/agent/components/shared-thread-notice.tsx +1 -1
- package/src/agent/components/thread-people.tsx +45 -15
- package/src/agent/components/threads-button.tsx +70 -0
- package/src/agent/components/transcript.tsx +30 -1
- package/src/agent/conversation.ts +25 -1
- package/src/agent/delegation/child-card.tsx +187 -247
- package/src/agent/delegation/child-cards.tsx +4 -7
- package/src/agent/delegation/child-group.tsx +179 -98
- package/src/agent/delegation/child-parts.tsx +71 -106
- package/src/agent/delegation/child-work.tsx +6 -52
- package/src/agent/delegation/interpret.ts +0 -28
- package/src/agent/delegation/model.ts +115 -39
- package/src/agent/hooks/use-agent-conversation.ts +7 -92
- package/src/agent/hooks/use-people-suggestions.ts +90 -0
- package/src/agent/hooks/use-thread-lists.ts +77 -0
- package/src/agent/i18n/en.ts +96 -83
- package/src/agent/i18n/fr.ts +105 -100
- package/src/agent/react-router.tsx +48 -5
- package/src/agent/run-presentation.ts +6 -2
- package/src/agent/thread-navigation.ts +16 -0
- package/src/agent/thread-pages.ts +24 -0
- package/src/artifacts/person-avatar.tsx +1 -1
- package/src/createCustomApp.ts +13 -6
- package/src/index.ts +7 -3
- package/src/pages/home.tsx +3 -1
- package/src/pages/observability/ai-usage/calls.tsx +2 -1
- package/src/pages/settings/memory-history.tsx +2 -1
- package/src/pages/settings/messages.ts +2 -3
- package/src/pages/values.tsx +23 -1
- package/src/pages.ts +5 -1
- package/src/shell/agent-dock.tsx +4 -2
- package/src/agent/agents-page.ts +0 -7
- package/src/agent/components/agent-thread-switcher.tsx +0 -519
- /package/dist/{chunk-vtp6nk44.js.map → chunk-736c9akn.js.map} +0 -0
- /package/dist/{chunk-1rhht9y0.js.map → chunk-n0cxwvej.js.map} +0 -0
- /package/dist/{chunk-0yb22w6m.js.map → chunk-qh1panvd.js.map} +0 -0
|
@@ -0,0 +1,377 @@
|
|
|
1
|
+
import {
|
|
2
|
+
getAgentOptions,
|
|
3
|
+
listAgentApprovalsQueryKey,
|
|
4
|
+
listAgentThreadsQueryKey,
|
|
5
|
+
useAgentActivityStream,
|
|
6
|
+
} from "@sixb/client/hooks"
|
|
7
|
+
import { Button } from "@sixb/ui/components"
|
|
8
|
+
import { useLocale } from "@sixb/ui/lib/i18n"
|
|
9
|
+
import { cn } from "@sixb/ui/lib/utils"
|
|
10
|
+
import { useQuery, useQueryClient } from "@tanstack/react-query"
|
|
11
|
+
import { CircleX, Search, SquarePen } from "lucide-react"
|
|
12
|
+
import { type KeyboardEvent, type ReactNode, useMemo, useState } from "react"
|
|
13
|
+
import { PersonAvatar } from "../../artifacts/person-avatar"
|
|
14
|
+
import { useCurrentUser } from "../../session"
|
|
15
|
+
import { formatRelativeTime, groupThreadsByDate } from "../format"
|
|
16
|
+
import { useAgentThreadLists } from "../hooks/use-thread-lists"
|
|
17
|
+
import { useAgentMessages } from "../i18n"
|
|
18
|
+
import { personName, threadOwner } from "../sharing"
|
|
19
|
+
import { agentThreadTitle } from "../thread-navigation"
|
|
20
|
+
import type { AgentThread } from "../types"
|
|
21
|
+
|
|
22
|
+
export interface AgentThreadsProps {
|
|
23
|
+
readonly onSelectThread: (threadId: string) => void
|
|
24
|
+
readonly onNewThread: () => void
|
|
25
|
+
/** Before the title, such as a way back to the app. */
|
|
26
|
+
readonly headerActions?: ReactNode
|
|
27
|
+
readonly className?: string
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
/**
|
|
31
|
+
* Every thread the reader can open, on a page of its own: searched by title, filtered to
|
|
32
|
+
* the ones shared with them or archived, grouped by when they last moved. Those where a call waits
|
|
33
|
+
* for the reader come first.
|
|
34
|
+
*/
|
|
35
|
+
export function AgentThreads({
|
|
36
|
+
onSelectThread,
|
|
37
|
+
onNewThread,
|
|
38
|
+
headerActions,
|
|
39
|
+
className,
|
|
40
|
+
}: AgentThreadsProps) {
|
|
41
|
+
const agentMessages = useAgentMessages()
|
|
42
|
+
const messages = agentMessages.threads
|
|
43
|
+
const user = useCurrentUser()
|
|
44
|
+
const agent = useQuery({ ...getAgentOptions(), retry: false, staleTime: 5 * 60_000 })
|
|
45
|
+
const agentName = agent.data?.name ?? "Agent"
|
|
46
|
+
// A run starting or ending anywhere, and a call held or decided, reach the list through the
|
|
47
|
+
// project's activity feed; poll only while it is away.
|
|
48
|
+
const queryClient = useQueryClient()
|
|
49
|
+
const refreshThreads = () =>
|
|
50
|
+
queryClient.invalidateQueries({ queryKey: listAgentThreadsQueryKey() })
|
|
51
|
+
const refreshWaiting = () =>
|
|
52
|
+
queryClient.invalidateQueries({ queryKey: listAgentApprovalsQueryKey() })
|
|
53
|
+
const activity = useAgentActivityStream({
|
|
54
|
+
onActivity: () => void refreshThreads(),
|
|
55
|
+
onApprovalActivity: () => void refreshWaiting(),
|
|
56
|
+
onSubscribed: () => {
|
|
57
|
+
void refreshThreads()
|
|
58
|
+
void refreshWaiting()
|
|
59
|
+
},
|
|
60
|
+
})
|
|
61
|
+
const { threadsQuery, sharedThreadsQuery, threads, sharedThreads, waitingThreadIds } =
|
|
62
|
+
useAgentThreadLists({
|
|
63
|
+
refetchInterval: !activity.connected || activity.error ? 10_000 : false,
|
|
64
|
+
})
|
|
65
|
+
const [searchTerm, setSearchTerm] = useState("")
|
|
66
|
+
const [filter, setFilter] = useState<"all" | "archived" | "shared">("all")
|
|
67
|
+
const canShare = user !== null
|
|
68
|
+
const sharedTotal = Math.max(sharedThreadsQuery.data?.pages[0]?.total ?? 0, sharedThreads.length)
|
|
69
|
+
|
|
70
|
+
const query = searchTerm.trim().toLowerCase()
|
|
71
|
+
const matching = useMemo(() => {
|
|
72
|
+
const listed =
|
|
73
|
+
filter === "archived"
|
|
74
|
+
? threads.filter((thread) => thread.status === "archived")
|
|
75
|
+
: filter === "shared"
|
|
76
|
+
? sharedThreads
|
|
77
|
+
: threads
|
|
78
|
+
if (!query) return listed
|
|
79
|
+
return listed.filter((thread) =>
|
|
80
|
+
agentThreadTitle(thread, messages).toLowerCase().includes(query)
|
|
81
|
+
)
|
|
82
|
+
}, [filter, query, threads, sharedThreads, messages])
|
|
83
|
+
|
|
84
|
+
// What waits on the reader comes first, theirs and what others shared alike.
|
|
85
|
+
const waiting =
|
|
86
|
+
filter === "archived"
|
|
87
|
+
? []
|
|
88
|
+
: unique([...threads, ...sharedThreads]).filter(
|
|
89
|
+
(thread) =>
|
|
90
|
+
waitingThreadIds.has(thread.id) &&
|
|
91
|
+
(!query || agentThreadTitle(thread, messages).toLowerCase().includes(query))
|
|
92
|
+
)
|
|
93
|
+
const waitingIds = new Set(waiting.map((thread) => thread.id))
|
|
94
|
+
const groups = groupThreadsByDate(matching.filter((thread) => !waitingIds.has(thread.id)))
|
|
95
|
+
const archivedCount = threads.filter((thread) => thread.status === "archived").length
|
|
96
|
+
const sharedIds = new Set(sharedThreads.map((thread) => thread.id))
|
|
97
|
+
// The list shown says its own paging; a failed read of either says so wherever it shows.
|
|
98
|
+
const list = filter === "shared" ? sharedThreadsQuery : threadsQuery
|
|
99
|
+
const errors = [
|
|
100
|
+
filter !== "shared" && threadsQuery.isError ? agentMessages.chat.threadsLoadFailed : null,
|
|
101
|
+
filter !== "archived" && sharedThreadsQuery.isError
|
|
102
|
+
? agentMessages.chat.sharedThreadsLoadFailed
|
|
103
|
+
: null,
|
|
104
|
+
].filter((error): error is string => error !== null)
|
|
105
|
+
const loading = list.isPending
|
|
106
|
+
|
|
107
|
+
return (
|
|
108
|
+
<div className={cn("min-h-0 overflow-y-auto", className)} onKeyDown={moveRowFocus}>
|
|
109
|
+
<div className="mx-auto w-full max-w-[46rem] px-4 pt-6 pb-[max(2rem,env(safe-area-inset-bottom))] sm:px-6 sm:pt-14">
|
|
110
|
+
<header className="flex min-h-11 items-center gap-2">
|
|
111
|
+
{headerActions}
|
|
112
|
+
<h1 className="min-w-0 flex-1 truncate text-[28px] leading-tight font-semibold tracking-[-0.02em] text-foreground">
|
|
113
|
+
{messages.title}
|
|
114
|
+
</h1>
|
|
115
|
+
{/* On a phone the title keeps the room: the button is its icon. */}
|
|
116
|
+
<Button
|
|
117
|
+
type="button"
|
|
118
|
+
onClick={onNewThread}
|
|
119
|
+
aria-label={messages.new}
|
|
120
|
+
className="size-9 gap-1.5 rounded-full p-0 sm:w-auto sm:px-4"
|
|
121
|
+
>
|
|
122
|
+
<SquarePen className="size-4" aria-hidden="true" />
|
|
123
|
+
<span className="max-sm:sr-only">{messages.new}</span>
|
|
124
|
+
</Button>
|
|
125
|
+
</header>
|
|
126
|
+
|
|
127
|
+
<div className="mt-6 flex h-11 items-center gap-2.5 rounded-xl bg-muted/70 px-3.5 text-muted-foreground transition-colors focus-within:bg-muted">
|
|
128
|
+
<Search className="size-4 shrink-0" aria-hidden="true" />
|
|
129
|
+
<input
|
|
130
|
+
autoFocus
|
|
131
|
+
type="search"
|
|
132
|
+
value={searchTerm}
|
|
133
|
+
onChange={(event) => setSearchTerm(event.target.value)}
|
|
134
|
+
placeholder={messages.search}
|
|
135
|
+
aria-label={messages.searchLabel(agentName)}
|
|
136
|
+
className="h-full min-w-0 flex-1 bg-transparent text-[15px] text-foreground outline-none placeholder:text-muted-foreground [&::-webkit-search-cancel-button]:appearance-none"
|
|
137
|
+
/>
|
|
138
|
+
{searchTerm ? (
|
|
139
|
+
<button
|
|
140
|
+
type="button"
|
|
141
|
+
onClick={() => setSearchTerm("")}
|
|
142
|
+
aria-label={messages.clearSearch}
|
|
143
|
+
className="-mr-1.5 flex size-7 items-center justify-center rounded-full outline-none hover:text-foreground focus-visible:ring-2 focus-visible:ring-ring/30"
|
|
144
|
+
>
|
|
145
|
+
<CircleX className="size-4" aria-hidden="true" />
|
|
146
|
+
</button>
|
|
147
|
+
) : null}
|
|
148
|
+
</div>
|
|
149
|
+
|
|
150
|
+
{archivedCount > 0 || canShare ? (
|
|
151
|
+
<div className="mt-3 flex flex-wrap gap-1.5" role="group" aria-label={messages.filter}>
|
|
152
|
+
<Filter
|
|
153
|
+
label={messages.all}
|
|
154
|
+
active={filter === "all"}
|
|
155
|
+
onClick={() => setFilter("all")}
|
|
156
|
+
/>
|
|
157
|
+
{canShare ? (
|
|
158
|
+
<Filter
|
|
159
|
+
label={messages.sharedFilter(sharedTotal)}
|
|
160
|
+
active={filter === "shared"}
|
|
161
|
+
onClick={() => setFilter("shared")}
|
|
162
|
+
/>
|
|
163
|
+
) : null}
|
|
164
|
+
{archivedCount > 0 ? (
|
|
165
|
+
<Filter
|
|
166
|
+
label={messages.archivedFilter(archivedCount)}
|
|
167
|
+
active={filter === "archived"}
|
|
168
|
+
onClick={() => setFilter("archived")}
|
|
169
|
+
/>
|
|
170
|
+
) : null}
|
|
171
|
+
</div>
|
|
172
|
+
) : null}
|
|
173
|
+
|
|
174
|
+
<div className="mt-6">
|
|
175
|
+
{waiting.length > 0 ? (
|
|
176
|
+
<Section label={agentMessages.approvals.threadWaiting} waiting>
|
|
177
|
+
{waiting.map((thread) => (
|
|
178
|
+
<Row
|
|
179
|
+
key={thread.id}
|
|
180
|
+
thread={thread}
|
|
181
|
+
shared={sharedIds.has(thread.id)}
|
|
182
|
+
waiting
|
|
183
|
+
onSelect={onSelectThread}
|
|
184
|
+
/>
|
|
185
|
+
))}
|
|
186
|
+
</Section>
|
|
187
|
+
) : null}
|
|
188
|
+
|
|
189
|
+
{groups.map((group) => (
|
|
190
|
+
<Section key={group.key} label={messages[group.key]}>
|
|
191
|
+
{group.threads.map((thread) => (
|
|
192
|
+
<Row
|
|
193
|
+
key={thread.id}
|
|
194
|
+
thread={thread}
|
|
195
|
+
shared={sharedIds.has(thread.id)}
|
|
196
|
+
waiting={false}
|
|
197
|
+
onSelect={onSelectThread}
|
|
198
|
+
/>
|
|
199
|
+
))}
|
|
200
|
+
</Section>
|
|
201
|
+
))}
|
|
202
|
+
|
|
203
|
+
{errors.map((error) => (
|
|
204
|
+
<p key={error} role="alert" className="px-3 py-2 text-sm text-destructive">
|
|
205
|
+
{error}
|
|
206
|
+
</p>
|
|
207
|
+
))}
|
|
208
|
+
{list.isFetchNextPageError ? (
|
|
209
|
+
<p role="alert" className="px-3 py-2 text-sm text-destructive">
|
|
210
|
+
{messages.loadMoreFailed}
|
|
211
|
+
</p>
|
|
212
|
+
) : null}
|
|
213
|
+
{list.hasNextPage ? (
|
|
214
|
+
<div className="mt-4 flex justify-center">
|
|
215
|
+
<Button
|
|
216
|
+
variant="secondary"
|
|
217
|
+
size="sm"
|
|
218
|
+
className="rounded-full"
|
|
219
|
+
disabled={list.isFetchingNextPage}
|
|
220
|
+
onClick={() => void list.fetchNextPage()}
|
|
221
|
+
>
|
|
222
|
+
{list.isFetchingNextPage ? messages.loading : messages.loadMore}
|
|
223
|
+
</Button>
|
|
224
|
+
</div>
|
|
225
|
+
) : null}
|
|
226
|
+
{!loading && matching.length === 0 && waiting.length === 0 ? (
|
|
227
|
+
<p className="px-3 py-16 text-center text-sm text-muted-foreground">
|
|
228
|
+
{query ? messages.empty : filter === "shared" ? messages.sharedEmpty : messages.none}
|
|
229
|
+
</p>
|
|
230
|
+
) : null}
|
|
231
|
+
</div>
|
|
232
|
+
</div>
|
|
233
|
+
</div>
|
|
234
|
+
)
|
|
235
|
+
}
|
|
236
|
+
|
|
237
|
+
function Filter({
|
|
238
|
+
label,
|
|
239
|
+
active,
|
|
240
|
+
onClick,
|
|
241
|
+
}: {
|
|
242
|
+
readonly label: string
|
|
243
|
+
readonly active: boolean
|
|
244
|
+
readonly onClick: () => void
|
|
245
|
+
}) {
|
|
246
|
+
return (
|
|
247
|
+
<button
|
|
248
|
+
type="button"
|
|
249
|
+
onClick={onClick}
|
|
250
|
+
aria-pressed={active}
|
|
251
|
+
className={cn(
|
|
252
|
+
"h-8 rounded-full px-3 text-[13px] outline-none transition-colors focus-visible:ring-2 focus-visible:ring-ring/30",
|
|
253
|
+
active
|
|
254
|
+
? "bg-foreground text-background"
|
|
255
|
+
: "bg-muted/70 text-muted-foreground hover:text-foreground"
|
|
256
|
+
)}
|
|
257
|
+
>
|
|
258
|
+
{label}
|
|
259
|
+
</button>
|
|
260
|
+
)
|
|
261
|
+
}
|
|
262
|
+
|
|
263
|
+
function Section({
|
|
264
|
+
label,
|
|
265
|
+
waiting = false,
|
|
266
|
+
children,
|
|
267
|
+
}: {
|
|
268
|
+
readonly label: string
|
|
269
|
+
/** The threads waiting for the reader: the heading carries the amber mark. */
|
|
270
|
+
readonly waiting?: boolean
|
|
271
|
+
readonly children: ReactNode
|
|
272
|
+
}) {
|
|
273
|
+
return (
|
|
274
|
+
<section className="mt-6 first:mt-0" aria-label={label}>
|
|
275
|
+
<h2
|
|
276
|
+
className={cn(
|
|
277
|
+
"flex items-center gap-1.5 px-3 pb-1.5 text-[13px]",
|
|
278
|
+
waiting ? "text-amber-700 dark:text-amber-400" : "text-muted-foreground"
|
|
279
|
+
)}
|
|
280
|
+
>
|
|
281
|
+
{waiting ? (
|
|
282
|
+
<span className="size-1.5 rounded-full bg-amber-500" aria-hidden="true" />
|
|
283
|
+
) : null}
|
|
284
|
+
{label}
|
|
285
|
+
</h2>
|
|
286
|
+
<div className="flex flex-col">{children}</div>
|
|
287
|
+
</section>
|
|
288
|
+
)
|
|
289
|
+
}
|
|
290
|
+
|
|
291
|
+
/**
|
|
292
|
+
* One thread: its title, then whether the agent is at work in it, how many messages it holds and
|
|
293
|
+
* whose it is when someone shared it; when it last moved, at the end. Its section says when it
|
|
294
|
+
* waits for the reader.
|
|
295
|
+
*/
|
|
296
|
+
function Row({
|
|
297
|
+
thread,
|
|
298
|
+
shared,
|
|
299
|
+
waiting,
|
|
300
|
+
onSelect,
|
|
301
|
+
}: {
|
|
302
|
+
readonly thread: AgentThread
|
|
303
|
+
/** Someone else's: the row names its owner. */
|
|
304
|
+
readonly shared: boolean
|
|
305
|
+
/** A call in it waits for the reader's approval. */
|
|
306
|
+
readonly waiting: boolean
|
|
307
|
+
readonly onSelect: (threadId: string) => void
|
|
308
|
+
}) {
|
|
309
|
+
const agentMessages = useAgentMessages()
|
|
310
|
+
const messages = agentMessages.threads
|
|
311
|
+
const locale = useLocale()
|
|
312
|
+
const title = agentThreadTitle(thread, messages)
|
|
313
|
+
const when =
|
|
314
|
+
thread.status === "archived"
|
|
315
|
+
? messages.archived
|
|
316
|
+
: formatRelativeTime(thread.lastMessageAt ?? thread.updatedAt, locale, agentMessages.time)
|
|
317
|
+
const owner = shared ? personName(threadOwner(thread)) : null
|
|
318
|
+
const detail = [messages.messageCount(thread.messageCount), owner].filter(Boolean).join(" · ")
|
|
319
|
+
const working = thread.activeRunId !== null
|
|
320
|
+
|
|
321
|
+
return (
|
|
322
|
+
<button
|
|
323
|
+
type="button"
|
|
324
|
+
data-thread-option=""
|
|
325
|
+
onClick={() => onSelect(thread.id)}
|
|
326
|
+
data-thread-working={working ? "" : undefined}
|
|
327
|
+
aria-label={[
|
|
328
|
+
title,
|
|
329
|
+
waiting ? agentMessages.approvals.threadWaiting : working ? messages.working : null,
|
|
330
|
+
detail,
|
|
331
|
+
when,
|
|
332
|
+
]
|
|
333
|
+
.filter(Boolean)
|
|
334
|
+
.join(", ")}
|
|
335
|
+
className="group flex min-h-16 w-full items-center gap-3 rounded-xl px-3 py-2.5 text-left outline-none transition-colors hover:bg-muted/70 focus-visible:bg-muted/70 focus-visible:ring-2 focus-visible:ring-ring/30"
|
|
336
|
+
>
|
|
337
|
+
{owner ? <PersonAvatar name={owner} /> : null}
|
|
338
|
+
<span className="min-w-0 flex-1">
|
|
339
|
+
<span className="block truncate text-[15px] text-foreground">{title}</span>
|
|
340
|
+
<span className="mt-0.5 block truncate text-[13px] text-muted-foreground">
|
|
341
|
+
{working ? (
|
|
342
|
+
<>
|
|
343
|
+
<span className="inline-flex items-center gap-1.5 align-middle">
|
|
344
|
+
<span
|
|
345
|
+
className="size-1.5 rounded-full bg-sky-500 motion-safe:animate-pulse"
|
|
346
|
+
aria-hidden="true"
|
|
347
|
+
/>
|
|
348
|
+
{messages.working}
|
|
349
|
+
</span>
|
|
350
|
+
<span aria-hidden="true"> · </span>
|
|
351
|
+
</>
|
|
352
|
+
) : null}
|
|
353
|
+
{detail}
|
|
354
|
+
</span>
|
|
355
|
+
</span>
|
|
356
|
+
{when ? (
|
|
357
|
+
<span className="shrink-0 text-[13px] text-muted-foreground tabular-nums">{when}</span>
|
|
358
|
+
) : null}
|
|
359
|
+
</button>
|
|
360
|
+
)
|
|
361
|
+
}
|
|
362
|
+
|
|
363
|
+
function unique(threads: readonly AgentThread[]): readonly AgentThread[] {
|
|
364
|
+
return [...new Map(threads.map((thread) => [thread.id, thread])).values()]
|
|
365
|
+
}
|
|
366
|
+
|
|
367
|
+
/** Up and down move between the rows, as in a list. */
|
|
368
|
+
function moveRowFocus(event: KeyboardEvent<HTMLDivElement>) {
|
|
369
|
+
if (event.key !== "ArrowDown" && event.key !== "ArrowUp") return
|
|
370
|
+
const options = [...event.currentTarget.querySelectorAll<HTMLElement>("[data-thread-option]")]
|
|
371
|
+
if (options.length === 0) return
|
|
372
|
+
const index = options.indexOf(document.activeElement as HTMLElement)
|
|
373
|
+
const delta = event.key === "ArrowDown" ? 1 : -1
|
|
374
|
+
const next = index < 0 ? (delta > 0 ? 0 : options.length - 1) : index + delta
|
|
375
|
+
options[(next + options.length) % options.length]?.focus()
|
|
376
|
+
event.preventDefault()
|
|
377
|
+
}
|