@meshagent/meshagent-tailwind 0.49.1 → 0.50.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (41) hide show
  1. package/CHANGELOG.md +6 -0
  2. package/dist/cjs/chat/agent-thread.d.ts +10 -6
  3. package/dist/cjs/chat/agent-thread.js +87 -213
  4. package/dist/cjs/chat/chat-bot-view.d.ts +5 -4
  5. package/dist/cjs/chat/chat-bot-view.js +2 -0
  6. package/dist/cjs/chat/chat-feed-widget.d.ts +3 -2
  7. package/dist/cjs/chat/chat-feed-widget.js +10 -10
  8. package/dist/cjs/chat/chat-hooks.d.ts +1 -1
  9. package/dist/cjs/chat/chat-hooks.js +1 -4
  10. package/dist/cjs/chat/chat-input.js +2 -2
  11. package/dist/cjs/chat/chat-typing-indicator.d.ts +2 -4
  12. package/dist/cjs/chat/chat-typing-indicator.js +4 -7
  13. package/dist/cjs/chat/dataset-agent-thread.d.ts +9 -6
  14. package/dist/cjs/chat/dataset-agent-thread.js +13 -3
  15. package/dist/cjs/chat/multi-thread-view.d.ts +6 -5
  16. package/dist/cjs/chat/multi-thread-view.js +2 -0
  17. package/dist/cjs/chat/new-chat-thread.d.ts +6 -4
  18. package/dist/cjs/chat/new-chat-thread.js +18 -11
  19. package/dist/cjs/chat/thread-view.d.ts +6 -5
  20. package/dist/cjs/chat/thread-view.js +21 -0
  21. package/dist/esm/chat/agent-thread.d.ts +10 -6
  22. package/dist/esm/chat/agent-thread.js +87 -213
  23. package/dist/esm/chat/chat-bot-view.d.ts +5 -4
  24. package/dist/esm/chat/chat-bot-view.js +2 -0
  25. package/dist/esm/chat/chat-feed-widget.d.ts +3 -2
  26. package/dist/esm/chat/chat-feed-widget.js +10 -10
  27. package/dist/esm/chat/chat-hooks.d.ts +1 -1
  28. package/dist/esm/chat/chat-hooks.js +1 -4
  29. package/dist/esm/chat/chat-input.js +2 -2
  30. package/dist/esm/chat/chat-typing-indicator.d.ts +2 -4
  31. package/dist/esm/chat/chat-typing-indicator.js +4 -7
  32. package/dist/esm/chat/dataset-agent-thread.d.ts +9 -6
  33. package/dist/esm/chat/dataset-agent-thread.js +13 -3
  34. package/dist/esm/chat/multi-thread-view.d.ts +6 -5
  35. package/dist/esm/chat/multi-thread-view.js +2 -0
  36. package/dist/esm/chat/new-chat-thread.d.ts +6 -4
  37. package/dist/esm/chat/new-chat-thread.js +18 -11
  38. package/dist/esm/chat/thread-view.d.ts +6 -5
  39. package/dist/esm/chat/thread-view.js +21 -0
  40. package/dist/index.css +1 -1
  41. package/package.json +6 -6
@@ -94,22 +94,6 @@ function isShellTool(message) {
94
94
  const values = [message.toolkit, message.tool].filter((value) => typeof value === "string").map((value) => value.trim().toLowerCase());
95
95
  return values.some((value) => value === "shell" || value === "exec" || value === "local_shell" || value === "local_shell_call" || value.includes("shell") || value.includes("exec"));
96
96
  }
97
- function firstNonEmptyLine(text) {
98
- for (const line of text.split(/\r?\n/)) {
99
- const trimmed = line.trim();
100
- if (trimmed !== "") {
101
- return trimmed;
102
- }
103
- }
104
- return null;
105
- }
106
- function detailGroupId(messages) {
107
- const first = messages[0];
108
- return ["details", first?.turnId ?? "", first?.id ?? "", first?.createdAt.getTime() ?? 0].join(":");
109
- }
110
- function messagesShareTurn(left, right) {
111
- return left.turnId != null && left.turnId.trim() !== "" && left.turnId === right.turnId;
112
- }
113
97
  function canCollapseAsCommentary(message) {
114
98
  if (message.phase === "final_answer") {
115
99
  return false;
@@ -210,104 +194,24 @@ function addDetailIndexesForSegment(messages, start, end, detailIndexes, chatFee
210
194
  }
211
195
  }
212
196
  }
213
- function nextNonDetailMessage(messages, detailIndexes, start, end) {
214
- for (let index = start; index < end; index += 1) {
215
- if (!detailIndexes.has(index)) {
216
- return messages[index];
217
- }
218
- }
219
- return null;
220
- }
221
- function detailGroupCollapsedMessage(messages) {
222
- for (const message of [...messages].reverse()) {
223
- if (canCollapseAsCommentary(message) && message.text.trim() !== "") {
224
- return message;
225
- }
226
- }
227
- for (const message of [...messages].reverse()) {
228
- if (message.kind === "reasoning" && message.text.trim() !== "") {
229
- return message;
230
- }
231
- }
232
- return null;
233
- }
234
- function formatDetailGroupDuration(milliseconds) {
235
- const seconds = Math.max(0, Math.round(milliseconds / 1e3));
236
- if (seconds < 60) {
237
- return `${seconds}s`;
238
- }
239
- const minutes = Math.floor(seconds / 60);
240
- const remainingSeconds = seconds % 60;
241
- return remainingSeconds === 0 ? `${minutes}m` : `${minutes}m ${remainingSeconds}s`;
242
- }
243
- function detailGroupCollapsedText(messages, nextMessage) {
244
- const first = messages[0];
245
- if (first && nextMessage != null && canRenderAsFinalAnswer(nextMessage) && messagesShareTurn(first, nextMessage)) {
246
- return `Worked for ${formatDetailGroupDuration(nextMessage.createdAt.getTime() - first.createdAt.getTime())}`;
247
- }
248
- return firstNonEmptyLine(detailGroupCollapsedMessage(messages)?.text ?? "") ?? "Working";
249
- }
250
- function detailGroupAuthorName(message, localParticipantName, agentName) {
251
- const authorName = message.authorName?.trim();
252
- if (authorName) {
253
- return authorName;
254
- }
255
- if (message.role === "user") {
256
- return localParticipantName;
257
- }
258
- return displayParticipantName(agentName);
259
- }
260
- function detailGroupForMessages(messages, nextMessage, expandedIds, localParticipantName, agentName) {
261
- const collapsedMessage = detailGroupCollapsedMessage(messages) ?? messages[0];
262
- const id = detailGroupId(messages);
263
- return {
264
- id,
265
- kind: "detail_group",
266
- messages,
267
- collapsedText: detailGroupCollapsedText(messages, nextMessage),
268
- authorName: detailGroupAuthorName(collapsedMessage, localParticipantName, agentName),
269
- createdAt: collapsedMessage.createdAt,
270
- expanded: expandedIds.has(id)
271
- };
272
- }
273
- function groupThreadItems(messages, expandedIds, localParticipantName, agentName, chatFeedWidgetsByName) {
197
+ function groupThreadItems(messages, chatFeedWidgetsByName) {
274
198
  const items = [];
275
199
  let index = 0;
276
200
  while (index < messages.length) {
277
201
  const segmentEnd = nextUserMessageIndex(messages, index + 1) ?? messages.length;
278
202
  const detailIndexes = /* @__PURE__ */ new Set();
279
203
  addDetailIndexesForSegment(messages, index, segmentEnd, detailIndexes, chatFeedWidgetsByName);
280
- const groupedMessages = [...detailIndexes].sort((left, right) => left - right).map((detailIndex) => messages[detailIndex]);
281
- let insertedDetailGroup = false;
282
204
  for (let segmentIndex = index; segmentIndex < segmentEnd; segmentIndex += 1) {
283
205
  if (!detailIndexes.has(segmentIndex)) {
284
206
  items.push(messages[segmentIndex]);
285
- continue;
286
207
  }
287
- if (insertedDetailGroup || groupedMessages.length === 0) {
288
- continue;
289
- }
290
- items.push(detailGroupForMessages(
291
- groupedMessages,
292
- nextNonDetailMessage(messages, detailIndexes, segmentIndex + 1, segmentEnd),
293
- expandedIds,
294
- localParticipantName,
295
- agentName
296
- ));
297
- insertedDetailGroup = true;
298
208
  }
299
209
  index = segmentEnd;
300
210
  }
301
211
  return items;
302
212
  }
303
213
  function previousMessageItem(items, index) {
304
- for (let cursor = index - 1; cursor >= 0; cursor -= 1) {
305
- const item = items[cursor];
306
- if (item.kind !== "detail_group") {
307
- return item;
308
- }
309
- }
310
- return null;
214
+ return index > 0 ? items[index - 1] : null;
311
215
  }
312
216
  function formatAgentUsageTokenCount(value) {
313
217
  const magnitude = Math.abs(value);
@@ -552,6 +456,10 @@ function ChatImageAttachment({ room, path }) {
552
456
  return;
553
457
  }
554
458
  setUrl(null);
459
+ if (room == null) {
460
+ setError(new Error("This attachment requires a room connection."));
461
+ return;
462
+ }
555
463
  void room.storage.downloadUrl(imagePath).then((nextUrl) => {
556
464
  if (!cancelled) {
557
465
  setUrl(nextUrl);
@@ -595,6 +503,7 @@ function AttachmentDownloadButton({ room, path, className }) {
595
503
  window.open(path, "_blank", "noopener,noreferrer");
596
504
  return;
597
505
  }
506
+ if (room == null) return;
598
507
  void room.storage.downloadUrl(preview).then((nextUrl) => {
599
508
  window.open(nextUrl, "_blank", "noopener,noreferrer");
600
509
  });
@@ -602,7 +511,7 @@ function AttachmentDownloadButton({ room, path, className }) {
602
511
  children: [
603
512
  /* @__PURE__ */ jsx(FileText, { className: "h-4 w-4 shrink-0 text-muted-foreground" }),
604
513
  /* @__PURE__ */ jsx("span", { className: "truncate text-sm font-medium", children: filename }),
605
- /* @__PURE__ */ jsx(Download, { className: "h-4 w-4 shrink-0 text-muted-foreground" })
514
+ room != null || isInlineImageUrl(path) || isHttpUrl(path) ? /* @__PURE__ */ jsx(Download, { className: "h-4 w-4 shrink-0 text-muted-foreground" }) : /* @__PURE__ */ jsx("span", { className: "shrink-0 text-xs text-muted-foreground", children: "Unavailable" })
606
515
  ]
607
516
  }
608
517
  );
@@ -614,50 +523,6 @@ function ChatThreadPreview({ room, path, className }) {
614
523
  }
615
524
  return /* @__PURE__ */ jsx(AttachmentDownloadButton, { room, path: normalizedPath, className });
616
525
  }
617
- function DetailGroupLine({ item, onToggle }) {
618
- return /* @__PURE__ */ jsxs(
619
- "button",
620
- {
621
- type: "button",
622
- className: "mx-auto flex max-w-[85%] items-center gap-2 rounded-md px-3 py-1.5 text-left text-xs text-muted-foreground transition-colors hover:bg-muted/50 hover:text-foreground sm:max-w-2xl",
623
- onClick: onToggle,
624
- "aria-expanded": item.expanded,
625
- title: item.expanded ? "Collapse details" : "Expand details",
626
- children: [
627
- item.expanded ? /* @__PURE__ */ jsx(ChevronDown, { className: "h-3.5 w-3.5 shrink-0" }) : /* @__PURE__ */ jsx(ChevronRight, { className: "h-3.5 w-3.5 shrink-0" }),
628
- /* @__PURE__ */ jsx("span", { className: "min-w-0 truncate", children: item.collapsedText }),
629
- /* @__PURE__ */ jsx("span", { className: "shrink-0", children: timeAgo(item.createdAt) })
630
- ]
631
- }
632
- );
633
- }
634
- function ExpandedDetailGroup({
635
- room,
636
- item,
637
- localParticipantName,
638
- agentName,
639
- chatFeedWidgetsByName
640
- }) {
641
- return /* @__PURE__ */ jsxs("div", { className: "flex flex-col gap-3", children: [
642
- /* @__PURE__ */ jsx("div", { className: "flex w-full justify-start", children: /* @__PURE__ */ jsx("div", { className: "max-w-[85%] px-1 text-left sm:max-w-2xl", children: /* @__PURE__ */ jsxs("div", { className: "flex flex-wrap items-center gap-x-3 gap-y-1 text-xs text-muted-foreground", children: [
643
- item.authorName.trim() !== "" ? /* @__PURE__ */ jsx("span", { className: "font-semibold text-foreground", children: displayParticipantName(item.authorName) }) : null,
644
- /* @__PURE__ */ jsx("span", { children: timeAgo(item.createdAt) })
645
- ] }) }) }),
646
- item.messages.map((message, index) => /* @__PURE__ */ jsx(
647
- ThreadMessageView,
648
- {
649
- room,
650
- message,
651
- previous: index > 0 ? item.messages[index - 1] : null,
652
- localParticipantName,
653
- agentName,
654
- chatFeedWidgetsByName,
655
- forceHideHeader: true
656
- },
657
- message.id
658
- ))
659
- ] });
660
- }
661
526
  function GeneratedImageView({ image }) {
662
527
  const completedImages = image.images?.filter((entry) => entry.uri?.trim()) ?? [];
663
528
  if (completedImages.length > 0) {
@@ -697,6 +562,7 @@ function ThreadMessageView({
697
562
  localParticipantName,
698
563
  agentName,
699
564
  chatFeedWidgetsByName,
565
+ onSendMessage,
700
566
  forceHideHeader = false
701
567
  }) {
702
568
  if (message.kind === "error") {
@@ -734,7 +600,8 @@ function ThreadMessageView({
734
600
  toolCall: {
735
601
  status,
736
602
  input: message.input ?? {},
737
- output: message.output
603
+ output: message.output,
604
+ sendMessage: onSendMessage
738
605
  },
739
606
  fallback: /* @__PURE__ */ jsx(ToolCallLine, { message })
740
607
  },
@@ -801,46 +668,46 @@ function normalizeAgentAttachmentUrl(path) {
801
668
  const roomPath = trimmedPath.startsWith("/") ? trimmedPath.slice(1) : trimmedPath;
802
669
  return roomPath === "" ? null : `room:///${roomPath}`;
803
670
  }
804
- const handledChatFeedWidgetRequests = /* @__PURE__ */ new WeakMap();
805
- const initializedChatFeedWidgetSessions = /* @__PURE__ */ new WeakSet();
806
- const replayingChatFeedWidgetSessions = /* @__PURE__ */ new WeakSet();
671
+ const handledClientToolRequests = /* @__PURE__ */ new WeakMap();
672
+ const initializedClientToolSessions = /* @__PURE__ */ new WeakSet();
673
+ const replayingClientToolSessions = /* @__PURE__ */ new WeakSet();
807
674
  function handledRequestsForSession(session) {
808
- const existing = handledChatFeedWidgetRequests.get(session);
675
+ const existing = handledClientToolRequests.get(session);
809
676
  if (existing != null) {
810
677
  return existing;
811
678
  }
812
679
  const created = /* @__PURE__ */ new Set();
813
- handledChatFeedWidgetRequests.set(session, created);
680
+ handledClientToolRequests.set(session, created);
814
681
  return created;
815
682
  }
816
- function chatFeedWidgetCallKey(threadPath, itemId) {
683
+ function clientToolCallKey(threadPath, itemId) {
817
684
  return [threadPath, itemId].join("\0");
818
685
  }
819
- function processChatFeedWidgetRequests({
686
+ function processClientToolRequests({
820
687
  session,
821
- widgetsByName,
688
+ toolsByName,
822
689
  updateCall,
823
690
  executeRequests
824
691
  }) {
825
- if (widgetsByName.size === 0) {
692
+ if (toolsByName.size === 0) {
826
693
  return;
827
694
  }
828
- const requests = session.messages.map((event) => event.message).filter((message) => message instanceof AgentClientToolCallRequested).filter((message) => message.toolkit === "client" && widgetsByName.has(message.tool));
695
+ const requests = session.messages.map((event) => event.message).filter((message) => message instanceof AgentClientToolCallRequested).filter((message) => message.toolkit === "client" && toolsByName.has(message.tool));
829
696
  const handledRequests = handledRequestsForSession(session);
830
- if (!initializedChatFeedWidgetSessions.has(session)) {
831
- initializedChatFeedWidgetSessions.add(session);
697
+ if (!initializedClientToolSessions.has(session)) {
698
+ initializedClientToolSessions.add(session);
832
699
  if (session.isLoading || session.loadState.requestMessageId != null) {
833
- replayingChatFeedWidgetSessions.add(session);
700
+ replayingClientToolSessions.add(session);
834
701
  }
835
702
  }
836
703
  if (!executeRequests) {
837
704
  return;
838
705
  }
839
- if (replayingChatFeedWidgetSessions.has(session)) {
706
+ if (replayingClientToolSessions.has(session)) {
840
707
  if (session.isLoading) {
841
708
  return;
842
709
  }
843
- replayingChatFeedWidgetSessions.delete(session);
710
+ replayingClientToolSessions.delete(session);
844
711
  const completedItemIds = new Set(session.messages.map((event) => event.message).filter((message) => message instanceof AgentToolCallEnded && message.toolkit === "client").map((message) => message.itemId));
845
712
  for (const request of requests) {
846
713
  if (completedItemIds.has(request.requestId)) {
@@ -852,8 +719,8 @@ function processChatFeedWidgetRequests({
852
719
  if (handledRequests.has(request.requestId)) {
853
720
  continue;
854
721
  }
855
- const widget = widgetsByName.get(request.tool);
856
- if (widget == null) {
722
+ const tool = toolsByName.get(request.tool);
723
+ if (tool == null) {
857
724
  continue;
858
725
  }
859
726
  if (!session.claimClientToolCall(request.requestId)) {
@@ -861,20 +728,20 @@ function processChatFeedWidgetRequests({
861
728
  continue;
862
729
  }
863
730
  handledRequests.add(request.requestId);
864
- updateCall(chatFeedWidgetCallKey(session.threadPath, request.requestId), {
731
+ updateCall(clientToolCallKey(session.threadPath, request.requestId), {
865
732
  status: "in_progress"
866
733
  });
867
734
  void (async () => {
868
735
  let response;
869
736
  let status;
870
737
  try {
871
- response = await widget.execute(request.arguments);
738
+ response = await tool.execute(request.arguments);
872
739
  status = response instanceof ErrorContent ? "failed" : "completed";
873
740
  } catch (error) {
874
741
  response = new ErrorContent({ text: describeError(error) });
875
742
  status = "failed";
876
743
  }
877
- updateCall(chatFeedWidgetCallKey(session.threadPath, request.requestId), {
744
+ updateCall(clientToolCallKey(session.threadPath, request.requestId), {
878
745
  status,
879
746
  output: response
880
747
  });
@@ -887,7 +754,7 @@ function processChatFeedWidgetRequests({
887
754
  session.finishClientToolCall(request.requestId, { responseSent: true });
888
755
  } catch (error) {
889
756
  session.finishClientToolCall(request.requestId, { responseSent: false });
890
- updateCall(chatFeedWidgetCallKey(session.threadPath, request.requestId), {
757
+ updateCall(clientToolCallKey(session.threadPath, request.requestId), {
891
758
  status: "failed",
892
759
  output: new ErrorContent({ text: describeError(error) })
893
760
  });
@@ -904,6 +771,7 @@ function AgentThread({
904
771
  emptyStateTitle = "Chat to get started",
905
772
  emptyStateDescription,
906
773
  clientToolkits,
774
+ clientTools,
907
775
  chatFeedWidgets,
908
776
  collapseMessages = true,
909
777
  suggestions,
@@ -923,8 +791,7 @@ function AgentThread({
923
791
  const [restorationError, setRestorationError] = useState(null);
924
792
  const [restorationAttempt, setRestorationAttempt] = useState(0);
925
793
  const [version, setVersion] = useState(0);
926
- const [expandedDetailGroupIds, setExpandedDetailGroupIds] = useState(() => /* @__PURE__ */ new Set());
927
- const [chatFeedWidgetCallOverrides, setChatFeedWidgetCallOverrides] = useState(() => /* @__PURE__ */ new Map());
794
+ const [clientToolCallOverrides, setClientToolCallOverrides] = useState(() => /* @__PURE__ */ new Map());
928
795
  const sessionRef = useRef(null);
929
796
  const mountedRef = useRef(true);
930
797
  const persistedEventsRef = useRef(persistedEvents);
@@ -934,29 +801,44 @@ function AgentThread({
934
801
  const pendingCloseRef = useRef(null);
935
802
  const ownsChatClient = chatClient == null;
936
803
  const activeChatClient = useMemo(
937
- () => chatClient ?? new MessagingChatClient({ room, agentName }),
804
+ () => {
805
+ if (chatClient != null) return chatClient;
806
+ if (room != null) return new MessagingChatClient({ room, agentName });
807
+ throw new Error("AgentThread requires either a room or a chat client.");
808
+ },
938
809
  [agentName, chatClient, room]
939
810
  );
940
811
  const resolvedClientToolkits = useMemo(
941
- () => resolveClientToolkitDescriptions(clientToolkits, chatFeedWidgets),
942
- [chatFeedWidgets, clientToolkits]
812
+ () => resolveClientToolkitDescriptions(clientToolkits, chatFeedWidgets, clientTools),
813
+ [chatFeedWidgets, clientToolkits, clientTools]
943
814
  );
944
815
  const chatFeedWidgetsByName = useMemo(
945
816
  () => new Map((chatFeedWidgets ?? []).map((widget) => [widget.name, widget])),
946
817
  [chatFeedWidgets]
947
818
  );
948
- const updateChatFeedWidgetCall = useCallback((callKey, override) => {
819
+ const clientToolsByName = useMemo(
820
+ () => new Map((clientTools ?? []).map((tool) => [tool.name, tool])),
821
+ [clientTools]
822
+ );
823
+ const clientToolExecutorsByName = useMemo(
824
+ () => new Map([
825
+ ...(clientTools ?? []).map((tool) => [tool.name, tool]),
826
+ ...(chatFeedWidgets ?? []).map((widget) => [widget.name, widget])
827
+ ]),
828
+ [chatFeedWidgets, clientTools]
829
+ );
830
+ const updateClientToolCall = useCallback((callKey, override) => {
949
831
  if (!mountedRef.current) {
950
832
  return;
951
833
  }
952
- setChatFeedWidgetCallOverrides((current) => {
834
+ setClientToolCallOverrides((current) => {
953
835
  const next = new Map(current);
954
836
  next.set(callKey, override);
955
837
  return next;
956
838
  });
957
839
  }, []);
958
- const localParticipantName = getParticipantName(room.localParticipant);
959
- const agentParticipant = activeChatClient.agentParticipant() ?? findAgentParticipant(room, agentName);
840
+ const localParticipantName = room == null ? activeChatClient.localParticipantName() ?? "" : getParticipantName(room.localParticipant);
841
+ const agentParticipant = activeChatClient.agentParticipant() ?? (room == null ? null : findAgentParticipant(room, agentName));
960
842
  useEffect(() => {
961
843
  mountedRef.current = true;
962
844
  return () => {
@@ -1034,10 +916,10 @@ function AgentThread({
1034
916
  };
1035
917
  const handleChange = () => {
1036
918
  synchronizeThreadLoadState();
1037
- processChatFeedWidgetRequests({
919
+ processClientToolRequests({
1038
920
  session: session2,
1039
- widgetsByName: chatFeedWidgetsByName,
1040
- updateCall: updateChatFeedWidgetCall,
921
+ toolsByName: clientToolExecutorsByName,
922
+ updateCall: updateClientToolCall,
1041
923
  executeRequests: !deferLiveEvents && restorationReadyRef.current
1042
924
  });
1043
925
  const latestMessage = session2.messages[session2.messages.length - 1]?.message;
@@ -1151,7 +1033,7 @@ function AgentThread({
1151
1033
  };
1152
1034
  }, [
1153
1035
  activeChatClient,
1154
- chatFeedWidgetsByName,
1036
+ clientToolExecutorsByName,
1155
1037
  closeThreadOnUnmount,
1156
1038
  deferLiveEvents,
1157
1039
  injectPersistedEvents,
@@ -1161,7 +1043,7 @@ function AgentThread({
1161
1043
  onPersistedEventsInjected,
1162
1044
  path,
1163
1045
  restorationAttempt,
1164
- updateChatFeedWidgetCall
1046
+ updateClientToolCall
1165
1047
  ]);
1166
1048
  const retryRestoration = useCallback(() => {
1167
1049
  restoredPathRef.current = null;
@@ -1181,7 +1063,7 @@ function AgentThread({
1181
1063
  return persistedEvents == null ? buildChatThreadTimeline(session.messages, session.pendingInputs) : buildMergedChatThreadTimeline(persistedEvents, session.messages, session.pendingInputs);
1182
1064
  }, [deferLiveEvents, persistedEvents, session, version]);
1183
1065
  const timelineItems = useMemo(() => (timeline?.items ?? []).map((item) => {
1184
- const override = session == null ? void 0 : chatFeedWidgetCallOverrides.get(chatFeedWidgetCallKey(session.threadPath, item.id));
1066
+ const override = session == null ? void 0 : clientToolCallOverrides.get(clientToolCallKey(session.threadPath, item.id));
1185
1067
  if (override == null || item.kind !== "tool_call" || (item.state === "completed" || item.state === "failed")) {
1186
1068
  return item;
1187
1069
  }
@@ -1191,17 +1073,17 @@ function AgentThread({
1191
1073
  failed: override.status === "failed",
1192
1074
  output: override.output ?? item.output
1193
1075
  };
1194
- }), [chatFeedWidgetCallOverrides, session, timeline]);
1076
+ }), [clientToolCallOverrides, session, timeline]);
1195
1077
  const showThreadLoading = (deferLiveEvents || session === null || session.isLoading) && timelineItems.length === 0;
1196
1078
  const followUpSuggestions = useMemo(
1197
1079
  () => latestTurnFollowUpSuggestions(timelineItems, chatFeedWidgetsByName),
1198
1080
  [chatFeedWidgetsByName, timelineItems]
1199
1081
  );
1200
1082
  const feedTimelineItems = useMemo(
1201
- () => timelineItems.filter((item) => !isFollowUpSuggestionCall(item, chatFeedWidgetsByName)),
1202
- [chatFeedWidgetsByName, timelineItems]
1083
+ () => timelineItems.filter((item) => !isFollowUpSuggestionCall(item, chatFeedWidgetsByName) && !(item.kind === "tool_call" && item.toolkit === "client" && item.tool != null && clientToolsByName.has(item.tool))),
1084
+ [chatFeedWidgetsByName, clientToolsByName, timelineItems]
1203
1085
  );
1204
- const renderedItems = useMemo(() => collapseMessages ? groupThreadItems(feedTimelineItems, expandedDetailGroupIds, localParticipantName, agentName, chatFeedWidgetsByName) : feedTimelineItems, [agentName, chatFeedWidgetsByName, collapseMessages, expandedDetailGroupIds, feedTimelineItems, localParticipantName]);
1086
+ const renderedItems = useMemo(() => collapseMessages ? groupThreadItems(feedTimelineItems, chatFeedWidgetsByName) : feedTimelineItems, [chatFeedWidgetsByName, collapseMessages, feedTimelineItems]);
1205
1087
  const status = useMemo(() => {
1206
1088
  if (session == null) return null;
1207
1089
  let current = null;
@@ -1234,6 +1116,7 @@ function AgentThread({
1234
1116
  return previousById;
1235
1117
  }, [renderedItems]);
1236
1118
  const selectAttachments = useCallback((files) => {
1119
+ if (room == null) return;
1237
1120
  const nextAttachments = files.map((file) => new MeshagentFileUpload(
1238
1121
  room,
1239
1122
  `uploaded-files/${file.name}`,
@@ -1287,6 +1170,16 @@ function AgentThread({
1287
1170
  text
1288
1171
  }));
1289
1172
  }, [handleSend]);
1173
+ const handleWidgetMessage = useCallback((message) => {
1174
+ const text = message.trim();
1175
+ if (text === "" || composerDisabled) {
1176
+ return;
1177
+ }
1178
+ void handleSend(new ChatMessage({
1179
+ id: uuidV4(),
1180
+ text
1181
+ }));
1182
+ }, [composerDisabled, handleSend]);
1290
1183
  const cancelTurn = useCallback(async () => {
1291
1184
  const openSession = sessionRef.current;
1292
1185
  if (openSession === null || turnId == null) {
@@ -1294,17 +1187,6 @@ function AgentThread({
1294
1187
  }
1295
1188
  await openSession.interruptTurn(turnId);
1296
1189
  }, [turnId]);
1297
- const toggleDetailGroup = useCallback((id) => {
1298
- setExpandedDetailGroupIds((current) => {
1299
- const next = new Set(current);
1300
- if (next.has(id)) {
1301
- next.delete(id);
1302
- } else {
1303
- next.add(id);
1304
- }
1305
- return next;
1306
- });
1307
- }, []);
1308
1190
  return /* @__PURE__ */ jsxs("div", { className: "flex h-full min-h-0 flex-1 flex-col", children: [
1309
1191
  /* @__PURE__ */ jsxs("div", { className: "relative flex h-full min-h-0 flex-1 flex-col", children: [
1310
1192
  showThreadLoading ? /* @__PURE__ */ jsx("div", { className: "min-h-0 flex-1 overflow-hidden", children: /* @__PURE__ */ jsx(LoadingState, {}) }) : timelineItems.length === 0 ? /* @__PURE__ */ jsx("div", { className: "min-h-0 flex-1 overflow-hidden", children: /* @__PURE__ */ jsx(EmptyState, { title: emptyStateTitle, description: emptyStateDescription }) }) : /* @__PURE__ */ jsx(
@@ -1313,23 +1195,14 @@ function AgentThread({
1313
1195
  bottomThresholdPx: 24,
1314
1196
  className: "flex-1 overflow-x-hidden",
1315
1197
  currentUserId: "user",
1316
- getMessageAuthorId: (item) => item.kind === "detail_group" ? "agent" : item.role,
1198
+ getMessageAuthorId: (item) => item.role,
1317
1199
  messages: renderedItemsNewestFirst,
1318
1200
  renderMessage: (item) => {
1319
1201
  return /* @__PURE__ */ jsx("div", { className: cn(
1320
1202
  "mx-auto w-full max-w-[912px] px-1 py-3",
1321
1203
  item.id === firstRenderedItemId ? "pt-6" : null,
1322
1204
  item.id === lastRenderedItemId ? statusText ? "pb-24" : "pb-6" : null
1323
- ), children: item.kind === "detail_group" ? item.expanded ? /* @__PURE__ */ jsx(
1324
- ExpandedDetailGroup,
1325
- {
1326
- room,
1327
- item,
1328
- localParticipantName,
1329
- agentName,
1330
- chatFeedWidgetsByName
1331
- }
1332
- ) : /* @__PURE__ */ jsx(DetailGroupLine, { item, onToggle: () => toggleDetailGroup(item.id) }) : /* @__PURE__ */ jsx(
1205
+ ), children: /* @__PURE__ */ jsx(
1333
1206
  ThreadMessageView,
1334
1207
  {
1335
1208
  room,
@@ -1337,7 +1210,8 @@ function AgentThread({
1337
1210
  previous: previousItemById.get(item.id) ?? null,
1338
1211
  localParticipantName,
1339
1212
  agentName,
1340
- chatFeedWidgetsByName
1213
+ chatFeedWidgetsByName,
1214
+ onSendMessage: handleWidgetMessage
1341
1215
  }
1342
1216
  ) });
1343
1217
  }
@@ -1350,7 +1224,6 @@ function AgentThread({
1350
1224
  thinking: false,
1351
1225
  statusText,
1352
1226
  startedAt: dateFromString(status?.startedAt),
1353
- totalBytes: status?.totalBytes,
1354
1227
  linesAdded: status?.linesAdded,
1355
1228
  linesRemoved: status?.linesRemoved,
1356
1229
  onCancel: canInterruptActiveTurn ? cancelTurn : void 0,
@@ -1372,16 +1245,17 @@ function AgentThread({
1372
1245
  "ul",
1373
1246
  {
1374
1247
  "aria-label": "Follow-up suggestions",
1375
- className: "mx-auto flex flex-wrap w-full max-w-[912px] gap-2 overflow-x-auto px-4 pt-2 pb-1",
1376
- children: visibleSuggestions.map((suggestion, index) => /* @__PURE__ */ jsx("li", { className: "shrink-0", children: /* @__PURE__ */ jsx(
1248
+ className: "mx-auto flex w-full max-w-[912px] flex-wrap gap-2 px-4 pt-2 pb-1",
1249
+ children: visibleSuggestions.map((suggestion, index) => /* @__PURE__ */ jsx("li", { className: "min-w-0 max-w-full", children: /* @__PURE__ */ jsx(
1377
1250
  Button,
1378
1251
  {
1379
1252
  type: "button",
1380
1253
  variant: "outline",
1381
- className: "h-auto min-h-8 rounded-full px-3 py-1.5",
1254
+ className: "h-auto min-h-8 max-w-full overflow-hidden rounded-full px-3 py-1.5 text-left text-sm leading-snug",
1255
+ title: suggestion.label,
1382
1256
  disabled: composerDisabled,
1383
1257
  onClick: () => handleSuggestionClick(suggestion),
1384
- children: suggestion.label
1258
+ children: /* @__PURE__ */ jsx("span", { className: "min-w-0 truncate", children: suggestion.label })
1385
1259
  }
1386
1260
  ) }, index))
1387
1261
  }
@@ -1393,7 +1267,7 @@ function AgentThread({
1393
1267
  attachments,
1394
1268
  onFilesSelected: selectAttachments,
1395
1269
  setAttachments,
1396
- enableFileUpload,
1270
+ enableFileUpload: enableFileUpload && room != null,
1397
1271
  disabled: composerDisabled,
1398
1272
  placeholder: agentParticipant || chatClient ? "Type a message" : `Waiting for ${displayParticipantName(agentName)}`
1399
1273
  }
@@ -1,5 +1,5 @@
1
1
  import type { ReactElement } from "react";
2
- import type { Participant, RoomClient } from "@meshagent/meshagent";
2
+ import type { Participant, RoomClient, Tool } from "@meshagent/meshagent";
3
3
  import type { AgentMessage, AgentMessageEvent, BaseChatClient, ClientToolkitDescription } from "@meshagent/meshagent-agents";
4
4
  import type { AgentToolChoice } from "./agent-thread.js";
5
5
  import type { DatasetThreadRowsLoader } from "./dataset-agent-thread.js";
@@ -33,8 +33,9 @@ export interface ChatBotViewProps {
33
33
  showThreadList?: boolean;
34
34
  threadListWidth?: number;
35
35
  threadListCollapsedHeight?: number;
36
- clientToolkits?: ClientToolkitDescription[];
37
- chatFeedWidgets?: ChatFeedWidget[];
36
+ clientToolkits?: readonly ClientToolkitDescription[];
37
+ clientTools?: readonly Tool[];
38
+ chatFeedWidgets?: readonly ChatFeedWidget[];
38
39
  toolChoice?: AgentToolChoice;
39
40
  collapseMessages?: boolean;
40
41
  enableFileUpload?: boolean;
@@ -50,4 +51,4 @@ export interface ChatBotViewProps {
50
51
  onEventsChanged?: (threadId: string, events: readonly AgentMessageEvent[], latestMessage: AgentMessage | null) => void;
51
52
  onThreadStarted?: (threadId: string, events: readonly AgentMessageEvent[]) => Promise<void> | void;
52
53
  }
53
- export declare function ChatBotView({ room, chatClient, disposeChatClient, path, documentPath, agentName, threadDisplayMode, threadDir, toolkit, tool, centerComposer, emptyStateTitle, emptyStateDescription, startNewThreadTitle, startNewThreadDescription, selectedThreadPath, selectedThreadDisplayName, onSelectedThreadPathChanged, onSelectedThreadResolved, onThreadResolved, newThreadResetVersion, showThreadList, threadListWidth, threadListCollapsedHeight, clientToolkits, chatFeedWidgets, toolChoice, collapseMessages, enableFileUpload, threadSource, rowsLoader, persistedEvents, loadThread, injectPersistedEvents, composerDisabled, closeThreadOnUnmount, onPersistedEventsInjectionStarted, onPersistedEventsInjected, onEventsChanged, onThreadStarted, }: ChatBotViewProps): ReactElement;
54
+ export declare function ChatBotView({ room, chatClient, disposeChatClient, path, documentPath, agentName, threadDisplayMode, threadDir, toolkit, tool, centerComposer, emptyStateTitle, emptyStateDescription, startNewThreadTitle, startNewThreadDescription, selectedThreadPath, selectedThreadDisplayName, onSelectedThreadPathChanged, onSelectedThreadResolved, onThreadResolved, newThreadResetVersion, showThreadList, threadListWidth, threadListCollapsedHeight, clientToolkits, clientTools, chatFeedWidgets, toolChoice, collapseMessages, enableFileUpload, threadSource, rowsLoader, persistedEvents, loadThread, injectPersistedEvents, composerDisabled, closeThreadOnUnmount, onPersistedEventsInjectionStarted, onPersistedEventsInjected, onEventsChanged, onThreadStarted, }: ChatBotViewProps): ReactElement;
@@ -59,6 +59,7 @@ function ChatBotView({
59
59
  threadListWidth = 280,
60
60
  threadListCollapsedHeight = 220,
61
61
  clientToolkits,
62
+ clientTools,
62
63
  chatFeedWidgets,
63
64
  toolChoice,
64
65
  collapseMessages = true,
@@ -160,6 +161,7 @@ function ChatBotView({
160
161
  onSelectedThreadResolved: emitResolvedThread,
161
162
  newThreadResetVersion,
162
163
  clientToolkits,
164
+ clientTools,
163
165
  chatFeedWidgets,
164
166
  toolChoice,
165
167
  collapseMessages,
@@ -8,9 +8,10 @@ export interface ToolCall {
8
8
  status: ToolCallStatus;
9
9
  input: Record<string, unknown>;
10
10
  output?: Content;
11
+ sendMessage?: (message: string) => void;
11
12
  }
12
13
  export declare abstract class ChatFeedWidget extends Tool {
13
- abstract render(toolCall: ToolCall): ReactElement;
14
+ abstract render(toolCall: ToolCall): ReactElement | null;
14
15
  getFollowUpSuggestions?(toolCall: ToolCall): readonly AgentThreadSuggestion[];
15
16
  }
16
- export declare function resolveClientToolkitDescriptions(clientToolkits: ClientToolkitDescription[] | undefined, chatFeedWidgets: ChatFeedWidget[] | undefined): ClientToolkitDescription[] | undefined;
17
+ export declare function resolveClientToolkitDescriptions(clientToolkits: readonly ClientToolkitDescription[] | undefined, chatFeedWidgets: readonly ChatFeedWidget[] | undefined, clientTools?: readonly Tool[]): ClientToolkitDescription[] | undefined;
@@ -2,22 +2,22 @@ import { Tool } from "@meshagent/meshagent";
2
2
  import { ClientToolkitDescription } from "@meshagent/meshagent-agents";
3
3
  class ChatFeedWidget extends Tool {
4
4
  }
5
- function resolveClientToolkitDescriptions(clientToolkits, chatFeedWidgets) {
6
- if ((clientToolkits?.length ?? 0) === 0 && (chatFeedWidgets?.length ?? 0) === 0) {
5
+ function resolveClientToolkitDescriptions(clientToolkits, chatFeedWidgets, clientTools) {
6
+ if ((clientToolkits?.length ?? 0) === 0 && (chatFeedWidgets?.length ?? 0) === 0 && (clientTools?.length ?? 0) === 0) {
7
7
  return void 0;
8
8
  }
9
9
  const descriptions = [...clientToolkits ?? []];
10
10
  const names = new Set(descriptions.map((description) => description.name));
11
- for (const widget of chatFeedWidgets ?? []) {
12
- if (names.has(widget.name)) {
13
- throw new Error(`client tool '${widget.name}' has already been registered`);
11
+ for (const tool of [...clientTools ?? [], ...chatFeedWidgets ?? []]) {
12
+ if (names.has(tool.name)) {
13
+ throw new Error(`client tool '${tool.name}' has already been registered`);
14
14
  }
15
- names.add(widget.name);
15
+ names.add(tool.name);
16
16
  descriptions.push(new ClientToolkitDescription({
17
- name: widget.name,
18
- title: widget.title,
19
- description: widget.description,
20
- inputSchema: widget.inputSchema ?? {
17
+ name: tool.name,
18
+ title: tool.title,
19
+ description: tool.description,
20
+ inputSchema: tool.inputSchema ?? {
21
21
  type: "object",
22
22
  additionalProperties: true
23
23
  }