@ai-sdk/google 4.0.0-beta.1 → 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,62 @@
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
+
3
60
  ## 4.0.0-beta.1
4
61
 
5
62
  ### Patch 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.1" : "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
  }
@@ -900,7 +936,7 @@ function mapGoogleGenerativeAIFinishReason({
900
936
  // src/google-generative-ai-language-model.ts
901
937
  var GoogleGenerativeAILanguageModel = class {
902
938
  constructor(modelId, config) {
903
- this.specificationVersion = "v3";
939
+ this.specificationVersion = "v4";
904
940
  var _a;
905
941
  this.modelId = modelId;
906
942
  this.config = config;
@@ -1012,7 +1048,7 @@ var GoogleGenerativeAILanguageModel = class {
1012
1048
  };
1013
1049
  }
1014
1050
  async doGenerate(options) {
1015
- var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j;
1051
+ var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k;
1016
1052
  const { args, warnings, providerOptionsName } = await this.getArgs(options);
1017
1053
  const mergedHeaders = (0, import_provider_utils6.combineHeaders)(
1018
1054
  await (0, import_provider_utils6.resolve)(this.config.headers),
@@ -1092,13 +1128,16 @@ var GoogleGenerativeAILanguageModel = class {
1092
1128
  } : void 0
1093
1129
  });
1094
1130
  } else if ("inlineData" in part) {
1131
+ const hasThought = part.thought === true;
1132
+ const hasThoughtSignature = !!part.thoughtSignature;
1095
1133
  content.push({
1096
1134
  type: "file",
1097
1135
  data: part.inlineData.data,
1098
1136
  mediaType: part.inlineData.mimeType,
1099
- providerMetadata: part.thoughtSignature ? {
1137
+ providerMetadata: hasThought || hasThoughtSignature ? {
1100
1138
  [providerOptionsName]: {
1101
- thoughtSignature: part.thoughtSignature
1139
+ ...hasThought ? { thought: true } : {},
1140
+ ...hasThoughtSignature ? { thoughtSignature: part.thoughtSignature } : {}
1102
1141
  }
1103
1142
  } : void 0
1104
1143
  });
@@ -1131,7 +1170,8 @@ var GoogleGenerativeAILanguageModel = class {
1131
1170
  groundingMetadata: (_h = candidate.groundingMetadata) != null ? _h : null,
1132
1171
  urlContextMetadata: (_i = candidate.urlContextMetadata) != null ? _i : null,
1133
1172
  safetyRatings: (_j = candidate.safetyRatings) != null ? _j : null,
1134
- usageMetadata: usageMetadata != null ? usageMetadata : null
1173
+ usageMetadata: usageMetadata != null ? usageMetadata : null,
1174
+ finishMessage: (_k = candidate.finishMessage) != null ? _k : null
1135
1175
  }
1136
1176
  },
1137
1177
  request: { body: args },
@@ -1165,6 +1205,8 @@ var GoogleGenerativeAILanguageModel = class {
1165
1205
  };
1166
1206
  let usage = void 0;
1167
1207
  let providerMetadata = void 0;
1208
+ let lastGroundingMetadata = null;
1209
+ let lastUrlContextMetadata = null;
1168
1210
  const generateId3 = this.config.generateId;
1169
1211
  let hasToolCalls = false;
1170
1212
  let currentTextBlockId = null;
@@ -1179,7 +1221,7 @@ var GoogleGenerativeAILanguageModel = class {
1179
1221
  controller.enqueue({ type: "stream-start", warnings });
1180
1222
  },
1181
1223
  transform(chunk, controller) {
1182
- var _a, _b, _c, _d, _e, _f, _g, _h;
1224
+ var _a, _b, _c, _d, _e, _f, _g;
1183
1225
  if (options.includeRawChunks) {
1184
1226
  controller.enqueue({ type: "raw", rawValue: chunk.rawValue });
1185
1227
  }
@@ -1197,6 +1239,12 @@ var GoogleGenerativeAILanguageModel = class {
1197
1239
  return;
1198
1240
  }
1199
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
+ }
1200
1248
  const sources = extractSources({
1201
1249
  groundingMetadata: candidate.groundingMetadata,
1202
1250
  generateId: generateId3
@@ -1311,16 +1359,19 @@ var GoogleGenerativeAILanguageModel = class {
1311
1359
  });
1312
1360
  currentReasoningBlockId = null;
1313
1361
  }
1314
- const thoughtSignatureMetadata = part.thoughtSignature ? {
1362
+ const hasThought = part.thought === true;
1363
+ const hasThoughtSignature = !!part.thoughtSignature;
1364
+ const fileMeta = hasThought || hasThoughtSignature ? {
1315
1365
  [providerOptionsName]: {
1316
- thoughtSignature: part.thoughtSignature
1366
+ ...hasThought ? { thought: true } : {},
1367
+ ...hasThoughtSignature ? { thoughtSignature: part.thoughtSignature } : {}
1317
1368
  }
1318
1369
  } : void 0;
1319
1370
  controller.enqueue({
1320
1371
  type: "file",
1321
1372
  mediaType: part.inlineData.mimeType,
1322
1373
  data: part.inlineData.data,
1323
- providerMetadata: thoughtSignatureMetadata
1374
+ providerMetadata: fileMeta
1324
1375
  });
1325
1376
  }
1326
1377
  }
@@ -1370,14 +1421,13 @@ var GoogleGenerativeAILanguageModel = class {
1370
1421
  providerMetadata = {
1371
1422
  [providerOptionsName]: {
1372
1423
  promptFeedback: (_e = value.promptFeedback) != null ? _e : null,
1373
- groundingMetadata: (_f = candidate.groundingMetadata) != null ? _f : null,
1374
- urlContextMetadata: (_g = candidate.urlContextMetadata) != null ? _g : null,
1375
- 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
1376
1429
  }
1377
1430
  };
1378
- if (usageMetadata != null) {
1379
- providerMetadata[providerOptionsName].usageMetadata = usageMetadata;
1380
- }
1381
1431
  }
1382
1432
  },
1383
1433
  flush(controller) {
@@ -1586,6 +1636,7 @@ var getContentSchema = () => import_v45.z.object({
1586
1636
  mimeType: import_v45.z.string(),
1587
1637
  data: import_v45.z.string()
1588
1638
  }),
1639
+ thought: import_v45.z.boolean().nullish(),
1589
1640
  thoughtSignature: import_v45.z.string().nullish()
1590
1641
  }),
1591
1642
  import_v45.z.object({
@@ -1636,6 +1687,7 @@ var responseSchema = (0, import_provider_utils6.lazySchema)(
1636
1687
  import_v45.z.object({
1637
1688
  content: getContentSchema().nullish().or(import_v45.z.object({}).strict()),
1638
1689
  finishReason: import_v45.z.string().nullish(),
1690
+ finishMessage: import_v45.z.string().nullish(),
1639
1691
  safetyRatings: import_v45.z.array(getSafetyRatingSchema()).nullish(),
1640
1692
  groundingMetadata: getGroundingMetadataSchema().nullish(),
1641
1693
  urlContextMetadata: getUrlContextMetadataSchema().nullish()
@@ -1656,6 +1708,7 @@ var chunkSchema = (0, import_provider_utils6.lazySchema)(
1656
1708
  import_v45.z.object({
1657
1709
  content: getContentSchema().nullish(),
1658
1710
  finishReason: import_v45.z.string().nullish(),
1711
+ finishMessage: import_v45.z.string().nullish(),
1659
1712
  safetyRatings: import_v45.z.array(getSafetyRatingSchema()).nullish(),
1660
1713
  groundingMetadata: getGroundingMetadataSchema().nullish(),
1661
1714
  urlContextMetadata: getUrlContextMetadataSchema().nullish()
@@ -1838,7 +1891,7 @@ var GoogleGenerativeAIImageModel = class {
1838
1891
  this.modelId = modelId;
1839
1892
  this.settings = settings;
1840
1893
  this.config = config;
1841
- this.specificationVersion = "v3";
1894
+ this.specificationVersion = "v4";
1842
1895
  }
1843
1896
  get maxImagesPerCall() {
1844
1897
  if (this.settings.maxImagesPerCall != null) {
@@ -2079,7 +2132,7 @@ var GoogleGenerativeAIVideoModel = class {
2079
2132
  constructor(modelId, config) {
2080
2133
  this.modelId = modelId;
2081
2134
  this.config = config;
2082
- this.specificationVersion = "v3";
2135
+ this.specificationVersion = "v4";
2083
2136
  }
2084
2137
  get provider() {
2085
2138
  return this.config.provider;
@@ -2391,7 +2444,7 @@ function createGoogleGenerativeAI(options = {}) {
2391
2444
  }
2392
2445
  return createChatModel(modelId);
2393
2446
  };
2394
- provider.specificationVersion = "v3";
2447
+ provider.specificationVersion = "v4";
2395
2448
  provider.languageModel = createChatModel;
2396
2449
  provider.chat = createChatModel;
2397
2450
  provider.generativeAI = createChatModel;