agl 42.1.0 → 42.2.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 +44 -0
- package/dist_serve/bundle.js +797 -785
- package/dist_serve/bundle.js.map +2 -2
- package/dist_ts/00_commitinfo_data.js +1 -1
- package/dist_ts/aglapi/aglapisurface.document.js +124 -10
- package/dist_ts/classes.accountsactions.d.ts +3 -1
- package/dist_ts/classes.accountsactions.js +16 -1
- package/dist_ts/classes.authstore.js +9 -1
- package/dist_ts/classes.cli.js +19 -49
- package/dist_ts/classes.configurationauthority.js +2 -2
- package/dist_ts/classes.controllerservice.d.ts +20 -2
- package/dist_ts/classes.controllerservice.js +42 -6
- package/dist_ts/classes.flexservice.js +8 -3
- package/dist_ts/classes.inferencegateway.d.ts +30 -2
- package/dist_ts/classes.inferencegateway.js +115 -20
- package/dist_ts/classes.inferencerouter.d.ts +16 -0
- package/dist_ts/classes.inferencerouter.js +5 -3
- package/dist_ts/classes.inferenceservice.js +7 -3
- package/dist_ts/classes.ticketmodels.js +4 -3
- package/dist_ts/classes.ticketnotifier.js +9 -2
- package/dist_ts/classes.ticketstore.js +9 -5
- package/dist_ts/classes.upgradecoordinator.d.ts +6 -1
- package/dist_ts/classes.upgradecoordinator.js +9 -2
- package/dist_ts/classes.upgradetransaction.d.ts +27 -1
- package/dist_ts/classes.upgradetransaction.js +92 -2
- package/dist_ts/configuration/functions.master.d.ts +7 -2
- package/dist_ts/configuration/functions.master.js +7 -4
- package/dist_ts/driver/classes.drivereventrelay.d.ts +1 -1
- package/dist_ts/driver/classes.drivereventrelay.js +3 -3
- package/dist_ts/fleet/classes.boardpump.d.ts +1 -1
- package/dist_ts/fleet/classes.boardpump.js +7 -4
- package/dist_ts/fleet/classes.claudeworkers.d.ts +6 -0
- package/dist_ts/fleet/classes.claudeworkers.js +17 -7
- package/dist_ts/fleet/classes.deploymodels.d.ts +19 -0
- package/dist_ts/fleet/classes.deploymodels.js +140 -0
- package/dist_ts/fleet/functions.validation.d.ts +8 -1
- package/dist_ts/fleet/functions.validation.js +65 -3
- package/dist_ts/fleet/interfaces.workers.d.ts +6 -0
- package/dist_ts/fleet/interfaces.workers.js +65 -2
- package/dist_ts/functions.fleetworkercli.d.ts +16 -3
- package/dist_ts/functions.fleetworkercli.js +21 -7
- package/dist_ts/functions.inferencecli.js +4 -2
- package/dist_ts/functions.mcptickettools.d.ts +1 -0
- package/dist_ts/functions.ticketvalidation.d.ts +36 -3
- package/dist_ts/functions.ticketvalidation.js +45 -14
- package/dist_ts/interfaces.auth.d.ts +1 -1
- package/dist_ts/interfaces.auth.js +2 -1
- package/dist_ts_authswitch/authority-contract.d.ts +23 -0
- package/dist_ts_authswitch/authority-contract.js +1 -1
- package/dist_ts_authswitch/classes.authoritybroker.d.ts +12 -0
- package/dist_ts_authswitch/classes.authoritybroker.js +72 -22
- package/dist_ts_authswitch/classes.authoritycli.d.ts +1 -0
- package/dist_ts_authswitch/classes.authoritycli.js +26 -1
- package/dist_ts_authswitch/classes.authorityclient.d.ts +3 -1
- package/dist_ts_authswitch/classes.authorityclient.js +10 -4
- package/dist_ts_authswitch/classes.authoritydaemon.js +7 -1
- package/dist_ts_authswitch/classes.authorityimport.js +2 -2
- package/dist_ts_authswitch/classes.authoritymodels.d.ts +3 -0
- package/dist_ts_authswitch/classes.authoritymodels.js +10 -3
- package/dist_ts_authswitch/classes.authorityusage.js +5 -3
- package/dist_ts_authswitch/classes.claudeauthority.js +2 -2
- package/dist_ts_authswitch/testsupport.js +4 -4
- package/dist_ts_authswitch/ts_migration/0012_account_claude_code.d.ts +11 -0
- package/dist_ts_authswitch/ts_migration/0012_account_claude_code.js +18 -0
- package/dist_ts_authswitch/ts_migration/index.js +3 -1
- package/dist_ts_interfaces/deployments.d.ts +104 -0
- package/dist_ts_interfaces/deployments.js +8 -0
- package/dist_ts_interfaces/fleet.d.ts +2 -0
- package/dist_ts_interfaces/index.d.ts +1 -0
- package/dist_ts_interfaces/index.js +2 -1
- package/dist_ts_interfaces/interfaces.d.ts +1 -1
- package/dist_ts_interfaces/interfaces.js +1 -1
- package/dist_ts_interfaces/requests.accounts.d.ts +18 -0
- package/dist_ts_interfaces/requests.accounts.js +1 -1
- package/dist_ts_interfaces/requests.d.ts +2 -2
- package/dist_ts_interfaces/requests.js +1 -1
- package/dist_ts_interfaces/tickets.d.ts +53 -4
- package/dist_ts_interfaces/tickets.js +6 -2
- package/dist_ts_migration/index.d.ts +1 -0
- package/dist_ts_migration/index.js +2 -1
- package/dist_ts_migration/v41_ticketmigrationmarkers.d.ts +19 -0
- package/dist_ts_migration/v41_ticketmigrationmarkers.js +85 -0
- package/docs/authswitch.md +9 -1
- package/package.json +5 -5
- package/readme.md +48 -12
- package/ts/00_commitinfo_data.ts +1 -1
- package/ts/aglapi/aglapisurface.document.ts +123 -9
- package/ts/classes.accountsactions.ts +24 -0
- package/ts/classes.authstore.ts +8 -0
- package/ts/classes.cli.ts +17 -54
- package/ts/classes.configurationauthority.ts +1 -1
- package/ts/classes.controllerservice.ts +49 -6
- package/ts/classes.flexservice.ts +7 -2
- package/ts/classes.inferencegateway.ts +133 -19
- package/ts/classes.inferencerouter.ts +20 -2
- package/ts/classes.inferenceservice.ts +6 -3
- package/ts/classes.ticketmodels.ts +3 -2
- package/ts/classes.ticketnotifier.ts +8 -1
- package/ts/classes.ticketstore.ts +8 -4
- package/ts/classes.upgradecoordinator.ts +14 -4
- package/ts/classes.upgradetransaction.ts +118 -0
- package/ts/configuration/functions.master.ts +6 -3
- package/ts/driver/classes.drivereventrelay.ts +2 -2
- package/ts/fleet/classes.boardpump.ts +7 -4
- package/ts/fleet/classes.claudeworkers.ts +16 -6
- package/ts/fleet/classes.deploymodels.ts +44 -0
- package/ts/fleet/functions.validation.ts +50 -2
- package/ts/fleet/interfaces.workers.ts +56 -1
- package/ts/functions.fleetworkercli.ts +26 -8
- package/ts/functions.inferencecli.ts +3 -1
- package/ts/functions.ticketvalidation.ts +48 -13
- package/ts/interfaces.auth.ts +1 -0
- package/ts_authswitch/authority-contract.ts +18 -0
- package/ts_authswitch/classes.authoritybroker.ts +67 -19
- package/ts_authswitch/classes.authoritycli.ts +29 -0
- package/ts_authswitch/classes.authorityclient.ts +12 -4
- package/ts_authswitch/classes.authoritydaemon.ts +8 -1
- package/ts_authswitch/classes.authorityimport.ts +1 -1
- package/ts_authswitch/classes.authoritymodels.ts +5 -1
- package/ts_authswitch/classes.authorityusage.ts +5 -2
- package/ts_authswitch/classes.claudeauthority.ts +1 -1
- package/ts_authswitch/native-contracts.md +10 -0
- package/ts_authswitch/testsupport.ts +3 -3
- package/ts_authswitch/ts_migration/0012_account_claude_code.ts +17 -0
- package/ts_authswitch/ts_migration/index.ts +2 -0
- package/ts_interfaces/deployments.ts +98 -0
- package/ts_interfaces/fleet.ts +2 -0
- package/ts_interfaces/index.ts +1 -0
- package/ts_interfaces/interfaces.ts +1 -1
- package/ts_interfaces/requests.accounts.ts +16 -0
- package/ts_interfaces/requests.ts +2 -0
- package/ts_interfaces/tickets.ts +34 -4
- package/ts_migration/index.ts +1 -0
- package/ts_migration/v41_ticketmigrationmarkers.ts +28 -0
- package/ts_web/00_commitinfo_data.ts +1 -1
- package/ts_web/classes.accountsreadmodel.ts +12 -1
- package/ts_web/elements.accounts.ts +44 -0
- package/ts_web/elements.ticketboard.ts +15 -4
|
@@ -156,7 +156,7 @@ const notOnApiKey = 'An API key account has no usage windows to keep a reserve o
|
|
|
156
156
|
const publicAccount = (account: IStoredAuthorityAccount): IAuthSwitchAccount => ({
|
|
157
157
|
id: account.id, providerId: account.providerId, label: account.label, email: account.email,
|
|
158
158
|
plan: account.plan, organizationId: account.workspaceId, maxUsagePercent: account.maxUsagePercent, reserveLiftUntil: account.reserveLiftUntil,
|
|
159
|
-
lapsesAt: account.lapsesAt, spendLimitMicroUsd: account.spendLimitMicroUsd, keyHint: account.keyHint,
|
|
159
|
+
lapsesAt: account.lapsesAt, spendLimitMicroUsd: account.spendLimitMicroUsd, keyHint: account.keyHint, claudeCode: account.claudeCode,
|
|
160
160
|
removed: account.removed, revision: account.revision, statusObservedAt: account.statusObservedAt,
|
|
161
161
|
});
|
|
162
162
|
|
|
@@ -315,21 +315,7 @@ export class AuthSwitchAuthorityBroker {
|
|
|
315
315
|
after = page.at(-1)!.id;
|
|
316
316
|
}
|
|
317
317
|
}
|
|
318
|
-
|
|
319
|
-
while (true) {
|
|
320
|
-
const page = await this.database.grantsByState('exchange_may_have_been_sent', after);
|
|
321
|
-
if (!page.length) break;
|
|
322
|
-
for (const grant of page) {
|
|
323
|
-
const updateId = plugins.crypto.randomUUID();
|
|
324
|
-
await this.database.changeGrant(updateId, grant.id, current => {
|
|
325
|
-
if (!current || current.state !== 'exchange_may_have_been_sent') throw new Error('Refresh recovery changed concurrently.');
|
|
326
|
-
return { ...current, state: 'needs_reauth', attemptId: null, problem: 'exchange_uncertain',
|
|
327
|
-
revision: current.revision + 1, statusObservedAt: new Date(this.now()).toISOString(), updateId };
|
|
328
|
-
});
|
|
329
|
-
this.publish();
|
|
330
|
-
}
|
|
331
|
-
after = page.at(-1)!.id;
|
|
332
|
-
}
|
|
318
|
+
await this.endUnheldRefreshes();
|
|
333
319
|
if (this.proactive) this.schedule();
|
|
334
320
|
}
|
|
335
321
|
|
|
@@ -363,6 +349,42 @@ export class AuthSwitchAuthorityBroker {
|
|
|
363
349
|
after = page.at(-1)!.id;
|
|
364
350
|
}
|
|
365
351
|
}
|
|
352
|
+
await this.endUnheldRefreshes();
|
|
353
|
+
}
|
|
354
|
+
|
|
355
|
+
/**
|
|
356
|
+
* Ends every refresh marker no renewal of this daemon holds. Only this daemon renews, so such an attempt is over with
|
|
357
|
+
* its outcome unrecorded: it failed past its marker, or an earlier daemon died during it. Its exchange may have spent
|
|
358
|
+
* the token, so it is never replayed and only a sign-in repairs the login.
|
|
359
|
+
*/
|
|
360
|
+
private async endUnheldRefreshes(): Promise<void> {
|
|
361
|
+
let after: string | null = null;
|
|
362
|
+
while (!this.closed) {
|
|
363
|
+
const page = await this.database.grantsByState('exchange_may_have_been_sent', after);
|
|
364
|
+
if (!page.length) break;
|
|
365
|
+
for (const grant of page) {
|
|
366
|
+
if (this.refreshes.has(grant.accountId) || this.claudeGrants?.pendingRefresh(grant.id)) continue;
|
|
367
|
+
const updateId = plugins.crypto.randomUUID();
|
|
368
|
+
try {
|
|
369
|
+
await this.database.changeGrant(updateId, grant.id, current => {
|
|
370
|
+
if (current.state !== 'exchange_may_have_been_sent' || current.attemptId !== grant.attemptId) {
|
|
371
|
+
throw new Error('Refresh recovery changed concurrently.');
|
|
372
|
+
}
|
|
373
|
+
return { ...current, state: 'needs_reauth', attemptId: null, problem: 'exchange_uncertain',
|
|
374
|
+
revision: current.revision + 1, statusObservedAt: new Date(this.now()).toISOString(), updateId };
|
|
375
|
+
});
|
|
376
|
+
} catch (error) {
|
|
377
|
+
// A renewal that ended between the page and this write has settled its own marker.
|
|
378
|
+
const latest = await this.database.readGrant(grant.id);
|
|
379
|
+
if (latest?.state === 'exchange_may_have_been_sent' && latest.attemptId === grant.attemptId) throw error;
|
|
380
|
+
continue;
|
|
381
|
+
}
|
|
382
|
+
process.stderr.write(`Authswitch ended login ${grant.id}: its renewal stopped with no recorded outcome, `
|
|
383
|
+
+ 'so it needs a new sign-in.\n');
|
|
384
|
+
this.publish();
|
|
385
|
+
}
|
|
386
|
+
after = page.at(-1)!.id;
|
|
387
|
+
}
|
|
366
388
|
}
|
|
367
389
|
|
|
368
390
|
private isDue(grant: IStoredAuthorityGrant, minValidityMs: number): boolean {
|
|
@@ -675,7 +697,7 @@ export class AuthSwitchAuthorityBroker {
|
|
|
675
697
|
revision: existing.revision + 1, statusObservedAt: now, updateId: commitId }
|
|
676
698
|
: { id: identity.id, providerId: 'openai', issuer: 'openai', subject: identity.subject,
|
|
677
699
|
workspaceId: identity.workspaceId, label: identity.email ?? `OpenAI ${identity.workspaceId}`,
|
|
678
|
-
email: identity.email, plan: identity.plan, primaryGrantId: grantId, maxUsagePercent: null, reserveLiftUntil: null, lapsesAt: null, spendLimitMicroUsd: null, keyHint: null, removed: false,
|
|
700
|
+
email: identity.email, plan: identity.plan, primaryGrantId: grantId, maxUsagePercent: null, reserveLiftUntil: null, lapsesAt: null, spendLimitMicroUsd: null, keyHint: null, claudeCode: true, removed: false,
|
|
679
701
|
revision: 1, statusObservedAt: now, updateId: commitId };
|
|
680
702
|
const grant: IStoredAuthorityGrant = oldGrant
|
|
681
703
|
? { ...oldGrant, state: 'ready', owner: 'daemon', ciphertext,
|
|
@@ -870,6 +892,32 @@ export class AuthSwitchAuthorityBroker {
|
|
|
870
892
|
return publicAccount(updated.account);
|
|
871
893
|
}
|
|
872
894
|
|
|
895
|
+
/**
|
|
896
|
+
* Sets whether an API key account may serve Claude Code (`IAuthSwitchAccount.claudeCode`), as `setAccountSpendLimit`
|
|
897
|
+
* changes its limit. The proxy applies it from the next request on: a Claude Code session on a key that may not serve
|
|
898
|
+
* it moves to another account then. The value the key already has changes nothing.
|
|
899
|
+
*/
|
|
900
|
+
public async setAccountClaudeCode(accountId: string, expectedRevision: number, claudeCode: boolean): Promise<IAuthSwitchAccount> {
|
|
901
|
+
if (!isId(accountId) || !validRevision(expectedRevision) || typeof claudeCode !== 'boolean') {
|
|
902
|
+
throw new Error('Invalid account change.');
|
|
903
|
+
}
|
|
904
|
+
const current = await this.database.readAccount(accountId);
|
|
905
|
+
if (current && !current.removed && current.revision === expectedRevision && isApiKeyAccount(current)
|
|
906
|
+
&& current.claudeCode === claudeCode) return publicAccount(current);
|
|
907
|
+
const updateId = plugins.crypto.randomUUID();
|
|
908
|
+
const updated = await this.database.changeAccount(updateId, accountId, account => {
|
|
909
|
+
if (!account || account.removed || account.revision !== expectedRevision) throw new AuthSwitchRefusal('account_changed', 'Account changed; refresh before editing.');
|
|
910
|
+
if (!isApiKeyAccount(account)) {
|
|
911
|
+
throw new AuthSwitchRefusal('invalid_input', 'A sign-in always serves Claude Code. Only an API key account can be '
|
|
912
|
+
+ 'kept from it.');
|
|
913
|
+
}
|
|
914
|
+
return { ...account, claudeCode, revision: account.revision + 1, updateId,
|
|
915
|
+
statusObservedAt: new Date(this.now()).toISOString() };
|
|
916
|
+
});
|
|
917
|
+
this.publish();
|
|
918
|
+
return publicAccount(updated.account);
|
|
919
|
+
}
|
|
920
|
+
|
|
873
921
|
/**
|
|
874
922
|
* Sets or clears the date an account's subscription ends, as `setAccountMaxUsage` changes its threshold. The date is
|
|
875
923
|
* stored in its ISO 8601 UTC form; a past one is kept as given and means the account lapsed already.
|
|
@@ -1379,7 +1427,7 @@ export class AuthSwitchAuthorityBroker {
|
|
|
1379
1427
|
: { id: accountId, providerId, issuer: providerId, subject, workspaceId: apiKeyWorkspace,
|
|
1380
1428
|
label: label ?? kind.label, email: null, plan: null, primaryGrantId: grantId, maxUsagePercent: null,
|
|
1381
1429
|
reserveLiftUntil: null, lapsesAt: null, spendLimitMicroUsd: spendLimitMicroUsd ?? null, keyHint,
|
|
1382
|
-
removed: false, revision: 1, statusObservedAt: now, updateId };
|
|
1430
|
+
claudeCode: true, removed: false, revision: 1, statusObservedAt: now, updateId };
|
|
1383
1431
|
const grant: IStoredAuthorityGrant = oldGrant
|
|
1384
1432
|
? { ...oldGrant, state: 'ready', owner: 'daemon', ciphertext, grantGeneration: oldGrant.grantGeneration + 1,
|
|
1385
1433
|
authorizationGeneration: oldGrant.authorizationGeneration + 1, revision: oldGrant.revision + 1,
|
|
@@ -1495,7 +1543,7 @@ export class AuthSwitchAuthorityBroker {
|
|
|
1495
1543
|
statusObservedAt: new Date(this.now()).toISOString(), updateId: uncertainId };
|
|
1496
1544
|
});
|
|
1497
1545
|
this.publish();
|
|
1498
|
-
} catch { /*
|
|
1546
|
+
} catch { /* The next scan ends the marker this left (`endUnheldRefreshes`). */ }
|
|
1499
1547
|
// The grant is now `needs_reauth`: an uncertain rotation is never replayed, so only a sign-in repairs it.
|
|
1500
1548
|
throw new AuthSwitchRefusal('login_needs_reauth', loginNeedsReauth);
|
|
1501
1549
|
}
|
|
@@ -61,6 +61,7 @@ export interface IAuthSwitchAuthorityCliClient {
|
|
|
61
61
|
setAccountLapse(accountId: string, expectedRevision: number, lapsesAt: string | null): Promise<IAuthSwitchAccount>;
|
|
62
62
|
setAccountSpendLimit(accountId: string, expectedRevision: number,
|
|
63
63
|
spendLimitMicroUsd: number | null): Promise<IAuthSwitchAccount>;
|
|
64
|
+
setAccountClaudeCode(accountId: string, expectedRevision: number, claudeCode: boolean): Promise<IAuthSwitchAccount>;
|
|
64
65
|
close(reason?: Error): void;
|
|
65
66
|
}
|
|
66
67
|
|
|
@@ -102,6 +103,7 @@ type TAuthorityCliCommand =
|
|
|
102
103
|
| { kind: 'setMaxUsage'; accountId: string; maxUsagePercent: number | null; json: boolean }
|
|
103
104
|
| { kind: 'setLapse'; accountId: string; lapsesAt: string | null; json: boolean }
|
|
104
105
|
| { kind: 'setSpendLimit'; accountId: string; spendLimitMicroUsd: number | null; json: boolean }
|
|
106
|
+
| { kind: 'setClaudeCode'; accountId: string; claudeCode: boolean; json: boolean }
|
|
105
107
|
| { kind: 'get'; operationId: string; json: boolean }
|
|
106
108
|
| { kind: 'cancel'; operationId: string; json: boolean }
|
|
107
109
|
| { kind: 'resume'; operationId: string; json: boolean }
|
|
@@ -176,6 +178,10 @@ Usage
|
|
|
176
178
|
what AGL's proxy relayed on it: at the limit the proxy places
|
|
177
179
|
nothing more on the key until the month ends;
|
|
178
180
|
--clear-spend-limit removes it
|
|
181
|
+
authswitch account set <account-id> --claude-code on|off [--json]
|
|
182
|
+
whether an API key may serve Claude Code: off keeps AGL's
|
|
183
|
+
proxy from placing Claude Code on it (a key whose credit is
|
|
184
|
+
not for Claude Code); other clients still use it
|
|
179
185
|
authswitch account operation get|cancel|resume <operation-id> [--json]
|
|
180
186
|
follow a sign-in that is still running
|
|
181
187
|
authswitch account preuse <account-id> <login-id>|--all [--prompt <text>] [--model <id>] [--json]
|
|
@@ -385,6 +391,9 @@ const parse = (argv: readonly string[]): TAuthorityCliCommand | null => {
|
|
|
385
391
|
if (options.length === 2 && options[0] === '--spend-limit' && authSwitchParseUsd(options[1]!) !== null) {
|
|
386
392
|
return { kind: 'setSpendLimit', accountId: argv[2], spendLimitMicroUsd: authSwitchParseUsd(options[1]!), json };
|
|
387
393
|
}
|
|
394
|
+
if (options.length === 2 && options[0] === '--claude-code' && (options[1] === 'on' || options[1] === 'off')) {
|
|
395
|
+
return { kind: 'setClaudeCode', accountId: argv[2], claudeCode: options[1] === 'on', json };
|
|
396
|
+
}
|
|
388
397
|
return null;
|
|
389
398
|
}
|
|
390
399
|
if (argv[0] === 'account' && argv[1] === 'operation'
|
|
@@ -520,6 +529,10 @@ class ScopedAuthorityCliClient implements IAuthSwitchAuthorityCliClient {
|
|
|
520
529
|
return this.client.setAccountSpendLimit(accountId, expectedRevision, spendLimitMicroUsd, this.controller.signal);
|
|
521
530
|
}
|
|
522
531
|
|
|
532
|
+
public setAccountClaudeCode(accountId: string, expectedRevision: number, claudeCode: boolean): Promise<IAuthSwitchAccount> {
|
|
533
|
+
return this.client.setAccountClaudeCode(accountId, expectedRevision, claudeCode, this.controller.signal);
|
|
534
|
+
}
|
|
535
|
+
|
|
523
536
|
public close(reason = new Error('Authswitch authority CLI closed.')): void {
|
|
524
537
|
if (!this.controller.signal.aborted) this.controller.abort(reason);
|
|
525
538
|
}
|
|
@@ -546,6 +559,11 @@ const renderApiKeyAdded = (account: IAuthSwitchAccount): string =>
|
|
|
546
559
|
const renderSpendLimit = (account: IAuthSwitchAccount): string =>
|
|
547
560
|
`Account ${safe(account.label)} (${safe(account.id)}): ${spendLimitText(account)}.\n`;
|
|
548
561
|
|
|
562
|
+
const renderClaudeCode = (account: IAuthSwitchAccount): string =>
|
|
563
|
+
`Account ${safe(account.label)} (${safe(account.id)}): ${account.claudeCode ? 'serves Claude Code'
|
|
564
|
+
: 'serves no Claude Code; AGL\'s inference proxy places Claude Code requests on other accounts, and other clients '
|
|
565
|
+
+ 'still use it'}.\n`;
|
|
566
|
+
|
|
549
567
|
/**
|
|
550
568
|
* The key `account add anthropic-api-key` adds, from standard input: a line typed at a terminal, which is not echoed
|
|
551
569
|
* (a muted output for the line editor), or everything a pipe or file supplies. A cancelled command stops reading, so
|
|
@@ -1492,6 +1510,17 @@ export const runAuthSwitchAuthorityCli = async (argv: readonly string[],
|
|
|
1492
1510
|
await writeOutput(command.json ? JSON.stringify({ account: changed }) + '\n' : renderSpendLimit(changed));
|
|
1493
1511
|
return 0;
|
|
1494
1512
|
}
|
|
1513
|
+
if (command.kind === 'setClaudeCode') {
|
|
1514
|
+
const account = (await activeClient.snapshotAll()).accounts.find(item => item.id === command.accountId && !item.removed);
|
|
1515
|
+
if (!account) {
|
|
1516
|
+
await writeDiagnostic('No authority account has this id. Run `authswitch account list` for the ids.\n');
|
|
1517
|
+
return 1;
|
|
1518
|
+
}
|
|
1519
|
+
const changed = await activeClient.setAccountClaudeCode(account.id, account.revision, command.claudeCode);
|
|
1520
|
+
if (changed.id !== account.id || changed.claudeCode !== command.claudeCode) throw new AuthorityCliFailure('response');
|
|
1521
|
+
await writeOutput(command.json ? JSON.stringify({ account: changed }) + '\n' : renderClaudeCode(changed));
|
|
1522
|
+
return 0;
|
|
1523
|
+
}
|
|
1495
1524
|
if (command.kind === 'addApiKey') {
|
|
1496
1525
|
const apiKey = (await withinDeadline(() => (options.readApiKey ?? readStandardInputApiKey)(operationController.signal,
|
|
1497
1526
|
command.providerId))).trim();
|
|
@@ -11,7 +11,7 @@ import type {
|
|
|
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,
|
|
14
|
-
IReq_AuthSwitchSetAccountSpendLimit,
|
|
14
|
+
IReq_AuthSwitchSetAccountSpendLimit, IReq_AuthSwitchSetAccountClaudeCode,
|
|
15
15
|
IReq_AuthSwitchRecheckUsage, IReq_AuthSwitchMoveClaudeHomeIn, IReq_AuthSwitchMoveClaudeHomeOut,
|
|
16
16
|
IReq_AuthSwitchRegisterClaudeHome, IReq_AuthSwitchResolveClaudeHome, IReq_AuthSwitchUnregisterClaudeHome,
|
|
17
17
|
IAuthSwitchClaudeSignInOperation, IReq_AuthSwitchCancelClaudeSignIn, IReq_AuthSwitchGetClaudeSignIn,
|
|
@@ -121,8 +121,9 @@ export class AuthSwitchDaemonOutdatedError extends Error {
|
|
|
121
121
|
/**
|
|
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
|
-
* on, its `lapsesAt` from 38.4.0 on, its `reserveLiftUntil` with reserve lifts,
|
|
125
|
-
* `keyHint` with API keys of both providers. Consumers still check their
|
|
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, and its `claudeCode` from AGL-1146 on. Consumers still check their
|
|
126
|
+
* supported version.
|
|
126
127
|
*/
|
|
127
128
|
const assertCurrentSnapshot = (snapshot: IAuthSwitchSnapshot): IAuthSwitchSnapshot => {
|
|
128
129
|
const page: Partial<IAuthSwitchSnapshot> = snapshot;
|
|
@@ -132,7 +133,8 @@ const assertCurrentSnapshot = (snapshot: IAuthSwitchSnapshot): IAuthSwitchSnapsh
|
|
|
132
133
|
|| (account as Partial<IAuthSwitchAccount>).lapsesAt === undefined
|
|
133
134
|
|| (account as Partial<IAuthSwitchAccount>).reserveLiftUntil === undefined
|
|
134
135
|
|| (account as Partial<IAuthSwitchAccount>).spendLimitMicroUsd === undefined
|
|
135
|
-
|| (account as Partial<IAuthSwitchAccount>).keyHint === undefined
|
|
136
|
+
|| (account as Partial<IAuthSwitchAccount>).keyHint === undefined
|
|
137
|
+
|| (account as Partial<IAuthSwitchAccount>).claudeCode === undefined)) {
|
|
136
138
|
throw new AuthSwitchDaemonOutdatedError();
|
|
137
139
|
}
|
|
138
140
|
return snapshot;
|
|
@@ -526,6 +528,12 @@ export class AuthSwitchClient {
|
|
|
526
528
|
return (await this.request<IReq_AuthSwitchSetAccountSpendLimit>('authswitch.authority.spendlimit',
|
|
527
529
|
{ accountId, expectedRevision, spendLimitMicroUsd }, 10_000, false, signal)).account;
|
|
528
530
|
}
|
|
531
|
+
/** Sets whether an API key account may serve Claude Code (see `IReq_AuthSwitchSetAccountClaudeCode`). */
|
|
532
|
+
public async setAccountClaudeCode(accountId: string, expectedRevision: number, claudeCode: boolean,
|
|
533
|
+
signal?: AbortSignal): Promise<IReq_AuthSwitchSetAccountClaudeCode['response']['account']> {
|
|
534
|
+
return (await this.request<IReq_AuthSwitchSetAccountClaudeCode>('authswitch.authority.claudecode',
|
|
535
|
+
{ accountId, expectedRevision, claudeCode }, 10_000, false, signal)).account;
|
|
536
|
+
}
|
|
529
537
|
|
|
530
538
|
/** Sets an account's usage threshold, or clears it with `null` (see `IReq_AuthSwitchSetAccountMaxUsage`). */
|
|
531
539
|
public async setAccountMaxUsage(accountId: string, expectedRevision: number, maxUsagePercent: number | null,
|
|
@@ -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_AuthSwitchSetAccountMaxUsage, IReq_AuthSwitchSetAccountSpendLimit, IReq_AuthSwitchLiftAccountReserve, IReq_AuthSwitchSnapshot,
|
|
11
|
+
IReq_AuthSwitchRenameAccount, IReq_AuthSwitchSetAccountLapse, 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,
|
|
@@ -733,6 +733,13 @@ export class AuthSwitchAuthorityDaemon {
|
|
|
733
733
|
return { account: await this.broker.setAccountSpendLimit(request.accountId, request.expectedRevision,
|
|
734
734
|
request.spendLimitMicroUsd) };
|
|
735
735
|
}));
|
|
736
|
+
this.managementRouter.addTypedHandler(this.handler<IReq_AuthSwitchSetAccountClaudeCode>(
|
|
737
|
+
'authswitch.authority.claudecode', async request => {
|
|
738
|
+
if (!hasKeys(request, ['accountId', 'expectedRevision', 'claudeCode']) || typeof request.accountId !== 'string'
|
|
739
|
+
|| typeof request.expectedRevision !== 'number' || typeof request.claudeCode !== 'boolean') invalid();
|
|
740
|
+
return { account: await this.broker.setAccountClaudeCode(request.accountId, request.expectedRevision,
|
|
741
|
+
request.claudeCode) };
|
|
742
|
+
}));
|
|
736
743
|
this.managementRouter.addTypedHandler(this.handler<IReq_AuthSwitchLiftAccountReserve>(
|
|
737
744
|
'authswitch.authority.reserve.lift', async request => {
|
|
738
745
|
if (!hasKeys(request, ['accountId', 'expectedRevision', 'hours']) || typeof request.accountId !== 'string'
|
|
@@ -687,7 +687,7 @@ export class AuthSwitchGrantImport {
|
|
|
687
687
|
removed: false, revision: existing.revision + 1, statusObservedAt: this.stamp(), updateId }
|
|
688
688
|
: { id: identity.accountId, providerId: plan.providerId, issuer: plan.providerId,
|
|
689
689
|
subject: identity.subject, workspaceId: identity.workspaceId, label, email: record.email,
|
|
690
|
-
plan: record.plan, primaryGrantId: grantId, maxUsagePercent: null, reserveLiftUntil: null, lapsesAt: null, spendLimitMicroUsd: null, keyHint: null, removed: false, revision: 1,
|
|
690
|
+
plan: record.plan, primaryGrantId: grantId, maxUsagePercent: null, reserveLiftUntil: null, lapsesAt: null, spendLimitMicroUsd: null, keyHint: null, claudeCode: true, removed: false, revision: 1,
|
|
691
691
|
statusObservedAt: this.stamp(), updateId };
|
|
692
692
|
}
|
|
693
693
|
|
|
@@ -34,6 +34,8 @@ export interface IStoredAuthorityAccount {
|
|
|
34
34
|
spendLimitMicroUsd: number | null;
|
|
35
35
|
/** How an API key account's key ends, or `null` (`IAuthSwitchAccount.keyHint`). */
|
|
36
36
|
keyHint: string | null;
|
|
37
|
+
/** Whether the account may serve Claude Code (`IAuthSwitchAccount.claudeCode`); always `true` for a sign-in. */
|
|
38
|
+
claudeCode: boolean;
|
|
37
39
|
removed: boolean;
|
|
38
40
|
revision: number;
|
|
39
41
|
statusObservedAt: string;
|
|
@@ -728,7 +730,7 @@ export const assertStoredAuthorityMeta: (value: unknown) => asserts value is ISt
|
|
|
728
730
|
export const assertStoredAuthorityAccount: (value: unknown) => asserts value is IStoredAuthorityAccount = value => {
|
|
729
731
|
if (!object(value) || !exactKeys(value, ['id', 'providerId', 'issuer', 'subject', 'workspaceId', 'label',
|
|
730
732
|
'email', 'plan', 'primaryGrantId', 'maxUsagePercent', 'reserveLiftUntil', 'lapsesAt', 'spendLimitMicroUsd', 'keyHint',
|
|
731
|
-
'removed', 'revision', 'statusObservedAt', 'updateId'])
|
|
733
|
+
'claudeCode', 'removed', 'revision', 'statusObservedAt', 'updateId'])
|
|
732
734
|
|| !hash(value.id) || typeof value.providerId !== 'string'
|
|
733
735
|
|| !/^[a-z][a-z0-9-]{0,63}$/.test(value.providerId)
|
|
734
736
|
|| !bounded(value.issuer) || !bounded(value.subject) || !bounded(value.workspaceId)
|
|
@@ -740,6 +742,7 @@ export const assertStoredAuthorityAccount: (value: unknown) => asserts value is
|
|
|
740
742
|
|| (value.lapsesAt !== null && (!iso(value.lapsesAt) || !isAuthSwitchLapsesAt(value.lapsesAt)))
|
|
741
743
|
|| (value.spendLimitMicroUsd !== null && !isAuthSwitchSpendLimitMicroUsd(value.spendLimitMicroUsd))
|
|
742
744
|
|| (value.keyHint !== null && !isAuthSwitchKeyHint(value.keyHint))
|
|
745
|
+
|| typeof value.claudeCode !== 'boolean'
|
|
743
746
|
|| typeof value.removed !== 'boolean' || !revision(value.revision)
|
|
744
747
|
|| !iso(value.statusObservedAt) || !uuid(value.updateId)) throw new Error('Invalid authswitch account record.');
|
|
745
748
|
};
|
|
@@ -1300,6 +1303,7 @@ export class AuthSwitchAuthorityAccountModel extends plugins.nosqldb.SmartDataDb
|
|
|
1300
1303
|
@plugins.nosqldb.svDb() public lapsesAt!: string | null;
|
|
1301
1304
|
@plugins.nosqldb.svDb() public spendLimitMicroUsd!: number | null;
|
|
1302
1305
|
@plugins.nosqldb.svDb() public keyHint!: string | null;
|
|
1306
|
+
@plugins.nosqldb.svDb() public claudeCode!: boolean;
|
|
1303
1307
|
@plugins.nosqldb.svDb() public removed!: boolean;
|
|
1304
1308
|
@plugins.nosqldb.svDb() public revision!: number;
|
|
1305
1309
|
@plugins.nosqldb.svDb() public statusObservedAt!: string;
|
|
@@ -405,6 +405,10 @@ const native = (context: IAuthSwitchUsageContext): boolean => context.providerId
|
|
|
405
405
|
const readable = (context: IAuthSwitchUsageContext): boolean => usable(context)
|
|
406
406
|
|| (native(context) && !context.removed && context.nativeSource === null);
|
|
407
407
|
|
|
408
|
+
/** What keeps a login of a readable kind from being read now, so its usage is missing for want of access. */
|
|
409
|
+
const accessStoppedStates = ['exchange_may_have_been_sent', 'needs_reauth', 'handoff_pending', 'handoff_quarantined',
|
|
410
|
+
'legacy_native_pending'];
|
|
411
|
+
|
|
408
412
|
/**
|
|
409
413
|
* Whether a reading or observation made under one context still describes the login of another: the same account,
|
|
410
414
|
* login, subject, workspace, owner and authorization, and the same Claude Code home where both name one. A renewed token
|
|
@@ -938,8 +942,7 @@ export class AuthSwitchAuthorityUsage {
|
|
|
938
942
|
if (!readable(context)) {
|
|
939
943
|
this.unschedule(accountId, loginId);
|
|
940
944
|
return this.unavailable(accountId, loginId,
|
|
941
|
-
context.removed ||
|
|
942
|
-
? 'access_unavailable' : 'unsupported');
|
|
945
|
+
context.removed || accessStoppedStates.includes(context.grantState) ? 'access_unavailable' : 'unsupported');
|
|
943
946
|
}
|
|
944
947
|
let stored: IAuthSwitchStoredUsage | null;
|
|
945
948
|
try { stored = await this.options.store.read(accountId, loginId); }
|
|
@@ -165,7 +165,7 @@ export class ClaudeNativeAuthority {
|
|
|
165
165
|
});
|
|
166
166
|
this.changed();
|
|
167
167
|
} catch {
|
|
168
|
-
// The pre-send marker is durable.
|
|
168
|
+
// The pre-send marker is durable. The broker's next scan makes an unresolved rotation needs_reauth.
|
|
169
169
|
throw new Error('Claude refresh commit is uncertain; the previous token will not be replayed.');
|
|
170
170
|
}
|
|
171
171
|
}
|
|
@@ -497,6 +497,16 @@ information", https://platform.claude.com/docs/en/api/errors, read 2026-10-20).
|
|
|
497
497
|
on exactly that, read before any byte reaches the client, and passes every other 402 through;
|
|
498
498
|
a `billing_error` event inside a stream that already started is not read.
|
|
499
499
|
|
|
500
|
+
Inference on an Anthropic API key whose organization has no credit left (observed 2026-10-29,
|
|
501
|
+
AGL-1147; not in Anthropic's error reference): HTTP 400 with a JSON body whose `error.type` is
|
|
502
|
+
`invalid_request_error` and whose message says the credit balance is too low ("Your credit balance
|
|
503
|
+
is too low to access the Anthropic API. Please go to Plans & Billing to upgrade or purchase
|
|
504
|
+
credits."; Claude Code shows it as "Credit balance is too low" and tags it `billing_error`). It
|
|
505
|
+
answered every request on the key from 11:59 to 12:03 UTC, a 40k-token one as well as a 755k-token
|
|
506
|
+
one; by 12:43 the same key answered requests of every size again (the cause of the change is not
|
|
507
|
+
visible through the key). The proxy reads it as a billing problem of the key; the balance itself
|
|
508
|
+
is not readable with the key.
|
|
509
|
+
|
|
500
510
|
Login refresh (`ClaudeTokenRefresh.refreshForAuthority`), with the vendor's grant: POST
|
|
501
511
|
`https://platform.claude.com/v1/oauth/token` (`s.TOKEN_URL` @12733057), `Content-Type: application/json`, a 30 s
|
|
502
512
|
timeout, and the body `{grant_type:"refresh_token", refresh_token, client_id: <stored clientId> ?? CLIENT_ID
|
|
@@ -444,7 +444,7 @@ export const authSwitchSeedClaudeAccount = async (daemon: AuthSwitchAuthorityDae
|
|
|
444
444
|
} else {
|
|
445
445
|
const account: IStoredAuthorityAccount = { id: accountId, providerId: 'anthropic', issuer: 'anthropic',
|
|
446
446
|
subject: identity.accountUuid, workspaceId: identity.organizationUuid, label: name,
|
|
447
|
-
email: identity.emailAddress, plan: 'max', primaryGrantId: loginId, maxUsagePercent: null, reserveLiftUntil: null, lapsesAt: null, spendLimitMicroUsd: null, keyHint: null, removed: false, revision: 1,
|
|
447
|
+
email: identity.emailAddress, plan: 'max', primaryGrantId: loginId, maxUsagePercent: null, reserveLiftUntil: null, lapsesAt: null, spendLimitMicroUsd: null, keyHint: null, claudeCode: true, removed: false, revision: 1,
|
|
448
448
|
statusObservedAt: now, updateId };
|
|
449
449
|
await database.changeAccountAndGrant(updateId, accountId, loginId, () => ({ account, grant }));
|
|
450
450
|
}
|
|
@@ -710,7 +710,7 @@ export class AuthSwitchTestAuthority {
|
|
|
710
710
|
await database.changeAccountAndGrant(updateId, account.accountId, account.loginId, () => ({
|
|
711
711
|
account: { id: account.accountId, providerId: 'anthropic', issuer: 'anthropic', subject: identity.accountUuid,
|
|
712
712
|
workspaceId: identity.organizationUuid, label: name, email: identity.emailAddress, plan: 'max',
|
|
713
|
-
primaryGrantId: account.loginId, maxUsagePercent: null, reserveLiftUntil: null, lapsesAt: null, spendLimitMicroUsd: null, keyHint: null, removed: false, revision: 1, statusObservedAt: now, updateId },
|
|
713
|
+
primaryGrantId: account.loginId, maxUsagePercent: null, reserveLiftUntil: null, lapsesAt: null, spendLimitMicroUsd: null, keyHint: null, claudeCode: true, removed: false, revision: 1, statusObservedAt: now, updateId },
|
|
714
714
|
grant: { id: account.loginId, accountId: account.accountId, providerId: 'anthropic', purpose: 'claude_host_native',
|
|
715
715
|
audience: 'claude-code-host', state: 'native', owner: 'claude_native', grantGeneration: 1, authorizationGeneration: 1,
|
|
716
716
|
revision: 1, ciphertext: null, accessExpiresAt: null, attemptId: null, retryAt: null, retryCount: 0,
|
|
@@ -748,7 +748,7 @@ export class AuthSwitchTestAuthority {
|
|
|
748
748
|
const identity = authSwitchFixtureOpenAiIdentity(name);
|
|
749
749
|
return { id: accountId, providerId: 'openai', issuer: 'openai', subject: identity.userId,
|
|
750
750
|
workspaceId: identity.chatgptAccountId, label: name, email: identity.email, plan: 'pro', primaryGrantId: loginId,
|
|
751
|
-
maxUsagePercent: null, reserveLiftUntil: null, lapsesAt: null, spendLimitMicroUsd: null, keyHint: null, removed: false, revision: 1, statusObservedAt: now, updateId };
|
|
751
|
+
maxUsagePercent: null, reserveLiftUntil: null, lapsesAt: null, spendLimitMicroUsd: null, keyHint: null, claudeCode: true, removed: false, revision: 1, statusObservedAt: now, updateId };
|
|
752
752
|
}
|
|
753
753
|
|
|
754
754
|
/**
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import * as plugins from '../plugins.js';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Gives every account recorded before an API key could be kept from Claude Code the member the account record now
|
|
5
|
+
* states (AGL-1146).
|
|
6
|
+
*
|
|
7
|
+
* Every account may serve Claude Code unless its owner set otherwise (`claudeCode`), so every account recorded earlier
|
|
8
|
+
* gains `claudeCode: true`, sign-ins and keys alike, and nothing else about it changes, neither its revision nor its
|
|
9
|
+
* update id, since no one changed the account. A record that already carries the member keeps it exactly as it is,
|
|
10
|
+
* which is what makes an interrupted run safe to repeat.
|
|
11
|
+
*/
|
|
12
|
+
export const addAccountClaudeCode = async (db: plugins.nosqldb.SmartdataDb): Promise<void> => {
|
|
13
|
+
const accounts = db.mongoDb.collection('authswitch_authority_accounts');
|
|
14
|
+
const missing = { claudeCode: { $exists: false } };
|
|
15
|
+
if (!await accounts.findOne(missing)) return;
|
|
16
|
+
await accounts.updateMany(missing, { $set: { claudeCode: true } });
|
|
17
|
+
};
|
|
@@ -10,6 +10,7 @@ import { addAccountLapse } from './0008_account_lapse.js';
|
|
|
10
10
|
import { addAccountReserveLift } from './0009_account_reserve_lift.js';
|
|
11
11
|
import { prepareCodexHostRelease } from './0010_codex_host_release.js';
|
|
12
12
|
import { addAccountApiKeyFields } from './0011_account_api_key_fields.js';
|
|
13
|
+
import { addAccountClaudeCode } from './0012_account_claude_code.js';
|
|
13
14
|
|
|
14
15
|
/**
|
|
15
16
|
* Runs on every start of an existing store, in this fixed order. Each module recognises the published shapes it
|
|
@@ -27,4 +28,5 @@ export const runAuthorityMigrations = async (db: plugins.nosqldb.SmartdataDb): P
|
|
|
27
28
|
await addAccountReserveLift(db);
|
|
28
29
|
await prepareCodexHostRelease(db);
|
|
29
30
|
await addAccountApiKeyFields(db);
|
|
31
|
+
await addAccountClaudeCode(db);
|
|
30
32
|
};
|
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Deployments (AGL-909): what runs where, observed rather than claimed. A release is the repository's tag `v<version>`;
|
|
3
|
+
* what a target runs is what its probe answers, recorded as an observation whenever it changes. Everything else (what a
|
|
4
|
+
* release holds, how far a target is behind, open bugs on the running version) is computed when it is read.
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* How a target tells what it runs. `controller` is the AGL controller itself (its package version and start time);
|
|
9
|
+
* `http` reads a JSON document and takes the version, and optionally the commit, at JSON pointers.
|
|
10
|
+
*/
|
|
11
|
+
export type TFleetDeployProbe =
|
|
12
|
+
| { kind: 'controller' }
|
|
13
|
+
| {
|
|
14
|
+
kind: 'http';
|
|
15
|
+
/** An http(s) URL without credentials. */
|
|
16
|
+
url: string;
|
|
17
|
+
/** RFC 6901 pointer to the version in the JSON answer; absent is `/version`. */
|
|
18
|
+
versionPointer?: string;
|
|
19
|
+
/** RFC 6901 pointer to the commit sha in the JSON answer; absent reads none. */
|
|
20
|
+
shaPointer?: string;
|
|
21
|
+
};
|
|
22
|
+
|
|
23
|
+
/** A deploy target id: lowercase letters, digits, `.`, `_` and `-`, at most 64. */
|
|
24
|
+
export const fleetDeployTargetIdPattern = /^[a-z0-9][a-z0-9._-]{0,63}$/u;
|
|
25
|
+
|
|
26
|
+
/**
|
|
27
|
+
* When a target's deploys may run: at any time, or only inside a maintenance window planned for it. The AGL controller
|
|
28
|
+
* declares neither: it is deployed (upgraded) when no session is busy.
|
|
29
|
+
*/
|
|
30
|
+
export type TFleetDeployWhen = 'anytime' | 'window';
|
|
31
|
+
|
|
32
|
+
/** A deploy target in the Configuration master (`fleet.deployTargets`). The AGL controller is built in and needs none. */
|
|
33
|
+
export interface IFleetDeployTarget {
|
|
34
|
+
/** Lowercase letters, digits, `.`, `_` and `-`; `agl-controller` names the built-in controller target. */
|
|
35
|
+
id: string;
|
|
36
|
+
/** The name the views show; absent shows the id. */
|
|
37
|
+
name?: string;
|
|
38
|
+
/** Where it runs, shown under its name: an environment such as `production`, or a host. */
|
|
39
|
+
environment?: string;
|
|
40
|
+
/** The repository it runs, `org/name` as fleet discovery knows it. */
|
|
41
|
+
repo: string;
|
|
42
|
+
probe: TFleetDeployProbe;
|
|
43
|
+
/** How a deploy happens, in words, for the target sheet. */
|
|
44
|
+
deploys?: string;
|
|
45
|
+
/** What a deploy interrupts, in words, for the target sheet. */
|
|
46
|
+
downtime?: string;
|
|
47
|
+
/**
|
|
48
|
+
* The board project that owns the target: its deploy plans are tickets there, and the direct report whose projects
|
|
49
|
+
* hold it deploys it; no report's project is the driver's own.
|
|
50
|
+
*/
|
|
51
|
+
project: string;
|
|
52
|
+
/** Absent is `anytime`. A controller target takes none: it waits until no session is busy. */
|
|
53
|
+
deployWhen?: TFleetDeployWhen;
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
/** A SHA-256 digest as `sha256:<64 hex digits>`. */
|
|
57
|
+
export type TSha256Digest = `sha256:${string}`;
|
|
58
|
+
/**
|
|
59
|
+
* What runs, as an artifact a vulnerability can be matched against: a lockfile at a commit (its git blob id), an OCI
|
|
60
|
+
* image (its index digest), the dependency tree a process reports it has installed, or a self-contained binary.
|
|
61
|
+
*/
|
|
62
|
+
export type TSecuritySubject =
|
|
63
|
+
| { kind: 'lockfile'; repo: string; sha: string; path: string; blob: string }
|
|
64
|
+
| { kind: 'image'; digest: TSha256Digest }
|
|
65
|
+
| { kind: 'installed'; targetId: string; treeDigest: TSha256Digest }
|
|
66
|
+
| { kind: 'binary'; sha256: TSha256Digest };
|
|
67
|
+
/** One artifact a target runs, and on how many replicas when it runs on several. */
|
|
68
|
+
export interface IFleetDeployArtifact {
|
|
69
|
+
subject: TSecuritySubject;
|
|
70
|
+
replicas?: number;
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
/**
|
|
74
|
+
* What a target ran, recorded only when its probe answered another version, commit or artifact set than the row recorded last. Rows are
|
|
75
|
+
* ordered by their per-target number, never by time: a clock that steps back cannot reorder them, and two controllers
|
|
76
|
+
* on one database cannot record one change twice.
|
|
77
|
+
*/
|
|
78
|
+
export interface IFleetDeployObservation {
|
|
79
|
+
/** `<targetId>:<seq>`. */
|
|
80
|
+
id: string;
|
|
81
|
+
targetId: string;
|
|
82
|
+
/** The target's observation number, 1 for its first; unique per target. */
|
|
83
|
+
seq: number;
|
|
84
|
+
/** The repository the target runs, `org/name`, as it was when the row was recorded. */
|
|
85
|
+
repo: string;
|
|
86
|
+
version: string;
|
|
87
|
+
sha?: string;
|
|
88
|
+
/** When the probe first answered this version (the controller's own start time for the controller); for display only. */
|
|
89
|
+
observedAt: string;
|
|
90
|
+
/** The version of the row before; a newer one means a rollback. */
|
|
91
|
+
previousVersion?: string;
|
|
92
|
+
/**
|
|
93
|
+
* What runs, as artifacts: the controller reports the dependency tree it has installed; a target whose probe cannot
|
|
94
|
+
* say reports none. A rebuild under the same version, a reinstall that resolved other dependencies or a rollout that
|
|
95
|
+
* runs two images is a new row.
|
|
96
|
+
*/
|
|
97
|
+
artifacts: IFleetDeployArtifact[];
|
|
98
|
+
}
|
package/ts_interfaces/fleet.ts
CHANGED
|
@@ -72,6 +72,8 @@ export interface IFleetConfiguration {
|
|
|
72
72
|
workerProfiles?: import('./fleetworkers.js').IFleetWorkerProfile[];
|
|
73
73
|
driver?: IFleetDriverConfiguration;
|
|
74
74
|
boardPump?: IFleetBoardPumpConfiguration;
|
|
75
|
+
/** The deploy targets whose running version AGL observes; the AGL controller is built in and needs no entry. */
|
|
76
|
+
deployTargets?: import('./deployments.js').IFleetDeployTarget[];
|
|
75
77
|
}
|
|
76
78
|
/** One fleet operation's configuration and the repositories discovered for it. */
|
|
77
79
|
export interface IFleetScope extends IFleetConfiguration {
|
package/ts_interfaces/index.ts
CHANGED
|
@@ -20,6 +20,7 @@ export * from './tickets.js';
|
|
|
20
20
|
export * from './requests.tickets.js';
|
|
21
21
|
export * from './fleet.js';
|
|
22
22
|
export * from './requests.fleet.js';
|
|
23
|
+
export * from './deployments.js';
|
|
23
24
|
|
|
24
25
|
export * from './fleetworkers.js';
|
|
25
26
|
export * from './requests.fleetworkers.js';
|
|
@@ -5,7 +5,7 @@ import type {
|
|
|
5
5
|
TControllerBrowserPaintAvailability,
|
|
6
6
|
TControllerBrowserPaintTermination,
|
|
7
7
|
} from './browserpaint.js';
|
|
8
|
-
export const controllerProtocolVersion =
|
|
8
|
+
export const controllerProtocolVersion = 50 as const;
|
|
9
9
|
export const controllerUpgradeManagementVersion = 2 as const;
|
|
10
10
|
export const controllerPackageName = 'agl' as const;
|
|
11
11
|
/** The systemd user unit `agl service install` writes; a controller it runs reports it in its status. */
|
|
@@ -235,6 +235,22 @@ export interface IReq_ControllerAccountsSpendLimit extends plugins.typedrequestI
|
|
|
235
235
|
response: { answer: TControllerAccountsAnswer<TControllerAccount> };
|
|
236
236
|
}
|
|
237
237
|
|
|
238
|
+
/**
|
|
239
|
+
* Sets whether an API key account may serve Claude Code (AGL-1146): `false` keeps AGL's inference proxy from placing a
|
|
240
|
+
* Claude Code request on the key, while its other clients still use it. `expectedRevision` is the revision the view
|
|
241
|
+
* showed, so a change of an account that changed meanwhile is refused as `account_changed`, and an account on a
|
|
242
|
+
* sign-in, which always serves Claude Code, as `invalid_input`, both by the service. The answer arrives only once the
|
|
243
|
+
* projection shows the result.
|
|
244
|
+
*/
|
|
245
|
+
export interface IReq_ControllerAccountsClaudeCode extends plugins.typedrequestInterfaces.implementsTR<
|
|
246
|
+
plugins.typedrequestInterfaces.ITypedRequest,
|
|
247
|
+
IReq_ControllerAccountsClaudeCode
|
|
248
|
+
> {
|
|
249
|
+
method: 'controller.accounts.claudecode';
|
|
250
|
+
request: { accountId: string; expectedRevision: number; claudeCode: boolean };
|
|
251
|
+
response: { answer: TControllerAccountsAnswer<TControllerAccount> };
|
|
252
|
+
}
|
|
253
|
+
|
|
238
254
|
/** Duration validation shared with the authority; no implicit duration is supplied. */
|
|
239
255
|
export const isControllerReserveLiftHours = plugins.authswitchAuthority.isAuthSwitchReserveLiftHours;
|
|
240
256
|
|
|
@@ -31,6 +31,7 @@ import type {
|
|
|
31
31
|
IReq_ControllerAccountsReserveLift,
|
|
32
32
|
IReq_ControllerAccountsApiKeyAdd,
|
|
33
33
|
IReq_ControllerAccountsSpendLimit,
|
|
34
|
+
IReq_ControllerAccountsClaudeCode,
|
|
34
35
|
IReq_ControllerAccountsSnapshot,
|
|
35
36
|
IReq_ControllerAccountsUsageGet,
|
|
36
37
|
IReq_ControllerAccountsUsageRecheck,
|
|
@@ -399,6 +400,7 @@ export type TControllerRequest =
|
|
|
399
400
|
| IReq_ControllerAccountsReserveLift
|
|
400
401
|
| IReq_ControllerAccountsApiKeyAdd
|
|
401
402
|
| IReq_ControllerAccountsSpendLimit
|
|
403
|
+
| IReq_ControllerAccountsClaudeCode
|
|
402
404
|
| IReq_ControllerAccountsRemove
|
|
403
405
|
| IReq_ControllerAccountsAdd
|
|
404
406
|
| IReq_ControllerAccountsReauth
|