call-ai 0.6.4 → 0.7.0-dev-preview-1
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/api.js +12 -14
- package/package.json +1 -1
package/dist/api.js
CHANGED
|
@@ -49,18 +49,17 @@ async function bufferStreamingResults(prompt, options) {
|
|
|
49
49
|
return finalResult;
|
|
50
50
|
}
|
|
51
51
|
catch (error) {
|
|
52
|
-
|
|
52
|
+
handleApiError(error, "Streaming buffer error", options.debug);
|
|
53
53
|
}
|
|
54
54
|
}
|
|
55
55
|
/**
|
|
56
56
|
* Standardized API error handler
|
|
57
57
|
*/
|
|
58
|
-
function handleApiError(error, context) {
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
});
|
|
58
|
+
function handleApiError(error, context, debug = false) {
|
|
59
|
+
if (debug) {
|
|
60
|
+
console.error(`[callAI:${context}]:`, error);
|
|
61
|
+
}
|
|
62
|
+
throw new Error(`${context}: ${String(error)}`);
|
|
64
63
|
}
|
|
65
64
|
/**
|
|
66
65
|
* Helper to check if an error indicates invalid model and handle fallback
|
|
@@ -176,7 +175,7 @@ async function callAINonStreaming(prompt, options = {}, isRetry = false) {
|
|
|
176
175
|
result = await extractClaudeResponse(response);
|
|
177
176
|
}
|
|
178
177
|
catch (error) {
|
|
179
|
-
|
|
178
|
+
handleApiError(error, "Claude API response processing failed", options.debug);
|
|
180
179
|
}
|
|
181
180
|
}
|
|
182
181
|
else {
|
|
@@ -208,7 +207,7 @@ async function callAINonStreaming(prompt, options = {}, isRetry = false) {
|
|
|
208
207
|
return schemaStrategy.processResponse(content);
|
|
209
208
|
}
|
|
210
209
|
catch (error) {
|
|
211
|
-
|
|
210
|
+
handleApiError(error, "Non-streaming API call", options.debug);
|
|
212
211
|
}
|
|
213
212
|
}
|
|
214
213
|
/**
|
|
@@ -333,10 +332,9 @@ async function* callAIStreaming(prompt, options = {}, isRetry = false) {
|
|
|
333
332
|
// Check for error in the parsed JSON response
|
|
334
333
|
if (json.error) {
|
|
335
334
|
// Use the standard error format as the rest of the library
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
//
|
|
339
|
-
break;
|
|
335
|
+
// We need to throw the error properly
|
|
336
|
+
handleApiError(new Error(`API returned error: ${JSON.stringify(json.error)}`), "Streaming API call error", options.debug);
|
|
337
|
+
// This code is unreachable as handleApiError throws
|
|
340
338
|
}
|
|
341
339
|
// Handle tool use response - Claude with schema cases
|
|
342
340
|
const isClaudeWithSchema = /claude/i.test(model) && schemaStrategy.strategy === "tool_mode";
|
|
@@ -452,6 +450,6 @@ async function* callAIStreaming(prompt, options = {}, isRetry = false) {
|
|
|
452
450
|
return schemaStrategy.processResponse(completeText);
|
|
453
451
|
}
|
|
454
452
|
catch (error) {
|
|
455
|
-
|
|
453
|
+
handleApiError(error, "Streaming API call", options.debug);
|
|
456
454
|
}
|
|
457
455
|
}
|