@meshagent/meshagent-tailwind 0.43.2 → 0.44.0

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 (99) hide show
  1. package/CHANGELOG.md +14 -0
  2. package/dist/cjs/chat/agent-thread-message-status-store.d.ts +107 -0
  3. package/dist/cjs/chat/agent-thread-message-status-store.js +649 -0
  4. package/dist/cjs/chat/agent-thread.d.ts +87 -0
  5. package/dist/cjs/chat/agent-thread.js +1673 -0
  6. package/dist/cjs/chat/chat-bot-view.d.ts +9 -5
  7. package/dist/cjs/chat/chat-bot-view.js +44 -536
  8. package/dist/cjs/chat/chat-hooks.d.ts +6 -5
  9. package/dist/cjs/chat/chat-hooks.js +21 -466
  10. package/dist/cjs/chat/chat-typing-indicator.d.ts +15 -1
  11. package/dist/cjs/chat/chat-typing-indicator.js +35 -5
  12. package/dist/cjs/chat/file-attachment.d.ts +7 -3
  13. package/dist/cjs/chat/file-attachment.js +30 -6
  14. package/dist/cjs/chat/multi-thread-view.d.ts +5 -2
  15. package/dist/cjs/chat/multi-thread-view.js +6 -2
  16. package/dist/cjs/chat/new-chat-thread.d.ts +5 -2
  17. package/dist/cjs/chat/new-chat-thread.js +10 -3
  18. package/dist/cjs/chat/thread-list-view.d.ts +22 -0
  19. package/dist/cjs/chat/thread-list-view.js +518 -0
  20. package/dist/cjs/chat/tool-call-status-accumulator.d.ts +69 -0
  21. package/dist/cjs/chat/tool-call-status-accumulator.js +268 -0
  22. package/dist/cjs/components/pane-example.d.ts +1 -1
  23. package/dist/cjs/components/ui/avatar.d.ts +3 -3
  24. package/dist/cjs/components/ui/button.d.ts +3 -3
  25. package/dist/cjs/components/ui/card.d.ts +7 -7
  26. package/dist/cjs/components/ui/dialog.d.ts +10 -10
  27. package/dist/cjs/components/ui/form.d.ts +7 -7
  28. package/dist/cjs/components/ui/input.d.ts +1 -1
  29. package/dist/cjs/components/ui/label.d.ts +1 -1
  30. package/dist/cjs/components/ui/progress.d.ts +1 -1
  31. package/dist/cjs/components/ui/radio-group.d.ts +2 -2
  32. package/dist/cjs/components/ui/select.d.ts +10 -10
  33. package/dist/cjs/components/ui/sheet.d.ts +8 -8
  34. package/dist/cjs/components/ui/skeleton.d.ts +1 -1
  35. package/dist/cjs/components/ui/sonner.d.ts +1 -1
  36. package/dist/cjs/components/ui/spinner.d.ts +2 -2
  37. package/dist/cjs/components/ui/textarea.d.ts +1 -1
  38. package/dist/cjs/file-preview/file-preview.d.ts +1 -0
  39. package/dist/cjs/file-preview/file-preview.js +43 -7
  40. package/dist/cjs/index.d.ts +4 -2
  41. package/dist/cjs/index.js +14 -2
  42. package/dist/cjs/meetings/camera-grid.d.ts +2 -2
  43. package/dist/cjs/tools/ask-user-for-file.js +2 -2
  44. package/dist/cjs/tools/file-dialog.d.ts +2 -1
  45. package/dist/cjs/tools/form-dialog.d.ts +2 -1
  46. package/dist/esm/chat/agent-thread-message-status-store.d.ts +107 -0
  47. package/dist/esm/chat/agent-thread-message-status-store.js +647 -0
  48. package/dist/esm/chat/agent-thread.d.ts +87 -0
  49. package/dist/esm/chat/agent-thread.js +1682 -0
  50. package/dist/esm/chat/chat-bot-view.d.ts +9 -5
  51. package/dist/esm/chat/chat-bot-view.js +51 -566
  52. package/dist/esm/chat/chat-hooks.d.ts +6 -5
  53. package/dist/esm/chat/chat-hooks.js +23 -468
  54. package/dist/esm/chat/chat-typing-indicator.d.ts +15 -1
  55. package/dist/esm/chat/chat-typing-indicator.js +35 -5
  56. package/dist/esm/chat/file-attachment.d.ts +7 -3
  57. package/dist/esm/chat/file-attachment.js +30 -6
  58. package/dist/esm/chat/multi-thread-view.d.ts +5 -2
  59. package/dist/esm/chat/multi-thread-view.js +6 -2
  60. package/dist/esm/chat/new-chat-thread.d.ts +5 -2
  61. package/dist/esm/chat/new-chat-thread.js +11 -4
  62. package/dist/esm/chat/thread-list-view.d.ts +22 -0
  63. package/dist/esm/chat/thread-list-view.js +514 -0
  64. package/dist/esm/chat/tool-call-status-accumulator.d.ts +69 -0
  65. package/dist/esm/chat/tool-call-status-accumulator.js +248 -0
  66. package/dist/esm/components/pane-example.d.ts +1 -1
  67. package/dist/esm/components/ui/avatar.d.ts +3 -3
  68. package/dist/esm/components/ui/button.d.ts +3 -3
  69. package/dist/esm/components/ui/card.d.ts +7 -7
  70. package/dist/esm/components/ui/dialog.d.ts +10 -10
  71. package/dist/esm/components/ui/form.d.ts +7 -7
  72. package/dist/esm/components/ui/input.d.ts +1 -1
  73. package/dist/esm/components/ui/label.d.ts +1 -1
  74. package/dist/esm/components/ui/progress.d.ts +1 -1
  75. package/dist/esm/components/ui/radio-group.d.ts +2 -2
  76. package/dist/esm/components/ui/select.d.ts +10 -10
  77. package/dist/esm/components/ui/sheet.d.ts +8 -8
  78. package/dist/esm/components/ui/skeleton.d.ts +1 -1
  79. package/dist/esm/components/ui/sonner.d.ts +1 -1
  80. package/dist/esm/components/ui/spinner.d.ts +2 -2
  81. package/dist/esm/components/ui/textarea.d.ts +1 -1
  82. package/dist/esm/file-preview/file-preview.d.ts +1 -0
  83. package/dist/esm/file-preview/file-preview.js +31 -5
  84. package/dist/esm/index.d.ts +4 -2
  85. package/dist/esm/index.js +10 -2
  86. package/dist/esm/meetings/camera-grid.d.ts +2 -2
  87. package/dist/esm/tools/ask-user-for-file.js +2 -2
  88. package/dist/esm/tools/file-dialog.d.ts +2 -1
  89. package/dist/esm/tools/form-dialog.d.ts +2 -1
  90. package/dist/index.css +1 -1
  91. package/package.json +10 -5
  92. package/dist/cjs/chat/chat-thread.d.ts +0 -12
  93. package/dist/cjs/chat/chat-thread.js +0 -815
  94. package/dist/cjs/chat/dataset-chat-thread.d.ts +0 -16
  95. package/dist/cjs/chat/dataset-chat-thread.js +0 -1813
  96. package/dist/esm/chat/chat-thread.d.ts +0 -12
  97. package/dist/esm/chat/chat-thread.js +0 -785
  98. package/dist/esm/chat/dataset-chat-thread.d.ts +0 -16
  99. package/dist/esm/chat/dataset-chat-thread.js +0 -1811
@@ -0,0 +1,518 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+ var thread_list_view_exports = {};
20
+ __export(thread_list_view_exports, {
21
+ ThreadListView: () => ThreadListView,
22
+ defaultAgentThreadListPath: () => defaultAgentThreadListPath
23
+ });
24
+ module.exports = __toCommonJS(thread_list_view_exports);
25
+ var import_jsx_runtime = require("react/jsx-runtime");
26
+ var import_react = require("react");
27
+ var import_meshagent_agents = require("@meshagent/meshagent-agents");
28
+ var import_lucide_react = require("lucide-react");
29
+ var import_chat_hooks = require("./chat-hooks.js");
30
+ var import_conversation_descriptor = require("./conversation-descriptor.js");
31
+ var import_button = require("../components/ui/button.js");
32
+ var import_dialog = require("../components/ui/dialog.js");
33
+ var import_input = require("../components/ui/input.js");
34
+ var import_label = require("../components/ui/label.js");
35
+ var import_spinner = require("../components/ui/spinner.js");
36
+ var import_utils = require("../lib/utils.js");
37
+ function defaultAgentThreadListPath(agentName) {
38
+ const normalizedAgentName = normalizePath(agentName);
39
+ return normalizedAgentName === null ? null : `agent://${normalizedAgentName}/threads`;
40
+ }
41
+ function normalizePath(path) {
42
+ const normalized = path?.trim();
43
+ return normalized ? normalized : null;
44
+ }
45
+ function parseDate(value) {
46
+ const parsed = new Date(value);
47
+ return Number.isNaN(parsed.getTime()) ? /* @__PURE__ */ new Date(0) : parsed;
48
+ }
49
+ function compareThreadEntries(left, right) {
50
+ const leftSortDate = left.modifiedAt.trim() ? parseDate(left.modifiedAt) : parseDate(left.createdAt);
51
+ const rightSortDate = right.modifiedAt.trim() ? parseDate(right.modifiedAt) : parseDate(right.createdAt);
52
+ const dateComparison = rightSortDate.getTime() - leftSortDate.getTime();
53
+ if (dateComparison !== 0) {
54
+ return dateComparison;
55
+ }
56
+ const createdDateComparison = parseDate(right.createdAt).getTime() - parseDate(left.createdAt).getTime();
57
+ if (createdDateComparison !== 0) {
58
+ return createdDateComparison;
59
+ }
60
+ return left.path.localeCompare(right.path);
61
+ }
62
+ function parseThreadListEntries(entries) {
63
+ return entries.map((entry) => ({
64
+ path: entry.path,
65
+ name: entry.name,
66
+ createdAt: entry.createdAt,
67
+ modifiedAt: entry.modifiedAt
68
+ })).sort(compareThreadEntries);
69
+ }
70
+ function threadEntriesEqual(left, right) {
71
+ return left.length === right.length && left.every((entry, index) => {
72
+ const other = right[index];
73
+ return entry.path === other?.path && entry.name === other.name && entry.createdAt === other.createdAt && entry.modifiedAt === other.modifiedAt;
74
+ });
75
+ }
76
+ function describeError(error) {
77
+ if (error instanceof Error && error.message.trim() !== "") {
78
+ return error.message;
79
+ }
80
+ return `${error}`;
81
+ }
82
+ class ChatThreadListStore {
83
+ constructor(repository, onChanged) {
84
+ this.repository = repository;
85
+ this.onChanged = onChanged;
86
+ }
87
+ repository;
88
+ onChanged;
89
+ async open() {
90
+ this.repository.addListener(this.onChanged);
91
+ await this.repository.open();
92
+ }
93
+ async close() {
94
+ this.repository.removeListener(this.onChanged);
95
+ await this.repository.close();
96
+ }
97
+ entries() {
98
+ return parseThreadListEntries(this.repository.entries());
99
+ }
100
+ async renameThread(entry, name) {
101
+ await this.repository.renameThread(entry.path, name);
102
+ }
103
+ async deleteThread(entry) {
104
+ await this.repository.deleteThread(entry.path);
105
+ }
106
+ }
107
+ function useThreadList({ room, chatClient }) {
108
+ const [entries, setEntries] = (0, import_react.useState)([]);
109
+ const [loading, setLoading] = (0, import_react.useState)(true);
110
+ const [error, setError] = (0, import_react.useState)(null);
111
+ const storeRef = (0, import_react.useRef)(null);
112
+ const syncEntries = (0, import_react.useCallback)((store = storeRef.current) => {
113
+ if (store === null) {
114
+ setEntries([]);
115
+ return;
116
+ }
117
+ const nextEntries = [...store.entries()].sort(compareThreadEntries);
118
+ setEntries((currentEntries) => threadEntriesEqual(currentEntries, nextEntries) ? currentEntries : nextEntries);
119
+ }, []);
120
+ const createStore = (0, import_react.useCallback)(() => {
121
+ if (chatClient === null) {
122
+ throw new Error("Agent thread lists require a chat client.");
123
+ }
124
+ return new ChatThreadListStore(
125
+ new import_meshagent_agents.AgentThreadStorageRepository({ chatClient }),
126
+ () => syncEntries()
127
+ );
128
+ }, [chatClient, room, syncEntries]);
129
+ (0, import_react.useEffect)(() => {
130
+ let cancelled = false;
131
+ setEntries([]);
132
+ setLoading(true);
133
+ setError(null);
134
+ const store = createStore();
135
+ storeRef.current = store;
136
+ void store.open().then(() => {
137
+ if (cancelled) {
138
+ void store.close();
139
+ return;
140
+ }
141
+ syncEntries(store);
142
+ setLoading(false);
143
+ setError(null);
144
+ }).catch((nextError) => {
145
+ if (cancelled) {
146
+ return;
147
+ }
148
+ setEntries([]);
149
+ setLoading(false);
150
+ setError(nextError);
151
+ });
152
+ return () => {
153
+ cancelled = true;
154
+ if (storeRef.current === store) {
155
+ storeRef.current = null;
156
+ }
157
+ void store.close();
158
+ };
159
+ }, [createStore, syncEntries]);
160
+ return {
161
+ entries,
162
+ loading,
163
+ error,
164
+ renameThread: async (entry, name) => {
165
+ await storeRef.current?.renameThread(entry, name);
166
+ syncEntries();
167
+ },
168
+ deleteThread: async (entry) => {
169
+ await storeRef.current?.deleteThread(entry);
170
+ syncEntries();
171
+ }
172
+ };
173
+ }
174
+ function ThreadListRow({
175
+ title,
176
+ selected,
177
+ onClick,
178
+ icon,
179
+ trailing
180
+ }) {
181
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsx)("div", { className: "px-2 py-1 cursor-pointer", children: /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(
182
+ "div",
183
+ {
184
+ className: (0, import_utils.cn)(
185
+ "flex min-w-0 items-center rounded-lg border border-transparent transition-colors",
186
+ selected ? "bg-accent text-accent-foreground" : "text-muted-foreground hover:bg-accent/50 hover:text-foreground"
187
+ ),
188
+ children: [
189
+ /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(
190
+ "button",
191
+ {
192
+ type: "button",
193
+ className: "flex min-w-0 flex-1 items-center gap-3 px-3 py-2 text-left",
194
+ onClick,
195
+ children: [
196
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)("span", { className: "flex h-4 w-4 shrink-0 items-center justify-center", children: icon }),
197
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
198
+ "span",
199
+ {
200
+ className: (0, import_utils.cn)(
201
+ "truncate text-sm font-medium",
202
+ selected ? "text-accent-foreground" : "text-foreground"
203
+ ),
204
+ children: title
205
+ }
206
+ )
207
+ ]
208
+ }
209
+ ),
210
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)("div", { className: "flex shrink-0 gap-1 pr-1", children: trailing ?? /* @__PURE__ */ (0, import_jsx_runtime.jsx)("div", { className: "h-8 w-8" }) })
211
+ ]
212
+ }
213
+ ) });
214
+ }
215
+ function ThreadListEntryRow({
216
+ room,
217
+ entry,
218
+ agentName,
219
+ selected,
220
+ onSelect,
221
+ onRename,
222
+ onDelete
223
+ }) {
224
+ const status = (0, import_chat_hooks.useThreadStatus)({ room, path: entry.path, agentName: agentName ?? void 0 });
225
+ const iconClassName = selected ? "text-accent-foreground" : "text-muted-foreground";
226
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
227
+ ThreadListRow,
228
+ {
229
+ title: entry.name,
230
+ selected,
231
+ onClick: () => onSelect(entry),
232
+ icon: status.hasStatus ? /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_spinner.Spinner, { size: "sm", className: iconClassName }) : selected ? /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_lucide_react.Check, { className: (0, import_utils.cn)("h-4 w-4", iconClassName) }) : /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_lucide_react.MessageSquare, { className: (0, import_utils.cn)("h-4 w-4", iconClassName) }),
233
+ trailing: /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(import_jsx_runtime.Fragment, { children: [
234
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
235
+ import_button.Button,
236
+ {
237
+ type: "button",
238
+ variant: "ghost",
239
+ size: "icon",
240
+ className: "h-8 w-8 rounded-md",
241
+ "aria-label": `Rename ${entry.name}`,
242
+ onClick: () => onRename(entry),
243
+ children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_lucide_react.Pencil, { className: "h-4 w-4" })
244
+ }
245
+ ),
246
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
247
+ import_button.Button,
248
+ {
249
+ type: "button",
250
+ variant: "ghost",
251
+ size: "icon",
252
+ className: "h-8 w-8 rounded-md text-muted-foreground hover:text-destructive",
253
+ "aria-label": `Delete ${entry.name}`,
254
+ onClick: () => onDelete(entry),
255
+ children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_lucide_react.Trash2, { className: "h-4 w-4" })
256
+ }
257
+ )
258
+ ] })
259
+ }
260
+ );
261
+ }
262
+ function RenameThreadDialog({
263
+ dialogState,
264
+ onNameChange,
265
+ onOpenChange,
266
+ onSubmit
267
+ }) {
268
+ const inputId = (0, import_react.useId)();
269
+ const inputRef = (0, import_react.useRef)(null);
270
+ const trimmedName = dialogState?.value.trim() ?? "";
271
+ const saveDisabled = dialogState === null || trimmedName === "" || trimmedName === dialogState.entry.name;
272
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_dialog.Dialog, { open: dialogState !== null, onOpenChange, children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
273
+ import_dialog.DialogContent,
274
+ {
275
+ showCloseButton: false,
276
+ className: "sm:max-w-[425px]",
277
+ onOpenAutoFocus: (event) => {
278
+ event.preventDefault();
279
+ inputRef.current?.focus();
280
+ inputRef.current?.select();
281
+ },
282
+ children: /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("form", { className: "space-y-4", onSubmit, children: [
283
+ /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(import_dialog.DialogHeader, { children: [
284
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_dialog.DialogTitle, { children: "Rename thread" }),
285
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_dialog.DialogDescription, { children: "Use a short and descriptive name" })
286
+ ] }),
287
+ /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", { className: "space-y-2", children: [
288
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_label.Label, { htmlFor: inputId, children: "Name" }),
289
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
290
+ import_input.Input,
291
+ {
292
+ ref: inputRef,
293
+ id: inputId,
294
+ value: dialogState?.value ?? "",
295
+ autoComplete: "off",
296
+ onChange: onNameChange
297
+ }
298
+ )
299
+ ] }),
300
+ /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(import_dialog.DialogFooter, { children: [
301
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_dialog.DialogClose, { asChild: true, children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_button.Button, { type: "button", variant: "outline", children: "Cancel" }) }),
302
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_button.Button, { type: "submit", disabled: saveDisabled, children: "Save" })
303
+ ] })
304
+ ] })
305
+ }
306
+ ) });
307
+ }
308
+ function DeleteThreadDialog({
309
+ dialogState,
310
+ onOpenChange,
311
+ onConfirm
312
+ }) {
313
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_dialog.Dialog, { open: dialogState !== null, onOpenChange, children: /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(import_dialog.DialogContent, { showCloseButton: false, className: "sm:max-w-[425px]", children: [
314
+ /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(import_dialog.DialogHeader, { children: [
315
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_dialog.DialogTitle, { children: "Delete thread" }),
316
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_dialog.DialogDescription, { children: dialogState === null ? "Delete this thread?" : `Delete "${dialogState.entry.name}"?` })
317
+ ] }),
318
+ /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(import_dialog.DialogFooter, { children: [
319
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_dialog.DialogClose, { asChild: true, children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_button.Button, { type: "button", variant: "outline", children: "Cancel" }) }),
320
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_button.Button, { type: "button", variant: "destructive", onClick: onConfirm, children: "Delete" })
321
+ ] })
322
+ ] }) });
323
+ }
324
+ function ThreadListView({
325
+ room,
326
+ chatClient = null,
327
+ selectedThreadPath,
328
+ selectedThreadDisplayName,
329
+ agentName,
330
+ showCreateItem = true,
331
+ newThreadResetVersion = 0,
332
+ onSelectedThreadPathChanged,
333
+ onSelectedThreadResolved
334
+ }) {
335
+ const normalizedSelectedThreadPath = normalizePath(selectedThreadPath);
336
+ const previousNewThreadResetVersionRef = (0, import_react.useRef)(newThreadResetVersion);
337
+ const [renameThreadDialog, setRenameThreadDialog] = (0, import_react.useState)(null);
338
+ const [deleteThreadDialog, setDeleteThreadDialog] = (0, import_react.useState)(null);
339
+ const [optimisticNames, setOptimisticNames] = (0, import_react.useState)(() => /* @__PURE__ */ new Map());
340
+ const [optimisticDeletedPaths, setOptimisticDeletedPaths] = (0, import_react.useState)(() => /* @__PURE__ */ new Set());
341
+ const threadList = useThreadList({ room, chatClient });
342
+ const entries = threadList.entries.filter((entry) => !optimisticDeletedPaths.has(entry.path)).map((entry) => {
343
+ const optimisticName = optimisticNames.get(entry.path);
344
+ return optimisticName === void 0 ? entry : { ...entry, name: optimisticName };
345
+ }).sort(compareThreadEntries);
346
+ (0, import_react.useEffect)(() => {
347
+ setOptimisticNames((current) => {
348
+ const next = new Map(current);
349
+ for (const entry of threadList.entries) {
350
+ if (next.get(entry.path) === entry.name) {
351
+ next.delete(entry.path);
352
+ }
353
+ }
354
+ return next.size === current.size ? current : next;
355
+ });
356
+ setOptimisticDeletedPaths((current) => {
357
+ const storePaths = new Set(threadList.entries.map((entry) => entry.path));
358
+ const next = new Set([...current].filter((path) => storePaths.has(path)));
359
+ return next.size === current.size ? current : next;
360
+ });
361
+ }, [threadList.entries]);
362
+ (0, import_react.useEffect)(() => {
363
+ setOptimisticNames(/* @__PURE__ */ new Map());
364
+ setOptimisticDeletedPaths(/* @__PURE__ */ new Set());
365
+ }, [chatClient, room]);
366
+ (0, import_react.useEffect)(() => {
367
+ if (previousNewThreadResetVersionRef.current !== newThreadResetVersion && normalizedSelectedThreadPath !== null) {
368
+ onSelectedThreadPathChanged(null);
369
+ onSelectedThreadResolved?.(null, null);
370
+ }
371
+ previousNewThreadResetVersionRef.current = newThreadResetVersion;
372
+ }, [newThreadResetVersion, normalizedSelectedThreadPath, onSelectedThreadPathChanged, onSelectedThreadResolved]);
373
+ const hasSelectedEntry = normalizedSelectedThreadPath !== null && entries.some((entry) => entry.path === normalizedSelectedThreadPath);
374
+ const showPendingNewThreadSelection = normalizedSelectedThreadPath === null;
375
+ const pendingSelectedThreadEntry = normalizedSelectedThreadPath !== null && !hasSelectedEntry ? {
376
+ path: normalizedSelectedThreadPath,
377
+ name: normalizePath(selectedThreadDisplayName) ?? (0, import_conversation_descriptor.defaultThreadDisplayNameFromPath)(normalizedSelectedThreadPath),
378
+ createdAt: "",
379
+ modifiedAt: ""
380
+ } : null;
381
+ const clearSelection = (0, import_react.useCallback)(() => {
382
+ onSelectedThreadPathChanged(null);
383
+ onSelectedThreadResolved?.(null, null);
384
+ }, [onSelectedThreadPathChanged, onSelectedThreadResolved]);
385
+ const selectEntry = (0, import_react.useCallback)((entry) => {
386
+ onSelectedThreadPathChanged(entry.path);
387
+ onSelectedThreadResolved?.(entry.path, entry.name);
388
+ }, [onSelectedThreadPathChanged, onSelectedThreadResolved]);
389
+ const closeRenameThreadDialog = (0, import_react.useCallback)(() => {
390
+ setRenameThreadDialog(null);
391
+ }, []);
392
+ const closeDeleteThreadDialog = (0, import_react.useCallback)(() => {
393
+ setDeleteThreadDialog(null);
394
+ }, []);
395
+ const handleRenameThreadNameChanged = (0, import_react.useCallback)((event) => {
396
+ const nextValue = event.target.value;
397
+ setRenameThreadDialog((currentDialogState) => {
398
+ if (currentDialogState === null) {
399
+ return currentDialogState;
400
+ }
401
+ return { ...currentDialogState, value: nextValue };
402
+ });
403
+ }, []);
404
+ const handleRenameThreadSubmit = (0, import_react.useCallback)((event) => {
405
+ event.preventDefault();
406
+ if (renameThreadDialog === null) {
407
+ return;
408
+ }
409
+ const trimmedName = renameThreadDialog.value.trim();
410
+ if (trimmedName === "" || trimmedName === renameThreadDialog.entry.name) {
411
+ return;
412
+ }
413
+ const entry = renameThreadDialog.entry;
414
+ setOptimisticNames((current) => new Map(current).set(entry.path, trimmedName));
415
+ void threadList.renameThread(entry, trimmedName).then(() => {
416
+ if (entry.path === normalizedSelectedThreadPath) {
417
+ onSelectedThreadResolved?.(entry.path, trimmedName);
418
+ }
419
+ closeRenameThreadDialog();
420
+ }).catch((renameError) => {
421
+ setOptimisticNames((current) => {
422
+ const next = new Map(current);
423
+ next.delete(entry.path);
424
+ return next;
425
+ });
426
+ setTimeout(() => {
427
+ throw renameError;
428
+ }, 0);
429
+ });
430
+ }, [closeRenameThreadDialog, normalizedSelectedThreadPath, onSelectedThreadResolved, renameThreadDialog, threadList]);
431
+ const handleDeleteThreadConfirm = (0, import_react.useCallback)(() => {
432
+ if (deleteThreadDialog === null) {
433
+ return;
434
+ }
435
+ const entry = deleteThreadDialog.entry;
436
+ setOptimisticDeletedPaths((current) => new Set(current).add(entry.path));
437
+ void threadList.deleteThread(entry).then(() => {
438
+ if (normalizedSelectedThreadPath === entry.path) {
439
+ clearSelection();
440
+ }
441
+ closeDeleteThreadDialog();
442
+ }).catch((deleteError) => {
443
+ setOptimisticDeletedPaths((current) => {
444
+ const next = new Set(current);
445
+ next.delete(entry.path);
446
+ return next;
447
+ });
448
+ setTimeout(() => {
449
+ throw deleteError;
450
+ }, 0);
451
+ });
452
+ }, [clearSelection, closeDeleteThreadDialog, deleteThreadDialog, normalizedSelectedThreadPath, threadList]);
453
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", { className: "h-full flex flex-col rounded-md border", children: [
454
+ threadList.loading ? /* @__PURE__ */ (0, import_jsx_runtime.jsx)("div", { className: "flex min-h-0 flex-1 items-center justify-center p-6", children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_spinner.Spinner, { size: "lg", className: "text-muted-foreground" }) }) : threadList.error ? /* @__PURE__ */ (0, import_jsx_runtime.jsx)("div", { className: "flex min-h-0 flex-1 items-center justify-center p-6 text-center text-sm text-muted-foreground", children: `Unable to load threads: ${describeError(threadList.error)}` }) : /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", { className: "flex h-full flex-1 flex-col overflow-y-auto py-1", children: [
455
+ showCreateItem ? /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
456
+ ThreadListRow,
457
+ {
458
+ title: "New thread",
459
+ selected: showPendingNewThreadSelection,
460
+ onClick: clearSelection,
461
+ icon: showPendingNewThreadSelection ? /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_lucide_react.Check, { className: "h-4 w-4 text-accent-foreground" }) : /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_lucide_react.MessageSquarePlus, { className: "h-4 w-4 text-muted-foreground" })
462
+ }
463
+ ) : null,
464
+ entries.length === 0 && showPendingNewThreadSelection ? /* @__PURE__ */ (0, import_jsx_runtime.jsx)("div", { className: "flex min-h-0 flex-1 items-center justify-center px-4 py-6 text-center text-sm text-muted-foreground", children: "No threads yet" }) : null,
465
+ pendingSelectedThreadEntry !== null ? /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
466
+ ThreadListEntryRow,
467
+ {
468
+ room,
469
+ entry: pendingSelectedThreadEntry,
470
+ agentName,
471
+ selected: true,
472
+ onSelect: selectEntry,
473
+ onRename: (entry) => setRenameThreadDialog({ entry, value: entry.name }),
474
+ onDelete: (entry) => setDeleteThreadDialog({ entry })
475
+ },
476
+ pendingSelectedThreadEntry.path
477
+ ) : null,
478
+ entries.map((entry) => /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
479
+ ThreadListEntryRow,
480
+ {
481
+ room,
482
+ entry,
483
+ agentName,
484
+ selected: entry.path === normalizedSelectedThreadPath,
485
+ onSelect: selectEntry,
486
+ onRename: (nextEntry) => setRenameThreadDialog({ entry: nextEntry, value: nextEntry.name }),
487
+ onDelete: (nextEntry) => setDeleteThreadDialog({ entry: nextEntry })
488
+ },
489
+ entry.path
490
+ ))
491
+ ] }),
492
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
493
+ RenameThreadDialog,
494
+ {
495
+ dialogState: renameThreadDialog,
496
+ onNameChange: handleRenameThreadNameChanged,
497
+ onOpenChange: (open) => {
498
+ if (!open) {
499
+ closeRenameThreadDialog();
500
+ }
501
+ },
502
+ onSubmit: handleRenameThreadSubmit
503
+ }
504
+ ),
505
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
506
+ DeleteThreadDialog,
507
+ {
508
+ dialogState: deleteThreadDialog,
509
+ onOpenChange: (open) => {
510
+ if (!open) {
511
+ closeDeleteThreadDialog();
512
+ }
513
+ },
514
+ onConfirm: handleDeleteThreadConfirm
515
+ }
516
+ )
517
+ ] });
518
+ }
@@ -0,0 +1,69 @@
1
+ export interface ToolCallStatusSnapshotParams {
2
+ itemId: string;
3
+ status?: string;
4
+ text?: string;
5
+ totalBytes?: number;
6
+ linesAdded?: number;
7
+ linesRemoved?: number;
8
+ }
9
+ export declare class ToolCallStatusSnapshot {
10
+ readonly itemId: string;
11
+ readonly status: string;
12
+ readonly text?: string;
13
+ readonly totalBytes?: number;
14
+ readonly linesAdded?: number;
15
+ readonly linesRemoved?: number;
16
+ constructor(params: ToolCallStatusSnapshotParams);
17
+ }
18
+ export declare class AccumulatedLiveToolCall {
19
+ tool?: string;
20
+ arguments?: Record<string, unknown>;
21
+ status: string;
22
+ argumentBytes: number;
23
+ argumentText: string;
24
+ }
25
+ export declare class LiveToolCallAccumulator {
26
+ private readonly callsByItemId;
27
+ private readonly textEncoder;
28
+ get isEmpty(): boolean;
29
+ hasSingleItem(itemId: string): boolean;
30
+ get(itemId: string): AccumulatedLiveToolCall | undefined;
31
+ totalBytes(itemId?: string | null): number | undefined;
32
+ appendDelta(params: {
33
+ itemId: string;
34
+ delta: string;
35
+ fallbackText?: string;
36
+ }): ToolCallStatusSnapshot;
37
+ upsert(params: {
38
+ itemId: string;
39
+ tool: string;
40
+ arguments?: Record<string, unknown> | null;
41
+ fallbackText?: string;
42
+ }): ToolCallStatusSnapshot;
43
+ complete(params: {
44
+ itemId: string;
45
+ status?: string;
46
+ fallbackText?: string;
47
+ }): ToolCallStatusSnapshot | undefined;
48
+ remove(itemId: string): boolean;
49
+ private callFor;
50
+ private snapshotFor;
51
+ private patchStatusInfo;
52
+ }
53
+ export interface PatchLineCounts {
54
+ added: number;
55
+ removed: number;
56
+ }
57
+ export interface ApplyPatchStatusInfo {
58
+ path?: string;
59
+ counts?: PatchLineCounts;
60
+ }
61
+ export declare function applyPatchTextFromArguments(value: unknown): string | undefined;
62
+ export declare function applyPatchPathFromArguments(value: unknown): string | undefined;
63
+ export declare function applyPatchPathFromText(patch: string): string | undefined;
64
+ export declare function diffLineCountsFromText(diff: string): PatchLineCounts | undefined;
65
+ export declare function applyPatchLineCountsFromText(patch: string): PatchLineCounts | undefined;
66
+ export declare function applyPatchStatusInfo(params: {
67
+ arguments?: unknown;
68
+ deltaText?: string;
69
+ }): ApplyPatchStatusInfo | undefined;