@sentropic/h2a-runtime 0.91.1 → 0.93.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/dist/config.d.ts +2 -0
- package/dist/config.d.ts.map +1 -1
- package/dist/config.js +16 -3
- package/dist/config.js.map +1 -1
- package/dist/conv-guard.d.ts +6 -1
- package/dist/conv-guard.d.ts.map +1 -1
- package/dist/conv-guard.js +33 -8
- package/dist/conv-guard.js.map +1 -1
- package/dist/enroll.d.ts.map +1 -1
- package/dist/enroll.js +12 -2
- package/dist/enroll.js.map +1 -1
- package/dist/index.d.ts +3 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +819 -155
- package/dist/index.js.map +1 -1
- package/dist/launch-layout.d.ts +74 -0
- package/dist/launch-layout.d.ts.map +1 -0
- package/dist/launch-layout.js +324 -0
- package/dist/launch-layout.js.map +1 -0
- package/dist/llm-gateway-runtime/index.d.ts +6 -0
- package/dist/llm-gateway-runtime/index.d.ts.map +1 -1
- package/dist/llm-gateway-runtime/index.js +134 -60
- package/dist/llm-gateway-runtime/index.js.map +1 -1
- package/dist/llm-gateway-runtime/session-ledger.d.ts +38 -55
- package/dist/llm-gateway-runtime/session-ledger.d.ts.map +1 -1
- package/dist/llm-gateway-runtime/session-ledger.js +102 -250
- package/dist/llm-gateway-runtime/session-ledger.js.map +1 -1
- package/dist/llm-gateway-runtime/sticky.d.ts +25 -52
- package/dist/llm-gateway-runtime/sticky.d.ts.map +1 -1
- package/dist/llm-gateway-runtime/sticky.js +36 -605
- package/dist/llm-gateway-runtime/sticky.js.map +1 -1
- package/dist/llm-mesh.d.ts +19 -72
- package/dist/llm-mesh.d.ts.map +1 -1
- package/dist/llm-mesh.js +42 -399
- package/dist/llm-mesh.js.map +1 -1
- package/dist/llm-routing-config.d.ts +28 -0
- package/dist/llm-routing-config.d.ts.map +1 -0
- package/dist/llm-routing-config.js +100 -0
- package/dist/llm-routing-config.js.map +1 -0
- package/dist/native-host.d.ts +146 -0
- package/dist/native-host.d.ts.map +1 -0
- package/dist/native-host.js +456 -0
- package/dist/native-host.js.map +1 -0
- package/dist/native-terminal/host.d.ts +317 -1
- package/dist/native-terminal/host.d.ts.map +1 -1
- package/dist/native-terminal/host.js +696 -3
- package/dist/native-terminal/host.js.map +1 -1
- package/dist/native-terminal/op.d.ts +5 -0
- package/dist/native-terminal/op.d.ts.map +1 -0
- package/dist/native-terminal/op.js +408 -0
- package/dist/native-terminal/op.js.map +1 -0
- package/dist/native-terminal/process.d.ts +2 -0
- package/dist/native-terminal/process.d.ts.map +1 -1
- package/dist/native-terminal/process.js +16 -2
- package/dist/native-terminal/process.js.map +1 -1
- package/dist/native-terminal/server.d.ts.map +1 -1
- package/dist/native-terminal/server.js +6 -2
- package/dist/native-terminal/server.js.map +1 -1
- package/dist/native-terminal/socket-path.d.ts +8 -0
- package/dist/native-terminal/socket-path.d.ts.map +1 -1
- package/dist/native-terminal/socket-path.js +31 -1
- package/dist/native-terminal/socket-path.js.map +1 -1
- package/dist/native-terminal/supervisor.d.ts +13 -0
- package/dist/native-terminal/supervisor.d.ts.map +1 -1
- package/dist/native-terminal/supervisor.js +45 -0
- package/dist/native-terminal/supervisor.js.map +1 -1
- package/dist/pty.d.ts +23 -0
- package/dist/pty.d.ts.map +1 -1
- package/dist/pty.js +35 -0
- package/dist/pty.js.map +1 -1
- package/dist/readiness.d.ts +7 -0
- package/dist/readiness.d.ts.map +1 -1
- package/dist/readiness.js +12 -9
- package/dist/readiness.js.map +1 -1
- package/dist/registry.d.ts +324 -2
- package/dist/registry.d.ts.map +1 -1
- package/dist/registry.js +659 -20
- package/dist/registry.js.map +1 -1
- package/dist/restore.d.ts +91 -32
- package/dist/restore.d.ts.map +1 -1
- package/dist/restore.js +226 -186
- package/dist/restore.js.map +1 -1
- package/dist/status-projection.d.ts.map +1 -1
- package/dist/tmux.d.ts +9 -6
- package/dist/tmux.d.ts.map +1 -1
- package/dist/tmux.js +34 -8
- package/dist/tmux.js.map +1 -1
- package/package.json +3 -3
- package/dist/llm-gateway-runtime/accounts.d.ts +0 -62
- package/dist/llm-gateway-runtime/accounts.d.ts.map +0 -1
- package/dist/llm-gateway-runtime/accounts.js +0 -323
- package/dist/llm-gateway-runtime/accounts.js.map +0 -1
- package/dist/llm-gateway-runtime/model-catalog.d.ts +0 -44
- package/dist/llm-gateway-runtime/model-catalog.d.ts.map +0 -1
- package/dist/llm-gateway-runtime/model-catalog.js +0 -191
- package/dist/llm-gateway-runtime/model-catalog.js.map +0 -1
- package/dist/llm-gateway-runtime/proxy-anthropic.d.ts +0 -3
- package/dist/llm-gateway-runtime/proxy-anthropic.d.ts.map +0 -1
- package/dist/llm-gateway-runtime/proxy-anthropic.js +0 -318
- package/dist/llm-gateway-runtime/proxy-anthropic.js.map +0 -1
- package/dist/llm-gateway-runtime/proxy-cloud-code.d.ts +0 -11
- package/dist/llm-gateway-runtime/proxy-cloud-code.d.ts.map +0 -1
- package/dist/llm-gateway-runtime/proxy-cloud-code.js +0 -215
- package/dist/llm-gateway-runtime/proxy-cloud-code.js.map +0 -1
- package/dist/llm-gateway-runtime/proxy-openai.d.ts +0 -118
- package/dist/llm-gateway-runtime/proxy-openai.d.ts.map +0 -1
- package/dist/llm-gateway-runtime/proxy-openai.js +0 -1305
- package/dist/llm-gateway-runtime/proxy-openai.js.map +0 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/llm-gateway-runtime/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/llm-gateway-runtime/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AACzC,OAAO,EAAE,KAAK,EAAE,MAAM,mBAAmB,CAAC;AAC1C,OAAO,EACL,sBAAsB,EACtB,kBAAkB,EAClB,aAAa,EACb,aAAa,EACb,aAAa,EACb,sBAAsB,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AAG,MAAM,CAAC,QAAQ,CAAC,OAAO,CAAC,GAAG,CAAC,IAAI,IAAI,MAAM,EAAE,EAAE,CAAC,CAAC;IAC7D,0EAA0E;IAC1E,sEAAsE;IACtE,KAAK,CAAC,EAAE,KAAK,EAAE,GAAG,CAAC,KAAK,EAAE,IAAI,EAAE,QAAQ,EAAE,WAAW,EAAE,EAAE,GAAG,EAAE;QAC5D,OAAO,CAAC,MAAM,CAAC,KAAK,CAClB,+BAA+B,IAAI,MAAM,YAAY,EAAE,kBAAkB,CAC1E,CAAC;IACJ,CAAC,CAAC,CAAC;AACL,CAAC;AAED,IAAI,OAAO,CAAC,GAAG,CAAC,QAAQ,KAAK,MAAM;IAAE,WAAW,EAAE,CAAC"}
|
|
@@ -1,66 +1,49 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
import {
|
|
3
|
-
import type {
|
|
1
|
+
import type { RoutePlan, RoutePlanInput } from "@sentropic/llm-mesh";
|
|
2
|
+
import type { RouteRequestSettlement } from "@sentropic/llm-gateway";
|
|
3
|
+
import type { SessionEntry } from "./sticky.js";
|
|
4
4
|
export type GatewaySessionState = "idle" | "active" | "rate-limited";
|
|
5
|
+
export interface PublicAccountDescriptor {
|
|
6
|
+
/** Redacted mesh diagnostic reference, never an executable account id. */
|
|
7
|
+
readonly id: string;
|
|
8
|
+
readonly provider: string;
|
|
9
|
+
readonly label: string;
|
|
10
|
+
}
|
|
5
11
|
export interface GatewayRateLimitSnapshot {
|
|
6
|
-
at: string;
|
|
7
|
-
account: PublicAccountDescriptor;
|
|
8
|
-
retryAfterMs?: number;
|
|
12
|
+
readonly at: string;
|
|
13
|
+
readonly account: PublicAccountDescriptor;
|
|
14
|
+
readonly retryAfterMs?: number;
|
|
9
15
|
}
|
|
10
16
|
export interface GatewayFallbackSnapshot {
|
|
11
|
-
at: string;
|
|
12
|
-
from: PublicAccountDescriptor;
|
|
13
|
-
to: PublicAccountDescriptor;
|
|
17
|
+
readonly at: string;
|
|
18
|
+
readonly from: PublicAccountDescriptor;
|
|
19
|
+
readonly to: PublicAccountDescriptor;
|
|
14
20
|
}
|
|
15
21
|
export interface SessionLedgerEntry {
|
|
16
|
-
gatewaySessionId: string;
|
|
17
|
-
clientSessionId: string;
|
|
18
|
-
workspaceId?: string;
|
|
19
|
-
profile?: string;
|
|
20
|
-
account: PublicAccountDescriptor;
|
|
21
|
-
transport:
|
|
22
|
-
state: GatewaySessionState;
|
|
23
|
-
requestedModel?: string;
|
|
24
|
-
modelId?: string;
|
|
25
|
-
upstreamModel?: string;
|
|
26
|
-
routePolicy?: string;
|
|
27
|
-
routeReason?: string;
|
|
28
|
-
createdAt: string;
|
|
29
|
-
lastUsedAt: string;
|
|
30
|
-
updatedAt: string;
|
|
31
|
-
requestCount: number;
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
lastRateLimit?: GatewayRateLimitSnapshot;
|
|
37
|
-
/** Recorded only after a rebind actually succeeds; never inferred from account changes. */
|
|
38
|
-
lastFallback?: GatewayFallbackSnapshot;
|
|
39
|
-
}
|
|
40
|
-
export interface UpsertSessionLedgerInput {
|
|
41
|
-
gatewaySessionId: string;
|
|
42
|
-
clientSessionId?: string;
|
|
43
|
-
workspaceId?: string;
|
|
44
|
-
profile?: string;
|
|
45
|
-
account: AccountDescriptor;
|
|
46
|
-
route?: RoutingTarget;
|
|
47
|
-
now?: Date;
|
|
22
|
+
readonly gatewaySessionId: string;
|
|
23
|
+
readonly clientSessionId: string;
|
|
24
|
+
readonly workspaceId?: string;
|
|
25
|
+
readonly profile?: string;
|
|
26
|
+
readonly account: PublicAccountDescriptor;
|
|
27
|
+
readonly transport: string;
|
|
28
|
+
readonly state: GatewaySessionState;
|
|
29
|
+
readonly requestedModel?: string;
|
|
30
|
+
readonly modelId?: string;
|
|
31
|
+
readonly upstreamModel?: string;
|
|
32
|
+
readonly routePolicy?: string;
|
|
33
|
+
readonly routeReason?: string;
|
|
34
|
+
readonly createdAt: string;
|
|
35
|
+
readonly lastUsedAt: string;
|
|
36
|
+
readonly updatedAt: string;
|
|
37
|
+
readonly requestCount: number;
|
|
38
|
+
readonly inFlightRequests: number;
|
|
39
|
+
readonly detailsAmbiguous: boolean;
|
|
40
|
+
readonly lastRateLimit?: GatewayRateLimitSnapshot;
|
|
41
|
+
readonly lastFallback?: GatewayFallbackSnapshot;
|
|
48
42
|
}
|
|
49
|
-
export declare function
|
|
50
|
-
export declare function
|
|
51
|
-
export declare function recordSessionActive(gatewaySessionId: string | undefined, route?: RoutingTarget, now?: Date): SessionLedgerEntry | undefined;
|
|
52
|
-
export declare function recordSessionIdle(gatewaySessionId: string | undefined, route?: RoutingTarget, now?: Date): SessionLedgerEntry | undefined;
|
|
53
|
-
export declare function recordSessionFallback(gatewaySessionId: string | undefined, from: AccountDescriptor, to: AccountDescriptor, route?: RoutingTarget, now?: Date): SessionLedgerEntry | undefined;
|
|
54
|
-
export declare function recordSessionRateLimited(gatewaySessionId: string | undefined, account: AccountDescriptor, options?: {
|
|
55
|
-
route?: RoutingTarget;
|
|
56
|
-
retryAfterMs?: number;
|
|
57
|
-
now?: Date;
|
|
58
|
-
}): SessionLedgerEntry | undefined;
|
|
59
|
-
/** Complete a terminal 429 after fallback selection/rebind has failed. */
|
|
60
|
-
export declare function recordSessionRateLimitComplete(gatewaySessionId: string | undefined, route?: RoutingTarget, now?: Date): SessionLedgerEntry | undefined;
|
|
43
|
+
export declare function recordRoutePlan(session: SessionEntry, input: RoutePlanInput, plan: RoutePlan, now?: Date): void;
|
|
44
|
+
export declare function recordRouteSettlement(settlement: RouteRequestSettlement, now?: Date): void;
|
|
61
45
|
export declare function listSessionLedger(): SessionLedgerEntry[];
|
|
62
|
-
export declare function getSessionLedgerEntry(
|
|
63
|
-
/** O(1) lookup for the exact client/tmux session status endpoint. */
|
|
46
|
+
export declare function getSessionLedgerEntry(sessionId: string): SessionLedgerEntry | undefined;
|
|
64
47
|
export declare function getSessionLedgerEntryForClient(clientSessionId: string): SessionLedgerEntry | undefined;
|
|
65
48
|
export declare function resetSessionLedger(): void;
|
|
66
49
|
//# sourceMappingURL=session-ledger.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"session-ledger.d.ts","sourceRoot":"","sources":["../../src/llm-gateway-runtime/session-ledger.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,
|
|
1
|
+
{"version":3,"file":"session-ledger.d.ts","sourceRoot":"","sources":["../../src/llm-gateway-runtime/session-ledger.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAEV,SAAS,EACT,cAAc,EACf,MAAM,qBAAqB,CAAC;AAC7B,OAAO,KAAK,EAAE,sBAAsB,EAAE,MAAM,wBAAwB,CAAC;AACrE,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAEhD,MAAM,MAAM,mBAAmB,GAAG,MAAM,GAAG,QAAQ,GAAG,cAAc,CAAC;AAErE,MAAM,WAAW,uBAAuB;IACtC,0EAA0E;IAC1E,QAAQ,CAAC,EAAE,EAAE,MAAM,CAAC;IACpB,QAAQ,CAAC,QAAQ,EAAE,MAAM,CAAC;IAC1B,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAC;CACxB;AAED,MAAM,WAAW,wBAAwB;IACvC,QAAQ,CAAC,EAAE,EAAE,MAAM,CAAC;IACpB,QAAQ,CAAC,OAAO,EAAE,uBAAuB,CAAC;IAC1C,QAAQ,CAAC,YAAY,CAAC,EAAE,MAAM,CAAC;CAChC;AAED,MAAM,WAAW,uBAAuB;IACtC,QAAQ,CAAC,EAAE,EAAE,MAAM,CAAC;IACpB,QAAQ,CAAC,IAAI,EAAE,uBAAuB,CAAC;IACvC,QAAQ,CAAC,EAAE,EAAE,uBAAuB,CAAC;CACtC;AAED,MAAM,WAAW,kBAAkB;IACjC,QAAQ,CAAC,gBAAgB,EAAE,MAAM,CAAC;IAClC,QAAQ,CAAC,eAAe,EAAE,MAAM,CAAC;IACjC,QAAQ,CAAC,WAAW,CAAC,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BAAkB,GAAG,SAAS,CAGhC;AAED,wBAAgB,kBAAkB,IAAI,IAAI,CAIzC"}
|
|
@@ -1,272 +1,124 @@
|
|
|
1
|
-
|
|
2
|
-
const
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
const
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
const
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
function refreshFreshestClientIndex(clientSessionId) {
|
|
24
|
-
const ids = _ledgerByClientSessionId.get(clientSessionId);
|
|
25
|
-
if (!ids || ids.size === 0) {
|
|
26
|
-
_freshestGatewayByClientSessionId.delete(clientSessionId);
|
|
27
|
-
return;
|
|
28
|
-
}
|
|
29
|
-
let freshest;
|
|
30
|
-
let tied = false;
|
|
31
|
-
for (const id of ids) {
|
|
32
|
-
const entry = _ledger.get(id);
|
|
33
|
-
if (!entry)
|
|
34
|
-
continue;
|
|
35
|
-
if (!freshest || entry.updatedAt > freshest.updatedAt) {
|
|
36
|
-
freshest = entry;
|
|
37
|
-
tied = false;
|
|
38
|
-
}
|
|
39
|
-
else if (entry.updatedAt === freshest.updatedAt) {
|
|
40
|
-
tied = true;
|
|
41
|
-
}
|
|
42
|
-
}
|
|
43
|
-
_freshestGatewayByClientSessionId.set(clientSessionId, !freshest || tied ? undefined : freshest.gatewaySessionId);
|
|
44
|
-
}
|
|
45
|
-
function setLedgerEntry(entry) {
|
|
46
|
-
_ledger.set(entry.gatewaySessionId, entry);
|
|
47
|
-
refreshFreshestClientIndex(entry.clientSessionId);
|
|
48
|
-
}
|
|
49
|
-
function timestamp(now = new Date()) {
|
|
50
|
-
return now.toISOString();
|
|
51
|
-
}
|
|
52
|
-
function routeFields(route) {
|
|
53
|
-
if (!route)
|
|
54
|
-
return {};
|
|
55
|
-
return {
|
|
56
|
-
...(route.requestedModel ? { requestedModel: route.requestedModel } : {}),
|
|
57
|
-
...(route.catalogModelId ? { modelId: route.catalogModelId } : {}),
|
|
58
|
-
...(route.upstreamModel ? { upstreamModel: route.upstreamModel } : {}),
|
|
59
|
-
routePolicy: route.routingPolicy,
|
|
60
|
-
routeReason: route.routeReason,
|
|
61
|
-
};
|
|
62
|
-
}
|
|
63
|
-
function existingRouteFields(entry) {
|
|
64
|
-
if (!entry)
|
|
65
|
-
return {};
|
|
66
|
-
return {
|
|
67
|
-
...(entry.requestedModel ? { requestedModel: entry.requestedModel } : {}),
|
|
68
|
-
...(entry.modelId ? { modelId: entry.modelId } : {}),
|
|
69
|
-
...(entry.upstreamModel ? { upstreamModel: entry.upstreamModel } : {}),
|
|
70
|
-
...(entry.routePolicy ? { routePolicy: entry.routePolicy } : {}),
|
|
71
|
-
...(entry.routeReason ? { routeReason: entry.routeReason } : {}),
|
|
72
|
-
};
|
|
73
|
-
}
|
|
74
|
-
export function upsertSessionLedger(input) {
|
|
75
|
-
const now = timestamp(input.now);
|
|
76
|
-
const existing = _ledger.get(input.gatewaySessionId);
|
|
77
|
-
const workspaceId = input.workspaceId ?? existing?.workspaceId;
|
|
78
|
-
const profile = input.profile ?? existing?.profile;
|
|
79
|
-
const account = publicAccountDescriptor(input.account);
|
|
80
|
-
const entry = {
|
|
81
|
-
gatewaySessionId: input.gatewaySessionId,
|
|
82
|
-
clientSessionId: input.clientSessionId ??
|
|
83
|
-
existing?.clientSessionId ??
|
|
84
|
-
input.gatewaySessionId,
|
|
85
|
-
...(workspaceId ? { workspaceId } : {}),
|
|
86
|
-
...(profile ? { profile } : {}),
|
|
87
|
-
account,
|
|
88
|
-
transport: upstreamTransportForAccount(input.account),
|
|
89
|
-
state: existing?.state ?? "idle",
|
|
90
|
-
// Acquiring (or re-acquiring) a gateway session only selects a possible
|
|
91
|
-
// route. It is not evidence that a request using that route left the
|
|
92
|
-
// gateway. Route fields are written exclusively by the dispatch lifecycle.
|
|
93
|
-
...existingRouteFields(existing),
|
|
94
|
-
createdAt: existing?.createdAt ?? now,
|
|
95
|
-
lastUsedAt: now,
|
|
96
|
-
updatedAt: now,
|
|
97
|
-
requestCount: existing?.requestCount ?? 0,
|
|
98
|
-
inFlightRequests: existing?.inFlightRequests ?? 0,
|
|
99
|
-
detailsAmbiguous: existing?.detailsAmbiguous ?? false,
|
|
100
|
-
...(existing?.lastRateLimit
|
|
101
|
-
? { lastRateLimit: existing.lastRateLimit }
|
|
102
|
-
: {}),
|
|
103
|
-
...(existing?.lastFallback ? { lastFallback: existing.lastFallback } : {}),
|
|
104
|
-
};
|
|
105
|
-
_ledger.set(entry.gatewaySessionId, entry);
|
|
106
|
-
if (existing && existing.clientSessionId !== entry.clientSessionId &&
|
|
107
|
-
_ledgerByClientSessionId.has(existing.clientSessionId)) {
|
|
108
|
-
removeClientIndex(existing.clientSessionId, entry.gatewaySessionId);
|
|
109
|
-
}
|
|
110
|
-
addClientIndex(entry.clientSessionId, entry.gatewaySessionId);
|
|
111
|
-
refreshFreshestClientIndex(entry.clientSessionId);
|
|
112
|
-
if (existing && existing.clientSessionId !== entry.clientSessionId) {
|
|
113
|
-
refreshFreshestClientIndex(existing.clientSessionId);
|
|
114
|
-
}
|
|
115
|
-
return entry;
|
|
116
|
-
}
|
|
117
|
-
export function recordSessionRequest(gatewaySessionId, route, now = new Date()) {
|
|
118
|
-
if (!gatewaySessionId)
|
|
119
|
-
return undefined;
|
|
120
|
-
const existing = _ledger.get(gatewaySessionId);
|
|
121
|
-
if (!existing)
|
|
122
|
-
return undefined;
|
|
123
|
-
const withoutRoute = { ...existing };
|
|
124
|
-
delete withoutRoute.requestedModel;
|
|
125
|
-
delete withoutRoute.modelId;
|
|
126
|
-
delete withoutRoute.upstreamModel;
|
|
127
|
-
delete withoutRoute.routePolicy;
|
|
128
|
-
delete withoutRoute.routeReason;
|
|
129
|
-
delete withoutRoute.lastFallback;
|
|
130
|
-
const detailsAmbiguous = existing.inFlightRequests > 0;
|
|
1
|
+
const ledger = new Map();
|
|
2
|
+
const byClientSession = new Map();
|
|
3
|
+
const plansByCandidate = new Map();
|
|
4
|
+
const unselectedAccount = (provider = "mesh") => ({
|
|
5
|
+
id: "unselected",
|
|
6
|
+
provider,
|
|
7
|
+
label: "unselected",
|
|
8
|
+
});
|
|
9
|
+
const accountFromDiagnostic = (diagnostic) => ({
|
|
10
|
+
id: diagnostic.diagnosticAccountRef,
|
|
11
|
+
provider: diagnostic.actualProviderId,
|
|
12
|
+
label: diagnostic.diagnosticAccountRef,
|
|
13
|
+
});
|
|
14
|
+
export function recordRoutePlan(session, input, plan, now = new Date()) {
|
|
15
|
+
const diagnostics = new Map(plan.diagnostics.map((value) => [value.candidateRef, value]));
|
|
16
|
+
const request = { session, input, plan, diagnostics };
|
|
17
|
+
for (const candidateRef of plan.candidateRefs)
|
|
18
|
+
plansByCandidate.set(candidateRef, request);
|
|
19
|
+
const at = now.toISOString();
|
|
20
|
+
const existing = ledger.get(session.sessionId);
|
|
21
|
+
const first = plan.diagnostics[0];
|
|
22
|
+
const detailsAmbiguous = (existing?.inFlightRequests ?? 0) > 0;
|
|
131
23
|
const entry = {
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
detailsAmbiguous,
|
|
140
|
-
};
|
|
141
|
-
setLedgerEntry(entry);
|
|
142
|
-
return entry;
|
|
143
|
-
}
|
|
144
|
-
export function recordSessionActive(gatewaySessionId, route, now = new Date()) {
|
|
145
|
-
if (!gatewaySessionId)
|
|
146
|
-
return undefined;
|
|
147
|
-
const existing = _ledger.get(gatewaySessionId);
|
|
148
|
-
if (!existing)
|
|
149
|
-
return undefined;
|
|
150
|
-
const entry = {
|
|
151
|
-
...existing,
|
|
152
|
-
...(existing.detailsAmbiguous ? {} : routeFields(route)),
|
|
153
|
-
state: "active",
|
|
154
|
-
lastUsedAt: timestamp(now),
|
|
155
|
-
updatedAt: timestamp(now),
|
|
156
|
-
};
|
|
157
|
-
setLedgerEntry(entry);
|
|
158
|
-
return entry;
|
|
159
|
-
}
|
|
160
|
-
export function recordSessionIdle(gatewaySessionId, route, now = new Date()) {
|
|
161
|
-
if (!gatewaySessionId)
|
|
162
|
-
return undefined;
|
|
163
|
-
const existing = _ledger.get(gatewaySessionId);
|
|
164
|
-
if (!existing)
|
|
165
|
-
return undefined;
|
|
166
|
-
const inFlightRequests = Math.max(0, existing.inFlightRequests - 1);
|
|
167
|
-
const entry = {
|
|
168
|
-
...existing,
|
|
169
|
-
...(existing.detailsAmbiguous ? {} : routeFields(route)),
|
|
170
|
-
state: inFlightRequests > 0 ? "active" : "idle",
|
|
171
|
-
lastUsedAt: timestamp(now),
|
|
172
|
-
updatedAt: timestamp(now),
|
|
173
|
-
inFlightRequests,
|
|
174
|
-
};
|
|
175
|
-
setLedgerEntry(entry);
|
|
176
|
-
return entry;
|
|
177
|
-
}
|
|
178
|
-
export function recordSessionFallback(gatewaySessionId, from, to, route, now = new Date()) {
|
|
179
|
-
if (!gatewaySessionId)
|
|
180
|
-
return undefined;
|
|
181
|
-
const existing = _ledger.get(gatewaySessionId);
|
|
182
|
-
if (!existing)
|
|
183
|
-
return undefined;
|
|
184
|
-
const at = timestamp(now);
|
|
185
|
-
const entry = {
|
|
186
|
-
...existing,
|
|
187
|
-
// The caller passes a route only after its first actual dispatch. A
|
|
188
|
-
// rebind may then retain that already-observed route while it updates the
|
|
189
|
-
// account, but cannot manufacture a new one.
|
|
190
|
-
...(existing.detailsAmbiguous || !route ? {} : routeFields(route)),
|
|
191
|
-
account: publicAccountDescriptor(to),
|
|
192
|
-
transport: upstreamTransportForAccount(to),
|
|
24
|
+
gatewaySessionId: session.sessionId,
|
|
25
|
+
clientSessionId: session.clientSessionId,
|
|
26
|
+
...(session.workspaceId ? { workspaceId: session.workspaceId } : {}),
|
|
27
|
+
...(session.profile ? { profile: session.profile } : {}),
|
|
28
|
+
account: detailsAmbiguous || !first
|
|
29
|
+
? unselectedAccount()
|
|
30
|
+
: accountFromDiagnostic(first),
|
|
31
|
+
transport: detailsAmbiguous || !first ? "mesh" : first.actualTransportProviderId,
|
|
193
32
|
state: "active",
|
|
33
|
+
...(detailsAmbiguous ? {} : {
|
|
34
|
+
requestedModel: input.requestedModel,
|
|
35
|
+
...(first ? {
|
|
36
|
+
modelId: first.actualModelId,
|
|
37
|
+
upstreamModel: first.actualModelId,
|
|
38
|
+
routeReason: first.reason,
|
|
39
|
+
} : {}),
|
|
40
|
+
routePolicy: plan.policy.strategy.kind,
|
|
41
|
+
}),
|
|
42
|
+
createdAt: existing?.createdAt ?? at,
|
|
194
43
|
lastUsedAt: at,
|
|
195
44
|
updatedAt: at,
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
from: publicAccountDescriptor(from),
|
|
202
|
-
to: publicAccountDescriptor(to),
|
|
203
|
-
},
|
|
204
|
-
}),
|
|
205
|
-
};
|
|
206
|
-
setLedgerEntry(entry);
|
|
207
|
-
return entry;
|
|
208
|
-
}
|
|
209
|
-
export function recordSessionRateLimited(gatewaySessionId, account, options = {}) {
|
|
210
|
-
if (!gatewaySessionId)
|
|
211
|
-
return undefined;
|
|
212
|
-
const existing = _ledger.get(gatewaySessionId);
|
|
213
|
-
if (!existing)
|
|
214
|
-
return undefined;
|
|
215
|
-
const now = timestamp(options.now);
|
|
216
|
-
const rateLimit = {
|
|
217
|
-
at: now,
|
|
218
|
-
account: publicAccountDescriptor(account),
|
|
219
|
-
...(options.retryAfterMs !== undefined
|
|
220
|
-
? { retryAfterMs: options.retryAfterMs }
|
|
221
|
-
: {}),
|
|
222
|
-
};
|
|
223
|
-
const entry = {
|
|
224
|
-
...existing,
|
|
225
|
-
...(existing.detailsAmbiguous || !options.route
|
|
226
|
-
? {}
|
|
227
|
-
: routeFields(options.route)),
|
|
228
|
-
state: existing.inFlightRequests > 1 ? "active" : "rate-limited",
|
|
229
|
-
lastUsedAt: now,
|
|
230
|
-
updatedAt: now,
|
|
231
|
-
lastRateLimit: rateLimit,
|
|
45
|
+
requestCount: (existing?.requestCount ?? 0) + 1,
|
|
46
|
+
inFlightRequests: (existing?.inFlightRequests ?? 0) + 1,
|
|
47
|
+
detailsAmbiguous,
|
|
48
|
+
...(existing?.lastRateLimit ? { lastRateLimit: existing.lastRateLimit } : {}),
|
|
49
|
+
...(existing?.lastFallback ? { lastFallback: existing.lastFallback } : {}),
|
|
232
50
|
};
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
}
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
const existing =
|
|
51
|
+
ledger.set(session.sessionId, entry);
|
|
52
|
+
byClientSession.set(session.clientSessionId, session.sessionId);
|
|
53
|
+
}
|
|
54
|
+
export function recordRouteSettlement(settlement, now = new Date()) {
|
|
55
|
+
const lastAttempt = settlement.attempts.at(-1);
|
|
56
|
+
const planned = lastAttempt ? plansByCandidate.get(lastAttempt.candidateRef) : undefined;
|
|
57
|
+
const sessionId = planned?.session.sessionId ?? settlement.cost.principalId;
|
|
58
|
+
const existing = ledger.get(sessionId);
|
|
241
59
|
if (!existing)
|
|
242
|
-
return
|
|
60
|
+
return;
|
|
61
|
+
const diagnostic = lastAttempt ? planned?.diagnostics.get(lastAttempt.candidateRef) : undefined;
|
|
62
|
+
const at = now.toISOString();
|
|
243
63
|
const inFlightRequests = Math.max(0, existing.inFlightRequests - 1);
|
|
244
|
-
const
|
|
64
|
+
const rateLimited = lastAttempt?.outcome === "rate-limited";
|
|
65
|
+
const detailsAmbiguous = inFlightRequests > 0;
|
|
66
|
+
const account = diagnostic ? accountFromDiagnostic(diagnostic) : existing.account;
|
|
67
|
+
const firstAttempt = settlement.attempts[0];
|
|
68
|
+
const firstDiagnostic = firstAttempt
|
|
69
|
+
? planned?.diagnostics.get(firstAttempt.candidateRef)
|
|
70
|
+
: undefined;
|
|
71
|
+
const fallback = firstDiagnostic && diagnostic
|
|
72
|
+
&& firstDiagnostic.candidateRef !== diagnostic.candidateRef
|
|
73
|
+
? {
|
|
74
|
+
at,
|
|
75
|
+
from: accountFromDiagnostic(firstDiagnostic),
|
|
76
|
+
to: account,
|
|
77
|
+
}
|
|
78
|
+
: undefined;
|
|
245
79
|
const entry = {
|
|
246
80
|
...existing,
|
|
247
|
-
|
|
248
|
-
|
|
81
|
+
account: detailsAmbiguous ? unselectedAccount() : account,
|
|
82
|
+
transport: detailsAmbiguous
|
|
83
|
+
? "mesh"
|
|
84
|
+
: diagnostic?.actualTransportProviderId ?? existing.transport,
|
|
85
|
+
state: inFlightRequests > 0 ? "active" : rateLimited ? "rate-limited" : "idle",
|
|
86
|
+
...(detailsAmbiguous ? {} : {
|
|
87
|
+
requestedModel: settlement.requestedModel,
|
|
88
|
+
...(diagnostic ? {
|
|
89
|
+
modelId: diagnostic.actualModelId,
|
|
90
|
+
upstreamModel: diagnostic.actualModelId,
|
|
91
|
+
routeReason: diagnostic.reason,
|
|
92
|
+
} : {}),
|
|
93
|
+
}),
|
|
249
94
|
lastUsedAt: at,
|
|
250
95
|
updatedAt: at,
|
|
251
96
|
inFlightRequests,
|
|
97
|
+
detailsAmbiguous,
|
|
98
|
+
...(rateLimited ? {
|
|
99
|
+
lastRateLimit: { at, account },
|
|
100
|
+
} : {}),
|
|
101
|
+
...(fallback ? { lastFallback: fallback } : {}),
|
|
252
102
|
};
|
|
253
|
-
|
|
254
|
-
|
|
103
|
+
ledger.set(sessionId, entry);
|
|
104
|
+
if (planned) {
|
|
105
|
+
for (const candidateRef of planned.plan.candidateRefs)
|
|
106
|
+
plansByCandidate.delete(candidateRef);
|
|
107
|
+
}
|
|
255
108
|
}
|
|
256
109
|
export function listSessionLedger() {
|
|
257
|
-
return [...
|
|
110
|
+
return [...ledger.values()].sort((a, b) => a.createdAt.localeCompare(b.createdAt));
|
|
258
111
|
}
|
|
259
|
-
export function getSessionLedgerEntry(
|
|
260
|
-
return
|
|
112
|
+
export function getSessionLedgerEntry(sessionId) {
|
|
113
|
+
return ledger.get(sessionId);
|
|
261
114
|
}
|
|
262
|
-
/** O(1) lookup for the exact client/tmux session status endpoint. */
|
|
263
115
|
export function getSessionLedgerEntryForClient(clientSessionId) {
|
|
264
|
-
const
|
|
265
|
-
return
|
|
116
|
+
const sessionId = byClientSession.get(clientSessionId);
|
|
117
|
+
return sessionId ? ledger.get(sessionId) : undefined;
|
|
266
118
|
}
|
|
267
119
|
export function resetSessionLedger() {
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
120
|
+
ledger.clear();
|
|
121
|
+
byClientSession.clear();
|
|
122
|
+
plansByCandidate.clear();
|
|
271
123
|
}
|
|
272
124
|
//# sourceMappingURL=session-ledger.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"session-ledger.js","sourceRoot":"","sources":["../../src/llm-gateway-runtime/session-ledger.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"session-ledger.js","sourceRoot":"","sources":["../../src/llm-gateway-runtime/session-ledger.ts"],"names":[],"mappings":"AA2DA,MAAM,MAAM,GAAG,IAAI,GAAG,EAA8B,CAAC;AACrD,MAAM,eAAe,GAAG,IAAI,GAAG,EAAkB,CAAC;AAClD,MAAM,gBAAgB,GAAG,IAAI,GAAG,EAA0B,CAAC;AAE3D,MAAM,iBAAiB,GAAG,CAAC,QAAQ,GAAG,MAAM,EAA2B,EAAE,CAAC,CAAC;IACzE,EAAE,EAAE,YAAY;IAChB,QAAQ;IACR,KAAK,EAAE,YAAY;CACpB,CAAC,CAAC;AAEH,MAAM,qBAAqB,GAAG,CAAC,UAA2B,EAA2B,EAAE,CAAC,CAAC;IACvF,EAAE,EAAE,UAAU,CAAC,oBAAoB;IACnC,QAAQ,EAAE,UAAU,CAAC,gBAAgB;IACrC,KAAK,EAAE,UAAU,CAAC,oBAAoB;CACvC,CAAC,CAAC;AAEH,MAAM,UAAU,eAAe,CAC7B,OAAqB,EACrB,K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