agents 0.17.0 → 0.17.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.
@@ -780,6 +780,8 @@ function useAgentChat(options) {
780
780
  const resumeStreamRef = useRef(resumeStream);
781
781
  resumeStreamRef.current = resumeStream;
782
782
  const hasConnectedOnceRef = useRef(false);
783
+ const resumeInFlightRef = useRef(false);
784
+ const resumeGenerationRef = useRef(0);
783
785
  const resumingToolContinuationRef = useRef(false);
784
786
  const pendingToolContinuationRef = useRef(false);
785
787
  const observedToolContinuationRequestIdRef = useRef(null);
@@ -1323,8 +1325,15 @@ function useAgentChat(options) {
1323
1325
  hasConnectedOnceRef.current = true;
1324
1326
  return;
1325
1327
  }
1326
- if (!resume || statusRef.current !== "ready" || resumingToolContinuationRef.current || customTransport.isAwaitingResume()) return;
1327
- Promise.resolve(resumeStreamRef.current?.()).catch(() => {});
1328
+ if (!resume || statusRef.current !== "ready" || resumingToolContinuationRef.current || resumeInFlightRef.current || customTransport.isAwaitingResume()) return;
1329
+ const resumeStreamFn = resumeStreamRef.current;
1330
+ if (!resumeStreamFn) return;
1331
+ resumeInFlightRef.current = true;
1332
+ const myGeneration = resumeGenerationRef.current;
1333
+ Promise.resolve(resumeStreamFn()).catch(() => {}).finally(() => {
1334
+ if (resumeGenerationRef.current !== myGeneration) return;
1335
+ resumeInFlightRef.current = false;
1336
+ });
1328
1337
  }
1329
1338
  agent.addEventListener("message", onAgentMessage);
1330
1339
  agent.addEventListener("close", onAgentClose);
@@ -1339,6 +1348,8 @@ function useAgentChat(options) {
1339
1348
  setIsRecovering(false);
1340
1349
  protectedStreamingAssistantRef.current = null;
1341
1350
  localResponseIds.clear();
1351
+ resumeGenerationRef.current++;
1352
+ resumeInFlightRef.current = false;
1342
1353
  };
1343
1354
  }, [
1344
1355
  agent,