@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.
@@ -189,6 +189,23 @@ function isEmptyObjectSchema(jsonSchema) {
189
189
  // src/convert-to-google-generative-ai-messages.ts
190
190
  var import_provider = require("@ai-sdk/provider");
191
191
  var import_provider_utils = require("@ai-sdk/provider-utils");
192
+ var SKIP_THOUGHT_SIGNATURE_VALIDATOR = "skip_thought_signature_validator";
193
+ function getGoogleProviderOptions(providerOptions, providerOptionsName) {
194
+ const namespaces = [
195
+ providerOptionsName,
196
+ "google",
197
+ "googleVertex",
198
+ "vertex"
199
+ ].filter((namespace, index, allNamespaces) => {
200
+ return allNamespaces.indexOf(namespace) === index;
201
+ });
202
+ for (const namespace of namespaces) {
203
+ const options = providerOptions == null ? void 0 : providerOptions[namespace];
204
+ if (options != null) {
205
+ return options;
206
+ }
207
+ }
208
+ }
192
209
  var dataUrlRegex = /^data:([^;,]+);base64,(.+)$/s;
193
210
  function parseBase64DataUrl(value) {
194
211
  const match = dataUrlRegex.exec(value);
@@ -296,13 +313,22 @@ function appendLegacyToolResultParts(parts, toolName, outputValue, toolCallId) {
296
313
  }
297
314
  }
298
315
  function convertToGoogleGenerativeAIMessages(prompt, options) {
299
- var _a, _b, _c, _d, _e, _f, _g, _h;
316
+ var _a, _b, _c, _d, _e;
300
317
  const systemInstructionParts = [];
301
318
  const contents = [];
302
319
  let systemMessagesAllowed = true;
303
320
  const isGemmaModel = (_a = options == null ? void 0 : options.isGemmaModel) != null ? _a : false;
304
- const providerOptionsName = (_b = options == null ? void 0 : options.providerOptionsName) != null ? _b : "google";
305
- const supportsFunctionResponseParts = (_c = options == null ? void 0 : options.supportsFunctionResponseParts) != null ? _c : true;
321
+ const isGemini3Model = (_b = options == null ? void 0 : options.isGemini3Model) != null ? _b : false;
322
+ const providerOptionsName = (_c = options == null ? void 0 : options.providerOptionsName) != null ? _c : "google";
323
+ const supportsFunctionResponseParts = (_d = options == null ? void 0 : options.supportsFunctionResponseParts) != null ? _d : true;
324
+ const onWarning = options == null ? void 0 : options.onWarning;
325
+ let sentinelInjected = false;
326
+ const missingSignatureToolNames = [];
327
+ const injectSkipSignature = (toolName) => {
328
+ missingSignatureToolNames.push(toolName);
329
+ sentinelInjected = true;
330
+ return SKIP_THOUGHT_SIGNATURE_VALIDATOR;
331
+ };
306
332
  for (const { role, content } of prompt) {
307
333
  switch (role) {
308
334
  case "system": {
@@ -350,8 +376,10 @@ function convertToGoogleGenerativeAIMessages(prompt, options) {
350
376
  contents.push({
351
377
  role: "model",
352
378
  parts: content.map((part) => {
353
- var _a2, _b2, _c2, _d2;
354
- 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;
379
+ const providerOpts = getGoogleProviderOptions(
380
+ part.providerOptions,
381
+ providerOptionsName
382
+ );
355
383
  const thoughtSignature = (providerOpts == null ? void 0 : providerOpts.thoughtSignature) != null ? String(providerOpts.thoughtSignature) : void 0;
356
384
  switch (part.type) {
357
385
  case "text": {
@@ -385,6 +413,7 @@ function convertToGoogleGenerativeAIMessages(prompt, options) {
385
413
  case "tool-call": {
386
414
  const serverToolCallId = (providerOpts == null ? void 0 : providerOpts.serverToolCallId) != null ? String(providerOpts.serverToolCallId) : void 0;
387
415
  const serverToolType = (providerOpts == null ? void 0 : providerOpts.serverToolType) != null ? String(providerOpts.serverToolType) : void 0;
416
+ const effectiveThoughtSignature = thoughtSignature != null ? thoughtSignature : isGemini3Model ? injectSkipSignature(part.toolName) : void 0;
388
417
  if (serverToolCallId && serverToolType) {
389
418
  return {
390
419
  toolCall: {
@@ -392,7 +421,7 @@ function convertToGoogleGenerativeAIMessages(prompt, options) {
392
421
  args: typeof part.input === "string" ? JSON.parse(part.input) : part.input,
393
422
  id: serverToolCallId
394
423
  },
395
- thoughtSignature
424
+ thoughtSignature: effectiveThoughtSignature
396
425
  };
397
426
  }
398
427
  return {
@@ -401,7 +430,7 @@ function convertToGoogleGenerativeAIMessages(prompt, options) {
401
430
  name: part.toolName,
402
431
  args: part.input
403
432
  },
404
- thoughtSignature
433
+ thoughtSignature: effectiveThoughtSignature
405
434
  };
406
435
  }
407
436
  case "tool-result": {
@@ -431,7 +460,10 @@ function convertToGoogleGenerativeAIMessages(prompt, options) {
431
460
  if (part.type === "tool-approval-response") {
432
461
  continue;
433
462
  }
434
- 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;
463
+ const partProviderOpts = getGoogleProviderOptions(
464
+ part.providerOptions,
465
+ providerOptionsName
466
+ );
435
467
  const serverToolCallId = (partProviderOpts == null ? void 0 : partProviderOpts.serverToolCallId) != null ? String(partProviderOpts.serverToolCallId) : void 0;
436
468
  const serverToolType = (partProviderOpts == null ? void 0 : partProviderOpts.serverToolType) != null ? String(partProviderOpts.serverToolType) : void 0;
437
469
  if (serverToolCallId && serverToolType) {
@@ -475,7 +507,7 @@ function convertToGoogleGenerativeAIMessages(prompt, options) {
475
507
  name: part.toolName,
476
508
  response: {
477
509
  name: part.toolName,
478
- content: output.type === "execution-denied" ? (_h = output.reason) != null ? _h : "Tool execution denied." : output.value
510
+ content: output.type === "execution-denied" ? (_e = output.reason) != null ? _e : "Tool execution denied." : output.value
479
511
  }
480
512
  }
481
513
  });
@@ -493,6 +525,13 @@ function convertToGoogleGenerativeAIMessages(prompt, options) {
493
525
  const systemText = systemInstructionParts.map((part) => part.text).join("\n\n");
494
526
  contents[0].parts.unshift({ text: systemText + "\n\n" });
495
527
  }
528
+ if (sentinelInjected && onWarning != null) {
529
+ const uniqueToolNames = Array.from(new Set(missingSignatureToolNames));
530
+ onWarning({
531
+ type: "other",
532
+ 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.`
533
+ });
534
+ }
496
535
  return {
497
536
  systemInstruction: systemInstructionParts.length > 0 && !isGemmaModel ? { parts: systemInstructionParts } : void 0,
498
537
  contents
@@ -1265,13 +1304,16 @@ var GoogleGenerativeAILanguageModel = class {
1265
1304
  } : void 0;
1266
1305
  const bodyServiceTier = isVertexProvider ? void 0 : googleOptions == null ? void 0 : googleOptions.serviceTier;
1267
1306
  const isGemmaModel = this.modelId.toLowerCase().startsWith("gemma-");
1268
- const supportsFunctionResponseParts = this.modelId.startsWith("gemini-3");
1307
+ const isGemini3Model = /^gemini-3[.-]/.test(this.modelId);
1308
+ const supportsFunctionResponseParts = isGemini3Model;
1269
1309
  const { contents, systemInstruction } = convertToGoogleGenerativeAIMessages(
1270
1310
  prompt,
1271
1311
  {
1272
1312
  isGemmaModel,
1313
+ isGemini3Model,
1273
1314
  providerOptionsName,
1274
- supportsFunctionResponseParts
1315
+ supportsFunctionResponseParts,
1316
+ onWarning: (warning) => warnings.push(warning)
1275
1317
  }
1276
1318
  );
1277
1319
  const {