@copilotkit/react-core 1.69.3 → 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 (36) hide show
  1. package/dist/{copilotkit-JdHy0xdu.mjs → copilotkit-B7aFKfQR.mjs} +65 -21
  2. package/dist/copilotkit-B7aFKfQR.mjs.map +1 -0
  3. package/dist/{copilotkit-BPeh62mW.cjs → copilotkit-BE76j111.cjs} +70 -20
  4. package/dist/copilotkit-BE76j111.cjs.map +1 -0
  5. package/dist/{copilotkit-CrNUgJiq.d.cts → copilotkit-BuzP0VeG.d.cts} +31 -4
  6. package/dist/copilotkit-BuzP0VeG.d.cts.map +1 -0
  7. package/dist/{copilotkit-DgO31tBq.d.mts → copilotkit-CbZGwElm.d.mts} +31 -4
  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 +133 -32
  18. package/dist/index.umd.js.map +1 -1
  19. package/dist/v2/headless.cjs +14 -7
  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 +14 -7
  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 +64 -19
  30. package/dist/v2/index.umd.js.map +1 -1
  31. package/package.json +9 -9
  32. package/skills/react-core/SKILL.md +1 -1
  33. package/dist/copilotkit-BPeh62mW.cjs.map +0 -1
  34. package/dist/copilotkit-CrNUgJiq.d.cts.map +0 -1
  35. package/dist/copilotkit-DgO31tBq.d.mts.map +0 -1
  36. package/dist/copilotkit-JdHy0xdu.mjs.map +0 -1
package/dist/index.umd.js CHANGED
@@ -2363,6 +2363,8 @@ window.parent.postMessage({jsonrpc:"2.0",method:"ui/notifications/sandbox-proxy-
2363
2363
  const a2uiCatalogProvided = !!a2ui?.catalog;
2364
2364
  const a2uiActive = runtimeA2UIEnabled || a2uiCatalogProvided;
2365
2365
  const [runtimeLicenseStatus, setRuntimeLicenseStatus] = (0, react.useState)(void 0);
2366
+ const [runtimeEntitlements, setRuntimeEntitlements] = (0, react.useState)(void 0);
2367
+ const [runtimeEntitlementRetryPending, setRuntimeEntitlementRetryPending] = (0, react.useState)(false);
2366
2368
  const requestInspectorOpen = (0, react.useCallback)((request) => {
2367
2369
  setInspectorOpenRequest({ ...request });
2368
2370
  }, []);
@@ -2553,6 +2555,8 @@ window.parent.postMessage({jsonrpc:"2.0",method:"ui/notifications/sandbox-proxy-
2553
2555
  setRuntimeA2UIEnabled(copilotkit.a2uiEnabled);
2554
2556
  setRuntimeOpenGenUIEnabled(copilotkit.openGenerativeUIEnabled);
2555
2557
  setRuntimeLicenseStatus(copilotkit.licenseStatus);
2558
+ setRuntimeEntitlements(copilotkit.runtimeEntitlements);
2559
+ setRuntimeEntitlementRetryPending(copilotkit.runtimeEntitlementRetryPending);
2556
2560
  };
2557
2561
  const subscription = copilotkit.subscribe({ onRuntimeConnectionStatusChanged: syncRuntimeInfo });
2558
2562
  syncRuntimeInfo();
@@ -2693,7 +2697,26 @@ window.parent.postMessage({jsonrpc:"2.0",method:"ui/notifications/sandbox-proxy-
2693
2697
  copilotkit,
2694
2698
  executingToolCallIds
2695
2699
  }), [copilotkit, executingToolCallIds]);
2696
- 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;
2697
2720
  return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(SandboxFunctionsContext.Provider, {
2698
2721
  value: sandboxFunctionsList,
2699
2722
  children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(CopilotKitContext.Provider, {
@@ -2713,10 +2736,10 @@ window.parent.postMessage({jsonrpc:"2.0",method:"ui/notifications/sandbox-proxy-
2713
2736
  openRequest: inspectorOpenRequest
2714
2737
  }) : null]
2715
2738
  }),
2716
- runtimeLicenseStatus === "none" && !resolvedPublicKey && /* @__PURE__ */ (0, react_jsx_runtime.jsx)(LicenseWarningBanner, { type: "no_license" }),
2717
- runtimeLicenseStatus === "expired" && /* @__PURE__ */ (0, react_jsx_runtime.jsx)(LicenseWarningBanner, { type: "expired" }),
2718
- runtimeLicenseStatus === "invalid" && /* @__PURE__ */ (0, react_jsx_runtime.jsx)(LicenseWarningBanner, { type: "invalid" }),
2719
- 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" })
2720
2743
  ]
2721
2744
  })
2722
2745
  })
@@ -2774,7 +2797,7 @@ window.parent.postMessage({jsonrpc:"2.0",method:"ui/notifications/sandbox-proxy-
2774
2797
  function useFrontendTool$1(tool, deps) {
2775
2798
  const { copilotkit } = useCopilotKit();
2776
2799
  const extraDeps = deps ?? EMPTY_DEPS;
2777
- (0, react.useEffect)(() => {
2800
+ (0, react.useLayoutEffect)(() => {
2778
2801
  const name = tool.name;
2779
2802
  if (copilotkit.getTool({
2780
2803
  toolName: name,
@@ -2803,6 +2826,8 @@ window.parent.postMessage({jsonrpc:"2.0",method:"ui/notifications/sandbox-proxy-
2803
2826
 
2804
2827
  //#endregion
2805
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 = "*";
2806
2831
  function useHumanInTheLoop$1(tool, deps) {
2807
2832
  const { copilotkit } = useCopilotKit();
2808
2833
  const resolvePromiseRef = (0, react.useRef)(null);
@@ -2838,10 +2863,11 @@ window.parent.postMessage({jsonrpc:"2.0",method:"ui/notifications/sandbox-proxy-
2838
2863
  }, []);
2839
2864
  const RenderComponent = (0, react.useCallback)((props) => {
2840
2865
  const ToolComponent = tool.render;
2866
+ const name = tool.name === WILDCARD_TOOL_NAME ? props.name : tool.name;
2841
2867
  if (props.status === _copilotkit_core.ToolCallStatus.InProgress) {
2842
2868
  const enhancedProps = {
2843
2869
  ...props,
2844
- name: tool.name,
2870
+ name,
2845
2871
  description: tool.description || "",
2846
2872
  agentId: tool.agentId,
2847
2873
  respond: void 0
@@ -2850,7 +2876,7 @@ window.parent.postMessage({jsonrpc:"2.0",method:"ui/notifications/sandbox-proxy-
2850
2876
  } else if (props.status === _copilotkit_core.ToolCallStatus.Executing) {
2851
2877
  const enhancedProps = {
2852
2878
  ...props,
2853
- name: tool.name,
2879
+ name,
2854
2880
  description: tool.description || "",
2855
2881
  agentId: tool.agentId,
2856
2882
  respond
@@ -2859,7 +2885,7 @@ window.parent.postMessage({jsonrpc:"2.0",method:"ui/notifications/sandbox-proxy-
2859
2885
  } else if (props.status === _copilotkit_core.ToolCallStatus.Complete) {
2860
2886
  const enhancedProps = {
2861
2887
  ...props,
2862
- name: tool.name,
2888
+ name,
2863
2889
  description: tool.description || "",
2864
2890
  agentId: tool.agentId,
2865
2891
  respond: void 0
@@ -2879,7 +2905,7 @@ window.parent.postMessage({jsonrpc:"2.0",method:"ui/notifications/sandbox-proxy-
2879
2905
  handler,
2880
2906
  render: RenderComponent
2881
2907
  }, deps);
2882
- (0, react.useEffect)(() => {
2908
+ (0, react.useLayoutEffect)(() => {
2883
2909
  return () => {
2884
2910
  copilotkit.removeHookRenderToolCall(tool.name, tool.agentId);
2885
2911
  };
@@ -3299,8 +3325,12 @@ window.parent.postMessage({jsonrpc:"2.0",method:"ui/notifications/sandbox-proxy-
3299
3325
  }
3300
3326
 
3301
3327
  //#endregion
3302
- //#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. */
3303
3330
  const INTERRUPT_EVENT_NAME = "on_interrupt";
3331
+
3332
+ //#endregion
3333
+ //#region src/v2/hooks/use-interrupt.tsx
3304
3334
  function isPromiseLike(value) {
3305
3335
  return (typeof value === "object" || typeof value === "function") && value !== null && typeof Reflect.get(value, "then") === "function";
3306
3336
  }
@@ -5753,13 +5783,18 @@ window.parent.postMessage({jsonrpc:"2.0",method:"ui/notifications/sandbox-proxy-
5753
5783
  const renderToolCall = useRenderToolCall$1();
5754
5784
  return (0, react.useCallback)((message, messages) => {
5755
5785
  if (!message?.toolCalls?.length) return null;
5756
- const toolCall = message.toolCalls[0];
5757
- if (!toolCall) return null;
5758
- const toolMessage = messages?.find((m) => m.role === "tool" && m.toolCallId === toolCall.id);
5759
- return () => renderToolCall({
5760
- toolCall,
5761
- toolMessage
5762
- });
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
+ };
5763
5798
  }, [renderToolCall]);
5764
5799
  }
5765
5800
 
@@ -6454,20 +6489,24 @@ window.parent.postMessage({jsonrpc:"2.0",method:"ui/notifications/sandbox-proxy-
6454
6489
  if (!render) return null;
6455
6490
  const rendered = render((() => {
6456
6491
  const mappedArgs = args.args;
6492
+ const toolCallName = args.name;
6457
6493
  switch (args.status) {
6458
6494
  case _copilotkit_core.ToolCallStatus.InProgress: return {
6495
+ name: toolCallName,
6459
6496
  args: mappedArgs,
6460
6497
  respond: args.respond,
6461
6498
  status: args.status,
6462
6499
  handler: void 0
6463
6500
  };
6464
6501
  case _copilotkit_core.ToolCallStatus.Executing: return {
6502
+ name: toolCallName,
6465
6503
  args: mappedArgs,
6466
6504
  respond: args.respond,
6467
6505
  status: args.status,
6468
6506
  handler: () => {}
6469
6507
  };
6470
6508
  case _copilotkit_core.ToolCallStatus.Complete: return {
6509
+ name: toolCallName,
6471
6510
  args: mappedArgs,
6472
6511
  respond: args.respond,
6473
6512
  status: args.status,
@@ -6627,10 +6666,21 @@ window.parent.postMessage({jsonrpc:"2.0",method:"ui/notifications/sandbox-proxy-
6627
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.
6628
6667
  */
6629
6668
  function getActionConfig(action) {
6630
- if (action.name === "*") return {
6631
- type: "render",
6632
- action
6633
- };
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
+ }
6634
6684
  if ("renderAndWaitForResponse" in action || "renderAndWait" in action) {
6635
6685
  let render = action.render;
6636
6686
  if (!render && "renderAndWaitForResponse" in action) render = action.renderAndWaitForResponse;
@@ -6941,37 +6991,87 @@ window.parent.postMessage({jsonrpc:"2.0",method:"ui/notifications/sandbox-proxy-
6941
6991
 
6942
6992
  //#endregion
6943
6993
  //#region src/v1-deprecated/hooks/use-agent-nodename.ts
6944
- /**
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
+ /**
6945
7031
  * Tracks the node the agent is currently executing.
6946
7032
  *
6947
7033
  * Backed by state rather than a ref: mutating a ref schedules no render, so
6948
7034
  * consumers such as `useCoAgent().nodeName` kept reporting whichever node was
6949
- * 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.
6950
7037
  */
6951
7038
  function useAgentNodeName(agentName) {
6952
7039
  const { agent } = useAgent({ agentId: agentName });
6953
- const [nodeName, setNodeName] = (0, react.useState)("start");
7040
+ const [nodeNameState, setNodeNameState] = (0, react.useState)(initialAgentNodeNameState);
6954
7041
  (0, react.useEffect)(() => {
7042
+ const transition = (event) => {
7043
+ setNodeNameState((state) => transitionAgentNodeName(state, event));
7044
+ };
7045
+ transition({ type: "reset" });
6955
7046
  if (!agent) return;
6956
7047
  const subscription = agent.subscribe({
6957
7048
  onStepStartedEvent: ({ event }) => {
6958
- setNodeName(event.stepName);
7049
+ transition({
7050
+ type: "stepStarted",
7051
+ nodeName: event.stepName
7052
+ });
6959
7053
  },
6960
7054
  onRunStartedEvent: () => {
6961
- setNodeName("start");
7055
+ transition({ type: "runStarted" });
6962
7056
  },
6963
- onRunFinishedEvent: () => {
6964
- setNodeName("end");
7057
+ onRunFinishedEvent: ({ outcome }) => {
7058
+ transition({
7059
+ type: "runFinished",
7060
+ outcome
7061
+ });
6965
7062
  },
6966
7063
  onRunErrorEvent: () => {
6967
- setNodeName("end");
7064
+ transition({ type: "runError" });
7065
+ },
7066
+ onCustomEvent: ({ event }) => {
7067
+ if (event.name === INTERRUPT_EVENT_NAME) transition({ type: "legacyInterruptReceived" });
6968
7068
  }
6969
7069
  });
6970
7070
  return () => {
6971
7071
  subscription.unsubscribe();
6972
7072
  };
6973
- }, [agent]);
6974
- return nodeName;
7073
+ }, [agent, agentName]);
7074
+ return nodeNameState.nodeName;
6975
7075
  }
6976
7076
 
6977
7077
  //#endregion
@@ -7174,6 +7274,7 @@ window.parent.postMessage({jsonrpc:"2.0",method:"ui/notifications/sandbox-proxy-
7174
7274
  agent?.threadId,
7175
7275
  agent?.isRunning,
7176
7276
  agent?.agentId,
7277
+ nodeName,
7177
7278
  handleStateUpdate,
7178
7279
  options.name
7179
7280
  ]);