call-ai 0.7.0-dev-preview-8 → 0.7.0-dev-preview-9
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 +19 -6
- package/package.json +1 -1
package/dist/api.js
CHANGED
|
@@ -462,6 +462,10 @@ async function extractClaudeResponse(response) {
|
|
|
462
462
|
/**
|
|
463
463
|
* Generator factory function for streaming API calls
|
|
464
464
|
* This is called after the fetch is made and response is validated
|
|
465
|
+
*
|
|
466
|
+
* Note: Even though we checked response.ok before creating this generator,
|
|
467
|
+
* we need to be prepared for errors that may occur during streaming. Some APIs
|
|
468
|
+
* return a 200 OK initially but then deliver error information in the stream.
|
|
465
469
|
*/
|
|
466
470
|
async function* createStreamingGenerator(response, options, schemaStrategy, model) {
|
|
467
471
|
try {
|
|
@@ -503,12 +507,21 @@ async function* createStreamingGenerator(response, options, schemaStrategy, mode
|
|
|
503
507
|
chunkCount++;
|
|
504
508
|
// Parse the JSON chunk
|
|
505
509
|
const json = JSON.parse(jsonLine);
|
|
506
|
-
//
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
510
|
+
// Enhanced error detection - check for BOTH error and json.error
|
|
511
|
+
// Some APIs return 200 OK but then deliver errors in the stream
|
|
512
|
+
if (json.error || (typeof json === 'object' && 'error' in json)) {
|
|
513
|
+
console.error(`[callAI:${PACKAGE_VERSION}] Detected error in streaming response:`, json);
|
|
514
|
+
// Create a detailed error object similar to our HTTP error handling
|
|
515
|
+
const errorMessage = json.error?.message ||
|
|
516
|
+
json.error?.toString() ||
|
|
517
|
+
JSON.stringify(json.error || json);
|
|
518
|
+
const detailedError = new Error(`API streaming error: ${errorMessage}`);
|
|
519
|
+
// Add error metadata
|
|
520
|
+
detailedError.status = json.error?.status || 400;
|
|
521
|
+
detailedError.statusText = json.error?.type || 'Bad Request';
|
|
522
|
+
detailedError.details = JSON.stringify(json.error || json);
|
|
523
|
+
console.error(`[callAI:${PACKAGE_VERSION}] Throwing stream error:`, detailedError);
|
|
524
|
+
throw detailedError;
|
|
512
525
|
}
|
|
513
526
|
// Handle tool use response - Claude with schema cases
|
|
514
527
|
const isClaudeWithSchema = /claude/i.test(model) && schemaStrategy.strategy === "tool_mode";
|