@driftgard/node 1.12.0-beta.1 → 1.13.0
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 +26 -0
- package/dist/index.js +3 -0
- package/dist/types.d.ts +2 -0
- package/dist/wasm/driftgard_evaluator_bg.wasm +0 -0
- package/package.json +2 -2
- package/dist/wasm/wasm/driftgard_evaluator.d.ts +0 -14
- package/dist/wasm/wasm/driftgard_evaluator.js +0 -127
- package/dist/wasm/wasm/driftgard_evaluator_bg.wasm +0 -0
package/README.md
CHANGED
|
@@ -161,6 +161,32 @@ const result = await dg.evaluate({
|
|
|
161
161
|
|
|
162
162
|
Agent identity fields are stored on the evaluation record and visible in the Live Activity detail dialog. The `on_behalf_of` field tracks which end-user triggered the agent action. The `parent_agent_id` field identifies which orchestrator agent delegated to this one in multi-agent systems.
|
|
163
163
|
|
|
164
|
+
## Jurisdiction-scoped rules
|
|
165
|
+
|
|
166
|
+
Control pack rules can be scoped to specific jurisdictions. Pass the user's jurisdiction in the evaluate request — only matching rules (plus global rules) will fire:
|
|
167
|
+
|
|
168
|
+
```typescript
|
|
169
|
+
const result = await dg.evaluate({
|
|
170
|
+
project_id: "your-project-id",
|
|
171
|
+
prompt: "What odds can I get?",
|
|
172
|
+
response: "Current odds for the Melbourne Cup are...",
|
|
173
|
+
model_id: "gpt-4o",
|
|
174
|
+
jurisdiction: "AU-VIC", // only VIC + global rules fire
|
|
175
|
+
});
|
|
176
|
+
```
|
|
177
|
+
|
|
178
|
+
Rules without a `jurisdictions` field are global — they fire for all requests regardless of jurisdiction. Rules with `jurisdictions: ["AU-VIC", "AU-NSW"]` only fire when the request's `jurisdiction` matches.
|
|
179
|
+
|
|
180
|
+
Supported jurisdiction codes include:
|
|
181
|
+
- Australia: `AU`, `AU-ACT`, `AU-NSW`, `AU-NT`, `AU-QLD`, `AU-SA`, `AU-TAS`, `AU-VIC`, `AU-WA`
|
|
182
|
+
- United States: `US`, `US-AL`, `US-AK`, `US-AZ`, `US-AR`, `US-CA`, `US-CO`, `US-CT`, `US-DE`, `US-FL`, `US-GA`, `US-HI`, `US-ID`, `US-IL`, `US-IN`, `US-IA`, `US-KS`, `US-KY`, `US-LA`, `US-ME`, `US-MD`, `US-MA`, `US-MI`, `US-MN`, `US-MS`, `US-MO`, `US-MT`, `US-NE`, `US-NV`, `US-NH`, `US-NJ`, `US-NM`, `US-NY`, `US-NC`, `US-ND`, `US-OH`, `US-OK`, `US-OR`, `US-PA`, `US-RI`, `US-SC`, `US-SD`, `US-TN`, `US-TX`, `US-UT`, `US-VT`, `US-VA`, `US-WA`, `US-WV`, `US-WI`, `US-WY`, `US-DC`
|
|
183
|
+
- United Kingdom: `GB`, `GB-ENG`, `GB-SCT`, `GB-WLS`, `GB-NIR`
|
|
184
|
+
- Europe: `EU`, `DE`, `FR`, `IE`, `NL`, `ES`, `IT`, `SE`
|
|
185
|
+
- Asia-Pacific: `NZ`, `SG`, `JP`, `IN`, `HK`
|
|
186
|
+
- Other: `CA`, `BR`, `ZA`, `AE`, `SA`
|
|
187
|
+
|
|
188
|
+
Custom codes are also supported — use any string your team agrees on.
|
|
189
|
+
|
|
164
190
|
### Per-tool identity rules
|
|
165
191
|
|
|
166
192
|
Control packs support `identity_rules` on each tool — restricting which agents, roles, users, or parent agents can call it. Rules use OR logic across entries and AND logic within each entry:
|
package/dist/index.js
CHANGED
|
@@ -101,6 +101,7 @@ class Driftgard {
|
|
|
101
101
|
...(req.agent_role ? { agent_role: req.agent_role } : {}),
|
|
102
102
|
...(req.on_behalf_of ? { on_behalf_of: req.on_behalf_of } : {}),
|
|
103
103
|
...(req.parent_agent_id ? { parent_agent_id: req.parent_agent_id } : {}),
|
|
104
|
+
...(req.jurisdiction ? { jurisdiction: req.jurisdiction } : {}),
|
|
104
105
|
};
|
|
105
106
|
const verdict = (0, local_evaluator_1.evaluateLocal)(cp, wasmRequest);
|
|
106
107
|
const response = {
|
|
@@ -149,6 +150,7 @@ class Driftgard {
|
|
|
149
150
|
session_id: req.session_id,
|
|
150
151
|
agent_id: req.agent_id,
|
|
151
152
|
agent_role: req.agent_role,
|
|
153
|
+
jurisdiction: req.jurisdiction,
|
|
152
154
|
stale_pack: meta.stale,
|
|
153
155
|
}).catch(() => { }); // fire-and-forget
|
|
154
156
|
}
|
|
@@ -197,6 +199,7 @@ class Driftgard {
|
|
|
197
199
|
...(req.on_behalf_of ? { on_behalf_of: req.on_behalf_of } : {}),
|
|
198
200
|
...(req.parent_agent_id ? { parent_agent_id: req.parent_agent_id } : {}),
|
|
199
201
|
...(req.usage ? { usage: req.usage } : {}),
|
|
202
|
+
...(req.jurisdiction ? { jurisdiction: req.jurisdiction } : {}),
|
|
200
203
|
}, idempotencyKey);
|
|
201
204
|
// Success — reset circuit breaker
|
|
202
205
|
this.cbFailures = 0;
|
package/dist/types.d.ts
CHANGED
|
@@ -61,6 +61,8 @@ export interface EvaluateRequest {
|
|
|
61
61
|
on_behalf_of?: string;
|
|
62
62
|
/** Parent agent ID — which orchestrator agent delegated to this one. */
|
|
63
63
|
parent_agent_id?: string;
|
|
64
|
+
/** User's jurisdiction for jurisdiction-scoped rules. e.g. "AU", "AU-VIC", "US-CA". */
|
|
65
|
+
jurisdiction?: string;
|
|
64
66
|
usage?: {
|
|
65
67
|
prompt_tokens?: number;
|
|
66
68
|
completion_tokens?: number;
|
|
Binary file
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@driftgard/node",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.13.0",
|
|
4
4
|
"description": "Official DriftGard Node.js SDK — evaluate LLM interactions against your compliance policy",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"types": "dist/index.d.ts",
|
|
@@ -9,7 +9,7 @@
|
|
|
9
9
|
"README.md"
|
|
10
10
|
],
|
|
11
11
|
"scripts": {
|
|
12
|
-
"build": "tsc && cp -r src/wasm dist/wasm",
|
|
12
|
+
"build": "tsc && rm -rf dist/wasm && cp -r src/wasm dist/wasm",
|
|
13
13
|
"prepublishOnly": "npm run build"
|
|
14
14
|
},
|
|
15
15
|
"keywords": [
|
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
/* tslint:disable */
|
|
2
|
-
/* eslint-disable */
|
|
3
|
-
|
|
4
|
-
/**
|
|
5
|
-
* Main evaluation entry point.
|
|
6
|
-
*
|
|
7
|
-
* # Arguments
|
|
8
|
-
* * `control_pack_json` - JSON string of the control pack
|
|
9
|
-
* * `request_json` - JSON string of the evaluation request
|
|
10
|
-
*
|
|
11
|
-
* # Returns
|
|
12
|
-
* JSON string of the verdict: { allowed, risk_score, violations, flags }
|
|
13
|
-
*/
|
|
14
|
-
export function evaluate(control_pack_json: string, request_json: string): string;
|
|
@@ -1,127 +0,0 @@
|
|
|
1
|
-
/* @ts-self-types="./driftgard_evaluator.d.ts" */
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* Main evaluation entry point.
|
|
5
|
-
*
|
|
6
|
-
* # Arguments
|
|
7
|
-
* * `control_pack_json` - JSON string of the control pack
|
|
8
|
-
* * `request_json` - JSON string of the evaluation request
|
|
9
|
-
*
|
|
10
|
-
* # Returns
|
|
11
|
-
* JSON string of the verdict: { allowed, risk_score, violations, flags }
|
|
12
|
-
* @param {string} control_pack_json
|
|
13
|
-
* @param {string} request_json
|
|
14
|
-
* @returns {string}
|
|
15
|
-
*/
|
|
16
|
-
function evaluate(control_pack_json, request_json) {
|
|
17
|
-
let deferred3_0;
|
|
18
|
-
let deferred3_1;
|
|
19
|
-
try {
|
|
20
|
-
const ptr0 = passStringToWasm0(control_pack_json, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
|
|
21
|
-
const len0 = WASM_VECTOR_LEN;
|
|
22
|
-
const ptr1 = passStringToWasm0(request_json, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
|
|
23
|
-
const len1 = WASM_VECTOR_LEN;
|
|
24
|
-
const ret = wasm.evaluate(ptr0, len0, ptr1, len1);
|
|
25
|
-
deferred3_0 = ret[0];
|
|
26
|
-
deferred3_1 = ret[1];
|
|
27
|
-
return getStringFromWasm0(ret[0], ret[1]);
|
|
28
|
-
} finally {
|
|
29
|
-
wasm.__wbindgen_free(deferred3_0, deferred3_1, 1);
|
|
30
|
-
}
|
|
31
|
-
}
|
|
32
|
-
exports.evaluate = evaluate;
|
|
33
|
-
function __wbg_get_imports() {
|
|
34
|
-
const import0 = {
|
|
35
|
-
__proto__: null,
|
|
36
|
-
__wbindgen_init_externref_table: function() {
|
|
37
|
-
const table = wasm.__wbindgen_externrefs;
|
|
38
|
-
const offset = table.grow(4);
|
|
39
|
-
table.set(0, undefined);
|
|
40
|
-
table.set(offset + 0, undefined);
|
|
41
|
-
table.set(offset + 1, null);
|
|
42
|
-
table.set(offset + 2, true);
|
|
43
|
-
table.set(offset + 3, false);
|
|
44
|
-
},
|
|
45
|
-
};
|
|
46
|
-
return {
|
|
47
|
-
__proto__: null,
|
|
48
|
-
"./driftgard_evaluator_bg.js": import0,
|
|
49
|
-
};
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
function getStringFromWasm0(ptr, len) {
|
|
53
|
-
return decodeText(ptr >>> 0, len);
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
let cachedUint8ArrayMemory0 = null;
|
|
57
|
-
function getUint8ArrayMemory0() {
|
|
58
|
-
if (cachedUint8ArrayMemory0 === null || cachedUint8ArrayMemory0.byteLength === 0) {
|
|
59
|
-
cachedUint8ArrayMemory0 = new Uint8Array(wasm.memory.buffer);
|
|
60
|
-
}
|
|
61
|
-
return cachedUint8ArrayMemory0;
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
function passStringToWasm0(arg, malloc, realloc) {
|
|
65
|
-
if (realloc === undefined) {
|
|
66
|
-
const buf = cachedTextEncoder.encode(arg);
|
|
67
|
-
const ptr = malloc(buf.length, 1) >>> 0;
|
|
68
|
-
getUint8ArrayMemory0().subarray(ptr, ptr + buf.length).set(buf);
|
|
69
|
-
WASM_VECTOR_LEN = buf.length;
|
|
70
|
-
return ptr;
|
|
71
|
-
}
|
|
72
|
-
|
|
73
|
-
let len = arg.length;
|
|
74
|
-
let ptr = malloc(len, 1) >>> 0;
|
|
75
|
-
|
|
76
|
-
const mem = getUint8ArrayMemory0();
|
|
77
|
-
|
|
78
|
-
let offset = 0;
|
|
79
|
-
|
|
80
|
-
for (; offset < len; offset++) {
|
|
81
|
-
const code = arg.charCodeAt(offset);
|
|
82
|
-
if (code > 0x7F) break;
|
|
83
|
-
mem[ptr + offset] = code;
|
|
84
|
-
}
|
|
85
|
-
if (offset !== len) {
|
|
86
|
-
if (offset !== 0) {
|
|
87
|
-
arg = arg.slice(offset);
|
|
88
|
-
}
|
|
89
|
-
ptr = realloc(ptr, len, len = offset + arg.length * 3, 1) >>> 0;
|
|
90
|
-
const view = getUint8ArrayMemory0().subarray(ptr + offset, ptr + len);
|
|
91
|
-
const ret = cachedTextEncoder.encodeInto(arg, view);
|
|
92
|
-
|
|
93
|
-
offset += ret.written;
|
|
94
|
-
ptr = realloc(ptr, len, offset, 1) >>> 0;
|
|
95
|
-
}
|
|
96
|
-
|
|
97
|
-
WASM_VECTOR_LEN = offset;
|
|
98
|
-
return ptr;
|
|
99
|
-
}
|
|
100
|
-
|
|
101
|
-
let cachedTextDecoder = new TextDecoder('utf-8', { ignoreBOM: true, fatal: true });
|
|
102
|
-
cachedTextDecoder.decode();
|
|
103
|
-
function decodeText(ptr, len) {
|
|
104
|
-
return cachedTextDecoder.decode(getUint8ArrayMemory0().subarray(ptr, ptr + len));
|
|
105
|
-
}
|
|
106
|
-
|
|
107
|
-
const cachedTextEncoder = new TextEncoder();
|
|
108
|
-
|
|
109
|
-
if (!('encodeInto' in cachedTextEncoder)) {
|
|
110
|
-
cachedTextEncoder.encodeInto = function (arg, view) {
|
|
111
|
-
const buf = cachedTextEncoder.encode(arg);
|
|
112
|
-
view.set(buf);
|
|
113
|
-
return {
|
|
114
|
-
read: arg.length,
|
|
115
|
-
written: buf.length
|
|
116
|
-
};
|
|
117
|
-
};
|
|
118
|
-
}
|
|
119
|
-
|
|
120
|
-
let WASM_VECTOR_LEN = 0;
|
|
121
|
-
|
|
122
|
-
const wasmPath = `${__dirname}/driftgard_evaluator_bg.wasm`;
|
|
123
|
-
const wasmBytes = require('fs').readFileSync(wasmPath);
|
|
124
|
-
const wasmModule = new WebAssembly.Module(wasmBytes);
|
|
125
|
-
let wasmInstance = new WebAssembly.Instance(wasmModule, __wbg_get_imports());
|
|
126
|
-
let wasm = wasmInstance.exports;
|
|
127
|
-
wasm.__wbindgen_start();
|
|
Binary file
|