@ai-sdk/google 2.0.0-canary.1 → 2.0.0-canary.10

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.js CHANGED
@@ -32,7 +32,7 @@ var import_provider_utils5 = require("@ai-sdk/provider-utils");
32
32
  // src/google-generative-ai-embedding-model.ts
33
33
  var import_provider = require("@ai-sdk/provider");
34
34
  var import_provider_utils2 = require("@ai-sdk/provider-utils");
35
- var import_zod2 = require("zod");
35
+ var import_zod3 = require("zod");
36
36
 
37
37
  // src/google-error.ts
38
38
  var import_provider_utils = require("@ai-sdk/provider-utils");
@@ -49,12 +49,21 @@ var googleFailedResponseHandler = (0, import_provider_utils.createJsonErrorRespo
49
49
  errorToMessage: (data) => data.error.message
50
50
  });
51
51
 
52
+ // src/google-generative-ai-embedding-options.ts
53
+ var import_zod2 = require("zod");
54
+ var googleGenerativeAIEmbeddingProviderOptions = import_zod2.z.object({
55
+ /**
56
+ * Optional. Optional reduced dimension for the output embedding.
57
+ * If set, excessive values in the output embedding are truncated from the end.
58
+ */
59
+ outputDimensionality: import_zod2.z.number().optional()
60
+ });
61
+
52
62
  // src/google-generative-ai-embedding-model.ts
53
63
  var GoogleGenerativeAIEmbeddingModel = class {
54
- constructor(modelId, settings, config) {
55
- this.specificationVersion = "v1";
64
+ constructor(modelId, config) {
65
+ this.specificationVersion = "v2";
56
66
  this.modelId = modelId;
57
- this.settings = settings;
58
67
  this.config = config;
59
68
  }
60
69
  get provider() {
@@ -69,8 +78,15 @@ var GoogleGenerativeAIEmbeddingModel = class {
69
78
  async doEmbed({
70
79
  values,
71
80
  headers,
72
- abortSignal
81
+ abortSignal,
82
+ providerOptions
73
83
  }) {
84
+ var _a;
85
+ const googleOptions = (_a = (0, import_provider_utils2.parseProviderOptions)({
86
+ provider: "google",
87
+ providerOptions,
88
+ schema: googleGenerativeAIEmbeddingProviderOptions
89
+ })) != null ? _a : {};
74
90
  if (values.length > this.maxEmbeddingsPerCall) {
75
91
  throw new import_provider.TooManyEmbeddingValuesForCallError({
76
92
  provider: this.provider,
@@ -83,14 +99,18 @@ var GoogleGenerativeAIEmbeddingModel = class {
83
99
  await (0, import_provider_utils2.resolve)(this.config.headers),
84
100
  headers
85
101
  );
86
- const { responseHeaders, value: response } = await (0, import_provider_utils2.postJsonToApi)({
102
+ const {
103
+ responseHeaders,
104
+ value: response,
105
+ rawValue
106
+ } = await (0, import_provider_utils2.postJsonToApi)({
87
107
  url: `${this.config.baseURL}/models/${this.modelId}:batchEmbedContents`,
88
108
  headers: mergedHeaders,
89
109
  body: {
90
110
  requests: values.map((value) => ({
91
111
  model: `models/${this.modelId}`,
92
112
  content: { role: "user", parts: [{ text: value }] },
93
- outputDimensionality: this.settings.outputDimensionality
113
+ outputDimensionality: googleOptions.outputDimensionality
94
114
  }))
95
115
  },
96
116
  failedResponseHandler: googleFailedResponseHandler,
@@ -103,21 +123,21 @@ var GoogleGenerativeAIEmbeddingModel = class {
103
123
  return {
104
124
  embeddings: response.embeddings.map((item) => item.values),
105
125
  usage: void 0,
106
- rawResponse: { headers: responseHeaders }
126
+ response: { headers: responseHeaders, body: rawValue }
107
127
  };
108
128
  }
109
129
  };
110
- var googleGenerativeAITextEmbeddingResponseSchema = import_zod2.z.object({
111
- embeddings: import_zod2.z.array(import_zod2.z.object({ values: import_zod2.z.array(import_zod2.z.number()) }))
130
+ var googleGenerativeAITextEmbeddingResponseSchema = import_zod3.z.object({
131
+ embeddings: import_zod3.z.array(import_zod3.z.object({ values: import_zod3.z.array(import_zod3.z.number()) }))
112
132
  });
113
133
 
114
134
  // src/google-generative-ai-language-model.ts
115
135
  var import_provider_utils4 = require("@ai-sdk/provider-utils");
116
- var import_zod3 = require("zod");
136
+ var import_zod4 = require("zod");
117
137
 
118
138
  // src/convert-json-schema-to-openapi-schema.ts
119
139
  function convertJSONSchemaToOpenAPISchema(jsonSchema) {
120
- if (isEmptyObjectSchema(jsonSchema)) {
140
+ if (jsonSchema == null || isEmptyObjectSchema(jsonSchema)) {
121
141
  return void 0;
122
142
  }
123
143
  if (typeof jsonSchema === "boolean") {
@@ -216,7 +236,6 @@ function isEmptyObjectSchema(jsonSchema) {
216
236
  var import_provider2 = require("@ai-sdk/provider");
217
237
  var import_provider_utils3 = require("@ai-sdk/provider-utils");
218
238
  function convertToGoogleGenerativeAIMessages(prompt) {
219
- var _a, _b;
220
239
  const systemInstructionParts = [];
221
240
  const contents = [];
222
241
  let systemMessagesAllowed = true;
@@ -240,33 +259,18 @@ function convertToGoogleGenerativeAIMessages(prompt) {
240
259
  parts.push({ text: part.text });
241
260
  break;
242
261
  }
243
- case "image": {
244
- parts.push(
245
- part.image instanceof URL ? {
246
- fileData: {
247
- mimeType: (_a = part.mimeType) != null ? _a : "image/jpeg",
248
- fileUri: part.image.toString()
249
- }
250
- } : {
251
- inlineData: {
252
- mimeType: (_b = part.mimeType) != null ? _b : "image/jpeg",
253
- data: (0, import_provider_utils3.convertUint8ArrayToBase64)(part.image)
254
- }
255
- }
256
- );
257
- break;
258
- }
259
262
  case "file": {
263
+ const mediaType = part.mediaType === "image/*" ? "image/jpeg" : part.mediaType;
260
264
  parts.push(
261
265
  part.data instanceof URL ? {
262
266
  fileData: {
263
- mimeType: part.mimeType,
267
+ mimeType: mediaType,
264
268
  fileUri: part.data.toString()
265
269
  }
266
270
  } : {
267
271
  inlineData: {
268
- mimeType: part.mimeType,
269
- data: part.data
272
+ mimeType: mediaType,
273
+ data: (0, import_provider_utils3.convertToBase64)(part.data)
270
274
  }
271
275
  }
272
276
  );
@@ -287,7 +291,7 @@ function convertToGoogleGenerativeAIMessages(prompt) {
287
291
  return part.text.length === 0 ? void 0 : { text: part.text };
288
292
  }
289
293
  case "file": {
290
- if (part.mimeType !== "image/png") {
294
+ if (part.mediaType !== "image/png") {
291
295
  throw new import_provider2.UnsupportedFunctionalityError({
292
296
  functionality: "Only PNG images are supported in assistant messages"
293
297
  });
@@ -299,8 +303,8 @@ function convertToGoogleGenerativeAIMessages(prompt) {
299
303
  }
300
304
  return {
301
305
  inlineData: {
302
- mimeType: part.mimeType,
303
- data: part.data
306
+ mimeType: part.mediaType,
307
+ data: (0, import_provider_utils3.convertToBase64)(part.data)
304
308
  }
305
309
  };
306
310
  }
@@ -348,9 +352,15 @@ function getModelPath(modelId) {
348
352
 
349
353
  // src/google-prepare-tools.ts
350
354
  var import_provider3 = require("@ai-sdk/provider");
351
- function prepareTools(mode, useSearchGrounding, dynamicRetrievalConfig, modelId) {
352
- var _a, _b;
353
- const tools = ((_a = mode.tools) == null ? void 0 : _a.length) ? mode.tools : void 0;
355
+ function prepareTools({
356
+ tools,
357
+ toolChoice,
358
+ useSearchGrounding,
359
+ dynamicRetrievalConfig,
360
+ modelId
361
+ }) {
362
+ var _a;
363
+ tools = (tools == null ? void 0 : tools.length) ? tools : void 0;
354
364
  const toolWarnings = [];
355
365
  const isGemini2 = modelId.includes("gemini-2");
356
366
  const supportsDynamicRetrieval = modelId.includes("gemini-1.5-flash") && !modelId.includes("-8b");
@@ -373,12 +383,11 @@ function prepareTools(mode, useSearchGrounding, dynamicRetrievalConfig, modelId)
373
383
  } else {
374
384
  functionDeclarations.push({
375
385
  name: tool.name,
376
- description: (_b = tool.description) != null ? _b : "",
386
+ description: (_a = tool.description) != null ? _a : "",
377
387
  parameters: convertJSONSchemaToOpenAPISchema(tool.parameters)
378
388
  });
379
389
  }
380
390
  }
381
- const toolChoice = mode.toolChoice;
382
391
  if (toolChoice == null) {
383
392
  return {
384
393
  tools: { functionDeclarations },
@@ -420,7 +429,7 @@ function prepareTools(mode, useSearchGrounding, dynamicRetrievalConfig, modelId)
420
429
  default: {
421
430
  const _exhaustiveCheck = type;
422
431
  throw new import_provider3.UnsupportedFunctionalityError({
423
- functionality: `Unsupported tool choice type: ${_exhaustiveCheck}`
432
+ functionality: `tool choice type: ${_exhaustiveCheck}`
424
433
  });
425
434
  }
426
435
  }
@@ -457,23 +466,20 @@ function mapGoogleGenerativeAIFinishReason({
457
466
  var GoogleGenerativeAILanguageModel = class {
458
467
  constructor(modelId, settings, config) {
459
468
  this.specificationVersion = "v2";
460
- this.defaultObjectGenerationMode = "json";
461
- this.supportsImageUrls = false;
462
469
  this.modelId = modelId;
463
470
  this.settings = settings;
464
471
  this.config = config;
465
472
  }
466
- get supportsStructuredOutputs() {
467
- var _a;
468
- return (_a = this.settings.structuredOutputs) != null ? _a : true;
469
- }
470
473
  get provider() {
471
474
  return this.config.provider;
472
475
  }
476
+ async getSupportedUrls() {
477
+ var _a, _b, _c;
478
+ return (_c = (_b = (_a = this.config).getSupportedUrls) == null ? void 0 : _b.call(_a)) != null ? _c : {};
479
+ }
473
480
  async getArgs({
474
- mode,
475
481
  prompt,
476
- maxTokens,
482
+ maxOutputTokens,
477
483
  temperature,
478
484
  topP,
479
485
  topK,
@@ -482,111 +488,66 @@ var GoogleGenerativeAILanguageModel = class {
482
488
  stopSequences,
483
489
  responseFormat,
484
490
  seed,
485
- providerMetadata
491
+ tools,
492
+ toolChoice,
493
+ providerOptions
486
494
  }) {
487
495
  var _a, _b;
488
- const type = mode.type;
489
496
  const warnings = [];
490
497
  const googleOptions = (0, import_provider_utils4.parseProviderOptions)({
491
498
  provider: "google",
492
- providerOptions: providerMetadata,
499
+ providerOptions,
493
500
  schema: googleGenerativeAIProviderOptionsSchema
494
501
  });
495
- const generationConfig = {
496
- // standardized settings:
497
- maxOutputTokens: maxTokens,
498
- temperature,
499
- topK,
500
- topP,
501
- frequencyPenalty,
502
- presencePenalty,
503
- stopSequences,
504
- seed,
505
- // response format:
506
- responseMimeType: (responseFormat == null ? void 0 : responseFormat.type) === "json" ? "application/json" : void 0,
507
- responseSchema: (responseFormat == null ? void 0 : responseFormat.type) === "json" && responseFormat.schema != null && // Google GenAI does not support all OpenAPI Schema features,
508
- // so this is needed as an escape hatch:
509
- this.supportsStructuredOutputs ? convertJSONSchemaToOpenAPISchema(responseFormat.schema) : void 0,
510
- ...this.settings.audioTimestamp && {
511
- audioTimestamp: this.settings.audioTimestamp
512
- },
513
- // provider options:
514
- responseModalities: googleOptions == null ? void 0 : googleOptions.responseModalities
515
- };
516
502
  const { contents, systemInstruction } = convertToGoogleGenerativeAIMessages(prompt);
517
- switch (type) {
518
- case "regular": {
519
- const { tools, toolConfig, toolWarnings } = prepareTools(
520
- mode,
521
- (_a = this.settings.useSearchGrounding) != null ? _a : false,
522
- this.settings.dynamicRetrievalConfig,
523
- this.modelId
524
- );
525
- return {
526
- args: {
527
- generationConfig,
528
- contents,
529
- systemInstruction,
530
- safetySettings: this.settings.safetySettings,
531
- tools,
532
- toolConfig,
533
- cachedContent: this.settings.cachedContent
534
- },
535
- warnings: [...warnings, ...toolWarnings]
536
- };
537
- }
538
- case "object-json": {
539
- return {
540
- args: {
541
- generationConfig: {
542
- ...generationConfig,
543
- responseMimeType: "application/json",
544
- responseSchema: mode.schema != null && // Google GenAI does not support all OpenAPI Schema features,
545
- // so this is needed as an escape hatch:
546
- this.supportsStructuredOutputs ? convertJSONSchemaToOpenAPISchema(mode.schema) : void 0
547
- },
548
- contents,
549
- systemInstruction,
550
- safetySettings: this.settings.safetySettings,
551
- cachedContent: this.settings.cachedContent
552
- },
553
- warnings
554
- };
555
- }
556
- case "object-tool": {
557
- return {
558
- args: {
559
- generationConfig,
560
- contents,
561
- tools: {
562
- functionDeclarations: [
563
- {
564
- name: mode.tool.name,
565
- description: (_b = mode.tool.description) != null ? _b : "",
566
- parameters: convertJSONSchemaToOpenAPISchema(
567
- mode.tool.parameters
568
- )
569
- }
570
- ]
571
- },
572
- toolConfig: { functionCallingConfig: { mode: "ANY" } },
573
- safetySettings: this.settings.safetySettings,
574
- cachedContent: this.settings.cachedContent
503
+ const {
504
+ tools: googleTools,
505
+ toolConfig: googleToolConfig,
506
+ toolWarnings
507
+ } = prepareTools({
508
+ tools,
509
+ toolChoice,
510
+ useSearchGrounding: (_a = this.settings.useSearchGrounding) != null ? _a : false,
511
+ dynamicRetrievalConfig: this.settings.dynamicRetrievalConfig,
512
+ modelId: this.modelId
513
+ });
514
+ return {
515
+ args: {
516
+ generationConfig: {
517
+ // standardized settings:
518
+ maxOutputTokens,
519
+ temperature,
520
+ topK,
521
+ topP,
522
+ frequencyPenalty,
523
+ presencePenalty,
524
+ stopSequences,
525
+ seed,
526
+ // response format:
527
+ responseMimeType: (responseFormat == null ? void 0 : responseFormat.type) === "json" ? "application/json" : void 0,
528
+ responseSchema: (responseFormat == null ? void 0 : responseFormat.type) === "json" && responseFormat.schema != null && // Google GenAI does not support all OpenAPI Schema features,
529
+ // so this is needed as an escape hatch:
530
+ // TODO convert into provider option
531
+ ((_b = this.settings.structuredOutputs) != null ? _b : true) ? convertJSONSchemaToOpenAPISchema(responseFormat.schema) : void 0,
532
+ ...this.settings.audioTimestamp && {
533
+ audioTimestamp: this.settings.audioTimestamp
575
534
  },
576
- warnings
577
- };
578
- }
579
- default: {
580
- const _exhaustiveCheck = type;
581
- throw new Error(`Unsupported type: ${_exhaustiveCheck}`);
582
- }
583
- }
584
- }
585
- supportsUrl(url) {
586
- return this.config.isSupportedUrl(url);
535
+ // provider options:
536
+ responseModalities: googleOptions == null ? void 0 : googleOptions.responseModalities,
537
+ thinkingConfig: googleOptions == null ? void 0 : googleOptions.thinkingConfig
538
+ },
539
+ contents,
540
+ systemInstruction,
541
+ safetySettings: this.settings.safetySettings,
542
+ tools: googleTools,
543
+ toolConfig: googleToolConfig,
544
+ cachedContent: this.settings.cachedContent
545
+ },
546
+ warnings: [...warnings, ...toolWarnings]
547
+ };
587
548
  }
588
549
  async doGenerate(options) {
589
- var _a, _b, _c, _d, _e;
550
+ var _a, _b, _c, _d, _e, _f;
590
551
  const { args, warnings } = await this.getArgs(options);
591
552
  const body = JSON.stringify(args);
592
553
  const mergedHeaders = (0, import_provider_utils4.combineHeaders)(
@@ -608,43 +569,59 @@ var GoogleGenerativeAILanguageModel = class {
608
569
  abortSignal: options.abortSignal,
609
570
  fetch: this.config.fetch
610
571
  });
611
- const { contents: rawPrompt, ...rawSettings } = args;
612
572
  const candidate = response.candidates[0];
613
- const parts = candidate.content == null || typeof candidate.content !== "object" || !("parts" in candidate.content) ? [] : candidate.content.parts;
614
- const toolCalls = getToolCallsFromParts({
615
- parts,
573
+ const content = [];
574
+ const parts = candidate.content == null || typeof candidate.content !== "object" || !("parts" in candidate.content) ? [] : (_a = candidate.content.parts) != null ? _a : [];
575
+ for (const part of parts) {
576
+ if ("text" in part && part.text.length > 0) {
577
+ content.push({ type: "text", text: part.text });
578
+ } else if ("functionCall" in part) {
579
+ content.push({
580
+ type: "tool-call",
581
+ toolCallType: "function",
582
+ toolCallId: this.config.generateId(),
583
+ toolName: part.functionCall.name,
584
+ args: JSON.stringify(part.functionCall.args)
585
+ });
586
+ } else if ("inlineData" in part) {
587
+ content.push({
588
+ type: "file",
589
+ data: part.inlineData.data,
590
+ mediaType: part.inlineData.mimeType
591
+ });
592
+ }
593
+ }
594
+ const sources = (_b = extractSources({
595
+ groundingMetadata: candidate.groundingMetadata,
616
596
  generateId: this.config.generateId
617
- });
597
+ })) != null ? _b : [];
598
+ for (const source of sources) {
599
+ content.push(source);
600
+ }
618
601
  const usageMetadata = response.usageMetadata;
619
602
  return {
620
- text: getTextFromParts(parts),
621
- files: (_a = getInlineDataParts(parts)) == null ? void 0 : _a.map((part) => ({
622
- data: part.inlineData.data,
623
- mimeType: part.inlineData.mimeType
624
- })),
625
- toolCalls,
603
+ content,
626
604
  finishReason: mapGoogleGenerativeAIFinishReason({
627
605
  finishReason: candidate.finishReason,
628
- hasToolCalls: toolCalls != null && toolCalls.length > 0
606
+ hasToolCalls: content.some((part) => part.type === "tool-call")
629
607
  }),
630
608
  usage: {
631
- promptTokens: (_b = usageMetadata == null ? void 0 : usageMetadata.promptTokenCount) != null ? _b : NaN,
632
- completionTokens: (_c = usageMetadata == null ? void 0 : usageMetadata.candidatesTokenCount) != null ? _c : NaN
609
+ inputTokens: (_c = usageMetadata == null ? void 0 : usageMetadata.promptTokenCount) != null ? _c : void 0,
610
+ outputTokens: (_d = usageMetadata == null ? void 0 : usageMetadata.candidatesTokenCount) != null ? _d : void 0
633
611
  },
634
- rawCall: { rawPrompt, rawSettings },
635
- rawResponse: { headers: responseHeaders, body: rawResponse },
636
612
  warnings,
637
613
  providerMetadata: {
638
614
  google: {
639
- groundingMetadata: (_d = candidate.groundingMetadata) != null ? _d : null,
640
- safetyRatings: (_e = candidate.safetyRatings) != null ? _e : null
615
+ groundingMetadata: (_e = candidate.groundingMetadata) != null ? _e : null,
616
+ safetyRatings: (_f = candidate.safetyRatings) != null ? _f : null
641
617
  }
642
618
  },
643
- sources: extractSources({
644
- groundingMetadata: candidate.groundingMetadata,
645
- generateId: this.config.generateId
646
- }),
647
- request: { body }
619
+ request: { body },
620
+ response: {
621
+ // TODO timestamp, model id, id
622
+ headers: responseHeaders,
623
+ body: rawResponse
624
+ }
648
625
  };
649
626
  }
650
627
  async doStream(options) {
@@ -665,11 +642,10 @@ var GoogleGenerativeAILanguageModel = class {
665
642
  abortSignal: options.abortSignal,
666
643
  fetch: this.config.fetch
667
644
  });
668
- const { contents: rawPrompt, ...rawSettings } = args;
669
645
  let finishReason = "unknown";
670
- let usage = {
671
- promptTokens: Number.NaN,
672
- completionTokens: Number.NaN
646
+ const usage = {
647
+ inputTokens: void 0,
648
+ outputTokens: void 0
673
649
  };
674
650
  let providerMetadata = void 0;
675
651
  const generateId2 = this.config.generateId;
@@ -677,6 +653,9 @@ var GoogleGenerativeAILanguageModel = class {
677
653
  return {
678
654
  stream: response.pipeThrough(
679
655
  new TransformStream({
656
+ start(controller) {
657
+ controller.enqueue({ type: "stream-start", warnings });
658
+ },
680
659
  transform(chunk, controller) {
681
660
  var _a, _b, _c, _d, _e, _f;
682
661
  if (!chunk.success) {
@@ -686,10 +665,8 @@ var GoogleGenerativeAILanguageModel = class {
686
665
  const value = chunk.value;
687
666
  const usageMetadata = value.usageMetadata;
688
667
  if (usageMetadata != null) {
689
- usage = {
690
- promptTokens: (_a = usageMetadata.promptTokenCount) != null ? _a : NaN,
691
- completionTokens: (_b = usageMetadata.candidatesTokenCount) != null ? _b : NaN
692
- };
668
+ usage.inputTokens = (_a = usageMetadata.promptTokenCount) != null ? _a : void 0;
669
+ usage.outputTokens = (_b = usageMetadata.candidatesTokenCount) != null ? _b : void 0;
693
670
  }
694
671
  const candidate = (_c = value.candidates) == null ? void 0 : _c[0];
695
672
  if (candidate == null) {
@@ -699,17 +676,14 @@ var GoogleGenerativeAILanguageModel = class {
699
676
  if (content != null) {
700
677
  const deltaText = getTextFromParts(content.parts);
701
678
  if (deltaText != null) {
702
- controller.enqueue({
703
- type: "text-delta",
704
- textDelta: deltaText
705
- });
679
+ controller.enqueue(deltaText);
706
680
  }
707
681
  const inlineDataParts = getInlineDataParts(content.parts);
708
682
  if (inlineDataParts != null) {
709
683
  for (const part of inlineDataParts) {
710
684
  controller.enqueue({
711
685
  type: "file",
712
- mimeType: part.inlineData.mimeType,
686
+ mediaType: part.inlineData.mimeType,
713
687
  data: part.inlineData.data
714
688
  });
715
689
  }
@@ -748,7 +722,7 @@ var GoogleGenerativeAILanguageModel = class {
748
722
  generateId: generateId2
749
723
  })) != null ? _d : [];
750
724
  for (const source of sources) {
751
- controller.enqueue({ type: "source", source });
725
+ controller.enqueue(source);
752
726
  }
753
727
  providerMetadata = {
754
728
  google: {
@@ -768,9 +742,7 @@ var GoogleGenerativeAILanguageModel = class {
768
742
  }
769
743
  })
770
744
  ),
771
- rawCall: { rawPrompt, rawSettings },
772
- rawResponse: { headers: responseHeaders },
773
- warnings,
745
+ response: { headers: responseHeaders },
774
746
  request: { body }
775
747
  };
776
748
  }
@@ -783,6 +755,7 @@ function getToolCallsFromParts({
783
755
  (part) => "functionCall" in part
784
756
  );
785
757
  return functionCallParts == null || functionCallParts.length === 0 ? void 0 : functionCallParts.map((part) => ({
758
+ type: "tool-call",
786
759
  toolCallType: "function",
787
760
  toolCallId: generateId2(),
788
761
  toolName: part.functionCall.name,
@@ -791,7 +764,10 @@ function getToolCallsFromParts({
791
764
  }
792
765
  function getTextFromParts(parts) {
793
766
  const textParts = parts == null ? void 0 : parts.filter((part) => "text" in part);
794
- return textParts == null || textParts.length === 0 ? void 0 : textParts.map((part) => part.text).join("");
767
+ return textParts == null || textParts.length === 0 ? void 0 : {
768
+ type: "text",
769
+ text: textParts.map((part) => part.text).join("")
770
+ };
795
771
  }
796
772
  function getInlineDataParts(parts) {
797
773
  return parts == null ? void 0 : parts.filter(
@@ -806,111 +782,110 @@ function extractSources({
806
782
  return (_a = groundingMetadata == null ? void 0 : groundingMetadata.groundingChunks) == null ? void 0 : _a.filter(
807
783
  (chunk) => chunk.web != null
808
784
  ).map((chunk) => ({
785
+ type: "source",
809
786
  sourceType: "url",
810
787
  id: generateId2(),
811
788
  url: chunk.web.uri,
812
789
  title: chunk.web.title
813
790
  }));
814
791
  }
815
- var contentSchema = import_zod3.z.object({
816
- role: import_zod3.z.string(),
817
- parts: import_zod3.z.array(
818
- import_zod3.z.union([
819
- import_zod3.z.object({
820
- text: import_zod3.z.string()
792
+ var contentSchema = import_zod4.z.object({
793
+ role: import_zod4.z.string(),
794
+ parts: import_zod4.z.array(
795
+ import_zod4.z.union([
796
+ import_zod4.z.object({
797
+ text: import_zod4.z.string()
821
798
  }),
822
- import_zod3.z.object({
823
- functionCall: import_zod3.z.object({
824
- name: import_zod3.z.string(),
825
- args: import_zod3.z.unknown()
799
+ import_zod4.z.object({
800
+ functionCall: import_zod4.z.object({
801
+ name: import_zod4.z.string(),
802
+ args: import_zod4.z.unknown()
826
803
  })
827
804
  }),
828
- import_zod3.z.object({
829
- inlineData: import_zod3.z.object({
830
- mimeType: import_zod3.z.string(),
831
- data: import_zod3.z.string()
805
+ import_zod4.z.object({
806
+ inlineData: import_zod4.z.object({
807
+ mimeType: import_zod4.z.string(),
808
+ data: import_zod4.z.string()
832
809
  })
833
810
  })
834
811
  ])
835
812
  ).nullish()
836
813
  });
837
- var groundingChunkSchema = import_zod3.z.object({
838
- web: import_zod3.z.object({ uri: import_zod3.z.string(), title: import_zod3.z.string() }).nullish(),
839
- retrievedContext: import_zod3.z.object({ uri: import_zod3.z.string(), title: import_zod3.z.string() }).nullish()
814
+ var groundingChunkSchema = import_zod4.z.object({
815
+ web: import_zod4.z.object({ uri: import_zod4.z.string(), title: import_zod4.z.string() }).nullish(),
816
+ retrievedContext: import_zod4.z.object({ uri: import_zod4.z.string(), title: import_zod4.z.string() }).nullish()
840
817
  });
841
- var groundingMetadataSchema = import_zod3.z.object({
842
- webSearchQueries: import_zod3.z.array(import_zod3.z.string()).nullish(),
843
- retrievalQueries: import_zod3.z.array(import_zod3.z.string()).nullish(),
844
- searchEntryPoint: import_zod3.z.object({ renderedContent: import_zod3.z.string() }).nullish(),
845
- groundingChunks: import_zod3.z.array(groundingChunkSchema).nullish(),
846
- groundingSupports: import_zod3.z.array(
847
- import_zod3.z.object({
848
- segment: import_zod3.z.object({
849
- startIndex: import_zod3.z.number().nullish(),
850
- endIndex: import_zod3.z.number().nullish(),
851
- text: import_zod3.z.string().nullish()
818
+ var groundingMetadataSchema = import_zod4.z.object({
819
+ webSearchQueries: import_zod4.z.array(import_zod4.z.string()).nullish(),
820
+ retrievalQueries: import_zod4.z.array(import_zod4.z.string()).nullish(),
821
+ searchEntryPoint: import_zod4.z.object({ renderedContent: import_zod4.z.string() }).nullish(),
822
+ groundingChunks: import_zod4.z.array(groundingChunkSchema).nullish(),
823
+ groundingSupports: import_zod4.z.array(
824
+ import_zod4.z.object({
825
+ segment: import_zod4.z.object({
826
+ startIndex: import_zod4.z.number().nullish(),
827
+ endIndex: import_zod4.z.number().nullish(),
828
+ text: import_zod4.z.string().nullish()
852
829
  }),
853
- segment_text: import_zod3.z.string().nullish(),
854
- groundingChunkIndices: import_zod3.z.array(import_zod3.z.number()).nullish(),
855
- supportChunkIndices: import_zod3.z.array(import_zod3.z.number()).nullish(),
856
- confidenceScores: import_zod3.z.array(import_zod3.z.number()).nullish(),
857
- confidenceScore: import_zod3.z.array(import_zod3.z.number()).nullish()
830
+ segment_text: import_zod4.z.string().nullish(),
831
+ groundingChunkIndices: import_zod4.z.array(import_zod4.z.number()).nullish(),
832
+ supportChunkIndices: import_zod4.z.array(import_zod4.z.number()).nullish(),
833
+ confidenceScores: import_zod4.z.array(import_zod4.z.number()).nullish(),
834
+ confidenceScore: import_zod4.z.array(import_zod4.z.number()).nullish()
858
835
  })
859
836
  ).nullish(),
860
- retrievalMetadata: import_zod3.z.union([
861
- import_zod3.z.object({
862
- webDynamicRetrievalScore: import_zod3.z.number()
837
+ retrievalMetadata: import_zod4.z.union([
838
+ import_zod4.z.object({
839
+ webDynamicRetrievalScore: import_zod4.z.number()
863
840
  }),
864
- import_zod3.z.object({})
841
+ import_zod4.z.object({})
865
842
  ]).nullish()
866
843
  });
867
- var safetyRatingSchema = import_zod3.z.object({
868
- category: import_zod3.z.string(),
869
- probability: import_zod3.z.string(),
870
- probabilityScore: import_zod3.z.number().nullish(),
871
- severity: import_zod3.z.string().nullish(),
872
- severityScore: import_zod3.z.number().nullish(),
873
- blocked: import_zod3.z.boolean().nullish()
844
+ var safetyRatingSchema = import_zod4.z.object({
845
+ category: import_zod4.z.string(),
846
+ probability: import_zod4.z.string(),
847
+ probabilityScore: import_zod4.z.number().nullish(),
848
+ severity: import_zod4.z.string().nullish(),
849
+ severityScore: import_zod4.z.number().nullish(),
850
+ blocked: import_zod4.z.boolean().nullish()
874
851
  });
875
- var responseSchema = import_zod3.z.object({
876
- candidates: import_zod3.z.array(
877
- import_zod3.z.object({
878
- content: contentSchema.nullish().or(import_zod3.z.object({}).strict()),
879
- finishReason: import_zod3.z.string().nullish(),
880
- safetyRatings: import_zod3.z.array(safetyRatingSchema).nullish(),
852
+ var responseSchema = import_zod4.z.object({
853
+ candidates: import_zod4.z.array(
854
+ import_zod4.z.object({
855
+ content: contentSchema.nullish().or(import_zod4.z.object({}).strict()),
856
+ finishReason: import_zod4.z.string().nullish(),
857
+ safetyRatings: import_zod4.z.array(safetyRatingSchema).nullish(),
881
858
  groundingMetadata: groundingMetadataSchema.nullish()
882
859
  })
883
860
  ),
884
- usageMetadata: import_zod3.z.object({
885
- promptTokenCount: import_zod3.z.number().nullish(),
886
- candidatesTokenCount: import_zod3.z.number().nullish(),
887
- totalTokenCount: import_zod3.z.number().nullish()
861
+ usageMetadata: import_zod4.z.object({
862
+ promptTokenCount: import_zod4.z.number().nullish(),
863
+ candidatesTokenCount: import_zod4.z.number().nullish(),
864
+ totalTokenCount: import_zod4.z.number().nullish()
888
865
  }).nullish()
889
866
  });
890
- var chunkSchema = import_zod3.z.object({
891
- candidates: import_zod3.z.array(
892
- import_zod3.z.object({
867
+ var chunkSchema = import_zod4.z.object({
868
+ candidates: import_zod4.z.array(
869
+ import_zod4.z.object({
893
870
  content: contentSchema.nullish(),
894
- finishReason: import_zod3.z.string().nullish(),
895
- safetyRatings: import_zod3.z.array(safetyRatingSchema).nullish(),
871
+ finishReason: import_zod4.z.string().nullish(),
872
+ safetyRatings: import_zod4.z.array(safetyRatingSchema).nullish(),
896
873
  groundingMetadata: groundingMetadataSchema.nullish()
897
874
  })
898
875
  ).nullish(),
899
- usageMetadata: import_zod3.z.object({
900
- promptTokenCount: import_zod3.z.number().nullish(),
901
- candidatesTokenCount: import_zod3.z.number().nullish(),
902
- totalTokenCount: import_zod3.z.number().nullish()
876
+ usageMetadata: import_zod4.z.object({
877
+ promptTokenCount: import_zod4.z.number().nullish(),
878
+ candidatesTokenCount: import_zod4.z.number().nullish(),
879
+ totalTokenCount: import_zod4.z.number().nullish()
903
880
  }).nullish()
904
881
  });
905
- var googleGenerativeAIProviderOptionsSchema = import_zod3.z.object({
906
- responseModalities: import_zod3.z.array(import_zod3.z.enum(["TEXT", "IMAGE"])).nullish()
882
+ var googleGenerativeAIProviderOptionsSchema = import_zod4.z.object({
883
+ responseModalities: import_zod4.z.array(import_zod4.z.enum(["TEXT", "IMAGE"])).nullish(),
884
+ thinkingConfig: import_zod4.z.object({
885
+ thinkingBudget: import_zod4.z.number().nullish()
886
+ }).nullish()
907
887
  });
908
888
 
909
- // src/google-supported-file-url.ts
910
- function isSupportedFileUrl(url) {
911
- return url.toString().startsWith("https://generativelanguage.googleapis.com/v1beta/files/");
912
- }
913
-
914
889
  // src/google-provider.ts
915
890
  function createGoogleGenerativeAI(options = {}) {
916
891
  var _a;
@@ -930,11 +905,16 @@ function createGoogleGenerativeAI(options = {}) {
930
905
  baseURL,
931
906
  headers: getHeaders,
932
907
  generateId: (_a2 = options.generateId) != null ? _a2 : import_provider_utils5.generateId,
933
- isSupportedUrl: isSupportedFileUrl,
908
+ getSupportedUrls: async () => ({
909
+ "*": [
910
+ // HTTP URLs:
911
+ /^https?:\/\/.*$/
912
+ ]
913
+ }),
934
914
  fetch: options.fetch
935
915
  });
936
916
  };
937
- const createEmbeddingModel = (modelId, settings = {}) => new GoogleGenerativeAIEmbeddingModel(modelId, settings, {
917
+ const createEmbeddingModel = (modelId) => new GoogleGenerativeAIEmbeddingModel(modelId, {
938
918
  provider: "google.generative-ai",
939
919
  baseURL,
940
920
  headers: getHeaders,