@meshagent/meshagent-tailwind 0.55.1 → 0.55.2

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 (38) hide show
  1. package/CHANGELOG.md +17 -0
  2. package/README.md +34 -3
  3. package/dist/cjs/chat/agent-thread.d.ts +42 -7
  4. package/dist/cjs/chat/agent-thread.js +422 -183
  5. package/dist/cjs/chat/chat-input-state.d.ts +2 -0
  6. package/dist/cjs/chat/chat-input-state.js +41 -0
  7. package/dist/cjs/chat/chat-input.d.ts +14 -2
  8. package/dist/cjs/chat/chat-input.js +41 -76
  9. package/dist/cjs/chat/chat-scroller.js +45 -43
  10. package/dist/cjs/chat/chat-thread-timeline.d.ts +2 -0
  11. package/dist/cjs/chat/chat-thread-timeline.js +83 -10
  12. package/dist/cjs/chat/composer-action-button.d.ts +11 -0
  13. package/dist/cjs/chat/composer-action-button.js +68 -0
  14. package/dist/cjs/chat/use-chat-virtualizer.d.ts +14 -17
  15. package/dist/cjs/chat/use-chat-virtualizer.js +288 -222
  16. package/dist/cjs/chat/virtualization.d.ts +0 -5
  17. package/dist/cjs/chat/virtualization.js +4 -6
  18. package/dist/cjs/index.d.ts +1 -0
  19. package/dist/cjs/index.js +1 -0
  20. package/dist/esm/chat/agent-thread.d.ts +42 -7
  21. package/dist/esm/chat/agent-thread.js +424 -186
  22. package/dist/esm/chat/chat-input-state.d.ts +2 -0
  23. package/dist/esm/chat/chat-input-state.js +21 -0
  24. package/dist/esm/chat/chat-input.d.ts +14 -2
  25. package/dist/esm/chat/chat-input.js +41 -76
  26. package/dist/esm/chat/chat-scroller.js +46 -44
  27. package/dist/esm/chat/chat-thread-timeline.d.ts +2 -0
  28. package/dist/esm/chat/chat-thread-timeline.js +83 -10
  29. package/dist/esm/chat/composer-action-button.d.ts +11 -0
  30. package/dist/esm/chat/composer-action-button.js +48 -0
  31. package/dist/esm/chat/use-chat-virtualizer.d.ts +14 -17
  32. package/dist/esm/chat/use-chat-virtualizer.js +290 -226
  33. package/dist/esm/chat/virtualization.d.ts +0 -5
  34. package/dist/esm/chat/virtualization.js +4 -6
  35. package/dist/esm/index.d.ts +1 -0
  36. package/dist/esm/index.js +1 -0
  37. package/dist/index.css +1 -1
  38. package/package.json +6 -5
@@ -32,6 +32,7 @@ __export(agent_thread_exports, {
32
32
  AgentThreadFeed: () => AgentThreadFeed,
33
33
  AgentThreadInput: () => AgentThreadInput,
34
34
  AgentThreadProvider: () => AgentThreadProvider,
35
+ AgentThreadSubmitButton: () => AgentThreadSubmitButton,
35
36
  AgentToolChoice: () => AgentToolChoice,
36
37
  AgentUsageFooter: () => AgentUsageFooter,
37
38
  AgentUsageSnapshot: () => import_chat_thread_timeline2.AgentUsageSnapshot,
@@ -42,7 +43,9 @@ __export(agent_thread_exports, {
42
43
  formatAgentUsageFooter: () => formatAgentUsageFooter,
43
44
  formatAgentUsageTokenCount: () => formatAgentUsageTokenCount,
44
45
  formatAgentUsageTooltip: () => formatAgentUsageTooltip,
45
- shouldReplaceAgentUsageSnapshot: () => import_chat_thread_timeline2.shouldReplaceAgentUsageSnapshot
46
+ shouldReplaceAgentUsageSnapshot: () => import_chat_thread_timeline2.shouldReplaceAgentUsageSnapshot,
47
+ useAgentThreadFeedState: () => useAgentThreadFeedState,
48
+ useAgentThreadStatus: () => useAgentThreadStatus
46
49
  });
47
50
  module.exports = __toCommonJS(agent_thread_exports);
48
51
  var import_jsx_runtime = require("react/jsx-runtime");
@@ -61,7 +64,9 @@ var import_button = require("../components/ui/button.js");
61
64
  var import_spinner = require("../components/ui/spinner.js");
62
65
  var import_utils = require("../lib/utils.js");
63
66
  var import_chat_input = require("./chat-input.js");
67
+ var import_chat_input_state = require("./chat-input-state.js");
64
68
  var import_chat_message = require("./chat-message.js");
69
+ var import_composer_action_button = require("./composer-action-button.js");
65
70
  var import_chat_scroller = require("./chat-scroller.js");
66
71
  var import_chat_typing_indicator = require("./chat-typing-indicator.js");
67
72
  var import_file_attachment = require("./file-attachment.js");
@@ -85,9 +90,7 @@ function stringValue(value) {
85
90
  }
86
91
  function mergeAgentMessageEvents(persistedEvents, liveEvents) {
87
92
  const merged = [...persistedEvents];
88
- const indexByMessageId = new Map(
89
- merged.map((event, index) => [event.message.messageId, index])
90
- );
93
+ const indexByMessageId = new Map(merged.map((event, index) => [event.message.messageId, index]));
91
94
  for (const event of liveEvents) {
92
95
  const existingIndex = indexByMessageId.get(event.message.messageId);
93
96
  if (existingIndex === void 0) {
@@ -132,7 +135,9 @@ function timeAgo(date) {
132
135
  }
133
136
  function isShellTool(message) {
134
137
  const values = [message.toolkit, message.tool].filter((value) => typeof value === "string").map((value) => value.trim().toLowerCase());
135
- return values.some((value) => value === "shell" || value === "exec" || value === "local_shell" || value === "local_shell_call" || value.includes("shell") || value.includes("exec"));
138
+ return values.some(
139
+ (value) => value === "shell" || value === "exec" || value === "local_shell" || value === "local_shell_call" || value.includes("shell") || value.includes("exec")
140
+ );
136
141
  }
137
142
  function canCollapseAsCommentary(message) {
138
143
  if (message.phase === "final_answer") {
@@ -249,7 +254,10 @@ function formatAgentUsageTooltip(usage) {
249
254
  }
250
255
  return lines.join("\n");
251
256
  }
252
- function AgentUsageFooter({ usage, className }) {
257
+ function AgentUsageFooter({
258
+ usage,
259
+ className
260
+ }) {
253
261
  const tooltip = usage === null ? void 0 : formatAgentUsageTooltip(usage);
254
262
  const label = usage === null ? "" : formatAgentUsageFooter(usage);
255
263
  return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
@@ -310,10 +318,16 @@ function ChatBubble({ text, mine }) {
310
318
  if (text.trim() === "") {
311
319
  return null;
312
320
  }
313
- return /* @__PURE__ */ (0, import_jsx_runtime.jsx)("div", { className: (0, import_utils.cn)(
314
- "w-fit max-w-[85%] rounded-md px-4 py-3 text-sm leading-6 shadow-xs sm:max-w-2xl",
315
- mine ? "bg-secondary/85 text-foreground" : "bg-muted/70 text-foreground"
316
- ), children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(MarkdownBlock, { text }) });
321
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
322
+ "div",
323
+ {
324
+ className: (0, import_utils.cn)(
325
+ "w-fit max-w-[85%] rounded-md px-4 py-3 text-sm leading-6 shadow-xs sm:max-w-2xl",
326
+ mine ? "bg-secondary/85 text-foreground" : "bg-muted/70 text-foreground"
327
+ ),
328
+ children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(MarkdownBlock, { text })
329
+ }
330
+ );
317
331
  }
318
332
  function ReasoningTrace({ text, className }) {
319
333
  if (text.trim() === "") {
@@ -327,7 +341,16 @@ function trimShellText(value) {
327
341
  }
328
342
  return value.length < 1024 ? value : value.slice(0, 1024) + "...";
329
343
  }
330
- function ShellLine({ command, result, stdout, stderr, argumentsText, logs, title = "Terminal", className }) {
344
+ function ShellLine({
345
+ command,
346
+ result,
347
+ stdout,
348
+ stderr,
349
+ argumentsText,
350
+ logs,
351
+ title = "Terminal",
352
+ className
353
+ }) {
331
354
  const displayCommand = command?.trim() || title;
332
355
  const [expanded, setExpanded] = (0, import_react.useState)(title.toLowerCase().includes("error"));
333
356
  const trimmedResult = trimShellText(result);
@@ -353,7 +376,16 @@ function ShellLine({ command, result, stdout, stderr, argumentsText, logs, title
353
376
  children: expanded ? /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_lucide_react.ChevronDown, { className: "h-4 w-4" }) : /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_lucide_react.ChevronRight, { className: "h-4 w-4" })
354
377
  }
355
378
  ),
356
- /* @__PURE__ */ (0, import_jsx_runtime.jsx)("pre", { className: (0, import_utils.cn)("min-w-0 flex-1 overflow-hidden whitespace-pre-wrap break-words font-mono text-xs leading-5 text-foreground", expanded ? null : "line-clamp-1"), children: displayCommand })
379
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
380
+ "pre",
381
+ {
382
+ className: (0, import_utils.cn)(
383
+ "min-w-0 flex-1 overflow-hidden whitespace-pre-wrap break-words font-mono text-xs leading-5 text-foreground",
384
+ expanded ? null : "line-clamp-1"
385
+ ),
386
+ children: displayCommand
387
+ }
388
+ )
357
389
  ] }),
358
390
  expanded && hasDetails ? /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", { className: "space-y-2 border-t px-4 py-3", children: [
359
391
  trimmedResult != null ? /* @__PURE__ */ (0, import_jsx_runtime.jsx)("pre", { className: "whitespace-pre-wrap break-words font-mono text-xs leading-5 text-foreground", children: trimmedResult }) : null,
@@ -384,7 +416,13 @@ function eventLineDetails(details) {
384
416
  const lines = typeof details === "string" ? details.split(/\r?\n/) : details;
385
417
  return lines.map((line) => line.trim()).filter((line) => line !== "");
386
418
  }
387
- function EventLine({ headline, details, state = "info", failed = false, className }) {
419
+ function EventLine({
420
+ headline,
421
+ details,
422
+ state = "info",
423
+ failed = false,
424
+ className
425
+ }) {
388
426
  const normalizedHeadline = headline.trim();
389
427
  const detailLines = eventLineDetails(details);
390
428
  if (normalizedHeadline === "") {
@@ -420,7 +458,14 @@ function ToolCallLine({ message }) {
420
458
  const [expanded, setExpanded] = (0, import_react.useState)(message.failed === true);
421
459
  const hasDetails = detailLines.length > 0;
422
460
  if (!hasDetails) {
423
- return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(EventLine, { headline: message.text, state: message.state ?? (message.failed === true ? "failed" : "completed"), failed: message.failed });
461
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
462
+ EventLine,
463
+ {
464
+ headline: message.text,
465
+ state: message.state ?? (message.failed === true ? "failed" : "completed"),
466
+ failed: message.failed
467
+ }
468
+ );
424
469
  }
425
470
  return /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", { className: "ml-1.5 max-w-[85%] overflow-hidden rounded-md border bg-background text-sm sm:max-w-2xl", children: [
426
471
  /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(
@@ -433,11 +478,30 @@ function ToolCallLine({ message }) {
433
478
  "aria-label": expanded ? "Collapse tool details" : "Expand tool details",
434
479
  children: [
435
480
  /* @__PURE__ */ (0, import_jsx_runtime.jsx)("span", { className: "mt-0.5 inline-flex h-5 w-5 shrink-0 items-center justify-center text-muted-foreground", children: expanded ? /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_lucide_react.ChevronDown, { className: "h-4 w-4" }) : /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_lucide_react.ChevronRight, { className: "h-4 w-4" }) }),
436
- /* @__PURE__ */ (0, import_jsx_runtime.jsx)("span", { className: (0, import_utils.cn)("min-w-0 flex-1 text-xs font-semibold leading-5", eventLineStateClass(message.state, message.failed)), children: message.text })
481
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
482
+ "span",
483
+ {
484
+ className: (0, import_utils.cn)(
485
+ "min-w-0 flex-1 text-xs font-semibold leading-5",
486
+ eventLineStateClass(message.state, message.failed)
487
+ ),
488
+ children: message.text
489
+ }
490
+ )
437
491
  ]
438
492
  }
439
493
  ),
440
- expanded ? /* @__PURE__ */ (0, import_jsx_runtime.jsx)("div", { className: "space-y-2 border-t px-4 py-3", children: detailLines.map((line, index) => /* @__PURE__ */ (0, import_jsx_runtime.jsx)("pre", { className: (0, import_utils.cn)("whitespace-pre-wrap break-words font-mono text-xs leading-5", message.failed === true ? "text-destructive" : "text-muted-foreground"), children: trimShellText(line) }, index)) }) : null
494
+ expanded ? /* @__PURE__ */ (0, import_jsx_runtime.jsx)("div", { className: "space-y-2 border-t px-4 py-3", children: detailLines.map((line, index) => /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
495
+ "pre",
496
+ {
497
+ className: (0, import_utils.cn)(
498
+ "whitespace-pre-wrap break-words font-mono text-xs leading-5",
499
+ message.failed === true ? "text-destructive" : "text-muted-foreground"
500
+ ),
501
+ children: trimShellText(line)
502
+ },
503
+ index
504
+ )) }) : null
441
505
  ] });
442
506
  }
443
507
  function AttachmentView({ room, path }) {
@@ -445,7 +509,9 @@ function AttachmentView({ room, path }) {
445
509
  }
446
510
  function ChatImageAttachment({ room, path }) {
447
511
  const imagePath = attachmentImagePath(path) ?? path;
448
- const [url, setUrl] = (0, import_react.useState)(() => isInlineImageUrl(imagePath) || isHttpUrl(imagePath) ? imagePath : null);
512
+ const [url, setUrl] = (0, import_react.useState)(
513
+ () => isInlineImageUrl(imagePath) || isHttpUrl(imagePath) ? imagePath : null
514
+ );
449
515
  const [error, setError] = (0, import_react.useState)(null);
450
516
  (0, import_react.useEffect)(() => {
451
517
  let cancelled = false;
@@ -489,14 +555,21 @@ function ChatImageAttachment({ room, path }) {
489
555
  }
490
556
  );
491
557
  }
492
- function AttachmentDownloadButton({ room, path, className }) {
558
+ function AttachmentDownloadButton({
559
+ room,
560
+ path,
561
+ className
562
+ }) {
493
563
  const preview = normalizeAttachmentPath(path);
494
564
  const filename = (0, import_file_preview.filePreviewName)(preview);
495
565
  return /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(
496
566
  "button",
497
567
  {
498
568
  type: "button",
499
- className: (0, import_utils.cn)("inline-flex max-w-full items-center gap-2 rounded-md bg-muted/60 px-3 py-2 text-left shadow-xs transition-colors hover:bg-muted/80", className),
569
+ className: (0, import_utils.cn)(
570
+ "inline-flex max-w-full items-center gap-2 rounded-md bg-muted/60 px-3 py-2 text-left shadow-xs transition-colors hover:bg-muted/80",
571
+ className
572
+ ),
500
573
  onClick: () => {
501
574
  if (isInlineImageUrl(path) || isHttpUrl(path)) {
502
575
  window.open(path, "_blank", "noopener,noreferrer");
@@ -518,7 +591,16 @@ function AttachmentDownloadButton({ room, path, className }) {
518
591
  function ChatThreadPreview({ room, path, className }) {
519
592
  const normalizedPath = normalizeAttachmentPath(path);
520
593
  if (attachmentImagePath(path) != null) {
521
- return /* @__PURE__ */ (0, import_jsx_runtime.jsx)("div", { className: (0, import_utils.cn)("h-[312.5px] w-[312.5px] max-w-full overflow-hidden rounded-2xl bg-background", className), children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(ChatImageAttachment, { room, path }) });
594
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
595
+ "div",
596
+ {
597
+ className: (0, import_utils.cn)(
598
+ "h-[312.5px] w-[312.5px] max-w-full overflow-hidden rounded-2xl bg-background",
599
+ className
600
+ ),
601
+ children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(ChatImageAttachment, { room, path })
602
+ }
603
+ );
522
604
  }
523
605
  return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(AttachmentDownloadButton, { room, path: normalizedPath, className });
524
606
  }
@@ -614,12 +696,37 @@ function ThreadMessageView({
614
696
  const previousAuthor = previous?.authorName ?? (previous?.role === "user" ? localParticipantName : displayParticipantName(agentName));
615
697
  const shouldShowHeader = !forceHideHeader && (previous?.kind !== "message" || previousAuthor !== authorName);
616
698
  return /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", { className: "flex flex-col gap-2", children: [
617
- shouldShowHeader ? /* @__PURE__ */ (0, import_jsx_runtime.jsx)("div", { className: (0, import_utils.cn)("flex w-full", mine ? "justify-end" : "justify-start"), children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)("div", { className: (0, import_utils.cn)("max-w-[85%] px-1 sm:max-w-2xl", mine ? "text-right" : "text-left"), children: /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", { className: (0, import_utils.cn)("flex flex-wrap items-center gap-x-3 gap-y-1 text-xs text-muted-foreground", mine ? "justify-end" : "justify-start"), children: [
618
- authorName.trim() !== "" ? /* @__PURE__ */ (0, import_jsx_runtime.jsx)("span", { className: "font-semibold text-foreground", children: displayParticipantName(authorName) }) : null,
619
- /* @__PURE__ */ (0, import_jsx_runtime.jsx)("span", { children: timeAgo(message.createdAt) })
620
- ] }) }) }) : null,
699
+ shouldShowHeader ? /* @__PURE__ */ (0, import_jsx_runtime.jsx)("div", { className: (0, import_utils.cn)("flex w-full", mine ? "justify-end" : "justify-start"), children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)("div", { className: (0, import_utils.cn)("max-w-[85%] px-1 sm:max-w-2xl", mine ? "text-right" : "text-left"), children: /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(
700
+ "div",
701
+ {
702
+ className: (0, import_utils.cn)(
703
+ "flex flex-wrap items-center gap-x-3 gap-y-1 text-xs text-muted-foreground",
704
+ mine ? "justify-end" : "justify-start"
705
+ ),
706
+ children: [
707
+ authorName.trim() !== "" ? /* @__PURE__ */ (0, import_jsx_runtime.jsx)("span", { className: "font-semibold text-foreground", children: displayParticipantName(authorName) }) : null,
708
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)("span", { children: timeAgo(message.createdAt) })
709
+ ]
710
+ }
711
+ ) }) }) : null,
621
712
  message.text.trim() !== "" ? /* @__PURE__ */ (0, import_jsx_runtime.jsx)("div", { className: (0, import_utils.cn)("flex w-full", mine ? "justify-end" : "justify-start"), children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(ChatBubble, { text: message.text, mine }) }) : null,
622
- message.attachments.length > 0 ? /* @__PURE__ */ (0, import_jsx_runtime.jsx)("div", { className: (0, import_utils.cn)("flex w-full", mine ? "justify-end" : "justify-start"), children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)("div", { className: (0, import_utils.cn)("flex max-w-[85%] flex-wrap gap-3 px-1 sm:max-w-2xl", mine ? "justify-end" : "justify-start"), children: message.attachments.map((attachment, index) => /* @__PURE__ */ (0, import_jsx_runtime.jsx)(AttachmentView, { room, path: attachment }, `${message.id}:attachment:${attachment}:${index}`)) }) }) : null,
713
+ message.attachments.length > 0 ? /* @__PURE__ */ (0, import_jsx_runtime.jsx)("div", { className: (0, import_utils.cn)("flex w-full", mine ? "justify-end" : "justify-start"), children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
714
+ "div",
715
+ {
716
+ className: (0, import_utils.cn)(
717
+ "flex max-w-[85%] flex-wrap gap-3 px-1 sm:max-w-2xl",
718
+ mine ? "justify-end" : "justify-start"
719
+ ),
720
+ children: message.attachments.map((attachment, index) => /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
721
+ AttachmentView,
722
+ {
723
+ room,
724
+ path: attachment
725
+ },
726
+ `${message.id}:attachment:${attachment}:${index}`
727
+ ))
728
+ }
729
+ ) }) : null,
623
730
  message.image ? /* @__PURE__ */ (0, import_jsx_runtime.jsx)("div", { className: "flex w-full justify-start", children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(GeneratedImageView, { image: message.image }) }) : null
624
731
  ] });
625
732
  }
@@ -632,10 +739,7 @@ function EmptyState({ title, description }) {
632
739
  function LoadingState() {
633
740
  return /* @__PURE__ */ (0, import_jsx_runtime.jsx)("div", { className: "h-full mx-auto flex max-w-2xl flex-col items-center justify-center px-6 py-20 text-muted-foreground", children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_spinner.Spinner, { size: "lg" }) });
634
741
  }
635
- function ErrorBanner({
636
- message,
637
- onRetry
638
- }) {
742
+ function ErrorBanner({ message, onRetry }) {
639
743
  return /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", { className: "mx-auto flex w-full max-w-[912px] items-center justify-between gap-3 whitespace-pre-wrap rounded-md border border-destructive/30 bg-destructive/5 px-4 py-3 text-sm text-destructive", children: [
640
744
  /* @__PURE__ */ (0, import_jsx_runtime.jsx)("span", { children: message }),
641
745
  onRetry ? /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_button.Button, { type: "button", variant: "outline", size: "sm", onClick: onRetry, children: "Retry restore" }) : null
@@ -691,7 +795,9 @@ function processClientToolRequests({
691
795
  if (toolsByName.size === 0) {
692
796
  return;
693
797
  }
694
- 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));
798
+ const requests = session.messages.map((event) => event.message).filter(
799
+ (message) => message instanceof import_meshagent_agents.AgentClientToolCallRequested
800
+ ).filter((message) => message.toolkit === "client" && toolsByName.has(message.tool));
695
801
  const handledRequests = handledRequestsForSession(session);
696
802
  if (!initializedClientToolSessions.has(session)) {
697
803
  initializedClientToolSessions.add(session);
@@ -707,9 +813,11 @@ function processClientToolRequests({
707
813
  return;
708
814
  }
709
815
  replayingClientToolSessions.delete(session);
710
- 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));
816
+ const completedRequestIds = new Set(
817
+ (0, import_chat_thread_timeline.buildChatThreadTimeline)(session.messages).items.filter((item) => item.kind === "tool_call" && item.toolkit === "client" && (item.state === "completed" || item.state === "failed")).map((item) => item.clientToolRequestId ?? item.id)
818
+ );
711
819
  for (const request of requests) {
712
- if (completedItemIds.has(request.requestId)) {
820
+ if (completedRequestIds.has(request.requestId)) {
713
821
  handledRequests.add(request.requestId);
714
822
  }
715
823
  }
@@ -783,14 +891,20 @@ function AgentThreadProvider({
783
891
  closeThreadOnUnmount = false,
784
892
  onPersistedEventsInjectionStarted,
785
893
  onPersistedEventsInjected,
786
- onEventsChanged
894
+ onEventsChanged,
895
+ onSubmissionStarted,
896
+ onSubmissionFailed
787
897
  }) {
788
898
  const [attachments, setAttachments] = (0, import_react.useState)([]);
899
+ const [composerValue, setComposerValue] = (0, import_react.useState)("");
789
900
  const [sendError, setSendError] = (0, import_react.useState)(null);
790
901
  const [restorationError, setRestorationError] = (0, import_react.useState)(null);
791
902
  const [restorationAttempt, setRestorationAttempt] = (0, import_react.useState)(0);
792
903
  const [version, setVersion] = (0, import_react.useState)(0);
793
- const [clientToolCallOverrides, setClientToolCallOverrides] = (0, import_react.useState)(() => /* @__PURE__ */ new Map());
904
+ const [clientToolCallOverrides, setClientToolCallOverrides] = (0, import_react.useState)(
905
+ () => /* @__PURE__ */ new Map()
906
+ );
907
+ const attachmentStatusVersion = (0, import_chat_input_state.useAttachmentStatusVersion)(attachments);
794
908
  const sessionRef = (0, import_react.useRef)(null);
795
909
  const mountedRef = (0, import_react.useRef)(true);
796
910
  const persistedEventsRef = (0, import_react.useRef)(persistedEvents);
@@ -799,14 +913,11 @@ function AgentThreadProvider({
799
913
  const restorationReadyRef = (0, import_react.useRef)(!injectPersistedEvents);
800
914
  const pendingCloseRef = (0, import_react.useRef)(null);
801
915
  const ownsChatClient = chatClient == null;
802
- const activeChatClient = (0, import_react.useMemo)(
803
- () => {
804
- if (chatClient != null) return chatClient;
805
- if (room != null) return new import_meshagent_agents.MessagingChatClient({ room, agentName });
806
- throw new Error("AgentThread requires either a room or a chat client.");
807
- },
808
- [agentName, chatClient, room]
809
- );
916
+ const activeChatClient = (0, import_react.useMemo)(() => {
917
+ if (chatClient != null) return chatClient;
918
+ if (room != null) return new import_meshagent_agents.MessagingChatClient({ room, agentName });
919
+ throw new Error("AgentThread requires either a room or a chat client.");
920
+ }, [agentName, chatClient, room]);
810
921
  const resolvedClientToolkits = (0, import_react.useMemo)(
811
922
  () => (0, import_chat_feed_widget.resolveClientToolkitDescriptions)(clientToolkits, chatFeedWidgets, clientTools),
812
923
  [chatFeedWidgets, clientToolkits, clientTools]
@@ -893,7 +1004,9 @@ function AgentThreadProvider({
893
1004
  return;
894
1005
  }
895
1006
  restorationReadyRef.current = false;
896
- setRestorationError("Unable to restore conversation context: the server thread did not finish loading within 30 seconds.");
1007
+ setRestorationError(
1008
+ "Unable to restore conversation context: the server thread did not finish loading within 30 seconds."
1009
+ );
897
1010
  setVersion((current) => current + 1);
898
1011
  }, threadLoadTimeoutMs);
899
1012
  }
@@ -1061,24 +1174,32 @@ function AgentThreadProvider({
1061
1174
  }
1062
1175
  return persistedEvents == null ? (0, import_chat_thread_timeline.buildChatThreadTimeline)(session.messages, session.pendingInputs) : (0, import_chat_thread_timeline.buildMergedChatThreadTimeline)(persistedEvents, session.messages, session.pendingInputs);
1063
1176
  }, [deferLiveEvents, persistedEvents, session, version]);
1064
- const timelineItems = (0, import_react.useMemo)(() => (timeline?.items ?? []).map((item) => {
1065
- const override = session == null ? void 0 : clientToolCallOverrides.get(clientToolCallKey(session.threadPath, item.id));
1066
- if (override == null || item.kind !== "tool_call" || (item.state === "completed" || item.state === "failed")) {
1067
- return item;
1068
- }
1069
- return {
1070
- ...item,
1071
- state: override.status,
1072
- failed: override.status === "failed",
1073
- output: override.output ?? item.output
1074
- };
1075
- }), [clientToolCallOverrides, session, timeline]);
1177
+ const timelineItems = (0, import_react.useMemo)(
1178
+ () => (timeline?.items ?? []).map((item) => {
1179
+ const override = session == null ? void 0 : clientToolCallOverrides.get(clientToolCallKey(session.threadPath, item.clientToolRequestId ?? item.id));
1180
+ if (override == null || item.kind !== "tool_call" || item.state === "completed" || item.state === "failed") {
1181
+ return item;
1182
+ }
1183
+ return {
1184
+ ...item,
1185
+ state: override.status,
1186
+ failed: override.status === "failed",
1187
+ output: override.output ?? item.output
1188
+ };
1189
+ }),
1190
+ [clientToolCallOverrides, session, timeline]
1191
+ );
1076
1192
  const showThreadLoading = (deferLiveEvents || session === null || session.isLoading) && timelineItems.length === 0;
1077
1193
  const feedTimelineItems = (0, import_react.useMemo)(
1078
- () => timelineItems.filter((item) => !(item.kind === "tool_call" && item.toolkit === "client" && item.tool != null && clientToolsByName.has(item.tool))),
1194
+ () => timelineItems.filter(
1195
+ (item) => !(item.kind === "tool_call" && item.toolkit === "client" && item.tool != null && clientToolsByName.has(item.tool))
1196
+ ),
1079
1197
  [clientToolsByName, timelineItems]
1080
1198
  );
1081
- const renderedItems = (0, import_react.useMemo)(() => collapseMessages ? groupThreadItems(feedTimelineItems, chatFeedWidgetsByName) : feedTimelineItems, [chatFeedWidgetsByName, collapseMessages, feedTimelineItems]);
1199
+ const renderedItems = (0, import_react.useMemo)(
1200
+ () => collapseMessages ? groupThreadItems(feedTimelineItems, chatFeedWidgetsByName) : feedTimelineItems,
1201
+ [chatFeedWidgetsByName, collapseMessages, feedTimelineItems]
1202
+ );
1082
1203
  const status = (0, import_react.useMemo)(() => {
1083
1204
  if (session == null) return null;
1084
1205
  let current = null;
@@ -1099,7 +1220,19 @@ function AgentThreadProvider({
1099
1220
  const usage = timeline?.usage ?? null;
1100
1221
  const statusText = status?.status?.trim() || null;
1101
1222
  const turnId = stringValue(status?.turnId);
1102
- const canInterruptActiveTurn = turnId != null && (agentParticipant != null || chatClient != null);
1223
+ const interruptibleTurnId = (0, import_react.useMemo)(() => {
1224
+ let active = null;
1225
+ for (const event of session?.messages ?? []) {
1226
+ if (event.message instanceof import_meshagent_agents.TurnStarted) {
1227
+ active = event.message.turnId;
1228
+ }
1229
+ if (event.message instanceof import_meshagent_agents.TurnEnded && event.message.turnId === active) {
1230
+ active = null;
1231
+ }
1232
+ }
1233
+ return active ?? turnId;
1234
+ }, [session, version, turnId]);
1235
+ const canInterruptActiveTurn = interruptibleTurnId != null && (agentParticipant != null || chatClient != null);
1103
1236
  const renderedItemsNewestFirst = (0, import_react.useMemo)(() => [...renderedItems].reverse(), [renderedItems]);
1104
1237
  const firstRenderedItemId = renderedItems[0]?.id;
1105
1238
  const lastRenderedItemId = renderedItems[renderedItems.length - 1]?.id;
@@ -1110,94 +1243,149 @@ function AgentThreadProvider({
1110
1243
  });
1111
1244
  return previousById;
1112
1245
  }, [renderedItems]);
1113
- const selectAttachments = (0, import_react.useCallback)((files) => {
1114
- if (room == null) return;
1115
- const nextAttachments = files.map((file) => new import_file_attachment.MeshagentFileUpload(
1116
- room,
1117
- `uploaded-files/${file.name}`,
1118
- (0, import_file_attachment.fileToAsyncIterable)(file),
1119
- file.size
1120
- ));
1121
- setAttachments((current) => [...current, ...nextAttachments]);
1122
- }, [room]);
1123
- const handleSend = (0, import_react.useCallback)(async (message) => {
1124
- if (message.text.trim() === "" && message.attachments.length === 0) {
1125
- return;
1126
- }
1127
- if (!agentParticipant && chatClient == null) {
1128
- setSendError("This thread requires an online agent that supports agent messages.");
1129
- return;
1130
- }
1131
- const openSession = sessionRef.current;
1132
- if (openSession === null) {
1133
- setSendError("No thread session is open.");
1134
- return;
1135
- }
1136
- const normalizedAttachments = message.attachments.map(normalizeAgentAttachmentUrl).filter((attachment) => attachment !== null);
1137
- try {
1138
- await openSession.sendText({
1139
- messageId: message.id,
1140
- text: message.text,
1141
- attachments: normalizedAttachments.map((url) => new import_meshagent_agents.AgentFileContent({ url })),
1142
- turnId,
1143
- steer: status?.mode === "steerable" && turnId != null,
1144
- senderName: localParticipantName.trim() || void 0,
1145
- clientToolkits: resolvedClientToolkits
1146
- });
1147
- setSendError(null);
1148
- setVersion((current) => current + 1);
1149
- } catch (error) {
1150
- setSendError(describeError(error));
1151
- }
1152
- }, [agentParticipant, chatClient, resolvedClientToolkits, localParticipantName, status?.mode, turnId]);
1246
+ const selectAttachments = (0, import_react.useCallback)(
1247
+ (files) => {
1248
+ if (room == null) return;
1249
+ const nextAttachments = files.map(
1250
+ (file) => new import_file_attachment.MeshagentFileUpload(room, `uploaded-files/${file.name}`, (0, import_file_attachment.fileToAsyncIterable)(file), file.size)
1251
+ );
1252
+ setAttachments((current) => [...current, ...nextAttachments]);
1253
+ },
1254
+ [room]
1255
+ );
1256
+ const handleSend = (0, import_react.useCallback)(
1257
+ async (message) => {
1258
+ if (message.text.trim() === "" && message.attachments.length === 0) {
1259
+ return;
1260
+ }
1261
+ if (!agentParticipant && chatClient == null) {
1262
+ setSendError("This thread requires an online agent that supports agent messages.");
1263
+ return;
1264
+ }
1265
+ const openSession = sessionRef.current;
1266
+ if (openSession === null) {
1267
+ setSendError("No thread session is open.");
1268
+ return;
1269
+ }
1270
+ const normalizedAttachments = message.attachments.map(normalizeAgentAttachmentUrl).filter((attachment) => attachment !== null);
1271
+ const steeringTurnId = status?.mode === "steerable" && turnId != null ? turnId : void 0;
1272
+ onSubmissionStarted?.(message, steeringTurnId);
1273
+ try {
1274
+ await openSession.sendText({
1275
+ messageId: message.id,
1276
+ text: message.text,
1277
+ attachments: normalizedAttachments.map((url) => new import_meshagent_agents.AgentFileContent({ url })),
1278
+ turnId,
1279
+ steer: status?.mode === "steerable" && turnId != null,
1280
+ senderName: localParticipantName.trim() || void 0,
1281
+ clientToolkits: resolvedClientToolkits
1282
+ });
1283
+ setSendError(null);
1284
+ setVersion((current) => current + 1);
1285
+ } catch (error) {
1286
+ onSubmissionFailed?.(message, error);
1287
+ setSendError(describeError(error));
1288
+ }
1289
+ },
1290
+ [
1291
+ agentParticipant,
1292
+ chatClient,
1293
+ resolvedClientToolkits,
1294
+ localParticipantName,
1295
+ status?.mode,
1296
+ turnId,
1297
+ onSubmissionStarted,
1298
+ onSubmissionFailed
1299
+ ]
1300
+ );
1153
1301
  const composerDisabled = composerDisabledProp || loadThread && !restorationReadyRef.current || injectPersistedEvents && restoredPathRef.current !== path || agentParticipant == null && chatClient == null;
1154
- const handleWidgetMessage = (0, import_react.useCallback)((message) => {
1155
- const text = message.trim();
1156
- if (text === "" || composerDisabled) {
1157
- return;
1158
- }
1159
- void handleSend(new import_chat_message.ChatMessage({
1160
- id: (0, import_uuid.v4)(),
1161
- text
1162
- }));
1163
- }, [composerDisabled, handleSend]);
1302
+ const allAttachmentsUploaded = (0, import_react.useMemo)(
1303
+ () => attachments.every((attachment) => attachment.status === import_file_attachment.UploadStatus.Completed),
1304
+ [attachmentStatusVersion, attachments]
1305
+ );
1306
+ const canSubmit = !composerDisabled && (composerValue.trim() !== "" || attachments.length > 0) && allAttachmentsUploaded;
1307
+ const handleComposerSubmit = (0, import_react.useCallback)(
1308
+ (message) => {
1309
+ if (!canSubmit) {
1310
+ return;
1311
+ }
1312
+ void handleSend(message);
1313
+ setComposerValue("");
1314
+ setAttachments([]);
1315
+ },
1316
+ [canSubmit, handleSend]
1317
+ );
1318
+ const submitDraft = (0, import_react.useCallback)(() => {
1319
+ handleComposerSubmit(
1320
+ new import_chat_message.ChatMessage({
1321
+ id: (0, import_uuid.v4)(),
1322
+ text: composerValue.trim(),
1323
+ attachments: attachments.map((attachment) => attachment.path)
1324
+ })
1325
+ );
1326
+ }, [attachments, composerValue, handleComposerSubmit]);
1327
+ const handleWidgetMessage = (0, import_react.useCallback)(
1328
+ (message) => {
1329
+ const text = message.trim();
1330
+ if (text === "" || composerDisabled) {
1331
+ return;
1332
+ }
1333
+ void handleSend(
1334
+ new import_chat_message.ChatMessage({
1335
+ id: (0, import_uuid.v4)(),
1336
+ text
1337
+ })
1338
+ );
1339
+ },
1340
+ [composerDisabled, handleSend]
1341
+ );
1164
1342
  const cancelTurn = (0, import_react.useCallback)(async () => {
1165
1343
  const openSession = sessionRef.current;
1166
- if (openSession === null || turnId == null) {
1344
+ if (openSession === null || interruptibleTurnId == null) {
1167
1345
  return;
1168
1346
  }
1169
- await openSession.interruptTurn(turnId);
1170
- }, [turnId]);
1171
- return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(AgentThreadContext.Provider, { value: {
1172
- room,
1173
- agentName,
1174
- emptyStateTitle,
1175
- emptyStateDescription,
1176
- chatFeedWidgetsByName,
1177
- timelineItems,
1178
- renderedItemsNewestFirst,
1179
- firstRenderedItemId,
1180
- lastRenderedItemId,
1181
- previousItemById,
1182
- showThreadLoading,
1183
- localParticipantName,
1184
- status,
1185
- statusText,
1186
- canInterruptActiveTurn,
1187
- restorationError,
1188
- retryRestoration,
1189
- handleWidgetMessage,
1190
- cancelTurn,
1191
- sendError,
1192
- composerDisabled,
1193
- handleSend,
1194
- attachments,
1195
- setAttachments,
1196
- selectAttachments,
1197
- enableFileUpload: enableFileUpload && room != null,
1198
- inputAvailable: agentParticipant != null || chatClient != null,
1199
- usage
1200
- }, children });
1347
+ await openSession.interruptTurn(interruptibleTurnId);
1348
+ }, [interruptibleTurnId]);
1349
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
1350
+ AgentThreadContext.Provider,
1351
+ {
1352
+ value: {
1353
+ room,
1354
+ agentName,
1355
+ emptyStateTitle,
1356
+ emptyStateDescription,
1357
+ chatFeedWidgetsByName,
1358
+ timelineItems,
1359
+ renderedItemsNewestFirst,
1360
+ firstRenderedItemId,
1361
+ lastRenderedItemId,
1362
+ previousItemById,
1363
+ showThreadLoading,
1364
+ localParticipantName,
1365
+ status,
1366
+ statusText,
1367
+ canInterruptActiveTurn,
1368
+ restorationError,
1369
+ retryRestoration,
1370
+ handleWidgetMessage,
1371
+ cancelTurn,
1372
+ sendError,
1373
+ composerDisabled,
1374
+ composerValue,
1375
+ setComposerValue,
1376
+ canSubmit,
1377
+ handleComposerSubmit,
1378
+ submitDraft,
1379
+ attachments,
1380
+ setAttachments,
1381
+ selectAttachments,
1382
+ enableFileUpload: enableFileUpload && room != null,
1383
+ inputAvailable: agentParticipant != null || chatClient != null,
1384
+ usage
1385
+ },
1386
+ children
1387
+ }
1388
+ );
1201
1389
  }
1202
1390
  function useAgentThreadContext(componentName) {
1203
1391
  const context = (0, import_react.useContext)(AgentThreadContext);
@@ -1206,14 +1394,25 @@ function useAgentThreadContext(componentName) {
1206
1394
  }
1207
1395
  return context;
1208
1396
  }
1209
- function AgentThreadFeed() {
1397
+ function useAgentThreadFeedState() {
1398
+ const { renderedItemsNewestFirst } = useAgentThreadContext("useAgentThreadFeedState");
1399
+ return (0, import_react.useMemo)(() => ({ items: [...renderedItemsNewestFirst].reverse() }), [renderedItemsNewestFirst]);
1400
+ }
1401
+ function useAgentThreadStatus() {
1402
+ const { canInterruptActiveTurn, cancelTurn } = useAgentThreadContext("useAgentThreadStatus");
1403
+ return { canInterrupt: canInterruptActiveTurn, interrupt: cancelTurn };
1404
+ }
1405
+ function AgentThreadFeed({
1406
+ renderAfterItem,
1407
+ renderUnanchored,
1408
+ showStatusIndicator = true
1409
+ } = {}) {
1210
1410
  const {
1211
1411
  room,
1212
1412
  agentName,
1213
1413
  emptyStateTitle,
1214
1414
  emptyStateDescription,
1215
1415
  chatFeedWidgetsByName,
1216
- timelineItems,
1217
1416
  renderedItemsNewestFirst,
1218
1417
  firstRenderedItemId,
1219
1418
  lastRenderedItemId,
@@ -1228,9 +1427,11 @@ function AgentThreadFeed() {
1228
1427
  handleWidgetMessage,
1229
1428
  cancelTurn
1230
1429
  } = useAgentThreadContext("AgentThreadFeed");
1430
+ const unanchoredContent = renderUnanchored?.();
1431
+ const hasUnanchoredContent = import_react.Children.toArray(unanchoredContent).length > 0;
1231
1432
  return /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(import_jsx_runtime.Fragment, { children: [
1232
1433
  /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", { className: "relative flex h-full min-h-0 flex-1 flex-col", children: [
1233
- 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)(
1434
+ showThreadLoading ? /* @__PURE__ */ (0, import_jsx_runtime.jsx)("div", { className: "min-h-0 flex-1 overflow-hidden", children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(LoadingState, {}) }) : renderedItemsNewestFirst.length === 0 ? hasUnanchoredContent ? /* @__PURE__ */ (0, import_jsx_runtime.jsx)("div", { className: "min-h-0 flex-1 overflow-y-auto", children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)("div", { className: "mx-auto w-full max-w-[912px] px-4 py-3", children: unanchoredContent }) }) : /* @__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)(
1234
1435
  import_chat_scroller.ChatScroller,
1235
1436
  {
1236
1437
  bottomThresholdPx: 24,
@@ -1239,26 +1440,36 @@ function AgentThreadFeed() {
1239
1440
  getMessageAuthorId: (item) => item.role,
1240
1441
  messages: renderedItemsNewestFirst,
1241
1442
  renderMessage: (item) => {
1242
- return /* @__PURE__ */ (0, import_jsx_runtime.jsx)("div", { className: (0, import_utils.cn)(
1243
- "mx-auto w-full max-w-[912px] px-1 py-3",
1244
- item.id === firstRenderedItemId ? "pt-6" : null,
1245
- item.id === lastRenderedItemId ? statusText ? "pb-24" : "pb-6" : null
1246
- ), children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
1247
- ThreadMessageView,
1443
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(
1444
+ "div",
1248
1445
  {
1249
- room,
1250
- message: item,
1251
- previous: previousItemById.get(item.id) ?? null,
1252
- localParticipantName,
1253
- agentName,
1254
- chatFeedWidgetsByName,
1255
- onSendMessage: handleWidgetMessage
1446
+ className: (0, import_utils.cn)(
1447
+ "mx-auto w-full max-w-[912px] px-1 py-3",
1448
+ item.id === firstRenderedItemId ? "pt-6" : null,
1449
+ item.id === lastRenderedItemId ? showStatusIndicator && statusText ? "pb-24" : "pb-6" : null
1450
+ ),
1451
+ children: [
1452
+ item.id === firstRenderedItemId ? unanchoredContent : null,
1453
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
1454
+ ThreadMessageView,
1455
+ {
1456
+ room,
1457
+ message: item,
1458
+ previous: previousItemById.get(item.id) ?? null,
1459
+ localParticipantName,
1460
+ agentName,
1461
+ chatFeedWidgetsByName,
1462
+ onSendMessage: handleWidgetMessage
1463
+ }
1464
+ ),
1465
+ renderAfterItem?.(item)
1466
+ ]
1256
1467
  }
1257
- ) });
1468
+ );
1258
1469
  }
1259
1470
  }
1260
1471
  ),
1261
- statusText ? /* @__PURE__ */ (0, import_jsx_runtime.jsx)("div", { className: "pointer-events-none absolute inset-x-0 bottom-0 flex justify-center px-4 pb-4", children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)("div", { className: "pointer-events-auto w-full max-w-[912px]", children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
1472
+ showStatusIndicator && statusText ? /* @__PURE__ */ (0, import_jsx_runtime.jsx)("div", { className: "pointer-events-none absolute inset-x-0 bottom-0 flex justify-center px-4 pb-4", children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)("div", { className: "pointer-events-auto w-full max-w-[912px]", children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
1262
1473
  import_chat_typing_indicator.ChatTypingIndicator,
1263
1474
  {
1264
1475
  typing: false,
@@ -1273,21 +1484,24 @@ function AgentThreadFeed() {
1273
1484
  }
1274
1485
  ) }) }) : null
1275
1486
  ] }),
1276
- restorationError ? /* @__PURE__ */ (0, import_jsx_runtime.jsx)("div", { className: "px-4 pb-2", children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
1277
- ErrorBanner,
1278
- {
1279
- message: restorationError,
1280
- onRetry: retryRestoration
1281
- }
1282
- ) }) : null
1487
+ restorationError ? /* @__PURE__ */ (0, import_jsx_runtime.jsx)("div", { className: "px-4 pb-2", children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(ErrorBanner, { message: restorationError, onRetry: retryRestoration }) }) : null
1283
1488
  ] });
1284
1489
  }
1285
- function AgentThreadInput() {
1490
+ function AgentThreadInput({
1491
+ className,
1492
+ inputRowClassName,
1493
+ textareaClassName,
1494
+ leadingButton,
1495
+ showSubmitButton = true,
1496
+ submitButtonComponent
1497
+ } = {}) {
1286
1498
  const {
1287
1499
  agentName,
1288
1500
  sendError,
1289
1501
  composerDisabled,
1290
- handleSend,
1502
+ composerValue,
1503
+ setComposerValue,
1504
+ handleComposerSubmit,
1291
1505
  attachments,
1292
1506
  setAttachments,
1293
1507
  selectAttachments,
@@ -1297,23 +1511,48 @@ function AgentThreadInput() {
1297
1511
  } = useAgentThreadContext("AgentThreadInput");
1298
1512
  return /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(import_jsx_runtime.Fragment, { children: [
1299
1513
  sendError ? /* @__PURE__ */ (0, import_jsx_runtime.jsx)("div", { className: "px-4 pb-2", children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(ErrorBanner, { message: sendError }) }) : null,
1300
- /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", { className: "flex flex-col gap-1", children: [
1301
- /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
1302
- import_chat_input.ChatInput,
1303
- {
1304
- onSubmit: handleSend,
1305
- attachments,
1306
- onFilesSelected: selectAttachments,
1307
- setAttachments,
1308
- enableFileUpload,
1309
- disabled: composerDisabled,
1310
- placeholder: inputAvailable ? "Type a message" : `Waiting for ${displayParticipantName(agentName)}`
1311
- }
1312
- ),
1313
- /* @__PURE__ */ (0, import_jsx_runtime.jsx)(AgentUsageFooter, { usage, className: "mx-auto w-full max-w-[912px]" })
1314
- ] })
1514
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)("div", { className: "flex flex-col gap-1", children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
1515
+ import_chat_input.ChatInput,
1516
+ {
1517
+ className,
1518
+ inputRowClassName,
1519
+ textareaClassName,
1520
+ leadingButton,
1521
+ onSubmit: handleComposerSubmit,
1522
+ attachments,
1523
+ onFilesSelected: selectAttachments,
1524
+ setAttachments,
1525
+ enableFileUpload,
1526
+ disabled: composerDisabled,
1527
+ clearOnSubmit: false,
1528
+ value: composerValue,
1529
+ onValueChange: setComposerValue,
1530
+ showSubmitButton,
1531
+ submitButtonComponent,
1532
+ placeholder: inputAvailable ? "Type a message" : `Waiting for ${displayParticipantName(agentName)}`
1533
+ }
1534
+ ) })
1315
1535
  ] });
1316
1536
  }
1537
+ function AgentThreadSubmitButton({
1538
+ className,
1539
+ icon,
1540
+ title,
1541
+ ariaLabel
1542
+ } = {}) {
1543
+ const { canSubmit, submitDraft } = useAgentThreadContext("AgentThreadSubmitButton");
1544
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
1545
+ import_composer_action_button.ComposerActionButton,
1546
+ {
1547
+ className,
1548
+ disabled: !canSubmit,
1549
+ onClick: submitDraft,
1550
+ icon,
1551
+ title,
1552
+ ariaLabel
1553
+ }
1554
+ );
1555
+ }
1317
1556
  function AgentThread(props) {
1318
1557
  return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(AgentThreadProvider, { ...props, children: /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", { className: "flex h-full min-h-0 flex-1 flex-col", children: [
1319
1558
  /* @__PURE__ */ (0, import_jsx_runtime.jsx)(AgentThreadFeed, {}),