@ai-sdk/google 2.0.17 → 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 +17 -0
- package/dist/index.d.mts +139 -132
- package/dist/index.d.ts +139 -132
- package/dist/index.js +332 -270
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +327 -251
- package/dist/index.mjs.map +1 -1
- package/dist/internal/index.d.mts +139 -11
- package/dist/internal/index.d.ts +139 -11
- package/dist/internal/index.js +263 -220
- package/dist/internal/index.js.map +1 -1
- package/dist/internal/index.mjs +254 -205
- package/dist/internal/index.mjs.map +1 -1
- package/package.json +3 -3
package/dist/index.js
CHANGED
@@ -1,7 +1,9 @@
|
|
1
1
|
"use strict";
|
2
|
+
var __create = Object.create;
|
2
3
|
var __defProp = Object.defineProperty;
|
3
4
|
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
4
5
|
var __getOwnPropNames = Object.getOwnPropertyNames;
|
6
|
+
var __getProtoOf = Object.getPrototypeOf;
|
5
7
|
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
6
8
|
var __export = (target, all) => {
|
7
9
|
for (var name in all)
|
@@ -15,6 +17,14 @@ var __copyProps = (to, from, except, desc) => {
|
|
15
17
|
}
|
16
18
|
return to;
|
17
19
|
};
|
20
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
21
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
22
|
+
// file that has been converted to a CommonJS file using a Babel-
|
23
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
24
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
25
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
26
|
+
mod
|
27
|
+
));
|
18
28
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
19
29
|
|
20
30
|
// src/index.ts
|
@@ -27,62 +37,71 @@ __export(src_exports, {
|
|
27
37
|
module.exports = __toCommonJS(src_exports);
|
28
38
|
|
29
39
|
// src/google-provider.ts
|
30
|
-
var
|
40
|
+
var import_provider_utils11 = require("@ai-sdk/provider-utils");
|
31
41
|
|
32
42
|
// src/version.ts
|
33
|
-
var VERSION = true ? "2.0.
|
43
|
+
var VERSION = true ? "2.0.19" : "0.0.0-test";
|
34
44
|
|
35
45
|
// src/google-generative-ai-embedding-model.ts
|
36
46
|
var import_provider = require("@ai-sdk/provider");
|
37
|
-
var
|
38
|
-
var
|
47
|
+
var import_provider_utils3 = require("@ai-sdk/provider-utils");
|
48
|
+
var z3 = __toESM(require("zod/v4"));
|
39
49
|
|
40
50
|
// src/google-error.ts
|
41
51
|
var import_provider_utils = require("@ai-sdk/provider-utils");
|
42
|
-
var
|
43
|
-
var googleErrorDataSchema =
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
52
|
+
var z = __toESM(require("zod/v4"));
|
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
|
+
);
|
50
64
|
var googleFailedResponseHandler = (0, import_provider_utils.createJsonErrorResponseHandler)({
|
51
65
|
errorSchema: googleErrorDataSchema,
|
52
66
|
errorToMessage: (data) => data.error.message
|
53
67
|
});
|
54
68
|
|
55
69
|
// src/google-generative-ai-embedding-options.ts
|
56
|
-
var
|
57
|
-
var
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
70
|
+
var import_provider_utils2 = require("@ai-sdk/provider-utils");
|
71
|
+
var z2 = __toESM(require("zod/v4"));
|
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
|
+
);
|
86
105
|
|
87
106
|
// src/google-generative-ai-embedding-model.ts
|
88
107
|
var GoogleGenerativeAIEmbeddingModel = class {
|
@@ -102,7 +121,7 @@ var GoogleGenerativeAIEmbeddingModel = class {
|
|
102
121
|
abortSignal,
|
103
122
|
providerOptions
|
104
123
|
}) {
|
105
|
-
const googleOptions = await (0,
|
124
|
+
const googleOptions = await (0, import_provider_utils3.parseProviderOptions)({
|
106
125
|
provider: "google",
|
107
126
|
providerOptions,
|
108
127
|
schema: googleGenerativeAIEmbeddingProviderOptions
|
@@ -115,8 +134,8 @@ var GoogleGenerativeAIEmbeddingModel = class {
|
|
115
134
|
values
|
116
135
|
});
|
117
136
|
}
|
118
|
-
const mergedHeaders = (0,
|
119
|
-
await (0,
|
137
|
+
const mergedHeaders = (0, import_provider_utils3.combineHeaders)(
|
138
|
+
await (0, import_provider_utils3.resolve)(this.config.headers),
|
120
139
|
headers
|
121
140
|
);
|
122
141
|
if (values.length === 1) {
|
@@ -124,7 +143,7 @@ var GoogleGenerativeAIEmbeddingModel = class {
|
|
124
143
|
responseHeaders: responseHeaders2,
|
125
144
|
value: response2,
|
126
145
|
rawValue: rawValue2
|
127
|
-
} = await (0,
|
146
|
+
} = await (0, import_provider_utils3.postJsonToApi)({
|
128
147
|
url: `${this.config.baseURL}/models/${this.modelId}:embedContent`,
|
129
148
|
headers: mergedHeaders,
|
130
149
|
body: {
|
@@ -136,7 +155,7 @@ var GoogleGenerativeAIEmbeddingModel = class {
|
|
136
155
|
taskType: googleOptions == null ? void 0 : googleOptions.taskType
|
137
156
|
},
|
138
157
|
failedResponseHandler: googleFailedResponseHandler,
|
139
|
-
successfulResponseHandler: (0,
|
158
|
+
successfulResponseHandler: (0, import_provider_utils3.createJsonResponseHandler)(
|
140
159
|
googleGenerativeAISingleEmbeddingResponseSchema
|
141
160
|
),
|
142
161
|
abortSignal,
|
@@ -152,7 +171,7 @@ var GoogleGenerativeAIEmbeddingModel = class {
|
|
152
171
|
responseHeaders,
|
153
172
|
value: response,
|
154
173
|
rawValue
|
155
|
-
} = await (0,
|
174
|
+
} = await (0, import_provider_utils3.postJsonToApi)({
|
156
175
|
url: `${this.config.baseURL}/models/${this.modelId}:batchEmbedContents`,
|
157
176
|
headers: mergedHeaders,
|
158
177
|
body: {
|
@@ -164,7 +183,7 @@ var GoogleGenerativeAIEmbeddingModel = class {
|
|
164
183
|
}))
|
165
184
|
},
|
166
185
|
failedResponseHandler: googleFailedResponseHandler,
|
167
|
-
successfulResponseHandler: (0,
|
186
|
+
successfulResponseHandler: (0, import_provider_utils3.createJsonResponseHandler)(
|
168
187
|
googleGenerativeAITextEmbeddingResponseSchema
|
169
188
|
),
|
170
189
|
abortSignal,
|
@@ -177,16 +196,24 @@ var GoogleGenerativeAIEmbeddingModel = class {
|
|
177
196
|
};
|
178
197
|
}
|
179
198
|
};
|
180
|
-
var googleGenerativeAITextEmbeddingResponseSchema =
|
181
|
-
|
182
|
-
|
183
|
-
|
184
|
-
|
185
|
-
|
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
|
+
);
|
186
213
|
|
187
214
|
// src/google-generative-ai-language-model.ts
|
188
215
|
var import_provider_utils6 = require("@ai-sdk/provider-utils");
|
189
|
-
var
|
216
|
+
var z5 = __toESM(require("zod/v4"));
|
190
217
|
|
191
218
|
// src/convert-json-schema-to-openapi-schema.ts
|
192
219
|
function convertJSONSchemaToOpenAPISchema(jsonSchema) {
|
@@ -211,12 +238,9 @@ function convertJSONSchemaToOpenAPISchema(jsonSchema) {
|
|
211
238
|
enum: enumValues
|
212
239
|
} = jsonSchema;
|
213
240
|
const result = {};
|
214
|
-
if (description)
|
215
|
-
|
216
|
-
if (
|
217
|
-
result.required = required;
|
218
|
-
if (format)
|
219
|
-
result.format = format;
|
241
|
+
if (description) result.description = description;
|
242
|
+
if (required) result.required = required;
|
243
|
+
if (format) result.format = format;
|
220
244
|
if (constValue !== void 0) {
|
221
245
|
result.enum = [constValue];
|
222
246
|
}
|
@@ -287,7 +311,7 @@ function isEmptyObjectSchema(jsonSchema) {
|
|
287
311
|
|
288
312
|
// src/convert-to-google-generative-ai-messages.ts
|
289
313
|
var import_provider2 = require("@ai-sdk/provider");
|
290
|
-
var
|
314
|
+
var import_provider_utils4 = require("@ai-sdk/provider-utils");
|
291
315
|
function convertToGoogleGenerativeAIMessages(prompt, options) {
|
292
316
|
var _a;
|
293
317
|
const systemInstructionParts = [];
|
@@ -325,7 +349,7 @@ function convertToGoogleGenerativeAIMessages(prompt, options) {
|
|
325
349
|
} : {
|
326
350
|
inlineData: {
|
327
351
|
mimeType: mediaType,
|
328
|
-
data: (0,
|
352
|
+
data: (0, import_provider_utils4.convertToBase64)(part.data)
|
329
353
|
}
|
330
354
|
}
|
331
355
|
);
|
@@ -370,7 +394,7 @@ function convertToGoogleGenerativeAIMessages(prompt, options) {
|
|
370
394
|
return {
|
371
395
|
inlineData: {
|
372
396
|
mimeType: part.mediaType,
|
373
|
-
data: (0,
|
397
|
+
data: (0, import_provider_utils4.convertToBase64)(part.data)
|
374
398
|
}
|
375
399
|
};
|
376
400
|
}
|
@@ -461,72 +485,88 @@ function getModelPath(modelId) {
|
|
461
485
|
}
|
462
486
|
|
463
487
|
// src/google-generative-ai-options.ts
|
464
|
-
var
|
465
|
-
var
|
466
|
-
|
467
|
-
|
468
|
-
|
469
|
-
|
470
|
-
|
471
|
-
|
472
|
-
|
473
|
-
|
474
|
-
|
475
|
-
|
476
|
-
|
477
|
-
|
478
|
-
|
479
|
-
|
480
|
-
|
481
|
-
|
482
|
-
|
483
|
-
|
484
|
-
|
485
|
-
|
486
|
-
|
487
|
-
|
488
|
-
|
489
|
-
|
490
|
-
|
491
|
-
|
492
|
-
|
493
|
-
|
494
|
-
|
495
|
-
|
496
|
-
|
497
|
-
|
498
|
-
|
499
|
-
|
488
|
+
var import_provider_utils5 = require("@ai-sdk/provider-utils");
|
489
|
+
var z4 = __toESM(require("zod/v4"));
|
490
|
+
var googleGenerativeAIProviderOptions = (0, import_provider_utils5.lazySchema)(
|
491
|
+
() => (0, import_provider_utils5.zodSchema)(
|
492
|
+
z4.object({
|
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(),
|
536
|
+
threshold: z4.enum([
|
500
537
|
"HARM_BLOCK_THRESHOLD_UNSPECIFIED",
|
501
538
|
"BLOCK_LOW_AND_ABOVE",
|
502
539
|
"BLOCK_MEDIUM_AND_ABOVE",
|
503
540
|
"BLOCK_ONLY_HIGH",
|
504
541
|
"BLOCK_NONE",
|
505
542
|
"OFF"
|
506
|
-
])
|
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()
|
507
567
|
})
|
508
|
-
)
|
509
|
-
|
510
|
-
"HARM_BLOCK_THRESHOLD_UNSPECIFIED",
|
511
|
-
"BLOCK_LOW_AND_ABOVE",
|
512
|
-
"BLOCK_MEDIUM_AND_ABOVE",
|
513
|
-
"BLOCK_ONLY_HIGH",
|
514
|
-
"BLOCK_NONE",
|
515
|
-
"OFF"
|
516
|
-
]).optional(),
|
517
|
-
/**
|
518
|
-
* Optional. Enables timestamp understanding for audio-only files.
|
519
|
-
*
|
520
|
-
* https://cloud.google.com/vertex-ai/generative-ai/docs/multimodal/audio-understanding
|
521
|
-
*/
|
522
|
-
audioTimestamp: import_v44.z.boolean().optional(),
|
523
|
-
/**
|
524
|
-
* Optional. Defines labels used in billing reports. Available on Vertex AI only.
|
525
|
-
*
|
526
|
-
* https://cloud.google.com/vertex-ai/generative-ai/docs/multimodal/add-labels-to-api-calls
|
527
|
-
*/
|
528
|
-
labels: import_v44.z.record(import_v44.z.string(), import_v44.z.string()).optional()
|
529
|
-
});
|
568
|
+
)
|
569
|
+
);
|
530
570
|
|
531
571
|
// src/google-prepare-tools.ts
|
532
572
|
var import_provider3 = require("@ai-sdk/provider");
|
@@ -697,64 +737,6 @@ function mapGoogleGenerativeAIFinishReason({
|
|
697
737
|
}
|
698
738
|
}
|
699
739
|
|
700
|
-
// src/tool/google-search.ts
|
701
|
-
var import_provider_utils4 = require("@ai-sdk/provider-utils");
|
702
|
-
var import_v45 = require("zod/v4");
|
703
|
-
var groundingChunkSchema = import_v45.z.object({
|
704
|
-
web: import_v45.z.object({ uri: import_v45.z.string(), title: import_v45.z.string() }).nullish(),
|
705
|
-
retrievedContext: import_v45.z.object({ uri: import_v45.z.string(), title: import_v45.z.string() }).nullish()
|
706
|
-
});
|
707
|
-
var groundingMetadataSchema = import_v45.z.object({
|
708
|
-
webSearchQueries: import_v45.z.array(import_v45.z.string()).nullish(),
|
709
|
-
retrievalQueries: import_v45.z.array(import_v45.z.string()).nullish(),
|
710
|
-
searchEntryPoint: import_v45.z.object({ renderedContent: import_v45.z.string() }).nullish(),
|
711
|
-
groundingChunks: import_v45.z.array(groundingChunkSchema).nullish(),
|
712
|
-
groundingSupports: import_v45.z.array(
|
713
|
-
import_v45.z.object({
|
714
|
-
segment: import_v45.z.object({
|
715
|
-
startIndex: import_v45.z.number().nullish(),
|
716
|
-
endIndex: import_v45.z.number().nullish(),
|
717
|
-
text: import_v45.z.string().nullish()
|
718
|
-
}),
|
719
|
-
segment_text: import_v45.z.string().nullish(),
|
720
|
-
groundingChunkIndices: import_v45.z.array(import_v45.z.number()).nullish(),
|
721
|
-
supportChunkIndices: import_v45.z.array(import_v45.z.number()).nullish(),
|
722
|
-
confidenceScores: import_v45.z.array(import_v45.z.number()).nullish(),
|
723
|
-
confidenceScore: import_v45.z.array(import_v45.z.number()).nullish()
|
724
|
-
})
|
725
|
-
).nullish(),
|
726
|
-
retrievalMetadata: import_v45.z.union([
|
727
|
-
import_v45.z.object({
|
728
|
-
webDynamicRetrievalScore: import_v45.z.number()
|
729
|
-
}),
|
730
|
-
import_v45.z.object({})
|
731
|
-
]).nullish()
|
732
|
-
});
|
733
|
-
var googleSearch = (0, import_provider_utils4.createProviderDefinedToolFactory)({
|
734
|
-
id: "google.google_search",
|
735
|
-
name: "google_search",
|
736
|
-
inputSchema: import_v45.z.object({
|
737
|
-
mode: import_v45.z.enum(["MODE_DYNAMIC", "MODE_UNSPECIFIED"]).default("MODE_UNSPECIFIED"),
|
738
|
-
dynamicThreshold: import_v45.z.number().default(1)
|
739
|
-
})
|
740
|
-
});
|
741
|
-
|
742
|
-
// src/tool/url-context.ts
|
743
|
-
var import_provider_utils5 = require("@ai-sdk/provider-utils");
|
744
|
-
var import_v46 = require("zod/v4");
|
745
|
-
var urlMetadataSchema = import_v46.z.object({
|
746
|
-
retrievedUrl: import_v46.z.string(),
|
747
|
-
urlRetrievalStatus: import_v46.z.string()
|
748
|
-
});
|
749
|
-
var urlContextMetadataSchema = import_v46.z.object({
|
750
|
-
urlMetadata: import_v46.z.array(urlMetadataSchema)
|
751
|
-
});
|
752
|
-
var urlContext = (0, import_provider_utils5.createProviderDefinedToolFactory)({
|
753
|
-
id: "google.url_context",
|
754
|
-
name: "url_context",
|
755
|
-
inputSchema: import_v46.z.object({})
|
756
|
-
});
|
757
|
-
|
758
740
|
// src/google-generative-ai-language-model.ts
|
759
741
|
var GoogleGenerativeAILanguageModel = class {
|
760
742
|
constructor(modelId, config) {
|
@@ -1247,103 +1229,175 @@ function extractSources({
|
|
1247
1229
|
title: chunk.web.title
|
1248
1230
|
}));
|
1249
1231
|
}
|
1250
|
-
var
|
1251
|
-
|
1252
|
-
|
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([
|
1253
1266
|
// note: order matters since text can be fully empty
|
1254
|
-
|
1255
|
-
functionCall:
|
1256
|
-
name:
|
1257
|
-
args:
|
1267
|
+
z5.object({
|
1268
|
+
functionCall: z5.object({
|
1269
|
+
name: z5.string(),
|
1270
|
+
args: z5.unknown()
|
1258
1271
|
}),
|
1259
|
-
thoughtSignature:
|
1272
|
+
thoughtSignature: z5.string().nullish()
|
1260
1273
|
}),
|
1261
|
-
|
1262
|
-
inlineData:
|
1263
|
-
mimeType:
|
1264
|
-
data:
|
1274
|
+
z5.object({
|
1275
|
+
inlineData: z5.object({
|
1276
|
+
mimeType: z5.string(),
|
1277
|
+
data: z5.string()
|
1265
1278
|
})
|
1266
1279
|
}),
|
1267
|
-
|
1268
|
-
executableCode:
|
1269
|
-
language:
|
1270
|
-
code:
|
1280
|
+
z5.object({
|
1281
|
+
executableCode: z5.object({
|
1282
|
+
language: z5.string(),
|
1283
|
+
code: z5.string()
|
1271
1284
|
}).nullish(),
|
1272
|
-
codeExecutionResult:
|
1273
|
-
outcome:
|
1274
|
-
output:
|
1285
|
+
codeExecutionResult: z5.object({
|
1286
|
+
outcome: z5.string(),
|
1287
|
+
output: z5.string()
|
1275
1288
|
}).nullish(),
|
1276
|
-
text:
|
1277
|
-
thought:
|
1278
|
-
thoughtSignature:
|
1289
|
+
text: z5.string().nullish(),
|
1290
|
+
thought: z5.boolean().nullish(),
|
1291
|
+
thoughtSignature: z5.string().nullish()
|
1279
1292
|
})
|
1280
1293
|
])
|
1281
1294
|
).nullish()
|
1282
1295
|
});
|
1283
|
-
var
|
1284
|
-
category:
|
1285
|
-
probability:
|
1286
|
-
probabilityScore:
|
1287
|
-
severity:
|
1288
|
-
severityScore:
|
1289
|
-
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()
|
1290
1303
|
});
|
1291
|
-
var usageSchema =
|
1292
|
-
cachedContentTokenCount:
|
1293
|
-
thoughtsTokenCount:
|
1294
|
-
promptTokenCount:
|
1295
|
-
candidatesTokenCount:
|
1296
|
-
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()
|
1297
1310
|
});
|
1298
|
-
var
|
1299
|
-
|
1300
|
-
|
1301
|
-
|
1302
|
-
|
1303
|
-
safetyRatings: import_v47.z.array(safetyRatingSchema).nullish(),
|
1304
|
-
groundingMetadata: groundingMetadataSchema.nullish(),
|
1305
|
-
urlContextMetadata: urlContextMetadataSchema.nullish()
|
1311
|
+
var getUrlContextMetadataSchema = () => z5.object({
|
1312
|
+
urlMetadata: z5.array(
|
1313
|
+
z5.object({
|
1314
|
+
retrievedUrl: z5.string(),
|
1315
|
+
urlRetrievalStatus: z5.string()
|
1306
1316
|
})
|
1307
|
-
)
|
1308
|
-
usageMetadata: usageSchema.nullish(),
|
1309
|
-
promptFeedback: import_v47.z.object({
|
1310
|
-
blockReason: import_v47.z.string().nullish(),
|
1311
|
-
safetyRatings: import_v47.z.array(safetyRatingSchema).nullish()
|
1312
|
-
}).nullish()
|
1317
|
+
)
|
1313
1318
|
});
|
1314
|
-
var
|
1315
|
-
|
1316
|
-
|
1317
|
-
|
1318
|
-
|
1319
|
-
|
1320
|
-
|
1321
|
-
|
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()
|
1322
1336
|
})
|
1323
|
-
)
|
1324
|
-
|
1325
|
-
|
1326
|
-
|
1327
|
-
|
1328
|
-
|
1329
|
-
|
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
|
+
);
|
1330
1359
|
|
1331
1360
|
// src/tool/code-execution.ts
|
1332
1361
|
var import_provider_utils7 = require("@ai-sdk/provider-utils");
|
1333
|
-
var
|
1362
|
+
var z6 = __toESM(require("zod/v4"));
|
1334
1363
|
var codeExecution = (0, import_provider_utils7.createProviderDefinedToolFactoryWithOutputSchema)({
|
1335
1364
|
id: "google.code_execution",
|
1336
1365
|
name: "code_execution",
|
1337
|
-
inputSchema:
|
1338
|
-
language:
|
1339
|
-
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.")
|
1340
1369
|
}),
|
1341
|
-
outputSchema:
|
1342
|
-
outcome:
|
1343
|
-
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.")
|
1344
1373
|
})
|
1345
1374
|
});
|
1346
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
|
+
|
1347
1401
|
// src/google-tools.ts
|
1348
1402
|
var googleTools = {
|
1349
1403
|
/**
|
@@ -1370,8 +1424,8 @@ var googleTools = {
|
|
1370
1424
|
};
|
1371
1425
|
|
1372
1426
|
// src/google-generative-ai-image-model.ts
|
1373
|
-
var
|
1374
|
-
var
|
1427
|
+
var import_provider_utils10 = require("@ai-sdk/provider-utils");
|
1428
|
+
var z9 = __toESM(require("zod/v4"));
|
1375
1429
|
var GoogleGenerativeAIImageModel = class {
|
1376
1430
|
constructor(modelId, settings, config) {
|
1377
1431
|
this.modelId = modelId;
|
@@ -1413,7 +1467,7 @@ var GoogleGenerativeAIImageModel = class {
|
|
1413
1467
|
details: "This model does not support the `seed` option through this provider."
|
1414
1468
|
});
|
1415
1469
|
}
|
1416
|
-
const googleOptions = await (0,
|
1470
|
+
const googleOptions = await (0, import_provider_utils10.parseProviderOptions)({
|
1417
1471
|
provider: "google",
|
1418
1472
|
providerOptions,
|
1419
1473
|
schema: googleImageProviderOptionsSchema
|
@@ -1432,12 +1486,12 @@ var GoogleGenerativeAIImageModel = class {
|
|
1432
1486
|
instances: [{ prompt }],
|
1433
1487
|
parameters
|
1434
1488
|
};
|
1435
|
-
const { responseHeaders, value: response } = await (0,
|
1489
|
+
const { responseHeaders, value: response } = await (0, import_provider_utils10.postJsonToApi)({
|
1436
1490
|
url: `${this.config.baseURL}/models/${this.modelId}:predict`,
|
1437
|
-
headers: (0,
|
1491
|
+
headers: (0, import_provider_utils10.combineHeaders)(await (0, import_provider_utils10.resolve)(this.config.headers), headers),
|
1438
1492
|
body,
|
1439
1493
|
failedResponseHandler: googleFailedResponseHandler,
|
1440
|
-
successfulResponseHandler: (0,
|
1494
|
+
successfulResponseHandler: (0, import_provider_utils10.createJsonResponseHandler)(
|
1441
1495
|
googleImageResponseSchema
|
1442
1496
|
),
|
1443
1497
|
abortSignal,
|
@@ -1463,21 +1517,29 @@ var GoogleGenerativeAIImageModel = class {
|
|
1463
1517
|
};
|
1464
1518
|
}
|
1465
1519
|
};
|
1466
|
-
var googleImageResponseSchema =
|
1467
|
-
|
1468
|
-
|
1469
|
-
|
1470
|
-
|
1471
|
-
|
1472
|
-
|
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
|
+
);
|
1473
1535
|
|
1474
1536
|
// src/google-provider.ts
|
1475
1537
|
function createGoogleGenerativeAI(options = {}) {
|
1476
1538
|
var _a;
|
1477
|
-
const baseURL = (_a = (0,
|
1478
|
-
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)(
|
1479
1541
|
{
|
1480
|
-
"x-goog-api-key": (0,
|
1542
|
+
"x-goog-api-key": (0, import_provider_utils11.loadApiKey)({
|
1481
1543
|
apiKey: options.apiKey,
|
1482
1544
|
environmentVariableName: "GOOGLE_GENERATIVE_AI_API_KEY",
|
1483
1545
|
description: "Google Generative AI"
|
@@ -1492,7 +1554,7 @@ function createGoogleGenerativeAI(options = {}) {
|
|
1492
1554
|
provider: "google.generative-ai",
|
1493
1555
|
baseURL,
|
1494
1556
|
headers: getHeaders,
|
1495
|
-
generateId: (_a2 = options.generateId) != null ? _a2 :
|
1557
|
+
generateId: (_a2 = options.generateId) != null ? _a2 : import_provider_utils11.generateId,
|
1496
1558
|
supportedUrls: () => ({
|
1497
1559
|
"*": [
|
1498
1560
|
// Google Generative Language "files" endpoint
|