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 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 and yield a structured error object instead of throwing
295
+ // Create a detailed error with status information
300
296
  const errorMessage = `API returned error ${response.status}: ${response.statusText}`;
301
- const errorObj = {
302
- error: true,
303
- type: "APIError",
304
- status: response.status,
305
- message: errorMessage,
306
- timestamp: new Date().toISOString()
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
- // Check if we encountered an error earlier but didn't throw it yet
467
- // This ensures browser environments will get the error during iteration
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
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "call-ai",
3
- "version": "0.7.0-dev-preview-4",
3
+ "version": "0.7.0-dev-preview-5",
4
4
  "description": "Lightweight library for making AI API calls with streaming support",
5
5
  "main": "dist/index.js",
6
6
  "browser": "dist/index.js",