adonis-ai-kit 0.0.0-stage → 1.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/CHANGELOG.md +74 -0
- package/LICENSE +21 -0
- package/README.md +397 -2
- package/dist/commands/ai_test.d.ts +12 -0
- package/dist/commands/ai_test.d.ts.map +1 -0
- package/dist/commands/ai_test.js +98 -0
- package/dist/commands/ai_test.js.map +1 -0
- package/dist/commands/main.d.ts +14 -0
- package/dist/commands/main.d.ts.map +1 -0
- package/dist/commands/main.js +31 -0
- package/dist/commands/main.js.map +1 -0
- package/dist/commands/make_agent.d.ts +13 -0
- package/dist/commands/make_agent.d.ts.map +1 -0
- package/dist/commands/make_agent.js +116 -0
- package/dist/commands/make_agent.js.map +1 -0
- package/dist/providers/ai_provider.d.ts +23 -0
- package/dist/providers/ai_provider.d.ts.map +1 -0
- package/dist/providers/ai_provider.js +34 -0
- package/dist/providers/ai_provider.js.map +1 -0
- package/dist/services/main.d.ts +4 -0
- package/dist/services/main.d.ts.map +1 -0
- package/dist/services/main.js +7 -0
- package/dist/services/main.js.map +1 -0
- package/dist/src/acp/acp_agents.d.ts +89 -0
- package/dist/src/acp/acp_agents.d.ts.map +1 -0
- package/dist/src/acp/acp_agents.js +367 -0
- package/dist/src/acp/acp_agents.js.map +1 -0
- package/dist/src/acp/index.d.ts +4 -0
- package/dist/src/acp/index.d.ts.map +1 -0
- package/dist/src/acp/index.js +4 -0
- package/dist/src/acp/index.js.map +1 -0
- package/dist/src/acp/provider.d.ts +74 -0
- package/dist/src/acp/provider.d.ts.map +1 -0
- package/dist/src/acp/provider.js +276 -0
- package/dist/src/acp/provider.js.map +1 -0
- package/dist/src/acp/types.d.ts +128 -0
- package/dist/src/acp/types.d.ts.map +1 -0
- package/dist/src/acp/types.js +2 -0
- package/dist/src/acp/types.js.map +1 -0
- package/dist/src/agents/agent_runner.d.ts +60 -0
- package/dist/src/agents/agent_runner.d.ts.map +1 -0
- package/dist/src/agents/agent_runner.js +134 -0
- package/dist/src/agents/agent_runner.js.map +1 -0
- package/dist/src/agents/index.d.ts +4 -0
- package/dist/src/agents/index.d.ts.map +1 -0
- package/dist/src/agents/index.js +4 -0
- package/dist/src/agents/index.js.map +1 -0
- package/dist/src/agents/loader.d.ts +56 -0
- package/dist/src/agents/loader.d.ts.map +1 -0
- package/dist/src/agents/loader.js +184 -0
- package/dist/src/agents/loader.js.map +1 -0
- package/dist/src/agents/manifest.d.ts +61 -0
- package/dist/src/agents/manifest.d.ts.map +1 -0
- package/dist/src/agents/manifest.js +35 -0
- package/dist/src/agents/manifest.js.map +1 -0
- package/dist/src/ai_manager.d.ts +140 -0
- package/dist/src/ai_manager.d.ts.map +1 -0
- package/dist/src/ai_manager.js +814 -0
- package/dist/src/ai_manager.js.map +1 -0
- package/dist/src/budget/budget_allocator.d.ts +37 -0
- package/dist/src/budget/budget_allocator.d.ts.map +1 -0
- package/dist/src/budget/budget_allocator.js +98 -0
- package/dist/src/budget/budget_allocator.js.map +1 -0
- package/dist/src/budget/budget_enforcer.d.ts +70 -0
- package/dist/src/budget/budget_enforcer.d.ts.map +1 -0
- package/dist/src/budget/budget_enforcer.js +195 -0
- package/dist/src/budget/budget_enforcer.js.map +1 -0
- package/dist/src/budget/cost_tracker.d.ts +71 -0
- package/dist/src/budget/cost_tracker.d.ts.map +1 -0
- package/dist/src/budget/cost_tracker.js +199 -0
- package/dist/src/budget/cost_tracker.js.map +1 -0
- package/dist/src/budget/index.d.ts +6 -0
- package/dist/src/budget/index.d.ts.map +1 -0
- package/dist/src/budget/index.js +6 -0
- package/dist/src/budget/index.js.map +1 -0
- package/dist/src/budget/pricing.d.ts +35 -0
- package/dist/src/budget/pricing.d.ts.map +1 -0
- package/dist/src/budget/pricing.js +129 -0
- package/dist/src/budget/pricing.js.map +1 -0
- package/dist/src/budget/types.d.ts +86 -0
- package/dist/src/budget/types.d.ts.map +1 -0
- package/dist/src/budget/types.js +2 -0
- package/dist/src/budget/types.js.map +1 -0
- package/dist/src/catalog/index.d.ts +3 -0
- package/dist/src/catalog/index.d.ts.map +1 -0
- package/dist/src/catalog/index.js +3 -0
- package/dist/src/catalog/index.js.map +1 -0
- package/dist/src/catalog/models_dev.d.ts +87 -0
- package/dist/src/catalog/models_dev.d.ts.map +1 -0
- package/dist/src/catalog/models_dev.js +38 -0
- package/dist/src/catalog/models_dev.js.map +1 -0
- package/dist/src/catalog/source.d.ts +67 -0
- package/dist/src/catalog/source.d.ts.map +1 -0
- package/dist/src/catalog/source.js +678 -0
- package/dist/src/catalog/source.js.map +1 -0
- package/dist/src/circuit_breaker.d.ts +61 -0
- package/dist/src/circuit_breaker.d.ts.map +1 -0
- package/dist/src/circuit_breaker.js +217 -0
- package/dist/src/circuit_breaker.js.map +1 -0
- package/dist/src/define_config.d.ts +11 -0
- package/dist/src/define_config.d.ts.map +1 -0
- package/dist/src/define_config.js +48 -0
- package/dist/src/define_config.js.map +1 -0
- package/dist/src/error_classifier.d.ts +50 -0
- package/dist/src/error_classifier.d.ts.map +1 -0
- package/dist/src/error_classifier.js +206 -0
- package/dist/src/error_classifier.js.map +1 -0
- package/dist/src/errors.d.ts +52 -0
- package/dist/src/errors.d.ts.map +1 -0
- package/dist/src/errors.js +70 -0
- package/dist/src/errors.js.map +1 -0
- package/dist/src/guard/confirmation.d.ts +67 -0
- package/dist/src/guard/confirmation.d.ts.map +1 -0
- package/dist/src/guard/confirmation.js +180 -0
- package/dist/src/guard/confirmation.js.map +1 -0
- package/dist/src/guard/errors.d.ts +10 -0
- package/dist/src/guard/errors.d.ts.map +1 -0
- package/dist/src/guard/errors.js +14 -0
- package/dist/src/guard/errors.js.map +1 -0
- package/dist/src/guard/guard.d.ts +47 -0
- package/dist/src/guard/guard.d.ts.map +1 -0
- package/dist/src/guard/guard.js +133 -0
- package/dist/src/guard/guard.js.map +1 -0
- package/dist/src/guard/index.d.ts +7 -0
- package/dist/src/guard/index.d.ts.map +1 -0
- package/dist/src/guard/index.js +7 -0
- package/dist/src/guard/index.js.map +1 -0
- package/dist/src/guard/registry.d.ts +72 -0
- package/dist/src/guard/registry.d.ts.map +1 -0
- package/dist/src/guard/registry.js +192 -0
- package/dist/src/guard/registry.js.map +1 -0
- package/dist/src/guard/schema_registry.d.ts +37 -0
- package/dist/src/guard/schema_registry.d.ts.map +1 -0
- package/dist/src/guard/schema_registry.js +57 -0
- package/dist/src/guard/schema_registry.js.map +1 -0
- package/dist/src/guard/types.d.ts +63 -0
- package/dist/src/guard/types.d.ts.map +1 -0
- package/dist/src/guard/types.js +2 -0
- package/dist/src/guard/types.js.map +1 -0
- package/dist/src/index.d.ts +16 -0
- package/dist/src/index.d.ts.map +1 -0
- package/dist/src/index.js +14 -0
- package/dist/src/index.js.map +1 -0
- package/dist/src/logger.d.ts +7 -0
- package/dist/src/logger.d.ts.map +1 -0
- package/dist/src/logger.js +2 -0
- package/dist/src/logger.js.map +1 -0
- package/dist/src/models/catalog_resolver.d.ts +24 -0
- package/dist/src/models/catalog_resolver.d.ts.map +1 -0
- package/dist/src/models/catalog_resolver.js +66 -0
- package/dist/src/models/catalog_resolver.js.map +1 -0
- package/dist/src/models/index.d.ts +14 -0
- package/dist/src/models/index.d.ts.map +1 -0
- package/dist/src/models/index.js +8 -0
- package/dist/src/models/index.js.map +1 -0
- package/dist/src/models/keys.d.ts +9 -0
- package/dist/src/models/keys.d.ts.map +1 -0
- package/dist/src/models/keys.js +12 -0
- package/dist/src/models/keys.js.map +1 -0
- package/dist/src/models/language_model_factory.d.ts +44 -0
- package/dist/src/models/language_model_factory.d.ts.map +1 -0
- package/dist/src/models/language_model_factory.js +193 -0
- package/dist/src/models/language_model_factory.js.map +1 -0
- package/dist/src/models/model_chain.d.ts +58 -0
- package/dist/src/models/model_chain.d.ts.map +1 -0
- package/dist/src/models/model_chain.js +144 -0
- package/dist/src/models/model_chain.js.map +1 -0
- package/dist/src/models/model_ref.d.ts +12 -0
- package/dist/src/models/model_ref.d.ts.map +1 -0
- package/dist/src/models/model_ref.js +33 -0
- package/dist/src/models/model_ref.js.map +1 -0
- package/dist/src/models/protocols.d.ts +6 -0
- package/dist/src/models/protocols.d.ts.map +1 -0
- package/dist/src/models/protocols.js +33 -0
- package/dist/src/models/protocols.js.map +1 -0
- package/dist/src/models/provider_factories.d.ts +19 -0
- package/dist/src/models/provider_factories.d.ts.map +1 -0
- package/dist/src/models/provider_factories.js +70 -0
- package/dist/src/models/provider_factories.js.map +1 -0
- package/dist/src/models/types.d.ts +17 -0
- package/dist/src/models/types.d.ts.map +1 -0
- package/dist/src/models/types.js +2 -0
- package/dist/src/models/types.js.map +1 -0
- package/dist/src/response_macro.d.ts +16 -0
- package/dist/src/response_macro.d.ts.map +1 -0
- package/dist/src/response_macro.js +151 -0
- package/dist/src/response_macro.js.map +1 -0
- package/dist/src/types.d.ts +340 -0
- package/dist/src/types.d.ts.map +1 -0
- package/dist/src/types.js +2 -0
- package/dist/src/types.js.map +1 -0
- package/dist/src/usage.d.ts +13 -0
- package/dist/src/usage.d.ts.map +1 -0
- package/dist/src/usage.js +61 -0
- package/dist/src/usage.js.map +1 -0
- package/package.json +208 -4
|
@@ -0,0 +1,206 @@
|
|
|
1
|
+
import { AiException, ProviderUnavailableError } from './errors.js';
|
|
2
|
+
const NETWORK_CODES = new Set([
|
|
3
|
+
'ECONNRESET',
|
|
4
|
+
'ECONNREFUSED',
|
|
5
|
+
'ECONNABORTED',
|
|
6
|
+
'ETIMEDOUT',
|
|
7
|
+
'ENOTFOUND',
|
|
8
|
+
'EAI_AGAIN',
|
|
9
|
+
'EPIPE',
|
|
10
|
+
'EHOSTUNREACH',
|
|
11
|
+
'ENETUNREACH',
|
|
12
|
+
'UND_ERR_SOCKET',
|
|
13
|
+
'UND_ERR_CONNECT_TIMEOUT',
|
|
14
|
+
'UND_ERR_HEADERS_TIMEOUT',
|
|
15
|
+
'UND_ERR_BODY_TIMEOUT',
|
|
16
|
+
]);
|
|
17
|
+
const FATAL_NAMES = new Set([
|
|
18
|
+
'AI_TypeValidationError',
|
|
19
|
+
'AI_InvalidPromptError',
|
|
20
|
+
'AI_InvalidArgumentError',
|
|
21
|
+
'AI_NoObjectGeneratedError',
|
|
22
|
+
'AI_NoSuchToolError',
|
|
23
|
+
'AI_InvalidToolInputError',
|
|
24
|
+
'AI_JSONParseError',
|
|
25
|
+
'AI_UnsupportedFunctionalityError',
|
|
26
|
+
'AI_LoadAPIKeyError',
|
|
27
|
+
'ZodError',
|
|
28
|
+
]);
|
|
29
|
+
const NETWORK_MESSAGE = /fetch failed|network|socket hang up|timed? ?out|connection (reset|refused|closed)/i;
|
|
30
|
+
/**
|
|
31
|
+
* Returns the first value `pick` extracts from the error or from its `cause` / `lastError`
|
|
32
|
+
* chain (AI SDK `RetryError` keeps the real failure in `lastError`), looking at most `depth` levels down.
|
|
33
|
+
*/
|
|
34
|
+
function findErrorField(error, pick, depth = 5) {
|
|
35
|
+
if (error === null || typeof error !== 'object')
|
|
36
|
+
return undefined;
|
|
37
|
+
const node = error;
|
|
38
|
+
const own = pick(node);
|
|
39
|
+
if (own !== undefined)
|
|
40
|
+
return own;
|
|
41
|
+
if (depth <= 0)
|
|
42
|
+
return undefined;
|
|
43
|
+
return findErrorField(node.cause, pick, depth - 1) ?? findErrorField(node.lastError, pick, depth - 1);
|
|
44
|
+
}
|
|
45
|
+
const asNumber = (v) => (typeof v === 'number' ? v : undefined);
|
|
46
|
+
function statusOf(error) {
|
|
47
|
+
return findErrorField(error, (n) => asNumber(n.statusCode) ?? asNumber(n.status) ?? asNumber(n.response?.status));
|
|
48
|
+
}
|
|
49
|
+
function codeOf(error) {
|
|
50
|
+
return findErrorField(error, (n) => (typeof n.code === 'string' ? n.code : undefined));
|
|
51
|
+
}
|
|
52
|
+
function classByStatusCode(status, message) {
|
|
53
|
+
if (status === 429)
|
|
54
|
+
return 'rate_limit';
|
|
55
|
+
if (status === 529 || status === 409 || status === 425)
|
|
56
|
+
return 'overloaded';
|
|
57
|
+
if (status === 408)
|
|
58
|
+
return 'timeout';
|
|
59
|
+
if (status === 401 || status === 403)
|
|
60
|
+
return 'auth_error';
|
|
61
|
+
if (status === 404)
|
|
62
|
+
return 'model_not_found';
|
|
63
|
+
if (status === 400) {
|
|
64
|
+
if (message.includes('too long') || message.includes('max_tokens') || message.includes('context length')) {
|
|
65
|
+
return 'prompt_too_long';
|
|
66
|
+
}
|
|
67
|
+
return 'invalid_request';
|
|
68
|
+
}
|
|
69
|
+
if (status >= 500)
|
|
70
|
+
return 'server_error';
|
|
71
|
+
return 'unknown';
|
|
72
|
+
}
|
|
73
|
+
/**
|
|
74
|
+
* Classifies an error into the fine-grained {@link ErrorClass} taxonomy.
|
|
75
|
+
* The HTTP status and error code are looked up through the `cause` / `lastError` chain.
|
|
76
|
+
*/
|
|
77
|
+
export function classifyErrorClass(error) {
|
|
78
|
+
const isObject = error !== null && typeof error === 'object';
|
|
79
|
+
const name = isObject ? error.name : undefined;
|
|
80
|
+
const message = isObject ? String(error.message ?? '') : '';
|
|
81
|
+
const status = statusOf(error);
|
|
82
|
+
if (status !== undefined)
|
|
83
|
+
return classByStatusCode(status, message);
|
|
84
|
+
if (name === 'AI_NoOutputGeneratedError' || name === 'NoOutputGeneratedError') {
|
|
85
|
+
if (message.includes('403') || message.includes('401'))
|
|
86
|
+
return 'auth_error';
|
|
87
|
+
if (message.includes('429'))
|
|
88
|
+
return 'rate_limit';
|
|
89
|
+
if (message.includes('500') || message.includes('502') || message.includes('503'))
|
|
90
|
+
return 'server_error';
|
|
91
|
+
return 'no_output_generated';
|
|
92
|
+
}
|
|
93
|
+
if (name === 'TimeoutError')
|
|
94
|
+
return 'timeout';
|
|
95
|
+
const code = codeOf(error);
|
|
96
|
+
if (code && NETWORK_CODES.has(code))
|
|
97
|
+
return 'network_error';
|
|
98
|
+
if (message.includes('fetch failed') || message.includes('ECONNREFUSED') || message.includes('ENOTFOUND')) {
|
|
99
|
+
return 'network_error';
|
|
100
|
+
}
|
|
101
|
+
if (message.includes('timeout') || message.includes('ETIMEDOUT'))
|
|
102
|
+
return 'timeout';
|
|
103
|
+
if (message.includes('too long') || message.includes('context length'))
|
|
104
|
+
return 'prompt_too_long';
|
|
105
|
+
return 'unknown';
|
|
106
|
+
}
|
|
107
|
+
const RETRYABLE_ERROR_CLASSES = new Set([
|
|
108
|
+
'rate_limit',
|
|
109
|
+
'overloaded',
|
|
110
|
+
'timeout',
|
|
111
|
+
'server_error',
|
|
112
|
+
'network_error',
|
|
113
|
+
'prompt_too_long',
|
|
114
|
+
'no_output_generated',
|
|
115
|
+
]);
|
|
116
|
+
/**
|
|
117
|
+
* Whether an error class is transient and therefore eligible for fallback routing.
|
|
118
|
+
*/
|
|
119
|
+
export function isRetryableError(errorClass) {
|
|
120
|
+
return RETRYABLE_ERROR_CLASSES.has(errorClass);
|
|
121
|
+
}
|
|
122
|
+
const BREAKER_ERROR_CLASSES = new Set([
|
|
123
|
+
'rate_limit',
|
|
124
|
+
'overloaded',
|
|
125
|
+
'timeout',
|
|
126
|
+
'server_error',
|
|
127
|
+
'network_error',
|
|
128
|
+
]);
|
|
129
|
+
/**
|
|
130
|
+
* Whether an error class reflects upstream health and should count against the circuit breaker.
|
|
131
|
+
* `prompt_too_long` and `no_output_generated` fall back to another model but never open the breaker.
|
|
132
|
+
*/
|
|
133
|
+
export function countsAsBreakerFailure(errorClass) {
|
|
134
|
+
return BREAKER_ERROR_CLASSES.has(errorClass);
|
|
135
|
+
}
|
|
136
|
+
/**
|
|
137
|
+
* Classifies an error for fallback / circuit-breaker decisions.
|
|
138
|
+
* `abortSignal` is the caller's signal: when it is aborted the failure is the caller's doing.
|
|
139
|
+
*/
|
|
140
|
+
export function classifyError(error, abortSignal) {
|
|
141
|
+
const outcome = (kind, reason, errorClass = 'unknown') => ({
|
|
142
|
+
kind,
|
|
143
|
+
reason,
|
|
144
|
+
errorClass,
|
|
145
|
+
countsAsFailure: kind === 'retryable' && countsAsBreakerFailure(errorClass),
|
|
146
|
+
});
|
|
147
|
+
if (abortSignal?.aborted)
|
|
148
|
+
return outcome('fatal', 'aborted by caller');
|
|
149
|
+
if (error instanceof ProviderUnavailableError)
|
|
150
|
+
return outcome('skip', 'circuit breaker open');
|
|
151
|
+
if (error instanceof AiException &&
|
|
152
|
+
(error.code === 'E_AI_MISSING_DEPENDENCY' || error.code === 'E_AI_CONFIG_ERROR')) {
|
|
153
|
+
return outcome('skip', error.code);
|
|
154
|
+
}
|
|
155
|
+
if (error === null || typeof error !== 'object')
|
|
156
|
+
return outcome('fatal', 'unknown error');
|
|
157
|
+
const err = error;
|
|
158
|
+
if (err.name === 'AbortError')
|
|
159
|
+
return outcome('fatal', 'aborted');
|
|
160
|
+
if (FATAL_NAMES.has(err.name))
|
|
161
|
+
return outcome('fatal', `validation (${err.name})`);
|
|
162
|
+
const errorClass = classifyErrorClass(error);
|
|
163
|
+
if (isRetryableError(errorClass))
|
|
164
|
+
return outcome('retryable', errorClass, errorClass);
|
|
165
|
+
if (errorClass !== 'unknown')
|
|
166
|
+
return outcome('fatal', errorClass, errorClass);
|
|
167
|
+
// Unclassified: keep the loose heuristics, but never override an explicit HTTP status.
|
|
168
|
+
if (statusOf(error) === undefined) {
|
|
169
|
+
if (NETWORK_MESSAGE.test(typeof err.message === 'string' ? err.message : '')) {
|
|
170
|
+
return outcome('retryable', 'network', 'network_error');
|
|
171
|
+
}
|
|
172
|
+
if (err.isRetryable === true)
|
|
173
|
+
return outcome('retryable', 'provider marked retryable');
|
|
174
|
+
}
|
|
175
|
+
return outcome('fatal', 'unclassified error');
|
|
176
|
+
}
|
|
177
|
+
/**
|
|
178
|
+
* Human-readable message for an error class, safe to show to an operator.
|
|
179
|
+
*/
|
|
180
|
+
export function getUserFriendlyMessage(errorClass) {
|
|
181
|
+
switch (errorClass) {
|
|
182
|
+
case 'rate_limit':
|
|
183
|
+
return 'Rate limited by API provider';
|
|
184
|
+
case 'overloaded':
|
|
185
|
+
return 'API provider overloaded';
|
|
186
|
+
case 'timeout':
|
|
187
|
+
return 'API request timed out';
|
|
188
|
+
case 'auth_error':
|
|
189
|
+
return 'API authentication failed — check API key';
|
|
190
|
+
case 'model_not_found':
|
|
191
|
+
return 'Model not found — check LLM_MODEL config';
|
|
192
|
+
case 'prompt_too_long':
|
|
193
|
+
return 'Context too large for model — consider compaction';
|
|
194
|
+
case 'invalid_request':
|
|
195
|
+
return 'Invalid API request';
|
|
196
|
+
case 'server_error':
|
|
197
|
+
return 'API server error';
|
|
198
|
+
case 'network_error':
|
|
199
|
+
return 'Network error — check connectivity';
|
|
200
|
+
case 'no_output_generated':
|
|
201
|
+
return 'Model produced no output — transient error, will retry';
|
|
202
|
+
default:
|
|
203
|
+
return 'Unknown API error';
|
|
204
|
+
}
|
|
205
|
+
}
|
|
206
|
+
//# sourceMappingURL=error_classifier.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"error_classifier.js","sourceRoot":"","sources":["../../src/error_classifier.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,wBAAwB,EAAE,MAAM,aAAa,CAAA;AAsBnE,MAAM,aAAa,GAAG,IAAI,GAAG,CAAC;IAC5B,YAAY;IACZ,cAAc;IACd,cAAc;IACd,WAAW;IACX,WAAW;IACX,WAAW;IACX,OAAO;IACP,cAAc;IACd,aAAa;IACb,gBAAgB;IAChB,yBAAyB;IACzB,yBAAyB;IACzB,sBAAsB;CACvB,CAAC,CAAA;AAEF,MAAM,WAAW,GAAG,IAAI,GAAG,CAAC;IAC1B,wBAAwB;IACxB,uBAAuB;IACvB,yBAAyB;IACzB,2BAA2B;IAC3B,oBAAoB;IACpB,0BAA0B;IAC1B,mBAAmB;IACnB,kCAAkC;IAClC,oBAAoB;IACpB,UAAU;CACX,CAAC,CAAA;AAEF,MAAM,eAAe,GAAG,oFAAoF,CAAA;AAE5G;;;GAGG;AACH,SAAS,cAAc,CACrB,KAAc,EACd,IAAkD,EAClD,KAAK,GAAG,CAAC;IAET,IAAI,KAAK,KAAK,IAAI,IAAI,OAAO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c;YACjB,OAAO,kBAAkB,CAAA;QAC3B,KAAK,eAAe;YAClB,OAAO,oCAAoC,CAAA;QAC7C,KAAK,qBAAqB;YACxB,OAAO,wDAAwD,CAAA;QACjE;YACE,OAAO,mBAAmB,CAAA;IAC9B,CAAC;AACH,CAAC"}
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Base exception class for all Adonis AI package errors.
|
|
3
|
+
*/
|
|
4
|
+
export declare class AiException extends Error {
|
|
5
|
+
code: string;
|
|
6
|
+
cause?: unknown | undefined;
|
|
7
|
+
constructor(message: string, code?: string, cause?: unknown | undefined);
|
|
8
|
+
}
|
|
9
|
+
/**
|
|
10
|
+
* Thrown when an AI provider is unreachable or circuit breaker is open.
|
|
11
|
+
*/
|
|
12
|
+
export declare class ProviderUnavailableError extends AiException {
|
|
13
|
+
provider: string;
|
|
14
|
+
constructor(provider: string, reason?: string);
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* Thrown when provider configuration is invalid or missing required credentials.
|
|
18
|
+
*/
|
|
19
|
+
export declare class ProviderConfigError extends AiException {
|
|
20
|
+
provider: string;
|
|
21
|
+
constructor(provider: string, message: string);
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* Thrown when primary provider and all fallback cascade providers fail.
|
|
25
|
+
*/
|
|
26
|
+
export declare class CascadingFallbackError extends AiException {
|
|
27
|
+
attempts: Array<{
|
|
28
|
+
provider: string;
|
|
29
|
+
model: string;
|
|
30
|
+
error: Error;
|
|
31
|
+
}>;
|
|
32
|
+
constructor(attempts: Array<{
|
|
33
|
+
provider: string;
|
|
34
|
+
model: string;
|
|
35
|
+
error: Error;
|
|
36
|
+
}>);
|
|
37
|
+
}
|
|
38
|
+
/**
|
|
39
|
+
* Thrown when token or cost budget thresholds are exceeded.
|
|
40
|
+
*/
|
|
41
|
+
export declare class BudgetExceededError extends AiException {
|
|
42
|
+
currentUsage?: unknown | undefined;
|
|
43
|
+
constructor(message: string, currentUsage?: unknown | undefined);
|
|
44
|
+
}
|
|
45
|
+
/**
|
|
46
|
+
* Thrown when a tool execution is rejected by security policy or fails during run.
|
|
47
|
+
*/
|
|
48
|
+
export declare class ToolExecutionError extends AiException {
|
|
49
|
+
toolName: string;
|
|
50
|
+
constructor(toolName: string, message: string, cause?: unknown);
|
|
51
|
+
}
|
|
52
|
+
//# sourceMappingURL=errors.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"errors.d.ts","sourceRoot":"","sources":["../../src/errors.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,qBAAa,WAAY,SAAQ,KAAK;IAG3B,IAAI,EAAE,MAAM;IACZ,KAAK,CAAC,EAAE,OAAO;gBAFtB,OAAO,EAAE,MAAM,EACR,IAAI,GAAE,MAAqB,EAC3B,KAAK,CAAC,EAAE,OAAO,YAAA;CAKzB;AAED;;GAEG;AACH,qBAAa,wBAAyB,SAAQ,WAAW;IACpC,QAAQ,EAAE,MAAM;gBAAhB,QAAQ,EAAE,MAAM,EAAE,MAAM,CAAC,EAAE,MAAM;CAOrD;AAED;;GAEG;AACH,qBAAa,mBAAoB,SAAQ,WAAW;IAC/B,QAAQ,EAAE,MAAM;gBAAhB,QAAQ,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM;CAIrD;AAED;;GAEG;AACH,qBAAa,sBAAuB,SAAQ,WAAW;IAClC,QAAQ,EAAE,KAAK,CAAC;QAAE,QAAQ,EAAE,MAAM,CAAC;QAAC,KAAK,EAAE,MAAM,CAAC;QAAC,KAAK,EAAE,KAAK,CAAA;KAAE,CAAC;gBAAlE,QAAQ,EAAE,KAAK,CAAC;QAAE,QAAQ,EAAE,MAAM,CAAC;QAAC,KAAK,EAAE,MAAM,CAAC;QAAC,KAAK,EAAE,KAAK,CAAA;KAAE,CAAC;CAKtF;AAED;;GAEG;AACH,qBAAa,mBAAoB,SAAQ,WAAW;IACd,YAAY,CAAC,EAAE,OAAO;gBAA9C,OAAO,EAAE,MAAM,EAAS,YAAY,CAAC,EAAE,OAAO,YAAA;CAI3D;AAED;;GAEG;AACH,qBAAa,kBAAmB,SAAQ,WAAW;IAC9B,QAAQ,EAAE,MAAM;gBAAhB,QAAQ,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,EAAE,KAAK,CAAC,EAAE,OAAO;CAItE"}
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Base exception class for all Adonis AI package errors.
|
|
3
|
+
*/
|
|
4
|
+
export class AiException extends Error {
|
|
5
|
+
code;
|
|
6
|
+
cause;
|
|
7
|
+
constructor(message, code = 'E_AI_ERROR', cause) {
|
|
8
|
+
super(message);
|
|
9
|
+
this.code = code;
|
|
10
|
+
this.cause = cause;
|
|
11
|
+
this.name = 'AiException';
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
/**
|
|
15
|
+
* Thrown when an AI provider is unreachable or circuit breaker is open.
|
|
16
|
+
*/
|
|
17
|
+
export class ProviderUnavailableError extends AiException {
|
|
18
|
+
provider;
|
|
19
|
+
constructor(provider, reason) {
|
|
20
|
+
super(`AI provider "${provider}" is currently unavailable: ${reason ?? 'Circuit breaker is OPEN'}`, 'E_AI_PROVIDER_UNAVAILABLE');
|
|
21
|
+
this.provider = provider;
|
|
22
|
+
this.name = 'ProviderUnavailableError';
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* Thrown when provider configuration is invalid or missing required credentials.
|
|
27
|
+
*/
|
|
28
|
+
export class ProviderConfigError extends AiException {
|
|
29
|
+
provider;
|
|
30
|
+
constructor(provider, message) {
|
|
31
|
+
super(`Invalid configuration for AI provider "${provider}": ${message}`, 'E_AI_CONFIG_ERROR');
|
|
32
|
+
this.provider = provider;
|
|
33
|
+
this.name = 'ProviderConfigError';
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* Thrown when primary provider and all fallback cascade providers fail.
|
|
38
|
+
*/
|
|
39
|
+
export class CascadingFallbackError extends AiException {
|
|
40
|
+
attempts;
|
|
41
|
+
constructor(attempts) {
|
|
42
|
+
const errorDetails = attempts.map((a) => `[${a.provider}:${a.model}] ${a.error.message}`).join('; ');
|
|
43
|
+
super(`All AI fallback providers failed: ${errorDetails}`, 'E_AI_FALLBACK_FAILED');
|
|
44
|
+
this.attempts = attempts;
|
|
45
|
+
this.name = 'CascadingFallbackError';
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
/**
|
|
49
|
+
* Thrown when token or cost budget thresholds are exceeded.
|
|
50
|
+
*/
|
|
51
|
+
export class BudgetExceededError extends AiException {
|
|
52
|
+
currentUsage;
|
|
53
|
+
constructor(message, currentUsage) {
|
|
54
|
+
super(message, 'E_AI_BUDGET_EXCEEDED');
|
|
55
|
+
this.currentUsage = currentUsage;
|
|
56
|
+
this.name = 'BudgetExceededError';
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
/**
|
|
60
|
+
* Thrown when a tool execution is rejected by security policy or fails during run.
|
|
61
|
+
*/
|
|
62
|
+
export class ToolExecutionError extends AiException {
|
|
63
|
+
toolName;
|
|
64
|
+
constructor(toolName, message, cause) {
|
|
65
|
+
super(`Tool execution error for "${toolName}": ${message}`, 'E_AI_TOOL_EXECUTION_ERROR', cause);
|
|
66
|
+
this.toolName = toolName;
|
|
67
|
+
this.name = 'ToolExecutionError';
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
//# sourceMappingURL=errors.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"errors.js","sourceRoot":"","sources":["../../src/errors.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,MAAM,OAAO,WAAY,SAAQ,KAAK;IAG3B;IACA;IAHT,YACE,OAAe,EACR,OAAe,YAAY,EAC3B,KAAe;QAEtB,KAAK,CAAC,OAAO,CAAC,CAAA;QAHP,SAAI,GAAJ,IAAI,CAAuB;QAC3B,UAAK,GAAL,KAAK,CAAU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AAU;QAExD,IAAI,CAAC,IAAI,GAAG,qBAAqB,CAAA;IACnC,CAAC;CACF;AAED;;GAEG;AACH,MAAM,OAAO,kBAAmB,SAAQ,WAAW;IAC9B;IAAnB,YAAmB,QAAgB,EAAE,OAAe,EAAE,KAAe;QACnE,KAAK,CAAC,6BAA6B,QAAQ,MAAM,OAAO,EAAE,EAAE,2BAA2B,EAAE,KAAK,CAAC,CAAA;QAD9E,aAAQ,GAAR,QAAQ,CAAQ;QAEjC,IAAI,CAAC,IAAI,GAAG,oBAAoB,CAAA;IAClC,CAAC;CACF"}
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
import type { ConfirmationResponse, Logger, PendingAction } from './types.js';
|
|
2
|
+
export type ConfirmationCallback = (response: ConfirmationResponse) => void;
|
|
3
|
+
export type ActionCreatedListener = (action: PendingAction) => void;
|
|
4
|
+
export type ActionResolvedListener = (action: PendingAction, response: ConfirmationResponse) => void;
|
|
5
|
+
export interface ConfirmationServiceOptions {
|
|
6
|
+
defaultTimeoutMs?: number;
|
|
7
|
+
logger?: Logger;
|
|
8
|
+
}
|
|
9
|
+
/** Largest delay `setTimeout` accepts; larger values fire after ~1ms with a TimeoutOverflowWarning. */
|
|
10
|
+
export declare const MAX_TIMEOUT_MS: number;
|
|
11
|
+
/**
|
|
12
|
+
* Manages human-in-the-loop confirmations for sensitive or irreversible actions.
|
|
13
|
+
*
|
|
14
|
+
* Actions are kept in memory with a configurable TTL.
|
|
15
|
+
* External interfaces (web UI, telegram bots, webhooks) approve or reject them.
|
|
16
|
+
* If no response arrives within the timeout window, the action automatically times out.
|
|
17
|
+
*
|
|
18
|
+
* Timers are `unref()`'d so a pending confirmation never keeps the process alive; call
|
|
19
|
+
* `dispose()` on shutdown to settle everything that is still pending.
|
|
20
|
+
*/
|
|
21
|
+
export declare class ConfirmationService {
|
|
22
|
+
private pending;
|
|
23
|
+
private defaultTimeoutMs;
|
|
24
|
+
private logger?;
|
|
25
|
+
private createdListeners;
|
|
26
|
+
private resolvedListeners;
|
|
27
|
+
private disposed;
|
|
28
|
+
constructor(opts?: ConfirmationServiceOptions);
|
|
29
|
+
setLogger(logger: Logger): void;
|
|
30
|
+
onActionCreated(listener: ActionCreatedListener): () => void;
|
|
31
|
+
onActionResolved(listener: ActionResolvedListener): () => void;
|
|
32
|
+
/**
|
|
33
|
+
* Create a pending action and wait for human confirmation, timeout, or abort.
|
|
34
|
+
* Never approves implicitly: timeout, abort and disposal all resolve as non-approved.
|
|
35
|
+
*/
|
|
36
|
+
waitForResponse(action: Omit<PendingAction, 'id' | 'status' | 'createdAt' | 'expiresAt'>, timeoutMs?: number, abortSignal?: AbortSignal): Promise<ConfirmationResponse>;
|
|
37
|
+
/**
|
|
38
|
+
* Approve a pending action. If the action is bound to a session, the caller must present the
|
|
39
|
+
* same `sessionId`; otherwise the approval is refused and the action stays pending.
|
|
40
|
+
*/
|
|
41
|
+
approve(actionId: string, reason?: string, sessionId?: string): boolean;
|
|
42
|
+
/**
|
|
43
|
+
* Reject a pending action. Same session binding rules as `approve()`.
|
|
44
|
+
*/
|
|
45
|
+
reject(actionId: string, reason?: string, sessionId?: string): boolean;
|
|
46
|
+
/**
|
|
47
|
+
* List current pending actions, optionally restricted to one session.
|
|
48
|
+
*/
|
|
49
|
+
getPendingActions(sessionId?: string): PendingAction[];
|
|
50
|
+
/**
|
|
51
|
+
* Get a specific pending action by ID.
|
|
52
|
+
*/
|
|
53
|
+
getPendingAction(actionId: string): PendingAction | null;
|
|
54
|
+
/**
|
|
55
|
+
* Resolves expired items as `timeout`, invoking `onActionResolved` listeners.
|
|
56
|
+
*/
|
|
57
|
+
clearExpired(): void;
|
|
58
|
+
/**
|
|
59
|
+
* Settles every pending action as rejected, clears timers and listeners.
|
|
60
|
+
* Further `waitForResponse()` calls resolve as rejected immediately.
|
|
61
|
+
*/
|
|
62
|
+
dispose(): void;
|
|
63
|
+
private resolveAction;
|
|
64
|
+
private notifyCreated;
|
|
65
|
+
private notifyResolved;
|
|
66
|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A8B,EACzC,WAAW,CAAC,EAAE,WAAW,GACxB,OAAO,CAAC,oBAAoB,CAAC;IAgEhC;;;OAGG;IACH,OAAO,CAAC,QAAQ,EAAE,MAAM,EAAE,MAAM,CAAC,EAAE,MAAM,EAAE,SAAS,CAAC,EAAE,MAAM,GAAG,OAAO;IAIvE;;OAEG;IACH,MAAM,CAAC,QAAQ,EAAE,MAAM,EAAE,MAAM,CAAC,EAAE,MAAM,EAAE,SAAS,CAAC,EAAE,MAAM,GAAG,OAAO;IAItE;;OAEG;IACH,iBAAiB,CAAC,SAAS,CAAC,EAAE,MAAM,GAAG,aAAa,EAAE;IAMtD;;OAEG;IACH,gBAAgB,CAAC,QAAQ,EAAE,MAAM,GAAG,aAAa,GAAG,IAAI;IAOxD;;OAEG;IACH,YAAY,IAAI,IAAI;IASpB;;;OAGG;IACH,OAAO,IAAI,IAAI;IAUf,OAAO,CAAC,aAAa;IAmBrB,OAAO,CAAC,aAAa;IAUrB,OAAO,CAAC,cAAc;CASvB"}
|
|
@@ -0,0 +1,180 @@
|
|
|
1
|
+
import { randomUUID } from 'node:crypto';
|
|
2
|
+
/** Largest delay `setTimeout` accepts; larger values fire after ~1ms with a TimeoutOverflowWarning. */
|
|
3
|
+
export const MAX_TIMEOUT_MS = 2 ** 31 - 1;
|
|
4
|
+
const DEFAULT_TIMEOUT_MS = 60_000;
|
|
5
|
+
function normalizeTimeout(value, fallback) {
|
|
6
|
+
if (typeof value !== 'number' || !Number.isFinite(value) || value <= 0) {
|
|
7
|
+
return Math.min(fallback, MAX_TIMEOUT_MS);
|
|
8
|
+
}
|
|
9
|
+
return Math.min(Math.floor(value), MAX_TIMEOUT_MS);
|
|
10
|
+
}
|
|
11
|
+
/**
|
|
12
|
+
* Manages human-in-the-loop confirmations for sensitive or irreversible actions.
|
|
13
|
+
*
|
|
14
|
+
* Actions are kept in memory with a configurable TTL.
|
|
15
|
+
* External interfaces (web UI, telegram bots, webhooks) approve or reject them.
|
|
16
|
+
* If no response arrives within the timeout window, the action automatically times out.
|
|
17
|
+
*
|
|
18
|
+
* Timers are `unref()`'d so a pending confirmation never keeps the process alive; call
|
|
19
|
+
* `dispose()` on shutdown to settle everything that is still pending.
|
|
20
|
+
*/
|
|
21
|
+
export class ConfirmationService {
|
|
22
|
+
pending = new Map();
|
|
23
|
+
defaultTimeoutMs;
|
|
24
|
+
logger;
|
|
25
|
+
createdListeners = new Set();
|
|
26
|
+
resolvedListeners = new Set();
|
|
27
|
+
disposed = false;
|
|
28
|
+
constructor(opts = {}) {
|
|
29
|
+
this.defaultTimeoutMs = normalizeTimeout(opts.defaultTimeoutMs, DEFAULT_TIMEOUT_MS);
|
|
30
|
+
this.logger = opts.logger;
|
|
31
|
+
}
|
|
32
|
+
setLogger(logger) {
|
|
33
|
+
this.logger = logger;
|
|
34
|
+
}
|
|
35
|
+
onActionCreated(listener) {
|
|
36
|
+
this.createdListeners.add(listener);
|
|
37
|
+
return () => this.createdListeners.delete(listener);
|
|
38
|
+
}
|
|
39
|
+
onActionResolved(listener) {
|
|
40
|
+
this.resolvedListeners.add(listener);
|
|
41
|
+
return () => this.resolvedListeners.delete(listener);
|
|
42
|
+
}
|
|
43
|
+
/**
|
|
44
|
+
* Create a pending action and wait for human confirmation, timeout, or abort.
|
|
45
|
+
* Never approves implicitly: timeout, abort and disposal all resolve as non-approved.
|
|
46
|
+
*/
|
|
47
|
+
async waitForResponse(action, timeoutMs = this.defaultTimeoutMs, abortSignal) {
|
|
48
|
+
if (this.disposed) {
|
|
49
|
+
return { status: 'rejected', reason: 'Confirmation service disposed' };
|
|
50
|
+
}
|
|
51
|
+
if (abortSignal?.aborted) {
|
|
52
|
+
return { status: 'rejected', reason: 'Aborted' };
|
|
53
|
+
}
|
|
54
|
+
const id = randomUUID();
|
|
55
|
+
const effectiveTimeout = normalizeTimeout(timeoutMs, this.defaultTimeoutMs);
|
|
56
|
+
const now = Date.now();
|
|
57
|
+
const expiresAt = now + effectiveTimeout;
|
|
58
|
+
return new Promise((resolve) => {
|
|
59
|
+
let settled = false;
|
|
60
|
+
const settle = (response) => {
|
|
61
|
+
if (settled)
|
|
62
|
+
return;
|
|
63
|
+
settled = true;
|
|
64
|
+
clearTimeout(timer);
|
|
65
|
+
abortSignal?.removeEventListener('abort', onAbort);
|
|
66
|
+
const item = this.pending.get(id);
|
|
67
|
+
this.pending.delete(id);
|
|
68
|
+
if (item) {
|
|
69
|
+
const { callback: _cb, timer: _t, ...rest } = item;
|
|
70
|
+
this.notifyResolved({ ...rest, status: response.status, reason: response.reason }, response);
|
|
71
|
+
}
|
|
72
|
+
resolve(response);
|
|
73
|
+
};
|
|
74
|
+
const onAbort = () => settle({ status: 'rejected', reason: 'Aborted' });
|
|
75
|
+
const timer = setTimeout(() => {
|
|
76
|
+
this.logger?.warn?.(`[ConfirmationService] Action ${id} timed out after ${effectiveTimeout}ms`);
|
|
77
|
+
settle({ status: 'timeout', reason: 'Confirmation timeout' });
|
|
78
|
+
}, effectiveTimeout);
|
|
79
|
+
timer.unref?.();
|
|
80
|
+
abortSignal?.addEventListener('abort', onAbort, { once: true });
|
|
81
|
+
const fullAction = {
|
|
82
|
+
...action,
|
|
83
|
+
id,
|
|
84
|
+
createdAt: now,
|
|
85
|
+
expiresAt,
|
|
86
|
+
status: 'pending',
|
|
87
|
+
};
|
|
88
|
+
this.pending.set(id, { ...fullAction, callback: settle, timer });
|
|
89
|
+
this.logger?.info?.(`[ConfirmationService] Action created: ${id} (${action.action} on ${action.toolName}), expires in ${effectiveTimeout}ms`);
|
|
90
|
+
this.notifyCreated(fullAction);
|
|
91
|
+
});
|
|
92
|
+
}
|
|
93
|
+
/**
|
|
94
|
+
* Approve a pending action. If the action is bound to a session, the caller must present the
|
|
95
|
+
* same `sessionId`; otherwise the approval is refused and the action stays pending.
|
|
96
|
+
*/
|
|
97
|
+
approve(actionId, reason, sessionId) {
|
|
98
|
+
return this.resolveAction(actionId, { status: 'approved', reason }, sessionId);
|
|
99
|
+
}
|
|
100
|
+
/**
|
|
101
|
+
* Reject a pending action. Same session binding rules as `approve()`.
|
|
102
|
+
*/
|
|
103
|
+
reject(actionId, reason, sessionId) {
|
|
104
|
+
return this.resolveAction(actionId, { status: 'rejected', reason }, sessionId);
|
|
105
|
+
}
|
|
106
|
+
/**
|
|
107
|
+
* List current pending actions, optionally restricted to one session.
|
|
108
|
+
*/
|
|
109
|
+
getPendingActions(sessionId) {
|
|
110
|
+
return Array.from(this.pending.values())
|
|
111
|
+
.filter((entry) => sessionId === undefined || entry.sessionId === sessionId)
|
|
112
|
+
.map(({ callback: _cb, timer: _t, ...action }) => action);
|
|
113
|
+
}
|
|
114
|
+
/**
|
|
115
|
+
* Get a specific pending action by ID.
|
|
116
|
+
*/
|
|
117
|
+
getPendingAction(actionId) {
|
|
118
|
+
const entry = this.pending.get(actionId);
|
|
119
|
+
if (!entry)
|
|
120
|
+
return null;
|
|
121
|
+
const { callback: _cb, timer: _t, ...action } = entry;
|
|
122
|
+
return action;
|
|
123
|
+
}
|
|
124
|
+
/**
|
|
125
|
+
* Resolves expired items as `timeout`, invoking `onActionResolved` listeners.
|
|
126
|
+
*/
|
|
127
|
+
clearExpired() {
|
|
128
|
+
const now = Date.now();
|
|
129
|
+
for (const item of [...this.pending.values()]) {
|
|
130
|
+
if (item.expiresAt <= now) {
|
|
131
|
+
item.callback({ status: 'timeout', reason: 'Confirmation expired' });
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
/**
|
|
136
|
+
* Settles every pending action as rejected, clears timers and listeners.
|
|
137
|
+
* Further `waitForResponse()` calls resolve as rejected immediately.
|
|
138
|
+
*/
|
|
139
|
+
dispose() {
|
|
140
|
+
this.disposed = true;
|
|
141
|
+
for (const item of [...this.pending.values()]) {
|
|
142
|
+
item.callback({ status: 'rejected', reason: 'Confirmation service disposed' });
|
|
143
|
+
}
|
|
144
|
+
this.pending.clear();
|
|
145
|
+
this.createdListeners.clear();
|
|
146
|
+
this.resolvedListeners.clear();
|
|
147
|
+
}
|
|
148
|
+
resolveAction(actionId, response, sessionId) {
|
|
149
|
+
const entry = this.pending.get(actionId);
|
|
150
|
+
if (!entry)
|
|
151
|
+
return false;
|
|
152
|
+
if (entry.sessionId !== undefined && entry.sessionId !== sessionId) {
|
|
153
|
+
this.logger?.warn?.(`[ConfirmationService] Refused to ${response.status === 'approved' ? 'approve' : 'reject'} action ${actionId}: session mismatch`);
|
|
154
|
+
return false;
|
|
155
|
+
}
|
|
156
|
+
entry.callback(response);
|
|
157
|
+
return true;
|
|
158
|
+
}
|
|
159
|
+
notifyCreated(action) {
|
|
160
|
+
for (const listener of this.createdListeners) {
|
|
161
|
+
try {
|
|
162
|
+
listener(action);
|
|
163
|
+
}
|
|
164
|
+
catch (err) {
|
|
165
|
+
this.logger?.warn?.('[ConfirmationService] Error in actionCreated listener:', err);
|
|
166
|
+
}
|
|
167
|
+
}
|
|
168
|
+
}
|
|
169
|
+
notifyResolved(action, response) {
|
|
170
|
+
for (const listener of this.resolvedListeners) {
|
|
171
|
+
try {
|
|
172
|
+
listener(action, response);
|
|
173
|
+
}
|
|
174
|
+
catch (err) {
|
|
175
|
+
this.logger?.warn?.('[ConfirmationService] Error in actionResolved listener:', err);
|
|
176
|
+
}
|
|
177
|
+
}
|
|
178
|
+
}
|
|
179
|
+
}
|
|
180
|
+
//# sourceMappingURL=confirmation.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"confirmation.js","sourceRoot":"","sources":["../../../src/guard/confirmation.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAA;AAexC,uGAAuG;AACvG,MAAM,CAAC,MAAM,cAAc,GAAG,CAAC,IAAI,EAAE,GAAG,CAAC,CAAA;AAEzC,MAAM,kBAAkB,GAAG,MAAM,CAAA;AAEjC,SAAS,gBAAgB,CAAC,KAAyB,EAAE,QAAgB;IACnE,IAAI,OAAO,KAAK,KAAK,QAAQ,IAAI,CAAC,MAAM,CAAC,QA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AC;gBACb,IAAI,CAAC,MAAM,EAAE,IAAI,EAAE,CAAC,wDAAwD,EAAE,GAAG,CAAC,CAAA;YACpF,CAAC;QACH,CAAC;IACH,CAAC;IAEO,cAAc,CAAC,MAAqB,EAAE,QAA8B;QAC1E,KAAK,MAAM,QAAQ,IAAI,IAAI,CAAC,iBAAiB,EAAE,CAAC;YAC9C,IAAI,CAAC;gBACH,QAAQ,CAAC,MAAM,EAAE,QAAQ,CAAC,CAAA;YAC5B,CAAC;YAAC,OAAO,GAAG,EAAE,CAAC;gBACb,IAAI,CAAC,MAAM,EAAE,IAAI,EAAE,CAAC,yDAAyD,EAAE,GAAG,CAAC,CAAA;YACrF,CAAC;QACH,CAAC;IACH,CAAC;CACF"}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Thrown when a tool call is refused by security policy and must not run:
|
|
3
|
+
* permission is `deny`, or `ask` without any way to obtain a confirmation (fail-closed).
|
|
4
|
+
*/
|
|
5
|
+
export declare class PolicyViolationError extends Error {
|
|
6
|
+
readonly toolName: string;
|
|
7
|
+
readonly code = "E_POLICY_VIOLATION";
|
|
8
|
+
constructor(toolName: string, message: string);
|
|
9
|
+
}
|
|
10
|
+
//# sourceMappingURL=errors.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"errors.d.ts","sourceRoot":"","sources":["../../../src/guard/errors.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,qBAAa,oBAAqB,SAAQ,KAAK;aAI3B,QAAQ,EAAE,MAAM;IAHlC,QAAQ,CAAC,IAAI,wBAAuB;gBAGlB,QAAQ,EAAE,MAAM,EAChC,OAAO,EAAE,MAAM;CAKlB"}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Thrown when a tool call is refused by security policy and must not run:
|
|
3
|
+
* permission is `deny`, or `ask` without any way to obtain a confirmation (fail-closed).
|
|
4
|
+
*/
|
|
5
|
+
export class PolicyViolationError extends Error {
|
|
6
|
+
toolName;
|
|
7
|
+
code = 'E_POLICY_VIOLATION';
|
|
8
|
+
constructor(toolName, message) {
|
|
9
|
+
super(`Tool "${toolName}" blocked by policy: ${message}`);
|
|
10
|
+
this.toolName = toolName;
|
|
11
|
+
this.name = 'PolicyViolationError';
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
//# sourceMappingURL=errors.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"errors.js","sourceRoot":"","sources":["../../../src/guard/errors.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,MAAM,OAAO,oBAAqB,SAAQ,KAAK;IAI3B;IAHT,IAAI,GAAG,oBAAoB,CAAA;IAEpC,YACkB,QAAgB,EAChC,OAAe;QAEf,KAAK,CAAC,SAAS,QAAQ,wBAAwB,OAAO,EAAE,CAAC,CAAA;QAHzC,aAAQ,GAAR,QAAQ,CAAQ;QAIhC,IAAI,CAAC,IAAI,GAAG,sBAAsB,CAAA;IACpC,CAAC;CACF"}
|