tuxevil-rotator 3.1.0 → 3.2.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.
@@ -149,6 +149,151 @@ function setCheckedModels(models) {
149
149
  updateModelsCountBadge();
150
150
  }
151
151
 
152
+ // ── Dynamic model grid (fetched from /api/models) ──────────────────
153
+ //
154
+ // The Generate/Edit Virtual Key modal used to ship with a hardcoded list
155
+ // of legacy Gemini/Claude/GPT-OSS models, so adding new providers
156
+ // (Ollama, OpenAI Codex, OpenCode Zen, ...) silently hid those models
157
+ // from the Allowed Models picker. The grid is now rendered from
158
+ // /api/models, which returns every model the rotator can route today
159
+ // grouped by `owned_by` provider. A static fallback is used only when
160
+ // the API is unreachable (e.g. dashboard served from a stale build).
161
+
162
+ // Provider id → human-readable group title for the modal UI.
163
+ var PROVIDER_LABELS = {
164
+ "tuxevil-rotator": "Google Antigravity",
165
+ "openai-codex": "OpenAI Codex",
166
+ "ollama": "Ollama Cloud",
167
+ "opencode-zen": "OpenCode Zen",
168
+ };
169
+
170
+ function providerLabel(ownedBy) {
171
+ if (PROVIDER_LABELS[ownedBy]) return PROVIDER_LABELS[ownedBy];
172
+ if (typeof ownedBy === "string" && ownedBy.length > 0) {
173
+ return ownedBy.charAt(0).toUpperCase() + ownedBy.slice(1);
174
+ }
175
+ return "Other";
176
+ }
177
+
178
+ function renderModelGridFromCatalog(catalog) {
179
+ var grid = document.getElementById("modelGrid");
180
+ var empty = document.getElementById("modelGridEmpty");
181
+ if (!grid) return false;
182
+
183
+ // Group models by `owned_by` provider while preserving the order in
184
+ // which the API returned them (static catalog first, then dynamic
185
+ // provider catalogs in the order they were enabled).
186
+ var groups = [];
187
+ var byKey = {};
188
+ (catalog || []).forEach(function(m) {
189
+ if (!m || !m.id) return;
190
+ var key = m.owned_by || "other";
191
+ if (!byKey[key]) {
192
+ byKey[key] = { key: key, label: providerLabel(key), models: [] };
193
+ groups.push(byKey[key]);
194
+ }
195
+ byKey[key].models.push(m);
196
+ });
197
+
198
+ if (groups.length === 0) {
199
+ grid.innerHTML = "";
200
+ if (empty) empty.style.display = "";
201
+ updateModelsCountBadge();
202
+ return false;
203
+ }
204
+
205
+ if (empty) empty.style.display = "none";
206
+
207
+ grid.innerHTML = groups.map(function(group) {
208
+ var cards = group.models.map(function(m) {
209
+ var id = "model-" + m.id.replace(/[^a-zA-Z0-9_-]/g, "_");
210
+ return '<label class="model-card">' +
211
+ '<input type="checkbox" id="' + escapeHtml(id) + '" value="' + escapeHtml(m.id) + '" class="modelCb" onchange="updateModelsCountBadge()">' +
212
+ '<span class="model-name" title="' + escapeHtml(m.id) + '">' + escapeHtml(m.id) + '</span>' +
213
+ '</label>';
214
+ }).join("");
215
+ return '<div class="model-category">' +
216
+ '<div class="cat-title">' + escapeHtml(group.label) + '</div>' +
217
+ '<div class="cat-grid">' + cards + '</div>' +
218
+ '</div>';
219
+ }).join("");
220
+
221
+ updateModelsCountBadge();
222
+ return true;
223
+ }
224
+
225
+ // Last successful catalog (cached so the Edit modal opens instantly
226
+ // without re-fetching when the user clicks Edit right after Generate).
227
+ var lastModelCatalog = null;
228
+ var modelCatalogInflight = null;
229
+
230
+ function fetchModelCatalog() {
231
+ if (modelCatalogInflight) return modelCatalogInflight;
232
+ modelCatalogInflight = fetch("/api/models", { headers: authHeaders() })
233
+ .then(function(r) {
234
+ if (!r.ok) throw new Error("HTTP " + r.status);
235
+ return r.json();
236
+ })
237
+ .then(function(d) {
238
+ var catalog = Array.isArray(d && d.data) ? d.data : [];
239
+ lastModelCatalog = catalog;
240
+ return catalog;
241
+ })
242
+ .finally(function() {
243
+ modelCatalogInflight = null;
244
+ });
245
+ return modelCatalogInflight;
246
+ }
247
+
248
+ // Static fallback used only when /api/models is unreachable. Mirrors
249
+ // the pre-refactor hardcoded list so the modal still works against an
250
+ // older server build that hasn't been restarted with this change.
251
+ var FALLBACK_MODEL_CATALOG = [
252
+ { id: "gemini-3.1-pro-low", owned_by: "tuxevil-rotator" },
253
+ { id: "gemini-3.1-pro-high", owned_by: "tuxevil-rotator" },
254
+ { id: "gemini-3.5-flash-medium", owned_by: "tuxevil-rotator" },
255
+ { id: "gemini-3.5-flash-high", owned_by: "tuxevil-rotator" },
256
+ { id: "gemini-3-flash", owned_by: "tuxevil-rotator" },
257
+ { id: "gemini-3.6-flash-low", owned_by: "tuxevil-rotator" },
258
+ { id: "gemini-3.6-flash-medium", owned_by: "tuxevil-rotator" },
259
+ { id: "gemini-3.6-flash-high", owned_by: "tuxevil-rotator" },
260
+ { id: "gemini-3.6-flash-tiered", owned_by: "tuxevil-rotator" },
261
+ { id: "gemini-3.7-flash-tiered", owned_by: "tuxevil-rotator" },
262
+ { id: "claude-sonnet-4-6", owned_by: "tuxevil-rotator" },
263
+ { id: "claude-opus-4-6-thinking", owned_by: "tuxevil-rotator" },
264
+ { id: "gpt-oss-120b-medium", owned_by: "tuxevil-rotator" },
265
+ ];
266
+
267
+ function ensureModelGridRendered(preselectedModels, callback) {
268
+ function applySelection() {
269
+ if (typeof preselectedModels !== "undefined") {
270
+ setCheckedModels(preselectedModels || []);
271
+ } else {
272
+ updateModelsCountBadge();
273
+ }
274
+ if (typeof callback === "function") callback();
275
+ }
276
+
277
+ if (lastModelCatalog && lastModelCatalog.length > 0) {
278
+ renderModelGridFromCatalog(lastModelCatalog);
279
+ applySelection();
280
+ return;
281
+ }
282
+
283
+ fetchModelCatalog()
284
+ .then(function(catalog) {
285
+ renderModelGridFromCatalog(catalog);
286
+ applySelection();
287
+ })
288
+ .catch(function() {
289
+ // Stale build or network glitch: fall back to the static list so
290
+ // the modal is never empty. The fallback lacks Ollama/Codex/Zen
291
+ // models, but at least existing keys can still be edited.
292
+ renderModelGridFromCatalog(FALLBACK_MODEL_CATALOG);
293
+ applySelection();
294
+ });
295
+ }
296
+
152
297
  function loadKeys() {
153
298
  fetch("/api/keys", { headers: authHeaders() })
154
299
  .then(function(r) { return r.json(); })
@@ -248,7 +393,6 @@ function showGenerateModal() {
248
393
  document.getElementById("keyFormAlias").disabled = false;
249
394
  document.getElementById("keyFormUserId").value = "";
250
395
  document.getElementById("keyFormUserId").disabled = false;
251
- selectNoModels();
252
396
  document.getElementById("keyFormError").textContent = "";
253
397
  document.getElementById("generatedKeyResult").style.display = "none";
254
398
  document.getElementById("submitKeyBtn").textContent = "Generate Key";
@@ -257,6 +401,10 @@ function showGenerateModal() {
257
401
  var sub = document.getElementById("modalSubtitle");
258
402
  if (sub) sub.textContent = "Configure key access and model restrictions";
259
403
  document.getElementById("keyModal").classList.add("open");
404
+ // Render the live provider catalog and default to "all models allowed"
405
+ // (empty selection). ensureModelGridRendered reuses the cached catalog
406
+ // when possible, so this opens instantly on the second open.
407
+ ensureModelGridRendered([]);
260
408
  }
261
409
 
262
410
  function showEditModal(hash) {
@@ -271,7 +419,6 @@ function showEditModal(hash) {
271
419
  document.getElementById("keyFormAlias").disabled = true;
272
420
  document.getElementById("keyFormUserId").value = k.userId || "";
273
421
  document.getElementById("keyFormUserId").disabled = true;
274
- setCheckedModels(k.models || []);
275
422
  document.getElementById("keyFormError").textContent = "";
276
423
  document.getElementById("generatedKeyResult").style.display = "none";
277
424
  document.getElementById("submitKeyBtn").textContent = "Save Changes";
@@ -280,6 +427,9 @@ function showEditModal(hash) {
280
427
  var sub = document.getElementById("modalSubtitle");
281
428
  if (sub) sub.textContent = "Updating model restrictions for alias: " + k.keyAlias;
282
429
  document.getElementById("keyModal").classList.add("open");
430
+ // Render the live catalog and preselect the key's existing allowlist
431
+ // (or all models when the key is unrestricted).
432
+ ensureModelGridRendered(k.models || []);
283
433
  }
284
434
 
285
435
  function hideModal() {
@@ -51,11 +51,33 @@ function isKickstartSupported(q) {
51
51
  );
52
52
  }
53
53
 
54
+ function getQuotaItemProviderRank(q) {
55
+ var p = q.providerId;
56
+ if (!p) {
57
+ var k = String(q.modelKey || "");
58
+ if (k === "claude" || k === "gemini") p = "google-antigravity";
59
+ else if (k === "session" || k === "weekly") p = "ollama";
60
+ else if (k.indexOf("opencode") === 0 || k === "opencode-zen") p = "opencode-zen";
61
+ else if (k.indexOf("codex") === 0 || k.indexOf("openai-codex") === 0) p = "openai-codex";
62
+ else p = "google-antigravity";
63
+ }
64
+ var ranks = {
65
+ "google-antigravity": 1,
66
+ "ollama": 2,
67
+ "opencode-zen": 3,
68
+ "openai-codex": 4
69
+ };
70
+ return ranks[p] || 99;
71
+ }
72
+
54
73
  function renderQuotaBars(account) {
55
74
  var quota = account.quota;
56
75
  if (!quota || quota.length === 0) return "";
76
+ var sortedQuota = quota.slice().sort(function (a, b) {
77
+ return getQuotaItemProviderRank(a) - getQuotaItemProviderRank(b);
78
+ });
57
79
  var now = Date.now();
58
- var rows = quota
80
+ var rows = sortedQuota
59
81
  .map(function (q) {
60
82
  var inFlightForModel = (account.inFlightByModel || {})[q.modelKey] || 0;
61
83
  var clearButton =
@@ -331,20 +353,6 @@ function renderAccounts(data) {
331
353
  Math.min(100, (cooldownRemaining / Math.max(totalCooldown, 1)) * 100),
332
354
  );
333
355
  }
334
- var modelBadges = (a.activeForModels || [])
335
- .map(function (m) {
336
- if (m.startsWith("claude")) {
337
- return '<span class="badge badge-model">CLAUDE</span>';
338
- }
339
- if (m === "gemini-3.1-pro") {
340
- return '<span class="badge badge-model">PRO</span>';
341
- }
342
- if (m === "gemini-3.5-flash") {
343
- return '<span class="badge badge-model">FLASH</span>';
344
- }
345
- return "";
346
- })
347
- .join("");
348
356
  var tierLabel = a.tier ? String(a.tier).toUpperCase() : "UNKNOWN";
349
357
 
350
358
  return (
@@ -393,7 +401,6 @@ function renderAccounts(data) {
393
401
  "ULTRA</div>" +
394
402
  "</div>" +
395
403
  "</div>" +
396
- modelBadges +
397
404
  "</div>" +
398
405
  "</div>" +
399
406
  '<div class="card-email">' +
@@ -1161,6 +1168,10 @@ var MODEL_PRICING_CLIENT = {
1161
1168
  "gemini-3.6-flash-medium": { input: 1.5, output: 7.5 },
1162
1169
  "gemini-3.6-flash-low": { input: 1.5, output: 7.5 },
1163
1170
  "gemini-3.6-flash-tiered": { input: 1.5, output: 7.5 },
1171
+ // Gemini 3.7 Flash tiered — public Gemini API pricing, verified 2026-08-13.
1172
+ // Introductory rates through 2026-12-31; from 2027-01-01 these double to
1173
+ // input 1.50 / output 7.50 per 1M tokens — update this entry then.
1174
+ "gemini-3.7-flash-tiered": { input: 0.75, output: 3.75 },
1164
1175
  "gpt-oss-120b-medium": { input: 2.0, output: 10.0 },
1165
1176
  // OpenAI Codex GPT-5.6 models — mirrors MODEL_PRICING in types.ts.
1166
1177
  "gpt-5.6-sol": { input: 5.0, output: 30.0 },
@@ -1185,6 +1196,14 @@ var MODEL_PRICING_CLIENT = {
1185
1196
  "nemotron-3-nano:30b": { input: 0.5, output: 1.5 },
1186
1197
  "nemotron-3-super": { input: 0.6, output: 1.8 },
1187
1198
  "nemotron-3-ultra": { input: 0.6, output: 1.8 },
1199
+ // OpenCode Zen free models — mirrors MODEL_PRICING in src/types.ts
1200
+ "deepseek-v4-flash-free": { input: 0.14, output: 0.28 },
1201
+ "nemotron-3.5-lightning-free": { input: 0.35, output: 1.05 },
1202
+ "nemotron-3-ultra-free": { input: 0.6, output: 1.8 },
1203
+ "mimo-v2.5-free": { input: 0.15, output: 0.6 },
1204
+ "hy3-free": { input: 0.25, output: 1.0 },
1205
+ "ling-3.0-tiny-free": { input: 0.05, output: 0.2 },
1206
+ "laguna-s-2.1-free": { input: 0.2, output: 0.8 },
1188
1207
  };
1189
1208
 
1190
1209
  function getModelPricingClient(m) {
@@ -1192,6 +1211,7 @@ function getModelPricingClient(m) {
1192
1211
  var lower = (m || "").toLowerCase();
1193
1212
  if (lower.indexOf("opus") !== -1) return MODEL_PRICING_CLIENT["claude-opus-4-6-thinking"];
1194
1213
  if (lower.indexOf("sonnet") !== -1) return MODEL_PRICING_CLIENT["claude-sonnet-4-6"];
1214
+ if (lower.indexOf("3.7-flash") !== -1) return MODEL_PRICING_CLIENT["gemini-3.7-flash-tiered"];
1195
1215
  if (lower.indexOf("3.6-flash") !== -1) return MODEL_PRICING_CLIENT["gemini-3.6-flash-high"];
1196
1216
  if (lower.indexOf("3.5-flash") !== -1) return MODEL_PRICING_CLIENT["gemini-3.5-flash-high"];
1197
1217
  if (lower.indexOf("flash") !== -1) return MODEL_PRICING_CLIENT["gemini-3-flash"];
package/src/types.ts CHANGED
@@ -277,6 +277,7 @@ export const QUOTA_MODEL_KEYS: Record<
277
277
  "gemini-3.6-flash-medium",
278
278
  "gemini-3.6-flash-low",
279
279
  "gemini-3.6-flash-tiered",
280
+ "gemini-3.7-flash-tiered",
280
281
  ],
281
282
  display: "Gemini",
282
283
  },
@@ -291,8 +292,6 @@ export function resolveQuotaModelKey(requestModel: string): string | null {
291
292
  lower === "nemotron-3-ultra-free" ||
292
293
  lower === "mimo-v2.5-free" ||
293
294
  lower === "hy3-free" ||
294
- lower === "ling-3.0-tiny-free" ||
295
- lower === "laguna-s-2.1-free" ||
296
295
  lower.endsWith("-free")
297
296
  ) {
298
297
  return "opencode-zen";
@@ -347,6 +346,17 @@ export function resolveDisplayModelKey(requestModel: string): string {
347
346
  if (lower.includes("-high")) return "gemini-3.6-flash-high";
348
347
  return "gemini-3.6-flash-high"; // unspecified variant
349
348
  }
349
+ // Gemini 3.7 Flash — only the tiered variant exists. Unsupported
350
+ // virtual variants (low/medium/high) intentionally fall through to the
351
+ // generic Flash fallback below instead of resolving as supported models.
352
+ if (
353
+ lower.includes("gemini") &&
354
+ lower.includes("3.7") &&
355
+ lower.includes("flash") &&
356
+ lower.includes("-tiered")
357
+ ) {
358
+ return "gemini-3.7-flash-tiered";
359
+ }
350
360
  // Gemini 3.5 Flash — distinguish medium vs high
351
361
  if (
352
362
  lower.includes("gemini") &&
@@ -755,6 +765,18 @@ export const MODEL_PRICING: Record<
755
765
  cachingPer1M: 0.15,
756
766
  cachingStoragePer1MPerHour: 1.0,
757
767
  },
768
+ // Gemini 3.7 Flash tiered — public Gemini API equivalent-value pricing,
769
+ // verified on the official Gemini API / Google Cloud pricing pages
770
+ // 2026-08-13. Introductory rates through 2026-12-31. From 2027-01-01
771
+ // these double to: input 1.50, output 7.50, cached input 0.15, cache
772
+ // storage 1.00 (USD per 1M tokens / per 1M tokens/hour) — update this
773
+ // static entry when the introductory period ends.
774
+ "gemini-3.7-flash-tiered": {
775
+ inputPer1M: 0.75,
776
+ outputPer1M: 3.75,
777
+ cachingPer1M: 0.075,
778
+ cachingStoragePer1MPerHour: 0.5,
779
+ },
758
780
  "gpt-oss-120b-medium": { inputPer1M: 2.0, outputPer1M: 10.0 },
759
781
 
760
782
  // OpenAI Codex GPT-5.6 models — official OpenAI API pricing checked
@@ -797,14 +819,13 @@ export const MODEL_PRICING: Record<
797
819
  "nemotron-3-super": { inputPer1M: 0.60, outputPer1M: 1.80 },
798
820
  "nemotron-3-ultra": { inputPer1M: 0.60, outputPer1M: 1.80 },
799
821
 
800
- // OpenCode Zen free models (cost: 0 USD per 1M tokens)
801
- "deepseek-v4-flash-free": { inputPer1M: 0.0, outputPer1M: 0.0 },
802
- "nemotron-3.5-lightning-free": { inputPer1M: 0.0, outputPer1M: 0.0 },
803
- "nemotron-3-ultra-free": { inputPer1M: 0.0, outputPer1M: 0.0 },
804
- "mimo-v2.5-free": { inputPer1M: 0.0, outputPer1M: 0.0 },
805
- "hy3-free": { inputPer1M: 0.0, outputPer1M: 0.0 },
806
- "ling-3.0-tiny-free": { inputPer1M: 0.0, outputPer1M: 0.0 },
807
- "laguna-s-2.1-free": { inputPer1M: 0.0, outputPer1M: 0.0 },
822
+ // OpenCode Zen free models — equivalent market rates (USD per 1M tokens) for savings tracking
823
+ "deepseek-v4-flash-free": { inputPer1M: 0.14, outputPer1M: 0.28, cachingPer1M: 0.0028 },
824
+ "nemotron-3.5-lightning-free": { inputPer1M: 0.35, outputPer1M: 1.05 },
825
+ "nemotron-3-ultra-free": { inputPer1M: 0.60, outputPer1M: 1.80 },
826
+ "mimo-v2.5-free": { inputPer1M: 0.15, outputPer1M: 0.60 },
827
+ "hy3-free": { inputPer1M: 0.25, outputPer1M: 1.00 },
828
+
808
829
  };
809
830
 
810
831
  // Which Ollama Cloud models respond on which subscription tiers, verified
@@ -337,6 +337,10 @@ const MODEL_PRICING = {
337
337
  "gemini-3.6-flash-medium": { inputPer1M: 1.50, outputPer1M: 7.50 },
338
338
  "gemini-3.6-flash-low": { inputPer1M: 1.50, outputPer1M: 7.50 },
339
339
  "gemini-3.6-flash-tiered": { inputPer1M: 1.50, outputPer1M: 7.50 },
340
+ // Gemini 3.7 Flash tiered — public Gemini API pricing, verified
341
+ // 2026-08-13. Introductory rates through 2026-12-31; from 2027-01-01
342
+ // these double to input 1.50 / output 7.50 per 1M tokens.
343
+ "gemini-3.7-flash-tiered": { inputPer1M: 0.75, outputPer1M: 3.75 },
340
344
  "gpt-oss-120b-medium": { inputPer1M: 2.00, outputPer1M: 10.00 },
341
345
 
342
346
  // Ollama Cloud models — mirrors MODEL_PRICING in src/types.ts
@@ -358,6 +362,20 @@ const MODEL_PRICING = {
358
362
  "nemotron-3-nano:30b": { inputPer1M: 0.50, outputPer1M: 1.50 },
359
363
  "nemotron-3-super": { inputPer1M: 0.60, outputPer1M: 1.80 },
360
364
  "nemotron-3-ultra": { inputPer1M: 0.60, outputPer1M: 1.80 },
365
+
366
+ // OpenCode Zen free models — mirrors MODEL_PRICING in src/types.ts
367
+ "deepseek-v4-flash-free": { inputPer1M: 0.14, outputPer1M: 0.28 },
368
+ "nemotron-3.5-lightning-free": { inputPer1M: 0.35, outputPer1M: 1.05 },
369
+ "nemotron-3-ultra-free": { inputPer1M: 0.60, outputPer1M: 1.80 },
370
+ "mimo-v2.5-free": { inputPer1M: 0.15, outputPer1M: 0.60 },
371
+ "hy3-free": { inputPer1M: 0.25, outputPer1M: 1.00 },
372
+ "ling-3.0-tiny-free": { inputPer1M: 0.05, outputPer1M: 0.20 },
373
+ "laguna-s-2.1-free": { inputPer1M: 0.20, outputPer1M: 0.80 },
374
+
375
+ // OpenAI Codex models — mirrors MODEL_PRICING in src/types.ts
376
+ "gpt-5.6-sol": { inputPer1M: 5.00, outputPer1M: 30.00 },
377
+ "gpt-5.6-terra": { inputPer1M: 2.00, outputPer1M: 12.00 },
378
+ "gpt-5.6-luna": { inputPer1M: 0.20, outputPer1M: 1.20 },
361
379
  };
362
380
 
363
381
  function getModelPricing(model) {
@@ -365,6 +383,7 @@ function getModelPricing(model) {
365
383
  const lower = (model || "").toLowerCase();
366
384
  if (lower.includes("opus")) return MODEL_PRICING["claude-opus-4-6-thinking"];
367
385
  if (lower.includes("sonnet")) return MODEL_PRICING["claude-sonnet-4-6"];
386
+ if (lower.includes("3.7-flash")) return MODEL_PRICING["gemini-3.7-flash-tiered"];
368
387
  if (lower.includes("3.6-flash")) return MODEL_PRICING["gemini-3.6-flash-high"];
369
388
  if (lower.includes("3.5-flash")) return MODEL_PRICING["gemini-3.5-flash-high"];
370
389
  if (lower.includes("flash")) return MODEL_PRICING["gemini-3-flash"];