@silmaril-security/sdk 0.11.2 → 0.11.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.
- package/CHANGELOG.md +8 -0
- package/README.md +6 -4
- package/dist/adapters/deepagents.d.cts +1 -1
- package/dist/adapters/deepagents.d.ts +1 -1
- package/dist/adapters/langchain.d.cts +1 -1
- package/dist/adapters/langchain.d.ts +1 -1
- package/dist/adapters/vercel-v4.d.cts +1 -1
- package/dist/adapters/vercel-v4.d.ts +1 -1
- package/dist/adapters/vercel.d.cts +1 -1
- package/dist/adapters/vercel.d.ts +1 -1
- package/dist/{firewall-D8XAQ9gj.d.cts → firewall-BZ8kfq5c.d.cts} +6 -1
- package/dist/{firewall-D8XAQ9gj.d.ts → firewall-BZ8kfq5c.d.ts} +6 -1
- package/dist/index.cjs +19 -6
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +2 -2
- package/dist/index.d.ts +2 -2
- package/dist/index.js +19 -6
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,13 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## 0.11.3
|
|
4
|
+
|
|
5
|
+
- Reject `protect()` with the caller's abort reason when the operation or output
|
|
6
|
+
extractor aborts the caller and then throws synchronously.
|
|
7
|
+
- Document that `flush()` waits for every check queued on the client,
|
|
8
|
+
foreground included, and not for direct `classify()` calls or the operation
|
|
9
|
+
that `protect()` runs.
|
|
10
|
+
|
|
3
11
|
## 0.11.2
|
|
4
12
|
|
|
5
13
|
- Keep protect() responsive to caller cancellation through operation and output handling.
|
package/README.md
CHANGED
|
@@ -35,10 +35,10 @@ This SDK is distributed as an npm package.
|
|
|
35
35
|
npm install @silmaril-security/sdk
|
|
36
36
|
```
|
|
37
37
|
|
|
38
|
-
Pin version 0.11.
|
|
38
|
+
Pin version 0.11.3 for reproducible installs:
|
|
39
39
|
|
|
40
40
|
```sh
|
|
41
|
-
npm install @silmaril-security/sdk@0.11.
|
|
41
|
+
npm install @silmaril-security/sdk@0.11.3
|
|
42
42
|
```
|
|
43
43
|
|
|
44
44
|
Requires Node 20 or later.
|
|
@@ -605,8 +605,10 @@ A background classification retries once, never rejects, logs its failure with
|
|
|
605
605
|
exceed `maxQueued` unjoined checks for its conversation, or
|
|
606
606
|
`maxConcurrent * maxQueued` background checks across all conversations
|
|
607
607
|
(2,048 by default), is dropped with a warning. `await fw.flush()` waits for
|
|
608
|
-
|
|
609
|
-
returns.
|
|
608
|
+
every check queued on the client to finish, foreground or background, for
|
|
609
|
+
example before a serverless handler returns. `protect()` and the parallel or
|
|
610
|
+
background checks of framework adapters are queued. Direct `classify()` calls
|
|
611
|
+
are not, and `flush()` does not wait for the operation that `protect()` runs.
|
|
610
612
|
|
|
611
613
|
## Migration Notes
|
|
612
614
|
|
|
@@ -13,7 +13,7 @@ import * as langchain from 'langchain';
|
|
|
13
13
|
import { CreateAgentParams } from 'langchain';
|
|
14
14
|
import * as _langchain_core_tools from '@langchain/core/tools';
|
|
15
15
|
import { StructuredTool } from '@langchain/core/tools';
|
|
16
|
-
import { h as FirewallMode, b as ClassifyEvent, e as Firewall } from '../firewall-
|
|
16
|
+
import { h as FirewallMode, b as ClassifyEvent, e as Firewall } from '../firewall-BZ8kfq5c.cjs';
|
|
17
17
|
|
|
18
18
|
declare const SAFE_TOOL_MESSAGE = "Silmaril Firewall blocked this tool interaction. Choose a different safe action.";
|
|
19
19
|
declare const SAFE_FINAL_MESSAGE = "Silmaril Firewall stopped this request after repeated unsafe actions.";
|
|
@@ -13,7 +13,7 @@ import * as langchain from 'langchain';
|
|
|
13
13
|
import { CreateAgentParams } from 'langchain';
|
|
14
14
|
import * as _langchain_core_tools from '@langchain/core/tools';
|
|
15
15
|
import { StructuredTool } from '@langchain/core/tools';
|
|
16
|
-
import { h as FirewallMode, b as ClassifyEvent, e as Firewall } from '../firewall-
|
|
16
|
+
import { h as FirewallMode, b as ClassifyEvent, e as Firewall } from '../firewall-BZ8kfq5c.js';
|
|
17
17
|
|
|
18
18
|
declare const SAFE_TOOL_MESSAGE = "Silmaril Firewall blocked this tool interaction. Choose a different safe action.";
|
|
19
19
|
declare const SAFE_FINAL_MESSAGE = "Silmaril Firewall stopped this request after repeated unsafe actions.";
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { RunnableConfig, Runnable, RunnableBinding } from '@langchain/core/runnables';
|
|
2
2
|
import { BaseCallbackHandler } from '@langchain/core/callbacks/base';
|
|
3
|
-
import { e as Firewall, L as LangChainAdapterOptions } from '../firewall-
|
|
3
|
+
import { e as Firewall, L as LangChainAdapterOptions } from '../firewall-BZ8kfq5c.cjs';
|
|
4
4
|
|
|
5
5
|
declare function createLangChainHandler(firewall: Firewall, options?: LangChainAdapterOptions): Promise<BaseCallbackHandler>;
|
|
6
6
|
/** Protect a runnable using its actual invocation config, including direct model/tool calls. */
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { RunnableConfig, Runnable, RunnableBinding } from '@langchain/core/runnables';
|
|
2
2
|
import { BaseCallbackHandler } from '@langchain/core/callbacks/base';
|
|
3
|
-
import { e as Firewall, L as LangChainAdapterOptions } from '../firewall-
|
|
3
|
+
import { e as Firewall, L as LangChainAdapterOptions } from '../firewall-BZ8kfq5c.js';
|
|
4
4
|
|
|
5
5
|
declare function createLangChainHandler(firewall: Firewall, options?: LangChainAdapterOptions): Promise<BaseCallbackHandler>;
|
|
6
6
|
/** Protect a runnable using its actual invocation config, including direct model/tool calls. */
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export { g as FirewallMiddleware, S as createMiddleware } from '../firewall-
|
|
1
|
+
export { g as FirewallMiddleware, S as createMiddleware } from '../firewall-BZ8kfq5c.cjs';
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export { g as FirewallMiddleware, S as createMiddleware } from '../firewall-
|
|
1
|
+
export { g as FirewallMiddleware, S as createMiddleware } from '../firewall-BZ8kfq5c.js';
|
|
@@ -326,7 +326,12 @@ declare class Firewall {
|
|
|
326
326
|
* when the caller's `signal` aborts at any point before `protect()` settles.
|
|
327
327
|
*/
|
|
328
328
|
protect<TResult>(operation: (signal: AbortSignal) => PromiseLike<TResult> | TResult, options: ProtectOptions<TResult>): Promise<TResult>;
|
|
329
|
-
/**
|
|
329
|
+
/**
|
|
330
|
+
* Wait for every check queued on this client, foreground or background.
|
|
331
|
+
* `protect()` and the parallel or background checks of framework adapters are
|
|
332
|
+
* queued. Direct `classify()` and `classifyBatch()` calls are not, and the
|
|
333
|
+
* operation that `protect()` runs is not awaited.
|
|
334
|
+
*/
|
|
330
335
|
flush(): Promise<void>;
|
|
331
336
|
/**
|
|
332
337
|
* @internal Classify in the background with one retry; resolves undefined on failure.
|
|
@@ -326,7 +326,12 @@ declare class Firewall {
|
|
|
326
326
|
* when the caller's `signal` aborts at any point before `protect()` settles.
|
|
327
327
|
*/
|
|
328
328
|
protect<TResult>(operation: (signal: AbortSignal) => PromiseLike<TResult> | TResult, options: ProtectOptions<TResult>): Promise<TResult>;
|
|
329
|
-
/**
|
|
329
|
+
/**
|
|
330
|
+
* Wait for every check queued on this client, foreground or background.
|
|
331
|
+
* `protect()` and the parallel or background checks of framework adapters are
|
|
332
|
+
* queued. Direct `classify()` and `classifyBatch()` calls are not, and the
|
|
333
|
+
* operation that `protect()` runs is not awaited.
|
|
334
|
+
*/
|
|
330
335
|
flush(): Promise<void>;
|
|
331
336
|
/**
|
|
332
337
|
* @internal Classify in the background with one retry; resolves undefined on failure.
|
package/dist/index.cjs
CHANGED
|
@@ -1580,7 +1580,7 @@ function sanitizeText(text) {
|
|
|
1580
1580
|
}
|
|
1581
1581
|
|
|
1582
1582
|
// src/firewall.ts
|
|
1583
|
-
var SDK_VERSION = "0.11.
|
|
1583
|
+
var SDK_VERSION = "0.11.3";
|
|
1584
1584
|
var DEFAULT_TIMEOUT_MS = 1e4;
|
|
1585
1585
|
var DEFAULT_MAX_RETRIES = 5;
|
|
1586
1586
|
var MAX_BACKOFF_SECONDS = 30;
|
|
@@ -1908,7 +1908,7 @@ function createAttemptSignal(timeoutMs, callerSignal) {
|
|
|
1908
1908
|
}
|
|
1909
1909
|
function linkCaller(callerSignal, controller) {
|
|
1910
1910
|
if (callerSignal === void 0) {
|
|
1911
|
-
return { until: (work) => Promise.resolve(work), dispose: () => void 0 };
|
|
1911
|
+
return { until: (work) => Promise.resolve(work), run: (callback) => callback(), dispose: () => void 0 };
|
|
1912
1912
|
}
|
|
1913
1913
|
let onAbort = () => void 0;
|
|
1914
1914
|
const cancelled = new Promise((_resolve, reject) => {
|
|
@@ -1921,6 +1921,14 @@ function linkCaller(callerSignal, controller) {
|
|
|
1921
1921
|
callerSignal.addEventListener("abort", onAbort, { once: true });
|
|
1922
1922
|
return {
|
|
1923
1923
|
until: (work) => Promise.race([work, cancelled]),
|
|
1924
|
+
run: (callback) => {
|
|
1925
|
+
try {
|
|
1926
|
+
return callback();
|
|
1927
|
+
} catch (error) {
|
|
1928
|
+
callerSignal.throwIfAborted();
|
|
1929
|
+
throw error;
|
|
1930
|
+
}
|
|
1931
|
+
},
|
|
1924
1932
|
dispose: () => callerSignal.removeEventListener("abort", onAbort)
|
|
1925
1933
|
};
|
|
1926
1934
|
}
|
|
@@ -2003,10 +2011,10 @@ var Firewall = class {
|
|
|
2003
2011
|
if (observed !== void 0) {
|
|
2004
2012
|
void this.background(text, observed);
|
|
2005
2013
|
}
|
|
2006
|
-
const result2 = await caller.until(operation(controller.signal));
|
|
2014
|
+
const result2 = await caller.until(caller.run(() => operation(controller.signal)));
|
|
2007
2015
|
callerSignal?.throwIfAborted();
|
|
2008
2016
|
if (observed !== void 0 && output !== void 0) {
|
|
2009
|
-
const generated = output(result2);
|
|
2017
|
+
const generated = caller.run(() => output(result2));
|
|
2010
2018
|
callerSignal?.throwIfAborted();
|
|
2011
2019
|
void this.background(generated, outputRequest(observed));
|
|
2012
2020
|
}
|
|
@@ -2028,7 +2036,7 @@ var Firewall = class {
|
|
|
2028
2036
|
]));
|
|
2029
2037
|
callerSignal?.throwIfAborted();
|
|
2030
2038
|
if (output !== void 0) {
|
|
2031
|
-
const generated = output(result);
|
|
2039
|
+
const generated = caller.run(() => output(result));
|
|
2032
2040
|
callerSignal?.throwIfAborted();
|
|
2033
2041
|
await caller.until(this.pending.submit(
|
|
2034
2042
|
() => this.enforce(generated, outputOptions),
|
|
@@ -2041,7 +2049,12 @@ var Firewall = class {
|
|
|
2041
2049
|
caller.dispose();
|
|
2042
2050
|
}
|
|
2043
2051
|
}
|
|
2044
|
-
/**
|
|
2052
|
+
/**
|
|
2053
|
+
* Wait for every check queued on this client, foreground or background.
|
|
2054
|
+
* `protect()` and the parallel or background checks of framework adapters are
|
|
2055
|
+
* queued. Direct `classify()` and `classifyBatch()` calls are not, and the
|
|
2056
|
+
* operation that `protect()` runs is not awaited.
|
|
2057
|
+
*/
|
|
2045
2058
|
flush() {
|
|
2046
2059
|
return this.pending.drain();
|
|
2047
2060
|
}
|