@askalf/dario 6.11.0 → 6.11.2
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/README.md +3 -5
- package/dist/admin-api.d.ts +3 -0
- package/dist/admin-api.js +2 -1
- package/dist/analytics.js +4 -0
- package/dist/cli.d.ts +4 -1
- package/dist/cli.js +17 -2
- package/dist/codex-accounts.d.ts +16 -3
- package/dist/codex-accounts.js +34 -13
- package/dist/codex-backend.d.ts +6 -0
- package/dist/codex-backend.js +46 -0
- package/dist/codex-usage.d.ts +80 -0
- package/dist/codex-usage.js +179 -0
- package/dist/doctor-core.js +11 -5
- package/dist/pool.d.ts +26 -1
- package/dist/pool.js +32 -0
- package/dist/proxy.js +35 -6
- package/docs/admin-api.md +1 -1
- package/docs/cli-and-endpoints.md +1 -1
- package/docs/configuration.md +7 -0
- package/docs/pool-keys-and-analytics.md +14 -0
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -28,7 +28,7 @@
|
|
|
28
28
|
|
|
29
29
|
<p><strong>One local endpoint. Every AI tool you own. The subscriptions you already pay for.</strong></p>
|
|
30
30
|
|
|
31
|
-
<sub><code>npm i -g @askalf/dario</code> · <strong>0</strong> runtime deps · <a href="https://www.npmjs.com/package/@askalf/dario">SLSA-attested</a> every release · nothing phones home · ~
|
|
31
|
+
<sub><code>npm i -g @askalf/dario</code> · <strong>0</strong> runtime deps · <a href="https://www.npmjs.com/package/@askalf/dario">SLSA-attested</a> every release · nothing phones home · ~40k lines you can read in a weekend · independent, unofficial, third-party (<a href="DISCLAIMER.md">DISCLAIMER.md</a>)</sub>
|
|
32
32
|
|
|
33
33
|
<sub><a href="#start-in-60-seconds">Start</a> · <a href="#why-people-pick-it">Why dario</a> · <a href="#what-it-does-with-a-request">Routing</a> · <a href="#will-my-account-get-suspended">Risk</a> · <a href="#reference">Reference</a> · <a href="#trust--transparency">Trust</a> · <a href="docs/returning.md">Coming back after a while?</a></sub>
|
|
34
34
|
|
|
@@ -64,7 +64,7 @@ Prefer Docker? `ghcr.io/askalf/dario:latest` — multi-arch (`amd64` + `arm64`),
|
|
|
64
64
|
- **Every tool, one URL.** No per-tool keys and no second bill: anything with a base-URL setting runs on the plan you already pay for. [Per-tool setup](docs/tools.md)
|
|
65
65
|
- **Either plan, either wire shape.** Your ChatGPT plan behind Claude Code and the Anthropic SDKs; Codex CLI on your Claude plan. [Two plans](docs/two-plans.md)
|
|
66
66
|
- **Failover that finishes the answer.** A 429 on one plan is re-served by the other, and a stream that dies mid-answer is completed on the same model first. [Failover](docs/two-plans.md#failover-between-subscriptions)
|
|
67
|
-
- **Many seats, one endpoint.** Per-model headroom routing, session-sticky prompt cache, in-flight 429 failover across every seat you hold. [The pool](docs/pool-keys-and-analytics.md)
|
|
67
|
+
- **Many seats, one endpoint.** Per-model headroom routing, session-sticky prompt cache, in-flight 429 failover across every seat you hold. New conversations go to the seat with the most headroom by default; `--pool-strategy=fill-first` fills seats in alias order and `expiring-first` spends the seat whose weekly window resets soonest. The active strategy shows in the startup banner, `GET /status`, `dario doctor` and `dario accounts list`. [The pool](docs/pool-keys-and-analytics.md)
|
|
68
68
|
- **One key per developer.** Named keys with a preferred seat, a model allowlist and a daily budget. [Keys](docs/pool-keys-and-analytics.md#one-key-per-developer)
|
|
69
69
|
- **Knows what it saved you.** A ledger prices every request at API rates; see it in the TUI, `/analytics`, Prometheus `/metrics` and a per-request timing split. [Analytics](docs/pool-keys-and-analytics.md#what-it-would-have-cost)
|
|
70
70
|
- **Tracks Claude Code on its own.** Eleven unattended watchers catch wire-shape drift and ship the fix, usually the same day. [Drift](docs/tracking-claude-code.md)
|
|
@@ -113,7 +113,7 @@ dario runs entirely on your machine, authenticates as you with your own Claude l
|
|
|
113
113
|
|
|
114
114
|
| Signal | Status |
|
|
115
115
|
|---|---|
|
|
116
|
-
| Source | **~
|
|
116
|
+
| Source | **~40k** lines of TypeScript across **78** files, auditable in a weekend. One credential path since v5: the pool. |
|
|
117
117
|
| Dependencies | **0 runtime.** Verify: `npm ls --production` |
|
|
118
118
|
| Provenance | Every release [SLSA-attested](https://www.npmjs.com/package/@askalf/dario) via GitHub Actions + Sigstore, published with OIDC trusted publishing — no long-lived npm token exists to leak |
|
|
119
119
|
| Scanning | [CodeQL](https://github.com/askalf/dario/actions/workflows/codeql.yml) on every push and weekly · [ClusterFuzzLite](./.github/workflows/cflite.yml) fuzzes the SSE translator and rejection parsers weekly · [OpenSSF Scorecard](https://scorecard.dev/viewer/?uri=github.com/askalf/dario) and [Best Practices](https://www.bestpractices.dev/projects/13638) badges above are live |
|
|
@@ -228,11 +228,9 @@ MIT — see [LICENSE](LICENSE) and [DISCLAIMER.md](DISCLAIMER.md). The embedded
|
|
|
228
228
|
dario is the routing layer of **[Own Your Stack](https://github.com/askalf)**, open tools for owning your AI infrastructure instead of renting it by the token. One subscription. Your box. Your terms.
|
|
229
229
|
|
|
230
230
|
- **[dario](https://github.com/askalf/dario)** — own your routing _(you are here)_
|
|
231
|
-
- **[hybrid](https://github.com/askalf/hybrid)** — own your inference
|
|
232
231
|
- **[browser-bridge](https://github.com/askalf/browser-bridge)** — own your browser
|
|
233
232
|
- **[redstamp](https://github.com/askalf/redstamp)** — own your agent security
|
|
234
233
|
- **[truecopy](https://github.com/askalf/truecopy)** — own your agent skills
|
|
235
|
-
- **[agent-security-stack](https://github.com/askalf/agent-security-stack)** — own your agent security stack: redstamp + truecopy + strongroom leases, one MCP server
|
|
236
234
|
- **[cordon](https://github.com/askalf/cordon)** — own your prompts · [pair it with dario](./docs/integrations/cordon.md)
|
|
237
235
|
- **[plumbline](https://github.com/askalf/plumbline)** — own your agent oversight
|
|
238
236
|
- **[amnesia](https://github.com/askalf/amnesia)** — own your search
|
package/dist/admin-api.d.ts
CHANGED
|
@@ -76,6 +76,7 @@
|
|
|
76
76
|
*/
|
|
77
77
|
import type { IncomingMessage, ServerResponse } from 'node:http';
|
|
78
78
|
import type { CodexSeatState } from './codex-accounts.js';
|
|
79
|
+
import { type CodexUsageView } from './codex-usage.js';
|
|
79
80
|
import { type KeyStore } from './keys.js';
|
|
80
81
|
/** Persisted account metadata surfaced by `GET /admin/accounts`. */
|
|
81
82
|
export interface AdminAccountRecord {
|
|
@@ -163,6 +164,8 @@ export interface AdminCodexAccountRecord extends CodexSeatState {
|
|
|
163
164
|
expiresAt: number;
|
|
164
165
|
/** The clock's opinion. `status` is the proxy's (dario#1343). */
|
|
165
166
|
needsRefresh: boolean;
|
|
167
|
+
/** The seat's utilisation (codex-usage.ts); null before its first answer or read. */
|
|
168
|
+
usage: CodexUsageView | null;
|
|
166
169
|
}
|
|
167
170
|
export interface AdminAuditEvent {
|
|
168
171
|
action: 'login_start' | 'login_complete' | 'account_remove' | 'auth_reject' | 'rate_limited' | 'key_create' | 'key_revoke' | 'key_rotate' | 'key_budget';
|
package/dist/admin-api.js
CHANGED
|
@@ -2,6 +2,7 @@ import { maskEmail } from './pool.js';
|
|
|
2
2
|
import { timingSafeEqual } from 'node:crypto';
|
|
3
3
|
import { startAddAccount, completeAddAccount, removeAccount, listAccountAliases, loadAccount, } from './accounts.js';
|
|
4
4
|
import { startAddCodexAccount, completeAddCodexAccount, removeCodexAccount, loadAllCodexAccounts, listCodexAccountAliases, codexAccountNeedsRefresh, codexSeatStatus, parseCodexManualPaste, } from './codex-accounts.js';
|
|
5
|
+
import { codexUsageView } from './codex-usage.js';
|
|
5
6
|
import { parseManualPaste } from './oauth.js';
|
|
6
7
|
import { grantAge } from './refresh-grant.js';
|
|
7
8
|
import { createKey, revokeKey, rotateKey, parseExpiry, publicKey, setKeyBudget, normalizeBudget, KEY_NAME_RE } from './keys.js';
|
|
@@ -173,7 +174,7 @@ async function doCompleteCodexLogin(alias, rawCode, now, deps, remote) {
|
|
|
173
174
|
async function listCodexAccountRecords() {
|
|
174
175
|
const all = await loadAllCodexAccounts();
|
|
175
176
|
return all
|
|
176
|
-
.map((a) => ({ alias: a.alias, expiresAt: a.expiresAt, needsRefresh: codexAccountNeedsRefresh(a), ...codexSeatStatus(a.alias) }))
|
|
177
|
+
.map((a) => ({ alias: a.alias, expiresAt: a.expiresAt, needsRefresh: codexAccountNeedsRefresh(a), ...codexSeatStatus(a.alias), usage: codexUsageView(a.alias) }))
|
|
177
178
|
.sort((x, y) => x.alias.localeCompare(y.alias));
|
|
178
179
|
}
|
|
179
180
|
/** On-disk account inventory — the default `AdminDeps.listAccounts`. */
|
package/dist/analytics.js
CHANGED
|
@@ -210,6 +210,10 @@ export const PRICING = {
|
|
|
210
210
|
// fast-mode tier is $10/$50, but that rides `speed:"fast"` on the API path,
|
|
211
211
|
// which the subscription surface dario proxies never sends.)
|
|
212
212
|
'claude-opus-5': { input: 5, output: 25, cacheRead: 0.5, cacheCreate: 6.25 },
|
|
213
|
+
// Opus 5.5 (2026-09-22) is the first Opus cheaper than the one before it: $4/$20,
|
|
214
|
+
// 5m cache-write $5, and cache-read $0.20 — 0.05x input where every other model
|
|
215
|
+
// is 0.1x (the pricing page footnotes it). Not a derived row; copy the table.
|
|
216
|
+
'claude-opus-5-5': { input: 4, output: 20, cacheRead: 0.2, cacheCreate: 5 },
|
|
213
217
|
'claude-opus-4-8': { input: 5, output: 25, cacheRead: 0.5, cacheCreate: 6.25 },
|
|
214
218
|
'claude-opus-4-7': { input: 5, output: 25, cacheRead: 0.5, cacheCreate: 6.25 },
|
|
215
219
|
// Opus 4.6 is $5/$25 (same as 4.7/4.8), not the old $15/$75 Opus-4.1 rate.
|
package/dist/cli.d.ts
CHANGED
|
@@ -10,6 +10,7 @@
|
|
|
10
10
|
* dario logout — Remove saved credentials
|
|
11
11
|
*/
|
|
12
12
|
import { type EffortValue } from './cc-template.js';
|
|
13
|
+
import { type CodexUsageView } from './codex-usage.js';
|
|
13
14
|
/**
|
|
14
15
|
* Bare words after `proxy` (dario#1353). `dario proxy` takes flags only, but it
|
|
15
16
|
* read them by prefix and ignored everything else, so `dario proxy status`,
|
|
@@ -171,9 +172,11 @@ export interface LiveCodexSeat {
|
|
|
171
172
|
status: number;
|
|
172
173
|
message: string;
|
|
173
174
|
} | null;
|
|
175
|
+
/** Absent from a proxy older than the usage reading; null until the seat has answered or been read. */
|
|
176
|
+
usage?: CodexUsageView | null;
|
|
174
177
|
}
|
|
175
178
|
/** Lines for `dario codex list --live` — pure, so the shape is testable without a proxy. */
|
|
176
|
-
export declare function formatLiveCodexListing(accounts: readonly LiveCodexSeat[], port: number): string[];
|
|
179
|
+
export declare function formatLiveCodexListing(accounts: readonly LiveCodexSeat[], port: number, now?: number): string[];
|
|
177
180
|
/**
|
|
178
181
|
* Decide whether this module is being invoked as the CLI entry point or
|
|
179
182
|
* imported as a library. Pure, exported for tests; the file-bottom uses
|
package/dist/cli.js
CHANGED
|
@@ -52,7 +52,7 @@ function readBudgetFlags(args) {
|
|
|
52
52
|
return budget;
|
|
53
53
|
}
|
|
54
54
|
import { loadAllAccounts as loadAllAccountsForIdentity, regenerateClientIdentity } from './accounts.js';
|
|
55
|
-
import { maskEmail, parsePoolHeadroomFloor } from './pool.js';
|
|
55
|
+
import { maskEmail, parsePoolHeadroomFloor, configuredPoolRouting, describePoolStrategy } from './pool.js';
|
|
56
56
|
import { realpathSync, readFileSync } from 'node:fs';
|
|
57
57
|
import { join } from 'node:path';
|
|
58
58
|
import { homedir } from 'node:os';
|
|
@@ -63,6 +63,7 @@ import { VALID_EFFORT_VALUES } from './cc-template.js';
|
|
|
63
63
|
import { grantAge, describeGrantAge } from './refresh-grant.js';
|
|
64
64
|
import { listAccountAliases, loadAllAccounts, addAccountViaOAuth, addAccountViaManualOAuth, addAccountFromKeychain, KeychainImportError, removeAccount, ensureLoginCredentialsInPool, resyncLoginFromCredentialsIfStale, MIGRATED_LOGIN_ALIAS } from './accounts.js';
|
|
65
65
|
import { listCodexAccountAliases, loadAllCodexAccounts, startAddCodexAccount, completeAddCodexAccount, removeCodexAccount, parseCodexManualPaste } from './codex-accounts.js';
|
|
66
|
+
import { describeCodexWindow } from './codex-usage.js';
|
|
66
67
|
import { listBackends, saveBackend, removeBackend } from './openai-backend.js';
|
|
67
68
|
import { parseOutboundProxy, installOutboundProxyWrapper } from './outbound-proxy.js';
|
|
68
69
|
// `args` / `command` at module scope — command handlers below close over
|
|
@@ -1228,7 +1229,7 @@ export function formatLiveAccountsListing(payload, port, now) {
|
|
|
1228
1229
|
return lines;
|
|
1229
1230
|
}
|
|
1230
1231
|
/** Lines for `dario codex list --live` — pure, so the shape is testable without a proxy. */
|
|
1231
|
-
export function formatLiveCodexListing(accounts, port) {
|
|
1232
|
+
export function formatLiveCodexListing(accounts, port, now = Date.now()) {
|
|
1232
1233
|
const out = ['', ` dario — Codex accounts (live, from http://127.0.0.1:${port}/codex)`, ' ───────────────────────────────────────', ''];
|
|
1233
1234
|
if (accounts.length === 0) {
|
|
1234
1235
|
out.push(' No Codex accounts.', '');
|
|
@@ -1250,6 +1251,15 @@ export function formatLiveCodexListing(accounts, port) {
|
|
|
1250
1251
|
}
|
|
1251
1252
|
out.push(` ${a.alias.padEnd(20)} ${state}`);
|
|
1252
1253
|
out.push(` ${''.padEnd(20)} token expires in ${expiry}, ${a.requestCount} request${a.requestCount === 1 ? '' : 's'} served`);
|
|
1254
|
+
if (a.usage === null) {
|
|
1255
|
+
out.push(` ${''.padEnd(20)} usage: no reading yet (the seat's first answer or the /wham/usage read supplies it)`);
|
|
1256
|
+
}
|
|
1257
|
+
else if (a.usage) {
|
|
1258
|
+
const windows = a.usage.windows.map((w) => describeCodexWindow(w, now)).join(' · ');
|
|
1259
|
+
const head = a.usage.headroom === null ? '' : ` — ${Math.round(a.usage.headroom * 100)}% headroom`;
|
|
1260
|
+
const reached = a.usage.limitReached ? ` — AT LIMIT (${a.usage.limitReached})` : '';
|
|
1261
|
+
out.push(` ${''.padEnd(20)} usage: ${windows || 'no windows reported'}${head}${reached} (${a.usage.source === 'headers' ? 'from its last answer' : 'from /wham/usage'})`);
|
|
1262
|
+
}
|
|
1253
1263
|
}
|
|
1254
1264
|
out.push('');
|
|
1255
1265
|
return out;
|
|
@@ -1344,6 +1354,11 @@ async function accounts() {
|
|
|
1344
1354
|
const loaded = await loadAllAccounts();
|
|
1345
1355
|
const now = Date.now();
|
|
1346
1356
|
console.log(` Pool of ${aliases.length} (${aliases.length === 1 ? '1 account' : aliases.length + ' accounts'})`);
|
|
1357
|
+
{
|
|
1358
|
+
const { loadConfig } = await import('./config-file.js');
|
|
1359
|
+
const routing = configuredPoolRouting(loadConfig().config.pool);
|
|
1360
|
+
console.log(` Routing: ${describePoolStrategy(routing.strategy, routing.headroomFloor)}`);
|
|
1361
|
+
}
|
|
1347
1362
|
if (aliases.length === 1) {
|
|
1348
1363
|
console.log(' (A pool of one — add another with `dario accounts add <alias>` to load-balance.)');
|
|
1349
1364
|
}
|
package/dist/codex-accounts.d.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { type PoolStrategy } from './pool.js';
|
|
1
2
|
export interface CodexAccountCredentials {
|
|
2
3
|
alias: string;
|
|
3
4
|
accessToken: string;
|
|
@@ -104,6 +105,18 @@ export declare function getFreshCodexAccount(creds: CodexAccountCredentials): Pr
|
|
|
104
105
|
* a dead refresh token must not become a token-endpoint storm, one per request.
|
|
105
106
|
*/
|
|
106
107
|
export declare function forceRefreshCodexAccount(creds: CodexAccountCredentials): Promise<CodexAccountCredentials>;
|
|
108
|
+
/** The proxy sets this from the same resolved values the Claude pool runs with. */
|
|
109
|
+
export declare function setCodexRouting(routing: {
|
|
110
|
+
strategy: PoolStrategy;
|
|
111
|
+
floor: number;
|
|
112
|
+
}): void;
|
|
113
|
+
/** Seat order for new conversations and failover: above-floor seats in strategy order, then the rest by headroom. */
|
|
114
|
+
export declare function orderCodexSeats<T extends {
|
|
115
|
+
alias: string;
|
|
116
|
+
}>(seats: readonly T[], now?: number, routing?: {
|
|
117
|
+
strategy: PoolStrategy;
|
|
118
|
+
floor: number;
|
|
119
|
+
}): T[];
|
|
107
120
|
/** Record that `alias` declined, for as long as the upstream asked. */
|
|
108
121
|
export declare function noteCodexDecline(alias: string, retryAfterMs?: number | null): number;
|
|
109
122
|
/** A seat that just served is not rate-limited — clear it. */
|
|
@@ -133,9 +146,9 @@ export declare function rebindCodexSticky(key: string | null | undefined, alias:
|
|
|
133
146
|
* pin is an instruction, so it is honoured even while cooling; the caller
|
|
134
147
|
* asked for that seat and gets its answer, 429 included.
|
|
135
148
|
* 2. the seat this conversation is already bound to, unless it is cooling.
|
|
136
|
-
* 3. the first seat
|
|
137
|
-
*
|
|
138
|
-
*
|
|
149
|
+
* 3. the first seat that is not cooling, in orderCodexSeats' order (the pool
|
|
150
|
+
* strategy over each seat's utilisation; alphabetical when there are no
|
|
151
|
+
* readings, so a fresh process is deterministic).
|
|
139
152
|
* 4. null when every seat is cooling. The caller answers from that rather
|
|
140
153
|
* than spending a request that can only 429 again.
|
|
141
154
|
*/
|
package/dist/codex-accounts.js
CHANGED
|
@@ -16,6 +16,8 @@ import { randomBytes } from 'node:crypto';
|
|
|
16
16
|
import { generateCodexPKCE, buildCodexAuthorizeUrl, exchangeCodexAuthorizationCode, refreshCodexAccessToken, CodexRefreshError, } from './codex-oauth.js';
|
|
17
17
|
import { durableWriteFile } from './durable-write.js';
|
|
18
18
|
import { ProviderCooldowns } from './provider-cooldown.js';
|
|
19
|
+
import { codexHeadroom, codexLongWindowResetAt } from './codex-usage.js';
|
|
20
|
+
import { DEFAULT_POOL_HEADROOM_FLOOR, resolvePoolStrategy } from './pool.js';
|
|
19
21
|
const DARIO_DIR = join(homedir(), '.dario');
|
|
20
22
|
const CODEX_ACCOUNTS_DIR = join(DARIO_DIR, 'codex-accounts');
|
|
21
23
|
/** Same alias charset/traversal guard as accounts.ts's safeAliasPath. */
|
|
@@ -374,14 +376,34 @@ async function refreshNow(creds) {
|
|
|
374
376
|
* come out behind. So a conversation binds to a seat and stays there until that
|
|
375
377
|
* seat actually declines.
|
|
376
378
|
*
|
|
377
|
-
*
|
|
378
|
-
*
|
|
379
|
-
*
|
|
380
|
-
* the only signal is the decline itself plus its `retry-after` — so this is
|
|
381
|
-
* fill-first with cool-down eviction, which is what the available signal
|
|
382
|
-
* supports. If the backend ever starts reporting utilisation, this is where
|
|
383
|
-
* headroom would go.
|
|
379
|
+
* NEW conversations are placed by the Claude pool's strategy and floor over
|
|
380
|
+
* each seat's utilisation (codex-usage.ts); an unread seat counts as full
|
|
381
|
+
* headroom so a new seat gets used. Cooling still overrides any reading.
|
|
384
382
|
*/
|
|
383
|
+
let codexRouting = null;
|
|
384
|
+
/** The proxy sets this from the same resolved values the Claude pool runs with. */
|
|
385
|
+
export function setCodexRouting(routing) {
|
|
386
|
+
codexRouting = routing;
|
|
387
|
+
}
|
|
388
|
+
function currentCodexRouting() {
|
|
389
|
+
return codexRouting ?? { strategy: resolvePoolStrategy(), floor: DEFAULT_POOL_HEADROOM_FLOOR };
|
|
390
|
+
}
|
|
391
|
+
/** Seat order for new conversations and failover: above-floor seats in strategy order, then the rest by headroom. */
|
|
392
|
+
export function orderCodexSeats(seats, now = Date.now(), routing = currentCodexRouting()) {
|
|
393
|
+
const byAlias = (a, b) => a.alias.localeCompare(b.alias);
|
|
394
|
+
const head = (s) => codexHeadroom(s.alias, now) ?? 1;
|
|
395
|
+
const byHeadroom = (a, b) => head(b) - head(a) || byAlias(a, b);
|
|
396
|
+
const alpha = [...seats].sort(byAlias);
|
|
397
|
+
const over = alpha.filter((s) => head(s) > routing.floor);
|
|
398
|
+
const under = alpha.filter((s) => head(s) <= routing.floor).sort(byHeadroom);
|
|
399
|
+
if (routing.strategy === 'fill-first')
|
|
400
|
+
return [...over, ...under];
|
|
401
|
+
if (routing.strategy === 'expiring-first') {
|
|
402
|
+
const soon = (s) => codexLongWindowResetAt(s.alias, now) ?? Number.POSITIVE_INFINITY;
|
|
403
|
+
return [...over.sort((a, b) => soon(a) - soon(b) || byAlias(a, b)), ...under];
|
|
404
|
+
}
|
|
405
|
+
return [...over.sort(byHeadroom), ...under];
|
|
406
|
+
}
|
|
385
407
|
let codexCooldowns = new ProviderCooldowns();
|
|
386
408
|
/** conversation sticky key -> alias. Bounded; swept when it exceeds the cap. */
|
|
387
409
|
const codexSticky = new Map();
|
|
@@ -444,9 +466,9 @@ export function rebindCodexSticky(key, alias) {
|
|
|
444
466
|
* pin is an instruction, so it is honoured even while cooling; the caller
|
|
445
467
|
* asked for that seat and gets its answer, 429 included.
|
|
446
468
|
* 2. the seat this conversation is already bound to, unless it is cooling.
|
|
447
|
-
* 3. the first seat
|
|
448
|
-
*
|
|
449
|
-
*
|
|
469
|
+
* 3. the first seat that is not cooling, in orderCodexSeats' order (the pool
|
|
470
|
+
* strategy over each seat's utilisation; alphabetical when there are no
|
|
471
|
+
* readings, so a fresh process is deterministic).
|
|
450
472
|
* 4. null when every seat is cooling. The caller answers from that rather
|
|
451
473
|
* than spending a request that can only 429 again.
|
|
452
474
|
*/
|
|
@@ -473,7 +495,7 @@ export async function selectCodexAccount(preferredAlias, opts) {
|
|
|
473
495
|
codexSticky.delete(key);
|
|
474
496
|
}
|
|
475
497
|
}
|
|
476
|
-
const free = byAlias.find((c) => !codexCooldowns.isCooled(c.alias));
|
|
498
|
+
const free = orderCodexSeats(byAlias).find((c) => !codexCooldowns.isCooled(c.alias));
|
|
477
499
|
if (!free)
|
|
478
500
|
return null;
|
|
479
501
|
if (key)
|
|
@@ -501,8 +523,7 @@ export async function selectCodexAccountExcluding(tried) {
|
|
|
501
523
|
const all = await loadAllCodexAccounts();
|
|
502
524
|
if (all.length === 0)
|
|
503
525
|
return null;
|
|
504
|
-
return
|
|
505
|
-
.sort((a, b) => a.alias.localeCompare(b.alias))
|
|
526
|
+
return orderCodexSeats(all)
|
|
506
527
|
.find((c) => !tried.has(c.alias) && !codexCooldowns.isCooled(c.alias)) ?? null;
|
|
507
528
|
}
|
|
508
529
|
/** Every seat is cooling — the fail-fast condition, for the caller's message. */
|
package/dist/codex-backend.d.ts
CHANGED
|
@@ -5,6 +5,12 @@ import { type ModelResolver, type ClaudeTarget } from './claude-model.js';
|
|
|
5
5
|
import { type EffortValue } from './effort.js';
|
|
6
6
|
import type { MidstreamGuard } from './midstream.js';
|
|
7
7
|
export declare const CODEX_BACKEND_BASE_URL: string;
|
|
8
|
+
/** The usage endpoint the Codex CLI's /status reads, beside the Responses base. */
|
|
9
|
+
export declare const CODEX_USAGE_URL: string;
|
|
10
|
+
/** Read a seat's utilisation without a model call. Never refreshes the token; false on any failure. */
|
|
11
|
+
export declare function seedCodexUsage(creds: CodexAccountCredentials, fetchImpl?: typeof fetch, timeoutMs?: number): Promise<boolean>;
|
|
12
|
+
/** Seed every seat that has no reading, or one older than `maxAgeMs`. Returns the aliases read. */
|
|
13
|
+
export declare function seedStaleCodexUsage(seats: readonly CodexAccountCredentials[], maxAgeMs: number, now?: number, fetchImpl?: typeof fetch): Promise<string[]>;
|
|
8
14
|
/**
|
|
9
15
|
* Client version sent on the model-discovery call. The backend REQUIRES the
|
|
10
16
|
* `client_version` query parameter and rejects the request without it; the
|
package/dist/codex-backend.js
CHANGED
|
@@ -29,7 +29,43 @@ import { resolveClaudeTarget } from './claude-model.js';
|
|
|
29
29
|
import { parseEffortSuffix } from './effort.js';
|
|
30
30
|
import { BAKED_BASE_MODELS } from './model-catalog.js';
|
|
31
31
|
import { parseRetryAfterMs } from './provider-cooldown.js';
|
|
32
|
+
import { noteCodexUsageHeaders, parseCodexUsageEndpoint, recordCodexUsage, codexUsageFor } from './codex-usage.js';
|
|
32
33
|
export const CODEX_BACKEND_BASE_URL = process.env.DARIO_CODEX_BASE_URL || 'https://chatgpt.com/backend-api/codex';
|
|
34
|
+
/** The usage endpoint the Codex CLI's /status reads, beside the Responses base. */
|
|
35
|
+
export const CODEX_USAGE_URL = process.env.DARIO_CODEX_USAGE_URL || `${CODEX_BACKEND_BASE_URL.replace(/\/+$/, '').replace(/\/codex$/, '')}/wham/usage`;
|
|
36
|
+
/** Read a seat's utilisation without a model call. Never refreshes the token; false on any failure. */
|
|
37
|
+
export async function seedCodexUsage(creds, fetchImpl = fetch, timeoutMs = 5000) {
|
|
38
|
+
// A real access token is a JWT; anything else would 401 (and keeps test placeholders off the network).
|
|
39
|
+
if (typeof creds.accessToken !== 'string' || creds.accessToken.split('.').length !== 3)
|
|
40
|
+
return false;
|
|
41
|
+
try {
|
|
42
|
+
const headers = { ...buildCodexHeaders(creds), Accept: 'application/json' };
|
|
43
|
+
delete headers['Content-Type'];
|
|
44
|
+
delete headers['OpenAI-Beta'];
|
|
45
|
+
const res = await fetchImpl(CODEX_USAGE_URL, { method: 'GET', headers, signal: AbortSignal.timeout(timeoutMs) });
|
|
46
|
+
if (!res.ok) {
|
|
47
|
+
await res.text().catch(() => '');
|
|
48
|
+
return false;
|
|
49
|
+
}
|
|
50
|
+
const usage = parseCodexUsageEndpoint(await res.json(), Date.now());
|
|
51
|
+
if (!usage)
|
|
52
|
+
return false;
|
|
53
|
+
recordCodexUsage(creds.alias, usage);
|
|
54
|
+
return true;
|
|
55
|
+
}
|
|
56
|
+
catch {
|
|
57
|
+
return false;
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
/** Seed every seat that has no reading, or one older than `maxAgeMs`. Returns the aliases read. */
|
|
61
|
+
export async function seedStaleCodexUsage(seats, maxAgeMs, now = Date.now(), fetchImpl = fetch) {
|
|
62
|
+
const stale = seats.filter((s) => {
|
|
63
|
+
const u = codexUsageFor(s.alias);
|
|
64
|
+
return !u || now - u.observedAt > maxAgeMs;
|
|
65
|
+
});
|
|
66
|
+
const results = await Promise.all(stale.map(async (s) => ((await seedCodexUsage(s, fetchImpl)) ? s.alias : null)));
|
|
67
|
+
return results.filter((a) => a !== null);
|
|
68
|
+
}
|
|
33
69
|
/** Originator string the codex CLI identifies itself with. */
|
|
34
70
|
const CODEX_ORIGINATOR = 'codex_cli_rs';
|
|
35
71
|
/**
|
|
@@ -830,6 +866,11 @@ timing) {
|
|
|
830
866
|
fetchStartedAt = Date.now();
|
|
831
867
|
const r = await fetchImpl(input, init);
|
|
832
868
|
upstreamHeadersAt = Date.now();
|
|
869
|
+
// Every answer, 429s included, carries the seat's utilisation.
|
|
870
|
+
try {
|
|
871
|
+
noteCodexUsageHeaders(creds.alias, r.headers, upstreamHeadersAt);
|
|
872
|
+
}
|
|
873
|
+
catch { /* best-effort */ }
|
|
833
874
|
return r;
|
|
834
875
|
};
|
|
835
876
|
const ttfbMs = () => (fetchStartedAt && upstreamHeadersAt ? Math.max(0, upstreamHeadersAt - fetchStartedAt) : 0);
|
|
@@ -1057,6 +1098,11 @@ timing) {
|
|
|
1057
1098
|
fetchStartedAt = Date.now();
|
|
1058
1099
|
const r = await fetchImpl(input, init);
|
|
1059
1100
|
upstreamHeadersAt = Date.now();
|
|
1101
|
+
// Every answer, 429s included, carries the seat's utilisation.
|
|
1102
|
+
try {
|
|
1103
|
+
noteCodexUsageHeaders(creds.alias, r.headers, upstreamHeadersAt);
|
|
1104
|
+
}
|
|
1105
|
+
catch { /* best-effort */ }
|
|
1060
1106
|
return r;
|
|
1061
1107
|
};
|
|
1062
1108
|
const ttfbMs = () => (fetchStartedAt && upstreamHeadersAt ? Math.max(0, upstreamHeadersAt - fetchStartedAt) : 0);
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* ChatGPT-seat utilisation, the Codex twin of the Claude pool's unified
|
|
3
|
+
* rate-limit readings. Every Responses answer carries
|
|
4
|
+
* `x-codex-{primary,secondary}-{used-percent,window-minutes,reset-at}` (reset
|
|
5
|
+
* in unix seconds; the family codex-rs/codex-api/src/rate_limits.rs parses),
|
|
6
|
+
* and `/backend-api/wham/usage` answers the same without a model call.
|
|
7
|
+
* Window shapes vary by plan (prolite: one weekly window), so nothing assumes
|
|
8
|
+
* which slot is which. Pure and memory-only, so codex-accounts and
|
|
9
|
+
* codex-backend can both import it without a cycle.
|
|
10
|
+
*/
|
|
11
|
+
export interface CodexUsageWindow {
|
|
12
|
+
/** As reported, 0–100. */
|
|
13
|
+
usedPercent: number;
|
|
14
|
+
/** Window length, when the backend states it. */
|
|
15
|
+
windowMinutes: number | null;
|
|
16
|
+
/** When the window rolls over, epoch ms. */
|
|
17
|
+
resetAt: number | null;
|
|
18
|
+
}
|
|
19
|
+
export interface CodexUsage {
|
|
20
|
+
primary: CodexUsageWindow | null;
|
|
21
|
+
secondary: CodexUsageWindow | null;
|
|
22
|
+
/** The backend's own "you are at the limit" flag: a reached-type header, or `limit_reached` on the usage endpoint. */
|
|
23
|
+
limitReached: string | null;
|
|
24
|
+
observedAt: number;
|
|
25
|
+
source: 'headers' | 'usage-endpoint';
|
|
26
|
+
}
|
|
27
|
+
/** Anything with a `get(name)` — a fetch `Headers`, or a stub in tests. */
|
|
28
|
+
export interface HeaderReader {
|
|
29
|
+
get(name: string): string | null;
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* Read the default (`codex`) rate-limit header family off a backend response.
|
|
33
|
+
* Null when the response carries no usage at all (an error body from a proxy
|
|
34
|
+
* in front, a stub), so a header-less response never erases a real reading.
|
|
35
|
+
*/
|
|
36
|
+
export declare function parseCodexUsageHeaders(h: HeaderReader, now?: number): CodexUsage | null;
|
|
37
|
+
/** Read a `GET /backend-api/wham/usage` body. Null when it carries no window. */
|
|
38
|
+
export declare function parseCodexUsageEndpoint(body: unknown, now?: number): CodexUsage | null;
|
|
39
|
+
/** How often an IDLE seat is re-read from /wham/usage. A seat that is serving is read from every answer and never polled. */
|
|
40
|
+
export declare const DEFAULT_CODEX_USAGE_POLL_MS: number;
|
|
41
|
+
/** `DARIO_CODEX_USAGE_POLL_MS`: unset/garbage → default, `0` → off, anything else floored at one minute. */
|
|
42
|
+
export declare function resolveCodexUsagePollMs(raw: string | undefined): number;
|
|
43
|
+
/** Record a reading for a seat. A newer reading replaces an older one; an older one never replaces a newer one. */
|
|
44
|
+
export declare function recordCodexUsage(alias: string, usage: CodexUsage): void;
|
|
45
|
+
/** The response hook: parse and record in one call; a header-less response changes nothing. */
|
|
46
|
+
export declare function noteCodexUsageHeaders(alias: string, h: HeaderReader, now?: number): void;
|
|
47
|
+
export declare function codexUsageFor(alias: string): CodexUsage | null;
|
|
48
|
+
/** Test seam. */
|
|
49
|
+
export declare function _resetCodexUsageForTest(): void;
|
|
50
|
+
/**
|
|
51
|
+
* Fraction of the tightest window still available, 0–1; null when the seat
|
|
52
|
+
* has no reading. A reached-limit flag reads as 0 until every window it could
|
|
53
|
+
* refer to has rolled.
|
|
54
|
+
*/
|
|
55
|
+
export declare function codexHeadroom(alias: string, now?: number): number | null;
|
|
56
|
+
/**
|
|
57
|
+
* When the seat's LONGEST window rolls over, epoch ms, if it is still ahead —
|
|
58
|
+
* the codex mirror of the Claude pool's 7-day reset, for `expiring-first`.
|
|
59
|
+
*/
|
|
60
|
+
export declare function codexLongWindowResetAt(alias: string, now?: number): number | null;
|
|
61
|
+
/** The JSON shape surfaces print: numbers plus ISO times, never a credential. */
|
|
62
|
+
export interface CodexUsageView {
|
|
63
|
+
headroom: number | null;
|
|
64
|
+
limitReached: string | null;
|
|
65
|
+
source: CodexUsage['source'];
|
|
66
|
+
observedAt: string;
|
|
67
|
+
windows: Array<{
|
|
68
|
+
slot: 'primary' | 'secondary';
|
|
69
|
+
usedPercent: number;
|
|
70
|
+
windowMinutes: number | null;
|
|
71
|
+
resetAt: string | null;
|
|
72
|
+
}>;
|
|
73
|
+
}
|
|
74
|
+
export declare function codexUsageView(alias: string, now?: number): CodexUsageView | null;
|
|
75
|
+
/** "6% of 7d, resets in 6d 22h" — one window, human-sized. */
|
|
76
|
+
export declare function describeCodexWindow(w: {
|
|
77
|
+
usedPercent: number;
|
|
78
|
+
windowMinutes: number | null;
|
|
79
|
+
resetAt: string | number | null;
|
|
80
|
+
}, now?: number): string;
|
|
@@ -0,0 +1,179 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* ChatGPT-seat utilisation, the Codex twin of the Claude pool's unified
|
|
3
|
+
* rate-limit readings. Every Responses answer carries
|
|
4
|
+
* `x-codex-{primary,secondary}-{used-percent,window-minutes,reset-at}` (reset
|
|
5
|
+
* in unix seconds; the family codex-rs/codex-api/src/rate_limits.rs parses),
|
|
6
|
+
* and `/backend-api/wham/usage` answers the same without a model call.
|
|
7
|
+
* Window shapes vary by plan (prolite: one weekly window), so nothing assumes
|
|
8
|
+
* which slot is which. Pure and memory-only, so codex-accounts and
|
|
9
|
+
* codex-backend can both import it without a cycle.
|
|
10
|
+
*/
|
|
11
|
+
function finite(raw) {
|
|
12
|
+
if (raw === null || raw === undefined || raw === '')
|
|
13
|
+
return null;
|
|
14
|
+
const n = typeof raw === 'number' ? raw : Number(String(raw).trim());
|
|
15
|
+
return Number.isFinite(n) ? n : null;
|
|
16
|
+
}
|
|
17
|
+
/** Unix seconds → epoch ms. A value already in ms (> ~2286 in seconds) passes through. */
|
|
18
|
+
function toMs(raw) {
|
|
19
|
+
const n = finite(raw);
|
|
20
|
+
if (n === null)
|
|
21
|
+
return null;
|
|
22
|
+
return n > 1e12 ? n : n * 1000;
|
|
23
|
+
}
|
|
24
|
+
function headerWindow(h, prefix) {
|
|
25
|
+
const used = finite(h.get(`${prefix}-used-percent`));
|
|
26
|
+
if (used === null)
|
|
27
|
+
return null;
|
|
28
|
+
const windowMinutes = finite(h.get(`${prefix}-window-minutes`));
|
|
29
|
+
// A one-window plan sends the unused slot zeroed with an empty reset: no window, not 0%.
|
|
30
|
+
if (windowMinutes !== null && windowMinutes <= 0)
|
|
31
|
+
return null;
|
|
32
|
+
return { usedPercent: used, windowMinutes, resetAt: toMs(h.get(`${prefix}-reset-at`)) };
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* Read the default (`codex`) rate-limit header family off a backend response.
|
|
36
|
+
* Null when the response carries no usage at all (an error body from a proxy
|
|
37
|
+
* in front, a stub), so a header-less response never erases a real reading.
|
|
38
|
+
*/
|
|
39
|
+
export function parseCodexUsageHeaders(h, now = Date.now()) {
|
|
40
|
+
const primary = headerWindow(h, 'x-codex-primary');
|
|
41
|
+
const secondary = headerWindow(h, 'x-codex-secondary');
|
|
42
|
+
if (!primary && !secondary)
|
|
43
|
+
return null;
|
|
44
|
+
const reached = h.get('x-codex-rate-limit-reached-type');
|
|
45
|
+
return { primary, secondary, limitReached: reached && reached.trim() ? reached.trim() : null, observedAt: now, source: 'headers' };
|
|
46
|
+
}
|
|
47
|
+
function endpointWindow(w, now) {
|
|
48
|
+
if (!w || typeof w !== 'object')
|
|
49
|
+
return null;
|
|
50
|
+
const used = finite(w.used_percent);
|
|
51
|
+
if (used === null)
|
|
52
|
+
return null;
|
|
53
|
+
const secs = finite(w.limit_window_seconds);
|
|
54
|
+
let resetAt = toMs(w.reset_at);
|
|
55
|
+
if (resetAt === null) {
|
|
56
|
+
const after = finite(w.reset_after_seconds);
|
|
57
|
+
if (after !== null)
|
|
58
|
+
resetAt = now + after * 1000;
|
|
59
|
+
}
|
|
60
|
+
return { usedPercent: used, windowMinutes: secs === null ? null : Math.round(secs / 60), resetAt };
|
|
61
|
+
}
|
|
62
|
+
/** Read a `GET /backend-api/wham/usage` body. Null when it carries no window. */
|
|
63
|
+
export function parseCodexUsageEndpoint(body, now = Date.now()) {
|
|
64
|
+
if (!body || typeof body !== 'object')
|
|
65
|
+
return null;
|
|
66
|
+
const b = body;
|
|
67
|
+
const rl = b.rate_limit;
|
|
68
|
+
if (!rl || typeof rl !== 'object')
|
|
69
|
+
return null;
|
|
70
|
+
const primary = endpointWindow(rl.primary_window, now);
|
|
71
|
+
const secondary = endpointWindow(rl.secondary_window, now);
|
|
72
|
+
if (!primary && !secondary)
|
|
73
|
+
return null;
|
|
74
|
+
const type = typeof b.rate_limit_reached_type === 'string' && b.rate_limit_reached_type ? b.rate_limit_reached_type : null;
|
|
75
|
+
const limitReached = type ?? (rl.limit_reached === true ? 'limit_reached' : null);
|
|
76
|
+
return { primary, secondary, limitReached, observedAt: now, source: 'usage-endpoint' };
|
|
77
|
+
}
|
|
78
|
+
/** How often an IDLE seat is re-read from /wham/usage. A seat that is serving is read from every answer and never polled. */
|
|
79
|
+
export const DEFAULT_CODEX_USAGE_POLL_MS = 30 * 60 * 1000;
|
|
80
|
+
/** `DARIO_CODEX_USAGE_POLL_MS`: unset/garbage → default, `0` → off, anything else floored at one minute. */
|
|
81
|
+
export function resolveCodexUsagePollMs(raw) {
|
|
82
|
+
if (raw === undefined || raw.trim() === '')
|
|
83
|
+
return DEFAULT_CODEX_USAGE_POLL_MS;
|
|
84
|
+
const n = Number(raw.trim());
|
|
85
|
+
if (!Number.isFinite(n) || n < 0)
|
|
86
|
+
return DEFAULT_CODEX_USAGE_POLL_MS;
|
|
87
|
+
if (n === 0)
|
|
88
|
+
return 0;
|
|
89
|
+
return Math.max(60_000, Math.round(n));
|
|
90
|
+
}
|
|
91
|
+
const readings = new Map();
|
|
92
|
+
/** Record a reading for a seat. A newer reading replaces an older one; an older one never replaces a newer one. */
|
|
93
|
+
export function recordCodexUsage(alias, usage) {
|
|
94
|
+
const prev = readings.get(alias);
|
|
95
|
+
if (prev && prev.observedAt > usage.observedAt)
|
|
96
|
+
return;
|
|
97
|
+
readings.set(alias, usage);
|
|
98
|
+
}
|
|
99
|
+
/** The response hook: parse and record in one call; a header-less response changes nothing. */
|
|
100
|
+
export function noteCodexUsageHeaders(alias, h, now = Date.now()) {
|
|
101
|
+
const u = parseCodexUsageHeaders(h, now);
|
|
102
|
+
if (u)
|
|
103
|
+
recordCodexUsage(alias, u);
|
|
104
|
+
}
|
|
105
|
+
export function codexUsageFor(alias) {
|
|
106
|
+
return readings.get(alias) ?? null;
|
|
107
|
+
}
|
|
108
|
+
/** Test seam. */
|
|
109
|
+
export function _resetCodexUsageForTest() {
|
|
110
|
+
readings.clear();
|
|
111
|
+
}
|
|
112
|
+
/** A window whose reset time has passed has rolled over: it counts as empty until the next reading says otherwise. */
|
|
113
|
+
function effectiveUsed(w, now) {
|
|
114
|
+
if (!w)
|
|
115
|
+
return null;
|
|
116
|
+
if (w.resetAt !== null && w.resetAt <= now)
|
|
117
|
+
return 0;
|
|
118
|
+
return Math.min(100, Math.max(0, w.usedPercent));
|
|
119
|
+
}
|
|
120
|
+
/**
|
|
121
|
+
* Fraction of the tightest window still available, 0–1; null when the seat
|
|
122
|
+
* has no reading. A reached-limit flag reads as 0 until every window it could
|
|
123
|
+
* refer to has rolled.
|
|
124
|
+
*/
|
|
125
|
+
export function codexHeadroom(alias, now = Date.now()) {
|
|
126
|
+
const u = readings.get(alias);
|
|
127
|
+
if (!u)
|
|
128
|
+
return null;
|
|
129
|
+
const used = [effectiveUsed(u.primary, now), effectiveUsed(u.secondary, now)].filter((x) => x !== null);
|
|
130
|
+
if (used.length === 0)
|
|
131
|
+
return null;
|
|
132
|
+
const rolled = [u.primary, u.secondary].every((w) => !w || (w.resetAt !== null && w.resetAt <= now));
|
|
133
|
+
if (u.limitReached && !rolled)
|
|
134
|
+
return 0;
|
|
135
|
+
return (100 - Math.max(...used)) / 100;
|
|
136
|
+
}
|
|
137
|
+
/**
|
|
138
|
+
* When the seat's LONGEST window rolls over, epoch ms, if it is still ahead —
|
|
139
|
+
* the codex mirror of the Claude pool's 7-day reset, for `expiring-first`.
|
|
140
|
+
*/
|
|
141
|
+
export function codexLongWindowResetAt(alias, now = Date.now()) {
|
|
142
|
+
const u = readings.get(alias);
|
|
143
|
+
if (!u)
|
|
144
|
+
return null;
|
|
145
|
+
const windows = [u.primary, u.secondary].filter((w) => w !== null);
|
|
146
|
+
if (windows.length === 0)
|
|
147
|
+
return null;
|
|
148
|
+
const longest = windows.reduce((a, b) => ((b.windowMinutes ?? 0) > (a.windowMinutes ?? 0) ? b : a));
|
|
149
|
+
return longest.resetAt !== null && longest.resetAt > now ? longest.resetAt : null;
|
|
150
|
+
}
|
|
151
|
+
export function codexUsageView(alias, now = Date.now()) {
|
|
152
|
+
const u = readings.get(alias);
|
|
153
|
+
if (!u)
|
|
154
|
+
return null;
|
|
155
|
+
const windows = [];
|
|
156
|
+
for (const slot of ['primary', 'secondary']) {
|
|
157
|
+
const w = u[slot];
|
|
158
|
+
if (w)
|
|
159
|
+
windows.push({ slot, usedPercent: w.usedPercent, windowMinutes: w.windowMinutes, resetAt: w.resetAt === null ? null : new Date(w.resetAt).toISOString() });
|
|
160
|
+
}
|
|
161
|
+
return { headroom: codexHeadroom(alias, now), limitReached: u.limitReached, source: u.source, observedAt: new Date(u.observedAt).toISOString(), windows };
|
|
162
|
+
}
|
|
163
|
+
/** "6% of 7d, resets in 6d 22h" — one window, human-sized. */
|
|
164
|
+
export function describeCodexWindow(w, now = Date.now()) {
|
|
165
|
+
const mins = w.windowMinutes;
|
|
166
|
+
const span = mins === null ? 'window' : mins >= 1440 ? `${Math.round(mins / 1440)}d` : mins >= 60 ? `${Math.round(mins / 60)}h` : `${mins}m`;
|
|
167
|
+
const resetMs = w.resetAt === null ? null : typeof w.resetAt === 'number' ? w.resetAt : Date.parse(w.resetAt);
|
|
168
|
+
let reset = '';
|
|
169
|
+
if (resetMs !== null && Number.isFinite(resetMs)) {
|
|
170
|
+
const left = resetMs - now;
|
|
171
|
+
if (left <= 0)
|
|
172
|
+
reset = ', rolled over';
|
|
173
|
+
else {
|
|
174
|
+
const h = Math.floor(left / 3_600_000);
|
|
175
|
+
reset = h >= 24 ? `, resets in ${Math.floor(h / 24)}d ${h % 24}h` : `, resets in ${h}h ${Math.floor((left % 3_600_000) / 60_000)}m`;
|
|
176
|
+
}
|
|
177
|
+
}
|
|
178
|
+
return `${Math.round(w.usedPercent)}% of ${span}${reset}`;
|
|
179
|
+
}
|
package/dist/doctor-core.js
CHANGED
|
@@ -1132,8 +1132,13 @@ export async function runChecks(opts = {}) {
|
|
|
1132
1132
|
// (v5.0): it confirms the sole account is eligible, not rejected.
|
|
1133
1133
|
if (aliases.length >= 1) {
|
|
1134
1134
|
try {
|
|
1135
|
-
const { AccountPool } = await import('./pool.js');
|
|
1136
|
-
const
|
|
1135
|
+
const { AccountPool, configuredPoolRouting, describePoolStrategy } = await import('./pool.js');
|
|
1136
|
+
const { loadConfig } = await import('./config-file.js');
|
|
1137
|
+
// The preview must use the strategy the proxy will run, not the
|
|
1138
|
+
// default: `new AccountPool()` here always predicted a max-headroom
|
|
1139
|
+
// pick, which is the wrong seat on a fill-first pool.
|
|
1140
|
+
const routing = configuredPoolRouting(loadConfig().config.pool);
|
|
1141
|
+
const pool = new AccountPool(routing.strategy, routing.headroomFloor);
|
|
1137
1142
|
for (const acc of loaded) {
|
|
1138
1143
|
pool.add(acc.alias, {
|
|
1139
1144
|
accessToken: acc.accessToken,
|
|
@@ -1148,9 +1153,10 @@ export async function runChecks(opts = {}) {
|
|
|
1148
1153
|
checks.push({
|
|
1149
1154
|
status: 'info',
|
|
1150
1155
|
label: 'Pool routing',
|
|
1151
|
-
detail: next
|
|
1152
|
-
? `next: ${next.alias} (
|
|
1153
|
-
: `no eligible account — all rejected or near-expiry (${ps.exhausted}/${ps.accounts} exhausted)
|
|
1156
|
+
detail: (next
|
|
1157
|
+
? `next: ${next.alias} (${ps.healthy}/${ps.accounts} healthy)`
|
|
1158
|
+
: `no eligible account — all rejected or near-expiry (${ps.exhausted}/${ps.accounts} exhausted)`)
|
|
1159
|
+
+ ` · ${describePoolStrategy(routing.strategy, routing.headroomFloor)} (env/config; a running proxy's --pool-strategy flag shows in GET /status)`,
|
|
1154
1160
|
});
|
|
1155
1161
|
}
|
|
1156
1162
|
catch (err) {
|
package/dist/pool.d.ts
CHANGED
|
@@ -369,6 +369,10 @@ export declare function isProbeable(account: PoolAccount, now?: number, family?:
|
|
|
369
369
|
*/
|
|
370
370
|
export declare function accountAction(account: PoolAccount, now?: number): 'none' | 'wait' | 'regrant';
|
|
371
371
|
export interface PoolStatus {
|
|
372
|
+
/** The routing strategy in force for new conversations. */
|
|
373
|
+
strategy: PoolStrategy;
|
|
374
|
+
/** Headroom at/below which a seat counts as drained (ratio). */
|
|
375
|
+
headroomFloor: number;
|
|
372
376
|
accounts: number;
|
|
373
377
|
healthy: number;
|
|
374
378
|
exhausted: number;
|
|
@@ -413,6 +417,27 @@ export type PoolStrategy = 'headroom' | 'fill-first' | 'expiring-first';
|
|
|
413
417
|
* in this codebase (see resolveSessionRotationConfig).
|
|
414
418
|
*/
|
|
415
419
|
export declare function resolvePoolStrategy(explicit?: string | null, env?: NodeJS.ProcessEnv): PoolStrategy;
|
|
420
|
+
/**
|
|
421
|
+
* One line saying where new conversations go, for every surface that names the
|
|
422
|
+
* strategy (startup banner, `dario doctor`, `dario accounts list`). The running
|
|
423
|
+
* strategy used to be invisible: the banner printed it only when it was NOT the
|
|
424
|
+
* default, and nothing else reported it, so a deployment whose compose file
|
|
425
|
+
* overrode the default ran that way unnoticed (fleet box, 2026-09-22).
|
|
426
|
+
*/
|
|
427
|
+
export declare function describePoolStrategy(strategy: PoolStrategy, floor?: number): string;
|
|
428
|
+
/**
|
|
429
|
+
* The strategy and floor a proxy started with no flags would run with, for
|
|
430
|
+
* commands that do not run the proxy (`doctor`, `accounts list`): env first,
|
|
431
|
+
* then the config file, then the defaults — the proxy's own order minus the
|
|
432
|
+
* CLI flag, which only the running process knows (GET /status reports it).
|
|
433
|
+
*/
|
|
434
|
+
export declare function configuredPoolRouting(file: {
|
|
435
|
+
strategy?: string;
|
|
436
|
+
headroomFloor?: number;
|
|
437
|
+
} | undefined, env?: NodeJS.ProcessEnv): {
|
|
438
|
+
strategy: PoolStrategy;
|
|
439
|
+
headroomFloor: number;
|
|
440
|
+
};
|
|
416
441
|
/**
|
|
417
442
|
* Which wire buckets bind which model family, when the wire does not say it
|
|
418
443
|
* by name. `7d_sonnet` names its family; `7d_oi` does not — it is the plan's
|
|
@@ -576,7 +601,7 @@ export declare function resolvePoolHeadroomFloor(explicit?: string | number | nu
|
|
|
576
601
|
*/
|
|
577
602
|
export declare function seatExpiry(account: PoolAccount, now?: number): number;
|
|
578
603
|
export declare class AccountPool {
|
|
579
|
-
|
|
604
|
+
readonly strategy: PoolStrategy;
|
|
580
605
|
/** Headroom at/below which a seat counts as drained — see DEFAULT_POOL_HEADROOM_FLOOR. */
|
|
581
606
|
readonly headroomFloor: number;
|
|
582
607
|
private accounts;
|
package/dist/pool.js
CHANGED
|
@@ -428,6 +428,36 @@ export function resolvePoolStrategy(explicit, env = process.env) {
|
|
|
428
428
|
}
|
|
429
429
|
return 'headroom';
|
|
430
430
|
}
|
|
431
|
+
/**
|
|
432
|
+
* One line saying where new conversations go, for every surface that names the
|
|
433
|
+
* strategy (startup banner, `dario doctor`, `dario accounts list`). The running
|
|
434
|
+
* strategy used to be invisible: the banner printed it only when it was NOT the
|
|
435
|
+
* default, and nothing else reported it, so a deployment whose compose file
|
|
436
|
+
* overrode the default ran that way unnoticed (fleet box, 2026-09-22).
|
|
437
|
+
*/
|
|
438
|
+
export function describePoolStrategy(strategy, floor = DEFAULT_POOL_HEADROOM_FLOOR) {
|
|
439
|
+
const pct = `${Math.round(floor * 100)}% floor`;
|
|
440
|
+
switch (strategy) {
|
|
441
|
+
case 'fill-first':
|
|
442
|
+
return `fill-first — new conversations fill the alphabetically-first seat until the ${pct}, then spill`;
|
|
443
|
+
case 'expiring-first':
|
|
444
|
+
return `expiring-first — new conversations fill the seat whose 7-day window resets soonest until the ${pct}, then spill`;
|
|
445
|
+
default:
|
|
446
|
+
return `headroom (default) — new conversations go to the seat with the most headroom; ${pct}`;
|
|
447
|
+
}
|
|
448
|
+
}
|
|
449
|
+
/**
|
|
450
|
+
* The strategy and floor a proxy started with no flags would run with, for
|
|
451
|
+
* commands that do not run the proxy (`doctor`, `accounts list`): env first,
|
|
452
|
+
* then the config file, then the defaults — the proxy's own order minus the
|
|
453
|
+
* CLI flag, which only the running process knows (GET /status reports it).
|
|
454
|
+
*/
|
|
455
|
+
export function configuredPoolRouting(file, env = process.env) {
|
|
456
|
+
return {
|
|
457
|
+
strategy: resolvePoolStrategy(env.DARIO_POOL_STRATEGY ?? file?.strategy, env),
|
|
458
|
+
headroomFloor: resolvePoolHeadroomFloor(env.DARIO_POOL_HEADROOM_FLOOR ?? file?.headroomFloor, env),
|
|
459
|
+
};
|
|
460
|
+
}
|
|
431
461
|
/**
|
|
432
462
|
* Match `anthropic-ratelimit-unified-7d_<family>-utilization`. Generic on
|
|
433
463
|
* `<family>` so a future `7d_opus` / `7d_haiku` (or anything Anthropic
|
|
@@ -1264,6 +1294,8 @@ export class AccountPool {
|
|
|
1264
1294
|
const avgHeadroom = headrooms.length > 0 ? headrooms.reduce((a, b) => a + b, 0) / headrooms.length : 0;
|
|
1265
1295
|
const best = this.select();
|
|
1266
1296
|
return {
|
|
1297
|
+
strategy: this.strategy,
|
|
1298
|
+
headroomFloor: this.headroomFloor,
|
|
1267
1299
|
accounts: all.length,
|
|
1268
1300
|
healthy: healthy.length,
|
|
1269
1301
|
exhausted: all.length - healthy.length,
|
package/dist/proxy.js
CHANGED
|
@@ -13,7 +13,7 @@ import { CC_TOOL_DEFINITIONS_UNADVERTISABLE, CC_TEMPLATE_PROMPT_BYTES, resolveMa
|
|
|
13
13
|
import { stampCch, hasCchSeed } from './cch.js';
|
|
14
14
|
import { foldTiming, timingHeaders, timingLogFields } from './timing.js';
|
|
15
15
|
import { describeTemplate, detectDrift, checkCCCompat, probeInstalledCCVersion } from './live-fingerprint.js';
|
|
16
|
-
import { AccountPool, computeStickyKey, parseRateLimits, modelFamily, isInAuthCooldown, authCooldownMs, accountIneligibility, reportedAccountStatus, activeParkedBuckets, reconcilePoolAccounts, resolvePoolStrategy, resolvePoolHeadroomFloor, DEFAULT_POOL_HEADROOM_FLOOR, utilFreshness, rateLimitWindow, accountAction, accountPeers, distinctAccounts, describeRejection, maskEmail, isAccountEligible } from './pool.js';
|
|
16
|
+
import { AccountPool, computeStickyKey, parseRateLimits, modelFamily, isInAuthCooldown, authCooldownMs, accountIneligibility, reportedAccountStatus, activeParkedBuckets, reconcilePoolAccounts, resolvePoolStrategy, resolvePoolHeadroomFloor, describePoolStrategy, DEFAULT_POOL_HEADROOM_FLOOR, utilFreshness, rateLimitWindow, accountAction, accountPeers, distinctAccounts, describeRejection, maskEmail, isAccountEligible } from './pool.js';
|
|
17
17
|
import { backfillIdentity } from './accounts.js';
|
|
18
18
|
import { PoolSync, DEFAULT_POOL_SYNC_INTERVAL_MS } from './pool-sync.js';
|
|
19
19
|
import { Analytics, billingBucketFromClaim, costOfTokens, formatUsageLogLine, SUBSCRIPTION_CLAIMS, consumerFromHeader, consumerFromBody, CONSUMER_HEADER, CODEX_CLAIM } from './analytics.js';
|
|
@@ -48,7 +48,9 @@ import { responsesRequestToAnthropic, unsupportedOnClaudeError, ResponsesRequest
|
|
|
48
48
|
import { isClaudeServableModel } from './claude-model.js';
|
|
49
49
|
import { MODEL_UNROUTABLE } from './upstream-rejection.js';
|
|
50
50
|
import { readCompareTarget, teeResponse, runCompare, writeCompareRecord, COMPARE_RESULT_HEADER } from './compare.js';
|
|
51
|
-
import { listCodexAccountAliases, loadAllCodexAccounts, codexAccountNeedsRefresh, hasAnyCodexAccount, selectCodexAccount, selectCodexAccountExcluding, rebindCodexSticky, getFreshCodexAccount, noteCodexDecline, clearCodexDecline, allAliasesCooled, CodexCredentialsUnavailableError, resetCodexPresenceCache, codexSeatStatus, } from './codex-accounts.js';
|
|
51
|
+
import { listCodexAccountAliases, loadAllCodexAccounts, codexAccountNeedsRefresh, hasAnyCodexAccount, selectCodexAccount, selectCodexAccountExcluding, rebindCodexSticky, getFreshCodexAccount, noteCodexDecline, clearCodexDecline, allAliasesCooled, CodexCredentialsUnavailableError, resetCodexPresenceCache, codexSeatStatus, setCodexRouting, } from './codex-accounts.js';
|
|
52
|
+
import { codexUsageView, resolveCodexUsagePollMs } from './codex-usage.js';
|
|
53
|
+
import { seedStaleCodexUsage } from './codex-backend.js';
|
|
52
54
|
import { route as routeProvider } from './provider-adapter.js';
|
|
53
55
|
import { selectPoolFallbackModels } from './pool-fallback-tier.js';
|
|
54
56
|
import { RequestQueue, QueueFullError, QueueTimeoutError, DEFAULT_MAX_CONCURRENT, DEFAULT_MAX_QUEUED, DEFAULT_QUEUE_TIMEOUT_MS, resolveMaxConcurrent } from './request-queue.js';
|
|
@@ -1521,9 +1523,26 @@ export async function startProxy(opts = {}) {
|
|
|
1521
1523
|
if (opts.poolSharedState && !poolSync) {
|
|
1522
1524
|
console.error('[dario] --pool-shared-state needs DARIO_REFRESH_LOCK_URL (the lock service carries the shared state) — running with this instance\'s own state');
|
|
1523
1525
|
}
|
|
1524
|
-
|
|
1525
|
-
|
|
1526
|
-
|
|
1526
|
+
// Always named, the default included: a deployment that overrides the
|
|
1527
|
+
// default should be visible at a glance, and one that does not should say so.
|
|
1528
|
+
console.log(` Pool strategy: ${describePoolStrategy(poolStrategy, pool.headroomFloor)}`);
|
|
1529
|
+
// ChatGPT seats: same strategy and floor. Idle seats are read from
|
|
1530
|
+
// /wham/usage (no model call) at most once per DARIO_CODEX_USAGE_POLL_MS.
|
|
1531
|
+
setCodexRouting({ strategy: poolStrategy, floor: pool.headroomFloor });
|
|
1532
|
+
const codexUsagePollMs = resolveCodexUsagePollMs(process.env['DARIO_CODEX_USAGE_POLL_MS']);
|
|
1533
|
+
let codexUsageTimer = null;
|
|
1534
|
+
if (codexUsagePollMs > 0) {
|
|
1535
|
+
const readIdleCodexSeats = async () => {
|
|
1536
|
+
try {
|
|
1537
|
+
const seats = (await loadAllCodexAccounts()).filter((a) => !codexAccountNeedsRefresh(a));
|
|
1538
|
+
if (seats.length > 0)
|
|
1539
|
+
await seedStaleCodexUsage(seats, codexUsagePollMs);
|
|
1540
|
+
}
|
|
1541
|
+
catch { /* best-effort: selection falls back to header readings */ }
|
|
1542
|
+
};
|
|
1543
|
+
void readIdleCodexSeats();
|
|
1544
|
+
codexUsageTimer = setInterval(() => { void readIdleCodexSeats(); }, codexUsagePollMs);
|
|
1545
|
+
codexUsageTimer.unref?.();
|
|
1527
1546
|
}
|
|
1528
1547
|
if (poolSync) {
|
|
1529
1548
|
console.log(` Pool shared state: on (instance ${poolSync.instance}, via ${lockUrl}, pulling peers every ${poolSync.intervalMs}ms; fails open)`);
|
|
@@ -2680,7 +2699,14 @@ export async function startProxy(opts = {}) {
|
|
|
2680
2699
|
// Version for auto-update checks (#640) — /status is key-gated (loopback
|
|
2681
2700
|
// or DARIO_API_KEY), so no public-disclosure concern like /health has.
|
|
2682
2701
|
res.writeHead(200, JSON_HEADERS);
|
|
2683
|
-
res.end(JSON.stringify({
|
|
2702
|
+
res.end(JSON.stringify({
|
|
2703
|
+
version: darioVersion(),
|
|
2704
|
+
...s,
|
|
2705
|
+
// The routing the running process uses — the only surface that can
|
|
2706
|
+
// report a --pool-strategy flag (doctor and `accounts list` read env
|
|
2707
|
+
// and config). null with no pool.
|
|
2708
|
+
pool: pool.size > 0 ? { strategy: pool.strategy, headroomFloor: pool.headroomFloor, accounts: pool.size } : null,
|
|
2709
|
+
}));
|
|
2684
2710
|
return;
|
|
2685
2711
|
}
|
|
2686
2712
|
// Pool status endpoint — shows loaded accounts, headroom, and the
|
|
@@ -2800,6 +2826,7 @@ export async function startProxy(opts = {}) {
|
|
|
2800
2826
|
// for a minute (DEV-179a412f). Read from memory only — a status read
|
|
2801
2827
|
// never spends or exposes a credential, so there is no token in any of it.
|
|
2802
2828
|
...codexSeatStatus(a.alias),
|
|
2829
|
+
usage: codexUsageView(a.alias, now),
|
|
2803
2830
|
}));
|
|
2804
2831
|
res.writeHead(200, JSON_HEADERS);
|
|
2805
2832
|
res.end(JSON.stringify({
|
|
@@ -5779,6 +5806,8 @@ export async function startProxy(opts = {}) {
|
|
|
5779
5806
|
}
|
|
5780
5807
|
}
|
|
5781
5808
|
});
|
|
5809
|
+
server.on('close', () => { if (codexUsageTimer)
|
|
5810
|
+
clearInterval(codexUsageTimer); });
|
|
5782
5811
|
server.on('error', async (err) => {
|
|
5783
5812
|
if (err.code === 'EADDRINUSE') {
|
|
5784
5813
|
// Before erroring, check whether dario itself is already running on this
|
package/docs/admin-api.md
CHANGED
|
@@ -267,7 +267,7 @@ The same flow for a ChatGPT Plus/Pro seat, for a proxy that never sees a termina
|
|
|
267
267
|
|---|---|---|
|
|
268
268
|
| `POST /admin/codex/login/start` | `{ "alias"?: string }` | `{ alias, authorize_url, expires_at, instructions }` — default alias `altman-1`, `altman-2`, … ; `409` if the alias already holds a seat |
|
|
269
269
|
| `POST /admin/codex/login/complete` | `{ "alias": string, "code": string }` — the redirect URL, or the bare code | `{ alias, status: "added", expires_at }` |
|
|
270
|
-
| `GET /admin/codex/accounts` | — | `{ accounts: [{ alias, expiresAt, needsRefresh }], count }` |
|
|
270
|
+
| `GET /admin/codex/accounts` | — | `{ accounts: [{ alias, expiresAt, needsRefresh, status, cooldownRemainingMs, lastRefreshError, usage }], count }`. `usage` is the seat's latest utilisation (`headroom` 0–1, `windows[]` with `usedPercent`, `windowMinutes`, `resetAt`, and `source`: `headers` or `usage-endpoint`), or `null` before its first answer or read |
|
|
271
271
|
| `DELETE /admin/codex/accounts/<alias>` | — | `{ alias, removed }` (`404` if no such alias) |
|
|
272
272
|
|
|
273
273
|
A running proxy serves the new seat on its next request; nothing restarts. Same token, same rate limits, same audit log — codex events carry `engine: "codex"`. The seat is stored where the CLI stores it (`~/.dario/codex-accounts/<alias>.json`), so `dario codex list` and `dario codex remove` see it too.
|
|
@@ -22,7 +22,7 @@
|
|
|
22
22
|
| `GET /health` · `GET /livez` | Serviceability (503 when not) · liveness. `/health?probe=1` sends one real request |
|
|
23
23
|
| `GET /status` · `GET /accounts` · `GET /analytics` | OAuth detail · per-seat utilization and grant age · per-account / per-model stats and burn rate |
|
|
24
24
|
| `POST /v1/messages/count_tokens` · `POST /v1/complete` | Token counting and the legacy Text Completions shape |
|
|
25
|
-
| `GET /analytics/stream` · `GET /analytics/ledger` · `GET /codex` | Live analytics over SSE · the ledger's per-day table · ChatGPT-seat status, read without spending or exposing a token |
|
|
25
|
+
| `GET /analytics/stream` · `GET /analytics/ledger` · `GET /codex` | Live analytics over SSE · the ledger's per-day table · ChatGPT-seat status and utilisation (used %, window, reset, headroom), read without spending or exposing a token |
|
|
26
26
|
| `/admin/*` | Provisioning, `GET /admin/accounts`, `/admin/keys`, `POST /admin/resume`; only with `DARIO_ADMIN=1` ([admin API](admin-api.md)) |
|
|
27
27
|
|
|
28
28
|
Flags: [commands.md](commands.md), plus `dario --help` for the ones it doesn't list yet (`--effort`, `--max-tokens`, `--model-alias`, `--fast-model`, session rotation, concurrency caps, the pacing knobs behind `--stealth`) · env vars grouped by task, for Docker / k8s / systemd: [configuration.md](configuration.md) · SDK examples: [usage.md](usage.md).
|
package/docs/configuration.md
CHANGED
|
@@ -50,6 +50,13 @@ Halts the proxy when an upstream response reports `representative-claim: overage
|
|
|
50
50
|
| `DARIO_KEYS` | `--no-keys` | on | `0` ignores `~/.dario/keys.json`: only `DARIO_API_KEY` authenticates. See [Named keys](./keys.md) |
|
|
51
51
|
| `DARIO_KEYS_PATH` | `--keys-path=<file>` | `~/.dario/keys.json` | where the key hashes live; `dario keys` and the running proxy read the same file |
|
|
52
52
|
|
|
53
|
+
## ChatGPT seats
|
|
54
|
+
|
|
55
|
+
| Variable | Flag | Default | Notes |
|
|
56
|
+
|---|---|---|---|
|
|
57
|
+
| `DARIO_CODEX_USAGE_POLL_MS` | — | `1800000` (30 min) | how stale a ChatGPT seat's utilisation reading may get before the proxy re-reads it from `/backend-api/wham/usage` (no model call). A seat that is serving is read from every answer and never polled; boot reads each seat once. `0` turns the reads off and leaves only the per-answer headers. Floored at one minute |
|
|
58
|
+
| `DARIO_CODEX_USAGE_URL` | — | derived from `DARIO_CODEX_BASE_URL` | the usage endpoint; `…/backend-api/wham/usage` beside the Responses base |
|
|
59
|
+
|
|
53
60
|
## Multi-instance
|
|
54
61
|
|
|
55
62
|
| Variable | Flag | Default | Notes |
|
|
@@ -21,6 +21,20 @@ Three things it does that a round-robin doesn't:
|
|
|
21
21
|
|
|
22
22
|
<img src="../.github/readme/pool.jpg" alt="Three pooled seats, work, personal and side, each with a headroom bar. dario routes the request to the seat with the most headroom." width="100%">
|
|
23
23
|
|
|
24
|
+
## ChatGPT seats
|
|
25
|
+
|
|
26
|
+
ChatGPT plans added with `dario codex add <alias>` pool the same way. The Codex backend states a seat's utilisation on every answer (`x-codex-primary-used-percent`, `-window-minutes`, `-reset-at`, and the same for the secondary window: the family the Codex CLI itself parses), so dario reads it off each response and places new conversations by the same `--pool-strategy` and floor as the Claude pool. A seat nothing has asked yet is read once from `/backend-api/wham/usage`, which spends no model call, and an idle seat is re-read at most every `DARIO_CODEX_USAGE_POLL_MS` (30 min). A conversation stays on the seat it started on, because the Codex prompt cache is scoped to the serving account; a seat that declines is cooled and skipped whatever its last reading said, and the request fails over mid-flight. Which windows a seat has depends on the plan: a Plus or Pro seat carries a short window and a weekly one, a Pro Lite seat a single weekly window.
|
|
27
|
+
|
|
28
|
+
`dario codex list --live` and `GET /codex` show each seat's used %, window and reset time, and its headroom:
|
|
29
|
+
|
|
30
|
+
```
|
|
31
|
+
fleet ok
|
|
32
|
+
token expires in 5523m, 214 requests served
|
|
33
|
+
usage: 6% of 7d, resets in 6d 22h — 94% headroom (from its last answer)
|
|
34
|
+
```
|
|
35
|
+
|
|
36
|
+
Earlier releases placed ChatGPT conversations fill-first in alias order with cool-down eviction only, on the belief that the backend reported nothing before a 429, so a second seat served nothing until the first one declined.
|
|
37
|
+
|
|
24
38
|
`--pool-strategy=fill-first` concentrates new conversations on one seat until it drains, for primary/backup setups; `--pool-strategy=expiring-first` fills in order of each seat's 7-day reset, soonest first, so capacity that expires soonest is spent first. `--pool-headroom-floor=5%` (env `DARIO_POOL_HEADROOM_FLOOR`, config `pool.headroomFloor`; default 2%) moves the line at which a seat counts as drained: a sticky session rebinds off it and new conversations skip it once its headroom is at or below the floor, so a seat that answers with API errors in its last percent is left alone before the 429, not at it. Refresh tokens expire about 28 days after the original grant regardless of rotation, so every seat's grant age is tracked and surfaced in `dario accounts list`, `dario doctor` and `GET /accounts` before it becomes a silent outage. Provision over HTTP with the headless [admin API](admin-api.md); pin one request to one seat with `dario accounts check <alias>` (admin API required: `DARIO_ADMIN=1` and a `DARIO_ADMIN_TOKEN`). Internals and the live `/accounts` + `/analytics` endpoints: [multi-account-pool.md](multi-account-pool.md); covered end-to-end by [`test/pool-e2e.mjs`](../test/pool-e2e.mjs).
|
|
25
39
|
|
|
26
40
|
## One key per developer
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@askalf/dario",
|
|
3
|
-
"version": "6.11.
|
|
3
|
+
"version": "6.11.2",
|
|
4
4
|
"description": "Use your Claude and ChatGPT subscriptions in Cursor, Cline, Aider, Claude Code and the Agent SDK — at subscription pricing, not per-token API bills. One local Anthropic + OpenAI-compatible endpoint: either plan answers either wire shape, with automatic failover when one hits its limit.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"bin": {
|