tuxevil-rotator 3.11.0 → 4.0.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 (49) hide show
  1. package/CHANGELOG.md +38 -0
  2. package/README.md +13 -12
  3. package/package.json +8 -4
  4. package/src/admin-auth.ts +233 -3
  5. package/src/dashboard-app.ts +257 -0
  6. package/src/dashboard-live.ts +654 -0
  7. package/src/dashboard-types.ts +192 -0
  8. package/src/dashboard.ts +165 -732
  9. package/src/db-store.ts +43 -0
  10. package/src/exposure.ts +21 -1
  11. package/src/proxy.ts +71 -25
  12. package/src/rotator.ts +30 -30
  13. package/src/settings-repository.ts +7 -0
  14. package/src/types.ts +2 -0
  15. package/src/web/app.tsx +765 -0
  16. package/src/web/components/charts.tsx +338 -0
  17. package/src/web/components/command.tsx +279 -0
  18. package/src/web/components/icons.tsx +357 -0
  19. package/src/web/components/overlays.tsx +432 -0
  20. package/src/web/components/ui.tsx +421 -0
  21. package/src/web/lib/accounts.ts +109 -0
  22. package/src/web/lib/attention.ts +219 -0
  23. package/src/web/lib/colors.ts +103 -0
  24. package/src/web/lib/format.ts +113 -0
  25. package/src/web/lib/mask.ts +92 -0
  26. package/src/web/lib/pools.ts +199 -0
  27. package/src/web/lib/status.ts +242 -0
  28. package/src/web/lib/usage.ts +296 -0
  29. package/src/web/main.tsx +16 -0
  30. package/src/web/nav.ts +28 -0
  31. package/src/web/pages/AccountDetail.tsx +346 -0
  32. package/src/web/pages/Accounts.tsx +581 -0
  33. package/src/web/pages/Keys.tsx +431 -0
  34. package/src/web/pages/Overview.tsx +600 -0
  35. package/src/web/pages/Requests.tsx +644 -0
  36. package/src/web/pages/Settings.tsx +546 -0
  37. package/src/web/pages/Usage.tsx +346 -0
  38. package/src/web/pages/shared.ts +36 -0
  39. package/src/web/state/actions.ts +211 -0
  40. package/src/web/state/api.ts +273 -0
  41. package/src/web/state/prefs.ts +19 -0
  42. package/src/web/state/router.ts +92 -0
  43. package/src/web/state/store.ts +266 -0
  44. package/src/web/styles/app.css +5043 -0
  45. package/src/web/tsconfig.json +14 -0
  46. package/src/static/dashboard-keys.js +0 -535
  47. package/src/static/dashboard-logs.js +0 -800
  48. package/src/static/dashboard.css +0 -2741
  49. package/src/static/dashboard.js +0 -3334
@@ -0,0 +1,192 @@
1
+ // Wire types for the dashboard API (/api/dashboard/*). Shared by the server
2
+ // and the browser app in src/web, so this file must stay type-only.
3
+
4
+ import type { ExhaustionPrediction } from "./providers/ollama/prediction.js";
5
+ import type {
6
+ AccountStatus,
7
+ AdminNotification,
8
+ HealthScoreBreakdown,
9
+ ModelTierAccess,
10
+ RecentEvent,
11
+ RequestLogEntry,
12
+ RoutingModelDiagnostics,
13
+ RoutingAccountDiagnostic,
14
+ StatusResponse,
15
+ UpdateInfo,
16
+ } from "./types.js";
17
+
18
+ export type { HealthScoreBreakdown };
19
+
20
+ /** Token bucket with an absolute refill time instead of a countdown. */
21
+ export interface DashboardTokenBucket {
22
+ enabled: boolean;
23
+ tokens: number;
24
+ capacity: number;
25
+ nextRefillAt: number | null;
26
+ }
27
+
28
+ export type DashboardAccount = Omit<AccountStatus, "tokenBucket"> & {
29
+ tokenBucket: DashboardTokenBucket;
30
+ };
31
+
32
+ export type DashboardRoutingAccount = Omit<
33
+ RoutingAccountDiagnostic,
34
+ "tokenBucket"
35
+ > & {
36
+ tokenBucket: DashboardTokenBucket;
37
+ };
38
+
39
+ export type DashboardRoutingDiagnostics = Omit<
40
+ RoutingModelDiagnostics,
41
+ "accounts"
42
+ > & {
43
+ accounts: DashboardRoutingAccount[];
44
+ };
45
+
46
+ export type RoutingHealthState = StatusResponse["routingHealth"]["state"];
47
+
48
+ export type DashboardRoutingHealth = Omit<
49
+ StatusResponse["routingHealth"],
50
+ "nextRetryIn"
51
+ > & {
52
+ nextRetryAt: number | null;
53
+ };
54
+
55
+ export interface TrafficMinute {
56
+ start: number;
57
+ requests: number;
58
+ tokens: number;
59
+ }
60
+
61
+ /**
62
+ * Everything the dashboard needs except history. Relative countdowns from
63
+ * the rotator are converted to absolute timestamps so an idle rotator
64
+ * produces an identical snapshot from one second to the next.
65
+ */
66
+ export interface DashboardOverview {
67
+ generatedAt: number;
68
+ version: string;
69
+ proxyPort: number;
70
+ startedAt: number;
71
+ requestsPerRotation: number;
72
+ maxConcurrentRequestsPerAccount: number;
73
+ totalRequestsAllAccounts: number;
74
+ activeAccounts: Record<string, string>;
75
+ accounts: DashboardAccount[];
76
+ protectivePause: { until: number; reason: string | null };
77
+ operatorControls: StatusResponse["operatorControls"];
78
+ security: StatusResponse["security"];
79
+ routingHealth: DashboardRoutingHealth;
80
+ routingDiagnostics: Record<string, DashboardRoutingDiagnostics>;
81
+ /** Breaker key -> epoch ms when it lifts. */
82
+ circuitBreakers: {
83
+ model: Record<string, number>;
84
+ project: Record<string, number>;
85
+ };
86
+ predictions: Record<string, ExhaustionPrediction>;
87
+ modelTierAccess: Record<string, ModelTierAccess> | null;
88
+ updateInfo: UpdateInfo | null;
89
+ notifications: AdminNotification[];
90
+ hostedOAuthConfigured: boolean;
91
+ capabilities: { database: boolean };
92
+ usage: {
93
+ totalRequests: number;
94
+ totalInputTokens: number;
95
+ totalOutputTokens: number;
96
+ savingsUsd: number;
97
+ };
98
+ /** Per-minute traffic for the last hour, oldest first. */
99
+ traffic: TrafficMinute[];
100
+ /** Requests per display model over the last hour. */
101
+ recentRequestsByModel: Record<string, number>;
102
+ }
103
+
104
+ export type OverviewSection = Exclude<keyof DashboardOverview, "accounts">;
105
+
106
+ export interface LiveRequest extends RequestLogEntry {
107
+ id: number;
108
+ }
109
+
110
+ export interface LiveEvent extends RecentEvent {
111
+ id: number;
112
+ }
113
+
114
+ export interface DashboardSnapshot {
115
+ overview: DashboardOverview;
116
+ /** Newest first. */
117
+ requests: LiveRequest[];
118
+ /** Newest first. */
119
+ events: LiveEvent[];
120
+ }
121
+
122
+ export interface AccountsPatch {
123
+ upsert: DashboardAccount[];
124
+ remove: string[];
125
+ /** Full email order, sent only when it changed. */
126
+ order?: string[];
127
+ }
128
+
129
+ export type DashboardStreamMessage =
130
+ | { type: "snapshot"; data: DashboardSnapshot }
131
+ | { type: "overview"; data: Partial<Pick<DashboardOverview, OverviewSection>> }
132
+ | { type: "accounts"; data: AccountsPatch }
133
+ | { type: "requests"; data: LiveRequest[] }
134
+ | { type: "events"; data: LiveEvent[] };
135
+
136
+ export const USAGE_RANGES = ["1h", "6h", "24h", "7d", "30d"] as const;
137
+ export type UsageRange = (typeof USAGE_RANGES)[number];
138
+
139
+ export interface UsageModelTotals {
140
+ inputTokens: number;
141
+ outputTokens: number;
142
+ requests: number;
143
+ }
144
+
145
+ export interface UsageBucket {
146
+ /** Bucket start, epoch ms. */
147
+ start: number;
148
+ /** Bucket length in ms (minute, hour or day). */
149
+ span: number;
150
+ inputTokens: number;
151
+ outputTokens: number;
152
+ requests: number;
153
+ byModel: Record<string, UsageModelTotals>;
154
+ }
155
+
156
+ export interface ModelPrice {
157
+ inputPer1M: number;
158
+ outputPer1M: number;
159
+ }
160
+
161
+ export interface LatencySummary {
162
+ ttfb: { p50: number; p95: number };
163
+ total: { p50: number; p95: number };
164
+ count: number;
165
+ }
166
+
167
+ export interface UsageResponse {
168
+ range: UsageRange;
169
+ generatedAt: number;
170
+ /** Buckets inside the range window (plus a small alignment margin). */
171
+ buckets: UsageBucket[];
172
+ /** List prices for every model in `buckets`; unpriced models are absent. */
173
+ pricing: Record<string, ModelPrice>;
174
+ allTime: {
175
+ inputTokens: number;
176
+ outputTokens: number;
177
+ requests: number;
178
+ savingsUsd: number;
179
+ };
180
+ latency: Record<string, LatencySummary>;
181
+ }
182
+
183
+ export interface ActivityResponse {
184
+ generatedAt: number;
185
+ /** [hourStartMs, requests] pairs for the last 60 days, non-zero only. */
186
+ hours: Array<[number, number]>;
187
+ }
188
+
189
+ export interface SessionInfo {
190
+ authenticated: boolean;
191
+ authRequired: boolean;
192
+ }