@ai-sdk/google 4.0.0-beta.46 → 4.0.0-beta.48
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 +21 -0
- package/dist/index.js +123 -77
- package/dist/index.js.map +1 -1
- package/dist/internal/index.js +113 -70
- package/dist/internal/index.js.map +1 -1
- package/package.json +6 -5
- package/src/convert-google-usage.ts +1 -1
- package/src/convert-json-schema-to-openapi-schema.ts +1 -1
- package/src/convert-to-google-messages.ts +123 -82
- package/src/google-embedding-model.ts +3 -4
- package/src/google-embedding-options.ts +1 -1
- package/src/google-error.ts +1 -1
- package/src/google-files.ts +3 -6
- package/src/google-image-model.ts +26 -17
- package/src/google-language-model.ts +14 -11
- package/src/google-options.ts +5 -1
- package/src/google-prepare-tools.ts +3 -3
- package/src/google-prompt.ts +2 -2
- package/src/google-provider.ts +6 -6
- package/src/google-video-model.ts +2 -2
- package/src/map-google-finish-reason.ts +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,26 @@
|
|
|
1
1
|
# @ai-sdk/google
|
|
2
2
|
|
|
3
|
+
## 4.0.0-beta.48
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- 9bd6512: feat(provider): change file part data property to be tagged with a type and remove the image part type
|
|
8
|
+
- 258c093: chore: ensure consistent import handling and avoid import duplicates or cycles
|
|
9
|
+
- Updated dependencies [9bd6512]
|
|
10
|
+
- Updated dependencies [258c093]
|
|
11
|
+
- Updated dependencies [b6783da]
|
|
12
|
+
- @ai-sdk/provider-utils@5.0.0-beta.29
|
|
13
|
+
- @ai-sdk/provider@4.0.0-beta.14
|
|
14
|
+
|
|
15
|
+
## 4.0.0-beta.47
|
|
16
|
+
|
|
17
|
+
### Patch Changes
|
|
18
|
+
|
|
19
|
+
- 9f0e36c: trigger release for all packages after provenance setup
|
|
20
|
+
- Updated dependencies [9f0e36c]
|
|
21
|
+
- @ai-sdk/provider@4.0.0-beta.13
|
|
22
|
+
- @ai-sdk/provider-utils@5.0.0-beta.28
|
|
23
|
+
|
|
3
24
|
## 4.0.0-beta.46
|
|
4
25
|
|
|
5
26
|
### Patch Changes
|
package/dist/index.js
CHANGED
|
@@ -7,7 +7,7 @@ import {
|
|
|
7
7
|
} from "@ai-sdk/provider-utils";
|
|
8
8
|
|
|
9
9
|
// src/version.ts
|
|
10
|
-
var VERSION = true ? "4.0.0-beta.
|
|
10
|
+
var VERSION = true ? "4.0.0-beta.48" : "0.0.0-test";
|
|
11
11
|
|
|
12
12
|
// src/google-embedding-model.ts
|
|
13
13
|
import {
|
|
@@ -425,7 +425,8 @@ import {
|
|
|
425
425
|
} from "@ai-sdk/provider";
|
|
426
426
|
import {
|
|
427
427
|
convertToBase64,
|
|
428
|
-
|
|
428
|
+
isFullMediaType,
|
|
429
|
+
resolveFullMediaType,
|
|
429
430
|
resolveProviderReference
|
|
430
431
|
} from "@ai-sdk/provider-utils";
|
|
431
432
|
var dataUrlRegex = /^data:([^;,]+);base64,(.+)$/s;
|
|
@@ -563,36 +564,53 @@ function convertToGoogleMessages(prompt, options) {
|
|
|
563
564
|
break;
|
|
564
565
|
}
|
|
565
566
|
case "file": {
|
|
566
|
-
|
|
567
|
-
|
|
568
|
-
|
|
569
|
-
|
|
570
|
-
|
|
571
|
-
|
|
572
|
-
|
|
573
|
-
});
|
|
574
|
-
} else if (isProviderReference(part.data)) {
|
|
575
|
-
if (providerOptionsName === "vertex") {
|
|
576
|
-
throw new UnsupportedFunctionalityError({
|
|
577
|
-
functionality: "file parts with provider references"
|
|
567
|
+
switch (part.data.type) {
|
|
568
|
+
case "url": {
|
|
569
|
+
parts.push({
|
|
570
|
+
fileData: {
|
|
571
|
+
mimeType: resolveFullMediaType({ part }),
|
|
572
|
+
fileUri: part.data.url.toString()
|
|
573
|
+
}
|
|
578
574
|
});
|
|
575
|
+
break;
|
|
579
576
|
}
|
|
580
|
-
|
|
581
|
-
|
|
582
|
-
|
|
583
|
-
|
|
584
|
-
|
|
585
|
-
provider: "google"
|
|
586
|
-
})
|
|
587
|
-
}
|
|
588
|
-
});
|
|
589
|
-
} else {
|
|
590
|
-
parts.push({
|
|
591
|
-
inlineData: {
|
|
592
|
-
mimeType: mediaType,
|
|
593
|
-
data: convertToBase64(part.data)
|
|
577
|
+
case "reference": {
|
|
578
|
+
if (providerOptionsName === "vertex") {
|
|
579
|
+
throw new UnsupportedFunctionalityError({
|
|
580
|
+
functionality: "file parts with provider references"
|
|
581
|
+
});
|
|
594
582
|
}
|
|
595
|
-
|
|
583
|
+
parts.push({
|
|
584
|
+
fileData: {
|
|
585
|
+
mimeType: resolveFullMediaType({ part }),
|
|
586
|
+
fileUri: resolveProviderReference({
|
|
587
|
+
reference: part.data.reference,
|
|
588
|
+
provider: "google"
|
|
589
|
+
})
|
|
590
|
+
}
|
|
591
|
+
});
|
|
592
|
+
break;
|
|
593
|
+
}
|
|
594
|
+
case "text": {
|
|
595
|
+
parts.push({
|
|
596
|
+
inlineData: {
|
|
597
|
+
mimeType: isFullMediaType(part.mediaType) ? part.mediaType : "text/plain",
|
|
598
|
+
data: convertToBase64(
|
|
599
|
+
new TextEncoder().encode(part.data.text)
|
|
600
|
+
)
|
|
601
|
+
}
|
|
602
|
+
});
|
|
603
|
+
break;
|
|
604
|
+
}
|
|
605
|
+
case "data": {
|
|
606
|
+
parts.push({
|
|
607
|
+
inlineData: {
|
|
608
|
+
mimeType: resolveFullMediaType({ part }),
|
|
609
|
+
data: convertToBase64(part.data.data)
|
|
610
|
+
}
|
|
611
|
+
});
|
|
612
|
+
break;
|
|
613
|
+
}
|
|
596
614
|
}
|
|
597
615
|
break;
|
|
598
616
|
}
|
|
@@ -624,52 +642,74 @@ function convertToGoogleMessages(prompt, options) {
|
|
|
624
642
|
};
|
|
625
643
|
}
|
|
626
644
|
case "reasoning-file": {
|
|
627
|
-
|
|
628
|
-
|
|
629
|
-
|
|
630
|
-
|
|
645
|
+
switch (part.data.type) {
|
|
646
|
+
case "url": {
|
|
647
|
+
throw new UnsupportedFunctionalityError({
|
|
648
|
+
functionality: "File data URLs in assistant messages are not supported"
|
|
649
|
+
});
|
|
650
|
+
}
|
|
651
|
+
case "data": {
|
|
652
|
+
return {
|
|
653
|
+
inlineData: {
|
|
654
|
+
mimeType: part.mediaType,
|
|
655
|
+
data: convertToBase64(part.data.data)
|
|
656
|
+
},
|
|
657
|
+
thought: true,
|
|
658
|
+
thoughtSignature
|
|
659
|
+
};
|
|
660
|
+
}
|
|
631
661
|
}
|
|
632
|
-
|
|
633
|
-
inlineData: {
|
|
634
|
-
mimeType: part.mediaType,
|
|
635
|
-
data: convertToBase64(part.data)
|
|
636
|
-
},
|
|
637
|
-
thought: true,
|
|
638
|
-
thoughtSignature
|
|
639
|
-
};
|
|
662
|
+
break;
|
|
640
663
|
}
|
|
641
664
|
case "file": {
|
|
642
|
-
|
|
643
|
-
|
|
644
|
-
functionality: "File data URLs in assistant messages are not supported"
|
|
645
|
-
});
|
|
646
|
-
}
|
|
647
|
-
if (isProviderReference(part.data)) {
|
|
648
|
-
if (providerOptionsName === "vertex") {
|
|
665
|
+
switch (part.data.type) {
|
|
666
|
+
case "url": {
|
|
649
667
|
throw new UnsupportedFunctionalityError({
|
|
650
|
-
functionality: "
|
|
668
|
+
functionality: "File data URLs in assistant messages are not supported"
|
|
651
669
|
});
|
|
652
670
|
}
|
|
653
|
-
|
|
654
|
-
|
|
655
|
-
|
|
656
|
-
|
|
657
|
-
|
|
658
|
-
|
|
659
|
-
|
|
660
|
-
|
|
661
|
-
|
|
662
|
-
|
|
663
|
-
|
|
671
|
+
case "reference": {
|
|
672
|
+
if (providerOptionsName === "vertex") {
|
|
673
|
+
throw new UnsupportedFunctionalityError({
|
|
674
|
+
functionality: "file parts with provider references"
|
|
675
|
+
});
|
|
676
|
+
}
|
|
677
|
+
return {
|
|
678
|
+
fileData: {
|
|
679
|
+
mimeType: part.mediaType,
|
|
680
|
+
fileUri: resolveProviderReference({
|
|
681
|
+
reference: part.data.reference,
|
|
682
|
+
provider: "google"
|
|
683
|
+
})
|
|
684
|
+
},
|
|
685
|
+
...(providerOpts == null ? void 0 : providerOpts.thought) === true ? { thought: true } : {},
|
|
686
|
+
thoughtSignature
|
|
687
|
+
};
|
|
688
|
+
}
|
|
689
|
+
case "text": {
|
|
690
|
+
return {
|
|
691
|
+
inlineData: {
|
|
692
|
+
mimeType: isFullMediaType(part.mediaType) ? part.mediaType : "text/plain",
|
|
693
|
+
data: convertToBase64(
|
|
694
|
+
new TextEncoder().encode(part.data.text)
|
|
695
|
+
)
|
|
696
|
+
},
|
|
697
|
+
...(providerOpts == null ? void 0 : providerOpts.thought) === true ? { thought: true } : {},
|
|
698
|
+
thoughtSignature
|
|
699
|
+
};
|
|
700
|
+
}
|
|
701
|
+
case "data": {
|
|
702
|
+
return {
|
|
703
|
+
inlineData: {
|
|
704
|
+
mimeType: part.mediaType,
|
|
705
|
+
data: convertToBase64(part.data.data)
|
|
706
|
+
},
|
|
707
|
+
...(providerOpts == null ? void 0 : providerOpts.thought) === true ? { thought: true } : {},
|
|
708
|
+
thoughtSignature
|
|
709
|
+
};
|
|
710
|
+
}
|
|
664
711
|
}
|
|
665
|
-
|
|
666
|
-
inlineData: {
|
|
667
|
-
mimeType: part.mediaType,
|
|
668
|
-
data: convertToBase64(part.data)
|
|
669
|
-
},
|
|
670
|
-
...(providerOpts == null ? void 0 : providerOpts.thought) === true ? { thought: true } : {},
|
|
671
|
-
thoughtSignature
|
|
672
|
-
};
|
|
712
|
+
break;
|
|
673
713
|
}
|
|
674
714
|
case "tool-call": {
|
|
675
715
|
const serverToolCallId = (providerOpts == null ? void 0 : providerOpts.serverToolCallId) != null ? String(providerOpts.serverToolCallId) : void 0;
|
|
@@ -782,7 +822,10 @@ function getModelPath(modelId) {
|
|
|
782
822
|
}
|
|
783
823
|
|
|
784
824
|
// src/google-options.ts
|
|
785
|
-
import {
|
|
825
|
+
import {
|
|
826
|
+
lazySchema as lazySchema4,
|
|
827
|
+
zodSchema as zodSchema4
|
|
828
|
+
} from "@ai-sdk/provider-utils";
|
|
786
829
|
import { z as z4 } from "zod/v4";
|
|
787
830
|
var googleLanguageModelOptions = lazySchema4(
|
|
788
831
|
() => zodSchema4(
|
|
@@ -1668,7 +1711,7 @@ var GoogleLanguageModel = class _GoogleLanguageModel {
|
|
|
1668
1711
|
const hasThoughtSignature = !!part.thoughtSignature;
|
|
1669
1712
|
content.push({
|
|
1670
1713
|
type: hasThought ? "reasoning-file" : "file",
|
|
1671
|
-
data: part.inlineData.data,
|
|
1714
|
+
data: { type: "data", data: part.inlineData.data },
|
|
1672
1715
|
mediaType: part.inlineData.mimeType,
|
|
1673
1716
|
providerMetadata: hasThoughtSignature ? {
|
|
1674
1717
|
[providerOptionsName]: {
|
|
@@ -1958,7 +2001,7 @@ var GoogleLanguageModel = class _GoogleLanguageModel {
|
|
|
1958
2001
|
controller.enqueue({
|
|
1959
2002
|
type: hasThought ? "reasoning-file" : "file",
|
|
1960
2003
|
mediaType: part.inlineData.mimeType,
|
|
1961
|
-
data: part.inlineData.data,
|
|
2004
|
+
data: { type: "data", data: part.inlineData.data },
|
|
1962
2005
|
providerMetadata: fileMeta
|
|
1963
2006
|
});
|
|
1964
2007
|
} else if ("toolCall" in part && part.toolCall) {
|
|
@@ -2869,13 +2912,16 @@ var GoogleImageModel = class _GoogleImageModel {
|
|
|
2869
2912
|
if (file.type === "url") {
|
|
2870
2913
|
userContent.push({
|
|
2871
2914
|
type: "file",
|
|
2872
|
-
data: new URL(file.url),
|
|
2915
|
+
data: { type: "url", url: new URL(file.url) },
|
|
2873
2916
|
mediaType: "image/*"
|
|
2874
2917
|
});
|
|
2875
2918
|
} else {
|
|
2876
2919
|
userContent.push({
|
|
2877
2920
|
type: "file",
|
|
2878
|
-
data:
|
|
2921
|
+
data: {
|
|
2922
|
+
type: "data",
|
|
2923
|
+
data: typeof file.data === "string" ? file.data : new Uint8Array(file.data)
|
|
2924
|
+
},
|
|
2879
2925
|
mediaType: file.mediaType
|
|
2880
2926
|
});
|
|
2881
2927
|
}
|
|
@@ -2909,8 +2955,8 @@ var GoogleImageModel = class _GoogleImageModel {
|
|
|
2909
2955
|
const currentDate = (_f = (_e = (_d = this.config._internal) == null ? void 0 : _d.currentDate) == null ? void 0 : _e.call(_d)) != null ? _f : /* @__PURE__ */ new Date();
|
|
2910
2956
|
const images = [];
|
|
2911
2957
|
for (const part of result.content) {
|
|
2912
|
-
if (part.type === "file" && part.mediaType.startsWith("image/")) {
|
|
2913
|
-
images.push(convertToBase642(part.data));
|
|
2958
|
+
if (part.type === "file" && part.mediaType.startsWith("image/") && part.data.type === "data") {
|
|
2959
|
+
images.push(convertToBase642(part.data.data));
|
|
2914
2960
|
}
|
|
2915
2961
|
}
|
|
2916
2962
|
return {
|
|
@@ -2959,6 +3005,7 @@ import {
|
|
|
2959
3005
|
} from "@ai-sdk/provider";
|
|
2960
3006
|
import {
|
|
2961
3007
|
combineHeaders as combineHeaders4,
|
|
3008
|
+
convertInlineFileDataToUint8Array,
|
|
2962
3009
|
createJsonResponseHandler as createJsonResponseHandler4,
|
|
2963
3010
|
delay,
|
|
2964
3011
|
lazySchema as lazySchema13,
|
|
@@ -2988,8 +3035,7 @@ var GoogleFiles = class {
|
|
|
2988
3035
|
if (options.filename != null) {
|
|
2989
3036
|
warnings.push({ type: "unsupported", feature: "filename" });
|
|
2990
3037
|
}
|
|
2991
|
-
const
|
|
2992
|
-
const fileBytes = data instanceof Uint8Array ? data : Uint8Array.from(atob(data), (c) => c.charCodeAt(0));
|
|
3038
|
+
const fileBytes = convertInlineFileDataToUint8Array(options.data);
|
|
2993
3039
|
const mediaType = options.mediaType;
|
|
2994
3040
|
const displayName = googleOptions == null ? void 0 : googleOptions.displayName;
|
|
2995
3041
|
const baseOrigin = this.config.baseURL.replace(/\/v1beta$/, "");
|