@ai-sdk/google 4.0.0-beta.6 → 4.0.0-beta.8

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 CHANGED
@@ -1,5 +1,17 @@
1
1
  # @ai-sdk/google
2
2
 
3
+ ## 4.0.0-beta.8
4
+
5
+ ### Patch Changes
6
+
7
+ - 4dac142: feat(google): add new finishMessage field in providerMetadata
8
+
9
+ ## 4.0.0-beta.7
10
+
11
+ ### Patch Changes
12
+
13
+ - 82288b0: feat(provider/google): add `gemini-embedding-2-preview` and fix multimodal embedding support with `embedMany`
14
+
3
15
  ## 4.0.0-beta.6
4
16
 
5
17
  ### Patch Changes
package/dist/index.d.mts CHANGED
@@ -73,6 +73,7 @@ declare const responseSchema: _ai_sdk_provider_utils.LazySchema<{
73
73
  })[] | null | undefined;
74
74
  } | null | undefined;
75
75
  finishReason?: string | null | undefined;
76
+ finishMessage?: string | null | undefined;
76
77
  safetyRatings?: {
77
78
  category?: string | null | undefined;
78
79
  probability?: string | null | undefined;
@@ -158,14 +159,21 @@ declare const responseSchema: _ai_sdk_provider_utils.LazySchema<{
158
159
  type GroundingMetadataSchema = NonNullable<InferSchema<typeof responseSchema>['candidates'][number]['groundingMetadata']>;
159
160
  type UrlContextMetadataSchema = NonNullable<InferSchema<typeof responseSchema>['candidates'][number]['urlContextMetadata']>;
160
161
  type SafetyRatingSchema = NonNullable<InferSchema<typeof responseSchema>['candidates'][number]['safetyRatings']>[number];
162
+ type PromptFeedbackSchema = NonNullable<InferSchema<typeof responseSchema>['promptFeedback']>;
163
+ type UsageMetadataSchema = NonNullable<InferSchema<typeof responseSchema>['usageMetadata']>;
161
164
 
162
165
  type GoogleGenerativeAIGroundingMetadata = GroundingMetadataSchema;
163
166
  type GoogleGenerativeAIUrlContextMetadata = UrlContextMetadataSchema;
164
167
  type GoogleGenerativeAISafetyRating = SafetyRatingSchema;
168
+ type GoogleGenerativeAIPromptFeedback = PromptFeedbackSchema;
169
+ type GoogleGenerativeAIUsageMetadata = UsageMetadataSchema;
165
170
  interface GoogleGenerativeAIProviderMetadata {
171
+ promptFeedback: GoogleGenerativeAIPromptFeedback | null;
166
172
  groundingMetadata: GoogleGenerativeAIGroundingMetadata | null;
167
173
  urlContextMetadata: GoogleGenerativeAIUrlContextMetadata | null;
168
174
  safetyRatings: GoogleGenerativeAISafetyRating[] | null;
175
+ usageMetadata: GoogleGenerativeAIUsageMetadata | null;
176
+ finishMessage: string | null;
169
177
  }
170
178
 
171
179
  type GoogleGenerativeAIImageModelId = 'imagen-4.0-generate-001' | 'imagen-4.0-ultra-generate-001' | 'imagen-4.0-fast-generate-001' | 'gemini-2.5-flash-image' | 'gemini-3-pro-image-preview' | 'gemini-3.1-flash-image-preview' | (string & {});
@@ -182,18 +190,18 @@ declare const googleImageModelOptionsSchema: _ai_sdk_provider_utils.LazySchema<{
182
190
  }>;
183
191
  type GoogleImageModelOptions = InferSchema<typeof googleImageModelOptionsSchema>;
184
192
 
185
- type GoogleGenerativeAIEmbeddingModelId = 'gemini-embedding-001' | (string & {});
193
+ type GoogleGenerativeAIEmbeddingModelId = 'gemini-embedding-001' | 'gemini-embedding-2-preview' | (string & {});
186
194
  declare const googleEmbeddingModelOptions: _ai_sdk_provider_utils.LazySchema<{
187
195
  outputDimensionality?: number | undefined;
188
196
  taskType?: "SEMANTIC_SIMILARITY" | "CLASSIFICATION" | "CLUSTERING" | "RETRIEVAL_DOCUMENT" | "RETRIEVAL_QUERY" | "QUESTION_ANSWERING" | "FACT_VERIFICATION" | "CODE_RETRIEVAL_QUERY" | undefined;
189
- content?: ({
197
+ content?: (({
190
198
  text: string;
191
199
  } | {
192
200
  inlineData: {
193
201
  mimeType: string;
194
202
  data: string;
195
203
  };
196
- })[] | undefined;
204
+ })[] | null)[] | undefined;
197
205
  }>;
198
206
  type GoogleEmbeddingModelOptions = InferSchema<typeof googleEmbeddingModelOptions>;
199
207
 
package/dist/index.d.ts CHANGED
@@ -73,6 +73,7 @@ declare const responseSchema: _ai_sdk_provider_utils.LazySchema<{
73
73
  })[] | null | undefined;
74
74
  } | null | undefined;
75
75
  finishReason?: string | null | undefined;
76
+ finishMessage?: string | null | undefined;
76
77
  safetyRatings?: {
77
78
  category?: string | null | undefined;
78
79
  probability?: string | null | undefined;
@@ -158,14 +159,21 @@ declare const responseSchema: _ai_sdk_provider_utils.LazySchema<{
158
159
  type GroundingMetadataSchema = NonNullable<InferSchema<typeof responseSchema>['candidates'][number]['groundingMetadata']>;
159
160
  type UrlContextMetadataSchema = NonNullable<InferSchema<typeof responseSchema>['candidates'][number]['urlContextMetadata']>;
160
161
  type SafetyRatingSchema = NonNullable<InferSchema<typeof responseSchema>['candidates'][number]['safetyRatings']>[number];
162
+ type PromptFeedbackSchema = NonNullable<InferSchema<typeof responseSchema>['promptFeedback']>;
163
+ type UsageMetadataSchema = NonNullable<InferSchema<typeof responseSchema>['usageMetadata']>;
161
164
 
162
165
  type GoogleGenerativeAIGroundingMetadata = GroundingMetadataSchema;
163
166
  type GoogleGenerativeAIUrlContextMetadata = UrlContextMetadataSchema;
164
167
  type GoogleGenerativeAISafetyRating = SafetyRatingSchema;
168
+ type GoogleGenerativeAIPromptFeedback = PromptFeedbackSchema;
169
+ type GoogleGenerativeAIUsageMetadata = UsageMetadataSchema;
165
170
  interface GoogleGenerativeAIProviderMetadata {
171
+ promptFeedback: GoogleGenerativeAIPromptFeedback | null;
166
172
  groundingMetadata: GoogleGenerativeAIGroundingMetadata | null;
167
173
  urlContextMetadata: GoogleGenerativeAIUrlContextMetadata | null;
168
174
  safetyRatings: GoogleGenerativeAISafetyRating[] | null;
175
+ usageMetadata: GoogleGenerativeAIUsageMetadata | null;
176
+ finishMessage: string | null;
169
177
  }
170
178
 
171
179
  type GoogleGenerativeAIImageModelId = 'imagen-4.0-generate-001' | 'imagen-4.0-ultra-generate-001' | 'imagen-4.0-fast-generate-001' | 'gemini-2.5-flash-image' | 'gemini-3-pro-image-preview' | 'gemini-3.1-flash-image-preview' | (string & {});
@@ -182,18 +190,18 @@ declare const googleImageModelOptionsSchema: _ai_sdk_provider_utils.LazySchema<{
182
190
  }>;
183
191
  type GoogleImageModelOptions = InferSchema<typeof googleImageModelOptionsSchema>;
184
192
 
185
- type GoogleGenerativeAIEmbeddingModelId = 'gemini-embedding-001' | (string & {});
193
+ type GoogleGenerativeAIEmbeddingModelId = 'gemini-embedding-001' | 'gemini-embedding-2-preview' | (string & {});
186
194
  declare const googleEmbeddingModelOptions: _ai_sdk_provider_utils.LazySchema<{
187
195
  outputDimensionality?: number | undefined;
188
196
  taskType?: "SEMANTIC_SIMILARITY" | "CLASSIFICATION" | "CLUSTERING" | "RETRIEVAL_DOCUMENT" | "RETRIEVAL_QUERY" | "QUESTION_ANSWERING" | "FACT_VERIFICATION" | "CODE_RETRIEVAL_QUERY" | undefined;
189
- content?: ({
197
+ content?: (({
190
198
  text: string;
191
199
  } | {
192
200
  inlineData: {
193
201
  mimeType: string;
194
202
  data: string;
195
203
  };
196
- })[] | undefined;
204
+ })[] | null)[] | undefined;
197
205
  }>;
198
206
  type GoogleEmbeddingModelOptions = InferSchema<typeof googleEmbeddingModelOptions>;
199
207
 
package/dist/index.js CHANGED
@@ -30,7 +30,7 @@ module.exports = __toCommonJS(src_exports);
30
30
  var import_provider_utils16 = require("@ai-sdk/provider-utils");
31
31
 
32
32
  // src/version.ts
33
- var VERSION = true ? "4.0.0-beta.6" : "0.0.0-test";
33
+ var VERSION = true ? "4.0.0-beta.8" : "0.0.0-test";
34
34
 
35
35
  // src/google-generative-ai-embedding-model.ts
36
36
  var import_provider = require("@ai-sdk/provider");
@@ -99,11 +99,15 @@ var googleEmbeddingModelOptions = (0, import_provider_utils2.lazySchema)(
99
99
  "CODE_RETRIEVAL_QUERY"
100
100
  ]).optional(),
101
101
  /**
102
- * Optional. Multimodal content parts for embedding non-text content
103
- * (images, video, PDF, audio). When provided, these parts are merged
104
- * with the text values in the embedding request.
102
+ * Optional. Per-value multimodal content parts for embedding non-text
103
+ * content (images, video, PDF, audio). Each entry corresponds to the
104
+ * embedding value at the same index and its parts are merged with the
105
+ * text value in the request. Use `null` for entries that are text-only.
106
+ *
107
+ * The array length must match the number of values being embedded. In
108
+ * the case of a single embedding, the array length must be 1.
105
109
  */
106
- content: import_v42.z.array(googleEmbeddingContentPartSchema).min(1).optional()
110
+ content: import_v42.z.array(import_v42.z.array(googleEmbeddingContentPartSchema).min(1).nullable()).optional()
107
111
  })
108
112
  )
109
113
  );
@@ -126,7 +130,6 @@ var GoogleGenerativeAIEmbeddingModel = class {
126
130
  abortSignal,
127
131
  providerOptions
128
132
  }) {
129
- var _a;
130
133
  const googleOptions = await (0, import_provider_utils3.parseProviderOptions)({
131
134
  provider: "google",
132
135
  providerOptions,
@@ -144,10 +147,16 @@ var GoogleGenerativeAIEmbeddingModel = class {
144
147
  await (0, import_provider_utils3.resolve)(this.config.headers),
145
148
  headers
146
149
  );
147
- const multimodalContent = (_a = googleOptions == null ? void 0 : googleOptions.content) != null ? _a : [];
150
+ const multimodalContent = googleOptions == null ? void 0 : googleOptions.content;
151
+ if (multimodalContent != null && multimodalContent.length !== values.length) {
152
+ throw new Error(
153
+ `The number of multimodal content entries (${multimodalContent.length}) must match the number of values (${values.length}).`
154
+ );
155
+ }
148
156
  if (values.length === 1) {
157
+ const valueParts = multimodalContent == null ? void 0 : multimodalContent[0];
149
158
  const textPart = values[0] ? [{ text: values[0] }] : [];
150
- const parts = multimodalContent.length > 0 ? [...textPart, ...multimodalContent] : [{ text: values[0] }];
159
+ const parts = valueParts != null ? [...textPart, ...valueParts] : [{ text: values[0] }];
151
160
  const {
152
161
  responseHeaders: responseHeaders2,
153
162
  value: response2,
@@ -185,13 +194,14 @@ var GoogleGenerativeAIEmbeddingModel = class {
185
194
  url: `${this.config.baseURL}/models/${this.modelId}:batchEmbedContents`,
186
195
  headers: mergedHeaders,
187
196
  body: {
188
- requests: values.map((value) => {
197
+ requests: values.map((value, index) => {
198
+ const valueParts = multimodalContent == null ? void 0 : multimodalContent[index];
189
199
  const textPart = value ? [{ text: value }] : [];
190
200
  return {
191
201
  model: `models/${this.modelId}`,
192
202
  content: {
193
203
  role: "user",
194
- parts: multimodalContent.length > 0 ? [...textPart, ...multimodalContent] : [{ text: value }]
204
+ parts: valueParts != null ? [...textPart, ...valueParts] : [{ text: value }]
195
205
  },
196
206
  outputDimensionality: googleOptions == null ? void 0 : googleOptions.outputDimensionality,
197
207
  taskType: googleOptions == null ? void 0 : googleOptions.taskType
@@ -1038,7 +1048,7 @@ var GoogleGenerativeAILanguageModel = class {
1038
1048
  };
1039
1049
  }
1040
1050
  async doGenerate(options) {
1041
- var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j;
1051
+ var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k;
1042
1052
  const { args, warnings, providerOptionsName } = await this.getArgs(options);
1043
1053
  const mergedHeaders = (0, import_provider_utils6.combineHeaders)(
1044
1054
  await (0, import_provider_utils6.resolve)(this.config.headers),
@@ -1160,7 +1170,8 @@ var GoogleGenerativeAILanguageModel = class {
1160
1170
  groundingMetadata: (_h = candidate.groundingMetadata) != null ? _h : null,
1161
1171
  urlContextMetadata: (_i = candidate.urlContextMetadata) != null ? _i : null,
1162
1172
  safetyRatings: (_j = candidate.safetyRatings) != null ? _j : null,
1163
- usageMetadata: usageMetadata != null ? usageMetadata : null
1173
+ usageMetadata: usageMetadata != null ? usageMetadata : null,
1174
+ finishMessage: (_k = candidate.finishMessage) != null ? _k : null
1164
1175
  }
1165
1176
  },
1166
1177
  request: { body: args },
@@ -1210,7 +1221,7 @@ var GoogleGenerativeAILanguageModel = class {
1210
1221
  controller.enqueue({ type: "stream-start", warnings });
1211
1222
  },
1212
1223
  transform(chunk, controller) {
1213
- var _a, _b, _c, _d, _e, _f;
1224
+ var _a, _b, _c, _d, _e, _f, _g;
1214
1225
  if (options.includeRawChunks) {
1215
1226
  controller.enqueue({ type: "raw", rawValue: chunk.rawValue });
1216
1227
  }
@@ -1412,12 +1423,11 @@ var GoogleGenerativeAILanguageModel = class {
1412
1423
  promptFeedback: (_e = value.promptFeedback) != null ? _e : null,
1413
1424
  groundingMetadata: lastGroundingMetadata,
1414
1425
  urlContextMetadata: lastUrlContextMetadata,
1415
- safetyRatings: (_f = candidate.safetyRatings) != null ? _f : null
1426
+ safetyRatings: (_f = candidate.safetyRatings) != null ? _f : null,
1427
+ usageMetadata: usageMetadata != null ? usageMetadata : null,
1428
+ finishMessage: (_g = candidate.finishMessage) != null ? _g : null
1416
1429
  }
1417
1430
  };
1418
- if (usageMetadata != null) {
1419
- providerMetadata[providerOptionsName].usageMetadata = usageMetadata;
1420
- }
1421
1431
  }
1422
1432
  },
1423
1433
  flush(controller) {
@@ -1677,6 +1687,7 @@ var responseSchema = (0, import_provider_utils6.lazySchema)(
1677
1687
  import_v45.z.object({
1678
1688
  content: getContentSchema().nullish().or(import_v45.z.object({}).strict()),
1679
1689
  finishReason: import_v45.z.string().nullish(),
1690
+ finishMessage: import_v45.z.string().nullish(),
1680
1691
  safetyRatings: import_v45.z.array(getSafetyRatingSchema()).nullish(),
1681
1692
  groundingMetadata: getGroundingMetadataSchema().nullish(),
1682
1693
  urlContextMetadata: getUrlContextMetadataSchema().nullish()
@@ -1697,6 +1708,7 @@ var chunkSchema = (0, import_provider_utils6.lazySchema)(
1697
1708
  import_v45.z.object({
1698
1709
  content: getContentSchema().nullish(),
1699
1710
  finishReason: import_v45.z.string().nullish(),
1711
+ finishMessage: import_v45.z.string().nullish(),
1700
1712
  safetyRatings: import_v45.z.array(getSafetyRatingSchema()).nullish(),
1701
1713
  groundingMetadata: getGroundingMetadataSchema().nullish(),
1702
1714
  urlContextMetadata: getUrlContextMetadataSchema().nullish()