agl 43.6.0 → 43.8.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 +27 -0
- package/dist_serve/bundle.js +1801 -1783
- package/dist_serve/bundle.js.map +2 -2
- package/dist_ts/00_commitinfo_data.js +1 -1
- package/dist_ts/aglapi/interfaces.d.ts +35 -0
- package/dist_ts/aglapi/interfaces.js +9 -1
- package/dist_ts/classes.accountsactions.d.ts +3 -1
- package/dist_ts/classes.accountsactions.js +17 -1
- package/dist_ts/classes.apnsclient.d.ts +97 -0
- package/dist_ts/classes.apnsclient.js +363 -0
- package/dist_ts/classes.authmodels.js +19 -6
- package/dist_ts/classes.authstore.js +15 -2
- package/dist_ts/classes.cli.js +8 -1
- package/dist_ts/classes.controller.d.ts +33 -6
- package/dist_ts/classes.controller.js +254 -12
- package/dist_ts/classes.controllerdevices.d.ts +35 -7
- package/dist_ts/classes.controllerdevices.js +86 -13
- package/dist_ts/classes.controllerpush.d.ts +111 -0
- package/dist_ts/classes.controllerpush.js +299 -0
- package/dist_ts/classes.fcmclient.d.ts +78 -0
- package/dist_ts/classes.fcmclient.js +278 -0
- package/dist_ts/classes.inbox.d.ts +10 -2
- package/dist_ts/classes.inbox.js +9 -2
- package/dist_ts/classes.inferencerouter.d.ts +21 -3
- package/dist_ts/classes.inferencerouter.js +40 -17
- package/dist_ts/classes.inferenceservice.js +2 -2
- package/dist_ts/classes.mcpclient.d.ts +5 -0
- package/dist_ts/classes.mcpclient.js +18 -6
- package/dist_ts/classes.mcpcontrollerhost.d.ts +3 -0
- package/dist_ts/classes.mcpcontrollerhost.js +19 -1
- package/dist_ts/classes.mcpvalidation.js +4 -1
- package/dist_ts/classes.mcpworkercaller.d.ts +6 -0
- package/dist_ts/classes.mcpworkercaller.js +26 -4
- package/dist_ts/classes.pushdelivery.d.ts +115 -0
- package/dist_ts/classes.pushdelivery.js +311 -0
- package/dist_ts/classes.pushhandover.d.ts +46 -0
- package/dist_ts/classes.pushhandover.js +131 -0
- package/dist_ts/classes.pushregistrations.d.ts +96 -0
- package/dist_ts/classes.pushregistrations.js +263 -0
- package/dist_ts/classes.pushsettings.d.ts +125 -0
- package/dist_ts/classes.pushsettings.js +377 -0
- package/dist_ts/classes.workercallers.d.ts +73 -2
- package/dist_ts/classes.workercallers.js +354 -43
- package/dist_ts/driver/classes.directreports.d.ts +5 -0
- package/dist_ts/driver/classes.directreports.js +3 -2
- package/dist_ts/fleet/classes.workerlaunches.d.ts +6 -4
- package/dist_ts/fleet/classes.workerlaunches.js +10 -9
- package/dist_ts/fleet/classes.workers.d.ts +12 -2
- package/dist_ts/fleet/classes.workers.js +82 -2
- package/dist_ts/functions.deviceapi.d.ts +23 -3
- package/dist_ts/functions.deviceapi.js +41 -3
- package/dist_ts/functions.inferencecli.js +2 -1
- package/dist_ts/functions.pushcli.d.ts +43 -0
- package/dist_ts/functions.pushcli.js +201 -0
- package/dist_ts/functions.pushcredentials.d.ts +53 -0
- package/dist_ts/functions.pushcredentials.js +111 -0
- package/dist_ts/functions.pushwire.d.ts +8 -0
- package/dist_ts/functions.pushwire.js +83 -0
- package/dist_ts/functions.remotecli.d.ts +2 -2
- package/dist_ts/functions.remotecli.js +4 -4
- package/dist_ts/functions.workercallervalidation.js +3 -2
- package/dist_ts/functions.workerprocessproof.d.ts +12 -0
- package/dist_ts/functions.workerprocessproof.js +32 -1
- package/dist_ts/interfaces.auth.d.ts +27 -3
- package/dist_ts/interfaces.auth.js +10 -1
- package/dist_ts/interfaces.lifecycle.d.ts +7 -1
- package/dist_ts/interfaces.push.d.ts +69 -0
- package/dist_ts/interfaces.push.js +25 -0
- package/dist_ts/plugins.d.ts +5 -2
- package/dist_ts/plugins.js +7 -3
- package/dist_ts_authswitch/authority-contract.d.ts +26 -0
- package/dist_ts_authswitch/authority-contract.js +1 -1
- package/dist_ts_authswitch/authority-overview.d.ts +8 -0
- package/dist_ts_authswitch/authority-overview.js +10 -4
- package/dist_ts_authswitch/authority-placement.d.ts +16 -9
- package/dist_ts_authswitch/authority-placement.js +10 -7
- package/dist_ts_authswitch/authority-priority.d.ts +20 -0
- package/dist_ts_authswitch/authority-priority.js +21 -0
- package/dist_ts_authswitch/classes.authoritybroker.d.ts +7 -0
- package/dist_ts_authswitch/classes.authoritybroker.js +26 -2
- package/dist_ts_authswitch/classes.authoritycli.d.ts +1 -0
- package/dist_ts_authswitch/classes.authoritycli.js +43 -3
- package/dist_ts_authswitch/classes.authorityclient.d.ts +6 -1
- package/dist_ts_authswitch/classes.authorityclient.js +12 -4
- package/dist_ts_authswitch/classes.authoritydaemon.js +7 -1
- package/dist_ts_authswitch/classes.authoritydatabase.d.ts +6 -0
- package/dist_ts_authswitch/classes.authoritydatabase.js +13 -2
- package/dist_ts_authswitch/classes.authoritymodels.d.ts +7 -0
- package/dist_ts_authswitch/classes.authoritymodels.js +17 -8
- package/dist_ts_interfaces/devices.d.ts +178 -2
- package/dist_ts_interfaces/devices.js +24 -2
- package/dist_ts_interfaces/index.d.ts +1 -0
- package/dist_ts_interfaces/index.js +2 -1
- package/dist_ts_interfaces/mcprequests.d.ts +3 -2
- package/dist_ts_interfaces/mcprequests.js +3 -1
- package/dist_ts_interfaces/push.d.ts +166 -0
- package/dist_ts_interfaces/push.js +24 -0
- 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.js +1 -1
- package/dist_ts_interfaces/workercallers.d.ts +43 -3
- package/docs/authswitch.md +25 -0
- package/package.json +1 -1
- package/readme.md +93 -16
- package/ts/00_commitinfo_data.ts +1 -1
- package/ts/aglapi/interfaces.ts +8 -0
- package/ts/classes.accountsactions.ts +25 -0
- package/ts/classes.apnsclient.ts +389 -0
- package/ts/classes.authmodels.ts +21 -5
- package/ts/classes.authstore.ts +14 -1
- package/ts/classes.cli.ts +7 -0
- package/ts/classes.controller.ts +277 -10
- package/ts/classes.controllerdevices.ts +94 -12
- package/ts/classes.controllerpush.ts +351 -0
- package/ts/classes.fcmclient.ts +292 -0
- package/ts/classes.inbox.ts +13 -2
- package/ts/classes.inferencerouter.ts +61 -16
- package/ts/classes.inferenceservice.ts +1 -1
- package/ts/classes.mcpclient.ts +20 -5
- package/ts/classes.mcpcontrollerhost.ts +20 -0
- package/ts/classes.mcpvalidation.ts +2 -0
- package/ts/classes.mcpworkercaller.ts +24 -2
- package/ts/classes.pushdelivery.ts +378 -0
- package/ts/classes.pushhandover.ts +98 -0
- package/ts/classes.pushregistrations.ts +244 -0
- package/ts/classes.pushsettings.ts +428 -0
- package/ts/classes.workercallers.ts +329 -37
- package/ts/driver/classes.directreports.ts +7 -1
- package/ts/fleet/classes.workerlaunches.ts +9 -7
- package/ts/fleet/classes.workers.ts +65 -2
- package/ts/functions.deviceapi.ts +52 -2
- package/ts/functions.inferencecli.ts +1 -0
- package/ts/functions.pushcli.ts +212 -0
- package/ts/functions.pushcredentials.ts +129 -0
- package/ts/functions.pushwire.ts +106 -0
- package/ts/functions.remotecli.ts +3 -2
- package/ts/functions.workercallervalidation.ts +2 -1
- package/ts/functions.workerprocessproof.ts +34 -0
- package/ts/interfaces.auth.ts +27 -3
- package/ts/interfaces.lifecycle.ts +7 -1
- package/ts/interfaces.push.ts +78 -0
- package/ts/plugins.ts +6 -1
- package/ts_authswitch/authority-contract.ts +21 -0
- package/ts_authswitch/authority-overview.ts +19 -5
- package/ts_authswitch/authority-placement.ts +18 -10
- package/ts_authswitch/authority-priority.ts +25 -0
- package/ts_authswitch/classes.authoritybroker.ts +26 -1
- package/ts_authswitch/classes.authoritycli.ts +48 -2
- package/ts_authswitch/classes.authorityclient.ts +14 -4
- package/ts_authswitch/classes.authoritydaemon.ts +8 -1
- package/ts_authswitch/classes.authoritydatabase.ts +11 -1
- package/ts_authswitch/classes.authoritymodels.ts +17 -6
- package/ts_authswitch/readme.md +1 -1
- package/ts_interfaces/devices.schema.json +327 -0
- package/ts_interfaces/devices.ts +206 -1
- package/ts_interfaces/index.ts +1 -0
- package/ts_interfaces/mcprequests.ts +3 -0
- package/ts_interfaces/push.ts +162 -0
- package/ts_interfaces/requests.accounts.ts +17 -0
- package/ts_interfaces/requests.ts +2 -0
- package/ts_interfaces/workercallers.ts +34 -2
- package/ts_web/00_commitinfo_data.ts +1 -1
- package/ts_web/accounts.plugins.ts +4 -2
- package/ts_web/classes.accountsreadmodel.ts +36 -2
- package/ts_web/elements.accounts.ts +48 -0
package/ts/classes.inbox.ts
CHANGED
|
@@ -24,7 +24,10 @@ export interface IInboxSources {
|
|
|
24
24
|
* the part of them a failed partial read could not renew. A read that fails keeps the source's previous items.
|
|
25
25
|
*/
|
|
26
26
|
read(sourceArg: TInboxSource, previousArg: readonly TControllerInboxItem[], signalArg: AbortSignal): Promise<TControllerInboxItem[]>;
|
|
27
|
-
/**
|
|
27
|
+
/**
|
|
28
|
+
* Whether a browser or a device receives controller events, or a notification could go out (a registered device on
|
|
29
|
+
* a platform the host can send on); without either the Inbox only marks its sources stale.
|
|
30
|
+
*/
|
|
28
31
|
hasViewers(): Promise<boolean>;
|
|
29
32
|
publish(deltaArg: TControllerInboxDelta): void;
|
|
30
33
|
reportError(messageArg: string, errorArg: unknown): void;
|
|
@@ -72,7 +75,7 @@ export const boundInboxItem = (itemArg: TControllerInboxItem): TControllerInboxI
|
|
|
72
75
|
* deltas. Nothing is stored: every item is read from the component that owns it, so an answer anywhere removes it.
|
|
73
76
|
*
|
|
74
77
|
* Events mark the sources they concern stale; a pass reads only the stale ones, coalesced, and only while a browser
|
|
75
|
-
* or a device is connected. `list()` reads every stale source first.
|
|
78
|
+
* or a device is connected or a notification could go out. `list()` reads every stale source first.
|
|
76
79
|
*/
|
|
77
80
|
export class ControllerInbox {
|
|
78
81
|
private readonly abort = new AbortController();
|
|
@@ -99,6 +102,14 @@ export class ControllerInbox {
|
|
|
99
102
|
public async list(): Promise<IControllerInboxSnapshot> {
|
|
100
103
|
this.abort.signal.throwIfAborted();
|
|
101
104
|
await this.enqueuePass();
|
|
105
|
+
return this.current();
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
/**
|
|
109
|
+
* What the last pass published, reading nothing: for a consumer of the published deltas that met a `reset` (the push
|
|
110
|
+
* trigger), never a second computation of the Inbox.
|
|
111
|
+
*/
|
|
112
|
+
public current(): IControllerInboxSnapshot {
|
|
102
113
|
return { epoch: this.published.epoch, revision: this.published.revision, items: this.published.values(), total: this.total, limited: this.limited };
|
|
103
114
|
}
|
|
104
115
|
|
|
@@ -83,6 +83,12 @@ export interface IInferenceAccount {
|
|
|
83
83
|
* without one. Placement only: a window's usage counts as spent by the next renewal (`authSwitchPlacement`).
|
|
84
84
|
*/
|
|
85
85
|
renewsAt: string | null;
|
|
86
|
+
/**
|
|
87
|
+
* When the owner's priority on the account ends (`IAuthSwitchAccount.priorityUntil`, AGL-1809); `null` without one.
|
|
88
|
+
* While it holds at the moment of placing (`authSwitchPriorityActive`), a new session goes to the account before any
|
|
89
|
+
* account of the pool without one, as long as it takes the request (`inferencePlacementOrder`).
|
|
90
|
+
*/
|
|
91
|
+
priorityUntil: string | null;
|
|
86
92
|
/**
|
|
87
93
|
* An API key's monthly spend limit in micro-dollars (`IAuthSwitchAccount.spendLimitMicroUsd`); `null` without one,
|
|
88
94
|
* and for a sign-in. It decides only whether a key whose spend the proxy holds no reading of may take work: one with
|
|
@@ -745,6 +751,11 @@ export interface IInferenceAccountStatus {
|
|
|
745
751
|
* without one. Placement ignores it while the account has a lapse date. A proxy of an earlier AGL reports none.
|
|
746
752
|
*/
|
|
747
753
|
renewal?: plugins.authswitchRenewal.IAuthSwitchRenewal | null;
|
|
754
|
+
/**
|
|
755
|
+
* When the owner's priority on the account ends, while it holds now (`IInferenceAccount.priorityUntil`), or `null`: the
|
|
756
|
+
* account ranks before every account without one. A proxy of an earlier AGL reports none.
|
|
757
|
+
*/
|
|
758
|
+
priorityUntil?: string | null;
|
|
748
759
|
/** The account's placement score in percent per hour (`IAuthSwitchPlacement.score`); `null` without a counted window. */
|
|
749
760
|
placementScore: number | null;
|
|
750
761
|
/**
|
|
@@ -979,6 +990,23 @@ const accountPlacement = (readingArg: plugins.authswitchAuthority.IAuthSwitchUsa
|
|
|
979
990
|
plugins.authswitchPlacement.authSwitchPlacement(readingArg, accountArg.maxUsagePercent, accountArg.lapsesAt,
|
|
980
991
|
accountArg.renewsAt, nowArg, accountArg.reserveLiftUntil);
|
|
981
992
|
|
|
993
|
+
/** An account of a pool as a new session is placed on it: its credential tier and its rank (`IAuthSwitchPlacementRank`). */
|
|
994
|
+
interface IInferencePlacementEntry {
|
|
995
|
+
tier: number;
|
|
996
|
+
rank: plugins.authswitchPlacement.IAuthSwitchPlacementRank;
|
|
997
|
+
}
|
|
998
|
+
|
|
999
|
+
/**
|
|
1000
|
+
* The order a new session is placed in across a pool's credential tiers (`inferenceCredentialTiers`): an account with its
|
|
1001
|
+
* owner's priority (AGL-1809) before any without one, whatever its tier -- the owner chose it to be used first -- then the
|
|
1002
|
+
* better tier, then the placement order (`authSwitchPlacementOrder`), which decides among several priority accounts too.
|
|
1003
|
+
*/
|
|
1004
|
+
const inferencePlacementOrder = (inFlightArg: (accountIdArg: string) => number) => {
|
|
1005
|
+
const order = plugins.authswitchPlacement.authSwitchPlacementOrder(inFlightArg);
|
|
1006
|
+
return (left: IInferencePlacementEntry, right: IInferencePlacementEntry): number =>
|
|
1007
|
+
Number(right.rank.priority) - Number(left.rank.priority) || left.tier - right.tier || order(left.rank, right.rank);
|
|
1008
|
+
};
|
|
1009
|
+
|
|
982
1010
|
/** Model-preserving account selection. Refresh grants and native sign-ins remain the authority's. */
|
|
983
1011
|
export class InferenceRouter {
|
|
984
1012
|
/** ChatGPT catalogs by account and the Codex release they were read as. */
|
|
@@ -1472,7 +1500,7 @@ export class InferenceRouter {
|
|
|
1472
1500
|
if (pinned && optionsArg.returnToBetterTier) {
|
|
1473
1501
|
// The session's account is of a later tier: an account of a better one that can take the request takes it, as a
|
|
1474
1502
|
// new session would be placed. When none can, the session stays where it is, judged as before.
|
|
1475
|
-
const better =
|
|
1503
|
+
const better = this.betterTier(accounts, tiers, pinned);
|
|
1476
1504
|
if (better.length) {
|
|
1477
1505
|
try {
|
|
1478
1506
|
const { accountId: _pinned, ...unpinned } = optionsArg;
|
|
@@ -1486,6 +1514,21 @@ export class InferenceRouter {
|
|
|
1486
1514
|
return this.routeOpenAi(modelIdArg, policyArg, accounts, tiers, signalArg, optionsArg);
|
|
1487
1515
|
}
|
|
1488
1516
|
|
|
1517
|
+
/**
|
|
1518
|
+
* The accounts of the pool a session on `pinnedArg`, of a later credential tier, returns to (`returnToBetterTier`): those
|
|
1519
|
+
* of a better tier, as a new session would be placed. A session on a priority account (AGL-1809) returns only to a
|
|
1520
|
+
* priority account of a better tier, since a new session would go to its own account before any account without one;
|
|
1521
|
+
* a priority is judged now.
|
|
1522
|
+
*/
|
|
1523
|
+
private betterTier(accountsArg: readonly IInferenceAccount[], tiersArg: readonly TInferenceCredential[],
|
|
1524
|
+
pinnedArg: IInferenceAccount): IInferenceAccount[] {
|
|
1525
|
+
const now = this.now();
|
|
1526
|
+
const priority = (accountArg: IInferenceAccount) => plugins.authswitchPriority.authSwitchPriorityActive(
|
|
1527
|
+
accountArg.priorityUntil, now);
|
|
1528
|
+
return accountsArg.filter((account) => tiersArg.indexOf(account.credential) < tiersArg.indexOf(pinnedArg.credential)
|
|
1529
|
+
&& (!priority(pinnedArg) || priority(account)));
|
|
1530
|
+
}
|
|
1531
|
+
|
|
1489
1532
|
/** `acquire` among `accountsArg`, the pool's accounts or those of its better tiers. */
|
|
1490
1533
|
private async routeOpenAi(modelIdArg: string, policyArg: IInferenceRoutingPolicy, accountsArg: readonly IInferenceAccount[],
|
|
1491
1534
|
tiersArg: readonly TInferenceCredential[], signalArg: AbortSignal, optionsArg: IInferenceAcquireOptions): Promise<IInferenceRoute> {
|
|
@@ -1779,7 +1822,7 @@ export class InferenceRouter {
|
|
|
1779
1822
|
if (pinned && optionsArg.returnToBetterTier && !optionsArg.ignoreLimits) {
|
|
1780
1823
|
// The session's account is of a later tier: an account of a better one that can take the request takes it, as a
|
|
1781
1824
|
// new session would be placed. When none can, the session stays where it is, judged as before.
|
|
1782
|
-
const better =
|
|
1825
|
+
const better = this.betterTier(accounts, tiers, pinned);
|
|
1783
1826
|
if (better.length) {
|
|
1784
1827
|
try {
|
|
1785
1828
|
const route = await this.routeClaude(modelIdArg, policyArg, better, tiers, signalArg, {
|
|
@@ -1911,9 +1954,9 @@ export class InferenceRouter {
|
|
|
1911
1954
|
}
|
|
1912
1955
|
|
|
1913
1956
|
/**
|
|
1914
|
-
* The candidate a request goes to -- of the best credential tier, then by
|
|
1915
|
-
* (`
|
|
1916
|
-
* account as its one candidate, so the order only ever places new sessions. An account at its reserve is refused like one at its limit, and the refusal names the reserve. A pinned account
|
|
1957
|
+
* The candidate a request goes to -- a priority account before any other, then of the best credential tier, then by
|
|
1958
|
+
* the placement order (`inferencePlacementOrder`) -- or the refusal that says why there is none. A pinned request has
|
|
1959
|
+
* its session's account as its one candidate, so the order only ever places new sessions. An account at its reserve is refused like one at its limit, and the refusal names the reserve. A pinned account
|
|
1917
1960
|
* that takes no request for a reason of its own (`refusal`) is refused with that account and reason.
|
|
1918
1961
|
*/
|
|
1919
1962
|
private select<TModel>(candidatesArg: ICandidate<TModel>[], stateArg: ISelectionState): ICandidate<TModel> {
|
|
@@ -1935,12 +1978,12 @@ export class InferenceRouter {
|
|
|
1935
1978
|
candidate.score = placement.score;
|
|
1936
1979
|
return true;
|
|
1937
1980
|
});
|
|
1938
|
-
//
|
|
1939
|
-
|
|
1940
|
-
candidatesArg.
|
|
1941
|
-
|
|
1942
|
-
lastResort:
|
|
1943
|
-
|
|
1981
|
+
// A priority account first, then the best credential tier, then the placement order within it. A priority is judged
|
|
1982
|
+
// now, as a lift is: one that ended while the pool was read is none.
|
|
1983
|
+
const selected = candidatesArg.map((candidate) => ({ candidate, tier: candidate.tier, rank: { id: candidate.account.id,
|
|
1984
|
+
priority: plugins.authswitchPriority.authSwitchPriorityActive(candidate.account.priorityUntil, now),
|
|
1985
|
+
score: candidate.score, lastResort: candidate.lastResort, headroom: candidate.headroom } }))
|
|
1986
|
+
.sort(inferencePlacementOrder((accountIdArg) => this.active.get(accountIdArg) ?? 0))[0]?.candidate;
|
|
1944
1987
|
if (selected) return selected;
|
|
1945
1988
|
// A refusal names the API keys held by their spend limit, and those with a limit whose spend could not be read.
|
|
1946
1989
|
const named = (messageArg: string, sentenceArg: string) => sentenceArg ? `${messageArg} ${sentenceArg}` : messageArg;
|
|
@@ -2004,6 +2047,7 @@ export class InferenceRouter {
|
|
|
2004
2047
|
maxUsagePercent: account.maxUsagePercent, reserveLiftUntil: account.reserveLiftUntil, inFlight: this.active.get(account.id) ?? 0,
|
|
2005
2048
|
lifecycle: placement.lifecycle, lapsesAt: account.lapsesAt,
|
|
2006
2049
|
renewal: plugins.authswitchRenewal.authSwitchRenewal(account.renewsAt, now),
|
|
2050
|
+
priorityUntil: plugins.authswitchPriority.authSwitchPriorityUntil(account.priorityUntil, now),
|
|
2007
2051
|
placementScore: placement.score, placementRank: null,
|
|
2008
2052
|
lastResort: placement.eligibility === 'last_resort', claudeCode: account.claudeCode,
|
|
2009
2053
|
readingSource: held?.observation ? 'headers' as const : held?.reading ? 'poll' as const : null,
|
|
@@ -2040,16 +2084,17 @@ export class InferenceRouter {
|
|
|
2040
2084
|
plan: limits.plan || null, headroom: limits.limit?.headroom ?? null, crossing: limits.limit?.crossing ?? [],
|
|
2041
2085
|
resetAt: state === 'cooling' ? new Date(cooldown).toISOString() : limits.limit?.resetAt ?? null };
|
|
2042
2086
|
});
|
|
2043
|
-
// Each provider's accounts that take a new session now, in the order placement takes them:
|
|
2044
|
-
//
|
|
2045
|
-
const order =
|
|
2087
|
+
// 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.
|
|
2089
|
+
const order = inferencePlacementOrder((accountIdArg) => this.active.get(accountIdArg) ?? 0);
|
|
2046
2090
|
const tiers = inferenceCredentialTiers(undefined);
|
|
2047
2091
|
for (const provider of new Set(statuses.map((statusArg) => statusArg.provider))) {
|
|
2048
2092
|
statuses.filter((statusArg) => statusArg.provider === provider && statusArg.state === 'available'
|
|
2049
2093
|
&& statusArg.lifecycle !== 'lapsed')
|
|
2050
2094
|
.map((statusArg) => ({ status: statusArg, tier: tiers.indexOf(statusArg.credential), rank: { id: statusArg.id,
|
|
2051
|
-
|
|
2052
|
-
|
|
2095
|
+
priority: Boolean(statusArg.priorityUntil), score: statusArg.placementScore, lastResort: statusArg.lastResort,
|
|
2096
|
+
headroom: statusArg.headroom ?? unknownHeadroom } }))
|
|
2097
|
+
.sort(order)
|
|
2053
2098
|
.forEach((entryArg, indexArg) => { entryArg.status.placementRank = indexArg + 1; });
|
|
2054
2099
|
}
|
|
2055
2100
|
return statuses;
|
|
@@ -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, spendLimitMicroUsd: account.spendLimitMicroUsd, claudeCode: account.claudeCode, loginId: typeof login === 'string' ? null : login.id }] : [];
|
|
162
|
+
renewsAt: account.renewsAt, priorityUntil: account.priorityUntil, 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
|
@@ -10,8 +10,10 @@ import { readTicketRevisionConflict, ticketErrorMessages, type TTicketClientErro
|
|
|
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';
|
|
13
|
+
import { assertPushResponse, assertPushWireRequest, isControllerMcpPushMethod, redactPushRequest } from './functions.pushwire.js';
|
|
13
14
|
import { fleetDeployRefreshClientMarginMs, fleetDeployRefreshWaitMs, type IFleetDeployOperations, type TFleetDeployOperation } from '../ts_interfaces/deployments.js';
|
|
14
15
|
import type { IReq_ControllerMcpSessionFeedAcknowledge, IReq_ControllerMcpSessionFeedList } from '../ts_interfaces/sessionfeed.js';
|
|
16
|
+
import type { IPushOperations, TControllerMcpPushMethod, TPushOperation } from '../ts_interfaces/push.js';
|
|
15
17
|
import { isProxyCapacityAnswer, type IProxyCapacityAnswer, type IProxyCapacityRequest } from '../ts_interfaces/proxycapacity.js';
|
|
16
18
|
import {
|
|
17
19
|
controllerMcpNativeDeliveries,
|
|
@@ -358,6 +360,10 @@ const assertResponsePayload = (
|
|
|
358
360
|
assertFleetDeployResponse(methodArg, valueArg);
|
|
359
361
|
return;
|
|
360
362
|
}
|
|
363
|
+
if (isControllerMcpPushMethod(methodArg)) {
|
|
364
|
+
assertPushResponse(methodArg, valueArg);
|
|
365
|
+
return;
|
|
366
|
+
}
|
|
361
367
|
if (methodArg.startsWith('agl.mcp.ticket.')) {
|
|
362
368
|
assertTicketResponse(methodArg, valueArg);
|
|
363
369
|
return;
|
|
@@ -790,6 +796,14 @@ export class ControllerMcpClient {
|
|
|
790
796
|
operation === 'refresh' ? Math.max(this.requestTimeoutMs, deployRefreshRequestTimeoutMs) : undefined,
|
|
791
797
|
) as Promise<IFleetDeployOperations[TOperation]['response']>;
|
|
792
798
|
}
|
|
799
|
+
/** The host's push settings as the local owner reads and changes them (`agl push`, AGL-1639). */
|
|
800
|
+
public async push<TOperation extends TPushOperation>(operation: TOperation,
|
|
801
|
+
request: IPushOperations[TOperation]['request'] & { ownerToken: string }, signal?: AbortSignal,
|
|
802
|
+
): Promise<IPushOperations[TOperation]['response']> {
|
|
803
|
+
const method = `agl.mcp.push.${operation}` as const;
|
|
804
|
+
const wireRequest = assertPushWireRequest(method, request);
|
|
805
|
+
return this.dispatchAfterHandshake(method as TControllerMcpPushMethod, wireRequest as never, signal, operation !== 'status') as Promise<IPushOperations[TOperation]['response']>;
|
|
806
|
+
}
|
|
793
807
|
public async fleetStatus(id: string, ownerToken: string, signal?: AbortSignal, ticketKey?: string): Promise<IFleetOperation> {
|
|
794
808
|
return this.dispatchAfterHandshake('agl.mcp.fleet.status', { id, ownerToken, ...(ticketKey ? { ticketKey } : {}) }, signal, false);
|
|
795
809
|
}
|
|
@@ -972,11 +986,12 @@ export class ControllerMcpClient {
|
|
|
972
986
|
|| decoded.method !== methodArg
|
|
973
987
|
|| !plugins.util.isDeepStrictEqual(
|
|
974
988
|
decoded.request,
|
|
975
|
-
(methodArg
|
|
976
|
-
|| methodArg.startsWith('agl.mcp.
|
|
977
|
-
|
|
978
|
-
...(
|
|
979
|
-
|
|
989
|
+
isControllerMcpPushMethod(methodArg) ? redactPushRequest(requestArg as Record<string, unknown>)
|
|
990
|
+
: (methodArg.startsWith('agl.mcp.configuration.') || methodArg.startsWith('agl.mcp.ticket.') || methodArg.startsWith('agl.mcp.fleet.')
|
|
991
|
+
|| methodArg.startsWith('agl.mcp.deploy.'))
|
|
992
|
+
? { ...requestArg, ...(Object.hasOwn(requestArg, 'ownerToken') ? { ownerToken: '[redacted]' } : {}),
|
|
993
|
+
...(methodArg === 'agl.mcp.configuration.master.save' ? { masterJson: '[redacted]' } : {}) }
|
|
994
|
+
: requestArg,
|
|
980
995
|
)
|
|
981
996
|
|| !controllerMcpValueIsRecord(decoded.response)
|
|
982
997
|
|| !controllerMcpValueIsRecord(decoded.correlation)
|
|
@@ -31,6 +31,8 @@ import type { IFleetOperation } from '../ts_interfaces/fleet.js';
|
|
|
31
31
|
import { controllerMcpTicketMethods, type TControllerMcpTicketTypedRequest } from '../ts_interfaces/requests.tickets.js';
|
|
32
32
|
import type { IReq_ControllerMcpSessionFeedAcknowledge, IReq_ControllerMcpSessionFeedList } from '../ts_interfaces/sessionfeed.js';
|
|
33
33
|
import { controllerMcpDeployMethods, type TControllerMcpDeployMethod, type TControllerMcpDeployTypedRequest } from '../ts_interfaces/deployments.js';
|
|
34
|
+
import { controllerMcpPushMethods, pushErrorCodes, type TControllerMcpPushMethod, type TControllerMcpPushTypedRequest } from '../ts_interfaces/push.js';
|
|
35
|
+
import { redactPushRequest } from './functions.pushwire.js';
|
|
34
36
|
import { deployErrorCodes } from './fleet/classes.deploymonitor.js';
|
|
35
37
|
import { readTicketRevisionConflict, ticketErrorMessages, type TTicketOperation, type TTicketRequest, type TTicketResponse } from '../ts_interfaces/tickets.js';
|
|
36
38
|
import { ticketOperation } from './functions.ticketvalidation.js';
|
|
@@ -94,6 +96,8 @@ export interface IControllerMcpPrivateApi {
|
|
|
94
96
|
fleet?: (method: string, request: Record<string, unknown>, signal: AbortSignal) => Promise<IFleetOperation>;
|
|
95
97
|
/** Deploy status, history, a probe now and release state for the local owner (`agl deploy`, `agl release status`). */
|
|
96
98
|
deploy?: (method: TControllerMcpDeployMethod, request: Record<string, unknown>, signal: AbortSignal) => Promise<unknown>;
|
|
99
|
+
/** The host's push settings for the local owner (`agl push`, AGL-1639); each call verifies the owner capability. */
|
|
100
|
+
push?: (method: TControllerMcpPushMethod, request: Record<string, unknown>, signal: AbortSignal) => Promise<unknown>;
|
|
97
101
|
/** A pool's room for new work in AGL's inference proxy, asked of the proxy (AGL-1097); open to every caller. */
|
|
98
102
|
proxyCapacity?: (request: IReq_ControllerMcpProxyCapacity['request'], signal: AbortSignal)
|
|
99
103
|
=> Promise<IReq_ControllerMcpProxyCapacity['response']>;
|
|
@@ -246,6 +250,11 @@ class ControllerMcpBoundedTypedRouter extends plugins.typedrequest.TypedRouter {
|
|
|
246
250
|
// and refuses anything else, an installed older one included. TypedRequest 9 answers `null` where TypedRequest 8
|
|
247
251
|
// returned the `{}` the client sent (an error, a handler that returns nothing), so the host restores it here.
|
|
248
252
|
if (response.response === null) (response as plugins.typedrequestInterfaces.ITypedRequest).response = {};
|
|
253
|
+
if (typeof response.method === 'string' && response.method.startsWith('agl.mcp.push.')
|
|
254
|
+
&& response.request && typeof response.request === 'object') {
|
|
255
|
+
// The owner capability and the push keys never travel back in the echo, including on rejected operations.
|
|
256
|
+
(response as plugins.typedrequestInterfaces.ITypedRequest).request = redactPushRequest(response.request as Record<string, unknown>);
|
|
257
|
+
}
|
|
249
258
|
if (typeof response.method === 'string' && (response.method.startsWith('agl.mcp.configuration.')
|
|
250
259
|
|| response.method.startsWith('agl.mcp.ticket.') || response.method.startsWith('agl.mcp.fleet.') || response.method.startsWith('agl.mcp.deploy.'))) {
|
|
251
260
|
// TypedRequest normally echoes the request. The owner capability must not travel back in
|
|
@@ -304,6 +313,10 @@ const safeTypedResponseError = (
|
|
|
304
313
|
if (methodArg.startsWith('agl.mcp.deploy.') && (deployErrorCodes as readonly unknown[]).includes(code)) {
|
|
305
314
|
return new plugins.typedrequest.TypedResponseError(errorArg.message.slice(0, 1024), { code });
|
|
306
315
|
}
|
|
316
|
+
// A push refusal's sentence names the field and the rule, never the input (`PushError`).
|
|
317
|
+
if (methodArg.startsWith('agl.mcp.push.') && (pushErrorCodes as readonly unknown[]).includes(code)) {
|
|
318
|
+
return new plugins.typedrequest.TypedResponseError(errorArg.message.slice(0, 1024), { code });
|
|
319
|
+
}
|
|
307
320
|
if (methodArg.startsWith('agl.mcp.fleet.worker.') && (fleetWorkerErrorCodes as readonly unknown[]).includes(code)) {
|
|
308
321
|
return new plugins.typedrequest.TypedResponseError(errorArg.message.slice(0, 1024), { code });
|
|
309
322
|
}
|
|
@@ -696,6 +709,13 @@ export class ControllerMcpHost {
|
|
|
696
709
|
return this.options.api.deploy(method, request as unknown as Record<string, unknown>, tools?.abortSignal ?? new AbortController().signal) as never;
|
|
697
710
|
})));
|
|
698
711
|
}
|
|
712
|
+
for (const method of controllerMcpPushMethods) {
|
|
713
|
+
routerArg.addTypedHandler(new plugins.typedrequest.TypedHandler<TControllerMcpPushTypedRequest>(method,
|
|
714
|
+
async (request, tools) => run(method, async () => {
|
|
715
|
+
if (!this.options.api.push) throw new Error('Push API is unavailable.');
|
|
716
|
+
return this.options.api.push(method, request as unknown as Record<string, unknown>, tools?.abortSignal ?? new AbortController().signal) as never;
|
|
717
|
+
})));
|
|
718
|
+
}
|
|
699
719
|
routerArg.addTypedHandler(new plugins.typedrequest.TypedHandler<IReq_ControllerMcpProxyCapacity>(
|
|
700
720
|
'agl.mcp.proxy.capacity', async (requestArg, toolsArg) => run('agl.mcp.proxy.capacity', async () => {
|
|
701
721
|
if (!this.options.api.proxyCapacity) throw new Error('Proxy capacity API is unavailable.');
|
|
@@ -28,6 +28,7 @@ import { assertMcpTicketRequest } from './functions.ticketvalidation.js';
|
|
|
28
28
|
import { assertFleetWireRequest } from './fleet/functions.validation.js';
|
|
29
29
|
import { assertSessionFeedWireRequest } from './functions.sessionfeedvalidation.js';
|
|
30
30
|
import { assertFleetDeployWireRequest } from './fleet/functions.deployvalidation.js';
|
|
31
|
+
import { assertPushWireRequest } from './functions.pushwire.js';
|
|
31
32
|
import { isProxyCapacityRequest } from '../ts_interfaces/proxycapacity.js';
|
|
32
33
|
|
|
33
34
|
const maximumIdBytes = 1024;
|
|
@@ -145,6 +146,7 @@ const assertMethodRequest = (
|
|
|
145
146
|
return assertSessionFeedWireRequest(methodArg, requestArg);
|
|
146
147
|
}
|
|
147
148
|
if (methodArg.startsWith('agl.mcp.deploy.')) return assertFleetDeployWireRequest(methodArg, requestArg);
|
|
149
|
+
if (methodArg.startsWith('agl.mcp.push.')) return assertPushWireRequest(methodArg, requestArg);
|
|
148
150
|
if (methodArg === 'agl.mcp.proxy.capacity') {
|
|
149
151
|
if (!isProxyCapacityRequest(requestArg)) throw new Error('Invalid private controller request.');
|
|
150
152
|
return requestArg;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { ControllerMcpClient } from './classes.mcpclient.js';
|
|
1
|
+
import { ControllerMcpClient, ControllerMcpClientError } from './classes.mcpclient.js';
|
|
2
2
|
import {
|
|
3
3
|
workerCallerLaunchIdEnvironmentVariable, workerCallerLaunchGenerationEnvironmentVariable,
|
|
4
4
|
type IWorkerCallerReadiness,
|
|
@@ -25,7 +25,13 @@ export class McpWorkerCaller {
|
|
|
25
25
|
if (this.closed) throw new Error('Worker caller enrollment is closed.');
|
|
26
26
|
return this.client.withCaller(response?.credential, undefined, operationArg);
|
|
27
27
|
}
|
|
28
|
-
if (nativeThreadIdArg === undefined)
|
|
28
|
+
if (nativeThreadIdArg === undefined) {
|
|
29
|
+
// Without a launch the controller identifies the bridge by the Claude job its parent runs (AGL-1888). A credential
|
|
30
|
+
// it answers with is the caller, never the one this process inherited; without one the call runs as before.
|
|
31
|
+
const credential = await this.enrollProcess();
|
|
32
|
+
if (this.closed) throw new Error('Worker caller enrollment is closed.');
|
|
33
|
+
return credential === undefined ? operationArg() : this.client.withCaller(credential, undefined, operationArg);
|
|
34
|
+
}
|
|
29
35
|
const response = await this.client.enrollWorker({ nativeThreadId: nativeThreadIdArg, bridgePid: process.pid });
|
|
30
36
|
if (this.closed) throw new Error('Worker caller enrollment is closed.');
|
|
31
37
|
return this.client.withCaller(response.credential, nativeThreadIdArg, operationArg);
|
|
@@ -44,4 +50,20 @@ export class McpWorkerCaller {
|
|
|
44
50
|
public close(): void {
|
|
45
51
|
this.closed = true;
|
|
46
52
|
}
|
|
53
|
+
|
|
54
|
+
/**
|
|
55
|
+
* The credential the controller answers a process enrollment with, if any. A controller that rejects the request
|
|
56
|
+
* (one older than process enrollment answers HTTP 400, read as `PROTOCOL_MISMATCH`) or fails it (`REQUEST_FAILED`)
|
|
57
|
+
* leaves the bridge as it was; every other failure is the call's own, as it would be without the enrollment.
|
|
58
|
+
*/
|
|
59
|
+
private async enrollProcess(): Promise<string | undefined> {
|
|
60
|
+
try {
|
|
61
|
+
return (await this.client.enrollWorker({ bridgePid: process.pid })).credential;
|
|
62
|
+
} catch (errorArg) {
|
|
63
|
+
if (errorArg instanceof ControllerMcpClientError && (errorArg.code === 'PROTOCOL_MISMATCH' || errorArg.code === 'REQUEST_FAILED')) {
|
|
64
|
+
return undefined;
|
|
65
|
+
}
|
|
66
|
+
throw errorArg;
|
|
67
|
+
}
|
|
68
|
+
}
|
|
47
69
|
}
|