ai 5.0.284 → 5.0.286
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 +29 -0
- package/dist/index.js +45 -35
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +47 -35
- package/dist/index.mjs.map +1 -1
- package/dist/internal/index.js +114 -64
- package/dist/internal/index.js.map +1 -1
- package/dist/internal/index.mjs +103 -51
- package/dist/internal/index.mjs.map +1 -1
- package/package.json +4 -3
package/dist/index.mjs
CHANGED
|
@@ -758,7 +758,7 @@ import {
|
|
|
758
758
|
} from "@ai-sdk/provider-utils";
|
|
759
759
|
|
|
760
760
|
// src/version.ts
|
|
761
|
-
var VERSION = true ? "5.0.
|
|
761
|
+
var VERSION = true ? "5.0.286" : "0.0.0-test";
|
|
762
762
|
|
|
763
763
|
// src/util/download/download.ts
|
|
764
764
|
var download = async ({
|
|
@@ -814,6 +814,8 @@ var createDefaultDownloadFunction = (download2 = download) => (requestedDownload
|
|
|
814
814
|
// src/prompt/data-content.ts
|
|
815
815
|
import { AISDKError as AISDKError19 } from "@ai-sdk/provider";
|
|
816
816
|
import {
|
|
817
|
+
isUint8Array,
|
|
818
|
+
isArrayBuffer,
|
|
817
819
|
convertBase64ToUint8Array as convertBase64ToUint8Array2,
|
|
818
820
|
convertUint8ArrayToBase64
|
|
819
821
|
} from "@ai-sdk/provider-utils";
|
|
@@ -838,8 +840,8 @@ function splitDataUrl(dataUrl) {
|
|
|
838
840
|
// src/prompt/data-content.ts
|
|
839
841
|
var dataContentSchema = z.union([
|
|
840
842
|
z.string(),
|
|
841
|
-
z.
|
|
842
|
-
z.
|
|
843
|
+
z.custom(isUint8Array, { message: "Must be a Uint8Array" }),
|
|
844
|
+
z.custom(isArrayBuffer, { message: "Must be an ArrayBuffer" }),
|
|
843
845
|
z.custom(
|
|
844
846
|
// Buffer might not be available in some environments such as CloudFlare:
|
|
845
847
|
(value) => {
|
|
@@ -850,10 +852,13 @@ var dataContentSchema = z.union([
|
|
|
850
852
|
)
|
|
851
853
|
]);
|
|
852
854
|
function convertToLanguageModelV2DataContent(content) {
|
|
853
|
-
if (content
|
|
854
|
-
return {
|
|
855
|
+
if (isUint8Array(content)) {
|
|
856
|
+
return {
|
|
857
|
+
data: convertDataContentToUint8Array(content),
|
|
858
|
+
mediaType: void 0
|
|
859
|
+
};
|
|
855
860
|
}
|
|
856
|
-
if (content
|
|
861
|
+
if (isArrayBuffer(content)) {
|
|
857
862
|
return { data: new Uint8Array(content), mediaType: void 0 };
|
|
858
863
|
}
|
|
859
864
|
if (typeof content === "string") {
|
|
@@ -880,14 +885,15 @@ function convertDataContentToBase64String(content) {
|
|
|
880
885
|
if (typeof content === "string") {
|
|
881
886
|
return content;
|
|
882
887
|
}
|
|
883
|
-
|
|
884
|
-
return convertUint8ArrayToBase64(new Uint8Array(content));
|
|
885
|
-
}
|
|
886
|
-
return convertUint8ArrayToBase64(content);
|
|
888
|
+
return convertUint8ArrayToBase64(convertDataContentToUint8Array(content));
|
|
887
889
|
}
|
|
888
890
|
function convertDataContentToUint8Array(content) {
|
|
889
|
-
if (content
|
|
890
|
-
|
|
891
|
+
if (isUint8Array(content)) {
|
|
892
|
+
if (content instanceof Uint8Array) {
|
|
893
|
+
return content;
|
|
894
|
+
}
|
|
895
|
+
const { buffer, byteOffset, byteLength } = content;
|
|
896
|
+
return new Uint8Array(buffer, byteOffset, byteLength);
|
|
891
897
|
}
|
|
892
898
|
if (typeof content === "string") {
|
|
893
899
|
try {
|
|
@@ -900,7 +906,7 @@ function convertDataContentToUint8Array(content) {
|
|
|
900
906
|
});
|
|
901
907
|
}
|
|
902
908
|
}
|
|
903
|
-
if (content
|
|
909
|
+
if (isArrayBuffer(content)) {
|
|
904
910
|
return new Uint8Array(content);
|
|
905
911
|
}
|
|
906
912
|
throw new InvalidDataContentError({ content });
|
|
@@ -1251,7 +1257,8 @@ function prepareToolsAndToolChoice({
|
|
|
1251
1257
|
if (!isNonEmptyObject(tools)) {
|
|
1252
1258
|
return {
|
|
1253
1259
|
tools: void 0,
|
|
1254
|
-
|
|
1260
|
+
// Providers can configure native tools without SDK tools.
|
|
1261
|
+
toolChoice: toolChoice === "none" ? { type: "none" } : void 0
|
|
1255
1262
|
};
|
|
1256
1263
|
}
|
|
1257
1264
|
const filteredTools = activeTools != null ? Object.entries(tools).filter(
|
|
@@ -1954,9 +1961,8 @@ var DefaultGeneratedFile = class {
|
|
|
1954
1961
|
data,
|
|
1955
1962
|
mediaType
|
|
1956
1963
|
}) {
|
|
1957
|
-
|
|
1958
|
-
this.
|
|
1959
|
-
this.uint8ArrayData = isUint8Array ? data : void 0;
|
|
1964
|
+
this.base64Data = typeof data === "string" ? data : void 0;
|
|
1965
|
+
this.uint8ArrayData = typeof data === "string" ? void 0 : convertDataContentToUint8Array(data);
|
|
1960
1966
|
this.mediaType = mediaType;
|
|
1961
1967
|
}
|
|
1962
1968
|
// lazy conversion with caching to avoid unnecessary conversion overhead:
|
|
@@ -2505,9 +2511,9 @@ async function generateText({
|
|
|
2505
2511
|
"ai.response.id": responseData.id,
|
|
2506
2512
|
"ai.response.model": responseData.modelId,
|
|
2507
2513
|
"ai.response.timestamp": responseData.timestamp.toISOString(),
|
|
2508
|
-
"ai.response.providerMetadata":
|
|
2509
|
-
result.providerMetadata
|
|
2510
|
-
|
|
2514
|
+
"ai.response.providerMetadata": {
|
|
2515
|
+
output: () => JSON.stringify(result.providerMetadata)
|
|
2516
|
+
},
|
|
2511
2517
|
// TODO rename telemetry attributes to inputTokens and outputTokens
|
|
2512
2518
|
"ai.usage.promptTokens": result.usage.inputTokens,
|
|
2513
2519
|
"ai.usage.completionTokens": result.usage.outputTokens,
|
|
@@ -2653,9 +2659,9 @@ async function generateText({
|
|
|
2653
2659
|
return toolCalls == null ? void 0 : JSON.stringify(toolCalls);
|
|
2654
2660
|
}
|
|
2655
2661
|
},
|
|
2656
|
-
"ai.response.providerMetadata":
|
|
2657
|
-
currentModelResponse.providerMetadata
|
|
2658
|
-
|
|
2662
|
+
"ai.response.providerMetadata": {
|
|
2663
|
+
output: () => JSON.stringify(currentModelResponse.providerMetadata)
|
|
2664
|
+
},
|
|
2659
2665
|
// TODO rename telemetry attributes to inputTokens and outputTokens
|
|
2660
2666
|
"ai.usage.promptTokens": currentModelResponse.usage.inputTokens,
|
|
2661
2667
|
"ai.usage.completionTokens": currentModelResponse.usage.outputTokens
|
|
@@ -5360,9 +5366,9 @@ var DefaultStreamTextResult = class {
|
|
|
5360
5366
|
return ((_a17 = finalStep.toolCalls) == null ? void 0 : _a17.length) ? JSON.stringify(finalStep.toolCalls) : void 0;
|
|
5361
5367
|
}
|
|
5362
5368
|
},
|
|
5363
|
-
"ai.response.providerMetadata":
|
|
5364
|
-
finalStep.providerMetadata
|
|
5365
|
-
|
|
5369
|
+
"ai.response.providerMetadata": {
|
|
5370
|
+
output: () => JSON.stringify(finalStep.providerMetadata)
|
|
5371
|
+
},
|
|
5366
5372
|
"ai.usage.inputTokens": totalUsage.inputTokens,
|
|
5367
5373
|
"ai.usage.outputTokens": totalUsage.outputTokens,
|
|
5368
5374
|
"ai.usage.totalTokens": totalUsage.totalTokens,
|
|
@@ -5761,7 +5767,9 @@ var DefaultStreamTextResult = class {
|
|
|
5761
5767
|
"ai.response.id": stepResponse.id,
|
|
5762
5768
|
"ai.response.model": stepResponse.modelId,
|
|
5763
5769
|
"ai.response.timestamp": stepResponse.timestamp.toISOString(),
|
|
5764
|
-
"ai.response.providerMetadata":
|
|
5770
|
+
"ai.response.providerMetadata": {
|
|
5771
|
+
output: () => JSON.stringify(stepProviderMetadata)
|
|
5772
|
+
},
|
|
5765
5773
|
"ai.usage.inputTokens": stepUsage.inputTokens,
|
|
5766
5774
|
"ai.usage.outputTokens": stepUsage.outputTokens,
|
|
5767
5775
|
"ai.usage.totalTokens": stepUsage.totalTokens,
|
|
@@ -7890,9 +7898,9 @@ async function generateObject(options) {
|
|
|
7890
7898
|
"ai.response.id": responseData.id,
|
|
7891
7899
|
"ai.response.model": responseData.modelId,
|
|
7892
7900
|
"ai.response.timestamp": responseData.timestamp.toISOString(),
|
|
7893
|
-
"ai.response.providerMetadata":
|
|
7894
|
-
result2.providerMetadata
|
|
7895
|
-
|
|
7901
|
+
"ai.response.providerMetadata": {
|
|
7902
|
+
output: () => JSON.stringify(result2.providerMetadata)
|
|
7903
|
+
},
|
|
7896
7904
|
// TODO rename telemetry attributes to inputTokens and outputTokens
|
|
7897
7905
|
"ai.usage.promptTokens": result2.usage.inputTokens,
|
|
7898
7906
|
"ai.usage.completionTokens": result2.usage.outputTokens,
|
|
@@ -7941,9 +7949,9 @@ async function generateObject(options) {
|
|
|
7941
7949
|
"ai.response.object": {
|
|
7942
7950
|
output: () => JSON.stringify(object2)
|
|
7943
7951
|
},
|
|
7944
|
-
"ai.response.providerMetadata":
|
|
7945
|
-
resultProviderMetadata
|
|
7946
|
-
|
|
7952
|
+
"ai.response.providerMetadata": {
|
|
7953
|
+
output: () => JSON.stringify(resultProviderMetadata)
|
|
7954
|
+
},
|
|
7947
7955
|
// TODO rename telemetry attributes to inputTokens and outputTokens
|
|
7948
7956
|
"ai.usage.promptTokens": usage.inputTokens,
|
|
7949
7957
|
"ai.usage.completionTokens": usage.outputTokens
|
|
@@ -8541,7 +8549,9 @@ var DefaultStreamObjectResult = class {
|
|
|
8541
8549
|
"ai.response.id": fullResponse.id,
|
|
8542
8550
|
"ai.response.model": fullResponse.modelId,
|
|
8543
8551
|
"ai.response.timestamp": fullResponse.timestamp.toISOString(),
|
|
8544
|
-
"ai.response.providerMetadata":
|
|
8552
|
+
"ai.response.providerMetadata": {
|
|
8553
|
+
output: () => JSON.stringify(providerMetadata)
|
|
8554
|
+
},
|
|
8545
8555
|
"ai.usage.inputTokens": finalUsage.inputTokens,
|
|
8546
8556
|
"ai.usage.outputTokens": finalUsage.outputTokens,
|
|
8547
8557
|
"ai.usage.totalTokens": finalUsage.totalTokens,
|
|
@@ -8569,7 +8579,9 @@ var DefaultStreamObjectResult = class {
|
|
|
8569
8579
|
"ai.response.object": {
|
|
8570
8580
|
output: () => JSON.stringify(object2)
|
|
8571
8581
|
},
|
|
8572
|
-
"ai.response.providerMetadata":
|
|
8582
|
+
"ai.response.providerMetadata": {
|
|
8583
|
+
output: () => JSON.stringify(providerMetadata)
|
|
8584
|
+
}
|
|
8573
8585
|
}
|
|
8574
8586
|
})
|
|
8575
8587
|
);
|