agl 43.9.0 → 43.10.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/changelog.md +20 -0
- package/dist_serve/bundle.js +997 -975
- package/dist_serve/bundle.js.map +2 -2
- package/dist_ts/00_commitinfo_data.js +2 -2
- package/dist_ts/aglapi/aglapisurface.document.js +3 -3
- package/dist_ts/classes.accountsactions.d.ts +3 -1
- package/dist_ts/classes.accountsactions.js +17 -1
- package/dist_ts/classes.authstore.d.ts +6 -0
- package/dist_ts/classes.authstore.js +8 -1
- package/dist_ts/classes.controller.d.ts +7 -1
- package/dist_ts/classes.controller.js +39 -7
- package/dist_ts/classes.inferencegateway.js +7 -5
- package/dist_ts/classes.inferenceplacement.d.ts +1 -1
- package/dist_ts/classes.inferencerouter.d.ts +20 -3
- package/dist_ts/classes.inferencerouter.js +37 -10
- package/dist_ts/classes.inferenceservice.js +2 -2
- package/dist_ts/classes.mcpcallerregistry.d.ts +19 -1
- package/dist_ts/classes.mcpcallerregistry.js +33 -7
- package/dist_ts/classes.terminalcallers.d.ts +40 -0
- package/dist_ts/classes.terminalcallers.js +90 -0
- package/dist_ts/classes.terminalmanager.d.ts +20 -1
- package/dist_ts/classes.terminalmanager.js +36 -2
- package/dist_ts/classes.ticketnotifier.d.ts +2 -2
- package/dist_ts/classes.ticketnotifier.js +6 -4
- package/dist_ts/classes.ticketorderspread.d.ts +25 -0
- package/dist_ts/classes.ticketorderspread.js +52 -0
- package/dist_ts/classes.ticketstore.d.ts +60 -5
- package/dist_ts/classes.ticketstore.js +176 -40
- package/dist_ts/classes.workercallers.d.ts +40 -2
- package/dist_ts/classes.workercallers.js +156 -30
- package/dist_ts/fleet/classes.boardpump.d.ts +1 -1
- package/dist_ts/fleet/classes.boardpump.js +4 -2
- package/dist_ts/fleet/classes.claudeworkers.d.ts +18 -5
- package/dist_ts/fleet/classes.claudeworkers.js +105 -31
- package/dist_ts/fleet/classes.ticketeffects.d.ts +11 -0
- package/dist_ts/fleet/classes.ticketeffects.js +28 -1
- package/dist_ts/fleet/classes.workers.d.ts +23 -4
- package/dist_ts/fleet/classes.workers.js +65 -18
- package/dist_ts/fleet/functions.workervalidation.js +7 -4
- package/dist_ts/fleet/interfaces.workers.d.ts +16 -2
- package/dist_ts/fleet/interfaces.workers.js +8 -1
- package/dist_ts/functions.fleetworkercli.d.ts +3 -1
- package/dist_ts/functions.fleetworkercli.js +6 -2
- package/dist_ts/functions.inferencecli.js +4 -1
- package/dist_ts/functions.mcpfleetworkertools.js +3 -3
- package/dist_ts/functions.proxycapacity.d.ts +2 -1
- package/dist_ts/functions.proxycapacity.js +6 -3
- package/dist_ts/functions.proxycapacitycli.js +2 -2
- package/dist_ts/functions.workerprocessproof.d.ts +6 -0
- package/dist_ts/functions.workerprocessproof.js +8 -3
- package/dist_ts/interfaces.auth.d.ts +1 -1
- package/dist_ts/interfaces.auth.js +2 -1
- package/dist_ts/interfaces.flexipc.d.ts +3 -1
- package/dist_ts/interfaces.flexipc.js +1 -1
- package/dist_ts_authswitch/authority-contract.d.ts +25 -0
- package/dist_ts_authswitch/authority-contract.js +1 -1
- package/dist_ts_authswitch/authority-overview.d.ts +7 -0
- package/dist_ts_authswitch/authority-overview.js +10 -6
- package/dist_ts_authswitch/authority-placement.d.ts +5 -2
- package/dist_ts_authswitch/authority-placement.js +6 -3
- package/dist_ts_authswitch/classes.authoritybroker.d.ts +6 -0
- package/dist_ts_authswitch/classes.authoritybroker.js +26 -1
- package/dist_ts_authswitch/classes.authoritycli.d.ts +1 -0
- package/dist_ts_authswitch/classes.authoritycli.js +50 -4
- package/dist_ts_authswitch/classes.authorityclient.d.ts +3 -1
- package/dist_ts_authswitch/classes.authorityclient.js +9 -4
- package/dist_ts_authswitch/classes.authoritydaemon.js +7 -1
- package/dist_ts_authswitch/classes.authoritydatabase.js +5 -1
- package/dist_ts_authswitch/classes.authoritymodels.d.ts +7 -0
- package/dist_ts_authswitch/classes.authoritymodels.js +13 -6
- package/dist_ts_interfaces/fleetworkers.d.ts +26 -1
- package/dist_ts_interfaces/fleetworkers.js +1 -1
- package/dist_ts_interfaces/interfaces.d.ts +4 -2
- package/dist_ts_interfaces/interfaces.js +1 -1
- package/dist_ts_interfaces/mcprequests.d.ts +2 -1
- package/dist_ts_interfaces/mcprequests.js +3 -2
- package/dist_ts_interfaces/proxycapacity.d.ts +1 -1
- package/dist_ts_interfaces/requests.accounts.d.ts +19 -0
- package/dist_ts_interfaces/requests.accounts.js +1 -1
- package/dist_ts_interfaces/requests.d.ts +2 -2
- package/dist_ts_interfaces/requests.fleetworkers.d.ts +3 -1
- package/dist_ts_interfaces/requests.js +1 -1
- package/dist_ts_migration/classes.documentmigrationrunner.d.ts +8 -1
- package/dist_ts_migration/classes.documentmigrationrunner.js +11 -2
- package/dist_ts_migration/index.d.ts +1 -0
- package/dist_ts_migration/index.js +2 -1
- package/dist_ts_migration/v41_ticketclosedcolumn.js +7 -3
- package/dist_ts_migration/v43_ticketorderstride.d.ts +54 -0
- package/dist_ts_migration/v43_ticketorderstride.js +161 -0
- package/docs/authswitch.md +22 -0
- package/package.json +1 -1
- package/readme.md +71 -4
- package/ts/00_commitinfo_data.ts +1 -1
- package/ts/aglapi/aglapisurface.document.ts +2 -2
- package/ts/classes.accountsactions.ts +25 -0
- package/ts/classes.authstore.ts +9 -0
- package/ts/classes.controller.ts +37 -3
- package/ts/classes.inferencegateway.ts +6 -4
- package/ts/classes.inferenceplacement.ts +1 -1
- package/ts/classes.inferencerouter.ts +49 -10
- package/ts/classes.inferenceservice.ts +1 -1
- package/ts/classes.mcpcallerregistry.ts +49 -7
- package/ts/classes.terminalcallers.ts +91 -0
- package/ts/classes.terminalmanager.ts +41 -1
- package/ts/classes.ticketnotifier.ts +5 -3
- package/ts/classes.ticketorderspread.ts +50 -0
- package/ts/classes.ticketstore.ts +164 -35
- package/ts/classes.workercallers.ts +183 -30
- package/ts/fleet/classes.boardpump.ts +3 -2
- package/ts/fleet/classes.claudeworkers.ts +101 -29
- package/ts/fleet/classes.ticketeffects.ts +25 -0
- package/ts/fleet/classes.workers.ts +62 -17
- package/ts/fleet/functions.workervalidation.ts +6 -3
- package/ts/fleet/interfaces.workers.ts +16 -2
- package/ts/functions.fleetworkercli.ts +5 -1
- package/ts/functions.inferencecli.ts +2 -0
- package/ts/functions.mcpfleetworkertools.ts +2 -2
- package/ts/functions.proxycapacity.ts +5 -2
- package/ts/functions.proxycapacitycli.ts +1 -1
- package/ts/functions.workerprocessproof.ts +10 -2
- package/ts/interfaces.auth.ts +1 -0
- package/ts/interfaces.flexipc.ts +3 -1
- package/ts_authswitch/authority-contract.ts +20 -0
- package/ts_authswitch/authority-overview.ts +17 -6
- package/ts_authswitch/authority-placement.ts +7 -3
- package/ts_authswitch/classes.authoritybroker.ts +24 -0
- package/ts_authswitch/classes.authoritycli.ts +58 -4
- package/ts_authswitch/classes.authorityclient.ts +11 -4
- package/ts_authswitch/classes.authoritydaemon.ts +8 -1
- package/ts_authswitch/classes.authoritydatabase.ts +3 -0
- package/ts_authswitch/classes.authoritymodels.ts +12 -4
- package/ts_interfaces/fleetworkers.ts +26 -1
- package/ts_interfaces/interfaces.ts +4 -2
- package/ts_interfaces/mcprequests.ts +2 -1
- package/ts_interfaces/proxycapacity.ts +1 -1
- package/ts_interfaces/requests.accounts.ts +17 -0
- package/ts_interfaces/requests.fleetworkers.ts +3 -1
- package/ts_interfaces/requests.ts +2 -0
- package/ts_migration/classes.documentmigrationrunner.ts +12 -1
- package/ts_migration/index.ts +1 -0
- package/ts_migration/v41_ticketclosedcolumn.ts +6 -2
- package/ts_migration/v43_ticketorderstride.ts +156 -0
- package/ts_web/00_commitinfo_data.ts +1 -1
- package/ts_web/accounts.templates.ts +12 -2
- package/ts_web/classes.accountsreadmodel.ts +42 -6
- package/ts_web/elements.accounts.ts +45 -3
- package/ts_web/elements.harnesscontrollerapp.ts +6 -1
|
@@ -49,7 +49,7 @@ const poolText = (poolArg: IProxyCapacityPool, observedSinceArg: string): string
|
|
|
49
49
|
`${poolNames[poolArg.provider]} pool (${poolArg.provider}): ${verdictText}; room ${percent(poolArg.room)}, `
|
|
50
50
|
+ `minimum ${poolArg.minHeadroom}%; last provider 429 on a member: ${poolArg.last429At ?? `none since ${observedSinceArg}`}`,
|
|
51
51
|
...poolArg.members.length ? poolArg.members.map(memberText)
|
|
52
|
-
: [` no account counts (${countedPlans(poolArg.provider)}, a subscription sign-in that has not lapsed)`],
|
|
52
|
+
: [` no account counts (${countedPlans(poolArg.provider)}, a subscription sign-in that has not lapsed and is not paused)`],
|
|
53
53
|
];
|
|
54
54
|
};
|
|
55
55
|
|
|
@@ -215,6 +215,15 @@ export const verifyClaudeWorkerProcess = async (
|
|
|
215
215
|
return snapshot;
|
|
216
216
|
};
|
|
217
217
|
|
|
218
|
+
/**
|
|
219
|
+
* Whether `executableArg`, a process's executable as the kernel names it, lies in the directory of the Claude Code
|
|
220
|
+
* release `releaseArg`: the directory Claude Code installs every release in. A release file removed since the process
|
|
221
|
+
* started still does (the kernel names it with ` (deleted)` appended); a shell or a terminal does not.
|
|
222
|
+
*/
|
|
223
|
+
export const inClaudeReleaseDirectory = (executableArg: string, releaseArg: string): boolean => (
|
|
224
|
+
plugins.path.isAbsolute(executableArg) && plugins.path.dirname(executableArg) === plugins.path.dirname(releaseArg)
|
|
225
|
+
);
|
|
226
|
+
|
|
218
227
|
/**
|
|
219
228
|
* The process `processArg` (PID and start), proved to run an installed Claude Code release: its executable is a
|
|
220
229
|
* regular file of the controller's user in the directory of `releaseArg`, the release `claude` resolves to now, and is
|
|
@@ -231,8 +240,7 @@ export const verifyClaudeReleaseProcess = async (
|
|
|
231
240
|
throw new WorkerCallerProofError('Invalid Claude launch observation.');
|
|
232
241
|
}
|
|
233
242
|
const snapshot = await readWorkerProcessSnapshot(processArg.pid);
|
|
234
|
-
if (snapshot.startTicks !== processArg.startTicks || !
|
|
235
|
-
|| plugins.path.dirname(snapshot.executable) !== plugins.path.dirname(releaseArg)) {
|
|
243
|
+
if (snapshot.startTicks !== processArg.startTicks || !inClaudeReleaseDirectory(snapshot.executable, releaseArg)) {
|
|
236
244
|
throw new WorkerCallerProofError('The Claude process does not run an installed Claude Code release.');
|
|
237
245
|
}
|
|
238
246
|
const [installed, running] = await Promise.all([plugins.fs.promises.lstat(snapshot.executable, { bigint: true }),
|
package/ts/interfaces.auth.ts
CHANGED
package/ts/interfaces.flexipc.ts
CHANGED
|
@@ -614,7 +614,9 @@ export type TFlexPublicConnectionState =
|
|
|
614
614
|
| 'deleting'
|
|
615
615
|
| 'reauthRequired'
|
|
616
616
|
/** This host's Codex runs on the account, which renews its login; Flex cannot use it meanwhile. */
|
|
617
|
-
| 'inHostCodex'
|
|
617
|
+
| 'inHostCodex'
|
|
618
|
+
/** The account's owner holds it paused (AGL-1933): AGL places nothing on it until it is resumed. */
|
|
619
|
+
| 'paused';
|
|
618
620
|
|
|
619
621
|
/**
|
|
620
622
|
* The providers Flex runs models of: OpenAI on the ChatGPT accounts the accounts service holds, Anthropic on the
|
|
@@ -288,6 +288,14 @@ export interface IAuthSwitchAccount {
|
|
|
288
288
|
* one.
|
|
289
289
|
*/
|
|
290
290
|
priorityUntil: string | null;
|
|
291
|
+
/**
|
|
292
|
+
* Since when the account is paused by its owner (AGL-1933), ISO 8601 UTC by the authority's clock; `null` while it is
|
|
293
|
+
* not. A paused account takes no new work: placement never chooses it (`authSwitchPlacement` answers `never`), AGL's
|
|
294
|
+
* inference proxy leaves it out of every pool, and a session on it moves to another account. Its sign-in, logins,
|
|
295
|
+
* usage readings, limits and renewal stay as they are and keep being read, so it is ready the moment it is resumed.
|
|
296
|
+
* It has no end: it holds until the owner resumes the account. A paused account holds no priority.
|
|
297
|
+
*/
|
|
298
|
+
pausedAt: string | null;
|
|
291
299
|
/**
|
|
292
300
|
* An API key account's spend limit per calendar month in UTC, in micro-dollars (`isAuthSwitchSpendLimitMicroUsd`);
|
|
293
301
|
* `null` for none, and always for an account on a sign-in. The limit counts what AGL's inference proxy relayed on the
|
|
@@ -1565,6 +1573,18 @@ export interface IReq_AuthSwitchSetAccountPriority extends ITypedRequest {
|
|
|
1565
1573
|
response: { account: IAuthSwitchAccount };
|
|
1566
1574
|
}
|
|
1567
1575
|
|
|
1576
|
+
/**
|
|
1577
|
+
* Pauses an account (`paused: true`) or resumes it (`false`): see `IAuthSwitchAccount.pausedAt`. Pausing ends a priority
|
|
1578
|
+
* the account holds; pausing a paused account, or resuming one that is not, changes nothing but its revision. The moment
|
|
1579
|
+
* is the authority's clock, never the caller's. `expectedRevision` is the revision the caller read, so a change of an
|
|
1580
|
+
* account that changed meanwhile is refused as `account_changed`.
|
|
1581
|
+
*/
|
|
1582
|
+
export interface IReq_AuthSwitchSetAccountPause extends ITypedRequest {
|
|
1583
|
+
method: 'authswitch.authority.pause';
|
|
1584
|
+
request: { accountId: string; expectedRevision: number; paused: boolean };
|
|
1585
|
+
response: { account: IAuthSwitchAccount };
|
|
1586
|
+
}
|
|
1587
|
+
|
|
1568
1588
|
/**
|
|
1569
1589
|
* One binding by the id `bind` returned, credential-free, or `null` when this authority holds no binding by
|
|
1570
1590
|
* that id. A backend checks that its binding still stands without reading the whole snapshot.
|
|
@@ -67,6 +67,11 @@ export interface IAuthSwitchAccountOverview {
|
|
|
67
67
|
* its pool without one, as long as it takes them.
|
|
68
68
|
*/
|
|
69
69
|
priorityUntil: string | null;
|
|
70
|
+
/**
|
|
71
|
+
* Since when the owner holds the account paused (`IAuthSwitchAccount.pausedAt`, AGL-1933), or null while it is not.
|
|
72
|
+
* A paused account takes no new work until it is resumed; its `placement.eligibility` is `never`.
|
|
73
|
+
*/
|
|
74
|
+
pausedAt: string | null;
|
|
70
75
|
/**
|
|
71
76
|
* How the AGL proxy treats the account for a new session, by the rule of `authority-placement.ts`: its score in
|
|
72
77
|
* percent per hour (null without a counted window) and whether it is a last resort or never placed on.
|
|
@@ -111,6 +116,8 @@ export interface IAuthSwitchLimitRow {
|
|
|
111
116
|
renewal: IAuthSwitchRenewal | null;
|
|
112
117
|
/** When the owner's priority on the account ends while it holds, or null (`IAuthSwitchAccountOverview.priorityUntil`). */
|
|
113
118
|
priorityUntil: string | null;
|
|
119
|
+
/** Since when the owner holds the account paused, or null (`IAuthSwitchAccountOverview.pausedAt`). */
|
|
120
|
+
pausedAt: string | null;
|
|
114
121
|
/** The account's placement score in percent per hour (`IAuthSwitchPlacement.score`), on each of its rows. */
|
|
115
122
|
placementScore: number | null;
|
|
116
123
|
placementEligibility: IAuthSwitchPlacement['eligibility'];
|
|
@@ -187,10 +194,11 @@ export const readAuthSwitchAccountOverview = async (snapshotArg: IAuthSwitchSnap
|
|
|
187
194
|
accountArg.reserveLiftUntil).lifecycle,
|
|
188
195
|
renewal: authSwitchRenewal(accountArg.renewsAt, nowArg),
|
|
189
196
|
priorityUntil: authSwitchPriorityUntil(accountArg.priorityUntil, nowArg),
|
|
197
|
+
pausedAt: accountArg.pausedAt,
|
|
190
198
|
};
|
|
191
199
|
const placement = (readingArg: IAuthSwitchUsageSnapshot['reading']): IAuthSwitchPlacement =>
|
|
192
200
|
authSwitchPlacement(readingArg, accountArg.maxUsagePercent, accountArg.lapsesAt, accountArg.renewsAt, nowArg,
|
|
193
|
-
accountArg.reserveLiftUntil);
|
|
201
|
+
accountArg.reserveLiftUntil, accountArg.pausedAt);
|
|
194
202
|
if (login === null) {
|
|
195
203
|
return { ...base, usage: null, windows: [], problem: 'The account has no login to read its usage with.',
|
|
196
204
|
subscription: [], paymentProblem: null, limit: null, placement: placement(null) };
|
|
@@ -242,8 +250,8 @@ export const authSwitchLimitList = (overviewArg: IAuthSwitchAccountOverviewList)
|
|
|
242
250
|
plan: accountArg.plan, usageState: accountArg.usage?.state ?? null, problem: accountArg.problem,
|
|
243
251
|
maxUsagePercent: accountArg.maxUsagePercent, accountState: accountArg.limit?.state ?? null,
|
|
244
252
|
lapsesAt: accountArg.lapsesAt, lifecycle: accountArg.lifecycle, renewal: accountArg.renewal,
|
|
245
|
-
priorityUntil: accountArg.priorityUntil,
|
|
246
|
-
placementEligibility: accountArg.placement.eligibility };
|
|
253
|
+
priorityUntil: accountArg.priorityUntil, pausedAt: accountArg.pausedAt,
|
|
254
|
+
placementScore: accountArg.placement.score, placementEligibility: accountArg.placement.eligibility };
|
|
247
255
|
if (accountArg.windows.length === 0) {
|
|
248
256
|
return [{ ...base, limit: null, windowSeconds: null, usedPercent: null, estimatedUsedPercent: null, resetAt: null,
|
|
249
257
|
crossing: false }];
|
|
@@ -322,15 +330,18 @@ const limitLines = (maxUsagePercentArg: number | null, limitArg: IAuthSwitchUsag
|
|
|
322
330
|
* lapsed. The priority's end is in local time: `priority until 14:05 (set by the owner)`, with its date on another day.
|
|
323
331
|
*/
|
|
324
332
|
const placementLines = (accountArg: Pick<IAuthSwitchLimitRow, 'lifecycle' | 'lapsesAt' | 'renewal' | 'priorityUntil'
|
|
325
|
-
| 'placementScore' | 'placementEligibility'>, nowArg: number): string[] => [
|
|
333
|
+
| 'pausedAt' | 'placementScore' | 'placementEligibility'>, nowArg: number): string[] => [
|
|
326
334
|
...accountArg.lifecycle === 'lapsed' ? ['lapsed · never placed on']
|
|
327
335
|
: accountArg.lifecycle === 'canceled' && accountArg.lapsesAt !== null
|
|
328
336
|
? [`canceled · lapses in ${compactUntil(accountArg.lapsesAt, nowArg)}`] : [],
|
|
337
|
+
// Paused by its owner (AGL-1933): it takes no new session until it is resumed, so it has no placement line.
|
|
338
|
+
...accountArg.lifecycle === 'lapsed' || accountArg.pausedAt === null ? []
|
|
339
|
+
: ['paused · never placed on'],
|
|
329
340
|
...accountArg.lifecycle === 'lapsed' || accountArg.priorityUntil === null ? []
|
|
330
341
|
: [`priority until ${asOfTime(accountArg.priorityUntil, nowArg)} (set by the owner)`],
|
|
331
342
|
...accountArg.lifecycle === 'lapsed' || accountArg.renewal === null ? []
|
|
332
343
|
: [renewalLine(accountArg.renewal, accountArg.lifecycle, nowArg)],
|
|
333
|
-
...accountArg.lifecycle === 'lapsed' ? []
|
|
344
|
+
...accountArg.lifecycle === 'lapsed' || accountArg.pausedAt !== null ? []
|
|
334
345
|
: [`placement ${placementScoreText(accountArg.placementScore)}${accountArg.placementEligibility === 'last_resort'
|
|
335
346
|
? ' · last resort' : ''}`],
|
|
336
347
|
];
|
|
@@ -357,7 +368,7 @@ const accountCell = (accountArg: IAuthSwitchAccountOverview, nowArg: number): st
|
|
|
357
368
|
...accountArg.paymentProblem === null ? [] : [`payment problem since ${asOfTime(accountArg.paymentProblem.at, nowArg)}`],
|
|
358
369
|
...limitLines(accountArg.maxUsagePercent, accountArg.limit, nowArg),
|
|
359
370
|
...placementLines({ lifecycle: accountArg.lifecycle, lapsesAt: accountArg.lapsesAt, renewal: accountArg.renewal,
|
|
360
|
-
priorityUntil: accountArg.priorityUntil, placementScore: accountArg.placement.score,
|
|
371
|
+
priorityUntil: accountArg.priorityUntil, pausedAt: accountArg.pausedAt, placementScore: accountArg.placement.score,
|
|
361
372
|
placementEligibility: accountArg.placement.eligibility }, nowArg),
|
|
362
373
|
...accountArg.loginHealth === null ? ['no login']
|
|
363
374
|
: accountArg.loginHealth === 'ready' ? []
|
|
@@ -22,7 +22,8 @@ export type TAuthSwitchAccountLifecycle = 'active' | 'canceled' | 'lapsed';
|
|
|
22
22
|
|
|
23
23
|
/**
|
|
24
24
|
* How placement treats an account for a new session. `normal`: by its score. `last_resort`: it lapses within
|
|
25
|
-
* `lapseHorizonMs`, so it takes a new session only while no `normal` account can. `never`: it lapsed
|
|
25
|
+
* `lapseHorizonMs`, so it takes a new session only while no `normal` account can. `never`: it lapsed, or its owner
|
|
26
|
+
* holds it paused (`IAuthSwitchAccount.pausedAt`, AGL-1933).
|
|
26
27
|
*/
|
|
27
28
|
export type TAuthSwitchPlacementEligibility = 'normal' | 'last_resort' | 'never';
|
|
28
29
|
|
|
@@ -64,15 +65,18 @@ export const authSwitchAccountLifecycle = (lapsesAtArg: string | null, nowArg: n
|
|
|
64
65
|
* An API key's spend reading whose month ended (`authSwitchSpendMonthEnded`, as `authSwitchUsageLimit` judges it) says
|
|
65
66
|
* nothing about the current month, which starts with nothing spent: its window counts as 0% used, with the end of the
|
|
66
67
|
* current month (`authSwitchSpendPeriod`) as its reset.
|
|
68
|
+
*
|
|
69
|
+
* `pausedAtArg` is `IAuthSwitchAccount.pausedAt`: an account its owner holds paused is `never` eligible.
|
|
67
70
|
*/
|
|
68
71
|
export const authSwitchPlacement = (readingArg: TAuthSwitchUsageReading | null, maxUsagePercentArg: number | null,
|
|
69
72
|
lapsesAtArg: string | null, renewalAnchorArg: string | null, nowArg: number,
|
|
70
|
-
reserveLiftUntilArg: string | null = null): IAuthSwitchPlacement => {
|
|
73
|
+
reserveLiftUntilArg: string | null = null, pausedAtArg: string | null = null): IAuthSwitchPlacement => {
|
|
71
74
|
const lifecycle = authSwitchAccountLifecycle(lapsesAtArg, nowArg);
|
|
72
75
|
const lapsesAt = lapsesAtArg === null ? Infinity : Date.parse(lapsesAtArg);
|
|
73
76
|
const renewsAt = lapsesAtArg !== null || renewalAnchorArg === null ? Infinity
|
|
74
77
|
: authSwitchNextRenewal(renewalAnchorArg, nowArg);
|
|
75
|
-
|
|
78
|
+
// A paused account is never placed on, whatever its lifecycle and usage; its score stays what its reading says.
|
|
79
|
+
const eligibility: TAuthSwitchPlacementEligibility = lifecycle === 'lapsed' || pausedAtArg !== null ? 'never'
|
|
76
80
|
: lapsesAt - nowArg <= lapseHorizonMs ? 'last_resort' : 'normal';
|
|
77
81
|
const threshold = authSwitchEffectiveMaxUsage(maxUsagePercentArg, reserveLiftUntilArg, nowArg) ?? 100;
|
|
78
82
|
const windows = readingArg === null ? [] : authSwitchCountedWindows(readingArg, maxUsagePercentArg);
|
|
@@ -159,6 +159,7 @@ const publicAccount = (account: IStoredAuthorityAccount): IAuthSwitchAccount =>
|
|
|
159
159
|
id: account.id, providerId: account.providerId, label: account.label, email: account.email,
|
|
160
160
|
plan: account.plan, organizationId: account.workspaceId, maxUsagePercent: account.maxUsagePercent, reserveLiftUntil: account.reserveLiftUntil,
|
|
161
161
|
lapsesAt: account.lapsesAt, renewsAt: account.renewsAt ?? null, priorityUntil: account.priorityUntil ?? null,
|
|
162
|
+
pausedAt: account.pausedAt ?? null,
|
|
162
163
|
spendLimitMicroUsd: account.spendLimitMicroUsd,
|
|
163
164
|
keyHint: account.keyHint, claudeCode: account.claudeCode,
|
|
164
165
|
removed: account.removed, revision: account.revision, statusObservedAt: account.statusObservedAt,
|
|
@@ -990,6 +991,8 @@ export class AuthSwitchAuthorityBroker {
|
|
|
990
991
|
const updateId = plugins.crypto.randomUUID();
|
|
991
992
|
const updated = await this.database.changeAccount(updateId, accountId, account => {
|
|
992
993
|
if (!account || account.removed || account.revision !== expectedRevision) throw new AuthSwitchRefusal('account_changed', 'Account changed; refresh before editing.');
|
|
994
|
+
// A paused account takes no new work, so a priority on it would place nothing (AGL-1933).
|
|
995
|
+
if (priority && account.pausedAt !== undefined) throw new AuthSwitchRefusal('invalid_input', 'The account is paused; resume it before giving it priority.');
|
|
993
996
|
const now = this.now();
|
|
994
997
|
const { priorityUntil: _previous, ...rest } = account;
|
|
995
998
|
return { ...rest, ...(priority ? { priorityUntil: new Date(now + authSwitchPriorityMs).toISOString() } : {}),
|
|
@@ -999,6 +1002,27 @@ export class AuthSwitchAuthorityBroker {
|
|
|
999
1002
|
return publicAccount(updated.account);
|
|
1000
1003
|
}
|
|
1001
1004
|
|
|
1005
|
+
/**
|
|
1006
|
+
* Pauses an account, by the authority's clock, or resumes it, as `setAccountPriority` sets a priority (AGL-1933). A
|
|
1007
|
+
* paused account keeps the moment it was paused at when it is paused again. Pausing ends a priority the account
|
|
1008
|
+
* holds. The stored record carries `pausedAt` only while the account is paused: resuming removes the member.
|
|
1009
|
+
*/
|
|
1010
|
+
public async setAccountPause(accountId: string, expectedRevision: number, paused: boolean): Promise<IAuthSwitchAccount> {
|
|
1011
|
+
if (!isId(accountId) || !validRevision(expectedRevision) || typeof paused !== 'boolean') {
|
|
1012
|
+
throw new Error('Invalid account change.');
|
|
1013
|
+
}
|
|
1014
|
+
const updateId = plugins.crypto.randomUUID();
|
|
1015
|
+
const updated = await this.database.changeAccount(updateId, accountId, account => {
|
|
1016
|
+
if (!account || account.removed || account.revision !== expectedRevision) throw new AuthSwitchRefusal('account_changed', 'Account changed; refresh before editing.');
|
|
1017
|
+
const now = new Date(this.now()).toISOString();
|
|
1018
|
+
const { pausedAt: previous, priorityUntil, ...rest } = account;
|
|
1019
|
+
return { ...rest, ...(paused ? { pausedAt: previous ?? now } : priorityUntil === undefined ? {} : { priorityUntil }),
|
|
1020
|
+
revision: account.revision + 1, updateId, statusObservedAt: now };
|
|
1021
|
+
});
|
|
1022
|
+
this.publish();
|
|
1023
|
+
return publicAccount(updated.account);
|
|
1024
|
+
}
|
|
1025
|
+
|
|
1002
1026
|
/** Refuses a removal that would not go ahead, changing nothing; `removeAccount` refuses the same. */
|
|
1003
1027
|
public async assertAccountRemovable(accountId: string, expectedRevision: number): Promise<void> {
|
|
1004
1028
|
if (!isId(accountId) || !validRevision(expectedRevision)) throw new Error('Invalid account change.');
|
|
@@ -63,6 +63,7 @@ export interface IAuthSwitchAuthorityCliClient {
|
|
|
63
63
|
setAccountLapse(accountId: string, expectedRevision: number, lapsesAt: string | null): Promise<IAuthSwitchAccount>;
|
|
64
64
|
setAccountRenewal(accountId: string, expectedRevision: number, renewsAt: string | null): Promise<IAuthSwitchAccount>;
|
|
65
65
|
setAccountPriority(accountId: string, expectedRevision: number, priority: boolean): Promise<IAuthSwitchAccount>;
|
|
66
|
+
setAccountPause(accountId: string, expectedRevision: number, paused: boolean): Promise<IAuthSwitchAccount>;
|
|
66
67
|
setAccountSpendLimit(accountId: string, expectedRevision: number,
|
|
67
68
|
spendLimitMicroUsd: number | null): Promise<IAuthSwitchAccount>;
|
|
68
69
|
setAccountClaudeCode(accountId: string, expectedRevision: number, claudeCode: boolean): Promise<IAuthSwitchAccount>;
|
|
@@ -108,6 +109,7 @@ type TAuthorityCliCommand =
|
|
|
108
109
|
| { kind: 'setLapse'; accountId: string; lapsesAt: string | null; json: boolean }
|
|
109
110
|
| { kind: 'setRenewal'; accountId: string; renewsAt: string | null; json: boolean }
|
|
110
111
|
| { kind: 'setPriority'; accountId: string; priority: boolean; json: boolean }
|
|
112
|
+
| { kind: 'setPause'; accountId: string; paused: boolean; json: boolean }
|
|
111
113
|
| { kind: 'setSpendLimit'; accountId: string; spendLimitMicroUsd: number | null; json: boolean }
|
|
112
114
|
| { kind: 'setClaudeCode'; accountId: string; claudeCode: boolean; json: boolean }
|
|
113
115
|
| { kind: 'get'; operationId: string; json: boolean }
|
|
@@ -126,7 +128,7 @@ class AuthorityCliFailure extends Error {
|
|
|
126
128
|
}
|
|
127
129
|
}
|
|
128
130
|
|
|
129
|
-
const usage = 'Usage: authswitch --help | authswitch --version [--json] | authswitch list [--json] | authswitch limits [--json] | authswitch account list [--json] | authswitch account add openai|claude [--json] | authswitch account add anthropic-api-key|openai-api-key [--label <label>] [--spend-limit <dollars>] [--json] | authswitch account use codex <account-id> [--json] | authswitch account release codex <account-id> [--end-running-turns] [--json] | authswitch account release claude <account-id> [--end-native-sessions] [--json] | authswitch account repair claude [--json] | authswitch account reauth <account-id> <login-id> [--json] | authswitch account recheck <account-id> [--json] | authswitch account remove <account-id> [--revoke] [--json] | authswitch account set <account-id> --max-usage <percent>|--clear|--lapses-at <date-time>|--clear-lapse|--renews-at <date-time>|--clear-renewal|--priority|--clear-priority|--spend-limit <dollars>|--clear-spend-limit [--json] | authswitch account operation get|cancel|resume <operation-id> [--json] | authswitch account preuse <account-id> <login-id>|--all [--prompt <text>] [--model <id>] [--json] | authswitch account preuse operation get|cancel|resume <operation-id> [--json] | authswitch authority doctor [--json] | authswitch authority import inventory [--json] | authswitch authority import status [--json] | authswitch authority import submit <source-id> --digest <source-digest> [--json] | authswitch authority service install|status|enable|start|stop | authswitch authority daemon';
|
|
131
|
+
const usage = 'Usage: authswitch --help | authswitch --version [--json] | authswitch list [--json] | authswitch limits [--json] | authswitch account list [--json] | authswitch account add openai|claude [--json] | authswitch account add anthropic-api-key|openai-api-key [--label <label>] [--spend-limit <dollars>] [--json] | authswitch account use codex <account-id> [--json] | authswitch account release codex <account-id> [--end-running-turns] [--json] | authswitch account release claude <account-id> [--end-native-sessions] [--json] | authswitch account repair claude [--json] | authswitch account reauth <account-id> <login-id> [--json] | authswitch account recheck <account-id> [--json] | authswitch account remove <account-id> [--revoke] [--json] | authswitch account set <account-id> --max-usage <percent>|--clear|--lapses-at <date-time>|--clear-lapse|--renews-at <date-time>|--clear-renewal|--priority|--clear-priority|--pause|--resume|--spend-limit <dollars>|--clear-spend-limit [--json] | authswitch account operation get|cancel|resume <operation-id> [--json] | authswitch account preuse <account-id> <login-id>|--all [--prompt <text>] [--model <id>] [--json] | authswitch account preuse operation get|cancel|resume <operation-id> [--json] | authswitch authority doctor [--json] | authswitch authority import inventory [--json] | authswitch authority import status [--json] | authswitch authority import submit <source-id> --digest <source-digest> [--json] | authswitch authority service install|status|enable|start|stop | authswitch authority daemon';
|
|
130
132
|
|
|
131
133
|
/** Every command, one per line, with what it does; `authswitch --help` prints it. */
|
|
132
134
|
const help = (): string => `authswitch ${authSwitchRelease.version}
|
|
@@ -190,6 +192,11 @@ Usage
|
|
|
190
192
|
takes them (several accounts can have it, and sessions
|
|
191
193
|
running elsewhere stay); again restarts the 24 hours;
|
|
192
194
|
--clear-priority ends it
|
|
195
|
+
authswitch account set <account-id> --pause|--resume [--json]
|
|
196
|
+
a paused account takes no new work until --resume: the AGL
|
|
197
|
+
proxy leaves it out of every pool and moves the sessions on
|
|
198
|
+
it; its sign-in, usage readings and limits stay, and a
|
|
199
|
+
priority on it ends
|
|
193
200
|
authswitch account set <account-id> --spend-limit <dollars>|--clear-spend-limit [--json]
|
|
194
201
|
an API key's monthly spend limit (calendar month, UTC) on
|
|
195
202
|
what AGL's proxy relayed on it: at the limit the proxy places
|
|
@@ -203,7 +210,8 @@ Usage
|
|
|
203
210
|
follow a sign-in that is still running
|
|
204
211
|
authswitch account preuse <account-id> <login-id>|--all [--prompt <text>] [--model <id>] [--json]
|
|
205
212
|
send one prompt through a ChatGPT login without switching;
|
|
206
|
-
--all does it for every ChatGPT login, one at a time
|
|
213
|
+
--all does it for every ChatGPT login, one at a time,
|
|
214
|
+
and skips a paused account by name
|
|
207
215
|
authswitch account preuse operation get|cancel|resume <operation-id> [--json]
|
|
208
216
|
follow a preuse that is still running
|
|
209
217
|
authswitch authority doctor [--json] the service's stored diagnostics
|
|
@@ -411,6 +419,9 @@ const parse = (argv: readonly string[]): TAuthorityCliCommand | null => {
|
|
|
411
419
|
if (options.length === 1 && (options[0] === '--priority' || options[0] === '--clear-priority')) {
|
|
412
420
|
return { kind: 'setPriority', accountId: argv[2], priority: options[0] === '--priority', json };
|
|
413
421
|
}
|
|
422
|
+
if (options.length === 1 && (options[0] === '--pause' || options[0] === '--resume')) {
|
|
423
|
+
return { kind: 'setPause', accountId: argv[2], paused: options[0] === '--pause', json };
|
|
424
|
+
}
|
|
414
425
|
if (options.length === 1 && options[0] === '--clear-spend-limit') {
|
|
415
426
|
return { kind: 'setSpendLimit', accountId: argv[2], spendLimitMicroUsd: null, json };
|
|
416
427
|
}
|
|
@@ -553,6 +564,10 @@ class ScopedAuthorityCliClient implements IAuthSwitchAuthorityCliClient {
|
|
|
553
564
|
return this.client.setAccountPriority(accountId, expectedRevision, priority, this.controller.signal);
|
|
554
565
|
}
|
|
555
566
|
|
|
567
|
+
public setAccountPause(accountId: string, expectedRevision: number, paused: boolean): Promise<IAuthSwitchAccount> {
|
|
568
|
+
return this.client.setAccountPause(accountId, expectedRevision, paused, this.controller.signal);
|
|
569
|
+
}
|
|
570
|
+
|
|
556
571
|
public addApiKey(providerId: TAuthSwitchApiKeyProvider, apiKey: string,
|
|
557
572
|
options: { label?: string; spendLimitMicroUsd?: number }): Promise<IReq_AuthSwitchAddApiKey['response']> {
|
|
558
573
|
return this.client.addApiKey(providerId, apiKey, options, this.controller.signal);
|
|
@@ -686,6 +701,15 @@ const renderPriority = (account: IAuthSwitchAccount, nowArg: number): string =>
|
|
|
686
701
|
: `${priorityText(account, nowArg)}; the AGL proxy places new sessions on it before any other account of its pool `
|
|
687
702
|
+ `as long as it takes them, for ${authSwitchPriorityMs / 3_600_000} hours or until --clear-priority.\n`);
|
|
688
703
|
|
|
704
|
+
/** An account's pause in words, as `account set --pause` and `account list` state it; empty while it is not paused. */
|
|
705
|
+
const pauseText = (account: IAuthSwitchAccount): string =>
|
|
706
|
+
account.pausedAt === null ? '' : `paused since ${safe(account.pausedAt)} (by the owner)`;
|
|
707
|
+
|
|
708
|
+
const renderPause = (account: IAuthSwitchAccount): string =>
|
|
709
|
+
`Account ${safe(account.email ?? account.label)} (${safe(account.id)}): `
|
|
710
|
+
+ (account.pausedAt === null ? 'not paused; it takes new work again.\n'
|
|
711
|
+
: `${pauseText(account)}; it takes no new work, and the AGL proxy moves the sessions on it, until --resume.\n`);
|
|
712
|
+
|
|
689
713
|
/** A re-check as `account recheck` states it: how the read went, and whether the account is still held. */
|
|
690
714
|
const renderRecheck = (account: IAuthSwitchAccount, recheck: IAuthSwitchUsageRecheck): string =>
|
|
691
715
|
`Account ${safe(account.email ?? account.label)} (${safe(account.id)}): ${authSwitchRecheckOutcomeText(recheck.outcome)}\n`
|
|
@@ -743,6 +767,7 @@ const renderList = (snapshot: IAuthSwitchSnapshot, nowArg: number): string => {
|
|
|
743
767
|
: `${account.maxUsagePercent}%`}; ${lapseText(account, nowArg)}; `
|
|
744
768
|
+ `${account.renewsAt === null ? '' : `${renewalText(account, nowArg)}; `}`
|
|
745
769
|
+ `${priorityText(account, nowArg) === '' ? '' : `${priorityText(account, nowArg)}; `}`
|
|
770
|
+
+ `${pauseText(account) === '' ? '' : `${pauseText(account)}; `}`
|
|
746
771
|
+ `${account.removed ? 'removed' : 'registered'}; `
|
|
747
772
|
+ `stored ${safe(account.statusObservedAt)}`);
|
|
748
773
|
const logins = snapshot.logins.filter(login => login.accountId === account.id);
|
|
@@ -1072,7 +1097,8 @@ interface IPreuseBatchSkip {
|
|
|
1072
1097
|
statusObservedAt: string;
|
|
1073
1098
|
health: IAuthSwitchSnapshot['logins'][number]['health'];
|
|
1074
1099
|
problem: IAuthSwitchSnapshot['logins'][number]['problem'];
|
|
1075
|
-
|
|
1100
|
+
/** `account_paused`: the account's owner holds it paused (AGL-1933), so `--all` starts nothing on it. */
|
|
1101
|
+
reason: 'snapshot_not_preuse_capable' | 'account_paused';
|
|
1076
1102
|
}
|
|
1077
1103
|
|
|
1078
1104
|
const renderPreuseSkip = (skip: IPreuseBatchSkip, json: boolean): string => {
|
|
@@ -1295,7 +1321,11 @@ const abortable = <T>(operation: Promise<T>, signal: AbortSignal): Promise<T> =>
|
|
|
1295
1321
|
});
|
|
1296
1322
|
};
|
|
1297
1323
|
|
|
1298
|
-
/**
|
|
1324
|
+
/**
|
|
1325
|
+
* The logins `preuse --all` goes through: every ChatGPT login the service renews, of an account that has not lapsed. A
|
|
1326
|
+
* login of a paused account is among them, and the batch skips it by name (`account_paused`): `--all` starts no usage
|
|
1327
|
+
* window on an account its owner holds back, while `account preuse <account-id> <login-id>` still does, as asked.
|
|
1328
|
+
*/
|
|
1299
1329
|
const preuseBatchTargets = (snapshot: IAuthSwitchSnapshot, nowArg: number): IAuthSwitchSnapshot['logins'] => {
|
|
1300
1330
|
const accountIds = new Set(snapshot.accounts
|
|
1301
1331
|
.filter(account => account.providerId === 'openai' && !account.removed
|
|
@@ -1590,6 +1620,19 @@ export const runAuthSwitchAuthorityCli = async (argv: readonly string[],
|
|
|
1590
1620
|
await writeOutput(command.json ? JSON.stringify({ account: changed }) + '\n' : renderPriority(changed, now()));
|
|
1591
1621
|
return 0;
|
|
1592
1622
|
}
|
|
1623
|
+
if (command.kind === 'setPause') {
|
|
1624
|
+
const account = (await activeClient.snapshotAll()).accounts.find(item => item.id === command.accountId && !item.removed);
|
|
1625
|
+
if (!account) {
|
|
1626
|
+
await writeDiagnostic('No authority account has this id. Run `authswitch account list` for the ids.\n');
|
|
1627
|
+
return 1;
|
|
1628
|
+
}
|
|
1629
|
+
const changed = await activeClient.setAccountPause(account.id, account.revision, command.paused);
|
|
1630
|
+
if (changed.id !== account.id || (changed.pausedAt === null) === command.paused) {
|
|
1631
|
+
throw new AuthorityCliFailure('response');
|
|
1632
|
+
}
|
|
1633
|
+
await writeOutput(command.json ? JSON.stringify({ account: changed }) + '\n' : renderPause(changed));
|
|
1634
|
+
return 0;
|
|
1635
|
+
}
|
|
1593
1636
|
if (command.kind === 'setSpendLimit') {
|
|
1594
1637
|
const account = (await activeClient.snapshotAll()).accounts.find(item => item.id === command.accountId && !item.removed);
|
|
1595
1638
|
if (!account) {
|
|
@@ -1803,6 +1846,17 @@ export const runAuthSwitchAuthorityCli = async (argv: readonly string[],
|
|
|
1803
1846
|
for (const login of preuseBatchTargets(snapshot, now())) {
|
|
1804
1847
|
if (operationController.signal.aborted) throw operationController.signal.reason;
|
|
1805
1848
|
deadlineAt = now() + operationDeadlineMs;
|
|
1849
|
+
if (snapshot.accounts.some(account => account.id === login.accountId && account.pausedAt !== null)) {
|
|
1850
|
+
operationIdForHint = null;
|
|
1851
|
+
const skip: IPreuseBatchSkip = {
|
|
1852
|
+
type: 'skipped', snapshotRevision: snapshot.revision,
|
|
1853
|
+
accountId: login.accountId, loginId: login.id, loginRevision: login.revision,
|
|
1854
|
+
statusObservedAt: login.statusObservedAt, health: login.health, problem: login.problem,
|
|
1855
|
+
reason: 'account_paused',
|
|
1856
|
+
};
|
|
1857
|
+
await writeOutput(renderPreuseSkip(skip, command.json));
|
|
1858
|
+
continue;
|
|
1859
|
+
}
|
|
1806
1860
|
if (!login.capabilities.canPreuse) {
|
|
1807
1861
|
operationIdForHint = null;
|
|
1808
1862
|
const skip: IPreuseBatchSkip = {
|
|
@@ -7,7 +7,7 @@ import type {
|
|
|
7
7
|
IReq_AuthSwitchClaudeHostLogin, IReq_AuthSwitchEvents, IReq_AuthSwitchReleaseClaudeNative,
|
|
8
8
|
IReq_AuthSwitchClaudeNativeReleaseOperation, IReq_AuthSwitchRepairClaudeHost,
|
|
9
9
|
IReq_AuthSwitchGetBinding, IReq_AuthSwitchGetOperation, IReq_AuthSwitchListOperations,
|
|
10
|
-
IReq_AuthSwitchRemoveAccount, IReq_AuthSwitchRenameAccount, IReq_AuthSwitchSetAccountLapse, IReq_AuthSwitchSetAccountRenewal, IReq_AuthSwitchSetAccountPriority, IReq_AuthSwitchSetAccountMaxUsage, IReq_AuthSwitchLiftAccountReserve,
|
|
10
|
+
IReq_AuthSwitchRemoveAccount, IReq_AuthSwitchRenameAccount, IReq_AuthSwitchSetAccountLapse, IReq_AuthSwitchSetAccountRenewal, IReq_AuthSwitchSetAccountPriority, IReq_AuthSwitchSetAccountPause, IReq_AuthSwitchSetAccountMaxUsage, IReq_AuthSwitchLiftAccountReserve,
|
|
11
11
|
IReq_AuthSwitchCancelPreuse, IReq_AuthSwitchGetPreuse, IReq_AuthSwitchSnapshot,
|
|
12
12
|
IReq_AuthSwitchStartPreuse, IReq_AuthSwitchUsage, IReq_AuthSwitchObserveUsage, IReq_AuthSwitchReportPaymentProblem,
|
|
13
13
|
IReq_AuthSwitchRecordSpend, IAuthSwitchSpendAnswer, TAuthSwitchPaymentProblemCause, TAuthSwitchApiKeyProvider,
|
|
@@ -122,8 +122,8 @@ export class AuthSwitchDaemonOutdatedError extends Error {
|
|
|
122
122
|
* A snapshot page carries every member of this release's contract. `schemaVersion` is not bumped for an
|
|
123
123
|
* additive member; version 3 adds the gateway runtime, every account states its `maxUsagePercent` from 38.3.0
|
|
124
124
|
* on, its `lapsesAt` from 38.4.0 on, its `reserveLiftUntil` with reserve lifts, its `spendLimitMicroUsd` and
|
|
125
|
-
* `keyHint` with API keys of both providers, its `claudeCode` from AGL-1146 on, its `renewsAt` from AGL-1644 on,
|
|
126
|
-
* `priorityUntil` from AGL-1809 on. Consumers still check their supported version.
|
|
125
|
+
* `keyHint` with API keys of both providers, its `claudeCode` from AGL-1146 on, its `renewsAt` from AGL-1644 on, its
|
|
126
|
+
* `priorityUntil` from AGL-1809 on, and its `pausedAt` from AGL-1933 on. Consumers still check their supported version.
|
|
127
127
|
*/
|
|
128
128
|
const assertCurrentSnapshot = (snapshot: IAuthSwitchSnapshot): IAuthSwitchSnapshot => {
|
|
129
129
|
const page: Partial<IAuthSwitchSnapshot> = snapshot;
|
|
@@ -136,7 +136,8 @@ const assertCurrentSnapshot = (snapshot: IAuthSwitchSnapshot): IAuthSwitchSnapsh
|
|
|
136
136
|
|| (account as Partial<IAuthSwitchAccount>).keyHint === undefined
|
|
137
137
|
|| (account as Partial<IAuthSwitchAccount>).claudeCode === undefined
|
|
138
138
|
|| (account as Partial<IAuthSwitchAccount>).renewsAt === undefined
|
|
139
|
-
|| (account as Partial<IAuthSwitchAccount>).priorityUntil === undefined
|
|
139
|
+
|| (account as Partial<IAuthSwitchAccount>).priorityUntil === undefined
|
|
140
|
+
|| (account as Partial<IAuthSwitchAccount>).pausedAt === undefined)) {
|
|
140
141
|
throw new AuthSwitchDaemonOutdatedError();
|
|
141
142
|
}
|
|
142
143
|
return snapshot;
|
|
@@ -573,6 +574,12 @@ export class AuthSwitchClient {
|
|
|
573
574
|
return (await this.request<IReq_AuthSwitchSetAccountPriority>('authswitch.authority.priority',
|
|
574
575
|
{ accountId, expectedRevision, priority }, 35_000, false, signal)).account;
|
|
575
576
|
}
|
|
577
|
+
/** Pauses an account, or resumes it with `false` (see `IReq_AuthSwitchSetAccountPause`). */
|
|
578
|
+
public async setAccountPause(accountId: string, expectedRevision: number, paused: boolean,
|
|
579
|
+
signal?: AbortSignal): Promise<IReq_AuthSwitchSetAccountPause['response']['account']> {
|
|
580
|
+
return (await this.request<IReq_AuthSwitchSetAccountPause>('authswitch.authority.pause',
|
|
581
|
+
{ accountId, expectedRevision, paused }, 35_000, false, signal)).account;
|
|
582
|
+
}
|
|
576
583
|
/**
|
|
577
584
|
* Removes an account; `revoke: true` also revokes its ChatGPT sign-in at OpenAI (see
|
|
578
585
|
* `IReq_AuthSwitchRemoveAccount`). An older daemon refuses `revoke` as an invalid request before it changes
|
|
@@ -8,7 +8,7 @@ import type {
|
|
|
8
8
|
IReq_AuthSwitchRepairClaudeHost,
|
|
9
9
|
IReq_AuthSwitchEvents, IReq_AuthSwitchGetBinding, IReq_AuthSwitchGetOperation, IReq_AuthSwitchListOperations,
|
|
10
10
|
IReq_AuthSwitchRemoveAccount,
|
|
11
|
-
IReq_AuthSwitchRenameAccount, IReq_AuthSwitchSetAccountLapse, IReq_AuthSwitchSetAccountRenewal, IReq_AuthSwitchSetAccountPriority, IReq_AuthSwitchSetAccountMaxUsage, IReq_AuthSwitchSetAccountSpendLimit, IReq_AuthSwitchSetAccountClaudeCode, IReq_AuthSwitchLiftAccountReserve, IReq_AuthSwitchSnapshot,
|
|
11
|
+
IReq_AuthSwitchRenameAccount, IReq_AuthSwitchSetAccountLapse, IReq_AuthSwitchSetAccountRenewal, IReq_AuthSwitchSetAccountPriority, IReq_AuthSwitchSetAccountPause, IReq_AuthSwitchSetAccountMaxUsage, IReq_AuthSwitchSetAccountSpendLimit, IReq_AuthSwitchSetAccountClaudeCode, IReq_AuthSwitchLiftAccountReserve, IReq_AuthSwitchSnapshot,
|
|
12
12
|
IReq_AuthSwitchCancelPreuse, IReq_AuthSwitchGetPreuse, IReq_AuthSwitchStartPreuse, IReq_AuthSwitchUsage,
|
|
13
13
|
IReq_AuthSwitchObserveUsage, IReq_AuthSwitchReportPaymentProblem, IReq_AuthSwitchRecheckUsage, IReq_AuthSwitchRecordSpend,
|
|
14
14
|
IReq_AuthSwitchMoveClaudeHomeIn, IReq_AuthSwitchMoveClaudeHomeOut, IReq_AuthSwitchRegisterClaudeHome,
|
|
@@ -769,6 +769,13 @@ export class AuthSwitchAuthorityDaemon {
|
|
|
769
769
|
return { account: await this.broker.setAccountPriority(request.accountId, request.expectedRevision,
|
|
770
770
|
request.priority) };
|
|
771
771
|
}));
|
|
772
|
+
this.managementRouter.addTypedHandler(this.handler<IReq_AuthSwitchSetAccountPause>(
|
|
773
|
+
'authswitch.authority.pause', async request => {
|
|
774
|
+
if (!hasKeys(request, ['accountId', 'expectedRevision', 'paused']) || typeof request.accountId !== 'string'
|
|
775
|
+
|| typeof request.expectedRevision !== 'number' || typeof request.paused !== 'boolean') invalid();
|
|
776
|
+
return { account: await this.broker.setAccountPause(request.accountId, request.expectedRevision,
|
|
777
|
+
request.paused) };
|
|
778
|
+
}));
|
|
772
779
|
this.managementRouter.addTypedHandler(this.handler<IReq_AuthSwitchGetBinding>(
|
|
773
780
|
'authswitch.authority.binding', async request => {
|
|
774
781
|
if (!hasKeys(request, ['bindingId']) || !validBindingId(request.bindingId)) invalid();
|
|
@@ -1579,6 +1579,8 @@ export class AuthSwitchAuthorityDatabase {
|
|
|
1579
1579
|
draft: IStoredAuthorityAccount): Promise<void> {
|
|
1580
1580
|
if (draft.priorityUntil !== undefined && (draft.removed
|
|
1581
1581
|
|| !authSwitchPriorityActive(draft.priorityUntil, Date.parse(draft.statusObservedAt)))) delete draft.priorityUntil;
|
|
1582
|
+
// A removed account is not paused: nothing is placed on it anyway, and its record goes back to the plain one.
|
|
1583
|
+
if (draft.pausedAt !== undefined && draft.removed) delete draft.pausedAt;
|
|
1582
1584
|
assertStoredAuthorityAccount(draft);
|
|
1583
1585
|
if (current) {
|
|
1584
1586
|
const prior = AuthSwitchAuthorityAccountModel.exact.toPersisted(current);
|
|
@@ -1591,6 +1593,7 @@ export class AuthSwitchAuthorityDatabase {
|
|
|
1591
1593
|
// Optional: a draft without them drops them, which `Object.assign` alone would keep (AGENTS.md, rollback floor).
|
|
1592
1594
|
model.renewsAt = draft.renewsAt;
|
|
1593
1595
|
model.priorityUntil = draft.priorityUntil;
|
|
1596
|
+
model.pausedAt = draft.pausedAt;
|
|
1594
1597
|
},
|
|
1595
1598
|
}, { session });
|
|
1596
1599
|
if (result.status !== 'transitioned') throw new Error('Account changed concurrently.');
|
|
@@ -43,6 +43,12 @@ export interface IStoredAuthorityAccount {
|
|
|
43
43
|
* account once it ended or the account is removed (`AuthSwitchAuthorityDatabase.persistAccount`).
|
|
44
44
|
*/
|
|
45
45
|
priorityUntil?: string;
|
|
46
|
+
/**
|
|
47
|
+
* Since when the owner holds the account paused, ISO 8601 UTC (`IAuthSwitchAccount.pausedAt`, AGL-1933). Present only
|
|
48
|
+
* while it is paused, as `renewsAt` is: resuming removes the member, and so does a write of a removed account
|
|
49
|
+
* (`AuthSwitchAuthorityDatabase.persistAccount`).
|
|
50
|
+
*/
|
|
51
|
+
pausedAt?: string;
|
|
46
52
|
/** An API key account's monthly spend limit in micro-dollars, or `null` (`IAuthSwitchAccount.spendLimitMicroUsd`). */
|
|
47
53
|
spendLimitMicroUsd: number | null;
|
|
48
54
|
/** How an API key account's key ends, or `null` (`IAuthSwitchAccount.keyHint`). */
|
|
@@ -745,18 +751,19 @@ const storedAccountKeys = ['id', 'providerId', 'issuer', 'subject', 'workspaceId
|
|
|
745
751
|
'removed', 'revision', 'statusObservedAt', 'updateId'] as const;
|
|
746
752
|
|
|
747
753
|
/** The members an account record holds only while they hold a value (AGENTS.md, rollback floor). */
|
|
748
|
-
const optionalAccountKeys = ['renewsAt', 'priorityUntil'] as const;
|
|
754
|
+
const optionalAccountKeys = ['renewsAt', 'priorityUntil', 'pausedAt'] as const;
|
|
749
755
|
|
|
750
756
|
/**
|
|
751
757
|
* An account record holds every member of `storedAccountKeys` and nothing else, besides any of `optionalAccountKeys`:
|
|
752
|
-
* a renewal anchor (`renewsAt`, only on a Claude sign-in)
|
|
753
|
-
* account). Each optional member is checked on its own: a record that holds it holds a valid value, never null.
|
|
758
|
+
* a renewal anchor (`renewsAt`, only on a Claude sign-in), the end of the owner's priority (`priorityUntil`, on any
|
|
759
|
+
* account) and since when the owner holds it paused (`pausedAt`, on any account). Each optional member is checked on its own: a record that holds it holds a valid value, never null.
|
|
754
760
|
*/
|
|
755
761
|
const storedAccountMembers = (value: Record<string, unknown>): boolean =>
|
|
756
762
|
exactKeys(value, [...storedAccountKeys, ...optionalAccountKeys.filter(key => Object.hasOwn(value, key))])
|
|
757
763
|
&& (!Object.hasOwn(value, 'renewsAt') || (iso(value.renewsAt) && isAuthSwitchRenewsAt(value.renewsAt)
|
|
758
764
|
&& value.providerId === 'anthropic' && value.workspaceId !== 'api-key'))
|
|
759
|
-
&& (!Object.hasOwn(value, 'priorityUntil') || iso(value.priorityUntil))
|
|
765
|
+
&& (!Object.hasOwn(value, 'priorityUntil') || iso(value.priorityUntil))
|
|
766
|
+
&& (!Object.hasOwn(value, 'pausedAt') || iso(value.pausedAt));
|
|
760
767
|
|
|
761
768
|
export const assertStoredAuthorityAccount: (value: unknown) => asserts value is IStoredAuthorityAccount = value => {
|
|
762
769
|
if (!object(value) || !storedAccountMembers(value)
|
|
@@ -1332,6 +1339,7 @@ export class AuthSwitchAuthorityAccountModel extends plugins.nosqldb.SmartDataDb
|
|
|
1332
1339
|
@plugins.nosqldb.svDb() public lapsesAt!: string | null;
|
|
1333
1340
|
@plugins.nosqldb.svDb() public renewsAt?: string;
|
|
1334
1341
|
@plugins.nosqldb.svDb() public priorityUntil?: string;
|
|
1342
|
+
@plugins.nosqldb.svDb() public pausedAt?: string;
|
|
1335
1343
|
@plugins.nosqldb.svDb() public spendLimitMicroUsd!: number | null;
|
|
1336
1344
|
@plugins.nosqldb.svDb() public keyHint!: string | null;
|
|
1337
1345
|
@plugins.nosqldb.svDb() public claudeCode!: boolean;
|
|
@@ -217,6 +217,24 @@ export type TFleetWorkerJobAction = Exclude<TFleetWorkerAction, (typeof fleetWor
|
|
|
217
217
|
export type TFleetWorkerListView = 'summary' | 'full';
|
|
218
218
|
/** The longest fleet worker job wait one request asks for. */
|
|
219
219
|
export const fleetWorkerJobWaitMaximumMs = 240_000;
|
|
220
|
+
/**
|
|
221
|
+
* A fleet Claude worker whose MCP calls run without its identity (AGL-1888): its bridge called the controller and passed
|
|
222
|
+
* the checks that identify the worker, but its enrollment was refused for good, or on consecutive calls spanning at
|
|
223
|
+
* least 60 s. Derived in the controller's memory from those calls, never stored: the worker's next verified call or its
|
|
224
|
+
* revocation (a stop, an archive, a re-bind) clears it, and a worker that does not call (an idle one) never shows it.
|
|
225
|
+
* Until then its calls are anonymous, so its ticket writes are refused.
|
|
226
|
+
*/
|
|
227
|
+
export interface IFleetWorkerIdentity {
|
|
228
|
+
unverified: true;
|
|
229
|
+
/**
|
|
230
|
+
* Why its calls are refused: the refusal it first showed for, or a later refusal for good for another reason; a
|
|
231
|
+
* refusal that may pass never replaces it. One of the controller's fixed phrases (`workerUnverifiedReasons`), never
|
|
232
|
+
* error text, a credential, a path, a launch or a process id.
|
|
233
|
+
*/
|
|
234
|
+
reason: string;
|
|
235
|
+
/** When the first of the refused calls since the worker's last verified one came (ISO 8601). */
|
|
236
|
+
since: string;
|
|
237
|
+
}
|
|
220
238
|
/**
|
|
221
239
|
* A worker as a summary list shows it: identity, binding, what the controller observed and which fences it holds,
|
|
222
240
|
* without attribution, proof or error bodies; `fleet_worker_get` returns the whole record.
|
|
@@ -249,6 +267,8 @@ export interface IFleetWorkerSummary {
|
|
|
249
267
|
/** The worker records an error (`error`). */
|
|
250
268
|
error?: true;
|
|
251
269
|
};
|
|
270
|
+
/** Present while the worker's MCP calls run without its identity; see `IFleetWorkerIdentity`. */
|
|
271
|
+
identity?: IFleetWorkerIdentity;
|
|
252
272
|
}
|
|
253
273
|
/**
|
|
254
274
|
* One page of a summary list. `total`, `fenced` (workers with an unresolved dispatch) and `failed` (workers that
|
|
@@ -400,8 +420,13 @@ export interface IFleetWorkerResponses {
|
|
|
400
420
|
'native-message': { job: IFleetWorkerJob };
|
|
401
421
|
}
|
|
402
422
|
export type TFleetWorkerResponse<T extends TFleetWorkerAction> = IFleetWorkerResponses[T];
|
|
423
|
+
/** A public record as a full list shows it: with `identity` while the worker's MCP calls run without it. */
|
|
424
|
+
export interface IFleetListedWorker extends IFleetWorker {
|
|
425
|
+
/** Derived, never stored; see `IFleetWorkerIdentity`. */
|
|
426
|
+
identity?: IFleetWorkerIdentity;
|
|
427
|
+
}
|
|
403
428
|
/** Every matching public record of a full list. */
|
|
404
|
-
export interface IFleetWorkerFullList { workers:
|
|
429
|
+
export interface IFleetWorkerFullList { workers: IFleetListedWorker[] }
|
|
405
430
|
/**
|
|
406
431
|
* What the request `R` of `T` gets back: a list answers a summary page to `view: 'summary'` and the full records to a
|
|
407
432
|
* request without `view` (the private request's default) or with `view: 'full'`.
|
|
@@ -1693,9 +1693,11 @@ export type TControllerSessionIntelligenceRemedy = (typeof controllerSessionInte
|
|
|
1693
1693
|
|
|
1694
1694
|
/**
|
|
1695
1695
|
* `inHostCodex`: this host's Codex runs on the account and renews its login, so Flex cannot use it until this host's
|
|
1696
|
-
* Codex is switched to another account (see `accountInHostCodexReason`).
|
|
1696
|
+
* Codex is switched to another account (see `accountInHostCodexReason`). `paused`: the account's owner holds it
|
|
1697
|
+
* paused in Accounts (AGL-1933), so no new conversation can choose it and a conversation on it sends nothing until it
|
|
1698
|
+
* is resumed; an account that also needs a sign-in, or runs this host's Codex, says that instead.
|
|
1697
1699
|
*/
|
|
1698
|
-
export type TControllerProviderConnectionStatus = 'active' | 'reauthRequired' | 'inHostCodex';
|
|
1700
|
+
export type TControllerProviderConnectionStatus = 'active' | 'reauthRequired' | 'inHostCodex' | 'paused';
|
|
1699
1701
|
export type TControllerModelRefreshJobStatus =
|
|
1700
1702
|
| 'pending'
|
|
1701
1703
|
| 'running'
|
|
@@ -132,7 +132,8 @@ export const controllerMcpSessionDetailFields = {
|
|
|
132
132
|
* harness process it spawns. Every `agl mcp` server that process launches inherits it and presents
|
|
133
133
|
* it on the private endpoint, so the controller authorizes the calling chat instead of trusting a
|
|
134
134
|
* caller-supplied task id. It is never allowlisted for inheritance: only explicit per-spawn writes
|
|
135
|
-
* may set it.
|
|
135
|
+
* may set it. Everything a terminal runs inherits it, daemons that leave the terminal too, so a
|
|
136
|
+
* terminal's is honoured only for a process still running inside that terminal (AGL-1891).
|
|
136
137
|
*/
|
|
137
138
|
export const controllerMcpCallerCredentialEnvironmentVariable = 'AGL_MCP_CALLER_CREDENTIAL';
|
|
138
139
|
/** Optional browser-minted owner capability; when absent, the CLI mints one through same-user controller database access. */
|
|
@@ -42,7 +42,7 @@ export type TProxyCapacityMemberState = 'available' | 'reserved' | 'exhausted' |
|
|
|
42
42
|
export const proxyCapacityMemberStates: readonly TProxyCapacityMemberState[] = ['available', 'reserved', 'exhausted',
|
|
43
43
|
'cooling', 'unavailable'];
|
|
44
44
|
|
|
45
|
-
/** An account the pool counts: a subscription sign-in of a counted plan that has not lapsed. */
|
|
45
|
+
/** An account the pool counts: a subscription sign-in of a counted plan that has not lapsed and is not paused. */
|
|
46
46
|
export interface IProxyCapacityMember {
|
|
47
47
|
/** The account's id (64 hex characters). */
|
|
48
48
|
accountId: string;
|