@highflame/policy 2.1.24 → 2.1.25
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/_schemas/ai_gateway/schema.cedarschema +70 -0
- package/_schemas/guardrails/schema.cedarschema +75 -3
- package/_schemas/mcp_gateway/schema.cedarschema +70 -0
- package/dist/engine.d.ts +37 -0
- package/dist/engine.js +56 -0
- package/dist/service-schemas.gen.d.ts +2 -2
- package/dist/service-schemas.gen.js +145 -3
- package/package.json +1 -1
|
@@ -137,6 +137,20 @@ action call_tool appliesTo {
|
|
|
137
137
|
suspicious_pattern?: Bool,
|
|
138
138
|
pattern_type?: String,
|
|
139
139
|
sequence_risk?: Long,
|
|
140
|
+
|
|
141
|
+
// --- Usage Budget (multi-window, multi-dimension) ---
|
|
142
|
+
budget_remaining_pct?: Long,
|
|
143
|
+
budget_exceeded?: Bool,
|
|
144
|
+
budget_cost_micros_this_turn?: Long,
|
|
145
|
+
budget_model?: String,
|
|
146
|
+
budget_tokens_pct_session?: Long,
|
|
147
|
+
budget_tokens_pct_daily?: Long,
|
|
148
|
+
budget_tokens_pct_monthly?: Long,
|
|
149
|
+
budget_cost_pct_daily?: Long,
|
|
150
|
+
budget_cost_pct_monthly?: Long,
|
|
151
|
+
budget_exceeded_session?: Bool,
|
|
152
|
+
budget_exceeded_daily?: Bool,
|
|
153
|
+
budget_exceeded_monthly?: Bool,
|
|
140
154
|
},
|
|
141
155
|
};
|
|
142
156
|
|
|
@@ -176,6 +190,20 @@ action connect_server appliesTo {
|
|
|
176
190
|
mcp_server_verified?: Bool,
|
|
177
191
|
mcp_config_risk?: Bool,
|
|
178
192
|
mcp_risk_score?: Long,
|
|
193
|
+
|
|
194
|
+
// --- Usage Budget (multi-window, multi-dimension) ---
|
|
195
|
+
budget_remaining_pct?: Long,
|
|
196
|
+
budget_exceeded?: Bool,
|
|
197
|
+
budget_cost_micros_this_turn?: Long,
|
|
198
|
+
budget_model?: String,
|
|
199
|
+
budget_tokens_pct_session?: Long,
|
|
200
|
+
budget_tokens_pct_daily?: Long,
|
|
201
|
+
budget_tokens_pct_monthly?: Long,
|
|
202
|
+
budget_cost_pct_daily?: Long,
|
|
203
|
+
budget_cost_pct_monthly?: Long,
|
|
204
|
+
budget_exceeded_session?: Bool,
|
|
205
|
+
budget_exceeded_daily?: Bool,
|
|
206
|
+
budget_exceeded_monthly?: Bool,
|
|
179
207
|
},
|
|
180
208
|
};
|
|
181
209
|
|
|
@@ -224,6 +252,20 @@ action process_prompt appliesTo {
|
|
|
224
252
|
// --- LLM-specific ---
|
|
225
253
|
model_name?: String, // Target model name (e.g., "gpt-4", "claude-3-opus")
|
|
226
254
|
model_provider?: String, // Provider name (e.g., "openai", "anthropic", "bedrock")
|
|
255
|
+
|
|
256
|
+
// --- Usage Budget (multi-window, multi-dimension) ---
|
|
257
|
+
budget_remaining_pct?: Long,
|
|
258
|
+
budget_exceeded?: Bool,
|
|
259
|
+
budget_cost_micros_this_turn?: Long,
|
|
260
|
+
budget_model?: String,
|
|
261
|
+
budget_tokens_pct_session?: Long,
|
|
262
|
+
budget_tokens_pct_daily?: Long,
|
|
263
|
+
budget_tokens_pct_monthly?: Long,
|
|
264
|
+
budget_cost_pct_daily?: Long,
|
|
265
|
+
budget_cost_pct_monthly?: Long,
|
|
266
|
+
budget_exceeded_session?: Bool,
|
|
267
|
+
budget_exceeded_daily?: Bool,
|
|
268
|
+
budget_exceeded_monthly?: Bool,
|
|
227
269
|
},
|
|
228
270
|
};
|
|
229
271
|
|
|
@@ -252,6 +294,20 @@ action read_file appliesTo {
|
|
|
252
294
|
pii_detected?: Bool,
|
|
253
295
|
pii_types?: Set<String>,
|
|
254
296
|
pii_count?: Long,
|
|
297
|
+
|
|
298
|
+
// --- Usage Budget (multi-window, multi-dimension) ---
|
|
299
|
+
budget_remaining_pct?: Long,
|
|
300
|
+
budget_exceeded?: Bool,
|
|
301
|
+
budget_cost_micros_this_turn?: Long,
|
|
302
|
+
budget_model?: String,
|
|
303
|
+
budget_tokens_pct_session?: Long,
|
|
304
|
+
budget_tokens_pct_daily?: Long,
|
|
305
|
+
budget_tokens_pct_monthly?: Long,
|
|
306
|
+
budget_cost_pct_daily?: Long,
|
|
307
|
+
budget_cost_pct_monthly?: Long,
|
|
308
|
+
budget_exceeded_session?: Bool,
|
|
309
|
+
budget_exceeded_daily?: Bool,
|
|
310
|
+
budget_exceeded_monthly?: Bool,
|
|
255
311
|
},
|
|
256
312
|
};
|
|
257
313
|
|
|
@@ -280,6 +336,20 @@ action write_file appliesTo {
|
|
|
280
336
|
pii_detected?: Bool,
|
|
281
337
|
pii_types?: Set<String>,
|
|
282
338
|
pii_count?: Long,
|
|
339
|
+
|
|
340
|
+
// --- Usage Budget (multi-window, multi-dimension) ---
|
|
341
|
+
budget_remaining_pct?: Long,
|
|
342
|
+
budget_exceeded?: Bool,
|
|
343
|
+
budget_cost_micros_this_turn?: Long,
|
|
344
|
+
budget_model?: String,
|
|
345
|
+
budget_tokens_pct_session?: Long,
|
|
346
|
+
budget_tokens_pct_daily?: Long,
|
|
347
|
+
budget_tokens_pct_monthly?: Long,
|
|
348
|
+
budget_cost_pct_daily?: Long,
|
|
349
|
+
budget_cost_pct_monthly?: Long,
|
|
350
|
+
budget_exceeded_session?: Bool,
|
|
351
|
+
budget_exceeded_daily?: Bool,
|
|
352
|
+
budget_exceeded_monthly?: Bool,
|
|
283
353
|
},
|
|
284
354
|
};
|
|
285
355
|
|
|
@@ -206,6 +206,22 @@ namespace Guardrails {
|
|
|
206
206
|
"session_max_secret_score"?: Long,
|
|
207
207
|
"session_cumulative_risk_score"?: Long,
|
|
208
208
|
|
|
209
|
+
// Usage Budget — multi-window token & cost enforcement (optional)
|
|
210
|
+
// Emitted by usage_budget detector. Enforced across session/daily/monthly windows
|
|
211
|
+
// and user/app/project/account dimensions. Percentages are 0-100.
|
|
212
|
+
"budget_remaining_pct"?: Long, // Min remaining % across all windows
|
|
213
|
+
"budget_exceeded"?: Bool, // Any window limit exceeded
|
|
214
|
+
"budget_cost_micros_this_turn"?: Long, // Cost of this request in microdollars (USD * 1e6)
|
|
215
|
+
"budget_model"?: String, // Model name used for cost calculation
|
|
216
|
+
"budget_tokens_pct_session"?: Long, // Session token usage % (0-100)
|
|
217
|
+
"budget_tokens_pct_daily"?: Long, // Daily token usage % (0-100)
|
|
218
|
+
"budget_tokens_pct_monthly"?: Long, // Monthly token usage % (0-100)
|
|
219
|
+
"budget_cost_pct_daily"?: Long, // Daily cost usage % (0-100)
|
|
220
|
+
"budget_cost_pct_monthly"?: Long, // Monthly cost usage % (0-100)
|
|
221
|
+
"budget_exceeded_session"?: Bool, // Session-scoped budget exceeded
|
|
222
|
+
"budget_exceeded_daily"?: Bool, // Any daily-scoped budget exceeded
|
|
223
|
+
"budget_exceeded_monthly"?: Bool, // Any monthly-scoped budget exceeded
|
|
224
|
+
|
|
209
225
|
// Agent Identity — authenticated agent principal metadata (optional)
|
|
210
226
|
// Present when the request is made by an AI agent (API key or JWT with agent claims).
|
|
211
227
|
// Empty strings for human user requests. Use these to write agent-specific policies.
|
|
@@ -245,9 +261,20 @@ namespace Guardrails {
|
|
|
245
261
|
"loop_count"?: Long,
|
|
246
262
|
"loop_tool"?: String,
|
|
247
263
|
|
|
248
|
-
//
|
|
249
|
-
|
|
250
|
-
"
|
|
264
|
+
// Usage Budget — multi-window token & cost enforcement (optional)
|
|
265
|
+
// See ProcessPromptContext for full documentation.
|
|
266
|
+
"budget_remaining_pct"?: Long, // Min remaining % across all windows
|
|
267
|
+
"budget_exceeded"?: Bool, // Any window limit exceeded
|
|
268
|
+
"budget_cost_micros_this_turn"?: Long, // Cost of this request in microdollars
|
|
269
|
+
"budget_model"?: String,
|
|
270
|
+
"budget_tokens_pct_session"?: Long,
|
|
271
|
+
"budget_tokens_pct_daily"?: Long,
|
|
272
|
+
"budget_tokens_pct_monthly"?: Long,
|
|
273
|
+
"budget_cost_pct_daily"?: Long,
|
|
274
|
+
"budget_cost_pct_monthly"?: Long,
|
|
275
|
+
"budget_exceeded_session"?: Bool,
|
|
276
|
+
"budget_exceeded_daily"?: Bool,
|
|
277
|
+
"budget_exceeded_monthly"?: Bool,
|
|
251
278
|
|
|
252
279
|
// Semantic - Topic Classification (optional)
|
|
253
280
|
"content_topics"?: Set<String>, // ["controlled_substances", "weapons_manufacturing", ...]
|
|
@@ -375,6 +402,21 @@ namespace Guardrails {
|
|
|
375
402
|
"session_max_secret_score"?: Long,
|
|
376
403
|
"session_cumulative_risk_score"?: Long,
|
|
377
404
|
|
|
405
|
+
// Usage Budget — multi-window token & cost enforcement (optional)
|
|
406
|
+
// See ProcessPromptContext for full documentation.
|
|
407
|
+
"budget_remaining_pct"?: Long,
|
|
408
|
+
"budget_exceeded"?: Bool,
|
|
409
|
+
"budget_cost_micros_this_turn"?: Long,
|
|
410
|
+
"budget_model"?: String,
|
|
411
|
+
"budget_tokens_pct_session"?: Long,
|
|
412
|
+
"budget_tokens_pct_daily"?: Long,
|
|
413
|
+
"budget_tokens_pct_monthly"?: Long,
|
|
414
|
+
"budget_cost_pct_daily"?: Long,
|
|
415
|
+
"budget_cost_pct_monthly"?: Long,
|
|
416
|
+
"budget_exceeded_session"?: Bool,
|
|
417
|
+
"budget_exceeded_daily"?: Bool,
|
|
418
|
+
"budget_exceeded_monthly"?: Bool,
|
|
419
|
+
|
|
378
420
|
// Agent Identity — authenticated agent principal metadata (optional)
|
|
379
421
|
"agent_id"?: String,
|
|
380
422
|
"agent_type"?: String,
|
|
@@ -424,6 +466,21 @@ namespace Guardrails {
|
|
|
424
466
|
"session_max_secret_score"?: Long,
|
|
425
467
|
"session_cumulative_risk_score"?: Long,
|
|
426
468
|
|
|
469
|
+
// Usage Budget — multi-window token & cost enforcement (optional)
|
|
470
|
+
// See ProcessPromptContext for full documentation.
|
|
471
|
+
"budget_remaining_pct"?: Long,
|
|
472
|
+
"budget_exceeded"?: Bool,
|
|
473
|
+
"budget_cost_micros_this_turn"?: Long,
|
|
474
|
+
"budget_model"?: String,
|
|
475
|
+
"budget_tokens_pct_session"?: Long,
|
|
476
|
+
"budget_tokens_pct_daily"?: Long,
|
|
477
|
+
"budget_tokens_pct_monthly"?: Long,
|
|
478
|
+
"budget_cost_pct_daily"?: Long,
|
|
479
|
+
"budget_cost_pct_monthly"?: Long,
|
|
480
|
+
"budget_exceeded_session"?: Bool,
|
|
481
|
+
"budget_exceeded_daily"?: Bool,
|
|
482
|
+
"budget_exceeded_monthly"?: Bool,
|
|
483
|
+
|
|
427
484
|
// Agent Identity — authenticated agent principal metadata (optional)
|
|
428
485
|
"agent_id"?: String,
|
|
429
486
|
"agent_type"?: String,
|
|
@@ -473,6 +530,21 @@ namespace Guardrails {
|
|
|
473
530
|
"session_max_secret_score"?: Long,
|
|
474
531
|
"session_cumulative_risk_score"?: Long,
|
|
475
532
|
|
|
533
|
+
// Usage Budget — multi-window token & cost enforcement (optional)
|
|
534
|
+
// See ProcessPromptContext for full documentation.
|
|
535
|
+
"budget_remaining_pct"?: Long,
|
|
536
|
+
"budget_exceeded"?: Bool,
|
|
537
|
+
"budget_cost_micros_this_turn"?: Long,
|
|
538
|
+
"budget_model"?: String,
|
|
539
|
+
"budget_tokens_pct_session"?: Long,
|
|
540
|
+
"budget_tokens_pct_daily"?: Long,
|
|
541
|
+
"budget_tokens_pct_monthly"?: Long,
|
|
542
|
+
"budget_cost_pct_daily"?: Long,
|
|
543
|
+
"budget_cost_pct_monthly"?: Long,
|
|
544
|
+
"budget_exceeded_session"?: Bool,
|
|
545
|
+
"budget_exceeded_daily"?: Bool,
|
|
546
|
+
"budget_exceeded_monthly"?: Bool,
|
|
547
|
+
|
|
476
548
|
// Agent Identity — authenticated agent principal metadata (optional)
|
|
477
549
|
"agent_id"?: String,
|
|
478
550
|
"agent_type"?: String,
|
|
@@ -137,6 +137,20 @@ action call_tool appliesTo {
|
|
|
137
137
|
suspicious_pattern?: Bool,
|
|
138
138
|
pattern_type?: String,
|
|
139
139
|
sequence_risk?: Long,
|
|
140
|
+
|
|
141
|
+
// --- Usage Budget (multi-window, multi-dimension) ---
|
|
142
|
+
budget_remaining_pct?: Long,
|
|
143
|
+
budget_exceeded?: Bool,
|
|
144
|
+
budget_cost_micros_this_turn?: Long,
|
|
145
|
+
budget_model?: String,
|
|
146
|
+
budget_tokens_pct_session?: Long,
|
|
147
|
+
budget_tokens_pct_daily?: Long,
|
|
148
|
+
budget_tokens_pct_monthly?: Long,
|
|
149
|
+
budget_cost_pct_daily?: Long,
|
|
150
|
+
budget_cost_pct_monthly?: Long,
|
|
151
|
+
budget_exceeded_session?: Bool,
|
|
152
|
+
budget_exceeded_daily?: Bool,
|
|
153
|
+
budget_exceeded_monthly?: Bool,
|
|
140
154
|
},
|
|
141
155
|
};
|
|
142
156
|
|
|
@@ -166,6 +180,20 @@ action connect_server appliesTo {
|
|
|
166
180
|
mcp_server_verified?: Bool,
|
|
167
181
|
mcp_config_risk?: Bool,
|
|
168
182
|
mcp_risk_score?: Long,
|
|
183
|
+
|
|
184
|
+
// --- Usage Budget (multi-window, multi-dimension) ---
|
|
185
|
+
budget_remaining_pct?: Long,
|
|
186
|
+
budget_exceeded?: Bool,
|
|
187
|
+
budget_cost_micros_this_turn?: Long,
|
|
188
|
+
budget_model?: String,
|
|
189
|
+
budget_tokens_pct_session?: Long,
|
|
190
|
+
budget_tokens_pct_daily?: Long,
|
|
191
|
+
budget_tokens_pct_monthly?: Long,
|
|
192
|
+
budget_cost_pct_daily?: Long,
|
|
193
|
+
budget_cost_pct_monthly?: Long,
|
|
194
|
+
budget_exceeded_session?: Bool,
|
|
195
|
+
budget_exceeded_daily?: Bool,
|
|
196
|
+
budget_exceeded_monthly?: Bool,
|
|
169
197
|
},
|
|
170
198
|
};
|
|
171
199
|
|
|
@@ -210,6 +238,20 @@ action process_prompt appliesTo {
|
|
|
210
238
|
// --- Encoding ---
|
|
211
239
|
contains_invisible_chars?: Bool,
|
|
212
240
|
invisible_chars_score?: Long,
|
|
241
|
+
|
|
242
|
+
// --- Usage Budget (multi-window, multi-dimension) ---
|
|
243
|
+
budget_remaining_pct?: Long,
|
|
244
|
+
budget_exceeded?: Bool,
|
|
245
|
+
budget_cost_micros_this_turn?: Long,
|
|
246
|
+
budget_model?: String,
|
|
247
|
+
budget_tokens_pct_session?: Long,
|
|
248
|
+
budget_tokens_pct_daily?: Long,
|
|
249
|
+
budget_tokens_pct_monthly?: Long,
|
|
250
|
+
budget_cost_pct_daily?: Long,
|
|
251
|
+
budget_cost_pct_monthly?: Long,
|
|
252
|
+
budget_exceeded_session?: Bool,
|
|
253
|
+
budget_exceeded_daily?: Bool,
|
|
254
|
+
budget_exceeded_monthly?: Bool,
|
|
213
255
|
},
|
|
214
256
|
};
|
|
215
257
|
|
|
@@ -238,6 +280,20 @@ action read_file appliesTo {
|
|
|
238
280
|
pii_detected?: Bool,
|
|
239
281
|
pii_types?: Set<String>,
|
|
240
282
|
pii_count?: Long,
|
|
283
|
+
|
|
284
|
+
// --- Usage Budget (multi-window, multi-dimension) ---
|
|
285
|
+
budget_remaining_pct?: Long,
|
|
286
|
+
budget_exceeded?: Bool,
|
|
287
|
+
budget_cost_micros_this_turn?: Long,
|
|
288
|
+
budget_model?: String,
|
|
289
|
+
budget_tokens_pct_session?: Long,
|
|
290
|
+
budget_tokens_pct_daily?: Long,
|
|
291
|
+
budget_tokens_pct_monthly?: Long,
|
|
292
|
+
budget_cost_pct_daily?: Long,
|
|
293
|
+
budget_cost_pct_monthly?: Long,
|
|
294
|
+
budget_exceeded_session?: Bool,
|
|
295
|
+
budget_exceeded_daily?: Bool,
|
|
296
|
+
budget_exceeded_monthly?: Bool,
|
|
241
297
|
},
|
|
242
298
|
};
|
|
243
299
|
|
|
@@ -266,6 +322,20 @@ action write_file appliesTo {
|
|
|
266
322
|
pii_detected?: Bool,
|
|
267
323
|
pii_types?: Set<String>,
|
|
268
324
|
pii_count?: Long,
|
|
325
|
+
|
|
326
|
+
// --- Usage Budget (multi-window, multi-dimension) ---
|
|
327
|
+
budget_remaining_pct?: Long,
|
|
328
|
+
budget_exceeded?: Bool,
|
|
329
|
+
budget_cost_micros_this_turn?: Long,
|
|
330
|
+
budget_model?: String,
|
|
331
|
+
budget_tokens_pct_session?: Long,
|
|
332
|
+
budget_tokens_pct_daily?: Long,
|
|
333
|
+
budget_tokens_pct_monthly?: Long,
|
|
334
|
+
budget_cost_pct_daily?: Long,
|
|
335
|
+
budget_cost_pct_monthly?: Long,
|
|
336
|
+
budget_exceeded_session?: Bool,
|
|
337
|
+
budget_exceeded_daily?: Bool,
|
|
338
|
+
budget_exceeded_monthly?: Bool,
|
|
269
339
|
},
|
|
270
340
|
};
|
|
271
341
|
|
package/dist/engine.d.ts
CHANGED
|
@@ -48,6 +48,19 @@ export interface DeterminingPolicy {
|
|
|
48
48
|
/** All annotations from this policy as key-value pairs */
|
|
49
49
|
annotations: Record<string, string>;
|
|
50
50
|
}
|
|
51
|
+
/**
|
|
52
|
+
* Pairs a Cedar policy text with a globally-unique identifier (typically the
|
|
53
|
+
* originating database row's UUID) used as the cedar PolicySet key.
|
|
54
|
+
*
|
|
55
|
+
* Use with {@link PolicyEngine.loadPoliciesWithIds} to safely load policies
|
|
56
|
+
* from multiple tenants whose @id annotations may collide.
|
|
57
|
+
*/
|
|
58
|
+
export interface PolicyTextWithID {
|
|
59
|
+
/** Cedar policy text (may contain @id and other annotations) */
|
|
60
|
+
text: string;
|
|
61
|
+
/** Unique identifier — must be unique across the input set */
|
|
62
|
+
id: string;
|
|
63
|
+
}
|
|
51
64
|
export declare class Decision {
|
|
52
65
|
readonly effect: "Allow" | "Deny";
|
|
53
66
|
readonly determining_policies: DeterminingPolicy[];
|
|
@@ -92,8 +105,32 @@ export declare class PolicyEngine {
|
|
|
92
105
|
* Load multiple Cedar policy texts (concatenated with newlines).
|
|
93
106
|
* Uses @id annotations as policy IDs when available.
|
|
94
107
|
* Stores all annotations per policy for enriching evaluation results.
|
|
108
|
+
*
|
|
109
|
+
* @deprecated Use {@link loadPoliciesWithIds} for any code that may load
|
|
110
|
+
* policies from multiple tenants. This method's @id-as-PolicyID behavior
|
|
111
|
+
* silently overwrites the cedar PolicySet entry when later policies share
|
|
112
|
+
* an @id with earlier ones (e.g., every tenant's `baseline-permit-all`).
|
|
113
|
+
* Kept for ad-hoc and test usage where uniqueness is guaranteed by the
|
|
114
|
+
* caller.
|
|
95
115
|
*/
|
|
96
116
|
loadPolicies(policies: string[]): void;
|
|
117
|
+
/**
|
|
118
|
+
* Load Cedar policies using caller-supplied unique IDs as the cedar
|
|
119
|
+
* PolicySet key, preventing cross-tenant @id collisions that occur when
|
|
120
|
+
* multiple tenants author policies from a shared template (e.g., each
|
|
121
|
+
* tenant's `baseline-permit-all` sharing the same @id annotation).
|
|
122
|
+
*
|
|
123
|
+
* Each input is parsed independently so the supplied id maps
|
|
124
|
+
* deterministically to its policy. If a single text contains multiple
|
|
125
|
+
* Cedar policies, each is stored under `"<id>#<index>"`. The original
|
|
126
|
+
* @id annotation remains accessible via {@link getPolicyAnnotations}.
|
|
127
|
+
*
|
|
128
|
+
* When `item.id` is empty, the method falls back to @id-annotation-based
|
|
129
|
+
* id assignment (matching {@link loadPolicies} semantics) — useful for
|
|
130
|
+
* tests and ad-hoc loaders. Production multi-tenant callers MUST supply
|
|
131
|
+
* a non-empty id per policy or they reintroduce the collision risk.
|
|
132
|
+
*/
|
|
133
|
+
loadPoliciesWithIds(policies: PolicyTextWithID[]): void;
|
|
97
134
|
/**
|
|
98
135
|
* Load schema from a Cedar schema string.
|
|
99
136
|
*/
|
package/dist/engine.js
CHANGED
|
@@ -226,12 +226,68 @@ export class PolicyEngine {
|
|
|
226
226
|
* Load multiple Cedar policy texts (concatenated with newlines).
|
|
227
227
|
* Uses @id annotations as policy IDs when available.
|
|
228
228
|
* Stores all annotations per policy for enriching evaluation results.
|
|
229
|
+
*
|
|
230
|
+
* @deprecated Use {@link loadPoliciesWithIds} for any code that may load
|
|
231
|
+
* policies from multiple tenants. This method's @id-as-PolicyID behavior
|
|
232
|
+
* silently overwrites the cedar PolicySet entry when later policies share
|
|
233
|
+
* an @id with earlier ones (e.g., every tenant's `baseline-permit-all`).
|
|
234
|
+
* Kept for ad-hoc and test usage where uniqueness is guaranteed by the
|
|
235
|
+
* caller.
|
|
229
236
|
*/
|
|
230
237
|
loadPolicies(policies) {
|
|
231
238
|
const extracted = extractPolicies(policies.join("\n"));
|
|
232
239
|
this.policySet = extracted.policySet;
|
|
233
240
|
this.policyAnnotations = extracted.annotations;
|
|
234
241
|
}
|
|
242
|
+
/**
|
|
243
|
+
* Load Cedar policies using caller-supplied unique IDs as the cedar
|
|
244
|
+
* PolicySet key, preventing cross-tenant @id collisions that occur when
|
|
245
|
+
* multiple tenants author policies from a shared template (e.g., each
|
|
246
|
+
* tenant's `baseline-permit-all` sharing the same @id annotation).
|
|
247
|
+
*
|
|
248
|
+
* Each input is parsed independently so the supplied id maps
|
|
249
|
+
* deterministically to its policy. If a single text contains multiple
|
|
250
|
+
* Cedar policies, each is stored under `"<id>#<index>"`. The original
|
|
251
|
+
* @id annotation remains accessible via {@link getPolicyAnnotations}.
|
|
252
|
+
*
|
|
253
|
+
* When `item.id` is empty, the method falls back to @id-annotation-based
|
|
254
|
+
* id assignment (matching {@link loadPolicies} semantics) — useful for
|
|
255
|
+
* tests and ad-hoc loaders. Production multi-tenant callers MUST supply
|
|
256
|
+
* a non-empty id per policy or they reintroduce the collision risk.
|
|
257
|
+
*/
|
|
258
|
+
loadPoliciesWithIds(policies) {
|
|
259
|
+
const policyMap = {};
|
|
260
|
+
const annotationsMap = new Map();
|
|
261
|
+
let posIdx = 0;
|
|
262
|
+
for (const item of policies) {
|
|
263
|
+
const parts = cedar.policySetTextToParts(item.text);
|
|
264
|
+
if (parts.type !== "success" || parts.policies.length === 0) {
|
|
265
|
+
continue;
|
|
266
|
+
}
|
|
267
|
+
for (let subIdx = 0; subIdx < parts.policies.length; subIdx++) {
|
|
268
|
+
const policy = parts.policies[subIdx];
|
|
269
|
+
const policyAnnotations = extractAnnotationsFromText(policy);
|
|
270
|
+
let id;
|
|
271
|
+
if (item.id !== "") {
|
|
272
|
+
id = subIdx === 0 ? item.id : `${item.id}#${subIdx}`;
|
|
273
|
+
}
|
|
274
|
+
else if (policyAnnotations["id"]) {
|
|
275
|
+
id = policyAnnotations["id"];
|
|
276
|
+
}
|
|
277
|
+
else {
|
|
278
|
+
id = `policy${posIdx}`;
|
|
279
|
+
}
|
|
280
|
+
if (annotationsMap.has(id)) {
|
|
281
|
+
throw new Error(`duplicate policy ID detected: ${id}`);
|
|
282
|
+
}
|
|
283
|
+
policyMap[id] = policy;
|
|
284
|
+
annotationsMap.set(id, policyAnnotations);
|
|
285
|
+
posIdx++;
|
|
286
|
+
}
|
|
287
|
+
}
|
|
288
|
+
this.policySet = policyMap;
|
|
289
|
+
this.policyAnnotations = annotationsMap;
|
|
290
|
+
}
|
|
235
291
|
/**
|
|
236
292
|
* Load schema from a Cedar schema string.
|
|
237
293
|
*/
|
|
@@ -3,13 +3,13 @@
|
|
|
3
3
|
*
|
|
4
4
|
* Full Cedar schema for ai_gateway, embedded at codegen time.
|
|
5
5
|
*/
|
|
6
|
-
export declare const AI_GATEWAY_SCHEMA = "// AIGateway Cedar Schema\n// ===================================\n// AI Gateway Security & Policy Enforcement\n//\n// AIGateway protects both MCP proxy operations (tool calls, server connections)\n// and LLM chat completions (prompt processing) by evaluating threats detected\n// by the Shield detection engine pipeline against Cedar policies.\n//\n// Architecture:\n// MCP/LLM Client -> Firehog Proxy -> Shield (detection + Cedar) -> Allow/Deny\n//\n// Threat Coverage:\n// - OWASP Top 10 for LLM Applications 2025 (LLM01, LLM06)\n// - OWASP Top 10 for Agentic Applications (ASI01, ASI02, ASI04)\n// - OWASP MCP Top 10 (MCP01-MCP05)\n\nnamespace AIGateway {\n\n// =============================================================================\n// ENTITIES - Tenant Hierarchy (ReBAC)\n// =============================================================================\n// AIGateway does not use App/Session hierarchy.\n//\n// Entity hierarchy:\n// Account (org root)\n// -> Project in [Account]\n// -> Tool/Server in [Project]\n//\n// Policy scoping examples:\n// resource == AIGateway::Tool::\"get_me\" -> specific tool\n// resource in AIGateway::Project::\"<uuid>\" -> project-wide\n// resource in AIGateway::Account::\"<uuid>\" -> org-wide\n\n/// Account represents an organization (top-level tenant)\nentity Account;\n\n/// Project represents a project within an account\nentity Project in [Account];\n\n// =============================================================================\n// ENTITIES - Principals\n// =============================================================================\n\n/// Human user authenticated via JWT or API key\nentity User;\n\n/// MCP client (default principal for unauthenticated requests)\nentity MCP_Client;\n\n// =============================================================================\n// ENTITIES - Resources (scoped under Project)\n// =============================================================================\n\n/// MCP tool -- resource for call_tool action\nentity Tool in [Project];\n\n/// MCP server -- resource for connect_server action\nentity Server in [Project];\n\n/// MCP prompt -- resource for process_prompt action\nentity LlmPrompt in [Project];\n\n/// File/resource path -- resource for read_file/write_file actions\nentity FilePath in [Project];\n\n// =============================================================================\n// ACTIONS\n// =============================================================================\n\n// Call an MCP tool\n// Threat focus: command injection, tool poisoning, rug pull, secrets, PII\naction call_tool appliesTo {\n principal: [User, MCP_Client],\n resource: [Tool],\n context: {\n // --- Content ---\n content: String, // Raw content being scanned\n\n // --- Tool & MCP ---\n tool_name?: String, // Tool name\n mcp_server?: String, // MCP server name\n mcp_tool?: String, // MCP tool name\n\n // --- Threat Detection (from Shield detection pipeline) ---\n threat_count?: Long, // Total threats detected\n highest_severity?: String, // \"critical\", \"high\", \"medium\", \"low\", \"none\"\n threat_categories?: Set<String>, // Threat category names\n detected_threats?: Set<String>, // Detection rule names that matched\n max_threat_severity?: Long, // Numeric severity (0=none, 1=low, 2=medium, 3=high, 4=critical)\n contains_secrets?: Bool, // Whether secrets/credentials detected\n\n // --- Secrets (granular) ---\n secret_types?: Set<String>,\n secret_count?: Long,\n\n // --- PII Detection ---\n pii_detected?: Bool,\n pii_types?: Set<String>,\n pii_count?: Long,\n\n // --- ML Detector Confidence Scores (0-100) ---\n injection_confidence?: Long, // Prompt injection classifier confidence\n jailbreak_confidence?: Long, // Jailbreak detection classifier confidence\n\n // --- Agent Security (0-100) ---\n tool_poisoning_score?: Long, // Hidden instructions in tool description/args\n tool_poisoning_detected?: Bool,\n rug_pull_score?: Long, // Tool behavior drift after trust establishment\n rug_pull_detected?: Bool,\n indirect_injection_score?: Long, // Indirect injection via tool output\n\n // --- Tool Risk Assessment ---\n tool_risk_score?: Long, // Computed tool risk (0-100)\n tool_category?: String, // \"safe\", \"sensitive\", \"dangerous\"\n tool_is_sensitive?: Bool,\n tool_is_builtin?: Bool,\n\n // --- MCP Trust ---\n mcp_server_verified?: Bool, // Whether server is from verified registry\n\n // --- Content Safety Scores (0-100) ---\n violence_score?: Long,\n weapons_score?: Long,\n hate_speech_score?: Long,\n crime_score?: Long,\n sexual_score?: Long,\n profanity_score?: Long,\n\n // --- Encoding & Unicode Attacks ---\n contains_invisible_chars?: Bool,\n invisible_chars_score?: Long,\n\n // --- Behavioral Analysis ---\n loop_detected?: Bool,\n loop_count?: Long,\n loop_tool?: String,\n suspicious_pattern?: Bool,\n pattern_type?: String,\n sequence_risk?: Long,\n },\n};\n\n// Connect to an MCP server\n// Threat focus: supply chain, tool poisoning, rug pull, config risk\naction connect_server appliesTo {\n principal: [User, MCP_Client],\n resource: [Server],\n context: {\n content?: String, // Server config content (if available)\n mcp_server?: String,\n\n // --- Threat Detection ---\n threat_count?: Long,\n highest_severity?: String,\n threat_categories?: Set<String>,\n max_threat_severity?: Long,\n\n // --- Agent Security (0-100) ---\n tool_poisoning_score?: Long,\n tool_poisoning_detected?: Bool,\n rug_pull_score?: Long,\n rug_pull_detected?: Bool,\n indirect_injection_score?: Long,\n\n // --- Secrets ---\n contains_secrets?: Bool,\n secret_types?: Set<String>,\n secret_count?: Long,\n\n // --- PII Detection ---\n pii_detected?: Bool,\n pii_types?: Set<String>,\n pii_count?: Long,\n\n // --- MCP Trust & Config Risk ---\n mcp_server_verified?: Bool,\n mcp_config_risk?: Bool,\n mcp_risk_score?: Long,\n },\n};\n\n// Process a prompt (MCP prompts/get or LLM chat completions)\n// Threat focus: injection, jailbreak, secrets, PII, content safety\naction process_prompt appliesTo {\n principal: [User, MCP_Client],\n resource: [LlmPrompt],\n context: {\n content: String,\n mcp_server?: String,\n\n // --- Threat Detection ---\n threat_count?: Long,\n highest_severity?: String,\n threat_categories?: Set<String>,\n detected_threats?: Set<String>,\n max_threat_severity?: Long,\n contains_secrets?: Bool,\n\n // --- Secrets ---\n secret_types?: Set<String>,\n secret_count?: Long,\n\n // --- PII Detection ---\n pii_detected?: Bool,\n pii_types?: Set<String>,\n pii_count?: Long,\n\n // --- ML Detector Confidence Scores (0-100) ---\n injection_confidence?: Long,\n jailbreak_confidence?: Long,\n\n // --- Content Safety Scores (0-100) ---\n violence_score?: Long,\n weapons_score?: Long,\n hate_speech_score?: Long,\n crime_score?: Long,\n sexual_score?: Long,\n profanity_score?: Long,\n\n // --- Encoding ---\n contains_invisible_chars?: Bool,\n invisible_chars_score?: Long,\n\n // --- LLM-specific ---\n model_name?: String, // Target model name (e.g., \"gpt-4\", \"claude-3-opus\")\n model_provider?: String, // Provider name (e.g., \"openai\", \"anthropic\", \"bedrock\")\n },\n};\n\n// Read an MCP resource (resources/read, resources/list)\n// Threat focus: secrets exposure, PII exposure, sensitive paths\naction read_file appliesTo {\n principal: [User, MCP_Client],\n resource: [FilePath],\n context: {\n content: String,\n mcp_server?: String,\n\n // --- Threat Detection ---\n threat_count?: Long,\n highest_severity?: String,\n threat_categories?: Set<String>,\n detected_threats?: Set<String>,\n max_threat_severity?: Long,\n contains_secrets?: Bool,\n\n // --- Secrets ---\n secret_types?: Set<String>,\n secret_count?: Long,\n\n // --- PII Detection ---\n pii_detected?: Bool,\n pii_types?: Set<String>,\n pii_count?: Long,\n },\n};\n\n// Write an MCP resource (resources/write)\n// Threat focus: secrets in output, PII in output\naction write_file appliesTo {\n principal: [User, MCP_Client],\n resource: [FilePath],\n context: {\n content: String,\n mcp_server?: String,\n\n // --- Threat Detection ---\n threat_count?: Long,\n highest_severity?: String,\n threat_categories?: Set<String>,\n detected_threats?: Set<String>,\n max_threat_severity?: Long,\n contains_secrets?: Bool,\n\n // --- Secrets ---\n secret_types?: Set<String>,\n secret_count?: Long,\n\n // --- PII Detection ---\n pii_detected?: Bool,\n pii_types?: Set<String>,\n pii_count?: Long,\n },\n};\n\n}\n";
|
|
6
|
+
export declare const AI_GATEWAY_SCHEMA = "// AIGateway Cedar Schema\n// ===================================\n// AI Gateway Security & Policy Enforcement\n//\n// AIGateway protects both MCP proxy operations (tool calls, server connections)\n// and LLM chat completions (prompt processing) by evaluating threats detected\n// by the Shield detection engine pipeline against Cedar policies.\n//\n// Architecture:\n// MCP/LLM Client -> Firehog Proxy -> Shield (detection + Cedar) -> Allow/Deny\n//\n// Threat Coverage:\n// - OWASP Top 10 for LLM Applications 2025 (LLM01, LLM06)\n// - OWASP Top 10 for Agentic Applications (ASI01, ASI02, ASI04)\n// - OWASP MCP Top 10 (MCP01-MCP05)\n\nnamespace AIGateway {\n\n// =============================================================================\n// ENTITIES - Tenant Hierarchy (ReBAC)\n// =============================================================================\n// AIGateway does not use App/Session hierarchy.\n//\n// Entity hierarchy:\n// Account (org root)\n// -> Project in [Account]\n// -> Tool/Server in [Project]\n//\n// Policy scoping examples:\n// resource == AIGateway::Tool::\"get_me\" -> specific tool\n// resource in AIGateway::Project::\"<uuid>\" -> project-wide\n// resource in AIGateway::Account::\"<uuid>\" -> org-wide\n\n/// Account represents an organization (top-level tenant)\nentity Account;\n\n/// Project represents a project within an account\nentity Project in [Account];\n\n// =============================================================================\n// ENTITIES - Principals\n// =============================================================================\n\n/// Human user authenticated via JWT or API key\nentity User;\n\n/// MCP client (default principal for unauthenticated requests)\nentity MCP_Client;\n\n// =============================================================================\n// ENTITIES - Resources (scoped under Project)\n// =============================================================================\n\n/// MCP tool -- resource for call_tool action\nentity Tool in [Project];\n\n/// MCP server -- resource for connect_server action\nentity Server in [Project];\n\n/// MCP prompt -- resource for process_prompt action\nentity LlmPrompt in [Project];\n\n/// File/resource path -- resource for read_file/write_file actions\nentity FilePath in [Project];\n\n// =============================================================================\n// ACTIONS\n// =============================================================================\n\n// Call an MCP tool\n// Threat focus: command injection, tool poisoning, rug pull, secrets, PII\naction call_tool appliesTo {\n principal: [User, MCP_Client],\n resource: [Tool],\n context: {\n // --- Content ---\n content: String, // Raw content being scanned\n\n // --- Tool & MCP ---\n tool_name?: String, // Tool name\n mcp_server?: String, // MCP server name\n mcp_tool?: String, // MCP tool name\n\n // --- Threat Detection (from Shield detection pipeline) ---\n threat_count?: Long, // Total threats detected\n highest_severity?: String, // \"critical\", \"high\", \"medium\", \"low\", \"none\"\n threat_categories?: Set<String>, // Threat category names\n detected_threats?: Set<String>, // Detection rule names that matched\n max_threat_severity?: Long, // Numeric severity (0=none, 1=low, 2=medium, 3=high, 4=critical)\n contains_secrets?: Bool, // Whether secrets/credentials detected\n\n // --- Secrets (granular) ---\n secret_types?: Set<String>,\n secret_count?: Long,\n\n // --- PII Detection ---\n pii_detected?: Bool,\n pii_types?: Set<String>,\n pii_count?: Long,\n\n // --- ML Detector Confidence Scores (0-100) ---\n injection_confidence?: Long, // Prompt injection classifier confidence\n jailbreak_confidence?: Long, // Jailbreak detection classifier confidence\n\n // --- Agent Security (0-100) ---\n tool_poisoning_score?: Long, // Hidden instructions in tool description/args\n tool_poisoning_detected?: Bool,\n rug_pull_score?: Long, // Tool behavior drift after trust establishment\n rug_pull_detected?: Bool,\n indirect_injection_score?: Long, // Indirect injection via tool output\n\n // --- Tool Risk Assessment ---\n tool_risk_score?: Long, // Computed tool risk (0-100)\n tool_category?: String, // \"safe\", \"sensitive\", \"dangerous\"\n tool_is_sensitive?: Bool,\n tool_is_builtin?: Bool,\n\n // --- MCP Trust ---\n mcp_server_verified?: Bool, // Whether server is from verified registry\n\n // --- Content Safety Scores (0-100) ---\n violence_score?: Long,\n weapons_score?: Long,\n hate_speech_score?: Long,\n crime_score?: Long,\n sexual_score?: Long,\n profanity_score?: Long,\n\n // --- Encoding & Unicode Attacks ---\n contains_invisible_chars?: Bool,\n invisible_chars_score?: Long,\n\n // --- Behavioral Analysis ---\n loop_detected?: Bool,\n loop_count?: Long,\n loop_tool?: String,\n suspicious_pattern?: Bool,\n pattern_type?: String,\n sequence_risk?: Long,\n\n // --- Usage Budget (multi-window, multi-dimension) ---\n budget_remaining_pct?: Long,\n budget_exceeded?: Bool,\n budget_cost_micros_this_turn?: Long,\n budget_model?: String,\n budget_tokens_pct_session?: Long,\n budget_tokens_pct_daily?: Long,\n budget_tokens_pct_monthly?: Long,\n budget_cost_pct_daily?: Long,\n budget_cost_pct_monthly?: Long,\n budget_exceeded_session?: Bool,\n budget_exceeded_daily?: Bool,\n budget_exceeded_monthly?: Bool,\n },\n};\n\n// Connect to an MCP server\n// Threat focus: supply chain, tool poisoning, rug pull, config risk\naction connect_server appliesTo {\n principal: [User, MCP_Client],\n resource: [Server],\n context: {\n content?: String, // Server config content (if available)\n mcp_server?: String,\n\n // --- Threat Detection ---\n threat_count?: Long,\n highest_severity?: String,\n threat_categories?: Set<String>,\n max_threat_severity?: Long,\n\n // --- Agent Security (0-100) ---\n tool_poisoning_score?: Long,\n tool_poisoning_detected?: Bool,\n rug_pull_score?: Long,\n rug_pull_detected?: Bool,\n indirect_injection_score?: Long,\n\n // --- Secrets ---\n contains_secrets?: Bool,\n secret_types?: Set<String>,\n secret_count?: Long,\n\n // --- PII Detection ---\n pii_detected?: Bool,\n pii_types?: Set<String>,\n pii_count?: Long,\n\n // --- MCP Trust & Config Risk ---\n mcp_server_verified?: Bool,\n mcp_config_risk?: Bool,\n mcp_risk_score?: Long,\n\n // --- Usage Budget (multi-window, multi-dimension) ---\n budget_remaining_pct?: Long,\n budget_exceeded?: Bool,\n budget_cost_micros_this_turn?: Long,\n budget_model?: String,\n budget_tokens_pct_session?: Long,\n budget_tokens_pct_daily?: Long,\n budget_tokens_pct_monthly?: Long,\n budget_cost_pct_daily?: Long,\n budget_cost_pct_monthly?: Long,\n budget_exceeded_session?: Bool,\n budget_exceeded_daily?: Bool,\n budget_exceeded_monthly?: Bool,\n },\n};\n\n// Process a prompt (MCP prompts/get or LLM chat completions)\n// Threat focus: injection, jailbreak, secrets, PII, content safety\naction process_prompt appliesTo {\n principal: [User, MCP_Client],\n resource: [LlmPrompt],\n context: {\n content: String,\n mcp_server?: String,\n\n // --- Threat Detection ---\n threat_count?: Long,\n highest_severity?: String,\n threat_categories?: Set<String>,\n detected_threats?: Set<String>,\n max_threat_severity?: Long,\n contains_secrets?: Bool,\n\n // --- Secrets ---\n secret_types?: Set<String>,\n secret_count?: Long,\n\n // --- PII Detection ---\n pii_detected?: Bool,\n pii_types?: Set<String>,\n pii_count?: Long,\n\n // --- ML Detector Confidence Scores (0-100) ---\n injection_confidence?: Long,\n jailbreak_confidence?: Long,\n\n // --- Content Safety Scores (0-100) ---\n violence_score?: Long,\n weapons_score?: Long,\n hate_speech_score?: Long,\n crime_score?: Long,\n sexual_score?: Long,\n profanity_score?: Long,\n\n // --- Encoding ---\n contains_invisible_chars?: Bool,\n invisible_chars_score?: Long,\n\n // --- LLM-specific ---\n model_name?: String, // Target model name (e.g., \"gpt-4\", \"claude-3-opus\")\n model_provider?: String, // Provider name (e.g., \"openai\", \"anthropic\", \"bedrock\")\n\n // --- Usage Budget (multi-window, multi-dimension) ---\n budget_remaining_pct?: Long,\n budget_exceeded?: Bool,\n budget_cost_micros_this_turn?: Long,\n budget_model?: String,\n budget_tokens_pct_session?: Long,\n budget_tokens_pct_daily?: Long,\n budget_tokens_pct_monthly?: Long,\n budget_cost_pct_daily?: Long,\n budget_cost_pct_monthly?: Long,\n budget_exceeded_session?: Bool,\n budget_exceeded_daily?: Bool,\n budget_exceeded_monthly?: Bool,\n },\n};\n\n// Read an MCP resource (resources/read, resources/list)\n// Threat focus: secrets exposure, PII exposure, sensitive paths\naction read_file appliesTo {\n principal: [User, MCP_Client],\n resource: [FilePath],\n context: {\n content: String,\n mcp_server?: String,\n\n // --- Threat Detection ---\n threat_count?: Long,\n highest_severity?: String,\n threat_categories?: Set<String>,\n detected_threats?: Set<String>,\n max_threat_severity?: Long,\n contains_secrets?: Bool,\n\n // --- Secrets ---\n secret_types?: Set<String>,\n secret_count?: Long,\n\n // --- PII Detection ---\n pii_detected?: Bool,\n pii_types?: Set<String>,\n pii_count?: Long,\n\n // --- Usage Budget (multi-window, multi-dimension) ---\n budget_remaining_pct?: Long,\n budget_exceeded?: Bool,\n budget_cost_micros_this_turn?: Long,\n budget_model?: String,\n budget_tokens_pct_session?: Long,\n budget_tokens_pct_daily?: Long,\n budget_tokens_pct_monthly?: Long,\n budget_cost_pct_daily?: Long,\n budget_cost_pct_monthly?: Long,\n budget_exceeded_session?: Bool,\n budget_exceeded_daily?: Bool,\n budget_exceeded_monthly?: Bool,\n },\n};\n\n// Write an MCP resource (resources/write)\n// Threat focus: secrets in output, PII in output\naction write_file appliesTo {\n principal: [User, MCP_Client],\n resource: [FilePath],\n context: {\n content: String,\n mcp_server?: String,\n\n // --- Threat Detection ---\n threat_count?: Long,\n highest_severity?: String,\n threat_categories?: Set<String>,\n detected_threats?: Set<String>,\n max_threat_severity?: Long,\n contains_secrets?: Bool,\n\n // --- Secrets ---\n secret_types?: Set<String>,\n secret_count?: Long,\n\n // --- PII Detection ---\n pii_detected?: Bool,\n pii_types?: Set<String>,\n pii_count?: Long,\n\n // --- Usage Budget (multi-window, multi-dimension) ---\n budget_remaining_pct?: Long,\n budget_exceeded?: Bool,\n budget_cost_micros_this_turn?: Long,\n budget_model?: String,\n budget_tokens_pct_session?: Long,\n budget_tokens_pct_daily?: Long,\n budget_tokens_pct_monthly?: Long,\n budget_cost_pct_daily?: Long,\n budget_cost_pct_monthly?: Long,\n budget_exceeded_session?: Bool,\n budget_exceeded_daily?: Bool,\n budget_exceeded_monthly?: Bool,\n },\n};\n\n}\n";
|
|
7
7
|
/**
|
|
8
8
|
* Guardrails Cedar schema
|
|
9
9
|
*
|
|
10
10
|
* Full Cedar schema for guardrails, embedded at codegen time.
|
|
11
11
|
*/
|
|
12
|
-
export declare const GUARDRAILS_SCHEMA = "// =============================================================================\n// Guardrails Cedar Schema\n// =============================================================================\n// Defines entity types, actions, and context attributes for the highflame-shield\n// guardrails service. This schema enables type-safe policy authoring and\n// validation in both Studio UI and backend.\n//\n// Service: highflame-shield (guardrails)\n// Namespace: Guardrails\n// =============================================================================\n\nnamespace Guardrails {\n // =========================================================================\n // Entity Types \u2014 ReBAC Hierarchy\n // =========================================================================\n // Entity hierarchy enables Cedar's `in` operator for policy scoping:\n // Account (org root)\n // \u2514\u2500\u2500 Project in [Account]\n // \u251C\u2500\u2500 App in [Project]\n // \u2502 \u2514\u2500\u2500 Session in [App, Agent]\n // \u2514\u2500\u2500 Agent in [Project]\n // \u2514\u2500\u2500 Session in [App, Agent]\n //\n // Policy scoping examples:\n // resource == Guardrails::App::\"<uuid>\" \u2192 app-scoped (app only)\n // resource == Guardrails::Agent::\"<agent_id>\" \u2192 agent-only (exact match)\n // resource in Guardrails::Agent::\"<agent_id>\" \u2192 agent + its sessions\n // resource in Guardrails::Project::\"<uuid>\" \u2192 project-wide (apps + agents)\n // resource in Guardrails::Account::\"<uuid>\" \u2192 org-wide\n // =========================================================================\n\n /// Account represents an organization (top-level tenant)\n entity Account;\n\n /// Project represents a project within an account\n entity Project in [Account];\n\n /// User represents a principal (human or service) making requests\n entity User;\n\n /// Agent represents an AI agent (Claude, Cursor, Copilot, etc.) making requests.\n /// Used as both principal (who is acting) and resource (policy scoping target).\n /// Agent + sessions: resource in Guardrails::Agent::\"<agent_id>\" (hierarchy match)\n /// Agent only: resource == Guardrails::Agent::\"<agent_id>\" (exact match)\n entity Agent in [Project];\n\n /// App represents a protected application (guardrails-enabled LLM app)\n entity App in [Project];\n\n /// Session represents an agentic conversation session with state tracking.\n /// Sessions can belong to either an App or an Agent.\n entity Session in [App, Agent];\n\n // =========================================================================\n // Actions\n // =========================================================================\n\n /// Process user prompts and AI responses for security threats and content violations\n action \"process_prompt\" appliesTo {\n principal: [User, Agent],\n resource: [App, Agent, Session],\n context: ProcessPromptContext\n };\n\n /// Execute tool calls (shell, file operations, MCP tools)\n action \"call_tool\" appliesTo {\n principal: [User, Agent],\n resource: [Agent, Session],\n context: CallToolContext\n };\n\n /// Read file operations\n action \"read_file\" appliesTo {\n principal: [User, Agent],\n resource: [Agent, Session],\n context: FileReadContext\n };\n\n /// Write file operations\n action \"write_file\" appliesTo {\n principal: [User, Agent],\n resource: [Agent, Session],\n context: FileWriteContext\n };\n\n /// Connect to an MCP server\n action \"connect_server\" appliesTo {\n principal: [User, Agent],\n resource: [Agent, Session],\n context: ConnectServerContext\n };\n\n // =========================================================================\n // Context Types (Action-Specific)\n // =========================================================================\n\n /// Context for process_prompt action (user prompts & AI responses)\n type ProcessPromptContext = {\n // Core metadata (required)\n \"request_id\": String,\n \"timestamp\": Long,\n \"direction\": String, // \"input\" | \"output\"\n \"content_type\": String, // \"prompt\" | \"response\" | \"tool_call\" | \"file\"\n \"detector_count\": Long,\n\n // Security - Injection & Jailbreak (optional)\n \"injection_confidence\"?: Long, // Combined injection confidence: MAX(pulse, deep_context)\n \"jailbreak_confidence\"?: Long, // Combined jailbreak confidence: MAX(pulse, deep_context)\n \"injection_pulse_score\"?: Long, // 0-100 Pulse single-turn classifier\n \"injection_deep_context_score\"?: Long, // 0-100 DeepContext multi-turn\n \"jailbreak_pulse_score\"?: Long, // 0-100 Pulse single-turn classifier\n \"jailbreak_deep_context_score\"?: Long, // 0-100 DeepContext multi-turn\n \"injection_type\"?: String, // \"prompt\" | \"sql\" | \"command\" | \"none\"\n\n // Privacy - Secrets (optional)\n \"contains_secrets\"?: Bool,\n \"secret_count\"?: Long,\n \"secret_types\"?: Set<String>, // [\"aws_access_key\", \"github_token\", ...]\n\n // Privacy - PII (optional)\n \"pii_detected\"?: Bool,\n \"pii_count\"?: Long,\n \"pii_types\"?: Set<String>, // [\"email\", \"phone\", \"ssn\", \"credit_card\", ...]\n \"pii_confidence\"?: Long, // PII ML classifier confidence (0-100) \u2014 catches novel PII patterns that escape regex detection\n\n // Threat Severity Aggregation (optional)\n \"highest_severity\"?: String, // Highest severity across all detectors: \"critical\" | \"high\" | \"medium\" | \"low\" | \"none\"\n\n // Trust & Safety - Toxicity (optional)\n \"violence_score\"?: Long, // 0-100\n \"hate_speech_score\"?: Long, // 0-100\n \"sexual_score\"?: Long, // 0-100\n \"weapons_score\"?: Long, // 0-100\n \"crime_score\"?: Long, // 0-100\n \"profanity_score\"?: Long, // 0-100\n\n // Semantic - Topic Classification (optional)\n \"content_topics\"?: Set<String>, // [\"controlled_substances\", \"weapons_manufacturing\", ...]\n \"topic_confidence\"?: Long, // 0-100\n\n // Security - Invisible Character Detection (optional)\n \"contains_invisible_chars\"?: Bool,\n \"invisible_chars_score\"?: Long, // 0-100\n\n // Security - Pattern Detection (optional)\n \"command_injection_detected\"?: Bool,\n \"command_injection_type\"?: String, // \"reverse_shell\" | \"privilege_escalation\" | \"code_execution\" | \"destructive_command\" | \"data_exfiltration\"\n \"command_injection_score\"?: Long, // 0-100\n \"path_traversal_detected\"?: Bool,\n \"path_traversal_severity\"?: String, // \"critical\" | \"high\" | \"medium\" | \"low\" | \"none\"\n \"path_traversal_type\"?: String,\n \"sql_injection_detected\"?: Bool,\n \"sql_injection_type\"?: String, // \"tautology\" | \"union_based\" | \"destructive\" | \"blind\" | \"error_based\"\n \"sql_injection_score\"?: Long, // 0-100\n\n // Security - Cross-Origin Escalation (optional)\n \"cross_origin_detected\"?: Bool,\n \"cross_origin_type\"?: String, // \"cross_origin_tool\" | \"cross_origin_server\" | \"none\"\n \"cross_origin_score\"?: Long, // 0-100\n\n // Security - Encoded Injection (optional)\n \"encoded_content_detected\"?: Bool,\n \"encoded_types\"?: Set<String>, // [\"base64\", \"hex\", \"unicode\", \"url\", ...]\n \"encoded_count\"?: Long,\n \"encoded_score\"?: Long, // 0-100\n\n // Language & Script Detection (optional)\n \"detected_language\"?: String, // ISO language code\n \"is_english\"?: Bool,\n \"language_confidence\"?: Long, // 0-100\n \"detected_script\"?: String, // \"latin\" | \"cyrillic\" | \"arabic\" | \"unknown\" | ...\n \"is_latin_script\"?: Bool,\n \"script_confidence\"?: Long, // 0-100\n\n // Content Analysis (optional)\n \"hallucination_score\"?: Long,\n \"factuality_score\"?: Long, // 0-100\n \"sentiment_score\"?: Long,\n \"contains_code\"?: Bool,\n \"code_languages\"?: Set<String>,\n \"code_ratio\"?: Long, // 0-100, percentage of content that is code\n \"keyword_matched\"?: Bool,\n \"keyword_categories\"?: Set<String>,\n \"keyword_count\"?: Long,\n \"contains_non_ascii\"?: Bool,\n \"phishing_detected\"?: Bool,\n \"content_safety_score\"?: Long, // 0-100\n \"content_safety_blocked\"?: Bool,\n\n // Agentic - Multi-Turn Context (optional)\n \"conversation_turn\"?: Long,\n \"multi_turn_detection\"?: Bool,\n\n // Session Detection History \u2014 cross-turn sticky flags (optional)\n \"session_pii_detected\"?: Bool,\n \"session_pii_types\"?: Set<String>,\n \"session_secrets_detected\"?: Bool,\n \"session_secret_types\"?: Set<String>,\n \"session_injection_detected\"?: Bool,\n \"session_command_injection\"?: Bool,\n \"session_threat_turns\"?: Long,\n \"session_max_injection_score\"?: Long,\n \"session_max_jailbreak_score\"?: Long,\n \"session_max_command_injection_score\"?: Long,\n \"session_max_pii_score\"?: Long,\n \"session_max_secret_score\"?: Long,\n \"session_cumulative_risk_score\"?: Long,\n\n // Agent Identity \u2014 authenticated agent principal metadata (optional)\n // Present when the request is made by an AI agent (API key or JWT with agent claims).\n // Empty strings for human user requests. Use these to write agent-specific policies.\n \"agent_id\"?: String, // Unique agent identifier (e.g., \"agent_research_v3\")\n \"agent_type\"?: String, // \"orchestrator\" | \"autonomous\" | \"tool_agent\" | \"human_proxy\"\n \"agent_trust_level\"?: String, // \"first_party\" | \"verified_third_party\" | \"unverified\"\n \"agent_framework\"?: String, // Agent framework (e.g., \"claude-code\", \"langchain\", \"crewai\")\n \"agent_publisher\"?: String, // Organization that published the agent\n\n };\n\n /// Context for call_tool action (agentic tool execution)\n type CallToolContext = {\n // Core metadata (required)\n \"request_id\": String,\n \"timestamp\": Long,\n\n // Tool Risk (optional)\n \"tool_name\"?: String, // \"shell\", \"write_file\", \"http_post\", etc.\n \"tool_risk_score\"?: Long, // 0-100\n \"tool_is_sensitive\"?: Bool,\n \"tool_category\"?: String, // \"safe\" | \"sensitive\" | \"dangerous\"\n \"tool_is_builtin\"?: Bool,\n\n // MCP context (optional \u2014 only present for MCP tool calls)\n \"mcp_server\"?: String, // MCP server name (e.g., \"github\", \"filesystem\")\n \"mcp_tool\"?: String, // MCP tool name within the server\n \"mcp_server_verified\"?: Bool, // Whether server is from verified registry\n\n // Agentic - Behavioral Patterns (optional)\n \"suspicious_pattern\"?: Bool,\n \"pattern_type\"?: String, // \"data_exfiltration\" | \"secret_exfiltration\" | \"db_exfiltration\" | \"credential_theft\" | \"destructive_sequence\" | \"none\"\n \"sequence_risk\"?: Long, // 0-100\n\n // Agentic - Loop Detection (optional)\n \"loop_detected\"?: Bool,\n \"loop_count\"?: Long,\n \"loop_tool\"?: String,\n\n // Agentic - Budget Control (optional)\n \"budget_remaining_pct\"?: Long, // 0-100\n \"budget_exceeded\"?: Bool,\n\n // Semantic - Topic Classification (optional)\n \"content_topics\"?: Set<String>, // [\"controlled_substances\", \"weapons_manufacturing\", ...]\n \"topic_confidence\"?: Long, // 0-100\n\n // Security checks on tool arguments (optional)\n \"contains_secrets\"?: Bool,\n \"secret_count\"?: Long,\n \"secret_types\"?: Set<String>,\n \"pii_detected\"?: Bool,\n \"pii_types\"?: Set<String>,\n \"pii_count\"?: Long, // Number of PII pattern matches in tool content\n \"pii_confidence\"?: Long, // PII ML classifier confidence (0-100)\n \"injection_confidence\"?: Long,\n \"injection_pulse_score\"?: Long, // 0-100 Pulse single-turn classifier\n \"injection_deep_context_score\"?: Long, // 0-100 DeepContext multi-turn\n\n // Security - Pattern Detection (optional)\n \"command_injection_detected\"?: Bool,\n \"command_injection_type\"?: String,\n \"command_injection_score\"?: Long, // 0-100\n \"path_traversal_detected\"?: Bool,\n \"path_traversal_severity\"?: String,\n \"path_traversal_type\"?: String,\n \"sql_injection_detected\"?: Bool,\n \"sql_injection_type\"?: String,\n \"sql_injection_score\"?: Long, // 0-100\n\n // Security - Cross-Origin Escalation (optional)\n \"cross_origin_detected\"?: Bool,\n \"cross_origin_type\"?: String,\n \"cross_origin_score\"?: Long, // 0-100\n\n // File & Path (optional \u2014 for path-based access control policies)\n \"path\"?: String, // File path when tool operates on files\n\n // Security - Invisible Character Detection in tool args (optional)\n \"contains_invisible_chars\"?: Bool, // Whether invisible Unicode chars detected in tool args\n \"invisible_chars_score\"?: Long, // Invisible character attack severity (0-100)\n\n // Security - Encoded Injection (optional)\n \"encoded_content_detected\"?: Bool,\n \"encoded_types\"?: Set<String>,\n \"encoded_count\"?: Long,\n \"encoded_score\"?: Long, // 0-100\n\n // Agentic - Agent Security (optional)\n \"tool_poisoning_detected\"?: Bool,\n \"tool_poisoning_score\"?: Long, // 0-100\n \"tool_poisoning_type\"?: String, // \"hidden_instructions\" | \"system_prompt_injection\" | \"authority_hijack\"\n \"rug_pull_detected\"?: Bool,\n \"rug_pull_score\"?: Long, // 0-100\n \"rug_pull_type\"?: String, // \"risk_spike\" | \"pattern_change\" | \"combined\" | \"none\"\n\n // Agentic - Indirect Prompt Injection (optional \u2014 injection via tool outputs/retrieved content)\n \"indirect_injection_score\"?: Long, // Indirect injection risk score (0-100)\n \"indirect_injection_type\"?: String, // Type of indirect injection detected\n\n // Agentic - MCP Risk (optional)\n \"mcp_config_risk\"?: Bool,\n \"mcp_risk_type\"?: String, // \"inline_execution\" | \"suspicious_url\" | \"cross_origin\"\n \"mcp_risk_score\"?: Long, // 0-100\n\n // Agentic - Multi-Turn Context (optional)\n \"conversation_turn\"?: Long,\n \"multi_turn_detection\"?: Bool,\n\n // Session Detection History \u2014 cross-turn sticky flags (optional)\n \"session_pii_detected\"?: Bool,\n \"session_pii_types\"?: Set<String>,\n \"session_secrets_detected\"?: Bool,\n \"session_secret_types\"?: Set<String>,\n \"session_injection_detected\"?: Bool,\n \"session_command_injection\"?: Bool,\n \"session_threat_turns\"?: Long,\n \"session_max_injection_score\"?: Long,\n \"session_max_jailbreak_score\"?: Long,\n \"session_max_command_injection_score\"?: Long,\n \"session_max_pii_score\"?: Long,\n \"session_max_secret_score\"?: Long,\n \"session_cumulative_risk_score\"?: Long,\n\n // Agent Identity \u2014 authenticated agent principal metadata (optional)\n \"agent_id\"?: String,\n \"agent_type\"?: String,\n \"agent_trust_level\"?: String,\n \"agent_framework\"?: String,\n \"agent_publisher\"?: String,\n\n };\n\n /// Context for read_file action\n type FileReadContext = {\n // Core metadata (required)\n \"request_id\": String,\n \"timestamp\": Long,\n\n // File path (optional \u2014 for path-based access control policies)\n \"path\"?: String, // File path being read\n\n // Security checks on file content (optional)\n \"contains_secrets\"?: Bool,\n \"secret_count\"?: Long,\n \"secret_types\"?: Set<String>,\n \"pii_detected\"?: Bool,\n \"pii_types\"?: Set<String>,\n\n // Security - Path Traversal (optional)\n \"path_traversal_detected\"?: Bool,\n \"path_traversal_severity\"?: String,\n \"path_traversal_type\"?: String,\n\n // Session Detection History \u2014 cross-turn sticky flags (optional)\n \"session_pii_detected\"?: Bool,\n \"session_pii_types\"?: Set<String>,\n \"session_secrets_detected\"?: Bool,\n \"session_secret_types\"?: Set<String>,\n \"session_injection_detected\"?: Bool,\n \"session_command_injection\"?: Bool,\n \"session_threat_turns\"?: Long,\n \"session_max_injection_score\"?: Long,\n \"session_max_jailbreak_score\"?: Long,\n \"session_max_command_injection_score\"?: Long,\n \"session_max_pii_score\"?: Long,\n \"session_max_secret_score\"?: Long,\n \"session_cumulative_risk_score\"?: Long,\n\n // Agent Identity \u2014 authenticated agent principal metadata (optional)\n \"agent_id\"?: String,\n \"agent_type\"?: String,\n \"agent_trust_level\"?: String,\n \"agent_framework\"?: String,\n \"agent_publisher\"?: String,\n\n };\n\n /// Context for write_file action\n type FileWriteContext = {\n // Core metadata (required)\n \"request_id\": String,\n \"timestamp\": Long,\n\n // File path (optional \u2014 for path-based access control policies)\n \"path\"?: String, // File path being written\n\n // Security - Invisible Character Detection in write content (optional)\n \"contains_invisible_chars\"?: Bool, // Whether invisible Unicode chars detected in write content\n \"invisible_chars_score\"?: Long, // Invisible character attack severity (0-100)\n\n // Security checks on content being written (optional)\n \"contains_secrets\"?: Bool,\n \"secret_count\"?: Long,\n \"secret_types\"?: Set<String>,\n \"pii_detected\"?: Bool,\n \"pii_types\"?: Set<String>,\n\n // Security - Path Traversal (optional)\n \"path_traversal_detected\"?: Bool,\n \"path_traversal_severity\"?: String,\n \"path_traversal_type\"?: String,\n\n // Session Detection History \u2014 cross-turn sticky flags (optional)\n \"session_pii_detected\"?: Bool,\n \"session_pii_types\"?: Set<String>,\n \"session_secrets_detected\"?: Bool,\n \"session_secret_types\"?: Set<String>,\n \"session_injection_detected\"?: Bool,\n \"session_command_injection\"?: Bool,\n \"session_threat_turns\"?: Long,\n \"session_max_injection_score\"?: Long,\n \"session_max_jailbreak_score\"?: Long,\n \"session_max_command_injection_score\"?: Long,\n \"session_max_pii_score\"?: Long,\n \"session_max_secret_score\"?: Long,\n \"session_cumulative_risk_score\"?: Long,\n\n // Agent Identity \u2014 authenticated agent principal metadata (optional)\n \"agent_id\"?: String,\n \"agent_type\"?: String,\n \"agent_trust_level\"?: String,\n \"agent_framework\"?: String,\n \"agent_publisher\"?: String,\n\n };\n\n /// Context for connect_server action (MCP server connections)\n type ConnectServerContext = {\n // Core metadata (required)\n \"request_id\": String,\n \"timestamp\": Long,\n\n // MCP context (optional)\n \"mcp_server\"?: String, // MCP server name (e.g., \"github\", \"filesystem\")\n \"mcp_server_verified\"?: Bool, // Whether server is from verified registry\n\n // Agentic - Agent Security (optional)\n \"tool_poisoning_detected\"?: Bool,\n \"tool_poisoning_score\"?: Long,\n \"tool_poisoning_type\"?: String,\n\n // Agentic - MCP Risk (optional)\n \"mcp_config_risk\"?: Bool,\n \"mcp_risk_type\"?: String,\n \"mcp_risk_score\"?: Long,\n\n // Security - Cross-Origin Escalation (optional)\n \"cross_origin_detected\"?: Bool,\n \"cross_origin_type\"?: String,\n \"cross_origin_score\"?: Long,\n\n // Session Detection History \u2014 cross-turn sticky flags (optional)\n \"session_pii_detected\"?: Bool,\n \"session_pii_types\"?: Set<String>,\n \"session_secrets_detected\"?: Bool,\n \"session_secret_types\"?: Set<String>,\n \"session_injection_detected\"?: Bool,\n \"session_command_injection\"?: Bool,\n \"session_threat_turns\"?: Long,\n \"session_max_injection_score\"?: Long,\n \"session_max_jailbreak_score\"?: Long,\n \"session_max_command_injection_score\"?: Long,\n \"session_max_pii_score\"?: Long,\n \"session_max_secret_score\"?: Long,\n \"session_cumulative_risk_score\"?: Long,\n\n // Agent Identity \u2014 authenticated agent principal metadata (optional)\n \"agent_id\"?: String,\n \"agent_type\"?: String,\n \"agent_trust_level\"?: String,\n \"agent_framework\"?: String,\n \"agent_publisher\"?: String,\n\n };\n}\n";
|
|
12
|
+
export declare const GUARDRAILS_SCHEMA = "// =============================================================================\n// Guardrails Cedar Schema\n// =============================================================================\n// Defines entity types, actions, and context attributes for the highflame-shield\n// guardrails service. This schema enables type-safe policy authoring and\n// validation in both Studio UI and backend.\n//\n// Service: highflame-shield (guardrails)\n// Namespace: Guardrails\n// =============================================================================\n\nnamespace Guardrails {\n // =========================================================================\n // Entity Types \u2014 ReBAC Hierarchy\n // =========================================================================\n // Entity hierarchy enables Cedar's `in` operator for policy scoping:\n // Account (org root)\n // \u2514\u2500\u2500 Project in [Account]\n // \u251C\u2500\u2500 App in [Project]\n // \u2502 \u2514\u2500\u2500 Session in [App, Agent]\n // \u2514\u2500\u2500 Agent in [Project]\n // \u2514\u2500\u2500 Session in [App, Agent]\n //\n // Policy scoping examples:\n // resource == Guardrails::App::\"<uuid>\" \u2192 app-scoped (app only)\n // resource == Guardrails::Agent::\"<agent_id>\" \u2192 agent-only (exact match)\n // resource in Guardrails::Agent::\"<agent_id>\" \u2192 agent + its sessions\n // resource in Guardrails::Project::\"<uuid>\" \u2192 project-wide (apps + agents)\n // resource in Guardrails::Account::\"<uuid>\" \u2192 org-wide\n // =========================================================================\n\n /// Account represents an organization (top-level tenant)\n entity Account;\n\n /// Project represents a project within an account\n entity Project in [Account];\n\n /// User represents a principal (human or service) making requests\n entity User;\n\n /// Agent represents an AI agent (Claude, Cursor, Copilot, etc.) making requests.\n /// Used as both principal (who is acting) and resource (policy scoping target).\n /// Agent + sessions: resource in Guardrails::Agent::\"<agent_id>\" (hierarchy match)\n /// Agent only: resource == Guardrails::Agent::\"<agent_id>\" (exact match)\n entity Agent in [Project];\n\n /// App represents a protected application (guardrails-enabled LLM app)\n entity App in [Project];\n\n /// Session represents an agentic conversation session with state tracking.\n /// Sessions can belong to either an App or an Agent.\n entity Session in [App, Agent];\n\n // =========================================================================\n // Actions\n // =========================================================================\n\n /// Process user prompts and AI responses for security threats and content violations\n action \"process_prompt\" appliesTo {\n principal: [User, Agent],\n resource: [App, Agent, Session],\n context: ProcessPromptContext\n };\n\n /// Execute tool calls (shell, file operations, MCP tools)\n action \"call_tool\" appliesTo {\n principal: [User, Agent],\n resource: [Agent, Session],\n context: CallToolContext\n };\n\n /// Read file operations\n action \"read_file\" appliesTo {\n principal: [User, Agent],\n resource: [Agent, Session],\n context: FileReadContext\n };\n\n /// Write file operations\n action \"write_file\" appliesTo {\n principal: [User, Agent],\n resource: [Agent, Session],\n context: FileWriteContext\n };\n\n /// Connect to an MCP server\n action \"connect_server\" appliesTo {\n principal: [User, Agent],\n resource: [Agent, Session],\n context: ConnectServerContext\n };\n\n // =========================================================================\n // Context Types (Action-Specific)\n // =========================================================================\n\n /// Context for process_prompt action (user prompts & AI responses)\n type ProcessPromptContext = {\n // Core metadata (required)\n \"request_id\": String,\n \"timestamp\": Long,\n \"direction\": String, // \"input\" | \"output\"\n \"content_type\": String, // \"prompt\" | \"response\" | \"tool_call\" | \"file\"\n \"detector_count\": Long,\n\n // Security - Injection & Jailbreak (optional)\n \"injection_confidence\"?: Long, // Combined injection confidence: MAX(pulse, deep_context)\n \"jailbreak_confidence\"?: Long, // Combined jailbreak confidence: MAX(pulse, deep_context)\n \"injection_pulse_score\"?: Long, // 0-100 Pulse single-turn classifier\n \"injection_deep_context_score\"?: Long, // 0-100 DeepContext multi-turn\n \"jailbreak_pulse_score\"?: Long, // 0-100 Pulse single-turn classifier\n \"jailbreak_deep_context_score\"?: Long, // 0-100 DeepContext multi-turn\n \"injection_type\"?: String, // \"prompt\" | \"sql\" | \"command\" | \"none\"\n\n // Privacy - Secrets (optional)\n \"contains_secrets\"?: Bool,\n \"secret_count\"?: Long,\n \"secret_types\"?: Set<String>, // [\"aws_access_key\", \"github_token\", ...]\n\n // Privacy - PII (optional)\n \"pii_detected\"?: Bool,\n \"pii_count\"?: Long,\n \"pii_types\"?: Set<String>, // [\"email\", \"phone\", \"ssn\", \"credit_card\", ...]\n \"pii_confidence\"?: Long, // PII ML classifier confidence (0-100) \u2014 catches novel PII patterns that escape regex detection\n\n // Threat Severity Aggregation (optional)\n \"highest_severity\"?: String, // Highest severity across all detectors: \"critical\" | \"high\" | \"medium\" | \"low\" | \"none\"\n\n // Trust & Safety - Toxicity (optional)\n \"violence_score\"?: Long, // 0-100\n \"hate_speech_score\"?: Long, // 0-100\n \"sexual_score\"?: Long, // 0-100\n \"weapons_score\"?: Long, // 0-100\n \"crime_score\"?: Long, // 0-100\n \"profanity_score\"?: Long, // 0-100\n\n // Semantic - Topic Classification (optional)\n \"content_topics\"?: Set<String>, // [\"controlled_substances\", \"weapons_manufacturing\", ...]\n \"topic_confidence\"?: Long, // 0-100\n\n // Security - Invisible Character Detection (optional)\n \"contains_invisible_chars\"?: Bool,\n \"invisible_chars_score\"?: Long, // 0-100\n\n // Security - Pattern Detection (optional)\n \"command_injection_detected\"?: Bool,\n \"command_injection_type\"?: String, // \"reverse_shell\" | \"privilege_escalation\" | \"code_execution\" | \"destructive_command\" | \"data_exfiltration\"\n \"command_injection_score\"?: Long, // 0-100\n \"path_traversal_detected\"?: Bool,\n \"path_traversal_severity\"?: String, // \"critical\" | \"high\" | \"medium\" | \"low\" | \"none\"\n \"path_traversal_type\"?: String,\n \"sql_injection_detected\"?: Bool,\n \"sql_injection_type\"?: String, // \"tautology\" | \"union_based\" | \"destructive\" | \"blind\" | \"error_based\"\n \"sql_injection_score\"?: Long, // 0-100\n\n // Security - Cross-Origin Escalation (optional)\n \"cross_origin_detected\"?: Bool,\n \"cross_origin_type\"?: String, // \"cross_origin_tool\" | \"cross_origin_server\" | \"none\"\n \"cross_origin_score\"?: Long, // 0-100\n\n // Security - Encoded Injection (optional)\n \"encoded_content_detected\"?: Bool,\n \"encoded_types\"?: Set<String>, // [\"base64\", \"hex\", \"unicode\", \"url\", ...]\n \"encoded_count\"?: Long,\n \"encoded_score\"?: Long, // 0-100\n\n // Language & Script Detection (optional)\n \"detected_language\"?: String, // ISO language code\n \"is_english\"?: Bool,\n \"language_confidence\"?: Long, // 0-100\n \"detected_script\"?: String, // \"latin\" | \"cyrillic\" | \"arabic\" | \"unknown\" | ...\n \"is_latin_script\"?: Bool,\n \"script_confidence\"?: Long, // 0-100\n\n // Content Analysis (optional)\n \"hallucination_score\"?: Long,\n \"factuality_score\"?: Long, // 0-100\n \"sentiment_score\"?: Long,\n \"contains_code\"?: Bool,\n \"code_languages\"?: Set<String>,\n \"code_ratio\"?: Long, // 0-100, percentage of content that is code\n \"keyword_matched\"?: Bool,\n \"keyword_categories\"?: Set<String>,\n \"keyword_count\"?: Long,\n \"contains_non_ascii\"?: Bool,\n \"phishing_detected\"?: Bool,\n \"content_safety_score\"?: Long, // 0-100\n \"content_safety_blocked\"?: Bool,\n\n // Agentic - Multi-Turn Context (optional)\n \"conversation_turn\"?: Long,\n \"multi_turn_detection\"?: Bool,\n\n // Session Detection History \u2014 cross-turn sticky flags (optional)\n \"session_pii_detected\"?: Bool,\n \"session_pii_types\"?: Set<String>,\n \"session_secrets_detected\"?: Bool,\n \"session_secret_types\"?: Set<String>,\n \"session_injection_detected\"?: Bool,\n \"session_command_injection\"?: Bool,\n \"session_threat_turns\"?: Long,\n \"session_max_injection_score\"?: Long,\n \"session_max_jailbreak_score\"?: Long,\n \"session_max_command_injection_score\"?: Long,\n \"session_max_pii_score\"?: Long,\n \"session_max_secret_score\"?: Long,\n \"session_cumulative_risk_score\"?: Long,\n\n // Usage Budget \u2014 multi-window token & cost enforcement (optional)\n // Emitted by usage_budget detector. Enforced across session/daily/monthly windows\n // and user/app/project/account dimensions. Percentages are 0-100.\n \"budget_remaining_pct\"?: Long, // Min remaining % across all windows\n \"budget_exceeded\"?: Bool, // Any window limit exceeded\n \"budget_cost_micros_this_turn\"?: Long, // Cost of this request in microdollars (USD * 1e6)\n \"budget_model\"?: String, // Model name used for cost calculation\n \"budget_tokens_pct_session\"?: Long, // Session token usage % (0-100)\n \"budget_tokens_pct_daily\"?: Long, // Daily token usage % (0-100)\n \"budget_tokens_pct_monthly\"?: Long, // Monthly token usage % (0-100)\n \"budget_cost_pct_daily\"?: Long, // Daily cost usage % (0-100)\n \"budget_cost_pct_monthly\"?: Long, // Monthly cost usage % (0-100)\n \"budget_exceeded_session\"?: Bool, // Session-scoped budget exceeded\n \"budget_exceeded_daily\"?: Bool, // Any daily-scoped budget exceeded\n \"budget_exceeded_monthly\"?: Bool, // Any monthly-scoped budget exceeded\n\n // Agent Identity \u2014 authenticated agent principal metadata (optional)\n // Present when the request is made by an AI agent (API key or JWT with agent claims).\n // Empty strings for human user requests. Use these to write agent-specific policies.\n \"agent_id\"?: String, // Unique agent identifier (e.g., \"agent_research_v3\")\n \"agent_type\"?: String, // \"orchestrator\" | \"autonomous\" | \"tool_agent\" | \"human_proxy\"\n \"agent_trust_level\"?: String, // \"first_party\" | \"verified_third_party\" | \"unverified\"\n \"agent_framework\"?: String, // Agent framework (e.g., \"claude-code\", \"langchain\", \"crewai\")\n \"agent_publisher\"?: String, // Organization that published the agent\n\n };\n\n /// Context for call_tool action (agentic tool execution)\n type CallToolContext = {\n // Core metadata (required)\n \"request_id\": String,\n \"timestamp\": Long,\n\n // Tool Risk (optional)\n \"tool_name\"?: String, // \"shell\", \"write_file\", \"http_post\", etc.\n \"tool_risk_score\"?: Long, // 0-100\n \"tool_is_sensitive\"?: Bool,\n \"tool_category\"?: String, // \"safe\" | \"sensitive\" | \"dangerous\"\n \"tool_is_builtin\"?: Bool,\n\n // MCP context (optional \u2014 only present for MCP tool calls)\n \"mcp_server\"?: String, // MCP server name (e.g., \"github\", \"filesystem\")\n \"mcp_tool\"?: String, // MCP tool name within the server\n \"mcp_server_verified\"?: Bool, // Whether server is from verified registry\n\n // Agentic - Behavioral Patterns (optional)\n \"suspicious_pattern\"?: Bool,\n \"pattern_type\"?: String, // \"data_exfiltration\" | \"secret_exfiltration\" | \"db_exfiltration\" | \"credential_theft\" | \"destructive_sequence\" | \"none\"\n \"sequence_risk\"?: Long, // 0-100\n\n // Agentic - Loop Detection (optional)\n \"loop_detected\"?: Bool,\n \"loop_count\"?: Long,\n \"loop_tool\"?: String,\n\n // Usage Budget \u2014 multi-window token & cost enforcement (optional)\n // See ProcessPromptContext for full documentation.\n \"budget_remaining_pct\"?: Long, // Min remaining % across all windows\n \"budget_exceeded\"?: Bool, // Any window limit exceeded\n \"budget_cost_micros_this_turn\"?: Long, // Cost of this request in microdollars\n \"budget_model\"?: String,\n \"budget_tokens_pct_session\"?: Long,\n \"budget_tokens_pct_daily\"?: Long,\n \"budget_tokens_pct_monthly\"?: Long,\n \"budget_cost_pct_daily\"?: Long,\n \"budget_cost_pct_monthly\"?: Long,\n \"budget_exceeded_session\"?: Bool,\n \"budget_exceeded_daily\"?: Bool,\n \"budget_exceeded_monthly\"?: Bool,\n\n // Semantic - Topic Classification (optional)\n \"content_topics\"?: Set<String>, // [\"controlled_substances\", \"weapons_manufacturing\", ...]\n \"topic_confidence\"?: Long, // 0-100\n\n // Security checks on tool arguments (optional)\n \"contains_secrets\"?: Bool,\n \"secret_count\"?: Long,\n \"secret_types\"?: Set<String>,\n \"pii_detected\"?: Bool,\n \"pii_types\"?: Set<String>,\n \"pii_count\"?: Long, // Number of PII pattern matches in tool content\n \"pii_confidence\"?: Long, // PII ML classifier confidence (0-100)\n \"injection_confidence\"?: Long,\n \"injection_pulse_score\"?: Long, // 0-100 Pulse single-turn classifier\n \"injection_deep_context_score\"?: Long, // 0-100 DeepContext multi-turn\n\n // Security - Pattern Detection (optional)\n \"command_injection_detected\"?: Bool,\n \"command_injection_type\"?: String,\n \"command_injection_score\"?: Long, // 0-100\n \"path_traversal_detected\"?: Bool,\n \"path_traversal_severity\"?: String,\n \"path_traversal_type\"?: String,\n \"sql_injection_detected\"?: Bool,\n \"sql_injection_type\"?: String,\n \"sql_injection_score\"?: Long, // 0-100\n\n // Security - Cross-Origin Escalation (optional)\n \"cross_origin_detected\"?: Bool,\n \"cross_origin_type\"?: String,\n \"cross_origin_score\"?: Long, // 0-100\n\n // File & Path (optional \u2014 for path-based access control policies)\n \"path\"?: String, // File path when tool operates on files\n\n // Security - Invisible Character Detection in tool args (optional)\n \"contains_invisible_chars\"?: Bool, // Whether invisible Unicode chars detected in tool args\n \"invisible_chars_score\"?: Long, // Invisible character attack severity (0-100)\n\n // Security - Encoded Injection (optional)\n \"encoded_content_detected\"?: Bool,\n \"encoded_types\"?: Set<String>,\n \"encoded_count\"?: Long,\n \"encoded_score\"?: Long, // 0-100\n\n // Agentic - Agent Security (optional)\n \"tool_poisoning_detected\"?: Bool,\n \"tool_poisoning_score\"?: Long, // 0-100\n \"tool_poisoning_type\"?: String, // \"hidden_instructions\" | \"system_prompt_injection\" | \"authority_hijack\"\n \"rug_pull_detected\"?: Bool,\n \"rug_pull_score\"?: Long, // 0-100\n \"rug_pull_type\"?: String, // \"risk_spike\" | \"pattern_change\" | \"combined\" | \"none\"\n\n // Agentic - Indirect Prompt Injection (optional \u2014 injection via tool outputs/retrieved content)\n \"indirect_injection_score\"?: Long, // Indirect injection risk score (0-100)\n \"indirect_injection_type\"?: String, // Type of indirect injection detected\n\n // Agentic - MCP Risk (optional)\n \"mcp_config_risk\"?: Bool,\n \"mcp_risk_type\"?: String, // \"inline_execution\" | \"suspicious_url\" | \"cross_origin\"\n \"mcp_risk_score\"?: Long, // 0-100\n\n // Agentic - Multi-Turn Context (optional)\n \"conversation_turn\"?: Long,\n \"multi_turn_detection\"?: Bool,\n\n // Session Detection History \u2014 cross-turn sticky flags (optional)\n \"session_pii_detected\"?: Bool,\n \"session_pii_types\"?: Set<String>,\n \"session_secrets_detected\"?: Bool,\n \"session_secret_types\"?: Set<String>,\n \"session_injection_detected\"?: Bool,\n \"session_command_injection\"?: Bool,\n \"session_threat_turns\"?: Long,\n \"session_max_injection_score\"?: Long,\n \"session_max_jailbreak_score\"?: Long,\n \"session_max_command_injection_score\"?: Long,\n \"session_max_pii_score\"?: Long,\n \"session_max_secret_score\"?: Long,\n \"session_cumulative_risk_score\"?: Long,\n\n // Agent Identity \u2014 authenticated agent principal metadata (optional)\n \"agent_id\"?: String,\n \"agent_type\"?: String,\n \"agent_trust_level\"?: String,\n \"agent_framework\"?: String,\n \"agent_publisher\"?: String,\n\n };\n\n /// Context for read_file action\n type FileReadContext = {\n // Core metadata (required)\n \"request_id\": String,\n \"timestamp\": Long,\n\n // File path (optional \u2014 for path-based access control policies)\n \"path\"?: String, // File path being read\n\n // Security checks on file content (optional)\n \"contains_secrets\"?: Bool,\n \"secret_count\"?: Long,\n \"secret_types\"?: Set<String>,\n \"pii_detected\"?: Bool,\n \"pii_types\"?: Set<String>,\n\n // Security - Path Traversal (optional)\n \"path_traversal_detected\"?: Bool,\n \"path_traversal_severity\"?: String,\n \"path_traversal_type\"?: String,\n\n // Session Detection History \u2014 cross-turn sticky flags (optional)\n \"session_pii_detected\"?: Bool,\n \"session_pii_types\"?: Set<String>,\n \"session_secrets_detected\"?: Bool,\n \"session_secret_types\"?: Set<String>,\n \"session_injection_detected\"?: Bool,\n \"session_command_injection\"?: Bool,\n \"session_threat_turns\"?: Long,\n \"session_max_injection_score\"?: Long,\n \"session_max_jailbreak_score\"?: Long,\n \"session_max_command_injection_score\"?: Long,\n \"session_max_pii_score\"?: Long,\n \"session_max_secret_score\"?: Long,\n \"session_cumulative_risk_score\"?: Long,\n\n // Usage Budget \u2014 multi-window token & cost enforcement (optional)\n // See ProcessPromptContext for full documentation.\n \"budget_remaining_pct\"?: Long,\n \"budget_exceeded\"?: Bool,\n \"budget_cost_micros_this_turn\"?: Long,\n \"budget_model\"?: String,\n \"budget_tokens_pct_session\"?: Long,\n \"budget_tokens_pct_daily\"?: Long,\n \"budget_tokens_pct_monthly\"?: Long,\n \"budget_cost_pct_daily\"?: Long,\n \"budget_cost_pct_monthly\"?: Long,\n \"budget_exceeded_session\"?: Bool,\n \"budget_exceeded_daily\"?: Bool,\n \"budget_exceeded_monthly\"?: Bool,\n\n // Agent Identity \u2014 authenticated agent principal metadata (optional)\n \"agent_id\"?: String,\n \"agent_type\"?: String,\n \"agent_trust_level\"?: String,\n \"agent_framework\"?: String,\n \"agent_publisher\"?: String,\n\n };\n\n /// Context for write_file action\n type FileWriteContext = {\n // Core metadata (required)\n \"request_id\": String,\n \"timestamp\": Long,\n\n // File path (optional \u2014 for path-based access control policies)\n \"path\"?: String, // File path being written\n\n // Security - Invisible Character Detection in write content (optional)\n \"contains_invisible_chars\"?: Bool, // Whether invisible Unicode chars detected in write content\n \"invisible_chars_score\"?: Long, // Invisible character attack severity (0-100)\n\n // Security checks on content being written (optional)\n \"contains_secrets\"?: Bool,\n \"secret_count\"?: Long,\n \"secret_types\"?: Set<String>,\n \"pii_detected\"?: Bool,\n \"pii_types\"?: Set<String>,\n\n // Security - Path Traversal (optional)\n \"path_traversal_detected\"?: Bool,\n \"path_traversal_severity\"?: String,\n \"path_traversal_type\"?: String,\n\n // Session Detection History \u2014 cross-turn sticky flags (optional)\n \"session_pii_detected\"?: Bool,\n \"session_pii_types\"?: Set<String>,\n \"session_secrets_detected\"?: Bool,\n \"session_secret_types\"?: Set<String>,\n \"session_injection_detected\"?: Bool,\n \"session_command_injection\"?: Bool,\n \"session_threat_turns\"?: Long,\n \"session_max_injection_score\"?: Long,\n \"session_max_jailbreak_score\"?: Long,\n \"session_max_command_injection_score\"?: Long,\n \"session_max_pii_score\"?: Long,\n \"session_max_secret_score\"?: Long,\n \"session_cumulative_risk_score\"?: Long,\n\n // Usage Budget \u2014 multi-window token & cost enforcement (optional)\n // See ProcessPromptContext for full documentation.\n \"budget_remaining_pct\"?: Long,\n \"budget_exceeded\"?: Bool,\n \"budget_cost_micros_this_turn\"?: Long,\n \"budget_model\"?: String,\n \"budget_tokens_pct_session\"?: Long,\n \"budget_tokens_pct_daily\"?: Long,\n \"budget_tokens_pct_monthly\"?: Long,\n \"budget_cost_pct_daily\"?: Long,\n \"budget_cost_pct_monthly\"?: Long,\n \"budget_exceeded_session\"?: Bool,\n \"budget_exceeded_daily\"?: Bool,\n \"budget_exceeded_monthly\"?: Bool,\n\n // Agent Identity \u2014 authenticated agent principal metadata (optional)\n \"agent_id\"?: String,\n \"agent_type\"?: String,\n \"agent_trust_level\"?: String,\n \"agent_framework\"?: String,\n \"agent_publisher\"?: String,\n\n };\n\n /// Context for connect_server action (MCP server connections)\n type ConnectServerContext = {\n // Core metadata (required)\n \"request_id\": String,\n \"timestamp\": Long,\n\n // MCP context (optional)\n \"mcp_server\"?: String, // MCP server name (e.g., \"github\", \"filesystem\")\n \"mcp_server_verified\"?: Bool, // Whether server is from verified registry\n\n // Agentic - Agent Security (optional)\n \"tool_poisoning_detected\"?: Bool,\n \"tool_poisoning_score\"?: Long,\n \"tool_poisoning_type\"?: String,\n\n // Agentic - MCP Risk (optional)\n \"mcp_config_risk\"?: Bool,\n \"mcp_risk_type\"?: String,\n \"mcp_risk_score\"?: Long,\n\n // Security - Cross-Origin Escalation (optional)\n \"cross_origin_detected\"?: Bool,\n \"cross_origin_type\"?: String,\n \"cross_origin_score\"?: Long,\n\n // Session Detection History \u2014 cross-turn sticky flags (optional)\n \"session_pii_detected\"?: Bool,\n \"session_pii_types\"?: Set<String>,\n \"session_secrets_detected\"?: Bool,\n \"session_secret_types\"?: Set<String>,\n \"session_injection_detected\"?: Bool,\n \"session_command_injection\"?: Bool,\n \"session_threat_turns\"?: Long,\n \"session_max_injection_score\"?: Long,\n \"session_max_jailbreak_score\"?: Long,\n \"session_max_command_injection_score\"?: Long,\n \"session_max_pii_score\"?: Long,\n \"session_max_secret_score\"?: Long,\n \"session_cumulative_risk_score\"?: Long,\n\n // Usage Budget \u2014 multi-window token & cost enforcement (optional)\n // See ProcessPromptContext for full documentation.\n \"budget_remaining_pct\"?: Long,\n \"budget_exceeded\"?: Bool,\n \"budget_cost_micros_this_turn\"?: Long,\n \"budget_model\"?: String,\n \"budget_tokens_pct_session\"?: Long,\n \"budget_tokens_pct_daily\"?: Long,\n \"budget_tokens_pct_monthly\"?: Long,\n \"budget_cost_pct_daily\"?: Long,\n \"budget_cost_pct_monthly\"?: Long,\n \"budget_exceeded_session\"?: Bool,\n \"budget_exceeded_daily\"?: Bool,\n \"budget_exceeded_monthly\"?: Bool,\n\n // Agent Identity \u2014 authenticated agent principal metadata (optional)\n \"agent_id\"?: String,\n \"agent_type\"?: String,\n \"agent_trust_level\"?: String,\n \"agent_framework\"?: String,\n \"agent_publisher\"?: String,\n\n };\n}\n";
|
|
13
13
|
/**
|
|
14
14
|
* Overwatch Cedar schema
|
|
15
15
|
*
|
|
@@ -154,6 +154,20 @@ action call_tool appliesTo {
|
|
|
154
154
|
suspicious_pattern?: Bool,
|
|
155
155
|
pattern_type?: String,
|
|
156
156
|
sequence_risk?: Long,
|
|
157
|
+
|
|
158
|
+
// --- Usage Budget (multi-window, multi-dimension) ---
|
|
159
|
+
budget_remaining_pct?: Long,
|
|
160
|
+
budget_exceeded?: Bool,
|
|
161
|
+
budget_cost_micros_this_turn?: Long,
|
|
162
|
+
budget_model?: String,
|
|
163
|
+
budget_tokens_pct_session?: Long,
|
|
164
|
+
budget_tokens_pct_daily?: Long,
|
|
165
|
+
budget_tokens_pct_monthly?: Long,
|
|
166
|
+
budget_cost_pct_daily?: Long,
|
|
167
|
+
budget_cost_pct_monthly?: Long,
|
|
168
|
+
budget_exceeded_session?: Bool,
|
|
169
|
+
budget_exceeded_daily?: Bool,
|
|
170
|
+
budget_exceeded_monthly?: Bool,
|
|
157
171
|
},
|
|
158
172
|
};
|
|
159
173
|
|
|
@@ -193,6 +207,20 @@ action connect_server appliesTo {
|
|
|
193
207
|
mcp_server_verified?: Bool,
|
|
194
208
|
mcp_config_risk?: Bool,
|
|
195
209
|
mcp_risk_score?: Long,
|
|
210
|
+
|
|
211
|
+
// --- Usage Budget (multi-window, multi-dimension) ---
|
|
212
|
+
budget_remaining_pct?: Long,
|
|
213
|
+
budget_exceeded?: Bool,
|
|
214
|
+
budget_cost_micros_this_turn?: Long,
|
|
215
|
+
budget_model?: String,
|
|
216
|
+
budget_tokens_pct_session?: Long,
|
|
217
|
+
budget_tokens_pct_daily?: Long,
|
|
218
|
+
budget_tokens_pct_monthly?: Long,
|
|
219
|
+
budget_cost_pct_daily?: Long,
|
|
220
|
+
budget_cost_pct_monthly?: Long,
|
|
221
|
+
budget_exceeded_session?: Bool,
|
|
222
|
+
budget_exceeded_daily?: Bool,
|
|
223
|
+
budget_exceeded_monthly?: Bool,
|
|
196
224
|
},
|
|
197
225
|
};
|
|
198
226
|
|
|
@@ -241,6 +269,20 @@ action process_prompt appliesTo {
|
|
|
241
269
|
// --- LLM-specific ---
|
|
242
270
|
model_name?: String, // Target model name (e.g., "gpt-4", "claude-3-opus")
|
|
243
271
|
model_provider?: String, // Provider name (e.g., "openai", "anthropic", "bedrock")
|
|
272
|
+
|
|
273
|
+
// --- Usage Budget (multi-window, multi-dimension) ---
|
|
274
|
+
budget_remaining_pct?: Long,
|
|
275
|
+
budget_exceeded?: Bool,
|
|
276
|
+
budget_cost_micros_this_turn?: Long,
|
|
277
|
+
budget_model?: String,
|
|
278
|
+
budget_tokens_pct_session?: Long,
|
|
279
|
+
budget_tokens_pct_daily?: Long,
|
|
280
|
+
budget_tokens_pct_monthly?: Long,
|
|
281
|
+
budget_cost_pct_daily?: Long,
|
|
282
|
+
budget_cost_pct_monthly?: Long,
|
|
283
|
+
budget_exceeded_session?: Bool,
|
|
284
|
+
budget_exceeded_daily?: Bool,
|
|
285
|
+
budget_exceeded_monthly?: Bool,
|
|
244
286
|
},
|
|
245
287
|
};
|
|
246
288
|
|
|
@@ -269,6 +311,20 @@ action read_file appliesTo {
|
|
|
269
311
|
pii_detected?: Bool,
|
|
270
312
|
pii_types?: Set<String>,
|
|
271
313
|
pii_count?: Long,
|
|
314
|
+
|
|
315
|
+
// --- Usage Budget (multi-window, multi-dimension) ---
|
|
316
|
+
budget_remaining_pct?: Long,
|
|
317
|
+
budget_exceeded?: Bool,
|
|
318
|
+
budget_cost_micros_this_turn?: Long,
|
|
319
|
+
budget_model?: String,
|
|
320
|
+
budget_tokens_pct_session?: Long,
|
|
321
|
+
budget_tokens_pct_daily?: Long,
|
|
322
|
+
budget_tokens_pct_monthly?: Long,
|
|
323
|
+
budget_cost_pct_daily?: Long,
|
|
324
|
+
budget_cost_pct_monthly?: Long,
|
|
325
|
+
budget_exceeded_session?: Bool,
|
|
326
|
+
budget_exceeded_daily?: Bool,
|
|
327
|
+
budget_exceeded_monthly?: Bool,
|
|
272
328
|
},
|
|
273
329
|
};
|
|
274
330
|
|
|
@@ -297,6 +353,20 @@ action write_file appliesTo {
|
|
|
297
353
|
pii_detected?: Bool,
|
|
298
354
|
pii_types?: Set<String>,
|
|
299
355
|
pii_count?: Long,
|
|
356
|
+
|
|
357
|
+
// --- Usage Budget (multi-window, multi-dimension) ---
|
|
358
|
+
budget_remaining_pct?: Long,
|
|
359
|
+
budget_exceeded?: Bool,
|
|
360
|
+
budget_cost_micros_this_turn?: Long,
|
|
361
|
+
budget_model?: String,
|
|
362
|
+
budget_tokens_pct_session?: Long,
|
|
363
|
+
budget_tokens_pct_daily?: Long,
|
|
364
|
+
budget_tokens_pct_monthly?: Long,
|
|
365
|
+
budget_cost_pct_daily?: Long,
|
|
366
|
+
budget_cost_pct_monthly?: Long,
|
|
367
|
+
budget_exceeded_session?: Bool,
|
|
368
|
+
budget_exceeded_daily?: Bool,
|
|
369
|
+
budget_exceeded_monthly?: Bool,
|
|
300
370
|
},
|
|
301
371
|
};
|
|
302
372
|
|
|
@@ -515,6 +585,22 @@ namespace Guardrails {
|
|
|
515
585
|
"session_max_secret_score"?: Long,
|
|
516
586
|
"session_cumulative_risk_score"?: Long,
|
|
517
587
|
|
|
588
|
+
// Usage Budget — multi-window token & cost enforcement (optional)
|
|
589
|
+
// Emitted by usage_budget detector. Enforced across session/daily/monthly windows
|
|
590
|
+
// and user/app/project/account dimensions. Percentages are 0-100.
|
|
591
|
+
"budget_remaining_pct"?: Long, // Min remaining % across all windows
|
|
592
|
+
"budget_exceeded"?: Bool, // Any window limit exceeded
|
|
593
|
+
"budget_cost_micros_this_turn"?: Long, // Cost of this request in microdollars (USD * 1e6)
|
|
594
|
+
"budget_model"?: String, // Model name used for cost calculation
|
|
595
|
+
"budget_tokens_pct_session"?: Long, // Session token usage % (0-100)
|
|
596
|
+
"budget_tokens_pct_daily"?: Long, // Daily token usage % (0-100)
|
|
597
|
+
"budget_tokens_pct_monthly"?: Long, // Monthly token usage % (0-100)
|
|
598
|
+
"budget_cost_pct_daily"?: Long, // Daily cost usage % (0-100)
|
|
599
|
+
"budget_cost_pct_monthly"?: Long, // Monthly cost usage % (0-100)
|
|
600
|
+
"budget_exceeded_session"?: Bool, // Session-scoped budget exceeded
|
|
601
|
+
"budget_exceeded_daily"?: Bool, // Any daily-scoped budget exceeded
|
|
602
|
+
"budget_exceeded_monthly"?: Bool, // Any monthly-scoped budget exceeded
|
|
603
|
+
|
|
518
604
|
// Agent Identity — authenticated agent principal metadata (optional)
|
|
519
605
|
// Present when the request is made by an AI agent (API key or JWT with agent claims).
|
|
520
606
|
// Empty strings for human user requests. Use these to write agent-specific policies.
|
|
@@ -554,9 +640,20 @@ namespace Guardrails {
|
|
|
554
640
|
"loop_count"?: Long,
|
|
555
641
|
"loop_tool"?: String,
|
|
556
642
|
|
|
557
|
-
//
|
|
558
|
-
|
|
559
|
-
"
|
|
643
|
+
// Usage Budget — multi-window token & cost enforcement (optional)
|
|
644
|
+
// See ProcessPromptContext for full documentation.
|
|
645
|
+
"budget_remaining_pct"?: Long, // Min remaining % across all windows
|
|
646
|
+
"budget_exceeded"?: Bool, // Any window limit exceeded
|
|
647
|
+
"budget_cost_micros_this_turn"?: Long, // Cost of this request in microdollars
|
|
648
|
+
"budget_model"?: String,
|
|
649
|
+
"budget_tokens_pct_session"?: Long,
|
|
650
|
+
"budget_tokens_pct_daily"?: Long,
|
|
651
|
+
"budget_tokens_pct_monthly"?: Long,
|
|
652
|
+
"budget_cost_pct_daily"?: Long,
|
|
653
|
+
"budget_cost_pct_monthly"?: Long,
|
|
654
|
+
"budget_exceeded_session"?: Bool,
|
|
655
|
+
"budget_exceeded_daily"?: Bool,
|
|
656
|
+
"budget_exceeded_monthly"?: Bool,
|
|
560
657
|
|
|
561
658
|
// Semantic - Topic Classification (optional)
|
|
562
659
|
"content_topics"?: Set<String>, // ["controlled_substances", "weapons_manufacturing", ...]
|
|
@@ -684,6 +781,21 @@ namespace Guardrails {
|
|
|
684
781
|
"session_max_secret_score"?: Long,
|
|
685
782
|
"session_cumulative_risk_score"?: Long,
|
|
686
783
|
|
|
784
|
+
// Usage Budget — multi-window token & cost enforcement (optional)
|
|
785
|
+
// See ProcessPromptContext for full documentation.
|
|
786
|
+
"budget_remaining_pct"?: Long,
|
|
787
|
+
"budget_exceeded"?: Bool,
|
|
788
|
+
"budget_cost_micros_this_turn"?: Long,
|
|
789
|
+
"budget_model"?: String,
|
|
790
|
+
"budget_tokens_pct_session"?: Long,
|
|
791
|
+
"budget_tokens_pct_daily"?: Long,
|
|
792
|
+
"budget_tokens_pct_monthly"?: Long,
|
|
793
|
+
"budget_cost_pct_daily"?: Long,
|
|
794
|
+
"budget_cost_pct_monthly"?: Long,
|
|
795
|
+
"budget_exceeded_session"?: Bool,
|
|
796
|
+
"budget_exceeded_daily"?: Bool,
|
|
797
|
+
"budget_exceeded_monthly"?: Bool,
|
|
798
|
+
|
|
687
799
|
// Agent Identity — authenticated agent principal metadata (optional)
|
|
688
800
|
"agent_id"?: String,
|
|
689
801
|
"agent_type"?: String,
|
|
@@ -733,6 +845,21 @@ namespace Guardrails {
|
|
|
733
845
|
"session_max_secret_score"?: Long,
|
|
734
846
|
"session_cumulative_risk_score"?: Long,
|
|
735
847
|
|
|
848
|
+
// Usage Budget — multi-window token & cost enforcement (optional)
|
|
849
|
+
// See ProcessPromptContext for full documentation.
|
|
850
|
+
"budget_remaining_pct"?: Long,
|
|
851
|
+
"budget_exceeded"?: Bool,
|
|
852
|
+
"budget_cost_micros_this_turn"?: Long,
|
|
853
|
+
"budget_model"?: String,
|
|
854
|
+
"budget_tokens_pct_session"?: Long,
|
|
855
|
+
"budget_tokens_pct_daily"?: Long,
|
|
856
|
+
"budget_tokens_pct_monthly"?: Long,
|
|
857
|
+
"budget_cost_pct_daily"?: Long,
|
|
858
|
+
"budget_cost_pct_monthly"?: Long,
|
|
859
|
+
"budget_exceeded_session"?: Bool,
|
|
860
|
+
"budget_exceeded_daily"?: Bool,
|
|
861
|
+
"budget_exceeded_monthly"?: Bool,
|
|
862
|
+
|
|
736
863
|
// Agent Identity — authenticated agent principal metadata (optional)
|
|
737
864
|
"agent_id"?: String,
|
|
738
865
|
"agent_type"?: String,
|
|
@@ -782,6 +909,21 @@ namespace Guardrails {
|
|
|
782
909
|
"session_max_secret_score"?: Long,
|
|
783
910
|
"session_cumulative_risk_score"?: Long,
|
|
784
911
|
|
|
912
|
+
// Usage Budget — multi-window token & cost enforcement (optional)
|
|
913
|
+
// See ProcessPromptContext for full documentation.
|
|
914
|
+
"budget_remaining_pct"?: Long,
|
|
915
|
+
"budget_exceeded"?: Bool,
|
|
916
|
+
"budget_cost_micros_this_turn"?: Long,
|
|
917
|
+
"budget_model"?: String,
|
|
918
|
+
"budget_tokens_pct_session"?: Long,
|
|
919
|
+
"budget_tokens_pct_daily"?: Long,
|
|
920
|
+
"budget_tokens_pct_monthly"?: Long,
|
|
921
|
+
"budget_cost_pct_daily"?: Long,
|
|
922
|
+
"budget_cost_pct_monthly"?: Long,
|
|
923
|
+
"budget_exceeded_session"?: Bool,
|
|
924
|
+
"budget_exceeded_daily"?: Bool,
|
|
925
|
+
"budget_exceeded_monthly"?: Bool,
|
|
926
|
+
|
|
785
927
|
// Agent Identity — authenticated agent principal metadata (optional)
|
|
786
928
|
"agent_id"?: String,
|
|
787
929
|
"agent_type"?: String,
|