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.
- package/README.md +5 -4
- package/package.json +4 -3
- package/src/circuit-breaker.js +321 -321
- package/src/detector-core.js +3 -3
- package/src/distributed.js +402 -359
- package/src/fuzzer.js +764 -764
- package/src/index.js +23 -7
- package/src/main.js +6 -2
- package/src/mcp-security-runtime.js +30 -5
- package/src/mcp-server.js +12 -8
- package/src/middleware.js +303 -208
- package/src/multi-agent.js +421 -404
- package/src/pii.js +401 -390
- package/src/stream-scanner.js +34 -4
- package/src/testing.js +505 -505
- package/src/utils.js +199 -83
- package/types/index.d.ts +374 -0
package/src/stream-scanner.js
CHANGED
|
@@ -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
|
-
|
|
786
|
-
|
|
787
|
-
|
|
788
|
-
|
|
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 {
|