agl 43.2.0 → 43.3.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/changelog.md +29 -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.authstore.d.ts +7 -0
- package/dist_ts/classes.authstore.js +9 -1
- package/dist_ts/classes.claudeharness.d.ts +29 -2
- package/dist_ts/classes.claudeharness.js +35 -6
- package/dist_ts/classes.codexclientadapter.d.ts +11 -0
- package/dist_ts/classes.codexclientadapter.js +14 -2
- package/dist_ts/classes.controller.d.ts +187 -12
- package/dist_ts/classes.controller.js +1208 -186
- 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 +6 -1
- package/dist_ts/classes.mcptools.js +18 -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 +29 -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/classes.workercallers.js +4 -2
- package/dist_ts/driver/classes.directreports.d.ts +14 -4
- package/dist_ts/driver/classes.directreports.js +42 -23
- package/dist_ts/driver/classes.directreportstore.d.ts +8 -1
- package/dist_ts/driver/classes.directreportstore.js +20 -10
- 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 +21 -1
- package/dist_ts/fleet/classes.workers.js +80 -40
- package/dist_ts/fleet/classes.workerstore.js +14 -8
- package/dist_ts/fleet/functions.unbounddrivers.js +2 -2
- package/dist_ts/fleet/functions.workervalidation.js +11 -4
- package/dist_ts/fleet/interfaces.workers.d.ts +27 -5
- package/dist_ts/fleet/interfaces.workers.js +8 -4
- package/dist_ts/functions.agentmessage.d.ts +3 -0
- package/dist_ts/functions.agentmessage.js +4 -1
- package/dist_ts/functions.deviceapi.d.ts +198 -4
- package/dist_ts/functions.deviceapi.js +1060 -38
- package/dist_ts/functions.exactpersistence.d.ts +3 -0
- package/dist_ts/functions.exactpersistence.js +4 -0
- 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 +3 -3
- package/dist_ts/functions.ticketactor.d.ts +17 -1
- package/dist_ts/functions.ticketactor.js +55 -15
- 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 +1027 -7
- package/dist_ts_interfaces/devices.js +68 -2
- package/dist_ts_interfaces/fleetworkers.d.ts +37 -10
- package/dist_ts_interfaces/fleetworkers.js +19 -8
- 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/dist_ts_interfaces/workercallers.d.ts +2 -0
- package/dist_ts_migration/classes.documentmigrationrunner.d.ts +14 -0
- package/dist_ts_migration/classes.documentmigrationrunner.js +20 -1
- package/dist_ts_migration/index.d.ts +1 -0
- package/dist_ts_migration/index.js +2 -1
- package/dist_ts_migration/v43_ticketactornames.d.ts +32 -0
- package/dist_ts_migration/v43_ticketactornames.js +236 -0
- package/docs/authswitch.md +20 -1
- package/package.json +3 -3
- package/readme.md +144 -27
- 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.authstore.ts +10 -0
- package/ts/classes.claudeharness.ts +45 -5
- package/ts/classes.codexclientadapter.ts +14 -1
- package/ts/classes.controller.ts +1412 -262
- 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 +5 -0
- package/ts/classes.mcptools.ts +17 -7
- package/ts/classes.mcpvalidation.ts +27 -1
- package/ts/classes.nativesessions.ts +63 -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/classes.workercallers.ts +3 -1
- package/ts/driver/classes.directreports.ts +42 -23
- package/ts/driver/classes.directreportstore.ts +20 -9
- 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 +75 -41
- package/ts/fleet/classes.workerstore.ts +11 -7
- package/ts/fleet/functions.unbounddrivers.ts +1 -1
- package/ts/fleet/functions.workervalidation.ts +8 -3
- package/ts/fleet/interfaces.workers.ts +26 -7
- package/ts/functions.agentmessage.ts +3 -0
- package/ts/functions.deviceapi.ts +1292 -34
- package/ts/functions.exactpersistence.ts +5 -0
- package/ts/functions.fleetworkercli.ts +10 -7
- package/ts/functions.inferencecli.ts +2 -0
- package/ts/functions.mcpfleetworkertools.ts +2 -2
- package/ts/functions.ticketactor.ts +58 -14
- 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 +3576 -603
- package/ts_interfaces/devices.ts +1111 -6
- package/ts_interfaces/fleetworkers.ts +38 -10
- 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_interfaces/workercallers.ts +2 -0
- package/ts_migration/classes.documentmigrationrunner.ts +21 -0
- package/ts_migration/index.ts +1 -0
- package/ts_migration/v43_ticketactornames.ts +225 -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.fleetworker.ts +4 -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
|
@@ -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>
|
|
@@ -978,10 +978,23 @@ export class AglDeployPlan extends plugins.deesElement.DeesElement {
|
|
|
978
978
|
}
|
|
979
979
|
}
|
|
980
980
|
|
|
981
|
+
/** When a go's deploy may run, for the Inbox's go: the target's condition and the window the deploy would run in. */
|
|
982
|
+
const inboxDeployWhenText = (planArg: interfaces.IControllerInboxDeployGo): string | undefined => {
|
|
983
|
+
switch (planArg.deployWhen) {
|
|
984
|
+
case undefined: return undefined;
|
|
985
|
+
case 'anytime': return 'At any time.';
|
|
986
|
+
case 'idle': return 'When no session is busy.';
|
|
987
|
+
case 'window': return planArg.window
|
|
988
|
+
? `Inside the maintenance window ${deployWindowRange(planArg.window)}.`
|
|
989
|
+
: 'Only inside a maintenance window; none is planned.';
|
|
990
|
+
}
|
|
991
|
+
};
|
|
992
|
+
|
|
981
993
|
/**
|
|
982
994
|
* The go dialog's body: the question of a deploy plan (what each answer does for the target, and who deploys it) or of a
|
|
983
995
|
* maintenance window the driver proposed (its time and targets). The answer is the owner's, as on the ticket; the
|
|
984
|
-
* dialog's buttons send it.
|
|
996
|
+
* dialog's buttons send it. The Inbox shows a go from what its item carries instead (`inboxPlan`, `inboxWindow`): what
|
|
997
|
+
* the target runs, what it deploys and what ships with it.
|
|
985
998
|
*/
|
|
986
999
|
@plugins.deesElement.customElement('agl-deploy-go')
|
|
987
1000
|
export class AglDeployGo extends plugins.deesElement.DeesElement {
|
|
@@ -1008,6 +1021,14 @@ export class AglDeployGo extends plugins.deesElement.DeesElement {
|
|
|
1008
1021
|
@plugins.deesElement.property({ attribute: false })
|
|
1009
1022
|
accessor question: interfaces.ITicketQuestion | undefined;
|
|
1010
1023
|
|
|
1024
|
+
/** A deploy plan's go as the Inbox lists it, in place of `target` and `plan`. */
|
|
1025
|
+
@plugins.deesElement.property({ attribute: false })
|
|
1026
|
+
accessor inboxPlan: interfaces.IControllerInboxDeployGo | undefined;
|
|
1027
|
+
|
|
1028
|
+
/** A proposed maintenance window's go as the Inbox lists it, in place of `window`. */
|
|
1029
|
+
@plugins.deesElement.property({ attribute: false })
|
|
1030
|
+
accessor inboxWindow: interfaces.IControllerInboxWindowGo | undefined;
|
|
1031
|
+
|
|
1011
1032
|
@plugins.deesElement.state()
|
|
1012
1033
|
accessor error = '';
|
|
1013
1034
|
|
|
@@ -1022,7 +1043,14 @@ export class AglDeployGo extends plugins.deesElement.DeesElement {
|
|
|
1022
1043
|
];
|
|
1023
1044
|
|
|
1024
1045
|
public render(): plugins.deesElement.TemplateResult {
|
|
1025
|
-
const { target, plan, window, question } = this;
|
|
1046
|
+
const { target, plan, window, question, inboxPlan, inboxWindow } = this;
|
|
1047
|
+
if (question && inboxPlan) return this.renderGo(question, false, this.inboxPlanSections(inboxPlan));
|
|
1048
|
+
if (question && inboxWindow) return this.renderGo(question, true, [{ header: 'Maintenance window', rows: [
|
|
1049
|
+
{ key: 'time', label: 'When', icon: 'lucide:Clock', description: deployWindowRange(inboxWindow) },
|
|
1050
|
+
{ key: 'targets', label: 'Targets', icon: 'lucide:Server', description: inboxWindow.targets.join(', ') },
|
|
1051
|
+
{ key: 'what', label: 'What it does', icon: 'lucide:Info',
|
|
1052
|
+
description: 'Approved, the targets that deploy only in a window may be deployed in it, and the deploys you queued into the next window run then.' },
|
|
1053
|
+
] }]);
|
|
1026
1054
|
if (!question || !(target && plan) && !window) return html``;
|
|
1027
1055
|
const icons: Record<string, string> = window
|
|
1028
1056
|
? { [interfaces.ticketWindowOptions.approve]: 'lucide:CalendarCheck', [interfaces.ticketWindowOptions.decline]: 'lucide:CalendarX' }
|
|
@@ -1051,6 +1079,42 @@ export class AglDeployGo extends plugins.deesElement.DeesElement {
|
|
|
1051
1079
|
`;
|
|
1052
1080
|
}
|
|
1053
1081
|
|
|
1082
|
+
/** The Inbox's go: the question's options, then what the deploy does and what ships with it. */
|
|
1083
|
+
private renderGo(questionArg: interfaces.ITicketQuestion, windowArg: boolean,
|
|
1084
|
+
sectionsArg: plugins.deesCatalog.IGroupedListSection[]): plugins.deesElement.TemplateResult {
|
|
1085
|
+
const icons: Record<string, string> = windowArg
|
|
1086
|
+
? { [interfaces.ticketWindowOptions.approve]: 'lucide:CalendarCheck', [interfaces.ticketWindowOptions.decline]: 'lucide:CalendarX' }
|
|
1087
|
+
: { [interfaces.ticketDeployPlanOptions.now]: 'lucide:Rocket', [interfaces.ticketDeployPlanOptions.later]: 'lucide:CalendarClock',
|
|
1088
|
+
[interfaces.ticketDeployPlanOptions.hold]: 'lucide:CirclePause' };
|
|
1089
|
+
const answer = questionArg.answer;
|
|
1090
|
+
const options: plugins.deesCatalog.IGroupedListRow[] = questionArg.options.map((optionArg) => ({ key: optionArg.id, label: optionArg.label,
|
|
1091
|
+
icon: icons[optionArg.id] ?? 'lucide:Circle', ...(optionArg.description ? { description: optionArg.description } : {}),
|
|
1092
|
+
...(answer?.choices.includes(optionArg.id) ? { accessory: html`<dees-badge tone="success" text="the answer"></dees-badge>` } : {}) }));
|
|
1093
|
+
return html`
|
|
1094
|
+
<dees-grouped-list .inset=${false} .sections=${[{ header: answer ? 'Answered' : 'Your go', rows: options,
|
|
1095
|
+
...(answer ? { footer: `${answer.answeredBy.name} answered ${deployMoment(answer.answeredAt)}.` } : {}) }, ...sectionsArg]}></dees-grouped-list>
|
|
1096
|
+
`;
|
|
1097
|
+
}
|
|
1098
|
+
|
|
1099
|
+
/** What a deploy plan's go names: what runs, what it deploys, when and by whom, and the tickets that ship with it. */
|
|
1100
|
+
private inboxPlanSections(planArg: interfaces.IControllerInboxDeployGo): plugins.deesCatalog.IGroupedListSection[] {
|
|
1101
|
+
const when = inboxDeployWhenText(planArg);
|
|
1102
|
+
const more = planArg.shipsTotal - planArg.ships.length;
|
|
1103
|
+
return [
|
|
1104
|
+
{ header: [planArg.targetName ?? planArg.target, planArg.environment].filter(Boolean).join(' → '), rows: [
|
|
1105
|
+
{ key: 'runs', label: 'Runs now', icon: 'lucide:Server', value: planArg.runs ?? 'not observed yet' },
|
|
1106
|
+
{ key: 'deploys', label: 'Deploys', icon: 'lucide:Rocket', value: planArg.version },
|
|
1107
|
+
...(when === undefined ? [] : [{ key: 'when', label: 'When it deploys', icon: 'lucide:Clock', description: when }]),
|
|
1108
|
+
{ key: 'who', label: 'Who deploys', icon: 'lucide:User',
|
|
1109
|
+
description: planArg.assignee ? `${planArg.assignee}, as the plan's assignee` : 'The driver: the plan has no assignee.' },
|
|
1110
|
+
] },
|
|
1111
|
+
{ header: `What ships · ${planArg.shipsTotal} ticket${planArg.shipsTotal === 1 ? '' : 's'}`,
|
|
1112
|
+
rows: planArg.ships.map((shipArg) => ({ key: shipArg.key, label: shipArg.key, description: shipArg.title })),
|
|
1113
|
+
...(planArg.shipsTotal === 0 ? { footer: `No ticket that ${planArg.targetName ?? planArg.target} does not run yet ships with it.` }
|
|
1114
|
+
: more > 0 ? { footer: `And ${more} more.` } : {}) },
|
|
1115
|
+
];
|
|
1116
|
+
}
|
|
1117
|
+
|
|
1054
1118
|
/** Sends the owner's answer; resolves false with the reason shown when the controller refuses it. */
|
|
1055
1119
|
public async answer(optionIdArg: string): Promise<boolean> {
|
|
1056
1120
|
if (!this.sender || !this.subjectKey || !this.question) return false;
|
|
@@ -371,12 +371,14 @@ export class AglFleetWorker extends plugins.deesElement.DeesElement {
|
|
|
371
371
|
{ timeoutMs: steerTimeoutMs },
|
|
372
372
|
);
|
|
373
373
|
if (generation !== this.generation) return;
|
|
374
|
-
// A report that is a fleet worker answers with the steer job.
|
|
374
|
+
// A report that is a fleet worker answers with the steer job. One that failed after its dispatch may have delivered
|
|
375
|
+
// the message (`errorOutcome`): its outcome is unknown, as when the answer was lost.
|
|
375
376
|
const job = 'job' in response ? response.job : undefined;
|
|
376
377
|
if (!job || job.state === 'succeeded') {
|
|
377
378
|
this.draft = '';
|
|
378
379
|
this.attachments = noAttachments;
|
|
379
|
-
} else this.steerError = job.error ?? 'The fleet did not deliver the message.';
|
|
380
|
+
} else if (job.errorOutcome === 'refused') this.steerError = job.error ?? 'The fleet did not deliver the message.';
|
|
381
|
+
else this.steerError = `The steer's outcome is unknown (${job.error ?? 'the fleet job failed'}). Check the transcript before sending it again.`;
|
|
380
382
|
} catch (errorArg) {
|
|
381
383
|
if (generation !== this.generation) return;
|
|
382
384
|
this.steerError = errorArg instanceof plugins.typedrequest.TypedResponseError
|