omnicell-router 0.8.1 → 0.8.2
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/backend/dist/cli/clients/activity.d.ts +35 -0
- package/backend/dist/cli/clients/activity.js +67 -0
- package/backend/dist/cli/clients/index.js +7 -1
- package/backend/dist/cli/types.d.ts +9 -0
- package/backend/dist/routes/console.js +6 -1
- package/backend/dist/server.js +8 -0
- package/frontend/dist/assets/{index-Cn3QMOQx.js → index-55VVwfFQ.js} +281 -247
- package/frontend/dist/assets/workbuddy.color-DOMpQkxJ.svg +29 -0
- package/frontend/dist/index.html +1 -1
- package/package.json +1 -1
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Per-client activity ledger — the console Clients page's dynamic sort key.
|
|
3
|
+
*
|
|
4
|
+
* A pure in-memory map, two timestamps per client ADAPTER name (the roster
|
|
5
|
+
* row key; there is no per-instance id — a family adapter is still one row):
|
|
6
|
+
*
|
|
7
|
+
* - `lastActiveAt` — stamped by the gateway's auth gate when an inference
|
|
8
|
+
* request arrives whose User-Agent fingerprints a known client CLI. The UA
|
|
9
|
+
* is forgeable and the fingerprint table is deliberately incomplete: this
|
|
10
|
+
* is DISPLAY-ONLY state (same doctrine as utils/harness-profiles.ts) — it
|
|
11
|
+
* never gates, rates or routes anything, so a spoofed or unknown UA costs
|
|
12
|
+
* at most a wrong card position.
|
|
13
|
+
* - `lastSetupAt` — stamped when `setupClient()` hooks a client successfully
|
|
14
|
+
* (the hooking moment — first takeover or a re-hook alike), so a freshly
|
|
15
|
+
* hooked client floats up even before it has sent any traffic.
|
|
16
|
+
*
|
|
17
|
+
* Memory-only by design: a gateway restart clears activity, and the roster
|
|
18
|
+
* falls back to `lastSetupAt` then the registry order. Nothing is persisted,
|
|
19
|
+
* nothing leaves the process.
|
|
20
|
+
*/
|
|
21
|
+
/** Record that `name` was hooked (setup succeeded) at `at`. */
|
|
22
|
+
export declare function noteClientSetup(name: string, at?: number): void;
|
|
23
|
+
/**
|
|
24
|
+
* Stamp activity for the client a request's User-Agent fingerprints, if any.
|
|
25
|
+
* Unknown / absent UAs are a no-op. Called per inference request — keep it
|
|
26
|
+
* allocation-free on the miss path.
|
|
27
|
+
*/
|
|
28
|
+
export declare function noteClientActivityFromUserAgent(ua: string | undefined, at?: number): void;
|
|
29
|
+
/** Activity timestamps for the clients the map knows about, keyed by adapter name. */
|
|
30
|
+
export declare function clientActivitySnapshot(): Record<string, {
|
|
31
|
+
lastActiveAt?: number;
|
|
32
|
+
lastSetupAt?: number;
|
|
33
|
+
}>;
|
|
34
|
+
/** Test reset — clears both maps (activity is process-local state). */
|
|
35
|
+
export declare function resetClientActivity(): void;
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Per-client activity ledger — the console Clients page's dynamic sort key.
|
|
3
|
+
*
|
|
4
|
+
* A pure in-memory map, two timestamps per client ADAPTER name (the roster
|
|
5
|
+
* row key; there is no per-instance id — a family adapter is still one row):
|
|
6
|
+
*
|
|
7
|
+
* - `lastActiveAt` — stamped by the gateway's auth gate when an inference
|
|
8
|
+
* request arrives whose User-Agent fingerprints a known client CLI. The UA
|
|
9
|
+
* is forgeable and the fingerprint table is deliberately incomplete: this
|
|
10
|
+
* is DISPLAY-ONLY state (same doctrine as utils/harness-profiles.ts) — it
|
|
11
|
+
* never gates, rates or routes anything, so a spoofed or unknown UA costs
|
|
12
|
+
* at most a wrong card position.
|
|
13
|
+
* - `lastSetupAt` — stamped when `setupClient()` hooks a client successfully
|
|
14
|
+
* (the hooking moment — first takeover or a re-hook alike), so a freshly
|
|
15
|
+
* hooked client floats up even before it has sent any traffic.
|
|
16
|
+
*
|
|
17
|
+
* Memory-only by design: a gateway restart clears activity, and the roster
|
|
18
|
+
* falls back to `lastSetupAt` then the registry order. Nothing is persisted,
|
|
19
|
+
* nothing leaves the process.
|
|
20
|
+
*/
|
|
21
|
+
const lastActiveAt = new Map();
|
|
22
|
+
const lastSetupAt = new Map();
|
|
23
|
+
/**
|
|
24
|
+
* UA → client-adapter-name fingerprints — first match wins. Only confident,
|
|
25
|
+
* observed wire spellings belong here (measured on real traffic, like the
|
|
26
|
+
* harness-profiles evidence rule); a speculative entry mis-sorts a card.
|
|
27
|
+
* Known CLI User-Agents not listed (kimi, openclaw, dsh, …) simply never
|
|
28
|
+
* move in the sort — add each only once observed.
|
|
29
|
+
*/
|
|
30
|
+
const UA_MATCHERS = [
|
|
31
|
+
{ match: /claude-cli\//i, client: 'claude' },
|
|
32
|
+
{ match: /opencode\//i, client: 'opencode' },
|
|
33
|
+
{ match: /codex/i, client: 'codex' },
|
|
34
|
+
];
|
|
35
|
+
/** Record that `name` was hooked (setup succeeded) at `at`. */
|
|
36
|
+
export function noteClientSetup(name, at = Date.now()) {
|
|
37
|
+
lastSetupAt.set(name, at);
|
|
38
|
+
}
|
|
39
|
+
/**
|
|
40
|
+
* Stamp activity for the client a request's User-Agent fingerprints, if any.
|
|
41
|
+
* Unknown / absent UAs are a no-op. Called per inference request — keep it
|
|
42
|
+
* allocation-free on the miss path.
|
|
43
|
+
*/
|
|
44
|
+
export function noteClientActivityFromUserAgent(ua, at = Date.now()) {
|
|
45
|
+
if (!ua)
|
|
46
|
+
return;
|
|
47
|
+
for (const entry of UA_MATCHERS) {
|
|
48
|
+
if (entry.match.test(ua)) {
|
|
49
|
+
lastActiveAt.set(entry.client, at);
|
|
50
|
+
return;
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
/** Activity timestamps for the clients the map knows about, keyed by adapter name. */
|
|
55
|
+
export function clientActivitySnapshot() {
|
|
56
|
+
const out = {};
|
|
57
|
+
for (const [name, at] of lastSetupAt)
|
|
58
|
+
out[name] = { lastSetupAt: at };
|
|
59
|
+
for (const [name, at] of lastActiveAt)
|
|
60
|
+
out[name] = { ...out[name], lastActiveAt: at };
|
|
61
|
+
return out;
|
|
62
|
+
}
|
|
63
|
+
/** Test reset — clears both maps (activity is process-local state). */
|
|
64
|
+
export function resetClientActivity() {
|
|
65
|
+
lastActiveAt.clear();
|
|
66
|
+
lastSetupAt.clear();
|
|
67
|
+
}
|
|
@@ -4,6 +4,7 @@ import { retiredClientHint } from './reserved.js';
|
|
|
4
4
|
import { popularityRank } from '../../utils/popularity.js';
|
|
5
5
|
import { compareVersions } from '../../utils/semver.js';
|
|
6
6
|
import { getPluginClientAdapter, listPluginClientAdapters, pluginClientRank, pluginIdForClient } from './plugin-adapters.js';
|
|
7
|
+
import { noteClientSetup } from './activity.js';
|
|
7
8
|
/** The hooks this build ships (`core-adapters.ts`) — the authoritative answer
|
|
8
9
|
* for "what is always available", even before the plugin host has run. */
|
|
9
10
|
const adapters = CORE_ADAPTERS;
|
|
@@ -202,8 +203,13 @@ export async function setupClient(name, options) {
|
|
|
202
203
|
}
|
|
203
204
|
const result = await adapter.setup(options);
|
|
204
205
|
// A hook flip invalidates the roster snapshot: the next read rebuilds.
|
|
205
|
-
|
|
206
|
+
// The success moment is also the client's "接入" timestamp — the activity
|
|
207
|
+
// ledger's fallback sort key, so a freshly hooked client floats up before
|
|
208
|
+
// it has sent any traffic.
|
|
209
|
+
if (result.success) {
|
|
206
210
|
rosterCache.at = 0;
|
|
211
|
+
noteClientSetup(name);
|
|
212
|
+
}
|
|
207
213
|
return siblingNote && result.success ? { ...result, message: result.message + siblingNote } : result;
|
|
208
214
|
}
|
|
209
215
|
export async function teardownClient(name, options) {
|
|
@@ -96,6 +96,15 @@ export interface ClientHookStatus {
|
|
|
96
96
|
* each with its own takeover state. Absent for single-product adapters —
|
|
97
97
|
* the console then renders the card row exactly as before. */
|
|
98
98
|
products?: ClientProductStatus[];
|
|
99
|
+
/** Last time an inference request was fingerprinted to this client's UA
|
|
100
|
+
* (ms epoch; the auth gate's in-memory activity ledger). Absent = no
|
|
101
|
+
* observed traffic since boot. Display-only sort key — never routing
|
|
102
|
+
* state; the CLI roster table ignores it. */
|
|
103
|
+
lastActiveAt?: number;
|
|
104
|
+
/** Last time `setupClient()` hooked this client successfully (ms epoch).
|
|
105
|
+
* The sort fallback while a client has sent no traffic yet; absent = not
|
|
106
|
+
* hooked this boot. */
|
|
107
|
+
lastSetupAt?: number;
|
|
99
108
|
}
|
|
100
109
|
/**
|
|
101
110
|
* One product instance inside a FAMILY adapter — one installed JetBrains IDE,
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import fs from 'node:fs';
|
|
2
2
|
import path from 'node:path';
|
|
3
3
|
import { getAllClientStatuses, setupClient, teardownClient } from '../cli/clients/index.js';
|
|
4
|
+
import { clientActivitySnapshot } from '../cli/clients/activity.js';
|
|
4
5
|
import { VIRTUAL_AUTO_IDS } from '../cli/types.js';
|
|
5
6
|
import { MEMBER_TIER_ORDER } from '../providers/member-match.js';
|
|
6
7
|
import { refreshDirectPool } from '../providers/boot-direct.js';
|
|
@@ -1026,9 +1027,13 @@ export function registerConsoleRoutes(app, registry, orchestrator) {
|
|
|
1026
1027
|
// "Refresh Status" button must never serve a stale snapshot.
|
|
1027
1028
|
app.get('/api/admin/clients', async (req) => {
|
|
1028
1029
|
const refresh = req.query.refresh === '1';
|
|
1030
|
+
// The activity ledger rides along per row (lastActiveAt / lastSetupAt);
|
|
1031
|
+
// SORTING stays on the console — the CLI's roster table must keep the
|
|
1032
|
+
// registry order regardless of live traffic.
|
|
1033
|
+
const activity = clientActivitySnapshot();
|
|
1029
1034
|
return {
|
|
1030
1035
|
status: 'ok',
|
|
1031
|
-
clients: await getAllClientStatuses({ refresh }),
|
|
1036
|
+
clients: (await getAllClientStatuses({ refresh })).map((c) => ({ ...c, ...(activity[c.name] ?? {}) })),
|
|
1032
1037
|
};
|
|
1033
1038
|
});
|
|
1034
1039
|
// 3A1'. Release update check — display-only and cached in-process. The
|
package/backend/dist/server.js
CHANGED
|
@@ -22,6 +22,7 @@ import { ProviderRegistry } from './providers/registry.js';
|
|
|
22
22
|
import { FinOpsTracker } from './metrics/finops-tracker.js';
|
|
23
23
|
import { APP_VERSION } from './version.js';
|
|
24
24
|
import { setGatewayMetaDeps } from './cli/clients/model-meta.js';
|
|
25
|
+
import { noteClientActivityFromUserAgent } from './cli/clients/activity.js';
|
|
25
26
|
import { comboEnvelope, findMemberCatalogRecords, modelsDevBlock, tierAliasEnvelope, virtualModelsDevBlock, } from './providers/virtual-meta.js';
|
|
26
27
|
import { modelSupportsEfforts } from './types/router.js';
|
|
27
28
|
import { isInternalSessionId } from './session/session-manager.js';
|
|
@@ -462,6 +463,13 @@ providerConfigs = []) {
|
|
|
462
463
|
}
|
|
463
464
|
// Attach client identity onto request for tracing and logging
|
|
464
465
|
req.authInfo = validation;
|
|
466
|
+
// Display-only client-activity stamp for the Clients page's dynamic sort:
|
|
467
|
+
// fingerprint the User-Agent on the four inference wires only (model /
|
|
468
|
+
// admin browsing is not "using a client"). Forgeable by design of HTTP —
|
|
469
|
+
// never routing state, a spoofed UA costs at most a wrong card position.
|
|
470
|
+
if (path !== null && INFERENCE_ROUTE_PATHS.has(path)) {
|
|
471
|
+
noteClientActivityFromUserAgent(req.headers['user-agent']);
|
|
472
|
+
}
|
|
465
473
|
// ── Inbound sliding-window enforcement (apiKeys[].limits) ───────────────
|
|
466
474
|
// The client key's window caps are a CONTRACT with the caller, enforced at
|
|
467
475
|
// the gate: an over-limit request never enters the pipeline and never
|