pi-mega-compact 0.20.63 → 0.20.65
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/README.md +1 -1
- package/dist/config/vector-cortex-enc2a.js +35 -0
- package/dist/config/vector-cortex-enc2b.js +36 -0
- package/dist/config/vector-cortex.js +4 -0
- package/dist/config.js +1 -1
- package/dist/extensions/dashboard-server/routes-rag-settings-vector-cortex.js +2 -0
- package/dist/extensions/dashboard-server/routes-setup-enc2a.js +119 -0
- package/dist/extensions/dashboard-server/routes-setup-enc2b.js +77 -0
- package/dist/extensions/dashboard-server/routes-setup.js +65 -3
- package/dist/src/config/vector-cortex-enc2a.js +35 -0
- package/dist/src/config/vector-cortex-enc2b.js +36 -0
- package/dist/src/config/vector-cortex.js +4 -0
- package/dist/src/config.js +1 -1
- package/dist/src/vector-cortex/encoder/native-install-artifacts.js +43 -0
- package/dist/src/vector-cortex/encoder/native-qualify-retest.js +225 -0
- package/dist/vector-cortex/encoder/native-install-artifacts.js +43 -0
- package/dist/vector-cortex/encoder/native-qualify-retest.js +225 -0
- package/extensions/dashboard-client/dist/assets/{AdminTab-DrJ9VWRu.js → AdminTab-B31efZ_R.js} +2 -2
- package/extensions/dashboard-client/dist/assets/{AdminTab-DrJ9VWRu.js.map → AdminTab-B31efZ_R.js.map} +1 -1
- package/extensions/dashboard-client/dist/assets/{AreaChart-B1OkLRGT.js → AreaChart-BpjHNUZm.js} +2 -2
- package/extensions/dashboard-client/dist/assets/{AreaChart-B1OkLRGT.js.map → AreaChart-BpjHNUZm.js.map} +1 -1
- package/extensions/dashboard-client/dist/assets/{BarChart-IWwm38i0.js → BarChart-CY2FndXC.js} +2 -2
- package/extensions/dashboard-client/dist/assets/{BarChart-IWwm38i0.js.map → BarChart-CY2FndXC.js.map} +1 -1
- package/extensions/dashboard-client/dist/assets/{CacheTab-DvNlBxzX.js → CacheTab-kMSrMD3e.js} +2 -2
- package/extensions/dashboard-client/dist/assets/{CacheTab-DvNlBxzX.js.map → CacheTab-kMSrMD3e.js.map} +1 -1
- package/extensions/dashboard-client/dist/assets/{ConfigTab-C1t0EM2H.js → ConfigTab-BrKpv2YG.js} +2 -2
- package/extensions/dashboard-client/dist/assets/{ConfigTab-C1t0EM2H.js.map → ConfigTab-BrKpv2YG.js.map} +1 -1
- package/extensions/dashboard-client/dist/assets/{EventsTab-CCexdJjG.js → EventsTab-DaClreCm.js} +2 -2
- package/extensions/dashboard-client/dist/assets/{EventsTab-CCexdJjG.js.map → EventsTab-DaClreCm.js.map} +1 -1
- package/extensions/dashboard-client/dist/assets/{HealthTab-BkAKwtxe.js → HealthTab-CxKQDqF3.js} +2 -2
- package/extensions/dashboard-client/dist/assets/{HealthTab-BkAKwtxe.js.map → HealthTab-CxKQDqF3.js.map} +1 -1
- package/extensions/dashboard-client/dist/assets/{MaintenanceTab-Beb59xuJ.js → MaintenanceTab-BKSlSjv0.js} +2 -2
- package/extensions/dashboard-client/dist/assets/{MaintenanceTab-Beb59xuJ.js.map → MaintenanceTab-BKSlSjv0.js.map} +1 -1
- package/extensions/dashboard-client/dist/assets/{MemoryMapTab-P04ao17z.js → MemoryMapTab-C2goWDt8.js} +2 -2
- package/extensions/dashboard-client/dist/assets/{MemoryMapTab-P04ao17z.js.map → MemoryMapTab-C2goWDt8.js.map} +1 -1
- package/extensions/dashboard-client/dist/assets/{MetricsCards-YlmnUe01.js → MetricsCards-DCPuCnrw.js} +2 -2
- package/extensions/dashboard-client/dist/assets/{MetricsCards-YlmnUe01.js.map → MetricsCards-DCPuCnrw.js.map} +1 -1
- package/extensions/dashboard-client/dist/assets/MetricsTab-Bz0Mdyb_.js +2 -0
- package/extensions/dashboard-client/dist/assets/{MetricsTab-C2rXqvoD.js.map → MetricsTab-Bz0Mdyb_.js.map} +1 -1
- package/extensions/dashboard-client/dist/assets/{OverviewTab-BBNvmR3X.js → OverviewTab-B-eZ-eDR.js} +2 -2
- package/extensions/dashboard-client/dist/assets/{OverviewTab-BBNvmR3X.js.map → OverviewTab-B-eZ-eDR.js.map} +1 -1
- package/extensions/dashboard-client/dist/assets/{ReposTab-CjlumghA.js → ReposTab-W_NKRWpk.js} +2 -2
- package/extensions/dashboard-client/dist/assets/{ReposTab-CjlumghA.js.map → ReposTab-W_NKRWpk.js.map} +1 -1
- package/extensions/dashboard-client/dist/assets/{SessionsTab-D1tWcUn-.js → SessionsTab-GYrtNt4_.js} +2 -2
- package/extensions/dashboard-client/dist/assets/{SessionsTab-D1tWcUn-.js.map → SessionsTab-GYrtNt4_.js.map} +1 -1
- package/extensions/dashboard-client/dist/assets/SetupTab-_1xa6eTJ.js +3 -0
- package/extensions/dashboard-client/dist/assets/SetupTab-_1xa6eTJ.js.map +1 -0
- package/extensions/dashboard-client/dist/assets/{TimeSavedCard-DzBeE2y4.js → TimeSavedCard-Ciu8anVG.js} +2 -2
- package/extensions/dashboard-client/dist/assets/{TimeSavedCard-DzBeE2y4.js.map → TimeSavedCard-Ciu8anVG.js.map} +1 -1
- package/extensions/dashboard-client/dist/assets/{TurnMemoryView-DKVIkjot.js → TurnMemoryView-BhXLIjWr.js} +2 -2
- package/extensions/dashboard-client/dist/assets/{TurnMemoryView-DKVIkjot.js.map → TurnMemoryView-BhXLIjWr.js.map} +1 -1
- package/extensions/dashboard-client/dist/assets/TurnsTab-C-f3DggL.js +2 -0
- package/extensions/dashboard-client/dist/assets/{TurnsTab-Cqyq6fVe.js.map → TurnsTab-C-f3DggL.js.map} +1 -1
- package/extensions/dashboard-client/dist/assets/{VcStatusBadge-CBtRo20h.js → VcStatusBadge-D97V04WE.js} +2 -2
- package/extensions/dashboard-client/dist/assets/{VcStatusBadge-CBtRo20h.js.map → VcStatusBadge-D97V04WE.js.map} +1 -1
- package/extensions/dashboard-client/dist/assets/{VectorCortexTab-Bk53uJZZ.js → VectorCortexTab-cyDJPAPB.js} +2 -2
- package/extensions/dashboard-client/dist/assets/{VectorCortexTab-Bk53uJZZ.js.map → VectorCortexTab-cyDJPAPB.js.map} +1 -1
- package/extensions/dashboard-client/dist/assets/{WikiTab-CemxY6Lm.js → WikiTab-dQ96DyjP.js} +2 -2
- package/extensions/dashboard-client/dist/assets/{WikiTab-CemxY6Lm.js.map → WikiTab-dQ96DyjP.js.map} +1 -1
- package/extensions/dashboard-client/dist/assets/{button-BJiUJyhV.js → button-B1beLEiV.js} +2 -2
- package/extensions/dashboard-client/dist/assets/{button-BJiUJyhV.js.map → button-B1beLEiV.js.map} +1 -1
- package/extensions/dashboard-client/dist/assets/{card-Cg_LPWdl.js → card-CK9KH_ob.js} +2 -2
- package/extensions/dashboard-client/dist/assets/{card-Cg_LPWdl.js.map → card-CK9KH_ob.js.map} +1 -1
- package/extensions/dashboard-client/dist/assets/{client-extra-DxQFx7HY.js → client-extra-gN7xjggX.js} +2 -2
- package/extensions/dashboard-client/dist/assets/{client-extra-DxQFx7HY.js.map → client-extra-gN7xjggX.js.map} +1 -1
- package/extensions/dashboard-client/dist/assets/{generateCategoricalChart-sE5oI3Ee.js → generateCategoricalChart-MB2_0u55.js} +2 -2
- package/extensions/dashboard-client/dist/assets/{generateCategoricalChart-sE5oI3Ee.js.map → generateCategoricalChart-MB2_0u55.js.map} +1 -1
- package/extensions/dashboard-client/dist/assets/{index-CeBW9Vtt.js → index-CKVd_Ym_.js} +3 -3
- package/extensions/dashboard-client/dist/assets/{index-CeBW9Vtt.js.map → index-CKVd_Ym_.js.map} +1 -1
- package/extensions/dashboard-client/dist/assets/{switch-CmkMKtTG.js → switch-CswmYrO_.js} +2 -2
- package/extensions/dashboard-client/dist/assets/{switch-CmkMKtTG.js.map → switch-CswmYrO_.js.map} +1 -1
- package/extensions/dashboard-client/dist/assets/{toggle-CqpZacm5.js → toggle-CMepFsf0.js} +2 -2
- package/extensions/dashboard-client/dist/assets/{toggle-CqpZacm5.js.map → toggle-CMepFsf0.js.map} +1 -1
- package/extensions/dashboard-client/dist/assets/{useSSE-DCKHmvXr.js → useSSE-Bl55LQFZ.js} +2 -2
- package/extensions/dashboard-client/dist/assets/{useSSE-DCKHmvXr.js.map → useSSE-Bl55LQFZ.js.map} +1 -1
- package/extensions/dashboard-client/dist/index.html +1 -1
- package/extensions/dashboard-client/src/tabs/SetupTab/CortexRetestCard.tsx +104 -0
- package/extensions/dashboard-client/src/tabs/SetupTab/CortexRuntimeInstallCard.tsx +103 -0
- package/extensions/dashboard-client/src/tabs/SetupTab/CortexSetup.tsx +4 -0
- package/extensions/dashboard-server/api-contracts/setup.ts +54 -0
- package/extensions/dashboard-server/routes-rag-settings-vector-cortex.ts +12 -0
- package/extensions/dashboard-server/routes-setup-enc2a.ts +140 -0
- package/extensions/dashboard-server/routes-setup-enc2b.ts +82 -0
- package/extensions/dashboard-server/routes-setup.ts +65 -3
- package/package.json +1 -1
- package/src/config/vector-cortex-enc2a.ts +37 -0
- package/src/config/vector-cortex-enc2b.ts +38 -0
- package/src/config/vector-cortex.ts +4 -0
- package/src/config.ts +2 -0
- package/src/vector-cortex/encoder/native-install-artifacts.ts +60 -0
- package/src/vector-cortex/encoder/native-qualify-retest.ts +264 -0
- package/extensions/dashboard-client/dist/assets/MetricsTab-C2rXqvoD.js +0 -2
- package/extensions/dashboard-client/dist/assets/SetupTab-CgC4Rz38.js +0 -3
- package/extensions/dashboard-client/dist/assets/SetupTab-CgC4Rz38.js.map +0 -1
- package/extensions/dashboard-client/dist/assets/TurnsTab-Cqyq6fVe.js +0 -2
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* vector-cortex/encoder/native-install-artifacts.ts — ENC-2a native
|
|
3
|
+
* onnxruntime install-guide constants (PURE data module).
|
|
4
|
+
*
|
|
5
|
+
* Single source of truth for the operator's native-backend install guide
|
|
6
|
+
* (`onnxruntime-node`, the sole onnxruntime Node.js binding this extension's
|
|
7
|
+
* native path uses). The guide rendered by
|
|
8
|
+
* `extensions/dashboard-server/routes-setup-enc2a.ts` and the operator script
|
|
9
|
+
* `scripts/encoder/install-native-ort.mjs` build their commands/URLs ONLY from
|
|
10
|
+
* these scalars — never an inline registry URL or literal hash in the route or
|
|
11
|
+
* extension runtime (PREVENT-PI-004: the registry tarball URL is derived by
|
|
12
|
+
* callers from `NATIVE_ORT_PACKAGE` + "@" + `NATIVE_ORT_VERSION`, so no network
|
|
13
|
+
* path and no literal registry URL or scheme appears in src/).
|
|
14
|
+
*
|
|
15
|
+
* Package facts (verified, not invented):
|
|
16
|
+
* - onnxruntime-node publishes ONE monolithic ~100MB npm tarball — not
|
|
17
|
+
* per-platform `optionalDependencies` — so a single
|
|
18
|
+
* `NATIVE_ORT_TARBALL_SHA256` pins the whole artifact for every host.
|
|
19
|
+
* - darwin-x64 has NO native binding (arm64-only upstream since 1.17), so the
|
|
20
|
+
* guide stays absent on an Intel Mac (the ENC-0e demotion sentinel).
|
|
21
|
+
* - `NATIVE_ORT_TARBALL_SHA256` was computed from TWO independent downloads of
|
|
22
|
+
* the 1.27.0 tarball (real, cross-checked, not guessed).
|
|
23
|
+
*
|
|
24
|
+
* Pi-agnostic, dependency-free, pure data — zero I/O, zero network
|
|
25
|
+
* (PREVENT-PI-004 / PREVENT-011).
|
|
26
|
+
*/
|
|
27
|
+
|
|
28
|
+
/** onnxruntime-node version the guide installs (real published version). */
|
|
29
|
+
export const NATIVE_ORT_VERSION: string = "1.27.0";
|
|
30
|
+
|
|
31
|
+
/** onnxruntime-node npm package name (the native onnxruntime binding). */
|
|
32
|
+
export const NATIVE_ORT_PACKAGE: string = "onnxruntime-node";
|
|
33
|
+
|
|
34
|
+
/** SHA-256 of the onnxruntime-node@1.27.0 npm tarball (one sha for all hosts).
|
|
35
|
+
* Computed from TWO independent tarball downloads; lowercase hex, 64 chars. */
|
|
36
|
+
export const NATIVE_ORT_TARBALL_SHA256: string =
|
|
37
|
+
"c3779c01c59832f8c03e2c392ac3af10bf08579f1822e8b1c63cc451edb302a2";
|
|
38
|
+
|
|
39
|
+
/**
|
|
40
|
+
* The host platform the guide can render for. darwin-x64 is deliberately NOT
|
|
41
|
+
* installable (no native onnxruntime binding upstream — arm64-only since 1.17);
|
|
42
|
+
* the guide stays absent on an Intel Mac (ENC-0e demotion sentinel).
|
|
43
|
+
*/
|
|
44
|
+
export type EncoderPlatform =
|
|
45
|
+
| "linux-x64"
|
|
46
|
+
| "linux-arm64"
|
|
47
|
+
| "darwin-arm64"
|
|
48
|
+
| "win32-x64"
|
|
49
|
+
| "darwin-x64";
|
|
50
|
+
|
|
51
|
+
/**
|
|
52
|
+
* Platforms for which an operator install-guide can be rendered (native
|
|
53
|
+
* binding exists upstream). darwin-x64 is excluded — it has NO native binding.
|
|
54
|
+
*/
|
|
55
|
+
export const NATIVE_ORT_INSTALLABLE_PLATFORMS: readonly EncoderPlatform[] = [
|
|
56
|
+
"linux-x64",
|
|
57
|
+
"linux-arm64",
|
|
58
|
+
"darwin-arm64",
|
|
59
|
+
"win32-x64",
|
|
60
|
+
];
|
|
@@ -0,0 +1,264 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* vector-cortex/encoder/native-qualify-retest.ts — ENC-2b native onnxruntime
|
|
3
|
+
* qualification retest (reader-only probe).
|
|
4
|
+
*
|
|
5
|
+
* When an operator installs onnxruntime-node via the ENC-2a guide, the encoder
|
|
6
|
+
* read path does not automatically re-evaluate the qualification verdict — the
|
|
7
|
+
* encoder still reports encoderBackend "wasm" until a retest runs. This module
|
|
8
|
+
* is that retest: a pure, bounded, reader-only probe that
|
|
9
|
+
*
|
|
10
|
+
* (a) resolves the installed binding `<native-ort>/node_modules/onnxruntime-node/`;
|
|
11
|
+
* (b) reads its `package.json` version;
|
|
12
|
+
* (c) dynamic-imports the binding;
|
|
13
|
+
* (d) finds a LOCAL onnx model to probe against (under `~/.pi/mega-compact/`);
|
|
14
|
+
* (e) runs a bounded warmup (3 passes) + 10 timed inference passes on a fixed
|
|
15
|
+
* 512-token synthetic input (the bench-onnx.mjs harness shape, in-process);
|
|
16
|
+
* (f) measures p95 (sorted index) and RSS (`process.memoryUsage().rss`);
|
|
17
|
+
* (g) computes a fresh qualification verdict against the ENC-0f p95 budget
|
|
18
|
+
* (`ENCODER_LATENCY_P95_MS`) and the operator install-budget
|
|
19
|
+
* (`installBudgetMib()` as the RSS ceiling — the ENC-2budget derivative).
|
|
20
|
+
*
|
|
21
|
+
* Results: `{platform, version, verdict: "qualified"|"degraded"|"failed",
|
|
22
|
+
* p95Ms, rssMiB, testedAt}` or `null` when no binding is installed. It NEVER
|
|
23
|
+
* throws into the route layer: every binding-load/session/model failure is
|
|
24
|
+
* caught and reported as a `failed` verdict with the error message surfaced in
|
|
25
|
+
* the engine, never raised. NO network (PREVENT-PI-004 — the binding + model
|
|
26
|
+
* are on disk from the operator's ENC-2a install), NO training (HG-1 unchanged).
|
|
27
|
+
*
|
|
28
|
+
* Pi-agnostic, dependency-free. No `any` (PREVENT-011).
|
|
29
|
+
*/
|
|
30
|
+
|
|
31
|
+
import { readFileSync, existsSync } from "node:fs";
|
|
32
|
+
import { join } from "node:path";
|
|
33
|
+
import { ENCODER_LATENCY_P95_MS, ENCODER_MAX_TOKENS } from "./types.js";
|
|
34
|
+
import { installBudgetMib } from "./decision.js";
|
|
35
|
+
import { detectPlatform } from "./asset.js";
|
|
36
|
+
import { NATIVE_ORT_PACKAGE, type EncoderPlatform } from "./native-install-artifacts.js";
|
|
37
|
+
|
|
38
|
+
/** Candidate ONNX runtime native-ort prefixes. The ENC-2a guide installs to
|
|
39
|
+
* the global `~/.pi/mega-compact/native-ort/`; `stateDir` (per-repo) is a
|
|
40
|
+
* secondary probe root so the retest resolves either install location. */
|
|
41
|
+
function nativeOrtRootCandidates(stateDir: string): string[] {
|
|
42
|
+
return [
|
|
43
|
+
join(process.env.HOME ?? "", ".pi", "mega-compact", "native-ort"),
|
|
44
|
+
join(stateDir, "native-ort"),
|
|
45
|
+
];
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
/** A single bounded inference pass on the fixed 512-token synthetic input;
|
|
49
|
+
* returns latency ms, or null when the session cannot run (caller reports
|
|
50
|
+
* failed). The input mirrors bench-onnx.mjs: batch 1, 512 int64 ids. */
|
|
51
|
+
async function timedPass(
|
|
52
|
+
ort: unknown,
|
|
53
|
+
session: unknown,
|
|
54
|
+
ids: BigInt64Array,
|
|
55
|
+
mask: BigInt64Array,
|
|
56
|
+
types: BigInt64Array,
|
|
57
|
+
): Promise<number | null> {
|
|
58
|
+
try {
|
|
59
|
+
const dims = [1, ENCODER_MAX_TOKENS];
|
|
60
|
+
const o = ort as {
|
|
61
|
+
Tensor: new (type: string, data: BigInt64Array, dims: number[]) => unknown;
|
|
62
|
+
};
|
|
63
|
+
const s = session as {
|
|
64
|
+
inputNames: readonly string[];
|
|
65
|
+
run: (feeds: Record<string, unknown>) => Promise<unknown>;
|
|
66
|
+
};
|
|
67
|
+
const feeds: Record<string, unknown> = {};
|
|
68
|
+
if (s.inputNames.includes("input_ids")) {
|
|
69
|
+
feeds.input_ids = new o.Tensor("int64", ids, dims);
|
|
70
|
+
}
|
|
71
|
+
if (s.inputNames.includes("attention_mask")) {
|
|
72
|
+
feeds.attention_mask = new o.Tensor("int64", mask, dims);
|
|
73
|
+
}
|
|
74
|
+
if (s.inputNames.includes("token_type_ids")) {
|
|
75
|
+
feeds.token_type_ids = new o.Tensor("int64", types, dims);
|
|
76
|
+
}
|
|
77
|
+
const t = process.hrtime.bigint();
|
|
78
|
+
await s.run(feeds);
|
|
79
|
+
return Number(process.hrtime.bigint() - t) / 1e6;
|
|
80
|
+
} catch {
|
|
81
|
+
return null;
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
/** The retest verdict covering the ENC-0f p95 budget + the RSS ceiling. */
|
|
86
|
+
export type RetestVerdict = "qualified" | "degraded" | "failed";
|
|
87
|
+
|
|
88
|
+
/** The ENC-2b retest result surfaced on the GET read path + retest card. */
|
|
89
|
+
export interface RetestResult {
|
|
90
|
+
readonly platform: string;
|
|
91
|
+
readonly version: string;
|
|
92
|
+
readonly verdict: RetestVerdict;
|
|
93
|
+
readonly p95Ms: number;
|
|
94
|
+
readonly rssMiB: number;
|
|
95
|
+
readonly testedAt: string;
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
/** Resolve the first existing installed-binding package root, or the first
|
|
99
|
+
* candidate's path (for a missing-binding probe) when none exists. */
|
|
100
|
+
function bindingRootDir(stateDir: string): string {
|
|
101
|
+
for (const root of nativeOrtRootCandidates(stateDir)) {
|
|
102
|
+
const pkg = join(root, "node_modules", NATIVE_ORT_PACKAGE);
|
|
103
|
+
if (existsSync(pkg)) return pkg;
|
|
104
|
+
}
|
|
105
|
+
return join(nativeOrtRootCandidates(stateDir)[0], "node_modules", NATIVE_ORT_PACKAGE);
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
/** Read the installed binding version from its package.json; null when absent. */
|
|
109
|
+
function readInstalledVersion(pkgJsonPath: string): string | null {
|
|
110
|
+
try {
|
|
111
|
+
const raw = JSON.parse(readFileSync(pkgJsonPath, "utf8")) as unknown;
|
|
112
|
+
if (
|
|
113
|
+
typeof raw === "object" &&
|
|
114
|
+
raw !== null &&
|
|
115
|
+
typeof (raw as { version?: unknown }).version === "string"
|
|
116
|
+
) {
|
|
117
|
+
return (raw as { version: string }).version;
|
|
118
|
+
}
|
|
119
|
+
return null;
|
|
120
|
+
} catch {
|
|
121
|
+
return null;
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
/** Locate a LOCAL onnx model to probe against, under the native-ort roots.
|
|
126
|
+
* Null when none exists (the retest cannot qualify without a probe target). */
|
|
127
|
+
function findLocalModel(stateDir: string): string | null {
|
|
128
|
+
const candidates = [
|
|
129
|
+
join(nativeOrtRootCandidates(stateDir)[0], "model.onnx"),
|
|
130
|
+
join(stateDir, "model.onnx"),
|
|
131
|
+
];
|
|
132
|
+
for (const c of candidates) {
|
|
133
|
+
if (existsSync(c)) return c;
|
|
134
|
+
}
|
|
135
|
+
return null;
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
/** p95 of sorted latencies (sorted-index percentile, bench-onnx idiom). */
|
|
139
|
+
function p95Of(sorted: number[]): number {
|
|
140
|
+
if (sorted.length === 0) return 0;
|
|
141
|
+
const idx = Math.min(sorted.length - 1, Math.floor(sorted.length * 0.95));
|
|
142
|
+
return +sorted[idx].toFixed(2);
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
/**
|
|
146
|
+
* Run the native onnxruntime qualification retest. Returns `RetestResult` on a
|
|
147
|
+
* completed (pass/fail/degrade) probe, or `null` when no binding is installed.
|
|
148
|
+
* Never throws: binding-load / session / model failures produce a `failed`
|
|
149
|
+
* verdict with the message on the result, and the `testedAt`/RSS are filled.
|
|
150
|
+
*/
|
|
151
|
+
export async function runNativeRetest(stateDir: string): Promise<RetestResult | null> {
|
|
152
|
+
const rootDir = bindingRootDir(stateDir);
|
|
153
|
+
const pkgJsonPath = join(rootDir, "package.json");
|
|
154
|
+
if (!existsSync(pkgJsonPath)) return null;
|
|
155
|
+
|
|
156
|
+
const version = readInstalledVersion(pkgJsonPath);
|
|
157
|
+
const platform: EncoderPlatform | null = detectPlatform();
|
|
158
|
+
const platformStr = platform ?? `${process.platform}-${process.arch}`;
|
|
159
|
+
const testedAt = new Date().toISOString();
|
|
160
|
+
const rssMiB = +((process.memoryUsage().rss / 1048576).toFixed(1));
|
|
161
|
+
|
|
162
|
+
// Binding present but version unreadable — report failed (never throw).
|
|
163
|
+
if (version === null) {
|
|
164
|
+
return {
|
|
165
|
+
platform: platformStr,
|
|
166
|
+
version: "unknown",
|
|
167
|
+
verdict: "failed",
|
|
168
|
+
p95Ms: 0,
|
|
169
|
+
rssMiB,
|
|
170
|
+
testedAt,
|
|
171
|
+
};
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
// Load the LOCAL binding via dynamic import. Load failure -> failed verdict.
|
|
175
|
+
let ort: unknown;
|
|
176
|
+
try {
|
|
177
|
+
ort = await import(join(rootDir, "lib", "index.js"));
|
|
178
|
+
} catch {
|
|
179
|
+
try {
|
|
180
|
+
ort = await import(join(rootDir, "dist", "ort.node.mjs"));
|
|
181
|
+
} catch {
|
|
182
|
+
return {
|
|
183
|
+
platform: platformStr,
|
|
184
|
+
version,
|
|
185
|
+
verdict: "failed",
|
|
186
|
+
p95Ms: 0,
|
|
187
|
+
rssMiB,
|
|
188
|
+
testedAt,
|
|
189
|
+
};
|
|
190
|
+
}
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
// Find a local probe model; without one the binding cannot be qualified.
|
|
194
|
+
const modelPath = findLocalModel(stateDir);
|
|
195
|
+
if (modelPath === null) {
|
|
196
|
+
return {
|
|
197
|
+
platform: platformStr,
|
|
198
|
+
version,
|
|
199
|
+
verdict: "failed",
|
|
200
|
+
p95Ms: 0,
|
|
201
|
+
rssMiB,
|
|
202
|
+
testedAt,
|
|
203
|
+
};
|
|
204
|
+
}
|
|
205
|
+
|
|
206
|
+
// Create the session (bounded); failure -> failed.
|
|
207
|
+
try {
|
|
208
|
+
const factory = ort as {
|
|
209
|
+
InferenceSession: {
|
|
210
|
+
create: (
|
|
211
|
+
path: string,
|
|
212
|
+
opts: { executionProviders: string[]; intraOpNumThreads: number; graphOptimizationLevel: string },
|
|
213
|
+
) => Promise<unknown>;
|
|
214
|
+
};
|
|
215
|
+
};
|
|
216
|
+
const session = await factory.InferenceSession.create(modelPath, {
|
|
217
|
+
executionProviders: ["cpu"],
|
|
218
|
+
intraOpNumThreads: 4,
|
|
219
|
+
graphOptimizationLevel: "all",
|
|
220
|
+
});
|
|
221
|
+
const n = ENCODER_MAX_TOKENS;
|
|
222
|
+
const ids = BigInt64Array.from({ length: n }, (_, i) =>
|
|
223
|
+
BigInt(i === 0 ? 101 : i === n - 1 ? 102 : 2000 + (i % 500)),
|
|
224
|
+
);
|
|
225
|
+
const mask = BigInt64Array.from({ length: n }, () => 1n);
|
|
226
|
+
const types = new BigInt64Array(n);
|
|
227
|
+
|
|
228
|
+
// Bounded warmup (3 passes) + 10 timed passes.
|
|
229
|
+
for (let i = 0; i < 3; i++) await timedPass(ort, session, ids, mask, types);
|
|
230
|
+
const lat: number[] = [];
|
|
231
|
+
for (let i = 0; i < 10; i++) {
|
|
232
|
+
const ms = await timedPass(ort, session, ids, mask, types);
|
|
233
|
+
if (ms === null) break;
|
|
234
|
+
lat.push(ms);
|
|
235
|
+
}
|
|
236
|
+
if (lat.length === 0) {
|
|
237
|
+
return {
|
|
238
|
+
platform: platformStr,
|
|
239
|
+
version,
|
|
240
|
+
verdict: "failed",
|
|
241
|
+
p95Ms: 0,
|
|
242
|
+
rssMiB,
|
|
243
|
+
testedAt,
|
|
244
|
+
};
|
|
245
|
+
}
|
|
246
|
+
lat.sort((a, b) => a - b);
|
|
247
|
+
const p95Ms = p95Of(lat);
|
|
248
|
+
const rssBudgetMib = installBudgetMib();
|
|
249
|
+
const verdict: RetestVerdict =
|
|
250
|
+
p95Ms <= ENCODER_LATENCY_P95_MS && rssMiB <= rssBudgetMib
|
|
251
|
+
? "qualified"
|
|
252
|
+
: "degraded";
|
|
253
|
+
return { platform: platformStr, version, verdict, p95Ms, rssMiB, testedAt };
|
|
254
|
+
} catch {
|
|
255
|
+
return {
|
|
256
|
+
platform: platformStr,
|
|
257
|
+
version,
|
|
258
|
+
verdict: "failed",
|
|
259
|
+
p95Ms: 0,
|
|
260
|
+
rssMiB,
|
|
261
|
+
testedAt,
|
|
262
|
+
};
|
|
263
|
+
}
|
|
264
|
+
}
|
|
@@ -1,2 +0,0 @@
|
|
|
1
|
-
import{j as r}from"./index-CeBW9Vtt.js";import{M as t}from"./MetricsCards-YlmnUe01.js";import"./card-Cg_LPWdl.js";import"./generateCategoricalChart-sE5oI3Ee.js";import"./BarChart-IWwm38i0.js";import"./AreaChart-B1OkLRGT.js";function e(){return r.jsx(t,{})}export{e as default};
|
|
2
|
-
//# sourceMappingURL=MetricsTab-C2rXqvoD.js.map
|
|
@@ -1,3 +0,0 @@
|
|
|
1
|
-
import{r as s,j as e,o as L,p as Y,q as ae,s as oe,C as le,t as ie,e as Z,v as de,w as ee,x as V,y as ce,u as X,z as te,A as se}from"./index-CeBW9Vtt.js";import{C as me}from"./ConfigTab-C1t0EM2H.js";import{S as ue}from"./switch-CmkMKtTG.js";import{b as he,p as pe,d as ge}from"./client-extra-DxQFx7HY.js";import{V as fe}from"./VcStatusBadge-CBtRo20h.js";import{T as xe}from"./toggle-CqpZacm5.js";function be(t){try{return new Date(t*1e3).toLocaleString()}catch{return"—"}}function re({achievements:t}){const n=s.useRef(0),[r,o]=s.useState(null),a=t.reduce((i,d)=>Math.max(i,d.unlocked_at??0),0),l=n.current;s.useEffect(()=>{a>n.current&&(n.current=a)},[a]),s.useEffect(()=>{if(l>0&&a>l){const i=t.filter(d=>d.unlocked_at!=null&&(d.unlocked_at??0)>l);if(i.length>0){const d=i.map(m=>`${m.icon??""} ${m.title}`.trim()).join(", ")+" unlocked!";o(d);const g=setTimeout(()=>o(null),4e3);return()=>clearTimeout(g)}}},[t,a,l]);const c=t.filter(i=>!(i.hidden===1&&i.unlocked_at==null));return e.jsxs("div",{className:"ach-section",children:[r!=null&&e.jsx("div",{className:"ach-toast show",children:r}),e.jsxs("div",{className:"ach-tiles",children:[c.length===0&&e.jsx("span",{className:"repo-none",children:"no achievements yet"}),c.map(i=>{if(i.unlocked_at!=null){const d=l>0&&(i.unlocked_at??0)>l;return e.jsxs("div",{className:`ach-tile unlocked${d?" just-unlocked":""}`,children:[i.icon??""," ",i.title,e.jsxs("span",{className:"ach-detail",children:["unlocked ",be(i.unlocked_at)]})]},i.id)}return e.jsxs("div",{className:"ach-tile locked",children:["??? ",i.title]},i.id)})]})]})}function P(t){return(Math.round(t*10)/10).toString()+"%"}function F(t){return t!=null?new Date(t).toLocaleString():"—"}function H(t){return t&&typeof t=="object"?t:{}}function ye(t){return t.split("/").pop()||t}function _({title:t,rows:n,badge:r,renderValue:o}){return e.jsxs("div",{className:"lb-card",children:[e.jsxs("h3",{children:[t,r]}),n.length===0?e.jsx("div",{className:"lb-empty",children:"—"}):e.jsx("table",{children:e.jsx("tbody",{children:n.map((a,l)=>e.jsxs("tr",{children:[e.jsx("td",{title:a.repo_root,children:ye(a.repo_root)}),e.jsx("td",{className:"num",children:o(a)})]},`${a.repo_root}-${l}`))})})]})}function je(){const[t,n]=s.useState({}),[r,o]=s.useState(0),[a,l]=s.useState([]),[c,i]=s.useState(!1),[d,g]=s.useState(!0),[m,x]=s.useState(null),f=s.useRef(0),b=s.useCallback(async()=>{try{const[y,p,R,z,W,U]=await Promise.all([L({metric:"cache",limit:25}),L({metric:"dedupe",limit:25}),L({metric:"turns",limit:25}),L({metric:"mega_cache",limit:25}),L({metric:"repos",limit:1}),Y()]),D=z.find(O=>O.ts>f.current&&O.value>100);f.current>0&&D&&(x(`oopsie! cache went to ${Math.round(D.value)}% — MEGA CACHE 🥧`),setTimeout(()=>x(null),4e3)),z.length>0&&(f.current=Math.max(...z.map(O=>O.ts))),n({cache:y,dedupe:p,turns:R,mega_cache:z}),o(W[0]?.value??0),l(U)}catch{}finally{g(!1)}},[]);s.useEffect(()=>{let y=!0;const p=async()=>{y&&await b()};p();const R=setInterval(()=>void p(),15e3);return()=>{y=!1,clearInterval(R)}},[b]),s.useEffect(()=>{let y=!0;const p=async()=>{try{const z=await ae();y&&(i(!!z.game_mode_on),z.theme&&(document.documentElement.dataset.theme=z.theme))}catch{}};p();const R=setInterval(()=>void p(),15e3);return()=>{y=!1,clearInterval(R)}},[]);const v=t.mega_cache??[];let S=null,w=null;for(const y of v){(S==null||y.value>S)&&(S=y.value);const p=H(y.meta),R=p.firstSeenTs??p.firstSeen??y.ts;(w==null||R<w)&&(w=R)}const E=S!=null&&S>100,h=t.turns??[],T=h.reduce((y,p)=>Math.max(y,p.value),0),N=Math.floor(Math.log2(T+1))+1,M=(t.cache?.length??0)>0||(t.dedupe?.length??0)>0||h.length>0||v.length>0||r>0;return e.jsxs("div",{className:`game-tab${c?" game-mode-on":""}`,children:[m!=null&&e.jsx("div",{className:"mega-cache-toast show",children:m}),E&&e.jsxs("div",{className:"mega-cache-banner",children:["🥧"," MEGA CACHE! peak ",P(S)," — first reached ",F(w)]}),E&&e.jsxs("div",{className:"achievement-tile unlocked",children:["🏆"," Opie's Wild Ride",e.jsxs("span",{className:"ach-detail",children:["best ",P(S)," · first ",F(w)]})]}),e.jsx("h2",{children:"High Scores"}),!M&&!d&&e.jsx("div",{className:"game-empty",children:"No scores yet — run a session with game mode on."}),M&&e.jsxs("div",{className:"game-leaderboards",children:[e.jsx(_,{title:"Cache %",rows:t.cache??[],renderValue:y=>P(y.value)}),e.jsx(_,{title:"Dedupe (collapsed)",rows:t.dedupe??[],renderValue:y=>y.value.toLocaleString()}),e.jsx(_,{title:"Turns",rows:h,badge:h.length>0?e.jsxs("span",{className:"lvl-badge",children:["LVL ",N]}):void 0,renderValue:y=>y.value.toLocaleString()}),e.jsx(_,{title:"MEGA CACHE trophies",rows:v,renderValue:y=>e.jsxs(e.Fragment,{children:[P(y.value),e.jsx("span",{className:"lb-meta",children:F(H(y.meta).firstSeenTs??H(y.meta).firstSeen??y.ts)})]})})]}),r>0&&e.jsx("div",{className:"repos-badge-line",children:e.jsxs("span",{className:"repos-badge",children:[r," repos"]})}),e.jsx("h3",{children:"Achievements"}),e.jsx(re,{achievements:a})]})}function ve(){const[t,n]=s.useState([]),[r,o]=s.useState(!0),[a,l]=s.useState(null),c=s.useCallback(async()=>{try{const i=await Y();n(i),l(null)}catch(i){l(i instanceof Error?i:new Error(String(i)))}finally{o(!1)}},[]);return s.useEffect(()=>{let i=!0;const d=async()=>{i&&await c()};d();const g=setInterval(()=>void d(),15e3);return()=>{i=!1,clearInterval(g)}},[c]),r&&t.length===0?e.jsx("div",{className:"tab-stub",children:"Loading achievements…"}):a&&t.length===0?e.jsxs("div",{className:"tab-stub",children:["Error: ",a.message]}):e.jsxs("div",{className:"achievements-tab",children:[e.jsx("h2",{children:"Achievements"}),e.jsx(re,{achievements:t})]})}const A={section:{background:"#1a1a2e",borderRadius:"8px",padding:"1rem",marginBottom:"1rem",border:"1px solid #2a2a4e"},sectionTitle:{fontSize:"1.1rem",fontWeight:700,marginTop:0,marginBottom:"0.75rem",color:"#e0e0e0",borderBottom:"1px solid #333",paddingBottom:"0.5rem"},label:{fontWeight:600,color:"#a0a0c0",marginRight:"0.5rem"},value:{color:"#e0e0e0"},row:{marginBottom:"0.4rem",fontSize:"0.9rem"}};function Se(){const[t,n]=s.useState(null),[r,o]=s.useState(null),a=s.useCallback(()=>{oe().then(n).catch(g=>o(g instanceof Error?g.message:String(g)))},[]);s.useEffect(()=>{a()},[a]),s.useEffect(()=>{const g=setInterval(a,3e4);return()=>clearInterval(g)},[a]);const l=t?.status==="ok",c=t?.status==="ok"?"Working":t?.status==="unreachable"?"Unreachable":"Error",i=l?"#4caf50":"#f44336",d=l?"✓":"✗";return e.jsxs("div",{style:A.section,children:[e.jsx("h3",{style:A.sectionTitle,children:"Embedder Health"}),r&&e.jsxs("p",{style:{color:"#f44336",fontSize:"0.85rem"},children:["Error: ",r]}),!t&&!r&&e.jsx("p",{style:{color:"#888",fontSize:"0.85rem"},children:"Probing embedder..."}),t&&e.jsxs(e.Fragment,{children:[e.jsxs("div",{style:A.row,children:[e.jsxs("span",{style:{...A.label,color:`${i}`},children:[d," ",c,":"]}),e.jsxs("span",{style:A.value,children:[t.dim," dims"]}),t.latencyMs!==void 0&&e.jsxs("span",{style:{color:"#a0a0c0",marginLeft:"0.5rem"},children:["(",t.latencyMs.toFixed(1)," ms)"]})]}),e.jsxs("div",{style:A.row,children:[e.jsx("span",{style:A.label,children:"Endpoint:"}),e.jsx("span",{style:A.value,children:t.url??e.jsx("span",{style:{color:"#888"},children:"built-in (no URL)"})})]}),t.error&&e.jsx("p",{style:{color:"#f44336",fontSize:"0.85rem"},children:t.error})]})]})}function we({title:t,children:n}){const[r,o]=s.useState(!0),a=`settings-${t.toLowerCase().replace(/[^a-z0-9]+/g,"-")}`;return e.jsxs("section",{className:"overflow-hidden rounded-xl border border-border bg-bg-elevated/40",children:[e.jsxs("button",{type:"button",onClick:()=>o(l=>!l),className:"flex w-full items-center justify-between rounded-t-xl bg-bg-elevated/60 px-4 py-3 text-left text-sm font-semibold text-foreground transition-colors hover:bg-bg-elevated","aria-expanded":r,"aria-controls":a,children:[e.jsx("span",{children:t}),e.jsx(le,{className:ie("h-4 w-4 text-muted-foreground transition-transform",r&&"rotate-180"),"aria-hidden":"true"})]}),r&&e.jsx("div",{id:a,className:"divide-y divide-border px-4 py-1",children:n})]})}const ke="rounded-md border border-border bg-bg-elevated/50 px-2 py-1 text-sm outline-none transition-colors focus:border-primary disabled:cursor-not-allowed disabled:opacity-50";function Ce(){return e.jsx("span",{className:"ml-2 inline-flex items-center rounded-md border border-warning/40 bg-warning/15 px-1.5 py-0.5 text-[10px] font-semibold uppercase tracking-wide text-warning",title:"Requires an LLM embedder (Ollama/HTTP) to be effective",children:"LLM"})}function Ee({setting:t,id:n,llmActive:r,saving:o,onUpdate:a}){const[l,c]=s.useState(null),i=t.requiresLlm&&!r,d=s.useRef(null);s.useEffect(()=>()=>{d.current&&clearTimeout(d.current)},[]);const g=s.useCallback(f=>{a(t.key,f).then(b=>c(b)).catch(b=>c(b instanceof Error?b.message:String(b)))},[a,t.key]),m=s.useCallback(f=>{d.current&&clearTimeout(d.current),d.current=setTimeout(()=>g(f),500)},[g]),x=o||i;return e.jsxs("div",{className:"py-2.5",children:[e.jsxs("div",{className:"flex items-start justify-between gap-3",children:[e.jsxs("div",{children:[e.jsxs("div",{className:"flex items-center text-sm font-semibold text-foreground",children:[e.jsx("label",{htmlFor:`${n}-input`,className:"cursor-pointer",children:t.label}),t.requiresLlm&&!r&&e.jsx(Ce,{})]}),e.jsx("div",{className:"mt-0.5 text-xs text-muted-foreground",children:t.description})]}),e.jsx("div",{className:"flex shrink-0 items-center gap-2",children:t.type==="boolean"?e.jsx(ue,{id:`${n}-input`,checked:!!t.value,disabled:x||i,onCheckedChange:f=>g(String(f)),"aria-label":t.label}):e.jsxs(e.Fragment,{children:[e.jsx("input",{id:`${n}-input`,type:t.type==="number"?"number":"text",defaultValue:String(t.value??""),min:t.min,max:t.max,disabled:x,onChange:f=>m(f.target.value),className:`${ke} ${t.type==="number"?"w-24":"w-56"}`}),t.unit&&e.jsx("span",{className:"text-xs text-muted-foreground",children:t.unit})]})})]}),l&&e.jsxs("p",{className:"mt-1 text-xs text-danger",children:["Error: ",l]})]})}function Ne(){const[t,n]=s.useState(null),[r,o]=s.useState(null),[a,l]=s.useState(!1),[c,i]=s.useState(null),d=s.useCallback(()=>{Z().then(n).catch(m=>o(m instanceof Error?m.message:String(m)))},[]);s.useEffect(()=>{d()},[d]);const g=s.useCallback(async(m,x)=>{l(!0);try{const f=await de({key:m,value:x});return i(f.restartRequired?"Saved — restart pi to apply changes.":"Saved."),d(),null}catch(f){return f instanceof Error?f.message:String(f)}finally{l(!1)}},[d]);return e.jsxs("div",{className:"flex flex-col gap-3",children:[r&&e.jsxs("p",{className:"text-sm text-danger",children:["Error: ",r]}),!t&&!r&&e.jsx("p",{className:"text-sm text-muted-foreground",children:"Loading settings..."}),t?.categories.map(m=>e.jsx(we,{title:m.name,children:m.settings.map(x=>e.jsx(Ee,{setting:x,id:`${m.name.replace(/[^a-z0-9]+/gi,"-")}-${x.key}`,llmActive:t.llmActive,saving:a,onUpdate:g},x.key))},m.name)),c&&e.jsx("div",{className:"mt-1 rounded-md border border-warning/40 bg-warning/10 p-2 text-xs text-warning",role:"status",children:c})]})}const u={container:{padding:"1rem",maxWidth:"720px",margin:"0 auto",fontFamily:"system-ui, sans-serif",color:"#e0e0e0"},section:{background:"#1a1a2e",borderRadius:"8px",padding:"1rem",marginBottom:"1rem",border:"1px solid #2a2a4e"},sectionTitle:{fontSize:"1.1rem",fontWeight:700,marginTop:0,marginBottom:"0.75rem",color:"#e0e0e0",borderBottom:"1px solid #333",paddingBottom:"0.5rem"},label:{fontWeight:600,color:"#a0a0c0",marginRight:"0.5rem"},value:{color:"#e0e0e0"},row:{marginBottom:"0.4rem",fontSize:"0.9rem"},warning:{background:"#3a2a00",border:"1px solid #665500",borderRadius:"8px",padding:"0.75rem",marginTop:"0.5rem",color:"#ffcc00",fontSize:"0.85rem"},badge:{display:"inline-block",padding:"0.15rem 0.5rem",borderRadius:"4px",fontSize:"0.8rem",fontWeight:600,marginLeft:"0.5rem"},detectRow:{display:"flex",justifyContent:"space-between",alignItems:"center",padding:"0.5rem 0",borderBottom:"1px solid #2a2a4e"},button:{background:"#3a5a9f",color:"#fff",border:"none",borderRadius:"6px",padding:"0.5rem 1rem",cursor:"pointer",fontSize:"0.9rem",fontWeight:600}},Te="Saved; takes effect on next session start";function Re({customUrl:t,setCustomUrl:n,applyEmbedder:r,configuring:o,inputEnabled:a,apiKeySet:l,embeddingDim:c,embeddingHeadersSet:i,allowRemoteEmbedder:d,configureResult:g,configureError:m}){const[x,f]=s.useState(""),[b,v]=s.useState(""),[S,w]=s.useState(!1),[E,h]=s.useState(""),[T,N]=s.useState(!1),[M,y]=s.useState(!1);return a&&!S&&typeof c=="string"&&(v(c),w(!0)),a&&!M&&typeof d=="boolean"&&(N(d),y(!0)),e.jsxs("div",{style:u.section,children:[e.jsx("h3",{style:u.sectionTitle,children:"Custom Endpoint (remote / third-party)"}),e.jsxs("p",{style:{fontSize:"0.85rem",color:"#a0a0c0",marginTop:0},children:["Point at any OpenAI-compatible embeddings API or hosted endpoint. This opts in to a non-loopback connection (sets"," ",e.jsx("code",{children:"MEGACOMPACT_ALLOW_REMOTE_EMBEDDER=1"}),") — your prompts' embedding requests will be sent to the URL you enter. Default is loopback-only."]}),e.jsxs("div",{style:{display:"flex",gap:"0.5rem",flexWrap:"wrap",alignItems:"center"},children:[e.jsx("input",{type:"url",placeholder:"https://api.example.com/v1/embeddings",value:t,onChange:p=>n(p.target.value),style:{flex:"1 1 300px",background:"#12122a",color:"#e0e0e0",border:"1px solid #2a2a4e",borderRadius:"6px",padding:"0.4rem 0.6rem",fontSize:"0.85rem",fontFamily:"monospace"}}),a&&e.jsx("input",{type:"password",autoComplete:"new-password","aria-label":"API key (optional Bearer)",placeholder:"API key (optional Bearer)",value:x,onChange:p=>f(p.target.value),style:{flex:"1 1 300px",background:"#12122a",color:"#e0e0e0",border:"1px solid #2a2a4e",borderRadius:"6px",padding:"0.4rem 0.6rem",fontSize:"0.85rem",fontFamily:"monospace"}}),a&&l&&e.jsx("span",{style:{fontSize:"0.75rem",color:"#81c784",border:"1px solid #2a4e2a",borderRadius:"4px",padding:"0.15rem 0.45rem"},children:"API key saved"}),a&&i&&e.jsx("span",{style:{fontSize:"0.75rem",color:"#81c784",border:"1px solid #2a4e2a",borderRadius:"4px",padding:"0.15rem 0.45rem"},children:"Headers saved"}),e.jsx("button",{style:{...u.button,opacity:t?1:.4},onClick:()=>r("custom",t,x,b,E,T),disabled:!t||o!==null,children:o==="custom"?"Writing...":"Use Custom URL"})]}),a&&e.jsxs("div",{style:{marginTop:"0.75rem"},children:[e.jsxs("div",{style:{marginBottom:"0.5rem"},children:[e.jsx("label",{style:{...u.label,display:"block",marginBottom:"0.25rem"},children:"Embedding dim (optional)"}),e.jsx("input",{type:"number",min:1,placeholder:"e.g. 384",value:b,onChange:p=>v(p.target.value),style:{width:"200px",background:"#12122a",color:"#e0e0e0",border:"1px solid #2a2a4e",borderRadius:"6px",padding:"0.4rem 0.6rem",fontSize:"0.85rem",fontFamily:"monospace"}})]}),e.jsxs("div",{style:{marginBottom:"0.5rem"},children:[e.jsx("label",{style:{...u.label,display:"block",marginBottom:"0.25rem"},children:"Embedding headers (JSON, write-only — never re-displayed)"}),e.jsx("textarea",{placeholder:'{"Authorization": "Bearer ..."}',value:E,onChange:p=>h(p.target.value),"aria-label":"Embedding headers JSON (write-only — never re-displayed)",rows:2,style:{width:"100%",background:"#12122a",color:"#e0e0e0",border:"1px solid #2a2a4e",borderRadius:"6px",padding:"0.4rem 0.6rem",fontSize:"0.85rem",fontFamily:"monospace",resize:"vertical"}})]}),e.jsxs("label",{style:{display:"flex",alignItems:"center",gap:"0.5rem",fontSize:"0.85rem"},children:[e.jsx("input",{type:"checkbox",checked:T,onChange:p=>N(p.target.checked),"aria-label":"Allow remote embedder (skips loopback-only check)"}),"Allow remote embedder (skips loopback-only check)"]})]}),m!==null&&e.jsxs("p",{style:{color:"#f44336",fontSize:"0.85rem",marginTop:"0.5rem"},children:["Configure error: ",m]}),g!==null&&g.embedder==="custom"&&e.jsx("div",{style:u.warning,children:Te}),e.jsxs("div",{style:u.warning,children:[e.jsx("strong",{children:"Heads up:"})," a remote endpoint receives the text you embed (it does NOT receive your full conversation — only the strings passed to",e.jsx("code",{children:" embed()"})," for recall/dedup). Verify the endpoint's privacy policy before use."]})]})}function K(t){switch(t){case"trigram":return"TrigramEmbedder (heuristic, default)";case"http":return"HTTP Embedder (BYO localhost)";case"minilm":return"MiniLM (experimental)";default:return"Unknown"}}function Be(t){return t?.currentEmbedder!=="trigram"?null:e.jsxs("div",{style:u.warning,children:[e.jsx("strong",{children:"Note:"})," TrigramEmbedder is a heuristic-strength default embedder. It works without any setup but recall quality may be lower than a dedicated embedding backend. If you notice poor recall results, consider installing Ollama and running the"," ",e.jsx("code",{children:"/megasetup"})," command, or set"," ",e.jsx("code",{children:"MEGACOMPACT_EMBEDDING_URL"})," to point at your own localhost embedding server."]})}function G(t){const n=t?"#1a5a1a":"#3a1a1a",r=t?"#4caf50":"#f44336";return e.jsx("span",{style:{...u.badge,background:n,color:r},children:t?"Detected":"Not found"})}function Me({status:t,statusError:n}){return e.jsxs("div",{style:u.section,children:[e.jsx("h3",{style:u.sectionTitle,children:"Current Embedder Configuration"}),n&&e.jsxs("p",{style:{color:"#f44336",fontSize:"0.85rem"},children:["Error: ",n]}),t&&e.jsxs(e.Fragment,{children:[e.jsxs("div",{style:u.row,children:[e.jsx("span",{style:u.label,children:"Active Embedder:"}),e.jsx("span",{style:u.value,children:K(t.currentEmbedder)})]}),"configuredEmbedder"in t&&t.configuredEmbedder!==t.currentEmbedder&&e.jsxs("div",{style:u.warning,children:[e.jsx("strong",{children:"Configured but not active:"})," ",K(t.configuredEmbedder)," is configured in .mega-compact.env but not yet loaded."," ",e.jsx("strong",{children:"Restart pi"})," to activate it.",t.configuredUrl&&e.jsxs(e.Fragment,{children:[" (",t.configuredUrl,")"]})]}),"restartRequired"in t&&t.restartRequired&&e.jsxs("div",{style:{...u.row,color:"#ff9800"},children:[e.jsx("span",{style:u.label,children:"Status:"}),e.jsx("span",{style:u.value,children:"Restart required to activate the configured embedder"})]}),e.jsxs("div",{style:u.row,children:[e.jsx("span",{style:u.label,children:"Embedding URL:"}),e.jsx("span",{style:u.value,children:t.embeddingUrl??e.jsx("span",{style:{color:"#888"},children:"not set"})})]}),e.jsxs("div",{style:u.row,children:[e.jsx("span",{style:u.label,children:"Embed Cache:"}),e.jsx("span",{style:u.value,children:t.embedCache??e.jsx("span",{style:{color:"#888"},children:"not set"})})]}),e.jsxs("div",{style:u.row,children:[e.jsx("span",{style:u.label,children:"MiniLM:"}),e.jsx("span",{style:u.value,children:t.minilm?"enabled":"disabled"})]}),Be(t)]}),!t&&!n&&e.jsx("p",{style:{color:"#888",fontSize:"0.85rem"},children:"Loading configuration..."})]})}function ze(){const[t,n]=s.useState(null),[r,o]=s.useState(null),[a,l]=s.useState(null),[c,i]=s.useState(null),[d,g]=s.useState(!1),[m,x]=s.useState(null),[f,b]=s.useState(null),[v,S]=s.useState(null),[w,E]=s.useState(""),[h,T]=s.useState(!1),N=s.useCallback(()=>{ee().then(n).catch(p=>l(p instanceof Error?p.message:String(p)))},[]),M=s.useCallback((p,R,z,W,U,D)=>{x(p),S(null),b(null);const O="embeddingHeadersSet"in(t??{});V({embedder:p,url:R,embeddingEndpointUrl:R,embeddingApiKey:z,...O?{embeddingDim:W,embeddingHeaders:U,allowRemoteEmbedder:D}:{}}).then(I=>{b(I),x(null),N()}).catch(I=>{S(I instanceof Error?I.message:String(I)),x(null)})},[N,t]),y=s.useCallback(()=>{g(!0),i(null),ce().then(p=>{o(p),g(!1)}).catch(p=>{i(p instanceof Error?p.message:String(p)),g(!1)})},[]);return s.useEffect(()=>{N()},[N]),s.useEffect(()=>{h||t&&typeof t.embeddingEndpointUrl=="string"&&t.embeddingEndpointUrl.length>0&&(E(t.embeddingEndpointUrl),T(!0))},[t,h]),s.useEffect(()=>{const p=setInterval(N,5e3);return()=>clearInterval(p)},[N]),s.useEffect(()=>{y();const p=setInterval(y,5e3);return()=>clearInterval(p)},[y]),e.jsxs("div",{style:u.container,children:[e.jsx("h2",{style:{fontSize:"1.3rem",marginTop:0,marginBottom:"1rem"},children:"Embedder Setup"}),e.jsx(Se,{}),e.jsx(Me,{status:t,statusError:a}),e.jsxs("div",{style:u.section,children:[e.jsx("h3",{style:u.sectionTitle,children:"Local Embedder Detection"}),e.jsx("p",{style:{fontSize:"0.85rem",color:"#a0a0c0",marginTop:0},children:"Detect which local embedding backends are available on this machine. No software is installed — detection only."}),r&&e.jsxs(e.Fragment,{children:[e.jsxs("div",{style:u.detectRow,children:[e.jsx("span",{children:e.jsx("strong",{children:"Ollama"})}),r.ollama!==null?e.jsxs("span",{children:[G(r.ollama.installed),r.ollama.installed&&e.jsx("span",{style:{fontSize:"0.8rem",color:"#a0a0c0",marginLeft:"0.5rem"},children:r.ollama.running?`server running, ${r.ollama.models.length} model(s)`:"server not running"})]}):e.jsx("span",{style:{color:"#888",fontSize:"0.85rem"},children:"not checked"})]}),e.jsxs("div",{style:u.detectRow,children:[e.jsx("span",{children:e.jsx("strong",{children:"llama.cpp"})}),r.llamaCpp!==null?e.jsxs("span",{children:[G(r.llamaCpp.installed),r.llamaCpp.installed&&r.llamaCpp.detail&&e.jsx("span",{style:{fontSize:"0.8rem",color:"#a0a0c0",marginLeft:"0.5rem"},children:r.llamaCpp.detail})]}):e.jsx("span",{style:{color:"#888",fontSize:"0.85rem"},children:"not checked"})]}),e.jsxs("div",{style:u.detectRow,children:[e.jsx("span",{children:e.jsx("strong",{children:"ONNX Runtime"})}),r.onnx!==null?e.jsxs("span",{children:[G(r.onnx.installed),r.onnx.installed&&r.onnx.detail&&e.jsx("span",{style:{fontSize:"0.8rem",color:"#a0a0c0",marginLeft:"0.5rem"},children:r.onnx.detail})]}):e.jsx("span",{style:{color:"#888",fontSize:"0.85rem"},children:"not checked"})]}),r.error&&e.jsxs("p",{style:{color:"#f44336",fontSize:"0.8rem",marginTop:"0.5rem"},children:["Detection error: ",r.error]})]}),c&&e.jsxs("p",{style:{color:"#f44336",fontSize:"0.85rem"},children:["Error: ",c]}),e.jsxs("div",{style:{marginTop:"1rem"},children:[e.jsx("button",{style:u.button,onClick:y,disabled:d,children:d?"Detecting...":"Run Detection"}),e.jsxs("span",{style:{fontSize:"0.8rem",color:"#888",marginLeft:"0.75rem"},children:["Or run ",e.jsx("code",{children:"/megasetup"})," in the chat for an interactive wizard."]})]}),r&&e.jsxs("div",{style:{marginTop:"1rem",paddingTop:"0.75rem",borderTop:"1px solid #2a2a4e"},children:[e.jsx("div",{style:{fontSize:"0.9rem",fontWeight:600,marginBottom:"0.5rem"},children:"Configure"}),e.jsxs("div",{style:{display:"flex",gap:"0.5rem",flexWrap:"wrap"},children:[e.jsx("button",{style:{...u.button,opacity:r.ollama?.installed?1:.4},onClick:()=>M("ollama"),disabled:!r.ollama?.installed||m!==null,children:m==="ollama"?"Writing...":"Use Ollama"}),e.jsx("button",{style:{...u.button,opacity:r.llamaCpp?.installed?1:.4},onClick:()=>M("llama"),disabled:!r.llamaCpp?.installed||m!==null,children:m==="llama"?"Writing...":"Use llama.cpp"}),e.jsx("button",{style:{...u.button,opacity:r.onnx?.installed?1:.4},onClick:()=>M("onnx"),disabled:!r.onnx?.installed||m!==null,children:m==="onnx"?"Writing...":"Use ONNX"}),e.jsx("button",{style:{...u.button,background:"#444"},onClick:()=>M("trigram"),disabled:m!==null,children:m==="trigram"?"Writing...":"Use Trigram (default)"})]}),f&&f.embedder!=="custom"&&e.jsx("div",{style:u.warning,children:f.alreadyActive?"Already active — no restart needed.":`Configured ${f.embedder}. Restart pi to activate (config written to ${f.envPath}).`}),v&&e.jsxs("p",{style:{color:"#f44336",fontSize:"0.85rem",marginTop:"0.5rem"},children:["Configure error: ",v]})]})]}),e.jsx(Re,{customUrl:w,setCustomUrl:E,applyEmbedder:M,configuring:m,inputEnabled:t!==null&&"embeddingApiKeySet"in t,apiKeySet:t?.embeddingApiKeySet===!0,embeddingDim:t?.embeddingDim,embeddingHeadersSet:t?.embeddingHeadersSet===!0,allowRemoteEmbedder:t?.allowRemoteEmbedder,configureResult:f,configureError:v}),e.jsxs("div",{style:u.section,children:[e.jsx("h3",{style:u.sectionTitle,children:"How to Upgrade"}),e.jsxs("ul",{style:{fontSize:"0.85rem",lineHeight:1.6,paddingLeft:"1.25rem"},children:[e.jsxs("li",{children:[e.jsx("strong",{children:"Ollama:"})," Install from"," ",e.jsx("a",{href:"https://ollama.com",style:{color:"#6a9fff"},target:"_blank",rel:"noopener noreferrer",children:"ollama.com"}),", then ",e.jsx("code",{children:"ollama pull nomic-embed-text"})," and restart pi. Set ",e.jsx("code",{children:"MEGACOMPACT_EMBEDDING_URL=http://localhost:11434/api/embeddings"}),"."]}),e.jsxs("li",{children:[e.jsx("strong",{children:"llama.cpp:"})," Build or install llama.cpp, run"," ",e.jsx("code",{children:"llama-server"})," with an embedding model, and set the URL accordingly."]}),e.jsxs("li",{children:[e.jsx("strong",{children:"ONNX Runtime:"})," Run a local text-embeddings server (e.g. TEI) and click ",e.jsx("strong",{children:"Use ONNX"})," above. Default URL: ",e.jsx("code",{children:"http://localhost:8081/v1/embeddings"}),"."]})]})]}),e.jsxs("div",{style:u.section,children:[e.jsx("h3",{style:u.sectionTitle,children:"Settings"}),e.jsx(Ne,{})]})]})}function $(t){return t>=1e6?`${(t/1e6).toFixed(2)}M`:t>=1e3?`${Math.round(t/1e3)}K`:String(t)}function Ae(t,n,r){if(t<=0)return"—";const a=(n>0?n:Math.ceil(t*.1))+Math.ceil(t*(r/100)),l=t-a;return l<=0?"0 (at risk)":`${$(l)} tokens`}function J({label:t,value:n,min:r,max:o,step:a=1,onChange:l,warning:c}){return e.jsxs("div",{className:"flex flex-col gap-1",children:[e.jsxs("div",{className:"flex items-center justify-between text-xs",children:[e.jsx("span",{className:"font-medium text-fg-muted",children:t}),e.jsxs("span",{className:`font-mono ${c?"text-warning":"text-fg"}`,title:c,children:[n,"%"]})]}),e.jsx("input",{type:"range",min:r,max:o,step:a,value:n,onChange:i=>l(Number(i.target.value)),className:"threshold-slider w-full"}),c&&e.jsxs("p",{className:"text-[10px] text-warning",children:["⚠ ",c]})]})}function Oe({model:t,defaults:n,safetyRange:r,fireRange:o,onSave:a,onReset:l,saving:c}){const[i,d]=s.useState(t.threshold.safetyMarginPct),[g,m]=s.useState(t.threshold.firePointPct),[x,f]=s.useState(!1),[b,v]=s.useState(null);s.useEffect(()=>{d(t.threshold.safetyMarginPct),m(t.threshold.firePointPct),f(!1)},[t.threshold.safetyMarginPct,t.threshold.firePointPct]);const S=i<5?'Low safety margin — risks "conversation too long" errors when a single turn injects a large tool output between gate fires.':void 0,w=g>85?"High fire point — compaction may trigger close to the window cap; a single large turn can overshoot before the gate fires.":void 0,E=s.useCallback(async()=>{v(null);try{await a(t.modelId,i,g),f(!1)}catch(h){v(h instanceof Error?h.message:String(h))}},[t.modelId,i,g,a]);return e.jsxs("div",{className:"rounded-md border border-border bg-bg-elevated/30 p-3",children:[e.jsxs("div",{className:"mb-2 flex items-start justify-between",children:[e.jsxs("div",{children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("span",{className:"text-sm font-semibold text-fg",children:t.modelName??t.modelId}),t.threshold.isOverride&&e.jsx("span",{className:"rounded border border-primary/40 bg-primary/15 px-1.5 py-0.5 text-[10px] font-semibold uppercase text-primary",title:"This model has a custom override (not the default)",children:"Override"})]}),e.jsxs("div",{className:"text-[11px] text-fg-muted",children:[t.provider," · ",$(t.contextWindow)," window ·"," ",$(t.maxTokens)," output"]})]}),e.jsxs("div",{className:"text-right text-[11px] text-fg-muted",children:[e.jsxs("div",{children:["Usable tail:"," ",e.jsx("span",{className:"font-mono text-fg",children:Ae(t.contextWindow,t.maxTokens,i)})]}),e.jsxs("div",{children:["Compaction fires at:"," ",e.jsx("span",{className:"font-mono text-fg",children:$(Math.ceil(t.contextWindow*(g/100)))})]})]})]}),e.jsxs("div",{className:"grid grid-cols-1 gap-3 sm:grid-cols-2",children:[e.jsx(J,{label:"Safety margin",value:i,min:r[0],max:r[1],onChange:h=>{d(h),f(!0)},warning:S}),e.jsx(J,{label:"Fire point",value:g,min:o[0],max:o[1],onChange:h=>{m(h),f(!0)},warning:w})]}),e.jsxs("div",{className:"mt-2 flex items-center gap-2",children:[e.jsx("button",{type:"button",onClick:E,disabled:!x||c,className:"rounded-md bg-primary px-2.5 py-1 text-xs font-semibold text-primary-fg disabled:cursor-not-allowed disabled:opacity-50",children:x?"Save override":"Saved"}),t.threshold.isOverride&&e.jsxs("button",{type:"button",onClick:()=>l(t.modelId),disabled:c,className:"rounded-md border border-border px-2.5 py-1 text-xs text-fg-muted disabled:cursor-not-allowed disabled:opacity-50",children:["Reset to default (",n.safetyMarginPct,"% /"," ",n.firePointPct,"%)"]}),b&&e.jsx("span",{className:"text-[11px] text-error",children:b})]})]})}function Ie(){const[t,n]=s.useState(null),[r,o]=s.useState(!0),[a,l]=s.useState(null),[c,i]=s.useState(!1),d=s.useCallback(async()=>{try{l(null),n(await he())}catch(x){l(x instanceof Error?x.message:String(x))}finally{o(!1)}},[]);s.useEffect(()=>{d()},[d]);const g=s.useCallback(async(x,f,b)=>{i(!0);try{await pe({modelId:x,safetyMarginPct:f,firePointPct:b}),await d()}finally{i(!1)}},[d]),m=s.useCallback(async x=>{i(!0);try{await ge(x),await d()}finally{i(!1)}},[d]);return r?e.jsx("div",{className:"p-4 text-sm text-fg-muted",children:"Loading thresholds…"}):a?e.jsxs("div",{className:"p-4 text-sm text-error",children:["Error: ",a]}):t?e.jsxs("div",{className:"flex flex-col gap-4",children:[e.jsxs("div",{className:"rounded-md border border-border bg-bg-elevated/20 p-3",children:[e.jsx("h3",{className:"text-sm font-semibold",children:"Per-Model Compaction Thresholds"}),e.jsxs("p",{className:"mt-1 text-[11px] text-fg-muted",children:["Tune when compaction fires + how much safety margin to reserve,",e.jsx("strong",{children:" per model"}),". Different providers' models range from 8K to 1M+ context — one global % is wrong. Defaults:"," ",e.jsxs("span",{className:"font-mono",children:[t.defaults.safetyMarginPct,"% safety"]})," ","/"," ",e.jsxs("span",{className:"font-mono",children:[t.defaults.firePointPct,"% fire"]}),". Values outside the safe band show warnings."]})]}),t.models.length===0?e.jsx("div",{className:"rounded-md border border-border p-4 text-sm text-fg-muted",children:"No models captured yet. Start a pi session in any repo to populate model snapshots, then return here to tune per-model thresholds."}):e.jsx("div",{className:"flex flex-col gap-3",children:t.models.map(x=>e.jsx(Oe,{model:x,defaults:t.defaults,safetyRange:t.defaults.safetyMarginRange,fireRange:t.defaults.firePointRange,onSave:g,onReset:m,saving:c},x.modelId))})]}):e.jsx("div",{className:"p-4 text-sm text-fg-muted",children:"No data."})}async function Le(){const t=await fetch("/api/setup-cortex-status");if(!t.ok)throw new Error(`setup-cortex status: ${t.status}`);return t.json()}async function De(t){const n=await fetch("/api/setup-cortex-action",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(t)});if(n.ok)return{ok:!0,result:await n.json()};let r;try{r=await n.json()}catch{r={error:"disabled"}}return{ok:!1,status:n.status,error:r}}async function Pe(t){const n=await fetch(`/api/setup-cortex-action-log?name=${encodeURIComponent(t)}`);if(!n.ok)throw new Error(`setup-cortex action-log: ${n.status}`);return n.json()}function _e(t){return t===null?!0:t.enabled&&t.status!=="off"}function ne(){const[t,n]=s.useState({loading:!0,error:null,data:null}),r=s.useCallback(()=>{n(o=>({...o,loading:!0})),Le().then(o=>n(a=>({...a,data:o,loading:!1,error:null}))).catch(o=>n(a=>({...a,loading:!1,error:o instanceof Error?o.message:String(o)})))},[]);return s.useEffect(()=>{r();const o=setInterval(r,5e3);return()=>clearInterval(o)},[r]),[t,r]}const j={container:{padding:"1rem",maxWidth:"720px",margin:"0 auto",fontFamily:"system-ui, sans-serif",color:"#e0e0e0"},section:{background:"#1a1a2e",borderRadius:"8px",padding:"1rem",marginBottom:"1rem",border:"1px solid #2a2a4e"},sectionTitle:{fontSize:"1.1rem",fontWeight:700,marginTop:0,marginBottom:"0.75rem",color:"#e0e0e0",borderBottom:"1px solid #333",paddingBottom:"0.5rem"},label:{fontWeight:600,color:"#a0a0c0",marginRight:"0.5rem"},value:{color:"#e0e0e0"},row:{marginBottom:"0.4rem",fontSize:"0.9rem"},warning:{background:"#3a2a00",border:"1px solid #665500",borderRadius:"8px",padding:"0.75rem",marginTop:"0.5rem",color:"#ffcc00",fontSize:"0.85rem"},blocked:{background:"#3a1a1a",border:"1px solid #662222",borderRadius:"8px",padding:"0.75rem",marginTop:"0.5rem",color:"#ff6666",fontSize:"0.85rem"},badge:{display:"inline-block",padding:"0.15rem 0.5rem",borderRadius:"4px",fontSize:"0.8rem",fontWeight:600,marginLeft:"0.5rem"},button:{background:"#3a5a9f",color:"#fff",border:"none",borderRadius:"6px",padding:"0.5rem 1rem",cursor:"pointer",fontSize:"0.9rem",fontWeight:600},buttonDanger:{background:"#6a2a2a",color:"#ffb3b3",border:"1px solid #662222",borderRadius:"6px",padding:"0.5rem 1rem",cursor:"pointer",fontSize:"0.9rem",fontWeight:600},blockerRow:{display:"flex",justifyContent:"space-between",alignItems:"center",gap:"0.5rem",padding:"0.5rem 0.6rem",borderRadius:"6px",marginBottom:"0.35rem",fontSize:"0.85rem"},blockerRowHighlighted:{background:"#3a1a1a",border:"1px solid #662222"},mono:{fontFamily:"ui-monospace, monospace",fontSize:"0.8rem"}};function $e(t){switch(t){case"A":return"A — qualified learned encoder asset";case"B":return"B — demoted (heuristic/trigram)";case"C":return"C — absent (asset not verified)";default:return"—"}}function We(t){const n=t==="qualified"?"#1a5a1a":t==="demoted"?"#3a3a1a":"#3a1a1a",r=t==="qualified"?"#4caf50":t==="demoted"?"#ffcc00":"#f44336";return e.jsx("span",{style:{...j.badge,background:n,color:r},children:t??"unknown"})}function Ue({data:t,error:n}){return e.jsxs("div",{style:j.section,children:[e.jsxs("h3",{style:j.sectionTitle,children:[e.jsx("span",{style:{marginRight:"0.5rem"},children:"Cortex Encoder"}),e.jsx(fe,{status:t?.status})]}),n&&e.jsxs("p",{style:{color:"#f44336",fontSize:"0.85rem"},children:["Error: ",n]}),!t&&!n&&e.jsx("p",{style:{color:"#888",fontSize:"0.85rem"},children:"Loading cortex status..."}),!t?.enabled&&e.jsx("p",{style:{color:"#f44336",fontSize:"0.85rem"},children:"Cortex status disabled (VC9A off)."}),e.jsxs("div",{style:j.row,children:[e.jsx("span",{style:j.label,children:"Mode:"}),e.jsx("span",{style:j.value,children:$e(t?.encoderHealth.mode)})]}),e.jsxs("div",{style:j.row,children:[e.jsx("span",{style:j.label,children:"Asset digest prefix:"}),e.jsx("span",{style:{...j.value,...j.mono},children:t?.assetDigestPrefix??e.jsx("span",{style:{color:"#888"},children:"not available"})})]}),e.jsxs("div",{style:j.row,children:[e.jsx("span",{style:j.label,children:"Qualification:"}),We(t?.qualification.verdict)]}),(t?.qualification.thresholdFailures.length??0)>0&&e.jsxs("div",{style:j.warning,children:[e.jsx("strong",{children:"Threshold failure(s):"})," ",t?.qualification.thresholdFailures.join(", ")]}),t?.status==="awaiting_data"&&e.jsx("p",{style:{color:"#a0a0c0",fontSize:"0.85rem"},children:"Awaiting encoder data. Qualification will appear once an asset is present."}),t?.status==="deferred"&&e.jsx("p",{style:{color:"#a0a0c0",fontSize:"0.85rem"},children:"Encoder status deferred."})]})}function Fe(t){switch(t){case"blocker":return"#f44336";case"high":return"#ff9800";default:return"#a0a0c0"}}function He({blockers:t,highlight:n,darwinX64:r}){const o=n??[];return e.jsxs("div",{style:j.section,children:[e.jsxs("h3",{style:j.sectionTitle,children:["Open Hard-Gate Blockers",e.jsx("span",{style:{...j.badge,background:"#3a1a1a",color:"#f44336"},children:t.length})]}),t.length===0&&e.jsx("p",{style:{color:"#4caf50",fontSize:"0.85rem"},children:"No open hard-gate blockers."}),r?.demoted===!0&&e.jsxs("div",{style:j.blockerRow,"data-darwin-x64-demoted":"true",children:[e.jsx("span",{style:{...j.mono,fontWeight:700},children:"HG-4"}),e.jsx("span",{style:{flex:1,color:"#e0e0e0"},children:r.reason||"darwin-x64: demoted to WASM (reason unavailable)"}),e.jsx("span",{style:{color:"#ff9800"},children:"high"}),e.jsx("span",{style:{color:"#4caf50",fontStyle:"italic"},children:"diagnosed"})]}),t.map(a=>{const l=o.includes(a.id);return e.jsxs("div",{style:{...j.blockerRow,...l?j.blockerRowHighlighted:{}},children:[e.jsx("span",{style:{...j.mono,fontWeight:700},children:a.id}),e.jsx("span",{style:{flex:1,color:"#e0e0e0"},children:a.title}),e.jsx("span",{style:{color:Fe(a.severity)},children:a.severity}),e.jsx("span",{style:{color:"#a0a0c0",fontStyle:"italic"},children:l?"gates this action":a.status})]},a.id)}),o.length>0&&e.jsxs("div",{style:j.blocked,children:[e.jsx("strong",{children:"Blocked:"})," the requested action is gated by the highlighted open hard-gate item(s). It was not run."]})]})}const Ge=[{key:"fetch-model",label:"Fetch Model",desc:"Fetch the qualified encoder model asset",dangerous:!0,confirm:"Fetch the encoder model asset onto this host? (Gated by any open hard gate.)"},{key:"bench",label:"Bench Encoder",desc:"Benchmark the encoder runtime on this host",dangerous:!0,confirm:"Run an encoder benchmark on this host? (Gated by any open hard gate.)"},{key:"verify-asset",label:"Verify Asset",desc:"Re-verify the committed encoder asset",dangerous:!1,confirm:"Re-verify the committed encoder asset?"}];function qe({data:t,onBlocked:n,onAction:r}){const[o,a]=s.useState(null),[l,c]=s.useState(null),[i,d]=s.useState(null),[g,m]=s.useState(!1),x=s.useCallback(async b=>{a(b.key),d(null),c(null),m(!1),n([]);try{const v=await De({action:b.key,confirm:!0});if(v.ok){const S=v.result;let w=null,E=null;try{const h=await Pe(S.logName);w=h.tail,E=h.complete}catch{}c({action:S.action,logName:S.logName,tail:w,complete:E,message:S.ok?`${S.action} completed (spawned: ${S.spawned})`:`${S.action} did not complete cleanly`}),r()}else v.error.error==="action_blocked_by_open_item"?(n(v.error.blockers),d("The action is blocked by an open hard-gate item and was not run.")):v.error.error==="confirmation_required"?d("The server rejected the action: explicit confirmation is required."):(m(!0),d(v.status===404?"Setup Cortex actions are disabled (off).":`Action failed (${v.status}).`))}catch(v){d(v instanceof Error?v.message:String(v))}finally{a(null)}},[n,r]),f=b=>{window.confirm(b.confirm)&&x(b)};return e.jsxs("div",{style:j.section,children:[e.jsx("h3",{style:j.sectionTitle,children:"Cortex Actions"}),Ge.map(b=>{const v=o===b.key;return e.jsxs("div",{style:{display:"flex",alignItems:"center",justifyContent:"space-between",gap:"0.5rem",padding:"0.5rem 0",borderBottom:"1px solid #2a2a4e"},children:[e.jsxs("div",{children:[e.jsx("div",{style:{fontWeight:600},children:b.label}),e.jsx("div",{style:{fontSize:"0.8rem",color:"#a0a0c0"},children:b.desc})]}),e.jsx("button",{style:b.dangerous?j.buttonDanger:j.button,disabled:o!==null,onClick:()=>f(b),children:v?"Running…":"Run"})]},b.key)}),g&&e.jsx("div",{style:j.blocked,children:"Setup Cortex actions are disabled. Enable MEGACOMPACT_VC9B to run them."}),i&&!g&&e.jsx("p",{style:{color:"#f44336",fontSize:"0.85rem",marginTop:"0.5rem"},children:i}),l&&e.jsxs("div",{style:j.warning,"data-testid":"cortex-action-result",children:[e.jsxs("strong",{children:["Result (",l.action,"):"]})," ",l.message,l.logName&&e.jsxs("span",{style:{...j.mono,marginLeft:"0.5rem"},children:["log: ",l.logName]}),l.tail!==null&&e.jsxs("pre",{style:{whiteSpace:"pre-wrap",wordBreak:"break-word",fontSize:"0.75rem",maxHeight:"12rem",overflow:"auto",marginTop:"0.5rem"},children:[l.tail,l.complete===!1&&`
|
|
2
|
-
… (truncated)`]})]}),!t?.enabled&&!g&&e.jsx("p",{style:{color:"#a0a0c0",fontSize:"0.8rem",marginTop:"0.5rem"},children:"Cortex status unavailable — actions may not be schedulable."})]})}const B={section:{background:"#1a1a2e",borderRadius:"8px",padding:"1rem",marginBottom:"1rem",border:"1px solid #2a2a4e"},sectionTitle:{fontSize:"1.1rem",fontWeight:700,marginTop:0,marginBottom:"0.25rem",color:"#e0e0e0"},subtitle:{fontSize:"0.85rem",color:"#a0a0c0",marginTop:0,marginBottom:"0.75rem"},row:{marginBottom:"0.4rem",fontSize:"0.9rem"},label:{fontWeight:600,color:"#a0a0c0",marginRight:"0.5rem"},value:{color:"#e0e0e0"},warning:{background:"#3a2a00",border:"1px solid #665500",borderRadius:"8px",padding:"0.75rem",marginTop:"0.5rem",color:"#ffcc00",fontSize:"0.85rem"},toggleRow:{display:"flex",alignItems:"center",gap:"0.5rem",marginBottom:"0.75rem",fontSize:"0.9rem"}},q=8192;function Ve(){const[t,n]=s.useState(null),[r,o]=s.useState(null),[a,l]=s.useState(!1),[c,i]=s.useState(""),[d,g]=s.useState(!1),m=s.useCallback(()=>{ee().then(n).catch(h=>o(h instanceof Error?h.message:String(h)))},[]);s.useEffect(()=>{m()},[m]),s.useEffect(()=>{const h=setInterval(m,5e3);return()=>clearInterval(h)},[m]);const x=t!==null&&"encoderNativeOptIn"in t,f=t?.nativeOrtBudgetEffectiveMib;s.useEffect(()=>{if(!d&&t&&"nativeOrtBudgetEffectiveMib"in t){const h=t.nativeOrtBudgetMib??t.nativeOrtBudgetEffectiveMib??"";typeof h=="string"&&i(h),g(!0)}},[d,t]);const b=s.useCallback(h=>{l(!0),o(null),V({embedder:"custom",url:t?.embeddingEndpointUrl??void 0,encoderNativeOptIn:h}).then(()=>{l(!1),m()}).catch(T=>{o(T instanceof Error?T.message:String(T)),l(!1)})},[t,m]),v=s.useCallback(()=>{const h=c.trim();if(!/^\d+$/.test(h)){o("Install budget must be a positive integer (MiB)");return}const T=Number(h);if(!Number.isSafeInteger(T)||T<1||T>q){o(`Install budget must be between 1 and ${q} MiB`);return}l(!0),o(null),V({embedder:"custom",url:t?.embeddingEndpointUrl??void 0,nativeOrtBudgetMib:h}).then(()=>{l(!1),m()}).catch(N=>{o(N instanceof Error?N.message:String(N)),l(!1)})},[c,t,m]);if(!x)return e.jsx(e.Fragment,{});const S=t?.encoderBackend??"wasm",w=t?.encoderDemotionReason??null,E=t!==null&&"nativeOrtBudgetEffectiveMib"in t;return e.jsxs("div",{style:B.section,children:[e.jsx("h3",{style:B.sectionTitle,children:"Encoder Runtime"}),e.jsx("p",{style:B.subtitle,children:"ONNX backend selection"}),e.jsxs("div",{style:B.toggleRow,children:[e.jsx("input",{type:"checkbox",checked:t?.encoderNativeOptIn===!0,onChange:h=>b(h.target.checked),disabled:a,"aria-label":"Native ONNX runtime (onnxruntime-node)"}),e.jsx("label",{children:"Native ONNX runtime (onnxruntime-node)"}),a&&e.jsx("span",{style:{fontSize:"0.8rem",color:"#a0a0c0"},children:"saving..."})]}),e.jsxs("div",{style:B.row,children:[e.jsx("span",{style:B.label,children:"Effective backend:"}),e.jsx("span",{style:B.value,children:S})]}),E&&e.jsxs("div",{style:B.row,children:[e.jsx("label",{htmlFor:"enc2-budget-input",style:{...B.label,marginRight:"0.5rem"},children:"Native install budget (MiB):"}),e.jsx("input",{id:"enc2-budget-input",type:"number",min:1,max:q,step:1,value:c,onChange:h=>i(h.target.value),disabled:a,style:{width:"6rem"},"aria-label":"Native onnxruntime install budget in MiB"}),e.jsx("button",{type:"button",onClick:v,disabled:a||c.trim().length===0,style:{marginLeft:"0.5rem"},children:"Save"}),f!==void 0&&e.jsxs("span",{style:{...B.value,marginLeft:"0.5rem"},children:["(effective: ",f," MiB)"]})]}),w!==null&&e.jsxs("div",{style:B.warning,children:[e.jsx("strong",{children:"Demoted:"})," ",w]}),r&&e.jsxs("p",{style:{color:"#f44336",fontSize:"0.85rem"},children:["Error: ",r]})]})}const k={section:{background:"#1a1a2e",borderRadius:"8px",padding:"1rem",marginBottom:"1rem",border:"1px solid #2a2a4e"},sectionTitle:{fontSize:"1.1rem",fontWeight:700,marginTop:0,marginBottom:"0.25rem",color:"#e0e0e0"},subtitle:{fontSize:"0.85rem",color:"#a0a0c0",marginTop:0,marginBottom:"0.75rem"},row:{marginBottom:"0.4rem",fontSize:"0.9rem"},label:{fontWeight:600,color:"#a0a0c0",marginRight:"0.5rem"},value:{color:"#e0e0e0"},disabled:{background:"#1a1a2e",border:"1px solid #2a2a4e",borderRadius:"8px",padding:"1rem",marginBottom:"1rem",color:"#a0a0c0",fontSize:"0.85rem"}},Xe=()=>{const{data:t,error:n,loading:r}=X(s.useMemo(()=>()=>te("/api/cosine-fp-report").catch(o=>{if(o instanceof se&&o.status===404)return null;throw o}),[]),{pollInterval:5e3});return t===null&&!n&&!r?e.jsx("div",{style:k.disabled,children:"Cosine FP synthetic bench: disabled (MEGACOMPACT_COSINE_FP_BENCH=0)."}):e.jsxs("div",{style:k.section,children:[e.jsx("h3",{style:k.sectionTitle,children:"Cosine FP threshold"}),e.jsx("p",{style:k.subtitle,children:"Last synthetic bench threshold recommendation"}),n!==null?e.jsxs("p",{style:{color:"#f44336",fontSize:"0.85rem"},children:["Error loading report: ",n.message]}):t===null?e.jsx("div",{style:k.value,children:"Loading…"}):e.jsxs("div",{children:[e.jsxs("div",{style:k.row,children:[e.jsx("span",{style:k.label,children:"Recommended default:"}),e.jsxs("span",{style:k.value,children:[t.recommendedDefault??"—"," (shipped"," ",t.shippedDefault,")"]})]}),e.jsxs("div",{style:k.row,children:[e.jsx("span",{style:k.label,children:"Overrides:"}),e.jsxs("span",{style:k.value,children:["CODE ",t.overrides?.code??"—"," · PROSE"," ",t.overrides?.prose??"—"," · MIXED"," ",t.overrides?.mixed??"—"]})]}),e.jsxs("div",{style:k.row,children:[e.jsx("span",{style:k.label,children:"Grid:"}),e.jsx("span",{style:k.value,children:t.grid?`${t.grid.lo} → ${t.grid.hi} (${t.grid.points} points)`:"—"})]}),e.jsxs("div",{style:k.row,children:[e.jsx("span",{style:k.label,children:"Report digest:"}),e.jsx("span",{style:k.value,title:t.digest??void 0,children:t.digest?t.digest.slice(0,16)+"…":"—"})]})]})]})},C={section:{background:"#1a1a2e",borderRadius:"8px",padding:"1rem",marginBottom:"1rem",border:"1px solid #2a2a4e"},sectionTitle:{fontSize:"1.1rem",fontWeight:700,marginTop:0,marginBottom:"0.25rem",color:"#e0e0e0"},subtitle:{fontSize:"0.85rem",color:"#a0a0c0",marginTop:0,marginBottom:"0.75rem"},row:{marginBottom:"0.4rem",fontSize:"0.9rem"},label:{fontWeight:600,color:"#a0a0c0",marginRight:"0.5rem"},value:{color:"#e0e0e0"},disabled:{background:"#1a1a2e",border:"1px solid #2a2a4e",borderRadius:"8px",padding:"1rem",marginBottom:"1rem",color:"#a0a0c0",fontSize:"0.85rem"}},Ke=()=>{const{data:t,error:n,loading:r}=X(s.useMemo(()=>()=>te("/api/repo-corpus").catch(o=>{if(o instanceof se&&o.status===404)return null;throw o}),[]),{pollInterval:5e3});return t===null&&!n&&!r?e.jsx("div",{style:C.disabled,children:"Cross-repo corpus: disabled (MEGACOMPACT_REPO_CORPUS=0)."}):e.jsxs("div",{style:C.section,children:[e.jsx("h3",{style:C.sectionTitle,children:"Cross-Repo Corpus"}),e.jsx("p",{style:C.subtitle,children:"Pseudonymous consent status across donated repos"}),n!==null?e.jsxs("p",{style:{color:"#f44336",fontSize:"0.85rem"},children:["Error loading corpus: ",n.message]}):t===null?e.jsx("div",{style:C.value,children:"Loading…"}):e.jsxs("div",{children:[e.jsxs("div",{style:C.row,children:[e.jsx("span",{style:C.label,children:"Status:"}),e.jsx("span",{style:C.value,children:t.status})]}),e.jsxs("div",{style:C.row,children:[e.jsx("span",{style:C.label,children:"Total events:"}),e.jsx("span",{style:C.value,children:t.totalEvents})]}),e.jsxs("div",{style:C.row,children:[e.jsx("span",{style:C.label,children:"Overlap pairs:"}),e.jsx("span",{style:C.value,children:t.corpus?t.corpus.overlaps.length:0})]}),e.jsx("div",{style:{marginTop:"0.5rem"},children:(t.perRepo??[]).map(o=>e.jsxs("div",{style:C.row,children:[e.jsxs("span",{style:C.label,children:[o.repoPseudonym.slice(0,8),":"]}),e.jsxs("span",{style:C.value,children:[o.sessions," sessions ·"," ",o.consentedCrossRepo?o.revokedAt?`revoked ${o.revokedAt}`:"consented":"not consented"]})]},o.repoPseudonym))})]})]})};function Je(){const[t,n]=ne(),[r,o]=s.useState([]),a=s.useCallback(c=>{o(c)},[]),l=s.useCallback(()=>{n()},[n]);return e.jsxs("div",{style:j.container,children:[e.jsx("h2",{style:{fontSize:"1.3rem",marginTop:0,marginBottom:"1rem"},children:"Setup Cortex"}),e.jsx("p",{style:{fontSize:"0.85rem",color:"#a0a0c0",marginTop:0},children:"Vector-cortex encoder gate: mode, qualification, open hard-gate blockers, and the confirmation-gated fetch/bench/verify actions."}),e.jsx(Ue,{data:t.data,error:t.error}),e.jsx(Ve,{}),e.jsx(Xe,{}),e.jsx(Ke,{}),e.jsx(He,{blockers:t.data?.blockers??[],highlight:r,darwinX64:t.data?.darwinX64}),e.jsx(qe,{data:t.data,onBlocked:a,onAction:l})]})}const Qe="MEGACOMPACT_DASH_0C";function Ye(t){if(!t)return!1;for(const n of t.categories)for(const r of n.settings)if(r.key===Qe&&r.type==="boolean")return r.value===!0;return!1}const Q=[{id:"embedder",label:"Embedder"},{id:"thresholds",label:"Thresholds"},{id:"config",label:"Config"},{id:"game",label:"Game Mode"},{id:"achievements",label:"Achievements"}],Ze={id:"cortex",label:"Cortex"};function ot(){const[t,n]=s.useState("embedder"),[r]=ne(),{data:o}=X(s.useCallback(()=>Z(),[]),{pollInterval:0,maxRetries:0}),a=Ye(o),l=s.useMemo(()=>{const c=a?Q.filter(i=>i.id!=="config"):[...Q];return _e(r.data)&&c.push(Ze),c},[r.data,a]);return e.jsxs("div",{className:"mx-auto flex max-w-3xl flex-col gap-4 p-4",children:[e.jsx("nav",{className:"flex gap-2 border-b border-border pb-2","aria-label":"Setup sections",children:l.map(c=>e.jsx(xe,{pressed:t===c.id,onClick:()=>n(c.id),children:c.label},c.id))}),t==="embedder"&&e.jsx(ze,{}),t==="thresholds"&&e.jsx(Ie,{}),t==="config"&&!a&&e.jsx(me,{}),t==="game"&&e.jsx(je,{}),t==="achievements"&&e.jsx(ve,{}),t==="cortex"&&e.jsx(Je,{})]})}export{ot as default};
|
|
3
|
-
//# sourceMappingURL=SetupTab-CgC4Rz38.js.map
|