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