mirror of
https://github.com/diegosouzapw/OmniRoute.git
synced 2026-09-16 03:42:21 +03:00
feat(dashboard): surface exclusive managed leases in Sessions view (#11389)
Merged into release/v3.8.51 via batch validation: exclusive-session-observability unit+UI suites green on the combined tree, static gates green. Nice additive observability layer over the #10362 lease backend — thanks @KaspaPulse!
This commit is contained in:
@@ -5,13 +5,44 @@ import {
|
||||
getAllActiveSessionCountsByKey,
|
||||
} from "@omniroute/open-sse/services/sessionManager.ts";
|
||||
import { sanitizeErrorMessage } from "@omniroute/open-sse/utils/error";
|
||||
import { getExclusiveLeaseConnectionIds } from "@/lib/db/apiKeys";
|
||||
import { getExclusiveLeaseOccupancy } from "@/lib/db/exclusiveConnectionLeases";
|
||||
import { getProviderConnectionDisplayMetadata } from "@/lib/db/providers";
|
||||
import { getAccountDisplayName } from "@/lib/display/names";
|
||||
import { getPendingRequests } from "@/lib/usage/usageHistory";
|
||||
import { buildExclusiveDashboardSessions } from "@/lib/sessionObservability";
|
||||
|
||||
export async function GET() {
|
||||
try {
|
||||
const sessions = getActiveSessions();
|
||||
const count = getActiveSessionCount();
|
||||
const byApiKey = getAllActiveSessionCountsByKey();
|
||||
return NextResponse.json({ count, sessions, byApiKey });
|
||||
|
||||
// Reuse the hard-lease authority added by #10362. The API-key policy derives
|
||||
// the managed candidate set; SQLite occupancy is the source of truth for
|
||||
// which of those connections are actually leased right now.
|
||||
const managedConnectionIds = Array.from(await getExclusiveLeaseConnectionIds());
|
||||
const occupancy = getExclusiveLeaseOccupancy(managedConnectionIds);
|
||||
const leasedConnectionIds = new Set(occupancy.keys());
|
||||
const connectionNames = new Map(
|
||||
getProviderConnectionDisplayMetadata([...leasedConnectionIds]).map((connection) => [
|
||||
connection.id,
|
||||
getAccountDisplayName(connection),
|
||||
])
|
||||
);
|
||||
const exclusiveSessions = buildExclusiveDashboardSessions(
|
||||
leasedConnectionIds,
|
||||
getPendingRequests().byAccount,
|
||||
sessions,
|
||||
connectionNames
|
||||
);
|
||||
|
||||
return NextResponse.json({
|
||||
count,
|
||||
sessions,
|
||||
byApiKey,
|
||||
exclusiveSessions,
|
||||
});
|
||||
} catch (error) {
|
||||
return NextResponse.json({ error: sanitizeErrorMessage(error) }, { status: 500 });
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user