@ai-sdk/google 4.0.0-beta.3 → 4.0.0-beta.30
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 +201 -4
- package/README.md +2 -0
- package/dist/index.d.mts +73 -23
- package/dist/index.d.ts +73 -23
- package/dist/index.js +756 -136
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +767 -130
- package/dist/index.mjs.map +1 -1
- package/dist/internal/index.d.mts +42 -15
- package/dist/internal/index.d.ts +42 -15
- package/dist/internal/index.js +499 -74
- package/dist/internal/index.js.map +1 -1
- package/dist/internal/index.mjs +504 -72
- package/dist/internal/index.mjs.map +1 -1
- package/docs/15-google-generative-ai.mdx +36 -3
- package/package.json +3 -5
- package/src/convert-google-generative-ai-usage.ts +9 -2
- package/src/convert-to-google-generative-ai-messages.ts +330 -50
- package/src/google-generative-ai-embedding-model.ts +42 -13
- package/src/google-generative-ai-embedding-options.ts +24 -0
- package/src/google-generative-ai-files.ts +230 -0
- package/src/google-generative-ai-image-model.ts +14 -14
- package/src/google-generative-ai-language-model.ts +317 -44
- package/src/google-generative-ai-options.ts +5 -1
- package/src/google-generative-ai-prompt.ts +48 -4
- package/src/google-generative-ai-video-model.ts +7 -7
- package/src/google-prepare-tools.ts +64 -9
- package/src/google-provider.ts +31 -18
- package/src/index.ts +1 -0
- package/src/map-google-generative-ai-finish-reason.ts +2 -2
package/dist/index.js
CHANGED
|
@@ -18,19 +18,19 @@ var __copyProps = (to, from, except, desc) => {
|
|
|
18
18
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
19
|
|
|
20
20
|
// src/index.ts
|
|
21
|
-
var
|
|
22
|
-
__export(
|
|
21
|
+
var index_exports = {};
|
|
22
|
+
__export(index_exports, {
|
|
23
23
|
VERSION: () => VERSION,
|
|
24
24
|
createGoogleGenerativeAI: () => createGoogleGenerativeAI,
|
|
25
25
|
google: () => google
|
|
26
26
|
});
|
|
27
|
-
module.exports = __toCommonJS(
|
|
27
|
+
module.exports = __toCommonJS(index_exports);
|
|
28
28
|
|
|
29
29
|
// src/google-provider.ts
|
|
30
|
-
var
|
|
30
|
+
var import_provider_utils17 = require("@ai-sdk/provider-utils");
|
|
31
31
|
|
|
32
32
|
// src/version.ts
|
|
33
|
-
var VERSION = true ? "4.0.0-beta.
|
|
33
|
+
var VERSION = true ? "4.0.0-beta.30" : "0.0.0-test";
|
|
34
34
|
|
|
35
35
|
// src/google-generative-ai-embedding-model.ts
|
|
36
36
|
var import_provider = require("@ai-sdk/provider");
|
|
@@ -59,6 +59,15 @@ var googleFailedResponseHandler = (0, import_provider_utils.createJsonErrorRespo
|
|
|
59
59
|
// src/google-generative-ai-embedding-options.ts
|
|
60
60
|
var import_provider_utils2 = require("@ai-sdk/provider-utils");
|
|
61
61
|
var import_v42 = require("zod/v4");
|
|
62
|
+
var googleEmbeddingContentPartSchema = import_v42.z.union([
|
|
63
|
+
import_v42.z.object({ text: import_v42.z.string() }),
|
|
64
|
+
import_v42.z.object({
|
|
65
|
+
inlineData: import_v42.z.object({
|
|
66
|
+
mimeType: import_v42.z.string(),
|
|
67
|
+
data: import_v42.z.string()
|
|
68
|
+
})
|
|
69
|
+
})
|
|
70
|
+
]);
|
|
62
71
|
var googleEmbeddingModelOptions = (0, import_provider_utils2.lazySchema)(
|
|
63
72
|
() => (0, import_provider_utils2.zodSchema)(
|
|
64
73
|
import_v42.z.object({
|
|
@@ -88,7 +97,17 @@ var googleEmbeddingModelOptions = (0, import_provider_utils2.lazySchema)(
|
|
|
88
97
|
"QUESTION_ANSWERING",
|
|
89
98
|
"FACT_VERIFICATION",
|
|
90
99
|
"CODE_RETRIEVAL_QUERY"
|
|
91
|
-
]).optional()
|
|
100
|
+
]).optional(),
|
|
101
|
+
/**
|
|
102
|
+
* Optional. Per-value multimodal content parts for embedding non-text
|
|
103
|
+
* content (images, video, PDF, audio). Each entry corresponds to the
|
|
104
|
+
* embedding value at the same index and its parts are merged with the
|
|
105
|
+
* text value in the request. Use `null` for entries that are text-only.
|
|
106
|
+
*
|
|
107
|
+
* The array length must match the number of values being embedded. In
|
|
108
|
+
* the case of a single embedding, the array length must be 1.
|
|
109
|
+
*/
|
|
110
|
+
content: import_v42.z.array(import_v42.z.array(googleEmbeddingContentPartSchema).min(1).nullable()).optional()
|
|
92
111
|
})
|
|
93
112
|
)
|
|
94
113
|
);
|
|
@@ -96,7 +115,7 @@ var googleEmbeddingModelOptions = (0, import_provider_utils2.lazySchema)(
|
|
|
96
115
|
// src/google-generative-ai-embedding-model.ts
|
|
97
116
|
var GoogleGenerativeAIEmbeddingModel = class {
|
|
98
117
|
constructor(modelId, config) {
|
|
99
|
-
this.specificationVersion = "
|
|
118
|
+
this.specificationVersion = "v4";
|
|
100
119
|
this.maxEmbeddingsPerCall = 2048;
|
|
101
120
|
this.supportsParallelCalls = true;
|
|
102
121
|
this.modelId = modelId;
|
|
@@ -128,7 +147,16 @@ var GoogleGenerativeAIEmbeddingModel = class {
|
|
|
128
147
|
await (0, import_provider_utils3.resolve)(this.config.headers),
|
|
129
148
|
headers
|
|
130
149
|
);
|
|
150
|
+
const multimodalContent = googleOptions == null ? void 0 : googleOptions.content;
|
|
151
|
+
if (multimodalContent != null && multimodalContent.length !== values.length) {
|
|
152
|
+
throw new Error(
|
|
153
|
+
`The number of multimodal content entries (${multimodalContent.length}) must match the number of values (${values.length}).`
|
|
154
|
+
);
|
|
155
|
+
}
|
|
131
156
|
if (values.length === 1) {
|
|
157
|
+
const valueParts = multimodalContent == null ? void 0 : multimodalContent[0];
|
|
158
|
+
const textPart = values[0] ? [{ text: values[0] }] : [];
|
|
159
|
+
const parts = valueParts != null ? [...textPart, ...valueParts] : [{ text: values[0] }];
|
|
132
160
|
const {
|
|
133
161
|
responseHeaders: responseHeaders2,
|
|
134
162
|
value: response2,
|
|
@@ -139,7 +167,7 @@ var GoogleGenerativeAIEmbeddingModel = class {
|
|
|
139
167
|
body: {
|
|
140
168
|
model: `models/${this.modelId}`,
|
|
141
169
|
content: {
|
|
142
|
-
parts
|
|
170
|
+
parts
|
|
143
171
|
},
|
|
144
172
|
outputDimensionality: googleOptions == null ? void 0 : googleOptions.outputDimensionality,
|
|
145
173
|
taskType: googleOptions == null ? void 0 : googleOptions.taskType
|
|
@@ -166,12 +194,19 @@ var GoogleGenerativeAIEmbeddingModel = class {
|
|
|
166
194
|
url: `${this.config.baseURL}/models/${this.modelId}:batchEmbedContents`,
|
|
167
195
|
headers: mergedHeaders,
|
|
168
196
|
body: {
|
|
169
|
-
requests: values.map((value) =>
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
197
|
+
requests: values.map((value, index) => {
|
|
198
|
+
const valueParts = multimodalContent == null ? void 0 : multimodalContent[index];
|
|
199
|
+
const textPart = value ? [{ text: value }] : [];
|
|
200
|
+
return {
|
|
201
|
+
model: `models/${this.modelId}`,
|
|
202
|
+
content: {
|
|
203
|
+
role: "user",
|
|
204
|
+
parts: valueParts != null ? [...textPart, ...valueParts] : [{ text: value }]
|
|
205
|
+
},
|
|
206
|
+
outputDimensionality: googleOptions == null ? void 0 : googleOptions.outputDimensionality,
|
|
207
|
+
taskType: googleOptions == null ? void 0 : googleOptions.taskType
|
|
208
|
+
};
|
|
209
|
+
})
|
|
175
210
|
},
|
|
176
211
|
failedResponseHandler: googleFailedResponseHandler,
|
|
177
212
|
successfulResponseHandler: (0, import_provider_utils3.createJsonResponseHandler)(
|
|
@@ -365,13 +400,118 @@ function isEmptyObjectSchema(jsonSchema) {
|
|
|
365
400
|
// src/convert-to-google-generative-ai-messages.ts
|
|
366
401
|
var import_provider2 = require("@ai-sdk/provider");
|
|
367
402
|
var import_provider_utils4 = require("@ai-sdk/provider-utils");
|
|
403
|
+
var dataUrlRegex = /^data:([^;,]+);base64,(.+)$/s;
|
|
404
|
+
function parseBase64DataUrl(value) {
|
|
405
|
+
const match = dataUrlRegex.exec(value);
|
|
406
|
+
if (match == null) {
|
|
407
|
+
return void 0;
|
|
408
|
+
}
|
|
409
|
+
return {
|
|
410
|
+
mediaType: match[1],
|
|
411
|
+
data: match[2]
|
|
412
|
+
};
|
|
413
|
+
}
|
|
414
|
+
function convertUrlToolResultPart(url) {
|
|
415
|
+
const parsedDataUrl = parseBase64DataUrl(url);
|
|
416
|
+
if (parsedDataUrl == null) {
|
|
417
|
+
return void 0;
|
|
418
|
+
}
|
|
419
|
+
return {
|
|
420
|
+
inlineData: {
|
|
421
|
+
mimeType: parsedDataUrl.mediaType,
|
|
422
|
+
data: parsedDataUrl.data
|
|
423
|
+
}
|
|
424
|
+
};
|
|
425
|
+
}
|
|
426
|
+
function appendToolResultParts(parts, toolName, outputValue) {
|
|
427
|
+
const functionResponseParts = [];
|
|
428
|
+
const responseTextParts = [];
|
|
429
|
+
for (const contentPart of outputValue) {
|
|
430
|
+
switch (contentPart.type) {
|
|
431
|
+
case "text": {
|
|
432
|
+
responseTextParts.push(contentPart.text);
|
|
433
|
+
break;
|
|
434
|
+
}
|
|
435
|
+
case "image-data":
|
|
436
|
+
case "file-data": {
|
|
437
|
+
functionResponseParts.push({
|
|
438
|
+
inlineData: {
|
|
439
|
+
mimeType: contentPart.mediaType,
|
|
440
|
+
data: contentPart.data
|
|
441
|
+
}
|
|
442
|
+
});
|
|
443
|
+
break;
|
|
444
|
+
}
|
|
445
|
+
case "image-url":
|
|
446
|
+
case "file-url": {
|
|
447
|
+
const functionResponsePart = convertUrlToolResultPart(
|
|
448
|
+
contentPart.url
|
|
449
|
+
);
|
|
450
|
+
if (functionResponsePart != null) {
|
|
451
|
+
functionResponseParts.push(functionResponsePart);
|
|
452
|
+
} else {
|
|
453
|
+
responseTextParts.push(JSON.stringify(contentPart));
|
|
454
|
+
}
|
|
455
|
+
break;
|
|
456
|
+
}
|
|
457
|
+
default: {
|
|
458
|
+
responseTextParts.push(JSON.stringify(contentPart));
|
|
459
|
+
break;
|
|
460
|
+
}
|
|
461
|
+
}
|
|
462
|
+
}
|
|
463
|
+
parts.push({
|
|
464
|
+
functionResponse: {
|
|
465
|
+
name: toolName,
|
|
466
|
+
response: {
|
|
467
|
+
name: toolName,
|
|
468
|
+
content: responseTextParts.length > 0 ? responseTextParts.join("\n") : "Tool executed successfully."
|
|
469
|
+
},
|
|
470
|
+
...functionResponseParts.length > 0 ? { parts: functionResponseParts } : {}
|
|
471
|
+
}
|
|
472
|
+
});
|
|
473
|
+
}
|
|
474
|
+
function appendLegacyToolResultParts(parts, toolName, outputValue) {
|
|
475
|
+
for (const contentPart of outputValue) {
|
|
476
|
+
switch (contentPart.type) {
|
|
477
|
+
case "text":
|
|
478
|
+
parts.push({
|
|
479
|
+
functionResponse: {
|
|
480
|
+
name: toolName,
|
|
481
|
+
response: {
|
|
482
|
+
name: toolName,
|
|
483
|
+
content: contentPart.text
|
|
484
|
+
}
|
|
485
|
+
}
|
|
486
|
+
});
|
|
487
|
+
break;
|
|
488
|
+
case "image-data":
|
|
489
|
+
parts.push(
|
|
490
|
+
{
|
|
491
|
+
inlineData: {
|
|
492
|
+
mimeType: String(contentPart.mediaType),
|
|
493
|
+
data: String(contentPart.data)
|
|
494
|
+
}
|
|
495
|
+
},
|
|
496
|
+
{
|
|
497
|
+
text: "Tool executed successfully and returned this image as a response"
|
|
498
|
+
}
|
|
499
|
+
);
|
|
500
|
+
break;
|
|
501
|
+
default:
|
|
502
|
+
parts.push({ text: JSON.stringify(contentPart) });
|
|
503
|
+
break;
|
|
504
|
+
}
|
|
505
|
+
}
|
|
506
|
+
}
|
|
368
507
|
function convertToGoogleGenerativeAIMessages(prompt, options) {
|
|
369
|
-
var _a, _b, _c;
|
|
508
|
+
var _a, _b, _c, _d, _e, _f, _g, _h;
|
|
370
509
|
const systemInstructionParts = [];
|
|
371
510
|
const contents = [];
|
|
372
511
|
let systemMessagesAllowed = true;
|
|
373
512
|
const isGemmaModel = (_a = options == null ? void 0 : options.isGemmaModel) != null ? _a : false;
|
|
374
513
|
const providerOptionsName = (_b = options == null ? void 0 : options.providerOptionsName) != null ? _b : "google";
|
|
514
|
+
const supportsFunctionResponseParts = (_c = options == null ? void 0 : options.supportsFunctionResponseParts) != null ? _c : true;
|
|
375
515
|
for (const { role, content } of prompt) {
|
|
376
516
|
switch (role) {
|
|
377
517
|
case "system": {
|
|
@@ -394,19 +534,36 @@ function convertToGoogleGenerativeAIMessages(prompt, options) {
|
|
|
394
534
|
}
|
|
395
535
|
case "file": {
|
|
396
536
|
const mediaType = part.mediaType === "image/*" ? "image/jpeg" : part.mediaType;
|
|
397
|
-
|
|
398
|
-
|
|
537
|
+
if (part.data instanceof URL) {
|
|
538
|
+
parts.push({
|
|
399
539
|
fileData: {
|
|
400
540
|
mimeType: mediaType,
|
|
401
541
|
fileUri: part.data.toString()
|
|
402
542
|
}
|
|
403
|
-
}
|
|
543
|
+
});
|
|
544
|
+
} else if ((0, import_provider_utils4.isProviderReference)(part.data)) {
|
|
545
|
+
if (providerOptionsName === "vertex") {
|
|
546
|
+
throw new import_provider2.UnsupportedFunctionalityError({
|
|
547
|
+
functionality: "file parts with provider references"
|
|
548
|
+
});
|
|
549
|
+
}
|
|
550
|
+
parts.push({
|
|
551
|
+
fileData: {
|
|
552
|
+
mimeType: mediaType,
|
|
553
|
+
fileUri: (0, import_provider_utils4.resolveProviderReference)({
|
|
554
|
+
reference: part.data,
|
|
555
|
+
provider: "google"
|
|
556
|
+
})
|
|
557
|
+
}
|
|
558
|
+
});
|
|
559
|
+
} else {
|
|
560
|
+
parts.push({
|
|
404
561
|
inlineData: {
|
|
405
562
|
mimeType: mediaType,
|
|
406
563
|
data: (0, import_provider_utils4.convertToBase64)(part.data)
|
|
407
564
|
}
|
|
408
|
-
}
|
|
409
|
-
|
|
565
|
+
});
|
|
566
|
+
}
|
|
410
567
|
break;
|
|
411
568
|
}
|
|
412
569
|
}
|
|
@@ -419,8 +576,8 @@ function convertToGoogleGenerativeAIMessages(prompt, options) {
|
|
|
419
576
|
contents.push({
|
|
420
577
|
role: "model",
|
|
421
578
|
parts: content.map((part) => {
|
|
422
|
-
var _a2, _b2, _c2,
|
|
423
|
-
const providerOpts = (
|
|
579
|
+
var _a2, _b2, _c2, _d2;
|
|
580
|
+
const providerOpts = (_d2 = (_a2 = part.providerOptions) == null ? void 0 : _a2[providerOptionsName]) != null ? _d2 : providerOptionsName !== "google" ? (_b2 = part.providerOptions) == null ? void 0 : _b2.google : (_c2 = part.providerOptions) == null ? void 0 : _c2.vertex;
|
|
424
581
|
const thoughtSignature = (providerOpts == null ? void 0 : providerOpts.thoughtSignature) != null ? String(providerOpts.thoughtSignature) : void 0;
|
|
425
582
|
switch (part.type) {
|
|
426
583
|
case "text": {
|
|
@@ -436,21 +593,67 @@ function convertToGoogleGenerativeAIMessages(prompt, options) {
|
|
|
436
593
|
thoughtSignature
|
|
437
594
|
};
|
|
438
595
|
}
|
|
596
|
+
case "reasoning-file": {
|
|
597
|
+
if (part.data instanceof URL) {
|
|
598
|
+
throw new import_provider2.UnsupportedFunctionalityError({
|
|
599
|
+
functionality: "File data URLs in assistant messages are not supported"
|
|
600
|
+
});
|
|
601
|
+
}
|
|
602
|
+
return {
|
|
603
|
+
inlineData: {
|
|
604
|
+
mimeType: part.mediaType,
|
|
605
|
+
data: (0, import_provider_utils4.convertToBase64)(part.data)
|
|
606
|
+
},
|
|
607
|
+
thought: true,
|
|
608
|
+
thoughtSignature
|
|
609
|
+
};
|
|
610
|
+
}
|
|
439
611
|
case "file": {
|
|
440
612
|
if (part.data instanceof URL) {
|
|
441
613
|
throw new import_provider2.UnsupportedFunctionalityError({
|
|
442
614
|
functionality: "File data URLs in assistant messages are not supported"
|
|
443
615
|
});
|
|
444
616
|
}
|
|
617
|
+
if ((0, import_provider_utils4.isProviderReference)(part.data)) {
|
|
618
|
+
if (providerOptionsName === "vertex") {
|
|
619
|
+
throw new import_provider2.UnsupportedFunctionalityError({
|
|
620
|
+
functionality: "file parts with provider references"
|
|
621
|
+
});
|
|
622
|
+
}
|
|
623
|
+
return {
|
|
624
|
+
fileData: {
|
|
625
|
+
mimeType: part.mediaType,
|
|
626
|
+
fileUri: (0, import_provider_utils4.resolveProviderReference)({
|
|
627
|
+
reference: part.data,
|
|
628
|
+
provider: "google"
|
|
629
|
+
})
|
|
630
|
+
},
|
|
631
|
+
...(providerOpts == null ? void 0 : providerOpts.thought) === true ? { thought: true } : {},
|
|
632
|
+
thoughtSignature
|
|
633
|
+
};
|
|
634
|
+
}
|
|
445
635
|
return {
|
|
446
636
|
inlineData: {
|
|
447
637
|
mimeType: part.mediaType,
|
|
448
638
|
data: (0, import_provider_utils4.convertToBase64)(part.data)
|
|
449
639
|
},
|
|
640
|
+
...(providerOpts == null ? void 0 : providerOpts.thought) === true ? { thought: true } : {},
|
|
450
641
|
thoughtSignature
|
|
451
642
|
};
|
|
452
643
|
}
|
|
453
644
|
case "tool-call": {
|
|
645
|
+
const serverToolCallId = (providerOpts == null ? void 0 : providerOpts.serverToolCallId) != null ? String(providerOpts.serverToolCallId) : void 0;
|
|
646
|
+
const serverToolType = (providerOpts == null ? void 0 : providerOpts.serverToolType) != null ? String(providerOpts.serverToolType) : void 0;
|
|
647
|
+
if (serverToolCallId && serverToolType) {
|
|
648
|
+
return {
|
|
649
|
+
toolCall: {
|
|
650
|
+
toolType: serverToolType,
|
|
651
|
+
args: typeof part.input === "string" ? JSON.parse(part.input) : part.input,
|
|
652
|
+
id: serverToolCallId
|
|
653
|
+
},
|
|
654
|
+
thoughtSignature
|
|
655
|
+
};
|
|
656
|
+
}
|
|
454
657
|
return {
|
|
455
658
|
functionCall: {
|
|
456
659
|
name: part.toolName,
|
|
@@ -459,6 +662,21 @@ function convertToGoogleGenerativeAIMessages(prompt, options) {
|
|
|
459
662
|
thoughtSignature
|
|
460
663
|
};
|
|
461
664
|
}
|
|
665
|
+
case "tool-result": {
|
|
666
|
+
const serverToolCallId = (providerOpts == null ? void 0 : providerOpts.serverToolCallId) != null ? String(providerOpts.serverToolCallId) : void 0;
|
|
667
|
+
const serverToolType = (providerOpts == null ? void 0 : providerOpts.serverToolType) != null ? String(providerOpts.serverToolType) : void 0;
|
|
668
|
+
if (serverToolCallId && serverToolType) {
|
|
669
|
+
return {
|
|
670
|
+
toolResponse: {
|
|
671
|
+
toolType: serverToolType,
|
|
672
|
+
response: part.output.type === "json" ? part.output.value : {},
|
|
673
|
+
id: serverToolCallId
|
|
674
|
+
},
|
|
675
|
+
thoughtSignature
|
|
676
|
+
};
|
|
677
|
+
}
|
|
678
|
+
return void 0;
|
|
679
|
+
}
|
|
462
680
|
}
|
|
463
681
|
}).filter((part) => part !== void 0)
|
|
464
682
|
});
|
|
@@ -471,38 +689,32 @@ function convertToGoogleGenerativeAIMessages(prompt, options) {
|
|
|
471
689
|
if (part.type === "tool-approval-response") {
|
|
472
690
|
continue;
|
|
473
691
|
}
|
|
692
|
+
const partProviderOpts = (_g = (_d = part.providerOptions) == null ? void 0 : _d[providerOptionsName]) != null ? _g : providerOptionsName !== "google" ? (_e = part.providerOptions) == null ? void 0 : _e.google : (_f = part.providerOptions) == null ? void 0 : _f.vertex;
|
|
693
|
+
const serverToolCallId = (partProviderOpts == null ? void 0 : partProviderOpts.serverToolCallId) != null ? String(partProviderOpts.serverToolCallId) : void 0;
|
|
694
|
+
const serverToolType = (partProviderOpts == null ? void 0 : partProviderOpts.serverToolType) != null ? String(partProviderOpts.serverToolType) : void 0;
|
|
695
|
+
if (serverToolCallId && serverToolType) {
|
|
696
|
+
const serverThoughtSignature = (partProviderOpts == null ? void 0 : partProviderOpts.thoughtSignature) != null ? String(partProviderOpts.thoughtSignature) : void 0;
|
|
697
|
+
if (contents.length > 0) {
|
|
698
|
+
const lastContent = contents[contents.length - 1];
|
|
699
|
+
if (lastContent.role === "model") {
|
|
700
|
+
lastContent.parts.push({
|
|
701
|
+
toolResponse: {
|
|
702
|
+
toolType: serverToolType,
|
|
703
|
+
response: part.output.type === "json" ? part.output.value : {},
|
|
704
|
+
id: serverToolCallId
|
|
705
|
+
},
|
|
706
|
+
thoughtSignature: serverThoughtSignature
|
|
707
|
+
});
|
|
708
|
+
continue;
|
|
709
|
+
}
|
|
710
|
+
}
|
|
711
|
+
}
|
|
474
712
|
const output = part.output;
|
|
475
713
|
if (output.type === "content") {
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
functionResponse: {
|
|
481
|
-
name: part.toolName,
|
|
482
|
-
response: {
|
|
483
|
-
name: part.toolName,
|
|
484
|
-
content: contentPart.text
|
|
485
|
-
}
|
|
486
|
-
}
|
|
487
|
-
});
|
|
488
|
-
break;
|
|
489
|
-
case "image-data":
|
|
490
|
-
parts.push(
|
|
491
|
-
{
|
|
492
|
-
inlineData: {
|
|
493
|
-
mimeType: contentPart.mediaType,
|
|
494
|
-
data: contentPart.data
|
|
495
|
-
}
|
|
496
|
-
},
|
|
497
|
-
{
|
|
498
|
-
text: "Tool executed successfully and returned this image as a response"
|
|
499
|
-
}
|
|
500
|
-
);
|
|
501
|
-
break;
|
|
502
|
-
default:
|
|
503
|
-
parts.push({ text: JSON.stringify(contentPart) });
|
|
504
|
-
break;
|
|
505
|
-
}
|
|
714
|
+
if (supportsFunctionResponseParts) {
|
|
715
|
+
appendToolResultParts(parts, part.toolName, output.value);
|
|
716
|
+
} else {
|
|
717
|
+
appendLegacyToolResultParts(parts, part.toolName, output.value);
|
|
506
718
|
}
|
|
507
719
|
} else {
|
|
508
720
|
parts.push({
|
|
@@ -510,7 +722,7 @@ function convertToGoogleGenerativeAIMessages(prompt, options) {
|
|
|
510
722
|
name: part.toolName,
|
|
511
723
|
response: {
|
|
512
724
|
name: part.toolName,
|
|
513
|
-
content: output.type === "execution-denied" ? (
|
|
725
|
+
content: output.type === "execution-denied" ? (_h = output.reason) != null ? _h : "Tool execution denied." : output.value
|
|
514
726
|
}
|
|
515
727
|
}
|
|
516
728
|
});
|
|
@@ -656,7 +868,11 @@ var googleLanguageModelOptions = (0, import_provider_utils5.lazySchema)(
|
|
|
656
868
|
latitude: import_v44.z.number(),
|
|
657
869
|
longitude: import_v44.z.number()
|
|
658
870
|
}).optional()
|
|
659
|
-
}).optional()
|
|
871
|
+
}).optional(),
|
|
872
|
+
/**
|
|
873
|
+
* Optional. The service tier to use for the request.
|
|
874
|
+
*/
|
|
875
|
+
serviceTier: import_v44.z.enum(["standard", "flex", "priority"]).optional()
|
|
660
876
|
})
|
|
661
877
|
)
|
|
662
878
|
);
|
|
@@ -668,7 +884,7 @@ function prepareTools({
|
|
|
668
884
|
toolChoice,
|
|
669
885
|
modelId
|
|
670
886
|
}) {
|
|
671
|
-
var _a;
|
|
887
|
+
var _a, _b;
|
|
672
888
|
tools = (tools == null ? void 0 : tools.length) ? tools : void 0;
|
|
673
889
|
const toolWarnings = [];
|
|
674
890
|
const isLatest = [
|
|
@@ -677,13 +893,14 @@ function prepareTools({
|
|
|
677
893
|
"gemini-pro-latest"
|
|
678
894
|
].some((id) => id === modelId);
|
|
679
895
|
const isGemini2orNewer = modelId.includes("gemini-2") || modelId.includes("gemini-3") || modelId.includes("nano-banana") || isLatest;
|
|
896
|
+
const isGemini3orNewer = modelId.includes("gemini-3");
|
|
680
897
|
const supportsFileSearch = modelId.includes("gemini-2.5") || modelId.includes("gemini-3");
|
|
681
898
|
if (tools == null) {
|
|
682
899
|
return { tools: void 0, toolConfig: void 0, toolWarnings };
|
|
683
900
|
}
|
|
684
901
|
const hasFunctionTools = tools.some((tool) => tool.type === "function");
|
|
685
902
|
const hasProviderTools = tools.some((tool) => tool.type === "provider");
|
|
686
|
-
if (hasFunctionTools && hasProviderTools) {
|
|
903
|
+
if (hasFunctionTools && hasProviderTools && !isGemini3orNewer) {
|
|
687
904
|
toolWarnings.push({
|
|
688
905
|
type: "unsupported",
|
|
689
906
|
feature: `combination of function and provider-defined tools`
|
|
@@ -734,7 +951,7 @@ function prepareTools({
|
|
|
734
951
|
toolWarnings.push({
|
|
735
952
|
type: "unsupported",
|
|
736
953
|
feature: `provider-defined tool ${tool.id}`,
|
|
737
|
-
details: "The code execution
|
|
954
|
+
details: "The code execution tool is not supported with other Gemini models than Gemini 2."
|
|
738
955
|
});
|
|
739
956
|
}
|
|
740
957
|
break;
|
|
@@ -788,6 +1005,45 @@ function prepareTools({
|
|
|
788
1005
|
break;
|
|
789
1006
|
}
|
|
790
1007
|
});
|
|
1008
|
+
if (hasFunctionTools && isGemini3orNewer && googleTools2.length > 0) {
|
|
1009
|
+
const functionDeclarations2 = [];
|
|
1010
|
+
for (const tool of tools) {
|
|
1011
|
+
if (tool.type === "function") {
|
|
1012
|
+
functionDeclarations2.push({
|
|
1013
|
+
name: tool.name,
|
|
1014
|
+
description: (_a = tool.description) != null ? _a : "",
|
|
1015
|
+
parameters: convertJSONSchemaToOpenAPISchema(tool.inputSchema)
|
|
1016
|
+
});
|
|
1017
|
+
}
|
|
1018
|
+
}
|
|
1019
|
+
const combinedToolConfig = {
|
|
1020
|
+
functionCallingConfig: { mode: "VALIDATED" },
|
|
1021
|
+
includeServerSideToolInvocations: true
|
|
1022
|
+
};
|
|
1023
|
+
if (toolChoice != null) {
|
|
1024
|
+
switch (toolChoice.type) {
|
|
1025
|
+
case "auto":
|
|
1026
|
+
break;
|
|
1027
|
+
case "none":
|
|
1028
|
+
combinedToolConfig.functionCallingConfig = { mode: "NONE" };
|
|
1029
|
+
break;
|
|
1030
|
+
case "required":
|
|
1031
|
+
combinedToolConfig.functionCallingConfig = { mode: "ANY" };
|
|
1032
|
+
break;
|
|
1033
|
+
case "tool":
|
|
1034
|
+
combinedToolConfig.functionCallingConfig = {
|
|
1035
|
+
mode: "ANY",
|
|
1036
|
+
allowedFunctionNames: [toolChoice.toolName]
|
|
1037
|
+
};
|
|
1038
|
+
break;
|
|
1039
|
+
}
|
|
1040
|
+
}
|
|
1041
|
+
return {
|
|
1042
|
+
tools: [...googleTools2, { functionDeclarations: functionDeclarations2 }],
|
|
1043
|
+
toolConfig: combinedToolConfig,
|
|
1044
|
+
toolWarnings
|
|
1045
|
+
};
|
|
1046
|
+
}
|
|
791
1047
|
return {
|
|
792
1048
|
tools: googleTools2.length > 0 ? googleTools2 : void 0,
|
|
793
1049
|
toolConfig: void 0,
|
|
@@ -801,7 +1057,7 @@ function prepareTools({
|
|
|
801
1057
|
case "function":
|
|
802
1058
|
functionDeclarations.push({
|
|
803
1059
|
name: tool.name,
|
|
804
|
-
description: (
|
|
1060
|
+
description: (_b = tool.description) != null ? _b : "",
|
|
805
1061
|
parameters: convertJSONSchemaToOpenAPISchema(tool.inputSchema)
|
|
806
1062
|
});
|
|
807
1063
|
if (tool.strict === true) {
|
|
@@ -900,7 +1156,7 @@ function mapGoogleGenerativeAIFinishReason({
|
|
|
900
1156
|
// src/google-generative-ai-language-model.ts
|
|
901
1157
|
var GoogleGenerativeAILanguageModel = class {
|
|
902
1158
|
constructor(modelId, config) {
|
|
903
|
-
this.specificationVersion = "
|
|
1159
|
+
this.specificationVersion = "v4";
|
|
904
1160
|
var _a;
|
|
905
1161
|
this.modelId = modelId;
|
|
906
1162
|
this.config = config;
|
|
@@ -926,6 +1182,7 @@ var GoogleGenerativeAILanguageModel = class {
|
|
|
926
1182
|
seed,
|
|
927
1183
|
tools,
|
|
928
1184
|
toolChoice,
|
|
1185
|
+
reasoning,
|
|
929
1186
|
providerOptions
|
|
930
1187
|
}) {
|
|
931
1188
|
var _a;
|
|
@@ -952,9 +1209,14 @@ var GoogleGenerativeAILanguageModel = class {
|
|
|
952
1209
|
});
|
|
953
1210
|
}
|
|
954
1211
|
const isGemmaModel = this.modelId.toLowerCase().startsWith("gemma-");
|
|
1212
|
+
const supportsFunctionResponseParts = this.modelId.startsWith("gemini-3");
|
|
955
1213
|
const { contents, systemInstruction } = convertToGoogleGenerativeAIMessages(
|
|
956
1214
|
prompt,
|
|
957
|
-
{
|
|
1215
|
+
{
|
|
1216
|
+
isGemmaModel,
|
|
1217
|
+
providerOptionsName,
|
|
1218
|
+
supportsFunctionResponseParts
|
|
1219
|
+
}
|
|
958
1220
|
);
|
|
959
1221
|
const {
|
|
960
1222
|
tools: googleTools2,
|
|
@@ -965,6 +1227,12 @@ var GoogleGenerativeAILanguageModel = class {
|
|
|
965
1227
|
toolChoice,
|
|
966
1228
|
modelId: this.modelId
|
|
967
1229
|
});
|
|
1230
|
+
const resolvedThinking = resolveThinkingConfig({
|
|
1231
|
+
reasoning,
|
|
1232
|
+
modelId: this.modelId,
|
|
1233
|
+
warnings
|
|
1234
|
+
});
|
|
1235
|
+
const thinkingConfig = (googleOptions == null ? void 0 : googleOptions.thinkingConfig) || resolvedThinking ? { ...resolvedThinking, ...googleOptions == null ? void 0 : googleOptions.thinkingConfig } : void 0;
|
|
968
1236
|
return {
|
|
969
1237
|
args: {
|
|
970
1238
|
generationConfig: {
|
|
@@ -988,7 +1256,7 @@ var GoogleGenerativeAILanguageModel = class {
|
|
|
988
1256
|
},
|
|
989
1257
|
// provider options:
|
|
990
1258
|
responseModalities: googleOptions == null ? void 0 : googleOptions.responseModalities,
|
|
991
|
-
thinkingConfig
|
|
1259
|
+
thinkingConfig,
|
|
992
1260
|
...(googleOptions == null ? void 0 : googleOptions.mediaResolution) && {
|
|
993
1261
|
mediaResolution: googleOptions.mediaResolution
|
|
994
1262
|
},
|
|
@@ -1005,14 +1273,15 @@ var GoogleGenerativeAILanguageModel = class {
|
|
|
1005
1273
|
retrievalConfig: googleOptions.retrievalConfig
|
|
1006
1274
|
} : googleToolConfig,
|
|
1007
1275
|
cachedContent: googleOptions == null ? void 0 : googleOptions.cachedContent,
|
|
1008
|
-
labels: googleOptions == null ? void 0 : googleOptions.labels
|
|
1276
|
+
labels: googleOptions == null ? void 0 : googleOptions.labels,
|
|
1277
|
+
serviceTier: googleOptions == null ? void 0 : googleOptions.serviceTier
|
|
1009
1278
|
},
|
|
1010
1279
|
warnings: [...warnings, ...toolWarnings],
|
|
1011
1280
|
providerOptionsName
|
|
1012
1281
|
};
|
|
1013
1282
|
}
|
|
1014
1283
|
async doGenerate(options) {
|
|
1015
|
-
var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j;
|
|
1284
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o, _p;
|
|
1016
1285
|
const { args, warnings, providerOptionsName } = await this.getArgs(options);
|
|
1017
1286
|
const mergedHeaders = (0, import_provider_utils6.combineHeaders)(
|
|
1018
1287
|
await (0, import_provider_utils6.resolve)(this.config.headers),
|
|
@@ -1038,6 +1307,7 @@ var GoogleGenerativeAILanguageModel = class {
|
|
|
1038
1307
|
const parts = (_b = (_a = candidate.content) == null ? void 0 : _a.parts) != null ? _b : [];
|
|
1039
1308
|
const usageMetadata = response.usageMetadata;
|
|
1040
1309
|
let lastCodeExecutionToolCallId;
|
|
1310
|
+
let lastServerToolCallId;
|
|
1041
1311
|
for (const part of parts) {
|
|
1042
1312
|
if ("executableCode" in part && ((_c = part.executableCode) == null ? void 0 : _c.code)) {
|
|
1043
1313
|
const toolCallId = this.config.generateId();
|
|
@@ -1092,22 +1362,68 @@ var GoogleGenerativeAILanguageModel = class {
|
|
|
1092
1362
|
} : void 0
|
|
1093
1363
|
});
|
|
1094
1364
|
} else if ("inlineData" in part) {
|
|
1365
|
+
const hasThought = part.thought === true;
|
|
1366
|
+
const hasThoughtSignature = !!part.thoughtSignature;
|
|
1095
1367
|
content.push({
|
|
1096
|
-
type: "file",
|
|
1368
|
+
type: hasThought ? "reasoning-file" : "file",
|
|
1097
1369
|
data: part.inlineData.data,
|
|
1098
1370
|
mediaType: part.inlineData.mimeType,
|
|
1099
|
-
providerMetadata:
|
|
1371
|
+
providerMetadata: hasThoughtSignature ? {
|
|
1100
1372
|
[providerOptionsName]: {
|
|
1101
1373
|
thoughtSignature: part.thoughtSignature
|
|
1102
1374
|
}
|
|
1103
1375
|
} : void 0
|
|
1104
1376
|
});
|
|
1377
|
+
} else if ("toolCall" in part && part.toolCall) {
|
|
1378
|
+
const toolCallId = (_e = part.toolCall.id) != null ? _e : this.config.generateId();
|
|
1379
|
+
lastServerToolCallId = toolCallId;
|
|
1380
|
+
content.push({
|
|
1381
|
+
type: "tool-call",
|
|
1382
|
+
toolCallId,
|
|
1383
|
+
toolName: `server:${part.toolCall.toolType}`,
|
|
1384
|
+
input: JSON.stringify((_f = part.toolCall.args) != null ? _f : {}),
|
|
1385
|
+
providerExecuted: true,
|
|
1386
|
+
dynamic: true,
|
|
1387
|
+
providerMetadata: part.thoughtSignature ? {
|
|
1388
|
+
[providerOptionsName]: {
|
|
1389
|
+
thoughtSignature: part.thoughtSignature,
|
|
1390
|
+
serverToolCallId: toolCallId,
|
|
1391
|
+
serverToolType: part.toolCall.toolType
|
|
1392
|
+
}
|
|
1393
|
+
} : {
|
|
1394
|
+
[providerOptionsName]: {
|
|
1395
|
+
serverToolCallId: toolCallId,
|
|
1396
|
+
serverToolType: part.toolCall.toolType
|
|
1397
|
+
}
|
|
1398
|
+
}
|
|
1399
|
+
});
|
|
1400
|
+
} else if ("toolResponse" in part && part.toolResponse) {
|
|
1401
|
+
const responseToolCallId = (_g = lastServerToolCallId != null ? lastServerToolCallId : part.toolResponse.id) != null ? _g : this.config.generateId();
|
|
1402
|
+
content.push({
|
|
1403
|
+
type: "tool-result",
|
|
1404
|
+
toolCallId: responseToolCallId,
|
|
1405
|
+
toolName: `server:${part.toolResponse.toolType}`,
|
|
1406
|
+
result: (_h = part.toolResponse.response) != null ? _h : {},
|
|
1407
|
+
providerMetadata: part.thoughtSignature ? {
|
|
1408
|
+
[providerOptionsName]: {
|
|
1409
|
+
thoughtSignature: part.thoughtSignature,
|
|
1410
|
+
serverToolCallId: responseToolCallId,
|
|
1411
|
+
serverToolType: part.toolResponse.toolType
|
|
1412
|
+
}
|
|
1413
|
+
} : {
|
|
1414
|
+
[providerOptionsName]: {
|
|
1415
|
+
serverToolCallId: responseToolCallId,
|
|
1416
|
+
serverToolType: part.toolResponse.toolType
|
|
1417
|
+
}
|
|
1418
|
+
}
|
|
1419
|
+
});
|
|
1420
|
+
lastServerToolCallId = void 0;
|
|
1105
1421
|
}
|
|
1106
1422
|
}
|
|
1107
|
-
const sources = (
|
|
1423
|
+
const sources = (_i = extractSources({
|
|
1108
1424
|
groundingMetadata: candidate.groundingMetadata,
|
|
1109
1425
|
generateId: this.config.generateId
|
|
1110
|
-
})) != null ?
|
|
1426
|
+
})) != null ? _i : [];
|
|
1111
1427
|
for (const source of sources) {
|
|
1112
1428
|
content.push(source);
|
|
1113
1429
|
}
|
|
@@ -1121,17 +1437,19 @@ var GoogleGenerativeAILanguageModel = class {
|
|
|
1121
1437
|
(part) => part.type === "tool-call" && !part.providerExecuted
|
|
1122
1438
|
)
|
|
1123
1439
|
}),
|
|
1124
|
-
raw: (
|
|
1440
|
+
raw: (_j = candidate.finishReason) != null ? _j : void 0
|
|
1125
1441
|
},
|
|
1126
1442
|
usage: convertGoogleGenerativeAIUsage(usageMetadata),
|
|
1127
1443
|
warnings,
|
|
1128
1444
|
providerMetadata: {
|
|
1129
1445
|
[providerOptionsName]: {
|
|
1130
|
-
promptFeedback: (
|
|
1131
|
-
groundingMetadata: (
|
|
1132
|
-
urlContextMetadata: (
|
|
1133
|
-
safetyRatings: (
|
|
1134
|
-
usageMetadata: usageMetadata != null ? usageMetadata : null
|
|
1446
|
+
promptFeedback: (_k = response.promptFeedback) != null ? _k : null,
|
|
1447
|
+
groundingMetadata: (_l = candidate.groundingMetadata) != null ? _l : null,
|
|
1448
|
+
urlContextMetadata: (_m = candidate.urlContextMetadata) != null ? _m : null,
|
|
1449
|
+
safetyRatings: (_n = candidate.safetyRatings) != null ? _n : null,
|
|
1450
|
+
usageMetadata: usageMetadata != null ? usageMetadata : null,
|
|
1451
|
+
finishMessage: (_o = candidate.finishMessage) != null ? _o : null,
|
|
1452
|
+
serviceTier: (_p = response.serviceTier) != null ? _p : null
|
|
1135
1453
|
}
|
|
1136
1454
|
},
|
|
1137
1455
|
request: { body: args },
|
|
@@ -1167,6 +1485,7 @@ var GoogleGenerativeAILanguageModel = class {
|
|
|
1167
1485
|
let providerMetadata = void 0;
|
|
1168
1486
|
let lastGroundingMetadata = null;
|
|
1169
1487
|
let lastUrlContextMetadata = null;
|
|
1488
|
+
let serviceTier = null;
|
|
1170
1489
|
const generateId3 = this.config.generateId;
|
|
1171
1490
|
let hasToolCalls = false;
|
|
1172
1491
|
let currentTextBlockId = null;
|
|
@@ -1174,6 +1493,7 @@ var GoogleGenerativeAILanguageModel = class {
|
|
|
1174
1493
|
let blockCounter = 0;
|
|
1175
1494
|
const emittedSourceUrls = /* @__PURE__ */ new Set();
|
|
1176
1495
|
let lastCodeExecutionToolCallId;
|
|
1496
|
+
let lastServerToolCallId;
|
|
1177
1497
|
return {
|
|
1178
1498
|
stream: response.pipeThrough(
|
|
1179
1499
|
new TransformStream({
|
|
@@ -1181,7 +1501,7 @@ var GoogleGenerativeAILanguageModel = class {
|
|
|
1181
1501
|
controller.enqueue({ type: "stream-start", warnings });
|
|
1182
1502
|
},
|
|
1183
1503
|
transform(chunk, controller) {
|
|
1184
|
-
var _a, _b, _c, _d, _e, _f;
|
|
1504
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k;
|
|
1185
1505
|
if (options.includeRawChunks) {
|
|
1186
1506
|
controller.enqueue({ type: "raw", rawValue: chunk.rawValue });
|
|
1187
1507
|
}
|
|
@@ -1194,6 +1514,9 @@ var GoogleGenerativeAILanguageModel = class {
|
|
|
1194
1514
|
if (usageMetadata != null) {
|
|
1195
1515
|
usage = usageMetadata;
|
|
1196
1516
|
}
|
|
1517
|
+
if (value.serviceTier != null) {
|
|
1518
|
+
serviceTier = value.serviceTier;
|
|
1519
|
+
}
|
|
1197
1520
|
const candidate = (_a = value.candidates) == null ? void 0 : _a[0];
|
|
1198
1521
|
if (candidate == null) {
|
|
1199
1522
|
return;
|
|
@@ -1319,17 +1642,55 @@ var GoogleGenerativeAILanguageModel = class {
|
|
|
1319
1642
|
});
|
|
1320
1643
|
currentReasoningBlockId = null;
|
|
1321
1644
|
}
|
|
1322
|
-
const
|
|
1645
|
+
const hasThought = part.thought === true;
|
|
1646
|
+
const hasThoughtSignature = !!part.thoughtSignature;
|
|
1647
|
+
const fileMeta = hasThoughtSignature ? {
|
|
1323
1648
|
[providerOptionsName]: {
|
|
1324
1649
|
thoughtSignature: part.thoughtSignature
|
|
1325
1650
|
}
|
|
1326
1651
|
} : void 0;
|
|
1327
1652
|
controller.enqueue({
|
|
1328
|
-
type: "file",
|
|
1653
|
+
type: hasThought ? "reasoning-file" : "file",
|
|
1329
1654
|
mediaType: part.inlineData.mimeType,
|
|
1330
1655
|
data: part.inlineData.data,
|
|
1331
|
-
providerMetadata:
|
|
1656
|
+
providerMetadata: fileMeta
|
|
1657
|
+
});
|
|
1658
|
+
} else if ("toolCall" in part && part.toolCall) {
|
|
1659
|
+
const toolCallId = (_e = part.toolCall.id) != null ? _e : generateId3();
|
|
1660
|
+
lastServerToolCallId = toolCallId;
|
|
1661
|
+
const serverMeta = {
|
|
1662
|
+
[providerOptionsName]: {
|
|
1663
|
+
...part.thoughtSignature ? { thoughtSignature: part.thoughtSignature } : {},
|
|
1664
|
+
serverToolCallId: toolCallId,
|
|
1665
|
+
serverToolType: part.toolCall.toolType
|
|
1666
|
+
}
|
|
1667
|
+
};
|
|
1668
|
+
controller.enqueue({
|
|
1669
|
+
type: "tool-call",
|
|
1670
|
+
toolCallId,
|
|
1671
|
+
toolName: `server:${part.toolCall.toolType}`,
|
|
1672
|
+
input: JSON.stringify((_f = part.toolCall.args) != null ? _f : {}),
|
|
1673
|
+
providerExecuted: true,
|
|
1674
|
+
dynamic: true,
|
|
1675
|
+
providerMetadata: serverMeta
|
|
1676
|
+
});
|
|
1677
|
+
} else if ("toolResponse" in part && part.toolResponse) {
|
|
1678
|
+
const responseToolCallId = (_g = lastServerToolCallId != null ? lastServerToolCallId : part.toolResponse.id) != null ? _g : generateId3();
|
|
1679
|
+
const serverMeta = {
|
|
1680
|
+
[providerOptionsName]: {
|
|
1681
|
+
...part.thoughtSignature ? { thoughtSignature: part.thoughtSignature } : {},
|
|
1682
|
+
serverToolCallId: responseToolCallId,
|
|
1683
|
+
serverToolType: part.toolResponse.toolType
|
|
1684
|
+
}
|
|
1685
|
+
};
|
|
1686
|
+
controller.enqueue({
|
|
1687
|
+
type: "tool-result",
|
|
1688
|
+
toolCallId: responseToolCallId,
|
|
1689
|
+
toolName: `server:${part.toolResponse.toolType}`,
|
|
1690
|
+
result: (_h = part.toolResponse.response) != null ? _h : {},
|
|
1691
|
+
providerMetadata: serverMeta
|
|
1332
1692
|
});
|
|
1693
|
+
lastServerToolCallId = void 0;
|
|
1333
1694
|
}
|
|
1334
1695
|
}
|
|
1335
1696
|
const toolCallDeltas = getToolCallsFromParts({
|
|
@@ -1377,15 +1738,15 @@ var GoogleGenerativeAILanguageModel = class {
|
|
|
1377
1738
|
};
|
|
1378
1739
|
providerMetadata = {
|
|
1379
1740
|
[providerOptionsName]: {
|
|
1380
|
-
promptFeedback: (
|
|
1741
|
+
promptFeedback: (_i = value.promptFeedback) != null ? _i : null,
|
|
1381
1742
|
groundingMetadata: lastGroundingMetadata,
|
|
1382
1743
|
urlContextMetadata: lastUrlContextMetadata,
|
|
1383
|
-
safetyRatings: (
|
|
1744
|
+
safetyRatings: (_j = candidate.safetyRatings) != null ? _j : null,
|
|
1745
|
+
usageMetadata: usageMetadata != null ? usageMetadata : null,
|
|
1746
|
+
finishMessage: (_k = candidate.finishMessage) != null ? _k : null,
|
|
1747
|
+
serviceTier
|
|
1384
1748
|
}
|
|
1385
1749
|
};
|
|
1386
|
-
if (usageMetadata != null) {
|
|
1387
|
-
providerMetadata[providerOptionsName].usageMetadata = usageMetadata;
|
|
1388
|
-
}
|
|
1389
1750
|
}
|
|
1390
1751
|
},
|
|
1391
1752
|
flush(controller) {
|
|
@@ -1415,6 +1776,75 @@ var GoogleGenerativeAILanguageModel = class {
|
|
|
1415
1776
|
};
|
|
1416
1777
|
}
|
|
1417
1778
|
};
|
|
1779
|
+
function isGemini3Model(modelId) {
|
|
1780
|
+
return /gemini-3[\.\-]/i.test(modelId) || /gemini-3$/i.test(modelId);
|
|
1781
|
+
}
|
|
1782
|
+
function getMaxOutputTokensForGemini25Model() {
|
|
1783
|
+
return 65536;
|
|
1784
|
+
}
|
|
1785
|
+
function getMaxThinkingTokensForGemini25Model(modelId) {
|
|
1786
|
+
const id = modelId.toLowerCase();
|
|
1787
|
+
if (id.includes("2.5-pro") || id.includes("gemini-3-pro-image")) {
|
|
1788
|
+
return 32768;
|
|
1789
|
+
}
|
|
1790
|
+
return 24576;
|
|
1791
|
+
}
|
|
1792
|
+
function resolveThinkingConfig({
|
|
1793
|
+
reasoning,
|
|
1794
|
+
modelId,
|
|
1795
|
+
warnings
|
|
1796
|
+
}) {
|
|
1797
|
+
if (!(0, import_provider_utils6.isCustomReasoning)(reasoning)) {
|
|
1798
|
+
return void 0;
|
|
1799
|
+
}
|
|
1800
|
+
if (isGemini3Model(modelId) && !modelId.includes("gemini-3-pro-image")) {
|
|
1801
|
+
return resolveGemini3ThinkingConfig({ reasoning, warnings });
|
|
1802
|
+
}
|
|
1803
|
+
return resolveGemini25ThinkingConfig({ reasoning, modelId, warnings });
|
|
1804
|
+
}
|
|
1805
|
+
function resolveGemini3ThinkingConfig({
|
|
1806
|
+
reasoning,
|
|
1807
|
+
warnings
|
|
1808
|
+
}) {
|
|
1809
|
+
if (reasoning === "none") {
|
|
1810
|
+
return { thinkingLevel: "minimal" };
|
|
1811
|
+
}
|
|
1812
|
+
const thinkingLevel = (0, import_provider_utils6.mapReasoningToProviderEffort)({
|
|
1813
|
+
reasoning,
|
|
1814
|
+
effortMap: {
|
|
1815
|
+
minimal: "minimal",
|
|
1816
|
+
low: "low",
|
|
1817
|
+
medium: "medium",
|
|
1818
|
+
high: "high",
|
|
1819
|
+
xhigh: "high"
|
|
1820
|
+
},
|
|
1821
|
+
warnings
|
|
1822
|
+
});
|
|
1823
|
+
if (thinkingLevel == null) {
|
|
1824
|
+
return void 0;
|
|
1825
|
+
}
|
|
1826
|
+
return { thinkingLevel };
|
|
1827
|
+
}
|
|
1828
|
+
function resolveGemini25ThinkingConfig({
|
|
1829
|
+
reasoning,
|
|
1830
|
+
modelId,
|
|
1831
|
+
warnings
|
|
1832
|
+
}) {
|
|
1833
|
+
if (reasoning === "none") {
|
|
1834
|
+
return { thinkingBudget: 0 };
|
|
1835
|
+
}
|
|
1836
|
+
const thinkingBudget = (0, import_provider_utils6.mapReasoningToProviderBudget)({
|
|
1837
|
+
reasoning,
|
|
1838
|
+
maxOutputTokens: getMaxOutputTokensForGemini25Model(),
|
|
1839
|
+
maxReasoningBudget: getMaxThinkingTokensForGemini25Model(modelId),
|
|
1840
|
+
minReasoningBudget: 0,
|
|
1841
|
+
warnings
|
|
1842
|
+
});
|
|
1843
|
+
if (thinkingBudget == null) {
|
|
1844
|
+
return void 0;
|
|
1845
|
+
}
|
|
1846
|
+
return { thinkingBudget };
|
|
1847
|
+
}
|
|
1418
1848
|
function getToolCallsFromParts({
|
|
1419
1849
|
parts,
|
|
1420
1850
|
generateId: generateId3,
|
|
@@ -1594,6 +2024,23 @@ var getContentSchema = () => import_v45.z.object({
|
|
|
1594
2024
|
mimeType: import_v45.z.string(),
|
|
1595
2025
|
data: import_v45.z.string()
|
|
1596
2026
|
}),
|
|
2027
|
+
thought: import_v45.z.boolean().nullish(),
|
|
2028
|
+
thoughtSignature: import_v45.z.string().nullish()
|
|
2029
|
+
}),
|
|
2030
|
+
import_v45.z.object({
|
|
2031
|
+
toolCall: import_v45.z.object({
|
|
2032
|
+
toolType: import_v45.z.string(),
|
|
2033
|
+
args: import_v45.z.unknown().nullish(),
|
|
2034
|
+
id: import_v45.z.string()
|
|
2035
|
+
}),
|
|
2036
|
+
thoughtSignature: import_v45.z.string().nullish()
|
|
2037
|
+
}),
|
|
2038
|
+
import_v45.z.object({
|
|
2039
|
+
toolResponse: import_v45.z.object({
|
|
2040
|
+
toolType: import_v45.z.string(),
|
|
2041
|
+
response: import_v45.z.unknown().nullish(),
|
|
2042
|
+
id: import_v45.z.string()
|
|
2043
|
+
}),
|
|
1597
2044
|
thoughtSignature: import_v45.z.string().nullish()
|
|
1598
2045
|
}),
|
|
1599
2046
|
import_v45.z.object({
|
|
@@ -1620,6 +2067,12 @@ var getSafetyRatingSchema = () => import_v45.z.object({
|
|
|
1620
2067
|
severityScore: import_v45.z.number().nullish(),
|
|
1621
2068
|
blocked: import_v45.z.boolean().nullish()
|
|
1622
2069
|
});
|
|
2070
|
+
var tokenDetailsSchema = import_v45.z.array(
|
|
2071
|
+
import_v45.z.object({
|
|
2072
|
+
modality: import_v45.z.string(),
|
|
2073
|
+
tokenCount: import_v45.z.number()
|
|
2074
|
+
})
|
|
2075
|
+
).nullish();
|
|
1623
2076
|
var usageSchema = import_v45.z.object({
|
|
1624
2077
|
cachedContentTokenCount: import_v45.z.number().nullish(),
|
|
1625
2078
|
thoughtsTokenCount: import_v45.z.number().nullish(),
|
|
@@ -1627,7 +2080,10 @@ var usageSchema = import_v45.z.object({
|
|
|
1627
2080
|
candidatesTokenCount: import_v45.z.number().nullish(),
|
|
1628
2081
|
totalTokenCount: import_v45.z.number().nullish(),
|
|
1629
2082
|
// https://cloud.google.com/vertex-ai/generative-ai/docs/reference/rest/v1/GenerateContentResponse#TrafficType
|
|
1630
|
-
trafficType: import_v45.z.string().nullish()
|
|
2083
|
+
trafficType: import_v45.z.string().nullish(),
|
|
2084
|
+
// https://ai.google.dev/api/generate-content#Modality
|
|
2085
|
+
promptTokensDetails: tokenDetailsSchema,
|
|
2086
|
+
candidatesTokensDetails: tokenDetailsSchema
|
|
1631
2087
|
});
|
|
1632
2088
|
var getUrlContextMetadataSchema = () => import_v45.z.object({
|
|
1633
2089
|
urlMetadata: import_v45.z.array(
|
|
@@ -1644,6 +2100,7 @@ var responseSchema = (0, import_provider_utils6.lazySchema)(
|
|
|
1644
2100
|
import_v45.z.object({
|
|
1645
2101
|
content: getContentSchema().nullish().or(import_v45.z.object({}).strict()),
|
|
1646
2102
|
finishReason: import_v45.z.string().nullish(),
|
|
2103
|
+
finishMessage: import_v45.z.string().nullish(),
|
|
1647
2104
|
safetyRatings: import_v45.z.array(getSafetyRatingSchema()).nullish(),
|
|
1648
2105
|
groundingMetadata: getGroundingMetadataSchema().nullish(),
|
|
1649
2106
|
urlContextMetadata: getUrlContextMetadataSchema().nullish()
|
|
@@ -1653,7 +2110,8 @@ var responseSchema = (0, import_provider_utils6.lazySchema)(
|
|
|
1653
2110
|
promptFeedback: import_v45.z.object({
|
|
1654
2111
|
blockReason: import_v45.z.string().nullish(),
|
|
1655
2112
|
safetyRatings: import_v45.z.array(getSafetyRatingSchema()).nullish()
|
|
1656
|
-
}).nullish()
|
|
2113
|
+
}).nullish(),
|
|
2114
|
+
serviceTier: import_v45.z.string().nullish()
|
|
1657
2115
|
})
|
|
1658
2116
|
)
|
|
1659
2117
|
);
|
|
@@ -1664,6 +2122,7 @@ var chunkSchema = (0, import_provider_utils6.lazySchema)(
|
|
|
1664
2122
|
import_v45.z.object({
|
|
1665
2123
|
content: getContentSchema().nullish(),
|
|
1666
2124
|
finishReason: import_v45.z.string().nullish(),
|
|
2125
|
+
finishMessage: import_v45.z.string().nullish(),
|
|
1667
2126
|
safetyRatings: import_v45.z.array(getSafetyRatingSchema()).nullish(),
|
|
1668
2127
|
groundingMetadata: getGroundingMetadataSchema().nullish(),
|
|
1669
2128
|
urlContextMetadata: getUrlContextMetadataSchema().nullish()
|
|
@@ -1673,7 +2132,8 @@ var chunkSchema = (0, import_provider_utils6.lazySchema)(
|
|
|
1673
2132
|
promptFeedback: import_v45.z.object({
|
|
1674
2133
|
blockReason: import_v45.z.string().nullish(),
|
|
1675
2134
|
safetyRatings: import_v45.z.array(getSafetyRatingSchema()).nullish()
|
|
1676
|
-
}).nullish()
|
|
2135
|
+
}).nullish(),
|
|
2136
|
+
serviceTier: import_v45.z.string().nullish()
|
|
1677
2137
|
})
|
|
1678
2138
|
)
|
|
1679
2139
|
);
|
|
@@ -1846,7 +2306,7 @@ var GoogleGenerativeAIImageModel = class {
|
|
|
1846
2306
|
this.modelId = modelId;
|
|
1847
2307
|
this.settings = settings;
|
|
1848
2308
|
this.config = config;
|
|
1849
|
-
this.specificationVersion = "
|
|
2309
|
+
this.specificationVersion = "v4";
|
|
1850
2310
|
}
|
|
1851
2311
|
get maxImagesPerCall() {
|
|
1852
2312
|
if (this.settings.maxImagesPerCall != null) {
|
|
@@ -2079,15 +2539,168 @@ var googleImageModelOptionsSchema = (0, import_provider_utils14.lazySchema)(
|
|
|
2079
2539
|
)
|
|
2080
2540
|
);
|
|
2081
2541
|
|
|
2082
|
-
// src/google-generative-ai-
|
|
2542
|
+
// src/google-generative-ai-files.ts
|
|
2083
2543
|
var import_provider4 = require("@ai-sdk/provider");
|
|
2084
2544
|
var import_provider_utils15 = require("@ai-sdk/provider-utils");
|
|
2085
2545
|
var import_v414 = require("zod/v4");
|
|
2546
|
+
var GoogleGenerativeAIFiles = class {
|
|
2547
|
+
constructor(config) {
|
|
2548
|
+
this.config = config;
|
|
2549
|
+
this.specificationVersion = "v4";
|
|
2550
|
+
}
|
|
2551
|
+
get provider() {
|
|
2552
|
+
return this.config.provider;
|
|
2553
|
+
}
|
|
2554
|
+
async uploadFile(options) {
|
|
2555
|
+
var _a, _b, _c, _d;
|
|
2556
|
+
const googleOptions = await (0, import_provider_utils15.parseProviderOptions)({
|
|
2557
|
+
provider: "google",
|
|
2558
|
+
providerOptions: options.providerOptions,
|
|
2559
|
+
schema: googleFilesUploadOptionsSchema
|
|
2560
|
+
});
|
|
2561
|
+
const resolvedHeaders = this.config.headers();
|
|
2562
|
+
const fetchFn = (_a = this.config.fetch) != null ? _a : globalThis.fetch;
|
|
2563
|
+
const warnings = [];
|
|
2564
|
+
if (options.filename != null) {
|
|
2565
|
+
warnings.push({ type: "unsupported", feature: "filename" });
|
|
2566
|
+
}
|
|
2567
|
+
const data = options.data;
|
|
2568
|
+
const fileBytes = data instanceof Uint8Array ? data : Uint8Array.from(atob(data), (c) => c.charCodeAt(0));
|
|
2569
|
+
const mediaType = options.mediaType;
|
|
2570
|
+
const displayName = googleOptions == null ? void 0 : googleOptions.displayName;
|
|
2571
|
+
const baseOrigin = this.config.baseURL.replace(/\/v1beta$/, "");
|
|
2572
|
+
const initResponse = await fetchFn(`${baseOrigin}/upload/v1beta/files`, {
|
|
2573
|
+
method: "POST",
|
|
2574
|
+
headers: {
|
|
2575
|
+
...resolvedHeaders,
|
|
2576
|
+
"X-Goog-Upload-Protocol": "resumable",
|
|
2577
|
+
"X-Goog-Upload-Command": "start",
|
|
2578
|
+
"X-Goog-Upload-Header-Content-Length": String(fileBytes.length),
|
|
2579
|
+
"X-Goog-Upload-Header-Content-Type": mediaType,
|
|
2580
|
+
"Content-Type": "application/json"
|
|
2581
|
+
},
|
|
2582
|
+
body: JSON.stringify({
|
|
2583
|
+
file: {
|
|
2584
|
+
...displayName != null ? { display_name: displayName } : {}
|
|
2585
|
+
}
|
|
2586
|
+
})
|
|
2587
|
+
});
|
|
2588
|
+
if (!initResponse.ok) {
|
|
2589
|
+
const errorBody = await initResponse.text();
|
|
2590
|
+
throw new import_provider4.AISDKError({
|
|
2591
|
+
name: "GOOGLE_FILES_UPLOAD_ERROR",
|
|
2592
|
+
message: `Failed to initiate resumable upload: ${initResponse.status} ${errorBody}`
|
|
2593
|
+
});
|
|
2594
|
+
}
|
|
2595
|
+
const uploadUrl = initResponse.headers.get("x-goog-upload-url");
|
|
2596
|
+
if (!uploadUrl) {
|
|
2597
|
+
throw new import_provider4.AISDKError({
|
|
2598
|
+
name: "GOOGLE_FILES_UPLOAD_ERROR",
|
|
2599
|
+
message: "No upload URL returned from initiation request"
|
|
2600
|
+
});
|
|
2601
|
+
}
|
|
2602
|
+
const uploadResponse = await fetchFn(uploadUrl, {
|
|
2603
|
+
method: "POST",
|
|
2604
|
+
headers: {
|
|
2605
|
+
"Content-Length": String(fileBytes.length),
|
|
2606
|
+
"X-Goog-Upload-Offset": "0",
|
|
2607
|
+
"X-Goog-Upload-Command": "upload, finalize"
|
|
2608
|
+
},
|
|
2609
|
+
body: fileBytes
|
|
2610
|
+
});
|
|
2611
|
+
if (!uploadResponse.ok) {
|
|
2612
|
+
const errorBody = await uploadResponse.text();
|
|
2613
|
+
throw new import_provider4.AISDKError({
|
|
2614
|
+
name: "GOOGLE_FILES_UPLOAD_ERROR",
|
|
2615
|
+
message: `Failed to upload file data: ${uploadResponse.status} ${errorBody}`
|
|
2616
|
+
});
|
|
2617
|
+
}
|
|
2618
|
+
const uploadResult = await uploadResponse.json();
|
|
2619
|
+
let file = uploadResult.file;
|
|
2620
|
+
const pollIntervalMs = (_b = googleOptions == null ? void 0 : googleOptions.pollIntervalMs) != null ? _b : 2e3;
|
|
2621
|
+
const pollTimeoutMs = (_c = googleOptions == null ? void 0 : googleOptions.pollTimeoutMs) != null ? _c : 3e5;
|
|
2622
|
+
const startTime = Date.now();
|
|
2623
|
+
while (file.state === "PROCESSING") {
|
|
2624
|
+
if (Date.now() - startTime > pollTimeoutMs) {
|
|
2625
|
+
throw new import_provider4.AISDKError({
|
|
2626
|
+
name: "GOOGLE_FILES_UPLOAD_TIMEOUT",
|
|
2627
|
+
message: `File processing timed out after ${pollTimeoutMs}ms`
|
|
2628
|
+
});
|
|
2629
|
+
}
|
|
2630
|
+
await (0, import_provider_utils15.delay)(pollIntervalMs);
|
|
2631
|
+
const { value: fileStatus } = await (0, import_provider_utils15.getFromApi)({
|
|
2632
|
+
url: `${this.config.baseURL}/${file.name}`,
|
|
2633
|
+
headers: (0, import_provider_utils15.combineHeaders)(resolvedHeaders),
|
|
2634
|
+
successfulResponseHandler: (0, import_provider_utils15.createJsonResponseHandler)(
|
|
2635
|
+
googleFileResponseSchema
|
|
2636
|
+
),
|
|
2637
|
+
failedResponseHandler: googleFailedResponseHandler,
|
|
2638
|
+
fetch: this.config.fetch
|
|
2639
|
+
});
|
|
2640
|
+
file = fileStatus;
|
|
2641
|
+
}
|
|
2642
|
+
if (file.state === "FAILED") {
|
|
2643
|
+
throw new import_provider4.AISDKError({
|
|
2644
|
+
name: "GOOGLE_FILES_UPLOAD_FAILED",
|
|
2645
|
+
message: `File processing failed for ${file.name}`
|
|
2646
|
+
});
|
|
2647
|
+
}
|
|
2648
|
+
return {
|
|
2649
|
+
warnings,
|
|
2650
|
+
providerReference: { google: file.uri },
|
|
2651
|
+
mediaType: (_d = file.mimeType) != null ? _d : options.mediaType,
|
|
2652
|
+
providerMetadata: {
|
|
2653
|
+
google: {
|
|
2654
|
+
name: file.name,
|
|
2655
|
+
displayName: file.displayName,
|
|
2656
|
+
mimeType: file.mimeType,
|
|
2657
|
+
sizeBytes: file.sizeBytes,
|
|
2658
|
+
state: file.state,
|
|
2659
|
+
uri: file.uri,
|
|
2660
|
+
...file.createTime != null ? { createTime: file.createTime } : {},
|
|
2661
|
+
...file.updateTime != null ? { updateTime: file.updateTime } : {},
|
|
2662
|
+
...file.expirationTime != null ? { expirationTime: file.expirationTime } : {},
|
|
2663
|
+
...file.sha256Hash != null ? { sha256Hash: file.sha256Hash } : {}
|
|
2664
|
+
}
|
|
2665
|
+
}
|
|
2666
|
+
};
|
|
2667
|
+
}
|
|
2668
|
+
};
|
|
2669
|
+
var googleFileResponseSchema = (0, import_provider_utils15.lazySchema)(
|
|
2670
|
+
() => (0, import_provider_utils15.zodSchema)(
|
|
2671
|
+
import_v414.z.object({
|
|
2672
|
+
name: import_v414.z.string(),
|
|
2673
|
+
displayName: import_v414.z.string().nullish(),
|
|
2674
|
+
mimeType: import_v414.z.string(),
|
|
2675
|
+
sizeBytes: import_v414.z.string().nullish(),
|
|
2676
|
+
createTime: import_v414.z.string().nullish(),
|
|
2677
|
+
updateTime: import_v414.z.string().nullish(),
|
|
2678
|
+
expirationTime: import_v414.z.string().nullish(),
|
|
2679
|
+
sha256Hash: import_v414.z.string().nullish(),
|
|
2680
|
+
uri: import_v414.z.string(),
|
|
2681
|
+
state: import_v414.z.string()
|
|
2682
|
+
})
|
|
2683
|
+
)
|
|
2684
|
+
);
|
|
2685
|
+
var googleFilesUploadOptionsSchema = (0, import_provider_utils15.lazySchema)(
|
|
2686
|
+
() => (0, import_provider_utils15.zodSchema)(
|
|
2687
|
+
import_v414.z.object({
|
|
2688
|
+
displayName: import_v414.z.string().nullish(),
|
|
2689
|
+
pollIntervalMs: import_v414.z.number().positive().nullish(),
|
|
2690
|
+
pollTimeoutMs: import_v414.z.number().positive().nullish()
|
|
2691
|
+
}).passthrough()
|
|
2692
|
+
)
|
|
2693
|
+
);
|
|
2694
|
+
|
|
2695
|
+
// src/google-generative-ai-video-model.ts
|
|
2696
|
+
var import_provider5 = require("@ai-sdk/provider");
|
|
2697
|
+
var import_provider_utils16 = require("@ai-sdk/provider-utils");
|
|
2698
|
+
var import_v415 = require("zod/v4");
|
|
2086
2699
|
var GoogleGenerativeAIVideoModel = class {
|
|
2087
2700
|
constructor(modelId, config) {
|
|
2088
2701
|
this.modelId = modelId;
|
|
2089
2702
|
this.config = config;
|
|
2090
|
-
this.specificationVersion = "
|
|
2703
|
+
this.specificationVersion = "v4";
|
|
2091
2704
|
}
|
|
2092
2705
|
get provider() {
|
|
2093
2706
|
return this.config.provider;
|
|
@@ -2099,7 +2712,7 @@ var GoogleGenerativeAIVideoModel = class {
|
|
|
2099
2712
|
var _a, _b, _c, _d, _e, _f, _g, _h;
|
|
2100
2713
|
const currentDate = (_c = (_b = (_a = this.config._internal) == null ? void 0 : _a.currentDate) == null ? void 0 : _b.call(_a)) != null ? _c : /* @__PURE__ */ new Date();
|
|
2101
2714
|
const warnings = [];
|
|
2102
|
-
const googleOptions = await (0,
|
|
2715
|
+
const googleOptions = await (0, import_provider_utils16.parseProviderOptions)({
|
|
2103
2716
|
provider: "google",
|
|
2104
2717
|
providerOptions: options.providerOptions,
|
|
2105
2718
|
schema: googleVideoModelOptionsSchema
|
|
@@ -2117,7 +2730,7 @@ var GoogleGenerativeAIVideoModel = class {
|
|
|
2117
2730
|
details: "Google Generative AI video models require base64-encoded images. URL will be ignored."
|
|
2118
2731
|
});
|
|
2119
2732
|
} else {
|
|
2120
|
-
const base64Data = typeof options.image.data === "string" ? options.image.data : (0,
|
|
2733
|
+
const base64Data = typeof options.image.data === "string" ? options.image.data : (0, import_provider_utils16.convertUint8ArrayToBase64)(options.image.data);
|
|
2121
2734
|
instance.image = {
|
|
2122
2735
|
inlineData: {
|
|
2123
2736
|
mimeType: options.image.mediaType || "image/png",
|
|
@@ -2183,17 +2796,17 @@ var GoogleGenerativeAIVideoModel = class {
|
|
|
2183
2796
|
}
|
|
2184
2797
|
}
|
|
2185
2798
|
}
|
|
2186
|
-
const { value: operation } = await (0,
|
|
2799
|
+
const { value: operation } = await (0, import_provider_utils16.postJsonToApi)({
|
|
2187
2800
|
url: `${this.config.baseURL}/models/${this.modelId}:predictLongRunning`,
|
|
2188
|
-
headers: (0,
|
|
2189
|
-
await (0,
|
|
2801
|
+
headers: (0, import_provider_utils16.combineHeaders)(
|
|
2802
|
+
await (0, import_provider_utils16.resolve)(this.config.headers),
|
|
2190
2803
|
options.headers
|
|
2191
2804
|
),
|
|
2192
2805
|
body: {
|
|
2193
2806
|
instances,
|
|
2194
2807
|
parameters
|
|
2195
2808
|
},
|
|
2196
|
-
successfulResponseHandler: (0,
|
|
2809
|
+
successfulResponseHandler: (0, import_provider_utils16.createJsonResponseHandler)(
|
|
2197
2810
|
googleOperationSchema
|
|
2198
2811
|
),
|
|
2199
2812
|
failedResponseHandler: googleFailedResponseHandler,
|
|
@@ -2202,7 +2815,7 @@ var GoogleGenerativeAIVideoModel = class {
|
|
|
2202
2815
|
});
|
|
2203
2816
|
const operationName = operation.name;
|
|
2204
2817
|
if (!operationName) {
|
|
2205
|
-
throw new
|
|
2818
|
+
throw new import_provider5.AISDKError({
|
|
2206
2819
|
name: "GOOGLE_VIDEO_GENERATION_ERROR",
|
|
2207
2820
|
message: "No operation name returned from API"
|
|
2208
2821
|
});
|
|
@@ -2214,25 +2827,25 @@ var GoogleGenerativeAIVideoModel = class {
|
|
|
2214
2827
|
let responseHeaders;
|
|
2215
2828
|
while (!finalOperation.done) {
|
|
2216
2829
|
if (Date.now() - startTime > pollTimeoutMs) {
|
|
2217
|
-
throw new
|
|
2830
|
+
throw new import_provider5.AISDKError({
|
|
2218
2831
|
name: "GOOGLE_VIDEO_GENERATION_TIMEOUT",
|
|
2219
2832
|
message: `Video generation timed out after ${pollTimeoutMs}ms`
|
|
2220
2833
|
});
|
|
2221
2834
|
}
|
|
2222
|
-
await (0,
|
|
2835
|
+
await (0, import_provider_utils16.delay)(pollIntervalMs);
|
|
2223
2836
|
if ((_f = options.abortSignal) == null ? void 0 : _f.aborted) {
|
|
2224
|
-
throw new
|
|
2837
|
+
throw new import_provider5.AISDKError({
|
|
2225
2838
|
name: "GOOGLE_VIDEO_GENERATION_ABORTED",
|
|
2226
2839
|
message: "Video generation request was aborted"
|
|
2227
2840
|
});
|
|
2228
2841
|
}
|
|
2229
|
-
const { value: statusOperation, responseHeaders: pollHeaders } = await (0,
|
|
2842
|
+
const { value: statusOperation, responseHeaders: pollHeaders } = await (0, import_provider_utils16.getFromApi)({
|
|
2230
2843
|
url: `${this.config.baseURL}/${operationName}`,
|
|
2231
|
-
headers: (0,
|
|
2232
|
-
await (0,
|
|
2844
|
+
headers: (0, import_provider_utils16.combineHeaders)(
|
|
2845
|
+
await (0, import_provider_utils16.resolve)(this.config.headers),
|
|
2233
2846
|
options.headers
|
|
2234
2847
|
),
|
|
2235
|
-
successfulResponseHandler: (0,
|
|
2848
|
+
successfulResponseHandler: (0, import_provider_utils16.createJsonResponseHandler)(
|
|
2236
2849
|
googleOperationSchema
|
|
2237
2850
|
),
|
|
2238
2851
|
failedResponseHandler: googleFailedResponseHandler,
|
|
@@ -2243,21 +2856,21 @@ var GoogleGenerativeAIVideoModel = class {
|
|
|
2243
2856
|
responseHeaders = pollHeaders;
|
|
2244
2857
|
}
|
|
2245
2858
|
if (finalOperation.error) {
|
|
2246
|
-
throw new
|
|
2859
|
+
throw new import_provider5.AISDKError({
|
|
2247
2860
|
name: "GOOGLE_VIDEO_GENERATION_FAILED",
|
|
2248
2861
|
message: `Video generation failed: ${finalOperation.error.message}`
|
|
2249
2862
|
});
|
|
2250
2863
|
}
|
|
2251
2864
|
const response = finalOperation.response;
|
|
2252
2865
|
if (!((_g = response == null ? void 0 : response.generateVideoResponse) == null ? void 0 : _g.generatedSamples) || response.generateVideoResponse.generatedSamples.length === 0) {
|
|
2253
|
-
throw new
|
|
2866
|
+
throw new import_provider5.AISDKError({
|
|
2254
2867
|
name: "GOOGLE_VIDEO_GENERATION_ERROR",
|
|
2255
2868
|
message: `No videos in response. Response: ${JSON.stringify(finalOperation)}`
|
|
2256
2869
|
});
|
|
2257
2870
|
}
|
|
2258
2871
|
const videos = [];
|
|
2259
2872
|
const videoMetadata = [];
|
|
2260
|
-
const resolvedHeaders = await (0,
|
|
2873
|
+
const resolvedHeaders = await (0, import_provider_utils16.resolve)(this.config.headers);
|
|
2261
2874
|
const apiKey = resolvedHeaders == null ? void 0 : resolvedHeaders["x-goog-api-key"];
|
|
2262
2875
|
for (const generatedSample of response.generateVideoResponse.generatedSamples) {
|
|
2263
2876
|
if ((_h = generatedSample.video) == null ? void 0 : _h.uri) {
|
|
@@ -2273,7 +2886,7 @@ var GoogleGenerativeAIVideoModel = class {
|
|
|
2273
2886
|
}
|
|
2274
2887
|
}
|
|
2275
2888
|
if (videos.length === 0) {
|
|
2276
|
-
throw new
|
|
2889
|
+
throw new import_provider5.AISDKError({
|
|
2277
2890
|
name: "GOOGLE_VIDEO_GENERATION_ERROR",
|
|
2278
2891
|
message: "No valid videos in response"
|
|
2279
2892
|
});
|
|
@@ -2294,37 +2907,37 @@ var GoogleGenerativeAIVideoModel = class {
|
|
|
2294
2907
|
};
|
|
2295
2908
|
}
|
|
2296
2909
|
};
|
|
2297
|
-
var googleOperationSchema =
|
|
2298
|
-
name:
|
|
2299
|
-
done:
|
|
2300
|
-
error:
|
|
2301
|
-
code:
|
|
2302
|
-
message:
|
|
2303
|
-
status:
|
|
2910
|
+
var googleOperationSchema = import_v415.z.object({
|
|
2911
|
+
name: import_v415.z.string().nullish(),
|
|
2912
|
+
done: import_v415.z.boolean().nullish(),
|
|
2913
|
+
error: import_v415.z.object({
|
|
2914
|
+
code: import_v415.z.number().nullish(),
|
|
2915
|
+
message: import_v415.z.string(),
|
|
2916
|
+
status: import_v415.z.string().nullish()
|
|
2304
2917
|
}).nullish(),
|
|
2305
|
-
response:
|
|
2306
|
-
generateVideoResponse:
|
|
2307
|
-
generatedSamples:
|
|
2308
|
-
|
|
2309
|
-
video:
|
|
2310
|
-
uri:
|
|
2918
|
+
response: import_v415.z.object({
|
|
2919
|
+
generateVideoResponse: import_v415.z.object({
|
|
2920
|
+
generatedSamples: import_v415.z.array(
|
|
2921
|
+
import_v415.z.object({
|
|
2922
|
+
video: import_v415.z.object({
|
|
2923
|
+
uri: import_v415.z.string().nullish()
|
|
2311
2924
|
}).nullish()
|
|
2312
2925
|
})
|
|
2313
2926
|
).nullish()
|
|
2314
2927
|
}).nullish()
|
|
2315
2928
|
}).nullish()
|
|
2316
2929
|
});
|
|
2317
|
-
var googleVideoModelOptionsSchema = (0,
|
|
2318
|
-
() => (0,
|
|
2319
|
-
|
|
2320
|
-
pollIntervalMs:
|
|
2321
|
-
pollTimeoutMs:
|
|
2322
|
-
personGeneration:
|
|
2323
|
-
negativePrompt:
|
|
2324
|
-
referenceImages:
|
|
2325
|
-
|
|
2326
|
-
bytesBase64Encoded:
|
|
2327
|
-
gcsUri:
|
|
2930
|
+
var googleVideoModelOptionsSchema = (0, import_provider_utils16.lazySchema)(
|
|
2931
|
+
() => (0, import_provider_utils16.zodSchema)(
|
|
2932
|
+
import_v415.z.object({
|
|
2933
|
+
pollIntervalMs: import_v415.z.number().positive().nullish(),
|
|
2934
|
+
pollTimeoutMs: import_v415.z.number().positive().nullish(),
|
|
2935
|
+
personGeneration: import_v415.z.enum(["dont_allow", "allow_adult", "allow_all"]).nullish(),
|
|
2936
|
+
negativePrompt: import_v415.z.string().nullish(),
|
|
2937
|
+
referenceImages: import_v415.z.array(
|
|
2938
|
+
import_v415.z.object({
|
|
2939
|
+
bytesBase64Encoded: import_v415.z.string().nullish(),
|
|
2940
|
+
gcsUri: import_v415.z.string().nullish()
|
|
2328
2941
|
})
|
|
2329
2942
|
).nullish()
|
|
2330
2943
|
}).passthrough()
|
|
@@ -2334,11 +2947,11 @@ var googleVideoModelOptionsSchema = (0, import_provider_utils15.lazySchema)(
|
|
|
2334
2947
|
// src/google-provider.ts
|
|
2335
2948
|
function createGoogleGenerativeAI(options = {}) {
|
|
2336
2949
|
var _a, _b;
|
|
2337
|
-
const baseURL = (_a = (0,
|
|
2950
|
+
const baseURL = (_a = (0, import_provider_utils17.withoutTrailingSlash)(options.baseURL)) != null ? _a : "https://generativelanguage.googleapis.com/v1beta";
|
|
2338
2951
|
const providerName = (_b = options.name) != null ? _b : "google.generative-ai";
|
|
2339
|
-
const getHeaders = () => (0,
|
|
2952
|
+
const getHeaders = () => (0, import_provider_utils17.withUserAgentSuffix)(
|
|
2340
2953
|
{
|
|
2341
|
-
"x-goog-api-key": (0,
|
|
2954
|
+
"x-goog-api-key": (0, import_provider_utils17.loadApiKey)({
|
|
2342
2955
|
apiKey: options.apiKey,
|
|
2343
2956
|
environmentVariableName: "GOOGLE_GENERATIVE_AI_API_KEY",
|
|
2344
2957
|
description: "Google Generative AI"
|
|
@@ -2353,7 +2966,7 @@ function createGoogleGenerativeAI(options = {}) {
|
|
|
2353
2966
|
provider: providerName,
|
|
2354
2967
|
baseURL,
|
|
2355
2968
|
headers: getHeaders,
|
|
2356
|
-
generateId: (_a2 = options.generateId) != null ? _a2 :
|
|
2969
|
+
generateId: (_a2 = options.generateId) != null ? _a2 : import_provider_utils17.generateId,
|
|
2357
2970
|
supportedUrls: () => ({
|
|
2358
2971
|
"*": [
|
|
2359
2972
|
// Google Generative Language "files" endpoint
|
|
@@ -2381,6 +2994,12 @@ function createGoogleGenerativeAI(options = {}) {
|
|
|
2381
2994
|
headers: getHeaders,
|
|
2382
2995
|
fetch: options.fetch
|
|
2383
2996
|
});
|
|
2997
|
+
const createFiles = () => new GoogleGenerativeAIFiles({
|
|
2998
|
+
provider: providerName,
|
|
2999
|
+
baseURL,
|
|
3000
|
+
headers: getHeaders,
|
|
3001
|
+
fetch: options.fetch
|
|
3002
|
+
});
|
|
2384
3003
|
const createVideoModel = (modelId) => {
|
|
2385
3004
|
var _a2;
|
|
2386
3005
|
return new GoogleGenerativeAIVideoModel(modelId, {
|
|
@@ -2388,7 +3007,7 @@ function createGoogleGenerativeAI(options = {}) {
|
|
|
2388
3007
|
baseURL,
|
|
2389
3008
|
headers: getHeaders,
|
|
2390
3009
|
fetch: options.fetch,
|
|
2391
|
-
generateId: (_a2 = options.generateId) != null ? _a2 :
|
|
3010
|
+
generateId: (_a2 = options.generateId) != null ? _a2 : import_provider_utils17.generateId
|
|
2392
3011
|
});
|
|
2393
3012
|
};
|
|
2394
3013
|
const provider = function(modelId) {
|
|
@@ -2399,7 +3018,7 @@ function createGoogleGenerativeAI(options = {}) {
|
|
|
2399
3018
|
}
|
|
2400
3019
|
return createChatModel(modelId);
|
|
2401
3020
|
};
|
|
2402
|
-
provider.specificationVersion = "
|
|
3021
|
+
provider.specificationVersion = "v4";
|
|
2403
3022
|
provider.languageModel = createChatModel;
|
|
2404
3023
|
provider.chat = createChatModel;
|
|
2405
3024
|
provider.generativeAI = createChatModel;
|
|
@@ -2411,6 +3030,7 @@ function createGoogleGenerativeAI(options = {}) {
|
|
|
2411
3030
|
provider.imageModel = createImageModel;
|
|
2412
3031
|
provider.video = createVideoModel;
|
|
2413
3032
|
provider.videoModel = createVideoModel;
|
|
3033
|
+
provider.files = createFiles;
|
|
2414
3034
|
provider.tools = googleTools;
|
|
2415
3035
|
return provider;
|
|
2416
3036
|
}
|