@ai-sdk/provider-utils
Advanced tools
Comparing version 1.0.4 to 1.0.5
@@ -41,3 +41,2 @@ "use strict"; | ||
createJsonStreamResponseHandler: () => createJsonStreamResponseHandler, | ||
download: () => download, | ||
extractResponseHeaders: () => extractResponseHeaders, | ||
@@ -105,31 +104,2 @@ generateId: () => generateId, | ||
// src/download.ts | ||
var import_provider = require("@ai-sdk/provider"); | ||
async function download({ | ||
url, | ||
fetchImplementation = fetch | ||
}) { | ||
var _a; | ||
const urlText = url.toString(); | ||
try { | ||
const response = await fetchImplementation(urlText); | ||
if (!response.ok) { | ||
throw new import_provider.DownloadError({ | ||
url: urlText, | ||
statusCode: response.status, | ||
statusText: response.statusText | ||
}); | ||
} | ||
return { | ||
data: new Uint8Array(await response.arrayBuffer()), | ||
mimeType: (_a = response.headers.get("content-type")) != null ? _a : void 0 | ||
}; | ||
} catch (error) { | ||
if (import_provider.DownloadError.isDownloadError(error)) { | ||
throw error; | ||
} | ||
throw new import_provider.DownloadError({ url: urlText, cause: error }); | ||
} | ||
} | ||
// src/extract-response-headers.ts | ||
@@ -171,3 +141,3 @@ function extractResponseHeaders(response) { | ||
// src/load-api-key.ts | ||
var import_provider2 = require("@ai-sdk/provider"); | ||
var import_provider = require("@ai-sdk/provider"); | ||
function loadApiKey({ | ||
@@ -183,3 +153,3 @@ apiKey, | ||
if (apiKey != null) { | ||
throw new import_provider2.LoadAPIKeyError({ | ||
throw new import_provider.LoadAPIKeyError({ | ||
message: `${description} API key must be a string.` | ||
@@ -189,3 +159,3 @@ }); | ||
if (typeof process === "undefined") { | ||
throw new import_provider2.LoadAPIKeyError({ | ||
throw new import_provider.LoadAPIKeyError({ | ||
message: `${description} API key is missing. Pass it using the '${apiKeyParameterName}' parameter. Environment variables is not supported in this environment.` | ||
@@ -196,3 +166,3 @@ }); | ||
if (apiKey == null) { | ||
throw new import_provider2.LoadAPIKeyError({ | ||
throw new import_provider.LoadAPIKeyError({ | ||
message: `${description} API key is missing. Pass it using the '${apiKeyParameterName}' parameter or the ${environmentVariableName} environment variable.` | ||
@@ -202,3 +172,3 @@ }); | ||
if (typeof apiKey !== "string") { | ||
throw new import_provider2.LoadAPIKeyError({ | ||
throw new import_provider.LoadAPIKeyError({ | ||
message: `${description} API key must be a string. The value of the ${environmentVariableName} environment variable is not a string.` | ||
@@ -211,3 +181,3 @@ }); | ||
// src/load-setting.ts | ||
var import_provider3 = require("@ai-sdk/provider"); | ||
var import_provider2 = require("@ai-sdk/provider"); | ||
function loadSetting({ | ||
@@ -223,3 +193,3 @@ settingValue, | ||
if (settingValue != null) { | ||
throw new import_provider3.LoadSettingError({ | ||
throw new import_provider2.LoadSettingError({ | ||
message: `${description} setting must be a string.` | ||
@@ -229,3 +199,3 @@ }); | ||
if (typeof process === "undefined") { | ||
throw new import_provider3.LoadSettingError({ | ||
throw new import_provider2.LoadSettingError({ | ||
message: `${description} setting is missing. Pass it using the '${settingName}' parameter. Environment variables is not supported in this environment.` | ||
@@ -236,3 +206,3 @@ }); | ||
if (settingValue == null) { | ||
throw new import_provider3.LoadSettingError({ | ||
throw new import_provider2.LoadSettingError({ | ||
message: `${description} setting is missing. Pass it using the '${settingName}' parameter or the ${environmentVariableName} environment variable.` | ||
@@ -242,3 +212,3 @@ }); | ||
if (typeof settingValue !== "string") { | ||
throw new import_provider3.LoadSettingError({ | ||
throw new import_provider2.LoadSettingError({ | ||
message: `${description} setting must be a string. The value of the ${environmentVariableName} environment variable is not a string.` | ||
@@ -251,7 +221,7 @@ }); | ||
// src/parse-json.ts | ||
var import_provider5 = require("@ai-sdk/provider"); | ||
var import_provider4 = require("@ai-sdk/provider"); | ||
var import_secure_json_parse = __toESM(require("secure-json-parse")); | ||
// src/validate-types.ts | ||
var import_provider4 = require("@ai-sdk/provider"); | ||
var import_provider3 = require("@ai-sdk/provider"); | ||
@@ -280,3 +250,3 @@ // src/validator.ts | ||
if (!result.success) { | ||
throw new import_provider4.TypeValidationError({ value, cause: result.error }); | ||
throw new import_provider3.TypeValidationError({ value, cause: result.error }); | ||
} | ||
@@ -300,3 +270,3 @@ return result.value; | ||
success: false, | ||
error: new import_provider4.TypeValidationError({ | ||
error: new import_provider3.TypeValidationError({ | ||
value, | ||
@@ -309,3 +279,3 @@ cause: validationResult.error | ||
success: false, | ||
error: import_provider4.TypeValidationError.isTypeValidationError(error) ? error : new import_provider4.TypeValidationError({ value, cause: error }) | ||
error: import_provider3.TypeValidationError.isTypeValidationError(error) ? error : new import_provider3.TypeValidationError({ value, cause: error }) | ||
}; | ||
@@ -327,6 +297,6 @@ } | ||
} catch (error) { | ||
if (import_provider5.JSONParseError.isJSONParseError(error) || import_provider5.TypeValidationError.isTypeValidationError(error)) { | ||
if (import_provider4.JSONParseError.isJSONParseError(error) || import_provider4.TypeValidationError.isTypeValidationError(error)) { | ||
throw error; | ||
} | ||
throw new import_provider5.JSONParseError({ text, cause: error }); | ||
throw new import_provider4.JSONParseError({ text, cause: error }); | ||
} | ||
@@ -350,3 +320,3 @@ } | ||
success: false, | ||
error: import_provider5.JSONParseError.isJSONParseError(error) ? error : new import_provider5.JSONParseError({ text, cause: error }) | ||
error: import_provider4.JSONParseError.isJSONParseError(error) ? error : new import_provider4.JSONParseError({ text, cause: error }) | ||
}; | ||
@@ -366,3 +336,3 @@ } | ||
// src/post-to-api.ts | ||
var import_provider6 = require("@ai-sdk/provider"); | ||
var import_provider5 = require("@ai-sdk/provider"); | ||
@@ -427,6 +397,6 @@ // src/remove-undefined-entries.ts | ||
} catch (error) { | ||
if (isAbortError(error) || import_provider6.APICallError.isAPICallError(error)) { | ||
if (isAbortError(error) || import_provider5.APICallError.isAPICallError(error)) { | ||
throw error; | ||
} | ||
throw new import_provider6.APICallError({ | ||
throw new import_provider5.APICallError({ | ||
message: "Failed to process error response", | ||
@@ -450,7 +420,7 @@ cause: error, | ||
if (error instanceof Error) { | ||
if (isAbortError(error) || import_provider6.APICallError.isAPICallError(error)) { | ||
if (isAbortError(error) || import_provider5.APICallError.isAPICallError(error)) { | ||
throw error; | ||
} | ||
} | ||
throw new import_provider6.APICallError({ | ||
throw new import_provider5.APICallError({ | ||
message: "Failed to process successful response", | ||
@@ -471,3 +441,3 @@ cause: error, | ||
if (cause != null) { | ||
throw new import_provider6.APICallError({ | ||
throw new import_provider5.APICallError({ | ||
message: `Cannot connect to API: ${cause.message}`, | ||
@@ -487,3 +457,3 @@ cause, | ||
// src/response-handler.ts | ||
var import_provider7 = require("@ai-sdk/provider"); | ||
var import_provider6 = require("@ai-sdk/provider"); | ||
var import_stream = require("eventsource-parser/stream"); | ||
@@ -500,3 +470,3 @@ var createJsonErrorResponseHandler = ({ | ||
responseHeaders, | ||
value: new import_provider7.APICallError({ | ||
value: new import_provider6.APICallError({ | ||
message: response.statusText, | ||
@@ -519,3 +489,3 @@ url, | ||
responseHeaders, | ||
value: new import_provider7.APICallError({ | ||
value: new import_provider6.APICallError({ | ||
message: errorToMessage(parsedError), | ||
@@ -534,3 +504,3 @@ url, | ||
responseHeaders, | ||
value: new import_provider7.APICallError({ | ||
value: new import_provider6.APICallError({ | ||
message: response.statusText, | ||
@@ -550,3 +520,3 @@ url, | ||
if (response.body == null) { | ||
throw new import_provider7.EmptyResponseBodyError({}); | ||
throw new import_provider6.EmptyResponseBodyError({}); | ||
} | ||
@@ -575,3 +545,3 @@ return { | ||
if (response.body == null) { | ||
throw new import_provider7.EmptyResponseBodyError({}); | ||
throw new import_provider6.EmptyResponseBodyError({}); | ||
} | ||
@@ -608,3 +578,3 @@ let buffer = ""; | ||
if (!parsedResult.success) { | ||
throw new import_provider7.APICallError({ | ||
throw new import_provider6.APICallError({ | ||
message: "Invalid JSON response", | ||
@@ -653,3 +623,2 @@ cause: parsedResult.error, | ||
createJsonStreamResponseHandler, | ||
download, | ||
extractResponseHeaders, | ||
@@ -656,0 +625,0 @@ generateId, |
@@ -16,10 +16,2 @@ import { JSONParseError, TypeValidationError, APICallError } from '@ai-sdk/provider'; | ||
declare function download({ url, fetchImplementation, }: { | ||
url: URL; | ||
fetchImplementation?: typeof fetch; | ||
}): Promise<{ | ||
data: Uint8Array; | ||
mimeType: string | undefined; | ||
}>; | ||
/** | ||
@@ -230,2 +222,2 @@ Extracts the headers from a response object and returns them as a key-value object. | ||
export { type ParseResult, type ResponseHandler, type Validator, combineHeaders, convertAsyncGeneratorToReadableStream, convertBase64ToUint8Array, convertUint8ArrayToBase64, createEventSourceResponseHandler, createJsonErrorResponseHandler, createJsonResponseHandler, createJsonStreamResponseHandler, download, extractResponseHeaders, generateId, getErrorMessage, isAbortError, isParsableJson, isParseableJson, isValidator, loadApiKey, loadSetting, parseJSON, postJsonToApi, postToApi, safeParseJSON, safeValidateTypes, validateTypes, validator, validatorSymbol, withoutTrailingSlash, zodValidator }; | ||
export { type ParseResult, type ResponseHandler, type Validator, combineHeaders, convertAsyncGeneratorToReadableStream, convertBase64ToUint8Array, convertUint8ArrayToBase64, createEventSourceResponseHandler, createJsonErrorResponseHandler, createJsonResponseHandler, createJsonStreamResponseHandler, extractResponseHeaders, generateId, getErrorMessage, isAbortError, isParsableJson, isParseableJson, isValidator, loadApiKey, loadSetting, parseJSON, postJsonToApi, postToApi, safeParseJSON, safeValidateTypes, validateTypes, validator, validatorSymbol, withoutTrailingSlash, zodValidator }; |
@@ -41,3 +41,2 @@ "use strict"; | ||
createJsonStreamResponseHandler: () => createJsonStreamResponseHandler, | ||
download: () => download, | ||
extractResponseHeaders: () => extractResponseHeaders, | ||
@@ -105,31 +104,2 @@ generateId: () => generateId, | ||
// src/download.ts | ||
var import_provider = require("@ai-sdk/provider"); | ||
async function download({ | ||
url, | ||
fetchImplementation = fetch | ||
}) { | ||
var _a; | ||
const urlText = url.toString(); | ||
try { | ||
const response = await fetchImplementation(urlText); | ||
if (!response.ok) { | ||
throw new import_provider.DownloadError({ | ||
url: urlText, | ||
statusCode: response.status, | ||
statusText: response.statusText | ||
}); | ||
} | ||
return { | ||
data: new Uint8Array(await response.arrayBuffer()), | ||
mimeType: (_a = response.headers.get("content-type")) != null ? _a : void 0 | ||
}; | ||
} catch (error) { | ||
if (import_provider.DownloadError.isDownloadError(error)) { | ||
throw error; | ||
} | ||
throw new import_provider.DownloadError({ url: urlText, cause: error }); | ||
} | ||
} | ||
// src/extract-response-headers.ts | ||
@@ -171,3 +141,3 @@ function extractResponseHeaders(response) { | ||
// src/load-api-key.ts | ||
var import_provider2 = require("@ai-sdk/provider"); | ||
var import_provider = require("@ai-sdk/provider"); | ||
function loadApiKey({ | ||
@@ -183,3 +153,3 @@ apiKey, | ||
if (apiKey != null) { | ||
throw new import_provider2.LoadAPIKeyError({ | ||
throw new import_provider.LoadAPIKeyError({ | ||
message: `${description} API key must be a string.` | ||
@@ -189,3 +159,3 @@ }); | ||
if (typeof process === "undefined") { | ||
throw new import_provider2.LoadAPIKeyError({ | ||
throw new import_provider.LoadAPIKeyError({ | ||
message: `${description} API key is missing. Pass it using the '${apiKeyParameterName}' parameter. Environment variables is not supported in this environment.` | ||
@@ -196,3 +166,3 @@ }); | ||
if (apiKey == null) { | ||
throw new import_provider2.LoadAPIKeyError({ | ||
throw new import_provider.LoadAPIKeyError({ | ||
message: `${description} API key is missing. Pass it using the '${apiKeyParameterName}' parameter or the ${environmentVariableName} environment variable.` | ||
@@ -202,3 +172,3 @@ }); | ||
if (typeof apiKey !== "string") { | ||
throw new import_provider2.LoadAPIKeyError({ | ||
throw new import_provider.LoadAPIKeyError({ | ||
message: `${description} API key must be a string. The value of the ${environmentVariableName} environment variable is not a string.` | ||
@@ -211,3 +181,3 @@ }); | ||
// src/load-setting.ts | ||
var import_provider3 = require("@ai-sdk/provider"); | ||
var import_provider2 = require("@ai-sdk/provider"); | ||
function loadSetting({ | ||
@@ -223,3 +193,3 @@ settingValue, | ||
if (settingValue != null) { | ||
throw new import_provider3.LoadSettingError({ | ||
throw new import_provider2.LoadSettingError({ | ||
message: `${description} setting must be a string.` | ||
@@ -229,3 +199,3 @@ }); | ||
if (typeof process === "undefined") { | ||
throw new import_provider3.LoadSettingError({ | ||
throw new import_provider2.LoadSettingError({ | ||
message: `${description} setting is missing. Pass it using the '${settingName}' parameter. Environment variables is not supported in this environment.` | ||
@@ -236,3 +206,3 @@ }); | ||
if (settingValue == null) { | ||
throw new import_provider3.LoadSettingError({ | ||
throw new import_provider2.LoadSettingError({ | ||
message: `${description} setting is missing. Pass it using the '${settingName}' parameter or the ${environmentVariableName} environment variable.` | ||
@@ -242,3 +212,3 @@ }); | ||
if (typeof settingValue !== "string") { | ||
throw new import_provider3.LoadSettingError({ | ||
throw new import_provider2.LoadSettingError({ | ||
message: `${description} setting must be a string. The value of the ${environmentVariableName} environment variable is not a string.` | ||
@@ -251,7 +221,7 @@ }); | ||
// src/parse-json.ts | ||
var import_provider5 = require("@ai-sdk/provider"); | ||
var import_provider4 = require("@ai-sdk/provider"); | ||
var import_secure_json_parse = __toESM(require("secure-json-parse")); | ||
// src/validate-types.ts | ||
var import_provider4 = require("@ai-sdk/provider"); | ||
var import_provider3 = require("@ai-sdk/provider"); | ||
@@ -280,3 +250,3 @@ // src/validator.ts | ||
if (!result.success) { | ||
throw new import_provider4.TypeValidationError({ value, cause: result.error }); | ||
throw new import_provider3.TypeValidationError({ value, cause: result.error }); | ||
} | ||
@@ -300,3 +270,3 @@ return result.value; | ||
success: false, | ||
error: new import_provider4.TypeValidationError({ | ||
error: new import_provider3.TypeValidationError({ | ||
value, | ||
@@ -309,3 +279,3 @@ cause: validationResult.error | ||
success: false, | ||
error: import_provider4.TypeValidationError.isTypeValidationError(error) ? error : new import_provider4.TypeValidationError({ value, cause: error }) | ||
error: import_provider3.TypeValidationError.isTypeValidationError(error) ? error : new import_provider3.TypeValidationError({ value, cause: error }) | ||
}; | ||
@@ -327,6 +297,6 @@ } | ||
} catch (error) { | ||
if (import_provider5.JSONParseError.isJSONParseError(error) || import_provider5.TypeValidationError.isTypeValidationError(error)) { | ||
if (import_provider4.JSONParseError.isJSONParseError(error) || import_provider4.TypeValidationError.isTypeValidationError(error)) { | ||
throw error; | ||
} | ||
throw new import_provider5.JSONParseError({ text, cause: error }); | ||
throw new import_provider4.JSONParseError({ text, cause: error }); | ||
} | ||
@@ -350,3 +320,3 @@ } | ||
success: false, | ||
error: import_provider5.JSONParseError.isJSONParseError(error) ? error : new import_provider5.JSONParseError({ text, cause: error }) | ||
error: import_provider4.JSONParseError.isJSONParseError(error) ? error : new import_provider4.JSONParseError({ text, cause: error }) | ||
}; | ||
@@ -366,3 +336,3 @@ } | ||
// src/post-to-api.ts | ||
var import_provider6 = require("@ai-sdk/provider"); | ||
var import_provider5 = require("@ai-sdk/provider"); | ||
@@ -427,6 +397,6 @@ // src/remove-undefined-entries.ts | ||
} catch (error) { | ||
if (isAbortError(error) || import_provider6.APICallError.isAPICallError(error)) { | ||
if (isAbortError(error) || import_provider5.APICallError.isAPICallError(error)) { | ||
throw error; | ||
} | ||
throw new import_provider6.APICallError({ | ||
throw new import_provider5.APICallError({ | ||
message: "Failed to process error response", | ||
@@ -450,7 +420,7 @@ cause: error, | ||
if (error instanceof Error) { | ||
if (isAbortError(error) || import_provider6.APICallError.isAPICallError(error)) { | ||
if (isAbortError(error) || import_provider5.APICallError.isAPICallError(error)) { | ||
throw error; | ||
} | ||
} | ||
throw new import_provider6.APICallError({ | ||
throw new import_provider5.APICallError({ | ||
message: "Failed to process successful response", | ||
@@ -471,3 +441,3 @@ cause: error, | ||
if (cause != null) { | ||
throw new import_provider6.APICallError({ | ||
throw new import_provider5.APICallError({ | ||
message: `Cannot connect to API: ${cause.message}`, | ||
@@ -487,3 +457,3 @@ cause, | ||
// src/response-handler.ts | ||
var import_provider7 = require("@ai-sdk/provider"); | ||
var import_provider6 = require("@ai-sdk/provider"); | ||
var import_stream = require("eventsource-parser/stream"); | ||
@@ -500,3 +470,3 @@ var createJsonErrorResponseHandler = ({ | ||
responseHeaders, | ||
value: new import_provider7.APICallError({ | ||
value: new import_provider6.APICallError({ | ||
message: response.statusText, | ||
@@ -519,3 +489,3 @@ url, | ||
responseHeaders, | ||
value: new import_provider7.APICallError({ | ||
value: new import_provider6.APICallError({ | ||
message: errorToMessage(parsedError), | ||
@@ -534,3 +504,3 @@ url, | ||
responseHeaders, | ||
value: new import_provider7.APICallError({ | ||
value: new import_provider6.APICallError({ | ||
message: response.statusText, | ||
@@ -550,3 +520,3 @@ url, | ||
if (response.body == null) { | ||
throw new import_provider7.EmptyResponseBodyError({}); | ||
throw new import_provider6.EmptyResponseBodyError({}); | ||
} | ||
@@ -575,3 +545,3 @@ return { | ||
if (response.body == null) { | ||
throw new import_provider7.EmptyResponseBodyError({}); | ||
throw new import_provider6.EmptyResponseBodyError({}); | ||
} | ||
@@ -608,3 +578,3 @@ let buffer = ""; | ||
if (!parsedResult.success) { | ||
throw new import_provider7.APICallError({ | ||
throw new import_provider6.APICallError({ | ||
message: "Invalid JSON response", | ||
@@ -653,3 +623,2 @@ cause: parsedResult.error, | ||
createJsonStreamResponseHandler, | ||
download, | ||
extractResponseHeaders, | ||
@@ -656,0 +625,0 @@ generateId, |
{ | ||
"name": "@ai-sdk/provider-utils", | ||
"version": "1.0.4", | ||
"version": "1.0.5", | ||
"license": "Apache-2.0", | ||
@@ -28,3 +28,3 @@ "sideEffects": false, | ||
"dependencies": { | ||
"@ai-sdk/provider": "0.0.13", | ||
"@ai-sdk/provider": "0.0.14", | ||
"eventsource-parser": "1.1.2", | ||
@@ -31,0 +31,0 @@ "nanoid": "3.3.6", |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
17
1274817
12886
+ Added@ai-sdk/provider@0.0.14(transitive)
- Removed@ai-sdk/provider@0.0.13(transitive)
Updated@ai-sdk/provider@0.0.14