@ai-sdk/google 3.0.126 → 3.0.127

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ai-sdk/google",
3
- "version": "3.0.126",
3
+ "version": "3.0.127",
4
4
  "license": "Apache-2.0",
5
5
  "sideEffects": false,
6
6
  "main": "./dist/index.js",
@@ -37,7 +37,7 @@
37
37
  },
38
38
  "dependencies": {
39
39
  "@ai-sdk/provider": "3.0.17",
40
- "@ai-sdk/provider-utils": "4.0.53"
40
+ "@ai-sdk/provider-utils": "4.0.54"
41
41
  },
42
42
  "devDependencies": {
43
43
  "@types/node": "20.17.24",
@@ -5,6 +5,8 @@ import {
5
5
  import {
6
6
  combineHeaders,
7
7
  createJsonResponseHandler,
8
+ type EmbeddingModelProviderOptionsTransformer,
9
+ EXPERIMENTAL_EMBEDDING_MODEL_PROVIDER_OPTIONS_TRANSFORMER,
8
10
  lazySchema,
9
11
  parseProviderOptions,
10
12
  postJsonToApi,
@@ -31,6 +33,28 @@ export class GoogleGenerativeAIEmbeddingModel implements EmbeddingModelV3 {
31
33
  readonly modelId: GoogleGenerativeAIEmbeddingModelId;
32
34
  readonly maxEmbeddingsPerCall = 100;
33
35
  readonly supportsParallelCalls = true;
36
+ readonly [EXPERIMENTAL_EMBEDDING_MODEL_PROVIDER_OPTIONS_TRANSFORMER]: EmbeddingModelProviderOptionsTransformer =
37
+ ({ providerOptions, values, startIndex, endIndex }) => {
38
+ const multimodalContent = providerOptions?.google?.content;
39
+
40
+ // Leave schema validation to doEmbed, after middleware transforms options.
41
+ if (!Array.isArray(multimodalContent)) {
42
+ return providerOptions;
43
+ }
44
+
45
+ validateMultimodalContentLength({
46
+ multimodalContent,
47
+ values,
48
+ });
49
+
50
+ return {
51
+ ...providerOptions,
52
+ google: {
53
+ ...providerOptions?.google,
54
+ content: multimodalContent.slice(startIndex, endIndex),
55
+ },
56
+ };
57
+ };
34
58
 
35
59
  private readonly config: GoogleGenerativeAIEmbeddingConfig;
36
60
 
@@ -76,14 +100,7 @@ export class GoogleGenerativeAIEmbeddingModel implements EmbeddingModelV3 {
76
100
 
77
101
  const multimodalContent = googleOptions?.content;
78
102
 
79
- if (
80
- multimodalContent != null &&
81
- multimodalContent.length !== values.length
82
- ) {
83
- throw new Error(
84
- `The number of multimodal content entries (${multimodalContent.length}) must match the number of values (${values.length}).`,
85
- );
86
- }
103
+ validateMultimodalContentLength({ multimodalContent, values });
87
104
 
88
105
  // For single embeddings, use the single endpoint
89
106
  if (values.length === 1) {
@@ -186,3 +203,17 @@ const googleGenerativeAISingleEmbeddingResponseSchema = lazySchema(() =>
186
203
  }),
187
204
  ),
188
205
  );
206
+
207
+ function validateMultimodalContentLength({
208
+ multimodalContent,
209
+ values,
210
+ }: {
211
+ multimodalContent: Array<unknown> | undefined;
212
+ values: Array<string>;
213
+ }) {
214
+ if (multimodalContent != null && multimodalContent.length !== values.length) {
215
+ throw new Error(
216
+ `The number of multimodal content entries (${multimodalContent.length}) must match the number of values (${values.length}).`,
217
+ );
218
+ }
219
+ }