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,808 @@
|
|
|
1
|
+
import * as plugins from './plugins.js';
|
|
2
|
+
import * as interfaces from '../ts_interfaces/index.js';
|
|
3
|
+
import { elicitationReply } from './classes.elicitationcards.js';
|
|
4
|
+
import type { IInboxItemState, InboxFeed } from './classes.inboxfeed.js';
|
|
5
|
+
import {
|
|
6
|
+
inboxAge, inboxAnswerFailure, inboxAskedBy, inboxChipLabels, inboxHarnessName, inboxKindViews, inboxOpenLabel,
|
|
7
|
+
inboxTicketAnswerText, inboxWhereText, type TInboxAnswerFailure,
|
|
8
|
+
} from './functions.inbox.js';
|
|
9
|
+
import { permissionCard, questionCards } from './functions.sessioncards.js';
|
|
10
|
+
import './elements.deployments.js';
|
|
11
|
+
|
|
12
|
+
const { html, css } = plugins.deesElement;
|
|
13
|
+
|
|
14
|
+
type TInboxItem = interfaces.TControllerInboxItem;
|
|
15
|
+
type TSessionPromptItem = interfaces.IControllerInboxPermissionItem | interfaces.IControllerInboxQuestionItem
|
|
16
|
+
| interfaces.IControllerInboxElicitationItem;
|
|
17
|
+
type TTicketItem = interfaces.IControllerInboxTicketQuestionItem | interfaces.IControllerInboxDeployGoItem
|
|
18
|
+
| interfaces.IControllerInboxWindowGoItem;
|
|
19
|
+
|
|
20
|
+
/** How the Inbox reaches the controller: the socket client, or a test's recorder. */
|
|
21
|
+
export interface IInboxSender {
|
|
22
|
+
/** Whether a request can be sent now; an answer is never sent while it cannot. */
|
|
23
|
+
readonly isConnected: boolean;
|
|
24
|
+
fire<TRequest extends interfaces.TControllerRequest>(
|
|
25
|
+
methodArg: TRequest['method'],
|
|
26
|
+
requestArg: TRequest['request'],
|
|
27
|
+
optionsArg?: { abortSignal?: AbortSignal; timeoutMs?: number },
|
|
28
|
+
): Promise<TRequest['response']>;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
/** Detail of `agl-inbox-open`: the item whose home the owner opens (its session, its ticket or the Driver). */
|
|
32
|
+
export interface IInboxOpenDetail {
|
|
33
|
+
item: TInboxItem;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
const ticketOperation = <TMethod extends interfaces.TTicketOperation>(senderArg: IInboxSender, operationArg: TMethod,
|
|
37
|
+
requestArg: interfaces.TTicketRequest<TMethod>): Promise<interfaces.TTicketResponse<TMethod>> => (
|
|
38
|
+
senderArg.fire<interfaces.TControllerTicketTypedRequest>(`controller.ticket.${operationArg}`, requestArg as never) as Promise<
|
|
39
|
+
interfaces.TTicketResponse<TMethod>>
|
|
40
|
+
);
|
|
41
|
+
|
|
42
|
+
const isTicketItem = (itemArg: TInboxItem): itemArg is TTicketItem => (
|
|
43
|
+
itemArg.kind === 'ticket_question' || itemArg.kind === 'deploy_go' || itemArg.kind === 'window_go'
|
|
44
|
+
);
|
|
45
|
+
|
|
46
|
+
/** Whether the owner answers the item here: its owner takes the answer, and its payload was not left out. */
|
|
47
|
+
const answeredHere = (itemArg: TInboxItem): boolean => {
|
|
48
|
+
if (itemArg.answer === 'none' || itemArg.omitted) return false;
|
|
49
|
+
switch (itemArg.kind) {
|
|
50
|
+
case 'permission': return itemArg.permission !== undefined;
|
|
51
|
+
case 'question': return itemArg.question !== undefined;
|
|
52
|
+
case 'elicitation': return itemArg.elicitation !== undefined && itemArg.answer !== 'child';
|
|
53
|
+
case 'ticket_question': case 'deploy_go': case 'window_go': return itemArg.question !== undefined;
|
|
54
|
+
case 'native_wait': case 'driver': return false;
|
|
55
|
+
}
|
|
56
|
+
};
|
|
57
|
+
|
|
58
|
+
/** A failure before the answer was sent: nothing reached its owner. */
|
|
59
|
+
class InboxNotSentError extends Error {}
|
|
60
|
+
|
|
61
|
+
const nativeWaitReasons: Readonly<Record<interfaces.TControllerNativeWaitReason, string>> = {
|
|
62
|
+
approval: 'waits for an approval', user_input: 'waits for a reply', native_prompt: 'waits for an answer', unrecognized: 'waits',
|
|
63
|
+
};
|
|
64
|
+
|
|
65
|
+
const unknownOutcomeText = (failureArg: string): string => (
|
|
66
|
+
`Outcome unknown: ${failureArg} The answer is not sent again on its own; check whether it arrived.`
|
|
67
|
+
);
|
|
68
|
+
const stillWaitsText = 'It still waits at its owner. Answer again if you still want to.';
|
|
69
|
+
const notConnectedText = 'The controller connection is down, so nothing was sent. Answer again once it is back.';
|
|
70
|
+
const notCheckedText = 'The controller connection is down, so nothing was checked. Check again once it is back.';
|
|
71
|
+
|
|
72
|
+
/**
|
|
73
|
+
* The Inbox (AGL-1643): what waits for the owner across sessions and the board, as the controller lists it
|
|
74
|
+
* (`InboxFeed`), filtered by chip and search in the browser, and answered in place with the cards the app already has.
|
|
75
|
+
* An answer goes to the item's owner through the request the item names; answering moves to the next item, and an
|
|
76
|
+
* answer from another client removes the item at once. An answer with an unknown outcome keeps its fence and its draft
|
|
77
|
+
* until the owner checks again; it is never sent again on its own.
|
|
78
|
+
*/
|
|
79
|
+
@plugins.deesElement.customElement('agl-inbox')
|
|
80
|
+
export class AglInbox extends plugins.deesElement.DeesElement {
|
|
81
|
+
@plugins.deesElement.property({ attribute: false })
|
|
82
|
+
accessor feed: InboxFeed | undefined;
|
|
83
|
+
|
|
84
|
+
@plugins.deesElement.property({ attribute: false })
|
|
85
|
+
accessor sender: IInboxSender | undefined;
|
|
86
|
+
|
|
87
|
+
@plugins.deesElement.state()
|
|
88
|
+
accessor chip: interfaces.TControllerInboxChip = 'all';
|
|
89
|
+
|
|
90
|
+
@plugins.deesElement.state()
|
|
91
|
+
accessor query = '';
|
|
92
|
+
|
|
93
|
+
/** The item the detail shows; empty shows the first. */
|
|
94
|
+
@plugins.deesElement.state()
|
|
95
|
+
accessor selectedId = '';
|
|
96
|
+
|
|
97
|
+
@plugins.deesElement.state()
|
|
98
|
+
accessor now = Date.now();
|
|
99
|
+
|
|
100
|
+
/** The selected item's place in the shown list, so the item that takes it is shown when it leaves. */
|
|
101
|
+
private selectedIndex = 0;
|
|
102
|
+
private unsubscribe: (() => void) | undefined;
|
|
103
|
+
private subscribedFeed: InboxFeed | undefined;
|
|
104
|
+
private ageTimer: ReturnType<typeof setInterval> | undefined;
|
|
105
|
+
|
|
106
|
+
public static styles = [
|
|
107
|
+
plugins.deesElement.cssManager.defaultStyles,
|
|
108
|
+
plugins.deesCatalog.themeDefaultStyles,
|
|
109
|
+
css`
|
|
110
|
+
:host { display: block; height: 100%; min-height: 0; overflow: auto; }
|
|
111
|
+
.page { display: grid; grid-template-rows: auto auto minmax(0, 1fr); gap: 16px; padding: 20px; max-width: 1400px; margin: 0 auto;
|
|
112
|
+
min-height: 100%; box-sizing: border-box; }
|
|
113
|
+
.head { display: flex; flex-wrap: wrap; align-items: flex-end; justify-content: space-between; gap: 12px 16px; }
|
|
114
|
+
h2 { margin: 0; font-size: 22px; font-weight: 700; color: var(--dees-color-text-primary); }
|
|
115
|
+
.subtitle { margin: 4px 0 0; font-size: 13px; color: var(--dees-color-text-secondary); }
|
|
116
|
+
.filters { display: flex; flex-wrap: wrap; align-items: center; gap: 10px; }
|
|
117
|
+
.search { width: 240px; }
|
|
118
|
+
.notes:empty { display: none; }
|
|
119
|
+
.notes { display: grid; gap: 8px; }
|
|
120
|
+
.split { display: grid; grid-template-columns: minmax(280px, 380px) minmax(0, 1fr); gap: 16px; align-items: start; min-height: 0; }
|
|
121
|
+
.list { display: grid; gap: 6px; align-content: start; }
|
|
122
|
+
.row { display: flex; gap: 12px; align-items: flex-start; width: 100%; padding: 12px; text-align: left; font: inherit;
|
|
123
|
+
color: var(--dees-color-text-primary); background: var(--dees-color-bg-secondary); border: 1px solid var(--dees-color-border-subtle);
|
|
124
|
+
border-radius: 10px; cursor: pointer; }
|
|
125
|
+
.row:hover { background: var(--dees-color-row-hover); }
|
|
126
|
+
.row:focus-visible { outline: 2px solid var(--dees-color-focus-ring); outline-offset: 1px; }
|
|
127
|
+
.row.selected { border-color: var(--dees-color-accent-primary); background: var(--dees-color-sidebar-selection); }
|
|
128
|
+
.row.answered { opacity: 0.6; }
|
|
129
|
+
.mark { flex: none; display: inline-flex; align-items: center; justify-content: center; width: 30px; height: 30px; border-radius: 8px;
|
|
130
|
+
background: var(--dees-color-fill-secondary); color: var(--dees-color-text-secondary); }
|
|
131
|
+
.mark.tone-warning { color: var(--dees-color-text-warning); background: var(--dees-color-badge-warning-bg); }
|
|
132
|
+
.mark.tone-info { color: var(--dees-color-text-info); background: var(--dees-color-fill-secondary); }
|
|
133
|
+
.mark.tone-success { color: var(--dees-color-text-success); background: var(--dees-color-badge-success-bg); }
|
|
134
|
+
.rowText { display: grid; gap: 3px; min-width: 0; flex: 1; }
|
|
135
|
+
.kindLine { display: flex; align-items: baseline; justify-content: space-between; gap: 8px; font-size: 12px; font-weight: 600; }
|
|
136
|
+
.kindLine time { font-weight: 400; color: var(--dees-color-text-secondary); white-space: nowrap; }
|
|
137
|
+
.kind.tone-warning { color: var(--dees-color-text-warning); }
|
|
138
|
+
.kind.tone-info { color: var(--dees-color-text-info); }
|
|
139
|
+
.kind.tone-success { color: var(--dees-color-text-success); }
|
|
140
|
+
.kind.tone-neutral { color: var(--dees-color-text-secondary); }
|
|
141
|
+
.title { font-size: 14px; line-height: 1.35; overflow-wrap: anywhere; }
|
|
142
|
+
.where { display: flex; flex-wrap: wrap; align-items: center; gap: 6px; font-size: 12px; color: var(--dees-color-text-secondary);
|
|
143
|
+
overflow-wrap: anywhere; }
|
|
144
|
+
.detail { display: grid; min-width: 0; background: var(--dees-color-bg-secondary); border: 1px solid var(--dees-color-border-subtle);
|
|
145
|
+
border-radius: 12px; overflow: hidden; }
|
|
146
|
+
.detailHead { display: flex; flex-wrap: wrap; align-items: center; gap: 12px; padding: 14px 16px;
|
|
147
|
+
border-bottom: 1px solid var(--dees-color-border-subtle); }
|
|
148
|
+
.detailWhat { flex: 1; min-width: 0; display: grid; gap: 2px; }
|
|
149
|
+
.detailKind { margin: 0; font-size: 13px; font-weight: 600; overflow-wrap: anywhere; }
|
|
150
|
+
.detailMeta { margin: 0; font-size: 12px; color: var(--dees-color-text-secondary); }
|
|
151
|
+
.detailBody { display: grid; gap: 14px; padding: 16px; min-width: 0; }
|
|
152
|
+
.detailTitle { margin: 0; font-size: 18px; font-weight: 600; line-height: 1.35; overflow-wrap: anywhere; }
|
|
153
|
+
.line { margin: 0; padding: 10px 12px; border-left: 3px solid var(--dees-color-accent-warning); background: var(--dees-color-fill-tertiary);
|
|
154
|
+
border-radius: 6px; font-size: 14px; line-height: 1.45; white-space: pre-wrap; overflow-wrap: anywhere; }
|
|
155
|
+
.info { margin: 0; font-size: 14px; line-height: 1.5; color: var(--dees-color-text-secondary); }
|
|
156
|
+
.detailFoot { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 10px; padding: 12px 16px;
|
|
157
|
+
border-top: 1px solid var(--dees-color-border-subtle); }
|
|
158
|
+
.footNote { font-size: 12px; color: var(--dees-color-text-secondary); flex: 1; min-width: 200px; }
|
|
159
|
+
.actions { display: flex; flex-wrap: wrap; gap: 8px; justify-content: flex-end; }
|
|
160
|
+
.nothingShown { margin: 0; padding: 12px; font-size: 13px; color: var(--dees-color-text-secondary); }
|
|
161
|
+
.emptyCard { align-self: start; padding: 40px 24px; background: var(--dees-color-bg-secondary);
|
|
162
|
+
border: 1px solid var(--dees-color-border-subtle); border-radius: 12px; }
|
|
163
|
+
@media (max-width: 900px) { .split { grid-template-columns: minmax(0, 1fr); } .search { width: 100%; } }
|
|
164
|
+
@media (max-width: 600px) { .page { padding: 12px; gap: 12px; } h2 { font-size: 19px; } }
|
|
165
|
+
`,
|
|
166
|
+
];
|
|
167
|
+
|
|
168
|
+
public async connectedCallback(): Promise<void> {
|
|
169
|
+
await super.connectedCallback();
|
|
170
|
+
this.subscribe();
|
|
171
|
+
this.ageTimer ??= setInterval(() => { this.now = Date.now(); }, 30_000);
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
public async disconnectedCallback(): Promise<void> {
|
|
175
|
+
this.unsubscribe?.();
|
|
176
|
+
this.unsubscribe = undefined;
|
|
177
|
+
this.subscribedFeed = undefined;
|
|
178
|
+
if (this.ageTimer) clearInterval(this.ageTimer);
|
|
179
|
+
this.ageTimer = undefined;
|
|
180
|
+
await super.disconnectedCallback();
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
/** Follows the feed on screen: every change of it renders the view. */
|
|
184
|
+
private subscribe(): void {
|
|
185
|
+
if (!this.isConnected || this.subscribedFeed === this.feed) return;
|
|
186
|
+
this.unsubscribe?.();
|
|
187
|
+
this.subscribedFeed = this.feed;
|
|
188
|
+
this.unsubscribe = this.feed?.subscribe(() => this.requestUpdate());
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
/** The items the chip and the search show, in the controller's order. */
|
|
192
|
+
public shownItems(): TInboxItem[] {
|
|
193
|
+
return (this.feed?.items ?? []).filter((itemArg) => interfaces.controllerInboxItemShown(itemArg, this.chip, this.query));
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
/** The item the detail shows: the selected one, a held one the owner still reads, or the one that took its place. */
|
|
197
|
+
public shownItem(): TInboxItem | undefined {
|
|
198
|
+
const feed = this.feed;
|
|
199
|
+
if (!feed) return undefined;
|
|
200
|
+
const held = feed.peek(this.selectedId);
|
|
201
|
+
if (held?.held) return held.item;
|
|
202
|
+
return this.shownItems().find((itemArg) => itemArg.id === this.selectedId);
|
|
203
|
+
}
|
|
204
|
+
|
|
205
|
+
protected willUpdate(changedArg: Map<PropertyKey, unknown>): void {
|
|
206
|
+
super.willUpdate(changedArg);
|
|
207
|
+
if (changedArg.has('feed')) this.subscribe();
|
|
208
|
+
const feed = this.feed;
|
|
209
|
+
if (!feed || feed.peek(this.selectedId)?.held) return;
|
|
210
|
+
const shown = this.shownItems();
|
|
211
|
+
const index = shown.findIndex((itemArg) => itemArg.id === this.selectedId);
|
|
212
|
+
if (index >= 0) {
|
|
213
|
+
this.selectedIndex = index;
|
|
214
|
+
return;
|
|
215
|
+
}
|
|
216
|
+
// The selected item left (answered here or elsewhere) or the filter hides it: the one that took its place shows.
|
|
217
|
+
const waiting = shown.filter((itemArg) => feed.peek(itemArg.id)?.phase !== 'answered');
|
|
218
|
+
const next = shown.slice(this.selectedIndex).find((itemArg) => waiting.includes(itemArg)) ?? waiting.at(-1) ?? shown[0];
|
|
219
|
+
this.selectedId = next?.id ?? '';
|
|
220
|
+
this.selectedIndex = next ? shown.indexOf(next) : 0;
|
|
221
|
+
}
|
|
222
|
+
|
|
223
|
+
public render(): plugins.deesElement.TemplateResult {
|
|
224
|
+
const feed = this.feed;
|
|
225
|
+
const total = feed?.total ?? 0;
|
|
226
|
+
const counts = feed?.counts() ?? { all: 0, sessions: 0, board: 0, deploys: 0 };
|
|
227
|
+
const chipOptions = interfaces.controllerInboxChips.map((chipArg) => ({ key: chipArg, label: inboxChipLabels[chipArg],
|
|
228
|
+
...(counts[chipArg] > 0 ? { badge: counts[chipArg] } : {}) }));
|
|
229
|
+
// A held item, an answer refused because another client answered first, stays on screen until the owner moves on.
|
|
230
|
+
const empty = feed?.loaded === true && total === 0 && feed.peek(this.selectedId)?.held !== true;
|
|
231
|
+
return html`
|
|
232
|
+
<div class="page">
|
|
233
|
+
<div class="head">
|
|
234
|
+
<div>
|
|
235
|
+
<h2>Inbox</h2>
|
|
236
|
+
<p class="subtitle">${!feed?.loaded ? (feed?.error ? '' : 'Reading what waits for you…')
|
|
237
|
+
: total === 0 ? 'Nothing waits for you'
|
|
238
|
+
: `${total} wait${total === 1 ? 's' : ''} for you · an answer here also clears it on your phone`}</p>
|
|
239
|
+
</div>
|
|
240
|
+
${empty || !feed?.loaded ? '' : html`
|
|
241
|
+
<div class="filters">
|
|
242
|
+
<dees-input-multitoggle class="chips" type="single" size="sm" labelPosition="none" label="Show"
|
|
243
|
+
.options=${chipOptions} .selectedOption=${this.chip}
|
|
244
|
+
@change=${(eventArg: CustomEvent<{ selectedOption: string }>) => {
|
|
245
|
+
const chip = interfaces.controllerInboxChips.find((chipArg) => chipArg === eventArg.detail?.selectedOption);
|
|
246
|
+
if (chip) this.chip = chip;
|
|
247
|
+
}}></dees-input-multitoggle>
|
|
248
|
+
<dees-input-text class="search" labelPosition="none" label="Search the inbox" placeholder="Search the inbox"
|
|
249
|
+
.value=${this.query}
|
|
250
|
+
@input=${(eventArg: Event) => {
|
|
251
|
+
this.query = String((eventArg.currentTarget as plugins.deesCatalog.DeesInputText).value ?? '');
|
|
252
|
+
}}></dees-input-text>
|
|
253
|
+
</div>
|
|
254
|
+
`}
|
|
255
|
+
</div>
|
|
256
|
+
<div class="notes">
|
|
257
|
+
${feed?.error && feed.loaded ? html`<dees-hint class="listError" .type=${'error'} .text=${`The Inbox could not be read again: ${feed.error}`}></dees-hint>` : ''}
|
|
258
|
+
${feed?.limited ? html`<dees-hint class="limited" .type=${'info'}
|
|
259
|
+
.text=${`The Inbox shows ${feed.items.length} of the ${total} items that wait; answer some to see the rest.`}></dees-hint>` : ''}
|
|
260
|
+
</div>
|
|
261
|
+
${!feed?.loaded ? this.renderUnloaded(feed) : empty ? this.renderEmpty() : this.renderSplit()}
|
|
262
|
+
</div>
|
|
263
|
+
`;
|
|
264
|
+
}
|
|
265
|
+
|
|
266
|
+
private renderUnloaded(feedArg: InboxFeed | undefined): plugins.deesElement.TemplateResult {
|
|
267
|
+
return feedArg?.error
|
|
268
|
+
? html`<dees-state class="readError" variant="error" heading="The Inbox could not be read" .description=${feedArg.error}
|
|
269
|
+
.onRetry=${() => feedArg.refresh()}></dees-state>`
|
|
270
|
+
: html`<dees-state variant="loading" heading="Reading the Inbox"></dees-state>`;
|
|
271
|
+
}
|
|
272
|
+
|
|
273
|
+
private renderEmpty(): plugins.deesElement.TemplateResult {
|
|
274
|
+
return html`
|
|
275
|
+
<div class="emptyCard">
|
|
276
|
+
<dees-state class="empty" variant="empty" iconName="lucide:CircleCheck" heading="Nothing waits for you"
|
|
277
|
+
description="New permissions, questions, forms and go's show up here and in the AGL app on your phone."></dees-state>
|
|
278
|
+
</div>
|
|
279
|
+
`;
|
|
280
|
+
}
|
|
281
|
+
|
|
282
|
+
private renderSplit(): plugins.deesElement.TemplateResult {
|
|
283
|
+
const shown = this.shownItems();
|
|
284
|
+
const item = this.shownItem();
|
|
285
|
+
return html`
|
|
286
|
+
<div class="split">
|
|
287
|
+
<div class="list" role="list" aria-label="What waits for you">
|
|
288
|
+
${shown.length === 0 ? html`<p class="nothingShown">Nothing that waits matches.</p>` : shown.map((itemArg) => this.renderRow(itemArg, itemArg.id === item?.id))}
|
|
289
|
+
</div>
|
|
290
|
+
${item ? this.renderDetail(item) : ''}
|
|
291
|
+
</div>
|
|
292
|
+
`;
|
|
293
|
+
}
|
|
294
|
+
|
|
295
|
+
private renderRow(itemArg: TInboxItem, selectedArg: boolean): plugins.deesElement.TemplateResult {
|
|
296
|
+
const view = inboxKindViews[itemArg.kind];
|
|
297
|
+
const answered = this.feed?.peek(itemArg.id)?.phase === 'answered';
|
|
298
|
+
const harness = itemArg.where.kind === 'conversation' || itemArg.where.kind === 'child' || itemArg.where.kind === 'native'
|
|
299
|
+
? itemArg.where.harness : undefined;
|
|
300
|
+
const askedBy = inboxAskedBy(itemArg);
|
|
301
|
+
return html`
|
|
302
|
+
<div role="listitem">
|
|
303
|
+
<button type="button" class=${`row${selectedArg ? ' selected' : ''}${answered ? ' answered' : ''}`} data-item=${itemArg.id}
|
|
304
|
+
aria-current=${selectedArg ? 'true' : 'false'} @click=${() => this.select(itemArg.id)}>
|
|
305
|
+
<span class=${`mark tone-${view.tone}`}><dees-icon icon=${view.icon} iconSize="15" aria-hidden="true"></dees-icon></span>
|
|
306
|
+
<span class="rowText">
|
|
307
|
+
<span class="kindLine"><span class=${`kind tone-${view.tone}`}>${view.label}</span>
|
|
308
|
+
<time>${answered ? 'answered' : inboxAge(itemArg.since, this.now)}</time></span>
|
|
309
|
+
<span class="title">${itemArg.title}</span>
|
|
310
|
+
<span class="where"><span>${inboxWhereText(itemArg)}</span>
|
|
311
|
+
${askedBy ? html`<span>${askedBy}</span>` : ''}
|
|
312
|
+
${harness ? html`<dees-badge size="compact" .tone=${'neutral'} .text=${inboxHarnessName(harness)}></dees-badge>` : ''}</span>
|
|
313
|
+
</span>
|
|
314
|
+
</button>
|
|
315
|
+
</div>
|
|
316
|
+
`;
|
|
317
|
+
}
|
|
318
|
+
|
|
319
|
+
private renderDetail(itemArg: TInboxItem): plugins.deesElement.TemplateResult {
|
|
320
|
+
const view = inboxKindViews[itemArg.kind];
|
|
321
|
+
const askedBy = inboxAskedBy(itemArg);
|
|
322
|
+
const age = inboxAge(itemArg.since, this.now);
|
|
323
|
+
const state = this.feed?.peek(itemArg.id);
|
|
324
|
+
const go = itemArg.kind === 'deploy_go' || itemArg.kind === 'window_go';
|
|
325
|
+
return html`
|
|
326
|
+
<section class="detail" data-detail=${itemArg.id} aria-label=${`${view.label}: ${itemArg.title}`}>
|
|
327
|
+
<header class="detailHead">
|
|
328
|
+
<span class=${`mark tone-${view.tone}`}><dees-icon icon=${view.icon} iconSize="15" aria-hidden="true"></dees-icon></span>
|
|
329
|
+
<div class="detailWhat">
|
|
330
|
+
<p class="detailKind"><span class=${`kind tone-${view.tone}`}>${view.label}</span> · ${inboxWhereText(itemArg)}</p>
|
|
331
|
+
<p class="detailMeta">${askedBy ? `asked by ${askedBy} · ` : ''}${age === 'just now' ? age : `${age} ago`}</p>
|
|
332
|
+
</div>
|
|
333
|
+
${go ? html`<dees-badge .tone=${'neutral'} text="Only you can give this go"></dees-badge>` : ''}
|
|
334
|
+
${itemArg.kind === 'driver' ? '' : html`
|
|
335
|
+
<dees-button class="openButton" type="outline" size="sm" @clicked=${() => this.open(itemArg)}>
|
|
336
|
+
${inboxOpenLabel(itemArg)} <dees-icon icon="lucide:ExternalLink" iconSize="13"></dees-icon>
|
|
337
|
+
</dees-button>`}
|
|
338
|
+
</header>
|
|
339
|
+
<div class="detailBody">
|
|
340
|
+
${this.cardShowsTitle(itemArg) ? '' : html`<h3 class="detailTitle">${itemArg.title}</h3>`}
|
|
341
|
+
${this.renderBody(itemArg, state)}
|
|
342
|
+
</div>
|
|
343
|
+
<footer class="detailFoot">
|
|
344
|
+
<span class="footNote">${this.footNote(itemArg)}</span>
|
|
345
|
+
<div class="actions">${this.renderActions(itemArg, state)}</div>
|
|
346
|
+
</footer>
|
|
347
|
+
</section>
|
|
348
|
+
`;
|
|
349
|
+
}
|
|
350
|
+
|
|
351
|
+
/** Whether the item's card says what is asked itself, or the driver's line does, so the detail adds no title. */
|
|
352
|
+
private cardShowsTitle(itemArg: TInboxItem): boolean {
|
|
353
|
+
if (itemArg.kind === 'driver') return itemArg.line !== undefined;
|
|
354
|
+
if (itemArg.kind === 'deploy_go' || itemArg.kind === 'window_go' || itemArg.kind === 'native_wait') return false;
|
|
355
|
+
return answeredHere(itemArg);
|
|
356
|
+
}
|
|
357
|
+
|
|
358
|
+
/** The item's own words and its card. */
|
|
359
|
+
private renderBody(itemArg: TInboxItem, stateArg: IInboxItemState | undefined): plugins.deesElement.TemplateResult {
|
|
360
|
+
if (itemArg.omitted) {
|
|
361
|
+
const kib = Math.ceil(itemArg.omitted.bytes / 1024);
|
|
362
|
+
const home = itemArg.where.kind === 'ticket' ? 'ticket' : 'session view';
|
|
363
|
+
return html`<p class="info omitted">${`This item is too large to show here (${kib} KiB), so it is answered in its ${home}: ${inboxOpenLabel(itemArg)}.`}</p>`;
|
|
364
|
+
}
|
|
365
|
+
const notice = stateArg?.message && (stateArg.phase === 'refused' || stateArg.phase === 'unknown' || stateArg.phase === 'checking')
|
|
366
|
+
? html`<dees-hint class="answerNotice" data-phase=${stateArg.phase} .type=${stateArg.phase === 'refused' ? 'error' : 'warning'}
|
|
367
|
+
.text=${stateArg.message}></dees-hint>`
|
|
368
|
+
: '';
|
|
369
|
+
switch (itemArg.kind) {
|
|
370
|
+
case 'native_wait': {
|
|
371
|
+
const where = itemArg.where;
|
|
372
|
+
return html`<p class="info nativeWait">${`${inboxHarnessName(where.harness)} ${nativeWaitReasons[itemArg.nativeWait.reason]} in its own `
|
|
373
|
+
+ `client on ${itemArg.host}. AGL holds no request for it, so it is answered there, not here.`}</p>`;
|
|
374
|
+
}
|
|
375
|
+
case 'driver':
|
|
376
|
+
return html`
|
|
377
|
+
${itemArg.line ? html`<p class="line driverLine">${itemArg.line}</p>` : ''}
|
|
378
|
+
<p class="info">The driver's last turn ended on this line. Answer it in the Driver view.</p>
|
|
379
|
+
`;
|
|
380
|
+
case 'permission': {
|
|
381
|
+
if (!answeredHere(itemArg) || !itemArg.permission) return this.renderElsewhere(itemArg);
|
|
382
|
+
const state = this.feed!.state(itemArg);
|
|
383
|
+
const card = permissionCard(itemArg.permission, itemArg.id);
|
|
384
|
+
const response = state.phase === 'unknown' || state.phase === 'checking' ? state.permission.answered : undefined;
|
|
385
|
+
return html`${notice}${plugins.deesElement.directives.keyed(`${itemArg.id}#${state.attempt}`, html`
|
|
386
|
+
<dees-harness-permission-card data-item=${itemArg.id}
|
|
387
|
+
.request=${response ? { ...card, response, outcome: { tone: 'warning', text: 'Outcome unknown: check whether it arrived.' } } : card}
|
|
388
|
+
.viewState=${state.permission} .busy=${state.phase === 'sending' || state.phase === 'checking'}
|
|
389
|
+
@harness-permission-response=${(eventArg: CustomEvent<plugins.deesCatalog.IHarnessPermissionResponseDetail>) => {
|
|
390
|
+
eventArg.stopPropagation();
|
|
391
|
+
void this.answerPermission(itemArg, eventArg.detail);
|
|
392
|
+
}}></dees-harness-permission-card>`)}`;
|
|
393
|
+
}
|
|
394
|
+
case 'question': {
|
|
395
|
+
if (!answeredHere(itemArg) || !itemArg.question) return this.renderElsewhere(itemArg);
|
|
396
|
+
const state = this.feed!.state(itemArg);
|
|
397
|
+
return html`${questionCards(itemArg.question, itemArg.id).map((cardArg) => this.renderQuestionCard(itemArg, state, cardArg))}`;
|
|
398
|
+
}
|
|
399
|
+
case 'elicitation': {
|
|
400
|
+
if (!answeredHere(itemArg) || !itemArg.elicitation) return this.renderElsewhere(itemArg);
|
|
401
|
+
const state = this.feed!.state(itemArg);
|
|
402
|
+
const [card] = state.elicitation.cards([itemArg.elicitation]);
|
|
403
|
+
return html`
|
|
404
|
+
<dees-harness-elicitation-card data-item=${itemArg.id} .request=${card} .busy=${this.fenced(state)}
|
|
405
|
+
@harness-elicitation-response=${(eventArg: CustomEvent<plugins.deesCatalog.IHarnessElicitationResponseDetail>) => {
|
|
406
|
+
eventArg.stopPropagation();
|
|
407
|
+
void this.answerElicitation(itemArg, eventArg.detail);
|
|
408
|
+
}}></dees-harness-elicitation-card>
|
|
409
|
+
`;
|
|
410
|
+
}
|
|
411
|
+
case 'ticket_question': {
|
|
412
|
+
if (!answeredHere(itemArg) || !itemArg.question) return this.renderElsewhere(itemArg);
|
|
413
|
+
const state = this.feed!.state(itemArg);
|
|
414
|
+
return this.renderQuestionCard(itemArg, state, interfaces.ticketQuestionCardRequest(itemArg.question));
|
|
415
|
+
}
|
|
416
|
+
case 'deploy_go': case 'window_go': {
|
|
417
|
+
if (!itemArg.question) return this.renderElsewhere(itemArg);
|
|
418
|
+
return html`${notice}
|
|
419
|
+
<agl-deploy-go data-item=${itemArg.id} .subjectKey=${itemArg.where.ticketKey} .question=${itemArg.question}
|
|
420
|
+
.inboxPlan=${itemArg.kind === 'deploy_go' ? itemArg.plan : undefined}
|
|
421
|
+
.inboxWindow=${itemArg.kind === 'window_go' ? itemArg.window : undefined}></agl-deploy-go>`;
|
|
422
|
+
}
|
|
423
|
+
}
|
|
424
|
+
}
|
|
425
|
+
|
|
426
|
+
private renderElsewhere(itemArg: TInboxItem): plugins.deesElement.TemplateResult {
|
|
427
|
+
return html`<p class="info">${`This is answered in its ${itemArg.where.kind === 'ticket' ? 'ticket' : 'session view'}: ${inboxOpenLabel(itemArg)}.`}</p>`;
|
|
428
|
+
}
|
|
429
|
+
|
|
430
|
+
private renderQuestionCard(itemArg: TInboxItem, stateArg: IInboxItemState,
|
|
431
|
+
cardArg: plugins.deesCatalog.IHarnessQuestionRequest): plugins.deesElement.TemplateResult {
|
|
432
|
+
let viewState = stateArg.questions.get(cardArg.id);
|
|
433
|
+
if (!viewState) {
|
|
434
|
+
viewState = {};
|
|
435
|
+
stateArg.questions.set(cardArg.id, viewState);
|
|
436
|
+
}
|
|
437
|
+
return html`
|
|
438
|
+
<dees-harness-question-card data-item=${itemArg.id} data-card=${cardArg.id} .request=${cardArg} .viewState=${viewState}
|
|
439
|
+
.busy=${this.fenced(stateArg)}
|
|
440
|
+
@harness-question-response=${(eventArg: CustomEvent<plugins.deesCatalog.IHarnessQuestionResponseDetail>) => {
|
|
441
|
+
eventArg.stopPropagation();
|
|
442
|
+
void this.answerQuestionCard(itemArg, cardArg, eventArg.detail);
|
|
443
|
+
}}></dees-harness-question-card>
|
|
444
|
+
`;
|
|
445
|
+
}
|
|
446
|
+
|
|
447
|
+
private footNote(itemArg: TInboxItem): string {
|
|
448
|
+
if (itemArg.omitted || itemArg.kind === 'native_wait') return 'Nothing can be answered here.';
|
|
449
|
+
switch (itemArg.kind) {
|
|
450
|
+
case 'driver': return 'The Driver view takes the answer.';
|
|
451
|
+
case 'ticket_question': {
|
|
452
|
+
const askedBy = inboxAskedBy(itemArg);
|
|
453
|
+
return `Goes to ${itemArg.where.ticketKey}${askedBy ? ` and to ${askedBy}` : ''}. A question takes one answer.`;
|
|
454
|
+
}
|
|
455
|
+
case 'deploy_go': return `Only your answer is a go. ${itemArg.plan.assignee ?? 'The driver'} deploys as you answer and reports on ${itemArg.where.ticketKey}.`;
|
|
456
|
+
case 'window_go': return `Only your answer is a go. It goes to ${itemArg.where.ticketKey}.`;
|
|
457
|
+
default: return answeredHere(itemArg) ? `Goes to ${inboxWhereText(itemArg)}.` : 'Nothing can be answered here.';
|
|
458
|
+
}
|
|
459
|
+
}
|
|
460
|
+
|
|
461
|
+
/** The footer's buttons: a go's answers, the way to an item answered elsewhere, a re-check, and Skip. */
|
|
462
|
+
private renderActions(itemArg: TInboxItem, stateArg: IInboxItemState | undefined): plugins.deesElement.TemplateResult {
|
|
463
|
+
const fenced = stateArg ? this.fenced(stateArg) : false;
|
|
464
|
+
const unknown = stateArg?.phase === 'unknown' || stateArg?.phase === 'checking';
|
|
465
|
+
const go = (itemArg.kind === 'deploy_go' || itemArg.kind === 'window_go') && !itemArg.omitted ? itemArg : undefined;
|
|
466
|
+
const goQuestion = go?.question?.status === 'open' && !stateArg?.held ? go.question : undefined;
|
|
467
|
+
const recommended = go?.kind === 'window_go' ? interfaces.ticketWindowOptions.approve
|
|
468
|
+
: go?.plan.deployWhen === 'anytime' ? interfaces.ticketDeployPlanOptions.now : interfaces.ticketDeployPlanOptions.later;
|
|
469
|
+
return html`
|
|
470
|
+
${unknown ? html`<dees-button class="recheckButton" type="accent" size="sm" .status=${stateArg?.phase === 'checking' ? 'pending' : 'normal'}
|
|
471
|
+
?disabled=${stateArg?.phase === 'checking'} @clicked=${() => void this.recheck(itemArg)}>
|
|
472
|
+
<dees-icon icon="lucide:RefreshCw" iconSize="13"></dees-icon> Check again</dees-button>` : ''}
|
|
473
|
+
<dees-button class="skipButton" type="outline" size="sm" @clicked=${() => this.skip(itemArg.id)}>${go ? 'Not now' : 'Skip'}</dees-button>
|
|
474
|
+
${itemArg.kind === 'driver' ? html`<dees-button class="openButton" type="accent" size="sm" @clicked=${() => this.open(itemArg)}>
|
|
475
|
+
<dees-icon icon="lucide:ShipWheel" iconSize="13"></dees-icon> Open Driver</dees-button>` : ''}
|
|
476
|
+
${!answeredHere(itemArg) && itemArg.kind !== 'driver' ? html`<dees-button class="openHomeButton" type="accent" size="sm"
|
|
477
|
+
@clicked=${() => this.open(itemArg)}>${inboxOpenLabel(itemArg)}</dees-button>` : ''}
|
|
478
|
+
${goQuestion ? [...goQuestion.options].reverse().map((optionArg) => html`
|
|
479
|
+
<dees-button class="goButton" data-option=${optionArg.id} type=${optionArg.id === recommended ? 'accent' : 'outline'} size="sm"
|
|
480
|
+
?disabled=${fenced} @clicked=${() => void this.answerGo(go!, optionArg.id)}>${optionArg.label}</dees-button>`) : ''}
|
|
481
|
+
`;
|
|
482
|
+
}
|
|
483
|
+
|
|
484
|
+
/** Whether the item takes no answer now: one is on its way, or its outcome is unknown until the owner checks again. */
|
|
485
|
+
private fenced(stateArg: IInboxItemState): boolean {
|
|
486
|
+
return stateArg.phase === 'sending' || stateArg.phase === 'unknown' || stateArg.phase === 'checking' || stateArg.phase === 'answered'
|
|
487
|
+
|| stateArg.held === true;
|
|
488
|
+
}
|
|
489
|
+
|
|
490
|
+
private select(idArg: string): void {
|
|
491
|
+
if (idArg === this.selectedId) return;
|
|
492
|
+
this.feed?.release(this.selectedId);
|
|
493
|
+
this.selectedId = idArg;
|
|
494
|
+
}
|
|
495
|
+
|
|
496
|
+
/** Skip and Not now: the next item shows, and nothing is stored. */
|
|
497
|
+
private skip(idArg: string): void {
|
|
498
|
+
this.advance(idArg);
|
|
499
|
+
}
|
|
500
|
+
|
|
501
|
+
/** Shows the item after `idArg` that still waits, else the one before it. */
|
|
502
|
+
private advance(idArg: string): void {
|
|
503
|
+
const feed = this.feed;
|
|
504
|
+
if (!feed) return;
|
|
505
|
+
const shown = this.shownItems();
|
|
506
|
+
const index = shown.findIndex((itemArg) => itemArg.id === idArg);
|
|
507
|
+
const waiting = (itemArg: TInboxItem) => itemArg.id !== idArg && feed.peek(itemArg.id)?.phase !== 'answered';
|
|
508
|
+
const next = shown.slice(index + 1).find(waiting) ?? shown.slice(0, Math.max(0, index)).find(waiting);
|
|
509
|
+
feed.release(idArg);
|
|
510
|
+
if (next) {
|
|
511
|
+
this.selectedId = next.id;
|
|
512
|
+
this.selectedIndex = shown.indexOf(next);
|
|
513
|
+
} else {
|
|
514
|
+
this.selectedIndex = Math.max(0, index);
|
|
515
|
+
}
|
|
516
|
+
}
|
|
517
|
+
|
|
518
|
+
private open(itemArg: TInboxItem): void {
|
|
519
|
+
this.dispatchEvent(new CustomEvent<IInboxOpenDetail>('agl-inbox-open', { detail: { item: itemArg }, bubbles: true, composed: true }));
|
|
520
|
+
}
|
|
521
|
+
|
|
522
|
+
// ---------------------------------------------------------------------------------------------- answers
|
|
523
|
+
|
|
524
|
+
private async answerPermission(itemArg: interfaces.IControllerInboxPermissionItem,
|
|
525
|
+
detailArg: plugins.deesCatalog.IHarnessPermissionResponseDetail | undefined): Promise<void> {
|
|
526
|
+
const permission = itemArg.permission;
|
|
527
|
+
if (!permission || !detailArg) return;
|
|
528
|
+
// A broad grant is not offered: 'always' grants this request once, as in the conversation.
|
|
529
|
+
const reply: interfaces.TControllerPermissionReply = detailArg.response === 'reject' ? 'reject' : 'once';
|
|
530
|
+
await this.send(itemArg, async (senderArg) => {
|
|
531
|
+
const where = itemArg.where;
|
|
532
|
+
switch (where.kind) {
|
|
533
|
+
case 'conversation': case 'driver':
|
|
534
|
+
await senderArg.fire<interfaces.IReq_ControllerPermissionReply>('controller.permission.reply',
|
|
535
|
+
{ projectId: where.projectId, sessionId: where.sessionId, requestId: permission.id, reply });
|
|
536
|
+
return;
|
|
537
|
+
case 'native':
|
|
538
|
+
await senderArg.fire<interfaces.IReq_ControllerNativeSessionPermissionReply>('controller.nativesession.permission.reply',
|
|
539
|
+
{ session: where.session, requestId: permission.id, reply });
|
|
540
|
+
return;
|
|
541
|
+
case 'child': {
|
|
542
|
+
const scopeGeneration = await this.childScope(senderArg, where);
|
|
543
|
+
await senderArg.fire<interfaces.IReq_ControllerSessionChildPermissionReply>('controller.session.child.permission.reply', {
|
|
544
|
+
projectId: where.projectId, parentSessionId: where.parentSessionId, childSessionId: where.childSessionId, scopeGeneration,
|
|
545
|
+
requestId: permission.id as interfaces.IControllerRuntimeId & { harnessId: 'opencode' }, reply,
|
|
546
|
+
});
|
|
547
|
+
}
|
|
548
|
+
}
|
|
549
|
+
});
|
|
550
|
+
}
|
|
551
|
+
|
|
552
|
+
private async answerQuestionCard(itemArg: TInboxItem, cardArg: plugins.deesCatalog.IHarnessQuestionRequest,
|
|
553
|
+
detailArg: plugins.deesCatalog.IHarnessQuestionResponseDetail | undefined): Promise<void> {
|
|
554
|
+
const answers = (detailArg?.answers ?? []).filter((answerArg) => typeof answerArg === 'string' && answerArg.trim().length > 0);
|
|
555
|
+
if (answers.length === 0) return;
|
|
556
|
+
if (itemArg.kind === 'ticket_question' && itemArg.question) {
|
|
557
|
+
const answer = interfaces.ticketAnswerFromCard(itemArg.question, answers);
|
|
558
|
+
this.keepDraft(itemArg, cardArg, answers);
|
|
559
|
+
await this.answerTicket(itemArg, answer);
|
|
560
|
+
return;
|
|
561
|
+
}
|
|
562
|
+
if (itemArg.kind !== 'question' || !itemArg.question) return;
|
|
563
|
+
const request = itemArg.question;
|
|
564
|
+
const state = this.feed!.state(itemArg);
|
|
565
|
+
const index = questionCards(request, itemArg.id).findIndex((candidateArg) => candidateArg.id === cardArg.id);
|
|
566
|
+
if (index < 0) return;
|
|
567
|
+
this.keepDraft(itemArg, cardArg, answers);
|
|
568
|
+
state.batch.set(index, answers);
|
|
569
|
+
if (state.batch.size < request.questions.length) return;
|
|
570
|
+
const assembled = request.questions.map((_questionArg, indexArg) => state.batch.get(indexArg) ?? []);
|
|
571
|
+
state.batch.clear();
|
|
572
|
+
await this.send(itemArg, async (senderArg) => {
|
|
573
|
+
const where = itemArg.where;
|
|
574
|
+
switch (where.kind) {
|
|
575
|
+
case 'conversation': case 'driver':
|
|
576
|
+
await senderArg.fire<interfaces.IReq_ControllerQuestionReply>('controller.question.reply',
|
|
577
|
+
{ projectId: where.projectId, sessionId: where.sessionId, requestId: request.id, answers: assembled });
|
|
578
|
+
return;
|
|
579
|
+
case 'native':
|
|
580
|
+
await senderArg.fire<interfaces.IReq_ControllerNativeSessionQuestionReply>('controller.nativesession.question.reply',
|
|
581
|
+
{ session: where.session, requestId: request.id, answers: assembled });
|
|
582
|
+
return;
|
|
583
|
+
case 'child': {
|
|
584
|
+
const scopeGeneration = await this.childScope(senderArg, where);
|
|
585
|
+
await senderArg.fire<interfaces.IReq_ControllerSessionChildQuestionReply>('controller.session.child.question.reply', {
|
|
586
|
+
projectId: where.projectId, parentSessionId: where.parentSessionId, childSessionId: where.childSessionId, scopeGeneration,
|
|
587
|
+
requestId: request.id as interfaces.IControllerRuntimeId & { harnessId: 'opencode' }, answers: assembled,
|
|
588
|
+
});
|
|
589
|
+
}
|
|
590
|
+
}
|
|
591
|
+
});
|
|
592
|
+
}
|
|
593
|
+
|
|
594
|
+
private async answerElicitation(itemArg: interfaces.IControllerInboxElicitationItem,
|
|
595
|
+
detailArg: plugins.deesCatalog.IHarnessElicitationResponseDetail | undefined): Promise<void> {
|
|
596
|
+
const elicitation = itemArg.elicitation;
|
|
597
|
+
const reply = elicitationReply(detailArg);
|
|
598
|
+
if (!elicitation || !reply) return;
|
|
599
|
+
await this.send(itemArg, async (senderArg) => {
|
|
600
|
+
const where = itemArg.where;
|
|
601
|
+
switch (where.kind) {
|
|
602
|
+
case 'conversation': case 'driver':
|
|
603
|
+
await senderArg.fire<interfaces.IReq_ControllerElicitationReply>('controller.elicitation.reply',
|
|
604
|
+
{ projectId: where.projectId, sessionId: where.sessionId, requestId: elicitation.id, reply });
|
|
605
|
+
return;
|
|
606
|
+
case 'native':
|
|
607
|
+
await senderArg.fire<interfaces.IReq_ControllerNativeSessionElicitationReply>('controller.nativesession.elicitation.reply',
|
|
608
|
+
{ session: where.session, requestId: elicitation.id, reply });
|
|
609
|
+
return;
|
|
610
|
+
case 'child':
|
|
611
|
+
throw new InboxNotSentError('A subagent\'s MCP form is answered in its session view, so nothing was sent.');
|
|
612
|
+
}
|
|
613
|
+
});
|
|
614
|
+
}
|
|
615
|
+
|
|
616
|
+
private async answerGo(itemArg: interfaces.IControllerInboxDeployGoItem | interfaces.IControllerInboxWindowGoItem,
|
|
617
|
+
optionIdArg: string): Promise<void> {
|
|
618
|
+
await this.answerTicket(itemArg, { choices: [optionIdArg] });
|
|
619
|
+
}
|
|
620
|
+
|
|
621
|
+
private async answerTicket(itemArg: TTicketItem, answerArg: Pick<interfaces.ITicketAnswer, 'choices' | 'text'>): Promise<void> {
|
|
622
|
+
const question = itemArg.question;
|
|
623
|
+
if (!question) return;
|
|
624
|
+
await this.send(itemArg, async (senderArg) => {
|
|
625
|
+
await ticketOperation(senderArg, 'answer', {
|
|
626
|
+
ticketId: itemArg.where.ticketId, questionId: question.id, choices: answerArg.choices,
|
|
627
|
+
...(answerArg.text === undefined ? {} : { text: answerArg.text }),
|
|
628
|
+
});
|
|
629
|
+
});
|
|
630
|
+
}
|
|
631
|
+
|
|
632
|
+
/** A direct child's scope, which its replies name: read from the controller before the answer goes. */
|
|
633
|
+
private async childScope(senderArg: IInboxSender, whereArg: Extract<interfaces.TControllerInboxWhere, { kind: 'child' }>): Promise<string> {
|
|
634
|
+
try {
|
|
635
|
+
const detail = await senderArg.fire<interfaces.IReq_ControllerSessionChildGet>('controller.session.child.get',
|
|
636
|
+
{ projectId: whereArg.projectId, parentSessionId: whereArg.parentSessionId, childSessionId: whereArg.childSessionId });
|
|
637
|
+
return detail.scopeGeneration;
|
|
638
|
+
} catch (errorArg) {
|
|
639
|
+
throw new InboxNotSentError(`The subagent could not be read, so nothing was sent: ${inboxAnswerFailure(errorArg).message}`);
|
|
640
|
+
}
|
|
641
|
+
}
|
|
642
|
+
|
|
643
|
+
/**
|
|
644
|
+
* Sends one answer and records where it stands. Taken, the next item shows. Refused, nothing was stored and the card
|
|
645
|
+
* takes an answer again with the owner's draft; a question that already has another answer shows it beside the
|
|
646
|
+
* draft. Of unknown outcome, the card keeps its fence and its draft until the owner checks again.
|
|
647
|
+
*/
|
|
648
|
+
private async send(itemArg: TInboxItem, sendArg: (senderArg: IInboxSender) => Promise<void>): Promise<void> {
|
|
649
|
+
const sender = this.sender;
|
|
650
|
+
const feed = this.feed;
|
|
651
|
+
if (!sender || !feed) return;
|
|
652
|
+
const state = feed.state(itemArg);
|
|
653
|
+
if (this.fenced(state)) return;
|
|
654
|
+
if (!sender.isConnected) {
|
|
655
|
+
this.refuse(state, notConnectedText);
|
|
656
|
+
return;
|
|
657
|
+
}
|
|
658
|
+
feed.update(state, { phase: 'sending' });
|
|
659
|
+
try {
|
|
660
|
+
await sendArg(sender);
|
|
661
|
+
} catch (errorArg) {
|
|
662
|
+
if (errorArg instanceof InboxNotSentError) {
|
|
663
|
+
this.refuse(state, errorArg.message);
|
|
664
|
+
return;
|
|
665
|
+
}
|
|
666
|
+
await this.failed(state, inboxAnswerFailure(errorArg));
|
|
667
|
+
return;
|
|
668
|
+
}
|
|
669
|
+
if (!feed.holds(state)) return;
|
|
670
|
+
feed.update(state, { phase: 'answered' });
|
|
671
|
+
if (this.selectedId === itemArg.id) this.advance(itemArg.id);
|
|
672
|
+
}
|
|
673
|
+
|
|
674
|
+
/** Records a failed answer; one that settles after a sign-out (`clear()`) records nothing. */
|
|
675
|
+
private async failed(stateArg: IInboxItemState, failureArg: TInboxAnswerFailure): Promise<void> {
|
|
676
|
+
if (!this.feed!.holds(stateArg)) return;
|
|
677
|
+
if (failureArg.kind === 'unknown') {
|
|
678
|
+
const message = unknownOutcomeText(failureArg.message);
|
|
679
|
+
stateArg.outcome = message;
|
|
680
|
+
this.feed!.update(stateArg, { phase: 'unknown', message });
|
|
681
|
+
this.showOnCards(stateArg, message);
|
|
682
|
+
return;
|
|
683
|
+
}
|
|
684
|
+
const item = stateArg.item;
|
|
685
|
+
if (failureArg.code === 'ticket_question_answered' && isTicketItem(item)) {
|
|
686
|
+
const stored = await this.storedAnswer(item);
|
|
687
|
+
if (!this.feed!.holds(stateArg)) return;
|
|
688
|
+
const message = `${stored ? `Already answered: ${stored}.` : 'Already answered elsewhere.'} A question takes one answer, so yours was not saved; it is kept here.`;
|
|
689
|
+
this.feed!.update(stateArg, { phase: 'refused', message, held: true });
|
|
690
|
+
this.showOnCards(stateArg, message);
|
|
691
|
+
return;
|
|
692
|
+
}
|
|
693
|
+
this.refuse(stateArg, failureArg.message);
|
|
694
|
+
}
|
|
695
|
+
|
|
696
|
+
/** A refusal: nothing was stored, and the card takes an answer again with the owner's draft. */
|
|
697
|
+
private refuse(stateArg: IInboxItemState, messageArg: string): void {
|
|
698
|
+
if (!this.feed!.holds(stateArg)) return;
|
|
699
|
+
if (stateArg.item.kind === 'permission') {
|
|
700
|
+
stateArg.attempt += 1;
|
|
701
|
+
stateArg.permission = {};
|
|
702
|
+
}
|
|
703
|
+
if (stateArg.item.kind === 'question') stateArg.batch.clear();
|
|
704
|
+
this.feed!.update(stateArg, { phase: 'refused', message: messageArg });
|
|
705
|
+
this.showOnCards(stateArg, messageArg);
|
|
706
|
+
}
|
|
707
|
+
|
|
708
|
+
/** The answer a ticket question already has, read from its ticket, in words; nothing when it cannot be read. */
|
|
709
|
+
private async storedAnswer(itemArg: TTicketItem): Promise<string | undefined> {
|
|
710
|
+
const sender = this.sender;
|
|
711
|
+
const questionId = itemArg.question?.id;
|
|
712
|
+
if (!sender || !questionId) return undefined;
|
|
713
|
+
try {
|
|
714
|
+
const { questions } = await ticketOperation(sender, 'get', { ticketId: itemArg.where.ticketId });
|
|
715
|
+
const question = questions.find((questionArg) => questionArg.id === questionId);
|
|
716
|
+
return question?.answer ? `“${inboxTicketAnswerText(question)}” by ${question.answer.answeredBy.name}` : undefined;
|
|
717
|
+
} catch {
|
|
718
|
+
return undefined;
|
|
719
|
+
}
|
|
720
|
+
}
|
|
721
|
+
|
|
722
|
+
/**
|
|
723
|
+
* Checks again whether an answer of unknown outcome arrived: the Inbox is listed again, and a ticket's question read
|
|
724
|
+
* from its ticket. An item that no longer waits goes; one that still waits takes an answer again, from the owner only.
|
|
725
|
+
* A check that cannot be made (the connection is down, the listing fails or a sign-out drops it) leaves the outcome
|
|
726
|
+
* unknown and the fence in place.
|
|
727
|
+
*/
|
|
728
|
+
private async recheck(itemArg: TInboxItem): Promise<void> {
|
|
729
|
+
const feed = this.feed;
|
|
730
|
+
const sender = this.sender;
|
|
731
|
+
if (!feed || !sender) return;
|
|
732
|
+
const state = feed.state(itemArg);
|
|
733
|
+
if (state.phase !== 'unknown') return;
|
|
734
|
+
// The answer's unknown outcome and the newest check's failure: an earlier check's failure is replaced.
|
|
735
|
+
const checkFailed = (failureArg: string): void => {
|
|
736
|
+
feed.update(state, { phase: 'unknown', message: `${state.outcome ?? ''} The check failed too: ${failureArg}`.trim() });
|
|
737
|
+
};
|
|
738
|
+
if (!sender.isConnected) {
|
|
739
|
+
checkFailed(notCheckedText);
|
|
740
|
+
return;
|
|
741
|
+
}
|
|
742
|
+
feed.update(state, { phase: 'checking', message: state.message });
|
|
743
|
+
let open = true;
|
|
744
|
+
let stored: interfaces.ITicketQuestion | undefined;
|
|
745
|
+
try {
|
|
746
|
+
if (!await feed.refresh()) throw new Error(feed.error || 'The Inbox could not be listed again.');
|
|
747
|
+
if (isTicketItem(itemArg) && itemArg.question) {
|
|
748
|
+
const questionId = itemArg.question.id;
|
|
749
|
+
const { questions } = await ticketOperation(sender, 'get', { ticketId: itemArg.where.ticketId });
|
|
750
|
+
stored = questions.find((questionArg) => questionArg.id === questionId);
|
|
751
|
+
open = stored?.status === 'open';
|
|
752
|
+
} else {
|
|
753
|
+
open = feed.listed(itemArg.id);
|
|
754
|
+
}
|
|
755
|
+
} catch (errorArg) {
|
|
756
|
+
checkFailed(inboxAnswerFailure(errorArg).message);
|
|
757
|
+
return;
|
|
758
|
+
}
|
|
759
|
+
if (!feed.holds(state)) return;
|
|
760
|
+
if (open) {
|
|
761
|
+
this.refuse(state, stillWaitsText);
|
|
762
|
+
return;
|
|
763
|
+
}
|
|
764
|
+
if (stored?.answer) {
|
|
765
|
+
// The ticket holds an answer: the owner's own, or another client's, which stands beside the owner's draft.
|
|
766
|
+
const message = `It no longer waits: answered “${inboxTicketAnswerText(stored)}” by ${stored.answer.answeredBy.name}.`;
|
|
767
|
+
feed.update(state, { phase: 'refused', message, held: this.selectedId === itemArg.id });
|
|
768
|
+
this.showOnCards(state, message);
|
|
769
|
+
return;
|
|
770
|
+
}
|
|
771
|
+
feed.update(state, { phase: 'answered' });
|
|
772
|
+
if (this.selectedId === itemArg.id) this.advance(itemArg.id);
|
|
773
|
+
}
|
|
774
|
+
|
|
775
|
+
/** Keeps what the owner chose on a question card, so a refusal shows the card with it. */
|
|
776
|
+
private keepDraft(itemArg: TInboxItem, cardArg: plugins.deesCatalog.IHarnessQuestionRequest, answersArg: readonly string[]): void {
|
|
777
|
+
const state = this.feed!.state(itemArg);
|
|
778
|
+
const viewState = state.questions.get(cardArg.id) ?? {};
|
|
779
|
+
const labels = new Set((cardArg.options ?? []).map((optionArg) => optionArg.label));
|
|
780
|
+
viewState.selected = answersArg.filter((answerArg) => labels.has(answerArg));
|
|
781
|
+
state.questions.set(cardArg.id, viewState);
|
|
782
|
+
}
|
|
783
|
+
|
|
784
|
+
/**
|
|
785
|
+
* Shows a refusal or an unknown outcome on the item's cards: a question card waits again with the draft kept (its
|
|
786
|
+
* fence holds it while the outcome is unknown), and an MCP form shows it as the refusal of its last answer.
|
|
787
|
+
*/
|
|
788
|
+
private showOnCards(stateArg: IInboxItemState, messageArg: string): void {
|
|
789
|
+
if (!this.feed?.holds(stateArg)) return;
|
|
790
|
+
const item = stateArg.item;
|
|
791
|
+
if (item.kind === 'elicitation') {
|
|
792
|
+
stateArg.elicitation.refuse(item.id, messageArg);
|
|
793
|
+
this.requestUpdate();
|
|
794
|
+
return;
|
|
795
|
+
}
|
|
796
|
+
// A card not on screen shows it from its view state when it comes back; one on screen is told now.
|
|
797
|
+
for (const viewState of stateArg.questions.values()) {
|
|
798
|
+
viewState.answered = undefined;
|
|
799
|
+
viewState.rejection = { message: messageArg };
|
|
800
|
+
}
|
|
801
|
+
void this.updateComplete.then(() => {
|
|
802
|
+
for (const card of this.shadowRoot?.querySelectorAll<plugins.deesCatalog.DeesHarnessQuestionCard>(
|
|
803
|
+
`dees-harness-question-card[data-item="${CSS.escape(item.id)}"]`) ?? []) {
|
|
804
|
+
card.rejectResponse({ message: messageArg });
|
|
805
|
+
}
|
|
806
|
+
});
|
|
807
|
+
}
|
|
808
|
+
}
|