@driftgard/node 1.8.0 → 1.10.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 +19 -5
- package/dist/index.d.ts +1 -1
- package/dist/index.js +2 -2
- package/dist/types.d.ts +1 -1
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# @driftgard/node
|
|
2
2
|
|
|
3
|
-
Official Node.js SDK for [
|
|
3
|
+
Official Node.js SDK for [DriftGard](https://driftgard.com) — evaluate LLM interactions against your compliance policy.
|
|
4
4
|
|
|
5
5
|
## Install
|
|
6
6
|
|
|
@@ -51,7 +51,7 @@ const result = await dg.evaluate({
|
|
|
51
51
|
});
|
|
52
52
|
```
|
|
53
53
|
|
|
54
|
-
This enables chain depth protection (prevents infinite agent loops) and lets you trace evaluation lineage in the dashboard. When `sequence_no` is provided,
|
|
54
|
+
This enables chain depth protection (prevents infinite agent loops) and lets you trace evaluation lineage in the dashboard. When `sequence_no` is provided, DriftGard enforces ordering — if an eval arrives out of order, the response includes a `sequence_warning`.
|
|
55
55
|
|
|
56
56
|
## A/B experiments
|
|
57
57
|
|
|
@@ -67,7 +67,7 @@ const result = await dg.evaluate({
|
|
|
67
67
|
});
|
|
68
68
|
```
|
|
69
69
|
|
|
70
|
-
View experiment results on the Experiments page in the
|
|
70
|
+
View experiment results on the Experiments page in the DriftGard dashboard.
|
|
71
71
|
|
|
72
72
|
## Cost attribution
|
|
73
73
|
|
|
@@ -136,6 +136,20 @@ await dg.reportOutcome(result.evaluation_id, "your-project-id", {
|
|
|
136
136
|
|
|
137
137
|
For Strands agents, use the `BeforeToolCallEvent` hook — see the integration guide.
|
|
138
138
|
|
|
139
|
+
### Custom expressions
|
|
140
|
+
|
|
141
|
+
Parameter rules support `custom_fn` for advanced validation. The expression is evaluated safely (no `eval`) with access to `value` (current param) and `params` (all params):
|
|
142
|
+
|
|
143
|
+
```json
|
|
144
|
+
{
|
|
145
|
+
"amount": { "type": "number", "custom_fn": "value > 0 && value <= 10000" },
|
|
146
|
+
"to_account": { "type": "string", "custom_fn": "value !== params.from_account" },
|
|
147
|
+
"message": { "type": "string", "custom_fn": "value.length <= 500" }
|
|
148
|
+
}
|
|
149
|
+
```
|
|
150
|
+
|
|
151
|
+
Supported: comparisons (`< > <= >= === !==`), logical (`&& || !`), arithmetic (`+ - * /`), string methods (`.length`, `.includes()`, `.startsWith()`, `.endsWith()`), and cross-parameter access via `params.field_name`.
|
|
152
|
+
|
|
139
153
|
## Features
|
|
140
154
|
|
|
141
155
|
- Single `evaluate()` method — send prompt/response, get verdict
|
|
@@ -182,7 +196,7 @@ console.log(dg.circuitBreakerState);
|
|
|
182
196
|
// { state: "closed", failures: 0, openedAt: 0 }
|
|
183
197
|
```
|
|
184
198
|
|
|
185
|
-
With `failureMode: "open"` (default), the SDK allows requests through when
|
|
199
|
+
With `failureMode: "open"` (default), the SDK allows requests through when DriftGard is unavailable. With `failureMode: "closed"`, it blocks them with a fallback message.
|
|
186
200
|
|
|
187
201
|
## Error handling
|
|
188
202
|
|
|
@@ -208,7 +222,7 @@ try {
|
|
|
208
222
|
## Requirements
|
|
209
223
|
|
|
210
224
|
- Node.js 18+ (uses native `fetch`)
|
|
211
|
-
- API key from
|
|
225
|
+
- API key from DriftGard (Settings → API Keys)
|
|
212
226
|
- Compliance or Enterprise tier for API evaluation
|
|
213
227
|
|
|
214
228
|
## License
|
package/dist/index.d.ts
CHANGED
|
@@ -31,7 +31,7 @@ export declare class Driftgard {
|
|
|
31
31
|
*/
|
|
32
32
|
reportOutcome(evaluationId: string, projectId: string, outcome: OutcomeRequest): Promise<any>;
|
|
33
33
|
/**
|
|
34
|
-
* Wrap a tool function with
|
|
34
|
+
* Wrap a tool function with DriftGard policy check.
|
|
35
35
|
* Returns a guarded version that evaluates before executing.
|
|
36
36
|
*/
|
|
37
37
|
guard<T extends (...args: any[]) => any>(toolFn: T, toolName: string, projectId: string, opts?: {
|
package/dist/index.js
CHANGED
|
@@ -105,7 +105,7 @@ class Driftgard {
|
|
|
105
105
|
clause_id: "DRIFTGARD_UNAVAILABLE",
|
|
106
106
|
severity: "critical",
|
|
107
107
|
category: "system",
|
|
108
|
-
reason: `
|
|
108
|
+
reason: `DriftGard API unavailable — fail-closed policy applied (${source})`,
|
|
109
109
|
}],
|
|
110
110
|
},
|
|
111
111
|
...(allowed ? {} : {
|
|
@@ -147,7 +147,7 @@ class Driftgard {
|
|
|
147
147
|
});
|
|
148
148
|
}
|
|
149
149
|
/**
|
|
150
|
-
* Wrap a tool function with
|
|
150
|
+
* Wrap a tool function with DriftGard policy check.
|
|
151
151
|
* Returns a guarded version that evaluates before executing.
|
|
152
152
|
*/
|
|
153
153
|
guard(toolFn, toolName, projectId, opts) {
|
package/dist/types.d.ts
CHANGED
|
@@ -9,7 +9,7 @@ export interface DriftgardConfig {
|
|
|
9
9
|
baseUrl?: string;
|
|
10
10
|
timeout?: number;
|
|
11
11
|
maxRetries?: number;
|
|
12
|
-
/** What to do when
|
|
12
|
+
/** What to do when DriftGard API is unreachable. "open" = allow, "closed" = block. Default "open". */
|
|
13
13
|
failureMode?: "open" | "closed";
|
|
14
14
|
/** Circuit breaker config. Skips API calls after consecutive failures. */
|
|
15
15
|
circuitBreaker?: CircuitBreakerConfig;
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@driftgard/node",
|
|
3
|
-
"version": "1.
|
|
4
|
-
"description": "Official
|
|
3
|
+
"version": "1.10.0",
|
|
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",
|
|
7
7
|
"files": ["dist", "README.md"],
|