@meshagent/meshagent-tailwind 0.43.2 → 0.43.3

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 (37) hide show
  1. package/CHANGELOG.md +3 -0
  2. package/dist/cjs/chat/agent-thread.d.ts +15 -0
  3. package/dist/cjs/chat/agent-thread.js +613 -0
  4. package/dist/cjs/chat/chat-bot-view.d.ts +3 -2
  5. package/dist/cjs/chat/chat-bot-view.js +34 -34
  6. package/dist/cjs/chat/chat-bot-view.test.js +325 -0
  7. package/dist/cjs/chat/live-chat-widgets.test.js +256 -0
  8. package/dist/cjs/chat/multi-thread-view.d.ts +3 -2
  9. package/dist/cjs/chat/multi-thread-view.js +4 -2
  10. package/dist/cjs/chat/new-chat-thread.d.ts +3 -2
  11. package/dist/cjs/chat/new-chat-thread.js +5 -2
  12. package/dist/cjs/file-preview/file-preview.js +2 -2
  13. package/dist/cjs/index.d.ts +1 -2
  14. package/dist/cjs/index.js +1 -2
  15. package/dist/esm/chat/agent-thread.d.ts +15 -0
  16. package/dist/esm/chat/agent-thread.js +606 -0
  17. package/dist/esm/chat/chat-bot-view.d.ts +3 -2
  18. package/dist/esm/chat/chat-bot-view.js +34 -34
  19. package/dist/esm/chat/chat-bot-view.test.js +336 -0
  20. package/dist/esm/chat/live-chat-widgets.test.js +262 -0
  21. package/dist/esm/chat/multi-thread-view.d.ts +3 -2
  22. package/dist/esm/chat/multi-thread-view.js +4 -2
  23. package/dist/esm/chat/new-chat-thread.d.ts +3 -2
  24. package/dist/esm/chat/new-chat-thread.js +5 -2
  25. package/dist/esm/file-preview/file-preview.js +2 -2
  26. package/dist/esm/index.d.ts +1 -2
  27. package/dist/esm/index.js +1 -2
  28. package/dist/index.css +1 -1
  29. package/package.json +10 -5
  30. package/dist/cjs/chat/chat-thread.d.ts +0 -12
  31. package/dist/cjs/chat/chat-thread.js +0 -815
  32. package/dist/cjs/chat/dataset-chat-thread.d.ts +0 -16
  33. package/dist/cjs/chat/dataset-chat-thread.js +0 -1813
  34. package/dist/esm/chat/chat-thread.d.ts +0 -12
  35. package/dist/esm/chat/chat-thread.js +0 -785
  36. package/dist/esm/chat/dataset-chat-thread.d.ts +0 -16
  37. package/dist/esm/chat/dataset-chat-thread.js +0 -1811
@@ -1,815 +0,0 @@
1
- "use strict";
2
- var __create = Object.create;
3
- var __defProp = Object.defineProperty;
4
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
- var __getOwnPropNames = Object.getOwnPropertyNames;
6
- var __getProtoOf = Object.getPrototypeOf;
7
- var __hasOwnProp = Object.prototype.hasOwnProperty;
8
- var __export = (target, all) => {
9
- for (var name in all)
10
- __defProp(target, name, { get: all[name], enumerable: true });
11
- };
12
- var __copyProps = (to, from, except, desc) => {
13
- if (from && typeof from === "object" || typeof from === "function") {
14
- for (let key of __getOwnPropNames(from))
15
- if (!__hasOwnProp.call(to, key) && key !== except)
16
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
17
- }
18
- return to;
19
- };
20
- var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
21
- // If the importer is in node compatibility mode or this is not an ESM
22
- // file that has been converted to a CommonJS file using a Babel-
23
- // compatible transform (i.e. "__esModule" has not been set), then set
24
- // "default" to the CommonJS "module.exports" for node compatibility.
25
- isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
26
- mod
27
- ));
28
- var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
29
- var chat_thread_exports = {};
30
- __export(chat_thread_exports, {
31
- ChatThread: () => ChatThread,
32
- timeAgo: () => timeAgo
33
- });
34
- module.exports = __toCommonJS(chat_thread_exports);
35
- var import_jsx_runtime = require("react/jsx-runtime");
36
- var import_react = require("react");
37
- var import_lucide_react = require("lucide-react");
38
- var import_react_markdown = __toESM(require("react-markdown"));
39
- var import_rehype_highlight = __toESM(require("rehype-highlight"));
40
- var import_rehype_sanitize = __toESM(require("rehype-sanitize"));
41
- var import_remark_gfm = __toESM(require("remark-gfm"));
42
- var import_button = require("../components/ui/button.js");
43
- var import_spinner = require("../components/ui/spinner.js");
44
- var import_chat_typing_indicator = require("./chat-typing-indicator.js");
45
- var import_chat_input = require("./chat-input.js");
46
- var import_chat_hooks = require("./chat-hooks.js");
47
- var import_file_preview = require("../file-preview/file-preview.js");
48
- var import_utils = require("../lib/utils.js");
49
- const supportedEventKinds = /* @__PURE__ */ new Set([
50
- "exec",
51
- "tool",
52
- "web",
53
- "search",
54
- "diff",
55
- "image",
56
- "approval",
57
- "collab",
58
- "plan",
59
- "thread",
60
- "file"
61
- ]);
62
- const stickyBottomThresholdPx = 24;
63
- function getStringAttribute(element, name) {
64
- const value = element.getAttribute(name);
65
- return typeof value === "string" ? value : null;
66
- }
67
- function getTrimmedStringAttribute(element, name) {
68
- return getStringAttribute(element, name)?.trim() ?? "";
69
- }
70
- function getElementChildren(element) {
71
- return element.getChildren() ?? [];
72
- }
73
- function formatDateTime(iso) {
74
- const date = new Date(iso);
75
- return new Intl.DateTimeFormat(void 0, {
76
- year: "numeric",
77
- month: "long",
78
- day: "numeric",
79
- hour: "numeric",
80
- minute: "2-digit",
81
- hour12: true,
82
- timeZoneName: "short"
83
- }).format(date);
84
- }
85
- function timeAgo(iso) {
86
- const date = new Date(iso);
87
- if (Number.isNaN(date.getTime())) {
88
- return "";
89
- }
90
- const relativeTime = new Intl.RelativeTimeFormat(void 0, { numeric: "auto" });
91
- const now = /* @__PURE__ */ new Date();
92
- const seconds = Math.round((date.getTime() - now.getTime()) / 1e3);
93
- const minutes = Math.round(seconds / 60);
94
- const hours = Math.round(minutes / 60);
95
- const days = Math.round(hours / 24);
96
- const months = Math.round(days / 30);
97
- if (Math.abs(months) >= 1) {
98
- return formatDateTime(iso);
99
- }
100
- if (Math.abs(days) >= 1) {
101
- return relativeTime.format(days, "day");
102
- }
103
- if (Math.abs(hours) >= 1) {
104
- return relativeTime.format(hours, "hour");
105
- }
106
- if (Math.abs(minutes) >= 1) {
107
- return relativeTime.format(minutes, "minute");
108
- }
109
- return relativeTime.format(seconds, "second");
110
- }
111
- function displayParticipantName(name) {
112
- return name.split("@")[0]?.trim() ?? name.trim();
113
- }
114
- function isThreadAttachmentElement(element) {
115
- return element.tagName === "file" || element.tagName === "image";
116
- }
117
- function isImageAttachmentElement(element) {
118
- if (!isThreadAttachmentElement(element)) {
119
- return false;
120
- }
121
- const path = getTrimmedStringAttribute(element, "path");
122
- return element.tagName === "image" || path !== "" && (0, import_file_preview.isImagePath)(path);
123
- }
124
- function getAttachmentTrackingId(attachment) {
125
- const path = getTrimmedStringAttribute(attachment, "path");
126
- return attachment.id || `${attachment.tagName}:${path}`;
127
- }
128
- function collectImageAttachmentIds(messages) {
129
- const ids = [];
130
- for (const message of messages) {
131
- if (message.tagName !== "message") {
132
- continue;
133
- }
134
- for (const attachment of getElementChildren(message)) {
135
- if (!isImageAttachmentElement(attachment)) {
136
- continue;
137
- }
138
- ids.push(getAttachmentTrackingId(attachment));
139
- }
140
- }
141
- return ids;
142
- }
143
- function parseEventDetailLines(raw) {
144
- const value = raw.trim();
145
- if (value === "") {
146
- return [];
147
- }
148
- if (value.startsWith("[") && value.endsWith("]")) {
149
- try {
150
- const decoded = JSON.parse(value);
151
- if (Array.isArray(decoded)) {
152
- return decoded.filter((item) => typeof item === "string").map((line) => line.trim()).filter((line) => line !== "");
153
- }
154
- } catch {
155
- }
156
- }
157
- return value.split(/\r?\n/u).map((line) => line.trim()).filter((line) => line !== "");
158
- }
159
- function isCompletedToolCallEvent(message) {
160
- if (message.tagName !== "event") {
161
- return false;
162
- }
163
- const kind = getTrimmedStringAttribute(message, "kind").toLowerCase();
164
- if (kind !== "tool") {
165
- return false;
166
- }
167
- const state = (getTrimmedStringAttribute(message, "state") || "info").toLowerCase();
168
- if (state !== "completed") {
169
- return false;
170
- }
171
- const itemType = getTrimmedStringAttribute(message, "item_type").toLowerCase();
172
- if (itemType === "tool_call") {
173
- return true;
174
- }
175
- const method = getTrimmedStringAttribute(message, "method") || "agent/event";
176
- const summary = getTrimmedStringAttribute(message, "summary") || method;
177
- const headline = getTrimmedStringAttribute(message, "headline");
178
- const detailLines = parseEventDetailLines(getTrimmedStringAttribute(message, "details"));
179
- const filterHeadline = (headline !== "" ? headline : summary).trim().toLowerCase();
180
- return filterHeadline === "called tool" && detailLines.length > 0 && detailLines.every((line) => line.trimStart().toLowerCase().startsWith("tool:"));
181
- }
182
- function shouldHideCompletedToolCallEvent(message, showCompletedToolCalls) {
183
- return !showCompletedToolCalls && isCompletedToolCallEvent(message);
184
- }
185
- function hasRenderableStandardThreadMessageContent(message) {
186
- if (message.tagName !== "message") {
187
- return true;
188
- }
189
- const text = getTrimmedStringAttribute(message, "text");
190
- if (text !== "") {
191
- return true;
192
- }
193
- return getElementChildren(message).some(isThreadAttachmentElement);
194
- }
195
- function shouldRenderThreadElement(message, showCompletedToolCalls) {
196
- if (message.tagName === "reasoning") {
197
- return getTrimmedStringAttribute(message, "summary") !== "";
198
- }
199
- if (message.tagName === "message") {
200
- return hasRenderableStandardThreadMessageContent(message);
201
- }
202
- if (message.tagName === "exec") {
203
- return true;
204
- }
205
- if (message.tagName !== "event") {
206
- return false;
207
- }
208
- const kind = getTrimmedStringAttribute(message, "kind").toLowerCase();
209
- if (!supportedEventKinds.has(kind)) {
210
- return false;
211
- }
212
- return !shouldHideCompletedToolCallEvent(message, showCompletedToolCalls);
213
- }
214
- function isCancellingThreadStatusText(statusText) {
215
- const normalized = statusText?.trim().toLowerCase();
216
- return normalized === "cancelling" || normalized === "canceling";
217
- }
218
- function distanceFromBottom(element) {
219
- return Math.max(element.scrollHeight - element.clientHeight - element.scrollTop, 0);
220
- }
221
- function isNearBottom(element) {
222
- return distanceFromBottom(element) <= stickyBottomThresholdPx;
223
- }
224
- function useDownloadUrl(room, path) {
225
- const [url, setUrl] = (0, import_react.useState)(null);
226
- (0, import_react.useEffect)(() => {
227
- let cancelled = false;
228
- if (path.trim() === "") {
229
- setUrl(null);
230
- return;
231
- }
232
- void room.storage.downloadUrl(path).then((nextUrl) => {
233
- if (!cancelled) {
234
- setUrl(nextUrl);
235
- }
236
- }).catch(() => {
237
- if (!cancelled) {
238
- setUrl(null);
239
- }
240
- });
241
- return () => {
242
- cancelled = true;
243
- };
244
- }, [path, room]);
245
- return url;
246
- }
247
- function MarkdownBlock({ text }) {
248
- return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
249
- import_react_markdown.default,
250
- {
251
- remarkPlugins: [import_remark_gfm.default],
252
- rehypePlugins: [import_rehype_sanitize.default, import_rehype_highlight.default],
253
- components: {
254
- pre: ({ className, children, ...props }) => /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
255
- "pre",
256
- {
257
- ...props,
258
- className: (0, import_utils.cn)("overflow-x-auto rounded-md border bg-background/80 p-3", className),
259
- children
260
- }
261
- ),
262
- p: ({ children, ...props }) => /* @__PURE__ */ (0, import_jsx_runtime.jsx)("p", { ...props, className: "mb-2 last:mb-0 overflow-hidden max-w-full", children }),
263
- table: ({ children, ...props }) => /* @__PURE__ */ (0, import_jsx_runtime.jsx)("div", { className: "my-4 w-full overflow-x-auto", children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
264
- "table",
265
- {
266
- ...props,
267
- className: "w-full border-collapse border-spacing-0",
268
- children
269
- }
270
- ) }),
271
- th: ({ children, ...props }) => /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
272
- "th",
273
- {
274
- ...props,
275
- className: "border bg-muted/50 px-3 py-2 text-left text-sm font-semibold",
276
- children
277
- }
278
- ),
279
- td: ({ children, ...props }) => /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
280
- "td",
281
- {
282
- ...props,
283
- className: "border px-3 py-2 align-top text-sm bg-background",
284
- children
285
- }
286
- ),
287
- ul: ({ children, ...props }) => /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
288
- "ul",
289
- {
290
- ...props,
291
- className: "mb-2 ml-6 list-disc last:mb-0",
292
- children
293
- }
294
- ),
295
- ol: ({ children, ...props }) => /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
296
- "ol",
297
- {
298
- ...props,
299
- className: "mb-2 ml-6 list-decimal last:mb-0",
300
- children
301
- }
302
- ),
303
- a: ({ children, href, ...props }) => /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
304
- "a",
305
- {
306
- ...props,
307
- href,
308
- target: "_blank",
309
- rel: "noopener noreferrer",
310
- className: "text-primary underline overflow-ellipsis inline-block max-w-full overflow-x-hidden",
311
- children
312
- }
313
- )
314
- },
315
- children: text
316
- }
317
- );
318
- }
319
- function ChatImage({
320
- room,
321
- path,
322
- alt,
323
- onSettled
324
- }) {
325
- const url = useDownloadUrl(room, path);
326
- const imageRef = (0, import_react.useRef)(null);
327
- const settledRef = (0, import_react.useRef)(false);
328
- const markSettled = (0, import_react.useCallback)(() => {
329
- if (settledRef.current) {
330
- return;
331
- }
332
- settledRef.current = true;
333
- onSettled?.();
334
- }, [onSettled]);
335
- (0, import_react.useEffect)(() => {
336
- settledRef.current = false;
337
- }, [path, url]);
338
- (0, import_react.useEffect)(() => {
339
- if (!url) {
340
- return;
341
- }
342
- if (imageRef.current?.complete) {
343
- markSettled();
344
- }
345
- }, [markSettled, url]);
346
- if (!url) {
347
- return null;
348
- }
349
- return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_file_preview.FilePreviewDialog, { room, path, children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
350
- "button",
351
- {
352
- type: "button",
353
- className: "block overflow-hidden rounded-md bg-muted/20 shadow-xs transition-opacity hover:opacity-95",
354
- children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
355
- "img",
356
- {
357
- ref: imageRef,
358
- src: url,
359
- alt,
360
- className: "max-h-[312px] w-auto max-w-full object-cover",
361
- onLoad: () => {
362
- markSettled();
363
- },
364
- onError: () => {
365
- markSettled();
366
- }
367
- }
368
- )
369
- }
370
- ) });
371
- }
372
- function FileAttachment({ room, path }) {
373
- const filename = path.split("/").pop() ?? path;
374
- return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_file_preview.FilePreviewDialog, { room, path, children: /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(
375
- "button",
376
- {
377
- type: "button",
378
- className: "inline-flex max-w-full items-center gap-2 rounded-md bg-muted/60 px-3 py-2 text-left shadow-xs transition-colors hover:bg-muted/80",
379
- children: [
380
- /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_lucide_react.FileText, { className: "h-4 w-4 shrink-0 text-muted-foreground" }),
381
- /* @__PURE__ */ (0, import_jsx_runtime.jsx)("span", { className: "truncate text-sm font-medium", children: filename })
382
- ]
383
- }
384
- ) });
385
- }
386
- function ThreadAttachment({ room, attachment, onImageSettled }) {
387
- const path = getTrimmedStringAttribute(attachment, "path");
388
- if (path === "") {
389
- return null;
390
- }
391
- const filename = path.split("/").pop() ?? "Attachment";
392
- if (attachment.tagName === "image" || (0, import_file_preview.isImagePath)(path)) {
393
- const attachmentId = getAttachmentTrackingId(attachment);
394
- return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
395
- ChatImage,
396
- {
397
- room,
398
- path,
399
- alt: filename,
400
- onSettled: () => {
401
- onImageSettled?.(attachmentId);
402
- }
403
- }
404
- );
405
- }
406
- return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(FileAttachment, { room, path });
407
- }
408
- function ChatBubble({ text, mine }) {
409
- if (text.trim() === "") {
410
- return null;
411
- }
412
- return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
413
- "div",
414
- {
415
- className: (0, import_utils.cn)(
416
- "w-fit max-w-[85%] rounded-md px-4 py-3 text-sm leading-6 shadow-xs sm:w-2xl",
417
- mine ? "bg-secondary/85 text-foreground" : "bg-muted/70 text-foreground"
418
- ),
419
- children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(MarkdownBlock, { text })
420
- }
421
- );
422
- }
423
- function ThreadReasoning({ message }) {
424
- const summary = getTrimmedStringAttribute(message, "summary");
425
- if (summary === "") {
426
- return null;
427
- }
428
- return /* @__PURE__ */ (0, import_jsx_runtime.jsx)("div", { className: "max-w-2xl border-l-2 border-primary/30 pl-4 text-sm text-muted-foreground", children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(MarkdownBlock, { text: summary }) });
429
- }
430
- function ThreadExec({ message }) {
431
- const command = getTrimmedStringAttribute(message, "command");
432
- const result = getTrimmedStringAttribute(message, "result");
433
- const stdout = getTrimmedStringAttribute(message, "stdout");
434
- const stderr = getTrimmedStringAttribute(message, "stderr");
435
- const sections = [
436
- command !== "" ? { label: "Command", value: command } : null,
437
- result !== "" ? { label: "Result", value: result } : null,
438
- stdout !== "" ? { label: "Stdout", value: stdout } : null,
439
- stderr !== "" ? { label: "Stderr", value: stderr } : null
440
- ].filter((section) => section !== null);
441
- return /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", { className: "max-w-3xl rounded-2xl border bg-background/70 p-4", children: [
442
- /* @__PURE__ */ (0, import_jsx_runtime.jsx)("div", { className: "mb-3 text-xs font-semibold uppercase tracking-[0.16em] text-muted-foreground", children: "Terminal" }),
443
- /* @__PURE__ */ (0, import_jsx_runtime.jsx)("div", { className: "space-y-3 font-mono text-xs leading-6 text-foreground", children: sections.length === 0 ? /* @__PURE__ */ (0, import_jsx_runtime.jsx)("div", { className: "text-muted-foreground", children: "No command output." }) : sections.map((section) => /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", { className: "space-y-1", children: [
444
- /* @__PURE__ */ (0, import_jsx_runtime.jsx)("div", { className: "text-[11px] uppercase tracking-[0.16em] text-muted-foreground", children: section.label }),
445
- /* @__PURE__ */ (0, import_jsx_runtime.jsx)("pre", { className: "overflow-x-auto whitespace-pre-wrap rounded-xl border bg-muted/30 p-3", children: section.value })
446
- ] }, section.label)) })
447
- ] });
448
- }
449
- function defaultEventHeadline(kind, state, eventName) {
450
- if (kind === "approval") {
451
- return state === "completed" ? "Approval resolved" : "Approval required";
452
- }
453
- if (kind === "tool") {
454
- if (state === "failed") {
455
- return "Tool failed";
456
- }
457
- if (state === "completed") {
458
- return "Tool completed";
459
- }
460
- return "Calling tool";
461
- }
462
- if (kind === "web") {
463
- return "Opened webpage";
464
- }
465
- if (kind === "search") {
466
- return "Ran search";
467
- }
468
- if (kind === "diff") {
469
- return "Updated diff";
470
- }
471
- if (kind === "file") {
472
- return "File event";
473
- }
474
- if (kind === "thread") {
475
- return "Thread event";
476
- }
477
- if (kind === "plan") {
478
- return "Updated plan";
479
- }
480
- if (kind === "exec") {
481
- return "Ran command";
482
- }
483
- return eventName.replace(/[._]/gu, " ");
484
- }
485
- function EventRow({ room, message }) {
486
- const method = getTrimmedStringAttribute(message, "method") || "agent/event";
487
- const eventName = getTrimmedStringAttribute(message, "name") || getTrimmedStringAttribute(message, "event_type") || method.replace(/\//gu, ".");
488
- const kind = getTrimmedStringAttribute(message, "kind").toLowerCase();
489
- const state = (getTrimmedStringAttribute(message, "state") || "info").toLowerCase();
490
- const summary = getTrimmedStringAttribute(message, "summary");
491
- const headline = getTrimmedStringAttribute(message, "headline") || (summary !== "" ? summary : defaultEventHeadline(kind, state, eventName));
492
- const detailLines = parseEventDetailLines(getTrimmedStringAttribute(message, "details"));
493
- const eventPath = getTrimmedStringAttribute(message, "path");
494
- const inProgress = state === "in_progress" || state === "running" || state === "queued";
495
- const textColorClass = state === "failed" ? "text-destructive" : state === "cancelled" ? "text-muted-foreground" : inProgress ? "text-primary" : "text-foreground";
496
- if (headline === "") {
497
- return null;
498
- }
499
- return /* @__PURE__ */ (0, import_jsx_runtime.jsx)("div", { className: "max-w-3xl rounded-2xl border bg-background/70 px-4 py-3 text-xs", children: /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", { className: "flex flex-wrap items-start gap-2", children: [
500
- /* @__PURE__ */ (0, import_jsx_runtime.jsx)("span", { className: "rounded-full border px-2 py-0.5 text-[10px] uppercase tracking-[0.16em] text-muted-foreground", children: kind }),
501
- /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", { className: "min-w-0 flex-1 space-y-2", children: [
502
- /* @__PURE__ */ (0, import_jsx_runtime.jsx)("div", { className: (0, import_utils.cn)("text-sm font-semibold leading-5", textColorClass), children: headline }),
503
- summary !== "" && summary !== headline ? /* @__PURE__ */ (0, import_jsx_runtime.jsx)("div", { className: "text-muted-foreground", children: summary }) : null,
504
- detailLines.length > 0 ? /* @__PURE__ */ (0, import_jsx_runtime.jsx)("div", { className: "space-y-1 text-muted-foreground", children: detailLines.map((line, index) => /* @__PURE__ */ (0, import_jsx_runtime.jsx)("div", { className: "leading-5", children: line }, `${line}-${index}`)) }) : null,
505
- eventPath !== "" ? /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(
506
- "button",
507
- {
508
- type: "button",
509
- className: "inline-flex items-center gap-2 rounded-full border px-3 py-1.5 text-left text-[11px] font-medium text-foreground transition-colors hover:bg-muted",
510
- onClick: () => {
511
- void room.storage.downloadUrl(eventPath).then((url) => {
512
- window.open(url, "_blank", "noopener,noreferrer");
513
- });
514
- },
515
- children: [
516
- /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_lucide_react.FileText, { className: "h-3.5 w-3.5 shrink-0" }),
517
- /* @__PURE__ */ (0, import_jsx_runtime.jsx)("span", { className: "truncate", children: eventPath })
518
- ]
519
- }
520
- ) : null
521
- ] })
522
- ] }) });
523
- }
524
- function ThreadMessage({
525
- room,
526
- message,
527
- previous,
528
- localParticipantName,
529
- onImageSettled
530
- }) {
531
- const authorName = getTrimmedStringAttribute(message, "author_name");
532
- const mine = authorName !== "" && authorName === localParticipantName.trim();
533
- const createdAt = getTrimmedStringAttribute(message, "created_at");
534
- const text = getStringAttribute(message, "text") ?? "";
535
- const attachments = getElementChildren(message).filter(isThreadAttachmentElement);
536
- const previousAuthor = previous ? getTrimmedStringAttribute(previous, "author_name") : "";
537
- const shouldShowHeader = previousAuthor !== authorName;
538
- return /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", { className: "flex flex-col gap-2", children: [
539
- shouldShowHeader && (authorName !== "" || createdAt !== "") ? /* @__PURE__ */ (0, import_jsx_runtime.jsx)("div", { className: (0, import_utils.cn)("flex w-full", mine ? "justify-end" : "justify-start"), children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)("div", { className: (0, import_utils.cn)("max-w-[85%] px-1 sm:max-w-2xl", mine ? "text-right" : "text-left"), children: /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(
540
- "div",
541
- {
542
- className: (0, import_utils.cn)(
543
- "flex flex-wrap items-center gap-x-3 gap-y-1 text-xs text-muted-foreground",
544
- mine ? "justify-end" : "justify-start"
545
- ),
546
- children: [
547
- authorName !== "" ? /* @__PURE__ */ (0, import_jsx_runtime.jsx)("span", { className: "font-semibold text-foreground", children: displayParticipantName(authorName) }) : null,
548
- createdAt !== "" ? /* @__PURE__ */ (0, import_jsx_runtime.jsx)("span", { children: timeAgo(createdAt) }) : null
549
- ]
550
- }
551
- ) }) }) : null,
552
- text.trim() !== "" ? /* @__PURE__ */ (0, import_jsx_runtime.jsx)("div", { className: (0, import_utils.cn)("flex w-full", mine ? "justify-end" : "justify-start"), children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(ChatBubble, { text, mine }) }) : null,
553
- attachments.length > 0 ? /* @__PURE__ */ (0, import_jsx_runtime.jsx)("div", { className: (0, import_utils.cn)("flex w-full", mine ? "justify-end" : "justify-start"), children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
554
- "div",
555
- {
556
- className: (0, import_utils.cn)(
557
- "flex max-w-[85%] flex-wrap gap-3 px-1 sm:max-w-2xl",
558
- mine ? "justify-end" : "justify-start"
559
- ),
560
- children: attachments.map((attachment) => /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
561
- ThreadAttachment,
562
- {
563
- room,
564
- attachment,
565
- onImageSettled
566
- },
567
- attachment.id
568
- ))
569
- }
570
- ) }) : null
571
- ] });
572
- }
573
- function EmptyState({
574
- title,
575
- description
576
- }) {
577
- return /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", { className: "h-full mx-auto flex max-w-2xl flex-col items-center justify-center px-6 py-20 text-center", children: [
578
- /* @__PURE__ */ (0, import_jsx_runtime.jsx)("h2", { className: "text-4xl font-semibold tracking-tight text-foreground sm:text-5xl", children: title }),
579
- description?.trim() ? /* @__PURE__ */ (0, import_jsx_runtime.jsx)("p", { className: "mt-3 max-w-xl text-sm leading-6 text-muted-foreground sm:text-base", children: description }) : null
580
- ] });
581
- }
582
- function ChatThread({
583
- room,
584
- path,
585
- participants,
586
- agentName,
587
- emptyStateTitle,
588
- emptyStateDescription
589
- }) {
590
- const status = (0, import_chat_hooks.useThreadStatus)({ room, path, agentName });
591
- const {
592
- document,
593
- messages,
594
- sendMessage,
595
- selectAttachments,
596
- attachments,
597
- setAttachments,
598
- localParticipantName,
599
- cancelRequest
600
- } = (0, import_chat_hooks.useChatThread)({
601
- room,
602
- path,
603
- participants,
604
- agentName,
605
- useAgentMessages: agentName?.trim() !== "",
606
- messageType: status.mode === "steerable" && status.turnId != null ? "steer" : "chat",
607
- turnId: status.turnId
608
- });
609
- return /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", { className: "flex min-h-0 flex-1 flex-col", children: [
610
- /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
611
- ChatThreadView,
612
- {
613
- room,
614
- messages,
615
- isLoading: document === null,
616
- localParticipantName,
617
- path,
618
- threadStatusText: status.text,
619
- threadStatusStartedAt: status.startedAt,
620
- threadStatusMode: status.mode,
621
- onCancelRequest: cancelRequest,
622
- emptyStateTitle,
623
- emptyStateDescription
624
- }
625
- ),
626
- /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
627
- import_chat_input.ChatInput,
628
- {
629
- onSubmit: sendMessage,
630
- attachments,
631
- onFilesSelected: selectAttachments,
632
- setAttachments,
633
- disabled: document === null,
634
- placeholder: agentName?.trim() ? `Type a message or @${displayParticipantName(agentName)}` : "Type a message"
635
- }
636
- )
637
- ] });
638
- }
639
- function ChatThreadView({
640
- room,
641
- messages,
642
- isLoading = false,
643
- localParticipantName,
644
- path,
645
- showCompletedToolCalls = false,
646
- onShowCompletedToolCallsChanged,
647
- typing = false,
648
- thinking = false,
649
- threadStatusText,
650
- threadStatusStartedAt,
651
- threadStatusMode,
652
- onCancelRequest,
653
- emptyStateTitle,
654
- emptyStateDescription
655
- }) {
656
- const visibleMessages = (0, import_react.useMemo)(
657
- () => messages.filter((message) => shouldRenderThreadElement(message, showCompletedToolCalls)),
658
- [messages, showCompletedToolCalls]
659
- );
660
- const hiddenCompletedToolCallCount = (0, import_react.useMemo)(
661
- () => messages.filter(isCompletedToolCallEvent).length,
662
- [messages]
663
- );
664
- const [trackedInitialImageThreadKey, setTrackedInitialImageThreadKey] = (0, import_react.useState)(null);
665
- const [pendingInitialImageIds, setPendingInitialImageIds] = (0, import_react.useState)([]);
666
- const scrollContainerRef = (0, import_react.useRef)(null);
667
- const contentRef = (0, import_react.useRef)(null);
668
- const stickToBottomRef = (0, import_react.useRef)(true);
669
- const forceBottomRef = (0, import_react.useRef)(false);
670
- const lastVisibleMessageId = visibleMessages.length > 0 ? visibleMessages[visibleMessages.length - 1]?.id : null;
671
- const threadKey = path?.trim() || "__default__";
672
- const hasOverlay = threadStatusText?.trim() || thinking || typing;
673
- const waitingForInitialImages = trackedInitialImageThreadKey === threadKey && pendingInitialImageIds.length > 0;
674
- (0, import_react.useEffect)(() => {
675
- forceBottomRef.current = waitingForInitialImages;
676
- }, [waitingForInitialImages]);
677
- (0, import_react.useEffect)(() => {
678
- setTrackedInitialImageThreadKey(null);
679
- setPendingInitialImageIds([]);
680
- }, [threadKey]);
681
- (0, import_react.useEffect)(() => {
682
- if (trackedInitialImageThreadKey === threadKey || visibleMessages.length === 0) {
683
- return;
684
- }
685
- setTrackedInitialImageThreadKey(threadKey);
686
- setPendingInitialImageIds(collectImageAttachmentIds(visibleMessages));
687
- }, [threadKey, trackedInitialImageThreadKey, visibleMessages]);
688
- const handleImageSettled = (0, import_react.useCallback)((attachmentId) => {
689
- setPendingInitialImageIds((currentIds) => {
690
- if (!currentIds.includes(attachmentId)) {
691
- return currentIds;
692
- }
693
- return currentIds.filter((currentId) => currentId !== attachmentId);
694
- });
695
- }, []);
696
- (0, import_react.useEffect)(() => {
697
- const container = scrollContainerRef.current;
698
- if (!container) {
699
- return;
700
- }
701
- stickToBottomRef.current = true;
702
- container.scrollTop = container.scrollHeight;
703
- }, [path]);
704
- (0, import_react.useEffect)(() => {
705
- if (!waitingForInitialImages) {
706
- return;
707
- }
708
- const container = scrollContainerRef.current;
709
- if (!container) {
710
- return;
711
- }
712
- container.scrollTop = container.scrollHeight;
713
- }, [pendingInitialImageIds, waitingForInitialImages]);
714
- (0, import_react.useEffect)(() => {
715
- const container = scrollContainerRef.current;
716
- if (!container || !stickToBottomRef.current) {
717
- return;
718
- }
719
- container.scrollTop = container.scrollHeight;
720
- }, [hasOverlay, lastVisibleMessageId, threadStatusText, thinking, typing]);
721
- (0, import_react.useEffect)(() => {
722
- const container = scrollContainerRef.current;
723
- const content = contentRef.current;
724
- if (!container || !content || typeof ResizeObserver === "undefined") {
725
- return;
726
- }
727
- const observer = new ResizeObserver(() => {
728
- if (!stickToBottomRef.current && !forceBottomRef.current) {
729
- return;
730
- }
731
- container.scrollTop = container.scrollHeight;
732
- });
733
- observer.observe(content);
734
- return () => {
735
- observer.disconnect();
736
- };
737
- }, []);
738
- return /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", { className: "relative flex min-h-0 flex-1 flex-col", children: [
739
- onShowCompletedToolCallsChanged && hiddenCompletedToolCallCount > 0 ? /* @__PURE__ */ (0, import_jsx_runtime.jsx)("div", { className: "pointer-events-none absolute inset-x-0 top-0 z-10 flex justify-center px-4 pt-3", children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)("div", { className: "pointer-events-auto flex w-full max-w-[912px] justify-end", children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
740
- import_button.Button,
741
- {
742
- type: "button",
743
- variant: "ghost",
744
- size: "sm",
745
- className: "rounded-full border bg-background/90 backdrop-blur",
746
- onClick: () => {
747
- onShowCompletedToolCallsChanged(!showCompletedToolCalls);
748
- },
749
- children: showCompletedToolCalls ? "Hide tool calls" : "Show tool calls"
750
- }
751
- ) }) }) : null,
752
- /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
753
- "div",
754
- {
755
- ref: scrollContainerRef,
756
- className: "min-h-0 flex-1 overflow-y-auto overflow-x-hidden [overflow-anchor:none]",
757
- onScroll: (event) => {
758
- stickToBottomRef.current = isNearBottom(event.currentTarget);
759
- },
760
- children: /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(
761
- "div",
762
- {
763
- ref: contentRef,
764
- className: (0, import_utils.cn)(
765
- "mx-auto flex min-h-full w-full max-w-[912px] flex-col gap-8 px-4 pt-6",
766
- visibleMessages.length > 0 ? "justify-end" : null,
767
- hasOverlay ? "pb-24" : "pb-6"
768
- ),
769
- children: [
770
- isLoading ? /* @__PURE__ */ (0, import_jsx_runtime.jsx)("div", { className: "flex flex-1 items-center justify-center py-20", children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_spinner.Spinner, { size: "lg", className: "text-muted-foreground" }) }) : visibleMessages.length === 0 && emptyStateTitle ? /* @__PURE__ */ (0, import_jsx_runtime.jsx)(EmptyState, { title: emptyStateTitle, description: emptyStateDescription }) : null,
771
- visibleMessages.map((message, index) => {
772
- const previous = index > 0 ? visibleMessages[index - 1] : null;
773
- if (message.tagName === "message") {
774
- return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
775
- ThreadMessage,
776
- {
777
- room,
778
- message,
779
- previous,
780
- localParticipantName,
781
- onImageSettled: handleImageSettled
782
- },
783
- message.id
784
- );
785
- }
786
- if (message.tagName === "reasoning") {
787
- return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(ThreadReasoning, { message }, message.id);
788
- }
789
- if (message.tagName === "exec") {
790
- return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(ThreadExec, { message }, message.id);
791
- }
792
- if (message.tagName === "event") {
793
- return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(EventRow, { room, message }, message.id);
794
- }
795
- return null;
796
- })
797
- ]
798
- }
799
- )
800
- }
801
- ),
802
- hasOverlay ? /* @__PURE__ */ (0, import_jsx_runtime.jsx)("div", { className: "pointer-events-none absolute inset-x-0 bottom-0 flex justify-center px-4 pb-4", children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)("div", { className: "pointer-events-auto w-full max-w-[912px]", children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
803
- import_chat_typing_indicator.ChatTypingIndicator,
804
- {
805
- typing,
806
- thinking,
807
- statusText: threadStatusText,
808
- startedAt: threadStatusStartedAt,
809
- onCancel: onCancelRequest,
810
- showCancelButton: threadStatusMode != null,
811
- cancelEnabled: !isCancellingThreadStatusText(threadStatusText)
812
- }
813
- ) }) }) : null
814
- ] });
815
- }