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