call-ai 0.6.3 → 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 +16 -10
- 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
|
/**
|
|
@@ -330,6 +329,13 @@ async function* callAIStreaming(prompt, options = {}, isRetry = false) {
|
|
|
330
329
|
chunkCount++;
|
|
331
330
|
// Parse the JSON chunk
|
|
332
331
|
const json = JSON.parse(jsonLine);
|
|
332
|
+
// Check for error in the parsed JSON response
|
|
333
|
+
if (json.error) {
|
|
334
|
+
// Use the standard error format as the rest of the library
|
|
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
|
|
338
|
+
}
|
|
333
339
|
// Handle tool use response - Claude with schema cases
|
|
334
340
|
const isClaudeWithSchema = /claude/i.test(model) && schemaStrategy.strategy === "tool_mode";
|
|
335
341
|
if (isClaudeWithSchema) {
|
|
@@ -444,6 +450,6 @@ async function* callAIStreaming(prompt, options = {}, isRetry = false) {
|
|
|
444
450
|
return schemaStrategy.processResponse(completeText);
|
|
445
451
|
}
|
|
446
452
|
catch (error) {
|
|
447
|
-
|
|
453
|
+
handleApiError(error, "Streaming API call", options.debug);
|
|
448
454
|
}
|
|
449
455
|
}
|