@copilotkit/react-core 1.61.0 → 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.
@@ -4096,15 +4096,34 @@ window.parent.postMessage({jsonrpc:"2.0",method:"ui/notifications/sandbox-proxy-
4096
4096
  function useHumanInTheLoop(tool, deps) {
4097
4097
  const { copilotkit } = useCopilotKit();
4098
4098
  const resolvePromiseRef = (0, react.useRef)(null);
4099
+ const cleanupAbortRef = (0, react.useRef)(null);
4099
4100
  const respond = (0, react.useCallback)(async (result) => {
4100
4101
  if (resolvePromiseRef.current) {
4102
+ cleanupAbortRef.current?.();
4103
+ cleanupAbortRef.current = null;
4101
4104
  resolvePromiseRef.current(result);
4102
4105
  resolvePromiseRef.current = null;
4103
4106
  }
4104
4107
  }, []);
4105
- const handler = (0, react.useCallback)(async () => {
4106
- return new Promise((resolve) => {
4108
+ const handler = (0, react.useCallback)(async (_args, context) => {
4109
+ const signal = context?.signal;
4110
+ return new Promise((resolve, reject) => {
4111
+ if (signal?.aborted) {
4112
+ reject(/* @__PURE__ */ new Error("Human-in-the-loop interaction aborted"));
4113
+ return;
4114
+ }
4107
4115
  resolvePromiseRef.current = resolve;
4116
+ if (signal) {
4117
+ const onAbort = () => {
4118
+ cleanupAbortRef.current = null;
4119
+ resolvePromiseRef.current = null;
4120
+ reject(/* @__PURE__ */ new Error("Human-in-the-loop interaction aborted"));
4121
+ };
4122
+ signal.addEventListener("abort", onAbort, { once: true });
4123
+ cleanupAbortRef.current = () => {
4124
+ signal.removeEventListener("abort", onAbort);
4125
+ };
4126
+ }
4108
4127
  });
4109
4128
  }, []);
4110
4129
  const RenderComponent = (0, react.useCallback)((props) => {
@@ -4809,21 +4828,32 @@ window.parent.postMessage({jsonrpc:"2.0",method:"ui/notifications/sandbox-proxy-
4809
4828
  const headersKey = (0, react.useMemo)(() => {
4810
4829
  return JSON.stringify(Object.entries(copilotkit.headers ?? {}).sort(([left], [right]) => left.localeCompare(right)));
4811
4830
  }, [copilotkit.headers]);
4831
+ const runtimeStatus = copilotkit.runtimeConnectionStatus;
4832
+ const threadListEndpointSupported = copilotkit.threadEndpoints?.list !== false;
4833
+ const threadMutationsSupported = copilotkit.threadEndpoints?.mutations !== false;
4834
+ const threadEndpointsUnavailable = !!copilotkit.runtimeUrl && runtimeStatus === _copilotkit_core.CopilotKitCoreRuntimeConnectionStatus.Connected && !threadListEndpointSupported;
4812
4835
  const runtimeError = (0, react.useMemo)(() => {
4813
4836
  if (copilotkit.runtimeUrl) return null;
4814
4837
  return /* @__PURE__ */ new Error("Runtime URL is not configured");
4815
4838
  }, [copilotkit.runtimeUrl]);
4839
+ const threadEndpointsError = (0, react.useMemo)(() => {
4840
+ if (!threadEndpointsUnavailable) return null;
4841
+ return /* @__PURE__ */ new Error("Thread endpoints are not available on this CopilotKit runtime");
4842
+ }, [threadEndpointsUnavailable]);
4843
+ const threadMutationsError = (0, react.useMemo)(() => {
4844
+ if (threadMutationsSupported) return null;
4845
+ return /* @__PURE__ */ new Error("Thread mutations are not available on this CopilotKit runtime");
4846
+ }, [threadMutationsSupported]);
4816
4847
  const [hasDispatchedContext, setHasDispatchedContext] = (0, react.useState)(false);
4817
- const preConnectLoading = !!copilotkit.runtimeUrl && !hasDispatchedContext;
4818
- const isLoading = runtimeError ? false : preConnectLoading || storeIsLoading;
4819
- const error = runtimeError ?? storeError;
4848
+ const preConnectLoading = !!copilotkit.runtimeUrl && !threadEndpointsUnavailable && !hasDispatchedContext;
4849
+ const isLoading = runtimeError || threadEndpointsError ? false : preConnectLoading || storeIsLoading;
4850
+ const error = runtimeError ?? threadEndpointsError ?? storeError;
4820
4851
  (0, react.useEffect)(() => {
4821
4852
  store.start();
4822
4853
  return () => {
4823
4854
  store.stop();
4824
4855
  };
4825
4856
  }, [store]);
4826
- const runtimeStatus = copilotkit.runtimeConnectionStatus;
4827
4857
  (0, react.useEffect)(() => {
4828
4858
  copilotkit.registerThreadStore(agentId, store);
4829
4859
  return () => {
@@ -4837,9 +4867,15 @@ window.parent.postMessage({jsonrpc:"2.0",method:"ui/notifications/sandbox-proxy-
4837
4867
  (0, react.useEffect)(() => {
4838
4868
  if (!copilotkit.runtimeUrl) {
4839
4869
  store.setContext(null);
4870
+ setHasDispatchedContext(false);
4840
4871
  return;
4841
4872
  }
4842
4873
  if (runtimeStatus !== _copilotkit_core.CopilotKitCoreRuntimeConnectionStatus.Connected) return;
4874
+ if (!threadListEndpointSupported) {
4875
+ store.setContext(null);
4876
+ setHasDispatchedContext(false);
4877
+ return;
4878
+ }
4843
4879
  const context = {
4844
4880
  runtimeUrl: copilotkit.runtimeUrl,
4845
4881
  headers: { ...copilotkit.headers },
@@ -4856,13 +4892,20 @@ window.parent.postMessage({jsonrpc:"2.0",method:"ui/notifications/sandbox-proxy-
4856
4892
  runtimeStatus,
4857
4893
  headersKey,
4858
4894
  copilotkit.intelligence?.wsUrl,
4895
+ threadListEndpointSupported,
4859
4896
  agentId,
4860
4897
  includeArchived,
4861
4898
  limit
4862
4899
  ]);
4863
- const renameThread = (0, react.useCallback)((threadId, name) => store.renameThread(threadId, name), [store]);
4864
- const archiveThread = (0, react.useCallback)((threadId) => store.archiveThread(threadId), [store]);
4865
- const deleteThread = (0, react.useCallback)((threadId) => store.deleteThread(threadId), [store]);
4900
+ const guardMutation = (0, react.useCallback)((mutation) => {
4901
+ return (...args) => {
4902
+ if (threadMutationsError) return Promise.reject(threadMutationsError);
4903
+ return mutation(...args);
4904
+ };
4905
+ }, [threadMutationsError]);
4906
+ const renameThread = (0, react.useMemo)(() => guardMutation((threadId, name) => store.renameThread(threadId, name)), [store, guardMutation]);
4907
+ const archiveThread = (0, react.useMemo)(() => guardMutation((threadId) => store.archiveThread(threadId)), [store, guardMutation]);
4908
+ const deleteThread = (0, react.useMemo)(() => guardMutation((threadId) => store.deleteThread(threadId)), [store, guardMutation]);
4866
4909
  return {
4867
4910
  threads,
4868
4911
  isLoading,