@ai-sdk/google 4.0.79 → 4.0.82

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.
@@ -22,15 +22,14 @@ import { z as z4 } from "zod/v4";
22
22
  // src/convert-google-usage.ts
23
23
  import { createNullLanguageModelUsage } from "@ai-sdk/provider-utils";
24
24
  function convertGoogleUsage(usage) {
25
- var _a, _b, _c, _d, _e;
26
25
  if (usage == null) {
27
26
  return createNullLanguageModelUsage();
28
27
  }
29
- const promptTokens = (_a = usage.promptTokenCount) != null ? _a : 0;
30
- const candidatesTokens = (_b = usage.candidatesTokenCount) != null ? _b : 0;
31
- const toolUsePromptTokens = (_c = usage.toolUsePromptTokenCount) != null ? _c : 0;
32
- const cachedContentTokens = (_d = usage.cachedContentTokenCount) != null ? _d : 0;
33
- const thoughtsTokens = (_e = usage.thoughtsTokenCount) != null ? _e : 0;
28
+ const promptTokens = usage.promptTokenCount ?? 0;
29
+ const candidatesTokens = usage.candidatesTokenCount ?? 0;
30
+ const toolUsePromptTokens = usage.toolUsePromptTokenCount ?? 0;
31
+ const cachedContentTokens = usage.cachedContentTokenCount ?? 0;
32
+ const thoughtsTokens = usage.thoughtsTokenCount ?? 0;
34
33
  const inputTokens = promptTokens + toolUsePromptTokens;
35
34
  return {
36
35
  inputTokens: {
@@ -56,6 +55,7 @@ import {
56
55
  convertToBase64,
57
56
  getTopLevelMediaType,
58
57
  isFullMediaType,
58
+ isUrlSupported,
59
59
  resolveFullMediaType,
60
60
  resolveProviderReference,
61
61
  secureJsonParse
@@ -103,7 +103,21 @@ function convertUrlToolResultPart(url) {
103
103
  }
104
104
  };
105
105
  }
106
- function appendToolResultParts(parts, toolName, outputValue, toolCallId, includeFunctionCallIds = true) {
106
+ function containsJSONSchemaReference(value) {
107
+ if (Array.isArray(value)) {
108
+ return value.some(containsJSONSchemaReference);
109
+ }
110
+ if (typeof value !== "object" || value === null) {
111
+ return false;
112
+ }
113
+ return Object.entries(value).some(
114
+ ([key, nestedValue]) => key === "$ref" || containsJSONSchemaReference(nestedValue)
115
+ );
116
+ }
117
+ function serializeFunctionResponseContent(value) {
118
+ return containsJSONSchemaReference(value) ? JSON.stringify(value) : value;
119
+ }
120
+ function appendToolResultParts(parts, toolName, outputValue, toolCallId, includeFunctionCallIds = true, supportedUrls = {}) {
107
121
  const functionResponseParts = [];
108
122
  const responseTextParts = [];
109
123
  for (const contentPart of outputValue) {
@@ -121,11 +135,22 @@ function appendToolResultParts(parts, toolName, outputValue, toolCallId, include
121
135
  }
122
136
  });
123
137
  } else if (contentPart.data.type === "url") {
124
- const functionResponsePart = convertUrlToolResultPart(
125
- contentPart.data.url.toString()
126
- );
127
- if (functionResponsePart != null) {
128
- functionResponseParts.push(functionResponsePart);
138
+ const url = contentPart.data.url.toString();
139
+ const convertedUrlPart = convertUrlToolResultPart(url);
140
+ const supportedUrl = contentPart.data.url.protocol === "gs:" && contentPart.data.originalUrl != null ? contentPart.data.originalUrl : url;
141
+ if (convertedUrlPart != null) {
142
+ functionResponseParts.push(convertedUrlPart);
143
+ } else if (isFullMediaType(contentPart.mediaType) && isUrlSupported({
144
+ url: supportedUrl,
145
+ mediaType: contentPart.mediaType,
146
+ supportedUrls
147
+ })) {
148
+ functionResponseParts.push({
149
+ fileData: {
150
+ mimeType: contentPart.mediaType,
151
+ fileUri: supportedUrl
152
+ }
153
+ });
129
154
  } else {
130
155
  responseTextParts.push(JSON.stringify(contentPart));
131
156
  }
@@ -193,17 +218,17 @@ function appendLegacyToolResultParts(parts, toolName, outputValue, toolCallId, i
193
218
  }
194
219
  }
195
220
  function convertToGoogleMessages(prompt, options) {
196
- var _a, _b, _c, _d, _e, _f;
197
221
  const systemInstructionParts = [];
198
222
  const contents = [];
199
223
  let systemMessagesAllowed = true;
200
- const isGemmaModel = (_a = options == null ? void 0 : options.isGemmaModel) != null ? _a : false;
201
- const isGemini3Model = (_b = options == null ? void 0 : options.isGemini3Model) != null ? _b : false;
202
- const onWarning = options == null ? void 0 : options.onWarning;
203
- const providerOptionsNames = (_c = options == null ? void 0 : options.providerOptionsNames) != null ? _c : ["google"];
224
+ const isGemmaModel = options?.isGemmaModel ?? false;
225
+ const isGemini3Model = options?.isGemini3Model ?? false;
226
+ const onWarning = options?.onWarning;
227
+ const providerOptionsNames = options?.providerOptionsNames ?? ["google"];
204
228
  const isVertexLike = !providerOptionsNames.includes("google");
205
- const supportsFunctionResponseParts = (_d = options == null ? void 0 : options.supportsFunctionResponseParts) != null ? _d : true;
206
- const includeFunctionCallIds = (_e = options == null ? void 0 : options.includeFunctionCallIds) != null ? _e : true;
229
+ const supportsFunctionResponseParts = options?.supportsFunctionResponseParts ?? true;
230
+ const includeFunctionCallIds = options?.includeFunctionCallIds ?? true;
231
+ const supportedFunctionResponseUrls = options?.supportedFunctionResponseUrls ?? {};
207
232
  let sentinelInjected = false;
208
233
  const missingSignatureToolNames = [];
209
234
  const injectSkipSignature = (toolName) => {
@@ -212,15 +237,14 @@ function convertToGoogleMessages(prompt, options) {
212
237
  return SKIP_THOUGHT_SIGNATURE_VALIDATOR;
213
238
  };
214
239
  const readProviderOpts = (part) => {
215
- var _a2, _b2, _c2, _d2, _e2;
216
240
  for (const name of providerOptionsNames) {
217
- const v = (_a2 = part.providerOptions) == null ? void 0 : _a2[name];
241
+ const v = part.providerOptions?.[name];
218
242
  if (v != null) return v;
219
243
  }
220
244
  if (isVertexLike) {
221
- return (_b2 = part.providerOptions) == null ? void 0 : _b2.google;
245
+ return part.providerOptions?.google;
222
246
  }
223
- return (_e2 = (_c2 = part.providerOptions) == null ? void 0 : _c2.googleVertex) != null ? _e2 : (_d2 = part.providerOptions) == null ? void 0 : _d2.vertex;
247
+ return part.providerOptions?.googleVertex ?? part.providerOptions?.vertex;
224
248
  };
225
249
  for (const { role, content } of prompt) {
226
250
  switch (role) {
@@ -305,7 +329,7 @@ function convertToGoogleMessages(prompt, options) {
305
329
  role: "model",
306
330
  parts: content.map((part) => {
307
331
  const providerOpts = readProviderOpts(part);
308
- const thoughtSignature = (providerOpts == null ? void 0 : providerOpts.thoughtSignature) != null ? String(providerOpts.thoughtSignature) : void 0;
332
+ const thoughtSignature = providerOpts?.thoughtSignature != null ? String(providerOpts.thoughtSignature) : void 0;
309
333
  switch (part.type) {
310
334
  case "text": {
311
335
  return part.text.length === 0 ? void 0 : {
@@ -361,7 +385,7 @@ function convertToGoogleMessages(prompt, options) {
361
385
  provider: "google"
362
386
  })
363
387
  },
364
- ...(providerOpts == null ? void 0 : providerOpts.thought) === true ? { thought: true } : {},
388
+ ...providerOpts?.thought === true ? { thought: true } : {},
365
389
  thoughtSignature
366
390
  };
367
391
  }
@@ -373,7 +397,7 @@ function convertToGoogleMessages(prompt, options) {
373
397
  new TextEncoder().encode(part.data.text)
374
398
  )
375
399
  },
376
- ...(providerOpts == null ? void 0 : providerOpts.thought) === true ? { thought: true } : {},
400
+ ...providerOpts?.thought === true ? { thought: true } : {},
377
401
  thoughtSignature
378
402
  };
379
403
  }
@@ -383,7 +407,7 @@ function convertToGoogleMessages(prompt, options) {
383
407
  mimeType: part.mediaType,
384
408
  data: convertToBase64(part.data.data)
385
409
  },
386
- ...(providerOpts == null ? void 0 : providerOpts.thought) === true ? { thought: true } : {},
410
+ ...providerOpts?.thought === true ? { thought: true } : {},
387
411
  thoughtSignature
388
412
  };
389
413
  }
@@ -398,8 +422,8 @@ function convertToGoogleMessages(prompt, options) {
398
422
  )
399
423
  };
400
424
  }
401
- const serverToolCallId = (providerOpts == null ? void 0 : providerOpts.serverToolCallId) != null ? String(providerOpts.serverToolCallId) : void 0;
402
- const serverToolType = (providerOpts == null ? void 0 : providerOpts.serverToolType) != null ? String(providerOpts.serverToolType) : void 0;
425
+ const serverToolCallId = providerOpts?.serverToolCallId != null ? String(providerOpts.serverToolCallId) : void 0;
426
+ const serverToolType = providerOpts?.serverToolType != null ? String(providerOpts.serverToolType) : void 0;
403
427
  const isServerToolCall = serverToolCallId != null && serverToolType != null;
404
428
  const shouldSkipMissingSignatureMitigation = (
405
429
  // Gemini 3 returns a single signature for a parallel
@@ -408,7 +432,7 @@ function convertToGoogleMessages(prompt, options) {
408
432
  // model response legitimately have no signature.
409
433
  !isServerToolCall && thoughtSignature == null && modelResponseHasSignedFunctionCall
410
434
  );
411
- const effectiveThoughtSignature = thoughtSignature != null ? thoughtSignature : isGemini3Model && !shouldSkipMissingSignatureMitigation ? injectSkipSignature(part.toolName) : void 0;
435
+ const effectiveThoughtSignature = thoughtSignature ?? (isGemini3Model && !shouldSkipMissingSignatureMitigation ? injectSkipSignature(part.toolName) : void 0);
412
436
  if (!isServerToolCall && thoughtSignature != null) {
413
437
  modelResponseHasSignedFunctionCall = true;
414
438
  }
@@ -439,8 +463,8 @@ function convertToGoogleMessages(prompt, options) {
439
463
  )
440
464
  };
441
465
  }
442
- const serverToolCallId = (providerOpts == null ? void 0 : providerOpts.serverToolCallId) != null ? String(providerOpts.serverToolCallId) : void 0;
443
- const serverToolType = (providerOpts == null ? void 0 : providerOpts.serverToolType) != null ? String(providerOpts.serverToolType) : void 0;
466
+ const serverToolCallId = providerOpts?.serverToolCallId != null ? String(providerOpts.serverToolCallId) : void 0;
467
+ const serverToolType = providerOpts?.serverToolType != null ? String(providerOpts.serverToolType) : void 0;
444
468
  if (serverToolCallId && serverToolType) {
445
469
  return {
446
470
  toolResponse: {
@@ -466,10 +490,10 @@ function convertToGoogleMessages(prompt, options) {
466
490
  continue;
467
491
  }
468
492
  const partProviderOpts = readProviderOpts(part);
469
- const serverToolCallId = (partProviderOpts == null ? void 0 : partProviderOpts.serverToolCallId) != null ? String(partProviderOpts.serverToolCallId) : void 0;
470
- const serverToolType = (partProviderOpts == null ? void 0 : partProviderOpts.serverToolType) != null ? String(partProviderOpts.serverToolType) : void 0;
493
+ const serverToolCallId = partProviderOpts?.serverToolCallId != null ? String(partProviderOpts.serverToolCallId) : void 0;
494
+ const serverToolType = partProviderOpts?.serverToolType != null ? String(partProviderOpts.serverToolType) : void 0;
471
495
  if (serverToolCallId && serverToolType) {
472
- const serverThoughtSignature = (partProviderOpts == null ? void 0 : partProviderOpts.thoughtSignature) != null ? String(partProviderOpts.thoughtSignature) : void 0;
496
+ const serverThoughtSignature = partProviderOpts?.thoughtSignature != null ? String(partProviderOpts.thoughtSignature) : void 0;
473
497
  if (contents.length > 0) {
474
498
  const lastContent = contents[contents.length - 1];
475
499
  if (lastContent.role === "model") {
@@ -493,7 +517,8 @@ function convertToGoogleMessages(prompt, options) {
493
517
  part.toolName,
494
518
  output.value,
495
519
  part.toolCallId,
496
- includeFunctionCallIds
520
+ includeFunctionCallIds,
521
+ supportedFunctionResponseUrls
497
522
  );
498
523
  } else {
499
524
  appendLegacyToolResultParts(
@@ -511,7 +536,7 @@ function convertToGoogleMessages(prompt, options) {
511
536
  name: part.toolName,
512
537
  response: {
513
538
  name: part.toolName,
514
- content: output.type === "execution-denied" ? (_f = output.reason) != null ? _f : "Tool call execution denied." : output.value
539
+ content: output.type === "execution-denied" ? output.reason ?? "Tool call execution denied." : serializeFunctionResponseContent(output.value)
515
540
  }
516
541
  }
517
542
  });
@@ -546,11 +571,13 @@ function convertToGoogleMessages(prompt, options) {
546
571
  import {
547
572
  detectMediaType,
548
573
  downloadBlob,
549
- isFullMediaType as isFullMediaType2
574
+ isFullMediaType as isFullMediaType2,
575
+ isUrlSupported as isUrlSupported2
550
576
  } from "@ai-sdk/provider-utils";
551
577
  async function downloadToolResultFiles(prompt, {
552
578
  abortSignal,
553
- maxBytes
579
+ maxBytes,
580
+ supportedUrls = {}
554
581
  }) {
555
582
  const result = [];
556
583
  for (const message of prompt) {
@@ -562,7 +589,8 @@ async function downloadToolResultFiles(prompt, {
562
589
  ...part,
563
590
  output: await downloadToolResultOutput(part.output, {
564
591
  abortSignal,
565
- maxBytes
592
+ maxBytes,
593
+ supportedUrls
566
594
  })
567
595
  } : part
568
596
  );
@@ -581,7 +609,8 @@ async function downloadToolResultFiles(prompt, {
581
609
  ...part,
582
610
  output: await downloadToolResultOutput(part.output, {
583
611
  abortSignal,
584
- maxBytes
612
+ maxBytes,
613
+ supportedUrls
585
614
  })
586
615
  });
587
616
  }
@@ -594,7 +623,8 @@ async function downloadToolResultFiles(prompt, {
594
623
  }
595
624
  async function downloadToolResultOutput(output, {
596
625
  abortSignal,
597
- maxBytes
626
+ maxBytes,
627
+ supportedUrls
598
628
  }) {
599
629
  if (output.type !== "content") {
600
630
  return output;
@@ -605,6 +635,14 @@ async function downloadToolResultOutput(output, {
605
635
  value.push(part);
606
636
  continue;
607
637
  }
638
+ if (isUrlSupported2({
639
+ url: part.data.url.toString(),
640
+ mediaType: part.mediaType,
641
+ supportedUrls
642
+ })) {
643
+ value.push(part);
644
+ continue;
645
+ }
608
646
  const blob = await downloadBlob(part.data.url.toString(), {
609
647
  abortSignal,
610
648
  maxBytes
@@ -617,7 +655,7 @@ async function downloadToolResultOutput(output, {
617
655
  value.push({
618
656
  ...part,
619
657
  data: { type: "data", data },
620
- mediaType: detectedMediaType != null ? detectedMediaType : blob.type && !isFullMediaType2(part.mediaType) ? blob.type : part.mediaType
658
+ mediaType: detectedMediaType ?? (blob.type && !isFullMediaType2(part.mediaType) ? blob.type : part.mediaType)
621
659
  });
622
660
  }
623
661
  return {
@@ -915,7 +953,7 @@ function prepareTools({
915
953
  modelId,
916
954
  isVertexProvider = false
917
955
  }) {
918
- tools = (tools == null ? void 0 : tools.length) ? tools : void 0;
956
+ tools = tools?.length ? tools : void 0;
919
957
  const toolWarnings = [];
920
958
  const { supportsGemini2Tools, supportsFileSearch, usesGemini3Features } = getGoogleModelCapabilities(modelId);
921
959
  if (tools == null) {
@@ -1144,10 +1182,9 @@ function prepareTools({
1144
1182
  }
1145
1183
  }
1146
1184
  function prepareFunctionDeclaration(tool) {
1147
- var _a;
1148
1185
  return {
1149
1186
  name: tool.name,
1150
- description: (_a = tool.description) != null ? _a : "",
1187
+ description: tool.description ?? "",
1151
1188
  parametersJsonSchema: tool.inputSchema
1152
1189
  };
1153
1190
  }
@@ -1386,8 +1423,7 @@ function setNestedValue(obj, segments, value) {
1386
1423
  defineOwnProperty(current, segments[segments.length - 1], value);
1387
1424
  }
1388
1425
  function resolvePartialArgValue(arg) {
1389
- var _a, _b;
1390
- const value = (_b = (_a = arg.stringValue) != null ? _a : arg.numberValue) != null ? _b : arg.boolValue;
1426
+ const value = arg.stringValue ?? arg.numberValue ?? arg.boolValue;
1391
1427
  if (value != null) return { value, json: JSON.stringify(value) };
1392
1428
  if ("nullValue" in arg) return { value: null, json: "null" };
1393
1429
  }
@@ -1426,13 +1462,19 @@ var configurableSafetySettingCategories = [
1426
1462
  "HARM_CATEGORY_SEXUALLY_EXPLICIT"
1427
1463
  ];
1428
1464
  var gemini25ModelPattern2 = /(^|\/)gemini-2\.5(?:[.-]|$)/i;
1465
+ var googleCloudStorageFunctionResponseUrls = {
1466
+ "image/png": [/^gs:\/\/.*$/],
1467
+ "image/jpeg": [/^gs:\/\/.*$/],
1468
+ "image/webp": [/^gs:\/\/.*$/],
1469
+ "application/pdf": [/^gs:\/\/.*$/],
1470
+ "text/plain": [/^gs:\/\/.*$/]
1471
+ };
1429
1472
  var GoogleLanguageModel = class _GoogleLanguageModel {
1430
1473
  constructor(modelId, config) {
1431
1474
  this.specificationVersion = "v4";
1432
- var _a;
1433
1475
  this.modelId = modelId;
1434
1476
  this.config = config;
1435
- this.generateId = (_a = config.generateId) != null ? _a : generateId;
1477
+ this.generateId = config.generateId ?? generateId;
1436
1478
  }
1437
1479
  static [WORKFLOW_SERIALIZE](model) {
1438
1480
  return serializeModelOptions({
@@ -1447,8 +1489,7 @@ var GoogleLanguageModel = class _GoogleLanguageModel {
1447
1489
  return this.config.provider;
1448
1490
  }
1449
1491
  get supportedUrls() {
1450
- var _a, _b, _c;
1451
- return (_c = (_b = (_a = this.config).supportedUrls) == null ? void 0 : _b.call(_a)) != null ? _c : {};
1492
+ return this.config.supportedUrls?.() ?? {};
1452
1493
  }
1453
1494
  static async prepareRequest({
1454
1495
  modelId,
@@ -1472,7 +1513,6 @@ var GoogleLanguageModel = class _GoogleLanguageModel {
1472
1513
  },
1473
1514
  isStreaming = false
1474
1515
  }) {
1475
- var _a, _b, _c;
1476
1516
  const warnings = [];
1477
1517
  const providerOptionsNames = config.provider.includes(
1478
1518
  "vertex"
@@ -1494,33 +1534,33 @@ var GoogleLanguageModel = class _GoogleLanguageModel {
1494
1534
  });
1495
1535
  }
1496
1536
  const isVertexProvider = config.provider.startsWith("google.vertex.");
1497
- if ((tools == null ? void 0 : tools.some(
1537
+ if (tools?.some(
1498
1538
  (tool) => tool.type === "provider" && tool.id === "google.vertex_rag_store"
1499
- )) && !isVertexProvider) {
1539
+ ) && !isVertexProvider) {
1500
1540
  warnings.push({
1501
1541
  type: "other",
1502
1542
  message: `The 'vertex_rag_store' tool is only supported with the Google Vertex provider and might not be supported or could behave unexpectedly with the current Google provider (${config.provider}).`
1503
1543
  });
1504
1544
  }
1505
- if ((googleOptions == null ? void 0 : googleOptions.streamFunctionCallArguments) && !isVertexProvider) {
1545
+ if (googleOptions?.streamFunctionCallArguments && !isVertexProvider) {
1506
1546
  warnings.push({
1507
1547
  type: "other",
1508
1548
  message: `'streamFunctionCallArguments' is only supported on the Vertex AI API and will be ignored with the current Google provider (${config.provider}). See https://docs.cloud.google.com/vertex-ai/generative-ai/docs/multimodal/function-calling#streaming-fc`
1509
1549
  });
1510
1550
  }
1511
- if ((googleOptions == null ? void 0 : googleOptions.serviceTier) && isVertexProvider) {
1551
+ if (googleOptions?.serviceTier && isVertexProvider) {
1512
1552
  warnings.push({
1513
1553
  type: "other",
1514
1554
  message: "'serviceTier' is a Gemini API option and is not supported on Vertex AI. Use 'sharedRequestType' (and optionally 'requestType') instead. See https://docs.cloud.google.com/vertex-ai/generative-ai/docs/priority-paygo"
1515
1555
  });
1516
1556
  }
1517
- if (((googleOptions == null ? void 0 : googleOptions.sharedRequestType) || (googleOptions == null ? void 0 : googleOptions.requestType)) && !isVertexProvider) {
1557
+ if ((googleOptions?.sharedRequestType || googleOptions?.requestType) && !isVertexProvider) {
1518
1558
  warnings.push({
1519
1559
  type: "other",
1520
1560
  message: `'sharedRequestType' and 'requestType' are Vertex AI options and are ignored with the current Google provider (${config.provider}).`
1521
1561
  });
1522
1562
  }
1523
- const vertexPaygoHeaders = isVertexProvider && ((googleOptions == null ? void 0 : googleOptions.sharedRequestType) || (googleOptions == null ? void 0 : googleOptions.requestType)) ? {
1563
+ const vertexPaygoHeaders = isVertexProvider && (googleOptions?.sharedRequestType || googleOptions?.requestType) ? {
1524
1564
  ...googleOptions.sharedRequestType && {
1525
1565
  "X-Vertex-AI-LLM-Shared-Request-Type": googleOptions.sharedRequestType
1526
1566
  },
@@ -1528,8 +1568,8 @@ var GoogleLanguageModel = class _GoogleLanguageModel {
1528
1568
  "X-Vertex-AI-LLM-Request-Type": googleOptions.requestType
1529
1569
  }
1530
1570
  } : void 0;
1531
- const bodyServiceTier = isVertexProvider ? void 0 : googleOptions == null ? void 0 : googleOptions.serviceTier;
1532
- let imageConfig = googleOptions == null ? void 0 : googleOptions.imageConfig;
1571
+ const bodyServiceTier = isVertexProvider ? void 0 : googleOptions?.serviceTier;
1572
+ let imageConfig = googleOptions?.imageConfig;
1533
1573
  if (imageConfig != null && !isVertexProvider) {
1534
1574
  const {
1535
1575
  personGeneration,
@@ -1565,9 +1605,11 @@ var GoogleLanguageModel = class _GoogleLanguageModel {
1565
1605
  });
1566
1606
  }
1567
1607
  const { usesGemini3Features } = getGoogleModelCapabilities(modelId);
1608
+ const supportedFunctionResponseUrls = usesGemini3Features && config.downloadToolResultFiles?.supportsGoogleCloudStorageUrls ? googleCloudStorageFunctionResponseUrls : void 0;
1568
1609
  const promptWithDownloadedToolResultFiles = config.downloadToolResultFiles ? await downloadToolResultFiles(prompt, {
1569
1610
  abortSignal,
1570
- maxBytes: config.downloadToolResultFiles.maxBytes
1611
+ maxBytes: config.downloadToolResultFiles.maxBytes,
1612
+ supportedUrls: supportedFunctionResponseUrls
1571
1613
  }) : prompt;
1572
1614
  const { contents, systemInstruction } = convertToGoogleMessages(
1573
1615
  promptWithDownloadedToolResultFiles,
@@ -1577,7 +1619,8 @@ var GoogleLanguageModel = class _GoogleLanguageModel {
1577
1619
  onWarning: (warning) => warnings.push(warning),
1578
1620
  providerOptionsNames,
1579
1621
  supportsFunctionResponseParts: usesGemini3Features,
1580
- includeFunctionCallIds: !isVertexProvider
1622
+ includeFunctionCallIds: !isVertexProvider,
1623
+ supportedFunctionResponseUrls
1581
1624
  }
1582
1625
  );
1583
1626
  const {
@@ -1601,22 +1644,22 @@ var GoogleLanguageModel = class _GoogleLanguageModel {
1601
1644
  modelId,
1602
1645
  warnings
1603
1646
  });
1604
- const thinkingConfig = (googleOptions == null ? void 0 : googleOptions.thinkingConfig) || resolvedThinking ? { ...resolvedThinking, ...googleOptions == null ? void 0 : googleOptions.thinkingConfig } : void 0;
1605
- const streamFunctionCallArguments = isStreaming && isVertexProvider ? (_a = googleOptions == null ? void 0 : googleOptions.streamFunctionCallArguments) != null ? _a : false : void 0;
1606
- const safetyThreshold = googleOptions == null ? void 0 : googleOptions.threshold;
1607
- const safetySettings = (_b = googleOptions == null ? void 0 : googleOptions.safetySettings) != null ? _b : safetyThreshold != null ? configurableSafetySettingCategories.map((category) => ({
1647
+ const thinkingConfig = googleOptions?.thinkingConfig || resolvedThinking ? { ...resolvedThinking, ...googleOptions?.thinkingConfig } : void 0;
1648
+ const streamFunctionCallArguments = isStreaming && isVertexProvider ? googleOptions?.streamFunctionCallArguments ?? false : void 0;
1649
+ const safetyThreshold = googleOptions?.threshold;
1650
+ const safetySettings = googleOptions?.safetySettings ?? (safetyThreshold != null ? configurableSafetySettingCategories.map((category) => ({
1608
1651
  category,
1609
1652
  threshold: safetyThreshold
1610
- })) : void 0;
1611
- const toolConfig = googleToolConfig || streamFunctionCallArguments || (googleOptions == null ? void 0 : googleOptions.retrievalConfig) ? {
1653
+ })) : void 0);
1654
+ const toolConfig = googleToolConfig || streamFunctionCallArguments || googleOptions?.retrievalConfig ? {
1612
1655
  ...googleToolConfig,
1613
1656
  ...streamFunctionCallArguments && {
1614
1657
  functionCallingConfig: {
1615
- ...googleToolConfig == null ? void 0 : googleToolConfig.functionCallingConfig,
1658
+ ...googleToolConfig?.functionCallingConfig,
1616
1659
  streamFunctionCallArguments: true
1617
1660
  }
1618
1661
  },
1619
- ...(googleOptions == null ? void 0 : googleOptions.retrievalConfig) && {
1662
+ ...googleOptions?.retrievalConfig && {
1620
1663
  retrievalConfig: googleOptions.retrievalConfig
1621
1664
  }
1622
1665
  } : void 0;
@@ -1633,18 +1676,18 @@ var GoogleLanguageModel = class _GoogleLanguageModel {
1633
1676
  stopSequences,
1634
1677
  seed,
1635
1678
  // response format:
1636
- responseMimeType: (responseFormat == null ? void 0 : responseFormat.type) === "json" ? "application/json" : void 0,
1637
- responseJsonSchema: (responseFormat == null ? void 0 : responseFormat.type) === "json" && responseFormat.schema != null && // Google does not support all JSON Schema features in
1679
+ responseMimeType: responseFormat?.type === "json" ? "application/json" : void 0,
1680
+ responseJsonSchema: responseFormat?.type === "json" && responseFormat.schema != null && // Google does not support all JSON Schema features in
1638
1681
  // responseJsonSchema, so this is needed as an escape hatch:
1639
1682
  // TODO convert into provider option
1640
- ((_c = googleOptions == null ? void 0 : googleOptions.structuredOutputs) != null ? _c : true) ? sanitizeResponseJsonSchema(responseFormat.schema) : void 0,
1641
- ...(googleOptions == null ? void 0 : googleOptions.audioTimestamp) && {
1683
+ (googleOptions?.structuredOutputs ?? true) ? sanitizeResponseJsonSchema(responseFormat.schema) : void 0,
1684
+ ...googleOptions?.audioTimestamp && {
1642
1685
  audioTimestamp: googleOptions.audioTimestamp
1643
1686
  },
1644
1687
  // provider options:
1645
- responseModalities: googleOptions == null ? void 0 : googleOptions.responseModalities,
1688
+ responseModalities: googleOptions?.responseModalities,
1646
1689
  thinkingConfig,
1647
- ...(googleOptions == null ? void 0 : googleOptions.mediaResolution) && {
1690
+ ...googleOptions?.mediaResolution && {
1648
1691
  mediaResolution: googleOptions.mediaResolution
1649
1692
  },
1650
1693
  ...imageConfig && { imageConfig }
@@ -1654,8 +1697,8 @@ var GoogleLanguageModel = class _GoogleLanguageModel {
1654
1697
  safetySettings,
1655
1698
  tools: googleTools2,
1656
1699
  toolConfig,
1657
- cachedContent: googleOptions == null ? void 0 : googleOptions.cachedContent,
1658
- labels: googleOptions == null ? void 0 : googleOptions.labels,
1700
+ cachedContent: googleOptions?.cachedContent,
1701
+ labels: googleOptions?.labels,
1659
1702
  serviceTier: bodyServiceTier
1660
1703
  },
1661
1704
  warnings: [...warnings, ...toolWarnings],
@@ -1679,30 +1722,29 @@ var GoogleLanguageModel = class _GoogleLanguageModel {
1679
1722
  providerOptionsNames,
1680
1723
  toolNameMapping
1681
1724
  }) {
1682
- var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o, _p, _q, _r, _s, _t;
1683
1725
  const wrapProviderMetadata = (payload) => Object.fromEntries(
1684
1726
  providerOptionsNames.map((name) => [name, payload])
1685
1727
  );
1686
- const candidate = (_a = response.candidates) == null ? void 0 : _a[0];
1687
- const promptBlockReason = (_b = response.promptFeedback) == null ? void 0 : _b.blockReason;
1728
+ const candidate = response.candidates?.[0];
1729
+ const promptBlockReason = response.promptFeedback?.blockReason;
1688
1730
  const confirmedPromptBlockReason = isConfirmedPromptBlockReason(
1689
1731
  promptBlockReason
1690
1732
  ) ? promptBlockReason : void 0;
1691
- const isPromptBlocked = (candidate == null ? void 0 : candidate.finishReason) == null && confirmedPromptBlockReason != null;
1692
- const rawFinishReason = (_c = candidate == null ? void 0 : candidate.finishReason) != null ? _c : confirmedPromptBlockReason;
1733
+ const isPromptBlocked = candidate?.finishReason == null && confirmedPromptBlockReason != null;
1734
+ const rawFinishReason = candidate?.finishReason ?? confirmedPromptBlockReason;
1693
1735
  const content = [];
1694
- const parts = (_e = (_d = candidate == null ? void 0 : candidate.content) == null ? void 0 : _d.parts) != null ? _e : [];
1736
+ const parts = candidate?.content?.parts ?? [];
1695
1737
  const usageMetadata = response.usageMetadata;
1696
1738
  let lastCodeExecutionToolCallId;
1697
1739
  let lastServerToolCallId;
1698
1740
  for (const part of parts) {
1699
- if ("executableCode" in part && ((_f = part.executableCode) == null ? void 0 : _f.code)) {
1741
+ if ("executableCode" in part && part.executableCode?.code) {
1700
1742
  const toolCallId = config.generateId();
1701
1743
  lastCodeExecutionToolCallId = toolCallId;
1702
1744
  content.push({
1703
1745
  type: "tool-call",
1704
1746
  toolCallId,
1705
- toolName: (_g = toolNameMapping == null ? void 0 : toolNameMapping.toCustomToolName("code_execution")) != null ? _g : "code_execution",
1747
+ toolName: toolNameMapping?.toCustomToolName("code_execution") ?? "code_execution",
1706
1748
  input: JSON.stringify(part.executableCode),
1707
1749
  providerExecuted: true
1708
1750
  });
@@ -1711,10 +1753,10 @@ var GoogleLanguageModel = class _GoogleLanguageModel {
1711
1753
  type: "tool-result",
1712
1754
  // Results correspond to the most recent executable code part.
1713
1755
  toolCallId: lastCodeExecutionToolCallId,
1714
- toolName: (_h = toolNameMapping == null ? void 0 : toolNameMapping.toCustomToolName("code_execution")) != null ? _h : "code_execution",
1756
+ toolName: toolNameMapping?.toCustomToolName("code_execution") ?? "code_execution",
1715
1757
  result: {
1716
1758
  outcome: part.codeExecutionResult.outcome,
1717
- output: (_i = part.codeExecutionResult.output) != null ? _i : ""
1759
+ output: part.codeExecutionResult.output ?? ""
1718
1760
  }
1719
1761
  });
1720
1762
  } else if ("text" in part && part.text != null) {
@@ -1738,7 +1780,7 @@ var GoogleLanguageModel = class _GoogleLanguageModel {
1738
1780
  type: "tool-call",
1739
1781
  toolCallId: part.functionCall.id || config.generateId(),
1740
1782
  toolName: part.functionCall.name,
1741
- input: JSON.stringify((_j = part.functionCall.args) != null ? _j : {}),
1783
+ input: JSON.stringify(part.functionCall.args ?? {}),
1742
1784
  providerMetadata: part.thoughtSignature ? wrapProviderMetadata({
1743
1785
  thoughtSignature: part.thoughtSignature
1744
1786
  }) : void 0
@@ -1761,7 +1803,7 @@ var GoogleLanguageModel = class _GoogleLanguageModel {
1761
1803
  type: "tool-call",
1762
1804
  toolCallId,
1763
1805
  toolName: `server:${part.toolCall.toolType}`,
1764
- input: JSON.stringify((_k = part.toolCall.args) != null ? _k : {}),
1806
+ input: JSON.stringify(part.toolCall.args ?? {}),
1765
1807
  providerExecuted: true,
1766
1808
  dynamic: true,
1767
1809
  providerMetadata: part.thoughtSignature ? wrapProviderMetadata({
@@ -1779,7 +1821,7 @@ var GoogleLanguageModel = class _GoogleLanguageModel {
1779
1821
  type: "tool-result",
1780
1822
  toolCallId: responseToolCallId,
1781
1823
  toolName: `server:${part.toolResponse.toolType}`,
1782
- result: (_l = part.toolResponse.response) != null ? _l : {},
1824
+ result: part.toolResponse.response ?? {},
1783
1825
  providerMetadata: part.thoughtSignature ? wrapProviderMetadata({
1784
1826
  thoughtSignature: part.thoughtSignature,
1785
1827
  serverToolCallId: responseToolCallId,
@@ -1792,10 +1834,10 @@ var GoogleLanguageModel = class _GoogleLanguageModel {
1792
1834
  lastServerToolCallId = void 0;
1793
1835
  }
1794
1836
  }
1795
- const sources = (_m = extractSources({
1796
- groundingMetadata: candidate == null ? void 0 : candidate.groundingMetadata,
1837
+ const sources = extractSources({
1838
+ groundingMetadata: candidate?.groundingMetadata,
1797
1839
  generateId: config.generateId
1798
- })) != null ? _m : [];
1840
+ }) ?? [];
1799
1841
  for (const source of sources) {
1800
1842
  content.push(source);
1801
1843
  }
@@ -1814,17 +1856,17 @@ var GoogleLanguageModel = class _GoogleLanguageModel {
1814
1856
  usage: convertGoogleUsage(usageMetadata),
1815
1857
  warnings,
1816
1858
  providerMetadata: wrapProviderMetadata({
1817
- promptFeedback: (_n = response.promptFeedback) != null ? _n : null,
1818
- groundingMetadata: (_o = candidate == null ? void 0 : candidate.groundingMetadata) != null ? _o : null,
1819
- urlContextMetadata: (_p = candidate == null ? void 0 : candidate.urlContextMetadata) != null ? _p : null,
1820
- safetyRatings: (_q = candidate == null ? void 0 : candidate.safetyRatings) != null ? _q : null,
1821
- usageMetadata: usageMetadata != null ? usageMetadata : null,
1822
- finishMessage: (_r = candidate == null ? void 0 : candidate.finishMessage) != null ? _r : null,
1823
- serviceTier: (_s = usageMetadata == null ? void 0 : usageMetadata.serviceTier) != null ? _s : null
1859
+ promptFeedback: response.promptFeedback ?? null,
1860
+ groundingMetadata: candidate?.groundingMetadata ?? null,
1861
+ urlContextMetadata: candidate?.urlContextMetadata ?? null,
1862
+ safetyRatings: candidate?.safetyRatings ?? null,
1863
+ usageMetadata: usageMetadata ?? null,
1864
+ finishMessage: candidate?.finishMessage ?? null,
1865
+ serviceTier: usageMetadata?.serviceTier ?? null
1824
1866
  }),
1825
1867
  response: {
1826
1868
  // TODO timestamp, model id
1827
- id: (_t = response.responseId) != null ? _t : void 0
1869
+ id: response.responseId ?? void 0
1828
1870
  }
1829
1871
  };
1830
1872
  }
@@ -1956,7 +1998,6 @@ var GoogleLanguageModel = class _GoogleLanguageModel {
1956
1998
  controller.enqueue({ type: "stream-start", warnings });
1957
1999
  },
1958
2000
  transform(chunk, controller) {
1959
- var _a, _b, _c, _d, _e, _f, _g;
1960
2001
  if (options.includeRawChunks) {
1961
2002
  controller.enqueue({ type: "raw", rawValue: chunk.rawValue });
1962
2003
  }
@@ -1986,7 +2027,7 @@ var GoogleLanguageModel = class _GoogleLanguageModel {
1986
2027
  };
1987
2028
  }
1988
2029
  }
1989
- const candidate = (_a = value.candidates) == null ? void 0 : _a[0];
2030
+ const candidate = value.candidates?.[0];
1990
2031
  if (candidate != null) {
1991
2032
  if (candidate.groundingMetadata != null) {
1992
2033
  lastGroundingMetadata = candidate.groundingMetadata;
@@ -2018,9 +2059,9 @@ var GoogleLanguageModel = class _GoogleLanguageModel {
2018
2059
  }
2019
2060
  }
2020
2061
  if (content != null) {
2021
- const parts = (_b = content.parts) != null ? _b : [];
2062
+ const parts = content.parts ?? [];
2022
2063
  for (const part of parts) {
2023
- if ("executableCode" in part && ((_c = part.executableCode) == null ? void 0 : _c.code)) {
2064
+ if ("executableCode" in part && part.executableCode?.code) {
2024
2065
  const toolCallId = generateId2();
2025
2066
  lastCodeExecutionToolCallId = toolCallId;
2026
2067
  controller.enqueue({
@@ -2039,7 +2080,7 @@ var GoogleLanguageModel = class _GoogleLanguageModel {
2039
2080
  toolName: toolNameMapping.toCustomToolName("code_execution"),
2040
2081
  result: {
2041
2082
  outcome: part.codeExecutionResult.outcome,
2042
- output: (_d = part.codeExecutionResult.output) != null ? _d : ""
2083
+ output: part.codeExecutionResult.output ?? ""
2043
2084
  }
2044
2085
  });
2045
2086
  }
@@ -2139,7 +2180,7 @@ var GoogleLanguageModel = class _GoogleLanguageModel {
2139
2180
  type: "tool-call",
2140
2181
  toolCallId,
2141
2182
  toolName: `server:${part.toolCall.toolType}`,
2142
- input: JSON.stringify((_e = part.toolCall.args) != null ? _e : {}),
2183
+ input: JSON.stringify(part.toolCall.args ?? {}),
2143
2184
  providerExecuted: true,
2144
2185
  dynamic: true,
2145
2186
  providerMetadata: serverMeta
@@ -2155,7 +2196,7 @@ var GoogleLanguageModel = class _GoogleLanguageModel {
2155
2196
  type: "tool-result",
2156
2197
  toolCallId: responseToolCallId,
2157
2198
  toolName: `server:${part.toolResponse.toolType}`,
2158
- result: (_f = part.toolResponse.response) != null ? _f : {},
2199
+ result: part.toolResponse.response ?? {},
2159
2200
  providerMetadata: serverMeta
2160
2201
  });
2161
2202
  lastServerToolCallId = void 0;
@@ -2222,7 +2263,7 @@ var GoogleLanguageModel = class _GoogleLanguageModel {
2222
2263
  } else if (isCompleteCall) {
2223
2264
  const toolCallId = part.functionCall.id || generateId2();
2224
2265
  const toolName = part.functionCall.name;
2225
- const args2 = typeof part.functionCall.args === "string" ? part.functionCall.args : JSON.stringify((_g = part.functionCall.args) != null ? _g : {});
2266
+ const args2 = typeof part.functionCall.args === "string" ? part.functionCall.args : JSON.stringify(part.functionCall.args ?? {});
2226
2267
  controller.enqueue({
2227
2268
  type: "tool-input-start",
2228
2269
  id: toolCallId,
@@ -2284,7 +2325,6 @@ var GoogleLanguageModel = class _GoogleLanguageModel {
2284
2325
  }
2285
2326
  },
2286
2327
  flush(controller) {
2287
- var _a;
2288
2328
  if (currentTextBlockId !== null) {
2289
2329
  controller.enqueue({
2290
2330
  type: "text-end",
@@ -2306,9 +2346,9 @@ var GoogleLanguageModel = class _GoogleLanguageModel {
2306
2346
  groundingMetadata: lastGroundingMetadata,
2307
2347
  urlContextMetadata: lastUrlContextMetadata,
2308
2348
  safetyRatings: lastSafetyRatings,
2309
- usageMetadata: usage != null ? usage : null,
2349
+ usageMetadata: usage ?? null,
2310
2350
  finishMessage: lastFinishMessage,
2311
- serviceTier: (_a = usage == null ? void 0 : usage.serviceTier) != null ? _a : null
2351
+ serviceTier: usage?.serviceTier ?? null
2312
2352
  })
2313
2353
  });
2314
2354
  }
@@ -2368,13 +2408,12 @@ function resolveGemini3ThinkingConfig({
2368
2408
  return { thinkingLevel };
2369
2409
  }
2370
2410
  function getMinimumThinkingLevelForGemini3Model(modelId) {
2371
- var _a;
2372
- const modelName = (_a = modelId.split("/").at(-1)) == null ? void 0 : _a.toLowerCase();
2411
+ const modelName = modelId.split("/").at(-1)?.toLowerCase();
2373
2412
  if (modelName === "gemini-flash-latest") {
2374
2413
  return "low";
2375
2414
  }
2376
2415
  const versionMatch = /^gemini-(\d+)\.(\d+)-flash(?:$|-(?!lite(?:-|$)))/.exec(
2377
- modelName != null ? modelName : ""
2416
+ modelName ?? ""
2378
2417
  );
2379
2418
  if (versionMatch == null) {
2380
2419
  return "minimal";
@@ -2407,8 +2446,7 @@ function extractSources({
2407
2446
  groundingMetadata,
2408
2447
  generateId: generateId2
2409
2448
  }) {
2410
- var _a, _b, _c, _d, _e, _f;
2411
- if (!(groundingMetadata == null ? void 0 : groundingMetadata.groundingChunks)) {
2449
+ if (!groundingMetadata?.groundingChunks) {
2412
2450
  return void 0;
2413
2451
  }
2414
2452
  const sources = [];
@@ -2419,7 +2457,7 @@ function extractSources({
2419
2457
  sourceType: "url",
2420
2458
  id: generateId2(),
2421
2459
  url: chunk.web.uri,
2422
- title: (_a = chunk.web.title) != null ? _a : void 0
2460
+ title: chunk.web.title ?? void 0
2423
2461
  });
2424
2462
  } else if (chunk.image != null) {
2425
2463
  sources.push({
@@ -2429,7 +2467,7 @@ function extractSources({
2429
2467
  // Google requires attribution to the source URI, not the actual image URI.
2430
2468
  // TODO: add another type in v7 to allow both the image and source URL to be included separately
2431
2469
  url: chunk.image.sourceUri,
2432
- title: (_b = chunk.image.title) != null ? _b : void 0
2470
+ title: chunk.image.title ?? void 0
2433
2471
  });
2434
2472
  } else if (chunk.retrievedContext != null) {
2435
2473
  const uri = chunk.retrievedContext.uri;
@@ -2440,10 +2478,10 @@ function extractSources({
2440
2478
  sourceType: "url",
2441
2479
  id: generateId2(),
2442
2480
  url: uri,
2443
- title: (_c = chunk.retrievedContext.title) != null ? _c : void 0
2481
+ title: chunk.retrievedContext.title ?? void 0
2444
2482
  });
2445
2483
  } else if (uri) {
2446
- const title = (_d = chunk.retrievedContext.title) != null ? _d : "Unknown Document";
2484
+ const title = chunk.retrievedContext.title ?? "Unknown Document";
2447
2485
  let mediaType = "application/octet-stream";
2448
2486
  let filename = void 0;
2449
2487
  if (uri.endsWith(".pdf")) {
@@ -2473,7 +2511,7 @@ function extractSources({
2473
2511
  filename
2474
2512
  });
2475
2513
  } else if (fileSearchStore) {
2476
- const title = (_e = chunk.retrievedContext.title) != null ? _e : "Unknown Document";
2514
+ const title = chunk.retrievedContext.title ?? "Unknown Document";
2477
2515
  sources.push({
2478
2516
  type: "source",
2479
2517
  sourceType: "document",
@@ -2490,7 +2528,7 @@ function extractSources({
2490
2528
  sourceType: "url",
2491
2529
  id: generateId2(),
2492
2530
  url: chunk.maps.uri,
2493
- title: (_f = chunk.maps.title) != null ? _f : void 0
2531
+ title: chunk.maps.title ?? void 0
2494
2532
  });
2495
2533
  }
2496
2534
  }
@@ -2740,7 +2778,7 @@ function getGoogleSpeechInput({
2740
2778
  voice,
2741
2779
  providerOptions
2742
2780
  }) {
2743
- const google = providerOptions == null ? void 0 : providerOptions.google;
2781
+ const google = providerOptions?.google;
2744
2782
  const options = google != null && typeof google === "object" ? google : void 0;
2745
2783
  const turns = options && "turns" in options ? options.turns : void 0;
2746
2784
  const turnTexts = [];
@@ -2759,7 +2797,7 @@ function getGoogleSpeechInput({
2759
2797
  const speakers = config != null && typeof config === "object" && "speakerVoiceConfigs" in config && Array.isArray(config.speakerVoiceConfigs) ? config.speakerVoiceConfigs : [];
2760
2798
  return {
2761
2799
  text,
2762
- usesCustomVoice: (voice == null ? void 0 : voice.startsWith("voice_")) === true || (voice == null ? void 0 : voice.startsWith("voicekey_")) === true || speakers.some(
2800
+ usesCustomVoice: voice?.startsWith("voice_") === true || voice?.startsWith("voicekey_") === true || speakers.some(
2763
2801
  (speaker) => speaker != null && typeof speaker === "object" && "voiceConfig" in speaker && speaker.voiceConfig != null && typeof speaker.voiceConfig === "object" && "voice" in speaker.voiceConfig
2764
2802
  )
2765
2803
  };
@@ -2848,7 +2886,6 @@ var GoogleSpeechModel = class _GoogleSpeechModel {
2848
2886
  language,
2849
2887
  providerOptions
2850
2888
  }) {
2851
- var _a;
2852
2889
  const warnings = [];
2853
2890
  const providerOptionsNames = this.config.provider.includes("vertex") ? ["googleVertex", "vertex"] : ["google"];
2854
2891
  let googleOptions;
@@ -2881,7 +2918,7 @@ var GoogleSpeechModel = class _GoogleSpeechModel {
2881
2918
  message: "Custom voices are not supported. Use a prebuilt voice instead."
2882
2919
  });
2883
2920
  }
2884
- const multiSpeakerVoiceConfig = googleOptions == null ? void 0 : googleOptions.multiSpeakerVoiceConfig;
2921
+ const multiSpeakerVoiceConfig = googleOptions?.multiSpeakerVoiceConfig;
2885
2922
  const speechConfig = multiSpeakerVoiceConfig ? { multiSpeakerVoiceConfig } : { voiceConfig: { prebuiltVoiceConfig: { voiceName: voice } } };
2886
2923
  let promptText = text;
2887
2924
  if (instructions != null && !usesStructuredSpeech) {
@@ -2897,25 +2934,24 @@ var GoogleSpeechModel = class _GoogleSpeechModel {
2897
2934
  }
2898
2935
  let parts = [{ text: promptText }];
2899
2936
  if (usesStructuredSpeech) {
2900
- if ((googleOptions == null ? void 0 : googleOptions.turns) && googleOptions.speechMetadata) {
2937
+ if (googleOptions?.turns && googleOptions.speechMetadata) {
2901
2938
  throw new InvalidArgumentError({
2902
2939
  argument: "providerOptions",
2903
2940
  message: "Set speechMetadata on each turn when using turns."
2904
2941
  });
2905
2942
  }
2906
- if ((googleOptions == null ? void 0 : googleOptions.turns) && text !== "") {
2943
+ if (googleOptions?.turns && text !== "") {
2907
2944
  warnings.push({
2908
2945
  type: "unsupported",
2909
2946
  feature: "text",
2910
2947
  details: "Google TTS turns replace the top-level text."
2911
2948
  });
2912
2949
  }
2913
- parts = ((_a = googleOptions == null ? void 0 : googleOptions.turns) != null ? _a : [
2914
- { text, speechMetadata: googleOptions == null ? void 0 : googleOptions.speechMetadata }
2950
+ parts = (googleOptions?.turns ?? [
2951
+ { text, speechMetadata: googleOptions?.speechMetadata }
2915
2952
  ]).map((part) => {
2916
- var _a2, _b, _c;
2917
- const style = (_b = (_a2 = part.speechMetadata) == null ? void 0 : _a2.style) != null ? _b : instructions;
2918
- const speaker = (_c = part.speechMetadata) == null ? void 0 : _c.speaker;
2953
+ const style = part.speechMetadata?.style ?? instructions;
2954
+ const speaker = part.speechMetadata?.speaker;
2919
2955
  if (multiSpeakerVoiceConfig && !multiSpeakerVoiceConfig.speakerVoiceConfigs.some(
2920
2956
  (config) => config.speaker === speaker
2921
2957
  )) {
@@ -2929,7 +2965,7 @@ var GoogleSpeechModel = class _GoogleSpeechModel {
2929
2965
  ...style != null || speaker != null ? { speechMetadata: { style, speaker } } : {}
2930
2966
  };
2931
2967
  });
2932
- } else if ((googleOptions == null ? void 0 : googleOptions.turns) || (googleOptions == null ? void 0 : googleOptions.speechMetadata)) {
2968
+ } else if (googleOptions?.turns || googleOptions?.speechMetadata) {
2933
2969
  throw new InvalidArgumentError({
2934
2970
  argument: "providerOptions",
2935
2971
  message: "Structured speech metadata and turns require Gemini 3.8 TTS."
@@ -2995,8 +3031,7 @@ var GoogleSpeechModel = class _GoogleSpeechModel {
2995
3031
  };
2996
3032
  }
2997
3033
  async doGenerate(options) {
2998
- var _a, _b, _c, _d, _e, _f, _g, _h, _i;
2999
- const currentDate = (_c = (_b = (_a = this.config._internal) == null ? void 0 : _a.currentDate) == null ? void 0 : _b.call(_a)) != null ? _c : /* @__PURE__ */ new Date();
3034
+ const currentDate = this.config._internal?.currentDate?.() ?? /* @__PURE__ */ new Date();
3000
3035
  const { requestBody, warnings, outputFormat, usesStructuredSpeech } = await this.getArgs(options);
3001
3036
  const {
3002
3037
  value: response,
@@ -3018,11 +3053,11 @@ var GoogleSpeechModel = class _GoogleSpeechModel {
3018
3053
  });
3019
3054
  let base64Audio;
3020
3055
  let mimeType;
3021
- for (const candidate of (_d = response.candidates) != null ? _d : []) {
3022
- for (const part of (_f = (_e = candidate.content) == null ? void 0 : _e.parts) != null ? _f : []) {
3023
- if ((_g = part.inlineData) == null ? void 0 : _g.data) {
3056
+ for (const candidate of response.candidates ?? []) {
3057
+ for (const part of candidate.content?.parts ?? []) {
3058
+ if (part.inlineData?.data) {
3024
3059
  base64Audio = part.inlineData.data;
3025
- mimeType = (_h = part.inlineData.mimeType) != null ? _h : void 0;
3060
+ mimeType = part.inlineData.mimeType ?? void 0;
3026
3061
  break;
3027
3062
  }
3028
3063
  }
@@ -3030,9 +3065,9 @@ var GoogleSpeechModel = class _GoogleSpeechModel {
3030
3065
  break;
3031
3066
  }
3032
3067
  }
3033
- const sampleRate = (_i = parseSampleRate(mimeType)) != null ? _i : DEFAULT_SAMPLE_RATE;
3068
+ const sampleRate = parseSampleRate(mimeType) ?? DEFAULT_SAMPLE_RATE;
3034
3069
  const bytes = base64Audio != null ? convertBase64ToUint8Array(base64Audio) : new Uint8Array(0);
3035
- const isPcm = /^audio\/(?:l16|pcm)(?:;|$)/i.test(mimeType != null ? mimeType : "") || mimeType == null && !usesStructuredSpeech;
3070
+ const isPcm = /^audio\/(?:l16|pcm)(?:;|$)/i.test(mimeType ?? "") || mimeType == null && !usesStructuredSpeech;
3036
3071
  const audio = outputFormat === "AUDIO_WAV" && isPcm && bytes.length > 0 ? addWavHeader(bytes, sampleRate) : bytes;
3037
3072
  if (outputFormat === "AUDIO_L16" && bytes.length > 0 && !usesStructuredSpeech) {
3038
3073
  warnings.push({
@@ -3056,7 +3091,7 @@ var GoogleSpeechModel = class _GoogleSpeechModel {
3056
3091
  providerMetadata: {
3057
3092
  google: {
3058
3093
  sampleRate,
3059
- mimeType: mimeType != null ? mimeType : null
3094
+ mimeType: mimeType ?? null
3060
3095
  }
3061
3096
  }
3062
3097
  };
@@ -3286,37 +3321,36 @@ import {
3286
3321
  // src/interactions/convert-google-interactions-usage.ts
3287
3322
  import { createNullLanguageModelUsage as createNullLanguageModelUsage2 } from "@ai-sdk/provider-utils";
3288
3323
  function convertGoogleInteractionsUsage(usage) {
3289
- var _a, _b, _c, _d, _e, _f, _g, _h;
3290
3324
  if (usage == null) {
3291
3325
  return createNullLanguageModelUsage2();
3292
3326
  }
3293
- const totalInput = (_a = usage.total_input_tokens) != null ? _a : 0;
3294
- const totalOutput = (_b = usage.total_output_tokens) != null ? _b : 0;
3295
- const totalThought = (_c = usage.total_thought_tokens) != null ? _c : 0;
3296
- const totalCached = (_d = usage.total_cached_tokens) != null ? _d : 0;
3327
+ const totalInput = usage.total_input_tokens ?? 0;
3328
+ const totalOutput = usage.total_output_tokens ?? 0;
3329
+ const totalThought = usage.total_thought_tokens ?? 0;
3330
+ const totalCached = usage.total_cached_tokens ?? 0;
3297
3331
  return {
3298
3332
  inputTokens: {
3299
- total: (_e = usage.total_input_tokens) != null ? _e : void 0,
3333
+ total: usage.total_input_tokens ?? void 0,
3300
3334
  noCache: usage.total_input_tokens == null ? void 0 : totalInput - totalCached,
3301
- cacheRead: (_f = usage.total_cached_tokens) != null ? _f : void 0,
3335
+ cacheRead: usage.total_cached_tokens ?? void 0,
3302
3336
  cacheWrite: void 0
3303
3337
  },
3304
3338
  outputTokens: {
3305
3339
  total: usage.total_output_tokens == null && usage.total_thought_tokens == null ? void 0 : totalOutput + totalThought,
3306
- text: (_g = usage.total_output_tokens) != null ? _g : void 0,
3307
- reasoning: (_h = usage.total_thought_tokens) != null ? _h : void 0
3340
+ text: usage.total_output_tokens ?? void 0,
3341
+ reasoning: usage.total_thought_tokens ?? void 0
3308
3342
  },
3309
3343
  raw: usage
3310
3344
  };
3311
3345
  }
3312
3346
  function getGoogleInteractionsOutputTokensByModality(usage) {
3313
- const byModality = usage == null ? void 0 : usage.output_tokens_by_modality;
3347
+ const byModality = usage?.output_tokens_by_modality;
3314
3348
  if (byModality == null) {
3315
3349
  return void 0;
3316
3350
  }
3317
3351
  const result = {};
3318
3352
  for (const entry of byModality) {
3319
- if ((entry == null ? void 0 : entry.modality) != null && entry.tokens != null) {
3353
+ if (entry?.modality != null && entry.tokens != null) {
3320
3354
  result[entry.modality] = entry.tokens;
3321
3355
  }
3322
3356
  }
@@ -3348,7 +3382,6 @@ function annotationToSource({
3348
3382
  annotation,
3349
3383
  generateId: generateId2
3350
3384
  }) {
3351
- var _a, _b, _c, _d, _e;
3352
3385
  switch (annotation.type) {
3353
3386
  case "url_citation": {
3354
3387
  const urlCitation = annotation;
@@ -3365,7 +3398,7 @@ function annotationToSource({
3365
3398
  }
3366
3399
  case "file_citation": {
3367
3400
  const fileCitation = annotation;
3368
- const uri = (_b = (_a = fileCitation.url) != null ? _a : fileCitation.document_uri) != null ? _b : fileCitation.file_name;
3401
+ const uri = fileCitation.url ?? fileCitation.document_uri ?? fileCitation.file_name;
3369
3402
  if (uri == null || uri.length === 0) return void 0;
3370
3403
  if (uri.startsWith("http://") || uri.startsWith("https://")) {
3371
3404
  return {
@@ -3376,14 +3409,14 @@ function annotationToSource({
3376
3409
  ...fileCitation.file_name != null ? { title: fileCitation.file_name } : {}
3377
3410
  };
3378
3411
  }
3379
- const filename = (_c = fileCitation.file_name) != null ? _c : basename(uri);
3412
+ const filename = fileCitation.file_name ?? basename(uri);
3380
3413
  const mediaType = inferDocMediaType(uri);
3381
3414
  return {
3382
3415
  type: "source",
3383
3416
  sourceType: "document",
3384
3417
  id: generateId2(),
3385
3418
  mediaType,
3386
- title: (_e = (_d = fileCitation.file_name) != null ? _d : filename) != null ? _e : uri,
3419
+ title: fileCitation.file_name ?? filename ?? uri,
3387
3420
  ...filename != null ? { filename } : {}
3388
3421
  };
3389
3422
  }
@@ -3408,13 +3441,12 @@ function builtinToolResultToSources({
3408
3441
  block,
3409
3442
  generateId: generateId2
3410
3443
  }) {
3411
- var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k;
3412
3444
  const sources = [];
3413
3445
  switch (block.type) {
3414
3446
  case "url_context_result": {
3415
- const result = (_a = block.result) != null ? _a : [];
3447
+ const result = block.result ?? [];
3416
3448
  for (const entry of result) {
3417
- if ((entry == null ? void 0 : entry.url) == null || entry.url.length === 0) continue;
3449
+ if (entry?.url == null || entry.url.length === 0) continue;
3418
3450
  if (entry.status != null && entry.status !== "success") continue;
3419
3451
  sources.push({
3420
3452
  type: "source",
@@ -3426,9 +3458,9 @@ function builtinToolResultToSources({
3426
3458
  break;
3427
3459
  }
3428
3460
  case "google_search_result": {
3429
- const result = (_b = block.result) != null ? _b : [];
3461
+ const result = block.result ?? [];
3430
3462
  for (const entry of result) {
3431
- const url = entry == null ? void 0 : entry.url;
3463
+ const url = entry?.url;
3432
3464
  if (url == null || url.length === 0) continue;
3433
3465
  sources.push({
3434
3466
  type: "source",
@@ -3441,9 +3473,9 @@ function builtinToolResultToSources({
3441
3473
  break;
3442
3474
  }
3443
3475
  case "google_maps_result": {
3444
- const result = (_c = block.result) != null ? _c : [];
3476
+ const result = block.result ?? [];
3445
3477
  for (const entry of result) {
3446
- for (const place of (_d = entry.places) != null ? _d : []) {
3478
+ for (const place of entry.places ?? []) {
3447
3479
  if (place.url == null || place.url.length === 0) continue;
3448
3480
  sources.push({
3449
3481
  type: "source",
@@ -3457,11 +3489,11 @@ function builtinToolResultToSources({
3457
3489
  break;
3458
3490
  }
3459
3491
  case "file_search_result": {
3460
- const result = (_e = block.result) != null ? _e : [];
3492
+ const result = block.result ?? [];
3461
3493
  for (const raw of result) {
3462
3494
  if (raw == null || typeof raw !== "object") continue;
3463
3495
  const entry = raw;
3464
- const uri = (_g = (_f = entry.url) != null ? _f : entry.document_uri) != null ? _g : entry.file_name;
3496
+ const uri = entry.url ?? entry.document_uri ?? entry.file_name;
3465
3497
  if (uri == null || uri.length === 0) continue;
3466
3498
  if (uri.startsWith("http://") || uri.startsWith("https://")) {
3467
3499
  sources.push({
@@ -3473,14 +3505,14 @@ function builtinToolResultToSources({
3473
3505
  });
3474
3506
  continue;
3475
3507
  }
3476
- const filename = (_h = entry.file_name) != null ? _h : basename(uri);
3508
+ const filename = entry.file_name ?? basename(uri);
3477
3509
  const mediaType = inferDocMediaType(uri);
3478
3510
  sources.push({
3479
3511
  type: "source",
3480
3512
  sourceType: "document",
3481
3513
  id: generateId2(),
3482
3514
  mediaType,
3483
- title: (_k = (_j = (_i = entry.title) != null ? _i : entry.file_name) != null ? _j : filename) != null ? _k : uri,
3515
+ title: entry.title ?? entry.file_name ?? filename ?? uri,
3484
3516
  ...filename != null ? { filename } : {}
3485
3517
  });
3486
3518
  }
@@ -3495,14 +3527,13 @@ function annotationsToSources({
3495
3527
  annotations,
3496
3528
  generateId: generateId2
3497
3529
  }) {
3498
- var _a;
3499
3530
  if (annotations == null) return [];
3500
3531
  const seen = /* @__PURE__ */ new Set();
3501
3532
  const sources = [];
3502
3533
  for (const annotation of annotations) {
3503
3534
  const source = annotationToSource({ annotation, generateId: generateId2 });
3504
3535
  if (source == null) continue;
3505
- const key = source.sourceType === "url" ? `url:${source.url}` : `doc:${(_a = source.filename) != null ? _a : source.title}`;
3536
+ const key = source.sourceType === "url" ? `url:${source.url}` : `doc:${source.filename ?? source.title}`;
3506
3537
  if (seen.has(key)) continue;
3507
3538
  seen.add(key);
3508
3539
  sources.push(source);
@@ -3569,15 +3600,13 @@ function buildGoogleInteractionsStreamTransform({
3569
3600
  const openBlocks = /* @__PURE__ */ new Map();
3570
3601
  const emittedSourceKeys = /* @__PURE__ */ new Set();
3571
3602
  function sourceKey(source) {
3572
- var _a;
3573
- return source.sourceType === "url" ? `url:${source.url}` : `doc:${(_a = source.filename) != null ? _a : source.title}`;
3603
+ return source.sourceType === "url" ? `url:${source.url}` : `doc:${source.filename ?? source.title}`;
3574
3604
  }
3575
3605
  return new TransformStream({
3576
3606
  start(controller) {
3577
3607
  controller.enqueue({ type: "stream-start", warnings });
3578
3608
  },
3579
3609
  transform(chunk, controller) {
3580
- var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o, _p, _q, _r, _s, _t;
3581
3610
  if (includeRawChunks) {
3582
3611
  controller.enqueue({ type: "raw", rawValue: chunk.rawValue });
3583
3612
  }
@@ -3592,8 +3621,8 @@ function buildGoogleInteractionsStreamTransform({
3592
3621
  case "interaction.created": {
3593
3622
  const event = value;
3594
3623
  const interaction = event.interaction;
3595
- interactionId = (interaction == null ? void 0 : interaction.id) != null && interaction.id.length > 0 ? interaction.id : void 0;
3596
- const created = interaction == null ? void 0 : interaction.created;
3624
+ interactionId = interaction?.id != null && interaction.id.length > 0 ? interaction.id : void 0;
3625
+ const created = interaction?.created;
3597
3626
  let timestamp;
3598
3627
  if (typeof created === "string") {
3599
3628
  const parsed = new Date(created);
@@ -3604,7 +3633,7 @@ function buildGoogleInteractionsStreamTransform({
3604
3633
  controller.enqueue({
3605
3634
  type: "response-metadata",
3606
3635
  ...interactionId != null ? { id: interactionId } : {},
3607
- modelId: interaction == null ? void 0 : interaction.model,
3636
+ modelId: interaction?.model,
3608
3637
  ...timestamp ? { timestamp } : {}
3609
3638
  });
3610
3639
  break;
@@ -3613,11 +3642,11 @@ function buildGoogleInteractionsStreamTransform({
3613
3642
  const event = value;
3614
3643
  const step = event.step;
3615
3644
  const index = event.index;
3616
- const blockId = `${interactionId != null ? interactionId : "interaction"}:${index}`;
3617
- const stepType = step == null ? void 0 : step.type;
3645
+ const blockId = `${interactionId ?? "interaction"}:${index}`;
3646
+ const stepType = step?.type;
3618
3647
  if (stepType === "model_output") {
3619
- const initial = (_a = step == null ? void 0 : step.content) == null ? void 0 : _a[0];
3620
- if ((initial == null ? void 0 : initial.type) === "text") {
3648
+ const initial = step?.content?.[0];
3649
+ if (initial?.type === "text") {
3621
3650
  openBlocks.set(index, {
3622
3651
  kind: "text",
3623
3652
  id: blockId,
@@ -3634,7 +3663,7 @@ function buildGoogleInteractionsStreamTransform({
3634
3663
  emittedSourceKeys.add(key);
3635
3664
  controller.enqueue(source);
3636
3665
  }
3637
- } else if ((initial == null ? void 0 : initial.type) === "image") {
3666
+ } else if (initial?.type === "image") {
3638
3667
  openBlocks.set(index, {
3639
3668
  kind: "image",
3640
3669
  id: blockId,
@@ -3649,16 +3678,16 @@ function buildGoogleInteractionsStreamTransform({
3649
3678
  });
3650
3679
  }
3651
3680
  } else if (stepType === "thought") {
3652
- const signature = step == null ? void 0 : step.signature;
3681
+ const signature = step?.signature;
3653
3682
  openBlocks.set(index, {
3654
3683
  kind: "reasoning",
3655
3684
  id: blockId,
3656
3685
  ...signature != null ? { signature } : {}
3657
3686
  });
3658
3687
  controller.enqueue({ type: "reasoning-start", id: blockId });
3659
- if (Array.isArray(step == null ? void 0 : step.summary)) {
3688
+ if (Array.isArray(step?.summary)) {
3660
3689
  for (const item of step.summary) {
3661
- if ((item == null ? void 0 : item.type) === "text" && typeof item.text === "string") {
3690
+ if (item?.type === "text" && typeof item.text === "string") {
3662
3691
  controller.enqueue({
3663
3692
  type: "reasoning-delta",
3664
3693
  id: blockId,
@@ -3669,12 +3698,12 @@ function buildGoogleInteractionsStreamTransform({
3669
3698
  }
3670
3699
  } else if (stepType === "processing_call" || stepType === "processing_result") {
3671
3700
  const google = {};
3672
- if ((step == null ? void 0 : step.signature) != null) google.signature = step.signature;
3701
+ if (step?.signature != null) google.signature = step.signature;
3673
3702
  if (interactionId != null) google.interactionId = interactionId;
3674
3703
  if (stepType === "processing_call") {
3675
- google.processingId = (step == null ? void 0 : step.id) || blockId;
3704
+ google.processingId = step?.id || blockId;
3676
3705
  } else {
3677
- google.processingCallId = (step == null ? void 0 : step.call_id) || blockId;
3706
+ google.processingCallId = step?.call_id || blockId;
3678
3707
  }
3679
3708
  openBlocks.set(index, {
3680
3709
  kind: "custom",
@@ -3683,8 +3712,8 @@ function buildGoogleInteractionsStreamTransform({
3683
3712
  google
3684
3713
  });
3685
3714
  } else if (stepType === "function_call") {
3686
- const toolCallId = (step == null ? void 0 : step.id) || blockId;
3687
- const toolName = (_b = step == null ? void 0 : step.name) != null ? _b : "unknown";
3715
+ const toolCallId = step?.id || blockId;
3716
+ const toolName = step?.name ?? "unknown";
3688
3717
  hasFunctionCall = true;
3689
3718
  const state = {
3690
3719
  kind: "function_call",
@@ -3692,7 +3721,7 @@ function buildGoogleInteractionsStreamTransform({
3692
3721
  toolCallId,
3693
3722
  toolName,
3694
3723
  argumentsAccum: "",
3695
- ...(step == null ? void 0 : step.signature) != null ? { signature: step.signature } : {}
3724
+ ...step?.signature != null ? { signature: step.signature } : {}
3696
3725
  };
3697
3726
  openBlocks.set(index, state);
3698
3727
  controller.enqueue({
@@ -3701,29 +3730,29 @@ function buildGoogleInteractionsStreamTransform({
3701
3730
  toolName
3702
3731
  });
3703
3732
  } else if (stepType != null && BUILTIN_TOOL_CALL_TYPES.has(stepType)) {
3704
- const toolName = stepType === "mcp_server_tool_call" ? (_c = step == null ? void 0 : step.name) != null ? _c : "mcp_server_tool" : builtinToolNameFromCallType(stepType);
3705
- const toolCallId = (step == null ? void 0 : step.id) || blockId;
3733
+ const toolName = stepType === "mcp_server_tool_call" ? step?.name ?? "mcp_server_tool" : builtinToolNameFromCallType(stepType);
3734
+ const toolCallId = step?.id || blockId;
3706
3735
  const state = {
3707
3736
  kind: "builtin_tool_call",
3708
3737
  id: blockId,
3709
3738
  blockType: stepType,
3710
3739
  toolCallId,
3711
3740
  toolName,
3712
- arguments: (_d = step == null ? void 0 : step.arguments) != null ? _d : {},
3741
+ arguments: step?.arguments ?? {},
3713
3742
  callEmitted: false
3714
3743
  };
3715
3744
  openBlocks.set(index, state);
3716
3745
  } else if (stepType != null && BUILTIN_TOOL_RESULT_TYPES.has(stepType)) {
3717
- const toolName = stepType === "mcp_server_tool_result" ? (_e = step == null ? void 0 : step.name) != null ? _e : "mcp_server_tool" : builtinToolNameFromResultType(stepType);
3718
- const callId = (step == null ? void 0 : step.call_id) || blockId;
3746
+ const toolName = stepType === "mcp_server_tool_result" ? step?.name ?? "mcp_server_tool" : builtinToolNameFromResultType(stepType);
3747
+ const callId = step?.call_id || blockId;
3719
3748
  const state = {
3720
3749
  kind: "builtin_tool_result",
3721
3750
  id: blockId,
3722
3751
  blockType: stepType,
3723
3752
  callId,
3724
3753
  toolName,
3725
- result: (_f = step == null ? void 0 : step.result) != null ? _f : null,
3726
- ...(step == null ? void 0 : step.is_error) != null ? { isError: step.is_error } : {},
3754
+ result: step?.result ?? null,
3755
+ ...step?.is_error != null ? { isError: step.is_error } : {},
3727
3756
  resultEmitted: false
3728
3757
  };
3729
3758
  openBlocks.set(index, state);
@@ -3736,7 +3765,7 @@ function buildGoogleInteractionsStreamTransform({
3736
3765
  const event = value;
3737
3766
  let open = openBlocks.get(event.index);
3738
3767
  if (open == null) break;
3739
- const dtype = (_g = event.delta) == null ? void 0 : _g.type;
3768
+ const dtype = event.delta?.type;
3740
3769
  if (open.kind === "pending_model_output") {
3741
3770
  if (dtype === "text" || dtype === "text_annotation" || dtype === "text_annotation_delta") {
3742
3771
  const promoted = {
@@ -3754,17 +3783,17 @@ function buildGoogleInteractionsStreamTransform({
3754
3783
  const google = {};
3755
3784
  if (interactionId != null) google.interactionId = interactionId;
3756
3785
  const providerMetadata = Object.keys(google).length > 0 ? { google } : void 0;
3757
- if ((imageDelta == null ? void 0 : imageDelta.data) != null && imageDelta.data.length > 0) {
3786
+ if (imageDelta?.data != null && imageDelta.data.length > 0) {
3758
3787
  controller.enqueue({
3759
3788
  type: "file",
3760
- mediaType: (_h = imageDelta.mime_type) != null ? _h : "image/png",
3789
+ mediaType: imageDelta.mime_type ?? "image/png",
3761
3790
  data: { type: "data", data: imageDelta.data },
3762
3791
  ...providerMetadata ? { providerMetadata } : {}
3763
3792
  });
3764
- } else if ((imageDelta == null ? void 0 : imageDelta.uri) != null && imageDelta.uri.length > 0) {
3793
+ } else if (imageDelta?.uri != null && imageDelta.uri.length > 0) {
3765
3794
  controller.enqueue({
3766
3795
  type: "file",
3767
- mediaType: (_i = imageDelta.mime_type) != null ? _i : "image/png",
3796
+ mediaType: imageDelta.mime_type ?? "image/png",
3768
3797
  data: { type: "url", url: new URL(imageDelta.uri) },
3769
3798
  ...providerMetadata ? { providerMetadata } : {}
3770
3799
  });
@@ -3780,17 +3809,17 @@ function buildGoogleInteractionsStreamTransform({
3780
3809
  const google = {};
3781
3810
  if (interactionId != null) google.interactionId = interactionId;
3782
3811
  const providerMetadata = Object.keys(google).length > 0 ? { google } : void 0;
3783
- if ((videoDelta == null ? void 0 : videoDelta.data) != null && videoDelta.data.length > 0) {
3812
+ if (videoDelta?.data != null && videoDelta.data.length > 0) {
3784
3813
  controller.enqueue({
3785
3814
  type: "file",
3786
- mediaType: (_j = videoDelta.mime_type) != null ? _j : "video/mp4",
3815
+ mediaType: videoDelta.mime_type ?? "video/mp4",
3787
3816
  data: { type: "data", data: videoDelta.data },
3788
3817
  ...providerMetadata ? { providerMetadata } : {}
3789
3818
  });
3790
- } else if ((videoDelta == null ? void 0 : videoDelta.uri) != null && videoDelta.uri.length > 0) {
3819
+ } else if (videoDelta?.uri != null && videoDelta.uri.length > 0) {
3791
3820
  controller.enqueue({
3792
3821
  type: "file",
3793
- mediaType: (_k = videoDelta.mime_type) != null ? _k : "video/mp4",
3822
+ mediaType: videoDelta.mime_type ?? "video/mp4",
3794
3823
  data: { type: "url", url: new URL(videoDelta.uri) },
3795
3824
  ...providerMetadata ? { providerMetadata } : {}
3796
3825
  });
@@ -3798,7 +3827,7 @@ function buildGoogleInteractionsStreamTransform({
3798
3827
  break;
3799
3828
  }
3800
3829
  const delta = event.delta;
3801
- if (open.kind === "custom" && ((delta == null ? void 0 : delta.type) === "processing_call" || (delta == null ? void 0 : delta.type) === "processing_result")) {
3830
+ if (open.kind === "custom" && (delta?.type === "processing_call" || delta?.type === "processing_result")) {
3802
3831
  if (delta.signature != null)
3803
3832
  open.google.signature = delta.signature;
3804
3833
  if (delta.type === "processing_call" && delta.id != null && delta.id.length > 0) {
@@ -3807,8 +3836,8 @@ function buildGoogleInteractionsStreamTransform({
3807
3836
  if (delta.type === "processing_result" && delta.call_id != null && delta.call_id.length > 0) {
3808
3837
  open.google.processingCallId = delta.call_id;
3809
3838
  }
3810
- } else if (open.kind === "text" && (delta == null ? void 0 : delta.type) === "text") {
3811
- const text = (_l = delta.text) != null ? _l : "";
3839
+ } else if (open.kind === "text" && delta?.type === "text") {
3840
+ const text = delta.text ?? "";
3812
3841
  if (text.length > 0) {
3813
3842
  controller.enqueue({
3814
3843
  type: "text-delta",
@@ -3816,7 +3845,7 @@ function buildGoogleInteractionsStreamTransform({
3816
3845
  delta: text
3817
3846
  });
3818
3847
  }
3819
- } else if (open.kind === "text" && ((delta == null ? void 0 : delta.type) === "text_annotation" || (delta == null ? void 0 : delta.type) === "text_annotation_delta")) {
3848
+ } else if (open.kind === "text" && (delta?.type === "text_annotation" || delta?.type === "text_annotation_delta")) {
3820
3849
  const sources = annotationsToSources({
3821
3850
  annotations: delta.annotations,
3822
3851
  generateId: generateId2
@@ -3828,27 +3857,27 @@ function buildGoogleInteractionsStreamTransform({
3828
3857
  open.emittedSourceKeys.add(key);
3829
3858
  controller.enqueue(source);
3830
3859
  }
3831
- } else if (open.kind === "image" && (delta == null ? void 0 : delta.type) === "image") {
3860
+ } else if (open.kind === "image" && delta?.type === "image") {
3832
3861
  if (delta.data != null) open.data = delta.data;
3833
3862
  if (delta.mime_type != null) open.mimeType = delta.mime_type;
3834
3863
  if (delta.uri != null) open.uri = delta.uri;
3835
3864
  } else if (open.kind === "reasoning") {
3836
- if ((delta == null ? void 0 : delta.type) === "thought_summary") {
3865
+ if (delta?.type === "thought_summary") {
3837
3866
  const item = delta.content;
3838
- if ((item == null ? void 0 : item.type) === "text" && typeof item.text === "string") {
3867
+ if (item?.type === "text" && typeof item.text === "string") {
3839
3868
  controller.enqueue({
3840
3869
  type: "reasoning-delta",
3841
3870
  id: open.id,
3842
3871
  delta: item.text
3843
3872
  });
3844
3873
  }
3845
- } else if ((delta == null ? void 0 : delta.type) === "thought_signature") {
3874
+ } else if (delta?.type === "thought_signature") {
3846
3875
  const signature = delta.signature;
3847
3876
  if (signature != null) {
3848
3877
  open.signature = signature;
3849
3878
  }
3850
3879
  }
3851
- } else if (open.kind === "function_call" && (delta == null ? void 0 : delta.type) === "arguments_delta") {
3880
+ } else if (open.kind === "function_call" && delta?.type === "arguments_delta") {
3852
3881
  const slice = typeof delta.arguments === "string" ? delta.arguments : "";
3853
3882
  if (slice.length > 0) {
3854
3883
  open.argumentsAccum += slice;
@@ -3865,7 +3894,7 @@ function buildGoogleInteractionsStreamTransform({
3865
3894
  open.signature = delta.signature;
3866
3895
  }
3867
3896
  hasFunctionCall = true;
3868
- } else if (open.kind === "builtin_tool_call" && (delta == null ? void 0 : delta.type) === open.blockType) {
3897
+ } else if (open.kind === "builtin_tool_call" && delta?.type === open.blockType) {
3869
3898
  if (delta.id != null && delta.id.length > 0) {
3870
3899
  open.toolCallId = delta.id;
3871
3900
  }
@@ -3875,7 +3904,7 @@ function buildGoogleInteractionsStreamTransform({
3875
3904
  if (delta.name != null && open.blockType === "mcp_server_tool_call") {
3876
3905
  open.toolName = delta.name;
3877
3906
  }
3878
- } else if (open.kind === "builtin_tool_result" && (delta == null ? void 0 : delta.type) === open.blockType) {
3907
+ } else if (open.kind === "builtin_tool_result" && delta?.type === open.blockType) {
3879
3908
  if (delta.call_id != null && delta.call_id.length > 0) {
3880
3909
  open.callId = delta.call_id;
3881
3910
  }
@@ -3915,14 +3944,14 @@ function buildGoogleInteractionsStreamTransform({
3915
3944
  if (open.data != null && open.data.length > 0) {
3916
3945
  controller.enqueue({
3917
3946
  type: "file",
3918
- mediaType: (_m = open.mimeType) != null ? _m : "image/png",
3947
+ mediaType: open.mimeType ?? "image/png",
3919
3948
  data: { type: "data", data: open.data },
3920
3949
  ...providerMetadata ? { providerMetadata } : {}
3921
3950
  });
3922
3951
  } else if (open.uri != null && open.uri.length > 0) {
3923
3952
  controller.enqueue({
3924
3953
  type: "file",
3925
- mediaType: (_n = open.mimeType) != null ? _n : "image/png",
3954
+ mediaType: open.mimeType ?? "image/png",
3926
3955
  data: { type: "url", url: new URL(open.uri) },
3927
3956
  ...providerMetadata ? { providerMetadata } : {}
3928
3957
  });
@@ -3955,7 +3984,7 @@ function buildGoogleInteractionsStreamTransform({
3955
3984
  type: "tool-call",
3956
3985
  toolCallId: open.toolCallId,
3957
3986
  toolName: open.toolName,
3958
- input: JSON.stringify((_o = open.arguments) != null ? _o : {}),
3987
+ input: JSON.stringify(open.arguments ?? {}),
3959
3988
  providerExecuted: true
3960
3989
  });
3961
3990
  open.callEmitted = true;
@@ -3964,7 +3993,7 @@ function buildGoogleInteractionsStreamTransform({
3964
3993
  type: "tool-result",
3965
3994
  toolCallId: open.callId,
3966
3995
  toolName: open.toolName,
3967
- result: (_p = open.result) != null ? _p : null
3996
+ result: open.result ?? null
3968
3997
  });
3969
3998
  open.resultEmitted = true;
3970
3999
  const sources = builtinToolResultToSources({
@@ -4001,16 +4030,16 @@ function buildGoogleInteractionsStreamTransform({
4001
4030
  case "interaction.completed": {
4002
4031
  const event = value;
4003
4032
  const interaction = event.interaction;
4004
- if ((interaction == null ? void 0 : interaction.id) != null && interaction.id.length > 0) {
4033
+ if (interaction?.id != null && interaction.id.length > 0) {
4005
4034
  interactionId = interaction.id;
4006
4035
  }
4007
- if ((interaction == null ? void 0 : interaction.status) != null) {
4036
+ if (interaction?.status != null) {
4008
4037
  finishStatus = interaction.status;
4009
4038
  }
4010
- if ((interaction == null ? void 0 : interaction.usage) != null) {
4039
+ if (interaction?.usage != null) {
4011
4040
  usage = interaction.usage;
4012
4041
  }
4013
- if ((interaction == null ? void 0 : interaction.service_tier) != null) {
4042
+ if (interaction?.service_tier != null) {
4014
4043
  serviceTier = interaction.service_tier;
4015
4044
  }
4016
4045
  break;
@@ -4021,9 +4050,9 @@ function buildGoogleInteractionsStreamTransform({
4021
4050
  controller.enqueue({
4022
4051
  type: "error",
4023
4052
  error: createProviderStreamError({
4024
- message: (_r = (_q = event.error) == null ? void 0 : _q.message) != null ? _r : "Unknown interaction error",
4053
+ message: event.error?.message ?? "Unknown interaction error",
4025
4054
  type: event.event_type,
4026
- code: (_t = (_s = event.error) == null ? void 0 : _s.code) != null ? _t : void 0,
4055
+ code: event.error?.code ?? void 0,
4027
4056
  data: event
4028
4057
  })
4029
4058
  });
@@ -4074,7 +4103,6 @@ function convertToGoogleInteractionsInput({
4074
4103
  store,
4075
4104
  mediaResolution
4076
4105
  }) {
4077
- var _a, _b, _c, _d, _e, _f, _g, _h;
4078
4106
  const warnings = [];
4079
4107
  const incoherentCombo = previousInteractionId != null && store === false;
4080
4108
  const shouldCompact = previousInteractionId != null && store !== false;
@@ -4131,7 +4159,7 @@ function convertToGoogleInteractionsInput({
4131
4159
  pendingModelOutput.push({ type: "text", text: part.text });
4132
4160
  } else if (part.type === "reasoning") {
4133
4161
  flushModelOutput();
4134
- const signature = (_b = (_a = part.providerOptions) == null ? void 0 : _a.google) == null ? void 0 : _b.signature;
4162
+ const signature = part.providerOptions?.google?.signature;
4135
4163
  steps.push({
4136
4164
  type: "thought",
4137
4165
  ...signature != null ? { signature } : {},
@@ -4148,15 +4176,15 @@ function convertToGoogleInteractionsInput({
4148
4176
  }
4149
4177
  } else if (part.type === "custom") {
4150
4178
  flushModelOutput();
4151
- const google = (_c = part.providerOptions) == null ? void 0 : _c.google;
4152
- const signature = typeof (google == null ? void 0 : google.signature) === "string" ? google.signature : void 0;
4153
- if (part.kind === "google.processing_call" && typeof (google == null ? void 0 : google.processingId) === "string") {
4179
+ const google = part.providerOptions?.google;
4180
+ const signature = typeof google?.signature === "string" ? google.signature : void 0;
4181
+ if (part.kind === "google.processing_call" && typeof google?.processingId === "string") {
4154
4182
  steps.push({
4155
4183
  type: "processing_call",
4156
4184
  id: google.processingId,
4157
4185
  ...signature != null ? { signature } : {}
4158
4186
  });
4159
- } else if (part.kind === "google.processing_result" && typeof (google == null ? void 0 : google.processingCallId) === "string") {
4187
+ } else if (part.kind === "google.processing_result" && typeof google?.processingCallId === "string") {
4160
4188
  steps.push({
4161
4189
  type: "processing_result",
4162
4190
  call_id: google.processingCallId,
@@ -4170,8 +4198,8 @@ function convertToGoogleInteractionsInput({
4170
4198
  }
4171
4199
  } else if (part.type === "tool-call") {
4172
4200
  flushModelOutput();
4173
- const signature = (_e = (_d = part.providerOptions) == null ? void 0 : _d.google) == null ? void 0 : _e.signature;
4174
- const args = typeof part.input === "string" ? safeParseToolArgs(part.input) : (_f = part.input) != null ? _f : {};
4201
+ const signature = part.providerOptions?.google?.signature;
4202
+ const args = typeof part.input === "string" ? safeParseToolArgs(part.input) : part.input ?? {};
4175
4203
  steps.push({
4176
4204
  type: "function_call",
4177
4205
  id: part.toolCallId,
@@ -4203,7 +4231,7 @@ function convertToGoogleInteractionsInput({
4203
4231
  toolCallId: part.toolCallId,
4204
4232
  toolName: part.toolName,
4205
4233
  output: part.output,
4206
- signature: (_h = (_g = part.providerOptions) == null ? void 0 : _g.google) == null ? void 0 : _h.signature,
4234
+ signature: part.providerOptions?.google?.signature,
4207
4235
  warnings
4208
4236
  });
4209
4237
  content.push(block);
@@ -4296,8 +4324,7 @@ function getVideoProcessingField({
4296
4324
  part,
4297
4325
  warnings
4298
4326
  }) {
4299
- var _a, _b;
4300
- const processing = (_b = (_a = part.providerOptions) == null ? void 0 : _a.google) == null ? void 0 : _b.processing;
4327
+ const processing = part.providerOptions?.google?.processing;
4301
4328
  if (processing == null) {
4302
4329
  return {};
4303
4330
  }
@@ -4309,8 +4336,8 @@ function getVideoProcessingField({
4309
4336
  return {
4310
4337
  processing: {
4311
4338
  type: "static",
4312
- ...typeof config.startOffset === "number" ? { start_offset: config.startOffset } : {},
4313
- ...typeof config.endOffset === "number" ? { end_offset: config.endOffset } : {},
4339
+ ...typeof config.startOffset === "number" ? { start_offset: `${config.startOffset}s` } : {},
4340
+ ...typeof config.endOffset === "number" ? { end_offset: `${config.endOffset}s` } : {},
4314
4341
  ...typeof config.fps === "number" ? { fps: config.fps } : {}
4315
4342
  }
4316
4343
  };
@@ -4330,8 +4357,7 @@ function compactPromptForPreviousInteraction({
4330
4357
  for (const message of prompt) {
4331
4358
  if (message.role === "assistant") {
4332
4359
  const matchesLinkedInteraction = message.content.some((part) => {
4333
- var _a, _b;
4334
- const partInteractionId = (_b = (_a = part.providerOptions) == null ? void 0 : _a.google) == null ? void 0 : _b.interactionId;
4360
+ const partInteractionId = part.providerOptions?.google?.interactionId;
4335
4361
  return partInteractionId === previousInteractionId;
4336
4362
  });
4337
4363
  if (matchesLinkedInteraction) {
@@ -4372,7 +4398,7 @@ function safeParseToolArgs(input) {
4372
4398
  return parsed;
4373
4399
  }
4374
4400
  return { value: parsed };
4375
- } catch (e) {
4401
+ } catch {
4376
4402
  return { value: input };
4377
4403
  }
4378
4404
  }
@@ -4383,7 +4409,6 @@ function convertToolResultPart({
4383
4409
  signature,
4384
4410
  warnings
4385
4411
  }) {
4386
- var _a;
4387
4412
  const base = {
4388
4413
  type: "function_result",
4389
4414
  call_id: toolCallId,
@@ -4403,7 +4428,7 @@ function convertToolResultPart({
4403
4428
  return {
4404
4429
  ...base,
4405
4430
  is_error: true,
4406
- result: (_a = output.reason) != null ? _a : "Tool execution denied by user."
4431
+ result: output.reason ?? "Tool execution denied by user."
4407
4432
  };
4408
4433
  case "content": {
4409
4434
  const blocks = [];
@@ -5094,7 +5119,6 @@ function parseGoogleInteractionsOutputs({
5094
5119
  generateId: generateId2,
5095
5120
  interactionId
5096
5121
  }) {
5097
- var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k;
5098
5122
  const content = [];
5099
5123
  let hasFunctionCall = false;
5100
5124
  if (steps == null) {
@@ -5109,12 +5133,12 @@ function parseGoogleInteractionsOutputs({
5109
5133
  break;
5110
5134
  }
5111
5135
  case "model_output": {
5112
- const blocks = (_a = step.content) != null ? _a : [];
5136
+ const blocks = step.content ?? [];
5113
5137
  for (const block of blocks) {
5114
5138
  if (block == null || typeof block !== "object") continue;
5115
5139
  const blockType = block.type;
5116
5140
  if (blockType === "text") {
5117
- const text = (_b = block.text) != null ? _b : "";
5141
+ const text = block.text ?? "";
5118
5142
  const annotations = block.annotations;
5119
5143
  content.push({
5120
5144
  type: "text",
@@ -5130,14 +5154,14 @@ function parseGoogleInteractionsOutputs({
5130
5154
  if (image.data != null && image.data.length > 0) {
5131
5155
  content.push({
5132
5156
  type: "file",
5133
- mediaType: (_c = image.mime_type) != null ? _c : "image/png",
5157
+ mediaType: image.mime_type ?? "image/png",
5134
5158
  data: { type: "data", data: image.data },
5135
5159
  ...googleProviderMetadata({ interactionId })
5136
5160
  });
5137
5161
  } else if (image.uri != null && image.uri.length > 0) {
5138
5162
  content.push({
5139
5163
  type: "file",
5140
- mediaType: (_d = image.mime_type) != null ? _d : "image/png",
5164
+ mediaType: image.mime_type ?? "image/png",
5141
5165
  data: { type: "url", url: new URL(image.uri) },
5142
5166
  ...googleProviderMetadata({ interactionId })
5143
5167
  });
@@ -5147,14 +5171,14 @@ function parseGoogleInteractionsOutputs({
5147
5171
  if (video.data != null && video.data.length > 0) {
5148
5172
  content.push({
5149
5173
  type: "file",
5150
- mediaType: (_e = video.mime_type) != null ? _e : "video/mp4",
5174
+ mediaType: video.mime_type ?? "video/mp4",
5151
5175
  data: { type: "data", data: video.data },
5152
5176
  ...googleProviderMetadata({ interactionId })
5153
5177
  });
5154
5178
  } else if (video.uri != null && video.uri.length > 0) {
5155
5179
  content.push({
5156
5180
  type: "file",
5157
- mediaType: (_f = video.mime_type) != null ? _f : "video/mp4",
5181
+ mediaType: video.mime_type ?? "video/mp4",
5158
5182
  data: { type: "url", url: new URL(video.uri) },
5159
5183
  ...googleProviderMetadata({ interactionId })
5160
5184
  });
@@ -5167,7 +5191,7 @@ function parseGoogleInteractionsOutputs({
5167
5191
  const thought = step;
5168
5192
  const summary = Array.isArray(thought.summary) ? thought.summary : [];
5169
5193
  const text = summary.filter(
5170
- (item) => (item == null ? void 0 : item.type) === "text" && typeof item.text === "string"
5194
+ (item) => item?.type === "text" && typeof item.text === "string"
5171
5195
  ).map((item) => item.text).join("\n");
5172
5196
  content.push({
5173
5197
  type: "reasoning",
@@ -5214,7 +5238,7 @@ function parseGoogleInteractionsOutputs({
5214
5238
  type: "tool-call",
5215
5239
  toolCallId: call.id,
5216
5240
  toolName: call.name,
5217
- input: JSON.stringify((_g = call.arguments) != null ? _g : {}),
5241
+ input: JSON.stringify(call.arguments ?? {}),
5218
5242
  ...googleProviderMetadata({
5219
5243
  signature: call.signature,
5220
5244
  interactionId
@@ -5225,8 +5249,8 @@ function parseGoogleInteractionsOutputs({
5225
5249
  default: {
5226
5250
  if (BUILTIN_TOOL_CALL_TYPES2.has(type)) {
5227
5251
  const call = step;
5228
- const toolName = type === "mcp_server_tool_call" ? (_h = call.name) != null ? _h : "mcp_server_tool" : builtinToolNameFromCallType2(type);
5229
- const input = JSON.stringify((_i = call.arguments) != null ? _i : {});
5252
+ const toolName = type === "mcp_server_tool_call" ? call.name ?? "mcp_server_tool" : builtinToolNameFromCallType2(type);
5253
+ const input = JSON.stringify(call.arguments ?? {});
5230
5254
  content.push({
5231
5255
  type: "tool-call",
5232
5256
  toolCallId: call.id || generateId2(),
@@ -5236,12 +5260,12 @@ function parseGoogleInteractionsOutputs({
5236
5260
  });
5237
5261
  } else if (BUILTIN_TOOL_RESULT_TYPES2.has(type)) {
5238
5262
  const result = step;
5239
- const toolName = type === "mcp_server_tool_result" ? (_j = result.name) != null ? _j : "mcp_server_tool" : builtinToolNameFromResultType2(type);
5263
+ const toolName = type === "mcp_server_tool_result" ? result.name ?? "mcp_server_tool" : builtinToolNameFromResultType2(type);
5240
5264
  content.push({
5241
5265
  type: "tool-result",
5242
5266
  toolCallId: result.call_id || generateId2(),
5243
5267
  toolName,
5244
- result: (_k = result.result) != null ? _k : null
5268
+ result: result.result ?? null
5245
5269
  });
5246
5270
  const sources = builtinToolResultToSources({
5247
5271
  block: step,
@@ -5294,9 +5318,9 @@ async function cancelGoogleInteraction({
5294
5318
  });
5295
5319
  try {
5296
5320
  await response.text();
5297
- } catch (e) {
5321
+ } catch {
5298
5322
  }
5299
- } catch (e) {
5323
+ } catch {
5300
5324
  }
5301
5325
  }
5302
5326
 
@@ -5329,7 +5353,7 @@ async function pollGoogleInteractionUntilTerminal({
5329
5353
  const cancelOnServer = () => cancelGoogleInteraction({ baseURL, interactionId, headers, fetch });
5330
5354
  try {
5331
5355
  while (true) {
5332
- if (abortSignal == null ? void 0 : abortSignal.aborted) {
5356
+ if (abortSignal?.aborted) {
5333
5357
  await cancelOnServer();
5334
5358
  throw new DOMException("Polling was aborted", "AbortError");
5335
5359
  }
@@ -5372,9 +5396,8 @@ function prepareGoogleInteractionsTools({
5372
5396
  tools,
5373
5397
  toolChoice
5374
5398
  }) {
5375
- var _a, _b, _c, _d;
5376
5399
  const toolWarnings = [];
5377
- const normalized = (tools == null ? void 0 : tools.length) ? tools : void 0;
5400
+ const normalized = tools?.length ? tools : void 0;
5378
5401
  if (normalized == null) {
5379
5402
  return { tools: void 0, toolChoice: void 0, toolWarnings };
5380
5403
  }
@@ -5384,13 +5407,13 @@ function prepareGoogleInteractionsTools({
5384
5407
  interactionsTools.push({
5385
5408
  type: "function",
5386
5409
  name: tool.name,
5387
- description: (_a = tool.description) != null ? _a : "",
5410
+ description: tool.description ?? "",
5388
5411
  parameters: tool.inputSchema
5389
5412
  });
5390
5413
  continue;
5391
5414
  }
5392
5415
  if (tool.type === "provider") {
5393
- const args = (_b = tool.args) != null ? _b : {};
5416
+ const args = tool.args ?? {};
5394
5417
  switch (tool.id) {
5395
5418
  case "google.google_search": {
5396
5419
  const searchTypesArg = args.searchTypes;
@@ -5440,7 +5463,7 @@ function prepareGoogleInteractionsTools({
5440
5463
  case "google.computer_use": {
5441
5464
  interactionsTools.push({
5442
5465
  type: "computer_use",
5443
- environment: (_c = args.environment) != null ? _c : "browser",
5466
+ environment: args.environment ?? "browser",
5444
5467
  ...args.excludedPredefinedFunctions != null ? {
5445
5468
  excludedPredefinedFunctions: args.excludedPredefinedFunctions
5446
5469
  } : {}
@@ -5458,7 +5481,7 @@ function prepareGoogleInteractionsTools({
5458
5481
  break;
5459
5482
  }
5460
5483
  case "google.retrieval": {
5461
- const vertexAiSearchConfig = (_d = args.vertexAiSearchConfig) != null ? _d : void 0;
5484
+ const vertexAiSearchConfig = args.vertexAiSearchConfig ?? void 0;
5462
5485
  interactionsTools.push({
5463
5486
  type: "retrieval",
5464
5487
  ...args.retrievalTypes != null ? {
@@ -5662,7 +5685,7 @@ function streamGoogleInteractionEvents({
5662
5685
  if (abortSignal != null) {
5663
5686
  abortSignal.removeEventListener("abort", upstreamAbortHandler);
5664
5687
  }
5665
- currentReader == null ? void 0 : currentReader.cancel().catch(() => {
5688
+ currentReader?.cancel().catch(() => {
5666
5689
  });
5667
5690
  currentReader = void 0;
5668
5691
  if (effectiveSignal.aborted && !complete) {
@@ -5677,7 +5700,7 @@ function streamGoogleInteractionEvents({
5677
5700
  },
5678
5701
  cancel() {
5679
5702
  internalAbort.abort();
5680
- currentReader == null ? void 0 : currentReader.cancel().catch(() => {
5703
+ currentReader?.cancel().catch(() => {
5681
5704
  });
5682
5705
  currentReader = void 0;
5683
5706
  }
@@ -5694,7 +5717,6 @@ function synthesizeGoogleInteractionsAgentStream({
5694
5717
  }) {
5695
5718
  return new ReadableStream({
5696
5719
  start(controller) {
5697
- var _a, _b, _c;
5698
5720
  controller.enqueue({ type: "stream-start", warnings });
5699
5721
  const interactionId = typeof response.id === "string" && response.id.length > 0 ? response.id : void 0;
5700
5722
  let timestamp;
@@ -5708,19 +5730,19 @@ function synthesizeGoogleInteractionsAgentStream({
5708
5730
  controller.enqueue({
5709
5731
  type: "response-metadata",
5710
5732
  ...interactionId != null ? { id: interactionId } : {},
5711
- modelId: (_a = response.model) != null ? _a : void 0,
5733
+ modelId: response.model ?? void 0,
5712
5734
  ...timestamp ? { timestamp } : {}
5713
5735
  });
5714
5736
  if (includeRawChunks) {
5715
5737
  controller.enqueue({ type: "raw", rawValue: response });
5716
5738
  }
5717
5739
  const { content, hasFunctionCall } = parseGoogleInteractionsOutputs({
5718
- steps: (_b = response.steps) != null ? _b : null,
5740
+ steps: response.steps ?? null,
5719
5741
  generateId: generateId2,
5720
5742
  interactionId
5721
5743
  });
5722
5744
  let blockCounter = 0;
5723
- const nextBlockId = () => `${interactionId != null ? interactionId : "agent"}:${blockCounter++}`;
5745
+ const nextBlockId = () => `${interactionId ?? "agent"}:${blockCounter++}`;
5724
5746
  for (const part of content) {
5725
5747
  switch (part.type) {
5726
5748
  case "text": {
@@ -5800,7 +5822,7 @@ function synthesizeGoogleInteractionsAgentStream({
5800
5822
  break;
5801
5823
  }
5802
5824
  }
5803
- const serviceTier = (_c = response.service_tier) != null ? _c : headerServiceTier;
5825
+ const serviceTier = response.service_tier ?? headerServiceTier;
5804
5826
  const finishReason = {
5805
5827
  unified: mapGoogleInteractionsFinishReason({
5806
5828
  status: response.status,
@@ -5875,7 +5897,6 @@ var GoogleInteractionsLanguageModel = class _GoogleInteractionsLanguageModel {
5875
5897
  };
5876
5898
  }
5877
5899
  async getArgs(options) {
5878
- var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o, _p, _q, _r, _s, _t, _u, _v, _w, _x, _y, _z, _A, _B, _C, _D, _E, _F;
5879
5900
  const warnings = [];
5880
5901
  const googleOptions = await parseProviderOptions3({
5881
5902
  provider: "google",
@@ -5910,7 +5931,7 @@ var GoogleInteractionsLanguageModel = class _GoogleInteractionsLanguageModel {
5910
5931
  warnings.push(...prepared.toolWarnings);
5911
5932
  }
5912
5933
  const responseFormatEntries = [];
5913
- if (((_a = options.responseFormat) == null ? void 0 : _a.type) === "json") {
5934
+ if (options.responseFormat?.type === "json") {
5914
5935
  if (isAgent) {
5915
5936
  warnings.push({
5916
5937
  type: "other",
@@ -5925,41 +5946,41 @@ var GoogleInteractionsLanguageModel = class _GoogleInteractionsLanguageModel {
5925
5946
  responseFormatEntries.push(entry);
5926
5947
  }
5927
5948
  }
5928
- if ((googleOptions == null ? void 0 : googleOptions.responseFormat) != null) {
5949
+ if (googleOptions?.responseFormat != null) {
5929
5950
  for (const entry of googleOptions.responseFormat) {
5930
5951
  if (entry.type === "text") {
5931
5952
  responseFormatEntries.push(
5932
5953
  pruneUndefined({
5933
5954
  type: "text",
5934
- mime_type: (_b = entry.mimeType) != null ? _b : void 0,
5935
- schema: (_c = entry.schema) != null ? _c : void 0
5955
+ mime_type: entry.mimeType ?? void 0,
5956
+ schema: entry.schema ?? void 0
5936
5957
  })
5937
5958
  );
5938
5959
  } else if (entry.type === "image") {
5939
5960
  responseFormatEntries.push(
5940
5961
  pruneUndefined({
5941
5962
  type: "image",
5942
- mime_type: (_d = entry.mimeType) != null ? _d : void 0,
5943
- aspect_ratio: (_e = entry.aspectRatio) != null ? _e : void 0,
5944
- image_size: (_f = entry.imageSize) != null ? _f : void 0
5963
+ mime_type: entry.mimeType ?? void 0,
5964
+ aspect_ratio: entry.aspectRatio ?? void 0,
5965
+ image_size: entry.imageSize ?? void 0
5945
5966
  })
5946
5967
  );
5947
5968
  } else if (entry.type === "audio") {
5948
5969
  responseFormatEntries.push(
5949
5970
  pruneUndefined({
5950
5971
  type: "audio",
5951
- mime_type: (_g = entry.mimeType) != null ? _g : void 0
5972
+ mime_type: entry.mimeType ?? void 0
5952
5973
  })
5953
5974
  );
5954
5975
  } else if (entry.type === "video") {
5955
5976
  responseFormatEntries.push(
5956
5977
  pruneUndefined({
5957
5978
  type: "video",
5958
- aspect_ratio: (_h = entry.aspectRatio) != null ? _h : void 0,
5959
- resolution: (_i = entry.resolution) != null ? _i : void 0,
5960
- duration: (_j = entry.duration) != null ? _j : void 0,
5961
- delivery: (_k = entry.delivery) != null ? _k : void 0,
5962
- gcs_uri: (_l = entry.gcsUri) != null ? _l : void 0
5979
+ aspect_ratio: entry.aspectRatio ?? void 0,
5980
+ resolution: entry.resolution ?? void 0,
5981
+ duration: entry.duration ?? void 0,
5982
+ delivery: entry.delivery ?? void 0,
5983
+ gcs_uri: entry.gcsUri ?? void 0
5963
5984
  })
5964
5985
  );
5965
5986
  }
@@ -5971,13 +5992,13 @@ var GoogleInteractionsLanguageModel = class _GoogleInteractionsLanguageModel {
5971
5992
  warnings: convWarnings
5972
5993
  } = convertToGoogleInteractionsInput({
5973
5994
  prompt: options.prompt,
5974
- previousInteractionId: (_m = googleOptions == null ? void 0 : googleOptions.previousInteractionId) != null ? _m : void 0,
5975
- store: (_n = googleOptions == null ? void 0 : googleOptions.store) != null ? _n : void 0,
5976
- mediaResolution: (_o = googleOptions == null ? void 0 : googleOptions.mediaResolution) != null ? _o : void 0
5995
+ previousInteractionId: googleOptions?.previousInteractionId ?? void 0,
5996
+ store: googleOptions?.store ?? void 0,
5997
+ mediaResolution: googleOptions?.mediaResolution ?? void 0
5977
5998
  });
5978
5999
  warnings.push(...convWarnings);
5979
6000
  let systemInstruction = convertedSystemInstruction;
5980
- const optionSystemInstruction = (_p = googleOptions == null ? void 0 : googleOptions.systemInstruction) != null ? _p : void 0;
6001
+ const optionSystemInstruction = googleOptions?.systemInstruction ?? void 0;
5981
6002
  if (systemInstruction != null && optionSystemInstruction != null) {
5982
6003
  warnings.push({
5983
6004
  type: "other",
@@ -6002,12 +6023,12 @@ var GoogleInteractionsLanguageModel = class _GoogleInteractionsLanguageModel {
6002
6023
  }
6003
6024
  if (options.maxOutputTokens != null)
6004
6025
  droppedFields.push("maxOutputTokens");
6005
- if ((googleOptions == null ? void 0 : googleOptions.thinkingLevel) != null)
6026
+ if (googleOptions?.thinkingLevel != null)
6006
6027
  droppedFields.push("thinkingLevel");
6007
- if ((googleOptions == null ? void 0 : googleOptions.thinkingSummaries) != null) {
6028
+ if (googleOptions?.thinkingSummaries != null) {
6008
6029
  droppedFields.push("thinkingSummaries");
6009
6030
  }
6010
- if ((googleOptions == null ? void 0 : googleOptions.imageConfig) != null) droppedFields.push("imageConfig");
6031
+ if (googleOptions?.imageConfig != null) droppedFields.push("imageConfig");
6011
6032
  if (droppedFields.length > 0) {
6012
6033
  warnings.push({
6013
6034
  type: "other",
@@ -6017,17 +6038,17 @@ var GoogleInteractionsLanguageModel = class _GoogleInteractionsLanguageModel {
6017
6038
  generationConfig = void 0;
6018
6039
  } else {
6019
6040
  generationConfig = pruneUndefined({
6020
- temperature: (_q = options.temperature) != null ? _q : void 0,
6021
- top_p: (_r = options.topP) != null ? _r : void 0,
6022
- top_k: (_s = options.topK) != null ? _s : void 0,
6023
- seed: (_t = options.seed) != null ? _t : void 0,
6041
+ temperature: options.temperature ?? void 0,
6042
+ top_p: options.topP ?? void 0,
6043
+ top_k: options.topK ?? void 0,
6044
+ seed: options.seed ?? void 0,
6024
6045
  stop_sequences: options.stopSequences != null && options.stopSequences.length > 0 ? options.stopSequences : void 0,
6025
- max_output_tokens: (_u = options.maxOutputTokens) != null ? _u : void 0,
6026
- thinking_level: (_v = googleOptions == null ? void 0 : googleOptions.thinkingLevel) != null ? _v : void 0,
6027
- thinking_summaries: (_w = googleOptions == null ? void 0 : googleOptions.thinkingSummaries) != null ? _w : void 0,
6046
+ max_output_tokens: options.maxOutputTokens ?? void 0,
6047
+ thinking_level: googleOptions?.thinkingLevel ?? void 0,
6048
+ thinking_summaries: googleOptions?.thinkingSummaries ?? void 0,
6028
6049
  tool_choice: toolChoiceForBody
6029
6050
  });
6030
- if ((googleOptions == null ? void 0 : googleOptions.imageConfig) != null) {
6051
+ if (googleOptions?.imageConfig != null) {
6031
6052
  const alreadyHasImageEntry = responseFormatEntries.some(
6032
6053
  (entry) => entry.type === "image"
6033
6054
  );
@@ -6046,21 +6067,21 @@ var GoogleInteractionsLanguageModel = class _GoogleInteractionsLanguageModel {
6046
6067
  }
6047
6068
  }
6048
6069
  let agentConfig;
6049
- if (isAgent && (googleOptions == null ? void 0 : googleOptions.agentConfig) != null) {
6070
+ if (isAgent && googleOptions?.agentConfig != null) {
6050
6071
  const agentConfigOptions = googleOptions.agentConfig;
6051
6072
  if (agentConfigOptions.type === "deep-research") {
6052
6073
  agentConfig = pruneUndefined({
6053
6074
  type: "deep-research",
6054
- thinking_summaries: (_x = agentConfigOptions.thinkingSummaries) != null ? _x : void 0,
6055
- visualization: (_y = agentConfigOptions.visualization) != null ? _y : void 0,
6056
- collaborative_planning: (_z = agentConfigOptions.collaborativePlanning) != null ? _z : void 0
6075
+ thinking_summaries: agentConfigOptions.thinkingSummaries ?? void 0,
6076
+ visualization: agentConfigOptions.visualization ?? void 0,
6077
+ collaborative_planning: agentConfigOptions.collaborativePlanning ?? void 0
6057
6078
  });
6058
6079
  } else if (agentConfigOptions.type === "dynamic") {
6059
6080
  agentConfig = { type: "dynamic" };
6060
6081
  }
6061
6082
  }
6062
6083
  let environment;
6063
- if ((googleOptions == null ? void 0 : googleOptions.environment) != null) {
6084
+ if (googleOptions?.environment != null) {
6064
6085
  if (!isAgent) {
6065
6086
  warnings.push({
6066
6087
  type: "other",
@@ -6070,8 +6091,7 @@ var GoogleInteractionsLanguageModel = class _GoogleInteractionsLanguageModel {
6070
6091
  environment = googleOptions.environment;
6071
6092
  } else {
6072
6093
  const environmentOptions = googleOptions.environment;
6073
- const sources = (_A = environmentOptions.sources) == null ? void 0 : _A.map((source) => {
6074
- var _a2;
6094
+ const sources = environmentOptions.sources?.map((source) => {
6075
6095
  if (source.type === "inline") {
6076
6096
  return {
6077
6097
  type: "inline",
@@ -6082,7 +6102,7 @@ var GoogleInteractionsLanguageModel = class _GoogleInteractionsLanguageModel {
6082
6102
  return pruneUndefined({
6083
6103
  type: source.type,
6084
6104
  source: source.source,
6085
- target: (_a2 = source.target) != null ? _a2 : void 0
6105
+ target: source.target ?? void 0
6086
6106
  });
6087
6107
  });
6088
6108
  let network;
@@ -6091,13 +6111,10 @@ var GoogleInteractionsLanguageModel = class _GoogleInteractionsLanguageModel {
6091
6111
  } else if (environmentOptions.network != null) {
6092
6112
  network = {
6093
6113
  allowlist: environmentOptions.network.allowlist.map(
6094
- (entry) => {
6095
- var _a2;
6096
- return pruneUndefined({
6097
- domain: entry.domain,
6098
- transform: (_a2 = entry.transform) != null ? _a2 : void 0
6099
- });
6100
- }
6114
+ (entry) => pruneUndefined({
6115
+ domain: entry.domain,
6116
+ transform: entry.transform ?? void 0
6117
+ })
6101
6118
  )
6102
6119
  };
6103
6120
  }
@@ -6114,25 +6131,24 @@ var GoogleInteractionsLanguageModel = class _GoogleInteractionsLanguageModel {
6114
6131
  system_instruction: systemInstruction,
6115
6132
  tools: toolsForBody,
6116
6133
  response_format: responseFormatEntries.length > 0 ? responseFormatEntries : void 0,
6117
- response_modalities: (googleOptions == null ? void 0 : googleOptions.responseModalities) != null ? googleOptions.responseModalities : void 0,
6118
- previous_interaction_id: (_B = googleOptions == null ? void 0 : googleOptions.previousInteractionId) != null ? _B : void 0,
6119
- service_tier: (_C = googleOptions == null ? void 0 : googleOptions.serviceTier) != null ? _C : void 0,
6120
- store: (_D = googleOptions == null ? void 0 : googleOptions.store) != null ? _D : void 0,
6134
+ response_modalities: googleOptions?.responseModalities != null ? googleOptions.responseModalities : void 0,
6135
+ previous_interaction_id: googleOptions?.previousInteractionId ?? void 0,
6136
+ service_tier: googleOptions?.serviceTier ?? void 0,
6137
+ store: googleOptions?.store ?? void 0,
6121
6138
  generation_config: generationConfig != null && Object.keys(generationConfig).length > 0 ? generationConfig : void 0,
6122
6139
  agent_config: agentConfig,
6123
6140
  environment,
6124
- background: (_E = googleOptions == null ? void 0 : googleOptions.background) != null ? _E : void 0
6141
+ background: googleOptions?.background ?? void 0
6125
6142
  });
6126
6143
  return {
6127
6144
  args,
6128
6145
  warnings,
6129
6146
  isAgent,
6130
- isBackground: (googleOptions == null ? void 0 : googleOptions.background) === true,
6131
- pollingTimeoutMs: (_F = googleOptions == null ? void 0 : googleOptions.pollingTimeoutMs) != null ? _F : void 0
6147
+ isBackground: googleOptions?.background === true,
6148
+ pollingTimeoutMs: googleOptions?.pollingTimeoutMs ?? void 0
6132
6149
  };
6133
6150
  }
6134
6151
  async doGenerate(options) {
6135
- var _a, _b, _c, _d, _e, _f;
6136
6152
  const { args, warnings, isAgent, pollingTimeoutMs } = await this.getArgs(options);
6137
6153
  const url = `${this.config.baseURL}/interactions`;
6138
6154
  const mergedHeaders = combineHeaders4(
@@ -6166,12 +6182,12 @@ var GoogleInteractionsLanguageModel = class _GoogleInteractionsLanguageModel {
6166
6182
  });
6167
6183
  response = polled.response;
6168
6184
  rawResponse = polled.rawResponse;
6169
- responseHeaders = (_a = polled.responseHeaders) != null ? _a : responseHeaders;
6185
+ responseHeaders = polled.responseHeaders ?? responseHeaders;
6170
6186
  }
6171
6187
  const interactionId = typeof response.id === "string" && response.id.length > 0 ? response.id : void 0;
6172
6188
  const { content, hasFunctionCall } = parseGoogleInteractionsOutputs({
6173
- steps: (_b = response.steps) != null ? _b : null,
6174
- generateId: (_c = this.config.generateId) != null ? _c : defaultGenerateId,
6189
+ steps: response.steps ?? null,
6190
+ generateId: this.config.generateId ?? defaultGenerateId,
6175
6191
  interactionId
6176
6192
  });
6177
6193
  const finishReason = {
@@ -6181,7 +6197,7 @@ var GoogleInteractionsLanguageModel = class _GoogleInteractionsLanguageModel {
6181
6197
  }),
6182
6198
  raw: response.status
6183
6199
  };
6184
- const serviceTier = (_e = (_d = response.service_tier) != null ? _d : responseHeaders == null ? void 0 : responseHeaders["x-gemini-service-tier"]) != null ? _e : void 0;
6200
+ const serviceTier = response.service_tier ?? responseHeaders?.["x-gemini-service-tier"] ?? void 0;
6185
6201
  const outputTokensByModality = getGoogleInteractionsOutputTokensByModality(
6186
6202
  response.usage
6187
6203
  );
@@ -6211,12 +6227,11 @@ var GoogleInteractionsLanguageModel = class _GoogleInteractionsLanguageModel {
6211
6227
  body: rawResponse,
6212
6228
  ...interactionId != null ? { id: interactionId } : {},
6213
6229
  ...timestamp ? { timestamp } : {},
6214
- modelId: (_f = response.model) != null ? _f : void 0
6230
+ modelId: response.model ?? void 0
6215
6231
  }
6216
6232
  };
6217
6233
  }
6218
6234
  async doStream(options) {
6219
- var _a;
6220
6235
  const { args, warnings, isBackground, pollingTimeoutMs } = await this.getArgs(options);
6221
6236
  const url = `${this.config.baseURL}/interactions`;
6222
6237
  const mergedHeaders = combineHeaders4(
@@ -6245,10 +6260,10 @@ var GoogleInteractionsLanguageModel = class _GoogleInteractionsLanguageModel {
6245
6260
  abortSignal: options.abortSignal,
6246
6261
  fetch: this.config.fetch
6247
6262
  });
6248
- const headerServiceTier = responseHeaders == null ? void 0 : responseHeaders["x-gemini-service-tier"];
6263
+ const headerServiceTier = responseHeaders?.["x-gemini-service-tier"];
6249
6264
  const transform = buildGoogleInteractionsStreamTransform({
6250
6265
  warnings,
6251
- generateId: (_a = this.config.generateId) != null ? _a : defaultGenerateId,
6266
+ generateId: this.config.generateId ?? defaultGenerateId,
6252
6267
  includeRawChunks: options.includeRawChunks,
6253
6268
  serviceTier: headerServiceTier
6254
6269
  });
@@ -6284,7 +6299,6 @@ var GoogleInteractionsLanguageModel = class _GoogleInteractionsLanguageModel {
6284
6299
  options,
6285
6300
  pollingTimeoutMs
6286
6301
  }) {
6287
- var _a, _b;
6288
6302
  const postResult = await postJsonToApi3({
6289
6303
  url,
6290
6304
  headers: mergedHeaders,
@@ -6303,12 +6317,12 @@ var GoogleInteractionsLanguageModel = class _GoogleInteractionsLanguageModel {
6303
6317
  "google.interactions: background POST response did not include an interaction id; cannot stream the result."
6304
6318
  );
6305
6319
  }
6306
- const headerServiceTier = postHeaders == null ? void 0 : postHeaders["x-gemini-service-tier"];
6320
+ const headerServiceTier = postHeaders?.["x-gemini-service-tier"];
6307
6321
  if (isTerminalStatus(postResponse.status)) {
6308
6322
  const synthesized = synthesizeGoogleInteractionsAgentStream({
6309
6323
  response: postResponse,
6310
6324
  warnings,
6311
- generateId: (_a = this.config.generateId) != null ? _a : defaultGenerateId,
6325
+ generateId: this.config.generateId ?? defaultGenerateId,
6312
6326
  includeRawChunks: options.includeRawChunks,
6313
6327
  headerServiceTier
6314
6328
  });
@@ -6328,7 +6342,7 @@ var GoogleInteractionsLanguageModel = class _GoogleInteractionsLanguageModel {
6328
6342
  });
6329
6343
  const transform = buildGoogleInteractionsStreamTransform({
6330
6344
  warnings,
6331
- generateId: (_b = this.config.generateId) != null ? _b : defaultGenerateId,
6345
+ generateId: this.config.generateId ?? defaultGenerateId,
6332
6346
  includeRawChunks: options.includeRawChunks,
6333
6347
  serviceTier: headerServiceTier
6334
6348
  });