@ai-sdk/google 3.0.51 → 3.0.53

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -1,5 +1,26 @@
1
1
  # @ai-sdk/google
2
2
 
3
+ ## 3.0.53
4
+
5
+ ### Patch Changes
6
+
7
+ - 2e5adff: chore(provider/google): remove obsolete Google image model
8
+
9
+ ## 3.0.52
10
+
11
+ ### Patch Changes
12
+
13
+ - 055cd68: fix: publish v6 to latest npm dist tag
14
+ - 47114a3: feat(provider/google): Add multimodal tool-result support for Google function responses.
15
+
16
+ Tool results with `output.type = 'content'` now map media parts into
17
+ `functionResponse.parts` for Google models, including `image-data`,
18
+ `file-data`, and base64 `data:` URLs in URL-style content parts.
19
+ Remote HTTP(S) URLs in URL-style tool-result parts are not supported.
20
+
21
+ - Updated dependencies [055cd68]
22
+ - @ai-sdk/provider-utils@4.0.21
23
+
3
24
  ## 3.0.51
4
25
 
5
26
  ### Patch Changes
@@ -363,13 +384,13 @@
363
384
  Before
364
385
 
365
386
  ```ts
366
- model.textEmbeddingModel('my-model-id');
387
+ model.textEmbeddingModel("my-model-id");
367
388
  ```
368
389
 
369
390
  After
370
391
 
371
392
  ```ts
372
- model.embeddingModel('my-model-id');
393
+ model.embeddingModel("my-model-id");
373
394
  ```
374
395
 
375
396
  - 2625a04: feat(openai); update spec for mcp approval
@@ -678,13 +699,13 @@
678
699
  Before
679
700
 
680
701
  ```ts
681
- model.textEmbeddingModel('my-model-id');
702
+ model.textEmbeddingModel("my-model-id");
682
703
  ```
683
704
 
684
705
  After
685
706
 
686
707
  ```ts
687
- model.embeddingModel('my-model-id');
708
+ model.embeddingModel("my-model-id");
688
709
  ```
689
710
 
690
711
  - Updated dependencies [8d9e8ad]
package/dist/index.d.mts CHANGED
@@ -11,7 +11,7 @@ declare const googleErrorDataSchema: _ai_sdk_provider_utils.LazySchema<{
11
11
  }>;
12
12
  type GoogleErrorData = InferSchema<typeof googleErrorDataSchema>;
13
13
 
14
- type GoogleGenerativeAIModelId = 'gemini-2.0-flash' | 'gemini-2.0-flash-001' | 'gemini-2.0-flash-lite' | 'gemini-2.0-flash-exp-image-generation' | 'gemini-2.0-flash-lite-001' | 'gemini-2.5-pro' | 'gemini-2.5-flash' | 'gemini-2.5-flash-image' | 'gemini-2.5-flash-lite' | 'gemini-2.5-flash-lite-preview-09-2025' | 'gemini-2.5-flash-preview-tts' | 'gemini-2.5-pro-preview-tts' | 'gemini-2.5-flash-native-audio-latest' | 'gemini-2.5-flash-native-audio-preview-09-2025' | 'gemini-2.5-flash-native-audio-preview-12-2025' | 'gemini-2.5-computer-use-preview-10-2025' | 'gemini-3-pro-preview' | 'gemini-3-pro-image-preview' | 'gemini-3-flash-preview' | 'gemini-3.1-pro-preview' | 'gemini-3.1-pro-preview-customtools' | 'gemini-3.1-flash-image-preview' | 'gemini-3.1-flash-lite-preview' | 'gemini-pro-latest' | 'gemini-flash-latest' | 'gemini-flash-lite-latest' | 'deep-research-pro-preview-12-2025' | 'nano-banana-pro-preview' | 'aqa' | 'gemini-robotics-er-1.5-preview' | 'gemma-3-1b-it' | 'gemma-3-4b-it' | 'gemma-3n-e4b-it' | 'gemma-3n-e2b-it' | 'gemma-3-12b-it' | 'gemma-3-27b-it' | (string & {});
14
+ type GoogleGenerativeAIModelId = 'gemini-2.0-flash' | 'gemini-2.0-flash-001' | 'gemini-2.0-flash-lite' | 'gemini-2.0-flash-lite-001' | 'gemini-2.5-pro' | 'gemini-2.5-flash' | 'gemini-2.5-flash-image' | 'gemini-2.5-flash-lite' | 'gemini-2.5-flash-lite-preview-09-2025' | 'gemini-2.5-flash-preview-tts' | 'gemini-2.5-pro-preview-tts' | 'gemini-2.5-flash-native-audio-latest' | 'gemini-2.5-flash-native-audio-preview-09-2025' | 'gemini-2.5-flash-native-audio-preview-12-2025' | 'gemini-2.5-computer-use-preview-10-2025' | 'gemini-3-pro-preview' | 'gemini-3-pro-image-preview' | 'gemini-3-flash-preview' | 'gemini-3.1-pro-preview' | 'gemini-3.1-pro-preview-customtools' | 'gemini-3.1-flash-image-preview' | 'gemini-3.1-flash-lite-preview' | 'gemini-pro-latest' | 'gemini-flash-latest' | 'gemini-flash-lite-latest' | 'deep-research-pro-preview-12-2025' | 'nano-banana-pro-preview' | 'aqa' | 'gemini-robotics-er-1.5-preview' | 'gemma-3-1b-it' | 'gemma-3-4b-it' | 'gemma-3n-e4b-it' | 'gemma-3n-e2b-it' | 'gemma-3-12b-it' | 'gemma-3-27b-it' | (string & {});
15
15
  declare const googleLanguageModelOptions: _ai_sdk_provider_utils.LazySchema<{
16
16
  responseModalities?: ("TEXT" | "IMAGE")[] | undefined;
17
17
  thinkingConfig?: {
package/dist/index.d.ts CHANGED
@@ -11,7 +11,7 @@ declare const googleErrorDataSchema: _ai_sdk_provider_utils.LazySchema<{
11
11
  }>;
12
12
  type GoogleErrorData = InferSchema<typeof googleErrorDataSchema>;
13
13
 
14
- type GoogleGenerativeAIModelId = 'gemini-2.0-flash' | 'gemini-2.0-flash-001' | 'gemini-2.0-flash-lite' | 'gemini-2.0-flash-exp-image-generation' | 'gemini-2.0-flash-lite-001' | 'gemini-2.5-pro' | 'gemini-2.5-flash' | 'gemini-2.5-flash-image' | 'gemini-2.5-flash-lite' | 'gemini-2.5-flash-lite-preview-09-2025' | 'gemini-2.5-flash-preview-tts' | 'gemini-2.5-pro-preview-tts' | 'gemini-2.5-flash-native-audio-latest' | 'gemini-2.5-flash-native-audio-preview-09-2025' | 'gemini-2.5-flash-native-audio-preview-12-2025' | 'gemini-2.5-computer-use-preview-10-2025' | 'gemini-3-pro-preview' | 'gemini-3-pro-image-preview' | 'gemini-3-flash-preview' | 'gemini-3.1-pro-preview' | 'gemini-3.1-pro-preview-customtools' | 'gemini-3.1-flash-image-preview' | 'gemini-3.1-flash-lite-preview' | 'gemini-pro-latest' | 'gemini-flash-latest' | 'gemini-flash-lite-latest' | 'deep-research-pro-preview-12-2025' | 'nano-banana-pro-preview' | 'aqa' | 'gemini-robotics-er-1.5-preview' | 'gemma-3-1b-it' | 'gemma-3-4b-it' | 'gemma-3n-e4b-it' | 'gemma-3n-e2b-it' | 'gemma-3-12b-it' | 'gemma-3-27b-it' | (string & {});
14
+ type GoogleGenerativeAIModelId = 'gemini-2.0-flash' | 'gemini-2.0-flash-001' | 'gemini-2.0-flash-lite' | 'gemini-2.0-flash-lite-001' | 'gemini-2.5-pro' | 'gemini-2.5-flash' | 'gemini-2.5-flash-image' | 'gemini-2.5-flash-lite' | 'gemini-2.5-flash-lite-preview-09-2025' | 'gemini-2.5-flash-preview-tts' | 'gemini-2.5-pro-preview-tts' | 'gemini-2.5-flash-native-audio-latest' | 'gemini-2.5-flash-native-audio-preview-09-2025' | 'gemini-2.5-flash-native-audio-preview-12-2025' | 'gemini-2.5-computer-use-preview-10-2025' | 'gemini-3-pro-preview' | 'gemini-3-pro-image-preview' | 'gemini-3-flash-preview' | 'gemini-3.1-pro-preview' | 'gemini-3.1-pro-preview-customtools' | 'gemini-3.1-flash-image-preview' | 'gemini-3.1-flash-lite-preview' | 'gemini-pro-latest' | 'gemini-flash-latest' | 'gemini-flash-lite-latest' | 'deep-research-pro-preview-12-2025' | 'nano-banana-pro-preview' | 'aqa' | 'gemini-robotics-er-1.5-preview' | 'gemma-3-1b-it' | 'gemma-3-4b-it' | 'gemma-3n-e4b-it' | 'gemma-3n-e2b-it' | 'gemma-3-12b-it' | 'gemma-3-27b-it' | (string & {});
15
15
  declare const googleLanguageModelOptions: _ai_sdk_provider_utils.LazySchema<{
16
16
  responseModalities?: ("TEXT" | "IMAGE")[] | undefined;
17
17
  thinkingConfig?: {
package/dist/index.js CHANGED
@@ -18,19 +18,19 @@ var __copyProps = (to, from, except, desc) => {
18
18
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
19
 
20
20
  // src/index.ts
21
- var src_exports = {};
22
- __export(src_exports, {
21
+ var index_exports = {};
22
+ __export(index_exports, {
23
23
  VERSION: () => VERSION,
24
24
  createGoogleGenerativeAI: () => createGoogleGenerativeAI,
25
25
  google: () => google
26
26
  });
27
- module.exports = __toCommonJS(src_exports);
27
+ module.exports = __toCommonJS(index_exports);
28
28
 
29
29
  // src/google-provider.ts
30
30
  var import_provider_utils16 = require("@ai-sdk/provider-utils");
31
31
 
32
32
  // src/version.ts
33
- var VERSION = true ? "3.0.51" : "0.0.0-test";
33
+ var VERSION = true ? "3.0.53" : "0.0.0-test";
34
34
 
35
35
  // src/google-generative-ai-embedding-model.ts
36
36
  var import_provider = require("@ai-sdk/provider");
@@ -400,13 +400,118 @@ function isEmptyObjectSchema(jsonSchema) {
400
400
  // src/convert-to-google-generative-ai-messages.ts
401
401
  var import_provider2 = require("@ai-sdk/provider");
402
402
  var import_provider_utils4 = require("@ai-sdk/provider-utils");
403
+ var dataUrlRegex = /^data:([^;,]+);base64,(.+)$/s;
404
+ function parseBase64DataUrl(value) {
405
+ const match = dataUrlRegex.exec(value);
406
+ if (match == null) {
407
+ return void 0;
408
+ }
409
+ return {
410
+ mediaType: match[1],
411
+ data: match[2]
412
+ };
413
+ }
414
+ function convertUrlToolResultPart(url) {
415
+ const parsedDataUrl = parseBase64DataUrl(url);
416
+ if (parsedDataUrl == null) {
417
+ return void 0;
418
+ }
419
+ return {
420
+ inlineData: {
421
+ mimeType: parsedDataUrl.mediaType,
422
+ data: parsedDataUrl.data
423
+ }
424
+ };
425
+ }
426
+ function appendToolResultParts(parts, toolName, outputValue) {
427
+ const functionResponseParts = [];
428
+ const responseTextParts = [];
429
+ for (const contentPart of outputValue) {
430
+ switch (contentPart.type) {
431
+ case "text": {
432
+ responseTextParts.push(contentPart.text);
433
+ break;
434
+ }
435
+ case "image-data":
436
+ case "file-data": {
437
+ functionResponseParts.push({
438
+ inlineData: {
439
+ mimeType: contentPart.mediaType,
440
+ data: contentPart.data
441
+ }
442
+ });
443
+ break;
444
+ }
445
+ case "image-url":
446
+ case "file-url": {
447
+ const functionResponsePart = convertUrlToolResultPart(
448
+ contentPart.url
449
+ );
450
+ if (functionResponsePart != null) {
451
+ functionResponseParts.push(functionResponsePart);
452
+ } else {
453
+ responseTextParts.push(JSON.stringify(contentPart));
454
+ }
455
+ break;
456
+ }
457
+ default: {
458
+ responseTextParts.push(JSON.stringify(contentPart));
459
+ break;
460
+ }
461
+ }
462
+ }
463
+ parts.push({
464
+ functionResponse: {
465
+ name: toolName,
466
+ response: {
467
+ name: toolName,
468
+ content: responseTextParts.length > 0 ? responseTextParts.join("\n") : "Tool executed successfully."
469
+ },
470
+ ...functionResponseParts.length > 0 ? { parts: functionResponseParts } : {}
471
+ }
472
+ });
473
+ }
474
+ function appendLegacyToolResultParts(parts, toolName, outputValue) {
475
+ for (const contentPart of outputValue) {
476
+ switch (contentPart.type) {
477
+ case "text":
478
+ parts.push({
479
+ functionResponse: {
480
+ name: toolName,
481
+ response: {
482
+ name: toolName,
483
+ content: contentPart.text
484
+ }
485
+ }
486
+ });
487
+ break;
488
+ case "image-data":
489
+ parts.push(
490
+ {
491
+ inlineData: {
492
+ mimeType: String(contentPart.mediaType),
493
+ data: String(contentPart.data)
494
+ }
495
+ },
496
+ {
497
+ text: "Tool executed successfully and returned this image as a response"
498
+ }
499
+ );
500
+ break;
501
+ default:
502
+ parts.push({ text: JSON.stringify(contentPart) });
503
+ break;
504
+ }
505
+ }
506
+ }
403
507
  function convertToGoogleGenerativeAIMessages(prompt, options) {
404
- var _a, _b, _c;
508
+ var _a, _b, _c, _d;
405
509
  const systemInstructionParts = [];
406
510
  const contents = [];
407
511
  let systemMessagesAllowed = true;
408
512
  const isGemmaModel = (_a = options == null ? void 0 : options.isGemmaModel) != null ? _a : false;
409
513
  const providerOptionsName = (_b = options == null ? void 0 : options.providerOptionsName) != null ? _b : "google";
514
+ const supportsFunctionResponseParts = (_c = options == null ? void 0 : options.supportsFunctionResponseParts) != null ? _c : true;
410
515
  for (const { role, content } of prompt) {
411
516
  switch (role) {
412
517
  case "system": {
@@ -454,8 +559,8 @@ function convertToGoogleGenerativeAIMessages(prompt, options) {
454
559
  contents.push({
455
560
  role: "model",
456
561
  parts: content.map((part) => {
457
- var _a2, _b2, _c2, _d;
458
- const providerOpts = (_d = (_a2 = part.providerOptions) == null ? void 0 : _a2[providerOptionsName]) != null ? _d : providerOptionsName !== "google" ? (_b2 = part.providerOptions) == null ? void 0 : _b2.google : (_c2 = part.providerOptions) == null ? void 0 : _c2.vertex;
562
+ var _a2, _b2, _c2, _d2;
563
+ const providerOpts = (_d2 = (_a2 = part.providerOptions) == null ? void 0 : _a2[providerOptionsName]) != null ? _d2 : providerOptionsName !== "google" ? (_b2 = part.providerOptions) == null ? void 0 : _b2.google : (_c2 = part.providerOptions) == null ? void 0 : _c2.vertex;
459
564
  const thoughtSignature = (providerOpts == null ? void 0 : providerOpts.thoughtSignature) != null ? String(providerOpts.thoughtSignature) : void 0;
460
565
  switch (part.type) {
461
566
  case "text": {
@@ -509,36 +614,10 @@ function convertToGoogleGenerativeAIMessages(prompt, options) {
509
614
  }
510
615
  const output = part.output;
511
616
  if (output.type === "content") {
512
- for (const contentPart of output.value) {
513
- switch (contentPart.type) {
514
- case "text":
515
- parts.push({
516
- functionResponse: {
517
- name: part.toolName,
518
- response: {
519
- name: part.toolName,
520
- content: contentPart.text
521
- }
522
- }
523
- });
524
- break;
525
- case "image-data":
526
- parts.push(
527
- {
528
- inlineData: {
529
- mimeType: contentPart.mediaType,
530
- data: contentPart.data
531
- }
532
- },
533
- {
534
- text: "Tool executed successfully and returned this image as a response"
535
- }
536
- );
537
- break;
538
- default:
539
- parts.push({ text: JSON.stringify(contentPart) });
540
- break;
541
- }
617
+ if (supportsFunctionResponseParts) {
618
+ appendToolResultParts(parts, part.toolName, output.value);
619
+ } else {
620
+ appendLegacyToolResultParts(parts, part.toolName, output.value);
542
621
  }
543
622
  } else {
544
623
  parts.push({
@@ -546,7 +625,7 @@ function convertToGoogleGenerativeAIMessages(prompt, options) {
546
625
  name: part.toolName,
547
626
  response: {
548
627
  name: part.toolName,
549
- content: output.type === "execution-denied" ? (_c = output.reason) != null ? _c : "Tool execution denied." : output.value
628
+ content: output.type === "execution-denied" ? (_d = output.reason) != null ? _d : "Tool execution denied." : output.value
550
629
  }
551
630
  }
552
631
  });
@@ -988,9 +1067,14 @@ var GoogleGenerativeAILanguageModel = class {
988
1067
  });
989
1068
  }
990
1069
  const isGemmaModel = this.modelId.toLowerCase().startsWith("gemma-");
1070
+ const supportsFunctionResponseParts = this.modelId.startsWith("gemini-3");
991
1071
  const { contents, systemInstruction } = convertToGoogleGenerativeAIMessages(
992
1072
  prompt,
993
- { isGemmaModel, providerOptionsName }
1073
+ {
1074
+ isGemmaModel,
1075
+ providerOptionsName,
1076
+ supportsFunctionResponseParts
1077
+ }
994
1078
  );
995
1079
  const {
996
1080
  tools: googleTools2,