aiexecode 1.0.157
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/LICENSE +68 -0
- package/README.md +347 -0
- package/config_template/mcp_config.json +3 -0
- package/config_template/package_name_store.json +5 -0
- package/config_template/settings.json +5 -0
- package/index.js +879 -0
- package/mcp-agent-lib/example/01-basic-usage.js +82 -0
- package/mcp-agent-lib/example/02-quick-start.js +52 -0
- package/mcp-agent-lib/example/03-http-server.js +76 -0
- package/mcp-agent-lib/example/04-multiple-servers.js +117 -0
- package/mcp-agent-lib/example/05-error-handling.js +116 -0
- package/mcp-agent-lib/example/06-resources-and-prompts.js +174 -0
- package/mcp-agent-lib/example/07-advanced-configuration.js +191 -0
- package/mcp-agent-lib/example/08-real-world-chatbot.js +331 -0
- package/mcp-agent-lib/example/README.md +346 -0
- package/mcp-agent-lib/index.js +19 -0
- package/mcp-agent-lib/init.sh +3 -0
- package/mcp-agent-lib/package-lock.json +1216 -0
- package/mcp-agent-lib/package.json +53 -0
- package/mcp-agent-lib/sampleFastMCPClient/client.py +25 -0
- package/mcp-agent-lib/sampleFastMCPClient/run.sh +3 -0
- package/mcp-agent-lib/sampleFastMCPServer/run.sh +3 -0
- package/mcp-agent-lib/sampleFastMCPServer/server.py +12 -0
- package/mcp-agent-lib/sampleFastMCPServerElicitationRequest/run.sh +3 -0
- package/mcp-agent-lib/sampleFastMCPServerElicitationRequest/server.py +43 -0
- package/mcp-agent-lib/sampleFastMCPServerRootsRequest/server.py +63 -0
- package/mcp-agent-lib/sampleMCPHost/index.js +386 -0
- package/mcp-agent-lib/sampleMCPHost/mcp_config.json +24 -0
- package/mcp-agent-lib/sampleMCPHostFeatures/elicitation.js +151 -0
- package/mcp-agent-lib/sampleMCPHostFeatures/index.js +166 -0
- package/mcp-agent-lib/sampleMCPHostFeatures/roots.js +197 -0
- package/mcp-agent-lib/src/mcp_client.js +1860 -0
- package/mcp-agent-lib/src/mcp_message_logger.js +517 -0
- package/package.json +72 -0
- package/payload_viewer/out/404/index.html +1 -0
- package/payload_viewer/out/404.html +1 -0
- package/payload_viewer/out/_next/static/chunks/060f9a97930f3d04.js +1 -0
- package/payload_viewer/out/_next/static/chunks/103c802c8f4a5ea1.js +1 -0
- package/payload_viewer/out/_next/static/chunks/16474fd6c6910c45.js +1 -0
- package/payload_viewer/out/_next/static/chunks/17722e3ac4e00587.js +1 -0
- package/payload_viewer/out/_next/static/chunks/305b077a9873cf54.js +1 -0
- package/payload_viewer/out/_next/static/chunks/4c1d05c6741c2bdd.js +5 -0
- package/payload_viewer/out/_next/static/chunks/538cc02e54714b23.js +1 -0
- package/payload_viewer/out/_next/static/chunks/6251fa5907d2b226.js +5 -0
- package/payload_viewer/out/_next/static/chunks/a6dad97d9634a72d.js +1 -0
- package/payload_viewer/out/_next/static/chunks/b6c0459f3789d25c.js +1 -0
- package/payload_viewer/out/_next/static/chunks/b75131b58f8ca46a.css +3 -0
- package/payload_viewer/out/_next/static/chunks/bd2dcf98c9b362f6.js +1 -0
- package/payload_viewer/out/_next/static/chunks/c8a542ae21335479.js +1 -0
- package/payload_viewer/out/_next/static/chunks/cdd12d5c1a5a6064.js +1 -0
- package/payload_viewer/out/_next/static/chunks/e411019f55d87c42.js +1 -0
- package/payload_viewer/out/_next/static/chunks/e60ef129113f6e24.js +1 -0
- package/payload_viewer/out/_next/static/chunks/f1ac9047ac4a3fde.js +1 -0
- package/payload_viewer/out/_next/static/chunks/turbopack-0ac29803ce3c3c7a.js +3 -0
- package/payload_viewer/out/_next/static/chunks/turbopack-89db4c64206a73e4.js +3 -0
- package/payload_viewer/out/_next/static/chunks/turbopack-a5b8235fa59d7119.js +3 -0
- package/payload_viewer/out/_next/static/media/4fa387ec64143e14-s.c1fdd6c2.woff2 +0 -0
- package/payload_viewer/out/_next/static/media/7178b3e590c64307-s.b97b3418.woff2 +0 -0
- package/payload_viewer/out/_next/static/media/797e433ab948586e-s.p.dbea232f.woff2 +0 -0
- package/payload_viewer/out/_next/static/media/8a480f0b521d4e75-s.8e0177b5.woff2 +0 -0
- package/payload_viewer/out/_next/static/media/bbc41e54d2fcbd21-s.799d8ef8.woff2 +0 -0
- package/payload_viewer/out/_next/static/media/caa3a2e1cccd8315-s.p.853070df.woff2 +0 -0
- package/payload_viewer/out/_next/static/media/favicon.0b3bf435.ico +0 -0
- package/payload_viewer/out/_next/static/uqQYtKpKV7kCSkUbLgdfJ/_buildManifest.js +14 -0
- package/payload_viewer/out/_next/static/uqQYtKpKV7kCSkUbLgdfJ/_clientMiddlewareManifest.json +1 -0
- package/payload_viewer/out/_next/static/uqQYtKpKV7kCSkUbLgdfJ/_ssgManifest.js +1 -0
- package/payload_viewer/out/favicon.ico +0 -0
- package/payload_viewer/out/file.svg +1 -0
- package/payload_viewer/out/globe.svg +1 -0
- package/payload_viewer/out/index.html +1 -0
- package/payload_viewer/out/index.txt +23 -0
- package/payload_viewer/out/next.svg +1 -0
- package/payload_viewer/out/vercel.svg +1 -0
- package/payload_viewer/out/window.svg +1 -0
- package/payload_viewer/web_server.js +861 -0
- package/prompts/completion_judge.txt +128 -0
- package/prompts/orchestrator.txt +1213 -0
- package/src/LLMClient/client.js +1375 -0
- package/src/LLMClient/converters/input-normalizer.js +238 -0
- package/src/LLMClient/converters/responses-to-claude.js +503 -0
- package/src/LLMClient/converters/responses-to-gemini.js +648 -0
- package/src/LLMClient/converters/responses-to-ollama.js +348 -0
- package/src/LLMClient/converters/responses-to-zai.js +667 -0
- package/src/LLMClient/errors.js +398 -0
- package/src/LLMClient/index.js +36 -0
- package/src/ai_based/completion_judge.js +421 -0
- package/src/ai_based/orchestrator.js +527 -0
- package/src/ai_based/pip_package_installer.js +173 -0
- package/src/ai_based/pip_package_lookup.js +197 -0
- package/src/cli/mcp_cli.js +70 -0
- package/src/cli/mcp_commands.js +255 -0
- package/src/commands/agents.js +18 -0
- package/src/commands/apikey.js +55 -0
- package/src/commands/bg.js +140 -0
- package/src/commands/commands.js +56 -0
- package/src/commands/debug.js +54 -0
- package/src/commands/exit.js +19 -0
- package/src/commands/help.js +35 -0
- package/src/commands/mcp.js +128 -0
- package/src/commands/model.js +176 -0
- package/src/commands/setup.js +13 -0
- package/src/commands/skills.js +51 -0
- package/src/commands/tools.js +165 -0
- package/src/commands/viewer.js +147 -0
- package/src/config/ai_models.js +312 -0
- package/src/config/config.js +10 -0
- package/src/config/constants.js +71 -0
- package/src/config/feature_flags.js +15 -0
- package/src/frontend/App.js +1263 -0
- package/src/frontend/README.md +81 -0
- package/src/frontend/components/AutocompleteMenu.js +47 -0
- package/src/frontend/components/BackgroundProcessList.js +175 -0
- package/src/frontend/components/BlankLine.js +62 -0
- package/src/frontend/components/ConversationItem.js +893 -0
- package/src/frontend/components/CurrentModelView.js +43 -0
- package/src/frontend/components/FileDiffViewer.js +616 -0
- package/src/frontend/components/Footer.js +25 -0
- package/src/frontend/components/Header.js +42 -0
- package/src/frontend/components/HelpView.js +154 -0
- package/src/frontend/components/Input.js +344 -0
- package/src/frontend/components/LoadingIndicator.js +31 -0
- package/src/frontend/components/ModelListView.js +49 -0
- package/src/frontend/components/ModelUpdatedView.js +22 -0
- package/src/frontend/components/SessionSpinner.js +66 -0
- package/src/frontend/components/SetupWizard.js +242 -0
- package/src/frontend/components/StreamOutput.js +34 -0
- package/src/frontend/components/TodoList.js +56 -0
- package/src/frontend/components/ToolApprovalPrompt.js +452 -0
- package/src/frontend/design/themeColors.js +42 -0
- package/src/frontend/hooks/useCompletion.js +84 -0
- package/src/frontend/hooks/useFileCompletion.js +467 -0
- package/src/frontend/hooks/useKeypress.js +145 -0
- package/src/frontend/index.js +65 -0
- package/src/frontend/utils/GridRenderer.js +140 -0
- package/src/frontend/utils/InlineFormatter.js +156 -0
- package/src/frontend/utils/diffUtils.js +235 -0
- package/src/frontend/utils/inputBuffer.js +441 -0
- package/src/frontend/utils/markdownParser.js +377 -0
- package/src/frontend/utils/outputRedirector.js +47 -0
- package/src/frontend/utils/renderInkComponent.js +42 -0
- package/src/frontend/utils/syntaxHighlighter.js +149 -0
- package/src/frontend/utils/toolUIFormatter.js +261 -0
- package/src/system/agents_loader.js +170 -0
- package/src/system/ai_request.js +737 -0
- package/src/system/background_process.js +317 -0
- package/src/system/code_executer.js +1233 -0
- package/src/system/command_loader.js +40 -0
- package/src/system/command_parser.js +133 -0
- package/src/system/conversation_state.js +265 -0
- package/src/system/conversation_trimmer.js +265 -0
- package/src/system/custom_command_loader.js +395 -0
- package/src/system/file_integrity.js +466 -0
- package/src/system/import_analyzer.py +174 -0
- package/src/system/log.js +82 -0
- package/src/system/mcp_integration.js +304 -0
- package/src/system/output_helper.js +89 -0
- package/src/system/session.js +1393 -0
- package/src/system/session_memory.js +481 -0
- package/src/system/skill_loader.js +324 -0
- package/src/system/system_info.js +483 -0
- package/src/system/tool_approval.js +160 -0
- package/src/system/tool_registry.js +184 -0
- package/src/system/ui_events.js +279 -0
- package/src/tools/code_editor.js +792 -0
- package/src/tools/file_reader.js +385 -0
- package/src/tools/glob.js +263 -0
- package/src/tools/response_message.js +30 -0
- package/src/tools/ripgrep.js +554 -0
- package/src/tools/skill_tool.js +122 -0
- package/src/tools/todo_write.js +182 -0
- package/src/tools/web_download.py +74 -0
- package/src/tools/web_downloader.js +83 -0
- package/src/util/clone.js +174 -0
- package/src/util/config.js +203 -0
- package/src/util/config_migration.js +174 -0
- package/src/util/debug_log.js +49 -0
- package/src/util/exit_handler.js +53 -0
- package/src/util/file_reference_parser.js +132 -0
- package/src/util/mcp_config_manager.js +159 -0
- package/src/util/output_formatter.js +50 -0
- package/src/util/path_helper.js +27 -0
- package/src/util/path_validator.js +178 -0
- package/src/util/prompt_loader.js +184 -0
- package/src/util/rag_helper.js +101 -0
- package/src/util/safe_fs.js +645 -0
- package/src/util/setup_wizard.js +62 -0
- package/src/util/text_formatter.js +33 -0
- package/src/util/version_check.js +116 -0
|
@@ -0,0 +1,398 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* OpenAI-compatible error handling
|
|
3
|
+
*/
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* OpenAI API Error class
|
|
7
|
+
* Follows OpenAI Responses API error format
|
|
8
|
+
*/
|
|
9
|
+
export class LLMError extends Error {
|
|
10
|
+
constructor(message, options = {}) {
|
|
11
|
+
super(message);
|
|
12
|
+
this.name = 'LLMError';
|
|
13
|
+
|
|
14
|
+
// OpenAI error structure
|
|
15
|
+
this.error = {
|
|
16
|
+
message: message,
|
|
17
|
+
type: options.type || 'api_error',
|
|
18
|
+
param: options.param || null,
|
|
19
|
+
code: options.code || null
|
|
20
|
+
};
|
|
21
|
+
|
|
22
|
+
// HTTP status code (if applicable)
|
|
23
|
+
this.status = options.status || 500;
|
|
24
|
+
|
|
25
|
+
// Original error (for debugging)
|
|
26
|
+
this.originalError = options.originalError || null;
|
|
27
|
+
|
|
28
|
+
// Provider information
|
|
29
|
+
this.provider = options.provider || 'unknown';
|
|
30
|
+
|
|
31
|
+
// Store original request for response format
|
|
32
|
+
this.request = options.request || {};
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
/**
|
|
36
|
+
* Convert to OpenAI Responses API error format
|
|
37
|
+
*/
|
|
38
|
+
toResponsesFormat() {
|
|
39
|
+
return {
|
|
40
|
+
id: `resp_error_${Date.now()}`,
|
|
41
|
+
object: 'response',
|
|
42
|
+
created_at: Math.floor(Date.now() / 1000),
|
|
43
|
+
status: 'failed',
|
|
44
|
+
background: false,
|
|
45
|
+
billing: {
|
|
46
|
+
payer: 'developer'
|
|
47
|
+
},
|
|
48
|
+
error: {
|
|
49
|
+
type: this.error.type,
|
|
50
|
+
message: this.error.message,
|
|
51
|
+
code: this.error.code,
|
|
52
|
+
param: this.error.param
|
|
53
|
+
},
|
|
54
|
+
incomplete_details: null,
|
|
55
|
+
instructions: this.request.instructions || null,
|
|
56
|
+
max_output_tokens: this.request.max_output_tokens || null,
|
|
57
|
+
max_tool_calls: null,
|
|
58
|
+
model: this.request.model || null,
|
|
59
|
+
output: [],
|
|
60
|
+
parallel_tool_calls: true,
|
|
61
|
+
previous_response_id: null,
|
|
62
|
+
prompt_cache_key: null,
|
|
63
|
+
prompt_cache_retention: null,
|
|
64
|
+
reasoning: {
|
|
65
|
+
effort: this.request.reasoning?.effort || null,
|
|
66
|
+
summary: this.request.reasoning?.summary || null
|
|
67
|
+
},
|
|
68
|
+
safety_identifier: null,
|
|
69
|
+
service_tier: 'default',
|
|
70
|
+
store: this.request.store !== undefined ? this.request.store : true,
|
|
71
|
+
temperature: this.request.temperature !== undefined ? this.request.temperature : 1,
|
|
72
|
+
text: {
|
|
73
|
+
format: {
|
|
74
|
+
type: 'text'
|
|
75
|
+
},
|
|
76
|
+
verbosity: 'medium'
|
|
77
|
+
},
|
|
78
|
+
tool_choice: this.request.tool_choice || 'auto',
|
|
79
|
+
tools: this.request.tools || [],
|
|
80
|
+
top_logprobs: 0,
|
|
81
|
+
top_p: this.request.top_p !== undefined ? this.request.top_p : 1,
|
|
82
|
+
truncation: 'disabled',
|
|
83
|
+
usage: {
|
|
84
|
+
input_tokens: 0,
|
|
85
|
+
input_tokens_details: {
|
|
86
|
+
cached_tokens: 0
|
|
87
|
+
},
|
|
88
|
+
output_tokens: 0,
|
|
89
|
+
output_tokens_details: {
|
|
90
|
+
reasoning_tokens: 0
|
|
91
|
+
},
|
|
92
|
+
total_tokens: 0
|
|
93
|
+
},
|
|
94
|
+
user: null,
|
|
95
|
+
metadata: {},
|
|
96
|
+
output_text: ''
|
|
97
|
+
};
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
/**
|
|
101
|
+
* Convert to JSON (Legacy OpenAI error format)
|
|
102
|
+
*/
|
|
103
|
+
toJSON() {
|
|
104
|
+
return {
|
|
105
|
+
error: this.error
|
|
106
|
+
};
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
/**
|
|
110
|
+
* Convert to string
|
|
111
|
+
*/
|
|
112
|
+
toString() {
|
|
113
|
+
return `${this.provider} Error [${this.error.type}]: ${this.error.message}`;
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
/**
|
|
118
|
+
* Map HTTP status codes to OpenAI error types
|
|
119
|
+
*/
|
|
120
|
+
const ERROR_TYPE_MAP = {
|
|
121
|
+
400: 'invalid_request_error',
|
|
122
|
+
401: 'authentication_error',
|
|
123
|
+
403: 'permission_error',
|
|
124
|
+
404: 'not_found_error',
|
|
125
|
+
429: 'rate_limit_error',
|
|
126
|
+
500: 'api_error',
|
|
127
|
+
502: 'api_error',
|
|
128
|
+
503: 'api_error'
|
|
129
|
+
};
|
|
130
|
+
|
|
131
|
+
/**
|
|
132
|
+
* Create LLMError from HTTP response
|
|
133
|
+
*/
|
|
134
|
+
export async function createErrorFromResponse(response, provider) {
|
|
135
|
+
const status = response.status;
|
|
136
|
+
let errorData = null;
|
|
137
|
+
|
|
138
|
+
try {
|
|
139
|
+
const text = await response.text();
|
|
140
|
+
errorData = JSON.parse(text);
|
|
141
|
+
} catch (e) {
|
|
142
|
+
// Failed to parse JSON
|
|
143
|
+
return new LLMError(
|
|
144
|
+
`HTTP ${status}: ${response.statusText}`,
|
|
145
|
+
{
|
|
146
|
+
type: ERROR_TYPE_MAP[status] || 'api_error',
|
|
147
|
+
status: status,
|
|
148
|
+
provider: provider
|
|
149
|
+
}
|
|
150
|
+
);
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
// Extract error information
|
|
154
|
+
let message = errorData.error?.message || errorData.message || response.statusText;
|
|
155
|
+
let type = errorData.error?.type || ERROR_TYPE_MAP[status] || 'api_error';
|
|
156
|
+
let param = errorData.error?.param || null;
|
|
157
|
+
let code = errorData.error?.code || null;
|
|
158
|
+
|
|
159
|
+
return new LLMError(message, {
|
|
160
|
+
type: type,
|
|
161
|
+
param: param,
|
|
162
|
+
code: code,
|
|
163
|
+
status: status,
|
|
164
|
+
provider: provider,
|
|
165
|
+
originalError: errorData
|
|
166
|
+
});
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
/**
|
|
170
|
+
* Convert provider-specific error to LLMError
|
|
171
|
+
*/
|
|
172
|
+
export function normalizeError(error, provider) {
|
|
173
|
+
// Already an LLMError
|
|
174
|
+
if (error instanceof LLMError) {
|
|
175
|
+
return error;
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
// Anthropic SDK error (check BEFORE OpenAI SDK error, as both have error.status && error.error)
|
|
179
|
+
// Z.AI uses Anthropic SDK so handle similarly
|
|
180
|
+
if ((provider === 'claude' || provider === 'zai') && error.status) {
|
|
181
|
+
// Parse Claude error from error.error object (Anthropic SDK provides parsed error)
|
|
182
|
+
let errorType = ERROR_TYPE_MAP[error.status] || 'api_error';
|
|
183
|
+
let code = null;
|
|
184
|
+
let message = error.message || (provider === 'zai' ? 'Z.AI API error' : 'Claude API error');
|
|
185
|
+
|
|
186
|
+
// Z.AI specific error format: { detail: [{ type, loc, msg, ... }] }
|
|
187
|
+
if (error.error && error.error.detail && Array.isArray(error.error.detail)) {
|
|
188
|
+
const zaiError = error.error.detail[0];
|
|
189
|
+
if (zaiError) {
|
|
190
|
+
code = zaiError.type || null;
|
|
191
|
+
message = zaiError.msg || message;
|
|
192
|
+
|
|
193
|
+
// Map Z.AI error types
|
|
194
|
+
if (zaiError.type === 'json_invalid') {
|
|
195
|
+
errorType = 'invalid_request_error';
|
|
196
|
+
}
|
|
197
|
+
}
|
|
198
|
+
}
|
|
199
|
+
// Z.AI auth error format: { error: { message, type: "401" } }
|
|
200
|
+
else if (error.error && error.error.type === '401') {
|
|
201
|
+
errorType = 'authentication_error';
|
|
202
|
+
code = 'invalid_api_key';
|
|
203
|
+
message = error.error.message || 'Invalid or expired API key';
|
|
204
|
+
}
|
|
205
|
+
// Z.AI context exceeded format: { error: { code: "1210", message: "..." } }
|
|
206
|
+
else if (error.error && (error.error.code === '1210' || error.error.code === 1210)) {
|
|
207
|
+
errorType = 'invalid_request_error';
|
|
208
|
+
code = 'context_length_exceeded';
|
|
209
|
+
message = error.error.message || 'Context length exceeded';
|
|
210
|
+
}
|
|
211
|
+
// Anthropic SDK provides error.error object with structure:
|
|
212
|
+
// { type: 'error', error: { type: 'not_found_error', message: '...' } }
|
|
213
|
+
else if (error.error && error.error.error) {
|
|
214
|
+
const claudeError = error.error.error;
|
|
215
|
+
|
|
216
|
+
if (claudeError.type) {
|
|
217
|
+
code = claudeError.type;
|
|
218
|
+
|
|
219
|
+
// Map Claude error types to OpenAI error types
|
|
220
|
+
const claudeType = claudeError.type;
|
|
221
|
+
if (claudeType === 'not_found_error') {
|
|
222
|
+
errorType = 'not_found_error';
|
|
223
|
+
} else if (claudeType === 'invalid_request_error') {
|
|
224
|
+
errorType = 'invalid_request_error';
|
|
225
|
+
} else if (claudeType === 'authentication_error') {
|
|
226
|
+
errorType = 'authentication_error';
|
|
227
|
+
} else if (claudeType === 'permission_error') {
|
|
228
|
+
errorType = 'permission_error';
|
|
229
|
+
} else if (claudeType === 'rate_limit_error') {
|
|
230
|
+
errorType = 'rate_limit_error';
|
|
231
|
+
} else if (claudeType === 'overloaded_error') {
|
|
232
|
+
errorType = 'api_error';
|
|
233
|
+
}
|
|
234
|
+
}
|
|
235
|
+
|
|
236
|
+
// Use the actual error message from Claude
|
|
237
|
+
if (claudeError.message) {
|
|
238
|
+
message = claudeError.message;
|
|
239
|
+
}
|
|
240
|
+
}
|
|
241
|
+
|
|
242
|
+
return new LLMError(
|
|
243
|
+
message,
|
|
244
|
+
{
|
|
245
|
+
type: errorType,
|
|
246
|
+
param: null,
|
|
247
|
+
code: code,
|
|
248
|
+
status: error.status,
|
|
249
|
+
provider: provider,
|
|
250
|
+
originalError: error
|
|
251
|
+
}
|
|
252
|
+
);
|
|
253
|
+
}
|
|
254
|
+
|
|
255
|
+
// OpenAI SDK error
|
|
256
|
+
if (error.status && error.error) {
|
|
257
|
+
return new LLMError(
|
|
258
|
+
error.error.message || error.message,
|
|
259
|
+
{
|
|
260
|
+
type: error.error.type || ERROR_TYPE_MAP[error.status] || 'api_error',
|
|
261
|
+
param: error.error.param || null,
|
|
262
|
+
code: error.error.code || null,
|
|
263
|
+
status: error.status,
|
|
264
|
+
provider: provider,
|
|
265
|
+
originalError: error
|
|
266
|
+
}
|
|
267
|
+
);
|
|
268
|
+
}
|
|
269
|
+
|
|
270
|
+
// Google Generative AI error
|
|
271
|
+
if (provider === 'gemini') {
|
|
272
|
+
// Extract status from error message if available
|
|
273
|
+
let status = 500;
|
|
274
|
+
const statusMatch = error.message?.match(/\[(\d+)\s+/);
|
|
275
|
+
if (statusMatch) {
|
|
276
|
+
status = parseInt(statusMatch[1]);
|
|
277
|
+
}
|
|
278
|
+
|
|
279
|
+
return new LLMError(
|
|
280
|
+
error.message || 'Gemini API error',
|
|
281
|
+
{
|
|
282
|
+
type: ERROR_TYPE_MAP[status] || 'api_error',
|
|
283
|
+
param: null,
|
|
284
|
+
code: null,
|
|
285
|
+
status: status,
|
|
286
|
+
provider: 'gemini',
|
|
287
|
+
originalError: error
|
|
288
|
+
}
|
|
289
|
+
);
|
|
290
|
+
}
|
|
291
|
+
|
|
292
|
+
// Ollama error
|
|
293
|
+
if (provider === 'ollama') {
|
|
294
|
+
return new LLMError(
|
|
295
|
+
error.message || 'Ollama API error',
|
|
296
|
+
{
|
|
297
|
+
type: 'api_error',
|
|
298
|
+
param: null,
|
|
299
|
+
code: null,
|
|
300
|
+
status: error.status || 500,
|
|
301
|
+
provider: 'ollama',
|
|
302
|
+
originalError: error
|
|
303
|
+
}
|
|
304
|
+
);
|
|
305
|
+
}
|
|
306
|
+
|
|
307
|
+
// Network errors (connection refused, DNS errors, etc)
|
|
308
|
+
if (error.code === 'ECONNREFUSED' || error.code === 'ENOTFOUND' || error.code === 'ETIMEDOUT') {
|
|
309
|
+
return new LLMError(
|
|
310
|
+
error.message || 'Network connection error',
|
|
311
|
+
{
|
|
312
|
+
type: 'api_error',
|
|
313
|
+
param: null,
|
|
314
|
+
code: error.code,
|
|
315
|
+
status: 500,
|
|
316
|
+
provider: provider,
|
|
317
|
+
originalError: error
|
|
318
|
+
}
|
|
319
|
+
);
|
|
320
|
+
}
|
|
321
|
+
|
|
322
|
+
// TypeError (usually from URL parsing or network issues)
|
|
323
|
+
if (error instanceof TypeError) {
|
|
324
|
+
return new LLMError(
|
|
325
|
+
error.message || 'Request error',
|
|
326
|
+
{
|
|
327
|
+
type: 'api_error',
|
|
328
|
+
param: null,
|
|
329
|
+
code: null,
|
|
330
|
+
status: 500,
|
|
331
|
+
provider: provider,
|
|
332
|
+
originalError: error
|
|
333
|
+
}
|
|
334
|
+
);
|
|
335
|
+
}
|
|
336
|
+
|
|
337
|
+
// Generic error
|
|
338
|
+
return new LLMError(
|
|
339
|
+
error.message || 'Unknown error',
|
|
340
|
+
{
|
|
341
|
+
type: 'api_error',
|
|
342
|
+
status: 500,
|
|
343
|
+
provider: provider,
|
|
344
|
+
originalError: error
|
|
345
|
+
}
|
|
346
|
+
);
|
|
347
|
+
}
|
|
348
|
+
|
|
349
|
+
/**
|
|
350
|
+
* Specific error types for common cases
|
|
351
|
+
*/
|
|
352
|
+
|
|
353
|
+
export class AuthenticationError extends LLMError {
|
|
354
|
+
constructor(message, provider) {
|
|
355
|
+
super(message, {
|
|
356
|
+
type: 'authentication_error',
|
|
357
|
+
code: 'invalid_api_key',
|
|
358
|
+
status: 401,
|
|
359
|
+
provider: provider
|
|
360
|
+
});
|
|
361
|
+
this.name = 'AuthenticationError';
|
|
362
|
+
}
|
|
363
|
+
}
|
|
364
|
+
|
|
365
|
+
export class InvalidRequestError extends LLMError {
|
|
366
|
+
constructor(message, param, provider) {
|
|
367
|
+
super(message, {
|
|
368
|
+
type: 'invalid_request_error',
|
|
369
|
+
param: param,
|
|
370
|
+
status: 400,
|
|
371
|
+
provider: provider
|
|
372
|
+
});
|
|
373
|
+
this.name = 'InvalidRequestError';
|
|
374
|
+
}
|
|
375
|
+
}
|
|
376
|
+
|
|
377
|
+
export class RateLimitError extends LLMError {
|
|
378
|
+
constructor(message, provider) {
|
|
379
|
+
super(message, {
|
|
380
|
+
type: 'rate_limit_error',
|
|
381
|
+
code: 'rate_limit_exceeded',
|
|
382
|
+
status: 429,
|
|
383
|
+
provider: provider
|
|
384
|
+
});
|
|
385
|
+
this.name = 'RateLimitError';
|
|
386
|
+
}
|
|
387
|
+
}
|
|
388
|
+
|
|
389
|
+
export class NotFoundError extends LLMError {
|
|
390
|
+
constructor(message, provider) {
|
|
391
|
+
super(message, {
|
|
392
|
+
type: 'not_found_error',
|
|
393
|
+
status: 404,
|
|
394
|
+
provider: provider
|
|
395
|
+
});
|
|
396
|
+
this.name = 'NotFoundError';
|
|
397
|
+
}
|
|
398
|
+
}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* LLM Function Adapter
|
|
3
|
+
* Unified interface for LLMs using OpenAI Responses API format
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
export { UnifiedLLMClient } from './client.js';
|
|
7
|
+
|
|
8
|
+
// Export Responses API converters
|
|
9
|
+
export {
|
|
10
|
+
convertResponsesRequestToClaudeFormat,
|
|
11
|
+
convertClaudeResponseToResponsesFormat
|
|
12
|
+
} from './converters/responses-to-claude.js';
|
|
13
|
+
|
|
14
|
+
export {
|
|
15
|
+
convertResponsesRequestToGeminiFormat,
|
|
16
|
+
convertGeminiResponseToResponsesFormat
|
|
17
|
+
} from './converters/responses-to-gemini.js';
|
|
18
|
+
|
|
19
|
+
export {
|
|
20
|
+
convertResponsesRequestToOllamaFormat,
|
|
21
|
+
convertOllamaResponseToResponsesFormat
|
|
22
|
+
} from './converters/responses-to-ollama.js';
|
|
23
|
+
|
|
24
|
+
export {
|
|
25
|
+
convertResponsesRequestToZaiFormat,
|
|
26
|
+
convertZaiResponseToResponsesFormat
|
|
27
|
+
} from './converters/responses-to-zai.js';
|
|
28
|
+
|
|
29
|
+
// Export error classes
|
|
30
|
+
export {
|
|
31
|
+
LLMError,
|
|
32
|
+
AuthenticationError,
|
|
33
|
+
InvalidRequestError,
|
|
34
|
+
RateLimitError,
|
|
35
|
+
NotFoundError
|
|
36
|
+
} from './errors.js';
|