🚀 Socket Launch Week Day 5:Introducing Repository Access Permissions and Custom Roles.Learn more
Sign In

ai

Package Overview
Dependencies
Maintainers
5
Versions
1315
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

ai - npm Package Compare versions

Comparing version
6.0.217
to
6.0.218
+1
-3
dist/internal/index.d.mts

@@ -1,2 +0,2 @@

import { SystemModelMessage, ModelMessage, Tool } from '@ai-sdk/provider-utils';
import { SystemModelMessage, ModelMessage, Tool, RetryFunction } from '@ai-sdk/provider-utils';
export { convertAsyncIteratorToReadableStream } from '@ai-sdk/provider-utils';

@@ -321,4 +321,2 @@ import { LanguageModelV3Prompt, LanguageModelV3Usage, JSONObject, LanguageModelV3FunctionTool, LanguageModelV3ProviderTool, LanguageModelV3ToolChoice } from '@ai-sdk/provider';

type RetryFunction = <OUTPUT>(fn: () => PromiseLike<OUTPUT>) => PromiseLike<OUTPUT>;
/**

@@ -325,0 +323,0 @@ * Validate and prepare retries.

@@ -1,2 +0,2 @@

import { SystemModelMessage, ModelMessage, Tool } from '@ai-sdk/provider-utils';
import { SystemModelMessage, ModelMessage, Tool, RetryFunction } from '@ai-sdk/provider-utils';
export { convertAsyncIteratorToReadableStream } from '@ai-sdk/provider-utils';

@@ -321,4 +321,2 @@ import { LanguageModelV3Prompt, LanguageModelV3Usage, JSONObject, LanguageModelV3FunctionTool, LanguageModelV3ProviderTool, LanguageModelV3ToolChoice } from '@ai-sdk/provider';

type RetryFunction = <OUTPUT>(fn: () => PromiseLike<OUTPUT>) => PromiseLike<OUTPUT>;
/**

@@ -325,0 +323,0 @@ * Validate and prepare retries.

@@ -155,3 +155,3 @@ "use strict";

// src/version.ts
var VERSION = true ? "6.0.217" : "0.0.0-test";
var VERSION = true ? "6.0.218" : "0.0.0-test";

@@ -1268,62 +1268,14 @@ // src/util/download/download.ts

abortSignal
} = {}) => async (f) => _retryWithExponentialBackoff(f, {
} = {}) => (0, import_provider_utils7.retryWithExponentialBackoff)({
maxRetries,
delayInMs: initialDelayInMs,
initialDelayInMs,
backoffFactor,
abortSignal
abortSignal,
shouldRetry: (error) => error instanceof Error && (import_provider7.APICallError.isInstance(error) && error.isRetryable === true || import_gateway.GatewayError.isInstance(error) && error.isRetryable === true),
getDelayInMs: ({ error, exponentialBackoffDelay }) => getRetryDelayInMs({
error,
exponentialBackoffDelay
}),
createRetryError: ({ message, reason, errors }) => new RetryError({ message, reason, errors })
});
async function _retryWithExponentialBackoff(f, {
maxRetries,
delayInMs,
backoffFactor,
abortSignal
}, errors = []) {
try {
return await f();
} catch (error) {
if ((0, import_provider_utils7.isAbortError)(error)) {
throw error;
}
if (maxRetries === 0) {
throw error;
}
const errorMessage = (0, import_provider_utils7.getErrorMessage)(error);
const newErrors = [...errors, error];
const tryNumber = newErrors.length;
if (tryNumber > maxRetries) {
throw new RetryError({
message: `Failed after ${tryNumber} attempts. Last error: ${errorMessage}`,
reason: "maxRetriesExceeded",
errors: newErrors
});
}
if (error instanceof Error && (import_provider7.APICallError.isInstance(error) && error.isRetryable === true || import_gateway.GatewayError.isInstance(error) && error.isRetryable === true) && tryNumber <= maxRetries) {
await (0, import_provider_utils7.delay)(
getRetryDelayInMs({
error,
exponentialBackoffDelay: delayInMs
}),
{ abortSignal }
);
return _retryWithExponentialBackoff(
f,
{
maxRetries,
delayInMs: backoffFactor * delayInMs,
backoffFactor,
abortSignal
},
newErrors
);
}
if (tryNumber === 1) {
throw error;
}
throw new RetryError({
message: `Failed after ${tryNumber} attempts with non-retryable error: '${errorMessage}'`,
reason: "errorNotRetryable",
errors: newErrors
});
}
}

@@ -1330,0 +1282,0 @@ // src/util/prepare-retries.ts

@@ -135,3 +135,3 @@ // internal/index.ts

// src/version.ts
var VERSION = true ? "6.0.217" : "0.0.0-test";
var VERSION = true ? "6.0.218" : "0.0.0-test";

@@ -1192,3 +1192,5 @@ // src/util/download/download.ts

import { GatewayError } from "@ai-sdk/gateway";
import { delay, getErrorMessage, isAbortError } from "@ai-sdk/provider-utils";
import {
retryWithExponentialBackoff
} from "@ai-sdk/provider-utils";

@@ -1254,62 +1256,14 @@ // src/util/retry-error.ts

abortSignal
} = {}) => async (f) => _retryWithExponentialBackoff(f, {
} = {}) => retryWithExponentialBackoff({
maxRetries,
delayInMs: initialDelayInMs,
initialDelayInMs,
backoffFactor,
abortSignal
abortSignal,
shouldRetry: (error) => error instanceof Error && (APICallError.isInstance(error) && error.isRetryable === true || GatewayError.isInstance(error) && error.isRetryable === true),
getDelayInMs: ({ error, exponentialBackoffDelay }) => getRetryDelayInMs({
error,
exponentialBackoffDelay
}),
createRetryError: ({ message, reason, errors }) => new RetryError({ message, reason, errors })
});
async function _retryWithExponentialBackoff(f, {
maxRetries,
delayInMs,
backoffFactor,
abortSignal
}, errors = []) {
try {
return await f();
} catch (error) {
if (isAbortError(error)) {
throw error;
}
if (maxRetries === 0) {
throw error;
}
const errorMessage = getErrorMessage(error);
const newErrors = [...errors, error];
const tryNumber = newErrors.length;
if (tryNumber > maxRetries) {
throw new RetryError({
message: `Failed after ${tryNumber} attempts. Last error: ${errorMessage}`,
reason: "maxRetriesExceeded",
errors: newErrors
});
}
if (error instanceof Error && (APICallError.isInstance(error) && error.isRetryable === true || GatewayError.isInstance(error) && error.isRetryable === true) && tryNumber <= maxRetries) {
await delay(
getRetryDelayInMs({
error,
exponentialBackoffDelay: delayInMs
}),
{ abortSignal }
);
return _retryWithExponentialBackoff(
f,
{
maxRetries,
delayInMs: backoffFactor * delayInMs,
backoffFactor,
abortSignal
},
newErrors
);
}
if (tryNumber === 1) {
throw error;
}
throw new RetryError({
message: `Failed after ${tryNumber} attempts with non-retryable error: '${errorMessage}'`,
reason: "errorNotRetryable",
errors: newErrors
});
}
}

@@ -1316,0 +1270,0 @@ // src/util/prepare-retries.ts

{
"name": "ai",
"version": "6.0.217",
"version": "6.0.218",
"description": "AI SDK by Vercel - build apps like ChatGPT, Claude, Gemini, and more with a single interface for any model using the Vercel AI Gateway or go direct to OpenAI, Anthropic, Google, or any other model provider.",

@@ -48,5 +48,5 @@ "license": "Apache-2.0",

"@opentelemetry/api": "^1.9.0",
"@ai-sdk/gateway": "3.0.141",
"@ai-sdk/gateway": "3.0.142",
"@ai-sdk/provider": "3.0.13",
"@ai-sdk/provider-utils": "4.0.34"
"@ai-sdk/provider-utils": "4.0.35"
},

@@ -53,0 +53,0 @@ "devDependencies": {

import { InvalidArgumentError } from '../error/invalid-argument-error';
import {
retryWithExponentialBackoffRespectingRetryHeaders,
type RetryFunction,
} from '../util/retry-with-exponential-backoff';
import type { RetryFunction } from '@ai-sdk/provider-utils';
import { retryWithExponentialBackoffRespectingRetryHeaders } from '../util/retry-with-exponential-backoff';

@@ -7,0 +5,0 @@ /**

import { APICallError } from '@ai-sdk/provider';
import { GatewayError } from '@ai-sdk/gateway';
import { delay, getErrorMessage, isAbortError } from '@ai-sdk/provider-utils';
import {
retryWithExponentialBackoff,
type RetryFunction,
} from '@ai-sdk/provider-utils';
import { RetryError } from './retry-error';
export type RetryFunction = <OUTPUT>(
fn: () => PromiseLike<OUTPUT>,
) => PromiseLike<OUTPUT>;
function getRetryDelayInMs({

@@ -65,96 +64,29 @@ error,

*/
export const retryWithExponentialBackoffRespectingRetryHeaders =
({
maxRetries = 2,
initialDelayInMs = 2000,
backoffFactor = 2,
abortSignal,
}: {
maxRetries?: number;
initialDelayInMs?: number;
backoffFactor?: number;
abortSignal?: AbortSignal;
} = {}): RetryFunction =>
async <OUTPUT>(f: () => PromiseLike<OUTPUT>) =>
_retryWithExponentialBackoff(f, {
maxRetries,
delayInMs: initialDelayInMs,
backoffFactor,
abortSignal,
});
async function _retryWithExponentialBackoff<OUTPUT>(
f: () => PromiseLike<OUTPUT>,
{
export const retryWithExponentialBackoffRespectingRetryHeaders = ({
maxRetries = 2,
initialDelayInMs = 2000,
backoffFactor = 2,
abortSignal,
}: {
maxRetries?: number;
initialDelayInMs?: number;
backoffFactor?: number;
abortSignal?: AbortSignal;
} = {}): RetryFunction =>
retryWithExponentialBackoff({
maxRetries,
delayInMs,
initialDelayInMs,
backoffFactor,
abortSignal,
}: {
maxRetries: number;
delayInMs: number;
backoffFactor: number;
abortSignal: AbortSignal | undefined;
},
errors: unknown[] = [],
): Promise<OUTPUT> {
try {
return await f();
} catch (error) {
if (isAbortError(error)) {
throw error; // don't retry when the request was aborted
}
if (maxRetries === 0) {
throw error; // don't wrap the error when retries are disabled
}
const errorMessage = getErrorMessage(error);
const newErrors = [...errors, error];
const tryNumber = newErrors.length;
if (tryNumber > maxRetries) {
throw new RetryError({
message: `Failed after ${tryNumber} attempts. Last error: ${errorMessage}`,
reason: 'maxRetriesExceeded',
errors: newErrors,
});
}
if (
shouldRetry: error =>
error instanceof Error &&
((APICallError.isInstance(error) && error.isRetryable === true) ||
(GatewayError.isInstance(error) && error.isRetryable === true)) &&
tryNumber <= maxRetries
) {
await delay(
getRetryDelayInMs({
error: error as APICallError | GatewayError,
exponentialBackoffDelay: delayInMs,
}),
{ abortSignal },
);
return _retryWithExponentialBackoff(
f,
{
maxRetries,
delayInMs: backoffFactor * delayInMs,
backoffFactor,
abortSignal,
},
newErrors,
);
}
if (tryNumber === 1) {
throw error; // don't wrap the error when a non-retryable error occurs on the first try
}
throw new RetryError({
message: `Failed after ${tryNumber} attempts with non-retryable error: '${errorMessage}'`,
reason: 'errorNotRetryable',
errors: newErrors,
});
}
}
(GatewayError.isInstance(error) && error.isRetryable === true)),
getDelayInMs: ({ error, exponentialBackoffDelay }) =>
getRetryDelayInMs({
error: error as APICallError | GatewayError,
exponentialBackoffDelay,
}),
createRetryError: ({ message, reason, errors }) =>
new RetryError({ message, reason, errors }),
});

Sorry, the diff of this file is too big to display

Sorry, the diff of this file is too big to display

Sorry, the diff of this file is too big to display

Sorry, the diff of this file is too big to display

Sorry, the diff of this file is too big to display

Sorry, the diff of this file is too big to display

Sorry, the diff of this file is too big to display

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet