@ai-sdk/google 3.0.79 → 3.0.80

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.mjs CHANGED
@@ -7,7 +7,7 @@ import {
7
7
  } from "@ai-sdk/provider-utils";
8
8
 
9
9
  // src/version.ts
10
- var VERSION = true ? "3.0.79" : "0.0.0-test";
10
+ var VERSION = true ? "3.0.80" : "0.0.0-test";
11
11
 
12
12
  // src/google-generative-ai-embedding-model.ts
13
13
  import {
@@ -412,6 +412,23 @@ import {
412
412
  UnsupportedFunctionalityError
413
413
  } from "@ai-sdk/provider";
414
414
  import { convertToBase64 } from "@ai-sdk/provider-utils";
415
+ var SKIP_THOUGHT_SIGNATURE_VALIDATOR = "skip_thought_signature_validator";
416
+ function getGoogleProviderOptions(providerOptions, providerOptionsName) {
417
+ const namespaces = [
418
+ providerOptionsName,
419
+ "google",
420
+ "googleVertex",
421
+ "vertex"
422
+ ].filter((namespace, index, allNamespaces) => {
423
+ return allNamespaces.indexOf(namespace) === index;
424
+ });
425
+ for (const namespace of namespaces) {
426
+ const options = providerOptions == null ? void 0 : providerOptions[namespace];
427
+ if (options != null) {
428
+ return options;
429
+ }
430
+ }
431
+ }
415
432
  var dataUrlRegex = /^data:([^;,]+);base64,(.+)$/s;
416
433
  function parseBase64DataUrl(value) {
417
434
  const match = dataUrlRegex.exec(value);
@@ -519,13 +536,22 @@ function appendLegacyToolResultParts(parts, toolName, outputValue, toolCallId) {
519
536
  }
520
537
  }
521
538
  function convertToGoogleGenerativeAIMessages(prompt, options) {
522
- var _a, _b, _c, _d, _e, _f, _g, _h;
539
+ var _a, _b, _c, _d, _e;
523
540
  const systemInstructionParts = [];
524
541
  const contents = [];
525
542
  let systemMessagesAllowed = true;
526
543
  const isGemmaModel = (_a = options == null ? void 0 : options.isGemmaModel) != null ? _a : false;
527
- const providerOptionsName = (_b = options == null ? void 0 : options.providerOptionsName) != null ? _b : "google";
528
- const supportsFunctionResponseParts = (_c = options == null ? void 0 : options.supportsFunctionResponseParts) != null ? _c : true;
544
+ const isGemini3Model = (_b = options == null ? void 0 : options.isGemini3Model) != null ? _b : false;
545
+ const providerOptionsName = (_c = options == null ? void 0 : options.providerOptionsName) != null ? _c : "google";
546
+ const supportsFunctionResponseParts = (_d = options == null ? void 0 : options.supportsFunctionResponseParts) != null ? _d : true;
547
+ const onWarning = options == null ? void 0 : options.onWarning;
548
+ let sentinelInjected = false;
549
+ const missingSignatureToolNames = [];
550
+ const injectSkipSignature = (toolName) => {
551
+ missingSignatureToolNames.push(toolName);
552
+ sentinelInjected = true;
553
+ return SKIP_THOUGHT_SIGNATURE_VALIDATOR;
554
+ };
529
555
  for (const { role, content } of prompt) {
530
556
  switch (role) {
531
557
  case "system": {
@@ -573,8 +599,10 @@ function convertToGoogleGenerativeAIMessages(prompt, options) {
573
599
  contents.push({
574
600
  role: "model",
575
601
  parts: content.map((part) => {
576
- var _a2, _b2, _c2, _d2;
577
- 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;
602
+ const providerOpts = getGoogleProviderOptions(
603
+ part.providerOptions,
604
+ providerOptionsName
605
+ );
578
606
  const thoughtSignature = (providerOpts == null ? void 0 : providerOpts.thoughtSignature) != null ? String(providerOpts.thoughtSignature) : void 0;
579
607
  switch (part.type) {
580
608
  case "text": {
@@ -608,6 +636,7 @@ function convertToGoogleGenerativeAIMessages(prompt, options) {
608
636
  case "tool-call": {
609
637
  const serverToolCallId = (providerOpts == null ? void 0 : providerOpts.serverToolCallId) != null ? String(providerOpts.serverToolCallId) : void 0;
610
638
  const serverToolType = (providerOpts == null ? void 0 : providerOpts.serverToolType) != null ? String(providerOpts.serverToolType) : void 0;
639
+ const effectiveThoughtSignature = thoughtSignature != null ? thoughtSignature : isGemini3Model ? injectSkipSignature(part.toolName) : void 0;
611
640
  if (serverToolCallId && serverToolType) {
612
641
  return {
613
642
  toolCall: {
@@ -615,7 +644,7 @@ function convertToGoogleGenerativeAIMessages(prompt, options) {
615
644
  args: typeof part.input === "string" ? JSON.parse(part.input) : part.input,
616
645
  id: serverToolCallId
617
646
  },
618
- thoughtSignature
647
+ thoughtSignature: effectiveThoughtSignature
619
648
  };
620
649
  }
621
650
  return {
@@ -624,7 +653,7 @@ function convertToGoogleGenerativeAIMessages(prompt, options) {
624
653
  name: part.toolName,
625
654
  args: part.input
626
655
  },
627
- thoughtSignature
656
+ thoughtSignature: effectiveThoughtSignature
628
657
  };
629
658
  }
630
659
  case "tool-result": {
@@ -654,7 +683,10 @@ function convertToGoogleGenerativeAIMessages(prompt, options) {
654
683
  if (part.type === "tool-approval-response") {
655
684
  continue;
656
685
  }
657
- const partProviderOpts = (_g = (_d = part.providerOptions) == null ? void 0 : _d[providerOptionsName]) != null ? _g : providerOptionsName !== "google" ? (_e = part.providerOptions) == null ? void 0 : _e.google : (_f = part.providerOptions) == null ? void 0 : _f.vertex;
686
+ const partProviderOpts = getGoogleProviderOptions(
687
+ part.providerOptions,
688
+ providerOptionsName
689
+ );
658
690
  const serverToolCallId = (partProviderOpts == null ? void 0 : partProviderOpts.serverToolCallId) != null ? String(partProviderOpts.serverToolCallId) : void 0;
659
691
  const serverToolType = (partProviderOpts == null ? void 0 : partProviderOpts.serverToolType) != null ? String(partProviderOpts.serverToolType) : void 0;
660
692
  if (serverToolCallId && serverToolType) {
@@ -698,7 +730,7 @@ function convertToGoogleGenerativeAIMessages(prompt, options) {
698
730
  name: part.toolName,
699
731
  response: {
700
732
  name: part.toolName,
701
- content: output.type === "execution-denied" ? (_h = output.reason) != null ? _h : "Tool execution denied." : output.value
733
+ content: output.type === "execution-denied" ? (_e = output.reason) != null ? _e : "Tool execution denied." : output.value
702
734
  }
703
735
  }
704
736
  });
@@ -716,6 +748,13 @@ function convertToGoogleGenerativeAIMessages(prompt, options) {
716
748
  const systemText = systemInstructionParts.map((part) => part.text).join("\n\n");
717
749
  contents[0].parts.unshift({ text: systemText + "\n\n" });
718
750
  }
751
+ if (sentinelInjected && onWarning != null) {
752
+ const uniqueToolNames = Array.from(new Set(missingSignatureToolNames));
753
+ onWarning({
754
+ type: "other",
755
+ message: `Replayed ${missingSignatureToolNames.length} \`functionCall\` part(s) for a Gemini 3 model without a \`thoughtSignature\` (tools: ${uniqueToolNames.map((name) => `\`${name}\``).join(", ")}). Injected the documented \`skip_thought_signature_validator\` sentinel to keep the request from failing with HTTP 400. The likely cause is application code that drops \`providerOptions.google.thoughtSignature\` when persisting or serializing assistant tool-call messages. See https://ai.google.dev/gemini-api/docs/thought-signatures.`
756
+ });
757
+ }
719
758
  return {
720
759
  systemInstruction: systemInstructionParts.length > 0 && !isGemmaModel ? { parts: systemInstructionParts } : void 0,
721
760
  contents
@@ -1474,13 +1513,16 @@ var GoogleGenerativeAILanguageModel = class {
1474
1513
  } : void 0;
1475
1514
  const bodyServiceTier = isVertexProvider ? void 0 : googleOptions == null ? void 0 : googleOptions.serviceTier;
1476
1515
  const isGemmaModel = this.modelId.toLowerCase().startsWith("gemma-");
1477
- const supportsFunctionResponseParts = this.modelId.startsWith("gemini-3");
1516
+ const isGemini3Model = /^gemini-3[.-]/.test(this.modelId);
1517
+ const supportsFunctionResponseParts = isGemini3Model;
1478
1518
  const { contents, systemInstruction } = convertToGoogleGenerativeAIMessages(
1479
1519
  prompt,
1480
1520
  {
1481
1521
  isGemmaModel,
1522
+ isGemini3Model,
1482
1523
  providerOptionsName,
1483
- supportsFunctionResponseParts
1524
+ supportsFunctionResponseParts,
1525
+ onWarning: (warning) => warnings.push(warning)
1484
1526
  }
1485
1527
  );
1486
1528
  const {