tuxevil-rotator 4.0.0 → 4.1.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.
- package/CHANGELOG.md +37 -0
- package/README.md +6 -1
- package/package.json +1 -1
- package/src/audio-transcription.ts +44 -4
- package/src/compat.ts +196 -222
- package/src/config-defaults.ts +5 -0
- package/src/dashboard-live.ts +10 -8
- package/src/dashboard-types.ts +39 -1
- package/src/dashboard.ts +156 -1
- package/src/model-catalog-revision.ts +17 -0
- package/src/model-catalog.ts +302 -0
- package/src/providers/adapter.ts +18 -0
- package/src/providers/google-antigravity/catalog.ts +190 -1
- package/src/providers/google-antigravity/forward.ts +2 -0
- package/src/providers/google-antigravity/index.ts +11 -0
- package/src/providers/google-antigravity/translators.ts +4 -0
- package/src/providers/ollama/index.ts +11 -1
- package/src/providers/ollama/quota-poll-store.ts +22 -1
- package/src/providers/ollama/quota.ts +95 -23
- package/src/providers/openai-codex/index.ts +18 -2
- package/src/providers/opencode-zen/index.ts +11 -2
- package/src/proxy.ts +143 -28
- package/src/rotator.ts +219 -10
- package/src/settings-repository.ts +36 -5
- package/src/types.ts +68 -26
- package/src/validators.ts +35 -0
- package/src/web/app.tsx +4 -0
- package/src/web/components/icons.tsx +29 -0
- package/src/web/components/ui.tsx +6 -1
- package/src/web/lib/accounts.ts +1 -0
- package/src/web/lib/attention.ts +12 -0
- package/src/web/lib/models.ts +279 -0
- package/src/web/lib/pools.ts +53 -9
- package/src/web/lib/status.ts +13 -3
- package/src/web/nav.ts +1 -0
- package/src/web/pages/AccountDetail.tsx +16 -2
- package/src/web/pages/Models.tsx +852 -0
- package/src/web/pages/Overview.tsx +31 -15
- package/src/web/pages/Usage.tsx +3 -3
- package/src/web/state/api.ts +18 -0
- package/src/web/state/model-catalog.ts +103 -0
- package/src/web/state/router.ts +24 -16
- package/src/web/state/store.ts +6 -6
- package/src/web/styles/app.css +294 -0
package/src/validators.ts
CHANGED
|
@@ -6,6 +6,7 @@ import {
|
|
|
6
6
|
type Config,
|
|
7
7
|
} from "./types.js";
|
|
8
8
|
import { getProxyConfigurationError } from "./providers/proxy-dispatcher.js";
|
|
9
|
+
import { PROVIDER_ORDER } from "./providers/credential-helpers.js";
|
|
9
10
|
import { isCodexRequestModel } from "./providers/openai-codex/catalog.js";
|
|
10
11
|
import { isOpenCodeZenModel } from "./providers/opencode-zen/catalog.js";
|
|
11
12
|
|
|
@@ -43,6 +44,15 @@ function isNonNegativeInteger(value: unknown): value is number {
|
|
|
43
44
|
return isNonNegativeNumber(value) && Number.isInteger(value);
|
|
44
45
|
}
|
|
45
46
|
|
|
47
|
+
function isStringArray(value: unknown): value is string[] {
|
|
48
|
+
return Array.isArray(value) && value.every(isNonEmptyString);
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
function isProviderModelKey(value: string): boolean {
|
|
52
|
+
const slash = value.indexOf("/");
|
|
53
|
+
return slash > 0 && slash < value.length - 1 && PROVIDER_ORDER.includes(value.slice(0, slash));
|
|
54
|
+
}
|
|
55
|
+
|
|
46
56
|
function isKnownNonGoogleModel(model: string): boolean {
|
|
47
57
|
const trimmed = model.trim();
|
|
48
58
|
if (!trimmed) return false;
|
|
@@ -346,6 +356,29 @@ export function validateConfig(value: unknown): ValidationResult<Config> {
|
|
|
346
356
|
}
|
|
347
357
|
}
|
|
348
358
|
|
|
359
|
+
for (const field of ["providerOrder", "disabledProviders"] as const) {
|
|
360
|
+
const list = value[field];
|
|
361
|
+
if (list === undefined) continue;
|
|
362
|
+
if (!isStringArray(list)) {
|
|
363
|
+
errors.push(`config.${field} must be an array of provider ids`);
|
|
364
|
+
continue;
|
|
365
|
+
}
|
|
366
|
+
const unknown = list.filter((id) => !PROVIDER_ORDER.includes(id));
|
|
367
|
+
if (unknown.length > 0) {
|
|
368
|
+
errors.push(`config.${field} has unknown providers: ${unknown.join(", ")}. Known: ${PROVIDER_ORDER.join(", ")}`);
|
|
369
|
+
}
|
|
370
|
+
}
|
|
371
|
+
for (const field of ["disabledModels", "reviewedModels"] as const) {
|
|
372
|
+
const list = value[field];
|
|
373
|
+
if (list === undefined) continue;
|
|
374
|
+
if (!isStringArray(list) || !list.every(isProviderModelKey)) {
|
|
375
|
+
errors.push(`config.${field} must be an array of "<provider>/<model>" entries, e.g. "ollama/gpt-oss:20b"`);
|
|
376
|
+
}
|
|
377
|
+
}
|
|
378
|
+
if (value.autoEnableNewModels !== undefined && typeof value.autoEnableNewModels !== "boolean") {
|
|
379
|
+
errors.push("config.autoEnableNewModels must be a boolean");
|
|
380
|
+
}
|
|
381
|
+
|
|
349
382
|
return errors.length > 0 ? fail(errors) : ok(value as unknown as Config);
|
|
350
383
|
}
|
|
351
384
|
|
|
@@ -356,6 +389,7 @@ export interface MinimalProxyRequestBody {
|
|
|
356
389
|
requestType?: string;
|
|
357
390
|
userAgent?: string;
|
|
358
391
|
requestId?: string;
|
|
392
|
+
requestedModel?: string;
|
|
359
393
|
[key: string]: unknown;
|
|
360
394
|
}
|
|
361
395
|
|
|
@@ -369,6 +403,7 @@ export function validateProxyRequestBody(value: unknown): ValidationResult<Minim
|
|
|
369
403
|
if (value.requestType !== undefined && typeof value.requestType !== "string") errors.push("body.requestType must be a string when provided");
|
|
370
404
|
if (value.userAgent !== undefined && typeof value.userAgent !== "string") errors.push("body.userAgent must be a string when provided");
|
|
371
405
|
if (value.requestId !== undefined && typeof value.requestId !== "string") errors.push("body.requestId must be a string when provided");
|
|
406
|
+
if (value.requestedModel !== undefined && typeof value.requestedModel !== "string") errors.push("body.requestedModel must be a string when provided");
|
|
372
407
|
|
|
373
408
|
return errors.length > 0 ? fail(errors) : ok(value as MinimalProxyRequestBody);
|
|
374
409
|
}
|
package/src/web/app.tsx
CHANGED
|
@@ -30,6 +30,7 @@ import { AsyncButton, Button, Link, Spinner } from "./components/ui.js";
|
|
|
30
30
|
import { OverviewPage } from "./pages/Overview.js";
|
|
31
31
|
import { AccountsPage } from "./pages/Accounts.js";
|
|
32
32
|
import { AccountDetail } from "./pages/AccountDetail.js";
|
|
33
|
+
import { ModelsPage } from "./pages/Models.js";
|
|
33
34
|
import { RequestsPage } from "./pages/Requests.js";
|
|
34
35
|
import { UsagePage } from "./pages/Usage.js";
|
|
35
36
|
import { KeysPage } from "./pages/Keys.js";
|
|
@@ -124,6 +125,9 @@ function Shell(): JSX.Element {
|
|
|
124
125
|
case "accounts":
|
|
125
126
|
page = <AccountsPage />;
|
|
126
127
|
break;
|
|
128
|
+
case "models":
|
|
129
|
+
page = <ModelsPage />;
|
|
130
|
+
break;
|
|
127
131
|
case "requests":
|
|
128
132
|
page = <RequestsPage />;
|
|
129
133
|
break;
|
|
@@ -138,6 +138,35 @@ const PATHS = {
|
|
|
138
138
|
</>
|
|
139
139
|
),
|
|
140
140
|
chevronRight: <path d="m9 18 6-6-6-6" />,
|
|
141
|
+
arrowUp: (
|
|
142
|
+
<>
|
|
143
|
+
<path d="M12 19V5" />
|
|
144
|
+
<path d="m5 12 7-7 7 7" />
|
|
145
|
+
</>
|
|
146
|
+
),
|
|
147
|
+
arrowDown: (
|
|
148
|
+
<>
|
|
149
|
+
<path d="M12 5v14" />
|
|
150
|
+
<path d="m19 12-7 7-7-7" />
|
|
151
|
+
</>
|
|
152
|
+
),
|
|
153
|
+
models: (
|
|
154
|
+
<>
|
|
155
|
+
<path d="M12.83 2.18a2 2 0 0 0-1.66 0L2.6 6.08a1 1 0 0 0 0 1.83l8.58 3.91a2 2 0 0 0 1.66 0l8.58-3.9a1 1 0 0 0 0-1.83Z" />
|
|
156
|
+
<path d="m22 17.65-9.17 4.16a2 2 0 0 1-1.66 0L2 17.65" />
|
|
157
|
+
<path d="m22 12.65-9.17 4.16a2 2 0 0 1-1.66 0L2 12.65" />
|
|
158
|
+
</>
|
|
159
|
+
),
|
|
160
|
+
grip: (
|
|
161
|
+
<>
|
|
162
|
+
<circle cx="9" cy="6" r="1" />
|
|
163
|
+
<circle cx="15" cy="6" r="1" />
|
|
164
|
+
<circle cx="9" cy="12" r="1" />
|
|
165
|
+
<circle cx="15" cy="12" r="1" />
|
|
166
|
+
<circle cx="9" cy="18" r="1" />
|
|
167
|
+
<circle cx="15" cy="18" r="1" />
|
|
168
|
+
</>
|
|
169
|
+
),
|
|
141
170
|
chevronDown: <path d="m6 9 6 6 6-6" />,
|
|
142
171
|
chevronLeft: <path d="m15 18-6-6 6-6" />,
|
|
143
172
|
more: (
|
|
@@ -154,12 +154,16 @@ export function Switch({
|
|
|
154
154
|
checked,
|
|
155
155
|
onChange,
|
|
156
156
|
label,
|
|
157
|
+
ariaLabel,
|
|
157
158
|
description,
|
|
158
159
|
disabled,
|
|
159
160
|
}: {
|
|
160
161
|
checked: boolean;
|
|
161
162
|
onChange: (next: boolean) => void | Promise<unknown>;
|
|
163
|
+
/** Visible text; empty for a bare switch, which then needs `ariaLabel`. */
|
|
162
164
|
label: string;
|
|
165
|
+
/** Accessible name when the visible label alone is not descriptive. */
|
|
166
|
+
ariaLabel?: string;
|
|
163
167
|
description?: ComponentChildren;
|
|
164
168
|
disabled?: boolean;
|
|
165
169
|
}): JSX.Element {
|
|
@@ -170,6 +174,7 @@ export function Switch({
|
|
|
170
174
|
type="button"
|
|
171
175
|
role="switch"
|
|
172
176
|
aria-checked={checked}
|
|
177
|
+
aria-label={ariaLabel}
|
|
173
178
|
class={`switch${checked ? " is-on" : ""}`}
|
|
174
179
|
disabled={disabled || busy}
|
|
175
180
|
onClick={async () => {
|
|
@@ -184,7 +189,7 @@ export function Switch({
|
|
|
184
189
|
<span class="switch-track" aria-hidden="true">
|
|
185
190
|
<span class="switch-thumb" />
|
|
186
191
|
</span>
|
|
187
|
-
<span class="switch-label">{label}</span>
|
|
192
|
+
{label && <span class="switch-label">{label}</span>}
|
|
188
193
|
</button>
|
|
189
194
|
{description && <div class="switch-description">{description}</div>}
|
|
190
195
|
</div>
|
package/src/web/lib/accounts.ts
CHANGED
package/src/web/lib/attention.ts
CHANGED
|
@@ -127,6 +127,18 @@ export function buildAttention(
|
|
|
127
127
|
}
|
|
128
128
|
|
|
129
129
|
for (const account of accounts) {
|
|
130
|
+
const codexCredentialError = account.invalidProviders?.["openai-codex"];
|
|
131
|
+
if (codexCredentialError) {
|
|
132
|
+
items.push({
|
|
133
|
+
id: `codex-credential:${account.email}`,
|
|
134
|
+
severity: "warning",
|
|
135
|
+
title: `Codex credential rejected for ${name(account.email)}`,
|
|
136
|
+
detail: truncate(codexCredentialError, 220),
|
|
137
|
+
hint: "Open this account to review the rejected Codex credential and re-authenticate it.",
|
|
138
|
+
actions: [{ kind: "open-account", email: account.email }],
|
|
139
|
+
});
|
|
140
|
+
}
|
|
141
|
+
|
|
130
142
|
if (account.status === "flagged") {
|
|
131
143
|
items.push({
|
|
132
144
|
id: `flagged:${account.email}`,
|
|
@@ -0,0 +1,279 @@
|
|
|
1
|
+
// Models page: one row per model id across providers, and a summary per
|
|
2
|
+
// provider built from the catalog API and the live overview.
|
|
3
|
+
|
|
4
|
+
import type {
|
|
5
|
+
CatalogModelEntry,
|
|
6
|
+
CatalogProvider,
|
|
7
|
+
DashboardAccount,
|
|
8
|
+
DashboardOverview,
|
|
9
|
+
ModelCatalogResponse,
|
|
10
|
+
} from "../../dashboard-types.js";
|
|
11
|
+
import type { ModelQuota } from "../../types.js";
|
|
12
|
+
import { buildPools } from "./pools.js";
|
|
13
|
+
import { canServe, providerIds, quotaProvider } from "./status.js";
|
|
14
|
+
|
|
15
|
+
/** Two-letter marks and hues for provider monograms. */
|
|
16
|
+
export const PROVIDER_MARKS: Record<string, { mark: string; hue: number }> = {
|
|
17
|
+
"google-antigravity": { mark: "AG", hue: 215 },
|
|
18
|
+
"openai-codex": { mark: "CX", hue: 165 },
|
|
19
|
+
ollama: { mark: "OL", hue: 28 },
|
|
20
|
+
"opencode-zen": { mark: "ZN", hue: 280 },
|
|
21
|
+
};
|
|
22
|
+
|
|
23
|
+
export function providerMark(id: string): { mark: string; hue: number } {
|
|
24
|
+
return PROVIDER_MARKS[id] ?? { mark: id.slice(0, 2).toUpperCase(), hue: 250 };
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
/** Config key for one provider's copy of a model. */
|
|
28
|
+
export function offeringKey(entry: Pick<CatalogModelEntry, "providerId" | "id">): string {
|
|
29
|
+
return `${entry.providerId}/${entry.id}`;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
export function isServed(entry: CatalogModelEntry): boolean {
|
|
33
|
+
return entry.offReason === null;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
export interface ModelRow {
|
|
37
|
+
/** Lower-cased id: one row per id across providers. */
|
|
38
|
+
key: string;
|
|
39
|
+
id: string;
|
|
40
|
+
/** Every provider that lists the id, in provider order. */
|
|
41
|
+
offerings: CatalogModelEntry[];
|
|
42
|
+
/** Served by at least one provider. */
|
|
43
|
+
on: boolean;
|
|
44
|
+
/** Listed by more than one provider. */
|
|
45
|
+
shared: boolean;
|
|
46
|
+
/** Waiting for review on at least one provider. */
|
|
47
|
+
waiting: boolean;
|
|
48
|
+
/** Requests in the last hour. */
|
|
49
|
+
requests: number;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
export function buildModelRows(
|
|
53
|
+
catalog: ModelCatalogResponse,
|
|
54
|
+
requestsByModel: Record<string, number>,
|
|
55
|
+
): ModelRow[] {
|
|
56
|
+
const requests = new Map<string, number>();
|
|
57
|
+
for (const [model, count] of Object.entries(requestsByModel)) {
|
|
58
|
+
const key = model.toLowerCase();
|
|
59
|
+
requests.set(key, (requests.get(key) ?? 0) + count);
|
|
60
|
+
}
|
|
61
|
+
const rows = new Map<string, ModelRow>();
|
|
62
|
+
for (const entry of catalog.models) {
|
|
63
|
+
const key = entry.id.toLowerCase();
|
|
64
|
+
const row = rows.get(key) ?? {
|
|
65
|
+
key,
|
|
66
|
+
id: entry.id,
|
|
67
|
+
offerings: [],
|
|
68
|
+
on: false,
|
|
69
|
+
shared: false,
|
|
70
|
+
waiting: false,
|
|
71
|
+
requests: requests.get(key) ?? 0,
|
|
72
|
+
};
|
|
73
|
+
row.offerings.push(entry);
|
|
74
|
+
row.on ||= isServed(entry);
|
|
75
|
+
row.waiting ||= entry.modelSwitch === "review";
|
|
76
|
+
row.shared = row.offerings.length > 1;
|
|
77
|
+
rows.set(key, row);
|
|
78
|
+
}
|
|
79
|
+
return [...rows.values()];
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
export type ModelFilter = "all" | "on" | "off" | "shared" | "waiting";
|
|
83
|
+
|
|
84
|
+
export const MODEL_FILTERS: Array<{ id: ModelFilter; label: string; match: (row: ModelRow) => boolean }> = [
|
|
85
|
+
{ id: "all", label: "All", match: () => true },
|
|
86
|
+
{ id: "on", label: "On", match: (row) => row.on },
|
|
87
|
+
{ id: "off", label: "Off", match: (row) => !row.on },
|
|
88
|
+
{ id: "shared", label: "Shared", match: (row) => row.shared },
|
|
89
|
+
{ id: "waiting", label: "Waiting for review", match: (row) => row.waiting },
|
|
90
|
+
];
|
|
91
|
+
|
|
92
|
+
export function isModelFilter(value: unknown): value is ModelFilter {
|
|
93
|
+
return MODEL_FILTERS.some((filter) => filter.id === value);
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
export type ModelSort = "requests" | "name";
|
|
97
|
+
|
|
98
|
+
export function filterModelRows(
|
|
99
|
+
rows: ModelRow[],
|
|
100
|
+
options: { filter: ModelFilter; provider: string; query: string },
|
|
101
|
+
): ModelRow[] {
|
|
102
|
+
const match = MODEL_FILTERS.find((filter) => filter.id === options.filter)?.match ?? (() => true);
|
|
103
|
+
const query = options.query.trim().toLowerCase();
|
|
104
|
+
return rows.filter(
|
|
105
|
+
(row) =>
|
|
106
|
+
match(row) &&
|
|
107
|
+
(!options.provider || row.offerings.some((entry) => entry.providerId === options.provider)) &&
|
|
108
|
+
(!query || row.offerings.some((entry) => entry.id.toLowerCase().includes(query))),
|
|
109
|
+
);
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
/** Busiest first, then by name; models that are off sink below the rest. */
|
|
113
|
+
export function sortModelRows(rows: ModelRow[], sort: ModelSort): ModelRow[] {
|
|
114
|
+
return [...rows].sort((a, b) => {
|
|
115
|
+
if (a.on !== b.on) return a.on ? -1 : 1;
|
|
116
|
+
if (sort === "requests" && a.requests !== b.requests) return b.requests - a.requests;
|
|
117
|
+
return a.id.localeCompare(b.id);
|
|
118
|
+
});
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
export type ProviderState = "off" | "not-connected" | "needs-sign-in" | "unavailable" | "healthy";
|
|
122
|
+
|
|
123
|
+
export interface ProviderQuota {
|
|
124
|
+
key: string;
|
|
125
|
+
name: string;
|
|
126
|
+
/** Tier-weighted remaining quota across in-service accounts, 0–100. */
|
|
127
|
+
percent: number;
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
export interface ProviderSummary {
|
|
131
|
+
provider: CatalogProvider;
|
|
132
|
+
/** 0-based position in the routing order. */
|
|
133
|
+
rank: number;
|
|
134
|
+
/** Accounts holding a credential for this provider. */
|
|
135
|
+
accounts: DashboardAccount[];
|
|
136
|
+
/** Accounts that can serve this provider now. */
|
|
137
|
+
canServe: number;
|
|
138
|
+
/** Accounts whose credential for this provider was rejected. */
|
|
139
|
+
rejected: DashboardAccount[];
|
|
140
|
+
models: number;
|
|
141
|
+
modelsOn: number;
|
|
142
|
+
quotas: ProviderQuota[];
|
|
143
|
+
state: ProviderState;
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
export function hasProvider(account: DashboardAccount, providerId: string): boolean {
|
|
147
|
+
return providerIds(account).includes(providerId);
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
export function isTurnedOffForAccount(account: DashboardAccount, providerId: string): boolean {
|
|
151
|
+
return account.disabledProviders?.includes(providerId) ?? false;
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
/** Account can take this provider's traffic now. */
|
|
155
|
+
export function canServeProvider(
|
|
156
|
+
account: DashboardAccount,
|
|
157
|
+
providerId: string,
|
|
158
|
+
now: number,
|
|
159
|
+
routing?: {
|
|
160
|
+
quotaPools: readonly string[];
|
|
161
|
+
diagnostics: DashboardOverview["routingDiagnostics"];
|
|
162
|
+
},
|
|
163
|
+
): boolean {
|
|
164
|
+
if (
|
|
165
|
+
!canServe(account) ||
|
|
166
|
+
account.invalidProviders?.[providerId] ||
|
|
167
|
+
(account.providerCooldowns?.[providerId] ?? 0) > now ||
|
|
168
|
+
isTurnedOffForAccount(account, providerId)
|
|
169
|
+
) return false;
|
|
170
|
+
|
|
171
|
+
const quotas = providerQuotaRows(account, providerId);
|
|
172
|
+
const pools = new Set(routing?.quotaPools.length ? routing.quotaPools : quotas.map((quota) => quota.modelKey));
|
|
173
|
+
if (pools.size === 0) return true;
|
|
174
|
+
return [...pools].some((key) => {
|
|
175
|
+
const diagnostics = routing?.diagnostics[key]?.accounts ?? [];
|
|
176
|
+
const identified = account.id ? diagnostics.filter((entry) => entry.id === account.id) : [];
|
|
177
|
+
const byEmail = diagnostics.filter((entry) => entry.email === account.email);
|
|
178
|
+
// A legacy producer may omit identity. Email is usable only if unique
|
|
179
|
+
// and must never replace a different identity supplied by the server.
|
|
180
|
+
const diagnostic = identified.length === 1
|
|
181
|
+
? identified[0]
|
|
182
|
+
: identified.length === 0 && byEmail.length === 1 && (!account.id || !byEmail[0].id)
|
|
183
|
+
? byEmail[0]
|
|
184
|
+
: null;
|
|
185
|
+
if (diagnostic) return diagnostic.rejectedReason === null;
|
|
186
|
+
if ((account.cooldownsByModel[key] ?? 0) > now) return false;
|
|
187
|
+
// Missing and negative quota mean unknown, which routing permits.
|
|
188
|
+
return quotas.find((quota) => quota.modelKey === key)?.percentRemaining !== 0;
|
|
189
|
+
});
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
export function providerQuotaRows(account: DashboardAccount, providerId: string): ModelQuota[] {
|
|
193
|
+
return (account.quota ?? []).filter((quota) => quotaProvider(quota) === providerId);
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
export function summarizeProviders(
|
|
197
|
+
catalog: ModelCatalogResponse,
|
|
198
|
+
overview: DashboardOverview,
|
|
199
|
+
now: number,
|
|
200
|
+
): ProviderSummary[] {
|
|
201
|
+
const pools = buildPools(overview, now);
|
|
202
|
+
return catalog.providers.map((provider, rank) => {
|
|
203
|
+
const accounts = overview.accounts.filter((account) => hasProvider(account, provider.id));
|
|
204
|
+
const rejected = accounts.filter((account) => Boolean(account.invalidProviders?.[provider.id]));
|
|
205
|
+
const models = catalog.models.filter((entry) => entry.providerId === provider.id);
|
|
206
|
+
const routing = { quotaPools: models.map((entry) => entry.quotaPool), diagnostics: overview.routingDiagnostics };
|
|
207
|
+
const servable = accounts.filter((account) => canServeProvider(account, provider.id, now, routing)).length;
|
|
208
|
+
const state: ProviderState = !provider.enabled
|
|
209
|
+
? "off"
|
|
210
|
+
: accounts.length === 0
|
|
211
|
+
? "not-connected"
|
|
212
|
+
: rejected.length > 0
|
|
213
|
+
? "needs-sign-in"
|
|
214
|
+
: servable === 0
|
|
215
|
+
? "unavailable"
|
|
216
|
+
: "healthy";
|
|
217
|
+
return {
|
|
218
|
+
provider,
|
|
219
|
+
rank,
|
|
220
|
+
accounts,
|
|
221
|
+
canServe: servable,
|
|
222
|
+
rejected,
|
|
223
|
+
models: models.length,
|
|
224
|
+
modelsOn: models.filter(isServed).length,
|
|
225
|
+
quotas: pools
|
|
226
|
+
.filter((pool) => pool.provider === provider.id && pool.members.length > 0)
|
|
227
|
+
.map((pool) => ({ key: pool.key, name: pool.name, percent: pool.capacity })),
|
|
228
|
+
state,
|
|
229
|
+
};
|
|
230
|
+
});
|
|
231
|
+
}
|
|
232
|
+
|
|
233
|
+
/** Move one provider up or down the routing order. */
|
|
234
|
+
export function moveProvider(order: string[], id: string, offset: number): string[] {
|
|
235
|
+
const from = order.indexOf(id);
|
|
236
|
+
const to = from + offset;
|
|
237
|
+
if (from < 0 || to < 0 || to >= order.length) return order;
|
|
238
|
+
const next = [...order];
|
|
239
|
+
next.splice(from, 1);
|
|
240
|
+
next.splice(to, 0, id);
|
|
241
|
+
return next;
|
|
242
|
+
}
|
|
243
|
+
|
|
244
|
+
/** Drop `id` just before or after `targetId` (drag and drop). */
|
|
245
|
+
export function placeProvider(order: string[], id: string, targetId: string, after: boolean): string[] {
|
|
246
|
+
if (id === targetId) return order;
|
|
247
|
+
const next = order.filter((entry) => entry !== id);
|
|
248
|
+
const at = next.indexOf(targetId);
|
|
249
|
+
if (at < 0 || !order.includes(id)) return order;
|
|
250
|
+
next.splice(after ? at + 1 : at, 0, id);
|
|
251
|
+
return next;
|
|
252
|
+
}
|
|
253
|
+
|
|
254
|
+
/** Context windows as people say them: 128K, 1M, 1.05M. */
|
|
255
|
+
export function formatContextWindow(tokens: number | null): string {
|
|
256
|
+
if (tokens === null || !Number.isFinite(tokens) || tokens <= 0) return "—";
|
|
257
|
+
if (tokens >= 1_000_000) {
|
|
258
|
+
const millions = tokens % 1_048_576 === 0 ? tokens / 1_048_576 : tokens / 1_000_000;
|
|
259
|
+
return `${Number(millions.toFixed(2))}M`;
|
|
260
|
+
}
|
|
261
|
+
if (tokens % 1000 === 0) return `${tokens / 1000}K`;
|
|
262
|
+
if (tokens % 1024 === 0) return `${tokens / 1024}K`;
|
|
263
|
+
return `${Math.round(tokens / 1000)}K`;
|
|
264
|
+
}
|
|
265
|
+
|
|
266
|
+
const POOL_NAMES: Record<string, string> = {
|
|
267
|
+
claude: "Claude",
|
|
268
|
+
gemini: "Gemini",
|
|
269
|
+
monthly: "Monthly",
|
|
270
|
+
session: "Session",
|
|
271
|
+
weekly: "Weekly",
|
|
272
|
+
"openai-codex": "Codex",
|
|
273
|
+
"openai-codex-spark": "Codex Spark",
|
|
274
|
+
"opencode-zen": "Zen",
|
|
275
|
+
};
|
|
276
|
+
|
|
277
|
+
export function quotaPoolLabel(key: string): string {
|
|
278
|
+
return POOL_NAMES[key] ?? key;
|
|
279
|
+
}
|
package/src/web/lib/pools.ts
CHANGED
|
@@ -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
|
-
/**
|
|
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
|
|
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 =
|
|
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 (
|
|
168
|
-
else if (
|
|
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
|
+
}
|
package/src/web/lib/status.ts
CHANGED
|
@@ -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: {
|
|
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" },
|