@ai-sdk/google 4.0.0-beta.35 → 4.0.0-beta.37
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 +18 -0
- package/dist/index.js +492 -416
- package/dist/index.js.map +1 -1
- package/dist/internal/index.js +307 -283
- package/dist/internal/index.js.map +1 -1
- package/package.json +9 -10
- package/src/google-generative-ai-language-model.ts +8 -1
- package/src/google-generative-ai-options.ts +7 -0
- package/dist/index.d.mts +0 -427
- package/dist/index.mjs +0 -3430
- package/dist/index.mjs.map +0 -1
- package/dist/internal/index.d.mts +0 -319
- package/dist/internal/index.mjs +0 -2449
- package/dist/internal/index.mjs.map +0 -1
package/dist/index.js
CHANGED
|
@@ -1,81 +1,75 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __defProp = Object.defineProperty;
|
|
3
|
-
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
-
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
-
var __export = (target, all) => {
|
|
7
|
-
for (var name in all)
|
|
8
|
-
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
-
};
|
|
10
|
-
var __copyProps = (to, from, except, desc) => {
|
|
11
|
-
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
-
for (let key of __getOwnPropNames(from))
|
|
13
|
-
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
-
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
-
}
|
|
16
|
-
return to;
|
|
17
|
-
};
|
|
18
|
-
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
-
|
|
20
|
-
// src/index.ts
|
|
21
|
-
var index_exports = {};
|
|
22
|
-
__export(index_exports, {
|
|
23
|
-
VERSION: () => VERSION,
|
|
24
|
-
createGoogleGenerativeAI: () => createGoogleGenerativeAI,
|
|
25
|
-
google: () => google
|
|
26
|
-
});
|
|
27
|
-
module.exports = __toCommonJS(index_exports);
|
|
28
|
-
|
|
29
1
|
// src/google-provider.ts
|
|
30
|
-
|
|
2
|
+
import {
|
|
3
|
+
generateId as generateId2,
|
|
4
|
+
loadApiKey,
|
|
5
|
+
withoutTrailingSlash,
|
|
6
|
+
withUserAgentSuffix
|
|
7
|
+
} from "@ai-sdk/provider-utils";
|
|
31
8
|
|
|
32
9
|
// src/version.ts
|
|
33
|
-
var VERSION = true ? "4.0.0-beta.
|
|
10
|
+
var VERSION = true ? "4.0.0-beta.37" : "0.0.0-test";
|
|
34
11
|
|
|
35
12
|
// src/google-generative-ai-embedding-model.ts
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
13
|
+
import {
|
|
14
|
+
TooManyEmbeddingValuesForCallError
|
|
15
|
+
} from "@ai-sdk/provider";
|
|
16
|
+
import {
|
|
17
|
+
combineHeaders,
|
|
18
|
+
createJsonResponseHandler,
|
|
19
|
+
lazySchema as lazySchema3,
|
|
20
|
+
parseProviderOptions,
|
|
21
|
+
postJsonToApi,
|
|
22
|
+
resolve,
|
|
23
|
+
zodSchema as zodSchema3
|
|
24
|
+
} from "@ai-sdk/provider-utils";
|
|
25
|
+
import { z as z3 } from "zod/v4";
|
|
39
26
|
|
|
40
27
|
// src/google-error.ts
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
28
|
+
import {
|
|
29
|
+
createJsonErrorResponseHandler,
|
|
30
|
+
lazySchema,
|
|
31
|
+
zodSchema
|
|
32
|
+
} from "@ai-sdk/provider-utils";
|
|
33
|
+
import { z } from "zod/v4";
|
|
34
|
+
var googleErrorDataSchema = lazySchema(
|
|
35
|
+
() => zodSchema(
|
|
36
|
+
z.object({
|
|
37
|
+
error: z.object({
|
|
38
|
+
code: z.number().nullable(),
|
|
39
|
+
message: z.string(),
|
|
40
|
+
status: z.string()
|
|
50
41
|
})
|
|
51
42
|
})
|
|
52
43
|
)
|
|
53
44
|
);
|
|
54
|
-
var googleFailedResponseHandler =
|
|
45
|
+
var googleFailedResponseHandler = createJsonErrorResponseHandler({
|
|
55
46
|
errorSchema: googleErrorDataSchema,
|
|
56
47
|
errorToMessage: (data) => data.error.message
|
|
57
48
|
});
|
|
58
49
|
|
|
59
50
|
// src/google-generative-ai-embedding-options.ts
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
51
|
+
import {
|
|
52
|
+
lazySchema as lazySchema2,
|
|
53
|
+
zodSchema as zodSchema2
|
|
54
|
+
} from "@ai-sdk/provider-utils";
|
|
55
|
+
import { z as z2 } from "zod/v4";
|
|
56
|
+
var googleEmbeddingContentPartSchema = z2.union([
|
|
57
|
+
z2.object({ text: z2.string() }),
|
|
58
|
+
z2.object({
|
|
59
|
+
inlineData: z2.object({
|
|
60
|
+
mimeType: z2.string(),
|
|
61
|
+
data: z2.string()
|
|
68
62
|
})
|
|
69
63
|
})
|
|
70
64
|
]);
|
|
71
|
-
var googleEmbeddingModelOptions = (
|
|
72
|
-
() => (
|
|
73
|
-
|
|
65
|
+
var googleEmbeddingModelOptions = lazySchema2(
|
|
66
|
+
() => zodSchema2(
|
|
67
|
+
z2.object({
|
|
74
68
|
/**
|
|
75
69
|
* Optional. Optional reduced dimension for the output embedding.
|
|
76
70
|
* If set, excessive values in the output embedding are truncated from the end.
|
|
77
71
|
*/
|
|
78
|
-
outputDimensionality:
|
|
72
|
+
outputDimensionality: z2.number().optional(),
|
|
79
73
|
/**
|
|
80
74
|
* Optional. Specifies the task type for generating embeddings.
|
|
81
75
|
* Supported task types:
|
|
@@ -88,7 +82,7 @@ var googleEmbeddingModelOptions = (0, import_provider_utils2.lazySchema)(
|
|
|
88
82
|
* - FACT_VERIFICATION: Optimized for verifying factual information.
|
|
89
83
|
* - CODE_RETRIEVAL_QUERY: Optimized for retrieving code blocks based on natural language queries.
|
|
90
84
|
*/
|
|
91
|
-
taskType:
|
|
85
|
+
taskType: z2.enum([
|
|
92
86
|
"SEMANTIC_SIMILARITY",
|
|
93
87
|
"CLASSIFICATION",
|
|
94
88
|
"CLUSTERING",
|
|
@@ -107,7 +101,7 @@ var googleEmbeddingModelOptions = (0, import_provider_utils2.lazySchema)(
|
|
|
107
101
|
* The array length must match the number of values being embedded. In
|
|
108
102
|
* the case of a single embedding, the array length must be 1.
|
|
109
103
|
*/
|
|
110
|
-
content:
|
|
104
|
+
content: z2.array(z2.array(googleEmbeddingContentPartSchema).min(1).nullable()).optional()
|
|
111
105
|
})
|
|
112
106
|
)
|
|
113
107
|
);
|
|
@@ -130,21 +124,21 @@ var GoogleGenerativeAIEmbeddingModel = class {
|
|
|
130
124
|
abortSignal,
|
|
131
125
|
providerOptions
|
|
132
126
|
}) {
|
|
133
|
-
const googleOptions = await
|
|
127
|
+
const googleOptions = await parseProviderOptions({
|
|
134
128
|
provider: "google",
|
|
135
129
|
providerOptions,
|
|
136
130
|
schema: googleEmbeddingModelOptions
|
|
137
131
|
});
|
|
138
132
|
if (values.length > this.maxEmbeddingsPerCall) {
|
|
139
|
-
throw new
|
|
133
|
+
throw new TooManyEmbeddingValuesForCallError({
|
|
140
134
|
provider: this.provider,
|
|
141
135
|
modelId: this.modelId,
|
|
142
136
|
maxEmbeddingsPerCall: this.maxEmbeddingsPerCall,
|
|
143
137
|
values
|
|
144
138
|
});
|
|
145
139
|
}
|
|
146
|
-
const mergedHeaders =
|
|
147
|
-
await
|
|
140
|
+
const mergedHeaders = combineHeaders(
|
|
141
|
+
await resolve(this.config.headers),
|
|
148
142
|
headers
|
|
149
143
|
);
|
|
150
144
|
const multimodalContent = googleOptions == null ? void 0 : googleOptions.content;
|
|
@@ -161,7 +155,7 @@ var GoogleGenerativeAIEmbeddingModel = class {
|
|
|
161
155
|
responseHeaders: responseHeaders2,
|
|
162
156
|
value: response2,
|
|
163
157
|
rawValue: rawValue2
|
|
164
|
-
} = await
|
|
158
|
+
} = await postJsonToApi({
|
|
165
159
|
url: `${this.config.baseURL}/models/${this.modelId}:embedContent`,
|
|
166
160
|
headers: mergedHeaders,
|
|
167
161
|
body: {
|
|
@@ -173,7 +167,7 @@ var GoogleGenerativeAIEmbeddingModel = class {
|
|
|
173
167
|
taskType: googleOptions == null ? void 0 : googleOptions.taskType
|
|
174
168
|
},
|
|
175
169
|
failedResponseHandler: googleFailedResponseHandler,
|
|
176
|
-
successfulResponseHandler:
|
|
170
|
+
successfulResponseHandler: createJsonResponseHandler(
|
|
177
171
|
googleGenerativeAISingleEmbeddingResponseSchema
|
|
178
172
|
),
|
|
179
173
|
abortSignal,
|
|
@@ -190,7 +184,7 @@ var GoogleGenerativeAIEmbeddingModel = class {
|
|
|
190
184
|
responseHeaders,
|
|
191
185
|
value: response,
|
|
192
186
|
rawValue
|
|
193
|
-
} = await
|
|
187
|
+
} = await postJsonToApi({
|
|
194
188
|
url: `${this.config.baseURL}/models/${this.modelId}:batchEmbedContents`,
|
|
195
189
|
headers: mergedHeaders,
|
|
196
190
|
body: {
|
|
@@ -209,7 +203,7 @@ var GoogleGenerativeAIEmbeddingModel = class {
|
|
|
209
203
|
})
|
|
210
204
|
},
|
|
211
205
|
failedResponseHandler: googleFailedResponseHandler,
|
|
212
|
-
successfulResponseHandler:
|
|
206
|
+
successfulResponseHandler: createJsonResponseHandler(
|
|
213
207
|
googleGenerativeAITextEmbeddingResponseSchema
|
|
214
208
|
),
|
|
215
209
|
abortSignal,
|
|
@@ -223,24 +217,37 @@ var GoogleGenerativeAIEmbeddingModel = class {
|
|
|
223
217
|
};
|
|
224
218
|
}
|
|
225
219
|
};
|
|
226
|
-
var googleGenerativeAITextEmbeddingResponseSchema = (
|
|
227
|
-
() => (
|
|
228
|
-
|
|
229
|
-
embeddings:
|
|
220
|
+
var googleGenerativeAITextEmbeddingResponseSchema = lazySchema3(
|
|
221
|
+
() => zodSchema3(
|
|
222
|
+
z3.object({
|
|
223
|
+
embeddings: z3.array(z3.object({ values: z3.array(z3.number()) }))
|
|
230
224
|
})
|
|
231
225
|
)
|
|
232
226
|
);
|
|
233
|
-
var googleGenerativeAISingleEmbeddingResponseSchema = (
|
|
234
|
-
() => (
|
|
235
|
-
|
|
236
|
-
embedding:
|
|
227
|
+
var googleGenerativeAISingleEmbeddingResponseSchema = lazySchema3(
|
|
228
|
+
() => zodSchema3(
|
|
229
|
+
z3.object({
|
|
230
|
+
embedding: z3.object({ values: z3.array(z3.number()) })
|
|
237
231
|
})
|
|
238
232
|
)
|
|
239
233
|
);
|
|
240
234
|
|
|
241
235
|
// src/google-generative-ai-language-model.ts
|
|
242
|
-
|
|
243
|
-
|
|
236
|
+
import {
|
|
237
|
+
combineHeaders as combineHeaders2,
|
|
238
|
+
createEventSourceResponseHandler,
|
|
239
|
+
createJsonResponseHandler as createJsonResponseHandler2,
|
|
240
|
+
generateId,
|
|
241
|
+
isCustomReasoning,
|
|
242
|
+
lazySchema as lazySchema5,
|
|
243
|
+
mapReasoningToProviderBudget,
|
|
244
|
+
mapReasoningToProviderEffort,
|
|
245
|
+
parseProviderOptions as parseProviderOptions2,
|
|
246
|
+
postJsonToApi as postJsonToApi2,
|
|
247
|
+
resolve as resolve2,
|
|
248
|
+
zodSchema as zodSchema5
|
|
249
|
+
} from "@ai-sdk/provider-utils";
|
|
250
|
+
import { z as z5 } from "zod/v4";
|
|
244
251
|
|
|
245
252
|
// src/convert-google-generative-ai-usage.ts
|
|
246
253
|
function convertGoogleGenerativeAIUsage(usage) {
|
|
@@ -398,8 +405,14 @@ function isEmptyObjectSchema(jsonSchema) {
|
|
|
398
405
|
}
|
|
399
406
|
|
|
400
407
|
// src/convert-to-google-generative-ai-messages.ts
|
|
401
|
-
|
|
402
|
-
|
|
408
|
+
import {
|
|
409
|
+
UnsupportedFunctionalityError
|
|
410
|
+
} from "@ai-sdk/provider";
|
|
411
|
+
import {
|
|
412
|
+
convertToBase64,
|
|
413
|
+
isProviderReference,
|
|
414
|
+
resolveProviderReference
|
|
415
|
+
} from "@ai-sdk/provider-utils";
|
|
403
416
|
var dataUrlRegex = /^data:([^;,]+);base64,(.+)$/s;
|
|
404
417
|
function parseBase64DataUrl(value) {
|
|
405
418
|
const match = dataUrlRegex.exec(value);
|
|
@@ -516,7 +529,7 @@ function convertToGoogleGenerativeAIMessages(prompt, options) {
|
|
|
516
529
|
switch (role) {
|
|
517
530
|
case "system": {
|
|
518
531
|
if (!systemMessagesAllowed) {
|
|
519
|
-
throw new
|
|
532
|
+
throw new UnsupportedFunctionalityError({
|
|
520
533
|
functionality: "system messages are only supported at the beginning of the conversation"
|
|
521
534
|
});
|
|
522
535
|
}
|
|
@@ -541,16 +554,16 @@ function convertToGoogleGenerativeAIMessages(prompt, options) {
|
|
|
541
554
|
fileUri: part.data.toString()
|
|
542
555
|
}
|
|
543
556
|
});
|
|
544
|
-
} else if (
|
|
557
|
+
} else if (isProviderReference(part.data)) {
|
|
545
558
|
if (providerOptionsName === "vertex") {
|
|
546
|
-
throw new
|
|
559
|
+
throw new UnsupportedFunctionalityError({
|
|
547
560
|
functionality: "file parts with provider references"
|
|
548
561
|
});
|
|
549
562
|
}
|
|
550
563
|
parts.push({
|
|
551
564
|
fileData: {
|
|
552
565
|
mimeType: mediaType,
|
|
553
|
-
fileUri:
|
|
566
|
+
fileUri: resolveProviderReference({
|
|
554
567
|
reference: part.data,
|
|
555
568
|
provider: "google"
|
|
556
569
|
})
|
|
@@ -560,7 +573,7 @@ function convertToGoogleGenerativeAIMessages(prompt, options) {
|
|
|
560
573
|
parts.push({
|
|
561
574
|
inlineData: {
|
|
562
575
|
mimeType: mediaType,
|
|
563
|
-
data:
|
|
576
|
+
data: convertToBase64(part.data)
|
|
564
577
|
}
|
|
565
578
|
});
|
|
566
579
|
}
|
|
@@ -595,14 +608,14 @@ function convertToGoogleGenerativeAIMessages(prompt, options) {
|
|
|
595
608
|
}
|
|
596
609
|
case "reasoning-file": {
|
|
597
610
|
if (part.data instanceof URL) {
|
|
598
|
-
throw new
|
|
611
|
+
throw new UnsupportedFunctionalityError({
|
|
599
612
|
functionality: "File data URLs in assistant messages are not supported"
|
|
600
613
|
});
|
|
601
614
|
}
|
|
602
615
|
return {
|
|
603
616
|
inlineData: {
|
|
604
617
|
mimeType: part.mediaType,
|
|
605
|
-
data:
|
|
618
|
+
data: convertToBase64(part.data)
|
|
606
619
|
},
|
|
607
620
|
thought: true,
|
|
608
621
|
thoughtSignature
|
|
@@ -610,20 +623,20 @@ function convertToGoogleGenerativeAIMessages(prompt, options) {
|
|
|
610
623
|
}
|
|
611
624
|
case "file": {
|
|
612
625
|
if (part.data instanceof URL) {
|
|
613
|
-
throw new
|
|
626
|
+
throw new UnsupportedFunctionalityError({
|
|
614
627
|
functionality: "File data URLs in assistant messages are not supported"
|
|
615
628
|
});
|
|
616
629
|
}
|
|
617
|
-
if (
|
|
630
|
+
if (isProviderReference(part.data)) {
|
|
618
631
|
if (providerOptionsName === "vertex") {
|
|
619
|
-
throw new
|
|
632
|
+
throw new UnsupportedFunctionalityError({
|
|
620
633
|
functionality: "file parts with provider references"
|
|
621
634
|
});
|
|
622
635
|
}
|
|
623
636
|
return {
|
|
624
637
|
fileData: {
|
|
625
638
|
mimeType: part.mediaType,
|
|
626
|
-
fileUri:
|
|
639
|
+
fileUri: resolveProviderReference({
|
|
627
640
|
reference: part.data,
|
|
628
641
|
provider: "google"
|
|
629
642
|
})
|
|
@@ -635,7 +648,7 @@ function convertToGoogleGenerativeAIMessages(prompt, options) {
|
|
|
635
648
|
return {
|
|
636
649
|
inlineData: {
|
|
637
650
|
mimeType: part.mediaType,
|
|
638
|
-
data:
|
|
651
|
+
data: convertToBase64(part.data)
|
|
639
652
|
},
|
|
640
653
|
...(providerOpts == null ? void 0 : providerOpts.thought) === true ? { thought: true } : {},
|
|
641
654
|
thoughtSignature
|
|
@@ -752,24 +765,24 @@ function getModelPath(modelId) {
|
|
|
752
765
|
}
|
|
753
766
|
|
|
754
767
|
// src/google-generative-ai-options.ts
|
|
755
|
-
|
|
756
|
-
|
|
757
|
-
var googleLanguageModelOptions = (
|
|
758
|
-
() => (
|
|
759
|
-
|
|
760
|
-
responseModalities:
|
|
761
|
-
thinkingConfig:
|
|
762
|
-
thinkingBudget:
|
|
763
|
-
includeThoughts:
|
|
768
|
+
import { lazySchema as lazySchema4, zodSchema as zodSchema4 } from "@ai-sdk/provider-utils";
|
|
769
|
+
import { z as z4 } from "zod/v4";
|
|
770
|
+
var googleLanguageModelOptions = lazySchema4(
|
|
771
|
+
() => zodSchema4(
|
|
772
|
+
z4.object({
|
|
773
|
+
responseModalities: z4.array(z4.enum(["TEXT", "IMAGE"])).optional(),
|
|
774
|
+
thinkingConfig: z4.object({
|
|
775
|
+
thinkingBudget: z4.number().optional(),
|
|
776
|
+
includeThoughts: z4.boolean().optional(),
|
|
764
777
|
// https://ai.google.dev/gemini-api/docs/gemini-3?thinking=high#thinking_level
|
|
765
|
-
thinkingLevel:
|
|
778
|
+
thinkingLevel: z4.enum(["minimal", "low", "medium", "high"]).optional()
|
|
766
779
|
}).optional(),
|
|
767
780
|
/**
|
|
768
781
|
* Optional.
|
|
769
782
|
* The name of the cached content used as context to serve the prediction.
|
|
770
783
|
* Format: cachedContents/{cachedContent}
|
|
771
784
|
*/
|
|
772
|
-
cachedContent:
|
|
785
|
+
cachedContent: z4.string().optional(),
|
|
773
786
|
/**
|
|
774
787
|
* Optional. Enable structured output. Default is true.
|
|
775
788
|
*
|
|
@@ -778,13 +791,13 @@ var googleLanguageModelOptions = (0, import_provider_utils5.lazySchema)(
|
|
|
778
791
|
* Google Generative AI uses. You can use this to disable
|
|
779
792
|
* structured outputs if you need to.
|
|
780
793
|
*/
|
|
781
|
-
structuredOutputs:
|
|
794
|
+
structuredOutputs: z4.boolean().optional(),
|
|
782
795
|
/**
|
|
783
796
|
* Optional. A list of unique safety settings for blocking unsafe content.
|
|
784
797
|
*/
|
|
785
|
-
safetySettings:
|
|
786
|
-
|
|
787
|
-
category:
|
|
798
|
+
safetySettings: z4.array(
|
|
799
|
+
z4.object({
|
|
800
|
+
category: z4.enum([
|
|
788
801
|
"HARM_CATEGORY_UNSPECIFIED",
|
|
789
802
|
"HARM_CATEGORY_HATE_SPEECH",
|
|
790
803
|
"HARM_CATEGORY_DANGEROUS_CONTENT",
|
|
@@ -792,7 +805,7 @@ var googleLanguageModelOptions = (0, import_provider_utils5.lazySchema)(
|
|
|
792
805
|
"HARM_CATEGORY_SEXUALLY_EXPLICIT",
|
|
793
806
|
"HARM_CATEGORY_CIVIC_INTEGRITY"
|
|
794
807
|
]),
|
|
795
|
-
threshold:
|
|
808
|
+
threshold: z4.enum([
|
|
796
809
|
"HARM_BLOCK_THRESHOLD_UNSPECIFIED",
|
|
797
810
|
"BLOCK_LOW_AND_ABOVE",
|
|
798
811
|
"BLOCK_MEDIUM_AND_ABOVE",
|
|
@@ -802,7 +815,7 @@ var googleLanguageModelOptions = (0, import_provider_utils5.lazySchema)(
|
|
|
802
815
|
])
|
|
803
816
|
})
|
|
804
817
|
).optional(),
|
|
805
|
-
threshold:
|
|
818
|
+
threshold: z4.enum([
|
|
806
819
|
"HARM_BLOCK_THRESHOLD_UNSPECIFIED",
|
|
807
820
|
"BLOCK_LOW_AND_ABOVE",
|
|
808
821
|
"BLOCK_MEDIUM_AND_ABOVE",
|
|
@@ -815,19 +828,19 @@ var googleLanguageModelOptions = (0, import_provider_utils5.lazySchema)(
|
|
|
815
828
|
*
|
|
816
829
|
* https://cloud.google.com/vertex-ai/generative-ai/docs/multimodal/audio-understanding
|
|
817
830
|
*/
|
|
818
|
-
audioTimestamp:
|
|
831
|
+
audioTimestamp: z4.boolean().optional(),
|
|
819
832
|
/**
|
|
820
833
|
* Optional. Defines labels used in billing reports. Available on Vertex AI only.
|
|
821
834
|
*
|
|
822
835
|
* https://cloud.google.com/vertex-ai/generative-ai/docs/multimodal/add-labels-to-api-calls
|
|
823
836
|
*/
|
|
824
|
-
labels:
|
|
837
|
+
labels: z4.record(z4.string(), z4.string()).optional(),
|
|
825
838
|
/**
|
|
826
839
|
* Optional. If specified, the media resolution specified will be used.
|
|
827
840
|
*
|
|
828
841
|
* https://ai.google.dev/api/generate-content#MediaResolution
|
|
829
842
|
*/
|
|
830
|
-
mediaResolution:
|
|
843
|
+
mediaResolution: z4.enum([
|
|
831
844
|
"MEDIA_RESOLUTION_UNSPECIFIED",
|
|
832
845
|
"MEDIA_RESOLUTION_LOW",
|
|
833
846
|
"MEDIA_RESOLUTION_MEDIUM",
|
|
@@ -838,8 +851,8 @@ var googleLanguageModelOptions = (0, import_provider_utils5.lazySchema)(
|
|
|
838
851
|
*
|
|
839
852
|
* https://ai.google.dev/gemini-api/docs/image-generation#aspect_ratios
|
|
840
853
|
*/
|
|
841
|
-
imageConfig:
|
|
842
|
-
aspectRatio:
|
|
854
|
+
imageConfig: z4.object({
|
|
855
|
+
aspectRatio: z4.enum([
|
|
843
856
|
"1:1",
|
|
844
857
|
"2:3",
|
|
845
858
|
"3:2",
|
|
@@ -855,7 +868,7 @@ var googleLanguageModelOptions = (0, import_provider_utils5.lazySchema)(
|
|
|
855
868
|
"1:4",
|
|
856
869
|
"4:1"
|
|
857
870
|
]).optional(),
|
|
858
|
-
imageSize:
|
|
871
|
+
imageSize: z4.enum(["1K", "2K", "4K", "512"]).optional()
|
|
859
872
|
}).optional(),
|
|
860
873
|
/**
|
|
861
874
|
* Optional. Configuration for grounding retrieval.
|
|
@@ -863,10 +876,10 @@ var googleLanguageModelOptions = (0, import_provider_utils5.lazySchema)(
|
|
|
863
876
|
*
|
|
864
877
|
* https://cloud.google.com/vertex-ai/generative-ai/docs/grounding/grounding-with-google-maps
|
|
865
878
|
*/
|
|
866
|
-
retrievalConfig:
|
|
867
|
-
latLng:
|
|
868
|
-
latitude:
|
|
869
|
-
longitude:
|
|
879
|
+
retrievalConfig: z4.object({
|
|
880
|
+
latLng: z4.object({
|
|
881
|
+
latitude: z4.number(),
|
|
882
|
+
longitude: z4.number()
|
|
870
883
|
}).optional()
|
|
871
884
|
}).optional(),
|
|
872
885
|
/**
|
|
@@ -879,17 +892,24 @@ var googleLanguageModelOptions = (0, import_provider_utils5.lazySchema)(
|
|
|
879
892
|
*
|
|
880
893
|
* https://docs.cloud.google.com/vertex-ai/generative-ai/docs/multimodal/function-calling#streaming-fc
|
|
881
894
|
*/
|
|
882
|
-
streamFunctionCallArguments:
|
|
895
|
+
streamFunctionCallArguments: z4.boolean().optional(),
|
|
883
896
|
/**
|
|
884
897
|
* Optional. The service tier to use for the request.
|
|
885
898
|
*/
|
|
886
|
-
serviceTier:
|
|
899
|
+
serviceTier: z4.enum(["standard", "flex", "priority"]).optional()
|
|
887
900
|
})
|
|
888
901
|
)
|
|
889
902
|
);
|
|
903
|
+
var VertexServiceTierMap = {
|
|
904
|
+
standard: "SERVICE_TIER_STANDARD",
|
|
905
|
+
flex: "SERVICE_TIER_FLEX",
|
|
906
|
+
priority: "SERVICE_TIER_PRIORITY"
|
|
907
|
+
};
|
|
890
908
|
|
|
891
909
|
// src/google-prepare-tools.ts
|
|
892
|
-
|
|
910
|
+
import {
|
|
911
|
+
UnsupportedFunctionalityError as UnsupportedFunctionalityError2
|
|
912
|
+
} from "@ai-sdk/provider";
|
|
893
913
|
function prepareTools({
|
|
894
914
|
tools,
|
|
895
915
|
toolChoice,
|
|
@@ -1131,7 +1151,7 @@ function prepareTools({
|
|
|
1131
1151
|
};
|
|
1132
1152
|
default: {
|
|
1133
1153
|
const _exhaustiveCheck = type;
|
|
1134
|
-
throw new
|
|
1154
|
+
throw new UnsupportedFunctionalityError2({
|
|
1135
1155
|
functionality: `tool choice type: ${_exhaustiveCheck}`
|
|
1136
1156
|
});
|
|
1137
1157
|
}
|
|
@@ -1394,7 +1414,7 @@ var GoogleGenerativeAILanguageModel = class {
|
|
|
1394
1414
|
var _a;
|
|
1395
1415
|
this.modelId = modelId;
|
|
1396
1416
|
this.config = config;
|
|
1397
|
-
this.generateId = (_a = config.generateId) != null ? _a :
|
|
1417
|
+
this.generateId = (_a = config.generateId) != null ? _a : generateId;
|
|
1398
1418
|
}
|
|
1399
1419
|
get provider() {
|
|
1400
1420
|
return this.config.provider;
|
|
@@ -1422,13 +1442,13 @@ var GoogleGenerativeAILanguageModel = class {
|
|
|
1422
1442
|
var _a, _b;
|
|
1423
1443
|
const warnings = [];
|
|
1424
1444
|
const providerOptionsName = this.config.provider.includes("vertex") ? "vertex" : "google";
|
|
1425
|
-
let googleOptions = await (
|
|
1445
|
+
let googleOptions = await parseProviderOptions2({
|
|
1426
1446
|
provider: providerOptionsName,
|
|
1427
1447
|
providerOptions,
|
|
1428
1448
|
schema: googleLanguageModelOptions
|
|
1429
1449
|
});
|
|
1430
1450
|
if (googleOptions == null && providerOptionsName !== "google") {
|
|
1431
|
-
googleOptions = await (
|
|
1451
|
+
googleOptions = await parseProviderOptions2({
|
|
1432
1452
|
provider: "google",
|
|
1433
1453
|
providerOptions,
|
|
1434
1454
|
schema: googleLanguageModelOptions
|
|
@@ -1449,6 +1469,10 @@ var GoogleGenerativeAILanguageModel = class {
|
|
|
1449
1469
|
message: `'streamFunctionCallArguments' is only supported on the Vertex AI API and will be ignored with the current Google provider (${this.config.provider}). See https://docs.cloud.google.com/vertex-ai/generative-ai/docs/multimodal/function-calling#streaming-fc`
|
|
1450
1470
|
});
|
|
1451
1471
|
}
|
|
1472
|
+
let sanitizedServiceTier = googleOptions == null ? void 0 : googleOptions.serviceTier;
|
|
1473
|
+
if ((googleOptions == null ? void 0 : googleOptions.serviceTier) && isVertexProvider) {
|
|
1474
|
+
sanitizedServiceTier = VertexServiceTierMap[googleOptions.serviceTier];
|
|
1475
|
+
}
|
|
1452
1476
|
const isGemmaModel = this.modelId.toLowerCase().startsWith("gemma-");
|
|
1453
1477
|
const supportsFunctionResponseParts = this.modelId.startsWith("gemini-3");
|
|
1454
1478
|
const { contents, systemInstruction } = convertToGoogleGenerativeAIMessages(
|
|
@@ -1525,7 +1549,7 @@ var GoogleGenerativeAILanguageModel = class {
|
|
|
1525
1549
|
toolConfig,
|
|
1526
1550
|
cachedContent: googleOptions == null ? void 0 : googleOptions.cachedContent,
|
|
1527
1551
|
labels: googleOptions == null ? void 0 : googleOptions.labels,
|
|
1528
|
-
serviceTier:
|
|
1552
|
+
serviceTier: sanitizedServiceTier
|
|
1529
1553
|
},
|
|
1530
1554
|
warnings: [...warnings, ...toolWarnings],
|
|
1531
1555
|
providerOptionsName
|
|
@@ -1534,22 +1558,22 @@ var GoogleGenerativeAILanguageModel = class {
|
|
|
1534
1558
|
async doGenerate(options) {
|
|
1535
1559
|
var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o, _p;
|
|
1536
1560
|
const { args, warnings, providerOptionsName } = await this.getArgs(options);
|
|
1537
|
-
const mergedHeaders = (
|
|
1538
|
-
await (
|
|
1561
|
+
const mergedHeaders = combineHeaders2(
|
|
1562
|
+
await resolve2(this.config.headers),
|
|
1539
1563
|
options.headers
|
|
1540
1564
|
);
|
|
1541
1565
|
const {
|
|
1542
1566
|
responseHeaders,
|
|
1543
1567
|
value: response,
|
|
1544
1568
|
rawValue: rawResponse
|
|
1545
|
-
} = await (
|
|
1569
|
+
} = await postJsonToApi2({
|
|
1546
1570
|
url: `${this.config.baseURL}/${getModelPath(
|
|
1547
1571
|
this.modelId
|
|
1548
1572
|
)}:generateContent`,
|
|
1549
1573
|
headers: mergedHeaders,
|
|
1550
1574
|
body: args,
|
|
1551
1575
|
failedResponseHandler: googleFailedResponseHandler,
|
|
1552
|
-
successfulResponseHandler: (
|
|
1576
|
+
successfulResponseHandler: createJsonResponseHandler2(responseSchema),
|
|
1553
1577
|
abortSignal: options.abortSignal,
|
|
1554
1578
|
fetch: this.config.fetch
|
|
1555
1579
|
});
|
|
@@ -1716,18 +1740,18 @@ var GoogleGenerativeAILanguageModel = class {
|
|
|
1716
1740
|
options,
|
|
1717
1741
|
{ isStreaming: true }
|
|
1718
1742
|
);
|
|
1719
|
-
const headers = (
|
|
1720
|
-
await (
|
|
1743
|
+
const headers = combineHeaders2(
|
|
1744
|
+
await resolve2(this.config.headers),
|
|
1721
1745
|
options.headers
|
|
1722
1746
|
);
|
|
1723
|
-
const { responseHeaders, value: response } = await (
|
|
1747
|
+
const { responseHeaders, value: response } = await postJsonToApi2({
|
|
1724
1748
|
url: `${this.config.baseURL}/${getModelPath(
|
|
1725
1749
|
this.modelId
|
|
1726
1750
|
)}:streamGenerateContent?alt=sse`,
|
|
1727
1751
|
headers,
|
|
1728
1752
|
body: args,
|
|
1729
1753
|
failedResponseHandler: googleFailedResponseHandler,
|
|
1730
|
-
successfulResponseHandler:
|
|
1754
|
+
successfulResponseHandler: createEventSourceResponseHandler(chunkSchema),
|
|
1731
1755
|
abortSignal: options.abortSignal,
|
|
1732
1756
|
fetch: this.config.fetch
|
|
1733
1757
|
});
|
|
@@ -2123,7 +2147,7 @@ function resolveThinkingConfig({
|
|
|
2123
2147
|
modelId,
|
|
2124
2148
|
warnings
|
|
2125
2149
|
}) {
|
|
2126
|
-
if (!
|
|
2150
|
+
if (!isCustomReasoning(reasoning)) {
|
|
2127
2151
|
return void 0;
|
|
2128
2152
|
}
|
|
2129
2153
|
if (isGemini3Model(modelId) && !modelId.includes("gemini-3-pro-image")) {
|
|
@@ -2138,7 +2162,7 @@ function resolveGemini3ThinkingConfig({
|
|
|
2138
2162
|
if (reasoning === "none") {
|
|
2139
2163
|
return { thinkingLevel: "minimal" };
|
|
2140
2164
|
}
|
|
2141
|
-
const thinkingLevel =
|
|
2165
|
+
const thinkingLevel = mapReasoningToProviderEffort({
|
|
2142
2166
|
reasoning,
|
|
2143
2167
|
effortMap: {
|
|
2144
2168
|
minimal: "minimal",
|
|
@@ -2162,7 +2186,7 @@ function resolveGemini25ThinkingConfig({
|
|
|
2162
2186
|
if (reasoning === "none") {
|
|
2163
2187
|
return { thinkingBudget: 0 };
|
|
2164
2188
|
}
|
|
2165
|
-
const thinkingBudget =
|
|
2189
|
+
const thinkingBudget = mapReasoningToProviderBudget({
|
|
2166
2190
|
reasoning,
|
|
2167
2191
|
maxOutputTokens: getMaxOutputTokensForGemini25Model(),
|
|
2168
2192
|
maxReasoningBudget: getMaxThinkingTokensForGemini25Model(modelId),
|
|
@@ -2268,270 +2292,286 @@ function extractSources({
|
|
|
2268
2292
|
}
|
|
2269
2293
|
return sources.length > 0 ? sources : void 0;
|
|
2270
2294
|
}
|
|
2271
|
-
var getGroundingMetadataSchema = () =>
|
|
2272
|
-
webSearchQueries:
|
|
2273
|
-
imageSearchQueries:
|
|
2274
|
-
retrievalQueries:
|
|
2275
|
-
searchEntryPoint:
|
|
2276
|
-
groundingChunks:
|
|
2277
|
-
|
|
2278
|
-
web:
|
|
2279
|
-
image:
|
|
2280
|
-
sourceUri:
|
|
2281
|
-
imageUri:
|
|
2282
|
-
title:
|
|
2283
|
-
domain:
|
|
2295
|
+
var getGroundingMetadataSchema = () => z5.object({
|
|
2296
|
+
webSearchQueries: z5.array(z5.string()).nullish(),
|
|
2297
|
+
imageSearchQueries: z5.array(z5.string()).nullish(),
|
|
2298
|
+
retrievalQueries: z5.array(z5.string()).nullish(),
|
|
2299
|
+
searchEntryPoint: z5.object({ renderedContent: z5.string() }).nullish(),
|
|
2300
|
+
groundingChunks: z5.array(
|
|
2301
|
+
z5.object({
|
|
2302
|
+
web: z5.object({ uri: z5.string(), title: z5.string().nullish() }).nullish(),
|
|
2303
|
+
image: z5.object({
|
|
2304
|
+
sourceUri: z5.string(),
|
|
2305
|
+
imageUri: z5.string(),
|
|
2306
|
+
title: z5.string().nullish(),
|
|
2307
|
+
domain: z5.string().nullish()
|
|
2284
2308
|
}).nullish(),
|
|
2285
|
-
retrievedContext:
|
|
2286
|
-
uri:
|
|
2287
|
-
title:
|
|
2288
|
-
text:
|
|
2289
|
-
fileSearchStore:
|
|
2309
|
+
retrievedContext: z5.object({
|
|
2310
|
+
uri: z5.string().nullish(),
|
|
2311
|
+
title: z5.string().nullish(),
|
|
2312
|
+
text: z5.string().nullish(),
|
|
2313
|
+
fileSearchStore: z5.string().nullish()
|
|
2290
2314
|
}).nullish(),
|
|
2291
|
-
maps:
|
|
2292
|
-
uri:
|
|
2293
|
-
title:
|
|
2294
|
-
text:
|
|
2295
|
-
placeId:
|
|
2315
|
+
maps: z5.object({
|
|
2316
|
+
uri: z5.string().nullish(),
|
|
2317
|
+
title: z5.string().nullish(),
|
|
2318
|
+
text: z5.string().nullish(),
|
|
2319
|
+
placeId: z5.string().nullish()
|
|
2296
2320
|
}).nullish()
|
|
2297
2321
|
})
|
|
2298
2322
|
).nullish(),
|
|
2299
|
-
groundingSupports:
|
|
2300
|
-
|
|
2301
|
-
segment:
|
|
2302
|
-
startIndex:
|
|
2303
|
-
endIndex:
|
|
2304
|
-
text:
|
|
2323
|
+
groundingSupports: z5.array(
|
|
2324
|
+
z5.object({
|
|
2325
|
+
segment: z5.object({
|
|
2326
|
+
startIndex: z5.number().nullish(),
|
|
2327
|
+
endIndex: z5.number().nullish(),
|
|
2328
|
+
text: z5.string().nullish()
|
|
2305
2329
|
}).nullish(),
|
|
2306
|
-
segment_text:
|
|
2307
|
-
groundingChunkIndices:
|
|
2308
|
-
supportChunkIndices:
|
|
2309
|
-
confidenceScores:
|
|
2310
|
-
confidenceScore:
|
|
2330
|
+
segment_text: z5.string().nullish(),
|
|
2331
|
+
groundingChunkIndices: z5.array(z5.number()).nullish(),
|
|
2332
|
+
supportChunkIndices: z5.array(z5.number()).nullish(),
|
|
2333
|
+
confidenceScores: z5.array(z5.number()).nullish(),
|
|
2334
|
+
confidenceScore: z5.array(z5.number()).nullish()
|
|
2311
2335
|
})
|
|
2312
2336
|
).nullish(),
|
|
2313
|
-
retrievalMetadata:
|
|
2314
|
-
|
|
2315
|
-
webDynamicRetrievalScore:
|
|
2337
|
+
retrievalMetadata: z5.union([
|
|
2338
|
+
z5.object({
|
|
2339
|
+
webDynamicRetrievalScore: z5.number()
|
|
2316
2340
|
}),
|
|
2317
|
-
|
|
2341
|
+
z5.object({})
|
|
2318
2342
|
]).nullish()
|
|
2319
2343
|
});
|
|
2320
|
-
var partialArgSchema =
|
|
2321
|
-
jsonPath:
|
|
2322
|
-
stringValue:
|
|
2323
|
-
numberValue:
|
|
2324
|
-
boolValue:
|
|
2325
|
-
nullValue:
|
|
2326
|
-
willContinue:
|
|
2344
|
+
var partialArgSchema = z5.object({
|
|
2345
|
+
jsonPath: z5.string(),
|
|
2346
|
+
stringValue: z5.string().nullish(),
|
|
2347
|
+
numberValue: z5.number().nullish(),
|
|
2348
|
+
boolValue: z5.boolean().nullish(),
|
|
2349
|
+
nullValue: z5.unknown().nullish(),
|
|
2350
|
+
willContinue: z5.boolean().nullish()
|
|
2327
2351
|
});
|
|
2328
|
-
var getContentSchema = () =>
|
|
2329
|
-
parts:
|
|
2330
|
-
|
|
2352
|
+
var getContentSchema = () => z5.object({
|
|
2353
|
+
parts: z5.array(
|
|
2354
|
+
z5.union([
|
|
2331
2355
|
// note: order matters since text can be fully empty
|
|
2332
|
-
|
|
2333
|
-
functionCall:
|
|
2334
|
-
name:
|
|
2335
|
-
args:
|
|
2336
|
-
partialArgs:
|
|
2337
|
-
willContinue:
|
|
2356
|
+
z5.object({
|
|
2357
|
+
functionCall: z5.object({
|
|
2358
|
+
name: z5.string().nullish(),
|
|
2359
|
+
args: z5.unknown().nullish(),
|
|
2360
|
+
partialArgs: z5.array(partialArgSchema).nullish(),
|
|
2361
|
+
willContinue: z5.boolean().nullish()
|
|
2338
2362
|
}),
|
|
2339
|
-
thoughtSignature:
|
|
2363
|
+
thoughtSignature: z5.string().nullish()
|
|
2340
2364
|
}),
|
|
2341
|
-
|
|
2342
|
-
inlineData:
|
|
2343
|
-
mimeType:
|
|
2344
|
-
data:
|
|
2365
|
+
z5.object({
|
|
2366
|
+
inlineData: z5.object({
|
|
2367
|
+
mimeType: z5.string(),
|
|
2368
|
+
data: z5.string()
|
|
2345
2369
|
}),
|
|
2346
|
-
thought:
|
|
2347
|
-
thoughtSignature:
|
|
2370
|
+
thought: z5.boolean().nullish(),
|
|
2371
|
+
thoughtSignature: z5.string().nullish()
|
|
2348
2372
|
}),
|
|
2349
|
-
|
|
2350
|
-
toolCall:
|
|
2351
|
-
toolType:
|
|
2352
|
-
args:
|
|
2353
|
-
id:
|
|
2373
|
+
z5.object({
|
|
2374
|
+
toolCall: z5.object({
|
|
2375
|
+
toolType: z5.string(),
|
|
2376
|
+
args: z5.unknown().nullish(),
|
|
2377
|
+
id: z5.string()
|
|
2354
2378
|
}),
|
|
2355
|
-
thoughtSignature:
|
|
2379
|
+
thoughtSignature: z5.string().nullish()
|
|
2356
2380
|
}),
|
|
2357
|
-
|
|
2358
|
-
toolResponse:
|
|
2359
|
-
toolType:
|
|
2360
|
-
response:
|
|
2361
|
-
id:
|
|
2381
|
+
z5.object({
|
|
2382
|
+
toolResponse: z5.object({
|
|
2383
|
+
toolType: z5.string(),
|
|
2384
|
+
response: z5.unknown().nullish(),
|
|
2385
|
+
id: z5.string()
|
|
2362
2386
|
}),
|
|
2363
|
-
thoughtSignature:
|
|
2387
|
+
thoughtSignature: z5.string().nullish()
|
|
2364
2388
|
}),
|
|
2365
|
-
|
|
2366
|
-
executableCode:
|
|
2367
|
-
language:
|
|
2368
|
-
code:
|
|
2389
|
+
z5.object({
|
|
2390
|
+
executableCode: z5.object({
|
|
2391
|
+
language: z5.string(),
|
|
2392
|
+
code: z5.string()
|
|
2369
2393
|
}).nullish(),
|
|
2370
|
-
codeExecutionResult:
|
|
2371
|
-
outcome:
|
|
2372
|
-
output:
|
|
2394
|
+
codeExecutionResult: z5.object({
|
|
2395
|
+
outcome: z5.string(),
|
|
2396
|
+
output: z5.string().nullish()
|
|
2373
2397
|
}).nullish(),
|
|
2374
|
-
text:
|
|
2375
|
-
thought:
|
|
2376
|
-
thoughtSignature:
|
|
2398
|
+
text: z5.string().nullish(),
|
|
2399
|
+
thought: z5.boolean().nullish(),
|
|
2400
|
+
thoughtSignature: z5.string().nullish()
|
|
2377
2401
|
})
|
|
2378
2402
|
])
|
|
2379
2403
|
).nullish()
|
|
2380
2404
|
});
|
|
2381
|
-
var getSafetyRatingSchema = () =>
|
|
2382
|
-
category:
|
|
2383
|
-
probability:
|
|
2384
|
-
probabilityScore:
|
|
2385
|
-
severity:
|
|
2386
|
-
severityScore:
|
|
2387
|
-
blocked:
|
|
2405
|
+
var getSafetyRatingSchema = () => z5.object({
|
|
2406
|
+
category: z5.string().nullish(),
|
|
2407
|
+
probability: z5.string().nullish(),
|
|
2408
|
+
probabilityScore: z5.number().nullish(),
|
|
2409
|
+
severity: z5.string().nullish(),
|
|
2410
|
+
severityScore: z5.number().nullish(),
|
|
2411
|
+
blocked: z5.boolean().nullish()
|
|
2388
2412
|
});
|
|
2389
|
-
var tokenDetailsSchema =
|
|
2390
|
-
|
|
2391
|
-
modality:
|
|
2392
|
-
tokenCount:
|
|
2413
|
+
var tokenDetailsSchema = z5.array(
|
|
2414
|
+
z5.object({
|
|
2415
|
+
modality: z5.string(),
|
|
2416
|
+
tokenCount: z5.number()
|
|
2393
2417
|
})
|
|
2394
2418
|
).nullish();
|
|
2395
|
-
var usageSchema =
|
|
2396
|
-
cachedContentTokenCount:
|
|
2397
|
-
thoughtsTokenCount:
|
|
2398
|
-
promptTokenCount:
|
|
2399
|
-
candidatesTokenCount:
|
|
2400
|
-
totalTokenCount:
|
|
2419
|
+
var usageSchema = z5.object({
|
|
2420
|
+
cachedContentTokenCount: z5.number().nullish(),
|
|
2421
|
+
thoughtsTokenCount: z5.number().nullish(),
|
|
2422
|
+
promptTokenCount: z5.number().nullish(),
|
|
2423
|
+
candidatesTokenCount: z5.number().nullish(),
|
|
2424
|
+
totalTokenCount: z5.number().nullish(),
|
|
2401
2425
|
// https://cloud.google.com/vertex-ai/generative-ai/docs/reference/rest/v1/GenerateContentResponse#TrafficType
|
|
2402
|
-
trafficType:
|
|
2426
|
+
trafficType: z5.string().nullish(),
|
|
2403
2427
|
// https://ai.google.dev/api/generate-content#Modality
|
|
2404
2428
|
promptTokensDetails: tokenDetailsSchema,
|
|
2405
2429
|
candidatesTokensDetails: tokenDetailsSchema
|
|
2406
2430
|
});
|
|
2407
|
-
var getUrlContextMetadataSchema = () =>
|
|
2408
|
-
urlMetadata:
|
|
2409
|
-
|
|
2410
|
-
retrievedUrl:
|
|
2411
|
-
urlRetrievalStatus:
|
|
2431
|
+
var getUrlContextMetadataSchema = () => z5.object({
|
|
2432
|
+
urlMetadata: z5.array(
|
|
2433
|
+
z5.object({
|
|
2434
|
+
retrievedUrl: z5.string(),
|
|
2435
|
+
urlRetrievalStatus: z5.string()
|
|
2412
2436
|
})
|
|
2413
2437
|
).nullish()
|
|
2414
2438
|
});
|
|
2415
|
-
var responseSchema = (
|
|
2416
|
-
() => (
|
|
2417
|
-
|
|
2418
|
-
candidates:
|
|
2419
|
-
|
|
2420
|
-
content: getContentSchema().nullish().or(
|
|
2421
|
-
finishReason:
|
|
2422
|
-
finishMessage:
|
|
2423
|
-
safetyRatings:
|
|
2439
|
+
var responseSchema = lazySchema5(
|
|
2440
|
+
() => zodSchema5(
|
|
2441
|
+
z5.object({
|
|
2442
|
+
candidates: z5.array(
|
|
2443
|
+
z5.object({
|
|
2444
|
+
content: getContentSchema().nullish().or(z5.object({}).strict()),
|
|
2445
|
+
finishReason: z5.string().nullish(),
|
|
2446
|
+
finishMessage: z5.string().nullish(),
|
|
2447
|
+
safetyRatings: z5.array(getSafetyRatingSchema()).nullish(),
|
|
2424
2448
|
groundingMetadata: getGroundingMetadataSchema().nullish(),
|
|
2425
2449
|
urlContextMetadata: getUrlContextMetadataSchema().nullish()
|
|
2426
2450
|
})
|
|
2427
2451
|
),
|
|
2428
2452
|
usageMetadata: usageSchema.nullish(),
|
|
2429
|
-
promptFeedback:
|
|
2430
|
-
blockReason:
|
|
2431
|
-
safetyRatings:
|
|
2453
|
+
promptFeedback: z5.object({
|
|
2454
|
+
blockReason: z5.string().nullish(),
|
|
2455
|
+
safetyRatings: z5.array(getSafetyRatingSchema()).nullish()
|
|
2432
2456
|
}).nullish(),
|
|
2433
|
-
serviceTier:
|
|
2457
|
+
serviceTier: z5.string().nullish()
|
|
2434
2458
|
})
|
|
2435
2459
|
)
|
|
2436
2460
|
);
|
|
2437
|
-
var chunkSchema = (
|
|
2438
|
-
() => (
|
|
2439
|
-
|
|
2440
|
-
candidates:
|
|
2441
|
-
|
|
2461
|
+
var chunkSchema = lazySchema5(
|
|
2462
|
+
() => zodSchema5(
|
|
2463
|
+
z5.object({
|
|
2464
|
+
candidates: z5.array(
|
|
2465
|
+
z5.object({
|
|
2442
2466
|
content: getContentSchema().nullish(),
|
|
2443
|
-
finishReason:
|
|
2444
|
-
finishMessage:
|
|
2445
|
-
safetyRatings:
|
|
2467
|
+
finishReason: z5.string().nullish(),
|
|
2468
|
+
finishMessage: z5.string().nullish(),
|
|
2469
|
+
safetyRatings: z5.array(getSafetyRatingSchema()).nullish(),
|
|
2446
2470
|
groundingMetadata: getGroundingMetadataSchema().nullish(),
|
|
2447
2471
|
urlContextMetadata: getUrlContextMetadataSchema().nullish()
|
|
2448
2472
|
})
|
|
2449
2473
|
).nullish(),
|
|
2450
2474
|
usageMetadata: usageSchema.nullish(),
|
|
2451
|
-
promptFeedback:
|
|
2452
|
-
blockReason:
|
|
2453
|
-
safetyRatings:
|
|
2475
|
+
promptFeedback: z5.object({
|
|
2476
|
+
blockReason: z5.string().nullish(),
|
|
2477
|
+
safetyRatings: z5.array(getSafetyRatingSchema()).nullish()
|
|
2454
2478
|
}).nullish(),
|
|
2455
|
-
serviceTier:
|
|
2479
|
+
serviceTier: z5.string().nullish()
|
|
2456
2480
|
})
|
|
2457
2481
|
)
|
|
2458
2482
|
);
|
|
2459
2483
|
|
|
2460
2484
|
// src/tool/code-execution.ts
|
|
2461
|
-
|
|
2462
|
-
|
|
2463
|
-
var codeExecution =
|
|
2485
|
+
import { createProviderToolFactoryWithOutputSchema } from "@ai-sdk/provider-utils";
|
|
2486
|
+
import { z as z6 } from "zod/v4";
|
|
2487
|
+
var codeExecution = createProviderToolFactoryWithOutputSchema({
|
|
2464
2488
|
id: "google.code_execution",
|
|
2465
|
-
inputSchema:
|
|
2466
|
-
language:
|
|
2467
|
-
code:
|
|
2489
|
+
inputSchema: z6.object({
|
|
2490
|
+
language: z6.string().describe("The programming language of the code."),
|
|
2491
|
+
code: z6.string().describe("The code to be executed.")
|
|
2468
2492
|
}),
|
|
2469
|
-
outputSchema:
|
|
2470
|
-
outcome:
|
|
2471
|
-
output:
|
|
2493
|
+
outputSchema: z6.object({
|
|
2494
|
+
outcome: z6.string().describe('The outcome of the execution (e.g., "OUTCOME_OK").'),
|
|
2495
|
+
output: z6.string().describe("The output from the code execution.")
|
|
2472
2496
|
})
|
|
2473
2497
|
});
|
|
2474
2498
|
|
|
2475
2499
|
// src/tool/enterprise-web-search.ts
|
|
2476
|
-
|
|
2477
|
-
|
|
2478
|
-
|
|
2500
|
+
import {
|
|
2501
|
+
createProviderToolFactory,
|
|
2502
|
+
lazySchema as lazySchema6,
|
|
2503
|
+
zodSchema as zodSchema6
|
|
2504
|
+
} from "@ai-sdk/provider-utils";
|
|
2505
|
+
import { z as z7 } from "zod/v4";
|
|
2506
|
+
var enterpriseWebSearch = createProviderToolFactory({
|
|
2479
2507
|
id: "google.enterprise_web_search",
|
|
2480
|
-
inputSchema: (
|
|
2508
|
+
inputSchema: lazySchema6(() => zodSchema6(z7.object({})))
|
|
2481
2509
|
});
|
|
2482
2510
|
|
|
2483
2511
|
// src/tool/file-search.ts
|
|
2484
|
-
|
|
2485
|
-
|
|
2486
|
-
|
|
2512
|
+
import {
|
|
2513
|
+
createProviderToolFactory as createProviderToolFactory2,
|
|
2514
|
+
lazySchema as lazySchema7,
|
|
2515
|
+
zodSchema as zodSchema7
|
|
2516
|
+
} from "@ai-sdk/provider-utils";
|
|
2517
|
+
import { z as z8 } from "zod/v4";
|
|
2518
|
+
var fileSearchArgsBaseSchema = z8.object({
|
|
2487
2519
|
/** The names of the file_search_stores to retrieve from.
|
|
2488
2520
|
* Example: `fileSearchStores/my-file-search-store-123`
|
|
2489
2521
|
*/
|
|
2490
|
-
fileSearchStoreNames:
|
|
2522
|
+
fileSearchStoreNames: z8.array(z8.string()).describe(
|
|
2491
2523
|
"The names of the file_search_stores to retrieve from. Example: `fileSearchStores/my-file-search-store-123`"
|
|
2492
2524
|
),
|
|
2493
2525
|
/** The number of file search retrieval chunks to retrieve. */
|
|
2494
|
-
topK:
|
|
2526
|
+
topK: z8.number().int().positive().describe("The number of file search retrieval chunks to retrieve.").optional(),
|
|
2495
2527
|
/** Metadata filter to apply to the file search retrieval documents.
|
|
2496
2528
|
* See https://google.aip.dev/160 for the syntax of the filter expression.
|
|
2497
2529
|
*/
|
|
2498
|
-
metadataFilter:
|
|
2530
|
+
metadataFilter: z8.string().describe(
|
|
2499
2531
|
"Metadata filter to apply to the file search retrieval documents. See https://google.aip.dev/160 for the syntax of the filter expression."
|
|
2500
2532
|
).optional()
|
|
2501
2533
|
}).passthrough();
|
|
2502
|
-
var fileSearchArgsSchema = (
|
|
2503
|
-
() => (
|
|
2534
|
+
var fileSearchArgsSchema = lazySchema7(
|
|
2535
|
+
() => zodSchema7(fileSearchArgsBaseSchema)
|
|
2504
2536
|
);
|
|
2505
|
-
var fileSearch = (
|
|
2537
|
+
var fileSearch = createProviderToolFactory2({
|
|
2506
2538
|
id: "google.file_search",
|
|
2507
2539
|
inputSchema: fileSearchArgsSchema
|
|
2508
2540
|
});
|
|
2509
2541
|
|
|
2510
2542
|
// src/tool/google-maps.ts
|
|
2511
|
-
|
|
2512
|
-
|
|
2513
|
-
|
|
2543
|
+
import {
|
|
2544
|
+
createProviderToolFactory as createProviderToolFactory3,
|
|
2545
|
+
lazySchema as lazySchema8,
|
|
2546
|
+
zodSchema as zodSchema8
|
|
2547
|
+
} from "@ai-sdk/provider-utils";
|
|
2548
|
+
import { z as z9 } from "zod/v4";
|
|
2549
|
+
var googleMaps = createProviderToolFactory3({
|
|
2514
2550
|
id: "google.google_maps",
|
|
2515
|
-
inputSchema: (
|
|
2551
|
+
inputSchema: lazySchema8(() => zodSchema8(z9.object({})))
|
|
2516
2552
|
});
|
|
2517
2553
|
|
|
2518
2554
|
// src/tool/google-search.ts
|
|
2519
|
-
|
|
2520
|
-
|
|
2521
|
-
|
|
2522
|
-
|
|
2523
|
-
|
|
2524
|
-
|
|
2555
|
+
import {
|
|
2556
|
+
createProviderToolFactory as createProviderToolFactory4,
|
|
2557
|
+
lazySchema as lazySchema9,
|
|
2558
|
+
zodSchema as zodSchema9
|
|
2559
|
+
} from "@ai-sdk/provider-utils";
|
|
2560
|
+
import { z as z10 } from "zod/v4";
|
|
2561
|
+
var googleSearchToolArgsBaseSchema = z10.object({
|
|
2562
|
+
searchTypes: z10.object({
|
|
2563
|
+
webSearch: z10.object({}).optional(),
|
|
2564
|
+
imageSearch: z10.object({}).optional()
|
|
2525
2565
|
}).optional(),
|
|
2526
|
-
timeRangeFilter:
|
|
2527
|
-
startTime:
|
|
2528
|
-
endTime:
|
|
2566
|
+
timeRangeFilter: z10.object({
|
|
2567
|
+
startTime: z10.string(),
|
|
2568
|
+
endTime: z10.string()
|
|
2529
2569
|
}).optional()
|
|
2530
2570
|
}).passthrough();
|
|
2531
|
-
var googleSearchToolArgsSchema = (
|
|
2532
|
-
() => (
|
|
2571
|
+
var googleSearchToolArgsSchema = lazySchema9(
|
|
2572
|
+
() => zodSchema9(googleSearchToolArgsBaseSchema)
|
|
2533
2573
|
);
|
|
2534
|
-
var googleSearch = (
|
|
2574
|
+
var googleSearch = createProviderToolFactory4(
|
|
2535
2575
|
{
|
|
2536
2576
|
id: "google.google_search",
|
|
2537
2577
|
inputSchema: googleSearchToolArgsSchema
|
|
@@ -2539,21 +2579,25 @@ var googleSearch = (0, import_provider_utils11.createProviderToolFactory)(
|
|
|
2539
2579
|
);
|
|
2540
2580
|
|
|
2541
2581
|
// src/tool/url-context.ts
|
|
2542
|
-
|
|
2543
|
-
|
|
2544
|
-
|
|
2582
|
+
import {
|
|
2583
|
+
createProviderToolFactory as createProviderToolFactory5,
|
|
2584
|
+
lazySchema as lazySchema10,
|
|
2585
|
+
zodSchema as zodSchema10
|
|
2586
|
+
} from "@ai-sdk/provider-utils";
|
|
2587
|
+
import { z as z11 } from "zod/v4";
|
|
2588
|
+
var urlContext = createProviderToolFactory5({
|
|
2545
2589
|
id: "google.url_context",
|
|
2546
|
-
inputSchema: (
|
|
2590
|
+
inputSchema: lazySchema10(() => zodSchema10(z11.object({})))
|
|
2547
2591
|
});
|
|
2548
2592
|
|
|
2549
2593
|
// src/tool/vertex-rag-store.ts
|
|
2550
|
-
|
|
2551
|
-
|
|
2552
|
-
var vertexRagStore = (
|
|
2594
|
+
import { createProviderToolFactory as createProviderToolFactory6 } from "@ai-sdk/provider-utils";
|
|
2595
|
+
import { z as z12 } from "zod/v4";
|
|
2596
|
+
var vertexRagStore = createProviderToolFactory6({
|
|
2553
2597
|
id: "google.vertex_rag_store",
|
|
2554
|
-
inputSchema:
|
|
2555
|
-
ragCorpus:
|
|
2556
|
-
topK:
|
|
2598
|
+
inputSchema: z12.object({
|
|
2599
|
+
ragCorpus: z12.string(),
|
|
2600
|
+
topK: z12.number().optional()
|
|
2557
2601
|
})
|
|
2558
2602
|
});
|
|
2559
2603
|
|
|
@@ -2618,8 +2662,18 @@ var googleTools = {
|
|
|
2618
2662
|
};
|
|
2619
2663
|
|
|
2620
2664
|
// src/google-generative-ai-image-model.ts
|
|
2621
|
-
|
|
2622
|
-
|
|
2665
|
+
import {
|
|
2666
|
+
combineHeaders as combineHeaders3,
|
|
2667
|
+
convertToBase64 as convertToBase642,
|
|
2668
|
+
createJsonResponseHandler as createJsonResponseHandler3,
|
|
2669
|
+
generateId as defaultGenerateId,
|
|
2670
|
+
lazySchema as lazySchema11,
|
|
2671
|
+
parseProviderOptions as parseProviderOptions3,
|
|
2672
|
+
postJsonToApi as postJsonToApi3,
|
|
2673
|
+
resolve as resolve3,
|
|
2674
|
+
zodSchema as zodSchema11
|
|
2675
|
+
} from "@ai-sdk/provider-utils";
|
|
2676
|
+
import { z as z13 } from "zod/v4";
|
|
2623
2677
|
var GoogleGenerativeAIImageModel = class {
|
|
2624
2678
|
constructor(modelId, settings, config) {
|
|
2625
2679
|
this.modelId = modelId;
|
|
@@ -2684,7 +2738,7 @@ var GoogleGenerativeAIImageModel = class {
|
|
|
2684
2738
|
details: "This model does not support the `seed` option through this provider."
|
|
2685
2739
|
});
|
|
2686
2740
|
}
|
|
2687
|
-
const googleOptions = await (
|
|
2741
|
+
const googleOptions = await parseProviderOptions3({
|
|
2688
2742
|
provider: "google",
|
|
2689
2743
|
providerOptions,
|
|
2690
2744
|
schema: googleImageModelOptionsSchema
|
|
@@ -2703,12 +2757,12 @@ var GoogleGenerativeAIImageModel = class {
|
|
|
2703
2757
|
instances: [{ prompt }],
|
|
2704
2758
|
parameters
|
|
2705
2759
|
};
|
|
2706
|
-
const { responseHeaders, value: response } = await (
|
|
2760
|
+
const { responseHeaders, value: response } = await postJsonToApi3({
|
|
2707
2761
|
url: `${this.config.baseURL}/models/${this.modelId}:predict`,
|
|
2708
|
-
headers: (
|
|
2762
|
+
headers: combineHeaders3(await resolve3(this.config.headers), headers),
|
|
2709
2763
|
body,
|
|
2710
2764
|
failedResponseHandler: googleFailedResponseHandler,
|
|
2711
|
-
successfulResponseHandler: (
|
|
2765
|
+
successfulResponseHandler: createJsonResponseHandler3(
|
|
2712
2766
|
googleImageResponseSchema
|
|
2713
2767
|
),
|
|
2714
2768
|
abortSignal,
|
|
@@ -2794,7 +2848,7 @@ var GoogleGenerativeAIImageModel = class {
|
|
|
2794
2848
|
baseURL: this.config.baseURL,
|
|
2795
2849
|
headers: (_a = this.config.headers) != null ? _a : {},
|
|
2796
2850
|
fetch: this.config.fetch,
|
|
2797
|
-
generateId: (_b = this.config.generateId) != null ? _b :
|
|
2851
|
+
generateId: (_b = this.config.generateId) != null ? _b : defaultGenerateId
|
|
2798
2852
|
});
|
|
2799
2853
|
const result = await languageModel.doGenerate({
|
|
2800
2854
|
prompt: languageModelPrompt,
|
|
@@ -2815,7 +2869,7 @@ var GoogleGenerativeAIImageModel = class {
|
|
|
2815
2869
|
const images = [];
|
|
2816
2870
|
for (const part of result.content) {
|
|
2817
2871
|
if (part.type === "file" && part.mediaType.startsWith("image/")) {
|
|
2818
|
-
images.push((
|
|
2872
|
+
images.push(convertToBase642(part.data));
|
|
2819
2873
|
}
|
|
2820
2874
|
}
|
|
2821
2875
|
return {
|
|
@@ -2842,26 +2896,36 @@ var GoogleGenerativeAIImageModel = class {
|
|
|
2842
2896
|
function isGeminiModel(modelId) {
|
|
2843
2897
|
return modelId.startsWith("gemini-");
|
|
2844
2898
|
}
|
|
2845
|
-
var googleImageResponseSchema = (
|
|
2846
|
-
() => (
|
|
2847
|
-
|
|
2848
|
-
predictions:
|
|
2899
|
+
var googleImageResponseSchema = lazySchema11(
|
|
2900
|
+
() => zodSchema11(
|
|
2901
|
+
z13.object({
|
|
2902
|
+
predictions: z13.array(z13.object({ bytesBase64Encoded: z13.string() })).default([])
|
|
2849
2903
|
})
|
|
2850
2904
|
)
|
|
2851
2905
|
);
|
|
2852
|
-
var googleImageModelOptionsSchema = (
|
|
2853
|
-
() => (
|
|
2854
|
-
|
|
2855
|
-
personGeneration:
|
|
2856
|
-
aspectRatio:
|
|
2906
|
+
var googleImageModelOptionsSchema = lazySchema11(
|
|
2907
|
+
() => zodSchema11(
|
|
2908
|
+
z13.object({
|
|
2909
|
+
personGeneration: z13.enum(["dont_allow", "allow_adult", "allow_all"]).nullish(),
|
|
2910
|
+
aspectRatio: z13.enum(["1:1", "3:4", "4:3", "9:16", "16:9"]).nullish()
|
|
2857
2911
|
})
|
|
2858
2912
|
)
|
|
2859
2913
|
);
|
|
2860
2914
|
|
|
2861
2915
|
// src/google-generative-ai-files.ts
|
|
2862
|
-
|
|
2863
|
-
|
|
2864
|
-
|
|
2916
|
+
import {
|
|
2917
|
+
AISDKError
|
|
2918
|
+
} from "@ai-sdk/provider";
|
|
2919
|
+
import {
|
|
2920
|
+
combineHeaders as combineHeaders4,
|
|
2921
|
+
createJsonResponseHandler as createJsonResponseHandler4,
|
|
2922
|
+
delay,
|
|
2923
|
+
lazySchema as lazySchema12,
|
|
2924
|
+
parseProviderOptions as parseProviderOptions4,
|
|
2925
|
+
zodSchema as zodSchema12,
|
|
2926
|
+
getFromApi
|
|
2927
|
+
} from "@ai-sdk/provider-utils";
|
|
2928
|
+
import { z as z14 } from "zod/v4";
|
|
2865
2929
|
var GoogleGenerativeAIFiles = class {
|
|
2866
2930
|
constructor(config) {
|
|
2867
2931
|
this.config = config;
|
|
@@ -2872,7 +2936,7 @@ var GoogleGenerativeAIFiles = class {
|
|
|
2872
2936
|
}
|
|
2873
2937
|
async uploadFile(options) {
|
|
2874
2938
|
var _a, _b, _c, _d;
|
|
2875
|
-
const googleOptions = await (
|
|
2939
|
+
const googleOptions = await parseProviderOptions4({
|
|
2876
2940
|
provider: "google",
|
|
2877
2941
|
providerOptions: options.providerOptions,
|
|
2878
2942
|
schema: googleFilesUploadOptionsSchema
|
|
@@ -2906,14 +2970,14 @@ var GoogleGenerativeAIFiles = class {
|
|
|
2906
2970
|
});
|
|
2907
2971
|
if (!initResponse.ok) {
|
|
2908
2972
|
const errorBody = await initResponse.text();
|
|
2909
|
-
throw new
|
|
2973
|
+
throw new AISDKError({
|
|
2910
2974
|
name: "GOOGLE_FILES_UPLOAD_ERROR",
|
|
2911
2975
|
message: `Failed to initiate resumable upload: ${initResponse.status} ${errorBody}`
|
|
2912
2976
|
});
|
|
2913
2977
|
}
|
|
2914
2978
|
const uploadUrl = initResponse.headers.get("x-goog-upload-url");
|
|
2915
2979
|
if (!uploadUrl) {
|
|
2916
|
-
throw new
|
|
2980
|
+
throw new AISDKError({
|
|
2917
2981
|
name: "GOOGLE_FILES_UPLOAD_ERROR",
|
|
2918
2982
|
message: "No upload URL returned from initiation request"
|
|
2919
2983
|
});
|
|
@@ -2929,7 +2993,7 @@ var GoogleGenerativeAIFiles = class {
|
|
|
2929
2993
|
});
|
|
2930
2994
|
if (!uploadResponse.ok) {
|
|
2931
2995
|
const errorBody = await uploadResponse.text();
|
|
2932
|
-
throw new
|
|
2996
|
+
throw new AISDKError({
|
|
2933
2997
|
name: "GOOGLE_FILES_UPLOAD_ERROR",
|
|
2934
2998
|
message: `Failed to upload file data: ${uploadResponse.status} ${errorBody}`
|
|
2935
2999
|
});
|
|
@@ -2941,16 +3005,16 @@ var GoogleGenerativeAIFiles = class {
|
|
|
2941
3005
|
const startTime = Date.now();
|
|
2942
3006
|
while (file.state === "PROCESSING") {
|
|
2943
3007
|
if (Date.now() - startTime > pollTimeoutMs) {
|
|
2944
|
-
throw new
|
|
3008
|
+
throw new AISDKError({
|
|
2945
3009
|
name: "GOOGLE_FILES_UPLOAD_TIMEOUT",
|
|
2946
3010
|
message: `File processing timed out after ${pollTimeoutMs}ms`
|
|
2947
3011
|
});
|
|
2948
3012
|
}
|
|
2949
|
-
await
|
|
2950
|
-
const { value: fileStatus } = await
|
|
3013
|
+
await delay(pollIntervalMs);
|
|
3014
|
+
const { value: fileStatus } = await getFromApi({
|
|
2951
3015
|
url: `${this.config.baseURL}/${file.name}`,
|
|
2952
|
-
headers: (
|
|
2953
|
-
successfulResponseHandler: (
|
|
3016
|
+
headers: combineHeaders4(resolvedHeaders),
|
|
3017
|
+
successfulResponseHandler: createJsonResponseHandler4(
|
|
2954
3018
|
googleFileResponseSchema
|
|
2955
3019
|
),
|
|
2956
3020
|
failedResponseHandler: googleFailedResponseHandler,
|
|
@@ -2959,7 +3023,7 @@ var GoogleGenerativeAIFiles = class {
|
|
|
2959
3023
|
file = fileStatus;
|
|
2960
3024
|
}
|
|
2961
3025
|
if (file.state === "FAILED") {
|
|
2962
|
-
throw new
|
|
3026
|
+
throw new AISDKError({
|
|
2963
3027
|
name: "GOOGLE_FILES_UPLOAD_FAILED",
|
|
2964
3028
|
message: `File processing failed for ${file.name}`
|
|
2965
3029
|
});
|
|
@@ -2985,36 +3049,49 @@ var GoogleGenerativeAIFiles = class {
|
|
|
2985
3049
|
};
|
|
2986
3050
|
}
|
|
2987
3051
|
};
|
|
2988
|
-
var googleFileResponseSchema = (
|
|
2989
|
-
() => (
|
|
2990
|
-
|
|
2991
|
-
name:
|
|
2992
|
-
displayName:
|
|
2993
|
-
mimeType:
|
|
2994
|
-
sizeBytes:
|
|
2995
|
-
createTime:
|
|
2996
|
-
updateTime:
|
|
2997
|
-
expirationTime:
|
|
2998
|
-
sha256Hash:
|
|
2999
|
-
uri:
|
|
3000
|
-
state:
|
|
3052
|
+
var googleFileResponseSchema = lazySchema12(
|
|
3053
|
+
() => zodSchema12(
|
|
3054
|
+
z14.object({
|
|
3055
|
+
name: z14.string(),
|
|
3056
|
+
displayName: z14.string().nullish(),
|
|
3057
|
+
mimeType: z14.string(),
|
|
3058
|
+
sizeBytes: z14.string().nullish(),
|
|
3059
|
+
createTime: z14.string().nullish(),
|
|
3060
|
+
updateTime: z14.string().nullish(),
|
|
3061
|
+
expirationTime: z14.string().nullish(),
|
|
3062
|
+
sha256Hash: z14.string().nullish(),
|
|
3063
|
+
uri: z14.string(),
|
|
3064
|
+
state: z14.string()
|
|
3001
3065
|
})
|
|
3002
3066
|
)
|
|
3003
3067
|
);
|
|
3004
|
-
var googleFilesUploadOptionsSchema = (
|
|
3005
|
-
() => (
|
|
3006
|
-
|
|
3007
|
-
displayName:
|
|
3008
|
-
pollIntervalMs:
|
|
3009
|
-
pollTimeoutMs:
|
|
3068
|
+
var googleFilesUploadOptionsSchema = lazySchema12(
|
|
3069
|
+
() => zodSchema12(
|
|
3070
|
+
z14.object({
|
|
3071
|
+
displayName: z14.string().nullish(),
|
|
3072
|
+
pollIntervalMs: z14.number().positive().nullish(),
|
|
3073
|
+
pollTimeoutMs: z14.number().positive().nullish()
|
|
3010
3074
|
}).passthrough()
|
|
3011
3075
|
)
|
|
3012
3076
|
);
|
|
3013
3077
|
|
|
3014
3078
|
// src/google-generative-ai-video-model.ts
|
|
3015
|
-
|
|
3016
|
-
|
|
3017
|
-
|
|
3079
|
+
import {
|
|
3080
|
+
AISDKError as AISDKError2
|
|
3081
|
+
} from "@ai-sdk/provider";
|
|
3082
|
+
import {
|
|
3083
|
+
combineHeaders as combineHeaders5,
|
|
3084
|
+
convertUint8ArrayToBase64,
|
|
3085
|
+
createJsonResponseHandler as createJsonResponseHandler5,
|
|
3086
|
+
delay as delay2,
|
|
3087
|
+
getFromApi as getFromApi2,
|
|
3088
|
+
lazySchema as lazySchema13,
|
|
3089
|
+
parseProviderOptions as parseProviderOptions5,
|
|
3090
|
+
postJsonToApi as postJsonToApi4,
|
|
3091
|
+
resolve as resolve4,
|
|
3092
|
+
zodSchema as zodSchema13
|
|
3093
|
+
} from "@ai-sdk/provider-utils";
|
|
3094
|
+
import { z as z15 } from "zod/v4";
|
|
3018
3095
|
var GoogleGenerativeAIVideoModel = class {
|
|
3019
3096
|
constructor(modelId, config) {
|
|
3020
3097
|
this.modelId = modelId;
|
|
@@ -3031,7 +3108,7 @@ var GoogleGenerativeAIVideoModel = class {
|
|
|
3031
3108
|
var _a, _b, _c, _d, _e, _f, _g, _h;
|
|
3032
3109
|
const currentDate = (_c = (_b = (_a = this.config._internal) == null ? void 0 : _a.currentDate) == null ? void 0 : _b.call(_a)) != null ? _c : /* @__PURE__ */ new Date();
|
|
3033
3110
|
const warnings = [];
|
|
3034
|
-
const googleOptions = await (
|
|
3111
|
+
const googleOptions = await parseProviderOptions5({
|
|
3035
3112
|
provider: "google",
|
|
3036
3113
|
providerOptions: options.providerOptions,
|
|
3037
3114
|
schema: googleVideoModelOptionsSchema
|
|
@@ -3049,7 +3126,7 @@ var GoogleGenerativeAIVideoModel = class {
|
|
|
3049
3126
|
details: "Google Generative AI video models require base64-encoded images. URL will be ignored."
|
|
3050
3127
|
});
|
|
3051
3128
|
} else {
|
|
3052
|
-
const base64Data = typeof options.image.data === "string" ? options.image.data :
|
|
3129
|
+
const base64Data = typeof options.image.data === "string" ? options.image.data : convertUint8ArrayToBase64(options.image.data);
|
|
3053
3130
|
instance.image = {
|
|
3054
3131
|
inlineData: {
|
|
3055
3132
|
mimeType: options.image.mediaType || "image/png",
|
|
@@ -3115,17 +3192,17 @@ var GoogleGenerativeAIVideoModel = class {
|
|
|
3115
3192
|
}
|
|
3116
3193
|
}
|
|
3117
3194
|
}
|
|
3118
|
-
const { value: operation } = await (
|
|
3195
|
+
const { value: operation } = await postJsonToApi4({
|
|
3119
3196
|
url: `${this.config.baseURL}/models/${this.modelId}:predictLongRunning`,
|
|
3120
|
-
headers: (
|
|
3121
|
-
await (
|
|
3197
|
+
headers: combineHeaders5(
|
|
3198
|
+
await resolve4(this.config.headers),
|
|
3122
3199
|
options.headers
|
|
3123
3200
|
),
|
|
3124
3201
|
body: {
|
|
3125
3202
|
instances,
|
|
3126
3203
|
parameters
|
|
3127
3204
|
},
|
|
3128
|
-
successfulResponseHandler: (
|
|
3205
|
+
successfulResponseHandler: createJsonResponseHandler5(
|
|
3129
3206
|
googleOperationSchema
|
|
3130
3207
|
),
|
|
3131
3208
|
failedResponseHandler: googleFailedResponseHandler,
|
|
@@ -3134,7 +3211,7 @@ var GoogleGenerativeAIVideoModel = class {
|
|
|
3134
3211
|
});
|
|
3135
3212
|
const operationName = operation.name;
|
|
3136
3213
|
if (!operationName) {
|
|
3137
|
-
throw new
|
|
3214
|
+
throw new AISDKError2({
|
|
3138
3215
|
name: "GOOGLE_VIDEO_GENERATION_ERROR",
|
|
3139
3216
|
message: "No operation name returned from API"
|
|
3140
3217
|
});
|
|
@@ -3146,25 +3223,25 @@ var GoogleGenerativeAIVideoModel = class {
|
|
|
3146
3223
|
let responseHeaders;
|
|
3147
3224
|
while (!finalOperation.done) {
|
|
3148
3225
|
if (Date.now() - startTime > pollTimeoutMs) {
|
|
3149
|
-
throw new
|
|
3226
|
+
throw new AISDKError2({
|
|
3150
3227
|
name: "GOOGLE_VIDEO_GENERATION_TIMEOUT",
|
|
3151
3228
|
message: `Video generation timed out after ${pollTimeoutMs}ms`
|
|
3152
3229
|
});
|
|
3153
3230
|
}
|
|
3154
|
-
await (
|
|
3231
|
+
await delay2(pollIntervalMs);
|
|
3155
3232
|
if ((_f = options.abortSignal) == null ? void 0 : _f.aborted) {
|
|
3156
|
-
throw new
|
|
3233
|
+
throw new AISDKError2({
|
|
3157
3234
|
name: "GOOGLE_VIDEO_GENERATION_ABORTED",
|
|
3158
3235
|
message: "Video generation request was aborted"
|
|
3159
3236
|
});
|
|
3160
3237
|
}
|
|
3161
|
-
const { value: statusOperation, responseHeaders: pollHeaders } = await (
|
|
3238
|
+
const { value: statusOperation, responseHeaders: pollHeaders } = await getFromApi2({
|
|
3162
3239
|
url: `${this.config.baseURL}/${operationName}`,
|
|
3163
|
-
headers: (
|
|
3164
|
-
await (
|
|
3240
|
+
headers: combineHeaders5(
|
|
3241
|
+
await resolve4(this.config.headers),
|
|
3165
3242
|
options.headers
|
|
3166
3243
|
),
|
|
3167
|
-
successfulResponseHandler: (
|
|
3244
|
+
successfulResponseHandler: createJsonResponseHandler5(
|
|
3168
3245
|
googleOperationSchema
|
|
3169
3246
|
),
|
|
3170
3247
|
failedResponseHandler: googleFailedResponseHandler,
|
|
@@ -3175,21 +3252,21 @@ var GoogleGenerativeAIVideoModel = class {
|
|
|
3175
3252
|
responseHeaders = pollHeaders;
|
|
3176
3253
|
}
|
|
3177
3254
|
if (finalOperation.error) {
|
|
3178
|
-
throw new
|
|
3255
|
+
throw new AISDKError2({
|
|
3179
3256
|
name: "GOOGLE_VIDEO_GENERATION_FAILED",
|
|
3180
3257
|
message: `Video generation failed: ${finalOperation.error.message}`
|
|
3181
3258
|
});
|
|
3182
3259
|
}
|
|
3183
3260
|
const response = finalOperation.response;
|
|
3184
3261
|
if (!((_g = response == null ? void 0 : response.generateVideoResponse) == null ? void 0 : _g.generatedSamples) || response.generateVideoResponse.generatedSamples.length === 0) {
|
|
3185
|
-
throw new
|
|
3262
|
+
throw new AISDKError2({
|
|
3186
3263
|
name: "GOOGLE_VIDEO_GENERATION_ERROR",
|
|
3187
3264
|
message: `No videos in response. Response: ${JSON.stringify(finalOperation)}`
|
|
3188
3265
|
});
|
|
3189
3266
|
}
|
|
3190
3267
|
const videos = [];
|
|
3191
3268
|
const videoMetadata = [];
|
|
3192
|
-
const resolvedHeaders = await (
|
|
3269
|
+
const resolvedHeaders = await resolve4(this.config.headers);
|
|
3193
3270
|
const apiKey = resolvedHeaders == null ? void 0 : resolvedHeaders["x-goog-api-key"];
|
|
3194
3271
|
for (const generatedSample of response.generateVideoResponse.generatedSamples) {
|
|
3195
3272
|
if ((_h = generatedSample.video) == null ? void 0 : _h.uri) {
|
|
@@ -3205,7 +3282,7 @@ var GoogleGenerativeAIVideoModel = class {
|
|
|
3205
3282
|
}
|
|
3206
3283
|
}
|
|
3207
3284
|
if (videos.length === 0) {
|
|
3208
|
-
throw new
|
|
3285
|
+
throw new AISDKError2({
|
|
3209
3286
|
name: "GOOGLE_VIDEO_GENERATION_ERROR",
|
|
3210
3287
|
message: "No valid videos in response"
|
|
3211
3288
|
});
|
|
@@ -3226,37 +3303,37 @@ var GoogleGenerativeAIVideoModel = class {
|
|
|
3226
3303
|
};
|
|
3227
3304
|
}
|
|
3228
3305
|
};
|
|
3229
|
-
var googleOperationSchema =
|
|
3230
|
-
name:
|
|
3231
|
-
done:
|
|
3232
|
-
error:
|
|
3233
|
-
code:
|
|
3234
|
-
message:
|
|
3235
|
-
status:
|
|
3306
|
+
var googleOperationSchema = z15.object({
|
|
3307
|
+
name: z15.string().nullish(),
|
|
3308
|
+
done: z15.boolean().nullish(),
|
|
3309
|
+
error: z15.object({
|
|
3310
|
+
code: z15.number().nullish(),
|
|
3311
|
+
message: z15.string(),
|
|
3312
|
+
status: z15.string().nullish()
|
|
3236
3313
|
}).nullish(),
|
|
3237
|
-
response:
|
|
3238
|
-
generateVideoResponse:
|
|
3239
|
-
generatedSamples:
|
|
3240
|
-
|
|
3241
|
-
video:
|
|
3242
|
-
uri:
|
|
3314
|
+
response: z15.object({
|
|
3315
|
+
generateVideoResponse: z15.object({
|
|
3316
|
+
generatedSamples: z15.array(
|
|
3317
|
+
z15.object({
|
|
3318
|
+
video: z15.object({
|
|
3319
|
+
uri: z15.string().nullish()
|
|
3243
3320
|
}).nullish()
|
|
3244
3321
|
})
|
|
3245
3322
|
).nullish()
|
|
3246
3323
|
}).nullish()
|
|
3247
3324
|
}).nullish()
|
|
3248
3325
|
});
|
|
3249
|
-
var googleVideoModelOptionsSchema = (
|
|
3250
|
-
() => (
|
|
3251
|
-
|
|
3252
|
-
pollIntervalMs:
|
|
3253
|
-
pollTimeoutMs:
|
|
3254
|
-
personGeneration:
|
|
3255
|
-
negativePrompt:
|
|
3256
|
-
referenceImages:
|
|
3257
|
-
|
|
3258
|
-
bytesBase64Encoded:
|
|
3259
|
-
gcsUri:
|
|
3326
|
+
var googleVideoModelOptionsSchema = lazySchema13(
|
|
3327
|
+
() => zodSchema13(
|
|
3328
|
+
z15.object({
|
|
3329
|
+
pollIntervalMs: z15.number().positive().nullish(),
|
|
3330
|
+
pollTimeoutMs: z15.number().positive().nullish(),
|
|
3331
|
+
personGeneration: z15.enum(["dont_allow", "allow_adult", "allow_all"]).nullish(),
|
|
3332
|
+
negativePrompt: z15.string().nullish(),
|
|
3333
|
+
referenceImages: z15.array(
|
|
3334
|
+
z15.object({
|
|
3335
|
+
bytesBase64Encoded: z15.string().nullish(),
|
|
3336
|
+
gcsUri: z15.string().nullish()
|
|
3260
3337
|
})
|
|
3261
3338
|
).nullish()
|
|
3262
3339
|
}).passthrough()
|
|
@@ -3266,11 +3343,11 @@ var googleVideoModelOptionsSchema = (0, import_provider_utils16.lazySchema)(
|
|
|
3266
3343
|
// src/google-provider.ts
|
|
3267
3344
|
function createGoogleGenerativeAI(options = {}) {
|
|
3268
3345
|
var _a, _b;
|
|
3269
|
-
const baseURL = (_a =
|
|
3346
|
+
const baseURL = (_a = withoutTrailingSlash(options.baseURL)) != null ? _a : "https://generativelanguage.googleapis.com/v1beta";
|
|
3270
3347
|
const providerName = (_b = options.name) != null ? _b : "google.generative-ai";
|
|
3271
|
-
const getHeaders = () =>
|
|
3348
|
+
const getHeaders = () => withUserAgentSuffix(
|
|
3272
3349
|
{
|
|
3273
|
-
"x-goog-api-key":
|
|
3350
|
+
"x-goog-api-key": loadApiKey({
|
|
3274
3351
|
apiKey: options.apiKey,
|
|
3275
3352
|
environmentVariableName: "GOOGLE_GENERATIVE_AI_API_KEY",
|
|
3276
3353
|
description: "Google Generative AI"
|
|
@@ -3285,7 +3362,7 @@ function createGoogleGenerativeAI(options = {}) {
|
|
|
3285
3362
|
provider: providerName,
|
|
3286
3363
|
baseURL,
|
|
3287
3364
|
headers: getHeaders,
|
|
3288
|
-
generateId: (_a2 = options.generateId) != null ? _a2 :
|
|
3365
|
+
generateId: (_a2 = options.generateId) != null ? _a2 : generateId2,
|
|
3289
3366
|
supportedUrls: () => ({
|
|
3290
3367
|
"*": [
|
|
3291
3368
|
// Google Generative Language "files" endpoint
|
|
@@ -3326,7 +3403,7 @@ function createGoogleGenerativeAI(options = {}) {
|
|
|
3326
3403
|
baseURL,
|
|
3327
3404
|
headers: getHeaders,
|
|
3328
3405
|
fetch: options.fetch,
|
|
3329
|
-
generateId: (_a2 = options.generateId) != null ? _a2 :
|
|
3406
|
+
generateId: (_a2 = options.generateId) != null ? _a2 : generateId2
|
|
3330
3407
|
});
|
|
3331
3408
|
};
|
|
3332
3409
|
const provider = function(modelId) {
|
|
@@ -3354,10 +3431,9 @@ function createGoogleGenerativeAI(options = {}) {
|
|
|
3354
3431
|
return provider;
|
|
3355
3432
|
}
|
|
3356
3433
|
var google = createGoogleGenerativeAI();
|
|
3357
|
-
|
|
3358
|
-
0 && (module.exports = {
|
|
3434
|
+
export {
|
|
3359
3435
|
VERSION,
|
|
3360
3436
|
createGoogleGenerativeAI,
|
|
3361
3437
|
google
|
|
3362
|
-
}
|
|
3438
|
+
};
|
|
3363
3439
|
//# sourceMappingURL=index.js.map
|