agl 43.1.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 +32 -0
- package/dist_serve/bundle.js +5950 -5530
- package/dist_serve/bundle.js.map +2 -2
- package/dist_serve/bundle.js.third-party-notices.json +31 -31
- package/dist_serve/bundle.js.third-party-notices.txt +31 -31
- package/dist_ts/00_commitinfo_data.js +1 -1
- package/dist_ts/aglapi/aglapisurface.document.js +521 -17
- package/dist_ts/aglapi/interfaces.d.ts +3 -0
- package/dist_ts/aglapi/interfaces.js +2 -1
- package/dist_ts/classes.accountsactions.d.ts +3 -1
- package/dist_ts/classes.accountsactions.js +21 -3
- package/dist_ts/classes.authmodels.js +17 -4
- package/dist_ts/classes.authstore.js +16 -2
- package/dist_ts/classes.claudeharness.d.ts +16 -0
- package/dist_ts/classes.claudeharness.js +24 -2
- package/dist_ts/classes.cli.d.ts +4 -2
- package/dist_ts/classes.cli.js +6 -3
- package/dist_ts/classes.codexclientadapter.d.ts +11 -0
- package/dist_ts/classes.codexclientadapter.js +14 -2
- package/dist_ts/classes.controller.d.ts +175 -11
- package/dist_ts/classes.controller.js +1213 -173
- package/dist_ts/classes.controllerdevices.d.ts +2 -0
- package/dist_ts/classes.controllerdevices.js +6 -1
- package/dist_ts/classes.controllermanagement.d.ts +14 -4
- package/dist_ts/classes.controllermanagement.js +20 -2
- package/dist_ts/classes.gatewayclient.d.ts +115 -0
- package/dist_ts/classes.gatewayclient.js +336 -0
- package/dist_ts/classes.gatewayclientstore.d.ts +97 -0
- package/dist_ts/classes.gatewayclientstore.js +261 -0
- package/dist_ts/classes.inbox.d.ts +72 -0
- package/dist_ts/classes.inbox.js +231 -0
- package/dist_ts/classes.inferencerouter.d.ts +19 -0
- package/dist_ts/classes.inferencerouter.js +15 -3
- package/dist_ts/classes.inferenceservice.d.ts +9 -0
- package/dist_ts/classes.inferenceservice.js +28 -2
- package/dist_ts/classes.mcpclient.d.ts +4 -1
- package/dist_ts/classes.mcpclient.js +42 -6
- package/dist_ts/classes.mcpcontrollerhost.d.ts +3 -1
- package/dist_ts/classes.mcpcontrollerhost.js +11 -1
- package/dist_ts/classes.mcptools.d.ts +3 -3
- package/dist_ts/classes.mcptools.js +38 -8
- package/dist_ts/classes.mcpvalidation.d.ts +5 -0
- package/dist_ts/classes.mcpvalidation.js +38 -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.proxycontrol.d.ts +11 -0
- package/dist_ts/classes.proxycontrol.js +7 -1
- package/dist_ts/classes.proxycontrolclient.d.ts +17 -0
- package/dist_ts/classes.proxycontrolclient.js +35 -1
- package/dist_ts/classes.proxydaemon.js +8 -1
- package/dist_ts/classes.proxymonitor.d.ts +7 -0
- package/dist_ts/classes.proxymonitor.js +13 -1
- 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.trustedproxysecrets.d.ts +2 -0
- package/dist_ts/classes.trustedproxysecrets.js +5 -1
- 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.controllermanagementsurface.d.ts +4 -0
- package/dist_ts/functions.controllermanagementsurface.js +15 -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.gatewaycli.d.ts +24 -0
- package/dist_ts/functions.gatewaycli.js +395 -0
- package/dist_ts/functions.gatewayroute.d.ts +135 -0
- package/dist_ts/functions.gatewayroute.js +366 -0
- package/dist_ts/functions.inferencecli.js +32 -1
- package/dist_ts/functions.inferencecliarguments.d.ts +8 -2
- package/dist_ts/functions.inferencecliarguments.js +31 -3
- package/dist_ts/functions.mcpfleetworkertools.js +2 -2
- package/dist_ts/functions.proxycapacity.d.ts +50 -0
- package/dist_ts/functions.proxycapacity.js +142 -0
- package/dist_ts/functions.proxycapacitycli.d.ts +30 -0
- package/dist_ts/functions.proxycapacitycli.js +65 -0
- package/dist_ts/functions.remotecli.d.ts +30 -3
- package/dist_ts/functions.remotecli.js +44 -18
- package/dist_ts/functions.ticketvalidation.js +11 -2
- package/dist_ts/interfaces.auth.d.ts +25 -4
- package/dist_ts/interfaces.auth.js +15 -1
- package/dist_ts/plugins.d.ts +5 -1
- package/dist_ts/plugins.js +10 -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 +19 -26
- package/dist_ts_authswitch/authority-renewal.d.ts +34 -0
- package/dist_ts_authswitch/authority-renewal.js +56 -0
- package/dist_ts_authswitch/authority-usagelimit.d.ts +29 -0
- package/dist_ts_authswitch/authority-usagelimit.js +66 -2
- package/dist_ts_authswitch/authority-usagewindows.d.ts +6 -0
- package/dist_ts_authswitch/authority-usagewindows.js +15 -1
- 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/gateway.d.ts +151 -0
- package/dist_ts_interfaces/gateway.js +66 -0
- package/dist_ts_interfaces/inbox.d.ts +234 -0
- package/dist_ts_interfaces/inbox.js +101 -0
- package/dist_ts_interfaces/index.d.ts +3 -0
- package/dist_ts_interfaces/index.js +4 -1
- package/dist_ts_interfaces/interfaces.d.ts +10 -3
- package/dist_ts_interfaces/interfaces.js +4 -2
- package/dist_ts_interfaces/management.d.ts +4 -4
- package/dist_ts_interfaces/management.js +3 -2
- package/dist_ts_interfaces/mcprequests.d.ts +48 -6
- package/dist_ts_interfaces/mcprequests.js +12 -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/proxycapacity.d.ts +99 -0
- package/dist_ts_interfaces/proxycapacity.js +74 -0
- 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 +6 -5
- package/readme.md +191 -31
- package/ts/00_commitinfo_data.ts +1 -1
- package/ts/aglapi/aglapisurface.document.ts +520 -16
- package/ts/aglapi/interfaces.ts +1 -0
- package/ts/classes.accountsactions.ts +30 -3
- package/ts/classes.authmodels.ts +22 -3
- package/ts/classes.authstore.ts +15 -1
- package/ts/classes.claudeharness.ts +27 -1
- package/ts/classes.cli.ts +7 -3
- package/ts/classes.codexclientadapter.ts +14 -1
- package/ts/classes.controller.ts +1428 -249
- package/ts/classes.controllerdevices.ts +6 -0
- package/ts/classes.controllermanagement.ts +40 -7
- package/ts/classes.gatewayclient.ts +401 -0
- package/ts/classes.gatewayclientstore.ts +272 -0
- package/ts/classes.inbox.ts +239 -0
- package/ts/classes.inferencerouter.ts +27 -2
- package/ts/classes.inferenceservice.ts +28 -1
- package/ts/classes.mcpclient.ts +42 -3
- package/ts/classes.mcpcontrollerhost.ts +15 -0
- package/ts/classes.mcptools.ts +42 -9
- package/ts/classes.mcpvalidation.ts +32 -1
- package/ts/classes.nativesessions.ts +50 -12
- package/ts/classes.opencodeclient.ts +55 -4
- package/ts/classes.proxycontrol.ts +16 -0
- package/ts/classes.proxycontrolclient.ts +30 -0
- package/ts/classes.proxydaemon.ts +8 -0
- package/ts/classes.proxymonitor.ts +12 -0
- 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.trustedproxysecrets.ts +5 -0
- 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.controllermanagementsurface.ts +15 -0
- package/ts/functions.deviceapi.ts +1071 -34
- package/ts/functions.fleetworkercli.ts +10 -7
- package/ts/functions.gatewaycli.ts +436 -0
- package/ts/functions.gatewayroute.ts +429 -0
- package/ts/functions.inferencecli.ts +26 -0
- package/ts/functions.inferencecliarguments.ts +30 -4
- package/ts/functions.mcpfleetworkertools.ts +1 -1
- package/ts/functions.proxycapacity.ts +191 -0
- package/ts/functions.proxycapacitycli.ts +104 -0
- package/ts/functions.remotecli.ts +56 -20
- package/ts/functions.ticketvalidation.ts +11 -1
- package/ts/interfaces.auth.ts +36 -4
- package/ts/plugins.ts +12 -0
- package/ts_authswitch/authority-contract.ts +20 -0
- package/ts_authswitch/authority-overview.ts +28 -6
- package/ts_authswitch/authority-placement.ts +27 -32
- package/ts_authswitch/authority-renewal.ts +64 -0
- package/ts_authswitch/authority-usagelimit.ts +84 -1
- package/ts_authswitch/authority-usagewindows.ts +13 -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/gateway.ts +242 -0
- package/ts_interfaces/inbox.ts +287 -0
- package/ts_interfaces/index.ts +3 -0
- package/ts_interfaces/interfaces.ts +9 -2
- package/ts_interfaces/management.ts +6 -4
- package/ts_interfaces/mcprequests.ts +61 -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/proxycapacity.ts +162 -0
- 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 +19 -6
- package/ts_web/classes.inboxfeed.ts +329 -0
- package/ts_web/classes.nativesessionstate.ts +9 -23
- package/ts_web/elements.accounts.ts +121 -113
- package/ts_web/elements.configurationpane.ts +24 -37
- package/ts_web/elements.deployments.ts +66 -2
- package/ts_web/elements.devices.ts +4 -17
- package/ts_web/elements.flexlimitstrip.ts +21 -70
- package/ts_web/elements.harnesscontrollerapp.ts +198 -222
- 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;
|