@ai-sdk/google 2.0.62 → 2.0.63

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,16 @@
1
1
  # @ai-sdk/google
2
2
 
3
+ ## 2.0.63
4
+
5
+ ### Patch Changes
6
+
7
+ - 7655bcf: feat(provider/google): Add multimodal tool-result support for Google function responses.
8
+
9
+ Tool results with `output.type = 'content'` now map media parts into
10
+ `functionResponse.parts` for Google models, including `image-data`,
11
+ `file-data`, and base64 `data:` URLs in URL-style content parts.
12
+ Remote HTTP(S) URLs in URL-style tool-result parts are not supported.
13
+
3
14
  ## 2.0.62
4
15
 
5
16
  ### Patch Changes
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_utils15 = require("@ai-sdk/provider-utils");
31
31
 
32
32
  // src/version.ts
33
- var VERSION = true ? "2.0.62" : "0.0.0-test";
33
+ var VERSION = true ? "2.0.63" : "0.0.0-test";
34
34
 
35
35
  // src/google-generative-ai-embedding-model.ts
36
36
  var import_provider = require("@ai-sdk/provider");
@@ -360,11 +360,12 @@ function isEmptyObjectSchema(jsonSchema) {
360
360
  var import_provider2 = require("@ai-sdk/provider");
361
361
  var import_provider_utils4 = require("@ai-sdk/provider-utils");
362
362
  function convertToGoogleGenerativeAIMessages(prompt, options) {
363
- var _a;
363
+ var _a, _b;
364
364
  const systemInstructionParts = [];
365
365
  const contents = [];
366
366
  let systemMessagesAllowed = true;
367
367
  const isGemmaModel = (_a = options == null ? void 0 : options.isGemmaModel) != null ? _a : false;
368
+ const supportsFunctionResponseParts = (_b = options == null ? void 0 : options.supportsFunctionResponseParts) != null ? _b : true;
368
369
  for (const { role, content } of prompt) {
369
370
  switch (role) {
370
371
  case "system": {
@@ -412,8 +413,8 @@ function convertToGoogleGenerativeAIMessages(prompt, options) {
412
413
  contents.push({
413
414
  role: "model",
414
415
  parts: content.map((part) => {
415
- var _a2, _b, _c;
416
- const thoughtSignature = ((_b = (_a2 = part.providerOptions) == null ? void 0 : _a2.google) == null ? void 0 : _b.thoughtSignature) != null ? String((_c = part.providerOptions.google) == null ? void 0 : _c.thoughtSignature) : void 0;
416
+ var _a2, _b2, _c;
417
+ const thoughtSignature = ((_b2 = (_a2 = part.providerOptions) == null ? void 0 : _a2.google) == null ? void 0 : _b2.thoughtSignature) != null ? String((_c = part.providerOptions.google) == null ? void 0 : _c.thoughtSignature) : void 0;
417
418
  switch (part.type) {
418
419
  case "text": {
419
420
  return part.text.length === 0 ? void 0 : {
@@ -466,36 +467,10 @@ function convertToGoogleGenerativeAIMessages(prompt, options) {
466
467
  for (const part of content) {
467
468
  const output = part.output;
468
469
  if (output.type === "content") {
469
- for (const contentPart of output.value) {
470
- switch (contentPart.type) {
471
- case "text":
472
- parts.push({
473
- functionResponse: {
474
- name: part.toolName,
475
- response: {
476
- name: part.toolName,
477
- content: contentPart.text
478
- }
479
- }
480
- });
481
- break;
482
- case "media":
483
- parts.push(
484
- {
485
- inlineData: {
486
- mimeType: contentPart.mediaType,
487
- data: contentPart.data
488
- }
489
- },
490
- {
491
- text: "Tool executed successfully and returned this image as a response"
492
- }
493
- );
494
- break;
495
- default:
496
- parts.push({ text: JSON.stringify(contentPart) });
497
- break;
498
- }
470
+ if (supportsFunctionResponseParts) {
471
+ appendToolResultParts({ parts, part, output });
472
+ } else {
473
+ appendLegacyToolResultParts({ parts, part, output });
499
474
  }
500
475
  } else {
501
476
  parts.push({
@@ -526,6 +501,77 @@ function convertToGoogleGenerativeAIMessages(prompt, options) {
526
501
  contents
527
502
  };
528
503
  }
504
+ function appendToolResultParts({
505
+ parts,
506
+ part,
507
+ output
508
+ }) {
509
+ const responseTextParts = [];
510
+ const functionResponseParts = [];
511
+ for (const contentPart of output.value) {
512
+ switch (contentPart.type) {
513
+ case "text":
514
+ responseTextParts.push(contentPart.text);
515
+ break;
516
+ case "media":
517
+ functionResponseParts.push({
518
+ inlineData: {
519
+ mimeType: contentPart.mediaType,
520
+ data: contentPart.data
521
+ }
522
+ });
523
+ break;
524
+ }
525
+ }
526
+ const responseText = responseTextParts.length > 0 ? responseTextParts.join("\n") : "Tool executed successfully.";
527
+ parts.push({
528
+ functionResponse: {
529
+ name: part.toolName,
530
+ response: {
531
+ name: part.toolName,
532
+ content: responseText
533
+ },
534
+ ...functionResponseParts.length > 0 ? { parts: functionResponseParts } : {}
535
+ }
536
+ });
537
+ }
538
+ function appendLegacyToolResultParts({
539
+ parts,
540
+ part,
541
+ output
542
+ }) {
543
+ for (const contentPart of output.value) {
544
+ switch (contentPart.type) {
545
+ case "text":
546
+ parts.push({
547
+ functionResponse: {
548
+ name: part.toolName,
549
+ response: {
550
+ name: part.toolName,
551
+ content: contentPart.text
552
+ }
553
+ }
554
+ });
555
+ break;
556
+ case "media":
557
+ parts.push(
558
+ {
559
+ inlineData: {
560
+ mimeType: contentPart.mediaType,
561
+ data: contentPart.data
562
+ }
563
+ },
564
+ {
565
+ text: "Tool executed successfully and returned this image as a response"
566
+ }
567
+ );
568
+ break;
569
+ default:
570
+ parts.push({ text: JSON.stringify(contentPart) });
571
+ break;
572
+ }
573
+ }
574
+ }
529
575
 
530
576
  // src/get-model-path.ts
531
577
  function getModelPath(modelId) {
@@ -926,9 +972,10 @@ var GoogleGenerativeAILanguageModel = class {
926
972
  });
927
973
  }
928
974
  const isGemmaModel = this.modelId.toLowerCase().startsWith("gemma-");
975
+ const supportsFunctionResponseParts = this.modelId.startsWith("gemini-3");
929
976
  const { contents, systemInstruction } = convertToGoogleGenerativeAIMessages(
930
977
  prompt,
931
- { isGemmaModel }
978
+ { isGemmaModel, supportsFunctionResponseParts }
932
979
  );
933
980
  const {
934
981
  tools: googleTools2,