@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.
Files changed (40) hide show
  1. package/dist/{copilotkit-Dr0speVK.cjs → copilotkit-BPeh62mW.cjs} +104 -341
  2. package/dist/copilotkit-BPeh62mW.cjs.map +1 -0
  3. package/dist/{copilotkit-Hl1t9Y1v.d.cts → copilotkit-CrNUgJiq.d.cts} +18 -21
  4. package/dist/copilotkit-CrNUgJiq.d.cts.map +1 -0
  5. package/dist/{copilotkit-DYKpg4pD.d.mts → copilotkit-DgO31tBq.d.mts} +18 -21
  6. package/dist/copilotkit-DgO31tBq.d.mts.map +1 -0
  7. package/dist/{copilotkit-Dr6g885f.mjs → copilotkit-JdHy0xdu.mjs} +106 -343
  8. package/dist/copilotkit-JdHy0xdu.mjs.map +1 -0
  9. package/dist/index.cjs +1 -1
  10. package/dist/index.d.cts +1 -1
  11. package/dist/index.d.mts +1 -1
  12. package/dist/index.mjs +1 -1
  13. package/dist/index.umd.js +77 -100
  14. package/dist/index.umd.js.map +1 -1
  15. package/dist/v2/headless.cjs +1 -2
  16. package/dist/v2/headless.cjs.map +1 -1
  17. package/dist/v2/headless.d.cts +0 -1
  18. package/dist/v2/headless.d.cts.map +1 -1
  19. package/dist/v2/headless.d.mts +0 -1
  20. package/dist/v2/headless.d.mts.map +1 -1
  21. package/dist/v2/headless.mjs +1 -2
  22. package/dist/v2/headless.mjs.map +1 -1
  23. package/dist/v2/index.cjs +1 -1
  24. package/dist/v2/index.css +1 -1
  25. package/dist/v2/index.d.cts +1 -1
  26. package/dist/v2/index.d.mts +1 -1
  27. package/dist/v2/index.mjs +1 -1
  28. package/dist/v2/index.umd.js +107 -343
  29. package/dist/v2/index.umd.js.map +1 -1
  30. package/package.json +7 -8
  31. package/skills/react-core/SKILL.md +5 -3
  32. package/skills/react-core/references/agent-access.md +68 -1
  33. package/skills/react-core/references/debug-mode.md +21 -34
  34. package/skills/react-core/references/switching-agents-recipes.md +1 -0
  35. package/skills/react-core/references/switching-agents.md +9 -0
  36. package/skills/react-core/references/threads.md +65 -0
  37. package/dist/copilotkit-DYKpg4pD.d.mts.map +0 -1
  38. package/dist/copilotkit-Dr0speVK.cjs.map +0 -1
  39. package/dist/copilotkit-Dr6g885f.mjs.map +0 -1
  40. package/dist/copilotkit-Hl1t9Y1v.d.cts.map +0 -1
@@ -1,10 +1,10 @@
1
1
  "use client";
2
2
 
3
3
  (function(global, factory) {
4
- typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('./index.css'), require('@copilotkit/core'), require('@ag-ui/client'), require('react'), require('tailwind-merge'), require('lucide-react'), require('@copilotkit/shared'), require('react/jsx-runtime'), require('@radix-ui/react-slot'), require('class-variance-authority'), require('clsx'), require('@radix-ui/react-tooltip'), require('@radix-ui/react-dropdown-menu'), require('streamdown'), require('zod'), require('@lit-labs/react'), require('@copilotkit/a2ui-renderer'), require('zod-to-json-schema'), require('react-dom'), require('@tanstack/react-virtual'), require('use-stick-to-bottom'), require('@copilotkit/web-components/threads-drawer')) :
5
- typeof define === 'function' && define.amd ? define(['exports', './index.css', '@copilotkit/core', '@ag-ui/client', 'react', 'tailwind-merge', 'lucide-react', '@copilotkit/shared', 'react/jsx-runtime', '@radix-ui/react-slot', 'class-variance-authority', 'clsx', '@radix-ui/react-tooltip', '@radix-ui/react-dropdown-menu', 'streamdown', 'zod', '@lit-labs/react', '@copilotkit/a2ui-renderer', 'zod-to-json-schema', 'react-dom', '@tanstack/react-virtual', 'use-stick-to-bottom', '@copilotkit/web-components/threads-drawer'], factory) :
6
- (global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory((global.CopilotKitReactCoreV2 = {}), global.src_v2_index_css,global.CopilotKitCore,global.AgUIClient,global.React,global.tailwindMerge,global.lucideReact,global.CopilotKitShared,global.ReactJsxRuntime,global.RadixReactSlot,global.classVarianceAuthority,global.clsx,global.RadixReactTooltip,global.RadixReactDropdownMenu,global.streamdown,global.Zod,global.LitLabsReact,global.CopilotKitA2UIRenderer,global.zod_to_json_schema,global.ReactDOM,global._tanstack_react_virtual,global.useStickToBottom,global._copilotkit_web_components_threads_drawer));
7
- })(this, function(exports, src_v2_index_css, _copilotkit_core, _ag_ui_client, react, tailwind_merge, lucide_react, _copilotkit_shared, react_jsx_runtime, _radix_ui_react_slot, class_variance_authority, clsx, _radix_ui_react_tooltip, _radix_ui_react_dropdown_menu, streamdown, zod, _lit_labs_react, _copilotkit_a2ui_renderer, zod_to_json_schema, react_dom, _tanstack_react_virtual, use_stick_to_bottom, _copilotkit_web_components_threads_drawer) {
4
+ typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('./index.css'), require('@copilotkit/core'), require('@ag-ui/client'), require('react'), require('tailwind-merge'), require('lucide-react'), require('@copilotkit/shared'), require('react/jsx-runtime'), require('@radix-ui/react-slot'), require('class-variance-authority'), require('clsx'), require('@radix-ui/react-tooltip'), require('@radix-ui/react-dropdown-menu'), require('streamdown'), require('zod'), require('@copilotkit/a2ui-renderer'), require('zod-to-json-schema'), require('react-dom'), require('@tanstack/react-virtual'), require('use-stick-to-bottom'), require('@copilotkit/web-components/threads-drawer')) :
5
+ typeof define === 'function' && define.amd ? define(['exports', './index.css', '@copilotkit/core', '@ag-ui/client', 'react', 'tailwind-merge', 'lucide-react', '@copilotkit/shared', 'react/jsx-runtime', '@radix-ui/react-slot', 'class-variance-authority', 'clsx', '@radix-ui/react-tooltip', '@radix-ui/react-dropdown-menu', 'streamdown', 'zod', '@copilotkit/a2ui-renderer', 'zod-to-json-schema', 'react-dom', '@tanstack/react-virtual', 'use-stick-to-bottom', '@copilotkit/web-components/threads-drawer'], factory) :
6
+ (global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory((global.CopilotKitReactCoreV2 = {}), global.src_v2_index_css,global.CopilotKitCore,global.AgUIClient,global.React,global.tailwindMerge,global.lucideReact,global.CopilotKitShared,global.ReactJsxRuntime,global.RadixReactSlot,global.classVarianceAuthority,global.clsx,global.RadixReactTooltip,global.RadixReactDropdownMenu,global.streamdown,global.Zod,global.CopilotKitA2UIRenderer,global.zod_to_json_schema,global.ReactDOM,global._tanstack_react_virtual,global.useStickToBottom,global._copilotkit_web_components_threads_drawer));
7
+ })(this, function(exports, src_v2_index_css, _copilotkit_core, _ag_ui_client, react, tailwind_merge, lucide_react, _copilotkit_shared, react_jsx_runtime, _radix_ui_react_slot, class_variance_authority, clsx, _radix_ui_react_tooltip, _radix_ui_react_dropdown_menu, streamdown, zod, _copilotkit_a2ui_renderer, zod_to_json_schema, react_dom, _tanstack_react_virtual, use_stick_to_bottom, _copilotkit_web_components_threads_drawer) {
8
8
  Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
9
9
  //#region \0rolldown/runtime.js
10
10
  var __create = Object.create;
@@ -91,8 +91,7 @@ _radix_ui_react_dropdown_menu = __toESM(_radix_ui_react_dropdown_menu);
91
91
  assistantMessageToolbarCopyCodeCopiedLabel: "Copied",
92
92
  assistantMessageToolbarCopyMessageLabel: "Copy",
93
93
  assistantMessageToolbarInspectorLabel: "View in Inspector",
94
- assistantMessageToolbarInspectorLocalOnlyLabel: "Local Only",
95
- assistantMessageToolbarSaveSnippetLabel: "Save as snippet",
94
+ assistantMessageToolbarInspectorLocalOnlyLabel: "Development Only",
96
95
  assistantMessageToolbarThumbsUpLabel: "Good response",
97
96
  assistantMessageToolbarThumbsDownLabel: "Bad response",
98
97
  assistantMessageToolbarReadAloudLabel: "Read aloud",
@@ -1637,32 +1636,43 @@ _radix_ui_react_dropdown_menu = __toESM(_radix_ui_react_dropdown_menu);
1637
1636
 
1638
1637
  //#endregion
1639
1638
  //#region src/v2/components/CopilotKitInspector.tsx
1640
- const CopilotKitInspector = ({ core, openRequest, ...rest }) => {
1641
- const [InspectorComponent, setInspectorComponent] = react.useState(null);
1639
+ const CopilotKitInspector = ({ core, openRequest }) => {
1640
+ const mountRef = react.useRef(null);
1642
1641
  const inspectorRef = react.useRef(null);
1642
+ const latestCoreRef = react.useRef(core ?? null);
1643
+ const latestOpenRequestRef = react.useRef(openRequest);
1644
+ latestCoreRef.current = core ?? null;
1645
+ latestOpenRequestRef.current = openRequest;
1643
1646
  react.useEffect(() => {
1644
1647
  let mounted = true;
1648
+ let inspector = null;
1645
1649
  import("@copilotkit/web-inspector").then((mod) => {
1650
+ if (!mounted || !mountRef.current) return;
1646
1651
  mod.defineWebInspector?.();
1647
- const Component = (0, _lit_labs_react.createComponent)({
1648
- tagName: mod.WEB_INSPECTOR_TAG,
1649
- elementClass: mod.WebInspectorElement,
1650
- react
1651
- });
1652
- if (mounted) setInspectorComponent(() => Component);
1652
+ inspector = mountRef.current.ownerDocument.createElement(mod.WEB_INSPECTOR_TAG);
1653
+ mod.configureWebInspectorElement(inspector, latestCoreRef.current);
1654
+ mountRef.current.appendChild(inspector);
1655
+ inspectorRef.current = inspector;
1656
+ const request = latestOpenRequestRef.current;
1657
+ if (request) inspector.openInspector("message_toolbar", request);
1658
+ }).catch((error) => {
1659
+ console.error("Failed to load CopilotKit inspector:", error);
1653
1660
  });
1654
1661
  return () => {
1655
1662
  mounted = false;
1663
+ inspector?.remove();
1664
+ if (inspectorRef.current === inspector) inspectorRef.current = null;
1656
1665
  };
1657
1666
  }, []);
1667
+ react.useEffect(() => {
1668
+ if (inspectorRef.current) inspectorRef.current.core = core ?? null;
1669
+ }, [core]);
1658
1670
  react.useEffect(() => {
1659
1671
  if (openRequest) inspectorRef.current?.openInspector("message_toolbar", openRequest);
1660
- }, [InspectorComponent, openRequest]);
1661
- if (!InspectorComponent) return null;
1662
- return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(InspectorComponent, {
1663
- ref: inspectorRef,
1664
- ...rest,
1665
- core: core ?? null
1672
+ }, [openRequest]);
1673
+ return /* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
1674
+ ref: mountRef,
1675
+ style: { display: "contents" }
1666
1676
  });
1667
1677
  };
1668
1678
  CopilotKitInspector.displayName = "CopilotKitInspector";
@@ -1670,9 +1680,8 @@ _radix_ui_react_dropdown_menu = __toESM(_radix_ui_react_dropdown_menu);
1670
1680
  //#endregion
1671
1681
  //#region src/v2/components/CopilotKitInspectorContext.tsx
1672
1682
  const CopilotKitInspectorContext = react.createContext({
1673
- isLocalInspectorEnabled: false,
1674
- openInspector: () => void 0,
1675
- saveEventSnippet: async () => void 0
1683
+ isInspectorEnabled: false,
1684
+ openInspector: () => void 0
1676
1685
  });
1677
1686
  const CopilotKitInspectorContextProvider = CopilotKitInspectorContext.Provider;
1678
1687
  function useCopilotKitInspector() {
@@ -2486,7 +2495,6 @@ window.parent.postMessage({jsonrpc:"2.0",method:"ui/notifications/sandbox-proxy-
2486
2495
  const OpenGenerativeUIActivityRendererInner = react.default.memo(function OpenGenerativeUIActivityRendererInner({ content }) {
2487
2496
  const initialHeight = content.initialHeight ?? 200;
2488
2497
  const [autoHeight, setAutoHeight] = (0, react.useState)(null);
2489
- const [sandboxReady, setSandboxReady] = (0, react.useState)(false);
2490
2498
  const sandboxFunctions = useSandboxFunctions();
2491
2499
  const localApi = (0, react.useMemo)(() => {
2492
2500
  const api = {};
@@ -2588,7 +2596,6 @@ window.parent.postMessage({jsonrpc:"2.0",method:"ui/notifications/sandbox-proxy-
2588
2596
  sandbox.promise.then(() => {
2589
2597
  if (cancelled) return;
2590
2598
  sandboxReadyRef.current = true;
2591
- setSandboxReady(true);
2592
2599
  sandbox.run(`
2593
2600
  var s = document.createElement('style');
2594
2601
  s.textContent = 'html, body { overflow: hidden !important; }';
@@ -2613,7 +2620,6 @@ window.parent.postMessage({jsonrpc:"2.0",method:"ui/notifications/sandbox-proxy-
2613
2620
  sandboxRef.current = null;
2614
2621
  }
2615
2622
  sandboxReadyRef.current = false;
2616
- setSandboxReady(false);
2617
2623
  setAutoHeight(null);
2618
2624
  };
2619
2625
  }, [
@@ -2644,7 +2650,7 @@ window.parent.postMessage({jsonrpc:"2.0",method:"ui/notifications/sandbox-proxy-
2644
2650
  const generationDone = content.generating === false;
2645
2651
  (0, react.useEffect)(() => {
2646
2652
  const sandbox = sandboxRef.current;
2647
- if (!generationDone || !sandboxReady || !sandbox) return;
2653
+ if (!generationDone || !sandbox) return;
2648
2654
  let handled = false;
2649
2655
  const onMessage = (e) => {
2650
2656
  if (handled) return;
@@ -2673,7 +2679,7 @@ window.parent.postMessage({jsonrpc:"2.0",method:"ui/notifications/sandbox-proxy-
2673
2679
  return () => {
2674
2680
  window.removeEventListener("message", onMessage);
2675
2681
  };
2676
- }, [generationDone, sandboxReady]);
2682
+ }, [generationDone]);
2677
2683
  const height = autoHeight ?? initialHeight;
2678
2684
  const isGenerating = content.generating !== false;
2679
2685
  return /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
@@ -3528,9 +3534,15 @@ window.parent.postMessage({jsonrpc:"2.0",method:"ui/notifications/sandbox-proxy-
3528
3534
  }, [value, warningMessage]);
3529
3535
  return value;
3530
3536
  }
3531
- const CopilotKitProvider = ({ children, runtimeUrl, headers: headersProp = EMPTY_HEADERS, credentials, publicApiKey, publicLicenseKey, licenseToken, properties = EMPTY_PROPERTIES, agents__unsafe_dev_only: agents = EMPTY_AGENTS, selfManagedAgents = EMPTY_AGENTS, renderToolCalls, renderActivityMessages, renderCustomMessages, frontendTools, humanInTheLoop, openGenerativeUI, showDevConsole = false, useSingleEndpoint, onError, a2ui, defaultThrottleMs, inspectorDefaultAnchor, debug }) => {
3537
+ const CopilotKitProvider = ({ children, runtimeUrl, headers: headersProp = EMPTY_HEADERS, credentials, publicApiKey, publicLicenseKey, licenseToken, properties = EMPTY_PROPERTIES, agents__unsafe_dev_only: agents = EMPTY_AGENTS, selfManagedAgents = EMPTY_AGENTS, renderToolCalls, renderActivityMessages, renderCustomMessages, frontendTools, humanInTheLoop, openGenerativeUI, enableInspector, useSingleEndpoint, onError, a2ui, defaultThrottleMs, debug }) => {
3532
3538
  const [shouldRenderInspector, setShouldRenderInspector] = (0, react.useState)(false);
3533
- const [isLocalInspectorEnabled, setIsLocalInspectorEnabled] = (0, react.useState)(false);
3539
+ (0, react.useEffect)(() => {
3540
+ setShouldRenderInspector((0, _copilotkit_shared.shouldEnableInspector)({
3541
+ enableInspector,
3542
+ isBrowser: true,
3543
+ isDevelopment: process.env.NODE_ENV === "development"
3544
+ }));
3545
+ }, [enableInspector]);
3534
3546
  const [inspectorOpenRequest, setInspectorOpenRequest] = (0, react.useState)(null);
3535
3547
  const [runtimeA2UIEnabled, setRuntimeA2UIEnabled] = (0, react.useState)(false);
3536
3548
  const [runtimeOpenGenUIEnabled, setRuntimeOpenGenUIEnabled] = (0, react.useState)(false);
@@ -3539,68 +3551,13 @@ window.parent.postMessage({jsonrpc:"2.0",method:"ui/notifications/sandbox-proxy-
3539
3551
  const a2uiCatalogProvided = !!a2ui?.catalog;
3540
3552
  const a2uiActive = runtimeA2UIEnabled || a2uiCatalogProvided;
3541
3553
  const [runtimeLicenseStatus, setRuntimeLicenseStatus] = (0, react.useState)(void 0);
3542
- (0, react.useEffect)(() => {
3543
- if (typeof window === "undefined") return;
3544
- const isLocalhost = new Set(["localhost", "127.0.0.1"]).has(window.location?.hostname ?? "");
3545
- const canShowLocalInspectorAction = process.env.NODE_ENV === "development" && isLocalhost;
3546
- if (showDevConsole === true) {
3547
- setShouldRenderInspector(true);
3548
- setIsLocalInspectorEnabled(canShowLocalInspectorAction);
3549
- } else if (showDevConsole === "auto") if (isLocalhost) {
3550
- setShouldRenderInspector(true);
3551
- setIsLocalInspectorEnabled(canShowLocalInspectorAction);
3552
- } else {
3553
- setShouldRenderInspector(false);
3554
- setIsLocalInspectorEnabled(false);
3555
- }
3556
- else {
3557
- setShouldRenderInspector(false);
3558
- setIsLocalInspectorEnabled(false);
3559
- }
3560
- }, [showDevConsole]);
3561
3554
  const requestInspectorOpen = (0, react.useCallback)((request) => {
3562
3555
  setInspectorOpenRequest({ ...request });
3563
3556
  }, []);
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]);
3595
3557
  const inspectorContextValue = (0, react.useMemo)(() => ({
3596
- isLocalInspectorEnabled,
3597
- openInspector: requestInspectorOpen,
3598
- saveEventSnippet
3599
- }), [
3600
- isLocalInspectorEnabled,
3601
- requestInspectorOpen,
3602
- saveEventSnippet
3603
- ]);
3558
+ isInspectorEnabled: shouldRenderInspector,
3559
+ openInspector: requestInspectorOpen
3560
+ }), [shouldRenderInspector, requestInspectorOpen]);
3604
3561
  const renderToolCallsList = useStableArrayProp(renderToolCalls, "renderToolCalls must be a stable array. If you want to dynamically add or remove tools, use `useFrontendTool` instead.", (initial, next) => {
3605
3562
  const key = (rc) => `${rc?.agentId ?? ""}:${rc?.name ?? ""}`;
3606
3563
  const setFrom = (arr) => new Set(arr.map(key));
@@ -3941,7 +3898,6 @@ window.parent.postMessage({jsonrpc:"2.0",method:"ui/notifications/sandbox-proxy-
3941
3898
  value: inspectorContextValue,
3942
3899
  children: [children, shouldRenderInspector ? /* @__PURE__ */ (0, react_jsx_runtime.jsx)(CopilotKitInspector, {
3943
3900
  core: copilotkit,
3944
- defaultAnchor: inspectorDefaultAnchor,
3945
3901
  openRequest: inspectorOpenRequest
3946
3902
  }) : null]
3947
3903
  }),
@@ -5977,191 +5933,25 @@ window.parent.postMessage({jsonrpc:"2.0",method:"ui/notifications/sandbox-proxy-
5977
5933
  });
5978
5934
  }
5979
5935
 
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
-
6098
5936
  //#endregion
6099
5937
  //#region src/v2/components/chat/CopilotChatToolCallsView.tsx
6100
5938
  function CopilotChatToolCallsView({ message, messages = [] }) {
6101
5939
  const renderToolCall = useRenderToolCall();
6102
- const { isLocalInspectorEnabled, saveEventSnippet } = useCopilotKitInspector();
6103
- const chatConfiguration = useCopilotChatConfiguration();
6104
- const labels = chatConfiguration?.labels ?? CopilotChatDefaultLabels;
6105
5940
  if (!message.toolCalls || message.toolCalls.length === 0) return null;
6106
5941
  return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(react_jsx_runtime.Fragment, { children: message.toolCalls.map((toolCall) => {
6107
- const rendered = renderToolCall({
5942
+ const toolMessage = messages.find((m) => m.role === "tool" && m.toolCallId === toolCall.id);
5943
+ return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(react.default.Fragment, { children: renderToolCall({
6108
5944
  toolCall,
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);
5945
+ toolMessage
5946
+ }) }, toolCall.id);
6126
5947
  }) });
6127
5948
  }
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
- }
6159
5949
 
6160
5950
  //#endregion
6161
5951
  //#region src/v2/components/chat/CopilotChatAssistantMessage.tsx
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 }) {
5952
+ function CopilotChatAssistantMessage({ message, messages, isRunning, onThumbsUp, onThumbsDown, onReadAloud, onRegenerate, additionalToolbarItems, toolbarVisible = true, markdownRenderer, toolbar, copyButton, inspectorButton, thumbsUpButton, thumbsDownButton, readAloudButton, regenerateButton, toolCallsView, children, className, ...props }) {
6163
5953
  useKatexStyles();
6164
- const { isLocalInspectorEnabled, openInspector, saveEventSnippet } = useCopilotKitInspector();
5954
+ const { isInspectorEnabled, openInspector } = useCopilotKitInspector();
6165
5955
  const chatConfiguration = useCopilotChatConfiguration();
6166
5956
  const boundMarkdownRenderer = renderSlot(markdownRenderer, CopilotChatAssistantMessage.MarkdownRenderer, { content: message.content || "" });
6167
5957
  const boundCopyButton = renderSlot(copyButton, CopilotChatAssistantMessage.CopyButton, { onClick: async () => {
@@ -6174,17 +5964,6 @@ window.parent.postMessage({jsonrpc:"2.0",method:"ui/notifications/sandbox-proxy-
6174
5964
  threadId: chatConfiguration?.threadId,
6175
5965
  agentId: chatConfiguration?.agentId
6176
5966
  }) });
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
- } });
6188
5967
  const boundThumbsDownButton = renderSlot(thumbsDownButton, CopilotChatAssistantMessage.ThumbsDownButton, { onClick: onThumbsDown ? () => onThumbsDown(message) : void 0 });
6189
5968
  const boundReadAloudButton = renderSlot(readAloudButton, CopilotChatAssistantMessage.ReadAloudButton, { onClick: onReadAloud ? () => onReadAloud(message) : void 0 });
6190
5969
  const boundRegenerateButton = renderSlot(regenerateButton, CopilotChatAssistantMessage.RegenerateButton, { onClick: onRegenerate ? () => onRegenerate(message) : void 0 });
@@ -6192,8 +5971,7 @@ window.parent.postMessage({jsonrpc:"2.0",method:"ui/notifications/sandbox-proxy-
6192
5971
  className: "cpk:flex cpk:items-center cpk:gap-1",
6193
5972
  children: [
6194
5973
  boundCopyButton,
6195
- isLocalInspectorEnabled && boundInspectorButton,
6196
- isLocalInspectorEnabled && hasContent && boundSaveSnippetButton,
5974
+ isInspectorEnabled && boundInspectorButton,
6197
5975
  (onThumbsUp || thumbsUpButton) && boundThumbsUpButton,
6198
5976
  (onThumbsDown || thumbsDownButton) && boundThumbsDownButton,
6199
5977
  (onReadAloud || readAloudButton) && boundReadAloudButton,
@@ -6205,8 +5983,9 @@ window.parent.postMessage({jsonrpc:"2.0",method:"ui/notifications/sandbox-proxy-
6205
5983
  message,
6206
5984
  messages
6207
5985
  });
5986
+ const hasContent = !!(message.content && message.content.trim().length > 0);
6208
5987
  const isLatestAssistantMessage = message.role === "assistant" && messages?.[messages.length - 1]?.id === message.id;
6209
- const shouldShowToolbar = toolbarVisible && (hasContent || isLocalInspectorEnabled) && !(isRunning && isLatestAssistantMessage);
5988
+ const shouldShowToolbar = toolbarVisible && (hasContent || isInspectorEnabled) && !(isRunning && isLatestAssistantMessage);
6210
5989
  if (children) return /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
6211
5990
  "data-copilotkit": true,
6212
5991
  style: { display: "contents" },
@@ -6216,7 +5995,6 @@ window.parent.postMessage({jsonrpc:"2.0",method:"ui/notifications/sandbox-proxy-
6216
5995
  toolCallsView: boundToolCallsView,
6217
5996
  copyButton: boundCopyButton,
6218
5997
  inspectorButton: boundInspectorButton,
6219
- saveSnippetButton: boundSaveSnippetButton,
6220
5998
  thumbsUpButton: boundThumbsUpButton,
6221
5999
  thumbsDownButton: boundThumbsDownButton,
6222
6000
  readAloudButton: boundReadAloudButton,
@@ -6363,7 +6141,7 @@ window.parent.postMessage({jsonrpc:"2.0",method:"ui/notifications/sandbox-proxy-
6363
6141
  className: (0, tailwind_merge.twMerge)("cpk:w-full cpk:bg-transparent cpk:flex cpk:items-center cpk:-ml-[5px] cpk:-mt-[0px]", className),
6364
6142
  ...props
6365
6143
  });
6366
- const ToolbarButton = _CopilotChatAssistantMessage.ToolbarButton = ({ title, tooltip, children, ...props }) => {
6144
+ const ToolbarButton = _CopilotChatAssistantMessage.ToolbarButton = ({ title, tooltip, tooltipClassName, children, ...props }) => {
6367
6145
  return /* @__PURE__ */ (0, react_jsx_runtime.jsxs)(Tooltip, { children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)(TooltipTrigger, {
6368
6146
  asChild: true,
6369
6147
  children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(Button, {
@@ -6375,6 +6153,7 @@ window.parent.postMessage({jsonrpc:"2.0",method:"ui/notifications/sandbox-proxy-
6375
6153
  })
6376
6154
  }), /* @__PURE__ */ (0, react_jsx_runtime.jsx)(TooltipContent, {
6377
6155
  side: "bottom",
6156
+ className: tooltipClassName,
6378
6157
  children: tooltip ?? /* @__PURE__ */ (0, react_jsx_runtime.jsx)("p", { children: title })
6379
6158
  })] });
6380
6159
  };
@@ -6408,29 +6187,30 @@ window.parent.postMessage({jsonrpc:"2.0",method:"ui/notifications/sandbox-proxy-
6408
6187
  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]" })
6409
6188
  });
6410
6189
  };
6411
- _CopilotChatAssistantMessage.InspectorButton = ({ title, ...props }) => {
6190
+ _CopilotChatAssistantMessage.InspectorButton = ({ title, className, ...props }) => {
6412
6191
  const labels = useCopilotChatConfiguration()?.labels ?? CopilotChatDefaultLabels;
6413
6192
  const primaryLabel = title || labels.assistantMessageToolbarInspectorLabel;
6414
- const localOnlyLabel = labels.assistantMessageToolbarInspectorLocalOnlyLabel;
6415
- const accessibleLabel = `${primaryLabel} (${localOnlyLabel})`;
6416
- return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(ToolbarButton, {
6193
+ const accessibleLabel = `${primaryLabel} (local only)`;
6194
+ return /* @__PURE__ */ (0, react_jsx_runtime.jsxs)(ToolbarButton, {
6417
6195
  "data-testid": "copilot-inspector-button",
6418
6196
  title: accessibleLabel,
6419
- tooltip: /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
6420
- className: "cpk:flex cpk:flex-col cpk:gap-0.5",
6421
- children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", { children: primaryLabel }), /* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
6422
- className: "cpk:text-[10px] cpk:opacity-65",
6423
- children: localOnlyLabel
6424
- })]
6425
- }),
6197
+ className: (0, tailwind_merge.twMerge)("cpk:w-auto cpk:gap-1.5 cpk:px-2", className),
6198
+ tooltipClassName: "cpk:max-w-64 cpk:text-left cpk:leading-4",
6199
+ tooltip: "View this message in the Inspector to get more information. This button and the inspector only display during local development (localhost, dev env).",
6426
6200
  ...props,
6427
- children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(CopilotKitColoredIcon, {})
6201
+ children: [
6202
+ /* @__PURE__ */ (0, react_jsx_runtime.jsx)(CopilotKitColoredIcon, {}),
6203
+ /* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
6204
+ className: "cpk:font-medium",
6205
+ children: primaryLabel
6206
+ }),
6207
+ /* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
6208
+ className: "cpk:text-xs cpk:text-muted-foreground",
6209
+ children: "(local only)"
6210
+ })
6211
+ ]
6428
6212
  });
6429
6213
  };
6430
- _CopilotChatAssistantMessage.SaveSnippetButton = (props) => /* @__PURE__ */ (0, react_jsx_runtime.jsx)(SaveSnippetIconButton, {
6431
- "data-testid": "copilot-save-snippet-button",
6432
- ...props
6433
- });
6434
6214
  _CopilotChatAssistantMessage.ThumbsUpButton = ({ title, ...props }) => {
6435
6215
  const labels = useCopilotChatConfiguration()?.labels ?? CopilotChatDefaultLabels;
6436
6216
  return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(ToolbarButton, {
@@ -6472,7 +6252,6 @@ window.parent.postMessage({jsonrpc:"2.0",method:"ui/notifications/sandbox-proxy-
6472
6252
  CopilotChatAssistantMessage.Toolbar.displayName = "CopilotChatAssistantMessage.Toolbar";
6473
6253
  CopilotChatAssistantMessage.CopyButton.displayName = "CopilotChatAssistantMessage.CopyButton";
6474
6254
  CopilotChatAssistantMessage.InspectorButton.displayName = "CopilotChatAssistantMessage.InspectorButton";
6475
- CopilotChatAssistantMessage.SaveSnippetButton.displayName = "CopilotChatAssistantMessage.SaveSnippetButton";
6476
6255
  CopilotChatAssistantMessage.ThumbsUpButton.displayName = "CopilotChatAssistantMessage.ThumbsUpButton";
6477
6256
  CopilotChatAssistantMessage.ThumbsDownButton.displayName = "CopilotChatAssistantMessage.ThumbsDownButton";
6478
6257
  CopilotChatAssistantMessage.ReadAloudButton.displayName = "CopilotChatAssistantMessage.ReadAloudButton";
@@ -6843,8 +6622,6 @@ window.parent.postMessage({jsonrpc:"2.0",method:"ui/notifications/sandbox-proxy-
6843
6622
  const isLatest = messages?.[messages.length - 1]?.id === message.id;
6844
6623
  const isStreaming = !!(isRunning && isLatest);
6845
6624
  const hasContent = !!(message.content && message.content.length > 0);
6846
- const { isLocalInspectorEnabled, saveEventSnippet } = useCopilotKitInspector();
6847
- const chatConfiguration = useCopilotChatConfiguration();
6848
6625
  const startTimeRef = (0, react.useRef)(null);
6849
6626
  const [elapsed, setElapsed] = (0, react.useState)(0);
6850
6627
  (0, react.useEffect)(() => {
@@ -6904,16 +6681,7 @@ window.parent.postMessage({jsonrpc:"2.0",method:"ui/notifications/sandbox-proxy-
6904
6681
  className: (0, tailwind_merge.twMerge)("cpk:my-1", className),
6905
6682
  "data-message-id": message.id,
6906
6683
  ...props,
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]
6684
+ children: [boundHeader, boundToggle]
6917
6685
  });
6918
6686
  }
6919
6687
  (function(_CopilotChatReasoningMessage) {
@@ -7432,33 +7200,8 @@ window.parent.postMessage({jsonrpc:"2.0",method:"ui/notifications/sandbox-proxy-
7432
7200
  /**
7433
7201
  * Memoized wrapper for activity messages to prevent re-renders when other messages change.
7434
7202
  */
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
- }
7457
7203
  const MemoizedActivityMessage = react.default.memo(function MemoizedActivityMessage({ message, renderActivityMessage }) {
7458
- return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(ActivitySnippetChrome, {
7459
- message,
7460
- children: renderActivityMessage(message)
7461
- });
7204
+ return renderActivityMessage(message);
7462
7205
  }, (prevProps, nextProps) => {
7463
7206
  if (prevProps.message.id !== nextProps.message.id) return false;
7464
7207
  if (prevProps.message.activityType !== nextProps.message.activityType) return false;
@@ -11699,20 +11442,42 @@ window.parent.postMessage({jsonrpc:"2.0",method:"ui/notifications/sandbox-proxy-
11699
11442
 
11700
11443
  //#endregion
11701
11444
  //#region src/v1-deprecated/components/CopilotListeners.tsx
11702
- const usePredictStateSubscription = (agent) => {
11703
- const predictStateToolsRef = (0, react.useRef)([]);
11704
- const getSubscriber = (0, react.useCallback)((agent) => ({
11445
+ function isPredictStateTool(value) {
11446
+ if (value === null || typeof value !== "object") return false;
11447
+ const config = value;
11448
+ return typeof config.tool === "string" && typeof config.state_key === "string" && (config.tool_argument === void 0 || typeof config.tool_argument === "string");
11449
+ }
11450
+ function getPredictStateUpdate(config, toolCallName, partialToolCallArgs) {
11451
+ if (config.tool !== toolCallName) return void 0;
11452
+ const emittedState = typeof partialToolCallArgs === "string" ? (0, _copilotkit_shared.partialJSONParse)(partialToolCallArgs) : partialToolCallArgs;
11453
+ if (emittedState === null || typeof emittedState !== "object") return;
11454
+ if (config.tool_argument) {
11455
+ if (!(config.tool_argument in emittedState)) return void 0;
11456
+ return { [config.state_key]: emittedState[config.tool_argument] };
11457
+ }
11458
+ return { [config.state_key]: emittedState };
11459
+ }
11460
+ function createPredictStateSubscriber(agent, predictStateToolsRef) {
11461
+ return {
11705
11462
  onCustomEvent: ({ event }) => {
11706
- if (event.name === "PredictState") predictStateToolsRef.current = event.value;
11463
+ if (event.name === "PredictState") predictStateToolsRef.current = Array.isArray(event.value) ? event.value.filter(isPredictStateTool) : [];
11707
11464
  },
11708
11465
  onToolCallArgsEvent: ({ partialToolCallArgs, toolCallName }) => {
11709
- predictStateToolsRef.current.forEach((t) => {
11710
- if (t?.tool !== toolCallName) return;
11711
- const emittedState = typeof partialToolCallArgs === "string" ? (0, _copilotkit_shared.parseJson)(partialToolCallArgs, partialToolCallArgs) : partialToolCallArgs;
11712
- agent.setState({ [t.state_key]: emittedState[t.state_key] });
11466
+ const updates = {};
11467
+ predictStateToolsRef.current.forEach((config) => {
11468
+ const update = getPredictStateUpdate(config, toolCallName, partialToolCallArgs);
11469
+ if (update) Object.assign(updates, update);
11470
+ });
11471
+ if (Object.keys(updates).length > 0) agent.setState({
11472
+ ...agent.state,
11473
+ ...updates
11713
11474
  });
11714
11475
  }
11715
- }), []);
11476
+ };
11477
+ }
11478
+ const usePredictStateSubscription = (agent) => {
11479
+ const predictStateToolsRef = (0, react.useRef)([]);
11480
+ const getSubscriber = (0, react.useCallback)((subscriptionAgent) => createPredictStateSubscriber(subscriptionAgent, predictStateToolsRef), []);
11716
11481
  (0, react.useEffect)(() => {
11717
11482
  if (!agent) return;
11718
11483
  const subscriber = getSubscriber(agent);
@@ -11771,7 +11536,6 @@ window.parent.postMessage({jsonrpc:"2.0",method:"ui/notifications/sandbox-proxy-
11771
11536
  //#region src/v1-deprecated/components/copilot-provider/copilotkit.tsx
11772
11537
  function CopilotKit({ children, ...props }) {
11773
11538
  const enabled = shouldShowDevConsole(props.showDevConsole);
11774
- const showInspector = shouldShowDevConsole(props.enableInspector);
11775
11539
  const publicApiKey = props.publicApiKey || props.publicLicenseKey;
11776
11540
  const renderArr = (0, react.useMemo)(() => [{ render: CoAgentStateRenderBridge }], []);
11777
11541
  const { onError: _onError, ...v2Props } = props;
@@ -11784,7 +11548,7 @@ window.parent.postMessage({jsonrpc:"2.0",method:"ui/notifications/sandbox-proxy-
11784
11548
  threadId: props.threadId,
11785
11549
  children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(CopilotKitProvider, {
11786
11550
  ...v2Props,
11787
- showDevConsole: showInspector,
11551
+ enableInspector: props.enableInspector,
11788
11552
  renderCustomMessages: renderArr,
11789
11553
  children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(CopilotKitInternal, {
11790
11554
  ...props,