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