@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.js
CHANGED
|
@@ -398,6 +398,25 @@ function isAbortError(error) {
|
|
|
398
398
|
|
|
399
399
|
// src/handle-fetch-error.ts
|
|
400
400
|
var FETCH_FAILED_ERROR_MESSAGES = ["fetch failed", "failed to fetch"];
|
|
401
|
+
var BUN_ERROR_CODES = [
|
|
402
|
+
"ConnectionRefused",
|
|
403
|
+
"ConnectionClosed",
|
|
404
|
+
"FailedToOpenSocket",
|
|
405
|
+
"ECONNRESET",
|
|
406
|
+
"ECONNREFUSED",
|
|
407
|
+
"ETIMEDOUT",
|
|
408
|
+
"EPIPE"
|
|
409
|
+
];
|
|
410
|
+
function isBunNetworkError(error) {
|
|
411
|
+
if (!(error instanceof Error)) {
|
|
412
|
+
return false;
|
|
413
|
+
}
|
|
414
|
+
const code = error.code;
|
|
415
|
+
if (typeof code === "string" && BUN_ERROR_CODES.includes(code)) {
|
|
416
|
+
return true;
|
|
417
|
+
}
|
|
418
|
+
return false;
|
|
419
|
+
}
|
|
401
420
|
function handleFetchError({
|
|
402
421
|
error,
|
|
403
422
|
url,
|
|
@@ -419,6 +438,15 @@ function handleFetchError({
|
|
|
419
438
|
});
|
|
420
439
|
}
|
|
421
440
|
}
|
|
441
|
+
if (isBunNetworkError(error)) {
|
|
442
|
+
return new import_provider3.APICallError({
|
|
443
|
+
message: `Cannot connect to API: ${error.message}`,
|
|
444
|
+
cause: error,
|
|
445
|
+
url,
|
|
446
|
+
requestBodyValues,
|
|
447
|
+
isRetryable: true
|
|
448
|
+
});
|
|
449
|
+
}
|
|
422
450
|
return error;
|
|
423
451
|
}
|
|
424
452
|
|
|
@@ -475,7 +503,7 @@ function withUserAgentSuffix(headers, ...userAgentSuffixParts) {
|
|
|
475
503
|
}
|
|
476
504
|
|
|
477
505
|
// src/version.ts
|
|
478
|
-
var VERSION = true ? "4.0.
|
|
506
|
+
var VERSION = true ? "4.0.11" : "0.0.0-test";
|
|
479
507
|
|
|
480
508
|
// src/get-from-api.ts
|
|
481
509
|
var getOriginalFetch = () => globalThis.fetch;
|
|
@@ -2083,17 +2111,19 @@ function zodSchema(zodSchema2, options) {
|
|
|
2083
2111
|
// src/validate-types.ts
|
|
2084
2112
|
async function validateTypes({
|
|
2085
2113
|
value,
|
|
2086
|
-
schema
|
|
2114
|
+
schema,
|
|
2115
|
+
context
|
|
2087
2116
|
}) {
|
|
2088
|
-
const result = await safeValidateTypes({ value, schema });
|
|
2117
|
+
const result = await safeValidateTypes({ value, schema, context });
|
|
2089
2118
|
if (!result.success) {
|
|
2090
|
-
throw import_provider8.TypeValidationError.wrap({ value, cause: result.error });
|
|
2119
|
+
throw import_provider8.TypeValidationError.wrap({ value, cause: result.error, context });
|
|
2091
2120
|
}
|
|
2092
2121
|
return result.value;
|
|
2093
2122
|
}
|
|
2094
2123
|
async function safeValidateTypes({
|
|
2095
2124
|
value,
|
|
2096
|
-
schema
|
|
2125
|
+
schema,
|
|
2126
|
+
context
|
|
2097
2127
|
}) {
|
|
2098
2128
|
const actualSchema = asSchema(schema);
|
|
2099
2129
|
try {
|
|
@@ -2106,13 +2136,13 @@ async function safeValidateTypes({
|
|
|
2106
2136
|
}
|
|
2107
2137
|
return {
|
|
2108
2138
|
success: false,
|
|
2109
|
-
error: import_provider8.TypeValidationError.wrap({ value, cause: result.error }),
|
|
2139
|
+
error: import_provider8.TypeValidationError.wrap({ value, cause: result.error, context }),
|
|
2110
2140
|
rawValue: value
|
|
2111
2141
|
};
|
|
2112
2142
|
} catch (error) {
|
|
2113
2143
|
return {
|
|
2114
2144
|
success: false,
|
|
2115
|
-
error: import_provider8.TypeValidationError.wrap({ value, cause: error }),
|
|
2145
|
+
error: import_provider8.TypeValidationError.wrap({ value, cause: error, context }),
|
|
2116
2146
|
rawValue: value
|
|
2117
2147
|
};
|
|
2118
2148
|
}
|