@amodalai/runtime 0.1.24 → 0.1.26
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/src/__tests__/providers.test.d.ts +6 -0
- package/dist/src/__tests__/providers.test.js +209 -0
- package/dist/src/__tests__/providers.test.js.map +1 -0
- package/dist/src/__tests__/sse-contract.test.d.ts +6 -0
- package/dist/src/__tests__/sse-contract.test.js +464 -0
- package/dist/src/__tests__/sse-contract.test.js.map +1 -0
- package/dist/src/__tests__/tools.test.d.ts +6 -0
- package/dist/src/__tests__/tools.test.js +583 -0
- package/dist/src/__tests__/tools.test.js.map +1 -0
- package/dist/src/agent/agent-types.d.ts +2 -2
- package/dist/src/agent/config-watcher.test.js +18 -14
- package/dist/src/agent/config-watcher.test.js.map +1 -1
- package/dist/src/agent/local-server.js +64 -9
- package/dist/src/agent/local-server.js.map +1 -1
- package/dist/src/agent/local-server.test.js +17 -13
- package/dist/src/agent/local-server.test.js.map +1 -1
- package/dist/src/agent/proactive/proactive-runner.js +6 -1
- package/dist/src/agent/proactive/proactive-runner.js.map +1 -1
- package/dist/src/agent/routes/admin-chat.js +1 -0
- package/dist/src/agent/routes/admin-chat.js.map +1 -1
- package/dist/src/agent/routes/automations.js +2 -0
- package/dist/src/agent/routes/automations.js.map +1 -1
- package/dist/src/agent/routes/evals.js +1 -0
- package/dist/src/agent/routes/evals.js.map +1 -1
- package/dist/src/agent/routes/files.js +3 -0
- package/dist/src/agent/routes/files.js.map +1 -1
- package/dist/src/agent/routes/inspect.js +4 -1
- package/dist/src/agent/routes/inspect.js.map +1 -1
- package/dist/src/agent/routes/stores.js +4 -0
- package/dist/src/agent/routes/stores.js.map +1 -1
- package/dist/src/agent/routes/task.js +1 -0
- package/dist/src/agent/routes/task.js.map +1 -1
- package/dist/src/agent/routes/webhooks.js +1 -0
- package/dist/src/agent/routes/webhooks.js.map +1 -1
- package/dist/src/config.d.ts +96 -0
- package/dist/src/config.js +221 -0
- package/dist/src/config.js.map +1 -0
- package/dist/src/config.test.d.ts +6 -0
- package/dist/src/config.test.js +235 -0
- package/dist/src/config.test.js.map +1 -0
- package/dist/src/errors.d.ts +145 -0
- package/dist/src/errors.js +218 -0
- package/dist/src/errors.js.map +1 -0
- package/dist/src/errors.test.d.ts +6 -0
- package/dist/src/errors.test.js +203 -0
- package/dist/src/errors.test.js.map +1 -0
- package/dist/src/index.d.ts +8 -1
- package/dist/src/index.js +8 -1
- package/dist/src/index.js.map +1 -1
- package/dist/src/logger.d.ts +33 -29
- package/dist/src/logger.js +70 -65
- package/dist/src/logger.js.map +1 -1
- package/dist/src/logger.test.d.ts +6 -0
- package/dist/src/logger.test.js +198 -0
- package/dist/src/logger.test.js.map +1 -0
- package/dist/src/routes/ai-stream.js +4 -1
- package/dist/src/routes/ai-stream.js.map +1 -1
- package/dist/src/routes/chat-stream.js +3 -1
- package/dist/src/routes/chat-stream.js.map +1 -1
- package/dist/src/routes/chat.js +1 -0
- package/dist/src/routes/chat.js.map +1 -1
- package/dist/src/routes/webhooks.js +3 -1
- package/dist/src/routes/webhooks.js.map +1 -1
- package/dist/src/server.test.js +66 -62
- package/dist/src/server.test.js.map +1 -1
- package/dist/src/session/session-manager.js +14 -4
- package/dist/src/session/session-manager.js.map +1 -1
- package/dist/src/session/session-manager.test.js +28 -24
- package/dist/src/session/session-manager.test.js.map +1 -1
- package/dist/src/session/session-runner.test.js +22 -18
- package/dist/src/session/session-runner.test.js.map +1 -1
- package/dist/src/stores/pglite-store-backend.js +6 -0
- package/dist/src/stores/pglite-store-backend.js.map +1 -1
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/package.json +3 -2
|
@@ -0,0 +1,235 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
* Copyright 2026 Amodal Labs, Inc.
|
|
4
|
+
* SPDX-License-Identifier: MIT
|
|
5
|
+
*/
|
|
6
|
+
import { describe, it, expect, beforeEach, afterEach } from 'vitest';
|
|
7
|
+
import { mkdtempSync, writeFileSync, mkdirSync, rmSync } from 'node:fs';
|
|
8
|
+
import { join } from 'node:path';
|
|
9
|
+
import { tmpdir } from 'node:os';
|
|
10
|
+
import { loadConfig } from './config.js';
|
|
11
|
+
import { ConfigError } from './errors.js';
|
|
12
|
+
function makeTempRepo(config) {
|
|
13
|
+
const dir = mkdtempSync(join(tmpdir(), 'amodal-config-test-'));
|
|
14
|
+
writeFileSync(join(dir, 'amodal.json'), JSON.stringify(config));
|
|
15
|
+
return dir;
|
|
16
|
+
}
|
|
17
|
+
const VALID_CONFIG = {
|
|
18
|
+
name: 'test-agent',
|
|
19
|
+
version: '1.0.0',
|
|
20
|
+
description: 'A test agent',
|
|
21
|
+
userContext: 'Always be helpful.',
|
|
22
|
+
models: {
|
|
23
|
+
main: { provider: 'anthropic', model: 'claude-sonnet-4-6' },
|
|
24
|
+
},
|
|
25
|
+
};
|
|
26
|
+
describe('loadConfig', () => {
|
|
27
|
+
let savedEnv;
|
|
28
|
+
beforeEach(() => {
|
|
29
|
+
savedEnv = {
|
|
30
|
+
ANTHROPIC_API_KEY: process.env['ANTHROPIC_API_KEY'],
|
|
31
|
+
LOG_LEVEL: process.env['LOG_LEVEL'],
|
|
32
|
+
};
|
|
33
|
+
process.env['ANTHROPIC_API_KEY'] = 'test-key';
|
|
34
|
+
});
|
|
35
|
+
afterEach(() => {
|
|
36
|
+
for (const [key, val] of Object.entries(savedEnv)) {
|
|
37
|
+
if (val === undefined)
|
|
38
|
+
delete process.env[key];
|
|
39
|
+
else
|
|
40
|
+
process.env[key] = val;
|
|
41
|
+
}
|
|
42
|
+
});
|
|
43
|
+
it('loads a valid config from amodal.json', () => {
|
|
44
|
+
const dir = makeTempRepo(VALID_CONFIG);
|
|
45
|
+
try {
|
|
46
|
+
const config = loadConfig({ repoPath: dir });
|
|
47
|
+
expect(config.name).toBe('test-agent');
|
|
48
|
+
expect(config.version).toBe('1.0.0');
|
|
49
|
+
expect(config.description).toBe('A test agent');
|
|
50
|
+
expect(config.userContext).toBe('Always be helpful.');
|
|
51
|
+
expect(config.primaryModel.provider).toBe('anthropic');
|
|
52
|
+
expect(config.primaryModel.model).toBe('claude-sonnet-4-6');
|
|
53
|
+
expect(config.repoPath).toBe(dir);
|
|
54
|
+
}
|
|
55
|
+
finally {
|
|
56
|
+
rmSync(dir, { recursive: true });
|
|
57
|
+
}
|
|
58
|
+
});
|
|
59
|
+
it('loads from .amodal/config.json if amodal.json missing', () => {
|
|
60
|
+
const dir = mkdtempSync(join(tmpdir(), 'amodal-config-test-'));
|
|
61
|
+
mkdirSync(join(dir, '.amodal'));
|
|
62
|
+
writeFileSync(join(dir, '.amodal', 'config.json'), JSON.stringify(VALID_CONFIG));
|
|
63
|
+
try {
|
|
64
|
+
const config = loadConfig({ repoPath: dir });
|
|
65
|
+
expect(config.name).toBe('test-agent');
|
|
66
|
+
}
|
|
67
|
+
finally {
|
|
68
|
+
rmSync(dir, { recursive: true });
|
|
69
|
+
}
|
|
70
|
+
});
|
|
71
|
+
it('throws ConfigError when no config file found', () => {
|
|
72
|
+
const dir = mkdtempSync(join(tmpdir(), 'amodal-config-test-'));
|
|
73
|
+
try {
|
|
74
|
+
expect(() => loadConfig({ repoPath: dir })).toThrow(ConfigError);
|
|
75
|
+
try {
|
|
76
|
+
loadConfig({ repoPath: dir });
|
|
77
|
+
}
|
|
78
|
+
catch (err) {
|
|
79
|
+
expect(err).toBeInstanceOf(ConfigError);
|
|
80
|
+
const ce = err;
|
|
81
|
+
expect(ce.key).toBe('amodal.json');
|
|
82
|
+
expect(ce.suggestion).toContain('amodal init');
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
finally {
|
|
86
|
+
rmSync(dir, { recursive: true });
|
|
87
|
+
}
|
|
88
|
+
});
|
|
89
|
+
it('throws ConfigError when provider API key is missing', () => {
|
|
90
|
+
delete process.env['ANTHROPIC_API_KEY'];
|
|
91
|
+
const dir = makeTempRepo(VALID_CONFIG);
|
|
92
|
+
try {
|
|
93
|
+
expect(() => loadConfig({ repoPath: dir })).toThrow(ConfigError);
|
|
94
|
+
try {
|
|
95
|
+
loadConfig({ repoPath: dir });
|
|
96
|
+
}
|
|
97
|
+
catch (err) {
|
|
98
|
+
const ce = err;
|
|
99
|
+
expect(ce.suggestion).toContain('ANTHROPIC_API_KEY');
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
finally {
|
|
103
|
+
rmSync(dir, { recursive: true });
|
|
104
|
+
}
|
|
105
|
+
});
|
|
106
|
+
it('skips provider key check when credentials are explicit', () => {
|
|
107
|
+
delete process.env['ANTHROPIC_API_KEY'];
|
|
108
|
+
const dir = makeTempRepo({
|
|
109
|
+
...VALID_CONFIG,
|
|
110
|
+
models: {
|
|
111
|
+
main: {
|
|
112
|
+
provider: 'anthropic',
|
|
113
|
+
model: 'claude-sonnet-4-6',
|
|
114
|
+
credentials: { ANTHROPIC_API_KEY: 'inline-key' },
|
|
115
|
+
},
|
|
116
|
+
},
|
|
117
|
+
});
|
|
118
|
+
try {
|
|
119
|
+
const config = loadConfig({ repoPath: dir });
|
|
120
|
+
expect(config.primaryModel.credentials).toEqual({ ANTHROPIC_API_KEY: 'inline-key' });
|
|
121
|
+
}
|
|
122
|
+
finally {
|
|
123
|
+
rmSync(dir, { recursive: true });
|
|
124
|
+
}
|
|
125
|
+
});
|
|
126
|
+
it('applies runtime overrides', () => {
|
|
127
|
+
const dir = makeTempRepo(VALID_CONFIG);
|
|
128
|
+
try {
|
|
129
|
+
const config = loadConfig({
|
|
130
|
+
repoPath: dir,
|
|
131
|
+
overrides: {
|
|
132
|
+
primaryModel: { model: 'claude-opus-4-6' },
|
|
133
|
+
storeBackend: 'postgres',
|
|
134
|
+
postgresUrl: 'postgresql://localhost/test',
|
|
135
|
+
},
|
|
136
|
+
});
|
|
137
|
+
expect(config.primaryModel.model).toBe('claude-opus-4-6');
|
|
138
|
+
expect(config.primaryModel.provider).toBe('anthropic'); // preserved from base
|
|
139
|
+
expect(config.stores.backend).toBe('postgres');
|
|
140
|
+
expect(config.stores.postgresUrl).toBe('postgresql://localhost/test');
|
|
141
|
+
}
|
|
142
|
+
finally {
|
|
143
|
+
rmSync(dir, { recursive: true });
|
|
144
|
+
}
|
|
145
|
+
});
|
|
146
|
+
it('sets default store config', () => {
|
|
147
|
+
const dir = makeTempRepo(VALID_CONFIG);
|
|
148
|
+
try {
|
|
149
|
+
const config = loadConfig({ repoPath: dir });
|
|
150
|
+
expect(config.stores.backend).toBe('pglite');
|
|
151
|
+
expect(config.stores.dataDir).toBe(join(dir, '.amodal', 'store-data'));
|
|
152
|
+
}
|
|
153
|
+
finally {
|
|
154
|
+
rmSync(dir, { recursive: true });
|
|
155
|
+
}
|
|
156
|
+
});
|
|
157
|
+
it('sets default sandbox config', () => {
|
|
158
|
+
const dir = makeTempRepo(VALID_CONFIG);
|
|
159
|
+
try {
|
|
160
|
+
const config = loadConfig({ repoPath: dir });
|
|
161
|
+
expect(config.sandbox.shellExec).toBe(false);
|
|
162
|
+
expect(config.sandbox.maxTimeout).toBe(30000);
|
|
163
|
+
}
|
|
164
|
+
finally {
|
|
165
|
+
rmSync(dir, { recursive: true });
|
|
166
|
+
}
|
|
167
|
+
});
|
|
168
|
+
it('parses MCP server configs', () => {
|
|
169
|
+
const dir = makeTempRepo({
|
|
170
|
+
...VALID_CONFIG,
|
|
171
|
+
mcp: {
|
|
172
|
+
servers: {
|
|
173
|
+
'my-server': {
|
|
174
|
+
transport: 'stdio',
|
|
175
|
+
command: 'node',
|
|
176
|
+
args: ['server.js'],
|
|
177
|
+
},
|
|
178
|
+
},
|
|
179
|
+
},
|
|
180
|
+
});
|
|
181
|
+
try {
|
|
182
|
+
const config = loadConfig({ repoPath: dir });
|
|
183
|
+
expect(config.mcpServers['my-server']).toEqual({
|
|
184
|
+
transport: 'stdio',
|
|
185
|
+
command: 'node',
|
|
186
|
+
args: ['server.js'],
|
|
187
|
+
});
|
|
188
|
+
}
|
|
189
|
+
finally {
|
|
190
|
+
rmSync(dir, { recursive: true });
|
|
191
|
+
}
|
|
192
|
+
});
|
|
193
|
+
it('exposes raw config for backwards compatibility', () => {
|
|
194
|
+
const dir = makeTempRepo(VALID_CONFIG);
|
|
195
|
+
try {
|
|
196
|
+
const config = loadConfig({ repoPath: dir });
|
|
197
|
+
expect(config.raw.name).toBe('test-agent');
|
|
198
|
+
}
|
|
199
|
+
finally {
|
|
200
|
+
rmSync(dir, { recursive: true });
|
|
201
|
+
}
|
|
202
|
+
});
|
|
203
|
+
it('respects LOG_LEVEL env var', () => {
|
|
204
|
+
process.env['LOG_LEVEL'] = 'debug';
|
|
205
|
+
const dir = makeTempRepo(VALID_CONFIG);
|
|
206
|
+
try {
|
|
207
|
+
const config = loadConfig({ repoPath: dir });
|
|
208
|
+
expect(config.logLevel).toBe(1); // LogLevel.DEBUG
|
|
209
|
+
}
|
|
210
|
+
finally {
|
|
211
|
+
delete process.env['LOG_LEVEL'];
|
|
212
|
+
rmSync(dir, { recursive: true });
|
|
213
|
+
}
|
|
214
|
+
});
|
|
215
|
+
it('throws on invalid JSON', () => {
|
|
216
|
+
const dir = mkdtempSync(join(tmpdir(), 'amodal-config-test-'));
|
|
217
|
+
writeFileSync(join(dir, 'amodal.json'), 'not json{{{');
|
|
218
|
+
try {
|
|
219
|
+
expect(() => loadConfig({ repoPath: dir })).toThrow(ConfigError);
|
|
220
|
+
}
|
|
221
|
+
finally {
|
|
222
|
+
rmSync(dir, { recursive: true });
|
|
223
|
+
}
|
|
224
|
+
});
|
|
225
|
+
it('throws on missing required fields', () => {
|
|
226
|
+
const dir = makeTempRepo({ name: 'test' }); // missing version, models
|
|
227
|
+
try {
|
|
228
|
+
expect(() => loadConfig({ repoPath: dir })).toThrow(ConfigError);
|
|
229
|
+
}
|
|
230
|
+
finally {
|
|
231
|
+
rmSync(dir, { recursive: true });
|
|
232
|
+
}
|
|
233
|
+
});
|
|
234
|
+
});
|
|
235
|
+
//# sourceMappingURL=config.test.js.map
|
|
@@ -0,0 +1 @@
|
|
|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+
* Copyright 2026 Amodal Labs, Inc.
|
|
4
|
+
* SPDX-License-Identifier: MIT
|
|
5
|
+
*/
|
|
6
|
+
/**
|
|
7
|
+
* A discriminated result type for operations that can fail.
|
|
8
|
+
* Forces callers to handle both success and error cases.
|
|
9
|
+
*/
|
|
10
|
+
export type Result<T, E = Error> = {
|
|
11
|
+
ok: true;
|
|
12
|
+
value: T;
|
|
13
|
+
} | {
|
|
14
|
+
ok: false;
|
|
15
|
+
error: E;
|
|
16
|
+
};
|
|
17
|
+
/**
|
|
18
|
+
* Base error class for all Amodal runtime errors.
|
|
19
|
+
*
|
|
20
|
+
* Every error carries:
|
|
21
|
+
* - `code` — a unique, stable string for programmatic matching
|
|
22
|
+
* - `context` — structured data about what was happening when the error occurred
|
|
23
|
+
* - `cause` — the underlying error (standard Error.cause)
|
|
24
|
+
*/
|
|
25
|
+
export declare class AmodalError extends Error {
|
|
26
|
+
readonly code: string;
|
|
27
|
+
readonly context: Record<string, unknown>;
|
|
28
|
+
constructor(code: string, message: string, context?: Record<string, unknown>, cause?: unknown);
|
|
29
|
+
/**
|
|
30
|
+
* Serialize to a structured object suitable for logging or JSON responses.
|
|
31
|
+
*/
|
|
32
|
+
toJSON(): Record<string, unknown>;
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* Error from an LLM provider call (Anthropic, OpenAI, Google, etc.).
|
|
36
|
+
*/
|
|
37
|
+
export declare class ProviderError extends AmodalError {
|
|
38
|
+
readonly provider: string;
|
|
39
|
+
readonly statusCode?: number;
|
|
40
|
+
readonly retryable: boolean;
|
|
41
|
+
constructor(message: string, options: {
|
|
42
|
+
provider: string;
|
|
43
|
+
statusCode?: number;
|
|
44
|
+
retryable?: boolean;
|
|
45
|
+
cause?: unknown;
|
|
46
|
+
context?: Record<string, unknown>;
|
|
47
|
+
});
|
|
48
|
+
}
|
|
49
|
+
/**
|
|
50
|
+
* Thrown on 429 rate limit responses.
|
|
51
|
+
*/
|
|
52
|
+
export declare class RateLimitError extends ProviderError {
|
|
53
|
+
readonly retryAfterMs?: number;
|
|
54
|
+
constructor(message: string, options: {
|
|
55
|
+
provider: string;
|
|
56
|
+
retryAfterMs?: number;
|
|
57
|
+
cause?: unknown;
|
|
58
|
+
});
|
|
59
|
+
}
|
|
60
|
+
/**
|
|
61
|
+
* Thrown when a provider request times out.
|
|
62
|
+
*/
|
|
63
|
+
export declare class ProviderTimeoutError extends ProviderError {
|
|
64
|
+
constructor(message: string, options: {
|
|
65
|
+
provider: string;
|
|
66
|
+
cause?: unknown;
|
|
67
|
+
});
|
|
68
|
+
}
|
|
69
|
+
/**
|
|
70
|
+
* Error during tool execution (custom tools, store tools, request tool, etc.).
|
|
71
|
+
*/
|
|
72
|
+
export declare class ToolExecutionError extends AmodalError {
|
|
73
|
+
readonly toolName: string;
|
|
74
|
+
readonly callId: string;
|
|
75
|
+
constructor(message: string, options: {
|
|
76
|
+
toolName: string;
|
|
77
|
+
callId: string;
|
|
78
|
+
cause?: unknown;
|
|
79
|
+
context?: Record<string, unknown>;
|
|
80
|
+
});
|
|
81
|
+
}
|
|
82
|
+
/**
|
|
83
|
+
* Error from a store backend operation (PGLite, Postgres, etc.).
|
|
84
|
+
*/
|
|
85
|
+
export declare class StoreError extends AmodalError {
|
|
86
|
+
readonly store: string;
|
|
87
|
+
readonly operation: string;
|
|
88
|
+
constructor(message: string, options: {
|
|
89
|
+
store: string;
|
|
90
|
+
operation: string;
|
|
91
|
+
cause?: unknown;
|
|
92
|
+
context?: Record<string, unknown>;
|
|
93
|
+
});
|
|
94
|
+
}
|
|
95
|
+
/**
|
|
96
|
+
* Error from a connection request (REST API calls, MCP, etc.).
|
|
97
|
+
*/
|
|
98
|
+
export declare class ConnectionError extends AmodalError {
|
|
99
|
+
readonly connection: string;
|
|
100
|
+
readonly action: string;
|
|
101
|
+
constructor(message: string, options: {
|
|
102
|
+
connection: string;
|
|
103
|
+
action: string;
|
|
104
|
+
cause?: unknown;
|
|
105
|
+
context?: Record<string, unknown>;
|
|
106
|
+
});
|
|
107
|
+
}
|
|
108
|
+
/**
|
|
109
|
+
* Error in session lifecycle (creation, destroy, state transitions).
|
|
110
|
+
*/
|
|
111
|
+
export declare class SessionError extends AmodalError {
|
|
112
|
+
readonly sessionId: string;
|
|
113
|
+
constructor(message: string, options: {
|
|
114
|
+
sessionId: string;
|
|
115
|
+
cause?: unknown;
|
|
116
|
+
context?: Record<string, unknown>;
|
|
117
|
+
});
|
|
118
|
+
}
|
|
119
|
+
/**
|
|
120
|
+
* Error during context compaction (summarization, truncation).
|
|
121
|
+
*/
|
|
122
|
+
export declare class CompactionError extends AmodalError {
|
|
123
|
+
readonly stage: string;
|
|
124
|
+
constructor(message: string, options: {
|
|
125
|
+
stage: string;
|
|
126
|
+
cause?: unknown;
|
|
127
|
+
context?: Record<string, unknown>;
|
|
128
|
+
});
|
|
129
|
+
}
|
|
130
|
+
/**
|
|
131
|
+
* Error in configuration loading or validation.
|
|
132
|
+
* Includes a `suggestion` field with actionable fix instructions.
|
|
133
|
+
*/
|
|
134
|
+
export declare class ConfigError extends AmodalError {
|
|
135
|
+
readonly key: string;
|
|
136
|
+
readonly suggestion: string;
|
|
137
|
+
constructor(message: string, options: {
|
|
138
|
+
key: string;
|
|
139
|
+
suggestion?: string;
|
|
140
|
+
cause?: unknown;
|
|
141
|
+
context?: Record<string, unknown>;
|
|
142
|
+
});
|
|
143
|
+
/** Format as a multi-line error message for CLI output. */
|
|
144
|
+
format(): string;
|
|
145
|
+
}
|
|
@@ -0,0 +1,218 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
* Copyright 2026 Amodal Labs, Inc.
|
|
4
|
+
* SPDX-License-Identifier: MIT
|
|
5
|
+
*/
|
|
6
|
+
// ---------------------------------------------------------------------------
|
|
7
|
+
// Base error
|
|
8
|
+
// ---------------------------------------------------------------------------
|
|
9
|
+
/**
|
|
10
|
+
* Base error class for all Amodal runtime errors.
|
|
11
|
+
*
|
|
12
|
+
* Every error carries:
|
|
13
|
+
* - `code` — a unique, stable string for programmatic matching
|
|
14
|
+
* - `context` — structured data about what was happening when the error occurred
|
|
15
|
+
* - `cause` — the underlying error (standard Error.cause)
|
|
16
|
+
*/
|
|
17
|
+
export class AmodalError extends Error {
|
|
18
|
+
code;
|
|
19
|
+
context;
|
|
20
|
+
constructor(code, message, context = {}, cause) {
|
|
21
|
+
super(message, { cause });
|
|
22
|
+
this.name = 'AmodalError';
|
|
23
|
+
this.code = code;
|
|
24
|
+
this.context = context;
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* Serialize to a structured object suitable for logging or JSON responses.
|
|
28
|
+
*/
|
|
29
|
+
toJSON() {
|
|
30
|
+
return {
|
|
31
|
+
name: this.name,
|
|
32
|
+
code: this.code,
|
|
33
|
+
message: this.message,
|
|
34
|
+
context: this.context,
|
|
35
|
+
...(this.cause instanceof Error
|
|
36
|
+
? { cause: { name: this.cause.name, message: this.cause.message } }
|
|
37
|
+
: this.cause !== undefined
|
|
38
|
+
? { cause: String(this.cause) }
|
|
39
|
+
: {}),
|
|
40
|
+
};
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
// ---------------------------------------------------------------------------
|
|
44
|
+
// Provider errors
|
|
45
|
+
// ---------------------------------------------------------------------------
|
|
46
|
+
/**
|
|
47
|
+
* Error from an LLM provider call (Anthropic, OpenAI, Google, etc.).
|
|
48
|
+
*/
|
|
49
|
+
export class ProviderError extends AmodalError {
|
|
50
|
+
provider;
|
|
51
|
+
statusCode;
|
|
52
|
+
retryable;
|
|
53
|
+
constructor(message, options) {
|
|
54
|
+
super('PROVIDER_ERROR', message, {
|
|
55
|
+
provider: options.provider,
|
|
56
|
+
statusCode: options.statusCode,
|
|
57
|
+
...options.context,
|
|
58
|
+
}, options.cause);
|
|
59
|
+
this.name = 'ProviderError';
|
|
60
|
+
this.provider = options.provider;
|
|
61
|
+
this.statusCode = options.statusCode;
|
|
62
|
+
this.retryable = options.retryable ?? false;
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
/**
|
|
66
|
+
* Thrown on 429 rate limit responses.
|
|
67
|
+
*/
|
|
68
|
+
export class RateLimitError extends ProviderError {
|
|
69
|
+
retryAfterMs;
|
|
70
|
+
constructor(message, options) {
|
|
71
|
+
super(message, {
|
|
72
|
+
provider: options.provider,
|
|
73
|
+
statusCode: 429,
|
|
74
|
+
retryable: true,
|
|
75
|
+
cause: options.cause,
|
|
76
|
+
context: { retryAfterMs: options.retryAfterMs },
|
|
77
|
+
});
|
|
78
|
+
this.name = 'RateLimitError';
|
|
79
|
+
this.retryAfterMs = options.retryAfterMs;
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
/**
|
|
83
|
+
* Thrown when a provider request times out.
|
|
84
|
+
*/
|
|
85
|
+
export class ProviderTimeoutError extends ProviderError {
|
|
86
|
+
constructor(message, options) {
|
|
87
|
+
super(message, {
|
|
88
|
+
provider: options.provider,
|
|
89
|
+
retryable: true,
|
|
90
|
+
cause: options.cause,
|
|
91
|
+
});
|
|
92
|
+
this.name = 'ProviderTimeoutError';
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
// ---------------------------------------------------------------------------
|
|
96
|
+
// Tool errors
|
|
97
|
+
// ---------------------------------------------------------------------------
|
|
98
|
+
/**
|
|
99
|
+
* Error during tool execution (custom tools, store tools, request tool, etc.).
|
|
100
|
+
*/
|
|
101
|
+
export class ToolExecutionError extends AmodalError {
|
|
102
|
+
toolName;
|
|
103
|
+
callId;
|
|
104
|
+
constructor(message, options) {
|
|
105
|
+
super('TOOL_EXECUTION_ERROR', message, {
|
|
106
|
+
toolName: options.toolName,
|
|
107
|
+
callId: options.callId,
|
|
108
|
+
...options.context,
|
|
109
|
+
}, options.cause);
|
|
110
|
+
this.name = 'ToolExecutionError';
|
|
111
|
+
this.toolName = options.toolName;
|
|
112
|
+
this.callId = options.callId;
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
// ---------------------------------------------------------------------------
|
|
116
|
+
// Store errors
|
|
117
|
+
// ---------------------------------------------------------------------------
|
|
118
|
+
/**
|
|
119
|
+
* Error from a store backend operation (PGLite, Postgres, etc.).
|
|
120
|
+
*/
|
|
121
|
+
export class StoreError extends AmodalError {
|
|
122
|
+
store;
|
|
123
|
+
operation;
|
|
124
|
+
constructor(message, options) {
|
|
125
|
+
super('STORE_ERROR', message, {
|
|
126
|
+
store: options.store,
|
|
127
|
+
operation: options.operation,
|
|
128
|
+
...options.context,
|
|
129
|
+
}, options.cause);
|
|
130
|
+
this.name = 'StoreError';
|
|
131
|
+
this.store = options.store;
|
|
132
|
+
this.operation = options.operation;
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
// ---------------------------------------------------------------------------
|
|
136
|
+
// Connection errors
|
|
137
|
+
// ---------------------------------------------------------------------------
|
|
138
|
+
/**
|
|
139
|
+
* Error from a connection request (REST API calls, MCP, etc.).
|
|
140
|
+
*/
|
|
141
|
+
export class ConnectionError extends AmodalError {
|
|
142
|
+
connection;
|
|
143
|
+
action;
|
|
144
|
+
constructor(message, options) {
|
|
145
|
+
super('CONNECTION_ERROR', message, {
|
|
146
|
+
connection: options.connection,
|
|
147
|
+
action: options.action,
|
|
148
|
+
...options.context,
|
|
149
|
+
}, options.cause);
|
|
150
|
+
this.name = 'ConnectionError';
|
|
151
|
+
this.connection = options.connection;
|
|
152
|
+
this.action = options.action;
|
|
153
|
+
}
|
|
154
|
+
}
|
|
155
|
+
// ---------------------------------------------------------------------------
|
|
156
|
+
// Session errors
|
|
157
|
+
// ---------------------------------------------------------------------------
|
|
158
|
+
/**
|
|
159
|
+
* Error in session lifecycle (creation, destroy, state transitions).
|
|
160
|
+
*/
|
|
161
|
+
export class SessionError extends AmodalError {
|
|
162
|
+
sessionId;
|
|
163
|
+
constructor(message, options) {
|
|
164
|
+
super('SESSION_ERROR', message, {
|
|
165
|
+
sessionId: options.sessionId,
|
|
166
|
+
...options.context,
|
|
167
|
+
}, options.cause);
|
|
168
|
+
this.name = 'SessionError';
|
|
169
|
+
this.sessionId = options.sessionId;
|
|
170
|
+
}
|
|
171
|
+
}
|
|
172
|
+
// ---------------------------------------------------------------------------
|
|
173
|
+
// Compaction errors
|
|
174
|
+
// ---------------------------------------------------------------------------
|
|
175
|
+
/**
|
|
176
|
+
* Error during context compaction (summarization, truncation).
|
|
177
|
+
*/
|
|
178
|
+
export class CompactionError extends AmodalError {
|
|
179
|
+
stage;
|
|
180
|
+
constructor(message, options) {
|
|
181
|
+
super('COMPACTION_ERROR', message, {
|
|
182
|
+
stage: options.stage,
|
|
183
|
+
...options.context,
|
|
184
|
+
}, options.cause);
|
|
185
|
+
this.name = 'CompactionError';
|
|
186
|
+
this.stage = options.stage;
|
|
187
|
+
}
|
|
188
|
+
}
|
|
189
|
+
// ---------------------------------------------------------------------------
|
|
190
|
+
// Config errors
|
|
191
|
+
// ---------------------------------------------------------------------------
|
|
192
|
+
/**
|
|
193
|
+
* Error in configuration loading or validation.
|
|
194
|
+
* Includes a `suggestion` field with actionable fix instructions.
|
|
195
|
+
*/
|
|
196
|
+
export class ConfigError extends AmodalError {
|
|
197
|
+
key;
|
|
198
|
+
suggestion;
|
|
199
|
+
constructor(message, options) {
|
|
200
|
+
super('CONFIG_ERROR', message, {
|
|
201
|
+
key: options.key,
|
|
202
|
+
...options.context,
|
|
203
|
+
}, options.cause);
|
|
204
|
+
this.name = 'ConfigError';
|
|
205
|
+
this.key = options.key;
|
|
206
|
+
this.suggestion = options.suggestion ?? '';
|
|
207
|
+
}
|
|
208
|
+
/** Format as a multi-line error message for CLI output. */
|
|
209
|
+
format() {
|
|
210
|
+
const lines = [`Config error: ${this.message}`];
|
|
211
|
+
if (this.key)
|
|
212
|
+
lines.push(` Key: ${this.key}`);
|
|
213
|
+
if (this.suggestion)
|
|
214
|
+
lines.push(` Fix: ${this.suggestion}`);
|
|
215
|
+
return lines.join('\n');
|
|
216
|
+
}
|
|
217
|
+
}
|
|
218
|
+
//# sourceMappingURL=errors.js.map
|
|
@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