@ai-sdk/google 4.0.0-beta.47 → 4.0.0-beta.49

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.
@@ -179,7 +179,8 @@ import {
179
179
  } from "@ai-sdk/provider";
180
180
  import {
181
181
  convertToBase64,
182
- isProviderReference,
182
+ isFullMediaType,
183
+ resolveFullMediaType,
183
184
  resolveProviderReference
184
185
  } from "@ai-sdk/provider-utils";
185
186
  var dataUrlRegex = /^data:([^;,]+);base64,(.+)$/s;
@@ -289,13 +290,25 @@ function appendLegacyToolResultParts(parts, toolName, outputValue) {
289
290
  }
290
291
  }
291
292
  function convertToGoogleMessages(prompt, options) {
292
- var _a, _b, _c, _d, _e, _f, _g, _h;
293
+ var _a, _b, _c, _d;
293
294
  const systemInstructionParts = [];
294
295
  const contents = [];
295
296
  let systemMessagesAllowed = true;
296
297
  const isGemmaModel = (_a = options == null ? void 0 : options.isGemmaModel) != null ? _a : false;
297
- const providerOptionsName = (_b = options == null ? void 0 : options.providerOptionsName) != null ? _b : "google";
298
+ const providerOptionsNames = (_b = options == null ? void 0 : options.providerOptionsNames) != null ? _b : ["google"];
299
+ const isVertexLike = !providerOptionsNames.includes("google");
298
300
  const supportsFunctionResponseParts = (_c = options == null ? void 0 : options.supportsFunctionResponseParts) != null ? _c : true;
301
+ const readProviderOpts = (part) => {
302
+ var _a2, _b2, _c2, _d2, _e;
303
+ for (const name of providerOptionsNames) {
304
+ const v = (_a2 = part.providerOptions) == null ? void 0 : _a2[name];
305
+ if (v != null) return v;
306
+ }
307
+ if (isVertexLike) {
308
+ return (_b2 = part.providerOptions) == null ? void 0 : _b2.google;
309
+ }
310
+ return (_e = (_c2 = part.providerOptions) == null ? void 0 : _c2.googleVertex) != null ? _e : (_d2 = part.providerOptions) == null ? void 0 : _d2.vertex;
311
+ };
299
312
  for (const { role, content } of prompt) {
300
313
  switch (role) {
301
314
  case "system": {
@@ -317,36 +330,53 @@ function convertToGoogleMessages(prompt, options) {
317
330
  break;
318
331
  }
319
332
  case "file": {
320
- const mediaType = part.mediaType === "image/*" ? "image/jpeg" : part.mediaType;
321
- if (part.data instanceof URL) {
322
- parts.push({
323
- fileData: {
324
- mimeType: mediaType,
325
- fileUri: part.data.toString()
326
- }
327
- });
328
- } else if (isProviderReference(part.data)) {
329
- if (providerOptionsName === "vertex") {
330
- throw new UnsupportedFunctionalityError({
331
- functionality: "file parts with provider references"
333
+ switch (part.data.type) {
334
+ case "url": {
335
+ parts.push({
336
+ fileData: {
337
+ mimeType: resolveFullMediaType({ part }),
338
+ fileUri: part.data.url.toString()
339
+ }
332
340
  });
341
+ break;
333
342
  }
334
- parts.push({
335
- fileData: {
336
- mimeType: mediaType,
337
- fileUri: resolveProviderReference({
338
- reference: part.data,
339
- provider: "google"
340
- })
341
- }
342
- });
343
- } else {
344
- parts.push({
345
- inlineData: {
346
- mimeType: mediaType,
347
- data: convertToBase64(part.data)
343
+ case "reference": {
344
+ if (isVertexLike) {
345
+ throw new UnsupportedFunctionalityError({
346
+ functionality: "file parts with provider references"
347
+ });
348
348
  }
349
- });
349
+ parts.push({
350
+ fileData: {
351
+ mimeType: resolveFullMediaType({ part }),
352
+ fileUri: resolveProviderReference({
353
+ reference: part.data.reference,
354
+ provider: "google"
355
+ })
356
+ }
357
+ });
358
+ break;
359
+ }
360
+ case "text": {
361
+ parts.push({
362
+ inlineData: {
363
+ mimeType: isFullMediaType(part.mediaType) ? part.mediaType : "text/plain",
364
+ data: convertToBase64(
365
+ new TextEncoder().encode(part.data.text)
366
+ )
367
+ }
368
+ });
369
+ break;
370
+ }
371
+ case "data": {
372
+ parts.push({
373
+ inlineData: {
374
+ mimeType: resolveFullMediaType({ part }),
375
+ data: convertToBase64(part.data.data)
376
+ }
377
+ });
378
+ break;
379
+ }
350
380
  }
351
381
  break;
352
382
  }
@@ -360,8 +390,7 @@ function convertToGoogleMessages(prompt, options) {
360
390
  contents.push({
361
391
  role: "model",
362
392
  parts: content.map((part) => {
363
- var _a2, _b2, _c2, _d2;
364
- 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;
393
+ const providerOpts = readProviderOpts(part);
365
394
  const thoughtSignature = (providerOpts == null ? void 0 : providerOpts.thoughtSignature) != null ? String(providerOpts.thoughtSignature) : void 0;
366
395
  switch (part.type) {
367
396
  case "text": {
@@ -378,52 +407,74 @@ function convertToGoogleMessages(prompt, options) {
378
407
  };
379
408
  }
380
409
  case "reasoning-file": {
381
- if (part.data instanceof URL) {
382
- throw new UnsupportedFunctionalityError({
383
- functionality: "File data URLs in assistant messages are not supported"
384
- });
410
+ switch (part.data.type) {
411
+ case "url": {
412
+ throw new UnsupportedFunctionalityError({
413
+ functionality: "File data URLs in assistant messages are not supported"
414
+ });
415
+ }
416
+ case "data": {
417
+ return {
418
+ inlineData: {
419
+ mimeType: part.mediaType,
420
+ data: convertToBase64(part.data.data)
421
+ },
422
+ thought: true,
423
+ thoughtSignature
424
+ };
425
+ }
385
426
  }
386
- return {
387
- inlineData: {
388
- mimeType: part.mediaType,
389
- data: convertToBase64(part.data)
390
- },
391
- thought: true,
392
- thoughtSignature
393
- };
427
+ break;
394
428
  }
395
429
  case "file": {
396
- if (part.data instanceof URL) {
397
- throw new UnsupportedFunctionalityError({
398
- functionality: "File data URLs in assistant messages are not supported"
399
- });
400
- }
401
- if (isProviderReference(part.data)) {
402
- if (providerOptionsName === "vertex") {
430
+ switch (part.data.type) {
431
+ case "url": {
403
432
  throw new UnsupportedFunctionalityError({
404
- functionality: "file parts with provider references"
433
+ functionality: "File data URLs in assistant messages are not supported"
405
434
  });
406
435
  }
407
- return {
408
- fileData: {
409
- mimeType: part.mediaType,
410
- fileUri: resolveProviderReference({
411
- reference: part.data,
412
- provider: "google"
413
- })
414
- },
415
- ...(providerOpts == null ? void 0 : providerOpts.thought) === true ? { thought: true } : {},
416
- thoughtSignature
417
- };
436
+ case "reference": {
437
+ if (isVertexLike) {
438
+ throw new UnsupportedFunctionalityError({
439
+ functionality: "file parts with provider references"
440
+ });
441
+ }
442
+ return {
443
+ fileData: {
444
+ mimeType: part.mediaType,
445
+ fileUri: resolveProviderReference({
446
+ reference: part.data.reference,
447
+ provider: "google"
448
+ })
449
+ },
450
+ ...(providerOpts == null ? void 0 : providerOpts.thought) === true ? { thought: true } : {},
451
+ thoughtSignature
452
+ };
453
+ }
454
+ case "text": {
455
+ return {
456
+ inlineData: {
457
+ mimeType: isFullMediaType(part.mediaType) ? part.mediaType : "text/plain",
458
+ data: convertToBase64(
459
+ new TextEncoder().encode(part.data.text)
460
+ )
461
+ },
462
+ ...(providerOpts == null ? void 0 : providerOpts.thought) === true ? { thought: true } : {},
463
+ thoughtSignature
464
+ };
465
+ }
466
+ case "data": {
467
+ return {
468
+ inlineData: {
469
+ mimeType: part.mediaType,
470
+ data: convertToBase64(part.data.data)
471
+ },
472
+ ...(providerOpts == null ? void 0 : providerOpts.thought) === true ? { thought: true } : {},
473
+ thoughtSignature
474
+ };
475
+ }
418
476
  }
419
- return {
420
- inlineData: {
421
- mimeType: part.mediaType,
422
- data: convertToBase64(part.data)
423
- },
424
- ...(providerOpts == null ? void 0 : providerOpts.thought) === true ? { thought: true } : {},
425
- thoughtSignature
426
- };
477
+ break;
427
478
  }
428
479
  case "tool-call": {
429
480
  const serverToolCallId = (providerOpts == null ? void 0 : providerOpts.serverToolCallId) != null ? String(providerOpts.serverToolCallId) : void 0;
@@ -473,7 +524,7 @@ function convertToGoogleMessages(prompt, options) {
473
524
  if (part.type === "tool-approval-response") {
474
525
  continue;
475
526
  }
476
- 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;
527
+ const partProviderOpts = readProviderOpts(part);
477
528
  const serverToolCallId = (partProviderOpts == null ? void 0 : partProviderOpts.serverToolCallId) != null ? String(partProviderOpts.serverToolCallId) : void 0;
478
529
  const serverToolType = (partProviderOpts == null ? void 0 : partProviderOpts.serverToolType) != null ? String(partProviderOpts.serverToolType) : void 0;
479
530
  if (serverToolCallId && serverToolType) {
@@ -506,7 +557,7 @@ function convertToGoogleMessages(prompt, options) {
506
557
  name: part.toolName,
507
558
  response: {
508
559
  name: part.toolName,
509
- content: output.type === "execution-denied" ? (_h = output.reason) != null ? _h : "Tool call execution denied." : output.value
560
+ content: output.type === "execution-denied" ? (_d = output.reason) != null ? _d : "Tool call execution denied." : output.value
510
561
  }
511
562
  }
512
563
  });
@@ -558,8 +609,11 @@ var googleFailedResponseHandler = createJsonErrorResponseHandler({
558
609
  errorToMessage: (data) => data.error.message
559
610
  });
560
611
 
561
- // src/google-options.ts
562
- import { lazySchema as lazySchema2, zodSchema as zodSchema2 } from "@ai-sdk/provider-utils";
612
+ // src/google-language-model-options.ts
613
+ import {
614
+ lazySchema as lazySchema2,
615
+ zodSchema as zodSchema2
616
+ } from "@ai-sdk/provider-utils";
563
617
  import { z as z2 } from "zod/v4";
564
618
  var googleLanguageModelOptions = lazySchema2(
565
619
  () => zodSchema2(
@@ -1247,13 +1301,17 @@ var GoogleLanguageModel = class _GoogleLanguageModel {
1247
1301
  }, { isStreaming = false } = {}) {
1248
1302
  var _a, _b;
1249
1303
  const warnings = [];
1250
- const providerOptionsName = this.config.provider.includes("vertex") ? "vertex" : "google";
1251
- let googleOptions = await parseProviderOptions({
1252
- provider: providerOptionsName,
1253
- providerOptions,
1254
- schema: googleLanguageModelOptions
1255
- });
1256
- if (googleOptions == null && providerOptionsName !== "google") {
1304
+ const providerOptionsNames = this.config.provider.includes("vertex") ? ["googleVertex", "vertex"] : ["google"];
1305
+ let googleOptions;
1306
+ for (const name of providerOptionsNames) {
1307
+ googleOptions = await parseProviderOptions({
1308
+ provider: name,
1309
+ providerOptions,
1310
+ schema: googleLanguageModelOptions
1311
+ });
1312
+ if (googleOptions != null) break;
1313
+ }
1314
+ if (googleOptions == null && !providerOptionsNames.includes("google")) {
1257
1315
  googleOptions = await parseProviderOptions({
1258
1316
  provider: "google",
1259
1317
  providerOptions,
@@ -1283,7 +1341,7 @@ var GoogleLanguageModel = class _GoogleLanguageModel {
1283
1341
  const supportsFunctionResponseParts = this.modelId.startsWith("gemini-3");
1284
1342
  const { contents, systemInstruction } = convertToGoogleMessages(prompt, {
1285
1343
  isGemmaModel,
1286
- providerOptionsName,
1344
+ providerOptionsNames,
1287
1345
  supportsFunctionResponseParts
1288
1346
  });
1289
1347
  const {
@@ -1356,12 +1414,15 @@ var GoogleLanguageModel = class _GoogleLanguageModel {
1356
1414
  serviceTier: sanitizedServiceTier
1357
1415
  },
1358
1416
  warnings: [...warnings, ...toolWarnings],
1359
- providerOptionsName
1417
+ providerOptionsNames
1360
1418
  };
1361
1419
  }
1362
1420
  async doGenerate(options) {
1363
1421
  var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o, _p;
1364
- const { args, warnings, providerOptionsName } = await this.getArgs(options);
1422
+ const { args, warnings, providerOptionsNames } = await this.getArgs(options);
1423
+ const wrapProviderMetadata = (payload) => Object.fromEntries(
1424
+ providerOptionsNames.map((name) => [name, payload])
1425
+ );
1365
1426
  const mergedHeaders = combineHeaders(
1366
1427
  this.config.headers ? await resolve(this.config.headers) : void 0,
1367
1428
  options.headers
@@ -1411,11 +1472,9 @@ var GoogleLanguageModel = class _GoogleLanguageModel {
1411
1472
  });
1412
1473
  lastCodeExecutionToolCallId = void 0;
1413
1474
  } else if ("text" in part && part.text != null) {
1414
- const thoughtSignatureMetadata = part.thoughtSignature ? {
1415
- [providerOptionsName]: {
1416
- thoughtSignature: part.thoughtSignature
1417
- }
1418
- } : void 0;
1475
+ const thoughtSignatureMetadata = part.thoughtSignature ? wrapProviderMetadata({
1476
+ thoughtSignature: part.thoughtSignature
1477
+ }) : void 0;
1419
1478
  if (part.text.length === 0) {
1420
1479
  if (thoughtSignatureMetadata != null && content.length > 0) {
1421
1480
  const lastContent = content[content.length - 1];
@@ -1434,24 +1493,20 @@ var GoogleLanguageModel = class _GoogleLanguageModel {
1434
1493
  toolCallId: this.config.generateId(),
1435
1494
  toolName: part.functionCall.name,
1436
1495
  input: JSON.stringify(part.functionCall.args),
1437
- providerMetadata: part.thoughtSignature ? {
1438
- [providerOptionsName]: {
1439
- thoughtSignature: part.thoughtSignature
1440
- }
1441
- } : void 0
1496
+ providerMetadata: part.thoughtSignature ? wrapProviderMetadata({
1497
+ thoughtSignature: part.thoughtSignature
1498
+ }) : void 0
1442
1499
  });
1443
1500
  } else if ("inlineData" in part) {
1444
1501
  const hasThought = part.thought === true;
1445
1502
  const hasThoughtSignature = !!part.thoughtSignature;
1446
1503
  content.push({
1447
1504
  type: hasThought ? "reasoning-file" : "file",
1448
- data: part.inlineData.data,
1505
+ data: { type: "data", data: part.inlineData.data },
1449
1506
  mediaType: part.inlineData.mimeType,
1450
- providerMetadata: hasThoughtSignature ? {
1451
- [providerOptionsName]: {
1452
- thoughtSignature: part.thoughtSignature
1453
- }
1454
- } : void 0
1507
+ providerMetadata: hasThoughtSignature ? wrapProviderMetadata({
1508
+ thoughtSignature: part.thoughtSignature
1509
+ }) : void 0
1455
1510
  });
1456
1511
  } else if ("toolCall" in part && part.toolCall) {
1457
1512
  const toolCallId = (_e = part.toolCall.id) != null ? _e : this.config.generateId();
@@ -1463,18 +1518,14 @@ var GoogleLanguageModel = class _GoogleLanguageModel {
1463
1518
  input: JSON.stringify((_f = part.toolCall.args) != null ? _f : {}),
1464
1519
  providerExecuted: true,
1465
1520
  dynamic: true,
1466
- providerMetadata: part.thoughtSignature ? {
1467
- [providerOptionsName]: {
1468
- thoughtSignature: part.thoughtSignature,
1469
- serverToolCallId: toolCallId,
1470
- serverToolType: part.toolCall.toolType
1471
- }
1472
- } : {
1473
- [providerOptionsName]: {
1474
- serverToolCallId: toolCallId,
1475
- serverToolType: part.toolCall.toolType
1476
- }
1477
- }
1521
+ providerMetadata: part.thoughtSignature ? wrapProviderMetadata({
1522
+ thoughtSignature: part.thoughtSignature,
1523
+ serverToolCallId: toolCallId,
1524
+ serverToolType: part.toolCall.toolType
1525
+ }) : wrapProviderMetadata({
1526
+ serverToolCallId: toolCallId,
1527
+ serverToolType: part.toolCall.toolType
1528
+ })
1478
1529
  });
1479
1530
  } else if ("toolResponse" in part && part.toolResponse) {
1480
1531
  const responseToolCallId = (_g = lastServerToolCallId != null ? lastServerToolCallId : part.toolResponse.id) != null ? _g : this.config.generateId();
@@ -1483,18 +1534,14 @@ var GoogleLanguageModel = class _GoogleLanguageModel {
1483
1534
  toolCallId: responseToolCallId,
1484
1535
  toolName: `server:${part.toolResponse.toolType}`,
1485
1536
  result: (_h = part.toolResponse.response) != null ? _h : {},
1486
- providerMetadata: part.thoughtSignature ? {
1487
- [providerOptionsName]: {
1488
- thoughtSignature: part.thoughtSignature,
1489
- serverToolCallId: responseToolCallId,
1490
- serverToolType: part.toolResponse.toolType
1491
- }
1492
- } : {
1493
- [providerOptionsName]: {
1494
- serverToolCallId: responseToolCallId,
1495
- serverToolType: part.toolResponse.toolType
1496
- }
1497
- }
1537
+ providerMetadata: part.thoughtSignature ? wrapProviderMetadata({
1538
+ thoughtSignature: part.thoughtSignature,
1539
+ serverToolCallId: responseToolCallId,
1540
+ serverToolType: part.toolResponse.toolType
1541
+ }) : wrapProviderMetadata({
1542
+ serverToolCallId: responseToolCallId,
1543
+ serverToolType: part.toolResponse.toolType
1544
+ })
1498
1545
  });
1499
1546
  lastServerToolCallId = void 0;
1500
1547
  }
@@ -1520,17 +1567,15 @@ var GoogleLanguageModel = class _GoogleLanguageModel {
1520
1567
  },
1521
1568
  usage: convertGoogleUsage(usageMetadata),
1522
1569
  warnings,
1523
- providerMetadata: {
1524
- [providerOptionsName]: {
1525
- promptFeedback: (_k = response.promptFeedback) != null ? _k : null,
1526
- groundingMetadata: (_l = candidate.groundingMetadata) != null ? _l : null,
1527
- urlContextMetadata: (_m = candidate.urlContextMetadata) != null ? _m : null,
1528
- safetyRatings: (_n = candidate.safetyRatings) != null ? _n : null,
1529
- usageMetadata: usageMetadata != null ? usageMetadata : null,
1530
- finishMessage: (_o = candidate.finishMessage) != null ? _o : null,
1531
- serviceTier: (_p = response.serviceTier) != null ? _p : null
1532
- }
1533
- },
1570
+ providerMetadata: wrapProviderMetadata({
1571
+ promptFeedback: (_k = response.promptFeedback) != null ? _k : null,
1572
+ groundingMetadata: (_l = candidate.groundingMetadata) != null ? _l : null,
1573
+ urlContextMetadata: (_m = candidate.urlContextMetadata) != null ? _m : null,
1574
+ safetyRatings: (_n = candidate.safetyRatings) != null ? _n : null,
1575
+ usageMetadata: usageMetadata != null ? usageMetadata : null,
1576
+ finishMessage: (_o = candidate.finishMessage) != null ? _o : null,
1577
+ serviceTier: (_p = response.serviceTier) != null ? _p : null
1578
+ }),
1534
1579
  request: { body: args },
1535
1580
  response: {
1536
1581
  // TODO timestamp, model id, id
@@ -1540,10 +1585,13 @@ var GoogleLanguageModel = class _GoogleLanguageModel {
1540
1585
  };
1541
1586
  }
1542
1587
  async doStream(options) {
1543
- const { args, warnings, providerOptionsName } = await this.getArgs(
1588
+ const { args, warnings, providerOptionsNames } = await this.getArgs(
1544
1589
  options,
1545
1590
  { isStreaming: true }
1546
1591
  );
1592
+ const wrapProviderMetadata = (payload) => Object.fromEntries(
1593
+ providerOptionsNames.map((name) => [name, payload])
1594
+ );
1547
1595
  const headers = combineHeaders(
1548
1596
  this.config.headers ? await resolve(this.config.headers) : void 0,
1549
1597
  options.headers
@@ -1651,11 +1699,9 @@ var GoogleLanguageModel = class _GoogleLanguageModel {
1651
1699
  lastCodeExecutionToolCallId = void 0;
1652
1700
  }
1653
1701
  } else if ("text" in part && part.text != null) {
1654
- const thoughtSignatureMetadata = part.thoughtSignature ? {
1655
- [providerOptionsName]: {
1656
- thoughtSignature: part.thoughtSignature
1657
- }
1658
- } : void 0;
1702
+ const thoughtSignatureMetadata = part.thoughtSignature ? wrapProviderMetadata({
1703
+ thoughtSignature: part.thoughtSignature
1704
+ }) : void 0;
1659
1705
  if (part.text.length === 0) {
1660
1706
  if (thoughtSignatureMetadata != null && currentTextBlockId !== null) {
1661
1707
  controller.enqueue({
@@ -1727,27 +1773,23 @@ var GoogleLanguageModel = class _GoogleLanguageModel {
1727
1773
  }
1728
1774
  const hasThought = part.thought === true;
1729
1775
  const hasThoughtSignature = !!part.thoughtSignature;
1730
- const fileMeta = hasThoughtSignature ? {
1731
- [providerOptionsName]: {
1732
- thoughtSignature: part.thoughtSignature
1733
- }
1734
- } : void 0;
1776
+ const fileMeta = hasThoughtSignature ? wrapProviderMetadata({
1777
+ thoughtSignature: part.thoughtSignature
1778
+ }) : void 0;
1735
1779
  controller.enqueue({
1736
1780
  type: hasThought ? "reasoning-file" : "file",
1737
1781
  mediaType: part.inlineData.mimeType,
1738
- data: part.inlineData.data,
1782
+ data: { type: "data", data: part.inlineData.data },
1739
1783
  providerMetadata: fileMeta
1740
1784
  });
1741
1785
  } else if ("toolCall" in part && part.toolCall) {
1742
1786
  const toolCallId = (_e = part.toolCall.id) != null ? _e : generateId2();
1743
1787
  lastServerToolCallId = toolCallId;
1744
- const serverMeta = {
1745
- [providerOptionsName]: {
1746
- ...part.thoughtSignature ? { thoughtSignature: part.thoughtSignature } : {},
1747
- serverToolCallId: toolCallId,
1748
- serverToolType: part.toolCall.toolType
1749
- }
1750
- };
1788
+ const serverMeta = wrapProviderMetadata({
1789
+ ...part.thoughtSignature ? { thoughtSignature: part.thoughtSignature } : {},
1790
+ serverToolCallId: toolCallId,
1791
+ serverToolType: part.toolCall.toolType
1792
+ });
1751
1793
  controller.enqueue({
1752
1794
  type: "tool-call",
1753
1795
  toolCallId,
@@ -1759,13 +1801,11 @@ var GoogleLanguageModel = class _GoogleLanguageModel {
1759
1801
  });
1760
1802
  } else if ("toolResponse" in part && part.toolResponse) {
1761
1803
  const responseToolCallId = (_g = lastServerToolCallId != null ? lastServerToolCallId : part.toolResponse.id) != null ? _g : generateId2();
1762
- const serverMeta = {
1763
- [providerOptionsName]: {
1764
- ...part.thoughtSignature ? { thoughtSignature: part.thoughtSignature } : {},
1765
- serverToolCallId: responseToolCallId,
1766
- serverToolType: part.toolResponse.toolType
1767
- }
1768
- };
1804
+ const serverMeta = wrapProviderMetadata({
1805
+ ...part.thoughtSignature ? { thoughtSignature: part.thoughtSignature } : {},
1806
+ serverToolCallId: responseToolCallId,
1807
+ serverToolType: part.toolResponse.toolType
1808
+ });
1769
1809
  controller.enqueue({
1770
1810
  type: "tool-result",
1771
1811
  toolCallId: responseToolCallId,
@@ -1778,11 +1818,9 @@ var GoogleLanguageModel = class _GoogleLanguageModel {
1778
1818
  }
1779
1819
  for (const part of parts) {
1780
1820
  if (!("functionCall" in part)) continue;
1781
- const providerMeta = part.thoughtSignature ? {
1782
- [providerOptionsName]: {
1783
- thoughtSignature: part.thoughtSignature
1784
- }
1785
- } : void 0;
1821
+ const providerMeta = part.thoughtSignature ? wrapProviderMetadata({
1822
+ thoughtSignature: part.thoughtSignature
1823
+ }) : void 0;
1786
1824
  const isStreamingChunk = part.functionCall.partialArgs != null || part.functionCall.name != null && part.functionCall.willContinue === true;
1787
1825
  const isTerminalChunk = part.functionCall.name == null && part.functionCall.args == null && part.functionCall.partialArgs == null && part.functionCall.willContinue == null;
1788
1826
  const isCompleteCall = part.functionCall.name != null && part.functionCall.args != null && part.functionCall.partialArgs == null;
@@ -1893,17 +1931,15 @@ var GoogleLanguageModel = class _GoogleLanguageModel {
1893
1931
  }),
1894
1932
  raw: candidate.finishReason
1895
1933
  };
1896
- providerMetadata = {
1897
- [providerOptionsName]: {
1898
- promptFeedback: (_j = value.promptFeedback) != null ? _j : null,
1899
- groundingMetadata: lastGroundingMetadata,
1900
- urlContextMetadata: lastUrlContextMetadata,
1901
- safetyRatings: (_k = candidate.safetyRatings) != null ? _k : null,
1902
- usageMetadata: usageMetadata != null ? usageMetadata : null,
1903
- finishMessage: (_l = candidate.finishMessage) != null ? _l : null,
1904
- serviceTier
1905
- }
1906
- };
1934
+ providerMetadata = wrapProviderMetadata({
1935
+ promptFeedback: (_j = value.promptFeedback) != null ? _j : null,
1936
+ groundingMetadata: lastGroundingMetadata,
1937
+ urlContextMetadata: lastUrlContextMetadata,
1938
+ safetyRatings: (_k = candidate.safetyRatings) != null ? _k : null,
1939
+ usageMetadata: usageMetadata != null ? usageMetadata : null,
1940
+ finishMessage: (_l = candidate.finishMessage) != null ? _l : null,
1941
+ serviceTier
1942
+ });
1907
1943
  }
1908
1944
  },
1909
1945
  flush(controller) {