@ai-sdk/google 2.0.18 → 2.0.19
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 +8 -0
- package/dist/index.d.mts +139 -132
- package/dist/index.d.ts +139 -132
- package/dist/index.js +312 -257
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +319 -240
- package/dist/index.mjs.map +1 -1
- package/dist/internal/index.d.mts +138 -10
- package/dist/internal/index.d.ts +138 -10
- package/dist/internal/index.js +246 -210
- package/dist/internal/index.js.map +1 -1
- package/dist/internal/index.mjs +249 -197
- package/dist/internal/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
@@ -37,62 +37,71 @@ __export(src_exports, {
|
|
37
37
|
module.exports = __toCommonJS(src_exports);
|
38
38
|
|
39
39
|
// src/google-provider.ts
|
40
|
-
var
|
40
|
+
var import_provider_utils11 = require("@ai-sdk/provider-utils");
|
41
41
|
|
42
42
|
// src/version.ts
|
43
|
-
var VERSION = true ? "2.0.
|
43
|
+
var VERSION = true ? "2.0.19" : "0.0.0-test";
|
44
44
|
|
45
45
|
// src/google-generative-ai-embedding-model.ts
|
46
46
|
var import_provider = require("@ai-sdk/provider");
|
47
|
-
var
|
47
|
+
var import_provider_utils3 = require("@ai-sdk/provider-utils");
|
48
48
|
var z3 = __toESM(require("zod/v4"));
|
49
49
|
|
50
50
|
// src/google-error.ts
|
51
51
|
var import_provider_utils = require("@ai-sdk/provider-utils");
|
52
52
|
var z = __toESM(require("zod/v4"));
|
53
|
-
var googleErrorDataSchema =
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
53
|
+
var googleErrorDataSchema = (0, import_provider_utils.lazySchema)(
|
54
|
+
() => (0, import_provider_utils.zodSchema)(
|
55
|
+
z.object({
|
56
|
+
error: z.object({
|
57
|
+
code: z.number().nullable(),
|
58
|
+
message: z.string(),
|
59
|
+
status: z.string()
|
60
|
+
})
|
61
|
+
})
|
62
|
+
)
|
63
|
+
);
|
60
64
|
var googleFailedResponseHandler = (0, import_provider_utils.createJsonErrorResponseHandler)({
|
61
65
|
errorSchema: googleErrorDataSchema,
|
62
66
|
errorToMessage: (data) => data.error.message
|
63
67
|
});
|
64
68
|
|
65
69
|
// src/google-generative-ai-embedding-options.ts
|
70
|
+
var import_provider_utils2 = require("@ai-sdk/provider-utils");
|
66
71
|
var z2 = __toESM(require("zod/v4"));
|
67
|
-
var googleGenerativeAIEmbeddingProviderOptions =
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
72
|
+
var googleGenerativeAIEmbeddingProviderOptions = (0, import_provider_utils2.lazySchema)(
|
73
|
+
() => (0, import_provider_utils2.zodSchema)(
|
74
|
+
z2.object({
|
75
|
+
/**
|
76
|
+
* Optional. Optional reduced dimension for the output embedding.
|
77
|
+
* If set, excessive values in the output embedding are truncated from the end.
|
78
|
+
*/
|
79
|
+
outputDimensionality: z2.number().optional(),
|
80
|
+
/**
|
81
|
+
* Optional. Specifies the task type for generating embeddings.
|
82
|
+
* Supported task types:
|
83
|
+
* - SEMANTIC_SIMILARITY: Optimized for text similarity.
|
84
|
+
* - CLASSIFICATION: Optimized for text classification.
|
85
|
+
* - CLUSTERING: Optimized for clustering texts based on similarity.
|
86
|
+
* - RETRIEVAL_DOCUMENT: Optimized for document retrieval.
|
87
|
+
* - RETRIEVAL_QUERY: Optimized for query-based retrieval.
|
88
|
+
* - QUESTION_ANSWERING: Optimized for answering questions.
|
89
|
+
* - FACT_VERIFICATION: Optimized for verifying factual information.
|
90
|
+
* - CODE_RETRIEVAL_QUERY: Optimized for retrieving code blocks based on natural language queries.
|
91
|
+
*/
|
92
|
+
taskType: z2.enum([
|
93
|
+
"SEMANTIC_SIMILARITY",
|
94
|
+
"CLASSIFICATION",
|
95
|
+
"CLUSTERING",
|
96
|
+
"RETRIEVAL_DOCUMENT",
|
97
|
+
"RETRIEVAL_QUERY",
|
98
|
+
"QUESTION_ANSWERING",
|
99
|
+
"FACT_VERIFICATION",
|
100
|
+
"CODE_RETRIEVAL_QUERY"
|
101
|
+
]).optional()
|
102
|
+
})
|
103
|
+
)
|
104
|
+
);
|
96
105
|
|
97
106
|
// src/google-generative-ai-embedding-model.ts
|
98
107
|
var GoogleGenerativeAIEmbeddingModel = class {
|
@@ -112,7 +121,7 @@ var GoogleGenerativeAIEmbeddingModel = class {
|
|
112
121
|
abortSignal,
|
113
122
|
providerOptions
|
114
123
|
}) {
|
115
|
-
const googleOptions = await (0,
|
124
|
+
const googleOptions = await (0, import_provider_utils3.parseProviderOptions)({
|
116
125
|
provider: "google",
|
117
126
|
providerOptions,
|
118
127
|
schema: googleGenerativeAIEmbeddingProviderOptions
|
@@ -125,8 +134,8 @@ var GoogleGenerativeAIEmbeddingModel = class {
|
|
125
134
|
values
|
126
135
|
});
|
127
136
|
}
|
128
|
-
const mergedHeaders = (0,
|
129
|
-
await (0,
|
137
|
+
const mergedHeaders = (0, import_provider_utils3.combineHeaders)(
|
138
|
+
await (0, import_provider_utils3.resolve)(this.config.headers),
|
130
139
|
headers
|
131
140
|
);
|
132
141
|
if (values.length === 1) {
|
@@ -134,7 +143,7 @@ var GoogleGenerativeAIEmbeddingModel = class {
|
|
134
143
|
responseHeaders: responseHeaders2,
|
135
144
|
value: response2,
|
136
145
|
rawValue: rawValue2
|
137
|
-
} = await (0,
|
146
|
+
} = await (0, import_provider_utils3.postJsonToApi)({
|
138
147
|
url: `${this.config.baseURL}/models/${this.modelId}:embedContent`,
|
139
148
|
headers: mergedHeaders,
|
140
149
|
body: {
|
@@ -146,7 +155,7 @@ var GoogleGenerativeAIEmbeddingModel = class {
|
|
146
155
|
taskType: googleOptions == null ? void 0 : googleOptions.taskType
|
147
156
|
},
|
148
157
|
failedResponseHandler: googleFailedResponseHandler,
|
149
|
-
successfulResponseHandler: (0,
|
158
|
+
successfulResponseHandler: (0, import_provider_utils3.createJsonResponseHandler)(
|
150
159
|
googleGenerativeAISingleEmbeddingResponseSchema
|
151
160
|
),
|
152
161
|
abortSignal,
|
@@ -162,7 +171,7 @@ var GoogleGenerativeAIEmbeddingModel = class {
|
|
162
171
|
responseHeaders,
|
163
172
|
value: response,
|
164
173
|
rawValue
|
165
|
-
} = await (0,
|
174
|
+
} = await (0, import_provider_utils3.postJsonToApi)({
|
166
175
|
url: `${this.config.baseURL}/models/${this.modelId}:batchEmbedContents`,
|
167
176
|
headers: mergedHeaders,
|
168
177
|
body: {
|
@@ -174,7 +183,7 @@ var GoogleGenerativeAIEmbeddingModel = class {
|
|
174
183
|
}))
|
175
184
|
},
|
176
185
|
failedResponseHandler: googleFailedResponseHandler,
|
177
|
-
successfulResponseHandler: (0,
|
186
|
+
successfulResponseHandler: (0, import_provider_utils3.createJsonResponseHandler)(
|
178
187
|
googleGenerativeAITextEmbeddingResponseSchema
|
179
188
|
),
|
180
189
|
abortSignal,
|
@@ -187,16 +196,24 @@ var GoogleGenerativeAIEmbeddingModel = class {
|
|
187
196
|
};
|
188
197
|
}
|
189
198
|
};
|
190
|
-
var googleGenerativeAITextEmbeddingResponseSchema =
|
191
|
-
|
192
|
-
|
193
|
-
|
194
|
-
|
195
|
-
|
199
|
+
var googleGenerativeAITextEmbeddingResponseSchema = (0, import_provider_utils3.lazySchema)(
|
200
|
+
() => (0, import_provider_utils3.zodSchema)(
|
201
|
+
z3.object({
|
202
|
+
embeddings: z3.array(z3.object({ values: z3.array(z3.number()) }))
|
203
|
+
})
|
204
|
+
)
|
205
|
+
);
|
206
|
+
var googleGenerativeAISingleEmbeddingResponseSchema = (0, import_provider_utils3.lazySchema)(
|
207
|
+
() => (0, import_provider_utils3.zodSchema)(
|
208
|
+
z3.object({
|
209
|
+
embedding: z3.object({ values: z3.array(z3.number()) })
|
210
|
+
})
|
211
|
+
)
|
212
|
+
);
|
196
213
|
|
197
214
|
// src/google-generative-ai-language-model.ts
|
198
215
|
var import_provider_utils6 = require("@ai-sdk/provider-utils");
|
199
|
-
var
|
216
|
+
var z5 = __toESM(require("zod/v4"));
|
200
217
|
|
201
218
|
// src/convert-json-schema-to-openapi-schema.ts
|
202
219
|
function convertJSONSchemaToOpenAPISchema(jsonSchema) {
|
@@ -294,7 +311,7 @@ function isEmptyObjectSchema(jsonSchema) {
|
|
294
311
|
|
295
312
|
// src/convert-to-google-generative-ai-messages.ts
|
296
313
|
var import_provider2 = require("@ai-sdk/provider");
|
297
|
-
var
|
314
|
+
var import_provider_utils4 = require("@ai-sdk/provider-utils");
|
298
315
|
function convertToGoogleGenerativeAIMessages(prompt, options) {
|
299
316
|
var _a;
|
300
317
|
const systemInstructionParts = [];
|
@@ -332,7 +349,7 @@ function convertToGoogleGenerativeAIMessages(prompt, options) {
|
|
332
349
|
} : {
|
333
350
|
inlineData: {
|
334
351
|
mimeType: mediaType,
|
335
|
-
data: (0,
|
352
|
+
data: (0, import_provider_utils4.convertToBase64)(part.data)
|
336
353
|
}
|
337
354
|
}
|
338
355
|
);
|
@@ -377,7 +394,7 @@ function convertToGoogleGenerativeAIMessages(prompt, options) {
|
|
377
394
|
return {
|
378
395
|
inlineData: {
|
379
396
|
mimeType: part.mediaType,
|
380
|
-
data: (0,
|
397
|
+
data: (0, import_provider_utils4.convertToBase64)(part.data)
|
381
398
|
}
|
382
399
|
};
|
383
400
|
}
|
@@ -468,41 +485,54 @@ function getModelPath(modelId) {
|
|
468
485
|
}
|
469
486
|
|
470
487
|
// src/google-generative-ai-options.ts
|
488
|
+
var import_provider_utils5 = require("@ai-sdk/provider-utils");
|
471
489
|
var z4 = __toESM(require("zod/v4"));
|
472
|
-
var googleGenerativeAIProviderOptions =
|
473
|
-
|
474
|
-
thinkingConfig: z4.object({
|
475
|
-
thinkingBudget: z4.number().optional(),
|
476
|
-
includeThoughts: z4.boolean().optional()
|
477
|
-
}).optional(),
|
478
|
-
/**
|
479
|
-
Optional.
|
480
|
-
The name of the cached content used as context to serve the prediction.
|
481
|
-
Format: cachedContents/{cachedContent}
|
482
|
-
*/
|
483
|
-
cachedContent: z4.string().optional(),
|
484
|
-
/**
|
485
|
-
* Optional. Enable structured output. Default is true.
|
486
|
-
*
|
487
|
-
* This is useful when the JSON Schema contains elements that are
|
488
|
-
* not supported by the OpenAPI schema version that
|
489
|
-
* Google Generative AI uses. You can use this to disable
|
490
|
-
* structured outputs if you need to.
|
491
|
-
*/
|
492
|
-
structuredOutputs: z4.boolean().optional(),
|
493
|
-
/**
|
494
|
-
Optional. A list of unique safety settings for blocking unsafe content.
|
495
|
-
*/
|
496
|
-
safetySettings: z4.array(
|
490
|
+
var googleGenerativeAIProviderOptions = (0, import_provider_utils5.lazySchema)(
|
491
|
+
() => (0, import_provider_utils5.zodSchema)(
|
497
492
|
z4.object({
|
498
|
-
|
499
|
-
|
500
|
-
|
501
|
-
|
502
|
-
|
503
|
-
|
504
|
-
|
505
|
-
|
493
|
+
responseModalities: z4.array(z4.enum(["TEXT", "IMAGE"])).optional(),
|
494
|
+
thinkingConfig: z4.object({
|
495
|
+
thinkingBudget: z4.number().optional(),
|
496
|
+
includeThoughts: z4.boolean().optional()
|
497
|
+
}).optional(),
|
498
|
+
/**
|
499
|
+
* Optional.
|
500
|
+
* The name of the cached content used as context to serve the prediction.
|
501
|
+
* Format: cachedContents/{cachedContent}
|
502
|
+
*/
|
503
|
+
cachedContent: z4.string().optional(),
|
504
|
+
/**
|
505
|
+
* Optional. Enable structured output. Default is true.
|
506
|
+
*
|
507
|
+
* This is useful when the JSON Schema contains elements that are
|
508
|
+
* not supported by the OpenAPI schema version that
|
509
|
+
* Google Generative AI uses. You can use this to disable
|
510
|
+
* structured outputs if you need to.
|
511
|
+
*/
|
512
|
+
structuredOutputs: z4.boolean().optional(),
|
513
|
+
/**
|
514
|
+
* Optional. A list of unique safety settings for blocking unsafe content.
|
515
|
+
*/
|
516
|
+
safetySettings: z4.array(
|
517
|
+
z4.object({
|
518
|
+
category: z4.enum([
|
519
|
+
"HARM_CATEGORY_UNSPECIFIED",
|
520
|
+
"HARM_CATEGORY_HATE_SPEECH",
|
521
|
+
"HARM_CATEGORY_DANGEROUS_CONTENT",
|
522
|
+
"HARM_CATEGORY_HARASSMENT",
|
523
|
+
"HARM_CATEGORY_SEXUALLY_EXPLICIT",
|
524
|
+
"HARM_CATEGORY_CIVIC_INTEGRITY"
|
525
|
+
]),
|
526
|
+
threshold: z4.enum([
|
527
|
+
"HARM_BLOCK_THRESHOLD_UNSPECIFIED",
|
528
|
+
"BLOCK_LOW_AND_ABOVE",
|
529
|
+
"BLOCK_MEDIUM_AND_ABOVE",
|
530
|
+
"BLOCK_ONLY_HIGH",
|
531
|
+
"BLOCK_NONE",
|
532
|
+
"OFF"
|
533
|
+
])
|
534
|
+
})
|
535
|
+
).optional(),
|
506
536
|
threshold: z4.enum([
|
507
537
|
"HARM_BLOCK_THRESHOLD_UNSPECIFIED",
|
508
538
|
"BLOCK_LOW_AND_ABOVE",
|
@@ -510,30 +540,33 @@ var googleGenerativeAIProviderOptions = z4.object({
|
|
510
540
|
"BLOCK_ONLY_HIGH",
|
511
541
|
"BLOCK_NONE",
|
512
542
|
"OFF"
|
513
|
-
])
|
543
|
+
]).optional(),
|
544
|
+
/**
|
545
|
+
* Optional. Enables timestamp understanding for audio-only files.
|
546
|
+
*
|
547
|
+
* https://cloud.google.com/vertex-ai/generative-ai/docs/multimodal/audio-understanding
|
548
|
+
*/
|
549
|
+
audioTimestamp: z4.boolean().optional(),
|
550
|
+
/**
|
551
|
+
* Optional. Defines labels used in billing reports. Available on Vertex AI only.
|
552
|
+
*
|
553
|
+
* https://cloud.google.com/vertex-ai/generative-ai/docs/multimodal/add-labels-to-api-calls
|
554
|
+
*/
|
555
|
+
labels: z4.record(z4.string(), z4.string()).optional(),
|
556
|
+
/**
|
557
|
+
* Optional. If specified, the media resolution specified will be used.
|
558
|
+
*
|
559
|
+
* https://ai.google.dev/api/generate-content#MediaResolution
|
560
|
+
*/
|
561
|
+
mediaResolution: z4.enum([
|
562
|
+
"MEDIA_RESOLUTION_UNSPECIFIED",
|
563
|
+
"MEDIA_RESOLUTION_LOW",
|
564
|
+
"MEDIA_RESOLUTION_MEDIUM",
|
565
|
+
"MEDIA_RESOLUTION_HIGH"
|
566
|
+
]).optional()
|
514
567
|
})
|
515
|
-
)
|
516
|
-
|
517
|
-
"HARM_BLOCK_THRESHOLD_UNSPECIFIED",
|
518
|
-
"BLOCK_LOW_AND_ABOVE",
|
519
|
-
"BLOCK_MEDIUM_AND_ABOVE",
|
520
|
-
"BLOCK_ONLY_HIGH",
|
521
|
-
"BLOCK_NONE",
|
522
|
-
"OFF"
|
523
|
-
]).optional(),
|
524
|
-
/**
|
525
|
-
* Optional. Enables timestamp understanding for audio-only files.
|
526
|
-
*
|
527
|
-
* https://cloud.google.com/vertex-ai/generative-ai/docs/multimodal/audio-understanding
|
528
|
-
*/
|
529
|
-
audioTimestamp: z4.boolean().optional(),
|
530
|
-
/**
|
531
|
-
* Optional. Defines labels used in billing reports. Available on Vertex AI only.
|
532
|
-
*
|
533
|
-
* https://cloud.google.com/vertex-ai/generative-ai/docs/multimodal/add-labels-to-api-calls
|
534
|
-
*/
|
535
|
-
labels: z4.record(z4.string(), z4.string()).optional()
|
536
|
-
});
|
568
|
+
)
|
569
|
+
);
|
537
570
|
|
538
571
|
// src/google-prepare-tools.ts
|
539
572
|
var import_provider3 = require("@ai-sdk/provider");
|
@@ -704,64 +737,6 @@ function mapGoogleGenerativeAIFinishReason({
|
|
704
737
|
}
|
705
738
|
}
|
706
739
|
|
707
|
-
// src/tool/google-search.ts
|
708
|
-
var import_provider_utils4 = require("@ai-sdk/provider-utils");
|
709
|
-
var z5 = __toESM(require("zod/v4"));
|
710
|
-
var groundingChunkSchema = z5.object({
|
711
|
-
web: z5.object({ uri: z5.string(), title: z5.string() }).nullish(),
|
712
|
-
retrievedContext: z5.object({ uri: z5.string(), title: z5.string() }).nullish()
|
713
|
-
});
|
714
|
-
var groundingMetadataSchema = z5.object({
|
715
|
-
webSearchQueries: z5.array(z5.string()).nullish(),
|
716
|
-
retrievalQueries: z5.array(z5.string()).nullish(),
|
717
|
-
searchEntryPoint: z5.object({ renderedContent: z5.string() }).nullish(),
|
718
|
-
groundingChunks: z5.array(groundingChunkSchema).nullish(),
|
719
|
-
groundingSupports: z5.array(
|
720
|
-
z5.object({
|
721
|
-
segment: z5.object({
|
722
|
-
startIndex: z5.number().nullish(),
|
723
|
-
endIndex: z5.number().nullish(),
|
724
|
-
text: z5.string().nullish()
|
725
|
-
}),
|
726
|
-
segment_text: z5.string().nullish(),
|
727
|
-
groundingChunkIndices: z5.array(z5.number()).nullish(),
|
728
|
-
supportChunkIndices: z5.array(z5.number()).nullish(),
|
729
|
-
confidenceScores: z5.array(z5.number()).nullish(),
|
730
|
-
confidenceScore: z5.array(z5.number()).nullish()
|
731
|
-
})
|
732
|
-
).nullish(),
|
733
|
-
retrievalMetadata: z5.union([
|
734
|
-
z5.object({
|
735
|
-
webDynamicRetrievalScore: z5.number()
|
736
|
-
}),
|
737
|
-
z5.object({})
|
738
|
-
]).nullish()
|
739
|
-
});
|
740
|
-
var googleSearch = (0, import_provider_utils4.createProviderDefinedToolFactory)({
|
741
|
-
id: "google.google_search",
|
742
|
-
name: "google_search",
|
743
|
-
inputSchema: z5.object({
|
744
|
-
mode: z5.enum(["MODE_DYNAMIC", "MODE_UNSPECIFIED"]).default("MODE_UNSPECIFIED"),
|
745
|
-
dynamicThreshold: z5.number().default(1)
|
746
|
-
})
|
747
|
-
});
|
748
|
-
|
749
|
-
// src/tool/url-context.ts
|
750
|
-
var import_provider_utils5 = require("@ai-sdk/provider-utils");
|
751
|
-
var z6 = __toESM(require("zod/v4"));
|
752
|
-
var urlMetadataSchema = z6.object({
|
753
|
-
retrievedUrl: z6.string(),
|
754
|
-
urlRetrievalStatus: z6.string()
|
755
|
-
});
|
756
|
-
var urlContextMetadataSchema = z6.object({
|
757
|
-
urlMetadata: z6.array(urlMetadataSchema)
|
758
|
-
});
|
759
|
-
var urlContext = (0, import_provider_utils5.createProviderDefinedToolFactory)({
|
760
|
-
id: "google.url_context",
|
761
|
-
name: "url_context",
|
762
|
-
inputSchema: z6.object({})
|
763
|
-
});
|
764
|
-
|
765
740
|
// src/google-generative-ai-language-model.ts
|
766
741
|
var GoogleGenerativeAILanguageModel = class {
|
767
742
|
constructor(modelId, config) {
|
@@ -1254,103 +1229,175 @@ function extractSources({
|
|
1254
1229
|
title: chunk.web.title
|
1255
1230
|
}));
|
1256
1231
|
}
|
1257
|
-
var
|
1258
|
-
|
1259
|
-
|
1232
|
+
var getGroundingMetadataSchema = () => z5.object({
|
1233
|
+
webSearchQueries: z5.array(z5.string()).nullish(),
|
1234
|
+
retrievalQueries: z5.array(z5.string()).nullish(),
|
1235
|
+
searchEntryPoint: z5.object({ renderedContent: z5.string() }).nullish(),
|
1236
|
+
groundingChunks: z5.array(
|
1237
|
+
z5.object({
|
1238
|
+
web: z5.object({ uri: z5.string(), title: z5.string() }).nullish(),
|
1239
|
+
retrievedContext: z5.object({ uri: z5.string(), title: z5.string() }).nullish()
|
1240
|
+
})
|
1241
|
+
).nullish(),
|
1242
|
+
groundingSupports: z5.array(
|
1243
|
+
z5.object({
|
1244
|
+
segment: z5.object({
|
1245
|
+
startIndex: z5.number().nullish(),
|
1246
|
+
endIndex: z5.number().nullish(),
|
1247
|
+
text: z5.string().nullish()
|
1248
|
+
}),
|
1249
|
+
segment_text: z5.string().nullish(),
|
1250
|
+
groundingChunkIndices: z5.array(z5.number()).nullish(),
|
1251
|
+
supportChunkIndices: z5.array(z5.number()).nullish(),
|
1252
|
+
confidenceScores: z5.array(z5.number()).nullish(),
|
1253
|
+
confidenceScore: z5.array(z5.number()).nullish()
|
1254
|
+
})
|
1255
|
+
).nullish(),
|
1256
|
+
retrievalMetadata: z5.union([
|
1257
|
+
z5.object({
|
1258
|
+
webDynamicRetrievalScore: z5.number()
|
1259
|
+
}),
|
1260
|
+
z5.object({})
|
1261
|
+
]).nullish()
|
1262
|
+
});
|
1263
|
+
var getContentSchema = () => z5.object({
|
1264
|
+
parts: z5.array(
|
1265
|
+
z5.union([
|
1260
1266
|
// note: order matters since text can be fully empty
|
1261
|
-
|
1262
|
-
functionCall:
|
1263
|
-
name:
|
1264
|
-
args:
|
1267
|
+
z5.object({
|
1268
|
+
functionCall: z5.object({
|
1269
|
+
name: z5.string(),
|
1270
|
+
args: z5.unknown()
|
1265
1271
|
}),
|
1266
|
-
thoughtSignature:
|
1272
|
+
thoughtSignature: z5.string().nullish()
|
1267
1273
|
}),
|
1268
|
-
|
1269
|
-
inlineData:
|
1270
|
-
mimeType:
|
1271
|
-
data:
|
1274
|
+
z5.object({
|
1275
|
+
inlineData: z5.object({
|
1276
|
+
mimeType: z5.string(),
|
1277
|
+
data: z5.string()
|
1272
1278
|
})
|
1273
1279
|
}),
|
1274
|
-
|
1275
|
-
executableCode:
|
1276
|
-
language:
|
1277
|
-
code:
|
1280
|
+
z5.object({
|
1281
|
+
executableCode: z5.object({
|
1282
|
+
language: z5.string(),
|
1283
|
+
code: z5.string()
|
1278
1284
|
}).nullish(),
|
1279
|
-
codeExecutionResult:
|
1280
|
-
outcome:
|
1281
|
-
output:
|
1285
|
+
codeExecutionResult: z5.object({
|
1286
|
+
outcome: z5.string(),
|
1287
|
+
output: z5.string()
|
1282
1288
|
}).nullish(),
|
1283
|
-
text:
|
1284
|
-
thought:
|
1285
|
-
thoughtSignature:
|
1289
|
+
text: z5.string().nullish(),
|
1290
|
+
thought: z5.boolean().nullish(),
|
1291
|
+
thoughtSignature: z5.string().nullish()
|
1286
1292
|
})
|
1287
1293
|
])
|
1288
1294
|
).nullish()
|
1289
1295
|
});
|
1290
|
-
var
|
1291
|
-
category:
|
1292
|
-
probability:
|
1293
|
-
probabilityScore:
|
1294
|
-
severity:
|
1295
|
-
severityScore:
|
1296
|
-
blocked:
|
1296
|
+
var getSafetyRatingSchema = () => z5.object({
|
1297
|
+
category: z5.string().nullish(),
|
1298
|
+
probability: z5.string().nullish(),
|
1299
|
+
probabilityScore: z5.number().nullish(),
|
1300
|
+
severity: z5.string().nullish(),
|
1301
|
+
severityScore: z5.number().nullish(),
|
1302
|
+
blocked: z5.boolean().nullish()
|
1297
1303
|
});
|
1298
|
-
var usageSchema =
|
1299
|
-
cachedContentTokenCount:
|
1300
|
-
thoughtsTokenCount:
|
1301
|
-
promptTokenCount:
|
1302
|
-
candidatesTokenCount:
|
1303
|
-
totalTokenCount:
|
1304
|
+
var usageSchema = z5.object({
|
1305
|
+
cachedContentTokenCount: z5.number().nullish(),
|
1306
|
+
thoughtsTokenCount: z5.number().nullish(),
|
1307
|
+
promptTokenCount: z5.number().nullish(),
|
1308
|
+
candidatesTokenCount: z5.number().nullish(),
|
1309
|
+
totalTokenCount: z5.number().nullish()
|
1304
1310
|
});
|
1305
|
-
var
|
1306
|
-
|
1307
|
-
|
1308
|
-
|
1309
|
-
|
1310
|
-
safetyRatings: z7.array(safetyRatingSchema).nullish(),
|
1311
|
-
groundingMetadata: groundingMetadataSchema.nullish(),
|
1312
|
-
urlContextMetadata: urlContextMetadataSchema.nullish()
|
1311
|
+
var getUrlContextMetadataSchema = () => z5.object({
|
1312
|
+
urlMetadata: z5.array(
|
1313
|
+
z5.object({
|
1314
|
+
retrievedUrl: z5.string(),
|
1315
|
+
urlRetrievalStatus: z5.string()
|
1313
1316
|
})
|
1314
|
-
)
|
1315
|
-
usageMetadata: usageSchema.nullish(),
|
1316
|
-
promptFeedback: z7.object({
|
1317
|
-
blockReason: z7.string().nullish(),
|
1318
|
-
safetyRatings: z7.array(safetyRatingSchema).nullish()
|
1319
|
-
}).nullish()
|
1317
|
+
)
|
1320
1318
|
});
|
1321
|
-
var
|
1322
|
-
|
1323
|
-
|
1324
|
-
|
1325
|
-
|
1326
|
-
|
1327
|
-
|
1328
|
-
|
1319
|
+
var responseSchema = (0, import_provider_utils6.lazySchema)(
|
1320
|
+
() => (0, import_provider_utils6.zodSchema)(
|
1321
|
+
z5.object({
|
1322
|
+
candidates: z5.array(
|
1323
|
+
z5.object({
|
1324
|
+
content: getContentSchema().nullish().or(z5.object({}).strict()),
|
1325
|
+
finishReason: z5.string().nullish(),
|
1326
|
+
safetyRatings: z5.array(getSafetyRatingSchema()).nullish(),
|
1327
|
+
groundingMetadata: getGroundingMetadataSchema().nullish(),
|
1328
|
+
urlContextMetadata: getUrlContextMetadataSchema().nullish()
|
1329
|
+
})
|
1330
|
+
),
|
1331
|
+
usageMetadata: usageSchema.nullish(),
|
1332
|
+
promptFeedback: z5.object({
|
1333
|
+
blockReason: z5.string().nullish(),
|
1334
|
+
safetyRatings: z5.array(getSafetyRatingSchema()).nullish()
|
1335
|
+
}).nullish()
|
1329
1336
|
})
|
1330
|
-
)
|
1331
|
-
|
1332
|
-
|
1333
|
-
|
1334
|
-
|
1335
|
-
|
1336
|
-
|
1337
|
+
)
|
1338
|
+
);
|
1339
|
+
var chunkSchema = (0, import_provider_utils6.lazySchema)(
|
1340
|
+
() => (0, import_provider_utils6.zodSchema)(
|
1341
|
+
z5.object({
|
1342
|
+
candidates: z5.array(
|
1343
|
+
z5.object({
|
1344
|
+
content: getContentSchema().nullish(),
|
1345
|
+
finishReason: z5.string().nullish(),
|
1346
|
+
safetyRatings: z5.array(getSafetyRatingSchema()).nullish(),
|
1347
|
+
groundingMetadata: getGroundingMetadataSchema().nullish(),
|
1348
|
+
urlContextMetadata: getUrlContextMetadataSchema().nullish()
|
1349
|
+
})
|
1350
|
+
).nullish(),
|
1351
|
+
usageMetadata: usageSchema.nullish(),
|
1352
|
+
promptFeedback: z5.object({
|
1353
|
+
blockReason: z5.string().nullish(),
|
1354
|
+
safetyRatings: z5.array(getSafetyRatingSchema()).nullish()
|
1355
|
+
}).nullish()
|
1356
|
+
})
|
1357
|
+
)
|
1358
|
+
);
|
1337
1359
|
|
1338
1360
|
// src/tool/code-execution.ts
|
1339
1361
|
var import_provider_utils7 = require("@ai-sdk/provider-utils");
|
1340
|
-
var
|
1362
|
+
var z6 = __toESM(require("zod/v4"));
|
1341
1363
|
var codeExecution = (0, import_provider_utils7.createProviderDefinedToolFactoryWithOutputSchema)({
|
1342
1364
|
id: "google.code_execution",
|
1343
1365
|
name: "code_execution",
|
1344
|
-
inputSchema:
|
1345
|
-
language:
|
1346
|
-
code:
|
1366
|
+
inputSchema: z6.object({
|
1367
|
+
language: z6.string().describe("The programming language of the code."),
|
1368
|
+
code: z6.string().describe("The code to be executed.")
|
1347
1369
|
}),
|
1348
|
-
outputSchema:
|
1349
|
-
outcome:
|
1350
|
-
output:
|
1370
|
+
outputSchema: z6.object({
|
1371
|
+
outcome: z6.string().describe('The outcome of the execution (e.g., "OUTCOME_OK").'),
|
1372
|
+
output: z6.string().describe("The output from the code execution.")
|
1351
1373
|
})
|
1352
1374
|
});
|
1353
1375
|
|
1376
|
+
// src/tool/google-search.ts
|
1377
|
+
var import_provider_utils8 = require("@ai-sdk/provider-utils");
|
1378
|
+
var z7 = __toESM(require("zod/v4"));
|
1379
|
+
var googleSearch = (0, import_provider_utils8.createProviderDefinedToolFactory)({
|
1380
|
+
id: "google.google_search",
|
1381
|
+
name: "google_search",
|
1382
|
+
inputSchema: (0, import_provider_utils8.lazySchema)(
|
1383
|
+
() => (0, import_provider_utils8.zodSchema)(
|
1384
|
+
z7.object({
|
1385
|
+
mode: z7.enum(["MODE_DYNAMIC", "MODE_UNSPECIFIED"]).default("MODE_UNSPECIFIED"),
|
1386
|
+
dynamicThreshold: z7.number().default(1)
|
1387
|
+
})
|
1388
|
+
)
|
1389
|
+
)
|
1390
|
+
});
|
1391
|
+
|
1392
|
+
// src/tool/url-context.ts
|
1393
|
+
var import_provider_utils9 = require("@ai-sdk/provider-utils");
|
1394
|
+
var z8 = __toESM(require("zod/v4"));
|
1395
|
+
var urlContext = (0, import_provider_utils9.createProviderDefinedToolFactory)({
|
1396
|
+
id: "google.url_context",
|
1397
|
+
name: "url_context",
|
1398
|
+
inputSchema: (0, import_provider_utils9.lazySchema)(() => (0, import_provider_utils9.zodSchema)(z8.object({})))
|
1399
|
+
});
|
1400
|
+
|
1354
1401
|
// src/google-tools.ts
|
1355
1402
|
var googleTools = {
|
1356
1403
|
/**
|
@@ -1377,7 +1424,7 @@ var googleTools = {
|
|
1377
1424
|
};
|
1378
1425
|
|
1379
1426
|
// src/google-generative-ai-image-model.ts
|
1380
|
-
var
|
1427
|
+
var import_provider_utils10 = require("@ai-sdk/provider-utils");
|
1381
1428
|
var z9 = __toESM(require("zod/v4"));
|
1382
1429
|
var GoogleGenerativeAIImageModel = class {
|
1383
1430
|
constructor(modelId, settings, config) {
|
@@ -1420,7 +1467,7 @@ var GoogleGenerativeAIImageModel = class {
|
|
1420
1467
|
details: "This model does not support the `seed` option through this provider."
|
1421
1468
|
});
|
1422
1469
|
}
|
1423
|
-
const googleOptions = await (0,
|
1470
|
+
const googleOptions = await (0, import_provider_utils10.parseProviderOptions)({
|
1424
1471
|
provider: "google",
|
1425
1472
|
providerOptions,
|
1426
1473
|
schema: googleImageProviderOptionsSchema
|
@@ -1439,12 +1486,12 @@ var GoogleGenerativeAIImageModel = class {
|
|
1439
1486
|
instances: [{ prompt }],
|
1440
1487
|
parameters
|
1441
1488
|
};
|
1442
|
-
const { responseHeaders, value: response } = await (0,
|
1489
|
+
const { responseHeaders, value: response } = await (0, import_provider_utils10.postJsonToApi)({
|
1443
1490
|
url: `${this.config.baseURL}/models/${this.modelId}:predict`,
|
1444
|
-
headers: (0,
|
1491
|
+
headers: (0, import_provider_utils10.combineHeaders)(await (0, import_provider_utils10.resolve)(this.config.headers), headers),
|
1445
1492
|
body,
|
1446
1493
|
failedResponseHandler: googleFailedResponseHandler,
|
1447
|
-
successfulResponseHandler: (0,
|
1494
|
+
successfulResponseHandler: (0, import_provider_utils10.createJsonResponseHandler)(
|
1448
1495
|
googleImageResponseSchema
|
1449
1496
|
),
|
1450
1497
|
abortSignal,
|
@@ -1470,21 +1517,29 @@ var GoogleGenerativeAIImageModel = class {
|
|
1470
1517
|
};
|
1471
1518
|
}
|
1472
1519
|
};
|
1473
|
-
var googleImageResponseSchema =
|
1474
|
-
|
1475
|
-
|
1476
|
-
|
1477
|
-
|
1478
|
-
|
1479
|
-
|
1520
|
+
var googleImageResponseSchema = (0, import_provider_utils10.lazySchema)(
|
1521
|
+
() => (0, import_provider_utils10.zodSchema)(
|
1522
|
+
z9.object({
|
1523
|
+
predictions: z9.array(z9.object({ bytesBase64Encoded: z9.string() })).default([])
|
1524
|
+
})
|
1525
|
+
)
|
1526
|
+
);
|
1527
|
+
var googleImageProviderOptionsSchema = (0, import_provider_utils10.lazySchema)(
|
1528
|
+
() => (0, import_provider_utils10.zodSchema)(
|
1529
|
+
z9.object({
|
1530
|
+
personGeneration: z9.enum(["dont_allow", "allow_adult", "allow_all"]).nullish(),
|
1531
|
+
aspectRatio: z9.enum(["1:1", "3:4", "4:3", "9:16", "16:9"]).nullish()
|
1532
|
+
})
|
1533
|
+
)
|
1534
|
+
);
|
1480
1535
|
|
1481
1536
|
// src/google-provider.ts
|
1482
1537
|
function createGoogleGenerativeAI(options = {}) {
|
1483
1538
|
var _a;
|
1484
|
-
const baseURL = (_a = (0,
|
1485
|
-
const getHeaders = () => (0,
|
1539
|
+
const baseURL = (_a = (0, import_provider_utils11.withoutTrailingSlash)(options.baseURL)) != null ? _a : "https://generativelanguage.googleapis.com/v1beta";
|
1540
|
+
const getHeaders = () => (0, import_provider_utils11.withUserAgentSuffix)(
|
1486
1541
|
{
|
1487
|
-
"x-goog-api-key": (0,
|
1542
|
+
"x-goog-api-key": (0, import_provider_utils11.loadApiKey)({
|
1488
1543
|
apiKey: options.apiKey,
|
1489
1544
|
environmentVariableName: "GOOGLE_GENERATIVE_AI_API_KEY",
|
1490
1545
|
description: "Google Generative AI"
|
@@ -1499,7 +1554,7 @@ function createGoogleGenerativeAI(options = {}) {
|
|
1499
1554
|
provider: "google.generative-ai",
|
1500
1555
|
baseURL,
|
1501
1556
|
headers: getHeaders,
|
1502
|
-
generateId: (_a2 = options.generateId) != null ? _a2 :
|
1557
|
+
generateId: (_a2 = options.generateId) != null ? _a2 : import_provider_utils11.generateId,
|
1503
1558
|
supportedUrls: () => ({
|
1504
1559
|
"*": [
|
1505
1560
|
// Google Generative Language "files" endpoint
|