@silmaril-security/sdk 0.3.1 → 0.4.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 +30 -0
- package/README.md +131 -32
- package/dist/adapters/langchain.cjs +349 -0
- package/dist/adapters/langchain.cjs.map +1 -0
- package/dist/adapters/langchain.d.cts +6 -0
- package/dist/adapters/langchain.d.ts +6 -0
- package/dist/adapters/langchain.js +312 -0
- package/dist/adapters/langchain.js.map +1 -0
- package/dist/adapters/vercel.cjs +321 -0
- package/dist/adapters/vercel.cjs.map +1 -0
- package/dist/adapters/vercel.d.cts +1 -0
- package/dist/adapters/vercel.d.ts +1 -0
- package/dist/adapters/vercel.js +294 -0
- package/dist/adapters/vercel.js.map +1 -0
- package/dist/firewall-DfZCCDU6.d.cts +197 -0
- package/dist/firewall-DfZCCDU6.d.ts +197 -0
- package/dist/index.cjs +257 -92
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +16 -146
- package/dist/index.d.ts +16 -146
- package/dist/index.js +244 -89
- package/dist/index.js.map +1 -1
- package/package.json +38 -10
package/dist/index.d.ts
CHANGED
|
@@ -1,147 +1,5 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
declare const HookLabel: {
|
|
4
|
-
readonly USER_INPUT: "user_input";
|
|
5
|
-
readonly SYSTEM_PROMPT: "system_prompt";
|
|
6
|
-
readonly TOOL_CALL: "tool_call";
|
|
7
|
-
readonly TOOL_RESPONSE: "tool_response";
|
|
8
|
-
readonly LLM_OUTPUT: "llm_output";
|
|
9
|
-
readonly UNKNOWN: "unknown";
|
|
10
|
-
};
|
|
11
|
-
type HookLabel = (typeof HookLabel)[keyof typeof HookLabel];
|
|
12
|
-
declare const FirewallHook: {
|
|
13
|
-
readonly LLM_START: "on_llm_start";
|
|
14
|
-
readonly CHAT_MODEL_START: "on_chat_model_start";
|
|
15
|
-
readonly TOOL_START: "on_tool_start";
|
|
16
|
-
readonly RETRIEVER_START: "on_retriever_start";
|
|
17
|
-
readonly LLM_END: "on_llm_end";
|
|
18
|
-
readonly TOOL_END: "on_tool_end";
|
|
19
|
-
readonly RETRIEVER_END: "on_retriever_end";
|
|
20
|
-
};
|
|
21
|
-
type FirewallHook = (typeof FirewallHook)[keyof typeof FirewallHook];
|
|
22
|
-
declare const DEFAULT_HOOKS: ReadonlySet<FirewallHook>;
|
|
23
|
-
declare const INPUT_HOOKS: ReadonlySet<FirewallHook>;
|
|
24
|
-
declare const OUTPUT_HOOKS: ReadonlySet<FirewallHook>;
|
|
25
|
-
declare const ALL_HOOKS: ReadonlySet<FirewallHook>;
|
|
26
|
-
declare const FIREWALL_HOOK_TO_LABEL: Readonly<Record<FirewallHook, HookLabel>>;
|
|
27
|
-
declare function resolveHooks(hooks: Iterable<FirewallHook | string> | undefined): ReadonlySet<FirewallHook>;
|
|
28
|
-
declare function prependHook(text: string, hook: HookLabel | string | undefined | null): string;
|
|
29
|
-
declare function prependToolName(text: string, toolName: string | undefined | null): string;
|
|
30
|
-
|
|
31
|
-
type Prediction = "BENIGN" | "MALICIOUS";
|
|
32
|
-
interface BlockResult {
|
|
33
|
-
readonly prediction: Prediction;
|
|
34
|
-
readonly score: number;
|
|
35
|
-
readonly threshold: number;
|
|
36
|
-
readonly primaryOutcome?: string;
|
|
37
|
-
readonly outcomeScores?: Readonly<Record<string, number>>;
|
|
38
|
-
readonly detectorScores?: Readonly<Record<string, number>>;
|
|
39
|
-
readonly detectorCounts?: Readonly<Record<string, number>>;
|
|
40
|
-
}
|
|
41
|
-
interface FirewallOptions {
|
|
42
|
-
apiKey: string;
|
|
43
|
-
apiUrl: string;
|
|
44
|
-
timeoutMs?: number;
|
|
45
|
-
chunkConcurrency?: number;
|
|
46
|
-
shadowMode?: boolean;
|
|
47
|
-
}
|
|
48
|
-
type ClassificationMetadata = Readonly<Record<string, unknown>>;
|
|
49
|
-
interface ClassifyOptions {
|
|
50
|
-
hook?: HookLabel;
|
|
51
|
-
toolName?: string;
|
|
52
|
-
metadata?: ClassificationMetadata;
|
|
53
|
-
}
|
|
54
|
-
interface ClassifyBatchOptions {
|
|
55
|
-
hooks?: readonly HookLabel[];
|
|
56
|
-
toolNames?: readonly (string | undefined)[];
|
|
57
|
-
metadata?: readonly (ClassificationMetadata | undefined)[];
|
|
58
|
-
}
|
|
59
|
-
interface LangChainAdapterOptions {
|
|
60
|
-
hooks?: ReadonlySet<FirewallHook>;
|
|
61
|
-
includeSystem?: boolean;
|
|
62
|
-
includeTool?: boolean;
|
|
63
|
-
failOpen?: boolean;
|
|
64
|
-
logger?: (message: string, error: unknown) => void;
|
|
65
|
-
shadowMode?: boolean;
|
|
66
|
-
onClassify?: (event: ClassifyEvent) => void;
|
|
67
|
-
}
|
|
68
|
-
interface ClassifyEvent {
|
|
69
|
-
readonly hook: HookLabel;
|
|
70
|
-
readonly toolName?: string;
|
|
71
|
-
readonly text: string;
|
|
72
|
-
readonly result: BlockResult;
|
|
73
|
-
readonly blocked: boolean;
|
|
74
|
-
readonly shadowMode: boolean;
|
|
75
|
-
}
|
|
76
|
-
interface MiddlewareOptions {
|
|
77
|
-
scanInput?: boolean;
|
|
78
|
-
scanOutput?: boolean;
|
|
79
|
-
scanToolCalls?: boolean;
|
|
80
|
-
shadowMode?: boolean;
|
|
81
|
-
onBlocked?: (err: Error) => void;
|
|
82
|
-
onClassify?: (event: ClassifyEvent) => void;
|
|
83
|
-
}
|
|
84
|
-
|
|
85
|
-
interface VercelContentPart {
|
|
86
|
-
type?: string;
|
|
87
|
-
text?: string;
|
|
88
|
-
toolCallId?: string;
|
|
89
|
-
toolName?: string;
|
|
90
|
-
args?: unknown;
|
|
91
|
-
result?: unknown;
|
|
92
|
-
}
|
|
93
|
-
interface VercelPromptMessage {
|
|
94
|
-
role: string;
|
|
95
|
-
content: string | ReadonlyArray<VercelContentPart | string>;
|
|
96
|
-
}
|
|
97
|
-
interface VercelToolCall {
|
|
98
|
-
toolCallType?: string;
|
|
99
|
-
toolCallId?: string;
|
|
100
|
-
toolName?: string;
|
|
101
|
-
args?: unknown;
|
|
102
|
-
}
|
|
103
|
-
interface VercelGenerateResult {
|
|
104
|
-
text?: string;
|
|
105
|
-
toolCalls?: ReadonlyArray<VercelToolCall>;
|
|
106
|
-
}
|
|
107
|
-
interface WrapGenerateArgs<TResult extends VercelGenerateResult & Record<string, unknown>> {
|
|
108
|
-
params: {
|
|
109
|
-
prompt: ReadonlyArray<VercelPromptMessage>;
|
|
110
|
-
} & Record<string, unknown>;
|
|
111
|
-
doGenerate: () => PromiseLike<TResult>;
|
|
112
|
-
}
|
|
113
|
-
interface WrapStreamArgs<TResult extends {
|
|
114
|
-
stream: ReadableStream<unknown>;
|
|
115
|
-
} & Record<string, unknown>> {
|
|
116
|
-
params: {
|
|
117
|
-
prompt: ReadonlyArray<VercelPromptMessage>;
|
|
118
|
-
} & Record<string, unknown>;
|
|
119
|
-
doStream: () => PromiseLike<TResult>;
|
|
120
|
-
}
|
|
121
|
-
interface FirewallMiddleware {
|
|
122
|
-
wrapGenerate: <TResult extends VercelGenerateResult & Record<string, unknown>>(args: WrapGenerateArgs<TResult>) => Promise<TResult>;
|
|
123
|
-
wrapStream: <TResult extends {
|
|
124
|
-
stream: ReadableStream<unknown>;
|
|
125
|
-
} & Record<string, unknown>>(args: WrapStreamArgs<TResult>) => Promise<TResult>;
|
|
126
|
-
}
|
|
127
|
-
|
|
128
|
-
declare const DEFAULT_TIMEOUT_MS = 10000;
|
|
129
|
-
declare const DEFAULT_CHUNK_CONCURRENCY = 8;
|
|
130
|
-
declare class Firewall {
|
|
131
|
-
readonly apiKey: string;
|
|
132
|
-
readonly apiUrl: string;
|
|
133
|
-
readonly timeoutMs: number;
|
|
134
|
-
readonly chunkConcurrency: number;
|
|
135
|
-
readonly shadowMode: boolean;
|
|
136
|
-
private readonly headers;
|
|
137
|
-
constructor(options: FirewallOptions);
|
|
138
|
-
classify(text: string, options?: ClassifyOptions): Promise<BlockResult>;
|
|
139
|
-
classifyBatch(texts: readonly string[], options?: ClassifyBatchOptions): Promise<BlockResult[]>;
|
|
140
|
-
asLangChainHandler(options?: LangChainAdapterOptions): Promise<BaseCallbackHandler>;
|
|
141
|
-
asMiddleware(options?: MiddlewareOptions): FirewallMiddleware;
|
|
142
|
-
private postWithRetry;
|
|
143
|
-
private classifySingleChunk;
|
|
144
|
-
}
|
|
1
|
+
import { H as HookLabel, B as BlockResult } from './firewall-DfZCCDU6.js';
|
|
2
|
+
export { A as ALL_HOOKS, C as ClassificationMetadata, a as ClassifyBatchOptions, b as ClassifyEvent, c as ClassifyOptions, D as DEFAULT_CHUNK_CONCURRENCY, d as DEFAULT_HOOKS, e as DEFAULT_TIMEOUT_MS, F as FIREWALL_HOOK_TO_LABEL, f as Firewall, g as FirewallHook, h as FirewallMiddleware, i as FirewallOptions, j as HARMFUL_OUTCOMES, k as HarmfulOutcome, I as INPUT_HOOKS, K as KnownHarmfulOutcome, l as KnownPrimaryOutcome, L as LangChainAdapterOptions, m as LangChainFirewallHandler, M as MiddlewareOptions, O as OUTCOME_DESCRIPTIONS, n as OUTPUT_HOOKS, o as Outcome, P as PRIMARY_OUTCOMES, p as Prediction, q as PrimaryOutcome, U as UnknownOutcome, r as isHarmfulOutcome, s as isPrimaryOutcome, t as normalizeHarmfulOutcome, u as normalizeHarmfulOutcomeMap, v as normalizePrimaryOutcome, w as prependHook, x as prependToolName, y as resolveHooks } from './firewall-DfZCCDU6.js';
|
|
145
3
|
|
|
146
4
|
interface MalformedInputDetails {
|
|
147
5
|
field?: string;
|
|
@@ -151,19 +9,31 @@ interface MalformedInputDetails {
|
|
|
151
9
|
codePoint?: string;
|
|
152
10
|
reason?: string;
|
|
153
11
|
}
|
|
154
|
-
declare class
|
|
12
|
+
declare class FirewallBlockedException extends Error {
|
|
155
13
|
readonly score: number;
|
|
156
14
|
readonly threshold: number;
|
|
157
15
|
readonly promptText: string;
|
|
158
16
|
readonly runId: string | undefined;
|
|
17
|
+
readonly hook: HookLabel | undefined;
|
|
18
|
+
readonly toolName: string | undefined;
|
|
19
|
+
readonly toolCallId: string | undefined;
|
|
20
|
+
readonly result: BlockResult | undefined;
|
|
159
21
|
constructor(params: {
|
|
160
22
|
score: number;
|
|
161
23
|
threshold: number;
|
|
162
24
|
promptText: string;
|
|
163
25
|
runId?: string;
|
|
26
|
+
hook?: HookLabel;
|
|
27
|
+
toolName?: string;
|
|
28
|
+
toolCallId?: string;
|
|
29
|
+
result?: BlockResult;
|
|
164
30
|
});
|
|
165
31
|
private static formatMessage;
|
|
166
32
|
}
|
|
33
|
+
/** @deprecated Use FirewallBlockedException instead. */
|
|
34
|
+
declare const PromptBlockedException: typeof FirewallBlockedException;
|
|
35
|
+
/** @deprecated Use FirewallBlockedException instead. */
|
|
36
|
+
type PromptBlockedException = FirewallBlockedException;
|
|
167
37
|
declare class SilmarilApiError extends Error {
|
|
168
38
|
readonly status: number;
|
|
169
39
|
readonly statusText: string;
|
|
@@ -190,4 +60,4 @@ declare const CHUNK_OVERLAP_CHARS: number;
|
|
|
190
60
|
declare function sanitizeText(text: string): string;
|
|
191
61
|
declare function chunkText(text: string): string[];
|
|
192
62
|
|
|
193
|
-
export {
|
|
63
|
+
export { BlockResult, CHUNK_OVERLAP, CHUNK_OVERLAP_CHARS, CHUNK_WINDOW, CHUNK_WINDOW_CHARS, FirewallBlockedException, HookLabel, MAX_INPUT_CHARS, MAX_INPUT_TOKENS, type MalformedInputDetails, PromptBlockedException, SilmarilApiError, chunkText, sanitizeText };
|