@copilotz/chat-ui 0.1.21 → 0.1.23

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
@@ -632,17 +632,29 @@ var ThinkingIndicator = (0, import_react.memo)(function ThinkingIndicator2({ lab
632
632
  });
633
633
  var ThinkingBlock = (0, import_react.memo)(function ThinkingBlock2({ content, isStreaming = false, label = "Thinking", chunkSize = 12e3 }) {
634
634
  const [open, setOpen] = (0, import_react.useState)(isStreaming);
635
+ const [thinkingActive, setThinkingActive] = (0, import_react.useState)(false);
636
+ const contentLenRef = (0, import_react.useRef)(0);
635
637
  (0, import_react.useEffect)(() => {
636
- if (isStreaming) setOpen(true);
637
- }, [isStreaming]);
638
- (0, import_react.useEffect)(() => {
639
- if (!isStreaming && open) {
640
- const timer = setTimeout(() => setOpen(false), 600);
641
- return () => clearTimeout(timer);
638
+ if (!isStreaming) {
639
+ setThinkingActive(false);
640
+ contentLenRef.current = 0;
641
+ return;
642
+ }
643
+ if (content.length > contentLenRef.current) {
644
+ contentLenRef.current = content.length;
645
+ setThinkingActive(true);
642
646
  }
643
- }, [isStreaming, open]);
647
+ }, [content.length, isStreaming]);
648
+ (0, import_react.useEffect)(() => {
649
+ if (!thinkingActive || !isStreaming) return;
650
+ const timer = setTimeout(() => setThinkingActive(false), 1e3);
651
+ return () => clearTimeout(timer);
652
+ }, [thinkingActive, isStreaming, content.length]);
653
+ (0, import_react.useEffect)(() => {
654
+ if (isStreaming && content.length > 0) setOpen(true);
655
+ }, [isStreaming, content.length]);
644
656
  return /* @__PURE__ */ (0, import_jsx_runtime7.jsxs)("div", { className: "mb-3 relative rounded-lg overflow-hidden", children: [
645
- isStreaming && /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(
657
+ thinkingActive && /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(
646
658
  "div",
647
659
  {
648
660
  className: "absolute inset-0 rounded-lg pointer-events-none",
@@ -657,8 +669,8 @@ var ThinkingBlock = (0, import_react.memo)(function ThinkingBlock2({ content, is
657
669
  /* @__PURE__ */ (0, import_jsx_runtime7.jsxs)(
658
670
  "div",
659
671
  {
660
- className: `relative rounded-lg border bg-muted/30 ${isStreaming ? "border-transparent" : "border-muted-foreground/20"}`,
661
- style: isStreaming ? { margin: "1px" } : void 0,
672
+ className: `relative rounded-lg border bg-muted/30 ${thinkingActive ? "border-transparent" : "border-muted-foreground/20"}`,
673
+ style: thinkingActive ? { margin: "1px" } : void 0,
662
674
  children: [
663
675
  /* @__PURE__ */ (0, import_jsx_runtime7.jsxs)(
664
676
  "button",
@@ -667,10 +679,10 @@ var ThinkingBlock = (0, import_react.memo)(function ThinkingBlock2({ content, is
667
679
  className: "flex w-full items-center gap-2 px-3 py-2 text-left text-xs font-medium text-muted-foreground hover:text-foreground/70 transition-colors",
668
680
  onClick: () => setOpen((v) => !v),
669
681
  children: [
670
- /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(import_lucide_react.BrainCircuit, { className: `h-3.5 w-3.5 flex-shrink-0 ${isStreaming ? "animate-pulse text-primary" : ""}` }),
682
+ /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(import_lucide_react.BrainCircuit, { className: `h-3.5 w-3.5 flex-shrink-0 ${thinkingActive ? "animate-pulse text-primary" : ""}` }),
671
683
  /* @__PURE__ */ (0, import_jsx_runtime7.jsxs)("span", { className: "flex-1", children: [
672
- isStreaming ? label : `${label}`,
673
- isStreaming && /* @__PURE__ */ (0, import_jsx_runtime7.jsxs)("span", { className: "ml-1 inline-flex gap-0.5", children: [
684
+ label,
685
+ thinkingActive && /* @__PURE__ */ (0, import_jsx_runtime7.jsxs)("span", { className: "ml-1 inline-flex gap-0.5", children: [
674
686
  /* @__PURE__ */ (0, import_jsx_runtime7.jsx)("span", { className: "inline-block w-1 h-1 bg-current rounded-full animate-bounce", style: { animationDelay: "0ms" } }),
675
687
  /* @__PURE__ */ (0, import_jsx_runtime7.jsx)("span", { className: "inline-block w-1 h-1 bg-current rounded-full animate-bounce", style: { animationDelay: "150ms" } }),
676
688
  /* @__PURE__ */ (0, import_jsx_runtime7.jsx)("span", { className: "inline-block w-1 h-1 bg-current rounded-full animate-bounce", style: { animationDelay: "300ms" } })
@@ -689,7 +701,7 @@ var ThinkingBlock = (0, import_react.memo)(function ThinkingBlock2({ content, is
689
701
  chunkSize
690
702
  }
691
703
  ),
692
- isStreaming && /* @__PURE__ */ (0, import_jsx_runtime7.jsx)("span", { className: "inline-block w-1.5 h-3 bg-muted-foreground/40 animate-pulse ml-0.5" })
704
+ thinkingActive && /* @__PURE__ */ (0, import_jsx_runtime7.jsx)("span", { className: "inline-block w-1.5 h-3 bg-muted-foreground/40 animate-pulse ml-0.5" })
693
705
  ] }) })
694
706
  ]
695
707
  }