agentshield-sdk 7.2.0 → 7.2.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.
@@ -551,6 +551,26 @@ class StreamScanner extends EventEmitter {
551
551
  const iterable = _eventEmitterToAsyncIterable(emitter);
552
552
  return this.wrap(iterable);
553
553
  }
554
+
555
+ /**
556
+ * Wrap a Promise that resolves to a stream/async iterable.
557
+ * Safely handles rejection before and during iteration.
558
+ *
559
+ * @param {Promise<AsyncIterable>} streamPromise - A Promise resolving to an async iterable.
560
+ * @param {object} [options] - Options passed to wrap().
561
+ * @returns {AsyncGenerator} Yields chunks with scanning applied.
562
+ */
563
+ async *wrapPromise(streamPromise, options = {}) {
564
+ let stream;
565
+ try {
566
+ stream = await streamPromise;
567
+ } catch (err) {
568
+ this._streamError = err;
569
+ this.finalize();
570
+ throw err;
571
+ }
572
+ yield* this.wrap(stream, options);
573
+ }
554
574
  }
555
575
 
556
576
  // =========================================================================
@@ -782,10 +802,20 @@ async function scanAsyncIterator(iterator, options = {}) {
782
802
  const scanner = new StreamScanner(scannerOpts);
783
803
  const wrapped = scanner.wrap(iterator, { extractText });
784
804
 
785
- // Consume the wrapped iterator fully
786
- // eslint-disable-next-line no-unused-vars
787
- for await (const _chunk of wrapped) {
788
- // consumed side effect is the scanning
805
+ try {
806
+ // Consume the wrapped iterator fully
807
+ // eslint-disable-next-line no-unused-vars
808
+ for await (const _chunk of wrapped) {
809
+ // consumed - side effect is the scanning
810
+ }
811
+ } catch (err) {
812
+ // Ensure finalization on error and attach the error to result
813
+ scanner._streamError = scanner._streamError || err;
814
+ if (!scanner._ended) {
815
+ scanner.finalize();
816
+ }
817
+ // Re-throw so callers know the stream failed
818
+ throw err;
789
819
  }
790
820
 
791
821
  return {