cloudassist-ai-provider 0.0.1 → 0.0.2

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.
Files changed (112) hide show
  1. package/dist/index.d.ts +326 -9
  2. package/dist/index.js +2187 -2
  3. package/dist/index.js.map +1 -1
  4. package/dist/index.mjs +86 -34
  5. package/dist/index.mjs.map +1 -1
  6. package/dist/internal/index.d.ts +262 -4
  7. package/dist/internal/index.js +1850 -2
  8. package/dist/internal/index.js.map +1 -1
  9. package/dist/internal/index.mjs +79 -29
  10. package/dist/internal/index.mjs.map +1 -1
  11. package/package.json +1 -1
  12. package/dist/convert-json-schema-to-openapi-schema.d.ts +0 -6
  13. package/dist/convert-json-schema-to-openapi-schema.d.ts.map +0 -1
  14. package/dist/convert-json-schema-to-openapi-schema.js +0 -108
  15. package/dist/convert-json-schema-to-openapi-schema.test.d.ts +0 -2
  16. package/dist/convert-json-schema-to-openapi-schema.test.d.ts.map +0 -1
  17. package/dist/convert-json-schema-to-openapi-schema.test.js +0 -630
  18. package/dist/convert-to-google-generative-ai-messages.d.ts +0 -7
  19. package/dist/convert-to-google-generative-ai-messages.d.ts.map +0 -1
  20. package/dist/convert-to-google-generative-ai-messages.js +0 -195
  21. package/dist/convert-to-google-generative-ai-messages.test.d.ts +0 -2
  22. package/dist/convert-to-google-generative-ai-messages.test.d.ts.map +0 -1
  23. package/dist/convert-to-google-generative-ai-messages.test.js +0 -456
  24. package/dist/get-model-path.d.ts +0 -2
  25. package/dist/get-model-path.d.ts.map +0 -1
  26. package/dist/get-model-path.js +0 -3
  27. package/dist/get-model-path.test.d.ts +0 -2
  28. package/dist/get-model-path.test.d.ts.map +0 -1
  29. package/dist/get-model-path.test.js +0 -11
  30. package/dist/google-error.d.ts +0 -12
  31. package/dist/google-error.d.ts.map +0 -1
  32. package/dist/google-error.js +0 -13
  33. package/dist/google-generative-ai-embedding-model.d.ts +0 -21
  34. package/dist/google-generative-ai-embedding-model.d.ts.map +0 -1
  35. package/dist/google-generative-ai-embedding-model.js +0 -88
  36. package/dist/google-generative-ai-embedding-model.test.d.ts +0 -2
  37. package/dist/google-generative-ai-embedding-model.test.d.ts.map +0 -1
  38. package/dist/google-generative-ai-embedding-model.test.js +0 -148
  39. package/dist/google-generative-ai-embedding-options.d.ts +0 -8
  40. package/dist/google-generative-ai-embedding-options.d.ts.map +0 -1
  41. package/dist/google-generative-ai-embedding-options.js +0 -33
  42. package/dist/google-generative-ai-image-model.d.ts +0 -31
  43. package/dist/google-generative-ai-image-model.d.ts.map +0 -1
  44. package/dist/google-generative-ai-image-model.js +0 -96
  45. package/dist/google-generative-ai-image-model.test.d.ts +0 -2
  46. package/dist/google-generative-ai-image-model.test.d.ts.map +0 -1
  47. package/dist/google-generative-ai-image-model.test.js +0 -252
  48. package/dist/google-generative-ai-image-settings.d.ts +0 -8
  49. package/dist/google-generative-ai-image-settings.d.ts.map +0 -1
  50. package/dist/google-generative-ai-image-settings.js +0 -1
  51. package/dist/google-generative-ai-language-model.d.ts +0 -183
  52. package/dist/google-generative-ai-language-model.d.ts.map +0 -1
  53. package/dist/google-generative-ai-language-model.js +0 -1001
  54. package/dist/google-generative-ai-language-model.test.d.ts +0 -2
  55. package/dist/google-generative-ai-language-model.test.d.ts.map +0 -1
  56. package/dist/google-generative-ai-language-model.test.js +0 -3463
  57. package/dist/google-generative-ai-options.d.ts +0 -37
  58. package/dist/google-generative-ai-options.d.ts.map +0 -1
  59. package/dist/google-generative-ai-options.js +0 -149
  60. package/dist/google-generative-ai-prompt.d.ts +0 -52
  61. package/dist/google-generative-ai-prompt.d.ts.map +0 -1
  62. package/dist/google-generative-ai-prompt.js +0 -1
  63. package/dist/google-prepare-tools.d.ts +0 -27
  64. package/dist/google-prepare-tools.d.ts.map +0 -1
  65. package/dist/google-prepare-tools.js +0 -219
  66. package/dist/google-prepare-tools.test.d.ts +0 -2
  67. package/dist/google-prepare-tools.test.d.ts.map +0 -1
  68. package/dist/google-prepare-tools.test.js +0 -447
  69. package/dist/google-provider.d.ts +0 -65
  70. package/dist/google-provider.d.ts.map +0 -1
  71. package/dist/google-provider.js +0 -74
  72. package/dist/google-provider.test.d.ts +0 -2
  73. package/dist/google-provider.test.d.ts.map +0 -1
  74. package/dist/google-provider.test.js +0 -234
  75. package/dist/google-supported-file-url.d.ts +0 -2
  76. package/dist/google-supported-file-url.d.ts.map +0 -1
  77. package/dist/google-supported-file-url.js +0 -13
  78. package/dist/google-supported-file-url.test.d.ts +0 -2
  79. package/dist/google-supported-file-url.test.d.ts.map +0 -1
  80. package/dist/google-supported-file-url.test.js +0 -45
  81. package/dist/google-tools.d.ts +0 -76
  82. package/dist/google-tools.d.ts.map +0 -1
  83. package/dist/google-tools.js +0 -65
  84. package/dist/index.d.ts.map +0 -1
  85. package/dist/internal/index.d.ts.map +0 -1
  86. package/dist/map-google-generative-ai-finish-reason.d.ts +0 -6
  87. package/dist/map-google-generative-ai-finish-reason.d.ts.map +0 -1
  88. package/dist/map-google-generative-ai-finish-reason.js +0 -22
  89. package/dist/tool/code-execution.d.ts +0 -17
  90. package/dist/tool/code-execution.d.ts.map +0 -1
  91. package/dist/tool/code-execution.js +0 -25
  92. package/dist/tool/enterprise-web-search.d.ts +0 -2
  93. package/dist/tool/enterprise-web-search.d.ts.map +0 -1
  94. package/dist/tool/enterprise-web-search.js +0 -8
  95. package/dist/tool/file-search.d.ts +0 -16
  96. package/dist/tool/file-search.d.ts.map +0 -1
  97. package/dist/tool/file-search.js +0 -33
  98. package/dist/tool/google-maps.d.ts +0 -2
  99. package/dist/tool/google-maps.d.ts.map +0 -1
  100. package/dist/tool/google-maps.js +0 -9
  101. package/dist/tool/google-search.d.ts +0 -14
  102. package/dist/tool/google-search.d.ts.map +0 -1
  103. package/dist/tool/google-search.js +0 -15
  104. package/dist/tool/url-context.d.ts +0 -2
  105. package/dist/tool/url-context.d.ts.map +0 -1
  106. package/dist/tool/url-context.js +0 -7
  107. package/dist/tool/vertex-rag-store.d.ts +0 -16
  108. package/dist/tool/vertex-rag-store.d.ts.map +0 -1
  109. package/dist/tool/vertex-rag-store.js +0 -17
  110. package/dist/version.d.ts +0 -2
  111. package/dist/version.d.ts.map +0 -1
  112. package/dist/version.js +0 -3
package/dist/index.js CHANGED
@@ -1,2 +1,2187 @@
1
- export { createGoogleGenerativeAI, google } from './google-provider';
2
- export { VERSION } from './version';
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 src_exports = {};
22
+ __export(src_exports, {
23
+ VERSION: () => VERSION,
24
+ createGoogleGenerativeAI: () => createGoogleGenerativeAI,
25
+ google: () => google
26
+ });
27
+ module.exports = __toCommonJS(src_exports);
28
+
29
+ // src/google-provider.ts
30
+ var import_provider_utils15 = require("@ai-sdk/provider-utils");
31
+
32
+ // src/version.ts
33
+ var VERSION = true ? "0.0.1" : "0.0.0-test";
34
+
35
+ // src/google-generative-ai-embedding-model.ts
36
+ var import_provider = require("@ai-sdk/provider");
37
+ var import_provider_utils3 = require("@ai-sdk/provider-utils");
38
+ var import_v43 = require("zod/v4");
39
+
40
+ // src/google-error.ts
41
+ var import_provider_utils = require("@ai-sdk/provider-utils");
42
+ var import_v4 = require("zod/v4");
43
+ var googleErrorDataSchema = (0, import_provider_utils.lazySchema)(
44
+ () => (0, import_provider_utils.zodSchema)(
45
+ import_v4.z.object({
46
+ error: import_v4.z.object({
47
+ code: import_v4.z.number().nullable(),
48
+ message: import_v4.z.string(),
49
+ status: import_v4.z.string()
50
+ })
51
+ })
52
+ )
53
+ );
54
+ var googleFailedResponseHandler = (0, import_provider_utils.createJsonErrorResponseHandler)({
55
+ errorSchema: googleErrorDataSchema,
56
+ errorToMessage: (data) => data.error.message
57
+ });
58
+
59
+ // src/google-generative-ai-embedding-options.ts
60
+ var import_provider_utils2 = require("@ai-sdk/provider-utils");
61
+ var import_v42 = require("zod/v4");
62
+ var googleGenerativeAIEmbeddingProviderOptions = (0, import_provider_utils2.lazySchema)(
63
+ () => (0, import_provider_utils2.zodSchema)(
64
+ import_v42.z.object({
65
+ /**
66
+ * Optional. Optional reduced dimension for the output embedding.
67
+ * If set, excessive values in the output embedding are truncated from the end.
68
+ */
69
+ outputDimensionality: import_v42.z.number().optional(),
70
+ /**
71
+ * Optional. Specifies the task type for generating embeddings.
72
+ * Supported task types:
73
+ * - SEMANTIC_SIMILARITY: Optimized for text similarity.
74
+ * - CLASSIFICATION: Optimized for text classification.
75
+ * - CLUSTERING: Optimized for clustering texts based on similarity.
76
+ * - RETRIEVAL_DOCUMENT: Optimized for document retrieval.
77
+ * - RETRIEVAL_QUERY: Optimized for query-based retrieval.
78
+ * - QUESTION_ANSWERING: Optimized for answering questions.
79
+ * - FACT_VERIFICATION: Optimized for verifying factual information.
80
+ * - CODE_RETRIEVAL_QUERY: Optimized for retrieving code blocks based on natural language queries.
81
+ */
82
+ taskType: import_v42.z.enum([
83
+ "SEMANTIC_SIMILARITY",
84
+ "CLASSIFICATION",
85
+ "CLUSTERING",
86
+ "RETRIEVAL_DOCUMENT",
87
+ "RETRIEVAL_QUERY",
88
+ "QUESTION_ANSWERING",
89
+ "FACT_VERIFICATION",
90
+ "CODE_RETRIEVAL_QUERY"
91
+ ]).optional()
92
+ })
93
+ )
94
+ );
95
+
96
+ // src/provider-key.ts
97
+ var ALLOWED_PROVIDER_KEYS = [
98
+ "antigravity",
99
+ "gemini-cli",
100
+ "cloudassist",
101
+ "google"
102
+ ];
103
+ function getProviderKey(providerOptions) {
104
+ return ALLOWED_PROVIDER_KEYS.find(
105
+ (key) => (providerOptions == null ? void 0 : providerOptions[key]) !== void 0
106
+ );
107
+ }
108
+
109
+ // src/google-generative-ai-embedding-model.ts
110
+ var GoogleGenerativeAIEmbeddingModel = class {
111
+ constructor(modelId, config) {
112
+ this.specificationVersion = "v2";
113
+ this.maxEmbeddingsPerCall = 2048;
114
+ this.supportsParallelCalls = true;
115
+ this.modelId = modelId;
116
+ this.config = config;
117
+ }
118
+ get provider() {
119
+ return this.config.provider;
120
+ }
121
+ async doEmbed({
122
+ values,
123
+ headers,
124
+ abortSignal,
125
+ providerOptions
126
+ }) {
127
+ const providerKey = getProviderKey(providerOptions);
128
+ const googleOptions = await (0, import_provider_utils3.parseProviderOptions)({
129
+ provider: providerKey != null ? providerKey : "google",
130
+ providerOptions,
131
+ schema: googleGenerativeAIEmbeddingProviderOptions
132
+ });
133
+ if (values.length > this.maxEmbeddingsPerCall) {
134
+ throw new import_provider.TooManyEmbeddingValuesForCallError({
135
+ provider: this.provider,
136
+ modelId: this.modelId,
137
+ maxEmbeddingsPerCall: this.maxEmbeddingsPerCall,
138
+ values
139
+ });
140
+ }
141
+ const mergedHeaders = (0, import_provider_utils3.combineHeaders)(
142
+ await (0, import_provider_utils3.resolve)(this.config.headers),
143
+ headers
144
+ );
145
+ if (values.length === 1) {
146
+ const {
147
+ responseHeaders: responseHeaders2,
148
+ value: response2,
149
+ rawValue: rawValue2
150
+ } = await (0, import_provider_utils3.postJsonToApi)({
151
+ url: `${this.config.baseURL}/models/${this.modelId}:embedContent`,
152
+ headers: mergedHeaders,
153
+ body: {
154
+ model: `models/${this.modelId}`,
155
+ content: {
156
+ parts: [{ text: values[0] }]
157
+ },
158
+ outputDimensionality: googleOptions == null ? void 0 : googleOptions.outputDimensionality,
159
+ taskType: googleOptions == null ? void 0 : googleOptions.taskType
160
+ },
161
+ failedResponseHandler: googleFailedResponseHandler,
162
+ successfulResponseHandler: (0, import_provider_utils3.createJsonResponseHandler)(
163
+ googleGenerativeAISingleEmbeddingResponseSchema
164
+ ),
165
+ abortSignal,
166
+ fetch: this.config.fetch
167
+ });
168
+ return {
169
+ embeddings: [response2.embedding.values],
170
+ usage: void 0,
171
+ response: { headers: responseHeaders2, body: rawValue2 }
172
+ };
173
+ }
174
+ const {
175
+ responseHeaders,
176
+ value: response,
177
+ rawValue
178
+ } = await (0, import_provider_utils3.postJsonToApi)({
179
+ url: `${this.config.baseURL}/models/${this.modelId}:batchEmbedContents`,
180
+ headers: mergedHeaders,
181
+ body: {
182
+ requests: values.map((value) => ({
183
+ model: `models/${this.modelId}`,
184
+ content: { role: "user", parts: [{ text: value }] },
185
+ outputDimensionality: googleOptions == null ? void 0 : googleOptions.outputDimensionality,
186
+ taskType: googleOptions == null ? void 0 : googleOptions.taskType
187
+ }))
188
+ },
189
+ failedResponseHandler: googleFailedResponseHandler,
190
+ successfulResponseHandler: (0, import_provider_utils3.createJsonResponseHandler)(
191
+ googleGenerativeAITextEmbeddingResponseSchema
192
+ ),
193
+ abortSignal,
194
+ fetch: this.config.fetch
195
+ });
196
+ return {
197
+ embeddings: response.embeddings.map((item) => item.values),
198
+ usage: void 0,
199
+ response: { headers: responseHeaders, body: rawValue }
200
+ };
201
+ }
202
+ };
203
+ var googleGenerativeAITextEmbeddingResponseSchema = (0, import_provider_utils3.lazySchema)(
204
+ () => (0, import_provider_utils3.zodSchema)(
205
+ import_v43.z.object({
206
+ embeddings: import_v43.z.array(import_v43.z.object({ values: import_v43.z.array(import_v43.z.number()) }))
207
+ })
208
+ )
209
+ );
210
+ var googleGenerativeAISingleEmbeddingResponseSchema = (0, import_provider_utils3.lazySchema)(
211
+ () => (0, import_provider_utils3.zodSchema)(
212
+ import_v43.z.object({
213
+ embedding: import_v43.z.object({ values: import_v43.z.array(import_v43.z.number()) })
214
+ })
215
+ )
216
+ );
217
+
218
+ // src/google-generative-ai-language-model.ts
219
+ var import_provider_utils6 = require("@ai-sdk/provider-utils");
220
+ var import_v45 = require("zod/v4");
221
+
222
+ // src/convert-json-schema-to-openapi-schema.ts
223
+ function convertJSONSchemaToOpenAPISchema(jsonSchema, isRoot = true) {
224
+ if (jsonSchema == null) {
225
+ return void 0;
226
+ }
227
+ if (isEmptyObjectSchema(jsonSchema)) {
228
+ if (isRoot) {
229
+ return void 0;
230
+ }
231
+ if (typeof jsonSchema === "object" && jsonSchema.description) {
232
+ return { type: "object", description: jsonSchema.description };
233
+ }
234
+ return { type: "object" };
235
+ }
236
+ if (typeof jsonSchema === "boolean") {
237
+ return { type: "boolean", properties: {} };
238
+ }
239
+ const {
240
+ type,
241
+ description,
242
+ required,
243
+ properties,
244
+ items,
245
+ allOf,
246
+ anyOf,
247
+ oneOf,
248
+ format,
249
+ const: constValue,
250
+ minLength,
251
+ enum: enumValues
252
+ } = jsonSchema;
253
+ const result = {};
254
+ if (description) result.description = description;
255
+ if (required) result.required = required;
256
+ if (format) result.format = format;
257
+ if (constValue !== void 0) {
258
+ result.enum = [constValue];
259
+ }
260
+ if (type) {
261
+ if (Array.isArray(type)) {
262
+ const hasNull = type.includes("null");
263
+ const nonNullTypes = type.filter((t) => t !== "null");
264
+ if (nonNullTypes.length === 0) {
265
+ result.type = "null";
266
+ } else {
267
+ result.anyOf = nonNullTypes.map((t) => ({ type: t }));
268
+ if (hasNull) {
269
+ result.nullable = true;
270
+ }
271
+ }
272
+ } else {
273
+ result.type = type;
274
+ }
275
+ }
276
+ if (enumValues !== void 0) {
277
+ result.enum = enumValues;
278
+ }
279
+ if (properties != null) {
280
+ result.properties = Object.entries(properties).reduce(
281
+ (acc, [key, value]) => {
282
+ acc[key] = convertJSONSchemaToOpenAPISchema(value, false);
283
+ return acc;
284
+ },
285
+ {}
286
+ );
287
+ }
288
+ if (items) {
289
+ result.items = Array.isArray(items) ? items.map((item) => convertJSONSchemaToOpenAPISchema(item, false)) : convertJSONSchemaToOpenAPISchema(items, false);
290
+ }
291
+ if (allOf) {
292
+ result.allOf = allOf.map(
293
+ (item) => convertJSONSchemaToOpenAPISchema(item, false)
294
+ );
295
+ }
296
+ if (anyOf) {
297
+ if (anyOf.some(
298
+ (schema) => typeof schema === "object" && (schema == null ? void 0 : schema.type) === "null"
299
+ )) {
300
+ const nonNullSchemas = anyOf.filter(
301
+ (schema) => !(typeof schema === "object" && (schema == null ? void 0 : schema.type) === "null")
302
+ );
303
+ if (nonNullSchemas.length === 1) {
304
+ const converted = convertJSONSchemaToOpenAPISchema(
305
+ nonNullSchemas[0],
306
+ false
307
+ );
308
+ if (typeof converted === "object") {
309
+ result.nullable = true;
310
+ Object.assign(result, converted);
311
+ }
312
+ } else {
313
+ result.anyOf = nonNullSchemas.map(
314
+ (item) => convertJSONSchemaToOpenAPISchema(item, false)
315
+ );
316
+ result.nullable = true;
317
+ }
318
+ } else {
319
+ result.anyOf = anyOf.map(
320
+ (item) => convertJSONSchemaToOpenAPISchema(item, false)
321
+ );
322
+ }
323
+ }
324
+ if (oneOf) {
325
+ result.oneOf = oneOf.map(
326
+ (item) => convertJSONSchemaToOpenAPISchema(item, false)
327
+ );
328
+ }
329
+ if (minLength !== void 0) {
330
+ result.minLength = minLength;
331
+ }
332
+ return result;
333
+ }
334
+ function isEmptyObjectSchema(jsonSchema) {
335
+ return jsonSchema != null && typeof jsonSchema === "object" && jsonSchema.type === "object" && (jsonSchema.properties == null || Object.keys(jsonSchema.properties).length === 0) && !jsonSchema.additionalProperties;
336
+ }
337
+
338
+ // src/convert-to-google-generative-ai-messages.ts
339
+ var import_provider3 = require("@ai-sdk/provider");
340
+ var import_provider_utils4 = require("@ai-sdk/provider-utils");
341
+
342
+ // src/google-prepare-tools.ts
343
+ var import_provider2 = require("@ai-sdk/provider");
344
+ function isClaudeModel(modelId) {
345
+ return modelId.toLowerCase().startsWith("claude-");
346
+ }
347
+ function prepareTools({
348
+ tools,
349
+ toolChoice,
350
+ modelId
351
+ }) {
352
+ var _a;
353
+ tools = (tools == null ? void 0 : tools.length) ? tools : void 0;
354
+ const toolWarnings = [];
355
+ const isLatest = [
356
+ "gemini-flash-latest",
357
+ "gemini-flash-lite-latest",
358
+ "gemini-pro-latest"
359
+ ].some((id) => id === modelId);
360
+ const isGemini2orNewer = modelId.includes("gemini-2") || modelId.includes("gemini-3") || isLatest;
361
+ const supportsDynamicRetrieval = modelId.includes("gemini-1.5-flash") && !modelId.includes("-8b");
362
+ const supportsFileSearch = modelId.includes("gemini-2.5");
363
+ if (tools == null) {
364
+ return { tools: void 0, toolConfig: void 0, toolWarnings };
365
+ }
366
+ const hasFunctionTools = tools.some((tool) => tool.type === "function");
367
+ const hasProviderDefinedTools = tools.some(
368
+ (tool) => tool.type === "provider-defined"
369
+ );
370
+ if (hasFunctionTools && hasProviderDefinedTools) {
371
+ const functionTools = tools.filter((tool) => tool.type === "function");
372
+ toolWarnings.push({
373
+ type: "unsupported-tool",
374
+ tool: tools.find((tool) => tool.type === "function"),
375
+ details: `Cannot mix function tools with provider-defined tools in the same request. Falling back to provider-defined tools only. The following function tools will be ignored: ${functionTools.map((t) => t.name).join(", ")}. Please use either function tools or provider-defined tools, but not both.`
376
+ });
377
+ }
378
+ if (hasProviderDefinedTools) {
379
+ const googleTools2 = [];
380
+ const providerDefinedTools = tools.filter(
381
+ (tool) => tool.type === "provider-defined"
382
+ );
383
+ providerDefinedTools.forEach((tool) => {
384
+ switch (tool.id) {
385
+ case "google.google_search":
386
+ if (isGemini2orNewer) {
387
+ googleTools2.push({ googleSearch: {} });
388
+ } else if (supportsDynamicRetrieval) {
389
+ googleTools2.push({
390
+ googleSearchRetrieval: {
391
+ dynamicRetrievalConfig: {
392
+ mode: tool.args.mode,
393
+ dynamicThreshold: tool.args.dynamicThreshold
394
+ }
395
+ }
396
+ });
397
+ } else {
398
+ googleTools2.push({ googleSearchRetrieval: {} });
399
+ }
400
+ break;
401
+ case "google.enterprise_web_search":
402
+ if (isGemini2orNewer) {
403
+ googleTools2.push({ enterpriseWebSearch: {} });
404
+ } else {
405
+ toolWarnings.push({
406
+ type: "unsupported-tool",
407
+ tool,
408
+ details: "Enterprise Web Search requires Gemini 2.0 or newer."
409
+ });
410
+ }
411
+ break;
412
+ case "google.url_context":
413
+ if (isGemini2orNewer) {
414
+ googleTools2.push({ urlContext: {} });
415
+ } else {
416
+ toolWarnings.push({
417
+ type: "unsupported-tool",
418
+ tool,
419
+ details: "The URL context tool is not supported with other Gemini models than Gemini 2."
420
+ });
421
+ }
422
+ break;
423
+ case "google.code_execution":
424
+ if (isGemini2orNewer) {
425
+ googleTools2.push({ codeExecution: {} });
426
+ } else {
427
+ toolWarnings.push({
428
+ type: "unsupported-tool",
429
+ tool,
430
+ details: "The code execution tools is not supported with other Gemini models than Gemini 2."
431
+ });
432
+ }
433
+ break;
434
+ case "google.file_search":
435
+ if (supportsFileSearch) {
436
+ googleTools2.push({ fileSearch: { ...tool.args } });
437
+ } else {
438
+ toolWarnings.push({
439
+ type: "unsupported-tool",
440
+ tool,
441
+ details: "The file search tool is only supported with Gemini 2.5 models."
442
+ });
443
+ }
444
+ break;
445
+ case "google.vertex_rag_store":
446
+ if (isGemini2orNewer) {
447
+ googleTools2.push({
448
+ retrieval: {
449
+ vertex_rag_store: {
450
+ rag_resources: {
451
+ rag_corpus: tool.args.ragCorpus
452
+ },
453
+ similarity_top_k: tool.args.topK
454
+ }
455
+ }
456
+ });
457
+ } else {
458
+ toolWarnings.push({
459
+ type: "unsupported-tool",
460
+ tool,
461
+ details: "The RAG store tool is not supported with other Gemini models than Gemini 2."
462
+ });
463
+ }
464
+ break;
465
+ case "google.google_maps":
466
+ if (isGemini2orNewer) {
467
+ googleTools2.push({ googleMaps: {} });
468
+ } else {
469
+ toolWarnings.push({
470
+ type: "unsupported-tool",
471
+ tool,
472
+ details: "The Google Maps grounding tool is not supported with Gemini models other than Gemini 2 or newer."
473
+ });
474
+ }
475
+ break;
476
+ default:
477
+ toolWarnings.push({ type: "unsupported-tool", tool });
478
+ break;
479
+ }
480
+ });
481
+ return {
482
+ tools: googleTools2.length > 0 ? googleTools2 : void 0,
483
+ toolConfig: void 0,
484
+ toolWarnings
485
+ };
486
+ }
487
+ const functionDeclarations = [];
488
+ for (const tool of tools) {
489
+ switch (tool.type) {
490
+ case "function": {
491
+ let parameters = convertJSONSchemaToOpenAPISchema(tool.inputSchema);
492
+ if (isClaudeModel(modelId) && !parameters) {
493
+ parameters = { type: "object", properties: {} };
494
+ }
495
+ functionDeclarations.push({
496
+ name: tool.name,
497
+ description: (_a = tool.description) != null ? _a : "",
498
+ parameters
499
+ });
500
+ break;
501
+ }
502
+ default:
503
+ toolWarnings.push({ type: "unsupported-tool", tool });
504
+ break;
505
+ }
506
+ }
507
+ if (toolChoice == null) {
508
+ return {
509
+ tools: [{ functionDeclarations }],
510
+ toolConfig: void 0,
511
+ toolWarnings
512
+ };
513
+ }
514
+ const type = toolChoice.type;
515
+ switch (type) {
516
+ case "auto":
517
+ return {
518
+ tools: [{ functionDeclarations }],
519
+ toolConfig: { functionCallingConfig: { mode: "AUTO" } },
520
+ toolWarnings
521
+ };
522
+ case "none":
523
+ return {
524
+ tools: [{ functionDeclarations }],
525
+ toolConfig: { functionCallingConfig: { mode: "NONE" } },
526
+ toolWarnings
527
+ };
528
+ case "required":
529
+ return {
530
+ tools: [{ functionDeclarations }],
531
+ toolConfig: { functionCallingConfig: { mode: "ANY" } },
532
+ toolWarnings
533
+ };
534
+ case "tool":
535
+ return {
536
+ tools: [{ functionDeclarations }],
537
+ toolConfig: {
538
+ functionCallingConfig: {
539
+ mode: "ANY",
540
+ allowedFunctionNames: [toolChoice.toolName]
541
+ }
542
+ },
543
+ toolWarnings
544
+ };
545
+ default: {
546
+ const _exhaustiveCheck = type;
547
+ throw new import_provider2.UnsupportedFunctionalityError({
548
+ functionality: `tool choice type: ${_exhaustiveCheck}`
549
+ });
550
+ }
551
+ }
552
+ }
553
+
554
+ // src/convert-to-google-generative-ai-messages.ts
555
+ function convertToGoogleGenerativeAIMessages(prompt, options) {
556
+ var _a, _b, _c;
557
+ const systemInstructionParts = [];
558
+ const contents = [];
559
+ let systemMessagesAllowed = true;
560
+ const isGemmaModel = (_a = options == null ? void 0 : options.isGemmaModel) != null ? _a : false;
561
+ const modelId = (_b = options == null ? void 0 : options.modelId) != null ? _b : "";
562
+ const includeToolCallId = isClaudeModel(modelId);
563
+ const providerKey = (_c = options == null ? void 0 : options.providerKey) != null ? _c : "google";
564
+ for (const { role, content } of prompt) {
565
+ switch (role) {
566
+ case "system": {
567
+ if (!systemMessagesAllowed) {
568
+ throw new import_provider3.UnsupportedFunctionalityError({
569
+ functionality: "system messages are only supported at the beginning of the conversation"
570
+ });
571
+ }
572
+ systemInstructionParts.push({ text: content });
573
+ break;
574
+ }
575
+ case "user": {
576
+ systemMessagesAllowed = false;
577
+ const parts = [];
578
+ for (const part of content) {
579
+ switch (part.type) {
580
+ case "text": {
581
+ parts.push({ text: part.text });
582
+ break;
583
+ }
584
+ case "file": {
585
+ const mediaType = part.mediaType === "image/*" ? "image/jpeg" : part.mediaType;
586
+ parts.push(
587
+ part.data instanceof URL ? {
588
+ fileData: {
589
+ mimeType: mediaType,
590
+ fileUri: part.data.toString()
591
+ }
592
+ } : {
593
+ inlineData: {
594
+ mimeType: mediaType,
595
+ data: (0, import_provider_utils4.convertToBase64)(part.data)
596
+ }
597
+ }
598
+ );
599
+ break;
600
+ }
601
+ }
602
+ }
603
+ contents.push({ role: "user", parts });
604
+ break;
605
+ }
606
+ case "assistant": {
607
+ systemMessagesAllowed = false;
608
+ contents.push({
609
+ role: "model",
610
+ parts: content.map((part) => {
611
+ var _a2, _b2, _c2;
612
+ const thoughtSignature = ((_b2 = (_a2 = part.providerOptions) == null ? void 0 : _a2[providerKey]) == null ? void 0 : _b2.thoughtSignature) != null ? String((_c2 = part.providerOptions[providerKey]) == null ? void 0 : _c2.thoughtSignature) : void 0;
613
+ switch (part.type) {
614
+ case "text": {
615
+ return part.text.length === 0 ? void 0 : {
616
+ text: part.text,
617
+ thoughtSignature
618
+ };
619
+ }
620
+ case "reasoning": {
621
+ return part.text.length === 0 ? void 0 : {
622
+ text: part.text,
623
+ thought: true,
624
+ thoughtSignature
625
+ };
626
+ }
627
+ case "file": {
628
+ if (part.mediaType !== "image/png") {
629
+ throw new import_provider3.UnsupportedFunctionalityError({
630
+ functionality: "Only PNG images are supported in assistant messages"
631
+ });
632
+ }
633
+ if (part.data instanceof URL) {
634
+ throw new import_provider3.UnsupportedFunctionalityError({
635
+ functionality: "File data URLs in assistant messages are not supported"
636
+ });
637
+ }
638
+ return {
639
+ inlineData: {
640
+ mimeType: part.mediaType,
641
+ data: (0, import_provider_utils4.convertToBase64)(part.data)
642
+ }
643
+ };
644
+ }
645
+ case "tool-call": {
646
+ return {
647
+ functionCall: {
648
+ name: part.toolName,
649
+ args: part.input,
650
+ ...includeToolCallId && part.toolCallId ? { id: part.toolCallId } : {}
651
+ },
652
+ thoughtSignature
653
+ };
654
+ }
655
+ }
656
+ }).filter((part) => part !== void 0)
657
+ });
658
+ break;
659
+ }
660
+ case "tool": {
661
+ systemMessagesAllowed = false;
662
+ const parts = [];
663
+ for (const part of content) {
664
+ const output = part.output;
665
+ if (output.type === "content") {
666
+ for (const contentPart of output.value) {
667
+ switch (contentPart.type) {
668
+ case "text":
669
+ parts.push({
670
+ functionResponse: {
671
+ name: part.toolName,
672
+ response: {
673
+ name: part.toolName,
674
+ content: contentPart.text
675
+ },
676
+ ...includeToolCallId && part.toolCallId ? { id: part.toolCallId } : {}
677
+ }
678
+ });
679
+ break;
680
+ case "media":
681
+ parts.push(
682
+ {
683
+ inlineData: {
684
+ mimeType: contentPart.mediaType,
685
+ data: contentPart.data
686
+ }
687
+ },
688
+ {
689
+ text: "Tool executed successfully and returned this image as a response"
690
+ }
691
+ );
692
+ break;
693
+ default:
694
+ parts.push({ text: JSON.stringify(contentPart) });
695
+ break;
696
+ }
697
+ }
698
+ } else {
699
+ parts.push({
700
+ functionResponse: {
701
+ name: part.toolName,
702
+ response: {
703
+ name: part.toolName,
704
+ content: output.value
705
+ },
706
+ ...includeToolCallId && part.toolCallId ? { id: part.toolCallId } : {}
707
+ }
708
+ });
709
+ }
710
+ }
711
+ contents.push({
712
+ role: "user",
713
+ parts
714
+ });
715
+ break;
716
+ }
717
+ }
718
+ }
719
+ if (isGemmaModel && systemInstructionParts.length > 0 && contents.length > 0 && contents[0].role === "user") {
720
+ const systemText = systemInstructionParts.map((part) => part.text).join("\n\n");
721
+ contents[0].parts.unshift({ text: systemText + "\n\n" });
722
+ }
723
+ return {
724
+ systemInstruction: systemInstructionParts.length > 0 && !isGemmaModel ? { parts: systemInstructionParts } : void 0,
725
+ contents
726
+ };
727
+ }
728
+
729
+ // src/google-generative-ai-options.ts
730
+ var import_provider_utils5 = require("@ai-sdk/provider-utils");
731
+ var import_v44 = require("zod/v4");
732
+ var googleGenerativeAIProviderOptions = (0, import_provider_utils5.lazySchema)(
733
+ () => (0, import_provider_utils5.zodSchema)(
734
+ import_v44.z.object({
735
+ responseModalities: import_v44.z.array(import_v44.z.enum(["TEXT", "IMAGE"])).optional(),
736
+ thinkingConfig: import_v44.z.object({
737
+ thinkingBudget: import_v44.z.number().optional(),
738
+ includeThoughts: import_v44.z.boolean().optional(),
739
+ // https://ai.google.dev/gemini-api/docs/gemini-3?thinking=high#thinking_level
740
+ thinkingLevel: import_v44.z.enum(["minimal", "low", "medium", "high"]).optional()
741
+ }).optional(),
742
+ /**
743
+ * Optional.
744
+ * The name of the cached content used as context to serve the prediction.
745
+ * Format: cachedContents/{cachedContent}
746
+ */
747
+ cachedContent: import_v44.z.string().optional(),
748
+ /**
749
+ * Optional. Enable structured output. Default is true.
750
+ *
751
+ * This is useful when the JSON Schema contains elements that are
752
+ * not supported by the OpenAPI schema version that
753
+ * Google Generative AI uses. You can use this to disable
754
+ * structured outputs if you need to.
755
+ */
756
+ structuredOutputs: import_v44.z.boolean().optional(),
757
+ /**
758
+ * Optional. A list of unique safety settings for blocking unsafe content.
759
+ */
760
+ safetySettings: import_v44.z.array(
761
+ import_v44.z.object({
762
+ category: import_v44.z.enum([
763
+ "HARM_CATEGORY_UNSPECIFIED",
764
+ "HARM_CATEGORY_HATE_SPEECH",
765
+ "HARM_CATEGORY_DANGEROUS_CONTENT",
766
+ "HARM_CATEGORY_HARASSMENT",
767
+ "HARM_CATEGORY_SEXUALLY_EXPLICIT",
768
+ "HARM_CATEGORY_CIVIC_INTEGRITY"
769
+ ]),
770
+ threshold: import_v44.z.enum([
771
+ "HARM_BLOCK_THRESHOLD_UNSPECIFIED",
772
+ "BLOCK_LOW_AND_ABOVE",
773
+ "BLOCK_MEDIUM_AND_ABOVE",
774
+ "BLOCK_ONLY_HIGH",
775
+ "BLOCK_NONE",
776
+ "OFF"
777
+ ])
778
+ })
779
+ ).optional(),
780
+ threshold: import_v44.z.enum([
781
+ "HARM_BLOCK_THRESHOLD_UNSPECIFIED",
782
+ "BLOCK_LOW_AND_ABOVE",
783
+ "BLOCK_MEDIUM_AND_ABOVE",
784
+ "BLOCK_ONLY_HIGH",
785
+ "BLOCK_NONE",
786
+ "OFF"
787
+ ]).optional(),
788
+ /**
789
+ * Optional. Enables timestamp understanding for audio-only files.
790
+ *
791
+ * https://cloud.google.com/vertex-ai/generative-ai/docs/multimodal/audio-understanding
792
+ */
793
+ audioTimestamp: import_v44.z.boolean().optional(),
794
+ /**
795
+ * Optional. Defines labels used in billing reports. Available on Vertex AI only.
796
+ *
797
+ * https://cloud.google.com/vertex-ai/generative-ai/docs/multimodal/add-labels-to-api-calls
798
+ */
799
+ labels: import_v44.z.record(import_v44.z.string(), import_v44.z.string()).optional(),
800
+ /**
801
+ * Optional. If specified, the media resolution specified will be used.
802
+ *
803
+ * https://ai.google.dev/api/generate-content#MediaResolution
804
+ */
805
+ mediaResolution: import_v44.z.enum([
806
+ "MEDIA_RESOLUTION_UNSPECIFIED",
807
+ "MEDIA_RESOLUTION_LOW",
808
+ "MEDIA_RESOLUTION_MEDIUM",
809
+ "MEDIA_RESOLUTION_HIGH"
810
+ ]).optional(),
811
+ /**
812
+ * Optional. Configures the image generation aspect ratio for Gemini models.
813
+ *
814
+ * https://ai.google.dev/gemini-api/docs/image-generation#aspect_ratios
815
+ */
816
+ imageConfig: import_v44.z.object({
817
+ aspectRatio: import_v44.z.enum([
818
+ "1:1",
819
+ "2:3",
820
+ "3:2",
821
+ "3:4",
822
+ "4:3",
823
+ "4:5",
824
+ "5:4",
825
+ "9:16",
826
+ "16:9",
827
+ "21:9"
828
+ ]).optional(),
829
+ imageSize: import_v44.z.enum(["1K", "2K", "4K"]).optional()
830
+ }).optional(),
831
+ /**
832
+ * Optional. Configuration for grounding retrieval.
833
+ * Used to provide location context for Google Maps and Google Search grounding.
834
+ *
835
+ * https://cloud.google.com/vertex-ai/generative-ai/docs/grounding/grounding-with-google-maps
836
+ */
837
+ retrievalConfig: import_v44.z.object({
838
+ latLng: import_v44.z.object({
839
+ latitude: import_v44.z.number(),
840
+ longitude: import_v44.z.number()
841
+ }).optional()
842
+ }).optional(),
843
+ // Cloud Assist specific options
844
+ /**
845
+ * Required for Cloud Assist. The Google Cloud project ID.
846
+ */
847
+ projectId: import_v44.z.string().optional(),
848
+ /**
849
+ * Optional. Session ID for conversation continuity.
850
+ */
851
+ sessionId: import_v44.z.string().optional(),
852
+ /**
853
+ * Optional. Request type (e.g., "agent").
854
+ */
855
+ requestType: import_v44.z.string().optional(),
856
+ /**
857
+ * Required for Cloud Assist. User agent identifier.
858
+ */
859
+ userAgent: import_v44.z.string().optional(),
860
+ /**
861
+ * Optional. Custom request ID. If not provided, one will be generated.
862
+ */
863
+ requestId: import_v44.z.string().optional()
864
+ })
865
+ )
866
+ );
867
+
868
+ // src/map-google-generative-ai-finish-reason.ts
869
+ function mapGoogleGenerativeAIFinishReason({
870
+ finishReason,
871
+ hasToolCalls
872
+ }) {
873
+ switch (finishReason) {
874
+ case "STOP":
875
+ return hasToolCalls ? "tool-calls" : "stop";
876
+ case "MAX_TOKENS":
877
+ return "length";
878
+ case "IMAGE_SAFETY":
879
+ case "RECITATION":
880
+ case "SAFETY":
881
+ case "BLOCKLIST":
882
+ case "PROHIBITED_CONTENT":
883
+ case "SPII":
884
+ return "content-filter";
885
+ case "FINISH_REASON_UNSPECIFIED":
886
+ case "OTHER":
887
+ return "other";
888
+ case "MALFORMED_FUNCTION_CALL":
889
+ return "error";
890
+ default:
891
+ return "unknown";
892
+ }
893
+ }
894
+
895
+ // src/google-generative-ai-language-model.ts
896
+ var GoogleGenerativeAILanguageModel = class {
897
+ constructor(modelId, config) {
898
+ this.specificationVersion = "v2";
899
+ var _a;
900
+ this.modelId = modelId;
901
+ this.config = config;
902
+ this.generateId = (_a = config.generateId) != null ? _a : import_provider_utils6.generateId;
903
+ }
904
+ get provider() {
905
+ return this.config.provider;
906
+ }
907
+ get supportedUrls() {
908
+ var _a, _b, _c;
909
+ return (_c = (_b = (_a = this.config).supportedUrls) == null ? void 0 : _b.call(_a)) != null ? _c : {};
910
+ }
911
+ async getArgs({
912
+ prompt,
913
+ maxOutputTokens,
914
+ temperature,
915
+ topP,
916
+ topK,
917
+ frequencyPenalty,
918
+ presencePenalty,
919
+ stopSequences,
920
+ responseFormat,
921
+ seed,
922
+ tools,
923
+ toolChoice,
924
+ providerOptions
925
+ }) {
926
+ var _a;
927
+ const warnings = [];
928
+ const providerKey = getProviderKey(providerOptions);
929
+ const googleOptions = await (0, import_provider_utils6.parseProviderOptions)({
930
+ provider: providerKey != null ? providerKey : "google",
931
+ providerOptions,
932
+ schema: googleGenerativeAIProviderOptions
933
+ });
934
+ if ((tools == null ? void 0 : tools.some(
935
+ (tool) => tool.type === "provider-defined" && tool.id === "google.vertex_rag_store"
936
+ )) && !this.config.provider.startsWith("google.vertex.")) {
937
+ warnings.push({
938
+ type: "other",
939
+ message: `The 'vertex_rag_store' tool is only supported with the Google Vertex provider and might not be supported or could behave unexpectedly with the current Google provider (${this.config.provider}).`
940
+ });
941
+ }
942
+ const isGemmaModel = this.modelId.toLowerCase().startsWith("gemma-");
943
+ const { contents, systemInstruction } = convertToGoogleGenerativeAIMessages(
944
+ prompt,
945
+ { isGemmaModel, modelId: this.modelId, providerKey }
946
+ );
947
+ const {
948
+ tools: googleTools2,
949
+ toolConfig: googleToolConfig,
950
+ toolWarnings
951
+ } = prepareTools({
952
+ tools,
953
+ toolChoice,
954
+ modelId: this.modelId
955
+ });
956
+ return {
957
+ args: {
958
+ generationConfig: {
959
+ // standardized settings:
960
+ maxOutputTokens,
961
+ temperature,
962
+ topK,
963
+ topP,
964
+ frequencyPenalty,
965
+ presencePenalty,
966
+ stopSequences,
967
+ seed,
968
+ // response format:
969
+ responseMimeType: (responseFormat == null ? void 0 : responseFormat.type) === "json" ? "application/json" : void 0,
970
+ responseSchema: (responseFormat == null ? void 0 : responseFormat.type) === "json" && responseFormat.schema != null && // Google GenAI does not support all OpenAPI Schema features,
971
+ // so this is needed as an escape hatch:
972
+ // TODO convert into provider option
973
+ ((_a = googleOptions == null ? void 0 : googleOptions.structuredOutputs) != null ? _a : true) ? convertJSONSchemaToOpenAPISchema(responseFormat.schema) : void 0,
974
+ ...(googleOptions == null ? void 0 : googleOptions.audioTimestamp) && {
975
+ audioTimestamp: googleOptions.audioTimestamp
976
+ },
977
+ // provider options:
978
+ responseModalities: googleOptions == null ? void 0 : googleOptions.responseModalities,
979
+ thinkingConfig: googleOptions == null ? void 0 : googleOptions.thinkingConfig,
980
+ ...(googleOptions == null ? void 0 : googleOptions.imageConfig) && {
981
+ imageConfig: googleOptions.imageConfig
982
+ },
983
+ ...(googleOptions == null ? void 0 : googleOptions.mediaResolution) && {
984
+ mediaResolution: googleOptions.mediaResolution
985
+ }
986
+ },
987
+ contents,
988
+ systemInstruction: isGemmaModel ? void 0 : systemInstruction,
989
+ safetySettings: googleOptions == null ? void 0 : googleOptions.safetySettings,
990
+ tools: googleTools2,
991
+ toolConfig: (googleOptions == null ? void 0 : googleOptions.retrievalConfig) ? {
992
+ ...googleToolConfig,
993
+ retrievalConfig: googleOptions.retrievalConfig
994
+ } : googleToolConfig,
995
+ cachedContent: googleOptions == null ? void 0 : googleOptions.cachedContent,
996
+ labels: googleOptions == null ? void 0 : googleOptions.labels,
997
+ // Cloud Assist: sessionId goes inside the request
998
+ ...(googleOptions == null ? void 0 : googleOptions.sessionId) && { sessionId: googleOptions.sessionId }
999
+ },
1000
+ warnings: [...warnings, ...toolWarnings],
1001
+ // Cloud Assist specific options (used to wrap the request)
1002
+ cloudAssistOptions: {
1003
+ projectId: googleOptions == null ? void 0 : googleOptions.projectId,
1004
+ requestType: googleOptions == null ? void 0 : googleOptions.requestType,
1005
+ userAgent: googleOptions == null ? void 0 : googleOptions.userAgent,
1006
+ requestId: googleOptions == null ? void 0 : googleOptions.requestId
1007
+ },
1008
+ providerKey
1009
+ };
1010
+ }
1011
+ async doGenerate(options) {
1012
+ var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m;
1013
+ const { args, warnings, cloudAssistOptions, providerKey } = await this.getArgs(options);
1014
+ const wrappedRequest = {
1015
+ project: cloudAssistOptions.projectId,
1016
+ model: this.modelId,
1017
+ request: args,
1018
+ ...cloudAssistOptions.requestType && {
1019
+ requestType: cloudAssistOptions.requestType
1020
+ },
1021
+ userAgent: (_a = cloudAssistOptions.userAgent) != null ? _a : "ai-sdk",
1022
+ requestId: (_b = cloudAssistOptions.requestId) != null ? _b : `ai-sdk-${Date.now()}-${Math.random().toString(36).slice(2, 11)}`
1023
+ };
1024
+ const body = JSON.stringify(wrappedRequest);
1025
+ const mergedHeaders = (0, import_provider_utils6.combineHeaders)(
1026
+ await (0, import_provider_utils6.resolve)(this.config.headers),
1027
+ options.headers
1028
+ );
1029
+ const { responseHeaders, value: response } = await (0, import_provider_utils6.postJsonToApi)({
1030
+ url: `${this.config.baseURL}/v1internal:streamGenerateContent?alt=sse`,
1031
+ headers: mergedHeaders,
1032
+ body: wrappedRequest,
1033
+ failedResponseHandler: googleFailedResponseHandler,
1034
+ successfulResponseHandler: (0, import_provider_utils6.createEventSourceResponseHandler)(chunkSchema),
1035
+ abortSignal: options.abortSignal,
1036
+ fetch: this.config.fetch
1037
+ });
1038
+ const content = [];
1039
+ let finishReason = "unknown";
1040
+ let usageMetadata;
1041
+ let promptFeedback;
1042
+ let groundingMetadata;
1043
+ let urlContextMetadata;
1044
+ let safetyRatings;
1045
+ let currentTextContent = "";
1046
+ let currentTextThoughtSignature;
1047
+ let currentReasoningContent = "";
1048
+ let currentReasoningThoughtSignature;
1049
+ let isInReasoning = false;
1050
+ let lastCodeExecutionToolCallId;
1051
+ const useToolCallId = isClaudeModel(this.modelId);
1052
+ const reader = response.getReader();
1053
+ try {
1054
+ while (true) {
1055
+ const { done, value: chunk } = await reader.read();
1056
+ if (done) break;
1057
+ if (!chunk.success) continue;
1058
+ const value = chunk.value;
1059
+ const responseData = (_c = value.response) != null ? _c : value;
1060
+ if (responseData.usageMetadata) {
1061
+ usageMetadata = responseData.usageMetadata;
1062
+ }
1063
+ if (responseData.promptFeedback) {
1064
+ promptFeedback = responseData.promptFeedback;
1065
+ }
1066
+ const candidate = (_d = responseData.candidates) == null ? void 0 : _d[0];
1067
+ if (!candidate) continue;
1068
+ if (candidate.groundingMetadata) {
1069
+ groundingMetadata = candidate.groundingMetadata;
1070
+ }
1071
+ if (candidate.urlContextMetadata) {
1072
+ urlContextMetadata = candidate.urlContextMetadata;
1073
+ }
1074
+ if (candidate.safetyRatings) {
1075
+ safetyRatings = candidate.safetyRatings;
1076
+ }
1077
+ const parts = (_f = (_e = candidate.content) == null ? void 0 : _e.parts) != null ? _f : [];
1078
+ for (const part of parts) {
1079
+ if ("executableCode" in part && ((_g = part.executableCode) == null ? void 0 : _g.code)) {
1080
+ if (currentTextContent) {
1081
+ content.push({
1082
+ type: "text",
1083
+ text: currentTextContent,
1084
+ providerMetadata: currentTextThoughtSignature ? {
1085
+ [providerKey != null ? providerKey : "google"]: {
1086
+ thoughtSignature: currentTextThoughtSignature
1087
+ }
1088
+ } : void 0
1089
+ });
1090
+ currentTextContent = "";
1091
+ currentTextThoughtSignature = void 0;
1092
+ }
1093
+ if (currentReasoningContent) {
1094
+ content.push({
1095
+ type: "reasoning",
1096
+ text: currentReasoningContent,
1097
+ providerMetadata: currentReasoningThoughtSignature ? {
1098
+ [providerKey != null ? providerKey : "google"]: {
1099
+ thoughtSignature: currentReasoningThoughtSignature
1100
+ }
1101
+ } : void 0
1102
+ });
1103
+ currentReasoningContent = "";
1104
+ currentReasoningThoughtSignature = void 0;
1105
+ }
1106
+ const toolCallId = this.config.generateId();
1107
+ lastCodeExecutionToolCallId = toolCallId;
1108
+ content.push({
1109
+ type: "tool-call",
1110
+ toolCallId,
1111
+ toolName: "code_execution",
1112
+ input: JSON.stringify(part.executableCode),
1113
+ providerExecuted: true
1114
+ });
1115
+ } else if ("codeExecutionResult" in part && part.codeExecutionResult) {
1116
+ content.push({
1117
+ type: "tool-result",
1118
+ toolCallId: lastCodeExecutionToolCallId,
1119
+ toolName: "code_execution",
1120
+ result: {
1121
+ outcome: part.codeExecutionResult.outcome,
1122
+ output: part.codeExecutionResult.output
1123
+ },
1124
+ providerExecuted: true
1125
+ });
1126
+ lastCodeExecutionToolCallId = void 0;
1127
+ } else if ("text" in part && part.text != null) {
1128
+ const isThinking = part.thought === true;
1129
+ if (isThinking) {
1130
+ if (!isInReasoning && currentTextContent) {
1131
+ content.push({
1132
+ type: "text",
1133
+ text: currentTextContent,
1134
+ providerMetadata: currentTextThoughtSignature ? {
1135
+ [providerKey != null ? providerKey : "google"]: {
1136
+ thoughtSignature: currentTextThoughtSignature
1137
+ }
1138
+ } : void 0
1139
+ });
1140
+ currentTextContent = "";
1141
+ currentTextThoughtSignature = void 0;
1142
+ }
1143
+ isInReasoning = true;
1144
+ currentReasoningContent += part.text;
1145
+ if (part.thoughtSignature) {
1146
+ currentReasoningThoughtSignature = part.thoughtSignature;
1147
+ }
1148
+ } else {
1149
+ if (isInReasoning && currentReasoningContent) {
1150
+ content.push({
1151
+ type: "reasoning",
1152
+ text: currentReasoningContent,
1153
+ providerMetadata: currentReasoningThoughtSignature ? {
1154
+ [providerKey != null ? providerKey : "google"]: {
1155
+ thoughtSignature: currentReasoningThoughtSignature
1156
+ }
1157
+ } : void 0
1158
+ });
1159
+ currentReasoningContent = "";
1160
+ currentReasoningThoughtSignature = void 0;
1161
+ }
1162
+ isInReasoning = false;
1163
+ currentTextContent += part.text;
1164
+ if (part.thoughtSignature) {
1165
+ currentTextThoughtSignature = part.thoughtSignature;
1166
+ }
1167
+ }
1168
+ } else if ("functionCall" in part) {
1169
+ if (currentTextContent) {
1170
+ content.push({
1171
+ type: "text",
1172
+ text: currentTextContent,
1173
+ providerMetadata: currentTextThoughtSignature ? {
1174
+ [providerKey != null ? providerKey : "google"]: {
1175
+ thoughtSignature: currentTextThoughtSignature
1176
+ }
1177
+ } : void 0
1178
+ });
1179
+ currentTextContent = "";
1180
+ currentTextThoughtSignature = void 0;
1181
+ }
1182
+ if (currentReasoningContent) {
1183
+ content.push({
1184
+ type: "reasoning",
1185
+ text: currentReasoningContent,
1186
+ providerMetadata: currentReasoningThoughtSignature ? {
1187
+ [providerKey != null ? providerKey : "google"]: {
1188
+ thoughtSignature: currentReasoningThoughtSignature
1189
+ }
1190
+ } : void 0
1191
+ });
1192
+ currentReasoningContent = "";
1193
+ currentReasoningThoughtSignature = void 0;
1194
+ }
1195
+ const toolCallId = useToolCallId && part.functionCall.id ? part.functionCall.id : this.config.generateId();
1196
+ content.push({
1197
+ type: "tool-call",
1198
+ toolCallId,
1199
+ toolName: part.functionCall.name,
1200
+ input: JSON.stringify(part.functionCall.args),
1201
+ providerMetadata: part.thoughtSignature ? {
1202
+ [providerKey != null ? providerKey : "google"]: {
1203
+ thoughtSignature: part.thoughtSignature
1204
+ }
1205
+ } : void 0
1206
+ });
1207
+ } else if ("inlineData" in part) {
1208
+ if (currentTextContent) {
1209
+ content.push({
1210
+ type: "text",
1211
+ text: currentTextContent,
1212
+ providerMetadata: currentTextThoughtSignature ? {
1213
+ [providerKey != null ? providerKey : "google"]: {
1214
+ thoughtSignature: currentTextThoughtSignature
1215
+ }
1216
+ } : void 0
1217
+ });
1218
+ currentTextContent = "";
1219
+ currentTextThoughtSignature = void 0;
1220
+ }
1221
+ if (currentReasoningContent) {
1222
+ content.push({
1223
+ type: "reasoning",
1224
+ text: currentReasoningContent,
1225
+ providerMetadata: currentReasoningThoughtSignature ? {
1226
+ [providerKey != null ? providerKey : "google"]: {
1227
+ thoughtSignature: currentReasoningThoughtSignature
1228
+ }
1229
+ } : void 0
1230
+ });
1231
+ currentReasoningContent = "";
1232
+ currentReasoningThoughtSignature = void 0;
1233
+ }
1234
+ content.push({
1235
+ type: "file",
1236
+ data: part.inlineData.data,
1237
+ mediaType: part.inlineData.mimeType
1238
+ });
1239
+ }
1240
+ }
1241
+ if (candidate.finishReason) {
1242
+ finishReason = mapGoogleGenerativeAIFinishReason({
1243
+ finishReason: candidate.finishReason,
1244
+ hasToolCalls: content.some((part) => part.type === "tool-call")
1245
+ });
1246
+ }
1247
+ }
1248
+ } finally {
1249
+ reader.releaseLock();
1250
+ }
1251
+ if (currentTextContent) {
1252
+ content.push({
1253
+ type: "text",
1254
+ text: currentTextContent,
1255
+ providerMetadata: currentTextThoughtSignature ? {
1256
+ [providerKey != null ? providerKey : "google"]: {
1257
+ thoughtSignature: currentTextThoughtSignature
1258
+ }
1259
+ } : void 0
1260
+ });
1261
+ }
1262
+ if (currentReasoningContent) {
1263
+ content.push({
1264
+ type: "reasoning",
1265
+ text: currentReasoningContent,
1266
+ providerMetadata: currentReasoningThoughtSignature ? {
1267
+ [providerKey != null ? providerKey : "google"]: {
1268
+ thoughtSignature: currentReasoningThoughtSignature
1269
+ }
1270
+ } : void 0
1271
+ });
1272
+ }
1273
+ const sources = (_h = extractSources({
1274
+ groundingMetadata,
1275
+ generateId: this.config.generateId
1276
+ })) != null ? _h : [];
1277
+ for (const source of sources) {
1278
+ content.push(source);
1279
+ }
1280
+ return {
1281
+ content,
1282
+ finishReason,
1283
+ usage: {
1284
+ inputTokens: (_i = usageMetadata == null ? void 0 : usageMetadata.promptTokenCount) != null ? _i : void 0,
1285
+ outputTokens: (_j = usageMetadata == null ? void 0 : usageMetadata.candidatesTokenCount) != null ? _j : void 0,
1286
+ totalTokens: (_k = usageMetadata == null ? void 0 : usageMetadata.totalTokenCount) != null ? _k : void 0,
1287
+ reasoningTokens: (_l = usageMetadata == null ? void 0 : usageMetadata.thoughtsTokenCount) != null ? _l : void 0,
1288
+ cachedInputTokens: (_m = usageMetadata == null ? void 0 : usageMetadata.cachedContentTokenCount) != null ? _m : void 0
1289
+ },
1290
+ warnings,
1291
+ providerMetadata: {
1292
+ [providerKey != null ? providerKey : "google"]: {
1293
+ promptFeedback: promptFeedback != null ? promptFeedback : null,
1294
+ groundingMetadata: groundingMetadata != null ? groundingMetadata : null,
1295
+ urlContextMetadata: urlContextMetadata != null ? urlContextMetadata : null,
1296
+ safetyRatings: safetyRatings != null ? safetyRatings : null,
1297
+ usageMetadata: usageMetadata != null ? usageMetadata : null
1298
+ }
1299
+ },
1300
+ request: { body },
1301
+ response: {
1302
+ headers: responseHeaders
1303
+ }
1304
+ };
1305
+ }
1306
+ async doStream(options) {
1307
+ var _a, _b;
1308
+ const { args, warnings, cloudAssistOptions, providerKey } = await this.getArgs(options);
1309
+ const wrappedRequest = {
1310
+ project: cloudAssistOptions.projectId,
1311
+ model: this.modelId,
1312
+ request: args,
1313
+ ...cloudAssistOptions.requestType && {
1314
+ requestType: cloudAssistOptions.requestType
1315
+ },
1316
+ userAgent: (_a = cloudAssistOptions.userAgent) != null ? _a : "ai-sdk",
1317
+ requestId: (_b = cloudAssistOptions.requestId) != null ? _b : `ai-sdk-${Date.now()}-${Math.random().toString(36).slice(2, 11)}`
1318
+ };
1319
+ const body = JSON.stringify(wrappedRequest);
1320
+ const headers = (0, import_provider_utils6.combineHeaders)(
1321
+ await (0, import_provider_utils6.resolve)(this.config.headers),
1322
+ options.headers
1323
+ );
1324
+ const { responseHeaders, value: response } = await (0, import_provider_utils6.postJsonToApi)({
1325
+ url: `${this.config.baseURL}/v1internal:streamGenerateContent?alt=sse`,
1326
+ headers,
1327
+ body: wrappedRequest,
1328
+ failedResponseHandler: googleFailedResponseHandler,
1329
+ successfulResponseHandler: (0, import_provider_utils6.createEventSourceResponseHandler)(chunkSchema),
1330
+ abortSignal: options.abortSignal,
1331
+ fetch: this.config.fetch
1332
+ });
1333
+ let finishReason = "unknown";
1334
+ const usage = {
1335
+ inputTokens: void 0,
1336
+ outputTokens: void 0,
1337
+ totalTokens: void 0
1338
+ };
1339
+ let providerMetadata = void 0;
1340
+ const generateId3 = this.config.generateId;
1341
+ const useToolCallId = isClaudeModel(this.modelId);
1342
+ let hasToolCalls = false;
1343
+ let currentTextBlockId = null;
1344
+ let currentReasoningBlockId = null;
1345
+ let blockCounter = 0;
1346
+ const emittedSourceUrls = /* @__PURE__ */ new Set();
1347
+ let lastCodeExecutionToolCallId;
1348
+ return {
1349
+ stream: response.pipeThrough(
1350
+ new TransformStream({
1351
+ start(controller) {
1352
+ controller.enqueue({ type: "stream-start", warnings });
1353
+ },
1354
+ transform(chunk, controller) {
1355
+ var _a2, _b2, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m;
1356
+ if (options.includeRawChunks) {
1357
+ controller.enqueue({ type: "raw", rawValue: chunk.rawValue });
1358
+ }
1359
+ if (!chunk.success) {
1360
+ controller.enqueue({ type: "error", error: chunk.error });
1361
+ return;
1362
+ }
1363
+ const value = chunk.value;
1364
+ const responseData = (_a2 = value.response) != null ? _a2 : value;
1365
+ const usageMetadata = responseData.usageMetadata;
1366
+ if (usageMetadata != null) {
1367
+ usage.inputTokens = (_b2 = usageMetadata.promptTokenCount) != null ? _b2 : void 0;
1368
+ usage.outputTokens = (_c = usageMetadata.candidatesTokenCount) != null ? _c : void 0;
1369
+ usage.totalTokens = (_d = usageMetadata.totalTokenCount) != null ? _d : void 0;
1370
+ usage.reasoningTokens = (_e = usageMetadata.thoughtsTokenCount) != null ? _e : void 0;
1371
+ usage.cachedInputTokens = (_f = usageMetadata.cachedContentTokenCount) != null ? _f : void 0;
1372
+ }
1373
+ const candidate = (_g = responseData.candidates) == null ? void 0 : _g[0];
1374
+ if (candidate == null) {
1375
+ return;
1376
+ }
1377
+ const content = candidate.content;
1378
+ const sources = extractSources({
1379
+ groundingMetadata: candidate.groundingMetadata,
1380
+ generateId: generateId3
1381
+ });
1382
+ if (sources != null) {
1383
+ for (const source of sources) {
1384
+ if (source.sourceType === "url" && !emittedSourceUrls.has(source.url)) {
1385
+ emittedSourceUrls.add(source.url);
1386
+ controller.enqueue(source);
1387
+ }
1388
+ }
1389
+ }
1390
+ if (content != null) {
1391
+ const parts = (_h = content.parts) != null ? _h : [];
1392
+ for (const part of parts) {
1393
+ if ("executableCode" in part && ((_i = part.executableCode) == null ? void 0 : _i.code)) {
1394
+ const toolCallId = generateId3();
1395
+ lastCodeExecutionToolCallId = toolCallId;
1396
+ controller.enqueue({
1397
+ type: "tool-call",
1398
+ toolCallId,
1399
+ toolName: "code_execution",
1400
+ input: JSON.stringify(part.executableCode),
1401
+ providerExecuted: true
1402
+ });
1403
+ hasToolCalls = true;
1404
+ } else if ("codeExecutionResult" in part && part.codeExecutionResult) {
1405
+ const toolCallId = lastCodeExecutionToolCallId;
1406
+ if (toolCallId) {
1407
+ controller.enqueue({
1408
+ type: "tool-result",
1409
+ toolCallId,
1410
+ toolName: "code_execution",
1411
+ result: {
1412
+ outcome: part.codeExecutionResult.outcome,
1413
+ output: part.codeExecutionResult.output
1414
+ },
1415
+ providerExecuted: true
1416
+ });
1417
+ lastCodeExecutionToolCallId = void 0;
1418
+ }
1419
+ } else if ("text" in part && part.text != null && part.text.length > 0) {
1420
+ if (part.thought === true) {
1421
+ if (currentTextBlockId !== null) {
1422
+ controller.enqueue({
1423
+ type: "text-end",
1424
+ id: currentTextBlockId
1425
+ });
1426
+ currentTextBlockId = null;
1427
+ }
1428
+ if (currentReasoningBlockId === null) {
1429
+ currentReasoningBlockId = String(blockCounter++);
1430
+ controller.enqueue({
1431
+ type: "reasoning-start",
1432
+ id: currentReasoningBlockId,
1433
+ providerMetadata: part.thoughtSignature ? {
1434
+ [providerKey != null ? providerKey : "google"]: {
1435
+ thoughtSignature: part.thoughtSignature
1436
+ }
1437
+ } : void 0
1438
+ });
1439
+ }
1440
+ controller.enqueue({
1441
+ type: "reasoning-delta",
1442
+ id: currentReasoningBlockId,
1443
+ delta: part.text,
1444
+ providerMetadata: part.thoughtSignature ? {
1445
+ [providerKey != null ? providerKey : "google"]: {
1446
+ thoughtSignature: part.thoughtSignature
1447
+ }
1448
+ } : void 0
1449
+ });
1450
+ } else {
1451
+ if (currentReasoningBlockId !== null) {
1452
+ controller.enqueue({
1453
+ type: "reasoning-end",
1454
+ id: currentReasoningBlockId
1455
+ });
1456
+ currentReasoningBlockId = null;
1457
+ }
1458
+ if (currentTextBlockId === null) {
1459
+ currentTextBlockId = String(blockCounter++);
1460
+ controller.enqueue({
1461
+ type: "text-start",
1462
+ id: currentTextBlockId,
1463
+ providerMetadata: part.thoughtSignature ? {
1464
+ [providerKey != null ? providerKey : "google"]: {
1465
+ thoughtSignature: part.thoughtSignature
1466
+ }
1467
+ } : void 0
1468
+ });
1469
+ }
1470
+ controller.enqueue({
1471
+ type: "text-delta",
1472
+ id: currentTextBlockId,
1473
+ delta: part.text,
1474
+ providerMetadata: part.thoughtSignature ? {
1475
+ [providerKey != null ? providerKey : "google"]: {
1476
+ thoughtSignature: part.thoughtSignature
1477
+ }
1478
+ } : void 0
1479
+ });
1480
+ }
1481
+ } else if ("inlineData" in part) {
1482
+ controller.enqueue({
1483
+ type: "file",
1484
+ mediaType: part.inlineData.mimeType,
1485
+ data: part.inlineData.data
1486
+ });
1487
+ }
1488
+ }
1489
+ const toolCallDeltas = getToolCallsFromParts({
1490
+ parts: content.parts,
1491
+ generateId: generateId3,
1492
+ useToolCallId,
1493
+ providerKey
1494
+ });
1495
+ if (toolCallDeltas != null) {
1496
+ for (const toolCall of toolCallDeltas) {
1497
+ controller.enqueue({
1498
+ type: "tool-input-start",
1499
+ id: toolCall.toolCallId,
1500
+ toolName: toolCall.toolName,
1501
+ providerMetadata: toolCall.providerMetadata
1502
+ });
1503
+ controller.enqueue({
1504
+ type: "tool-input-delta",
1505
+ id: toolCall.toolCallId,
1506
+ delta: toolCall.args,
1507
+ providerMetadata: toolCall.providerMetadata
1508
+ });
1509
+ controller.enqueue({
1510
+ type: "tool-input-end",
1511
+ id: toolCall.toolCallId,
1512
+ providerMetadata: toolCall.providerMetadata
1513
+ });
1514
+ controller.enqueue({
1515
+ type: "tool-call",
1516
+ toolCallId: toolCall.toolCallId,
1517
+ toolName: toolCall.toolName,
1518
+ input: toolCall.args,
1519
+ providerMetadata: toolCall.providerMetadata
1520
+ });
1521
+ hasToolCalls = true;
1522
+ }
1523
+ }
1524
+ }
1525
+ if (candidate.finishReason != null) {
1526
+ finishReason = mapGoogleGenerativeAIFinishReason({
1527
+ finishReason: candidate.finishReason,
1528
+ hasToolCalls
1529
+ });
1530
+ providerMetadata = {
1531
+ [providerKey != null ? providerKey : "google"]: {
1532
+ promptFeedback: (_j = responseData.promptFeedback) != null ? _j : null,
1533
+ groundingMetadata: (_k = candidate.groundingMetadata) != null ? _k : null,
1534
+ urlContextMetadata: (_l = candidate.urlContextMetadata) != null ? _l : null,
1535
+ safetyRatings: (_m = candidate.safetyRatings) != null ? _m : null
1536
+ }
1537
+ };
1538
+ if (usageMetadata != null) {
1539
+ providerMetadata[providerKey != null ? providerKey : "google"].usageMetadata = usageMetadata;
1540
+ }
1541
+ }
1542
+ },
1543
+ flush(controller) {
1544
+ if (currentTextBlockId !== null) {
1545
+ controller.enqueue({
1546
+ type: "text-end",
1547
+ id: currentTextBlockId
1548
+ });
1549
+ }
1550
+ if (currentReasoningBlockId !== null) {
1551
+ controller.enqueue({
1552
+ type: "reasoning-end",
1553
+ id: currentReasoningBlockId
1554
+ });
1555
+ }
1556
+ controller.enqueue({
1557
+ type: "finish",
1558
+ finishReason,
1559
+ usage,
1560
+ providerMetadata
1561
+ });
1562
+ }
1563
+ })
1564
+ ),
1565
+ response: { headers: responseHeaders },
1566
+ request: { body }
1567
+ };
1568
+ }
1569
+ };
1570
+ function getToolCallsFromParts({
1571
+ parts,
1572
+ generateId: generateId3,
1573
+ useToolCallId = false,
1574
+ providerKey
1575
+ }) {
1576
+ const functionCallParts = parts == null ? void 0 : parts.filter(
1577
+ (part) => "functionCall" in part
1578
+ );
1579
+ return functionCallParts == null || functionCallParts.length === 0 ? void 0 : functionCallParts.map((part) => ({
1580
+ type: "tool-call",
1581
+ // Use provided id for Claude models, generate for others
1582
+ toolCallId: useToolCallId && part.functionCall.id ? part.functionCall.id : generateId3(),
1583
+ toolName: part.functionCall.name,
1584
+ args: JSON.stringify(part.functionCall.args),
1585
+ providerMetadata: part.thoughtSignature ? {
1586
+ [providerKey != null ? providerKey : "google"]: {
1587
+ thoughtSignature: part.thoughtSignature
1588
+ }
1589
+ } : void 0
1590
+ }));
1591
+ }
1592
+ function extractSources({
1593
+ groundingMetadata,
1594
+ generateId: generateId3
1595
+ }) {
1596
+ var _a, _b, _c, _d, _e;
1597
+ if (!(groundingMetadata == null ? void 0 : groundingMetadata.groundingChunks)) {
1598
+ return void 0;
1599
+ }
1600
+ const sources = [];
1601
+ for (const chunk of groundingMetadata.groundingChunks) {
1602
+ if (chunk.web != null) {
1603
+ sources.push({
1604
+ type: "source",
1605
+ sourceType: "url",
1606
+ id: generateId3(),
1607
+ url: chunk.web.uri,
1608
+ title: (_a = chunk.web.title) != null ? _a : void 0
1609
+ });
1610
+ } else if (chunk.retrievedContext != null) {
1611
+ const uri = chunk.retrievedContext.uri;
1612
+ const fileSearchStore = chunk.retrievedContext.fileSearchStore;
1613
+ if (uri && (uri.startsWith("http://") || uri.startsWith("https://"))) {
1614
+ sources.push({
1615
+ type: "source",
1616
+ sourceType: "url",
1617
+ id: generateId3(),
1618
+ url: uri,
1619
+ title: (_b = chunk.retrievedContext.title) != null ? _b : void 0
1620
+ });
1621
+ } else if (uri) {
1622
+ const title = (_c = chunk.retrievedContext.title) != null ? _c : "Unknown Document";
1623
+ let mediaType = "application/octet-stream";
1624
+ let filename = void 0;
1625
+ if (uri.endsWith(".pdf")) {
1626
+ mediaType = "application/pdf";
1627
+ filename = uri.split("/").pop();
1628
+ } else if (uri.endsWith(".txt")) {
1629
+ mediaType = "text/plain";
1630
+ filename = uri.split("/").pop();
1631
+ } else if (uri.endsWith(".docx")) {
1632
+ mediaType = "application/vnd.openxmlformats-officedocument.wordprocessingml.document";
1633
+ filename = uri.split("/").pop();
1634
+ } else if (uri.endsWith(".doc")) {
1635
+ mediaType = "application/msword";
1636
+ filename = uri.split("/").pop();
1637
+ } else if (uri.match(/\.(md|markdown)$/)) {
1638
+ mediaType = "text/markdown";
1639
+ filename = uri.split("/").pop();
1640
+ } else {
1641
+ filename = uri.split("/").pop();
1642
+ }
1643
+ sources.push({
1644
+ type: "source",
1645
+ sourceType: "document",
1646
+ id: generateId3(),
1647
+ mediaType,
1648
+ title,
1649
+ filename
1650
+ });
1651
+ } else if (fileSearchStore) {
1652
+ const title = (_d = chunk.retrievedContext.title) != null ? _d : "Unknown Document";
1653
+ sources.push({
1654
+ type: "source",
1655
+ sourceType: "document",
1656
+ id: generateId3(),
1657
+ mediaType: "application/octet-stream",
1658
+ title,
1659
+ filename: fileSearchStore.split("/").pop()
1660
+ });
1661
+ }
1662
+ } else if (chunk.maps != null) {
1663
+ if (chunk.maps.uri) {
1664
+ sources.push({
1665
+ type: "source",
1666
+ sourceType: "url",
1667
+ id: generateId3(),
1668
+ url: chunk.maps.uri,
1669
+ title: (_e = chunk.maps.title) != null ? _e : void 0
1670
+ });
1671
+ }
1672
+ }
1673
+ }
1674
+ return sources.length > 0 ? sources : void 0;
1675
+ }
1676
+ var getGroundingMetadataSchema = () => import_v45.z.object({
1677
+ webSearchQueries: import_v45.z.array(import_v45.z.string()).nullish(),
1678
+ retrievalQueries: import_v45.z.array(import_v45.z.string()).nullish(),
1679
+ searchEntryPoint: import_v45.z.object({ renderedContent: import_v45.z.string() }).nullish(),
1680
+ groundingChunks: import_v45.z.array(
1681
+ import_v45.z.object({
1682
+ web: import_v45.z.object({ uri: import_v45.z.string(), title: import_v45.z.string().nullish() }).nullish(),
1683
+ retrievedContext: import_v45.z.object({
1684
+ uri: import_v45.z.string().nullish(),
1685
+ title: import_v45.z.string().nullish(),
1686
+ text: import_v45.z.string().nullish(),
1687
+ fileSearchStore: import_v45.z.string().nullish()
1688
+ }).nullish(),
1689
+ maps: import_v45.z.object({
1690
+ uri: import_v45.z.string().nullish(),
1691
+ title: import_v45.z.string().nullish(),
1692
+ text: import_v45.z.string().nullish(),
1693
+ placeId: import_v45.z.string().nullish()
1694
+ }).nullish()
1695
+ })
1696
+ ).nullish(),
1697
+ groundingSupports: import_v45.z.array(
1698
+ import_v45.z.object({
1699
+ segment: import_v45.z.object({
1700
+ startIndex: import_v45.z.number().nullish(),
1701
+ endIndex: import_v45.z.number().nullish(),
1702
+ text: import_v45.z.string().nullish()
1703
+ }),
1704
+ segment_text: import_v45.z.string().nullish(),
1705
+ groundingChunkIndices: import_v45.z.array(import_v45.z.number()).nullish(),
1706
+ supportChunkIndices: import_v45.z.array(import_v45.z.number()).nullish(),
1707
+ confidenceScores: import_v45.z.array(import_v45.z.number()).nullish(),
1708
+ confidenceScore: import_v45.z.array(import_v45.z.number()).nullish()
1709
+ })
1710
+ ).nullish(),
1711
+ retrievalMetadata: import_v45.z.union([
1712
+ import_v45.z.object({
1713
+ webDynamicRetrievalScore: import_v45.z.number()
1714
+ }),
1715
+ import_v45.z.object({})
1716
+ ]).nullish()
1717
+ });
1718
+ var getContentSchema = () => import_v45.z.object({
1719
+ parts: import_v45.z.array(
1720
+ import_v45.z.union([
1721
+ // note: order matters since text can be fully empty
1722
+ import_v45.z.object({
1723
+ functionCall: import_v45.z.object({
1724
+ name: import_v45.z.string(),
1725
+ args: import_v45.z.unknown(),
1726
+ id: import_v45.z.string().nullish()
1727
+ // Claude models include tool call ID
1728
+ }),
1729
+ thoughtSignature: import_v45.z.string().nullish()
1730
+ }),
1731
+ import_v45.z.object({
1732
+ inlineData: import_v45.z.object({
1733
+ mimeType: import_v45.z.string(),
1734
+ data: import_v45.z.string()
1735
+ })
1736
+ }),
1737
+ import_v45.z.object({
1738
+ executableCode: import_v45.z.object({
1739
+ language: import_v45.z.string(),
1740
+ code: import_v45.z.string()
1741
+ }).nullish(),
1742
+ codeExecutionResult: import_v45.z.object({
1743
+ outcome: import_v45.z.string(),
1744
+ output: import_v45.z.string()
1745
+ }).nullish(),
1746
+ text: import_v45.z.string().nullish(),
1747
+ thought: import_v45.z.boolean().nullish(),
1748
+ thoughtSignature: import_v45.z.string().nullish()
1749
+ })
1750
+ ])
1751
+ ).nullish()
1752
+ });
1753
+ var getSafetyRatingSchema = () => import_v45.z.object({
1754
+ category: import_v45.z.string().nullish(),
1755
+ probability: import_v45.z.string().nullish(),
1756
+ probabilityScore: import_v45.z.number().nullish(),
1757
+ severity: import_v45.z.string().nullish(),
1758
+ severityScore: import_v45.z.number().nullish(),
1759
+ blocked: import_v45.z.boolean().nullish()
1760
+ });
1761
+ var usageSchema = import_v45.z.object({
1762
+ cachedContentTokenCount: import_v45.z.number().nullish(),
1763
+ thoughtsTokenCount: import_v45.z.number().nullish(),
1764
+ promptTokenCount: import_v45.z.number().nullish(),
1765
+ candidatesTokenCount: import_v45.z.number().nullish(),
1766
+ totalTokenCount: import_v45.z.number().nullish(),
1767
+ // https://cloud.google.com/vertex-ai/generative-ai/docs/reference/rest/v1/GenerateContentResponse#TrafficType
1768
+ trafficType: import_v45.z.string().nullish()
1769
+ });
1770
+ var getUrlContextMetadataSchema = () => import_v45.z.object({
1771
+ urlMetadata: import_v45.z.array(
1772
+ import_v45.z.object({
1773
+ retrievedUrl: import_v45.z.string(),
1774
+ urlRetrievalStatus: import_v45.z.string()
1775
+ })
1776
+ )
1777
+ });
1778
+ var responseSchema = (0, import_provider_utils6.lazySchema)(
1779
+ () => (0, import_provider_utils6.zodSchema)(
1780
+ import_v45.z.object({
1781
+ candidates: import_v45.z.array(
1782
+ import_v45.z.object({
1783
+ content: getContentSchema().nullish().or(import_v45.z.object({}).strict()),
1784
+ finishReason: import_v45.z.string().nullish(),
1785
+ safetyRatings: import_v45.z.array(getSafetyRatingSchema()).nullish(),
1786
+ groundingMetadata: getGroundingMetadataSchema().nullish(),
1787
+ urlContextMetadata: getUrlContextMetadataSchema().nullish()
1788
+ })
1789
+ ),
1790
+ usageMetadata: usageSchema.nullish(),
1791
+ promptFeedback: import_v45.z.object({
1792
+ blockReason: import_v45.z.string().nullish(),
1793
+ safetyRatings: import_v45.z.array(getSafetyRatingSchema()).nullish()
1794
+ }).nullish()
1795
+ })
1796
+ )
1797
+ );
1798
+ var getResponseContentSchema = () => import_v45.z.object({
1799
+ candidates: import_v45.z.array(
1800
+ import_v45.z.object({
1801
+ content: getContentSchema().nullish(),
1802
+ finishReason: import_v45.z.string().nullish(),
1803
+ safetyRatings: import_v45.z.array(getSafetyRatingSchema()).nullish(),
1804
+ groundingMetadata: getGroundingMetadataSchema().nullish(),
1805
+ urlContextMetadata: getUrlContextMetadataSchema().nullish()
1806
+ })
1807
+ ).nullish(),
1808
+ usageMetadata: usageSchema.nullish(),
1809
+ promptFeedback: import_v45.z.object({
1810
+ blockReason: import_v45.z.string().nullish(),
1811
+ safetyRatings: import_v45.z.array(getSafetyRatingSchema()).nullish()
1812
+ }).nullish(),
1813
+ modelVersion: import_v45.z.string().nullish(),
1814
+ responseId: import_v45.z.string().nullish()
1815
+ });
1816
+ var chunkSchema = (0, import_provider_utils6.lazySchema)(
1817
+ () => (0, import_provider_utils6.zodSchema)(
1818
+ import_v45.z.object({
1819
+ // Cloud Assist wrapper fields
1820
+ response: getResponseContentSchema().nullish(),
1821
+ traceId: import_v45.z.string().nullish(),
1822
+ // Also allow direct fields for compatibility
1823
+ candidates: import_v45.z.array(
1824
+ import_v45.z.object({
1825
+ content: getContentSchema().nullish(),
1826
+ finishReason: import_v45.z.string().nullish(),
1827
+ safetyRatings: import_v45.z.array(getSafetyRatingSchema()).nullish(),
1828
+ groundingMetadata: getGroundingMetadataSchema().nullish(),
1829
+ urlContextMetadata: getUrlContextMetadataSchema().nullish()
1830
+ })
1831
+ ).nullish(),
1832
+ usageMetadata: usageSchema.nullish(),
1833
+ promptFeedback: import_v45.z.object({
1834
+ blockReason: import_v45.z.string().nullish(),
1835
+ safetyRatings: import_v45.z.array(getSafetyRatingSchema()).nullish()
1836
+ }).nullish()
1837
+ })
1838
+ )
1839
+ );
1840
+
1841
+ // src/tool/code-execution.ts
1842
+ var import_provider_utils7 = require("@ai-sdk/provider-utils");
1843
+ var import_v46 = require("zod/v4");
1844
+ var codeExecution = (0, import_provider_utils7.createProviderDefinedToolFactoryWithOutputSchema)({
1845
+ id: "google.code_execution",
1846
+ name: "code_execution",
1847
+ inputSchema: import_v46.z.object({
1848
+ language: import_v46.z.string().describe("The programming language of the code."),
1849
+ code: import_v46.z.string().describe("The code to be executed.")
1850
+ }),
1851
+ outputSchema: import_v46.z.object({
1852
+ outcome: import_v46.z.string().describe('The outcome of the execution (e.g., "OUTCOME_OK").'),
1853
+ output: import_v46.z.string().describe("The output from the code execution.")
1854
+ })
1855
+ });
1856
+
1857
+ // src/tool/enterprise-web-search.ts
1858
+ var import_provider_utils8 = require("@ai-sdk/provider-utils");
1859
+ var import_v47 = require("zod/v4");
1860
+ var enterpriseWebSearch = (0, import_provider_utils8.createProviderDefinedToolFactory)({
1861
+ id: "google.enterprise_web_search",
1862
+ name: "enterprise_web_search",
1863
+ inputSchema: (0, import_provider_utils8.lazySchema)(() => (0, import_provider_utils8.zodSchema)(import_v47.z.object({})))
1864
+ });
1865
+
1866
+ // src/tool/file-search.ts
1867
+ var import_provider_utils9 = require("@ai-sdk/provider-utils");
1868
+ var import_v48 = require("zod/v4");
1869
+ var fileSearchArgsBaseSchema = import_v48.z.object({
1870
+ /** The names of the file_search_stores to retrieve from.
1871
+ * Example: `fileSearchStores/my-file-search-store-123`
1872
+ */
1873
+ fileSearchStoreNames: import_v48.z.array(import_v48.z.string()).describe(
1874
+ "The names of the file_search_stores to retrieve from. Example: `fileSearchStores/my-file-search-store-123`"
1875
+ ),
1876
+ /** The number of file search retrieval chunks to retrieve. */
1877
+ topK: import_v48.z.number().int().positive().describe("The number of file search retrieval chunks to retrieve.").optional(),
1878
+ /** Metadata filter to apply to the file search retrieval documents.
1879
+ * See https://google.aip.dev/160 for the syntax of the filter expression.
1880
+ */
1881
+ metadataFilter: import_v48.z.string().describe(
1882
+ "Metadata filter to apply to the file search retrieval documents. See https://google.aip.dev/160 for the syntax of the filter expression."
1883
+ ).optional()
1884
+ }).passthrough();
1885
+ var fileSearchArgsSchema = (0, import_provider_utils9.lazySchema)(
1886
+ () => (0, import_provider_utils9.zodSchema)(fileSearchArgsBaseSchema)
1887
+ );
1888
+ var fileSearch = (0, import_provider_utils9.createProviderDefinedToolFactory)({
1889
+ id: "google.file_search",
1890
+ name: "file_search",
1891
+ inputSchema: fileSearchArgsSchema
1892
+ });
1893
+
1894
+ // src/tool/google-maps.ts
1895
+ var import_provider_utils10 = require("@ai-sdk/provider-utils");
1896
+ var import_v49 = require("zod/v4");
1897
+ var googleMaps = (0, import_provider_utils10.createProviderDefinedToolFactory)({
1898
+ id: "google.google_maps",
1899
+ name: "google_maps",
1900
+ inputSchema: (0, import_provider_utils10.lazySchema)(() => (0, import_provider_utils10.zodSchema)(import_v49.z.object({})))
1901
+ });
1902
+
1903
+ // src/tool/google-search.ts
1904
+ var import_provider_utils11 = require("@ai-sdk/provider-utils");
1905
+ var import_v410 = require("zod/v4");
1906
+ var googleSearch = (0, import_provider_utils11.createProviderDefinedToolFactory)({
1907
+ id: "google.google_search",
1908
+ name: "google_search",
1909
+ inputSchema: (0, import_provider_utils11.lazySchema)(
1910
+ () => (0, import_provider_utils11.zodSchema)(
1911
+ import_v410.z.object({
1912
+ mode: import_v410.z.enum(["MODE_DYNAMIC", "MODE_UNSPECIFIED"]).default("MODE_UNSPECIFIED"),
1913
+ dynamicThreshold: import_v410.z.number().default(1)
1914
+ })
1915
+ )
1916
+ )
1917
+ });
1918
+
1919
+ // src/tool/url-context.ts
1920
+ var import_provider_utils12 = require("@ai-sdk/provider-utils");
1921
+ var import_v411 = require("zod/v4");
1922
+ var urlContext = (0, import_provider_utils12.createProviderDefinedToolFactory)({
1923
+ id: "google.url_context",
1924
+ name: "url_context",
1925
+ inputSchema: (0, import_provider_utils12.lazySchema)(() => (0, import_provider_utils12.zodSchema)(import_v411.z.object({})))
1926
+ });
1927
+
1928
+ // src/tool/vertex-rag-store.ts
1929
+ var import_provider_utils13 = require("@ai-sdk/provider-utils");
1930
+ var import_v412 = require("zod/v4");
1931
+ var vertexRagStore = (0, import_provider_utils13.createProviderDefinedToolFactory)({
1932
+ id: "google.vertex_rag_store",
1933
+ name: "vertex_rag_store",
1934
+ inputSchema: import_v412.z.object({
1935
+ ragCorpus: import_v412.z.string(),
1936
+ topK: import_v412.z.number().optional()
1937
+ })
1938
+ });
1939
+
1940
+ // src/google-tools.ts
1941
+ var googleTools = {
1942
+ /**
1943
+ * Creates a Google search tool that gives Google direct access to real-time web content.
1944
+ * Must have name "google_search".
1945
+ */
1946
+ googleSearch,
1947
+ /**
1948
+ * Creates an Enterprise Web Search tool for grounding responses using a compliance-focused web index.
1949
+ * Designed for highly-regulated industries (finance, healthcare, public sector).
1950
+ * Does not log customer data and supports VPC service controls.
1951
+ * Must have name "enterprise_web_search".
1952
+ *
1953
+ * @note Only available on Vertex AI. Requires Gemini 2.0 or newer.
1954
+ *
1955
+ * @see https://cloud.google.com/vertex-ai/generative-ai/docs/grounding/web-grounding-enterprise
1956
+ */
1957
+ enterpriseWebSearch,
1958
+ /**
1959
+ * Creates a Google Maps grounding tool that gives the model access to Google Maps data.
1960
+ * Must have name "google_maps".
1961
+ *
1962
+ * @see https://ai.google.dev/gemini-api/docs/maps-grounding
1963
+ * @see https://cloud.google.com/vertex-ai/generative-ai/docs/grounding/grounding-with-google-maps
1964
+ */
1965
+ googleMaps,
1966
+ /**
1967
+ * Creates a URL context tool that gives Google direct access to real-time web content.
1968
+ * Must have name "url_context".
1969
+ */
1970
+ urlContext,
1971
+ /**
1972
+ * Enables Retrieval Augmented Generation (RAG) via the Gemini File Search tool.
1973
+ * Must have name "file_search".
1974
+ *
1975
+ * @param fileSearchStoreNames - Fully-qualified File Search store resource names.
1976
+ * @param metadataFilter - Optional filter expression to restrict the files that can be retrieved.
1977
+ * @param topK - Optional result limit for the number of chunks returned from File Search.
1978
+ *
1979
+ * @see https://ai.google.dev/gemini-api/docs/file-search
1980
+ */
1981
+ fileSearch,
1982
+ /**
1983
+ * A tool that enables the model to generate and run Python code.
1984
+ * Must have name "code_execution".
1985
+ *
1986
+ * @note Ensure the selected model supports Code Execution.
1987
+ * Multi-tool usage with the code execution tool is typically compatible with Gemini >=2 models.
1988
+ *
1989
+ * @see https://ai.google.dev/gemini-api/docs/code-execution (Google AI)
1990
+ * @see https://cloud.google.com/vertex-ai/generative-ai/docs/model-reference/code-execution-api (Vertex AI)
1991
+ */
1992
+ codeExecution,
1993
+ /**
1994
+ * Creates a Vertex RAG Store tool that enables the model to perform RAG searches against a Vertex RAG Store.
1995
+ * Must have name "vertex_rag_store".
1996
+ */
1997
+ vertexRagStore
1998
+ };
1999
+
2000
+ // src/google-generative-ai-image-model.ts
2001
+ var import_provider_utils14 = require("@ai-sdk/provider-utils");
2002
+ var import_v413 = require("zod/v4");
2003
+ var GoogleGenerativeAIImageModel = class {
2004
+ constructor(modelId, settings, config) {
2005
+ this.modelId = modelId;
2006
+ this.settings = settings;
2007
+ this.config = config;
2008
+ this.specificationVersion = "v2";
2009
+ }
2010
+ get maxImagesPerCall() {
2011
+ var _a;
2012
+ return (_a = this.settings.maxImagesPerCall) != null ? _a : 4;
2013
+ }
2014
+ get provider() {
2015
+ return this.config.provider;
2016
+ }
2017
+ async doGenerate(options) {
2018
+ var _a, _b, _c;
2019
+ const {
2020
+ prompt,
2021
+ n = 1,
2022
+ size = "1024x1024",
2023
+ aspectRatio = "1:1",
2024
+ seed,
2025
+ providerOptions,
2026
+ headers,
2027
+ abortSignal
2028
+ } = options;
2029
+ const warnings = [];
2030
+ if (size != null) {
2031
+ warnings.push({
2032
+ type: "unsupported-setting",
2033
+ setting: "size",
2034
+ details: "This model does not support the `size` option. Use `aspectRatio` instead."
2035
+ });
2036
+ }
2037
+ if (seed != null) {
2038
+ warnings.push({
2039
+ type: "unsupported-setting",
2040
+ setting: "seed",
2041
+ details: "This model does not support the `seed` option through this provider."
2042
+ });
2043
+ }
2044
+ const providerKey = getProviderKey(providerOptions);
2045
+ const googleOptions = await (0, import_provider_utils14.parseProviderOptions)({
2046
+ provider: providerKey != null ? providerKey : "google",
2047
+ providerOptions,
2048
+ schema: googleImageProviderOptionsSchema
2049
+ });
2050
+ const currentDate = (_c = (_b = (_a = this.config._internal) == null ? void 0 : _a.currentDate) == null ? void 0 : _b.call(_a)) != null ? _c : /* @__PURE__ */ new Date();
2051
+ const parameters = {
2052
+ sampleCount: n
2053
+ };
2054
+ if (aspectRatio != null) {
2055
+ parameters.aspectRatio = aspectRatio;
2056
+ }
2057
+ if (googleOptions) {
2058
+ Object.assign(parameters, googleOptions);
2059
+ }
2060
+ const body = {
2061
+ instances: [{ prompt }],
2062
+ parameters
2063
+ };
2064
+ const { responseHeaders, value: response } = await (0, import_provider_utils14.postJsonToApi)({
2065
+ url: `${this.config.baseURL}/models/${this.modelId}:predict`,
2066
+ headers: (0, import_provider_utils14.combineHeaders)(await (0, import_provider_utils14.resolve)(this.config.headers), headers),
2067
+ body,
2068
+ failedResponseHandler: googleFailedResponseHandler,
2069
+ successfulResponseHandler: (0, import_provider_utils14.createJsonResponseHandler)(
2070
+ googleImageResponseSchema
2071
+ ),
2072
+ abortSignal,
2073
+ fetch: this.config.fetch
2074
+ });
2075
+ return {
2076
+ images: response.predictions.map(
2077
+ (p) => p.bytesBase64Encoded
2078
+ ),
2079
+ warnings: warnings != null ? warnings : [],
2080
+ providerMetadata: {
2081
+ [providerKey != null ? providerKey : "google"]: {
2082
+ images: response.predictions.map((prediction) => ({
2083
+ // Add any prediction-specific metadata here
2084
+ }))
2085
+ }
2086
+ },
2087
+ response: {
2088
+ timestamp: currentDate,
2089
+ modelId: this.modelId,
2090
+ headers: responseHeaders
2091
+ }
2092
+ };
2093
+ }
2094
+ };
2095
+ var googleImageResponseSchema = (0, import_provider_utils14.lazySchema)(
2096
+ () => (0, import_provider_utils14.zodSchema)(
2097
+ import_v413.z.object({
2098
+ predictions: import_v413.z.array(import_v413.z.object({ bytesBase64Encoded: import_v413.z.string() })).default([])
2099
+ })
2100
+ )
2101
+ );
2102
+ var googleImageProviderOptionsSchema = (0, import_provider_utils14.lazySchema)(
2103
+ () => (0, import_provider_utils14.zodSchema)(
2104
+ import_v413.z.object({
2105
+ personGeneration: import_v413.z.enum(["dont_allow", "allow_adult", "allow_all"]).nullish(),
2106
+ aspectRatio: import_v413.z.enum(["1:1", "3:4", "4:3", "9:16", "16:9"]).nullish()
2107
+ })
2108
+ )
2109
+ );
2110
+
2111
+ // src/google-provider.ts
2112
+ function createGoogleGenerativeAI(options = {}) {
2113
+ var _a, _b;
2114
+ const baseURL = (_a = (0, import_provider_utils15.withoutTrailingSlash)(options.baseURL)) != null ? _a : "https://cloudcode-pa.googleapis.com";
2115
+ const providerName = (_b = options.name) != null ? _b : "cloudassist";
2116
+ const getHeaders = () => (0, import_provider_utils15.withUserAgentSuffix)(
2117
+ {
2118
+ Authorization: `Bearer ${(0, import_provider_utils15.loadApiKey)({
2119
+ apiKey: options.apiKey,
2120
+ environmentVariableName: "GOOGLE_CLOUD_ACCESS_TOKEN",
2121
+ description: "Google Cloud Access Token"
2122
+ })}`,
2123
+ ...options.headers
2124
+ },
2125
+ `ai-sdk/google-cloudassist/${VERSION}`
2126
+ );
2127
+ const createChatModel = (modelId) => {
2128
+ var _a2;
2129
+ return new GoogleGenerativeAILanguageModel(modelId, {
2130
+ provider: providerName,
2131
+ baseURL,
2132
+ headers: getHeaders,
2133
+ generateId: (_a2 = options.generateId) != null ? _a2 : import_provider_utils15.generateId,
2134
+ supportedUrls: () => ({
2135
+ "*": [
2136
+ // Google Generative Language "files" endpoint
2137
+ // e.g. https://generativelanguage.googleapis.com/v1beta/files/...
2138
+ new RegExp(`^${baseURL}/files/.*$`),
2139
+ // YouTube URLs (public or unlisted videos)
2140
+ new RegExp(
2141
+ `^https://(?:www\\.)?youtube\\.com/watch\\?v=[\\w-]+(?:&[\\w=&.-]*)?$`
2142
+ ),
2143
+ new RegExp(`^https://youtu\\.be/[\\w-]+(?:\\?[\\w=&.-]*)?$`)
2144
+ ]
2145
+ }),
2146
+ fetch: options.fetch
2147
+ });
2148
+ };
2149
+ const createEmbeddingModel = (modelId) => new GoogleGenerativeAIEmbeddingModel(modelId, {
2150
+ provider: providerName,
2151
+ baseURL,
2152
+ headers: getHeaders,
2153
+ fetch: options.fetch
2154
+ });
2155
+ const createImageModel = (modelId, settings = {}) => new GoogleGenerativeAIImageModel(modelId, settings, {
2156
+ provider: providerName,
2157
+ baseURL,
2158
+ headers: getHeaders,
2159
+ fetch: options.fetch
2160
+ });
2161
+ const provider = function(modelId) {
2162
+ if (new.target) {
2163
+ throw new Error(
2164
+ "The Google Generative AI model function cannot be called with the new keyword."
2165
+ );
2166
+ }
2167
+ return createChatModel(modelId);
2168
+ };
2169
+ provider.languageModel = createChatModel;
2170
+ provider.chat = createChatModel;
2171
+ provider.generativeAI = createChatModel;
2172
+ provider.embedding = createEmbeddingModel;
2173
+ provider.textEmbedding = createEmbeddingModel;
2174
+ provider.textEmbeddingModel = createEmbeddingModel;
2175
+ provider.image = createImageModel;
2176
+ provider.imageModel = createImageModel;
2177
+ provider.tools = googleTools;
2178
+ return provider;
2179
+ }
2180
+ var google = createGoogleGenerativeAI();
2181
+ // Annotate the CommonJS export names for ESM import in node:
2182
+ 0 && (module.exports = {
2183
+ VERSION,
2184
+ createGoogleGenerativeAI,
2185
+ google
2186
+ });
2187
+ //# sourceMappingURL=index.js.map