veto-sdk 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +209 -0
- package/dist/benchmark/cli.d.ts +22 -0
- package/dist/benchmark/cli.d.ts.map +1 -0
- package/dist/benchmark/cli.js +238 -0
- package/dist/benchmark/cli.js.map +1 -0
- package/dist/benchmark/index.d.ts +10 -0
- package/dist/benchmark/index.d.ts.map +1 -0
- package/dist/benchmark/index.js +10 -0
- package/dist/benchmark/index.js.map +1 -0
- package/dist/benchmark/loader.d.ts +19 -0
- package/dist/benchmark/loader.d.ts.map +1 -0
- package/dist/benchmark/loader.js +321 -0
- package/dist/benchmark/loader.js.map +1 -0
- package/dist/benchmark/metrics.d.ts +35 -0
- package/dist/benchmark/metrics.d.ts.map +1 -0
- package/dist/benchmark/metrics.js +195 -0
- package/dist/benchmark/metrics.js.map +1 -0
- package/dist/benchmark/runner.d.ts +39 -0
- package/dist/benchmark/runner.d.ts.map +1 -0
- package/dist/benchmark/runner.js +279 -0
- package/dist/benchmark/runner.js.map +1 -0
- package/dist/benchmark/types.d.ts +188 -0
- package/dist/benchmark/types.d.ts.map +1 -0
- package/dist/benchmark/types.js +24 -0
- package/dist/benchmark/types.js.map +1 -0
- package/dist/cli/bin.d.ts +8 -0
- package/dist/cli/bin.d.ts.map +1 -0
- package/dist/cli/bin.js +120 -0
- package/dist/cli/bin.js.map +1 -0
- package/dist/cli/config.d.ts +126 -0
- package/dist/cli/config.d.ts.map +1 -0
- package/dist/cli/config.js +137 -0
- package/dist/cli/config.js.map +1 -0
- package/dist/cli/index.d.ts +9 -0
- package/dist/cli/index.d.ts.map +1 -0
- package/dist/cli/index.js +9 -0
- package/dist/cli/index.js.map +1 -0
- package/dist/cli/init.d.ts +64 -0
- package/dist/cli/init.d.ts.map +1 -0
- package/dist/cli/init.js +160 -0
- package/dist/cli/init.js.map +1 -0
- package/dist/cli/templates.d.ts +22 -0
- package/dist/cli/templates.d.ts.map +1 -0
- package/dist/cli/templates.js +132 -0
- package/dist/cli/templates.js.map +1 -0
- package/dist/core/history.d.ts +104 -0
- package/dist/core/history.d.ts.map +1 -0
- package/dist/core/history.js +148 -0
- package/dist/core/history.js.map +1 -0
- package/dist/core/index.d.ts +10 -0
- package/dist/core/index.d.ts.map +1 -0
- package/dist/core/index.js +10 -0
- package/dist/core/index.js.map +1 -0
- package/dist/core/interceptor.d.ts +96 -0
- package/dist/core/interceptor.d.ts.map +1 -0
- package/dist/core/interceptor.js +227 -0
- package/dist/core/interceptor.js.map +1 -0
- package/dist/core/validator.d.ts +107 -0
- package/dist/core/validator.d.ts.map +1 -0
- package/dist/core/validator.js +263 -0
- package/dist/core/validator.js.map +1 -0
- package/dist/core/veto.d.ts +265 -0
- package/dist/core/veto.d.ts.map +1 -0
- package/dist/core/veto.js +681 -0
- package/dist/core/veto.js.map +1 -0
- package/dist/index.d.ts +43 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +40 -0
- package/dist/index.js.map +1 -0
- package/dist/kernel/client.d.ts +82 -0
- package/dist/kernel/client.d.ts.map +1 -0
- package/dist/kernel/client.js +162 -0
- package/dist/kernel/client.js.map +1 -0
- package/dist/kernel/index.d.ts +9 -0
- package/dist/kernel/index.d.ts.map +1 -0
- package/dist/kernel/index.js +9 -0
- package/dist/kernel/index.js.map +1 -0
- package/dist/kernel/prompt.d.ts +27 -0
- package/dist/kernel/prompt.d.ts.map +1 -0
- package/dist/kernel/prompt.js +127 -0
- package/dist/kernel/prompt.js.map +1 -0
- package/dist/kernel/types.d.ts +85 -0
- package/dist/kernel/types.d.ts.map +1 -0
- package/dist/kernel/types.js +52 -0
- package/dist/kernel/types.js.map +1 -0
- package/dist/providers/adapters.d.ts +167 -0
- package/dist/providers/adapters.d.ts.map +1 -0
- package/dist/providers/adapters.js +244 -0
- package/dist/providers/adapters.js.map +1 -0
- package/dist/providers/index.d.ts +11 -0
- package/dist/providers/index.d.ts.map +1 -0
- package/dist/providers/index.js +11 -0
- package/dist/providers/index.js.map +1 -0
- package/dist/providers/types.d.ts +92 -0
- package/dist/providers/types.d.ts.map +1 -0
- package/dist/providers/types.js +10 -0
- package/dist/providers/types.js.map +1 -0
- package/dist/rules/api-client.d.ts +103 -0
- package/dist/rules/api-client.d.ts.map +1 -0
- package/dist/rules/api-client.js +241 -0
- package/dist/rules/api-client.js.map +1 -0
- package/dist/rules/index.d.ts +10 -0
- package/dist/rules/index.d.ts.map +1 -0
- package/dist/rules/index.js +10 -0
- package/dist/rules/index.js.map +1 -0
- package/dist/rules/loader.d.ts +116 -0
- package/dist/rules/loader.d.ts.map +1 -0
- package/dist/rules/loader.js +300 -0
- package/dist/rules/loader.js.map +1 -0
- package/dist/rules/rule-validator.d.ts +135 -0
- package/dist/rules/rule-validator.d.ts.map +1 -0
- package/dist/rules/rule-validator.js +239 -0
- package/dist/rules/rule-validator.js.map +1 -0
- package/dist/rules/types.d.ts +162 -0
- package/dist/rules/types.d.ts.map +1 -0
- package/dist/rules/types.js +16 -0
- package/dist/rules/types.js.map +1 -0
- package/dist/types/config.d.ts +171 -0
- package/dist/types/config.d.ts.map +1 -0
- package/dist/types/config.js +31 -0
- package/dist/types/config.js.map +1 -0
- package/dist/types/index.d.ts +8 -0
- package/dist/types/index.d.ts.map +1 -0
- package/dist/types/index.js +8 -0
- package/dist/types/index.js.map +1 -0
- package/dist/types/tool.d.ts +156 -0
- package/dist/types/tool.d.ts.map +1 -0
- package/dist/types/tool.js +27 -0
- package/dist/types/tool.js.map +1 -0
- package/dist/utils/glob.d.ts +21 -0
- package/dist/utils/glob.d.ts.map +1 -0
- package/dist/utils/glob.js +147 -0
- package/dist/utils/glob.js.map +1 -0
- package/dist/utils/id.d.ts +28 -0
- package/dist/utils/id.d.ts.map +1 -0
- package/dist/utils/id.js +43 -0
- package/dist/utils/id.js.map +1 -0
- package/dist/utils/index.d.ts +9 -0
- package/dist/utils/index.d.ts.map +1 -0
- package/dist/utils/index.js +9 -0
- package/dist/utils/index.js.map +1 -0
- package/dist/utils/logger.d.ts +97 -0
- package/dist/utils/logger.d.ts.map +1 -0
- package/dist/utils/logger.js +153 -0
- package/dist/utils/logger.js.map +1 -0
- package/package.json +90 -0
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/providers/types.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,kBAAkB,CAAC;AAMxD;;;;GAIG;AACH,MAAM,WAAW,wBAAwB;IACvC,IAAI,EAAE,MAAM,CAAC;IACb,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,UAAU,CAAC,EAAE,eAAe,CAAC;CAC9B;AAED;;GAEG;AACH,MAAM,WAAW,UAAU;IACzB,IAAI,EAAE,UAAU,CAAC;IACjB,QAAQ,EAAE,wBAAwB,CAAC;CACpC;AAED;;GAEG;AACH,MAAM,WAAW,cAAc;IAC7B,EAAE,EAAE,MAAM,CAAC;IACX,IAAI,EAAE,UAAU,CAAC;IACjB,QAAQ,EAAE;QACR,IAAI,EAAE,MAAM,CAAC;QACb,SAAS,EAAE,MAAM,CAAC;KACnB,CAAC;CACH;AAMD;;;;GAIG;AACH,MAAM,WAAW,aAAa;IAC5B,IAAI,EAAE,MAAM,CAAC;IACb,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,YAAY,EAAE,eAAe,CAAC;CAC/B;AAED;;GAEG;AACH,MAAM,WAAW,gBAAgB;IAC/B,IAAI,EAAE,UAAU,CAAC;IACjB,EAAE,EAAE,MAAM,CAAC;IACX,IAAI,EAAE,MAAM,CAAC;IACb,KAAK,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;CAChC;AAMD;;;;GAIG;AACH,MAAM,WAAW,yBAAyB;IACxC,IAAI,EAAE,MAAM,CAAC;IACb,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,UAAU,CAAC,EAAE,eAAe,CAAC;CAC9B;AAED;;GAEG;AACH,MAAM,WAAW,UAAU;IACzB,oBAAoB,EAAE,yBAAyB,EAAE,CAAC;CACnD;AAED;;GAEG;AACH,MAAM,WAAW,kBAAkB;IACjC,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;CAC/B;AAMD;;GAEG;AACH,MAAM,MAAM,QAAQ,GAAG,QAAQ,GAAG,WAAW,GAAG,QAAQ,CAAC;AAEzD;;GAEG;AACH,MAAM,MAAM,YAAY,GAAG,UAAU,GAAG,aAAa,GAAG,UAAU,CAAC;AAEnE;;GAEG;AACH,MAAM,MAAM,gBAAgB,GAAG,cAAc,GAAG,gBAAgB,GAAG,kBAAkB,CAAC"}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Provider-specific type definitions.
|
|
3
|
+
*
|
|
4
|
+
* This module defines the tool schema formats used by different AI providers,
|
|
5
|
+
* allowing Veto to work transparently with each provider's format.
|
|
6
|
+
*
|
|
7
|
+
* @module providers/types
|
|
8
|
+
*/
|
|
9
|
+
export {};
|
|
10
|
+
//# sourceMappingURL=types.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../src/providers/types.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG"}
|
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* API client for the validation endpoint.
|
|
3
|
+
*
|
|
4
|
+
* Sends tool call context and rules to an external API for validation
|
|
5
|
+
* and returns the decision.
|
|
6
|
+
*
|
|
7
|
+
* @module rules/api-client
|
|
8
|
+
*/
|
|
9
|
+
import type { Logger } from '../utils/logger.js';
|
|
10
|
+
import type { Rule, ToolCallContext, ValidationAPIResponse } from './types.js';
|
|
11
|
+
/**
|
|
12
|
+
* Configuration for the validation API client.
|
|
13
|
+
*/
|
|
14
|
+
export interface ValidationAPIConfig {
|
|
15
|
+
/** Base URL of the validation API */
|
|
16
|
+
baseUrl: string;
|
|
17
|
+
/** Endpoint path for tool call validation */
|
|
18
|
+
endpoint?: string;
|
|
19
|
+
/** Request timeout in milliseconds */
|
|
20
|
+
timeout?: number;
|
|
21
|
+
/** Additional headers to include in requests */
|
|
22
|
+
headers?: Record<string, string>;
|
|
23
|
+
/** API key for authentication (sent as Authorization: Bearer header) */
|
|
24
|
+
apiKey?: string;
|
|
25
|
+
/** Number of retries on failure */
|
|
26
|
+
retries?: number;
|
|
27
|
+
/** Delay between retries in milliseconds */
|
|
28
|
+
retryDelay?: number;
|
|
29
|
+
}
|
|
30
|
+
/**
|
|
31
|
+
* Options for the API client.
|
|
32
|
+
*/
|
|
33
|
+
export interface ValidationAPIClientOptions {
|
|
34
|
+
/** API configuration */
|
|
35
|
+
config: ValidationAPIConfig;
|
|
36
|
+
/** Logger instance */
|
|
37
|
+
logger: Logger;
|
|
38
|
+
/** Behavior when API is unavailable */
|
|
39
|
+
failMode?: 'open' | 'closed';
|
|
40
|
+
}
|
|
41
|
+
/**
|
|
42
|
+
* Error thrown when the validation API fails.
|
|
43
|
+
*/
|
|
44
|
+
export declare class ValidationAPIError extends Error {
|
|
45
|
+
readonly statusCode?: number;
|
|
46
|
+
readonly responseBody?: string;
|
|
47
|
+
constructor(message: string, statusCode?: number, responseBody?: string);
|
|
48
|
+
}
|
|
49
|
+
/**
|
|
50
|
+
* Client for communicating with the validation API.
|
|
51
|
+
*/
|
|
52
|
+
export declare class ValidationAPIClient {
|
|
53
|
+
private readonly config;
|
|
54
|
+
private readonly logger;
|
|
55
|
+
private readonly failMode;
|
|
56
|
+
constructor(options: ValidationAPIClientOptions);
|
|
57
|
+
/**
|
|
58
|
+
* Validate a tool call against the rules.
|
|
59
|
+
*
|
|
60
|
+
* @param context - Tool call context
|
|
61
|
+
* @param rules - Applicable rules
|
|
62
|
+
* @returns Validation response
|
|
63
|
+
*/
|
|
64
|
+
validate(context: ToolCallContext, rules: Rule[]): Promise<ValidationAPIResponse>;
|
|
65
|
+
/**
|
|
66
|
+
* Check if the API is healthy.
|
|
67
|
+
*
|
|
68
|
+
* @returns True if the API is reachable
|
|
69
|
+
*/
|
|
70
|
+
healthCheck(): Promise<boolean>;
|
|
71
|
+
/**
|
|
72
|
+
* Make the actual HTTP request.
|
|
73
|
+
*/
|
|
74
|
+
private makeRequest;
|
|
75
|
+
/**
|
|
76
|
+
* Build request headers.
|
|
77
|
+
*/
|
|
78
|
+
private buildHeaders;
|
|
79
|
+
/**
|
|
80
|
+
* Parse and validate the API response.
|
|
81
|
+
*/
|
|
82
|
+
private parseResponse;
|
|
83
|
+
/**
|
|
84
|
+
* Get a response based on fail mode when API is unavailable.
|
|
85
|
+
*/
|
|
86
|
+
private getFailModeResponse;
|
|
87
|
+
/**
|
|
88
|
+
* Resolve configuration with defaults.
|
|
89
|
+
*/
|
|
90
|
+
private resolveConfig;
|
|
91
|
+
/**
|
|
92
|
+
* Delay for the specified milliseconds.
|
|
93
|
+
*/
|
|
94
|
+
private delay;
|
|
95
|
+
}
|
|
96
|
+
/**
|
|
97
|
+
* Create a new validation API client.
|
|
98
|
+
*
|
|
99
|
+
* @param options - Client options
|
|
100
|
+
* @returns ValidationAPIClient instance
|
|
101
|
+
*/
|
|
102
|
+
export declare function createValidationAPIClient(options: ValidationAPIClientOptions): ValidationAPIClient;
|
|
103
|
+
//# sourceMappingURL=api-client.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"api-client.d.ts","sourceRoot":"","sources":["../../src/rules/api-client.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,oBAAoB,CAAC;AACjD,OAAO,KAAK,EACV,IAAI,EACJ,eAAe,EAEf,qBAAqB,EACtB,MAAM,YAAY,CAAC;AAEpB;;GAEG;AACH,MAAM,WAAW,mBAAmB;IAClC,qCAAqC;IACrC,OAAO,EAAE,MAAM,CAAC;IAChB,6CAA6C;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O,CAAC,aAAa;IA+BrB;;OAEG;IACH,OAAO,CAAC,mBAAmB;IAoB3B;;OAEG;IACH,OAAO,CAAC,aAAa;IAYrB;;OAEG;IACH,OAAO,CAAC,KAAK;CAGd;AAED;;;;;GAKG;AACH,wBAAgB,yBAAyB,CACvC,OAAO,EAAE,0BAA0B,GAClC,mBAAmB,CAErB"}
|
|
@@ -0,0 +1,241 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* API client for the validation endpoint.
|
|
3
|
+
*
|
|
4
|
+
* Sends tool call context and rules to an external API for validation
|
|
5
|
+
* and returns the decision.
|
|
6
|
+
*
|
|
7
|
+
* @module rules/api-client
|
|
8
|
+
*/
|
|
9
|
+
/**
|
|
10
|
+
* Error thrown when the validation API fails.
|
|
11
|
+
*/
|
|
12
|
+
export class ValidationAPIError extends Error {
|
|
13
|
+
statusCode;
|
|
14
|
+
responseBody;
|
|
15
|
+
constructor(message, statusCode, responseBody) {
|
|
16
|
+
super(message);
|
|
17
|
+
this.name = 'ValidationAPIError';
|
|
18
|
+
this.statusCode = statusCode;
|
|
19
|
+
this.responseBody = responseBody;
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* Client for communicating with the validation API.
|
|
24
|
+
*/
|
|
25
|
+
export class ValidationAPIClient {
|
|
26
|
+
config;
|
|
27
|
+
logger;
|
|
28
|
+
failMode;
|
|
29
|
+
constructor(options) {
|
|
30
|
+
this.config = this.resolveConfig(options.config);
|
|
31
|
+
this.logger = options.logger;
|
|
32
|
+
this.failMode = options.failMode ?? 'closed';
|
|
33
|
+
this.logger.info('Validation API client initialized', {
|
|
34
|
+
baseUrl: this.config.baseUrl,
|
|
35
|
+
endpoint: this.config.endpoint,
|
|
36
|
+
timeout: this.config.timeout,
|
|
37
|
+
failMode: this.failMode,
|
|
38
|
+
});
|
|
39
|
+
}
|
|
40
|
+
/**
|
|
41
|
+
* Validate a tool call against the rules.
|
|
42
|
+
*
|
|
43
|
+
* @param context - Tool call context
|
|
44
|
+
* @param rules - Applicable rules
|
|
45
|
+
* @returns Validation response
|
|
46
|
+
*/
|
|
47
|
+
async validate(context, rules) {
|
|
48
|
+
const request = {
|
|
49
|
+
context,
|
|
50
|
+
rules,
|
|
51
|
+
};
|
|
52
|
+
const url = `${this.config.baseUrl}${this.config.endpoint}`;
|
|
53
|
+
this.logger.debug('Sending validation request', {
|
|
54
|
+
url,
|
|
55
|
+
toolName: context.tool_name,
|
|
56
|
+
callId: context.call_id,
|
|
57
|
+
ruleCount: rules.length,
|
|
58
|
+
});
|
|
59
|
+
let lastError;
|
|
60
|
+
for (let attempt = 0; attempt <= this.config.retries; attempt++) {
|
|
61
|
+
try {
|
|
62
|
+
const response = await this.makeRequest(url, request);
|
|
63
|
+
this.logger.debug('Received validation response', {
|
|
64
|
+
callId: context.call_id,
|
|
65
|
+
decision: response.decision,
|
|
66
|
+
shouldPassWeight: response.should_pass_weight,
|
|
67
|
+
shouldBlockWeight: response.should_block_weight,
|
|
68
|
+
});
|
|
69
|
+
return response;
|
|
70
|
+
}
|
|
71
|
+
catch (error) {
|
|
72
|
+
lastError = error instanceof Error ? error : new Error(String(error));
|
|
73
|
+
if (attempt < this.config.retries) {
|
|
74
|
+
this.logger.warn('Validation request failed, retrying', {
|
|
75
|
+
attempt: attempt + 1,
|
|
76
|
+
maxRetries: this.config.retries,
|
|
77
|
+
error: lastError.message,
|
|
78
|
+
});
|
|
79
|
+
await this.delay(this.config.retryDelay);
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
// All retries exhausted
|
|
84
|
+
this.logger.error('Validation API request failed after all retries', {
|
|
85
|
+
url,
|
|
86
|
+
callId: context.call_id,
|
|
87
|
+
retries: this.config.retries,
|
|
88
|
+
}, lastError);
|
|
89
|
+
// Return based on fail mode
|
|
90
|
+
return this.getFailModeResponse(lastError?.message ?? 'API unavailable');
|
|
91
|
+
}
|
|
92
|
+
/**
|
|
93
|
+
* Check if the API is healthy.
|
|
94
|
+
*
|
|
95
|
+
* @returns True if the API is reachable
|
|
96
|
+
*/
|
|
97
|
+
async healthCheck() {
|
|
98
|
+
try {
|
|
99
|
+
const controller = new AbortController();
|
|
100
|
+
const timeoutId = setTimeout(() => controller.abort(), 5000);
|
|
101
|
+
const response = await fetch(`${this.config.baseUrl}/health`, {
|
|
102
|
+
method: 'GET',
|
|
103
|
+
headers: this.buildHeaders(),
|
|
104
|
+
signal: controller.signal,
|
|
105
|
+
});
|
|
106
|
+
clearTimeout(timeoutId);
|
|
107
|
+
return response.ok;
|
|
108
|
+
}
|
|
109
|
+
catch {
|
|
110
|
+
return false;
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
/**
|
|
114
|
+
* Make the actual HTTP request.
|
|
115
|
+
*/
|
|
116
|
+
async makeRequest(url, request) {
|
|
117
|
+
const controller = new AbortController();
|
|
118
|
+
const timeoutId = setTimeout(() => controller.abort(), this.config.timeout);
|
|
119
|
+
try {
|
|
120
|
+
const response = await fetch(url, {
|
|
121
|
+
method: 'POST',
|
|
122
|
+
headers: this.buildHeaders(),
|
|
123
|
+
body: JSON.stringify(request),
|
|
124
|
+
signal: controller.signal,
|
|
125
|
+
});
|
|
126
|
+
clearTimeout(timeoutId);
|
|
127
|
+
if (!response.ok) {
|
|
128
|
+
const body = await response.text().catch(() => 'Unable to read response body');
|
|
129
|
+
throw new ValidationAPIError(`API returned status ${response.status}`, response.status, body);
|
|
130
|
+
}
|
|
131
|
+
const data = await response.json();
|
|
132
|
+
return this.parseResponse(data);
|
|
133
|
+
}
|
|
134
|
+
catch (error) {
|
|
135
|
+
clearTimeout(timeoutId);
|
|
136
|
+
if (error instanceof ValidationAPIError) {
|
|
137
|
+
throw error;
|
|
138
|
+
}
|
|
139
|
+
if (error instanceof Error && error.name === 'AbortError') {
|
|
140
|
+
throw new ValidationAPIError(`Request timed out after ${this.config.timeout}ms`);
|
|
141
|
+
}
|
|
142
|
+
throw new ValidationAPIError(`Request failed: ${error instanceof Error ? error.message : String(error)}`);
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
/**
|
|
146
|
+
* Build request headers.
|
|
147
|
+
*/
|
|
148
|
+
buildHeaders() {
|
|
149
|
+
const headers = {
|
|
150
|
+
'Content-Type': 'application/json',
|
|
151
|
+
...this.config.headers,
|
|
152
|
+
};
|
|
153
|
+
if (this.config.apiKey) {
|
|
154
|
+
headers['Authorization'] = `Bearer ${this.config.apiKey}`;
|
|
155
|
+
}
|
|
156
|
+
return headers;
|
|
157
|
+
}
|
|
158
|
+
/**
|
|
159
|
+
* Parse and validate the API response.
|
|
160
|
+
*/
|
|
161
|
+
parseResponse(data) {
|
|
162
|
+
if (!data || typeof data !== 'object') {
|
|
163
|
+
throw new ValidationAPIError('Invalid response format');
|
|
164
|
+
}
|
|
165
|
+
const response = data;
|
|
166
|
+
// Validate required fields
|
|
167
|
+
if (typeof response.should_pass_weight !== 'number') {
|
|
168
|
+
throw new ValidationAPIError('Missing or invalid should_pass_weight');
|
|
169
|
+
}
|
|
170
|
+
if (typeof response.should_block_weight !== 'number') {
|
|
171
|
+
throw new ValidationAPIError('Missing or invalid should_block_weight');
|
|
172
|
+
}
|
|
173
|
+
if (response.decision !== 'pass' && response.decision !== 'block') {
|
|
174
|
+
throw new ValidationAPIError('Missing or invalid decision (must be "pass" or "block")');
|
|
175
|
+
}
|
|
176
|
+
if (typeof response.reasoning !== 'string') {
|
|
177
|
+
throw new ValidationAPIError('Missing or invalid reasoning');
|
|
178
|
+
}
|
|
179
|
+
return {
|
|
180
|
+
should_pass_weight: response.should_pass_weight,
|
|
181
|
+
should_block_weight: response.should_block_weight,
|
|
182
|
+
decision: response.decision,
|
|
183
|
+
reasoning: response.reasoning,
|
|
184
|
+
matched_rules: response.matched_rules,
|
|
185
|
+
metadata: response.metadata,
|
|
186
|
+
};
|
|
187
|
+
}
|
|
188
|
+
/**
|
|
189
|
+
* Get a response based on fail mode when API is unavailable.
|
|
190
|
+
*/
|
|
191
|
+
getFailModeResponse(reason) {
|
|
192
|
+
if (this.failMode === 'open') {
|
|
193
|
+
this.logger.warn('Failing open due to API error', { reason });
|
|
194
|
+
return {
|
|
195
|
+
should_pass_weight: 1.0,
|
|
196
|
+
should_block_weight: 0.0,
|
|
197
|
+
decision: 'pass',
|
|
198
|
+
reasoning: `API unavailable, failing open: ${reason}`,
|
|
199
|
+
};
|
|
200
|
+
}
|
|
201
|
+
else {
|
|
202
|
+
this.logger.warn('Failing closed due to API error', { reason });
|
|
203
|
+
return {
|
|
204
|
+
should_pass_weight: 0.0,
|
|
205
|
+
should_block_weight: 1.0,
|
|
206
|
+
decision: 'block',
|
|
207
|
+
reasoning: `API unavailable, failing closed: ${reason}`,
|
|
208
|
+
};
|
|
209
|
+
}
|
|
210
|
+
}
|
|
211
|
+
/**
|
|
212
|
+
* Resolve configuration with defaults.
|
|
213
|
+
*/
|
|
214
|
+
resolveConfig(config) {
|
|
215
|
+
return {
|
|
216
|
+
baseUrl: config.baseUrl.replace(/\/$/, ''), // Remove trailing slash
|
|
217
|
+
endpoint: config.endpoint ?? '/tool/call/check',
|
|
218
|
+
timeout: config.timeout ?? 10000,
|
|
219
|
+
headers: config.headers ?? {},
|
|
220
|
+
apiKey: config.apiKey,
|
|
221
|
+
retries: config.retries ?? 2,
|
|
222
|
+
retryDelay: config.retryDelay ?? 1000,
|
|
223
|
+
};
|
|
224
|
+
}
|
|
225
|
+
/**
|
|
226
|
+
* Delay for the specified milliseconds.
|
|
227
|
+
*/
|
|
228
|
+
delay(ms) {
|
|
229
|
+
return new Promise((resolve) => setTimeout(resolve, ms));
|
|
230
|
+
}
|
|
231
|
+
}
|
|
232
|
+
/**
|
|
233
|
+
* Create a new validation API client.
|
|
234
|
+
*
|
|
235
|
+
* @param options - Client options
|
|
236
|
+
* @returns ValidationAPIClient instance
|
|
237
|
+
*/
|
|
238
|
+
export function createValidationAPIClient(options) {
|
|
239
|
+
return new ValidationAPIClient(options);
|
|
240
|
+
}
|
|
241
|
+
//# sourceM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AC,UAAU,CAAC,OAAO,EAAE,EAAE,CAAC,CAAC,CAAC;IAC3D,CAAC;CACF;AAED;;;;;GAKG;AACH,MAAM,UAAU,yBAAyB,CACvC,OAAmC;IAEnC,OAAO,IAAI,mBAAmB,CAAC,OAAO,CAAC,CAAC;AAC1C,CAAC"}
|
|
@@ -0,0 +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"}
|
|
@@ -0,0 +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"}
|
|
@@ -0,0 +1,116 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* YAML rule loader and parser.
|
|
3
|
+
*
|
|
4
|
+
* Loads rules from YAML files and builds an indexed structure for
|
|
5
|
+
* efficient rule lookup during validation.
|
|
6
|
+
*
|
|
7
|
+
* @module rules/loader
|
|
8
|
+
*/
|
|
9
|
+
import type { Logger } from '../utils/logger.js';
|
|
10
|
+
import type { Rule, LoadedRules } from './types.js';
|
|
11
|
+
/**
|
|
12
|
+
* Options for the rule loader.
|
|
13
|
+
*/
|
|
14
|
+
export interface RuleLoaderOptions {
|
|
15
|
+
/** Logger instance */
|
|
16
|
+
logger: Logger;
|
|
17
|
+
/** Whether to watch for file changes (future feature) */
|
|
18
|
+
watch?: boolean;
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* YAML parser function type.
|
|
22
|
+
* Users must provide their own YAML parser (e.g., js-yaml).
|
|
23
|
+
*/
|
|
24
|
+
export type YamlParser = (content: string) => unknown;
|
|
25
|
+
/**
|
|
26
|
+
* Loads and manages YAML-based rules.
|
|
27
|
+
*/
|
|
28
|
+
export declare class RuleLoader {
|
|
29
|
+
private readonly logger;
|
|
30
|
+
private yamlParser;
|
|
31
|
+
private loadedRules;
|
|
32
|
+
constructor(options: RuleLoaderOptions);
|
|
33
|
+
/**
|
|
34
|
+
* Set the YAML parser to use for loading rules.
|
|
35
|
+
*
|
|
36
|
+
* @param parser - YAML parsing function
|
|
37
|
+
*
|
|
38
|
+
* @example
|
|
39
|
+
* ```typescript
|
|
40
|
+
* import yaml from 'js-yaml';
|
|
41
|
+
* loader.setYamlParser(yaml.load);
|
|
42
|
+
* ```
|
|
43
|
+
*/
|
|
44
|
+
setYamlParser(parser: YamlParser): void;
|
|
45
|
+
/**
|
|
46
|
+
* Load rules from a directory containing YAML files.
|
|
47
|
+
*
|
|
48
|
+
* @param dirPath - Path to the directory
|
|
49
|
+
* @param recursive - Whether to search subdirectories
|
|
50
|
+
* @returns Loaded rules
|
|
51
|
+
*/
|
|
52
|
+
loadFromDirectory(dirPath: string, recursive?: boolean): LoadedRules;
|
|
53
|
+
/**
|
|
54
|
+
* Load rules from a single YAML file.
|
|
55
|
+
*
|
|
56
|
+
* @param filePath - Path to the YAML file
|
|
57
|
+
*/
|
|
58
|
+
loadFromFile(filePath: string): void;
|
|
59
|
+
/**
|
|
60
|
+
* Load rules from a YAML string.
|
|
61
|
+
*
|
|
62
|
+
* @param content - YAML content
|
|
63
|
+
* @param sourceName - Name to identify the source
|
|
64
|
+
*/
|
|
65
|
+
loadFromString(content: string, sourceName?: string): void;
|
|
66
|
+
/**
|
|
67
|
+
* Add rules directly without YAML parsing.
|
|
68
|
+
*
|
|
69
|
+
* @param rules - Rules to add
|
|
70
|
+
* @param setName - Name for the rule set
|
|
71
|
+
*/
|
|
72
|
+
addRules(rules: Rule[], setName?: string): void;
|
|
73
|
+
/**
|
|
74
|
+
* Get all loaded rules.
|
|
75
|
+
*/
|
|
76
|
+
getRules(): LoadedRules;
|
|
77
|
+
/**
|
|
78
|
+
* Get rules applicable to a specific tool.
|
|
79
|
+
*
|
|
80
|
+
* @param toolName - Name of the tool
|
|
81
|
+
* @returns Rules that apply to the tool
|
|
82
|
+
*/
|
|
83
|
+
getRulesForTool(toolName: string): Rule[];
|
|
84
|
+
/**
|
|
85
|
+
* Clear all loaded rules.
|
|
86
|
+
*/
|
|
87
|
+
clear(): void;
|
|
88
|
+
/**
|
|
89
|
+
* Reload rules from previously loaded sources.
|
|
90
|
+
*/
|
|
91
|
+
reload(): LoadedRules;
|
|
92
|
+
/**
|
|
93
|
+
* Find YAML files in a directory.
|
|
94
|
+
*/
|
|
95
|
+
private findYamlFiles;
|
|
96
|
+
/**
|
|
97
|
+
* Parse a rule set from parsed YAML.
|
|
98
|
+
*/
|
|
99
|
+
private parseRuleSet;
|
|
100
|
+
/**
|
|
101
|
+
* Parse a single rule from YAML data.
|
|
102
|
+
*/
|
|
103
|
+
private parseRule;
|
|
104
|
+
/**
|
|
105
|
+
* Build the rule index for efficient lookup.
|
|
106
|
+
*/
|
|
107
|
+
private buildIndex;
|
|
108
|
+
}
|
|
109
|
+
/**
|
|
110
|
+
* Create a new rule loader.
|
|
111
|
+
*
|
|
112
|
+
* @param options - Loader options
|
|
113
|
+
* @returns RuleLoader instance
|
|
114
|
+
*/
|
|
115
|
+
export declare function createRuleLoader(options: RuleLoaderOptions): RuleLoader;
|
|
116
|
+
//# sourceMappingURL=loader.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"loader.d.ts","sourceRoot":"","sources":["../../src/rules/loader.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAIH,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,oBAAoB,CAAC;AACjD,OAAO,KAAK,EAAE,IAAI,EAAW,WAAW,EAAE,MAAM,YAAY,CAAC;AAE7D;;GAEG;AACH,MAAM,WAAW,iBAAiB;IAChC,sBAAsB;IACtB,MAA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