Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@ai-sdk/provider-utils

Package Overview
Dependencies
Maintainers
2
Versions
44
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@ai-sdk/provider-utils - npm Package Compare versions

Comparing version 0.0.11 to 0.0.12

96

./dist/index.js

@@ -39,2 +39,3 @@ "use strict";

createJsonResponseHandler: () => createJsonResponseHandler,
download: () => download,
extractResponseHeaders: () => extractResponseHeaders,

@@ -44,2 +45,3 @@ generateId: () => generateId,

isAbortError: () => isAbortError,
isParsableJson: () => isParsableJson,
isParseableJson: () => isParseableJson,

@@ -87,2 +89,31 @@ loadApiKey: () => loadApiKey,

// 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

@@ -124,3 +155,3 @@ function extractResponseHeaders(response) {

// src/load-api-key.ts
var import_provider = require("@ai-sdk/provider");
var import_provider2 = require("@ai-sdk/provider");
function loadApiKey({

@@ -136,3 +167,3 @@ apiKey,

if (apiKey != null) {
throw new import_provider.LoadAPIKeyError({
throw new import_provider2.LoadAPIKeyError({
message: `${description} API key must be a string.`

@@ -142,3 +173,3 @@ });

if (typeof process === "undefined") {
throw new import_provider.LoadAPIKeyError({
throw new import_provider2.LoadAPIKeyError({
message: `${description} API key is missing. Pass it using the '${apiKeyParameterName}' parameter. Environment variables is not supported in this environment.`

@@ -149,3 +180,3 @@ });

if (apiKey == null) {
throw new import_provider.LoadAPIKeyError({
throw new import_provider2.LoadAPIKeyError({
message: `${description} API key is missing. Pass it using the '${apiKeyParameterName}' parameter or the ${environmentVariableName} environment variable.`

@@ -155,3 +186,3 @@ });

if (typeof apiKey !== "string") {
throw new import_provider.LoadAPIKeyError({
throw new import_provider2.LoadAPIKeyError({
message: `${description} API key must be a string. The value of the ${environmentVariableName} environment variable is not a string.`

@@ -164,3 +195,3 @@ });

// src/load-setting.ts
var import_provider2 = require("@ai-sdk/provider");
var import_provider3 = require("@ai-sdk/provider");
function loadSetting({

@@ -176,3 +207,3 @@ settingValue,

if (settingValue != null) {
throw new import_provider2.LoadSettingError({
throw new import_provider3.LoadSettingError({
message: `${description} setting must be a string.`

@@ -182,3 +213,3 @@ });

if (typeof process === "undefined") {
throw new import_provider2.LoadSettingError({
throw new import_provider3.LoadSettingError({
message: `${description} setting is missing. Pass it using the '${settingName}' parameter. Environment variables is not supported in this environment.`

@@ -189,3 +220,3 @@ });

if (settingValue == null) {
throw new import_provider2.LoadSettingError({
throw new import_provider3.LoadSettingError({
message: `${description} setting is missing. Pass it using the '${settingName}' parameter or the ${environmentVariableName} environment variable.`

@@ -195,3 +226,3 @@ });

if (typeof settingValue !== "string") {
throw new import_provider2.LoadSettingError({
throw new import_provider3.LoadSettingError({
message: `${description} setting must be a string. The value of the ${environmentVariableName} environment variable is not a string.`

@@ -204,7 +235,7 @@ });

// src/parse-json.ts
var import_provider4 = require("@ai-sdk/provider");
var import_provider5 = require("@ai-sdk/provider");
var import_secure_json_parse = __toESM(require("secure-json-parse"));
// src/validate-types.ts
var import_provider3 = require("@ai-sdk/provider");
var import_provider4 = require("@ai-sdk/provider");
function validateTypes({

@@ -217,3 +248,3 @@ value,

} catch (error) {
throw new import_provider3.TypeValidationError({ value, cause: error });
throw new import_provider4.TypeValidationError({ value, cause: error });
}

@@ -235,3 +266,3 @@ }

success: false,
error: new import_provider3.TypeValidationError({
error: new import_provider4.TypeValidationError({
value,

@@ -244,3 +275,3 @@ cause: validationResult.error

success: false,
error: import_provider3.TypeValidationError.isTypeValidationError(error) ? error : new import_provider3.TypeValidationError({ value, cause: error })
error: import_provider4.TypeValidationError.isTypeValidationError(error) ? error : new import_provider4.TypeValidationError({ value, cause: error })
};

@@ -262,6 +293,6 @@ }

} catch (error) {
if (import_provider4.JSONParseError.isJSONParseError(error) || import_provider4.TypeValidationError.isTypeValidationError(error)) {
if (import_provider5.JSONParseError.isJSONParseError(error) || import_provider5.TypeValidationError.isTypeValidationError(error)) {
throw error;
}
throw new import_provider4.JSONParseError({ text, cause: error });
throw new import_provider5.JSONParseError({ text, cause: error });
}

@@ -285,7 +316,7 @@ }

success: false,
error: import_provider4.JSONParseError.isJSONParseError(error) ? error : new import_provider4.JSONParseError({ text, cause: error })
error: import_provider5.JSONParseError.isJSONParseError(error) ? error : new import_provider5.JSONParseError({ text, cause: error })
};
}
}
function isParseableJson(input) {
function isParsableJson(input) {
try {

@@ -298,5 +329,6 @@ import_secure_json_parse.default.parse(input);

}
var isParseableJson = isParsableJson;
// src/post-to-api.ts
var import_provider5 = require("@ai-sdk/provider");
var import_provider6 = require("@ai-sdk/provider");
var postJsonToApi = async ({

@@ -351,6 +383,6 @@ url,

} catch (error) {
if (isAbortError(error) || import_provider5.APICallError.isAPICallError(error)) {
if (isAbortError(error) || import_provider6.APICallError.isAPICallError(error)) {
throw error;
}
throw new import_provider5.APICallError({
throw new import_provider6.APICallError({
message: "Failed to process error response",

@@ -374,7 +406,7 @@ cause: error,

if (error instanceof Error) {
if (isAbortError(error) || import_provider5.APICallError.isAPICallError(error)) {
if (isAbortError(error) || import_provider6.APICallError.isAPICallError(error)) {
throw error;
}
}
throw new import_provider5.APICallError({
throw new import_provider6.APICallError({
message: "Failed to process successful response",

@@ -395,3 +427,3 @@ cause: error,

if (cause != null) {
throw new import_provider5.APICallError({
throw new import_provider6.APICallError({
message: `Cannot connect to API: ${cause.message}`,

@@ -411,3 +443,3 @@ cause,

// src/response-handler.ts
var import_provider6 = require("@ai-sdk/provider");
var import_provider7 = require("@ai-sdk/provider");
var import_stream = require("eventsource-parser/stream");

@@ -424,3 +456,3 @@ var createJsonErrorResponseHandler = ({

responseHeaders,
value: new import_provider6.APICallError({
value: new import_provider7.APICallError({
message: response.statusText,

@@ -443,3 +475,3 @@ url,

responseHeaders,
value: new import_provider6.APICallError({
value: new import_provider7.APICallError({
message: errorToMessage(parsedError),

@@ -458,3 +490,3 @@ url,

responseHeaders,
value: new import_provider6.APICallError({
value: new import_provider7.APICallError({
message: response.statusText,

@@ -474,3 +506,3 @@ url,

if (response.body == null) {
throw new import_provider6.EmptyResponseBodyError({});
throw new import_provider7.EmptyResponseBodyError({});
}

@@ -504,3 +536,3 @@ return {

if (!parsedResult.success) {
throw new import_provider6.APICallError({
throw new import_provider7.APICallError({
message: "Invalid JSON response",

@@ -547,2 +579,3 @@ cause: parsedResult.error,

createJsonResponseHandler,
download,
extractResponseHeaders,

@@ -552,2 +585,3 @@ generateId,

isAbortError,
isParsableJson,
isParseableJson,

@@ -554,0 +588,0 @@ loadApiKey,

@@ -14,2 +14,10 @@ import { JSONParseError, TypeValidationError, APICallError } from '@ai-sdk/provider';

declare function download({ url, fetchImplementation, }: {
url: URL;
fetchImplementation?: typeof fetch;
}): Promise<{
data: Uint8Array;
mimeType: string | undefined;
}>;
/**

@@ -95,3 +103,7 @@ Extracts the headers from a response object and returns them as a key-value object.

}): ParseResult<T>;
declare function isParseableJson(input: string): boolean;
declare function isParsableJson(input: string): boolean;
/**
@deprecated Use `isParsableJson` instead.
*/
declare const isParseableJson: typeof isParsableJson;

@@ -178,2 +190,2 @@ type ResponseHandler<RETURN_TYPE> = (options: {

export { type ParseResult, type ResponseHandler, convertAsyncGeneratorToReadableStream, convertBase64ToUint8Array, convertUint8ArrayToBase64, createEventSourceResponseHandler, createJsonErrorResponseHandler, createJsonResponseHandler, extractResponseHeaders, generateId, getErrorMessage, isAbortError, isParseableJson, loadApiKey, loadSetting, parseJSON, postJsonToApi, postToApi, safeParseJSON, safeValidateTypes, validateTypes, withoutTrailingSlash };
export { type ParseResult, type ResponseHandler, convertAsyncGeneratorToReadableStream, convertBase64ToUint8Array, convertUint8ArrayToBase64, createEventSourceResponseHandler, createJsonErrorResponseHandler, createJsonResponseHandler, download, extractResponseHeaders, generateId, getErrorMessage, isAbortError, isParsableJson, isParseableJson, loadApiKey, loadSetting, parseJSON, postJsonToApi, postToApi, safeParseJSON, safeValidateTypes, validateTypes, withoutTrailingSlash };

@@ -39,2 +39,3 @@ "use strict";

createJsonResponseHandler: () => createJsonResponseHandler,
download: () => download,
extractResponseHeaders: () => extractResponseHeaders,

@@ -44,2 +45,3 @@ generateId: () => generateId,

isAbortError: () => isAbortError,
isParsableJson: () => isParsableJson,
isParseableJson: () => isParseableJson,

@@ -87,2 +89,31 @@ loadApiKey: () => loadApiKey,

// 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

@@ -124,3 +155,3 @@ function extractResponseHeaders(response) {

// src/load-api-key.ts
var import_provider = require("@ai-sdk/provider");
var import_provider2 = require("@ai-sdk/provider");
function loadApiKey({

@@ -136,3 +167,3 @@ apiKey,

if (apiKey != null) {
throw new import_provider.LoadAPIKeyError({
throw new import_provider2.LoadAPIKeyError({
message: `${description} API key must be a string.`

@@ -142,3 +173,3 @@ });

if (typeof process === "undefined") {
throw new import_provider.LoadAPIKeyError({
throw new import_provider2.LoadAPIKeyError({
message: `${description} API key is missing. Pass it using the '${apiKeyParameterName}' parameter. Environment variables is not supported in this environment.`

@@ -149,3 +180,3 @@ });

if (apiKey == null) {
throw new import_provider.LoadAPIKeyError({
throw new import_provider2.LoadAPIKeyError({
message: `${description} API key is missing. Pass it using the '${apiKeyParameterName}' parameter or the ${environmentVariableName} environment variable.`

@@ -155,3 +186,3 @@ });

if (typeof apiKey !== "string") {
throw new import_provider.LoadAPIKeyError({
throw new import_provider2.LoadAPIKeyError({
message: `${description} API key must be a string. The value of the ${environmentVariableName} environment variable is not a string.`

@@ -164,3 +195,3 @@ });

// src/load-setting.ts
var import_provider2 = require("@ai-sdk/provider");
var import_provider3 = require("@ai-sdk/provider");
function loadSetting({

@@ -176,3 +207,3 @@ settingValue,

if (settingValue != null) {
throw new import_provider2.LoadSettingError({
throw new import_provider3.LoadSettingError({
message: `${description} setting must be a string.`

@@ -182,3 +213,3 @@ });

if (typeof process === "undefined") {
throw new import_provider2.LoadSettingError({
throw new import_provider3.LoadSettingError({
message: `${description} setting is missing. Pass it using the '${settingName}' parameter. Environment variables is not supported in this environment.`

@@ -189,3 +220,3 @@ });

if (settingValue == null) {
throw new import_provider2.LoadSettingError({
throw new import_provider3.LoadSettingError({
message: `${description} setting is missing. Pass it using the '${settingName}' parameter or the ${environmentVariableName} environment variable.`

@@ -195,3 +226,3 @@ });

if (typeof settingValue !== "string") {
throw new import_provider2.LoadSettingError({
throw new import_provider3.LoadSettingError({
message: `${description} setting must be a string. The value of the ${environmentVariableName} environment variable is not a string.`

@@ -204,7 +235,7 @@ });

// src/parse-json.ts
var import_provider4 = require("@ai-sdk/provider");
var import_provider5 = require("@ai-sdk/provider");
var import_secure_json_parse = __toESM(require("secure-json-parse"));
// src/validate-types.ts
var import_provider3 = require("@ai-sdk/provider");
var import_provider4 = require("@ai-sdk/provider");
function validateTypes({

@@ -217,3 +248,3 @@ value,

} catch (error) {
throw new import_provider3.TypeValidationError({ value, cause: error });
throw new import_provider4.TypeValidationError({ value, cause: error });
}

@@ -235,3 +266,3 @@ }

success: false,
error: new import_provider3.TypeValidationError({
error: new import_provider4.TypeValidationError({
value,

@@ -244,3 +275,3 @@ cause: validationResult.error

success: false,
error: import_provider3.TypeValidationError.isTypeValidationError(error) ? error : new import_provider3.TypeValidationError({ value, cause: error })
error: import_provider4.TypeValidationError.isTypeValidationError(error) ? error : new import_provider4.TypeValidationError({ value, cause: error })
};

@@ -262,6 +293,6 @@ }

} catch (error) {
if (import_provider4.JSONParseError.isJSONParseError(error) || import_provider4.TypeValidationError.isTypeValidationError(error)) {
if (import_provider5.JSONParseError.isJSONParseError(error) || import_provider5.TypeValidationError.isTypeValidationError(error)) {
throw error;
}
throw new import_provider4.JSONParseError({ text, cause: error });
throw new import_provider5.JSONParseError({ text, cause: error });
}

@@ -285,7 +316,7 @@ }

success: false,
error: import_provider4.JSONParseError.isJSONParseError(error) ? error : new import_provider4.JSONParseError({ text, cause: error })
error: import_provider5.JSONParseError.isJSONParseError(error) ? error : new import_provider5.JSONParseError({ text, cause: error })
};
}
}
function isParseableJson(input) {
function isParsableJson(input) {
try {

@@ -298,5 +329,6 @@ import_secure_json_parse.default.parse(input);

}
var isParseableJson = isParsableJson;
// src/post-to-api.ts
var import_provider5 = require("@ai-sdk/provider");
var import_provider6 = require("@ai-sdk/provider");
var postJsonToApi = async ({

@@ -351,6 +383,6 @@ url,

} catch (error) {
if (isAbortError(error) || import_provider5.APICallError.isAPICallError(error)) {
if (isAbortError(error) || import_provider6.APICallError.isAPICallError(error)) {
throw error;
}
throw new import_provider5.APICallError({
throw new import_provider6.APICallError({
message: "Failed to process error response",

@@ -374,7 +406,7 @@ cause: error,

if (error instanceof Error) {
if (isAbortError(error) || import_provider5.APICallError.isAPICallError(error)) {
if (isAbortError(error) || import_provider6.APICallError.isAPICallError(error)) {
throw error;
}
}
throw new import_provider5.APICallError({
throw new import_provider6.APICallError({
message: "Failed to process successful response",

@@ -395,3 +427,3 @@ cause: error,

if (cause != null) {
throw new import_provider5.APICallError({
throw new import_provider6.APICallError({
message: `Cannot connect to API: ${cause.message}`,

@@ -411,3 +443,3 @@ cause,

// src/response-handler.ts
var import_provider6 = require("@ai-sdk/provider");
var import_provider7 = require("@ai-sdk/provider");
var import_stream = require("eventsource-parser/stream");

@@ -424,3 +456,3 @@ var createJsonErrorResponseHandler = ({

responseHeaders,
value: new import_provider6.APICallError({
value: new import_provider7.APICallError({
message: response.statusText,

@@ -443,3 +475,3 @@ url,

responseHeaders,
value: new import_provider6.APICallError({
value: new import_provider7.APICallError({
message: errorToMessage(parsedError),

@@ -458,3 +490,3 @@ url,

responseHeaders,
value: new import_provider6.APICallError({
value: new import_provider7.APICallError({
message: response.statusText,

@@ -474,3 +506,3 @@ url,

if (response.body == null) {
throw new import_provider6.EmptyResponseBodyError({});
throw new import_provider7.EmptyResponseBodyError({});
}

@@ -504,3 +536,3 @@ return {

if (!parsedResult.success) {
throw new import_provider6.APICallError({
throw new import_provider7.APICallError({
message: "Invalid JSON response",

@@ -547,2 +579,3 @@ cause: parsedResult.error,

createJsonResponseHandler,
download,
extractResponseHeaders,

@@ -552,2 +585,3 @@ generateId,

isAbortError,
isParsableJson,
isParseableJson,

@@ -554,0 +588,0 @@ loadApiKey,

{
"name": "@ai-sdk/provider-utils",
"version": "0.0.11",
"version": "0.0.12",
"license": "Apache-2.0",

@@ -28,3 +28,3 @@ "sideEffects": false,

"dependencies": {
"@ai-sdk/provider": "0.0.8",
"@ai-sdk/provider": "0.0.9",
"eventsource-parser": "1.1.2",

@@ -73,4 +73,7 @@ "nanoid": "3.3.6",

"type-check": "tsc --noEmit",
"prettier-check": "prettier --check \"./**/*.ts*\""
"prettier-check": "prettier --check \"./**/*.ts*\"",
"test": "pnpm test:node && pnpm test:edge",
"test:edge": "vitest --config vitest.edge.config.js --run",
"test:node": "vitest --config vitest.node.config.js --run"
}
}

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

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc