@ai-sdk/google 3.0.49 → 3.0.51

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.mjs CHANGED
@@ -7,7 +7,7 @@ import {
7
7
  } from "@ai-sdk/provider-utils";
8
8
 
9
9
  // src/version.ts
10
- var VERSION = true ? "3.0.49" : "0.0.0-test";
10
+ var VERSION = true ? "3.0.51" : "0.0.0-test";
11
11
 
12
12
  // src/google-generative-ai-embedding-model.ts
13
13
  import {
@@ -93,11 +93,15 @@ var googleEmbeddingModelOptions = lazySchema2(
93
93
  "CODE_RETRIEVAL_QUERY"
94
94
  ]).optional(),
95
95
  /**
96
- * Optional. Multimodal content parts for embedding non-text content
97
- * (images, video, PDF, audio). When provided, these parts are merged
98
- * with the text values in the embedding request.
96
+ * Optional. Per-value multimodal content parts for embedding non-text
97
+ * content (images, video, PDF, audio). Each entry corresponds to the
98
+ * embedding value at the same index and its parts are merged with the
99
+ * text value in the request. Use `null` for entries that are text-only.
100
+ *
101
+ * The array length must match the number of values being embedded. In
102
+ * the case of a single embedding, the array length must be 1.
99
103
  */
100
- content: z2.array(googleEmbeddingContentPartSchema).min(1).optional()
104
+ content: z2.array(z2.array(googleEmbeddingContentPartSchema).min(1).nullable()).optional()
101
105
  })
102
106
  )
103
107
  );
@@ -120,7 +124,6 @@ var GoogleGenerativeAIEmbeddingModel = class {
120
124
  abortSignal,
121
125
  providerOptions
122
126
  }) {
123
- var _a;
124
127
  const googleOptions = await parseProviderOptions({
125
128
  provider: "google",
126
129
  providerOptions,
@@ -138,10 +141,16 @@ var GoogleGenerativeAIEmbeddingModel = class {
138
141
  await resolve(this.config.headers),
139
142
  headers
140
143
  );
141
- const multimodalContent = (_a = googleOptions == null ? void 0 : googleOptions.content) != null ? _a : [];
144
+ const multimodalContent = googleOptions == null ? void 0 : googleOptions.content;
145
+ if (multimodalContent != null && multimodalContent.length !== values.length) {
146
+ throw new Error(
147
+ `The number of multimodal content entries (${multimodalContent.length}) must match the number of values (${values.length}).`
148
+ );
149
+ }
142
150
  if (values.length === 1) {
151
+ const valueParts = multimodalContent == null ? void 0 : multimodalContent[0];
143
152
  const textPart = values[0] ? [{ text: values[0] }] : [];
144
- const parts = multimodalContent.length > 0 ? [...textPart, ...multimodalContent] : [{ text: values[0] }];
153
+ const parts = valueParts != null ? [...textPart, ...valueParts] : [{ text: values[0] }];
145
154
  const {
146
155
  responseHeaders: responseHeaders2,
147
156
  value: response2,
@@ -179,13 +188,14 @@ var GoogleGenerativeAIEmbeddingModel = class {
179
188
  url: `${this.config.baseURL}/models/${this.modelId}:batchEmbedContents`,
180
189
  headers: mergedHeaders,
181
190
  body: {
182
- requests: values.map((value) => {
191
+ requests: values.map((value, index) => {
192
+ const valueParts = multimodalContent == null ? void 0 : multimodalContent[index];
183
193
  const textPart = value ? [{ text: value }] : [];
184
194
  return {
185
195
  model: `models/${this.modelId}`,
186
196
  content: {
187
197
  role: "user",
188
- parts: multimodalContent.length > 0 ? [...textPart, ...multimodalContent] : [{ text: value }]
198
+ parts: valueParts != null ? [...textPart, ...valueParts] : [{ text: value }]
189
199
  },
190
200
  outputDimensionality: googleOptions == null ? void 0 : googleOptions.outputDimensionality,
191
201
  taskType: googleOptions == null ? void 0 : googleOptions.taskType
@@ -1046,7 +1056,7 @@ var GoogleGenerativeAILanguageModel = class {
1046
1056
  };
1047
1057
  }
1048
1058
  async doGenerate(options) {
1049
- var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j;
1059
+ var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k;
1050
1060
  const { args, warnings, providerOptionsName } = await this.getArgs(options);
1051
1061
  const mergedHeaders = combineHeaders2(
1052
1062
  await resolve2(this.config.headers),
@@ -1168,7 +1178,8 @@ var GoogleGenerativeAILanguageModel = class {
1168
1178
  groundingMetadata: (_h = candidate.groundingMetadata) != null ? _h : null,
1169
1179
  urlContextMetadata: (_i = candidate.urlContextMetadata) != null ? _i : null,
1170
1180
  safetyRatings: (_j = candidate.safetyRatings) != null ? _j : null,
1171
- usageMetadata: usageMetadata != null ? usageMetadata : null
1181
+ usageMetadata: usageMetadata != null ? usageMetadata : null,
1182
+ finishMessage: (_k = candidate.finishMessage) != null ? _k : null
1172
1183
  }
1173
1184
  },
1174
1185
  request: { body: args },
@@ -1218,7 +1229,7 @@ var GoogleGenerativeAILanguageModel = class {
1218
1229
  controller.enqueue({ type: "stream-start", warnings });
1219
1230
  },
1220
1231
  transform(chunk, controller) {
1221
- var _a, _b, _c, _d, _e, _f;
1232
+ var _a, _b, _c, _d, _e, _f, _g;
1222
1233
  if (options.includeRawChunks) {
1223
1234
  controller.enqueue({ type: "raw", rawValue: chunk.rawValue });
1224
1235
  }
@@ -1420,12 +1431,11 @@ var GoogleGenerativeAILanguageModel = class {
1420
1431
  promptFeedback: (_e = value.promptFeedback) != null ? _e : null,
1421
1432
  groundingMetadata: lastGroundingMetadata,
1422
1433
  urlContextMetadata: lastUrlContextMetadata,
1423
- safetyRatings: (_f = candidate.safetyRatings) != null ? _f : null
1434
+ safetyRatings: (_f = candidate.safetyRatings) != null ? _f : null,
1435
+ usageMetadata: usageMetadata != null ? usageMetadata : null,
1436
+ finishMessage: (_g = candidate.finishMessage) != null ? _g : null
1424
1437
  }
1425
1438
  };
1426
- if (usageMetadata != null) {
1427
- providerMetadata[providerOptionsName].usageMetadata = usageMetadata;
1428
- }
1429
1439
  }
1430
1440
  },
1431
1441
  flush(controller) {
@@ -1685,6 +1695,7 @@ var responseSchema = lazySchema5(
1685
1695
  z5.object({
1686
1696
  content: getContentSchema().nullish().or(z5.object({}).strict()),
1687
1697
  finishReason: z5.string().nullish(),
1698
+ finishMessage: z5.string().nullish(),
1688
1699
  safetyRatings: z5.array(getSafetyRatingSchema()).nullish(),
1689
1700
  groundingMetadata: getGroundingMetadataSchema().nullish(),
1690
1701
  urlContextMetadata: getUrlContextMetadataSchema().nullish()
@@ -1705,6 +1716,7 @@ var chunkSchema = lazySchema5(
1705
1716
  z5.object({
1706
1717
  content: getContentSchema().nullish(),
1707
1718
  finishReason: z5.string().nullish(),
1719
+ finishMessage: z5.string().nullish(),
1708
1720
  safetyRatings: z5.array(getSafetyRatingSchema()).nullish(),
1709
1721
  groundingMetadata: getGroundingMetadataSchema().nullish(),
1710
1722
  urlContextMetadata: getUrlContextMetadataSchema().nullish()