agl 42.0.0 → 42.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/changelog.md +44 -0
- package/dist_serve/bundle.js +2520 -2158
- 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.d.ts +2 -0
- package/dist_ts/classes.authstore.js +58 -17
- package/dist_ts/classes.cli.js +19 -49
- package/dist_ts/classes.configurationauthority.js +2 -2
- package/dist_ts/classes.controller.d.ts +71 -2
- package/dist_ts/classes.controller.js +500 -113
- package/dist_ts/classes.controllerdevices.d.ts +128 -0
- package/dist_ts/classes.controllerdevices.js +472 -0
- 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.sessionfeed.d.ts +10 -1
- package/dist_ts/classes.sessionfeed.js +12 -2
- 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/classes.validation.d.ts +2 -0
- package/dist_ts/classes.validation.js +2 -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.deviceapi.d.ts +28 -0
- package/dist_ts/functions.deviceapi.js +246 -0
- package/dist_ts/functions.deviceproof.d.ts +33 -0
- package/dist_ts/functions.deviceproof.js +93 -0
- 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.remotecli.d.ts +1 -1
- package/dist_ts/functions.remotecli.js +12 -7
- 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 +7 -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 +6 -0
- package/dist_ts_authswitch/classes.authoritybroker.js +31 -4
- 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/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/devices.d.ts +331 -0
- package/dist_ts_interfaces/devices.js +34 -0
- package/dist_ts_interfaces/fleet.d.ts +2 -0
- package/dist_ts_interfaces/index.d.ts +3 -0
- package/dist_ts_interfaces/index.js +4 -1
- package/dist_ts_interfaces/interfaces.d.ts +4 -2
- package/dist_ts_interfaces/interfaces.js +3 -2
- package/dist_ts_interfaces/mcprequests.d.ts +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 +3 -2
- package/dist_ts_interfaces/requests.devices.d.ts +89 -0
- package/dist_ts_interfaces/requests.devices.js +2 -0
- 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 +6 -0
- package/package.json +5 -5
- package/readme.md +84 -16
- 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 +54 -14
- package/ts/classes.cli.ts +17 -54
- package/ts/classes.configurationauthority.ts +1 -1
- package/ts/classes.controller.ts +697 -167
- package/ts/classes.controllerdevices.ts +469 -0
- 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.sessionfeed.ts +13 -1
- 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/classes.validation.ts +1 -1
- 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.deviceapi.ts +295 -0
- package/ts/functions.deviceproof.ts +118 -0
- package/ts/functions.fleetworkercli.ts +26 -8
- package/ts/functions.inferencecli.ts +3 -1
- package/ts/functions.remotecli.ts +11 -5
- package/ts/functions.ticketvalidation.ts +48 -13
- package/ts/interfaces.auth.ts +6 -0
- package/ts_authswitch/authority-contract.ts +18 -0
- package/ts_authswitch/classes.authoritybroker.ts +29 -3
- 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/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/devices.schema.json +890 -0
- package/ts_interfaces/devices.ts +392 -0
- package/ts_interfaces/fleet.ts +2 -0
- package/ts_interfaces/index.ts +3 -0
- package/ts_interfaces/interfaces.ts +4 -1
- package/ts_interfaces/mcprequests.ts +1 -1
- package/ts_interfaces/requests.accounts.ts +16 -0
- package/ts_interfaces/requests.devices.ts +95 -0
- package/ts_interfaces/requests.ts +12 -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/classes.controllersocketclient.ts +27 -0
- package/ts_web/elements.accounts.ts +44 -0
- package/ts_web/elements.devices.ts +752 -0
- package/ts_web/elements.harnesscontrollerapp.ts +18 -1
- package/ts_web/elements.ticketboard.ts +15 -4
|
@@ -1,5 +1,8 @@
|
|
|
1
1
|
import * as plugins from './plugins.js';
|
|
2
|
-
import {
|
|
2
|
+
import {
|
|
3
|
+
ticketAutoLabels, ticketColumns, ticketHistoryPage, type TTicketFleetEvent, type TTicketLink, type TTicketOperation, type TTicketRequest,
|
|
4
|
+
} from '../ts_interfaces/tickets.js';
|
|
5
|
+
import { fleetDeployTargetIdPattern } from '../ts_interfaces/deployments.js';
|
|
3
6
|
|
|
4
7
|
const text = (maximumArg: number) => plugins.z.string().max(maximumArg);
|
|
5
8
|
const identifier = text(1024).min(1).refine((valueArg) => !/[\x00-\x1f\x7f]/u.test(valueArg));
|
|
@@ -11,11 +14,37 @@ const person = plugins.z.object({
|
|
|
11
14
|
sessionId: identifier.optional(),
|
|
12
15
|
}).strict();
|
|
13
16
|
const actor = person.extend({ role: plugins.z.enum(['owner', 'driver', 'worker']) }).strict();
|
|
17
|
+
const branchLink = plugins.z.object({ kind: plugins.z.literal('branch'), repo: identifier, branch: identifier, sha }).strict();
|
|
18
|
+
const commitLink = plugins.z.object({ kind: plugins.z.literal('commit'), repo: identifier, sha }).strict();
|
|
14
19
|
const link = plugins.z.discriminatedUnion('kind', [
|
|
15
|
-
|
|
16
|
-
plugins.z.object({ kind: plugins.z.literal('commit'), repo: identifier, sha }).strict(),
|
|
20
|
+
branchLink, commitLink,
|
|
17
21
|
plugins.z.object({ kind: plugins.z.literal('release'), package: identifier, version: identifier }).strict(),
|
|
18
22
|
]);
|
|
23
|
+
/**
|
|
24
|
+
* Every link a stored ticket may hold: what callers link, plus the repository and commit a fleet release adds to its
|
|
25
|
+
* release link and the `affects` link (found in). Readers accept these one release before any writer sends them.
|
|
26
|
+
*/
|
|
27
|
+
const storedLink = plugins.z.discriminatedUnion('kind', [
|
|
28
|
+
branchLink, commitLink,
|
|
29
|
+
plugins.z.object({ kind: plugins.z.literal('release'), version: identifier, package: identifier.optional(),
|
|
30
|
+
repo: identifier.optional(), sha: sha.optional() }).strict(),
|
|
31
|
+
plugins.z.object({ kind: plugins.z.literal('affects'), repo: identifier, version: identifier }).strict(),
|
|
32
|
+
]).refine((linkArg) => linkArg.kind !== 'release' || linkArg.package !== undefined || linkArg.repo !== undefined,
|
|
33
|
+
'A release link names its repository or its package.');
|
|
34
|
+
/** The columns a stored ticket may name. */
|
|
35
|
+
const storedColumn = plugins.z.enum(ticketColumns);
|
|
36
|
+
/** The columns a request may move a ticket to; `closed` is read one release before anything moves a ticket there. */
|
|
37
|
+
const requestColumn = plugins.z.enum(ticketColumns).exclude(['closed']);
|
|
38
|
+
const releasePlan = plugins.z.object({ repo: identifier, version: identifier.optional() }).strict();
|
|
39
|
+
const deployTargetId = plugins.z.string().regex(fleetDeployTargetIdPattern);
|
|
40
|
+
const questionId = plugins.z.string().regex(/^Q[1-9][0-9]*$/u);
|
|
41
|
+
/** A stored maintenance window; read one release before anything writes one. */
|
|
42
|
+
const maintenanceWindow = plugins.z.object({ from: plugins.z.iso.datetime(), to: plugins.z.iso.datetime(),
|
|
43
|
+
targets: plugins.z.array(deployTargetId).min(1).max(64).refine((valueArg) => new Set(valueArg).size === valueArg.length),
|
|
44
|
+
questionId: questionId.optional() }).strict()
|
|
45
|
+
.refine((valueArg) => Date.parse(valueArg.to) > Date.parse(valueArg.from), 'A maintenance window ends after it starts.');
|
|
46
|
+
/** A stored deploy plan; read one release before anything writes one. */
|
|
47
|
+
const deployPlan = plugins.z.object({ target: deployTargetId, version: identifier, questionId }).strict();
|
|
19
48
|
const attachment = plugins.z.object({ name: text(200).min(1),
|
|
20
49
|
url: plugins.z.url().max(4096).refine((valueArg) => /^https?:\/\//iu.test(valueArg), 'Attachments require HTTP or HTTPS URLs.') }).strict();
|
|
21
50
|
const labels = plugins.z.array(text(100).min(1)).max(100).refine((valueArg) => new Set(valueArg).size === valueArg.length);
|
|
@@ -25,7 +54,6 @@ const referenceContent = plugins.z.array(plugins.z.discriminatedUnion('type', [
|
|
|
25
54
|
plugins.z.object({ type: plugins.z.literal('text'), text: text(64 * 1024) }).strict(),
|
|
26
55
|
plugins.z.object({ type: plugins.z.literal('reference'), id: identifier, label: text(200).min(1) }).strict(),
|
|
27
56
|
])).min(1).max(100).refine((valueArg) => JSON.stringify(valueArg).length <= 64 * 1024);
|
|
28
|
-
const questionId = plugins.z.string().regex(/^Q[1-9][0-9]*$/u);
|
|
29
57
|
const optionId = plugins.z.string().regex(/^[1-9][0-9]*$/u);
|
|
30
58
|
const questionOption = plugins.z.object({ label: text(200).trim().min(1), description: text(1000).optional() }).strict();
|
|
31
59
|
const filters = plugins.z.object({ mine: plugins.z.boolean().optional(), project: identifier.optional(),
|
|
@@ -44,11 +72,11 @@ export const ticketInputSchemas = {
|
|
|
44
72
|
'commentId reads one comment and excludes before and limit.'),
|
|
45
73
|
comments: plugins.z.object({ ticketId }).strict(),
|
|
46
74
|
create: plugins.z.object({ project: identifier, kind: kind.optional(), title: text(200).trim().min(1),
|
|
47
|
-
description: text(64 * 1024).optional(), columnId:
|
|
75
|
+
description: text(64 * 1024).optional(), columnId: requestColumn.optional(), parentId: ticketId.optional(),
|
|
48
76
|
priority: priority.optional(), assignee: person.optional(), labels: labels.optional(), sourceText: text(64 * 1024).optional(),
|
|
49
77
|
attachments: plugins.z.array(attachment).max(100).optional() }).strict(),
|
|
50
78
|
update: plugins.z.object({ ticketId, expectedRevision: plugins.z.number().int().nonnegative(), changes }).strict(),
|
|
51
|
-
move: plugins.z.object({ ticketId, columnId:
|
|
79
|
+
move: plugins.z.object({ ticketId, columnId: requestColumn, beforeTicketId: ticketId.optional() }).strict(),
|
|
52
80
|
comment: plugins.z.object({ ticketId, body: plugins.z.union([text(64 * 1024).min(1), referenceContent]) }).strict(),
|
|
53
81
|
link: plugins.z.object({ ticketId, link }).strict(),
|
|
54
82
|
ask: plugins.z.object({ ticketId, question: text(16 * 1024).trim().min(1),
|
|
@@ -69,15 +97,22 @@ const fleetEventBase = { ticketKey: ticketId,
|
|
|
69
97
|
export const ticketFleetEventSchema = plugins.z.discriminatedUnion('kind', [
|
|
70
98
|
plugins.z.object({ ...fleetEventBase, kind: plugins.z.literal('landed'), repo: identifier,
|
|
71
99
|
branch: identifier, sha, body: ticketInputSchemas.comment.shape.body.optional() }).strict(),
|
|
72
|
-
plugins.z.object({ ...fleetEventBase, kind: plugins.z.literal('released'), package: identifier,
|
|
73
|
-
|
|
100
|
+
plugins.z.object({ ...fleetEventBase, kind: plugins.z.literal('released'), version: identifier, package: identifier.optional(),
|
|
101
|
+
repo: identifier.optional(), sha: sha.optional(), body: ticketInputSchemas.comment.shape.body.optional() }).strict(),
|
|
74
102
|
plugins.z.object({ ...fleetEventBase, kind: plugins.z.literal('comment'), body: ticketInputSchemas.comment.shape.body }).strict(),
|
|
75
|
-
])
|
|
103
|
+
]).refine((eventArg) => eventArg.kind !== 'released' || eventArg.package !== undefined || eventArg.repo !== undefined,
|
|
104
|
+
'A released event names its repository or its package.');
|
|
105
|
+
/** The release link a `released` event writes: its version, and the repository, commit and package it names. */
|
|
106
|
+
export const ticketReleaseLink = (eventArg: Extract<TTicketFleetEvent, { kind: 'released' }>): Extract<TTicketLink, { kind: 'release' }> => ({
|
|
107
|
+
kind: 'release', version: eventArg.version, ...(eventArg.package === undefined ? {} : { package: eventArg.package }),
|
|
108
|
+
...(eventArg.repo === undefined ? {} : { repo: eventArg.repo }), ...(eventArg.sha === undefined ? {} : { sha: eventArg.sha }),
|
|
109
|
+
});
|
|
76
110
|
export const ticketSchema = plugins.z.object({
|
|
77
111
|
id: ticketId, key: ticketId, revision: plugins.z.number().int().nonnegative().optional(),
|
|
78
112
|
project: identifier, kind, title: text(200).min(1), description: text(64 * 1024),
|
|
79
|
-
parentId: ticketId.optional(), columnId:
|
|
80
|
-
priority, assignee: person.optional(), labels, links: plugins.z.array(
|
|
113
|
+
parentId: ticketId.optional(), columnId: storedColumn, order: plugins.z.number().int().nonnegative(),
|
|
114
|
+
priority, assignee: person.optional(), labels, links: plugins.z.array(storedLink).max(100), releasePlan: releasePlan.optional(),
|
|
115
|
+
maintenanceWindow: maintenanceWindow.optional(), deployPlan: deployPlan.optional(),
|
|
81
116
|
source: plugins.z.object({ kind: plugins.z.enum(['owner_words', 'driver', 'worker']), text: text(64 * 1024),
|
|
82
117
|
actor, attachments: plugins.z.array(attachment).max(100) }).strict(),
|
|
83
118
|
createdBy: actor, updatedBy: actor, createdAt: plugins.z.iso.datetime(), updatedAt: plugins.z.iso.datetime(),
|
|
@@ -85,7 +120,7 @@ export const ticketSchema = plugins.z.object({
|
|
|
85
120
|
export const ticketCommentSchema = plugins.z.object({ id: identifier, ticketId, author: actor,
|
|
86
121
|
createdAt: plugins.z.iso.datetime(), body: referenceContent }).strict();
|
|
87
122
|
export const ticketActivitySchema = plugins.z.object({ id: identifier, ticketId, actor, createdAt: plugins.z.iso.datetime(),
|
|
88
|
-
action: plugins.z.enum(['created', 'updated', 'moved', 'reordered', 'commented', 'linked', 'asked', 'answered']),
|
|
123
|
+
action: plugins.z.enum(['created', 'updated', 'moved', 'reordered', 'commented', 'linked', 'unlinked', 'asked', 'answered']),
|
|
89
124
|
changes: plugins.z.record(plugins.z.string(), plugins.z.object({ before: plugins.z.unknown().optional(), after: plugins.z.unknown().optional() }).strict()) }).strict();
|
|
90
125
|
export const ticketQuestionSchema = plugins.z.object({ id: questionId, ticketId, kind: plugins.z.literal('question'),
|
|
91
126
|
question: text(16 * 1024).min(1), options: plugins.z.array(questionOption.extend({ id: optionId }).strict()).max(20),
|
|
@@ -118,7 +153,7 @@ export const assertTicketResponse = (methodArg: string, valueArg: unknown): void
|
|
|
118
153
|
list: plugins.z.object({ tickets: plugins.z.array(ticket) }).strict(),
|
|
119
154
|
search: plugins.z.object({ tickets: plugins.z.array(ticket) }).strict(),
|
|
120
155
|
board: plugins.z.object({ revision: plugins.z.number().int().nonnegative(), columns: plugins.z.array(plugins.z.object({
|
|
121
|
-
id:
|
|
156
|
+
id: storedColumn, title: plugins.z.string(), done: plugins.z.boolean().optional() }).strict()), tickets: plugins.z.array(ticket),
|
|
122
157
|
viewer: person }).strict(),
|
|
123
158
|
get: plugins.z.object({ ticket, comments: plugins.z.array(ticketCommentSchema), activity: plugins.z.array(ticketActivitySchema),
|
|
124
159
|
questions: plugins.z.array(ticketQuestionSchema), historyBefore: identifier.optional() }).strict(),
|
package/ts/interfaces.auth.ts
CHANGED
|
@@ -75,6 +75,7 @@ export const controllerAuditEventTypes = [
|
|
|
75
75
|
'accounts.reserve.lift',
|
|
76
76
|
'accounts.apikey.add',
|
|
77
77
|
'accounts.spendlimit',
|
|
78
|
+
'accounts.claudecode',
|
|
78
79
|
'accounts.remove',
|
|
79
80
|
'accounts.add',
|
|
80
81
|
'accounts.reauth',
|
|
@@ -145,6 +146,11 @@ export const controllerAuditEventTypes = [
|
|
|
145
146
|
'remote.set',
|
|
146
147
|
'remote.unset',
|
|
147
148
|
'remote.secret.import',
|
|
149
|
+
// Paired devices (AGL-824): the owner makes a pairing code and revokes a device; a device pairs and authenticates.
|
|
150
|
+
'device.pairing.begin',
|
|
151
|
+
'device.pair',
|
|
152
|
+
'device.auth',
|
|
153
|
+
'device.revoke',
|
|
148
154
|
] as const;
|
|
149
155
|
export type TControllerAuditEventType = (typeof controllerAuditEventTypes)[number];
|
|
150
156
|
export type TControllerAuditOutcome = 'attempted' | 'succeeded' | 'denied' | 'failed';
|
|
@@ -282,6 +282,13 @@ export interface IAuthSwitchAccount {
|
|
|
282
282
|
* account on a sign-in, and for an Anthropic key the accounts service held before it kept hints.
|
|
283
283
|
*/
|
|
284
284
|
keyHint: string | null;
|
|
285
|
+
/**
|
|
286
|
+
* Whether the account may serve Claude Code (AGL-1146): `false` keeps AGL's inference proxy from placing a Claude Code
|
|
287
|
+
* request on the key -- for a key whose credit its provider grants for API use other than Claude Code -- while every
|
|
288
|
+
* other client of the pool still uses it. Always `true` for an account on a sign-in, and for a key unless its owner
|
|
289
|
+
* set it otherwise.
|
|
290
|
+
*/
|
|
291
|
+
claudeCode: boolean;
|
|
285
292
|
removed: boolean;
|
|
286
293
|
revision: number;
|
|
287
294
|
statusObservedAt: string;
|
|
@@ -1485,6 +1492,17 @@ export interface IReq_AuthSwitchSetAccountSpendLimit extends ITypedRequest {
|
|
|
1485
1492
|
response: { account: IAuthSwitchAccount };
|
|
1486
1493
|
}
|
|
1487
1494
|
|
|
1495
|
+
/**
|
|
1496
|
+
* Sets whether an API key account may serve Claude Code (`claudeCode`). Refused (`invalid_input`) for an account on a
|
|
1497
|
+
* sign-in, which always may; a change of an account that changed since `expectedRevision` is refused as
|
|
1498
|
+
* `account_changed`. Setting the value the account already has changes nothing and keeps its revision.
|
|
1499
|
+
*/
|
|
1500
|
+
export interface IReq_AuthSwitchSetAccountClaudeCode extends ITypedRequest {
|
|
1501
|
+
method: 'authswitch.authority.claudecode';
|
|
1502
|
+
request: { accountId: string; expectedRevision: number; claudeCode: boolean };
|
|
1503
|
+
response: { account: IAuthSwitchAccount };
|
|
1504
|
+
}
|
|
1505
|
+
|
|
1488
1506
|
/**
|
|
1489
1507
|
* Lift only the saved reserve for whole hours 1..24, using the authority clock and expected revision. Refused
|
|
1490
1508
|
* (`invalid_input`) for an API key account, which has a spend limit instead of a reserve.
|
|
@@ -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
|
|
|
@@ -675,7 +675,7 @@ export class AuthSwitchAuthorityBroker {
|
|
|
675
675
|
revision: existing.revision + 1, statusObservedAt: now, updateId: commitId }
|
|
676
676
|
: { id: identity.id, providerId: 'openai', issuer: 'openai', subject: identity.subject,
|
|
677
677
|
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,
|
|
678
|
+
email: identity.email, plan: identity.plan, primaryGrantId: grantId, maxUsagePercent: null, reserveLiftUntil: null, lapsesAt: null, spendLimitMicroUsd: null, keyHint: null, claudeCode: true, removed: false,
|
|
679
679
|
revision: 1, statusObservedAt: now, updateId: commitId };
|
|
680
680
|
const grant: IStoredAuthorityGrant = oldGrant
|
|
681
681
|
? { ...oldGrant, state: 'ready', owner: 'daemon', ciphertext,
|
|
@@ -870,6 +870,32 @@ export class AuthSwitchAuthorityBroker {
|
|
|
870
870
|
return publicAccount(updated.account);
|
|
871
871
|
}
|
|
872
872
|
|
|
873
|
+
/**
|
|
874
|
+
* Sets whether an API key account may serve Claude Code (`IAuthSwitchAccount.claudeCode`), as `setAccountSpendLimit`
|
|
875
|
+
* changes its limit. The proxy applies it from the next request on: a Claude Code session on a key that may not serve
|
|
876
|
+
* it moves to another account then. The value the key already has changes nothing.
|
|
877
|
+
*/
|
|
878
|
+
public async setAccountClaudeCode(accountId: string, expectedRevision: number, claudeCode: boolean): Promise<IAuthSwitchAccount> {
|
|
879
|
+
if (!isId(accountId) || !validRevision(expectedRevision) || typeof claudeCode !== 'boolean') {
|
|
880
|
+
throw new Error('Invalid account change.');
|
|
881
|
+
}
|
|
882
|
+
const current = await this.database.readAccount(accountId);
|
|
883
|
+
if (current && !current.removed && current.revision === expectedRevision && isApiKeyAccount(current)
|
|
884
|
+
&& current.claudeCode === claudeCode) return publicAccount(current);
|
|
885
|
+
const updateId = plugins.crypto.randomUUID();
|
|
886
|
+
const updated = await this.database.changeAccount(updateId, accountId, account => {
|
|
887
|
+
if (!account || account.removed || account.revision !== expectedRevision) throw new AuthSwitchRefusal('account_changed', 'Account changed; refresh before editing.');
|
|
888
|
+
if (!isApiKeyAccount(account)) {
|
|
889
|
+
throw new AuthSwitchRefusal('invalid_input', 'A sign-in always serves Claude Code. Only an API key account can be '
|
|
890
|
+
+ 'kept from it.');
|
|
891
|
+
}
|
|
892
|
+
return { ...account, claudeCode, revision: account.revision + 1, updateId,
|
|
893
|
+
statusObservedAt: new Date(this.now()).toISOString() };
|
|
894
|
+
});
|
|
895
|
+
this.publish();
|
|
896
|
+
return publicAccount(updated.account);
|
|
897
|
+
}
|
|
898
|
+
|
|
873
899
|
/**
|
|
874
900
|
* Sets or clears the date an account's subscription ends, as `setAccountMaxUsage` changes its threshold. The date is
|
|
875
901
|
* stored in its ISO 8601 UTC form; a past one is kept as given and means the account lapsed already.
|
|
@@ -1379,7 +1405,7 @@ export class AuthSwitchAuthorityBroker {
|
|
|
1379
1405
|
: { id: accountId, providerId, issuer: providerId, subject, workspaceId: apiKeyWorkspace,
|
|
1380
1406
|
label: label ?? kind.label, email: null, plan: null, primaryGrantId: grantId, maxUsagePercent: null,
|
|
1381
1407
|
reserveLiftUntil: null, lapsesAt: null, spendLimitMicroUsd: spendLimitMicroUsd ?? null, keyHint,
|
|
1382
|
-
removed: false, revision: 1, statusObservedAt: now, updateId };
|
|
1408
|
+
claudeCode: true, removed: false, revision: 1, statusObservedAt: now, updateId };
|
|
1383
1409
|
const grant: IStoredAuthorityGrant = oldGrant
|
|
1384
1410
|
? { ...oldGrant, state: 'ready', owner: 'daemon', ciphertext, grantGeneration: oldGrant.grantGeneration + 1,
|
|
1385
1411
|
authorizationGeneration: oldGrant.authorizationGeneration + 1, revision: oldGrant.revision + 1,
|
|
@@ -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;
|
|
@@ -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
|
+
}
|