call-ai 0.7.0-dev-preview-4 → 0.7.0-dev-preview-5
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 +10 -27
- package/dist/types.d.ts +0 -10
- package/package.json +1 -1
package/dist/api.js
CHANGED
|
@@ -281,10 +281,6 @@ async function extractClaudeResponse(response) {
|
|
|
281
281
|
* Internal implementation for streaming API calls
|
|
282
282
|
*/
|
|
283
283
|
async function* callAIStreaming(prompt, options = {}, isRetry = false) {
|
|
284
|
-
// Track errors to ensure consistent propagation across environments
|
|
285
|
-
let streamingError = null;
|
|
286
|
-
// Browser-specific detection to help with environment-specific handling
|
|
287
|
-
const isBrowser = typeof window !== 'undefined';
|
|
288
284
|
try {
|
|
289
285
|
const { endpoint, requestOptions, model, schemaStrategy } = prepareRequestParams(prompt, { ...options, stream: true });
|
|
290
286
|
const response = await fetch(endpoint, requestOptions);
|
|
@@ -296,21 +292,15 @@ async function* callAIStreaming(prompt, options = {}, isRetry = false) {
|
|
|
296
292
|
}
|
|
297
293
|
const errorText = await response.text();
|
|
298
294
|
console.error(`API Error: ${response.status} ${response.statusText}`, errorText);
|
|
299
|
-
// Create
|
|
295
|
+
// Create a detailed error with status information
|
|
300
296
|
const errorMessage = `API returned error ${response.status}: ${response.statusText}`;
|
|
301
|
-
const
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
// Store for later reference
|
|
309
|
-
streamingError = new Error(errorMessage);
|
|
310
|
-
// Yield the error object as a JSON string - this works in all environments
|
|
311
|
-
yield JSON.stringify(errorObj);
|
|
312
|
-
// Return after yielding the error to end the generator
|
|
313
|
-
return;
|
|
297
|
+
const error = new Error(errorMessage);
|
|
298
|
+
// Add extra properties for more context
|
|
299
|
+
error.status = response.status;
|
|
300
|
+
error.statusText = response.statusText;
|
|
301
|
+
error.details = errorText;
|
|
302
|
+
// Throw immediately - we want this to propagate correctly in all environments
|
|
303
|
+
throw error;
|
|
314
304
|
}
|
|
315
305
|
// Handle streaming response
|
|
316
306
|
if (!response.body) {
|
|
@@ -463,15 +453,8 @@ async function* callAIStreaming(prompt, options = {}, isRetry = false) {
|
|
|
463
453
|
}
|
|
464
454
|
}
|
|
465
455
|
}
|
|
466
|
-
//
|
|
467
|
-
//
|
|
468
|
-
if (streamingError) {
|
|
469
|
-
handleApiError(streamingError, "Streaming API call", options.debug);
|
|
470
|
-
}
|
|
471
|
-
// We don't need this check anymore as we're yielding errors
|
|
472
|
-
// and returning immediately after
|
|
473
|
-
// We no longer need this check since we're yielding errors directly
|
|
474
|
-
// and returning from the generator after yielding an error
|
|
456
|
+
// We no longer need special error handling here as errors are thrown immediately
|
|
457
|
+
// No extra error handling needed here - errors are thrown immediately
|
|
475
458
|
// If we have assembled tool calls but haven't yielded them yet
|
|
476
459
|
if (toolCallsAssembled && (!completeText || completeText.length === 0)) {
|
|
477
460
|
return toolCallsAssembled;
|
package/dist/types.d.ts
CHANGED
|
@@ -64,16 +64,6 @@ export interface SchemaStrategy {
|
|
|
64
64
|
processResponse: ModelStrategy["processResponse"];
|
|
65
65
|
shouldForceStream: boolean;
|
|
66
66
|
}
|
|
67
|
-
/**
|
|
68
|
-
* Structured error response format for streaming errors
|
|
69
|
-
*/
|
|
70
|
-
export interface StreamingErrorResponse {
|
|
71
|
-
error: true;
|
|
72
|
-
type: string;
|
|
73
|
-
status: number;
|
|
74
|
-
message: string;
|
|
75
|
-
timestamp: string;
|
|
76
|
-
}
|
|
77
67
|
export interface CallAIOptions {
|
|
78
68
|
/**
|
|
79
69
|
* API key for authentication
|