@ai-sdk/google 2.1.0-beta.9 → 3.0.0-beta.15
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 +51 -0
- package/dist/index.d.mts +2 -2
- package/dist/index.d.ts +2 -2
- package/dist/index.js +152 -137
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +20 -15
- package/dist/index.mjs.map +1 -1
- package/dist/internal/index.d.mts +2 -2
- package/dist/internal/index.d.ts +2 -2
- package/dist/internal/index.js +136 -121
- package/dist/internal/index.js.map +1 -1
- package/dist/internal/index.mjs +16 -11
- package/dist/internal/index.mjs.map +1 -1
- package/package.json +4 -4
package/dist/internal/index.js
CHANGED
@@ -1,7 +1,9 @@
|
|
1
1
|
"use strict";
|
2
|
+
var __create = Object.create;
|
2
3
|
var __defProp = Object.defineProperty;
|
3
4
|
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
4
5
|
var __getOwnPropNames = Object.getOwnPropertyNames;
|
6
|
+
var __getProtoOf = Object.getPrototypeOf;
|
5
7
|
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
6
8
|
var __export = (target, all) => {
|
7
9
|
for (var name in all)
|
@@ -15,6 +17,14 @@ var __copyProps = (to, from, except, desc) => {
|
|
15
17
|
}
|
16
18
|
return to;
|
17
19
|
};
|
20
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
21
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
22
|
+
// file that has been converted to a CommonJS file using a Babel-
|
23
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
24
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
25
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
26
|
+
mod
|
27
|
+
));
|
18
28
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
19
29
|
|
20
30
|
// src/internal/index.ts
|
@@ -28,7 +38,7 @@ module.exports = __toCommonJS(internal_exports);
|
|
28
38
|
|
29
39
|
// src/google-generative-ai-language-model.ts
|
30
40
|
var import_provider_utils5 = require("@ai-sdk/provider-utils");
|
31
|
-
var
|
41
|
+
var z5 = __toESM(require("zod/v4"));
|
32
42
|
|
33
43
|
// src/convert-json-schema-to-openapi-schema.ts
|
34
44
|
function convertJSONSchemaToOpenAPISchema(jsonSchema) {
|
@@ -128,7 +138,7 @@ function isEmptyObjectSchema(jsonSchema) {
|
|
128
138
|
var import_provider = require("@ai-sdk/provider");
|
129
139
|
var import_provider_utils = require("@ai-sdk/provider-utils");
|
130
140
|
function convertToGoogleGenerativeAIMessages(prompt, options) {
|
131
|
-
var _a;
|
141
|
+
var _a, _b;
|
132
142
|
const systemInstructionParts = [];
|
133
143
|
const contents = [];
|
134
144
|
let systemMessagesAllowed = true;
|
@@ -180,12 +190,12 @@ function convertToGoogleGenerativeAIMessages(prompt, options) {
|
|
180
190
|
contents.push({
|
181
191
|
role: "model",
|
182
192
|
parts: content.map((part) => {
|
183
|
-
var _a2,
|
193
|
+
var _a2, _b2, _c, _d, _e, _f;
|
184
194
|
switch (part.type) {
|
185
195
|
case "text": {
|
186
196
|
return part.text.length === 0 ? void 0 : {
|
187
197
|
text: part.text,
|
188
|
-
thoughtSignature: (
|
198
|
+
thoughtSignature: (_b2 = (_a2 = part.providerOptions) == null ? void 0 : _a2.google) == null ? void 0 : _b2.thoughtSignature
|
189
199
|
};
|
190
200
|
}
|
191
201
|
case "reasoning": {
|
@@ -270,7 +280,7 @@ function convertToGoogleGenerativeAIMessages(prompt, options) {
|
|
270
280
|
name: part.toolName,
|
271
281
|
response: {
|
272
282
|
name: part.toolName,
|
273
|
-
content: output.value
|
283
|
+
content: output.type === "execution-denied" ? (_b = output.reason) != null ? _b : "Tool execution denied." : output.value
|
274
284
|
}
|
275
285
|
}
|
276
286
|
});
|
@@ -301,12 +311,12 @@ function getModelPath(modelId) {
|
|
301
311
|
|
302
312
|
// src/google-error.ts
|
303
313
|
var import_provider_utils2 = require("@ai-sdk/provider-utils");
|
304
|
-
var
|
305
|
-
var googleErrorDataSchema =
|
306
|
-
error:
|
307
|
-
code:
|
308
|
-
message:
|
309
|
-
status:
|
314
|
+
var z = __toESM(require("zod/v4"));
|
315
|
+
var googleErrorDataSchema = z.object({
|
316
|
+
error: z.object({
|
317
|
+
code: z.number().nullable(),
|
318
|
+
message: z.string(),
|
319
|
+
status: z.string()
|
310
320
|
})
|
311
321
|
});
|
312
322
|
var googleFailedResponseHandler = (0, import_provider_utils2.createJsonErrorResponseHandler)({
|
@@ -315,19 +325,19 @@ var googleFailedResponseHandler = (0, import_provider_utils2.createJsonErrorResp
|
|
315
325
|
});
|
316
326
|
|
317
327
|
// src/google-generative-ai-options.ts
|
318
|
-
var
|
319
|
-
var googleGenerativeAIProviderOptions =
|
320
|
-
responseModalities:
|
321
|
-
thinkingConfig:
|
322
|
-
thinkingBudget:
|
323
|
-
includeThoughts:
|
328
|
+
var z2 = __toESM(require("zod/v4"));
|
329
|
+
var googleGenerativeAIProviderOptions = z2.object({
|
330
|
+
responseModalities: z2.array(z2.enum(["TEXT", "IMAGE"])).optional(),
|
331
|
+
thinkingConfig: z2.object({
|
332
|
+
thinkingBudget: z2.number().optional(),
|
333
|
+
includeThoughts: z2.boolean().optional()
|
324
334
|
}).optional(),
|
325
335
|
/**
|
326
336
|
Optional.
|
327
337
|
The name of the cached content used as context to serve the prediction.
|
328
338
|
Format: cachedContents/{cachedContent}
|
329
339
|
*/
|
330
|
-
cachedContent:
|
340
|
+
cachedContent: z2.string().optional(),
|
331
341
|
/**
|
332
342
|
* Optional. Enable structured output. Default is true.
|
333
343
|
*
|
@@ -336,13 +346,13 @@ var googleGenerativeAIProviderOptions = import_v42.z.object({
|
|
336
346
|
* Google Generative AI uses. You can use this to disable
|
337
347
|
* structured outputs if you need to.
|
338
348
|
*/
|
339
|
-
structuredOutputs:
|
349
|
+
structuredOutputs: z2.boolean().optional(),
|
340
350
|
/**
|
341
351
|
Optional. A list of unique safety settings for blocking unsafe content.
|
342
352
|
*/
|
343
|
-
safetySettings:
|
344
|
-
|
345
|
-
category:
|
353
|
+
safetySettings: z2.array(
|
354
|
+
z2.object({
|
355
|
+
category: z2.enum([
|
346
356
|
"HARM_CATEGORY_UNSPECIFIED",
|
347
357
|
"HARM_CATEGORY_HATE_SPEECH",
|
348
358
|
"HARM_CATEGORY_DANGEROUS_CONTENT",
|
@@ -350,7 +360,7 @@ var googleGenerativeAIProviderOptions = import_v42.z.object({
|
|
350
360
|
"HARM_CATEGORY_SEXUALLY_EXPLICIT",
|
351
361
|
"HARM_CATEGORY_CIVIC_INTEGRITY"
|
352
362
|
]),
|
353
|
-
threshold:
|
363
|
+
threshold: z2.enum([
|
354
364
|
"HARM_BLOCK_THRESHOLD_UNSPECIFIED",
|
355
365
|
"BLOCK_LOW_AND_ABOVE",
|
356
366
|
"BLOCK_MEDIUM_AND_ABOVE",
|
@@ -360,7 +370,7 @@ var googleGenerativeAIProviderOptions = import_v42.z.object({
|
|
360
370
|
])
|
361
371
|
})
|
362
372
|
).optional(),
|
363
|
-
threshold:
|
373
|
+
threshold: z2.enum([
|
364
374
|
"HARM_BLOCK_THRESHOLD_UNSPECIFIED",
|
365
375
|
"BLOCK_LOW_AND_ABOVE",
|
366
376
|
"BLOCK_MEDIUM_AND_ABOVE",
|
@@ -373,19 +383,19 @@ var googleGenerativeAIProviderOptions = import_v42.z.object({
|
|
373
383
|
*
|
374
384
|
* https://cloud.google.com/vertex-ai/generative-ai/docs/multimodal/audio-understanding
|
375
385
|
*/
|
376
|
-
audioTimestamp:
|
386
|
+
audioTimestamp: z2.boolean().optional(),
|
377
387
|
/**
|
378
388
|
* Optional. Defines labels used in billing reports. Available on Vertex AI only.
|
379
389
|
*
|
380
390
|
* https://cloud.google.com/vertex-ai/generative-ai/docs/multimodal/add-labels-to-api-calls
|
381
391
|
*/
|
382
|
-
labels:
|
392
|
+
labels: z2.record(z2.string(), z2.string()).optional(),
|
383
393
|
/**
|
384
394
|
* Optional. If specified, the media resolution specified will be used.
|
385
395
|
*
|
386
396
|
* https://ai.google.dev/api/generate-content#MediaResolution
|
387
397
|
*/
|
388
|
-
mediaResolution:
|
398
|
+
mediaResolution: z2.enum([
|
389
399
|
"MEDIA_RESOLUTION_UNSPECIFIED",
|
390
400
|
"MEDIA_RESOLUTION_LOW",
|
391
401
|
"MEDIA_RESOLUTION_MEDIUM",
|
@@ -403,7 +413,12 @@ function prepareTools({
|
|
403
413
|
var _a;
|
404
414
|
tools = (tools == null ? void 0 : tools.length) ? tools : void 0;
|
405
415
|
const toolWarnings = [];
|
406
|
-
const
|
416
|
+
const isLatest = [
|
417
|
+
"gemini-flash-latest",
|
418
|
+
"gemini-flash-lite-latest",
|
419
|
+
"gemini-pro-latest"
|
420
|
+
].some((id) => id === modelId);
|
421
|
+
const isGemini2 = modelId.includes("gemini-2") || isLatest;
|
407
422
|
const supportsDynamicRetrieval = modelId.includes("gemini-1.5-flash") && !modelId.includes("-8b");
|
408
423
|
if (tools == null) {
|
409
424
|
return { tools: void 0, toolConfig: void 0, toolWarnings };
|
@@ -564,60 +579,60 @@ function mapGoogleGenerativeAIFinishReason({
|
|
564
579
|
|
565
580
|
// src/tool/google-search.ts
|
566
581
|
var import_provider_utils3 = require("@ai-sdk/provider-utils");
|
567
|
-
var
|
568
|
-
var groundingChunkSchema =
|
569
|
-
web:
|
570
|
-
retrievedContext:
|
582
|
+
var z3 = __toESM(require("zod/v4"));
|
583
|
+
var groundingChunkSchema = z3.object({
|
584
|
+
web: z3.object({ uri: z3.string(), title: z3.string() }).nullish(),
|
585
|
+
retrievedContext: z3.object({ uri: z3.string(), title: z3.string() }).nullish()
|
571
586
|
});
|
572
|
-
var groundingMetadataSchema =
|
573
|
-
webSearchQueries:
|
574
|
-
retrievalQueries:
|
575
|
-
searchEntryPoint:
|
576
|
-
groundingChunks:
|
577
|
-
groundingSupports:
|
578
|
-
|
579
|
-
segment:
|
580
|
-
startIndex:
|
581
|
-
endIndex:
|
582
|
-
text:
|
587
|
+
var groundingMetadataSchema = z3.object({
|
588
|
+
webSearchQueries: z3.array(z3.string()).nullish(),
|
589
|
+
retrievalQueries: z3.array(z3.string()).nullish(),
|
590
|
+
searchEntryPoint: z3.object({ renderedContent: z3.string() }).nullish(),
|
591
|
+
groundingChunks: z3.array(groundingChunkSchema).nullish(),
|
592
|
+
groundingSupports: z3.array(
|
593
|
+
z3.object({
|
594
|
+
segment: z3.object({
|
595
|
+
startIndex: z3.number().nullish(),
|
596
|
+
endIndex: z3.number().nullish(),
|
597
|
+
text: z3.string().nullish()
|
583
598
|
}),
|
584
|
-
segment_text:
|
585
|
-
groundingChunkIndices:
|
586
|
-
supportChunkIndices:
|
587
|
-
confidenceScores:
|
588
|
-
confidenceScore:
|
599
|
+
segment_text: z3.string().nullish(),
|
600
|
+
groundingChunkIndices: z3.array(z3.number()).nullish(),
|
601
|
+
supportChunkIndices: z3.array(z3.number()).nullish(),
|
602
|
+
confidenceScores: z3.array(z3.number()).nullish(),
|
603
|
+
confidenceScore: z3.array(z3.number()).nullish()
|
589
604
|
})
|
590
605
|
).nullish(),
|
591
|
-
retrievalMetadata:
|
592
|
-
|
593
|
-
webDynamicRetrievalScore:
|
606
|
+
retrievalMetadata: z3.union([
|
607
|
+
z3.object({
|
608
|
+
webDynamicRetrievalScore: z3.number()
|
594
609
|
}),
|
595
|
-
|
610
|
+
z3.object({})
|
596
611
|
]).nullish()
|
597
612
|
});
|
598
613
|
var googleSearch = (0, import_provider_utils3.createProviderDefinedToolFactory)({
|
599
614
|
id: "google.google_search",
|
600
615
|
name: "google_search",
|
601
|
-
inputSchema:
|
602
|
-
mode:
|
603
|
-
dynamicThreshold:
|
616
|
+
inputSchema: z3.object({
|
617
|
+
mode: z3.enum(["MODE_DYNAMIC", "MODE_UNSPECIFIED"]).default("MODE_UNSPECIFIED"),
|
618
|
+
dynamicThreshold: z3.number().default(1)
|
604
619
|
})
|
605
620
|
});
|
606
621
|
|
607
622
|
// src/tool/url-context.ts
|
608
623
|
var import_provider_utils4 = require("@ai-sdk/provider-utils");
|
609
|
-
var
|
610
|
-
var urlMetadataSchema =
|
611
|
-
retrievedUrl:
|
612
|
-
urlRetrievalStatus:
|
624
|
+
var z4 = __toESM(require("zod/v4"));
|
625
|
+
var urlMetadataSchema = z4.object({
|
626
|
+
retrievedUrl: z4.string(),
|
627
|
+
urlRetrievalStatus: z4.string()
|
613
628
|
});
|
614
|
-
var urlContextMetadataSchema =
|
615
|
-
urlMetadata:
|
629
|
+
var urlContextMetadataSchema = z4.object({
|
630
|
+
urlMetadata: z4.array(urlMetadataSchema)
|
616
631
|
});
|
617
632
|
var urlContext = (0, import_provider_utils4.createProviderDefinedToolFactory)({
|
618
633
|
id: "google.url_context",
|
619
634
|
name: "url_context",
|
620
|
-
inputSchema:
|
635
|
+
inputSchema: z4.object({})
|
621
636
|
});
|
622
637
|
|
623
638
|
// src/google-generative-ai-language-model.ts
|
@@ -1115,100 +1130,100 @@ function extractSources({
|
|
1115
1130
|
title: chunk.web.title
|
1116
1131
|
}));
|
1117
1132
|
}
|
1118
|
-
var contentSchema =
|
1119
|
-
parts:
|
1120
|
-
|
1133
|
+
var contentSchema = z5.object({
|
1134
|
+
parts: z5.array(
|
1135
|
+
z5.union([
|
1121
1136
|
// note: order matters since text can be fully empty
|
1122
|
-
|
1123
|
-
functionCall:
|
1124
|
-
name:
|
1125
|
-
args:
|
1137
|
+
z5.object({
|
1138
|
+
functionCall: z5.object({
|
1139
|
+
name: z5.string(),
|
1140
|
+
args: z5.unknown()
|
1126
1141
|
}),
|
1127
|
-
thoughtSignature:
|
1142
|
+
thoughtSignature: z5.string().nullish()
|
1128
1143
|
}),
|
1129
|
-
|
1130
|
-
inlineData:
|
1131
|
-
mimeType:
|
1132
|
-
data:
|
1144
|
+
z5.object({
|
1145
|
+
inlineData: z5.object({
|
1146
|
+
mimeType: z5.string(),
|
1147
|
+
data: z5.string()
|
1133
1148
|
})
|
1134
1149
|
}),
|
1135
|
-
|
1136
|
-
executableCode:
|
1137
|
-
language:
|
1138
|
-
code:
|
1150
|
+
z5.object({
|
1151
|
+
executableCode: z5.object({
|
1152
|
+
language: z5.string(),
|
1153
|
+
code: z5.string()
|
1139
1154
|
}).nullish(),
|
1140
|
-
codeExecutionResult:
|
1141
|
-
outcome:
|
1142
|
-
output:
|
1155
|
+
codeExecutionResult: z5.object({
|
1156
|
+
outcome: z5.string(),
|
1157
|
+
output: z5.string()
|
1143
1158
|
}).nullish(),
|
1144
|
-
text:
|
1145
|
-
thought:
|
1146
|
-
thoughtSignature:
|
1159
|
+
text: z5.string().nullish(),
|
1160
|
+
thought: z5.boolean().nullish(),
|
1161
|
+
thoughtSignature: z5.string().nullish()
|
1147
1162
|
})
|
1148
1163
|
])
|
1149
1164
|
).nullish()
|
1150
1165
|
});
|
1151
|
-
var safetyRatingSchema =
|
1152
|
-
category:
|
1153
|
-
probability:
|
1154
|
-
probabilityScore:
|
1155
|
-
severity:
|
1156
|
-
severityScore:
|
1157
|
-
blocked:
|
1166
|
+
var safetyRatingSchema = z5.object({
|
1167
|
+
category: z5.string().nullish(),
|
1168
|
+
probability: z5.string().nullish(),
|
1169
|
+
probabilityScore: z5.number().nullish(),
|
1170
|
+
severity: z5.string().nullish(),
|
1171
|
+
severityScore: z5.number().nullish(),
|
1172
|
+
blocked: z5.boolean().nullish()
|
1158
1173
|
});
|
1159
|
-
var usageSchema =
|
1160
|
-
cachedContentTokenCount:
|
1161
|
-
thoughtsTokenCount:
|
1162
|
-
promptTokenCount:
|
1163
|
-
candidatesTokenCount:
|
1164
|
-
totalTokenCount:
|
1174
|
+
var usageSchema = z5.object({
|
1175
|
+
cachedContentTokenCount: z5.number().nullish(),
|
1176
|
+
thoughtsTokenCount: z5.number().nullish(),
|
1177
|
+
promptTokenCount: z5.number().nullish(),
|
1178
|
+
candidatesTokenCount: z5.number().nullish(),
|
1179
|
+
totalTokenCount: z5.number().nullish()
|
1165
1180
|
});
|
1166
|
-
var responseSchema =
|
1167
|
-
candidates:
|
1168
|
-
|
1169
|
-
content: contentSchema.nullish().or(
|
1170
|
-
finishReason:
|
1171
|
-
safetyRatings:
|
1181
|
+
var responseSchema = z5.object({
|
1182
|
+
candidates: z5.array(
|
1183
|
+
z5.object({
|
1184
|
+
content: contentSchema.nullish().or(z5.object({}).strict()),
|
1185
|
+
finishReason: z5.string().nullish(),
|
1186
|
+
safetyRatings: z5.array(safetyRatingSchema).nullish(),
|
1172
1187
|
groundingMetadata: groundingMetadataSchema.nullish(),
|
1173
1188
|
urlContextMetadata: urlContextMetadataSchema.nullish()
|
1174
1189
|
})
|
1175
1190
|
),
|
1176
1191
|
usageMetadata: usageSchema.nullish(),
|
1177
|
-
promptFeedback:
|
1178
|
-
blockReason:
|
1179
|
-
safetyRatings:
|
1192
|
+
promptFeedback: z5.object({
|
1193
|
+
blockReason: z5.string().nullish(),
|
1194
|
+
safetyRatings: z5.array(safetyRatingSchema).nullish()
|
1180
1195
|
}).nullish()
|
1181
1196
|
});
|
1182
|
-
var chunkSchema =
|
1183
|
-
candidates:
|
1184
|
-
|
1197
|
+
var chunkSchema = z5.object({
|
1198
|
+
candidates: z5.array(
|
1199
|
+
z5.object({
|
1185
1200
|
content: contentSchema.nullish(),
|
1186
|
-
finishReason:
|
1187
|
-
safetyRatings:
|
1201
|
+
finishReason: z5.string().nullish(),
|
1202
|
+
safetyRatings: z5.array(safetyRatingSchema).nullish(),
|
1188
1203
|
groundingMetadata: groundingMetadataSchema.nullish(),
|
1189
1204
|
urlContextMetadata: urlContextMetadataSchema.nullish()
|
1190
1205
|
})
|
1191
1206
|
).nullish(),
|
1192
1207
|
usageMetadata: usageSchema.nullish(),
|
1193
|
-
promptFeedback:
|
1194
|
-
blockReason:
|
1195
|
-
safetyRatings:
|
1208
|
+
promptFeedback: z5.object({
|
1209
|
+
blockReason: z5.string().nullish(),
|
1210
|
+
safetyRatings: z5.array(safetyRatingSchema).nullish()
|
1196
1211
|
}).nullish()
|
1197
1212
|
});
|
1198
1213
|
|
1199
1214
|
// src/tool/code-execution.ts
|
1200
1215
|
var import_provider_utils6 = require("@ai-sdk/provider-utils");
|
1201
|
-
var
|
1216
|
+
var z6 = __toESM(require("zod/v4"));
|
1202
1217
|
var codeExecution = (0, import_provider_utils6.createProviderDefinedToolFactoryWithOutputSchema)({
|
1203
1218
|
id: "google.code_execution",
|
1204
1219
|
name: "code_execution",
|
1205
|
-
inputSchema:
|
1206
|
-
language:
|
1207
|
-
code:
|
1220
|
+
inputSchema: z6.object({
|
1221
|
+
language: z6.string().describe("The programming language of the code."),
|
1222
|
+
code: z6.string().describe("The code to be executed.")
|
1208
1223
|
}),
|
1209
|
-
outputSchema:
|
1210
|
-
outcome:
|
1211
|
-
output:
|
1224
|
+
outputSchema: z6.object({
|
1225
|
+
outcome: z6.string().describe('The outcome of the execution (e.g., "OUTCOME_OK").'),
|
1226
|
+
output: z6.string().describe("The output from the code execution.")
|
1212
1227
|
})
|
1213
1228
|
});
|
1214
1229
|
|