veto-sdk 2.0.0 → 2.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/browser/index.d.ts +1 -1
- package/dist/browser/index.d.ts.map +1 -1
- package/dist/browser/index.js.map +1 -1
- package/dist/browser/types.d.ts +17 -1
- package/dist/browser/types.d.ts.map +1 -1
- package/dist/browser/veto.d.ts +10 -0
- package/dist/browser/veto.d.ts.map +1 -1
- package/dist/browser/veto.js +68 -4
- package/dist/browser/veto.js.map +1 -1
- package/dist/cli/bin.js +0 -0
- package/dist/cloud/types.d.ts +17 -2
- package/dist/cloud/types.d.ts.map +1 -1
- package/dist/core/events.d.ts +11 -1
- package/dist/core/events.d.ts.map +1 -1
- package/dist/core/events.js +4 -0
- package/dist/core/events.js.map +1 -1
- package/dist/core/protect.d.ts +3 -1
- package/dist/core/protect.d.ts.map +1 -1
- package/dist/core/protect.js +14 -4
- package/dist/core/protect.js.map +1 -1
- package/dist/core/veto.d.ts +43 -1
- package/dist/core/veto.d.ts.map +1 -1
- package/dist/core/veto.js +248 -13
- package/dist/core/veto.js.map +1 -1
- package/dist/deterministic/types.d.ts +103 -0
- package/dist/deterministic/types.d.ts.map +1 -1
- package/dist/economic/budget-engine.d.ts +29 -0
- package/dist/economic/budget-engine.d.ts.map +1 -0
- package/dist/economic/budget-engine.js +146 -0
- package/dist/economic/budget-engine.js.map +1 -0
- package/dist/economic/connectors/ap2.d.ts +51 -0
- package/dist/economic/connectors/ap2.d.ts.map +1 -0
- package/dist/economic/connectors/ap2.js +133 -0
- package/dist/economic/connectors/ap2.js.map +1 -0
- package/dist/economic/connectors/index.d.ts +8 -0
- package/dist/economic/connectors/index.d.ts.map +1 -0
- package/dist/economic/connectors/index.js +8 -0
- package/dist/economic/connectors/index.js.map +1 -0
- package/dist/economic/connectors/mpp.d.ts +41 -0
- package/dist/economic/connectors/mpp.d.ts.map +1 -0
- package/dist/economic/connectors/mpp.js +97 -0
- package/dist/economic/connectors/mpp.js.map +1 -0
- package/dist/economic/connectors/x402.d.ts +20 -0
- package/dist/economic/connectors/x402.d.ts.map +1 -0
- package/dist/economic/connectors/x402.js +142 -0
- package/dist/economic/connectors/x402.js.map +1 -0
- package/dist/economic/evaluator.d.ts +77 -0
- package/dist/economic/evaluator.d.ts.map +1 -0
- package/dist/economic/evaluator.js +231 -0
- package/dist/economic/evaluator.js.map +1 -0
- package/dist/economic/index.d.ts +13 -0
- package/dist/economic/index.d.ts.map +1 -0
- package/dist/economic/index.js +15 -0
- package/dist/economic/index.js.map +1 -0
- package/dist/economic/types.d.ts +188 -0
- package/dist/economic/types.d.ts.map +1 -0
- package/dist/economic/types.js +10 -0
- package/dist/economic/types.js.map +1 -0
- package/dist/extractors/content.d.ts +42 -0
- package/dist/extractors/content.d.ts.map +1 -0
- package/dist/extractors/content.js +154 -0
- package/dist/extractors/content.js.map +1 -0
- package/dist/extractors/index.d.ts +7 -0
- package/dist/extractors/index.d.ts.map +1 -0
- package/dist/extractors/index.js +7 -0
- package/dist/extractors/index.js.map +1 -0
- package/dist/index.d.ts +9 -3
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +10 -2
- package/dist/index.js.map +1 -1
- package/dist/policy/generator.d.ts +110 -0
- package/dist/policy/generator.d.ts.map +1 -0
- package/dist/policy/generator.js +463 -0
- package/dist/policy/generator.js.map +1 -0
- package/dist/policy/index.d.ts +7 -0
- package/dist/policy/index.d.ts.map +1 -0
- package/dist/policy/index.js +7 -0
- package/dist/policy/index.js.map +1 -0
- package/dist/providers/adapters.d.ts +27 -0
- package/dist/providers/adapters.d.ts.map +1 -1
- package/dist/providers/adapters.js +58 -0
- package/dist/providers/adapters.js.map +1 -1
- package/dist/rules/index.d.ts +1 -0
- package/dist/rules/index.d.ts.map +1 -1
- package/dist/rules/index.js +1 -0
- package/dist/rules/index.js.map +1 -1
- package/dist/rules/local-evaluator.d.ts +69 -0
- package/dist/rules/local-evaluator.d.ts.map +1 -0
- package/dist/rules/local-evaluator.js +217 -0
- package/dist/rules/local-evaluator.js.map +1 -0
- package/dist/rules/policy-ir-schema.d.ts +109 -0
- package/dist/rules/policy-ir-schema.d.ts.map +1 -1
- package/dist/rules/policy-ir-schema.js +90 -0
- package/dist/rules/policy-ir-schema.js.map +1 -1
- package/dist/rules/policy-packs.d.ts.map +1 -1
- package/dist/rules/policy-packs.js +1 -0
- package/dist/rules/policy-packs.js.map +1 -1
- package/dist/types/config.d.ts +2 -1
- package/dist/types/config.d.ts.map +1 -1
- package/dist/types/config.js.map +1 -1
- package/dist/utils/logger.d.ts +38 -2
- package/dist/utils/logger.d.ts.map +1 -1
- package/dist/utils/logger.js +231 -26
- package/dist/utils/logger.js.map +1 -1
- package/package.json +9 -1
- package/packs/economic-agent.yaml +62 -0
|
@@ -7,6 +7,7 @@
|
|
|
7
7
|
* @module providers/adapters
|
|
8
8
|
*/
|
|
9
9
|
import type { ToolDefinition, ToolCall } from '../types/tool.js';
|
|
10
|
+
import type { EconomicContext } from '../economic/types.js';
|
|
10
11
|
import type { OpenAITool, OpenAIToolCall, AnthropicTool, AnthropicToolUse, GoogleTool, GoogleFunctionDeclaration, GoogleFunctionCall, MCPTool, MCPToolCallArgs } from './types.js';
|
|
11
12
|
/**
|
|
12
13
|
* Convert Veto tool definition to OpenAI format.
|
|
@@ -163,6 +164,32 @@ export declare function toMCPTools(tools: readonly ToolDefinition[]): MCPTool[];
|
|
|
163
164
|
* no `input_schema` (Anthropic) or `function` (OpenAI) properties.
|
|
164
165
|
*/
|
|
165
166
|
export declare function isMCPTool(tool: unknown): tool is MCPTool;
|
|
167
|
+
/**
|
|
168
|
+
* Extract economic context from MCP tool call metadata.
|
|
169
|
+
*
|
|
170
|
+
* MCP servers can include economic metadata in tool call arguments or
|
|
171
|
+
* _meta fields. This function looks for the `economic_context` convention:
|
|
172
|
+
*
|
|
173
|
+
* ```json
|
|
174
|
+
* {
|
|
175
|
+
* "name": "search_api",
|
|
176
|
+
* "arguments": {
|
|
177
|
+
* "query": "...",
|
|
178
|
+
* "_meta": {
|
|
179
|
+
* "economic_context": {
|
|
180
|
+
* "cost": 0.01,
|
|
181
|
+
* "currency": "USD",
|
|
182
|
+
* "protocol": "mpp",
|
|
183
|
+
* "payer": "cus_stripe_123"
|
|
184
|
+
* }
|
|
185
|
+
* }
|
|
186
|
+
* }
|
|
187
|
+
* }
|
|
188
|
+
* ```
|
|
189
|
+
*
|
|
190
|
+
* Returns null if no economic context is found.
|
|
191
|
+
*/
|
|
192
|
+
export declare function extractMCPEconomicContext(toolCall: MCPToolCallArgs): EconomicContext | null;
|
|
166
193
|
/**
|
|
167
194
|
* Adapter interface for converting between formats.
|
|
168
195
|
*/
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"adapters.d.ts","sourceRoot":"","sources":["../../src/providers/adapters.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,OAAO,KAAK,EAAE,cAAc,EAAE,QAAQ,EAAE,MAAM,kBAAkB,CAAC;AACjE,OAAO,KAAK,EAEV,UAAU,EACV,cAAc,EACd,aAAa,EACb,gBAAgB,EAChB,UAAU,EACV,yBAAyB,EACzB,kBAAkB,EAClB,OAAO,EACP,eAAe,EAChB,MAAM,YAAY,CAAC;AAOpB;;;;;;;;;;;;;;GAcG;AACH,wBAAgB,QAAQ,CAAC,IAAI,EAAE,cAAc,GAAG,UAAU,CASzD;AAED;;;;;GAKG;AACH,wBAAgB,UAAU,CAAC,IAAI,EAAE,UAAU,GAAG,cAAc,CAM3D;AAED;;;;;GAKG;AACH,wBAAgB,kBAAkB,CAAC,QAAQ,EAAE,cAAc,GAAG,QAAQ,CAcrE;AAED;;;;;GAKG;AACH,wBAAgB,aAAa,CAAC,KAAK,EAAE,SAAS,cAAc,EAAE,GAAG,UAAU,EAAE,CAE5E;AAMD;;;;;;;;;;;;;;GAcG;AACH,wBAAgB,WAAW,CAAC,IAAI,EAAE,cAAc,GAAG,aAAa,CAM/D;AAED;;;;;GAKG;AAC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eAAe,CAAC,aAAa,EAAE,gBAAgB,CAAC,CAAC;AACpD,wBAAgB,UAAU,CACxB,QAAQ,EAAE,KAAK,GACd,eAAe,CAAC,OAAO,EAAE,eAAe,CAAC,CAAC"}
|
|
@@ -296,6 +296,64 @@ export function isMCPTool(tool) {
|
|
|
296
296
|
return false;
|
|
297
297
|
return true;
|
|
298
298
|
}
|
|
299
|
+
// ============================================================================
|
|
300
|
+
// MCP Economic Context Extraction
|
|
301
|
+
// ============================================================================
|
|
302
|
+
/**
|
|
303
|
+
* Extract economic context from MCP tool call metadata.
|
|
304
|
+
*
|
|
305
|
+
* MCP servers can include economic metadata in tool call arguments or
|
|
306
|
+
* _meta fields. This function looks for the `economic_context` convention:
|
|
307
|
+
*
|
|
308
|
+
* ```json
|
|
309
|
+
* {
|
|
310
|
+
* "name": "search_api",
|
|
311
|
+
* "arguments": {
|
|
312
|
+
* "query": "...",
|
|
313
|
+
* "_meta": {
|
|
314
|
+
* "economic_context": {
|
|
315
|
+
* "cost": 0.01,
|
|
316
|
+
* "currency": "USD",
|
|
317
|
+
* "protocol": "mpp",
|
|
318
|
+
* "payer": "cus_stripe_123"
|
|
319
|
+
* }
|
|
320
|
+
* }
|
|
321
|
+
* }
|
|
322
|
+
* }
|
|
323
|
+
* ```
|
|
324
|
+
*
|
|
325
|
+
* Returns null if no economic context is found.
|
|
326
|
+
*/
|
|
327
|
+
export function extractMCPEconomicContext(toolCall) {
|
|
328
|
+
const args = toolCall.arguments;
|
|
329
|
+
if (!args)
|
|
330
|
+
return null;
|
|
331
|
+
// Check _meta.economic_context (preferred convention)
|
|
332
|
+
const meta = args._meta;
|
|
333
|
+
if (meta?.economic_context && typeof meta.economic_context === 'object') {
|
|
334
|
+
return parseMCPEconomicContext(meta.economic_context);
|
|
335
|
+
}
|
|
336
|
+
// Check top-level economic_context (alternative)
|
|
337
|
+
if (args.economic_context && typeof args.economic_context === 'object') {
|
|
338
|
+
return parseMCPEconomicContext(args.economic_context);
|
|
339
|
+
}
|
|
340
|
+
return null;
|
|
341
|
+
}
|
|
342
|
+
function parseMCPEconomicContext(data) {
|
|
343
|
+
const cost = typeof data.cost === 'number' ? data.cost : undefined;
|
|
344
|
+
if (cost === undefined || !Number.isFinite(cost) || cost < 0)
|
|
345
|
+
return null;
|
|
346
|
+
const currency = typeof data.currency === 'string' ? data.currency : 'USD';
|
|
347
|
+
const VALID_PROTOCOLS = new Set(['x402', 'mpp', 'ap2', 'custom']);
|
|
348
|
+
const protocol = typeof data.protocol === 'string'
|
|
349
|
+
&& VALID_PROTOCOLS.has(data.protocol)
|
|
350
|
+
? data.protocol
|
|
351
|
+
: 'custom';
|
|
352
|
+
const payer = typeof data.payer === 'string' ? data.payer : undefined;
|
|
353
|
+
const { cost: _, currency: _c, protocol: _p, payer: _py, ...rest } = data;
|
|
354
|
+
const protocol_metadata = Object.keys(rest).length > 0 ? rest : undefined;
|
|
355
|
+
return { cost, currency, payer, protocol, protocol_metadata };
|
|
356
|
+
}
|
|
299
357
|
/**
|
|
300
358
|
* OpenAI adapter instance.
|
|
301
359
|
*/
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"adapters.js","sourceRoot":"","sources":["../../src/providers/adapters.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;
|
|
1
|
+
{"version":3,"file":"adapters.js","sourceRoot":"","sources":["../../src/providers/adapters.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAgBH,OAAO,EAAE,kBAAkB,EAAE,MAAM,gBAAgB,CAAC;AAEpD,+EAA+E;AAC/E,iBAAiB;AACjB,+EAA+E;AAE/E;;;;;;;;;;;;;;GAcG;AACH,MAAM,UAAU,QAAQ,CAAC,IAAoB;IAC3C,OAAO;QACL,IAAI,EAAE,UAAU;QAChB,QAAQ,EAAE;YACR,IAAI,EAAE,IAAI,CAAC,IAAI;YACf,WAAW,EAAE,IAAI,CAAC,WAAW;YAC7B,UAAU,EAAE,IAAI,CAAC,WAAW;SAC7B;KACF,CAAC;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AC,CAAC,IAAI,CAAC,CAAC,CAAC,SAAS,CAAC;IAE1E,OAAO,EAAE,IAAI,EAAE,QAAQ,EAAE,KAAK,EAAE,QAAQ,EAAE,iBAAiB,EAAE,CAAC;AAChE,CAAC;AAoBD;;GAEG;AACH,MAAM,CAAC,MAAM,aAAa,GAAgD;IACxE,cAAc,EAAE,QAAQ;IACxB,gBAAgB,EAAE,UAAU;IAC5B,oBAAoB,EAAE,kBAAkB;IACxC,eAAe,EAAE,aAAa;CAC/B,CAAC;AAEF;;GAEG;AACH,MAAM,CAAC,MAAM,gBAAgB,GAAqD;IAChF,cAAc,EAAE,WAAW;IAC3B,gBAAgB,EAAE,aAAa;IAC/B,oBAAoB,EAAE,oBAAoB;IAC1C,eAAe,EAAE,gBAAgB;CAClC,CAAC;AAEF;;GAEG;AACH,MAAM,CAAC,MAAM,UAAU,GAA8C;IACnE,cAAc,EAAE,KAAK;IACrB,gBAAgB,EAAE,OAAO;IACzB,oBAAoB,EAAE,eAAe;IACrC,eAAe,EAAE,UAAU;CAC5B,CAAC;AAwBF,MAAM,UAAU,UAAU,CACxB,QAAkB;IAElB,QAAQ,QAAQ,EAAE,CAAC;QACjB,KAAK,QAAQ;YACX,OAAO,aAAa,CAAC;QACvB,KAAK,WAAW;YACd,OAAO,gBAAgB,CAAC;QAC1B,KAAK,KAAK;YACR,OAAO,UAAU,CAAC;QACpB,KAAK,QAAQ;YACX,MAAM,IAAI,KAAK,CACb,0GAA0G,CAC3G,CAAC;QACJ;YACE,MAAM,IAAI,KAAK,CAAC,qBAAqB,QAAQ,EAAE,CAAC,CAAC;IACrD,CAAC;AACH,CAAC"}
|
package/dist/rules/index.d.ts
CHANGED
|
@@ -12,4 +12,5 @@ export * from './schema-validator.js';
|
|
|
12
12
|
export * from './policy-ir-schema.js';
|
|
13
13
|
export * from './condition-evaluator.js';
|
|
14
14
|
export * from './patterns.js';
|
|
15
|
+
export { evaluateRulesLocally, evaluateCondition as evaluateConditionLocally, resolveFieldPath as resolveLocalFieldPath, type LocalEvalResult, } from './local-evaluator.js';
|
|
15
16
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/rules/index.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,cAAc,YAAY,CAAC;AAC3B,cAAc,aAAa,CAAC;AAC5B,cAAc,iBAAiB,CAAC;AAChC,cAAc,qBAAqB,CAAC;AACpC,cAAc,2BAA2B,CAAC;AAC1C,cAAc,uBAAuB,CAAC;AACtC,cAAc,uBAAuB,CAAC;AACtC,cAAc,0BAA0B,CAAC;AACzC,cAAc,eAAe,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/rules/index.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,cAAc,YAAY,CAAC;AAC3B,cAAc,aAAa,CAAC;AAC5B,cAAc,iBAAiB,CAAC;AAChC,cAAc,qBAAqB,CAAC;AACpC,cAAc,2BAA2B,CAAC;AAC1C,cAAc,uBAAuB,CAAC;AACtC,cAAc,uBAAuB,CAAC;AACtC,cAAc,0BAA0B,CAAC;AACzC,cAAc,eAAe,CAAC;AAC9B,OAAO,EACL,oBAAoB,EACpB,iBAAiB,IAAI,wBAAwB,EAC7C,gBAAgB,IAAI,qBAAqB,EACzC,KAAK,eAAe,GACrB,MAAM,sBAAsB,CAAC"}
|
package/dist/rules/index.js
CHANGED
|
@@ -12,4 +12,5 @@ export * from './schema-validator.js';
|
|
|
12
12
|
export * from './policy-ir-schema.js';
|
|
13
13
|
export * from './condition-evaluator.js';
|
|
14
14
|
export * from './patterns.js';
|
|
15
|
+
export { evaluateRulesLocally, evaluateCondition as evaluateConditionLocally, resolveFieldPath as resolveLocalFieldPath, } from './local-evaluator.js';
|
|
15
16
|
//# sourceMappingURL=index.js.map
|
package/dist/rules/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/rules/index.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,cAAc,YAAY,CAAC;AAC3B,cAAc,aAAa,CAAC;AAC5B,cAAc,iBAAiB,CAAC;AAChC,cAAc,qBAAqB,CAAC;AACpC,cAAc,2BAA2B,CAAC;AAC1C,cAAc,uBAAuB,CAAC;AACtC,cAAc,uBAAuB,CAAC;AACtC,cAAc,0BAA0B,CAAC;AACzC,cAAc,eAAe,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/rules/index.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,cAAc,YAAY,CAAC;AAC3B,cAAc,aAAa,CAAC;AAC5B,cAAc,iBAAiB,CAAC;AAChC,cAAc,qBAAqB,CAAC;AACpC,cAAc,2BAA2B,CAAC;AAC1C,cAAc,uBAAuB,CAAC;AACtC,cAAc,uBAAuB,CAAC;AACtC,cAAc,0BAA0B,CAAC;AACzC,cAAc,eAAe,CAAC;AAC9B,OAAO,EACL,oBAAoB,EACpB,iBAAiB,IAAI,wBAAwB,EAC7C,gBAAgB,IAAI,qBAAqB,GAE1C,MAAM,sBAAsB,CAAC"}
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Local rule evaluator — evaluate Rule[] against a tool call without cloud.
|
|
3
|
+
*
|
|
4
|
+
* Supports 16 operators, dot-notation field resolution, AND/OR condition
|
|
5
|
+
* groups, and tool filtering. Designed for sub-millisecond local evaluation.
|
|
6
|
+
*
|
|
7
|
+
* Key behavior: undefined fields NEVER match. This prevents false positives
|
|
8
|
+
* on negative operators like not_equals, not_contains, not_in.
|
|
9
|
+
*
|
|
10
|
+
* **Divergences from canonical condition-evaluator.ts:**
|
|
11
|
+
* - All string comparisons are case-insensitive (canonical is case-sensitive).
|
|
12
|
+
* - `within_hours`/`outside_hours` use wall clock time with "HH:MM-HH:MM"
|
|
13
|
+
* strings (canonical uses field values as timestamps with structured
|
|
14
|
+
* {@link TimeWindowConditionValue} objects including timezone/day support).
|
|
15
|
+
* - `percent_of` falls back to simplified `fieldValue >= expected` when
|
|
16
|
+
* no `reference` field is provided (canonical requires `reference`).
|
|
17
|
+
*
|
|
18
|
+
* @module rules/local-evaluator
|
|
19
|
+
*/
|
|
20
|
+
import type { Rule, RuleCondition } from './types.js';
|
|
21
|
+
export interface LocalEvalResult {
|
|
22
|
+
decision: 'allow' | 'deny' | 'require_approval' | null;
|
|
23
|
+
reason?: string;
|
|
24
|
+
ruleId?: string;
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* Resolve a dot-notation field path in a nested object.
|
|
28
|
+
*
|
|
29
|
+
* Returns `undefined` for any broken path segment.
|
|
30
|
+
*/
|
|
31
|
+
export declare function resolveFieldPath(path: string, obj: Record<string, unknown>): unknown;
|
|
32
|
+
/**
|
|
33
|
+
* Evaluate a single condition against a context object.
|
|
34
|
+
*
|
|
35
|
+
* All string comparisons are case-insensitive. This differs from the
|
|
36
|
+
* canonical `condition-evaluator.ts` which is case-sensitive.
|
|
37
|
+
*
|
|
38
|
+
* **`within_hours` / `outside_hours` divergence:**
|
|
39
|
+
* The local evaluator uses wall clock time (not the field value).
|
|
40
|
+
* Expected format is a simple `"HH:MM-HH:MM"` string. There is no
|
|
41
|
+
* timezone or day-of-week support. This intentionally diverges from the
|
|
42
|
+
* canonical evaluator which interprets the field value as a timestamp
|
|
43
|
+
* and uses structured `TimeWindowConditionValue` objects with timezone
|
|
44
|
+
* and day support. The simplified approach is designed for local/browser
|
|
45
|
+
* use where wall clock checks are sufficient.
|
|
46
|
+
*
|
|
47
|
+
* **`percent_of` divergence:**
|
|
48
|
+
* When a `reference` field is present on the condition, the local
|
|
49
|
+
* evaluator resolves it and computes `fieldValue / referenceValue * 100`,
|
|
50
|
+
* returning true when the percentage exceeds `expected`. When no
|
|
51
|
+
* `reference` field exists, it falls back to a simplified comparison:
|
|
52
|
+
* `fieldValue >= expected`. The canonical evaluator always requires a
|
|
53
|
+
* `reference` field and returns false without one.
|
|
54
|
+
*
|
|
55
|
+
* Unknown operators return false.
|
|
56
|
+
*/
|
|
57
|
+
export declare function evaluateCondition(condition: RuleCondition, context: Record<string, unknown>): boolean;
|
|
58
|
+
/**
|
|
59
|
+
* Evaluate an array of rules against a tool call.
|
|
60
|
+
*
|
|
61
|
+
* Rules are evaluated in order. First matching rule wins.
|
|
62
|
+
* Returns `null` if no rule matched (caller should fall through to cloud).
|
|
63
|
+
*
|
|
64
|
+
* @param rules - Rules to evaluate (only enabled rules are considered)
|
|
65
|
+
* @param toolName - The tool being called (e.g. "browser_click")
|
|
66
|
+
* @param args - Context object for field resolution (typically `{ arguments: { ... } }`)
|
|
67
|
+
*/
|
|
68
|
+
export declare function evaluateRulesLocally(rules: Rule[], toolName: string, args: Record<string, unknown>): LocalEvalResult;
|
|
69
|
+
//# sourceMappingURL=local-evaluator.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"local-evaluator.d.ts","sourceRoot":"","sources":["../../src/rules/local-evaluator.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;GAkBG;AAEH,OAAO,KAAK,EAAE,IAAI,EAAE,aAAa,EAAE,MAAM,YAAY,CAAC;AAGtD,MAAM,WAAW,eAAe;IAC9B,QAAQ,EAAE,OAAO,GAAG,MAAM,GAAG,kBAAkB,GAAG,IAAI,CAAC;IACvD,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,MAAM,CAAC,EAAE,MAAM,CAAC;CACjB;AAED;;;;GAIG;AACH,wBAAgB,gBAAgB,CAC9B,IAAI,EAAE,MAAM,EACZ,GAAG,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAC3B,OAAO,CAQT;AAED;;;;;;;;;;;;;;;;;;;;;;;;GAwBG;AACH,wBAAgB,iBAAiB,CAC/B,SAAS,EAAE,aAAa,EACxB,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAC/B,OAAO,CA2GT;AAED;;;;;;;;;GASG;AACH,wBAAgB,oBAAoB,CAClC,KAAK,EAAE,IAAI,EAAE,EACb,QAAQ,EAAE,MAAM,EAChB,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAC5B,eAAe,CAiCjB"}
|
|
@@ -0,0 +1,217 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Local rule evaluator — evaluate Rule[] against a tool call without cloud.
|
|
3
|
+
*
|
|
4
|
+
* Supports 16 operators, dot-notation field resolution, AND/OR condition
|
|
5
|
+
* groups, and tool filtering. Designed for sub-millisecond local evaluation.
|
|
6
|
+
*
|
|
7
|
+
* Key behavior: undefined fields NEVER match. This prevents false positives
|
|
8
|
+
* on negative operators like not_equals, not_contains, not_in.
|
|
9
|
+
*
|
|
10
|
+
* **Divergences from canonical condition-evaluator.ts:**
|
|
11
|
+
* - All string comparisons are case-insensitive (canonical is case-sensitive).
|
|
12
|
+
* - `within_hours`/`outside_hours` use wall clock time with "HH:MM-HH:MM"
|
|
13
|
+
* strings (canonical uses field values as timestamps with structured
|
|
14
|
+
* {@link TimeWindowConditionValue} objects including timezone/day support).
|
|
15
|
+
* - `percent_of` falls back to simplified `fieldValue >= expected` when
|
|
16
|
+
* no `reference` field is provided (canonical requires `reference`).
|
|
17
|
+
*
|
|
18
|
+
* @module rules/local-evaluator
|
|
19
|
+
*/
|
|
20
|
+
import { createSafeRegex } from './condition-evaluator.js';
|
|
21
|
+
/**
|
|
22
|
+
* Resolve a dot-notation field path in a nested object.
|
|
23
|
+
*
|
|
24
|
+
* Returns `undefined` for any broken path segment.
|
|
25
|
+
*/
|
|
26
|
+
export function resolveFieldPath(path, obj) {
|
|
27
|
+
const parts = path.split('.');
|
|
28
|
+
let current = obj;
|
|
29
|
+
for (const part of parts) {
|
|
30
|
+
if (current === null || current === undefined || typeof current !== 'object')
|
|
31
|
+
return undefined;
|
|
32
|
+
current = current[part];
|
|
33
|
+
}
|
|
34
|
+
return current;
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* Evaluate a single condition against a context object.
|
|
38
|
+
*
|
|
39
|
+
* All string comparisons are case-insensitive. This differs from the
|
|
40
|
+
* canonical `condition-evaluator.ts` which is case-sensitive.
|
|
41
|
+
*
|
|
42
|
+
* **`within_hours` / `outside_hours` divergence:**
|
|
43
|
+
* The local evaluator uses wall clock time (not the field value).
|
|
44
|
+
* Expected format is a simple `"HH:MM-HH:MM"` string. There is no
|
|
45
|
+
* timezone or day-of-week support. This intentionally diverges from the
|
|
46
|
+
* canonical evaluator which interprets the field value as a timestamp
|
|
47
|
+
* and uses structured `TimeWindowConditionValue` objects with timezone
|
|
48
|
+
* and day support. The simplified approach is designed for local/browser
|
|
49
|
+
* use where wall clock checks are sufficient.
|
|
50
|
+
*
|
|
51
|
+
* **`percent_of` divergence:**
|
|
52
|
+
* When a `reference` field is present on the condition, the local
|
|
53
|
+
* evaluator resolves it and computes `fieldValue / referenceValue * 100`,
|
|
54
|
+
* returning true when the percentage exceeds `expected`. When no
|
|
55
|
+
* `reference` field exists, it falls back to a simplified comparison:
|
|
56
|
+
* `fieldValue >= expected`. The canonical evaluator always requires a
|
|
57
|
+
* `reference` field and returns false without one.
|
|
58
|
+
*
|
|
59
|
+
* Unknown operators return false.
|
|
60
|
+
*/
|
|
61
|
+
export function evaluateCondition(condition, context) {
|
|
62
|
+
if (!condition.field || !condition.operator)
|
|
63
|
+
return true;
|
|
64
|
+
const fieldValue = resolveFieldPath(condition.field, context);
|
|
65
|
+
const expected = condition.value;
|
|
66
|
+
if (fieldValue === undefined)
|
|
67
|
+
return false;
|
|
68
|
+
switch (condition.operator) {
|
|
69
|
+
case 'equals':
|
|
70
|
+
if (typeof fieldValue === 'string' && typeof expected === 'string') {
|
|
71
|
+
return fieldValue.toLowerCase() === expected.toLowerCase();
|
|
72
|
+
}
|
|
73
|
+
return fieldValue === expected;
|
|
74
|
+
case 'not_equals':
|
|
75
|
+
if (typeof fieldValue === 'string' && typeof expected === 'string') {
|
|
76
|
+
return fieldValue.toLowerCase() !== expected.toLowerCase();
|
|
77
|
+
}
|
|
78
|
+
return fieldValue !== expected;
|
|
79
|
+
case 'contains':
|
|
80
|
+
if (typeof fieldValue === 'string' && typeof expected === 'string') {
|
|
81
|
+
return fieldValue.toLowerCase().includes(expected.toLowerCase());
|
|
82
|
+
}
|
|
83
|
+
if (Array.isArray(fieldValue))
|
|
84
|
+
return fieldValue.includes(expected);
|
|
85
|
+
return false;
|
|
86
|
+
case 'not_contains':
|
|
87
|
+
if (typeof fieldValue === 'string' && typeof expected === 'string') {
|
|
88
|
+
return !fieldValue.toLowerCase().includes(expected.toLowerCase());
|
|
89
|
+
}
|
|
90
|
+
if (Array.isArray(fieldValue))
|
|
91
|
+
return !fieldValue.includes(expected);
|
|
92
|
+
return false;
|
|
93
|
+
case 'starts_with':
|
|
94
|
+
return (typeof fieldValue === 'string' &&
|
|
95
|
+
typeof expected === 'string' &&
|
|
96
|
+
fieldValue.toLowerCase().startsWith(expected.toLowerCase()));
|
|
97
|
+
case 'ends_with':
|
|
98
|
+
return (typeof fieldValue === 'string' &&
|
|
99
|
+
typeof expected === 'string' &&
|
|
100
|
+
fieldValue.toLowerCase().endsWith(expected.toLowerCase()));
|
|
101
|
+
case 'matches':
|
|
102
|
+
if (typeof fieldValue === 'string' && typeof expected === 'string') {
|
|
103
|
+
const regex = createSafeRegex(expected, 'i');
|
|
104
|
+
return regex !== null && regex.test(fieldValue);
|
|
105
|
+
}
|
|
106
|
+
return false;
|
|
107
|
+
case 'greater_than':
|
|
108
|
+
return typeof fieldValue === 'number' && typeof expected === 'number' && fieldValue > expected;
|
|
109
|
+
case 'less_than':
|
|
110
|
+
return typeof fieldValue === 'number' && typeof expected === 'number' && fieldValue < expected;
|
|
111
|
+
case 'in':
|
|
112
|
+
return Array.isArray(expected) && expected.includes(fieldValue);
|
|
113
|
+
case 'not_in':
|
|
114
|
+
return Array.isArray(expected) && !expected.includes(fieldValue);
|
|
115
|
+
case 'length_greater_than':
|
|
116
|
+
if (typeof fieldValue === 'string' || Array.isArray(fieldValue)) {
|
|
117
|
+
return typeof expected === 'number' && fieldValue.length > expected;
|
|
118
|
+
}
|
|
119
|
+
return false;
|
|
120
|
+
case 'percent_of': {
|
|
121
|
+
if (typeof fieldValue !== 'number' || typeof expected !== 'number')
|
|
122
|
+
return false;
|
|
123
|
+
if (typeof condition.reference === 'string') {
|
|
124
|
+
const referenceValue = resolveFieldPath(condition.reference, context);
|
|
125
|
+
if (typeof referenceValue !== 'number' || referenceValue === 0)
|
|
126
|
+
return false;
|
|
127
|
+
return (fieldValue / referenceValue) * 100 > expected;
|
|
128
|
+
}
|
|
129
|
+
return fieldValue >= expected;
|
|
130
|
+
}
|
|
131
|
+
/**
|
|
132
|
+
* `within_hours` / `outside_hours` — wall clock check.
|
|
133
|
+
*
|
|
134
|
+
* Uses the current wall clock time, NOT the field value. Expected
|
|
135
|
+
* value is a simple `"HH:MM-HH:MM"` string (24h format). No
|
|
136
|
+
* timezone or day-of-week support. Wrap-around ranges (e.g.
|
|
137
|
+
* `"22:00-06:00"`) are supported. This intentionally diverges
|
|
138
|
+
* from the canonical `condition-evaluator.ts`.
|
|
139
|
+
*/
|
|
140
|
+
case 'within_hours':
|
|
141
|
+
case 'outside_hours': {
|
|
142
|
+
if (typeof expected !== 'string')
|
|
143
|
+
return false;
|
|
144
|
+
const parts = expected.split('-');
|
|
145
|
+
if (parts.length !== 2)
|
|
146
|
+
return false;
|
|
147
|
+
const startParts = parts[0].split(':').map(Number);
|
|
148
|
+
const endParts = parts[1].split(':').map(Number);
|
|
149
|
+
const [sH, sM] = startParts;
|
|
150
|
+
const [eH, eM] = endParts;
|
|
151
|
+
if (isNaN(sH) || isNaN(sM) || isNaN(eH) || isNaN(eM))
|
|
152
|
+
return false;
|
|
153
|
+
if (sH < 0 || sH > 23 || eH < 0 || eH > 23)
|
|
154
|
+
return false;
|
|
155
|
+
if (sM < 0 || sM > 59 || eM < 0 || eM > 59)
|
|
156
|
+
return false;
|
|
157
|
+
const now = new Date();
|
|
158
|
+
const nowMins = now.getHours() * 60 + now.getMinutes();
|
|
159
|
+
const startMins = sH * 60 + sM;
|
|
160
|
+
const endMins = eH * 60 + eM;
|
|
161
|
+
let within;
|
|
162
|
+
if (startMins <= endMins) {
|
|
163
|
+
within = nowMins >= startMins && nowMins < endMins;
|
|
164
|
+
}
|
|
165
|
+
else {
|
|
166
|
+
within = nowMins >= startMins || nowMins < endMins;
|
|
167
|
+
}
|
|
168
|
+
return condition.operator === 'within_hours' ? within : !within;
|
|
169
|
+
}
|
|
170
|
+
default:
|
|
171
|
+
return false;
|
|
172
|
+
}
|
|
173
|
+
}
|
|
174
|
+
/**
|
|
175
|
+
* Evaluate an array of rules against a tool call.
|
|
176
|
+
*
|
|
177
|
+
* Rules are evaluated in order. First matching rule wins.
|
|
178
|
+
* Returns `null` if no rule matched (caller should fall through to cloud).
|
|
179
|
+
*
|
|
180
|
+
* @param rules - Rules to evaluate (only enabled rules are considered)
|
|
181
|
+
* @param toolName - The tool being called (e.g. "browser_click")
|
|
182
|
+
* @param args - Context object for field resolution (typically `{ arguments: { ... } }`)
|
|
183
|
+
*/
|
|
184
|
+
export function evaluateRulesLocally(rules, toolName, args) {
|
|
185
|
+
for (const rule of rules) {
|
|
186
|
+
if (!rule.enabled)
|
|
187
|
+
continue;
|
|
188
|
+
if (rule.tools && rule.tools.length > 0 && !rule.tools.includes(toolName))
|
|
189
|
+
continue;
|
|
190
|
+
// Conditions-first fallthrough: matches canonical evaluateConditionCollections.
|
|
191
|
+
// If `conditions` is present and non-empty, evaluate only those.
|
|
192
|
+
// Otherwise fall through to `condition_groups`.
|
|
193
|
+
if (rule.conditions && rule.conditions.length > 0) {
|
|
194
|
+
const allMatch = rule.conditions.every(c => evaluateCondition(c, args));
|
|
195
|
+
if (!allMatch)
|
|
196
|
+
continue;
|
|
197
|
+
}
|
|
198
|
+
else if (rule.condition_groups && rule.condition_groups.length > 0) {
|
|
199
|
+
const anyGroupMatch = rule.condition_groups.some(group => group.every(c => evaluateCondition(c, args)));
|
|
200
|
+
if (!anyGroupMatch)
|
|
201
|
+
continue;
|
|
202
|
+
}
|
|
203
|
+
const action = rule.action;
|
|
204
|
+
if (action === 'block') {
|
|
205
|
+
return { decision: 'deny', reason: rule.description || rule.name, ruleId: rule.id };
|
|
206
|
+
}
|
|
207
|
+
if (action === 'require_approval') {
|
|
208
|
+
return { decision: 'require_approval', reason: rule.description || rule.name, ruleId: rule.id };
|
|
209
|
+
}
|
|
210
|
+
if (action === 'allow') {
|
|
211
|
+
return { decision: 'allow', ruleId: rule.id };
|
|
212
|
+
}
|
|
213
|
+
// warn/log: no enforcement, continue to next rule
|
|
214
|
+
}
|
|
215
|
+
return { decision: null };
|
|
216
|
+
}
|
|
217
|
+
//# sourceMappingURL=local-evaluator.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"local-evaluator.js","sourceRoot":"","sources":["../../src/rules/local-evaluator.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;GAkBG;AAGH,OAAO,EAAE,eAAe,EAAE,MAAM,0BAA0B,CAAC;AAQ3D;;;;GAIG;AACH,MAAM,UAAU,gBAAgB,CAC9B,IAAY,EACZ,GAA4B;IAE5B,MAAM,KAAK,GAAG,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC;IAC9B,IAAI,OAAO,GAAY,GAAG,CAAC;IAC3B,KAAK,MAAM,IAAI,IAAI,KAAK,EAAE,CAAC;QACzB,IAAI,OAAO,KAAK,IAAI,IAAI,OAAO,KAAK,SAAS,IAAI,OAAO,OAAO,KAAK,QAAQ;YAAE,OAAO,SAAS,CAAC;QAC/F,OAAO,GAAI,OAAmC,CAAC,IAAI,CAAC,CAAC;IACvD,CAAC;IACD,OAAO,OAAO,CAAC;AACjB,CAAC;AAED;;;;;;;;;;;;;;;;;;;;;;;;GAwBG;AACH,MAAM,UAAU,iBAAiB,CAC/B,SA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MAAM,EAAE,MAAM,EAAE,IAAI,CAAC,WAAW,IAAI,IAAI,CAAC,IAAI,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE,EAAE,CAAC;QACtF,CAAC;QACD,IAAI,MAAM,KAAK,kBAAkB,EAAE,CAAC;YAClC,OAAO,EAAE,QAAQ,EAAE,kBAAkB,EAAE,MAAM,EAAE,IAAI,CAAC,WAAW,IAAI,IAAI,CAAC,IAAI,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE,EAAE,CAAC;QAClG,CAAC;QACD,IAAI,MAAM,KAAK,OAAO,EAAE,CAAC;YACvB,OAAO,EAAE,QAAQ,EAAE,OAAO,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE,EAAE,CAAC;QAChD,CAAC;QACD,kDAAkD;IACpD,CAAC;IAED,OAAO,EAAE,QAAQ,EAAE,IAAI,EAAE,CAAC;AAC5B,CAAC"}
|
|
@@ -11,6 +11,8 @@ export declare const POLICY_IR_V1_SCHEMA: {
|
|
|
11
11
|
readonly required: readonly ["output_rules"];
|
|
12
12
|
}, {
|
|
13
13
|
readonly required: readonly ["extends"];
|
|
14
|
+
}, {
|
|
15
|
+
readonly required: readonly ["economic"];
|
|
14
16
|
}];
|
|
15
17
|
readonly properties: {
|
|
16
18
|
readonly version: {
|
|
@@ -48,6 +50,9 @@ export declare const POLICY_IR_V1_SCHEMA: {
|
|
|
48
50
|
readonly settings: {
|
|
49
51
|
readonly $ref: "#/$defs/Settings";
|
|
50
52
|
};
|
|
53
|
+
readonly economic: {
|
|
54
|
+
readonly $ref: "#/$defs/EconomicPolicy";
|
|
55
|
+
};
|
|
51
56
|
};
|
|
52
57
|
readonly additionalProperties: false;
|
|
53
58
|
readonly $defs: {
|
|
@@ -397,6 +402,110 @@ export declare const POLICY_IR_V1_SCHEMA: {
|
|
|
397
402
|
};
|
|
398
403
|
readonly additionalProperties: false;
|
|
399
404
|
};
|
|
405
|
+
readonly EconomicPolicy: {
|
|
406
|
+
readonly type: "object";
|
|
407
|
+
readonly description: "Economic authorization policy for x402, MPP, and AP2 protocols.";
|
|
408
|
+
readonly properties: {
|
|
409
|
+
readonly budgets: {
|
|
410
|
+
readonly type: "array";
|
|
411
|
+
readonly items: {
|
|
412
|
+
readonly $ref: "#/$defs/EconomicBudget";
|
|
413
|
+
};
|
|
414
|
+
readonly description: "Budget configurations per scope.";
|
|
415
|
+
};
|
|
416
|
+
readonly cost_extraction: {
|
|
417
|
+
readonly type: "object";
|
|
418
|
+
readonly properties: {
|
|
419
|
+
readonly default: {
|
|
420
|
+
readonly type: "string";
|
|
421
|
+
readonly description: "Default dot-notation path to extract cost from tool arguments.";
|
|
422
|
+
};
|
|
423
|
+
readonly overrides: {
|
|
424
|
+
readonly type: "object";
|
|
425
|
+
readonly additionalProperties: {
|
|
426
|
+
readonly type: "string";
|
|
427
|
+
};
|
|
428
|
+
readonly description: "Per-tool cost extraction path overrides.";
|
|
429
|
+
};
|
|
430
|
+
};
|
|
431
|
+
readonly additionalProperties: false;
|
|
432
|
+
};
|
|
433
|
+
readonly payer: {
|
|
434
|
+
readonly type: "object";
|
|
435
|
+
readonly properties: {
|
|
436
|
+
readonly required: {
|
|
437
|
+
readonly type: "boolean";
|
|
438
|
+
readonly description: "Whether a payer identity is required.";
|
|
439
|
+
};
|
|
440
|
+
readonly approved: {
|
|
441
|
+
readonly type: "array";
|
|
442
|
+
readonly items: {
|
|
443
|
+
readonly type: "string";
|
|
444
|
+
};
|
|
445
|
+
readonly description: "Allowlist of approved payer identifiers.";
|
|
446
|
+
};
|
|
447
|
+
};
|
|
448
|
+
readonly additionalProperties: false;
|
|
449
|
+
};
|
|
450
|
+
readonly denial_reasons: {
|
|
451
|
+
readonly type: "object";
|
|
452
|
+
readonly description: "Custom denial message templates. Keys are denial reason codes, values are message templates with {variable} placeholders.";
|
|
453
|
+
readonly properties: {
|
|
454
|
+
readonly budget_exceeded: {
|
|
455
|
+
readonly type: "string";
|
|
456
|
+
};
|
|
457
|
+
readonly approval_required: {
|
|
458
|
+
readonly type: "string";
|
|
459
|
+
};
|
|
460
|
+
readonly payer_missing: {
|
|
461
|
+
readonly type: "string";
|
|
462
|
+
};
|
|
463
|
+
readonly payer_unauthorized: {
|
|
464
|
+
readonly type: "string";
|
|
465
|
+
};
|
|
466
|
+
readonly currency_mismatch: {
|
|
467
|
+
readonly type: "string";
|
|
468
|
+
};
|
|
469
|
+
readonly connector_error: {
|
|
470
|
+
readonly type: "string";
|
|
471
|
+
};
|
|
472
|
+
};
|
|
473
|
+
readonly additionalProperties: false;
|
|
474
|
+
};
|
|
475
|
+
};
|
|
476
|
+
readonly additionalProperties: false;
|
|
477
|
+
};
|
|
478
|
+
readonly EconomicBudget: {
|
|
479
|
+
readonly type: "object";
|
|
480
|
+
readonly required: readonly ["scope", "limit", "currency", "window"];
|
|
481
|
+
readonly properties: {
|
|
482
|
+
readonly scope: {
|
|
483
|
+
readonly type: "string";
|
|
484
|
+
readonly enum: readonly ["session", "agent", "user", "global"];
|
|
485
|
+
readonly description: "Budget scope.";
|
|
486
|
+
};
|
|
487
|
+
readonly limit: {
|
|
488
|
+
readonly type: "number";
|
|
489
|
+
readonly minimum: 0;
|
|
490
|
+
readonly description: "Maximum spend limit.";
|
|
491
|
+
};
|
|
492
|
+
readonly currency: {
|
|
493
|
+
readonly type: "string";
|
|
494
|
+
readonly minLength: 1;
|
|
495
|
+
readonly description: "Currency code (e.g., \"USD\").";
|
|
496
|
+
};
|
|
497
|
+
readonly approval_threshold: {
|
|
498
|
+
readonly type: "number";
|
|
499
|
+
readonly minimum: 0;
|
|
500
|
+
readonly description: "Cost above which approval is required.";
|
|
501
|
+
};
|
|
502
|
+
readonly window: {
|
|
503
|
+
readonly type: "string";
|
|
504
|
+
readonly description: "Budget time window (e.g., \"session\", \"24h\").";
|
|
505
|
+
};
|
|
506
|
+
};
|
|
507
|
+
readonly additionalProperties: false;
|
|
508
|
+
};
|
|
400
509
|
};
|
|
401
510
|
};
|
|
402
511
|
//# sourceMappingURL=policy-ir-schema.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"policy-ir-schema.d.ts","sourceRoot":"","sources":["../../src/rules/policy-ir-schema.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,mBAAmB
|
|
1
|
+
{"version":3,"file":"policy-ir-schema.d.ts","sourceRoot":"","sources":["../../src/rules/policy-ir-schema.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,mBAAmB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CAsdtB,CAAC"}
|