@ai-sdk/google 4.0.68 → 4.0.70

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.js CHANGED
@@ -7,7 +7,7 @@ import {
7
7
  } from "@ai-sdk/provider-utils";
8
8
 
9
9
  // src/version.ts
10
- var VERSION = true ? "4.0.68" : "0.0.0-test";
10
+ var VERSION = true ? "4.0.70" : "0.0.0-test";
11
11
 
12
12
  // src/google-embedding-model.ts
13
13
  import {
@@ -255,7 +255,7 @@ var googleGenerativeAISingleEmbeddingResponseSchema = lazySchema3(
255
255
  import {
256
256
  InvalidArgumentError,
257
257
  InvalidResponseDataError,
258
- UnsupportedFunctionalityError as UnsupportedFunctionalityError4
258
+ UnsupportedFunctionalityError as UnsupportedFunctionalityError3
259
259
  } from "@ai-sdk/provider";
260
260
  import {
261
261
  combineHeaders as combineHeaders3,
@@ -329,289 +329,9 @@ function convertGoogleUsage(usage) {
329
329
  };
330
330
  }
331
331
 
332
- // src/convert-json-schema-to-openapi-schema.ts
333
- import {
334
- UnsupportedFunctionalityError
335
- } from "@ai-sdk/provider";
336
- var recursiveReferenceFunctionalityPrefix = "recursive JSON Schema reference:";
337
- function isRecursiveJSONSchemaReferenceError(error) {
338
- return UnsupportedFunctionalityError.isInstance(error) && error.functionality.startsWith(recursiveReferenceFunctionalityPrefix);
339
- }
340
- function convertJSONSchemaToOpenAPISchema(jsonSchema, isRoot = true) {
341
- const rootSchema = typeof jsonSchema === "object" ? jsonSchema : void 0;
342
- return convertJSONSchemaDefinition(jsonSchema, isRoot, {
343
- definitions: rootSchema == null ? void 0 : rootSchema.definitions,
344
- dollarDefinitions: rootSchema == null ? void 0 : rootSchema.$defs,
345
- resolvingReferences: /* @__PURE__ */ new Set()
346
- });
347
- }
348
- function convertJSONSchemaDefinition(jsonSchema, isRoot, referenceContext) {
349
- if (jsonSchema == null) {
350
- return void 0;
351
- }
352
- if (typeof jsonSchema === "boolean") {
353
- return { type: "boolean", properties: {} };
354
- }
355
- if (jsonSchema.$ref != null) {
356
- return convertJSONSchemaReference({
357
- jsonSchema,
358
- reference: jsonSchema.$ref,
359
- isRoot,
360
- referenceContext
361
- });
362
- }
363
- if (isEmptyObjectSchema(jsonSchema)) {
364
- if (isRoot) {
365
- return void 0;
366
- }
367
- if (jsonSchema.description) {
368
- return { type: "object", description: jsonSchema.description };
369
- }
370
- return { type: "object" };
371
- }
372
- const {
373
- type,
374
- description,
375
- required,
376
- properties,
377
- items,
378
- allOf,
379
- anyOf,
380
- oneOf,
381
- format,
382
- const: constValue,
383
- minLength,
384
- minItems,
385
- maxItems,
386
- enum: enumValues
387
- } = jsonSchema;
388
- const result = {};
389
- if (description) result.description = description;
390
- if (required) result.required = required;
391
- if (format) result.format = format;
392
- if (type) {
393
- if (Array.isArray(type)) {
394
- const hasNull = type.includes("null");
395
- const nonNullTypes = type.filter((t) => t !== "null");
396
- if (nonNullTypes.length === 0) {
397
- result.type = "null";
398
- } else {
399
- result.anyOf = nonNullTypes.map((t) => ({ type: t }));
400
- if (hasNull) {
401
- result.nullable = true;
402
- }
403
- }
404
- } else {
405
- result.type = type;
406
- }
407
- }
408
- const values = enumValues != null ? enumValues : constValue !== void 0 ? [constValue] : void 0;
409
- if (values !== void 0) {
410
- addEnumToSchema({ values, type, result });
411
- }
412
- if (properties != null) {
413
- result.properties = Object.entries(properties).reduce(
414
- (acc, [key, value]) => {
415
- acc[key] = convertJSONSchemaDefinition(value, false, referenceContext);
416
- return acc;
417
- },
418
- {}
419
- );
420
- }
421
- if (items) {
422
- result.items = Array.isArray(items) ? items.map(
423
- (item) => convertJSONSchemaDefinition(item, false, referenceContext)
424
- ) : convertJSONSchemaDefinition(items, false, referenceContext);
425
- }
426
- if (allOf) {
427
- result.allOf = allOf.map(
428
- (item) => convertJSONSchemaDefinition(item, false, referenceContext)
429
- );
430
- }
431
- if (anyOf) {
432
- if (anyOf.some(
433
- (schema) => typeof schema === "object" && (schema == null ? void 0 : schema.type) === "null"
434
- )) {
435
- const nonNullSchemas = anyOf.filter(
436
- (schema) => !(typeof schema === "object" && (schema == null ? void 0 : schema.type) === "null")
437
- );
438
- if (nonNullSchemas.length === 1) {
439
- const converted = convertJSONSchemaDefinition(
440
- nonNullSchemas[0],
441
- false,
442
- referenceContext
443
- );
444
- if (typeof converted === "object") {
445
- result.nullable = true;
446
- Object.assign(result, converted);
447
- }
448
- } else {
449
- result.anyOf = nonNullSchemas.map(
450
- (item) => convertJSONSchemaDefinition(item, false, referenceContext)
451
- );
452
- result.nullable = true;
453
- }
454
- } else {
455
- result.anyOf = anyOf.map(
456
- (item) => convertJSONSchemaDefinition(item, false, referenceContext)
457
- );
458
- }
459
- }
460
- if (oneOf) {
461
- result.oneOf = oneOf.map(
462
- (item) => convertJSONSchemaDefinition(item, false, referenceContext)
463
- );
464
- }
465
- if (minLength !== void 0) {
466
- result.minLength = minLength;
467
- }
468
- if (minItems !== void 0) {
469
- result.minItems = minItems;
470
- }
471
- if (maxItems !== void 0) {
472
- result.maxItems = maxItems;
473
- }
474
- return result;
475
- }
476
- function convertJSONSchemaReference({
477
- jsonSchema,
478
- reference,
479
- isRoot,
480
- referenceContext
481
- }) {
482
- const { definition, referenceKey } = getReferencedDefinition(
483
- reference,
484
- referenceContext
485
- );
486
- if (referenceContext.resolvingReferences.has(referenceKey)) {
487
- throw new UnsupportedFunctionalityError({
488
- functionality: `${recursiveReferenceFunctionalityPrefix} ${reference}`,
489
- message: "Google schema conversion does not support recursive JSON Schema references."
490
- });
491
- }
492
- const resolvingReferences = new Set(referenceContext.resolvingReferences);
493
- resolvingReferences.add(referenceKey);
494
- const { $ref: _reference, ...siblingSchema } = jsonSchema;
495
- const resolvedSchema = typeof definition === "boolean" ? definition ? siblingSchema : false : { ...definition, ...siblingSchema };
496
- return convertJSONSchemaDefinition(resolvedSchema, isRoot, {
497
- ...referenceContext,
498
- resolvingReferences
499
- });
500
- }
501
- function getReferencedDefinition(reference, referenceContext) {
502
- const definitionSources = [
503
- {
504
- prefix: "#/$defs/",
505
- definitions: referenceContext.dollarDefinitions
506
- },
507
- {
508
- prefix: "#/definitions/",
509
- definitions: referenceContext.definitions
510
- }
511
- ];
512
- const source = definitionSources.find(
513
- ({ prefix }) => reference.startsWith(prefix)
514
- );
515
- const encodedDefinitionName = source ? reference.slice(source.prefix.length) : void 0;
516
- if (source == null || encodedDefinitionName == null || encodedDefinitionName.length === 0 || encodedDefinitionName.includes("/")) {
517
- throwUnsupportedReference(reference);
518
- }
519
- let decodedDefinitionName;
520
- try {
521
- decodedDefinitionName = decodeURIComponent(encodedDefinitionName);
522
- } catch (e) {
523
- throwUnsupportedReference(reference);
524
- }
525
- if (decodedDefinitionName.includes("/") || /~(?![01])/u.test(decodedDefinitionName) || source.definitions == null) {
526
- throwUnsupportedReference(reference);
527
- }
528
- const definitionName = decodedDefinitionName.replace(
529
- /~[01]/g,
530
- (match) => match === "~1" ? "/" : "~"
531
- );
532
- if (!Object.prototype.hasOwnProperty.call(source.definitions, definitionName)) {
533
- throwUnsupportedReference(reference);
534
- }
535
- return {
536
- definition: source.definitions[definitionName],
537
- referenceKey: `${source.prefix}${definitionName}`
538
- };
539
- }
540
- function throwUnsupportedReference(reference) {
541
- throw new UnsupportedFunctionalityError({
542
- functionality: `JSON Schema reference: ${reference}`,
543
- message: "Google schema conversion only supports references to direct children of root-level $defs or definitions."
544
- });
545
- }
546
- function addEnumToSchema({
547
- values,
548
- type,
549
- result
550
- }) {
551
- const nullable = Array.isArray(type) && type.includes("null") || type === void 0 && values.includes(null);
552
- const enumValues = nullable ? values.filter((value) => value !== null) : values;
553
- if (values.length > 0 && values.every((value) => value === null)) {
554
- const typeAllowsNull = type === void 0 || type === "null" || Array.isArray(type) && type.includes("null");
555
- if (typeAllowsNull) {
556
- result.type = "null";
557
- if (Array.isArray(type)) {
558
- delete result.anyOf;
559
- }
560
- return;
561
- }
562
- }
563
- const enumType = getEnumType({ values: enumValues, type });
564
- if (enumType === void 0) {
565
- throw new UnsupportedFunctionalityError({
566
- functionality: "JSON Schema enum with mixed or unsupported values",
567
- message: "Google does not support this JSON Schema enum. Enum values must share one supported primitive type and match the schema type."
568
- });
569
- }
570
- result.type = enumType;
571
- if (Array.isArray(type)) {
572
- delete result.anyOf;
573
- }
574
- if (nullable) {
575
- result.nullable = true;
576
- }
577
- if (enumType === "string") {
578
- result.enum = enumValues;
579
- } else {
580
- result.format = "enum";
581
- result.enum = enumValues.map(String);
582
- }
583
- }
584
- function getEnumType({
585
- values,
586
- type
587
- }) {
588
- if (values.length === 0) {
589
- return void 0;
590
- }
591
- const typeAllows = (enumType) => type === void 0 || type === enumType || Array.isArray(type) && type.includes(enumType);
592
- if (typeAllows("string") && values.every((value) => typeof value === "string")) {
593
- return "string";
594
- }
595
- if ((typeAllows("number") || typeAllows("integer")) && values.every((value) => typeof value === "number" && Number.isFinite(value))) {
596
- if (typeAllows("number")) {
597
- return "number";
598
- }
599
- if (values.every((value) => Number.isInteger(value))) {
600
- return "integer";
601
- }
602
- }
603
- if (typeAllows("boolean") && values.every((value) => typeof value === "boolean")) {
604
- return "boolean";
605
- }
606
- return void 0;
607
- }
608
- function isEmptyObjectSchema(jsonSchema) {
609
- return jsonSchema != null && typeof jsonSchema === "object" && jsonSchema.type === "object" && (jsonSchema.properties == null || Object.keys(jsonSchema.properties).length === 0) && !jsonSchema.additionalProperties;
610
- }
611
-
612
332
  // src/convert-to-google-messages.ts
613
333
  import {
614
- UnsupportedFunctionalityError as UnsupportedFunctionalityError2
334
+ UnsupportedFunctionalityError
615
335
  } from "@ai-sdk/provider";
616
336
  import {
617
337
  convertToBase64,
@@ -768,7 +488,7 @@ function convertToGoogleMessages(prompt, options) {
768
488
  switch (role) {
769
489
  case "system": {
770
490
  if (!systemMessagesAllowed) {
771
- throw new UnsupportedFunctionalityError2({
491
+ throw new UnsupportedFunctionalityError({
772
492
  functionality: "system messages are only supported at the beginning of the conversation"
773
493
  });
774
494
  }
@@ -797,7 +517,7 @@ function convertToGoogleMessages(prompt, options) {
797
517
  }
798
518
  case "reference": {
799
519
  if (isVertexLike) {
800
- throw new UnsupportedFunctionalityError2({
520
+ throw new UnsupportedFunctionalityError({
801
521
  functionality: "file parts with provider references"
802
522
  });
803
523
  }
@@ -865,7 +585,7 @@ function convertToGoogleMessages(prompt, options) {
865
585
  case "reasoning-file": {
866
586
  switch (part.data.type) {
867
587
  case "url": {
868
- throw new UnsupportedFunctionalityError2({
588
+ throw new UnsupportedFunctionalityError({
869
589
  functionality: "File data URLs in assistant messages are not supported"
870
590
  });
871
591
  }
@@ -885,13 +605,13 @@ function convertToGoogleMessages(prompt, options) {
885
605
  case "file": {
886
606
  switch (part.data.type) {
887
607
  case "url": {
888
- throw new UnsupportedFunctionalityError2({
608
+ throw new UnsupportedFunctionalityError({
889
609
  functionality: "File data URLs in assistant messages are not supported"
890
610
  });
891
611
  }
892
612
  case "reference": {
893
613
  if (isVertexLike) {
894
- throw new UnsupportedFunctionalityError2({
614
+ throw new UnsupportedFunctionalityError({
895
615
  functionality: "file parts with provider references"
896
616
  });
897
617
  }
@@ -1070,6 +790,128 @@ function convertToGoogleMessages(prompt, options) {
1070
790
  };
1071
791
  }
1072
792
 
793
+ // src/download-tool-result-files.ts
794
+ import {
795
+ detectMediaType,
796
+ downloadBlob,
797
+ isFullMediaType as isFullMediaType2
798
+ } from "@ai-sdk/provider-utils";
799
+ async function downloadToolResultFiles(prompt, {
800
+ abortSignal,
801
+ maxBytes
802
+ }) {
803
+ const result = [];
804
+ for (const message of prompt) {
805
+ if (message.role === "assistant") {
806
+ const content = [];
807
+ for (const part of message.content) {
808
+ content.push(
809
+ part.type === "tool-result" ? {
810
+ ...part,
811
+ output: await downloadToolResultOutput(part.output, {
812
+ abortSignal,
813
+ maxBytes
814
+ })
815
+ } : part
816
+ );
817
+ }
818
+ result.push({ ...message, content });
819
+ continue;
820
+ }
821
+ if (message.role === "tool") {
822
+ const content = [];
823
+ for (const part of message.content) {
824
+ if (part.type !== "tool-result") {
825
+ content.push(part);
826
+ continue;
827
+ }
828
+ content.push({
829
+ ...part,
830
+ output: await downloadToolResultOutput(part.output, {
831
+ abortSignal,
832
+ maxBytes
833
+ })
834
+ });
835
+ }
836
+ result.push({ ...message, content });
837
+ continue;
838
+ }
839
+ result.push(message);
840
+ }
841
+ return result;
842
+ }
843
+ async function downloadToolResultOutput(output, {
844
+ abortSignal,
845
+ maxBytes
846
+ }) {
847
+ if (output.type !== "content") {
848
+ return output;
849
+ }
850
+ const value = [];
851
+ for (const part of output.value) {
852
+ if (part.type !== "file" || part.data.type !== "url") {
853
+ value.push(part);
854
+ continue;
855
+ }
856
+ const blob = await downloadBlob(part.data.url.toString(), {
857
+ abortSignal,
858
+ maxBytes
859
+ });
860
+ const data = new Uint8Array(await blob.arrayBuffer());
861
+ const detectedMediaType = detectMediaType({
862
+ data,
863
+ topLevelType: "image"
864
+ });
865
+ value.push({
866
+ ...part,
867
+ data: { type: "data", data },
868
+ mediaType: detectedMediaType != null ? detectedMediaType : blob.type && !isFullMediaType2(part.mediaType) ? blob.type : part.mediaType
869
+ });
870
+ }
871
+ return {
872
+ ...output,
873
+ value
874
+ };
875
+ }
876
+
877
+ // src/sanitize-response-json-schema.ts
878
+ function sanitizeResponseJsonSchema(schema) {
879
+ const {
880
+ const: constValue,
881
+ properties,
882
+ items,
883
+ additionalProperties,
884
+ anyOf,
885
+ oneOf,
886
+ ...result
887
+ } = schema;
888
+ return {
889
+ ...result,
890
+ ...constValue !== void 0 ? { enum: [constValue] } : {},
891
+ ...properties != null ? { properties: sanitizeDefinitions(properties) } : {},
892
+ ...items != null ? {
893
+ items: Array.isArray(items) ? items.map(sanitizeDefinition) : sanitizeDefinition(items)
894
+ } : {},
895
+ ...additionalProperties != null ? {
896
+ additionalProperties: typeof additionalProperties === "boolean" ? additionalProperties : sanitizeDefinition(additionalProperties)
897
+ } : {},
898
+ ...anyOf != null ? { anyOf: anyOf.map(sanitizeDefinition) } : {},
899
+ ...oneOf != null ? { oneOf: oneOf.map(sanitizeDefinition) } : {},
900
+ ...result.$defs != null ? { $defs: sanitizeDefinitions(result.$defs) } : {}
901
+ };
902
+ }
903
+ function sanitizeDefinitions(definitions) {
904
+ return Object.fromEntries(
905
+ Object.entries(definitions).map(([name, definition]) => [
906
+ name,
907
+ sanitizeDefinition(definition)
908
+ ])
909
+ );
910
+ }
911
+ function sanitizeDefinition(definition) {
912
+ return typeof definition === "boolean" ? definition : sanitizeResponseJsonSchema(definition);
913
+ }
914
+
1073
915
  // src/google-language-model-options.ts
1074
916
  import {
1075
917
  lazySchema as lazySchema4,
@@ -1284,7 +1126,7 @@ function getGoogleModelCapabilities(modelId) {
1284
1126
 
1285
1127
  // src/google-prepare-tools.ts
1286
1128
  import {
1287
- UnsupportedFunctionalityError as UnsupportedFunctionalityError3
1129
+ UnsupportedFunctionalityError as UnsupportedFunctionalityError2
1288
1130
  } from "@ai-sdk/provider";
1289
1131
  function prepareTools({
1290
1132
  tools,
@@ -1514,7 +1356,7 @@ function prepareTools({
1514
1356
  };
1515
1357
  default: {
1516
1358
  const _exhaustiveCheck = type;
1517
- throw new UnsupportedFunctionalityError3({
1359
+ throw new UnsupportedFunctionalityError2({
1518
1360
  functionality: `tool choice type: ${_exhaustiveCheck}`
1519
1361
  });
1520
1362
  }
@@ -1522,24 +1364,11 @@ function prepareTools({
1522
1364
  }
1523
1365
  function prepareFunctionDeclaration(tool) {
1524
1366
  var _a;
1525
- const declaration = {
1367
+ return {
1526
1368
  name: tool.name,
1527
- description: (_a = tool.description) != null ? _a : ""
1369
+ description: (_a = tool.description) != null ? _a : "",
1370
+ parametersJsonSchema: tool.inputSchema
1528
1371
  };
1529
- try {
1530
- return {
1531
- ...declaration,
1532
- parameters: convertJSONSchemaToOpenAPISchema(tool.inputSchema)
1533
- };
1534
- } catch (error) {
1535
- if (!isRecursiveJSONSchemaReferenceError(error)) {
1536
- throw error;
1537
- }
1538
- return {
1539
- ...declaration,
1540
- parametersJsonSchema: tool.inputSchema
1541
- };
1542
- }
1543
1372
  }
1544
1373
 
1545
1374
  // src/google-json-accumulator.ts
@@ -1858,7 +1687,8 @@ var GoogleLanguageModel = class _GoogleLanguageModel {
1858
1687
  tools,
1859
1688
  toolChoice,
1860
1689
  reasoning,
1861
- providerOptions
1690
+ providerOptions,
1691
+ abortSignal
1862
1692
  },
1863
1693
  isStreaming = false
1864
1694
  }) {
@@ -1955,14 +1785,21 @@ var GoogleLanguageModel = class _GoogleLanguageModel {
1955
1785
  });
1956
1786
  }
1957
1787
  const { usesGemini3Features } = getGoogleModelCapabilities(modelId);
1958
- const { contents, systemInstruction } = convertToGoogleMessages(prompt, {
1959
- isGemmaModel,
1960
- isGemini3Model: usesGemini3Features,
1961
- onWarning: (warning) => warnings.push(warning),
1962
- providerOptionsNames,
1963
- supportsFunctionResponseParts: usesGemini3Features,
1964
- includeFunctionCallIds: !isVertexProvider
1965
- });
1788
+ const promptWithDownloadedToolResultFiles = config.downloadToolResultFiles ? await downloadToolResultFiles(prompt, {
1789
+ abortSignal,
1790
+ maxBytes: config.downloadToolResultFiles.maxBytes
1791
+ }) : prompt;
1792
+ const { contents, systemInstruction } = convertToGoogleMessages(
1793
+ promptWithDownloadedToolResultFiles,
1794
+ {
1795
+ isGemmaModel,
1796
+ isGemini3Model: usesGemini3Features,
1797
+ onWarning: (warning) => warnings.push(warning),
1798
+ providerOptionsNames,
1799
+ supportsFunctionResponseParts: usesGemini3Features,
1800
+ includeFunctionCallIds: !isVertexProvider
1801
+ }
1802
+ );
1966
1803
  const {
1967
1804
  tools: googleTools2,
1968
1805
  toolConfig: googleToolConfig,
@@ -2017,10 +1854,10 @@ var GoogleLanguageModel = class _GoogleLanguageModel {
2017
1854
  seed,
2018
1855
  // response format:
2019
1856
  responseMimeType: (responseFormat == null ? void 0 : responseFormat.type) === "json" ? "application/json" : void 0,
2020
- responseSchema: (responseFormat == null ? void 0 : responseFormat.type) === "json" && responseFormat.schema != null && // Google GenAI does not support all OpenAPI Schema features,
2021
- // so this is needed as an escape hatch:
1857
+ responseJsonSchema: (responseFormat == null ? void 0 : responseFormat.type) === "json" && responseFormat.schema != null && // Google does not support all JSON Schema features in
1858
+ // responseJsonSchema, so this is needed as an escape hatch:
2022
1859
  // TODO convert into provider option
2023
- ((_c = googleOptions == null ? void 0 : googleOptions.structuredOutputs) != null ? _c : true) ? convertJSONSchemaToOpenAPISchema(responseFormat.schema) : void 0,
1860
+ ((_c = googleOptions == null ? void 0 : googleOptions.structuredOutputs) != null ? _c : true) ? sanitizeResponseJsonSchema(responseFormat.schema) : void 0,
2024
1861
  ...(googleOptions == null ? void 0 : googleOptions.audioTimestamp) && {
2025
1862
  audioTimestamp: googleOptions.audioTimestamp
2026
1863
  },
@@ -3122,7 +2959,7 @@ function assertSupportedBatchRequests(requests) {
3122
2959
  for (const request of requests) {
3123
2960
  const requestType = request.type;
3124
2961
  if (requestType !== "text" && requestType !== "image") {
3125
- throw new UnsupportedFunctionalityError4({
2962
+ throw new UnsupportedFunctionalityError3({
3126
2963
  functionality: `batch request type: ${requestType}`,
3127
2964
  message: `The Google Batch API does not support batch requests with type "${requestType}".`
3128
2965
  });
@@ -3611,12 +3448,12 @@ var GoogleBatch = class {
3611
3448
  const { prompt, n, size, aspectRatio, seed, files, mask, providerOptions } = request.options;
3612
3449
  const warnings = [];
3613
3450
  if (mask != null) {
3614
- throw new UnsupportedFunctionalityError4({
3451
+ throw new UnsupportedFunctionalityError3({
3615
3452
  functionality: "mask-based image editing in Google batches"
3616
3453
  });
3617
3454
  }
3618
3455
  if (n > 1) {
3619
- throw new UnsupportedFunctionalityError4({
3456
+ throw new UnsupportedFunctionalityError3({
3620
3457
  functionality: "multiple images per Google batch request"
3621
3458
  });
3622
3459
  }
@@ -5758,7 +5595,7 @@ function buildGoogleInteractionsStreamTransform({
5758
5595
  import {
5759
5596
  convertToBase64 as convertToBase644,
5760
5597
  getTopLevelMediaType as getTopLevelMediaType2,
5761
- isFullMediaType as isFullMediaType2,
5598
+ isFullMediaType as isFullMediaType3,
5762
5599
  resolveFullMediaType as resolveFullMediaType2,
5763
5600
  resolveProviderReference as resolveProviderReference2,
5764
5601
  secureJsonParse as secureJsonParse2
@@ -5967,7 +5804,7 @@ function convertFilePartToContent({
5967
5804
  return {
5968
5805
  type: kind,
5969
5806
  uri: part.data.url.toString(),
5970
- ...isFullMediaType2(part.mediaType) ? { mime_type: part.mediaType } : {},
5807
+ ...isFullMediaType3(part.mediaType) ? { mime_type: part.mediaType } : {},
5971
5808
  ...resolutionField,
5972
5809
  ...processingField
5973
5810
  };
@@ -5980,7 +5817,7 @@ function convertFilePartToContent({
5980
5817
  return {
5981
5818
  type: kind,
5982
5819
  uri,
5983
- ...isFullMediaType2(part.mediaType) ? { mime_type: part.mediaType } : {},
5820
+ ...isFullMediaType3(part.mediaType) ? { mime_type: part.mediaType } : {},
5984
5821
  ...resolutionField,
5985
5822
  ...processingField
5986
5823
  };
@@ -6135,7 +5972,7 @@ function filePartToImageBlock({
6135
5972
  }) {
6136
5973
  switch (part.data.type) {
6137
5974
  case "data": {
6138
- const mimeType = isFullMediaType2(part.mediaType) ? part.mediaType : resolveFullMediaType2({
5975
+ const mimeType = isFullMediaType3(part.mediaType) ? part.mediaType : resolveFullMediaType2({
6139
5976
  part: {
6140
5977
  type: "file",
6141
5978
  mediaType: part.mediaType,
@@ -6152,7 +5989,7 @@ function filePartToImageBlock({
6152
5989
  return {
6153
5990
  type: "image",
6154
5991
  uri: part.data.url.toString(),
6155
- ...isFullMediaType2(part.mediaType) ? { mime_type: part.mediaType } : {}
5992
+ ...isFullMediaType3(part.mediaType) ? { mime_type: part.mediaType } : {}
6156
5993
  };
6157
5994
  case "reference": {
6158
5995
  const uri = resolveProviderReference2({
@@ -6162,7 +5999,7 @@ function filePartToImageBlock({
6162
5999
  return {
6163
6000
  type: "image",
6164
6001
  uri,
6165
- ...isFullMediaType2(part.mediaType) ? { mime_type: part.mediaType } : {}
6002
+ ...isFullMediaType3(part.mediaType) ? { mime_type: part.mediaType } : {}
6166
6003
  };
6167
6004
  }
6168
6005
  case "text": {
@@ -8308,9 +8145,16 @@ var GoogleRealtimeEventMapper = class {
8308
8145
  return null;
8309
8146
  }
8310
8147
  };
8148
+ function toFunctionResponseStruct(value) {
8149
+ const isStruct = typeof value === "object" && value !== null && !Array.isArray(value);
8150
+ return isStruct ? value : { output: value };
8151
+ }
8311
8152
  async function serializeFunctionCallOutput(item) {
8312
8153
  const parseResult = await safeParseJSON({ text: item.output });
8313
- const response = parseResult.success ? parseResult.value : {};
8154
+ const response = parseResult.success ? toFunctionResponseStruct(parseResult.value) : (
8155
+ // Preserve non-JSON output in the required object wrapper.
8156
+ { output: item.output }
8157
+ );
8314
8158
  return {
8315
8159
  toolResponse: {
8316
8160
  functionResponses: [
@@ -8356,7 +8200,7 @@ function buildGoogleSessionConfig(config, modelId) {
8356
8200
  functionDeclarations: config.tools.map((tool) => ({
8357
8201
  name: tool.name,
8358
8202
  description: tool.description,
8359
- parameters: convertJSONSchemaToOpenAPISchema(tool.parameters)
8203
+ parametersJsonSchema: tool.parameters
8360
8204
  }))
8361
8205
  }
8362
8206
  ];