agentid-sdk 0.1.23 → 0.1.25
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 +25 -0
- package/dist/{agentid-BmsXTOCc.d.mts → agentid-B5Y1g2Ko.d.mts} +47 -4
- package/dist/{agentid-BmsXTOCc.d.ts → agentid-B5Y1g2Ko.d.ts} +47 -4
- package/dist/{chunk-4FSEYTEC.mjs → chunk-3PLUMWYC.mjs} +308 -56
- package/dist/index.d.mts +31 -2
- package/dist/index.d.ts +31 -2
- package/dist/index.js +470 -56
- package/dist/index.mjs +163 -1
- package/dist/langchain.d.mts +4 -1
- package/dist/langchain.d.ts +4 -1
- package/dist/langchain.js +65 -8
- package/dist/langchain.mjs +65 -8
- package/package.json +7 -2
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({
|
|
@@ -109,6 +110,8 @@ const response = await secured.chat.completions.create({
|
|
|
109
110
|
console.log(response.choices[0]?.message?.content ?? "");
|
|
110
111
|
```
|
|
111
112
|
|
|
113
|
+
> Scope note: AgentID compliance/risk controls apply to the specific SDK-wrapped LLM calls (`guard()`, `wrapOpenAI()`, LangChain callback-wrapped flows). They do not automatically classify unrelated code paths in your whole monolithic application.
|
|
114
|
+
|
|
112
115
|
### LangChain Integration
|
|
113
116
|
|
|
114
117
|
```bash
|
|
@@ -125,6 +128,7 @@ import { StringOutputParser } from "@langchain/core/output_parsers";
|
|
|
125
128
|
const agent = new AgentID();
|
|
126
129
|
const handler = new AgentIDCallbackHandler(agent, {
|
|
127
130
|
system_id: process.env.AGENTID_SYSTEM_ID!,
|
|
131
|
+
expected_languages: ["en"],
|
|
128
132
|
});
|
|
129
133
|
|
|
130
134
|
const prompt = ChatPromptTemplate.fromTemplate("Answer in one sentence: {question}");
|
|
@@ -159,6 +163,27 @@ await agent.log({
|
|
|
159
163
|
});
|
|
160
164
|
```
|
|
161
165
|
|
|
166
|
+
### Transparency Badge (Article 50 UI Evidence)
|
|
167
|
+
|
|
168
|
+
When rendering disclosure UI, log proof-of-render telemetry so you can demonstrate the end-user actually saw the badge.
|
|
169
|
+
|
|
170
|
+
```tsx
|
|
171
|
+
import { AgentIDTransparencyBadge } from "agentid-sdk";
|
|
172
|
+
|
|
173
|
+
<AgentIDTransparencyBadge
|
|
174
|
+
telemetry={{
|
|
175
|
+
systemId: process.env.NEXT_PUBLIC_AGENTID_SYSTEM_ID!,
|
|
176
|
+
// Prefer a backend relay endpoint so no secret key is exposed in browser code.
|
|
177
|
+
ingestUrl: "/api/agentid/transparency-render",
|
|
178
|
+
headers: { "x-agentid-system-id": process.env.NEXT_PUBLIC_AGENTID_SYSTEM_ID! },
|
|
179
|
+
userId: "customer-123",
|
|
180
|
+
}}
|
|
181
|
+
placement="chat-header"
|
|
182
|
+
/>;
|
|
183
|
+
```
|
|
184
|
+
|
|
185
|
+
On mount, the component asynchronously emits `event_type: "transparency_badge_rendered"` to the AgentID ingest endpoint.
|
|
186
|
+
|
|
162
187
|
## 6. Advanced Configuration
|
|
163
188
|
|
|
164
189
|
### Custom identity / role metadata
|
|
@@ -3,7 +3,9 @@ type CapabilityConfig = {
|
|
|
3
3
|
strict_security_mode: boolean;
|
|
4
4
|
failure_mode: "fail_open" | "fail_close";
|
|
5
5
|
block_on_heuristic: boolean;
|
|
6
|
+
inject_transparency_metadata: boolean;
|
|
6
7
|
block_pii_leakage: boolean;
|
|
8
|
+
enable_sdk_pii_masking?: boolean;
|
|
7
9
|
block_db_access: boolean;
|
|
8
10
|
block_code_execution: boolean;
|
|
9
11
|
block_toxicity: boolean;
|
|
@@ -15,6 +17,7 @@ interface GuardParams {
|
|
|
15
17
|
model?: string;
|
|
16
18
|
user_id?: string;
|
|
17
19
|
client_event_id?: string;
|
|
20
|
+
expected_languages?: string[];
|
|
18
21
|
client_capabilities?: {
|
|
19
22
|
capabilities: {
|
|
20
23
|
has_feedback_handler: boolean;
|
|
@@ -30,12 +33,34 @@ interface GuardResponse {
|
|
|
30
33
|
transformed_input?: string;
|
|
31
34
|
guard_event_id?: string;
|
|
32
35
|
client_event_id?: string;
|
|
36
|
+
guard_latency_ms?: number;
|
|
33
37
|
shadow_mode?: boolean;
|
|
34
38
|
simulated_decision?: "allowed" | "masked" | "blocked";
|
|
39
|
+
shadow_blocked?: boolean;
|
|
40
|
+
policy_pack_matcher_backend?: "rust_wasm" | "js_hybrid" | "legacy_fallback";
|
|
41
|
+
policy_pack_scan_profile?: "expected_languages" | "auto_detected" | "global_high_priority" | "core_en_fallback";
|
|
42
|
+
policy_pack_scan_mode?: "full" | "segmented";
|
|
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";
|
|
49
|
+
transparency?: TransparencyMetadata;
|
|
50
|
+
}
|
|
51
|
+
interface TransparencyMetadata {
|
|
52
|
+
is_ai_generated: true;
|
|
53
|
+
disclosure: "You are interacting with an AI.";
|
|
54
|
+
article: "EU_AI_ACT_ARTICLE_50";
|
|
55
|
+
injection_mode: "deterministic";
|
|
35
56
|
}
|
|
36
57
|
interface RequestOptions {
|
|
37
58
|
apiKey?: string;
|
|
38
59
|
}
|
|
60
|
+
type InjectionScanRequestOptions = RequestOptions & {
|
|
61
|
+
clientEventId?: string;
|
|
62
|
+
systemId?: string;
|
|
63
|
+
};
|
|
39
64
|
interface LogParams {
|
|
40
65
|
event_id?: string;
|
|
41
66
|
system_id?: string;
|
|
@@ -47,7 +72,7 @@ interface LogParams {
|
|
|
47
72
|
latency?: number;
|
|
48
73
|
user_id?: string;
|
|
49
74
|
metadata?: Record<string, unknown>;
|
|
50
|
-
event_type?: "start" | "complete" | "error" | "human_override" | "security_alert" | "security_block" | "security_policy_violation";
|
|
75
|
+
event_type?: "start" | "complete" | "error" | "human_override" | "security_alert" | "security_block" | "security_policy_violation" | "transparency_badge_rendered";
|
|
51
76
|
severity?: "info" | "warning" | "error" | "high";
|
|
52
77
|
timestamp?: string;
|
|
53
78
|
client_capabilities?: {
|
|
@@ -66,6 +91,7 @@ type AgentIDConfig = {
|
|
|
66
91
|
aiScanEnabled?: boolean;
|
|
67
92
|
storePii?: boolean;
|
|
68
93
|
strictMode?: boolean;
|
|
94
|
+
failureMode?: "fail_open" | "fail_close";
|
|
69
95
|
guardTimeoutMs?: number;
|
|
70
96
|
ingestTimeoutMs?: number;
|
|
71
97
|
};
|
|
@@ -78,14 +104,25 @@ declare class SecurityBlockError extends Error {
|
|
|
78
104
|
reason: string;
|
|
79
105
|
constructor(reason?: string);
|
|
80
106
|
}
|
|
107
|
+
declare class DependencyError extends Error {
|
|
108
|
+
dependency: "ingest";
|
|
109
|
+
reason: string;
|
|
110
|
+
status: number | null;
|
|
111
|
+
constructor(params: {
|
|
112
|
+
dependency: "ingest";
|
|
113
|
+
reason: string;
|
|
114
|
+
status: number | null;
|
|
115
|
+
});
|
|
116
|
+
}
|
|
81
117
|
declare class AgentID {
|
|
82
118
|
private baseUrl;
|
|
83
119
|
private apiKey;
|
|
84
|
-
private
|
|
120
|
+
private configuredPiiMasking;
|
|
85
121
|
private checkInjection;
|
|
86
122
|
private aiScanEnabled;
|
|
87
123
|
private storePii;
|
|
88
124
|
private strictMode;
|
|
125
|
+
private configuredFailureMode;
|
|
89
126
|
private guardTimeoutMs;
|
|
90
127
|
private ingestTimeoutMs;
|
|
91
128
|
private pii;
|
|
@@ -93,6 +130,9 @@ declare class AgentID {
|
|
|
93
130
|
private injectionScanner;
|
|
94
131
|
private recentGuardVerdicts;
|
|
95
132
|
constructor(config?: AgentIDConfig);
|
|
133
|
+
get piiMasking(): boolean | undefined;
|
|
134
|
+
private resolveEffectivePiiMasking;
|
|
135
|
+
getEffectivePiiMasking(options?: RequestOptions): boolean;
|
|
96
136
|
private buildClientCapabilities;
|
|
97
137
|
private resolveApiKey;
|
|
98
138
|
private resolveClientEventId;
|
|
@@ -102,6 +142,7 @@ declare class AgentID {
|
|
|
102
142
|
getCapabilityConfig(force?: boolean, options?: RequestOptions): Promise<CapabilityConfig>;
|
|
103
143
|
private getCachedCapabilityConfig;
|
|
104
144
|
private resolveEffectiveStrictMode;
|
|
145
|
+
private maybeRaiseStrictIngestDependencyError;
|
|
105
146
|
private shouldRunLocalInjectionScan;
|
|
106
147
|
prepareInputForDispatch(params: {
|
|
107
148
|
input: string;
|
|
@@ -109,7 +150,7 @@ declare class AgentID {
|
|
|
109
150
|
stream: boolean;
|
|
110
151
|
skipInjectionScan?: boolean;
|
|
111
152
|
}, options?: RequestOptions): Promise<PreparedInput>;
|
|
112
|
-
scanPromptInjection(input: string, options?:
|
|
153
|
+
scanPromptInjection(input: string, options?: InjectionScanRequestOptions): Promise<void>;
|
|
113
154
|
private withMaskedOpenAIRequest;
|
|
114
155
|
private logSecurityPolicyViolation;
|
|
115
156
|
private logGuardFallback;
|
|
@@ -144,10 +185,12 @@ declare class AgentID {
|
|
|
144
185
|
wrapOpenAI<T>(openai: T, options: {
|
|
145
186
|
system_id: string;
|
|
146
187
|
user_id?: string;
|
|
188
|
+
expected_languages?: string[];
|
|
189
|
+
expectedLanguages?: string[];
|
|
147
190
|
apiKey?: string;
|
|
148
191
|
api_key?: string;
|
|
149
192
|
resolveApiKey?: (request: Record<string, unknown>) => string | undefined;
|
|
150
193
|
}): T;
|
|
151
194
|
}
|
|
152
195
|
|
|
153
|
-
export { AgentID as A, type GuardParams as G, type LogParams as L, type PreparedInput as P, type RequestOptions as R, SecurityBlockError as S, type GuardResponse as a };
|
|
196
|
+
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 };
|
|
@@ -3,7 +3,9 @@ type CapabilityConfig = {
|
|
|
3
3
|
strict_security_mode: boolean;
|
|
4
4
|
failure_mode: "fail_open" | "fail_close";
|
|
5
5
|
block_on_heuristic: boolean;
|
|
6
|
+
inject_transparency_metadata: boolean;
|
|
6
7
|
block_pii_leakage: boolean;
|
|
8
|
+
enable_sdk_pii_masking?: boolean;
|
|
7
9
|
block_db_access: boolean;
|
|
8
10
|
block_code_execution: boolean;
|
|
9
11
|
block_toxicity: boolean;
|
|
@@ -15,6 +17,7 @@ interface GuardParams {
|
|
|
15
17
|
model?: string;
|
|
16
18
|
user_id?: string;
|
|
17
19
|
client_event_id?: string;
|
|
20
|
+
expected_languages?: string[];
|
|
18
21
|
client_capabilities?: {
|
|
19
22
|
capabilities: {
|
|
20
23
|
has_feedback_handler: boolean;
|
|
@@ -30,12 +33,34 @@ interface GuardResponse {
|
|
|
30
33
|
transformed_input?: string;
|
|
31
34
|
guard_event_id?: string;
|
|
32
35
|
client_event_id?: string;
|
|
36
|
+
guard_latency_ms?: number;
|
|
33
37
|
shadow_mode?: boolean;
|
|
34
38
|
simulated_decision?: "allowed" | "masked" | "blocked";
|
|
39
|
+
shadow_blocked?: boolean;
|
|
40
|
+
policy_pack_matcher_backend?: "rust_wasm" | "js_hybrid" | "legacy_fallback";
|
|
41
|
+
policy_pack_scan_profile?: "expected_languages" | "auto_detected" | "global_high_priority" | "core_en_fallback";
|
|
42
|
+
policy_pack_scan_mode?: "full" | "segmented";
|
|
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";
|
|
49
|
+
transparency?: TransparencyMetadata;
|
|
50
|
+
}
|
|
51
|
+
interface TransparencyMetadata {
|
|
52
|
+
is_ai_generated: true;
|
|
53
|
+
disclosure: "You are interacting with an AI.";
|
|
54
|
+
article: "EU_AI_ACT_ARTICLE_50";
|
|
55
|
+
injection_mode: "deterministic";
|
|
35
56
|
}
|
|
36
57
|
interface RequestOptions {
|
|
37
58
|
apiKey?: string;
|
|
38
59
|
}
|
|
60
|
+
type InjectionScanRequestOptions = RequestOptions & {
|
|
61
|
+
clientEventId?: string;
|
|
62
|
+
systemId?: string;
|
|
63
|
+
};
|
|
39
64
|
interface LogParams {
|
|
40
65
|
event_id?: string;
|
|
41
66
|
system_id?: string;
|
|
@@ -47,7 +72,7 @@ interface LogParams {
|
|
|
47
72
|
latency?: number;
|
|
48
73
|
user_id?: string;
|
|
49
74
|
metadata?: Record<string, unknown>;
|
|
50
|
-
event_type?: "start" | "complete" | "error" | "human_override" | "security_alert" | "security_block" | "security_policy_violation";
|
|
75
|
+
event_type?: "start" | "complete" | "error" | "human_override" | "security_alert" | "security_block" | "security_policy_violation" | "transparency_badge_rendered";
|
|
51
76
|
severity?: "info" | "warning" | "error" | "high";
|
|
52
77
|
timestamp?: string;
|
|
53
78
|
client_capabilities?: {
|
|
@@ -66,6 +91,7 @@ type AgentIDConfig = {
|
|
|
66
91
|
aiScanEnabled?: boolean;
|
|
67
92
|
storePii?: boolean;
|
|
68
93
|
strictMode?: boolean;
|
|
94
|
+
failureMode?: "fail_open" | "fail_close";
|
|
69
95
|
guardTimeoutMs?: number;
|
|
70
96
|
ingestTimeoutMs?: number;
|
|
71
97
|
};
|
|
@@ -78,14 +104,25 @@ declare class SecurityBlockError extends Error {
|
|
|
78
104
|
reason: string;
|
|
79
105
|
constructor(reason?: string);
|
|
80
106
|
}
|
|
107
|
+
declare class DependencyError extends Error {
|
|
108
|
+
dependency: "ingest";
|
|
109
|
+
reason: string;
|
|
110
|
+
status: number | null;
|
|
111
|
+
constructor(params: {
|
|
112
|
+
dependency: "ingest";
|
|
113
|
+
reason: string;
|
|
114
|
+
status: number | null;
|
|
115
|
+
});
|
|
116
|
+
}
|
|
81
117
|
declare class AgentID {
|
|
82
118
|
private baseUrl;
|
|
83
119
|
private apiKey;
|
|
84
|
-
private
|
|
120
|
+
private configuredPiiMasking;
|
|
85
121
|
private checkInjection;
|
|
86
122
|
private aiScanEnabled;
|
|
87
123
|
private storePii;
|
|
88
124
|
private strictMode;
|
|
125
|
+
private configuredFailureMode;
|
|
89
126
|
private guardTimeoutMs;
|
|
90
127
|
private ingestTimeoutMs;
|
|
91
128
|
private pii;
|
|
@@ -93,6 +130,9 @@ declare class AgentID {
|
|
|
93
130
|
private injectionScanner;
|
|
94
131
|
private recentGuardVerdicts;
|
|
95
132
|
constructor(config?: AgentIDConfig);
|
|
133
|
+
get piiMasking(): boolean | undefined;
|
|
134
|
+
private resolveEffectivePiiMasking;
|
|
135
|
+
getEffectivePiiMasking(options?: RequestOptions): boolean;
|
|
96
136
|
private buildClientCapabilities;
|
|
97
137
|
private resolveApiKey;
|
|
98
138
|
private resolveClientEventId;
|
|
@@ -102,6 +142,7 @@ declare class AgentID {
|
|
|
102
142
|
getCapabilityConfig(force?: boolean, options?: RequestOptions): Promise<CapabilityConfig>;
|
|
103
143
|
private getCachedCapabilityConfig;
|
|
104
144
|
private resolveEffectiveStrictMode;
|
|
145
|
+
private maybeRaiseStrictIngestDependencyError;
|
|
105
146
|
private shouldRunLocalInjectionScan;
|
|
106
147
|
prepareInputForDispatch(params: {
|
|
107
148
|
input: string;
|
|
@@ -109,7 +150,7 @@ declare class AgentID {
|
|
|
109
150
|
stream: boolean;
|
|
110
151
|
skipInjectionScan?: boolean;
|
|
111
152
|
}, options?: RequestOptions): Promise<PreparedInput>;
|
|
112
|
-
scanPromptInjection(input: string, options?:
|
|
153
|
+
scanPromptInjection(input: string, options?: InjectionScanRequestOptions): Promise<void>;
|
|
113
154
|
private withMaskedOpenAIRequest;
|
|
114
155
|
private logSecurityPolicyViolation;
|
|
115
156
|
private logGuardFallback;
|
|
@@ -144,10 +185,12 @@ declare class AgentID {
|
|
|
144
185
|
wrapOpenAI<T>(openai: T, options: {
|
|
145
186
|
system_id: string;
|
|
146
187
|
user_id?: string;
|
|
188
|
+
expected_languages?: string[];
|
|
189
|
+
expectedLanguages?: string[];
|
|
147
190
|
apiKey?: string;
|
|
148
191
|
api_key?: string;
|
|
149
192
|
resolveApiKey?: (request: Record<string, unknown>) => string | undefined;
|
|
150
193
|
}): T;
|
|
151
194
|
}
|
|
152
195
|
|
|
153
|
-
export { AgentID as A, type GuardParams as G, type LogParams as L, type PreparedInput as P, type RequestOptions as R, SecurityBlockError as S, type GuardResponse as a };
|
|
196
|
+
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 };
|