@copilotkit/react-core 1.66.2 → 1.66.4

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.
@@ -715,6 +715,8 @@ function useInterrupt(config) {
715
715
  pendingRef.current = pending;
716
716
  const [handlerResult, setHandlerResult] = (0, react.useState)(null);
717
717
  const interruptStateRef = (0, react.useRef)(new _copilotkit_core.ɵInterruptState());
718
+ const interruptRunIdsRef = (0, react.useRef)(/* @__PURE__ */ new Map());
719
+ const legacyRunIdRef = (0, react.useRef)(void 0);
718
720
  (0, react.useEffect)(() => {
719
721
  const interruptState = interruptStateRef.current;
720
722
  let localLegacy = null;
@@ -727,19 +729,26 @@ function useInterrupt(config) {
727
729
  };
728
730
  },
729
731
  onRunFinishedEvent: (params) => {
730
- if (params.outcome === "interrupt") localStandard = params.interrupts;
732
+ if (params.outcome === "interrupt") {
733
+ const runId = params.input.runId;
734
+ for (const interrupt of params.interrupts) interruptRunIdsRef.current.set(interrupt.id, runId);
735
+ localStandard = params.interrupts;
736
+ }
731
737
  },
732
738
  onRunStartedEvent: () => {
733
739
  localLegacy = null;
734
740
  localStandard = null;
741
+ interruptRunIdsRef.current.clear();
742
+ legacyRunIdRef.current = void 0;
735
743
  interruptState.clear();
736
744
  setPending(null);
737
745
  },
738
- onRunFinalized: () => {
746
+ onRunFinalized: (params) => {
739
747
  if (localStandard && localStandard.length > 0) {
740
748
  interruptState.setStandard(localStandard);
741
749
  setPending(interruptState.pending);
742
750
  } else if (localLegacy) {
751
+ legacyRunIdRef.current = params.input.runId;
743
752
  interruptState.setLegacy(localLegacy);
744
753
  setPending(interruptState.pending);
745
754
  }
@@ -749,6 +758,8 @@ function useInterrupt(config) {
749
758
  onRunFailed: () => {
750
759
  localLegacy = null;
751
760
  localStandard = null;
761
+ interruptRunIdsRef.current.clear();
762
+ legacyRunIdRef.current = void 0;
752
763
  interruptState.clear();
753
764
  setPending(null);
754
765
  }
@@ -763,18 +774,22 @@ function useInterrupt(config) {
763
774
  if (!current) return;
764
775
  if (current.kind === "standard" && current.interrupts.length > 1 && interruptId === void 0) console.warn(`[CopilotKit] useInterrupt: resolve()/cancel() called without an interruptId while ${current.interrupts.length} interrupts are open; defaulting to the first. Pass an interruptId to address a specific interrupt.`);
765
776
  const decision = interruptStateRef.current.resolve(payload, interruptId);
766
- if (decision.kind === "legacy-resume") try {
767
- return await copilotkit.runAgent({
768
- agent,
769
- forwardedProps: { command: {
770
- resume: decision.payload,
771
- interruptEvent: decision.interruptValue
772
- } }
773
- });
774
- } catch (err) {
775
- console.error("[CopilotKit] useInterrupt resolve: runAgent rejected; clearing pending + rethrowing", err);
776
- setPending(null);
777
- throw err;
777
+ if (decision.kind === "legacy-resume") {
778
+ const runId = legacyRunIdRef.current;
779
+ try {
780
+ return await copilotkit.runAgent({
781
+ agent,
782
+ ...runId !== void 0 ? { runId } : {},
783
+ forwardedProps: { command: {
784
+ resume: decision.payload,
785
+ interruptEvent: decision.interruptValue
786
+ } }
787
+ });
788
+ } catch (err) {
789
+ console.error("[CopilotKit] useInterrupt resolve: runAgent rejected; clearing pending + rethrowing", err);
790
+ setPending(null);
791
+ throw err;
792
+ }
778
793
  }
779
794
  if (decision.kind === "expired") {
780
795
  console.error(`[CopilotKit] useInterrupt: interrupt ${decision.interrupt.id} expired at ${decision.interrupt.expiresAt}; not resuming.`);
@@ -783,6 +798,7 @@ function useInterrupt(config) {
783
798
  return;
784
799
  }
785
800
  if (decision.kind !== "resume") return;
801
+ const runId = decision.resume.map((entry) => interruptRunIdsRef.current.get(entry.interruptId)).find((candidate) => candidate !== void 0);
786
802
  for (const toolResult of decision.toolResults) agent.addMessage({
787
803
  id: (0, _ag_ui_client.randomUUID)(),
788
804
  role: "tool",
@@ -792,7 +808,8 @@ function useInterrupt(config) {
792
808
  try {
793
809
  return await copilotkit.runAgent({
794
810
  agent,
795
- resume: decision.resume
811
+ resume: decision.resume,
812
+ ...runId !== void 0 ? { runId } : {}
796
813
  });
797
814
  } catch (err) {
798
815
  console.error("[CopilotKit] useInterrupt resolve: runAgent rejected; clearing pending + rethrowing", err);
@@ -819,6 +836,7 @@ function useInterrupt(config) {
819
836
  return;
820
837
  }
821
838
  if (decision.kind !== "resume") return;
839
+ const runId = decision.resume.map((entry) => interruptRunIdsRef.current.get(entry.interruptId)).find((candidate) => candidate !== void 0);
822
840
  for (const toolResult of decision.toolResults) agent.addMessage({
823
841
  id: (0, _ag_ui_client.randomUUID)(),
824
842
  role: "tool",
@@ -828,7 +846,8 @@ function useInterrupt(config) {
828
846
  try {
829
847
  return await copilotkit.runAgent({
830
848
  agent,
831
- resume: decision.resume
849
+ resume: decision.resume,
850
+ ...runId !== void 0 ? { runId } : {}
832
851
  });
833
852
  } catch (err) {
834
853
  console.error("[CopilotKit] useInterrupt resolve: runAgent rejected; clearing pending + rethrowing", err);