agentid-sdk 0.1.23 → 0.1.24
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 +23 -0
- package/dist/{agentid-BmsXTOCc.d.mts → agentid-BGCUoYV7.d.mts} +17 -2
- package/dist/{agentid-BmsXTOCc.d.ts → agentid-BGCUoYV7.d.ts} +17 -2
- package/dist/{chunk-4FSEYTEC.mjs → chunk-JLHAS2EE.mjs} +113 -24
- package/dist/index.d.mts +25 -2
- package/dist/index.d.ts +25 -2
- package/dist/index.js +274 -24
- package/dist/index.mjs +161 -1
- package/dist/langchain.d.mts +1 -1
- package/dist/langchain.d.ts +1 -1
- package/dist/langchain.js +50 -5
- package/dist/langchain.mjs +50 -5
- package/package.json +7 -2
package/README.md
CHANGED
|
@@ -109,6 +109,8 @@ const response = await secured.chat.completions.create({
|
|
|
109
109
|
console.log(response.choices[0]?.message?.content ?? "");
|
|
110
110
|
```
|
|
111
111
|
|
|
112
|
+
> 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.
|
|
113
|
+
|
|
112
114
|
### LangChain Integration
|
|
113
115
|
|
|
114
116
|
```bash
|
|
@@ -159,6 +161,27 @@ await agent.log({
|
|
|
159
161
|
});
|
|
160
162
|
```
|
|
161
163
|
|
|
164
|
+
### Transparency Badge (Article 50 UI Evidence)
|
|
165
|
+
|
|
166
|
+
When rendering disclosure UI, log proof-of-render telemetry so you can demonstrate the end-user actually saw the badge.
|
|
167
|
+
|
|
168
|
+
```tsx
|
|
169
|
+
import { AgentIDTransparencyBadge } from "agentid-sdk";
|
|
170
|
+
|
|
171
|
+
<AgentIDTransparencyBadge
|
|
172
|
+
telemetry={{
|
|
173
|
+
systemId: process.env.NEXT_PUBLIC_AGENTID_SYSTEM_ID!,
|
|
174
|
+
// Prefer a backend relay endpoint so no secret key is exposed in browser code.
|
|
175
|
+
ingestUrl: "/api/agentid/transparency-render",
|
|
176
|
+
headers: { "x-agentid-system-id": process.env.NEXT_PUBLIC_AGENTID_SYSTEM_ID! },
|
|
177
|
+
userId: "customer-123",
|
|
178
|
+
}}
|
|
179
|
+
placement="chat-header"
|
|
180
|
+
/>;
|
|
181
|
+
```
|
|
182
|
+
|
|
183
|
+
On mount, the component asynchronously emits `event_type: "transparency_badge_rendered"` to the AgentID ingest endpoint.
|
|
184
|
+
|
|
162
185
|
## 6. Advanced Configuration
|
|
163
186
|
|
|
164
187
|
### Custom identity / role metadata
|
|
@@ -3,6 +3,7 @@ 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;
|
|
7
8
|
block_db_access: boolean;
|
|
8
9
|
block_code_execution: boolean;
|
|
@@ -15,6 +16,7 @@ interface GuardParams {
|
|
|
15
16
|
model?: string;
|
|
16
17
|
user_id?: string;
|
|
17
18
|
client_event_id?: string;
|
|
19
|
+
expected_languages?: string[];
|
|
18
20
|
client_capabilities?: {
|
|
19
21
|
capabilities: {
|
|
20
22
|
has_feedback_handler: boolean;
|
|
@@ -30,8 +32,21 @@ interface GuardResponse {
|
|
|
30
32
|
transformed_input?: string;
|
|
31
33
|
guard_event_id?: string;
|
|
32
34
|
client_event_id?: string;
|
|
35
|
+
guard_latency_ms?: number;
|
|
33
36
|
shadow_mode?: boolean;
|
|
34
37
|
simulated_decision?: "allowed" | "masked" | "blocked";
|
|
38
|
+
shadow_blocked?: boolean;
|
|
39
|
+
policy_pack_matcher_backend?: "rust_wasm" | "js_hybrid" | "legacy_fallback";
|
|
40
|
+
policy_pack_scan_profile?: "expected_languages" | "core_en_fallback";
|
|
41
|
+
policy_pack_scan_mode?: "full" | "segmented";
|
|
42
|
+
exotic_language_detected?: boolean;
|
|
43
|
+
transparency?: TransparencyMetadata;
|
|
44
|
+
}
|
|
45
|
+
interface TransparencyMetadata {
|
|
46
|
+
is_ai_generated: true;
|
|
47
|
+
disclosure: "You are interacting with an AI.";
|
|
48
|
+
article: "EU_AI_ACT_ARTICLE_50";
|
|
49
|
+
injection_mode: "deterministic";
|
|
35
50
|
}
|
|
36
51
|
interface RequestOptions {
|
|
37
52
|
apiKey?: string;
|
|
@@ -47,7 +62,7 @@ interface LogParams {
|
|
|
47
62
|
latency?: number;
|
|
48
63
|
user_id?: string;
|
|
49
64
|
metadata?: Record<string, unknown>;
|
|
50
|
-
event_type?: "start" | "complete" | "error" | "human_override" | "security_alert" | "security_block" | "security_policy_violation";
|
|
65
|
+
event_type?: "start" | "complete" | "error" | "human_override" | "security_alert" | "security_block" | "security_policy_violation" | "transparency_badge_rendered";
|
|
51
66
|
severity?: "info" | "warning" | "error" | "high";
|
|
52
67
|
timestamp?: string;
|
|
53
68
|
client_capabilities?: {
|
|
@@ -150,4 +165,4 @@ declare class AgentID {
|
|
|
150
165
|
}): T;
|
|
151
166
|
}
|
|
152
167
|
|
|
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 };
|
|
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 };
|
|
@@ -3,6 +3,7 @@ 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;
|
|
7
8
|
block_db_access: boolean;
|
|
8
9
|
block_code_execution: boolean;
|
|
@@ -15,6 +16,7 @@ interface GuardParams {
|
|
|
15
16
|
model?: string;
|
|
16
17
|
user_id?: string;
|
|
17
18
|
client_event_id?: string;
|
|
19
|
+
expected_languages?: string[];
|
|
18
20
|
client_capabilities?: {
|
|
19
21
|
capabilities: {
|
|
20
22
|
has_feedback_handler: boolean;
|
|
@@ -30,8 +32,21 @@ interface GuardResponse {
|
|
|
30
32
|
transformed_input?: string;
|
|
31
33
|
guard_event_id?: string;
|
|
32
34
|
client_event_id?: string;
|
|
35
|
+
guard_latency_ms?: number;
|
|
33
36
|
shadow_mode?: boolean;
|
|
34
37
|
simulated_decision?: "allowed" | "masked" | "blocked";
|
|
38
|
+
shadow_blocked?: boolean;
|
|
39
|
+
policy_pack_matcher_backend?: "rust_wasm" | "js_hybrid" | "legacy_fallback";
|
|
40
|
+
policy_pack_scan_profile?: "expected_languages" | "core_en_fallback";
|
|
41
|
+
policy_pack_scan_mode?: "full" | "segmented";
|
|
42
|
+
exotic_language_detected?: boolean;
|
|
43
|
+
transparency?: TransparencyMetadata;
|
|
44
|
+
}
|
|
45
|
+
interface TransparencyMetadata {
|
|
46
|
+
is_ai_generated: true;
|
|
47
|
+
disclosure: "You are interacting with an AI.";
|
|
48
|
+
article: "EU_AI_ACT_ARTICLE_50";
|
|
49
|
+
injection_mode: "deterministic";
|
|
35
50
|
}
|
|
36
51
|
interface RequestOptions {
|
|
37
52
|
apiKey?: string;
|
|
@@ -47,7 +62,7 @@ interface LogParams {
|
|
|
47
62
|
latency?: number;
|
|
48
63
|
user_id?: string;
|
|
49
64
|
metadata?: Record<string, unknown>;
|
|
50
|
-
event_type?: "start" | "complete" | "error" | "human_override" | "security_alert" | "security_block" | "security_policy_violation";
|
|
65
|
+
event_type?: "start" | "complete" | "error" | "human_override" | "security_alert" | "security_block" | "security_policy_violation" | "transparency_badge_rendered";
|
|
51
66
|
severity?: "info" | "warning" | "error" | "high";
|
|
52
67
|
timestamp?: string;
|
|
53
68
|
client_capabilities?: {
|
|
@@ -150,4 +165,4 @@ declare class AgentID {
|
|
|
150
165
|
}): T;
|
|
151
166
|
}
|
|
152
167
|
|
|
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 };
|
|
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 };
|
|
@@ -1555,7 +1555,7 @@ function getInjectionScanner() {
|
|
|
1555
1555
|
|
|
1556
1556
|
// src/sdk-version.ts
|
|
1557
1557
|
var FALLBACK_SDK_VERSION = "js-0.0.0-dev";
|
|
1558
|
-
var AGENTID_SDK_VERSION_HEADER = "js-0.1.
|
|
1558
|
+
var AGENTID_SDK_VERSION_HEADER = "js-0.1.24".trim().length > 0 ? "js-0.1.24" : FALLBACK_SDK_VERSION;
|
|
1559
1559
|
|
|
1560
1560
|
// src/local-security-enforcer.ts
|
|
1561
1561
|
var DEFAULT_FAIL_OPEN_CONFIG = {
|
|
@@ -1563,6 +1563,7 @@ var DEFAULT_FAIL_OPEN_CONFIG = {
|
|
|
1563
1563
|
strict_security_mode: false,
|
|
1564
1564
|
failure_mode: "fail_open",
|
|
1565
1565
|
block_on_heuristic: false,
|
|
1566
|
+
inject_transparency_metadata: false,
|
|
1566
1567
|
block_pii_leakage: false,
|
|
1567
1568
|
block_db_access: false,
|
|
1568
1569
|
block_code_execution: false,
|
|
@@ -1745,6 +1746,11 @@ function normalizeCapabilityConfig(payload) {
|
|
|
1745
1746
|
strict_security_mode: effectiveStrictMode,
|
|
1746
1747
|
failure_mode: effectiveStrictMode ? "fail_close" : "fail_open",
|
|
1747
1748
|
block_on_heuristic: blockOnHeuristic,
|
|
1749
|
+
inject_transparency_metadata: readOptionalBooleanAliases(
|
|
1750
|
+
body,
|
|
1751
|
+
["inject_transparency_metadata", "transparency_metadata_enabled"],
|
|
1752
|
+
false
|
|
1753
|
+
),
|
|
1748
1754
|
block_pii_leakage: readBooleanField(body, "block_pii_leakage", "block_pii"),
|
|
1749
1755
|
block_db_access: readBooleanField(body, "block_db_access", "block_db"),
|
|
1750
1756
|
block_code_execution: readBooleanField(
|
|
@@ -2059,6 +2065,53 @@ async function safeReadJson2(response) {
|
|
|
2059
2065
|
return null;
|
|
2060
2066
|
}
|
|
2061
2067
|
}
|
|
2068
|
+
function coerceTransparencyMetadata(value) {
|
|
2069
|
+
if (!value || typeof value !== "object" || Array.isArray(value)) {
|
|
2070
|
+
return void 0;
|
|
2071
|
+
}
|
|
2072
|
+
const raw = value;
|
|
2073
|
+
if (raw.is_ai_generated !== true) {
|
|
2074
|
+
return void 0;
|
|
2075
|
+
}
|
|
2076
|
+
if (raw.disclosure !== "You are interacting with an AI.") {
|
|
2077
|
+
return void 0;
|
|
2078
|
+
}
|
|
2079
|
+
if (raw.article !== "EU_AI_ACT_ARTICLE_50") {
|
|
2080
|
+
return void 0;
|
|
2081
|
+
}
|
|
2082
|
+
if (raw.injection_mode !== "deterministic") {
|
|
2083
|
+
return void 0;
|
|
2084
|
+
}
|
|
2085
|
+
return {
|
|
2086
|
+
is_ai_generated: true,
|
|
2087
|
+
disclosure: "You are interacting with an AI.",
|
|
2088
|
+
article: "EU_AI_ACT_ARTICLE_50",
|
|
2089
|
+
injection_mode: "deterministic"
|
|
2090
|
+
};
|
|
2091
|
+
}
|
|
2092
|
+
function attachTransparencyMetadata(target, transparency) {
|
|
2093
|
+
if (!transparency) {
|
|
2094
|
+
return target;
|
|
2095
|
+
}
|
|
2096
|
+
if (!target || typeof target !== "object" && typeof target !== "function") {
|
|
2097
|
+
return target;
|
|
2098
|
+
}
|
|
2099
|
+
try {
|
|
2100
|
+
Object.defineProperty(target, "agentid_transparency", {
|
|
2101
|
+
value: transparency,
|
|
2102
|
+
enumerable: false,
|
|
2103
|
+
configurable: true,
|
|
2104
|
+
writable: false
|
|
2105
|
+
});
|
|
2106
|
+
return target;
|
|
2107
|
+
} catch {
|
|
2108
|
+
try {
|
|
2109
|
+
target.agentid_transparency = transparency;
|
|
2110
|
+
} catch {
|
|
2111
|
+
}
|
|
2112
|
+
return target;
|
|
2113
|
+
}
|
|
2114
|
+
}
|
|
2062
2115
|
function createCompletionChunkCollector() {
|
|
2063
2116
|
if (typeof TransformStream === "function") {
|
|
2064
2117
|
const stream = new TransformStream({
|
|
@@ -2383,6 +2436,16 @@ var AgentID = class {
|
|
|
2383
2436
|
* strictMode=true: FAIL-CLOSED and throws on connectivity/timeouts.
|
|
2384
2437
|
*/
|
|
2385
2438
|
async guard(params, options) {
|
|
2439
|
+
const guardStartedAt = Date.now();
|
|
2440
|
+
const withGuardLatency = (response) => {
|
|
2441
|
+
if (typeof response.guard_latency_ms === "number" && Number.isFinite(response.guard_latency_ms)) {
|
|
2442
|
+
return response;
|
|
2443
|
+
}
|
|
2444
|
+
return {
|
|
2445
|
+
...response,
|
|
2446
|
+
guard_latency_ms: Math.max(0, Date.now() - guardStartedAt)
|
|
2447
|
+
};
|
|
2448
|
+
};
|
|
2386
2449
|
const effectiveApiKey = this.resolveApiKey(options?.apiKey);
|
|
2387
2450
|
const effectiveStrictMode = await this.resolveEffectiveStrictMode({
|
|
2388
2451
|
apiKey: effectiveApiKey
|
|
@@ -2394,7 +2457,7 @@ var AgentID = class {
|
|
|
2394
2457
|
const guardCacheKey = this.buildGuardCacheKey(payload);
|
|
2395
2458
|
const cachedVerdict = this.readCachedGuardVerdict(guardCacheKey);
|
|
2396
2459
|
if (cachedVerdict) {
|
|
2397
|
-
return cachedVerdict;
|
|
2460
|
+
return withGuardLatency(cachedVerdict);
|
|
2398
2461
|
}
|
|
2399
2462
|
const correlationId = createCorrelationId(payload.client_event_id);
|
|
2400
2463
|
let lastStatusCode = null;
|
|
@@ -2418,7 +2481,12 @@ var AgentID = class {
|
|
|
2418
2481
|
lastStatusCode = res.status;
|
|
2419
2482
|
const responseBody = await safeReadJson2(res);
|
|
2420
2483
|
if (responseBody && typeof responseBody.allowed === "boolean") {
|
|
2421
|
-
const
|
|
2484
|
+
const rawVerdict = responseBody;
|
|
2485
|
+
const transparency = coerceTransparencyMetadata(rawVerdict.transparency);
|
|
2486
|
+
const verdict = {
|
|
2487
|
+
...rawVerdict,
|
|
2488
|
+
...transparency ? { transparency } : {}
|
|
2489
|
+
};
|
|
2422
2490
|
const infrastructureFailure = verdict.allowed === false && (isInfrastructureGuardReason(verdict.reason) || !verdict.reason && res.status >= 500);
|
|
2423
2491
|
if (infrastructureFailure) {
|
|
2424
2492
|
if (attempt < GUARD_MAX_ATTEMPTS - 1) {
|
|
@@ -2429,7 +2497,10 @@ var AgentID = class {
|
|
|
2429
2497
|
console.warn(
|
|
2430
2498
|
`[AgentID] Guard API infrastructure failure in strict mode (${verdict.reason ?? `http_${res.status}`}). Blocking request.`
|
|
2431
2499
|
);
|
|
2432
|
-
return {
|
|
2500
|
+
return withGuardLatency({
|
|
2501
|
+
allowed: false,
|
|
2502
|
+
reason: verdict.reason ?? "network_error_strict_mode"
|
|
2503
|
+
});
|
|
2433
2504
|
}
|
|
2434
2505
|
console.warn(
|
|
2435
2506
|
`[AgentID] Guard API infrastructure fallback in fail-open mode (${verdict.reason ?? `http_${res.status}`}).`
|
|
@@ -2440,10 +2511,10 @@ var AgentID = class {
|
|
|
2440
2511
|
guardParams: params,
|
|
2441
2512
|
apiKey: effectiveApiKey
|
|
2442
2513
|
});
|
|
2443
|
-
return { allowed: true, reason: "system_failure_fail_open" };
|
|
2514
|
+
return withGuardLatency({ allowed: true, reason: "system_failure_fail_open" });
|
|
2444
2515
|
}
|
|
2445
2516
|
this.cacheGuardVerdict(guardCacheKey, verdict);
|
|
2446
|
-
return verdict;
|
|
2517
|
+
return withGuardLatency(verdict);
|
|
2447
2518
|
}
|
|
2448
2519
|
if (!res.ok) {
|
|
2449
2520
|
if (res.status >= 500 && attempt < GUARD_MAX_ATTEMPTS - 1) {
|
|
@@ -2473,9 +2544,9 @@ var AgentID = class {
|
|
|
2473
2544
|
apiKey: effectiveApiKey
|
|
2474
2545
|
});
|
|
2475
2546
|
if (effectiveStrictMode) {
|
|
2476
|
-
return { allowed: false, reason: "network_error_strict_mode" };
|
|
2547
|
+
return withGuardLatency({ allowed: false, reason: "network_error_strict_mode" });
|
|
2477
2548
|
}
|
|
2478
|
-
return { allowed: true, reason: "timeout_fallback" };
|
|
2549
|
+
return withGuardLatency({ allowed: true, reason: "timeout_fallback" });
|
|
2479
2550
|
}
|
|
2480
2551
|
console.warn(
|
|
2481
2552
|
effectiveStrictMode ? "[AgentID] Guard check failed (Strict mode active):" : "[AgentID] Guard check failed (Fail-Open active):",
|
|
@@ -2488,33 +2559,33 @@ var AgentID = class {
|
|
|
2488
2559
|
apiKey: effectiveApiKey
|
|
2489
2560
|
});
|
|
2490
2561
|
if (effectiveStrictMode) {
|
|
2491
|
-
return { allowed: false, reason: "network_error_strict_mode" };
|
|
2562
|
+
return withGuardLatency({ allowed: false, reason: "network_error_strict_mode" });
|
|
2492
2563
|
}
|
|
2493
|
-
return { allowed: true, reason: "guard_unreachable" };
|
|
2564
|
+
return withGuardLatency({ allowed: true, reason: "guard_unreachable" });
|
|
2494
2565
|
} finally {
|
|
2495
2566
|
clearTimeout(timeoutId);
|
|
2496
2567
|
}
|
|
2497
2568
|
}
|
|
2498
2569
|
if (lastAbort) {
|
|
2499
2570
|
if (effectiveStrictMode) {
|
|
2500
|
-
return { allowed: false, reason: "network_error_strict_mode" };
|
|
2571
|
+
return withGuardLatency({ allowed: false, reason: "network_error_strict_mode" });
|
|
2501
2572
|
}
|
|
2502
|
-
return { allowed: true, reason: "timeout_fallback" };
|
|
2573
|
+
return withGuardLatency({ allowed: true, reason: "timeout_fallback" });
|
|
2503
2574
|
}
|
|
2504
2575
|
if (typeof lastStatusCode === "number" && lastStatusCode >= 500) {
|
|
2505
2576
|
if (effectiveStrictMode) {
|
|
2506
|
-
return { allowed: false, reason: "server_error" };
|
|
2577
|
+
return withGuardLatency({ allowed: false, reason: "server_error" });
|
|
2507
2578
|
}
|
|
2508
|
-
return { allowed: true, reason: "system_failure_fail_open" };
|
|
2579
|
+
return withGuardLatency({ allowed: true, reason: "system_failure_fail_open" });
|
|
2509
2580
|
}
|
|
2510
2581
|
console.warn(
|
|
2511
2582
|
effectiveStrictMode ? "[AgentID] Guard check failed (Strict mode active):" : "[AgentID] Guard check failed (Fail-Open active):",
|
|
2512
2583
|
lastError
|
|
2513
2584
|
);
|
|
2514
2585
|
if (effectiveStrictMode) {
|
|
2515
|
-
return { allowed: false, reason: "network_error_strict_mode" };
|
|
2586
|
+
return withGuardLatency({ allowed: false, reason: "network_error_strict_mode" });
|
|
2516
2587
|
}
|
|
2517
|
-
return { allowed: true, reason: "guard_unreachable" };
|
|
2588
|
+
return withGuardLatency({ allowed: true, reason: "guard_unreachable" });
|
|
2518
2589
|
}
|
|
2519
2590
|
async sendIngest(params, options) {
|
|
2520
2591
|
const effectiveApiKey = this.resolveApiKey(options?.apiKey);
|
|
@@ -2735,6 +2806,7 @@ var AgentID = class {
|
|
|
2735
2806
|
return async (...args) => {
|
|
2736
2807
|
const normalizedCreateArgs = normalizeOpenAICreateArgs(args);
|
|
2737
2808
|
const req = normalizedCreateArgs?.[0] ?? {};
|
|
2809
|
+
const pipelineStartedAt = Date.now();
|
|
2738
2810
|
const requestLevelApiKey = options.resolveApiKey?.(req) ?? options.apiKey ?? options.api_key;
|
|
2739
2811
|
const effectiveApiKey = this.resolveApiKey(requestLevelApiKey);
|
|
2740
2812
|
const requestOptions = { apiKey: effectiveApiKey };
|
|
@@ -2802,6 +2874,8 @@ var AgentID = class {
|
|
|
2802
2874
|
}
|
|
2803
2875
|
const canonicalClientEventId = typeof verdict.client_event_id === "string" && isUuidLike(verdict.client_event_id) ? verdict.client_event_id : clientEventId;
|
|
2804
2876
|
const guardEventId = typeof verdict.guard_event_id === "string" && verdict.guard_event_id.length > 0 ? verdict.guard_event_id : null;
|
|
2877
|
+
const guardLatencyMs = typeof verdict.guard_latency_ms === "number" && Number.isFinite(verdict.guard_latency_ms) ? Math.max(0, Math.trunc(verdict.guard_latency_ms)) : Math.max(0, Date.now() - pipelineStartedAt);
|
|
2878
|
+
const transparency = coerceTransparencyMetadata(verdict.transparency);
|
|
2805
2879
|
const isShadowMode = verdict.shadow_mode === true;
|
|
2806
2880
|
const transformedInput = isShadowMode ? maskedText : typeof verdict.transformed_input === "string" && verdict.transformed_input.length > 0 ? verdict.transformed_input : maskedText;
|
|
2807
2881
|
if (transformedInput !== maskedText) {
|
|
@@ -2815,6 +2889,7 @@ var AgentID = class {
|
|
|
2815
2889
|
createArgs = nextCreateArgs;
|
|
2816
2890
|
}
|
|
2817
2891
|
if (stream) {
|
|
2892
|
+
const modelStartedAt2 = Date.now();
|
|
2818
2893
|
const streamResponse = await originalCreate.apply(compTarget, createArgs);
|
|
2819
2894
|
const wrappedCompletion = this.wrapCompletion(
|
|
2820
2895
|
isAsyncIterable(streamResponse) ? streamResponse : (async function* () {
|
|
@@ -2825,6 +2900,8 @@ var AgentID = class {
|
|
|
2825
2900
|
);
|
|
2826
2901
|
if (maskedText && wrappedCompletion.mode === "stream") {
|
|
2827
2902
|
void wrappedCompletion.done.then(async (result) => {
|
|
2903
|
+
const modelLatencyMs2 = Math.max(0, Date.now() - modelStartedAt2);
|
|
2904
|
+
const totalPipelineLatencyMs2 = Math.max(0, Date.now() - pipelineStartedAt);
|
|
2828
2905
|
const outputForLog = isShadowMode ? result.rawOutput : result.transformedOutput;
|
|
2829
2906
|
const ingestResult = await this.sendIngest({
|
|
2830
2907
|
event_id: canonicalClientEventId,
|
|
@@ -2834,7 +2911,7 @@ var AgentID = class {
|
|
|
2834
2911
|
output: outputForLog,
|
|
2835
2912
|
model: adapter.getModelName(maskedReq),
|
|
2836
2913
|
usage: void 0,
|
|
2837
|
-
latency:
|
|
2914
|
+
latency: modelLatencyMs2,
|
|
2838
2915
|
event_type: "complete",
|
|
2839
2916
|
metadata: {
|
|
2840
2917
|
transformed_input: maskedText,
|
|
@@ -2844,8 +2921,12 @@ var AgentID = class {
|
|
|
2844
2921
|
simulated_decision: verdict.simulated_decision ?? null,
|
|
2845
2922
|
simulated_output_decision: isShadowMode && result.outputMasked ? "masked" : "allowed",
|
|
2846
2923
|
response_streamed: true,
|
|
2924
|
+
guard_latency_ms: guardLatencyMs,
|
|
2925
|
+
model_latency_ms: modelLatencyMs2,
|
|
2926
|
+
total_pipeline_latency_ms: totalPipelineLatencyMs2,
|
|
2847
2927
|
guard_event_id: guardEventId,
|
|
2848
|
-
client_event_id: canonicalClientEventId
|
|
2928
|
+
client_event_id: canonicalClientEventId,
|
|
2929
|
+
transparency
|
|
2849
2930
|
},
|
|
2850
2931
|
client_capabilities: this.buildClientCapabilities("openai", false)
|
|
2851
2932
|
}, requestOptions);
|
|
@@ -2858,11 +2939,15 @@ var AgentID = class {
|
|
|
2858
2939
|
console.error("[AgentID] Stream completion wrapping failed:", error);
|
|
2859
2940
|
});
|
|
2860
2941
|
}
|
|
2861
|
-
|
|
2942
|
+
if (wrappedCompletion.mode === "stream") {
|
|
2943
|
+
return attachTransparencyMetadata(wrappedCompletion.completion, transparency);
|
|
2944
|
+
}
|
|
2945
|
+
return attachTransparencyMetadata(streamResponse, transparency);
|
|
2862
2946
|
}
|
|
2863
|
-
const
|
|
2947
|
+
const modelStartedAt = Date.now();
|
|
2864
2948
|
const res = await originalCreate.apply(compTarget, createArgs);
|
|
2865
|
-
const
|
|
2949
|
+
const modelLatencyMs = Math.max(0, Date.now() - modelStartedAt);
|
|
2950
|
+
const totalPipelineLatencyMs = Math.max(0, Date.now() - pipelineStartedAt);
|
|
2866
2951
|
if (maskedText) {
|
|
2867
2952
|
const output = adapter.extractOutput(res);
|
|
2868
2953
|
const wrappedCompletion = this.wrapCompletion(output);
|
|
@@ -2877,7 +2962,7 @@ var AgentID = class {
|
|
|
2877
2962
|
output: outputForLog,
|
|
2878
2963
|
model,
|
|
2879
2964
|
usage,
|
|
2880
|
-
latency,
|
|
2965
|
+
latency: modelLatencyMs,
|
|
2881
2966
|
event_type: "complete",
|
|
2882
2967
|
metadata: {
|
|
2883
2968
|
transformed_input: maskedText,
|
|
@@ -2887,8 +2972,12 @@ var AgentID = class {
|
|
|
2887
2972
|
simulated_decision: verdict.simulated_decision ?? null,
|
|
2888
2973
|
simulated_output_decision: isShadowMode && wrappedCompletion.outputMasked ? "masked" : "allowed",
|
|
2889
2974
|
response_streamed: false,
|
|
2975
|
+
guard_latency_ms: guardLatencyMs,
|
|
2976
|
+
model_latency_ms: modelLatencyMs,
|
|
2977
|
+
total_pipeline_latency_ms: totalPipelineLatencyMs,
|
|
2890
2978
|
guard_event_id: guardEventId,
|
|
2891
|
-
client_event_id: canonicalClientEventId
|
|
2979
|
+
client_event_id: canonicalClientEventId,
|
|
2980
|
+
transparency
|
|
2892
2981
|
},
|
|
2893
2982
|
client_capabilities: this.buildClientCapabilities("openai", false)
|
|
2894
2983
|
}, requestOptions);
|
|
@@ -2915,7 +3004,7 @@ var AgentID = class {
|
|
|
2915
3004
|
} catch {
|
|
2916
3005
|
}
|
|
2917
3006
|
}
|
|
2918
|
-
return res;
|
|
3007
|
+
return attachTransparencyMetadata(res, transparency);
|
|
2919
3008
|
};
|
|
2920
3009
|
}
|
|
2921
3010
|
});
|
package/dist/index.d.mts
CHANGED
|
@@ -1,4 +1,6 @@
|
|
|
1
|
-
|
|
1
|
+
import { T as TransparencyMetadata } from './agentid-BGCUoYV7.mjs';
|
|
2
|
+
export { A as AgentID, G as GuardParams, a as GuardResponse, L as LogParams, P as PreparedInput, R as RequestOptions, S as SecurityBlockError } from './agentid-BGCUoYV7.mjs';
|
|
3
|
+
import * as react_jsx_runtime from 'react/jsx-runtime';
|
|
2
4
|
|
|
3
5
|
type PIIMapping = Record<string, string>;
|
|
4
6
|
declare class PIIManager {
|
|
@@ -52,4 +54,25 @@ declare class InjectionScanner {
|
|
|
52
54
|
}
|
|
53
55
|
declare function getInjectionScanner(): InjectionScanner;
|
|
54
56
|
|
|
55
|
-
|
|
57
|
+
type AgentIDTransparencyBadgeTelemetry = {
|
|
58
|
+
systemId: string;
|
|
59
|
+
apiKey?: string;
|
|
60
|
+
ingestUrl?: string;
|
|
61
|
+
baseUrl?: string;
|
|
62
|
+
userId?: string;
|
|
63
|
+
model?: string;
|
|
64
|
+
headers?: Record<string, string>;
|
|
65
|
+
metadata?: Record<string, unknown>;
|
|
66
|
+
onError?: (error: unknown) => void;
|
|
67
|
+
};
|
|
68
|
+
type AgentIDTransparencyBadgeProps = {
|
|
69
|
+
telemetry: AgentIDTransparencyBadgeTelemetry;
|
|
70
|
+
metadata?: TransparencyMetadata | null;
|
|
71
|
+
message?: string;
|
|
72
|
+
placement?: "chat-header" | "watermark-overlay";
|
|
73
|
+
fixed?: boolean;
|
|
74
|
+
className?: string;
|
|
75
|
+
};
|
|
76
|
+
declare function AgentIDTransparencyBadge(props: AgentIDTransparencyBadgeProps): react_jsx_runtime.JSX.Element;
|
|
77
|
+
|
|
78
|
+
export { AgentIDTransparencyBadge, type AgentIDTransparencyBadgeProps, type AgentIDTransparencyBadgeTelemetry, type InjectionScanParams, InjectionScanner, type LLMAdapter, OpenAIAdapter, PIIManager, type PIIMapping, type TokenUsage, TransparencyMetadata, getInjectionScanner, scanWithRegex };
|
package/dist/index.d.ts
CHANGED
|
@@ -1,4 +1,6 @@
|
|
|
1
|
-
|
|
1
|
+
import { T as TransparencyMetadata } from './agentid-BGCUoYV7.js';
|
|
2
|
+
export { A as AgentID, G as GuardParams, a as GuardResponse, L as LogParams, P as PreparedInput, R as RequestOptions, S as SecurityBlockError } from './agentid-BGCUoYV7.js';
|
|
3
|
+
import * as react_jsx_runtime from 'react/jsx-runtime';
|
|
2
4
|
|
|
3
5
|
type PIIMapping = Record<string, string>;
|
|
4
6
|
declare class PIIManager {
|
|
@@ -52,4 +54,25 @@ declare class InjectionScanner {
|
|
|
52
54
|
}
|
|
53
55
|
declare function getInjectionScanner(): InjectionScanner;
|
|
54
56
|
|
|
55
|
-
|
|
57
|
+
type AgentIDTransparencyBadgeTelemetry = {
|
|
58
|
+
systemId: string;
|
|
59
|
+
apiKey?: string;
|
|
60
|
+
ingestUrl?: string;
|
|
61
|
+
baseUrl?: string;
|
|
62
|
+
userId?: string;
|
|
63
|
+
model?: string;
|
|
64
|
+
headers?: Record<string, string>;
|
|
65
|
+
metadata?: Record<string, unknown>;
|
|
66
|
+
onError?: (error: unknown) => void;
|
|
67
|
+
};
|
|
68
|
+
type AgentIDTransparencyBadgeProps = {
|
|
69
|
+
telemetry: AgentIDTransparencyBadgeTelemetry;
|
|
70
|
+
metadata?: TransparencyMetadata | null;
|
|
71
|
+
message?: string;
|
|
72
|
+
placement?: "chat-header" | "watermark-overlay";
|
|
73
|
+
fixed?: boolean;
|
|
74
|
+
className?: string;
|
|
75
|
+
};
|
|
76
|
+
declare function AgentIDTransparencyBadge(props: AgentIDTransparencyBadgeProps): react_jsx_runtime.JSX.Element;
|
|
77
|
+
|
|
78
|
+
export { AgentIDTransparencyBadge, type AgentIDTransparencyBadgeProps, type AgentIDTransparencyBadgeTelemetry, type InjectionScanParams, InjectionScanner, type LLMAdapter, OpenAIAdapter, PIIManager, type PIIMapping, type TokenUsage, TransparencyMetadata, getInjectionScanner, scanWithRegex };
|