agentid-sdk 0.1.25 → 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 CHANGED
@@ -215,6 +215,15 @@ const agent = new AgentID({
215
215
  });
216
216
  ```
217
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
+
218
227
  ### Error Handling & Strict Mode
219
228
 
220
229
  By default, AgentID is designed to keep your application running if the AgentID API has a timeout or is temporarily unreachable.
@@ -222,12 +231,14 @@ By default, AgentID is designed to keep your application running if the AgentID
222
231
  | Mode | Connectivity Failure | LLM Execution | Best For |
223
232
  | :--- | :--- | :--- | :--- |
224
233
  | **Default** (Strict Off) | API Timeout / Unreachable | **Fail-Open** (continues) | Standard SaaS, chatbots |
225
- | **Strict Mode** (`strictMode: true`) | API Timeout / Unreachable | **Fail-Closed** (blocks) | Healthcare, FinTech, high-risk |
234
+ | **Strict Mode** (`strictMode: true`) | API Timeout / Unreachable | Direct `guard()` denies; wrapped flows can apply local fallback first | Healthcare, FinTech, high-risk |
226
235
 
227
236
  - `guard()` returns a verdict (`allowed`, `reason`); handle deny paths explicitly.
228
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.
229
241
  - If `strictMode` is not explicitly set in SDK code, runtime behavior follows the system configuration from AgentID (`strict_security_mode` / `failure_mode`).
230
- - 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.
231
242
  - Ingest retries transient failures (5xx/429) and logs warnings if persistence fails.
232
243
 
233
244
  ### Event Identity Model
@@ -246,10 +257,20 @@ SDK behavior:
246
257
  - `metadata.client_event_id`
247
258
  - `metadata.guard_event_id` (when available from wrappers/callbacks)
248
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`
249
261
  - SDK requests include `x-agentid-sdk-version` for telemetry/version diagnostics.
250
262
 
251
263
  This keeps Guard + Complete linked under one correlation key while preserving internal event linkage in the dashboard.
252
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
+
253
274
  ### Policy-Pack Runtime Telemetry
254
275
 
255
276
  When the backend uses compiled policy packs, runtime metadata includes:
@@ -282,9 +303,9 @@ powershell -ExecutionPolicy Bypass -File .\scripts\qa\run-ai-label-audit-check.p
282
303
 
283
304
  ## 7. Security & Compliance
284
305
 
285
- - Optional local PII masking and local policy enforcement before model dispatch.
286
- - Prompt-injection scanning in the SDK request path.
287
- - 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.
288
309
  - Safe for server and serverless runtimes (including async completion flows).
289
310
  - Supports compliance and forensics workflows with durable event records.
290
311
 
@@ -88,6 +88,8 @@ type AgentIDConfig = {
88
88
  baseUrl?: string;
89
89
  piiMasking?: boolean;
90
90
  checkInjection?: boolean;
91
+ clientFastFail?: boolean;
92
+ client_fast_fail?: boolean;
91
93
  aiScanEnabled?: boolean;
92
94
  storePii?: boolean;
93
95
  strictMode?: boolean;
@@ -99,6 +101,8 @@ type AgentIDConfig = {
99
101
  type PreparedInput = {
100
102
  sanitizedInput: string;
101
103
  capabilityConfig: CapabilityConfig;
104
+ sdkConfigFetchMs?: number;
105
+ sdkLocalScanMs?: number;
102
106
  };
103
107
  declare class SecurityBlockError extends Error {
104
108
  reason: string;
@@ -119,6 +123,7 @@ declare class AgentID {
119
123
  private apiKey;
120
124
  private configuredPiiMasking;
121
125
  private checkInjection;
126
+ private clientFastFail;
122
127
  private aiScanEnabled;
123
128
  private storePii;
124
129
  private strictMode;
@@ -140,20 +145,32 @@ declare class AgentID {
140
145
  private readCachedGuardVerdict;
141
146
  private cacheGuardVerdict;
142
147
  getCapabilityConfig(force?: boolean, options?: RequestOptions): Promise<CapabilityConfig>;
148
+ private getCapabilityConfigWithTelemetry;
143
149
  private getCachedCapabilityConfig;
144
150
  private resolveEffectiveStrictMode;
145
151
  private maybeRaiseStrictIngestDependencyError;
146
152
  private shouldRunLocalInjectionScan;
153
+ private applyLocalPolicyChecks;
147
154
  prepareInputForDispatch(params: {
148
155
  input: string;
149
156
  systemId: string;
150
157
  stream: boolean;
151
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;
152
168
  }, options?: RequestOptions): Promise<PreparedInput>;
153
169
  scanPromptInjection(input: string, options?: InjectionScanRequestOptions): Promise<void>;
154
170
  private withMaskedOpenAIRequest;
155
171
  private logSecurityPolicyViolation;
156
172
  private logGuardFallback;
173
+ private finalizeIngestTelemetry;
157
174
  /**
158
175
  * GUARD: Checks limits, PII, and security before execution.
159
176
  * strictMode=false (default): FAIL-OPEN on connectivity/timeouts.
@@ -88,6 +88,8 @@ type AgentIDConfig = {
88
88
  baseUrl?: string;
89
89
  piiMasking?: boolean;
90
90
  checkInjection?: boolean;
91
+ clientFastFail?: boolean;
92
+ client_fast_fail?: boolean;
91
93
  aiScanEnabled?: boolean;
92
94
  storePii?: boolean;
93
95
  strictMode?: boolean;
@@ -99,6 +101,8 @@ type AgentIDConfig = {
99
101
  type PreparedInput = {
100
102
  sanitizedInput: string;
101
103
  capabilityConfig: CapabilityConfig;
104
+ sdkConfigFetchMs?: number;
105
+ sdkLocalScanMs?: number;
102
106
  };
103
107
  declare class SecurityBlockError extends Error {
104
108
  reason: string;
@@ -119,6 +123,7 @@ declare class AgentID {
119
123
  private apiKey;
120
124
  private configuredPiiMasking;
121
125
  private checkInjection;
126
+ private clientFastFail;
122
127
  private aiScanEnabled;
123
128
  private storePii;
124
129
  private strictMode;
@@ -140,20 +145,32 @@ declare class AgentID {
140
145
  private readCachedGuardVerdict;
141
146
  private cacheGuardVerdict;
142
147
  getCapabilityConfig(force?: boolean, options?: RequestOptions): Promise<CapabilityConfig>;
148
+ private getCapabilityConfigWithTelemetry;
143
149
  private getCachedCapabilityConfig;
144
150
  private resolveEffectiveStrictMode;
145
151
  private maybeRaiseStrictIngestDependencyError;
146
152
  private shouldRunLocalInjectionScan;
153
+ private applyLocalPolicyChecks;
147
154
  prepareInputForDispatch(params: {
148
155
  input: string;
149
156
  systemId: string;
150
157
  stream: boolean;
151
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;
152
168
  }, options?: RequestOptions): Promise<PreparedInput>;
153
169
  scanPromptInjection(input: string, options?: InjectionScanRequestOptions): Promise<void>;
154
170
  private withMaskedOpenAIRequest;
155
171
  private logSecurityPolicyViolation;
156
172
  private logGuardFallback;
173
+ private finalizeIngestTelemetry;
157
174
  /**
158
175
  * GUARD: Checks limits, PII, and security before execution.
159
176
  * strictMode=false (default): FAIL-OPEN on connectivity/timeouts.