@ai-sdk/google 3.0.79 → 3.0.81

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.
@@ -172,6 +172,23 @@ import {
172
172
  UnsupportedFunctionalityError
173
173
  } from "@ai-sdk/provider";
174
174
  import { convertToBase64 } from "@ai-sdk/provider-utils";
175
+ var SKIP_THOUGHT_SIGNATURE_VALIDATOR = "skip_thought_signature_validator";
176
+ function getGoogleProviderOptions(providerOptions, providerOptionsName) {
177
+ const namespaces = [
178
+ providerOptionsName,
179
+ "google",
180
+ "googleVertex",
181
+ "vertex"
182
+ ].filter((namespace, index, allNamespaces) => {
183
+ return allNamespaces.indexOf(namespace) === index;
184
+ });
185
+ for (const namespace of namespaces) {
186
+ const options = providerOptions == null ? void 0 : providerOptions[namespace];
187
+ if (options != null) {
188
+ return options;
189
+ }
190
+ }
191
+ }
175
192
  var dataUrlRegex = /^data:([^;,]+);base64,(.+)$/s;
176
193
  function parseBase64DataUrl(value) {
177
194
  const match = dataUrlRegex.exec(value);
@@ -279,13 +296,22 @@ function appendLegacyToolResultParts(parts, toolName, outputValue, toolCallId) {
279
296
  }
280
297
  }
281
298
  function convertToGoogleGenerativeAIMessages(prompt, options) {
282
- var _a, _b, _c, _d, _e, _f, _g, _h;
299
+ var _a, _b, _c, _d, _e;
283
300
  const systemInstructionParts = [];
284
301
  const contents = [];
285
302
  let systemMessagesAllowed = true;
286
303
  const isGemmaModel = (_a = options == null ? void 0 : options.isGemmaModel) != null ? _a : false;
287
- const providerOptionsName = (_b = options == null ? void 0 : options.providerOptionsName) != null ? _b : "google";
288
- const supportsFunctionResponseParts = (_c = options == null ? void 0 : options.supportsFunctionResponseParts) != null ? _c : true;
304
+ const isGemini3Model = (_b = options == null ? void 0 : options.isGemini3Model) != null ? _b : false;
305
+ const providerOptionsName = (_c = options == null ? void 0 : options.providerOptionsName) != null ? _c : "google";
306
+ const supportsFunctionResponseParts = (_d = options == null ? void 0 : options.supportsFunctionResponseParts) != null ? _d : true;
307
+ const onWarning = options == null ? void 0 : options.onWarning;
308
+ let sentinelInjected = false;
309
+ const missingSignatureToolNames = [];
310
+ const injectSkipSignature = (toolName) => {
311
+ missingSignatureToolNames.push(toolName);
312
+ sentinelInjected = true;
313
+ return SKIP_THOUGHT_SIGNATURE_VALIDATOR;
314
+ };
289
315
  for (const { role, content } of prompt) {
290
316
  switch (role) {
291
317
  case "system": {
@@ -333,8 +359,10 @@ function convertToGoogleGenerativeAIMessages(prompt, options) {
333
359
  contents.push({
334
360
  role: "model",
335
361
  parts: content.map((part) => {
336
- var _a2, _b2, _c2, _d2;
337
- 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;
362
+ const providerOpts = getGoogleProviderOptions(
363
+ part.providerOptions,
364
+ providerOptionsName
365
+ );
338
366
  const thoughtSignature = (providerOpts == null ? void 0 : providerOpts.thoughtSignature) != null ? String(providerOpts.thoughtSignature) : void 0;
339
367
  switch (part.type) {
340
368
  case "text": {
@@ -368,6 +396,7 @@ function convertToGoogleGenerativeAIMessages(prompt, options) {
368
396
  case "tool-call": {
369
397
  const serverToolCallId = (providerOpts == null ? void 0 : providerOpts.serverToolCallId) != null ? String(providerOpts.serverToolCallId) : void 0;
370
398
  const serverToolType = (providerOpts == null ? void 0 : providerOpts.serverToolType) != null ? String(providerOpts.serverToolType) : void 0;
399
+ const effectiveThoughtSignature = thoughtSignature != null ? thoughtSignature : isGemini3Model ? injectSkipSignature(part.toolName) : void 0;
371
400
  if (serverToolCallId && serverToolType) {
372
401
  return {
373
402
  toolCall: {
@@ -375,7 +404,7 @@ function convertToGoogleGenerativeAIMessages(prompt, options) {
375
404
  args: typeof part.input === "string" ? JSON.parse(part.input) : part.input,
376
405
  id: serverToolCallId
377
406
  },
378
- thoughtSignature
407
+ thoughtSignature: effectiveThoughtSignature
379
408
  };
380
409
  }
381
410
  return {
@@ -384,7 +413,7 @@ function convertToGoogleGenerativeAIMessages(prompt, options) {
384
413
  name: part.toolName,
385
414
  args: part.input
386
415
  },
387
- thoughtSignature
416
+ thoughtSignature: effectiveThoughtSignature
388
417
  };
389
418
  }
390
419
  case "tool-result": {
@@ -414,7 +443,10 @@ function convertToGoogleGenerativeAIMessages(prompt, options) {
414
443
  if (part.type === "tool-approval-response") {
415
444
  continue;
416
445
  }
417
- 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;
446
+ const partProviderOpts = getGoogleProviderOptions(
447
+ part.providerOptions,
448
+ providerOptionsName
449
+ );
418
450
  const serverToolCallId = (partProviderOpts == null ? void 0 : partProviderOpts.serverToolCallId) != null ? String(partProviderOpts.serverToolCallId) : void 0;
419
451
  const serverToolType = (partProviderOpts == null ? void 0 : partProviderOpts.serverToolType) != null ? String(partProviderOpts.serverToolType) : void 0;
420
452
  if (serverToolCallId && serverToolType) {
@@ -458,7 +490,7 @@ function convertToGoogleGenerativeAIMessages(prompt, options) {
458
490
  name: part.toolName,
459
491
  response: {
460
492
  name: part.toolName,
461
- content: output.type === "execution-denied" ? (_h = output.reason) != null ? _h : "Tool execution denied." : output.value
493
+ content: output.type === "execution-denied" ? (_e = output.reason) != null ? _e : "Tool execution denied." : output.value
462
494
  }
463
495
  }
464
496
  });
@@ -476,6 +508,13 @@ function convertToGoogleGenerativeAIMessages(prompt, options) {
476
508
  const systemText = systemInstructionParts.map((part) => part.text).join("\n\n");
477
509
  contents[0].parts.unshift({ text: systemText + "\n\n" });
478
510
  }
511
+ if (sentinelInjected && onWarning != null) {
512
+ const uniqueToolNames = Array.from(new Set(missingSignatureToolNames));
513
+ onWarning({
514
+ type: "other",
515
+ 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.`
516
+ });
517
+ }
479
518
  return {
480
519
  systemInstruction: systemInstructionParts.length > 0 && !isGemmaModel ? { parts: systemInstructionParts } : void 0,
481
520
  contents
@@ -1257,13 +1296,16 @@ var GoogleGenerativeAILanguageModel = class {
1257
1296
  } : void 0;
1258
1297
  const bodyServiceTier = isVertexProvider ? void 0 : googleOptions == null ? void 0 : googleOptions.serviceTier;
1259
1298
  const isGemmaModel = this.modelId.toLowerCase().startsWith("gemma-");
1260
- const supportsFunctionResponseParts = this.modelId.startsWith("gemini-3");
1299
+ const isGemini3Model = /^gemini-3[.-]/.test(this.modelId);
1300
+ const supportsFunctionResponseParts = isGemini3Model;
1261
1301
  const { contents, systemInstruction } = convertToGoogleGenerativeAIMessages(
1262
1302
  prompt,
1263
1303
  {
1264
1304
  isGemmaModel,
1305
+ isGemini3Model,
1265
1306
  providerOptionsName,
1266
- supportsFunctionResponseParts
1307
+ supportsFunctionResponseParts,
1308
+ onWarning: (warning) => warnings.push(warning)
1267
1309
  }
1268
1310
  );
1269
1311
  const {