call-ai 14.3.343 → 14.3.345
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/api.js +24 -14
- package/error-handling.d.ts +12 -7
- package/error-handling.js +1 -1
- package/package.json +1 -1
- package/streaming.d.ts +6 -1
- package/streaming.js +1 -1
package/api.js
CHANGED
|
@@ -165,7 +165,7 @@ export function callAi(prompt, options = {}) {
|
|
|
165
165
|
if (options.debug) {
|
|
166
166
|
console.log(`[callAi:${PACKAGE_VERSION}] Response OK, creating streaming generator`);
|
|
167
167
|
}
|
|
168
|
-
return createStreamingGenerator(response, options, schemaStrategy, model);
|
|
168
|
+
return createStreamingGenerator({ response, options, schemaStrategy, model });
|
|
169
169
|
})();
|
|
170
170
|
if (process.env.NODE_ENV !== "production") {
|
|
171
171
|
if (options.debug) {
|
|
@@ -198,12 +198,17 @@ async function bufferStreamingResults(prompt, options) {
|
|
|
198
198
|
}
|
|
199
199
|
}
|
|
200
200
|
catch (error) {
|
|
201
|
-
await handleApiError(
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
201
|
+
await handleApiError({
|
|
202
|
+
ierror: error,
|
|
203
|
+
context: "Buffered streaming",
|
|
204
|
+
debug: options.debug,
|
|
205
|
+
options: {
|
|
206
|
+
apiKey: options.apiKey,
|
|
207
|
+
endpoint: options.endpoint,
|
|
208
|
+
skipRefresh: options.skipRefresh,
|
|
209
|
+
refreshToken: options.refreshToken,
|
|
210
|
+
updateRefreshToken: options.updateRefreshToken,
|
|
211
|
+
},
|
|
207
212
|
});
|
|
208
213
|
return bufferStreamingResults(prompt, {
|
|
209
214
|
...options,
|
|
@@ -311,7 +316,7 @@ async function callAINonStreaming(prompt, options = {}, isRetry = false) {
|
|
|
311
316
|
result = (await extractClaudeResponse(response));
|
|
312
317
|
}
|
|
313
318
|
catch (error) {
|
|
314
|
-
await handleApiError(error, "Claude API response processing failed", options.debug);
|
|
319
|
+
await handleApiError({ ierror: error, context: "Claude API response processing failed", debug: options.debug });
|
|
315
320
|
throw error;
|
|
316
321
|
}
|
|
317
322
|
}
|
|
@@ -352,12 +357,17 @@ async function callAINonStreaming(prompt, options = {}, isRetry = false) {
|
|
|
352
357
|
return processedContent;
|
|
353
358
|
}
|
|
354
359
|
catch (error) {
|
|
355
|
-
await handleApiError(
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
360
|
+
await handleApiError({
|
|
361
|
+
ierror: error,
|
|
362
|
+
context: "Non-streaming API call",
|
|
363
|
+
debug: options.debug,
|
|
364
|
+
options: {
|
|
365
|
+
apiKey: options.apiKey,
|
|
366
|
+
endpoint: options.endpoint,
|
|
367
|
+
skipRefresh: options.skipRefresh,
|
|
368
|
+
refreshToken: options.refreshToken,
|
|
369
|
+
updateRefreshToken: options.updateRefreshToken,
|
|
370
|
+
},
|
|
361
371
|
});
|
|
362
372
|
return callAINonStreaming(prompt, {
|
|
363
373
|
...options,
|
package/error-handling.d.ts
CHANGED
|
@@ -1,11 +1,16 @@
|
|
|
1
1
|
import { Mocks, APIErrorResponse } from "./types.js";
|
|
2
|
-
declare function handleApiError(ierror
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
2
|
+
declare function handleApiError({ ierror, context, debug, options, }: {
|
|
3
|
+
ierror: unknown;
|
|
4
|
+
context: string;
|
|
5
|
+
debug?: boolean;
|
|
6
|
+
options?: {
|
|
7
|
+
apiKey?: string;
|
|
8
|
+
endpoint?: string;
|
|
9
|
+
skipRefresh?: boolean;
|
|
10
|
+
refreshToken?: string;
|
|
11
|
+
updateRefreshToken?: (currentToken: string) => Promise<string>;
|
|
12
|
+
mock?: Mocks;
|
|
13
|
+
};
|
|
9
14
|
}): Promise<void>;
|
|
10
15
|
declare function checkForInvalidModelError(response: Response, model: string, debug?: boolean): Promise<{
|
|
11
16
|
isInvalidModel: boolean;
|
package/error-handling.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { globalDebug, isNewKeyError } from "./key-management.js";
|
|
2
2
|
import { CallAIError } from "./types.js";
|
|
3
|
-
async function handleApiError(ierror, context, debug = globalDebug, options = {}) {
|
|
3
|
+
async function handleApiError({ ierror, context, debug = globalDebug, options = {}, }) {
|
|
4
4
|
const error = ierror;
|
|
5
5
|
const errorMessage = error?.message || String(error);
|
|
6
6
|
const status = error?.status ||
|
package/package.json
CHANGED
package/streaming.d.ts
CHANGED
|
@@ -1,3 +1,8 @@
|
|
|
1
1
|
import { CallAIOptions, SchemaStrategy } from "./types.js";
|
|
2
|
-
declare function createStreamingGenerator(response
|
|
2
|
+
declare function createStreamingGenerator({ response, options, schemaStrategy, model, }: {
|
|
3
|
+
response: Response;
|
|
4
|
+
options: CallAIOptions;
|
|
5
|
+
schemaStrategy: SchemaStrategy;
|
|
6
|
+
model: string;
|
|
7
|
+
}): AsyncGenerator<string, string, unknown>;
|
|
3
8
|
export { createStreamingGenerator };
|
package/streaming.js
CHANGED
|
@@ -2,7 +2,7 @@ import { CallAIError } from "./types.js";
|
|
|
2
2
|
import { globalDebug } from "./key-management.js";
|
|
3
3
|
import { responseMetadata, boxString } from "./response-metadata.js";
|
|
4
4
|
import { PACKAGE_VERSION } from "./non-streaming.js";
|
|
5
|
-
async function* createStreamingGenerator(response, options, schemaStrategy, model) {
|
|
5
|
+
async function* createStreamingGenerator({ response, options, schemaStrategy, model, }) {
|
|
6
6
|
const meta = {
|
|
7
7
|
model,
|
|
8
8
|
endpoint: options.endpoint || "https://openrouter.ai/api/v1",
|