@ai-sdk/google 4.0.0-beta.44 → 4.0.0-beta.45

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 (28) hide show
  1. package/CHANGELOG.md +11 -0
  2. package/README.md +4 -4
  3. package/dist/index.d.ts +33 -33
  4. package/dist/index.js +46 -55
  5. package/dist/index.js.map +1 -1
  6. package/dist/internal/index.d.ts +9 -9
  7. package/dist/internal/index.js +22 -25
  8. package/dist/internal/index.js.map +1 -1
  9. package/docs/{15-google-generative-ai.mdx → 15-google.mdx} +36 -36
  10. package/package.json +4 -4
  11. package/src/{convert-google-generative-ai-usage.ts → convert-google-usage.ts} +6 -6
  12. package/src/{convert-to-google-generative-ai-messages.ts → convert-to-google-messages.ts} +14 -14
  13. package/src/{google-generative-ai-embedding-model.ts → google-embedding-model.ts} +10 -16
  14. package/src/{google-generative-ai-embedding-options.ts → google-embedding-options.ts} +1 -1
  15. package/src/{google-generative-ai-files.ts → google-files.ts} +3 -3
  16. package/src/{google-generative-ai-image-model.ts → google-image-model.ts} +16 -20
  17. package/src/{google-generative-ai-image-settings.ts → google-image-settings.ts} +2 -2
  18. package/src/{google-generative-ai-language-model.ts → google-language-model.ts} +28 -34
  19. package/src/{google-generative-ai-options.ts → google-options.ts} +2 -2
  20. package/src/google-prepare-tools.ts +3 -3
  21. package/src/google-prompt.ts +82 -0
  22. package/src/google-provider.ts +42 -46
  23. package/src/{google-generative-ai-video-model.ts → google-video-model.ts} +5 -5
  24. package/src/{google-generative-ai-video-settings.ts → google-video-settings.ts} +1 -1
  25. package/src/index.ts +28 -10
  26. package/src/internal/index.ts +2 -2
  27. package/src/{map-google-generative-ai-finish-reason.ts → map-google-finish-reason.ts} +1 -1
  28. package/src/google-generative-ai-prompt.ts +0 -82
@@ -3,9 +3,9 @@ import { WORKFLOW_SERIALIZE, WORKFLOW_DESERIALIZE, Resolvable, FetchFunction, In
3
3
  import { LanguageModelV4, JSONObject, LanguageModelV4CallOptions, LanguageModelV4GenerateResult, LanguageModelV4StreamResult } from '@ai-sdk/provider';
4
4
  import { z } from 'zod/v4';
5
5
 
6
- type GoogleGenerativeAIModelId = '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-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 & {});
6
+ 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-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
7
 
8
- type GoogleGenerativeAIConfig = {
8
+ type GoogleConfig = {
9
9
  provider: string;
10
10
  baseURL: string;
11
11
  headers?: Resolvable<Record<string, string | undefined>>;
@@ -16,20 +16,20 @@ type GoogleGenerativeAIConfig = {
16
16
  */
17
17
  supportedUrls?: () => LanguageModelV4['supportedUrls'];
18
18
  };
19
- declare class GoogleGenerativeAILanguageModel implements LanguageModelV4 {
19
+ declare class GoogleLanguageModel implements LanguageModelV4 {
20
20
  readonly specificationVersion = "v4";
21
- readonly modelId: GoogleGenerativeAIModelId;
21
+ readonly modelId: GoogleModelId;
22
22
  private readonly config;
23
23
  private readonly generateId;
24
- static [WORKFLOW_SERIALIZE](model: GoogleGenerativeAILanguageModel): {
24
+ static [WORKFLOW_SERIALIZE](model: GoogleLanguageModel): {
25
25
  modelId: string;
26
26
  config: JSONObject;
27
27
  };
28
28
  static [WORKFLOW_DESERIALIZE](options: {
29
29
  modelId: string;
30
- config: GoogleGenerativeAIConfig;
31
- }): GoogleGenerativeAILanguageModel;
32
- constructor(modelId: GoogleGenerativeAIModelId, config: GoogleGenerativeAIConfig);
30
+ config: GoogleConfig;
31
+ }): GoogleLanguageModel;
32
+ constructor(modelId: GoogleModelId, config: GoogleConfig);
33
33
  get provider(): string;
34
34
  get supportedUrls(): Record<string, RegExp[]> | PromiseLike<Record<string, RegExp[]>>;
35
35
  private getArgs;
@@ -324,4 +324,4 @@ declare const googleTools: {
324
324
  }, {}>;
325
325
  };
326
326
 
327
- export { GoogleGenerativeAILanguageModel, type GoogleGenerativeAIModelId, type GroundingMetadataSchema, type PromptFeedbackSchema, type SafetyRatingSchema, type UrlContextMetadataSchema, type UsageMetadataSchema, getGroundingMetadataSchema, getUrlContextMetadataSchema, googleTools };
327
+ export { GoogleLanguageModel, type GoogleModelId, type GroundingMetadataSchema, type PromptFeedbackSchema, type SafetyRatingSchema, type UrlContextMetadataSchema, type UsageMetadataSchema, getGroundingMetadataSchema, getUrlContextMetadataSchema, googleTools };
@@ -1,4 +1,4 @@
1
- // src/google-generative-ai-language-model.ts
1
+ // src/google-language-model.ts
2
2
  import {
3
3
  combineHeaders,
4
4
  createEventSourceResponseHandler,
@@ -18,8 +18,8 @@ import {
18
18
  } from "@ai-sdk/provider-utils";
19
19
  import { z as z3 } from "zod/v4";
20
20
 
21
- // src/convert-google-generative-ai-usage.ts
22
- function convertGoogleGenerativeAIUsage(usage) {
21
+ // src/convert-google-usage.ts
22
+ function convertGoogleUsage(usage) {
23
23
  var _a, _b, _c, _d;
24
24
  if (usage == null) {
25
25
  return {
@@ -173,7 +173,7 @@ function isEmptyObjectSchema(jsonSchema) {
173
173
  return jsonSchema != null && typeof jsonSchema === "object" && jsonSchema.type === "object" && (jsonSchema.properties == null || Object.keys(jsonSchema.properties).length === 0) && !jsonSchema.additionalProperties;
174
174
  }
175
175
 
176
- // src/convert-to-google-generative-ai-messages.ts
176
+ // src/convert-to-google-messages.ts
177
177
  import {
178
178
  UnsupportedFunctionalityError
179
179
  } from "@ai-sdk/provider";
@@ -288,7 +288,7 @@ function appendLegacyToolResultParts(parts, toolName, outputValue) {
288
288
  }
289
289
  }
290
290
  }
291
- function convertToGoogleGenerativeAIMessages(prompt, options) {
291
+ function convertToGoogleMessages(prompt, options) {
292
292
  var _a, _b, _c, _d, _e, _f, _g, _h;
293
293
  const systemInstructionParts = [];
294
294
  const contents = [];
@@ -558,7 +558,7 @@ var googleFailedResponseHandler = createJsonErrorResponseHandler({
558
558
  errorToMessage: (data) => data.error.message
559
559
  });
560
560
 
561
- // src/google-generative-ai-options.ts
561
+ // src/google-options.ts
562
562
  import { lazySchema as lazySchema2, zodSchema as zodSchema2 } from "@ai-sdk/provider-utils";
563
563
  import { z as z2 } from "zod/v4";
564
564
  var googleLanguageModelOptions = lazySchema2(
@@ -582,7 +582,7 @@ var googleLanguageModelOptions = lazySchema2(
582
582
  *
583
583
  * This is useful when the JSON Schema contains elements that are
584
584
  * not supported by the OpenAPI schema version that
585
- * Google Generative AI uses. You can use this to disable
585
+ * Google uses. You can use this to disable
586
586
  * structured outputs if you need to.
587
587
  */
588
588
  structuredOutputs: z2.boolean().optional(),
@@ -1175,8 +1175,8 @@ function resolvePartialArgValue(arg) {
1175
1175
  return void 0;
1176
1176
  }
1177
1177
 
1178
- // src/map-google-generative-ai-finish-reason.ts
1179
- function mapGoogleGenerativeAIFinishReason({
1178
+ // src/map-google-finish-reason.ts
1179
+ function mapGoogleFinishReason({
1180
1180
  finishReason,
1181
1181
  hasToolCalls
1182
1182
  }) {
@@ -1201,8 +1201,8 @@ function mapGoogleGenerativeAIFinishReason({
1201
1201
  }
1202
1202
  }
1203
1203
 
1204
- // src/google-generative-ai-language-model.ts
1205
- var GoogleGenerativeAILanguageModel = class _GoogleGenerativeAILanguageModel {
1204
+ // src/google-language-model.ts
1205
+ var GoogleLanguageModel = class _GoogleLanguageModel {
1206
1206
  constructor(modelId, config) {
1207
1207
  this.specificationVersion = "v4";
1208
1208
  var _a;
@@ -1217,7 +1217,7 @@ var GoogleGenerativeAILanguageModel = class _GoogleGenerativeAILanguageModel {
1217
1217
  });
1218
1218
  }
1219
1219
  static [WORKFLOW_DESERIALIZE](options) {
1220
- return new _GoogleGenerativeAILanguageModel(options.modelId, options.config);
1220
+ return new _GoogleLanguageModel(options.modelId, options.config);
1221
1221
  }
1222
1222
  get provider() {
1223
1223
  return this.config.provider;
@@ -1278,14 +1278,11 @@ var GoogleGenerativeAILanguageModel = class _GoogleGenerativeAILanguageModel {
1278
1278
  }
1279
1279
  const isGemmaModel = this.modelId.toLowerCase().startsWith("gemma-");
1280
1280
  const supportsFunctionResponseParts = this.modelId.startsWith("gemini-3");
1281
- const { contents, systemInstruction } = convertToGoogleGenerativeAIMessages(
1282
- prompt,
1283
- {
1284
- isGemmaModel,
1285
- providerOptionsName,
1286
- supportsFunctionResponseParts
1287
- }
1288
- );
1281
+ const { contents, systemInstruction } = convertToGoogleMessages(prompt, {
1282
+ isGemmaModel,
1283
+ providerOptionsName,
1284
+ supportsFunctionResponseParts
1285
+ });
1289
1286
  const {
1290
1287
  tools: googleTools2,
1291
1288
  toolConfig: googleToolConfig,
@@ -1508,7 +1505,7 @@ var GoogleGenerativeAILanguageModel = class _GoogleGenerativeAILanguageModel {
1508
1505
  return {
1509
1506
  content,
1510
1507
  finishReason: {
1511
- unified: mapGoogleGenerativeAIFinishReason({
1508
+ unified: mapGoogleFinishReason({
1512
1509
  finishReason: candidate.finishReason,
1513
1510
  // Only count client-executed tool calls for finish reason determination.
1514
1511
  hasToolCalls: content.some(
@@ -1517,7 +1514,7 @@ var GoogleGenerativeAILanguageModel = class _GoogleGenerativeAILanguageModel {
1517
1514
  }),
1518
1515
  raw: (_j = candidate.finishReason) != null ? _j : void 0
1519
1516
  },
1520
- usage: convertGoogleGenerativeAIUsage(usageMetadata),
1517
+ usage: convertGoogleUsage(usageMetadata),
1521
1518
  warnings,
1522
1519
  providerMetadata: {
1523
1520
  [providerOptionsName]: {
@@ -1886,7 +1883,7 @@ var GoogleGenerativeAILanguageModel = class _GoogleGenerativeAILanguageModel {
1886
1883
  }
1887
1884
  if (candidate.finishReason != null) {
1888
1885
  finishReason = {
1889
- unified: mapGoogleGenerativeAIFinishReason({
1886
+ unified: mapGoogleFinishReason({
1890
1887
  finishReason: candidate.finishReason,
1891
1888
  hasToolCalls
1892
1889
  }),
@@ -1921,7 +1918,7 @@ var GoogleGenerativeAILanguageModel = class _GoogleGenerativeAILanguageModel {
1921
1918
  controller.enqueue({
1922
1919
  type: "finish",
1923
1920
  finishReason,
1924
- usage: convertGoogleGenerativeAIUsage(usage),
1921
+ usage: convertGoogleUsage(usage),
1925
1922
  providerMetadata
1926
1923
  });
1927
1924
  }
@@ -2464,7 +2461,7 @@ var googleTools = {
2464
2461
  vertexRagStore
2465
2462
  };
2466
2463
  export {
2467
- GoogleGenerativeAILanguageModel,
2464
+ GoogleLanguageModel,
2468
2465
  getGroundingMetadataSchema,
2469
2466
  getUrlContextMetadataSchema,
2470
2467
  googleTools