@gullabs/google 0.7.0 → 0.8.1

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
@@ -1,4 +1,5 @@
1
- import { LlmError, assertNever, classifyError, redactSecrets } from '@gullabs/core';
1
+ import { zodToStandardSchema, toConfigJsonSchema, createModelRegistry, LlmError, classifyError, assertNever, computeCost, redactSecrets } from '@gullabs/core';
2
+ import { z } from 'zod';
2
3
 
3
4
  // src/adapter.ts
4
5
  function requireApiKey(auth) {
@@ -22,6 +23,10 @@ async function buildGoogleClient(auth) {
22
23
  async generateContent(params) {
23
24
  const result = await ai.models.generateContent(params);
24
25
  return result;
26
+ },
27
+ async countTokens(params) {
28
+ const result = await ai.models.countTokens(params);
29
+ return result;
25
30
  }
26
31
  }
27
32
  };
@@ -67,6 +72,7 @@ function isGeminiCapacityError(err) {
67
72
  // src/adapter.ts
68
73
  var ALLOWED_GOOGLE_PROVIDER_OPTION_KEYS = /* @__PURE__ */ new Set([
69
74
  "cachedContent",
75
+ "flexFallback",
70
76
  "httpOptions",
71
77
  "safetySettings",
72
78
  "tools"
@@ -197,7 +203,7 @@ function mapGoogleProviderOptions(googleOpts, model, structuredOutputRequested,
197
203
  throw badGoogleProviderOptions(
198
204
  `providerOptions.google contains unsupported keys [${unknownKeys.join(
199
205
  ", "
200
- )}] for model "${model}". Allowed keys: cachedContent, httpOptions, safetySettings, tools.`
206
+ )}] for model "${model}". Allowed keys: cachedContent, flexFallback, httpOptions, safetySettings, tools.`
201
207
  );
202
208
  }
203
209
  const mapped = {};
@@ -209,6 +215,14 @@ function mapGoogleProviderOptions(googleOpts, model, structuredOutputRequested,
209
215
  }
210
216
  mapped.cachedContent = googleOpts["cachedContent"];
211
217
  }
218
+ if (googleOpts["flexFallback"] !== void 0) {
219
+ if (typeof googleOpts["flexFallback"] !== "boolean") {
220
+ throw badGoogleProviderOptions(
221
+ `providerOptions.google.flexFallback must be a boolean for model "${model}".`
222
+ );
223
+ }
224
+ mapped.flexFallback = googleOpts["flexFallback"];
225
+ }
212
226
  if (googleOpts["httpOptions"] !== void 0) {
213
227
  if (!isPlainRecord(googleOpts["httpOptions"])) {
214
228
  throw badGoogleProviderOptions(
@@ -345,6 +359,38 @@ function mapUsage(meta) {
345
359
  };
346
360
  return usage;
347
361
  }
362
+ function mapPart(p) {
363
+ switch (p.kind) {
364
+ case "text":
365
+ return { text: p.text };
366
+ case "inline-media": {
367
+ return {
368
+ inlineData: {
369
+ mimeType: p.mimeType,
370
+ data: p.data
371
+ },
372
+ ...p.mediaResolution !== void 0 ? { mediaResolution: { level: mapMediaResolution(p.mediaResolution) } } : {}
373
+ };
374
+ }
375
+ case "file-uri": {
376
+ return {
377
+ fileData: {
378
+ mimeType: p.mimeType,
379
+ fileUri: p.uri
380
+ },
381
+ ...p.mediaResolution !== void 0 ? { mediaResolution: { level: mapMediaResolution(p.mediaResolution) } } : {}
382
+ };
383
+ }
384
+ default:
385
+ return assertNever(p);
386
+ }
387
+ }
388
+ function mapMessagesToGeminiContents(messages) {
389
+ return messages.map((msg) => ({
390
+ role: msg.role === "assistant" ? "model" : "user",
391
+ parts: msg.parts.map(mapPart)
392
+ }));
393
+ }
348
394
  function geminiAdapter(opts) {
349
395
  return {
350
396
  id: "google",
@@ -357,36 +403,7 @@ function geminiAdapter(opts) {
357
403
  }
358
404
  const warnings = [];
359
405
  const model = req.model;
360
- const mapPart = (p) => {
361
- switch (p.kind) {
362
- case "text":
363
- return { text: p.text };
364
- case "inline-media": {
365
- return {
366
- inlineData: {
367
- mimeType: p.mimeType,
368
- data: p.data
369
- },
370
- ...p.mediaResolution !== void 0 ? { mediaResolution: { level: mapMediaResolution(p.mediaResolution) } } : {}
371
- };
372
- }
373
- case "file-uri": {
374
- return {
375
- fileData: {
376
- mimeType: p.mimeType,
377
- fileUri: p.uri
378
- },
379
- ...p.mediaResolution !== void 0 ? { mediaResolution: { level: mapMediaResolution(p.mediaResolution) } } : {}
380
- };
381
- }
382
- default:
383
- return assertNever(p);
384
- }
385
- };
386
- const contents = req.messages.map((msg) => ({
387
- role: msg.role === "assistant" ? "model" : "user",
388
- parts: msg.parts.map(mapPart)
389
- }));
406
+ const contents = mapMessagesToGeminiContents(req.messages);
390
407
  const genConfig = req.config;
391
408
  const config = {};
392
409
  if (req.system !== void 0) {
@@ -570,7 +587,7 @@ function geminiAdapter(opts) {
570
587
  cause: classified.cause ?? rawErr,
571
588
  ...servedServiceTier !== void 0 ? { servedServiceTier } : {}
572
589
  });
573
- if (config.serviceTier === "flex" && genConfig.flexFallback !== false && isGeminiCapacityError(typed)) {
590
+ if (config.serviceTier === "flex" && googleProviderConfig.flexFallback !== false && isGeminiCapacityError(typed)) {
574
591
  config.serviceTier = "standard";
575
592
  servedServiceTier = "standard";
576
593
  const fallbackTimeout = genConfig.timeoutMs !== void 0 ? genConfig.timeoutMs + TRANSPORT_TIMEOUT_BUFFER_MS : STANDARD_DEFAULT_TIMEOUT_MS;
@@ -675,9 +692,2006 @@ function geminiAdapter(opts) {
675
692
  })()
676
693
  };
677
694
  return result;
695
+ },
696
+ async countTokens(req, ctx) {
697
+ if (req.provider !== "google") {
698
+ throw new LlmError(
699
+ `geminiAdapter received a request for provider "${req.provider}", expected "google".`,
700
+ { kind: "bad_request", retryable: false }
701
+ );
702
+ }
703
+ const contents = mapMessagesToGeminiContents(req.messages);
704
+ const params = {
705
+ model: req.model,
706
+ contents,
707
+ ...req.system !== void 0 || ctx.signal !== void 0 ? {
708
+ config: {
709
+ ...req.system !== void 0 ? { systemInstruction: { parts: [{ text: req.system }] } } : {},
710
+ ...ctx.signal !== void 0 ? { abortSignal: ctx.signal } : {}
711
+ }
712
+ } : {}
713
+ };
714
+ try {
715
+ const buildClient = opts?._clientFactory ?? buildGoogleClient;
716
+ const client = opts?.client !== void 0 ? opts.client : await buildClient(ctx.auth);
717
+ const response = await client.models.countTokens(params);
718
+ if (response.totalTokens === void 0) {
719
+ throw new LlmError(
720
+ "Gemini countTokens response is malformed: missing required field: totalTokens",
721
+ { kind: "server", retryable: true, provider: "google" }
722
+ );
723
+ }
724
+ const details = response.cachedContentTokenCount !== void 0 ? { cached: response.cachedContentTokenCount } : void 0;
725
+ return {
726
+ totalTokens: response.totalTokens,
727
+ ...details !== void 0 ? { details } : {},
728
+ raw: response
729
+ };
730
+ } catch (rawErr) {
731
+ if (rawErr instanceof LlmError) throw rawErr;
732
+ const classified = classifyError(rawErr);
733
+ throw new LlmError(classified.message, {
734
+ kind: classified.kind,
735
+ retryable: classified.retryable,
736
+ ...classified.httpStatus !== void 0 ? { httpStatus: classified.httpStatus } : {},
737
+ ...classified.retryAfterMs !== void 0 ? { retryAfterMs: classified.retryAfterMs } : {},
738
+ provider: "google",
739
+ cause: classified.cause ?? rawErr
740
+ });
741
+ }
678
742
  }
679
743
  };
680
744
  }
745
+
746
+ // src/pricing.ts
747
+ var pricingVersion = "gemini-2026-06-28";
748
+ var TIER_FACTOR = Object.freeze({
749
+ standard: 1,
750
+ flex: 0.5,
751
+ batch: 0.5
752
+ });
753
+ var GEMINI_PRICING = Object.freeze({
754
+ // ── Gemini 2.5 Pro ── $1.25/$10 (≤200k), $2.50/$15 (>200k); cached $0.125/$0.25
755
+ "gemini-2.5-pro": {
756
+ inputPerM: 125e4,
757
+ cachedPerM: 125e3,
758
+ outputPerM: 1e7,
759
+ gt200k: {
760
+ inputPerM: 25e5,
761
+ cachedPerM: 25e4,
762
+ outputPerM: 15e6
763
+ }
764
+ },
765
+ // ── Gemini 2.5 Flash ── input $0.30 (text), output $2.50, cached $0.03
766
+ "gemini-2.5-flash": {
767
+ inputPerM: 3e5,
768
+ cachedPerM: 3e4,
769
+ outputPerM: 25e5
770
+ },
771
+ // ── Gemini 2.5 Flash-Lite ── input $0.10 (text), output $0.40, cached $0.01
772
+ "gemini-2.5-flash-lite": {
773
+ inputPerM: 1e5,
774
+ cachedPerM: 1e4,
775
+ outputPerM: 4e5
776
+ },
777
+ // ── Gemini 3.5 Flash ── input $1.50, output $9.00, cached $0.15
778
+ "gemini-3.5-flash": {
779
+ inputPerM: 15e5,
780
+ cachedPerM: 15e4,
781
+ outputPerM: 9e6
782
+ },
783
+ // ── Gemini 3.1 Flash-Lite ── input $0.25 (text), output $1.50, cached $0.025
784
+ "gemini-3.1-flash-lite": {
785
+ inputPerM: 25e4,
786
+ cachedPerM: 25e3,
787
+ outputPerM: 15e5
788
+ },
789
+ // ── Gemini 3.1 Pro (preview) ── $2.00/$12 (≤200k), $4.00/$18 (>200k); cached $0.20/$0.40
790
+ "gemini-3.1-pro-preview": {
791
+ inputPerM: 2e6,
792
+ cachedPerM: 2e5,
793
+ outputPerM: 12e6,
794
+ gt200k: {
795
+ inputPerM: 4e6,
796
+ cachedPerM: 4e5,
797
+ outputPerM: 18e6
798
+ }
799
+ },
800
+ // ── Gemini 3 Flash (preview) ── input $0.50, output $3.00, cached $0.05 (90% discount)
801
+ "gemini-3-flash-preview": {
802
+ inputPerM: 5e5,
803
+ cachedPerM: 5e4,
804
+ outputPerM: 3e6
805
+ }
806
+ });
807
+
808
+ // src/cost.ts
809
+ function lookupRates(model) {
810
+ const exact = GEMINI_PRICING[model];
811
+ if (exact !== void 0) return exact;
812
+ let bestKey = "";
813
+ let bestRates;
814
+ for (const key of Object.keys(GEMINI_PRICING)) {
815
+ if (model.startsWith(key) && key.length > bestKey.length) {
816
+ bestKey = key;
817
+ bestRates = GEMINI_PRICING[key];
818
+ }
819
+ }
820
+ return bestRates;
821
+ }
822
+ function geminiPricingSource() {
823
+ return {
824
+ version: pricingVersion,
825
+ price(model, usage, tier) {
826
+ return computeCost(model, usage, tier, lookupRates, TIER_FACTOR, pricingVersion);
827
+ },
828
+ hasModel(model) {
829
+ return lookupRates(model) !== void 0;
830
+ },
831
+ listModels() {
832
+ return Object.keys(GEMINI_PRICING);
833
+ }
834
+ };
835
+ }
836
+ var Gemini25ProConfigSchema = z.union([
837
+ z.strictObject({
838
+ temperature: z.number().min(0).max(2).optional().meta({
839
+ title: "Temperature",
840
+ description: "Sampling temperature for gemini-2.5-pro.",
841
+ examples: [0.7]
842
+ }),
843
+ topP: z.number().min(0).max(1).optional().meta({
844
+ title: "Top P",
845
+ description: "Nucleus sampling probability for gemini-2.5-pro."
846
+ }),
847
+ topK: z.number().int().positive().optional().meta({
848
+ title: "Top K",
849
+ description: "Top-k sampling limit for gemini-2.5-pro."
850
+ }),
851
+ maxOutputTokens: z.number().int().positive().optional().meta({
852
+ title: "Max Output Tokens",
853
+ description: "Maximum output token cap for gemini-2.5-pro."
854
+ }),
855
+ stopSequences: z.array(z.string()).max(5).optional().meta({
856
+ title: "Stop Sequences",
857
+ description: "Up to five stop sequences for gemini-2.5-pro."
858
+ }),
859
+ serviceTier: z.literal("flex").meta({
860
+ title: "Service Tier",
861
+ description: "Explicit flex tier for gemini-2.5-pro."
862
+ }),
863
+ reasoning: z.union([
864
+ z.strictObject({
865
+ effort: z.enum(["low", "medium", "high"]).meta({
866
+ title: "Reasoning Effort",
867
+ description: "Reasoning effort for gemini-2.5-pro. Thinking off is not supported."
868
+ }),
869
+ includeThoughts: z.boolean().optional().meta({
870
+ title: "Include Thoughts",
871
+ description: "Return provider thought summaries when supported."
872
+ })
873
+ }),
874
+ z.strictObject({
875
+ budgetTokens: z.number().int().min(128).max(32768).meta({
876
+ title: "Reasoning Budget Tokens",
877
+ description: "thinkingBudget token range for gemini-2.5-pro."
878
+ }),
879
+ includeThoughts: z.boolean().optional().meta({
880
+ title: "Include Thoughts",
881
+ description: "Return provider thought summaries when supported."
882
+ })
883
+ }),
884
+ z.strictObject({
885
+ includeThoughts: z.boolean().meta({
886
+ title: "Include Thoughts",
887
+ description: "Return provider thought summaries when supported."
888
+ })
889
+ })
890
+ ]).optional().meta({
891
+ title: "Reasoning",
892
+ description: "Gemini 2.5 Pro thinkingBudget configuration."
893
+ }),
894
+ timeoutMs: z.number().int().positive().optional().meta({
895
+ title: "Timeout",
896
+ description: "Logical request timeout in milliseconds."
897
+ }),
898
+ providerOptions: z.strictObject({
899
+ google: z.strictObject({
900
+ cachedContent: z.string().min(1).optional().meta({
901
+ title: "Cached Content",
902
+ description: "Google cached content resource name."
903
+ }),
904
+ safetySettings: z.array(
905
+ z.strictObject({
906
+ category: z.string().min(1).meta({
907
+ title: "Safety Category",
908
+ description: "Google safety category identifier."
909
+ }),
910
+ threshold: z.string().min(1).meta({
911
+ title: "Safety Threshold",
912
+ description: "Google safety threshold identifier."
913
+ })
914
+ })
915
+ ).optional().meta({
916
+ title: "Safety Settings",
917
+ description: "Allowlisted Google safety settings."
918
+ }),
919
+ tools: z.array(
920
+ z.strictObject({
921
+ googleSearch: z.strictObject({}).meta({
922
+ title: "Google Search",
923
+ description: "Google Search grounding tool."
924
+ })
925
+ })
926
+ ).min(1).optional().meta({
927
+ title: "Tools",
928
+ description: "Allowlisted Google tools for gemini-2.5-pro."
929
+ }),
930
+ httpOptions: z.strictObject({
931
+ timeout: z.number().int().positive().optional().meta({
932
+ title: "HTTP Timeout",
933
+ description: "Per-request Google transport timeout in milliseconds."
934
+ })
935
+ }).optional().meta({
936
+ title: "HTTP Options",
937
+ description: "Allowlisted Google transport options."
938
+ }),
939
+ flexFallback: z.boolean().optional().meta({
940
+ title: "Flex Fallback",
941
+ description: "Allow provider fallback from flex when flex was explicitly selected."
942
+ })
943
+ }).optional().meta({
944
+ title: "Google Provider Options",
945
+ description: "Allowlisted Google provider options for gemini-2.5-pro."
946
+ })
947
+ }).optional().meta({
948
+ title: "Provider Options",
949
+ description: "Provider-specific options accepted for gemini-2.5-pro."
950
+ })
951
+ }),
952
+ z.strictObject({
953
+ temperature: z.number().min(0).max(2).optional().meta({
954
+ title: "Temperature",
955
+ description: "Sampling temperature for gemini-2.5-pro.",
956
+ examples: [0.7]
957
+ }),
958
+ topP: z.number().min(0).max(1).optional().meta({
959
+ title: "Top P",
960
+ description: "Nucleus sampling probability for gemini-2.5-pro."
961
+ }),
962
+ topK: z.number().int().positive().optional().meta({
963
+ title: "Top K",
964
+ description: "Top-k sampling limit for gemini-2.5-pro."
965
+ }),
966
+ maxOutputTokens: z.number().int().positive().optional().meta({
967
+ title: "Max Output Tokens",
968
+ description: "Maximum output token cap for gemini-2.5-pro."
969
+ }),
970
+ stopSequences: z.array(z.string()).max(5).optional().meta({
971
+ title: "Stop Sequences",
972
+ description: "Up to five stop sequences for gemini-2.5-pro."
973
+ }),
974
+ serviceTier: z.literal("standard").optional().meta({
975
+ title: "Service Tier",
976
+ description: "Standard tier or omitted tier for gemini-2.5-pro."
977
+ }),
978
+ reasoning: z.union([
979
+ z.strictObject({
980
+ effort: z.enum(["low", "medium", "high"]).meta({
981
+ title: "Reasoning Effort",
982
+ description: "Reasoning effort for gemini-2.5-pro. Thinking off is not supported."
983
+ }),
984
+ includeThoughts: z.boolean().optional().meta({
985
+ title: "Include Thoughts",
986
+ description: "Return provider thought summaries when supported."
987
+ })
988
+ }),
989
+ z.strictObject({
990
+ budgetTokens: z.number().int().min(128).max(32768).meta({
991
+ title: "Reasoning Budget Tokens",
992
+ description: "thinkingBudget token range for gemini-2.5-pro."
993
+ }),
994
+ includeThoughts: z.boolean().optional().meta({
995
+ title: "Include Thoughts",
996
+ description: "Return provider thought summaries when supported."
997
+ })
998
+ }),
999
+ z.strictObject({
1000
+ includeThoughts: z.boolean().meta({
1001
+ title: "Include Thoughts",
1002
+ description: "Return provider thought summaries when supported."
1003
+ })
1004
+ })
1005
+ ]).optional().meta({
1006
+ title: "Reasoning",
1007
+ description: "Gemini 2.5 Pro thinkingBudget configuration."
1008
+ }),
1009
+ timeoutMs: z.number().int().positive().optional().meta({
1010
+ title: "Timeout",
1011
+ description: "Logical request timeout in milliseconds."
1012
+ }),
1013
+ providerOptions: z.strictObject({
1014
+ google: z.strictObject({
1015
+ cachedContent: z.string().min(1).optional().meta({
1016
+ title: "Cached Content",
1017
+ description: "Google cached content resource name."
1018
+ }),
1019
+ safetySettings: z.array(
1020
+ z.strictObject({
1021
+ category: z.string().min(1).meta({
1022
+ title: "Safety Category",
1023
+ description: "Google safety category identifier."
1024
+ }),
1025
+ threshold: z.string().min(1).meta({
1026
+ title: "Safety Threshold",
1027
+ description: "Google safety threshold identifier."
1028
+ })
1029
+ })
1030
+ ).optional().meta({
1031
+ title: "Safety Settings",
1032
+ description: "Allowlisted Google safety settings."
1033
+ }),
1034
+ tools: z.array(
1035
+ z.strictObject({
1036
+ googleSearch: z.strictObject({}).meta({
1037
+ title: "Google Search",
1038
+ description: "Google Search grounding tool."
1039
+ })
1040
+ })
1041
+ ).min(1).optional().meta({
1042
+ title: "Tools",
1043
+ description: "Allowlisted Google tools for gemini-2.5-pro."
1044
+ }),
1045
+ httpOptions: z.strictObject({
1046
+ timeout: z.number().int().positive().optional().meta({
1047
+ title: "HTTP Timeout",
1048
+ description: "Per-request Google transport timeout in milliseconds."
1049
+ })
1050
+ }).optional().meta({
1051
+ title: "HTTP Options",
1052
+ description: "Allowlisted Google transport options."
1053
+ })
1054
+ }).optional().meta({
1055
+ title: "Google Provider Options",
1056
+ description: "Allowlisted Google provider options for gemini-2.5-pro."
1057
+ })
1058
+ }).optional().meta({
1059
+ title: "Provider Options",
1060
+ description: "Provider-specific options accepted for gemini-2.5-pro."
1061
+ })
1062
+ })
1063
+ ]).meta({
1064
+ title: "Gemini25ProConfig",
1065
+ description: "Strict generateContent config for model gemini-2.5-pro. Budget reasoning, tunable sampling, flex/standard tiers, structured output, grounding, priced.",
1066
+ examples: [{ serviceTier: "flex", temperature: 0.7, reasoning: { effort: "high" } }]
1067
+ });
1068
+ var Gemini25FlashConfigSchema = z.union([
1069
+ z.strictObject({
1070
+ temperature: z.number().min(0).max(2).optional().meta({
1071
+ title: "Temperature",
1072
+ description: "Sampling temperature for gemini-2.5-flash.",
1073
+ examples: [0.7]
1074
+ }),
1075
+ topP: z.number().min(0).max(1).optional().meta({
1076
+ title: "Top P",
1077
+ description: "Nucleus sampling probability for gemini-2.5-flash."
1078
+ }),
1079
+ topK: z.number().int().positive().optional().meta({
1080
+ title: "Top K",
1081
+ description: "Top-k sampling limit for gemini-2.5-flash."
1082
+ }),
1083
+ maxOutputTokens: z.number().int().positive().optional().meta({
1084
+ title: "Max Output Tokens",
1085
+ description: "Maximum output token cap for gemini-2.5-flash."
1086
+ }),
1087
+ stopSequences: z.array(z.string()).max(5).optional().meta({
1088
+ title: "Stop Sequences",
1089
+ description: "Up to five stop sequences for gemini-2.5-flash."
1090
+ }),
1091
+ serviceTier: z.literal("flex").meta({
1092
+ title: "Service Tier",
1093
+ description: "Explicit flex tier for gemini-2.5-flash."
1094
+ }),
1095
+ reasoning: z.union([
1096
+ z.strictObject({
1097
+ effort: z.enum(["none", "low", "medium", "high"]).meta({
1098
+ title: "Reasoning Effort",
1099
+ description: "Reasoning effort for gemini-2.5-flash."
1100
+ }),
1101
+ includeThoughts: z.boolean().optional().meta({
1102
+ title: "Include Thoughts",
1103
+ description: "Return provider thought summaries when supported."
1104
+ })
1105
+ }),
1106
+ z.strictObject({
1107
+ budgetTokens: z.number().int().min(0).max(24576).meta({
1108
+ title: "Reasoning Budget Tokens",
1109
+ description: "thinkingBudget token range for gemini-2.5-flash."
1110
+ }),
1111
+ includeThoughts: z.boolean().optional().meta({
1112
+ title: "Include Thoughts",
1113
+ description: "Return provider thought summaries when supported."
1114
+ })
1115
+ }),
1116
+ z.strictObject({
1117
+ includeThoughts: z.boolean().meta({
1118
+ title: "Include Thoughts",
1119
+ description: "Return provider thought summaries when supported."
1120
+ })
1121
+ })
1122
+ ]).optional().meta({
1123
+ title: "Reasoning",
1124
+ description: "Gemini 2.5 Flash thinkingBudget configuration."
1125
+ }),
1126
+ timeoutMs: z.number().int().positive().optional().meta({
1127
+ title: "Timeout",
1128
+ description: "Logical request timeout in milliseconds."
1129
+ }),
1130
+ providerOptions: z.strictObject({
1131
+ google: z.strictObject({
1132
+ cachedContent: z.string().min(1).optional().meta({
1133
+ title: "Cached Content",
1134
+ description: "Google cached content resource name."
1135
+ }),
1136
+ safetySettings: z.array(
1137
+ z.strictObject({
1138
+ category: z.string().min(1).meta({
1139
+ title: "Safety Category",
1140
+ description: "Google safety category identifier."
1141
+ }),
1142
+ threshold: z.string().min(1).meta({
1143
+ title: "Safety Threshold",
1144
+ description: "Google safety threshold identifier."
1145
+ })
1146
+ })
1147
+ ).optional().meta({
1148
+ title: "Safety Settings",
1149
+ description: "Allowlisted Google safety settings."
1150
+ }),
1151
+ tools: z.array(
1152
+ z.strictObject({
1153
+ googleSearch: z.strictObject({}).meta({
1154
+ title: "Google Search",
1155
+ description: "Google Search grounding tool."
1156
+ })
1157
+ })
1158
+ ).min(1).optional().meta({
1159
+ title: "Tools",
1160
+ description: "Allowlisted Google tools for gemini-2.5-flash."
1161
+ }),
1162
+ httpOptions: z.strictObject({
1163
+ timeout: z.number().int().positive().optional().meta({
1164
+ title: "HTTP Timeout",
1165
+ description: "Per-request Google transport timeout in milliseconds."
1166
+ })
1167
+ }).optional().meta({
1168
+ title: "HTTP Options",
1169
+ description: "Allowlisted Google transport options."
1170
+ }),
1171
+ flexFallback: z.boolean().optional().meta({
1172
+ title: "Flex Fallback",
1173
+ description: "Allow provider fallback from flex when flex was explicitly selected."
1174
+ })
1175
+ }).optional().meta({
1176
+ title: "Google Provider Options",
1177
+ description: "Allowlisted Google provider options for gemini-2.5-flash."
1178
+ })
1179
+ }).optional().meta({
1180
+ title: "Provider Options",
1181
+ description: "Provider-specific options accepted for gemini-2.5-flash."
1182
+ })
1183
+ }),
1184
+ z.strictObject({
1185
+ temperature: z.number().min(0).max(2).optional().meta({
1186
+ title: "Temperature",
1187
+ description: "Sampling temperature for gemini-2.5-flash.",
1188
+ examples: [0.7]
1189
+ }),
1190
+ topP: z.number().min(0).max(1).optional().meta({
1191
+ title: "Top P",
1192
+ description: "Nucleus sampling probability for gemini-2.5-flash."
1193
+ }),
1194
+ topK: z.number().int().positive().optional().meta({
1195
+ title: "Top K",
1196
+ description: "Top-k sampling limit for gemini-2.5-flash."
1197
+ }),
1198
+ maxOutputTokens: z.number().int().positive().optional().meta({
1199
+ title: "Max Output Tokens",
1200
+ description: "Maximum output token cap for gemini-2.5-flash."
1201
+ }),
1202
+ stopSequences: z.array(z.string()).max(5).optional().meta({
1203
+ title: "Stop Sequences",
1204
+ description: "Up to five stop sequences for gemini-2.5-flash."
1205
+ }),
1206
+ serviceTier: z.literal("standard").optional().meta({
1207
+ title: "Service Tier",
1208
+ description: "Standard tier or omitted tier for gemini-2.5-flash."
1209
+ }),
1210
+ reasoning: z.union([
1211
+ z.strictObject({
1212
+ effort: z.enum(["none", "low", "medium", "high"]).meta({
1213
+ title: "Reasoning Effort",
1214
+ description: "Reasoning effort for gemini-2.5-flash."
1215
+ }),
1216
+ includeThoughts: z.boolean().optional().meta({
1217
+ title: "Include Thoughts",
1218
+ description: "Return provider thought summaries when supported."
1219
+ })
1220
+ }),
1221
+ z.strictObject({
1222
+ budgetTokens: z.number().int().min(0).max(24576).meta({
1223
+ title: "Reasoning Budget Tokens",
1224
+ description: "thinkingBudget token range for gemini-2.5-flash."
1225
+ }),
1226
+ includeThoughts: z.boolean().optional().meta({
1227
+ title: "Include Thoughts",
1228
+ description: "Return provider thought summaries when supported."
1229
+ })
1230
+ }),
1231
+ z.strictObject({
1232
+ includeThoughts: z.boolean().meta({
1233
+ title: "Include Thoughts",
1234
+ description: "Return provider thought summaries when supported."
1235
+ })
1236
+ })
1237
+ ]).optional().meta({
1238
+ title: "Reasoning",
1239
+ description: "Gemini 2.5 Flash thinkingBudget configuration."
1240
+ }),
1241
+ timeoutMs: z.number().int().positive().optional().meta({
1242
+ title: "Timeout",
1243
+ description: "Logical request timeout in milliseconds."
1244
+ }),
1245
+ providerOptions: z.strictObject({
1246
+ google: z.strictObject({
1247
+ cachedContent: z.string().min(1).optional().meta({
1248
+ title: "Cached Content",
1249
+ description: "Google cached content resource name."
1250
+ }),
1251
+ safetySettings: z.array(
1252
+ z.strictObject({
1253
+ category: z.string().min(1).meta({
1254
+ title: "Safety Category",
1255
+ description: "Google safety category identifier."
1256
+ }),
1257
+ threshold: z.string().min(1).meta({
1258
+ title: "Safety Threshold",
1259
+ description: "Google safety threshold identifier."
1260
+ })
1261
+ })
1262
+ ).optional().meta({
1263
+ title: "Safety Settings",
1264
+ description: "Allowlisted Google safety settings."
1265
+ }),
1266
+ tools: z.array(
1267
+ z.strictObject({
1268
+ googleSearch: z.strictObject({}).meta({
1269
+ title: "Google Search",
1270
+ description: "Google Search grounding tool."
1271
+ })
1272
+ })
1273
+ ).min(1).optional().meta({
1274
+ title: "Tools",
1275
+ description: "Allowlisted Google tools for gemini-2.5-flash."
1276
+ }),
1277
+ httpOptions: z.strictObject({
1278
+ timeout: z.number().int().positive().optional().meta({
1279
+ title: "HTTP Timeout",
1280
+ description: "Per-request Google transport timeout in milliseconds."
1281
+ })
1282
+ }).optional().meta({
1283
+ title: "HTTP Options",
1284
+ description: "Allowlisted Google transport options."
1285
+ })
1286
+ }).optional().meta({
1287
+ title: "Google Provider Options",
1288
+ description: "Allowlisted Google provider options for gemini-2.5-flash."
1289
+ })
1290
+ }).optional().meta({
1291
+ title: "Provider Options",
1292
+ description: "Provider-specific options accepted for gemini-2.5-flash."
1293
+ })
1294
+ })
1295
+ ]).meta({
1296
+ title: "Gemini25FlashConfig",
1297
+ description: "Strict generateContent config for model gemini-2.5-flash. Budget reasoning, tunable sampling, flex/standard tiers, structured output, grounding, priced.",
1298
+ examples: [{ serviceTier: "flex", temperature: 0.7, reasoning: { effort: "none" } }]
1299
+ });
1300
+ var Gemini25FlashLiteConfigSchema = z.union([
1301
+ z.strictObject({
1302
+ temperature: z.number().min(0).max(2).optional().meta({
1303
+ title: "Temperature",
1304
+ description: "Sampling temperature for gemini-2.5-flash-lite.",
1305
+ examples: [0.7]
1306
+ }),
1307
+ topP: z.number().min(0).max(1).optional().meta({
1308
+ title: "Top P",
1309
+ description: "Nucleus sampling probability for gemini-2.5-flash-lite."
1310
+ }),
1311
+ topK: z.number().int().positive().optional().meta({
1312
+ title: "Top K",
1313
+ description: "Top-k sampling limit for gemini-2.5-flash-lite."
1314
+ }),
1315
+ maxOutputTokens: z.number().int().positive().optional().meta({
1316
+ title: "Max Output Tokens",
1317
+ description: "Maximum output token cap for gemini-2.5-flash-lite."
1318
+ }),
1319
+ stopSequences: z.array(z.string()).max(5).optional().meta({
1320
+ title: "Stop Sequences",
1321
+ description: "Up to five stop sequences for gemini-2.5-flash-lite."
1322
+ }),
1323
+ serviceTier: z.literal("flex").meta({
1324
+ title: "Service Tier",
1325
+ description: "Explicit flex tier for gemini-2.5-flash-lite."
1326
+ }),
1327
+ reasoning: z.union([
1328
+ z.strictObject({
1329
+ effort: z.enum(["none", "low", "medium", "high"]).meta({
1330
+ title: "Reasoning Effort",
1331
+ description: "Reasoning effort for gemini-2.5-flash-lite."
1332
+ }),
1333
+ includeThoughts: z.boolean().optional().meta({
1334
+ title: "Include Thoughts",
1335
+ description: "Return provider thought summaries when supported."
1336
+ })
1337
+ }),
1338
+ z.strictObject({
1339
+ budgetTokens: z.union([z.literal(0), z.number().int().min(512).max(24576)]).meta({
1340
+ title: "Reasoning Budget Tokens",
1341
+ description: "thinkingBudget token range for gemini-2.5-flash-lite. Zero disables thinking; non-zero values must be 512..24576."
1342
+ }),
1343
+ includeThoughts: z.boolean().optional().meta({
1344
+ title: "Include Thoughts",
1345
+ description: "Return provider thought summaries when supported."
1346
+ })
1347
+ }),
1348
+ z.strictObject({
1349
+ includeThoughts: z.boolean().meta({
1350
+ title: "Include Thoughts",
1351
+ description: "Return provider thought summaries when supported."
1352
+ })
1353
+ })
1354
+ ]).optional().meta({
1355
+ title: "Reasoning",
1356
+ description: "Gemini 2.5 Flash-Lite thinkingBudget configuration."
1357
+ }),
1358
+ timeoutMs: z.number().int().positive().optional().meta({
1359
+ title: "Timeout",
1360
+ description: "Logical request timeout in milliseconds."
1361
+ }),
1362
+ providerOptions: z.strictObject({
1363
+ google: z.strictObject({
1364
+ cachedContent: z.string().min(1).optional().meta({
1365
+ title: "Cached Content",
1366
+ description: "Google cached content resource name."
1367
+ }),
1368
+ safetySettings: z.array(
1369
+ z.strictObject({
1370
+ category: z.string().min(1).meta({
1371
+ title: "Safety Category",
1372
+ description: "Google safety category identifier."
1373
+ }),
1374
+ threshold: z.string().min(1).meta({
1375
+ title: "Safety Threshold",
1376
+ description: "Google safety threshold identifier."
1377
+ })
1378
+ })
1379
+ ).optional().meta({
1380
+ title: "Safety Settings",
1381
+ description: "Allowlisted Google safety settings."
1382
+ }),
1383
+ tools: z.array(
1384
+ z.strictObject({
1385
+ googleSearch: z.strictObject({}).meta({
1386
+ title: "Google Search",
1387
+ description: "Google Search grounding tool."
1388
+ })
1389
+ })
1390
+ ).min(1).optional().meta({
1391
+ title: "Tools",
1392
+ description: "Allowlisted Google tools for gemini-2.5-flash-lite."
1393
+ }),
1394
+ httpOptions: z.strictObject({
1395
+ timeout: z.number().int().positive().optional().meta({
1396
+ title: "HTTP Timeout",
1397
+ description: "Per-request Google transport timeout in milliseconds."
1398
+ })
1399
+ }).optional().meta({
1400
+ title: "HTTP Options",
1401
+ description: "Allowlisted Google transport options."
1402
+ }),
1403
+ flexFallback: z.boolean().optional().meta({
1404
+ title: "Flex Fallback",
1405
+ description: "Allow provider fallback from flex when flex was explicitly selected."
1406
+ })
1407
+ }).optional().meta({
1408
+ title: "Google Provider Options",
1409
+ description: "Allowlisted Google provider options for gemini-2.5-flash-lite."
1410
+ })
1411
+ }).optional().meta({
1412
+ title: "Provider Options",
1413
+ description: "Provider-specific options accepted for gemini-2.5-flash-lite."
1414
+ })
1415
+ }),
1416
+ z.strictObject({
1417
+ temperature: z.number().min(0).max(2).optional().meta({
1418
+ title: "Temperature",
1419
+ description: "Sampling temperature for gemini-2.5-flash-lite.",
1420
+ examples: [0.7]
1421
+ }),
1422
+ topP: z.number().min(0).max(1).optional().meta({
1423
+ title: "Top P",
1424
+ description: "Nucleus sampling probability for gemini-2.5-flash-lite."
1425
+ }),
1426
+ topK: z.number().int().positive().optional().meta({
1427
+ title: "Top K",
1428
+ description: "Top-k sampling limit for gemini-2.5-flash-lite."
1429
+ }),
1430
+ maxOutputTokens: z.number().int().positive().optional().meta({
1431
+ title: "Max Output Tokens",
1432
+ description: "Maximum output token cap for gemini-2.5-flash-lite."
1433
+ }),
1434
+ stopSequences: z.array(z.string()).max(5).optional().meta({
1435
+ title: "Stop Sequences",
1436
+ description: "Up to five stop sequences for gemini-2.5-flash-lite."
1437
+ }),
1438
+ serviceTier: z.literal("standard").optional().meta({
1439
+ title: "Service Tier",
1440
+ description: "Standard tier or omitted tier for gemini-2.5-flash-lite."
1441
+ }),
1442
+ reasoning: z.union([
1443
+ z.strictObject({
1444
+ effort: z.enum(["none", "low", "medium", "high"]).meta({
1445
+ title: "Reasoning Effort",
1446
+ description: "Reasoning effort for gemini-2.5-flash-lite."
1447
+ }),
1448
+ includeThoughts: z.boolean().optional().meta({
1449
+ title: "Include Thoughts",
1450
+ description: "Return provider thought summaries when supported."
1451
+ })
1452
+ }),
1453
+ z.strictObject({
1454
+ budgetTokens: z.union([z.literal(0), z.number().int().min(512).max(24576)]).meta({
1455
+ title: "Reasoning Budget Tokens",
1456
+ description: "thinkingBudget token range for gemini-2.5-flash-lite. Zero disables thinking; non-zero values must be 512..24576."
1457
+ }),
1458
+ includeThoughts: z.boolean().optional().meta({
1459
+ title: "Include Thoughts",
1460
+ description: "Return provider thought summaries when supported."
1461
+ })
1462
+ }),
1463
+ z.strictObject({
1464
+ includeThoughts: z.boolean().meta({
1465
+ title: "Include Thoughts",
1466
+ description: "Return provider thought summaries when supported."
1467
+ })
1468
+ })
1469
+ ]).optional().meta({
1470
+ title: "Reasoning",
1471
+ description: "Gemini 2.5 Flash-Lite thinkingBudget configuration."
1472
+ }),
1473
+ timeoutMs: z.number().int().positive().optional().meta({
1474
+ title: "Timeout",
1475
+ description: "Logical request timeout in milliseconds."
1476
+ }),
1477
+ providerOptions: z.strictObject({
1478
+ google: z.strictObject({
1479
+ cachedContent: z.string().min(1).optional().meta({
1480
+ title: "Cached Content",
1481
+ description: "Google cached content resource name."
1482
+ }),
1483
+ safetySettings: z.array(
1484
+ z.strictObject({
1485
+ category: z.string().min(1).meta({
1486
+ title: "Safety Category",
1487
+ description: "Google safety category identifier."
1488
+ }),
1489
+ threshold: z.string().min(1).meta({
1490
+ title: "Safety Threshold",
1491
+ description: "Google safety threshold identifier."
1492
+ })
1493
+ })
1494
+ ).optional().meta({
1495
+ title: "Safety Settings",
1496
+ description: "Allowlisted Google safety settings."
1497
+ }),
1498
+ tools: z.array(
1499
+ z.strictObject({
1500
+ googleSearch: z.strictObject({}).meta({
1501
+ title: "Google Search",
1502
+ description: "Google Search grounding tool."
1503
+ })
1504
+ })
1505
+ ).min(1).optional().meta({
1506
+ title: "Tools",
1507
+ description: "Allowlisted Google tools for gemini-2.5-flash-lite."
1508
+ }),
1509
+ httpOptions: z.strictObject({
1510
+ timeout: z.number().int().positive().optional().meta({
1511
+ title: "HTTP Timeout",
1512
+ description: "Per-request Google transport timeout in milliseconds."
1513
+ })
1514
+ }).optional().meta({
1515
+ title: "HTTP Options",
1516
+ description: "Allowlisted Google transport options."
1517
+ })
1518
+ }).optional().meta({
1519
+ title: "Google Provider Options",
1520
+ description: "Allowlisted Google provider options for gemini-2.5-flash-lite."
1521
+ })
1522
+ }).optional().meta({
1523
+ title: "Provider Options",
1524
+ description: "Provider-specific options accepted for gemini-2.5-flash-lite."
1525
+ })
1526
+ })
1527
+ ]).meta({
1528
+ title: "Gemini25FlashLiteConfig",
1529
+ description: "Strict generateContent config for model gemini-2.5-flash-lite. Budget reasoning, tunable sampling, flex/standard tiers, structured output, grounding, priced.",
1530
+ examples: [{ serviceTier: "flex", temperature: 0.7, reasoning: { budgetTokens: 0 } }]
1531
+ });
1532
+ var Gemini35FlashConfigSchema = z.union([
1533
+ z.strictObject({
1534
+ maxOutputTokens: z.number().int().positive().optional().meta({
1535
+ title: "Max Output Tokens",
1536
+ description: "Maximum output token cap for gemini-3.5-flash."
1537
+ }),
1538
+ stopSequences: z.array(z.string()).max(5).optional().meta({
1539
+ title: "Stop Sequences",
1540
+ description: "Up to five stop sequences for gemini-3.5-flash."
1541
+ }),
1542
+ serviceTier: z.literal("flex").meta({
1543
+ title: "Service Tier",
1544
+ description: "Explicit flex tier for gemini-3.5-flash."
1545
+ }),
1546
+ reasoning: z.union([
1547
+ z.strictObject({
1548
+ effort: z.enum(["none", "low", "medium", "high"]).meta({
1549
+ title: "Reasoning Effort",
1550
+ description: "Reasoning effort for gemini-3.5-flash; none maps to minimal thinking."
1551
+ }),
1552
+ includeThoughts: z.boolean().optional().meta({
1553
+ title: "Include Thoughts",
1554
+ description: "Return provider thought summaries when supported."
1555
+ })
1556
+ }),
1557
+ z.strictObject({
1558
+ includeThoughts: z.boolean().meta({
1559
+ title: "Include Thoughts",
1560
+ description: "Return provider thought summaries when supported."
1561
+ })
1562
+ })
1563
+ ]).optional().meta({
1564
+ title: "Reasoning",
1565
+ description: "Gemini 3.5 Flash thinkingLevel configuration."
1566
+ }),
1567
+ timeoutMs: z.number().int().positive().optional().meta({
1568
+ title: "Timeout",
1569
+ description: "Logical request timeout in milliseconds."
1570
+ }),
1571
+ providerOptions: z.strictObject({
1572
+ google: z.strictObject({
1573
+ cachedContent: z.string().min(1).optional().meta({
1574
+ title: "Cached Content",
1575
+ description: "Google cached content resource name."
1576
+ }),
1577
+ safetySettings: z.array(
1578
+ z.strictObject({
1579
+ category: z.string().min(1).meta({
1580
+ title: "Safety Category",
1581
+ description: "Google safety category identifier."
1582
+ }),
1583
+ threshold: z.string().min(1).meta({
1584
+ title: "Safety Threshold",
1585
+ description: "Google safety threshold identifier."
1586
+ })
1587
+ })
1588
+ ).optional().meta({
1589
+ title: "Safety Settings",
1590
+ description: "Allowlisted Google safety settings."
1591
+ }),
1592
+ tools: z.array(
1593
+ z.strictObject({
1594
+ googleSearch: z.strictObject({}).meta({
1595
+ title: "Google Search",
1596
+ description: "Google Search grounding tool."
1597
+ })
1598
+ })
1599
+ ).min(1).optional().meta({
1600
+ title: "Tools",
1601
+ description: "Allowlisted Google tools for gemini-3.5-flash."
1602
+ }),
1603
+ httpOptions: z.strictObject({
1604
+ timeout: z.number().int().positive().optional().meta({
1605
+ title: "HTTP Timeout",
1606
+ description: "Per-request Google transport timeout in milliseconds."
1607
+ })
1608
+ }).optional().meta({
1609
+ title: "HTTP Options",
1610
+ description: "Allowlisted Google transport options."
1611
+ }),
1612
+ flexFallback: z.boolean().optional().meta({
1613
+ title: "Flex Fallback",
1614
+ description: "Allow provider fallback from flex when flex was explicitly selected."
1615
+ })
1616
+ }).optional().meta({
1617
+ title: "Google Provider Options",
1618
+ description: "Allowlisted Google provider options for gemini-3.5-flash."
1619
+ })
1620
+ }).optional().meta({
1621
+ title: "Provider Options",
1622
+ description: "Provider-specific options accepted for gemini-3.5-flash."
1623
+ })
1624
+ }),
1625
+ z.strictObject({
1626
+ maxOutputTokens: z.number().int().positive().optional().meta({
1627
+ title: "Max Output Tokens",
1628
+ description: "Maximum output token cap for gemini-3.5-flash."
1629
+ }),
1630
+ stopSequences: z.array(z.string()).max(5).optional().meta({
1631
+ title: "Stop Sequences",
1632
+ description: "Up to five stop sequences for gemini-3.5-flash."
1633
+ }),
1634
+ serviceTier: z.literal("standard").optional().meta({
1635
+ title: "Service Tier",
1636
+ description: "Standard tier or omitted tier for gemini-3.5-flash."
1637
+ }),
1638
+ reasoning: z.union([
1639
+ z.strictObject({
1640
+ effort: z.enum(["none", "low", "medium", "high"]).meta({
1641
+ title: "Reasoning Effort",
1642
+ description: "Reasoning effort for gemini-3.5-flash; none maps to minimal thinking."
1643
+ }),
1644
+ includeThoughts: z.boolean().optional().meta({
1645
+ title: "Include Thoughts",
1646
+ description: "Return provider thought summaries when supported."
1647
+ })
1648
+ }),
1649
+ z.strictObject({
1650
+ includeThoughts: z.boolean().meta({
1651
+ title: "Include Thoughts",
1652
+ description: "Return provider thought summaries when supported."
1653
+ })
1654
+ })
1655
+ ]).optional().meta({
1656
+ title: "Reasoning",
1657
+ description: "Gemini 3.5 Flash thinkingLevel configuration."
1658
+ }),
1659
+ timeoutMs: z.number().int().positive().optional().meta({
1660
+ title: "Timeout",
1661
+ description: "Logical request timeout in milliseconds."
1662
+ }),
1663
+ providerOptions: z.strictObject({
1664
+ google: z.strictObject({
1665
+ cachedContent: z.string().min(1).optional().meta({
1666
+ title: "Cached Content",
1667
+ description: "Google cached content resource name."
1668
+ }),
1669
+ safetySettings: z.array(
1670
+ z.strictObject({
1671
+ category: z.string().min(1).meta({
1672
+ title: "Safety Category",
1673
+ description: "Google safety category identifier."
1674
+ }),
1675
+ threshold: z.string().min(1).meta({
1676
+ title: "Safety Threshold",
1677
+ description: "Google safety threshold identifier."
1678
+ })
1679
+ })
1680
+ ).optional().meta({
1681
+ title: "Safety Settings",
1682
+ description: "Allowlisted Google safety settings."
1683
+ }),
1684
+ tools: z.array(
1685
+ z.strictObject({
1686
+ googleSearch: z.strictObject({}).meta({
1687
+ title: "Google Search",
1688
+ description: "Google Search grounding tool."
1689
+ })
1690
+ })
1691
+ ).min(1).optional().meta({
1692
+ title: "Tools",
1693
+ description: "Allowlisted Google tools for gemini-3.5-flash."
1694
+ }),
1695
+ httpOptions: z.strictObject({
1696
+ timeout: z.number().int().positive().optional().meta({
1697
+ title: "HTTP Timeout",
1698
+ description: "Per-request Google transport timeout in milliseconds."
1699
+ })
1700
+ }).optional().meta({
1701
+ title: "HTTP Options",
1702
+ description: "Allowlisted Google transport options."
1703
+ })
1704
+ }).optional().meta({
1705
+ title: "Google Provider Options",
1706
+ description: "Allowlisted Google provider options for gemini-3.5-flash."
1707
+ })
1708
+ }).optional().meta({
1709
+ title: "Provider Options",
1710
+ description: "Provider-specific options accepted for gemini-3.5-flash."
1711
+ })
1712
+ })
1713
+ ]).meta({
1714
+ title: "Gemini35FlashConfig",
1715
+ description: "Strict generateContent config for model gemini-3.5-flash. Level reasoning, fixed sampling, flex/standard tiers, structured output, grounding, priced.",
1716
+ examples: [{ serviceTier: "flex", reasoning: { effort: "high" } }]
1717
+ });
1718
+ var Gemini31FlashLiteConfigSchema = z.union([
1719
+ z.strictObject({
1720
+ maxOutputTokens: z.number().int().positive().optional().meta({
1721
+ title: "Max Output Tokens",
1722
+ description: "Maximum output token cap for gemini-3.1-flash-lite."
1723
+ }),
1724
+ stopSequences: z.array(z.string()).max(5).optional().meta({
1725
+ title: "Stop Sequences",
1726
+ description: "Up to five stop sequences for gemini-3.1-flash-lite."
1727
+ }),
1728
+ serviceTier: z.literal("flex").meta({
1729
+ title: "Service Tier",
1730
+ description: "Explicit flex tier for gemini-3.1-flash-lite."
1731
+ }),
1732
+ reasoning: z.union([
1733
+ z.strictObject({
1734
+ effort: z.enum(["none", "low", "medium", "high"]).meta({
1735
+ title: "Reasoning Effort",
1736
+ description: "Reasoning effort for gemini-3.1-flash-lite; none maps to minimal thinking."
1737
+ }),
1738
+ includeThoughts: z.boolean().optional().meta({
1739
+ title: "Include Thoughts",
1740
+ description: "Return provider thought summaries when supported."
1741
+ })
1742
+ }),
1743
+ z.strictObject({
1744
+ includeThoughts: z.boolean().meta({
1745
+ title: "Include Thoughts",
1746
+ description: "Return provider thought summaries when supported."
1747
+ })
1748
+ })
1749
+ ]).optional().meta({
1750
+ title: "Reasoning",
1751
+ description: "Gemini 3.1 Flash-Lite thinkingLevel configuration."
1752
+ }),
1753
+ timeoutMs: z.number().int().positive().optional().meta({
1754
+ title: "Timeout",
1755
+ description: "Logical request timeout in milliseconds."
1756
+ }),
1757
+ providerOptions: z.strictObject({
1758
+ google: z.strictObject({
1759
+ cachedContent: z.string().min(1).optional().meta({
1760
+ title: "Cached Content",
1761
+ description: "Google cached content resource name."
1762
+ }),
1763
+ safetySettings: z.array(
1764
+ z.strictObject({
1765
+ category: z.string().min(1).meta({
1766
+ title: "Safety Category",
1767
+ description: "Google safety category identifier."
1768
+ }),
1769
+ threshold: z.string().min(1).meta({
1770
+ title: "Safety Threshold",
1771
+ description: "Google safety threshold identifier."
1772
+ })
1773
+ })
1774
+ ).optional().meta({
1775
+ title: "Safety Settings",
1776
+ description: "Allowlisted Google safety settings."
1777
+ }),
1778
+ tools: z.array(
1779
+ z.strictObject({
1780
+ googleSearch: z.strictObject({}).meta({
1781
+ title: "Google Search",
1782
+ description: "Google Search grounding tool."
1783
+ })
1784
+ })
1785
+ ).min(1).optional().meta({
1786
+ title: "Tools",
1787
+ description: "Allowlisted Google tools for gemini-3.1-flash-lite."
1788
+ }),
1789
+ httpOptions: z.strictObject({
1790
+ timeout: z.number().int().positive().optional().meta({
1791
+ title: "HTTP Timeout",
1792
+ description: "Per-request Google transport timeout in milliseconds."
1793
+ })
1794
+ }).optional().meta({
1795
+ title: "HTTP Options",
1796
+ description: "Allowlisted Google transport options."
1797
+ }),
1798
+ flexFallback: z.boolean().optional().meta({
1799
+ title: "Flex Fallback",
1800
+ description: "Allow provider fallback from flex when flex was explicitly selected."
1801
+ })
1802
+ }).optional().meta({
1803
+ title: "Google Provider Options",
1804
+ description: "Allowlisted Google provider options for gemini-3.1-flash-lite."
1805
+ })
1806
+ }).optional().meta({
1807
+ title: "Provider Options",
1808
+ description: "Provider-specific options accepted for gemini-3.1-flash-lite."
1809
+ })
1810
+ }),
1811
+ z.strictObject({
1812
+ maxOutputTokens: z.number().int().positive().optional().meta({
1813
+ title: "Max Output Tokens",
1814
+ description: "Maximum output token cap for gemini-3.1-flash-lite."
1815
+ }),
1816
+ stopSequences: z.array(z.string()).max(5).optional().meta({
1817
+ title: "Stop Sequences",
1818
+ description: "Up to five stop sequences for gemini-3.1-flash-lite."
1819
+ }),
1820
+ serviceTier: z.literal("standard").optional().meta({
1821
+ title: "Service Tier",
1822
+ description: "Standard tier or omitted tier for gemini-3.1-flash-lite."
1823
+ }),
1824
+ reasoning: z.union([
1825
+ z.strictObject({
1826
+ effort: z.enum(["none", "low", "medium", "high"]).meta({
1827
+ title: "Reasoning Effort",
1828
+ description: "Reasoning effort for gemini-3.1-flash-lite; none maps to minimal thinking."
1829
+ }),
1830
+ includeThoughts: z.boolean().optional().meta({
1831
+ title: "Include Thoughts",
1832
+ description: "Return provider thought summaries when supported."
1833
+ })
1834
+ }),
1835
+ z.strictObject({
1836
+ includeThoughts: z.boolean().meta({
1837
+ title: "Include Thoughts",
1838
+ description: "Return provider thought summaries when supported."
1839
+ })
1840
+ })
1841
+ ]).optional().meta({
1842
+ title: "Reasoning",
1843
+ description: "Gemini 3.1 Flash-Lite thinkingLevel configuration."
1844
+ }),
1845
+ timeoutMs: z.number().int().positive().optional().meta({
1846
+ title: "Timeout",
1847
+ description: "Logical request timeout in milliseconds."
1848
+ }),
1849
+ providerOptions: z.strictObject({
1850
+ google: z.strictObject({
1851
+ cachedContent: z.string().min(1).optional().meta({
1852
+ title: "Cached Content",
1853
+ description: "Google cached content resource name."
1854
+ }),
1855
+ safetySettings: z.array(
1856
+ z.strictObject({
1857
+ category: z.string().min(1).meta({
1858
+ title: "Safety Category",
1859
+ description: "Google safety category identifier."
1860
+ }),
1861
+ threshold: z.string().min(1).meta({
1862
+ title: "Safety Threshold",
1863
+ description: "Google safety threshold identifier."
1864
+ })
1865
+ })
1866
+ ).optional().meta({
1867
+ title: "Safety Settings",
1868
+ description: "Allowlisted Google safety settings."
1869
+ }),
1870
+ tools: z.array(
1871
+ z.strictObject({
1872
+ googleSearch: z.strictObject({}).meta({
1873
+ title: "Google Search",
1874
+ description: "Google Search grounding tool."
1875
+ })
1876
+ })
1877
+ ).min(1).optional().meta({
1878
+ title: "Tools",
1879
+ description: "Allowlisted Google tools for gemini-3.1-flash-lite."
1880
+ }),
1881
+ httpOptions: z.strictObject({
1882
+ timeout: z.number().int().positive().optional().meta({
1883
+ title: "HTTP Timeout",
1884
+ description: "Per-request Google transport timeout in milliseconds."
1885
+ })
1886
+ }).optional().meta({
1887
+ title: "HTTP Options",
1888
+ description: "Allowlisted Google transport options."
1889
+ })
1890
+ }).optional().meta({
1891
+ title: "Google Provider Options",
1892
+ description: "Allowlisted Google provider options for gemini-3.1-flash-lite."
1893
+ })
1894
+ }).optional().meta({
1895
+ title: "Provider Options",
1896
+ description: "Provider-specific options accepted for gemini-3.1-flash-lite."
1897
+ })
1898
+ })
1899
+ ]).meta({
1900
+ title: "Gemini31FlashLiteConfig",
1901
+ description: "Strict generateContent config for model gemini-3.1-flash-lite. Level reasoning, fixed sampling, flex/standard tiers, structured output, grounding, priced.",
1902
+ examples: [{ serviceTier: "flex", reasoning: { effort: "medium" } }]
1903
+ });
1904
+ var Gemini31ProPreviewConfigSchema = z.union([
1905
+ z.strictObject({
1906
+ maxOutputTokens: z.number().int().positive().optional().meta({
1907
+ title: "Max Output Tokens",
1908
+ description: "Maximum output token cap for gemini-3.1-pro-preview."
1909
+ }),
1910
+ stopSequences: z.array(z.string()).max(5).optional().meta({
1911
+ title: "Stop Sequences",
1912
+ description: "Up to five stop sequences for gemini-3.1-pro-preview."
1913
+ }),
1914
+ serviceTier: z.literal("flex").meta({
1915
+ title: "Service Tier",
1916
+ description: "Explicit flex tier for gemini-3.1-pro-preview."
1917
+ }),
1918
+ reasoning: z.union([
1919
+ z.strictObject({
1920
+ effort: z.enum(["low", "medium", "high"]).meta({
1921
+ title: "Reasoning Effort",
1922
+ description: "Reasoning effort for gemini-3.1-pro-preview. Thinking off is not supported."
1923
+ }),
1924
+ includeThoughts: z.boolean().optional().meta({
1925
+ title: "Include Thoughts",
1926
+ description: "Return provider thought summaries when supported."
1927
+ })
1928
+ }),
1929
+ z.strictObject({
1930
+ includeThoughts: z.boolean().meta({
1931
+ title: "Include Thoughts",
1932
+ description: "Return provider thought summaries when supported."
1933
+ })
1934
+ })
1935
+ ]).optional().meta({
1936
+ title: "Reasoning",
1937
+ description: "Gemini 3.1 Pro Preview thinkingLevel configuration."
1938
+ }),
1939
+ timeoutMs: z.number().int().positive().optional().meta({
1940
+ title: "Timeout",
1941
+ description: "Logical request timeout in milliseconds."
1942
+ }),
1943
+ providerOptions: z.strictObject({
1944
+ google: z.strictObject({
1945
+ cachedContent: z.string().min(1).optional().meta({
1946
+ title: "Cached Content",
1947
+ description: "Google cached content resource name."
1948
+ }),
1949
+ safetySettings: z.array(
1950
+ z.strictObject({
1951
+ category: z.string().min(1).meta({
1952
+ title: "Safety Category",
1953
+ description: "Google safety category identifier."
1954
+ }),
1955
+ threshold: z.string().min(1).meta({
1956
+ title: "Safety Threshold",
1957
+ description: "Google safety threshold identifier."
1958
+ })
1959
+ })
1960
+ ).optional().meta({
1961
+ title: "Safety Settings",
1962
+ description: "Allowlisted Google safety settings."
1963
+ }),
1964
+ tools: z.array(
1965
+ z.strictObject({
1966
+ googleSearch: z.strictObject({}).meta({
1967
+ title: "Google Search",
1968
+ description: "Google Search grounding tool."
1969
+ })
1970
+ })
1971
+ ).min(1).optional().meta({
1972
+ title: "Tools",
1973
+ description: "Allowlisted Google tools for gemini-3.1-pro-preview."
1974
+ }),
1975
+ httpOptions: z.strictObject({
1976
+ timeout: z.number().int().positive().optional().meta({
1977
+ title: "HTTP Timeout",
1978
+ description: "Per-request Google transport timeout in milliseconds."
1979
+ })
1980
+ }).optional().meta({
1981
+ title: "HTTP Options",
1982
+ description: "Allowlisted Google transport options."
1983
+ }),
1984
+ flexFallback: z.boolean().optional().meta({
1985
+ title: "Flex Fallback",
1986
+ description: "Allow provider fallback from flex when flex was explicitly selected."
1987
+ })
1988
+ }).optional().meta({
1989
+ title: "Google Provider Options",
1990
+ description: "Allowlisted Google provider options for gemini-3.1-pro-preview."
1991
+ })
1992
+ }).optional().meta({
1993
+ title: "Provider Options",
1994
+ description: "Provider-specific options accepted for gemini-3.1-pro-preview."
1995
+ })
1996
+ }),
1997
+ z.strictObject({
1998
+ maxOutputTokens: z.number().int().positive().optional().meta({
1999
+ title: "Max Output Tokens",
2000
+ description: "Maximum output token cap for gemini-3.1-pro-preview."
2001
+ }),
2002
+ stopSequences: z.array(z.string()).max(5).optional().meta({
2003
+ title: "Stop Sequences",
2004
+ description: "Up to five stop sequences for gemini-3.1-pro-preview."
2005
+ }),
2006
+ serviceTier: z.literal("standard").optional().meta({
2007
+ title: "Service Tier",
2008
+ description: "Standard tier or omitted tier for gemini-3.1-pro-preview."
2009
+ }),
2010
+ reasoning: z.union([
2011
+ z.strictObject({
2012
+ effort: z.enum(["low", "medium", "high"]).meta({
2013
+ title: "Reasoning Effort",
2014
+ description: "Reasoning effort for gemini-3.1-pro-preview. Thinking off is not supported."
2015
+ }),
2016
+ includeThoughts: z.boolean().optional().meta({
2017
+ title: "Include Thoughts",
2018
+ description: "Return provider thought summaries when supported."
2019
+ })
2020
+ }),
2021
+ z.strictObject({
2022
+ includeThoughts: z.boolean().meta({
2023
+ title: "Include Thoughts",
2024
+ description: "Return provider thought summaries when supported."
2025
+ })
2026
+ })
2027
+ ]).optional().meta({
2028
+ title: "Reasoning",
2029
+ description: "Gemini 3.1 Pro Preview thinkingLevel configuration."
2030
+ }),
2031
+ timeoutMs: z.number().int().positive().optional().meta({
2032
+ title: "Timeout",
2033
+ description: "Logical request timeout in milliseconds."
2034
+ }),
2035
+ providerOptions: z.strictObject({
2036
+ google: z.strictObject({
2037
+ cachedContent: z.string().min(1).optional().meta({
2038
+ title: "Cached Content",
2039
+ description: "Google cached content resource name."
2040
+ }),
2041
+ safetySettings: z.array(
2042
+ z.strictObject({
2043
+ category: z.string().min(1).meta({
2044
+ title: "Safety Category",
2045
+ description: "Google safety category identifier."
2046
+ }),
2047
+ threshold: z.string().min(1).meta({
2048
+ title: "Safety Threshold",
2049
+ description: "Google safety threshold identifier."
2050
+ })
2051
+ })
2052
+ ).optional().meta({
2053
+ title: "Safety Settings",
2054
+ description: "Allowlisted Google safety settings."
2055
+ }),
2056
+ tools: z.array(
2057
+ z.strictObject({
2058
+ googleSearch: z.strictObject({}).meta({
2059
+ title: "Google Search",
2060
+ description: "Google Search grounding tool."
2061
+ })
2062
+ })
2063
+ ).min(1).optional().meta({
2064
+ title: "Tools",
2065
+ description: "Allowlisted Google tools for gemini-3.1-pro-preview."
2066
+ }),
2067
+ httpOptions: z.strictObject({
2068
+ timeout: z.number().int().positive().optional().meta({
2069
+ title: "HTTP Timeout",
2070
+ description: "Per-request Google transport timeout in milliseconds."
2071
+ })
2072
+ }).optional().meta({
2073
+ title: "HTTP Options",
2074
+ description: "Allowlisted Google transport options."
2075
+ })
2076
+ }).optional().meta({
2077
+ title: "Google Provider Options",
2078
+ description: "Allowlisted Google provider options for gemini-3.1-pro-preview."
2079
+ })
2080
+ }).optional().meta({
2081
+ title: "Provider Options",
2082
+ description: "Provider-specific options accepted for gemini-3.1-pro-preview."
2083
+ })
2084
+ })
2085
+ ]).meta({
2086
+ title: "Gemini31ProPreviewConfig",
2087
+ description: "Strict generateContent config for model gemini-3.1-pro-preview. Level reasoning, fixed sampling, flex/standard tiers, structured output, grounding, priced.",
2088
+ examples: [{ serviceTier: "flex", reasoning: { effort: "high" } }]
2089
+ });
2090
+ var Gemini3FlashPreviewConfigSchema = z.union([
2091
+ z.strictObject({
2092
+ maxOutputTokens: z.number().int().positive().optional().meta({
2093
+ title: "Max Output Tokens",
2094
+ description: "Maximum output token cap for gemini-3-flash-preview."
2095
+ }),
2096
+ stopSequences: z.array(z.string()).max(5).optional().meta({
2097
+ title: "Stop Sequences",
2098
+ description: "Up to five stop sequences for gemini-3-flash-preview."
2099
+ }),
2100
+ serviceTier: z.literal("flex").meta({
2101
+ title: "Service Tier",
2102
+ description: "Explicit flex tier for gemini-3-flash-preview."
2103
+ }),
2104
+ reasoning: z.union([
2105
+ z.strictObject({
2106
+ effort: z.enum(["none", "low", "medium", "high"]).meta({
2107
+ title: "Reasoning Effort",
2108
+ description: "Reasoning effort for gemini-3-flash-preview; none maps to minimal thinking."
2109
+ }),
2110
+ includeThoughts: z.boolean().optional().meta({
2111
+ title: "Include Thoughts",
2112
+ description: "Return provider thought summaries when supported."
2113
+ })
2114
+ }),
2115
+ z.strictObject({
2116
+ includeThoughts: z.boolean().meta({
2117
+ title: "Include Thoughts",
2118
+ description: "Return provider thought summaries when supported."
2119
+ })
2120
+ })
2121
+ ]).optional().meta({
2122
+ title: "Reasoning",
2123
+ description: "Gemini 3 Flash Preview thinkingLevel configuration."
2124
+ }),
2125
+ timeoutMs: z.number().int().positive().optional().meta({
2126
+ title: "Timeout",
2127
+ description: "Logical request timeout in milliseconds."
2128
+ }),
2129
+ providerOptions: z.strictObject({
2130
+ google: z.strictObject({
2131
+ cachedContent: z.string().min(1).optional().meta({
2132
+ title: "Cached Content",
2133
+ description: "Google cached content resource name."
2134
+ }),
2135
+ safetySettings: z.array(
2136
+ z.strictObject({
2137
+ category: z.string().min(1).meta({
2138
+ title: "Safety Category",
2139
+ description: "Google safety category identifier."
2140
+ }),
2141
+ threshold: z.string().min(1).meta({
2142
+ title: "Safety Threshold",
2143
+ description: "Google safety threshold identifier."
2144
+ })
2145
+ })
2146
+ ).optional().meta({
2147
+ title: "Safety Settings",
2148
+ description: "Allowlisted Google safety settings."
2149
+ }),
2150
+ tools: z.array(
2151
+ z.strictObject({
2152
+ googleSearch: z.strictObject({}).meta({
2153
+ title: "Google Search",
2154
+ description: "Google Search grounding tool."
2155
+ })
2156
+ })
2157
+ ).min(1).optional().meta({
2158
+ title: "Tools",
2159
+ description: "Allowlisted Google tools for gemini-3-flash-preview."
2160
+ }),
2161
+ httpOptions: z.strictObject({
2162
+ timeout: z.number().int().positive().optional().meta({
2163
+ title: "HTTP Timeout",
2164
+ description: "Per-request Google transport timeout in milliseconds."
2165
+ })
2166
+ }).optional().meta({
2167
+ title: "HTTP Options",
2168
+ description: "Allowlisted Google transport options."
2169
+ }),
2170
+ flexFallback: z.boolean().optional().meta({
2171
+ title: "Flex Fallback",
2172
+ description: "Allow provider fallback from flex when flex was explicitly selected."
2173
+ })
2174
+ }).optional().meta({
2175
+ title: "Google Provider Options",
2176
+ description: "Allowlisted Google provider options for gemini-3-flash-preview."
2177
+ })
2178
+ }).optional().meta({
2179
+ title: "Provider Options",
2180
+ description: "Provider-specific options accepted for gemini-3-flash-preview."
2181
+ })
2182
+ }),
2183
+ z.strictObject({
2184
+ maxOutputTokens: z.number().int().positive().optional().meta({
2185
+ title: "Max Output Tokens",
2186
+ description: "Maximum output token cap for gemini-3-flash-preview."
2187
+ }),
2188
+ stopSequences: z.array(z.string()).max(5).optional().meta({
2189
+ title: "Stop Sequences",
2190
+ description: "Up to five stop sequences for gemini-3-flash-preview."
2191
+ }),
2192
+ serviceTier: z.literal("standard").optional().meta({
2193
+ title: "Service Tier",
2194
+ description: "Standard tier or omitted tier for gemini-3-flash-preview."
2195
+ }),
2196
+ reasoning: z.union([
2197
+ z.strictObject({
2198
+ effort: z.enum(["none", "low", "medium", "high"]).meta({
2199
+ title: "Reasoning Effort",
2200
+ description: "Reasoning effort for gemini-3-flash-preview; none maps to minimal thinking."
2201
+ }),
2202
+ includeThoughts: z.boolean().optional().meta({
2203
+ title: "Include Thoughts",
2204
+ description: "Return provider thought summaries when supported."
2205
+ })
2206
+ }),
2207
+ z.strictObject({
2208
+ includeThoughts: z.boolean().meta({
2209
+ title: "Include Thoughts",
2210
+ description: "Return provider thought summaries when supported."
2211
+ })
2212
+ })
2213
+ ]).optional().meta({
2214
+ title: "Reasoning",
2215
+ description: "Gemini 3 Flash Preview thinkingLevel configuration."
2216
+ }),
2217
+ timeoutMs: z.number().int().positive().optional().meta({
2218
+ title: "Timeout",
2219
+ description: "Logical request timeout in milliseconds."
2220
+ }),
2221
+ providerOptions: z.strictObject({
2222
+ google: z.strictObject({
2223
+ cachedContent: z.string().min(1).optional().meta({
2224
+ title: "Cached Content",
2225
+ description: "Google cached content resource name."
2226
+ }),
2227
+ safetySettings: z.array(
2228
+ z.strictObject({
2229
+ category: z.string().min(1).meta({
2230
+ title: "Safety Category",
2231
+ description: "Google safety category identifier."
2232
+ }),
2233
+ threshold: z.string().min(1).meta({
2234
+ title: "Safety Threshold",
2235
+ description: "Google safety threshold identifier."
2236
+ })
2237
+ })
2238
+ ).optional().meta({
2239
+ title: "Safety Settings",
2240
+ description: "Allowlisted Google safety settings."
2241
+ }),
2242
+ tools: z.array(
2243
+ z.strictObject({
2244
+ googleSearch: z.strictObject({}).meta({
2245
+ title: "Google Search",
2246
+ description: "Google Search grounding tool."
2247
+ })
2248
+ })
2249
+ ).min(1).optional().meta({
2250
+ title: "Tools",
2251
+ description: "Allowlisted Google tools for gemini-3-flash-preview."
2252
+ }),
2253
+ httpOptions: z.strictObject({
2254
+ timeout: z.number().int().positive().optional().meta({
2255
+ title: "HTTP Timeout",
2256
+ description: "Per-request Google transport timeout in milliseconds."
2257
+ })
2258
+ }).optional().meta({
2259
+ title: "HTTP Options",
2260
+ description: "Allowlisted Google transport options."
2261
+ })
2262
+ }).optional().meta({
2263
+ title: "Google Provider Options",
2264
+ description: "Allowlisted Google provider options for gemini-3-flash-preview."
2265
+ })
2266
+ }).optional().meta({
2267
+ title: "Provider Options",
2268
+ description: "Provider-specific options accepted for gemini-3-flash-preview."
2269
+ })
2270
+ })
2271
+ ]).meta({
2272
+ title: "Gemini3FlashPreviewConfig",
2273
+ description: "Strict generateContent config for model gemini-3-flash-preview. Level reasoning, fixed sampling, flex/standard tiers, structured output, grounding, priced.",
2274
+ examples: [{ serviceTier: "flex", reasoning: { effort: "medium" } }]
2275
+ });
2276
+ var Gemma431bItConfigSchema = z.strictObject({
2277
+ temperature: z.number().min(0).max(2).optional().meta({
2278
+ title: "Temperature",
2279
+ description: "Sampling temperature for gemma-4-31b-it.",
2280
+ examples: [0.7]
2281
+ }),
2282
+ topP: z.number().min(0).max(1).optional().meta({
2283
+ title: "Top P",
2284
+ description: "Nucleus sampling probability for gemma-4-31b-it."
2285
+ }),
2286
+ topK: z.number().int().positive().optional().meta({
2287
+ title: "Top K",
2288
+ description: "Top-k sampling limit for gemma-4-31b-it."
2289
+ }),
2290
+ maxOutputTokens: z.number().int().positive().optional().meta({
2291
+ title: "Max Output Tokens",
2292
+ description: "Maximum output token cap for gemma-4-31b-it."
2293
+ }),
2294
+ stopSequences: z.array(z.string()).max(5).optional().meta({
2295
+ title: "Stop Sequences",
2296
+ description: "Up to five stop sequences for gemma-4-31b-it."
2297
+ }),
2298
+ reasoning: z.union([
2299
+ z.strictObject({
2300
+ effort: z.enum(["none", "high"]).meta({
2301
+ title: "Reasoning Effort",
2302
+ description: "Reasoning effort for gemma-4-31b-it."
2303
+ }),
2304
+ includeThoughts: z.boolean().optional().meta({
2305
+ title: "Include Thoughts",
2306
+ description: "Return provider thought summaries when supported."
2307
+ })
2308
+ }),
2309
+ z.strictObject({
2310
+ includeThoughts: z.boolean().meta({
2311
+ title: "Include Thoughts",
2312
+ description: "Return provider thought summaries when supported."
2313
+ })
2314
+ })
2315
+ ]).optional().meta({
2316
+ title: "Reasoning",
2317
+ description: "Gemma 4 31B IT thinkingLevel configuration."
2318
+ }),
2319
+ timeoutMs: z.number().int().positive().optional().meta({
2320
+ title: "Timeout",
2321
+ description: "Logical request timeout in milliseconds."
2322
+ }),
2323
+ providerOptions: z.strictObject({
2324
+ google: z.strictObject({
2325
+ cachedContent: z.string().min(1).optional().meta({
2326
+ title: "Cached Content",
2327
+ description: "Google cached content resource name."
2328
+ }),
2329
+ safetySettings: z.array(
2330
+ z.strictObject({
2331
+ category: z.string().min(1).meta({
2332
+ title: "Safety Category",
2333
+ description: "Google safety category identifier."
2334
+ }),
2335
+ threshold: z.string().min(1).meta({
2336
+ title: "Safety Threshold",
2337
+ description: "Google safety threshold identifier."
2338
+ })
2339
+ })
2340
+ ).optional().meta({
2341
+ title: "Safety Settings",
2342
+ description: "Allowlisted Google safety settings."
2343
+ }),
2344
+ tools: z.array(
2345
+ z.strictObject({
2346
+ googleSearch: z.strictObject({}).meta({
2347
+ title: "Google Search",
2348
+ description: "Google Search grounding tool."
2349
+ })
2350
+ })
2351
+ ).min(1).optional().meta({
2352
+ title: "Tools",
2353
+ description: "Allowlisted Google tools for gemma-4-31b-it."
2354
+ }),
2355
+ httpOptions: z.strictObject({
2356
+ timeout: z.number().int().positive().optional().meta({
2357
+ title: "HTTP Timeout",
2358
+ description: "Per-request Google transport timeout in milliseconds."
2359
+ })
2360
+ }).optional().meta({
2361
+ title: "HTTP Options",
2362
+ description: "Allowlisted Google transport options."
2363
+ })
2364
+ }).optional().meta({
2365
+ title: "Google Provider Options",
2366
+ description: "Allowlisted Google provider options for gemma-4-31b-it."
2367
+ })
2368
+ }).optional().meta({
2369
+ title: "Provider Options",
2370
+ description: "Provider-specific options accepted for gemma-4-31b-it."
2371
+ })
2372
+ }).meta({
2373
+ title: "Gemma431bItConfig",
2374
+ description: "Strict generateContent config for model gemma-4-31b-it. Level reasoning, tunable sampling, no service tier, structured output, grounding, intentionally unpriced.",
2375
+ examples: [{ temperature: 0.7, reasoning: { effort: "high" } }]
2376
+ });
2377
+ var Gemma426bA4bItConfigSchema = z.strictObject({
2378
+ temperature: z.number().min(0).max(2).optional().meta({
2379
+ title: "Temperature",
2380
+ description: "Sampling temperature for gemma-4-26b-a4b-it.",
2381
+ examples: [0.7]
2382
+ }),
2383
+ topP: z.number().min(0).max(1).optional().meta({
2384
+ title: "Top P",
2385
+ description: "Nucleus sampling probability for gemma-4-26b-a4b-it."
2386
+ }),
2387
+ topK: z.number().int().positive().optional().meta({
2388
+ title: "Top K",
2389
+ description: "Top-k sampling limit for gemma-4-26b-a4b-it."
2390
+ }),
2391
+ maxOutputTokens: z.number().int().positive().optional().meta({
2392
+ title: "Max Output Tokens",
2393
+ description: "Maximum output token cap for gemma-4-26b-a4b-it."
2394
+ }),
2395
+ stopSequences: z.array(z.string()).max(5).optional().meta({
2396
+ title: "Stop Sequences",
2397
+ description: "Up to five stop sequences for gemma-4-26b-a4b-it."
2398
+ }),
2399
+ reasoning: z.union([
2400
+ z.strictObject({
2401
+ effort: z.enum(["none", "high"]).meta({
2402
+ title: "Reasoning Effort",
2403
+ description: "Reasoning effort for gemma-4-26b-a4b-it."
2404
+ }),
2405
+ includeThoughts: z.boolean().optional().meta({
2406
+ title: "Include Thoughts",
2407
+ description: "Return provider thought summaries when supported."
2408
+ })
2409
+ }),
2410
+ z.strictObject({
2411
+ includeThoughts: z.boolean().meta({
2412
+ title: "Include Thoughts",
2413
+ description: "Return provider thought summaries when supported."
2414
+ })
2415
+ })
2416
+ ]).optional().meta({
2417
+ title: "Reasoning",
2418
+ description: "Gemma 4 26B A4B IT thinkingLevel configuration."
2419
+ }),
2420
+ timeoutMs: z.number().int().positive().optional().meta({
2421
+ title: "Timeout",
2422
+ description: "Logical request timeout in milliseconds."
2423
+ }),
2424
+ providerOptions: z.strictObject({
2425
+ google: z.strictObject({
2426
+ cachedContent: z.string().min(1).optional().meta({
2427
+ title: "Cached Content",
2428
+ description: "Google cached content resource name."
2429
+ }),
2430
+ safetySettings: z.array(
2431
+ z.strictObject({
2432
+ category: z.string().min(1).meta({
2433
+ title: "Safety Category",
2434
+ description: "Google safety category identifier."
2435
+ }),
2436
+ threshold: z.string().min(1).meta({
2437
+ title: "Safety Threshold",
2438
+ description: "Google safety threshold identifier."
2439
+ })
2440
+ })
2441
+ ).optional().meta({
2442
+ title: "Safety Settings",
2443
+ description: "Allowlisted Google safety settings."
2444
+ }),
2445
+ tools: z.array(
2446
+ z.strictObject({
2447
+ googleSearch: z.strictObject({}).meta({
2448
+ title: "Google Search",
2449
+ description: "Google Search grounding tool."
2450
+ })
2451
+ })
2452
+ ).min(1).optional().meta({
2453
+ title: "Tools",
2454
+ description: "Allowlisted Google tools for gemma-4-26b-a4b-it."
2455
+ }),
2456
+ httpOptions: z.strictObject({
2457
+ timeout: z.number().int().positive().optional().meta({
2458
+ title: "HTTP Timeout",
2459
+ description: "Per-request Google transport timeout in milliseconds."
2460
+ })
2461
+ }).optional().meta({
2462
+ title: "HTTP Options",
2463
+ description: "Allowlisted Google transport options."
2464
+ })
2465
+ }).optional().meta({
2466
+ title: "Google Provider Options",
2467
+ description: "Allowlisted Google provider options for gemma-4-26b-a4b-it."
2468
+ })
2469
+ }).optional().meta({
2470
+ title: "Provider Options",
2471
+ description: "Provider-specific options accepted for gemma-4-26b-a4b-it."
2472
+ })
2473
+ }).meta({
2474
+ title: "Gemma426bA4bItConfig",
2475
+ description: "Strict generateContent config for model gemma-4-26b-a4b-it. Level reasoning, tunable sampling, no service tier, structured output, grounding, intentionally unpriced.",
2476
+ examples: [{ temperature: 0.7, reasoning: { effort: "none" } }]
2477
+ });
2478
+ var GEMINI_25_PRO_REASONING_EFFORTS = [
2479
+ "low",
2480
+ "medium",
2481
+ "high"
2482
+ ];
2483
+ var GEMINI_LEVEL_REASONING_EFFORTS = [
2484
+ "none",
2485
+ "low",
2486
+ "medium",
2487
+ "high"
2488
+ ];
2489
+ var GEMINI_LEVEL_PRO_PREVIEW_REASONING_EFFORTS = [
2490
+ "low",
2491
+ "medium",
2492
+ "high"
2493
+ ];
2494
+ var GEMINI_25_FLASH_REASONING_EFFORTS = [
2495
+ "none",
2496
+ "low",
2497
+ "medium",
2498
+ "high"
2499
+ ];
2500
+ var GEMMA_REASONING_EFFORTS = [
2501
+ "none",
2502
+ "high"
2503
+ ];
2504
+ var geminiModelDescriptors = [
2505
+ {
2506
+ model: "gemini-2.5-pro",
2507
+ provider: "google",
2508
+ pricingFamily: "gemini-2.5-pro",
2509
+ capabilities: {
2510
+ reasoning: true,
2511
+ structuredOutput: true,
2512
+ nativeStructuredOutput: true,
2513
+ vision: true,
2514
+ reasoningApi: "budget",
2515
+ admittedReasoningEfforts: GEMINI_25_PRO_REASONING_EFFORTS,
2516
+ sampling: "tunable",
2517
+ caching: { explicit: true, minTokens: 2048 },
2518
+ grounding: true,
2519
+ serviceTiers: ["flex", "standard"]
2520
+ },
2521
+ configSchema: Gemini25ProConfigSchema,
2522
+ configJsonSchema: toConfigJsonSchema(Gemini25ProConfigSchema),
2523
+ validateConfig: zodToStandardSchema(Gemini25ProConfigSchema)
2524
+ },
2525
+ {
2526
+ model: "gemini-2.5-flash",
2527
+ provider: "google",
2528
+ pricingFamily: "gemini-2.5-flash",
2529
+ capabilities: {
2530
+ reasoning: true,
2531
+ structuredOutput: true,
2532
+ nativeStructuredOutput: true,
2533
+ vision: true,
2534
+ reasoningApi: "budget",
2535
+ admittedReasoningEfforts: GEMINI_25_FLASH_REASONING_EFFORTS,
2536
+ sampling: "tunable",
2537
+ caching: { explicit: true, minTokens: 2048 },
2538
+ grounding: true,
2539
+ serviceTiers: ["flex", "standard"]
2540
+ },
2541
+ configSchema: Gemini25FlashConfigSchema,
2542
+ configJsonSchema: toConfigJsonSchema(Gemini25FlashConfigSchema),
2543
+ validateConfig: zodToStandardSchema(Gemini25FlashConfigSchema)
2544
+ },
2545
+ {
2546
+ model: "gemini-2.5-flash-lite",
2547
+ provider: "google",
2548
+ pricingFamily: "gemini-2.5-flash-lite",
2549
+ capabilities: {
2550
+ reasoning: true,
2551
+ structuredOutput: true,
2552
+ nativeStructuredOutput: true,
2553
+ vision: true,
2554
+ reasoningApi: "budget",
2555
+ admittedReasoningEfforts: GEMINI_25_FLASH_REASONING_EFFORTS,
2556
+ sampling: "tunable",
2557
+ caching: { explicit: true, minTokens: 2048 },
2558
+ grounding: true,
2559
+ serviceTiers: ["flex", "standard"]
2560
+ },
2561
+ configSchema: Gemini25FlashLiteConfigSchema,
2562
+ configJsonSchema: toConfigJsonSchema(Gemini25FlashLiteConfigSchema),
2563
+ validateConfig: zodToStandardSchema(Gemini25FlashLiteConfigSchema)
2564
+ },
2565
+ {
2566
+ model: "gemini-3.5-flash",
2567
+ provider: "google",
2568
+ pricingFamily: "gemini-3.5-flash",
2569
+ capabilities: {
2570
+ reasoning: true,
2571
+ structuredOutput: true,
2572
+ nativeStructuredOutput: true,
2573
+ vision: true,
2574
+ reasoningApi: "level",
2575
+ admittedReasoningEfforts: GEMINI_LEVEL_REASONING_EFFORTS,
2576
+ sampling: "fixed",
2577
+ caching: { explicit: true, minTokens: 2048 },
2578
+ grounding: true,
2579
+ serviceTiers: ["flex", "standard"]
2580
+ },
2581
+ configSchema: Gemini35FlashConfigSchema,
2582
+ configJsonSchema: toConfigJsonSchema(Gemini35FlashConfigSchema),
2583
+ validateConfig: zodToStandardSchema(Gemini35FlashConfigSchema)
2584
+ },
2585
+ {
2586
+ model: "gemini-3.1-flash-lite",
2587
+ provider: "google",
2588
+ pricingFamily: "gemini-3.1-flash-lite",
2589
+ capabilities: {
2590
+ reasoning: true,
2591
+ structuredOutput: true,
2592
+ nativeStructuredOutput: true,
2593
+ vision: true,
2594
+ reasoningApi: "level",
2595
+ admittedReasoningEfforts: GEMINI_LEVEL_REASONING_EFFORTS,
2596
+ sampling: "fixed",
2597
+ caching: { explicit: true, minTokens: 2048 },
2598
+ grounding: true,
2599
+ serviceTiers: ["flex", "standard"]
2600
+ },
2601
+ configSchema: Gemini31FlashLiteConfigSchema,
2602
+ configJsonSchema: toConfigJsonSchema(Gemini31FlashLiteConfigSchema),
2603
+ validateConfig: zodToStandardSchema(Gemini31FlashLiteConfigSchema)
2604
+ },
2605
+ {
2606
+ model: "gemini-3.1-pro-preview",
2607
+ provider: "google",
2608
+ pricingFamily: "gemini-3.1-pro-preview",
2609
+ capabilities: {
2610
+ reasoning: true,
2611
+ structuredOutput: true,
2612
+ nativeStructuredOutput: true,
2613
+ vision: true,
2614
+ reasoningApi: "level",
2615
+ admittedReasoningEfforts: GEMINI_LEVEL_PRO_PREVIEW_REASONING_EFFORTS,
2616
+ sampling: "fixed",
2617
+ caching: { explicit: true, minTokens: 2048 },
2618
+ grounding: true,
2619
+ serviceTiers: ["flex", "standard"]
2620
+ },
2621
+ configSchema: Gemini31ProPreviewConfigSchema,
2622
+ configJsonSchema: toConfigJsonSchema(Gemini31ProPreviewConfigSchema),
2623
+ validateConfig: zodToStandardSchema(Gemini31ProPreviewConfigSchema)
2624
+ },
2625
+ {
2626
+ model: "gemini-3-flash-preview",
2627
+ provider: "google",
2628
+ pricingFamily: "gemini-3-flash-preview",
2629
+ capabilities: {
2630
+ reasoning: true,
2631
+ structuredOutput: true,
2632
+ nativeStructuredOutput: true,
2633
+ vision: true,
2634
+ reasoningApi: "level",
2635
+ admittedReasoningEfforts: GEMINI_LEVEL_REASONING_EFFORTS,
2636
+ sampling: "fixed",
2637
+ caching: { explicit: true, minTokens: 2048 },
2638
+ grounding: true,
2639
+ serviceTiers: ["flex", "standard"]
2640
+ },
2641
+ configSchema: Gemini3FlashPreviewConfigSchema,
2642
+ configJsonSchema: toConfigJsonSchema(Gemini3FlashPreviewConfigSchema),
2643
+ validateConfig: zodToStandardSchema(Gemini3FlashPreviewConfigSchema)
2644
+ }
2645
+ ];
2646
+ var gemmaModelDescriptors = [
2647
+ {
2648
+ model: "gemma-4-31b-it",
2649
+ provider: "google",
2650
+ capabilities: {
2651
+ reasoning: true,
2652
+ reasoningApi: "level",
2653
+ admittedReasoningEfforts: GEMMA_REASONING_EFFORTS,
2654
+ structuredOutput: true,
2655
+ nativeStructuredOutput: true,
2656
+ grounding: true,
2657
+ vision: true,
2658
+ sampling: "tunable"
2659
+ },
2660
+ configSchema: Gemma431bItConfigSchema,
2661
+ configJsonSchema: toConfigJsonSchema(Gemma431bItConfigSchema),
2662
+ validateConfig: zodToStandardSchema(Gemma431bItConfigSchema)
2663
+ },
2664
+ {
2665
+ model: "gemma-4-26b-a4b-it",
2666
+ provider: "google",
2667
+ capabilities: {
2668
+ reasoning: true,
2669
+ reasoningApi: "level",
2670
+ admittedReasoningEfforts: GEMMA_REASONING_EFFORTS,
2671
+ structuredOutput: true,
2672
+ nativeStructuredOutput: true,
2673
+ grounding: true,
2674
+ vision: true,
2675
+ sampling: "tunable"
2676
+ },
2677
+ configSchema: Gemma426bA4bItConfigSchema,
2678
+ configJsonSchema: toConfigJsonSchema(Gemma426bA4bItConfigSchema),
2679
+ validateConfig: zodToStandardSchema(Gemma426bA4bItConfigSchema)
2680
+ }
2681
+ ];
2682
+ var defaultGeminiRegistry = createModelRegistry([
2683
+ ...geminiModelDescriptors,
2684
+ ...gemmaModelDescriptors
2685
+ ]);
2686
+
2687
+ // src/provider.ts
2688
+ function googleProvider(opts) {
2689
+ return {
2690
+ adapter: geminiAdapter(opts),
2691
+ modelDescriptors: [...geminiModelDescriptors, ...gemmaModelDescriptors],
2692
+ pricingSource: geminiPricingSource()
2693
+ };
2694
+ }
681
2695
  var DEFAULT_INTERVAL_MS = 3e3;
682
2696
  var DEFAULT_TIMEOUT_MS = 3e5;
683
2697
  var realSleep = (ms) => new Promise((resolve) => setTimeout(resolve, ms));
@@ -779,8 +2793,9 @@ var GoogleFileStore = class {
779
2793
  const { name, uri } = uploadResp;
780
2794
  if (name === void 0 || name.length === 0 || uri === void 0 || uri.length === 0) {
781
2795
  throw new LlmError("File upload response missing required fields (name or uri)", {
782
- kind: "bad_request",
783
- retryable: false
2796
+ kind: "server",
2797
+ retryable: false,
2798
+ provider: "google"
784
2799
  });
785
2800
  }
786
2801
  const fallback = { name, uri, mimeType };
@@ -893,6 +2908,7 @@ var GoogleCacheStore = class {
893
2908
  onDeleteError;
894
2909
  logger;
895
2910
  now;
2911
+ preflight;
896
2912
  /** Memoised client promise — built at most once per store instance. */
897
2913
  clientPromise;
898
2914
  /** In-process cache of live handles, keyed by `${model}:${stableKey}`. */
@@ -919,6 +2935,7 @@ var GoogleCacheStore = class {
919
2935
  }
920
2936
  });
921
2937
  this.now = opts.now ?? (() => Date.now());
2938
+ this.preflight = opts.preflight;
922
2939
  }
923
2940
  getClient() {
924
2941
  if (this.clientOverride !== void 0) return Promise.resolve(this.clientOverride);
@@ -938,6 +2955,19 @@ var GoogleCacheStore = class {
938
2955
  * `now + ttlSeconds * 1000`.
939
2956
  */
940
2957
  async create(input) {
2958
+ if (this.preflight !== void 0) {
2959
+ const counted = await this.preflight.countTokens({
2960
+ model: input.model,
2961
+ ...input.contents !== void 0 ? { contents: input.contents } : {},
2962
+ ...input.systemInstruction !== void 0 ? { systemInstruction: input.systemInstruction } : {}
2963
+ });
2964
+ if (counted < this.preflight.minTokens) {
2965
+ throw new LlmError(
2966
+ `GoogleCacheStore preflight: counted ${counted} token(s), below the configured minimum of ${this.preflight.minTokens} for model "${input.model}".`,
2967
+ { kind: "bad_request", retryable: false }
2968
+ );
2969
+ }
2970
+ }
941
2971
  const client = await this.getClient();
942
2972
  const config = { ttl: `${input.ttlSeconds}s` };
943
2973
  if (input.contents !== void 0) config.contents = input.contents;
@@ -952,8 +2982,9 @@ var GoogleCacheStore = class {
952
2982
  }
953
2983
  if (resp.name === void 0 || resp.name.length === 0) {
954
2984
  throw new LlmError("Cache create response missing required field: name", {
955
- kind: "bad_request",
956
- retryable: false
2985
+ kind: "server",
2986
+ retryable: false,
2987
+ provider: "google"
957
2988
  });
958
2989
  }
959
2990
  const fallbackExpiry = new Date(this.now() + input.ttlSeconds * 1e3);
@@ -1115,7 +3146,177 @@ function normalizeGroundingCitations(groundingMetadata) {
1115
3146
  }
1116
3147
  return citations;
1117
3148
  }
3149
+ function badRequest(message) {
3150
+ return new LlmError(message, { kind: "bad_request", retryable: false });
3151
+ }
3152
+ function definedKeys(obj) {
3153
+ return Object.keys(obj).filter(
3154
+ (key) => obj[key] !== void 0
3155
+ );
3156
+ }
3157
+ function mapMediaResolutionLevel(level, location) {
3158
+ switch (level) {
3159
+ case "MEDIA_RESOLUTION_LOW":
3160
+ return "low";
3161
+ case "MEDIA_RESOLUTION_MEDIUM":
3162
+ return "medium";
3163
+ case "MEDIA_RESOLUTION_HIGH":
3164
+ return "high";
3165
+ default:
3166
+ throw badRequest(
3167
+ `${location}: unsupported Part.mediaResolution.level "${level}" \u2014 any-llm only supports MEDIA_RESOLUTION_LOW, MEDIA_RESOLUTION_MEDIUM, MEDIA_RESOLUTION_HIGH.`
3168
+ );
3169
+ }
3170
+ }
3171
+ function convertMediaResolution(mediaResolution, location) {
3172
+ const extraKeys = definedKeys(mediaResolution).filter((key) => key !== "level");
3173
+ if (extraKeys.length > 0) {
3174
+ throw badRequest(
3175
+ `${location}: Part.mediaResolution keys [${extraKeys.join(", ")}] are not representable in any-llm \u2014 only mediaResolution.level is supported.`
3176
+ );
3177
+ }
3178
+ if (mediaResolution.level === void 0) {
3179
+ throw badRequest(
3180
+ `${location}: Part.mediaResolution is present but carries no level \u2014 an explicit-but-empty mediaResolution is ambiguous; set level or omit the field.`
3181
+ );
3182
+ }
3183
+ return mapMediaResolutionLevel(mediaResolution.level, location);
3184
+ }
3185
+ function convertPart(part, location) {
3186
+ const keys = definedKeys(part);
3187
+ const baseKeys = keys.filter(
3188
+ (key) => key === "text" || key === "inlineData" || key === "fileData"
3189
+ );
3190
+ if (baseKeys.length === 0) {
3191
+ if (keys.length === 0) {
3192
+ throw badRequest(
3193
+ `${location}: Part has no recognized fields set (expected exactly one of text, inlineData, fileData).`
3194
+ );
3195
+ }
3196
+ throw badRequest(
3197
+ `${location}: Part keys [${keys.join(", ")}] are not supported by geminiContentToMessages \u2014 only text, inlineData, and fileData parts can be represented in any-llm.`
3198
+ );
3199
+ }
3200
+ if (baseKeys.length > 1) {
3201
+ throw badRequest(
3202
+ `${location}: Part has more than one of text/inlineData/fileData set ([${baseKeys.join(", ")}]) \u2014 geminiContentToMessages requires exactly one.`
3203
+ );
3204
+ }
3205
+ const base = baseKeys[0];
3206
+ const extraKeys = keys.filter(
3207
+ (key) => key !== base && !(base !== "text" && key === "mediaResolution")
3208
+ );
3209
+ if (extraKeys.length > 0) {
3210
+ throw badRequest(
3211
+ `${location}: Part keys [${extraKeys.join(", ")}] cannot be represented in any-llm alongside ${base} \u2014 nothing is silently dropped.`
3212
+ );
3213
+ }
3214
+ if (part.text !== void 0) {
3215
+ return { kind: "text", text: part.text };
3216
+ }
3217
+ if (part.inlineData !== void 0) {
3218
+ const inlineData = part.inlineData;
3219
+ const inlineExtraKeys = definedKeys(inlineData).filter(
3220
+ (key) => key !== "mimeType" && key !== "data"
3221
+ );
3222
+ if (inlineExtraKeys.length > 0) {
3223
+ throw badRequest(
3224
+ `${location}: Part.inlineData keys [${inlineExtraKeys.join(", ")}] are not representable in any-llm.`
3225
+ );
3226
+ }
3227
+ if (inlineData.mimeType === void 0) {
3228
+ throw badRequest(`${location}: Part.inlineData.mimeType is required.`);
3229
+ }
3230
+ if (inlineData.data === void 0) {
3231
+ throw badRequest(`${location}: Part.inlineData.data is required.`);
3232
+ }
3233
+ return {
3234
+ kind: "inline-media",
3235
+ mimeType: inlineData.mimeType,
3236
+ data: inlineData.data,
3237
+ ...part.mediaResolution !== void 0 ? { mediaResolution: convertMediaResolution(part.mediaResolution, location) } : {}
3238
+ };
3239
+ }
3240
+ if (part.fileData !== void 0) {
3241
+ const fileData = part.fileData;
3242
+ const fileExtraKeys = definedKeys(fileData).filter(
3243
+ (key) => key !== "fileUri" && key !== "mimeType"
3244
+ );
3245
+ if (fileExtraKeys.length > 0) {
3246
+ throw badRequest(
3247
+ `${location}: Part.fileData keys [${fileExtraKeys.join(", ")}] are not representable in any-llm.`
3248
+ );
3249
+ }
3250
+ if (fileData.fileUri === void 0) {
3251
+ throw badRequest(`${location}: Part.fileData.fileUri is required.`);
3252
+ }
3253
+ if (fileData.mimeType === void 0) {
3254
+ throw badRequest(`${location}: Part.fileData.mimeType is required.`);
3255
+ }
3256
+ return {
3257
+ kind: "file-uri",
3258
+ uri: fileData.fileUri,
3259
+ mimeType: fileData.mimeType,
3260
+ ...part.mediaResolution !== void 0 ? { mediaResolution: convertMediaResolution(part.mediaResolution, location) } : {}
3261
+ };
3262
+ }
3263
+ throw badRequest(`${location}: Part has no recognized fields set.`);
3264
+ }
3265
+ function convertRole(role, location) {
3266
+ if (role === "user") return "user";
3267
+ if (role === "model") return "assistant";
3268
+ throw badRequest(
3269
+ `${location}: Content.role "${String(role)}" is not supported \u2014 only "user" and "model" are recognized. any-llm never infers a missing role.`
3270
+ );
3271
+ }
3272
+ function convertSystemInstruction(systemInstruction) {
3273
+ if (typeof systemInstruction === "string") {
3274
+ return systemInstruction;
3275
+ }
3276
+ const envelopeExtraKeys = definedKeys(systemInstruction).filter(
3277
+ (key) => key !== "parts"
3278
+ );
3279
+ if (envelopeExtraKeys.length > 0) {
3280
+ throw badRequest(
3281
+ `systemInstruction: Content keys [${envelopeExtraKeys.join(", ")}] are not supported on a system instruction \u2014 only parts is allowed.`
3282
+ );
3283
+ }
3284
+ const parts = systemInstruction.parts ?? [];
3285
+ const textFragments = [];
3286
+ parts.forEach((part, index) => {
3287
+ const keys = definedKeys(part);
3288
+ if (keys.length !== 1 || keys[0] !== "text" || part.text === void 0) {
3289
+ const offending = keys.filter((key) => key !== "text");
3290
+ const named = offending.length > 0 ? offending : keys;
3291
+ throw badRequest(
3292
+ `systemInstruction.parts[${index}]: only text parts are allowed in a system instruction \u2014 part keys [${named.length > 0 ? named.join(", ") : "none"}] are not supported.`
3293
+ );
3294
+ }
3295
+ textFragments.push(part.text);
3296
+ });
3297
+ return textFragments.join("");
3298
+ }
3299
+ function geminiContentToMessages(input) {
3300
+ const system = input.systemInstruction !== void 0 ? convertSystemInstruction(input.systemInstruction) : void 0;
3301
+ const messages = input.contents.map((content, contentIndex) => {
3302
+ const location = `contents[${contentIndex}]`;
3303
+ const envelopeExtraKeys = definedKeys(content).filter(
3304
+ (key) => key !== "role" && key !== "parts"
3305
+ );
3306
+ if (envelopeExtraKeys.length > 0) {
3307
+ throw badRequest(
3308
+ `${location}: Content keys [${envelopeExtraKeys.join(", ")}] are not supported \u2014 only role and parts are allowed.`
3309
+ );
3310
+ }
3311
+ const role = convertRole(content.role, location);
3312
+ const parts = (content.parts ?? []).map(
3313
+ (part, partIndex) => convertPart(part, `${location}.parts[${partIndex}]`)
3314
+ );
3315
+ return { role, parts };
3316
+ });
3317
+ return { ...system !== void 0 ? { system } : {}, messages };
3318
+ }
1118
3319
 
1119
- export { FLEX_DEFAULT_TIMEOUT_MS, GoogleCacheStore, GoogleFileStore, STANDARD_DEFAULT_TIMEOUT_MS, TRANSPORT_TIMEOUT_BUFFER_MS, buildGoogleClient, geminiAdapter, isGeminiCapacityError, normalizeGroundingCitations, requireApiKey };
3320
+ export { FLEX_DEFAULT_TIMEOUT_MS, GEMINI_PRICING, GoogleCacheStore, GoogleFileStore, STANDARD_DEFAULT_TIMEOUT_MS, TIER_FACTOR, TRANSPORT_TIMEOUT_BUFFER_MS, buildGoogleClient, defaultGeminiRegistry, geminiAdapter, geminiContentToMessages, geminiModelDescriptors, geminiPricingSource, gemmaModelDescriptors, googleProvider, isGeminiCapacityError, normalizeGroundingCitations, pricingVersion, requireApiKey };
1120
3321
  //# sourceMappingURL=index.js.map
1121
3322
  //# sourceMappingURL=index.js.map