@copilotkit/react-core 1.60.2 → 1.61.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -3642,6 +3642,10 @@ const CopilotKitProvider = ({ children, runtimeUrl, headers: headersProp = EMPTY
3642
3642
  ...selfManagedAgents
3643
3643
  }), [agents, selfManagedAgents]);
3644
3644
  const hasLocalAgents = mergedAgents && Object.keys(mergedAgents).length > 0;
3645
+ const hasSelfManagedAgents = Object.keys(selfManagedAgents).length > 0;
3646
+ (0, react.useEffect)(() => {
3647
+ if (hasSelfManagedAgents && !resolvedPublicKey) console.warn("[CopilotKit] `selfManagedAgents` is part of CopilotKit's Enterprise Intelligence offering. Provide a `publicLicenseKey` for production use — contact the CopilotKit team about licensing.");
3648
+ }, [hasSelfManagedAgents, resolvedPublicKey]);
3645
3649
  const headers = typeof headersProp === "function" ? headersProp() : headersProp;
3646
3650
  const mergedHeaders = (0, react.useMemo)(() => {
3647
3651
  if (!resolvedPublicKey) return headers;
@@ -4106,49 +4110,72 @@ function useComponent(config, deps) {
4106
4110
  function useHumanInTheLoop(tool, deps) {
4107
4111
  const { copilotkit } = useCopilotKit();
4108
4112
  const resolvePromiseRef = (0, react.useRef)(null);
4113
+ const cleanupAbortRef = (0, react.useRef)(null);
4109
4114
  const respond = (0, react.useCallback)(async (result) => {
4110
4115
  if (resolvePromiseRef.current) {
4116
+ cleanupAbortRef.current?.();
4117
+ cleanupAbortRef.current = null;
4111
4118
  resolvePromiseRef.current(result);
4112
4119
  resolvePromiseRef.current = null;
4113
4120
  }
4114
4121
  }, []);
4115
- const handler = (0, react.useCallback)(async () => {
4116
- return new Promise((resolve) => {
4122
+ const handler = (0, react.useCallback)(async (_args, context) => {
4123
+ const signal = context?.signal;
4124
+ return new Promise((resolve, reject) => {
4125
+ if (signal?.aborted) {
4126
+ reject(/* @__PURE__ */ new Error("Human-in-the-loop interaction aborted"));
4127
+ return;
4128
+ }
4117
4129
  resolvePromiseRef.current = resolve;
4130
+ if (signal) {
4131
+ const onAbort = () => {
4132
+ cleanupAbortRef.current = null;
4133
+ resolvePromiseRef.current = null;
4134
+ reject(/* @__PURE__ */ new Error("Human-in-the-loop interaction aborted"));
4135
+ };
4136
+ signal.addEventListener("abort", onAbort, { once: true });
4137
+ cleanupAbortRef.current = () => {
4138
+ signal.removeEventListener("abort", onAbort);
4139
+ };
4140
+ }
4118
4141
  });
4119
4142
  }, []);
4120
4143
  const RenderComponent = (0, react.useCallback)((props) => {
4121
4144
  const ToolComponent = tool.render;
4122
- if (props.status === "inProgress") {
4145
+ if (props.status === _copilotkit_core.ToolCallStatus.InProgress) {
4123
4146
  const enhancedProps = {
4124
4147
  ...props,
4125
4148
  name: tool.name,
4126
4149
  description: tool.description || "",
4150
+ agentId: tool.agentId,
4127
4151
  respond: void 0
4128
4152
  };
4129
4153
  return react.default.createElement(ToolComponent, enhancedProps);
4130
- } else if (props.status === "executing") {
4154
+ } else if (props.status === _copilotkit_core.ToolCallStatus.Executing) {
4131
4155
  const enhancedProps = {
4132
4156
  ...props,
4133
4157
  name: tool.name,
4134
4158
  description: tool.description || "",
4159
+ agentId: tool.agentId,
4135
4160
  respond
4136
4161
  };
4137
4162
  return react.default.createElement(ToolComponent, enhancedProps);
4138
- } else if (props.status === "complete") {
4163
+ } else if (props.status === _copilotkit_core.ToolCallStatus.Complete) {
4139
4164
  const enhancedProps = {
4140
4165
  ...props,
4141
4166
  name: tool.name,
4142
4167
  description: tool.description || "",
4168
+ agentId: tool.agentId,
4143
4169
  respond: void 0
4144
4170
  };
4145
4171
  return react.default.createElement(ToolComponent, enhancedProps);
4146
4172
  }
4147
- return react.default.createElement(ToolComponent, props);
4173
+ return props;
4148
4174
  }, [
4149
4175
  tool.render,
4150
4176
  tool.name,
4151
4177
  tool.description,
4178
+ tool.agentId,
4152
4179
  respond
4153
4180
  ]);
4154
4181
  useFrontendTool({
@@ -4815,21 +4842,32 @@ function useThreads$1({ agentId, includeArchived, limit }) {
4815
4842
  const headersKey = (0, react.useMemo)(() => {
4816
4843
  return JSON.stringify(Object.entries(copilotkit.headers ?? {}).sort(([left], [right]) => left.localeCompare(right)));
4817
4844
  }, [copilotkit.headers]);
4845
+ const runtimeStatus = copilotkit.runtimeConnectionStatus;
4846
+ const threadListEndpointSupported = copilotkit.threadEndpoints?.list !== false;
4847
+ const threadMutationsSupported = copilotkit.threadEndpoints?.mutations !== false;
4848
+ const threadEndpointsUnavailable = !!copilotkit.runtimeUrl && runtimeStatus === _copilotkit_core.CopilotKitCoreRuntimeConnectionStatus.Connected && !threadListEndpointSupported;
4818
4849
  const runtimeError = (0, react.useMemo)(() => {
4819
4850
  if (copilotkit.runtimeUrl) return null;
4820
4851
  return /* @__PURE__ */ new Error("Runtime URL is not configured");
4821
4852
  }, [copilotkit.runtimeUrl]);
4853
+ const threadEndpointsError = (0, react.useMemo)(() => {
4854
+ if (!threadEndpointsUnavailable) return null;
4855
+ return /* @__PURE__ */ new Error("Thread endpoints are not available on this CopilotKit runtime");
4856
+ }, [threadEndpointsUnavailable]);
4857
+ const threadMutationsError = (0, react.useMemo)(() => {
4858
+ if (threadMutationsSupported) return null;
4859
+ return /* @__PURE__ */ new Error("Thread mutations are not available on this CopilotKit runtime");
4860
+ }, [threadMutationsSupported]);
4822
4861
  const [hasDispatchedContext, setHasDispatchedContext] = (0, react.useState)(false);
4823
- const preConnectLoading = !!copilotkit.runtimeUrl && !hasDispatchedContext;
4824
- const isLoading = runtimeError ? false : preConnectLoading || storeIsLoading;
4825
- const error = runtimeError ?? storeError;
4862
+ const preConnectLoading = !!copilotkit.runtimeUrl && !threadEndpointsUnavailable && !hasDispatchedContext;
4863
+ const isLoading = runtimeError || threadEndpointsError ? false : preConnectLoading || storeIsLoading;
4864
+ const error = runtimeError ?? threadEndpointsError ?? storeError;
4826
4865
  (0, react.useEffect)(() => {
4827
4866
  store.start();
4828
4867
  return () => {
4829
4868
  store.stop();
4830
4869
  };
4831
4870
  }, [store]);
4832
- const runtimeStatus = copilotkit.runtimeConnectionStatus;
4833
4871
  (0, react.useEffect)(() => {
4834
4872
  copilotkit.registerThreadStore(agentId, store);
4835
4873
  return () => {
@@ -4843,9 +4881,15 @@ function useThreads$1({ agentId, includeArchived, limit }) {
4843
4881
  (0, react.useEffect)(() => {
4844
4882
  if (!copilotkit.runtimeUrl) {
4845
4883
  store.setContext(null);
4884
+ setHasDispatchedContext(false);
4846
4885
  return;
4847
4886
  }
4848
4887
  if (runtimeStatus !== _copilotkit_core.CopilotKitCoreRuntimeConnectionStatus.Connected) return;
4888
+ if (!threadListEndpointSupported) {
4889
+ store.setContext(null);
4890
+ setHasDispatchedContext(false);
4891
+ return;
4892
+ }
4849
4893
  const context = {
4850
4894
  runtimeUrl: copilotkit.runtimeUrl,
4851
4895
  headers: { ...copilotkit.headers },
@@ -4862,13 +4906,20 @@ function useThreads$1({ agentId, includeArchived, limit }) {
4862
4906
  runtimeStatus,
4863
4907
  headersKey,
4864
4908
  copilotkit.intelligence?.wsUrl,
4909
+ threadListEndpointSupported,
4865
4910
  agentId,
4866
4911
  includeArchived,
4867
4912
  limit
4868
4913
  ]);
4869
- const renameThread = (0, react.useCallback)((threadId, name) => store.renameThread(threadId, name), [store]);
4870
- const archiveThread = (0, react.useCallback)((threadId) => store.archiveThread(threadId), [store]);
4871
- const deleteThread = (0, react.useCallback)((threadId) => store.deleteThread(threadId), [store]);
4914
+ const guardMutation = (0, react.useCallback)((mutation) => {
4915
+ return (...args) => {
4916
+ if (threadMutationsError) return Promise.reject(threadMutationsError);
4917
+ return mutation(...args);
4918
+ };
4919
+ }, [threadMutationsError]);
4920
+ const renameThread = (0, react.useMemo)(() => guardMutation((threadId, name) => store.renameThread(threadId, name)), [store, guardMutation]);
4921
+ const archiveThread = (0, react.useMemo)(() => guardMutation((threadId) => store.archiveThread(threadId)), [store, guardMutation]);
4922
+ const deleteThread = (0, react.useMemo)(() => guardMutation((threadId) => store.deleteThread(threadId)), [store, guardMutation]);
4872
4923
  return {
4873
4924
  threads,
4874
4925
  isLoading,
@@ -10110,21 +10161,6 @@ function CopilotListeners() {
10110
10161
 
10111
10162
  //#endregion
10112
10163
  //#region src/components/copilot-provider/copilotkit.tsx
10113
- /**
10114
- * This component will typically wrap your entire application (or a sub-tree of your application where you want to have a copilot). It provides the copilot context to all other components and hooks.
10115
- *
10116
- * ## Example
10117
- *
10118
- * You can find more information about self-hosting CopilotKit [here](/guides/self-hosting).
10119
- *
10120
- * ```tsx
10121
- * import { CopilotKit } from "@copilotkit/react-core";
10122
- *
10123
- * <CopilotKit runtimeUrl="<your-runtime-url>">
10124
- * // ... your app ...
10125
- * </CopilotKit>
10126
- * ```
10127
- */
10128
10164
  function CopilotKit({ children, ...props }) {
10129
10165
  const enabled = shouldShowDevConsole(props.showDevConsole);
10130
10166
  const showInspector = shouldShowDevConsole(props.enableInspector);
@@ -10613,7 +10649,11 @@ function formatFeatureName(featureName) {
10613
10649
  function validateProps(props) {
10614
10650
  const cloudFeatures = Object.keys(props).filter((key) => key.endsWith("_c"));
10615
10651
  const hasApiKey = props.publicApiKey || props.publicLicenseKey;
10616
- if (!props.runtimeUrl && !hasApiKey) throw new _copilotkit_shared.ConfigurationError("Missing required prop: 'runtimeUrl' or 'publicApiKey' or 'publicLicenseKey'");
10652
+ const hasLocalAgents = Object.keys({
10653
+ ...props.agents__unsafe_dev_only,
10654
+ ...props.selfManagedAgents
10655
+ }).length > 0;
10656
+ if (!props.runtimeUrl && !hasApiKey && !hasLocalAgents) throw new _copilotkit_shared.ConfigurationError("Missing required prop: 'runtimeUrl' or 'publicApiKey' or 'publicLicenseKey'");
10617
10657
  if (cloudFeatures.length > 0 && !hasApiKey) throw new _copilotkit_shared.MissingPublicApiKeyError(`Missing required prop: 'publicApiKey' or 'publicLicenseKey' to use cloud features: ${cloudFeatures.map(formatFeatureName).join(", ")}`);
10618
10658
  }
10619
10659
 
@@ -11086,4 +11126,4 @@ Object.defineProperty(exports, 'useToast', {
11086
11126
  return useToast;
11087
11127
  }
11088
11128
  });
11089
- //# sourceMappingURL=copilotkit-CP5uyB2h.cjs.map
11129
+ //# sourceMappingURL=copilotkit-BCJDP8qd.cjs.map