agentid-sdk 0.1.18 → 0.1.20
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 +199 -38
- package/dist/chunk-LOZUJLLF.mjs +3222 -0
- package/dist/index.d.mts +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js +98 -29
- package/dist/index.mjs +10 -2724
- package/dist/{langchain-BykeB2WB.d.mts → langchain-BipmisU1.d.mts} +12 -3
- package/dist/{langchain-BykeB2WB.d.ts → langchain-BipmisU1.d.ts} +12 -3
- package/dist/langchain.d.mts +1 -1
- package/dist/langchain.d.ts +1 -1
- package/dist/langchain.js +190 -2
- package/dist/langchain.mjs +1 -1
- package/package.json +1 -1
- package/dist/chunk-6YR4ECGB.mjs +0 -424
|
@@ -2,6 +2,8 @@ import { BaseCallbackHandler } from '@langchain/core/callbacks/base';
|
|
|
2
2
|
|
|
3
3
|
type CapabilityConfig = {
|
|
4
4
|
shadow_mode: boolean;
|
|
5
|
+
strict_security_mode: boolean;
|
|
6
|
+
failure_mode: "fail_open" | "fail_close";
|
|
5
7
|
block_pii_leakage: boolean;
|
|
6
8
|
block_db_access: boolean;
|
|
7
9
|
block_code_execution: boolean;
|
|
@@ -58,7 +60,7 @@ interface LogParams {
|
|
|
58
60
|
};
|
|
59
61
|
}
|
|
60
62
|
type AgentIDConfig = {
|
|
61
|
-
apiKey
|
|
63
|
+
apiKey?: string;
|
|
62
64
|
baseUrl?: string;
|
|
63
65
|
piiMasking?: boolean;
|
|
64
66
|
checkInjection?: boolean;
|
|
@@ -66,12 +68,17 @@ type AgentIDConfig = {
|
|
|
66
68
|
storePii?: boolean;
|
|
67
69
|
strictMode?: boolean;
|
|
68
70
|
guardTimeoutMs?: number;
|
|
71
|
+
ingestTimeoutMs?: number;
|
|
69
72
|
};
|
|
70
73
|
|
|
71
74
|
type PreparedInput = {
|
|
72
75
|
sanitizedInput: string;
|
|
73
76
|
capabilityConfig: CapabilityConfig;
|
|
74
77
|
};
|
|
78
|
+
declare class SecurityBlockError extends Error {
|
|
79
|
+
reason: string;
|
|
80
|
+
constructor(reason?: string);
|
|
81
|
+
}
|
|
75
82
|
declare class AgentID {
|
|
76
83
|
private baseUrl;
|
|
77
84
|
private apiKey;
|
|
@@ -81,11 +88,12 @@ declare class AgentID {
|
|
|
81
88
|
private storePii;
|
|
82
89
|
private strictMode;
|
|
83
90
|
private guardTimeoutMs;
|
|
91
|
+
private ingestTimeoutMs;
|
|
84
92
|
private pii;
|
|
85
93
|
private localEnforcer;
|
|
86
94
|
private injectionScanner;
|
|
87
95
|
private recentGuardVerdicts;
|
|
88
|
-
constructor(config
|
|
96
|
+
constructor(config?: AgentIDConfig);
|
|
89
97
|
private buildClientCapabilities;
|
|
90
98
|
private resolveApiKey;
|
|
91
99
|
private resolveClientEventId;
|
|
@@ -94,6 +102,7 @@ declare class AgentID {
|
|
|
94
102
|
private cacheGuardVerdict;
|
|
95
103
|
getCapabilityConfig(force?: boolean, options?: RequestOptions): Promise<CapabilityConfig>;
|
|
96
104
|
private getCachedCapabilityConfig;
|
|
105
|
+
private resolveEffectiveStrictMode;
|
|
97
106
|
prepareInputForDispatch(params: {
|
|
98
107
|
input: string;
|
|
99
108
|
systemId: string;
|
|
@@ -167,4 +176,4 @@ declare class AgentIDCallbackHandler extends BaseCallbackHandler {
|
|
|
167
176
|
handleLLMError(err: unknown, runId?: string): Promise<void>;
|
|
168
177
|
}
|
|
169
178
|
|
|
170
|
-
export { AgentID as A, type GuardParams as G, type LogParams as L, type PreparedInput as P, type RequestOptions as R, AgentIDCallbackHandler as a, type GuardResponse as b };
|
|
179
|
+
export { AgentID as A, type GuardParams as G, type LogParams as L, type PreparedInput as P, type RequestOptions as R, SecurityBlockError as S, AgentIDCallbackHandler as a, type GuardResponse as b };
|
|
@@ -2,6 +2,8 @@ import { BaseCallbackHandler } from '@langchain/core/callbacks/base';
|
|
|
2
2
|
|
|
3
3
|
type CapabilityConfig = {
|
|
4
4
|
shadow_mode: boolean;
|
|
5
|
+
strict_security_mode: boolean;
|
|
6
|
+
failure_mode: "fail_open" | "fail_close";
|
|
5
7
|
block_pii_leakage: boolean;
|
|
6
8
|
block_db_access: boolean;
|
|
7
9
|
block_code_execution: boolean;
|
|
@@ -58,7 +60,7 @@ interface LogParams {
|
|
|
58
60
|
};
|
|
59
61
|
}
|
|
60
62
|
type AgentIDConfig = {
|
|
61
|
-
apiKey
|
|
63
|
+
apiKey?: string;
|
|
62
64
|
baseUrl?: string;
|
|
63
65
|
piiMasking?: boolean;
|
|
64
66
|
checkInjection?: boolean;
|
|
@@ -66,12 +68,17 @@ type AgentIDConfig = {
|
|
|
66
68
|
storePii?: boolean;
|
|
67
69
|
strictMode?: boolean;
|
|
68
70
|
guardTimeoutMs?: number;
|
|
71
|
+
ingestTimeoutMs?: number;
|
|
69
72
|
};
|
|
70
73
|
|
|
71
74
|
type PreparedInput = {
|
|
72
75
|
sanitizedInput: string;
|
|
73
76
|
capabilityConfig: CapabilityConfig;
|
|
74
77
|
};
|
|
78
|
+
declare class SecurityBlockError extends Error {
|
|
79
|
+
reason: string;
|
|
80
|
+
constructor(reason?: string);
|
|
81
|
+
}
|
|
75
82
|
declare class AgentID {
|
|
76
83
|
private baseUrl;
|
|
77
84
|
private apiKey;
|
|
@@ -81,11 +88,12 @@ declare class AgentID {
|
|
|
81
88
|
private storePii;
|
|
82
89
|
private strictMode;
|
|
83
90
|
private guardTimeoutMs;
|
|
91
|
+
private ingestTimeoutMs;
|
|
84
92
|
private pii;
|
|
85
93
|
private localEnforcer;
|
|
86
94
|
private injectionScanner;
|
|
87
95
|
private recentGuardVerdicts;
|
|
88
|
-
constructor(config
|
|
96
|
+
constructor(config?: AgentIDConfig);
|
|
89
97
|
private buildClientCapabilities;
|
|
90
98
|
private resolveApiKey;
|
|
91
99
|
private resolveClientEventId;
|
|
@@ -94,6 +102,7 @@ declare class AgentID {
|
|
|
94
102
|
private cacheGuardVerdict;
|
|
95
103
|
getCapabilityConfig(force?: boolean, options?: RequestOptions): Promise<CapabilityConfig>;
|
|
96
104
|
private getCachedCapabilityConfig;
|
|
105
|
+
private resolveEffectiveStrictMode;
|
|
97
106
|
prepareInputForDispatch(params: {
|
|
98
107
|
input: string;
|
|
99
108
|
systemId: string;
|
|
@@ -167,4 +176,4 @@ declare class AgentIDCallbackHandler extends BaseCallbackHandler {
|
|
|
167
176
|
handleLLMError(err: unknown, runId?: string): Promise<void>;
|
|
168
177
|
}
|
|
169
178
|
|
|
170
|
-
export { AgentID as A, type GuardParams as G, type LogParams as L, type PreparedInput as P, type RequestOptions as R, AgentIDCallbackHandler as a, type GuardResponse as b };
|
|
179
|
+
export { AgentID as A, type GuardParams as G, type LogParams as L, type PreparedInput as P, type RequestOptions as R, SecurityBlockError as S, AgentIDCallbackHandler as a, type GuardResponse as b };
|
package/dist/langchain.d.mts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
import '@langchain/core/callbacks/base';
|
|
2
|
-
export { a as AgentIDCallbackHandler } from './langchain-
|
|
2
|
+
export { a as AgentIDCallbackHandler } from './langchain-BipmisU1.mjs';
|
package/dist/langchain.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
import '@langchain/core/callbacks/base';
|
|
2
|
-
export { a as AgentIDCallbackHandler } from './langchain-
|
|
2
|
+
export { a as AgentIDCallbackHandler } from './langchain-BipmisU1.js';
|
package/dist/langchain.js
CHANGED
|
@@ -24,6 +24,194 @@ __export(langchain_exports, {
|
|
|
24
24
|
});
|
|
25
25
|
module.exports = __toCommonJS(langchain_exports);
|
|
26
26
|
var import_base = require("@langchain/core/callbacks/base");
|
|
27
|
+
|
|
28
|
+
// src/sdk-version.ts
|
|
29
|
+
var FALLBACK_SDK_VERSION = "js-0.0.0-dev";
|
|
30
|
+
var AGENTID_SDK_VERSION_HEADER = "js-0.1.20".trim().length > 0 ? "js-0.1.20" : FALLBACK_SDK_VERSION;
|
|
31
|
+
|
|
32
|
+
// src/pii-national-identifiers.ts
|
|
33
|
+
var REGION_ANCHORS = {
|
|
34
|
+
czsk: ["rodne cislo", "rc", "cislo", "birth number", "personal number"],
|
|
35
|
+
pl: ["pesel", "nip", "dowod", "poland"],
|
|
36
|
+
ro: ["cnp", "romania"],
|
|
37
|
+
de: ["steuer id", "steuer-id", "steueridentifikationsnummer", "ust-idnr", "deutschland"],
|
|
38
|
+
hu: ["taj", "szemelyi", "hungary"],
|
|
39
|
+
gb: ["nino", "national insurance", "gb", "great britain", "driving licence", "driver licence"],
|
|
40
|
+
fr: ["insee", "nir", "securite sociale", "france"],
|
|
41
|
+
es: ["dni", "nie", "nif", "cif", "espana", "spain"],
|
|
42
|
+
it: ["codice fiscale", "fiscal code", "italia", "italy"],
|
|
43
|
+
nl: ["bsn", "burgerservicenummer", "nederland", "netherlands"],
|
|
44
|
+
at: ["svnr", "sozialversicherung", "sozialversicherungsnummer", "austria", "oesterreich"]
|
|
45
|
+
};
|
|
46
|
+
var TAX_ANCHORS = [
|
|
47
|
+
"vat",
|
|
48
|
+
"vat number",
|
|
49
|
+
"tax",
|
|
50
|
+
"tax id",
|
|
51
|
+
"tin",
|
|
52
|
+
"dic",
|
|
53
|
+
"nip",
|
|
54
|
+
"nino",
|
|
55
|
+
"steuernummer",
|
|
56
|
+
"steuer id",
|
|
57
|
+
"steuer-id",
|
|
58
|
+
"ust-idnr",
|
|
59
|
+
"insee",
|
|
60
|
+
"nir",
|
|
61
|
+
"dni",
|
|
62
|
+
"nie",
|
|
63
|
+
"nif",
|
|
64
|
+
"cif",
|
|
65
|
+
"codice fiscale",
|
|
66
|
+
"fiscal code",
|
|
67
|
+
"bsn",
|
|
68
|
+
"burgerservicenummer",
|
|
69
|
+
"svnr",
|
|
70
|
+
"sozialversicherung",
|
|
71
|
+
"sozialversicherungsnummer",
|
|
72
|
+
"fiscal"
|
|
73
|
+
];
|
|
74
|
+
var NL_BSN_ANCHORS = ["bsn", "burgerservicenummer"];
|
|
75
|
+
var AT_SVNR_ANCHORS = ["svnr", "sozialversicherung", "sozialversicherungsnummer", "ssn"];
|
|
76
|
+
var DRIVER_ANCHORS = [
|
|
77
|
+
"driver licence",
|
|
78
|
+
"driving licence",
|
|
79
|
+
"drivers license",
|
|
80
|
+
"driving license",
|
|
81
|
+
"ridicsky prukaz",
|
|
82
|
+
"vodicsky preukaz",
|
|
83
|
+
"prawo jazdy",
|
|
84
|
+
"fuhrerschein",
|
|
85
|
+
"fuehrerschein",
|
|
86
|
+
"permis",
|
|
87
|
+
"driving permit"
|
|
88
|
+
];
|
|
89
|
+
var ADDRESS_ANCHORS = [
|
|
90
|
+
"street",
|
|
91
|
+
"st.",
|
|
92
|
+
"strasse",
|
|
93
|
+
"str.",
|
|
94
|
+
"ulice",
|
|
95
|
+
"ul.",
|
|
96
|
+
"ulica",
|
|
97
|
+
"road",
|
|
98
|
+
"rd.",
|
|
99
|
+
"avenue",
|
|
100
|
+
"ave.",
|
|
101
|
+
"postcode",
|
|
102
|
+
"postal code",
|
|
103
|
+
"zip",
|
|
104
|
+
"psc",
|
|
105
|
+
"plz"
|
|
106
|
+
];
|
|
107
|
+
var MRZ_ANCHORS = ["mrz", "machine readable zone", "passport", "id card", "travel document"];
|
|
108
|
+
var ALL_ANCHORS = dedupeAnchors([
|
|
109
|
+
...TAX_ANCHORS,
|
|
110
|
+
...DRIVER_ANCHORS,
|
|
111
|
+
...ADDRESS_ANCHORS,
|
|
112
|
+
...MRZ_ANCHORS,
|
|
113
|
+
...REGION_ANCHORS.czsk,
|
|
114
|
+
...REGION_ANCHORS.pl,
|
|
115
|
+
...REGION_ANCHORS.ro,
|
|
116
|
+
...REGION_ANCHORS.de,
|
|
117
|
+
...REGION_ANCHORS.hu,
|
|
118
|
+
...REGION_ANCHORS.gb,
|
|
119
|
+
...REGION_ANCHORS.fr,
|
|
120
|
+
...REGION_ANCHORS.es,
|
|
121
|
+
...REGION_ANCHORS.it,
|
|
122
|
+
...REGION_ANCHORS.nl,
|
|
123
|
+
...REGION_ANCHORS.at
|
|
124
|
+
]);
|
|
125
|
+
var TAX_ANCHOR_SET = new Set(TAX_ANCHORS.map(normalizeAnchorWord));
|
|
126
|
+
var DRIVER_ANCHOR_SET = new Set(DRIVER_ANCHORS.map(normalizeAnchorWord));
|
|
127
|
+
var ADDRESS_ANCHOR_SET = new Set(ADDRESS_ANCHORS.map(normalizeAnchorWord));
|
|
128
|
+
var MRZ_ANCHOR_SET = new Set(MRZ_ANCHORS.map(normalizeAnchorWord));
|
|
129
|
+
var NL_BSN_ANCHOR_SET = new Set(NL_BSN_ANCHORS.map(normalizeAnchorWord));
|
|
130
|
+
var AT_SVNR_ANCHOR_SET = new Set(AT_SVNR_ANCHORS.map(normalizeAnchorWord));
|
|
131
|
+
var anchorTrie = buildTrie(ALL_ANCHORS);
|
|
132
|
+
function dedupeAnchors(anchors) {
|
|
133
|
+
const unique = /* @__PURE__ */ new Set();
|
|
134
|
+
for (const anchor of anchors) {
|
|
135
|
+
const normalized = normalizeAnchorWord(anchor);
|
|
136
|
+
if (normalized.length > 0) unique.add(normalized);
|
|
137
|
+
}
|
|
138
|
+
return Array.from(unique);
|
|
139
|
+
}
|
|
140
|
+
function foldForMatching(value) {
|
|
141
|
+
return value.toLowerCase().normalize("NFD").replace(/\p{M}+/gu, "");
|
|
142
|
+
}
|
|
143
|
+
function normalizeAnchorWord(value) {
|
|
144
|
+
return foldForMatching(value).trim().replace(/\s+/g, " ");
|
|
145
|
+
}
|
|
146
|
+
function createTrieNode() {
|
|
147
|
+
return { children: /* @__PURE__ */ new Map(), terminalWords: [] };
|
|
148
|
+
}
|
|
149
|
+
function buildTrie(words) {
|
|
150
|
+
const root = createTrieNode();
|
|
151
|
+
for (const word of words) {
|
|
152
|
+
let node = root;
|
|
153
|
+
for (const char of word) {
|
|
154
|
+
const next = node.children.get(char);
|
|
155
|
+
if (next) {
|
|
156
|
+
node = next;
|
|
157
|
+
} else {
|
|
158
|
+
const created = createTrieNode();
|
|
159
|
+
node.children.set(char, created);
|
|
160
|
+
node = created;
|
|
161
|
+
}
|
|
162
|
+
}
|
|
163
|
+
node.terminalWords.push(word);
|
|
164
|
+
}
|
|
165
|
+
return root;
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
// src/pii.ts
|
|
169
|
+
var PHONE_CONTEXT_KEYWORDS = [
|
|
170
|
+
"tel",
|
|
171
|
+
"phone",
|
|
172
|
+
"mobile",
|
|
173
|
+
"cell",
|
|
174
|
+
"call",
|
|
175
|
+
"contact",
|
|
176
|
+
"number",
|
|
177
|
+
"hotline",
|
|
178
|
+
"support",
|
|
179
|
+
"infoline",
|
|
180
|
+
"customer service",
|
|
181
|
+
"client service",
|
|
182
|
+
"telefon",
|
|
183
|
+
"telefonu",
|
|
184
|
+
"telefonszam",
|
|
185
|
+
"telefonnummer",
|
|
186
|
+
"rufnummer",
|
|
187
|
+
"zadzwon",
|
|
188
|
+
"hivas",
|
|
189
|
+
"wsparcie",
|
|
190
|
+
"podpora",
|
|
191
|
+
"kontakt",
|
|
192
|
+
"dial"
|
|
193
|
+
];
|
|
194
|
+
function escapeRegex(value) {
|
|
195
|
+
return value.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
|
|
196
|
+
}
|
|
197
|
+
var PHONE_CONTEXT_RE = new RegExp(
|
|
198
|
+
`(?:^|[^\\p{L}])(?:${PHONE_CONTEXT_KEYWORDS.map(escapeRegex).join("|")})(?:$|[^\\p{L}])`,
|
|
199
|
+
"iu"
|
|
200
|
+
);
|
|
201
|
+
|
|
202
|
+
// src/capability-config.ts
|
|
203
|
+
var CONFIG_TTL_MS = 5 * 60 * 1e3;
|
|
204
|
+
|
|
205
|
+
// src/agentid.ts
|
|
206
|
+
var SecurityBlockError = class extends Error {
|
|
207
|
+
constructor(reason = "guard_denied") {
|
|
208
|
+
super(`AgentID: Security Blocked (${reason})`);
|
|
209
|
+
this.name = "SecurityBlockError";
|
|
210
|
+
this.reason = reason;
|
|
211
|
+
}
|
|
212
|
+
};
|
|
213
|
+
|
|
214
|
+
// src/langchain.ts
|
|
27
215
|
function safeString(val) {
|
|
28
216
|
return typeof val === "string" ? val : "";
|
|
29
217
|
}
|
|
@@ -303,7 +491,7 @@ var AgentIDCallbackHandler = class extends import_base.BaseCallbackHandler {
|
|
|
303
491
|
client_capabilities: this.getLangchainCapabilities()
|
|
304
492
|
}, this.requestOptions);
|
|
305
493
|
if (!verdict.allowed) {
|
|
306
|
-
throw new
|
|
494
|
+
throw new SecurityBlockError(verdict.reason ?? "guard_denied");
|
|
307
495
|
}
|
|
308
496
|
const canonicalClientEventId = isUuidLike(verdict.client_event_id) ? verdict.client_event_id.trim() : requestedClientEventId;
|
|
309
497
|
const guardEventId = typeof verdict.guard_event_id === "string" && verdict.guard_event_id.length > 0 ? verdict.guard_event_id : void 0;
|
|
@@ -354,7 +542,7 @@ var AgentIDCallbackHandler = class extends import_base.BaseCallbackHandler {
|
|
|
354
542
|
client_capabilities: this.getLangchainCapabilities()
|
|
355
543
|
}, this.requestOptions);
|
|
356
544
|
if (!verdict.allowed) {
|
|
357
|
-
throw new
|
|
545
|
+
throw new SecurityBlockError(verdict.reason ?? "guard_denied");
|
|
358
546
|
}
|
|
359
547
|
const canonicalClientEventId = isUuidLike(verdict.client_event_id) ? verdict.client_event_id.trim() : requestedClientEventId;
|
|
360
548
|
const guardEventId = typeof verdict.guard_event_id === "string" && verdict.guard_event_id.length > 0 ? verdict.guard_event_id : void 0;
|
package/dist/langchain.mjs
CHANGED