call-ai 0.6.4 → 0.7.0-dev-preview-1

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.
Files changed (2) hide show
  1. package/dist/api.js +12 -14
  2. package/package.json +1 -1
package/dist/api.js CHANGED
@@ -49,18 +49,17 @@ async function bufferStreamingResults(prompt, options) {
49
49
  return finalResult;
50
50
  }
51
51
  catch (error) {
52
- return handleApiError(error, "Streaming buffer error");
52
+ handleApiError(error, "Streaming buffer error", options.debug);
53
53
  }
54
54
  }
55
55
  /**
56
56
  * Standardized API error handler
57
57
  */
58
- function handleApiError(error, context) {
59
- console.error(`[callAI:${context}]:`, error);
60
- return JSON.stringify({
61
- error: String(error),
62
- message: `Sorry, I couldn't process that request: ${String(error)}`,
63
- });
58
+ function handleApiError(error, context, debug = false) {
59
+ if (debug) {
60
+ console.error(`[callAI:${context}]:`, error);
61
+ }
62
+ throw new Error(`${context}: ${String(error)}`);
64
63
  }
65
64
  /**
66
65
  * Helper to check if an error indicates invalid model and handle fallback
@@ -176,7 +175,7 @@ async function callAINonStreaming(prompt, options = {}, isRetry = false) {
176
175
  result = await extractClaudeResponse(response);
177
176
  }
178
177
  catch (error) {
179
- return handleApiError(error, "Claude API response processing failed");
178
+ handleApiError(error, "Claude API response processing failed", options.debug);
180
179
  }
181
180
  }
182
181
  else {
@@ -208,7 +207,7 @@ async function callAINonStreaming(prompt, options = {}, isRetry = false) {
208
207
  return schemaStrategy.processResponse(content);
209
208
  }
210
209
  catch (error) {
211
- return handleApiError(error, "Non-streaming API call");
210
+ handleApiError(error, "Non-streaming API call", options.debug);
212
211
  }
213
212
  }
214
213
  /**
@@ -333,10 +332,9 @@ async function* callAIStreaming(prompt, options = {}, isRetry = false) {
333
332
  // Check for error in the parsed JSON response
334
333
  if (json.error) {
335
334
  // Use the standard error format as the rest of the library
336
- const errorResponse = handleApiError(new Error(`API returned error: ${JSON.stringify(json.error)}`), "Streaming API call error");
337
- yield errorResponse;
338
- // After yielding the error, break out of the loop to end streaming
339
- break;
335
+ // We need to throw the error properly
336
+ handleApiError(new Error(`API returned error: ${JSON.stringify(json.error)}`), "Streaming API call error", options.debug);
337
+ // This code is unreachable as handleApiError throws
340
338
  }
341
339
  // Handle tool use response - Claude with schema cases
342
340
  const isClaudeWithSchema = /claude/i.test(model) && schemaStrategy.strategy === "tool_mode";
@@ -452,6 +450,6 @@ async function* callAIStreaming(prompt, options = {}, isRetry = false) {
452
450
  return schemaStrategy.processResponse(completeText);
453
451
  }
454
452
  catch (error) {
455
- return handleApiError(error, "Streaming API call");
453
+ handleApiError(error, "Streaming API call", options.debug);
456
454
  }
457
455
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "call-ai",
3
- "version": "0.6.4",
3
+ "version": "0.7.0-dev-preview-1",
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",