@copilotz/chat-ui 0.6.4 → 0.6.6

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.
package/dist/index.cjs CHANGED
@@ -543,6 +543,7 @@ var CollapsibleContent2 = CollapsiblePrimitive.CollapsibleContent;
543
543
  var import_lucide_react = require("lucide-react");
544
544
  var import_jsx_runtime7 = require("react/jsx-runtime");
545
545
  var ROOT_SPACING_CLASS = "mb-4 w-full max-w-full min-w-0";
546
+ var ACTION_SLOT_CLASS = "inline-flex h-9 min-w-[132px] items-center justify-end px-2 text-xs";
546
547
  var interpolate = (template, replacements) => Object.entries(replacements).reduce(
547
548
  (output, [key, value]) => output.replaceAll(`{{${key}}}`, String(value ?? "")),
548
549
  template
@@ -617,15 +618,15 @@ var ActivitySummaryRow = (0, import_react.memo)(function ActivitySummaryRow2({
617
618
  hasDetails,
618
619
  open
619
620
  }) {
620
- if (!hasDetails) {
621
- return /* @__PURE__ */ (0, import_jsx_runtime7.jsx)("div", { className: "block w-full min-w-0", children: /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(ActivitySummaryCard, { activity, labels }) });
622
- }
623
621
  return /* @__PURE__ */ (0, import_jsx_runtime7.jsxs)("div", { className: "grid w-full min-w-0 grid-cols-[minmax(0,1fr)_auto] items-center gap-2", children: [
624
622
  /* @__PURE__ */ (0, import_jsx_runtime7.jsx)("div", { className: "min-w-0", children: /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(ActivitySummaryCard, { activity, labels }) }),
625
- /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(CollapsibleTrigger2, { asChild: true, children: /* @__PURE__ */ (0, import_jsx_runtime7.jsxs)(Button, { variant: "ghost", size: "sm", className: "h-9 shrink-0 px-2 text-xs text-muted-foreground", children: [
623
+ hasDetails ? /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(CollapsibleTrigger2, { asChild: true, children: /* @__PURE__ */ (0, import_jsx_runtime7.jsxs)(Button, { variant: "ghost", size: "sm", className: cn(ACTION_SLOT_CLASS, "shrink-0 text-muted-foreground"), children: [
626
624
  open ? labels?.activityHideDetails || "Hide details" : labels?.activityShowDetails || "Show details",
627
625
  open ? /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(import_lucide_react.ChevronDown, { className: "ml-1 h-3.5 w-3.5" }) : /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(import_lucide_react.ChevronRight, { className: "ml-1 h-3.5 w-3.5" })
628
- ] }) })
626
+ ] }) }) : /* @__PURE__ */ (0, import_jsx_runtime7.jsxs)("div", { "aria-hidden": "true", className: cn(ACTION_SLOT_CLASS, "pointer-events-none invisible shrink-0"), children: [
627
+ labels?.activityShowDetails || "Show details",
628
+ /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(import_lucide_react.ChevronRight, { className: "ml-1 h-3.5 w-3.5" })
629
+ ] })
629
630
  ] });
630
631
  });
631
632
  var ActivityDetails = (0, import_react.memo)(function ActivityDetails2({
@@ -689,21 +690,26 @@ var AssistantActivity = (0, import_react.memo)(function AssistantActivity2({
689
690
  setOpen(true);
690
691
  }
691
692
  }, [activity.isActive, hasDetails]);
692
- if (!hasDetails) {
693
- return /* @__PURE__ */ (0, import_jsx_runtime7.jsx)("div", { className: ROOT_SPACING_CLASS, children: /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(ActivitySummaryCard, { activity, labels }) });
694
- }
695
- return /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(Collapsible, { open, onOpenChange: setOpen, className: ROOT_SPACING_CLASS, children: /* @__PURE__ */ (0, import_jsx_runtime7.jsxs)("div", { className: "space-y-2", children: [
696
- /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(
697
- ActivitySummaryRow,
698
- {
699
- activity,
700
- labels,
701
- hasDetails,
702
- open
703
- }
704
- ),
705
- /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(CollapsibleContent2, { className: "w-full overflow-hidden rounded-lg border border-border/60 bg-muted/10 px-3", children: /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(ActivityDetails, { activity }) })
706
- ] }) });
693
+ return /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(
694
+ Collapsible,
695
+ {
696
+ open: hasDetails ? open : false,
697
+ onOpenChange: hasDetails ? setOpen : void 0,
698
+ className: ROOT_SPACING_CLASS,
699
+ children: /* @__PURE__ */ (0, import_jsx_runtime7.jsxs)("div", { className: "space-y-2", children: [
700
+ /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(
701
+ ActivitySummaryRow,
702
+ {
703
+ activity,
704
+ labels,
705
+ hasDetails,
706
+ open
707
+ }
708
+ ),
709
+ hasDetails && /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(CollapsibleContent2, { className: "w-full overflow-hidden rounded-lg border border-border/60 bg-muted/10 px-3", children: /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(ActivityDetails, { activity }) })
710
+ ] })
711
+ }
712
+ );
707
713
  });
708
714
 
709
715
  // src/components/chat/Message.tsx
@@ -5041,6 +5047,25 @@ function getMessageSpeakerKey(message) {
5041
5047
  }
5042
5048
  return message.role;
5043
5049
  }
5050
+ function getAssistantSpeakerTokens(message) {
5051
+ if (!message || message.role !== "assistant") return [];
5052
+ const rawTokens = [message.senderAgentId, message.senderName].filter((value) => typeof value === "string" && value.trim().length > 0).map((value) => value.trim().toLowerCase());
5053
+ if (rawTokens.length > 0) {
5054
+ return Array.from(new Set(rawTokens));
5055
+ }
5056
+ return ["assistant"];
5057
+ }
5058
+ function canGroupMessages(previous, next) {
5059
+ if (previous.role !== next.role) {
5060
+ return false;
5061
+ }
5062
+ if (previous.role !== "assistant") {
5063
+ return getMessageSpeakerKey(previous) === getMessageSpeakerKey(next);
5064
+ }
5065
+ const previousTokens = getAssistantSpeakerTokens(previous);
5066
+ const nextTokens = getAssistantSpeakerTokens(next);
5067
+ return previousTokens.some((token) => nextTokens.includes(token));
5068
+ }
5044
5069
  var mergeToolCalls = (activities) => {
5045
5070
  const merged = /* @__PURE__ */ new Map();
5046
5071
  for (const activity of activities) {
@@ -5106,7 +5131,7 @@ var groupMessagesForRender = (messages) => {
5106
5131
  for (let index = 1; index < messages.length; index++) {
5107
5132
  const previous = currentGroup[currentGroup.length - 1];
5108
5133
  const next = messages[index];
5109
- if (previous.role === next.role && getMessageSpeakerKey(previous) === getMessageSpeakerKey(next)) {
5134
+ if (canGroupMessages(previous, next)) {
5110
5135
  currentGroup.push(next);
5111
5136
  continue;
5112
5137
  }
@@ -5122,6 +5147,7 @@ var ChatUI = ({
5122
5147
  currentThreadId = null,
5123
5148
  config: userConfig,
5124
5149
  sidebar: _sidebar,
5150
+ userMenuAdditionalItems,
5125
5151
  isGenerating = false,
5126
5152
  isMessagesLoading = false,
5127
5153
  isLoadingOlderMessages = false,
@@ -5569,7 +5595,8 @@ var ChatUI = ({
5569
5595
  user: sidebarUser,
5570
5596
  userMenuCallbacks: sidebarUserMenuCallbacks,
5571
5597
  currentTheme: config.ui.theme === "auto" ? "system" : config.ui.theme,
5572
- showThemeOptions: !!callbacks.onThemeChange
5598
+ showThemeOptions: !!callbacks.onThemeChange,
5599
+ userMenuAdditionalItems
5573
5600
  }
5574
5601
  ),
5575
5602
  /* @__PURE__ */ (0, import_jsx_runtime27.jsx)(SidebarInset, { children: /* @__PURE__ */ (0, import_jsx_runtime27.jsxs)("div", { className: "flex flex-col h-full min-h-0", children: [