@tangle-network/agent-app 0.60.234 → 0.60.235

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.
@@ -1,749 +0,0 @@
1
- import {
2
- ActionDialog,
3
- ActionDialogButton
4
- } from "./chunk-A2GG4D4A.js";
5
- import {
6
- UNTITLED_SESSION_LABEL,
7
- mergeSessionPages,
8
- sessionLabel
9
- } from "./chunk-SJWIZT7B.js";
10
- import {
11
- OVERLAY_SHADOW,
12
- PopoverSurface,
13
- usePopover
14
- } from "./chunk-XIN7DOAB.js";
15
-
16
- // src/web-react/session-history.tsx
17
- import {
18
- useCallback,
19
- useEffect,
20
- useId,
21
- useMemo,
22
- useRef,
23
- useState
24
- } from "react";
25
- import { Button, Checkbox, Input, Select, SelectContent, SelectItem, SelectTrigger, SelectValue } from "@tangle-network/ui/primitives";
26
- import { ShellHeader } from "@tangle-network/sandbox-ui/workspace";
27
- import { Fragment, jsx, jsxs } from "react/jsx-runtime";
28
- function rethrowAsync(error) {
29
- queueMicrotask(() => {
30
- throw error;
31
- });
32
- }
33
- function useInfiniteScroll(onLoadMore, { enabled, root, rootMargin = "300px" }) {
34
- const [sentinel, setSentinel] = useState(null);
35
- const sentinelRef = useCallback((node) => setSentinel(node), []);
36
- const onLoadMoreRef = useRef(onLoadMore);
37
- useEffect(() => {
38
- onLoadMoreRef.current = onLoadMore;
39
- }, [onLoadMore]);
40
- useEffect(() => {
41
- if (!sentinel || !enabled) return;
42
- if (typeof IntersectionObserver === "undefined") return;
43
- const observer = new IntersectionObserver(
44
- (entries) => {
45
- if (!entries.some((entry) => entry.isIntersecting)) return;
46
- try {
47
- onLoadMoreRef.current();
48
- } catch (error) {
49
- rethrowAsync(error);
50
- }
51
- },
52
- { root: root?.current ?? null, rootMargin }
53
- );
54
- observer.observe(sentinel);
55
- return () => observer.disconnect();
56
- }, [sentinel, enabled, root, rootMargin]);
57
- return sentinelRef;
58
- }
59
- function seedSignature(page) {
60
- return JSON.stringify({
61
- nextCursor: page.nextCursor ?? null,
62
- items: page.items.map((item) => ({
63
- id: item.id,
64
- title: item.title,
65
- updatedAt: item.updatedAt,
66
- isPinned: Boolean(item.isPinned),
67
- unread: Boolean(item.unread),
68
- category: item.category ?? null
69
- }))
70
- });
71
- }
72
- function useSessionHistory({
73
- fetchPage,
74
- q,
75
- sort,
76
- initialPage,
77
- defaultSort = "newest"
78
- }) {
79
- const [items, setItems] = useState(initialPage.items);
80
- const [nextCursor, setNextCursor] = useState(initialPage.nextCursor ?? null);
81
- const [phase, setPhase] = useState("idle");
82
- const [reloadKey, setReloadKey] = useState(0);
83
- const seqRef = useRef(0);
84
- const resetAbortRef = useRef(null);
85
- const loadMoreAbortRef = useRef(null);
86
- const loadingMoreRef = useRef(false);
87
- const lastOpRef = useRef("first");
88
- const nextCursorRef = useRef(nextCursor);
89
- nextCursorRef.current = nextCursor;
90
- const viewRef = useRef({ q, sort, fetchPage });
91
- viewRef.current = { q, sort, fetchPage };
92
- const seedRef = useRef(initialPage);
93
- seedRef.current = initialPage;
94
- const isDefaultView = q === "" && sort === defaultSort;
95
- const seedKey = useMemo(() => seedSignature(initialPage), [initialPage]);
96
- useEffect(() => {
97
- resetAbortRef.current?.abort();
98
- loadMoreAbortRef.current?.abort();
99
- loadingMoreRef.current = false;
100
- const seq = ++seqRef.current;
101
- if (isDefaultView && reloadKey === 0) {
102
- setItems(seedRef.current.items);
103
- setNextCursor(seedRef.current.nextCursor ?? null);
104
- setPhase("idle");
105
- return;
106
- }
107
- const controller = new AbortController();
108
- resetAbortRef.current = controller;
109
- lastOpRef.current = "first";
110
- setItems([]);
111
- setNextCursor(null);
112
- setPhase("loadingFirst");
113
- void (async () => {
114
- try {
115
- const page = await viewRef.current.fetchPage({ q, sort, cursor: null, signal: controller.signal });
116
- if (seq !== seqRef.current) return;
117
- setItems(page.items);
118
- setNextCursor(page.nextCursor ?? null);
119
- setPhase("idle");
120
- } catch {
121
- if (controller.signal.aborted || seq !== seqRef.current) return;
122
- setPhase("error");
123
- }
124
- })();
125
- return () => controller.abort();
126
- }, [q, sort, seedKey, isDefaultView, reloadKey]);
127
- const loadMore = useCallback(() => {
128
- const cursor = nextCursorRef.current;
129
- if (!cursor || loadingMoreRef.current) return;
130
- const { q: currentQ, sort: currentSort, fetchPage: currentFetch } = viewRef.current;
131
- const seq = seqRef.current;
132
- loadingMoreRef.current = true;
133
- lastOpRef.current = "more";
134
- const controller = new AbortController();
135
- loadMoreAbortRef.current = controller;
136
- setPhase("loadingMore");
137
- void (async () => {
138
- try {
139
- const page = await currentFetch({ q: currentQ, sort: currentSort, cursor, signal: controller.signal });
140
- if (seq !== seqRef.current) return;
141
- setItems((prev) => mergeSessionPages(prev, page.items));
142
- setNextCursor(page.nextCursor ?? null);
143
- setPhase("idle");
144
- } catch {
145
- if (controller.signal.aborted || seq !== seqRef.current) return;
146
- setPhase("error");
147
- } finally {
148
- if (seq === seqRef.current) loadingMoreRef.current = false;
149
- }
150
- })();
151
- }, []);
152
- const retry = useCallback(() => {
153
- if (lastOpRef.current === "more") loadMore();
154
- else setReloadKey((key) => key + 1);
155
- }, [loadMore]);
156
- const reload = useCallback(() => {
157
- setReloadKey((key) => key + 1);
158
- }, []);
159
- useEffect(
160
- () => () => {
161
- resetAbortRef.current?.abort();
162
- loadMoreAbortRef.current?.abort();
163
- },
164
- []
165
- );
166
- return {
167
- items,
168
- hasMore: nextCursor !== null,
169
- isLoadingFirst: phase === "loadingFirst",
170
- isLoadingMore: phase === "loadingMore",
171
- isError: phase === "error",
172
- loadMore,
173
- retry,
174
- reload
175
- };
176
- }
177
- var DEFAULT_LABELS = {
178
- renameTitle: "Rename session",
179
- renameField: "Title",
180
- renameSubmit: "Save",
181
- deleteTitle: "Delete session?",
182
- deleteBody: (title) => `This will permanently delete \u201C${title}\u201D and its messages. This cannot be undone.`,
183
- deleteSubmit: "Delete",
184
- cancel: "Cancel",
185
- renamed: "Session renamed",
186
- deleted: "Session deleted",
187
- renameFailed: "Failed to rename session",
188
- deleteFailed: "Failed to delete session"
189
- };
190
- function useSessionActions({
191
- renameSession,
192
- deleteSession,
193
- onChanged,
194
- onDeletedCurrent,
195
- currentSessionId,
196
- notify,
197
- labels
198
- }) {
199
- const text = { ...DEFAULT_LABELS, ...labels };
200
- const [renameTarget, setRenameTarget] = useState(null);
201
- const [renameValue, setRenameValue] = useState("");
202
- const [deleteTarget, setDeleteTarget] = useState(null);
203
- const [busy, setBusy] = useState(false);
204
- const [error, setError] = useState(null);
205
- const openRename = useCallback((session) => {
206
- setError(null);
207
- setRenameTarget(session);
208
- setRenameValue(session.title ?? "");
209
- }, []);
210
- const openDelete = useCallback((session) => {
211
- setError(null);
212
- setDeleteTarget(session);
213
- }, []);
214
- const submitRename = useCallback(async () => {
215
- if (!renameTarget) return;
216
- const title = renameValue.trim();
217
- if (!title || title === renameTarget.title) {
218
- setRenameTarget(null);
219
- return;
220
- }
221
- setBusy(true);
222
- setError(null);
223
- try {
224
- await renameSession(renameTarget.id, title);
225
- setRenameTarget(null);
226
- notify?.("success", text.renamed);
227
- onChanged?.();
228
- } catch (e) {
229
- const message = e instanceof Error ? e.message : text.renameFailed;
230
- setError(message);
231
- notify?.("error", message);
232
- } finally {
233
- setBusy(false);
234
- }
235
- }, [renameTarget, renameValue, renameSession, notify, onChanged, text.renamed, text.renameFailed]);
236
- const confirmDelete = useCallback(async () => {
237
- if (!deleteTarget) return;
238
- const deletingCurrent = currentSessionId != null && deleteTarget.id === currentSessionId;
239
- setBusy(true);
240
- setError(null);
241
- try {
242
- await deleteSession(deleteTarget.id);
243
- setDeleteTarget(null);
244
- notify?.("success", text.deleted);
245
- onChanged?.();
246
- if (deletingCurrent) onDeletedCurrent?.();
247
- } catch (e) {
248
- const message = e instanceof Error ? e.message : text.deleteFailed;
249
- setError(message);
250
- notify?.("error", message);
251
- } finally {
252
- setBusy(false);
253
- }
254
- }, [deleteTarget, currentSessionId, deleteSession, notify, onChanged, onDeletedCurrent, text.deleted, text.deleteFailed]);
255
- const dialogs = /* @__PURE__ */ jsxs(Fragment, { children: [
256
- renameTarget && /* @__PURE__ */ jsxs(
257
- ActionDialog,
258
- {
259
- title: text.renameTitle,
260
- onClose: () => setRenameTarget(null),
261
- busy,
262
- error,
263
- footer: /* @__PURE__ */ jsxs(Fragment, { children: [
264
- /* @__PURE__ */ jsx(ActionDialogButton, { onClick: () => setRenameTarget(null), disabled: busy, variant: "ghost", children: text.cancel }),
265
- /* @__PURE__ */ jsx(ActionDialogButton, { onClick: () => void submitRename(), disabled: busy || !renameValue.trim(), children: text.renameSubmit })
266
- ] }),
267
- children: [
268
- /* @__PURE__ */ jsx("label", { htmlFor: "agent-app-rename-session", className: "text-xs text-muted-foreground", children: text.renameField }),
269
- /* @__PURE__ */ jsx(
270
- Input,
271
- {
272
- id: "agent-app-rename-session",
273
- value: renameValue,
274
- autoFocus: true,
275
- onChange: (e) => setRenameValue(e.target.value),
276
- onKeyDown: (e) => {
277
- if (e.key === "Enter" && !busy) {
278
- e.preventDefault();
279
- void submitRename();
280
- }
281
- },
282
- className: "mt-1.5"
283
- }
284
- )
285
- ]
286
- }
287
- ),
288
- deleteTarget && /* @__PURE__ */ jsx(
289
- ActionDialog,
290
- {
291
- title: text.deleteTitle,
292
- onClose: () => setDeleteTarget(null),
293
- busy,
294
- error,
295
- footer: /* @__PURE__ */ jsxs(Fragment, { children: [
296
- /* @__PURE__ */ jsx(ActionDialogButton, { onClick: () => setDeleteTarget(null), disabled: busy, variant: "ghost", children: text.cancel }),
297
- /* @__PURE__ */ jsx(ActionDialogButton, { onClick: () => void confirmDelete(), disabled: busy, variant: "destructive", children: text.deleteSubmit })
298
- ] }),
299
- children: /* @__PURE__ */ jsx("p", { className: "text-sm text-muted-foreground", children: text.deleteBody(sessionLabel(deleteTarget)) })
300
- }
301
- )
302
- ] });
303
- return { openRename, openDelete, dialogs, busy };
304
- }
305
- function AnchorLink({ to, className, children }) {
306
- return /* @__PURE__ */ jsx("a", { href: to, className, children });
307
- }
308
- var MINUTE = 6e4;
309
- var HOUR = 60 * MINUTE;
310
- var DAY = 24 * HOUR;
311
- function formatSessionTimestamp(isoDate) {
312
- if (!isoDate) return "";
313
- const at = Date.parse(isoDate);
314
- if (Number.isNaN(at)) return "";
315
- const delta = Date.now() - at;
316
- if (delta < MINUTE) return "just now";
317
- if (delta < HOUR) return `${Math.floor(delta / MINUTE)}m ago`;
318
- if (delta < DAY) return `${Math.floor(delta / HOUR)}h ago`;
319
- if (delta < 7 * DAY) return `${Math.floor(delta / DAY)}d ago`;
320
- return new Date(at).toLocaleDateString(void 0, { month: "short", day: "numeric" });
321
- }
322
- function SkeletonRows() {
323
- return /* @__PURE__ */ jsxs(Fragment, { children: [
324
- /* @__PURE__ */ jsx("span", { role: "status", "aria-live": "polite", "aria-busy": true, className: "sr-only", children: "Loading sessions\u2026" }),
325
- /* @__PURE__ */ jsx("div", { className: "flex flex-col gap-0.5", "aria-hidden": true, children: Array.from({ length: 8 }).map((_, i) => /* @__PURE__ */ jsxs("div", { className: "flex items-center gap-3 px-3 py-2.5", children: [
326
- /* @__PURE__ */ jsx("div", { className: "h-4 w-4 animate-pulse rounded bg-muted" }),
327
- /* @__PURE__ */ jsx("div", { className: "h-4 w-1/2 animate-pulse rounded bg-muted" }),
328
- /* @__PURE__ */ jsx("div", { className: "ml-auto h-3 w-12 animate-pulse rounded bg-muted" })
329
- ] }, i)) })
330
- ] });
331
- }
332
- function MessageIcon({ className }) {
333
- return /* @__PURE__ */ jsx("svg", { viewBox: "0 0 24 24", className, fill: "none", stroke: "currentColor", strokeWidth: "2", strokeLinecap: "round", strokeLinejoin: "round", "aria-hidden": true, children: /* @__PURE__ */ jsx("path", { d: "M21 15a2 2 0 0 1-2 2H7l-4 4V5a2 2 0 0 1 2-2h14a2 2 0 0 1 2 2z" }) });
334
- }
335
- function SessionHistoryPanel({
336
- history,
337
- hasAnySessions,
338
- query,
339
- onQueryChange,
340
- sort,
341
- onSortChange,
342
- hrefForSession,
343
- linkComponent: Link = AnchorLink,
344
- respondingSessionIds,
345
- onRename,
346
- onDelete,
347
- onBulkAction,
348
- renameLabel = "Rename",
349
- deleteLabel = "Delete",
350
- extraActions,
351
- newSessionHref,
352
- title = "History",
353
- showHeader = true,
354
- untitledLabel = UNTITLED_SESSION_LABEL,
355
- emptyTitle = "No sessions yet",
356
- emptyDescription = "Your chat sessions will show up here once you start one.",
357
- formatTimestamp = formatSessionTimestamp,
358
- contentWidth = "reading",
359
- className
360
- }) {
361
- const scrollRef = useRef(null);
362
- const sentinelRef = useInfiniteScroll(history.loadMore, {
363
- enabled: history.hasMore && !history.isLoadingMore && !history.isError,
364
- root: scrollRef,
365
- rootMargin: "300px"
366
- });
367
- const searchTerm = query.trim();
368
- const isSearching = searchTerm.length > 0;
369
- const column = contentWidth === "full" ? "w-full" : "mx-auto w-full max-w-4xl";
370
- const [selectedIds, setSelectedIds] = useState(/* @__PURE__ */ new Set());
371
- const [ageDays, setAgeDays] = useState("30");
372
- const [bulkTarget, setBulkTarget] = useState(null);
373
- const [bulkBusy, setBulkBusy] = useState(false);
374
- const [bulkError, setBulkError] = useState(null);
375
- useEffect(() => {
376
- setSelectedIds(/* @__PURE__ */ new Set());
377
- }, [searchTerm, sort]);
378
- useEffect(() => {
379
- const visible = new Set(history.items.map((item) => item.id));
380
- setSelectedIds((current) => {
381
- const next = new Set([...current].filter((id) => visible.has(id)));
382
- return next.size === current.size ? current : next;
383
- });
384
- }, [history.items]);
385
- const selectedCount = selectedIds.size;
386
- const allVisibleSelected = history.items.length > 0 && history.items.every((item) => selectedIds.has(item.id));
387
- const parsedAgeDays = Number(ageDays);
388
- const validAgeDays = Number.isInteger(parsedAgeDays) && parsedAgeDays >= 1 && parsedAgeDays <= 36500;
389
- const openBulkAction = useCallback((action) => {
390
- const verb = deleteLabel.toLowerCase();
391
- if (action.kind === "selected") {
392
- setBulkTarget({
393
- action,
394
- title: `${deleteLabel} selected sessions?`,
395
- body: `${verb === "delete" ? "This permanently removes" : `This ${verb}s`} ${action.ids.length} selected session${action.ids.length === 1 ? "" : "s"} and its messages.`
396
- });
397
- return;
398
- }
399
- const range = action.kind === "older-than" ? `older than ${action.days} days` : `from the last ${action.days} days`;
400
- setBulkTarget({
401
- action,
402
- title: `${deleteLabel} sessions ${range}?`,
403
- body: "This applies to every matching session in this workspace, including sessions not currently loaded in this list."
404
- });
405
- }, [deleteLabel]);
406
- const confirmBulkAction = useCallback(async () => {
407
- if (!bulkTarget || !onBulkAction) return;
408
- setBulkBusy(true);
409
- setBulkError(null);
410
- try {
411
- await onBulkAction(bulkTarget.action);
412
- setBulkTarget(null);
413
- setSelectedIds(/* @__PURE__ */ new Set());
414
- history.reload();
415
- } catch (error) {
416
- setBulkError(error instanceof Error ? error.message : `Could not ${deleteLabel.toLowerCase()} sessions`);
417
- } finally {
418
- setBulkBusy(false);
419
- }
420
- }, [bulkTarget, deleteLabel, history, onBulkAction]);
421
- return /* @__PURE__ */ jsxs("div", { className: `flex min-h-0 min-w-0 flex-1 flex-col ${className ?? ""}`, children: [
422
- showHeader && /* @__PURE__ */ jsx(ShellHeader, { as: "header", className: "bg-transparent px-4 sm:px-6", children: /* @__PURE__ */ jsxs("div", { className: `flex items-center gap-3 px-3 ${column}`, children: [
423
- /* @__PURE__ */ jsx("h1", { className: "flex-1 truncate text-sm font-semibold text-foreground", children: title }),
424
- newSessionHref && /* @__PURE__ */ jsxs(
425
- Link,
426
- {
427
- to: newSessionHref,
428
- className: "inline-flex h-8 shrink-0 items-center gap-1.5 rounded-md bg-primary px-3 text-xs font-medium text-primary-foreground transition hover:opacity-90",
429
- children: [
430
- /* @__PURE__ */ jsx("span", { "aria-hidden": true, className: "text-sm leading-none", children: "+" }),
431
- "New chat"
432
- ]
433
- }
434
- )
435
- ] }) }),
436
- /* @__PURE__ */ jsxs("div", { ref: scrollRef, className: "min-h-0 flex-1 overflow-y-auto", children: [
437
- hasAnySessions && /* @__PURE__ */ jsxs("div", { className: "sticky top-0 z-10 bg-background px-4 sm:px-6", children: [
438
- /* @__PURE__ */ jsxs("div", { className: `flex flex-col gap-2 px-3 pb-3 pt-4 sm:flex-row sm:items-center sm:gap-3 ${column}`, children: [
439
- /* @__PURE__ */ jsx(
440
- Input,
441
- {
442
- type: "search",
443
- value: query,
444
- onChange: (e) => onQueryChange(e.target.value),
445
- placeholder: "Search your sessions\u2026",
446
- "aria-label": "Search sessions",
447
- className: "sm:flex-1 [&::-webkit-search-cancel-button]:appearance-none"
448
- }
449
- ),
450
- /* @__PURE__ */ jsxs(Select, { value: sort, onValueChange: (value) => onSortChange(value), children: [
451
- /* @__PURE__ */ jsx(SelectTrigger, { "aria-label": "Sort sessions", className: "shrink-0 sm:w-[132px]", children: /* @__PURE__ */ jsx(SelectValue, {}) }),
452
- /* @__PURE__ */ jsxs(SelectContent, { children: [
453
- /* @__PURE__ */ jsx(SelectItem, { value: "newest", children: "Newest" }),
454
- /* @__PURE__ */ jsx(SelectItem, { value: "oldest", children: "Oldest" })
455
- ] })
456
- ] })
457
- ] }),
458
- onBulkAction && /* @__PURE__ */ jsxs("div", { className: `flex flex-col gap-2 border-t border-border px-3 py-3 ${column}`, children: [
459
- /* @__PURE__ */ jsxs("div", { className: "flex flex-wrap items-center gap-2", children: [
460
- /* @__PURE__ */ jsx(
461
- Button,
462
- {
463
- type: "button",
464
- variant: "outline",
465
- size: "sm",
466
- onClick: () => setSelectedIds(new Set(history.items.map((item) => item.id))),
467
- disabled: allVisibleSelected || history.items.length === 0,
468
- children: "Select all"
469
- }
470
- ),
471
- /* @__PURE__ */ jsx(
472
- Button,
473
- {
474
- type: "button",
475
- variant: "outline",
476
- size: "sm",
477
- onClick: () => setSelectedIds(/* @__PURE__ */ new Set()),
478
- disabled: selectedCount === 0,
479
- children: "Deselect all"
480
- }
481
- ),
482
- selectedCount > 0 && /* @__PURE__ */ jsxs(
483
- Button,
484
- {
485
- type: "button",
486
- variant: "destructive",
487
- size: "sm",
488
- onClick: () => openBulkAction({ kind: "selected", ids: [...selectedIds] }),
489
- children: [
490
- deleteLabel,
491
- " selected"
492
- ]
493
- }
494
- )
495
- ] }),
496
- /* @__PURE__ */ jsxs("div", { className: "flex flex-wrap items-center gap-2", children: [
497
- /* @__PURE__ */ jsx("label", { htmlFor: "agent-app-session-age", className: "text-xs text-muted-foreground", children: "Session age" }),
498
- /* @__PURE__ */ jsx(
499
- Input,
500
- {
501
- id: "agent-app-session-age",
502
- type: "number",
503
- min: 1,
504
- max: 36500,
505
- value: ageDays,
506
- onChange: (event) => setAgeDays(event.target.value),
507
- "aria-invalid": ageDays.length > 0 && !validAgeDays,
508
- size: "sm",
509
- className: "w-20 tabular-nums"
510
- }
511
- ),
512
- /* @__PURE__ */ jsx("span", { className: "text-xs text-muted-foreground", children: "days" }),
513
- /* @__PURE__ */ jsxs(
514
- Button,
515
- {
516
- type: "button",
517
- variant: "outline",
518
- size: "sm",
519
- onClick: () => openBulkAction({ kind: "older-than", days: parsedAgeDays }),
520
- disabled: !validAgeDays,
521
- children: [
522
- deleteLabel,
523
- " older"
524
- ]
525
- }
526
- ),
527
- /* @__PURE__ */ jsxs(
528
- Button,
529
- {
530
- type: "button",
531
- variant: "outline",
532
- size: "sm",
533
- onClick: () => openBulkAction({ kind: "newer-than", days: parsedAgeDays }),
534
- disabled: !validAgeDays,
535
- children: [
536
- deleteLabel,
537
- " recent"
538
- ]
539
- }
540
- )
541
- ] })
542
- ] })
543
- ] }),
544
- /* @__PURE__ */ jsx("div", { className: `px-4 pb-8 pt-1 sm:px-6 ${column}`, children: !hasAnySessions ? /* @__PURE__ */ jsxs("div", { className: "flex min-h-[50vh] flex-col items-center justify-center gap-2 text-center", children: [
545
- /* @__PURE__ */ jsx("p", { className: "text-sm font-medium text-foreground", children: emptyTitle }),
546
- /* @__PURE__ */ jsx("p", { className: "max-w-xs text-xs text-muted-foreground", children: emptyDescription })
547
- ] }) : history.isLoadingFirst ? /* @__PURE__ */ jsx(SkeletonRows, {}) : history.items.length === 0 ? history.isError ? /* @__PURE__ */ jsx(ErrorBlock, { onRetry: history.retry, message: "Couldn\u2019t load your sessions." }) : isSearching ? /* @__PURE__ */ jsxs("p", { className: "py-16 text-center text-sm text-muted-foreground", children: [
548
- "No sessions match \u201C",
549
- searchTerm,
550
- "\u201D."
551
- ] }) : /* @__PURE__ */ jsx("p", { className: "py-16 text-center text-sm text-muted-foreground", children: "No sessions remain." }) : /* @__PURE__ */ jsxs("div", { className: "flex flex-col gap-0.5", children: [
552
- history.items.map((session) => /* @__PURE__ */ jsx(
553
- SessionRow,
554
- {
555
- session,
556
- href: hrefForSession(session.id),
557
- Link,
558
- responding: respondingSessionIds?.has(session.id) ?? false,
559
- untitledLabel,
560
- timestamp: formatTimestamp(session.updatedAt),
561
- onRename,
562
- onDelete,
563
- selectable: Boolean(onBulkAction),
564
- selected: selectedIds.has(session.id),
565
- onSelectedChange: (selected) => {
566
- setSelectedIds((current) => {
567
- const next = new Set(current);
568
- if (selected) next.add(session.id);
569
- else next.delete(session.id);
570
- return next;
571
- });
572
- },
573
- renameLabel,
574
- deleteLabel,
575
- extraActions
576
- },
577
- session.id
578
- )),
579
- history.isError ? /* @__PURE__ */ jsx(ErrorBlock, { onRetry: history.retry, message: "Couldn\u2019t load more sessions.", inline: true }) : history.hasMore ? /* @__PURE__ */ jsx("div", { ref: sentinelRef, className: "flex items-center justify-center py-6", children: history.isLoadingMore && /* @__PURE__ */ jsx("span", { role: "status", "aria-live": "polite", "aria-busy": true, className: "text-xs text-muted-foreground", children: "Loading\u2026" }) }) : null
580
- ] }) })
581
- ] }),
582
- bulkTarget && /* @__PURE__ */ jsx(
583
- ActionDialog,
584
- {
585
- title: bulkTarget.title,
586
- onClose: () => {
587
- if (!bulkBusy) {
588
- setBulkTarget(null);
589
- setBulkError(null);
590
- }
591
- },
592
- busy: bulkBusy,
593
- error: bulkError,
594
- footer: /* @__PURE__ */ jsxs(Fragment, { children: [
595
- /* @__PURE__ */ jsx(
596
- ActionDialogButton,
597
- {
598
- onClick: () => {
599
- setBulkTarget(null);
600
- setBulkError(null);
601
- },
602
- disabled: bulkBusy,
603
- variant: "ghost",
604
- children: "Cancel"
605
- }
606
- ),
607
- /* @__PURE__ */ jsx(ActionDialogButton, { onClick: () => void confirmBulkAction(), disabled: bulkBusy, variant: "destructive", children: bulkBusy ? "Working\u2026" : deleteLabel })
608
- ] }),
609
- children: /* @__PURE__ */ jsx("p", { className: "text-sm text-muted-foreground", children: bulkTarget.body })
610
- }
611
- )
612
- ] });
613
- }
614
- function ErrorBlock({ message, onRetry, inline }) {
615
- return /* @__PURE__ */ jsxs(
616
- "div",
617
- {
618
- className: inline ? "flex items-center justify-center gap-3 py-6 text-sm text-muted-foreground" : "flex min-h-[40vh] flex-col items-center justify-center gap-3 text-center",
619
- children: [
620
- /* @__PURE__ */ jsx("span", { className: "text-sm text-muted-foreground", children: message }),
621
- /* @__PURE__ */ jsx(Button, { type: "button", variant: "outline", size: "sm", onClick: onRetry, children: "Retry" })
622
- ]
623
- }
624
- );
625
- }
626
- function SessionRow({
627
- session,
628
- href,
629
- Link,
630
- responding,
631
- untitledLabel,
632
- timestamp,
633
- onRename,
634
- onDelete,
635
- renameLabel,
636
- deleteLabel,
637
- extraActions,
638
- selectable,
639
- selected,
640
- onSelectedChange
641
- }) {
642
- const [menuOpen, setMenuOpen] = useState(false);
643
- const panelId = useId();
644
- const { containerRef, triggerRef, panelRef, triggerProps } = usePopover(menuOpen, setMenuOpen);
645
- const extras = extraActions?.(session) ?? [];
646
- const hasMenu = Boolean(onRename) || Boolean(onDelete) || extras.length > 0;
647
- const showUnread = Boolean(session.unread) && !responding;
648
- return /* @__PURE__ */ jsxs("div", { className: `group relative flex items-center gap-2 rounded-lg px-3 py-2.5 transition-colors hover:bg-accent ${selected ? "bg-primary/10" : ""}`, children: [
649
- selectable && /* @__PURE__ */ jsx(
650
- Checkbox,
651
- {
652
- checked: selected,
653
- onCheckedChange: (checked) => onSelectedChange(checked === true),
654
- "aria-label": `Select ${sessionLabel(session, untitledLabel)}`
655
- }
656
- ),
657
- /* @__PURE__ */ jsxs(Link, { to: href, className: "flex min-w-0 flex-1 items-center gap-3", children: [
658
- showUnread && /* @__PURE__ */ jsx("span", { className: "h-1.5 w-1.5 shrink-0 rounded-full bg-primary", "aria-hidden": true }),
659
- /* @__PURE__ */ jsx(MessageIcon, { className: "h-4 w-4 shrink-0 text-muted-foreground" }),
660
- /* @__PURE__ */ jsx(
661
- "span",
662
- {
663
- className: `truncate text-sm ${responding ? "text-muted-foreground" : "text-foreground"} ${showUnread ? "font-semibold" : ""}`,
664
- ...responding ? { role: "status", "aria-label": "Agent responding" } : {},
665
- children: sessionLabel(session, untitledLabel)
666
- }
667
- )
668
- ] }),
669
- /* @__PURE__ */ jsx("span", { className: "shrink-0 text-xs tabular-nums text-muted-foreground", children: timestamp }),
670
- hasMenu && /* @__PURE__ */ jsxs("div", { ref: containerRef, className: "relative shrink-0", children: [
671
- /* @__PURE__ */ jsx(
672
- Button,
673
- {
674
- type: "button",
675
- variant: "ghost",
676
- size: "icon-sm",
677
- ...triggerProps,
678
- "aria-label": "Session actions",
679
- "aria-controls": menuOpen ? panelId : void 0,
680
- onClick: () => setMenuOpen((open) => !open),
681
- className: "text-muted-foreground focus-visible:opacity-100 sm:opacity-0 sm:group-hover:opacity-100 aria-expanded:opacity-100",
682
- children: /* @__PURE__ */ jsx("span", { "aria-hidden": true, className: "text-base leading-none", children: "\u22EF" })
683
- }
684
- ),
685
- /* @__PURE__ */ jsxs(
686
- PopoverSurface,
687
- {
688
- open: menuOpen,
689
- id: panelId,
690
- role: "menu",
691
- triggerRef,
692
- panelRef,
693
- className: `w-36 overflow-hidden rounded-md border border-card-edge bg-popover py-1 ${OVERLAY_SHADOW}`,
694
- children: [
695
- onRename && /* @__PURE__ */ jsx(
696
- "button",
697
- {
698
- type: "button",
699
- role: "menuitem",
700
- onClick: () => {
701
- setMenuOpen(false);
702
- onRename(session);
703
- },
704
- className: "block w-full px-3 py-1.5 text-left text-xs text-foreground transition hover:bg-accent",
705
- children: renameLabel
706
- }
707
- ),
708
- extras.map((action) => /* @__PURE__ */ jsx(
709
- "button",
710
- {
711
- type: "button",
712
- role: "menuitem",
713
- onClick: () => {
714
- setMenuOpen(false);
715
- action.onSelect();
716
- },
717
- className: `block w-full px-3 py-1.5 text-left text-xs transition ${action.destructive ? "text-destructive hover:bg-destructive/10" : "text-foreground hover:bg-accent"}`,
718
- children: action.label
719
- },
720
- action.id
721
- )),
722
- onDelete && /* @__PURE__ */ jsx(
723
- "button",
724
- {
725
- type: "button",
726
- role: "menuitem",
727
- onClick: () => {
728
- setMenuOpen(false);
729
- onDelete(session);
730
- },
731
- className: "block w-full px-3 py-1.5 text-left text-xs text-destructive transition hover:bg-destructive/10",
732
- children: deleteLabel
733
- }
734
- )
735
- ]
736
- }
737
- )
738
- ] })
739
- ] });
740
- }
741
-
742
- export {
743
- useInfiniteScroll,
744
- useSessionHistory,
745
- useSessionActions,
746
- formatSessionTimestamp,
747
- SessionHistoryPanel
748
- };
749
- //# sourceMappingURL=chunk-35APKGPB.js.map