@ai-sdk/google 4.0.0-beta.8 → 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 +608 -5
  2. package/README.md +6 -4
  3. package/dist/index.d.ts +297 -54
  4. package/dist/index.js +5409 -640
  5. package/dist/index.js.map +1 -1
  6. package/dist/internal/index.d.ts +97 -26
  7. package/dist/internal/index.js +1653 -453
  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} +691 -217
  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 -384
  65. package/dist/index.mjs +0 -2519
  66. package/dist/index.mjs.map +0 -1
  67. package/dist/internal/index.d.mts +0 -287
  68. package/dist/internal/index.mjs +0 -1708
  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 -47
@@ -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;
@@ -182,6 +215,15 @@ declare const responseSchema: _ai_sdk_provider_utils.LazySchema<{
182
215
  candidatesTokenCount?: number | null | undefined;
183
216
  totalTokenCount?: number | null | undefined;
184
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;
185
227
  } | null | undefined;
186
228
  promptFeedback?: {
187
229
  blockReason?: string | null | undefined;
@@ -201,12 +243,41 @@ type SafetyRatingSchema = NonNullable<InferSchema<typeof responseSchema>['candid
201
243
  type PromptFeedbackSchema = NonNullable<InferSchema<typeof responseSchema>['promptFeedback']>;
202
244
  type UsageMetadataSchema = NonNullable<InferSchema<typeof responseSchema>['usageMetadata']>;
203
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
+ }
274
+
204
275
  declare const googleTools: {
205
276
  /**
206
277
  * Creates a Google search tool that gives Google direct access to real-time web content.
207
278
  * Must have name "google_search".
208
279
  */
209
- googleSearch: _ai_sdk_provider_utils.ProviderToolFactory<{}, {
280
+ googleSearch: _ai_sdk_provider_utils.ProviderExecutedToolFactory<{}, {}, {
210
281
  [x: string]: unknown;
211
282
  searchTypes?: {
212
283
  webSearch?: Record<string, never> | undefined;
@@ -216,7 +287,7 @@ declare const googleTools: {
216
287
  startTime: string;
217
288
  endTime: string;
218
289
  } | undefined;
219
- }>;
290
+ }, {}>;
220
291
  /**
221
292
  * Creates an Enterprise Web Search tool for grounding responses using a compliance-focused web index.
222
293
  * Designed for highly-regulated industries (finance, healthcare, public sector).
@@ -227,7 +298,7 @@ declare const googleTools: {
227
298
  *
228
299
  * @see https://cloud.google.com/vertex-ai/generative-ai/docs/grounding/web-grounding-enterprise
229
300
  */
230
- enterpriseWebSearch: _ai_sdk_provider_utils.ProviderToolFactory<{}, {}>;
301
+ enterpriseWebSearch: _ai_sdk_provider_utils.ProviderExecutedToolFactory<{}, {}, {}, {}>;
231
302
  /**
232
303
  * Creates a Google Maps grounding tool that gives the model access to Google Maps data.
233
304
  * Must have name "google_maps".
@@ -235,12 +306,12 @@ declare const googleTools: {
235
306
  * @see https://ai.google.dev/gemini-api/docs/maps-grounding
236
307
  * @see https://cloud.google.com/vertex-ai/generative-ai/docs/grounding/grounding-with-google-maps
237
308
  */
238
- googleMaps: _ai_sdk_provider_utils.ProviderToolFactory<{}, {}>;
309
+ googleMaps: _ai_sdk_provider_utils.ProviderExecutedToolFactory<{}, {}, {}, {}>;
239
310
  /**
240
311
  * Creates a URL context tool that gives Google direct access to real-time web content.
241
312
  * Must have name "url_context".
242
313
  */
243
- urlContext: _ai_sdk_provider_utils.ProviderToolFactory<{}, {}>;
314
+ urlContext: _ai_sdk_provider_utils.ProviderExecutedToolFactory<{}, {}, {}, {}>;
244
315
  /**
245
316
  * Enables Retrieval Augmented Generation (RAG) via the Gemini File Search tool.
246
317
  * Must have name "file_search".
@@ -251,12 +322,12 @@ declare const googleTools: {
251
322
  *
252
323
  * @see https://ai.google.dev/gemini-api/docs/file-search
253
324
  */
254
- fileSearch: _ai_sdk_provider_utils.ProviderToolFactory<{}, {
325
+ fileSearch: _ai_sdk_provider_utils.ProviderExecutedToolFactory<{}, {}, {
255
326
  [x: string]: unknown;
256
327
  fileSearchStoreNames: string[];
257
328
  topK?: number | undefined;
258
329
  metadataFilter?: string | undefined;
259
- }>;
330
+ }, {}>;
260
331
  /**
261
332
  * A tool that enables the model to generate and run Python code.
262
333
  * Must have name "code_execution".
@@ -267,21 +338,21 @@ declare const googleTools: {
267
338
  * @see https://ai.google.dev/gemini-api/docs/code-execution (Google AI)
268
339
  * @see https://cloud.google.com/vertex-ai/generative-ai/docs/model-reference/code-execution-api (Vertex AI)
269
340
  */
270
- codeExecution: _ai_sdk_provider_utils.ProviderToolFactoryWithOutputSchema<{
341
+ codeExecution: _ai_sdk_provider_utils.ProviderExecutedToolFactory<{
271
342
  language: string;
272
343
  code: string;
273
344
  }, {
274
345
  outcome: string;
275
346
  output: string;
276
- }, {}>;
347
+ }, {}, {}>;
277
348
  /**
278
349
  * Creates a Vertex RAG Store tool that enables the model to perform RAG searches against a Vertex RAG Store.
279
350
  * Must have name "vertex_rag_store".
280
351
  */
281
- vertexRagStore: _ai_sdk_provider_utils.ProviderToolFactory<{}, {
352
+ vertexRagStore: _ai_sdk_provider_utils.ProviderExecutedToolFactory<{}, {}, {
282
353
  ragCorpus: string;
283
354
  topK?: number;
284
- }>;
355
+ }, {}>;
285
356
  };
286
357
 
287
- export { GoogleGenerativeAILanguageModel, type GoogleGenerativeAIModelId, type GroundingMetadataSchema, type PromptFeedbackSchema, type SafetyRatingSchema, type UrlContextMetadataSchema, type UsageMetadataSchema, getGroundingMetadataSchema, getUrlContextMetadataSchema, googleTools };
358
+ export { GoogleLanguageModel, type GoogleModelId, GoogleSpeechModel, type GroundingMetadataSchema, type PromptFeedbackSchema, type SafetyRatingSchema, type UrlContextMetadataSchema, type UsageMetadataSchema, getGroundingMetadataSchema, getUrlContextMetadataSchema, googleTools };