@copilotkit/react-core 1.68.3 → 1.69.1
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-BUIK5yln.d.mts → copilotkit-DYKpg4pD.d.mts} +34 -25
- package/dist/copilotkit-DYKpg4pD.d.mts.map +1 -0
- package/dist/{copilotkit-Bocmlr37.cjs → copilotkit-Dr0speVK.cjs} +454 -48
- package/dist/copilotkit-Dr0speVK.cjs.map +1 -0
- package/dist/{copilotkit-C4RqjAba.mjs → copilotkit-Dr6g885f.mjs} +456 -50
- package/dist/copilotkit-Dr6g885f.mjs.map +1 -0
- package/dist/{copilotkit-DSvKW3SS.d.cts → copilotkit-Hl1t9Y1v.d.cts} +34 -25
- package/dist/copilotkit-Hl1t9Y1v.d.cts.map +1 -0
- package/dist/index.cjs +119 -75
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +904 -28
- package/dist/index.d.cts.map +1 -1
- package/dist/index.d.mts +904 -28
- package/dist/index.d.mts.map +1 -1
- package/dist/index.mjs +119 -75
- package/dist/index.mjs.map +1 -1
- package/dist/index.umd.js +185 -101
- package/dist/index.umd.js.map +1 -1
- package/dist/v2/headless.cjs +3 -2
- package/dist/v2/headless.cjs.map +1 -1
- package/dist/v2/headless.d.cts +5 -4
- package/dist/v2/headless.d.cts.map +1 -1
- package/dist/v2/headless.d.mts +5 -4
- package/dist/v2/headless.d.mts.map +1 -1
- package/dist/v2/headless.mjs +3 -2
- package/dist/v2/headless.mjs.map +1 -1
- package/dist/v2/index.cjs +1 -1
- package/dist/v2/index.css +1 -1
- package/dist/v2/index.d.cts +2 -2
- package/dist/v2/index.d.mts +2 -2
- package/dist/v2/index.mjs +1 -1
- package/dist/v2/index.umd.js +451 -45
- package/dist/v2/index.umd.js.map +1 -1
- package/package.json +8 -8
- package/skills/react-core/SKILL.md +1 -1
- package/skills/react-core/references/provider-setup.md +23 -2
- package/skills/react-core/references/threads.md +3 -4
- package/dist/copilotkit-BUIK5yln.d.mts.map +0 -1
- package/dist/copilotkit-Bocmlr37.cjs.map +0 -1
- package/dist/copilotkit-C4RqjAba.mjs.map +0 -1
- package/dist/copilotkit-DSvKW3SS.d.cts.map +0 -1
package/dist/v2/index.umd.js
CHANGED
|
@@ -92,6 +92,7 @@ _radix_ui_react_dropdown_menu = __toESM(_radix_ui_react_dropdown_menu);
|
|
|
92
92
|
assistantMessageToolbarCopyMessageLabel: "Copy",
|
|
93
93
|
assistantMessageToolbarInspectorLabel: "View in Inspector",
|
|
94
94
|
assistantMessageToolbarInspectorLocalOnlyLabel: "Local Only",
|
|
95
|
+
assistantMessageToolbarSaveSnippetLabel: "Save as snippet",
|
|
95
96
|
assistantMessageToolbarThumbsUpLabel: "Good response",
|
|
96
97
|
assistantMessageToolbarThumbsDownLabel: "Bad response",
|
|
97
98
|
assistantMessageToolbarReadAloudLabel: "Read aloud",
|
|
@@ -1670,7 +1671,8 @@ _radix_ui_react_dropdown_menu = __toESM(_radix_ui_react_dropdown_menu);
|
|
|
1670
1671
|
//#region src/v2/components/CopilotKitInspectorContext.tsx
|
|
1671
1672
|
const CopilotKitInspectorContext = react.createContext({
|
|
1672
1673
|
isLocalInspectorEnabled: false,
|
|
1673
|
-
openInspector: () => void 0
|
|
1674
|
+
openInspector: () => void 0,
|
|
1675
|
+
saveEventSnippet: async () => void 0
|
|
1674
1676
|
});
|
|
1675
1677
|
const CopilotKitInspectorContextProvider = CopilotKitInspectorContext.Provider;
|
|
1676
1678
|
function useCopilotKitInspector() {
|
|
@@ -2484,6 +2486,7 @@ window.parent.postMessage({jsonrpc:"2.0",method:"ui/notifications/sandbox-proxy-
|
|
|
2484
2486
|
const OpenGenerativeUIActivityRendererInner = react.default.memo(function OpenGenerativeUIActivityRendererInner({ content }) {
|
|
2485
2487
|
const initialHeight = content.initialHeight ?? 200;
|
|
2486
2488
|
const [autoHeight, setAutoHeight] = (0, react.useState)(null);
|
|
2489
|
+
const [sandboxReady, setSandboxReady] = (0, react.useState)(false);
|
|
2487
2490
|
const sandboxFunctions = useSandboxFunctions();
|
|
2488
2491
|
const localApi = (0, react.useMemo)(() => {
|
|
2489
2492
|
const api = {};
|
|
@@ -2585,6 +2588,7 @@ window.parent.postMessage({jsonrpc:"2.0",method:"ui/notifications/sandbox-proxy-
|
|
|
2585
2588
|
sandbox.promise.then(() => {
|
|
2586
2589
|
if (cancelled) return;
|
|
2587
2590
|
sandboxReadyRef.current = true;
|
|
2591
|
+
setSandboxReady(true);
|
|
2588
2592
|
sandbox.run(`
|
|
2589
2593
|
var s = document.createElement('style');
|
|
2590
2594
|
s.textContent = 'html, body { overflow: hidden !important; }';
|
|
@@ -2609,6 +2613,7 @@ window.parent.postMessage({jsonrpc:"2.0",method:"ui/notifications/sandbox-proxy-
|
|
|
2609
2613
|
sandboxRef.current = null;
|
|
2610
2614
|
}
|
|
2611
2615
|
sandboxReadyRef.current = false;
|
|
2616
|
+
setSandboxReady(false);
|
|
2612
2617
|
setAutoHeight(null);
|
|
2613
2618
|
};
|
|
2614
2619
|
}, [
|
|
@@ -2639,7 +2644,7 @@ window.parent.postMessage({jsonrpc:"2.0",method:"ui/notifications/sandbox-proxy-
|
|
|
2639
2644
|
const generationDone = content.generating === false;
|
|
2640
2645
|
(0, react.useEffect)(() => {
|
|
2641
2646
|
const sandbox = sandboxRef.current;
|
|
2642
|
-
if (!generationDone || !sandbox) return;
|
|
2647
|
+
if (!generationDone || !sandboxReady || !sandbox) return;
|
|
2643
2648
|
let handled = false;
|
|
2644
2649
|
const onMessage = (e) => {
|
|
2645
2650
|
if (handled) return;
|
|
@@ -2668,7 +2673,7 @@ window.parent.postMessage({jsonrpc:"2.0",method:"ui/notifications/sandbox-proxy-
|
|
|
2668
2673
|
return () => {
|
|
2669
2674
|
window.removeEventListener("message", onMessage);
|
|
2670
2675
|
};
|
|
2671
|
-
}, [generationDone]);
|
|
2676
|
+
}, [generationDone, sandboxReady]);
|
|
2672
2677
|
const height = autoHeight ?? initialHeight;
|
|
2673
2678
|
const isGenerating = content.generating !== false;
|
|
2674
2679
|
return /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
|
|
@@ -3556,10 +3561,46 @@ window.parent.postMessage({jsonrpc:"2.0",method:"ui/notifications/sandbox-proxy-
|
|
|
3556
3561
|
const requestInspectorOpen = (0, react.useCallback)((request) => {
|
|
3557
3562
|
setInspectorOpenRequest({ ...request });
|
|
3558
3563
|
}, []);
|
|
3564
|
+
const saveEventSnippet = (0, react.useCallback)(async (request) => {
|
|
3565
|
+
try {
|
|
3566
|
+
const mod = await import("@copilotkit/web-inspector");
|
|
3567
|
+
const threadId = request.threadId ?? "inspector-snippet";
|
|
3568
|
+
const runId = `inspector-snippet-${Date.now()}`;
|
|
3569
|
+
const compiled = mod.compileChatSnippet({
|
|
3570
|
+
...request,
|
|
3571
|
+
threadId,
|
|
3572
|
+
runId
|
|
3573
|
+
});
|
|
3574
|
+
const now = (/* @__PURE__ */ new Date()).toISOString();
|
|
3575
|
+
const snippet = {
|
|
3576
|
+
id: crypto.randomUUID(),
|
|
3577
|
+
name: compiled.name,
|
|
3578
|
+
recipe: compiled.recipe,
|
|
3579
|
+
events: compiled.events,
|
|
3580
|
+
createdAt: now,
|
|
3581
|
+
updatedAt: now
|
|
3582
|
+
};
|
|
3583
|
+
mod.upsertEventSnippet(snippet);
|
|
3584
|
+
requestInspectorOpen({
|
|
3585
|
+
messageId: request.messageId,
|
|
3586
|
+
threadId: request.threadId,
|
|
3587
|
+
agentId: request.agentId,
|
|
3588
|
+
menu: "event-snippets",
|
|
3589
|
+
snippetId: snippet.id
|
|
3590
|
+
});
|
|
3591
|
+
} catch (error) {
|
|
3592
|
+
console.error("[CopilotKit] Could not save the event snippet.", error);
|
|
3593
|
+
}
|
|
3594
|
+
}, [requestInspectorOpen]);
|
|
3559
3595
|
const inspectorContextValue = (0, react.useMemo)(() => ({
|
|
3560
3596
|
isLocalInspectorEnabled,
|
|
3561
|
-
openInspector: requestInspectorOpen
|
|
3562
|
-
|
|
3597
|
+
openInspector: requestInspectorOpen,
|
|
3598
|
+
saveEventSnippet
|
|
3599
|
+
}), [
|
|
3600
|
+
isLocalInspectorEnabled,
|
|
3601
|
+
requestInspectorOpen,
|
|
3602
|
+
saveEventSnippet
|
|
3603
|
+
]);
|
|
3563
3604
|
const renderToolCallsList = useStableArrayProp(renderToolCalls, "renderToolCalls must be a stable array. If you want to dynamically add or remove tools, use `useFrontendTool` instead.", (initial, next) => {
|
|
3564
3605
|
const key = (rc) => `${rc?.agentId ?? ""}:${rc?.name ?? ""}`;
|
|
3565
3606
|
const setFrom = (arr) => new Set(arr.map(key));
|
|
@@ -3614,7 +3655,7 @@ window.parent.postMessage({jsonrpc:"2.0",method:"ui/notifications/sandbox-proxy-
|
|
|
3614
3655
|
const hasLocalAgents = mergedAgents && Object.keys(mergedAgents).length > 0;
|
|
3615
3656
|
const hasSelfManagedAgents = Object.keys(selfManagedAgents).length > 0;
|
|
3616
3657
|
(0, react.useEffect)(() => {
|
|
3617
|
-
if (hasSelfManagedAgents && !resolvedPublicKey) console.warn("[CopilotKit] `selfManagedAgents` is part of CopilotKit's Enterprise Intelligence
|
|
3658
|
+
if (hasSelfManagedAgents && !resolvedPublicKey) console.warn("[CopilotKit] `selfManagedAgents` is part of CopilotKit's Enterprise Intelligence tier. Provide a `publicLicenseKey` for production use — contact the CopilotKit team about licensing.");
|
|
3618
3659
|
}, [hasSelfManagedAgents, resolvedPublicKey]);
|
|
3619
3660
|
const headers = typeof headersProp === "function" ? headersProp() : headersProp;
|
|
3620
3661
|
const mergedHeaders = (0, react.useMemo)(() => {
|
|
@@ -5211,10 +5252,10 @@ window.parent.postMessage({jsonrpc:"2.0",method:"ui/notifications/sandbox-proxy-
|
|
|
5211
5252
|
}, [store, selector]), () => selector(store.getState()), () => selector(store.getServerState()));
|
|
5212
5253
|
}
|
|
5213
5254
|
/**
|
|
5214
|
-
* React hook for listing and managing Intelligence
|
|
5255
|
+
* React hook for listing and managing CopilotKit Intelligence threads.
|
|
5215
5256
|
*
|
|
5216
5257
|
* On mount the hook fetches the thread list for the runtime-authenticated user
|
|
5217
|
-
* and the given `agentId`. When
|
|
5258
|
+
* and the given `agentId`. When CopilotKit Intelligence exposes a WebSocket
|
|
5218
5259
|
* URL, it also opens a realtime subscription so the `threads` array stays
|
|
5219
5260
|
* current without polling — thread creates, renames, archives, and deletes
|
|
5220
5261
|
* from any client are reflected immediately.
|
|
@@ -5510,7 +5551,7 @@ window.parent.postMessage({jsonrpc:"2.0",method:"ui/notifications/sandbox-proxy-
|
|
|
5510
5551
|
//#endregion
|
|
5511
5552
|
//#region src/v2/hooks/use-learn-from-user-action.tsx
|
|
5512
5553
|
/**
|
|
5513
|
-
* Record a user UI interaction in
|
|
5554
|
+
* Record a user UI interaction in CopilotKit Intelligence's user-actions
|
|
5514
5555
|
* stream. The platform's auto-curated knowledge base agent reads these
|
|
5515
5556
|
* (alongside finished agent runs) and writes free-form Obsidian-flavored
|
|
5516
5557
|
* markdown to `/project`, where any agent in the same project can later
|
|
@@ -5936,25 +5977,191 @@ window.parent.postMessage({jsonrpc:"2.0",method:"ui/notifications/sandbox-proxy-
|
|
|
5936
5977
|
});
|
|
5937
5978
|
}
|
|
5938
5979
|
|
|
5980
|
+
//#endregion
|
|
5981
|
+
//#region src/v2/components/chat/save-snippet-beside.ts
|
|
5982
|
+
const SAVE_SNIPPET_ICON_SLOT_PX = 36;
|
|
5983
|
+
const SAVE_SNIPPET_BESIDE_WRAP_CLASS = "cpk:relative cpk:w-full cpk:overflow-visible";
|
|
5984
|
+
const SAVE_SNIPPET_BESIDE_BODY_CLASS = "cpk:w-full";
|
|
5985
|
+
const SAVE_SNIPPET_BESIDE_SAVE_CLASS = "cpk:absolute cpk:top-0 cpk:z-10";
|
|
5986
|
+
function saveSnippetBesideStyle(side) {
|
|
5987
|
+
if (side === "left") return {
|
|
5988
|
+
left: "auto",
|
|
5989
|
+
right: "100%",
|
|
5990
|
+
marginLeft: 0,
|
|
5991
|
+
marginRight: 4
|
|
5992
|
+
};
|
|
5993
|
+
return {
|
|
5994
|
+
left: "100%",
|
|
5995
|
+
right: "auto",
|
|
5996
|
+
marginLeft: 4,
|
|
5997
|
+
marginRight: 0
|
|
5998
|
+
};
|
|
5999
|
+
}
|
|
6000
|
+
function pickSaveSnippetSide(roomRight, roomLeft, slotPx = SAVE_SNIPPET_ICON_SLOT_PX) {
|
|
6001
|
+
if (roomRight >= slotPx) return "right";
|
|
6002
|
+
if (roomLeft >= slotPx) return "left";
|
|
6003
|
+
return "right";
|
|
6004
|
+
}
|
|
6005
|
+
function findOverflowAncestor(el) {
|
|
6006
|
+
let node = el.parentElement;
|
|
6007
|
+
while (node) {
|
|
6008
|
+
const style = getComputedStyle(node);
|
|
6009
|
+
const overflowX = style.overflowX;
|
|
6010
|
+
const overflow = style.overflow;
|
|
6011
|
+
if (overflowX === "hidden" || overflowX === "auto" || overflowX === "scroll" || overflow === "hidden" || overflow === "auto" || overflow === "scroll") return node;
|
|
6012
|
+
node = node.parentElement;
|
|
6013
|
+
}
|
|
6014
|
+
return document.documentElement;
|
|
6015
|
+
}
|
|
6016
|
+
function measurableBox(el) {
|
|
6017
|
+
let node = el;
|
|
6018
|
+
while (node && getComputedStyle(node).display === "contents") node = node.firstElementChild;
|
|
6019
|
+
return node ?? el;
|
|
6020
|
+
}
|
|
6021
|
+
function measureSaveSnippetSide(wrap, body) {
|
|
6022
|
+
const clipRect = findOverflowAncestor(wrap).getBoundingClientRect();
|
|
6023
|
+
const bodyRect = measurableBox(body.firstElementChild ?? body).getBoundingClientRect();
|
|
6024
|
+
return pickSaveSnippetSide(clipRect.right - bodyRect.right, bodyRect.left - clipRect.left);
|
|
6025
|
+
}
|
|
6026
|
+
|
|
6027
|
+
//#endregion
|
|
6028
|
+
//#region src/v2/components/chat/SaveSnippetIconButton.tsx
|
|
6029
|
+
function SaveSnippetIconButton({ title, className, ...props }) {
|
|
6030
|
+
const labels = useCopilotChatConfiguration()?.labels ?? CopilotChatDefaultLabels;
|
|
6031
|
+
const primaryLabel = title || labels.assistantMessageToolbarSaveSnippetLabel;
|
|
6032
|
+
const localOnlyLabel = labels.assistantMessageToolbarInspectorLocalOnlyLabel;
|
|
6033
|
+
const accessibleLabel = `${primaryLabel} (${localOnlyLabel})`;
|
|
6034
|
+
return /* @__PURE__ */ (0, react_jsx_runtime.jsxs)(Tooltip, { children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)(TooltipTrigger, {
|
|
6035
|
+
asChild: true,
|
|
6036
|
+
children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(Button, {
|
|
6037
|
+
type: "button",
|
|
6038
|
+
variant: "assistantMessageToolbarButton",
|
|
6039
|
+
"aria-label": accessibleLabel,
|
|
6040
|
+
title: accessibleLabel,
|
|
6041
|
+
className,
|
|
6042
|
+
...props,
|
|
6043
|
+
children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(lucide_react.Bookmark, { className: "cpk:size-[18px]" })
|
|
6044
|
+
})
|
|
6045
|
+
}), /* @__PURE__ */ (0, react_jsx_runtime.jsx)(TooltipContent, {
|
|
6046
|
+
side: "bottom",
|
|
6047
|
+
children: /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
|
|
6048
|
+
className: "cpk:flex cpk:flex-col cpk:gap-0.5",
|
|
6049
|
+
children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", { children: primaryLabel }), /* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
|
|
6050
|
+
className: "cpk:text-[10px] cpk:opacity-65",
|
|
6051
|
+
children: localOnlyLabel
|
|
6052
|
+
})]
|
|
6053
|
+
})
|
|
6054
|
+
})] });
|
|
6055
|
+
}
|
|
6056
|
+
function SaveSnippetBesideChrome({ children, showSave, saveButton }) {
|
|
6057
|
+
const wrapRef = (0, react.useRef)(null);
|
|
6058
|
+
const bodyRef = (0, react.useRef)(null);
|
|
6059
|
+
const [side, setSide] = (0, react.useState)("right");
|
|
6060
|
+
(0, react.useLayoutEffect)(() => {
|
|
6061
|
+
if (!showSave) return;
|
|
6062
|
+
const wrap = wrapRef.current;
|
|
6063
|
+
const body = bodyRef.current;
|
|
6064
|
+
if (!wrap || !body) return;
|
|
6065
|
+
const measure = () => {
|
|
6066
|
+
setSide(measureSaveSnippetSide(wrap, body));
|
|
6067
|
+
};
|
|
6068
|
+
measure();
|
|
6069
|
+
if (typeof ResizeObserver === "undefined") return;
|
|
6070
|
+
const observer = new ResizeObserver(measure);
|
|
6071
|
+
observer.observe(wrap);
|
|
6072
|
+
observer.observe(body);
|
|
6073
|
+
const clip = findOverflowAncestor(wrap);
|
|
6074
|
+
if (clip !== wrap) observer.observe(clip);
|
|
6075
|
+
window.addEventListener("resize", measure);
|
|
6076
|
+
return () => {
|
|
6077
|
+
observer.disconnect();
|
|
6078
|
+
window.removeEventListener("resize", measure);
|
|
6079
|
+
};
|
|
6080
|
+
}, [showSave]);
|
|
6081
|
+
if (!showSave) return children;
|
|
6082
|
+
return /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
|
|
6083
|
+
ref: wrapRef,
|
|
6084
|
+
className: SAVE_SNIPPET_BESIDE_WRAP_CLASS,
|
|
6085
|
+
"data-save-snippet-side": side,
|
|
6086
|
+
children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
|
|
6087
|
+
ref: bodyRef,
|
|
6088
|
+
className: SAVE_SNIPPET_BESIDE_BODY_CLASS,
|
|
6089
|
+
children
|
|
6090
|
+
}), /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
|
|
6091
|
+
className: SAVE_SNIPPET_BESIDE_SAVE_CLASS,
|
|
6092
|
+
style: saveSnippetBesideStyle(side),
|
|
6093
|
+
children: saveButton
|
|
6094
|
+
})]
|
|
6095
|
+
});
|
|
6096
|
+
}
|
|
6097
|
+
|
|
5939
6098
|
//#endregion
|
|
5940
6099
|
//#region src/v2/components/chat/CopilotChatToolCallsView.tsx
|
|
5941
6100
|
function CopilotChatToolCallsView({ message, messages = [] }) {
|
|
5942
6101
|
const renderToolCall = useRenderToolCall();
|
|
6102
|
+
const { isLocalInspectorEnabled, saveEventSnippet } = useCopilotKitInspector();
|
|
6103
|
+
const chatConfiguration = useCopilotChatConfiguration();
|
|
6104
|
+
const labels = chatConfiguration?.labels ?? CopilotChatDefaultLabels;
|
|
5943
6105
|
if (!message.toolCalls || message.toolCalls.length === 0) return null;
|
|
5944
6106
|
return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(react_jsx_runtime.Fragment, { children: message.toolCalls.map((toolCall) => {
|
|
5945
|
-
const
|
|
5946
|
-
return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(react.default.Fragment, { children: renderToolCall({
|
|
6107
|
+
const rendered = renderToolCall({
|
|
5947
6108
|
toolCall,
|
|
5948
|
-
toolMessage
|
|
5949
|
-
})
|
|
6109
|
+
toolMessage: messages.find((m) => m.role === "tool" && m.toolCallId === toolCall.id)
|
|
6110
|
+
});
|
|
6111
|
+
if (!isLocalInspectorEnabled || !hasCompleteArgs(toolCall.function.arguments)) return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(react.default.Fragment, { children: rendered }, toolCall.id);
|
|
6112
|
+
const primaryLabel = labels.assistantMessageToolbarSaveSnippetLabel;
|
|
6113
|
+
return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(ToolCallSnippetChrome, {
|
|
6114
|
+
label: primaryLabel,
|
|
6115
|
+
onSave: () => void saveEventSnippet({
|
|
6116
|
+
kind: "tool-call",
|
|
6117
|
+
messageId: message.id,
|
|
6118
|
+
toolCallId: toolCall.id,
|
|
6119
|
+
toolName: toolCall.function.name,
|
|
6120
|
+
argsJson: toolCall.function.arguments || "{}",
|
|
6121
|
+
threadId: chatConfiguration?.threadId,
|
|
6122
|
+
agentId: chatConfiguration?.agentId
|
|
6123
|
+
}),
|
|
6124
|
+
children: rendered
|
|
6125
|
+
}, toolCall.id);
|
|
5950
6126
|
}) });
|
|
5951
6127
|
}
|
|
6128
|
+
function hasCompleteArgs(args) {
|
|
6129
|
+
const trimmed = (args ?? "").trim();
|
|
6130
|
+
if (!trimmed) return true;
|
|
6131
|
+
try {
|
|
6132
|
+
JSON.parse(trimmed);
|
|
6133
|
+
return true;
|
|
6134
|
+
} catch {
|
|
6135
|
+
return false;
|
|
6136
|
+
}
|
|
6137
|
+
}
|
|
6138
|
+
function ToolCallSnippetChrome({ children, label, onSave }) {
|
|
6139
|
+
const bodyRef = (0, react.useRef)(null);
|
|
6140
|
+
const [showSave, setShowSave] = (0, react.useState)(false);
|
|
6141
|
+
(0, react.useLayoutEffect)(() => {
|
|
6142
|
+
const el = bodyRef.current;
|
|
6143
|
+
setShowSave(!!el && el.childElementCount > 0);
|
|
6144
|
+
});
|
|
6145
|
+
return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(SaveSnippetBesideChrome, {
|
|
6146
|
+
showSave,
|
|
6147
|
+
saveButton: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(SaveSnippetIconButton, {
|
|
6148
|
+
"data-testid": "copilot-tool-save-snippet-button",
|
|
6149
|
+
title: label,
|
|
6150
|
+
onClick: onSave
|
|
6151
|
+
}),
|
|
6152
|
+
children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
|
|
6153
|
+
ref: bodyRef,
|
|
6154
|
+
className: "cpk:contents",
|
|
6155
|
+
children
|
|
6156
|
+
})
|
|
6157
|
+
});
|
|
6158
|
+
}
|
|
5952
6159
|
|
|
5953
6160
|
//#endregion
|
|
5954
6161
|
//#region src/v2/components/chat/CopilotChatAssistantMessage.tsx
|
|
5955
|
-
function CopilotChatAssistantMessage({ message, messages, isRunning, onThumbsUp, onThumbsDown, onReadAloud, onRegenerate, additionalToolbarItems, toolbarVisible = true, markdownRenderer, toolbar, copyButton, inspectorButton, thumbsUpButton, thumbsDownButton, readAloudButton, regenerateButton, toolCallsView, children, className, ...props }) {
|
|
6162
|
+
function CopilotChatAssistantMessage({ message, messages, isRunning, onThumbsUp, onThumbsDown, onReadAloud, onRegenerate, additionalToolbarItems, toolbarVisible = true, markdownRenderer, toolbar, copyButton, inspectorButton, saveSnippetButton, thumbsUpButton, thumbsDownButton, readAloudButton, regenerateButton, toolCallsView, children, className, ...props }) {
|
|
5956
6163
|
useKatexStyles();
|
|
5957
|
-
const { isLocalInspectorEnabled, openInspector } = useCopilotKitInspector();
|
|
6164
|
+
const { isLocalInspectorEnabled, openInspector, saveEventSnippet } = useCopilotKitInspector();
|
|
5958
6165
|
const chatConfiguration = useCopilotChatConfiguration();
|
|
5959
6166
|
const boundMarkdownRenderer = renderSlot(markdownRenderer, CopilotChatAssistantMessage.MarkdownRenderer, { content: message.content || "" });
|
|
5960
6167
|
const boundCopyButton = renderSlot(copyButton, CopilotChatAssistantMessage.CopyButton, { onClick: async () => {
|
|
@@ -5967,6 +6174,17 @@ window.parent.postMessage({jsonrpc:"2.0",method:"ui/notifications/sandbox-proxy-
|
|
|
5967
6174
|
threadId: chatConfiguration?.threadId,
|
|
5968
6175
|
agentId: chatConfiguration?.agentId
|
|
5969
6176
|
}) });
|
|
6177
|
+
const hasContent = !!(message.content && message.content.trim().length > 0);
|
|
6178
|
+
const boundSaveSnippetButton = renderSlot(saveSnippetButton, CopilotChatAssistantMessage.SaveSnippetButton, { onClick: () => {
|
|
6179
|
+
if (!hasContent) return;
|
|
6180
|
+
saveEventSnippet({
|
|
6181
|
+
kind: "text",
|
|
6182
|
+
messageId: message.id,
|
|
6183
|
+
content: message.content ?? "",
|
|
6184
|
+
threadId: chatConfiguration?.threadId,
|
|
6185
|
+
agentId: chatConfiguration?.agentId
|
|
6186
|
+
});
|
|
6187
|
+
} });
|
|
5970
6188
|
const boundThumbsDownButton = renderSlot(thumbsDownButton, CopilotChatAssistantMessage.ThumbsDownButton, { onClick: onThumbsDown ? () => onThumbsDown(message) : void 0 });
|
|
5971
6189
|
const boundReadAloudButton = renderSlot(readAloudButton, CopilotChatAssistantMessage.ReadAloudButton, { onClick: onReadAloud ? () => onReadAloud(message) : void 0 });
|
|
5972
6190
|
const boundRegenerateButton = renderSlot(regenerateButton, CopilotChatAssistantMessage.RegenerateButton, { onClick: onRegenerate ? () => onRegenerate(message) : void 0 });
|
|
@@ -5975,6 +6193,7 @@ window.parent.postMessage({jsonrpc:"2.0",method:"ui/notifications/sandbox-proxy-
|
|
|
5975
6193
|
children: [
|
|
5976
6194
|
boundCopyButton,
|
|
5977
6195
|
isLocalInspectorEnabled && boundInspectorButton,
|
|
6196
|
+
isLocalInspectorEnabled && hasContent && boundSaveSnippetButton,
|
|
5978
6197
|
(onThumbsUp || thumbsUpButton) && boundThumbsUpButton,
|
|
5979
6198
|
(onThumbsDown || thumbsDownButton) && boundThumbsDownButton,
|
|
5980
6199
|
(onReadAloud || readAloudButton) && boundReadAloudButton,
|
|
@@ -5986,9 +6205,8 @@ window.parent.postMessage({jsonrpc:"2.0",method:"ui/notifications/sandbox-proxy-
|
|
|
5986
6205
|
message,
|
|
5987
6206
|
messages
|
|
5988
6207
|
});
|
|
5989
|
-
const hasContent = !!(message.content && message.content.trim().length > 0);
|
|
5990
6208
|
const isLatestAssistantMessage = message.role === "assistant" && messages?.[messages.length - 1]?.id === message.id;
|
|
5991
|
-
const shouldShowToolbar = toolbarVisible && hasContent && !(isRunning && isLatestAssistantMessage);
|
|
6209
|
+
const shouldShowToolbar = toolbarVisible && (hasContent || isLocalInspectorEnabled) && !(isRunning && isLatestAssistantMessage);
|
|
5992
6210
|
if (children) return /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
|
|
5993
6211
|
"data-copilotkit": true,
|
|
5994
6212
|
style: { display: "contents" },
|
|
@@ -5998,6 +6216,7 @@ window.parent.postMessage({jsonrpc:"2.0",method:"ui/notifications/sandbox-proxy-
|
|
|
5998
6216
|
toolCallsView: boundToolCallsView,
|
|
5999
6217
|
copyButton: boundCopyButton,
|
|
6000
6218
|
inspectorButton: boundInspectorButton,
|
|
6219
|
+
saveSnippetButton: boundSaveSnippetButton,
|
|
6001
6220
|
thumbsUpButton: boundThumbsUpButton,
|
|
6002
6221
|
thumbsDownButton: boundThumbsDownButton,
|
|
6003
6222
|
readAloudButton: boundReadAloudButton,
|
|
@@ -6208,6 +6427,10 @@ window.parent.postMessage({jsonrpc:"2.0",method:"ui/notifications/sandbox-proxy-
|
|
|
6208
6427
|
children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(CopilotKitColoredIcon, {})
|
|
6209
6428
|
});
|
|
6210
6429
|
};
|
|
6430
|
+
_CopilotChatAssistantMessage.SaveSnippetButton = (props) => /* @__PURE__ */ (0, react_jsx_runtime.jsx)(SaveSnippetIconButton, {
|
|
6431
|
+
"data-testid": "copilot-save-snippet-button",
|
|
6432
|
+
...props
|
|
6433
|
+
});
|
|
6211
6434
|
_CopilotChatAssistantMessage.ThumbsUpButton = ({ title, ...props }) => {
|
|
6212
6435
|
const labels = useCopilotChatConfiguration()?.labels ?? CopilotChatDefaultLabels;
|
|
6213
6436
|
return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(ToolbarButton, {
|
|
@@ -6249,6 +6472,7 @@ window.parent.postMessage({jsonrpc:"2.0",method:"ui/notifications/sandbox-proxy-
|
|
|
6249
6472
|
CopilotChatAssistantMessage.Toolbar.displayName = "CopilotChatAssistantMessage.Toolbar";
|
|
6250
6473
|
CopilotChatAssistantMessage.CopyButton.displayName = "CopilotChatAssistantMessage.CopyButton";
|
|
6251
6474
|
CopilotChatAssistantMessage.InspectorButton.displayName = "CopilotChatAssistantMessage.InspectorButton";
|
|
6475
|
+
CopilotChatAssistantMessage.SaveSnippetButton.displayName = "CopilotChatAssistantMessage.SaveSnippetButton";
|
|
6252
6476
|
CopilotChatAssistantMessage.ThumbsUpButton.displayName = "CopilotChatAssistantMessage.ThumbsUpButton";
|
|
6253
6477
|
CopilotChatAssistantMessage.ThumbsDownButton.displayName = "CopilotChatAssistantMessage.ThumbsDownButton";
|
|
6254
6478
|
CopilotChatAssistantMessage.ReadAloudButton.displayName = "CopilotChatAssistantMessage.ReadAloudButton";
|
|
@@ -6619,6 +6843,8 @@ window.parent.postMessage({jsonrpc:"2.0",method:"ui/notifications/sandbox-proxy-
|
|
|
6619
6843
|
const isLatest = messages?.[messages.length - 1]?.id === message.id;
|
|
6620
6844
|
const isStreaming = !!(isRunning && isLatest);
|
|
6621
6845
|
const hasContent = !!(message.content && message.content.length > 0);
|
|
6846
|
+
const { isLocalInspectorEnabled, saveEventSnippet } = useCopilotKitInspector();
|
|
6847
|
+
const chatConfiguration = useCopilotChatConfiguration();
|
|
6622
6848
|
const startTimeRef = (0, react.useRef)(null);
|
|
6623
6849
|
const [elapsed, setElapsed] = (0, react.useState)(0);
|
|
6624
6850
|
(0, react.useEffect)(() => {
|
|
@@ -6678,7 +6904,16 @@ window.parent.postMessage({jsonrpc:"2.0",method:"ui/notifications/sandbox-proxy-
|
|
|
6678
6904
|
className: (0, tailwind_merge.twMerge)("cpk:my-1", className),
|
|
6679
6905
|
"data-message-id": message.id,
|
|
6680
6906
|
...props,
|
|
6681
|
-
children: [
|
|
6907
|
+
children: [/* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
|
|
6908
|
+
className: "cpk:flex cpk:items-center cpk:gap-1",
|
|
6909
|
+
children: [boundHeader, isLocalInspectorEnabled && hasContent && /* @__PURE__ */ (0, react_jsx_runtime.jsx)(CopilotChatAssistantMessage_default.SaveSnippetButton, { onClick: () => void saveEventSnippet({
|
|
6910
|
+
kind: "reasoning",
|
|
6911
|
+
messageId: message.id,
|
|
6912
|
+
content: message.content ?? "",
|
|
6913
|
+
threadId: chatConfiguration?.threadId,
|
|
6914
|
+
agentId: chatConfiguration?.agentId
|
|
6915
|
+
}) })]
|
|
6916
|
+
}), boundToggle]
|
|
6682
6917
|
});
|
|
6683
6918
|
}
|
|
6684
6919
|
(function(_CopilotChatReasoningMessage) {
|
|
@@ -7197,8 +7432,33 @@ window.parent.postMessage({jsonrpc:"2.0",method:"ui/notifications/sandbox-proxy-
|
|
|
7197
7432
|
/**
|
|
7198
7433
|
* Memoized wrapper for activity messages to prevent re-renders when other messages change.
|
|
7199
7434
|
*/
|
|
7435
|
+
function ActivitySnippetChrome({ message, children }) {
|
|
7436
|
+
const { isLocalInspectorEnabled, saveEventSnippet } = useCopilotKitInspector();
|
|
7437
|
+
const chatConfiguration = useCopilotChatConfiguration();
|
|
7438
|
+
if (!(isLocalInspectorEnabled && (message.activityType === "a2ui-surface" || message.activityType === "open-generative-ui"))) return children;
|
|
7439
|
+
const primaryLabel = (chatConfiguration?.labels ?? CopilotChatDefaultLabels).assistantMessageToolbarSaveSnippetLabel;
|
|
7440
|
+
return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(SaveSnippetBesideChrome, {
|
|
7441
|
+
showSave: true,
|
|
7442
|
+
saveButton: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(SaveSnippetIconButton, {
|
|
7443
|
+
"data-testid": "copilot-activity-save-snippet-button",
|
|
7444
|
+
title: primaryLabel,
|
|
7445
|
+
onClick: () => void saveEventSnippet({
|
|
7446
|
+
kind: "activity",
|
|
7447
|
+
messageId: message.id,
|
|
7448
|
+
activityType: message.activityType,
|
|
7449
|
+
content: message.content,
|
|
7450
|
+
threadId: chatConfiguration?.threadId,
|
|
7451
|
+
agentId: chatConfiguration?.agentId
|
|
7452
|
+
})
|
|
7453
|
+
}),
|
|
7454
|
+
children
|
|
7455
|
+
});
|
|
7456
|
+
}
|
|
7200
7457
|
const MemoizedActivityMessage = react.default.memo(function MemoizedActivityMessage({ message, renderActivityMessage }) {
|
|
7201
|
-
return
|
|
7458
|
+
return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(ActivitySnippetChrome, {
|
|
7459
|
+
message,
|
|
7460
|
+
children: renderActivityMessage(message)
|
|
7461
|
+
});
|
|
7202
7462
|
}, (prevProps, nextProps) => {
|
|
7203
7463
|
if (prevProps.message.id !== nextProps.message.id) return false;
|
|
7204
7464
|
if (prevProps.message.activityType !== nextProps.message.activityType) return false;
|
|
@@ -7339,6 +7599,30 @@ window.parent.postMessage({jsonrpc:"2.0",method:"ui/notifications/sandbox-proxy-
|
|
|
7339
7599
|
const deduplicatedMessages = (0, react.useMemo)(() => deduplicateMessages(messages), [messages]);
|
|
7340
7600
|
if (process.env.NODE_ENV === "development" && deduplicatedMessages.length < messages.length) console.warn(`CopilotChatMessageView: Merged ${messages.length - deduplicatedMessages.length} message(s) with duplicate IDs.`);
|
|
7341
7601
|
const { Component: AssistantComponent, slotProps: assistantSlotProps } = (0, react.useMemo)(() => resolveSlotComponent(assistantMessage, CopilotChatAssistantMessage_default), [assistantMessage]);
|
|
7602
|
+
const agentId = config?.agentId;
|
|
7603
|
+
const threadId = config?.threadId;
|
|
7604
|
+
const assistantSlotPropsWithFeedback = (0, react.useMemo)(() => {
|
|
7605
|
+
const onThumbsUp = assistantSlotProps?.onThumbsUp;
|
|
7606
|
+
const onThumbsDown = assistantSlotProps?.onThumbsDown;
|
|
7607
|
+
if (!onThumbsUp && !onThumbsDown) return assistantSlotProps;
|
|
7608
|
+
const withRawEvent = (message) => {
|
|
7609
|
+
const rawEvent = agentId === void 0 || threadId === void 0 ? void 0 : copilotkit.getRawEventForMessage(agentId, threadId, message.id);
|
|
7610
|
+
return rawEvent === void 0 ? message : {
|
|
7611
|
+
...message,
|
|
7612
|
+
rawEvent
|
|
7613
|
+
};
|
|
7614
|
+
};
|
|
7615
|
+
return {
|
|
7616
|
+
...assistantSlotProps,
|
|
7617
|
+
...onThumbsUp && { onThumbsUp: (message) => onThumbsUp(withRawEvent(message)) },
|
|
7618
|
+
...onThumbsDown && { onThumbsDown: (message) => onThumbsDown(withRawEvent(message)) }
|
|
7619
|
+
};
|
|
7620
|
+
}, [
|
|
7621
|
+
assistantSlotProps,
|
|
7622
|
+
agentId,
|
|
7623
|
+
threadId,
|
|
7624
|
+
copilotkit
|
|
7625
|
+
]);
|
|
7342
7626
|
const { Component: UserComponent, slotProps: userSlotProps } = (0, react.useMemo)(() => resolveSlotComponent(userMessage, CopilotChatUserMessage_default), [userMessage]);
|
|
7343
7627
|
const { Component: ReasoningComponent, slotProps: reasoningSlotProps } = (0, react.useMemo)(() => resolveSlotComponent(reasoningMessage, CopilotChatReasoningMessage_default), [reasoningMessage]);
|
|
7344
7628
|
const scrollElementFromCtx = (0, react.useContext)(ScrollElementContext);
|
|
@@ -7378,7 +7662,7 @@ window.parent.postMessage({jsonrpc:"2.0",method:"ui/notifications/sandbox-proxy-
|
|
|
7378
7662
|
messages,
|
|
7379
7663
|
isRunning,
|
|
7380
7664
|
AssistantMessageComponent: AssistantComponent,
|
|
7381
|
-
slotProps:
|
|
7665
|
+
slotProps: assistantSlotPropsWithFeedback
|
|
7382
7666
|
}, message.id));
|
|
7383
7667
|
else if (message.role === "user") elements.push(/* @__PURE__ */ (0, react_jsx_runtime.jsx)(MemoizedUserMessage, {
|
|
7384
7668
|
message,
|
|
@@ -8342,14 +8626,109 @@ window.parent.postMessage({jsonrpc:"2.0",method:"ui/notifications/sandbox-proxy-
|
|
|
8342
8626
|
return await response.json();
|
|
8343
8627
|
}
|
|
8344
8628
|
|
|
8629
|
+
//#endregion
|
|
8630
|
+
//#region src/v2/providers/use-inspector-thread-override.ts
|
|
8631
|
+
function useInspectorThreadOverride(args) {
|
|
8632
|
+
const [override, setOverride] = (0, react.useState)(null);
|
|
8633
|
+
const latestRef = (0, react.useRef)({
|
|
8634
|
+
...args,
|
|
8635
|
+
override
|
|
8636
|
+
});
|
|
8637
|
+
latestRef.current = {
|
|
8638
|
+
...args,
|
|
8639
|
+
override
|
|
8640
|
+
};
|
|
8641
|
+
const restoreOverride = (0, react.useCallback)((current, nextThreadId) => {
|
|
8642
|
+
setOverride(null);
|
|
8643
|
+
(0, _copilotkit_core.emitInspectorActiveThread)({
|
|
8644
|
+
requestId: current.requestId,
|
|
8645
|
+
threadId: nextThreadId,
|
|
8646
|
+
agentId: current.agentId,
|
|
8647
|
+
source: "app"
|
|
8648
|
+
});
|
|
8649
|
+
}, []);
|
|
8650
|
+
const failInspectorOverride = (0, react.useCallback)((requestId) => {
|
|
8651
|
+
const current = latestRef.current.override;
|
|
8652
|
+
if (!current || current.requestId !== requestId) return;
|
|
8653
|
+
(0, _copilotkit_core.emitInspectorViewThreadResult)({
|
|
8654
|
+
requestId,
|
|
8655
|
+
threadId: current.threadId,
|
|
8656
|
+
agentId: current.agentId,
|
|
8657
|
+
ok: false,
|
|
8658
|
+
reason: "connect-failed"
|
|
8659
|
+
});
|
|
8660
|
+
restoreOverride(current, current.previousThreadId);
|
|
8661
|
+
}, [restoreOverride]);
|
|
8662
|
+
(0, react.useEffect)(() => {
|
|
8663
|
+
if (!(0, _copilotkit_core.isInspectorThreadBridgeEnabled)()) return;
|
|
8664
|
+
const offView = (0, _copilotkit_core.onInspectorViewThread)((payload) => {
|
|
8665
|
+
const current = latestRef.current;
|
|
8666
|
+
if (payload.agentId !== current.agentId) return false;
|
|
8667
|
+
setOverride(current.override ? {
|
|
8668
|
+
...current.override,
|
|
8669
|
+
...payload
|
|
8670
|
+
} : {
|
|
8671
|
+
...payload,
|
|
8672
|
+
previousThreadId: current.baseThreadId
|
|
8673
|
+
});
|
|
8674
|
+
(0, _copilotkit_core.emitInspectorViewThreadResult)({
|
|
8675
|
+
...payload,
|
|
8676
|
+
ok: true
|
|
8677
|
+
});
|
|
8678
|
+
(0, _copilotkit_core.emitInspectorActiveThread)({
|
|
8679
|
+
...payload,
|
|
8680
|
+
source: "override"
|
|
8681
|
+
});
|
|
8682
|
+
return true;
|
|
8683
|
+
});
|
|
8684
|
+
const offStop = (0, _copilotkit_core.onInspectorStopViewing)((payload) => {
|
|
8685
|
+
const current = latestRef.current.override;
|
|
8686
|
+
if (!current) return;
|
|
8687
|
+
if (payload.requestId !== current.requestId) return;
|
|
8688
|
+
if (payload.agentId !== current.agentId) return;
|
|
8689
|
+
restoreOverride(current, current.previousThreadId);
|
|
8690
|
+
});
|
|
8691
|
+
return () => {
|
|
8692
|
+
offView();
|
|
8693
|
+
offStop();
|
|
8694
|
+
};
|
|
8695
|
+
}, [restoreOverride]);
|
|
8696
|
+
(0, react.useEffect)(() => {
|
|
8697
|
+
if (!override) return;
|
|
8698
|
+
if (args.agentId !== override.agentId) {
|
|
8699
|
+
restoreOverride(override, override.previousThreadId);
|
|
8700
|
+
return;
|
|
8701
|
+
}
|
|
8702
|
+
if (args.baseThreadId === override.previousThreadId) return;
|
|
8703
|
+
if (args.baseThreadId === override.threadId) return;
|
|
8704
|
+
restoreOverride(override, args.baseThreadId);
|
|
8705
|
+
}, [
|
|
8706
|
+
args.agentId,
|
|
8707
|
+
args.baseThreadId,
|
|
8708
|
+
override,
|
|
8709
|
+
restoreOverride
|
|
8710
|
+
]);
|
|
8711
|
+
return {
|
|
8712
|
+
inspectorThreadId: override?.threadId ?? null,
|
|
8713
|
+
inspectorRequestId: override?.requestId ?? null,
|
|
8714
|
+
failInspectorOverride
|
|
8715
|
+
};
|
|
8716
|
+
}
|
|
8717
|
+
|
|
8345
8718
|
//#endregion
|
|
8346
8719
|
//#region src/v2/components/chat/CopilotChat.tsx
|
|
8347
8720
|
function CopilotChat({ agentId, threadId, labels, chatView, isModalDefaultOpen, attachments: attachmentsConfig, onError, throttleMs, ...props }) {
|
|
8348
8721
|
const existingConfig = useCopilotChatConfiguration();
|
|
8349
8722
|
const resolvedAgentId = agentId ?? existingConfig?.agentId ?? _copilotkit_shared.DEFAULT_AGENT_ID;
|
|
8350
8723
|
const providedThreadId = threadId ?? existingConfig?.threadId;
|
|
8351
|
-
const
|
|
8352
|
-
const
|
|
8724
|
+
const baseThreadId = (0, react.useMemo)(() => providedThreadId ?? (0, _copilotkit_shared.randomUUID)(), [providedThreadId]);
|
|
8725
|
+
const baseHasExplicitThreadId = !!threadId || !!existingConfig?.hasExplicitThreadId;
|
|
8726
|
+
const { inspectorThreadId, inspectorRequestId, failInspectorOverride } = useInspectorThreadOverride({
|
|
8727
|
+
agentId: resolvedAgentId,
|
|
8728
|
+
baseThreadId
|
|
8729
|
+
});
|
|
8730
|
+
const resolvedThreadId = inspectorThreadId ?? baseThreadId;
|
|
8731
|
+
const hasExplicitThreadId = inspectorThreadId !== null || baseHasExplicitThreadId;
|
|
8353
8732
|
const { agent, isReady } = useAgent({
|
|
8354
8733
|
agentId: resolvedAgentId,
|
|
8355
8734
|
throttleMs
|
|
@@ -8378,6 +8757,24 @@ window.parent.postMessage({jsonrpc:"2.0",method:"ui/notifications/sandbox-proxy-
|
|
|
8378
8757
|
subscription.unsubscribe();
|
|
8379
8758
|
};
|
|
8380
8759
|
}, [copilotkit, resolvedAgentId]);
|
|
8760
|
+
(0, react.useEffect)(() => {
|
|
8761
|
+
if (!inspectorRequestId) return;
|
|
8762
|
+
const requestId = inspectorRequestId;
|
|
8763
|
+
const expectedThreadId = resolvedThreadId;
|
|
8764
|
+
const subscription = copilotkit.subscribe({ onError: (event) => {
|
|
8765
|
+
if (event.code !== _copilotkit_core.CopilotKitCoreErrorCode.AGENT_CONNECT_FAILED) return;
|
|
8766
|
+
if (event.context?.agentId !== resolvedAgentId) return;
|
|
8767
|
+
if (event.context?.threadId !== expectedThreadId) return;
|
|
8768
|
+
failInspectorOverride(requestId);
|
|
8769
|
+
} });
|
|
8770
|
+
return () => subscription.unsubscribe();
|
|
8771
|
+
}, [
|
|
8772
|
+
copilotkit,
|
|
8773
|
+
failInspectorOverride,
|
|
8774
|
+
inspectorRequestId,
|
|
8775
|
+
resolvedAgentId,
|
|
8776
|
+
resolvedThreadId
|
|
8777
|
+
]);
|
|
8381
8778
|
const [transcribeMode, setTranscribeMode] = (0, react.useState)("input");
|
|
8382
8779
|
const [inputValue, setInputValue] = (0, react.useState)("");
|
|
8383
8780
|
const [transcriptionError, setTranscriptionError] = (0, react.useState)(null);
|
|
@@ -8404,7 +8801,7 @@ window.parent.postMessage({jsonrpc:"2.0",method:"ui/notifications/sandbox-proxy-
|
|
|
8404
8801
|
const runtimeStatus = copilotkit.runtimeConnectionStatus === _copilotkit_core.CopilotKitCoreRuntimeConnectionStatus.Connected ? "Connected" : copilotkit.runtimeConnectionStatus;
|
|
8405
8802
|
const hasNativeIntelligenceRunActivity = hasExplicitThreadId && runtimeStatus === "Connected" && !!copilotkit.intelligence?.wsUrl && copilotkit.threadEndpoints?.realtimeMetadata === true;
|
|
8406
8803
|
const [standaloneRunActivityStore] = (0, react.useState)(() => (0, _copilotkit_core.ɵcreateThreadStore)({ fetch: globalThis.fetch }));
|
|
8407
|
-
const
|
|
8804
|
+
const previousThreadRef = (0, react.useRef)(null);
|
|
8408
8805
|
const hasExplicitThreadIdRef = (0, react.useRef)(hasExplicitThreadId);
|
|
8409
8806
|
hasExplicitThreadIdRef.current = hasExplicitThreadId;
|
|
8410
8807
|
const rememberRecentlyLocalRunId = (0, react.useCallback)((runId) => {
|
|
@@ -8444,8 +8841,15 @@ window.parent.postMessage({jsonrpc:"2.0",method:"ui/notifications/sandbox-proxy-
|
|
|
8444
8841
|
};
|
|
8445
8842
|
}, []);
|
|
8446
8843
|
(0, react.useEffect)(() => {
|
|
8447
|
-
const
|
|
8448
|
-
|
|
8844
|
+
const previousThread = previousThreadRef.current;
|
|
8845
|
+
const threadChanged = previousThread?.threadId !== resolvedThreadId;
|
|
8846
|
+
const inspectorTransition = threadChanged && previousThread !== null && previousThread.inspectorRequestId !== inspectorRequestId && (previousThread.inspectorRequestId !== null || inspectorRequestId !== null);
|
|
8847
|
+
previousThreadRef.current = {
|
|
8848
|
+
threadId: resolvedThreadId,
|
|
8849
|
+
inspectorRequestId
|
|
8850
|
+
};
|
|
8851
|
+
if (inspectorTransition) if (typeof copilotkit.stopAgent === "function") copilotkit.stopAgent({ agent });
|
|
8852
|
+
else agent.abortRun?.();
|
|
8449
8853
|
agent.threadId = resolvedThreadId;
|
|
8450
8854
|
if (!hasExplicitThreadId) {
|
|
8451
8855
|
if (threadChanged && agent.messages.length > 0) agent.setMessages([]);
|
|
@@ -8461,6 +8865,7 @@ window.parent.postMessage({jsonrpc:"2.0",method:"ui/notifications/sandbox-proxy-
|
|
|
8461
8865
|
} catch (error) {
|
|
8462
8866
|
if (detached) return;
|
|
8463
8867
|
console.error("CopilotChat: connectAgent failed", error);
|
|
8868
|
+
if (inspectorRequestId) failInspectorOverride(inspectorRequestId);
|
|
8464
8869
|
} finally {
|
|
8465
8870
|
if (!detached) (typeof requestAnimationFrame === "function" ? requestAnimationFrame : (cb) => setTimeout(cb, 16))(() => {
|
|
8466
8871
|
if (!detached) setLastConnectedThreadId(resolvedThreadId);
|
|
@@ -8486,7 +8891,9 @@ window.parent.postMessage({jsonrpc:"2.0",method:"ui/notifications/sandbox-proxy-
|
|
|
8486
8891
|
resolvedThreadId,
|
|
8487
8892
|
agent,
|
|
8488
8893
|
resolvedAgentId,
|
|
8489
|
-
hasExplicitThreadId
|
|
8894
|
+
hasExplicitThreadId,
|
|
8895
|
+
inspectorRequestId,
|
|
8896
|
+
failInspectorOverride
|
|
8490
8897
|
]);
|
|
8491
8898
|
(0, react.useEffect)(() => {
|
|
8492
8899
|
if (!hasNativeIntelligenceRunActivity) return;
|
|
@@ -9843,7 +10250,7 @@ window.parent.postMessage({jsonrpc:"2.0",method:"ui/notifications/sandbox-proxy-
|
|
|
9843
10250
|
});
|
|
9844
10251
|
|
|
9845
10252
|
//#endregion
|
|
9846
|
-
//#region src/context/copilot-context.tsx
|
|
10253
|
+
//#region src/v1-deprecated/context/copilot-context.tsx
|
|
9847
10254
|
const emptyCopilotContext$1 = {
|
|
9848
10255
|
actions: {},
|
|
9849
10256
|
setAction: () => {},
|
|
@@ -9923,7 +10330,7 @@ window.parent.postMessage({jsonrpc:"2.0",method:"ui/notifications/sandbox-proxy-
|
|
|
9923
10330
|
}
|
|
9924
10331
|
|
|
9925
10332
|
//#endregion
|
|
9926
|
-
//#region src/hooks/use-tree.ts
|
|
10333
|
+
//#region src/v1-deprecated/hooks/use-tree.ts
|
|
9927
10334
|
const removeNode = (nodes, id) => {
|
|
9928
10335
|
return nodes.reduce((result, node) => {
|
|
9929
10336
|
if (node.id !== id) {
|
|
@@ -10036,7 +10443,7 @@ window.parent.postMessage({jsonrpc:"2.0",method:"ui/notifications/sandbox-proxy-
|
|
|
10036
10443
|
}
|
|
10037
10444
|
|
|
10038
10445
|
//#endregion
|
|
10039
|
-
//#region src/hooks/use-flat-category-store.ts
|
|
10446
|
+
//#region src/v1-deprecated/hooks/use-flat-category-store.ts
|
|
10040
10447
|
const useFlatCategoryStore = () => {
|
|
10041
10448
|
const [elements, dispatch] = (0, react.useReducer)(flatCategoryStoreReducer, /* @__PURE__ */ new Map());
|
|
10042
10449
|
return {
|
|
@@ -10094,7 +10501,7 @@ window.parent.postMessage({jsonrpc:"2.0",method:"ui/notifications/sandbox-proxy-
|
|
|
10094
10501
|
}
|
|
10095
10502
|
|
|
10096
10503
|
//#endregion
|
|
10097
|
-
//#region src/context/copilot-messages-context.tsx
|
|
10504
|
+
//#region src/v1-deprecated/context/copilot-messages-context.tsx
|
|
10098
10505
|
const emptyCopilotContext = {
|
|
10099
10506
|
messages: [],
|
|
10100
10507
|
setMessages: () => [],
|
|
@@ -10104,7 +10511,7 @@ window.parent.postMessage({jsonrpc:"2.0",method:"ui/notifications/sandbox-proxy-
|
|
|
10104
10511
|
const CopilotMessagesContext = react.default.createContext(emptyCopilotContext);
|
|
10105
10512
|
|
|
10106
10513
|
//#endregion
|
|
10107
|
-
//#region src/components/toast/toast-provider.tsx
|
|
10514
|
+
//#region src/v1-deprecated/components/toast/toast-provider.tsx
|
|
10108
10515
|
const ToastContext = (0, react.createContext)(void 0);
|
|
10109
10516
|
function getErrorSeverity(error) {
|
|
10110
10517
|
if (error.severity) switch (error.severity) {
|
|
@@ -10411,7 +10818,7 @@ window.parent.postMessage({jsonrpc:"2.0",method:"ui/notifications/sandbox-proxy-
|
|
|
10411
10818
|
}
|
|
10412
10819
|
|
|
10413
10820
|
//#endregion
|
|
10414
|
-
//#region src/utils/dev-console.ts
|
|
10821
|
+
//#region src/v1-deprecated/utils/dev-console.ts
|
|
10415
10822
|
function isLocalhost() {
|
|
10416
10823
|
if (typeof window === "undefined") return false;
|
|
10417
10824
|
return window.location.hostname === "localhost" || window.location.hostname === "127.0.0.1" || window.location.hostname === "0.0.0.0";
|
|
@@ -10422,7 +10829,7 @@ window.parent.postMessage({jsonrpc:"2.0",method:"ui/notifications/sandbox-proxy-
|
|
|
10422
10829
|
}
|
|
10423
10830
|
|
|
10424
10831
|
//#endregion
|
|
10425
|
-
//#region src/components/copilot-provider/copilot-messages.tsx
|
|
10832
|
+
//#region src/v1-deprecated/components/copilot-provider/copilot-messages.tsx
|
|
10426
10833
|
/**
|
|
10427
10834
|
* An internal context to separate the messages state (which is constantly changing) from the rest of CopilotKit context
|
|
10428
10835
|
*/
|
|
@@ -10572,7 +10979,7 @@ window.parent.postMessage({jsonrpc:"2.0",method:"ui/notifications/sandbox-proxy-
|
|
|
10572
10979
|
}
|
|
10573
10980
|
|
|
10574
10981
|
//#endregion
|
|
10575
|
-
//#region src/components/usage-banner.tsx
|
|
10982
|
+
//#region src/v1-deprecated/components/usage-banner.tsx
|
|
10576
10983
|
function UsageBanner({ severity = _copilotkit_shared.Severity.CRITICAL, message = "", onClose, actions }) {
|
|
10577
10984
|
if (!message || !severity) return null;
|
|
10578
10985
|
const theme = {
|
|
@@ -10769,7 +11176,7 @@ window.parent.postMessage({jsonrpc:"2.0",method:"ui/notifications/sandbox-proxy-
|
|
|
10769
11176
|
};
|
|
10770
11177
|
|
|
10771
11178
|
//#endregion
|
|
10772
|
-
//#region src/lib/status-checker.ts
|
|
11179
|
+
//#region src/v1-deprecated/lib/status-checker.ts
|
|
10773
11180
|
const STATUS_CHECK_INTERVAL = 1e3 * 60 * 5;
|
|
10774
11181
|
var StatusChecker = class {
|
|
10775
11182
|
constructor() {
|
|
@@ -10791,7 +11198,7 @@ window.parent.postMessage({jsonrpc:"2.0",method:"ui/notifications/sandbox-proxy-
|
|
|
10791
11198
|
this.lastResponse = response;
|
|
10792
11199
|
onUpdate?.(response);
|
|
10793
11200
|
return response;
|
|
10794
|
-
} catch
|
|
11201
|
+
} catch {
|
|
10795
11202
|
return null;
|
|
10796
11203
|
}
|
|
10797
11204
|
};
|
|
@@ -10817,7 +11224,7 @@ window.parent.postMessage({jsonrpc:"2.0",method:"ui/notifications/sandbox-proxy-
|
|
|
10817
11224
|
};
|
|
10818
11225
|
|
|
10819
11226
|
//#endregion
|
|
10820
|
-
//#region src/components/error-boundary/error-boundary.tsx
|
|
11227
|
+
//#region src/v1-deprecated/components/error-boundary/error-boundary.tsx
|
|
10821
11228
|
const statusChecker = new StatusChecker();
|
|
10822
11229
|
var CopilotErrorBoundary = class extends react.default.Component {
|
|
10823
11230
|
constructor(props) {
|
|
@@ -10858,7 +11265,7 @@ window.parent.postMessage({jsonrpc:"2.0",method:"ui/notifications/sandbox-proxy-
|
|
|
10858
11265
|
};
|
|
10859
11266
|
|
|
10860
11267
|
//#endregion
|
|
10861
|
-
//#region src/context/coagent-state-renders-context.tsx
|
|
11268
|
+
//#region src/v1-deprecated/context/coagent-state-renders-context.tsx
|
|
10862
11269
|
const CoAgentStateRendersContext = (0, react.createContext)(void 0);
|
|
10863
11270
|
function CoAgentStateRendersProvider({ children }) {
|
|
10864
11271
|
const [coAgentStateRenders, setCoAgentStateRenders] = (0, react.useState)({});
|
|
@@ -10893,7 +11300,7 @@ window.parent.postMessage({jsonrpc:"2.0",method:"ui/notifications/sandbox-proxy-
|
|
|
10893
11300
|
}
|
|
10894
11301
|
|
|
10895
11302
|
//#endregion
|
|
10896
|
-
//#region src/context/threads-context.tsx
|
|
11303
|
+
//#region src/v1-deprecated/context/threads-context.tsx
|
|
10897
11304
|
const ThreadsContext = (0, react.createContext)(void 0);
|
|
10898
11305
|
function ThreadsProvider({ children, threadId: explicitThreadId }) {
|
|
10899
11306
|
const [internalThreadId, setInternalThreadId] = (0, react.useState)(() => (0, _copilotkit_shared.randomUUID)());
|
|
@@ -10920,7 +11327,7 @@ window.parent.postMessage({jsonrpc:"2.0",method:"ui/notifications/sandbox-proxy-
|
|
|
10920
11327
|
}
|
|
10921
11328
|
|
|
10922
11329
|
//#endregion
|
|
10923
|
-
//#region src/hooks/use-coagent-state-render-bridge.helpers.ts
|
|
11330
|
+
//#region src/v1-deprecated/hooks/use-coagent-state-render-bridge.helpers.ts
|
|
10924
11331
|
let RenderStatus = /* @__PURE__ */ function(RenderStatus) {
|
|
10925
11332
|
RenderStatus["InProgress"] = "inProgress";
|
|
10926
11333
|
RenderStatus["Complete"] = "complete";
|
|
@@ -11085,7 +11492,7 @@ window.parent.postMessage({jsonrpc:"2.0",method:"ui/notifications/sandbox-proxy-
|
|
|
11085
11492
|
}
|
|
11086
11493
|
|
|
11087
11494
|
//#endregion
|
|
11088
|
-
//#region src/hooks/use-coagent-state-render-registry.ts
|
|
11495
|
+
//#region src/v1-deprecated/hooks/use-coagent-state-render-registry.ts
|
|
11089
11496
|
const LAST_SNAPSHOTS_BY_RENDER_AND_RUN = "__lastSnapshotsByStateRenderIdAndRun";
|
|
11090
11497
|
const LAST_SNAPSHOTS_BY_MESSAGE = "__lastSnapshotsByMessageId";
|
|
11091
11498
|
function getClaimsStore(claimsRef) {
|
|
@@ -11207,7 +11614,7 @@ window.parent.postMessage({jsonrpc:"2.0",method:"ui/notifications/sandbox-proxy-
|
|
|
11207
11614
|
}
|
|
11208
11615
|
|
|
11209
11616
|
//#endregion
|
|
11210
|
-
//#region src/hooks/use-coagent-state-render-bridge.tsx
|
|
11617
|
+
//#region src/v1-deprecated/hooks/use-coagent-state-render-bridge.tsx
|
|
11211
11618
|
function useCoagentStateRenderBridge(agentId, props) {
|
|
11212
11619
|
const { stateSnapshot, message } = props;
|
|
11213
11620
|
const { coAgentStateRenders, claimsRef } = useCoAgentStateRenders();
|
|
@@ -11291,7 +11698,7 @@ window.parent.postMessage({jsonrpc:"2.0",method:"ui/notifications/sandbox-proxy-
|
|
|
11291
11698
|
}
|
|
11292
11699
|
|
|
11293
11700
|
//#endregion
|
|
11294
|
-
//#region src/components/CopilotListeners.tsx
|
|
11701
|
+
//#region src/v1-deprecated/components/CopilotListeners.tsx
|
|
11295
11702
|
const usePredictStateSubscription = (agent) => {
|
|
11296
11703
|
const predictStateToolsRef = (0, react.useRef)([]);
|
|
11297
11704
|
const getSubscriber = (0, react.useCallback)((agent) => ({
|
|
@@ -11361,7 +11768,7 @@ window.parent.postMessage({jsonrpc:"2.0",method:"ui/notifications/sandbox-proxy-
|
|
|
11361
11768
|
}
|
|
11362
11769
|
|
|
11363
11770
|
//#endregion
|
|
11364
|
-
//#region src/components/copilot-provider/copilotkit.tsx
|
|
11771
|
+
//#region src/v1-deprecated/components/copilot-provider/copilotkit.tsx
|
|
11365
11772
|
function CopilotKit({ children, ...props }) {
|
|
11366
11773
|
const enabled = shouldShowDevConsole(props.showDevConsole);
|
|
11367
11774
|
const showInspector = shouldShowDevConsole(props.enableInspector);
|
|
@@ -11379,7 +11786,6 @@ window.parent.postMessage({jsonrpc:"2.0",method:"ui/notifications/sandbox-proxy-
|
|
|
11379
11786
|
...v2Props,
|
|
11380
11787
|
showDevConsole: showInspector,
|
|
11381
11788
|
renderCustomMessages: renderArr,
|
|
11382
|
-
useSingleEndpoint: props.useSingleEndpoint ?? true,
|
|
11383
11789
|
children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(CopilotKitInternal, {
|
|
11384
11790
|
...props,
|
|
11385
11791
|
children
|