call-ai 0.7.0-dev-preview-1 → 0.7.0-dev-preview-2
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 +14 -1
- package/package.json +1 -1
package/dist/api.js
CHANGED
|
@@ -278,6 +278,8 @@ async function extractClaudeResponse(response) {
|
|
|
278
278
|
* Internal implementation for streaming API calls
|
|
279
279
|
*/
|
|
280
280
|
async function* callAIStreaming(prompt, options = {}, isRetry = false) {
|
|
281
|
+
// Track errors to ensure consistent propagation across environments
|
|
282
|
+
let streamingError = null;
|
|
281
283
|
try {
|
|
282
284
|
const { endpoint, requestOptions, model, schemaStrategy } = prepareRequestParams(prompt, { ...options, stream: true });
|
|
283
285
|
const response = await fetch(endpoint, requestOptions);
|
|
@@ -289,7 +291,8 @@ async function* callAIStreaming(prompt, options = {}, isRetry = false) {
|
|
|
289
291
|
}
|
|
290
292
|
const errorText = await response.text();
|
|
291
293
|
console.error(`API Error: ${response.status} ${response.statusText}`, errorText);
|
|
292
|
-
|
|
294
|
+
streamingError = new Error(`API returned error ${response.status}: ${response.statusText}`);
|
|
295
|
+
throw streamingError;
|
|
293
296
|
}
|
|
294
297
|
// Handle streaming response
|
|
295
298
|
if (!response.body) {
|
|
@@ -442,6 +445,15 @@ async function* callAIStreaming(prompt, options = {}, isRetry = false) {
|
|
|
442
445
|
}
|
|
443
446
|
}
|
|
444
447
|
}
|
|
448
|
+
// Check if we encountered an error earlier but didn't throw it yet
|
|
449
|
+
// This ensures browser environments will get the error during iteration
|
|
450
|
+
if (streamingError) {
|
|
451
|
+
handleApiError(streamingError, "Streaming API call", options.debug);
|
|
452
|
+
}
|
|
453
|
+
// Final check for errors before returning
|
|
454
|
+
if (streamingError) {
|
|
455
|
+
throw streamingError;
|
|
456
|
+
}
|
|
445
457
|
// If we have assembled tool calls but haven't yielded them yet
|
|
446
458
|
if (toolCallsAssembled && (!completeText || completeText.length === 0)) {
|
|
447
459
|
return toolCallsAssembled;
|
|
@@ -450,6 +462,7 @@ async function* callAIStreaming(prompt, options = {}, isRetry = false) {
|
|
|
450
462
|
return schemaStrategy.processResponse(completeText);
|
|
451
463
|
}
|
|
452
464
|
catch (error) {
|
|
465
|
+
// Standardize error handling
|
|
453
466
|
handleApiError(error, "Streaming API call", options.debug);
|
|
454
467
|
}
|
|
455
468
|
}
|