@sentropic/h2a-runtime 0.91.0 → 0.92.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/index.d.ts +4 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +79 -58
- package/dist/index.js.map +1 -1
- 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-terminal/client.d.ts +23 -0
- package/dist/native-terminal/client.d.ts.map +1 -0
- package/dist/native-terminal/client.js +203 -0
- package/dist/native-terminal/client.js.map +1 -0
- package/dist/native-terminal/host.d.ts +78 -0
- package/dist/native-terminal/host.d.ts.map +1 -0
- package/dist/native-terminal/host.js +275 -0
- package/dist/native-terminal/host.js.map +1 -0
- package/dist/native-terminal/process.d.ts +11 -0
- package/dist/native-terminal/process.d.ts.map +1 -0
- package/dist/native-terminal/process.js +137 -0
- package/dist/native-terminal/process.js.map +1 -0
- package/dist/native-terminal/protocol.d.ts +57 -0
- package/dist/native-terminal/protocol.d.ts.map +1 -0
- package/dist/native-terminal/protocol.js +102 -0
- package/dist/native-terminal/protocol.js.map +1 -0
- package/dist/native-terminal/replay-buffer.d.ts +26 -0
- package/dist/native-terminal/replay-buffer.d.ts.map +1 -0
- package/dist/native-terminal/replay-buffer.js +84 -0
- package/dist/native-terminal/replay-buffer.js.map +1 -0
- package/dist/native-terminal/server.d.ts +13 -0
- package/dist/native-terminal/server.d.ts.map +1 -0
- package/dist/native-terminal/server.js +555 -0
- package/dist/native-terminal/server.js.map +1 -0
- package/dist/native-terminal/socket-path.d.ts +8 -0
- package/dist/native-terminal/socket-path.d.ts.map +1 -0
- package/dist/native-terminal/socket-path.js +41 -0
- package/dist/native-terminal/socket-path.js.map +1 -0
- package/dist/native-terminal/supervisor.d.ts +26 -0
- package/dist/native-terminal/supervisor.d.ts.map +1 -0
- package/dist/native-terminal/supervisor.js +273 -0
- package/dist/native-terminal/supervisor.js.map +1 -0
- package/dist/pty.d.ts +1 -0
- package/dist/pty.d.ts.map +1 -1
- package/dist/pty.js +78 -2
- package/dist/pty.js.map +1 -1
- package/dist/registry.d.ts +7 -0
- package/dist/registry.d.ts.map +1 -1
- package/dist/registry.js +37 -1
- package/dist/registry.js.map +1 -1
- package/dist/status-projection.d.ts.map +1 -1
- package/dist/tmux.d.ts +7 -5
- package/dist/tmux.d.ts.map +1 -1
- package/dist/tmux.js +33 -7
- 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,4 +1,10 @@
|
|
|
1
1
|
import { Hono } from "hono";
|
|
2
|
+
import { type LlmMeshRoutingConfig } from "../llm-routing-config.js";
|
|
3
|
+
export interface LocalGatewayAppOptions {
|
|
4
|
+
readonly routing?: LlmMeshRoutingConfig;
|
|
5
|
+
readonly ownerScopeRef?: string;
|
|
6
|
+
}
|
|
7
|
+
export declare function createLocalGatewayApp(options?: LocalGatewayAppOptions): Hono;
|
|
2
8
|
export declare const app: Hono<import("hono/types").BlankEnv, import("hono/types").BlankSchema, "/">;
|
|
3
9
|
export declare function startServer(): void;
|
|
4
10
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/llm-gateway-runtime/index.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/llm-gateway-runtime/index.ts"],"names":[],"mappings":"AAmBA,OAAO,EAAE,IAAI,EAAE,MAAM,MAAM,CAAC;AAM5B,OAAO,EAGL,KAAK,oBAAoB,EAC1B,MAAM,0BAA0B,CAAC;AAoDlC,MAAM,WAAW,sBAAsB;IACrC,QAAQ,CAAC,OAAO,CAAC,EAAE,oBAAoB,CAAC;IACxC,QAAQ,CAAC,aAAa,CAAC,EAAE,MAAM,CAAC;CACjC;AAED,wBAAgB,qBAAqB,CAAC,OAAO,GAAE,sBAA2B,GAAG,IAAI,CA6FhF;AAED,eAAO,MAAM,GAAG,4EAA0B,CAAC;AAE3C,wBAAgB,WAAW,IAAI,IAAI,CASlC"}
|
|
@@ -1,70 +1,144 @@
|
|
|
1
|
+
import { randomUUID } from "node:crypto";
|
|
1
2
|
import { serve } from "@hono/node-server";
|
|
3
|
+
import { CloudCodeRuntimeClient, CodexRuntimeClient, GeminiAdapter, OpenAIAdapter, createLlmMesh, createProviderRegistry, } from "@sentropic/llm-mesh";
|
|
4
|
+
import { createGatewayRouter, stubGatewayConfig, } from "@sentropic/llm-gateway";
|
|
2
5
|
import { Hono } from "hono";
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
6
|
-
import {
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
return
|
|
21
|
-
}
|
|
22
|
-
if (typeof body.sessionId !== "string" || !body.sessionId) {
|
|
23
|
-
return c.json({ error: "sessionId (string) required" }, 400);
|
|
6
|
+
import { createCliLlmMeshFacade, llmMeshOwnerScopeRef, readLlmMeshConfig, } from "../llm-mesh.js";
|
|
7
|
+
import { parseLlmMeshRoutingConfig, routingProfiles, } from "../llm-routing-config.js";
|
|
8
|
+
import { getSessionLedgerEntry, getSessionLedgerEntryForClient, listSessionLedger, recordRoutePlan, recordRouteSettlement, } from "./session-ledger.js";
|
|
9
|
+
import { acquireSession, lookupSessionById, lookupToken, sessionCount, } from "./sticky.js";
|
|
10
|
+
const routingConfigFromEnvironment = () => {
|
|
11
|
+
const raw = process.env.H2A_LLM_MESH_ROUTING_JSON;
|
|
12
|
+
return raw ? parseLlmMeshRoutingConfig(raw) : undefined;
|
|
13
|
+
};
|
|
14
|
+
const runtimeMesh = () => createLlmMesh({
|
|
15
|
+
registry: createProviderRegistry([
|
|
16
|
+
new OpenAIAdapter({ client: new CodexRuntimeClient() }),
|
|
17
|
+
new GeminiAdapter({ client: new CloudCodeRuntimeClient() }),
|
|
18
|
+
]),
|
|
19
|
+
});
|
|
20
|
+
const bearerFromHeaders = (headers) => {
|
|
21
|
+
const authorization = headers.authorization;
|
|
22
|
+
if (authorization?.toLowerCase().startsWith("bearer ")) {
|
|
23
|
+
return authorization.slice(7).trim();
|
|
24
24
|
}
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
25
|
+
return headers["x-api-key"]?.trim() || undefined;
|
|
26
|
+
};
|
|
27
|
+
const observablePlanner = (delegate) => ({
|
|
28
|
+
...(delegate.listModels
|
|
29
|
+
? { listModels: (subject) => delegate.listModels(subject) }
|
|
30
|
+
: {}),
|
|
31
|
+
async plan(subject, input) {
|
|
32
|
+
const plan = await delegate.plan(subject, input);
|
|
33
|
+
const session = lookupSessionById(subject.principalRef);
|
|
34
|
+
if (session)
|
|
35
|
+
recordRoutePlan(session, input, plan);
|
|
36
|
+
return plan;
|
|
37
|
+
},
|
|
38
|
+
prepareAttempt: (...args) => delegate.prepareAttempt(...args),
|
|
39
|
+
describeAffinity: (...args) => delegate.describeAffinity(...args),
|
|
40
|
+
promoteAffinity: (...args) => delegate.promoteAffinity(...args),
|
|
41
|
+
rebindAffinity: (...args) => delegate.rebindAffinity(...args),
|
|
42
|
+
resetAffinity: (...args) => delegate.resetAffinity(...args),
|
|
43
|
+
});
|
|
44
|
+
export function createLocalGatewayApp(options = {}) {
|
|
45
|
+
const routing = options.routing ?? routingConfigFromEnvironment();
|
|
46
|
+
const currentRouting = () => {
|
|
47
|
+
if (options.routing)
|
|
48
|
+
return options.routing;
|
|
49
|
+
const publicConfig = readLlmMeshConfig();
|
|
50
|
+
// A present config with no routing field is an intentional live reset.
|
|
51
|
+
// Fall back to the startup environment only when no config exists at all.
|
|
52
|
+
return publicConfig ? publicConfig.routing : routing;
|
|
53
|
+
};
|
|
54
|
+
const ownerScopeRef = options.ownerScopeRef ?? llmMeshOwnerScopeRef();
|
|
55
|
+
const facade = createCliLlmMeshFacade();
|
|
56
|
+
const profiles = routingProfiles(routing);
|
|
57
|
+
const planner = observablePlanner(facade.createRoutePlanner(runtimeMesh(), {
|
|
58
|
+
...(routing?.council ? { council: routing.council } : {}),
|
|
59
|
+
...(profiles ? { profiles } : {}),
|
|
60
|
+
}));
|
|
61
|
+
const callerAuth = {
|
|
62
|
+
async verify(headers) {
|
|
63
|
+
const token = bearerFromHeaders(headers);
|
|
64
|
+
const session = token ? await lookupToken(token) : undefined;
|
|
65
|
+
if (!session)
|
|
66
|
+
return { ok: false, reason: "invalid local gateway bearer" };
|
|
67
|
+
return {
|
|
68
|
+
ok: true,
|
|
69
|
+
cost: {
|
|
70
|
+
tenantId: ownerScopeRef,
|
|
71
|
+
principalId: session.sessionId,
|
|
72
|
+
ownerScopeRef,
|
|
73
|
+
...(session.workspaceId ? { workspaceId: session.workspaceId } : {}),
|
|
74
|
+
source: "h2a-local-gateway",
|
|
75
|
+
correlationId: randomUUID(),
|
|
76
|
+
},
|
|
77
|
+
};
|
|
78
|
+
},
|
|
79
|
+
};
|
|
80
|
+
const routeMetering = {
|
|
81
|
+
settleRoute(settlement) {
|
|
82
|
+
recordRouteSettlement(settlement);
|
|
83
|
+
},
|
|
84
|
+
};
|
|
85
|
+
const gateway = createGatewayRouter({
|
|
86
|
+
config: { ...stubGatewayConfig, callerAuth },
|
|
87
|
+
routePlanner: planner,
|
|
88
|
+
routeMetering,
|
|
89
|
+
routeInput({ cost }) {
|
|
90
|
+
const session = lookupSessionById(cost.principalId);
|
|
91
|
+
const activeRouting = currentRouting();
|
|
92
|
+
return {
|
|
93
|
+
affinityKey: session?.clientSessionId ?? cost.principalId,
|
|
94
|
+
...(session?.workspaceId ? { workspaceId: session.workspaceId } : {}),
|
|
95
|
+
...(activeRouting?.policy ? { policyOverride: activeRouting.policy } : {}),
|
|
96
|
+
...(activeRouting?.activeProfile ? { policyProfile: activeRouting.activeProfile } : {}),
|
|
97
|
+
...(activeRouting?.explicit ? { explicit: activeRouting.explicit } : {}),
|
|
98
|
+
};
|
|
99
|
+
},
|
|
100
|
+
});
|
|
101
|
+
const app = new Hono();
|
|
102
|
+
app.get("/health", (c) => c.json({ ok: true }));
|
|
103
|
+
app.post("/v1/session", async (c) => {
|
|
104
|
+
let body;
|
|
105
|
+
try {
|
|
106
|
+
body = await c.req.json();
|
|
107
|
+
}
|
|
108
|
+
catch {
|
|
109
|
+
return c.json({ error: "invalid JSON" }, 400);
|
|
110
|
+
}
|
|
111
|
+
if (typeof body.sessionId !== "string" || !body.sessionId.trim()) {
|
|
112
|
+
return c.json({ error: "sessionId (string) required" }, 400);
|
|
113
|
+
}
|
|
114
|
+
const session = await acquireSession(body.sessionId, {
|
|
115
|
+
...(typeof body.clientSessionId === "string"
|
|
116
|
+
? { clientSessionId: body.clientSessionId }
|
|
117
|
+
: {}),
|
|
29
118
|
...(typeof body.workspaceId === "string" ? { workspaceId: body.workspaceId } : {}),
|
|
30
119
|
...(typeof body.profile === "string" ? { profile: body.profile } : {}),
|
|
31
|
-
...(typeof body.clientSessionId === "string" ? { clientSessionId: body.clientSessionId } : {}),
|
|
32
|
-
...(typeof body.reasoningEffort === "string"
|
|
33
|
-
? { reasoningEffort: body.reasoningEffort }
|
|
34
|
-
: {}),
|
|
35
|
-
...(typeof body.requiredTransport === "string"
|
|
36
|
-
? { requiredTransport: body.requiredTransport }
|
|
37
|
-
: {}),
|
|
38
120
|
});
|
|
39
|
-
return c.json(
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
});
|
|
45
|
-
|
|
46
|
-
app.get("/v1/
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
// The tmux surface asks for one attested client session. This is deliberately
|
|
55
|
-
// not the collection endpoint: a five-second status refresh must stay O(1).
|
|
56
|
-
app.get("/v1/status/client/:clientSessionId", (c) => {
|
|
57
|
-
const entry = getSessionLedgerEntryForClient(c.req.param("clientSessionId"));
|
|
58
|
-
if (!entry)
|
|
59
|
-
return c.json({ error: "client session not found" }, 404);
|
|
60
|
-
return c.json(entry);
|
|
61
|
-
});
|
|
62
|
-
// Anthropic Messages proxy — pods call this with Bearer gw-<hex>
|
|
63
|
-
app.post("/v1/messages", handleMessages);
|
|
121
|
+
return c.json(session, 201);
|
|
122
|
+
});
|
|
123
|
+
app.get("/v1/sessions", (c) => c.json({ data: listSessionLedger() }));
|
|
124
|
+
app.get("/v1/sessions/:id", (c) => {
|
|
125
|
+
const entry = getSessionLedgerEntry(c.req.param("id"));
|
|
126
|
+
return entry ? c.json(entry) : c.json({ error: "session not found" }, 404);
|
|
127
|
+
});
|
|
128
|
+
app.get("/v1/status/client/:clientSessionId", (c) => {
|
|
129
|
+
const entry = getSessionLedgerEntryForClient(c.req.param("clientSessionId"));
|
|
130
|
+
return entry ? c.json(entry) : c.json({ error: "client session not found" }, 404);
|
|
131
|
+
});
|
|
132
|
+
app.route("/", gateway);
|
|
133
|
+
return app;
|
|
134
|
+
}
|
|
135
|
+
export const app = createLocalGatewayApp();
|
|
64
136
|
export function startServer() {
|
|
65
|
-
const port = parseInt(process.env.PORT ?? "
|
|
66
|
-
|
|
67
|
-
|
|
137
|
+
const port = Number.parseInt(process.env.PORT ?? "3002", 10);
|
|
138
|
+
// Session minting is intentionally unauthenticated control-plane traffic.
|
|
139
|
+
// The embedded solo-dev host therefore never listens beyond loopback.
|
|
140
|
+
serve({ fetch: app.fetch, port, hostname: "127.0.0.1" }, () => {
|
|
141
|
+
process.stdout.write(`[llm-gateway] listening on :${port} — ${sessionCount()} local bearers\n`);
|
|
68
142
|
});
|
|
69
143
|
}
|
|
70
144
|
if (process.env.NODE_ENV !== "test")
|
|
@@ -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,GAIvB,MAAM,qBAAqB,CAAC;AAC7B,OAAO,EACL,mBAAmB,EACnB,iBAAiB,GAGlB,MAAM,wBAAwB,CAAC;AAChC,OAAO,EAAE,IAAI,EAAE,MAAM,MAAM,CAAC;AAC5B,OAAO,EACL,sBAAsB,EACtB,oBAAoB,EACpB,iBAAiB,GAClB,MAAM,gBAAgB,CAAC;AACxB,OAAO,EACL,yBAAyB,EACzB,eAAe,GAEhB,MAAM,0BAA0B,CAAC;AAClC,OAAO,EACL,qBAAqB,EACrB,8BAA8B,EAC9B,iBAAiB,EACjB,eAAe,EACf,qBAAqB,GACtB,MAAM,qBAAqB,CAAC;AAC7B,OAAO,EACL,cAAc,EACd,iBAAiB,EACjB,WAAW,EACX,YAAY,GACb,MAAM,aAAa,CAAC;AAErB,MAAM,4BAA4B,GAAG,GAAqC,EAAE;IAC1E,MAAM,GAAG,GAAG,OAAO,CAAC,GAAG,CAAC,yBAAyB,CAAC;IAClD,OAAO,GAAG,CAAC,CAAC,CAAC,yBAAyB,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,SAAS,CAAC;AAC1D,CAAC,CAAC;AAEF,M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CAAoC,EAAE,CAAC,CAAC,EAAE,EAAE;QAClD,MAAM,KAAK,GAAG,8BAA8B,CAAC,CAAC,CAAC,GAAG,CAAC,KAAK,CAAC,iBAAiB,CAAC,CAAC,CAAC;QAC7E,OAAO,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,EAAE,KAAK,EAAE,0BAA0B,EAAE,EAAE,GAAG,CAAC,CAAC;IACpF,CAAC,CAAC,CAAC;IACH,GAAG,CAAC,KAAK,CAAC,GAAG,EAAE,OAAO,CAAC,CAAC;IACxB,OAAO,GAAG,CAAC;AACb,CAAC;AAED,MAAM,CAAC,MAAM,GAAG,GAAG,qBAAqB,EAAE,CAAC;AAE3C,MAAM,UAAU,WAAW;IACzB,MAAM,IAAI,GAAG,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;IAC1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