tuxevil-rotator 4.0.0 → 4.2.0

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.
Files changed (52) hide show
  1. package/CHANGELOG.md +62 -0
  2. package/README.md +8 -1
  3. package/package.json +1 -1
  4. package/src/audio-transcription.ts +44 -4
  5. package/src/compat.ts +196 -222
  6. package/src/config-defaults.ts +5 -0
  7. package/src/config-overrides.ts +16 -0
  8. package/src/dashboard-live.ts +10 -8
  9. package/src/dashboard-types.ts +94 -1
  10. package/src/dashboard.ts +194 -1
  11. package/src/effort-levels.ts +43 -0
  12. package/src/effort-routing.ts +304 -0
  13. package/src/index.ts +2 -5
  14. package/src/model-catalog-revision.ts +20 -0
  15. package/src/model-catalog.ts +304 -0
  16. package/src/providers/adapter.ts +18 -0
  17. package/src/providers/google-antigravity/catalog.ts +190 -1
  18. package/src/providers/google-antigravity/forward.ts +2 -0
  19. package/src/providers/google-antigravity/index.ts +11 -0
  20. package/src/providers/google-antigravity/translators.ts +67 -14
  21. package/src/providers/ollama/index.ts +11 -1
  22. package/src/providers/ollama/quota-poll-store.ts +22 -1
  23. package/src/providers/ollama/quota.ts +95 -23
  24. package/src/providers/openai-codex/catalog.ts +9 -4
  25. package/src/providers/openai-codex/index.ts +18 -2
  26. package/src/providers/opencode-zen/index.ts +11 -2
  27. package/src/proxy.ts +143 -28
  28. package/src/rotator.ts +296 -21
  29. package/src/settings-repository.ts +36 -5
  30. package/src/types.ts +72 -26
  31. package/src/validators.ts +37 -1
  32. package/src/web/app.tsx +6 -1
  33. package/src/web/components/icons.tsx +29 -0
  34. package/src/web/components/overlays.tsx +13 -1
  35. package/src/web/components/ui.tsx +6 -1
  36. package/src/web/lib/accounts.ts +1 -0
  37. package/src/web/lib/attention.ts +12 -0
  38. package/src/web/lib/effort.ts +407 -0
  39. package/src/web/lib/models.ts +284 -0
  40. package/src/web/lib/pools.ts +53 -9
  41. package/src/web/lib/status.ts +13 -3
  42. package/src/web/nav.ts +1 -0
  43. package/src/web/pages/AccountDetail.tsx +16 -2
  44. package/src/web/pages/EffortRouting.tsx +1130 -0
  45. package/src/web/pages/Models.tsx +888 -0
  46. package/src/web/pages/Overview.tsx +31 -15
  47. package/src/web/pages/Usage.tsx +3 -3
  48. package/src/web/state/api.ts +31 -0
  49. package/src/web/state/model-catalog.ts +103 -0
  50. package/src/web/state/router.ts +150 -19
  51. package/src/web/state/store.ts +6 -6
  52. package/src/web/styles/app.css +854 -0
@@ -8,7 +8,7 @@ import type {
8
8
  DashboardRoutingAccount,
9
9
  DashboardRoutingDiagnostics,
10
10
  } from "../../dashboard-types.js";
11
- import { isOutOfService, providerRank, quotaProvider } from "./status.js";
11
+ import { isOutOfService, providerRank, providerIds, quotaProvider } from "./status.js";
12
12
 
13
13
  /** Rough requests per full quota window, used only to weight pooled capacity. */
14
14
  const TIER_CAPACITY: Record<string, number> = {
@@ -41,8 +41,10 @@ export interface ModelPool {
41
41
  members: PoolMember[];
42
42
  /** Members with quota left. */
43
43
  withQuota: number;
44
- /** Tier-weighted remaining quota, 0–100. */
44
+ /** Remaining included quota, weighted by credit allowance or account tier, 0–100. */
45
45
  capacity: number;
46
+ /** Actual included credits, summed across in-service accounts. */
47
+ credits: ModelQuota["credits"] | null;
46
48
  /** The account routing this pool now; null before its first request or after it stops being routable. */
47
49
  serving: DashboardAccount | null;
48
50
  /** Eligible accounts after `serving`, the policy's pick first. */
@@ -94,7 +96,7 @@ export function buildPools(overview: DashboardOverview, now: number): ModelPool[
94
96
  };
95
97
  byKey.set(quota.modelKey, pool);
96
98
  }
97
- if (isOutOfService(account)) continue;
99
+ if (isOutOfService(account) || account.disabledProviders?.includes(quotaProvider(quota))) continue;
98
100
  const diag = overview.routingDiagnostics[quota.modelKey];
99
101
  pool.members.push({
100
102
  account,
@@ -120,14 +122,22 @@ export function buildPools(overview: DashboardOverview, now: number): ModelPool[
120
122
  let remainingRequests = 0;
121
123
  let withQuota = 0;
122
124
  let nextResetAt: number | null = null;
125
+ let credits: ModelQuota["credits"] | null = null;
123
126
 
124
127
  for (const member of pool.members) {
125
- const weight = tierWeight(member.account.tier);
128
+ const credit = member.quota.credits;
129
+ const weight = credit?.allowanceUsd ?? tierWeight(member.account.tier);
130
+ if (credit) {
131
+ credits ??= { balanceUsd: 0, allowanceUsd: 0, purchasedUsd: 0 };
132
+ credits.balanceUsd += credit.balanceUsd;
133
+ credits.allowanceUsd += credit.allowanceUsd;
134
+ credits.purchasedUsd += credit.purchasedUsd;
135
+ }
126
136
  const pct = Math.max(0, Math.min(100, member.quota.percentRemaining || 0));
127
137
  weighted += pct * weight;
128
138
  weightTotal += weight;
129
139
  remainingRequests += (pct / 100) * weight;
130
- if (pct > 0) withQuota += 1;
140
+ if (pct > 0 || (credit?.purchasedUsd ?? 0) > 0) withQuota += 1;
131
141
  if (member.quota.resetTime && member.quota.timerType !== "fresh") {
132
142
  const resetAt = Date.parse(member.quota.resetTime);
133
143
  const remaining = resetAt - now;
@@ -154,9 +164,14 @@ export function buildPools(overview: DashboardOverview, now: number): ModelPool[
154
164
  .filter((a): a is DashboardAccount => Boolean(a))
155
165
  .slice(0, 2);
156
166
 
157
- const capacity = weightTotal > 0 ? Math.round(weighted / weightTotal) : 0;
167
+ const capacity = credits && credits.allowanceUsd > 0
168
+ ? Math.max(0, Math.min(100, Math.round(credits.balanceUsd / credits.allowanceUsd * 100)))
169
+ : weightTotal > 0 ? Math.round(weighted / weightTotal) : 0;
170
+ const availableCapacity = credits && credits.allowanceUsd > 0
171
+ ? (credits.balanceUsd + credits.purchasedUsd) / credits.allowanceUsd * 100
172
+ : capacity;
158
173
  const burnPerHour = burnByPool[key] || 0;
159
- const hoursLeft = burnPerHour > 0 ? remainingRequests / burnPerHour : null;
174
+ const hoursLeft = !credits && burnPerHour > 0 ? remainingRequests / burnPerHour : null;
160
175
  const breaker = overview.circuitBreakers.model[key];
161
176
  const breakerUntil = breaker && breaker > now ? breaker : null;
162
177
 
@@ -164,8 +179,8 @@ export function buildPools(overview: DashboardOverview, now: number): ModelPool[
164
179
  if (breakerUntil || (pool.members.length > 0 && withQuota === 0)) state = "blocked";
165
180
  else if (diagnostics && !diagnostics.selectedEmail && diagnostics.availableCandidates === 0)
166
181
  state = "blocked";
167
- else if (capacity === 0) state = "empty";
168
- else if (capacity < 20) state = "low";
182
+ else if (availableCapacity === 0) state = "empty";
183
+ else if (availableCapacity < 20) state = "low";
169
184
 
170
185
  pools.push({
171
186
  key,
@@ -174,6 +189,7 @@ export function buildPools(overview: DashboardOverview, now: number): ModelPool[
174
189
  members: pool.members,
175
190
  withQuota,
176
191
  capacity,
192
+ credits,
177
193
  serving,
178
194
  nextUp,
179
195
  nextResetAt,
@@ -197,3 +213,31 @@ export function buildPools(overview: DashboardOverview, now: number): ModelPool[
197
213
  a.name.localeCompare(b.name),
198
214
  );
199
215
  }
216
+
217
+ export interface ProviderGroup {
218
+ provider: string;
219
+ accounts: DashboardAccount[];
220
+ pools: ModelPool[];
221
+ }
222
+
223
+ /** Connected providers remain visible even before their first successful quota poll. */
224
+ export function buildProviderGroups(overview: DashboardOverview, now: number): ProviderGroup[] {
225
+ const groups = new Map<string, ProviderGroup>();
226
+ const ensure = (provider: string): ProviderGroup => {
227
+ let group = groups.get(provider);
228
+ if (!group) {
229
+ group = { provider, accounts: [], pools: [] };
230
+ groups.set(provider, group);
231
+ }
232
+ return group;
233
+ };
234
+ for (const account of overview.accounts) {
235
+ const providers = new Set([
236
+ ...providerIds(account),
237
+ ...account.quota.map(quotaProvider),
238
+ ]);
239
+ for (const provider of providers) ensure(provider).accounts.push(account);
240
+ }
241
+ for (const pool of buildPools(overview, now)) ensure(pool.provider).pools.push(pool);
242
+ return [...groups.values()].sort((a, b) => providerRank(a.provider) - providerRank(b.provider));
243
+ }
@@ -57,6 +57,12 @@ export const ACCOUNT_STATUS: Record<AccountState, StatusMeta> = {
57
57
  description:
58
58
  "Flagged by the provider or quarantined by an operator. Excluded from routing until restored.",
59
59
  },
60
+ off: {
61
+ label: "Off",
62
+ tone: "muted",
63
+ description:
64
+ "Every provider on this account is turned off on the Models page. It stays signed in and gets no traffic.",
65
+ },
60
66
  };
61
67
 
62
68
  export function accountStatus(state: AccountState): StatusMeta {
@@ -71,16 +77,20 @@ export function isCooling(account: { status: AccountState }): boolean {
71
77
  return account.status === "cooldown" || account.status === "exhausted";
72
78
  }
73
79
 
74
- export function needsAttention(account: { status: AccountState }): boolean {
80
+ export function needsAttention(account: {
81
+ status: AccountState;
82
+ invalidProviders?: Record<string, string>;
83
+ }): boolean {
75
84
  return (
76
85
  account.status === "error" ||
77
86
  account.status === "disabled" ||
78
- account.status === "flagged"
87
+ account.status === "flagged" ||
88
+ Boolean(account.invalidProviders?.["openai-codex"])
79
89
  );
80
90
  }
81
91
 
82
92
  export function isOutOfService(account: { status: AccountState }): boolean {
83
- return account.status === "disabled" || account.status === "flagged";
93
+ return account.status === "disabled" || account.status === "flagged" || account.status === "off";
84
94
  }
85
95
 
86
96
  export const ROUTING_STATE: Record<RoutingHealthState, StatusMeta> = {
package/src/web/nav.ts CHANGED
@@ -16,6 +16,7 @@ export interface NavItem {
16
16
  export const NAV: NavItem[] = [
17
17
  { id: "overview", label: "Overview", icon: "overview", href: BASE, keywords: "home status health models pools" },
18
18
  { id: "accounts", label: "Accounts", icon: "accounts", href: `${BASE}/accounts`, keywords: "providers quota" },
19
+ { id: "models", label: "Models", icon: "models", href: `${BASE}/models`, keywords: "providers order enable disable catalog" },
19
20
  { id: "requests", label: "Requests", icon: "requests", href: `${BASE}/requests`, keywords: "traffic logs history live" },
20
21
  { id: "usage", label: "Usage", icon: "usage", href: `${BASE}/usage`, keywords: "tokens savings latency heatmap" },
21
22
  { id: "keys", label: "Virtual keys", icon: "keys", href: `${BASE}/keys`, keywords: "api clients" },
@@ -3,7 +3,7 @@
3
3
  import type { JSX } from "preact";
4
4
  import type { AccountTier, ModelQuota } from "../../types.js";
5
5
  import type { DashboardAccount, DashboardOverview } from "../../dashboard-types.js";
6
- import { formatCount } from "../lib/format.js";
6
+ import { formatCount, formatUsd } from "../lib/format.js";
7
7
  import {
8
8
  ACCOUNT_TIERS,
9
9
  accountStatus,
@@ -27,6 +27,7 @@ import {
27
27
  Button,
28
28
  Countdown,
29
29
  KeyValue,
30
+ Link,
30
31
  Meter,
31
32
  Pill,
32
33
  ProviderTags,
@@ -34,6 +35,7 @@ import {
34
35
  StatusPill,
35
36
  } from "../components/ui.js";
36
37
  import { accountMenuItems } from "./Accounts.js";
38
+ import { providerPath } from "../state/router.js";
37
39
 
38
40
  export function AccountDetail({ email, onClose }: { email: string; onClose: () => void }): JSX.Element {
39
41
  const data = overview.value!;
@@ -210,7 +212,8 @@ function ProviderProblems({ account }: { account: DashboardAccount }): JSX.Eleme
210
212
  const invalid = Object.entries(account.invalidProviders || {});
211
213
  const cooldowns = Object.entries(account.providerCooldowns || {}).filter(([, until]) => until > now.value);
212
214
  const modelCooldowns = Object.entries(account.cooldownsByModel || {}).filter(([, until]) => until > now.value);
213
- if (invalid.length === 0 && cooldowns.length === 0 && modelCooldowns.length === 0) return null;
215
+ const turnedOff = account.disabledProviders ?? [];
216
+ if (invalid.length === 0 && cooldowns.length === 0 && modelCooldowns.length === 0 && turnedOff.length === 0) return null;
214
217
  return (
215
218
  <section class="callout tone-warn">
216
219
  <Icon name="clock" size={16} />
@@ -230,6 +233,11 @@ function ProviderProblems({ account }: { account: DashboardAccount }): JSX.Eleme
230
233
  <strong>{providerLabel(provider)}</strong> credential rejected: {masker.value.text(reason)}
231
234
  </div>
232
235
  ))}
236
+ {turnedOff.map((provider) => (
237
+ <div key={`o-${provider}`}>
238
+ <strong>{providerLabel(provider)}</strong> is turned off for this account. <Link href={providerPath(provider)}>Manage</Link>
239
+ </div>
240
+ ))}
233
241
  </div>
234
242
  </section>
235
243
  );
@@ -248,6 +256,12 @@ function QuotaRow({ account, quota, inactive }: { account: DashboardAccount; quo
248
256
  <span class="num quota-pct">{quota.percentRemaining}%</span>
249
257
  </div>
250
258
  <Meter value={quota.percentRemaining} label={`${quota.displayName} quota remaining`} />
259
+ {quota.credits && (
260
+ <p class="cell-sub num">
261
+ {formatUsd(quota.credits.balanceUsd)} / {formatUsd(quota.credits.allowanceUsd)} included credits remaining
262
+ {quota.credits.purchasedUsd > 0 && <> · {formatUsd(quota.credits.purchasedUsd)} purchased credits</>}
263
+ </p>
264
+ )}
251
265
  <div class="quota-meta">
252
266
  <span>{TIMER_LABELS[quota.timerType] ?? quota.timerType}</span>
253
267
  {quota.timerType !== "fresh" && resetAt && resetAt > now.value && (