@copilotkit/react-core 1.59.0 → 1.59.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.
- package/dist/{copilotkit-L4mM_JqG.mjs → copilotkit-B5RsC6la.mjs} +144 -39
- package/dist/copilotkit-B5RsC6la.mjs.map +1 -0
- package/dist/{copilotkit-WlmeVijs.d.mts → copilotkit-CEJz6krE.d.mts} +3 -2
- package/dist/{copilotkit-WlmeVijs.d.mts.map → copilotkit-CEJz6krE.d.mts.map} +1 -1
- package/dist/{copilotkit-BK9CVq9A.d.cts → copilotkit-D16eCFkt.d.cts} +3 -2
- package/dist/{copilotkit-BK9CVq9A.d.cts.map → copilotkit-D16eCFkt.d.cts.map} +1 -1
- package/dist/{copilotkit-B4ouY7qC.cjs → copilotkit-IQO0VDZb.cjs} +144 -39
- package/dist/copilotkit-IQO0VDZb.cjs.map +1 -0
- package/dist/index.cjs +1 -1
- package/dist/index.d.cts +1 -1
- package/dist/index.d.mts +1 -1
- package/dist/index.mjs +1 -1
- package/dist/index.umd.js +368 -398
- package/dist/index.umd.js.map +1 -1
- package/dist/v2/headless.cjs +44 -19
- package/dist/v2/headless.cjs.map +1 -1
- package/dist/v2/headless.mjs +44 -19
- package/dist/v2/headless.mjs.map +1 -1
- package/dist/v2/index.cjs +1 -1
- package/dist/v2/index.d.cts +1 -1
- package/dist/v2/index.d.mts +1 -1
- package/dist/v2/index.mjs +1 -1
- package/dist/v2/index.umd.js +444 -523
- package/dist/v2/index.umd.js.map +1 -1
- package/package.json +12 -7
- package/dist/copilotkit-B4ouY7qC.cjs.map +0 -1
- package/dist/copilotkit-L4mM_JqG.mjs.map +0 -1
package/dist/v2/index.umd.js
CHANGED
|
@@ -162,27 +162,26 @@ _radix_ui_react_dropdown_menu = __toESM(_radix_ui_react_dropdown_menu);
|
|
|
162
162
|
};
|
|
163
163
|
const CopilotChatConfiguration = (0, react.createContext)(null);
|
|
164
164
|
const CopilotChatConfigurationProvider = ({ children, labels, agentId, threadId, hasExplicitThreadId, isModalDefaultOpen }) => {
|
|
165
|
-
var _ref, _parentConfig$isModal, _parentConfig$setModa;
|
|
166
165
|
const parentConfig = (0, react.useContext)(CopilotChatConfiguration);
|
|
167
166
|
const stableLabels = useShallowStableRef(labels);
|
|
168
167
|
const mergedLabels = (0, react.useMemo)(() => ({
|
|
169
168
|
...CopilotChatDefaultLabels,
|
|
170
|
-
...parentConfig
|
|
169
|
+
...parentConfig?.labels,
|
|
171
170
|
...stableLabels
|
|
172
|
-
}), [stableLabels, parentConfig
|
|
173
|
-
const resolvedAgentId =
|
|
171
|
+
}), [stableLabels, parentConfig?.labels]);
|
|
172
|
+
const resolvedAgentId = agentId ?? parentConfig?.agentId ?? _copilotkit_shared.DEFAULT_AGENT_ID;
|
|
174
173
|
const resolvedThreadId = (0, react.useMemo)(() => {
|
|
175
174
|
if (threadId) return threadId;
|
|
176
|
-
if (parentConfig
|
|
175
|
+
if (parentConfig?.threadId) return parentConfig.threadId;
|
|
177
176
|
return (0, _copilotkit_shared.randomUUID)();
|
|
178
|
-
}, [threadId, parentConfig
|
|
179
|
-
const resolvedHasExplicitThreadId = (hasExplicitThreadId !== void 0 ? hasExplicitThreadId : !!threadId) || !!
|
|
180
|
-
const [internalModalOpen, setInternalModalOpen] = (0, react.useState)(isModalDefaultOpen
|
|
177
|
+
}, [threadId, parentConfig?.threadId]);
|
|
178
|
+
const resolvedHasExplicitThreadId = (hasExplicitThreadId !== void 0 ? hasExplicitThreadId : !!threadId) || !!parentConfig?.hasExplicitThreadId;
|
|
179
|
+
const [internalModalOpen, setInternalModalOpen] = (0, react.useState)(isModalDefaultOpen ?? true);
|
|
181
180
|
const hasExplicitDefault = isModalDefaultOpen !== void 0;
|
|
182
181
|
const setAndSync = (0, react.useCallback)((open) => {
|
|
183
182
|
setInternalModalOpen(open);
|
|
184
|
-
parentConfig
|
|
185
|
-
}, [parentConfig
|
|
183
|
+
parentConfig?.setModalOpen(open);
|
|
184
|
+
}, [parentConfig?.setModalOpen]);
|
|
186
185
|
const isMounted = (0, react.useRef)(false);
|
|
187
186
|
(0, react.useEffect)(() => {
|
|
188
187
|
if (!hasExplicitDefault) return;
|
|
@@ -190,11 +189,11 @@ _radix_ui_react_dropdown_menu = __toESM(_radix_ui_react_dropdown_menu);
|
|
|
190
189
|
isMounted.current = true;
|
|
191
190
|
return;
|
|
192
191
|
}
|
|
193
|
-
if (
|
|
192
|
+
if (parentConfig?.isModalOpen === void 0) return;
|
|
194
193
|
setInternalModalOpen(parentConfig.isModalOpen);
|
|
195
|
-
}, [parentConfig
|
|
196
|
-
const resolvedIsModalOpen = hasExplicitDefault ? internalModalOpen :
|
|
197
|
-
const resolvedSetModalOpen = hasExplicitDefault ? setAndSync :
|
|
194
|
+
}, [parentConfig?.isModalOpen, hasExplicitDefault]);
|
|
195
|
+
const resolvedIsModalOpen = hasExplicitDefault ? internalModalOpen : parentConfig?.isModalOpen ?? internalModalOpen;
|
|
196
|
+
const resolvedSetModalOpen = hasExplicitDefault ? setAndSync : parentConfig?.setModalOpen ?? setInternalModalOpen;
|
|
198
197
|
const configurationValue = (0, react.useMemo)(() => ({
|
|
199
198
|
labels: mergedLabels,
|
|
200
199
|
agentId: resolvedAgentId,
|
|
@@ -427,7 +426,7 @@ _radix_ui_react_dropdown_menu = __toESM(_radix_ui_react_dropdown_menu);
|
|
|
427
426
|
}
|
|
428
427
|
if (mediaRecorderRef.current && mediaRecorderRef.current.state !== "inactive") try {
|
|
429
428
|
mediaRecorderRef.current.stop();
|
|
430
|
-
} catch
|
|
429
|
+
} catch {}
|
|
431
430
|
if (streamRef.current) {
|
|
432
431
|
streamRef.current.getTracks().forEach((track) => track.stop());
|
|
433
432
|
streamRef.current = null;
|
|
@@ -500,8 +499,7 @@ _radix_ui_react_dropdown_menu = __toESM(_radix_ui_react_dropdown_menu);
|
|
|
500
499
|
const calculateAmplitude = (dataArray) => {
|
|
501
500
|
let sum = 0;
|
|
502
501
|
for (let i = 0; i < dataArray.length; i++) {
|
|
503
|
-
|
|
504
|
-
const sample = ((_dataArray$i = dataArray[i]) !== null && _dataArray$i !== void 0 ? _dataArray$i : 128) / 128 - 1;
|
|
502
|
+
const sample = (dataArray[i] ?? 128) / 128 - 1;
|
|
505
503
|
sum += sample * sample;
|
|
506
504
|
}
|
|
507
505
|
return Math.sqrt(sum / dataArray.length);
|
|
@@ -549,8 +547,7 @@ _radix_ui_react_dropdown_menu = __toESM(_radix_ui_react_dropdown_menu);
|
|
|
549
547
|
const offset = scrollOffsetRef.current;
|
|
550
548
|
const edgeFadeWidth = 12;
|
|
551
549
|
for (let i = 0; i < history.length; i++) {
|
|
552
|
-
|
|
553
|
-
const amplitude = (_history$i = history[i]) !== null && _history$i !== void 0 ? _history$i : 0;
|
|
550
|
+
const amplitude = history[i] ?? 0;
|
|
554
551
|
const scaledAmplitude = Math.min(amplitude * 4, 1);
|
|
555
552
|
const barHeight = Math.max(2, scaledAmplitude * maxAmplitude * 2);
|
|
556
553
|
const x = rect.width - (history.length - i) * barSpacing - offset;
|
|
@@ -603,13 +600,12 @@ _radix_ui_react_dropdown_menu = __toESM(_radix_ui_react_dropdown_menu);
|
|
|
603
600
|
const SLASH_MENU_MAX_VISIBLE_ITEMS = 5;
|
|
604
601
|
const SLASH_MENU_ITEM_HEIGHT_PX = 40;
|
|
605
602
|
function CopilotChatInput({ mode = "input", onSubmitMessage, onStop, isRunning = false, onStartTranscribe, onCancelTranscribe, onFinishTranscribe, onFinishTranscribeWithAudio, onAddFile, onChange, value, toolsMenu, autoFocus = false, positioning = "static", keyboardHeight = 0, containerRef, showDisclaimer, bottomAnchored = false, textArea, sendButton, startTranscribeButton, cancelTranscribeButton, finishTranscribeButton, addMenuButton, audioRecorder, disclaimer, children, className, ...props }) {
|
|
606
|
-
var _config$labels;
|
|
607
603
|
const isControlled = value !== void 0;
|
|
608
|
-
const [internalValue, setInternalValue] = (0, react.useState)(() => value
|
|
604
|
+
const [internalValue, setInternalValue] = (0, react.useState)(() => value ?? "");
|
|
609
605
|
(0, react.useEffect)(() => {
|
|
610
606
|
if (!isControlled && value !== void 0) setInternalValue(value);
|
|
611
607
|
}, [isControlled, value]);
|
|
612
|
-
const resolvedValue = isControlled ? value
|
|
608
|
+
const resolvedValue = isControlled ? value ?? "" : internalValue;
|
|
613
609
|
const [layout, setLayout] = (0, react.useState)("compact");
|
|
614
610
|
const ignoreResizeRef = (0, react.useRef)(false);
|
|
615
611
|
const resizeEvaluationRafRef = (0, react.useRef)(null);
|
|
@@ -623,7 +619,7 @@ _radix_ui_react_dropdown_menu = __toESM(_radix_ui_react_dropdown_menu);
|
|
|
623
619
|
const audioRecorderRef = (0, react.useRef)(null);
|
|
624
620
|
const slashMenuRef = (0, react.useRef)(null);
|
|
625
621
|
const config = useCopilotChatConfiguration();
|
|
626
|
-
const labels =
|
|
622
|
+
const labels = config?.labels ?? CopilotChatDefaultLabels;
|
|
627
623
|
const previousModalStateRef = (0, react.useRef)(void 0);
|
|
628
624
|
const measurementCanvasRef = (0, react.useRef)(null);
|
|
629
625
|
const measurementsRef = (0, react.useRef)({
|
|
@@ -674,15 +670,12 @@ _radix_ui_react_dropdown_menu = __toESM(_radix_ui_react_dropdown_menu);
|
|
|
674
670
|
}, [commandItems, commandQuery]);
|
|
675
671
|
(0, react.useEffect)(() => {
|
|
676
672
|
if (!autoFocus) {
|
|
677
|
-
previousModalStateRef.current = config
|
|
673
|
+
previousModalStateRef.current = config?.isModalOpen;
|
|
678
674
|
return;
|
|
679
675
|
}
|
|
680
|
-
if (
|
|
681
|
-
|
|
682
|
-
|
|
683
|
-
}
|
|
684
|
-
previousModalStateRef.current = config === null || config === void 0 ? void 0 : config.isModalOpen;
|
|
685
|
-
}, [config === null || config === void 0 ? void 0 : config.isModalOpen, autoFocus]);
|
|
676
|
+
if (config?.isModalOpen && !previousModalStateRef.current) inputRef.current?.focus({ preventScroll: true });
|
|
677
|
+
previousModalStateRef.current = config?.isModalOpen;
|
|
678
|
+
}, [config?.isModalOpen, autoFocus]);
|
|
686
679
|
(0, react.useEffect)(() => {
|
|
687
680
|
if (commandItems.length === 0 && commandQuery !== null) setCommandQuery(null);
|
|
688
681
|
}, [commandItems.length, commandQuery]);
|
|
@@ -721,8 +714,7 @@ _radix_ui_react_dropdown_menu = __toESM(_radix_ui_react_dropdown_menu);
|
|
|
721
714
|
return;
|
|
722
715
|
}
|
|
723
716
|
if (value.startsWith("/")) {
|
|
724
|
-
|
|
725
|
-
const query = ((_value$split$ = value.split(/\r?\n/, 1)[0]) !== null && _value$split$ !== void 0 ? _value$split$ : "").slice(1);
|
|
717
|
+
const query = (value.split(/\r?\n/, 1)[0] ?? "").slice(1);
|
|
726
718
|
setCommandQuery((prev) => prev === query ? prev : query);
|
|
727
719
|
} else setCommandQuery((prev) => prev === null ? prev : null);
|
|
728
720
|
}, [commandItems.length]);
|
|
@@ -732,7 +724,7 @@ _radix_ui_react_dropdown_menu = __toESM(_radix_ui_react_dropdown_menu);
|
|
|
732
724
|
const handleChange = (e) => {
|
|
733
725
|
const nextValue = e.target.value;
|
|
734
726
|
if (!isControlled) setInternalValue(nextValue);
|
|
735
|
-
onChange
|
|
727
|
+
onChange?.(nextValue);
|
|
736
728
|
updateSlashState(nextValue);
|
|
737
729
|
};
|
|
738
730
|
const clearInputValue = (0, react.useCallback)(() => {
|
|
@@ -740,14 +732,12 @@ _radix_ui_react_dropdown_menu = __toESM(_radix_ui_react_dropdown_menu);
|
|
|
740
732
|
if (onChange) onChange("");
|
|
741
733
|
}, [isControlled, onChange]);
|
|
742
734
|
const runCommand = (0, react.useCallback)((item) => {
|
|
743
|
-
var _item$action;
|
|
744
735
|
clearInputValue();
|
|
745
|
-
|
|
736
|
+
item.action?.();
|
|
746
737
|
setCommandQuery(null);
|
|
747
738
|
setSlashHighlightIndex(0);
|
|
748
739
|
requestAnimationFrame(() => {
|
|
749
|
-
|
|
750
|
-
(_inputRef$current2 = inputRef.current) === null || _inputRef$current2 === void 0 || _inputRef$current2.focus();
|
|
740
|
+
inputRef.current?.focus();
|
|
751
741
|
});
|
|
752
742
|
}, [clearInputValue]);
|
|
753
743
|
const handleKeyDown = (e) => {
|
|
@@ -790,7 +780,7 @@ _radix_ui_react_dropdown_menu = __toESM(_radix_ui_react_dropdown_menu);
|
|
|
790
780
|
}
|
|
791
781
|
if (e.key === "Enter" && !e.shiftKey) {
|
|
792
782
|
e.preventDefault();
|
|
793
|
-
if (isProcessing) onStop
|
|
783
|
+
if (isProcessing) onStop?.();
|
|
794
784
|
else send();
|
|
795
785
|
}
|
|
796
786
|
};
|
|
@@ -800,7 +790,7 @@ _radix_ui_react_dropdown_menu = __toESM(_radix_ui_react_dropdown_menu);
|
|
|
800
790
|
if (!trimmed) return;
|
|
801
791
|
onSubmitMessage(trimmed);
|
|
802
792
|
if (!isControlled) setInternalValue("");
|
|
803
|
-
onChange
|
|
793
|
+
onChange?.("");
|
|
804
794
|
if (inputRef.current) inputRef.current.focus();
|
|
805
795
|
};
|
|
806
796
|
const BoundTextArea = renderSlot(textArea, CopilotChatInput.TextArea, {
|
|
@@ -822,7 +812,7 @@ _radix_ui_react_dropdown_menu = __toESM(_radix_ui_react_dropdown_menu);
|
|
|
822
812
|
const canStop = !!onStop;
|
|
823
813
|
const handleSendButtonClick = () => {
|
|
824
814
|
if (isProcessing) {
|
|
825
|
-
onStop
|
|
815
|
+
onStop?.();
|
|
826
816
|
return;
|
|
827
817
|
}
|
|
828
818
|
send();
|
|
@@ -843,7 +833,7 @@ _radix_ui_react_dropdown_menu = __toESM(_radix_ui_react_dropdown_menu);
|
|
|
843
833
|
} catch (error) {
|
|
844
834
|
console.error("Failed to stop recording:", error);
|
|
845
835
|
}
|
|
846
|
-
onFinishTranscribe
|
|
836
|
+
onFinishTranscribe?.();
|
|
847
837
|
}, [onFinishTranscribe, onFinishTranscribeWithAudio]);
|
|
848
838
|
const BoundFinishTranscribeButton = renderSlot(finishTranscribeButton, CopilotChatInput.FinishTranscribeButton, { onClick: handleFinishTranscribe });
|
|
849
839
|
const BoundAddMenuButton = renderSlot(addMenuButton, CopilotChatInput.AddMenuButton, {
|
|
@@ -852,7 +842,7 @@ _radix_ui_react_dropdown_menu = __toESM(_radix_ui_react_dropdown_menu);
|
|
|
852
842
|
toolsMenu
|
|
853
843
|
});
|
|
854
844
|
const BoundDisclaimer = renderSlot(disclaimer, CopilotChatInput.Disclaimer, {});
|
|
855
|
-
const shouldShowDisclaimer = showDisclaimer
|
|
845
|
+
const shouldShowDisclaimer = showDisclaimer ?? positioning === "absolute";
|
|
856
846
|
if (children) {
|
|
857
847
|
const childProps = {
|
|
858
848
|
textArea: BoundTextArea,
|
|
@@ -976,8 +966,7 @@ _radix_ui_react_dropdown_menu = __toESM(_radix_ui_react_dropdown_menu);
|
|
|
976
966
|
const renderedMultiline = baseline > 0 ? scrollHeight > baseline + 1 : false;
|
|
977
967
|
let shouldExpand = hasExplicitBreak || renderedMultiline;
|
|
978
968
|
if (!shouldExpand) {
|
|
979
|
-
|
|
980
|
-
const cache = (_containerCacheRef$cu = containerCacheRef.current) !== null && _containerCacheRef$cu !== void 0 ? _containerCacheRef$cu : updateContainerCache();
|
|
969
|
+
const cache = containerCacheRef.current ?? updateContainerCache();
|
|
981
970
|
if (cache && cache.compactWidth > 0) {
|
|
982
971
|
const compactInnerWidth = Math.max(cache.compactWidth - (measurementsRef.current.paddingLeft || 0) - (measurementsRef.current.paddingRight || 0), 0);
|
|
983
972
|
if (compactInnerWidth > 0) {
|
|
@@ -987,9 +976,8 @@ _radix_ui_react_dropdown_menu = __toESM(_radix_ui_react_dropdown_menu);
|
|
|
987
976
|
const { fontStyle, fontVariant, fontWeight, fontSize, lineHeight, fontFamily } = textareaStyles;
|
|
988
977
|
if (fontSize && fontFamily) font = `${fontStyle} ${fontVariant} ${fontWeight} ${fontSize}/${lineHeight} ${fontFamily}`;
|
|
989
978
|
}
|
|
990
|
-
if (font
|
|
991
|
-
|
|
992
|
-
const canvas = (_measurementCanvasRef = measurementCanvasRef.current) !== null && _measurementCanvasRef !== void 0 ? _measurementCanvasRef : document.createElement("canvas");
|
|
979
|
+
if (font?.trim()) {
|
|
980
|
+
const canvas = measurementCanvasRef.current ?? document.createElement("canvas");
|
|
993
981
|
if (!measurementCanvasRef.current) measurementCanvasRef.current = canvas;
|
|
994
982
|
const context = canvas.getContext("2d");
|
|
995
983
|
if (context) {
|
|
@@ -1068,10 +1056,8 @@ _radix_ui_react_dropdown_menu = __toESM(_radix_ui_react_dropdown_menu);
|
|
|
1068
1056
|
}, [evaluateLayout]);
|
|
1069
1057
|
const slashMenuVisible = commandQuery !== null && commandItems.length > 0;
|
|
1070
1058
|
(0, react.useEffect)(() => {
|
|
1071
|
-
var _slashMenuRef$current;
|
|
1072
1059
|
if (!slashMenuVisible || slashHighlightIndex < 0) return;
|
|
1073
|
-
|
|
1074
|
-
active === null || active === void 0 || active.scrollIntoView({ block: "nearest" });
|
|
1060
|
+
(slashMenuRef.current?.querySelector(`[data-slash-index="${slashHighlightIndex}"]`))?.scrollIntoView({ block: "nearest" });
|
|
1075
1061
|
}, [slashMenuVisible, slashHighlightIndex]);
|
|
1076
1062
|
const slashMenu = slashMenuVisible ? /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
|
|
1077
1063
|
"data-testid": "copilot-slash-menu",
|
|
@@ -1157,13 +1143,11 @@ _radix_ui_react_dropdown_menu = __toESM(_radix_ui_react_dropdown_menu);
|
|
|
1157
1143
|
size: "chatInputToolbarIcon",
|
|
1158
1144
|
className,
|
|
1159
1145
|
...props,
|
|
1160
|
-
children: children
|
|
1146
|
+
children: children ?? /* @__PURE__ */ (0, react_jsx_runtime.jsx)(lucide_react.ArrowUp, { className: "cpk:size-[18px]" })
|
|
1161
1147
|
})
|
|
1162
1148
|
});
|
|
1163
1149
|
const ToolbarButton = _CopilotChatInput.ToolbarButton = ({ icon, labelKey, defaultClassName, className, ...props }) => {
|
|
1164
|
-
|
|
1165
|
-
const config = useCopilotChatConfiguration();
|
|
1166
|
-
const labels = (_config$labels2 = config === null || config === void 0 ? void 0 : config.labels) !== null && _config$labels2 !== void 0 ? _config$labels2 : CopilotChatDefaultLabels;
|
|
1150
|
+
const labels = useCopilotChatConfiguration()?.labels ?? CopilotChatDefaultLabels;
|
|
1167
1151
|
return /* @__PURE__ */ (0, react_jsx_runtime.jsxs)(Tooltip, { children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)(TooltipTrigger, {
|
|
1168
1152
|
asChild: true,
|
|
1169
1153
|
children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(Button, {
|
|
@@ -1201,9 +1185,7 @@ _radix_ui_react_dropdown_menu = __toESM(_radix_ui_react_dropdown_menu);
|
|
|
1201
1185
|
...props
|
|
1202
1186
|
});
|
|
1203
1187
|
_CopilotChatInput.AddMenuButton = ({ className, toolsMenu, onAddFile, disabled, ...props }) => {
|
|
1204
|
-
|
|
1205
|
-
const config = useCopilotChatConfiguration();
|
|
1206
|
-
const labels = (_config$labels3 = config === null || config === void 0 ? void 0 : config.labels) !== null && _config$labels3 !== void 0 ? _config$labels3 : CopilotChatDefaultLabels;
|
|
1188
|
+
const labels = useCopilotChatConfiguration()?.labels ?? CopilotChatDefaultLabels;
|
|
1207
1189
|
const [mounted, setMounted] = (0, react.useState)(false);
|
|
1208
1190
|
(0, react.useEffect)(() => setMounted(true), []);
|
|
1209
1191
|
const menuItems = (0, react.useMemo)(() => {
|
|
@@ -1269,21 +1251,16 @@ _radix_ui_react_dropdown_menu = __toESM(_radix_ui_react_dropdown_menu);
|
|
|
1269
1251
|
})] });
|
|
1270
1252
|
};
|
|
1271
1253
|
_CopilotChatInput.TextArea = (0, react.forwardRef)(function TextArea({ style, className, autoFocus, placeholder, ...props }, ref) {
|
|
1272
|
-
var _config$labels4;
|
|
1273
1254
|
const internalTextareaRef = (0, react.useRef)(null);
|
|
1274
|
-
const
|
|
1275
|
-
const labels = (_config$labels4 = config === null || config === void 0 ? void 0 : config.labels) !== null && _config$labels4 !== void 0 ? _config$labels4 : CopilotChatDefaultLabels;
|
|
1255
|
+
const labels = useCopilotChatConfiguration()?.labels ?? CopilotChatDefaultLabels;
|
|
1276
1256
|
(0, react.useImperativeHandle)(ref, () => internalTextareaRef.current);
|
|
1277
1257
|
(0, react.useEffect)(() => {
|
|
1278
|
-
if (autoFocus) {
|
|
1279
|
-
var _internalTextareaRef$;
|
|
1280
|
-
(_internalTextareaRef$ = internalTextareaRef.current) === null || _internalTextareaRef$ === void 0 || _internalTextareaRef$.focus({ preventScroll: true });
|
|
1281
|
-
}
|
|
1258
|
+
if (autoFocus) internalTextareaRef.current?.focus({ preventScroll: true });
|
|
1282
1259
|
}, [autoFocus]);
|
|
1283
1260
|
return /* @__PURE__ */ (0, react_jsx_runtime.jsx)("textarea", {
|
|
1284
1261
|
ref: internalTextareaRef,
|
|
1285
1262
|
"data-testid": "copilot-chat-textarea",
|
|
1286
|
-
placeholder: placeholder
|
|
1263
|
+
placeholder: placeholder ?? labels.chatInputPlaceholder,
|
|
1287
1264
|
className: (0, tailwind_merge.twMerge)("cpk:bg-transparent cpk:outline-none cpk:antialiased cpk:font-regular cpk:leading-relaxed cpk:text-[16px] cpk:placeholder:text-[#00000077] cpk:dark:placeholder:text-[#fffc]", className),
|
|
1288
1265
|
style: {
|
|
1289
1266
|
overflow: "auto",
|
|
@@ -1296,9 +1273,7 @@ _radix_ui_react_dropdown_menu = __toESM(_radix_ui_react_dropdown_menu);
|
|
|
1296
1273
|
});
|
|
1297
1274
|
_CopilotChatInput.AudioRecorder = CopilotChatAudioRecorder;
|
|
1298
1275
|
_CopilotChatInput.Disclaimer = ({ className, ...props }) => {
|
|
1299
|
-
|
|
1300
|
-
const config = useCopilotChatConfiguration();
|
|
1301
|
-
const labels = (_config$labels5 = config === null || config === void 0 ? void 0 : config.labels) !== null && _config$labels5 !== void 0 ? _config$labels5 : CopilotChatDefaultLabels;
|
|
1276
|
+
const labels = useCopilotChatConfiguration()?.labels ?? CopilotChatDefaultLabels;
|
|
1302
1277
|
return /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
|
|
1303
1278
|
className: cn("cpk:text-center cpk:text-xs cpk:text-muted-foreground cpk:py-3 cpk:px-4 cpk:max-w-3xl cpk:mx-auto", className),
|
|
1304
1279
|
...props,
|
|
@@ -1339,7 +1314,6 @@ _radix_ui_react_dropdown_menu = __toESM(_radix_ui_react_dropdown_menu);
|
|
|
1339
1314
|
//#region src/v2/lib/react-core.ts
|
|
1340
1315
|
var CopilotKitCoreReact = class extends _copilotkit_core.CopilotKitCore {
|
|
1341
1316
|
constructor(config) {
|
|
1342
|
-
var _config$renderToolCal, _config$renderCustomM, _config$renderActivit;
|
|
1343
1317
|
super(config);
|
|
1344
1318
|
this._renderToolCalls = [];
|
|
1345
1319
|
this._hookRenderToolCalls = /* @__PURE__ */ new Map();
|
|
@@ -1347,9 +1321,9 @@ _radix_ui_react_dropdown_menu = __toESM(_radix_ui_react_dropdown_menu);
|
|
|
1347
1321
|
this._renderCustomMessages = [];
|
|
1348
1322
|
this._renderActivityMessages = [];
|
|
1349
1323
|
this._interruptElement = null;
|
|
1350
|
-
this._renderToolCalls =
|
|
1351
|
-
this._renderCustomMessages =
|
|
1352
|
-
this._renderActivityMessages =
|
|
1324
|
+
this._renderToolCalls = config.renderToolCalls ?? [];
|
|
1325
|
+
this._renderCustomMessages = config.renderCustomMessages ?? [];
|
|
1326
|
+
this._renderActivityMessages = config.renderActivityMessages ?? [];
|
|
1353
1327
|
}
|
|
1354
1328
|
get renderCustomMessages() {
|
|
1355
1329
|
return this._renderCustomMessages;
|
|
@@ -1361,10 +1335,7 @@ _radix_ui_react_dropdown_menu = __toESM(_radix_ui_react_dropdown_menu);
|
|
|
1361
1335
|
if (this._hookRenderToolCalls.size === 0) return this._renderToolCalls;
|
|
1362
1336
|
if (this._cachedMergedRenderToolCalls) return this._cachedMergedRenderToolCalls;
|
|
1363
1337
|
const merged = /* @__PURE__ */ new Map();
|
|
1364
|
-
for (const rc of this._renderToolCalls) {
|
|
1365
|
-
var _rc$agentId;
|
|
1366
|
-
merged.set(`${(_rc$agentId = rc.agentId) !== null && _rc$agentId !== void 0 ? _rc$agentId : ""}:${rc.name}`, rc);
|
|
1367
|
-
}
|
|
1338
|
+
for (const rc of this._renderToolCalls) merged.set(`${rc.agentId ?? ""}:${rc.name}`, rc);
|
|
1368
1339
|
for (const [key, rc] of this._hookRenderToolCalls) merged.set(key, rc);
|
|
1369
1340
|
this._cachedMergedRenderToolCalls = Array.from(merged.values());
|
|
1370
1341
|
return this._cachedMergedRenderToolCalls;
|
|
@@ -1381,14 +1352,13 @@ _radix_ui_react_dropdown_menu = __toESM(_radix_ui_react_dropdown_menu);
|
|
|
1381
1352
|
this._notifyRenderToolCallsChanged();
|
|
1382
1353
|
}
|
|
1383
1354
|
addHookRenderToolCall(entry) {
|
|
1384
|
-
|
|
1385
|
-
const key = `${(_entry$agentId = entry.agentId) !== null && _entry$agentId !== void 0 ? _entry$agentId : ""}:${entry.name}`;
|
|
1355
|
+
const key = `${entry.agentId ?? ""}:${entry.name}`;
|
|
1386
1356
|
this._hookRenderToolCalls.set(key, entry);
|
|
1387
1357
|
this._cachedMergedRenderToolCalls = null;
|
|
1388
1358
|
this._notifyRenderToolCallsChanged();
|
|
1389
1359
|
}
|
|
1390
1360
|
removeHookRenderToolCall(name, agentId) {
|
|
1391
|
-
const key = `${agentId
|
|
1361
|
+
const key = `${agentId ?? ""}:${name}`;
|
|
1392
1362
|
if (this._hookRenderToolCalls.delete(key)) {
|
|
1393
1363
|
this._cachedMergedRenderToolCalls = null;
|
|
1394
1364
|
this._notifyRenderToolCallsChanged();
|
|
@@ -1409,9 +1379,7 @@ _radix_ui_react_dropdown_menu = __toESM(_radix_ui_react_dropdown_menu);
|
|
|
1409
1379
|
setInterruptElement(element) {
|
|
1410
1380
|
this._interruptElement = element;
|
|
1411
1381
|
this.notifySubscribers((subscriber) => {
|
|
1412
|
-
|
|
1413
|
-
const reactSubscriber = subscriber;
|
|
1414
|
-
(_reactSubscriber$onIn = reactSubscriber.onInterruptElementChanged) === null || _reactSubscriber$onIn === void 0 || _reactSubscriber$onIn.call(reactSubscriber, {
|
|
1382
|
+
subscriber.onInterruptElementChanged?.({
|
|
1415
1383
|
copilotkit: this,
|
|
1416
1384
|
interruptElement: this._interruptElement
|
|
1417
1385
|
});
|
|
@@ -1521,7 +1489,7 @@ _radix_ui_react_dropdown_menu = __toESM(_radix_ui_react_dropdown_menu);
|
|
|
1521
1489
|
*/
|
|
1522
1490
|
function useRenderTool(config, deps) {
|
|
1523
1491
|
const { copilotkit } = useCopilotKit();
|
|
1524
|
-
const extraDeps = deps
|
|
1492
|
+
const extraDeps = deps ?? EMPTY_DEPS$1;
|
|
1525
1493
|
(0, react.useEffect)(() => {
|
|
1526
1494
|
const renderer = config.name === "*" && !config.parameters ? defineToolCallRenderer({
|
|
1527
1495
|
name: "*",
|
|
@@ -1550,6 +1518,47 @@ _radix_ui_react_dropdown_menu = __toESM(_radix_ui_react_dropdown_menu);
|
|
|
1550
1518
|
//#endregion
|
|
1551
1519
|
//#region src/v2/hooks/use-default-render-tool.tsx
|
|
1552
1520
|
/**
|
|
1521
|
+
* Module-level dedup set so an unknown status value only emits a console
|
|
1522
|
+
* warning the FIRST time we encounter it. Otherwise a stuck/unmapped status
|
|
1523
|
+
* would log on every re-render (potentially many per second).
|
|
1524
|
+
*/
|
|
1525
|
+
const warnedUnknownStatuses = /* @__PURE__ */ new Set();
|
|
1526
|
+
/**
|
|
1527
|
+
* Map a {@link ToolCallStatus} enum value to the documented string-union
|
|
1528
|
+
* status the {@link DefaultRenderProps} contract exposes. Unknown / future
|
|
1529
|
+
* enum members log a warning (once per distinct value) and fall back to
|
|
1530
|
+
* `"inProgress"`.
|
|
1531
|
+
*/
|
|
1532
|
+
function mapToolCallStatus(status) {
|
|
1533
|
+
switch (status) {
|
|
1534
|
+
case _copilotkit_core.ToolCallStatus.Complete: return "complete";
|
|
1535
|
+
case _copilotkit_core.ToolCallStatus.Executing: return "executing";
|
|
1536
|
+
case _copilotkit_core.ToolCallStatus.InProgress: return "inProgress";
|
|
1537
|
+
default: {
|
|
1538
|
+
const key = String(status);
|
|
1539
|
+
if (!warnedUnknownStatuses.has(key)) {
|
|
1540
|
+
warnedUnknownStatuses.add(key);
|
|
1541
|
+
console.warn(`[CopilotKit] Unknown ToolCallStatus "${key}" in default tool-call renderer; falling back to "inProgress".`);
|
|
1542
|
+
}
|
|
1543
|
+
return "inProgress";
|
|
1544
|
+
}
|
|
1545
|
+
}
|
|
1546
|
+
}
|
|
1547
|
+
/**
|
|
1548
|
+
* Convert the framework-internal renderer props (`args`, enum status) into
|
|
1549
|
+
* the documented {@link DefaultRenderProps} shape (`parameters`, string-union
|
|
1550
|
+
* status) so a user `config.render` always sees the documented contract.
|
|
1551
|
+
*/
|
|
1552
|
+
function adaptRendererProps(props) {
|
|
1553
|
+
return {
|
|
1554
|
+
name: props.name,
|
|
1555
|
+
toolCallId: props.toolCallId,
|
|
1556
|
+
parameters: props.args,
|
|
1557
|
+
status: mapToolCallStatus(props.status),
|
|
1558
|
+
result: props.result
|
|
1559
|
+
};
|
|
1560
|
+
}
|
|
1561
|
+
/**
|
|
1553
1562
|
* Registers a wildcard (`"*"`) tool-call renderer via `useRenderTool`.
|
|
1554
1563
|
*
|
|
1555
1564
|
* - Call with no config to use CopilotKit's built-in default tool-call card.
|
|
@@ -1586,17 +1595,33 @@ _radix_ui_react_dropdown_menu = __toESM(_radix_ui_react_dropdown_menu);
|
|
|
1586
1595
|
* ```
|
|
1587
1596
|
*/
|
|
1588
1597
|
function useDefaultRenderTool(config, deps) {
|
|
1589
|
-
|
|
1598
|
+
const userRender = config?.render;
|
|
1590
1599
|
useRenderTool({
|
|
1591
1600
|
name: "*",
|
|
1592
|
-
render:
|
|
1601
|
+
render: userRender ? (raw) => userRender(adaptRendererProps(raw)) : (raw) => /* @__PURE__ */ (0, react_jsx_runtime.jsx)(DefaultToolCallRenderer, { ...adaptRendererProps(raw) })
|
|
1593
1602
|
}, deps);
|
|
1594
1603
|
}
|
|
1595
|
-
|
|
1604
|
+
/**
|
|
1605
|
+
* Guarded JSON.stringify used inside the expanded `<pre>` blocks. A circular
|
|
1606
|
+
* reference would otherwise crash the entire React tree on render.
|
|
1607
|
+
*/
|
|
1608
|
+
function safeStringifyForPre(value) {
|
|
1609
|
+
try {
|
|
1610
|
+
return JSON.stringify(value, null, 2);
|
|
1611
|
+
} catch (err) {
|
|
1612
|
+
console.warn("[CopilotKit] Failed to JSON.stringify tool-call payload for default renderer; falling back to String():", err);
|
|
1613
|
+
try {
|
|
1614
|
+
return String(value);
|
|
1615
|
+
} catch (innerErr) {
|
|
1616
|
+
console.warn("[CopilotKit] safeStringifyForPre: value could not be stringified:", innerErr);
|
|
1617
|
+
return "[unserializable]";
|
|
1618
|
+
}
|
|
1619
|
+
}
|
|
1620
|
+
}
|
|
1621
|
+
function DefaultToolCallRenderer({ name, toolCallId, parameters, status, result }) {
|
|
1596
1622
|
const [isExpanded, setIsExpanded] = (0, react.useState)(false);
|
|
1597
|
-
const
|
|
1598
|
-
const
|
|
1599
|
-
const isComplete = statusString === "complete";
|
|
1623
|
+
const isActive = status === "inProgress" || status === "executing";
|
|
1624
|
+
const isComplete = status === "complete";
|
|
1600
1625
|
const statusLabel = isActive ? "Running" : isComplete ? "Done" : status;
|
|
1601
1626
|
const dotColor = isActive ? "#f59e0b" : isComplete ? "#10b981" : "#a1a1aa";
|
|
1602
1627
|
const badgeBg = isActive ? "#fef3c7" : isComplete ? "#d1fae5" : "#f4f4f5";
|
|
@@ -1604,7 +1629,8 @@ _radix_ui_react_dropdown_menu = __toESM(_radix_ui_react_dropdown_menu);
|
|
|
1604
1629
|
return /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
|
|
1605
1630
|
"data-testid": "copilot-tool-render",
|
|
1606
1631
|
"data-tool-name": name,
|
|
1607
|
-
"data-
|
|
1632
|
+
"data-tool-call-id": toolCallId,
|
|
1633
|
+
"data-status": status,
|
|
1608
1634
|
"data-args": safeStringifyForAttr(parameters),
|
|
1609
1635
|
"data-result": safeStringifyForAttr(result),
|
|
1610
1636
|
style: {
|
|
@@ -1618,7 +1644,9 @@ _radix_ui_react_dropdown_menu = __toESM(_radix_ui_react_dropdown_menu);
|
|
|
1618
1644
|
backgroundColor: "#fafafa",
|
|
1619
1645
|
padding: "14px 16px"
|
|
1620
1646
|
},
|
|
1621
|
-
children: [/* @__PURE__ */ (0, react_jsx_runtime.jsxs)("
|
|
1647
|
+
children: [/* @__PURE__ */ (0, react_jsx_runtime.jsxs)("button", {
|
|
1648
|
+
type: "button",
|
|
1649
|
+
"aria-expanded": isExpanded,
|
|
1622
1650
|
onClick: () => setIsExpanded(!isExpanded),
|
|
1623
1651
|
style: {
|
|
1624
1652
|
display: "flex",
|
|
@@ -1626,7 +1654,15 @@ _radix_ui_react_dropdown_menu = __toESM(_radix_ui_react_dropdown_menu);
|
|
|
1626
1654
|
justifyContent: "space-between",
|
|
1627
1655
|
gap: "10px",
|
|
1628
1656
|
cursor: "pointer",
|
|
1629
|
-
userSelect: "none"
|
|
1657
|
+
userSelect: "none",
|
|
1658
|
+
width: "100%",
|
|
1659
|
+
border: "none",
|
|
1660
|
+
padding: 0,
|
|
1661
|
+
margin: 0,
|
|
1662
|
+
background: "transparent",
|
|
1663
|
+
textAlign: "left",
|
|
1664
|
+
font: "inherit",
|
|
1665
|
+
color: "inherit"
|
|
1630
1666
|
},
|
|
1631
1667
|
children: [/* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
|
|
1632
1668
|
style: {
|
|
@@ -1719,7 +1755,7 @@ _radix_ui_react_dropdown_menu = __toESM(_radix_ui_react_dropdown_menu);
|
|
|
1719
1755
|
whiteSpace: "pre-wrap",
|
|
1720
1756
|
wordBreak: "break-word"
|
|
1721
1757
|
},
|
|
1722
|
-
children:
|
|
1758
|
+
children: safeStringifyForPre(parameters ?? {})
|
|
1723
1759
|
})] }), result !== void 0 && /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", { children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
|
|
1724
1760
|
style: {
|
|
1725
1761
|
fontSize: "10px",
|
|
@@ -1742,7 +1778,7 @@ _radix_ui_react_dropdown_menu = __toESM(_radix_ui_react_dropdown_menu);
|
|
|
1742
1778
|
whiteSpace: "pre-wrap",
|
|
1743
1779
|
wordBreak: "break-word"
|
|
1744
1780
|
},
|
|
1745
|
-
children: typeof result === "string" ? result :
|
|
1781
|
+
children: typeof result === "string" ? result : safeStringifyForPre(result)
|
|
1746
1782
|
})] })]
|
|
1747
1783
|
})]
|
|
1748
1784
|
})
|
|
@@ -1753,8 +1789,14 @@ _radix_ui_react_dropdown_menu = __toESM(_radix_ui_react_dropdown_menu);
|
|
|
1753
1789
|
if (typeof value === "string") return value;
|
|
1754
1790
|
try {
|
|
1755
1791
|
return JSON.stringify(value);
|
|
1756
|
-
} catch (
|
|
1757
|
-
|
|
1792
|
+
} catch (err) {
|
|
1793
|
+
console.warn("[CopilotKit] Failed to JSON.stringify tool-call payload for data-* attribute; falling back to String():", err);
|
|
1794
|
+
try {
|
|
1795
|
+
return String(value);
|
|
1796
|
+
} catch (innerErr) {
|
|
1797
|
+
console.warn("[CopilotKit] safeStringifyForAttr: value could not be stringified:", innerErr);
|
|
1798
|
+
return "";
|
|
1799
|
+
}
|
|
1758
1800
|
}
|
|
1759
1801
|
}
|
|
1760
1802
|
|
|
@@ -1790,11 +1832,10 @@ _radix_ui_react_dropdown_menu = __toESM(_radix_ui_react_dropdown_menu);
|
|
|
1790
1832
|
result: void 0
|
|
1791
1833
|
});
|
|
1792
1834
|
}, (prevProps, nextProps) => {
|
|
1793
|
-
var _prevProps$toolMessag, _nextProps$toolMessag;
|
|
1794
1835
|
if (prevProps.toolCall.id !== nextProps.toolCall.id) return false;
|
|
1795
1836
|
if (prevProps.toolCall.function.name !== nextProps.toolCall.function.name) return false;
|
|
1796
1837
|
if (prevProps.toolCall.function.arguments !== nextProps.toolCall.function.arguments) return false;
|
|
1797
|
-
if (
|
|
1838
|
+
if (prevProps.toolMessage?.content !== nextProps.toolMessage?.content) return false;
|
|
1798
1839
|
if (prevProps.isExecuting !== nextProps.isExecuting) return false;
|
|
1799
1840
|
if (prevProps.RenderComponent !== nextProps.RenderComponent) return false;
|
|
1800
1841
|
return true;
|
|
@@ -1806,21 +1847,17 @@ _radix_ui_react_dropdown_menu = __toESM(_radix_ui_react_dropdown_menu);
|
|
|
1806
1847
|
* @returns A function that takes a tool call and optional tool message and returns the rendered component
|
|
1807
1848
|
*/
|
|
1808
1849
|
function useRenderToolCall() {
|
|
1809
|
-
var _config$agentId;
|
|
1810
1850
|
const { copilotkit, executingToolCallIds } = useCopilotKit();
|
|
1811
|
-
const
|
|
1812
|
-
const agentId = (_config$agentId = config === null || config === void 0 ? void 0 : config.agentId) !== null && _config$agentId !== void 0 ? _config$agentId : _copilotkit_shared.DEFAULT_AGENT_ID;
|
|
1851
|
+
const agentId = useCopilotChatConfiguration()?.agentId ?? _copilotkit_shared.DEFAULT_AGENT_ID;
|
|
1813
1852
|
const renderToolCalls = (0, react.useSyncExternalStore)((callback) => {
|
|
1814
1853
|
return copilotkit.subscribe({ onRenderToolCallsChanged: callback }).unsubscribe;
|
|
1815
1854
|
}, () => copilotkit.renderToolCalls, () => copilotkit.renderToolCalls);
|
|
1816
1855
|
return (0, react.useCallback)(({ toolCall, toolMessage }) => {
|
|
1817
|
-
var _renderConfig$render;
|
|
1818
1856
|
const exactMatches = renderToolCalls.filter((rc) => rc.name === toolCall.function.name);
|
|
1819
|
-
const renderConfig = exactMatches.find((rc) => rc.agentId === agentId) || exactMatches.find((rc) => !rc.agentId) || exactMatches[0] || renderToolCalls.find((rc) => rc.name === "*");
|
|
1820
1857
|
return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(ToolCallRenderer, {
|
|
1821
1858
|
toolCall,
|
|
1822
1859
|
toolMessage,
|
|
1823
|
-
RenderComponent: (
|
|
1860
|
+
RenderComponent: (exactMatches.find((rc) => rc.agentId === agentId) || exactMatches.find((rc) => !rc.agentId) || exactMatches[0] || renderToolCalls.find((rc) => rc.name === "*"))?.render ?? defaultToolCallRenderAdapter,
|
|
1824
1861
|
isExecuting: executingToolCallIds.has(toolCall.id)
|
|
1825
1862
|
}, toolCall.id);
|
|
1826
1863
|
}, [
|
|
@@ -1830,11 +1867,11 @@ _radix_ui_react_dropdown_menu = __toESM(_radix_ui_react_dropdown_menu);
|
|
|
1830
1867
|
]);
|
|
1831
1868
|
}
|
|
1832
1869
|
function defaultToolCallRenderAdapter(props) {
|
|
1833
|
-
const status = props.status === _copilotkit_core.ToolCallStatus.Complete ? "complete" : props.status === _copilotkit_core.ToolCallStatus.Executing ? "executing" : "inProgress";
|
|
1834
1870
|
return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(DefaultToolCallRenderer, {
|
|
1835
1871
|
name: props.name,
|
|
1872
|
+
toolCallId: props.toolCallId,
|
|
1836
1873
|
parameters: props.args,
|
|
1837
|
-
status,
|
|
1874
|
+
status: mapToolCallStatus(props.status),
|
|
1838
1875
|
result: props.result
|
|
1839
1876
|
});
|
|
1840
1877
|
}
|
|
@@ -1846,8 +1883,7 @@ _radix_ui_react_dropdown_menu = __toESM(_radix_ui_react_dropdown_menu);
|
|
|
1846
1883
|
react.useEffect(() => {
|
|
1847
1884
|
let mounted = true;
|
|
1848
1885
|
import("@copilotkit/web-inspector").then((mod) => {
|
|
1849
|
-
|
|
1850
|
-
(_mod$defineWebInspect = mod.defineWebInspector) === null || _mod$defineWebInspect === void 0 || _mod$defineWebInspect.call(mod);
|
|
1886
|
+
mod.defineWebInspector?.();
|
|
1851
1887
|
const Component = (0, _lit_labs_react.createComponent)({
|
|
1852
1888
|
tagName: mod.WEB_INSPECTOR_TAG,
|
|
1853
1889
|
elementClass: mod.WebInspectorElement,
|
|
@@ -1862,7 +1898,7 @@ _radix_ui_react_dropdown_menu = __toESM(_radix_ui_react_dropdown_menu);
|
|
|
1862
1898
|
if (!InspectorComponent) return null;
|
|
1863
1899
|
return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(InspectorComponent, {
|
|
1864
1900
|
...rest,
|
|
1865
|
-
core: core
|
|
1901
|
+
core: core ?? null
|
|
1866
1902
|
});
|
|
1867
1903
|
};
|
|
1868
1904
|
CopilotKitInspector.displayName = "CopilotKitInspector";
|
|
@@ -2031,7 +2067,7 @@ _radix_ui_react_dropdown_menu = __toESM(_radix_ui_react_dropdown_menu);
|
|
|
2031
2067
|
function buildSandboxHTML(extraCspDomains) {
|
|
2032
2068
|
const baseScriptSrc = "'self' 'wasm-unsafe-eval' 'unsafe-inline' 'unsafe-eval' blob: data: http://localhost:* https://localhost:*";
|
|
2033
2069
|
const baseFrameSrc = "* blob: data: http://localhost:* https://localhost:*";
|
|
2034
|
-
const extra =
|
|
2070
|
+
const extra = extraCspDomains?.length ? " " + extraCspDomains.join(" ") : "";
|
|
2035
2071
|
return `<!doctype html>
|
|
2036
2072
|
<html>
|
|
2037
2073
|
<head>
|
|
@@ -2167,7 +2203,6 @@ window.parent.postMessage({jsonrpc:"2.0",method:"ui/notifications/sandbox-proxy-
|
|
|
2167
2203
|
* Fetches resource content on-demand via proxied MCP requests.
|
|
2168
2204
|
*/
|
|
2169
2205
|
const MCPAppsActivityRenderer = function MCPAppsActivityRenderer({ content, agent }) {
|
|
2170
|
-
var _fetchedResource$_met2;
|
|
2171
2206
|
const { copilotkit } = useCopilotKit();
|
|
2172
2207
|
const containerRef = (0, react.useRef)(null);
|
|
2173
2208
|
const iframeRef = (0, react.useRef)(null);
|
|
@@ -2186,8 +2221,7 @@ window.parent.postMessage({jsonrpc:"2.0",method:"ui/notifications/sandbox-proxy-
|
|
|
2186
2221
|
resourceUri: null
|
|
2187
2222
|
});
|
|
2188
2223
|
const sendToIframe = (0, react.useCallback)((msg) => {
|
|
2189
|
-
|
|
2190
|
-
if ((_iframeRef$current = iframeRef.current) === null || _iframeRef$current === void 0 ? void 0 : _iframeRef$current.contentWindow) {
|
|
2224
|
+
if (iframeRef.current?.contentWindow) {
|
|
2191
2225
|
console.log("[MCPAppsRenderer] Sending to iframe:", msg);
|
|
2192
2226
|
iframeRef.current.contentWindow.postMessage(msg, "*");
|
|
2193
2227
|
}
|
|
@@ -2219,8 +2253,7 @@ window.parent.postMessage({jsonrpc:"2.0",method:"ui/notifications/sandbox-proxy-
|
|
|
2219
2253
|
(0, react.useEffect)(() => {
|
|
2220
2254
|
const { resourceUri, serverHash, serverId } = content;
|
|
2221
2255
|
if (fetchStateRef.current.inProgress && fetchStateRef.current.resourceUri === resourceUri) {
|
|
2222
|
-
|
|
2223
|
-
(_fetchStateRef$curren = fetchStateRef.current.promise) === null || _fetchStateRef$curren === void 0 || _fetchStateRef$curren.then((resource) => {
|
|
2256
|
+
fetchStateRef.current.promise?.then((resource) => {
|
|
2224
2257
|
if (resource) {
|
|
2225
2258
|
setFetchedResource(resource);
|
|
2226
2259
|
setIsLoading(false);
|
|
@@ -2240,14 +2273,12 @@ window.parent.postMessage({jsonrpc:"2.0",method:"ui/notifications/sandbox-proxy-
|
|
|
2240
2273
|
fetchStateRef.current.resourceUri = resourceUri;
|
|
2241
2274
|
const fetchPromise = (async () => {
|
|
2242
2275
|
try {
|
|
2243
|
-
|
|
2244
|
-
const resultData = (await mcpAppsRequestQueue.enqueue(agent, () => agent.runAgent({ forwardedProps: { __proxiedMCPRequest: {
|
|
2276
|
+
const resource = (await mcpAppsRequestQueue.enqueue(agent, () => agent.runAgent({ forwardedProps: { __proxiedMCPRequest: {
|
|
2245
2277
|
serverHash,
|
|
2246
2278
|
serverId,
|
|
2247
2279
|
method: "resources/read",
|
|
2248
2280
|
params: { uri: resourceUri }
|
|
2249
|
-
} } }))).result;
|
|
2250
|
-
const resource = resultData === null || resultData === void 0 || (_resultData$contents = resultData.contents) === null || _resultData$contents === void 0 ? void 0 : _resultData$contents[0];
|
|
2281
|
+
} } }))).result?.contents?.[0];
|
|
2251
2282
|
if (!resource) throw new Error("No resource content in response");
|
|
2252
2283
|
return resource;
|
|
2253
2284
|
} catch (err) {
|
|
@@ -2278,7 +2309,6 @@ window.parent.postMessage({jsonrpc:"2.0",method:"ui/notifications/sandbox-proxy-
|
|
|
2278
2309
|
let createdIframe = null;
|
|
2279
2310
|
const setup = async () => {
|
|
2280
2311
|
try {
|
|
2281
|
-
var _fetchedResource$_met;
|
|
2282
2312
|
const iframe = document.createElement("iframe");
|
|
2283
2313
|
createdIframe = iframe;
|
|
2284
2314
|
iframe.style.width = "100%";
|
|
@@ -2290,8 +2320,7 @@ window.parent.postMessage({jsonrpc:"2.0",method:"ui/notifications/sandbox-proxy-
|
|
|
2290
2320
|
const sandboxReady = new Promise((resolve) => {
|
|
2291
2321
|
initialListener = (event) => {
|
|
2292
2322
|
if (event.source === iframe.contentWindow) {
|
|
2293
|
-
|
|
2294
|
-
if (((_event$data = event.data) === null || _event$data === void 0 ? void 0 : _event$data.method) === "ui/notifications/sandbox-proxy-ready") {
|
|
2323
|
+
if (event.data?.method === "ui/notifications/sandbox-proxy-ready") {
|
|
2295
2324
|
if (initialListener) {
|
|
2296
2325
|
window.removeEventListener("message", initialListener);
|
|
2297
2326
|
initialListener = null;
|
|
@@ -2309,7 +2338,8 @@ window.parent.postMessage({jsonrpc:"2.0",method:"ui/notifications/sandbox-proxy-
|
|
|
2309
2338
|
}
|
|
2310
2339
|
return;
|
|
2311
2340
|
}
|
|
2312
|
-
|
|
2341
|
+
const cspDomains = fetchedResource._meta?.ui?.csp?.resourceDomains;
|
|
2342
|
+
iframe.srcdoc = buildSandboxHTML(cspDomains);
|
|
2313
2343
|
iframeRef.current = iframe;
|
|
2314
2344
|
container.appendChild(iframe);
|
|
2315
2345
|
await sandboxReady;
|
|
@@ -2346,17 +2376,16 @@ window.parent.postMessage({jsonrpc:"2.0",method:"ui/notifications/sandbox-proxy-
|
|
|
2346
2376
|
break;
|
|
2347
2377
|
}
|
|
2348
2378
|
try {
|
|
2349
|
-
var _params$content, _params$followUp;
|
|
2350
2379
|
const params = msg.params;
|
|
2351
2380
|
const role = params.role || "user";
|
|
2352
|
-
const textContent =
|
|
2381
|
+
const textContent = params.content?.filter((c) => c.type === "text" && c.text).map((c) => c.text).join("\n") || "";
|
|
2353
2382
|
if (textContent) currentAgent.addMessage({
|
|
2354
2383
|
id: crypto.randomUUID(),
|
|
2355
2384
|
role,
|
|
2356
2385
|
content: textContent
|
|
2357
2386
|
});
|
|
2358
2387
|
sendResponse(msg.id, { isError: false });
|
|
2359
|
-
if ((
|
|
2388
|
+
if ((params.followUp ?? role === "user") && textContent) mcpAppsRequestQueue.enqueue(currentAgent, () => copilotkit.runAgent({ agent: currentAgent })).catch((err) => console.error("[MCPAppsRenderer] ui/message agent run failed:", err));
|
|
2360
2389
|
} catch (err) {
|
|
2361
2390
|
console.error("[MCPAppsRenderer] ui/message error:", err);
|
|
2362
2391
|
sendResponse(msg.id, { isError: true });
|
|
@@ -2364,8 +2393,7 @@ window.parent.postMessage({jsonrpc:"2.0",method:"ui/notifications/sandbox-proxy-
|
|
|
2364
2393
|
break;
|
|
2365
2394
|
}
|
|
2366
2395
|
case "ui/open-link": {
|
|
2367
|
-
|
|
2368
|
-
const url = (_msg$params = msg.params) === null || _msg$params === void 0 ? void 0 : _msg$params.url;
|
|
2396
|
+
const url = msg.params?.url;
|
|
2369
2397
|
if (url) {
|
|
2370
2398
|
window.open(url, "_blank", "noopener,noreferrer");
|
|
2371
2399
|
sendResponse(msg.id, { isError: false });
|
|
@@ -2482,7 +2510,7 @@ window.parent.postMessage({jsonrpc:"2.0",method:"ui/notifications/sandbox-proxy-
|
|
|
2482
2510
|
content.result,
|
|
2483
2511
|
sendNotification
|
|
2484
2512
|
]);
|
|
2485
|
-
const borderStyle =
|
|
2513
|
+
const borderStyle = fetchedResource?._meta?.ui?.prefersBorder === true ? {
|
|
2486
2514
|
borderRadius: "8px",
|
|
2487
2515
|
backgroundColor: "#f9f9f9",
|
|
2488
2516
|
border: "1px solid #e0e0e0"
|
|
@@ -2588,13 +2616,12 @@ window.parent.postMessage({jsonrpc:"2.0",method:"ui/notifications/sandbox-proxy-
|
|
|
2588
2616
|
* (no throttle delay).
|
|
2589
2617
|
*/
|
|
2590
2618
|
function shouldFlushImmediately(prev, next) {
|
|
2591
|
-
var _next$jsExpressions$l, _next$jsExpressions, _prev$jsExpressions$l, _prev$jsExpressions, _next$html, _prev$html;
|
|
2592
2619
|
if (next.cssComplete && (!prev || !prev.cssComplete)) return true;
|
|
2593
2620
|
if (next.htmlComplete) return true;
|
|
2594
2621
|
if (next.generating === false) return true;
|
|
2595
2622
|
if (next.jsFunctions && (!prev || !prev.jsFunctions)) return true;
|
|
2596
|
-
if ((
|
|
2597
|
-
if (
|
|
2623
|
+
if ((next.jsExpressions?.length ?? 0) > (prev?.jsExpressions?.length ?? 0)) return true;
|
|
2624
|
+
if (next.html?.length && (!prev || !prev.html?.length)) return true;
|
|
2598
2625
|
return false;
|
|
2599
2626
|
}
|
|
2600
2627
|
/**
|
|
@@ -2644,8 +2671,7 @@ window.parent.postMessage({jsonrpc:"2.0",method:"ui/notifications/sandbox-proxy-
|
|
|
2644
2671
|
return `<head><style>${css}</style></head>${html}`;
|
|
2645
2672
|
}
|
|
2646
2673
|
const OpenGenerativeUIActivityRendererInner = react.default.memo(function OpenGenerativeUIActivityRendererInner({ content }) {
|
|
2647
|
-
|
|
2648
|
-
const initialHeight = (_content$initialHeigh = content.initialHeight) !== null && _content$initialHeigh !== void 0 ? _content$initialHeigh : 200;
|
|
2674
|
+
const initialHeight = content.initialHeight ?? 200;
|
|
2649
2675
|
const [autoHeight, setAutoHeight] = (0, react.useState)(null);
|
|
2650
2676
|
const sandboxFunctions = useSandboxFunctions();
|
|
2651
2677
|
const localApi = (0, react.useMemo)(() => {
|
|
@@ -2653,13 +2679,13 @@ window.parent.postMessage({jsonrpc:"2.0",method:"ui/notifications/sandbox-proxy-
|
|
|
2653
2679
|
for (const fn of sandboxFunctions) api[fn.name] = fn.handler;
|
|
2654
2680
|
return api;
|
|
2655
2681
|
}, [sandboxFunctions]);
|
|
2656
|
-
const fullHtml = content.htmlComplete &&
|
|
2682
|
+
const fullHtml = content.htmlComplete && content.html?.length ? content.html.join("") : void 0;
|
|
2657
2683
|
const css = content.cssComplete ? content.css : void 0;
|
|
2658
2684
|
const cssReady = !!content.cssComplete;
|
|
2659
|
-
const partialHtml = !content.htmlComplete &&
|
|
2685
|
+
const partialHtml = !content.htmlComplete && content.html?.length ? content.html.join("") : void 0;
|
|
2660
2686
|
const previewBody = partialHtml ? processPartialHtml(partialHtml) : void 0;
|
|
2661
2687
|
const previewStyles = partialHtml ? extractCompleteStyles(partialHtml) : "";
|
|
2662
|
-
const hasPreview = cssReady && !!
|
|
2688
|
+
const hasPreview = cssReady && !!previewBody?.trim();
|
|
2663
2689
|
const hasVisibleSandbox = !!fullHtml || hasPreview;
|
|
2664
2690
|
const containerRef = (0, react.useRef)(null);
|
|
2665
2691
|
const sandboxRef = (0, react.useRef)(null);
|
|
@@ -2674,9 +2700,8 @@ window.parent.postMessage({jsonrpc:"2.0",method:"ui/notifications/sandbox-proxy-
|
|
|
2674
2700
|
if (!container || fullHtml || !hasPreview || previewSandboxRef.current) return;
|
|
2675
2701
|
let cancelled = false;
|
|
2676
2702
|
import("@jetbrains/websandbox").then((mod) => {
|
|
2677
|
-
var _mod$default$default, _mod$default;
|
|
2678
2703
|
if (cancelled) return;
|
|
2679
|
-
const sandbox = (
|
|
2704
|
+
const sandbox = (mod.default?.default ?? mod.default).create({}, {
|
|
2680
2705
|
frameContainer: container,
|
|
2681
2706
|
frameContent: "<head></head><body></body>",
|
|
2682
2707
|
allowAdditionalAttributes: ""
|
|
@@ -2735,9 +2760,8 @@ window.parent.postMessage({jsonrpc:"2.0",method:"ui/notifications/sandbox-proxy-
|
|
|
2735
2760
|
pendingQueueRef.current = [];
|
|
2736
2761
|
const htmlContent = css ? injectCssIntoHtml(fullHtml, css) : fullHtml;
|
|
2737
2762
|
import("@jetbrains/websandbox").then((mod) => {
|
|
2738
|
-
var _mod$default$default2, _mod$default2;
|
|
2739
2763
|
if (cancelled) return;
|
|
2740
|
-
const sandbox = (
|
|
2764
|
+
const sandbox = (mod.default?.default ?? mod.default).create(localApi, {
|
|
2741
2765
|
frameContainer: container,
|
|
2742
2766
|
frameContent: ensureHead(htmlContent),
|
|
2743
2767
|
allowAdditionalAttributes: ""
|
|
@@ -2800,16 +2824,15 @@ window.parent.postMessage({jsonrpc:"2.0",method:"ui/notifications/sandbox-proxy-
|
|
|
2800
2824
|
for (const expr of newExprs) await sandbox.run(expr);
|
|
2801
2825
|
})();
|
|
2802
2826
|
else pendingQueueRef.current.push(...newExprs);
|
|
2803
|
-
}, [
|
|
2827
|
+
}, [content.jsExpressions?.length]);
|
|
2804
2828
|
const generationDone = content.generating === false;
|
|
2805
2829
|
(0, react.useEffect)(() => {
|
|
2806
2830
|
const sandbox = sandboxRef.current;
|
|
2807
2831
|
if (!generationDone || !sandbox) return;
|
|
2808
2832
|
let handled = false;
|
|
2809
2833
|
const onMessage = (e) => {
|
|
2810
|
-
var _e$data;
|
|
2811
2834
|
if (handled) return;
|
|
2812
|
-
if (e.source === sandbox.iframe.contentWindow &&
|
|
2835
|
+
if (e.source === sandbox.iframe.contentWindow && e.data?.type === "__ck_resize") {
|
|
2813
2836
|
handled = true;
|
|
2814
2837
|
setAutoHeight(e.data.height);
|
|
2815
2838
|
window.removeEventListener("message", onMessage);
|
|
@@ -2835,7 +2858,7 @@ window.parent.postMessage({jsonrpc:"2.0",method:"ui/notifications/sandbox-proxy-
|
|
|
2835
2858
|
window.removeEventListener("message", onMessage);
|
|
2836
2859
|
};
|
|
2837
2860
|
}, [generationDone]);
|
|
2838
|
-
const height = autoHeight
|
|
2861
|
+
const height = autoHeight ?? initialHeight;
|
|
2839
2862
|
const isGenerating = content.generating !== false;
|
|
2840
2863
|
return /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
|
|
2841
2864
|
ref: containerRef,
|
|
@@ -2889,7 +2912,6 @@ window.parent.postMessage({jsonrpc:"2.0",method:"ui/notifications/sandbox-proxy-
|
|
|
2889
2912
|
* Displays placeholder messages while the UI is being generated.
|
|
2890
2913
|
*/
|
|
2891
2914
|
const OpenGenerativeUIToolRenderer = function OpenGenerativeUIToolRenderer(props) {
|
|
2892
|
-
var _messages$visibleMess;
|
|
2893
2915
|
const [visibleMessageIndex, setVisibleMessageIndex] = (0, react.useState)(0);
|
|
2894
2916
|
const prevMessageCountRef = (0, react.useRef)(0);
|
|
2895
2917
|
const messages = props.args.placeholderMessages;
|
|
@@ -2904,7 +2926,7 @@ window.parent.postMessage({jsonrpc:"2.0",method:"ui/notifications/sandbox-proxy-
|
|
|
2904
2926
|
setVisibleMessageIndex((i) => (i + 1) % messages.length);
|
|
2905
2927
|
}, 5e3);
|
|
2906
2928
|
return () => clearInterval(timer);
|
|
2907
|
-
}, [messages
|
|
2929
|
+
}, [messages?.length, props.status]);
|
|
2908
2930
|
if (props.status === _copilotkit_core.ToolCallStatus.Complete) return null;
|
|
2909
2931
|
if (!messages || messages.length === 0) return null;
|
|
2910
2932
|
return /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
|
|
@@ -2913,7 +2935,7 @@ window.parent.postMessage({jsonrpc:"2.0",method:"ui/notifications/sandbox-proxy-
|
|
|
2913
2935
|
color: "#999",
|
|
2914
2936
|
fontSize: "14px"
|
|
2915
2937
|
},
|
|
2916
|
-
children:
|
|
2938
|
+
children: messages[visibleMessageIndex] ?? messages[0]
|
|
2917
2939
|
});
|
|
2918
2940
|
};
|
|
2919
2941
|
|
|
@@ -2945,7 +2967,7 @@ window.parent.postMessage({jsonrpc:"2.0",method:"ui/notifications/sandbox-proxy-
|
|
|
2945
2967
|
(0, react.useEffect)(() => {
|
|
2946
2968
|
if (content === lastContentRef.current) return;
|
|
2947
2969
|
lastContentRef.current = content;
|
|
2948
|
-
const incoming = content
|
|
2970
|
+
const incoming = content?.[A2UI_OPERATIONS_KEY];
|
|
2949
2971
|
if (!content || !Array.isArray(incoming)) {
|
|
2950
2972
|
setOperations([]);
|
|
2951
2973
|
return;
|
|
@@ -2955,14 +2977,13 @@ window.parent.postMessage({jsonrpc:"2.0",method:"ui/notifications/sandbox-proxy-
|
|
|
2955
2977
|
const groupedOperations = (0, react.useMemo)(() => {
|
|
2956
2978
|
const groups = /* @__PURE__ */ new Map();
|
|
2957
2979
|
for (const operation of operations) {
|
|
2958
|
-
|
|
2959
|
-
const surfaceId = (_getOperationSurfaceI = getOperationSurfaceId(operation)) !== null && _getOperationSurfaceI !== void 0 ? _getOperationSurfaceI : _copilotkit_a2ui_renderer.DEFAULT_SURFACE_ID;
|
|
2980
|
+
const surfaceId = getOperationSurfaceId(operation) ?? _copilotkit_a2ui_renderer.DEFAULT_SURFACE_ID;
|
|
2960
2981
|
if (!groups.has(surfaceId)) groups.set(surfaceId, []);
|
|
2961
2982
|
groups.get(surfaceId).push(operation);
|
|
2962
2983
|
}
|
|
2963
2984
|
return groups;
|
|
2964
2985
|
}, [operations]);
|
|
2965
|
-
if (!groupedOperations.size) return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(loadingComponent
|
|
2986
|
+
if (!groupedOperations.size) return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(loadingComponent ?? DefaultA2UILoading, {});
|
|
2966
2987
|
return /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
|
|
2967
2988
|
className: "cpk:flex cpk:min-h-0 cpk:flex-1 cpk:flex-col cpk:gap-6 cpk:overflow-auto cpk:py-6",
|
|
2968
2989
|
children: Array.from(groupedOperations.entries()).map(([surfaceId, ops]) => /* @__PURE__ */ (0, react_jsx_runtime.jsx)(ReactSurfaceHost, {
|
|
@@ -3036,7 +3057,7 @@ window.parent.postMessage({jsonrpc:"2.0",method:"ui/notifications/sandbox-proxy-
|
|
|
3036
3057
|
const hash = JSON.stringify(operations);
|
|
3037
3058
|
if (hash === lastHashRef.current) return;
|
|
3038
3059
|
lastHashRef.current = hash;
|
|
3039
|
-
processMessages(getSurface(surfaceId) ? operations.filter((op) => !
|
|
3060
|
+
processMessages(getSurface(surfaceId) ? operations.filter((op) => !op?.createSurface) : operations);
|
|
3040
3061
|
}, [
|
|
3041
3062
|
processMessages,
|
|
3042
3063
|
getSurface,
|
|
@@ -3088,10 +3109,9 @@ window.parent.postMessage({jsonrpc:"2.0",method:"ui/notifications/sandbox-proxy-
|
|
|
3088
3109
|
});
|
|
3089
3110
|
}
|
|
3090
3111
|
function getOperationSurfaceId(operation) {
|
|
3091
|
-
var _ref, _ref2, _ref3, _operation$createSurf, _operation$createSurf2, _operation$updateComp, _operation$updateData, _operation$deleteSurf;
|
|
3092
3112
|
if (!operation || typeof operation !== "object") return null;
|
|
3093
3113
|
if (typeof operation.surfaceId === "string") return operation.surfaceId;
|
|
3094
|
-
return
|
|
3114
|
+
return operation?.createSurface?.surfaceId ?? operation?.updateComponents?.surfaceId ?? operation?.updateDataModel?.surfaceId ?? operation?.deleteSurface?.surfaceId ?? null;
|
|
3095
3115
|
}
|
|
3096
3116
|
|
|
3097
3117
|
//#endregion
|
|
@@ -3116,7 +3136,7 @@ window.parent.postMessage({jsonrpc:"2.0",method:"ui/notifications/sandbox-proxy-
|
|
|
3116
3136
|
const now = Date.now();
|
|
3117
3137
|
let { tokens } = lastRef.current;
|
|
3118
3138
|
if (now - lastRef.current.time > 200) {
|
|
3119
|
-
const chars = JSON.stringify(parameters
|
|
3139
|
+
const chars = JSON.stringify(parameters ?? {}).length;
|
|
3120
3140
|
tokens = Math.round(chars / 4);
|
|
3121
3141
|
lastRef.current = {
|
|
3122
3142
|
time: now,
|
|
@@ -3404,21 +3424,20 @@ window.parent.postMessage({jsonrpc:"2.0",method:"ui/notifications/sandbox-proxy-
|
|
|
3404
3424
|
function A2UIBuiltInToolCallRenderer() {
|
|
3405
3425
|
const { copilotkit } = useCopilotKit();
|
|
3406
3426
|
(0, react.useEffect)(() => {
|
|
3407
|
-
var _renderToolCalls;
|
|
3408
3427
|
const renderer = defineToolCallRenderer({
|
|
3409
3428
|
name: RENDER_A2UI_TOOL_NAME,
|
|
3410
3429
|
args: zod.z.any(),
|
|
3411
3430
|
render: ({ status, args: parameters }) => {
|
|
3412
3431
|
if (status === "complete") return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(react_jsx_runtime.Fragment, {});
|
|
3413
3432
|
const params = parameters;
|
|
3414
|
-
const items = params
|
|
3433
|
+
const items = params?.items;
|
|
3415
3434
|
if (Array.isArray(items) && items.length > 0) return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(react_jsx_runtime.Fragment, {});
|
|
3416
|
-
const components = params
|
|
3435
|
+
const components = params?.components;
|
|
3417
3436
|
if (Array.isArray(components) && components.length > 2) return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(react_jsx_runtime.Fragment, {});
|
|
3418
3437
|
return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(A2UIProgressIndicator, { parameters });
|
|
3419
3438
|
}
|
|
3420
3439
|
});
|
|
3421
|
-
const existing =
|
|
3440
|
+
const existing = copilotkit._renderToolCalls ?? [];
|
|
3422
3441
|
copilotkit.setRenderToolCalls([...existing.filter((rc) => rc.name !== RENDER_A2UI_TOOL_NAME), renderer]);
|
|
3423
3442
|
}, [copilotkit]);
|
|
3424
3443
|
return null;
|
|
@@ -3492,6 +3511,9 @@ window.parent.postMessage({jsonrpc:"2.0",method:"ui/notifications/sandbox-proxy-
|
|
|
3492
3511
|
//#region src/v2/providers/CopilotKitProvider.tsx
|
|
3493
3512
|
const HEADER_NAME = "X-CopilotCloud-Public-Api-Key";
|
|
3494
3513
|
const COPILOT_CLOUD_CHAT_URL$1 = "https://api.cloud.copilotkit.ai/copilotkit/v1";
|
|
3514
|
+
const EMPTY_HEADERS = Object.freeze({});
|
|
3515
|
+
const EMPTY_PROPERTIES = Object.freeze({});
|
|
3516
|
+
const EMPTY_AGENTS = Object.freeze({});
|
|
3495
3517
|
const DEFAULT_DESIGN_SKILL = `When generating UI with generateSandboxedUi, follow these design principles inspired by shadcn/ui:
|
|
3496
3518
|
|
|
3497
3519
|
- Use a minimal, flat aesthetic. Avoid drop shadows and gradients — rely on subtle borders (1px solid, light gray like #e5e7eb) to define surfaces.
|
|
@@ -3505,15 +3527,14 @@ window.parent.postMessage({jsonrpc:"2.0",method:"ui/notifications/sandbox-proxy-
|
|
|
3505
3527
|
const GENERATE_SANDBOXED_UI_DESCRIPTION = "Generate sandboxed UI. IMPORTANT: The generated code runs in a sandboxed iframe WITHOUT same-origin access. Do NOT use localStorage, sessionStorage, document.cookie, IndexedDB, or fetch/XMLHttpRequest to same-origin URLs. To communicate with the host application, use Websandbox.connection.remote.<functionName>(args) which returns a Promise.\n\nYou CAN use external libraries from CDNs by including <script> or <link> tags in the HTML <head> (e.g., Chart.js, D3, Three.js, x-data-spreadsheet, etc.). CDN resources load normally inside the sandbox.\n\nPARAMETER ORDER IS CRITICAL — generate parameters in exactly this order:\n1. initialHeight + placeholderMessages (shown to user while generating)\n2. css (all styles FIRST — the user sees a placeholder until CSS is complete)\n3. html (streams in live — the user watches the UI build as HTML is generated)\n4. jsFunctions (reusable helper functions)\n5. jsExpressions (applied one-by-one — the user sees each expression take effect)";
|
|
3506
3528
|
function useStableArrayProp(prop, warningMessage, isMeaningfulChange) {
|
|
3507
3529
|
const empty = (0, react.useMemo)(() => [], []);
|
|
3508
|
-
const value = prop
|
|
3530
|
+
const value = prop ?? empty;
|
|
3509
3531
|
const initial = (0, react.useRef)(value);
|
|
3510
3532
|
(0, react.useEffect)(() => {
|
|
3511
3533
|
if (warningMessage && value !== initial.current && (isMeaningfulChange ? isMeaningfulChange(initial.current, value) : true)) console.error(warningMessage);
|
|
3512
3534
|
}, [value, warningMessage]);
|
|
3513
3535
|
return value;
|
|
3514
3536
|
}
|
|
3515
|
-
const CopilotKitProvider = ({ children, runtimeUrl, headers: headersProp =
|
|
3516
|
-
var _openGenerativeUI$des;
|
|
3537
|
+
const CopilotKitProvider = ({ children, runtimeUrl, headers: headersProp = EMPTY_HEADERS, credentials, publicApiKey, publicLicenseKey, licenseToken, properties = EMPTY_PROPERTIES, agents__unsafe_dev_only: agents = EMPTY_AGENTS, selfManagedAgents = EMPTY_AGENTS, renderToolCalls, renderActivityMessages, renderCustomMessages, frontendTools, humanInTheLoop, openGenerativeUI, showDevConsole = false, useSingleEndpoint, onError, a2ui, defaultThrottleMs, inspectorDefaultAnchor, debug }) => {
|
|
3517
3538
|
const [shouldRenderInspector, setShouldRenderInspector] = (0, react.useState)(false);
|
|
3518
3539
|
const [runtimeA2UIEnabled, setRuntimeA2UIEnabled] = (0, react.useState)(false);
|
|
3519
3540
|
const [runtimeOpenGenUIEnabled, setRuntimeOpenGenUIEnabled] = (0, react.useState)(false);
|
|
@@ -3527,10 +3548,7 @@ window.parent.postMessage({jsonrpc:"2.0",method:"ui/notifications/sandbox-proxy-
|
|
|
3527
3548
|
else setShouldRenderInspector(false);
|
|
3528
3549
|
}, [showDevConsole]);
|
|
3529
3550
|
const renderToolCallsList = useStableArrayProp(renderToolCalls, "renderToolCalls must be a stable array. If you want to dynamically add or remove tools, use `useFrontendTool` instead.", (initial, next) => {
|
|
3530
|
-
const key = (rc) => {
|
|
3531
|
-
var _rc$agentId, _rc$name;
|
|
3532
|
-
return `${(_rc$agentId = rc === null || rc === void 0 ? void 0 : rc.agentId) !== null && _rc$agentId !== void 0 ? _rc$agentId : ""}:${(_rc$name = rc === null || rc === void 0 ? void 0 : rc.name) !== null && _rc$name !== void 0 ? _rc$name : ""}`;
|
|
3533
|
-
};
|
|
3551
|
+
const key = (rc) => `${rc?.agentId ?? ""}:${rc?.name ?? ""}`;
|
|
3534
3552
|
const setFrom = (arr) => new Set(arr.map(key));
|
|
3535
3553
|
const a = setFrom(initial);
|
|
3536
3554
|
const b = setFrom(next);
|
|
@@ -3551,14 +3569,11 @@ window.parent.postMessage({jsonrpc:"2.0",method:"ui/notifications/sandbox-proxy-
|
|
|
3551
3569
|
content: OpenGenerativeUIContentSchema,
|
|
3552
3570
|
render: OpenGenerativeUIActivityRenderer
|
|
3553
3571
|
});
|
|
3554
|
-
if (runtimeA2UIEnabled) {
|
|
3555
|
-
|
|
3556
|
-
|
|
3557
|
-
|
|
3558
|
-
|
|
3559
|
-
loadingComponent: a2ui === null || a2ui === void 0 ? void 0 : a2ui.loadingComponent
|
|
3560
|
-
}));
|
|
3561
|
-
}
|
|
3572
|
+
if (runtimeA2UIEnabled) renderers.unshift(createA2UIMessageRenderer({
|
|
3573
|
+
theme: a2ui?.theme ?? _copilotkit_a2ui_renderer.viewerTheme,
|
|
3574
|
+
catalog: a2ui?.catalog,
|
|
3575
|
+
loadingComponent: a2ui?.loadingComponent
|
|
3576
|
+
}));
|
|
3562
3577
|
return renderers;
|
|
3563
3578
|
}, [
|
|
3564
3579
|
runtimeA2UIEnabled,
|
|
@@ -3568,7 +3583,7 @@ window.parent.postMessage({jsonrpc:"2.0",method:"ui/notifications/sandbox-proxy-
|
|
|
3568
3583
|
const allActivityRenderers = (0, react.useMemo)(() => {
|
|
3569
3584
|
return [...renderActivityMessagesList, ...builtInActivityRenderers];
|
|
3570
3585
|
}, [renderActivityMessagesList, builtInActivityRenderers]);
|
|
3571
|
-
const resolvedPublicKey = publicApiKey
|
|
3586
|
+
const resolvedPublicKey = publicApiKey ?? publicLicenseKey;
|
|
3572
3587
|
const mergedAgents = (0, react.useMemo)(() => ({
|
|
3573
3588
|
...agents,
|
|
3574
3589
|
...selfManagedAgents
|
|
@@ -3588,10 +3603,10 @@ window.parent.postMessage({jsonrpc:"2.0",method:"ui/notifications/sandbox-proxy-
|
|
|
3588
3603
|
if (process.env.NODE_ENV === "production") throw new Error(message);
|
|
3589
3604
|
else console.warn(message);
|
|
3590
3605
|
}
|
|
3591
|
-
const chatApiEndpoint = runtimeUrl
|
|
3606
|
+
const chatApiEndpoint = runtimeUrl ?? (resolvedPublicKey ? COPILOT_CLOUD_CHAT_URL$1 : void 0);
|
|
3592
3607
|
const frontendToolsList = useStableArrayProp(frontendTools, "frontendTools must be a stable array. If you want to dynamically add or remove tools, use `useFrontendTool` instead.");
|
|
3593
3608
|
const humanInTheLoopList = useStableArrayProp(humanInTheLoop, "humanInTheLoop must be a stable array. If you want to dynamically add or remove human-in-the-loop tools, use `useHumanInTheLoop` instead.");
|
|
3594
|
-
const sandboxFunctionsList = useStableArrayProp(openGenerativeUI
|
|
3609
|
+
const sandboxFunctionsList = useStableArrayProp(openGenerativeUI?.sandboxFunctions, "openGenerativeUI.sandboxFunctions must be a stable array.");
|
|
3595
3610
|
const processedHumanInTheLoopTools = (0, react.useMemo)(() => {
|
|
3596
3611
|
const processedTools = [];
|
|
3597
3612
|
const processedRenderToolCalls = [];
|
|
@@ -3733,10 +3748,7 @@ window.parent.postMessage({jsonrpc:"2.0",method:"ui/notifications/sandbox-proxy-
|
|
|
3733
3748
|
(0, react.useEffect)(() => {
|
|
3734
3749
|
const subscription = copilotkit.subscribe({ onError: (event) => {
|
|
3735
3750
|
if (onErrorRef.current) onErrorRef.current(event);
|
|
3736
|
-
else {
|
|
3737
|
-
var _event$context;
|
|
3738
|
-
console.error(`[CopilotKit] Error (${event.code}):`, event.error, (_event$context = event.context) !== null && _event$context !== void 0 ? _event$context : {});
|
|
3739
|
-
}
|
|
3751
|
+
else console.error(`[CopilotKit] Error (${event.code}):`, event.error, event.context ?? {});
|
|
3740
3752
|
} });
|
|
3741
3753
|
return () => {
|
|
3742
3754
|
subscription.unsubscribe();
|
|
@@ -3783,7 +3795,7 @@ window.parent.postMessage({jsonrpc:"2.0",method:"ui/notifications/sandbox-proxy-
|
|
|
3783
3795
|
(0, react.useEffect)(() => {
|
|
3784
3796
|
copilotkit.setDefaultThrottleMs(defaultThrottleMs);
|
|
3785
3797
|
}, [copilotkit, defaultThrottleMs]);
|
|
3786
|
-
const designSkill =
|
|
3798
|
+
const designSkill = openGenerativeUI?.designSkill ?? DEFAULT_DESIGN_SKILL;
|
|
3787
3799
|
(0, react.useLayoutEffect)(() => {
|
|
3788
3800
|
if (!copilotkit || !openGenUIActive) return;
|
|
3789
3801
|
const id = copilotkit.addContext({
|
|
@@ -3834,8 +3846,8 @@ window.parent.postMessage({jsonrpc:"2.0",method:"ui/notifications/sandbox-proxy-
|
|
|
3834
3846
|
children: [
|
|
3835
3847
|
runtimeA2UIEnabled && /* @__PURE__ */ (0, react_jsx_runtime.jsx)(A2UIBuiltInToolCallRenderer, {}),
|
|
3836
3848
|
runtimeA2UIEnabled && /* @__PURE__ */ (0, react_jsx_runtime.jsx)(A2UICatalogContext, {
|
|
3837
|
-
catalog: a2ui
|
|
3838
|
-
includeSchema: a2ui
|
|
3849
|
+
catalog: a2ui?.catalog,
|
|
3850
|
+
includeSchema: a2ui?.includeSchema
|
|
3839
3851
|
}),
|
|
3840
3852
|
children,
|
|
3841
3853
|
shouldRenderInspector ? /* @__PURE__ */ (0, react_jsx_runtime.jsx)(CopilotKitInspector, {
|
|
@@ -3865,11 +3877,10 @@ window.parent.postMessage({jsonrpc:"2.0",method:"ui/notifications/sandbox-proxy-
|
|
|
3865
3877
|
return aHasAgent ? -1 : 1;
|
|
3866
3878
|
});
|
|
3867
3879
|
return function(params) {
|
|
3868
|
-
var _copilotkit$getRunIdF;
|
|
3869
3880
|
if (!customMessageRenderers.length) return null;
|
|
3870
3881
|
const { message, position } = params;
|
|
3871
|
-
const resolvedRunId =
|
|
3872
|
-
const runId = resolvedRunId
|
|
3882
|
+
const resolvedRunId = copilotkit.getRunIdForMessage(agentId, threadId, message.id) ?? copilotkit.getRunIdsForThread(agentId, threadId).slice(-1)[0];
|
|
3883
|
+
const runId = resolvedRunId ?? `missing-run-id:${message.id}`;
|
|
3873
3884
|
const agent = copilotkit.getAgent(agentId);
|
|
3874
3885
|
if (!agent) return null;
|
|
3875
3886
|
const messagesIdsInRun = resolvedRunId ? agent.messages.filter((msg) => copilotkit.getRunIdForMessage(agentId, threadId, msg.id) === resolvedRunId).map((msg) => msg.id) : [message.id];
|
|
@@ -3901,15 +3912,13 @@ window.parent.postMessage({jsonrpc:"2.0",method:"ui/notifications/sandbox-proxy-
|
|
|
3901
3912
|
//#endregion
|
|
3902
3913
|
//#region src/v2/hooks/use-render-activity-message.tsx
|
|
3903
3914
|
function useRenderActivityMessage() {
|
|
3904
|
-
var _useCopilotChatConfig, _useCopilotChatConfig2;
|
|
3905
3915
|
const { copilotkit } = useCopilotKit();
|
|
3906
|
-
const agentId =
|
|
3916
|
+
const agentId = useCopilotChatConfiguration()?.agentId ?? _copilotkit_shared.DEFAULT_AGENT_ID;
|
|
3907
3917
|
const renderers = copilotkit.renderActivityMessages;
|
|
3908
3918
|
const findRenderer = (0, react.useCallback)((activityType) => {
|
|
3909
|
-
var _ref, _ref2, _matches$find;
|
|
3910
3919
|
if (!renderers.length) return null;
|
|
3911
3920
|
const matches = renderers.filter((renderer) => renderer.activityType === activityType);
|
|
3912
|
-
return
|
|
3921
|
+
return matches.find((candidate) => candidate.agentId === agentId) ?? matches.find((candidate) => candidate.agentId === void 0) ?? renderers.find((candidate) => candidate.activityType === "*") ?? null;
|
|
3913
3922
|
}, [agentId, renderers]);
|
|
3914
3923
|
const renderActivityMessage = (0, react.useCallback)((message) => {
|
|
3915
3924
|
const renderer = findRenderer(message.activityType);
|
|
@@ -3943,7 +3952,7 @@ window.parent.postMessage({jsonrpc:"2.0",method:"ui/notifications/sandbox-proxy-
|
|
|
3943
3952
|
const EMPTY_DEPS = [];
|
|
3944
3953
|
function useFrontendTool(tool, deps) {
|
|
3945
3954
|
const { copilotkit } = useCopilotKit();
|
|
3946
|
-
const extraDeps = deps
|
|
3955
|
+
const extraDeps = deps ?? EMPTY_DEPS;
|
|
3947
3956
|
(0, react.useEffect)(() => {
|
|
3948
3957
|
const name = tool.name;
|
|
3949
3958
|
if (copilotkit.getTool({
|
|
@@ -4119,15 +4128,13 @@ window.parent.postMessage({jsonrpc:"2.0",method:"ui/notifications/sandbox-proxy-
|
|
|
4119
4128
|
UseAgentUpdate.OnRunStatusChanged
|
|
4120
4129
|
];
|
|
4121
4130
|
function useAgent({ agentId, updates, throttleMs } = {}) {
|
|
4122
|
-
|
|
4123
|
-
(_agentId = agentId) !== null && _agentId !== void 0 || (agentId = _copilotkit_shared.DEFAULT_AGENT_ID);
|
|
4131
|
+
agentId ?? (agentId = _copilotkit_shared.DEFAULT_AGENT_ID);
|
|
4124
4132
|
const { copilotkit } = useCopilotKit();
|
|
4125
4133
|
const providerThrottleMs = copilotkit.defaultThrottleMs;
|
|
4126
4134
|
const [, forceUpdate] = (0, react.useReducer)((x) => x + 1, 0);
|
|
4127
|
-
const updateFlags = (0, react.useMemo)(() => updates
|
|
4135
|
+
const updateFlags = (0, react.useMemo)(() => updates ?? ALL_UPDATES, [JSON.stringify(updates)]);
|
|
4128
4136
|
const provisionalAgentCache = (0, react.useRef)(/* @__PURE__ */ new Map());
|
|
4129
4137
|
const agent = (0, react.useMemo)(() => {
|
|
4130
|
-
var _copilotkit$agents;
|
|
4131
4138
|
const existing = copilotkit.getAgent(agentId);
|
|
4132
4139
|
if (existing) {
|
|
4133
4140
|
provisionalAgentCache.current.delete(agentId);
|
|
@@ -4167,7 +4174,7 @@ window.parent.postMessage({jsonrpc:"2.0",method:"ui/notifications/sandbox-proxy-
|
|
|
4167
4174
|
provisionalAgentCache.current.set(agentId, provisional);
|
|
4168
4175
|
return provisional;
|
|
4169
4176
|
}
|
|
4170
|
-
const knownAgents = Object.keys(
|
|
4177
|
+
const knownAgents = Object.keys(copilotkit.agents ?? {});
|
|
4171
4178
|
const runtimePart = isRuntimeConfigured ? `runtimeUrl=${copilotkit.runtimeUrl}` : "no runtimeUrl";
|
|
4172
4179
|
throw new Error(`useAgent: Agent '${agentId}' not found after runtime sync (${runtimePart}). ` + (knownAgents.length ? `Known agents: [${knownAgents.join(", ")}]` : "No agents registered.") + " Verify your runtime /info and/or agents__unsafe_dev_only.");
|
|
4173
4180
|
}, [
|
|
@@ -4217,8 +4224,8 @@ window.parent.postMessage({jsonrpc:"2.0",method:"ui/notifications/sandbox-proxy-
|
|
|
4217
4224
|
if (agent instanceof _ag_ui_client.HttpAgent) agent.headers = { ...copilotkit.headers };
|
|
4218
4225
|
}, [agent, JSON.stringify(copilotkit.headers)]);
|
|
4219
4226
|
const chatConfig = useCopilotChatConfiguration();
|
|
4220
|
-
const configThreadId = chatConfig
|
|
4221
|
-
const configHasExplicitThreadId = chatConfig
|
|
4227
|
+
const configThreadId = chatConfig?.threadId;
|
|
4228
|
+
const configHasExplicitThreadId = chatConfig?.hasExplicitThreadId;
|
|
4222
4229
|
(0, react.useEffect)(() => {
|
|
4223
4230
|
if (!configHasExplicitThreadId || !configThreadId) return;
|
|
4224
4231
|
agent.threadId = configThreadId;
|
|
@@ -4253,10 +4260,7 @@ window.parent.postMessage({jsonrpc:"2.0",method:"ui/notifications/sandbox-proxy-
|
|
|
4253
4260
|
function useSuggestions({ agentId } = {}) {
|
|
4254
4261
|
const { copilotkit } = useCopilotKit();
|
|
4255
4262
|
const config = useCopilotChatConfiguration();
|
|
4256
|
-
const resolvedAgentId = (0, react.useMemo)(() =>
|
|
4257
|
-
var _ref;
|
|
4258
|
-
return (_ref = agentId !== null && agentId !== void 0 ? agentId : config === null || config === void 0 ? void 0 : config.agentId) !== null && _ref !== void 0 ? _ref : _copilotkit_shared.DEFAULT_AGENT_ID;
|
|
4259
|
-
}, [agentId, config === null || config === void 0 ? void 0 : config.agentId]);
|
|
4263
|
+
const resolvedAgentId = (0, react.useMemo)(() => agentId ?? config?.agentId ?? _copilotkit_shared.DEFAULT_AGENT_ID, [agentId, config?.agentId]);
|
|
4260
4264
|
const [suggestions, setSuggestions] = (0, react.useState)(() => {
|
|
4261
4265
|
return copilotkit.getSuggestions(resolvedAgentId).suggestions;
|
|
4262
4266
|
});
|
|
@@ -4309,11 +4313,8 @@ window.parent.postMessage({jsonrpc:"2.0",method:"ui/notifications/sandbox-proxy-
|
|
|
4309
4313
|
function useConfigureSuggestions(config, deps) {
|
|
4310
4314
|
const { copilotkit } = useCopilotKit();
|
|
4311
4315
|
const chatConfig = useCopilotChatConfiguration();
|
|
4312
|
-
const extraDeps = deps
|
|
4313
|
-
const resolvedConsumerAgentId = (0, react.useMemo)(() =>
|
|
4314
|
-
var _chatConfig$agentId;
|
|
4315
|
-
return (_chatConfig$agentId = chatConfig === null || chatConfig === void 0 ? void 0 : chatConfig.agentId) !== null && _chatConfig$agentId !== void 0 ? _chatConfig$agentId : _copilotkit_shared.DEFAULT_AGENT_ID;
|
|
4316
|
-
}, [chatConfig === null || chatConfig === void 0 ? void 0 : chatConfig.agentId]);
|
|
4316
|
+
const extraDeps = deps ?? [];
|
|
4317
|
+
const resolvedConsumerAgentId = (0, react.useMemo)(() => chatConfig?.agentId ?? _copilotkit_shared.DEFAULT_AGENT_ID, [chatConfig?.agentId]);
|
|
4317
4318
|
const rawConsumerAgentId = (0, react.useMemo)(() => config ? config.consumerAgentId : void 0, [config]);
|
|
4318
4319
|
const normalizationCacheRef = (0, react.useRef)({
|
|
4319
4320
|
serialized: null,
|
|
@@ -4382,9 +4383,8 @@ window.parent.postMessage({jsonrpc:"2.0",method:"ui/notifications/sandbox-proxy-
|
|
|
4382
4383
|
const requestReload = (0, react.useCallback)(() => {
|
|
4383
4384
|
if (!normalizedConfig) return;
|
|
4384
4385
|
if (isGlobalConfig) {
|
|
4385
|
-
var _copilotkit$agents;
|
|
4386
4386
|
const seen = /* @__PURE__ */ new Set();
|
|
4387
|
-
const agents = Object.values(
|
|
4387
|
+
const agents = Object.values(copilotkit.agents ?? {});
|
|
4388
4388
|
for (const entry of agents) {
|
|
4389
4389
|
const agentId = entry.agentId;
|
|
4390
4390
|
if (!agentId) continue;
|
|
@@ -4461,13 +4461,10 @@ window.parent.postMessage({jsonrpc:"2.0",method:"ui/notifications/sandbox-proxy-
|
|
|
4461
4461
|
return "instructions" in config;
|
|
4462
4462
|
}
|
|
4463
4463
|
function normalizeStaticSuggestions(suggestions) {
|
|
4464
|
-
return suggestions.map((suggestion) => {
|
|
4465
|
-
|
|
4466
|
-
|
|
4467
|
-
|
|
4468
|
-
isLoading: (_suggestion$isLoading = suggestion.isLoading) !== null && _suggestion$isLoading !== void 0 ? _suggestion$isLoading : false
|
|
4469
|
-
};
|
|
4470
|
-
});
|
|
4464
|
+
return suggestions.map((suggestion) => ({
|
|
4465
|
+
...suggestion,
|
|
4466
|
+
isLoading: suggestion.isLoading ?? false
|
|
4467
|
+
}));
|
|
4471
4468
|
}
|
|
4472
4469
|
|
|
4473
4470
|
//#endregion
|
|
@@ -4569,54 +4566,75 @@ window.parent.postMessage({jsonrpc:"2.0",method:"ui/notifications/sandbox-proxy-
|
|
|
4569
4566
|
return () => subscription.unsubscribe();
|
|
4570
4567
|
}, [agent]);
|
|
4571
4568
|
const resolve = (0, react.useCallback)((response) => {
|
|
4572
|
-
var _pendingEventRef$curr;
|
|
4573
|
-
setPendingEvent(null);
|
|
4574
4569
|
copilotkit.runAgent({
|
|
4575
4570
|
agent,
|
|
4576
4571
|
forwardedProps: { command: {
|
|
4577
4572
|
resume: response,
|
|
4578
|
-
interruptEvent:
|
|
4573
|
+
interruptEvent: pendingEventRef.current?.value
|
|
4579
4574
|
} }
|
|
4580
4575
|
});
|
|
4581
4576
|
}, [agent, copilotkit]);
|
|
4577
|
+
const renderRef = (0, react.useRef)(config.render);
|
|
4578
|
+
renderRef.current = config.render;
|
|
4579
|
+
const enabledRef = (0, react.useRef)(config.enabled);
|
|
4580
|
+
enabledRef.current = config.enabled;
|
|
4581
|
+
const handlerRef = (0, react.useRef)(config.handler);
|
|
4582
|
+
handlerRef.current = config.handler;
|
|
4583
|
+
const resolveRef = (0, react.useRef)(resolve);
|
|
4584
|
+
resolveRef.current = resolve;
|
|
4585
|
+
const isEnabled = (event) => {
|
|
4586
|
+
const predicate = enabledRef.current;
|
|
4587
|
+
if (!predicate) return true;
|
|
4588
|
+
try {
|
|
4589
|
+
return predicate(event);
|
|
4590
|
+
} catch (err) {
|
|
4591
|
+
console.error("[CopilotKit] useInterrupt enabled predicate threw; treating interrupt as disabled:", err);
|
|
4592
|
+
return false;
|
|
4593
|
+
}
|
|
4594
|
+
};
|
|
4582
4595
|
(0, react.useEffect)(() => {
|
|
4583
4596
|
if (!pendingEvent) {
|
|
4584
4597
|
setHandlerResult(null);
|
|
4585
4598
|
return;
|
|
4586
4599
|
}
|
|
4587
|
-
if (
|
|
4600
|
+
if (!isEnabled(pendingEvent)) {
|
|
4588
4601
|
setHandlerResult(null);
|
|
4589
4602
|
return;
|
|
4590
4603
|
}
|
|
4591
|
-
const handler =
|
|
4604
|
+
const handler = handlerRef.current;
|
|
4592
4605
|
if (!handler) {
|
|
4593
4606
|
setHandlerResult(null);
|
|
4594
4607
|
return;
|
|
4595
4608
|
}
|
|
4596
4609
|
let cancelled = false;
|
|
4597
|
-
|
|
4598
|
-
|
|
4599
|
-
|
|
4600
|
-
|
|
4610
|
+
let maybePromise;
|
|
4611
|
+
try {
|
|
4612
|
+
maybePromise = handler({
|
|
4613
|
+
event: pendingEvent,
|
|
4614
|
+
resolve: resolveRef.current
|
|
4615
|
+
});
|
|
4616
|
+
} catch (err) {
|
|
4617
|
+
console.error("[CopilotKit] useInterrupt handler threw; result will be null:", err);
|
|
4618
|
+
if (!cancelled) setHandlerResult(null);
|
|
4619
|
+
return () => {
|
|
4620
|
+
cancelled = true;
|
|
4621
|
+
};
|
|
4622
|
+
}
|
|
4601
4623
|
if (isPromiseLike(maybePromise)) Promise.resolve(maybePromise).then((resolved) => {
|
|
4602
4624
|
if (!cancelled) setHandlerResult(resolved);
|
|
4603
|
-
}).catch(() => {
|
|
4625
|
+
}).catch((err) => {
|
|
4626
|
+
console.error("[CopilotKit] useInterrupt handler rejected; result will be null:", err);
|
|
4604
4627
|
if (!cancelled) setHandlerResult(null);
|
|
4605
4628
|
});
|
|
4606
4629
|
else setHandlerResult(maybePromise);
|
|
4607
4630
|
return () => {
|
|
4608
4631
|
cancelled = true;
|
|
4609
4632
|
};
|
|
4610
|
-
}, [
|
|
4611
|
-
pendingEvent,
|
|
4612
|
-
config.enabled,
|
|
4613
|
-
config.handler,
|
|
4614
|
-
resolve
|
|
4615
|
-
]);
|
|
4633
|
+
}, [pendingEvent]);
|
|
4616
4634
|
const element = (0, react.useMemo)(() => {
|
|
4617
4635
|
if (!pendingEvent) return null;
|
|
4618
|
-
if (
|
|
4619
|
-
return
|
|
4636
|
+
if (!isEnabled(pendingEvent)) return null;
|
|
4637
|
+
return renderRef.current({
|
|
4620
4638
|
event: pendingEvent,
|
|
4621
4639
|
result: handlerResult,
|
|
4622
4640
|
resolve
|
|
@@ -4624,19 +4642,22 @@ window.parent.postMessage({jsonrpc:"2.0",method:"ui/notifications/sandbox-proxy-
|
|
|
4624
4642
|
}, [
|
|
4625
4643
|
pendingEvent,
|
|
4626
4644
|
handlerResult,
|
|
4627
|
-
config.enabled,
|
|
4628
|
-
config.render,
|
|
4629
4645
|
resolve
|
|
4630
4646
|
]);
|
|
4631
4647
|
(0, react.useEffect)(() => {
|
|
4632
4648
|
if (config.renderInChat === false) return;
|
|
4633
4649
|
copilotkit.setInterruptElement(element);
|
|
4634
|
-
return () => copilotkit.setInterruptElement(null);
|
|
4635
4650
|
}, [
|
|
4636
4651
|
element,
|
|
4637
4652
|
config.renderInChat,
|
|
4638
4653
|
copilotkit
|
|
4639
4654
|
]);
|
|
4655
|
+
(0, react.useEffect)(() => {
|
|
4656
|
+
if (config.renderInChat === false) return;
|
|
4657
|
+
return () => {
|
|
4658
|
+
copilotkit.setInterruptElement(null);
|
|
4659
|
+
};
|
|
4660
|
+
}, []);
|
|
4640
4661
|
if (config.renderInChat === false) return element;
|
|
4641
4662
|
}
|
|
4642
4663
|
|
|
@@ -4690,7 +4711,6 @@ window.parent.postMessage({jsonrpc:"2.0",method:"ui/notifications/sandbox-proxy-
|
|
|
4690
4711
|
* ```
|
|
4691
4712
|
*/
|
|
4692
4713
|
function useThreads({ agentId, includeArchived, limit }) {
|
|
4693
|
-
var _copilotkit$intellige2;
|
|
4694
4714
|
const { copilotkit } = useCopilotKit();
|
|
4695
4715
|
const [store] = (0, react.useState)(() => (0, _copilotkit_core.ɵcreateThreadStore)({ fetch: globalThis.fetch }));
|
|
4696
4716
|
const coreThreads = useThreadStoreSelector(store, _copilotkit_core.ɵselectThreads);
|
|
@@ -4708,8 +4728,7 @@ window.parent.postMessage({jsonrpc:"2.0",method:"ui/notifications/sandbox-proxy-
|
|
|
4708
4728
|
const hasMoreThreads = useThreadStoreSelector(store, _copilotkit_core.ɵselectHasNextPage);
|
|
4709
4729
|
const isFetchingMoreThreads = useThreadStoreSelector(store, _copilotkit_core.ɵselectIsFetchingNextPage);
|
|
4710
4730
|
const headersKey = (0, react.useMemo)(() => {
|
|
4711
|
-
|
|
4712
|
-
return JSON.stringify(Object.entries((_copilotkit$headers = copilotkit.headers) !== null && _copilotkit$headers !== void 0 ? _copilotkit$headers : {}).sort(([left], [right]) => left.localeCompare(right)));
|
|
4731
|
+
return JSON.stringify(Object.entries(copilotkit.headers ?? {}).sort(([left], [right]) => left.localeCompare(right)));
|
|
4713
4732
|
}, [copilotkit.headers]);
|
|
4714
4733
|
const runtimeError = (0, react.useMemo)(() => {
|
|
4715
4734
|
if (copilotkit.runtimeUrl) return null;
|
|
@@ -4718,7 +4737,7 @@ window.parent.postMessage({jsonrpc:"2.0",method:"ui/notifications/sandbox-proxy-
|
|
|
4718
4737
|
const [hasDispatchedContext, setHasDispatchedContext] = (0, react.useState)(false);
|
|
4719
4738
|
const preConnectLoading = !!copilotkit.runtimeUrl && !hasDispatchedContext;
|
|
4720
4739
|
const isLoading = runtimeError ? false : preConnectLoading || storeIsLoading;
|
|
4721
|
-
const error = runtimeError
|
|
4740
|
+
const error = runtimeError ?? storeError;
|
|
4722
4741
|
(0, react.useEffect)(() => {
|
|
4723
4742
|
store.start();
|
|
4724
4743
|
return () => {
|
|
@@ -4737,7 +4756,6 @@ window.parent.postMessage({jsonrpc:"2.0",method:"ui/notifications/sandbox-proxy-
|
|
|
4737
4756
|
store
|
|
4738
4757
|
]);
|
|
4739
4758
|
(0, react.useEffect)(() => {
|
|
4740
|
-
var _copilotkit$intellige;
|
|
4741
4759
|
if (!copilotkit.runtimeUrl) {
|
|
4742
4760
|
store.setContext(null);
|
|
4743
4761
|
return;
|
|
@@ -4746,7 +4764,7 @@ window.parent.postMessage({jsonrpc:"2.0",method:"ui/notifications/sandbox-proxy-
|
|
|
4746
4764
|
const context = {
|
|
4747
4765
|
runtimeUrl: copilotkit.runtimeUrl,
|
|
4748
4766
|
headers: { ...copilotkit.headers },
|
|
4749
|
-
wsUrl:
|
|
4767
|
+
wsUrl: copilotkit.intelligence?.wsUrl,
|
|
4750
4768
|
agentId,
|
|
4751
4769
|
includeArchived,
|
|
4752
4770
|
limit
|
|
@@ -4758,7 +4776,7 @@ window.parent.postMessage({jsonrpc:"2.0",method:"ui/notifications/sandbox-proxy-
|
|
|
4758
4776
|
copilotkit.runtimeUrl,
|
|
4759
4777
|
runtimeStatus,
|
|
4760
4778
|
headersKey,
|
|
4761
|
-
|
|
4779
|
+
copilotkit.intelligence?.wsUrl,
|
|
4762
4780
|
agentId,
|
|
4763
4781
|
includeArchived,
|
|
4764
4782
|
limit
|
|
@@ -4787,8 +4805,7 @@ window.parent.postMessage({jsonrpc:"2.0",method:"ui/notifications/sandbox-proxy-
|
|
|
4787
4805
|
* renders (via useCallback) to avoid destabilizing downstream memoization.
|
|
4788
4806
|
*/
|
|
4789
4807
|
function useAttachments({ config }) {
|
|
4790
|
-
|
|
4791
|
-
const enabled = (_config$enabled = config === null || config === void 0 ? void 0 : config.enabled) !== null && _config$enabled !== void 0 ? _config$enabled : false;
|
|
4808
|
+
const enabled = config?.enabled ?? false;
|
|
4792
4809
|
const [attachments, setAttachments] = (0, react.useState)([]);
|
|
4793
4810
|
const [dragOver, setDragOver] = (0, react.useState)(false);
|
|
4794
4811
|
const fileInputRef = (0, react.useRef)(null);
|
|
@@ -4798,24 +4815,19 @@ window.parent.postMessage({jsonrpc:"2.0",method:"ui/notifications/sandbox-proxy-
|
|
|
4798
4815
|
const attachmentsRef = (0, react.useRef)([]);
|
|
4799
4816
|
attachmentsRef.current = attachments;
|
|
4800
4817
|
const processFiles = (0, react.useCallback)(async (files) => {
|
|
4801
|
-
var _cfg$accept, _cfg$maxSize;
|
|
4802
4818
|
const cfg = configRef.current;
|
|
4803
|
-
const accept =
|
|
4804
|
-
const maxSize =
|
|
4819
|
+
const accept = cfg?.accept ?? "*/*";
|
|
4820
|
+
const maxSize = cfg?.maxSize ?? 20 * 1024 * 1024;
|
|
4805
4821
|
const rejectedFiles = files.filter((file) => !(0, _copilotkit_shared.matchesAcceptFilter)(file, accept));
|
|
4806
|
-
for (const file of rejectedFiles) {
|
|
4807
|
-
|
|
4808
|
-
|
|
4809
|
-
|
|
4810
|
-
|
|
4811
|
-
message: `File "${file.name}" is not accepted. Supported types: ${accept}`
|
|
4812
|
-
});
|
|
4813
|
-
}
|
|
4822
|
+
for (const file of rejectedFiles) cfg?.onUploadFailed?.({
|
|
4823
|
+
reason: "invalid-type",
|
|
4824
|
+
file,
|
|
4825
|
+
message: `File "${file.name}" is not accepted. Supported types: ${accept}`
|
|
4826
|
+
});
|
|
4814
4827
|
const validFiles = files.filter((file) => (0, _copilotkit_shared.matchesAcceptFilter)(file, accept));
|
|
4815
4828
|
for (const file of validFiles) {
|
|
4816
4829
|
if ((0, _copilotkit_shared.exceedsMaxSize)(file, maxSize)) {
|
|
4817
|
-
|
|
4818
|
-
cfg === null || cfg === void 0 || (_cfg$onUploadFailed2 = cfg.onUploadFailed) === null || _cfg$onUploadFailed2 === void 0 || _cfg$onUploadFailed2.call(cfg, {
|
|
4830
|
+
cfg?.onUploadFailed?.({
|
|
4819
4831
|
reason: "file-too-large",
|
|
4820
4832
|
file,
|
|
4821
4833
|
message: `File "${file.name}" exceeds the maximum size of ${(0, _copilotkit_shared.formatFileSize)(maxSize)}`
|
|
@@ -4840,7 +4852,7 @@ window.parent.postMessage({jsonrpc:"2.0",method:"ui/notifications/sandbox-proxy-
|
|
|
4840
4852
|
try {
|
|
4841
4853
|
let source;
|
|
4842
4854
|
let uploadMetadata;
|
|
4843
|
-
if (cfg
|
|
4855
|
+
if (cfg?.onUpload) {
|
|
4844
4856
|
const { metadata: meta, ...uploadSource } = await cfg.onUpload(file);
|
|
4845
4857
|
source = uploadSource;
|
|
4846
4858
|
uploadMetadata = meta;
|
|
@@ -4859,10 +4871,9 @@ window.parent.postMessage({jsonrpc:"2.0",method:"ui/notifications/sandbox-proxy-
|
|
|
4859
4871
|
metadata: uploadMetadata
|
|
4860
4872
|
} : att));
|
|
4861
4873
|
} catch (error) {
|
|
4862
|
-
var _cfg$onUploadFailed3;
|
|
4863
4874
|
setAttachments((prev) => prev.filter((att) => att.id !== placeholderId));
|
|
4864
4875
|
console.error(`[CopilotKit] Failed to upload "${file.name}":`, error);
|
|
4865
|
-
cfg
|
|
4876
|
+
cfg?.onUploadFailed?.({
|
|
4866
4877
|
reason: "upload-failed",
|
|
4867
4878
|
file,
|
|
4868
4879
|
message: error instanceof Error ? error.message : `Failed to upload "${file.name}"`
|
|
@@ -4871,8 +4882,7 @@ window.parent.postMessage({jsonrpc:"2.0",method:"ui/notifications/sandbox-proxy-
|
|
|
4871
4882
|
}
|
|
4872
4883
|
}, []);
|
|
4873
4884
|
const handleFileUpload = (0, react.useCallback)(async (e) => {
|
|
4874
|
-
|
|
4875
|
-
if (!((_e$target$files = e.target.files) === null || _e$target$files === void 0 ? void 0 : _e$target$files.length)) return;
|
|
4885
|
+
if (!e.target.files?.length) return;
|
|
4876
4886
|
try {
|
|
4877
4887
|
await processFiles(Array.from(e.target.files));
|
|
4878
4888
|
} catch (error) {
|
|
@@ -4880,8 +4890,7 @@ window.parent.postMessage({jsonrpc:"2.0",method:"ui/notifications/sandbox-proxy-
|
|
|
4880
4890
|
}
|
|
4881
4891
|
}, [processFiles]);
|
|
4882
4892
|
const handleDragOver = (0, react.useCallback)((e) => {
|
|
4883
|
-
|
|
4884
|
-
if (!((_configRef$current = configRef.current) === null || _configRef$current === void 0 ? void 0 : _configRef$current.enabled)) return;
|
|
4893
|
+
if (!configRef.current?.enabled) return;
|
|
4885
4894
|
e.preventDefault();
|
|
4886
4895
|
e.stopPropagation();
|
|
4887
4896
|
setDragOver(true);
|
|
@@ -4892,11 +4901,10 @@ window.parent.postMessage({jsonrpc:"2.0",method:"ui/notifications/sandbox-proxy-
|
|
|
4892
4901
|
setDragOver(false);
|
|
4893
4902
|
}, []);
|
|
4894
4903
|
const handleDrop = (0, react.useCallback)(async (e) => {
|
|
4895
|
-
var _configRef$current2;
|
|
4896
4904
|
e.preventDefault();
|
|
4897
4905
|
e.stopPropagation();
|
|
4898
4906
|
setDragOver(false);
|
|
4899
|
-
if (!
|
|
4907
|
+
if (!configRef.current?.enabled) return;
|
|
4900
4908
|
const files = Array.from(e.dataTransfer.files);
|
|
4901
4909
|
if (files.length > 0) try {
|
|
4902
4910
|
await processFiles(files);
|
|
@@ -4907,11 +4915,10 @@ window.parent.postMessage({jsonrpc:"2.0",method:"ui/notifications/sandbox-proxy-
|
|
|
4907
4915
|
(0, react.useEffect)(() => {
|
|
4908
4916
|
if (!enabled) return;
|
|
4909
4917
|
const handlePaste = async (e) => {
|
|
4910
|
-
var _containerRef$current, _configRef$current$ac, _configRef$current3, _e$clipboardData;
|
|
4911
4918
|
const target = e.target;
|
|
4912
|
-
if (!target || !
|
|
4913
|
-
const accept =
|
|
4914
|
-
const fileItems = Array.from(
|
|
4919
|
+
if (!target || !containerRef.current?.contains(target)) return;
|
|
4920
|
+
const accept = configRef.current?.accept ?? "*/*";
|
|
4921
|
+
const fileItems = Array.from(e.clipboardData?.items || []).filter((item) => item.kind === "file" && item.getAsFile() !== null && (0, _copilotkit_shared.matchesAcceptFilter)(item.getAsFile(), accept));
|
|
4915
4922
|
if (fileItems.length === 0) return;
|
|
4916
4923
|
e.preventDefault();
|
|
4917
4924
|
const files = fileItems.map((item) => item.getAsFile()).filter((f) => f !== null);
|
|
@@ -4965,7 +4972,6 @@ window.parent.postMessage({jsonrpc:"2.0",method:"ui/notifications/sandbox-proxy-
|
|
|
4965
4972
|
//#endregion
|
|
4966
4973
|
//#region src/v2/components/chat/CopilotChatAssistantMessage.tsx
|
|
4967
4974
|
function CopilotChatAssistantMessage({ message, messages, isRunning, onThumbsUp, onThumbsDown, onReadAloud, onRegenerate, additionalToolbarItems, toolbarVisible = true, markdownRenderer, toolbar, copyButton, thumbsUpButton, thumbsDownButton, readAloudButton, regenerateButton, toolCallsView, children, className, ...props }) {
|
|
4968
|
-
var _messages;
|
|
4969
4975
|
useKatexStyles();
|
|
4970
4976
|
const boundMarkdownRenderer = renderSlot(markdownRenderer, CopilotChatAssistantMessage.MarkdownRenderer, { content: message.content || "" });
|
|
4971
4977
|
const boundCopyButton = renderSlot(copyButton, CopilotChatAssistantMessage.CopyButton, { onClick: async () => {
|
|
@@ -4992,7 +4998,7 @@ window.parent.postMessage({jsonrpc:"2.0",method:"ui/notifications/sandbox-proxy-
|
|
|
4992
4998
|
messages
|
|
4993
4999
|
});
|
|
4994
5000
|
const hasContent = !!(message.content && message.content.trim().length > 0);
|
|
4995
|
-
const isLatestAssistantMessage = message.role === "assistant" &&
|
|
5001
|
+
const isLatestAssistantMessage = message.role === "assistant" && messages?.[messages.length - 1]?.id === message.id;
|
|
4996
5002
|
const shouldShowToolbar = toolbarVisible && hasContent && !(isRunning && isLatestAssistantMessage);
|
|
4997
5003
|
if (children) return /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
|
|
4998
5004
|
"data-copilotkit": true,
|
|
@@ -5037,7 +5043,7 @@ window.parent.postMessage({jsonrpc:"2.0",method:"ui/notifications/sandbox-proxy-
|
|
|
5037
5043
|
_CopilotChatAssistantMessage.MarkdownRenderer = ({ content, className, ...props }) => /* @__PURE__ */ (0, react_jsx_runtime.jsx)(streamdown.Streamdown, {
|
|
5038
5044
|
className,
|
|
5039
5045
|
...props,
|
|
5040
|
-
children: content
|
|
5046
|
+
children: content ?? ""
|
|
5041
5047
|
});
|
|
5042
5048
|
_CopilotChatAssistantMessage.Toolbar = ({ className, ...props }) => /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
|
|
5043
5049
|
"data-testid": "copilot-assistant-toolbar",
|
|
@@ -5060,9 +5066,7 @@ window.parent.postMessage({jsonrpc:"2.0",method:"ui/notifications/sandbox-proxy-
|
|
|
5060
5066
|
})] });
|
|
5061
5067
|
};
|
|
5062
5068
|
_CopilotChatAssistantMessage.CopyButton = ({ className, title, onClick, ...props }) => {
|
|
5063
|
-
|
|
5064
|
-
const config = useCopilotChatConfiguration();
|
|
5065
|
-
const labels = (_config$labels = config === null || config === void 0 ? void 0 : config.labels) !== null && _config$labels !== void 0 ? _config$labels : CopilotChatDefaultLabels;
|
|
5069
|
+
const labels = useCopilotChatConfiguration()?.labels ?? CopilotChatDefaultLabels;
|
|
5066
5070
|
const [copied, setCopied] = (0, react.useState)(false);
|
|
5067
5071
|
const timerRef = (0, react.useRef)(null);
|
|
5068
5072
|
(0, react.useEffect)(() => {
|
|
@@ -5092,9 +5096,7 @@ window.parent.postMessage({jsonrpc:"2.0",method:"ui/notifications/sandbox-proxy-
|
|
|
5092
5096
|
});
|
|
5093
5097
|
};
|
|
5094
5098
|
_CopilotChatAssistantMessage.ThumbsUpButton = ({ title, ...props }) => {
|
|
5095
|
-
|
|
5096
|
-
const config = useCopilotChatConfiguration();
|
|
5097
|
-
const labels = (_config$labels2 = config === null || config === void 0 ? void 0 : config.labels) !== null && _config$labels2 !== void 0 ? _config$labels2 : CopilotChatDefaultLabels;
|
|
5099
|
+
const labels = useCopilotChatConfiguration()?.labels ?? CopilotChatDefaultLabels;
|
|
5098
5100
|
return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(ToolbarButton, {
|
|
5099
5101
|
"data-testid": "copilot-thumbs-up-button",
|
|
5100
5102
|
title: title || labels.assistantMessageToolbarThumbsUpLabel,
|
|
@@ -5103,9 +5105,7 @@ window.parent.postMessage({jsonrpc:"2.0",method:"ui/notifications/sandbox-proxy-
|
|
|
5103
5105
|
});
|
|
5104
5106
|
};
|
|
5105
5107
|
_CopilotChatAssistantMessage.ThumbsDownButton = ({ title, ...props }) => {
|
|
5106
|
-
|
|
5107
|
-
const config = useCopilotChatConfiguration();
|
|
5108
|
-
const labels = (_config$labels3 = config === null || config === void 0 ? void 0 : config.labels) !== null && _config$labels3 !== void 0 ? _config$labels3 : CopilotChatDefaultLabels;
|
|
5108
|
+
const labels = useCopilotChatConfiguration()?.labels ?? CopilotChatDefaultLabels;
|
|
5109
5109
|
return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(ToolbarButton, {
|
|
5110
5110
|
"data-testid": "copilot-thumbs-down-button",
|
|
5111
5111
|
title: title || labels.assistantMessageToolbarThumbsDownLabel,
|
|
@@ -5114,9 +5114,7 @@ window.parent.postMessage({jsonrpc:"2.0",method:"ui/notifications/sandbox-proxy-
|
|
|
5114
5114
|
});
|
|
5115
5115
|
};
|
|
5116
5116
|
_CopilotChatAssistantMessage.ReadAloudButton = ({ title, ...props }) => {
|
|
5117
|
-
|
|
5118
|
-
const config = useCopilotChatConfiguration();
|
|
5119
|
-
const labels = (_config$labels4 = config === null || config === void 0 ? void 0 : config.labels) !== null && _config$labels4 !== void 0 ? _config$labels4 : CopilotChatDefaultLabels;
|
|
5117
|
+
const labels = useCopilotChatConfiguration()?.labels ?? CopilotChatDefaultLabels;
|
|
5120
5118
|
return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(ToolbarButton, {
|
|
5121
5119
|
"data-testid": "copilot-read-aloud-button",
|
|
5122
5120
|
title: title || labels.assistantMessageToolbarReadAloudLabel,
|
|
@@ -5125,9 +5123,7 @@ window.parent.postMessage({jsonrpc:"2.0",method:"ui/notifications/sandbox-proxy-
|
|
|
5125
5123
|
});
|
|
5126
5124
|
};
|
|
5127
5125
|
_CopilotChatAssistantMessage.RegenerateButton = ({ title, ...props }) => {
|
|
5128
|
-
|
|
5129
|
-
const config = useCopilotChatConfiguration();
|
|
5130
|
-
const labels = (_config$labels5 = config === null || config === void 0 ? void 0 : config.labels) !== null && _config$labels5 !== void 0 ? _config$labels5 : CopilotChatDefaultLabels;
|
|
5126
|
+
const labels = useCopilotChatConfiguration()?.labels ?? CopilotChatDefaultLabels;
|
|
5131
5127
|
return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(ToolbarButton, {
|
|
5132
5128
|
"data-testid": "copilot-regenerate-button",
|
|
5133
5129
|
title: title || labels.assistantMessageToolbarRegenerateLabel,
|
|
@@ -5264,12 +5260,11 @@ window.parent.postMessage({jsonrpc:"2.0",method:"ui/notifications/sandbox-proxy-
|
|
|
5264
5260
|
});
|
|
5265
5261
|
});
|
|
5266
5262
|
const DocumentAttachment = (0, react.memo)(function DocumentAttachment({ source, filename, className }) {
|
|
5267
|
-
var _source$mimeType;
|
|
5268
5263
|
return /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
|
|
5269
5264
|
className: cn("cpk:inline-flex cpk:items-center cpk:gap-2 cpk:px-3 cpk:py-2 cpk:border cpk:border-border cpk:rounded-lg cpk:bg-muted", className),
|
|
5270
5265
|
children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
|
|
5271
5266
|
className: "cpk:text-xs cpk:font-bold cpk:uppercase",
|
|
5272
|
-
children: (0, _copilotkit_shared.getDocumentIcon)(
|
|
5267
|
+
children: (0, _copilotkit_shared.getDocumentIcon)(source.mimeType ?? "")
|
|
5273
5268
|
}), /* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
|
|
5274
5269
|
className: "cpk:text-sm cpk:text-muted-foreground cpk:truncate",
|
|
5275
5270
|
children: filename || source.mimeType || "Unknown type"
|
|
@@ -5326,7 +5321,7 @@ window.parent.postMessage({jsonrpc:"2.0",method:"ui/notifications/sandbox-proxy-
|
|
|
5326
5321
|
if (flattenedContent) return await (0, _copilotkit_shared.copyToClipboard)(flattenedContent);
|
|
5327
5322
|
return false;
|
|
5328
5323
|
} });
|
|
5329
|
-
const BoundEditButton = renderSlot(editButton, CopilotChatUserMessage.EditButton, { onClick: () => onEditMessage
|
|
5324
|
+
const BoundEditButton = renderSlot(editButton, CopilotChatUserMessage.EditButton, { onClick: () => onEditMessage?.({ message }) });
|
|
5330
5325
|
const BoundBranchNavigation = renderSlot(branchNavigation, CopilotChatUserMessage.BranchNavigation, {
|
|
5331
5326
|
currentBranch: branchIndex,
|
|
5332
5327
|
numberOfBranches,
|
|
@@ -5410,9 +5405,7 @@ window.parent.postMessage({jsonrpc:"2.0",method:"ui/notifications/sandbox-proxy-
|
|
|
5410
5405
|
})] });
|
|
5411
5406
|
};
|
|
5412
5407
|
_CopilotChatUserMessage.CopyButton = ({ className, title, onClick, ...props }) => {
|
|
5413
|
-
|
|
5414
|
-
const config = useCopilotChatConfiguration();
|
|
5415
|
-
const labels = (_config$labels = config === null || config === void 0 ? void 0 : config.labels) !== null && _config$labels !== void 0 ? _config$labels : CopilotChatDefaultLabels;
|
|
5408
|
+
const labels = useCopilotChatConfiguration()?.labels ?? CopilotChatDefaultLabels;
|
|
5416
5409
|
const [copied, setCopied] = (0, react.useState)(false);
|
|
5417
5410
|
const handleClick = async (event) => {
|
|
5418
5411
|
let success = false;
|
|
@@ -5432,9 +5425,7 @@ window.parent.postMessage({jsonrpc:"2.0",method:"ui/notifications/sandbox-proxy-
|
|
|
5432
5425
|
});
|
|
5433
5426
|
};
|
|
5434
5427
|
_CopilotChatUserMessage.EditButton = ({ className, title, ...props }) => {
|
|
5435
|
-
|
|
5436
|
-
const config = useCopilotChatConfiguration();
|
|
5437
|
-
const labels = (_config$labels2 = config === null || config === void 0 ? void 0 : config.labels) !== null && _config$labels2 !== void 0 ? _config$labels2 : CopilotChatDefaultLabels;
|
|
5428
|
+
const labels = useCopilotChatConfiguration()?.labels ?? CopilotChatDefaultLabels;
|
|
5438
5429
|
return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(ToolbarButton, {
|
|
5439
5430
|
"data-testid": "copilot-edit-button",
|
|
5440
5431
|
title: title || labels.userMessageToolbarEditMessageLabel,
|
|
@@ -5455,7 +5446,7 @@ window.parent.postMessage({jsonrpc:"2.0",method:"ui/notifications/sandbox-proxy-
|
|
|
5455
5446
|
/* @__PURE__ */ (0, react_jsx_runtime.jsx)(Button, {
|
|
5456
5447
|
type: "button",
|
|
5457
5448
|
variant: "assistantMessageToolbarButton",
|
|
5458
|
-
onClick: () => onSwitchToBranch
|
|
5449
|
+
onClick: () => onSwitchToBranch?.({
|
|
5459
5450
|
branchIndex: currentBranch - 1,
|
|
5460
5451
|
numberOfBranches,
|
|
5461
5452
|
message
|
|
@@ -5475,7 +5466,7 @@ window.parent.postMessage({jsonrpc:"2.0",method:"ui/notifications/sandbox-proxy-
|
|
|
5475
5466
|
/* @__PURE__ */ (0, react_jsx_runtime.jsx)(Button, {
|
|
5476
5467
|
type: "button",
|
|
5477
5468
|
variant: "assistantMessageToolbarButton",
|
|
5478
|
-
onClick: () => onSwitchToBranch
|
|
5469
|
+
onClick: () => onSwitchToBranch?.({
|
|
5479
5470
|
branchIndex: currentBranch + 1,
|
|
5480
5471
|
numberOfBranches,
|
|
5481
5472
|
message
|
|
@@ -5511,8 +5502,7 @@ window.parent.postMessage({jsonrpc:"2.0",method:"ui/notifications/sandbox-proxy-
|
|
|
5511
5502
|
return `${mins}m ${secs}s`;
|
|
5512
5503
|
}
|
|
5513
5504
|
function CopilotChatReasoningMessage({ message, messages, isRunning, header, contentView, toggle, children, className, ...props }) {
|
|
5514
|
-
|
|
5515
|
-
const isLatest = (messages === null || messages === void 0 || (_messages = messages[messages.length - 1]) === null || _messages === void 0 ? void 0 : _messages.id) === message.id;
|
|
5505
|
+
const isLatest = messages?.[messages.length - 1]?.id === message.id;
|
|
5516
5506
|
const isStreaming = !!(isRunning && isLatest);
|
|
5517
5507
|
const hasContent = !!(message.content && message.content.length > 0);
|
|
5518
5508
|
const startTimeRef = (0, react.useRef)(null);
|
|
@@ -5642,7 +5632,7 @@ window.parent.postMessage({jsonrpc:"2.0",method:"ui/notifications/sandbox-proxy-
|
|
|
5642
5632
|
"data-testid": "copilot-suggestion",
|
|
5643
5633
|
"data-slot": "suggestion-pill",
|
|
5644
5634
|
className: cn(baseClasses, className),
|
|
5645
|
-
type: type
|
|
5635
|
+
type: type ?? "button",
|
|
5646
5636
|
"aria-busy": isLoading || void 0,
|
|
5647
5637
|
disabled: isLoading || props.disabled,
|
|
5648
5638
|
...props,
|
|
@@ -5691,16 +5681,15 @@ window.parent.postMessage({jsonrpc:"2.0",method:"ui/notifications/sandbox-proxy-
|
|
|
5691
5681
|
className: suggestion.className,
|
|
5692
5682
|
isLoading,
|
|
5693
5683
|
type: "button",
|
|
5694
|
-
onClick: () => onSelectSuggestion
|
|
5684
|
+
onClick: () => onSelectSuggestion?.(suggestion, index)
|
|
5695
5685
|
});
|
|
5696
5686
|
return react.default.cloneElement(pill, { key: `${suggestion.title}-${index}` });
|
|
5697
5687
|
});
|
|
5698
5688
|
const boundContainer = react.default.cloneElement(ContainerElement, void 0, suggestionElements);
|
|
5699
5689
|
if (typeof children === "function") {
|
|
5700
|
-
var _suggestions$0$title, _suggestions$, _suggestions$2;
|
|
5701
5690
|
const sampleSuggestion = renderSlot(suggestionSlot, CopilotChatSuggestionPill, {
|
|
5702
|
-
children:
|
|
5703
|
-
isLoading: suggestions.length > 0 ? loadingSet.has(0) ||
|
|
5691
|
+
children: suggestions[0]?.title ?? "",
|
|
5692
|
+
isLoading: suggestions.length > 0 ? loadingSet.has(0) || suggestions[0]?.isLoading === true : false,
|
|
5704
5693
|
type: "button"
|
|
5705
5694
|
});
|
|
5706
5695
|
return /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
|
|
@@ -5832,10 +5821,7 @@ window.parent.postMessage({jsonrpc:"2.0",method:"ui/notifications/sandbox-proxy-
|
|
|
5832
5821
|
if (message.role !== "assistant") return [];
|
|
5833
5822
|
const tcs = Array.isArray(message.toolCalls) ? message.toolCalls : [];
|
|
5834
5823
|
const ids = [];
|
|
5835
|
-
for (const tc of tcs)
|
|
5836
|
-
var _tc$function;
|
|
5837
|
-
if (isMatchingToolCallName(tc === null || tc === void 0 || (_tc$function = tc.function) === null || _tc$function === void 0 ? void 0 : _tc$function.name) && (tc === null || tc === void 0 ? void 0 : tc.id)) ids.push(tc.id);
|
|
5838
|
-
}
|
|
5824
|
+
for (const tc of tcs) if (isMatchingToolCallName(tc?.function?.name) && tc?.id) ids.push(tc.id);
|
|
5839
5825
|
return ids;
|
|
5840
5826
|
}, [message]);
|
|
5841
5827
|
const hasPending = (0, react.useMemo)(() => {
|
|
@@ -5879,18 +5865,12 @@ window.parent.postMessage({jsonrpc:"2.0",method:"ui/notifications/sandbox-proxy-
|
|
|
5879
5865
|
if (!config) return null;
|
|
5880
5866
|
if (phase === "idle" || phase === "hidden") return null;
|
|
5881
5867
|
if (message.role !== "assistant") return null;
|
|
5882
|
-
if (!(Array.isArray(message.toolCalls) ? message.toolCalls : []).some((tc) =>
|
|
5883
|
-
var _tc$function2;
|
|
5884
|
-
return isMatchingToolCallName(tc === null || tc === void 0 || (_tc$function2 = tc.function) === null || _tc$function2 === void 0 ? void 0 : _tc$function2.name);
|
|
5885
|
-
})) return null;
|
|
5868
|
+
if (!(Array.isArray(message.toolCalls) ? message.toolCalls : []).some((tc) => isMatchingToolCallName(tc?.function?.name))) return null;
|
|
5886
5869
|
let latestMatchingAssistantId;
|
|
5887
5870
|
for (let i = agent.messages.length - 1; i >= 0; i -= 1) {
|
|
5888
5871
|
const m = agent.messages[i];
|
|
5889
5872
|
if (m.role !== "assistant") continue;
|
|
5890
|
-
if ((Array.isArray(m.toolCalls) ? m.toolCalls : []).some((tc) => {
|
|
5891
|
-
var _tc$function3;
|
|
5892
|
-
return isMatchingToolCallName(tc === null || tc === void 0 || (_tc$function3 = tc.function) === null || _tc$function3 === void 0 ? void 0 : _tc$function3.name);
|
|
5893
|
-
})) {
|
|
5873
|
+
if ((Array.isArray(m.toolCalls) ? m.toolCalls : []).some((tc) => isMatchingToolCallName(tc?.function?.name))) {
|
|
5894
5874
|
latestMatchingAssistantId = m.id;
|
|
5895
5875
|
break;
|
|
5896
5876
|
}
|
|
@@ -5966,12 +5946,11 @@ window.parent.postMessage({jsonrpc:"2.0",method:"ui/notifications/sandbox-proxy-
|
|
|
5966
5946
|
...slotProps
|
|
5967
5947
|
});
|
|
5968
5948
|
}, (prevProps, nextProps) => {
|
|
5969
|
-
var _nextProps$messages;
|
|
5970
5949
|
if (prevProps.message.id !== nextProps.message.id) return false;
|
|
5971
5950
|
if (prevProps.message.content !== nextProps.message.content) return false;
|
|
5972
5951
|
const prevToolCalls = prevProps.message.toolCalls;
|
|
5973
5952
|
const nextToolCalls = nextProps.message.toolCalls;
|
|
5974
|
-
if (
|
|
5953
|
+
if (prevToolCalls?.length !== nextToolCalls?.length) return false;
|
|
5975
5954
|
if (prevToolCalls && nextToolCalls) for (let i = 0; i < prevToolCalls.length; i++) {
|
|
5976
5955
|
const prevTc = prevToolCalls[i];
|
|
5977
5956
|
const nextTc = nextToolCalls[i];
|
|
@@ -5985,7 +5964,7 @@ window.parent.postMessage({jsonrpc:"2.0",method:"ui/notifications/sandbox-proxy-
|
|
|
5985
5964
|
if (prevToolResults.length !== nextToolResults.length) return false;
|
|
5986
5965
|
for (let i = 0; i < prevToolResults.length; i++) if (prevToolResults[i].content !== nextToolResults[i].content) return false;
|
|
5987
5966
|
}
|
|
5988
|
-
if (
|
|
5967
|
+
if (nextProps.messages[nextProps.messages.length - 1]?.id === nextProps.message.id && prevProps.isRunning !== nextProps.isRunning) return false;
|
|
5989
5968
|
if (prevProps.AssistantMessageComponent !== nextProps.AssistantMessageComponent) return false;
|
|
5990
5969
|
if (prevProps.slotProps !== nextProps.slotProps) return false;
|
|
5991
5970
|
return true;
|
|
@@ -6027,11 +6006,10 @@ window.parent.postMessage({jsonrpc:"2.0",method:"ui/notifications/sandbox-proxy-
|
|
|
6027
6006
|
...slotProps
|
|
6028
6007
|
});
|
|
6029
6008
|
}, (prevProps, nextProps) => {
|
|
6030
|
-
var _prevProps$messages, _nextProps$messages2;
|
|
6031
6009
|
if (prevProps.message.id !== nextProps.message.id) return false;
|
|
6032
6010
|
if (prevProps.message.content !== nextProps.message.content) return false;
|
|
6033
|
-
const prevIsLatest =
|
|
6034
|
-
const nextIsLatest =
|
|
6011
|
+
const prevIsLatest = prevProps.messages[prevProps.messages.length - 1]?.id === prevProps.message.id;
|
|
6012
|
+
const nextIsLatest = nextProps.messages[nextProps.messages.length - 1]?.id === nextProps.message.id;
|
|
6035
6013
|
if (prevIsLatest !== nextIsLatest) return false;
|
|
6036
6014
|
if (nextIsLatest && prevProps.isRunning !== nextProps.isRunning) return false;
|
|
6037
6015
|
if (prevProps.ReasoningMessageComponent !== nextProps.ReasoningMessageComponent) return false;
|
|
@@ -6069,9 +6047,8 @@ window.parent.postMessage({jsonrpc:"2.0",method:"ui/notifications/sandbox-proxy-
|
|
|
6069
6047
|
for (const message of messages) {
|
|
6070
6048
|
const existing = acc.get(message.id);
|
|
6071
6049
|
if (existing && message.role === "assistant" && existing.role === "assistant") {
|
|
6072
|
-
var _message$toolCalls;
|
|
6073
6050
|
const content = message.content || existing.content;
|
|
6074
|
-
const toolCalls =
|
|
6051
|
+
const toolCalls = message.toolCalls ?? existing.toolCalls;
|
|
6075
6052
|
acc.set(message.id, {
|
|
6076
6053
|
...existing,
|
|
6077
6054
|
...message,
|
|
@@ -6084,20 +6061,19 @@ window.parent.postMessage({jsonrpc:"2.0",method:"ui/notifications/sandbox-proxy-
|
|
|
6084
6061
|
}
|
|
6085
6062
|
const VIRTUALIZE_THRESHOLD = 50;
|
|
6086
6063
|
function CopilotChatMessageView({ messages = [], assistantMessage, userMessage, reasoningMessage, cursor, isRunning = false, children, className, ...props }) {
|
|
6087
|
-
var _deduplicatedMessages;
|
|
6088
6064
|
const renderCustomMessage = useRenderCustomMessages();
|
|
6089
6065
|
const { renderActivityMessage } = useRenderActivityMessage();
|
|
6090
6066
|
const { copilotkit } = useCopilotKit();
|
|
6091
6067
|
const config = useCopilotChatConfiguration();
|
|
6092
6068
|
const [, forceUpdate] = (0, react.useReducer)((x) => x + 1, 0);
|
|
6093
6069
|
(0, react.useEffect)(() => {
|
|
6094
|
-
if (!
|
|
6070
|
+
if (!config?.agentId) return;
|
|
6095
6071
|
const agent = copilotkit.getAgent(config.agentId);
|
|
6096
6072
|
if (!agent) return;
|
|
6097
6073
|
const subscription = agent.subscribe({ onStateChanged: forceUpdate });
|
|
6098
6074
|
return () => subscription.unsubscribe();
|
|
6099
6075
|
}, [
|
|
6100
|
-
config
|
|
6076
|
+
config?.agentId,
|
|
6101
6077
|
copilotkit,
|
|
6102
6078
|
forceUpdate
|
|
6103
6079
|
]);
|
|
@@ -6110,9 +6086,8 @@ window.parent.postMessage({jsonrpc:"2.0",method:"ui/notifications/sandbox-proxy-
|
|
|
6110
6086
|
return () => subscription.unsubscribe();
|
|
6111
6087
|
}, [copilotkit]);
|
|
6112
6088
|
const getStateSnapshotForMessage = (messageId) => {
|
|
6113
|
-
var _copilotkit$getRunIdF;
|
|
6114
6089
|
if (!config) return void 0;
|
|
6115
|
-
const resolvedRunId =
|
|
6090
|
+
const resolvedRunId = copilotkit.getRunIdForMessage(config.agentId, config.threadId, messageId) ?? copilotkit.getRunIdsForThread(config.agentId, config.threadId).slice(-1)[0];
|
|
6116
6091
|
if (!resolvedRunId) return void 0;
|
|
6117
6092
|
return copilotkit.getStateByRun(config.agentId, config.threadId, resolvedRunId);
|
|
6118
6093
|
};
|
|
@@ -6132,19 +6107,17 @@ window.parent.postMessage({jsonrpc:"2.0",method:"ui/notifications/sandbox-proxy-
|
|
|
6132
6107
|
getScrollElement: () => scrollElement,
|
|
6133
6108
|
estimateSize: () => 100,
|
|
6134
6109
|
overscan: 5,
|
|
6135
|
-
measureElement: (el) =>
|
|
6136
|
-
var _el$getBoundingClient;
|
|
6137
|
-
return (_el$getBoundingClient = el === null || el === void 0 ? void 0 : el.getBoundingClientRect().height) !== null && _el$getBoundingClient !== void 0 ? _el$getBoundingClient : 0;
|
|
6138
|
-
},
|
|
6110
|
+
measureElement: (el) => el?.getBoundingClientRect().height ?? 0,
|
|
6139
6111
|
initialRect: {
|
|
6140
6112
|
width: 0,
|
|
6141
6113
|
height: 600
|
|
6142
6114
|
}
|
|
6143
6115
|
});
|
|
6116
|
+
const firstMessageId = deduplicatedMessages[0]?.id;
|
|
6144
6117
|
(0, react.useLayoutEffect)(() => {
|
|
6145
6118
|
if (!shouldVirtualize || !deduplicatedMessages.length) return;
|
|
6146
6119
|
virtualizer.scrollToIndex(deduplicatedMessages.length - 1, { align: "end" });
|
|
6147
|
-
}, [shouldVirtualize,
|
|
6120
|
+
}, [shouldVirtualize, firstMessageId]);
|
|
6148
6121
|
const renderMessageBlock = (message) => {
|
|
6149
6122
|
const elements = [];
|
|
6150
6123
|
const stateSnapshot = getStateSnapshotForMessage(message.id);
|
|
@@ -6183,13 +6156,10 @@ window.parent.postMessage({jsonrpc:"2.0",method:"ui/notifications/sandbox-proxy-
|
|
|
6183
6156
|
renderCustomMessage,
|
|
6184
6157
|
stateSnapshot
|
|
6185
6158
|
}, `${message.id}-custom-after`));
|
|
6186
|
-
if (copilotkit.intelligence !== void 0 && message.role === "assistant") {
|
|
6187
|
-
|
|
6188
|
-
|
|
6189
|
-
|
|
6190
|
-
agentId: (_config$agentId = config === null || config === void 0 ? void 0 : config.agentId) !== null && _config$agentId !== void 0 ? _config$agentId : _copilotkit_shared.DEFAULT_AGENT_ID
|
|
6191
|
-
}, `${message.id}-intelligence`));
|
|
6192
|
-
}
|
|
6159
|
+
if (copilotkit.intelligence !== void 0 && message.role === "assistant") elements.push(/* @__PURE__ */ (0, react_jsx_runtime.jsx)(IntelligenceIndicator, {
|
|
6160
|
+
message,
|
|
6161
|
+
agentId: config?.agentId ?? _copilotkit_shared.DEFAULT_AGENT_ID
|
|
6162
|
+
}, `${message.id}-intelligence`));
|
|
6193
6163
|
return elements.filter(Boolean);
|
|
6194
6164
|
};
|
|
6195
6165
|
const messageElements = shouldVirtualize ? [] : deduplicatedMessages.flatMap(renderMessageBlock);
|
|
@@ -6204,7 +6174,7 @@ window.parent.postMessage({jsonrpc:"2.0",method:"ui/notifications/sandbox-proxy-
|
|
|
6204
6174
|
})
|
|
6205
6175
|
});
|
|
6206
6176
|
const lastMessage = messages[messages.length - 1];
|
|
6207
|
-
const showCursor = isRunning &&
|
|
6177
|
+
const showCursor = isRunning && lastMessage?.role !== "reasoning";
|
|
6208
6178
|
return /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
|
|
6209
6179
|
"data-copilotkit": true,
|
|
6210
6180
|
"data-testid": "copilot-message-list",
|
|
@@ -6413,7 +6383,7 @@ window.parent.postMessage({jsonrpc:"2.0",method:"ui/notifications/sandbox-proxy-
|
|
|
6413
6383
|
const textContent = attachment.source.type === "data" ? (() => {
|
|
6414
6384
|
try {
|
|
6415
6385
|
return atob(attachment.source.value);
|
|
6416
|
-
} catch
|
|
6386
|
+
} catch {
|
|
6417
6387
|
return attachment.source.value;
|
|
6418
6388
|
}
|
|
6419
6389
|
})() : null;
|
|
@@ -6439,7 +6409,7 @@ window.parent.postMessage({jsonrpc:"2.0",method:"ui/notifications/sandbox-proxy-
|
|
|
6439
6409
|
children: [
|
|
6440
6410
|
/* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
|
|
6441
6411
|
className: "cpk:w-16 cpk:h-16 cpk:rounded-xl cpk:bg-primary cpk:text-primary-foreground cpk:flex cpk:items-center cpk:justify-center cpk:text-xl cpk:font-bold",
|
|
6442
|
-
children: (0, _copilotkit_shared.getDocumentIcon)(mimeType
|
|
6412
|
+
children: (0, _copilotkit_shared.getDocumentIcon)(mimeType ?? "")
|
|
6443
6413
|
}),
|
|
6444
6414
|
/* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
|
|
6445
6415
|
className: "cpk:text-center",
|
|
@@ -6468,7 +6438,7 @@ window.parent.postMessage({jsonrpc:"2.0",method:"ui/notifications/sandbox-proxy-
|
|
|
6468
6438
|
onClick: previewable ? openLightbox : void 0,
|
|
6469
6439
|
children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
|
|
6470
6440
|
className: "cpk:w-8 cpk:h-8 cpk:rounded-md cpk:bg-primary cpk:text-primary-foreground cpk:flex cpk:items-center cpk:justify-center cpk:text-[10px] cpk:font-semibold cpk:shrink-0",
|
|
6471
|
-
children: (0, _copilotkit_shared.getDocumentIcon)(mimeType
|
|
6441
|
+
children: (0, _copilotkit_shared.getDocumentIcon)(mimeType ?? "")
|
|
6472
6442
|
}), /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
|
|
6473
6443
|
className: "cpk:flex cpk:flex-col cpk:min-w-0",
|
|
6474
6444
|
children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
|
|
@@ -6728,13 +6698,13 @@ window.parent.postMessage({jsonrpc:"2.0",method:"ui/notifications/sandbox-proxy-
|
|
|
6728
6698
|
className: "cpk:w-full",
|
|
6729
6699
|
children: [attachments && attachments.length > 0 && /* @__PURE__ */ (0, react_jsx_runtime.jsx)(CopilotChatAttachmentQueue, {
|
|
6730
6700
|
attachments,
|
|
6731
|
-
onRemoveAttachment: (id) => onRemoveAttachment
|
|
6701
|
+
onRemoveAttachment: (id) => onRemoveAttachment?.(id),
|
|
6732
6702
|
className: "cpk:mb-2"
|
|
6733
6703
|
}), BoundInputForWelcome]
|
|
6734
6704
|
});
|
|
6735
6705
|
const BoundWelcomeScreen = renderSlot(welcomeScreenSlot, CopilotChatView.WelcomeScreen, {
|
|
6736
6706
|
input: inputWithAttachments,
|
|
6737
|
-
suggestionView: BoundSuggestionView
|
|
6707
|
+
suggestionView: BoundSuggestionView ?? /* @__PURE__ */ (0, react_jsx_runtime.jsx)(react_jsx_runtime.Fragment, {})
|
|
6738
6708
|
});
|
|
6739
6709
|
return /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
|
|
6740
6710
|
"data-copilotkit": true,
|
|
@@ -6755,7 +6725,7 @@ window.parent.postMessage({jsonrpc:"2.0",method:"ui/notifications/sandbox-proxy-
|
|
|
6755
6725
|
messageView: BoundMessageView,
|
|
6756
6726
|
input: BoundInput,
|
|
6757
6727
|
scrollView: BoundScrollView,
|
|
6758
|
-
suggestionView: BoundSuggestionView
|
|
6728
|
+
suggestionView: BoundSuggestionView ?? /* @__PURE__ */ (0, react_jsx_runtime.jsx)(react_jsx_runtime.Fragment, {})
|
|
6759
6729
|
})
|
|
6760
6730
|
});
|
|
6761
6731
|
return /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
|
|
@@ -6778,7 +6748,7 @@ window.parent.postMessage({jsonrpc:"2.0",method:"ui/notifications/sandbox-proxy-
|
|
|
6778
6748
|
className: "cpk:max-w-3xl cpk:mx-auto cpk:w-full cpk:pointer-events-auto",
|
|
6779
6749
|
children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(CopilotChatAttachmentQueue, {
|
|
6780
6750
|
attachments,
|
|
6781
|
-
onRemoveAttachment: (id) => onRemoveAttachment
|
|
6751
|
+
onRemoveAttachment: (id) => onRemoveAttachment?.(id),
|
|
6782
6752
|
className: "cpk:px-4"
|
|
6783
6753
|
})
|
|
6784
6754
|
}), BoundInput]
|
|
@@ -6791,8 +6761,7 @@ window.parent.postMessage({jsonrpc:"2.0",method:"ui/notifications/sandbox-proxy-
|
|
|
6791
6761
|
const { isAtBottom, scrollToBottom, scrollRef } = (0, use_stick_to_bottom.useStickToBottomContext)();
|
|
6792
6762
|
const [scrollEl, setScrollEl] = (0, react.useState)(null);
|
|
6793
6763
|
(0, react.useLayoutEffect)(() => {
|
|
6794
|
-
|
|
6795
|
-
setScrollEl((_scrollRef$current = scrollRef.current) !== null && _scrollRef$current !== void 0 ? _scrollRef$current : null);
|
|
6764
|
+
setScrollEl(scrollRef.current ?? null);
|
|
6796
6765
|
}, []);
|
|
6797
6766
|
const BoundFeather = renderSlot(feather, CopilotChatView.Feather, {});
|
|
6798
6767
|
return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(ScrollElementContext.Provider, {
|
|
@@ -6970,9 +6939,7 @@ window.parent.postMessage({jsonrpc:"2.0",method:"ui/notifications/sandbox-proxy-
|
|
|
6970
6939
|
...props
|
|
6971
6940
|
});
|
|
6972
6941
|
_CopilotChatView.WelcomeMessage = ({ className, ...props }) => {
|
|
6973
|
-
|
|
6974
|
-
const config = useCopilotChatConfiguration();
|
|
6975
|
-
const labels = (_config$labels = config === null || config === void 0 ? void 0 : config.labels) !== null && _config$labels !== void 0 ? _config$labels : CopilotChatDefaultLabels;
|
|
6942
|
+
const labels = useCopilotChatConfiguration()?.labels ?? CopilotChatDefaultLabels;
|
|
6976
6943
|
return /* @__PURE__ */ (0, react_jsx_runtime.jsx)("h1", {
|
|
6977
6944
|
className: cn("cpk:text-xl cpk:sm:text-2xl cpk:font-medium cpk:text-foreground cpk:text-center", className),
|
|
6978
6945
|
...props,
|
|
@@ -7028,7 +6995,7 @@ window.parent.postMessage({jsonrpc:"2.0",method:"ui/notifications/sandbox-proxy-
|
|
|
7028
6995
|
const reader = new FileReader();
|
|
7029
6996
|
reader.onloadend = () => {
|
|
7030
6997
|
const base64 = reader.result.split(",")[1];
|
|
7031
|
-
resolve(base64
|
|
6998
|
+
resolve(base64 ?? "");
|
|
7032
6999
|
};
|
|
7033
7000
|
reader.onerror = () => reject(/* @__PURE__ */ new Error("Failed to read audio data"));
|
|
7034
7001
|
reader.readAsDataURL(blob);
|
|
@@ -7044,11 +7011,10 @@ window.parent.postMessage({jsonrpc:"2.0",method:"ui/notifications/sandbox-proxy-
|
|
|
7044
7011
|
* Parse error info from a transcription error response
|
|
7045
7012
|
*/
|
|
7046
7013
|
function parseTranscriptionError(response) {
|
|
7047
|
-
var _response$retryable;
|
|
7048
7014
|
return {
|
|
7049
7015
|
code: response.error,
|
|
7050
7016
|
message: response.message,
|
|
7051
|
-
retryable:
|
|
7017
|
+
retryable: response.retryable ?? false
|
|
7052
7018
|
};
|
|
7053
7019
|
}
|
|
7054
7020
|
/**
|
|
@@ -7115,7 +7081,7 @@ window.parent.postMessage({jsonrpc:"2.0",method:"ui/notifications/sandbox-proxy-
|
|
|
7115
7081
|
let errorData;
|
|
7116
7082
|
try {
|
|
7117
7083
|
errorData = await response.json();
|
|
7118
|
-
} catch
|
|
7084
|
+
} catch {
|
|
7119
7085
|
throw new TranscriptionError({
|
|
7120
7086
|
code: _copilotkit_shared.TranscriptionErrorCode.PROVIDER_ERROR,
|
|
7121
7087
|
message: `HTTP ${response.status}: ${response.statusText}`,
|
|
@@ -7135,12 +7101,11 @@ window.parent.postMessage({jsonrpc:"2.0",method:"ui/notifications/sandbox-proxy-
|
|
|
7135
7101
|
//#endregion
|
|
7136
7102
|
//#region src/v2/components/chat/CopilotChat.tsx
|
|
7137
7103
|
function CopilotChat({ agentId, threadId, labels, chatView, isModalDefaultOpen, attachments: attachmentsConfig, onError, throttleMs, ...props }) {
|
|
7138
|
-
var _ref, _attachmentsConfig$ac;
|
|
7139
7104
|
const existingConfig = useCopilotChatConfiguration();
|
|
7140
|
-
const resolvedAgentId =
|
|
7141
|
-
const providedThreadId = threadId
|
|
7142
|
-
const resolvedThreadId = (0, react.useMemo)(() => providedThreadId
|
|
7143
|
-
const hasExplicitThreadId = !!threadId || !!
|
|
7105
|
+
const resolvedAgentId = agentId ?? existingConfig?.agentId ?? _copilotkit_shared.DEFAULT_AGENT_ID;
|
|
7106
|
+
const providedThreadId = threadId ?? existingConfig?.threadId;
|
|
7107
|
+
const resolvedThreadId = (0, react.useMemo)(() => providedThreadId ?? (0, _copilotkit_shared.randomUUID)(), [providedThreadId]);
|
|
7108
|
+
const hasExplicitThreadId = !!threadId || !!existingConfig?.hasExplicitThreadId;
|
|
7144
7109
|
const { agent } = useAgent({
|
|
7145
7110
|
agentId: resolvedAgentId,
|
|
7146
7111
|
throttleMs
|
|
@@ -7159,15 +7124,11 @@ window.parent.postMessage({jsonrpc:"2.0",method:"ui/notifications/sandbox-proxy-
|
|
|
7159
7124
|
(0, react.useEffect)(() => {
|
|
7160
7125
|
if (!onErrorRef.current) return;
|
|
7161
7126
|
const subscription = copilotkit.subscribe({ onError: (event) => {
|
|
7162
|
-
|
|
7163
|
-
|
|
7164
|
-
|
|
7165
|
-
|
|
7166
|
-
|
|
7167
|
-
code: event.code,
|
|
7168
|
-
context: event.context
|
|
7169
|
-
});
|
|
7170
|
-
}
|
|
7127
|
+
if (event.context?.agentId === resolvedAgentId || !event.context?.agentId) onErrorRef.current?.({
|
|
7128
|
+
error: event.error,
|
|
7129
|
+
code: event.code,
|
|
7130
|
+
context: event.context
|
|
7131
|
+
});
|
|
7171
7132
|
} });
|
|
7172
7133
|
return () => {
|
|
7173
7134
|
subscription.unsubscribe();
|
|
@@ -7184,14 +7145,14 @@ window.parent.postMessage({jsonrpc:"2.0",method:"ui/notifications/sandbox-proxy-
|
|
|
7184
7145
|
const [lastConnectedThreadId, setLastConnectedThreadId] = (0, react.useState)(null);
|
|
7185
7146
|
const isConnecting = hasExplicitThreadId && lastConnectedThreadId !== resolvedThreadId;
|
|
7186
7147
|
(0, react.useEffect)(() => {
|
|
7148
|
+
agent.threadId = resolvedThreadId;
|
|
7187
7149
|
if (!hasExplicitThreadId) return;
|
|
7188
7150
|
let detached = false;
|
|
7189
7151
|
const connectAbortController = new AbortController();
|
|
7190
7152
|
if (agent instanceof _ag_ui_client.HttpAgent) agent.abortController = connectAbortController;
|
|
7191
|
-
|
|
7192
|
-
const connect = async (agent) => {
|
|
7153
|
+
const connect = async (agentToConnect) => {
|
|
7193
7154
|
try {
|
|
7194
|
-
await copilotkit.connectAgent({ agent });
|
|
7155
|
+
await copilotkit.connectAgent({ agent: agentToConnect });
|
|
7195
7156
|
} catch (error) {
|
|
7196
7157
|
if (detached) return;
|
|
7197
7158
|
console.error("CopilotChat: connectAgent failed", error);
|
|
@@ -7344,8 +7305,7 @@ window.parent.postMessage({jsonrpc:"2.0",method:"ui/notifications/sandbox-proxy-
|
|
|
7344
7305
|
const stableSuggestionView = useShallowStableRef(providedSuggestionView);
|
|
7345
7306
|
const handleAddFile = (0, react.useCallback)(() => {
|
|
7346
7307
|
setTimeout(() => {
|
|
7347
|
-
|
|
7348
|
-
(_fileInputRef$current = fileInputRef.current) === null || _fileInputRef$current === void 0 || _fileInputRef$current.click();
|
|
7308
|
+
fileInputRef.current?.click();
|
|
7349
7309
|
}, 100);
|
|
7350
7310
|
}, []);
|
|
7351
7311
|
const mergedProps = {
|
|
@@ -7357,15 +7317,12 @@ window.parent.postMessage({jsonrpc:"2.0",method:"ui/notifications/sandbox-proxy-
|
|
|
7357
7317
|
};
|
|
7358
7318
|
if (stableMessageView !== void 0) mergedProps.messageView = stableMessageView;
|
|
7359
7319
|
const hasMessages = agent.messages.length > 0;
|
|
7360
|
-
const effectiveStopHandler = agent.isRunning && hasMessages ? providedStopHandler
|
|
7320
|
+
const effectiveStopHandler = agent.isRunning && hasMessages ? providedStopHandler ?? stopCurrentRun : providedStopHandler;
|
|
7361
7321
|
const showTranscription = isTranscriptionEnabled && isMediaRecorderSupported;
|
|
7362
7322
|
const effectiveMode = isTranscribing ? "processing" : transcribeMode;
|
|
7363
7323
|
const messages = (0, react.useMemo)(() => [...agent.messages], [agent.messages.map((m) => {
|
|
7364
7324
|
const contentKey = typeof m.content === "string" ? m.content.length : Array.isArray(m.content) ? m.content.length : 0;
|
|
7365
|
-
const toolCallsKey = "toolCalls" in m && Array.isArray(m.toolCalls) ? m.toolCalls.map((tc) => {
|
|
7366
|
-
var _tc$function$argument, _tc$function;
|
|
7367
|
-
return `${tc.id}:${(_tc$function$argument = (_tc$function = tc.function) === null || _tc$function === void 0 || (_tc$function = _tc$function.arguments) === null || _tc$function === void 0 ? void 0 : _tc$function.length) !== null && _tc$function$argument !== void 0 ? _tc$function$argument : 0}`;
|
|
7368
|
-
}).join(";") : "";
|
|
7325
|
+
const toolCallsKey = "toolCalls" in m && Array.isArray(m.toolCalls) ? m.toolCalls.map((tc) => `${tc.id}:${tc.function?.arguments?.length ?? 0}`).join(";") : "";
|
|
7369
7326
|
return `${m.id}:${m.role}:${contentKey}:${toolCallsKey}`;
|
|
7370
7327
|
}).join(",")]);
|
|
7371
7328
|
const lastUserMessageId = (0, react.useMemo)(() => {
|
|
@@ -7421,7 +7378,7 @@ window.parent.postMessage({jsonrpc:"2.0",method:"ui/notifications/sandbox-proxy-
|
|
|
7421
7378
|
multiple: true,
|
|
7422
7379
|
ref: fileInputRef,
|
|
7423
7380
|
onChange: handleFileUpload,
|
|
7424
|
-
accept:
|
|
7381
|
+
accept: attachmentsConfig?.accept ?? "*/*",
|
|
7425
7382
|
style: { display: "none" }
|
|
7426
7383
|
}),
|
|
7427
7384
|
!isChatLicensed && /* @__PURE__ */ (0, react_jsx_runtime.jsx)(InlineFeatureWarning, { featureName: "Chat" }),
|
|
@@ -7471,13 +7428,12 @@ window.parent.postMessage({jsonrpc:"2.0",method:"ui/notifications/sandbox-proxy-
|
|
|
7471
7428
|
const ICON_WRAPPER_BASE = "cpk:pointer-events-none cpk:absolute cpk:inset-0 cpk:flex cpk:items-center cpk:justify-center cpk:will-change-transform";
|
|
7472
7429
|
const BUTTON_BASE_CLASSES = cn("copilotKitButton", "cpk:fixed cpk:bottom-6 cpk:right-6 cpk:z-[1100] cpk:flex cpk:h-14 cpk:w-14 cpk:items-center cpk:justify-center", "cpk:rounded-full cpk:border cpk:border-primary cpk:bg-primary cpk:text-primary-foreground", "cpk:shadow-sm cpk:transition-all cpk:duration-200 cpk:ease-out", "cpk:hover:scale-[1.04] cpk:hover:shadow-md", "cpk:cursor-pointer", "cpk:active:scale-[0.96]", "cpk:focus-visible:outline-none cpk:focus-visible:ring-2 cpk:focus-visible:ring-primary/50 cpk:focus-visible:ring-offset-2 cpk:focus-visible:ring-offset-background", "cpk:disabled:pointer-events-none cpk:disabled:opacity-60");
|
|
7473
7430
|
const CopilotChatToggleButton = react.default.forwardRef(function CopilotChatToggleButton({ openIcon, closeIcon, className, ...buttonProps }, ref) {
|
|
7474
|
-
var _configuration$labels, _configuration$isModa, _configuration$setMod;
|
|
7475
7431
|
const { onClick, type, disabled, ...restProps } = buttonProps;
|
|
7476
7432
|
const configuration = useCopilotChatConfiguration();
|
|
7477
|
-
const labels =
|
|
7433
|
+
const labels = configuration?.labels ?? CopilotChatDefaultLabels;
|
|
7478
7434
|
const [fallbackOpen, setFallbackOpen] = (0, react.useState)(false);
|
|
7479
|
-
const isOpen =
|
|
7480
|
-
const setModalOpen =
|
|
7435
|
+
const isOpen = configuration?.isModalOpen ?? fallbackOpen;
|
|
7436
|
+
const setModalOpen = configuration?.setModalOpen ?? setFallbackOpen;
|
|
7481
7437
|
const handleClick = (event) => {
|
|
7482
7438
|
if (disabled) return;
|
|
7483
7439
|
if (onClick) onClick(event);
|
|
@@ -7518,7 +7474,7 @@ window.parent.postMessage({jsonrpc:"2.0",method:"ui/notifications/sandbox-proxy-
|
|
|
7518
7474
|
});
|
|
7519
7475
|
return /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("button", {
|
|
7520
7476
|
ref,
|
|
7521
|
-
type: type
|
|
7477
|
+
type: type ?? "button",
|
|
7522
7478
|
"data-copilotkit": true,
|
|
7523
7479
|
"data-testid": "copilot-chat-toggle",
|
|
7524
7480
|
"data-slot": "chat-toggle-button",
|
|
@@ -7537,13 +7493,11 @@ window.parent.postMessage({jsonrpc:"2.0",method:"ui/notifications/sandbox-proxy-
|
|
|
7537
7493
|
//#endregion
|
|
7538
7494
|
//#region src/v2/components/chat/CopilotModalHeader.tsx
|
|
7539
7495
|
function CopilotModalHeader({ title, titleContent, closeButton, children, className, ...rest }) {
|
|
7540
|
-
var _configuration$labels;
|
|
7541
7496
|
const configuration = useCopilotChatConfiguration();
|
|
7542
|
-
const fallbackTitle =
|
|
7543
|
-
const resolvedTitle = title
|
|
7497
|
+
const fallbackTitle = configuration?.labels.modalHeaderTitle ?? CopilotChatDefaultLabels.modalHeaderTitle;
|
|
7498
|
+
const resolvedTitle = title ?? fallbackTitle;
|
|
7544
7499
|
const handleClose = (0, react.useCallback)(() => {
|
|
7545
|
-
|
|
7546
|
-
configuration === null || configuration === void 0 || (_configuration$setMod = configuration.setModalOpen) === null || _configuration$setMod === void 0 || _configuration$setMod.call(configuration, false);
|
|
7500
|
+
configuration?.setModalOpen?.(false);
|
|
7547
7501
|
}, [configuration]);
|
|
7548
7502
|
const BoundTitle = renderSlot(titleContent, CopilotModalHeader.Title, { children: resolvedTitle });
|
|
7549
7503
|
const BoundCloseButton = renderSlot(closeButton, CopilotModalHeader.CloseButton, { onClick: handleClose });
|
|
@@ -7617,11 +7571,9 @@ window.parent.postMessage({jsonrpc:"2.0",method:"ui/notifications/sandbox-proxy-
|
|
|
7617
7571
|
});
|
|
7618
7572
|
}
|
|
7619
7573
|
function CopilotSidebarViewInternal({ header, toggleButton, width, position = "right", ...props }) {
|
|
7620
|
-
|
|
7621
|
-
const configuration = useCopilotChatConfiguration();
|
|
7622
|
-
const isSidebarOpen = (_configuration$isModa = configuration === null || configuration === void 0 ? void 0 : configuration.isModalOpen) !== null && _configuration$isModa !== void 0 ? _configuration$isModa : false;
|
|
7574
|
+
const isSidebarOpen = useCopilotChatConfiguration()?.isModalOpen ?? false;
|
|
7623
7575
|
const sidebarRef = (0, react.useRef)(null);
|
|
7624
|
-
const [sidebarWidth, setSidebarWidth] = (0, react.useState)(width
|
|
7576
|
+
const [sidebarWidth, setSidebarWidth] = (0, react.useState)(width ?? DEFAULT_SIDEBAR_WIDTH);
|
|
7625
7577
|
const widthToCss = (w) => {
|
|
7626
7578
|
return typeof w === "number" ? `${w}px` : w;
|
|
7627
7579
|
};
|
|
@@ -7755,11 +7707,10 @@ window.parent.postMessage({jsonrpc:"2.0",method:"ui/notifications/sandbox-proxy-
|
|
|
7755
7707
|
});
|
|
7756
7708
|
}
|
|
7757
7709
|
function CopilotPopupViewInternal({ header, toggleButton, width, height, clickOutsideToClose, className, ...restProps }) {
|
|
7758
|
-
var _configuration$isModa, _configuration$labels;
|
|
7759
7710
|
const configuration = useCopilotChatConfiguration();
|
|
7760
|
-
const isPopupOpen =
|
|
7761
|
-
const setModalOpen = configuration
|
|
7762
|
-
const labels =
|
|
7711
|
+
const isPopupOpen = configuration?.isModalOpen ?? false;
|
|
7712
|
+
const setModalOpen = configuration?.setModalOpen;
|
|
7713
|
+
const labels = configuration?.labels ?? CopilotChatDefaultLabels;
|
|
7763
7714
|
const containerRef = (0, react.useRef)(null);
|
|
7764
7715
|
const [isRendered, setIsRendered] = (0, react.useState)(isPopupOpen);
|
|
7765
7716
|
const [isAnimatingOut, setIsAnimatingOut] = (0, react.useState)(false);
|
|
@@ -7783,7 +7734,7 @@ window.parent.postMessage({jsonrpc:"2.0",method:"ui/notifications/sandbox-proxy-
|
|
|
7783
7734
|
const handleKeyDown = (event) => {
|
|
7784
7735
|
if (event.key === "Escape") {
|
|
7785
7736
|
event.preventDefault();
|
|
7786
|
-
setModalOpen
|
|
7737
|
+
setModalOpen?.(false);
|
|
7787
7738
|
}
|
|
7788
7739
|
};
|
|
7789
7740
|
window.addEventListener("keydown", handleKeyDown);
|
|
@@ -7803,11 +7754,10 @@ window.parent.postMessage({jsonrpc:"2.0",method:"ui/notifications/sandbox-proxy-
|
|
|
7803
7754
|
const handlePointerDown = (event) => {
|
|
7804
7755
|
const target = event.target;
|
|
7805
7756
|
if (!target) return;
|
|
7806
|
-
|
|
7807
|
-
if (container === null || container === void 0 ? void 0 : container.contains(target)) return;
|
|
7757
|
+
if (containerRef.current?.contains(target)) return;
|
|
7808
7758
|
const toggleButton = document.querySelector("[data-slot='chat-toggle-button']");
|
|
7809
7759
|
if (toggleButton && toggleButton.contains(target)) return;
|
|
7810
|
-
setModalOpen
|
|
7760
|
+
setModalOpen?.(false);
|
|
7811
7761
|
};
|
|
7812
7762
|
document.addEventListener("pointerdown", handlePointerDown);
|
|
7813
7763
|
return () => document.removeEventListener("pointerdown", handlePointerDown);
|
|
@@ -7897,11 +7847,11 @@ window.parent.postMessage({jsonrpc:"2.0",method:"ui/notifications/sandbox-proxy-
|
|
|
7897
7847
|
const { header: viewHeader, toggleButton: viewToggleButton, width: viewWidth, defaultOpen: viewDefaultOpen, position: viewPosition, ...restProps } = viewProps;
|
|
7898
7848
|
return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(CopilotSidebarView, {
|
|
7899
7849
|
...restProps,
|
|
7900
|
-
header: header
|
|
7901
|
-
toggleButton: toggleButton
|
|
7902
|
-
width: width
|
|
7903
|
-
defaultOpen: defaultOpen
|
|
7904
|
-
position: position
|
|
7850
|
+
header: header ?? viewHeader,
|
|
7851
|
+
toggleButton: toggleButton ?? viewToggleButton,
|
|
7852
|
+
width: width ?? viewWidth,
|
|
7853
|
+
defaultOpen: defaultOpen ?? viewDefaultOpen,
|
|
7854
|
+
position: position ?? viewPosition
|
|
7905
7855
|
});
|
|
7906
7856
|
};
|
|
7907
7857
|
return Object.assign(Component, CopilotChatView_default);
|
|
@@ -7934,12 +7884,12 @@ window.parent.postMessage({jsonrpc:"2.0",method:"ui/notifications/sandbox-proxy-
|
|
|
7934
7884
|
const { header: viewHeader, toggleButton: viewToggleButton, width: viewWidth, height: viewHeight, clickOutsideToClose: viewClickOutsideToClose, defaultOpen: viewDefaultOpen, ...restProps } = viewProps;
|
|
7935
7885
|
return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(CopilotPopupView_default, {
|
|
7936
7886
|
...restProps,
|
|
7937
|
-
header: header
|
|
7938
|
-
toggleButton: toggleButton
|
|
7939
|
-
width: width
|
|
7940
|
-
height: height
|
|
7941
|
-
clickOutsideToClose: clickOutsideToClose
|
|
7942
|
-
defaultOpen: defaultOpen
|
|
7887
|
+
header: header ?? viewHeader,
|
|
7888
|
+
toggleButton: toggleButton ?? viewToggleButton,
|
|
7889
|
+
width: width ?? viewWidth,
|
|
7890
|
+
height: height ?? viewHeight,
|
|
7891
|
+
clickOutsideToClose: clickOutsideToClose ?? viewClickOutsideToClose,
|
|
7892
|
+
defaultOpen: defaultOpen ?? viewDefaultOpen
|
|
7943
7893
|
});
|
|
7944
7894
|
};
|
|
7945
7895
|
return Object.assign(Component, CopilotChatView_default);
|
|
@@ -8006,7 +7956,7 @@ window.parent.postMessage({jsonrpc:"2.0",method:"ui/notifications/sandbox-proxy-
|
|
|
8006
7956
|
children: "Arguments"
|
|
8007
7957
|
}), /* @__PURE__ */ (0, react_jsx_runtime.jsx)("pre", {
|
|
8008
7958
|
className: "cpk:mt-2 cpk:max-h-64 cpk:overflow-auto cpk:rounded-md cpk:bg-zinc-50 cpk:dark:bg-zinc-800/60 cpk:p-3 cpk:text-xs cpk:leading-relaxed cpk:text-zinc-800 cpk:dark:text-zinc-200 cpk:whitespace-pre-wrap cpk:break-words",
|
|
8009
|
-
children: JSON.stringify(args
|
|
7959
|
+
children: JSON.stringify(args ?? {}, null, 2)
|
|
8010
7960
|
})] }), result !== void 0 && /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", { children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
|
|
8011
7961
|
className: "cpk:text-xs cpk:uppercase cpk:tracking-wide cpk:text-zinc-500 cpk:dark:text-zinc-400",
|
|
8012
7962
|
children: "Result"
|
|
@@ -8351,6 +8301,7 @@ window.parent.postMessage({jsonrpc:"2.0",method:"ui/notifications/sandbox-proxy-
|
|
|
8351
8301
|
const details = bannerError.details;
|
|
8352
8302
|
const link = extractUrl(bannerError.message);
|
|
8353
8303
|
return /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
|
|
8304
|
+
"data-testid": "copilot-error-banner",
|
|
8354
8305
|
style: {
|
|
8355
8306
|
position: "fixed",
|
|
8356
8307
|
bottom: "20px",
|
|
@@ -8550,9 +8501,8 @@ window.parent.postMessage({jsonrpc:"2.0",method:"ui/notifications/sandbox-proxy-
|
|
|
8550
8501
|
setToasts((prev) => prev.filter((toast) => toast.id !== id));
|
|
8551
8502
|
}, []);
|
|
8552
8503
|
const addToast = (0, react.useCallback)((toast) => {
|
|
8553
|
-
var _toast$id;
|
|
8554
8504
|
if (!enabled) return;
|
|
8555
|
-
const id =
|
|
8505
|
+
const id = toast.id ?? Math.random().toString(36).slice(2, 9);
|
|
8556
8506
|
setToasts((currentToasts) => {
|
|
8557
8507
|
if (currentToasts.find((toast) => toast.id === id)) return currentToasts;
|
|
8558
8508
|
return [...currentToasts, {
|
|
@@ -8679,8 +8629,8 @@ window.parent.postMessage({jsonrpc:"2.0",method:"ui/notifications/sandbox-proxy-
|
|
|
8679
8629
|
]);
|
|
8680
8630
|
const createStructuredError = (gqlError) => {
|
|
8681
8631
|
const extensions = gqlError.extensions;
|
|
8682
|
-
const originalError = extensions
|
|
8683
|
-
if (originalError
|
|
8632
|
+
const originalError = extensions?.originalError;
|
|
8633
|
+
if (originalError?.stack) {
|
|
8684
8634
|
if (originalError.stack.includes("CopilotApiDiscoveryError")) return new _copilotkit_shared.CopilotKitApiDiscoveryError({ message: originalError.message });
|
|
8685
8635
|
if (originalError.stack.includes("CopilotKitRemoteEndpointDiscoveryError")) return new _copilotkit_shared.CopilotKitRemoteEndpointDiscoveryError({ message: originalError.message });
|
|
8686
8636
|
if (originalError.stack.includes("CopilotKitAgentDiscoveryError")) return new _copilotkit_shared.CopilotKitAgentDiscoveryError({
|
|
@@ -8688,8 +8638,8 @@ window.parent.postMessage({jsonrpc:"2.0",method:"ui/notifications/sandbox-proxy-
|
|
|
8688
8638
|
availableAgents: []
|
|
8689
8639
|
});
|
|
8690
8640
|
}
|
|
8691
|
-
const message =
|
|
8692
|
-
const code = extensions
|
|
8641
|
+
const message = originalError?.message || gqlError.message;
|
|
8642
|
+
const code = extensions?.code;
|
|
8693
8643
|
if (code) return new _copilotkit_shared.CopilotKitError({
|
|
8694
8644
|
message,
|
|
8695
8645
|
code
|
|
@@ -8697,12 +8647,11 @@ window.parent.postMessage({jsonrpc:"2.0",method:"ui/notifications/sandbox-proxy-
|
|
|
8697
8647
|
return null;
|
|
8698
8648
|
};
|
|
8699
8649
|
(0, react.useCallback)((error) => {
|
|
8700
|
-
|
|
8701
|
-
if ((_error$graphQLErrors = error.graphQLErrors) === null || _error$graphQLErrors === void 0 ? void 0 : _error$graphQLErrors.length) {
|
|
8650
|
+
if (error.graphQLErrors?.length) {
|
|
8702
8651
|
const graphQLErrors = error.graphQLErrors;
|
|
8703
8652
|
const routeError = (gqlError) => {
|
|
8704
|
-
const
|
|
8705
|
-
const suppression = getErrorSuppression(
|
|
8653
|
+
const visibility = gqlError.extensions?.visibility;
|
|
8654
|
+
const suppression = getErrorSuppression(visibility, shouldShowDevConsole(showDevConsole));
|
|
8706
8655
|
if (suppression) {
|
|
8707
8656
|
console.error(suppression, gqlError.message);
|
|
8708
8657
|
return;
|
|
@@ -8723,7 +8672,7 @@ window.parent.postMessage({jsonrpc:"2.0",method:"ui/notifications/sandbox-proxy-
|
|
|
8723
8672
|
graphQLErrors.forEach(routeError);
|
|
8724
8673
|
} else {
|
|
8725
8674
|
const fallbackError = new _copilotkit_shared.CopilotKitError({
|
|
8726
|
-
message:
|
|
8675
|
+
message: error?.message || String(error),
|
|
8727
8676
|
code: _copilotkit_shared.CopilotKitErrorCode.UNKNOWN
|
|
8728
8677
|
});
|
|
8729
8678
|
setBannerError(fallbackError);
|
|
@@ -8910,6 +8859,7 @@ window.parent.postMessage({jsonrpc:"2.0",method:"ui/notifications/sandbox-proxy-
|
|
|
8910
8859
|
}
|
|
8911
8860
|
` }), /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
|
|
8912
8861
|
className: "usage-banner",
|
|
8862
|
+
"data-testid": "copilot-error-banner",
|
|
8913
8863
|
children: /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
|
|
8914
8864
|
className: "banner-content",
|
|
8915
8865
|
children: [
|
|
@@ -8917,7 +8867,7 @@ window.parent.postMessage({jsonrpc:"2.0",method:"ui/notifications/sandbox-proxy-
|
|
|
8917
8867
|
className: "banner-message",
|
|
8918
8868
|
children: message
|
|
8919
8869
|
}),
|
|
8920
|
-
|
|
8870
|
+
actions?.primary && /* @__PURE__ */ (0, react_jsx_runtime.jsx)("button", {
|
|
8921
8871
|
className: "btn-primary",
|
|
8922
8872
|
onClick: actions.primary.onClick,
|
|
8923
8873
|
children: actions.primary.label
|
|
@@ -8967,7 +8917,7 @@ window.parent.postMessage({jsonrpc:"2.0",method:"ui/notifications/sandbox-proxy-
|
|
|
8967
8917
|
headers: { [_copilotkit_shared.COPILOT_CLOUD_PUBLIC_API_KEY_HEADER]: publicApiKey }
|
|
8968
8918
|
}).then((response) => response.json());
|
|
8969
8919
|
this.lastResponse = response;
|
|
8970
|
-
onUpdate
|
|
8920
|
+
onUpdate?.(response);
|
|
8971
8921
|
return response;
|
|
8972
8922
|
} catch (error) {
|
|
8973
8923
|
return null;
|
|
@@ -9011,8 +8961,7 @@ window.parent.postMessage({jsonrpc:"2.0",method:"ui/notifications/sandbox-proxy-
|
|
|
9011
8961
|
componentDidMount() {
|
|
9012
8962
|
if (this.props.publicApiKey) statusChecker.start(this.props.publicApiKey, (newStatus) => {
|
|
9013
8963
|
this.setState((prevState) => {
|
|
9014
|
-
|
|
9015
|
-
if ((newStatus === null || newStatus === void 0 ? void 0 : newStatus.severity) !== ((_prevState$status = prevState.status) === null || _prevState$status === void 0 ? void 0 : _prevState$status.severity)) return { status: newStatus !== null && newStatus !== void 0 ? newStatus : void 0 };
|
|
8964
|
+
if (newStatus?.severity !== prevState.status?.severity) return { status: newStatus ?? void 0 };
|
|
9016
8965
|
return null;
|
|
9017
8966
|
});
|
|
9018
8967
|
});
|
|
@@ -9025,14 +8974,11 @@ window.parent.postMessage({jsonrpc:"2.0",method:"ui/notifications/sandbox-proxy-
|
|
|
9025
8974
|
}
|
|
9026
8975
|
render() {
|
|
9027
8976
|
if (this.state.hasError) {
|
|
9028
|
-
if (this.state.error instanceof _copilotkit_shared.CopilotKitError) {
|
|
9029
|
-
|
|
9030
|
-
|
|
9031
|
-
|
|
9032
|
-
|
|
9033
|
-
actions: getErrorActions(this.state.error)
|
|
9034
|
-
})] });
|
|
9035
|
-
}
|
|
8977
|
+
if (this.state.error instanceof _copilotkit_shared.CopilotKitError) return /* @__PURE__ */ (0, react_jsx_runtime.jsxs)(react_jsx_runtime.Fragment, { children: [this.props.children, this.props.showUsageBanner && /* @__PURE__ */ (0, react_jsx_runtime.jsx)(UsageBanner, {
|
|
8978
|
+
severity: this.state.status?.severity ?? this.state.error.severity,
|
|
8979
|
+
message: this.state.status?.message ?? this.state.error.message,
|
|
8980
|
+
actions: getErrorActions(this.state.error)
|
|
8981
|
+
})] });
|
|
9036
8982
|
throw this.state.error;
|
|
9037
8983
|
}
|
|
9038
8984
|
return this.props.children;
|
|
@@ -9080,7 +9026,7 @@ window.parent.postMessage({jsonrpc:"2.0",method:"ui/notifications/sandbox-proxy-
|
|
|
9080
9026
|
function ThreadsProvider({ children, threadId: explicitThreadId }) {
|
|
9081
9027
|
const [internalThreadId, setInternalThreadId] = (0, react.useState)(() => (0, _copilotkit_shared.randomUUID)());
|
|
9082
9028
|
const [internalIsExplicit, setInternalIsExplicit] = (0, react.useState)(false);
|
|
9083
|
-
const threadId = explicitThreadId
|
|
9029
|
+
const threadId = explicitThreadId ?? internalThreadId;
|
|
9084
9030
|
const isThreadIdExplicit = explicitThreadId != null || internalIsExplicit;
|
|
9085
9031
|
const setThreadId = (0, react.useCallback)((value) => {
|
|
9086
9032
|
setInternalThreadId(value);
|
|
@@ -9161,13 +9107,10 @@ window.parent.postMessage({jsonrpc:"2.0",method:"ui/notifications/sandbox-proxy-
|
|
|
9161
9107
|
updateRunId: shouldUpdateRunId ? runId : void 0
|
|
9162
9108
|
};
|
|
9163
9109
|
}
|
|
9164
|
-
const normalizedRunId = runId
|
|
9165
|
-
const renderClaimedByOtherMessageEntry = Object.entries(claims).find(([, claim]) =>
|
|
9166
|
-
|
|
9167
|
-
|
|
9168
|
-
});
|
|
9169
|
-
const renderClaimedByOtherMessage = renderClaimedByOtherMessageEntry === null || renderClaimedByOtherMessageEntry === void 0 ? void 0 : renderClaimedByOtherMessageEntry[1];
|
|
9170
|
-
const claimedMessageId = renderClaimedByOtherMessageEntry === null || renderClaimedByOtherMessageEntry === void 0 ? void 0 : renderClaimedByOtherMessageEntry[0];
|
|
9110
|
+
const normalizedRunId = runId ?? "pending";
|
|
9111
|
+
const renderClaimedByOtherMessageEntry = Object.entries(claims).find(([, claim]) => claim.stateRenderId === stateRenderId && (claim.runId ?? "pending") === normalizedRunId && (0, _copilotkit_shared.dataToUUID)(getStateWithoutConstantKeys(claim.stateSnapshot)) === (0, _copilotkit_shared.dataToUUID)(getStateWithoutConstantKeys(stateSnapshot)));
|
|
9112
|
+
const renderClaimedByOtherMessage = renderClaimedByOtherMessageEntry?.[1];
|
|
9113
|
+
const claimedMessageId = renderClaimedByOtherMessageEntry?.[0];
|
|
9171
9114
|
if (renderClaimedByOtherMessage) {
|
|
9172
9115
|
if (messageIndex !== void 0 && renderClaimedByOtherMessage.messageIndex !== void 0 && messageIndex > renderClaimedByOtherMessage.messageIndex) return {
|
|
9173
9116
|
canRender: true,
|
|
@@ -9236,17 +9179,14 @@ window.parent.postMessage({jsonrpc:"2.0",method:"ui/notifications/sandbox-proxy-
|
|
|
9236
9179
|
* 5) last cached snapshot for stateRenderId
|
|
9237
9180
|
*/
|
|
9238
9181
|
function selectSnapshot({ messageId, messageName, allowLiveState, skipLatestCache, stateRenderId, effectiveRunId, stateSnapshotProp, agentState, agentMessages, existingClaim, caches }) {
|
|
9239
|
-
|
|
9240
|
-
const lastAssistantId = agentMessages ? (_toReversed$find = [...agentMessages].toReversed().find((msg) => msg.role === "assistant")) === null || _toReversed$find === void 0 ? void 0 : _toReversed$find.id : void 0;
|
|
9182
|
+
const lastAssistantId = agentMessages ? [...agentMessages].toReversed().find((msg) => msg.role === "assistant")?.id : void 0;
|
|
9241
9183
|
const latestSnapshot = stateRenderId !== void 0 ? caches.byStateRenderAndRun[`${stateRenderId}::latest`] : void 0;
|
|
9242
9184
|
const messageIndex = agentMessages ? agentMessages.findIndex((msg) => msg.id === messageId) : -1;
|
|
9243
|
-
const messageRole = messageIndex >= 0 && agentMessages ?
|
|
9185
|
+
const messageRole = messageIndex >= 0 && agentMessages ? agentMessages[messageIndex]?.role : void 0;
|
|
9244
9186
|
let previousUserMessageId;
|
|
9245
|
-
if (messageIndex > 0 && agentMessages)
|
|
9246
|
-
|
|
9247
|
-
|
|
9248
|
-
var _agentMessages$i2;
|
|
9249
|
-
previousUserMessageId = (_agentMessages$i2 = agentMessages[i]) === null || _agentMessages$i2 === void 0 ? void 0 : _agentMessages$i2.id;
|
|
9187
|
+
if (messageIndex > 0 && agentMessages) {
|
|
9188
|
+
for (let i = messageIndex - 1; i >= 0; i -= 1) if (agentMessages[i]?.role === "user") {
|
|
9189
|
+
previousUserMessageId = agentMessages[i]?.id;
|
|
9250
9190
|
break;
|
|
9251
9191
|
}
|
|
9252
9192
|
}
|
|
@@ -9258,11 +9198,11 @@ window.parent.postMessage({jsonrpc:"2.0",method:"ui/notifications/sandbox-proxy-
|
|
|
9258
9198
|
const messageCacheEntry = caches.byMessageId[messageId];
|
|
9259
9199
|
const cachedMessageSnapshot = readCachedMessageEntry(messageCacheEntry).snapshot;
|
|
9260
9200
|
const cacheKey = stateRenderId !== void 0 ? `${stateRenderId}::${effectiveRunId}` : void 0;
|
|
9261
|
-
let cachedSnapshot = cachedMessageSnapshot
|
|
9201
|
+
let cachedSnapshot = cachedMessageSnapshot ?? caches.byMessageId[messageId];
|
|
9262
9202
|
if (cachedSnapshot === void 0 && cacheKey && caches.byStateRenderAndRun[cacheKey] !== void 0) cachedSnapshot = caches.byStateRenderAndRun[cacheKey];
|
|
9263
9203
|
if (cachedSnapshot === void 0 && stateRenderId && previousUserMessageId && caches.byStateRenderAndRun[`${stateRenderId}::pending:${previousUserMessageId}`] !== void 0) cachedSnapshot = caches.byStateRenderAndRun[`${stateRenderId}::pending:${previousUserMessageId}`];
|
|
9264
9204
|
if (cachedSnapshot === void 0 && !skipLatestCache && stateRenderId && messageRole !== "assistant" && (stateSnapshotProp !== void 0 || agentState && Object.keys(agentState).length > 0)) cachedSnapshot = caches.byStateRenderAndRun[`${stateRenderId}::latest`];
|
|
9265
|
-
const snapshotForClaim =
|
|
9205
|
+
const snapshotForClaim = existingClaim?.locked ? existingClaim.stateSnapshot ?? cachedSnapshot : hasSnapshotKeys ? snapshot : existingClaim?.stateSnapshot ?? cachedSnapshot;
|
|
9266
9206
|
return {
|
|
9267
9207
|
snapshot,
|
|
9268
9208
|
hasSnapshotKeys,
|
|
@@ -9280,37 +9220,36 @@ window.parent.postMessage({jsonrpc:"2.0",method:"ui/notifications/sandbox-proxy-
|
|
|
9280
9220
|
return claimsRef.current;
|
|
9281
9221
|
}
|
|
9282
9222
|
function getSnapshotCaches(claimsRef) {
|
|
9283
|
-
var _store$LAST_SNAPSHOTS, _store$LAST_SNAPSHOTS2;
|
|
9284
9223
|
const store = getClaimsStore(claimsRef);
|
|
9285
9224
|
return {
|
|
9286
|
-
byStateRenderAndRun:
|
|
9287
|
-
byMessageId:
|
|
9225
|
+
byStateRenderAndRun: store[LAST_SNAPSHOTS_BY_RENDER_AND_RUN] ?? {},
|
|
9226
|
+
byMessageId: store[LAST_SNAPSHOTS_BY_MESSAGE] ?? {}
|
|
9288
9227
|
};
|
|
9289
9228
|
}
|
|
9290
9229
|
function useStateRenderRegistry({ agentId, stateRenderId, message, messageIndex, stateSnapshot, agentState, agentMessages, claimsRef }) {
|
|
9291
|
-
var _store$LAST_SNAPSHOTS3, _claimsRef$current$me;
|
|
9292
9230
|
const store = getClaimsStore(claimsRef);
|
|
9293
9231
|
const runId = message.runId;
|
|
9294
|
-
const
|
|
9232
|
+
const cachedMessageEntry = store[LAST_SNAPSHOTS_BY_MESSAGE]?.[message.id];
|
|
9233
|
+
const { runId: cachedMessageRunId } = readCachedMessageEntry(cachedMessageEntry);
|
|
9234
|
+
const existingClaimRunId = claimsRef.current[message.id]?.runId;
|
|
9295
9235
|
const effectiveRunId = getEffectiveRunId({
|
|
9296
|
-
existingClaimRunId
|
|
9236
|
+
existingClaimRunId,
|
|
9297
9237
|
cachedMessageRunId,
|
|
9298
9238
|
runId
|
|
9299
9239
|
});
|
|
9300
9240
|
(0, react.useEffect)(() => {
|
|
9301
9241
|
return () => {
|
|
9302
9242
|
const existingClaim = claimsRef.current[message.id];
|
|
9303
|
-
if (
|
|
9304
|
-
var _existingClaim$runId, _existingClaim$runId2;
|
|
9243
|
+
if (existingClaim?.stateSnapshot && Object.keys(existingClaim.stateSnapshot).length > 0) {
|
|
9305
9244
|
const snapshotCache = { ...store[LAST_SNAPSHOTS_BY_RENDER_AND_RUN] };
|
|
9306
|
-
const cacheKey = `${existingClaim.stateRenderId}::${
|
|
9245
|
+
const cacheKey = `${existingClaim.stateRenderId}::${existingClaim.runId ?? "pending"}`;
|
|
9307
9246
|
snapshotCache[cacheKey] = existingClaim.stateSnapshot;
|
|
9308
9247
|
snapshotCache[`${existingClaim.stateRenderId}::latest`] = existingClaim.stateSnapshot;
|
|
9309
9248
|
store[LAST_SNAPSHOTS_BY_RENDER_AND_RUN] = snapshotCache;
|
|
9310
9249
|
const messageCache = { ...store[LAST_SNAPSHOTS_BY_MESSAGE] };
|
|
9311
9250
|
messageCache[message.id] = {
|
|
9312
9251
|
snapshot: existingClaim.stateSnapshot,
|
|
9313
|
-
runId:
|
|
9252
|
+
runId: existingClaim.runId ?? effectiveRunId
|
|
9314
9253
|
};
|
|
9315
9254
|
store[LAST_SNAPSHOTS_BY_MESSAGE] = messageCache;
|
|
9316
9255
|
}
|
|
@@ -9354,7 +9293,7 @@ window.parent.postMessage({jsonrpc:"2.0",method:"ui/notifications/sandbox-proxy-
|
|
|
9354
9293
|
if (resolution.lockOthers) Object.entries(claimsRef.current).forEach(([id, claim]) => {
|
|
9355
9294
|
if (id !== message.id && claim.stateRenderId === stateRenderId) claim.locked = true;
|
|
9356
9295
|
});
|
|
9357
|
-
if (existingClaim && !existingClaim.locked &&
|
|
9296
|
+
if (existingClaim && !existingClaim.locked && agentMessages?.length) {
|
|
9358
9297
|
const indexInAgentMessages = agentMessages.findIndex((msg) => msg.id === message.id);
|
|
9359
9298
|
if (indexInAgentMessages >= 0 && indexInAgentMessages < agentMessages.length - 1) existingClaim.locked = true;
|
|
9360
9299
|
}
|
|
@@ -9398,7 +9337,6 @@ window.parent.postMessage({jsonrpc:"2.0",method:"ui/notifications/sandbox-proxy-
|
|
|
9398
9337
|
//#endregion
|
|
9399
9338
|
//#region src/hooks/use-coagent-state-render-bridge.tsx
|
|
9400
9339
|
function useCoagentStateRenderBridge(agentId, props) {
|
|
9401
|
-
var _props$runId;
|
|
9402
9340
|
const { stateSnapshot, message } = props;
|
|
9403
9341
|
const { coAgentStateRenders, claimsRef } = useCoAgentStateRenders();
|
|
9404
9342
|
const { agent } = useAgent({ agentId });
|
|
@@ -9434,46 +9372,42 @@ window.parent.postMessage({jsonrpc:"2.0",method:"ui/notifications/sandbox-proxy-
|
|
|
9434
9372
|
agentId
|
|
9435
9373
|
]);
|
|
9436
9374
|
const stateRenderEntry = (0, react.useMemo)(() => getStateRender(message.id), [getStateRender, message.id]);
|
|
9437
|
-
const stateRenderId = stateRenderEntry
|
|
9438
|
-
const stateRender = stateRenderEntry
|
|
9375
|
+
const stateRenderId = stateRenderEntry?.[0];
|
|
9376
|
+
const stateRender = stateRenderEntry?.[1];
|
|
9439
9377
|
const { canRender } = useStateRenderRegistry({
|
|
9440
9378
|
agentId,
|
|
9441
9379
|
stateRenderId,
|
|
9442
9380
|
message: {
|
|
9443
9381
|
...message,
|
|
9444
|
-
runId:
|
|
9382
|
+
runId: props.runId ?? message.runId
|
|
9445
9383
|
},
|
|
9446
9384
|
messageIndex: props.messageIndex,
|
|
9447
9385
|
stateSnapshot,
|
|
9448
|
-
agentState: agent
|
|
9449
|
-
agentMessages: agent
|
|
9386
|
+
agentState: agent?.state,
|
|
9387
|
+
agentMessages: agent?.messages,
|
|
9450
9388
|
claimsRef
|
|
9451
9389
|
});
|
|
9452
9390
|
return (0, react.useMemo)(() => {
|
|
9453
9391
|
if (!stateRender || !stateRenderId) return null;
|
|
9454
9392
|
if (!canRender) return null;
|
|
9455
|
-
if (stateRender.handler) {
|
|
9456
|
-
|
|
9457
|
-
|
|
9458
|
-
|
|
9459
|
-
nodeName: nodeName !== null && nodeName !== void 0 ? nodeName : ""
|
|
9460
|
-
});
|
|
9461
|
-
}
|
|
9393
|
+
if (stateRender.handler) stateRender.handler({
|
|
9394
|
+
state: stateSnapshot ? (0, _copilotkit_shared.parseJson)(stateSnapshot, stateSnapshot) : agent?.state ?? {},
|
|
9395
|
+
nodeName: nodeName ?? ""
|
|
9396
|
+
});
|
|
9462
9397
|
if (stateRender.render) {
|
|
9463
|
-
|
|
9464
|
-
const status = (agent === null || agent === void 0 ? void 0 : agent.isRunning) ? RenderStatus.InProgress : RenderStatus.Complete;
|
|
9398
|
+
const status = agent?.isRunning ? RenderStatus.InProgress : RenderStatus.Complete;
|
|
9465
9399
|
if (typeof stateRender.render === "string") return stateRender.render;
|
|
9466
9400
|
return stateRender.render({
|
|
9467
9401
|
status,
|
|
9468
|
-
state:
|
|
9469
|
-
nodeName: nodeName
|
|
9402
|
+
state: claimsRef.current[message.id].stateSnapshot ?? {},
|
|
9403
|
+
nodeName: nodeName ?? ""
|
|
9470
9404
|
});
|
|
9471
9405
|
}
|
|
9472
9406
|
}, [
|
|
9473
9407
|
stateRender,
|
|
9474
9408
|
stateRenderId,
|
|
9475
|
-
agent
|
|
9476
|
-
agent
|
|
9409
|
+
agent?.state,
|
|
9410
|
+
agent?.isRunning,
|
|
9477
9411
|
nodeName,
|
|
9478
9412
|
message.id,
|
|
9479
9413
|
stateSnapshot,
|
|
@@ -9494,7 +9428,7 @@ window.parent.postMessage({jsonrpc:"2.0",method:"ui/notifications/sandbox-proxy-
|
|
|
9494
9428
|
},
|
|
9495
9429
|
onToolCallArgsEvent: ({ partialToolCallArgs, toolCallName }) => {
|
|
9496
9430
|
predictStateToolsRef.current.forEach((t) => {
|
|
9497
|
-
if (
|
|
9431
|
+
if (t?.tool !== toolCallName) return;
|
|
9498
9432
|
const emittedState = typeof partialToolCallArgs === "string" ? (0, _copilotkit_shared.parseJson)(partialToolCallArgs, partialToolCallArgs) : partialToolCallArgs;
|
|
9499
9433
|
agent.setState({ [t.state_key]: emittedState[t.state_key] });
|
|
9500
9434
|
});
|
|
@@ -9510,16 +9444,15 @@ window.parent.postMessage({jsonrpc:"2.0",method:"ui/notifications/sandbox-proxy-
|
|
|
9510
9444
|
}, [agent, getSubscriber]);
|
|
9511
9445
|
};
|
|
9512
9446
|
function CopilotListenersAgentSubscription() {
|
|
9513
|
-
const
|
|
9514
|
-
const { agent } = useAgent({ agentId:
|
|
9447
|
+
const resolvedAgentId = useCopilotChatConfiguration()?.agentId;
|
|
9448
|
+
const { agent } = useAgent({ agentId: resolvedAgentId });
|
|
9515
9449
|
usePredictStateSubscription(agent);
|
|
9516
9450
|
return null;
|
|
9517
9451
|
}
|
|
9518
9452
|
function CopilotListeners() {
|
|
9519
|
-
var _copilotkit$agents;
|
|
9520
9453
|
const { copilotkit } = useCopilotKit();
|
|
9521
9454
|
const { setBannerError } = useToast();
|
|
9522
|
-
const hasAgents = Object.keys(
|
|
9455
|
+
const hasAgents = Object.keys(copilotkit.agents ?? {}).length > 0;
|
|
9523
9456
|
const hasRuntime = copilotkit.runtimeUrl !== void 0;
|
|
9524
9457
|
(0, react.useEffect)(() => {
|
|
9525
9458
|
const subscription = copilotkit.subscribe({ onError: ({ error, code, context }) => {
|
|
@@ -9541,7 +9474,7 @@ window.parent.postMessage({jsonrpc:"2.0",method:"ui/notifications/sandbox-proxy-
|
|
|
9541
9474
|
return () => {
|
|
9542
9475
|
subscription.unsubscribe();
|
|
9543
9476
|
};
|
|
9544
|
-
}, [copilotkit
|
|
9477
|
+
}, [copilotkit?.subscribe]);
|
|
9545
9478
|
return hasAgents || hasRuntime ? /* @__PURE__ */ (0, react_jsx_runtime.jsx)(CopilotListenersAgentSubscription, {}) : null;
|
|
9546
9479
|
}
|
|
9547
9480
|
|
|
@@ -9563,7 +9496,6 @@ window.parent.postMessage({jsonrpc:"2.0",method:"ui/notifications/sandbox-proxy-
|
|
|
9563
9496
|
* ```
|
|
9564
9497
|
*/
|
|
9565
9498
|
function CopilotKit({ children, ...props }) {
|
|
9566
|
-
var _props$useSingleEndpo;
|
|
9567
9499
|
const enabled = shouldShowDevConsole(props.showDevConsole);
|
|
9568
9500
|
const showInspector = shouldShowDevConsole(props.enableInspector);
|
|
9569
9501
|
const publicApiKey = props.publicApiKey || props.publicLicenseKey;
|
|
@@ -9579,7 +9511,7 @@ window.parent.postMessage({jsonrpc:"2.0",method:"ui/notifications/sandbox-proxy-
|
|
|
9579
9511
|
...props,
|
|
9580
9512
|
showDevConsole: showInspector,
|
|
9581
9513
|
renderCustomMessages: renderArr,
|
|
9582
|
-
useSingleEndpoint:
|
|
9514
|
+
useSingleEndpoint: props.useSingleEndpoint ?? true,
|
|
9583
9515
|
children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(CopilotKitInternal, {
|
|
9584
9516
|
...props,
|
|
9585
9517
|
children
|
|
@@ -9608,7 +9540,7 @@ window.parent.postMessage({jsonrpc:"2.0",method:"ui/notifications/sandbox-proxy-
|
|
|
9608
9540
|
source: "agent",
|
|
9609
9541
|
request: {
|
|
9610
9542
|
operation: event.code || "unknown",
|
|
9611
|
-
url: copilotApiConfig
|
|
9543
|
+
url: copilotApiConfig?.chatApiEndpoint,
|
|
9612
9544
|
startTime: Date.now()
|
|
9613
9545
|
},
|
|
9614
9546
|
technical: {
|
|
@@ -9637,7 +9569,6 @@ window.parent.postMessage({jsonrpc:"2.0",method:"ui/notifications/sandbox-proxy-
|
|
|
9637
9569
|
return null;
|
|
9638
9570
|
}
|
|
9639
9571
|
function CopilotKitInternal(cpkProps) {
|
|
9640
|
-
var _props$agent2;
|
|
9641
9572
|
const { children, ...props } = cpkProps;
|
|
9642
9573
|
/**
|
|
9643
9574
|
* This will throw an error if the props are invalid.
|
|
@@ -9701,14 +9632,11 @@ window.parent.postMessage({jsonrpc:"2.0",method:"ui/notifications/sandbox-proxy-
|
|
|
9701
9632
|
}, [removeDocument]);
|
|
9702
9633
|
const copilotApiConfig = (0, react.useMemo)(() => {
|
|
9703
9634
|
let cloud = void 0;
|
|
9704
|
-
if (publicApiKey) {
|
|
9705
|
-
|
|
9706
|
-
|
|
9707
|
-
|
|
9708
|
-
|
|
9709
|
-
invalidTopics: ((_props$guardrails_c2 = props.guardrails_c) === null || _props$guardrails_c2 === void 0 ? void 0 : _props$guardrails_c2.invalidTopics) || []
|
|
9710
|
-
} } } };
|
|
9711
|
-
}
|
|
9635
|
+
if (publicApiKey) cloud = { guardrails: { input: { restrictToTopic: {
|
|
9636
|
+
enabled: Boolean(props.guardrails_c),
|
|
9637
|
+
validTopics: props.guardrails_c?.validTopics || [],
|
|
9638
|
+
invalidTopics: props.guardrails_c?.invalidTopics || []
|
|
9639
|
+
} } } };
|
|
9712
9640
|
return {
|
|
9713
9641
|
publicApiKey,
|
|
9714
9642
|
...cloud ? { cloud } : {},
|
|
@@ -9864,14 +9792,8 @@ window.parent.postMessage({jsonrpc:"2.0",method:"ui/notifications/sandbox-proxy-
|
|
|
9864
9792
|
}, []);
|
|
9865
9793
|
const memoizedChildren = (0, react.useMemo)(() => children, [children]);
|
|
9866
9794
|
const [bannerError, setBannerError] = (0, react.useState)(null);
|
|
9867
|
-
const agentLock = (0, react.useMemo)(() =>
|
|
9868
|
-
|
|
9869
|
-
return (_props$agent = props.agent) !== null && _props$agent !== void 0 ? _props$agent : null;
|
|
9870
|
-
}, [props.agent]);
|
|
9871
|
-
const forwardedParameters = (0, react.useMemo)(() => {
|
|
9872
|
-
var _props$forwardedParam;
|
|
9873
|
-
return (_props$forwardedParam = props.forwardedParameters) !== null && _props$forwardedParam !== void 0 ? _props$forwardedParam : {};
|
|
9874
|
-
}, [props.forwardedParameters]);
|
|
9795
|
+
const agentLock = (0, react.useMemo)(() => props.agent ?? null, [props.agent]);
|
|
9796
|
+
const forwardedParameters = (0, react.useMemo)(() => props.forwardedParameters ?? {}, [props.forwardedParameters]);
|
|
9875
9797
|
const updateExtensions = (0, react.useCallback)((newExtensions) => {
|
|
9876
9798
|
setExtensions((prev) => {
|
|
9877
9799
|
const resolved = typeof newExtensions === "function" ? newExtensions(prev) : newExtensions;
|
|
@@ -10014,7 +9936,7 @@ window.parent.postMessage({jsonrpc:"2.0",method:"ui/notifications/sandbox-proxy-
|
|
|
10014
9936
|
removeInternalErrorHandler
|
|
10015
9937
|
]);
|
|
10016
9938
|
return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(CopilotChatConfigurationProvider, {
|
|
10017
|
-
agentId:
|
|
9939
|
+
agentId: props.agent ?? "default",
|
|
10018
9940
|
threadId,
|
|
10019
9941
|
hasExplicitThreadId: isThreadIdExplicit,
|
|
10020
9942
|
children: /* @__PURE__ */ (0, react_jsx_runtime.jsxs)(CopilotContext.Provider, {
|
|
@@ -10043,8 +9965,7 @@ window.parent.postMessage({jsonrpc:"2.0",method:"ui/notifications/sandbox-proxy-
|
|
|
10043
9965
|
await new Promise((resolve, reject) => {
|
|
10044
9966
|
(0, react_dom.flushSync)(async () => {
|
|
10045
9967
|
try {
|
|
10046
|
-
|
|
10047
|
-
result = await ((_action$handler = action.handler) === null || _action$handler === void 0 ? void 0 : _action$handler.call(action, args));
|
|
9968
|
+
result = await action.handler?.(args);
|
|
10048
9969
|
resolve();
|
|
10049
9970
|
} catch (error) {
|
|
10050
9971
|
reject(error);
|