ai 6.0.217 → 6.0.219
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 +16 -0
- package/dist/index.js +14 -62
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +25 -71
- package/dist/index.mjs.map +1 -1
- package/dist/internal/index.d.mts +1 -3
- package/dist/internal/index.d.ts +1 -3
- package/dist/internal/index.js +10 -58
- package/dist/internal/index.js.map +1 -1
- package/dist/internal/index.mjs +13 -59
- package/dist/internal/index.mjs.map +1 -1
- package/docs/03-ai-sdk-core/16-mcp-tools.mdx +28 -0
- package/docs/03-ai-sdk-core/36-transcription.mdx +2 -2
- package/docs/07-reference/01-ai-sdk-core/23-create-mcp-client.mdx +7 -0
- package/docs/07-reference/01-ai-sdk-core/index.mdx +5 -0
- package/package.json +3 -3
- package/src/util/prepare-retries.ts +2 -4
- package/src/util/retry-with-exponential-backoff.ts +27 -95
package/dist/index.mjs
CHANGED
|
@@ -23,7 +23,7 @@ import { validateTypes as validateTypes2 } from "@ai-sdk/provider-utils";
|
|
|
23
23
|
// src/generate-text/generate-text.ts
|
|
24
24
|
import {
|
|
25
25
|
createIdGenerator,
|
|
26
|
-
getErrorMessage as
|
|
26
|
+
getErrorMessage as getErrorMessage4,
|
|
27
27
|
withUserAgentSuffix as withUserAgentSuffix2
|
|
28
28
|
} from "@ai-sdk/provider-utils";
|
|
29
29
|
|
|
@@ -1171,7 +1171,7 @@ import {
|
|
|
1171
1171
|
} from "@ai-sdk/provider-utils";
|
|
1172
1172
|
|
|
1173
1173
|
// src/version.ts
|
|
1174
|
-
var VERSION = true ? "6.0.
|
|
1174
|
+
var VERSION = true ? "6.0.219" : "0.0.0-test";
|
|
1175
1175
|
|
|
1176
1176
|
// src/util/download/download.ts
|
|
1177
1177
|
var download = async ({
|
|
@@ -2675,7 +2675,9 @@ function mergeObjects(base, overrides) {
|
|
|
2675
2675
|
// src/util/retry-with-exponential-backoff.ts
|
|
2676
2676
|
import { APICallError as APICallError2 } from "@ai-sdk/provider";
|
|
2677
2677
|
import { GatewayError } from "@ai-sdk/gateway";
|
|
2678
|
-
import {
|
|
2678
|
+
import {
|
|
2679
|
+
retryWithExponentialBackoff
|
|
2680
|
+
} from "@ai-sdk/provider-utils";
|
|
2679
2681
|
function getRetryDelayInMs({
|
|
2680
2682
|
error,
|
|
2681
2683
|
exponentialBackoffDelay
|
|
@@ -2710,66 +2712,18 @@ var retryWithExponentialBackoffRespectingRetryHeaders = ({
|
|
|
2710
2712
|
initialDelayInMs = 2e3,
|
|
2711
2713
|
backoffFactor = 2,
|
|
2712
2714
|
abortSignal
|
|
2713
|
-
} = {}) =>
|
|
2715
|
+
} = {}) => retryWithExponentialBackoff({
|
|
2714
2716
|
maxRetries,
|
|
2715
|
-
|
|
2717
|
+
initialDelayInMs,
|
|
2716
2718
|
backoffFactor,
|
|
2717
|
-
abortSignal
|
|
2719
|
+
abortSignal,
|
|
2720
|
+
shouldRetry: (error) => error instanceof Error && (APICallError2.isInstance(error) && error.isRetryable === true || GatewayError.isInstance(error) && error.isRetryable === true),
|
|
2721
|
+
getDelayInMs: ({ error, exponentialBackoffDelay }) => getRetryDelayInMs({
|
|
2722
|
+
error,
|
|
2723
|
+
exponentialBackoffDelay
|
|
2724
|
+
}),
|
|
2725
|
+
createRetryError: ({ message, reason, errors }) => new RetryError({ message, reason, errors })
|
|
2718
2726
|
});
|
|
2719
|
-
async function _retryWithExponentialBackoff(f, {
|
|
2720
|
-
maxRetries,
|
|
2721
|
-
delayInMs,
|
|
2722
|
-
backoffFactor,
|
|
2723
|
-
abortSignal
|
|
2724
|
-
}, errors = []) {
|
|
2725
|
-
try {
|
|
2726
|
-
return await f();
|
|
2727
|
-
} catch (error) {
|
|
2728
|
-
if (isAbortError(error)) {
|
|
2729
|
-
throw error;
|
|
2730
|
-
}
|
|
2731
|
-
if (maxRetries === 0) {
|
|
2732
|
-
throw error;
|
|
2733
|
-
}
|
|
2734
|
-
const errorMessage = getErrorMessage4(error);
|
|
2735
|
-
const newErrors = [...errors, error];
|
|
2736
|
-
const tryNumber = newErrors.length;
|
|
2737
|
-
if (tryNumber > maxRetries) {
|
|
2738
|
-
throw new RetryError({
|
|
2739
|
-
message: `Failed after ${tryNumber} attempts. Last error: ${errorMessage}`,
|
|
2740
|
-
reason: "maxRetriesExceeded",
|
|
2741
|
-
errors: newErrors
|
|
2742
|
-
});
|
|
2743
|
-
}
|
|
2744
|
-
if (error instanceof Error && (APICallError2.isInstance(error) && error.isRetryable === true || GatewayError.isInstance(error) && error.isRetryable === true) && tryNumber <= maxRetries) {
|
|
2745
|
-
await delay(
|
|
2746
|
-
getRetryDelayInMs({
|
|
2747
|
-
error,
|
|
2748
|
-
exponentialBackoffDelay: delayInMs
|
|
2749
|
-
}),
|
|
2750
|
-
{ abortSignal }
|
|
2751
|
-
);
|
|
2752
|
-
return _retryWithExponentialBackoff(
|
|
2753
|
-
f,
|
|
2754
|
-
{
|
|
2755
|
-
maxRetries,
|
|
2756
|
-
delayInMs: backoffFactor * delayInMs,
|
|
2757
|
-
backoffFactor,
|
|
2758
|
-
abortSignal
|
|
2759
|
-
},
|
|
2760
|
-
newErrors
|
|
2761
|
-
);
|
|
2762
|
-
}
|
|
2763
|
-
if (tryNumber === 1) {
|
|
2764
|
-
throw error;
|
|
2765
|
-
}
|
|
2766
|
-
throw new RetryError({
|
|
2767
|
-
message: `Failed after ${tryNumber} attempts with non-retryable error: '${errorMessage}'`,
|
|
2768
|
-
reason: "errorNotRetryable",
|
|
2769
|
-
errors: newErrors
|
|
2770
|
-
});
|
|
2771
|
-
}
|
|
2772
|
-
}
|
|
2773
2727
|
|
|
2774
2728
|
// src/util/prepare-retries.ts
|
|
2775
2729
|
function prepareRetries({
|
|
@@ -4799,7 +4753,7 @@ async function generateText({
|
|
|
4799
4753
|
toolCallId: toolCall.toolCallId,
|
|
4800
4754
|
toolName: toolCall.toolName,
|
|
4801
4755
|
input: toolCall.input,
|
|
4802
|
-
error:
|
|
4756
|
+
error: getErrorMessage4(toolCall.error),
|
|
4803
4757
|
dynamic: true
|
|
4804
4758
|
});
|
|
4805
4759
|
}
|
|
@@ -5260,13 +5214,13 @@ function asContent({
|
|
|
5260
5214
|
|
|
5261
5215
|
// src/generate-text/stream-text.ts
|
|
5262
5216
|
import {
|
|
5263
|
-
getErrorMessage as
|
|
5217
|
+
getErrorMessage as getErrorMessage6,
|
|
5264
5218
|
UnsupportedFunctionalityError as UnsupportedFunctionalityError2
|
|
5265
5219
|
} from "@ai-sdk/provider";
|
|
5266
5220
|
import {
|
|
5267
5221
|
createIdGenerator as createIdGenerator2,
|
|
5268
5222
|
DelayedPromise,
|
|
5269
|
-
isAbortError
|
|
5223
|
+
isAbortError
|
|
5270
5224
|
} from "@ai-sdk/provider-utils";
|
|
5271
5225
|
|
|
5272
5226
|
// src/util/prepare-headers.ts
|
|
@@ -6509,7 +6463,7 @@ function createStitchableStream() {
|
|
|
6509
6463
|
|
|
6510
6464
|
// src/generate-text/run-tools-transformation.ts
|
|
6511
6465
|
import {
|
|
6512
|
-
getErrorMessage as
|
|
6466
|
+
getErrorMessage as getErrorMessage5
|
|
6513
6467
|
} from "@ai-sdk/provider-utils";
|
|
6514
6468
|
function runToolsTransformation({
|
|
6515
6469
|
tools,
|
|
@@ -6625,7 +6579,7 @@ function runToolsTransformation({
|
|
|
6625
6579
|
toolCallId: toolCall.toolCallId,
|
|
6626
6580
|
toolName: toolCall.toolName,
|
|
6627
6581
|
input: toolCall.input,
|
|
6628
|
-
error:
|
|
6582
|
+
error: getErrorMessage5(toolCall.error),
|
|
6629
6583
|
dynamic: true,
|
|
6630
6584
|
title: toolCall.title,
|
|
6631
6585
|
...toolCall.toolMetadata != null ? { toolMetadata: toolCall.toolMetadata } : {}
|
|
@@ -7293,7 +7247,7 @@ var DefaultStreamTextResult = class {
|
|
|
7293
7247
|
// The `reason` is usually of type DOMException, but it can also be of any type,
|
|
7294
7248
|
// so we use getErrorMessage for serialization because it is already designed to accept values of the unknown type.
|
|
7295
7249
|
// See: https://developer.mozilla.org/en-US/docs/Web/API/AbortSignal/reason
|
|
7296
|
-
...(abortSignal == null ? void 0 : abortSignal.reason) !== void 0 ? { reason:
|
|
7250
|
+
...(abortSignal == null ? void 0 : abortSignal.reason) !== void 0 ? { reason: getErrorMessage6(abortSignal.reason) } : {}
|
|
7297
7251
|
});
|
|
7298
7252
|
controller.close();
|
|
7299
7253
|
}
|
|
@@ -7309,7 +7263,7 @@ var DefaultStreamTextResult = class {
|
|
|
7309
7263
|
}
|
|
7310
7264
|
controller.enqueue(value);
|
|
7311
7265
|
} catch (error) {
|
|
7312
|
-
if (
|
|
7266
|
+
if (isAbortError(error) && (abortSignal == null ? void 0 : abortSignal.aborted)) {
|
|
7313
7267
|
abort();
|
|
7314
7268
|
} else {
|
|
7315
7269
|
controller.error(error);
|
|
@@ -11004,12 +10958,12 @@ function simulateReadableStream({
|
|
|
11004
10958
|
_internal
|
|
11005
10959
|
}) {
|
|
11006
10960
|
var _a22;
|
|
11007
|
-
const
|
|
10961
|
+
const delay = (_a22 = _internal == null ? void 0 : _internal.delay) != null ? _a22 : delayFunction;
|
|
11008
10962
|
let index = 0;
|
|
11009
10963
|
return new ReadableStream({
|
|
11010
10964
|
async pull(controller) {
|
|
11011
10965
|
if (index < chunks.length) {
|
|
11012
|
-
await
|
|
10966
|
+
await delay(index === 0 ? initialDelayInMs : chunkDelayInMs);
|
|
11013
10967
|
controller.enqueue(chunks[index++]);
|
|
11014
10968
|
} else {
|
|
11015
10969
|
controller.close();
|
|
@@ -11753,7 +11707,7 @@ var CHUNKING_REGEXPS = {
|
|
|
11753
11707
|
function smoothStream({
|
|
11754
11708
|
delayInMs = 10,
|
|
11755
11709
|
chunking = "word",
|
|
11756
|
-
_internal: { delay
|
|
11710
|
+
_internal: { delay = originalDelay } = {}
|
|
11757
11711
|
} = {}) {
|
|
11758
11712
|
let detectChunk;
|
|
11759
11713
|
if (chunking != null && typeof chunking === "object" && "segment" in chunking && typeof chunking.segment === "function") {
|
|
@@ -11834,7 +11788,7 @@ function smoothStream({
|
|
|
11834
11788
|
while ((match = detectChunk(buffer)) != null) {
|
|
11835
11789
|
controller.enqueue({ type, text: match, id });
|
|
11836
11790
|
buffer = buffer.slice(match.length);
|
|
11837
|
-
await
|
|
11791
|
+
await delay(delayInMs);
|
|
11838
11792
|
}
|
|
11839
11793
|
}
|
|
11840
11794
|
});
|