@ai-sdk/google 4.0.0-beta.7 → 4.0.0-beta.82

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.
Files changed (71) hide show
  1. package/CHANGELOG.md +614 -5
  2. package/README.md +6 -4
  3. package/dist/index.d.ts +301 -50
  4. package/dist/index.js +5410 -639
  5. package/dist/index.js.map +1 -1
  6. package/dist/internal/index.d.ts +100 -26
  7. package/dist/internal/index.js +1653 -451
  8. package/dist/internal/index.js.map +1 -1
  9. package/docs/{15-google-generative-ai.mdx → 15-google.mdx} +784 -69
  10. package/package.json +16 -17
  11. package/src/{convert-google-generative-ai-usage.ts → convert-google-usage.ts} +13 -5
  12. package/src/convert-json-schema-to-openapi-schema.ts +1 -1
  13. package/src/convert-to-google-messages.ts +647 -0
  14. package/src/{google-generative-ai-embedding-options.ts → google-embedding-model-options.ts} +9 -2
  15. package/src/{google-generative-ai-embedding-model.ts → google-embedding-model.ts} +31 -18
  16. package/src/google-error.ts +1 -1
  17. package/src/google-files.ts +225 -0
  18. package/src/google-image-model-options.ts +35 -0
  19. package/src/{google-generative-ai-image-model.ts → google-image-model.ts} +116 -65
  20. package/src/{google-generative-ai-image-settings.ts → google-image-settings.ts} +2 -2
  21. package/src/google-json-accumulator.ts +371 -0
  22. package/src/{google-generative-ai-options.ts → google-language-model-options.ts} +50 -5
  23. package/src/{google-generative-ai-language-model.ts → google-language-model.ts} +701 -219
  24. package/src/google-prepare-tools.ts +72 -12
  25. package/src/google-prompt.ts +86 -0
  26. package/src/google-provider.ts +157 -53
  27. package/src/google-speech-api.ts +36 -0
  28. package/src/google-speech-model-options.ts +48 -0
  29. package/src/google-speech-model.ts +311 -0
  30. package/src/google-video-model-options.ts +43 -0
  31. package/src/{google-generative-ai-video-model.ts → google-video-model.ts} +25 -60
  32. package/src/{google-generative-ai-video-settings.ts → google-video-settings.ts} +2 -1
  33. package/src/index.ts +40 -9
  34. package/src/interactions/build-google-interactions-stream-transform.ts +818 -0
  35. package/src/interactions/cancel-google-interaction.ts +60 -0
  36. package/src/interactions/convert-google-interactions-usage.ts +47 -0
  37. package/src/interactions/convert-to-google-interactions-input.ts +557 -0
  38. package/src/interactions/extract-google-interactions-sources.ts +252 -0
  39. package/src/interactions/google-interactions-agent.ts +15 -0
  40. package/src/interactions/google-interactions-api.ts +530 -0
  41. package/src/interactions/google-interactions-language-model-options.ts +262 -0
  42. package/src/interactions/google-interactions-language-model.ts +776 -0
  43. package/src/interactions/google-interactions-prompt.ts +582 -0
  44. package/src/interactions/google-interactions-provider-metadata.ts +23 -0
  45. package/src/interactions/map-google-interactions-finish-reason.ts +31 -0
  46. package/src/interactions/parse-google-interactions-outputs.ts +252 -0
  47. package/src/interactions/poll-google-interactions.ts +129 -0
  48. package/src/interactions/prepare-google-interactions-tools.ts +245 -0
  49. package/src/interactions/stream-google-interactions.ts +242 -0
  50. package/src/interactions/synthesize-google-interactions-agent-stream.ts +185 -0
  51. package/src/internal/index.ts +3 -2
  52. package/src/{map-google-generative-ai-finish-reason.ts → map-google-finish-reason.ts} +3 -3
  53. package/src/realtime/google-realtime-event-mapper.ts +383 -0
  54. package/src/realtime/google-realtime-model-options.ts +3 -0
  55. package/src/realtime/google-realtime-model.ts +160 -0
  56. package/src/realtime/index.ts +2 -0
  57. package/src/tool/code-execution.ts +2 -2
  58. package/src/tool/enterprise-web-search.ts +9 -3
  59. package/src/tool/file-search.ts +5 -7
  60. package/src/tool/google-maps.ts +3 -2
  61. package/src/tool/google-search.ts +11 -12
  62. package/src/tool/url-context.ts +4 -2
  63. package/src/tool/vertex-rag-store.ts +9 -6
  64. package/dist/index.d.mts +0 -376
  65. package/dist/index.mjs +0 -2517
  66. package/dist/index.mjs.map +0 -1
  67. package/dist/internal/index.d.mts +0 -284
  68. package/dist/internal/index.mjs +0 -1706
  69. package/dist/internal/index.mjs.map +0 -1
  70. package/src/convert-to-google-generative-ai-messages.ts +0 -239
  71. package/src/google-generative-ai-prompt.ts +0 -38
@@ -1,32 +1,41 @@
1
1
  import * as _ai_sdk_provider_utils from '@ai-sdk/provider-utils';
2
- import { Resolvable, FetchFunction, InferSchema } from '@ai-sdk/provider-utils';
3
- import { LanguageModelV3, LanguageModelV3CallOptions, LanguageModelV3GenerateResult, LanguageModelV3StreamResult } from '@ai-sdk/provider';
2
+ import { WORKFLOW_SERIALIZE, WORKFLOW_DESERIALIZE, Resolvable, FetchFunction, InferSchema } from '@ai-sdk/provider-utils';
3
+ import * as _ai_sdk_provider from '@ai-sdk/provider';
4
+ import { LanguageModelV4, JSONObject, LanguageModelV4CallOptions, LanguageModelV4GenerateResult, LanguageModelV4StreamResult, SpeechModelV4 } from '@ai-sdk/provider';
4
5
  import { z } from 'zod/v4';
5
6
 
6
- type GoogleGenerativeAIModelId = 'gemini-2.0-flash' | 'gemini-2.0-flash-001' | 'gemini-2.0-flash-lite' | 'gemini-2.0-flash-exp-image-generation' | 'gemini-2.0-flash-lite-001' | 'gemini-2.5-pro' | 'gemini-2.5-flash' | 'gemini-2.5-flash-image' | 'gemini-2.5-flash-lite' | 'gemini-2.5-flash-lite-preview-09-2025' | 'gemini-2.5-flash-preview-tts' | 'gemini-2.5-pro-preview-tts' | 'gemini-2.5-flash-native-audio-latest' | 'gemini-2.5-flash-native-audio-preview-09-2025' | 'gemini-2.5-flash-native-audio-preview-12-2025' | 'gemini-2.5-computer-use-preview-10-2025' | 'gemini-3-pro-preview' | 'gemini-3-pro-image-preview' | 'gemini-3-flash-preview' | 'gemini-3.1-pro-preview' | 'gemini-3.1-pro-preview-customtools' | 'gemini-3.1-flash-image-preview' | 'gemini-3.1-flash-lite-preview' | 'gemini-pro-latest' | 'gemini-flash-latest' | 'gemini-flash-lite-latest' | 'deep-research-pro-preview-12-2025' | 'nano-banana-pro-preview' | 'aqa' | 'gemini-robotics-er-1.5-preview' | 'gemma-3-1b-it' | 'gemma-3-4b-it' | 'gemma-3n-e4b-it' | 'gemma-3n-e2b-it' | 'gemma-3-12b-it' | 'gemma-3-27b-it' | (string & {});
7
+ type GoogleModelId = 'gemini-2.0-flash' | 'gemini-2.0-flash-001' | 'gemini-2.0-flash-lite' | 'gemini-2.0-flash-lite-001' | 'gemini-2.5-pro' | 'gemini-2.5-flash' | 'gemini-2.5-flash-image' | 'gemini-2.5-flash-lite' | 'gemini-2.5-flash-preview-tts' | 'gemini-2.5-pro-preview-tts' | 'gemini-2.5-flash-native-audio-latest' | 'gemini-2.5-flash-native-audio-preview-09-2025' | 'gemini-2.5-flash-native-audio-preview-12-2025' | 'gemini-2.5-computer-use-preview-10-2025' | 'gemini-3-pro-preview' | 'gemini-3-pro-image-preview' | 'gemini-3-flash-preview' | 'gemini-3.1-pro-preview' | 'gemini-3.1-pro-preview-customtools' | 'gemini-3.1-flash-image-preview' | 'gemini-3.1-flash-lite-preview' | 'gemini-3.1-flash-tts-preview' | 'gemini-3.5-flash' | 'gemini-pro-latest' | 'gemini-flash-latest' | 'gemini-flash-lite-latest' | 'deep-research-pro-preview-12-2025' | 'deep-research-max-preview-04-2026' | 'deep-research-preview-04-2026' | 'nano-banana-pro-preview' | 'aqa' | 'gemini-robotics-er-1.5-preview' | 'gemma-3-1b-it' | 'gemma-3-4b-it' | 'gemma-3n-e4b-it' | 'gemma-3n-e2b-it' | 'gemma-3-12b-it' | 'gemma-3-27b-it' | (string & {});
7
8
 
8
- type GoogleGenerativeAIConfig = {
9
+ type GoogleConfig = {
9
10
  provider: string;
10
11
  baseURL: string;
11
- headers: Resolvable<Record<string, string | undefined>>;
12
+ headers?: Resolvable<Record<string, string | undefined>>;
12
13
  fetch?: FetchFunction;
13
14
  generateId: () => string;
14
15
  /**
15
16
  * The supported URLs for the model.
16
17
  */
17
- supportedUrls?: () => LanguageModelV3['supportedUrls'];
18
+ supportedUrls?: () => LanguageModelV4['supportedUrls'];
18
19
  };
19
- declare class GoogleGenerativeAILanguageModel implements LanguageModelV3 {
20
- readonly specificationVersion = "v3";
21
- readonly modelId: GoogleGenerativeAIModelId;
20
+ declare class GoogleLanguageModel implements LanguageModelV4 {
21
+ readonly specificationVersion = "v4";
22
+ readonly modelId: GoogleModelId;
22
23
  private readonly config;
23
24
  private readonly generateId;
24
- constructor(modelId: GoogleGenerativeAIModelId, config: GoogleGenerativeAIConfig);
25
+ static [WORKFLOW_SERIALIZE](model: GoogleLanguageModel): {
26
+ modelId: string;
27
+ config: JSONObject;
28
+ };
29
+ static [WORKFLOW_DESERIALIZE](options: {
30
+ modelId: string;
31
+ config: GoogleConfig;
32
+ }): GoogleLanguageModel;
33
+ constructor(modelId: GoogleModelId, config: GoogleConfig);
25
34
  get provider(): string;
26
35
  get supportedUrls(): Record<string, RegExp[]> | PromiseLike<Record<string, RegExp[]>>;
27
36
  private getArgs;
28
- doGenerate(options: LanguageModelV3CallOptions): Promise<LanguageModelV3GenerateResult>;
29
- doStream(options: LanguageModelV3CallOptions): Promise<LanguageModelV3StreamResult>;
37
+ doGenerate(options: LanguageModelV4CallOptions): Promise<LanguageModelV4GenerateResult>;
38
+ doStream(options: LanguageModelV4CallOptions): Promise<LanguageModelV4StreamResult>;
30
39
  }
31
40
  declare const getGroundingMetadataSchema: () => z.ZodObject<{
32
41
  webSearchQueries: z.ZodOptional<z.ZodNullable<z.ZodArray<z.ZodString>>>;
@@ -86,8 +95,18 @@ declare const responseSchema: _ai_sdk_provider_utils.LazySchema<{
86
95
  content?: Record<string, never> | {
87
96
  parts?: ({
88
97
  functionCall: {
89
- name: string;
90
- args: unknown;
98
+ id?: string | null | undefined;
99
+ name?: string | null | undefined;
100
+ args?: unknown;
101
+ partialArgs?: {
102
+ jsonPath: string;
103
+ stringValue?: string | null | undefined;
104
+ numberValue?: number | null | undefined;
105
+ boolValue?: boolean | null | undefined;
106
+ nullValue?: unknown;
107
+ willContinue?: boolean | null | undefined;
108
+ }[] | null | undefined;
109
+ willContinue?: boolean | null | undefined;
91
110
  };
92
111
  thoughtSignature?: string | null | undefined;
93
112
  } | {
@@ -97,6 +116,20 @@ declare const responseSchema: _ai_sdk_provider_utils.LazySchema<{
97
116
  };
98
117
  thought?: boolean | null | undefined;
99
118
  thoughtSignature?: string | null | undefined;
119
+ } | {
120
+ toolCall: {
121
+ toolType: string;
122
+ id: string;
123
+ args?: unknown;
124
+ };
125
+ thoughtSignature?: string | null | undefined;
126
+ } | {
127
+ toolResponse: {
128
+ toolType: string;
129
+ id: string;
130
+ response?: unknown;
131
+ };
132
+ thoughtSignature?: string | null | undefined;
100
133
  } | {
101
134
  executableCode?: {
102
135
  language: string;
@@ -112,6 +145,7 @@ declare const responseSchema: _ai_sdk_provider_utils.LazySchema<{
112
145
  })[] | null | undefined;
113
146
  } | null | undefined;
114
147
  finishReason?: string | null | undefined;
148
+ finishMessage?: string | null | undefined;
115
149
  safetyRatings?: {
116
150
  category?: string | null | undefined;
117
151
  probability?: string | null | undefined;
@@ -181,6 +215,15 @@ declare const responseSchema: _ai_sdk_provider_utils.LazySchema<{
181
215
  candidatesTokenCount?: number | null | undefined;
182
216
  totalTokenCount?: number | null | undefined;
183
217
  trafficType?: string | null | undefined;
218
+ serviceTier?: string | null | undefined;
219
+ promptTokensDetails?: {
220
+ modality: string;
221
+ tokenCount: number;
222
+ }[] | null | undefined;
223
+ candidatesTokensDetails?: {
224
+ modality: string;
225
+ tokenCount: number;
226
+ }[] | null | undefined;
184
227
  } | null | undefined;
185
228
  promptFeedback?: {
186
229
  blockReason?: string | null | undefined;
@@ -197,13 +240,44 @@ declare const responseSchema: _ai_sdk_provider_utils.LazySchema<{
197
240
  type GroundingMetadataSchema = NonNullable<InferSchema<typeof responseSchema>['candidates'][number]['groundingMetadata']>;
198
241
  type UrlContextMetadataSchema = NonNullable<InferSchema<typeof responseSchema>['candidates'][number]['urlContextMetadata']>;
199
242
  type SafetyRatingSchema = NonNullable<InferSchema<typeof responseSchema>['candidates'][number]['safetyRatings']>[number];
243
+ type PromptFeedbackSchema = NonNullable<InferSchema<typeof responseSchema>['promptFeedback']>;
244
+ type UsageMetadataSchema = NonNullable<InferSchema<typeof responseSchema>['usageMetadata']>;
245
+
246
+ type GoogleSpeechModelId = 'gemini-2.5-flash-preview-tts' | 'gemini-2.5-pro-preview-tts' | 'gemini-3.1-flash-tts-preview' | (string & {});
247
+
248
+ interface GoogleSpeechModelConfig {
249
+ provider: string;
250
+ baseURL: string;
251
+ headers?: Resolvable<Record<string, string | undefined>>;
252
+ fetch?: FetchFunction;
253
+ _internal?: {
254
+ currentDate?: () => Date;
255
+ };
256
+ }
257
+ declare class GoogleSpeechModel implements SpeechModelV4 {
258
+ readonly modelId: GoogleSpeechModelId;
259
+ private readonly config;
260
+ readonly specificationVersion = "v4";
261
+ static [WORKFLOW_SERIALIZE](model: GoogleSpeechModel): {
262
+ modelId: string;
263
+ config: _ai_sdk_provider.JSONObject;
264
+ };
265
+ static [WORKFLOW_DESERIALIZE](options: {
266
+ modelId: GoogleSpeechModelId;
267
+ config: GoogleSpeechModelConfig;
268
+ }): GoogleSpeechModel;
269
+ get provider(): string;
270
+ constructor(modelId: GoogleSpeechModelId, config: GoogleSpeechModelConfig);
271
+ private getArgs;
272
+ doGenerate(options: Parameters<SpeechModelV4['doGenerate']>[0]): Promise<Awaited<ReturnType<SpeechModelV4['doGenerate']>>>;
273
+ }
200
274
 
201
275
  declare const googleTools: {
202
276
  /**
203
277
  * Creates a Google search tool that gives Google direct access to real-time web content.
204
278
  * Must have name "google_search".
205
279
  */
206
- googleSearch: _ai_sdk_provider_utils.ProviderToolFactory<{}, {
280
+ googleSearch: _ai_sdk_provider_utils.ProviderExecutedToolFactory<{}, {}, {
207
281
  [x: string]: unknown;
208
282
  searchTypes?: {
209
283
  webSearch?: Record<string, never> | undefined;
@@ -213,7 +287,7 @@ declare const googleTools: {
213
287
  startTime: string;
214
288
  endTime: string;
215
289
  } | undefined;
216
- }>;
290
+ }, {}>;
217
291
  /**
218
292
  * Creates an Enterprise Web Search tool for grounding responses using a compliance-focused web index.
219
293
  * Designed for highly-regulated industries (finance, healthcare, public sector).
@@ -224,7 +298,7 @@ declare const googleTools: {
224
298
  *
225
299
  * @see https://cloud.google.com/vertex-ai/generative-ai/docs/grounding/web-grounding-enterprise
226
300
  */
227
- enterpriseWebSearch: _ai_sdk_provider_utils.ProviderToolFactory<{}, {}>;
301
+ enterpriseWebSearch: _ai_sdk_provider_utils.ProviderExecutedToolFactory<{}, {}, {}, {}>;
228
302
  /**
229
303
  * Creates a Google Maps grounding tool that gives the model access to Google Maps data.
230
304
  * Must have name "google_maps".
@@ -232,12 +306,12 @@ declare const googleTools: {
232
306
  * @see https://ai.google.dev/gemini-api/docs/maps-grounding
233
307
  * @see https://cloud.google.com/vertex-ai/generative-ai/docs/grounding/grounding-with-google-maps
234
308
  */
235
- googleMaps: _ai_sdk_provider_utils.ProviderToolFactory<{}, {}>;
309
+ googleMaps: _ai_sdk_provider_utils.ProviderExecutedToolFactory<{}, {}, {}, {}>;
236
310
  /**
237
311
  * Creates a URL context tool that gives Google direct access to real-time web content.
238
312
  * Must have name "url_context".
239
313
  */
240
- urlContext: _ai_sdk_provider_utils.ProviderToolFactory<{}, {}>;
314
+ urlContext: _ai_sdk_provider_utils.ProviderExecutedToolFactory<{}, {}, {}, {}>;
241
315
  /**
242
316
  * Enables Retrieval Augmented Generation (RAG) via the Gemini File Search tool.
243
317
  * Must have name "file_search".
@@ -248,12 +322,12 @@ declare const googleTools: {
248
322
  *
249
323
  * @see https://ai.google.dev/gemini-api/docs/file-search
250
324
  */
251
- fileSearch: _ai_sdk_provider_utils.ProviderToolFactory<{}, {
325
+ fileSearch: _ai_sdk_provider_utils.ProviderExecutedToolFactory<{}, {}, {
252
326
  [x: string]: unknown;
253
327
  fileSearchStoreNames: string[];
254
328
  topK?: number | undefined;
255
329
  metadataFilter?: string | undefined;
256
- }>;
330
+ }, {}>;
257
331
  /**
258
332
  * A tool that enables the model to generate and run Python code.
259
333
  * Must have name "code_execution".
@@ -264,21 +338,21 @@ declare const googleTools: {
264
338
  * @see https://ai.google.dev/gemini-api/docs/code-execution (Google AI)
265
339
  * @see https://cloud.google.com/vertex-ai/generative-ai/docs/model-reference/code-execution-api (Vertex AI)
266
340
  */
267
- codeExecution: _ai_sdk_provider_utils.ProviderToolFactoryWithOutputSchema<{
341
+ codeExecution: _ai_sdk_provider_utils.ProviderExecutedToolFactory<{
268
342
  language: string;
269
343
  code: string;
270
344
  }, {
271
345
  outcome: string;
272
346
  output: string;
273
- }, {}>;
347
+ }, {}, {}>;
274
348
  /**
275
349
  * Creates a Vertex RAG Store tool that enables the model to perform RAG searches against a Vertex RAG Store.
276
350
  * Must have name "vertex_rag_store".
277
351
  */
278
- vertexRagStore: _ai_sdk_provider_utils.ProviderToolFactory<{}, {
352
+ vertexRagStore: _ai_sdk_provider_utils.ProviderExecutedToolFactory<{}, {}, {
279
353
  ragCorpus: string;
280
354
  topK?: number;
281
- }>;
355
+ }, {}>;
282
356
  };
283
357
 
284
- export { GoogleGenerativeAILanguageModel, type GoogleGenerativeAIModelId, type GroundingMetadataSchema, type SafetyRatingSchema, type UrlContextMetadataSchema, getGroundingMetadataSchema, getUrlContextMetadataSchema, googleTools };
358
+ export { GoogleLanguageModel, type GoogleModelId, GoogleSpeechModel, type GroundingMetadataSchema, type PromptFeedbackSchema, type SafetyRatingSchema, type UrlContextMetadataSchema, type UsageMetadataSchema, getGroundingMetadataSchema, getUrlContextMetadataSchema, googleTools };