agl 43.0.5 → 43.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/changelog.md +30 -0
- package/dist_serve/bundle.js +5996 -5280
- package/dist_serve/bundle.js.map +2 -2
- package/dist_serve/bundle.js.third-party-notices.json +30 -30
- package/dist_serve/bundle.js.third-party-notices.txt +30 -30
- package/dist_serve/third-party-notices.md +1 -1
- package/dist_ts/00_commitinfo_data.js +1 -1
- package/dist_ts/aglapi/aglapisurface.document.js +805 -10
- package/dist_ts/aglapi/interfaces.d.ts +13 -0
- package/dist_ts/aglapi/interfaces.js +4 -1
- package/dist_ts/classes.authmodels.js +17 -4
- package/dist_ts/classes.authstore.js +16 -2
- package/dist_ts/classes.claudeharness.d.ts +14 -5
- package/dist_ts/classes.claudeharness.js +62 -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 +7 -5
- package/dist_ts/classes.codexclientadapter.js +38 -3
- package/dist_ts/classes.controller.d.ts +19 -2
- package/dist_ts/classes.controller.js +234 -27
- 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.inferencegateway.d.ts +8 -5
- package/dist_ts/classes.inferencegateway.js +62 -19
- package/dist_ts/classes.inferencerouter.d.ts +9 -0
- package/dist_ts/classes.inferencerouter.js +11 -1
- package/dist_ts/classes.inferenceservice.d.ts +9 -0
- package/dist_ts/classes.inferenceservice.js +27 -1
- package/dist_ts/classes.inferencespend.d.ts +9 -3
- package/dist_ts/classes.inferencespend.js +44 -16
- package/dist_ts/classes.mcpclient.d.ts +9 -4
- package/dist_ts/classes.mcpclient.js +24 -2
- package/dist_ts/classes.mcpcontrollerhost.d.ts +3 -1
- package/dist_ts/classes.mcpcontrollerhost.js +13 -1
- package/dist_ts/classes.mcptools.d.ts +3 -3
- package/dist_ts/classes.mcptools.js +42 -4
- package/dist_ts/classes.mcpvalidation.js +7 -1
- package/dist_ts/classes.opencodeclient.js +3 -1
- package/dist_ts/classes.proxycontrol.d.ts +33 -11
- package/dist_ts/classes.proxycontrol.js +12 -3
- package/dist_ts/classes.proxycontrolclient.d.ts +23 -5
- package/dist_ts/classes.proxycontrolclient.js +42 -6
- package/dist_ts/classes.proxydaemon.d.ts +8 -6
- package/dist_ts/classes.proxydaemon.js +42 -21
- package/dist_ts/classes.proxyleaseholder.d.ts +12 -4
- package/dist_ts/classes.proxyleaseholder.js +39 -9
- package/dist_ts/classes.proxymonitor.d.ts +7 -0
- package/dist_ts/classes.proxymonitor.js +13 -1
- package/dist_ts/classes.proxystore.d.ts +4 -3
- package/dist_ts/classes.proxystore.js +17 -7
- package/dist_ts/classes.sessionfeed.d.ts +1 -1
- package/dist_ts/classes.trustedproxysecrets.d.ts +2 -0
- package/dist_ts/classes.trustedproxysecrets.js +5 -1
- package/dist_ts/classes.validation.d.ts +7 -0
- package/dist_ts/classes.validation.js +49 -2
- package/dist_ts/driver/functions.drivertools.js +2 -2
- package/dist_ts/fleet/classes.codexworkers.d.ts +4 -11
- package/dist_ts/fleet/classes.codexworkers.js +6 -3
- package/dist_ts/fleet/classes.workers.d.ts +25 -13
- package/dist_ts/fleet/classes.workers.js +105 -9
- package/dist_ts/fleet/functions.workervalidation.d.ts +26 -1
- package/dist_ts/fleet/functions.workervalidation.js +40 -11
- package/dist_ts/fleet/interfaces.workers.d.ts +17 -11
- package/dist_ts/fleet/interfaces.workers.js +10 -1
- package/dist_ts/functions.confinedrelay.d.ts +21 -0
- package/dist_ts/functions.confinedrelay.js +65 -0
- package/dist_ts/functions.controllermanagementsurface.d.ts +4 -0
- package/dist_ts/functions.controllermanagementsurface.js +15 -1
- package/dist_ts/functions.deviceapi.d.ts +4 -2
- package/dist_ts/functions.deviceapi.js +20 -2
- package/dist_ts/functions.elicitation.d.ts +49 -0
- package/dist_ts/functions.elicitation.js +418 -0
- 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.d.ts +3 -3
- package/dist_ts/functions.inferencecli.js +62 -10
- package/dist_ts/functions.inferencecliarguments.d.ts +9 -2
- package/dist_ts/functions.inferencecliarguments.js +59 -10
- package/dist_ts/functions.inferencelaunch.d.ts +35 -7
- package/dist_ts/functions.inferencelaunch.js +143 -16
- package/dist_ts/functions.mcpfleetworkertools.d.ts +63 -70
- package/dist_ts/functions.mcpfleetworkertools.js +32 -4
- 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.proxycontract.d.ts +21 -4
- package/dist_ts/functions.proxycontract.js +12 -5
- package/dist_ts/functions.proxyharnessconfig.d.ts +7 -0
- package/dist_ts/functions.proxyharnessconfig.js +11 -1
- package/dist_ts/functions.remotecli.d.ts +30 -3
- package/dist_ts/functions.remotecli.js +44 -18
- package/dist_ts/interfaces.auth.d.ts +25 -4
- package/dist_ts/interfaces.auth.js +8 -1
- package/dist_ts/plugins.d.ts +2 -0
- package/dist_ts/plugins.js +4 -1
- package/dist_ts_authswitch/authority-placement.js +3 -17
- 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_interfaces/devices.d.ts +133 -3
- package/dist_ts_interfaces/devices.js +3 -2
- package/dist_ts_interfaces/elicitations.d.ts +125 -0
- package/dist_ts_interfaces/elicitations.js +7 -0
- package/dist_ts_interfaces/fleetworkers.d.ts +119 -5
- package/dist_ts_interfaces/fleetworkers.js +14 -2
- package/dist_ts_interfaces/gateway.d.ts +151 -0
- package/dist_ts_interfaces/gateway.js +66 -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 +3 -1
- package/dist_ts_interfaces/interfaces.js +2 -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 +18 -2
- package/dist_ts_interfaces/mcprequests.js +3 -1
- package/dist_ts_interfaces/nativesessions.d.ts +14 -0
- package/dist_ts_interfaces/proxycapacity.d.ts +99 -0
- package/dist_ts_interfaces/proxycapacity.js +74 -0
- package/dist_ts_interfaces/requests.d.ts +3 -3
- package/dist_ts_interfaces/requests.fleetworkers.js +2 -2
- package/dist_ts_interfaces/requests.js +1 -1
- package/dist_ts_interfaces/requests.promptreply.d.ts +18 -0
- package/dist_ts_interfaces/sessionfeed.d.ts +3 -2
- package/dist_ts_interfaces/sessionfeed.js +1 -1
- package/package.json +5 -4
- package/readme.md +267 -26
- package/third-party-notices.md +1 -1
- package/ts/00_commitinfo_data.ts +1 -1
- package/ts/aglapi/aglapisurface.document.ts +804 -9
- package/ts/aglapi/interfaces.ts +3 -0
- package/ts/classes.authmodels.ts +22 -3
- package/ts/classes.authstore.ts +15 -1
- package/ts/classes.claudeharness.ts +80 -9
- package/ts/classes.cli.ts +7 -3
- package/ts/classes.codexclientadapter.ts +41 -5
- package/ts/classes.controller.ts +276 -32
- package/ts/classes.controllermanagement.ts +40 -7
- package/ts/classes.gatewayclient.ts +401 -0
- package/ts/classes.gatewayclientstore.ts +272 -0
- package/ts/classes.inferencegateway.ts +69 -23
- package/ts/classes.inferencerouter.ts +12 -0
- package/ts/classes.inferenceservice.ts +27 -0
- package/ts/classes.inferencespend.ts +46 -13
- package/ts/classes.mcpclient.ts +26 -4
- package/ts/classes.mcpcontrollerhost.ts +17 -0
- package/ts/classes.mcptools.ts +47 -5
- package/ts/classes.mcpvalidation.ts +5 -0
- package/ts/classes.opencodeclient.ts +2 -0
- package/ts/classes.proxycontrol.ts +43 -13
- package/ts/classes.proxycontrolclient.ts +39 -6
- package/ts/classes.proxydaemon.ts +57 -27
- package/ts/classes.proxyleaseholder.ts +43 -11
- package/ts/classes.proxymonitor.ts +12 -0
- package/ts/classes.proxystore.ts +21 -8
- package/ts/classes.sessionfeed.ts +1 -1
- package/ts/classes.trustedproxysecrets.ts +5 -0
- package/ts/classes.validation.ts +52 -0
- package/ts/driver/functions.drivertools.ts +1 -1
- package/ts/fleet/classes.codexworkers.ts +8 -6
- package/ts/fleet/classes.workers.ts +101 -17
- package/ts/fleet/functions.workervalidation.ts +35 -9
- package/ts/fleet/interfaces.workers.ts +11 -4
- package/ts/functions.confinedrelay.ts +65 -0
- package/ts/functions.controllermanagementsurface.ts +15 -0
- package/ts/functions.deviceapi.ts +24 -1
- package/ts/functions.elicitation.ts +443 -0
- package/ts/functions.gatewaycli.ts +436 -0
- package/ts/functions.gatewayroute.ts +429 -0
- package/ts/functions.inferencecli.ts +62 -13
- package/ts/functions.inferencecliarguments.ts +56 -9
- package/ts/functions.inferencelaunch.ts +143 -16
- package/ts/functions.mcpfleetworkertools.ts +34 -4
- package/ts/functions.proxycapacity.ts +191 -0
- package/ts/functions.proxycapacitycli.ts +104 -0
- package/ts/functions.proxycontract.ts +17 -4
- package/ts/functions.proxyharnessconfig.ts +11 -0
- package/ts/functions.remotecli.ts +56 -20
- package/ts/interfaces.auth.ts +29 -4
- package/ts/plugins.ts +5 -0
- package/ts_authswitch/authority-placement.ts +2 -15
- package/ts_authswitch/authority-usagelimit.ts +84 -1
- package/ts_authswitch/authority-usagewindows.ts +13 -0
- package/ts_interfaces/devices.schema.json +476 -2
- package/ts_interfaces/devices.ts +146 -2
- package/ts_interfaces/elicitations.ts +148 -0
- package/ts_interfaces/fleetworkers.ts +96 -4
- package/ts_interfaces/gateway.ts +242 -0
- package/ts_interfaces/index.ts +3 -0
- package/ts_interfaces/interfaces.ts +3 -1
- package/ts_interfaces/management.ts +6 -4
- package/ts_interfaces/mcprequests.ts +19 -0
- package/ts_interfaces/nativesessions.ts +16 -0
- package/ts_interfaces/proxycapacity.ts +162 -0
- package/ts_interfaces/requests.fleetworkers.ts +1 -1
- package/ts_interfaces/requests.promptreply.ts +22 -0
- package/ts_interfaces/requests.ts +4 -0
- package/ts_interfaces/sessionfeed.ts +3 -2
- package/ts_web/00_commitinfo_data.ts +1 -1
- package/ts_web/classes.browserpresentation.ts +13 -5
- package/ts_web/classes.elicitationcards.ts +106 -0
- package/ts_web/classes.nativesessionstate.ts +38 -1
- package/ts_web/elements.accounts.ts +40 -113
- package/ts_web/elements.configurationpane.ts +24 -37
- package/ts_web/elements.devices.ts +4 -17
- package/ts_web/elements.fleetworker.ts +27 -2
- package/ts_web/elements.flexlimitstrip.ts +21 -70
- package/ts_web/elements.harnesscontrollerapp.ts +159 -186
- package/ts_web/functions.sessionchat.ts +5 -0
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import type * as plugins from './plugins.js';
|
|
2
|
+
import type { TControllerElicitation, TControllerElicitationReply } from './elicitations.js';
|
|
2
3
|
import type {
|
|
3
4
|
IControllerDraftAttachment,
|
|
4
5
|
TControllerPermissionReply,
|
|
@@ -71,6 +72,7 @@ export interface IReq_ControllerNativeSessionRead extends plugins.typedrequestIn
|
|
|
71
72
|
/** Requests of a turn AGL runs in the session that wait for the owner. */
|
|
72
73
|
permissions: IControllerPermission[];
|
|
73
74
|
questions: IControllerQuestion[];
|
|
75
|
+
elicitations: TControllerElicitation[];
|
|
74
76
|
todos: IControllerTodo[];
|
|
75
77
|
scratchpad: IControllerSessionScratchpad;
|
|
76
78
|
intelligenceExchanges: IControllerIntelligenceExchange[];
|
|
@@ -157,3 +159,17 @@ export interface IReq_ControllerNativeSessionQuestionReply extends plugins.typed
|
|
|
157
159
|
};
|
|
158
160
|
response: { success: boolean };
|
|
159
161
|
}
|
|
162
|
+
|
|
163
|
+
/** Answers an MCP elicitation of a turn AGL runs in a native session. */
|
|
164
|
+
export interface IReq_ControllerNativeSessionElicitationReply extends plugins.typedrequestInterfaces.implementsTR<
|
|
165
|
+
plugins.typedrequestInterfaces.ITypedRequest,
|
|
166
|
+
IReq_ControllerNativeSessionElicitationReply
|
|
167
|
+
> {
|
|
168
|
+
method: 'controller.nativesession.elicitation.reply';
|
|
169
|
+
request: {
|
|
170
|
+
session: IControllerNativeSessionRef;
|
|
171
|
+
requestId: IControllerRuntimeId;
|
|
172
|
+
reply: TControllerElicitationReply;
|
|
173
|
+
};
|
|
174
|
+
response: { success: boolean };
|
|
175
|
+
}
|
|
@@ -0,0 +1,162 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A pool's room for new work in AGL's inference proxy (AGL-1097): `agl proxy capacity`, the proxy's
|
|
3
|
+
* `agl.proxy.capacity` and the MCP tool `proxy_capacity` answer it alike. A leaf: it imports nothing.
|
|
4
|
+
*
|
|
5
|
+
* The answer carries no identity: an account is named by its account id alone, never by its label or email.
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
/** A pool: Claude accounts (`anthropic`) or ChatGPT accounts (`openai`). */
|
|
9
|
+
export type TProxyCapacityProvider = 'anthropic' | 'openai';
|
|
10
|
+
export const proxyCapacityProviders: readonly TProxyCapacityProvider[] = ['anthropic', 'openai'];
|
|
11
|
+
|
|
12
|
+
/** The room a pool needs, in headroom percent summed over its members, when a request names none. */
|
|
13
|
+
export const proxyCapacityDefaultMinimumHeadroom = 15;
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* How long a pool waits after the newest provider 429 on one of its members, and how long a proxy must have observed its
|
|
17
|
+
* pools before the absence of a 429 counts: five minutes.
|
|
18
|
+
*/
|
|
19
|
+
export const proxyCapacityQuietMs = 300_000;
|
|
20
|
+
|
|
21
|
+
/** What is asked: one pool, or both when `provider` is absent, against `minHeadroom` (a non-negative integer). */
|
|
22
|
+
export interface IProxyCapacityRequest {
|
|
23
|
+
provider?: TProxyCapacityProvider;
|
|
24
|
+
minHeadroom?: number;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
/** A member's window, as its reading states it. */
|
|
28
|
+
export interface IProxyCapacityWindow {
|
|
29
|
+
/** The provider's name for the window, or its length (`5h`, `7d`) for one without a name. */
|
|
30
|
+
name: string;
|
|
31
|
+
durationSeconds: number;
|
|
32
|
+
/** The percent its limit decides by: the account service's estimate between reads where it has one. */
|
|
33
|
+
usedPercent: number;
|
|
34
|
+
/** Whether `usedPercent` is that estimate. */
|
|
35
|
+
estimated: boolean;
|
|
36
|
+
/** When its current period ends, as the reading states it; `null` when it states none. */
|
|
37
|
+
resetAt: string | null;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
/** Whether a member takes new work now, as `agl proxy status` judges it, or why not. */
|
|
41
|
+
export type TProxyCapacityMemberState = 'available' | 'reserved' | 'exhausted' | 'cooling' | 'unavailable';
|
|
42
|
+
export const proxyCapacityMemberStates: readonly TProxyCapacityMemberState[] = ['available', 'reserved', 'exhausted',
|
|
43
|
+
'cooling', 'unavailable'];
|
|
44
|
+
|
|
45
|
+
/** An account the pool counts: a subscription sign-in of a counted plan that has not lapsed. */
|
|
46
|
+
export interface IProxyCapacityMember {
|
|
47
|
+
/** The account's id (64 hex characters). */
|
|
48
|
+
accountId: string;
|
|
49
|
+
/** Its plan as its held reading states it, one the pool counts. */
|
|
50
|
+
plan: string;
|
|
51
|
+
state: TProxyCapacityMemberState;
|
|
52
|
+
/** The headroom it adds to the room now: its headroom below its threshold while it takes new work, else 0. */
|
|
53
|
+
headroom: number;
|
|
54
|
+
/** The window its headroom is bound by; `null` without a usable reading with a counted window. */
|
|
55
|
+
binding: IProxyCapacityWindow | null;
|
|
56
|
+
/**
|
|
57
|
+
* When the headroom it adds next grows, from its reading alone: the binding window's reset, or the moment it takes
|
|
58
|
+
* work again (a provider 429's rest, a provider refusal, its windows' resets); `null` when it cannot grow or that
|
|
59
|
+
* moment is unknown (a stale reading, a sign-in or payment problem).
|
|
60
|
+
*/
|
|
61
|
+
growsAt: string | null;
|
|
62
|
+
/** The headroom it adds from `growsAt` on, at most; `null` with it. */
|
|
63
|
+
growsTo: number | null;
|
|
64
|
+
/** When the account service reads an account it cannot judge now again, when it says; `null` otherwise. */
|
|
65
|
+
recheckAt: string | null;
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
/** Why a pool waits: too little room, a provider 429 within the quiet period, or a proxy that has not observed it long enough. */
|
|
69
|
+
export type TProxyCapacityWaitReason = 'room' | 'provider-429' | 'quiet-unobserved';
|
|
70
|
+
export const proxyCapacityWaitReasons: readonly TProxyCapacityWaitReason[] = ['room', 'provider-429', 'quiet-unobserved'];
|
|
71
|
+
|
|
72
|
+
/**
|
|
73
|
+
* `open`: the pool takes new work now. `wait`: not before `until`, `seconds` from the answer's `at`; both `null` when
|
|
74
|
+
* the members' readings foresee no moment the room reaches the minimum.
|
|
75
|
+
*/
|
|
76
|
+
export type TProxyCapacityVerdict =
|
|
77
|
+
| { state: 'open' }
|
|
78
|
+
| { state: 'wait'; reason: TProxyCapacityWaitReason; until: string; seconds: number }
|
|
79
|
+
| { state: 'wait'; reason: TProxyCapacityWaitReason; until: null; seconds: null };
|
|
80
|
+
|
|
81
|
+
export interface IProxyCapacityPool {
|
|
82
|
+
provider: TProxyCapacityProvider;
|
|
83
|
+
minHeadroom: number;
|
|
84
|
+
/** The members' headroom summed, in percent. */
|
|
85
|
+
room: number;
|
|
86
|
+
members: IProxyCapacityMember[];
|
|
87
|
+
/** The newest provider 429 on a member the proxy saw since `observedSince`, or `null`. */
|
|
88
|
+
last429At: string | null;
|
|
89
|
+
verdict: TProxyCapacityVerdict;
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
export interface IProxyCapacityAnswer {
|
|
93
|
+
/** When the proxy judged it, by its own clock. */
|
|
94
|
+
at: string;
|
|
95
|
+
/** Since when the proxy observes its pools' provider 429s: its start. */
|
|
96
|
+
observedSince: string;
|
|
97
|
+
pools: IProxyCapacityPool[];
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
/** At most this many members a pool lists (the proxy routes a pool of at most 64 accounts per request). */
|
|
101
|
+
const maximumMembers = 256;
|
|
102
|
+
|
|
103
|
+
const isRecord = (valueArg: unknown): valueArg is Record<string, unknown> =>
|
|
104
|
+
typeof valueArg === 'object' && valueArg !== null && !Array.isArray(valueArg);
|
|
105
|
+
const hasExactKeys = (valueArg: Record<string, unknown>, requiredArg: readonly string[],
|
|
106
|
+
optionalArg: readonly string[] = []): boolean => requiredArg.every((keyArg) => Object.hasOwn(valueArg, keyArg))
|
|
107
|
+
&& Object.keys(valueArg).every((keyArg) => requiredArg.includes(keyArg) || optionalArg.includes(keyArg));
|
|
108
|
+
const isTime = (valueArg: unknown): valueArg is string => typeof valueArg === 'string' && valueArg.length <= 32
|
|
109
|
+
&& Number.isFinite(Date.parse(valueArg));
|
|
110
|
+
const isTimeOrNull = (valueArg: unknown): boolean => valueArg === null || isTime(valueArg);
|
|
111
|
+
const isPercent = (valueArg: unknown): valueArg is number => typeof valueArg === 'number' && Number.isFinite(valueArg);
|
|
112
|
+
const isMinimum = (valueArg: unknown): valueArg is number => typeof valueArg === 'number' && Number.isSafeInteger(valueArg)
|
|
113
|
+
&& valueArg >= 0;
|
|
114
|
+
|
|
115
|
+
/** Whether a value is a capacity request as `IProxyCapacityRequest` states it, and nothing else. */
|
|
116
|
+
export const isProxyCapacityRequest = (valueArg: unknown): valueArg is IProxyCapacityRequest => isRecord(valueArg)
|
|
117
|
+
&& hasExactKeys(valueArg, [], ['provider', 'minHeadroom'])
|
|
118
|
+
&& (valueArg.provider === undefined || proxyCapacityProviders.includes(valueArg.provider as TProxyCapacityProvider))
|
|
119
|
+
&& (valueArg.minHeadroom === undefined || isMinimum(valueArg.minHeadroom));
|
|
120
|
+
|
|
121
|
+
const isWindow = (valueArg: unknown): boolean => isRecord(valueArg)
|
|
122
|
+
&& hasExactKeys(valueArg, ['name', 'durationSeconds', 'usedPercent', 'estimated', 'resetAt'])
|
|
123
|
+
&& typeof valueArg.name === 'string' && valueArg.name.length <= 128
|
|
124
|
+
&& isPercent(valueArg.durationSeconds) && isPercent(valueArg.usedPercent) && typeof valueArg.estimated === 'boolean'
|
|
125
|
+
&& isTimeOrNull(valueArg.resetAt);
|
|
126
|
+
|
|
127
|
+
const isMember = (valueArg: unknown): boolean => isRecord(valueArg)
|
|
128
|
+
&& hasExactKeys(valueArg, ['accountId', 'plan', 'state', 'headroom', 'binding', 'growsAt', 'growsTo', 'recheckAt'])
|
|
129
|
+
&& typeof valueArg.accountId === 'string' && /^[a-f0-9]{64}$/.test(valueArg.accountId)
|
|
130
|
+
&& typeof valueArg.plan === 'string' && valueArg.plan.length > 0 && valueArg.plan.length <= 128
|
|
131
|
+
&& proxyCapacityMemberStates.includes(valueArg.state as TProxyCapacityMemberState)
|
|
132
|
+
&& isPercent(valueArg.headroom) && valueArg.headroom >= 0
|
|
133
|
+
&& (valueArg.binding === null || isWindow(valueArg.binding))
|
|
134
|
+
&& isTimeOrNull(valueArg.growsAt) && (valueArg.growsAt === null) === (valueArg.growsTo === null)
|
|
135
|
+
&& (valueArg.growsTo === null || isPercent(valueArg.growsTo))
|
|
136
|
+
&& isTimeOrNull(valueArg.recheckAt);
|
|
137
|
+
|
|
138
|
+
const isVerdict = (valueArg: unknown): boolean => {
|
|
139
|
+
if (!isRecord(valueArg)) return false;
|
|
140
|
+
if (valueArg.state === 'open') return hasExactKeys(valueArg, ['state']);
|
|
141
|
+
return valueArg.state === 'wait' && hasExactKeys(valueArg, ['state', 'reason', 'until', 'seconds'])
|
|
142
|
+
&& proxyCapacityWaitReasons.includes(valueArg.reason as TProxyCapacityWaitReason)
|
|
143
|
+
&& (valueArg.until === null
|
|
144
|
+
? valueArg.seconds === null
|
|
145
|
+
: isTime(valueArg.until) && typeof valueArg.seconds === 'number' && Number.isSafeInteger(valueArg.seconds)
|
|
146
|
+
&& valueArg.seconds >= 0);
|
|
147
|
+
};
|
|
148
|
+
|
|
149
|
+
const isPool = (valueArg: unknown): boolean => isRecord(valueArg)
|
|
150
|
+
&& hasExactKeys(valueArg, ['provider', 'minHeadroom', 'room', 'members', 'last429At', 'verdict'])
|
|
151
|
+
&& proxyCapacityProviders.includes(valueArg.provider as TProxyCapacityProvider)
|
|
152
|
+
&& isMinimum(valueArg.minHeadroom) && isPercent(valueArg.room) && valueArg.room >= 0
|
|
153
|
+
&& Array.isArray(valueArg.members) && valueArg.members.length <= maximumMembers && valueArg.members.every(isMember)
|
|
154
|
+
&& isTimeOrNull(valueArg.last429At) && isVerdict(valueArg.verdict);
|
|
155
|
+
|
|
156
|
+
/** Whether a value is a capacity answer as `IProxyCapacityAnswer` states it, and nothing else. */
|
|
157
|
+
export const isProxyCapacityAnswer = (valueArg: unknown): valueArg is IProxyCapacityAnswer => isRecord(valueArg)
|
|
158
|
+
&& hasExactKeys(valueArg, ['at', 'observedSince', 'pools'])
|
|
159
|
+
&& isTime(valueArg.at) && isTime(valueArg.observedSince)
|
|
160
|
+
&& Array.isArray(valueArg.pools) && valueArg.pools.length >= 1 && valueArg.pools.length <= proxyCapacityProviders.length
|
|
161
|
+
&& valueArg.pools.every(isPool)
|
|
162
|
+
&& new Set(valueArg.pools.map((poolArg) => (poolArg as IProxyCapacityPool).provider)).size === valueArg.pools.length;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import type * as plugins from './plugins.js';
|
|
2
2
|
import type { IFleetWorker, IFleetWorkerJob, IFleetWorkerReport, IFleetWorkerTurnOutcome, TFleetWorkerAction, TFleetWorkerRequest, TFleetWorkerResponse } from './fleetworkers.js';
|
|
3
3
|
import type { IControllerDraftAttachment, IControllerMessageBundle, IControllerNativeWait } from './interfaces.js';
|
|
4
|
-
export const controllerMcpFleetWorkerMethods = ['start', 'adopt', 'resolve-lost', 'reconfirm', 'steer', 'report', 'stop', 'archive', 'refresh', 'move', 'list', 'status', 'watch', 'native-message'].map(
|
|
4
|
+
export const controllerMcpFleetWorkerMethods = ['start', 'adopt', 'resolve-lost', 'reconfirm', 'steer', 'report', 'stop', 'archive', 'refresh', 'move', 'list', 'get', 'status', 'job-wait', 'watch', 'native-message'].map(
|
|
5
5
|
(action) => `agl.mcp.fleet.worker.${action}`,
|
|
6
6
|
) as Array<`agl.mcp.fleet.worker.${TFleetWorkerAction}`>;
|
|
7
7
|
export type TControllerMcpFleetWorkerRequest<T extends TFleetWorkerAction> = {
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import * as plugins from './plugins.js';
|
|
2
2
|
import type { IControllerRuntimeId, TControllerPermissionReply } from './interfaces.js';
|
|
3
|
+
import type { TControllerElicitationReply } from './elicitations.js';
|
|
3
4
|
|
|
4
5
|
export interface IReq_ControllerPermissionReply extends plugins.typedrequestInterfaces.implementsTR<
|
|
5
6
|
plugins.typedrequestInterfaces.ITypedRequest,
|
|
@@ -34,3 +35,24 @@ export interface IReq_ControllerQuestionReply extends plugins.typedrequestInterf
|
|
|
34
35
|
success: boolean;
|
|
35
36
|
};
|
|
36
37
|
}
|
|
38
|
+
|
|
39
|
+
/**
|
|
40
|
+
* Answers an MCP elicitation of a Claude Code or Codex conversation. An accepted form's content is checked against the
|
|
41
|
+
* form before anything is sent; a mismatch is refused with `invalid_request`, a request no longer pending with
|
|
42
|
+
* `not_found`.
|
|
43
|
+
*/
|
|
44
|
+
export interface IReq_ControllerElicitationReply extends plugins.typedrequestInterfaces.implementsTR<
|
|
45
|
+
plugins.typedrequestInterfaces.ITypedRequest,
|
|
46
|
+
IReq_ControllerElicitationReply
|
|
47
|
+
> {
|
|
48
|
+
method: 'controller.elicitation.reply';
|
|
49
|
+
request: {
|
|
50
|
+
projectId: string;
|
|
51
|
+
sessionId: IControllerRuntimeId;
|
|
52
|
+
requestId: IControllerRuntimeId;
|
|
53
|
+
reply: TControllerElicitationReply;
|
|
54
|
+
};
|
|
55
|
+
response: {
|
|
56
|
+
success: boolean;
|
|
57
|
+
};
|
|
58
|
+
}
|
|
@@ -62,6 +62,7 @@ import type { IReq_ControllerSessionFeedAcknowledge, IReq_ControllerSessionFeedL
|
|
|
62
62
|
import type { TControllerDeployTypedRequest } from './deployments.js';
|
|
63
63
|
import type {
|
|
64
64
|
IReq_ControllerNativeSessionAuxiliaryGet,
|
|
65
|
+
IReq_ControllerNativeSessionElicitationReply,
|
|
65
66
|
IReq_ControllerNativeSessionIntelligenceAsk,
|
|
66
67
|
IReq_ControllerNativeSessionPermissionReply,
|
|
67
68
|
IReq_ControllerNativeSessionQuestionReply,
|
|
@@ -148,6 +149,7 @@ import type {
|
|
|
148
149
|
IReq_ControllerSessionYolo,
|
|
149
150
|
} from './requests.session.js';
|
|
150
151
|
import type {
|
|
152
|
+
IReq_ControllerElicitationReply,
|
|
151
153
|
IReq_ControllerPermissionReply,
|
|
152
154
|
IReq_ControllerQuestionReply,
|
|
153
155
|
} from './requests.promptreply.js';
|
|
@@ -277,6 +279,7 @@ export type TControllerRequest =
|
|
|
277
279
|
| IReq_ControllerNativeSessionIntelligenceAsk
|
|
278
280
|
| IReq_ControllerNativeSessionPermissionReply
|
|
279
281
|
| IReq_ControllerNativeSessionQuestionReply
|
|
282
|
+
| IReq_ControllerNativeSessionElicitationReply
|
|
280
283
|
| IReq_ControllerUsageWatch
|
|
281
284
|
| IReq_ControllerUsageUnwatch
|
|
282
285
|
| IReq_ControllerSystemMetrics
|
|
@@ -351,6 +354,7 @@ export type TControllerRequest =
|
|
|
351
354
|
| IReq_ControllerSessionPendingPromptAction
|
|
352
355
|
| IReq_ControllerPermissionReply
|
|
353
356
|
| IReq_ControllerQuestionReply
|
|
357
|
+
| IReq_ControllerElicitationReply
|
|
354
358
|
| IReq_ControllerSessionRename
|
|
355
359
|
| IReq_ControllerSessionArchive
|
|
356
360
|
| IReq_ControllerSessionGroupsGet
|
|
@@ -46,8 +46,9 @@ export interface IControllerSessionFeedRow {
|
|
|
46
46
|
updatedAt: number;
|
|
47
47
|
open: TControllerSessionFeedOpen;
|
|
48
48
|
/**
|
|
49
|
-
* On a `needs_input` row AGL holds no question or
|
|
50
|
-
* cannot answer, for `reason`. A `needs_input` row without it holds a request the owner answers in
|
|
49
|
+
* On a `needs_input` row AGL holds no question, permission or MCP elicitation for: the harness waits in its own
|
|
50
|
+
* client, which AGL cannot answer, for `reason`. A `needs_input` row without it holds a request the owner answers in
|
|
51
|
+
* AGL.
|
|
51
52
|
*/
|
|
52
53
|
nativeWait?: IControllerNativeWait;
|
|
53
54
|
/** On a `completed` row: its newest turn was interrupted. */
|
|
@@ -214,7 +214,7 @@ export class ControllerBrowserPresentation {
|
|
|
214
214
|
const paint = this.paint;
|
|
215
215
|
if (paint && paint.response.paintId === eventArg.paintId) {
|
|
216
216
|
void this.openVideoRoute(paint, eventArg.routeId).catch((errorArg) => {
|
|
217
|
-
if (this.paint
|
|
217
|
+
if (this.isCurrentPaint(paint)) this.options.onError('Show the browser view\'s video', errorArg);
|
|
218
218
|
});
|
|
219
219
|
return;
|
|
220
220
|
}
|
|
@@ -330,7 +330,7 @@ export class ControllerBrowserPresentation {
|
|
|
330
330
|
for (const pending of this.pendingVideoRoutes.splice(0)) {
|
|
331
331
|
if (pending.paintId === opened.paintId) {
|
|
332
332
|
void this.openVideoRoute(paint, pending.routeId).catch((errorArg) => {
|
|
333
|
-
if (this.paint
|
|
333
|
+
if (this.isCurrentPaint(paint)) this.options.onError('Show the browser view\'s video', errorArg);
|
|
334
334
|
});
|
|
335
335
|
}
|
|
336
336
|
}
|
|
@@ -384,7 +384,15 @@ export class ControllerBrowserPresentation {
|
|
|
384
384
|
if (failure !== undefined) this.fallBackToVideo({ kind: 'viewer-cannot-render', failure });
|
|
385
385
|
}
|
|
386
386
|
|
|
387
|
+
/** Whether `paintArg` is the run this view presents: a stopping, replaced or closed run is not. */
|
|
388
|
+
private isCurrentPaint(paintArg: IPaintRun): boolean {
|
|
389
|
+
return this.paint === paintArg && !this.closed;
|
|
390
|
+
}
|
|
391
|
+
|
|
387
392
|
private async stopPaint(paintArg: IPaintRun): Promise<void> {
|
|
393
|
+
// The run stops being current before its abort listeners run: they fire synchronously, and
|
|
394
|
+
// what they end belongs to the stopping run, never to the view.
|
|
395
|
+
if (this.paint === paintArg) this.paint = undefined;
|
|
388
396
|
paintArg.abortController.abort(new Error('The Paint stream closed.'));
|
|
389
397
|
paintArg.removeSessionEnd();
|
|
390
398
|
this.closeVideoRoutes(paintArg);
|
|
@@ -392,7 +400,6 @@ export class ControllerBrowserPresentation {
|
|
|
392
400
|
// Closes the controller's Paint stream exactly once and stops the renderer.
|
|
393
401
|
await paintArg.presenter.close();
|
|
394
402
|
} finally {
|
|
395
|
-
if (this.paint === paintArg) this.paint = undefined;
|
|
396
403
|
this.clearRenderer(paintArg.renderer);
|
|
397
404
|
}
|
|
398
405
|
}
|
|
@@ -427,10 +434,11 @@ export class ControllerBrowserPresentation {
|
|
|
427
434
|
// The host ended the route on purpose (a source rebind or a closed subscription): the worker
|
|
428
435
|
// keeps running and the next route mounts on it.
|
|
429
436
|
onEnded: () => { paintArg.routes.delete(mount); },
|
|
430
|
-
// A broken route closes only its own decoders; the renderer keeps running.
|
|
437
|
+
// A broken route closes only its own decoders; the renderer keeps running. A route of a
|
|
438
|
+
// stopping, replaced or closed run is not this view's fault.
|
|
431
439
|
onFailure: (errorArg) => {
|
|
432
440
|
paintArg.routes.delete(mount);
|
|
433
|
-
this.options.onError('Show the browser view\'s video', errorArg);
|
|
441
|
+
if (this.isCurrentPaint(paintArg)) this.options.onError('Show the browser view\'s video', errorArg);
|
|
434
442
|
},
|
|
435
443
|
});
|
|
436
444
|
paintArg.routes.add(mount);
|
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
import * as plugins from './plugins.js';
|
|
2
|
+
import type * as interfaces from '../ts_interfaces/index.js';
|
|
3
|
+
|
|
4
|
+
type TElicitationCard = plugins.deesCatalog.IHarnessElicitationRequest;
|
|
5
|
+
type TElicitationRefusals = readonly plugins.deesCatalog.IHarnessElicitationRefusal[];
|
|
6
|
+
|
|
7
|
+
/** A pending request, the card the chat shows for it, and the controller's refusal that stands on it. */
|
|
8
|
+
interface IElicitationCardEntry {
|
|
9
|
+
request: interfaces.TControllerElicitation;
|
|
10
|
+
/** The request as the controller sent it, to tell a changed request from the same one read again. */
|
|
11
|
+
signature: string;
|
|
12
|
+
refusals?: TElicitationRefusals;
|
|
13
|
+
card: TElicitationCard;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
/** An MCP elicitation as its card: the same union on `mode`, under the card id `idArg`. */
|
|
17
|
+
export const elicitationCard = (
|
|
18
|
+
idArg: string,
|
|
19
|
+
requestArg: interfaces.TControllerElicitation,
|
|
20
|
+
refusalsArg?: TElicitationRefusals,
|
|
21
|
+
): TElicitationCard => {
|
|
22
|
+
const shared = {
|
|
23
|
+
id: idArg,
|
|
24
|
+
serverName: requestArg.serverName,
|
|
25
|
+
message: requestArg.message,
|
|
26
|
+
createdAt: requestArg.createdAt,
|
|
27
|
+
...(refusalsArg ? { refusals: refusalsArg } : {}),
|
|
28
|
+
};
|
|
29
|
+
switch (requestArg.mode) {
|
|
30
|
+
case 'form': return { ...shared, mode: 'form', fields: requestArg.schema.fields };
|
|
31
|
+
case 'url': return { ...shared, mode: 'url', url: requestArg.url };
|
|
32
|
+
case 'unsupported': return { ...shared, mode: 'unsupported', reason: requestArg.reason };
|
|
33
|
+
}
|
|
34
|
+
};
|
|
35
|
+
|
|
36
|
+
/**
|
|
37
|
+
* The owner's answer from a card's `harness-elicitation-response` as the controller takes it; `undefined` for an
|
|
38
|
+
* action the card does not send. Only an accept carries content, and only the reply request carries the reply: the
|
|
39
|
+
* caller sends it and keeps nothing of it.
|
|
40
|
+
*/
|
|
41
|
+
export const elicitationReply = (
|
|
42
|
+
detailArg: plugins.deesCatalog.IHarnessElicitationResponseDetail | undefined,
|
|
43
|
+
): interfaces.TControllerElicitationReply | undefined => {
|
|
44
|
+
switch (detailArg?.action) {
|
|
45
|
+
case 'accept': return detailArg.content === undefined ? { action: 'accept' } : { action: 'accept', content: detailArg.content };
|
|
46
|
+
case 'decline': return { action: 'decline' };
|
|
47
|
+
case 'cancel': return { action: 'cancel' };
|
|
48
|
+
default: return undefined;
|
|
49
|
+
}
|
|
50
|
+
};
|
|
51
|
+
|
|
52
|
+
/**
|
|
53
|
+
* The MCP elicitation cards of the session on screen. A card keeps its object while its request and the refusal on it
|
|
54
|
+
* stay, and the list its array while every card does, so a render or another read of the session changes nothing the
|
|
55
|
+
* card compares. A refusal of the controller is a new array each time, even one that reads as the last (the controller
|
|
56
|
+
* refused a new answer the same way), and the same array while it stands: that is how the card tells a refused new
|
|
57
|
+
* answer, which it takes again, from a render. A request that leaves the list takes its refusal along. What the owner
|
|
58
|
+
* enters stays in the card; nothing here holds it.
|
|
59
|
+
*/
|
|
60
|
+
export class ElicitationCards {
|
|
61
|
+
private entries = new Map<string, IElicitationCardEntry>();
|
|
62
|
+
private list: TElicitationCard[] = [];
|
|
63
|
+
|
|
64
|
+
/** `keyOfArg` names a card by its request id, unique among the requests of one session. */
|
|
65
|
+
constructor(private readonly keyOfArg: (idArg: interfaces.IControllerRuntimeId) => string) {}
|
|
66
|
+
|
|
67
|
+
/** The cards of the controller's pending requests, in their order: the same array while none of them changed. */
|
|
68
|
+
public cards(pendingArg: readonly interfaces.TControllerElicitation[]): TElicitationCard[] {
|
|
69
|
+
const entries = new Map<string, IElicitationCardEntry>();
|
|
70
|
+
for (const request of pendingArg) {
|
|
71
|
+
const key = this.keyOfArg(request.id);
|
|
72
|
+
const signature = JSON.stringify(request);
|
|
73
|
+
const previous = this.entries.get(key);
|
|
74
|
+
entries.set(key, previous?.signature === signature
|
|
75
|
+
? previous
|
|
76
|
+
// Another request under the same id is another question: the refusal of the last one does not stand on it.
|
|
77
|
+
: { request, signature, card: elicitationCard(key, request) });
|
|
78
|
+
}
|
|
79
|
+
this.entries = entries;
|
|
80
|
+
const cards = [...entries.values()].map((entryArg) => entryArg.card);
|
|
81
|
+
if (cards.length !== this.list.length || cards.some((cardArg, indexArg) => cardArg !== this.list[indexArg])) this.list = cards;
|
|
82
|
+
return this.list;
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
/** The pending request a card answers, as the last `cards` read it. */
|
|
86
|
+
public request(cardIdArg: string): interfaces.TControllerElicitation | undefined {
|
|
87
|
+
return this.entries.get(cardIdArg)?.request;
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
/**
|
|
91
|
+
* The controller refused the answer to a card, or it could not be sent: the card shows why under a new refusal and
|
|
92
|
+
* takes an answer again. A card no longer pending has nothing to show it on.
|
|
93
|
+
*/
|
|
94
|
+
public refuse(cardIdArg: string, reasonArg: string): void {
|
|
95
|
+
const entry = this.entries.get(cardIdArg);
|
|
96
|
+
if (!entry) return;
|
|
97
|
+
const refusals: TElicitationRefusals = [{ reason: reasonArg }];
|
|
98
|
+
this.entries.set(cardIdArg, { ...entry, refusals, card: elicitationCard(cardIdArg, entry.request, refusals) });
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
/** Forgets every card, for another session or connection. */
|
|
102
|
+
public clear(): void {
|
|
103
|
+
this.entries = new Map();
|
|
104
|
+
this.list = [];
|
|
105
|
+
}
|
|
106
|
+
}
|
|
@@ -3,6 +3,7 @@ import * as interfaces from '../ts_interfaces/index.js';
|
|
|
3
3
|
import type { ISessionChatHandlers, ISessionChatView } from './functions.sessionchat.js';
|
|
4
4
|
import { sessionIntelligenceAvailabilityAction } from './functions.sessionchat.js';
|
|
5
5
|
import { errorText, type IFleetWorkerSender } from './elements.fleetworker.js';
|
|
6
|
+
import { ElicitationCards, elicitationReply } from './classes.elicitationcards.js';
|
|
6
7
|
|
|
7
8
|
/** The element a session's state belongs to: it renders the state and hears the settings remedy. */
|
|
8
9
|
export interface INativeSessionStateHost {
|
|
@@ -61,6 +62,8 @@ export class NativeSessionState {
|
|
|
61
62
|
private intelligenceAction: plugins.deesCatalog.IHarnessIntelligenceAvailabilityAction | undefined;
|
|
62
63
|
private permissionCards: plugins.deesCatalog.IHarnessPermissionRequest[] = [];
|
|
63
64
|
private questionCards: plugins.deesCatalog.IHarnessQuestionRequest[] = [];
|
|
65
|
+
private readonly elicitations = new ElicitationCards((idArg) => idArg.nativeId);
|
|
66
|
+
private elicitationCards: plugins.deesCatalog.IHarnessElicitationRequest[] = [];
|
|
64
67
|
private readonly answeredPermissions = new Map<string, plugins.deesCatalog.IHarnessPermissionRequest>();
|
|
65
68
|
private readonly answeredQuestions = new Map<string, plugins.deesCatalog.IHarnessQuestionRequest>();
|
|
66
69
|
private readonly questionBatches = new Map<string, Map<number, string[]>>();
|
|
@@ -118,6 +121,8 @@ export class NativeSessionState {
|
|
|
118
121
|
this.questionBatches.clear();
|
|
119
122
|
this.permissionCards = [];
|
|
120
123
|
this.questionCards = [];
|
|
124
|
+
this.elicitations.clear();
|
|
125
|
+
this.elicitationCards = [];
|
|
121
126
|
}
|
|
122
127
|
|
|
123
128
|
/** Reads the session again; a read under way reads once more after it. */
|
|
@@ -205,13 +210,14 @@ export class NativeSessionState {
|
|
|
205
210
|
: ''),
|
|
206
211
|
permissions: this.permissionCards,
|
|
207
212
|
questions: this.questionCards,
|
|
213
|
+
elicitations: this.elicitationCards,
|
|
208
214
|
};
|
|
209
215
|
}
|
|
210
216
|
|
|
211
217
|
/** The chat events of the session state. */
|
|
212
218
|
public readonly handlers: Pick<
|
|
213
219
|
ISessionChatHandlers,
|
|
214
|
-
'scratchpadSave' | 'intelligenceAsk' | 'intelligenceAvailabilityAction' | 'permissionResponse' | 'questionResponse'
|
|
220
|
+
'scratchpadSave' | 'intelligenceAsk' | 'intelligenceAvailabilityAction' | 'permissionResponse' | 'questionResponse' | 'elicitationResponse'
|
|
215
221
|
> = {
|
|
216
222
|
scratchpadSave: (eventArg: CustomEvent<plugins.deesCatalog.IHarnessScratchpadSaveDetail>) => {
|
|
217
223
|
const detail = eventArg.detail;
|
|
@@ -269,6 +275,12 @@ export class NativeSessionState {
|
|
|
269
275
|
return;
|
|
270
276
|
}
|
|
271
277
|
},
|
|
278
|
+
elicitationResponse: (eventArg: CustomEvent<plugins.deesCatalog.IHarnessElicitationResponseDetail>) => {
|
|
279
|
+
const cardId = eventArg.detail?.requestId;
|
|
280
|
+
if (typeof cardId !== 'string') return;
|
|
281
|
+
const request = this.elicitations.request(cardId), reply = elicitationReply(eventArg.detail);
|
|
282
|
+
if (request && reply) void this.answerElicitation(cardId, request.id, reply);
|
|
283
|
+
},
|
|
272
284
|
};
|
|
273
285
|
|
|
274
286
|
private async read(generationArg: number): Promise<void> {
|
|
@@ -369,6 +381,30 @@ export class NativeSessionState {
|
|
|
369
381
|
if (generation === this.generation) void this.refresh();
|
|
370
382
|
}
|
|
371
383
|
|
|
384
|
+
/**
|
|
385
|
+
* Sends the owner's answer to an MCP elicitation and reads the session again. A refusal, or an answer that did not
|
|
386
|
+
* reach the controller, shows on the card, which takes an answer again; the answer itself is kept nowhere.
|
|
387
|
+
*/
|
|
388
|
+
private async answerElicitation(
|
|
389
|
+
cardIdArg: string,
|
|
390
|
+
requestIdArg: interfaces.IControllerRuntimeId,
|
|
391
|
+
replyArg: interfaces.TControllerElicitationReply,
|
|
392
|
+
): Promise<void> {
|
|
393
|
+
const { ref, sender, generation } = this;
|
|
394
|
+
if (!ref || !sender) return;
|
|
395
|
+
try {
|
|
396
|
+
await sender.fire<interfaces.IReq_ControllerNativeSessionElicitationReply>(
|
|
397
|
+
'controller.nativesession.elicitation.reply',
|
|
398
|
+
{ session: ref, requestId: requestIdArg, reply: replyArg },
|
|
399
|
+
);
|
|
400
|
+
} catch (errorArg) {
|
|
401
|
+
if (generation !== this.generation) return;
|
|
402
|
+
this.elicitations.refuse(cardIdArg, errorText(errorArg));
|
|
403
|
+
this.rebuildCards();
|
|
404
|
+
}
|
|
405
|
+
if (generation === this.generation) void this.refresh();
|
|
406
|
+
}
|
|
407
|
+
|
|
372
408
|
/** The request cards: pending ones as asked, or as answered while the reply is on its way. */
|
|
373
409
|
private rebuildCards(): void {
|
|
374
410
|
const response = this.response;
|
|
@@ -394,6 +430,7 @@ export class NativeSessionState {
|
|
|
394
430
|
}
|
|
395
431
|
for (const id of this.answeredQuestions.keys()) if (!pendingQuestions.has(id)) this.answeredQuestions.delete(id);
|
|
396
432
|
this.questionCards = cards;
|
|
433
|
+
this.elicitationCards = this.elicitations.cards(response?.elicitations ?? []);
|
|
397
434
|
this.host.requestUpdate();
|
|
398
435
|
}
|
|
399
436
|
|