@copilotkit/react-core 1.69.2 → 1.70.0

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 (41) hide show
  1. package/dist/{copilotkit-BmW2sFH6.mjs → copilotkit-B7aFKfQR.mjs} +138 -77
  2. package/dist/copilotkit-B7aFKfQR.mjs.map +1 -0
  3. package/dist/{copilotkit-Ba7qwYt3.cjs → copilotkit-BE76j111.cjs} +142 -75
  4. package/dist/copilotkit-BE76j111.cjs.map +1 -0
  5. package/dist/{copilotkit-CF1Pm2VG.d.cts → copilotkit-BuzP0VeG.d.cts} +47 -18
  6. package/dist/copilotkit-BuzP0VeG.d.cts.map +1 -0
  7. package/dist/{copilotkit-TdM-5onZ.d.mts → copilotkit-CbZGwElm.d.mts} +47 -18
  8. package/dist/copilotkit-CbZGwElm.d.mts.map +1 -0
  9. package/dist/index.cjs +93 -21
  10. package/dist/index.cjs.map +1 -1
  11. package/dist/index.d.cts +17 -2
  12. package/dist/index.d.cts.map +1 -1
  13. package/dist/index.d.mts +17 -2
  14. package/dist/index.d.mts.map +1 -1
  15. package/dist/index.mjs +93 -21
  16. package/dist/index.mjs.map +1 -1
  17. package/dist/index.umd.js +206 -87
  18. package/dist/index.umd.js.map +1 -1
  19. package/dist/v2/headless.cjs +15 -8
  20. package/dist/v2/headless.cjs.map +1 -1
  21. package/dist/v2/headless.d.cts.map +1 -1
  22. package/dist/v2/headless.d.mts.map +1 -1
  23. package/dist/v2/headless.mjs +15 -8
  24. package/dist/v2/headless.mjs.map +1 -1
  25. package/dist/v2/index.cjs +2 -1
  26. package/dist/v2/index.d.cts +2 -2
  27. package/dist/v2/index.d.mts +2 -2
  28. package/dist/v2/index.mjs +2 -2
  29. package/dist/v2/index.umd.js +140 -77
  30. package/dist/v2/index.umd.js.map +1 -1
  31. package/package.json +9 -10
  32. package/skills/react-core/SKILL.md +5 -3
  33. package/skills/react-core/references/agent-access.md +68 -1
  34. package/skills/react-core/references/debug-mode.md +21 -34
  35. package/skills/react-core/references/switching-agents-recipes.md +1 -0
  36. package/skills/react-core/references/switching-agents.md +9 -0
  37. package/skills/react-core/references/threads.md +65 -0
  38. package/dist/copilotkit-Ba7qwYt3.cjs.map +0 -1
  39. package/dist/copilotkit-BmW2sFH6.mjs.map +0 -1
  40. package/dist/copilotkit-CF1Pm2VG.d.cts.map +0 -1
  41. package/dist/copilotkit-TdM-5onZ.d.mts.map +0 -1
package/dist/index.umd.js CHANGED
@@ -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('react'), require('@copilotkit/core'), require('@ag-ui/client'), require('@copilotkit/shared'), require('react/jsx-runtime'), require('zod'), require('@lit-labs/react'), require('@copilotkit/a2ui-renderer'), require('zod-to-json-schema'), require('react-dom'), require('react-markdown'), require('@copilotkit/runtime-client-gql')) :
5
- typeof define === 'function' && define.amd ? define(['exports', 'react', '@copilotkit/core', '@ag-ui/client', '@copilotkit/shared', 'react/jsx-runtime', 'zod', '@lit-labs/react', '@copilotkit/a2ui-renderer', 'zod-to-json-schema', 'react-dom', 'react-markdown', '@copilotkit/runtime-client-gql'], factory) :
6
- (global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory((global.CopilotKitReactCore = {}), global.React,global.CopilotKitCore,global.AgUIClient,global.CopilotKitShared,global.ReactJsxRuntime,global.Zod,global._lit_labs_react,global.CopilotKitA2UIRenderer,global.zod_to_json_schema,global.ReactDOM,global.ReactMarkdown,global.CopilotKitRuntimeClientGQL));
7
- })(this, function(exports, react, _copilotkit_core, _ag_ui_client, _copilotkit_shared, react_jsx_runtime, zod, _lit_labs_react, _copilotkit_a2ui_renderer, zod_to_json_schema, react_dom, react_markdown, _copilotkit_runtime_client_gql) {
4
+ typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('react'), require('@copilotkit/core'), require('@ag-ui/client'), require('@copilotkit/shared'), require('react/jsx-runtime'), require('zod'), require('@copilotkit/a2ui-renderer'), require('zod-to-json-schema'), require('react-dom'), require('react-markdown'), require('@copilotkit/runtime-client-gql')) :
5
+ typeof define === 'function' && define.amd ? define(['exports', 'react', '@copilotkit/core', '@ag-ui/client', '@copilotkit/shared', 'react/jsx-runtime', 'zod', '@copilotkit/a2ui-renderer', 'zod-to-json-schema', 'react-dom', 'react-markdown', '@copilotkit/runtime-client-gql'], factory) :
6
+ (global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory((global.CopilotKitReactCore = {}), global.React,global.CopilotKitCore,global.AgUIClient,global.CopilotKitShared,global.ReactJsxRuntime,global.Zod,global.CopilotKitA2UIRenderer,global.zod_to_json_schema,global.ReactDOM,global.ReactMarkdown,global.CopilotKitRuntimeClientGQL));
7
+ })(this, function(exports, react, _copilotkit_core, _ag_ui_client, _copilotkit_shared, react_jsx_runtime, zod, _copilotkit_a2ui_renderer, zod_to_json_schema, react_dom, react_markdown, _copilotkit_runtime_client_gql) {
8
8
  Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
9
9
  //#region \0rolldown/runtime.js
10
10
  var __create = Object.create;
@@ -90,7 +90,7 @@ react_markdown = __toESM(react_markdown);
90
90
  assistantMessageToolbarCopyCodeCopiedLabel: "Copied",
91
91
  assistantMessageToolbarCopyMessageLabel: "Copy",
92
92
  assistantMessageToolbarInspectorLabel: "View in Inspector",
93
- assistantMessageToolbarInspectorLocalOnlyLabel: "Local Only",
93
+ assistantMessageToolbarInspectorLocalOnlyLabel: "Development Only",
94
94
  assistantMessageToolbarThumbsUpLabel: "Good response",
95
95
  assistantMessageToolbarThumbsDownLabel: "Bad response",
96
96
  assistantMessageToolbarReadAloudLabel: "Read aloud",
@@ -480,32 +480,43 @@ react_markdown = __toESM(react_markdown);
480
480
 
481
481
  //#endregion
482
482
  //#region src/v2/components/CopilotKitInspector.tsx
483
- const CopilotKitInspector = ({ core, openRequest, ...rest }) => {
484
- const [InspectorComponent, setInspectorComponent] = react.useState(null);
483
+ const CopilotKitInspector = ({ core, openRequest }) => {
484
+ const mountRef = react.useRef(null);
485
485
  const inspectorRef = react.useRef(null);
486
+ const latestCoreRef = react.useRef(core ?? null);
487
+ const latestOpenRequestRef = react.useRef(openRequest);
488
+ latestCoreRef.current = core ?? null;
489
+ latestOpenRequestRef.current = openRequest;
486
490
  react.useEffect(() => {
487
491
  let mounted = true;
492
+ let inspector = null;
488
493
  import("@copilotkit/web-inspector").then((mod) => {
494
+ if (!mounted || !mountRef.current) return;
489
495
  mod.defineWebInspector?.();
490
- const Component = (0, _lit_labs_react.createComponent)({
491
- tagName: mod.WEB_INSPECTOR_TAG,
492
- elementClass: mod.WebInspectorElement,
493
- react
494
- });
495
- if (mounted) setInspectorComponent(() => Component);
496
+ inspector = mountRef.current.ownerDocument.createElement(mod.WEB_INSPECTOR_TAG);
497
+ mod.configureWebInspectorElement(inspector, latestCoreRef.current);
498
+ mountRef.current.appendChild(inspector);
499
+ inspectorRef.current = inspector;
500
+ const request = latestOpenRequestRef.current;
501
+ if (request) inspector.openInspector("message_toolbar", request);
502
+ }).catch((error) => {
503
+ console.error("Failed to load CopilotKit inspector:", error);
496
504
  });
497
505
  return () => {
498
506
  mounted = false;
507
+ inspector?.remove();
508
+ if (inspectorRef.current === inspector) inspectorRef.current = null;
499
509
  };
500
510
  }, []);
511
+ react.useEffect(() => {
512
+ if (inspectorRef.current) inspectorRef.current.core = core ?? null;
513
+ }, [core]);
501
514
  react.useEffect(() => {
502
515
  if (openRequest) inspectorRef.current?.openInspector("message_toolbar", openRequest);
503
- }, [InspectorComponent, openRequest]);
504
- if (!InspectorComponent) return null;
505
- return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(InspectorComponent, {
506
- ref: inspectorRef,
507
- ...rest,
508
- core: core ?? null
516
+ }, [openRequest]);
517
+ return /* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
518
+ ref: mountRef,
519
+ style: { display: "contents" }
509
520
  });
510
521
  };
511
522
  CopilotKitInspector.displayName = "CopilotKitInspector";
@@ -513,7 +524,7 @@ react_markdown = __toESM(react_markdown);
513
524
  //#endregion
514
525
  //#region src/v2/components/CopilotKitInspectorContext.tsx
515
526
  const CopilotKitInspectorContext = react.createContext({
516
- isLocalInspectorEnabled: false,
527
+ isInspectorEnabled: false,
517
528
  openInspector: () => void 0
518
529
  });
519
530
  const CopilotKitInspectorContextProvider = CopilotKitInspectorContext.Provider;
@@ -2335,9 +2346,15 @@ window.parent.postMessage({jsonrpc:"2.0",method:"ui/notifications/sandbox-proxy-
2335
2346
  }, [value, warningMessage]);
2336
2347
  return value;
2337
2348
  }
2338
- 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 }) => {
2349
+ 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 }) => {
2339
2350
  const [shouldRenderInspector, setShouldRenderInspector] = (0, react.useState)(false);
2340
- const [isLocalInspectorEnabled, setIsLocalInspectorEnabled] = (0, react.useState)(false);
2351
+ (0, react.useEffect)(() => {
2352
+ setShouldRenderInspector((0, _copilotkit_shared.shouldEnableInspector)({
2353
+ enableInspector,
2354
+ isBrowser: true,
2355
+ isDevelopment: process.env.NODE_ENV === "development"
2356
+ }));
2357
+ }, [enableInspector]);
2341
2358
  const [inspectorOpenRequest, setInspectorOpenRequest] = (0, react.useState)(null);
2342
2359
  const [runtimeA2UIEnabled, setRuntimeA2UIEnabled] = (0, react.useState)(false);
2343
2360
  const [runtimeOpenGenUIEnabled, setRuntimeOpenGenUIEnabled] = (0, react.useState)(false);
@@ -2346,32 +2363,15 @@ window.parent.postMessage({jsonrpc:"2.0",method:"ui/notifications/sandbox-proxy-
2346
2363
  const a2uiCatalogProvided = !!a2ui?.catalog;
2347
2364
  const a2uiActive = runtimeA2UIEnabled || a2uiCatalogProvided;
2348
2365
  const [runtimeLicenseStatus, setRuntimeLicenseStatus] = (0, react.useState)(void 0);
2349
- (0, react.useEffect)(() => {
2350
- if (typeof window === "undefined") return;
2351
- const isLocalhost = new Set(["localhost", "127.0.0.1"]).has(window.location?.hostname ?? "");
2352
- const canShowLocalInspectorAction = process.env.NODE_ENV === "development" && isLocalhost;
2353
- if (showDevConsole === true) {
2354
- setShouldRenderInspector(true);
2355
- setIsLocalInspectorEnabled(canShowLocalInspectorAction);
2356
- } else if (showDevConsole === "auto") if (isLocalhost) {
2357
- setShouldRenderInspector(true);
2358
- setIsLocalInspectorEnabled(canShowLocalInspectorAction);
2359
- } else {
2360
- setShouldRenderInspector(false);
2361
- setIsLocalInspectorEnabled(false);
2362
- }
2363
- else {
2364
- setShouldRenderInspector(false);
2365
- setIsLocalInspectorEnabled(false);
2366
- }
2367
- }, [showDevConsole]);
2366
+ const [runtimeEntitlements, setRuntimeEntitlements] = (0, react.useState)(void 0);
2367
+ const [runtimeEntitlementRetryPending, setRuntimeEntitlementRetryPending] = (0, react.useState)(false);
2368
2368
  const requestInspectorOpen = (0, react.useCallback)((request) => {
2369
2369
  setInspectorOpenRequest({ ...request });
2370
2370
  }, []);
2371
2371
  const inspectorContextValue = (0, react.useMemo)(() => ({
2372
- isLocalInspectorEnabled,
2372
+ isInspectorEnabled: shouldRenderInspector,
2373
2373
  openInspector: requestInspectorOpen
2374
- }), [isLocalInspectorEnabled, requestInspectorOpen]);
2374
+ }), [shouldRenderInspector, requestInspectorOpen]);
2375
2375
  const renderToolCallsList = useStableArrayProp(renderToolCalls, "renderToolCalls must be a stable array. If you want to dynamically add or remove tools, use `useFrontendTool` instead.", (initial, next) => {
2376
2376
  const key = (rc) => `${rc?.agentId ?? ""}:${rc?.name ?? ""}`;
2377
2377
  const setFrom = (arr) => new Set(arr.map(key));
@@ -2555,6 +2555,8 @@ window.parent.postMessage({jsonrpc:"2.0",method:"ui/notifications/sandbox-proxy-
2555
2555
  setRuntimeA2UIEnabled(copilotkit.a2uiEnabled);
2556
2556
  setRuntimeOpenGenUIEnabled(copilotkit.openGenerativeUIEnabled);
2557
2557
  setRuntimeLicenseStatus(copilotkit.licenseStatus);
2558
+ setRuntimeEntitlements(copilotkit.runtimeEntitlements);
2559
+ setRuntimeEntitlementRetryPending(copilotkit.runtimeEntitlementRetryPending);
2558
2560
  };
2559
2561
  const subscription = copilotkit.subscribe({ onRuntimeConnectionStatusChanged: syncRuntimeInfo });
2560
2562
  syncRuntimeInfo();
@@ -2695,7 +2697,26 @@ window.parent.postMessage({jsonrpc:"2.0",method:"ui/notifications/sandbox-proxy-
2695
2697
  copilotkit,
2696
2698
  executingToolCallIds
2697
2699
  }), [copilotkit, executingToolCallIds]);
2698
- const licenseContextValue = (0, react.useMemo)(() => (0, _copilotkit_shared.createLicenseContextValue)(runtimeLicenseStatus), [runtimeLicenseStatus]);
2700
+ const retryableRuntimeEntitlementFailure = runtimeEntitlements?.status !== "ready" && runtimeEntitlements?.error.retryable === true;
2701
+ const hasNonReadyRuntimeEntitlement = runtimeEntitlements !== void 0 && runtimeEntitlements.status !== "ready";
2702
+ const hasLegacyRuntimeEntitlementFallback = runtimeLicenseStatus === "valid" || runtimeLicenseStatus === "expiring";
2703
+ const runtimeEntitlementRetryInProgress = retryableRuntimeEntitlementFailure && runtimeEntitlementRetryPending && !hasLegacyRuntimeEntitlementFallback;
2704
+ const runtimeEntitlementFailureSettled = hasNonReadyRuntimeEntitlement && !runtimeEntitlementRetryInProgress && !hasLegacyRuntimeEntitlementFallback;
2705
+ const licenseContextValue = (0, react.useMemo)(() => {
2706
+ const runtimeLicenseContext = (0, _copilotkit_shared.createLicenseContextValue)(runtimeEntitlementRetryInProgress ? void 0 : runtimeLicenseStatus, runtimeEntitlements);
2707
+ if (!runtimeEntitlementFailureSettled) return runtimeLicenseContext;
2708
+ return {
2709
+ ...runtimeLicenseContext,
2710
+ checkFeature: () => false,
2711
+ getLimit: () => null
2712
+ };
2713
+ }, [
2714
+ runtimeEntitlementFailureSettled,
2715
+ runtimeEntitlementRetryInProgress,
2716
+ runtimeEntitlements,
2717
+ runtimeLicenseStatus
2718
+ ]);
2719
+ const runtimeLicenseWarningStatus = runtimeEntitlementRetryInProgress ? void 0 : licenseContextValue.status ?? void 0;
2699
2720
  return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(SandboxFunctionsContext.Provider, {
2700
2721
  value: sandboxFunctionsList,
2701
2722
  children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(CopilotKitContext.Provider, {
@@ -2712,14 +2733,13 @@ window.parent.postMessage({jsonrpc:"2.0",method:"ui/notifications/sandbox-proxy-
2712
2733
  value: inspectorContextValue,
2713
2734
  children: [children, shouldRenderInspector ? /* @__PURE__ */ (0, react_jsx_runtime.jsx)(CopilotKitInspector, {
2714
2735
  core: copilotkit,
2715
- defaultAnchor: inspectorDefaultAnchor,
2716
2736
  openRequest: inspectorOpenRequest
2717
2737
  }) : null]
2718
2738
  }),
2719
- runtimeLicenseStatus === "none" && !resolvedPublicKey && /* @__PURE__ */ (0, react_jsx_runtime.jsx)(LicenseWarningBanner, { type: "no_license" }),
2720
- runtimeLicenseStatus === "expired" && /* @__PURE__ */ (0, react_jsx_runtime.jsx)(LicenseWarningBanner, { type: "expired" }),
2721
- runtimeLicenseStatus === "invalid" && /* @__PURE__ */ (0, react_jsx_runtime.jsx)(LicenseWarningBanner, { type: "invalid" }),
2722
- runtimeLicenseStatus === "expiring" && /* @__PURE__ */ (0, react_jsx_runtime.jsx)(LicenseWarningBanner, { type: "expiring" })
2739
+ runtimeLicenseWarningStatus === "none" && !resolvedPublicKey && /* @__PURE__ */ (0, react_jsx_runtime.jsx)(LicenseWarningBanner, { type: "no_license" }),
2740
+ runtimeLicenseWarningStatus === "expired" && /* @__PURE__ */ (0, react_jsx_runtime.jsx)(LicenseWarningBanner, { type: "expired" }),
2741
+ runtimeLicenseWarningStatus === "invalid" && /* @__PURE__ */ (0, react_jsx_runtime.jsx)(LicenseWarningBanner, { type: "invalid" }),
2742
+ runtimeLicenseWarningStatus === "expiring" && /* @__PURE__ */ (0, react_jsx_runtime.jsx)(LicenseWarningBanner, { type: "expiring" })
2723
2743
  ]
2724
2744
  })
2725
2745
  })
@@ -2777,7 +2797,7 @@ window.parent.postMessage({jsonrpc:"2.0",method:"ui/notifications/sandbox-proxy-
2777
2797
  function useFrontendTool$1(tool, deps) {
2778
2798
  const { copilotkit } = useCopilotKit();
2779
2799
  const extraDeps = deps ?? EMPTY_DEPS;
2780
- (0, react.useEffect)(() => {
2800
+ (0, react.useLayoutEffect)(() => {
2781
2801
  const name = tool.name;
2782
2802
  if (copilotkit.getTool({
2783
2803
  toolName: name,
@@ -2806,6 +2826,8 @@ window.parent.postMessage({jsonrpc:"2.0",method:"ui/notifications/sandbox-proxy-
2806
2826
 
2807
2827
  //#endregion
2808
2828
  //#region src/v2/hooks/use-human-in-the-loop.tsx
2829
+ /** Registration name of a catch-all tool: handles any otherwise-unhandled call. */
2830
+ const WILDCARD_TOOL_NAME = "*";
2809
2831
  function useHumanInTheLoop$1(tool, deps) {
2810
2832
  const { copilotkit } = useCopilotKit();
2811
2833
  const resolvePromiseRef = (0, react.useRef)(null);
@@ -2841,10 +2863,11 @@ window.parent.postMessage({jsonrpc:"2.0",method:"ui/notifications/sandbox-proxy-
2841
2863
  }, []);
2842
2864
  const RenderComponent = (0, react.useCallback)((props) => {
2843
2865
  const ToolComponent = tool.render;
2866
+ const name = tool.name === WILDCARD_TOOL_NAME ? props.name : tool.name;
2844
2867
  if (props.status === _copilotkit_core.ToolCallStatus.InProgress) {
2845
2868
  const enhancedProps = {
2846
2869
  ...props,
2847
- name: tool.name,
2870
+ name,
2848
2871
  description: tool.description || "",
2849
2872
  agentId: tool.agentId,
2850
2873
  respond: void 0
@@ -2853,7 +2876,7 @@ window.parent.postMessage({jsonrpc:"2.0",method:"ui/notifications/sandbox-proxy-
2853
2876
  } else if (props.status === _copilotkit_core.ToolCallStatus.Executing) {
2854
2877
  const enhancedProps = {
2855
2878
  ...props,
2856
- name: tool.name,
2879
+ name,
2857
2880
  description: tool.description || "",
2858
2881
  agentId: tool.agentId,
2859
2882
  respond
@@ -2862,7 +2885,7 @@ window.parent.postMessage({jsonrpc:"2.0",method:"ui/notifications/sandbox-proxy-
2862
2885
  } else if (props.status === _copilotkit_core.ToolCallStatus.Complete) {
2863
2886
  const enhancedProps = {
2864
2887
  ...props,
2865
- name: tool.name,
2888
+ name,
2866
2889
  description: tool.description || "",
2867
2890
  agentId: tool.agentId,
2868
2891
  respond: void 0
@@ -2882,7 +2905,7 @@ window.parent.postMessage({jsonrpc:"2.0",method:"ui/notifications/sandbox-proxy-
2882
2905
  handler,
2883
2906
  render: RenderComponent
2884
2907
  }, deps);
2885
- (0, react.useEffect)(() => {
2908
+ (0, react.useLayoutEffect)(() => {
2886
2909
  return () => {
2887
2910
  copilotkit.removeHookRenderToolCall(tool.name, tool.agentId);
2888
2911
  };
@@ -3302,8 +3325,12 @@ window.parent.postMessage({jsonrpc:"2.0",method:"ui/notifications/sandbox-proxy-
3302
3325
  }
3303
3326
 
3304
3327
  //#endregion
3305
- //#region src/v2/hooks/use-interrupt.tsx
3328
+ //#region src/v2/types/interrupt.ts
3329
+ /** Name of the legacy custom event agents emit to signal an interrupt. */
3306
3330
  const INTERRUPT_EVENT_NAME = "on_interrupt";
3331
+
3332
+ //#endregion
3333
+ //#region src/v2/hooks/use-interrupt.tsx
3307
3334
  function isPromiseLike(value) {
3308
3335
  return (typeof value === "object" || typeof value === "function") && value !== null && typeof Reflect.get(value, "then") === "function";
3309
3336
  }
@@ -5163,20 +5190,42 @@ window.parent.postMessage({jsonrpc:"2.0",method:"ui/notifications/sandbox-proxy-
5163
5190
 
5164
5191
  //#endregion
5165
5192
  //#region src/v1-deprecated/components/CopilotListeners.tsx
5166
- const usePredictStateSubscription = (agent) => {
5167
- const predictStateToolsRef = (0, react.useRef)([]);
5168
- const getSubscriber = (0, react.useCallback)((agent) => ({
5193
+ function isPredictStateTool(value) {
5194
+ if (value === null || typeof value !== "object") return false;
5195
+ const config = value;
5196
+ return typeof config.tool === "string" && typeof config.state_key === "string" && (config.tool_argument === void 0 || typeof config.tool_argument === "string");
5197
+ }
5198
+ function getPredictStateUpdate(config, toolCallName, partialToolCallArgs) {
5199
+ if (config.tool !== toolCallName) return void 0;
5200
+ const emittedState = typeof partialToolCallArgs === "string" ? (0, _copilotkit_shared.partialJSONParse)(partialToolCallArgs) : partialToolCallArgs;
5201
+ if (emittedState === null || typeof emittedState !== "object") return;
5202
+ if (config.tool_argument) {
5203
+ if (!(config.tool_argument in emittedState)) return void 0;
5204
+ return { [config.state_key]: emittedState[config.tool_argument] };
5205
+ }
5206
+ return { [config.state_key]: emittedState };
5207
+ }
5208
+ function createPredictStateSubscriber(agent, predictStateToolsRef) {
5209
+ return {
5169
5210
  onCustomEvent: ({ event }) => {
5170
- if (event.name === "PredictState") predictStateToolsRef.current = event.value;
5211
+ if (event.name === "PredictState") predictStateToolsRef.current = Array.isArray(event.value) ? event.value.filter(isPredictStateTool) : [];
5171
5212
  },
5172
5213
  onToolCallArgsEvent: ({ partialToolCallArgs, toolCallName }) => {
5173
- predictStateToolsRef.current.forEach((t) => {
5174
- if (t?.tool !== toolCallName) return;
5175
- const emittedState = typeof partialToolCallArgs === "string" ? (0, _copilotkit_shared.parseJson)(partialToolCallArgs, partialToolCallArgs) : partialToolCallArgs;
5176
- agent.setState({ [t.state_key]: emittedState[t.state_key] });
5214
+ const updates = {};
5215
+ predictStateToolsRef.current.forEach((config) => {
5216
+ const update = getPredictStateUpdate(config, toolCallName, partialToolCallArgs);
5217
+ if (update) Object.assign(updates, update);
5218
+ });
5219
+ if (Object.keys(updates).length > 0) agent.setState({
5220
+ ...agent.state,
5221
+ ...updates
5177
5222
  });
5178
5223
  }
5179
- }), []);
5224
+ };
5225
+ }
5226
+ const usePredictStateSubscription = (agent) => {
5227
+ const predictStateToolsRef = (0, react.useRef)([]);
5228
+ const getSubscriber = (0, react.useCallback)((subscriptionAgent) => createPredictStateSubscriber(subscriptionAgent, predictStateToolsRef), []);
5180
5229
  (0, react.useEffect)(() => {
5181
5230
  if (!agent) return;
5182
5231
  const subscriber = getSubscriber(agent);
@@ -5235,7 +5284,6 @@ window.parent.postMessage({jsonrpc:"2.0",method:"ui/notifications/sandbox-proxy-
5235
5284
  //#region src/v1-deprecated/components/copilot-provider/copilotkit.tsx
5236
5285
  function CopilotKit({ children, ...props }) {
5237
5286
  const enabled = shouldShowDevConsole(props.showDevConsole);
5238
- const showInspector = shouldShowDevConsole(props.enableInspector);
5239
5287
  const publicApiKey = props.publicApiKey || props.publicLicenseKey;
5240
5288
  const renderArr = (0, react.useMemo)(() => [{ render: CoAgentStateRenderBridge }], []);
5241
5289
  const { onError: _onError, ...v2Props } = props;
@@ -5248,7 +5296,7 @@ window.parent.postMessage({jsonrpc:"2.0",method:"ui/notifications/sandbox-proxy-
5248
5296
  threadId: props.threadId,
5249
5297
  children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(CopilotKitProvider, {
5250
5298
  ...v2Props,
5251
- showDevConsole: showInspector,
5299
+ enableInspector: props.enableInspector,
5252
5300
  renderCustomMessages: renderArr,
5253
5301
  children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(CopilotKitInternal, {
5254
5302
  ...props,
@@ -5735,13 +5783,18 @@ window.parent.postMessage({jsonrpc:"2.0",method:"ui/notifications/sandbox-proxy-
5735
5783
  const renderToolCall = useRenderToolCall$1();
5736
5784
  return (0, react.useCallback)((message, messages) => {
5737
5785
  if (!message?.toolCalls?.length) return null;
5738
- const toolCall = message.toolCalls[0];
5739
- if (!toolCall) return null;
5740
- const toolMessage = messages?.find((m) => m.role === "tool" && m.toolCallId === toolCall.id);
5741
- return () => renderToolCall({
5742
- toolCall,
5743
- toolMessage
5744
- });
5786
+ const toolCalls = message.toolCalls;
5787
+ return () => {
5788
+ const renderedToolCalls = toolCalls.map((toolCall) => {
5789
+ const toolMessage = messages?.find((m) => m.role === "tool" && m.toolCallId === toolCall.id);
5790
+ return renderToolCall({
5791
+ toolCall,
5792
+ toolMessage
5793
+ });
5794
+ }).filter((renderedToolCall) => renderedToolCall !== null);
5795
+ if (!renderedToolCalls.length) return null;
5796
+ return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(react_jsx_runtime.Fragment, { children: renderedToolCalls });
5797
+ };
5745
5798
  }, [renderToolCall]);
5746
5799
  }
5747
5800
 
@@ -6436,20 +6489,24 @@ window.parent.postMessage({jsonrpc:"2.0",method:"ui/notifications/sandbox-proxy-
6436
6489
  if (!render) return null;
6437
6490
  const rendered = render((() => {
6438
6491
  const mappedArgs = args.args;
6492
+ const toolCallName = args.name;
6439
6493
  switch (args.status) {
6440
6494
  case _copilotkit_core.ToolCallStatus.InProgress: return {
6495
+ name: toolCallName,
6441
6496
  args: mappedArgs,
6442
6497
  respond: args.respond,
6443
6498
  status: args.status,
6444
6499
  handler: void 0
6445
6500
  };
6446
6501
  case _copilotkit_core.ToolCallStatus.Executing: return {
6502
+ name: toolCallName,
6447
6503
  args: mappedArgs,
6448
6504
  respond: args.respond,
6449
6505
  status: args.status,
6450
6506
  handler: () => {}
6451
6507
  };
6452
6508
  case _copilotkit_core.ToolCallStatus.Complete: return {
6509
+ name: toolCallName,
6453
6510
  args: mappedArgs,
6454
6511
  respond: args.respond,
6455
6512
  status: args.status,
@@ -6609,10 +6666,21 @@ window.parent.postMessage({jsonrpc:"2.0",method:"ui/notifications/sandbox-proxy-
6609
6666
  * This hooks enables you to dynamically generate UI elements and render them in the copilot chat. For more information, check out the [Generative UI](/guides/generative-ui) page.
6610
6667
  */
6611
6668
  function getActionConfig(action) {
6612
- if (action.name === "*") return {
6613
- type: "render",
6614
- action
6615
- };
6669
+ if (action.name === "*") {
6670
+ const catchAll = action;
6671
+ const waitRender = catchAll.renderAndWaitForResponse ?? catchAll.renderAndWait;
6672
+ if (waitRender) return {
6673
+ type: "hitl",
6674
+ action: {
6675
+ ...catchAll,
6676
+ render: waitRender
6677
+ }
6678
+ };
6679
+ return {
6680
+ type: "render",
6681
+ action
6682
+ };
6683
+ }
6616
6684
  if ("renderAndWaitForResponse" in action || "renderAndWait" in action) {
6617
6685
  let render = action.render;
6618
6686
  if (!render && "renderAndWaitForResponse" in action) render = action.renderAndWaitForResponse;
@@ -6923,37 +6991,87 @@ window.parent.postMessage({jsonrpc:"2.0",method:"ui/notifications/sandbox-proxy-
6923
6991
 
6924
6992
  //#endregion
6925
6993
  //#region src/v1-deprecated/hooks/use-agent-nodename.ts
6926
- /**
6994
+ const initialAgentNodeNameState = {
6995
+ nodeName: "start",
6996
+ lastActiveNodeName: "start",
6997
+ hasLegacyInterrupt: false
6998
+ };
6999
+ const transitionAgentNodeName = (state, event) => {
7000
+ switch (event.type) {
7001
+ case "reset":
7002
+ case "runStarted": return initialAgentNodeNameState;
7003
+ case "stepStarted": return {
7004
+ ...state,
7005
+ nodeName: event.nodeName,
7006
+ lastActiveNodeName: event.nodeName
7007
+ };
7008
+ case "legacyInterruptReceived": return {
7009
+ ...state,
7010
+ hasLegacyInterrupt: true
7011
+ };
7012
+ case "runFinished":
7013
+ if (event.outcome === "interrupt" || state.hasLegacyInterrupt) return {
7014
+ ...state,
7015
+ nodeName: state.lastActiveNodeName,
7016
+ hasLegacyInterrupt: false
7017
+ };
7018
+ return {
7019
+ ...state,
7020
+ nodeName: "end",
7021
+ hasLegacyInterrupt: false
7022
+ };
7023
+ case "runError": return {
7024
+ ...state,
7025
+ nodeName: "end",
7026
+ hasLegacyInterrupt: false
7027
+ };
7028
+ }
7029
+ };
7030
+ /**
6927
7031
  * Tracks the node the agent is currently executing.
6928
7032
  *
6929
7033
  * Backed by state rather than a ref: mutating a ref schedules no render, so
6930
7034
  * consumers such as `useCoAgent().nodeName` kept reporting whichever node was
6931
- * current at their last render and never updated on their own.
7035
+ * current at their last render and never updated on their own. Interrupt-aware
7036
+ * transitions keep the last active node available while an interrupt is pending.
6932
7037
  */
6933
7038
  function useAgentNodeName(agentName) {
6934
7039
  const { agent } = useAgent({ agentId: agentName });
6935
- const [nodeName, setNodeName] = (0, react.useState)("start");
7040
+ const [nodeNameState, setNodeNameState] = (0, react.useState)(initialAgentNodeNameState);
6936
7041
  (0, react.useEffect)(() => {
7042
+ const transition = (event) => {
7043
+ setNodeNameState((state) => transitionAgentNodeName(state, event));
7044
+ };
7045
+ transition({ type: "reset" });
6937
7046
  if (!agent) return;
6938
7047
  const subscription = agent.subscribe({
6939
7048
  onStepStartedEvent: ({ event }) => {
6940
- setNodeName(event.stepName);
7049
+ transition({
7050
+ type: "stepStarted",
7051
+ nodeName: event.stepName
7052
+ });
6941
7053
  },
6942
7054
  onRunStartedEvent: () => {
6943
- setNodeName("start");
7055
+ transition({ type: "runStarted" });
6944
7056
  },
6945
- onRunFinishedEvent: () => {
6946
- setNodeName("end");
7057
+ onRunFinishedEvent: ({ outcome }) => {
7058
+ transition({
7059
+ type: "runFinished",
7060
+ outcome
7061
+ });
6947
7062
  },
6948
7063
  onRunErrorEvent: () => {
6949
- setNodeName("end");
7064
+ transition({ type: "runError" });
7065
+ },
7066
+ onCustomEvent: ({ event }) => {
7067
+ if (event.name === INTERRUPT_EVENT_NAME) transition({ type: "legacyInterruptReceived" });
6950
7068
  }
6951
7069
  });
6952
7070
  return () => {
6953
7071
  subscription.unsubscribe();
6954
7072
  };
6955
- }, [agent]);
6956
- return nodeName;
7073
+ }, [agent, agentName]);
7074
+ return nodeNameState.nodeName;
6957
7075
  }
6958
7076
 
6959
7077
  //#endregion
@@ -7156,6 +7274,7 @@ window.parent.postMessage({jsonrpc:"2.0",method:"ui/notifications/sandbox-proxy-
7156
7274
  agent?.threadId,
7157
7275
  agent?.isRunning,
7158
7276
  agent?.agentId,
7277
+ nodeName,
7159
7278
  handleStateUpdate,
7160
7279
  options.name
7161
7280
  ]);