@copilotkit/react-core 1.66.2 → 1.66.3

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.
@@ -686,6 +686,8 @@ function useInterrupt(config) {
686
686
  pendingRef.current = pending;
687
687
  const [handlerResult, setHandlerResult] = useState(null);
688
688
  const interruptStateRef = useRef(new ɵInterruptState());
689
+ const interruptRunIdsRef = useRef(/* @__PURE__ */ new Map());
690
+ const legacyRunIdRef = useRef(void 0);
689
691
  useEffect(() => {
690
692
  const interruptState = interruptStateRef.current;
691
693
  let localLegacy = null;
@@ -698,19 +700,26 @@ function useInterrupt(config) {
698
700
  };
699
701
  },
700
702
  onRunFinishedEvent: (params) => {
701
- if (params.outcome === "interrupt") localStandard = params.interrupts;
703
+ if (params.outcome === "interrupt") {
704
+ const runId = params.input.runId;
705
+ for (const interrupt of params.interrupts) interruptRunIdsRef.current.set(interrupt.id, runId);
706
+ localStandard = params.interrupts;
707
+ }
702
708
  },
703
709
  onRunStartedEvent: () => {
704
710
  localLegacy = null;
705
711
  localStandard = null;
712
+ interruptRunIdsRef.current.clear();
713
+ legacyRunIdRef.current = void 0;
706
714
  interruptState.clear();
707
715
  setPending(null);
708
716
  },
709
- onRunFinalized: () => {
717
+ onRunFinalized: (params) => {
710
718
  if (localStandard && localStandard.length > 0) {
711
719
  interruptState.setStandard(localStandard);
712
720
  setPending(interruptState.pending);
713
721
  } else if (localLegacy) {
722
+ legacyRunIdRef.current = params.input.runId;
714
723
  interruptState.setLegacy(localLegacy);
715
724
  setPending(interruptState.pending);
716
725
  }
@@ -720,6 +729,8 @@ function useInterrupt(config) {
720
729
  onRunFailed: () => {
721
730
  localLegacy = null;
722
731
  localStandard = null;
732
+ interruptRunIdsRef.current.clear();
733
+ legacyRunIdRef.current = void 0;
723
734
  interruptState.clear();
724
735
  setPending(null);
725
736
  }
@@ -734,18 +745,22 @@ function useInterrupt(config) {
734
745
  if (!current) return;
735
746
  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.`);
736
747
  const decision = interruptStateRef.current.resolve(payload, interruptId);
737
- if (decision.kind === "legacy-resume") try {
738
- return await copilotkit.runAgent({
739
- agent,
740
- forwardedProps: { command: {
741
- resume: decision.payload,
742
- interruptEvent: decision.interruptValue
743
- } }
744
- });
745
- } catch (err) {
746
- console.error("[CopilotKit] useInterrupt resolve: runAgent rejected; clearing pending + rethrowing", err);
747
- setPending(null);
748
- throw err;
748
+ if (decision.kind === "legacy-resume") {
749
+ const runId = legacyRunIdRef.current;
750
+ try {
751
+ return await copilotkit.runAgent({
752
+ agent,
753
+ ...runId !== void 0 ? { runId } : {},
754
+ forwardedProps: { command: {
755
+ resume: decision.payload,
756
+ interruptEvent: decision.interruptValue
757
+ } }
758
+ });
759
+ } catch (err) {
760
+ console.error("[CopilotKit] useInterrupt resolve: runAgent rejected; clearing pending + rethrowing", err);
761
+ setPending(null);
762
+ throw err;
763
+ }
749
764
  }
750
765
  if (decision.kind === "expired") {
751
766
  console.error(`[CopilotKit] useInterrupt: interrupt ${decision.interrupt.id} expired at ${decision.interrupt.expiresAt}; not resuming.`);
@@ -754,6 +769,7 @@ function useInterrupt(config) {
754
769
  return;
755
770
  }
756
771
  if (decision.kind !== "resume") return;
772
+ const runId = decision.resume.map((entry) => interruptRunIdsRef.current.get(entry.interruptId)).find((candidate) => candidate !== void 0);
757
773
  for (const toolResult of decision.toolResults) agent.addMessage({
758
774
  id: randomUUID$1(),
759
775
  role: "tool",
@@ -763,7 +779,8 @@ function useInterrupt(config) {
763
779
  try {
764
780
  return await copilotkit.runAgent({
765
781
  agent,
766
- resume: decision.resume
782
+ resume: decision.resume,
783
+ ...runId !== void 0 ? { runId } : {}
767
784
  });
768
785
  } catch (err) {
769
786
  console.error("[CopilotKit] useInterrupt resolve: runAgent rejected; clearing pending + rethrowing", err);
@@ -790,6 +807,7 @@ function useInterrupt(config) {
790
807
  return;
791
808
  }
792
809
  if (decision.kind !== "resume") return;
810
+ const runId = decision.resume.map((entry) => interruptRunIdsRef.current.get(entry.interruptId)).find((candidate) => candidate !== void 0);
793
811
  for (const toolResult of decision.toolResults) agent.addMessage({
794
812
  id: randomUUID$1(),
795
813
  role: "tool",
@@ -799,7 +817,8 @@ function useInterrupt(config) {
799
817
  try {
800
818
  return await copilotkit.runAgent({
801
819
  agent,
802
- resume: decision.resume
820
+ resume: decision.resume,
821
+ ...runId !== void 0 ? { runId } : {}
803
822
  });
804
823
  } catch (err) {
805
824
  console.error("[CopilotKit] useInterrupt resolve: runAgent rejected; clearing pending + rethrowing", err);