@ai-sdk/google 2.0.87 → 2.0.89

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.
@@ -3,7 +3,7 @@ import { Resolvable, FetchFunction, InferValidator } from '@ai-sdk/provider-util
3
3
  import { LanguageModelV2 } from '@ai-sdk/provider';
4
4
  import { z } from 'zod/v4';
5
5
 
6
- type GoogleGenerativeAIModelId = 'gemini-1.5-flash' | 'gemini-1.5-flash-latest' | 'gemini-1.5-flash-001' | 'gemini-1.5-flash-002' | 'gemini-1.5-flash-8b' | 'gemini-1.5-flash-8b-latest' | 'gemini-1.5-flash-8b-001' | 'gemini-1.5-pro' | 'gemini-1.5-pro-latest' | 'gemini-1.5-pro-001' | 'gemini-1.5-pro-002' | 'gemini-2.0-flash' | 'gemini-2.0-flash-001' | 'gemini-2.0-flash-live-001' | 'gemini-2.0-flash-lite' | 'gemini-2.0-pro-exp-02-05' | 'gemini-2.0-flash-thinking-exp-01-21' | 'gemini-2.0-flash-exp' | 'gemini-2.5-pro' | 'gemini-2.5-flash' | 'gemini-2.5-flash-image-preview' | '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-3.5-flash-lite' | 'gemini-3.6-flash' | 'gemini-pro-latest' | 'gemini-flash-latest' | 'gemini-flash-lite-latest' | 'gemini-2.5-pro-exp-03-25' | 'gemini-exp-1206' | 'gemma-3-12b-it' | 'gemma-3-27b-it' | (string & {});
6
+ type GoogleGenerativeAIModelId = 'gemini-1.5-flash' | 'gemini-1.5-flash-latest' | 'gemini-1.5-flash-001' | 'gemini-1.5-flash-002' | 'gemini-1.5-flash-8b' | 'gemini-1.5-flash-8b-latest' | 'gemini-1.5-flash-8b-001' | 'gemini-1.5-pro' | 'gemini-1.5-pro-latest' | 'gemini-1.5-pro-001' | 'gemini-1.5-pro-002' | 'gemini-2.0-flash' | 'gemini-2.0-flash-001' | 'gemini-2.0-flash-live-001' | 'gemini-2.0-flash-lite' | 'gemini-2.0-pro-exp-02-05' | 'gemini-2.0-flash-thinking-exp-01-21' | 'gemini-2.0-flash-exp' | 'gemini-2.5-pro' | 'gemini-2.5-flash' | 'gemini-2.5-flash-image-preview' | '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-3.5-flash-lite' | 'gemini-3.6-flash' | 'gemini-3.7-flash' | 'gemini-pro-latest' | 'gemini-flash-latest' | 'gemini-flash-lite-latest' | 'gemini-2.5-pro-exp-03-25' | 'gemini-exp-1206' | 'gemma-3-12b-it' | 'gemma-3-27b-it' | (string & {});
7
7
 
8
8
  type GoogleGenerativeAIConfig = {
9
9
  provider: string;
@@ -3,7 +3,7 @@ import { Resolvable, FetchFunction, InferValidator } from '@ai-sdk/provider-util
3
3
  import { LanguageModelV2 } from '@ai-sdk/provider';
4
4
  import { z } from 'zod/v4';
5
5
 
6
- type GoogleGenerativeAIModelId = 'gemini-1.5-flash' | 'gemini-1.5-flash-latest' | 'gemini-1.5-flash-001' | 'gemini-1.5-flash-002' | 'gemini-1.5-flash-8b' | 'gemini-1.5-flash-8b-latest' | 'gemini-1.5-flash-8b-001' | 'gemini-1.5-pro' | 'gemini-1.5-pro-latest' | 'gemini-1.5-pro-001' | 'gemini-1.5-pro-002' | 'gemini-2.0-flash' | 'gemini-2.0-flash-001' | 'gemini-2.0-flash-live-001' | 'gemini-2.0-flash-lite' | 'gemini-2.0-pro-exp-02-05' | 'gemini-2.0-flash-thinking-exp-01-21' | 'gemini-2.0-flash-exp' | 'gemini-2.5-pro' | 'gemini-2.5-flash' | 'gemini-2.5-flash-image-preview' | '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-3.5-flash-lite' | 'gemini-3.6-flash' | 'gemini-pro-latest' | 'gemini-flash-latest' | 'gemini-flash-lite-latest' | 'gemini-2.5-pro-exp-03-25' | 'gemini-exp-1206' | 'gemma-3-12b-it' | 'gemma-3-27b-it' | (string & {});
6
+ type GoogleGenerativeAIModelId = 'gemini-1.5-flash' | 'gemini-1.5-flash-latest' | 'gemini-1.5-flash-001' | 'gemini-1.5-flash-002' | 'gemini-1.5-flash-8b' | 'gemini-1.5-flash-8b-latest' | 'gemini-1.5-flash-8b-001' | 'gemini-1.5-pro' | 'gemini-1.5-pro-latest' | 'gemini-1.5-pro-001' | 'gemini-1.5-pro-002' | 'gemini-2.0-flash' | 'gemini-2.0-flash-001' | 'gemini-2.0-flash-live-001' | 'gemini-2.0-flash-lite' | 'gemini-2.0-pro-exp-02-05' | 'gemini-2.0-flash-thinking-exp-01-21' | 'gemini-2.0-flash-exp' | 'gemini-2.5-pro' | 'gemini-2.5-flash' | 'gemini-2.5-flash-image-preview' | '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-3.5-flash-lite' | 'gemini-3.6-flash' | 'gemini-3.7-flash' | 'gemini-pro-latest' | 'gemini-flash-latest' | 'gemini-flash-lite-latest' | 'gemini-2.5-pro-exp-03-25' | 'gemini-exp-1206' | 'gemma-3-12b-it' | 'gemma-3-27b-it' | (string & {});
7
7
 
8
8
  type GoogleGenerativeAIConfig = {
9
9
  provider: string;
@@ -32,22 +32,39 @@ var import_provider_utils4 = require("@ai-sdk/provider-utils");
32
32
  var import_v43 = require("zod/v4");
33
33
 
34
34
  // src/convert-json-schema-to-openapi-schema.ts
35
+ var import_provider = require("@ai-sdk/provider");
35
36
  function convertJSONSchemaToOpenAPISchema(jsonSchema, isRoot = true) {
37
+ const rootSchema = typeof jsonSchema === "object" ? jsonSchema : void 0;
38
+ return convertJSONSchemaDefinition(jsonSchema, isRoot, {
39
+ definitions: rootSchema == null ? void 0 : rootSchema.definitions,
40
+ dollarDefinitions: rootSchema == null ? void 0 : rootSchema.$defs,
41
+ resolvingReferences: /* @__PURE__ */ new Set()
42
+ });
43
+ }
44
+ function convertJSONSchemaDefinition(jsonSchema, isRoot, referenceContext) {
36
45
  if (jsonSchema == null) {
37
46
  return void 0;
38
47
  }
48
+ if (typeof jsonSchema === "boolean") {
49
+ return { type: "boolean", properties: {} };
50
+ }
51
+ if (jsonSchema.$ref != null) {
52
+ return convertJSONSchemaReference({
53
+ jsonSchema,
54
+ reference: jsonSchema.$ref,
55
+ isRoot,
56
+ referenceContext
57
+ });
58
+ }
39
59
  if (isEmptyObjectSchema(jsonSchema)) {
40
60
  if (isRoot) {
41
61
  return void 0;
42
62
  }
43
- if (typeof jsonSchema === "object" && jsonSchema.description) {
63
+ if (jsonSchema.description) {
44
64
  return { type: "object", description: jsonSchema.description };
45
65
  }
46
66
  return { type: "object" };
47
67
  }
48
- if (typeof jsonSchema === "boolean") {
49
- return { type: "boolean", properties: {} };
50
- }
51
68
  const {
52
69
  type,
53
70
  description,
@@ -91,18 +108,20 @@ function convertJSONSchemaToOpenAPISchema(jsonSchema, isRoot = true) {
91
108
  if (properties != null) {
92
109
  result.properties = Object.entries(properties).reduce(
93
110
  (acc, [key, value]) => {
94
- acc[key] = convertJSONSchemaToOpenAPISchema(value, false);
111
+ acc[key] = convertJSONSchemaDefinition(value, false, referenceContext);
95
112
  return acc;
96
113
  },
97
114
  {}
98
115
  );
99
116
  }
100
117
  if (items) {
101
- result.items = Array.isArray(items) ? items.map((item) => convertJSONSchemaToOpenAPISchema(item, false)) : convertJSONSchemaToOpenAPISchema(items, false);
118
+ result.items = Array.isArray(items) ? items.map(
119
+ (item) => convertJSONSchemaDefinition(item, false, referenceContext)
120
+ ) : convertJSONSchemaDefinition(items, false, referenceContext);
102
121
  }
103
122
  if (allOf) {
104
123
  result.allOf = allOf.map(
105
- (item) => convertJSONSchemaToOpenAPISchema(item, false)
124
+ (item) => convertJSONSchemaDefinition(item, false, referenceContext)
106
125
  );
107
126
  }
108
127
  if (anyOf) {
@@ -113,9 +132,10 @@ function convertJSONSchemaToOpenAPISchema(jsonSchema, isRoot = true) {
113
132
  (schema) => !(typeof schema === "object" && (schema == null ? void 0 : schema.type) === "null")
114
133
  );
115
134
  if (nonNullSchemas.length === 1) {
116
- const converted = convertJSONSchemaToOpenAPISchema(
135
+ const converted = convertJSONSchemaDefinition(
117
136
  nonNullSchemas[0],
118
- false
137
+ false,
138
+ referenceContext
119
139
  );
120
140
  if (typeof converted === "object") {
121
141
  result.nullable = true;
@@ -123,19 +143,19 @@ function convertJSONSchemaToOpenAPISchema(jsonSchema, isRoot = true) {
123
143
  }
124
144
  } else {
125
145
  result.anyOf = nonNullSchemas.map(
126
- (item) => convertJSONSchemaToOpenAPISchema(item, false)
146
+ (item) => convertJSONSchemaDefinition(item, false, referenceContext)
127
147
  );
128
148
  result.nullable = true;
129
149
  }
130
150
  } else {
131
151
  result.anyOf = anyOf.map(
132
- (item) => convertJSONSchemaToOpenAPISchema(item, false)
152
+ (item) => convertJSONSchemaDefinition(item, false, referenceContext)
133
153
  );
134
154
  }
135
155
  }
136
156
  if (oneOf) {
137
157
  result.oneOf = oneOf.map(
138
- (item) => convertJSONSchemaToOpenAPISchema(item, false)
158
+ (item) => convertJSONSchemaDefinition(item, false, referenceContext)
139
159
  );
140
160
  }
141
161
  if (minLength !== void 0) {
@@ -143,12 +163,82 @@ function convertJSONSchemaToOpenAPISchema(jsonSchema, isRoot = true) {
143
163
  }
144
164
  return result;
145
165
  }
166
+ function convertJSONSchemaReference({
167
+ jsonSchema,
168
+ reference,
169
+ isRoot,
170
+ referenceContext
171
+ }) {
172
+ const { definition, referenceKey } = getReferencedDefinition(
173
+ reference,
174
+ referenceContext
175
+ );
176
+ if (referenceContext.resolvingReferences.has(referenceKey)) {
177
+ throw new import_provider.UnsupportedFunctionalityError({
178
+ functionality: `recursive JSON Schema reference: ${reference}`,
179
+ message: "Google schema conversion does not support recursive JSON Schema references."
180
+ });
181
+ }
182
+ const resolvingReferences = new Set(referenceContext.resolvingReferences);
183
+ resolvingReferences.add(referenceKey);
184
+ const { $ref: _reference, ...siblingSchema } = jsonSchema;
185
+ const resolvedSchema = typeof definition === "boolean" ? definition ? siblingSchema : false : { ...definition, ...siblingSchema };
186
+ return convertJSONSchemaDefinition(resolvedSchema, isRoot, {
187
+ ...referenceContext,
188
+ resolvingReferences
189
+ });
190
+ }
191
+ function getReferencedDefinition(reference, referenceContext) {
192
+ const definitionSources = [
193
+ {
194
+ prefix: "#/$defs/",
195
+ definitions: referenceContext.dollarDefinitions
196
+ },
197
+ {
198
+ prefix: "#/definitions/",
199
+ definitions: referenceContext.definitions
200
+ }
201
+ ];
202
+ const source = definitionSources.find(
203
+ ({ prefix }) => reference.startsWith(prefix)
204
+ );
205
+ const encodedDefinitionName = source ? reference.slice(source.prefix.length) : void 0;
206
+ if (source == null || encodedDefinitionName == null || encodedDefinitionName.length === 0 || encodedDefinitionName.includes("/")) {
207
+ throwUnsupportedReference(reference);
208
+ }
209
+ let decodedDefinitionName;
210
+ try {
211
+ decodedDefinitionName = decodeURIComponent(encodedDefinitionName);
212
+ } catch (e) {
213
+ throwUnsupportedReference(reference);
214
+ }
215
+ if (decodedDefinitionName.includes("/") || /~(?![01])/u.test(decodedDefinitionName) || source.definitions == null) {
216
+ throwUnsupportedReference(reference);
217
+ }
218
+ const definitionName = decodedDefinitionName.replace(
219
+ /~[01]/g,
220
+ (match) => match === "~1" ? "/" : "~"
221
+ );
222
+ if (!Object.prototype.hasOwnProperty.call(source.definitions, definitionName)) {
223
+ throwUnsupportedReference(reference);
224
+ }
225
+ return {
226
+ definition: source.definitions[definitionName],
227
+ referenceKey: `${source.prefix}${definitionName}`
228
+ };
229
+ }
230
+ function throwUnsupportedReference(reference) {
231
+ throw new import_provider.UnsupportedFunctionalityError({
232
+ functionality: `JSON Schema reference: ${reference}`,
233
+ message: "Google schema conversion only supports references to direct children of root-level $defs or definitions."
234
+ });
235
+ }
146
236
  function isEmptyObjectSchema(jsonSchema) {
147
237
  return jsonSchema != null && typeof jsonSchema === "object" && jsonSchema.type === "object" && (jsonSchema.properties == null || Object.keys(jsonSchema.properties).length === 0) && !jsonSchema.additionalProperties;
148
238
  }
149
239
 
150
240
  // src/convert-to-google-generative-ai-messages.ts
151
- var import_provider = require("@ai-sdk/provider");
241
+ var import_provider2 = require("@ai-sdk/provider");
152
242
  var import_provider_utils = require("@ai-sdk/provider-utils");
153
243
  var SKIP_THOUGHT_SIGNATURE_VALIDATOR = "skip_thought_signature_validator";
154
244
  function convertToGoogleGenerativeAIMessages(prompt, options) {
@@ -163,7 +253,7 @@ function convertToGoogleGenerativeAIMessages(prompt, options) {
163
253
  switch (role) {
164
254
  case "system": {
165
255
  if (!systemMessagesAllowed) {
166
- throw new import_provider.UnsupportedFunctionalityError({
256
+ throw new import_provider2.UnsupportedFunctionalityError({
167
257
  functionality: "system messages are only supported at the beginning of the conversation"
168
258
  });
169
259
  }
@@ -225,12 +315,12 @@ function convertToGoogleGenerativeAIMessages(prompt, options) {
225
315
  }
226
316
  case "file": {
227
317
  if (part.mediaType !== "image/png") {
228
- throw new import_provider.UnsupportedFunctionalityError({
318
+ throw new import_provider2.UnsupportedFunctionalityError({
229
319
  functionality: "Only PNG images are supported in assistant messages"
230
320
  });
231
321
  }
232
322
  if (part.data instanceof URL) {
233
- throw new import_provider.UnsupportedFunctionalityError({
323
+ throw new import_provider2.UnsupportedFunctionalityError({
234
324
  functionality: "File data URLs in assistant messages are not supported"
235
325
  });
236
326
  }
@@ -584,7 +674,7 @@ function getGoogleModelCapabilities(modelId) {
584
674
  }
585
675
 
586
676
  // src/google-prepare-tools.ts
587
- var import_provider2 = require("@ai-sdk/provider");
677
+ var import_provider3 = require("@ai-sdk/provider");
588
678
  function prepareTools({
589
679
  tools,
590
680
  toolChoice,
@@ -822,7 +912,7 @@ function prepareTools({
822
912
  };
823
913
  default: {
824
914
  const _exhaustiveCheck = type;
825
- throw new import_provider2.UnsupportedFunctionalityError({
915
+ throw new import_provider3.UnsupportedFunctionalityError({
826
916
  functionality: `tool choice type: ${_exhaustiveCheck}`
827
917
  });
828
918
  }