agentid-sdk 0.1.36 → 0.1.38

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.
@@ -0,0 +1,399 @@
1
+ type PIIMapping = Record<string, string>;
2
+ type PIIAnonymizeOptions = {
3
+ pii?: boolean;
4
+ secrets?: boolean;
5
+ };
6
+ declare class PIIManager {
7
+ /**
8
+ * Reversible local-first masking using <TYPE_INDEX> placeholders.
9
+ *
10
+ * Zero-dependency fallback with strict checksum validation for CEE national IDs.
11
+ */
12
+ anonymize(text: string, options?: PIIAnonymizeOptions): {
13
+ maskedText: string;
14
+ mapping: PIIMapping;
15
+ };
16
+ deanonymize(text: string, mapping: PIIMapping): string;
17
+ }
18
+
19
+ type CapabilityConfig = {
20
+ version?: number | null;
21
+ shadow_mode: boolean;
22
+ strict_security_mode: boolean;
23
+ failure_mode: "fail_open" | "fail_close";
24
+ block_on_heuristic: boolean;
25
+ inject_transparency_metadata: boolean;
26
+ block_pii_leakage: boolean;
27
+ enable_sdk_pii_masking?: boolean;
28
+ block_secret_leakage?: boolean;
29
+ enable_sdk_secret_masking?: boolean;
30
+ block_db_access: boolean;
31
+ block_code_execution: boolean;
32
+ block_toxicity: boolean;
33
+ };
34
+
35
+ interface GuardAttachment {
36
+ filename: string;
37
+ mime_type?: string;
38
+ mimeType?: string;
39
+ content_base64?: string;
40
+ contentBase64?: string;
41
+ text?: string;
42
+ }
43
+ interface GuardParams {
44
+ input: string;
45
+ system_id: string;
46
+ model?: string;
47
+ user_id?: string;
48
+ client_event_id?: string;
49
+ expected_languages?: string[];
50
+ request_identity?: Record<string, unknown>;
51
+ metadata?: AgentTelemetryContext;
52
+ attachments?: GuardAttachment[];
53
+ client_capabilities?: {
54
+ capabilities: {
55
+ has_feedback_handler: boolean;
56
+ pii_masking_enabled: boolean;
57
+ framework: string;
58
+ };
59
+ };
60
+ }
61
+ interface GuardResponse {
62
+ allowed: boolean;
63
+ reason?: string;
64
+ detected_pii?: boolean;
65
+ transformed_input?: string;
66
+ guard_event_id?: string;
67
+ client_event_id?: string;
68
+ guard_latency_ms?: number;
69
+ shadow_mode?: boolean;
70
+ simulated_decision?: "allowed" | "masked" | "blocked";
71
+ shadow_blocked?: boolean;
72
+ policy_pack_matcher_backend?: "rust_wasm" | "js_hybrid" | "legacy_fallback";
73
+ policy_pack_scan_profile?: "expected_languages" | "auto_detected" | "global_high_priority" | "core_en_fallback";
74
+ policy_pack_scan_mode?: "full" | "segmented";
75
+ exotic_language_detected?: boolean;
76
+ langid_primary?: string;
77
+ langid_confidence?: "high" | "medium" | "low";
78
+ langid_secondary?: string[];
79
+ langid_mixed?: boolean;
80
+ langid_source?: "input_detection" | "input_detection_with_hint";
81
+ transparency?: TransparencyMetadata;
82
+ }
83
+ interface TransparencyMetadata {
84
+ is_ai_generated: true;
85
+ disclosure: "You are interacting with an AI.";
86
+ article: "EU_AI_ACT_ARTICLE_50";
87
+ injection_mode: "deterministic";
88
+ }
89
+ interface RequestOptions {
90
+ apiKey?: string;
91
+ }
92
+ type AgentTelemetryContext = {
93
+ workflow_id?: string;
94
+ workflow_run_id?: string;
95
+ workflow_step_id?: string;
96
+ workflow_name?: string;
97
+ workflow_step_name?: string;
98
+ workflow_step_index?: number;
99
+ parent_event_id?: string;
100
+ tool_name?: string;
101
+ tool_target?: string;
102
+ tool_target_type?: string;
103
+ event_title?: string;
104
+ event_status?: string;
105
+ event_category?: string;
106
+ event_subtype?: string;
107
+ workflowId?: string;
108
+ workflowRunId?: string;
109
+ workflowStepId?: string;
110
+ workflowName?: string;
111
+ workflowStepName?: string;
112
+ workflowStepIndex?: number;
113
+ parentEventId?: string;
114
+ toolName?: string;
115
+ toolTarget?: string;
116
+ toolTargetType?: string;
117
+ eventTitle?: string;
118
+ eventStatus?: string;
119
+ eventCategory?: string;
120
+ eventSubtype?: string;
121
+ [key: string]: unknown;
122
+ };
123
+ type AgentOperationCategory = "ai" | "guard" | "tool" | "delivery" | "inbox" | "workflow" | "compliance" | "operational";
124
+ type AgentOperationStatus = "started" | "completed" | "failed" | "blocked" | "skipped";
125
+ type AgentEventType = "start" | "complete" | "error" | "human_override" | "security_alert" | "security_block" | "security_policy_violation" | "transparency_badge_rendered" | (string & {});
126
+ type InjectionScanRequestOptions = RequestOptions & {
127
+ clientEventId?: string;
128
+ systemId?: string;
129
+ };
130
+ type PromptPreflightLogParams = {
131
+ system_id: string;
132
+ user_id?: string;
133
+ request_identity?: Record<string, unknown>;
134
+ model?: string;
135
+ input: string;
136
+ telemetry?: AgentTelemetryContext;
137
+ guard_event_id?: string | null;
138
+ guard_latency_ms?: number | null;
139
+ preflight_for_client_event_id: string;
140
+ verdict: Pick<GuardResponse, "allowed" | "reason" | "detected_pii" | "shadow_mode" | "simulated_decision" | "shadow_blocked">;
141
+ client_capabilities?: LogParams["client_capabilities"];
142
+ local_fallback_applied?: boolean;
143
+ local_fallback_reason?: string | null;
144
+ runtime_surface?: string;
145
+ };
146
+ interface WrapOpenAIOptions {
147
+ system_id: string;
148
+ user_id?: string;
149
+ expected_languages?: string[];
150
+ expectedLanguages?: string[];
151
+ request_identity?: Record<string, unknown>;
152
+ telemetry?: AgentTelemetryContext;
153
+ apiKey?: string;
154
+ api_key?: string;
155
+ resolveApiKey?: (request: Record<string, unknown>) => string | undefined;
156
+ }
157
+ interface LogParams {
158
+ event_id?: string;
159
+ system_id?: string;
160
+ input: string;
161
+ output: string;
162
+ model: string;
163
+ usage?: Record<string, unknown>;
164
+ tokens?: Record<string, unknown>;
165
+ latency?: number;
166
+ user_id?: string;
167
+ request_identity?: Record<string, unknown>;
168
+ metadata?: Record<string, unknown>;
169
+ event_type?: AgentEventType;
170
+ severity?: "info" | "warning" | "error" | "high";
171
+ timestamp?: string;
172
+ client_capabilities?: {
173
+ capabilities: {
174
+ has_feedback_handler: boolean;
175
+ pii_masking_enabled: boolean;
176
+ framework: string;
177
+ };
178
+ };
179
+ }
180
+ type AgentIDConfig = {
181
+ apiKey?: string;
182
+ baseUrl?: string;
183
+ piiMasking?: boolean;
184
+ secretMasking?: boolean;
185
+ checkInjection?: boolean;
186
+ clientFastFail?: boolean;
187
+ client_fast_fail?: boolean;
188
+ aiScanEnabled?: boolean;
189
+ storePii?: boolean;
190
+ strictMode?: boolean;
191
+ failureMode?: "fail_open" | "fail_close";
192
+ guardTimeoutMs?: number;
193
+ ingestTimeoutMs?: number;
194
+ };
195
+
196
+ declare function createAgentIdCorrelationId(seed?: string): string;
197
+ declare function createAgentIdTelemetryContext(value?: AgentTelemetryContext): AgentTelemetryContext | undefined;
198
+ declare function createAgentIdOperationLog(params: OperationLogParams): LogParams;
199
+ interface OperationLogParams {
200
+ event_id?: string;
201
+ client_event_id?: string;
202
+ system_id?: string;
203
+ user_id?: string;
204
+ request_identity?: Record<string, unknown>;
205
+ input?: string;
206
+ output?: string;
207
+ model?: string;
208
+ usage?: Record<string, unknown>;
209
+ tokens?: Record<string, unknown>;
210
+ latency?: number;
211
+ metadata?: Record<string, unknown>;
212
+ telemetry?: AgentTelemetryContext;
213
+ event_type?: AgentEventType;
214
+ event_category?: AgentOperationCategory | string;
215
+ event_subtype?: string;
216
+ event_status?: AgentOperationStatus | string;
217
+ severity?: "info" | "warning" | "error" | "high";
218
+ timestamp?: string;
219
+ client_capabilities?: {
220
+ capabilities: {
221
+ has_feedback_handler: boolean;
222
+ pii_masking_enabled: boolean;
223
+ framework: string;
224
+ };
225
+ };
226
+ }
227
+ type PreparedInput = {
228
+ sanitizedInput: string;
229
+ capabilityConfig: CapabilityConfig;
230
+ sdkConfigFetchMs?: number;
231
+ sdkLocalScanMs?: number;
232
+ piiMapping?: PIIMapping;
233
+ shouldDeanonymize?: boolean;
234
+ };
235
+ declare class SecurityBlockError extends Error {
236
+ reason: string;
237
+ constructor(reason?: string);
238
+ }
239
+ declare class DependencyError extends Error {
240
+ dependency: "ingest";
241
+ reason: string;
242
+ status: number | null;
243
+ constructor(params: {
244
+ dependency: "ingest";
245
+ reason: string;
246
+ status: number | null;
247
+ });
248
+ }
249
+ declare class AgentID {
250
+ private baseUrl;
251
+ private apiKey;
252
+ private configuredPiiMasking;
253
+ private configuredSecretMasking;
254
+ private checkInjection;
255
+ private clientFastFail;
256
+ private aiScanEnabled;
257
+ private storePii;
258
+ private strictMode;
259
+ private configuredFailureMode;
260
+ private guardTimeoutMs;
261
+ private ingestTimeoutMs;
262
+ private pii;
263
+ private localEnforcer;
264
+ private injectionScanner;
265
+ private recentGuardVerdicts;
266
+ constructor(config?: AgentIDConfig);
267
+ get piiMasking(): boolean | undefined;
268
+ get secretMasking(): boolean | undefined;
269
+ private resolveEffectivePiiMasking;
270
+ private resolveEffectiveSecretMasking;
271
+ getEffectivePiiMasking(options?: RequestOptions): boolean;
272
+ getEffectivePiiMaskingForConfig(capabilityConfig?: CapabilityConfig): boolean;
273
+ getEffectiveSecretMaskingForConfig(capabilityConfig?: CapabilityConfig): boolean;
274
+ private buildClientCapabilities;
275
+ private resolveApiKey;
276
+ private resolveClientEventId;
277
+ private buildGuardCacheKey;
278
+ private readCachedGuardVerdict;
279
+ private cacheGuardVerdict;
280
+ getCapabilityConfig(force?: boolean, options?: RequestOptions): Promise<CapabilityConfig>;
281
+ private getCapabilityConfigWithTelemetry;
282
+ private getCachedCapabilityConfig;
283
+ private resolveEffectiveStrictMode;
284
+ private maybeRaiseStrictIngestDependencyError;
285
+ private shouldRunLocalInjectionScan;
286
+ private refreshCapabilityConfigBeforeClientControl;
287
+ private applyLocalPolicyChecks;
288
+ prepareInputForDispatch(params: {
289
+ input: string;
290
+ systemId: string;
291
+ stream: boolean;
292
+ skipInjectionScan?: boolean;
293
+ clientEventId?: string;
294
+ telemetryMetadata?: AgentTelemetryContext;
295
+ }, options?: RequestOptions): Promise<PreparedInput>;
296
+ applyLocalFallbackForGuardFailure(params: {
297
+ input: string;
298
+ systemId: string;
299
+ stream: boolean;
300
+ clientEventId?: string;
301
+ capabilityConfig?: CapabilityConfig;
302
+ sdkConfigFetchMs?: number;
303
+ telemetryMetadata?: AgentTelemetryContext;
304
+ }, options?: RequestOptions): Promise<PreparedInput>;
305
+ scanPromptInjection(input: string, options?: InjectionScanRequestOptions): Promise<void>;
306
+ private withMaskedOpenAIRequest;
307
+ private logSecurityPolicyViolation;
308
+ private logGuardFallback;
309
+ private finalizeIngestTelemetry;
310
+ /**
311
+ * GUARD: Checks limits, PII, and security before execution.
312
+ * strictMode=false (default): FAIL-OPEN on connectivity/timeouts.
313
+ * strictMode=true: FAIL-CLOSED and throws on connectivity/timeouts.
314
+ */
315
+ guard(params: GuardParams, options?: RequestOptions): Promise<GuardResponse>;
316
+ private sendIngest;
317
+ private extractStreamChunkText;
318
+ private extractStreamChunkUsage;
319
+ private isOpenAIStreamFinishChunk;
320
+ private setOpenAIStreamChunkText;
321
+ private createSyntheticOpenAIStreamChunk;
322
+ private rewriteOpenAIStreamChunkForClient;
323
+ private wrapCompletion;
324
+ /**
325
+ * LOG: Sends telemetry after execution.
326
+ * Returns a Promise so callers can await persistence when needed.
327
+ */
328
+ log(params: LogParams, options?: RequestOptions): Promise<void>;
329
+ buildOperationLogParams(params: OperationLogParams): LogParams;
330
+ logOperation(params: OperationLogParams, options?: RequestOptions): Promise<void>;
331
+ logPromptPreflightStep(params: PromptPreflightLogParams, options?: RequestOptions): Promise<void>;
332
+ operation(params: OperationLogParams, options?: RequestOptions): Promise<void>;
333
+ /**
334
+ * Analytics alias for telemetry logging.
335
+ */
336
+ analytics(params: LogParams, options?: RequestOptions): Promise<void>;
337
+ /**
338
+ * Trace alias for telemetry logging.
339
+ */
340
+ trace(params: LogParams, options?: RequestOptions): Promise<void>;
341
+ /**
342
+ * Wrap an OpenAI client once; AgentID will automatically:
343
+ * - run guard() before chat.completions.create
344
+ * - measure latency
345
+ * - persist ingest telemetry for the wrapped call
346
+ */
347
+ wrapOpenAI<T>(openai: T, options: WrapOpenAIOptions): T;
348
+ }
349
+ type AgentIDWorkflowTrailAgent = Pick<AgentID, "buildOperationLogParams" | "log">;
350
+ interface AgentIDWorkflowTrailOptions {
351
+ agent: AgentIDWorkflowTrailAgent;
352
+ system_id: string;
353
+ user_id?: string;
354
+ request_identity?: Record<string, unknown>;
355
+ telemetry?: AgentTelemetryContext;
356
+ client_capabilities?: LogParams["client_capabilities"];
357
+ requestOptions?: RequestOptions;
358
+ }
359
+ type AgentIDWorkflowStepParams = Omit<OperationLogParams, "system_id" | "user_id" | "request_identity">;
360
+ interface AgentIDWorkflowRunHooks<TResult = unknown> {
361
+ complete?: AgentIDWorkflowStepParams;
362
+ fail?: AgentIDWorkflowStepParams;
363
+ onComplete?: (result: TResult) => AgentIDWorkflowStepParams | void;
364
+ onError?: (error: unknown) => AgentIDWorkflowStepParams | void;
365
+ }
366
+ declare class AgentIDWorkflowStep {
367
+ readonly workflowStepId: string;
368
+ readonly startEventId: string;
369
+ readonly telemetry?: AgentTelemetryContext;
370
+ private trail;
371
+ private startedAtMs;
372
+ constructor(params: {
373
+ trail: AgentIDWorkflowTrail;
374
+ workflowStepId: string;
375
+ startEventId: string;
376
+ telemetry?: AgentTelemetryContext;
377
+ startedAtMs: number;
378
+ });
379
+ private resolveStepTelemetry;
380
+ log(params?: AgentIDWorkflowStepParams, options?: RequestOptions): Promise<LogParams>;
381
+ complete(params?: AgentIDWorkflowStepParams, options?: RequestOptions): Promise<LogParams>;
382
+ fail(error: unknown, params?: AgentIDWorkflowStepParams, options?: RequestOptions): Promise<LogParams>;
383
+ }
384
+ declare class AgentIDWorkflowTrail {
385
+ private agent;
386
+ private systemId;
387
+ private userId?;
388
+ private requestIdentity?;
389
+ private telemetry?;
390
+ private clientCapabilities?;
391
+ private requestOptions?;
392
+ constructor(options: AgentIDWorkflowTrailOptions);
393
+ logStep(params?: AgentIDWorkflowStepParams, options?: RequestOptions): Promise<LogParams>;
394
+ startStep(params?: AgentIDWorkflowStepParams, options?: RequestOptions): Promise<AgentIDWorkflowStep>;
395
+ runStep<TResult>(params: AgentIDWorkflowStepParams, run: () => Promise<TResult> | TResult, hooks?: AgentIDWorkflowRunHooks<TResult>, options?: RequestOptions): Promise<TResult>;
396
+ }
397
+ declare function createAgentIdWorkflowTrail(options: AgentIDWorkflowTrailOptions): AgentIDWorkflowTrail;
398
+
399
+ export { type AgentEventType as A, DependencyError as D, type GuardAttachment as G, type LogParams as L, type OperationLogParams as O, PIIManager as P, type RequestOptions as R, SecurityBlockError as S, type TransparencyMetadata as T, type WrapOpenAIOptions as W, AgentID as a, type AgentIDWorkflowRunHooks as b, AgentIDWorkflowStep as c, type AgentIDWorkflowStepParams as d, AgentIDWorkflowTrail as e, type AgentIDWorkflowTrailOptions as f, type AgentOperationCategory as g, type AgentOperationStatus as h, type AgentTelemetryContext as i, type GuardParams as j, type GuardResponse as k, type PIIAnonymizeOptions as l, type PIIMapping as m, type PreparedInput as n, createAgentIdCorrelationId as o, createAgentIdOperationLog as p, createAgentIdTelemetryContext as q, createAgentIdWorkflowTrail as r };