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.
Files changed (168) hide show
  1. package/changelog.md +44 -0
  2. package/dist_serve/bundle.js +2520 -2158
  3. package/dist_serve/bundle.js.map +2 -2
  4. package/dist_ts/00_commitinfo_data.js +1 -1
  5. package/dist_ts/aglapi/aglapisurface.document.js +124 -10
  6. package/dist_ts/classes.accountsactions.d.ts +3 -1
  7. package/dist_ts/classes.accountsactions.js +16 -1
  8. package/dist_ts/classes.authstore.d.ts +2 -0
  9. package/dist_ts/classes.authstore.js +58 -17
  10. package/dist_ts/classes.cli.js +19 -49
  11. package/dist_ts/classes.configurationauthority.js +2 -2
  12. package/dist_ts/classes.controller.d.ts +71 -2
  13. package/dist_ts/classes.controller.js +500 -113
  14. package/dist_ts/classes.controllerdevices.d.ts +128 -0
  15. package/dist_ts/classes.controllerdevices.js +472 -0
  16. package/dist_ts/classes.controllerservice.d.ts +20 -2
  17. package/dist_ts/classes.controllerservice.js +42 -6
  18. package/dist_ts/classes.flexservice.js +8 -3
  19. package/dist_ts/classes.inferencegateway.d.ts +30 -2
  20. package/dist_ts/classes.inferencegateway.js +115 -20
  21. package/dist_ts/classes.inferencerouter.d.ts +16 -0
  22. package/dist_ts/classes.inferencerouter.js +5 -3
  23. package/dist_ts/classes.inferenceservice.js +7 -3
  24. package/dist_ts/classes.sessionfeed.d.ts +10 -1
  25. package/dist_ts/classes.sessionfeed.js +12 -2
  26. package/dist_ts/classes.ticketmodels.js +4 -3
  27. package/dist_ts/classes.ticketnotifier.js +9 -2
  28. package/dist_ts/classes.ticketstore.js +9 -5
  29. package/dist_ts/classes.upgradecoordinator.d.ts +6 -1
  30. package/dist_ts/classes.upgradecoordinator.js +9 -2
  31. package/dist_ts/classes.upgradetransaction.d.ts +27 -1
  32. package/dist_ts/classes.upgradetransaction.js +92 -2
  33. package/dist_ts/classes.validation.d.ts +2 -0
  34. package/dist_ts/classes.validation.js +2 -2
  35. package/dist_ts/configuration/functions.master.d.ts +7 -2
  36. package/dist_ts/configuration/functions.master.js +7 -4
  37. package/dist_ts/driver/classes.drivereventrelay.d.ts +1 -1
  38. package/dist_ts/driver/classes.drivereventrelay.js +3 -3
  39. package/dist_ts/fleet/classes.boardpump.d.ts +1 -1
  40. package/dist_ts/fleet/classes.boardpump.js +7 -4
  41. package/dist_ts/fleet/classes.claudeworkers.d.ts +6 -0
  42. package/dist_ts/fleet/classes.claudeworkers.js +17 -7
  43. package/dist_ts/fleet/classes.deploymodels.d.ts +19 -0
  44. package/dist_ts/fleet/classes.deploymodels.js +140 -0
  45. package/dist_ts/fleet/functions.validation.d.ts +8 -1
  46. package/dist_ts/fleet/functions.validation.js +65 -3
  47. package/dist_ts/fleet/interfaces.workers.d.ts +6 -0
  48. package/dist_ts/fleet/interfaces.workers.js +65 -2
  49. package/dist_ts/functions.deviceapi.d.ts +28 -0
  50. package/dist_ts/functions.deviceapi.js +246 -0
  51. package/dist_ts/functions.deviceproof.d.ts +33 -0
  52. package/dist_ts/functions.deviceproof.js +93 -0
  53. package/dist_ts/functions.fleetworkercli.d.ts +16 -3
  54. package/dist_ts/functions.fleetworkercli.js +21 -7
  55. package/dist_ts/functions.inferencecli.js +4 -2
  56. package/dist_ts/functions.mcptickettools.d.ts +1 -0
  57. package/dist_ts/functions.remotecli.d.ts +1 -1
  58. package/dist_ts/functions.remotecli.js +12 -7
  59. package/dist_ts/functions.ticketvalidation.d.ts +36 -3
  60. package/dist_ts/functions.ticketvalidation.js +45 -14
  61. package/dist_ts/interfaces.auth.d.ts +1 -1
  62. package/dist_ts/interfaces.auth.js +7 -1
  63. package/dist_ts_authswitch/authority-contract.d.ts +23 -0
  64. package/dist_ts_authswitch/authority-contract.js +1 -1
  65. package/dist_ts_authswitch/classes.authoritybroker.d.ts +6 -0
  66. package/dist_ts_authswitch/classes.authoritybroker.js +31 -4
  67. package/dist_ts_authswitch/classes.authoritycli.d.ts +1 -0
  68. package/dist_ts_authswitch/classes.authoritycli.js +26 -1
  69. package/dist_ts_authswitch/classes.authorityclient.d.ts +3 -1
  70. package/dist_ts_authswitch/classes.authorityclient.js +10 -4
  71. package/dist_ts_authswitch/classes.authoritydaemon.js +7 -1
  72. package/dist_ts_authswitch/classes.authorityimport.js +2 -2
  73. package/dist_ts_authswitch/classes.authoritymodels.d.ts +3 -0
  74. package/dist_ts_authswitch/classes.authoritymodels.js +10 -3
  75. package/dist_ts_authswitch/testsupport.js +4 -4
  76. package/dist_ts_authswitch/ts_migration/0012_account_claude_code.d.ts +11 -0
  77. package/dist_ts_authswitch/ts_migration/0012_account_claude_code.js +18 -0
  78. package/dist_ts_authswitch/ts_migration/index.js +3 -1
  79. package/dist_ts_interfaces/deployments.d.ts +104 -0
  80. package/dist_ts_interfaces/deployments.js +8 -0
  81. package/dist_ts_interfaces/devices.d.ts +331 -0
  82. package/dist_ts_interfaces/devices.js +34 -0
  83. package/dist_ts_interfaces/fleet.d.ts +2 -0
  84. package/dist_ts_interfaces/index.d.ts +3 -0
  85. package/dist_ts_interfaces/index.js +4 -1
  86. package/dist_ts_interfaces/interfaces.d.ts +4 -2
  87. package/dist_ts_interfaces/interfaces.js +3 -2
  88. package/dist_ts_interfaces/mcprequests.d.ts +1 -1
  89. package/dist_ts_interfaces/requests.accounts.d.ts +18 -0
  90. package/dist_ts_interfaces/requests.accounts.js +1 -1
  91. package/dist_ts_interfaces/requests.d.ts +3 -2
  92. package/dist_ts_interfaces/requests.devices.d.ts +89 -0
  93. package/dist_ts_interfaces/requests.devices.js +2 -0
  94. package/dist_ts_interfaces/requests.js +1 -1
  95. package/dist_ts_interfaces/tickets.d.ts +53 -4
  96. package/dist_ts_interfaces/tickets.js +6 -2
  97. package/dist_ts_migration/index.d.ts +1 -0
  98. package/dist_ts_migration/index.js +2 -1
  99. package/dist_ts_migration/v41_ticketmigrationmarkers.d.ts +19 -0
  100. package/dist_ts_migration/v41_ticketmigrationmarkers.js +85 -0
  101. package/docs/authswitch.md +6 -0
  102. package/package.json +5 -5
  103. package/readme.md +84 -16
  104. package/ts/00_commitinfo_data.ts +1 -1
  105. package/ts/aglapi/aglapisurface.document.ts +123 -9
  106. package/ts/classes.accountsactions.ts +24 -0
  107. package/ts/classes.authstore.ts +54 -14
  108. package/ts/classes.cli.ts +17 -54
  109. package/ts/classes.configurationauthority.ts +1 -1
  110. package/ts/classes.controller.ts +697 -167
  111. package/ts/classes.controllerdevices.ts +469 -0
  112. package/ts/classes.controllerservice.ts +49 -6
  113. package/ts/classes.flexservice.ts +7 -2
  114. package/ts/classes.inferencegateway.ts +133 -19
  115. package/ts/classes.inferencerouter.ts +20 -2
  116. package/ts/classes.inferenceservice.ts +6 -3
  117. package/ts/classes.sessionfeed.ts +13 -1
  118. package/ts/classes.ticketmodels.ts +3 -2
  119. package/ts/classes.ticketnotifier.ts +8 -1
  120. package/ts/classes.ticketstore.ts +8 -4
  121. package/ts/classes.upgradecoordinator.ts +14 -4
  122. package/ts/classes.upgradetransaction.ts +118 -0
  123. package/ts/classes.validation.ts +1 -1
  124. package/ts/configuration/functions.master.ts +6 -3
  125. package/ts/driver/classes.drivereventrelay.ts +2 -2
  126. package/ts/fleet/classes.boardpump.ts +7 -4
  127. package/ts/fleet/classes.claudeworkers.ts +16 -6
  128. package/ts/fleet/classes.deploymodels.ts +44 -0
  129. package/ts/fleet/functions.validation.ts +50 -2
  130. package/ts/fleet/interfaces.workers.ts +56 -1
  131. package/ts/functions.deviceapi.ts +295 -0
  132. package/ts/functions.deviceproof.ts +118 -0
  133. package/ts/functions.fleetworkercli.ts +26 -8
  134. package/ts/functions.inferencecli.ts +3 -1
  135. package/ts/functions.remotecli.ts +11 -5
  136. package/ts/functions.ticketvalidation.ts +48 -13
  137. package/ts/interfaces.auth.ts +6 -0
  138. package/ts_authswitch/authority-contract.ts +18 -0
  139. package/ts_authswitch/classes.authoritybroker.ts +29 -3
  140. package/ts_authswitch/classes.authoritycli.ts +29 -0
  141. package/ts_authswitch/classes.authorityclient.ts +12 -4
  142. package/ts_authswitch/classes.authoritydaemon.ts +8 -1
  143. package/ts_authswitch/classes.authorityimport.ts +1 -1
  144. package/ts_authswitch/classes.authoritymodels.ts +5 -1
  145. package/ts_authswitch/native-contracts.md +10 -0
  146. package/ts_authswitch/testsupport.ts +3 -3
  147. package/ts_authswitch/ts_migration/0012_account_claude_code.ts +17 -0
  148. package/ts_authswitch/ts_migration/index.ts +2 -0
  149. package/ts_interfaces/deployments.ts +98 -0
  150. package/ts_interfaces/devices.schema.json +890 -0
  151. package/ts_interfaces/devices.ts +392 -0
  152. package/ts_interfaces/fleet.ts +2 -0
  153. package/ts_interfaces/index.ts +3 -0
  154. package/ts_interfaces/interfaces.ts +4 -1
  155. package/ts_interfaces/mcprequests.ts +1 -1
  156. package/ts_interfaces/requests.accounts.ts +16 -0
  157. package/ts_interfaces/requests.devices.ts +95 -0
  158. package/ts_interfaces/requests.ts +12 -0
  159. package/ts_interfaces/tickets.ts +34 -4
  160. package/ts_migration/index.ts +1 -0
  161. package/ts_migration/v41_ticketmigrationmarkers.ts +28 -0
  162. package/ts_web/00_commitinfo_data.ts +1 -1
  163. package/ts_web/classes.accountsreadmodel.ts +12 -1
  164. package/ts_web/classes.controllersocketclient.ts +27 -0
  165. package/ts_web/elements.accounts.ts +44 -0
  166. package/ts_web/elements.devices.ts +752 -0
  167. package/ts_web/elements.harnesscontrollerapp.ts +18 -1
  168. package/ts_web/elements.ticketboard.ts +15 -4
@@ -1,7 +1,10 @@
1
+ /** `closed` holds work that ships no code: done without a landing or a release. */
1
2
  export const ticketColumns = [
2
- 'backlog', 'ready', 'in_progress', 'needs_input', 'review', 'landed', 'released',
3
+ 'backlog', 'ready', 'in_progress', 'needs_input', 'review', 'landed', 'released', 'closed',
3
4
  ] as const;
4
5
  export type TTicketColumn = (typeof ticketColumns)[number];
6
+ /** The columns of finished work; the board folds them. */
7
+ export const ticketDoneColumns: readonly TTicketColumn[] = ['released', 'closed'];
5
8
  export type TTicketKind = 'epic' | 'task' | 'subtask';
6
9
  export type TTicketPriority = 'none' | 'low' | 'normal' | 'high' | 'urgent';
7
10
  export interface ITicketPerson {
@@ -13,10 +16,33 @@ export interface ITicketPerson {
13
16
  export interface ITicketActor extends ITicketPerson {
14
17
  role: 'owner' | 'driver' | 'worker';
15
18
  }
19
+ /**
20
+ * Evidence a ticket carries. A release is a repository's tag `v<version>`: its link names the repository (`org/name`)
21
+ * and the commit the tag points at, and the package it published where there is one; a release linked by hand names
22
+ * the package alone. `affects` records the version of a repository a bug was found in.
23
+ */
16
24
  export type TTicketLink =
17
25
  | { kind: 'branch'; repo: string; branch: string; sha: string }
18
26
  | { kind: 'commit'; repo: string; sha: string }
19
- | { kind: 'release'; package: string; version: string };
27
+ | { kind: 'release'; version: string; package?: string; repo?: string; sha?: string }
28
+ | { kind: 'affects'; repo: string; version: string };
29
+ /**
30
+ * A planned release: the repository (`org/name`, one fleet discovery knows) and, optionally, the version it should
31
+ * reach; without a version it means the next release. A hotfix is the same plan on an urgent ticket.
32
+ */
33
+ export interface ITicketReleasePlan { repo: string; version?: string }
34
+ /**
35
+ * A maintenance window: between `from` and `to` (ISO 8601 instants, `to` after `from`) the deploy targets it lists may
36
+ * be deployed, which a target whose deploys need a window waits for. A window counts while its ticket is not done.
37
+ * `questionId` is the owner's question on the ticket when the driver proposed the window: it counts once the owner
38
+ * approves it there. The owner's own window has none and counts at once.
39
+ */
40
+ export interface ITicketMaintenanceWindow { from: string; to: string; targets: string[]; questionId?: string }
41
+ /**
42
+ * A planned deploy: the deploy target should run `version`, a release of its repository, or a newer one. Setting it
43
+ * asks the owner `questionId` on the ticket; the answer is the owner's go.
44
+ */
45
+ export interface ITicketDeployPlan { target: string; version: string; questionId: string }
20
46
  export interface ITicketAttachment { name: string; url: string; }
21
47
  export interface ITicketSource {
22
48
  kind: 'owner_words' | 'driver' | 'worker';
@@ -39,6 +65,9 @@ export interface ITicket {
39
65
  assignee?: ITicketPerson;
40
66
  labels: string[];
41
67
  links: TTicketLink[];
68
+ releasePlan?: ITicketReleasePlan;
69
+ maintenanceWindow?: ITicketMaintenanceWindow;
70
+ deployPlan?: ITicketDeployPlan;
42
71
  source: ITicketSource;
43
72
  createdBy: ITicketActor;
44
73
  updatedBy: ITicketActor;
@@ -80,7 +109,7 @@ export interface ITicketActivity {
80
109
  ticketId: string;
81
110
  actor: ITicketActor;
82
111
  createdAt: string;
83
- action: 'created' | 'updated' | 'moved' | 'reordered' | 'commented' | 'linked' | 'asked' | 'answered';
112
+ action: 'created' | 'updated' | 'moved' | 'reordered' | 'commented' | 'linked' | 'unlinked' | 'asked' | 'answered';
84
113
  changes: Record<string, { before?: unknown; after?: unknown }>;
85
114
  }
86
115
  /**
@@ -262,7 +291,7 @@ export interface ITicketFleetEventBase {
262
291
  }
263
292
  export type TTicketFleetEvent = ITicketFleetEventBase & (
264
293
  | { kind: 'landed'; repo: string; branch: string; sha: string; body?: string | TTicketReferenceContent }
265
- | { kind: 'released'; package: string; version: string; body?: string | TTicketReferenceContent }
294
+ | { kind: 'released'; version: string; package?: string; repo?: string; sha?: string; body?: string | TTicketReferenceContent }
266
295
  | { kind: 'comment'; body: string | TTicketReferenceContent }
267
296
  );
268
297
  export interface ITicketFleetEventResult {
@@ -288,6 +317,7 @@ export const ticketErrorMessages = {
288
317
  ticket_label_reserved: 'AutoLabels such as openQuestion are computed by AGL and cannot be set by hand.',
289
318
  ticket_ask_forbidden: 'Workers may ask questions only on tickets assigned to their verified session.',
290
319
  ticket_answer_forbidden: 'Only the owner or the driver may answer ticket questions.',
320
+ ticket_go_owner_only: 'Only the owner answers the question of a deploy plan or a maintenance window: the answer is the owner\'s go.',
291
321
  ticket_question_not_found: 'The requested question does not exist on this ticket.',
292
322
  ticket_comment_not_found: 'The requested comment does not exist on this ticket.',
293
323
  ticket_question_answered: 'The question already has a different answer; a second answer is refused. Ask a new question instead.',
@@ -27,3 +27,4 @@ export * from './v38_flextranscripts.js';
27
27
  export * from './v39_fleetrepositorydiscovery.js';
28
28
  export * from './v39_flexcompaction.js';
29
29
  export * from './v39_flexpublicheadpointers.js';
30
+ export * from './v41_ticketmigrationmarkers.js';
@@ -0,0 +1,28 @@
1
+ import * as plugins from './plugins.js';
2
+
3
+ /** A ticket migration that ran: its name, when it finished and the tickets it changed. */
4
+ export interface ITicketMigrationMarkerDocument {
5
+ /** The migration's name, such as `v41_ticketclosedcolumn`. */
6
+ id: string;
7
+ completedAt: string;
8
+ /** The keys of the tickets it changed. */
9
+ tickets: string[];
10
+ }
11
+
12
+ const markerSchema = plugins.z.object({
13
+ id: plugins.z.string().regex(/^v[0-9]+_[a-z0-9]+$/u), completedAt: plugins.z.iso.datetime(),
14
+ tickets: plugins.z.array(plugins.z.string().regex(/^AGL-[1-9][0-9]*$/u)).max(100_000),
15
+ }).strict();
16
+
17
+ /**
18
+ * One record per ticket migration that ran, written in the transaction that ran it: a migration with a marker never
19
+ * runs again, whatever the board looks like at a later start.
20
+ */
21
+ @plugins.nosqldb.managed({ collectionName: 'agl_ticket_migrations' })
22
+ @plugins.nosqldb.exactPersistence({ assertDocument: (input: unknown) => { markerSchema.parse(input); } })
23
+ export class TicketMigrationMarkerModel extends plugins.nosqldb.SmartDataDbDoc<TicketMigrationMarkerModel, ITicketMigrationMarkerDocument> {
24
+ declare static exact: plugins.nosqldb.TExact<TicketMigrationMarkerModel>;
25
+ @plugins.nosqldb.unI() public id!: string;
26
+ @plugins.nosqldb.svDb() public completedAt!: string;
27
+ @plugins.nosqldb.svDb() public tickets!: string[];
28
+ }
@@ -3,6 +3,6 @@
3
3
  */
4
4
  export const commitinfo = {
5
5
  name: 'agl',
6
- version: '42.0.0',
6
+ version: '42.2.0',
7
7
  description: 'Agent Gateway Layer for OpenCode, FlexHarness, and Codex sessions'
8
8
  }
@@ -146,6 +146,7 @@ export type TAccountActionId =
146
146
  | 'clearMaxUsage'
147
147
  | 'spendLimit'
148
148
  | 'clearSpendLimit'
149
+ | 'claudeCode'
149
150
  | 'addApiKey'
150
151
  | 'remove'
151
152
  | 'usage'
@@ -353,6 +354,8 @@ export interface IAccountRow {
353
354
  apiKey: boolean;
354
355
  /** An API key's monthly spend limit in micro-dollars, or `null` for none and for every sign-in. */
355
356
  spendLimitMicroUsd: number | null;
357
+ /** Whether the account may serve Claude Code (AGL-1146); always `true` for a sign-in. */
358
+ claudeCode: boolean;
356
359
  /** What a removal does that the owner must know, said with the removal; empty for a sign-in. */
357
360
  removeNote: string;
358
361
  label: string;
@@ -1437,6 +1440,11 @@ export const spendLimitText = (spendLimitMicroUsdArg: number | null): string =>
1437
1440
  ? 'No monthly limit'
1438
1441
  : `${plugins.authswitchSpend.authSwitchUsdText(spendLimitMicroUsdArg)} per calendar month (UTC)`;
1439
1442
 
1443
+ /** Whether a key serves Claude Code, in words, as its page states it (AGL-1146). */
1444
+ export const claudeCodeText = (claudeCodeArg: boolean): string => claudeCodeArg
1445
+ ? 'Serves Claude Code'
1446
+ : 'Not for Claude Code: AGL places Claude Code requests on other accounts; other clients still use the key';
1447
+
1440
1448
  /**
1441
1449
  * Why the Add API key dialog cannot add yet, or `''` when it can: a key typed, an optional name the service's label rule
1442
1450
  * accepts, and an optional spend limit in dollars its spend limit rule accepts.
@@ -1536,6 +1544,7 @@ const serviceRow = (
1536
1544
  groupId: apiKey ? `${accountArg.providerId}-api-key` : accountArg.providerId,
1537
1545
  apiKey,
1538
1546
  spendLimitMicroUsd: apiKey ? accountArg.spendLimitMicroUsd : null,
1547
+ claudeCode: accountArg.claudeCode,
1539
1548
  removeNote: apiKey
1540
1549
  ? `AGL stops using the key. It stays valid at ${provider.name} until you revoke it in ${provider.console}.`
1541
1550
  : '',
@@ -1585,7 +1594,8 @@ const serviceRow = (
1585
1594
  manage: [
1586
1595
  serviceSlot('rename', 'Rename', 'lucide:PenLine', contextArg.service, removed),
1587
1596
  // A key's limit is its spend; a usage threshold and its reserve are a sign-in's.
1588
- ...(apiKey ? [serviceSlot('spendLimit', 'Spend limit', 'lucide:Wallet', contextArg.service, removed)]
1597
+ ...(apiKey ? [serviceSlot('spendLimit', 'Spend limit', 'lucide:Wallet', contextArg.service, removed),
1598
+ serviceSlot('claudeCode', 'Claude Code', 'lucide:Terminal', contextArg.service, removed)]
1589
1599
  : [serviceSlot('maxUsage', 'Max usage', 'lucide:SlidersHorizontal', contextArg.service, removed)]),
1590
1600
  ...(!apiKey && accountArg.maxUsagePercent !== null && accountArg.maxUsagePercent < 100
1591
1601
  ? [serviceSlot('liftReserve', 'Lift reserve', 'lucide:Clock', contextArg.service, removed)] : []),
@@ -1605,6 +1615,7 @@ const serviceRow = (
1605
1615
  ? plugins.authswitchSubscription.authSwitchSubscriptionFacts(usageRead.usage.reading) : []),
1606
1616
  apiKey ? { label: 'Monthly spend limit', value: spendLimitText(accountArg.spendLimitMicroUsd) }
1607
1617
  : { label: 'Max usage', value: maxUsageFact(accountArg.maxUsagePercent) },
1618
+ ...(apiKey ? [{ label: 'Claude Code', value: claudeCodeText(accountArg.claudeCode) }] : []),
1608
1619
  { label: 'Account reference', value: accountArg.id },
1609
1620
  ],
1610
1621
  accountId: accountArg.id,
@@ -663,6 +663,30 @@ export const isControllerUsageWatch = (
663
663
  && candidate.buckets.every((bucketArg) => isControllerUsageBucket(bucketArg) && bucketArg.span === span);
664
664
  };
665
665
 
666
+ const deviceKeys: ReadonlySet<string> = new Set(['id', 'name', 'model', 'fingerprint', 'pairedAt', 'lastSeenAt', 'connected']);
667
+
668
+ /** A paired device as the controller lists it. */
669
+ export const isControllerDevice = (valueArg: unknown): valueArg is interfaces.IControllerDevice => {
670
+ if (!valueArg || typeof valueArg !== 'object' || Array.isArray(valueArg)) return false;
671
+ const candidate = valueArg as Partial<interfaces.IControllerDevice>;
672
+ return Object.keys(candidate).every((keyArg) => deviceKeys.has(keyArg))
673
+ && typeof candidate.id === 'string' && /^[A-Za-z0-9_-]{24}$/u.test(candidate.id)
674
+ && isNonEmptyString(candidate.name) && candidate.name.length <= 256
675
+ && isNonEmptyString(candidate.model) && candidate.model.length <= 256
676
+ && typeof candidate.fingerprint === 'string' && /^[0-9A-F]{4}( [0-9A-F]{4}){7}$/u.test(candidate.fingerprint)
677
+ && Number.isSafeInteger(candidate.pairedAt)
678
+ && (candidate.lastSeenAt === undefined || Number.isSafeInteger(candidate.lastSeenAt))
679
+ && typeof candidate.connected === 'boolean';
680
+ };
681
+
682
+ const isDevicePairingOutcome = (valueArg: unknown): valueArg is interfaces.IControllerDevicePairingOutcome => {
683
+ if (!valueArg || typeof valueArg !== 'object' || Array.isArray(valueArg)) return false;
684
+ const candidate = valueArg as Partial<interfaces.IControllerDevicePairingOutcome>;
685
+ return Object.keys(candidate).length === 2
686
+ && typeof candidate.pairingId === 'string' && /^[A-Za-z0-9_-]{22}$/u.test(candidate.pairingId)
687
+ && isControllerDevice(candidate.device);
688
+ };
689
+
666
690
  export const isControllerEvent = (valueArg: unknown): valueArg is interfaces.IControllerEvent => {
667
691
  if (!valueArg || typeof valueArg !== 'object') {
668
692
  return false;
@@ -857,6 +881,9 @@ export const isControllerEvent = (valueArg: unknown): valueArg is interfaces.ICo
857
881
  candidate.type === 'usage.changed' && isControllerUsageDelta(candidate.usageDelta)
858
882
  ))
859
883
  && (candidate.usageDelta !== undefined || candidate.type !== 'usage.changed')
884
+ && (candidate.devicePairing === undefined || (
885
+ candidate.type === 'devices.changed' && isDevicePairingOutcome(candidate.devicePairing)
886
+ ))
860
887
  );
861
888
  };
862
889
 
@@ -1070,6 +1070,43 @@ export class AglAccounts extends plugins.deesElement.DeesElement {
1070
1070
  });
1071
1071
  }
1072
1072
 
1073
+ /** Sets whether an API key may serve Claude Code (AGL-1146). */
1074
+ private async setClaudeCode(rowArg: IAccountRow, claudeCodeArg: boolean): Promise<void> {
1075
+ await this.runAction(`claudecode:${rowArg.accountId}`, async () => {
1076
+ const { answer } = await this.client!.fire<interfaces.IReq_ControllerAccountsClaudeCode>(
1077
+ 'controller.accounts.claudecode',
1078
+ { accountId: rowArg.accountId, expectedRevision: rowArg.revision, claudeCode: claudeCodeArg },
1079
+ { maxRetries: 0 },
1080
+ );
1081
+ this.notice = answerNotice(answer);
1082
+ await this.refresh();
1083
+ });
1084
+ }
1085
+
1086
+ /**
1087
+ * Whether an API key serves Claude Code, switched with one button. A key whose credit its provider grants for API use
1088
+ * other than Claude Code is kept from it; every other client still uses the key.
1089
+ */
1090
+ private renderClaudeCode(rowArg: IAccountRow, slotArg: IAccountActionSlot): plugins.deesElement.TemplateResult {
1091
+ return plugins.deesElement.html`
1092
+ <div class="item" data-claude-code>
1093
+ <div>
1094
+ <div class="itemLabel">Claude Code</div>
1095
+ <div class="itemText">${rowArg.claudeCode
1096
+ ? 'AGL may place Claude Code requests on this key when no sign-in can take them. Keep it from Claude Code if'
1097
+ + ' its credit is not for Claude Code; other clients still use it.'
1098
+ : 'AGL places no Claude Code request on this key, and moves Claude Code sessions on it to other accounts.'
1099
+ + ' Other clients still use it.'}</div>
1100
+ </div>
1101
+ ${this.slots(
1102
+ [{ ...slotArg, label: rowArg.claudeCode ? 'Keep from Claude Code' : 'Serve Claude Code',
1103
+ icon: rowArg.claudeCode ? 'lucide:Ban' : 'lucide:Check' }],
1104
+ () => void this.setClaudeCode(rowArg, !rowArg.claudeCode),
1105
+ )}
1106
+ </div>
1107
+ `;
1108
+ }
1109
+
1073
1110
  /**
1074
1111
  * Adds the API key the dialog holds. The accounts service asks the provider whether it accepts the key before it holds
1075
1112
  * anything, so the dialog's fields stay locked while it does; added, the dialog closes and the screen says the spend
@@ -1652,6 +1689,7 @@ export class AglAccounts extends plugins.deesElement.DeesElement {
1652
1689
  const renameSlot = slot('rename');
1653
1690
  const maxUsageSlot = slot('maxUsage');
1654
1691
  const spendLimitSlot = slot('spendLimit');
1692
+ const claudeCodeSlot = slot('claudeCode');
1655
1693
  const liftSlot = slot('liftReserve');
1656
1694
  const removeSlot = slot('remove');
1657
1695
  const useCodexSlot = slot('useCodex');
@@ -1749,6 +1787,12 @@ export class AglAccounts extends plugins.deesElement.DeesElement {
1749
1787
  <div class="card">${this.renderSpendLimit(rowArg, this.effectiveSlot(spendLimitSlot))}</div>
1750
1788
  </section>`
1751
1789
  : ''}
1790
+ ${claudeCodeSlot
1791
+ ? plugins.deesElement.html`<section class="section" data-clients aria-label="Clients">
1792
+ <div class="sectionHead"><span>Clients</span></div>
1793
+ <div class="card">${this.renderClaudeCode(rowArg, this.effectiveSlot(claudeCodeSlot))}</div>
1794
+ </section>`
1795
+ : ''}
1752
1796
  ${maxUsageSlot
1753
1797
  ? plugins.deesElement.html`<section class="section" data-limits aria-label="Limits">
1754
1798
  <div class="sectionHead"><span>Limits</span></div>