@ai-sdk/provider-utils 4.0.9 → 4.0.11
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/CHANGELOG.md +14 -0
- package/dist/index.d.mts +170 -166
- package/dist/index.d.ts +170 -166
- package/dist/index.js +37 -7
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +37 -7
- package/dist/index.mjs.map +1 -1
- package/package.json +2 -2
- package/src/extract-response-headers.ts +5 -5
- package/src/generate-id.ts +11 -11
- package/src/handle-fetch-error.ts +33 -0
- package/src/types/assistant-model-message.ts +6 -6
- package/src/types/content-part.ts +70 -70
- package/src/types/data-content.ts +1 -1
- package/src/types/model-message.ts +2 -2
- package/src/types/provider-options.ts +4 -4
- package/src/types/system-model-message.ts +9 -9
- package/src/types/tool-call.ts +7 -7
- package/src/types/tool-model-message.ts +5 -5
- package/src/types/tool-result.ts +8 -8
- package/src/types/tool.ts +28 -28
- package/src/types/user-model-message.ts +7 -7
- package/src/validate-types.ts +11 -5
package/dist/index.mjs
CHANGED
|
@@ -305,6 +305,25 @@ function isAbortError(error) {
|
|
|
305
305
|
|
|
306
306
|
// src/handle-fetch-error.ts
|
|
307
307
|
var FETCH_FAILED_ERROR_MESSAGES = ["fetch failed", "failed to fetch"];
|
|
308
|
+
var BUN_ERROR_CODES = [
|
|
309
|
+
"ConnectionRefused",
|
|
310
|
+
"ConnectionClosed",
|
|
311
|
+
"FailedToOpenSocket",
|
|
312
|
+
"ECONNRESET",
|
|
313
|
+
"ECONNREFUSED",
|
|
314
|
+
"ETIMEDOUT",
|
|
315
|
+
"EPIPE"
|
|
316
|
+
];
|
|
317
|
+
function isBunNetworkError(error) {
|
|
318
|
+
if (!(error instanceof Error)) {
|
|
319
|
+
return false;
|
|
320
|
+
}
|
|
321
|
+
const code = error.code;
|
|
322
|
+
if (typeof code === "string" && BUN_ERROR_CODES.includes(code)) {
|
|
323
|
+
return true;
|
|
324
|
+
}
|
|
325
|
+
return false;
|
|
326
|
+
}
|
|
308
327
|
function handleFetchError({
|
|
309
328
|
error,
|
|
310
329
|
url,
|
|
@@ -326,6 +345,15 @@ function handleFetchError({
|
|
|
326
345
|
});
|
|
327
346
|
}
|
|
328
347
|
}
|
|
348
|
+
if (isBunNetworkError(error)) {
|
|
349
|
+
return new APICallError({
|
|
350
|
+
message: `Cannot connect to API: ${error.message}`,
|
|
351
|
+
cause: error,
|
|
352
|
+
url,
|
|
353
|
+
requestBodyValues,
|
|
354
|
+
isRetryable: true
|
|
355
|
+
});
|
|
356
|
+
}
|
|
329
357
|
return error;
|
|
330
358
|
}
|
|
331
359
|
|
|
@@ -382,7 +410,7 @@ function withUserAgentSuffix(headers, ...userAgentSuffixParts) {
|
|
|
382
410
|
}
|
|
383
411
|
|
|
384
412
|
// src/version.ts
|
|
385
|
-
var VERSION = true ? "4.0.
|
|
413
|
+
var VERSION = true ? "4.0.11" : "0.0.0-test";
|
|
386
414
|
|
|
387
415
|
// src/get-from-api.ts
|
|
388
416
|
var getOriginalFetch = () => globalThis.fetch;
|
|
@@ -1995,17 +2023,19 @@ function zodSchema(zodSchema2, options) {
|
|
|
1995
2023
|
// src/validate-types.ts
|
|
1996
2024
|
async function validateTypes({
|
|
1997
2025
|
value,
|
|
1998
|
-
schema
|
|
2026
|
+
schema,
|
|
2027
|
+
context
|
|
1999
2028
|
}) {
|
|
2000
|
-
const result = await safeValidateTypes({ value, schema });
|
|
2029
|
+
const result = await safeValidateTypes({ value, schema, context });
|
|
2001
2030
|
if (!result.success) {
|
|
2002
|
-
throw TypeValidationError2.wrap({ value, cause: result.error });
|
|
2031
|
+
throw TypeValidationError2.wrap({ value, cause: result.error, context });
|
|
2003
2032
|
}
|
|
2004
2033
|
return result.value;
|
|
2005
2034
|
}
|
|
2006
2035
|
async function safeValidateTypes({
|
|
2007
2036
|
value,
|
|
2008
|
-
schema
|
|
2037
|
+
schema,
|
|
2038
|
+
context
|
|
2009
2039
|
}) {
|
|
2010
2040
|
const actualSchema = asSchema(schema);
|
|
2011
2041
|
try {
|
|
@@ -2018,13 +2048,13 @@ async function safeValidateTypes({
|
|
|
2018
2048
|
}
|
|
2019
2049
|
return {
|
|
2020
2050
|
success: false,
|
|
2021
|
-
error: TypeValidationError2.wrap({ value, cause: result.error }),
|
|
2051
|
+
error: TypeValidationError2.wrap({ value, cause: result.error, context }),
|
|
2022
2052
|
rawValue: value
|
|
2023
2053
|
};
|
|
2024
2054
|
} catch (error) {
|
|
2025
2055
|
return {
|
|
2026
2056
|
success: false,
|
|
2027
|
-
error: TypeValidationError2.wrap({ value, cause: error }),
|
|
2057
|
+
error: TypeValidationError2.wrap({ value, cause: error, context }),
|
|
2028
2058
|
rawValue: value
|
|
2029
2059
|
};
|
|
2030
2060
|
}
|