agl 43.8.0 → 43.10.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 +28 -0
- package/dist_serve/bundle.js +1157 -1122
- package/dist_serve/bundle.js.map +2 -2
- package/dist_ts/00_commitinfo_data.js +2 -2
- package/dist_ts/aglapi/aglapisurface.document.js +826 -8
- package/dist_ts/aglapi/interfaces.d.ts +8 -0
- package/dist_ts/aglapi/interfaces.js +3 -1
- package/dist_ts/classes.accountsactions.d.ts +3 -1
- package/dist_ts/classes.accountsactions.js +17 -1
- package/dist_ts/classes.controller.d.ts +1 -1
- package/dist_ts/classes.controller.js +21 -7
- package/dist_ts/classes.inferencegateway.js +7 -5
- package/dist_ts/classes.inferenceplacement.d.ts +1 -1
- package/dist_ts/classes.inferencerouter.d.ts +20 -3
- package/dist_ts/classes.inferencerouter.js +37 -10
- package/dist_ts/classes.inferenceservice.js +2 -2
- package/dist_ts/classes.mcpclient.js +3 -3
- package/dist_ts/classes.mcpcontrollerhost.js +3 -2
- package/dist_ts/classes.mcptools.d.ts +1 -1
- package/dist_ts/classes.mcptools.js +2 -1
- package/dist_ts/classes.ticketnotifier.d.ts +2 -2
- package/dist_ts/classes.ticketnotifier.js +6 -4
- package/dist_ts/classes.ticketstore.d.ts +36 -8
- package/dist_ts/classes.ticketstore.js +131 -29
- package/dist_ts/classes.workercallers.d.ts +35 -1
- package/dist_ts/classes.workercallers.js +139 -28
- package/dist_ts/fleet/classes.boardpump.d.ts +1 -1
- package/dist_ts/fleet/classes.boardpump.js +4 -2
- package/dist_ts/fleet/classes.ticketeffects.d.ts +11 -0
- package/dist_ts/fleet/classes.ticketeffects.js +28 -1
- package/dist_ts/fleet/classes.workers.d.ts +18 -1
- package/dist_ts/fleet/classes.workers.js +49 -8
- package/dist_ts/fleet/functions.workervalidation.js +7 -4
- package/dist_ts/functions.deviceapi.js +3 -1
- package/dist_ts/functions.fleetworkercli.d.ts +3 -1
- package/dist_ts/functions.fleetworkercli.js +6 -2
- package/dist_ts/functions.inferencecli.js +4 -1
- package/dist_ts/functions.mcpfleetworkertools.js +3 -3
- package/dist_ts/functions.mcptickettools.d.ts +60 -0
- package/dist_ts/functions.mcptickettools.js +4 -3
- package/dist_ts/functions.proxycapacity.d.ts +2 -1
- package/dist_ts/functions.proxycapacity.js +6 -3
- package/dist_ts/functions.proxycapacitycli.js +2 -2
- package/dist_ts/functions.ticketcli.d.ts +4 -2
- package/dist_ts/functions.ticketcli.js +70 -4
- package/dist_ts/functions.ticketlisting.d.ts +38 -0
- package/dist_ts/functions.ticketlisting.js +211 -0
- package/dist_ts/functions.ticketvalidation.d.ts +62 -0
- package/dist_ts/functions.ticketvalidation.js +41 -3
- package/dist_ts/functions.workerprocessproof.d.ts +6 -0
- package/dist_ts/functions.workerprocessproof.js +8 -3
- package/dist_ts/interfaces.auth.d.ts +1 -1
- package/dist_ts/interfaces.auth.js +2 -1
- package/dist_ts/interfaces.flexipc.d.ts +3 -1
- package/dist_ts/interfaces.flexipc.js +1 -1
- 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 +7 -0
- package/dist_ts_authswitch/authority-overview.js +10 -6
- package/dist_ts_authswitch/authority-placement.d.ts +5 -2
- package/dist_ts_authswitch/authority-placement.js +6 -3
- package/dist_ts_authswitch/classes.authoritybroker.d.ts +6 -0
- package/dist_ts_authswitch/classes.authoritybroker.js +26 -1
- package/dist_ts_authswitch/classes.authoritycli.d.ts +1 -0
- package/dist_ts_authswitch/classes.authoritycli.js +50 -4
- package/dist_ts_authswitch/classes.authorityclient.d.ts +3 -1
- package/dist_ts_authswitch/classes.authorityclient.js +9 -4
- package/dist_ts_authswitch/classes.authoritydaemon.js +7 -1
- package/dist_ts_authswitch/classes.authoritydatabase.js +5 -1
- package/dist_ts_authswitch/classes.authoritymodels.d.ts +7 -0
- package/dist_ts_authswitch/classes.authoritymodels.js +13 -6
- package/dist_ts_interfaces/fleetworkers.d.ts +26 -1
- package/dist_ts_interfaces/fleetworkers.js +1 -1
- package/dist_ts_interfaces/interfaces.d.ts +4 -2
- package/dist_ts_interfaces/interfaces.js +1 -1
- package/dist_ts_interfaces/mcprequests.d.ts +1 -1
- package/dist_ts_interfaces/proxycapacity.d.ts +1 -1
- package/dist_ts_interfaces/requests.accounts.d.ts +19 -0
- package/dist_ts_interfaces/requests.accounts.js +1 -1
- package/dist_ts_interfaces/requests.d.ts +2 -2
- package/dist_ts_interfaces/requests.fleetworkers.d.ts +3 -1
- package/dist_ts_interfaces/requests.js +1 -1
- package/dist_ts_interfaces/requests.tickets.d.ts +31 -3
- package/dist_ts_interfaces/requests.tickets.js +2 -2
- package/dist_ts_interfaces/tickets.d.ts +174 -2
- package/dist_ts_interfaces/tickets.js +20 -2
- package/dist_ts_migration/v41_ticketclosedcolumn.js +7 -3
- package/docs/authswitch.md +22 -0
- package/package.json +2 -2
- package/readme.md +85 -6
- package/ts/00_commitinfo_data.ts +1 -1
- package/ts/aglapi/aglapisurface.document.ts +825 -7
- package/ts/aglapi/interfaces.ts +2 -0
- package/ts/classes.accountsactions.ts +25 -0
- package/ts/classes.controller.ts +18 -3
- package/ts/classes.inferencegateway.ts +6 -4
- package/ts/classes.inferenceplacement.ts +1 -1
- package/ts/classes.inferencerouter.ts +49 -10
- package/ts/classes.inferenceservice.ts +1 -1
- package/ts/classes.mcpclient.ts +2 -2
- package/ts/classes.mcpcontrollerhost.ts +2 -1
- package/ts/classes.mcptools.ts +1 -0
- package/ts/classes.ticketnotifier.ts +5 -3
- package/ts/classes.ticketstore.ts +124 -27
- package/ts/classes.workercallers.ts +165 -28
- package/ts/fleet/classes.boardpump.ts +3 -2
- package/ts/fleet/classes.ticketeffects.ts +25 -0
- package/ts/fleet/classes.workers.ts +47 -7
- package/ts/fleet/functions.workervalidation.ts +6 -3
- package/ts/functions.deviceapi.ts +2 -0
- package/ts/functions.fleetworkercli.ts +5 -1
- package/ts/functions.inferencecli.ts +2 -0
- package/ts/functions.mcpfleetworkertools.ts +2 -2
- package/ts/functions.mcptickettools.ts +3 -2
- package/ts/functions.proxycapacity.ts +5 -2
- package/ts/functions.proxycapacitycli.ts +1 -1
- package/ts/functions.ticketcli.ts +70 -5
- package/ts/functions.ticketlisting.ts +214 -0
- package/ts/functions.ticketvalidation.ts +41 -2
- package/ts/functions.workerprocessproof.ts +10 -2
- package/ts/interfaces.auth.ts +1 -0
- package/ts/interfaces.flexipc.ts +3 -1
- package/ts_authswitch/authority-contract.ts +20 -0
- package/ts_authswitch/authority-overview.ts +17 -6
- package/ts_authswitch/authority-placement.ts +7 -3
- package/ts_authswitch/classes.authoritybroker.ts +24 -0
- package/ts_authswitch/classes.authoritycli.ts +58 -4
- package/ts_authswitch/classes.authorityclient.ts +11 -4
- package/ts_authswitch/classes.authoritydaemon.ts +8 -1
- package/ts_authswitch/classes.authoritydatabase.ts +3 -0
- package/ts_authswitch/classes.authoritymodels.ts +12 -4
- package/ts_interfaces/fleetworkers.ts +26 -1
- package/ts_interfaces/interfaces.ts +4 -2
- package/ts_interfaces/proxycapacity.ts +1 -1
- package/ts_interfaces/requests.accounts.ts +17 -0
- package/ts_interfaces/requests.fleetworkers.ts +3 -1
- package/ts_interfaces/requests.tickets.ts +32 -2
- package/ts_interfaces/requests.ts +2 -0
- package/ts_interfaces/tickets.ts +136 -3
- package/ts_migration/v41_ticketclosedcolumn.ts +6 -2
- package/ts_web/00_commitinfo_data.ts +1 -1
- package/ts_web/accounts.templates.ts +12 -2
- package/ts_web/classes.accountsreadmodel.ts +42 -6
- package/ts_web/elements.accounts.ts +45 -3
- package/ts_web/elements.harnesscontrollerapp.ts +6 -1
- package/ts_web/elements.inbox.ts +50 -9
package/ts/aglapi/interfaces.ts
CHANGED
|
@@ -111,6 +111,8 @@ export const aglApiMethods = {
|
|
|
111
111
|
'agl.mcp.configuration.operation.recover': { use: 'excluded', exclusion: 'person', reason: ownerToken },
|
|
112
112
|
'agl.mcp.configuration.operation.abandon': { use: 'excluded', exclusion: 'person', reason: ownerToken },
|
|
113
113
|
'agl.mcp.ticket.list': { use: 'read', roles: tickets },
|
|
114
|
+
'agl.mcp.ticket.page': { use: 'read', roles: tickets },
|
|
115
|
+
'agl.mcp.ticket.overview': { use: 'read', roles: tickets },
|
|
114
116
|
'agl.mcp.ticket.board': { use: 'read', roles: tickets },
|
|
115
117
|
'agl.mcp.ticket.search': { use: 'read', roles: tickets },
|
|
116
118
|
'agl.mcp.ticket.get': { use: 'read', roles: tickets },
|
|
@@ -30,6 +30,7 @@ import type {
|
|
|
30
30
|
IReq_ControllerAccountsClaudeCode,
|
|
31
31
|
IReq_ControllerAccountsRenewal,
|
|
32
32
|
IReq_ControllerAccountsPriority,
|
|
33
|
+
IReq_ControllerAccountsPause,
|
|
33
34
|
IReq_ControllerAccountsUsageGet,
|
|
34
35
|
IReq_ControllerAccountsUsageRecheck,
|
|
35
36
|
TControllerAccountBinding,
|
|
@@ -269,6 +270,18 @@ export class AccountsActions {
|
|
|
269
270
|
}));
|
|
270
271
|
},
|
|
271
272
|
);
|
|
273
|
+
routerArg.addHandler<IReq_ControllerAccountsPause>(
|
|
274
|
+
'controller.accounts.pause',
|
|
275
|
+
async (requestArg, toolsArg) => {
|
|
276
|
+
const request = assertRequestShape(requestArg, {
|
|
277
|
+
accountId: 'string', expectedRevision: 'number', paused: 'boolean',
|
|
278
|
+
}) as IReq_ControllerAccountsPause['request'];
|
|
279
|
+
// The audit names the action and the peer; the moment is the account's, which the accounts service journals.
|
|
280
|
+
return hostArg.runAudited(toolsArg?.localData, 'accounts.pause', async (signalArg) => ({
|
|
281
|
+
answer: await this.setPause(request, signalArg),
|
|
282
|
+
}));
|
|
283
|
+
},
|
|
284
|
+
);
|
|
272
285
|
routerArg.addHandler<IReq_ControllerAccountsRemove>(
|
|
273
286
|
'controller.accounts.remove',
|
|
274
287
|
async (requestArg, toolsArg) => {
|
|
@@ -584,6 +597,18 @@ export class AccountsActions {
|
|
|
584
597
|
return answer;
|
|
585
598
|
}
|
|
586
599
|
|
|
600
|
+
/** Pauses an account, or resumes it, and answers once the projection shows it (AGL-1933). */
|
|
601
|
+
public async setPause(
|
|
602
|
+
requestArg: IReq_ControllerAccountsPause['request'],
|
|
603
|
+
signalArg: AbortSignal,
|
|
604
|
+
): Promise<TControllerAccountsAnswer<plugins.authswitchAuthority.IAuthSwitchAccount>> {
|
|
605
|
+
const answer = await this.answer((clientArg) => clientArg.setAccountPause(
|
|
606
|
+
requestArg.accountId, requestArg.expectedRevision, requestArg.paused, signalArg,
|
|
607
|
+
));
|
|
608
|
+
if (answer.state === 'done') await this.waitForAccountRevision(answer.value, signalArg);
|
|
609
|
+
return answer;
|
|
610
|
+
}
|
|
611
|
+
|
|
587
612
|
/** Waits until the controller's projection shows the account at `accountArg`'s revision or later. */
|
|
588
613
|
private async waitForAccountRevision(
|
|
589
614
|
accountArg: plugins.authswitchAuthority.IAuthSwitchAccount,
|
package/ts/classes.controller.ts
CHANGED
|
@@ -3427,6 +3427,8 @@ export class OpenCodeController {
|
|
|
3427
3427
|
claudeReleases: (releaseArg) => this.observeClaudeRelease(releaseArg, 'fleet'),
|
|
3428
3428
|
// No controller event names a native thread; the Inbox reads the fleet connection's requests again.
|
|
3429
3429
|
onNativeCodexAttention: () => this.inbox?.nativeAttentionChanged('codex'),
|
|
3430
|
+
// The views show a worker whose MCP calls run without its identity, as this controller's worker callers derive it (AGL-1888).
|
|
3431
|
+
callerIdentity: (workerIdArg) => this.workerCallers?.workerCallerIdentity(workerIdArg),
|
|
3430
3432
|
...(this.fleetWorkerLaunches ? { callers: this.fleetWorkerLaunches } : {}) });
|
|
3431
3433
|
// The Driver view's direct reports, an open fleet worker and the session feed follow worker changes and newly observed statuses.
|
|
3432
3434
|
this.fleetWorkers.watchViews(() => {
|
|
@@ -11578,7 +11580,9 @@ export class OpenCodeController {
|
|
|
11578
11580
|
// its parent runs, from the same fleet's inventory and registry (AGL-1888).
|
|
11579
11581
|
identifyClaudeProcess: async (request) => this.fleetWorkers
|
|
11580
11582
|
? await this.fleetWorkers.identifyCallerProcess(request)
|
|
11581
|
-
: { state: 'refused', check: 'inventory', reason: 'the fleet is not running yet', forGood: false }
|
|
11583
|
+
: { state: 'refused', check: 'inventory', reason: 'the fleet is not running yet', forGood: false },
|
|
11584
|
+
// A worker shown calling without its identity, or verified again: the fleet's views follow, and its ticket is noticed once per reason.
|
|
11585
|
+
workerIdentityChanged: (workerIdArg, identityArg) => { void this.fleetWorkers?.callerIdentityChanged(workerIdArg, identityArg); } });
|
|
11582
11586
|
this.workerCallers = workerCallers;
|
|
11583
11587
|
const mcpControllerHost = new ControllerMcpHost({
|
|
11584
11588
|
controllerPort: runtimeConfig.controllerPort,
|
|
@@ -16846,6 +16850,7 @@ export class OpenCodeController {
|
|
|
16846
16850
|
connection.status === 'active'
|
|
16847
16851
|
|| connection.status === 'reauthRequired'
|
|
16848
16852
|
|| connection.status === 'inHostCodex'
|
|
16853
|
+
|| connection.status === 'paused'
|
|
16849
16854
|
))
|
|
16850
16855
|
.map((connection) => this.toPublicProviderConnection(connection)),
|
|
16851
16856
|
runtimeAvailable: response.runtimeAvailable,
|
|
@@ -21696,7 +21701,7 @@ export class OpenCodeController {
|
|
|
21696
21701
|
/**
|
|
21697
21702
|
* The usable Flex accounts in the order AGL's account placement takes a new conversation now
|
|
21698
21703
|
* (`authSwitchPlacementOrder`, a priority account first), judged on each account's usage reading as
|
|
21699
|
-
* the inference proxy judges it: an account at its limit or reserve, lapsed, or without a reading it
|
|
21704
|
+
* the inference proxy judges it: an account at its limit or reserve, lapsed, paused by its owner, or without a reading it
|
|
21700
21705
|
* can be judged on takes none. A conversation keeps its account for its life, so accounts rank by their score and
|
|
21701
21706
|
* headroom alone, with none counted as in flight. The Claude pool, which the proxy places inside,
|
|
21702
21707
|
* comes last.
|
|
@@ -21738,7 +21743,9 @@ export class OpenCodeController {
|
|
|
21738
21743
|
account.renewsAt,
|
|
21739
21744
|
now,
|
|
21740
21745
|
account.reserveLiftUntil,
|
|
21746
|
+
account.pausedAt,
|
|
21741
21747
|
);
|
|
21748
|
+
// Lapsed, or paused by its owner (AGL-1933): no new conversation goes to it.
|
|
21742
21749
|
if (placement.eligibility === 'never') return undefined;
|
|
21743
21750
|
return {
|
|
21744
21751
|
id: providerConnectionId,
|
|
@@ -22009,6 +22016,12 @@ export class OpenCodeController {
|
|
|
22009
22016
|
remedy: 'accountSettings',
|
|
22010
22017
|
};
|
|
22011
22018
|
}
|
|
22019
|
+
if (connection?.status === 'paused') {
|
|
22020
|
+
return {
|
|
22021
|
+
reason: `Session Intelligence uses ${label}, but its account is paused. Resume it in Settings → Accounts.`,
|
|
22022
|
+
remedy: 'accountSettings',
|
|
22023
|
+
};
|
|
22024
|
+
}
|
|
22012
22025
|
if (connection?.status === 'inHostCodex') {
|
|
22013
22026
|
return {
|
|
22014
22027
|
reason: `Session Intelligence uses ${label}, but its account runs this host's Codex. `
|
|
@@ -22257,7 +22270,8 @@ export class OpenCodeController {
|
|
|
22257
22270
|
: !login
|
|
22258
22271
|
? undefined
|
|
22259
22272
|
: login.health === 'ready' || login.health === 'refreshing' || login.health === 'retry_wait'
|
|
22260
|
-
|
|
22273
|
+
// Paused by its owner (AGL-1933): listed, and not to be chosen until it is resumed.
|
|
22274
|
+
? accountArg.pausedAt !== null ? 'paused' : 'active'
|
|
22261
22275
|
: 'reauthRequired';
|
|
22262
22276
|
if (status === undefined) return [];
|
|
22263
22277
|
return [{
|
|
@@ -26444,6 +26458,7 @@ export class OpenCodeController {
|
|
|
26444
26458
|
connectionArg.status !== 'active'
|
|
26445
26459
|
&& connectionArg.status !== 'reauthRequired'
|
|
26446
26460
|
&& connectionArg.status !== 'inHostCodex'
|
|
26461
|
+
&& connectionArg.status !== 'paused'
|
|
26447
26462
|
) {
|
|
26448
26463
|
throw new Error('The Flex provider connection is not publicly listable.');
|
|
26449
26464
|
}
|
|
@@ -381,12 +381,12 @@ const codexPlanType = (plansArg: readonly string[]): string | undefined => {
|
|
|
381
381
|
};
|
|
382
382
|
|
|
383
383
|
/**
|
|
384
|
-
* The session's account cannot serve this client's pool: it left the pool,
|
|
385
|
-
* leaves it out. The session moves to an account of the pool, as it does from an account at its limit.
|
|
384
|
+
* The session's account cannot serve this client's pool: it left the pool, its owner paused it (AGL-1933), or the
|
|
385
|
+
* client's account restriction leaves it out. The session moves to an account of the pool, as it does from an account at its limit.
|
|
386
386
|
*/
|
|
387
387
|
const sessionAccountOutsidePool = (errorArg: unknown): boolean => errorArg instanceof InferenceRoutingError
|
|
388
388
|
&& (errorArg.code === 'account_left_pool' || errorArg.code === 'account_outside_restriction'
|
|
389
|
-
|| errorArg.code === 'account_lapsed');
|
|
389
|
+
|| errorArg.code === 'account_lapsed' || errorArg.code === 'account_paused');
|
|
390
390
|
|
|
391
391
|
/**
|
|
392
392
|
* A Claude session's account takes no request for a reason of its own (`InferenceRoutingError.reason`): no usage reading,
|
|
@@ -398,7 +398,9 @@ const sessionAccountUnavailable = (errorArg: unknown, accountIdArg: string): boo
|
|
|
398
398
|
/** Why a session's own account refused its request, as the placement journal names it; see `TInferencePlacementReason`. */
|
|
399
399
|
const placementReason = (errorArg: InferenceRoutingError): TInferencePlacementReason =>
|
|
400
400
|
errorArg.reason !== undefined ? 'unavailable'
|
|
401
|
-
|
|
401
|
+
// A paused account left the pool for as long as it is paused; the journal has no reason of its own for it, so an
|
|
402
|
+
// AGL that reads the journal after a rollback knows every reason in it.
|
|
403
|
+
: errorArg.code === 'account_left_pool' || errorArg.code === 'account_paused' ? 'left_pool'
|
|
402
404
|
: errorArg.code === 'account_outside_restriction' ? 'outside_restriction'
|
|
403
405
|
: errorArg.code === 'account_lapsed' ? 'lapsed' : errorArg.accountLimit ?? 'exhausted';
|
|
404
406
|
|
|
@@ -5,7 +5,7 @@ import { inferenceProviders, type TInferenceProvider } from './functions.proxyco
|
|
|
5
5
|
* Why a session was placed on its account. `new`: the session had no account. Every other reason moved a session off
|
|
6
6
|
* the account it had: `exhausted` (a window used up, or the provider refusing until a time it named), `reserved` (its
|
|
7
7
|
* usage threshold reached), `cooling` (resting after a provider 429 another request met), `provider_429` (the provider
|
|
8
|
-
* refused this request with a 429), `left_pool` (removed, signed out,
|
|
8
|
+
* refused this request with a 429), `left_pool` (removed, signed out, taken by a native tool, or paused by its owner), `outside_restriction`
|
|
9
9
|
* (the client's account restriction leaves it out), `lapsed` (its subscription ended), `unavailable` (an account that
|
|
10
10
|
* takes no request for a reason of its own: no usage reading, no model list, no access, no such model, or a payment
|
|
11
11
|
* problem) or `returned` (the session was on an API key, and a subscription of the pool could take its request again).
|
|
@@ -89,6 +89,12 @@ export interface IInferenceAccount {
|
|
|
89
89
|
* account of the pool without one, as long as it takes the request (`inferencePlacementOrder`).
|
|
90
90
|
*/
|
|
91
91
|
priorityUntil: string | null;
|
|
92
|
+
/**
|
|
93
|
+
* Since when the owner holds the account paused (`IAuthSwitchAccount.pausedAt`, AGL-1933); `null` while it is not. A
|
|
94
|
+
* paused account is in no pool: no new session goes to it, a session on it moves (`account_paused`), and a request
|
|
95
|
+
* that could reach only paused accounts is refused as `accounts_paused`.
|
|
96
|
+
*/
|
|
97
|
+
pausedAt: string | null;
|
|
92
98
|
/**
|
|
93
99
|
* An API key's monthly spend limit in micro-dollars (`IAuthSwitchAccount.spendLimitMicroUsd`); `null` without one,
|
|
94
100
|
* and for a sign-in. It decides only whether a key whose spend the proxy holds no reading of may take work: one with
|
|
@@ -756,6 +762,12 @@ export interface IInferenceAccountStatus {
|
|
|
756
762
|
* account ranks before every account without one. A proxy of an earlier AGL reports none.
|
|
757
763
|
*/
|
|
758
764
|
priorityUntil?: string | null;
|
|
765
|
+
/**
|
|
766
|
+
* Since when the owner holds the account paused (`IInferenceAccount.pausedAt`), or `null`: it takes no new session
|
|
767
|
+
* and has no placement rank, whatever `state` says of its usage; `stateText` says it is paused. A proxy of an earlier
|
|
768
|
+
* AGL reports none.
|
|
769
|
+
*/
|
|
770
|
+
pausedAt?: string | null;
|
|
759
771
|
/** The account's placement score in percent per hour (`IAuthSwitchPlacement.score`); `null` without a counted window. */
|
|
760
772
|
placementScore: number | null;
|
|
761
773
|
/**
|
|
@@ -988,7 +1000,7 @@ const emptySelection = (accountsArg: number, pinnedArg: boolean): ISelectionStat
|
|
|
988
1000
|
const accountPlacement = (readingArg: plugins.authswitchAuthority.IAuthSwitchUsageSnapshot['reading'],
|
|
989
1001
|
accountArg: IInferenceAccount, nowArg: number): plugins.authswitchPlacement.IAuthSwitchPlacement =>
|
|
990
1002
|
plugins.authswitchPlacement.authSwitchPlacement(readingArg, accountArg.maxUsagePercent, accountArg.lapsesAt,
|
|
991
|
-
accountArg.renewsAt, nowArg, accountArg.reserveLiftUntil);
|
|
1003
|
+
accountArg.renewsAt, nowArg, accountArg.reserveLiftUntil, accountArg.pausedAt);
|
|
992
1004
|
|
|
993
1005
|
/** An account of a pool as a new session is placed on it: its credential tier and its rank (`IAuthSwitchPlacementRank`). */
|
|
994
1006
|
interface IInferencePlacementEntry {
|
|
@@ -1056,12 +1068,13 @@ export class InferenceRouter {
|
|
|
1056
1068
|
/**
|
|
1057
1069
|
* The policy's accounts of its provider and credential tiers (`tiers`), and every eligible account's id of that pool:
|
|
1058
1070
|
* an account absent from both left the pool. An account whose lapse date passed is in neither -- it is never routed to
|
|
1059
|
-
* again -- and is named in `lapsed`.
|
|
1071
|
+
* again -- and is named in `lapsed`. An account its owner holds paused (AGL-1933) is in neither as well, for as long
|
|
1072
|
+
* as it is paused, and is named in `paused`. A pool that names its credential serves that kind alone: Flex's API-key pool
|
|
1060
1073
|
* never takes a Claude account. One that names none spans both, and a session placed on a key returns to a Claude
|
|
1061
1074
|
* account once one can take its request.
|
|
1062
1075
|
*/
|
|
1063
1076
|
private async pool(policyArg: IInferenceRoutingPolicy, signalArg: AbortSignal): Promise<{ accounts: IInferenceAccount[];
|
|
1064
|
-
eligible: Set<string>; lapsed: Set<string>; tiers: readonly TInferenceCredential[] }> {
|
|
1077
|
+
eligible: Set<string>; lapsed: Set<string>; paused: Set<string>; tiers: readonly TInferenceCredential[] }> {
|
|
1065
1078
|
const everyAccount = await this.options.accounts(signalArg);
|
|
1066
1079
|
this.apiKeyAccounts = new Set(everyAccount.filter((account) => account.credential === 'api_key')
|
|
1067
1080
|
.map((account) => account.id));
|
|
@@ -1074,7 +1087,9 @@ export class InferenceRouter {
|
|
|
1074
1087
|
&& !(policyArg.claudeCode && accountArg.credential === 'api_key' && !accountArg.claudeCode);
|
|
1075
1088
|
const lapsed = new Set(everyAccount.filter((account) => inPool(account)
|
|
1076
1089
|
&& plugins.authswitchPlacement.authSwitchAccountLifecycle(account.lapsesAt, now) === 'lapsed').map((account) => account.id));
|
|
1077
|
-
const
|
|
1090
|
+
const paused = new Set(everyAccount.filter((account) => inPool(account) && !lapsed.has(account.id)
|
|
1091
|
+
&& account.pausedAt !== null).map((account) => account.id));
|
|
1092
|
+
const allAccounts = everyAccount.filter((account) => inPool(account) && !lapsed.has(account.id) && !paused.has(account.id));
|
|
1078
1093
|
const accounts = allAccounts.filter((account) => !policyArg.accountIds || policyArg.accountIds.includes(account.id));
|
|
1079
1094
|
if (accounts.length > 64) throw new InferenceRoutingError(503, 'pool_too_large',
|
|
1080
1095
|
'Select at most 64 accounts for this gateway.');
|
|
@@ -1085,21 +1100,38 @@ export class InferenceRouter {
|
|
|
1085
1100
|
for (const id of this.cooldowns.keys()) if (!known.has(id)) this.cooldowns.delete(id);
|
|
1086
1101
|
for (const id of this.modelCooldowns.keys()) if (!known.has(id)) this.modelCooldowns.delete(id);
|
|
1087
1102
|
for (const id of this.noted.keys()) if (!known.has(id)) this.noted.delete(id);
|
|
1088
|
-
return { accounts, eligible: new Set(allAccounts.map((account) => account.id)), lapsed, tiers };
|
|
1103
|
+
return { accounts, eligible: new Set(allAccounts.map((account) => account.id)), lapsed, paused, tiers };
|
|
1089
1104
|
}
|
|
1090
1105
|
|
|
1091
1106
|
/**
|
|
1092
1107
|
* The pool for one request of a session served by `accountIdArg`, which it refuses when that account cannot serve
|
|
1093
1108
|
* the session any more: one no longer eligible at all -- removed, signed out, or taken by a native tool -- left the
|
|
1094
1109
|
* pool, and one the policy's account restriction leaves out is outside it, as the operator chose. Either way the
|
|
1095
|
-
* session moves to an account of the pool. So it does from an account that lapsed
|
|
1096
|
-
* the session waiting.
|
|
1110
|
+
* session moves to an account of the pool. So it does from an account that lapsed, and from one its owner paused
|
|
1111
|
+
* (`account_paused`). A plan the policy leaves out keeps the session waiting.
|
|
1112
|
+
*
|
|
1113
|
+
* A request that reaches no account only because its accounts are paused -- every account of the pool, or every one
|
|
1114
|
+
* the client's account restriction names, as Flex's chosen account is -- is refused as `accounts_paused`, which says
|
|
1115
|
+
* so and how to end it. Only a request is refused so: the model lists read the pool without it.
|
|
1097
1116
|
*/
|
|
1098
1117
|
private async sessionPool(policyArg: IInferenceRoutingPolicy, signalArg: AbortSignal,
|
|
1099
1118
|
accountIdArg: string | undefined): Promise<{ accounts: IInferenceAccount[]; eligible: Set<string>;
|
|
1100
1119
|
tiers: readonly TInferenceCredential[] }> {
|
|
1101
1120
|
const pool = await this.pool(policyArg, signalArg);
|
|
1121
|
+
if (!pool.accounts.length) {
|
|
1122
|
+
const paused = [...pool.paused].filter((idArg) => !policyArg.accountIds || policyArg.accountIds.includes(idArg));
|
|
1123
|
+
if (paused.length) {
|
|
1124
|
+
throw new InferenceRoutingError(503, 'accounts_paused', policyArg.accountIds
|
|
1125
|
+
? `${paused.length === 1 ? 'The account this client uses is' : 'The accounts this client uses are'} paused in AGL `
|
|
1126
|
+
+ 'Accounts, so AGL places nothing on ' + (paused.length === 1 ? 'it' : 'them') + '. Resume '
|
|
1127
|
+
+ (paused.length === 1 ? 'it' : 'one') + ' there, or choose another account.'
|
|
1128
|
+
: 'Every account of this pool is paused in AGL Accounts, so AGL places nothing on them. Resume one there.');
|
|
1129
|
+
}
|
|
1130
|
+
}
|
|
1102
1131
|
if (!accountIdArg) return pool;
|
|
1132
|
+
if (pool.paused.has(accountIdArg)) {
|
|
1133
|
+
throw new InferenceRoutingError(503, 'account_paused', 'The account serving this session is paused by its owner.');
|
|
1134
|
+
}
|
|
1103
1135
|
if (pool.lapsed.has(accountIdArg)) {
|
|
1104
1136
|
throw new InferenceRoutingError(503, 'account_lapsed', 'The account serving this session lapsed; its subscription ended.');
|
|
1105
1137
|
}
|
|
@@ -2034,7 +2066,7 @@ export class InferenceRouter {
|
|
|
2034
2066
|
public accountStatus(accountsArg: readonly IInferenceAccount[],
|
|
2035
2067
|
heldArg: (accountIdArg: string) => plugins.authswitchAuthority.IAuthSwitchUsageSnapshot | undefined): IInferenceAccountStatus[] {
|
|
2036
2068
|
const now = this.now();
|
|
2037
|
-
const
|
|
2069
|
+
const judge = (account: IInferenceAccount): IInferenceAccountStatus => {
|
|
2038
2070
|
const apiKey = account.credential === 'api_key';
|
|
2039
2071
|
// A key's usage is its month's spend, with the payment problem the account service holds on it.
|
|
2040
2072
|
const held = heldArg(account.id);
|
|
@@ -2048,6 +2080,7 @@ export class InferenceRouter {
|
|
|
2048
2080
|
lifecycle: placement.lifecycle, lapsesAt: account.lapsesAt,
|
|
2049
2081
|
renewal: plugins.authswitchRenewal.authSwitchRenewal(account.renewsAt, now),
|
|
2050
2082
|
priorityUntil: plugins.authswitchPriority.authSwitchPriorityUntil(account.priorityUntil, now),
|
|
2083
|
+
pausedAt: account.pausedAt,
|
|
2051
2084
|
placementScore: placement.score, placementRank: null,
|
|
2052
2085
|
lastResort: placement.eligibility === 'last_resort', claudeCode: account.claudeCode,
|
|
2053
2086
|
readingSource: held?.observation ? 'headers' as const : held?.reading ? 'poll' as const : null,
|
|
@@ -2083,14 +2116,20 @@ export class InferenceRouter {
|
|
|
2083
2116
|
: 'available (no usage reported)'}${this.modelRestText(account.id, held, now)}`,
|
|
2084
2117
|
plan: limits.plan || null, headroom: limits.limit?.headroom ?? null, crossing: limits.limit?.crossing ?? [],
|
|
2085
2118
|
resetAt: state === 'cooling' ? new Date(cooldown).toISOString() : limits.limit?.resetAt ?? null };
|
|
2119
|
+
};
|
|
2120
|
+
const statuses = accountsArg.map((account): IInferenceAccountStatus => {
|
|
2121
|
+
const judged = judge(account);
|
|
2122
|
+
// Paused by its owner (AGL-1933): it says so instead of what its usage would allow, and names no reset to wait for.
|
|
2123
|
+
return account.pausedAt === null ? judged : { ...judged, resetAt: null,
|
|
2124
|
+
stateText: `paused by the owner since ${account.pausedAt}; takes no new session until it is resumed` };
|
|
2086
2125
|
});
|
|
2087
2126
|
// Each provider's accounts that take a new session now, in the order placement takes them: a priority account first,
|
|
2088
|
-
// then the best credential tier.
|
|
2127
|
+
// then the best credential tier. A paused account takes none.
|
|
2089
2128
|
const order = inferencePlacementOrder((accountIdArg) => this.active.get(accountIdArg) ?? 0);
|
|
2090
2129
|
const tiers = inferenceCredentialTiers(undefined);
|
|
2091
2130
|
for (const provider of new Set(statuses.map((statusArg) => statusArg.provider))) {
|
|
2092
2131
|
statuses.filter((statusArg) => statusArg.provider === provider && statusArg.state === 'available'
|
|
2093
|
-
&& statusArg.lifecycle !== 'lapsed')
|
|
2132
|
+
&& statusArg.lifecycle !== 'lapsed' && !statusArg.pausedAt)
|
|
2094
2133
|
.map((statusArg) => ({ status: statusArg, tier: tiers.indexOf(statusArg.credential), rank: { id: statusArg.id,
|
|
2095
2134
|
priority: Boolean(statusArg.priorityUntil), score: statusArg.placementScore, lastResort: statusArg.lastResort,
|
|
2096
2135
|
headroom: statusArg.headroom ?? unknownHeadroom } }))
|
|
@@ -159,7 +159,7 @@ export class InferenceService {
|
|
|
159
159
|
const login = findAuthorityGatewayLogin(projection, account.id);
|
|
160
160
|
return pool ? [{ id: account.id, label: account.label, revision: String(account.revision), providerId: pool.provider,
|
|
161
161
|
credential: pool.credential, maxUsagePercent: account.maxUsagePercent, reserveLiftUntil: account.reserveLiftUntil, lapsesAt: account.lapsesAt,
|
|
162
|
-
renewsAt: account.renewsAt, priorityUntil: account.priorityUntil, spendLimitMicroUsd: account.spendLimitMicroUsd, claudeCode: account.claudeCode, loginId: typeof login === 'string' ? null : login.id }] : [];
|
|
162
|
+
renewsAt: account.renewsAt, priorityUntil: account.priorityUntil, pausedAt: account.pausedAt, spendLimitMicroUsd: account.spendLimitMicroUsd, claudeCode: account.claudeCode, loginId: typeof login === 'string' ? null : login.id }] : [];
|
|
163
163
|
});
|
|
164
164
|
}
|
|
165
165
|
|
package/ts/classes.mcpclient.ts
CHANGED
|
@@ -6,7 +6,7 @@ import type { TWorkerCallerEnrollment, IWorkerCallerEnrollmentResponse } from '.
|
|
|
6
6
|
import type { IControllerMcpWireCaller } from '../ts_interfaces/mcprequests.js';
|
|
7
7
|
import type { TFleetOperation, TFleetRequest, TFleetResult, IFleetOperation } from '../ts_interfaces/fleet.js';
|
|
8
8
|
import { assertFleetOperation, assertFleetWireRequest } from './fleet/functions.validation.js';
|
|
9
|
-
import { readTicketRevisionConflict, ticketErrorMessages, type TTicketClientErrorCode, type TTicketOperation, type TTicketRequest, type TTicketResponse } from '../ts_interfaces/tickets.js';
|
|
9
|
+
import { readTicketRevisionConflict, ticketErrorMessages, ticketPageErrorMessages, type TTicketClientErrorCode, type TTicketOperation, type TTicketRequest, type TTicketResponse } from '../ts_interfaces/tickets.js';
|
|
10
10
|
import { assertMcpTicketRequest, assertTicketResponse } from './functions.ticketvalidation.js';
|
|
11
11
|
import { assertSessionFeedWireRequest, assertSessionFeedWireResponse } from './functions.sessionfeedvalidation.js';
|
|
12
12
|
import { assertFleetDeployResponse, assertFleetDeployWireRequest } from './fleet/functions.deployvalidation.js';
|
|
@@ -1022,7 +1022,7 @@ export class ControllerMcpClient {
|
|
|
1022
1022
|
const conflict = readTicketRevisionConflict(decoded.error.data);
|
|
1023
1023
|
if (serverCode === 'ticket_revision_conflict' && !conflict) throw new Error('Invalid conflict metadata.');
|
|
1024
1024
|
currentRevision = conflict?.currentRevision;
|
|
1025
|
-
if (typeof serverCode === 'string' && Object.hasOwn(ticketErrorMessages, serverCode)) code = serverCode.toUpperCase() as TTicketClientErrorCode;
|
|
1025
|
+
if (typeof serverCode === 'string' && (Object.hasOwn(ticketErrorMessages, serverCode) || Object.hasOwn(ticketPageErrorMessages, serverCode))) code = serverCode.toUpperCase() as TTicketClientErrorCode;
|
|
1026
1026
|
if (serverCode === 'controller_unavailable') code = 'CONTROLLER_UNAVAILABLE';
|
|
1027
1027
|
if (serverCode === 'authentication_failed') code = 'AUTHENTICATION_FAILED';
|
|
1028
1028
|
if (serverCode === 'response_limit') code = 'RESPONSE_LIMIT';
|
|
@@ -34,7 +34,7 @@ import { controllerMcpDeployMethods, type TControllerMcpDeployMethod, type TCont
|
|
|
34
34
|
import { controllerMcpPushMethods, pushErrorCodes, type TControllerMcpPushMethod, type TControllerMcpPushTypedRequest } from '../ts_interfaces/push.js';
|
|
35
35
|
import { redactPushRequest } from './functions.pushwire.js';
|
|
36
36
|
import { deployErrorCodes } from './fleet/classes.deploymonitor.js';
|
|
37
|
-
import { readTicketRevisionConflict, ticketErrorMessages, type TTicketOperation, type TTicketRequest, type TTicketResponse } from '../ts_interfaces/tickets.js';
|
|
37
|
+
import { readTicketRevisionConflict, ticketErrorMessages, ticketPageErrorMessages, type TTicketOperation, type TTicketRequest, type TTicketResponse } from '../ts_interfaces/tickets.js';
|
|
38
38
|
import { ticketOperation } from './functions.ticketvalidation.js';
|
|
39
39
|
import { controllerFailureJournal } from './classes.failurejournal.js';
|
|
40
40
|
import { configurationErrorCodes } from './configuration/classes.configurationerror.js';
|
|
@@ -323,6 +323,7 @@ const safeTypedResponseError = (
|
|
|
323
323
|
if (typeof code === 'string' && /^[a-z0-9_]{1,64}$/.test(code)) {
|
|
324
324
|
const messages: Record<string, string> = {
|
|
325
325
|
...ticketErrorMessages,
|
|
326
|
+
...ticketPageErrorMessages,
|
|
326
327
|
controller_unavailable: 'The controller is not ready to accept this operation.',
|
|
327
328
|
operation_limit: 'The controller is busy. Try again after current operations settle.',
|
|
328
329
|
rate_limited: 'The authenticated operation rate limit was reached.',
|
package/ts/classes.mcptools.ts
CHANGED
|
@@ -3,6 +3,7 @@ import type { IFleetEvent } from '../ts_interfaces/fleetworkers.js';
|
|
|
3
3
|
import type { ITicketChange, ITicketObservation } from './classes.ticketstore.js';
|
|
4
4
|
import { quoteAgentMessageHeaderText } from './functions.agentmessage.js';
|
|
5
5
|
import { boardPumpActor } from './fleet/classes.boardpump.js';
|
|
6
|
+
import { workerIdentityActor } from './fleet/classes.ticketeffects.js';
|
|
6
7
|
|
|
7
8
|
export interface ITicketNotifierOptions {
|
|
8
9
|
/** Steers the live native session (`harness:nativeId`) with the notice; rejects when it was not admitted. */
|
|
@@ -124,8 +125,8 @@ export const ticketNoticeText = (changesArg: ITicketChange[], recipientArg: stri
|
|
|
124
125
|
/**
|
|
125
126
|
* Tells assignees about changes others make to their tickets, and the session that asked a question about its answer. Changes to one ticket for one session gather for a
|
|
126
127
|
* short window and then go out as one notice, at most one per interval, steered into the live session. A session
|
|
127
|
-
* never hears of its own changes, and nobody hears of the board pump's
|
|
128
|
-
* fleet event stream.
|
|
128
|
+
* never hears of its own changes, and nobody hears of the board pump's or of a notice that a worker calls without its
|
|
129
|
+
* identity. Every change but the driver's own also goes to the fleet event stream.
|
|
129
130
|
*/
|
|
130
131
|
export class TicketNotifier {
|
|
131
132
|
private readonly batches = new Map<string, ITicketNoticeBatch>();
|
|
@@ -146,7 +147,8 @@ export class TicketNotifier {
|
|
|
146
147
|
// A reorder is the side effect of another ticket's move; the mover's ticket carries the notice.
|
|
147
148
|
if (change.action === 'reordered') continue;
|
|
148
149
|
// The board pump tells the driver through its own event; steering the assignee would start the work it must leave to the driver.
|
|
149
|
-
|
|
150
|
+
// A notice that a worker calls without its identity is for the owner: it would only wake the worker it is about.
|
|
151
|
+
if (change.actor.id === boardPumpActor.id || change.actor.id === workerIdentityActor.id) continue;
|
|
150
152
|
if (change.actor.role !== 'driver' && change.origin === undefined) {
|
|
151
153
|
// A comment's whole text is the comment, which the driver reads by its id.
|
|
152
154
|
const comment = change.action === 'commented' ? change.changes.comment?.after as ITicketComment | undefined : undefined;
|
|
@@ -5,7 +5,9 @@ import {
|
|
|
5
5
|
type TTicketLink, type TTicketOperation, type TTicketRequest, type TTicketResponse,
|
|
6
6
|
type TTicketFleetEvent, type ITicketFleetEventResult, type ITicketComment, type TTicketData, type ITicketOpenQuestion, type TTicketAutoLabel,
|
|
7
7
|
type ITicketDetail, type ITicketGet, type ITicketAsk, type ITicketMaintenanceWindow, ticketHistoryPage,
|
|
8
|
+
type ITicketOverviewRequest, type ITicketPageRequest, ticketPageErrorMessages,
|
|
8
9
|
} from '../ts_interfaces/tickets.js';
|
|
10
|
+
import { TicketCursorError, ticketOverview, ticketPage } from './functions.ticketlisting.js';
|
|
9
11
|
import {
|
|
10
12
|
TicketModel, TicketBoardModel, TicketCommentModel, TicketActivityModel, TicketQuestionModel, TicketFleetEventModel,
|
|
11
13
|
} from './classes.ticketmodels.js';
|
|
@@ -21,6 +23,14 @@ const mutableOperations = new Set<TTicketOperation>(['create', 'update', 'move',
|
|
|
21
23
|
* entries it returns, whatever its `limit`, so a page cut by the byte budget does not read `limit` records.
|
|
22
24
|
*/
|
|
23
25
|
export const ticketHistoryBatch = 16;
|
|
26
|
+
/**
|
|
27
|
+
* The gap a ticket placed at the end of a column leaves after the last one (AGL-1907). A ticket's `order` is a sparse,
|
|
28
|
+
* non-negative integer sort key: only its value relative to the other tickets of its column means anything, never a
|
|
29
|
+
* position or a count. A placement before another ticket takes the integer halfway into the gap before it.
|
|
30
|
+
*/
|
|
31
|
+
export const ticketOrderStride = 1024;
|
|
32
|
+
/** The order range the first read of a run of tickets that leave no integer free covers; each further read doubles it, up to `ticketOrderRunSpan.maximum`. */
|
|
33
|
+
const ticketOrderRunSpan = { first: 16, maximum: 512 } as const;
|
|
24
34
|
|
|
25
35
|
/** One change a committed ticket transaction made, or an edit it refused as stale. */
|
|
26
36
|
export interface ITicketChange {
|
|
@@ -62,7 +72,7 @@ interface ITicketTrack {
|
|
|
62
72
|
* lost (`concurrent_change`, nothing written), a transaction whose commit outcome is unknown (`outcome_unknown`), a
|
|
63
73
|
* fleet event key that names another request, and an owner capability the controller could not verify.
|
|
64
74
|
*/
|
|
65
|
-
export type TTicketErrorCode = keyof typeof ticketErrorMessages | 'concurrent_change' | 'outcome_unknown'
|
|
75
|
+
export type TTicketErrorCode = keyof typeof ticketErrorMessages | keyof typeof ticketPageErrorMessages | 'concurrent_change' | 'outcome_unknown'
|
|
66
76
|
| 'ticket_fleet_event_conflict' | 'unauthorized';
|
|
67
77
|
|
|
68
78
|
export class TicketError extends Error {
|
|
@@ -449,7 +459,7 @@ export class TicketStore {
|
|
|
449
459
|
public async execute<TMethod extends TTicketOperation>(
|
|
450
460
|
methodArg: TMethod, requestArg: TTicketRequest<TMethod>, actorArg: ITicketActor | undefined, signalArg?: AbortSignal,
|
|
451
461
|
): Promise<TTicketResponse<TMethod>> {
|
|
452
|
-
if (actorArg === undefined && methodArg !== 'list' && methodArg !== 'get') {
|
|
462
|
+
if (actorArg === undefined && methodArg !== 'list' && methodArg !== 'get' && methodArg !== 'page' && methodArg !== 'overview') {
|
|
453
463
|
throw new TicketError('ticket_identity_required', ticketErrorMessages.ticket_identity_required);
|
|
454
464
|
}
|
|
455
465
|
const actor = actorArg === undefined ? undefined : ticketActorSchema.parse(actorArg);
|
|
@@ -532,10 +542,65 @@ export class TicketStore {
|
|
|
532
542
|
return await TicketModel.exact.findStoredOne({ id: ticketIdArg }, { session: sessionArg });
|
|
533
543
|
}
|
|
534
544
|
|
|
535
|
-
/**
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
|
|
545
|
+
/**
|
|
546
|
+
* The ticket last in a column, `excludeArg` (the ticket being placed) left out: one document, `ticket_column_order`
|
|
547
|
+
* read backwards. The store keeps the orders of a column distinct, so the last order is the column's end.
|
|
548
|
+
*/
|
|
549
|
+
private async lastInColumn(columnIdArg: ITicket['columnId'], excludeArg: string | undefined, sessionArg: TSession): Promise<TTicketStored | undefined> {
|
|
550
|
+
return (await TicketModel.exact.findStored({ filter: { 'ticket.columnId': columnIdArg,
|
|
551
|
+
...(excludeArg === undefined ? {} : { id: { $ne: excludeArg } }) }, sort: { 'ticket.order': -1 }, limit: 1, session: sessionArg }))[0];
|
|
552
|
+
}
|
|
553
|
+
|
|
554
|
+
/**
|
|
555
|
+
* The order a ticket placed at the end of a column takes: `ticketOrderStride` after the last one's, or
|
|
556
|
+
* `ticketOrderStride` in an empty column.
|
|
557
|
+
*/
|
|
558
|
+
private async columnEnd(columnIdArg: ITicket['columnId'], excludeArg: string | undefined, sessionArg: TSession): Promise<{ last?: TTicketStored; order: number }> {
|
|
559
|
+
const last = await this.lastInColumn(columnIdArg, excludeArg, sessionArg);
|
|
560
|
+
return { ...(last ? { last } : {}), order: (last?.ticket.order ?? 0) + ticketOrderStride };
|
|
561
|
+
}
|
|
562
|
+
|
|
563
|
+
/**
|
|
564
|
+
* Where a ticket goes before an anchor at order `anchorArg` when the ticket before it holds `previousArg` (−1 for none)
|
|
565
|
+
* and no integer is free between them: the shorter of two runs moves by one. Either the anchor and the tickets right
|
|
566
|
+
* above it move up to the first integer none of them holds, and the ticket takes the anchor's order (`step` 1), or the
|
|
567
|
+
* ticket before the anchor and those right below it move down to the first free integer from 0 on, and the ticket
|
|
568
|
+
* takes that one's order (`step` −1); with every integer from 0 to `previousArg` held, only the first is possible.
|
|
569
|
+
* `excludeArg`, the ticket being placed, is left out of both, so its own order is free on either side. Both runs are
|
|
570
|
+
* read by order range through `ticket_column_order`, nearest the anchor first, one range of each per round, each round
|
|
571
|
+
* twice the last (at most 512 orders). The rounds stop when the first run ends, which is the shorter, so the longer
|
|
572
|
+
* side is read no further than the shorter run needs, never to the column's end. A range holds every ticket of its orders.
|
|
573
|
+
*/
|
|
574
|
+
private async orderShift(columnIdArg: ITicket['columnId'], previousArg: number, anchorArg: number, excludeArg: string,
|
|
575
|
+
sessionArg: TSession): Promise<{ order: number; step: 1 | -1; run: TTicketStored[] }> {
|
|
576
|
+
/** Each run: its tickets nearest the anchor first, the next order it reads, and whether that order is free (`ended`). */
|
|
577
|
+
const up = { run: [] as TTicketStored[], next: anchorArg, ended: false };
|
|
578
|
+
const down = { run: [] as TTicketStored[], next: previousArg, ended: false, blocked: previousArg < 0 };
|
|
579
|
+
const range = (orderArg: Record<string, number>, sortArg: 1 | -1) => TicketModel.exact.findStored({ filter: {
|
|
580
|
+
'ticket.columnId': columnIdArg, 'ticket.order': orderArg, id: { $ne: excludeArg } }, sort: { 'ticket.order': sortArg }, session: sessionArg });
|
|
581
|
+
for (let span: number = ticketOrderRunSpan.first; ; span = Math.min(span * 2, ticketOrderRunSpan.maximum)) {
|
|
582
|
+
const upEnd = up.next + span;
|
|
583
|
+
for (const record of await range({ $gte: up.next, $lt: upEnd }, 1)) {
|
|
584
|
+
if (record.ticket.order > up.next) break;
|
|
585
|
+
up.run.push(record);
|
|
586
|
+
up.next = record.ticket.order + 1;
|
|
587
|
+
}
|
|
588
|
+
up.ended = up.next < upEnd;
|
|
589
|
+
if (!down.blocked) {
|
|
590
|
+
// Orders below 0 are not free: a run that reaches −1 cannot move down.
|
|
591
|
+
const downEnd = Math.max(down.next - span, -1);
|
|
592
|
+
for (const record of await range({ $lte: down.next, $gt: downEnd }, -1)) {
|
|
593
|
+
if (record.ticket.order < down.next) break;
|
|
594
|
+
down.run.push(record);
|
|
595
|
+
down.next = record.ticket.order - 1;
|
|
596
|
+
}
|
|
597
|
+
down.ended = down.next > downEnd;
|
|
598
|
+
down.blocked = !down.ended && down.next < 0;
|
|
599
|
+
}
|
|
600
|
+
// Both read as many orders this round, so a run still going is at least as long as one that ended.
|
|
601
|
+
if (up.ended && (!down.ended || up.run.length <= down.run.length)) return { order: anchorArg, step: 1, run: up.run };
|
|
602
|
+
if (down.ended) return { order: previousArg, step: -1, run: down.run };
|
|
603
|
+
}
|
|
539
604
|
}
|
|
540
605
|
|
|
541
606
|
private async paged<TRecord extends { id: string }>(pageArg: (afterArg: string | undefined) => Promise<TRecord[]>): Promise<TRecord[]> {
|
|
@@ -792,14 +857,32 @@ export class TicketStore {
|
|
|
792
857
|
}
|
|
793
858
|
|
|
794
859
|
/**
|
|
795
|
-
* Each operation reads what it decides on and nothing more: the listing operations read the whole board and every
|
|
796
|
-
* open question; create the parent and the
|
|
797
|
-
*
|
|
798
|
-
*
|
|
860
|
+
* Each operation reads what it decides on and nothing more: the listing operations (list, board, search, page, overview) read the whole board and every
|
|
861
|
+
* open question; create the parent and the last ticket of its column; move the ticket and, in the destination, the
|
|
862
|
+
* last ticket or the anchor and the ticket before it, plus, only when no integer is free between them, both sides of
|
|
863
|
+
* them a range at a time until the shorter run ends (never the column it leaves, which it does not write either);
|
|
864
|
+
* update the ticket, its parent and, when the project changes, its children; every other operation one ticket, and get
|
|
865
|
+
* one page of its history or, with `commentId`, that one comment. The board document's revision transition in the caller orders every mutation.
|
|
799
866
|
*/
|
|
800
867
|
private async perform(methodArg: TTicketOperation, requestArg: TTicketRequest<TTicketOperation>, actorArg: ITicketActor | undefined,
|
|
801
868
|
sessionArg: TSession, nowArg: string, sequenceArg: number,
|
|
802
869
|
revisionArg: number, trackArg: ITicketTrack): Promise<unknown> {
|
|
870
|
+
if (methodArg === 'page' || methodArg === 'overview') {
|
|
871
|
+
// Reads what `list` reads; `functions.ticketlisting.ts` pages or summarizes it without another read.
|
|
872
|
+
const request = requestArg as ITicketPageRequest & ITicketOverviewRequest;
|
|
873
|
+
const all = await this.allTickets(sessionArg);
|
|
874
|
+
await this.countOpenQuestions(trackArg, sessionArg);
|
|
875
|
+
const matches = ticketFilter(methodArg === 'page' ? request : { mine: request.mine, project: request.project }, actorArg);
|
|
876
|
+
const tickets = all.map((recordArg) => this.visible(recordArg.ticket, actorArg, trackArg)).filter(matches);
|
|
877
|
+
const openQuestions = (ticketIdArg: string): number => trackArg.openQuestions.get(ticketIdArg) ?? 0;
|
|
878
|
+
try {
|
|
879
|
+
return methodArg === 'page' ? ticketPage(tickets, request, revisionArg, openQuestions, actorArg?.sessionId ?? actorArg?.id)
|
|
880
|
+
: ticketOverview(tickets, request, revisionArg, nowArg, openQuestions);
|
|
881
|
+
} catch (errorArg) {
|
|
882
|
+
if (errorArg instanceof TicketCursorError) throw new TicketError(errorArg.code, ticketPageErrorMessages[errorArg.code]);
|
|
883
|
+
throw errorArg;
|
|
884
|
+
}
|
|
885
|
+
}
|
|
803
886
|
if (methodArg === 'list' || methodArg === 'board' || methodArg === 'search') {
|
|
804
887
|
const filters: ITicketFilters = methodArg === 'search'
|
|
805
888
|
? { text: (requestArg as TTicketRequest<'search'>).query, label: (requestArg as TTicketRequest<'search'>).label }
|
|
@@ -831,7 +914,7 @@ export class TicketStore {
|
|
|
831
914
|
const id = `AGL-${sequenceArg}`;
|
|
832
915
|
const ticket: ITicket = { id, key: id, revision: 1, project: input.project, kind: input.kind ?? 'task', title: input.title,
|
|
833
916
|
description: input.description ?? '', ...(input.parentId ? { parentId: input.parentId } : {}), columnId,
|
|
834
|
-
order: await
|
|
917
|
+
order: (await this.columnEnd(columnId, undefined, sessionArg)).order,
|
|
835
918
|
priority: input.priority ?? 'normal', ...(input.assignee ? { assignee: input.assignee } : {}), labels: input.labels ?? [], links: [],
|
|
836
919
|
...(input.releasePlan ? { releasePlan: input.releasePlan } : {}),
|
|
837
920
|
...(input.maintenanceWindow ? { maintenanceWindow: input.maintenanceWindow } : {}),
|
|
@@ -1028,23 +1111,37 @@ export class TicketStore {
|
|
|
1028
1111
|
if (ticket.columnId !== input.columnId) this.requireEvidence(ticket, input.columnId);
|
|
1029
1112
|
// Landed code ships with the tag that holds it: closing its ticket would drop it from release and deploy tracking.
|
|
1030
1113
|
if (ticket.columnId === 'landed' && input.columnId === 'closed') throw new TicketError('ticket_closed_landed', ticketErrorMessages.ticket_closed_landed);
|
|
1031
|
-
|
|
1032
|
-
|
|
1033
|
-
const
|
|
1034
|
-
|
|
1035
|
-
|
|
1036
|
-
|
|
1037
|
-
|
|
1038
|
-
|
|
1039
|
-
|
|
1040
|
-
|
|
1041
|
-
|
|
1042
|
-
|
|
1043
|
-
|
|
1044
|
-
|
|
1045
|
-
changed.push(await this.save(record, next, actorArg, sessionArg,
|
|
1046
|
-
record.id === ticketId ? 'moved' : 'reordered', nowArg, trackArg, revisionArg));
|
|
1114
|
+
// Orders are sparse (AGL-1907): the column a ticket leaves is neither read nor written, and a place in the destination
|
|
1115
|
+
// costs the ticket's own write unless no integer is free before its anchor. A ticket already in place writes nothing.
|
|
1116
|
+
const sameColumn = ticket.columnId === input.columnId;
|
|
1117
|
+
// The order the ticket takes and, when no integer is free before its anchor, the run that moves by one to free it.
|
|
1118
|
+
let order: number;
|
|
1119
|
+
let shift: { step: 1 | -1; run: TTicketStored[] } = { step: 1, run: [] };
|
|
1120
|
+
if (input.beforeTicketId === undefined) {
|
|
1121
|
+
const end = await this.columnEnd(input.columnId, ticketId, sessionArg);
|
|
1122
|
+
if (sameColumn && (end.last === undefined || end.last.ticket.order < ticket.order)) return { tickets: [] };
|
|
1123
|
+
order = end.order;
|
|
1124
|
+
} else {
|
|
1125
|
+
const anchor = await this.ticket(input.beforeTicketId, sessionArg);
|
|
1126
|
+
if (anchor?.ticket.columnId !== input.columnId) {
|
|
1127
|
+
throw new TicketError('ticket_move_anchor_invalid', 'The before-ticket must belong to the destination column.');
|
|
1047
1128
|
}
|
|
1129
|
+
const next = anchor.ticket.order;
|
|
1130
|
+
const previous = (await TicketModel.exact.findStored({ filter: { 'ticket.columnId': input.columnId, 'ticket.order': { $lt: next },
|
|
1131
|
+
id: { $ne: ticketId } }, sort: { 'ticket.order': -1 }, limit: 1, session: sessionArg }))[0]?.ticket.order ?? -1;
|
|
1132
|
+
if (sameColumn && previous < ticket.order && ticket.order < next) return { tickets: [] };
|
|
1133
|
+
if (next - previous >= 2) order = previous + Math.floor((next - previous) / 2);
|
|
1134
|
+
else {
|
|
1135
|
+
// No integer is free before the anchor: the shorter run on either side of it moves by one.
|
|
1136
|
+
const placed = await this.orderShift(input.columnId, previous, next, ticketId, sessionArg);
|
|
1137
|
+
order = placed.order;
|
|
1138
|
+
shift = placed;
|
|
1139
|
+
}
|
|
1140
|
+
}
|
|
1141
|
+
const changed = [await this.save(current, { ...ticket, columnId: input.columnId, order }, actorArg, sessionArg, 'moved', nowArg, trackArg, revisionArg)];
|
|
1142
|
+
for (const record of shift.run) {
|
|
1143
|
+
changed.push(await this.save(record, { ...record.ticket, order: record.ticket.order + shift.step }, actorArg, sessionArg,
|
|
1144
|
+
'reordered', nowArg, trackArg, revisionArg));
|
|
1048
1145
|
}
|
|
1049
1146
|
await this.countOpenQuestions(trackArg, sessionArg, changed.map((ticketArg) => ticketArg.id));
|
|
1050
1147
|
return { tickets: changed.map((ticketArg) => this.visible(ticketArg, actorArg, trackArg)) };
|