@ai-sdk/google 3.0.135 → 3.0.137
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 +15 -0
- package/dist/index.d.mts +10 -11
- package/dist/index.d.ts +10 -11
- package/dist/index.js +291 -256
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +201 -161
- package/dist/index.mjs.map +1 -1
- package/dist/internal/index.js +62 -40
- package/dist/internal/index.js.map +1 -1
- package/dist/internal/index.mjs +62 -40
- package/dist/internal/index.mjs.map +1 -1
- package/docs/15-google-generative-ai.mdx +8 -0
- package/package.json +2 -2
- package/src/google-generative-ai-embedding-options.ts +15 -14
- package/src/google-generative-ai-image-model.ts +1 -1
- package/src/google-generative-ai-language-model.ts +73 -42
- package/src/google-generative-ai-prompt.ts +2 -0
- package/src/google-generative-ai-video-model.ts +30 -26
- package/src/tool/file-search.ts +33 -30
- package/src/tool/google-search.ts +19 -18
- package/src/transcription/google-transcription-model-options.ts +40 -31
- package/src/transcription/google-transcription-model.ts +37 -30
package/dist/index.js
CHANGED
|
@@ -29,7 +29,7 @@ module.exports = __toCommonJS(index_exports);
|
|
|
29
29
|
|
|
30
30
|
// src/transcription/google-transcription-model.ts
|
|
31
31
|
var import_provider = require("@ai-sdk/provider");
|
|
32
|
-
var
|
|
32
|
+
var import_provider_utils3 = require("@ai-sdk/provider-utils");
|
|
33
33
|
var import_v43 = require("zod/v4");
|
|
34
34
|
|
|
35
35
|
// src/google-error.ts
|
|
@@ -53,37 +53,42 @@ var googleFailedResponseHandler = (0, import_provider_utils.createJsonErrorRespo
|
|
|
53
53
|
});
|
|
54
54
|
|
|
55
55
|
// src/transcription/google-transcription-model-options.ts
|
|
56
|
+
var import_provider_utils2 = require("@ai-sdk/provider-utils");
|
|
56
57
|
var import_v42 = require("zod/v4");
|
|
57
|
-
var googleTranscriptionModelOptions =
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
58
|
+
var googleTranscriptionModelOptions = (0, import_provider_utils2.lazySchema)(
|
|
59
|
+
() => (0, import_provider_utils2.zodSchema)(
|
|
60
|
+
import_v42.z.object({
|
|
61
|
+
/**
|
|
62
|
+
* BCP-47 language codes providing hints about the languages present in the
|
|
63
|
+
* audio. If omitted or empty, defaults to automatic language detection.
|
|
64
|
+
*/
|
|
65
|
+
languageCodes: import_v42.z.array(import_v42.z.string()).optional(),
|
|
66
|
+
/**
|
|
67
|
+
* Custom vocabulary phrases, which bias the speech recognition model
|
|
68
|
+
* toward recognizing specific terms.
|
|
69
|
+
*/
|
|
70
|
+
customVocabulary: import_v42.z.array(import_v42.z.string()).optional(),
|
|
71
|
+
/**
|
|
72
|
+
* Enables word-level timestamp generation.
|
|
73
|
+
*/
|
|
74
|
+
wordTimestamp: import_v42.z.boolean().optional(),
|
|
75
|
+
/**
|
|
76
|
+
* Enables speaker diarization.
|
|
77
|
+
*/
|
|
78
|
+
diarization: import_v42.z.boolean().optional(),
|
|
79
|
+
/**
|
|
80
|
+
* Transcription output formatting mode.
|
|
81
|
+
*
|
|
82
|
+
* - `VERBATIM` (default): exact literal transcript preserving filler
|
|
83
|
+
* words, repetitions, and false starts.
|
|
84
|
+
* - `SMART`: cleans up and structures the transcript in real time —
|
|
85
|
+
* disfluency removal, inline self-corrections, structured formatting
|
|
86
|
+
* (lists, numbers, dates, paragraph breaks), and grammar/casing polish.
|
|
87
|
+
*/
|
|
88
|
+
mode: import_v42.z.enum(["SMART", "VERBATIM"]).optional()
|
|
89
|
+
})
|
|
90
|
+
)
|
|
91
|
+
);
|
|
87
92
|
|
|
88
93
|
// src/transcription/google-transcription-model.ts
|
|
89
94
|
function isLiveTranscriptionModelId(modelId) {
|
|
@@ -99,7 +104,7 @@ var GoogleTranscriptionModel = class {
|
|
|
99
104
|
return this.config.provider;
|
|
100
105
|
}
|
|
101
106
|
async parseOptions(providerOptions) {
|
|
102
|
-
return (0,
|
|
107
|
+
return (0, import_provider_utils3.parseProviderOptions)({
|
|
103
108
|
provider: "google",
|
|
104
109
|
providerOptions,
|
|
105
110
|
schema: googleTranscriptionModelOptions
|
|
@@ -122,7 +127,7 @@ var GoogleTranscriptionModel = class {
|
|
|
122
127
|
input: [
|
|
123
128
|
{
|
|
124
129
|
type: "audio",
|
|
125
|
-
data: (0,
|
|
130
|
+
data: (0, import_provider_utils3.convertToBase64)(options.audio),
|
|
126
131
|
mime_type: options.mediaType
|
|
127
132
|
}
|
|
128
133
|
],
|
|
@@ -132,15 +137,15 @@ var GoogleTranscriptionModel = class {
|
|
|
132
137
|
value: response,
|
|
133
138
|
responseHeaders,
|
|
134
139
|
rawValue: rawResponse
|
|
135
|
-
} = await (0,
|
|
140
|
+
} = await (0, import_provider_utils3.postJsonToApi)({
|
|
136
141
|
url: `${this.config.baseURL}/interactions`,
|
|
137
|
-
headers: (0,
|
|
138
|
-
this.config.headers ? await (0,
|
|
142
|
+
headers: (0, import_provider_utils3.combineHeaders)(
|
|
143
|
+
this.config.headers ? await (0, import_provider_utils3.resolve)(this.config.headers) : void 0,
|
|
139
144
|
options.headers
|
|
140
145
|
),
|
|
141
146
|
body: requestBody,
|
|
142
147
|
failedResponseHandler: googleFailedResponseHandler,
|
|
143
|
-
successfulResponseHandler: (0,
|
|
148
|
+
successfulResponseHandler: (0, import_provider_utils3.createJsonResponseHandler)(
|
|
144
149
|
googleInteractionsTranscriptionResponseSchema
|
|
145
150
|
),
|
|
146
151
|
abortSignal: options.abortSignal,
|
|
@@ -207,45 +212,49 @@ function parseOffsetSeconds(offset) {
|
|
|
207
212
|
const parsed = Number.parseFloat(offset);
|
|
208
213
|
return Number.isFinite(parsed) ? parsed : void 0;
|
|
209
214
|
}
|
|
210
|
-
var googleInteractionsWordAnnotationSchema = import_v43.z.object({
|
|
215
|
+
var googleInteractionsWordAnnotationSchema = () => import_v43.z.object({
|
|
211
216
|
type: import_v43.z.string().nullish(),
|
|
212
217
|
text: import_v43.z.string().nullish(),
|
|
213
218
|
speaker: import_v43.z.string().nullish(),
|
|
214
219
|
start_offset: import_v43.z.string().nullish(),
|
|
215
220
|
end_offset: import_v43.z.string().nullish()
|
|
216
221
|
});
|
|
217
|
-
var googleInteractionsTranscriptionResponseSchema =
|
|
218
|
-
|
|
219
|
-
steps: import_v43.z.array(
|
|
222
|
+
var googleInteractionsTranscriptionResponseSchema = (0, import_provider_utils3.lazySchema)(
|
|
223
|
+
() => (0, import_provider_utils3.zodSchema)(
|
|
220
224
|
import_v43.z.object({
|
|
221
|
-
|
|
222
|
-
|
|
225
|
+
status: import_v43.z.string().nullish(),
|
|
226
|
+
steps: import_v43.z.array(
|
|
223
227
|
import_v43.z.object({
|
|
224
228
|
type: import_v43.z.string().nullish(),
|
|
225
|
-
|
|
226
|
-
|
|
229
|
+
content: import_v43.z.array(
|
|
230
|
+
import_v43.z.object({
|
|
231
|
+
type: import_v43.z.string().nullish(),
|
|
232
|
+
text: import_v43.z.string().nullish(),
|
|
233
|
+
annotations: import_v43.z.array(googleInteractionsWordAnnotationSchema()).nullish()
|
|
234
|
+
})
|
|
235
|
+
).nullish()
|
|
227
236
|
})
|
|
228
|
-
).nullish()
|
|
237
|
+
).nullish(),
|
|
238
|
+
usage: import_v43.z.record(import_v43.z.string(), import_v43.z.unknown()).nullish()
|
|
229
239
|
})
|
|
230
|
-
)
|
|
231
|
-
|
|
232
|
-
});
|
|
240
|
+
)
|
|
241
|
+
);
|
|
233
242
|
|
|
234
243
|
// src/google-provider.ts
|
|
235
|
-
var
|
|
244
|
+
var import_provider_utils26 = require("@ai-sdk/provider-utils");
|
|
236
245
|
|
|
237
246
|
// src/version.ts
|
|
238
|
-
var VERSION = true ? "3.0.
|
|
247
|
+
var VERSION = true ? "3.0.137" : "0.0.0-test";
|
|
239
248
|
|
|
240
249
|
// src/google-generative-ai-embedding-model.ts
|
|
241
250
|
var import_provider2 = require("@ai-sdk/provider");
|
|
242
|
-
var
|
|
251
|
+
var import_provider_utils5 = require("@ai-sdk/provider-utils");
|
|
243
252
|
var import_v45 = require("zod/v4");
|
|
244
253
|
|
|
245
254
|
// src/google-generative-ai-embedding-options.ts
|
|
246
|
-
var
|
|
255
|
+
var import_provider_utils4 = require("@ai-sdk/provider-utils");
|
|
247
256
|
var import_v44 = require("zod/v4");
|
|
248
|
-
var googleEmbeddingContentPartSchema = import_v44.z.union([
|
|
257
|
+
var googleEmbeddingContentPartSchema = () => import_v44.z.union([
|
|
249
258
|
import_v44.z.object({ text: import_v44.z.string() }),
|
|
250
259
|
import_v44.z.object({
|
|
251
260
|
inlineData: import_v44.z.object({
|
|
@@ -260,8 +269,8 @@ var googleEmbeddingContentPartSchema = import_v44.z.union([
|
|
|
260
269
|
})
|
|
261
270
|
})
|
|
262
271
|
]);
|
|
263
|
-
var googleEmbeddingModelOptions = (0,
|
|
264
|
-
() => (0,
|
|
272
|
+
var googleEmbeddingModelOptions = (0, import_provider_utils4.lazySchema)(
|
|
273
|
+
() => (0, import_provider_utils4.zodSchema)(
|
|
265
274
|
import_v44.z.object({
|
|
266
275
|
/**
|
|
267
276
|
* Optional. Optional reduced dimension for the output embedding.
|
|
@@ -299,14 +308,14 @@ var googleEmbeddingModelOptions = (0, import_provider_utils3.lazySchema)(
|
|
|
299
308
|
* The array length must match the number of values being embedded. In
|
|
300
309
|
* the case of a single embedding, the array length must be 1.
|
|
301
310
|
*/
|
|
302
|
-
content: import_v44.z.array(import_v44.z.array(googleEmbeddingContentPartSchema).min(1).nullable()).optional()
|
|
311
|
+
content: import_v44.z.array(import_v44.z.array(googleEmbeddingContentPartSchema()).min(1).nullable()).optional()
|
|
303
312
|
})
|
|
304
313
|
)
|
|
305
314
|
);
|
|
306
315
|
|
|
307
316
|
// src/google-generative-ai-embedding-model.ts
|
|
308
317
|
var _a;
|
|
309
|
-
_a =
|
|
318
|
+
_a = import_provider_utils5.EXPERIMENTAL_EMBEDDING_MODEL_PROVIDER_OPTIONS_TRANSFORMER;
|
|
310
319
|
var GoogleGenerativeAIEmbeddingModel = class {
|
|
311
320
|
constructor(modelId, config) {
|
|
312
321
|
this.specificationVersion = "v3";
|
|
@@ -342,7 +351,7 @@ var GoogleGenerativeAIEmbeddingModel = class {
|
|
|
342
351
|
abortSignal,
|
|
343
352
|
providerOptions
|
|
344
353
|
}) {
|
|
345
|
-
const googleOptions = await (0,
|
|
354
|
+
const googleOptions = await (0, import_provider_utils5.parseProviderOptions)({
|
|
346
355
|
provider: "google",
|
|
347
356
|
providerOptions,
|
|
348
357
|
schema: googleEmbeddingModelOptions
|
|
@@ -355,8 +364,8 @@ var GoogleGenerativeAIEmbeddingModel = class {
|
|
|
355
364
|
values
|
|
356
365
|
});
|
|
357
366
|
}
|
|
358
|
-
const mergedHeaders = (0,
|
|
359
|
-
await (0,
|
|
367
|
+
const mergedHeaders = (0, import_provider_utils5.combineHeaders)(
|
|
368
|
+
await (0, import_provider_utils5.resolve)(this.config.headers),
|
|
360
369
|
headers
|
|
361
370
|
);
|
|
362
371
|
const multimodalContent = googleOptions == null ? void 0 : googleOptions.content;
|
|
@@ -369,7 +378,7 @@ var GoogleGenerativeAIEmbeddingModel = class {
|
|
|
369
378
|
responseHeaders: responseHeaders2,
|
|
370
379
|
value: response2,
|
|
371
380
|
rawValue: rawValue2
|
|
372
|
-
} = await (0,
|
|
381
|
+
} = await (0, import_provider_utils5.postJsonToApi)({
|
|
373
382
|
url: `${this.config.baseURL}/models/${this.modelId}:embedContent`,
|
|
374
383
|
headers: mergedHeaders,
|
|
375
384
|
body: {
|
|
@@ -381,7 +390,7 @@ var GoogleGenerativeAIEmbeddingModel = class {
|
|
|
381
390
|
taskType: googleOptions == null ? void 0 : googleOptions.taskType
|
|
382
391
|
},
|
|
383
392
|
failedResponseHandler: googleFailedResponseHandler,
|
|
384
|
-
successfulResponseHandler: (0,
|
|
393
|
+
successfulResponseHandler: (0, import_provider_utils5.createJsonResponseHandler)(
|
|
385
394
|
googleGenerativeAISingleEmbeddingResponseSchema
|
|
386
395
|
),
|
|
387
396
|
abortSignal,
|
|
@@ -398,7 +407,7 @@ var GoogleGenerativeAIEmbeddingModel = class {
|
|
|
398
407
|
responseHeaders,
|
|
399
408
|
value: response,
|
|
400
409
|
rawValue
|
|
401
|
-
} = await (0,
|
|
410
|
+
} = await (0, import_provider_utils5.postJsonToApi)({
|
|
402
411
|
url: `${this.config.baseURL}/models/${this.modelId}:batchEmbedContents`,
|
|
403
412
|
headers: mergedHeaders,
|
|
404
413
|
body: {
|
|
@@ -417,7 +426,7 @@ var GoogleGenerativeAIEmbeddingModel = class {
|
|
|
417
426
|
})
|
|
418
427
|
},
|
|
419
428
|
failedResponseHandler: googleFailedResponseHandler,
|
|
420
|
-
successfulResponseHandler: (0,
|
|
429
|
+
successfulResponseHandler: (0, import_provider_utils5.createJsonResponseHandler)(
|
|
421
430
|
googleGenerativeAITextEmbeddingResponseSchema
|
|
422
431
|
),
|
|
423
432
|
abortSignal,
|
|
@@ -431,15 +440,15 @@ var GoogleGenerativeAIEmbeddingModel = class {
|
|
|
431
440
|
};
|
|
432
441
|
}
|
|
433
442
|
};
|
|
434
|
-
var googleGenerativeAITextEmbeddingResponseSchema = (0,
|
|
435
|
-
() => (0,
|
|
443
|
+
var googleGenerativeAITextEmbeddingResponseSchema = (0, import_provider_utils5.lazySchema)(
|
|
444
|
+
() => (0, import_provider_utils5.zodSchema)(
|
|
436
445
|
import_v45.z.object({
|
|
437
446
|
embeddings: import_v45.z.array(import_v45.z.object({ values: import_v45.z.array(import_v45.z.number()) }))
|
|
438
447
|
})
|
|
439
448
|
)
|
|
440
449
|
);
|
|
441
|
-
var googleGenerativeAISingleEmbeddingResponseSchema = (0,
|
|
442
|
-
() => (0,
|
|
450
|
+
var googleGenerativeAISingleEmbeddingResponseSchema = (0, import_provider_utils5.lazySchema)(
|
|
451
|
+
() => (0, import_provider_utils5.zodSchema)(
|
|
443
452
|
import_v45.z.object({
|
|
444
453
|
embedding: import_v45.z.object({ values: import_v45.z.array(import_v45.z.number()) })
|
|
445
454
|
})
|
|
@@ -457,7 +466,7 @@ function validateMultimodalContentLength({
|
|
|
457
466
|
}
|
|
458
467
|
|
|
459
468
|
// src/google-generative-ai-language-model.ts
|
|
460
|
-
var
|
|
469
|
+
var import_provider_utils9 = require("@ai-sdk/provider-utils");
|
|
461
470
|
var import_v47 = require("zod/v4");
|
|
462
471
|
|
|
463
472
|
// src/continue-google-stream.ts
|
|
@@ -875,7 +884,7 @@ function isEmptyObjectSchema(jsonSchema) {
|
|
|
875
884
|
|
|
876
885
|
// src/convert-to-google-generative-ai-messages.ts
|
|
877
886
|
var import_provider4 = require("@ai-sdk/provider");
|
|
878
|
-
var
|
|
887
|
+
var import_provider_utils6 = require("@ai-sdk/provider-utils");
|
|
879
888
|
var SKIP_THOUGHT_SIGNATURE_VALIDATOR = "skip_thought_signature_validator";
|
|
880
889
|
function getGoogleProviderOptions(providerOptions, providerOptionsName) {
|
|
881
890
|
const namespaces = [
|
|
@@ -914,7 +923,7 @@ function convertUrlToolResultPart(url, mediaType, supportedFunctionResponseUrls)
|
|
|
914
923
|
}
|
|
915
924
|
};
|
|
916
925
|
}
|
|
917
|
-
return mediaType != null && (0,
|
|
926
|
+
return mediaType != null && (0, import_provider_utils6.isUrlSupported)({
|
|
918
927
|
url,
|
|
919
928
|
mediaType,
|
|
920
929
|
supportedUrls: supportedFunctionResponseUrls
|
|
@@ -1063,7 +1072,7 @@ function convertToGoogleGenerativeAIMessages(prompt, options) {
|
|
|
1063
1072
|
} : {
|
|
1064
1073
|
inlineData: {
|
|
1065
1074
|
mimeType: mediaType,
|
|
1066
|
-
data: (0,
|
|
1075
|
+
data: (0, import_provider_utils6.convertToBase64)(part.data)
|
|
1067
1076
|
}
|
|
1068
1077
|
}
|
|
1069
1078
|
);
|
|
@@ -1108,7 +1117,7 @@ function convertToGoogleGenerativeAIMessages(prompt, options) {
|
|
|
1108
1117
|
return {
|
|
1109
1118
|
inlineData: {
|
|
1110
1119
|
mimeType: part.mediaType,
|
|
1111
|
-
data: (0,
|
|
1120
|
+
data: (0, import_provider_utils6.convertToBase64)(part.data)
|
|
1112
1121
|
},
|
|
1113
1122
|
...(providerOpts == null ? void 0 : providerOpts.thought) === true ? { thought: true } : {},
|
|
1114
1123
|
thoughtSignature
|
|
@@ -1133,7 +1142,7 @@ function convertToGoogleGenerativeAIMessages(prompt, options) {
|
|
|
1133
1142
|
return {
|
|
1134
1143
|
toolCall: {
|
|
1135
1144
|
toolType: serverToolType,
|
|
1136
|
-
args: typeof part.input === "string" ? (0,
|
|
1145
|
+
args: typeof part.input === "string" ? (0, import_provider_utils6.secureJsonParse)(part.input) : part.input,
|
|
1137
1146
|
id: serverToolCallId
|
|
1138
1147
|
},
|
|
1139
1148
|
thoughtSignature: effectiveThoughtSignature
|
|
@@ -1257,7 +1266,7 @@ function convertToGoogleGenerativeAIMessages(prompt, options) {
|
|
|
1257
1266
|
}
|
|
1258
1267
|
|
|
1259
1268
|
// src/download-tool-result-files.ts
|
|
1260
|
-
var
|
|
1269
|
+
var import_provider_utils7 = require("@ai-sdk/provider-utils");
|
|
1261
1270
|
async function downloadToolResultFiles(prompt, {
|
|
1262
1271
|
abortSignal,
|
|
1263
1272
|
supportedUrls = {}
|
|
@@ -1274,17 +1283,17 @@ async function downloadToolResultFiles(prompt, {
|
|
|
1274
1283
|
if (part.type !== "file-url" && part.type !== "image-url") {
|
|
1275
1284
|
return part;
|
|
1276
1285
|
}
|
|
1277
|
-
if (part.type === "file-url" && part.mediaType != null && (0,
|
|
1286
|
+
if (part.type === "file-url" && part.mediaType != null && (0, import_provider_utils7.isUrlSupported)({
|
|
1278
1287
|
url: part.url,
|
|
1279
1288
|
mediaType: part.mediaType,
|
|
1280
1289
|
supportedUrls
|
|
1281
1290
|
})) {
|
|
1282
1291
|
return part;
|
|
1283
1292
|
}
|
|
1284
|
-
const blob = await (0,
|
|
1293
|
+
const blob = await (0, import_provider_utils7.downloadBlob)(part.url, { abortSignal });
|
|
1285
1294
|
return {
|
|
1286
1295
|
type: part.type === "file-url" ? "file-data" : "image-data",
|
|
1287
|
-
data: (0,
|
|
1296
|
+
data: (0, import_provider_utils7.convertUint8ArrayToBase64)(
|
|
1288
1297
|
new Uint8Array(await blob.arrayBuffer())
|
|
1289
1298
|
),
|
|
1290
1299
|
mediaType: blob.type || (part.type === "file-url" ? (_a2 = part.mediaType) != null ? _a2 : "application/octet-stream" : "image/*"),
|
|
@@ -1328,10 +1337,10 @@ function getModelPath(modelId) {
|
|
|
1328
1337
|
}
|
|
1329
1338
|
|
|
1330
1339
|
// src/google-generative-ai-options.ts
|
|
1331
|
-
var
|
|
1340
|
+
var import_provider_utils8 = require("@ai-sdk/provider-utils");
|
|
1332
1341
|
var import_v46 = require("zod/v4");
|
|
1333
|
-
var googleLanguageModelOptions = (0,
|
|
1334
|
-
() => (0,
|
|
1342
|
+
var googleLanguageModelOptions = (0, import_provider_utils8.lazySchema)(
|
|
1343
|
+
() => (0, import_provider_utils8.zodSchema)(
|
|
1335
1344
|
import_v46.z.object({
|
|
1336
1345
|
responseModalities: import_v46.z.array(import_v46.z.enum(["TEXT", "IMAGE"])).optional(),
|
|
1337
1346
|
thinkingConfig: import_v46.z.object({
|
|
@@ -2091,7 +2100,7 @@ var GoogleGenerativeAILanguageModel = class {
|
|
|
2091
2100
|
var _a2;
|
|
2092
2101
|
this.modelId = modelId;
|
|
2093
2102
|
this.config = config;
|
|
2094
|
-
this.generateId = (_a2 = config.generateId) != null ? _a2 :
|
|
2103
|
+
this.generateId = (_a2 = config.generateId) != null ? _a2 : import_provider_utils9.generateId;
|
|
2095
2104
|
}
|
|
2096
2105
|
get provider() {
|
|
2097
2106
|
return this.config.provider;
|
|
@@ -2119,13 +2128,13 @@ var GoogleGenerativeAILanguageModel = class {
|
|
|
2119
2128
|
var _a2, _b, _c;
|
|
2120
2129
|
const warnings = [];
|
|
2121
2130
|
const providerOptionsName = this.config.provider.includes("vertex") ? "vertex" : "google";
|
|
2122
|
-
let googleOptions = await (0,
|
|
2131
|
+
let googleOptions = await (0, import_provider_utils9.parseProviderOptions)({
|
|
2123
2132
|
provider: providerOptionsName,
|
|
2124
2133
|
providerOptions,
|
|
2125
2134
|
schema: googleLanguageModelOptions
|
|
2126
2135
|
});
|
|
2127
2136
|
if (googleOptions == null && providerOptionsName !== "google") {
|
|
2128
|
-
googleOptions = await (0,
|
|
2137
|
+
googleOptions = await (0, import_provider_utils9.parseProviderOptions)({
|
|
2129
2138
|
provider: "google",
|
|
2130
2139
|
providerOptions,
|
|
2131
2140
|
schema: googleLanguageModelOptions
|
|
@@ -2295,21 +2304,21 @@ var GoogleGenerativeAILanguageModel = class {
|
|
|
2295
2304
|
};
|
|
2296
2305
|
}
|
|
2297
2306
|
async doGenerate(options) {
|
|
2298
|
-
var _a2, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o, _p, _q, _r, _s, _t, _u, _v, _w, _x, _y, _z, _A;
|
|
2307
|
+
var _a2, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o, _p, _q, _r, _s, _t, _u, _v, _w, _x, _y, _z, _A, _B;
|
|
2299
2308
|
const { args, warnings, providerOptionsName, extraHeaders } = await this.getArgs(options);
|
|
2300
|
-
const mergedHeaders = (0,
|
|
2301
|
-
await (0,
|
|
2309
|
+
const mergedHeaders = (0, import_provider_utils9.combineHeaders)(
|
|
2310
|
+
await (0, import_provider_utils9.resolve)(this.config.headers),
|
|
2302
2311
|
options.headers,
|
|
2303
2312
|
extraHeaders
|
|
2304
2313
|
);
|
|
2305
|
-
const generateContent = (body) => (0,
|
|
2314
|
+
const generateContent = (body) => (0, import_provider_utils9.postJsonToApi)({
|
|
2306
2315
|
url: `${this.config.baseURL}/${getModelPath(
|
|
2307
2316
|
this.modelId
|
|
2308
2317
|
)}:generateContent`,
|
|
2309
2318
|
headers: mergedHeaders,
|
|
2310
2319
|
body,
|
|
2311
2320
|
failedResponseHandler: googleFailedResponseHandler,
|
|
2312
|
-
successfulResponseHandler: (0,
|
|
2321
|
+
successfulResponseHandler: (0, import_provider_utils9.createJsonResponseHandler)(responseSchema),
|
|
2313
2322
|
abortSignal: options.abortSignal,
|
|
2314
2323
|
fetch: this.config.fetch
|
|
2315
2324
|
});
|
|
@@ -2319,18 +2328,20 @@ var GoogleGenerativeAILanguageModel = class {
|
|
|
2319
2328
|
rawValue: rawResponse
|
|
2320
2329
|
} = await generateContent(args);
|
|
2321
2330
|
const continuedParts = [];
|
|
2331
|
+
const groundingMetadataPerRequest = [];
|
|
2322
2332
|
let continuedUsageMetadata;
|
|
2323
2333
|
const firstPromptTokenCount = (_a2 = response.usageMetadata) == null ? void 0 : _a2.promptTokenCount;
|
|
2324
2334
|
while (true) {
|
|
2325
2335
|
const candidate2 = (_b = response.candidates) == null ? void 0 : _b[0];
|
|
2336
|
+
groundingMetadataPerRequest.push((_c = candidate2 == null ? void 0 : candidate2.groundingMetadata) != null ? _c : null);
|
|
2326
2337
|
const continuationToken = (candidate2 == null ? void 0 : candidate2.finishReason) === "CONTINUATION" ? candidate2.continuationToken : void 0;
|
|
2327
2338
|
if (continuationToken == null) {
|
|
2328
2339
|
break;
|
|
2329
2340
|
}
|
|
2330
|
-
continuedParts.push(...(
|
|
2341
|
+
continuedParts.push(...(_e = (_d = candidate2 == null ? void 0 : candidate2.content) == null ? void 0 : _d.parts) != null ? _e : []);
|
|
2331
2342
|
continuedUsageMetadata = addGoogleGenerativeAIUsageMetadata(
|
|
2332
2343
|
continuedUsageMetadata,
|
|
2333
|
-
(
|
|
2344
|
+
(_f = response.usageMetadata) != null ? _f : void 0
|
|
2334
2345
|
);
|
|
2335
2346
|
({
|
|
2336
2347
|
responseHeaders,
|
|
@@ -2338,23 +2349,23 @@ var GoogleGenerativeAILanguageModel = class {
|
|
|
2338
2349
|
rawValue: rawResponse
|
|
2339
2350
|
} = await generateContent({ ...args, continuationToken }));
|
|
2340
2351
|
}
|
|
2341
|
-
const candidate = (
|
|
2342
|
-
const promptBlockReason = (
|
|
2352
|
+
const candidate = (_g = response.candidates) == null ? void 0 : _g[0];
|
|
2353
|
+
const promptBlockReason = (_h = response.promptFeedback) == null ? void 0 : _h.blockReason;
|
|
2343
2354
|
const confirmedPromptBlockReason = isConfirmedPromptBlockReason(
|
|
2344
2355
|
promptBlockReason
|
|
2345
2356
|
) ? promptBlockReason : void 0;
|
|
2346
2357
|
const isPromptBlocked = (candidate == null ? void 0 : candidate.finishReason) == null && confirmedPromptBlockReason != null;
|
|
2347
|
-
const rawFinishReason = (
|
|
2358
|
+
const rawFinishReason = (_i = candidate == null ? void 0 : candidate.finishReason) != null ? _i : confirmedPromptBlockReason;
|
|
2348
2359
|
const content = [];
|
|
2349
|
-
const parts = [...continuedParts, ...(
|
|
2360
|
+
const parts = [...continuedParts, ...(_k = (_j = candidate == null ? void 0 : candidate.content) == null ? void 0 : _j.parts) != null ? _k : []];
|
|
2350
2361
|
const usageMetadata = addGoogleGenerativeAIUsageMetadata(
|
|
2351
2362
|
continuedUsageMetadata,
|
|
2352
|
-
(
|
|
2363
|
+
(_l = response.usageMetadata) != null ? _l : void 0
|
|
2353
2364
|
);
|
|
2354
2365
|
let lastCodeExecutionToolCallId;
|
|
2355
2366
|
let lastServerToolCallId;
|
|
2356
2367
|
for (const part of parts) {
|
|
2357
|
-
if ("executableCode" in part && ((
|
|
2368
|
+
if ("executableCode" in part && ((_m = part.executableCode) == null ? void 0 : _m.code)) {
|
|
2358
2369
|
const toolCallId = this.config.generateId();
|
|
2359
2370
|
lastCodeExecutionToolCallId = toolCallId;
|
|
2360
2371
|
content.push({
|
|
@@ -2372,7 +2383,7 @@ var GoogleGenerativeAILanguageModel = class {
|
|
|
2372
2383
|
toolName: "code_execution",
|
|
2373
2384
|
result: {
|
|
2374
2385
|
outcome: part.codeExecutionResult.outcome,
|
|
2375
|
-
output: (
|
|
2386
|
+
output: (_n = part.codeExecutionResult.output) != null ? _n : ""
|
|
2376
2387
|
}
|
|
2377
2388
|
});
|
|
2378
2389
|
} else if ("text" in part && part.text != null) {
|
|
@@ -2396,9 +2407,9 @@ var GoogleGenerativeAILanguageModel = class {
|
|
|
2396
2407
|
} else if ("functionCall" in part && part.functionCall.name != null) {
|
|
2397
2408
|
content.push({
|
|
2398
2409
|
type: "tool-call",
|
|
2399
|
-
toolCallId: (
|
|
2410
|
+
toolCallId: (_o = part.functionCall.id) != null ? _o : this.config.generateId(),
|
|
2400
2411
|
toolName: part.functionCall.name,
|
|
2401
|
-
input: JSON.stringify((
|
|
2412
|
+
input: JSON.stringify((_p = part.functionCall.args) != null ? _p : {}),
|
|
2402
2413
|
providerMetadata: part.thoughtSignature ? {
|
|
2403
2414
|
[providerOptionsName]: {
|
|
2404
2415
|
thoughtSignature: part.thoughtSignature
|
|
@@ -2420,13 +2431,13 @@ var GoogleGenerativeAILanguageModel = class {
|
|
|
2420
2431
|
} : void 0
|
|
2421
2432
|
});
|
|
2422
2433
|
} else if ("toolCall" in part && part.toolCall) {
|
|
2423
|
-
const toolCallId = (
|
|
2434
|
+
const toolCallId = (_q = part.toolCall.id) != null ? _q : this.config.generateId();
|
|
2424
2435
|
lastServerToolCallId = toolCallId;
|
|
2425
2436
|
content.push({
|
|
2426
2437
|
type: "tool-call",
|
|
2427
2438
|
toolCallId,
|
|
2428
2439
|
toolName: `server:${part.toolCall.toolType}`,
|
|
2429
|
-
input: JSON.stringify((
|
|
2440
|
+
input: JSON.stringify((_r = part.toolCall.args) != null ? _r : {}),
|
|
2430
2441
|
providerExecuted: true,
|
|
2431
2442
|
dynamic: true,
|
|
2432
2443
|
providerMetadata: part.thoughtSignature ? {
|
|
@@ -2443,12 +2454,12 @@ var GoogleGenerativeAILanguageModel = class {
|
|
|
2443
2454
|
}
|
|
2444
2455
|
});
|
|
2445
2456
|
} else if ("toolResponse" in part && part.toolResponse) {
|
|
2446
|
-
const responseToolCallId = (
|
|
2457
|
+
const responseToolCallId = (_s = lastServerToolCallId != null ? lastServerToolCallId : part.toolResponse.id) != null ? _s : this.config.generateId();
|
|
2447
2458
|
content.push({
|
|
2448
2459
|
type: "tool-result",
|
|
2449
2460
|
toolCallId: responseToolCallId,
|
|
2450
2461
|
toolName: `server:${part.toolResponse.toolType}`,
|
|
2451
|
-
result: (
|
|
2462
|
+
result: (_t = part.toolResponse.response) != null ? _t : {},
|
|
2452
2463
|
providerMetadata: part.thoughtSignature ? {
|
|
2453
2464
|
[providerOptionsName]: {
|
|
2454
2465
|
thoughtSignature: part.thoughtSignature,
|
|
@@ -2465,10 +2476,10 @@ var GoogleGenerativeAILanguageModel = class {
|
|
|
2465
2476
|
lastServerToolCallId = void 0;
|
|
2466
2477
|
}
|
|
2467
2478
|
}
|
|
2468
|
-
const sources = (
|
|
2479
|
+
const sources = (_u = extractSources({
|
|
2469
2480
|
groundingMetadata: candidate == null ? void 0 : candidate.groundingMetadata,
|
|
2470
2481
|
generateId: this.config.generateId
|
|
2471
|
-
})) != null ?
|
|
2482
|
+
})) != null ? _u : [];
|
|
2472
2483
|
for (const source of sources) {
|
|
2473
2484
|
content.push(source);
|
|
2474
2485
|
}
|
|
@@ -2488,13 +2499,14 @@ var GoogleGenerativeAILanguageModel = class {
|
|
|
2488
2499
|
warnings,
|
|
2489
2500
|
providerMetadata: {
|
|
2490
2501
|
[providerOptionsName]: {
|
|
2491
|
-
promptFeedback: (
|
|
2492
|
-
groundingMetadata: (
|
|
2493
|
-
|
|
2494
|
-
|
|
2502
|
+
promptFeedback: (_v = response.promptFeedback) != null ? _v : null,
|
|
2503
|
+
groundingMetadata: (_w = candidate == null ? void 0 : candidate.groundingMetadata) != null ? _w : null,
|
|
2504
|
+
...groundingMetadataPerRequest.length > 1 ? { groundingMetadataPerRequest } : {},
|
|
2505
|
+
urlContextMetadata: (_x = candidate == null ? void 0 : candidate.urlContextMetadata) != null ? _x : null,
|
|
2506
|
+
safetyRatings: (_y = candidate == null ? void 0 : candidate.safetyRatings) != null ? _y : null,
|
|
2495
2507
|
usageMetadata: usageMetadata != null ? usageMetadata : null,
|
|
2496
|
-
finishMessage: (
|
|
2497
|
-
serviceTier: (
|
|
2508
|
+
finishMessage: (_z = candidate == null ? void 0 : candidate.finishMessage) != null ? _z : null,
|
|
2509
|
+
serviceTier: (_A = usageMetadata == null ? void 0 : usageMetadata.serviceTier) != null ? _A : null,
|
|
2498
2510
|
...(candidate == null ? void 0 : candidate.continuationToken) != null && rawFinishReason === "MAX_TOKENS" ? { continuationToken: candidate.continuationToken } : {},
|
|
2499
2511
|
...continuedUsageMetadata != null && firstPromptTokenCount != null ? { initialPromptTokenCount: firstPromptTokenCount } : {}
|
|
2500
2512
|
}
|
|
@@ -2502,7 +2514,7 @@ var GoogleGenerativeAILanguageModel = class {
|
|
|
2502
2514
|
request: { body: args },
|
|
2503
2515
|
response: {
|
|
2504
2516
|
// TODO timestamp, model id
|
|
2505
|
-
id: (
|
|
2517
|
+
id: (_B = response.responseId) != null ? _B : void 0,
|
|
2506
2518
|
headers: responseHeaders,
|
|
2507
2519
|
body: rawResponse
|
|
2508
2520
|
}
|
|
@@ -2510,31 +2522,44 @@ var GoogleGenerativeAILanguageModel = class {
|
|
|
2510
2522
|
}
|
|
2511
2523
|
async doStream(options) {
|
|
2512
2524
|
const { args, warnings, providerOptionsName, extraHeaders } = await this.getArgs(options, { isStreaming: true });
|
|
2513
|
-
const headers = (0,
|
|
2514
|
-
await (0,
|
|
2525
|
+
const headers = (0, import_provider_utils9.combineHeaders)(
|
|
2526
|
+
await (0, import_provider_utils9.resolve)(this.config.headers),
|
|
2515
2527
|
options.headers,
|
|
2516
2528
|
extraHeaders
|
|
2517
2529
|
);
|
|
2518
|
-
const streamGenerateContent = (body) => (0,
|
|
2530
|
+
const streamGenerateContent = (body) => (0, import_provider_utils9.postJsonToApi)({
|
|
2519
2531
|
url: `${this.config.baseURL}/${getModelPath(
|
|
2520
2532
|
this.modelId
|
|
2521
2533
|
)}:streamGenerateContent?alt=sse`,
|
|
2522
2534
|
headers,
|
|
2523
2535
|
body,
|
|
2524
2536
|
failedResponseHandler: googleFailedResponseHandler,
|
|
2525
|
-
successfulResponseHandler: (0,
|
|
2537
|
+
successfulResponseHandler: (0, import_provider_utils9.createEventSourceResponseHandler)(chunkSchema),
|
|
2526
2538
|
abortSignal: options.abortSignal,
|
|
2527
2539
|
fetch: this.config.fetch
|
|
2528
2540
|
});
|
|
2529
2541
|
const { responseHeaders, value: firstResponse } = await streamGenerateContent(args);
|
|
2542
|
+
const groundingMetadataPerRequest = [];
|
|
2543
|
+
let requestGroundingMetadata = null;
|
|
2530
2544
|
const response = continueGoogleStream({
|
|
2531
2545
|
stream: firstResponse,
|
|
2532
2546
|
getContinuationToken: (chunk) => {
|
|
2533
2547
|
var _a2, _b;
|
|
2534
2548
|
const candidate = (_a2 = chunk.candidates) == null ? void 0 : _a2[0];
|
|
2549
|
+
if ((candidate == null ? void 0 : candidate.groundingMetadata) != null) {
|
|
2550
|
+
requestGroundingMetadata = candidate.groundingMetadata;
|
|
2551
|
+
}
|
|
2535
2552
|
return (candidate == null ? void 0 : candidate.finishReason) === "CONTINUATION" ? (_b = candidate.continuationToken) != null ? _b : void 0 : void 0;
|
|
2536
2553
|
},
|
|
2537
|
-
continueStream: async (continuationToken) =>
|
|
2554
|
+
continueStream: async (continuationToken) => {
|
|
2555
|
+
const { value } = await streamGenerateContent({
|
|
2556
|
+
...args,
|
|
2557
|
+
continuationToken
|
|
2558
|
+
});
|
|
2559
|
+
groundingMetadataPerRequest.push(requestGroundingMetadata);
|
|
2560
|
+
requestGroundingMetadata = null;
|
|
2561
|
+
return value;
|
|
2562
|
+
}
|
|
2538
2563
|
});
|
|
2539
2564
|
let finishReason = {
|
|
2540
2565
|
unified: "other",
|
|
@@ -2969,6 +2994,12 @@ var GoogleGenerativeAILanguageModel = class {
|
|
|
2969
2994
|
[providerOptionsName]: {
|
|
2970
2995
|
promptFeedback,
|
|
2971
2996
|
groundingMetadata: lastGroundingMetadata,
|
|
2997
|
+
...groundingMetadataPerRequest.length > 0 ? {
|
|
2998
|
+
groundingMetadataPerRequest: [
|
|
2999
|
+
...groundingMetadataPerRequest,
|
|
3000
|
+
requestGroundingMetadata
|
|
3001
|
+
]
|
|
3002
|
+
} : {},
|
|
2972
3003
|
urlContextMetadata: lastUrlContextMetadata,
|
|
2973
3004
|
safetyRatings: lastSafetyRatings,
|
|
2974
3005
|
usageMetadata: usage != null ? usage : null,
|
|
@@ -3141,7 +3172,7 @@ var getGroundingMetadataSchema = () => import_v47.z.object({
|
|
|
3141
3172
|
import_v47.z.object({})
|
|
3142
3173
|
]).nullish()
|
|
3143
3174
|
});
|
|
3144
|
-
var partialArgSchema = import_v47.z.object({
|
|
3175
|
+
var partialArgSchema = () => import_v47.z.object({
|
|
3145
3176
|
jsonPath: import_v47.z.string(),
|
|
3146
3177
|
stringValue: import_v47.z.string().nullish(),
|
|
3147
3178
|
numberValue: import_v47.z.number().nullish(),
|
|
@@ -3158,7 +3189,7 @@ var getContentSchema = () => import_v47.z.object({
|
|
|
3158
3189
|
id: import_v47.z.string().nullish(),
|
|
3159
3190
|
name: import_v47.z.string().nullish(),
|
|
3160
3191
|
args: import_v47.z.unknown().nullish(),
|
|
3161
|
-
partialArgs: import_v47.z.array(partialArgSchema).nullish(),
|
|
3192
|
+
partialArgs: import_v47.z.array(partialArgSchema()).nullish(),
|
|
3162
3193
|
willContinue: import_v47.z.boolean().nullish()
|
|
3163
3194
|
}),
|
|
3164
3195
|
thoughtSignature: import_v47.z.string().nullish()
|
|
@@ -3211,13 +3242,13 @@ var getSafetyRatingSchema = () => import_v47.z.object({
|
|
|
3211
3242
|
severityScore: import_v47.z.number().nullish(),
|
|
3212
3243
|
blocked: import_v47.z.boolean().nullish()
|
|
3213
3244
|
});
|
|
3214
|
-
var tokenDetailsSchema = import_v47.z.array(
|
|
3245
|
+
var tokenDetailsSchema = () => import_v47.z.array(
|
|
3215
3246
|
import_v47.z.object({
|
|
3216
3247
|
modality: import_v47.z.string(),
|
|
3217
3248
|
tokenCount: import_v47.z.number()
|
|
3218
3249
|
}).catchall(import_v47.z.json())
|
|
3219
3250
|
).nullish();
|
|
3220
|
-
var usageSchema = import_v47.z.object({
|
|
3251
|
+
var usageSchema = () => import_v47.z.object({
|
|
3221
3252
|
cachedContentTokenCount: import_v47.z.number().nullish(),
|
|
3222
3253
|
thoughtsTokenCount: import_v47.z.number().nullish(),
|
|
3223
3254
|
promptTokenCount: import_v47.z.number().nullish(),
|
|
@@ -3228,10 +3259,10 @@ var usageSchema = import_v47.z.object({
|
|
|
3228
3259
|
trafficType: import_v47.z.string().nullish(),
|
|
3229
3260
|
serviceTier: import_v47.z.string().nullish(),
|
|
3230
3261
|
// https://ai.google.dev/api/generate-content#Modality
|
|
3231
|
-
promptTokensDetails: tokenDetailsSchema,
|
|
3232
|
-
cacheTokensDetails: tokenDetailsSchema,
|
|
3233
|
-
candidatesTokensDetails: tokenDetailsSchema,
|
|
3234
|
-
toolUsePromptTokensDetails: tokenDetailsSchema
|
|
3262
|
+
promptTokensDetails: tokenDetailsSchema(),
|
|
3263
|
+
cacheTokensDetails: tokenDetailsSchema(),
|
|
3264
|
+
candidatesTokensDetails: tokenDetailsSchema(),
|
|
3265
|
+
toolUsePromptTokensDetails: tokenDetailsSchema()
|
|
3235
3266
|
}).catchall(import_v47.z.json());
|
|
3236
3267
|
var getUrlContextMetadataSchema = () => import_v47.z.object({
|
|
3237
3268
|
urlMetadata: import_v47.z.array(
|
|
@@ -3241,8 +3272,8 @@ var getUrlContextMetadataSchema = () => import_v47.z.object({
|
|
|
3241
3272
|
})
|
|
3242
3273
|
).nullish()
|
|
3243
3274
|
});
|
|
3244
|
-
var responseSchema = (0,
|
|
3245
|
-
() => (0,
|
|
3275
|
+
var responseSchema = (0, import_provider_utils9.lazySchema)(
|
|
3276
|
+
() => (0, import_provider_utils9.zodSchema)(
|
|
3246
3277
|
import_v47.z.object({
|
|
3247
3278
|
responseId: import_v47.z.string().nullish(),
|
|
3248
3279
|
candidates: import_v47.z.array(
|
|
@@ -3256,7 +3287,7 @@ var responseSchema = (0, import_provider_utils8.lazySchema)(
|
|
|
3256
3287
|
urlContextMetadata: getUrlContextMetadataSchema().nullish()
|
|
3257
3288
|
})
|
|
3258
3289
|
).nullish(),
|
|
3259
|
-
usageMetadata: usageSchema.nullish(),
|
|
3290
|
+
usageMetadata: usageSchema().nullish(),
|
|
3260
3291
|
promptFeedback: import_v47.z.object({
|
|
3261
3292
|
blockReason: import_v47.z.string().nullish(),
|
|
3262
3293
|
safetyRatings: import_v47.z.array(getSafetyRatingSchema()).nullish()
|
|
@@ -3264,8 +3295,8 @@ var responseSchema = (0, import_provider_utils8.lazySchema)(
|
|
|
3264
3295
|
})
|
|
3265
3296
|
)
|
|
3266
3297
|
);
|
|
3267
|
-
var chunkSchema = (0,
|
|
3268
|
-
() => (0,
|
|
3298
|
+
var chunkSchema = (0, import_provider_utils9.lazySchema)(
|
|
3299
|
+
() => (0, import_provider_utils9.zodSchema)(
|
|
3269
3300
|
import_v47.z.object({
|
|
3270
3301
|
responseId: import_v47.z.string().nullish(),
|
|
3271
3302
|
candidates: import_v47.z.array(
|
|
@@ -3279,7 +3310,7 @@ var chunkSchema = (0, import_provider_utils8.lazySchema)(
|
|
|
3279
3310
|
urlContextMetadata: getUrlContextMetadataSchema().nullish()
|
|
3280
3311
|
})
|
|
3281
3312
|
).nullish(),
|
|
3282
|
-
usageMetadata: usageSchema.nullish(),
|
|
3313
|
+
usageMetadata: usageSchema().nullish(),
|
|
3283
3314
|
promptFeedback: import_v47.z.object({
|
|
3284
3315
|
blockReason: import_v47.z.string().nullish(),
|
|
3285
3316
|
safetyRatings: import_v47.z.array(getSafetyRatingSchema()).nullish()
|
|
@@ -3292,9 +3323,9 @@ function isConfirmedPromptBlockReason(blockReason) {
|
|
|
3292
3323
|
}
|
|
3293
3324
|
|
|
3294
3325
|
// src/tool/code-execution.ts
|
|
3295
|
-
var
|
|
3326
|
+
var import_provider_utils10 = require("@ai-sdk/provider-utils");
|
|
3296
3327
|
var import_v48 = require("zod/v4");
|
|
3297
|
-
var codeExecution = (0,
|
|
3328
|
+
var codeExecution = (0, import_provider_utils10.createProviderToolFactoryWithOutputSchema)({
|
|
3298
3329
|
id: "google.code_execution",
|
|
3299
3330
|
inputSchema: import_v48.z.object({
|
|
3300
3331
|
language: import_v48.z.string().describe("The programming language of the code."),
|
|
@@ -3307,17 +3338,17 @@ var codeExecution = (0, import_provider_utils9.createProviderToolFactoryWithOutp
|
|
|
3307
3338
|
});
|
|
3308
3339
|
|
|
3309
3340
|
// src/tool/enterprise-web-search.ts
|
|
3310
|
-
var
|
|
3341
|
+
var import_provider_utils11 = require("@ai-sdk/provider-utils");
|
|
3311
3342
|
var import_v49 = require("zod/v4");
|
|
3312
|
-
var enterpriseWebSearch = (0,
|
|
3343
|
+
var enterpriseWebSearch = (0, import_provider_utils11.createProviderToolFactory)({
|
|
3313
3344
|
id: "google.enterprise_web_search",
|
|
3314
|
-
inputSchema: (0,
|
|
3345
|
+
inputSchema: (0, import_provider_utils11.lazySchema)(() => (0, import_provider_utils11.zodSchema)(import_v49.z.object({})))
|
|
3315
3346
|
});
|
|
3316
3347
|
|
|
3317
3348
|
// src/tool/file-search.ts
|
|
3318
|
-
var
|
|
3349
|
+
var import_provider_utils12 = require("@ai-sdk/provider-utils");
|
|
3319
3350
|
var import_v410 = require("zod/v4");
|
|
3320
|
-
var fileSearchArgsBaseSchema = import_v410.z.object({
|
|
3351
|
+
var fileSearchArgsBaseSchema = () => import_v410.z.object({
|
|
3321
3352
|
/** The names of the file_search_stores to retrieve from.
|
|
3322
3353
|
* Example: `fileSearchStores/my-file-search-store-123`
|
|
3323
3354
|
*/
|
|
@@ -3333,26 +3364,26 @@ var fileSearchArgsBaseSchema = import_v410.z.object({
|
|
|
3333
3364
|
"Metadata filter to apply to the file search retrieval documents. See https://google.aip.dev/160 for the syntax of the filter expression."
|
|
3334
3365
|
).optional()
|
|
3335
3366
|
}).passthrough();
|
|
3336
|
-
var fileSearchArgsSchema = (0,
|
|
3337
|
-
() => (0,
|
|
3367
|
+
var fileSearchArgsSchema = (0, import_provider_utils12.lazySchema)(
|
|
3368
|
+
() => (0, import_provider_utils12.zodSchema)(fileSearchArgsBaseSchema())
|
|
3338
3369
|
);
|
|
3339
|
-
var fileSearch = (0,
|
|
3370
|
+
var fileSearch = (0, import_provider_utils12.createProviderToolFactory)({
|
|
3340
3371
|
id: "google.file_search",
|
|
3341
3372
|
inputSchema: fileSearchArgsSchema
|
|
3342
3373
|
});
|
|
3343
3374
|
|
|
3344
3375
|
// src/tool/google-maps.ts
|
|
3345
|
-
var
|
|
3376
|
+
var import_provider_utils13 = require("@ai-sdk/provider-utils");
|
|
3346
3377
|
var import_v411 = require("zod/v4");
|
|
3347
|
-
var googleMaps = (0,
|
|
3378
|
+
var googleMaps = (0, import_provider_utils13.createProviderToolFactory)({
|
|
3348
3379
|
id: "google.google_maps",
|
|
3349
|
-
inputSchema: (0,
|
|
3380
|
+
inputSchema: (0, import_provider_utils13.lazySchema)(() => (0, import_provider_utils13.zodSchema)(import_v411.z.object({})))
|
|
3350
3381
|
});
|
|
3351
3382
|
|
|
3352
3383
|
// src/tool/google-search.ts
|
|
3353
|
-
var
|
|
3384
|
+
var import_provider_utils14 = require("@ai-sdk/provider-utils");
|
|
3354
3385
|
var import_v412 = require("zod/v4");
|
|
3355
|
-
var googleSearchToolArgsBaseSchema = import_v412.z.object({
|
|
3386
|
+
var googleSearchToolArgsBaseSchema = () => import_v412.z.object({
|
|
3356
3387
|
searchTypes: import_v412.z.object({
|
|
3357
3388
|
webSearch: import_v412.z.object({}).optional(),
|
|
3358
3389
|
imageSearch: import_v412.z.object({}).optional()
|
|
@@ -3362,10 +3393,10 @@ var googleSearchToolArgsBaseSchema = import_v412.z.object({
|
|
|
3362
3393
|
endTime: import_v412.z.string()
|
|
3363
3394
|
}).optional()
|
|
3364
3395
|
}).passthrough();
|
|
3365
|
-
var googleSearchToolArgsSchema = (0,
|
|
3366
|
-
() => (0,
|
|
3396
|
+
var googleSearchToolArgsSchema = (0, import_provider_utils14.lazySchema)(
|
|
3397
|
+
() => (0, import_provider_utils14.zodSchema)(googleSearchToolArgsBaseSchema())
|
|
3367
3398
|
);
|
|
3368
|
-
var googleSearch = (0,
|
|
3399
|
+
var googleSearch = (0, import_provider_utils14.createProviderToolFactory)(
|
|
3369
3400
|
{
|
|
3370
3401
|
id: "google.google_search",
|
|
3371
3402
|
inputSchema: googleSearchToolArgsSchema
|
|
@@ -3373,17 +3404,17 @@ var googleSearch = (0, import_provider_utils13.createProviderToolFactory)(
|
|
|
3373
3404
|
);
|
|
3374
3405
|
|
|
3375
3406
|
// src/tool/url-context.ts
|
|
3376
|
-
var
|
|
3407
|
+
var import_provider_utils15 = require("@ai-sdk/provider-utils");
|
|
3377
3408
|
var import_v413 = require("zod/v4");
|
|
3378
|
-
var urlContext = (0,
|
|
3409
|
+
var urlContext = (0, import_provider_utils15.createProviderToolFactory)({
|
|
3379
3410
|
id: "google.url_context",
|
|
3380
|
-
inputSchema: (0,
|
|
3411
|
+
inputSchema: (0, import_provider_utils15.lazySchema)(() => (0, import_provider_utils15.zodSchema)(import_v413.z.object({})))
|
|
3381
3412
|
});
|
|
3382
3413
|
|
|
3383
3414
|
// src/tool/vertex-rag-store.ts
|
|
3384
|
-
var
|
|
3415
|
+
var import_provider_utils16 = require("@ai-sdk/provider-utils");
|
|
3385
3416
|
var import_v414 = require("zod/v4");
|
|
3386
|
-
var vertexRagStore = (0,
|
|
3417
|
+
var vertexRagStore = (0, import_provider_utils16.createProviderToolFactory)({
|
|
3387
3418
|
id: "google.vertex_rag_store",
|
|
3388
3419
|
inputSchema: import_v414.z.object({
|
|
3389
3420
|
ragCorpus: import_v414.z.string(),
|
|
@@ -3452,7 +3483,7 @@ var googleTools = {
|
|
|
3452
3483
|
};
|
|
3453
3484
|
|
|
3454
3485
|
// src/google-generative-ai-image-model.ts
|
|
3455
|
-
var
|
|
3486
|
+
var import_provider_utils17 = require("@ai-sdk/provider-utils");
|
|
3456
3487
|
var import_v415 = require("zod/v4");
|
|
3457
3488
|
var GoogleGenerativeAIImageModel = class {
|
|
3458
3489
|
constructor(modelId, settings, config) {
|
|
@@ -3518,7 +3549,7 @@ var GoogleGenerativeAIImageModel = class {
|
|
|
3518
3549
|
details: "This model does not support the `seed` option through this provider."
|
|
3519
3550
|
});
|
|
3520
3551
|
}
|
|
3521
|
-
const googleOptions = await (0,
|
|
3552
|
+
const googleOptions = await (0, import_provider_utils17.parseProviderOptions)({
|
|
3522
3553
|
provider: "google",
|
|
3523
3554
|
providerOptions,
|
|
3524
3555
|
schema: googleImageModelOptionsSchema
|
|
@@ -3545,12 +3576,12 @@ var GoogleGenerativeAIImageModel = class {
|
|
|
3545
3576
|
instances: [{ prompt }],
|
|
3546
3577
|
parameters
|
|
3547
3578
|
};
|
|
3548
|
-
const { responseHeaders, value: response } = await (0,
|
|
3579
|
+
const { responseHeaders, value: response } = await (0, import_provider_utils17.postJsonToApi)({
|
|
3549
3580
|
url: `${this.config.baseURL}/models/${this.modelId}:predict`,
|
|
3550
|
-
headers: (0,
|
|
3581
|
+
headers: (0, import_provider_utils17.combineHeaders)(await (0, import_provider_utils17.resolve)(this.config.headers), headers),
|
|
3551
3582
|
body,
|
|
3552
3583
|
failedResponseHandler: googleFailedResponseHandler,
|
|
3553
|
-
successfulResponseHandler: (0,
|
|
3584
|
+
successfulResponseHandler: (0, import_provider_utils17.createJsonResponseHandler)(
|
|
3554
3585
|
googleImageResponseSchema
|
|
3555
3586
|
),
|
|
3556
3587
|
abortSignal,
|
|
@@ -3637,7 +3668,7 @@ var GoogleGenerativeAIImageModel = class {
|
|
|
3637
3668
|
const languageModelPrompt = [
|
|
3638
3669
|
{ role: "user", content: userContent }
|
|
3639
3670
|
];
|
|
3640
|
-
const googleImageOptions = await (0,
|
|
3671
|
+
const googleImageOptions = await (0, import_provider_utils17.parseProviderOptions)({
|
|
3641
3672
|
provider: "google",
|
|
3642
3673
|
providerOptions,
|
|
3643
3674
|
schema: googleImageModelOptionsSchema
|
|
@@ -3648,7 +3679,7 @@ var GoogleGenerativeAIImageModel = class {
|
|
|
3648
3679
|
baseURL: this.config.baseURL,
|
|
3649
3680
|
headers: (_b = this.config.headers) != null ? _b : {},
|
|
3650
3681
|
fetch: this.config.fetch,
|
|
3651
|
-
generateId: (_c = this.config.generateId) != null ? _c :
|
|
3682
|
+
generateId: (_c = this.config.generateId) != null ? _c : import_provider_utils17.generateId
|
|
3652
3683
|
});
|
|
3653
3684
|
const result = await languageModel.doGenerate({
|
|
3654
3685
|
prompt: languageModelPrompt,
|
|
@@ -3677,7 +3708,7 @@ var GoogleGenerativeAIImageModel = class {
|
|
|
3677
3708
|
const images = [];
|
|
3678
3709
|
for (const part of result.content) {
|
|
3679
3710
|
if (part.type === "file" && part.mediaType.startsWith("image/")) {
|
|
3680
|
-
images.push((0,
|
|
3711
|
+
images.push((0, import_provider_utils17.convertToBase64)(part.data));
|
|
3681
3712
|
}
|
|
3682
3713
|
}
|
|
3683
3714
|
const languageModelGoogleMetadata = (_h = (_g = result.providerMetadata) == null ? void 0 : _g.google) != null ? _h : {};
|
|
@@ -3707,8 +3738,8 @@ var GoogleGenerativeAIImageModel = class {
|
|
|
3707
3738
|
function isGeminiModel(modelId) {
|
|
3708
3739
|
return modelId.startsWith("gemini-");
|
|
3709
3740
|
}
|
|
3710
|
-
var googleImageResponseSchema = (0,
|
|
3711
|
-
() => (0,
|
|
3741
|
+
var googleImageResponseSchema = (0, import_provider_utils17.lazySchema)(
|
|
3742
|
+
() => (0, import_provider_utils17.zodSchema)(
|
|
3712
3743
|
import_v415.z.object({
|
|
3713
3744
|
predictions: import_v415.z.array(
|
|
3714
3745
|
import_v415.z.union([
|
|
@@ -3719,8 +3750,8 @@ var googleImageResponseSchema = (0, import_provider_utils16.lazySchema)(
|
|
|
3719
3750
|
})
|
|
3720
3751
|
)
|
|
3721
3752
|
);
|
|
3722
|
-
var googleImageModelOptionsSchema = (0,
|
|
3723
|
-
() => (0,
|
|
3753
|
+
var googleImageModelOptionsSchema = (0, import_provider_utils17.lazySchema)(
|
|
3754
|
+
() => (0, import_provider_utils17.zodSchema)(
|
|
3724
3755
|
import_v415.z.object({
|
|
3725
3756
|
personGeneration: import_v415.z.enum(["dont_allow", "allow_adult", "allow_all"]).nullish(),
|
|
3726
3757
|
aspectRatio: import_v415.z.enum(["1:1", "3:4", "4:3", "9:16", "16:9"]).nullish(),
|
|
@@ -3733,14 +3764,14 @@ var googleImageModelOptionsSchema = (0, import_provider_utils16.lazySchema)(
|
|
|
3733
3764
|
* dedicated escape hatch for grounding image generation the same way
|
|
3734
3765
|
* `generateText` does.
|
|
3735
3766
|
*/
|
|
3736
|
-
googleSearch: googleSearchToolArgsBaseSchema.optional()
|
|
3767
|
+
googleSearch: googleSearchToolArgsBaseSchema().optional()
|
|
3737
3768
|
})
|
|
3738
3769
|
)
|
|
3739
3770
|
);
|
|
3740
3771
|
|
|
3741
3772
|
// src/google-generative-ai-video-model.ts
|
|
3742
3773
|
var import_provider6 = require("@ai-sdk/provider");
|
|
3743
|
-
var
|
|
3774
|
+
var import_provider_utils18 = require("@ai-sdk/provider-utils");
|
|
3744
3775
|
var import_v416 = require("zod/v4");
|
|
3745
3776
|
function getFirstFrameImage(options) {
|
|
3746
3777
|
var _a2, _b;
|
|
@@ -3775,7 +3806,7 @@ function convertFileToGoogleImage(file, warnings) {
|
|
|
3775
3806
|
});
|
|
3776
3807
|
return void 0;
|
|
3777
3808
|
}
|
|
3778
|
-
const base64Data = typeof file.data === "string" ? file.data : (0,
|
|
3809
|
+
const base64Data = typeof file.data === "string" ? file.data : (0, import_provider_utils18.convertUint8ArrayToBase64)(file.data);
|
|
3779
3810
|
return {
|
|
3780
3811
|
bytesBase64Encoded: base64Data,
|
|
3781
3812
|
mimeType: file.mediaType || "image/png"
|
|
@@ -3820,7 +3851,7 @@ var GoogleGenerativeAIVideoModel = class {
|
|
|
3820
3851
|
var _a2, _b, _c, _d, _e, _f, _g, _h;
|
|
3821
3852
|
const currentDate = (_c = (_b = (_a2 = this.config._internal) == null ? void 0 : _a2.currentDate) == null ? void 0 : _b.call(_a2)) != null ? _c : /* @__PURE__ */ new Date();
|
|
3822
3853
|
const warnings = [];
|
|
3823
|
-
const googleOptions = await (0,
|
|
3854
|
+
const googleOptions = await (0, import_provider_utils18.parseProviderOptions)({
|
|
3824
3855
|
provider: "google",
|
|
3825
3856
|
providerOptions: options.providerOptions,
|
|
3826
3857
|
schema: googleVideoModelOptionsSchema
|
|
@@ -3895,17 +3926,17 @@ var GoogleGenerativeAIVideoModel = class {
|
|
|
3895
3926
|
}
|
|
3896
3927
|
}
|
|
3897
3928
|
}
|
|
3898
|
-
const { value: operation } = await (0,
|
|
3929
|
+
const { value: operation } = await (0, import_provider_utils18.postJsonToApi)({
|
|
3899
3930
|
url: `${this.config.baseURL}/models/${this.modelId}:predictLongRunning`,
|
|
3900
|
-
headers: (0,
|
|
3901
|
-
await (0,
|
|
3931
|
+
headers: (0, import_provider_utils18.combineHeaders)(
|
|
3932
|
+
await (0, import_provider_utils18.resolve)(this.config.headers),
|
|
3902
3933
|
options.headers
|
|
3903
3934
|
),
|
|
3904
3935
|
body: {
|
|
3905
3936
|
instances,
|
|
3906
3937
|
parameters
|
|
3907
3938
|
},
|
|
3908
|
-
successfulResponseHandler: (0,
|
|
3939
|
+
successfulResponseHandler: (0, import_provider_utils18.createJsonResponseHandler)(
|
|
3909
3940
|
googleOperationSchema
|
|
3910
3941
|
),
|
|
3911
3942
|
failedResponseHandler: googleFailedResponseHandler,
|
|
@@ -3931,20 +3962,20 @@ var GoogleGenerativeAIVideoModel = class {
|
|
|
3931
3962
|
message: `Video generation timed out after ${pollTimeoutMs}ms`
|
|
3932
3963
|
});
|
|
3933
3964
|
}
|
|
3934
|
-
await (0,
|
|
3965
|
+
await (0, import_provider_utils18.delay)(pollIntervalMs);
|
|
3935
3966
|
if ((_f = options.abortSignal) == null ? void 0 : _f.aborted) {
|
|
3936
3967
|
throw new import_provider6.AISDKError({
|
|
3937
3968
|
name: "GOOGLE_VIDEO_GENERATION_ABORTED",
|
|
3938
3969
|
message: "Video generation request was aborted"
|
|
3939
3970
|
});
|
|
3940
3971
|
}
|
|
3941
|
-
const { value: statusOperation, responseHeaders: pollHeaders } = await (0,
|
|
3972
|
+
const { value: statusOperation, responseHeaders: pollHeaders } = await (0, import_provider_utils18.getFromApi)({
|
|
3942
3973
|
url: `${this.config.baseURL}/${operationName}`,
|
|
3943
|
-
headers: (0,
|
|
3944
|
-
await (0,
|
|
3974
|
+
headers: (0, import_provider_utils18.combineHeaders)(
|
|
3975
|
+
await (0, import_provider_utils18.resolve)(this.config.headers),
|
|
3945
3976
|
options.headers
|
|
3946
3977
|
),
|
|
3947
|
-
successfulResponseHandler: (0,
|
|
3978
|
+
successfulResponseHandler: (0, import_provider_utils18.createJsonResponseHandler)(
|
|
3948
3979
|
googleOperationSchema
|
|
3949
3980
|
),
|
|
3950
3981
|
failedResponseHandler: googleFailedResponseHandler,
|
|
@@ -3969,11 +4000,11 @@ var GoogleGenerativeAIVideoModel = class {
|
|
|
3969
4000
|
}
|
|
3970
4001
|
const videos = [];
|
|
3971
4002
|
const videoMetadata = [];
|
|
3972
|
-
const resolvedHeaders = await (0,
|
|
4003
|
+
const resolvedHeaders = await (0, import_provider_utils18.resolve)(this.config.headers);
|
|
3973
4004
|
const apiKey = resolvedHeaders == null ? void 0 : resolvedHeaders["x-goog-api-key"];
|
|
3974
4005
|
for (const generatedSample of response.generateVideoResponse.generatedSamples) {
|
|
3975
4006
|
if ((_h = generatedSample.video) == null ? void 0 : _h.uri) {
|
|
3976
|
-
const urlWithAuth = apiKey && (0,
|
|
4007
|
+
const urlWithAuth = apiKey && (0, import_provider_utils18.isSameOrigin)(generatedSample.video.uri, this.config.baseURL) ? `${generatedSample.video.uri}${generatedSample.video.uri.includes("?") ? "&" : "?"}key=${apiKey}` : generatedSample.video.uri;
|
|
3977
4008
|
videos.push({
|
|
3978
4009
|
type: "url",
|
|
3979
4010
|
url: urlWithAuth,
|
|
@@ -4006,28 +4037,32 @@ var GoogleGenerativeAIVideoModel = class {
|
|
|
4006
4037
|
};
|
|
4007
4038
|
}
|
|
4008
4039
|
};
|
|
4009
|
-
var googleOperationSchema =
|
|
4010
|
-
|
|
4011
|
-
|
|
4012
|
-
|
|
4013
|
-
|
|
4014
|
-
|
|
4015
|
-
|
|
4016
|
-
|
|
4017
|
-
|
|
4018
|
-
|
|
4019
|
-
|
|
4020
|
-
import_v416.z.object({
|
|
4021
|
-
|
|
4022
|
-
|
|
4023
|
-
|
|
4024
|
-
|
|
4025
|
-
|
|
4026
|
-
|
|
4027
|
-
|
|
4028
|
-
})
|
|
4029
|
-
|
|
4030
|
-
|
|
4040
|
+
var googleOperationSchema = (0, import_provider_utils18.lazySchema)(
|
|
4041
|
+
() => (0, import_provider_utils18.zodSchema)(
|
|
4042
|
+
import_v416.z.object({
|
|
4043
|
+
name: import_v416.z.string().nullish(),
|
|
4044
|
+
done: import_v416.z.boolean().nullish(),
|
|
4045
|
+
error: import_v416.z.object({
|
|
4046
|
+
code: import_v416.z.number().nullish(),
|
|
4047
|
+
message: import_v416.z.string(),
|
|
4048
|
+
status: import_v416.z.string().nullish()
|
|
4049
|
+
}).nullish(),
|
|
4050
|
+
response: import_v416.z.object({
|
|
4051
|
+
generateVideoResponse: import_v416.z.object({
|
|
4052
|
+
generatedSamples: import_v416.z.array(
|
|
4053
|
+
import_v416.z.object({
|
|
4054
|
+
video: import_v416.z.object({
|
|
4055
|
+
uri: import_v416.z.string().nullish()
|
|
4056
|
+
}).nullish()
|
|
4057
|
+
})
|
|
4058
|
+
).nullish()
|
|
4059
|
+
}).nullish()
|
|
4060
|
+
}).nullish()
|
|
4061
|
+
})
|
|
4062
|
+
)
|
|
4063
|
+
);
|
|
4064
|
+
var googleVideoModelOptionsSchema = (0, import_provider_utils18.lazySchema)(
|
|
4065
|
+
() => (0, import_provider_utils18.zodSchema)(
|
|
4031
4066
|
import_v416.z.object({
|
|
4032
4067
|
pollIntervalMs: import_v416.z.number().positive().nullish(),
|
|
4033
4068
|
pollTimeoutMs: import_v416.z.number().positive().nullish(),
|
|
@@ -4044,7 +4079,7 @@ var googleVideoModelOptionsSchema = (0, import_provider_utils17.lazySchema)(
|
|
|
4044
4079
|
);
|
|
4045
4080
|
|
|
4046
4081
|
// src/interactions/google-interactions-language-model.ts
|
|
4047
|
-
var
|
|
4082
|
+
var import_provider_utils25 = require("@ai-sdk/provider-utils");
|
|
4048
4083
|
|
|
4049
4084
|
// src/interactions/convert-google-interactions-usage.ts
|
|
4050
4085
|
function convertGoogleInteractionsUsage(usage) {
|
|
@@ -4810,7 +4845,7 @@ function buildGoogleInteractionsStreamTransform({
|
|
|
4810
4845
|
}
|
|
4811
4846
|
|
|
4812
4847
|
// src/interactions/convert-to-google-interactions-input.ts
|
|
4813
|
-
var
|
|
4848
|
+
var import_provider_utils19 = require("@ai-sdk/provider-utils");
|
|
4814
4849
|
function getTopLevelMediaType(mediaType) {
|
|
4815
4850
|
const slashIndex = mediaType.indexOf("/");
|
|
4816
4851
|
return slashIndex === -1 ? mediaType : mediaType.substring(0, slashIndex);
|
|
@@ -4999,7 +5034,7 @@ function convertFilePartToContent({
|
|
|
4999
5034
|
}
|
|
5000
5035
|
return {
|
|
5001
5036
|
type: kind,
|
|
5002
|
-
data: (0,
|
|
5037
|
+
data: (0, import_provider_utils19.convertToBase64)(part.data),
|
|
5003
5038
|
mime_type: part.mediaType,
|
|
5004
5039
|
...resolutionField
|
|
5005
5040
|
};
|
|
@@ -5050,7 +5085,7 @@ function compactPromptForPreviousInteraction({
|
|
|
5050
5085
|
}
|
|
5051
5086
|
function safeParseToolArgs(input) {
|
|
5052
5087
|
try {
|
|
5053
|
-
const parsed = (0,
|
|
5088
|
+
const parsed = (0, import_provider_utils19.secureJsonParse)(input);
|
|
5054
5089
|
if (parsed != null && typeof parsed === "object" && !Array.isArray(parsed)) {
|
|
5055
5090
|
return parsed;
|
|
5056
5091
|
}
|
|
@@ -5173,7 +5208,7 @@ function filePartToImageBlock({
|
|
|
5173
5208
|
}
|
|
5174
5209
|
return {
|
|
5175
5210
|
type: "image",
|
|
5176
|
-
data: (0,
|
|
5211
|
+
data: (0, import_provider_utils19.convertToBase64)(part.data),
|
|
5177
5212
|
mime_type: part.mediaType
|
|
5178
5213
|
};
|
|
5179
5214
|
}
|
|
@@ -5200,7 +5235,7 @@ ${block.text}`
|
|
|
5200
5235
|
}
|
|
5201
5236
|
|
|
5202
5237
|
// src/interactions/google-interactions-api.ts
|
|
5203
|
-
var
|
|
5238
|
+
var import_provider_utils20 = require("@ai-sdk/provider-utils");
|
|
5204
5239
|
var import_v417 = require("zod/v4");
|
|
5205
5240
|
var tokenByModalitySchema = () => import_v417.z.object({
|
|
5206
5241
|
modality: import_v417.z.string().nullish(),
|
|
@@ -5363,8 +5398,8 @@ var stepSchema = () => {
|
|
|
5363
5398
|
import_v417.z.object({ type: import_v417.z.string() }).loose()
|
|
5364
5399
|
]);
|
|
5365
5400
|
};
|
|
5366
|
-
var googleInteractionsResponseSchema = (0,
|
|
5367
|
-
() => (0,
|
|
5401
|
+
var googleInteractionsResponseSchema = (0, import_provider_utils20.lazySchema)(
|
|
5402
|
+
() => (0, import_provider_utils20.zodSchema)(
|
|
5368
5403
|
import_v417.z.object({
|
|
5369
5404
|
/*
|
|
5370
5405
|
* `id` is omitted from the response body when `store: false` (fully
|
|
@@ -5385,8 +5420,8 @@ var googleInteractionsResponseSchema = (0, import_provider_utils19.lazySchema)(
|
|
|
5385
5420
|
}).loose()
|
|
5386
5421
|
)
|
|
5387
5422
|
);
|
|
5388
|
-
var googleInteractionsEventSchema = (0,
|
|
5389
|
-
() => (0,
|
|
5423
|
+
var googleInteractionsEventSchema = (0, import_provider_utils20.lazySchema)(
|
|
5424
|
+
() => (0, import_provider_utils20.zodSchema)(
|
|
5390
5425
|
(() => {
|
|
5391
5426
|
const status = interactionStatusSchema();
|
|
5392
5427
|
const annotation = annotationSchema();
|
|
@@ -5543,10 +5578,10 @@ var googleInteractionsEventSchema = (0, import_provider_utils19.lazySchema)(
|
|
|
5543
5578
|
);
|
|
5544
5579
|
|
|
5545
5580
|
// src/interactions/google-interactions-language-model-options.ts
|
|
5546
|
-
var
|
|
5581
|
+
var import_provider_utils21 = require("@ai-sdk/provider-utils");
|
|
5547
5582
|
var import_v418 = require("zod/v4");
|
|
5548
|
-
var googleInteractionsLanguageModelOptions = (0,
|
|
5549
|
-
() => (0,
|
|
5583
|
+
var googleInteractionsLanguageModelOptions = (0, import_provider_utils21.lazySchema)(
|
|
5584
|
+
() => (0, import_provider_utils21.zodSchema)(
|
|
5550
5585
|
import_v418.z.object({
|
|
5551
5586
|
previousInteractionId: import_v418.z.string().nullish(),
|
|
5552
5587
|
store: import_v418.z.boolean().nullish(),
|
|
@@ -5913,10 +5948,10 @@ function parseGoogleInteractionsOutputs({
|
|
|
5913
5948
|
}
|
|
5914
5949
|
|
|
5915
5950
|
// src/interactions/poll-google-interactions.ts
|
|
5916
|
-
var
|
|
5951
|
+
var import_provider_utils23 = require("@ai-sdk/provider-utils");
|
|
5917
5952
|
|
|
5918
5953
|
// src/interactions/cancel-google-interaction.ts
|
|
5919
|
-
var
|
|
5954
|
+
var import_provider_utils22 = require("@ai-sdk/provider-utils");
|
|
5920
5955
|
var getOriginalFetch = () => globalThis.fetch;
|
|
5921
5956
|
async function cancelGoogleInteraction({
|
|
5922
5957
|
baseURL,
|
|
@@ -5931,9 +5966,9 @@ async function cancelGoogleInteraction({
|
|
|
5931
5966
|
try {
|
|
5932
5967
|
const response = await fetch(url, {
|
|
5933
5968
|
method: "POST",
|
|
5934
|
-
headers: (0,
|
|
5935
|
-
(0,
|
|
5936
|
-
(0,
|
|
5969
|
+
headers: (0, import_provider_utils22.withUserAgentSuffix)(
|
|
5970
|
+
(0, import_provider_utils22.combineHeaders)({ "Content-Type": "application/json" }, headers),
|
|
5971
|
+
(0, import_provider_utils22.getRuntimeEnvironmentUserAgent)()
|
|
5937
5972
|
),
|
|
5938
5973
|
body: "{}"
|
|
5939
5974
|
});
|
|
@@ -5983,16 +6018,16 @@ async function pollGoogleInteractionUntilTerminal({
|
|
|
5983
6018
|
`google.interactions: timed out polling interaction ${interactionId} after ${timeoutMs}ms.`
|
|
5984
6019
|
);
|
|
5985
6020
|
}
|
|
5986
|
-
await (0,
|
|
6021
|
+
await (0, import_provider_utils23.delay)(nextDelayMs, { abortSignal });
|
|
5987
6022
|
const {
|
|
5988
6023
|
value: response,
|
|
5989
6024
|
rawValue: rawResponse,
|
|
5990
6025
|
responseHeaders
|
|
5991
|
-
} = await (0,
|
|
6026
|
+
} = await (0, import_provider_utils23.getFromApi)({
|
|
5992
6027
|
url,
|
|
5993
6028
|
headers,
|
|
5994
6029
|
failedResponseHandler: googleFailedResponseHandler,
|
|
5995
|
-
successfulResponseHandler: (0,
|
|
6030
|
+
successfulResponseHandler: (0, import_provider_utils23.createJsonResponseHandler)(
|
|
5996
6031
|
googleInteractionsResponseSchema
|
|
5997
6032
|
),
|
|
5998
6033
|
abortSignal,
|
|
@@ -6004,7 +6039,7 @@ async function pollGoogleInteractionUntilTerminal({
|
|
|
6004
6039
|
nextDelayMs = Math.min(nextDelayMs * 2, maxDelayMs);
|
|
6005
6040
|
}
|
|
6006
6041
|
} catch (error) {
|
|
6007
|
-
if ((0,
|
|
6042
|
+
if ((0, import_provider_utils23.isAbortError)(error)) {
|
|
6008
6043
|
await cancelOnServer();
|
|
6009
6044
|
}
|
|
6010
6045
|
throw error;
|
|
@@ -6160,7 +6195,7 @@ function prepareGoogleInteractionsTools({
|
|
|
6160
6195
|
}
|
|
6161
6196
|
|
|
6162
6197
|
// src/interactions/stream-google-interactions.ts
|
|
6163
|
-
var
|
|
6198
|
+
var import_provider_utils24 = require("@ai-sdk/provider-utils");
|
|
6164
6199
|
var DEFAULT_MAX_RETRIES = 3;
|
|
6165
6200
|
var DEFAULT_RETRY_DELAY_MS = 500;
|
|
6166
6201
|
function streamGoogleInteractionEvents({
|
|
@@ -6207,11 +6242,11 @@ function streamGoogleInteractionEvents({
|
|
|
6207
6242
|
return `${base}?${params.toString()}`;
|
|
6208
6243
|
}
|
|
6209
6244
|
async function openReader() {
|
|
6210
|
-
const { value: stream } = await (0,
|
|
6245
|
+
const { value: stream } = await (0, import_provider_utils24.getFromApi)({
|
|
6211
6246
|
url: buildUrl(),
|
|
6212
6247
|
headers: eventSourceHeaders,
|
|
6213
6248
|
failedResponseHandler: googleFailedResponseHandler,
|
|
6214
|
-
successfulResponseHandler: (0,
|
|
6249
|
+
successfulResponseHandler: (0, import_provider_utils24.createEventSourceResponseHandler)(
|
|
6215
6250
|
googleInteractionsEventSchema
|
|
6216
6251
|
),
|
|
6217
6252
|
abortSignal: effectiveSignal,
|
|
@@ -6228,7 +6263,7 @@ function streamGoogleInteractionEvents({
|
|
|
6228
6263
|
currentReader = await openReader();
|
|
6229
6264
|
receivedAnyEventThisAttempt = false;
|
|
6230
6265
|
} catch (error) {
|
|
6231
|
-
if ((0,
|
|
6266
|
+
if ((0, import_provider_utils24.isAbortError)(error) || effectiveSignal.aborted) {
|
|
6232
6267
|
controller.error(error);
|
|
6233
6268
|
return;
|
|
6234
6269
|
}
|
|
@@ -6237,7 +6272,7 @@ function streamGoogleInteractionEvents({
|
|
|
6237
6272
|
controller.error(error);
|
|
6238
6273
|
return;
|
|
6239
6274
|
}
|
|
6240
|
-
await (0,
|
|
6275
|
+
await (0, import_provider_utils24.delay)(retryDelayMs * attempt, {
|
|
6241
6276
|
abortSignal: effectiveSignal
|
|
6242
6277
|
});
|
|
6243
6278
|
continue;
|
|
@@ -6258,7 +6293,7 @@ function streamGoogleInteractionEvents({
|
|
|
6258
6293
|
);
|
|
6259
6294
|
return;
|
|
6260
6295
|
}
|
|
6261
|
-
await (0,
|
|
6296
|
+
await (0, import_provider_utils24.delay)(retryDelayMs * attempt, {
|
|
6262
6297
|
abortSignal: effectiveSignal
|
|
6263
6298
|
});
|
|
6264
6299
|
} else {
|
|
@@ -6278,7 +6313,7 @@ function streamGoogleInteractionEvents({
|
|
|
6278
6313
|
}
|
|
6279
6314
|
controller.enqueue(value);
|
|
6280
6315
|
} catch (error) {
|
|
6281
|
-
if ((0,
|
|
6316
|
+
if ((0, import_provider_utils24.isAbortError)(error) || effectiveSignal.aborted) {
|
|
6282
6317
|
controller.error(error);
|
|
6283
6318
|
return;
|
|
6284
6319
|
}
|
|
@@ -6288,7 +6323,7 @@ function streamGoogleInteractionEvents({
|
|
|
6288
6323
|
controller.error(error);
|
|
6289
6324
|
return;
|
|
6290
6325
|
}
|
|
6291
|
-
await (0,
|
|
6326
|
+
await (0, import_provider_utils24.delay)(retryDelayMs * attempt, {
|
|
6292
6327
|
abortSignal: effectiveSignal
|
|
6293
6328
|
});
|
|
6294
6329
|
}
|
|
@@ -6500,7 +6535,7 @@ var GoogleInteractionsLanguageModel = class {
|
|
|
6500
6535
|
async getArgs(options) {
|
|
6501
6536
|
var _a2, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o, _p, _q, _r, _s, _t, _u, _v, _w, _x, _y, _z, _A, _B, _C, _D, _E, _F;
|
|
6502
6537
|
const warnings = [];
|
|
6503
|
-
const opts = await (0,
|
|
6538
|
+
const opts = await (0, import_provider_utils25.parseProviderOptions)({
|
|
6504
6539
|
provider: "google",
|
|
6505
6540
|
providerOptions: options.providerOptions,
|
|
6506
6541
|
schema: googleInteractionsLanguageModelOptions
|
|
@@ -6757,17 +6792,17 @@ var GoogleInteractionsLanguageModel = class {
|
|
|
6757
6792
|
var _a2, _b, _c, _d, _e, _f;
|
|
6758
6793
|
const { args, warnings, isAgent, isBackground, pollingTimeoutMs } = await this.getArgs(options);
|
|
6759
6794
|
const url = `${this.config.baseURL}/interactions`;
|
|
6760
|
-
const mergedHeaders = (0,
|
|
6795
|
+
const mergedHeaders = (0, import_provider_utils25.combineHeaders)(
|
|
6761
6796
|
INTERACTIONS_API_REVISION_HEADER,
|
|
6762
|
-
this.config.headers ? await (0,
|
|
6797
|
+
this.config.headers ? await (0, import_provider_utils25.resolve)(this.config.headers) : void 0,
|
|
6763
6798
|
options.headers
|
|
6764
6799
|
);
|
|
6765
|
-
const postResult = await (0,
|
|
6800
|
+
const postResult = await (0, import_provider_utils25.postJsonToApi)({
|
|
6766
6801
|
url,
|
|
6767
6802
|
headers: mergedHeaders,
|
|
6768
6803
|
body: args,
|
|
6769
6804
|
failedResponseHandler: googleFailedResponseHandler,
|
|
6770
|
-
successfulResponseHandler: (0,
|
|
6805
|
+
successfulResponseHandler: (0, import_provider_utils25.createJsonResponseHandler)(
|
|
6771
6806
|
googleInteractionsResponseSchema
|
|
6772
6807
|
),
|
|
6773
6808
|
abortSignal: options.abortSignal,
|
|
@@ -6794,7 +6829,7 @@ var GoogleInteractionsLanguageModel = class {
|
|
|
6794
6829
|
const interactionId = typeof response.id === "string" && response.id.length > 0 ? response.id : void 0;
|
|
6795
6830
|
const { content, hasFunctionCall } = parseGoogleInteractionsOutputs({
|
|
6796
6831
|
steps: (_b = response.steps) != null ? _b : null,
|
|
6797
|
-
generateId: (_c = this.config.generateId) != null ? _c :
|
|
6832
|
+
generateId: (_c = this.config.generateId) != null ? _c : import_provider_utils25.generateId,
|
|
6798
6833
|
interactionId
|
|
6799
6834
|
});
|
|
6800
6835
|
const finishReason = {
|
|
@@ -6842,9 +6877,9 @@ var GoogleInteractionsLanguageModel = class {
|
|
|
6842
6877
|
var _a2;
|
|
6843
6878
|
const { args, warnings, isBackground, pollingTimeoutMs } = await this.getArgs(options);
|
|
6844
6879
|
const url = `${this.config.baseURL}/interactions`;
|
|
6845
|
-
const mergedHeaders = (0,
|
|
6880
|
+
const mergedHeaders = (0, import_provider_utils25.combineHeaders)(
|
|
6846
6881
|
INTERACTIONS_API_REVISION_HEADER,
|
|
6847
|
-
this.config.headers ? await (0,
|
|
6882
|
+
this.config.headers ? await (0, import_provider_utils25.resolve)(this.config.headers) : void 0,
|
|
6848
6883
|
options.headers
|
|
6849
6884
|
);
|
|
6850
6885
|
if (isBackground) {
|
|
@@ -6858,12 +6893,12 @@ var GoogleInteractionsLanguageModel = class {
|
|
|
6858
6893
|
});
|
|
6859
6894
|
}
|
|
6860
6895
|
const body = { ...args, stream: true };
|
|
6861
|
-
const { responseHeaders, value: response } = await (0,
|
|
6896
|
+
const { responseHeaders, value: response } = await (0, import_provider_utils25.postJsonToApi)({
|
|
6862
6897
|
url,
|
|
6863
6898
|
headers: mergedHeaders,
|
|
6864
6899
|
body,
|
|
6865
6900
|
failedResponseHandler: googleFailedResponseHandler,
|
|
6866
|
-
successfulResponseHandler: (0,
|
|
6901
|
+
successfulResponseHandler: (0, import_provider_utils25.createEventSourceResponseHandler)(
|
|
6867
6902
|
googleInteractionsEventSchema
|
|
6868
6903
|
),
|
|
6869
6904
|
abortSignal: options.abortSignal,
|
|
@@ -6872,7 +6907,7 @@ var GoogleInteractionsLanguageModel = class {
|
|
|
6872
6907
|
const headerServiceTier = responseHeaders == null ? void 0 : responseHeaders["x-gemini-service-tier"];
|
|
6873
6908
|
const transform = buildGoogleInteractionsStreamTransform({
|
|
6874
6909
|
warnings,
|
|
6875
|
-
generateId: (_a2 = this.config.generateId) != null ? _a2 :
|
|
6910
|
+
generateId: (_a2 = this.config.generateId) != null ? _a2 : import_provider_utils25.generateId,
|
|
6876
6911
|
includeRawChunks: options.includeRawChunks,
|
|
6877
6912
|
serviceTier: headerServiceTier
|
|
6878
6913
|
});
|
|
@@ -6909,12 +6944,12 @@ var GoogleInteractionsLanguageModel = class {
|
|
|
6909
6944
|
pollingTimeoutMs
|
|
6910
6945
|
}) {
|
|
6911
6946
|
var _a2, _b;
|
|
6912
|
-
const postResult = await (0,
|
|
6947
|
+
const postResult = await (0, import_provider_utils25.postJsonToApi)({
|
|
6913
6948
|
url,
|
|
6914
6949
|
headers: mergedHeaders,
|
|
6915
6950
|
body: args,
|
|
6916
6951
|
failedResponseHandler: googleFailedResponseHandler,
|
|
6917
|
-
successfulResponseHandler: (0,
|
|
6952
|
+
successfulResponseHandler: (0, import_provider_utils25.createJsonResponseHandler)(
|
|
6918
6953
|
googleInteractionsResponseSchema
|
|
6919
6954
|
),
|
|
6920
6955
|
abortSignal: options.abortSignal,
|
|
@@ -6932,7 +6967,7 @@ var GoogleInteractionsLanguageModel = class {
|
|
|
6932
6967
|
const synthesized = synthesizeGoogleInteractionsAgentStream({
|
|
6933
6968
|
response: postResponse,
|
|
6934
6969
|
warnings,
|
|
6935
|
-
generateId: (_a2 = this.config.generateId) != null ? _a2 :
|
|
6970
|
+
generateId: (_a2 = this.config.generateId) != null ? _a2 : import_provider_utils25.generateId,
|
|
6936
6971
|
includeRawChunks: options.includeRawChunks,
|
|
6937
6972
|
headerServiceTier
|
|
6938
6973
|
});
|
|
@@ -6952,7 +6987,7 @@ var GoogleInteractionsLanguageModel = class {
|
|
|
6952
6987
|
});
|
|
6953
6988
|
const transform = buildGoogleInteractionsStreamTransform({
|
|
6954
6989
|
warnings,
|
|
6955
|
-
generateId: (_b = this.config.generateId) != null ? _b :
|
|
6990
|
+
generateId: (_b = this.config.generateId) != null ? _b : import_provider_utils25.generateId,
|
|
6956
6991
|
includeRawChunks: options.includeRawChunks,
|
|
6957
6992
|
serviceTier: headerServiceTier
|
|
6958
6993
|
});
|
|
@@ -7006,11 +7041,11 @@ function supportsExternalFileUrls(modelId) {
|
|
|
7006
7041
|
}
|
|
7007
7042
|
function createGoogleGenerativeAI(options = {}) {
|
|
7008
7043
|
var _a2, _b;
|
|
7009
|
-
const baseURL = (_a2 = (0,
|
|
7044
|
+
const baseURL = (_a2 = (0, import_provider_utils26.withoutTrailingSlash)(options.baseURL)) != null ? _a2 : "https://generativelanguage.googleapis.com/v1beta";
|
|
7010
7045
|
const providerName = (_b = options.name) != null ? _b : "google.generative-ai";
|
|
7011
|
-
const getHeaders = () => (0,
|
|
7046
|
+
const getHeaders = () => (0, import_provider_utils26.withUserAgentSuffix)(
|
|
7012
7047
|
{
|
|
7013
|
-
"x-goog-api-key": (0,
|
|
7048
|
+
"x-goog-api-key": (0, import_provider_utils26.loadApiKey)({
|
|
7014
7049
|
apiKey: options.apiKey,
|
|
7015
7050
|
environmentVariableName: "GOOGLE_GENERATIVE_AI_API_KEY",
|
|
7016
7051
|
description: "Google Generative AI"
|
|
@@ -7025,7 +7060,7 @@ function createGoogleGenerativeAI(options = {}) {
|
|
|
7025
7060
|
provider: providerName,
|
|
7026
7061
|
baseURL,
|
|
7027
7062
|
headers: getHeaders,
|
|
7028
|
-
generateId: (_a3 = options.generateId) != null ? _a3 :
|
|
7063
|
+
generateId: (_a3 = options.generateId) != null ? _a3 : import_provider_utils26.generateId,
|
|
7029
7064
|
supportedUrls: () => ({
|
|
7030
7065
|
"*": [
|
|
7031
7066
|
// Google Generative Language "files" endpoint
|
|
@@ -7072,7 +7107,7 @@ function createGoogleGenerativeAI(options = {}) {
|
|
|
7072
7107
|
baseURL,
|
|
7073
7108
|
headers: getHeaders,
|
|
7074
7109
|
fetch: options.fetch,
|
|
7075
|
-
generateId: (_a3 = options.generateId) != null ? _a3 :
|
|
7110
|
+
generateId: (_a3 = options.generateId) != null ? _a3 : import_provider_utils26.generateId
|
|
7076
7111
|
});
|
|
7077
7112
|
};
|
|
7078
7113
|
const createInteractionsModel = (modelIdOrAgent) => {
|
|
@@ -7083,7 +7118,7 @@ function createGoogleGenerativeAI(options = {}) {
|
|
|
7083
7118
|
provider: `${providerName}.interactions`,
|
|
7084
7119
|
baseURL,
|
|
7085
7120
|
headers: getHeaders,
|
|
7086
|
-
generateId: (_a3 = options.generateId) != null ? _a3 :
|
|
7121
|
+
generateId: (_a3 = options.generateId) != null ? _a3 : import_provider_utils26.generateId,
|
|
7087
7122
|
fetch: options.fetch
|
|
7088
7123
|
}
|
|
7089
7124
|
);
|