@driftgard/node 1.7.0 → 1.9.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 CHANGED
@@ -47,10 +47,11 @@ const result = await dg.evaluate({
47
47
  model_id: "gpt-4o",
48
48
  session_id: "sess_abc123", // groups evals in a conversation
49
49
  parent_evaluation_id: "eval_prev_id", // chains to the previous eval
50
+ sequence_no: 1, // optional — enforces ordering within session
50
51
  });
51
52
  ```
52
53
 
53
- This enables chain depth protection (prevents infinite agent loops) and lets you trace evaluation lineage in the dashboard.
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`.
54
55
 
55
56
  ## A/B experiments
56
57
 
@@ -135,6 +136,20 @@ await dg.reportOutcome(result.evaluation_id, "your-project-id", {
135
136
 
136
137
  For Strands agents, use the `BeforeToolCallEvent` hook — see the integration guide.
137
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
+
138
153
  ## Features
139
154
 
140
155
  - Single `evaluate()` method — send prompt/response, get verdict
package/dist/index.js CHANGED
@@ -60,6 +60,7 @@ class Driftgard {
60
60
  ...(req.dry_run ? { dry_run: req.dry_run } : {}),
61
61
  ...(req.eval_mode ? { eval_mode: req.eval_mode } : {}),
62
62
  ...(req.tool_call ? { tool_call: req.tool_call } : {}),
63
+ ...(req.sequence_no != null ? { sequence_no: req.sequence_no } : {}),
63
64
  ...(req.usage ? { usage: req.usage } : {}),
64
65
  }, idempotencyKey);
65
66
  // Success — reset circuit breaker
@@ -133,6 +134,7 @@ class Driftgard {
133
134
  session_id: req.session_id,
134
135
  parent_evaluation_id: req.parent_evaluation_id,
135
136
  idempotency_key: req.idempotency_key,
137
+ sequence_no: req.sequence_no,
136
138
  });
137
139
  }
138
140
  /**
package/dist/types.d.ts CHANGED
@@ -33,6 +33,8 @@ export interface EvaluateRequest {
33
33
  };
34
34
  /** Caller-provided idempotency key. If omitted, the SDK generates one. */
35
35
  idempotency_key?: string;
36
+ /** Sequence number within a session for ordering. Optional — if sent, ordering is enforced. */
37
+ sequence_no?: number;
36
38
  usage?: {
37
39
  prompt_tokens?: number;
38
40
  completion_tokens?: number;
@@ -122,6 +124,13 @@ export interface EvaluateResponse {
122
124
  tool_name: string;
123
125
  parameters?: Record<string, any>;
124
126
  };
127
+ sequence_no?: number;
128
+ sequence_warning?: {
129
+ message: string;
130
+ expected_next: number;
131
+ received: number;
132
+ max_seen: number;
133
+ };
125
134
  }
126
135
  export interface ToolCallRequest {
127
136
  project_id: string;
@@ -131,6 +140,7 @@ export interface ToolCallRequest {
131
140
  session_id?: string;
132
141
  parent_evaluation_id?: string;
133
142
  idempotency_key?: string;
143
+ sequence_no?: number;
134
144
  }
135
145
  export interface OutcomeRequest {
136
146
  execution_status: "success" | "failed" | "rolled_back";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@driftgard/node",
3
- "version": "1.7.0",
3
+ "version": "1.9.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",