@copilotkit/react-core 1.59.1 → 1.59.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/{copilotkit-CDK5ny-e.mjs → copilotkit-BRNy5UvX.mjs} +158 -44
- package/dist/copilotkit-BRNy5UvX.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-DKPrBplZ.cjs → copilotkit-DhONbYmz.cjs} +158 -44
- package/dist/copilotkit-DhONbYmz.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 +364 -397
- 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 +457 -527
- package/dist/v2/index.umd.js.map +1 -1
- package/package.json +12 -7
- package/dist/copilotkit-CDK5ny-e.mjs.map +0 -1
- package/dist/copilotkit-DKPrBplZ.cjs.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
|
|
783
|
+
if (isProcessing && !canSend) 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;
|
|
@@ -3508,7 +3527,7 @@ window.parent.postMessage({jsonrpc:"2.0",method:"ui/notifications/sandbox-proxy-
|
|
|
3508
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)";
|
|
3509
3528
|
function useStableArrayProp(prop, warningMessage, isMeaningfulChange) {
|
|
3510
3529
|
const empty = (0, react.useMemo)(() => [], []);
|
|
3511
|
-
const value = prop
|
|
3530
|
+
const value = prop ?? empty;
|
|
3512
3531
|
const initial = (0, react.useRef)(value);
|
|
3513
3532
|
(0, react.useEffect)(() => {
|
|
3514
3533
|
if (warningMessage && value !== initial.current && (isMeaningfulChange ? isMeaningfulChange(initial.current, value) : true)) console.error(warningMessage);
|
|
@@ -3516,7 +3535,6 @@ window.parent.postMessage({jsonrpc:"2.0",method:"ui/notifications/sandbox-proxy-
|
|
|
3516
3535
|
return value;
|
|
3517
3536
|
}
|
|
3518
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 }) => {
|
|
3519
|
-
var _openGenerativeUI$des;
|
|
3520
3538
|
const [shouldRenderInspector, setShouldRenderInspector] = (0, react.useState)(false);
|
|
3521
3539
|
const [runtimeA2UIEnabled, setRuntimeA2UIEnabled] = (0, react.useState)(false);
|
|
3522
3540
|
const [runtimeOpenGenUIEnabled, setRuntimeOpenGenUIEnabled] = (0, react.useState)(false);
|
|
@@ -3530,10 +3548,7 @@ window.parent.postMessage({jsonrpc:"2.0",method:"ui/notifications/sandbox-proxy-
|
|
|
3530
3548
|
else setShouldRenderInspector(false);
|
|
3531
3549
|
}, [showDevConsole]);
|
|
3532
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) => {
|
|
3533
|
-
const key = (rc) => {
|
|
3534
|
-
var _rc$agentId, _rc$name;
|
|
3535
|
-
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 : ""}`;
|
|
3536
|
-
};
|
|
3551
|
+
const key = (rc) => `${rc?.agentId ?? ""}:${rc?.name ?? ""}`;
|
|
3537
3552
|
const setFrom = (arr) => new Set(arr.map(key));
|
|
3538
3553
|
const a = setFrom(initial);
|
|
3539
3554
|
const b = setFrom(next);
|
|
@@ -3554,14 +3569,11 @@ window.parent.postMessage({jsonrpc:"2.0",method:"ui/notifications/sandbox-proxy-
|
|
|
3554
3569
|
content: OpenGenerativeUIContentSchema,
|
|
3555
3570
|
render: OpenGenerativeUIActivityRenderer
|
|
3556
3571
|
});
|
|
3557
|
-
if (runtimeA2UIEnabled) {
|
|
3558
|
-
|
|
3559
|
-
|
|
3560
|
-
|
|
3561
|
-
|
|
3562
|
-
loadingComponent: a2ui === null || a2ui === void 0 ? void 0 : a2ui.loadingComponent
|
|
3563
|
-
}));
|
|
3564
|
-
}
|
|
3572
|
+
if (runtimeA2UIEnabled) renderers.unshift(createA2UIMessageRenderer({
|
|
3573
|
+
theme: a2ui?.theme ?? _copilotkit_a2ui_renderer.viewerTheme,
|
|
3574
|
+
catalog: a2ui?.catalog,
|
|
3575
|
+
loadingComponent: a2ui?.loadingComponent
|
|
3576
|
+
}));
|
|
3565
3577
|
return renderers;
|
|
3566
3578
|
}, [
|
|
3567
3579
|
runtimeA2UIEnabled,
|
|
@@ -3571,7 +3583,7 @@ window.parent.postMessage({jsonrpc:"2.0",method:"ui/notifications/sandbox-proxy-
|
|
|
3571
3583
|
const allActivityRenderers = (0, react.useMemo)(() => {
|
|
3572
3584
|
return [...renderActivityMessagesList, ...builtInActivityRenderers];
|
|
3573
3585
|
}, [renderActivityMessagesList, builtInActivityRenderers]);
|
|
3574
|
-
const resolvedPublicKey = publicApiKey
|
|
3586
|
+
const resolvedPublicKey = publicApiKey ?? publicLicenseKey;
|
|
3575
3587
|
const mergedAgents = (0, react.useMemo)(() => ({
|
|
3576
3588
|
...agents,
|
|
3577
3589
|
...selfManagedAgents
|
|
@@ -3591,10 +3603,10 @@ window.parent.postMessage({jsonrpc:"2.0",method:"ui/notifications/sandbox-proxy-
|
|
|
3591
3603
|
if (process.env.NODE_ENV === "production") throw new Error(message);
|
|
3592
3604
|
else console.warn(message);
|
|
3593
3605
|
}
|
|
3594
|
-
const chatApiEndpoint = runtimeUrl
|
|
3606
|
+
const chatApiEndpoint = runtimeUrl ?? (resolvedPublicKey ? COPILOT_CLOUD_CHAT_URL$1 : void 0);
|
|
3595
3607
|
const frontendToolsList = useStableArrayProp(frontendTools, "frontendTools must be a stable array. If you want to dynamically add or remove tools, use `useFrontendTool` instead.");
|
|
3596
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.");
|
|
3597
|
-
const sandboxFunctionsList = useStableArrayProp(openGenerativeUI
|
|
3609
|
+
const sandboxFunctionsList = useStableArrayProp(openGenerativeUI?.sandboxFunctions, "openGenerativeUI.sandboxFunctions must be a stable array.");
|
|
3598
3610
|
const processedHumanInTheLoopTools = (0, react.useMemo)(() => {
|
|
3599
3611
|
const processedTools = [];
|
|
3600
3612
|
const processedRenderToolCalls = [];
|
|
@@ -3736,10 +3748,7 @@ window.parent.postMessage({jsonrpc:"2.0",method:"ui/notifications/sandbox-proxy-
|
|
|
3736
3748
|
(0, react.useEffect)(() => {
|
|
3737
3749
|
const subscription = copilotkit.subscribe({ onError: (event) => {
|
|
3738
3750
|
if (onErrorRef.current) onErrorRef.current(event);
|
|
3739
|
-
else {
|
|
3740
|
-
var _event$context;
|
|
3741
|
-
console.error(`[CopilotKit] Error (${event.code}):`, event.error, (_event$context = event.context) !== null && _event$context !== void 0 ? _event$context : {});
|
|
3742
|
-
}
|
|
3751
|
+
else console.error(`[CopilotKit] Error (${event.code}):`, event.error, event.context ?? {});
|
|
3743
3752
|
} });
|
|
3744
3753
|
return () => {
|
|
3745
3754
|
subscription.unsubscribe();
|
|
@@ -3786,7 +3795,7 @@ window.parent.postMessage({jsonrpc:"2.0",method:"ui/notifications/sandbox-proxy-
|
|
|
3786
3795
|
(0, react.useEffect)(() => {
|
|
3787
3796
|
copilotkit.setDefaultThrottleMs(defaultThrottleMs);
|
|
3788
3797
|
}, [copilotkit, defaultThrottleMs]);
|
|
3789
|
-
const designSkill =
|
|
3798
|
+
const designSkill = openGenerativeUI?.designSkill ?? DEFAULT_DESIGN_SKILL;
|
|
3790
3799
|
(0, react.useLayoutEffect)(() => {
|
|
3791
3800
|
if (!copilotkit || !openGenUIActive) return;
|
|
3792
3801
|
const id = copilotkit.addContext({
|
|
@@ -3837,8 +3846,8 @@ window.parent.postMessage({jsonrpc:"2.0",method:"ui/notifications/sandbox-proxy-
|
|
|
3837
3846
|
children: [
|
|
3838
3847
|
runtimeA2UIEnabled && /* @__PURE__ */ (0, react_jsx_runtime.jsx)(A2UIBuiltInToolCallRenderer, {}),
|
|
3839
3848
|
runtimeA2UIEnabled && /* @__PURE__ */ (0, react_jsx_runtime.jsx)(A2UICatalogContext, {
|
|
3840
|
-
catalog: a2ui
|
|
3841
|
-
includeSchema: a2ui
|
|
3849
|
+
catalog: a2ui?.catalog,
|
|
3850
|
+
includeSchema: a2ui?.includeSchema
|
|
3842
3851
|
}),
|
|
3843
3852
|
children,
|
|
3844
3853
|
shouldRenderInspector ? /* @__PURE__ */ (0, react_jsx_runtime.jsx)(CopilotKitInspector, {
|
|
@@ -3868,11 +3877,10 @@ window.parent.postMessage({jsonrpc:"2.0",method:"ui/notifications/sandbox-proxy-
|
|
|
3868
3877
|
return aHasAgent ? -1 : 1;
|
|
3869
3878
|
});
|
|
3870
3879
|
return function(params) {
|
|
3871
|
-
var _copilotkit$getRunIdF;
|
|
3872
3880
|
if (!customMessageRenderers.length) return null;
|
|
3873
3881
|
const { message, position } = params;
|
|
3874
|
-
const resolvedRunId =
|
|
3875
|
-
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}`;
|
|
3876
3884
|
const agent = copilotkit.getAgent(agentId);
|
|
3877
3885
|
if (!agent) return null;
|
|
3878
3886
|
const messagesIdsInRun = resolvedRunId ? agent.messages.filter((msg) => copilotkit.getRunIdForMessage(agentId, threadId, msg.id) === resolvedRunId).map((msg) => msg.id) : [message.id];
|
|
@@ -3904,15 +3912,13 @@ window.parent.postMessage({jsonrpc:"2.0",method:"ui/notifications/sandbox-proxy-
|
|
|
3904
3912
|
//#endregion
|
|
3905
3913
|
//#region src/v2/hooks/use-render-activity-message.tsx
|
|
3906
3914
|
function useRenderActivityMessage() {
|
|
3907
|
-
var _useCopilotChatConfig, _useCopilotChatConfig2;
|
|
3908
3915
|
const { copilotkit } = useCopilotKit();
|
|
3909
|
-
const agentId =
|
|
3916
|
+
const agentId = useCopilotChatConfiguration()?.agentId ?? _copilotkit_shared.DEFAULT_AGENT_ID;
|
|
3910
3917
|
const renderers = copilotkit.renderActivityMessages;
|
|
3911
3918
|
const findRenderer = (0, react.useCallback)((activityType) => {
|
|
3912
|
-
var _ref, _ref2, _matches$find;
|
|
3913
3919
|
if (!renderers.length) return null;
|
|
3914
3920
|
const matches = renderers.filter((renderer) => renderer.activityType === activityType);
|
|
3915
|
-
return
|
|
3921
|
+
return matches.find((candidate) => candidate.agentId === agentId) ?? matches.find((candidate) => candidate.agentId === void 0) ?? renderers.find((candidate) => candidate.activityType === "*") ?? null;
|
|
3916
3922
|
}, [agentId, renderers]);
|
|
3917
3923
|
const renderActivityMessage = (0, react.useCallback)((message) => {
|
|
3918
3924
|
const renderer = findRenderer(message.activityType);
|
|
@@ -3946,7 +3952,7 @@ window.parent.postMessage({jsonrpc:"2.0",method:"ui/notifications/sandbox-proxy-
|
|
|
3946
3952
|
const EMPTY_DEPS = [];
|
|
3947
3953
|
function useFrontendTool(tool, deps) {
|
|
3948
3954
|
const { copilotkit } = useCopilotKit();
|
|
3949
|
-
const extraDeps = deps
|
|
3955
|
+
const extraDeps = deps ?? EMPTY_DEPS;
|
|
3950
3956
|
(0, react.useEffect)(() => {
|
|
3951
3957
|
const name = tool.name;
|
|
3952
3958
|
if (copilotkit.getTool({
|
|
@@ -4122,15 +4128,13 @@ window.parent.postMessage({jsonrpc:"2.0",method:"ui/notifications/sandbox-proxy-
|
|
|
4122
4128
|
UseAgentUpdate.OnRunStatusChanged
|
|
4123
4129
|
];
|
|
4124
4130
|
function useAgent({ agentId, updates, throttleMs } = {}) {
|
|
4125
|
-
|
|
4126
|
-
(_agentId = agentId) !== null && _agentId !== void 0 || (agentId = _copilotkit_shared.DEFAULT_AGENT_ID);
|
|
4131
|
+
agentId ?? (agentId = _copilotkit_shared.DEFAULT_AGENT_ID);
|
|
4127
4132
|
const { copilotkit } = useCopilotKit();
|
|
4128
4133
|
const providerThrottleMs = copilotkit.defaultThrottleMs;
|
|
4129
4134
|
const [, forceUpdate] = (0, react.useReducer)((x) => x + 1, 0);
|
|
4130
|
-
const updateFlags = (0, react.useMemo)(() => updates
|
|
4135
|
+
const updateFlags = (0, react.useMemo)(() => updates ?? ALL_UPDATES, [JSON.stringify(updates)]);
|
|
4131
4136
|
const provisionalAgentCache = (0, react.useRef)(/* @__PURE__ */ new Map());
|
|
4132
4137
|
const agent = (0, react.useMemo)(() => {
|
|
4133
|
-
var _copilotkit$agents;
|
|
4134
4138
|
const existing = copilotkit.getAgent(agentId);
|
|
4135
4139
|
if (existing) {
|
|
4136
4140
|
provisionalAgentCache.current.delete(agentId);
|
|
@@ -4170,7 +4174,7 @@ window.parent.postMessage({jsonrpc:"2.0",method:"ui/notifications/sandbox-proxy-
|
|
|
4170
4174
|
provisionalAgentCache.current.set(agentId, provisional);
|
|
4171
4175
|
return provisional;
|
|
4172
4176
|
}
|
|
4173
|
-
const knownAgents = Object.keys(
|
|
4177
|
+
const knownAgents = Object.keys(copilotkit.agents ?? {});
|
|
4174
4178
|
const runtimePart = isRuntimeConfigured ? `runtimeUrl=${copilotkit.runtimeUrl}` : "no runtimeUrl";
|
|
4175
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.");
|
|
4176
4180
|
}, [
|
|
@@ -4220,8 +4224,8 @@ window.parent.postMessage({jsonrpc:"2.0",method:"ui/notifications/sandbox-proxy-
|
|
|
4220
4224
|
if (agent instanceof _ag_ui_client.HttpAgent) agent.headers = { ...copilotkit.headers };
|
|
4221
4225
|
}, [agent, JSON.stringify(copilotkit.headers)]);
|
|
4222
4226
|
const chatConfig = useCopilotChatConfiguration();
|
|
4223
|
-
const configThreadId = chatConfig
|
|
4224
|
-
const configHasExplicitThreadId = chatConfig
|
|
4227
|
+
const configThreadId = chatConfig?.threadId;
|
|
4228
|
+
const configHasExplicitThreadId = chatConfig?.hasExplicitThreadId;
|
|
4225
4229
|
(0, react.useEffect)(() => {
|
|
4226
4230
|
if (!configHasExplicitThreadId || !configThreadId) return;
|
|
4227
4231
|
agent.threadId = configThreadId;
|
|
@@ -4256,10 +4260,7 @@ window.parent.postMessage({jsonrpc:"2.0",method:"ui/notifications/sandbox-proxy-
|
|
|
4256
4260
|
function useSuggestions({ agentId } = {}) {
|
|
4257
4261
|
const { copilotkit } = useCopilotKit();
|
|
4258
4262
|
const config = useCopilotChatConfiguration();
|
|
4259
|
-
const resolvedAgentId = (0, react.useMemo)(() =>
|
|
4260
|
-
var _ref;
|
|
4261
|
-
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;
|
|
4262
|
-
}, [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]);
|
|
4263
4264
|
const [suggestions, setSuggestions] = (0, react.useState)(() => {
|
|
4264
4265
|
return copilotkit.getSuggestions(resolvedAgentId).suggestions;
|
|
4265
4266
|
});
|
|
@@ -4312,11 +4313,8 @@ window.parent.postMessage({jsonrpc:"2.0",method:"ui/notifications/sandbox-proxy-
|
|
|
4312
4313
|
function useConfigureSuggestions(config, deps) {
|
|
4313
4314
|
const { copilotkit } = useCopilotKit();
|
|
4314
4315
|
const chatConfig = useCopilotChatConfiguration();
|
|
4315
|
-
const extraDeps = deps
|
|
4316
|
-
const resolvedConsumerAgentId = (0, react.useMemo)(() =>
|
|
4317
|
-
var _chatConfig$agentId;
|
|
4318
|
-
return (_chatConfig$agentId = chatConfig === null || chatConfig === void 0 ? void 0 : chatConfig.agentId) !== null && _chatConfig$agentId !== void 0 ? _chatConfig$agentId : _copilotkit_shared.DEFAULT_AGENT_ID;
|
|
4319
|
-
}, [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]);
|
|
4320
4318
|
const rawConsumerAgentId = (0, react.useMemo)(() => config ? config.consumerAgentId : void 0, [config]);
|
|
4321
4319
|
const normalizationCacheRef = (0, react.useRef)({
|
|
4322
4320
|
serialized: null,
|
|
@@ -4385,9 +4383,8 @@ window.parent.postMessage({jsonrpc:"2.0",method:"ui/notifications/sandbox-proxy-
|
|
|
4385
4383
|
const requestReload = (0, react.useCallback)(() => {
|
|
4386
4384
|
if (!normalizedConfig) return;
|
|
4387
4385
|
if (isGlobalConfig) {
|
|
4388
|
-
var _copilotkit$agents;
|
|
4389
4386
|
const seen = /* @__PURE__ */ new Set();
|
|
4390
|
-
const agents = Object.values(
|
|
4387
|
+
const agents = Object.values(copilotkit.agents ?? {});
|
|
4391
4388
|
for (const entry of agents) {
|
|
4392
4389
|
const agentId = entry.agentId;
|
|
4393
4390
|
if (!agentId) continue;
|
|
@@ -4464,13 +4461,10 @@ window.parent.postMessage({jsonrpc:"2.0",method:"ui/notifications/sandbox-proxy-
|
|
|
4464
4461
|
return "instructions" in config;
|
|
4465
4462
|
}
|
|
4466
4463
|
function normalizeStaticSuggestions(suggestions) {
|
|
4467
|
-
return suggestions.map((suggestion) => {
|
|
4468
|
-
|
|
4469
|
-
|
|
4470
|
-
|
|
4471
|
-
isLoading: (_suggestion$isLoading = suggestion.isLoading) !== null && _suggestion$isLoading !== void 0 ? _suggestion$isLoading : false
|
|
4472
|
-
};
|
|
4473
|
-
});
|
|
4464
|
+
return suggestions.map((suggestion) => ({
|
|
4465
|
+
...suggestion,
|
|
4466
|
+
isLoading: suggestion.isLoading ?? false
|
|
4467
|
+
}));
|
|
4474
4468
|
}
|
|
4475
4469
|
|
|
4476
4470
|
//#endregion
|
|
@@ -4572,54 +4566,75 @@ window.parent.postMessage({jsonrpc:"2.0",method:"ui/notifications/sandbox-proxy-
|
|
|
4572
4566
|
return () => subscription.unsubscribe();
|
|
4573
4567
|
}, [agent]);
|
|
4574
4568
|
const resolve = (0, react.useCallback)((response) => {
|
|
4575
|
-
var _pendingEventRef$curr;
|
|
4576
|
-
setPendingEvent(null);
|
|
4577
4569
|
copilotkit.runAgent({
|
|
4578
4570
|
agent,
|
|
4579
4571
|
forwardedProps: { command: {
|
|
4580
4572
|
resume: response,
|
|
4581
|
-
interruptEvent:
|
|
4573
|
+
interruptEvent: pendingEventRef.current?.value
|
|
4582
4574
|
} }
|
|
4583
4575
|
});
|
|
4584
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
|
+
};
|
|
4585
4595
|
(0, react.useEffect)(() => {
|
|
4586
4596
|
if (!pendingEvent) {
|
|
4587
4597
|
setHandlerResult(null);
|
|
4588
4598
|
return;
|
|
4589
4599
|
}
|
|
4590
|
-
if (
|
|
4600
|
+
if (!isEnabled(pendingEvent)) {
|
|
4591
4601
|
setHandlerResult(null);
|
|
4592
4602
|
return;
|
|
4593
4603
|
}
|
|
4594
|
-
const handler =
|
|
4604
|
+
const handler = handlerRef.current;
|
|
4595
4605
|
if (!handler) {
|
|
4596
4606
|
setHandlerResult(null);
|
|
4597
4607
|
return;
|
|
4598
4608
|
}
|
|
4599
4609
|
let cancelled = false;
|
|
4600
|
-
|
|
4601
|
-
|
|
4602
|
-
|
|
4603
|
-
|
|
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
|
+
}
|
|
4604
4623
|
if (isPromiseLike(maybePromise)) Promise.resolve(maybePromise).then((resolved) => {
|
|
4605
4624
|
if (!cancelled) setHandlerResult(resolved);
|
|
4606
|
-
}).catch(() => {
|
|
4625
|
+
}).catch((err) => {
|
|
4626
|
+
console.error("[CopilotKit] useInterrupt handler rejected; result will be null:", err);
|
|
4607
4627
|
if (!cancelled) setHandlerResult(null);
|
|
4608
4628
|
});
|
|
4609
4629
|
else setHandlerResult(maybePromise);
|
|
4610
4630
|
return () => {
|
|
4611
4631
|
cancelled = true;
|
|
4612
4632
|
};
|
|
4613
|
-
}, [
|
|
4614
|
-
pendingEvent,
|
|
4615
|
-
config.enabled,
|
|
4616
|
-
config.handler,
|
|
4617
|
-
resolve
|
|
4618
|
-
]);
|
|
4633
|
+
}, [pendingEvent]);
|
|
4619
4634
|
const element = (0, react.useMemo)(() => {
|
|
4620
4635
|
if (!pendingEvent) return null;
|
|
4621
|
-
if (
|
|
4622
|
-
return
|
|
4636
|
+
if (!isEnabled(pendingEvent)) return null;
|
|
4637
|
+
return renderRef.current({
|
|
4623
4638
|
event: pendingEvent,
|
|
4624
4639
|
result: handlerResult,
|
|
4625
4640
|
resolve
|
|
@@ -4627,19 +4642,22 @@ window.parent.postMessage({jsonrpc:"2.0",method:"ui/notifications/sandbox-proxy-
|
|
|
4627
4642
|
}, [
|
|
4628
4643
|
pendingEvent,
|
|
4629
4644
|
handlerResult,
|
|
4630
|
-
config.enabled,
|
|
4631
|
-
config.render,
|
|
4632
4645
|
resolve
|
|
4633
4646
|
]);
|
|
4634
4647
|
(0, react.useEffect)(() => {
|
|
4635
4648
|
if (config.renderInChat === false) return;
|
|
4636
4649
|
copilotkit.setInterruptElement(element);
|
|
4637
|
-
return () => copilotkit.setInterruptElement(null);
|
|
4638
4650
|
}, [
|
|
4639
4651
|
element,
|
|
4640
4652
|
config.renderInChat,
|
|
4641
4653
|
copilotkit
|
|
4642
4654
|
]);
|
|
4655
|
+
(0, react.useEffect)(() => {
|
|
4656
|
+
if (config.renderInChat === false) return;
|
|
4657
|
+
return () => {
|
|
4658
|
+
copilotkit.setInterruptElement(null);
|
|
4659
|
+
};
|
|
4660
|
+
}, []);
|
|
4643
4661
|
if (config.renderInChat === false) return element;
|
|
4644
4662
|
}
|
|
4645
4663
|
|
|
@@ -4693,7 +4711,6 @@ window.parent.postMessage({jsonrpc:"2.0",method:"ui/notifications/sandbox-proxy-
|
|
|
4693
4711
|
* ```
|
|
4694
4712
|
*/
|
|
4695
4713
|
function useThreads({ agentId, includeArchived, limit }) {
|
|
4696
|
-
var _copilotkit$intellige2;
|
|
4697
4714
|
const { copilotkit } = useCopilotKit();
|
|
4698
4715
|
const [store] = (0, react.useState)(() => (0, _copilotkit_core.ɵcreateThreadStore)({ fetch: globalThis.fetch }));
|
|
4699
4716
|
const coreThreads = useThreadStoreSelector(store, _copilotkit_core.ɵselectThreads);
|
|
@@ -4711,8 +4728,7 @@ window.parent.postMessage({jsonrpc:"2.0",method:"ui/notifications/sandbox-proxy-
|
|
|
4711
4728
|
const hasMoreThreads = useThreadStoreSelector(store, _copilotkit_core.ɵselectHasNextPage);
|
|
4712
4729
|
const isFetchingMoreThreads = useThreadStoreSelector(store, _copilotkit_core.ɵselectIsFetchingNextPage);
|
|
4713
4730
|
const headersKey = (0, react.useMemo)(() => {
|
|
4714
|
-
|
|
4715
|
-
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)));
|
|
4716
4732
|
}, [copilotkit.headers]);
|
|
4717
4733
|
const runtimeError = (0, react.useMemo)(() => {
|
|
4718
4734
|
if (copilotkit.runtimeUrl) return null;
|
|
@@ -4721,7 +4737,7 @@ window.parent.postMessage({jsonrpc:"2.0",method:"ui/notifications/sandbox-proxy-
|
|
|
4721
4737
|
const [hasDispatchedContext, setHasDispatchedContext] = (0, react.useState)(false);
|
|
4722
4738
|
const preConnectLoading = !!copilotkit.runtimeUrl && !hasDispatchedContext;
|
|
4723
4739
|
const isLoading = runtimeError ? false : preConnectLoading || storeIsLoading;
|
|
4724
|
-
const error = runtimeError
|
|
4740
|
+
const error = runtimeError ?? storeError;
|
|
4725
4741
|
(0, react.useEffect)(() => {
|
|
4726
4742
|
store.start();
|
|
4727
4743
|
return () => {
|
|
@@ -4740,7 +4756,6 @@ window.parent.postMessage({jsonrpc:"2.0",method:"ui/notifications/sandbox-proxy-
|
|
|
4740
4756
|
store
|
|
4741
4757
|
]);
|
|
4742
4758
|
(0, react.useEffect)(() => {
|
|
4743
|
-
var _copilotkit$intellige;
|
|
4744
4759
|
if (!copilotkit.runtimeUrl) {
|
|
4745
4760
|
store.setContext(null);
|
|
4746
4761
|
return;
|
|
@@ -4749,7 +4764,7 @@ window.parent.postMessage({jsonrpc:"2.0",method:"ui/notifications/sandbox-proxy-
|
|
|
4749
4764
|
const context = {
|
|
4750
4765
|
runtimeUrl: copilotkit.runtimeUrl,
|
|
4751
4766
|
headers: { ...copilotkit.headers },
|
|
4752
|
-
wsUrl:
|
|
4767
|
+
wsUrl: copilotkit.intelligence?.wsUrl,
|
|
4753
4768
|
agentId,
|
|
4754
4769
|
includeArchived,
|
|
4755
4770
|
limit
|
|
@@ -4761,7 +4776,7 @@ window.parent.postMessage({jsonrpc:"2.0",method:"ui/notifications/sandbox-proxy-
|
|
|
4761
4776
|
copilotkit.runtimeUrl,
|
|
4762
4777
|
runtimeStatus,
|
|
4763
4778
|
headersKey,
|
|
4764
|
-
|
|
4779
|
+
copilotkit.intelligence?.wsUrl,
|
|
4765
4780
|
agentId,
|
|
4766
4781
|
includeArchived,
|
|
4767
4782
|
limit
|
|
@@ -4790,8 +4805,7 @@ window.parent.postMessage({jsonrpc:"2.0",method:"ui/notifications/sandbox-proxy-
|
|
|
4790
4805
|
* renders (via useCallback) to avoid destabilizing downstream memoization.
|
|
4791
4806
|
*/
|
|
4792
4807
|
function useAttachments({ config }) {
|
|
4793
|
-
|
|
4794
|
-
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;
|
|
4795
4809
|
const [attachments, setAttachments] = (0, react.useState)([]);
|
|
4796
4810
|
const [dragOver, setDragOver] = (0, react.useState)(false);
|
|
4797
4811
|
const fileInputRef = (0, react.useRef)(null);
|
|
@@ -4801,24 +4815,19 @@ window.parent.postMessage({jsonrpc:"2.0",method:"ui/notifications/sandbox-proxy-
|
|
|
4801
4815
|
const attachmentsRef = (0, react.useRef)([]);
|
|
4802
4816
|
attachmentsRef.current = attachments;
|
|
4803
4817
|
const processFiles = (0, react.useCallback)(async (files) => {
|
|
4804
|
-
var _cfg$accept, _cfg$maxSize;
|
|
4805
4818
|
const cfg = configRef.current;
|
|
4806
|
-
const accept =
|
|
4807
|
-
const maxSize =
|
|
4819
|
+
const accept = cfg?.accept ?? "*/*";
|
|
4820
|
+
const maxSize = cfg?.maxSize ?? 20 * 1024 * 1024;
|
|
4808
4821
|
const rejectedFiles = files.filter((file) => !(0, _copilotkit_shared.matchesAcceptFilter)(file, accept));
|
|
4809
|
-
for (const file of rejectedFiles) {
|
|
4810
|
-
|
|
4811
|
-
|
|
4812
|
-
|
|
4813
|
-
|
|
4814
|
-
message: `File "${file.name}" is not accepted. Supported types: ${accept}`
|
|
4815
|
-
});
|
|
4816
|
-
}
|
|
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
|
+
});
|
|
4817
4827
|
const validFiles = files.filter((file) => (0, _copilotkit_shared.matchesAcceptFilter)(file, accept));
|
|
4818
4828
|
for (const file of validFiles) {
|
|
4819
4829
|
if ((0, _copilotkit_shared.exceedsMaxSize)(file, maxSize)) {
|
|
4820
|
-
|
|
4821
|
-
cfg === null || cfg === void 0 || (_cfg$onUploadFailed2 = cfg.onUploadFailed) === null || _cfg$onUploadFailed2 === void 0 || _cfg$onUploadFailed2.call(cfg, {
|
|
4830
|
+
cfg?.onUploadFailed?.({
|
|
4822
4831
|
reason: "file-too-large",
|
|
4823
4832
|
file,
|
|
4824
4833
|
message: `File "${file.name}" exceeds the maximum size of ${(0, _copilotkit_shared.formatFileSize)(maxSize)}`
|
|
@@ -4843,7 +4852,7 @@ window.parent.postMessage({jsonrpc:"2.0",method:"ui/notifications/sandbox-proxy-
|
|
|
4843
4852
|
try {
|
|
4844
4853
|
let source;
|
|
4845
4854
|
let uploadMetadata;
|
|
4846
|
-
if (cfg
|
|
4855
|
+
if (cfg?.onUpload) {
|
|
4847
4856
|
const { metadata: meta, ...uploadSource } = await cfg.onUpload(file);
|
|
4848
4857
|
source = uploadSource;
|
|
4849
4858
|
uploadMetadata = meta;
|
|
@@ -4862,10 +4871,9 @@ window.parent.postMessage({jsonrpc:"2.0",method:"ui/notifications/sandbox-proxy-
|
|
|
4862
4871
|
metadata: uploadMetadata
|
|
4863
4872
|
} : att));
|
|
4864
4873
|
} catch (error) {
|
|
4865
|
-
var _cfg$onUploadFailed3;
|
|
4866
4874
|
setAttachments((prev) => prev.filter((att) => att.id !== placeholderId));
|
|
4867
4875
|
console.error(`[CopilotKit] Failed to upload "${file.name}":`, error);
|
|
4868
|
-
cfg
|
|
4876
|
+
cfg?.onUploadFailed?.({
|
|
4869
4877
|
reason: "upload-failed",
|
|
4870
4878
|
file,
|
|
4871
4879
|
message: error instanceof Error ? error.message : `Failed to upload "${file.name}"`
|
|
@@ -4874,8 +4882,7 @@ window.parent.postMessage({jsonrpc:"2.0",method:"ui/notifications/sandbox-proxy-
|
|
|
4874
4882
|
}
|
|
4875
4883
|
}, []);
|
|
4876
4884
|
const handleFileUpload = (0, react.useCallback)(async (e) => {
|
|
4877
|
-
|
|
4878
|
-
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;
|
|
4879
4886
|
try {
|
|
4880
4887
|
await processFiles(Array.from(e.target.files));
|
|
4881
4888
|
} catch (error) {
|
|
@@ -4883,8 +4890,7 @@ window.parent.postMessage({jsonrpc:"2.0",method:"ui/notifications/sandbox-proxy-
|
|
|
4883
4890
|
}
|
|
4884
4891
|
}, [processFiles]);
|
|
4885
4892
|
const handleDragOver = (0, react.useCallback)((e) => {
|
|
4886
|
-
|
|
4887
|
-
if (!((_configRef$current = configRef.current) === null || _configRef$current === void 0 ? void 0 : _configRef$current.enabled)) return;
|
|
4893
|
+
if (!configRef.current?.enabled) return;
|
|
4888
4894
|
e.preventDefault();
|
|
4889
4895
|
e.stopPropagation();
|
|
4890
4896
|
setDragOver(true);
|
|
@@ -4895,11 +4901,10 @@ window.parent.postMessage({jsonrpc:"2.0",method:"ui/notifications/sandbox-proxy-
|
|
|
4895
4901
|
setDragOver(false);
|
|
4896
4902
|
}, []);
|
|
4897
4903
|
const handleDrop = (0, react.useCallback)(async (e) => {
|
|
4898
|
-
var _configRef$current2;
|
|
4899
4904
|
e.preventDefault();
|
|
4900
4905
|
e.stopPropagation();
|
|
4901
4906
|
setDragOver(false);
|
|
4902
|
-
if (!
|
|
4907
|
+
if (!configRef.current?.enabled) return;
|
|
4903
4908
|
const files = Array.from(e.dataTransfer.files);
|
|
4904
4909
|
if (files.length > 0) try {
|
|
4905
4910
|
await processFiles(files);
|
|
@@ -4910,11 +4915,10 @@ window.parent.postMessage({jsonrpc:"2.0",method:"ui/notifications/sandbox-proxy-
|
|
|
4910
4915
|
(0, react.useEffect)(() => {
|
|
4911
4916
|
if (!enabled) return;
|
|
4912
4917
|
const handlePaste = async (e) => {
|
|
4913
|
-
var _containerRef$current, _configRef$current$ac, _configRef$current3, _e$clipboardData;
|
|
4914
4918
|
const target = e.target;
|
|
4915
|
-
if (!target || !
|
|
4916
|
-
const accept =
|
|
4917
|
-
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));
|
|
4918
4922
|
if (fileItems.length === 0) return;
|
|
4919
4923
|
e.preventDefault();
|
|
4920
4924
|
const files = fileItems.map((item) => item.getAsFile()).filter((f) => f !== null);
|
|
@@ -4968,7 +4972,6 @@ window.parent.postMessage({jsonrpc:"2.0",method:"ui/notifications/sandbox-proxy-
|
|
|
4968
4972
|
//#endregion
|
|
4969
4973
|
//#region src/v2/components/chat/CopilotChatAssistantMessage.tsx
|
|
4970
4974
|
function CopilotChatAssistantMessage({ message, messages, isRunning, onThumbsUp, onThumbsDown, onReadAloud, onRegenerate, additionalToolbarItems, toolbarVisible = true, markdownRenderer, toolbar, copyButton, thumbsUpButton, thumbsDownButton, readAloudButton, regenerateButton, toolCallsView, children, className, ...props }) {
|
|
4971
|
-
var _messages;
|
|
4972
4975
|
useKatexStyles();
|
|
4973
4976
|
const boundMarkdownRenderer = renderSlot(markdownRenderer, CopilotChatAssistantMessage.MarkdownRenderer, { content: message.content || "" });
|
|
4974
4977
|
const boundCopyButton = renderSlot(copyButton, CopilotChatAssistantMessage.CopyButton, { onClick: async () => {
|
|
@@ -4995,7 +4998,7 @@ window.parent.postMessage({jsonrpc:"2.0",method:"ui/notifications/sandbox-proxy-
|
|
|
4995
4998
|
messages
|
|
4996
4999
|
});
|
|
4997
5000
|
const hasContent = !!(message.content && message.content.trim().length > 0);
|
|
4998
|
-
const isLatestAssistantMessage = message.role === "assistant" &&
|
|
5001
|
+
const isLatestAssistantMessage = message.role === "assistant" && messages?.[messages.length - 1]?.id === message.id;
|
|
4999
5002
|
const shouldShowToolbar = toolbarVisible && hasContent && !(isRunning && isLatestAssistantMessage);
|
|
5000
5003
|
if (children) return /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
|
|
5001
5004
|
"data-copilotkit": true,
|
|
@@ -5040,7 +5043,7 @@ window.parent.postMessage({jsonrpc:"2.0",method:"ui/notifications/sandbox-proxy-
|
|
|
5040
5043
|
_CopilotChatAssistantMessage.MarkdownRenderer = ({ content, className, ...props }) => /* @__PURE__ */ (0, react_jsx_runtime.jsx)(streamdown.Streamdown, {
|
|
5041
5044
|
className,
|
|
5042
5045
|
...props,
|
|
5043
|
-
children: content
|
|
5046
|
+
children: content ?? ""
|
|
5044
5047
|
});
|
|
5045
5048
|
_CopilotChatAssistantMessage.Toolbar = ({ className, ...props }) => /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
|
|
5046
5049
|
"data-testid": "copilot-assistant-toolbar",
|
|
@@ -5063,9 +5066,7 @@ window.parent.postMessage({jsonrpc:"2.0",method:"ui/notifications/sandbox-proxy-
|
|
|
5063
5066
|
})] });
|
|
5064
5067
|
};
|
|
5065
5068
|
_CopilotChatAssistantMessage.CopyButton = ({ className, title, onClick, ...props }) => {
|
|
5066
|
-
|
|
5067
|
-
const config = useCopilotChatConfiguration();
|
|
5068
|
-
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;
|
|
5069
5070
|
const [copied, setCopied] = (0, react.useState)(false);
|
|
5070
5071
|
const timerRef = (0, react.useRef)(null);
|
|
5071
5072
|
(0, react.useEffect)(() => {
|
|
@@ -5095,9 +5096,7 @@ window.parent.postMessage({jsonrpc:"2.0",method:"ui/notifications/sandbox-proxy-
|
|
|
5095
5096
|
});
|
|
5096
5097
|
};
|
|
5097
5098
|
_CopilotChatAssistantMessage.ThumbsUpButton = ({ title, ...props }) => {
|
|
5098
|
-
|
|
5099
|
-
const config = useCopilotChatConfiguration();
|
|
5100
|
-
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;
|
|
5101
5100
|
return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(ToolbarButton, {
|
|
5102
5101
|
"data-testid": "copilot-thumbs-up-button",
|
|
5103
5102
|
title: title || labels.assistantMessageToolbarThumbsUpLabel,
|
|
@@ -5106,9 +5105,7 @@ window.parent.postMessage({jsonrpc:"2.0",method:"ui/notifications/sandbox-proxy-
|
|
|
5106
5105
|
});
|
|
5107
5106
|
};
|
|
5108
5107
|
_CopilotChatAssistantMessage.ThumbsDownButton = ({ title, ...props }) => {
|
|
5109
|
-
|
|
5110
|
-
const config = useCopilotChatConfiguration();
|
|
5111
|
-
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;
|
|
5112
5109
|
return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(ToolbarButton, {
|
|
5113
5110
|
"data-testid": "copilot-thumbs-down-button",
|
|
5114
5111
|
title: title || labels.assistantMessageToolbarThumbsDownLabel,
|
|
@@ -5117,9 +5114,7 @@ window.parent.postMessage({jsonrpc:"2.0",method:"ui/notifications/sandbox-proxy-
|
|
|
5117
5114
|
});
|
|
5118
5115
|
};
|
|
5119
5116
|
_CopilotChatAssistantMessage.ReadAloudButton = ({ title, ...props }) => {
|
|
5120
|
-
|
|
5121
|
-
const config = useCopilotChatConfiguration();
|
|
5122
|
-
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;
|
|
5123
5118
|
return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(ToolbarButton, {
|
|
5124
5119
|
"data-testid": "copilot-read-aloud-button",
|
|
5125
5120
|
title: title || labels.assistantMessageToolbarReadAloudLabel,
|
|
@@ -5128,9 +5123,7 @@ window.parent.postMessage({jsonrpc:"2.0",method:"ui/notifications/sandbox-proxy-
|
|
|
5128
5123
|
});
|
|
5129
5124
|
};
|
|
5130
5125
|
_CopilotChatAssistantMessage.RegenerateButton = ({ title, ...props }) => {
|
|
5131
|
-
|
|
5132
|
-
const config = useCopilotChatConfiguration();
|
|
5133
|
-
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;
|
|
5134
5127
|
return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(ToolbarButton, {
|
|
5135
5128
|
"data-testid": "copilot-regenerate-button",
|
|
5136
5129
|
title: title || labels.assistantMessageToolbarRegenerateLabel,
|
|
@@ -5267,12 +5260,11 @@ window.parent.postMessage({jsonrpc:"2.0",method:"ui/notifications/sandbox-proxy-
|
|
|
5267
5260
|
});
|
|
5268
5261
|
});
|
|
5269
5262
|
const DocumentAttachment = (0, react.memo)(function DocumentAttachment({ source, filename, className }) {
|
|
5270
|
-
var _source$mimeType;
|
|
5271
5263
|
return /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
|
|
5272
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),
|
|
5273
5265
|
children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
|
|
5274
5266
|
className: "cpk:text-xs cpk:font-bold cpk:uppercase",
|
|
5275
|
-
children: (0, _copilotkit_shared.getDocumentIcon)(
|
|
5267
|
+
children: (0, _copilotkit_shared.getDocumentIcon)(source.mimeType ?? "")
|
|
5276
5268
|
}), /* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
|
|
5277
5269
|
className: "cpk:text-sm cpk:text-muted-foreground cpk:truncate",
|
|
5278
5270
|
children: filename || source.mimeType || "Unknown type"
|
|
@@ -5329,7 +5321,7 @@ window.parent.postMessage({jsonrpc:"2.0",method:"ui/notifications/sandbox-proxy-
|
|
|
5329
5321
|
if (flattenedContent) return await (0, _copilotkit_shared.copyToClipboard)(flattenedContent);
|
|
5330
5322
|
return false;
|
|
5331
5323
|
} });
|
|
5332
|
-
const BoundEditButton = renderSlot(editButton, CopilotChatUserMessage.EditButton, { onClick: () => onEditMessage
|
|
5324
|
+
const BoundEditButton = renderSlot(editButton, CopilotChatUserMessage.EditButton, { onClick: () => onEditMessage?.({ message }) });
|
|
5333
5325
|
const BoundBranchNavigation = renderSlot(branchNavigation, CopilotChatUserMessage.BranchNavigation, {
|
|
5334
5326
|
currentBranch: branchIndex,
|
|
5335
5327
|
numberOfBranches,
|
|
@@ -5413,9 +5405,7 @@ window.parent.postMessage({jsonrpc:"2.0",method:"ui/notifications/sandbox-proxy-
|
|
|
5413
5405
|
})] });
|
|
5414
5406
|
};
|
|
5415
5407
|
_CopilotChatUserMessage.CopyButton = ({ className, title, onClick, ...props }) => {
|
|
5416
|
-
|
|
5417
|
-
const config = useCopilotChatConfiguration();
|
|
5418
|
-
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;
|
|
5419
5409
|
const [copied, setCopied] = (0, react.useState)(false);
|
|
5420
5410
|
const handleClick = async (event) => {
|
|
5421
5411
|
let success = false;
|
|
@@ -5435,9 +5425,7 @@ window.parent.postMessage({jsonrpc:"2.0",method:"ui/notifications/sandbox-proxy-
|
|
|
5435
5425
|
});
|
|
5436
5426
|
};
|
|
5437
5427
|
_CopilotChatUserMessage.EditButton = ({ className, title, ...props }) => {
|
|
5438
|
-
|
|
5439
|
-
const config = useCopilotChatConfiguration();
|
|
5440
|
-
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;
|
|
5441
5429
|
return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(ToolbarButton, {
|
|
5442
5430
|
"data-testid": "copilot-edit-button",
|
|
5443
5431
|
title: title || labels.userMessageToolbarEditMessageLabel,
|
|
@@ -5458,7 +5446,7 @@ window.parent.postMessage({jsonrpc:"2.0",method:"ui/notifications/sandbox-proxy-
|
|
|
5458
5446
|
/* @__PURE__ */ (0, react_jsx_runtime.jsx)(Button, {
|
|
5459
5447
|
type: "button",
|
|
5460
5448
|
variant: "assistantMessageToolbarButton",
|
|
5461
|
-
onClick: () => onSwitchToBranch
|
|
5449
|
+
onClick: () => onSwitchToBranch?.({
|
|
5462
5450
|
branchIndex: currentBranch - 1,
|
|
5463
5451
|
numberOfBranches,
|
|
5464
5452
|
message
|
|
@@ -5478,7 +5466,7 @@ window.parent.postMessage({jsonrpc:"2.0",method:"ui/notifications/sandbox-proxy-
|
|
|
5478
5466
|
/* @__PURE__ */ (0, react_jsx_runtime.jsx)(Button, {
|
|
5479
5467
|
type: "button",
|
|
5480
5468
|
variant: "assistantMessageToolbarButton",
|
|
5481
|
-
onClick: () => onSwitchToBranch
|
|
5469
|
+
onClick: () => onSwitchToBranch?.({
|
|
5482
5470
|
branchIndex: currentBranch + 1,
|
|
5483
5471
|
numberOfBranches,
|
|
5484
5472
|
message
|
|
@@ -5514,8 +5502,7 @@ window.parent.postMessage({jsonrpc:"2.0",method:"ui/notifications/sandbox-proxy-
|
|
|
5514
5502
|
return `${mins}m ${secs}s`;
|
|
5515
5503
|
}
|
|
5516
5504
|
function CopilotChatReasoningMessage({ message, messages, isRunning, header, contentView, toggle, children, className, ...props }) {
|
|
5517
|
-
|
|
5518
|
-
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;
|
|
5519
5506
|
const isStreaming = !!(isRunning && isLatest);
|
|
5520
5507
|
const hasContent = !!(message.content && message.content.length > 0);
|
|
5521
5508
|
const startTimeRef = (0, react.useRef)(null);
|
|
@@ -5645,7 +5632,7 @@ window.parent.postMessage({jsonrpc:"2.0",method:"ui/notifications/sandbox-proxy-
|
|
|
5645
5632
|
"data-testid": "copilot-suggestion",
|
|
5646
5633
|
"data-slot": "suggestion-pill",
|
|
5647
5634
|
className: cn(baseClasses, className),
|
|
5648
|
-
type: type
|
|
5635
|
+
type: type ?? "button",
|
|
5649
5636
|
"aria-busy": isLoading || void 0,
|
|
5650
5637
|
disabled: isLoading || props.disabled,
|
|
5651
5638
|
...props,
|
|
@@ -5694,16 +5681,15 @@ window.parent.postMessage({jsonrpc:"2.0",method:"ui/notifications/sandbox-proxy-
|
|
|
5694
5681
|
className: suggestion.className,
|
|
5695
5682
|
isLoading,
|
|
5696
5683
|
type: "button",
|
|
5697
|
-
onClick: () => onSelectSuggestion
|
|
5684
|
+
onClick: () => onSelectSuggestion?.(suggestion, index)
|
|
5698
5685
|
});
|
|
5699
5686
|
return react.default.cloneElement(pill, { key: `${suggestion.title}-${index}` });
|
|
5700
5687
|
});
|
|
5701
5688
|
const boundContainer = react.default.cloneElement(ContainerElement, void 0, suggestionElements);
|
|
5702
5689
|
if (typeof children === "function") {
|
|
5703
|
-
var _suggestions$0$title, _suggestions$, _suggestions$2;
|
|
5704
5690
|
const sampleSuggestion = renderSlot(suggestionSlot, CopilotChatSuggestionPill, {
|
|
5705
|
-
children:
|
|
5706
|
-
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,
|
|
5707
5693
|
type: "button"
|
|
5708
5694
|
});
|
|
5709
5695
|
return /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
|
|
@@ -5835,10 +5821,7 @@ window.parent.postMessage({jsonrpc:"2.0",method:"ui/notifications/sandbox-proxy-
|
|
|
5835
5821
|
if (message.role !== "assistant") return [];
|
|
5836
5822
|
const tcs = Array.isArray(message.toolCalls) ? message.toolCalls : [];
|
|
5837
5823
|
const ids = [];
|
|
5838
|
-
for (const tc of tcs)
|
|
5839
|
-
var _tc$function;
|
|
5840
|
-
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);
|
|
5841
|
-
}
|
|
5824
|
+
for (const tc of tcs) if (isMatchingToolCallName(tc?.function?.name) && tc?.id) ids.push(tc.id);
|
|
5842
5825
|
return ids;
|
|
5843
5826
|
}, [message]);
|
|
5844
5827
|
const hasPending = (0, react.useMemo)(() => {
|
|
@@ -5882,18 +5865,12 @@ window.parent.postMessage({jsonrpc:"2.0",method:"ui/notifications/sandbox-proxy-
|
|
|
5882
5865
|
if (!config) return null;
|
|
5883
5866
|
if (phase === "idle" || phase === "hidden") return null;
|
|
5884
5867
|
if (message.role !== "assistant") return null;
|
|
5885
|
-
if (!(Array.isArray(message.toolCalls) ? message.toolCalls : []).some((tc) =>
|
|
5886
|
-
var _tc$function2;
|
|
5887
|
-
return isMatchingToolCallName(tc === null || tc === void 0 || (_tc$function2 = tc.function) === null || _tc$function2 === void 0 ? void 0 : _tc$function2.name);
|
|
5888
|
-
})) return null;
|
|
5868
|
+
if (!(Array.isArray(message.toolCalls) ? message.toolCalls : []).some((tc) => isMatchingToolCallName(tc?.function?.name))) return null;
|
|
5889
5869
|
let latestMatchingAssistantId;
|
|
5890
5870
|
for (let i = agent.messages.length - 1; i >= 0; i -= 1) {
|
|
5891
5871
|
const m = agent.messages[i];
|
|
5892
5872
|
if (m.role !== "assistant") continue;
|
|
5893
|
-
if ((Array.isArray(m.toolCalls) ? m.toolCalls : []).some((tc) => {
|
|
5894
|
-
var _tc$function3;
|
|
5895
|
-
return isMatchingToolCallName(tc === null || tc === void 0 || (_tc$function3 = tc.function) === null || _tc$function3 === void 0 ? void 0 : _tc$function3.name);
|
|
5896
|
-
})) {
|
|
5873
|
+
if ((Array.isArray(m.toolCalls) ? m.toolCalls : []).some((tc) => isMatchingToolCallName(tc?.function?.name))) {
|
|
5897
5874
|
latestMatchingAssistantId = m.id;
|
|
5898
5875
|
break;
|
|
5899
5876
|
}
|
|
@@ -5969,12 +5946,11 @@ window.parent.postMessage({jsonrpc:"2.0",method:"ui/notifications/sandbox-proxy-
|
|
|
5969
5946
|
...slotProps
|
|
5970
5947
|
});
|
|
5971
5948
|
}, (prevProps, nextProps) => {
|
|
5972
|
-
var _nextProps$messages;
|
|
5973
5949
|
if (prevProps.message.id !== nextProps.message.id) return false;
|
|
5974
5950
|
if (prevProps.message.content !== nextProps.message.content) return false;
|
|
5975
5951
|
const prevToolCalls = prevProps.message.toolCalls;
|
|
5976
5952
|
const nextToolCalls = nextProps.message.toolCalls;
|
|
5977
|
-
if (
|
|
5953
|
+
if (prevToolCalls?.length !== nextToolCalls?.length) return false;
|
|
5978
5954
|
if (prevToolCalls && nextToolCalls) for (let i = 0; i < prevToolCalls.length; i++) {
|
|
5979
5955
|
const prevTc = prevToolCalls[i];
|
|
5980
5956
|
const nextTc = nextToolCalls[i];
|
|
@@ -5988,7 +5964,7 @@ window.parent.postMessage({jsonrpc:"2.0",method:"ui/notifications/sandbox-proxy-
|
|
|
5988
5964
|
if (prevToolResults.length !== nextToolResults.length) return false;
|
|
5989
5965
|
for (let i = 0; i < prevToolResults.length; i++) if (prevToolResults[i].content !== nextToolResults[i].content) return false;
|
|
5990
5966
|
}
|
|
5991
|
-
if (
|
|
5967
|
+
if (nextProps.messages[nextProps.messages.length - 1]?.id === nextProps.message.id && prevProps.isRunning !== nextProps.isRunning) return false;
|
|
5992
5968
|
if (prevProps.AssistantMessageComponent !== nextProps.AssistantMessageComponent) return false;
|
|
5993
5969
|
if (prevProps.slotProps !== nextProps.slotProps) return false;
|
|
5994
5970
|
return true;
|
|
@@ -6030,11 +6006,10 @@ window.parent.postMessage({jsonrpc:"2.0",method:"ui/notifications/sandbox-proxy-
|
|
|
6030
6006
|
...slotProps
|
|
6031
6007
|
});
|
|
6032
6008
|
}, (prevProps, nextProps) => {
|
|
6033
|
-
var _prevProps$messages, _nextProps$messages2;
|
|
6034
6009
|
if (prevProps.message.id !== nextProps.message.id) return false;
|
|
6035
6010
|
if (prevProps.message.content !== nextProps.message.content) return false;
|
|
6036
|
-
const prevIsLatest =
|
|
6037
|
-
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;
|
|
6038
6013
|
if (prevIsLatest !== nextIsLatest) return false;
|
|
6039
6014
|
if (nextIsLatest && prevProps.isRunning !== nextProps.isRunning) return false;
|
|
6040
6015
|
if (prevProps.ReasoningMessageComponent !== nextProps.ReasoningMessageComponent) return false;
|
|
@@ -6072,9 +6047,8 @@ window.parent.postMessage({jsonrpc:"2.0",method:"ui/notifications/sandbox-proxy-
|
|
|
6072
6047
|
for (const message of messages) {
|
|
6073
6048
|
const existing = acc.get(message.id);
|
|
6074
6049
|
if (existing && message.role === "assistant" && existing.role === "assistant") {
|
|
6075
|
-
var _message$toolCalls;
|
|
6076
6050
|
const content = message.content || existing.content;
|
|
6077
|
-
const toolCalls =
|
|
6051
|
+
const toolCalls = message.toolCalls ?? existing.toolCalls;
|
|
6078
6052
|
acc.set(message.id, {
|
|
6079
6053
|
...existing,
|
|
6080
6054
|
...message,
|
|
@@ -6087,20 +6061,19 @@ window.parent.postMessage({jsonrpc:"2.0",method:"ui/notifications/sandbox-proxy-
|
|
|
6087
6061
|
}
|
|
6088
6062
|
const VIRTUALIZE_THRESHOLD = 50;
|
|
6089
6063
|
function CopilotChatMessageView({ messages = [], assistantMessage, userMessage, reasoningMessage, cursor, isRunning = false, children, className, ...props }) {
|
|
6090
|
-
var _deduplicatedMessages;
|
|
6091
6064
|
const renderCustomMessage = useRenderCustomMessages();
|
|
6092
6065
|
const { renderActivityMessage } = useRenderActivityMessage();
|
|
6093
6066
|
const { copilotkit } = useCopilotKit();
|
|
6094
6067
|
const config = useCopilotChatConfiguration();
|
|
6095
6068
|
const [, forceUpdate] = (0, react.useReducer)((x) => x + 1, 0);
|
|
6096
6069
|
(0, react.useEffect)(() => {
|
|
6097
|
-
if (!
|
|
6070
|
+
if (!config?.agentId) return;
|
|
6098
6071
|
const agent = copilotkit.getAgent(config.agentId);
|
|
6099
6072
|
if (!agent) return;
|
|
6100
6073
|
const subscription = agent.subscribe({ onStateChanged: forceUpdate });
|
|
6101
6074
|
return () => subscription.unsubscribe();
|
|
6102
6075
|
}, [
|
|
6103
|
-
config
|
|
6076
|
+
config?.agentId,
|
|
6104
6077
|
copilotkit,
|
|
6105
6078
|
forceUpdate
|
|
6106
6079
|
]);
|
|
@@ -6113,9 +6086,8 @@ window.parent.postMessage({jsonrpc:"2.0",method:"ui/notifications/sandbox-proxy-
|
|
|
6113
6086
|
return () => subscription.unsubscribe();
|
|
6114
6087
|
}, [copilotkit]);
|
|
6115
6088
|
const getStateSnapshotForMessage = (messageId) => {
|
|
6116
|
-
var _copilotkit$getRunIdF;
|
|
6117
6089
|
if (!config) return void 0;
|
|
6118
|
-
const resolvedRunId =
|
|
6090
|
+
const resolvedRunId = copilotkit.getRunIdForMessage(config.agentId, config.threadId, messageId) ?? copilotkit.getRunIdsForThread(config.agentId, config.threadId).slice(-1)[0];
|
|
6119
6091
|
if (!resolvedRunId) return void 0;
|
|
6120
6092
|
return copilotkit.getStateByRun(config.agentId, config.threadId, resolvedRunId);
|
|
6121
6093
|
};
|
|
@@ -6135,19 +6107,17 @@ window.parent.postMessage({jsonrpc:"2.0",method:"ui/notifications/sandbox-proxy-
|
|
|
6135
6107
|
getScrollElement: () => scrollElement,
|
|
6136
6108
|
estimateSize: () => 100,
|
|
6137
6109
|
overscan: 5,
|
|
6138
|
-
measureElement: (el) =>
|
|
6139
|
-
var _el$getBoundingClient;
|
|
6140
|
-
return (_el$getBoundingClient = el === null || el === void 0 ? void 0 : el.getBoundingClientRect().height) !== null && _el$getBoundingClient !== void 0 ? _el$getBoundingClient : 0;
|
|
6141
|
-
},
|
|
6110
|
+
measureElement: (el) => el?.getBoundingClientRect().height ?? 0,
|
|
6142
6111
|
initialRect: {
|
|
6143
6112
|
width: 0,
|
|
6144
6113
|
height: 600
|
|
6145
6114
|
}
|
|
6146
6115
|
});
|
|
6116
|
+
const firstMessageId = deduplicatedMessages[0]?.id;
|
|
6147
6117
|
(0, react.useLayoutEffect)(() => {
|
|
6148
6118
|
if (!shouldVirtualize || !deduplicatedMessages.length) return;
|
|
6149
6119
|
virtualizer.scrollToIndex(deduplicatedMessages.length - 1, { align: "end" });
|
|
6150
|
-
}, [shouldVirtualize,
|
|
6120
|
+
}, [shouldVirtualize, firstMessageId]);
|
|
6151
6121
|
const renderMessageBlock = (message) => {
|
|
6152
6122
|
const elements = [];
|
|
6153
6123
|
const stateSnapshot = getStateSnapshotForMessage(message.id);
|
|
@@ -6186,13 +6156,10 @@ window.parent.postMessage({jsonrpc:"2.0",method:"ui/notifications/sandbox-proxy-
|
|
|
6186
6156
|
renderCustomMessage,
|
|
6187
6157
|
stateSnapshot
|
|
6188
6158
|
}, `${message.id}-custom-after`));
|
|
6189
|
-
if (copilotkit.intelligence !== void 0 && message.role === "assistant") {
|
|
6190
|
-
|
|
6191
|
-
|
|
6192
|
-
|
|
6193
|
-
agentId: (_config$agentId = config === null || config === void 0 ? void 0 : config.agentId) !== null && _config$agentId !== void 0 ? _config$agentId : _copilotkit_shared.DEFAULT_AGENT_ID
|
|
6194
|
-
}, `${message.id}-intelligence`));
|
|
6195
|
-
}
|
|
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`));
|
|
6196
6163
|
return elements.filter(Boolean);
|
|
6197
6164
|
};
|
|
6198
6165
|
const messageElements = shouldVirtualize ? [] : deduplicatedMessages.flatMap(renderMessageBlock);
|
|
@@ -6207,7 +6174,7 @@ window.parent.postMessage({jsonrpc:"2.0",method:"ui/notifications/sandbox-proxy-
|
|
|
6207
6174
|
})
|
|
6208
6175
|
});
|
|
6209
6176
|
const lastMessage = messages[messages.length - 1];
|
|
6210
|
-
const showCursor = isRunning &&
|
|
6177
|
+
const showCursor = isRunning && lastMessage?.role !== "reasoning";
|
|
6211
6178
|
return /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
|
|
6212
6179
|
"data-copilotkit": true,
|
|
6213
6180
|
"data-testid": "copilot-message-list",
|
|
@@ -6416,7 +6383,7 @@ window.parent.postMessage({jsonrpc:"2.0",method:"ui/notifications/sandbox-proxy-
|
|
|
6416
6383
|
const textContent = attachment.source.type === "data" ? (() => {
|
|
6417
6384
|
try {
|
|
6418
6385
|
return atob(attachment.source.value);
|
|
6419
|
-
} catch
|
|
6386
|
+
} catch {
|
|
6420
6387
|
return attachment.source.value;
|
|
6421
6388
|
}
|
|
6422
6389
|
})() : null;
|
|
@@ -6442,7 +6409,7 @@ window.parent.postMessage({jsonrpc:"2.0",method:"ui/notifications/sandbox-proxy-
|
|
|
6442
6409
|
children: [
|
|
6443
6410
|
/* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
|
|
6444
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",
|
|
6445
|
-
children: (0, _copilotkit_shared.getDocumentIcon)(mimeType
|
|
6412
|
+
children: (0, _copilotkit_shared.getDocumentIcon)(mimeType ?? "")
|
|
6446
6413
|
}),
|
|
6447
6414
|
/* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
|
|
6448
6415
|
className: "cpk:text-center",
|
|
@@ -6471,7 +6438,7 @@ window.parent.postMessage({jsonrpc:"2.0",method:"ui/notifications/sandbox-proxy-
|
|
|
6471
6438
|
onClick: previewable ? openLightbox : void 0,
|
|
6472
6439
|
children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
|
|
6473
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",
|
|
6474
|
-
children: (0, _copilotkit_shared.getDocumentIcon)(mimeType
|
|
6441
|
+
children: (0, _copilotkit_shared.getDocumentIcon)(mimeType ?? "")
|
|
6475
6442
|
}), /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
|
|
6476
6443
|
className: "cpk:flex cpk:flex-col cpk:min-w-0",
|
|
6477
6444
|
children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
|
|
@@ -6731,13 +6698,13 @@ window.parent.postMessage({jsonrpc:"2.0",method:"ui/notifications/sandbox-proxy-
|
|
|
6731
6698
|
className: "cpk:w-full",
|
|
6732
6699
|
children: [attachments && attachments.length > 0 && /* @__PURE__ */ (0, react_jsx_runtime.jsx)(CopilotChatAttachmentQueue, {
|
|
6733
6700
|
attachments,
|
|
6734
|
-
onRemoveAttachment: (id) => onRemoveAttachment
|
|
6701
|
+
onRemoveAttachment: (id) => onRemoveAttachment?.(id),
|
|
6735
6702
|
className: "cpk:mb-2"
|
|
6736
6703
|
}), BoundInputForWelcome]
|
|
6737
6704
|
});
|
|
6738
6705
|
const BoundWelcomeScreen = renderSlot(welcomeScreenSlot, CopilotChatView.WelcomeScreen, {
|
|
6739
6706
|
input: inputWithAttachments,
|
|
6740
|
-
suggestionView: BoundSuggestionView
|
|
6707
|
+
suggestionView: BoundSuggestionView ?? /* @__PURE__ */ (0, react_jsx_runtime.jsx)(react_jsx_runtime.Fragment, {})
|
|
6741
6708
|
});
|
|
6742
6709
|
return /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
|
|
6743
6710
|
"data-copilotkit": true,
|
|
@@ -6758,7 +6725,7 @@ window.parent.postMessage({jsonrpc:"2.0",method:"ui/notifications/sandbox-proxy-
|
|
|
6758
6725
|
messageView: BoundMessageView,
|
|
6759
6726
|
input: BoundInput,
|
|
6760
6727
|
scrollView: BoundScrollView,
|
|
6761
|
-
suggestionView: BoundSuggestionView
|
|
6728
|
+
suggestionView: BoundSuggestionView ?? /* @__PURE__ */ (0, react_jsx_runtime.jsx)(react_jsx_runtime.Fragment, {})
|
|
6762
6729
|
})
|
|
6763
6730
|
});
|
|
6764
6731
|
return /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
|
|
@@ -6781,7 +6748,7 @@ window.parent.postMessage({jsonrpc:"2.0",method:"ui/notifications/sandbox-proxy-
|
|
|
6781
6748
|
className: "cpk:max-w-3xl cpk:mx-auto cpk:w-full cpk:pointer-events-auto",
|
|
6782
6749
|
children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(CopilotChatAttachmentQueue, {
|
|
6783
6750
|
attachments,
|
|
6784
|
-
onRemoveAttachment: (id) => onRemoveAttachment
|
|
6751
|
+
onRemoveAttachment: (id) => onRemoveAttachment?.(id),
|
|
6785
6752
|
className: "cpk:px-4"
|
|
6786
6753
|
})
|
|
6787
6754
|
}), BoundInput]
|
|
@@ -6794,8 +6761,7 @@ window.parent.postMessage({jsonrpc:"2.0",method:"ui/notifications/sandbox-proxy-
|
|
|
6794
6761
|
const { isAtBottom, scrollToBottom, scrollRef } = (0, use_stick_to_bottom.useStickToBottomContext)();
|
|
6795
6762
|
const [scrollEl, setScrollEl] = (0, react.useState)(null);
|
|
6796
6763
|
(0, react.useLayoutEffect)(() => {
|
|
6797
|
-
|
|
6798
|
-
setScrollEl((_scrollRef$current = scrollRef.current) !== null && _scrollRef$current !== void 0 ? _scrollRef$current : null);
|
|
6764
|
+
setScrollEl(scrollRef.current ?? null);
|
|
6799
6765
|
}, []);
|
|
6800
6766
|
const BoundFeather = renderSlot(feather, CopilotChatView.Feather, {});
|
|
6801
6767
|
return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(ScrollElementContext.Provider, {
|
|
@@ -6973,9 +6939,7 @@ window.parent.postMessage({jsonrpc:"2.0",method:"ui/notifications/sandbox-proxy-
|
|
|
6973
6939
|
...props
|
|
6974
6940
|
});
|
|
6975
6941
|
_CopilotChatView.WelcomeMessage = ({ className, ...props }) => {
|
|
6976
|
-
|
|
6977
|
-
const config = useCopilotChatConfiguration();
|
|
6978
|
-
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;
|
|
6979
6943
|
return /* @__PURE__ */ (0, react_jsx_runtime.jsx)("h1", {
|
|
6980
6944
|
className: cn("cpk:text-xl cpk:sm:text-2xl cpk:font-medium cpk:text-foreground cpk:text-center", className),
|
|
6981
6945
|
...props,
|
|
@@ -7031,7 +6995,7 @@ window.parent.postMessage({jsonrpc:"2.0",method:"ui/notifications/sandbox-proxy-
|
|
|
7031
6995
|
const reader = new FileReader();
|
|
7032
6996
|
reader.onloadend = () => {
|
|
7033
6997
|
const base64 = reader.result.split(",")[1];
|
|
7034
|
-
resolve(base64
|
|
6998
|
+
resolve(base64 ?? "");
|
|
7035
6999
|
};
|
|
7036
7000
|
reader.onerror = () => reject(/* @__PURE__ */ new Error("Failed to read audio data"));
|
|
7037
7001
|
reader.readAsDataURL(blob);
|
|
@@ -7047,11 +7011,10 @@ window.parent.postMessage({jsonrpc:"2.0",method:"ui/notifications/sandbox-proxy-
|
|
|
7047
7011
|
* Parse error info from a transcription error response
|
|
7048
7012
|
*/
|
|
7049
7013
|
function parseTranscriptionError(response) {
|
|
7050
|
-
var _response$retryable;
|
|
7051
7014
|
return {
|
|
7052
7015
|
code: response.error,
|
|
7053
7016
|
message: response.message,
|
|
7054
|
-
retryable:
|
|
7017
|
+
retryable: response.retryable ?? false
|
|
7055
7018
|
};
|
|
7056
7019
|
}
|
|
7057
7020
|
/**
|
|
@@ -7118,7 +7081,7 @@ window.parent.postMessage({jsonrpc:"2.0",method:"ui/notifications/sandbox-proxy-
|
|
|
7118
7081
|
let errorData;
|
|
7119
7082
|
try {
|
|
7120
7083
|
errorData = await response.json();
|
|
7121
|
-
} catch
|
|
7084
|
+
} catch {
|
|
7122
7085
|
throw new TranscriptionError({
|
|
7123
7086
|
code: _copilotkit_shared.TranscriptionErrorCode.PROVIDER_ERROR,
|
|
7124
7087
|
message: `HTTP ${response.status}: ${response.statusText}`,
|
|
@@ -7138,12 +7101,11 @@ window.parent.postMessage({jsonrpc:"2.0",method:"ui/notifications/sandbox-proxy-
|
|
|
7138
7101
|
//#endregion
|
|
7139
7102
|
//#region src/v2/components/chat/CopilotChat.tsx
|
|
7140
7103
|
function CopilotChat({ agentId, threadId, labels, chatView, isModalDefaultOpen, attachments: attachmentsConfig, onError, throttleMs, ...props }) {
|
|
7141
|
-
var _ref, _attachmentsConfig$ac;
|
|
7142
7104
|
const existingConfig = useCopilotChatConfiguration();
|
|
7143
|
-
const resolvedAgentId =
|
|
7144
|
-
const providedThreadId = threadId
|
|
7145
|
-
const resolvedThreadId = (0, react.useMemo)(() => providedThreadId
|
|
7146
|
-
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;
|
|
7147
7109
|
const { agent } = useAgent({
|
|
7148
7110
|
agentId: resolvedAgentId,
|
|
7149
7111
|
throttleMs
|
|
@@ -7162,15 +7124,11 @@ window.parent.postMessage({jsonrpc:"2.0",method:"ui/notifications/sandbox-proxy-
|
|
|
7162
7124
|
(0, react.useEffect)(() => {
|
|
7163
7125
|
if (!onErrorRef.current) return;
|
|
7164
7126
|
const subscription = copilotkit.subscribe({ onError: (event) => {
|
|
7165
|
-
|
|
7166
|
-
|
|
7167
|
-
|
|
7168
|
-
|
|
7169
|
-
|
|
7170
|
-
code: event.code,
|
|
7171
|
-
context: event.context
|
|
7172
|
-
});
|
|
7173
|
-
}
|
|
7127
|
+
if (event.context?.agentId === resolvedAgentId || !event.context?.agentId) onErrorRef.current?.({
|
|
7128
|
+
error: event.error,
|
|
7129
|
+
code: event.code,
|
|
7130
|
+
context: event.context
|
|
7131
|
+
});
|
|
7174
7132
|
} });
|
|
7175
7133
|
return () => {
|
|
7176
7134
|
subscription.unsubscribe();
|
|
@@ -7181,6 +7139,10 @@ window.parent.postMessage({jsonrpc:"2.0",method:"ui/notifications/sandbox-proxy-
|
|
|
7181
7139
|
const [transcriptionError, setTranscriptionError] = (0, react.useState)(null);
|
|
7182
7140
|
const [isTranscribing, setIsTranscribing] = (0, react.useState)(false);
|
|
7183
7141
|
const { attachments: selectedAttachments, enabled: attachmentsEnabled, dragOver, fileInputRef, containerRef: chatContainerRef, handleFileUpload, handleDragOver, handleDragLeave, handleDrop, removeAttachment, consumeAttachments } = useAttachments({ config: attachmentsConfig });
|
|
7142
|
+
const selectedAttachmentsRef = (0, react.useRef)(selectedAttachments);
|
|
7143
|
+
(0, react.useEffect)(() => {
|
|
7144
|
+
selectedAttachmentsRef.current = selectedAttachments;
|
|
7145
|
+
}, [selectedAttachments]);
|
|
7184
7146
|
const isTranscriptionEnabled = copilotkit.audioFileTranscriptionEnabled;
|
|
7185
7147
|
const isMediaRecorderSupported = typeof window !== "undefined" && typeof MediaRecorder !== "undefined";
|
|
7186
7148
|
const { messageView: providedMessageView, suggestionView: providedSuggestionView, onStop: providedStopHandler, ...restProps } = props;
|
|
@@ -7217,8 +7179,21 @@ window.parent.postMessage({jsonrpc:"2.0",method:"ui/notifications/sandbox-proxy-
|
|
|
7217
7179
|
hasExplicitThreadId
|
|
7218
7180
|
]);
|
|
7219
7181
|
const onSubmitInput = (0, react.useCallback)(async (value) => {
|
|
7220
|
-
if (
|
|
7221
|
-
console.error("[CopilotKit] Cannot send while attachments are uploading");
|
|
7182
|
+
if (selectedAttachmentsRef.current.some((a) => a.status === "uploading")) {
|
|
7183
|
+
console.error("[CopilotKit] Cannot send while attachments are uploading (pre-await guard)");
|
|
7184
|
+
setTranscriptionError("Cannot send while attachments are uploading.");
|
|
7185
|
+
return;
|
|
7186
|
+
}
|
|
7187
|
+
setInputValue("");
|
|
7188
|
+
if (agent.isRunning && "activeRunCompletionPromise" in agent && agent.activeRunCompletionPromise) try {
|
|
7189
|
+
await agent.activeRunCompletionPromise;
|
|
7190
|
+
} catch (error) {
|
|
7191
|
+
console.error("CopilotChat: in-flight run rejected while queuing send", error);
|
|
7192
|
+
}
|
|
7193
|
+
if (selectedAttachmentsRef.current.some((a) => a.status === "uploading")) {
|
|
7194
|
+
console.error("[CopilotKit] Cannot send while attachments are uploading (post-await re-check)");
|
|
7195
|
+
setTranscriptionError("Cannot send while attachments are uploading.");
|
|
7196
|
+
setInputValue(value);
|
|
7222
7197
|
return;
|
|
7223
7198
|
}
|
|
7224
7199
|
const readyAttachments = consumeAttachments();
|
|
@@ -7246,17 +7221,12 @@ window.parent.postMessage({jsonrpc:"2.0",method:"ui/notifications/sandbox-proxy-
|
|
|
7246
7221
|
role: "user",
|
|
7247
7222
|
content: value
|
|
7248
7223
|
});
|
|
7249
|
-
setInputValue("");
|
|
7250
7224
|
try {
|
|
7251
7225
|
await copilotkit.runAgent({ agent });
|
|
7252
7226
|
} catch (error) {
|
|
7253
7227
|
console.error("CopilotChat: runAgent failed", error);
|
|
7254
7228
|
}
|
|
7255
|
-
}, [
|
|
7256
|
-
agent,
|
|
7257
|
-
selectedAttachments,
|
|
7258
|
-
consumeAttachments
|
|
7259
|
-
]);
|
|
7229
|
+
}, [agent, consumeAttachments]);
|
|
7260
7230
|
const handleSelectSuggestion = (0, react.useCallback)(async (suggestion) => {
|
|
7261
7231
|
agent.addMessage({
|
|
7262
7232
|
id: (0, _copilotkit_shared.randomUUID)(),
|
|
@@ -7347,8 +7317,7 @@ window.parent.postMessage({jsonrpc:"2.0",method:"ui/notifications/sandbox-proxy-
|
|
|
7347
7317
|
const stableSuggestionView = useShallowStableRef(providedSuggestionView);
|
|
7348
7318
|
const handleAddFile = (0, react.useCallback)(() => {
|
|
7349
7319
|
setTimeout(() => {
|
|
7350
|
-
|
|
7351
|
-
(_fileInputRef$current = fileInputRef.current) === null || _fileInputRef$current === void 0 || _fileInputRef$current.click();
|
|
7320
|
+
fileInputRef.current?.click();
|
|
7352
7321
|
}, 100);
|
|
7353
7322
|
}, []);
|
|
7354
7323
|
const mergedProps = {
|
|
@@ -7360,15 +7329,12 @@ window.parent.postMessage({jsonrpc:"2.0",method:"ui/notifications/sandbox-proxy-
|
|
|
7360
7329
|
};
|
|
7361
7330
|
if (stableMessageView !== void 0) mergedProps.messageView = stableMessageView;
|
|
7362
7331
|
const hasMessages = agent.messages.length > 0;
|
|
7363
|
-
const effectiveStopHandler = agent.isRunning && hasMessages ? providedStopHandler
|
|
7332
|
+
const effectiveStopHandler = agent.isRunning && hasMessages ? providedStopHandler ?? stopCurrentRun : providedStopHandler;
|
|
7364
7333
|
const showTranscription = isTranscriptionEnabled && isMediaRecorderSupported;
|
|
7365
7334
|
const effectiveMode = isTranscribing ? "processing" : transcribeMode;
|
|
7366
7335
|
const messages = (0, react.useMemo)(() => [...agent.messages], [agent.messages.map((m) => {
|
|
7367
7336
|
const contentKey = typeof m.content === "string" ? m.content.length : Array.isArray(m.content) ? m.content.length : 0;
|
|
7368
|
-
const toolCallsKey = "toolCalls" in m && Array.isArray(m.toolCalls) ? m.toolCalls.map((tc) => {
|
|
7369
|
-
var _tc$function$argument, _tc$function;
|
|
7370
|
-
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}`;
|
|
7371
|
-
}).join(";") : "";
|
|
7337
|
+
const toolCallsKey = "toolCalls" in m && Array.isArray(m.toolCalls) ? m.toolCalls.map((tc) => `${tc.id}:${tc.function?.arguments?.length ?? 0}`).join(";") : "";
|
|
7372
7338
|
return `${m.id}:${m.role}:${contentKey}:${toolCallsKey}`;
|
|
7373
7339
|
}).join(",")]);
|
|
7374
7340
|
const lastUserMessageId = (0, react.useMemo)(() => {
|
|
@@ -7424,7 +7390,7 @@ window.parent.postMessage({jsonrpc:"2.0",method:"ui/notifications/sandbox-proxy-
|
|
|
7424
7390
|
multiple: true,
|
|
7425
7391
|
ref: fileInputRef,
|
|
7426
7392
|
onChange: handleFileUpload,
|
|
7427
|
-
accept:
|
|
7393
|
+
accept: attachmentsConfig?.accept ?? "*/*",
|
|
7428
7394
|
style: { display: "none" }
|
|
7429
7395
|
}),
|
|
7430
7396
|
!isChatLicensed && /* @__PURE__ */ (0, react_jsx_runtime.jsx)(InlineFeatureWarning, { featureName: "Chat" }),
|
|
@@ -7474,13 +7440,12 @@ window.parent.postMessage({jsonrpc:"2.0",method:"ui/notifications/sandbox-proxy-
|
|
|
7474
7440
|
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";
|
|
7475
7441
|
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");
|
|
7476
7442
|
const CopilotChatToggleButton = react.default.forwardRef(function CopilotChatToggleButton({ openIcon, closeIcon, className, ...buttonProps }, ref) {
|
|
7477
|
-
var _configuration$labels, _configuration$isModa, _configuration$setMod;
|
|
7478
7443
|
const { onClick, type, disabled, ...restProps } = buttonProps;
|
|
7479
7444
|
const configuration = useCopilotChatConfiguration();
|
|
7480
|
-
const labels =
|
|
7445
|
+
const labels = configuration?.labels ?? CopilotChatDefaultLabels;
|
|
7481
7446
|
const [fallbackOpen, setFallbackOpen] = (0, react.useState)(false);
|
|
7482
|
-
const isOpen =
|
|
7483
|
-
const setModalOpen =
|
|
7447
|
+
const isOpen = configuration?.isModalOpen ?? fallbackOpen;
|
|
7448
|
+
const setModalOpen = configuration?.setModalOpen ?? setFallbackOpen;
|
|
7484
7449
|
const handleClick = (event) => {
|
|
7485
7450
|
if (disabled) return;
|
|
7486
7451
|
if (onClick) onClick(event);
|
|
@@ -7521,7 +7486,7 @@ window.parent.postMessage({jsonrpc:"2.0",method:"ui/notifications/sandbox-proxy-
|
|
|
7521
7486
|
});
|
|
7522
7487
|
return /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("button", {
|
|
7523
7488
|
ref,
|
|
7524
|
-
type: type
|
|
7489
|
+
type: type ?? "button",
|
|
7525
7490
|
"data-copilotkit": true,
|
|
7526
7491
|
"data-testid": "copilot-chat-toggle",
|
|
7527
7492
|
"data-slot": "chat-toggle-button",
|
|
@@ -7540,13 +7505,11 @@ window.parent.postMessage({jsonrpc:"2.0",method:"ui/notifications/sandbox-proxy-
|
|
|
7540
7505
|
//#endregion
|
|
7541
7506
|
//#region src/v2/components/chat/CopilotModalHeader.tsx
|
|
7542
7507
|
function CopilotModalHeader({ title, titleContent, closeButton, children, className, ...rest }) {
|
|
7543
|
-
var _configuration$labels;
|
|
7544
7508
|
const configuration = useCopilotChatConfiguration();
|
|
7545
|
-
const fallbackTitle =
|
|
7546
|
-
const resolvedTitle = title
|
|
7509
|
+
const fallbackTitle = configuration?.labels.modalHeaderTitle ?? CopilotChatDefaultLabels.modalHeaderTitle;
|
|
7510
|
+
const resolvedTitle = title ?? fallbackTitle;
|
|
7547
7511
|
const handleClose = (0, react.useCallback)(() => {
|
|
7548
|
-
|
|
7549
|
-
configuration === null || configuration === void 0 || (_configuration$setMod = configuration.setModalOpen) === null || _configuration$setMod === void 0 || _configuration$setMod.call(configuration, false);
|
|
7512
|
+
configuration?.setModalOpen?.(false);
|
|
7550
7513
|
}, [configuration]);
|
|
7551
7514
|
const BoundTitle = renderSlot(titleContent, CopilotModalHeader.Title, { children: resolvedTitle });
|
|
7552
7515
|
const BoundCloseButton = renderSlot(closeButton, CopilotModalHeader.CloseButton, { onClick: handleClose });
|
|
@@ -7620,11 +7583,9 @@ window.parent.postMessage({jsonrpc:"2.0",method:"ui/notifications/sandbox-proxy-
|
|
|
7620
7583
|
});
|
|
7621
7584
|
}
|
|
7622
7585
|
function CopilotSidebarViewInternal({ header, toggleButton, width, position = "right", ...props }) {
|
|
7623
|
-
|
|
7624
|
-
const configuration = useCopilotChatConfiguration();
|
|
7625
|
-
const isSidebarOpen = (_configuration$isModa = configuration === null || configuration === void 0 ? void 0 : configuration.isModalOpen) !== null && _configuration$isModa !== void 0 ? _configuration$isModa : false;
|
|
7586
|
+
const isSidebarOpen = useCopilotChatConfiguration()?.isModalOpen ?? false;
|
|
7626
7587
|
const sidebarRef = (0, react.useRef)(null);
|
|
7627
|
-
const [sidebarWidth, setSidebarWidth] = (0, react.useState)(width
|
|
7588
|
+
const [sidebarWidth, setSidebarWidth] = (0, react.useState)(width ?? DEFAULT_SIDEBAR_WIDTH);
|
|
7628
7589
|
const widthToCss = (w) => {
|
|
7629
7590
|
return typeof w === "number" ? `${w}px` : w;
|
|
7630
7591
|
};
|
|
@@ -7758,11 +7719,10 @@ window.parent.postMessage({jsonrpc:"2.0",method:"ui/notifications/sandbox-proxy-
|
|
|
7758
7719
|
});
|
|
7759
7720
|
}
|
|
7760
7721
|
function CopilotPopupViewInternal({ header, toggleButton, width, height, clickOutsideToClose, className, ...restProps }) {
|
|
7761
|
-
var _configuration$isModa, _configuration$labels;
|
|
7762
7722
|
const configuration = useCopilotChatConfiguration();
|
|
7763
|
-
const isPopupOpen =
|
|
7764
|
-
const setModalOpen = configuration
|
|
7765
|
-
const labels =
|
|
7723
|
+
const isPopupOpen = configuration?.isModalOpen ?? false;
|
|
7724
|
+
const setModalOpen = configuration?.setModalOpen;
|
|
7725
|
+
const labels = configuration?.labels ?? CopilotChatDefaultLabels;
|
|
7766
7726
|
const containerRef = (0, react.useRef)(null);
|
|
7767
7727
|
const [isRendered, setIsRendered] = (0, react.useState)(isPopupOpen);
|
|
7768
7728
|
const [isAnimatingOut, setIsAnimatingOut] = (0, react.useState)(false);
|
|
@@ -7786,7 +7746,7 @@ window.parent.postMessage({jsonrpc:"2.0",method:"ui/notifications/sandbox-proxy-
|
|
|
7786
7746
|
const handleKeyDown = (event) => {
|
|
7787
7747
|
if (event.key === "Escape") {
|
|
7788
7748
|
event.preventDefault();
|
|
7789
|
-
setModalOpen
|
|
7749
|
+
setModalOpen?.(false);
|
|
7790
7750
|
}
|
|
7791
7751
|
};
|
|
7792
7752
|
window.addEventListener("keydown", handleKeyDown);
|
|
@@ -7806,11 +7766,10 @@ window.parent.postMessage({jsonrpc:"2.0",method:"ui/notifications/sandbox-proxy-
|
|
|
7806
7766
|
const handlePointerDown = (event) => {
|
|
7807
7767
|
const target = event.target;
|
|
7808
7768
|
if (!target) return;
|
|
7809
|
-
|
|
7810
|
-
if (container === null || container === void 0 ? void 0 : container.contains(target)) return;
|
|
7769
|
+
if (containerRef.current?.contains(target)) return;
|
|
7811
7770
|
const toggleButton = document.querySelector("[data-slot='chat-toggle-button']");
|
|
7812
7771
|
if (toggleButton && toggleButton.contains(target)) return;
|
|
7813
|
-
setModalOpen
|
|
7772
|
+
setModalOpen?.(false);
|
|
7814
7773
|
};
|
|
7815
7774
|
document.addEventListener("pointerdown", handlePointerDown);
|
|
7816
7775
|
return () => document.removeEventListener("pointerdown", handlePointerDown);
|
|
@@ -7900,11 +7859,11 @@ window.parent.postMessage({jsonrpc:"2.0",method:"ui/notifications/sandbox-proxy-
|
|
|
7900
7859
|
const { header: viewHeader, toggleButton: viewToggleButton, width: viewWidth, defaultOpen: viewDefaultOpen, position: viewPosition, ...restProps } = viewProps;
|
|
7901
7860
|
return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(CopilotSidebarView, {
|
|
7902
7861
|
...restProps,
|
|
7903
|
-
header: header
|
|
7904
|
-
toggleButton: toggleButton
|
|
7905
|
-
width: width
|
|
7906
|
-
defaultOpen: defaultOpen
|
|
7907
|
-
position: position
|
|
7862
|
+
header: header ?? viewHeader,
|
|
7863
|
+
toggleButton: toggleButton ?? viewToggleButton,
|
|
7864
|
+
width: width ?? viewWidth,
|
|
7865
|
+
defaultOpen: defaultOpen ?? viewDefaultOpen,
|
|
7866
|
+
position: position ?? viewPosition
|
|
7908
7867
|
});
|
|
7909
7868
|
};
|
|
7910
7869
|
return Object.assign(Component, CopilotChatView_default);
|
|
@@ -7937,12 +7896,12 @@ window.parent.postMessage({jsonrpc:"2.0",method:"ui/notifications/sandbox-proxy-
|
|
|
7937
7896
|
const { header: viewHeader, toggleButton: viewToggleButton, width: viewWidth, height: viewHeight, clickOutsideToClose: viewClickOutsideToClose, defaultOpen: viewDefaultOpen, ...restProps } = viewProps;
|
|
7938
7897
|
return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(CopilotPopupView_default, {
|
|
7939
7898
|
...restProps,
|
|
7940
|
-
header: header
|
|
7941
|
-
toggleButton: toggleButton
|
|
7942
|
-
width: width
|
|
7943
|
-
height: height
|
|
7944
|
-
clickOutsideToClose: clickOutsideToClose
|
|
7945
|
-
defaultOpen: defaultOpen
|
|
7899
|
+
header: header ?? viewHeader,
|
|
7900
|
+
toggleButton: toggleButton ?? viewToggleButton,
|
|
7901
|
+
width: width ?? viewWidth,
|
|
7902
|
+
height: height ?? viewHeight,
|
|
7903
|
+
clickOutsideToClose: clickOutsideToClose ?? viewClickOutsideToClose,
|
|
7904
|
+
defaultOpen: defaultOpen ?? viewDefaultOpen
|
|
7946
7905
|
});
|
|
7947
7906
|
};
|
|
7948
7907
|
return Object.assign(Component, CopilotChatView_default);
|
|
@@ -8009,7 +7968,7 @@ window.parent.postMessage({jsonrpc:"2.0",method:"ui/notifications/sandbox-proxy-
|
|
|
8009
7968
|
children: "Arguments"
|
|
8010
7969
|
}), /* @__PURE__ */ (0, react_jsx_runtime.jsx)("pre", {
|
|
8011
7970
|
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",
|
|
8012
|
-
children: JSON.stringify(args
|
|
7971
|
+
children: JSON.stringify(args ?? {}, null, 2)
|
|
8013
7972
|
})] }), result !== void 0 && /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", { children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
|
|
8014
7973
|
className: "cpk:text-xs cpk:uppercase cpk:tracking-wide cpk:text-zinc-500 cpk:dark:text-zinc-400",
|
|
8015
7974
|
children: "Result"
|
|
@@ -8354,6 +8313,7 @@ window.parent.postMessage({jsonrpc:"2.0",method:"ui/notifications/sandbox-proxy-
|
|
|
8354
8313
|
const details = bannerError.details;
|
|
8355
8314
|
const link = extractUrl(bannerError.message);
|
|
8356
8315
|
return /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
|
|
8316
|
+
"data-testid": "copilot-error-banner",
|
|
8357
8317
|
style: {
|
|
8358
8318
|
position: "fixed",
|
|
8359
8319
|
bottom: "20px",
|
|
@@ -8553,9 +8513,8 @@ window.parent.postMessage({jsonrpc:"2.0",method:"ui/notifications/sandbox-proxy-
|
|
|
8553
8513
|
setToasts((prev) => prev.filter((toast) => toast.id !== id));
|
|
8554
8514
|
}, []);
|
|
8555
8515
|
const addToast = (0, react.useCallback)((toast) => {
|
|
8556
|
-
var _toast$id;
|
|
8557
8516
|
if (!enabled) return;
|
|
8558
|
-
const id =
|
|
8517
|
+
const id = toast.id ?? Math.random().toString(36).slice(2, 9);
|
|
8559
8518
|
setToasts((currentToasts) => {
|
|
8560
8519
|
if (currentToasts.find((toast) => toast.id === id)) return currentToasts;
|
|
8561
8520
|
return [...currentToasts, {
|
|
@@ -8682,8 +8641,8 @@ window.parent.postMessage({jsonrpc:"2.0",method:"ui/notifications/sandbox-proxy-
|
|
|
8682
8641
|
]);
|
|
8683
8642
|
const createStructuredError = (gqlError) => {
|
|
8684
8643
|
const extensions = gqlError.extensions;
|
|
8685
|
-
const originalError = extensions
|
|
8686
|
-
if (originalError
|
|
8644
|
+
const originalError = extensions?.originalError;
|
|
8645
|
+
if (originalError?.stack) {
|
|
8687
8646
|
if (originalError.stack.includes("CopilotApiDiscoveryError")) return new _copilotkit_shared.CopilotKitApiDiscoveryError({ message: originalError.message });
|
|
8688
8647
|
if (originalError.stack.includes("CopilotKitRemoteEndpointDiscoveryError")) return new _copilotkit_shared.CopilotKitRemoteEndpointDiscoveryError({ message: originalError.message });
|
|
8689
8648
|
if (originalError.stack.includes("CopilotKitAgentDiscoveryError")) return new _copilotkit_shared.CopilotKitAgentDiscoveryError({
|
|
@@ -8691,8 +8650,8 @@ window.parent.postMessage({jsonrpc:"2.0",method:"ui/notifications/sandbox-proxy-
|
|
|
8691
8650
|
availableAgents: []
|
|
8692
8651
|
});
|
|
8693
8652
|
}
|
|
8694
|
-
const message =
|
|
8695
|
-
const code = extensions
|
|
8653
|
+
const message = originalError?.message || gqlError.message;
|
|
8654
|
+
const code = extensions?.code;
|
|
8696
8655
|
if (code) return new _copilotkit_shared.CopilotKitError({
|
|
8697
8656
|
message,
|
|
8698
8657
|
code
|
|
@@ -8700,12 +8659,11 @@ window.parent.postMessage({jsonrpc:"2.0",method:"ui/notifications/sandbox-proxy-
|
|
|
8700
8659
|
return null;
|
|
8701
8660
|
};
|
|
8702
8661
|
(0, react.useCallback)((error) => {
|
|
8703
|
-
|
|
8704
|
-
if ((_error$graphQLErrors = error.graphQLErrors) === null || _error$graphQLErrors === void 0 ? void 0 : _error$graphQLErrors.length) {
|
|
8662
|
+
if (error.graphQLErrors?.length) {
|
|
8705
8663
|
const graphQLErrors = error.graphQLErrors;
|
|
8706
8664
|
const routeError = (gqlError) => {
|
|
8707
|
-
const
|
|
8708
|
-
const suppression = getErrorSuppression(
|
|
8665
|
+
const visibility = gqlError.extensions?.visibility;
|
|
8666
|
+
const suppression = getErrorSuppression(visibility, shouldShowDevConsole(showDevConsole));
|
|
8709
8667
|
if (suppression) {
|
|
8710
8668
|
console.error(suppression, gqlError.message);
|
|
8711
8669
|
return;
|
|
@@ -8726,7 +8684,7 @@ window.parent.postMessage({jsonrpc:"2.0",method:"ui/notifications/sandbox-proxy-
|
|
|
8726
8684
|
graphQLErrors.forEach(routeError);
|
|
8727
8685
|
} else {
|
|
8728
8686
|
const fallbackError = new _copilotkit_shared.CopilotKitError({
|
|
8729
|
-
message:
|
|
8687
|
+
message: error?.message || String(error),
|
|
8730
8688
|
code: _copilotkit_shared.CopilotKitErrorCode.UNKNOWN
|
|
8731
8689
|
});
|
|
8732
8690
|
setBannerError(fallbackError);
|
|
@@ -8913,6 +8871,7 @@ window.parent.postMessage({jsonrpc:"2.0",method:"ui/notifications/sandbox-proxy-
|
|
|
8913
8871
|
}
|
|
8914
8872
|
` }), /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
|
|
8915
8873
|
className: "usage-banner",
|
|
8874
|
+
"data-testid": "copilot-error-banner",
|
|
8916
8875
|
children: /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
|
|
8917
8876
|
className: "banner-content",
|
|
8918
8877
|
children: [
|
|
@@ -8920,7 +8879,7 @@ window.parent.postMessage({jsonrpc:"2.0",method:"ui/notifications/sandbox-proxy-
|
|
|
8920
8879
|
className: "banner-message",
|
|
8921
8880
|
children: message
|
|
8922
8881
|
}),
|
|
8923
|
-
|
|
8882
|
+
actions?.primary && /* @__PURE__ */ (0, react_jsx_runtime.jsx)("button", {
|
|
8924
8883
|
className: "btn-primary",
|
|
8925
8884
|
onClick: actions.primary.onClick,
|
|
8926
8885
|
children: actions.primary.label
|
|
@@ -8970,7 +8929,7 @@ window.parent.postMessage({jsonrpc:"2.0",method:"ui/notifications/sandbox-proxy-
|
|
|
8970
8929
|
headers: { [_copilotkit_shared.COPILOT_CLOUD_PUBLIC_API_KEY_HEADER]: publicApiKey }
|
|
8971
8930
|
}).then((response) => response.json());
|
|
8972
8931
|
this.lastResponse = response;
|
|
8973
|
-
onUpdate
|
|
8932
|
+
onUpdate?.(response);
|
|
8974
8933
|
return response;
|
|
8975
8934
|
} catch (error) {
|
|
8976
8935
|
return null;
|
|
@@ -9014,8 +8973,7 @@ window.parent.postMessage({jsonrpc:"2.0",method:"ui/notifications/sandbox-proxy-
|
|
|
9014
8973
|
componentDidMount() {
|
|
9015
8974
|
if (this.props.publicApiKey) statusChecker.start(this.props.publicApiKey, (newStatus) => {
|
|
9016
8975
|
this.setState((prevState) => {
|
|
9017
|
-
|
|
9018
|
-
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 };
|
|
8976
|
+
if (newStatus?.severity !== prevState.status?.severity) return { status: newStatus ?? void 0 };
|
|
9019
8977
|
return null;
|
|
9020
8978
|
});
|
|
9021
8979
|
});
|
|
@@ -9028,14 +8986,11 @@ window.parent.postMessage({jsonrpc:"2.0",method:"ui/notifications/sandbox-proxy-
|
|
|
9028
8986
|
}
|
|
9029
8987
|
render() {
|
|
9030
8988
|
if (this.state.hasError) {
|
|
9031
|
-
if (this.state.error instanceof _copilotkit_shared.CopilotKitError) {
|
|
9032
|
-
|
|
9033
|
-
|
|
9034
|
-
|
|
9035
|
-
|
|
9036
|
-
actions: getErrorActions(this.state.error)
|
|
9037
|
-
})] });
|
|
9038
|
-
}
|
|
8989
|
+
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, {
|
|
8990
|
+
severity: this.state.status?.severity ?? this.state.error.severity,
|
|
8991
|
+
message: this.state.status?.message ?? this.state.error.message,
|
|
8992
|
+
actions: getErrorActions(this.state.error)
|
|
8993
|
+
})] });
|
|
9039
8994
|
throw this.state.error;
|
|
9040
8995
|
}
|
|
9041
8996
|
return this.props.children;
|
|
@@ -9083,7 +9038,7 @@ window.parent.postMessage({jsonrpc:"2.0",method:"ui/notifications/sandbox-proxy-
|
|
|
9083
9038
|
function ThreadsProvider({ children, threadId: explicitThreadId }) {
|
|
9084
9039
|
const [internalThreadId, setInternalThreadId] = (0, react.useState)(() => (0, _copilotkit_shared.randomUUID)());
|
|
9085
9040
|
const [internalIsExplicit, setInternalIsExplicit] = (0, react.useState)(false);
|
|
9086
|
-
const threadId = explicitThreadId
|
|
9041
|
+
const threadId = explicitThreadId ?? internalThreadId;
|
|
9087
9042
|
const isThreadIdExplicit = explicitThreadId != null || internalIsExplicit;
|
|
9088
9043
|
const setThreadId = (0, react.useCallback)((value) => {
|
|
9089
9044
|
setInternalThreadId(value);
|
|
@@ -9164,13 +9119,10 @@ window.parent.postMessage({jsonrpc:"2.0",method:"ui/notifications/sandbox-proxy-
|
|
|
9164
9119
|
updateRunId: shouldUpdateRunId ? runId : void 0
|
|
9165
9120
|
};
|
|
9166
9121
|
}
|
|
9167
|
-
const normalizedRunId = runId
|
|
9168
|
-
const renderClaimedByOtherMessageEntry = Object.entries(claims).find(([, claim]) =>
|
|
9169
|
-
|
|
9170
|
-
|
|
9171
|
-
});
|
|
9172
|
-
const renderClaimedByOtherMessage = renderClaimedByOtherMessageEntry === null || renderClaimedByOtherMessageEntry === void 0 ? void 0 : renderClaimedByOtherMessageEntry[1];
|
|
9173
|
-
const claimedMessageId = renderClaimedByOtherMessageEntry === null || renderClaimedByOtherMessageEntry === void 0 ? void 0 : renderClaimedByOtherMessageEntry[0];
|
|
9122
|
+
const normalizedRunId = runId ?? "pending";
|
|
9123
|
+
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)));
|
|
9124
|
+
const renderClaimedByOtherMessage = renderClaimedByOtherMessageEntry?.[1];
|
|
9125
|
+
const claimedMessageId = renderClaimedByOtherMessageEntry?.[0];
|
|
9174
9126
|
if (renderClaimedByOtherMessage) {
|
|
9175
9127
|
if (messageIndex !== void 0 && renderClaimedByOtherMessage.messageIndex !== void 0 && messageIndex > renderClaimedByOtherMessage.messageIndex) return {
|
|
9176
9128
|
canRender: true,
|
|
@@ -9239,17 +9191,14 @@ window.parent.postMessage({jsonrpc:"2.0",method:"ui/notifications/sandbox-proxy-
|
|
|
9239
9191
|
* 5) last cached snapshot for stateRenderId
|
|
9240
9192
|
*/
|
|
9241
9193
|
function selectSnapshot({ messageId, messageName, allowLiveState, skipLatestCache, stateRenderId, effectiveRunId, stateSnapshotProp, agentState, agentMessages, existingClaim, caches }) {
|
|
9242
|
-
|
|
9243
|
-
const lastAssistantId = agentMessages ? (_toReversed$find = [...agentMessages].toReversed().find((msg) => msg.role === "assistant")) === null || _toReversed$find === void 0 ? void 0 : _toReversed$find.id : void 0;
|
|
9194
|
+
const lastAssistantId = agentMessages ? [...agentMessages].toReversed().find((msg) => msg.role === "assistant")?.id : void 0;
|
|
9244
9195
|
const latestSnapshot = stateRenderId !== void 0 ? caches.byStateRenderAndRun[`${stateRenderId}::latest`] : void 0;
|
|
9245
9196
|
const messageIndex = agentMessages ? agentMessages.findIndex((msg) => msg.id === messageId) : -1;
|
|
9246
|
-
const messageRole = messageIndex >= 0 && agentMessages ?
|
|
9197
|
+
const messageRole = messageIndex >= 0 && agentMessages ? agentMessages[messageIndex]?.role : void 0;
|
|
9247
9198
|
let previousUserMessageId;
|
|
9248
|
-
if (messageIndex > 0 && agentMessages)
|
|
9249
|
-
|
|
9250
|
-
|
|
9251
|
-
var _agentMessages$i2;
|
|
9252
|
-
previousUserMessageId = (_agentMessages$i2 = agentMessages[i]) === null || _agentMessages$i2 === void 0 ? void 0 : _agentMessages$i2.id;
|
|
9199
|
+
if (messageIndex > 0 && agentMessages) {
|
|
9200
|
+
for (let i = messageIndex - 1; i >= 0; i -= 1) if (agentMessages[i]?.role === "user") {
|
|
9201
|
+
previousUserMessageId = agentMessages[i]?.id;
|
|
9253
9202
|
break;
|
|
9254
9203
|
}
|
|
9255
9204
|
}
|
|
@@ -9261,11 +9210,11 @@ window.parent.postMessage({jsonrpc:"2.0",method:"ui/notifications/sandbox-proxy-
|
|
|
9261
9210
|
const messageCacheEntry = caches.byMessageId[messageId];
|
|
9262
9211
|
const cachedMessageSnapshot = readCachedMessageEntry(messageCacheEntry).snapshot;
|
|
9263
9212
|
const cacheKey = stateRenderId !== void 0 ? `${stateRenderId}::${effectiveRunId}` : void 0;
|
|
9264
|
-
let cachedSnapshot = cachedMessageSnapshot
|
|
9213
|
+
let cachedSnapshot = cachedMessageSnapshot ?? caches.byMessageId[messageId];
|
|
9265
9214
|
if (cachedSnapshot === void 0 && cacheKey && caches.byStateRenderAndRun[cacheKey] !== void 0) cachedSnapshot = caches.byStateRenderAndRun[cacheKey];
|
|
9266
9215
|
if (cachedSnapshot === void 0 && stateRenderId && previousUserMessageId && caches.byStateRenderAndRun[`${stateRenderId}::pending:${previousUserMessageId}`] !== void 0) cachedSnapshot = caches.byStateRenderAndRun[`${stateRenderId}::pending:${previousUserMessageId}`];
|
|
9267
9216
|
if (cachedSnapshot === void 0 && !skipLatestCache && stateRenderId && messageRole !== "assistant" && (stateSnapshotProp !== void 0 || agentState && Object.keys(agentState).length > 0)) cachedSnapshot = caches.byStateRenderAndRun[`${stateRenderId}::latest`];
|
|
9268
|
-
const snapshotForClaim =
|
|
9217
|
+
const snapshotForClaim = existingClaim?.locked ? existingClaim.stateSnapshot ?? cachedSnapshot : hasSnapshotKeys ? snapshot : existingClaim?.stateSnapshot ?? cachedSnapshot;
|
|
9269
9218
|
return {
|
|
9270
9219
|
snapshot,
|
|
9271
9220
|
hasSnapshotKeys,
|
|
@@ -9283,37 +9232,36 @@ window.parent.postMessage({jsonrpc:"2.0",method:"ui/notifications/sandbox-proxy-
|
|
|
9283
9232
|
return claimsRef.current;
|
|
9284
9233
|
}
|
|
9285
9234
|
function getSnapshotCaches(claimsRef) {
|
|
9286
|
-
var _store$LAST_SNAPSHOTS, _store$LAST_SNAPSHOTS2;
|
|
9287
9235
|
const store = getClaimsStore(claimsRef);
|
|
9288
9236
|
return {
|
|
9289
|
-
byStateRenderAndRun:
|
|
9290
|
-
byMessageId:
|
|
9237
|
+
byStateRenderAndRun: store[LAST_SNAPSHOTS_BY_RENDER_AND_RUN] ?? {},
|
|
9238
|
+
byMessageId: store[LAST_SNAPSHOTS_BY_MESSAGE] ?? {}
|
|
9291
9239
|
};
|
|
9292
9240
|
}
|
|
9293
9241
|
function useStateRenderRegistry({ agentId, stateRenderId, message, messageIndex, stateSnapshot, agentState, agentMessages, claimsRef }) {
|
|
9294
|
-
var _store$LAST_SNAPSHOTS3, _claimsRef$current$me;
|
|
9295
9242
|
const store = getClaimsStore(claimsRef);
|
|
9296
9243
|
const runId = message.runId;
|
|
9297
|
-
const
|
|
9244
|
+
const cachedMessageEntry = store[LAST_SNAPSHOTS_BY_MESSAGE]?.[message.id];
|
|
9245
|
+
const { runId: cachedMessageRunId } = readCachedMessageEntry(cachedMessageEntry);
|
|
9246
|
+
const existingClaimRunId = claimsRef.current[message.id]?.runId;
|
|
9298
9247
|
const effectiveRunId = getEffectiveRunId({
|
|
9299
|
-
existingClaimRunId
|
|
9248
|
+
existingClaimRunId,
|
|
9300
9249
|
cachedMessageRunId,
|
|
9301
9250
|
runId
|
|
9302
9251
|
});
|
|
9303
9252
|
(0, react.useEffect)(() => {
|
|
9304
9253
|
return () => {
|
|
9305
9254
|
const existingClaim = claimsRef.current[message.id];
|
|
9306
|
-
if (
|
|
9307
|
-
var _existingClaim$runId, _existingClaim$runId2;
|
|
9255
|
+
if (existingClaim?.stateSnapshot && Object.keys(existingClaim.stateSnapshot).length > 0) {
|
|
9308
9256
|
const snapshotCache = { ...store[LAST_SNAPSHOTS_BY_RENDER_AND_RUN] };
|
|
9309
|
-
const cacheKey = `${existingClaim.stateRenderId}::${
|
|
9257
|
+
const cacheKey = `${existingClaim.stateRenderId}::${existingClaim.runId ?? "pending"}`;
|
|
9310
9258
|
snapshotCache[cacheKey] = existingClaim.stateSnapshot;
|
|
9311
9259
|
snapshotCache[`${existingClaim.stateRenderId}::latest`] = existingClaim.stateSnapshot;
|
|
9312
9260
|
store[LAST_SNAPSHOTS_BY_RENDER_AND_RUN] = snapshotCache;
|
|
9313
9261
|
const messageCache = { ...store[LAST_SNAPSHOTS_BY_MESSAGE] };
|
|
9314
9262
|
messageCache[message.id] = {
|
|
9315
9263
|
snapshot: existingClaim.stateSnapshot,
|
|
9316
|
-
runId:
|
|
9264
|
+
runId: existingClaim.runId ?? effectiveRunId
|
|
9317
9265
|
};
|
|
9318
9266
|
store[LAST_SNAPSHOTS_BY_MESSAGE] = messageCache;
|
|
9319
9267
|
}
|
|
@@ -9357,7 +9305,7 @@ window.parent.postMessage({jsonrpc:"2.0",method:"ui/notifications/sandbox-proxy-
|
|
|
9357
9305
|
if (resolution.lockOthers) Object.entries(claimsRef.current).forEach(([id, claim]) => {
|
|
9358
9306
|
if (id !== message.id && claim.stateRenderId === stateRenderId) claim.locked = true;
|
|
9359
9307
|
});
|
|
9360
|
-
if (existingClaim && !existingClaim.locked &&
|
|
9308
|
+
if (existingClaim && !existingClaim.locked && agentMessages?.length) {
|
|
9361
9309
|
const indexInAgentMessages = agentMessages.findIndex((msg) => msg.id === message.id);
|
|
9362
9310
|
if (indexInAgentMessages >= 0 && indexInAgentMessages < agentMessages.length - 1) existingClaim.locked = true;
|
|
9363
9311
|
}
|
|
@@ -9401,7 +9349,6 @@ window.parent.postMessage({jsonrpc:"2.0",method:"ui/notifications/sandbox-proxy-
|
|
|
9401
9349
|
//#endregion
|
|
9402
9350
|
//#region src/hooks/use-coagent-state-render-bridge.tsx
|
|
9403
9351
|
function useCoagentStateRenderBridge(agentId, props) {
|
|
9404
|
-
var _props$runId;
|
|
9405
9352
|
const { stateSnapshot, message } = props;
|
|
9406
9353
|
const { coAgentStateRenders, claimsRef } = useCoAgentStateRenders();
|
|
9407
9354
|
const { agent } = useAgent({ agentId });
|
|
@@ -9437,46 +9384,42 @@ window.parent.postMessage({jsonrpc:"2.0",method:"ui/notifications/sandbox-proxy-
|
|
|
9437
9384
|
agentId
|
|
9438
9385
|
]);
|
|
9439
9386
|
const stateRenderEntry = (0, react.useMemo)(() => getStateRender(message.id), [getStateRender, message.id]);
|
|
9440
|
-
const stateRenderId = stateRenderEntry
|
|
9441
|
-
const stateRender = stateRenderEntry
|
|
9387
|
+
const stateRenderId = stateRenderEntry?.[0];
|
|
9388
|
+
const stateRender = stateRenderEntry?.[1];
|
|
9442
9389
|
const { canRender } = useStateRenderRegistry({
|
|
9443
9390
|
agentId,
|
|
9444
9391
|
stateRenderId,
|
|
9445
9392
|
message: {
|
|
9446
9393
|
...message,
|
|
9447
|
-
runId:
|
|
9394
|
+
runId: props.runId ?? message.runId
|
|
9448
9395
|
},
|
|
9449
9396
|
messageIndex: props.messageIndex,
|
|
9450
9397
|
stateSnapshot,
|
|
9451
|
-
agentState: agent
|
|
9452
|
-
agentMessages: agent
|
|
9398
|
+
agentState: agent?.state,
|
|
9399
|
+
agentMessages: agent?.messages,
|
|
9453
9400
|
claimsRef
|
|
9454
9401
|
});
|
|
9455
9402
|
return (0, react.useMemo)(() => {
|
|
9456
9403
|
if (!stateRender || !stateRenderId) return null;
|
|
9457
9404
|
if (!canRender) return null;
|
|
9458
|
-
if (stateRender.handler) {
|
|
9459
|
-
|
|
9460
|
-
|
|
9461
|
-
|
|
9462
|
-
nodeName: nodeName !== null && nodeName !== void 0 ? nodeName : ""
|
|
9463
|
-
});
|
|
9464
|
-
}
|
|
9405
|
+
if (stateRender.handler) stateRender.handler({
|
|
9406
|
+
state: stateSnapshot ? (0, _copilotkit_shared.parseJson)(stateSnapshot, stateSnapshot) : agent?.state ?? {},
|
|
9407
|
+
nodeName: nodeName ?? ""
|
|
9408
|
+
});
|
|
9465
9409
|
if (stateRender.render) {
|
|
9466
|
-
|
|
9467
|
-
const status = (agent === null || agent === void 0 ? void 0 : agent.isRunning) ? RenderStatus.InProgress : RenderStatus.Complete;
|
|
9410
|
+
const status = agent?.isRunning ? RenderStatus.InProgress : RenderStatus.Complete;
|
|
9468
9411
|
if (typeof stateRender.render === "string") return stateRender.render;
|
|
9469
9412
|
return stateRender.render({
|
|
9470
9413
|
status,
|
|
9471
|
-
state:
|
|
9472
|
-
nodeName: nodeName
|
|
9414
|
+
state: claimsRef.current[message.id].stateSnapshot ?? {},
|
|
9415
|
+
nodeName: nodeName ?? ""
|
|
9473
9416
|
});
|
|
9474
9417
|
}
|
|
9475
9418
|
}, [
|
|
9476
9419
|
stateRender,
|
|
9477
9420
|
stateRenderId,
|
|
9478
|
-
agent
|
|
9479
|
-
agent
|
|
9421
|
+
agent?.state,
|
|
9422
|
+
agent?.isRunning,
|
|
9480
9423
|
nodeName,
|
|
9481
9424
|
message.id,
|
|
9482
9425
|
stateSnapshot,
|
|
@@ -9497,7 +9440,7 @@ window.parent.postMessage({jsonrpc:"2.0",method:"ui/notifications/sandbox-proxy-
|
|
|
9497
9440
|
},
|
|
9498
9441
|
onToolCallArgsEvent: ({ partialToolCallArgs, toolCallName }) => {
|
|
9499
9442
|
predictStateToolsRef.current.forEach((t) => {
|
|
9500
|
-
if (
|
|
9443
|
+
if (t?.tool !== toolCallName) return;
|
|
9501
9444
|
const emittedState = typeof partialToolCallArgs === "string" ? (0, _copilotkit_shared.parseJson)(partialToolCallArgs, partialToolCallArgs) : partialToolCallArgs;
|
|
9502
9445
|
agent.setState({ [t.state_key]: emittedState[t.state_key] });
|
|
9503
9446
|
});
|
|
@@ -9513,16 +9456,15 @@ window.parent.postMessage({jsonrpc:"2.0",method:"ui/notifications/sandbox-proxy-
|
|
|
9513
9456
|
}, [agent, getSubscriber]);
|
|
9514
9457
|
};
|
|
9515
9458
|
function CopilotListenersAgentSubscription() {
|
|
9516
|
-
const
|
|
9517
|
-
const { agent } = useAgent({ agentId:
|
|
9459
|
+
const resolvedAgentId = useCopilotChatConfiguration()?.agentId;
|
|
9460
|
+
const { agent } = useAgent({ agentId: resolvedAgentId });
|
|
9518
9461
|
usePredictStateSubscription(agent);
|
|
9519
9462
|
return null;
|
|
9520
9463
|
}
|
|
9521
9464
|
function CopilotListeners() {
|
|
9522
|
-
var _copilotkit$agents;
|
|
9523
9465
|
const { copilotkit } = useCopilotKit();
|
|
9524
9466
|
const { setBannerError } = useToast();
|
|
9525
|
-
const hasAgents = Object.keys(
|
|
9467
|
+
const hasAgents = Object.keys(copilotkit.agents ?? {}).length > 0;
|
|
9526
9468
|
const hasRuntime = copilotkit.runtimeUrl !== void 0;
|
|
9527
9469
|
(0, react.useEffect)(() => {
|
|
9528
9470
|
const subscription = copilotkit.subscribe({ onError: ({ error, code, context }) => {
|
|
@@ -9544,7 +9486,7 @@ window.parent.postMessage({jsonrpc:"2.0",method:"ui/notifications/sandbox-proxy-
|
|
|
9544
9486
|
return () => {
|
|
9545
9487
|
subscription.unsubscribe();
|
|
9546
9488
|
};
|
|
9547
|
-
}, [copilotkit
|
|
9489
|
+
}, [copilotkit?.subscribe]);
|
|
9548
9490
|
return hasAgents || hasRuntime ? /* @__PURE__ */ (0, react_jsx_runtime.jsx)(CopilotListenersAgentSubscription, {}) : null;
|
|
9549
9491
|
}
|
|
9550
9492
|
|
|
@@ -9566,7 +9508,6 @@ window.parent.postMessage({jsonrpc:"2.0",method:"ui/notifications/sandbox-proxy-
|
|
|
9566
9508
|
* ```
|
|
9567
9509
|
*/
|
|
9568
9510
|
function CopilotKit({ children, ...props }) {
|
|
9569
|
-
var _props$useSingleEndpo;
|
|
9570
9511
|
const enabled = shouldShowDevConsole(props.showDevConsole);
|
|
9571
9512
|
const showInspector = shouldShowDevConsole(props.enableInspector);
|
|
9572
9513
|
const publicApiKey = props.publicApiKey || props.publicLicenseKey;
|
|
@@ -9582,7 +9523,7 @@ window.parent.postMessage({jsonrpc:"2.0",method:"ui/notifications/sandbox-proxy-
|
|
|
9582
9523
|
...props,
|
|
9583
9524
|
showDevConsole: showInspector,
|
|
9584
9525
|
renderCustomMessages: renderArr,
|
|
9585
|
-
useSingleEndpoint:
|
|
9526
|
+
useSingleEndpoint: props.useSingleEndpoint ?? true,
|
|
9586
9527
|
children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(CopilotKitInternal, {
|
|
9587
9528
|
...props,
|
|
9588
9529
|
children
|
|
@@ -9611,7 +9552,7 @@ window.parent.postMessage({jsonrpc:"2.0",method:"ui/notifications/sandbox-proxy-
|
|
|
9611
9552
|
source: "agent",
|
|
9612
9553
|
request: {
|
|
9613
9554
|
operation: event.code || "unknown",
|
|
9614
|
-
url: copilotApiConfig
|
|
9555
|
+
url: copilotApiConfig?.chatApiEndpoint,
|
|
9615
9556
|
startTime: Date.now()
|
|
9616
9557
|
},
|
|
9617
9558
|
technical: {
|
|
@@ -9640,7 +9581,6 @@ window.parent.postMessage({jsonrpc:"2.0",method:"ui/notifications/sandbox-proxy-
|
|
|
9640
9581
|
return null;
|
|
9641
9582
|
}
|
|
9642
9583
|
function CopilotKitInternal(cpkProps) {
|
|
9643
|
-
var _props$agent2;
|
|
9644
9584
|
const { children, ...props } = cpkProps;
|
|
9645
9585
|
/**
|
|
9646
9586
|
* This will throw an error if the props are invalid.
|
|
@@ -9704,14 +9644,11 @@ window.parent.postMessage({jsonrpc:"2.0",method:"ui/notifications/sandbox-proxy-
|
|
|
9704
9644
|
}, [removeDocument]);
|
|
9705
9645
|
const copilotApiConfig = (0, react.useMemo)(() => {
|
|
9706
9646
|
let cloud = void 0;
|
|
9707
|
-
if (publicApiKey) {
|
|
9708
|
-
|
|
9709
|
-
|
|
9710
|
-
|
|
9711
|
-
|
|
9712
|
-
invalidTopics: ((_props$guardrails_c2 = props.guardrails_c) === null || _props$guardrails_c2 === void 0 ? void 0 : _props$guardrails_c2.invalidTopics) || []
|
|
9713
|
-
} } } };
|
|
9714
|
-
}
|
|
9647
|
+
if (publicApiKey) cloud = { guardrails: { input: { restrictToTopic: {
|
|
9648
|
+
enabled: Boolean(props.guardrails_c),
|
|
9649
|
+
validTopics: props.guardrails_c?.validTopics || [],
|
|
9650
|
+
invalidTopics: props.guardrails_c?.invalidTopics || []
|
|
9651
|
+
} } } };
|
|
9715
9652
|
return {
|
|
9716
9653
|
publicApiKey,
|
|
9717
9654
|
...cloud ? { cloud } : {},
|
|
@@ -9867,14 +9804,8 @@ window.parent.postMessage({jsonrpc:"2.0",method:"ui/notifications/sandbox-proxy-
|
|
|
9867
9804
|
}, []);
|
|
9868
9805
|
const memoizedChildren = (0, react.useMemo)(() => children, [children]);
|
|
9869
9806
|
const [bannerError, setBannerError] = (0, react.useState)(null);
|
|
9870
|
-
const agentLock = (0, react.useMemo)(() =>
|
|
9871
|
-
|
|
9872
|
-
return (_props$agent = props.agent) !== null && _props$agent !== void 0 ? _props$agent : null;
|
|
9873
|
-
}, [props.agent]);
|
|
9874
|
-
const forwardedParameters = (0, react.useMemo)(() => {
|
|
9875
|
-
var _props$forwardedParam;
|
|
9876
|
-
return (_props$forwardedParam = props.forwardedParameters) !== null && _props$forwardedParam !== void 0 ? _props$forwardedParam : {};
|
|
9877
|
-
}, [props.forwardedParameters]);
|
|
9807
|
+
const agentLock = (0, react.useMemo)(() => props.agent ?? null, [props.agent]);
|
|
9808
|
+
const forwardedParameters = (0, react.useMemo)(() => props.forwardedParameters ?? {}, [props.forwardedParameters]);
|
|
9878
9809
|
const updateExtensions = (0, react.useCallback)((newExtensions) => {
|
|
9879
9810
|
setExtensions((prev) => {
|
|
9880
9811
|
const resolved = typeof newExtensions === "function" ? newExtensions(prev) : newExtensions;
|
|
@@ -10017,7 +9948,7 @@ window.parent.postMessage({jsonrpc:"2.0",method:"ui/notifications/sandbox-proxy-
|
|
|
10017
9948
|
removeInternalErrorHandler
|
|
10018
9949
|
]);
|
|
10019
9950
|
return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(CopilotChatConfigurationProvider, {
|
|
10020
|
-
agentId:
|
|
9951
|
+
agentId: props.agent ?? "default",
|
|
10021
9952
|
threadId,
|
|
10022
9953
|
hasExplicitThreadId: isThreadIdExplicit,
|
|
10023
9954
|
children: /* @__PURE__ */ (0, react_jsx_runtime.jsxs)(CopilotContext.Provider, {
|
|
@@ -10046,8 +9977,7 @@ window.parent.postMessage({jsonrpc:"2.0",method:"ui/notifications/sandbox-proxy-
|
|
|
10046
9977
|
await new Promise((resolve, reject) => {
|
|
10047
9978
|
(0, react_dom.flushSync)(async () => {
|
|
10048
9979
|
try {
|
|
10049
|
-
|
|
10050
|
-
result = await ((_action$handler = action.handler) === null || _action$handler === void 0 ? void 0 : _action$handler.call(action, args));
|
|
9980
|
+
result = await action.handler?.(args);
|
|
10051
9981
|
resolve();
|
|
10052
9982
|
} catch (error) {
|
|
10053
9983
|
reject(error);
|