agl 43.2.0 → 43.3.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 +20 -0
- package/dist_serve/bundle.js +2845 -2638
- package/dist_serve/bundle.js.map +2 -2
- package/dist_serve/bundle.js.third-party-notices.json +1 -1
- package/dist_serve/bundle.js.third-party-notices.txt +1 -1
- package/dist_ts/00_commitinfo_data.js +1 -1
- package/dist_ts/aglapi/aglapisurface.document.js +197 -17
- package/dist_ts/classes.accountsactions.d.ts +3 -1
- package/dist_ts/classes.accountsactions.js +21 -3
- package/dist_ts/classes.claudeharness.d.ts +16 -0
- package/dist_ts/classes.claudeharness.js +24 -2
- package/dist_ts/classes.codexclientadapter.d.ts +11 -0
- package/dist_ts/classes.codexclientadapter.js +14 -2
- package/dist_ts/classes.controller.d.ts +165 -11
- package/dist_ts/classes.controller.js +1095 -170
- package/dist_ts/classes.controllerdevices.d.ts +2 -0
- package/dist_ts/classes.controllerdevices.js +6 -1
- package/dist_ts/classes.inbox.d.ts +72 -0
- package/dist_ts/classes.inbox.js +231 -0
- package/dist_ts/classes.inferencerouter.d.ts +10 -0
- package/dist_ts/classes.inferencerouter.js +5 -3
- package/dist_ts/classes.inferenceservice.js +2 -2
- package/dist_ts/classes.mcpclient.d.ts +1 -1
- package/dist_ts/classes.mcpclient.js +24 -6
- package/dist_ts/classes.mcpcontrollerhost.js +3 -1
- package/dist_ts/classes.mcptools.js +13 -8
- package/dist_ts/classes.mcpvalidation.d.ts +5 -0
- package/dist_ts/classes.mcpvalidation.js +32 -2
- package/dist_ts/classes.nativesessions.d.ts +17 -4
- package/dist_ts/classes.nativesessions.js +41 -9
- package/dist_ts/classes.opencodeclient.d.ts +23 -2
- package/dist_ts/classes.opencodeclient.js +47 -3
- package/dist_ts/classes.publishedset.d.ts +38 -0
- package/dist_ts/classes.publishedset.js +50 -0
- package/dist_ts/classes.sessionfeed.d.ts +3 -3
- package/dist_ts/classes.sessionfeed.js +18 -26
- package/dist_ts/classes.systemmetricssampler.d.ts +6 -0
- package/dist_ts/classes.systemmetricssampler.js +15 -3
- package/dist_ts/classes.ticketstore.d.ts +50 -3
- package/dist_ts/classes.ticketstore.js +45 -8
- package/dist_ts/driver/classes.directreports.d.ts +14 -4
- package/dist_ts/driver/classes.directreports.js +25 -6
- package/dist_ts/driver/classes.driverservice.d.ts +44 -3
- package/dist_ts/driver/classes.driverservice.js +50 -16
- package/dist_ts/fleet/classes.claudeworkers.d.ts +21 -5
- package/dist_ts/fleet/classes.claudeworkers.js +142 -46
- package/dist_ts/fleet/classes.codexworkers.d.ts +16 -4
- package/dist_ts/fleet/classes.codexworkers.js +22 -5
- package/dist_ts/fleet/classes.workercommand.d.ts +6 -1
- package/dist_ts/fleet/classes.workercommand.js +15 -4
- package/dist_ts/fleet/classes.workers.d.ts +5 -1
- package/dist_ts/fleet/classes.workers.js +8 -2
- package/dist_ts/fleet/functions.unbounddrivers.js +2 -2
- package/dist_ts/fleet/functions.workervalidation.js +2 -2
- package/dist_ts/fleet/interfaces.workers.d.ts +21 -3
- package/dist_ts/fleet/interfaces.workers.js +1 -1
- package/dist_ts/functions.agentmessage.d.ts +3 -0
- package/dist_ts/functions.agentmessage.js +4 -1
- package/dist_ts/functions.deviceapi.d.ts +151 -4
- package/dist_ts/functions.deviceapi.js +893 -38
- package/dist_ts/functions.fleetworkercli.d.ts +1 -1
- package/dist_ts/functions.fleetworkercli.js +11 -8
- package/dist_ts/functions.inferencecli.js +3 -1
- package/dist_ts/functions.mcpfleetworkertools.js +2 -2
- package/dist_ts/functions.ticketvalidation.js +11 -2
- package/dist_ts/interfaces.auth.d.ts +1 -1
- package/dist_ts/interfaces.auth.js +9 -1
- package/dist_ts/plugins.d.ts +3 -1
- package/dist_ts/plugins.js +7 -2
- package/dist_ts_authswitch/authority-contract.d.ts +25 -0
- package/dist_ts_authswitch/authority-contract.js +1 -1
- package/dist_ts_authswitch/authority-overview.d.ts +8 -0
- package/dist_ts_authswitch/authority-overview.js +17 -6
- package/dist_ts_authswitch/authority-placement.d.ts +20 -16
- package/dist_ts_authswitch/authority-placement.js +17 -10
- package/dist_ts_authswitch/authority-renewal.d.ts +34 -0
- package/dist_ts_authswitch/authority-renewal.js +56 -0
- package/dist_ts_authswitch/classes.authoritybroker.d.ts +8 -0
- package/dist_ts_authswitch/classes.authoritybroker.js +35 -2
- package/dist_ts_authswitch/classes.authoritycli.d.ts +1 -0
- package/dist_ts_authswitch/classes.authoritycli.js +44 -3
- package/dist_ts_authswitch/classes.authorityclient.d.ts +6 -1
- package/dist_ts_authswitch/classes.authorityclient.js +12 -4
- package/dist_ts_authswitch/classes.authoritydaemon.js +8 -1
- package/dist_ts_authswitch/classes.authoritydatabase.js +6 -2
- package/dist_ts_authswitch/classes.authoritymodels.d.ts +7 -0
- package/dist_ts_authswitch/classes.authoritymodels.js +21 -5
- package/dist_ts_interfaces/devices.d.ts +1012 -5
- package/dist_ts_interfaces/devices.js +68 -2
- package/dist_ts_interfaces/fleetworkers.d.ts +5 -3
- package/dist_ts_interfaces/inbox.d.ts +234 -0
- package/dist_ts_interfaces/inbox.js +101 -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 +10 -3
- package/dist_ts_interfaces/interfaces.js +4 -2
- package/dist_ts_interfaces/mcprequests.d.ts +34 -4
- package/dist_ts_interfaces/mcprequests.js +11 -1
- package/dist_ts_interfaces/mcpworkspacerequests.d.ts +4 -1
- package/dist_ts_interfaces/mcpworkspacerequests.js +1 -1
- package/dist_ts_interfaces/nativesessions.d.ts +16 -3
- package/dist_ts_interfaces/plugins.d.ts +2 -1
- package/dist_ts_interfaces/plugins.js +4 -2
- package/dist_ts_interfaces/requests.accounts.d.ts +21 -0
- package/dist_ts_interfaces/requests.accounts.js +3 -1
- package/dist_ts_interfaces/requests.d.ts +3 -2
- package/dist_ts_interfaces/requests.js +1 -1
- package/docs/authswitch.md +20 -1
- package/package.json +3 -3
- package/readme.md +112 -26
- package/ts/00_commitinfo_data.ts +1 -1
- package/ts/aglapi/aglapisurface.document.ts +196 -16
- package/ts/classes.accountsactions.ts +30 -3
- package/ts/classes.claudeharness.ts +27 -1
- package/ts/classes.codexclientadapter.ts +14 -1
- package/ts/classes.controller.ts +1294 -246
- package/ts/classes.controllerdevices.ts +6 -0
- package/ts/classes.inbox.ts +239 -0
- package/ts/classes.inferencerouter.ts +15 -2
- package/ts/classes.inferenceservice.ts +1 -1
- package/ts/classes.mcpclient.ts +24 -3
- package/ts/classes.mcpcontrollerhost.ts +2 -0
- package/ts/classes.mcptools.ts +12 -7
- package/ts/classes.mcpvalidation.ts +27 -1
- package/ts/classes.nativesessions.ts +50 -12
- package/ts/classes.opencodeclient.ts +55 -4
- package/ts/classes.publishedset.ts +56 -0
- package/ts/classes.sessionfeed.ts +17 -20
- package/ts/classes.systemmetricssampler.ts +13 -2
- package/ts/classes.ticketstore.ts +73 -12
- package/ts/driver/classes.directreports.ts +25 -6
- package/ts/driver/classes.driverservice.ts +75 -14
- package/ts/fleet/classes.claudeworkers.ts +112 -39
- package/ts/fleet/classes.codexworkers.ts +21 -6
- package/ts/fleet/classes.workercommand.ts +14 -4
- package/ts/fleet/classes.workers.ts +9 -2
- package/ts/fleet/functions.unbounddrivers.ts +1 -1
- package/ts/fleet/functions.workervalidation.ts +1 -1
- package/ts/fleet/interfaces.workers.ts +20 -5
- package/ts/functions.agentmessage.ts +3 -0
- package/ts/functions.deviceapi.ts +1071 -34
- package/ts/functions.fleetworkercli.ts +10 -7
- package/ts/functions.inferencecli.ts +2 -0
- package/ts/functions.mcpfleetworkertools.ts +1 -1
- package/ts/functions.ticketvalidation.ts +11 -1
- package/ts/interfaces.auth.ts +8 -0
- package/ts/plugins.ts +7 -0
- package/ts_authswitch/authority-contract.ts +20 -0
- package/ts_authswitch/authority-overview.ts +28 -6
- package/ts_authswitch/authority-placement.ts +25 -17
- package/ts_authswitch/authority-renewal.ts +64 -0
- package/ts_authswitch/classes.authoritybroker.ts +34 -1
- package/ts_authswitch/classes.authoritycli.ts +49 -2
- package/ts_authswitch/classes.authorityclient.ts +14 -4
- package/ts_authswitch/classes.authoritydaemon.ts +9 -1
- package/ts_authswitch/classes.authoritydatabase.ts +5 -1
- package/ts_authswitch/classes.authoritymodels.ts +23 -3
- package/ts_authswitch/native-contracts.md +21 -0
- package/ts_authswitch/readme.md +1 -1
- package/ts_interfaces/devices.schema.json +3573 -603
- package/ts_interfaces/devices.ts +1093 -4
- package/ts_interfaces/fleetworkers.ts +5 -3
- package/ts_interfaces/inbox.ts +287 -0
- package/ts_interfaces/index.ts +1 -0
- package/ts_interfaces/interfaces.ts +9 -2
- package/ts_interfaces/mcprequests.ts +43 -4
- package/ts_interfaces/mcpworkspacerequests.ts +4 -2
- package/ts_interfaces/nativesessions.ts +17 -3
- package/ts_interfaces/plugins.ts +3 -1
- package/ts_interfaces/requests.accounts.ts +20 -0
- package/ts_interfaces/requests.ts +4 -0
- package/ts_web/00_commitinfo_data.ts +1 -1
- package/ts_web/accounts.plugins.ts +4 -2
- package/ts_web/classes.accountsreadmodel.ts +33 -0
- package/ts_web/classes.browserpresentation.ts +10 -5
- package/ts_web/classes.inboxfeed.ts +329 -0
- package/ts_web/classes.nativesessionstate.ts +9 -23
- package/ts_web/elements.accounts.ts +81 -0
- package/ts_web/elements.deployments.ts +66 -2
- package/ts_web/elements.harnesscontrollerapp.ts +107 -37
- package/ts_web/elements.inbox.ts +808 -0
- package/ts_web/functions.inbox.ts +95 -0
- package/ts_web/functions.sessioncards.ts +40 -0
- package/ts_web/plugins.ts +2 -0
|
@@ -147,6 +147,8 @@ export type TAccountActionId =
|
|
|
147
147
|
| 'spendLimit'
|
|
148
148
|
| 'clearSpendLimit'
|
|
149
149
|
| 'claudeCode'
|
|
150
|
+
| 'renewal'
|
|
151
|
+
| 'clearRenewal'
|
|
150
152
|
| 'addApiKey'
|
|
151
153
|
| 'remove'
|
|
152
154
|
| 'usage'
|
|
@@ -356,6 +358,11 @@ export interface IAccountRow {
|
|
|
356
358
|
spendLimitMicroUsd: number | null;
|
|
357
359
|
/** Whether the account may serve Claude Code (AGL-1146); always `true` for a sign-in. */
|
|
358
360
|
claudeCode: boolean;
|
|
361
|
+
/**
|
|
362
|
+
* The anchor of a Claude sign-in's monthly renewal as its owner set it (ISO 8601 UTC, AGL-1644), or `null` without
|
|
363
|
+
* one and for every other account.
|
|
364
|
+
*/
|
|
365
|
+
renewsAt: string | null;
|
|
359
366
|
/** What a removal does that the owner must know, said with the removal; empty for a sign-in. */
|
|
360
367
|
removeNote: string;
|
|
361
368
|
label: string;
|
|
@@ -1353,6 +1360,27 @@ const identityText = (emailArg: string | null | undefined, planArg: string | nul
|
|
|
1353
1360
|
`${emailArg || 'No email reported'} · ${planArg ? `${planArg} plan` : 'plan not reported'}`
|
|
1354
1361
|
);
|
|
1355
1362
|
|
|
1363
|
+
/**
|
|
1364
|
+
* What the Details say of a Claude sign-in's renewal: the next one, rolled forward from the anchor its owner set as
|
|
1365
|
+
* placement rolls it, or that none is set. AGL derives no renewal from what Claude states.
|
|
1366
|
+
*/
|
|
1367
|
+
export const renewalFact = (renewsAtArg: string | null, nowArg: number): string => {
|
|
1368
|
+
const renewal = plugins.authswitchRenewal.authSwitchRenewal(renewsAtArg, nowArg);
|
|
1369
|
+
return renewal === null ? 'Not set'
|
|
1370
|
+
: `${plugins.authswitchPreuseText.localDateTime(renewal.at)}, monthly (set by you)`;
|
|
1371
|
+
};
|
|
1372
|
+
|
|
1373
|
+
/**
|
|
1374
|
+
* Why a renewal draft cannot be saved yet, or `''` when it can: a date and time the service's own rule reads, other
|
|
1375
|
+
* than the renewal the account has. A past one is valid: the next renewal is a whole number of months after it.
|
|
1376
|
+
*/
|
|
1377
|
+
export const renewalReason = (draftArg: string, currentArg: string | null): string => {
|
|
1378
|
+
const draft = draftArg.trim();
|
|
1379
|
+
if (draft.length === 0) return 'Enter a date and time.';
|
|
1380
|
+
if (!interfaces.isControllerRenewsAt(draft)) return 'Enter a date and time, year first, such as 2026-11-20 09:30.';
|
|
1381
|
+
return currentArg !== null && Date.parse(draft) === Date.parse(currentArg) ? 'The renewal is unchanged.' : '';
|
|
1382
|
+
};
|
|
1383
|
+
|
|
1356
1384
|
/** What the Details say of an account's usage threshold. */
|
|
1357
1385
|
const maxUsageFact = (maxUsagePercentArg: number | null): string => maxUsagePercentArg === null
|
|
1358
1386
|
? 'Not set'
|
|
@@ -1530,6 +1558,7 @@ const serviceRow = (
|
|
|
1530
1558
|
const payment = accountArg.removed || usageRead?.state !== 'read' ? null
|
|
1531
1559
|
: paymentView(accountArg, usageRead.usage, contextArg.now);
|
|
1532
1560
|
const apiKey = isApiKeyAccount(accountArg);
|
|
1561
|
+
const claudeSignIn = !apiKey && accountArg.providerId === 'anthropic';
|
|
1533
1562
|
const provider = keyProvider(accountArg.providerId);
|
|
1534
1563
|
const identity = apiKey ? keyIdentityText(accountArg) : identityText(accountArg.email, accountArg.plan);
|
|
1535
1564
|
const liftedUntil = !accountArg.removed && accountArg.maxUsagePercent !== null
|
|
@@ -1545,6 +1574,7 @@ const serviceRow = (
|
|
|
1545
1574
|
apiKey,
|
|
1546
1575
|
spendLimitMicroUsd: apiKey ? accountArg.spendLimitMicroUsd : null,
|
|
1547
1576
|
claudeCode: accountArg.claudeCode,
|
|
1577
|
+
renewsAt: claudeSignIn ? accountArg.renewsAt : null,
|
|
1548
1578
|
removeNote: apiKey
|
|
1549
1579
|
? `AGL stops using the key. It stays valid at ${provider.name} until you revoke it in ${provider.console}.`
|
|
1550
1580
|
: '',
|
|
@@ -1599,6 +1629,8 @@ const serviceRow = (
|
|
|
1599
1629
|
: [serviceSlot('maxUsage', 'Max usage', 'lucide:SlidersHorizontal', contextArg.service, removed)]),
|
|
1600
1630
|
...(!apiKey && accountArg.maxUsagePercent !== null && accountArg.maxUsagePercent < 100
|
|
1601
1631
|
? [serviceSlot('liftReserve', 'Lift reserve', 'lucide:Clock', contextArg.service, removed)] : []),
|
|
1632
|
+
// A renewal is a Claude subscription's: neither a key nor a ChatGPT account has one to set.
|
|
1633
|
+
...(claudeSignIn ? [serviceSlot('renewal', 'Renewal', 'lucide:CalendarClock', contextArg.service, removed)] : []),
|
|
1602
1634
|
serviceSlot('remove', 'Remove', 'lucide:Trash2', contextArg.service, removed),
|
|
1603
1635
|
...(usageLogin ? [serviceSlot('usage', 'Show latest usage', 'lucide:Gauge', contextArg.service)] : []),
|
|
1604
1636
|
...(usageLogin && payment ? [serviceSlot('recheck', 'Re-check', 'lucide:RotateCcw', contextArg.service)] : []),
|
|
@@ -1616,6 +1648,7 @@ const serviceRow = (
|
|
|
1616
1648
|
apiKey ? { label: 'Monthly spend limit', value: spendLimitText(accountArg.spendLimitMicroUsd) }
|
|
1617
1649
|
: { label: 'Max usage', value: maxUsageFact(accountArg.maxUsagePercent) },
|
|
1618
1650
|
...(apiKey ? [{ label: 'Claude Code', value: claudeCodeText(accountArg.claudeCode) }] : []),
|
|
1651
|
+
...(claudeSignIn ? [{ label: 'Renews', value: renewalFact(accountArg.renewsAt, contextArg.now) }] : []),
|
|
1619
1652
|
{ label: 'Account reference', value: accountArg.id },
|
|
1620
1653
|
],
|
|
1621
1654
|
accountId: accountArg.id,
|
|
@@ -11,6 +11,8 @@ type TPaintOpen = interfaces.IReq_ControllerBrowserPaintOpen['response'];
|
|
|
11
11
|
|
|
12
12
|
/** Original-video route requests kept while a Paint stream is still opening; it binds at most four. */
|
|
13
13
|
const maximumPendingVideoRoutes = 4;
|
|
14
|
+
/** The operation a failed original-video route of the run on screen reports. */
|
|
15
|
+
const pageVideoOperation = 'Show the page\'s video in Paint';
|
|
14
16
|
|
|
15
17
|
/** The controller requests this presentation issues, with the socket client's fire options. */
|
|
16
18
|
export interface IBrowserPresentationSocket {
|
|
@@ -214,7 +216,7 @@ export class ControllerBrowserPresentation {
|
|
|
214
216
|
const paint = this.paint;
|
|
215
217
|
if (paint && paint.response.paintId === eventArg.paintId) {
|
|
216
218
|
void this.openVideoRoute(paint, eventArg.routeId).catch((errorArg) => {
|
|
217
|
-
if (this.isCurrentPaint(paint)) this.options.onError(
|
|
219
|
+
if (this.isCurrentPaint(paint)) this.options.onError(pageVideoOperation, errorArg);
|
|
218
220
|
});
|
|
219
221
|
return;
|
|
220
222
|
}
|
|
@@ -330,7 +332,7 @@ export class ControllerBrowserPresentation {
|
|
|
330
332
|
for (const pending of this.pendingVideoRoutes.splice(0)) {
|
|
331
333
|
if (pending.paintId === opened.paintId) {
|
|
332
334
|
void this.openVideoRoute(paint, pending.routeId).catch((errorArg) => {
|
|
333
|
-
if (this.isCurrentPaint(paint)) this.options.onError(
|
|
335
|
+
if (this.isCurrentPaint(paint)) this.options.onError(pageVideoOperation, errorArg);
|
|
334
336
|
});
|
|
335
337
|
}
|
|
336
338
|
}
|
|
@@ -435,10 +437,13 @@ export class ControllerBrowserPresentation {
|
|
|
435
437
|
// keeps running and the next route mounts on it.
|
|
436
438
|
onEnded: () => { paintArg.routes.delete(mount); },
|
|
437
439
|
// A broken route closes only its own decoders; the renderer keeps running. A route of a
|
|
438
|
-
// stopping, replaced or closed run is not this view's fault.
|
|
439
|
-
|
|
440
|
+
// stopping, replaced or closed run is not this view's fault. Every reason of the run on
|
|
441
|
+
// screen is reported: SmartBrowser never reports this view's own close of a route (its
|
|
442
|
+
// abort signal or `close()`), so `fenced` is the host's revocation or a pair broken
|
|
443
|
+
// underneath it, `protocol` a broken route and `worker` a failed worker request.
|
|
444
|
+
onFailure: (errorArg: plugins.PaintVideoRouteError) => {
|
|
440
445
|
paintArg.routes.delete(mount);
|
|
441
|
-
if (this.isCurrentPaint(paintArg)) this.options.onError(
|
|
446
|
+
if (this.isCurrentPaint(paintArg)) this.options.onError(pageVideoOperation, errorArg);
|
|
442
447
|
},
|
|
443
448
|
});
|
|
444
449
|
paintArg.routes.add(mount);
|
|
@@ -0,0 +1,329 @@
|
|
|
1
|
+
import type * as plugins from './plugins.js';
|
|
2
|
+
import * as interfaces from '../ts_interfaces/index.js';
|
|
3
|
+
import { ElicitationCards } from './classes.elicitationcards.js';
|
|
4
|
+
|
|
5
|
+
type TInboxItem = interfaces.TControllerInboxItem;
|
|
6
|
+
|
|
7
|
+
const isRecord = (valueArg: unknown): valueArg is Record<string, unknown> => (
|
|
8
|
+
typeof valueArg === 'object' && valueArg !== null && !Array.isArray(valueArg)
|
|
9
|
+
);
|
|
10
|
+
const isText = (valueArg: unknown): valueArg is string => typeof valueArg === 'string' && valueArg.length > 0;
|
|
11
|
+
const isCount = (valueArg: unknown): valueArg is number => Number.isSafeInteger(valueArg) && (valueArg as number) >= 0;
|
|
12
|
+
const inboxKinds = new Set<string>(interfaces.controllerInboxKinds);
|
|
13
|
+
const inboxAnswers = new Set<string>(['conversation', 'child', 'native', 'ticket', 'none']);
|
|
14
|
+
const inboxWheres = new Set<string>(['conversation', 'child', 'native', 'driver', 'ticket']);
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* An Inbox item in the shape the view reads: its kind, where it lives and how it is answered, and the payload its kind
|
|
18
|
+
* carries unless the controller left it out (`omitted`). An item that fails it makes the browser list the Inbox again.
|
|
19
|
+
*/
|
|
20
|
+
export const isControllerInboxItem = (valueArg: unknown): valueArg is TInboxItem => {
|
|
21
|
+
if (!isRecord(valueArg) || !isText(valueArg.id) || !isText(valueArg.kind) || !inboxKinds.has(valueArg.kind)) return false;
|
|
22
|
+
if (typeof valueArg.since !== 'number' || !Number.isFinite(valueArg.since) || typeof valueArg.title !== 'string') return false;
|
|
23
|
+
if (!isText(valueArg.answer) || !inboxAnswers.has(valueArg.answer)) return false;
|
|
24
|
+
const where = valueArg.where;
|
|
25
|
+
if (!isRecord(where) || !isText(where.kind) || !inboxWheres.has(where.kind)) return false;
|
|
26
|
+
if (where.kind === 'ticket' ? !isText(where.ticketKey) || !isText(where.ticketId) : where.kind !== 'driver' && !isText(where.rowId)) return false;
|
|
27
|
+
const omitted = valueArg.omitted;
|
|
28
|
+
if (omitted !== undefined && (!isRecord(omitted) || omitted.reason !== 'oversize' || !isCount(omitted.bytes) || valueArg.answer !== 'none')) return false;
|
|
29
|
+
const payload = (keyArg: string): boolean => omitted !== undefined || isRecord(valueArg[keyArg]);
|
|
30
|
+
switch (valueArg.kind as interfaces.TControllerInboxKind) {
|
|
31
|
+
case 'permission': return payload('permission');
|
|
32
|
+
case 'question': return payload('question') && (omitted !== undefined || Array.isArray((valueArg.question as Record<string, unknown>).questions));
|
|
33
|
+
case 'elicitation': return payload('elicitation');
|
|
34
|
+
case 'native_wait': return isRecord(valueArg.nativeWait) && typeof valueArg.host === 'string';
|
|
35
|
+
case 'driver': return isText(valueArg.messageId) && (valueArg.line === undefined || typeof valueArg.line === 'string');
|
|
36
|
+
case 'deploy_go': return payload('question') && isRecord(valueArg.plan) && Array.isArray(valueArg.plan.ships) && isCount(valueArg.plan.shipsTotal);
|
|
37
|
+
case 'window_go': return payload('question') && isRecord(valueArg.window) && Array.isArray(valueArg.window.targets);
|
|
38
|
+
case 'ticket_question': return payload('question');
|
|
39
|
+
}
|
|
40
|
+
};
|
|
41
|
+
|
|
42
|
+
/** The answer of `controller.inbox.list`. */
|
|
43
|
+
export const isControllerInboxSnapshot = (valueArg: unknown): valueArg is interfaces.IControllerInboxSnapshot => (
|
|
44
|
+
isRecord(valueArg) && isText(valueArg.epoch) && isCount(valueArg.revision) && isCount(valueArg.total)
|
|
45
|
+
&& typeof valueArg.limited === 'boolean' && Array.isArray(valueArg.items) && valueArg.items.every(isControllerInboxItem)
|
|
46
|
+
);
|
|
47
|
+
|
|
48
|
+
/** One `inbox.changed` delta. */
|
|
49
|
+
export const isControllerInboxDelta = (valueArg: unknown): valueArg is interfaces.TControllerInboxDelta => {
|
|
50
|
+
if (!isRecord(valueArg) || !isText(valueArg.epoch) || !isCount(valueArg.revision) || valueArg.revision < 1) return false;
|
|
51
|
+
if (valueArg.reset !== undefined) return valueArg.reset === true;
|
|
52
|
+
return Array.isArray(valueArg.upserts) && valueArg.upserts.every(isControllerInboxItem)
|
|
53
|
+
&& Array.isArray(valueArg.removed) && valueArg.removed.every(isText)
|
|
54
|
+
&& Array.isArray(valueArg.order) && valueArg.order.every(isText)
|
|
55
|
+
&& isCount(valueArg.total) && typeof valueArg.limited === 'boolean';
|
|
56
|
+
};
|
|
57
|
+
|
|
58
|
+
/**
|
|
59
|
+
* Where the owner's answer to an item stands: on its way (`sending`), taken (`answered`, until the controller's list
|
|
60
|
+
* drops the item), refused by its owner with nothing stored (`refused`), or of unknown outcome (`unknown`), which keeps
|
|
61
|
+
* its fence until the owner checks again (`checking`). An answer is never sent again on its own.
|
|
62
|
+
*/
|
|
63
|
+
export type TInboxAnswerPhase = 'sending' | 'answered' | 'refused' | 'unknown' | 'checking';
|
|
64
|
+
|
|
65
|
+
/** What the Inbox keeps for one item while the owner answers it: the cards' drafts and where the answer stands. */
|
|
66
|
+
export interface IInboxItemState {
|
|
67
|
+
/** The feed's generation the state belongs to: once `clear()` moved on, nothing records into it any more. */
|
|
68
|
+
readonly generation: number;
|
|
69
|
+
/** The item as it was last listed or answered. */
|
|
70
|
+
item: TInboxItem;
|
|
71
|
+
phase?: TInboxAnswerPhase;
|
|
72
|
+
/** What the card says beside the draft: the refusal, the stored answer or that the outcome is unknown. */
|
|
73
|
+
message?: string;
|
|
74
|
+
/** The unknown-outcome text of the last answer, which a failed check shows with its own reason. */
|
|
75
|
+
outcome?: string;
|
|
76
|
+
/**
|
|
77
|
+
* Shown after the item left the list, until the owner moves on: a refused answer whose question another client
|
|
78
|
+
* answered keeps the owner's draft beside the answer that stands.
|
|
79
|
+
*/
|
|
80
|
+
held?: boolean;
|
|
81
|
+
/** The question cards' drafts and answers, by card id. */
|
|
82
|
+
questions: Map<string, plugins.deesCatalog.IHarnessQuestionViewState>;
|
|
83
|
+
/** The permission card's answer, kept while its outcome is unknown. */
|
|
84
|
+
permission: plugins.deesCatalog.IHarnessPermissionViewState;
|
|
85
|
+
/** The answers of a request that asks several questions, by question, until the last is answered. */
|
|
86
|
+
batch: Map<number, string[]>;
|
|
87
|
+
/** The item's MCP form card, which keeps the refusal on it. */
|
|
88
|
+
elicitation: ElicitationCards;
|
|
89
|
+
/** Counts the owner's attempts on a permission: a refused one shows a fresh card. */
|
|
90
|
+
attempt: number;
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
/** How the feed reads the Inbox: `controller.inbox.list` on the current connection. */
|
|
94
|
+
export interface IInboxFeedSource {
|
|
95
|
+
list(): Promise<unknown>;
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
/**
|
|
99
|
+
* The Inbox as the browser holds it: the controller's list, kept current by `inbox.changed` deltas the way the session
|
|
100
|
+
* list keeps its feed (a delta applies only on its epoch at the next revision; a gap, another epoch or a reset lists
|
|
101
|
+
* again, and deltas that arrive while it lists apply on top). The controller sorts; the feed keeps its order. It also
|
|
102
|
+
* keeps, per item, what the owner entered and where an answer stands, so a fence on an unknown outcome outlives
|
|
103
|
+
* leaving the view. Listeners hear every change.
|
|
104
|
+
*/
|
|
105
|
+
export class InboxFeed {
|
|
106
|
+
public items: readonly TInboxItem[] = [];
|
|
107
|
+
public total = 0;
|
|
108
|
+
public limited = false;
|
|
109
|
+
/** Whether a listing has been applied since the feed was cleared. */
|
|
110
|
+
public loaded = false;
|
|
111
|
+
public loading = false;
|
|
112
|
+
/** Why the last listing failed; the next delta lists again. */
|
|
113
|
+
public error = '';
|
|
114
|
+
private epoch = '';
|
|
115
|
+
private revision = 0;
|
|
116
|
+
private buffered: interfaces.TControllerInboxDelta[] | undefined;
|
|
117
|
+
private requestId = 0;
|
|
118
|
+
/** The last request whose listing settled while it was the newest, and whether it was applied. */
|
|
119
|
+
private settled = { requestId: 0, applied: false };
|
|
120
|
+
/** Counts `clear()`: a listing, a state or an answer from before one changes nothing after it. */
|
|
121
|
+
private generationCount = 0;
|
|
122
|
+
private readonly reads = new Map<number, Promise<void>>();
|
|
123
|
+
private readonly states = new Map<string, IInboxItemState>();
|
|
124
|
+
private readonly listeners = new Set<() => void>();
|
|
125
|
+
|
|
126
|
+
constructor(private readonly source: IInboxFeedSource) {}
|
|
127
|
+
|
|
128
|
+
/** Calls `listenerArg` on every change until the returned function is called. */
|
|
129
|
+
public subscribe(listenerArg: () => void): () => void {
|
|
130
|
+
this.listeners.add(listenerArg);
|
|
131
|
+
return () => { this.listeners.delete(listenerArg); };
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
/**
|
|
135
|
+
* Lists the Inbox. Resolves once a listing issued after the call has been applied (`true`) or has failed (`false`,
|
|
136
|
+
* with `error` set): a newer call's listing wins over an older one, and the older call waits for it and reports it.
|
|
137
|
+
* A `clear()` before the listing settles drops it: `false`.
|
|
138
|
+
*/
|
|
139
|
+
public async refresh(): Promise<boolean> {
|
|
140
|
+
const generation = this.generationCount;
|
|
141
|
+
let requestId = this.startRead();
|
|
142
|
+
for (;;) {
|
|
143
|
+
await this.reads.get(requestId);
|
|
144
|
+
if (generation !== this.generationCount) return false;
|
|
145
|
+
if (!this.reads.has(this.requestId)) return this.settled.requestId === this.requestId && this.settled.applied;
|
|
146
|
+
requestId = this.requestId;
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
/** Applies one `inbox.changed` delta on top of the revision held; anything else lists again. */
|
|
151
|
+
public apply(deltaArg: unknown): void {
|
|
152
|
+
if (!isControllerInboxDelta(deltaArg)) {
|
|
153
|
+
void this.refresh();
|
|
154
|
+
return;
|
|
155
|
+
}
|
|
156
|
+
if (this.buffered) {
|
|
157
|
+
if (this.buffered.length < interfaces.controllerInboxLimits.deltaItems) this.buffered.push(deltaArg);
|
|
158
|
+
else {
|
|
159
|
+
// More changes than a listing should wait for: a fresh listing reads them all at once.
|
|
160
|
+
this.buffered = undefined;
|
|
161
|
+
void this.refresh();
|
|
162
|
+
}
|
|
163
|
+
return;
|
|
164
|
+
}
|
|
165
|
+
if (deltaArg.epoch === this.epoch && deltaArg.revision <= this.revision) return;
|
|
166
|
+
if ('reset' in deltaArg || deltaArg.epoch !== this.epoch || deltaArg.revision !== this.revision + 1) {
|
|
167
|
+
void this.refresh();
|
|
168
|
+
return;
|
|
169
|
+
}
|
|
170
|
+
const byId = new Map(this.items.map((itemArg) => [itemArg.id, itemArg]));
|
|
171
|
+
for (const id of deltaArg.removed) byId.delete(id);
|
|
172
|
+
for (const item of deltaArg.upserts) byId.set(item.id, item);
|
|
173
|
+
const items = deltaArg.order.map((idArg) => byId.get(idArg));
|
|
174
|
+
if (items.some((itemArg) => itemArg === undefined)) {
|
|
175
|
+
void this.refresh();
|
|
176
|
+
return;
|
|
177
|
+
}
|
|
178
|
+
this.items = items as TInboxItem[];
|
|
179
|
+
this.total = deltaArg.total;
|
|
180
|
+
this.limited = deltaArg.limited;
|
|
181
|
+
this.revision = deltaArg.revision;
|
|
182
|
+
this.settleStates();
|
|
183
|
+
this.notify();
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
/** Forgets everything, for a sign-out: a listing still on its way is dropped. */
|
|
187
|
+
public clear(): void {
|
|
188
|
+
this.generationCount += 1;
|
|
189
|
+
this.requestId += 1;
|
|
190
|
+
this.reads.clear();
|
|
191
|
+
this.items = [];
|
|
192
|
+
this.total = 0;
|
|
193
|
+
this.limited = false;
|
|
194
|
+
this.loaded = false;
|
|
195
|
+
this.loading = false;
|
|
196
|
+
this.error = '';
|
|
197
|
+
this.epoch = '';
|
|
198
|
+
this.revision = 0;
|
|
199
|
+
this.buffered = undefined;
|
|
200
|
+
this.states.clear();
|
|
201
|
+
this.notify();
|
|
202
|
+
}
|
|
203
|
+
|
|
204
|
+
/** The listed item `idArg`, or the held one the owner still looks at. */
|
|
205
|
+
public find(idArg: string): TInboxItem | undefined {
|
|
206
|
+
return this.items.find((itemArg) => itemArg.id === idArg) ?? (this.states.get(idArg)?.held ? this.states.get(idArg)!.item : undefined);
|
|
207
|
+
}
|
|
208
|
+
|
|
209
|
+
/** Whether the controller lists `idArg`. */
|
|
210
|
+
public listed(idArg: string): boolean {
|
|
211
|
+
return this.items.some((itemArg) => itemArg.id === idArg);
|
|
212
|
+
}
|
|
213
|
+
|
|
214
|
+
/** What the Inbox keeps for `itemArg` while the owner answers it, made on first use. */
|
|
215
|
+
public state(itemArg: TInboxItem): IInboxItemState {
|
|
216
|
+
let state = this.states.get(itemArg.id);
|
|
217
|
+
if (!state) {
|
|
218
|
+
state = { generation: this.generationCount, item: itemArg, questions: new Map(), permission: {}, batch: new Map(), elicitation: new ElicitationCards(() => itemArg.id), attempt: 0 };
|
|
219
|
+
this.states.set(itemArg.id, state);
|
|
220
|
+
} else if (!state.held) {
|
|
221
|
+
state.item = itemArg;
|
|
222
|
+
}
|
|
223
|
+
return state;
|
|
224
|
+
}
|
|
225
|
+
|
|
226
|
+
/** Whether `stateArg` belongs to the feed's generation, so an answer's outcome still records into it. */
|
|
227
|
+
public holds(stateArg: IInboxItemState): boolean {
|
|
228
|
+
return stateArg.generation === this.generationCount;
|
|
229
|
+
}
|
|
230
|
+
|
|
231
|
+
/** The state of `idArg` if the Inbox keeps one. */
|
|
232
|
+
public peek(idArg: string): IInboxItemState | undefined {
|
|
233
|
+
return this.states.get(idArg);
|
|
234
|
+
}
|
|
235
|
+
|
|
236
|
+
/**
|
|
237
|
+
* Records where the answer to `stateArg`'s item stands. A state whose item left the list is dropped once its answer
|
|
238
|
+
* settled, unless it is `held` for the owner to read. A state from before a `clear()` changes nothing.
|
|
239
|
+
*/
|
|
240
|
+
public update(stateArg: IInboxItemState, changeArg: Pick<IInboxItemState, 'phase' | 'message' | 'held'>): void {
|
|
241
|
+
if (!this.holds(stateArg)) return;
|
|
242
|
+
stateArg.phase = changeArg.phase;
|
|
243
|
+
stateArg.message = changeArg.message;
|
|
244
|
+
stateArg.held = changeArg.held;
|
|
245
|
+
if (!this.states.has(stateArg.item.id) && (changeArg.held || this.listed(stateArg.item.id))) this.states.set(stateArg.item.id, stateArg);
|
|
246
|
+
this.settleStates();
|
|
247
|
+
this.notify();
|
|
248
|
+
}
|
|
249
|
+
|
|
250
|
+
/** The owner moved on from a held item: it goes. */
|
|
251
|
+
public release(idArg: string): void {
|
|
252
|
+
const state = this.states.get(idArg);
|
|
253
|
+
if (!state?.held) return;
|
|
254
|
+
state.held = false;
|
|
255
|
+
this.settleStates();
|
|
256
|
+
this.notify();
|
|
257
|
+
}
|
|
258
|
+
|
|
259
|
+
/** The waiting items per chip, All included. */
|
|
260
|
+
public counts(): Record<interfaces.TControllerInboxChip, number> {
|
|
261
|
+
const counts: Record<interfaces.TControllerInboxChip, number> = { all: 0, sessions: 0, board: 0, deploys: 0 };
|
|
262
|
+
for (const item of this.items) {
|
|
263
|
+
counts.all += 1;
|
|
264
|
+
counts[interfaces.controllerInboxChipOf(item.kind)] += 1;
|
|
265
|
+
}
|
|
266
|
+
return counts;
|
|
267
|
+
}
|
|
268
|
+
|
|
269
|
+
private startRead(): number {
|
|
270
|
+
const requestId = ++this.requestId;
|
|
271
|
+
this.buffered ??= [];
|
|
272
|
+
this.loading = true;
|
|
273
|
+
this.notify();
|
|
274
|
+
const read = this.read(requestId).finally(() => { this.reads.delete(requestId); });
|
|
275
|
+
this.reads.set(requestId, read);
|
|
276
|
+
return requestId;
|
|
277
|
+
}
|
|
278
|
+
|
|
279
|
+
private async read(requestIdArg: number): Promise<void> {
|
|
280
|
+
try {
|
|
281
|
+
const snapshot = await this.source.list();
|
|
282
|
+
if (requestIdArg !== this.requestId) return;
|
|
283
|
+
if (!isControllerInboxSnapshot(snapshot)) throw new Error('The controller returned an invalid Inbox.');
|
|
284
|
+
this.epoch = snapshot.epoch;
|
|
285
|
+
this.revision = snapshot.revision;
|
|
286
|
+
this.items = snapshot.items;
|
|
287
|
+
this.total = snapshot.total;
|
|
288
|
+
this.limited = snapshot.limited;
|
|
289
|
+
this.loaded = true;
|
|
290
|
+
this.loading = false;
|
|
291
|
+
this.error = '';
|
|
292
|
+
this.settled = { requestId: requestIdArg, applied: true };
|
|
293
|
+
const buffered = this.buffered ?? [];
|
|
294
|
+
this.buffered = undefined;
|
|
295
|
+
this.settleStates();
|
|
296
|
+
this.notify();
|
|
297
|
+
for (const delta of buffered) this.apply(delta);
|
|
298
|
+
} catch (errorArg) {
|
|
299
|
+
if (requestIdArg !== this.requestId) return;
|
|
300
|
+
// The next delta lists again.
|
|
301
|
+
this.loading = false;
|
|
302
|
+
this.buffered = undefined;
|
|
303
|
+
this.error = errorArg instanceof Error && errorArg.message ? errorArg.message : 'The Inbox could not be listed.';
|
|
304
|
+
this.settled = { requestId: requestIdArg, applied: false };
|
|
305
|
+
this.notify();
|
|
306
|
+
}
|
|
307
|
+
}
|
|
308
|
+
|
|
309
|
+
/**
|
|
310
|
+
* Drops the states of items that left the list, except an answer still on its way, being checked or held for the
|
|
311
|
+
* owner, and takes the listed item into each state that stays.
|
|
312
|
+
*/
|
|
313
|
+
private settleStates(): void {
|
|
314
|
+
const listed = new Map(this.items.map((itemArg) => [itemArg.id, itemArg]));
|
|
315
|
+
for (const [id, state] of this.states) {
|
|
316
|
+
const item = listed.get(id);
|
|
317
|
+
if (item) {
|
|
318
|
+
if (!state.held) state.item = item;
|
|
319
|
+
continue;
|
|
320
|
+
}
|
|
321
|
+
if (state.held || state.phase === 'sending' || state.phase === 'checking') continue;
|
|
322
|
+
this.states.delete(id);
|
|
323
|
+
}
|
|
324
|
+
}
|
|
325
|
+
|
|
326
|
+
private notify(): void {
|
|
327
|
+
for (const listener of [...this.listeners]) listener();
|
|
328
|
+
}
|
|
329
|
+
}
|
|
@@ -4,6 +4,7 @@ import type { ISessionChatHandlers, ISessionChatView } from './functions.session
|
|
|
4
4
|
import { sessionIntelligenceAvailabilityAction } from './functions.sessionchat.js';
|
|
5
5
|
import { errorText, type IFleetWorkerSender } from './elements.fleetworker.js';
|
|
6
6
|
import { ElicitationCards, elicitationReply } from './classes.elicitationcards.js';
|
|
7
|
+
import { permissionCard, questionCardId, questionCards } from './functions.sessioncards.js';
|
|
7
8
|
|
|
8
9
|
/** The element a session's state belongs to: it renders the state and hears the settings remedy. */
|
|
9
10
|
export interface INativeSessionStateHost {
|
|
@@ -27,17 +28,9 @@ const refKey = (refArg: interfaces.IControllerNativeSessionRef): string => (
|
|
|
27
28
|
JSON.stringify([refArg.harness, refArg.nativeId, refArg.profileId ?? null])
|
|
28
29
|
);
|
|
29
30
|
|
|
30
|
-
const permissionCard = (requestArg: interfaces.IControllerPermission): plugins.deesCatalog.IHarnessPermissionRequest => ({
|
|
31
|
-
id: requestArg.id.nativeId,
|
|
32
|
-
...(requestArg.createdAt === undefined ? {} : { createdAt: requestArg.createdAt }),
|
|
33
|
-
title: requestArg.title || 'Permission requested',
|
|
34
|
-
type: requestArg.type,
|
|
35
|
-
metadata: { ...(requestArg.patterns.length > 0 ? { patterns: requestArg.patterns } : {}), ...requestArg.metadata },
|
|
36
|
-
});
|
|
37
|
-
|
|
38
31
|
/** A question request's cards: one per question, numbered when the request asks several. */
|
|
39
|
-
const
|
|
40
|
-
requestArg.
|
|
32
|
+
const questionCardIdOf = (requestArg: interfaces.IControllerQuestion, indexArg: number): string => (
|
|
33
|
+
questionCardId(requestArg.id.nativeId, requestArg.questions.length, indexArg)
|
|
41
34
|
);
|
|
42
35
|
|
|
43
36
|
/**
|
|
@@ -258,7 +251,7 @@ export class NativeSessionState {
|
|
|
258
251
|
: [];
|
|
259
252
|
if (answers.length === 0) return;
|
|
260
253
|
for (const request of this.response?.questions ?? []) {
|
|
261
|
-
const index = request.questions.findIndex((_questionArg, indexArg) =>
|
|
254
|
+
const index = request.questions.findIndex((_questionArg, indexArg) => questionCardIdOf(request, indexArg) === detail.requestId);
|
|
262
255
|
if (index < 0) continue;
|
|
263
256
|
this.answeredQuestions.set(detail.requestId, { ...detail.request, response: answers, respondedAt: Date.now() });
|
|
264
257
|
this.rebuildCards();
|
|
@@ -411,22 +404,15 @@ export class NativeSessionState {
|
|
|
411
404
|
const pendingPermissions = new Set(response?.permissions.map((requestArg) => requestArg.id.nativeId));
|
|
412
405
|
for (const id of this.answeredPermissions.keys()) if (!pendingPermissions.has(id)) this.answeredPermissions.delete(id);
|
|
413
406
|
this.permissionCards = (response?.permissions ?? []).map((requestArg) => (
|
|
414
|
-
this.answeredPermissions.get(requestArg.id.nativeId) ?? permissionCard(requestArg)
|
|
407
|
+
this.answeredPermissions.get(requestArg.id.nativeId) ?? permissionCard(requestArg, requestArg.id.nativeId)
|
|
415
408
|
));
|
|
416
409
|
const cards: plugins.deesCatalog.IHarnessQuestionRequest[] = [];
|
|
417
410
|
const pendingQuestions = new Set<string>();
|
|
418
411
|
for (const request of response?.questions ?? []) {
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
id,
|
|
424
|
-
question: questionArg.question,
|
|
425
|
-
options: questionArg.options.map((optionArg) => ({ label: optionArg.label, description: optionArg.description })),
|
|
426
|
-
multiSelect: questionArg.multiple === true,
|
|
427
|
-
allowCustom: questionArg.custom !== false,
|
|
428
|
-
});
|
|
429
|
-
});
|
|
412
|
+
for (const card of questionCards(request, request.id.nativeId)) {
|
|
413
|
+
pendingQuestions.add(card.id);
|
|
414
|
+
cards.push(this.answeredQuestions.get(card.id) ?? card);
|
|
415
|
+
}
|
|
430
416
|
}
|
|
431
417
|
for (const id of this.answeredQuestions.keys()) if (!pendingQuestions.has(id)) this.answeredQuestions.delete(id);
|
|
432
418
|
this.questionCards = cards;
|
|
@@ -31,6 +31,8 @@ import {
|
|
|
31
31
|
preuseView,
|
|
32
32
|
maxUsageReason,
|
|
33
33
|
recheckNotice,
|
|
34
|
+
renewalFact,
|
|
35
|
+
renewalReason,
|
|
34
36
|
renameReason,
|
|
35
37
|
servicePanel,
|
|
36
38
|
spendLimitDraft,
|
|
@@ -136,6 +138,10 @@ const apiKeyProviderName = (providerIdArg: interfaces.TControllerApiKeyProvider)
|
|
|
136
138
|
providerIdArg === 'openai' ? 'OpenAI' : 'Anthropic'
|
|
137
139
|
);
|
|
138
140
|
|
|
141
|
+
/** What a renewal does, under its field. */
|
|
142
|
+
const renewalDescription = 'Any date and time the subscription renewed or renews; it renews monthly from there. Usage a'
|
|
143
|
+
+ ' window would still hold at the next renewal is used first. Whether Claude resets usage at a renewal is not known.';
|
|
144
|
+
|
|
139
145
|
/** What a usage threshold does, under its field. */
|
|
140
146
|
const maxUsageDescription = 'At this share of any usage window AGL places no new work on the account and moves its'
|
|
141
147
|
+ ' sessions on, so the rest stays yours outside AGL.';
|
|
@@ -268,6 +274,10 @@ export class AglAccounts extends plugins.deesElement.DeesElement {
|
|
|
268
274
|
@plugins.deesElement.state()
|
|
269
275
|
private accessor maxUsageDraft: string | null = null;
|
|
270
276
|
|
|
277
|
+
/** A Claude sign-in's renewal as the open page's field holds it while edited; `null` while it shows the saved one. */
|
|
278
|
+
@plugins.deesElement.state()
|
|
279
|
+
private accessor renewalDraft: string | null = null;
|
|
280
|
+
|
|
271
281
|
/** A key's spend limit, in dollars, as the open page's field holds it while edited; `null` while it shows the saved one. */
|
|
272
282
|
@plugins.deesElement.state()
|
|
273
283
|
private accessor spendLimitDraft: string | null = null;
|
|
@@ -988,6 +998,24 @@ export class AglAccounts extends plugins.deesElement.DeesElement {
|
|
|
988
998
|
});
|
|
989
999
|
}
|
|
990
1000
|
|
|
1001
|
+
/**
|
|
1002
|
+
* Sets a Claude sign-in's renewal from the field, or clears it with `null`. The field is read here, in the page's own
|
|
1003
|
+
* time zone, and sent as its UTC instant, so the accounts service never reads a local time in its own zone.
|
|
1004
|
+
*/
|
|
1005
|
+
private async setRenewal(rowArg: IAccountRow, draftArg: string | null): Promise<void> {
|
|
1006
|
+
const renewsAt = draftArg === null ? null : new Date(Date.parse(draftArg.trim())).toISOString();
|
|
1007
|
+
await this.runAction(`renewal:${rowArg.accountId}`, async () => {
|
|
1008
|
+
const { answer } = await this.client!.fire<interfaces.IReq_ControllerAccountsRenewal>(
|
|
1009
|
+
'controller.accounts.renewal',
|
|
1010
|
+
{ accountId: rowArg.accountId, expectedRevision: rowArg.revision, renewsAt },
|
|
1011
|
+
{ maxRetries: 0 },
|
|
1012
|
+
);
|
|
1013
|
+
this.notice = answerNotice(answer);
|
|
1014
|
+
if (answer.state === 'done') this.renewalDraft = null;
|
|
1015
|
+
await this.refresh();
|
|
1016
|
+
});
|
|
1017
|
+
}
|
|
1018
|
+
|
|
991
1019
|
/** Sets an API key's monthly spend limit from the field, in dollars, or clears it with `null`. */
|
|
992
1020
|
private async setSpendLimit(rowArg: IAccountRow, spendLimitMicroUsdArg: number | null): Promise<void> {
|
|
993
1021
|
await this.runAction(`spendlimit:${rowArg.accountId}`, async () => {
|
|
@@ -1373,6 +1401,7 @@ export class AglAccounts extends plugins.deesElement.DeesElement {
|
|
|
1373
1401
|
this.openKey = rowArg.key;
|
|
1374
1402
|
this.renaming = false;
|
|
1375
1403
|
this.maxUsageDraft = null;
|
|
1404
|
+
this.renewalDraft = null;
|
|
1376
1405
|
this.spendLimitDraft = null;
|
|
1377
1406
|
}
|
|
1378
1407
|
|
|
@@ -1566,6 +1595,56 @@ export class AglAccounts extends plugins.deesElement.DeesElement {
|
|
|
1566
1595
|
`;
|
|
1567
1596
|
}
|
|
1568
1597
|
|
|
1598
|
+
/**
|
|
1599
|
+
* A Claude sign-in's monthly renewal: any date and time the subscription renewed or renews, saved with its own Save,
|
|
1600
|
+
* or cleared. AGL then spends first the usage a window would still hold at the next renewal.
|
|
1601
|
+
*/
|
|
1602
|
+
private renderRenewal(rowArg: IAccountRow, slotArg: IAccountActionSlot): plugins.deesElement.TemplateResult {
|
|
1603
|
+
const saved = rowArg.renewsAt;
|
|
1604
|
+
if (saved === null && this.renewalDraft === null) {
|
|
1605
|
+
return plugins.deesElement.html`
|
|
1606
|
+
<div class="item" data-renewal>
|
|
1607
|
+
<div>
|
|
1608
|
+
<div class="itemLabel">Renewal</div>
|
|
1609
|
+
<div class="itemText">Not set. Set the date and time the subscription renews each month, and AGL uses first
|
|
1610
|
+
the usage that would still be left at the renewal.</div>
|
|
1611
|
+
</div>
|
|
1612
|
+
${this.slots([slotArg], () => { this.renewalDraft = ''; }, () => 'Set the renewal…')}
|
|
1613
|
+
</div>
|
|
1614
|
+
`;
|
|
1615
|
+
}
|
|
1616
|
+
const draft = this.renewalDraft ?? saved!;
|
|
1617
|
+
const reason = slotArg.reason || renewalReason(draft, saved);
|
|
1618
|
+
return plugins.deesElement.html`
|
|
1619
|
+
<div class="item stacked" data-renewal>
|
|
1620
|
+
<div>
|
|
1621
|
+
<div class="itemLabel">Renewal</div>
|
|
1622
|
+
<div class="itemText">${renewalDescription}${saved === null ? ''
|
|
1623
|
+
: ` Next: ${renewalFact(saved, Date.now())}.`}</div>
|
|
1624
|
+
</div>
|
|
1625
|
+
<div class="inline">
|
|
1626
|
+
<dees-input-text .label=${'Renewal (date and time)'} .labelPosition=${'none'} .value=${draft}
|
|
1627
|
+
@input=${(eventArg: Event) => {
|
|
1628
|
+
const target = eventArg.currentTarget as HTMLElement & { value?: string };
|
|
1629
|
+
this.renewalDraft = target.value ?? '';
|
|
1630
|
+
}}></dees-input-text>
|
|
1631
|
+
<div>${this.slots(
|
|
1632
|
+
[
|
|
1633
|
+
{ id: 'renewal', label: 'Save', icon: 'lucide:Check', reason },
|
|
1634
|
+
...(saved === null ? []
|
|
1635
|
+
: [{ id: 'clearRenewal' as const, label: 'No renewal', icon: 'lucide:X', reason: slotArg.reason }]),
|
|
1636
|
+
],
|
|
1637
|
+
(runArg) => void this.setRenewal(rowArg, runArg.id === 'clearRenewal' ? null : draft),
|
|
1638
|
+
)}</div>
|
|
1639
|
+
${saved === null
|
|
1640
|
+
? plugins.deesElement.html`<dees-button size="sm" type="ghost" text="Keep it unset" data-action="keepRenewal"
|
|
1641
|
+
@clicked=${() => { this.renewalDraft = null; }}></dees-button>`
|
|
1642
|
+
: ''}
|
|
1643
|
+
</div>
|
|
1644
|
+
</div>
|
|
1645
|
+
`;
|
|
1646
|
+
}
|
|
1647
|
+
|
|
1569
1648
|
/**
|
|
1570
1649
|
* An API key's monthly spend limit in dollars, saved with its own Save, or removed so the key serves without one. A
|
|
1571
1650
|
* limit below what the month spent holds the key at its next request.
|
|
@@ -1623,6 +1702,7 @@ export class AglAccounts extends plugins.deesElement.DeesElement {
|
|
|
1623
1702
|
?? rowArg.actions.find((slotArg) => slotArg.id === idArg) ?? null;
|
|
1624
1703
|
const renameSlot = slot('rename');
|
|
1625
1704
|
const maxUsageSlot = slot('maxUsage');
|
|
1705
|
+
const renewalSlot = slot('renewal');
|
|
1626
1706
|
const spendLimitSlot = slot('spendLimit');
|
|
1627
1707
|
const claudeCodeSlot = slot('claudeCode');
|
|
1628
1708
|
const liftSlot = slot('liftReserve');
|
|
@@ -1732,6 +1812,7 @@ export class AglAccounts extends plugins.deesElement.DeesElement {
|
|
|
1732
1812
|
<div class="sectionHead"><span>Limits</span></div>
|
|
1733
1813
|
<div class="card">
|
|
1734
1814
|
${this.renderMaxUsage(rowArg, this.effectiveSlot(maxUsageSlot))}
|
|
1815
|
+
${renewalSlot ? this.renderRenewal(rowArg, this.effectiveSlot(renewalSlot)) : ''}
|
|
1735
1816
|
${liftSlot
|
|
1736
1817
|
? plugins.deesElement.html`<div class="item" data-lift>
|
|
1737
1818
|
<div>
|