call-ai 0.7.0-dev-preview-3 → 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.d.ts CHANGED
@@ -9,4 +9,4 @@ import { CallAIOptions, Message } from "./types";
9
9
  * @returns A Promise that resolves to the complete response string when streaming is disabled,
10
10
  * or an AsyncGenerator that yields partial responses when streaming is enabled
11
11
  */
12
- export declare function callAI(prompt: string | Message[], options?: CallAIOptions): Promise<string> | AsyncGenerator<string, string, unknown>;
12
+ export declare function callAI(prompt: string | Message[], options?: CallAIOptions): Promise<string> | AsyncGenerator<string, string | undefined, unknown>;
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,18 +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 the error object
300
- streamingError = new Error(`API returned error ${response.status}: ${response.statusText}`);
301
- // For browsers, we need to handle errors differently
302
- if (isBrowser) {
303
- // In browsers, return an error string that can be detected and handled
304
- // The string format helps our client detect this is an error condition
305
- return `{"error":true,"message":"API returned error ${response.status}: ${response.statusText}"}`;
306
- }
307
- else {
308
- // In Node.js, throw directly as it propagates correctly
309
- throw streamingError;
310
- }
295
+ // Create a detailed error with status information
296
+ const errorMessage = `API returned error ${response.status}: ${response.statusText}`;
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;
311
304
  }
312
305
  // Handle streaming response
313
306
  if (!response.body) {
@@ -460,30 +453,8 @@ async function* callAIStreaming(prompt, options = {}, isRetry = false) {
460
453
  }
461
454
  }
462
455
  }
463
- // Check if we encountered an error earlier but didn't throw it yet
464
- // This ensures browser environments will get the error during iteration
465
- if (streamingError) {
466
- handleApiError(streamingError, "Streaming API call", options.debug);
467
- }
468
- // Final check for errors before returning
469
- if (streamingError) {
470
- throw streamingError;
471
- }
472
- // Check if the completeText looks like our error marker format
473
- if (completeText && completeText.includes('"error":true') && completeText.includes('"message":')) {
474
- try {
475
- // Try to parse the error info
476
- const errorInfo = JSON.parse(completeText);
477
- if (errorInfo.error === true && errorInfo.message) {
478
- // Create and throw proper error
479
- const detectedError = new Error(errorInfo.message);
480
- handleApiError(detectedError, "Streaming API call", options.debug);
481
- }
482
- }
483
- catch (parseError) {
484
- // If we can't parse, continue with normal processing
485
- }
486
- }
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
487
458
  // If we have assembled tool calls but haven't yielded them yet
488
459
  if (toolCallsAssembled && (!completeText || completeText.length === 0)) {
489
460
  return toolCallsAssembled;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "call-ai",
3
- "version": "0.7.0-dev-preview-3",
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",