ai 3.0.21 → 3.0.23
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/dist/index.d.mts +42 -1
- package/dist/index.d.ts +42 -1
- package/dist/index.js +104 -177
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +65 -138
- package/dist/index.mjs.map +1 -1
- package/package.json +4 -33
- package/react/dist/index.d.mts +6 -2
- package/react/dist/index.d.ts +6 -2
- package/react/dist/index.js +107 -24
- package/react/dist/index.js.map +1 -1
- package/react/dist/index.mjs +107 -24
- package/react/dist/index.mjs.map +1 -1
- package/rsc/dist/rsc-server.mjs +3 -3
- package/rsc/dist/rsc-server.mjs.map +1 -1
- package/solid/dist/index.d.mts +6 -2
- package/solid/dist/index.d.ts +6 -2
- package/solid/dist/index.js +105 -23
- package/solid/dist/index.js.map +1 -1
- package/solid/dist/index.mjs +105 -23
- package/solid/dist/index.mjs.map +1 -1
- package/svelte/dist/index.d.mts +6 -2
- package/svelte/dist/index.d.ts +6 -2
- package/svelte/dist/index.js +107 -24
- package/svelte/dist/index.js.map +1 -1
- package/svelte/dist/index.mjs +107 -24
- package/svelte/dist/index.mjs.map +1 -1
- package/vue/dist/index.d.mts +6 -2
- package/vue/dist/index.d.ts +6 -2
- package/vue/dist/index.js +105 -23
- package/vue/dist/index.js.map +1 -1
- package/vue/dist/index.mjs +105 -23
- package/vue/dist/index.mjs.map +1 -1
- package/anthropic/dist/index.d.mts +0 -51
- package/anthropic/dist/index.d.ts +0 -51
- package/anthropic/dist/index.js +0 -792
- package/anthropic/dist/index.js.map +0 -1
- package/anthropic/dist/index.mjs +0 -760
- package/anthropic/dist/index.mjs.map +0 -1
- package/google/dist/index.d.mts +0 -47
- package/google/dist/index.d.ts +0 -47
- package/google/dist/index.js +0 -796
- package/google/dist/index.js.map +0 -1
- package/google/dist/index.mjs +0 -764
- package/google/dist/index.mjs.map +0 -1
- package/mistral/dist/index.d.mts +0 -52
- package/mistral/dist/index.d.ts +0 -52
- package/mistral/dist/index.js +0 -763
- package/mistral/dist/index.js.map +0 -1
- package/mistral/dist/index.mjs +0 -731
- package/mistral/dist/index.mjs.map +0 -1
- package/openai/dist/index.d.mts +0 -116
- package/openai/dist/index.d.ts +0 -116
- package/openai/dist/index.js +0 -1143
- package/openai/dist/index.js.map +0 -1
- package/openai/dist/index.mjs +0 -1115
- package/openai/dist/index.mjs.map +0 -1
package/dist/index.mjs
CHANGED
@@ -2,89 +2,7 @@
|
|
2
2
|
import {
|
3
3
|
NoTextGeneratedError
|
4
4
|
} from "@ai-sdk/provider";
|
5
|
-
|
6
|
-
// spec/util/get-error-message.ts
|
7
|
-
function getErrorMessage(error) {
|
8
|
-
if (error == null) {
|
9
|
-
return "unknown error";
|
10
|
-
}
|
11
|
-
if (typeof error === "string") {
|
12
|
-
return error;
|
13
|
-
}
|
14
|
-
if (error instanceof Error) {
|
15
|
-
return error.message;
|
16
|
-
}
|
17
|
-
return JSON.stringify(error);
|
18
|
-
}
|
19
|
-
|
20
|
-
// spec/util/parse-json.ts
|
21
|
-
import { JSONParseError, TypeValidationError as TypeValidationError2 } from "@ai-sdk/provider";
|
22
|
-
import SecureJSON from "secure-json-parse";
|
23
|
-
|
24
|
-
// spec/util/validate-types.ts
|
25
|
-
import { TypeValidationError } from "@ai-sdk/provider";
|
26
|
-
function safeValidateTypes({
|
27
|
-
value,
|
28
|
-
schema
|
29
|
-
}) {
|
30
|
-
try {
|
31
|
-
const validationResult = schema.safeParse(value);
|
32
|
-
if (validationResult.success) {
|
33
|
-
return {
|
34
|
-
success: true,
|
35
|
-
value: validationResult.data
|
36
|
-
};
|
37
|
-
}
|
38
|
-
return {
|
39
|
-
success: false,
|
40
|
-
error: new TypeValidationError({
|
41
|
-
value,
|
42
|
-
cause: validationResult.error
|
43
|
-
})
|
44
|
-
};
|
45
|
-
} catch (error) {
|
46
|
-
return {
|
47
|
-
success: false,
|
48
|
-
error: TypeValidationError.isTypeValidationError(error) ? error : new TypeValidationError({ value, cause: error })
|
49
|
-
};
|
50
|
-
}
|
51
|
-
}
|
52
|
-
|
53
|
-
// spec/util/parse-json.ts
|
54
|
-
function safeParseJSON({
|
55
|
-
text,
|
56
|
-
schema
|
57
|
-
}) {
|
58
|
-
try {
|
59
|
-
const value = SecureJSON.parse(text);
|
60
|
-
if (schema == null) {
|
61
|
-
return {
|
62
|
-
success: true,
|
63
|
-
value
|
64
|
-
};
|
65
|
-
}
|
66
|
-
return safeValidateTypes({ value, schema });
|
67
|
-
} catch (error) {
|
68
|
-
return {
|
69
|
-
success: false,
|
70
|
-
error: JSONParseError.isJSONParseError(error) ? error : new JSONParseError({ text, cause: error })
|
71
|
-
};
|
72
|
-
}
|
73
|
-
}
|
74
|
-
|
75
|
-
// spec/util/uint8-utils.ts
|
76
|
-
function convertBase64ToUint8Array(base64String) {
|
77
|
-
const base64Url = base64String.replace(/-/g, "+").replace(/_/g, "/");
|
78
|
-
const latin1string = globalThis.atob(base64Url);
|
79
|
-
return Uint8Array.from(latin1string, (byte) => byte.codePointAt(0));
|
80
|
-
}
|
81
|
-
function convertUint8ArrayToBase64(array) {
|
82
|
-
let latin1string = "";
|
83
|
-
for (let i = 0; i < array.length; i++) {
|
84
|
-
latin1string += String.fromCodePoint(array[i]);
|
85
|
-
}
|
86
|
-
return globalThis.btoa(latin1string);
|
87
|
-
}
|
5
|
+
import { safeParseJSON } from "@ai-sdk/provider-utils";
|
88
6
|
|
89
7
|
// core/generate-text/token-usage.ts
|
90
8
|
function calculateTokenUsage(usage) {
|
@@ -113,6 +31,10 @@ function detectImageMimeType(image) {
|
|
113
31
|
|
114
32
|
// core/prompt/data-content.ts
|
115
33
|
import { InvalidDataContentError } from "@ai-sdk/provider";
|
34
|
+
import {
|
35
|
+
convertBase64ToUint8Array,
|
36
|
+
convertUint8ArrayToBase64
|
37
|
+
} from "@ai-sdk/provider-utils";
|
116
38
|
function convertDataContentToBase64String(content) {
|
117
39
|
if (typeof content === "string") {
|
118
40
|
return content;
|
@@ -365,8 +287,8 @@ function prepareCallSettings({
|
|
365
287
|
maxTokens,
|
366
288
|
temperature: temperature != null ? temperature : 0,
|
367
289
|
topP,
|
368
|
-
presencePenalty
|
369
|
-
frequencyPenalty
|
290
|
+
presencePenalty,
|
291
|
+
frequencyPenalty,
|
370
292
|
seed,
|
371
293
|
maxRetries: maxRetries != null ? maxRetries : 2
|
372
294
|
};
|
@@ -380,6 +302,7 @@ function convertZodToJSONSchema(zodSchema) {
|
|
380
302
|
|
381
303
|
// core/util/retry-with-exponential-backoff.ts
|
382
304
|
import { APICallError, RetryError } from "@ai-sdk/provider";
|
305
|
+
import { getErrorMessage } from "@ai-sdk/provider-utils";
|
383
306
|
|
384
307
|
// core/util/delay.ts
|
385
308
|
async function delay(delayInMs) {
|
@@ -415,7 +338,7 @@ async function _retryWithExponentialBackoff(f, {
|
|
415
338
|
const tryNumber = newErrors.length;
|
416
339
|
if (tryNumber > maxRetries) {
|
417
340
|
throw new RetryError({
|
418
|
-
message: `Failed after ${tryNumber}
|
341
|
+
message: `Failed after ${tryNumber} attempts. Last error: ${errorMessage}`,
|
419
342
|
reason: "maxRetriesExceeded",
|
420
343
|
errors: newErrors
|
421
344
|
});
|
@@ -432,7 +355,7 @@ async function _retryWithExponentialBackoff(f, {
|
|
432
355
|
throw error;
|
433
356
|
}
|
434
357
|
throw new RetryError({
|
435
|
-
message: `Failed after ${tryNumber}
|
358
|
+
message: `Failed after ${tryNumber} attempts with non-retryable error: '${errorMessage}'`,
|
436
359
|
reason: "errorNotRetryable",
|
437
360
|
errors: newErrors
|
438
361
|
});
|
@@ -643,7 +566,7 @@ function isDeepEqualData(obj1, obj2) {
|
|
643
566
|
}
|
644
567
|
|
645
568
|
// core/util/parse-partial-json.ts
|
646
|
-
import
|
569
|
+
import SecureJSON from "secure-json-parse";
|
647
570
|
|
648
571
|
// core/util/fix-json.ts
|
649
572
|
function fixJson(input) {
|
@@ -968,11 +891,11 @@ function parsePartialJson(jsonText) {
|
|
968
891
|
return void 0;
|
969
892
|
}
|
970
893
|
try {
|
971
|
-
return
|
894
|
+
return SecureJSON.parse(jsonText);
|
972
895
|
} catch (ignored) {
|
973
896
|
try {
|
974
897
|
const fixedJsonText = fixJson(jsonText);
|
975
|
-
return
|
898
|
+
return SecureJSON.parse(fixedJsonText);
|
976
899
|
} catch (ignored2) {
|
977
900
|
}
|
978
901
|
}
|
@@ -1138,6 +1061,7 @@ import {
|
|
1138
1061
|
InvalidToolArgumentsError,
|
1139
1062
|
NoSuchToolError
|
1140
1063
|
} from "@ai-sdk/provider";
|
1064
|
+
import { safeParseJSON as safeParseJSON2 } from "@ai-sdk/provider-utils";
|
1141
1065
|
function parseToolCall({
|
1142
1066
|
toolCall,
|
1143
1067
|
tools
|
@@ -1153,7 +1077,7 @@ function parseToolCall({
|
|
1153
1077
|
availableTools: Object.keys(tools)
|
1154
1078
|
});
|
1155
1079
|
}
|
1156
|
-
const parseResult =
|
1080
|
+
const parseResult = safeParseJSON2({
|
1157
1081
|
text: toolCall.args,
|
1158
1082
|
schema: tool2.parameters
|
1159
1083
|
});
|
@@ -1493,7 +1417,7 @@ var StreamTextResult = class {
|
|
1493
1417
|
@returns an `AIStream` object.
|
1494
1418
|
*/
|
1495
1419
|
toAIStream(callbacks) {
|
1496
|
-
return
|
1420
|
+
return this.textStream.pipeThrough(createCallbacksTransformer(callbacks)).pipeThrough(createStreamDataTransformer());
|
1497
1421
|
}
|
1498
1422
|
/**
|
1499
1423
|
Creates a simple text stream response.
|
@@ -1627,9 +1551,9 @@ var toolCallStreamPart = {
|
|
1627
1551
|
code: "7",
|
1628
1552
|
name: "tool_calls",
|
1629
1553
|
parse: (value) => {
|
1630
|
-
if (value == null || typeof value !== "object" || !("tool_calls" in value) || typeof value.tool_calls !== "object" || value.tool_calls == null || !Array.isArray(value.tool_calls) || value.tool_calls.some(
|
1631
|
-
tc == null || typeof tc !== "object" || !("id" in tc) || typeof tc.id !== "string" || !("type" in tc) || typeof tc.type !== "string" || !("function" in tc) || tc.function == null || typeof tc.function !== "object" || !("arguments" in tc.function) || typeof tc.function.name !== "string" || typeof tc.function.arguments !== "string"
|
1632
|
-
|
1554
|
+
if (value == null || typeof value !== "object" || !("tool_calls" in value) || typeof value.tool_calls !== "object" || value.tool_calls == null || !Array.isArray(value.tool_calls) || value.tool_calls.some(
|
1555
|
+
(tc) => tc == null || typeof tc !== "object" || !("id" in tc) || typeof tc.id !== "string" || !("type" in tc) || typeof tc.type !== "string" || !("function" in tc) || tc.function == null || typeof tc.function !== "object" || !("arguments" in tc.function) || typeof tc.function.name !== "string" || typeof tc.function.arguments !== "string"
|
1556
|
+
)) {
|
1633
1557
|
throw new Error(
|
1634
1558
|
'"tool_calls" parts expect an object with a ToolCallPayload.'
|
1635
1559
|
);
|
@@ -1707,6 +1631,49 @@ function formatStreamPart(type, value) {
|
|
1707
1631
|
`;
|
1708
1632
|
}
|
1709
1633
|
|
1634
|
+
// shared/read-data-stream.ts
|
1635
|
+
var NEWLINE = "\n".charCodeAt(0);
|
1636
|
+
function concatChunks(chunks, totalLength) {
|
1637
|
+
const concatenatedChunks = new Uint8Array(totalLength);
|
1638
|
+
let offset = 0;
|
1639
|
+
for (const chunk of chunks) {
|
1640
|
+
concatenatedChunks.set(chunk, offset);
|
1641
|
+
offset += chunk.length;
|
1642
|
+
}
|
1643
|
+
chunks.length = 0;
|
1644
|
+
return concatenatedChunks;
|
1645
|
+
}
|
1646
|
+
async function* readDataStream(reader, {
|
1647
|
+
isAborted
|
1648
|
+
} = {}) {
|
1649
|
+
const decoder = new TextDecoder();
|
1650
|
+
const chunks = [];
|
1651
|
+
let totalLength = 0;
|
1652
|
+
while (true) {
|
1653
|
+
const { value } = await reader.read();
|
1654
|
+
if (value) {
|
1655
|
+
chunks.push(value);
|
1656
|
+
totalLength += value.length;
|
1657
|
+
if (value[value.length - 1] !== NEWLINE) {
|
1658
|
+
continue;
|
1659
|
+
}
|
1660
|
+
}
|
1661
|
+
if (chunks.length === 0) {
|
1662
|
+
break;
|
1663
|
+
}
|
1664
|
+
const concatenatedChunks = concatChunks(chunks, totalLength);
|
1665
|
+
totalLength = 0;
|
1666
|
+
const streamParts2 = decoder.decode(concatenatedChunks, { stream: true }).split("\n").filter((line) => line !== "").map(parseStreamPart);
|
1667
|
+
for (const streamPart of streamParts2) {
|
1668
|
+
yield streamPart;
|
1669
|
+
}
|
1670
|
+
if (isAborted == null ? void 0 : isAborted()) {
|
1671
|
+
reader.cancel();
|
1672
|
+
break;
|
1673
|
+
}
|
1674
|
+
}
|
1675
|
+
}
|
1676
|
+
|
1710
1677
|
// shared/utils.ts
|
1711
1678
|
function createChunkDecoder(complex) {
|
1712
1679
|
const decoder = new TextDecoder();
|
@@ -2682,49 +2649,6 @@ async function ReplicateStream(res, cb, options) {
|
|
2682
2649
|
);
|
2683
2650
|
}
|
2684
2651
|
|
2685
|
-
// shared/read-data-stream.ts
|
2686
|
-
var NEWLINE = "\n".charCodeAt(0);
|
2687
|
-
function concatChunks(chunks, totalLength) {
|
2688
|
-
const concatenatedChunks = new Uint8Array(totalLength);
|
2689
|
-
let offset = 0;
|
2690
|
-
for (const chunk of chunks) {
|
2691
|
-
concatenatedChunks.set(chunk, offset);
|
2692
|
-
offset += chunk.length;
|
2693
|
-
}
|
2694
|
-
chunks.length = 0;
|
2695
|
-
return concatenatedChunks;
|
2696
|
-
}
|
2697
|
-
async function* readDataStream(reader, {
|
2698
|
-
isAborted
|
2699
|
-
} = {}) {
|
2700
|
-
const decoder = new TextDecoder();
|
2701
|
-
const chunks = [];
|
2702
|
-
let totalLength = 0;
|
2703
|
-
while (true) {
|
2704
|
-
const { value } = await reader.read();
|
2705
|
-
if (value) {
|
2706
|
-
chunks.push(value);
|
2707
|
-
totalLength += value.length;
|
2708
|
-
if (value[value.length - 1] !== NEWLINE) {
|
2709
|
-
continue;
|
2710
|
-
}
|
2711
|
-
}
|
2712
|
-
if (chunks.length === 0) {
|
2713
|
-
break;
|
2714
|
-
}
|
2715
|
-
const concatenatedChunks = concatChunks(chunks, totalLength);
|
2716
|
-
totalLength = 0;
|
2717
|
-
const streamParts2 = decoder.decode(concatenatedChunks, { stream: true }).split("\n").filter((line) => line !== "").map(parseStreamPart);
|
2718
|
-
for (const streamPart of streamParts2) {
|
2719
|
-
yield streamPart;
|
2720
|
-
}
|
2721
|
-
if (isAborted == null ? void 0 : isAborted()) {
|
2722
|
-
reader.cancel();
|
2723
|
-
break;
|
2724
|
-
}
|
2725
|
-
}
|
2726
|
-
}
|
2727
|
-
|
2728
2652
|
// shared/parse-complex-response.ts
|
2729
2653
|
function assignAnnotationsToMessage(message, annotations) {
|
2730
2654
|
if (!message || !annotations || !annotations.length)
|
@@ -2949,9 +2873,12 @@ export {
|
|
2949
2873
|
experimental_generateText,
|
2950
2874
|
experimental_streamObject,
|
2951
2875
|
experimental_streamText,
|
2876
|
+
formatStreamPart,
|
2952
2877
|
generateId,
|
2953
2878
|
isStreamStringEqualToType,
|
2954
2879
|
generateId as nanoid,
|
2880
|
+
parseStreamPart,
|
2881
|
+
readDataStream,
|
2955
2882
|
readableFromAsyncIterable,
|
2956
2883
|
streamToResponse,
|
2957
2884
|
tool,
|