@yourgpt/copilot-sdk 2.1.5-alpha.2 → 2.1.5-alpha.3
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/ui/index.cjs +622 -231
- package/dist/ui/index.cjs.map +1 -1
- package/dist/ui/index.d.cts +297 -52
- package/dist/ui/index.d.ts +297 -52
- package/dist/ui/index.js +573 -183
- package/dist/ui/index.js.map +1 -1
- package/package.json +1 -1
package/dist/ui/index.cjs
CHANGED
|
@@ -20,7 +20,7 @@ require('../chunk-JEQ2X3Z6.cjs');
|
|
|
20
20
|
var clsx = require('clsx');
|
|
21
21
|
var tailwindMerge = require('tailwind-merge');
|
|
22
22
|
var jsxRuntime = require('react/jsx-runtime');
|
|
23
|
-
var
|
|
23
|
+
var React19 = require('react');
|
|
24
24
|
var streamdown = require('streamdown');
|
|
25
25
|
var code = require('@streamdown/code');
|
|
26
26
|
var reactSlot = require('@radix-ui/react-slot');
|
|
@@ -50,7 +50,7 @@ function _interopNamespace(e) {
|
|
|
50
50
|
return Object.freeze(n);
|
|
51
51
|
}
|
|
52
52
|
|
|
53
|
-
var
|
|
53
|
+
var React19__namespace = /*#__PURE__*/_interopNamespace(React19);
|
|
54
54
|
var AvatarPrimitive__namespace = /*#__PURE__*/_interopNamespace(AvatarPrimitive);
|
|
55
55
|
var HoverCardPrimitive__namespace = /*#__PURE__*/_interopNamespace(HoverCardPrimitive);
|
|
56
56
|
|
|
@@ -366,7 +366,7 @@ function MarkdownComponent({
|
|
|
366
366
|
}
|
|
367
367
|
) });
|
|
368
368
|
}
|
|
369
|
-
var Markdown =
|
|
369
|
+
var Markdown = React19.memo(MarkdownComponent);
|
|
370
370
|
Markdown.displayName = "Markdown";
|
|
371
371
|
function CodeBlock({ children, className, ...props }) {
|
|
372
372
|
return /* @__PURE__ */ jsxRuntime.jsx(
|
|
@@ -407,7 +407,7 @@ var buttonVariants = classVarianceAuthority.cva(
|
|
|
407
407
|
}
|
|
408
408
|
}
|
|
409
409
|
);
|
|
410
|
-
var Button =
|
|
410
|
+
var Button = React19__namespace.forwardRef(
|
|
411
411
|
({ className, variant, size, asChild = false, ...props }, ref) => {
|
|
412
412
|
const Comp = asChild ? reactSlot.Slot : "button";
|
|
413
413
|
return /* @__PURE__ */ jsxRuntime.jsx(
|
|
@@ -648,7 +648,7 @@ function TooltipTrigger({
|
|
|
648
648
|
disabled,
|
|
649
649
|
...props
|
|
650
650
|
}) {
|
|
651
|
-
if (asChild &&
|
|
651
|
+
if (asChild && React19__namespace.default.isValidElement(children)) {
|
|
652
652
|
return /* @__PURE__ */ jsxRuntime.jsx(tooltip.Tooltip.Trigger, { disabled, render: children, ...props });
|
|
653
653
|
}
|
|
654
654
|
return /* @__PURE__ */ jsxRuntime.jsx(tooltip.Tooltip.Trigger, { disabled, ...props, children });
|
|
@@ -677,7 +677,7 @@ function TooltipContent({
|
|
|
677
677
|
}
|
|
678
678
|
) }) });
|
|
679
679
|
}
|
|
680
|
-
var Avatar =
|
|
680
|
+
var Avatar = React19__namespace.forwardRef(({ className, ...props }, ref) => /* @__PURE__ */ jsxRuntime.jsx(
|
|
681
681
|
AvatarPrimitive__namespace.Root,
|
|
682
682
|
{
|
|
683
683
|
ref,
|
|
@@ -689,7 +689,7 @@ var Avatar = React17__namespace.forwardRef(({ className, ...props }, ref) => /*
|
|
|
689
689
|
}
|
|
690
690
|
));
|
|
691
691
|
Avatar.displayName = AvatarPrimitive__namespace.Root.displayName;
|
|
692
|
-
var AvatarImage =
|
|
692
|
+
var AvatarImage = React19__namespace.forwardRef(({ className, ...props }, ref) => /* @__PURE__ */ jsxRuntime.jsx(
|
|
693
693
|
AvatarPrimitive__namespace.Image,
|
|
694
694
|
{
|
|
695
695
|
ref,
|
|
@@ -698,7 +698,7 @@ var AvatarImage = React17__namespace.forwardRef(({ className, ...props }, ref) =
|
|
|
698
698
|
}
|
|
699
699
|
));
|
|
700
700
|
AvatarImage.displayName = AvatarPrimitive__namespace.Image.displayName;
|
|
701
|
-
var AvatarFallback =
|
|
701
|
+
var AvatarFallback = React19__namespace.forwardRef(({ className, ...props }, ref) => /* @__PURE__ */ jsxRuntime.jsx(
|
|
702
702
|
AvatarPrimitive__namespace.Fallback,
|
|
703
703
|
{
|
|
704
704
|
ref,
|
|
@@ -758,7 +758,34 @@ var MessageContent = ({
|
|
|
758
758
|
);
|
|
759
759
|
return markdown ? /* @__PURE__ */ jsxRuntime.jsx(Markdown, { className: classNames, ...props, children }) : /* @__PURE__ */ jsxRuntime.jsx("div", { className: classNames, ...props, children });
|
|
760
760
|
};
|
|
761
|
-
var
|
|
761
|
+
var MessageActions = ({
|
|
762
|
+
children,
|
|
763
|
+
className,
|
|
764
|
+
...props
|
|
765
|
+
}) => /* @__PURE__ */ jsxRuntime.jsx(
|
|
766
|
+
"div",
|
|
767
|
+
{
|
|
768
|
+
className: cn(
|
|
769
|
+
"csdk-message-actions text-muted-foreground flex items-center gap-2",
|
|
770
|
+
className
|
|
771
|
+
),
|
|
772
|
+
...props,
|
|
773
|
+
children
|
|
774
|
+
}
|
|
775
|
+
);
|
|
776
|
+
var MessageAction = ({
|
|
777
|
+
tooltip,
|
|
778
|
+
children,
|
|
779
|
+
className,
|
|
780
|
+
side = "top",
|
|
781
|
+
...props
|
|
782
|
+
}) => {
|
|
783
|
+
return /* @__PURE__ */ jsxRuntime.jsx(TooltipProvider, { children: /* @__PURE__ */ jsxRuntime.jsxs(Tooltip, { ...props, children: [
|
|
784
|
+
/* @__PURE__ */ jsxRuntime.jsx(TooltipTrigger, { asChild: true, children }),
|
|
785
|
+
/* @__PURE__ */ jsxRuntime.jsx(TooltipContent, { side, className, children: tooltip })
|
|
786
|
+
] }) });
|
|
787
|
+
};
|
|
788
|
+
var Textarea = React19__namespace.forwardRef(({ className, ...props }, ref) => {
|
|
762
789
|
return /* @__PURE__ */ jsxRuntime.jsx(
|
|
763
790
|
"textarea",
|
|
764
791
|
{
|
|
@@ -772,7 +799,7 @@ var Textarea = React17__namespace.forwardRef(({ className, ...props }, ref) => {
|
|
|
772
799
|
);
|
|
773
800
|
});
|
|
774
801
|
Textarea.displayName = "Textarea";
|
|
775
|
-
var PromptInputContext =
|
|
802
|
+
var PromptInputContext = React19.createContext({
|
|
776
803
|
isLoading: false,
|
|
777
804
|
value: "",
|
|
778
805
|
setValue: () => {
|
|
@@ -783,7 +810,7 @@ var PromptInputContext = React17.createContext({
|
|
|
783
810
|
textareaRef: { current: null }
|
|
784
811
|
});
|
|
785
812
|
function usePromptInput() {
|
|
786
|
-
return
|
|
813
|
+
return React19.useContext(PromptInputContext);
|
|
787
814
|
}
|
|
788
815
|
function PromptInput({
|
|
789
816
|
className,
|
|
@@ -797,8 +824,8 @@ function PromptInput({
|
|
|
797
824
|
onClick,
|
|
798
825
|
...props
|
|
799
826
|
}) {
|
|
800
|
-
const [internalValue, setInternalValue] =
|
|
801
|
-
const textareaRef =
|
|
827
|
+
const [internalValue, setInternalValue] = React19.useState(value || "");
|
|
828
|
+
const textareaRef = React19.useRef(null);
|
|
802
829
|
const handleChange = (newValue) => {
|
|
803
830
|
setInternalValue(newValue);
|
|
804
831
|
onValueChange?.(newValue);
|
|
@@ -855,7 +882,7 @@ function PromptInputTextarea({
|
|
|
855
882
|
textareaRef.current = el;
|
|
856
883
|
adjustHeight(el);
|
|
857
884
|
};
|
|
858
|
-
|
|
885
|
+
React19.useLayoutEffect(() => {
|
|
859
886
|
if (!textareaRef.current || disableAutosize) return;
|
|
860
887
|
const el = textareaRef.current;
|
|
861
888
|
el.style.height = "auto";
|
|
@@ -922,7 +949,7 @@ function PromptInputAction({
|
|
|
922
949
|
}
|
|
923
950
|
var HoverCard = HoverCardPrimitive__namespace.Root;
|
|
924
951
|
var HoverCardTrigger = HoverCardPrimitive__namespace.Trigger;
|
|
925
|
-
var HoverCardContent =
|
|
952
|
+
var HoverCardContent = React19__namespace.forwardRef(({ className, align = "center", sideOffset = 4, ...props }, ref) => /* @__PURE__ */ jsxRuntime.jsx(
|
|
926
953
|
HoverCardPrimitive__namespace.Content,
|
|
927
954
|
{
|
|
928
955
|
ref,
|
|
@@ -936,9 +963,9 @@ var HoverCardContent = React17__namespace.forwardRef(({ className, align = "cent
|
|
|
936
963
|
}
|
|
937
964
|
));
|
|
938
965
|
HoverCardContent.displayName = HoverCardPrimitive__namespace.Content.displayName;
|
|
939
|
-
var SourceContext =
|
|
966
|
+
var SourceContext = React19.createContext(null);
|
|
940
967
|
function useSourceContext() {
|
|
941
|
-
const ctx =
|
|
968
|
+
const ctx = React19.useContext(SourceContext);
|
|
942
969
|
if (!ctx) throw new Error("Source.* must be used inside <Source>");
|
|
943
970
|
return ctx;
|
|
944
971
|
}
|
|
@@ -1465,7 +1492,7 @@ function SourcesCollapsible({
|
|
|
1465
1492
|
defaultExpanded = false,
|
|
1466
1493
|
className
|
|
1467
1494
|
}) {
|
|
1468
|
-
const [expanded, setExpanded] =
|
|
1495
|
+
const [expanded, setExpanded] = React19__namespace.useState(defaultExpanded);
|
|
1469
1496
|
if (citations.length === 0) return null;
|
|
1470
1497
|
return /* @__PURE__ */ jsxRuntime.jsxs("div", { className: cn("border rounded-lg", className), children: [
|
|
1471
1498
|
/* @__PURE__ */ jsxRuntime.jsxs(
|
|
@@ -1531,7 +1558,7 @@ function SourcesList({
|
|
|
1531
1558
|
if (compact) {
|
|
1532
1559
|
return /* @__PURE__ */ jsxRuntime.jsxs("div", { className: cn("text-xs text-muted-foreground", className), children: [
|
|
1533
1560
|
/* @__PURE__ */ jsxRuntime.jsx("span", { className: "font-medium", children: "Sources: " }),
|
|
1534
|
-
citations.map((c, i) => /* @__PURE__ */ jsxRuntime.jsxs(
|
|
1561
|
+
citations.map((c, i) => /* @__PURE__ */ jsxRuntime.jsxs(React19__namespace.Fragment, { children: [
|
|
1535
1562
|
/* @__PURE__ */ jsxRuntime.jsxs(
|
|
1536
1563
|
"a",
|
|
1537
1564
|
{
|
|
@@ -1609,11 +1636,11 @@ function resultsToCitations(results) {
|
|
|
1609
1636
|
domain: result.domain || getDomain3(result.url)
|
|
1610
1637
|
}));
|
|
1611
1638
|
}
|
|
1612
|
-
var ReasoningContext =
|
|
1639
|
+
var ReasoningContext = React19__namespace.createContext(
|
|
1613
1640
|
null
|
|
1614
1641
|
);
|
|
1615
1642
|
function useReasoningContext() {
|
|
1616
|
-
const context =
|
|
1643
|
+
const context = React19__namespace.useContext(ReasoningContext);
|
|
1617
1644
|
if (!context) {
|
|
1618
1645
|
throw new Error(
|
|
1619
1646
|
"Reasoning components must be used within a Reasoning provider"
|
|
@@ -1629,11 +1656,11 @@ function Reasoning({
|
|
|
1629
1656
|
defaultOpen = false,
|
|
1630
1657
|
className
|
|
1631
1658
|
}) {
|
|
1632
|
-
const [uncontrolledOpen, setUncontrolledOpen] =
|
|
1633
|
-
const prevStreamingRef =
|
|
1659
|
+
const [uncontrolledOpen, setUncontrolledOpen] = React19__namespace.useState(defaultOpen);
|
|
1660
|
+
const prevStreamingRef = React19__namespace.useRef(isStreaming);
|
|
1634
1661
|
const isControlled = controlledOpen !== void 0;
|
|
1635
1662
|
const isOpen = isControlled ? controlledOpen : uncontrolledOpen;
|
|
1636
|
-
const setIsOpen =
|
|
1663
|
+
const setIsOpen = React19__namespace.useCallback(
|
|
1637
1664
|
(open) => {
|
|
1638
1665
|
if (onOpenChange) {
|
|
1639
1666
|
onOpenChange(open);
|
|
@@ -1644,7 +1671,7 @@ function Reasoning({
|
|
|
1644
1671
|
},
|
|
1645
1672
|
[isControlled, onOpenChange]
|
|
1646
1673
|
);
|
|
1647
|
-
|
|
1674
|
+
React19__namespace.useEffect(() => {
|
|
1648
1675
|
if (isStreaming && !prevStreamingRef.current) {
|
|
1649
1676
|
setIsOpen(true);
|
|
1650
1677
|
} else if (!isStreaming && prevStreamingRef.current) {
|
|
@@ -1700,9 +1727,9 @@ function ReasoningContent({
|
|
|
1700
1727
|
className
|
|
1701
1728
|
}) {
|
|
1702
1729
|
const { isOpen } = useReasoningContext();
|
|
1703
|
-
const contentRef =
|
|
1704
|
-
const [height, setHeight] =
|
|
1705
|
-
|
|
1730
|
+
const contentRef = React19__namespace.useRef(null);
|
|
1731
|
+
const [height, setHeight] = React19__namespace.useState(0);
|
|
1732
|
+
React19__namespace.useEffect(() => {
|
|
1706
1733
|
if (contentRef.current) {
|
|
1707
1734
|
const resizeObserver = new ResizeObserver((entries) => {
|
|
1708
1735
|
for (const entry of entries) {
|
|
@@ -1751,11 +1778,11 @@ function SimpleReasoning({
|
|
|
1751
1778
|
/* @__PURE__ */ jsxRuntime.jsx(ReasoningContent, { markdown, children: content })
|
|
1752
1779
|
] });
|
|
1753
1780
|
}
|
|
1754
|
-
var CopilotUIContext =
|
|
1781
|
+
var CopilotUIContext = React19__namespace.createContext(
|
|
1755
1782
|
null
|
|
1756
1783
|
);
|
|
1757
1784
|
function useCopilotUI() {
|
|
1758
|
-
const context =
|
|
1785
|
+
const context = React19__namespace.useContext(CopilotUIContext);
|
|
1759
1786
|
if (!context) {
|
|
1760
1787
|
return {
|
|
1761
1788
|
debug: false,
|
|
@@ -1770,7 +1797,7 @@ function CopilotUIProvider({
|
|
|
1770
1797
|
debug = false,
|
|
1771
1798
|
defaultDebugExpanded = false
|
|
1772
1799
|
}) {
|
|
1773
|
-
const value =
|
|
1800
|
+
const value = React19__namespace.useMemo(
|
|
1774
1801
|
() => ({
|
|
1775
1802
|
debug,
|
|
1776
1803
|
defaultDebugExpanded,
|
|
@@ -1913,7 +1940,7 @@ function ToolStep({
|
|
|
1913
1940
|
}) {
|
|
1914
1941
|
const { isDebug, defaultDebugExpanded } = useCopilotUI();
|
|
1915
1942
|
const debug = debugProp ?? isDebug;
|
|
1916
|
-
const [expanded, setExpanded] =
|
|
1943
|
+
const [expanded, setExpanded] = React19__namespace.useState(
|
|
1917
1944
|
defaultExpanded ?? defaultDebugExpanded ?? false
|
|
1918
1945
|
);
|
|
1919
1946
|
const displayTitle = getDisplayTitle(step);
|
|
@@ -2394,9 +2421,9 @@ function ArrowUpRightIcon({ className }) {
|
|
|
2394
2421
|
}
|
|
2395
2422
|
);
|
|
2396
2423
|
}
|
|
2397
|
-
var ConfirmationContext =
|
|
2424
|
+
var ConfirmationContext = React19__namespace.createContext(null);
|
|
2398
2425
|
function useConfirmationContext() {
|
|
2399
|
-
const context =
|
|
2426
|
+
const context = React19__namespace.useContext(ConfirmationContext);
|
|
2400
2427
|
if (!context) {
|
|
2401
2428
|
throw new Error(
|
|
2402
2429
|
"Confirmation components must be used within a Confirmation provider"
|
|
@@ -2880,8 +2907,8 @@ function DevLogger({
|
|
|
2880
2907
|
position = "bottom-right",
|
|
2881
2908
|
className
|
|
2882
2909
|
}) {
|
|
2883
|
-
const [isOpen, setIsOpen] =
|
|
2884
|
-
const [activeTab, setActiveTab] =
|
|
2910
|
+
const [isOpen, setIsOpen] = React19.useState(false);
|
|
2911
|
+
const [activeTab, setActiveTab] = React19.useState("chat");
|
|
2885
2912
|
const positionClasses = {
|
|
2886
2913
|
"bottom-left": "bottom-4 left-4",
|
|
2887
2914
|
"bottom-right": "bottom-4 right-4",
|
|
@@ -3306,9 +3333,9 @@ function ModelSelector({
|
|
|
3306
3333
|
showCapabilities = true,
|
|
3307
3334
|
className
|
|
3308
3335
|
}) {
|
|
3309
|
-
const [isOpen, setIsOpen] =
|
|
3310
|
-
const containerRef =
|
|
3311
|
-
|
|
3336
|
+
const [isOpen, setIsOpen] = React19__namespace.useState(false);
|
|
3337
|
+
const containerRef = React19__namespace.useRef(null);
|
|
3338
|
+
React19__namespace.useEffect(() => {
|
|
3312
3339
|
function handleClickOutside(event) {
|
|
3313
3340
|
if (containerRef.current && !containerRef.current.contains(event.target)) {
|
|
3314
3341
|
setIsOpen(false);
|
|
@@ -3317,7 +3344,7 @@ function ModelSelector({
|
|
|
3317
3344
|
document.addEventListener("mousedown", handleClickOutside);
|
|
3318
3345
|
return () => document.removeEventListener("mousedown", handleClickOutside);
|
|
3319
3346
|
}, []);
|
|
3320
|
-
const selectedModel =
|
|
3347
|
+
const selectedModel = React19__namespace.useMemo(() => {
|
|
3321
3348
|
if (!value) return null;
|
|
3322
3349
|
if (providers) {
|
|
3323
3350
|
for (const provider of providers) {
|
|
@@ -3543,7 +3570,7 @@ function PopoverTrigger({
|
|
|
3543
3570
|
className,
|
|
3544
3571
|
...props
|
|
3545
3572
|
}) {
|
|
3546
|
-
if (asChild &&
|
|
3573
|
+
if (asChild && React19__namespace.isValidElement(children)) {
|
|
3547
3574
|
return /* @__PURE__ */ jsxRuntime.jsx(popover.Popover.Trigger, { render: children, className, ...props });
|
|
3548
3575
|
}
|
|
3549
3576
|
return /* @__PURE__ */ jsxRuntime.jsx(popover.Popover.Trigger, { className, ...props, children });
|
|
@@ -3678,8 +3705,8 @@ function ThreadPicker({
|
|
|
3678
3705
|
itemClassName,
|
|
3679
3706
|
newButtonClassName
|
|
3680
3707
|
}) {
|
|
3681
|
-
const [isOpen, setIsOpen] =
|
|
3682
|
-
const selectedThread =
|
|
3708
|
+
const [isOpen, setIsOpen] = React19__namespace.useState(false);
|
|
3709
|
+
const selectedThread = React19__namespace.useMemo(() => {
|
|
3683
3710
|
if (!value) return null;
|
|
3684
3711
|
return threads.find((t) => t.id === value) ?? null;
|
|
3685
3712
|
}, [value, threads]);
|
|
@@ -3885,7 +3912,7 @@ function ThreadCard({
|
|
|
3885
3912
|
showDelete = true,
|
|
3886
3913
|
className
|
|
3887
3914
|
}) {
|
|
3888
|
-
const [isHovered, setIsHovered] =
|
|
3915
|
+
const [isHovered, setIsHovered] = React19__namespace.useState(false);
|
|
3889
3916
|
const handleDelete = (e) => {
|
|
3890
3917
|
e.stopPropagation();
|
|
3891
3918
|
onDelete?.();
|
|
@@ -4126,10 +4153,10 @@ function MCPUIFrame({
|
|
|
4126
4153
|
showLoading = true,
|
|
4127
4154
|
testId
|
|
4128
4155
|
}) {
|
|
4129
|
-
const iframeRef =
|
|
4130
|
-
const [isLoading, setIsLoading] =
|
|
4131
|
-
const [error, setError] =
|
|
4132
|
-
|
|
4156
|
+
const iframeRef = React19__namespace.useRef(null);
|
|
4157
|
+
const [isLoading, setIsLoading] = React19__namespace.useState(true);
|
|
4158
|
+
const [error, setError] = React19__namespace.useState(null);
|
|
4159
|
+
React19__namespace.useEffect(() => {
|
|
4133
4160
|
const handleMessage = (event) => {
|
|
4134
4161
|
if (event.source !== iframeRef.current?.contentWindow) {
|
|
4135
4162
|
return;
|
|
@@ -4142,17 +4169,17 @@ function MCPUIFrame({
|
|
|
4142
4169
|
window.addEventListener("message", handleMessage);
|
|
4143
4170
|
return () => window.removeEventListener("message", handleMessage);
|
|
4144
4171
|
}, [onIntent]);
|
|
4145
|
-
const handleLoad =
|
|
4172
|
+
const handleLoad = React19__namespace.useCallback(() => {
|
|
4146
4173
|
setIsLoading(false);
|
|
4147
4174
|
onLoad?.();
|
|
4148
4175
|
}, [onLoad]);
|
|
4149
|
-
const handleError =
|
|
4176
|
+
const handleError = React19__namespace.useCallback(() => {
|
|
4150
4177
|
const err = new Error("Failed to load MCP UI content");
|
|
4151
4178
|
setError(err);
|
|
4152
4179
|
setIsLoading(false);
|
|
4153
4180
|
onError?.(err);
|
|
4154
4181
|
}, [onError]);
|
|
4155
|
-
const { srcDoc, src } =
|
|
4182
|
+
const { srcDoc, src } = React19__namespace.useMemo(() => {
|
|
4156
4183
|
if (resource.mimeType === "text/html") {
|
|
4157
4184
|
let content = resource.content || "";
|
|
4158
4185
|
if (resource.blob && !resource.content) {
|
|
@@ -4302,6 +4329,284 @@ function MCPUIFrameList({
|
|
|
4302
4329
|
`${resource.uri}-${index}`
|
|
4303
4330
|
)) });
|
|
4304
4331
|
}
|
|
4332
|
+
var MessageActionsContext = React19.createContext(
|
|
4333
|
+
null
|
|
4334
|
+
);
|
|
4335
|
+
function MessageActionsProvider({
|
|
4336
|
+
children
|
|
4337
|
+
}) {
|
|
4338
|
+
const [registry, setRegistry] = React19.useState(
|
|
4339
|
+
{}
|
|
4340
|
+
);
|
|
4341
|
+
const registerActions = React19.useCallback(
|
|
4342
|
+
(role, actions) => {
|
|
4343
|
+
setRegistry((prev) => ({ ...prev, [role]: actions }));
|
|
4344
|
+
},
|
|
4345
|
+
[]
|
|
4346
|
+
);
|
|
4347
|
+
const clearActions = React19.useCallback((role) => {
|
|
4348
|
+
setRegistry((prev) => {
|
|
4349
|
+
const next = { ...prev };
|
|
4350
|
+
delete next[role];
|
|
4351
|
+
return next;
|
|
4352
|
+
});
|
|
4353
|
+
}, []);
|
|
4354
|
+
const getActions = React19.useCallback(
|
|
4355
|
+
(role) => registry[role] ?? [],
|
|
4356
|
+
[registry]
|
|
4357
|
+
);
|
|
4358
|
+
return /* @__PURE__ */ jsxRuntime.jsx(
|
|
4359
|
+
MessageActionsContext.Provider,
|
|
4360
|
+
{
|
|
4361
|
+
value: { getActions, registerActions, clearActions },
|
|
4362
|
+
children
|
|
4363
|
+
}
|
|
4364
|
+
);
|
|
4365
|
+
}
|
|
4366
|
+
function useMessageActionsContext() {
|
|
4367
|
+
return React19.useContext(MessageActionsContext);
|
|
4368
|
+
}
|
|
4369
|
+
React19.createContext(null);
|
|
4370
|
+
function CopyIcon2() {
|
|
4371
|
+
return /* @__PURE__ */ jsxRuntime.jsxs(
|
|
4372
|
+
"svg",
|
|
4373
|
+
{
|
|
4374
|
+
width: "13",
|
|
4375
|
+
height: "13",
|
|
4376
|
+
viewBox: "0 0 24 24",
|
|
4377
|
+
fill: "none",
|
|
4378
|
+
stroke: "currentColor",
|
|
4379
|
+
strokeWidth: 2,
|
|
4380
|
+
strokeLinecap: "round",
|
|
4381
|
+
strokeLinejoin: "round",
|
|
4382
|
+
children: [
|
|
4383
|
+
/* @__PURE__ */ jsxRuntime.jsx("rect", { x: "9", y: "9", width: "13", height: "13", rx: "2", ry: "2" }),
|
|
4384
|
+
/* @__PURE__ */ jsxRuntime.jsx("path", { d: "M5 15H4a2 2 0 0 1-2-2V4a2 2 0 0 1 2-2h9a2 2 0 0 1 2 2v1" })
|
|
4385
|
+
]
|
|
4386
|
+
}
|
|
4387
|
+
);
|
|
4388
|
+
}
|
|
4389
|
+
function CheckIcon3() {
|
|
4390
|
+
return /* @__PURE__ */ jsxRuntime.jsx(
|
|
4391
|
+
"svg",
|
|
4392
|
+
{
|
|
4393
|
+
width: "13",
|
|
4394
|
+
height: "13",
|
|
4395
|
+
viewBox: "0 0 24 24",
|
|
4396
|
+
fill: "none",
|
|
4397
|
+
stroke: "currentColor",
|
|
4398
|
+
strokeWidth: 2.5,
|
|
4399
|
+
strokeLinecap: "round",
|
|
4400
|
+
strokeLinejoin: "round",
|
|
4401
|
+
children: /* @__PURE__ */ jsxRuntime.jsx("path", { d: "M20 6L9 17l-5-5" })
|
|
4402
|
+
}
|
|
4403
|
+
);
|
|
4404
|
+
}
|
|
4405
|
+
function EditIcon() {
|
|
4406
|
+
return /* @__PURE__ */ jsxRuntime.jsxs(
|
|
4407
|
+
"svg",
|
|
4408
|
+
{
|
|
4409
|
+
width: "12",
|
|
4410
|
+
height: "12",
|
|
4411
|
+
viewBox: "0 0 24 24",
|
|
4412
|
+
fill: "none",
|
|
4413
|
+
stroke: "currentColor",
|
|
4414
|
+
strokeWidth: 2,
|
|
4415
|
+
strokeLinecap: "round",
|
|
4416
|
+
strokeLinejoin: "round",
|
|
4417
|
+
children: [
|
|
4418
|
+
/* @__PURE__ */ jsxRuntime.jsx("path", { d: "M11 4H4a2 2 0 0 0-2 2v14a2 2 0 0 0 2 2h14a2 2 0 0 0 2-2v-7" }),
|
|
4419
|
+
/* @__PURE__ */ jsxRuntime.jsx("path", { d: "M18.5 2.5a2.121 2.121 0 0 1 3 3L12 15l-4 1 1-4 9.5-9.5z" })
|
|
4420
|
+
]
|
|
4421
|
+
}
|
|
4422
|
+
);
|
|
4423
|
+
}
|
|
4424
|
+
function ThumbsUpIcon3() {
|
|
4425
|
+
return /* @__PURE__ */ jsxRuntime.jsxs(
|
|
4426
|
+
"svg",
|
|
4427
|
+
{
|
|
4428
|
+
width: "13",
|
|
4429
|
+
height: "13",
|
|
4430
|
+
viewBox: "0 0 24 24",
|
|
4431
|
+
fill: "none",
|
|
4432
|
+
stroke: "currentColor",
|
|
4433
|
+
strokeWidth: 2,
|
|
4434
|
+
strokeLinecap: "round",
|
|
4435
|
+
strokeLinejoin: "round",
|
|
4436
|
+
children: [
|
|
4437
|
+
/* @__PURE__ */ jsxRuntime.jsx("path", { d: "M7 10v12" }),
|
|
4438
|
+
/* @__PURE__ */ jsxRuntime.jsx("path", { d: "M15 5.88 14 10h5.83a2 2 0 0 1 1.92 2.56l-2.33 8A2 2 0 0 1 17.5 22H4a2 2 0 0 1-2-2v-8a2 2 0 0 1 2-2h2.76a2 2 0 0 0 1.79-1.11L12 2a3.13 3.13 0 0 1 3 3.88Z" })
|
|
4439
|
+
]
|
|
4440
|
+
}
|
|
4441
|
+
);
|
|
4442
|
+
}
|
|
4443
|
+
function ThumbsDownIcon3() {
|
|
4444
|
+
return /* @__PURE__ */ jsxRuntime.jsxs(
|
|
4445
|
+
"svg",
|
|
4446
|
+
{
|
|
4447
|
+
width: "13",
|
|
4448
|
+
height: "13",
|
|
4449
|
+
viewBox: "0 0 24 24",
|
|
4450
|
+
fill: "none",
|
|
4451
|
+
stroke: "currentColor",
|
|
4452
|
+
strokeWidth: 2,
|
|
4453
|
+
strokeLinecap: "round",
|
|
4454
|
+
strokeLinejoin: "round",
|
|
4455
|
+
children: [
|
|
4456
|
+
/* @__PURE__ */ jsxRuntime.jsx("path", { d: "M17 14V2" }),
|
|
4457
|
+
/* @__PURE__ */ jsxRuntime.jsx("path", { d: "M9 18.12 10 14H4.17a2 2 0 0 1-1.92-2.56l2.33-8A2 2 0 0 1 6.5 2H20a2 2 0 0 1 2 2v8a2 2 0 0 1-2 2h-2.76a2 2 0 0 0-1.79 1.11L12 22a3.13 3.13 0 0 1-3-3.88Z" })
|
|
4458
|
+
]
|
|
4459
|
+
}
|
|
4460
|
+
);
|
|
4461
|
+
}
|
|
4462
|
+
function CopyAction({ tooltip = "Copy", className }) {
|
|
4463
|
+
return null;
|
|
4464
|
+
}
|
|
4465
|
+
CopyAction.displayName = "CopyAction";
|
|
4466
|
+
function EditAction({ tooltip = "Edit", className }) {
|
|
4467
|
+
return null;
|
|
4468
|
+
}
|
|
4469
|
+
EditAction.displayName = "EditAction";
|
|
4470
|
+
function FeedbackAction({
|
|
4471
|
+
onFeedback,
|
|
4472
|
+
tooltip = "Feedback",
|
|
4473
|
+
className
|
|
4474
|
+
}) {
|
|
4475
|
+
return null;
|
|
4476
|
+
}
|
|
4477
|
+
FeedbackAction.displayName = "FeedbackAction";
|
|
4478
|
+
function Action({
|
|
4479
|
+
icon,
|
|
4480
|
+
tooltip,
|
|
4481
|
+
onClick,
|
|
4482
|
+
hidden,
|
|
4483
|
+
className
|
|
4484
|
+
}) {
|
|
4485
|
+
return null;
|
|
4486
|
+
}
|
|
4487
|
+
Action.displayName = "Action";
|
|
4488
|
+
function MessageActions2({ role, children }) {
|
|
4489
|
+
const ctx = useMessageActionsContext();
|
|
4490
|
+
const actions = React19.useMemo(() => {
|
|
4491
|
+
const result = [];
|
|
4492
|
+
React19__namespace.default.Children.forEach(children, (child) => {
|
|
4493
|
+
if (!React19__namespace.default.isValidElement(child)) return;
|
|
4494
|
+
const props = child.props;
|
|
4495
|
+
const type = child.type;
|
|
4496
|
+
if (type === CopyAction || child.type?.displayName === "CopyAction") {
|
|
4497
|
+
result.push({
|
|
4498
|
+
id: "copy",
|
|
4499
|
+
icon: /* @__PURE__ */ jsxRuntime.jsx(CopyIcon2, {}),
|
|
4500
|
+
tooltip: props.tooltip ?? "Copy",
|
|
4501
|
+
onClick: ({ message }) => {
|
|
4502
|
+
navigator.clipboard.writeText(message.content ?? "");
|
|
4503
|
+
},
|
|
4504
|
+
className: props.className
|
|
4505
|
+
});
|
|
4506
|
+
} else if (type === EditAction || child.type?.displayName === "EditAction") {
|
|
4507
|
+
result.push({
|
|
4508
|
+
id: "edit",
|
|
4509
|
+
icon: /* @__PURE__ */ jsxRuntime.jsx(EditIcon, {}),
|
|
4510
|
+
tooltip: props.tooltip ?? "Edit",
|
|
4511
|
+
onClick: () => {
|
|
4512
|
+
},
|
|
4513
|
+
// handled internally by DefaultMessage via onEditMessage
|
|
4514
|
+
className: props.className
|
|
4515
|
+
});
|
|
4516
|
+
} else if (type === FeedbackAction || child.type?.displayName === "FeedbackAction") {
|
|
4517
|
+
const onFeedback = props.onFeedback;
|
|
4518
|
+
result.push(
|
|
4519
|
+
{
|
|
4520
|
+
id: "feedback-up",
|
|
4521
|
+
icon: /* @__PURE__ */ jsxRuntime.jsx(ThumbsUpIcon3, {}),
|
|
4522
|
+
tooltip: "Helpful",
|
|
4523
|
+
onClick: ({ message }) => onFeedback?.(message, "helpful"),
|
|
4524
|
+
className: props.className
|
|
4525
|
+
},
|
|
4526
|
+
{
|
|
4527
|
+
id: "feedback-down",
|
|
4528
|
+
icon: /* @__PURE__ */ jsxRuntime.jsx(ThumbsDownIcon3, {}),
|
|
4529
|
+
tooltip: "Not helpful",
|
|
4530
|
+
onClick: ({ message }) => onFeedback?.(message, "not-helpful"),
|
|
4531
|
+
className: props.className
|
|
4532
|
+
}
|
|
4533
|
+
);
|
|
4534
|
+
} else if (type === Action || child.type?.displayName === "Action") {
|
|
4535
|
+
result.push({
|
|
4536
|
+
id: props.id ?? props.tooltip,
|
|
4537
|
+
icon: props.icon,
|
|
4538
|
+
tooltip: props.tooltip,
|
|
4539
|
+
onClick: props.onClick,
|
|
4540
|
+
hidden: props.hidden,
|
|
4541
|
+
className: props.className
|
|
4542
|
+
});
|
|
4543
|
+
}
|
|
4544
|
+
});
|
|
4545
|
+
return result;
|
|
4546
|
+
}, [children]);
|
|
4547
|
+
React19.useLayoutEffect(() => {
|
|
4548
|
+
if (!ctx) return;
|
|
4549
|
+
ctx.registerActions(role, actions);
|
|
4550
|
+
return () => ctx.clearActions(role);
|
|
4551
|
+
}, [ctx, role, actions]);
|
|
4552
|
+
return null;
|
|
4553
|
+
}
|
|
4554
|
+
function FloatingActions({
|
|
4555
|
+
message,
|
|
4556
|
+
role,
|
|
4557
|
+
align = "left",
|
|
4558
|
+
onEdit
|
|
4559
|
+
}) {
|
|
4560
|
+
const ctx = useMessageActionsContext();
|
|
4561
|
+
const [copiedId, setCopiedId] = React19__namespace.useState(null);
|
|
4562
|
+
if (!ctx) return null;
|
|
4563
|
+
const actions = ctx.getActions(role);
|
|
4564
|
+
if (actions.length === 0) return null;
|
|
4565
|
+
return /* @__PURE__ */ jsxRuntime.jsx(
|
|
4566
|
+
"div",
|
|
4567
|
+
{
|
|
4568
|
+
className: cn(
|
|
4569
|
+
"flex items-center gap-0.5 mt-1",
|
|
4570
|
+
"opacity-0 group-hover/message:opacity-100 transition-opacity duration-150",
|
|
4571
|
+
align === "right" ? "justify-end" : "justify-start"
|
|
4572
|
+
),
|
|
4573
|
+
children: actions.map((action) => {
|
|
4574
|
+
const isHidden = typeof action.hidden === "function" ? action.hidden({ message }) : action.hidden;
|
|
4575
|
+
if (isHidden) return null;
|
|
4576
|
+
const isCopied = copiedId === action.id;
|
|
4577
|
+
return /* @__PURE__ */ jsxRuntime.jsx(
|
|
4578
|
+
"button",
|
|
4579
|
+
{
|
|
4580
|
+
type: "button",
|
|
4581
|
+
title: action.tooltip,
|
|
4582
|
+
"aria-label": action.tooltip,
|
|
4583
|
+
className: cn(
|
|
4584
|
+
"flex items-center justify-center size-6 rounded-md",
|
|
4585
|
+
"text-muted-foreground hover:text-foreground hover:bg-muted",
|
|
4586
|
+
"transition-colors",
|
|
4587
|
+
action.className
|
|
4588
|
+
),
|
|
4589
|
+
onClick: () => {
|
|
4590
|
+
if (action.id === "edit" && onEdit) {
|
|
4591
|
+
onEdit();
|
|
4592
|
+
return;
|
|
4593
|
+
}
|
|
4594
|
+
if (action.id === "copy") {
|
|
4595
|
+
navigator.clipboard.writeText(message.content ?? "");
|
|
4596
|
+
setCopiedId("copy");
|
|
4597
|
+
setTimeout(() => setCopiedId(null), 1500);
|
|
4598
|
+
return;
|
|
4599
|
+
}
|
|
4600
|
+
action.onClick({ message });
|
|
4601
|
+
},
|
|
4602
|
+
children: action.id === "copy" && isCopied ? /* @__PURE__ */ jsxRuntime.jsx(CheckIcon3, {}) : action.icon
|
|
4603
|
+
},
|
|
4604
|
+
action.id
|
|
4605
|
+
);
|
|
4606
|
+
})
|
|
4607
|
+
}
|
|
4608
|
+
);
|
|
4609
|
+
}
|
|
4305
4610
|
function DefaultMessage({
|
|
4306
4611
|
message,
|
|
4307
4612
|
userAvatar,
|
|
@@ -4332,24 +4637,24 @@ function DefaultMessage({
|
|
|
4332
4637
|
const isUser = message.role === "user";
|
|
4333
4638
|
const isCompactionMarker = message.role === "system" && message.metadata?.type === "compaction-marker";
|
|
4334
4639
|
const isStreaming = isLastMessage && isLoading;
|
|
4335
|
-
const [isEditing, setIsEditing] =
|
|
4336
|
-
const [editValue, setEditValue] =
|
|
4337
|
-
const editRef =
|
|
4338
|
-
const startEdit =
|
|
4640
|
+
const [isEditing, setIsEditing] = React19__namespace.useState(false);
|
|
4641
|
+
const [editValue, setEditValue] = React19__namespace.useState(message.content ?? "");
|
|
4642
|
+
const editRef = React19__namespace.useRef(null);
|
|
4643
|
+
const startEdit = React19__namespace.useCallback(() => {
|
|
4339
4644
|
setEditValue(message.content ?? "");
|
|
4340
4645
|
setIsEditing(true);
|
|
4341
4646
|
requestAnimationFrame(() => editRef.current?.focus());
|
|
4342
4647
|
}, [message.content]);
|
|
4343
|
-
const cancelEdit =
|
|
4648
|
+
const cancelEdit = React19__namespace.useCallback(() => {
|
|
4344
4649
|
setIsEditing(false);
|
|
4345
4650
|
}, []);
|
|
4346
|
-
const submitEdit =
|
|
4651
|
+
const submitEdit = React19__namespace.useCallback(() => {
|
|
4347
4652
|
const trimmed = editValue.trim();
|
|
4348
4653
|
if (!trimmed || !onEditMessage) return;
|
|
4349
4654
|
onEditMessage(message.id, trimmed);
|
|
4350
4655
|
setIsEditing(false);
|
|
4351
4656
|
}, [editValue, message.id, onEditMessage]);
|
|
4352
|
-
const handleEditKeyDown =
|
|
4657
|
+
const handleEditKeyDown = React19__namespace.useCallback(
|
|
4353
4658
|
(e) => {
|
|
4354
4659
|
if (e.key === "Enter" && !e.shiftKey) {
|
|
4355
4660
|
e.preventDefault();
|
|
@@ -4391,18 +4696,18 @@ function DefaultMessage({
|
|
|
4391
4696
|
/* @__PURE__ */ jsxRuntime.jsx("div", { className: "flex-1 h-px bg-border" })
|
|
4392
4697
|
] });
|
|
4393
4698
|
}
|
|
4394
|
-
const { cleanContent: contentWithoutFollowUps, followUps } =
|
|
4699
|
+
const { cleanContent: contentWithoutFollowUps, followUps } = React19__namespace.useMemo(() => {
|
|
4395
4700
|
if (isUser || !message.content) {
|
|
4396
4701
|
return { cleanContent: message.content, followUps: [] };
|
|
4397
4702
|
}
|
|
4398
4703
|
return parseFollowUps(message.content);
|
|
4399
4704
|
}, [message.content, isUser]);
|
|
4400
|
-
const cleanContent =
|
|
4705
|
+
const cleanContent = React19__namespace.useMemo(() => {
|
|
4401
4706
|
if (!contentWithoutFollowUps) return contentWithoutFollowUps;
|
|
4402
4707
|
return contentWithoutFollowUps.replace(/\n*\*{0,2}Sources:?\*{0,2}\s*(\[.+?\]\(.+?\)[,\s]*)+$/gi, "").trim();
|
|
4403
4708
|
}, [contentWithoutFollowUps]);
|
|
4404
4709
|
const shouldShowFollowUps = showFollowUps && !isUser && isLastMessage && !isLoading && followUps.length > 0 && onFollowUpClick;
|
|
4405
|
-
const sources =
|
|
4710
|
+
const sources = React19__namespace.useMemo(() => {
|
|
4406
4711
|
if (isUser || !citations.enabled) return [];
|
|
4407
4712
|
const extractedSources = [];
|
|
4408
4713
|
const addSource = (url, title, description) => {
|
|
@@ -4456,121 +4761,136 @@ function DefaultMessage({
|
|
|
4456
4761
|
const shouldShowSources = citations.enabled && sources.length > 0;
|
|
4457
4762
|
if (isUser) {
|
|
4458
4763
|
const hasAttachments = message.attachments && message.attachments.length > 0;
|
|
4459
|
-
return /* @__PURE__ */ jsxRuntime.jsxs(
|
|
4460
|
-
|
|
4461
|
-
|
|
4462
|
-
|
|
4463
|
-
|
|
4464
|
-
|
|
4465
|
-
|
|
4466
|
-
|
|
4467
|
-
|
|
4468
|
-
|
|
4469
|
-
|
|
4470
|
-
|
|
4471
|
-
|
|
4472
|
-
|
|
4473
|
-
|
|
4474
|
-
|
|
4475
|
-
|
|
4476
|
-
|
|
4477
|
-
|
|
4478
|
-
|
|
4479
|
-
|
|
4480
|
-
|
|
4481
|
-
|
|
4482
|
-
|
|
4483
|
-
|
|
4484
|
-
|
|
4485
|
-
|
|
4486
|
-
|
|
4487
|
-
|
|
4488
|
-
|
|
4489
|
-
|
|
4490
|
-
type: "button",
|
|
4491
|
-
onClick: submitEdit,
|
|
4492
|
-
disabled: !editValue.trim(),
|
|
4493
|
-
className: "csdk-edit-submit px-3 py-1 text-xs rounded-md bg-primary text-primary-foreground hover:bg-primary/90 disabled:opacity-50 transition-colors",
|
|
4494
|
-
children: "Send"
|
|
4495
|
-
}
|
|
4496
|
-
)
|
|
4497
|
-
] })
|
|
4498
|
-
] }) : /* @__PURE__ */ jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [
|
|
4499
|
-
message.content && /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "relative", children: [
|
|
4500
|
-
/* @__PURE__ */ jsxRuntime.jsx(
|
|
4501
|
-
MessageContent,
|
|
4502
|
-
{
|
|
4503
|
-
className: cn(
|
|
4504
|
-
"csdk-message-user rounded-lg px-4 py-2 bg-primary text-primary-foreground",
|
|
4505
|
-
userMessageClassName
|
|
4764
|
+
return /* @__PURE__ */ jsxRuntime.jsxs(
|
|
4765
|
+
Message,
|
|
4766
|
+
{
|
|
4767
|
+
className: cn("flex gap-2 group/user-msg group/message justify-end"),
|
|
4768
|
+
children: [
|
|
4769
|
+
/* @__PURE__ */ jsxRuntime.jsx("div", { className: "flex flex-col items-end max-w-[80%] min-w-0", children: isEditing ? /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col gap-1.5 w-full min-w-[200px]", children: [
|
|
4770
|
+
/* @__PURE__ */ jsxRuntime.jsx(
|
|
4771
|
+
"textarea",
|
|
4772
|
+
{
|
|
4773
|
+
ref: editRef,
|
|
4774
|
+
value: editValue,
|
|
4775
|
+
onChange: (e) => setEditValue(e.target.value),
|
|
4776
|
+
onKeyDown: handleEditKeyDown,
|
|
4777
|
+
rows: Math.max(2, (editValue.match(/\n/g) || []).length + 1),
|
|
4778
|
+
className: cn(
|
|
4779
|
+
"csdk-edit-textarea w-full rounded-lg px-3 py-2 text-sm resize-none",
|
|
4780
|
+
"bg-primary text-primary-foreground placeholder:text-primary-foreground/50",
|
|
4781
|
+
"focus:outline-none focus:ring-2 focus:ring-primary-foreground/30",
|
|
4782
|
+
userMessageClassName
|
|
4783
|
+
)
|
|
4784
|
+
}
|
|
4785
|
+
),
|
|
4786
|
+
/* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex gap-1.5 justify-end", children: [
|
|
4787
|
+
/* @__PURE__ */ jsxRuntime.jsx(
|
|
4788
|
+
"button",
|
|
4789
|
+
{
|
|
4790
|
+
type: "button",
|
|
4791
|
+
onClick: cancelEdit,
|
|
4792
|
+
className: "csdk-edit-cancel px-3 py-1 text-xs rounded-md bg-muted text-muted-foreground hover:bg-muted/80 transition-colors",
|
|
4793
|
+
children: "Cancel"
|
|
4794
|
+
}
|
|
4506
4795
|
),
|
|
4507
|
-
|
|
4508
|
-
|
|
4509
|
-
|
|
4510
|
-
|
|
4511
|
-
|
|
4512
|
-
|
|
4513
|
-
|
|
4514
|
-
|
|
4515
|
-
|
|
4516
|
-
|
|
4517
|
-
|
|
4518
|
-
|
|
4519
|
-
|
|
4520
|
-
|
|
4521
|
-
|
|
4522
|
-
|
|
4523
|
-
|
|
4796
|
+
/* @__PURE__ */ jsxRuntime.jsx(
|
|
4797
|
+
"button",
|
|
4798
|
+
{
|
|
4799
|
+
type: "button",
|
|
4800
|
+
onClick: submitEdit,
|
|
4801
|
+
disabled: !editValue.trim(),
|
|
4802
|
+
className: "csdk-edit-submit px-3 py-1 text-xs rounded-md bg-primary text-primary-foreground hover:bg-primary/90 disabled:opacity-50 transition-colors",
|
|
4803
|
+
children: "Send"
|
|
4804
|
+
}
|
|
4805
|
+
)
|
|
4806
|
+
] })
|
|
4807
|
+
] }) : /* @__PURE__ */ jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [
|
|
4808
|
+
message.content && /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "relative", children: [
|
|
4809
|
+
/* @__PURE__ */ jsxRuntime.jsx(
|
|
4810
|
+
MessageContent,
|
|
4811
|
+
{
|
|
4812
|
+
className: cn(
|
|
4813
|
+
"csdk-message-user rounded-lg px-4 py-2 bg-primary text-primary-foreground",
|
|
4814
|
+
userMessageClassName
|
|
4815
|
+
),
|
|
4816
|
+
markdown: true,
|
|
4817
|
+
size,
|
|
4818
|
+
children: message.content
|
|
4819
|
+
}
|
|
4524
4820
|
),
|
|
4525
|
-
|
|
4526
|
-
"
|
|
4821
|
+
showEditBtn && /* @__PURE__ */ jsxRuntime.jsx(
|
|
4822
|
+
"button",
|
|
4527
4823
|
{
|
|
4528
|
-
|
|
4529
|
-
|
|
4530
|
-
|
|
4531
|
-
|
|
4532
|
-
|
|
4533
|
-
|
|
4534
|
-
|
|
4535
|
-
|
|
4536
|
-
|
|
4537
|
-
|
|
4538
|
-
|
|
4539
|
-
|
|
4824
|
+
type: "button",
|
|
4825
|
+
onClick: startEdit,
|
|
4826
|
+
"aria-label": "Edit message",
|
|
4827
|
+
className: cn(
|
|
4828
|
+
"csdk-edit-btn absolute -left-7 top-1/2 -translate-y-1/2",
|
|
4829
|
+
"size-6 flex items-center justify-center rounded-full",
|
|
4830
|
+
"text-muted-foreground bg-background border border-border shadow-sm",
|
|
4831
|
+
"opacity-0 group-hover/user-msg:opacity-100 transition-opacity",
|
|
4832
|
+
"hover:text-foreground hover:bg-muted"
|
|
4833
|
+
),
|
|
4834
|
+
children: /* @__PURE__ */ jsxRuntime.jsxs(
|
|
4835
|
+
"svg",
|
|
4836
|
+
{
|
|
4837
|
+
width: "12",
|
|
4838
|
+
height: "12",
|
|
4839
|
+
viewBox: "0 0 24 24",
|
|
4840
|
+
fill: "none",
|
|
4841
|
+
stroke: "currentColor",
|
|
4842
|
+
strokeWidth: 2,
|
|
4843
|
+
strokeLinecap: "round",
|
|
4844
|
+
strokeLinejoin: "round",
|
|
4845
|
+
children: [
|
|
4846
|
+
/* @__PURE__ */ jsxRuntime.jsx("path", { d: "M11 4H4a2 2 0 0 0-2 2v14a2 2 0 0 0 2 2h14a2 2 0 0 0 2-2v-7" }),
|
|
4847
|
+
/* @__PURE__ */ jsxRuntime.jsx("path", { d: "M18.5 2.5a2.121 2.121 0 0 1 3 3L12 15l-4 1 1-4 9.5-9.5z" })
|
|
4848
|
+
]
|
|
4849
|
+
}
|
|
4850
|
+
)
|
|
4540
4851
|
}
|
|
4541
4852
|
)
|
|
4853
|
+
] }),
|
|
4854
|
+
hasAttachments && /* @__PURE__ */ jsxRuntime.jsx("div", { className: "mt-2 flex flex-wrap gap-2 justify-end", children: message.attachments.map((attachment, index) => /* @__PURE__ */ jsxRuntime.jsx(AttachmentPreview, { attachment }, index)) }),
|
|
4855
|
+
showBranchNav && /* @__PURE__ */ jsxRuntime.jsx(
|
|
4856
|
+
BranchNavigator,
|
|
4857
|
+
{
|
|
4858
|
+
siblingIndex: branchInfo.siblingIndex,
|
|
4859
|
+
totalSiblings: branchInfo.totalSiblings,
|
|
4860
|
+
hasPrevious: branchInfo.hasPrevious,
|
|
4861
|
+
hasNext: branchInfo.hasNext,
|
|
4862
|
+
onPrevious: () => onSwitchBranch(
|
|
4863
|
+
branchInfo.siblingIds[branchInfo.siblingIndex - 1]
|
|
4864
|
+
),
|
|
4865
|
+
onNext: () => onSwitchBranch(
|
|
4866
|
+
branchInfo.siblingIds[branchInfo.siblingIndex + 1]
|
|
4867
|
+
),
|
|
4868
|
+
className: "mt-1"
|
|
4869
|
+
}
|
|
4870
|
+
),
|
|
4871
|
+
/* @__PURE__ */ jsxRuntime.jsx(
|
|
4872
|
+
FloatingActions,
|
|
4873
|
+
{
|
|
4874
|
+
message,
|
|
4875
|
+
role: "user",
|
|
4876
|
+
align: "right",
|
|
4877
|
+
onEdit: onEditMessage ? startEdit : void 0
|
|
4878
|
+
}
|
|
4879
|
+
)
|
|
4880
|
+
] }) }),
|
|
4881
|
+
showUserAvatar && /* @__PURE__ */ jsxRuntime.jsx(
|
|
4882
|
+
MessageAvatar,
|
|
4883
|
+
{
|
|
4884
|
+
src: userAvatar.src,
|
|
4885
|
+
alt: "User",
|
|
4886
|
+
fallback: userAvatar.fallback,
|
|
4887
|
+
className: userAvatar.className,
|
|
4888
|
+
children: userAvatar.component
|
|
4542
4889
|
}
|
|
4543
4890
|
)
|
|
4544
|
-
]
|
|
4545
|
-
|
|
4546
|
-
|
|
4547
|
-
BranchNavigator,
|
|
4548
|
-
{
|
|
4549
|
-
siblingIndex: branchInfo.siblingIndex,
|
|
4550
|
-
totalSiblings: branchInfo.totalSiblings,
|
|
4551
|
-
hasPrevious: branchInfo.hasPrevious,
|
|
4552
|
-
hasNext: branchInfo.hasNext,
|
|
4553
|
-
onPrevious: () => onSwitchBranch(
|
|
4554
|
-
branchInfo.siblingIds[branchInfo.siblingIndex - 1]
|
|
4555
|
-
),
|
|
4556
|
-
onNext: () => onSwitchBranch(
|
|
4557
|
-
branchInfo.siblingIds[branchInfo.siblingIndex + 1]
|
|
4558
|
-
),
|
|
4559
|
-
className: "mt-1"
|
|
4560
|
-
}
|
|
4561
|
-
)
|
|
4562
|
-
] }) }),
|
|
4563
|
-
showUserAvatar && /* @__PURE__ */ jsxRuntime.jsx(
|
|
4564
|
-
MessageAvatar,
|
|
4565
|
-
{
|
|
4566
|
-
src: userAvatar.src,
|
|
4567
|
-
alt: "User",
|
|
4568
|
-
fallback: userAvatar.fallback,
|
|
4569
|
-
className: userAvatar.className,
|
|
4570
|
-
children: userAvatar.component
|
|
4571
|
-
}
|
|
4572
|
-
)
|
|
4573
|
-
] });
|
|
4891
|
+
]
|
|
4892
|
+
}
|
|
4893
|
+
);
|
|
4574
4894
|
}
|
|
4575
4895
|
const isToolHidden = (exec) => {
|
|
4576
4896
|
if (exec.hidden === true) return true;
|
|
@@ -4607,7 +4927,7 @@ function DefaultMessage({
|
|
|
4607
4927
|
result: exec.result,
|
|
4608
4928
|
error: exec.error
|
|
4609
4929
|
}));
|
|
4610
|
-
return /* @__PURE__ */ jsxRuntime.jsxs(Message, { className: "flex gap-2", children: [
|
|
4930
|
+
return /* @__PURE__ */ jsxRuntime.jsxs(Message, { className: "flex gap-2 group/message", children: [
|
|
4611
4931
|
/* @__PURE__ */ jsxRuntime.jsx(
|
|
4612
4932
|
MessageAvatar,
|
|
4613
4933
|
{
|
|
@@ -4665,7 +4985,7 @@ function DefaultMessage({
|
|
|
4665
4985
|
renderProps
|
|
4666
4986
|
);
|
|
4667
4987
|
if (output != null) {
|
|
4668
|
-
return /* @__PURE__ */ jsxRuntime.jsx(
|
|
4988
|
+
return /* @__PURE__ */ jsxRuntime.jsx(React19__namespace.Fragment, { children: output }, exec.id);
|
|
4669
4989
|
}
|
|
4670
4990
|
}
|
|
4671
4991
|
if (mcpToolRenderer && (exec.source === "mcp" || toolDef?.source === "mcp")) {
|
|
@@ -4781,7 +5101,7 @@ function DefaultMessage({
|
|
|
4781
5101
|
const output = toolDef.render(
|
|
4782
5102
|
renderProps
|
|
4783
5103
|
);
|
|
4784
|
-
return /* @__PURE__ */ jsxRuntime.jsx(
|
|
5104
|
+
return /* @__PURE__ */ jsxRuntime.jsx(React19__namespace.Fragment, { children: output }, tool.id);
|
|
4785
5105
|
}
|
|
4786
5106
|
return /* @__PURE__ */ jsxRuntime.jsx(
|
|
4787
5107
|
PermissionConfirmation,
|
|
@@ -4823,14 +5143,15 @@ function DefaultMessage({
|
|
|
4823
5143
|
className: followUpClassName,
|
|
4824
5144
|
buttonClassName: followUpButtonClassName
|
|
4825
5145
|
}
|
|
4826
|
-
)
|
|
5146
|
+
),
|
|
5147
|
+
/* @__PURE__ */ jsxRuntime.jsx(FloatingActions, { message, role: "assistant", align: "left" })
|
|
4827
5148
|
] })
|
|
4828
5149
|
)
|
|
4829
5150
|
] })
|
|
4830
5151
|
] });
|
|
4831
5152
|
}
|
|
4832
5153
|
function AttachmentPreview({ attachment }) {
|
|
4833
|
-
const [expanded, setExpanded] =
|
|
5154
|
+
const [expanded, setExpanded] = React19__namespace.useState(false);
|
|
4834
5155
|
if (attachment.type !== "image") {
|
|
4835
5156
|
return /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center gap-2 rounded-lg border bg-muted/50 px-3 py-2 text-sm", children: [
|
|
4836
5157
|
/* @__PURE__ */ jsxRuntime.jsx("span", { className: "text-muted-foreground", children: attachment.type }),
|
|
@@ -4959,10 +5280,10 @@ function ChatWelcome({
|
|
|
4959
5280
|
processAttachment: processAttachmentProp,
|
|
4960
5281
|
classNames = {}
|
|
4961
5282
|
}) {
|
|
4962
|
-
const [input, setInput] =
|
|
4963
|
-
const [pendingAttachments, setPendingAttachments] =
|
|
4964
|
-
const fileInputRef =
|
|
4965
|
-
const fileInputId =
|
|
5283
|
+
const [input, setInput] = React19.useState("");
|
|
5284
|
+
const [pendingAttachments, setPendingAttachments] = React19.useState([]);
|
|
5285
|
+
const fileInputRef = React19.useRef(null);
|
|
5286
|
+
const fileInputId = React19.useId();
|
|
4966
5287
|
const title = config?.title ?? DEFAULT_TITLE;
|
|
4967
5288
|
const subtitle = config?.subtitle ?? DEFAULT_SUBTITLE;
|
|
4968
5289
|
const logo = config?.logo;
|
|
@@ -4971,7 +5292,7 @@ function ChatWelcome({
|
|
|
4971
5292
|
config?.recentChatsLabel ?? DEFAULT_RECENT_CHATS_LABEL;
|
|
4972
5293
|
const maxRecentChats = config?.maxRecentChats ?? DEFAULT_MAX_RECENT_CHATS;
|
|
4973
5294
|
config?.viewMoreLabel ?? DEFAULT_VIEW_MORE_LABEL;
|
|
4974
|
-
const isFileTypeAllowed =
|
|
5295
|
+
const isFileTypeAllowed = React19.useCallback(
|
|
4975
5296
|
(file) => {
|
|
4976
5297
|
for (const type of allowedFileTypes) {
|
|
4977
5298
|
if (type.endsWith("/*")) {
|
|
@@ -4985,7 +5306,7 @@ function ChatWelcome({
|
|
|
4985
5306
|
},
|
|
4986
5307
|
[allowedFileTypes]
|
|
4987
5308
|
);
|
|
4988
|
-
const handleFileSelect =
|
|
5309
|
+
const handleFileSelect = React19.useCallback(
|
|
4989
5310
|
async (files) => {
|
|
4990
5311
|
if (!files || !attachmentsEnabled) return;
|
|
4991
5312
|
for (const file of Array.from(files)) {
|
|
@@ -5048,7 +5369,7 @@ function ChatWelcome({
|
|
|
5048
5369
|
},
|
|
5049
5370
|
[attachmentsEnabled, maxFileSize, isFileTypeAllowed, processAttachmentProp]
|
|
5050
5371
|
);
|
|
5051
|
-
const handleInputChange =
|
|
5372
|
+
const handleInputChange = React19.useCallback(
|
|
5052
5373
|
(e) => {
|
|
5053
5374
|
handleFileSelect(e.target.files);
|
|
5054
5375
|
if (fileInputRef.current) {
|
|
@@ -5057,7 +5378,7 @@ function ChatWelcome({
|
|
|
5057
5378
|
},
|
|
5058
5379
|
[handleFileSelect]
|
|
5059
5380
|
);
|
|
5060
|
-
const removePendingAttachment =
|
|
5381
|
+
const removePendingAttachment = React19.useCallback((id) => {
|
|
5061
5382
|
setPendingAttachments((prev) => {
|
|
5062
5383
|
const att = prev.find((a) => a.id === id);
|
|
5063
5384
|
if (att) {
|
|
@@ -5066,7 +5387,7 @@ function ChatWelcome({
|
|
|
5066
5387
|
return prev.filter((a) => a.id !== id);
|
|
5067
5388
|
});
|
|
5068
5389
|
}, []);
|
|
5069
|
-
const handleSubmit =
|
|
5390
|
+
const handleSubmit = React19.useCallback(() => {
|
|
5070
5391
|
const hasContent = input.trim();
|
|
5071
5392
|
const hasAttachments = pendingAttachments.some(
|
|
5072
5393
|
(att) => att.status === "ready"
|
|
@@ -5078,7 +5399,7 @@ function ChatWelcome({
|
|
|
5078
5399
|
setPendingAttachments([]);
|
|
5079
5400
|
setInput("");
|
|
5080
5401
|
}, [input, isLoading, onSendMessage, pendingAttachments]);
|
|
5081
|
-
const handleSuggestionClick =
|
|
5402
|
+
const handleSuggestionClick = React19.useCallback(
|
|
5082
5403
|
(suggestion) => {
|
|
5083
5404
|
onSendMessage(suggestion);
|
|
5084
5405
|
},
|
|
@@ -5250,11 +5571,11 @@ function ChatWelcome({
|
|
|
5250
5571
|
}
|
|
5251
5572
|
);
|
|
5252
5573
|
}
|
|
5253
|
-
var CopilotChatContext =
|
|
5574
|
+
var CopilotChatContext = React19.createContext(
|
|
5254
5575
|
null
|
|
5255
5576
|
);
|
|
5256
5577
|
var useCopilotChatContext = () => {
|
|
5257
|
-
const ctx =
|
|
5578
|
+
const ctx = React19.useContext(CopilotChatContext);
|
|
5258
5579
|
if (!ctx) {
|
|
5259
5580
|
throw new Error(
|
|
5260
5581
|
"useCopilotChatContext must be used within CopilotChat. Make sure you're using CopilotChat.Home, CopilotChat.Input, etc. inside <CopilotChat>"
|
|
@@ -5288,10 +5609,10 @@ function ChatView({ children, className }) {
|
|
|
5288
5609
|
ChatView.displayName = "ChatView";
|
|
5289
5610
|
function chatViewHasOnlyLayoutChildren(chatViewElement) {
|
|
5290
5611
|
if (!chatViewElement?.props?.children) return false;
|
|
5291
|
-
const childArray =
|
|
5612
|
+
const childArray = React19__namespace.default.Children.toArray(chatViewElement.props.children);
|
|
5292
5613
|
if (childArray.length === 0) return false;
|
|
5293
5614
|
return childArray.every(
|
|
5294
|
-
(child) =>
|
|
5615
|
+
(child) => React19__namespace.default.isValidElement(child) && (child.type === Header || child.type === Footer)
|
|
5295
5616
|
);
|
|
5296
5617
|
}
|
|
5297
5618
|
function Header({ children, className }) {
|
|
@@ -5307,8 +5628,8 @@ function Input({ placeholder: placeholderProp, className }) {
|
|
|
5307
5628
|
onStop,
|
|
5308
5629
|
placeholder: defaultPlaceholder
|
|
5309
5630
|
} = useCopilotChatContext();
|
|
5310
|
-
const [value, setValue] =
|
|
5311
|
-
const handleSubmit =
|
|
5631
|
+
const [value, setValue] = React19.useState("");
|
|
5632
|
+
const handleSubmit = React19.useCallback(() => {
|
|
5312
5633
|
if (value.trim() && !isLoading) {
|
|
5313
5634
|
send(value.trim());
|
|
5314
5635
|
setValue("");
|
|
@@ -5429,18 +5750,18 @@ function ThreadPickerCompound(props) {
|
|
|
5429
5750
|
);
|
|
5430
5751
|
}
|
|
5431
5752
|
function hasCompoundChild(children, ...components) {
|
|
5432
|
-
return
|
|
5433
|
-
(child) =>
|
|
5753
|
+
return React19__namespace.default.Children.toArray(children).some(
|
|
5754
|
+
(child) => React19__namespace.default.isValidElement(child) && components.includes(child.type)
|
|
5434
5755
|
);
|
|
5435
5756
|
}
|
|
5436
5757
|
function findCompoundChild(children, component) {
|
|
5437
|
-
return
|
|
5438
|
-
(child) =>
|
|
5758
|
+
return React19__namespace.default.Children.toArray(children).find(
|
|
5759
|
+
(child) => React19__namespace.default.isValidElement(child) && child.type === component
|
|
5439
5760
|
);
|
|
5440
5761
|
}
|
|
5441
5762
|
function filterCompoundChildren(children, ...components) {
|
|
5442
|
-
return
|
|
5443
|
-
(child) =>
|
|
5763
|
+
return React19__namespace.default.Children.toArray(children).filter(
|
|
5764
|
+
(child) => React19__namespace.default.isValidElement(child) && components.includes(child.type)
|
|
5444
5765
|
);
|
|
5445
5766
|
}
|
|
5446
5767
|
var DEFAULT_MAX_FILE_SIZE2 = 5 * 1024 * 1024;
|
|
@@ -5547,12 +5868,12 @@ function ChatComponent({
|
|
|
5547
5868
|
}) {
|
|
5548
5869
|
const userAvatar = { fallback: "U", ...userAvatarProp };
|
|
5549
5870
|
const assistantAvatar = { fallback: "AI", ...assistantAvatarProp };
|
|
5550
|
-
const [input, setInput] =
|
|
5551
|
-
const [pendingAttachments, setPendingAttachments] =
|
|
5552
|
-
const [isDragging, setIsDragging] =
|
|
5553
|
-
const fileInputRef =
|
|
5554
|
-
const fileInputId =
|
|
5555
|
-
const isFileTypeAllowed =
|
|
5871
|
+
const [input, setInput] = React19.useState("");
|
|
5872
|
+
const [pendingAttachments, setPendingAttachments] = React19.useState([]);
|
|
5873
|
+
const [isDragging, setIsDragging] = React19.useState(false);
|
|
5874
|
+
const fileInputRef = React19.useRef(null);
|
|
5875
|
+
const fileInputId = React19.useId();
|
|
5876
|
+
const isFileTypeAllowed = React19.useCallback(
|
|
5556
5877
|
(file) => {
|
|
5557
5878
|
for (const type of allowedFileTypes) {
|
|
5558
5879
|
if (type.endsWith("/*")) {
|
|
@@ -5566,7 +5887,7 @@ function ChatComponent({
|
|
|
5566
5887
|
},
|
|
5567
5888
|
[allowedFileTypes]
|
|
5568
5889
|
);
|
|
5569
|
-
const handleFileSelect =
|
|
5890
|
+
const handleFileSelect = React19.useCallback(
|
|
5570
5891
|
async (files) => {
|
|
5571
5892
|
if (!files || !attachmentsEnabled) return;
|
|
5572
5893
|
for (const file of Array.from(files)) {
|
|
@@ -5629,7 +5950,7 @@ function ChatComponent({
|
|
|
5629
5950
|
},
|
|
5630
5951
|
[attachmentsEnabled, maxFileSize, isFileTypeAllowed, processAttachmentProp]
|
|
5631
5952
|
);
|
|
5632
|
-
const handleInputChange =
|
|
5953
|
+
const handleInputChange = React19.useCallback(
|
|
5633
5954
|
(e) => {
|
|
5634
5955
|
handleFileSelect(e.target.files);
|
|
5635
5956
|
if (fileInputRef.current) {
|
|
@@ -5638,7 +5959,7 @@ function ChatComponent({
|
|
|
5638
5959
|
},
|
|
5639
5960
|
[handleFileSelect]
|
|
5640
5961
|
);
|
|
5641
|
-
const removePendingAttachment =
|
|
5962
|
+
const removePendingAttachment = React19.useCallback((id) => {
|
|
5642
5963
|
setPendingAttachments((prev) => {
|
|
5643
5964
|
const att = prev.find((a) => a.id === id);
|
|
5644
5965
|
if (att) {
|
|
@@ -5647,7 +5968,7 @@ function ChatComponent({
|
|
|
5647
5968
|
return prev.filter((a) => a.id !== id);
|
|
5648
5969
|
});
|
|
5649
5970
|
}, []);
|
|
5650
|
-
const handleDragOver =
|
|
5971
|
+
const handleDragOver = React19.useCallback(
|
|
5651
5972
|
(e) => {
|
|
5652
5973
|
e.preventDefault();
|
|
5653
5974
|
e.stopPropagation();
|
|
@@ -5657,12 +5978,12 @@ function ChatComponent({
|
|
|
5657
5978
|
},
|
|
5658
5979
|
[attachmentsEnabled]
|
|
5659
5980
|
);
|
|
5660
|
-
const handleDragLeave =
|
|
5981
|
+
const handleDragLeave = React19.useCallback((e) => {
|
|
5661
5982
|
e.preventDefault();
|
|
5662
5983
|
e.stopPropagation();
|
|
5663
5984
|
setIsDragging(false);
|
|
5664
5985
|
}, []);
|
|
5665
|
-
const handleDrop =
|
|
5986
|
+
const handleDrop = React19.useCallback(
|
|
5666
5987
|
(e) => {
|
|
5667
5988
|
e.preventDefault();
|
|
5668
5989
|
e.stopPropagation();
|
|
@@ -5673,7 +5994,7 @@ function ChatComponent({
|
|
|
5673
5994
|
},
|
|
5674
5995
|
[attachmentsEnabled, handleFileSelect]
|
|
5675
5996
|
);
|
|
5676
|
-
const handleSubmit =
|
|
5997
|
+
const handleSubmit = React19.useCallback(() => {
|
|
5677
5998
|
const hasContent = input.trim();
|
|
5678
5999
|
const hasAttachments = pendingAttachments.some(
|
|
5679
6000
|
(att) => att.status === "ready"
|
|
@@ -5685,7 +6006,7 @@ function ChatComponent({
|
|
|
5685
6006
|
setPendingAttachments([]);
|
|
5686
6007
|
setInput("");
|
|
5687
6008
|
}, [input, isLoading, onSendMessage, pendingAttachments]);
|
|
5688
|
-
const handleSuggestionClick =
|
|
6009
|
+
const handleSuggestionClick = React19.useCallback(
|
|
5689
6010
|
(suggestion) => {
|
|
5690
6011
|
if (onSuggestionClick) {
|
|
5691
6012
|
onSuggestionClick(suggestion);
|
|
@@ -5712,13 +6033,13 @@ function ChatComponent({
|
|
|
5712
6033
|
const chatViewNeedsDefault = chatViewElement && (!chatViewElement.props.children || chatViewHasOnlyLayoutChildren(chatViewElement));
|
|
5713
6034
|
const showDefaultWelcome = view === "home" && !hasCustomHome && welcome !== false;
|
|
5714
6035
|
const welcomeConfig = typeof welcome === "object" ? welcome : void 0;
|
|
5715
|
-
const send =
|
|
6036
|
+
const send = React19.useCallback(
|
|
5716
6037
|
(message, attachments) => {
|
|
5717
6038
|
onSendMessage?.(message, attachments);
|
|
5718
6039
|
},
|
|
5719
6040
|
[onSendMessage]
|
|
5720
6041
|
);
|
|
5721
|
-
const contextValue =
|
|
6042
|
+
const contextValue = React19__namespace.default.useMemo(
|
|
5722
6043
|
() => ({
|
|
5723
6044
|
view,
|
|
5724
6045
|
send,
|
|
@@ -5726,6 +6047,9 @@ function ChatComponent({
|
|
|
5726
6047
|
onStop,
|
|
5727
6048
|
attachmentsEnabled,
|
|
5728
6049
|
placeholder,
|
|
6050
|
+
// Messages for Chat.MessageList primitive
|
|
6051
|
+
messages,
|
|
6052
|
+
registeredTools,
|
|
5729
6053
|
// Thread management - passed from connected-chat
|
|
5730
6054
|
onNewChat,
|
|
5731
6055
|
threads,
|
|
@@ -5741,6 +6065,8 @@ function ChatComponent({
|
|
|
5741
6065
|
onStop,
|
|
5742
6066
|
attachmentsEnabled,
|
|
5743
6067
|
placeholder,
|
|
6068
|
+
messages,
|
|
6069
|
+
registeredTools,
|
|
5744
6070
|
onNewChat,
|
|
5745
6071
|
threads,
|
|
5746
6072
|
currentThreadId,
|
|
@@ -5749,7 +6075,7 @@ function ChatComponent({
|
|
|
5749
6075
|
isThreadBusy
|
|
5750
6076
|
]
|
|
5751
6077
|
);
|
|
5752
|
-
return /* @__PURE__ */ jsxRuntime.jsx(CopilotChatContext.Provider, { value: contextValue, children: /* @__PURE__ */ jsxRuntime.jsxs(
|
|
6078
|
+
return /* @__PURE__ */ jsxRuntime.jsx(MessageActionsProvider, { children: /* @__PURE__ */ jsxRuntime.jsx(CopilotChatContext.Provider, { value: contextValue, children: /* @__PURE__ */ jsxRuntime.jsxs(
|
|
5753
6079
|
"div",
|
|
5754
6080
|
{
|
|
5755
6081
|
className: cn(
|
|
@@ -5849,7 +6175,10 @@ function ChatComponent({
|
|
|
5849
6175
|
}
|
|
5850
6176
|
const savedExecutions = message.metadata?.toolExecutions;
|
|
5851
6177
|
const messageToolExecutions = message.toolExecutions || savedExecutions;
|
|
5852
|
-
const messageWithExecutions = messageToolExecutions ? {
|
|
6178
|
+
const messageWithExecutions = messageToolExecutions ? {
|
|
6179
|
+
...message,
|
|
6180
|
+
toolExecutions: messageToolExecutions
|
|
6181
|
+
} : message;
|
|
5853
6182
|
const handleFollowUpClick = (question) => {
|
|
5854
6183
|
if (onSuggestionClick) {
|
|
5855
6184
|
onSuggestionClick(question);
|
|
@@ -5857,7 +6186,7 @@ function ChatComponent({
|
|
|
5857
6186
|
onSendMessage?.(question);
|
|
5858
6187
|
}
|
|
5859
6188
|
};
|
|
5860
|
-
return renderMessage ? /* @__PURE__ */ jsxRuntime.jsx(
|
|
6189
|
+
return renderMessage ? /* @__PURE__ */ jsxRuntime.jsx(React19__namespace.default.Fragment, { children: renderMessage(messageWithExecutions, index) }, message.id) : /* @__PURE__ */ jsxRuntime.jsx(
|
|
5861
6190
|
DefaultMessage,
|
|
5862
6191
|
{
|
|
5863
6192
|
message: messageWithExecutions,
|
|
@@ -6040,7 +6369,7 @@ function ChatComponent({
|
|
|
6040
6369
|
rootFooter
|
|
6041
6370
|
]
|
|
6042
6371
|
}
|
|
6043
|
-
) });
|
|
6372
|
+
) }) });
|
|
6044
6373
|
}
|
|
6045
6374
|
var Chat = Object.assign(ChatComponent, {
|
|
6046
6375
|
Root: ChatComponent,
|
|
@@ -6056,9 +6385,34 @@ var Chat = Object.assign(ChatComponent, {
|
|
|
6056
6385
|
Suggestions: SuggestionsCompound,
|
|
6057
6386
|
BackButton,
|
|
6058
6387
|
// Navigation: start new chat
|
|
6059
|
-
ThreadPicker: ThreadPickerCompound
|
|
6388
|
+
ThreadPicker: ThreadPickerCompound,
|
|
6060
6389
|
// Thread switching
|
|
6390
|
+
// Message actions compound components
|
|
6391
|
+
MessageActions: MessageActions2,
|
|
6392
|
+
CopyAction,
|
|
6393
|
+
EditAction,
|
|
6394
|
+
FeedbackAction,
|
|
6395
|
+
Action
|
|
6061
6396
|
});
|
|
6397
|
+
function MessageList({ children, className }) {
|
|
6398
|
+
const { messages, registeredTools } = useCopilotChatContext();
|
|
6399
|
+
return /* @__PURE__ */ jsxRuntime.jsx("div", { className, children: messages.map((message, index) => {
|
|
6400
|
+
if (children) {
|
|
6401
|
+
return /* @__PURE__ */ jsxRuntime.jsx(React19__namespace.Fragment, { children: children(message, index) }, message.id);
|
|
6402
|
+
}
|
|
6403
|
+
return /* @__PURE__ */ jsxRuntime.jsx(
|
|
6404
|
+
DefaultMessage,
|
|
6405
|
+
{
|
|
6406
|
+
message,
|
|
6407
|
+
userAvatar: { fallback: "U" },
|
|
6408
|
+
assistantAvatar: { fallback: "AI" },
|
|
6409
|
+
registeredTools,
|
|
6410
|
+
isLastMessage: index === messages.length - 1
|
|
6411
|
+
},
|
|
6412
|
+
message.id
|
|
6413
|
+
);
|
|
6414
|
+
}) });
|
|
6415
|
+
}
|
|
6062
6416
|
function ToolExecutionMessage({
|
|
6063
6417
|
executions,
|
|
6064
6418
|
assistantAvatar = { fallback: "AI" },
|
|
@@ -6202,7 +6556,8 @@ function useInternalThreadManager(config = {}) {
|
|
|
6202
6556
|
adapter,
|
|
6203
6557
|
saveDebounce = 1e3,
|
|
6204
6558
|
autoRestoreLastThread = true,
|
|
6205
|
-
onThreadChange
|
|
6559
|
+
onThreadChange,
|
|
6560
|
+
enabled = true
|
|
6206
6561
|
} = config;
|
|
6207
6562
|
const threadManagerConfig = {
|
|
6208
6563
|
adapter,
|
|
@@ -6220,17 +6575,17 @@ function useInternalThreadManager(config = {}) {
|
|
|
6220
6575
|
refreshThreads
|
|
6221
6576
|
} = threadManager;
|
|
6222
6577
|
const { messages, setMessages, status, isLoading, getAllMessages } = chunkTCPAT3WG_cjs.useCopilot();
|
|
6223
|
-
const isLoadingMessagesRef =
|
|
6224
|
-
const savingToThreadRef =
|
|
6225
|
-
const lastSavedSnapshotRef =
|
|
6226
|
-
const hasInitializedRef =
|
|
6227
|
-
const getMessageSnapshot =
|
|
6578
|
+
const isLoadingMessagesRef = React19.useRef(false);
|
|
6579
|
+
const savingToThreadRef = React19.useRef(null);
|
|
6580
|
+
const lastSavedSnapshotRef = React19.useRef("");
|
|
6581
|
+
const hasInitializedRef = React19.useRef(false);
|
|
6582
|
+
const getMessageSnapshot = React19.useCallback((msgs) => {
|
|
6228
6583
|
return msgs.map((m) => {
|
|
6229
6584
|
const contentPreview = (m.content ?? "").slice(0, 20);
|
|
6230
6585
|
return `${m.id}:${contentPreview}:${m.content?.length ?? 0}`;
|
|
6231
6586
|
}).join("|");
|
|
6232
6587
|
}, []);
|
|
6233
|
-
const convertToCore =
|
|
6588
|
+
const convertToCore = React19.useCallback((msgs) => {
|
|
6234
6589
|
return msgs.map((m) => ({
|
|
6235
6590
|
id: m.id,
|
|
6236
6591
|
role: m.role,
|
|
@@ -6248,7 +6603,7 @@ function useInternalThreadManager(config = {}) {
|
|
|
6248
6603
|
}
|
|
6249
6604
|
}));
|
|
6250
6605
|
}, []);
|
|
6251
|
-
const handleSwitchThread =
|
|
6606
|
+
const handleSwitchThread = React19.useCallback(
|
|
6252
6607
|
async (threadId) => {
|
|
6253
6608
|
isLoadingMessagesRef.current = true;
|
|
6254
6609
|
const thread = await switchThread(threadId);
|
|
@@ -6279,7 +6634,7 @@ function useInternalThreadManager(config = {}) {
|
|
|
6279
6634
|
},
|
|
6280
6635
|
[switchThread, setMessages, getMessageSnapshot, onThreadChange]
|
|
6281
6636
|
);
|
|
6282
|
-
const handleNewThread =
|
|
6637
|
+
const handleNewThread = React19.useCallback(async () => {
|
|
6283
6638
|
isLoadingMessagesRef.current = true;
|
|
6284
6639
|
clearCurrentThread();
|
|
6285
6640
|
lastSavedSnapshotRef.current = "";
|
|
@@ -6290,7 +6645,8 @@ function useInternalThreadManager(config = {}) {
|
|
|
6290
6645
|
isLoadingMessagesRef.current = false;
|
|
6291
6646
|
});
|
|
6292
6647
|
}, [clearCurrentThread, setMessages, onThreadChange]);
|
|
6293
|
-
|
|
6648
|
+
React19.useEffect(() => {
|
|
6649
|
+
if (!enabled) return;
|
|
6294
6650
|
if (hasInitializedRef.current || !currentThread) {
|
|
6295
6651
|
return;
|
|
6296
6652
|
}
|
|
@@ -6322,8 +6678,9 @@ function useInternalThreadManager(config = {}) {
|
|
|
6322
6678
|
requestAnimationFrame(() => {
|
|
6323
6679
|
isLoadingMessagesRef.current = false;
|
|
6324
6680
|
});
|
|
6325
|
-
}, [adapter, currentThread, setMessages, getMessageSnapshot, onThreadChange]);
|
|
6326
|
-
|
|
6681
|
+
}, [enabled, adapter, currentThread, setMessages, getMessageSnapshot, onThreadChange]);
|
|
6682
|
+
React19.useEffect(() => {
|
|
6683
|
+
if (!enabled) return;
|
|
6327
6684
|
if (isLoadingMessagesRef.current) {
|
|
6328
6685
|
return;
|
|
6329
6686
|
}
|
|
@@ -6356,6 +6713,7 @@ function useInternalThreadManager(config = {}) {
|
|
|
6356
6713
|
updateCurrentThread({ messages: coreMessages });
|
|
6357
6714
|
lastSavedSnapshotRef.current = currentSnapshot;
|
|
6358
6715
|
}, [
|
|
6716
|
+
enabled,
|
|
6359
6717
|
adapter,
|
|
6360
6718
|
messages,
|
|
6361
6719
|
currentThreadId,
|
|
@@ -6434,7 +6792,7 @@ function CopilotChatBase(props) {
|
|
|
6434
6792
|
} = props;
|
|
6435
6793
|
const persistenceConfig = parsePersistenceConfig(persistence, onThreadChange);
|
|
6436
6794
|
const threadManagerResult = useInternalThreadManager(
|
|
6437
|
-
persistenceConfig ?? { autoRestoreLastThread: false }
|
|
6795
|
+
persistenceConfig ?? { autoRestoreLastThread: false, enabled: false }
|
|
6438
6796
|
);
|
|
6439
6797
|
const isPersistenceEnabled = !!persistence;
|
|
6440
6798
|
const {
|
|
@@ -6603,7 +6961,7 @@ function CopilotChatBase(props) {
|
|
|
6603
6961
|
footer: classNames.footer
|
|
6604
6962
|
} : void 0;
|
|
6605
6963
|
const { threadManager, handleSwitchThread, handleNewThread, isBusy } = threadManagerResult;
|
|
6606
|
-
const handleDeleteThread =
|
|
6964
|
+
const handleDeleteThread = React19__namespace.default.useCallback(
|
|
6607
6965
|
(threadId) => {
|
|
6608
6966
|
const isCurrentThread = threadManager.currentThreadId === threadId;
|
|
6609
6967
|
threadManager.deleteThread(threadId);
|
|
@@ -6731,6 +7089,38 @@ function PoweredBy({ className, showLogo = true }) {
|
|
|
6731
7089
|
);
|
|
6732
7090
|
}
|
|
6733
7091
|
|
|
7092
|
+
// src/ui/index.ts
|
|
7093
|
+
var ChatPrimitives = {
|
|
7094
|
+
// ── List ──────────────────────────────────────────────
|
|
7095
|
+
/** Renders the message list via render-prop. Falls back to DefaultMessage if no children. */
|
|
7096
|
+
MessageList,
|
|
7097
|
+
// ── Messages ──────────────────────────────────────────
|
|
7098
|
+
/** Full SDK message bubble (user + assistant + tools). Use as fallback inside MessageList. */
|
|
7099
|
+
DefaultMessage,
|
|
7100
|
+
/** Low-level message row wrapper (flex layout + avatar slot) */
|
|
7101
|
+
Message,
|
|
7102
|
+
/** Message avatar — image with fallback text/icon */
|
|
7103
|
+
MessageAvatar,
|
|
7104
|
+
/** Message content bubble — supports markdown */
|
|
7105
|
+
MessageContent,
|
|
7106
|
+
/** Action bar below a message (copy, feedback, etc.) */
|
|
7107
|
+
MessageActions,
|
|
7108
|
+
/** Single action button with tooltip inside MessageActions */
|
|
7109
|
+
MessageAction,
|
|
7110
|
+
// ── Layout ────────────────────────────────────────────
|
|
7111
|
+
/** Chat header bar with title and controls */
|
|
7112
|
+
Header: ChatHeader,
|
|
7113
|
+
/** Welcome screen shown when there are no messages */
|
|
7114
|
+
Welcome: ChatWelcome,
|
|
7115
|
+
/** Chat input / composer */
|
|
7116
|
+
Input: PromptInput,
|
|
7117
|
+
/** Scroll anchor — keeps the view pinned to the latest message */
|
|
7118
|
+
ScrollAnchor: ChatContainerScrollAnchor,
|
|
7119
|
+
// ── Indicators ────────────────────────────────────────
|
|
7120
|
+
/** Loading / streaming indicator (dots, wave, typing variants) */
|
|
7121
|
+
Loader
|
|
7122
|
+
};
|
|
7123
|
+
|
|
6734
7124
|
exports.AlertTriangleIcon = AlertTriangleIcon;
|
|
6735
7125
|
exports.BotIcon = BotIcon;
|
|
6736
7126
|
exports.BranchNavigator = BranchNavigator;
|
|
@@ -6741,6 +7131,7 @@ exports.Chat = Chat;
|
|
|
6741
7131
|
exports.ChatContainerContent = ChatContainerContent;
|
|
6742
7132
|
exports.ChatContainerRoot = ChatContainerRoot;
|
|
6743
7133
|
exports.ChatContainerScrollAnchor = ChatContainerScrollAnchor;
|
|
7134
|
+
exports.ChatPrimitives = ChatPrimitives;
|
|
6744
7135
|
exports.ChatWelcome = ChatWelcome;
|
|
6745
7136
|
exports.CheckIcon = CheckIcon;
|
|
6746
7137
|
exports.ChevronDownIcon = ChevronDownIcon2;
|