@meshagent/meshagent-tailwind 0.49.0 → 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 +9 -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
package/CHANGELOG.md CHANGED
@@ -1,3 +1,12 @@
1
+ ## [0.50.0]
2
+ - Chat clients now support per-turn LLM authorization providers, and websocket chat tokens are optional for `auth=none` deployments.
3
+ - The typed client gained `connectLlm`, optional access-subject IDs, service-account principals, room and service enabled flags, `llm_quota_manager`, and the `router` project settings document.
4
+ - Chat-thread constructors now take a chat client instead of requiring a room client, which is a breaking signature change for callers.
5
+ - The Tailwind chat package was updated to `tailwindcss` 4.3.3, and the chat and thread UI was refactored for more reliable optimistic streaming plus richer attachment and thread handling.
6
+
7
+ ## [0.49.1]
8
+ - Stability
9
+
1
10
  ## [0.49.0]
2
11
  - Breaking: `createProject` no longer accepts inline settings; project settings are now document-based with `room_roles` support.
3
12
  - Route path models now use a service-port/content-target union and support CORS, compression, index, and IAP for room-content routes.
@@ -1,5 +1,5 @@
1
1
  import type { ReactElement } from "react";
2
- import type { RoomClient } from "@meshagent/meshagent";
2
+ import type { RoomClient, Tool } from "@meshagent/meshagent";
3
3
  import type { AgentMessage, AgentMessageEvent, BaseChatClient, ClientToolkitDescription } from "@meshagent/meshagent-agents";
4
4
  import type { AgentUsageSnapshot } from "./chat-thread-timeline.js";
5
5
  export { AgentUsageSnapshot, shouldReplaceAgentUsageSnapshot } from "./chat-thread-timeline.js";
@@ -18,15 +18,19 @@ export interface AgentThreadSuggestion {
18
18
  prompt?: string;
19
19
  }
20
20
  export interface AgentThreadProps {
21
- room: RoomClient;
21
+ room?: RoomClient;
22
22
  path: string;
23
23
  chatClient?: BaseChatClient;
24
24
  disposeChatClient?: boolean;
25
25
  agentName?: string;
26
26
  emptyStateTitle?: string;
27
27
  emptyStateDescription?: string;
28
- clientToolkits?: ClientToolkitDescription[];
29
- chatFeedWidgets?: ChatFeedWidget[];
28
+ /** Description-only client tools whose execution is owned outside this component. */
29
+ clientToolkits?: readonly ClientToolkitDescription[];
30
+ /** Client tools executed locally without rendering conversation-feed rows. */
31
+ clientTools?: readonly Tool[];
32
+ /** Client tools executed locally with custom feed rendering or feed behavior. */
33
+ chatFeedWidgets?: readonly ChatFeedWidget[];
30
34
  toolChoice?: AgentToolChoice;
31
35
  collapseMessages?: boolean;
32
36
  suggestions?: readonly AgentThreadSuggestion[];
@@ -79,9 +83,9 @@ export interface EventLineProps {
79
83
  }
80
84
  export declare function EventLine({ headline, details, state, failed, className }: EventLineProps): ReactElement | null;
81
85
  export interface ChatThreadPreviewProps {
82
- room: RoomClient;
86
+ room?: RoomClient;
83
87
  path: string;
84
88
  className?: string;
85
89
  }
86
90
  export declare function ChatThreadPreview({ room, path, className }: ChatThreadPreviewProps): ReactElement;
87
- export declare function AgentThread({ room, path, chatClient, disposeChatClient, agentName, emptyStateTitle, emptyStateDescription, clientToolkits, chatFeedWidgets, collapseMessages, suggestions, enableFileUpload, persistedEvents, deferLiveEvents, loadThread, injectPersistedEvents, composerDisabled: composerDisabledProp, closeThreadOnUnmount, onPersistedEventsInjectionStarted, onPersistedEventsInjected, onEventsChanged, }: AgentThreadProps): ReactElement;
91
+ export declare function AgentThread({ room, path, chatClient, disposeChatClient, agentName, emptyStateTitle, emptyStateDescription, clientToolkits, clientTools, chatFeedWidgets, collapseMessages, suggestions, enableFileUpload, persistedEvents, deferLiveEvents, loadThread, injectPersistedEvents, composerDisabled: composerDisabledProp, closeThreadOnUnmount, onPersistedEventsInjectionStarted, onPersistedEventsInjected, onEventsChanged, }: AgentThreadProps): ReactElement;
@@ -130,22 +130,6 @@ function isShellTool(message) {
130
130
  const values = [message.toolkit, message.tool].filter((value) => typeof value === "string").map((value) => value.trim().toLowerCase());
131
131
  return values.some((value) => value === "shell" || value === "exec" || value === "local_shell" || value === "local_shell_call" || value.includes("shell") || value.includes("exec"));
132
132
  }
133
- function firstNonEmptyLine(text) {
134
- for (const line of text.split(/\r?\n/)) {
135
- const trimmed = line.trim();
136
- if (trimmed !== "") {
137
- return trimmed;
138
- }
139
- }
140
- return null;
141
- }
142
- function detailGroupId(messages) {
143
- const first = messages[0];
144
- return ["details", first?.turnId ?? "", first?.id ?? "", first?.createdAt.getTime() ?? 0].join(":");
145
- }
146
- function messagesShareTurn(left, right) {
147
- return left.turnId != null && left.turnId.trim() !== "" && left.turnId === right.turnId;
148
- }
149
133
  function canCollapseAsCommentary(message) {
150
134
  if (message.phase === "final_answer") {
151
135
  return false;
@@ -246,104 +230,24 @@ function addDetailIndexesForSegment(messages, start, end, detailIndexes, chatFee
246
230
  }
247
231
  }
248
232
  }
249
- function nextNonDetailMessage(messages, detailIndexes, start, end) {
250
- for (let index = start; index < end; index += 1) {
251
- if (!detailIndexes.has(index)) {
252
- return messages[index];
253
- }
254
- }
255
- return null;
256
- }
257
- function detailGroupCollapsedMessage(messages) {
258
- for (const message of [...messages].reverse()) {
259
- if (canCollapseAsCommentary(message) && message.text.trim() !== "") {
260
- return message;
261
- }
262
- }
263
- for (const message of [...messages].reverse()) {
264
- if (message.kind === "reasoning" && message.text.trim() !== "") {
265
- return message;
266
- }
267
- }
268
- return null;
269
- }
270
- function formatDetailGroupDuration(milliseconds) {
271
- const seconds = Math.max(0, Math.round(milliseconds / 1e3));
272
- if (seconds < 60) {
273
- return `${seconds}s`;
274
- }
275
- const minutes = Math.floor(seconds / 60);
276
- const remainingSeconds = seconds % 60;
277
- return remainingSeconds === 0 ? `${minutes}m` : `${minutes}m ${remainingSeconds}s`;
278
- }
279
- function detailGroupCollapsedText(messages, nextMessage) {
280
- const first = messages[0];
281
- if (first && nextMessage != null && canRenderAsFinalAnswer(nextMessage) && messagesShareTurn(first, nextMessage)) {
282
- return `Worked for ${formatDetailGroupDuration(nextMessage.createdAt.getTime() - first.createdAt.getTime())}`;
283
- }
284
- return firstNonEmptyLine(detailGroupCollapsedMessage(messages)?.text ?? "") ?? "Working";
285
- }
286
- function detailGroupAuthorName(message, localParticipantName, agentName) {
287
- const authorName = message.authorName?.trim();
288
- if (authorName) {
289
- return authorName;
290
- }
291
- if (message.role === "user") {
292
- return localParticipantName;
293
- }
294
- return displayParticipantName(agentName);
295
- }
296
- function detailGroupForMessages(messages, nextMessage, expandedIds, localParticipantName, agentName) {
297
- const collapsedMessage = detailGroupCollapsedMessage(messages) ?? messages[0];
298
- const id = detailGroupId(messages);
299
- return {
300
- id,
301
- kind: "detail_group",
302
- messages,
303
- collapsedText: detailGroupCollapsedText(messages, nextMessage),
304
- authorName: detailGroupAuthorName(collapsedMessage, localParticipantName, agentName),
305
- createdAt: collapsedMessage.createdAt,
306
- expanded: expandedIds.has(id)
307
- };
308
- }
309
- function groupThreadItems(messages, expandedIds, localParticipantName, agentName, chatFeedWidgetsByName) {
233
+ function groupThreadItems(messages, chatFeedWidgetsByName) {
310
234
  const items = [];
311
235
  let index = 0;
312
236
  while (index < messages.length) {
313
237
  const segmentEnd = nextUserMessageIndex(messages, index + 1) ?? messages.length;
314
238
  const detailIndexes = /* @__PURE__ */ new Set();
315
239
  addDetailIndexesForSegment(messages, index, segmentEnd, detailIndexes, chatFeedWidgetsByName);
316
- const groupedMessages = [...detailIndexes].sort((left, right) => left - right).map((detailIndex) => messages[detailIndex]);
317
- let insertedDetailGroup = false;
318
240
  for (let segmentIndex = index; segmentIndex < segmentEnd; segmentIndex += 1) {
319
241
  if (!detailIndexes.has(segmentIndex)) {
320
242
  items.push(messages[segmentIndex]);
321
- continue;
322
243
  }
323
- if (insertedDetailGroup || groupedMessages.length === 0) {
324
- continue;
325
- }
326
- items.push(detailGroupForMessages(
327
- groupedMessages,
328
- nextNonDetailMessage(messages, detailIndexes, segmentIndex + 1, segmentEnd),
329
- expandedIds,
330
- localParticipantName,
331
- agentName
332
- ));
333
- insertedDetailGroup = true;
334
244
  }
335
245
  index = segmentEnd;
336
246
  }
337
247
  return items;
338
248
  }
339
249
  function previousMessageItem(items, index) {
340
- for (let cursor = index - 1; cursor >= 0; cursor -= 1) {
341
- const item = items[cursor];
342
- if (item.kind !== "detail_group") {
343
- return item;
344
- }
345
- }
346
- return null;
250
+ return index > 0 ? items[index - 1] : null;
347
251
  }
348
252
  function formatAgentUsageTokenCount(value) {
349
253
  const magnitude = Math.abs(value);
@@ -588,6 +492,10 @@ function ChatImageAttachment({ room, path }) {
588
492
  return;
589
493
  }
590
494
  setUrl(null);
495
+ if (room == null) {
496
+ setError(new Error("This attachment requires a room connection."));
497
+ return;
498
+ }
591
499
  void room.storage.downloadUrl(imagePath).then((nextUrl) => {
592
500
  if (!cancelled) {
593
501
  setUrl(nextUrl);
@@ -631,6 +539,7 @@ function AttachmentDownloadButton({ room, path, className }) {
631
539
  window.open(path, "_blank", "noopener,noreferrer");
632
540
  return;
633
541
  }
542
+ if (room == null) return;
634
543
  void room.storage.downloadUrl(preview).then((nextUrl) => {
635
544
  window.open(nextUrl, "_blank", "noopener,noreferrer");
636
545
  });
@@ -638,7 +547,7 @@ function AttachmentDownloadButton({ room, path, className }) {
638
547
  children: [
639
548
  /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_lucide_react.FileText, { className: "h-4 w-4 shrink-0 text-muted-foreground" }),
640
549
  /* @__PURE__ */ (0, import_jsx_runtime.jsx)("span", { className: "truncate text-sm font-medium", children: filename }),
641
- /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_lucide_react.Download, { className: "h-4 w-4 shrink-0 text-muted-foreground" })
550
+ room != null || isInlineImageUrl(path) || isHttpUrl(path) ? /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_lucide_react.Download, { className: "h-4 w-4 shrink-0 text-muted-foreground" }) : /* @__PURE__ */ (0, import_jsx_runtime.jsx)("span", { className: "shrink-0 text-xs text-muted-foreground", children: "Unavailable" })
642
551
  ]
643
552
  }
644
553
  );
@@ -650,50 +559,6 @@ function ChatThreadPreview({ room, path, className }) {
650
559
  }
651
560
  return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(AttachmentDownloadButton, { room, path: normalizedPath, className });
652
561
  }
653
- function DetailGroupLine({ item, onToggle }) {
654
- return /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(
655
- "button",
656
- {
657
- type: "button",
658
- 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",
659
- onClick: onToggle,
660
- "aria-expanded": item.expanded,
661
- title: item.expanded ? "Collapse details" : "Expand details",
662
- children: [
663
- item.expanded ? /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_lucide_react.ChevronDown, { className: "h-3.5 w-3.5 shrink-0" }) : /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_lucide_react.ChevronRight, { className: "h-3.5 w-3.5 shrink-0" }),
664
- /* @__PURE__ */ (0, import_jsx_runtime.jsx)("span", { className: "min-w-0 truncate", children: item.collapsedText }),
665
- /* @__PURE__ */ (0, import_jsx_runtime.jsx)("span", { className: "shrink-0", children: timeAgo(item.createdAt) })
666
- ]
667
- }
668
- );
669
- }
670
- function ExpandedDetailGroup({
671
- room,
672
- item,
673
- localParticipantName,
674
- agentName,
675
- chatFeedWidgetsByName
676
- }) {
677
- return /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", { className: "flex flex-col gap-3", children: [
678
- /* @__PURE__ */ (0, import_jsx_runtime.jsx)("div", { className: "flex w-full justify-start", children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)("div", { className: "max-w-[85%] px-1 text-left sm:max-w-2xl", children: /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", { className: "flex flex-wrap items-center gap-x-3 gap-y-1 text-xs text-muted-foreground", children: [
679
- item.authorName.trim() !== "" ? /* @__PURE__ */ (0, import_jsx_runtime.jsx)("span", { className: "font-semibold text-foreground", children: displayParticipantName(item.authorName) }) : null,
680
- /* @__PURE__ */ (0, import_jsx_runtime.jsx)("span", { children: timeAgo(item.createdAt) })
681
- ] }) }) }),
682
- item.messages.map((message, index) => /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
683
- ThreadMessageView,
684
- {
685
- room,
686
- message,
687
- previous: index > 0 ? item.messages[index - 1] : null,
688
- localParticipantName,
689
- agentName,
690
- chatFeedWidgetsByName,
691
- forceHideHeader: true
692
- },
693
- message.id
694
- ))
695
- ] });
696
- }
697
562
  function GeneratedImageView({ image }) {
698
563
  const completedImages = image.images?.filter((entry) => entry.uri?.trim()) ?? [];
699
564
  if (completedImages.length > 0) {
@@ -733,6 +598,7 @@ function ThreadMessageView({
733
598
  localParticipantName,
734
599
  agentName,
735
600
  chatFeedWidgetsByName,
601
+ onSendMessage,
736
602
  forceHideHeader = false
737
603
  }) {
738
604
  if (message.kind === "error") {
@@ -770,7 +636,8 @@ function ThreadMessageView({
770
636
  toolCall: {
771
637
  status,
772
638
  input: message.input ?? {},
773
- output: message.output
639
+ output: message.output,
640
+ sendMessage: onSendMessage
774
641
  },
775
642
  fallback: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(ToolCallLine, { message })
776
643
  },
@@ -837,46 +704,46 @@ function normalizeAgentAttachmentUrl(path) {
837
704
  const roomPath = trimmedPath.startsWith("/") ? trimmedPath.slice(1) : trimmedPath;
838
705
  return roomPath === "" ? null : `room:///${roomPath}`;
839
706
  }
840
- const handledChatFeedWidgetRequests = /* @__PURE__ */ new WeakMap();
841
- const initializedChatFeedWidgetSessions = /* @__PURE__ */ new WeakSet();
842
- const replayingChatFeedWidgetSessions = /* @__PURE__ */ new WeakSet();
707
+ const handledClientToolRequests = /* @__PURE__ */ new WeakMap();
708
+ const initializedClientToolSessions = /* @__PURE__ */ new WeakSet();
709
+ const replayingClientToolSessions = /* @__PURE__ */ new WeakSet();
843
710
  function handledRequestsForSession(session) {
844
- const existing = handledChatFeedWidgetRequests.get(session);
711
+ const existing = handledClientToolRequests.get(session);
845
712
  if (existing != null) {
846
713
  return existing;
847
714
  }
848
715
  const created = /* @__PURE__ */ new Set();
849
- handledChatFeedWidgetRequests.set(session, created);
716
+ handledClientToolRequests.set(session, created);
850
717
  return created;
851
718
  }
852
- function chatFeedWidgetCallKey(threadPath, itemId) {
719
+ function clientToolCallKey(threadPath, itemId) {
853
720
  return [threadPath, itemId].join("\0");
854
721
  }
855
- function processChatFeedWidgetRequests({
722
+ function processClientToolRequests({
856
723
  session,
857
- widgetsByName,
724
+ toolsByName,
858
725
  updateCall,
859
726
  executeRequests
860
727
  }) {
861
- if (widgetsByName.size === 0) {
728
+ if (toolsByName.size === 0) {
862
729
  return;
863
730
  }
864
- const requests = session.messages.map((event) => event.message).filter((message) => message instanceof import_meshagent_agents.AgentClientToolCallRequested).filter((message) => message.toolkit === "client" && widgetsByName.has(message.tool));
731
+ const requests = session.messages.map((event) => event.message).filter((message) => message instanceof import_meshagent_agents.AgentClientToolCallRequested).filter((message) => message.toolkit === "client" && toolsByName.has(message.tool));
865
732
  const handledRequests = handledRequestsForSession(session);
866
- if (!initializedChatFeedWidgetSessions.has(session)) {
867
- initializedChatFeedWidgetSessions.add(session);
733
+ if (!initializedClientToolSessions.has(session)) {
734
+ initializedClientToolSessions.add(session);
868
735
  if (session.isLoading || session.loadState.requestMessageId != null) {
869
- replayingChatFeedWidgetSessions.add(session);
736
+ replayingClientToolSessions.add(session);
870
737
  }
871
738
  }
872
739
  if (!executeRequests) {
873
740
  return;
874
741
  }
875
- if (replayingChatFeedWidgetSessions.has(session)) {
742
+ if (replayingClientToolSessions.has(session)) {
876
743
  if (session.isLoading) {
877
744
  return;
878
745
  }
879
- replayingChatFeedWidgetSessions.delete(session);
746
+ replayingClientToolSessions.delete(session);
880
747
  const completedItemIds = new Set(session.messages.map((event) => event.message).filter((message) => message instanceof import_meshagent_agents.AgentToolCallEnded && message.toolkit === "client").map((message) => message.itemId));
881
748
  for (const request of requests) {
882
749
  if (completedItemIds.has(request.requestId)) {
@@ -888,8 +755,8 @@ function processChatFeedWidgetRequests({
888
755
  if (handledRequests.has(request.requestId)) {
889
756
  continue;
890
757
  }
891
- const widget = widgetsByName.get(request.tool);
892
- if (widget == null) {
758
+ const tool = toolsByName.get(request.tool);
759
+ if (tool == null) {
893
760
  continue;
894
761
  }
895
762
  if (!session.claimClientToolCall(request.requestId)) {
@@ -897,20 +764,20 @@ function processChatFeedWidgetRequests({
897
764
  continue;
898
765
  }
899
766
  handledRequests.add(request.requestId);
900
- updateCall(chatFeedWidgetCallKey(session.threadPath, request.requestId), {
767
+ updateCall(clientToolCallKey(session.threadPath, request.requestId), {
901
768
  status: "in_progress"
902
769
  });
903
770
  void (async () => {
904
771
  let response;
905
772
  let status;
906
773
  try {
907
- response = await widget.execute(request.arguments);
774
+ response = await tool.execute(request.arguments);
908
775
  status = response instanceof import_meshagent.ErrorContent ? "failed" : "completed";
909
776
  } catch (error) {
910
777
  response = new import_meshagent.ErrorContent({ text: describeError(error) });
911
778
  status = "failed";
912
779
  }
913
- updateCall(chatFeedWidgetCallKey(session.threadPath, request.requestId), {
780
+ updateCall(clientToolCallKey(session.threadPath, request.requestId), {
914
781
  status,
915
782
  output: response
916
783
  });
@@ -923,7 +790,7 @@ function processChatFeedWidgetRequests({
923
790
  session.finishClientToolCall(request.requestId, { responseSent: true });
924
791
  } catch (error) {
925
792
  session.finishClientToolCall(request.requestId, { responseSent: false });
926
- updateCall(chatFeedWidgetCallKey(session.threadPath, request.requestId), {
793
+ updateCall(clientToolCallKey(session.threadPath, request.requestId), {
927
794
  status: "failed",
928
795
  output: new import_meshagent.ErrorContent({ text: describeError(error) })
929
796
  });
@@ -940,6 +807,7 @@ function AgentThread({
940
807
  emptyStateTitle = "Chat to get started",
941
808
  emptyStateDescription,
942
809
  clientToolkits,
810
+ clientTools,
943
811
  chatFeedWidgets,
944
812
  collapseMessages = true,
945
813
  suggestions,
@@ -959,8 +827,7 @@ function AgentThread({
959
827
  const [restorationError, setRestorationError] = (0, import_react.useState)(null);
960
828
  const [restorationAttempt, setRestorationAttempt] = (0, import_react.useState)(0);
961
829
  const [version, setVersion] = (0, import_react.useState)(0);
962
- const [expandedDetailGroupIds, setExpandedDetailGroupIds] = (0, import_react.useState)(() => /* @__PURE__ */ new Set());
963
- const [chatFeedWidgetCallOverrides, setChatFeedWidgetCallOverrides] = (0, import_react.useState)(() => /* @__PURE__ */ new Map());
830
+ const [clientToolCallOverrides, setClientToolCallOverrides] = (0, import_react.useState)(() => /* @__PURE__ */ new Map());
964
831
  const sessionRef = (0, import_react.useRef)(null);
965
832
  const mountedRef = (0, import_react.useRef)(true);
966
833
  const persistedEventsRef = (0, import_react.useRef)(persistedEvents);
@@ -970,29 +837,44 @@ function AgentThread({
970
837
  const pendingCloseRef = (0, import_react.useRef)(null);
971
838
  const ownsChatClient = chatClient == null;
972
839
  const activeChatClient = (0, import_react.useMemo)(
973
- () => chatClient ?? new import_meshagent_agents.MessagingChatClient({ room, agentName }),
840
+ () => {
841
+ if (chatClient != null) return chatClient;
842
+ if (room != null) return new import_meshagent_agents.MessagingChatClient({ room, agentName });
843
+ throw new Error("AgentThread requires either a room or a chat client.");
844
+ },
974
845
  [agentName, chatClient, room]
975
846
  );
976
847
  const resolvedClientToolkits = (0, import_react.useMemo)(
977
- () => (0, import_chat_feed_widget.resolveClientToolkitDescriptions)(clientToolkits, chatFeedWidgets),
978
- [chatFeedWidgets, clientToolkits]
848
+ () => (0, import_chat_feed_widget.resolveClientToolkitDescriptions)(clientToolkits, chatFeedWidgets, clientTools),
849
+ [chatFeedWidgets, clientToolkits, clientTools]
979
850
  );
980
851
  const chatFeedWidgetsByName = (0, import_react.useMemo)(
981
852
  () => new Map((chatFeedWidgets ?? []).map((widget) => [widget.name, widget])),
982
853
  [chatFeedWidgets]
983
854
  );
984
- const updateChatFeedWidgetCall = (0, import_react.useCallback)((callKey, override) => {
855
+ const clientToolsByName = (0, import_react.useMemo)(
856
+ () => new Map((clientTools ?? []).map((tool) => [tool.name, tool])),
857
+ [clientTools]
858
+ );
859
+ const clientToolExecutorsByName = (0, import_react.useMemo)(
860
+ () => new Map([
861
+ ...(clientTools ?? []).map((tool) => [tool.name, tool]),
862
+ ...(chatFeedWidgets ?? []).map((widget) => [widget.name, widget])
863
+ ]),
864
+ [chatFeedWidgets, clientTools]
865
+ );
866
+ const updateClientToolCall = (0, import_react.useCallback)((callKey, override) => {
985
867
  if (!mountedRef.current) {
986
868
  return;
987
869
  }
988
- setChatFeedWidgetCallOverrides((current) => {
870
+ setClientToolCallOverrides((current) => {
989
871
  const next = new Map(current);
990
872
  next.set(callKey, override);
991
873
  return next;
992
874
  });
993
875
  }, []);
994
- const localParticipantName = getParticipantName(room.localParticipant);
995
- const agentParticipant = activeChatClient.agentParticipant() ?? findAgentParticipant(room, agentName);
876
+ const localParticipantName = room == null ? activeChatClient.localParticipantName() ?? "" : getParticipantName(room.localParticipant);
877
+ const agentParticipant = activeChatClient.agentParticipant() ?? (room == null ? null : findAgentParticipant(room, agentName));
996
878
  (0, import_react.useEffect)(() => {
997
879
  mountedRef.current = true;
998
880
  return () => {
@@ -1070,10 +952,10 @@ function AgentThread({
1070
952
  };
1071
953
  const handleChange = () => {
1072
954
  synchronizeThreadLoadState();
1073
- processChatFeedWidgetRequests({
955
+ processClientToolRequests({
1074
956
  session: session2,
1075
- widgetsByName: chatFeedWidgetsByName,
1076
- updateCall: updateChatFeedWidgetCall,
957
+ toolsByName: clientToolExecutorsByName,
958
+ updateCall: updateClientToolCall,
1077
959
  executeRequests: !deferLiveEvents && restorationReadyRef.current
1078
960
  });
1079
961
  const latestMessage = session2.messages[session2.messages.length - 1]?.message;
@@ -1187,7 +1069,7 @@ function AgentThread({
1187
1069
  };
1188
1070
  }, [
1189
1071
  activeChatClient,
1190
- chatFeedWidgetsByName,
1072
+ clientToolExecutorsByName,
1191
1073
  closeThreadOnUnmount,
1192
1074
  deferLiveEvents,
1193
1075
  injectPersistedEvents,
@@ -1197,7 +1079,7 @@ function AgentThread({
1197
1079
  onPersistedEventsInjected,
1198
1080
  path,
1199
1081
  restorationAttempt,
1200
- updateChatFeedWidgetCall
1082
+ updateClientToolCall
1201
1083
  ]);
1202
1084
  const retryRestoration = (0, import_react.useCallback)(() => {
1203
1085
  restoredPathRef.current = null;
@@ -1217,7 +1099,7 @@ function AgentThread({
1217
1099
  return persistedEvents == null ? (0, import_chat_thread_timeline.buildChatThreadTimeline)(session.messages, session.pendingInputs) : (0, import_chat_thread_timeline.buildMergedChatThreadTimeline)(persistedEvents, session.messages, session.pendingInputs);
1218
1100
  }, [deferLiveEvents, persistedEvents, session, version]);
1219
1101
  const timelineItems = (0, import_react.useMemo)(() => (timeline?.items ?? []).map((item) => {
1220
- const override = session == null ? void 0 : chatFeedWidgetCallOverrides.get(chatFeedWidgetCallKey(session.threadPath, item.id));
1102
+ const override = session == null ? void 0 : clientToolCallOverrides.get(clientToolCallKey(session.threadPath, item.id));
1221
1103
  if (override == null || item.kind !== "tool_call" || (item.state === "completed" || item.state === "failed")) {
1222
1104
  return item;
1223
1105
  }
@@ -1227,17 +1109,17 @@ function AgentThread({
1227
1109
  failed: override.status === "failed",
1228
1110
  output: override.output ?? item.output
1229
1111
  };
1230
- }), [chatFeedWidgetCallOverrides, session, timeline]);
1112
+ }), [clientToolCallOverrides, session, timeline]);
1231
1113
  const showThreadLoading = (deferLiveEvents || session === null || session.isLoading) && timelineItems.length === 0;
1232
1114
  const followUpSuggestions = (0, import_react.useMemo)(
1233
1115
  () => latestTurnFollowUpSuggestions(timelineItems, chatFeedWidgetsByName),
1234
1116
  [chatFeedWidgetsByName, timelineItems]
1235
1117
  );
1236
1118
  const feedTimelineItems = (0, import_react.useMemo)(
1237
- () => timelineItems.filter((item) => !isFollowUpSuggestionCall(item, chatFeedWidgetsByName)),
1238
- [chatFeedWidgetsByName, timelineItems]
1119
+ () => timelineItems.filter((item) => !isFollowUpSuggestionCall(item, chatFeedWidgetsByName) && !(item.kind === "tool_call" && item.toolkit === "client" && item.tool != null && clientToolsByName.has(item.tool))),
1120
+ [chatFeedWidgetsByName, clientToolsByName, timelineItems]
1239
1121
  );
1240
- const renderedItems = (0, import_react.useMemo)(() => collapseMessages ? groupThreadItems(feedTimelineItems, expandedDetailGroupIds, localParticipantName, agentName, chatFeedWidgetsByName) : feedTimelineItems, [agentName, chatFeedWidgetsByName, collapseMessages, expandedDetailGroupIds, feedTimelineItems, localParticipantName]);
1122
+ const renderedItems = (0, import_react.useMemo)(() => collapseMessages ? groupThreadItems(feedTimelineItems, chatFeedWidgetsByName) : feedTimelineItems, [chatFeedWidgetsByName, collapseMessages, feedTimelineItems]);
1241
1123
  const status = (0, import_react.useMemo)(() => {
1242
1124
  if (session == null) return null;
1243
1125
  let current = null;
@@ -1270,6 +1152,7 @@ function AgentThread({
1270
1152
  return previousById;
1271
1153
  }, [renderedItems]);
1272
1154
  const selectAttachments = (0, import_react.useCallback)((files) => {
1155
+ if (room == null) return;
1273
1156
  const nextAttachments = files.map((file) => new import_file_attachment.MeshagentFileUpload(
1274
1157
  room,
1275
1158
  `uploaded-files/${file.name}`,
@@ -1323,6 +1206,16 @@ function AgentThread({
1323
1206
  text
1324
1207
  }));
1325
1208
  }, [handleSend]);
1209
+ const handleWidgetMessage = (0, import_react.useCallback)((message) => {
1210
+ const text = message.trim();
1211
+ if (text === "" || composerDisabled) {
1212
+ return;
1213
+ }
1214
+ void handleSend(new import_chat_message.ChatMessage({
1215
+ id: (0, import_uuid.v4)(),
1216
+ text
1217
+ }));
1218
+ }, [composerDisabled, handleSend]);
1326
1219
  const cancelTurn = (0, import_react.useCallback)(async () => {
1327
1220
  const openSession = sessionRef.current;
1328
1221
  if (openSession === null || turnId == null) {
@@ -1330,17 +1223,6 @@ function AgentThread({
1330
1223
  }
1331
1224
  await openSession.interruptTurn(turnId);
1332
1225
  }, [turnId]);
1333
- const toggleDetailGroup = (0, import_react.useCallback)((id) => {
1334
- setExpandedDetailGroupIds((current) => {
1335
- const next = new Set(current);
1336
- if (next.has(id)) {
1337
- next.delete(id);
1338
- } else {
1339
- next.add(id);
1340
- }
1341
- return next;
1342
- });
1343
- }, []);
1344
1226
  return /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", { className: "flex h-full min-h-0 flex-1 flex-col", children: [
1345
1227
  /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", { className: "relative flex h-full min-h-0 flex-1 flex-col", children: [
1346
1228
  showThreadLoading ? /* @__PURE__ */ (0, import_jsx_runtime.jsx)("div", { className: "min-h-0 flex-1 overflow-hidden", children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(LoadingState, {}) }) : timelineItems.length === 0 ? /* @__PURE__ */ (0, import_jsx_runtime.jsx)("div", { className: "min-h-0 flex-1 overflow-hidden", children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(EmptyState, { title: emptyStateTitle, description: emptyStateDescription }) }) : /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
@@ -1349,23 +1231,14 @@ function AgentThread({
1349
1231
  bottomThresholdPx: 24,
1350
1232
  className: "flex-1 overflow-x-hidden",
1351
1233
  currentUserId: "user",
1352
- getMessageAuthorId: (item) => item.kind === "detail_group" ? "agent" : item.role,
1234
+ getMessageAuthorId: (item) => item.role,
1353
1235
  messages: renderedItemsNewestFirst,
1354
1236
  renderMessage: (item) => {
1355
1237
  return /* @__PURE__ */ (0, import_jsx_runtime.jsx)("div", { className: (0, import_utils.cn)(
1356
1238
  "mx-auto w-full max-w-[912px] px-1 py-3",
1357
1239
  item.id === firstRenderedItemId ? "pt-6" : null,
1358
1240
  item.id === lastRenderedItemId ? statusText ? "pb-24" : "pb-6" : null
1359
- ), children: item.kind === "detail_group" ? item.expanded ? /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
1360
- ExpandedDetailGroup,
1361
- {
1362
- room,
1363
- item,
1364
- localParticipantName,
1365
- agentName,
1366
- chatFeedWidgetsByName
1367
- }
1368
- ) : /* @__PURE__ */ (0, import_jsx_runtime.jsx)(DetailGroupLine, { item, onToggle: () => toggleDetailGroup(item.id) }) : /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
1241
+ ), children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
1369
1242
  ThreadMessageView,
1370
1243
  {
1371
1244
  room,
@@ -1373,7 +1246,8 @@ function AgentThread({
1373
1246
  previous: previousItemById.get(item.id) ?? null,
1374
1247
  localParticipantName,
1375
1248
  agentName,
1376
- chatFeedWidgetsByName
1249
+ chatFeedWidgetsByName,
1250
+ onSendMessage: handleWidgetMessage
1377
1251
  }
1378
1252
  ) });
1379
1253
  }
@@ -1386,7 +1260,6 @@ function AgentThread({
1386
1260
  thinking: false,
1387
1261
  statusText,
1388
1262
  startedAt: dateFromString(status?.startedAt),
1389
- totalBytes: status?.totalBytes,
1390
1263
  linesAdded: status?.linesAdded,
1391
1264
  linesRemoved: status?.linesRemoved,
1392
1265
  onCancel: canInterruptActiveTurn ? cancelTurn : void 0,
@@ -1408,16 +1281,17 @@ function AgentThread({
1408
1281
  "ul",
1409
1282
  {
1410
1283
  "aria-label": "Follow-up suggestions",
1411
- className: "mx-auto flex flex-wrap w-full max-w-[912px] gap-2 overflow-x-auto px-4 pt-2 pb-1",
1412
- children: visibleSuggestions.map((suggestion, index) => /* @__PURE__ */ (0, import_jsx_runtime.jsx)("li", { className: "shrink-0", children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
1284
+ className: "mx-auto flex w-full max-w-[912px] flex-wrap gap-2 px-4 pt-2 pb-1",
1285
+ children: visibleSuggestions.map((suggestion, index) => /* @__PURE__ */ (0, import_jsx_runtime.jsx)("li", { className: "min-w-0 max-w-full", children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
1413
1286
  import_button.Button,
1414
1287
  {
1415
1288
  type: "button",
1416
1289
  variant: "outline",
1417
- className: "h-auto min-h-8 rounded-full px-3 py-1.5",
1290
+ className: "h-auto min-h-8 max-w-full overflow-hidden rounded-full px-3 py-1.5 text-left text-sm leading-snug",
1291
+ title: suggestion.label,
1418
1292
  disabled: composerDisabled,
1419
1293
  onClick: () => handleSuggestionClick(suggestion),
1420
- children: suggestion.label
1294
+ children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)("span", { className: "min-w-0 truncate", children: suggestion.label })
1421
1295
  }
1422
1296
  ) }, index))
1423
1297
  }
@@ -1429,7 +1303,7 @@ function AgentThread({
1429
1303
  attachments,
1430
1304
  onFilesSelected: selectAttachments,
1431
1305
  setAttachments,
1432
- enableFileUpload,
1306
+ enableFileUpload: enableFileUpload && room != null,
1433
1307
  disabled: composerDisabled,
1434
1308
  placeholder: agentParticipant || chatClient ? "Type a message" : `Waiting for ${displayParticipantName(agentName)}`
1435
1309
  }
@@ -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;