@ai-sdk/google 4.0.0-beta.0 → 4.0.0-beta.10

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,68 @@
1
1
  # @ai-sdk/google
2
2
 
3
+ ## 4.0.0-beta.10
4
+
5
+ ### Patch Changes
6
+
7
+ - Updated dependencies [5c2a5a2]
8
+ - @ai-sdk/provider@4.0.0-beta.1
9
+ - @ai-sdk/provider-utils@5.0.0-beta.2
10
+
11
+ ## 4.0.0-beta.9
12
+
13
+ ### Patch Changes
14
+
15
+ - e59176c: chore(google): update v3 specs to v4
16
+
17
+ ## 4.0.0-beta.8
18
+
19
+ ### Patch Changes
20
+
21
+ - 4dac142: feat(google): add new finishMessage field in providerMetadata
22
+
23
+ ## 4.0.0-beta.7
24
+
25
+ ### Patch Changes
26
+
27
+ - 82288b0: feat(provider/google): add `gemini-embedding-2-preview` and fix multimodal embedding support with `embedMany`
28
+
29
+ ## 4.0.0-beta.6
30
+
31
+ ### Patch Changes
32
+
33
+ - add4326: fix(provider/google): correct JSDoc for multimodal embedding content option
34
+
35
+ ## 4.0.0-beta.5
36
+
37
+ ### Patch Changes
38
+
39
+ - ab43029: feat(provider/google): support multimodal content parts in embedding provider options
40
+
41
+ ## 4.0.0-beta.4
42
+
43
+ ### Patch Changes
44
+
45
+ - 2edd14e: fix(provider/google): correctly mark reasoning files as such and fix related multi-turn errors
46
+
47
+ ## 4.0.0-beta.3
48
+
49
+ ### Patch Changes
50
+
51
+ - Updated dependencies [531251e]
52
+ - @ai-sdk/provider-utils@5.0.0-beta.1
53
+
54
+ ## 4.0.0-beta.2
55
+
56
+ ### Patch Changes
57
+
58
+ - c9c4661: fix(provider/google): preserve groundingMetadata and urlContextMetadata when they arrive in a stream chunk before the finishReason chunk
59
+
60
+ ## 4.0.0-beta.1
61
+
62
+ ### Patch Changes
63
+
64
+ - 19b95f9: fix(google): use VALIDATED function calling mode when any tool has strict:true
65
+
3
66
  ## 4.0.0-beta.0
4
67
 
5
68
  ### Major Changes
package/dist/index.d.mts CHANGED
@@ -1,6 +1,6 @@
1
1
  import * as _ai_sdk_provider_utils from '@ai-sdk/provider-utils';
2
2
  import { InferSchema, FetchFunction } from '@ai-sdk/provider-utils';
3
- import { ProviderV3, LanguageModelV3, ImageModelV3, EmbeddingModelV3, Experimental_VideoModelV3 } from '@ai-sdk/provider';
3
+ import { ProviderV4, LanguageModelV4, ImageModelV4, EmbeddingModelV4, Experimental_VideoModelV4 } from '@ai-sdk/provider';
4
4
 
5
5
  declare const googleErrorDataSchema: _ai_sdk_provider_utils.LazySchema<{
6
6
  error: {
@@ -56,6 +56,7 @@ declare const responseSchema: _ai_sdk_provider_utils.LazySchema<{
56
56
  mimeType: string;
57
57
  data: string;
58
58
  };
59
+ thought?: boolean | null | undefined;
59
60
  thoughtSignature?: string | null | undefined;
60
61
  } | {
61
62
  executableCode?: {
@@ -72,6 +73,7 @@ declare const responseSchema: _ai_sdk_provider_utils.LazySchema<{
72
73
  })[] | null | undefined;
73
74
  } | null | undefined;
74
75
  finishReason?: string | null | undefined;
76
+ finishMessage?: string | null | undefined;
75
77
  safetyRatings?: {
76
78
  category?: string | null | undefined;
77
79
  probability?: string | null | undefined;
@@ -157,14 +159,21 @@ declare const responseSchema: _ai_sdk_provider_utils.LazySchema<{
157
159
  type GroundingMetadataSchema = NonNullable<InferSchema<typeof responseSchema>['candidates'][number]['groundingMetadata']>;
158
160
  type UrlContextMetadataSchema = NonNullable<InferSchema<typeof responseSchema>['candidates'][number]['urlContextMetadata']>;
159
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']>;
160
164
 
161
165
  type GoogleGenerativeAIGroundingMetadata = GroundingMetadataSchema;
162
166
  type GoogleGenerativeAIUrlContextMetadata = UrlContextMetadataSchema;
163
167
  type GoogleGenerativeAISafetyRating = SafetyRatingSchema;
168
+ type GoogleGenerativeAIPromptFeedback = PromptFeedbackSchema;
169
+ type GoogleGenerativeAIUsageMetadata = UsageMetadataSchema;
164
170
  interface GoogleGenerativeAIProviderMetadata {
171
+ promptFeedback: GoogleGenerativeAIPromptFeedback | null;
165
172
  groundingMetadata: GoogleGenerativeAIGroundingMetadata | null;
166
173
  urlContextMetadata: GoogleGenerativeAIUrlContextMetadata | null;
167
174
  safetyRatings: GoogleGenerativeAISafetyRating[] | null;
175
+ usageMetadata: GoogleGenerativeAIUsageMetadata | null;
176
+ finishMessage: string | null;
168
177
  }
169
178
 
170
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 & {});
@@ -181,10 +190,18 @@ declare const googleImageModelOptionsSchema: _ai_sdk_provider_utils.LazySchema<{
181
190
  }>;
182
191
  type GoogleImageModelOptions = InferSchema<typeof googleImageModelOptionsSchema>;
183
192
 
184
- type GoogleGenerativeAIEmbeddingModelId = 'gemini-embedding-001' | (string & {});
193
+ type GoogleGenerativeAIEmbeddingModelId = 'gemini-embedding-001' | 'gemini-embedding-2-preview' | (string & {});
185
194
  declare const googleEmbeddingModelOptions: _ai_sdk_provider_utils.LazySchema<{
186
195
  outputDimensionality?: number | undefined;
187
196
  taskType?: "SEMANTIC_SIMILARITY" | "CLASSIFICATION" | "CLUSTERING" | "RETRIEVAL_DOCUMENT" | "RETRIEVAL_QUERY" | "QUESTION_ANSWERING" | "FACT_VERIFICATION" | "CODE_RETRIEVAL_QUERY" | undefined;
197
+ content?: (({
198
+ text: string;
199
+ } | {
200
+ inlineData: {
201
+ mimeType: string;
202
+ data: string;
203
+ };
204
+ })[] | null)[] | undefined;
188
205
  }>;
189
206
  type GoogleEmbeddingModelOptions = InferSchema<typeof googleEmbeddingModelOptions>;
190
207
 
@@ -285,42 +302,42 @@ declare const googleTools: {
285
302
  }>;
286
303
  };
287
304
 
288
- interface GoogleGenerativeAIProvider extends ProviderV3 {
289
- (modelId: GoogleGenerativeAIModelId): LanguageModelV3;
290
- languageModel(modelId: GoogleGenerativeAIModelId): LanguageModelV3;
291
- chat(modelId: GoogleGenerativeAIModelId): LanguageModelV3;
305
+ interface GoogleGenerativeAIProvider extends ProviderV4 {
306
+ (modelId: GoogleGenerativeAIModelId): LanguageModelV4;
307
+ languageModel(modelId: GoogleGenerativeAIModelId): LanguageModelV4;
308
+ chat(modelId: GoogleGenerativeAIModelId): LanguageModelV4;
292
309
  /**
293
310
  * Creates a model for image generation.
294
311
  */
295
- image(modelId: GoogleGenerativeAIImageModelId, settings?: GoogleGenerativeAIImageSettings): ImageModelV3;
312
+ image(modelId: GoogleGenerativeAIImageModelId, settings?: GoogleGenerativeAIImageSettings): ImageModelV4;
296
313
  /**
297
314
  * @deprecated Use `chat()` instead.
298
315
  */
299
- generativeAI(modelId: GoogleGenerativeAIModelId): LanguageModelV3;
316
+ generativeAI(modelId: GoogleGenerativeAIModelId): LanguageModelV4;
300
317
  /**
301
318
  * Creates a model for text embeddings.
302
319
  */
303
- embedding(modelId: GoogleGenerativeAIEmbeddingModelId): EmbeddingModelV3;
320
+ embedding(modelId: GoogleGenerativeAIEmbeddingModelId): EmbeddingModelV4;
304
321
  /**
305
322
  * Creates a model for text embeddings.
306
323
  */
307
- embeddingModel(modelId: GoogleGenerativeAIEmbeddingModelId): EmbeddingModelV3;
324
+ embeddingModel(modelId: GoogleGenerativeAIEmbeddingModelId): EmbeddingModelV4;
308
325
  /**
309
326
  * @deprecated Use `embedding` instead.
310
327
  */
311
- textEmbedding(modelId: GoogleGenerativeAIEmbeddingModelId): EmbeddingModelV3;
328
+ textEmbedding(modelId: GoogleGenerativeAIEmbeddingModelId): EmbeddingModelV4;
312
329
  /**
313
330
  * @deprecated Use `embeddingModel` instead.
314
331
  */
315
- textEmbeddingModel(modelId: GoogleGenerativeAIEmbeddingModelId): EmbeddingModelV3;
332
+ textEmbeddingModel(modelId: GoogleGenerativeAIEmbeddingModelId): EmbeddingModelV4;
316
333
  /**
317
334
  * Creates a model for video generation.
318
335
  */
319
- video(modelId: GoogleGenerativeAIVideoModelId): Experimental_VideoModelV3;
336
+ video(modelId: GoogleGenerativeAIVideoModelId): Experimental_VideoModelV4;
320
337
  /**
321
338
  * Creates a model for video generation.
322
339
  */
323
- videoModel(modelId: GoogleGenerativeAIVideoModelId): Experimental_VideoModelV3;
340
+ videoModel(modelId: GoogleGenerativeAIVideoModelId): Experimental_VideoModelV4;
324
341
  tools: typeof googleTools;
325
342
  }
326
343
  interface GoogleGenerativeAIProviderSettings {
package/dist/index.d.ts CHANGED
@@ -1,6 +1,6 @@
1
1
  import * as _ai_sdk_provider_utils from '@ai-sdk/provider-utils';
2
2
  import { InferSchema, FetchFunction } from '@ai-sdk/provider-utils';
3
- import { ProviderV3, LanguageModelV3, ImageModelV3, EmbeddingModelV3, Experimental_VideoModelV3 } from '@ai-sdk/provider';
3
+ import { ProviderV4, LanguageModelV4, ImageModelV4, EmbeddingModelV4, Experimental_VideoModelV4 } from '@ai-sdk/provider';
4
4
 
5
5
  declare const googleErrorDataSchema: _ai_sdk_provider_utils.LazySchema<{
6
6
  error: {
@@ -56,6 +56,7 @@ declare const responseSchema: _ai_sdk_provider_utils.LazySchema<{
56
56
  mimeType: string;
57
57
  data: string;
58
58
  };
59
+ thought?: boolean | null | undefined;
59
60
  thoughtSignature?: string | null | undefined;
60
61
  } | {
61
62
  executableCode?: {
@@ -72,6 +73,7 @@ declare const responseSchema: _ai_sdk_provider_utils.LazySchema<{
72
73
  })[] | null | undefined;
73
74
  } | null | undefined;
74
75
  finishReason?: string | null | undefined;
76
+ finishMessage?: string | null | undefined;
75
77
  safetyRatings?: {
76
78
  category?: string | null | undefined;
77
79
  probability?: string | null | undefined;
@@ -157,14 +159,21 @@ declare const responseSchema: _ai_sdk_provider_utils.LazySchema<{
157
159
  type GroundingMetadataSchema = NonNullable<InferSchema<typeof responseSchema>['candidates'][number]['groundingMetadata']>;
158
160
  type UrlContextMetadataSchema = NonNullable<InferSchema<typeof responseSchema>['candidates'][number]['urlContextMetadata']>;
159
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']>;
160
164
 
161
165
  type GoogleGenerativeAIGroundingMetadata = GroundingMetadataSchema;
162
166
  type GoogleGenerativeAIUrlContextMetadata = UrlContextMetadataSchema;
163
167
  type GoogleGenerativeAISafetyRating = SafetyRatingSchema;
168
+ type GoogleGenerativeAIPromptFeedback = PromptFeedbackSchema;
169
+ type GoogleGenerativeAIUsageMetadata = UsageMetadataSchema;
164
170
  interface GoogleGenerativeAIProviderMetadata {
171
+ promptFeedback: GoogleGenerativeAIPromptFeedback | null;
165
172
  groundingMetadata: GoogleGenerativeAIGroundingMetadata | null;
166
173
  urlContextMetadata: GoogleGenerativeAIUrlContextMetadata | null;
167
174
  safetyRatings: GoogleGenerativeAISafetyRating[] | null;
175
+ usageMetadata: GoogleGenerativeAIUsageMetadata | null;
176
+ finishMessage: string | null;
168
177
  }
169
178
 
170
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 & {});
@@ -181,10 +190,18 @@ declare const googleImageModelOptionsSchema: _ai_sdk_provider_utils.LazySchema<{
181
190
  }>;
182
191
  type GoogleImageModelOptions = InferSchema<typeof googleImageModelOptionsSchema>;
183
192
 
184
- type GoogleGenerativeAIEmbeddingModelId = 'gemini-embedding-001' | (string & {});
193
+ type GoogleGenerativeAIEmbeddingModelId = 'gemini-embedding-001' | 'gemini-embedding-2-preview' | (string & {});
185
194
  declare const googleEmbeddingModelOptions: _ai_sdk_provider_utils.LazySchema<{
186
195
  outputDimensionality?: number | undefined;
187
196
  taskType?: "SEMANTIC_SIMILARITY" | "CLASSIFICATION" | "CLUSTERING" | "RETRIEVAL_DOCUMENT" | "RETRIEVAL_QUERY" | "QUESTION_ANSWERING" | "FACT_VERIFICATION" | "CODE_RETRIEVAL_QUERY" | undefined;
197
+ content?: (({
198
+ text: string;
199
+ } | {
200
+ inlineData: {
201
+ mimeType: string;
202
+ data: string;
203
+ };
204
+ })[] | null)[] | undefined;
188
205
  }>;
189
206
  type GoogleEmbeddingModelOptions = InferSchema<typeof googleEmbeddingModelOptions>;
190
207
 
@@ -285,42 +302,42 @@ declare const googleTools: {
285
302
  }>;
286
303
  };
287
304
 
288
- interface GoogleGenerativeAIProvider extends ProviderV3 {
289
- (modelId: GoogleGenerativeAIModelId): LanguageModelV3;
290
- languageModel(modelId: GoogleGenerativeAIModelId): LanguageModelV3;
291
- chat(modelId: GoogleGenerativeAIModelId): LanguageModelV3;
305
+ interface GoogleGenerativeAIProvider extends ProviderV4 {
306
+ (modelId: GoogleGenerativeAIModelId): LanguageModelV4;
307
+ languageModel(modelId: GoogleGenerativeAIModelId): LanguageModelV4;
308
+ chat(modelId: GoogleGenerativeAIModelId): LanguageModelV4;
292
309
  /**
293
310
  * Creates a model for image generation.
294
311
  */
295
- image(modelId: GoogleGenerativeAIImageModelId, settings?: GoogleGenerativeAIImageSettings): ImageModelV3;
312
+ image(modelId: GoogleGenerativeAIImageModelId, settings?: GoogleGenerativeAIImageSettings): ImageModelV4;
296
313
  /**
297
314
  * @deprecated Use `chat()` instead.
298
315
  */
299
- generativeAI(modelId: GoogleGenerativeAIModelId): LanguageModelV3;
316
+ generativeAI(modelId: GoogleGenerativeAIModelId): LanguageModelV4;
300
317
  /**
301
318
  * Creates a model for text embeddings.
302
319
  */
303
- embedding(modelId: GoogleGenerativeAIEmbeddingModelId): EmbeddingModelV3;
320
+ embedding(modelId: GoogleGenerativeAIEmbeddingModelId): EmbeddingModelV4;
304
321
  /**
305
322
  * Creates a model for text embeddings.
306
323
  */
307
- embeddingModel(modelId: GoogleGenerativeAIEmbeddingModelId): EmbeddingModelV3;
324
+ embeddingModel(modelId: GoogleGenerativeAIEmbeddingModelId): EmbeddingModelV4;
308
325
  /**
309
326
  * @deprecated Use `embedding` instead.
310
327
  */
311
- textEmbedding(modelId: GoogleGenerativeAIEmbeddingModelId): EmbeddingModelV3;
328
+ textEmbedding(modelId: GoogleGenerativeAIEmbeddingModelId): EmbeddingModelV4;
312
329
  /**
313
330
  * @deprecated Use `embeddingModel` instead.
314
331
  */
315
- textEmbeddingModel(modelId: GoogleGenerativeAIEmbeddingModelId): EmbeddingModelV3;
332
+ textEmbeddingModel(modelId: GoogleGenerativeAIEmbeddingModelId): EmbeddingModelV4;
316
333
  /**
317
334
  * Creates a model for video generation.
318
335
  */
319
- video(modelId: GoogleGenerativeAIVideoModelId): Experimental_VideoModelV3;
336
+ video(modelId: GoogleGenerativeAIVideoModelId): Experimental_VideoModelV4;
320
337
  /**
321
338
  * Creates a model for video generation.
322
339
  */
323
- videoModel(modelId: GoogleGenerativeAIVideoModelId): Experimental_VideoModelV3;
340
+ videoModel(modelId: GoogleGenerativeAIVideoModelId): Experimental_VideoModelV4;
324
341
  tools: typeof googleTools;
325
342
  }
326
343
  interface GoogleGenerativeAIProviderSettings {
package/dist/index.js CHANGED
@@ -18,19 +18,19 @@ var __copyProps = (to, from, except, desc) => {
18
18
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
19
 
20
20
  // src/index.ts
21
- var src_exports = {};
22
- __export(src_exports, {
21
+ var index_exports = {};
22
+ __export(index_exports, {
23
23
  VERSION: () => VERSION,
24
24
  createGoogleGenerativeAI: () => createGoogleGenerativeAI,
25
25
  google: () => google
26
26
  });
27
- module.exports = __toCommonJS(src_exports);
27
+ module.exports = __toCommonJS(index_exports);
28
28
 
29
29
  // src/google-provider.ts
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.0" : "0.0.0-test";
33
+ var VERSION = true ? "4.0.0-beta.10" : "0.0.0-test";
34
34
 
35
35
  // src/google-generative-ai-embedding-model.ts
36
36
  var import_provider = require("@ai-sdk/provider");
@@ -59,6 +59,15 @@ var googleFailedResponseHandler = (0, import_provider_utils.createJsonErrorRespo
59
59
  // src/google-generative-ai-embedding-options.ts
60
60
  var import_provider_utils2 = require("@ai-sdk/provider-utils");
61
61
  var import_v42 = require("zod/v4");
62
+ var googleEmbeddingContentPartSchema = import_v42.z.union([
63
+ import_v42.z.object({ text: import_v42.z.string() }),
64
+ import_v42.z.object({
65
+ inlineData: import_v42.z.object({
66
+ mimeType: import_v42.z.string(),
67
+ data: import_v42.z.string()
68
+ })
69
+ })
70
+ ]);
62
71
  var googleEmbeddingModelOptions = (0, import_provider_utils2.lazySchema)(
63
72
  () => (0, import_provider_utils2.zodSchema)(
64
73
  import_v42.z.object({
@@ -88,7 +97,17 @@ var googleEmbeddingModelOptions = (0, import_provider_utils2.lazySchema)(
88
97
  "QUESTION_ANSWERING",
89
98
  "FACT_VERIFICATION",
90
99
  "CODE_RETRIEVAL_QUERY"
91
- ]).optional()
100
+ ]).optional(),
101
+ /**
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.
109
+ */
110
+ content: import_v42.z.array(import_v42.z.array(googleEmbeddingContentPartSchema).min(1).nullable()).optional()
92
111
  })
93
112
  )
94
113
  );
@@ -96,7 +115,7 @@ var googleEmbeddingModelOptions = (0, import_provider_utils2.lazySchema)(
96
115
  // src/google-generative-ai-embedding-model.ts
97
116
  var GoogleGenerativeAIEmbeddingModel = class {
98
117
  constructor(modelId, config) {
99
- this.specificationVersion = "v3";
118
+ this.specificationVersion = "v4";
100
119
  this.maxEmbeddingsPerCall = 2048;
101
120
  this.supportsParallelCalls = true;
102
121
  this.modelId = modelId;
@@ -128,7 +147,16 @@ var GoogleGenerativeAIEmbeddingModel = class {
128
147
  await (0, import_provider_utils3.resolve)(this.config.headers),
129
148
  headers
130
149
  );
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
+ }
131
156
  if (values.length === 1) {
157
+ const valueParts = multimodalContent == null ? void 0 : multimodalContent[0];
158
+ const textPart = values[0] ? [{ text: values[0] }] : [];
159
+ const parts = valueParts != null ? [...textPart, ...valueParts] : [{ text: values[0] }];
132
160
  const {
133
161
  responseHeaders: responseHeaders2,
134
162
  value: response2,
@@ -139,7 +167,7 @@ var GoogleGenerativeAIEmbeddingModel = class {
139
167
  body: {
140
168
  model: `models/${this.modelId}`,
141
169
  content: {
142
- parts: [{ text: values[0] }]
170
+ parts
143
171
  },
144
172
  outputDimensionality: googleOptions == null ? void 0 : googleOptions.outputDimensionality,
145
173
  taskType: googleOptions == null ? void 0 : googleOptions.taskType
@@ -166,12 +194,19 @@ var GoogleGenerativeAIEmbeddingModel = class {
166
194
  url: `${this.config.baseURL}/models/${this.modelId}:batchEmbedContents`,
167
195
  headers: mergedHeaders,
168
196
  body: {
169
- requests: values.map((value) => ({
170
- model: `models/${this.modelId}`,
171
- content: { role: "user", parts: [{ text: value }] },
172
- outputDimensionality: googleOptions == null ? void 0 : googleOptions.outputDimensionality,
173
- taskType: googleOptions == null ? void 0 : googleOptions.taskType
174
- }))
197
+ requests: values.map((value, index) => {
198
+ const valueParts = multimodalContent == null ? void 0 : multimodalContent[index];
199
+ const textPart = value ? [{ text: value }] : [];
200
+ return {
201
+ model: `models/${this.modelId}`,
202
+ content: {
203
+ role: "user",
204
+ parts: valueParts != null ? [...textPart, ...valueParts] : [{ text: value }]
205
+ },
206
+ outputDimensionality: googleOptions == null ? void 0 : googleOptions.outputDimensionality,
207
+ taskType: googleOptions == null ? void 0 : googleOptions.taskType
208
+ };
209
+ })
175
210
  },
176
211
  failedResponseHandler: googleFailedResponseHandler,
177
212
  successfulResponseHandler: (0, import_provider_utils3.createJsonResponseHandler)(
@@ -447,6 +482,7 @@ function convertToGoogleGenerativeAIMessages(prompt, options) {
447
482
  mimeType: part.mediaType,
448
483
  data: (0, import_provider_utils4.convertToBase64)(part.data)
449
484
  },
485
+ ...(providerOpts == null ? void 0 : providerOpts.thought) === true ? { thought: true } : {},
450
486
  thoughtSignature
451
487
  };
452
488
  }
@@ -795,6 +831,7 @@ function prepareTools({
795
831
  };
796
832
  }
797
833
  const functionDeclarations = [];
834
+ let hasStrictTools = false;
798
835
  for (const tool of tools) {
799
836
  switch (tool.type) {
800
837
  case "function":
@@ -803,6 +840,9 @@ function prepareTools({
803
840
  description: (_a = tool.description) != null ? _a : "",
804
841
  parameters: convertJSONSchemaToOpenAPISchema(tool.inputSchema)
805
842
  });
843
+ if (tool.strict === true) {
844
+ hasStrictTools = true;
845
+ }
806
846
  break;
807
847
  default:
808
848
  toolWarnings.push({
@@ -815,7 +855,7 @@ function prepareTools({
815
855
  if (toolChoice == null) {
816
856
  return {
817
857
  tools: [{ functionDeclarations }],
818
- toolConfig: void 0,
858
+ toolConfig: hasStrictTools ? { functionCallingConfig: { mode: "VALIDATED" } } : void 0,
819
859
  toolWarnings
820
860
  };
821
861
  }
@@ -824,7 +864,11 @@ function prepareTools({
824
864
  case "auto":
825
865
  return {
826
866
  tools: [{ functionDeclarations }],
827
- toolConfig: { functionCallingConfig: { mode: "AUTO" } },
867
+ toolConfig: {
868
+ functionCallingConfig: {
869
+ mode: hasStrictTools ? "VALIDATED" : "AUTO"
870
+ }
871
+ },
828
872
  toolWarnings
829
873
  };
830
874
  case "none":
@@ -836,7 +880,11 @@ function prepareTools({
836
880
  case "required":
837
881
  return {
838
882
  tools: [{ functionDeclarations }],
839
- toolConfig: { functionCallingConfig: { mode: "ANY" } },
883
+ toolConfig: {
884
+ functionCallingConfig: {
885
+ mode: hasStrictTools ? "VALIDATED" : "ANY"
886
+ }
887
+ },
840
888
  toolWarnings
841
889
  };
842
890
  case "tool":
@@ -844,7 +892,7 @@ function prepareTools({
844
892
  tools: [{ functionDeclarations }],
845
893
  toolConfig: {
846
894
  functionCallingConfig: {
847
- mode: "ANY",
895
+ mode: hasStrictTools ? "VALIDATED" : "ANY",
848
896
  allowedFunctionNames: [toolChoice.toolName]
849
897
  }
850
898
  },
@@ -888,7 +936,7 @@ function mapGoogleGenerativeAIFinishReason({
888
936
  // src/google-generative-ai-language-model.ts
889
937
  var GoogleGenerativeAILanguageModel = class {
890
938
  constructor(modelId, config) {
891
- this.specificationVersion = "v3";
939
+ this.specificationVersion = "v4";
892
940
  var _a;
893
941
  this.modelId = modelId;
894
942
  this.config = config;
@@ -1000,7 +1048,7 @@ var GoogleGenerativeAILanguageModel = class {
1000
1048
  };
1001
1049
  }
1002
1050
  async doGenerate(options) {
1003
- var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j;
1051
+ var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k;
1004
1052
  const { args, warnings, providerOptionsName } = await this.getArgs(options);
1005
1053
  const mergedHeaders = (0, import_provider_utils6.combineHeaders)(
1006
1054
  await (0, import_provider_utils6.resolve)(this.config.headers),
@@ -1080,13 +1128,16 @@ var GoogleGenerativeAILanguageModel = class {
1080
1128
  } : void 0
1081
1129
  });
1082
1130
  } else if ("inlineData" in part) {
1131
+ const hasThought = part.thought === true;
1132
+ const hasThoughtSignature = !!part.thoughtSignature;
1083
1133
  content.push({
1084
1134
  type: "file",
1085
1135
  data: part.inlineData.data,
1086
1136
  mediaType: part.inlineData.mimeType,
1087
- providerMetadata: part.thoughtSignature ? {
1137
+ providerMetadata: hasThought || hasThoughtSignature ? {
1088
1138
  [providerOptionsName]: {
1089
- thoughtSignature: part.thoughtSignature
1139
+ ...hasThought ? { thought: true } : {},
1140
+ ...hasThoughtSignature ? { thoughtSignature: part.thoughtSignature } : {}
1090
1141
  }
1091
1142
  } : void 0
1092
1143
  });
@@ -1119,7 +1170,8 @@ var GoogleGenerativeAILanguageModel = class {
1119
1170
  groundingMetadata: (_h = candidate.groundingMetadata) != null ? _h : null,
1120
1171
  urlContextMetadata: (_i = candidate.urlContextMetadata) != null ? _i : null,
1121
1172
  safetyRatings: (_j = candidate.safetyRatings) != null ? _j : null,
1122
- usageMetadata: usageMetadata != null ? usageMetadata : null
1173
+ usageMetadata: usageMetadata != null ? usageMetadata : null,
1174
+ finishMessage: (_k = candidate.finishMessage) != null ? _k : null
1123
1175
  }
1124
1176
  },
1125
1177
  request: { body: args },
@@ -1153,6 +1205,8 @@ var GoogleGenerativeAILanguageModel = class {
1153
1205
  };
1154
1206
  let usage = void 0;
1155
1207
  let providerMetadata = void 0;
1208
+ let lastGroundingMetadata = null;
1209
+ let lastUrlContextMetadata = null;
1156
1210
  const generateId3 = this.config.generateId;
1157
1211
  let hasToolCalls = false;
1158
1212
  let currentTextBlockId = null;
@@ -1167,7 +1221,7 @@ var GoogleGenerativeAILanguageModel = class {
1167
1221
  controller.enqueue({ type: "stream-start", warnings });
1168
1222
  },
1169
1223
  transform(chunk, controller) {
1170
- var _a, _b, _c, _d, _e, _f, _g, _h;
1224
+ var _a, _b, _c, _d, _e, _f, _g;
1171
1225
  if (options.includeRawChunks) {
1172
1226
  controller.enqueue({ type: "raw", rawValue: chunk.rawValue });
1173
1227
  }
@@ -1185,6 +1239,12 @@ var GoogleGenerativeAILanguageModel = class {
1185
1239
  return;
1186
1240
  }
1187
1241
  const content = candidate.content;
1242
+ if (candidate.groundingMetadata != null) {
1243
+ lastGroundingMetadata = candidate.groundingMetadata;
1244
+ }
1245
+ if (candidate.urlContextMetadata != null) {
1246
+ lastUrlContextMetadata = candidate.urlContextMetadata;
1247
+ }
1188
1248
  const sources = extractSources({
1189
1249
  groundingMetadata: candidate.groundingMetadata,
1190
1250
  generateId: generateId3
@@ -1299,16 +1359,19 @@ var GoogleGenerativeAILanguageModel = class {
1299
1359
  });
1300
1360
  currentReasoningBlockId = null;
1301
1361
  }
1302
- const thoughtSignatureMetadata = part.thoughtSignature ? {
1362
+ const hasThought = part.thought === true;
1363
+ const hasThoughtSignature = !!part.thoughtSignature;
1364
+ const fileMeta = hasThought || hasThoughtSignature ? {
1303
1365
  [providerOptionsName]: {
1304
- thoughtSignature: part.thoughtSignature
1366
+ ...hasThought ? { thought: true } : {},
1367
+ ...hasThoughtSignature ? { thoughtSignature: part.thoughtSignature } : {}
1305
1368
  }
1306
1369
  } : void 0;
1307
1370
  controller.enqueue({
1308
1371
  type: "file",
1309
1372
  mediaType: part.inlineData.mimeType,
1310
1373
  data: part.inlineData.data,
1311
- providerMetadata: thoughtSignatureMetadata
1374
+ providerMetadata: fileMeta
1312
1375
  });
1313
1376
  }
1314
1377
  }
@@ -1358,14 +1421,13 @@ var GoogleGenerativeAILanguageModel = class {
1358
1421
  providerMetadata = {
1359
1422
  [providerOptionsName]: {
1360
1423
  promptFeedback: (_e = value.promptFeedback) != null ? _e : null,
1361
- groundingMetadata: (_f = candidate.groundingMetadata) != null ? _f : null,
1362
- urlContextMetadata: (_g = candidate.urlContextMetadata) != null ? _g : null,
1363
- safetyRatings: (_h = candidate.safetyRatings) != null ? _h : null
1424
+ groundingMetadata: lastGroundingMetadata,
1425
+ urlContextMetadata: lastUrlContextMetadata,
1426
+ safetyRatings: (_f = candidate.safetyRatings) != null ? _f : null,
1427
+ usageMetadata: usageMetadata != null ? usageMetadata : null,
1428
+ finishMessage: (_g = candidate.finishMessage) != null ? _g : null
1364
1429
  }
1365
1430
  };
1366
- if (usageMetadata != null) {
1367
- providerMetadata[providerOptionsName].usageMetadata = usageMetadata;
1368
- }
1369
1431
  }
1370
1432
  },
1371
1433
  flush(controller) {
@@ -1574,6 +1636,7 @@ var getContentSchema = () => import_v45.z.object({
1574
1636
  mimeType: import_v45.z.string(),
1575
1637
  data: import_v45.z.string()
1576
1638
  }),
1639
+ thought: import_v45.z.boolean().nullish(),
1577
1640
  thoughtSignature: import_v45.z.string().nullish()
1578
1641
  }),
1579
1642
  import_v45.z.object({
@@ -1624,6 +1687,7 @@ var responseSchema = (0, import_provider_utils6.lazySchema)(
1624
1687
  import_v45.z.object({
1625
1688
  content: getContentSchema().nullish().or(import_v45.z.object({}).strict()),
1626
1689
  finishReason: import_v45.z.string().nullish(),
1690
+ finishMessage: import_v45.z.string().nullish(),
1627
1691
  safetyRatings: import_v45.z.array(getSafetyRatingSchema()).nullish(),
1628
1692
  groundingMetadata: getGroundingMetadataSchema().nullish(),
1629
1693
  urlContextMetadata: getUrlContextMetadataSchema().nullish()
@@ -1644,6 +1708,7 @@ var chunkSchema = (0, import_provider_utils6.lazySchema)(
1644
1708
  import_v45.z.object({
1645
1709
  content: getContentSchema().nullish(),
1646
1710
  finishReason: import_v45.z.string().nullish(),
1711
+ finishMessage: import_v45.z.string().nullish(),
1647
1712
  safetyRatings: import_v45.z.array(getSafetyRatingSchema()).nullish(),
1648
1713
  groundingMetadata: getGroundingMetadataSchema().nullish(),
1649
1714
  urlContextMetadata: getUrlContextMetadataSchema().nullish()
@@ -1826,7 +1891,7 @@ var GoogleGenerativeAIImageModel = class {
1826
1891
  this.modelId = modelId;
1827
1892
  this.settings = settings;
1828
1893
  this.config = config;
1829
- this.specificationVersion = "v3";
1894
+ this.specificationVersion = "v4";
1830
1895
  }
1831
1896
  get maxImagesPerCall() {
1832
1897
  if (this.settings.maxImagesPerCall != null) {
@@ -2067,7 +2132,7 @@ var GoogleGenerativeAIVideoModel = class {
2067
2132
  constructor(modelId, config) {
2068
2133
  this.modelId = modelId;
2069
2134
  this.config = config;
2070
- this.specificationVersion = "v3";
2135
+ this.specificationVersion = "v4";
2071
2136
  }
2072
2137
  get provider() {
2073
2138
  return this.config.provider;
@@ -2379,7 +2444,7 @@ function createGoogleGenerativeAI(options = {}) {
2379
2444
  }
2380
2445
  return createChatModel(modelId);
2381
2446
  };
2382
- provider.specificationVersion = "v3";
2447
+ provider.specificationVersion = "v4";
2383
2448
  provider.languageModel = createChatModel;
2384
2449
  provider.chat = createChatModel;
2385
2450
  provider.generativeAI = createChatModel;