agentid-sdk 0.1.24 → 0.1.26
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 +28 -5
- package/dist/{agentid-BGCUoYV7.d.mts → agentid-DviYzyAM.d.mts} +49 -4
- package/dist/{agentid-BGCUoYV7.d.ts → agentid-DviYzyAM.d.ts} +49 -4
- package/dist/{chunk-JLHAS2EE.mjs → chunk-JIQGHFHI.mjs} +493 -54
- package/dist/index.d.mts +10 -2
- package/dist/index.d.ts +10 -2
- package/dist/index.js +496 -56
- package/dist/index.mjs +3 -1
- package/dist/langchain.d.mts +4 -1
- package/dist/langchain.d.ts +4 -1
- package/dist/langchain.js +111 -20
- package/dist/langchain.mjs +111 -20
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -99,6 +99,7 @@ const openai = new OpenAI({ apiKey: process.env.OPENAI_API_KEY! });
|
|
|
99
99
|
const secured = agent.wrapOpenAI(openai, {
|
|
100
100
|
system_id: process.env.AGENTID_SYSTEM_ID!,
|
|
101
101
|
user_id: "customer-123",
|
|
102
|
+
expected_languages: ["en"],
|
|
102
103
|
});
|
|
103
104
|
|
|
104
105
|
const response = await secured.chat.completions.create({
|
|
@@ -127,6 +128,7 @@ import { StringOutputParser } from "@langchain/core/output_parsers";
|
|
|
127
128
|
const agent = new AgentID();
|
|
128
129
|
const handler = new AgentIDCallbackHandler(agent, {
|
|
129
130
|
system_id: process.env.AGENTID_SYSTEM_ID!,
|
|
131
|
+
expected_languages: ["en"],
|
|
130
132
|
});
|
|
131
133
|
|
|
132
134
|
const prompt = ChatPromptTemplate.fromTemplate("Answer in one sentence: {question}");
|
|
@@ -213,6 +215,15 @@ const agent = new AgentID({
|
|
|
213
215
|
});
|
|
214
216
|
```
|
|
215
217
|
|
|
218
|
+
### Optional client-side fast fail
|
|
219
|
+
|
|
220
|
+
```ts
|
|
221
|
+
const agent = new AgentID({
|
|
222
|
+
failureMode: "fail_close",
|
|
223
|
+
clientFastFail: true, // opt-in local preflight before /guard
|
|
224
|
+
});
|
|
225
|
+
```
|
|
226
|
+
|
|
216
227
|
### Error Handling & Strict Mode
|
|
217
228
|
|
|
218
229
|
By default, AgentID is designed to keep your application running if the AgentID API has a timeout or is temporarily unreachable.
|
|
@@ -220,12 +231,14 @@ By default, AgentID is designed to keep your application running if the AgentID
|
|
|
220
231
|
| Mode | Connectivity Failure | LLM Execution | Best For |
|
|
221
232
|
| :--- | :--- | :--- | :--- |
|
|
222
233
|
| **Default** (Strict Off) | API Timeout / Unreachable | **Fail-Open** (continues) | Standard SaaS, chatbots |
|
|
223
|
-
| **Strict Mode** (`strictMode: true`) | API Timeout / Unreachable |
|
|
234
|
+
| **Strict Mode** (`strictMode: true`) | API Timeout / Unreachable | Direct `guard()` denies; wrapped flows can apply local fallback first | Healthcare, FinTech, high-risk |
|
|
224
235
|
|
|
225
236
|
- `guard()` returns a verdict (`allowed`, `reason`); handle deny paths explicitly.
|
|
226
237
|
- `wrapOpenAI()` and LangChain handlers throw `SecurityBlockError` when a prompt is blocked.
|
|
238
|
+
- Backend `/guard` is the default authority for prompt injection, DB access, code execution, and PII leakage in SDK-wrapped flows.
|
|
239
|
+
- `clientFastFail` / `client_fast_fail` is optional and disabled by default. Enable it only when you explicitly want local preflight before the backend call.
|
|
240
|
+
- If backend guard is unreachable and the effective failure mode is `fail_close`, wrapped OpenAI/LangChain flows can run local fallback enforcement. Local hits still block; otherwise the request can continue with fallback telemetry attached.
|
|
227
241
|
- If `strictMode` is not explicitly set in SDK code, runtime behavior follows the system configuration from AgentID (`strict_security_mode` / `failure_mode`).
|
|
228
|
-
- Local prompt-injection heuristics are enabled only when dashboard policy enables injection blocking (`block_on_heuristic` / legacy injection flags). `strictMode` does not force local heuristic blocking.
|
|
229
242
|
- Ingest retries transient failures (5xx/429) and logs warnings if persistence fails.
|
|
230
243
|
|
|
231
244
|
### Event Identity Model
|
|
@@ -244,10 +257,20 @@ SDK behavior:
|
|
|
244
257
|
- `metadata.client_event_id`
|
|
245
258
|
- `metadata.guard_event_id` (when available from wrappers/callbacks)
|
|
246
259
|
- `x-correlation-id = client_event_id`
|
|
260
|
+
- after a successful primary ingest, SDK wrappers can call `/ingest/finalize` with the same `client_event_id` to attach `sdk_ingest_ms`
|
|
247
261
|
- SDK requests include `x-agentid-sdk-version` for telemetry/version diagnostics.
|
|
248
262
|
|
|
249
263
|
This keeps Guard + Complete linked under one correlation key while preserving internal event linkage in the dashboard.
|
|
250
264
|
|
|
265
|
+
### SDK Timing Telemetry
|
|
266
|
+
|
|
267
|
+
SDK-managed metadata can include:
|
|
268
|
+
|
|
269
|
+
- `sdk_config_fetch_ms`: capability/config fetch time before dispatch.
|
|
270
|
+
- `sdk_local_scan_ms`: optional local enforcement time (`clientFastFail` or fail-close fallback path).
|
|
271
|
+
- `sdk_guard_ms`: backend `/guard` round-trip time observed by the SDK wrapper.
|
|
272
|
+
- `sdk_ingest_ms`: post-ingest transport timing finalized by the SDK through `/ingest/finalize` after a successful primary `/ingest`.
|
|
273
|
+
|
|
251
274
|
### Policy-Pack Runtime Telemetry
|
|
252
275
|
|
|
253
276
|
When the backend uses compiled policy packs, runtime metadata includes:
|
|
@@ -280,9 +303,9 @@ powershell -ExecutionPolicy Bypass -File .\scripts\qa\run-ai-label-audit-check.p
|
|
|
280
303
|
|
|
281
304
|
## 7. Security & Compliance
|
|
282
305
|
|
|
283
|
-
-
|
|
284
|
-
-
|
|
285
|
-
- Guard checks run pre-execution; ingest telemetry captures prompt/output lifecycle.
|
|
306
|
+
- Backend `/guard` remains the primary enforcement authority by default.
|
|
307
|
+
- Optional local PII masking and opt-in `clientFastFail` are available for edge cases.
|
|
308
|
+
- Guard checks run pre-execution; ingest + finalize telemetry captures prompt/output lifecycle and SDK timing breakdowns.
|
|
286
309
|
- Safe for server and serverless runtimes (including async completion flows).
|
|
287
310
|
- Supports compliance and forensics workflows with durable event records.
|
|
288
311
|
|
|
@@ -5,6 +5,7 @@ type CapabilityConfig = {
|
|
|
5
5
|
block_on_heuristic: boolean;
|
|
6
6
|
inject_transparency_metadata: boolean;
|
|
7
7
|
block_pii_leakage: boolean;
|
|
8
|
+
enable_sdk_pii_masking?: boolean;
|
|
8
9
|
block_db_access: boolean;
|
|
9
10
|
block_code_execution: boolean;
|
|
10
11
|
block_toxicity: boolean;
|
|
@@ -37,9 +38,14 @@ interface GuardResponse {
|
|
|
37
38
|
simulated_decision?: "allowed" | "masked" | "blocked";
|
|
38
39
|
shadow_blocked?: boolean;
|
|
39
40
|
policy_pack_matcher_backend?: "rust_wasm" | "js_hybrid" | "legacy_fallback";
|
|
40
|
-
policy_pack_scan_profile?: "expected_languages" | "core_en_fallback";
|
|
41
|
+
policy_pack_scan_profile?: "expected_languages" | "auto_detected" | "global_high_priority" | "core_en_fallback";
|
|
41
42
|
policy_pack_scan_mode?: "full" | "segmented";
|
|
42
43
|
exotic_language_detected?: boolean;
|
|
44
|
+
langid_primary?: string;
|
|
45
|
+
langid_confidence?: "high" | "medium" | "low";
|
|
46
|
+
langid_secondary?: string[];
|
|
47
|
+
langid_mixed?: boolean;
|
|
48
|
+
langid_source?: "input_detection" | "input_detection_with_hint";
|
|
43
49
|
transparency?: TransparencyMetadata;
|
|
44
50
|
}
|
|
45
51
|
interface TransparencyMetadata {
|
|
@@ -51,6 +57,10 @@ interface TransparencyMetadata {
|
|
|
51
57
|
interface RequestOptions {
|
|
52
58
|
apiKey?: string;
|
|
53
59
|
}
|
|
60
|
+
type InjectionScanRequestOptions = RequestOptions & {
|
|
61
|
+
clientEventId?: string;
|
|
62
|
+
systemId?: string;
|
|
63
|
+
};
|
|
54
64
|
interface LogParams {
|
|
55
65
|
event_id?: string;
|
|
56
66
|
system_id?: string;
|
|
@@ -78,9 +88,12 @@ type AgentIDConfig = {
|
|
|
78
88
|
baseUrl?: string;
|
|
79
89
|
piiMasking?: boolean;
|
|
80
90
|
checkInjection?: boolean;
|
|
91
|
+
clientFastFail?: boolean;
|
|
92
|
+
client_fast_fail?: boolean;
|
|
81
93
|
aiScanEnabled?: boolean;
|
|
82
94
|
storePii?: boolean;
|
|
83
95
|
strictMode?: boolean;
|
|
96
|
+
failureMode?: "fail_open" | "fail_close";
|
|
84
97
|
guardTimeoutMs?: number;
|
|
85
98
|
ingestTimeoutMs?: number;
|
|
86
99
|
};
|
|
@@ -88,19 +101,33 @@ type AgentIDConfig = {
|
|
|
88
101
|
type PreparedInput = {
|
|
89
102
|
sanitizedInput: string;
|
|
90
103
|
capabilityConfig: CapabilityConfig;
|
|
104
|
+
sdkConfigFetchMs?: number;
|
|
105
|
+
sdkLocalScanMs?: number;
|
|
91
106
|
};
|
|
92
107
|
declare class SecurityBlockError extends Error {
|
|
93
108
|
reason: string;
|
|
94
109
|
constructor(reason?: string);
|
|
95
110
|
}
|
|
111
|
+
declare class DependencyError extends Error {
|
|
112
|
+
dependency: "ingest";
|
|
113
|
+
reason: string;
|
|
114
|
+
status: number | null;
|
|
115
|
+
constructor(params: {
|
|
116
|
+
dependency: "ingest";
|
|
117
|
+
reason: string;
|
|
118
|
+
status: number | null;
|
|
119
|
+
});
|
|
120
|
+
}
|
|
96
121
|
declare class AgentID {
|
|
97
122
|
private baseUrl;
|
|
98
123
|
private apiKey;
|
|
99
|
-
private
|
|
124
|
+
private configuredPiiMasking;
|
|
100
125
|
private checkInjection;
|
|
126
|
+
private clientFastFail;
|
|
101
127
|
private aiScanEnabled;
|
|
102
128
|
private storePii;
|
|
103
129
|
private strictMode;
|
|
130
|
+
private configuredFailureMode;
|
|
104
131
|
private guardTimeoutMs;
|
|
105
132
|
private ingestTimeoutMs;
|
|
106
133
|
private pii;
|
|
@@ -108,6 +135,9 @@ declare class AgentID {
|
|
|
108
135
|
private injectionScanner;
|
|
109
136
|
private recentGuardVerdicts;
|
|
110
137
|
constructor(config?: AgentIDConfig);
|
|
138
|
+
get piiMasking(): boolean | undefined;
|
|
139
|
+
private resolveEffectivePiiMasking;
|
|
140
|
+
getEffectivePiiMasking(options?: RequestOptions): boolean;
|
|
111
141
|
private buildClientCapabilities;
|
|
112
142
|
private resolveApiKey;
|
|
113
143
|
private resolveClientEventId;
|
|
@@ -115,19 +145,32 @@ declare class AgentID {
|
|
|
115
145
|
private readCachedGuardVerdict;
|
|
116
146
|
private cacheGuardVerdict;
|
|
117
147
|
getCapabilityConfig(force?: boolean, options?: RequestOptions): Promise<CapabilityConfig>;
|
|
148
|
+
private getCapabilityConfigWithTelemetry;
|
|
118
149
|
private getCachedCapabilityConfig;
|
|
119
150
|
private resolveEffectiveStrictMode;
|
|
151
|
+
private maybeRaiseStrictIngestDependencyError;
|
|
120
152
|
private shouldRunLocalInjectionScan;
|
|
153
|
+
private applyLocalPolicyChecks;
|
|
121
154
|
prepareInputForDispatch(params: {
|
|
122
155
|
input: string;
|
|
123
156
|
systemId: string;
|
|
124
157
|
stream: boolean;
|
|
125
158
|
skipInjectionScan?: boolean;
|
|
159
|
+
clientEventId?: string;
|
|
160
|
+
}, options?: RequestOptions): Promise<PreparedInput>;
|
|
161
|
+
applyLocalFallbackForGuardFailure(params: {
|
|
162
|
+
input: string;
|
|
163
|
+
systemId: string;
|
|
164
|
+
stream: boolean;
|
|
165
|
+
clientEventId?: string;
|
|
166
|
+
capabilityConfig?: CapabilityConfig;
|
|
167
|
+
sdkConfigFetchMs?: number;
|
|
126
168
|
}, options?: RequestOptions): Promise<PreparedInput>;
|
|
127
|
-
scanPromptInjection(input: string, options?:
|
|
169
|
+
scanPromptInjection(input: string, options?: InjectionScanRequestOptions): Promise<void>;
|
|
128
170
|
private withMaskedOpenAIRequest;
|
|
129
171
|
private logSecurityPolicyViolation;
|
|
130
172
|
private logGuardFallback;
|
|
173
|
+
private finalizeIngestTelemetry;
|
|
131
174
|
/**
|
|
132
175
|
* GUARD: Checks limits, PII, and security before execution.
|
|
133
176
|
* strictMode=false (default): FAIL-OPEN on connectivity/timeouts.
|
|
@@ -159,10 +202,12 @@ declare class AgentID {
|
|
|
159
202
|
wrapOpenAI<T>(openai: T, options: {
|
|
160
203
|
system_id: string;
|
|
161
204
|
user_id?: string;
|
|
205
|
+
expected_languages?: string[];
|
|
206
|
+
expectedLanguages?: string[];
|
|
162
207
|
apiKey?: string;
|
|
163
208
|
api_key?: string;
|
|
164
209
|
resolveApiKey?: (request: Record<string, unknown>) => string | undefined;
|
|
165
210
|
}): T;
|
|
166
211
|
}
|
|
167
212
|
|
|
168
|
-
export { AgentID as A, type GuardParams as G, type LogParams as L, type PreparedInput as P, type RequestOptions as R, SecurityBlockError as S, type TransparencyMetadata as T, type GuardResponse as a };
|
|
213
|
+
export { AgentID as A, DependencyError as D, type GuardParams as G, type LogParams as L, type PreparedInput as P, type RequestOptions as R, SecurityBlockError as S, type TransparencyMetadata as T, type GuardResponse as a };
|
|
@@ -5,6 +5,7 @@ type CapabilityConfig = {
|
|
|
5
5
|
block_on_heuristic: boolean;
|
|
6
6
|
inject_transparency_metadata: boolean;
|
|
7
7
|
block_pii_leakage: boolean;
|
|
8
|
+
enable_sdk_pii_masking?: boolean;
|
|
8
9
|
block_db_access: boolean;
|
|
9
10
|
block_code_execution: boolean;
|
|
10
11
|
block_toxicity: boolean;
|
|
@@ -37,9 +38,14 @@ interface GuardResponse {
|
|
|
37
38
|
simulated_decision?: "allowed" | "masked" | "blocked";
|
|
38
39
|
shadow_blocked?: boolean;
|
|
39
40
|
policy_pack_matcher_backend?: "rust_wasm" | "js_hybrid" | "legacy_fallback";
|
|
40
|
-
policy_pack_scan_profile?: "expected_languages" | "core_en_fallback";
|
|
41
|
+
policy_pack_scan_profile?: "expected_languages" | "auto_detected" | "global_high_priority" | "core_en_fallback";
|
|
41
42
|
policy_pack_scan_mode?: "full" | "segmented";
|
|
42
43
|
exotic_language_detected?: boolean;
|
|
44
|
+
langid_primary?: string;
|
|
45
|
+
langid_confidence?: "high" | "medium" | "low";
|
|
46
|
+
langid_secondary?: string[];
|
|
47
|
+
langid_mixed?: boolean;
|
|
48
|
+
langid_source?: "input_detection" | "input_detection_with_hint";
|
|
43
49
|
transparency?: TransparencyMetadata;
|
|
44
50
|
}
|
|
45
51
|
interface TransparencyMetadata {
|
|
@@ -51,6 +57,10 @@ interface TransparencyMetadata {
|
|
|
51
57
|
interface RequestOptions {
|
|
52
58
|
apiKey?: string;
|
|
53
59
|
}
|
|
60
|
+
type InjectionScanRequestOptions = RequestOptions & {
|
|
61
|
+
clientEventId?: string;
|
|
62
|
+
systemId?: string;
|
|
63
|
+
};
|
|
54
64
|
interface LogParams {
|
|
55
65
|
event_id?: string;
|
|
56
66
|
system_id?: string;
|
|
@@ -78,9 +88,12 @@ type AgentIDConfig = {
|
|
|
78
88
|
baseUrl?: string;
|
|
79
89
|
piiMasking?: boolean;
|
|
80
90
|
checkInjection?: boolean;
|
|
91
|
+
clientFastFail?: boolean;
|
|
92
|
+
client_fast_fail?: boolean;
|
|
81
93
|
aiScanEnabled?: boolean;
|
|
82
94
|
storePii?: boolean;
|
|
83
95
|
strictMode?: boolean;
|
|
96
|
+
failureMode?: "fail_open" | "fail_close";
|
|
84
97
|
guardTimeoutMs?: number;
|
|
85
98
|
ingestTimeoutMs?: number;
|
|
86
99
|
};
|
|
@@ -88,19 +101,33 @@ type AgentIDConfig = {
|
|
|
88
101
|
type PreparedInput = {
|
|
89
102
|
sanitizedInput: string;
|
|
90
103
|
capabilityConfig: CapabilityConfig;
|
|
104
|
+
sdkConfigFetchMs?: number;
|
|
105
|
+
sdkLocalScanMs?: number;
|
|
91
106
|
};
|
|
92
107
|
declare class SecurityBlockError extends Error {
|
|
93
108
|
reason: string;
|
|
94
109
|
constructor(reason?: string);
|
|
95
110
|
}
|
|
111
|
+
declare class DependencyError extends Error {
|
|
112
|
+
dependency: "ingest";
|
|
113
|
+
reason: string;
|
|
114
|
+
status: number | null;
|
|
115
|
+
constructor(params: {
|
|
116
|
+
dependency: "ingest";
|
|
117
|
+
reason: string;
|
|
118
|
+
status: number | null;
|
|
119
|
+
});
|
|
120
|
+
}
|
|
96
121
|
declare class AgentID {
|
|
97
122
|
private baseUrl;
|
|
98
123
|
private apiKey;
|
|
99
|
-
private
|
|
124
|
+
private configuredPiiMasking;
|
|
100
125
|
private checkInjection;
|
|
126
|
+
private clientFastFail;
|
|
101
127
|
private aiScanEnabled;
|
|
102
128
|
private storePii;
|
|
103
129
|
private strictMode;
|
|
130
|
+
private configuredFailureMode;
|
|
104
131
|
private guardTimeoutMs;
|
|
105
132
|
private ingestTimeoutMs;
|
|
106
133
|
private pii;
|
|
@@ -108,6 +135,9 @@ declare class AgentID {
|
|
|
108
135
|
private injectionScanner;
|
|
109
136
|
private recentGuardVerdicts;
|
|
110
137
|
constructor(config?: AgentIDConfig);
|
|
138
|
+
get piiMasking(): boolean | undefined;
|
|
139
|
+
private resolveEffectivePiiMasking;
|
|
140
|
+
getEffectivePiiMasking(options?: RequestOptions): boolean;
|
|
111
141
|
private buildClientCapabilities;
|
|
112
142
|
private resolveApiKey;
|
|
113
143
|
private resolveClientEventId;
|
|
@@ -115,19 +145,32 @@ declare class AgentID {
|
|
|
115
145
|
private readCachedGuardVerdict;
|
|
116
146
|
private cacheGuardVerdict;
|
|
117
147
|
getCapabilityConfig(force?: boolean, options?: RequestOptions): Promise<CapabilityConfig>;
|
|
148
|
+
private getCapabilityConfigWithTelemetry;
|
|
118
149
|
private getCachedCapabilityConfig;
|
|
119
150
|
private resolveEffectiveStrictMode;
|
|
151
|
+
private maybeRaiseStrictIngestDependencyError;
|
|
120
152
|
private shouldRunLocalInjectionScan;
|
|
153
|
+
private applyLocalPolicyChecks;
|
|
121
154
|
prepareInputForDispatch(params: {
|
|
122
155
|
input: string;
|
|
123
156
|
systemId: string;
|
|
124
157
|
stream: boolean;
|
|
125
158
|
skipInjectionScan?: boolean;
|
|
159
|
+
clientEventId?: string;
|
|
160
|
+
}, options?: RequestOptions): Promise<PreparedInput>;
|
|
161
|
+
applyLocalFallbackForGuardFailure(params: {
|
|
162
|
+
input: string;
|
|
163
|
+
systemId: string;
|
|
164
|
+
stream: boolean;
|
|
165
|
+
clientEventId?: string;
|
|
166
|
+
capabilityConfig?: CapabilityConfig;
|
|
167
|
+
sdkConfigFetchMs?: number;
|
|
126
168
|
}, options?: RequestOptions): Promise<PreparedInput>;
|
|
127
|
-
scanPromptInjection(input: string, options?:
|
|
169
|
+
scanPromptInjection(input: string, options?: InjectionScanRequestOptions): Promise<void>;
|
|
128
170
|
private withMaskedOpenAIRequest;
|
|
129
171
|
private logSecurityPolicyViolation;
|
|
130
172
|
private logGuardFallback;
|
|
173
|
+
private finalizeIngestTelemetry;
|
|
131
174
|
/**
|
|
132
175
|
* GUARD: Checks limits, PII, and security before execution.
|
|
133
176
|
* strictMode=false (default): FAIL-OPEN on connectivity/timeouts.
|
|
@@ -159,10 +202,12 @@ declare class AgentID {
|
|
|
159
202
|
wrapOpenAI<T>(openai: T, options: {
|
|
160
203
|
system_id: string;
|
|
161
204
|
user_id?: string;
|
|
205
|
+
expected_languages?: string[];
|
|
206
|
+
expectedLanguages?: string[];
|
|
162
207
|
apiKey?: string;
|
|
163
208
|
api_key?: string;
|
|
164
209
|
resolveApiKey?: (request: Record<string, unknown>) => string | undefined;
|
|
165
210
|
}): T;
|
|
166
211
|
}
|
|
167
212
|
|
|
168
|
-
export { AgentID as A, type GuardParams as G, type LogParams as L, type PreparedInput as P, type RequestOptions as R, SecurityBlockError as S, type TransparencyMetadata as T, type GuardResponse as a };
|
|
213
|
+
export { AgentID as A, DependencyError as D, type GuardParams as G, type LogParams as L, type PreparedInput as P, type RequestOptions as R, SecurityBlockError as S, type TransparencyMetadata as T, type GuardResponse as a };
|