@copilotkit/react-core 1.69.1 → 1.69.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-Dr0speVK.cjs → copilotkit-BPeh62mW.cjs} +104 -341
- package/dist/copilotkit-BPeh62mW.cjs.map +1 -0
- package/dist/{copilotkit-Hl1t9Y1v.d.cts → copilotkit-CrNUgJiq.d.cts} +18 -21
- package/dist/copilotkit-CrNUgJiq.d.cts.map +1 -0
- package/dist/{copilotkit-DYKpg4pD.d.mts → copilotkit-DgO31tBq.d.mts} +18 -21
- package/dist/copilotkit-DgO31tBq.d.mts.map +1 -0
- package/dist/{copilotkit-Dr6g885f.mjs → copilotkit-JdHy0xdu.mjs} +106 -343
- package/dist/copilotkit-JdHy0xdu.mjs.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 +77 -100
- package/dist/index.umd.js.map +1 -1
- package/dist/v2/headless.cjs +1 -2
- package/dist/v2/headless.cjs.map +1 -1
- package/dist/v2/headless.d.cts +0 -1
- package/dist/v2/headless.d.cts.map +1 -1
- package/dist/v2/headless.d.mts +0 -1
- package/dist/v2/headless.d.mts.map +1 -1
- package/dist/v2/headless.mjs +1 -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 +1 -1
- package/dist/v2/index.d.mts +1 -1
- package/dist/v2/index.mjs +1 -1
- package/dist/v2/index.umd.js +107 -343
- package/dist/v2/index.umd.js.map +1 -1
- package/package.json +7 -8
- package/skills/react-core/SKILL.md +5 -3
- package/skills/react-core/references/agent-access.md +68 -1
- package/skills/react-core/references/debug-mode.md +21 -34
- package/skills/react-core/references/switching-agents-recipes.md +1 -0
- package/skills/react-core/references/switching-agents.md +9 -0
- package/skills/react-core/references/threads.md +65 -0
- package/dist/copilotkit-DYKpg4pD.d.mts.map +0 -1
- package/dist/copilotkit-Dr0speVK.cjs.map +0 -1
- package/dist/copilotkit-Dr6g885f.mjs.map +0 -1
- package/dist/copilotkit-Hl1t9Y1v.d.cts.map +0 -1
|
@@ -43,7 +43,6 @@ _radix_ui_react_dropdown_menu = __toESM(_radix_ui_react_dropdown_menu);
|
|
|
43
43
|
let streamdown = require("streamdown");
|
|
44
44
|
let _copilotkit_react_core_v2_context = require("@copilotkit/react-core/v2/context");
|
|
45
45
|
let zod = require("zod");
|
|
46
|
-
let _lit_labs_react = require("@lit-labs/react");
|
|
47
46
|
let _copilotkit_a2ui_renderer = require("@copilotkit/a2ui-renderer");
|
|
48
47
|
let zod_to_json_schema = require("zod-to-json-schema");
|
|
49
48
|
let react_dom = require("react-dom");
|
|
@@ -107,8 +106,7 @@ const CopilotChatDefaultLabels = {
|
|
|
107
106
|
assistantMessageToolbarCopyCodeCopiedLabel: "Copied",
|
|
108
107
|
assistantMessageToolbarCopyMessageLabel: "Copy",
|
|
109
108
|
assistantMessageToolbarInspectorLabel: "View in Inspector",
|
|
110
|
-
assistantMessageToolbarInspectorLocalOnlyLabel: "
|
|
111
|
-
assistantMessageToolbarSaveSnippetLabel: "Save as snippet",
|
|
109
|
+
assistantMessageToolbarInspectorLocalOnlyLabel: "Development Only",
|
|
112
110
|
assistantMessageToolbarThumbsUpLabel: "Good response",
|
|
113
111
|
assistantMessageToolbarThumbsDownLabel: "Bad response",
|
|
114
112
|
assistantMessageToolbarReadAloudLabel: "Read aloud",
|
|
@@ -1527,32 +1525,43 @@ function useRenderToolCall() {
|
|
|
1527
1525
|
|
|
1528
1526
|
//#endregion
|
|
1529
1527
|
//#region src/v2/components/CopilotKitInspector.tsx
|
|
1530
|
-
const CopilotKitInspector = ({ core, openRequest
|
|
1531
|
-
const
|
|
1528
|
+
const CopilotKitInspector = ({ core, openRequest }) => {
|
|
1529
|
+
const mountRef = react.useRef(null);
|
|
1532
1530
|
const inspectorRef = react.useRef(null);
|
|
1531
|
+
const latestCoreRef = react.useRef(core ?? null);
|
|
1532
|
+
const latestOpenRequestRef = react.useRef(openRequest);
|
|
1533
|
+
latestCoreRef.current = core ?? null;
|
|
1534
|
+
latestOpenRequestRef.current = openRequest;
|
|
1533
1535
|
react.useEffect(() => {
|
|
1534
1536
|
let mounted = true;
|
|
1537
|
+
let inspector = null;
|
|
1535
1538
|
import("@copilotkit/web-inspector").then((mod) => {
|
|
1539
|
+
if (!mounted || !mountRef.current) return;
|
|
1536
1540
|
mod.defineWebInspector?.();
|
|
1537
|
-
|
|
1538
|
-
|
|
1539
|
-
|
|
1540
|
-
|
|
1541
|
-
|
|
1542
|
-
if (
|
|
1541
|
+
inspector = mountRef.current.ownerDocument.createElement(mod.WEB_INSPECTOR_TAG);
|
|
1542
|
+
mod.configureWebInspectorElement(inspector, latestCoreRef.current);
|
|
1543
|
+
mountRef.current.appendChild(inspector);
|
|
1544
|
+
inspectorRef.current = inspector;
|
|
1545
|
+
const request = latestOpenRequestRef.current;
|
|
1546
|
+
if (request) inspector.openInspector("message_toolbar", request);
|
|
1547
|
+
}).catch((error) => {
|
|
1548
|
+
console.error("Failed to load CopilotKit inspector:", error);
|
|
1543
1549
|
});
|
|
1544
1550
|
return () => {
|
|
1545
1551
|
mounted = false;
|
|
1552
|
+
inspector?.remove();
|
|
1553
|
+
if (inspectorRef.current === inspector) inspectorRef.current = null;
|
|
1546
1554
|
};
|
|
1547
1555
|
}, []);
|
|
1556
|
+
react.useEffect(() => {
|
|
1557
|
+
if (inspectorRef.current) inspectorRef.current.core = core ?? null;
|
|
1558
|
+
}, [core]);
|
|
1548
1559
|
react.useEffect(() => {
|
|
1549
1560
|
if (openRequest) inspectorRef.current?.openInspector("message_toolbar", openRequest);
|
|
1550
|
-
}, [
|
|
1551
|
-
|
|
1552
|
-
|
|
1553
|
-
|
|
1554
|
-
...rest,
|
|
1555
|
-
core: core ?? null
|
|
1561
|
+
}, [openRequest]);
|
|
1562
|
+
return /* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
|
|
1563
|
+
ref: mountRef,
|
|
1564
|
+
style: { display: "contents" }
|
|
1556
1565
|
});
|
|
1557
1566
|
};
|
|
1558
1567
|
CopilotKitInspector.displayName = "CopilotKitInspector";
|
|
@@ -1560,9 +1569,8 @@ CopilotKitInspector.displayName = "CopilotKitInspector";
|
|
|
1560
1569
|
//#endregion
|
|
1561
1570
|
//#region src/v2/components/CopilotKitInspectorContext.tsx
|
|
1562
1571
|
const CopilotKitInspectorContext = react.createContext({
|
|
1563
|
-
|
|
1564
|
-
openInspector: () => void 0
|
|
1565
|
-
saveEventSnippet: async () => void 0
|
|
1572
|
+
isInspectorEnabled: false,
|
|
1573
|
+
openInspector: () => void 0
|
|
1566
1574
|
});
|
|
1567
1575
|
const CopilotKitInspectorContextProvider = CopilotKitInspectorContext.Provider;
|
|
1568
1576
|
function useCopilotKitInspector() {
|
|
@@ -2376,7 +2384,6 @@ function injectCssIntoHtml(html, css) {
|
|
|
2376
2384
|
const OpenGenerativeUIActivityRendererInner = react.default.memo(function OpenGenerativeUIActivityRendererInner({ content }) {
|
|
2377
2385
|
const initialHeight = content.initialHeight ?? 200;
|
|
2378
2386
|
const [autoHeight, setAutoHeight] = (0, react.useState)(null);
|
|
2379
|
-
const [sandboxReady, setSandboxReady] = (0, react.useState)(false);
|
|
2380
2387
|
const sandboxFunctions = useSandboxFunctions();
|
|
2381
2388
|
const localApi = (0, react.useMemo)(() => {
|
|
2382
2389
|
const api = {};
|
|
@@ -2478,7 +2485,6 @@ const OpenGenerativeUIActivityRendererInner = react.default.memo(function OpenGe
|
|
|
2478
2485
|
sandbox.promise.then(() => {
|
|
2479
2486
|
if (cancelled) return;
|
|
2480
2487
|
sandboxReadyRef.current = true;
|
|
2481
|
-
setSandboxReady(true);
|
|
2482
2488
|
sandbox.run(`
|
|
2483
2489
|
var s = document.createElement('style');
|
|
2484
2490
|
s.textContent = 'html, body { overflow: hidden !important; }';
|
|
@@ -2503,7 +2509,6 @@ const OpenGenerativeUIActivityRendererInner = react.default.memo(function OpenGe
|
|
|
2503
2509
|
sandboxRef.current = null;
|
|
2504
2510
|
}
|
|
2505
2511
|
sandboxReadyRef.current = false;
|
|
2506
|
-
setSandboxReady(false);
|
|
2507
2512
|
setAutoHeight(null);
|
|
2508
2513
|
};
|
|
2509
2514
|
}, [
|
|
@@ -2534,7 +2539,7 @@ const OpenGenerativeUIActivityRendererInner = react.default.memo(function OpenGe
|
|
|
2534
2539
|
const generationDone = content.generating === false;
|
|
2535
2540
|
(0, react.useEffect)(() => {
|
|
2536
2541
|
const sandbox = sandboxRef.current;
|
|
2537
|
-
if (!generationDone || !
|
|
2542
|
+
if (!generationDone || !sandbox) return;
|
|
2538
2543
|
let handled = false;
|
|
2539
2544
|
const onMessage = (e) => {
|
|
2540
2545
|
if (handled) return;
|
|
@@ -2563,7 +2568,7 @@ const OpenGenerativeUIActivityRendererInner = react.default.memo(function OpenGe
|
|
|
2563
2568
|
return () => {
|
|
2564
2569
|
window.removeEventListener("message", onMessage);
|
|
2565
2570
|
};
|
|
2566
|
-
}, [generationDone
|
|
2571
|
+
}, [generationDone]);
|
|
2567
2572
|
const height = autoHeight ?? initialHeight;
|
|
2568
2573
|
const isGenerating = content.generating !== false;
|
|
2569
2574
|
return /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
|
|
@@ -3514,9 +3519,15 @@ function useStableArrayProp(prop, warningMessage, isMeaningfulChange) {
|
|
|
3514
3519
|
}, [value, warningMessage]);
|
|
3515
3520
|
return value;
|
|
3516
3521
|
}
|
|
3517
|
-
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,
|
|
3522
|
+
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, enableInspector, useSingleEndpoint, onError, a2ui, defaultThrottleMs, debug }) => {
|
|
3518
3523
|
const [shouldRenderInspector, setShouldRenderInspector] = (0, react.useState)(false);
|
|
3519
|
-
|
|
3524
|
+
(0, react.useEffect)(() => {
|
|
3525
|
+
setShouldRenderInspector((0, _copilotkit_shared.shouldEnableInspector)({
|
|
3526
|
+
enableInspector,
|
|
3527
|
+
isBrowser: true,
|
|
3528
|
+
isDevelopment: process.env.NODE_ENV === "development"
|
|
3529
|
+
}));
|
|
3530
|
+
}, [enableInspector]);
|
|
3520
3531
|
const [inspectorOpenRequest, setInspectorOpenRequest] = (0, react.useState)(null);
|
|
3521
3532
|
const [runtimeA2UIEnabled, setRuntimeA2UIEnabled] = (0, react.useState)(false);
|
|
3522
3533
|
const [runtimeOpenGenUIEnabled, setRuntimeOpenGenUIEnabled] = (0, react.useState)(false);
|
|
@@ -3525,68 +3536,13 @@ const CopilotKitProvider = ({ children, runtimeUrl, headers: headersProp = EMPTY
|
|
|
3525
3536
|
const a2uiCatalogProvided = !!a2ui?.catalog;
|
|
3526
3537
|
const a2uiActive = runtimeA2UIEnabled || a2uiCatalogProvided;
|
|
3527
3538
|
const [runtimeLicenseStatus, setRuntimeLicenseStatus] = (0, react.useState)(void 0);
|
|
3528
|
-
(0, react.useEffect)(() => {
|
|
3529
|
-
if (typeof window === "undefined") return;
|
|
3530
|
-
const isLocalhost = new Set(["localhost", "127.0.0.1"]).has(window.location?.hostname ?? "");
|
|
3531
|
-
const canShowLocalInspectorAction = process.env.NODE_ENV === "development" && isLocalhost;
|
|
3532
|
-
if (showDevConsole === true) {
|
|
3533
|
-
setShouldRenderInspector(true);
|
|
3534
|
-
setIsLocalInspectorEnabled(canShowLocalInspectorAction);
|
|
3535
|
-
} else if (showDevConsole === "auto") if (isLocalhost) {
|
|
3536
|
-
setShouldRenderInspector(true);
|
|
3537
|
-
setIsLocalInspectorEnabled(canShowLocalInspectorAction);
|
|
3538
|
-
} else {
|
|
3539
|
-
setShouldRenderInspector(false);
|
|
3540
|
-
setIsLocalInspectorEnabled(false);
|
|
3541
|
-
}
|
|
3542
|
-
else {
|
|
3543
|
-
setShouldRenderInspector(false);
|
|
3544
|
-
setIsLocalInspectorEnabled(false);
|
|
3545
|
-
}
|
|
3546
|
-
}, [showDevConsole]);
|
|
3547
3539
|
const requestInspectorOpen = (0, react.useCallback)((request) => {
|
|
3548
3540
|
setInspectorOpenRequest({ ...request });
|
|
3549
3541
|
}, []);
|
|
3550
|
-
const saveEventSnippet = (0, react.useCallback)(async (request) => {
|
|
3551
|
-
try {
|
|
3552
|
-
const mod = await import("@copilotkit/web-inspector");
|
|
3553
|
-
const threadId = request.threadId ?? "inspector-snippet";
|
|
3554
|
-
const runId = `inspector-snippet-${Date.now()}`;
|
|
3555
|
-
const compiled = mod.compileChatSnippet({
|
|
3556
|
-
...request,
|
|
3557
|
-
threadId,
|
|
3558
|
-
runId
|
|
3559
|
-
});
|
|
3560
|
-
const now = (/* @__PURE__ */ new Date()).toISOString();
|
|
3561
|
-
const snippet = {
|
|
3562
|
-
id: crypto.randomUUID(),
|
|
3563
|
-
name: compiled.name,
|
|
3564
|
-
recipe: compiled.recipe,
|
|
3565
|
-
events: compiled.events,
|
|
3566
|
-
createdAt: now,
|
|
3567
|
-
updatedAt: now
|
|
3568
|
-
};
|
|
3569
|
-
mod.upsertEventSnippet(snippet);
|
|
3570
|
-
requestInspectorOpen({
|
|
3571
|
-
messageId: request.messageId,
|
|
3572
|
-
threadId: request.threadId,
|
|
3573
|
-
agentId: request.agentId,
|
|
3574
|
-
menu: "event-snippets",
|
|
3575
|
-
snippetId: snippet.id
|
|
3576
|
-
});
|
|
3577
|
-
} catch (error) {
|
|
3578
|
-
console.error("[CopilotKit] Could not save the event snippet.", error);
|
|
3579
|
-
}
|
|
3580
|
-
}, [requestInspectorOpen]);
|
|
3581
3542
|
const inspectorContextValue = (0, react.useMemo)(() => ({
|
|
3582
|
-
|
|
3583
|
-
openInspector: requestInspectorOpen
|
|
3584
|
-
|
|
3585
|
-
}), [
|
|
3586
|
-
isLocalInspectorEnabled,
|
|
3587
|
-
requestInspectorOpen,
|
|
3588
|
-
saveEventSnippet
|
|
3589
|
-
]);
|
|
3543
|
+
isInspectorEnabled: shouldRenderInspector,
|
|
3544
|
+
openInspector: requestInspectorOpen
|
|
3545
|
+
}), [shouldRenderInspector, requestInspectorOpen]);
|
|
3590
3546
|
const renderToolCallsList = useStableArrayProp(renderToolCalls, "renderToolCalls must be a stable array. If you want to dynamically add or remove tools, use `useFrontendTool` instead.", (initial, next) => {
|
|
3591
3547
|
const key = (rc) => `${rc?.agentId ?? ""}:${rc?.name ?? ""}`;
|
|
3592
3548
|
const setFrom = (arr) => new Set(arr.map(key));
|
|
@@ -3927,7 +3883,6 @@ const CopilotKitProvider = ({ children, runtimeUrl, headers: headersProp = EMPTY
|
|
|
3927
3883
|
value: inspectorContextValue,
|
|
3928
3884
|
children: [children, shouldRenderInspector ? /* @__PURE__ */ (0, react_jsx_runtime.jsx)(CopilotKitInspector, {
|
|
3929
3885
|
core: copilotkit,
|
|
3930
|
-
defaultAnchor: inspectorDefaultAnchor,
|
|
3931
3886
|
openRequest: inspectorOpenRequest
|
|
3932
3887
|
}) : null]
|
|
3933
3888
|
}),
|
|
@@ -5963,191 +5918,25 @@ function useLearningContainersInCurrentThread({ learningContainers }) {
|
|
|
5963
5918
|
});
|
|
5964
5919
|
}
|
|
5965
5920
|
|
|
5966
|
-
//#endregion
|
|
5967
|
-
//#region src/v2/components/chat/save-snippet-beside.ts
|
|
5968
|
-
const SAVE_SNIPPET_ICON_SLOT_PX = 36;
|
|
5969
|
-
const SAVE_SNIPPET_BESIDE_WRAP_CLASS = "cpk:relative cpk:w-full cpk:overflow-visible";
|
|
5970
|
-
const SAVE_SNIPPET_BESIDE_BODY_CLASS = "cpk:w-full";
|
|
5971
|
-
const SAVE_SNIPPET_BESIDE_SAVE_CLASS = "cpk:absolute cpk:top-0 cpk:z-10";
|
|
5972
|
-
function saveSnippetBesideStyle(side) {
|
|
5973
|
-
if (side === "left") return {
|
|
5974
|
-
left: "auto",
|
|
5975
|
-
right: "100%",
|
|
5976
|
-
marginLeft: 0,
|
|
5977
|
-
marginRight: 4
|
|
5978
|
-
};
|
|
5979
|
-
return {
|
|
5980
|
-
left: "100%",
|
|
5981
|
-
right: "auto",
|
|
5982
|
-
marginLeft: 4,
|
|
5983
|
-
marginRight: 0
|
|
5984
|
-
};
|
|
5985
|
-
}
|
|
5986
|
-
function pickSaveSnippetSide(roomRight, roomLeft, slotPx = SAVE_SNIPPET_ICON_SLOT_PX) {
|
|
5987
|
-
if (roomRight >= slotPx) return "right";
|
|
5988
|
-
if (roomLeft >= slotPx) return "left";
|
|
5989
|
-
return "right";
|
|
5990
|
-
}
|
|
5991
|
-
function findOverflowAncestor(el) {
|
|
5992
|
-
let node = el.parentElement;
|
|
5993
|
-
while (node) {
|
|
5994
|
-
const style = getComputedStyle(node);
|
|
5995
|
-
const overflowX = style.overflowX;
|
|
5996
|
-
const overflow = style.overflow;
|
|
5997
|
-
if (overflowX === "hidden" || overflowX === "auto" || overflowX === "scroll" || overflow === "hidden" || overflow === "auto" || overflow === "scroll") return node;
|
|
5998
|
-
node = node.parentElement;
|
|
5999
|
-
}
|
|
6000
|
-
return document.documentElement;
|
|
6001
|
-
}
|
|
6002
|
-
function measurableBox(el) {
|
|
6003
|
-
let node = el;
|
|
6004
|
-
while (node && getComputedStyle(node).display === "contents") node = node.firstElementChild;
|
|
6005
|
-
return node ?? el;
|
|
6006
|
-
}
|
|
6007
|
-
function measureSaveSnippetSide(wrap, body) {
|
|
6008
|
-
const clipRect = findOverflowAncestor(wrap).getBoundingClientRect();
|
|
6009
|
-
const bodyRect = measurableBox(body.firstElementChild ?? body).getBoundingClientRect();
|
|
6010
|
-
return pickSaveSnippetSide(clipRect.right - bodyRect.right, bodyRect.left - clipRect.left);
|
|
6011
|
-
}
|
|
6012
|
-
|
|
6013
|
-
//#endregion
|
|
6014
|
-
//#region src/v2/components/chat/SaveSnippetIconButton.tsx
|
|
6015
|
-
function SaveSnippetIconButton({ title, className, ...props }) {
|
|
6016
|
-
const labels = useCopilotChatConfiguration()?.labels ?? CopilotChatDefaultLabels;
|
|
6017
|
-
const primaryLabel = title || labels.assistantMessageToolbarSaveSnippetLabel;
|
|
6018
|
-
const localOnlyLabel = labels.assistantMessageToolbarInspectorLocalOnlyLabel;
|
|
6019
|
-
const accessibleLabel = `${primaryLabel} (${localOnlyLabel})`;
|
|
6020
|
-
return /* @__PURE__ */ (0, react_jsx_runtime.jsxs)(Tooltip, { children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)(TooltipTrigger, {
|
|
6021
|
-
asChild: true,
|
|
6022
|
-
children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(Button, {
|
|
6023
|
-
type: "button",
|
|
6024
|
-
variant: "assistantMessageToolbarButton",
|
|
6025
|
-
"aria-label": accessibleLabel,
|
|
6026
|
-
title: accessibleLabel,
|
|
6027
|
-
className,
|
|
6028
|
-
...props,
|
|
6029
|
-
children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(lucide_react.Bookmark, { className: "cpk:size-[18px]" })
|
|
6030
|
-
})
|
|
6031
|
-
}), /* @__PURE__ */ (0, react_jsx_runtime.jsx)(TooltipContent, {
|
|
6032
|
-
side: "bottom",
|
|
6033
|
-
children: /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
|
|
6034
|
-
className: "cpk:flex cpk:flex-col cpk:gap-0.5",
|
|
6035
|
-
children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", { children: primaryLabel }), /* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
|
|
6036
|
-
className: "cpk:text-[10px] cpk:opacity-65",
|
|
6037
|
-
children: localOnlyLabel
|
|
6038
|
-
})]
|
|
6039
|
-
})
|
|
6040
|
-
})] });
|
|
6041
|
-
}
|
|
6042
|
-
function SaveSnippetBesideChrome({ children, showSave, saveButton }) {
|
|
6043
|
-
const wrapRef = (0, react.useRef)(null);
|
|
6044
|
-
const bodyRef = (0, react.useRef)(null);
|
|
6045
|
-
const [side, setSide] = (0, react.useState)("right");
|
|
6046
|
-
(0, react.useLayoutEffect)(() => {
|
|
6047
|
-
if (!showSave) return;
|
|
6048
|
-
const wrap = wrapRef.current;
|
|
6049
|
-
const body = bodyRef.current;
|
|
6050
|
-
if (!wrap || !body) return;
|
|
6051
|
-
const measure = () => {
|
|
6052
|
-
setSide(measureSaveSnippetSide(wrap, body));
|
|
6053
|
-
};
|
|
6054
|
-
measure();
|
|
6055
|
-
if (typeof ResizeObserver === "undefined") return;
|
|
6056
|
-
const observer = new ResizeObserver(measure);
|
|
6057
|
-
observer.observe(wrap);
|
|
6058
|
-
observer.observe(body);
|
|
6059
|
-
const clip = findOverflowAncestor(wrap);
|
|
6060
|
-
if (clip !== wrap) observer.observe(clip);
|
|
6061
|
-
window.addEventListener("resize", measure);
|
|
6062
|
-
return () => {
|
|
6063
|
-
observer.disconnect();
|
|
6064
|
-
window.removeEventListener("resize", measure);
|
|
6065
|
-
};
|
|
6066
|
-
}, [showSave]);
|
|
6067
|
-
if (!showSave) return children;
|
|
6068
|
-
return /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
|
|
6069
|
-
ref: wrapRef,
|
|
6070
|
-
className: SAVE_SNIPPET_BESIDE_WRAP_CLASS,
|
|
6071
|
-
"data-save-snippet-side": side,
|
|
6072
|
-
children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
|
|
6073
|
-
ref: bodyRef,
|
|
6074
|
-
className: SAVE_SNIPPET_BESIDE_BODY_CLASS,
|
|
6075
|
-
children
|
|
6076
|
-
}), /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
|
|
6077
|
-
className: SAVE_SNIPPET_BESIDE_SAVE_CLASS,
|
|
6078
|
-
style: saveSnippetBesideStyle(side),
|
|
6079
|
-
children: saveButton
|
|
6080
|
-
})]
|
|
6081
|
-
});
|
|
6082
|
-
}
|
|
6083
|
-
|
|
6084
5921
|
//#endregion
|
|
6085
5922
|
//#region src/v2/components/chat/CopilotChatToolCallsView.tsx
|
|
6086
5923
|
function CopilotChatToolCallsView({ message, messages = [] }) {
|
|
6087
5924
|
const renderToolCall = useRenderToolCall();
|
|
6088
|
-
const { isLocalInspectorEnabled, saveEventSnippet } = useCopilotKitInspector();
|
|
6089
|
-
const chatConfiguration = useCopilotChatConfiguration();
|
|
6090
|
-
const labels = chatConfiguration?.labels ?? CopilotChatDefaultLabels;
|
|
6091
5925
|
if (!message.toolCalls || message.toolCalls.length === 0) return null;
|
|
6092
5926
|
return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(react_jsx_runtime.Fragment, { children: message.toolCalls.map((toolCall) => {
|
|
6093
|
-
const
|
|
5927
|
+
const toolMessage = messages.find((m) => m.role === "tool" && m.toolCallId === toolCall.id);
|
|
5928
|
+
return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(react.default.Fragment, { children: renderToolCall({
|
|
6094
5929
|
toolCall,
|
|
6095
|
-
toolMessage
|
|
6096
|
-
});
|
|
6097
|
-
if (!isLocalInspectorEnabled || !hasCompleteArgs(toolCall.function.arguments)) return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(react.default.Fragment, { children: rendered }, toolCall.id);
|
|
6098
|
-
const primaryLabel = labels.assistantMessageToolbarSaveSnippetLabel;
|
|
6099
|
-
return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(ToolCallSnippetChrome, {
|
|
6100
|
-
label: primaryLabel,
|
|
6101
|
-
onSave: () => void saveEventSnippet({
|
|
6102
|
-
kind: "tool-call",
|
|
6103
|
-
messageId: message.id,
|
|
6104
|
-
toolCallId: toolCall.id,
|
|
6105
|
-
toolName: toolCall.function.name,
|
|
6106
|
-
argsJson: toolCall.function.arguments || "{}",
|
|
6107
|
-
threadId: chatConfiguration?.threadId,
|
|
6108
|
-
agentId: chatConfiguration?.agentId
|
|
6109
|
-
}),
|
|
6110
|
-
children: rendered
|
|
6111
|
-
}, toolCall.id);
|
|
5930
|
+
toolMessage
|
|
5931
|
+
}) }, toolCall.id);
|
|
6112
5932
|
}) });
|
|
6113
5933
|
}
|
|
6114
|
-
function hasCompleteArgs(args) {
|
|
6115
|
-
const trimmed = (args ?? "").trim();
|
|
6116
|
-
if (!trimmed) return true;
|
|
6117
|
-
try {
|
|
6118
|
-
JSON.parse(trimmed);
|
|
6119
|
-
return true;
|
|
6120
|
-
} catch {
|
|
6121
|
-
return false;
|
|
6122
|
-
}
|
|
6123
|
-
}
|
|
6124
|
-
function ToolCallSnippetChrome({ children, label, onSave }) {
|
|
6125
|
-
const bodyRef = (0, react.useRef)(null);
|
|
6126
|
-
const [showSave, setShowSave] = (0, react.useState)(false);
|
|
6127
|
-
(0, react.useLayoutEffect)(() => {
|
|
6128
|
-
const el = bodyRef.current;
|
|
6129
|
-
setShowSave(!!el && el.childElementCount > 0);
|
|
6130
|
-
});
|
|
6131
|
-
return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(SaveSnippetBesideChrome, {
|
|
6132
|
-
showSave,
|
|
6133
|
-
saveButton: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(SaveSnippetIconButton, {
|
|
6134
|
-
"data-testid": "copilot-tool-save-snippet-button",
|
|
6135
|
-
title: label,
|
|
6136
|
-
onClick: onSave
|
|
6137
|
-
}),
|
|
6138
|
-
children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
|
|
6139
|
-
ref: bodyRef,
|
|
6140
|
-
className: "cpk:contents",
|
|
6141
|
-
children
|
|
6142
|
-
})
|
|
6143
|
-
});
|
|
6144
|
-
}
|
|
6145
5934
|
|
|
6146
5935
|
//#endregion
|
|
6147
5936
|
//#region src/v2/components/chat/CopilotChatAssistantMessage.tsx
|
|
6148
|
-
function CopilotChatAssistantMessage({ message, messages, isRunning, onThumbsUp, onThumbsDown, onReadAloud, onRegenerate, additionalToolbarItems, toolbarVisible = true, markdownRenderer, toolbar, copyButton, inspectorButton,
|
|
5937
|
+
function CopilotChatAssistantMessage({ message, messages, isRunning, onThumbsUp, onThumbsDown, onReadAloud, onRegenerate, additionalToolbarItems, toolbarVisible = true, markdownRenderer, toolbar, copyButton, inspectorButton, thumbsUpButton, thumbsDownButton, readAloudButton, regenerateButton, toolCallsView, children, className, ...props }) {
|
|
6149
5938
|
useKatexStyles();
|
|
6150
|
-
const {
|
|
5939
|
+
const { isInspectorEnabled, openInspector } = useCopilotKitInspector();
|
|
6151
5940
|
const chatConfiguration = useCopilotChatConfiguration();
|
|
6152
5941
|
const boundMarkdownRenderer = renderSlot(markdownRenderer, CopilotChatAssistantMessage.MarkdownRenderer, { content: message.content || "" });
|
|
6153
5942
|
const boundCopyButton = renderSlot(copyButton, CopilotChatAssistantMessage.CopyButton, { onClick: async () => {
|
|
@@ -6160,17 +5949,6 @@ function CopilotChatAssistantMessage({ message, messages, isRunning, onThumbsUp,
|
|
|
6160
5949
|
threadId: chatConfiguration?.threadId,
|
|
6161
5950
|
agentId: chatConfiguration?.agentId
|
|
6162
5951
|
}) });
|
|
6163
|
-
const hasContent = !!(message.content && message.content.trim().length > 0);
|
|
6164
|
-
const boundSaveSnippetButton = renderSlot(saveSnippetButton, CopilotChatAssistantMessage.SaveSnippetButton, { onClick: () => {
|
|
6165
|
-
if (!hasContent) return;
|
|
6166
|
-
saveEventSnippet({
|
|
6167
|
-
kind: "text",
|
|
6168
|
-
messageId: message.id,
|
|
6169
|
-
content: message.content ?? "",
|
|
6170
|
-
threadId: chatConfiguration?.threadId,
|
|
6171
|
-
agentId: chatConfiguration?.agentId
|
|
6172
|
-
});
|
|
6173
|
-
} });
|
|
6174
5952
|
const boundThumbsDownButton = renderSlot(thumbsDownButton, CopilotChatAssistantMessage.ThumbsDownButton, { onClick: onThumbsDown ? () => onThumbsDown(message) : void 0 });
|
|
6175
5953
|
const boundReadAloudButton = renderSlot(readAloudButton, CopilotChatAssistantMessage.ReadAloudButton, { onClick: onReadAloud ? () => onReadAloud(message) : void 0 });
|
|
6176
5954
|
const boundRegenerateButton = renderSlot(regenerateButton, CopilotChatAssistantMessage.RegenerateButton, { onClick: onRegenerate ? () => onRegenerate(message) : void 0 });
|
|
@@ -6178,8 +5956,7 @@ function CopilotChatAssistantMessage({ message, messages, isRunning, onThumbsUp,
|
|
|
6178
5956
|
className: "cpk:flex cpk:items-center cpk:gap-1",
|
|
6179
5957
|
children: [
|
|
6180
5958
|
boundCopyButton,
|
|
6181
|
-
|
|
6182
|
-
isLocalInspectorEnabled && hasContent && boundSaveSnippetButton,
|
|
5959
|
+
isInspectorEnabled && boundInspectorButton,
|
|
6183
5960
|
(onThumbsUp || thumbsUpButton) && boundThumbsUpButton,
|
|
6184
5961
|
(onThumbsDown || thumbsDownButton) && boundThumbsDownButton,
|
|
6185
5962
|
(onReadAloud || readAloudButton) && boundReadAloudButton,
|
|
@@ -6191,8 +5968,9 @@ function CopilotChatAssistantMessage({ message, messages, isRunning, onThumbsUp,
|
|
|
6191
5968
|
message,
|
|
6192
5969
|
messages
|
|
6193
5970
|
});
|
|
5971
|
+
const hasContent = !!(message.content && message.content.trim().length > 0);
|
|
6194
5972
|
const isLatestAssistantMessage = message.role === "assistant" && messages?.[messages.length - 1]?.id === message.id;
|
|
6195
|
-
const shouldShowToolbar = toolbarVisible && (hasContent ||
|
|
5973
|
+
const shouldShowToolbar = toolbarVisible && (hasContent || isInspectorEnabled) && !(isRunning && isLatestAssistantMessage);
|
|
6196
5974
|
if (children) return /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
|
|
6197
5975
|
"data-copilotkit": true,
|
|
6198
5976
|
style: { display: "contents" },
|
|
@@ -6202,7 +5980,6 @@ function CopilotChatAssistantMessage({ message, messages, isRunning, onThumbsUp,
|
|
|
6202
5980
|
toolCallsView: boundToolCallsView,
|
|
6203
5981
|
copyButton: boundCopyButton,
|
|
6204
5982
|
inspectorButton: boundInspectorButton,
|
|
6205
|
-
saveSnippetButton: boundSaveSnippetButton,
|
|
6206
5983
|
thumbsUpButton: boundThumbsUpButton,
|
|
6207
5984
|
thumbsDownButton: boundThumbsDownButton,
|
|
6208
5985
|
readAloudButton: boundReadAloudButton,
|
|
@@ -6349,7 +6126,7 @@ function CopilotKitColoredIcon() {
|
|
|
6349
6126
|
className: (0, tailwind_merge.twMerge)("cpk:w-full cpk:bg-transparent cpk:flex cpk:items-center cpk:-ml-[5px] cpk:-mt-[0px]", className),
|
|
6350
6127
|
...props
|
|
6351
6128
|
});
|
|
6352
|
-
const ToolbarButton = _CopilotChatAssistantMessage.ToolbarButton = ({ title, tooltip, children, ...props }) => {
|
|
6129
|
+
const ToolbarButton = _CopilotChatAssistantMessage.ToolbarButton = ({ title, tooltip, tooltipClassName, children, ...props }) => {
|
|
6353
6130
|
return /* @__PURE__ */ (0, react_jsx_runtime.jsxs)(Tooltip, { children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)(TooltipTrigger, {
|
|
6354
6131
|
asChild: true,
|
|
6355
6132
|
children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(Button, {
|
|
@@ -6361,6 +6138,7 @@ function CopilotKitColoredIcon() {
|
|
|
6361
6138
|
})
|
|
6362
6139
|
}), /* @__PURE__ */ (0, react_jsx_runtime.jsx)(TooltipContent, {
|
|
6363
6140
|
side: "bottom",
|
|
6141
|
+
className: tooltipClassName,
|
|
6364
6142
|
children: tooltip ?? /* @__PURE__ */ (0, react_jsx_runtime.jsx)("p", { children: title })
|
|
6365
6143
|
})] });
|
|
6366
6144
|
};
|
|
@@ -6394,29 +6172,30 @@ function CopilotKitColoredIcon() {
|
|
|
6394
6172
|
children: copied ? /* @__PURE__ */ (0, react_jsx_runtime.jsx)(lucide_react.Check, { className: "cpk:size-[18px]" }) : /* @__PURE__ */ (0, react_jsx_runtime.jsx)(lucide_react.Copy, { className: "cpk:size-[18px]" })
|
|
6395
6173
|
});
|
|
6396
6174
|
};
|
|
6397
|
-
_CopilotChatAssistantMessage.InspectorButton = ({ title, ...props }) => {
|
|
6175
|
+
_CopilotChatAssistantMessage.InspectorButton = ({ title, className, ...props }) => {
|
|
6398
6176
|
const labels = useCopilotChatConfiguration()?.labels ?? CopilotChatDefaultLabels;
|
|
6399
6177
|
const primaryLabel = title || labels.assistantMessageToolbarInspectorLabel;
|
|
6400
|
-
const
|
|
6401
|
-
|
|
6402
|
-
return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(ToolbarButton, {
|
|
6178
|
+
const accessibleLabel = `${primaryLabel} (local only)`;
|
|
6179
|
+
return /* @__PURE__ */ (0, react_jsx_runtime.jsxs)(ToolbarButton, {
|
|
6403
6180
|
"data-testid": "copilot-inspector-button",
|
|
6404
6181
|
title: accessibleLabel,
|
|
6405
|
-
|
|
6406
|
-
|
|
6407
|
-
|
|
6408
|
-
className: "cpk:text-[10px] cpk:opacity-65",
|
|
6409
|
-
children: localOnlyLabel
|
|
6410
|
-
})]
|
|
6411
|
-
}),
|
|
6182
|
+
className: (0, tailwind_merge.twMerge)("cpk:w-auto cpk:gap-1.5 cpk:px-2", className),
|
|
6183
|
+
tooltipClassName: "cpk:max-w-64 cpk:text-left cpk:leading-4",
|
|
6184
|
+
tooltip: "View this message in the Inspector to get more information. This button and the inspector only display during local development (localhost, dev env).",
|
|
6412
6185
|
...props,
|
|
6413
|
-
children:
|
|
6186
|
+
children: [
|
|
6187
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsx)(CopilotKitColoredIcon, {}),
|
|
6188
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
|
|
6189
|
+
className: "cpk:font-medium",
|
|
6190
|
+
children: primaryLabel
|
|
6191
|
+
}),
|
|
6192
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
|
|
6193
|
+
className: "cpk:text-xs cpk:text-muted-foreground",
|
|
6194
|
+
children: "(local only)"
|
|
6195
|
+
})
|
|
6196
|
+
]
|
|
6414
6197
|
});
|
|
6415
6198
|
};
|
|
6416
|
-
_CopilotChatAssistantMessage.SaveSnippetButton = (props) => /* @__PURE__ */ (0, react_jsx_runtime.jsx)(SaveSnippetIconButton, {
|
|
6417
|
-
"data-testid": "copilot-save-snippet-button",
|
|
6418
|
-
...props
|
|
6419
|
-
});
|
|
6420
6199
|
_CopilotChatAssistantMessage.ThumbsUpButton = ({ title, ...props }) => {
|
|
6421
6200
|
const labels = useCopilotChatConfiguration()?.labels ?? CopilotChatDefaultLabels;
|
|
6422
6201
|
return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(ToolbarButton, {
|
|
@@ -6458,7 +6237,6 @@ CopilotChatAssistantMessage.MarkdownRenderer.displayName = "CopilotChatAssistant
|
|
|
6458
6237
|
CopilotChatAssistantMessage.Toolbar.displayName = "CopilotChatAssistantMessage.Toolbar";
|
|
6459
6238
|
CopilotChatAssistantMessage.CopyButton.displayName = "CopilotChatAssistantMessage.CopyButton";
|
|
6460
6239
|
CopilotChatAssistantMessage.InspectorButton.displayName = "CopilotChatAssistantMessage.InspectorButton";
|
|
6461
|
-
CopilotChatAssistantMessage.SaveSnippetButton.displayName = "CopilotChatAssistantMessage.SaveSnippetButton";
|
|
6462
6240
|
CopilotChatAssistantMessage.ThumbsUpButton.displayName = "CopilotChatAssistantMessage.ThumbsUpButton";
|
|
6463
6241
|
CopilotChatAssistantMessage.ThumbsDownButton.displayName = "CopilotChatAssistantMessage.ThumbsDownButton";
|
|
6464
6242
|
CopilotChatAssistantMessage.ReadAloudButton.displayName = "CopilotChatAssistantMessage.ReadAloudButton";
|
|
@@ -6829,8 +6607,6 @@ function CopilotChatReasoningMessage({ message, messages, isRunning, header, con
|
|
|
6829
6607
|
const isLatest = messages?.[messages.length - 1]?.id === message.id;
|
|
6830
6608
|
const isStreaming = !!(isRunning && isLatest);
|
|
6831
6609
|
const hasContent = !!(message.content && message.content.length > 0);
|
|
6832
|
-
const { isLocalInspectorEnabled, saveEventSnippet } = useCopilotKitInspector();
|
|
6833
|
-
const chatConfiguration = useCopilotChatConfiguration();
|
|
6834
6610
|
const startTimeRef = (0, react.useRef)(null);
|
|
6835
6611
|
const [elapsed, setElapsed] = (0, react.useState)(0);
|
|
6836
6612
|
(0, react.useEffect)(() => {
|
|
@@ -6890,16 +6666,7 @@ function CopilotChatReasoningMessage({ message, messages, isRunning, header, con
|
|
|
6890
6666
|
className: (0, tailwind_merge.twMerge)("cpk:my-1", className),
|
|
6891
6667
|
"data-message-id": message.id,
|
|
6892
6668
|
...props,
|
|
6893
|
-
children: [
|
|
6894
|
-
className: "cpk:flex cpk:items-center cpk:gap-1",
|
|
6895
|
-
children: [boundHeader, isLocalInspectorEnabled && hasContent && /* @__PURE__ */ (0, react_jsx_runtime.jsx)(CopilotChatAssistantMessage_default.SaveSnippetButton, { onClick: () => void saveEventSnippet({
|
|
6896
|
-
kind: "reasoning",
|
|
6897
|
-
messageId: message.id,
|
|
6898
|
-
content: message.content ?? "",
|
|
6899
|
-
threadId: chatConfiguration?.threadId,
|
|
6900
|
-
agentId: chatConfiguration?.agentId
|
|
6901
|
-
}) })]
|
|
6902
|
-
}), boundToggle]
|
|
6669
|
+
children: [boundHeader, boundToggle]
|
|
6903
6670
|
});
|
|
6904
6671
|
}
|
|
6905
6672
|
(function(_CopilotChatReasoningMessage) {
|
|
@@ -7418,33 +7185,8 @@ const MemoizedUserMessage = react.default.memo(function MemoizedUserMessage({ me
|
|
|
7418
7185
|
/**
|
|
7419
7186
|
* Memoized wrapper for activity messages to prevent re-renders when other messages change.
|
|
7420
7187
|
*/
|
|
7421
|
-
function ActivitySnippetChrome({ message, children }) {
|
|
7422
|
-
const { isLocalInspectorEnabled, saveEventSnippet } = useCopilotKitInspector();
|
|
7423
|
-
const chatConfiguration = useCopilotChatConfiguration();
|
|
7424
|
-
if (!(isLocalInspectorEnabled && (message.activityType === "a2ui-surface" || message.activityType === "open-generative-ui"))) return children;
|
|
7425
|
-
const primaryLabel = (chatConfiguration?.labels ?? CopilotChatDefaultLabels).assistantMessageToolbarSaveSnippetLabel;
|
|
7426
|
-
return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(SaveSnippetBesideChrome, {
|
|
7427
|
-
showSave: true,
|
|
7428
|
-
saveButton: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(SaveSnippetIconButton, {
|
|
7429
|
-
"data-testid": "copilot-activity-save-snippet-button",
|
|
7430
|
-
title: primaryLabel,
|
|
7431
|
-
onClick: () => void saveEventSnippet({
|
|
7432
|
-
kind: "activity",
|
|
7433
|
-
messageId: message.id,
|
|
7434
|
-
activityType: message.activityType,
|
|
7435
|
-
content: message.content,
|
|
7436
|
-
threadId: chatConfiguration?.threadId,
|
|
7437
|
-
agentId: chatConfiguration?.agentId
|
|
7438
|
-
})
|
|
7439
|
-
}),
|
|
7440
|
-
children
|
|
7441
|
-
});
|
|
7442
|
-
}
|
|
7443
7188
|
const MemoizedActivityMessage = react.default.memo(function MemoizedActivityMessage({ message, renderActivityMessage }) {
|
|
7444
|
-
return
|
|
7445
|
-
message,
|
|
7446
|
-
children: renderActivityMessage(message)
|
|
7447
|
-
});
|
|
7189
|
+
return renderActivityMessage(message);
|
|
7448
7190
|
}, (prevProps, nextProps) => {
|
|
7449
7191
|
if (prevProps.message.id !== nextProps.message.id) return false;
|
|
7450
7192
|
if (prevProps.message.activityType !== nextProps.message.activityType) return false;
|
|
@@ -11799,20 +11541,42 @@ function CoAgentStateRenderBridge(props) {
|
|
|
11799
11541
|
|
|
11800
11542
|
//#endregion
|
|
11801
11543
|
//#region src/v1-deprecated/components/CopilotListeners.tsx
|
|
11802
|
-
|
|
11803
|
-
|
|
11804
|
-
const
|
|
11544
|
+
function isPredictStateTool(value) {
|
|
11545
|
+
if (value === null || typeof value !== "object") return false;
|
|
11546
|
+
const config = value;
|
|
11547
|
+
return typeof config.tool === "string" && typeof config.state_key === "string" && (config.tool_argument === void 0 || typeof config.tool_argument === "string");
|
|
11548
|
+
}
|
|
11549
|
+
function getPredictStateUpdate(config, toolCallName, partialToolCallArgs) {
|
|
11550
|
+
if (config.tool !== toolCallName) return void 0;
|
|
11551
|
+
const emittedState = typeof partialToolCallArgs === "string" ? (0, _copilotkit_shared.partialJSONParse)(partialToolCallArgs) : partialToolCallArgs;
|
|
11552
|
+
if (emittedState === null || typeof emittedState !== "object") return;
|
|
11553
|
+
if (config.tool_argument) {
|
|
11554
|
+
if (!(config.tool_argument in emittedState)) return void 0;
|
|
11555
|
+
return { [config.state_key]: emittedState[config.tool_argument] };
|
|
11556
|
+
}
|
|
11557
|
+
return { [config.state_key]: emittedState };
|
|
11558
|
+
}
|
|
11559
|
+
function createPredictStateSubscriber(agent, predictStateToolsRef) {
|
|
11560
|
+
return {
|
|
11805
11561
|
onCustomEvent: ({ event }) => {
|
|
11806
|
-
if (event.name === "PredictState") predictStateToolsRef.current = event.value;
|
|
11562
|
+
if (event.name === "PredictState") predictStateToolsRef.current = Array.isArray(event.value) ? event.value.filter(isPredictStateTool) : [];
|
|
11807
11563
|
},
|
|
11808
11564
|
onToolCallArgsEvent: ({ partialToolCallArgs, toolCallName }) => {
|
|
11809
|
-
|
|
11810
|
-
|
|
11811
|
-
const
|
|
11812
|
-
|
|
11565
|
+
const updates = {};
|
|
11566
|
+
predictStateToolsRef.current.forEach((config) => {
|
|
11567
|
+
const update = getPredictStateUpdate(config, toolCallName, partialToolCallArgs);
|
|
11568
|
+
if (update) Object.assign(updates, update);
|
|
11569
|
+
});
|
|
11570
|
+
if (Object.keys(updates).length > 0) agent.setState({
|
|
11571
|
+
...agent.state,
|
|
11572
|
+
...updates
|
|
11813
11573
|
});
|
|
11814
11574
|
}
|
|
11815
|
-
}
|
|
11575
|
+
};
|
|
11576
|
+
}
|
|
11577
|
+
const usePredictStateSubscription = (agent) => {
|
|
11578
|
+
const predictStateToolsRef = (0, react.useRef)([]);
|
|
11579
|
+
const getSubscriber = (0, react.useCallback)((subscriptionAgent) => createPredictStateSubscriber(subscriptionAgent, predictStateToolsRef), []);
|
|
11816
11580
|
(0, react.useEffect)(() => {
|
|
11817
11581
|
if (!agent) return;
|
|
11818
11582
|
const subscriber = getSubscriber(agent);
|
|
@@ -11871,7 +11635,6 @@ function CopilotListeners() {
|
|
|
11871
11635
|
//#region src/v1-deprecated/components/copilot-provider/copilotkit.tsx
|
|
11872
11636
|
function CopilotKit({ children, ...props }) {
|
|
11873
11637
|
const enabled = shouldShowDevConsole(props.showDevConsole);
|
|
11874
|
-
const showInspector = shouldShowDevConsole(props.enableInspector);
|
|
11875
11638
|
const publicApiKey = props.publicApiKey || props.publicLicenseKey;
|
|
11876
11639
|
const renderArr = (0, react.useMemo)(() => [{ render: CoAgentStateRenderBridge }], []);
|
|
11877
11640
|
const { onError: _onError, ...v2Props } = props;
|
|
@@ -11884,7 +11647,7 @@ function CopilotKit({ children, ...props }) {
|
|
|
11884
11647
|
threadId: props.threadId,
|
|
11885
11648
|
children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(CopilotKitProvider, {
|
|
11886
11649
|
...v2Props,
|
|
11887
|
-
|
|
11650
|
+
enableInspector: props.enableInspector,
|
|
11888
11651
|
renderCustomMessages: renderArr,
|
|
11889
11652
|
children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(CopilotKitInternal, {
|
|
11890
11653
|
...props,
|
|
@@ -12876,4 +12639,4 @@ Object.defineProperty(exports, 'ɵrunMcpFollowUp', {
|
|
|
12876
12639
|
return ɵrunMcpFollowUp;
|
|
12877
12640
|
}
|
|
12878
12641
|
});
|
|
12879
|
-
//# sourceMappingURL=copilotkit-
|
|
12642
|
+
//# sourceMappingURL=copilotkit-BPeh62mW.cjs.map
|