@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.
Files changed (95) hide show
  1. package/CHANGELOG.md +14 -0
  2. package/dist/cjs/chat/agent-thread-message-status-store.d.ts +105 -0
  3. package/dist/cjs/chat/agent-thread-message-status-store.js +617 -0
  4. package/dist/cjs/chat/agent-thread.d.ts +76 -4
  5. package/dist/cjs/chat/agent-thread.js +1114 -54
  6. package/dist/cjs/chat/chat-bot-view.d.ts +7 -4
  7. package/dist/cjs/chat/chat-bot-view.js +33 -525
  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 +3 -1
  15. package/dist/cjs/chat/multi-thread-view.js +4 -2
  16. package/dist/cjs/chat/new-chat-thread.d.ts +3 -1
  17. package/dist/cjs/chat/new-chat-thread.js +7 -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 +41 -5
  40. package/dist/cjs/index.d.ts +3 -0
  41. package/dist/cjs/index.js +13 -0
  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 +105 -0
  47. package/dist/esm/chat/agent-thread-message-status-store.js +614 -0
  48. package/dist/esm/chat/agent-thread.d.ts +76 -4
  49. package/dist/esm/chat/agent-thread.js +1132 -56
  50. package/dist/esm/chat/chat-bot-view.d.ts +7 -4
  51. package/dist/esm/chat/chat-bot-view.js +40 -555
  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 +3 -1
  59. package/dist/esm/chat/multi-thread-view.js +4 -2
  60. package/dist/esm/chat/new-chat-thread.d.ts +3 -1
  61. package/dist/esm/chat/new-chat-thread.js +8 -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 +29 -3
  84. package/dist/esm/index.d.ts +3 -0
  85. package/dist/esm/index.js +9 -0
  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 +4 -4
  92. package/dist/cjs/chat/chat-bot-view.test.js +0 -325
  93. package/dist/cjs/chat/live-chat-widgets.test.js +0 -256
  94. package/dist/esm/chat/chat-bot-view.test.js +0 -336
  95. package/dist/esm/chat/live-chat-widgets.test.js +0 -262
@@ -1,6 +1,6 @@
1
1
  import { Element, MeshDocument, Participant, RemoteParticipant, RoomClient } from "@meshagent/meshagent";
2
- import { ChatMessage } from "./chat-message.js";
3
- import { type FileUpload } from "./file-attachment.js";
2
+ import { ChatMessage } from "./chat-message";
3
+ import type { FileUpload } from "./file-attachment";
4
4
  export interface UseChatThreadProps {
5
5
  room: RoomClient;
6
6
  path: string;
@@ -35,8 +35,9 @@ export declare class PendingAgentMessage {
35
35
  readonly createdAt?: Date;
36
36
  readonly matchByContentOnly: boolean;
37
37
  readonly awaitingAcceptance: boolean;
38
+ readonly awaitingApplication: boolean;
38
39
  readonly awaitingOnline: boolean;
39
- constructor({ messageId, messageType, threadPath, text, attachments, senderName, createdAt, matchByContentOnly, awaitingAcceptance, awaitingOnline, }: {
40
+ constructor({ messageId, messageType, threadPath, text, attachments, senderName, createdAt, matchByContentOnly, awaitingAcceptance, awaitingApplication, awaitingOnline, }: {
40
41
  messageId: string;
41
42
  messageType: string;
42
43
  threadPath: string;
@@ -46,6 +47,7 @@ export declare class PendingAgentMessage {
46
47
  createdAt?: Date;
47
48
  matchByContentOnly?: boolean;
48
49
  awaitingAcceptance?: boolean;
50
+ awaitingApplication?: boolean;
49
51
  awaitingOnline?: boolean;
50
52
  });
51
53
  static fromQueueJson(json: Record<string, unknown>): PendingAgentMessage;
@@ -76,6 +78,5 @@ export interface UseThreadStatusProps {
76
78
  agentName?: string;
77
79
  previous?: ChatThreadStatusState;
78
80
  }
79
- export declare function formatThreadStatusText(text: string, startedAt?: Date | null): string;
80
- export declare function useChatThread({ room, path, participants, participantNames, initialMessage, includeLocalParticipant, agentName, useAgentMessages, messageType, turnId, }: UseChatThreadProps): UseChatThreadResult;
81
+ export declare function formatThreadStatusText(text: string, startedAt?: Date | null, totalBytes?: number | null, linesAdded?: number | null, linesRemoved?: number | null): string;
81
82
  export declare function useThreadStatus({ room, path, agentName }: UseThreadStatusProps): ThreadStatus;
@@ -1,18 +1,9 @@
1
- import { useCallback, useEffect, useMemo, useRef, useState } from "react";
1
+ import { useEffect, useState } from "react";
2
2
  import {
3
3
  RoomMessageEvent
4
4
  } from "@meshagent/meshagent";
5
- import { subscribe, useDocumentChanged, useRoomParticipants } from "@meshagent/meshagent-react";
6
- import { MeshagentFileUpload, fileToAsyncIterable } from "./file-attachment.js";
7
- const agentRoomMessageType = "agent-message";
8
- const agentTurnStartType = "meshagent.agent.turn.start";
5
+ import { subscribe } from "@meshagent/meshagent-react";
9
6
  const agentTurnSteerType = "meshagent.agent.turn.steer";
10
- class ChatSendCancelledError extends Error {
11
- constructor() {
12
- super("chat send cancelled");
13
- this.name = "ChatSendCancelledError";
14
- }
15
- }
16
7
  class PendingAgentMessage {
17
8
  messageId;
18
9
  messageType;
@@ -23,6 +14,7 @@ class PendingAgentMessage {
23
14
  createdAt;
24
15
  matchByContentOnly;
25
16
  awaitingAcceptance;
17
+ awaitingApplication;
26
18
  awaitingOnline;
27
19
  constructor({
28
20
  messageId,
@@ -34,6 +26,7 @@ class PendingAgentMessage {
34
26
  createdAt,
35
27
  matchByContentOnly = false,
36
28
  awaitingAcceptance = false,
29
+ awaitingApplication = false,
37
30
  awaitingOnline = false
38
31
  }) {
39
32
  this.messageId = messageId;
@@ -45,6 +38,7 @@ class PendingAgentMessage {
45
38
  this.createdAt = createdAt;
46
39
  this.matchByContentOnly = matchByContentOnly;
47
40
  this.awaitingAcceptance = awaitingAcceptance;
41
+ this.awaitingApplication = awaitingApplication;
48
42
  this.awaitingOnline = awaitingOnline;
49
43
  }
50
44
  static fromQueueJson(json) {
@@ -86,6 +80,7 @@ class PendingAgentMessage {
86
80
  senderName: typeof senderName === "string" && senderName.trim().length > 0 ? senderName.trim() : void 0,
87
81
  createdAt: parsedCreatedAt instanceof Date && !Number.isNaN(parsedCreatedAt.getTime()) ? parsedCreatedAt : void 0,
88
82
  matchByContentOnly: false,
83
+ awaitingApplication: true,
89
84
  awaitingOnline: false
90
85
  });
91
86
  }
@@ -119,251 +114,12 @@ class ChatThreadStatusState {
119
114
  return this.text != null && this.text.trim().length > 0;
120
115
  }
121
116
  }
122
- function getParticipantName(participant) {
123
- const name = participant.getAttribute("name");
124
- return typeof name === "string" ? name.trim() : "";
125
- }
126
- function matchesParticipantName(participant, participantName) {
127
- const normalizedParticipantName = participantName?.trim();
128
- if (!normalizedParticipantName) {
129
- return true;
130
- }
131
- return getParticipantName(participant) === normalizedParticipantName;
132
- }
133
- function ensureParticipants(document, localParticipant, includeLocalParticipant, participants, participantNames) {
134
- const nextParticipants = [
135
- ...participants,
136
- ...includeLocalParticipant ? [localParticipant] : []
137
- ];
138
- const existing = /* @__PURE__ */ new Set();
139
- const children = document.root.getChildren();
140
- for (const child of children) {
141
- if (child.tagName !== "members") {
142
- continue;
143
- }
144
- const members = child.getChildren();
145
- for (const member of members) {
146
- const name = getParticipantName(member);
147
- if (name !== "") {
148
- existing.add(name);
149
- }
150
- }
151
- for (const participant of nextParticipants) {
152
- const name = getParticipantName(participant);
153
- if (name !== "" && !existing.has(name)) {
154
- child.createChildElement("member", { name });
155
- existing.add(name);
156
- }
157
- }
158
- for (const name of participantNames) {
159
- const trimmed = name.trim();
160
- if (trimmed !== "" && !existing.has(trimmed)) {
161
- child.createChildElement("member", { name: trimmed });
162
- existing.add(trimmed);
163
- }
164
- }
165
- }
166
- }
167
- function mapThreadElements(document) {
168
- const children = document.root.getChildren();
169
- const thread = children.find((child) => child.tagName === "messages");
170
- return [...thread?.getChildren() ?? []];
171
- }
172
- function getDocumentParticipantNames(document) {
173
- const children = document.root.getChildren();
174
- const membersElement = children.find((child) => child.tagName === "members");
175
- const members = membersElement?.getChildren() ?? [];
176
- const participantNames = [];
177
- for (const member of members) {
178
- const name = getParticipantName(member);
179
- if (name !== "") {
180
- participantNames.push(name);
181
- }
182
- }
183
- return participantNames;
184
- }
185
117
  function stringArraysEqual(left, right) {
186
118
  return left.length === right.length && left.every((value, index) => value === right[index]);
187
119
  }
188
- function getOnlineParticipants(roomParticipants, participantNames) {
189
- const participantSet = new Set(participantNames);
190
- return Array.from(roomParticipants).filter((participant) => {
191
- const name = getParticipantName(participant);
192
- return name !== "" && participantSet.has(name);
193
- });
194
- }
195
120
  function supportsAgentMessages(participant) {
196
121
  return participant.getAttribute("supports_agent_messages") === true;
197
122
  }
198
- function uniqueRemoteParticipantsById(participants) {
199
- const seenParticipantIds = /* @__PURE__ */ new Set();
200
- const uniqueParticipants = [];
201
- for (const participant of participants) {
202
- if (seenParticipantIds.has(participant.id)) {
203
- continue;
204
- }
205
- seenParticipantIds.add(participant.id);
206
- uniqueParticipants.push(participant);
207
- }
208
- return uniqueParticipants;
209
- }
210
- function getAgentParticipants({
211
- room,
212
- document,
213
- participantName
214
- }) {
215
- const normalizedParticipantName = participantName?.trim();
216
- return uniqueRemoteParticipantsById(
217
- getOnlineParticipants(room.messaging.remoteParticipants, getDocumentParticipantNames(document)).filter((participant) => {
218
- if (normalizedParticipantName && getParticipantName(participant) !== normalizedParticipantName) {
219
- return false;
220
- }
221
- return supportsAgentMessages(participant);
222
- })
223
- );
224
- }
225
- function matchingRecipients({
226
- room,
227
- document,
228
- useAgentMessages,
229
- participantName
230
- }) {
231
- const normalizedParticipantName = participantName?.trim();
232
- if (useAgentMessages) {
233
- return getAgentParticipants({ room, document, participantName: normalizedParticipantName });
234
- }
235
- return uniqueRemoteParticipantsById(
236
- getOnlineParticipants(room.messaging.remoteParticipants, getDocumentParticipantNames(document)).filter((participant) => {
237
- if (!normalizedParticipantName) {
238
- return true;
239
- }
240
- return getParticipantName(participant) === normalizedParticipantName;
241
- })
242
- );
243
- }
244
- function normalizeAgentAttachmentUrl(path) {
245
- const trimmedPath = path.trim();
246
- if (trimmedPath === "") {
247
- return null;
248
- }
249
- try {
250
- const url = new URL(trimmedPath);
251
- if (url.protocol !== "") {
252
- return trimmedPath;
253
- }
254
- } catch {
255
- }
256
- const roomPath = trimmedPath.startsWith("/") ? trimmedPath.slice(1) : trimmedPath;
257
- return roomPath === "" ? null : `room:///${roomPath}`;
258
- }
259
- function agentInputContentFromMessage(message) {
260
- const content = [];
261
- if (message.text.trim() !== "") {
262
- content.push({ type: "text", text: message.text });
263
- }
264
- for (const attachmentPath of message.attachments) {
265
- const normalizedUrl = normalizeAgentAttachmentUrl(attachmentPath);
266
- if (normalizedUrl !== null) {
267
- content.push({ type: "file", url: normalizedUrl });
268
- }
269
- }
270
- return content;
271
- }
272
- async function sendMessageToParticipant({
273
- room,
274
- participant,
275
- path,
276
- message,
277
- messageType = "chat",
278
- useAgentMessages = false,
279
- turnId,
280
- store = false
281
- }) {
282
- if (message.text.trim() === "" && message.attachments.length === 0) {
283
- return;
284
- }
285
- if (useAgentMessages) {
286
- const isSteer = messageType === "steer";
287
- const payload = {
288
- type: isSteer ? agentTurnSteerType : agentTurnStartType,
289
- thread_id: path,
290
- message_id: message.id,
291
- content: agentInputContentFromMessage(message)
292
- };
293
- if (isSteer && turnId?.trim()) {
294
- payload.turn_id = turnId.trim();
295
- }
296
- await room.messaging.sendMessage({
297
- to: participant,
298
- type: agentRoomMessageType,
299
- message: payload
300
- });
301
- return;
302
- }
303
- await room.messaging.sendMessage({
304
- to: participant,
305
- type: messageType,
306
- message: {
307
- path,
308
- text: message.text,
309
- attachments: message.attachments.map((attachmentPath) => ({ path: attachmentPath })),
310
- store
311
- }
312
- });
313
- }
314
- function waitForRecipients({
315
- room,
316
- document,
317
- messageId,
318
- useAgentMessages,
319
- participantName,
320
- pendingRecipientWaits
321
- }) {
322
- pendingRecipientWaits.get(messageId)?.();
323
- return new Promise((resolve, reject) => {
324
- let finished = false;
325
- const eventNames = [
326
- "participant_added",
327
- "participant_removed",
328
- "participant_attributes_updated",
329
- "messaging_enabled"
330
- ];
331
- const finish = () => {
332
- if (finished) {
333
- return;
334
- }
335
- finished = true;
336
- for (const eventName of eventNames) {
337
- room.messaging.off(eventName, listener);
338
- }
339
- if (pendingRecipientWaits.get(messageId) === cancel) {
340
- pendingRecipientWaits.delete(messageId);
341
- }
342
- };
343
- const cancel = () => {
344
- finish();
345
- reject(new ChatSendCancelledError());
346
- };
347
- const listener = () => {
348
- const recipients = matchingRecipients({
349
- room,
350
- document,
351
- useAgentMessages,
352
- participantName
353
- });
354
- if (recipients.length === 0) {
355
- return;
356
- }
357
- finish();
358
- resolve(recipients);
359
- };
360
- pendingRecipientWaits.set(messageId, cancel);
361
- for (const eventName of eventNames) {
362
- room.messaging.on(eventName, listener);
363
- }
364
- listener();
365
- });
366
- }
367
123
  function threadStatusAttributeCandidates(path, prefix) {
368
124
  if (path.startsWith("/")) {
369
125
  return [`${prefix}.${path}`, `${prefix}.${path.slice(1)}`];
@@ -520,232 +276,32 @@ function resolveThreadStatus({
520
276
  function pendingMessagesEqual(left, right) {
521
277
  return left.length === right.length && left.every((message, index) => {
522
278
  const other = right[index];
523
- return message.messageId === other.messageId && message.messageType === other.messageType && message.text === other.text && stringArraysEqual(message.attachments, other.attachments) && message.senderName === other.senderName && message.createdAt?.getTime() === other.createdAt?.getTime() && message.matchByContentOnly === other.matchByContentOnly && message.awaitingAcceptance === other.awaitingAcceptance && message.awaitingOnline === other.awaitingOnline;
279
+ return message.messageId === other.messageId && message.messageType === other.messageType && message.text === other.text && stringArraysEqual(message.attachments, other.attachments) && message.senderName === other.senderName && message.createdAt?.getTime() === other.createdAt?.getTime() && message.matchByContentOnly === other.matchByContentOnly && message.awaitingAcceptance === other.awaitingAcceptance && message.awaitingApplication === other.awaitingApplication && message.awaitingOnline === other.awaitingOnline;
524
280
  });
525
281
  }
526
282
  function threadStatusEquals(left, right) {
527
283
  return left.text === right.text && left.mode === right.mode && left.startedAt?.getTime() === right.startedAt?.getTime() && left.turnId === right.turnId && left.pendingItemId === right.pendingItemId && pendingMessagesEqual(left.pendingMessages, right.pendingMessages) && left.supportsAgentMessages === right.supportsAgentMessages;
528
284
  }
529
- function formatThreadStatusText(text, startedAt) {
285
+ function formatGroupedStatusDigits(value) {
286
+ return Math.trunc(value).toLocaleString("en-US");
287
+ }
288
+ function formatStatusSecondUnit(value) {
289
+ return value === 1 ? "second" : "seconds";
290
+ }
291
+ function formatThreadStatusText(text, startedAt, totalBytes, linesAdded, linesRemoved) {
292
+ if (linesAdded != null || linesRemoved != null) {
293
+ const added = linesAdded != null ? "+" + formatGroupedStatusDigits(linesAdded) : null;
294
+ const removed = linesRemoved != null ? "-" + formatGroupedStatusDigits(linesRemoved) : null;
295
+ return [text, added, removed].filter((part) => part != null).join(" ");
296
+ }
297
+ if (totalBytes != null && totalBytes > 100) {
298
+ return text + " " + formatGroupedStatusDigits(totalBytes) + " bytes";
299
+ }
530
300
  if (!(startedAt instanceof Date) || Number.isNaN(startedAt.getTime())) {
531
301
  return text;
532
302
  }
533
303
  const elapsedSeconds = Math.max(0, Math.floor((Date.now() - startedAt.getTime()) / 1e3));
534
- return elapsedSeconds === 0 ? text : `${text} (${elapsedSeconds}s)`;
535
- }
536
- function getRetryDelayMs(retryCount) {
537
- return Math.min(6e4, 500 * 2 ** retryCount);
538
- }
539
- async function closeDocument(room, path) {
540
- try {
541
- await room.sync.close(path);
542
- } catch {
543
- }
544
- }
545
- function useChatThread({
546
- room,
547
- path,
548
- participants,
549
- participantNames,
550
- initialMessage,
551
- includeLocalParticipant,
552
- agentName,
553
- useAgentMessages = false,
554
- messageType = "chat",
555
- turnId
556
- }) {
557
- const [document, setDocument] = useState(null);
558
- const [messages, setMessages] = useState(() => document ? mapThreadElements(document) : []);
559
- const [attachments, setAttachments] = useState([]);
560
- const [documentParticipantNames, setDocumentParticipantNames] = useState(() => document ? getDocumentParticipantNames(document) : []);
561
- const initialMessageSentRef = useRef(false);
562
- const pendingRecipientWaitsRef = useRef(/* @__PURE__ */ new Map());
563
- const syncDocumentState = useCallback((nextDocument) => {
564
- const nextMessages = mapThreadElements(nextDocument);
565
- const nextParticipantNames = getDocumentParticipantNames(nextDocument);
566
- setMessages(nextMessages);
567
- setDocumentParticipantNames((current) => stringArraysEqual(current, nextParticipantNames) ? current : nextParticipantNames);
568
- }, []);
569
- useEffect(() => {
570
- let cancelled = false;
571
- let opened = false;
572
- let retryCount = 0;
573
- setDocument(null);
574
- setMessages([]);
575
- setDocumentParticipantNames([]);
576
- initialMessageSentRef.current = false;
577
- void (async () => {
578
- while (!cancelled) {
579
- try {
580
- const nextDocument = await room.sync.open(path);
581
- if (cancelled) {
582
- await closeDocument(room, path);
583
- return;
584
- }
585
- opened = true;
586
- setDocument(nextDocument);
587
- syncDocumentState(nextDocument);
588
- return;
589
- } catch (error) {
590
- if (cancelled) {
591
- return;
592
- }
593
- setDocument(null);
594
- setMessages([]);
595
- setDocumentParticipantNames([]);
596
- console.error("Failed to open document:", error);
597
- await new Promise((resolve) => {
598
- window.setTimeout(resolve, getRetryDelayMs(retryCount));
599
- });
600
- retryCount += 1;
601
- }
602
- }
603
- })();
604
- return () => {
605
- cancelled = true;
606
- if (opened) {
607
- void closeDocument(room, path);
608
- }
609
- };
610
- }, [path, room, syncDocumentState]);
611
- useEffect(() => {
612
- return () => {
613
- for (const cancel of pendingRecipientWaitsRef.current.values()) {
614
- cancel();
615
- }
616
- pendingRecipientWaitsRef.current.clear();
617
- };
618
- }, []);
619
- useEffect(() => {
620
- if (!document || !room.localParticipant) {
621
- return;
622
- }
623
- ensureParticipants(
624
- document,
625
- room.localParticipant,
626
- includeLocalParticipant ?? true,
627
- participants ?? [],
628
- participantNames ?? []
629
- );
630
- setDocumentParticipantNames((current) => {
631
- const nextParticipantNames = getDocumentParticipantNames(document);
632
- return stringArraysEqual(current, nextParticipantNames) ? current : nextParticipantNames;
633
- });
634
- }, [document, includeLocalParticipant, participantNames, participants, room.localParticipant]);
635
- useDocumentChanged({
636
- document,
637
- onChanged: syncDocumentState
638
- });
639
- const selectAttachments = useCallback((files) => {
640
- const nextAttachments = files.map((file) => new MeshagentFileUpload(
641
- room,
642
- `uploaded-files/${file.name}`,
643
- fileToAsyncIterable(file),
644
- file.size
645
- ));
646
- setAttachments((current) => [...current, ...nextAttachments]);
647
- }, [room]);
648
- const roomParticipants = useRoomParticipants(room);
649
- const onlineParticipants = useMemo(
650
- () => getOnlineParticipants(roomParticipants, documentParticipantNames),
651
- [roomParticipants, documentParticipantNames]
652
- );
653
- const sendMessage = useCallback(async (message) => {
654
- if (message.text.trim() === "" && message.attachments.length === 0) {
655
- return;
656
- }
657
- const normalizedParticipantName = agentName?.trim();
658
- const storeLocally = !normalizedParticipantName && !useAgentMessages;
659
- const children = document?.root.getChildren() ?? [];
660
- const messagesElement = children.find((child) => child.tagName === "messages");
661
- if (!document || !messagesElement) {
662
- return;
663
- }
664
- if (storeLocally) {
665
- const authorName = getParticipantName(room.localParticipant);
666
- const messageElement = messagesElement.createChildElement("message", {
667
- id: message.id,
668
- text: message.text,
669
- created_at: (/* @__PURE__ */ new Date()).toISOString(),
670
- author_name: authorName,
671
- author_ref: null
672
- });
673
- for (const attachmentPath of message.attachments) {
674
- messageElement.createChildElement("file", { path: attachmentPath });
675
- }
676
- }
677
- let recipients = matchingRecipients({
678
- room,
679
- document,
680
- useAgentMessages,
681
- participantName: normalizedParticipantName
682
- });
683
- if (recipients.length === 0) {
684
- const shouldWaitForRecipient = useAgentMessages || Boolean(normalizedParticipantName);
685
- if (!shouldWaitForRecipient) {
686
- throw new Error(`no matching recipients are available for '${path}'`);
687
- }
688
- try {
689
- recipients = await waitForRecipients({
690
- room,
691
- document,
692
- messageId: message.id,
693
- useAgentMessages,
694
- participantName: normalizedParticipantName,
695
- pendingRecipientWaits: pendingRecipientWaitsRef.current
696
- });
697
- } catch (error) {
698
- if (error instanceof ChatSendCancelledError) {
699
- return;
700
- }
701
- throw error;
702
- }
703
- }
704
- await Promise.all(recipients.map((participant) => sendMessageToParticipant({
705
- room,
706
- participant,
707
- path,
708
- message,
709
- messageType,
710
- useAgentMessages,
711
- turnId,
712
- store: Boolean(normalizedParticipantName) && getParticipantName(participant) === normalizedParticipantName
713
- })));
714
- }, [agentName, document, messageType, path, room, turnId, useAgentMessages]);
715
- useEffect(() => {
716
- if (!document || !initialMessage || initialMessageSentRef.current) {
717
- return;
718
- }
719
- initialMessageSentRef.current = true;
720
- sendMessage(initialMessage);
721
- }, [document, initialMessage, sendMessage]);
722
- const cancelRequest = useCallback(() => {
723
- for (const participant of onlineParticipants) {
724
- if (!matchesParticipantName(participant, agentName)) {
725
- continue;
726
- }
727
- if (participant.role !== "agent") {
728
- continue;
729
- }
730
- room.messaging.sendMessage({
731
- to: participant,
732
- type: "cancel",
733
- message: { path }
734
- });
735
- }
736
- }, [agentName, onlineParticipants, path, room]);
737
- return {
738
- document,
739
- messages,
740
- sendMessage,
741
- selectAttachments,
742
- attachments,
743
- setAttachments,
744
- schemaFileExists: true,
745
- onlineParticipants,
746
- localParticipantName: room.localParticipant ? getParticipantName(room.localParticipant) : "",
747
- cancelRequest
748
- };
304
+ return elapsedSeconds === 0 ? text : text + " " + elapsedSeconds + " " + formatStatusSecondUnit(elapsedSeconds);
749
305
  }
750
306
  function useThreadStatus({ room, path, agentName }) {
751
307
  const [status, setStatus] = useState(() => resolveThreadStatus({ room, path, agentName }));
@@ -787,6 +343,5 @@ export {
787
343
  ChatThreadStatusState,
788
344
  PendingAgentMessage,
789
345
  formatThreadStatusText,
790
- useChatThread,
791
346
  useThreadStatus
792
347
  };
@@ -7,8 +7,22 @@ export interface ChatTypingIndicatorProps {
7
7
  thinking?: boolean;
8
8
  statusText?: string | null;
9
9
  startedAt?: Date | null;
10
+ totalBytes?: number | null;
11
+ linesAdded?: number | null;
12
+ linesRemoved?: number | null;
10
13
  onCancel?: () => void;
11
14
  showCancelButton?: boolean;
12
15
  cancelEnabled?: boolean;
13
16
  }
14
- export declare function ChatTypingIndicator({ room, path, typing, thinking, statusText, startedAt, onCancel, showCancelButton, cancelEnabled, }: ChatTypingIndicatorProps): React.ReactElement | null;
17
+ export interface ChatThreadStatusIndicatorProps {
18
+ statusText?: string | null;
19
+ startedAt?: Date | null;
20
+ totalBytes?: number | null;
21
+ linesAdded?: number | null;
22
+ linesRemoved?: number | null;
23
+ reserveSpace?: boolean;
24
+ size?: number;
25
+ className?: string;
26
+ }
27
+ export declare function ChatThreadStatusIndicator({ statusText, startedAt, totalBytes, linesAdded, linesRemoved, reserveSpace, size, className, }: ChatThreadStatusIndicatorProps): React.ReactElement | null;
28
+ export declare function ChatTypingIndicator({ room, path, typing, thinking, statusText, startedAt, totalBytes, linesAdded, linesRemoved, onCancel, showCancelButton, cancelEnabled, }: ChatTypingIndicatorProps): React.ReactElement | null;
@@ -4,7 +4,7 @@ import { useRoomIndicators } from "@meshagent/meshagent-react";
4
4
  import { LoaderCircle, X } from "lucide-react";
5
5
  import { formatThreadStatusText } from "./chat-hooks.js";
6
6
  import { cn } from "../lib/utils.js";
7
- function useStatusLabel(text, startedAt) {
7
+ function useStatusLabel(text, startedAt, totalBytes, linesAdded, linesRemoved) {
8
8
  const normalizedText = text?.trim() ?? "";
9
9
  const [tick, setTick] = React.useState(0);
10
10
  React.useEffect(() => {
@@ -17,12 +17,35 @@ function useStatusLabel(text, startedAt) {
17
17
  return () => {
18
18
  window.clearInterval(timer);
19
19
  };
20
- }, [normalizedText, startedAt]);
20
+ }, [normalizedText, startedAt, totalBytes, linesAdded, linesRemoved]);
21
21
  if (normalizedText === "") {
22
22
  return null;
23
23
  }
24
24
  void tick;
25
- return formatThreadStatusText(normalizedText, startedAt);
25
+ return formatThreadStatusText(normalizedText, startedAt, totalBytes, linesAdded, linesRemoved);
26
+ }
27
+ function ChatThreadStatusIndicator({
28
+ statusText,
29
+ startedAt,
30
+ totalBytes,
31
+ linesAdded,
32
+ linesRemoved,
33
+ reserveSpace = false,
34
+ size = 16,
35
+ className
36
+ }) {
37
+ const label = useStatusLabel(statusText, startedAt, totalBytes, linesAdded, linesRemoved);
38
+ if (label == null) {
39
+ return reserveSpace ? /* @__PURE__ */ jsx("span", { "aria-hidden": "true", style: { width: size, height: size }, className: cn("inline-block shrink-0", className) }) : null;
40
+ }
41
+ return /* @__PURE__ */ jsx("span", { title: label, className: "inline-flex shrink-0", style: { width: size, height: size }, children: /* @__PURE__ */ jsx(
42
+ LoaderCircle,
43
+ {
44
+ "aria-label": label,
45
+ className: cn("animate-spin text-muted-foreground", className),
46
+ style: { width: size, height: size }
47
+ }
48
+ ) });
26
49
  }
27
50
  function ProcessingStatusRow({
28
51
  text,
@@ -47,7 +70,7 @@ function ProcessingStatusRow({
47
70
  /* @__PURE__ */ jsx("span", { className: "relative inline-flex h-4 w-4 items-center justify-center rounded-full bg-foreground text-background", children: /* @__PURE__ */ jsx(X, { className: "h-3 w-3" }) })
48
71
  ]
49
72
  }
50
- ) : /* @__PURE__ */ jsx(LoaderCircle, { className: "h-4 w-4 animate-spin text-muted-foreground" }),
73
+ ) : /* @__PURE__ */ jsx(ChatThreadStatusIndicator, { statusText: text, reserveSpace: true }),
51
74
  /* @__PURE__ */ jsx("span", { className: "text-sm text-muted-foreground", children: text })
52
75
  ] });
53
76
  }
@@ -58,6 +81,9 @@ function ChatTypingIndicator({
58
81
  thinking,
59
82
  statusText,
60
83
  startedAt,
84
+ totalBytes,
85
+ linesAdded,
86
+ linesRemoved,
61
87
  onCancel,
62
88
  showCancelButton = false,
63
89
  cancelEnabled = true
@@ -67,7 +93,10 @@ function ChatTypingIndicator({
67
93
  const resolvedThinking = thinking ?? roomIndicators.thinking;
68
94
  const resolvedStatusText = useStatusLabel(
69
95
  statusText?.trim() ? statusText : resolvedThinking ? "Thinking" : null,
70
- startedAt
96
+ startedAt,
97
+ totalBytes,
98
+ linesAdded,
99
+ linesRemoved
71
100
  );
72
101
  if (resolvedStatusText) {
73
102
  return /* @__PURE__ */ jsx(
@@ -105,5 +134,6 @@ function ChatTypingIndicator({
105
134
  ] });
106
135
  }
107
136
  export {
137
+ ChatThreadStatusIndicator,
108
138
  ChatTypingIndicator
109
139
  };