@silmaril-security/sdk 0.11.1 → 0.11.2
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 +4 -0
- package/README.md +10 -3
- 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-BD4YdAmB.d.cts → firewall-D8XAQ9gj.d.cts} +10 -1
- package/dist/{firewall-BD4YdAmB.d.ts → firewall-D8XAQ9gj.d.ts} +10 -1
- package/dist/index.cjs +64 -30
- 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 +64 -30
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.d.cts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { H as HookLabel, B as BlockResult, R as ReviewLevel } from './firewall-
|
|
2
|
-
export { A as ALL_HOOKS, C as ClassificationMetadata, a as ClassifyBatchOptions, b as ClassifyEvent, c as ClassifyOptions, D as DEFAULT_HOOKS, d as DEFAULT_TIMEOUT_MS, F as FIREWALL_HOOK_TO_LABEL, e as Firewall, f as FirewallHook, g as FirewallMiddleware, h as FirewallMode, i as FirewallOptions, G as GovernanceAction, j as GovernanceContext, k as GovernanceDecision, l as GovernanceResource, m as GovernanceResourceKind, n as HARMFUL_OUTCOMES, o as HarmfulOutcome, I as INPUT_HOOKS, K as KnownHarmfulOutcome, p as KnownPrimaryOutcome, L as LangChainAdapterOptions, q as LangChainFirewallHandler, M as MiddlewareOptions, O as OUTCOME_DESCRIPTIONS, r as OUTPUT_HOOKS, s as Outcome, P as PRIMARY_OUTCOMES, t as Prediction, u as PrimaryOutcome, v as ProtectOptions, U as UnknownOutcome, w as isHarmfulOutcome, x as isPrimaryOutcome, y as normalizeHarmfulOutcome, z as normalizeHarmfulOutcomeMap, E as normalizePrimaryOutcome, J as prependHook, N as prependToolName, Q as resolveHooks } from './firewall-
|
|
1
|
+
import { H as HookLabel, B as BlockResult, R as ReviewLevel } from './firewall-D8XAQ9gj.cjs';
|
|
2
|
+
export { A as ALL_HOOKS, C as ClassificationMetadata, a as ClassifyBatchOptions, b as ClassifyEvent, c as ClassifyOptions, D as DEFAULT_HOOKS, d as DEFAULT_TIMEOUT_MS, F as FIREWALL_HOOK_TO_LABEL, e as Firewall, f as FirewallHook, g as FirewallMiddleware, h as FirewallMode, i as FirewallOptions, G as GovernanceAction, j as GovernanceContext, k as GovernanceDecision, l as GovernanceResource, m as GovernanceResourceKind, n as HARMFUL_OUTCOMES, o as HarmfulOutcome, I as INPUT_HOOKS, K as KnownHarmfulOutcome, p as KnownPrimaryOutcome, L as LangChainAdapterOptions, q as LangChainFirewallHandler, M as MiddlewareOptions, O as OUTCOME_DESCRIPTIONS, r as OUTPUT_HOOKS, s as Outcome, P as PRIMARY_OUTCOMES, t as Prediction, u as PrimaryOutcome, v as ProtectOptions, U as UnknownOutcome, w as isHarmfulOutcome, x as isPrimaryOutcome, y as normalizeHarmfulOutcome, z as normalizeHarmfulOutcomeMap, E as normalizePrimaryOutcome, J as prependHook, N as prependToolName, Q as resolveHooks } from './firewall-D8XAQ9gj.cjs';
|
|
3
3
|
|
|
4
4
|
interface MalformedInputDetails {
|
|
5
5
|
field?: string;
|
package/dist/index.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { H as HookLabel, B as BlockResult, R as ReviewLevel } from './firewall-
|
|
2
|
-
export { A as ALL_HOOKS, C as ClassificationMetadata, a as ClassifyBatchOptions, b as ClassifyEvent, c as ClassifyOptions, D as DEFAULT_HOOKS, d as DEFAULT_TIMEOUT_MS, F as FIREWALL_HOOK_TO_LABEL, e as Firewall, f as FirewallHook, g as FirewallMiddleware, h as FirewallMode, i as FirewallOptions, G as GovernanceAction, j as GovernanceContext, k as GovernanceDecision, l as GovernanceResource, m as GovernanceResourceKind, n as HARMFUL_OUTCOMES, o as HarmfulOutcome, I as INPUT_HOOKS, K as KnownHarmfulOutcome, p as KnownPrimaryOutcome, L as LangChainAdapterOptions, q as LangChainFirewallHandler, M as MiddlewareOptions, O as OUTCOME_DESCRIPTIONS, r as OUTPUT_HOOKS, s as Outcome, P as PRIMARY_OUTCOMES, t as Prediction, u as PrimaryOutcome, v as ProtectOptions, U as UnknownOutcome, w as isHarmfulOutcome, x as isPrimaryOutcome, y as normalizeHarmfulOutcome, z as normalizeHarmfulOutcomeMap, E as normalizePrimaryOutcome, J as prependHook, N as prependToolName, Q as resolveHooks } from './firewall-
|
|
1
|
+
import { H as HookLabel, B as BlockResult, R as ReviewLevel } from './firewall-D8XAQ9gj.js';
|
|
2
|
+
export { A as ALL_HOOKS, C as ClassificationMetadata, a as ClassifyBatchOptions, b as ClassifyEvent, c as ClassifyOptions, D as DEFAULT_HOOKS, d as DEFAULT_TIMEOUT_MS, F as FIREWALL_HOOK_TO_LABEL, e as Firewall, f as FirewallHook, g as FirewallMiddleware, h as FirewallMode, i as FirewallOptions, G as GovernanceAction, j as GovernanceContext, k as GovernanceDecision, l as GovernanceResource, m as GovernanceResourceKind, n as HARMFUL_OUTCOMES, o as HarmfulOutcome, I as INPUT_HOOKS, K as KnownHarmfulOutcome, p as KnownPrimaryOutcome, L as LangChainAdapterOptions, q as LangChainFirewallHandler, M as MiddlewareOptions, O as OUTCOME_DESCRIPTIONS, r as OUTPUT_HOOKS, s as Outcome, P as PRIMARY_OUTCOMES, t as Prediction, u as PrimaryOutcome, v as ProtectOptions, U as UnknownOutcome, w as isHarmfulOutcome, x as isPrimaryOutcome, y as normalizeHarmfulOutcome, z as normalizeHarmfulOutcomeMap, E as normalizePrimaryOutcome, J as prependHook, N as prependToolName, Q as resolveHooks } from './firewall-D8XAQ9gj.js';
|
|
3
3
|
|
|
4
4
|
interface MalformedInputDetails {
|
|
5
5
|
field?: string;
|
package/dist/index.js
CHANGED
|
@@ -1527,7 +1527,7 @@ function sanitizeText(text) {
|
|
|
1527
1527
|
}
|
|
1528
1528
|
|
|
1529
1529
|
// src/firewall.ts
|
|
1530
|
-
var SDK_VERSION = "0.11.
|
|
1530
|
+
var SDK_VERSION = "0.11.2";
|
|
1531
1531
|
var DEFAULT_TIMEOUT_MS = 1e4;
|
|
1532
1532
|
var DEFAULT_MAX_RETRIES = 5;
|
|
1533
1533
|
var MAX_BACKOFF_SECONDS = 30;
|
|
@@ -1853,6 +1853,24 @@ function createAttemptSignal(timeoutMs, callerSignal) {
|
|
|
1853
1853
|
}
|
|
1854
1854
|
};
|
|
1855
1855
|
}
|
|
1856
|
+
function linkCaller(callerSignal, controller) {
|
|
1857
|
+
if (callerSignal === void 0) {
|
|
1858
|
+
return { until: (work) => Promise.resolve(work), dispose: () => void 0 };
|
|
1859
|
+
}
|
|
1860
|
+
let onAbort = () => void 0;
|
|
1861
|
+
const cancelled = new Promise((_resolve, reject) => {
|
|
1862
|
+
onAbort = () => {
|
|
1863
|
+
reject(callerSignal.reason);
|
|
1864
|
+
controller.abort(callerSignal.reason);
|
|
1865
|
+
};
|
|
1866
|
+
});
|
|
1867
|
+
cancelled.catch(() => void 0);
|
|
1868
|
+
callerSignal.addEventListener("abort", onAbort, { once: true });
|
|
1869
|
+
return {
|
|
1870
|
+
until: (work) => Promise.race([work, cancelled]),
|
|
1871
|
+
dispose: () => callerSignal.removeEventListener("abort", onAbort)
|
|
1872
|
+
};
|
|
1873
|
+
}
|
|
1856
1874
|
function sleep(ms, signal) {
|
|
1857
1875
|
return new Promise((resolve, reject) => {
|
|
1858
1876
|
if (signal?.aborted) {
|
|
@@ -1916,43 +1934,59 @@ var Firewall = class {
|
|
|
1916
1934
|
}
|
|
1917
1935
|
/**
|
|
1918
1936
|
* Run an operation while its input is classified and withhold a blocked result.
|
|
1919
|
-
* The operation's signal aborts when a block arrives before it finishes
|
|
1937
|
+
* The operation's signal aborts when a block arrives before it finishes, and
|
|
1938
|
+
* when the caller's `signal` aborts at any point before `protect()` settles.
|
|
1920
1939
|
*/
|
|
1921
1940
|
async protect(operation, options) {
|
|
1922
1941
|
const { text, output, ...request } = options;
|
|
1923
1942
|
const requestedMode = validateMode(options.mode) ?? this.mode;
|
|
1943
|
+
const callerSignal = request.signal;
|
|
1944
|
+
callerSignal?.throwIfAborted();
|
|
1924
1945
|
const controller = new AbortController();
|
|
1925
|
-
|
|
1926
|
-
|
|
1927
|
-
if (
|
|
1928
|
-
|
|
1946
|
+
const caller = linkCaller(callerSignal, controller);
|
|
1947
|
+
try {
|
|
1948
|
+
if (requestedMode === "shadow" || requestedMode === "warn") {
|
|
1949
|
+
const observed = this.observable(request);
|
|
1950
|
+
if (observed !== void 0) {
|
|
1951
|
+
void this.background(text, observed);
|
|
1952
|
+
}
|
|
1953
|
+
const result2 = await caller.until(operation(controller.signal));
|
|
1954
|
+
callerSignal?.throwIfAborted();
|
|
1955
|
+
if (observed !== void 0 && output !== void 0) {
|
|
1956
|
+
const generated = output(result2);
|
|
1957
|
+
callerSignal?.throwIfAborted();
|
|
1958
|
+
void this.background(generated, outputRequest(observed));
|
|
1959
|
+
}
|
|
1960
|
+
return result2;
|
|
1929
1961
|
}
|
|
1930
|
-
const
|
|
1931
|
-
|
|
1932
|
-
|
|
1962
|
+
const input = snapshotRequest(request);
|
|
1963
|
+
const conversation = conversationId(input.metadata);
|
|
1964
|
+
const outputOptions = outputRequest(input);
|
|
1965
|
+
const verdict = this.pending.submit(() => this.enforce(text, input), conversation, input.signal);
|
|
1966
|
+
const [, result] = await caller.until(Promise.all([
|
|
1967
|
+
verdict.catch((error) => {
|
|
1968
|
+
controller.abort(error);
|
|
1969
|
+
throw error;
|
|
1970
|
+
}),
|
|
1971
|
+
Promise.resolve().then(() => {
|
|
1972
|
+
callerSignal?.throwIfAborted();
|
|
1973
|
+
return operation(controller.signal);
|
|
1974
|
+
})
|
|
1975
|
+
]));
|
|
1976
|
+
callerSignal?.throwIfAborted();
|
|
1977
|
+
if (output !== void 0) {
|
|
1978
|
+
const generated = output(result);
|
|
1979
|
+
callerSignal?.throwIfAborted();
|
|
1980
|
+
await caller.until(this.pending.submit(
|
|
1981
|
+
() => this.enforce(generated, outputOptions),
|
|
1982
|
+
conversation,
|
|
1983
|
+
input.signal
|
|
1984
|
+
));
|
|
1933
1985
|
}
|
|
1934
|
-
return
|
|
1935
|
-
}
|
|
1936
|
-
|
|
1937
|
-
const conversation = conversationId(input.metadata);
|
|
1938
|
-
const outputOptions = outputRequest(input);
|
|
1939
|
-
const verdict = this.pending.submit(() => this.enforce(text, input), conversation, input.signal);
|
|
1940
|
-
const [, result] = await Promise.all([
|
|
1941
|
-
verdict.catch((error) => {
|
|
1942
|
-
controller.abort(error);
|
|
1943
|
-
throw error;
|
|
1944
|
-
}),
|
|
1945
|
-
Promise.resolve().then(() => operation(controller.signal))
|
|
1946
|
-
]);
|
|
1947
|
-
if (output !== void 0) {
|
|
1948
|
-
const generated = output(result);
|
|
1949
|
-
await this.pending.submit(
|
|
1950
|
-
() => this.enforce(generated, outputOptions),
|
|
1951
|
-
conversation,
|
|
1952
|
-
input.signal
|
|
1953
|
-
);
|
|
1986
|
+
return result;
|
|
1987
|
+
} finally {
|
|
1988
|
+
caller.dispose();
|
|
1954
1989
|
}
|
|
1955
|
-
return result;
|
|
1956
1990
|
}
|
|
1957
1991
|
/** Wait for classifications still running in the background. */
|
|
1958
1992
|
flush() {
|