pi-mega-compact 0.20.50 → 0.20.52
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/assets/vector-cortex/encoder-v1/manifest.json +1 -1
- package/dist/config/vector-cortex-enc1b.js +46 -0
- package/dist/config/vector-cortex.js +1 -0
- package/dist/config.js +1 -1
- package/dist/extensions/dashboard-server/api-contracts/vector-cortex-ledger.js +9 -0
- package/dist/extensions/dashboard-server/routes-rag-settings-vector-cortex.js +1 -0
- package/dist/extensions/dashboard-server/routes-setup-enc1b.js +297 -0
- package/dist/extensions/dashboard-server/routes-setup-env-upsert.js +79 -0
- package/dist/extensions/dashboard-server/routes-setup.js +27 -26
- package/dist/extensions/dashboard-server/routes-vector-cortex-eval.js +4 -1
- package/dist/src/config/vector-cortex-enc1b.js +46 -0
- package/dist/src/config/vector-cortex.js +1 -0
- package/dist/src/config.js +1 -1
- package/extensions/dashboard-client/dist/assets/{AreaChart-CeVnaV-0.js → AreaChart-Dika24if.js} +2 -2
- package/extensions/dashboard-client/dist/assets/{AreaChart-CeVnaV-0.js.map → AreaChart-Dika24if.js.map} +1 -1
- package/extensions/dashboard-client/dist/assets/{BarChart-DoNd35sw.js → BarChart-MxPpphaX.js} +2 -2
- package/extensions/dashboard-client/dist/assets/{BarChart-DoNd35sw.js.map → BarChart-MxPpphaX.js.map} +1 -1
- package/extensions/dashboard-client/dist/assets/{CacheTab-BROshdFf.js → CacheTab-e90mt1aw.js} +2 -2
- package/extensions/dashboard-client/dist/assets/{CacheTab-BROshdFf.js.map → CacheTab-e90mt1aw.js.map} +1 -1
- package/extensions/dashboard-client/dist/assets/{EventsTab-DAD6NeBR.js → EventsTab-CSl9CNXa.js} +2 -2
- package/extensions/dashboard-client/dist/assets/{EventsTab-DAD6NeBR.js.map → EventsTab-CSl9CNXa.js.map} +1 -1
- package/extensions/dashboard-client/dist/assets/{HealthTab-BBVMM54F.js → HealthTab-CgUm8sp5.js} +2 -2
- package/extensions/dashboard-client/dist/assets/{HealthTab-BBVMM54F.js.map → HealthTab-CgUm8sp5.js.map} +1 -1
- package/extensions/dashboard-client/dist/assets/{MaintenanceTab-f9VhlFco.js → MaintenanceTab-Dyhjzk6G.js} +2 -2
- package/extensions/dashboard-client/dist/assets/{MaintenanceTab-f9VhlFco.js.map → MaintenanceTab-Dyhjzk6G.js.map} +1 -1
- package/extensions/dashboard-client/dist/assets/{MemoryMapTab-BaxfyzN2.js → MemoryMapTab-C1YR7CoA.js} +2 -2
- package/extensions/dashboard-client/dist/assets/{MemoryMapTab-BaxfyzN2.js.map → MemoryMapTab-C1YR7CoA.js.map} +1 -1
- package/extensions/dashboard-client/dist/assets/{MetricsTab-DkUvoeS_.js → MetricsTab-Bktg-486.js} +2 -2
- package/extensions/dashboard-client/dist/assets/{MetricsTab-DkUvoeS_.js.map → MetricsTab-Bktg-486.js.map} +1 -1
- package/extensions/dashboard-client/dist/assets/{OverviewTab-BCpK1vgt.js → OverviewTab-B7qTLQc2.js} +2 -2
- package/extensions/dashboard-client/dist/assets/{OverviewTab-BCpK1vgt.js.map → OverviewTab-B7qTLQc2.js.map} +1 -1
- package/extensions/dashboard-client/dist/assets/{ReposTab-cJ5neYIG.js → ReposTab-Cr9W3KFw.js} +2 -2
- package/extensions/dashboard-client/dist/assets/{ReposTab-cJ5neYIG.js.map → ReposTab-Cr9W3KFw.js.map} +1 -1
- package/extensions/dashboard-client/dist/assets/{SessionsTab-8DyQv1Ry.js → SessionsTab-5x_LL9D8.js} +2 -2
- package/extensions/dashboard-client/dist/assets/{SessionsTab-8DyQv1Ry.js.map → SessionsTab-5x_LL9D8.js.map} +1 -1
- package/extensions/dashboard-client/dist/assets/SetupTab-vB72Y7pk.js +3 -0
- package/extensions/dashboard-client/dist/assets/SetupTab-vB72Y7pk.js.map +1 -0
- package/extensions/dashboard-client/dist/assets/{TimeSavedCard-8N7Vvlch.js → TimeSavedCard-hsMc2BFT.js} +2 -2
- package/extensions/dashboard-client/dist/assets/{TimeSavedCard-8N7Vvlch.js.map → TimeSavedCard-hsMc2BFT.js.map} +1 -1
- package/extensions/dashboard-client/dist/assets/{TurnsTab-CCijkQoH.js → TurnsTab-CjUIvDlj.js} +2 -2
- package/extensions/dashboard-client/dist/assets/{TurnsTab-CCijkQoH.js.map → TurnsTab-CjUIvDlj.js.map} +1 -1
- package/extensions/dashboard-client/dist/assets/{VcStatusBadge-D9a7By8x.js → VcStatusBadge-yDtZGtnm.js} +2 -2
- package/extensions/dashboard-client/dist/assets/{VcStatusBadge-D9a7By8x.js.map → VcStatusBadge-yDtZGtnm.js.map} +1 -1
- package/extensions/dashboard-client/dist/assets/{VectorCortexTab-pviD6CCy.js → VectorCortexTab-CvbaaeXD.js} +2 -2
- package/extensions/dashboard-client/dist/assets/{VectorCortexTab-pviD6CCy.js.map → VectorCortexTab-CvbaaeXD.js.map} +1 -1
- package/extensions/dashboard-client/dist/assets/{WikiTab-DLyicguz.js → WikiTab-c7K7kspY.js} +2 -2
- package/extensions/dashboard-client/dist/assets/{WikiTab-DLyicguz.js.map → WikiTab-c7K7kspY.js.map} +1 -1
- package/extensions/dashboard-client/dist/assets/{button-D8nKit8Y.js → button-vdqzHHyW.js} +2 -2
- package/extensions/dashboard-client/dist/assets/{button-D8nKit8Y.js.map → button-vdqzHHyW.js.map} +1 -1
- package/extensions/dashboard-client/dist/assets/{card-Xf5wHHBL.js → card-DEzbxZLz.js} +2 -2
- package/extensions/dashboard-client/dist/assets/{card-Xf5wHHBL.js.map → card-DEzbxZLz.js.map} +1 -1
- package/extensions/dashboard-client/dist/assets/{client-extra-CvxDLpQr.js → client-extra-CJe2UKEK.js} +2 -2
- package/extensions/dashboard-client/dist/assets/{client-extra-CvxDLpQr.js.map → client-extra-CJe2UKEK.js.map} +1 -1
- package/extensions/dashboard-client/dist/assets/{generateCategoricalChart-DhQquRa8.js → generateCategoricalChart-Br3cS-GZ.js} +2 -2
- package/extensions/dashboard-client/dist/assets/{generateCategoricalChart-DhQquRa8.js.map → generateCategoricalChart-Br3cS-GZ.js.map} +1 -1
- package/extensions/dashboard-client/dist/assets/{index-BUP3MK5S.js → index-CBMWirAB.js} +3 -3
- package/extensions/dashboard-client/dist/assets/{index-BUP3MK5S.js.map → index-CBMWirAB.js.map} +1 -1
- package/extensions/dashboard-client/dist/assets/index-C_aDd9kk.css +1 -0
- package/extensions/dashboard-client/dist/assets/{switch-B13rb8Z2.js → switch-D_uPnF8u.js} +2 -2
- package/extensions/dashboard-client/dist/assets/{switch-B13rb8Z2.js.map → switch-D_uPnF8u.js.map} +1 -1
- package/extensions/dashboard-client/dist/assets/{toggle-4h6DUEB5.js → toggle-DIaGjpNm.js} +2 -2
- package/extensions/dashboard-client/dist/assets/{toggle-4h6DUEB5.js.map → toggle-DIaGjpNm.js.map} +1 -1
- package/extensions/dashboard-client/dist/assets/{useSSE-Djom4z1K.js → useSSE-CJOcvXIe.js} +2 -2
- package/extensions/dashboard-client/dist/assets/{useSSE-Djom4z1K.js.map → useSSE-CJOcvXIe.js.map} +1 -1
- package/extensions/dashboard-client/dist/index.html +2 -2
- package/extensions/dashboard-client/src/tabs/SetupTab/CortexRuntimeCard.tsx +103 -0
- package/extensions/dashboard-client/src/tabs/SetupTab/CortexRuntimeCardStyles.ts +49 -0
- package/extensions/dashboard-client/src/tabs/SetupTab/CortexSetup.tsx +2 -0
- package/extensions/dashboard-client/src/tabs/SetupTab/CustomEndpointSection.tsx +122 -1
- package/extensions/dashboard-client/src/tabs/SetupTab/EmbedderSetup.tsx +57 -79
- package/extensions/dashboard-client/src/tabs/SetupTab/EmbedderSetupHelpers.tsx +75 -0
- package/extensions/dashboard-client/src/tabs/VectorCortexTab.tsx +7 -5
- package/extensions/dashboard-client/src/types/vector-cortex.ts +6 -0
- package/extensions/dashboard-server/api-contracts/setup.ts +35 -0
- package/extensions/dashboard-server/api-contracts/vector-cortex-ledger.ts +39 -0
- package/extensions/dashboard-server/api-contracts/vector-cortex.ts +10 -28
- package/extensions/dashboard-server/routes-rag-settings-vector-cortex.ts +6 -0
- package/extensions/dashboard-server/routes-setup-enc1b.ts +336 -0
- package/extensions/dashboard-server/routes-setup-env-upsert.ts +93 -0
- package/extensions/dashboard-server/routes-setup.ts +26 -24
- package/extensions/dashboard-server/routes-vector-cortex-eval.ts +4 -1
- package/package.json +1 -1
- package/src/config/vector-cortex-enc1b.ts +50 -0
- package/src/config/vector-cortex.ts +8 -0
- package/src/config.ts +1 -0
- package/extensions/dashboard-client/dist/assets/SetupTab-BQGPf9CI.js +0 -3
- package/extensions/dashboard-client/dist/assets/SetupTab-BQGPf9CI.js.map +0 -1
- package/extensions/dashboard-client/dist/assets/index-DbuGwYD7.css +0 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"batch":1,"heads":{"cacheStability":64,"contradiction":128,"dependency":128,"payloadRouting":32,"semantic":384},"hiddenWidth":384,"maxTokens":512,"modelVersion":"encoder-v1","onnx":{"bytes":33793354,"path":"model.onnx","sha256":"913a643a697a53fe88476395682995d5647c14f51321d344e69abcc3c4e854a2"},"opset":21,"platform":"linux-x64","schema":"model-manifest-v1","semanticWidth":384,"tokenizer":{"bytes":
|
|
1
|
+
{"batch":1,"heads":{"cacheStability":64,"contradiction":128,"dependency":128,"payloadRouting":32,"semantic":384},"hiddenWidth":384,"maxTokens":512,"modelVersion":"encoder-v1","onnx":{"bytes":33793354,"path":"model.onnx","sha256":"913a643a697a53fe88476395682995d5647c14f51321d344e69abcc3c4e854a2"},"opset":21,"platform":"linux-x64","schema":"model-manifest-v1","semanticWidth":384,"tokenizer":{"bytes":533603,"path":"tokenizer.json","sha256":"ea77de727ef7fd34d177b83b4b1f1d3bb8884c95c90b6554a0adb0b3b65350a9"},"totalBytes":34326957,"trainingManifestDigest":"e9b2550dbb79141af84440dda65ca21d3509904b2c09a89316145137a5b5e3de"}
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* config/vector-cortex-enc1b.ts — ENC-1b ONNX runtime backend + embedder API
|
|
3
|
+
* Settings fields.
|
|
4
|
+
*
|
|
5
|
+
* Extracted from vector-cortex.ts so that file stays under the 300-line soft
|
|
6
|
+
* limit (soft-as-hard gate), exactly as the ENC-1a sibling was. vector-cortex.ts
|
|
7
|
+
* re-exports the flag + constants below and root src/config.ts re-exports them,
|
|
8
|
+
* so no consumer import path changes.
|
|
9
|
+
*
|
|
10
|
+
* ENC-1b adds two Settings surfaces. (A) Embedder API completion: the three
|
|
11
|
+
* remaining env vars the runtime reads (src/httpEmbedder.ts:embeddingConfigFromEnv)
|
|
12
|
+
* gain dashboard-visible fields — `MEGACOMPACT_EMBEDDING_DIM` (numeric, validated
|
|
13
|
+
* positive int bounded by `ENC_1B_MAX_EMBEDDING_DIM`), `MEGACOMPACT_EMBEDDING_HEADERS`
|
|
14
|
+
* (JSON object string — secret-bearing, written verbatim to the per-repo
|
|
15
|
+
* `.mega-compact.env`, NEVER echoed raw; the GET reports only a boolean
|
|
16
|
+
* presence marker), and `MEGACOMPACT_ALLOW_REMOTE_EMBEDDER` (boolDirect toggle,
|
|
17
|
+
* default off — a deliberate escape hatch that skips the loopback-only check).
|
|
18
|
+
* (B) ONNX runtime selection surface: `MEGACOMPACT_ENCODER_NATIVE` is persisted
|
|
19
|
+
* to the per-repo env + surfaced as a Settings toggle, and the GET status route
|
|
20
|
+
* computes the current effective backend + demotion reason through the existing
|
|
21
|
+
* `selectRuntimeBackend` (reader-only — no selection literals reimplemented).
|
|
22
|
+
*
|
|
23
|
+
* `MEGACOMPACT_ENC_1B=0` disables: no new GET fields, no writer branch, no new
|
|
24
|
+
* Settings rows or toggle — byte-identical to the ENC-1a predecessor. The flag
|
|
25
|
+
* MUST also be a dashboard SETTINGS toggle (visible in config UI, never in
|
|
26
|
+
* EXCLUDED_SETTINGS).
|
|
27
|
+
*
|
|
28
|
+
* Pi-agnostic, dependency-free (PREVENT-PI-004 / PREVENT-011).
|
|
29
|
+
*/
|
|
30
|
+
import { sprintFlag } from "./vector-cortex-flag.js";
|
|
31
|
+
/** ENC-1b `MEGACOMPACT_EMBEDDING_DIM` upper bound (positive integer string). */
|
|
32
|
+
export const ENC_1B_MAX_EMBEDDING_DIM = 8192;
|
|
33
|
+
/** Persisted env names pinned here so the aggregator scan + the routes share
|
|
34
|
+
* one source of truth (exactly the names embeddingConfigFromEnv reads). */
|
|
35
|
+
export const ENC_1B_EMBEDDING_DIM_ENV = "MEGACOMPACT_EMBEDDING_DIM";
|
|
36
|
+
export const ENC_1B_EMBEDDING_HEADERS_ENV = "MEGACOMPACT_EMBEDDING_HEADERS";
|
|
37
|
+
export const ENC_1B_ALLOW_REMOTE_EMBEDDER_ENV = "MEGACOMPACT_ALLOW_REMOTE_EMBEDDER";
|
|
38
|
+
export const ENC_1B_ENCODER_NATIVE_ENV = "MEGACOMPACT_ENCODER_NATIVE";
|
|
39
|
+
/**
|
|
40
|
+
* ENC-1b — ONNX runtime backend + embedder API Settings fields. Default ON.
|
|
41
|
+
* `MEGACOMPACT_ENC_1B=0` disables and is byte-identical to the ENC-1a
|
|
42
|
+
* predecessor: no new GET fields, no writer branch, no new Settings rows or
|
|
43
|
+
* toggle. This flag MUST also be a dashboard SETTINGS toggle (visible in config
|
|
44
|
+
* UI, never in EXCLUDED_SETTINGS).
|
|
45
|
+
*/
|
|
46
|
+
export const ENC_1B_ENABLED = () => sprintFlag("MEGACOMPACT_ENC_1B");
|
|
@@ -33,5 +33,6 @@ export { ENC_0E_ENABLED } from "./vector-cortex-enc0e.js";
|
|
|
33
33
|
export { ENC_0F_ENABLED } from "./vector-cortex-enc0f.js";
|
|
34
34
|
export { ENC_0G_ENABLED } from "./vector-cortex-enc0g.js";
|
|
35
35
|
export { ENC_1A_ENABLED } from "./vector-cortex-enc1a.js";
|
|
36
|
+
export { ENC_1B_ENABLED, ENC_1B_MAX_EMBEDDING_DIM, ENC_1B_EMBEDDING_DIM_ENV, ENC_1B_EMBEDDING_HEADERS_ENV, ENC_1B_ALLOW_REMOTE_EMBEDDER_ENV, ENC_1B_ENCODER_NATIVE_ENV, } from "./vector-cortex-enc1b.js";
|
|
36
37
|
// Breaker constants (TRIAD_RESILIENCE.md §breaker) extracted to vector-cortex-breakers.ts.
|
|
37
38
|
export { BREAKER_WINDOW_MS, BREAKER_MIN_ATTEMPTS, BREAKER_PERF_FAILURES, BREAKER_PERF_FAILURE_RATE, BREAKER_CORRECTNESS_FAILURES, BREAKER_COOLDOWN_MS, BREAKER_PROBE_COUNT, BREAKER_RETRY_BASE_MS, BREAKER_RETRY_CAP_MS, BREAKER_RETRY_JITTER, BREAKER_HYSTERESIS_FAILURE_RATE, BREAKER_HYSTERESIS_BUDGET_P95_MS, BREAKER_MIN_HEALTHY_RESIDENCE_MS, } from "./vector-cortex-breakers.js";
|
package/dist/config.js
CHANGED
|
@@ -114,4 +114,4 @@ export const NEW_UI = () => ragEnabled("MEGACOMPACT_NEW_UI");
|
|
|
114
114
|
// default ON, `=0`/`_DISABLED` off. Re-exported from src/config/vector-cortex.ts
|
|
115
115
|
// so root consumers share one source of truth.
|
|
116
116
|
// ---------------------------------------------------------------------------
|
|
117
|
-
export { VC0A_ENABLED, VC0B_ENABLED, VC1A_ENABLED, VC0C_ENABLED, VC1B_ENABLED, VC1C_ENABLED, VC2A_ENABLED, VC2B_ENABLED, VC2C_ENABLED, VC3A_ENABLED, VC3B_ENABLED, VC3C_ENABLED, VC4A_ENABLED, VC4B_ENABLED, VC4C_ENABLED, VC5A_ENABLED, VC5B_ENABLED, VC5C_ENABLED, VC6A_ENABLED, VC6B_ENABLED, VC6C_ENABLED, VC7A_ENABLED, VC7B_ENABLED, VC7C_ENABLED, VC8A_ENABLED, VC8B_ENABLED, VC8C_ENABLED, VC9A_ENABLED, VC9B_ENABLED, VC9C_ENABLED, VC9D_ENABLED, PCC_ENABLED, ML5A_ENABLED, ML5B_ENABLED, ML5C_ENABLED, ML5D_ENABLED, ML5E_ENABLED, DEDUP_ATTR_ENABLED, ENC_0A_ENABLED, ENC_0B_ENABLED, ENC_0C_ENABLED, ENC_0D_ENABLED, ENC_0E_ENABLED, ENC_0F_ENABLED, ENC_0G_ENABLED, ENC_1A_ENABLED, BREAKER_WINDOW_MS, BREAKER_MIN_ATTEMPTS, BREAKER_PERF_FAILURES, BREAKER_PERF_FAILURE_RATE, BREAKER_CORRECTNESS_FAILURES, BREAKER_COOLDOWN_MS, BREAKER_PROBE_COUNT, BREAKER_RETRY_BASE_MS, BREAKER_RETRY_CAP_MS, BREAKER_RETRY_JITTER, BREAKER_HYSTERESIS_FAILURE_RATE, BREAKER_HYSTERESIS_BUDGET_P95_MS, BREAKER_MIN_HEALTHY_RESIDENCE_MS, } from "./config/vector-cortex.js";
|
|
117
|
+
export { VC0A_ENABLED, VC0B_ENABLED, VC1A_ENABLED, VC0C_ENABLED, VC1B_ENABLED, VC1C_ENABLED, VC2A_ENABLED, VC2B_ENABLED, VC2C_ENABLED, VC3A_ENABLED, VC3B_ENABLED, VC3C_ENABLED, VC4A_ENABLED, VC4B_ENABLED, VC4C_ENABLED, VC5A_ENABLED, VC5B_ENABLED, VC5C_ENABLED, VC6A_ENABLED, VC6B_ENABLED, VC6C_ENABLED, VC7A_ENABLED, VC7B_ENABLED, VC7C_ENABLED, VC8A_ENABLED, VC8B_ENABLED, VC8C_ENABLED, VC9A_ENABLED, VC9B_ENABLED, VC9C_ENABLED, VC9D_ENABLED, PCC_ENABLED, ML5A_ENABLED, ML5B_ENABLED, ML5C_ENABLED, ML5D_ENABLED, ML5E_ENABLED, DEDUP_ATTR_ENABLED, ENC_0A_ENABLED, ENC_0B_ENABLED, ENC_0C_ENABLED, ENC_0D_ENABLED, ENC_0E_ENABLED, ENC_0F_ENABLED, ENC_0G_ENABLED, ENC_1A_ENABLED, ENC_1B_ENABLED, BREAKER_WINDOW_MS, BREAKER_MIN_ATTEMPTS, BREAKER_PERF_FAILURES, BREAKER_PERF_FAILURE_RATE, BREAKER_CORRECTNESS_FAILURES, BREAKER_COOLDOWN_MS, BREAKER_PROBE_COUNT, BREAKER_RETRY_BASE_MS, BREAKER_RETRY_CAP_MS, BREAKER_RETRY_JITTER, BREAKER_HYSTERESIS_FAILURE_RATE, BREAKER_HYSTERESIS_BUDGET_P95_MS, BREAKER_MIN_HEALTHY_RESIDENCE_MS, } from "./config/vector-cortex.js";
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* api-contracts/vector-cortex-ledger.ts — VC1B occurrence-ledger surface.
|
|
3
|
+
*
|
|
4
|
+
* Extracted from `vector-cortex.ts` so the combined api-contracts module stays
|
|
5
|
+
* under the 400-line `extensions/` soft limit. Owns the reader-only ledger
|
|
6
|
+
* views (VC1B aggregate + identity rows). PREVENT-PI-004: type definitions
|
|
7
|
+
* only, no network code. PREVENT-011: no `any` type.
|
|
8
|
+
*/
|
|
9
|
+
export {};
|
|
@@ -66,5 +66,6 @@ export const VECTOR_CORTEX_SETTINGS = {
|
|
|
66
66
|
boolDirect("MEGACOMPACT_ENC_0F", "ENC-0f p95 + marginal-RSS Qualification Gate", "ENC-0f p95 + marginal-RSS qualification gate (real trained asset → mode A): runs the ENC-0d-promoted trained asset through the bench under --expose-gc, asserts p95 ≤ 40 ms @ 512/4 threads, marginal RSS ≤ 150 MiB (baseline-subtracted), determinism, and opset-21; on pass emits QualificationV1 + flips runtime to qualified mode A, on failure asset stays demoted to mode B. OFF = no qualification gate runs, no QualificationV1 written, runtime keeps serving the ENC-0d survivor (byte-identical predecessor).", true),
|
|
67
67
|
boolDirect("MEGACOMPACT_ENC_0G", "ENC-0g Setup Cortex honest state (verdict override + live blockers)", "ENC-0g makes the Setup Cortex status route honest: reads the ENC-0f QualificationV1 record (when ENC_0F is ON and a record exists) and lets its verdict override the structural verify for the qualification field; computes the blocker list from (platform, record, manifest head-count) with corrected HG statuses/wording; re-derives VC9B action gating from live blockers. OFF = verdict from verifyEncoderAsset alone, static SETUP_CORTEX_BLOCKERS, static action gating (byte-identical ENC-0f predecessor).", true),
|
|
68
68
|
boolDirect("MEGACOMPACT_ENC_1A", "ENC-1a external embedder API key + endpoint Settings fields", "ENC-1a adds a Settings-visible field pair for the external embedder endpoint URL + optional Bearer API key, persisted by the setup-configure writer branch to the per-repo .mega-compact.env (MEGACOMPACT_EMBEDDING_URL / MEGACOMPACT_EMBEDDING_KEY). The GET status route echoes the endpoint URL and reports embeddingApiKeySet as a boolean ONLY — the raw key is never returned. OFF = no new GET fields, no writer branch, no new Settings text rows (byte-identical ENC-0g predecessor).", true),
|
|
69
|
+
boolDirect("MEGACOMPACT_ENC_1B", "ENC-1b ONNX runtime backend + embedder API settings", "ENC-1b completes the embedder API Settings surface (dim / headers / allow-remote persisted to the per-repo .mega-compact.env) and surfaces the ONNX runtime selection knob (MEGACOMPACT_ENCODER_NATIVE) as a toggle plus the current effective backend + demotion reason. OFF = no new GET fields, no writer branch, no new Settings rows or toggle (byte-identical ENC-1a predecessor).", true),
|
|
69
70
|
],
|
|
70
71
|
};
|
|
@@ -0,0 +1,297 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* dashboard-server/routes-setup-enc1b.ts — ENC-1b embedder API completion +
|
|
3
|
+
* ONNX runtime selection Settings read/write + the additive writer branch.
|
|
4
|
+
*
|
|
5
|
+
* Extracted out of routes-setup.ts (which hovers at the 300-line source soft
|
|
6
|
+
* cap, mirroring the ENC-1a sibling extract) so the ENC-1b additive read/write
|
|
7
|
+
* of the per-repo `.mega-compact.env` keys AND the runtime-backend computation
|
|
8
|
+
* live in a sibling impl file. Four keys are managed here:
|
|
9
|
+
* `MEGACOMPACT_EMBEDDING_DIM`, `MEGACOMPACT_EMBEDDING_HEADERS`,
|
|
10
|
+
* `MEGACOMPACT_ALLOW_REMOTE_EMBEDDER`, `MEGACOMPACT_ENCODER_NATIVE` — the exact
|
|
11
|
+
* names `embeddingConfigFromEnv` (src/httpEmbedder.ts) and the runtime selector
|
|
12
|
+
* read at runtime.
|
|
13
|
+
*
|
|
14
|
+
* The write is create-or-append: it upserts the four keys into the existing
|
|
15
|
+
* per-repo `.mega-compact.env`, preserving every unrelated line and never
|
|
16
|
+
* deleting another key. The read reports the persisted dim, booleans for
|
|
17
|
+
* headers-set / allow-remote / native-opt-in, and computes the current
|
|
18
|
+
* effective backend + demotion reason through the EXISTING `selectRuntimeBackend`
|
|
19
|
+
* (reader-only — the runtime's own selection, never a reimplemented literal,
|
|
20
|
+
* never install logic). The raw headers JSON is NEVER returned, logged or
|
|
21
|
+
* emitted (redaction invariant — it may carry secrets such as an Authorization
|
|
22
|
+
* header for a TEI/ONNX server).
|
|
23
|
+
*
|
|
24
|
+
* Guardrails: PREVENT-PI-004 (local filesystem reads/writes + in-memory
|
|
25
|
+
* runtime selection only, zero network), PREVENT-001 (null-safe JSON),
|
|
26
|
+
* PREVENT-011 (no `any`).
|
|
27
|
+
*/
|
|
28
|
+
import { writeFileSync, mkdirSync, readFileSync, existsSync } from "node:fs";
|
|
29
|
+
import { join } from "node:path";
|
|
30
|
+
import { ENC_1B_ENABLED, ENC_1B_MAX_EMBEDDING_DIM, ENC_1B_EMBEDDING_DIM_ENV, ENC_1B_EMBEDDING_HEADERS_ENV, ENC_1B_ALLOW_REMOTE_EMBEDDER_ENV, ENC_1B_ENCODER_NATIVE_ENV, } from "../../src/config/vector-cortex.js";
|
|
31
|
+
import { selectRuntimeBackend } from "../../src/vector-cortex/encoder/runtime-select.js";
|
|
32
|
+
import { detectPlatform } from "../../src/vector-cortex/encoder/asset.js";
|
|
33
|
+
function envPath(stateDir) {
|
|
34
|
+
return join(stateDir, ".mega-compact.env");
|
|
35
|
+
}
|
|
36
|
+
/** Extract the value of `export MEGACOMPACT_X="..."` (or unquoted) from a line. */
|
|
37
|
+
function lineValue(line, key) {
|
|
38
|
+
const m = line.match(new RegExp(`^export\\s+${key}=(.*)$`));
|
|
39
|
+
if (!m)
|
|
40
|
+
return null;
|
|
41
|
+
const rest = m[1].trim();
|
|
42
|
+
if (rest.length === 0)
|
|
43
|
+
return null;
|
|
44
|
+
const q = rest.match(/^"([^"]*)"$/);
|
|
45
|
+
return q ? q[1] : rest;
|
|
46
|
+
}
|
|
47
|
+
/** True when the payload carries any ENC-1b key (flag-gated). */
|
|
48
|
+
export function wantsEnc1b(body) {
|
|
49
|
+
return (ENC_1B_ENABLED() &&
|
|
50
|
+
(typeof body.embeddingDim === "string" ||
|
|
51
|
+
typeof body.embeddingHeaders === "string" ||
|
|
52
|
+
typeof body.allowRemoteEmbedder === "boolean" ||
|
|
53
|
+
typeof body.encoderNativeOptIn === "boolean"));
|
|
54
|
+
}
|
|
55
|
+
/** Read the ENC-1b keys from the per-repo `.mega-compact.env`. The headers
|
|
56
|
+
* value is NEVER surfaced to callers — only its presence boolean. */
|
|
57
|
+
export function readEnc1bEnv(stateDir) {
|
|
58
|
+
try {
|
|
59
|
+
const p = envPath(stateDir);
|
|
60
|
+
if (!existsSync(p))
|
|
61
|
+
return { dim: null, headersSet: false, allowRemote: false, nativeOptIn: false };
|
|
62
|
+
const lines = readFileSync(p, "utf8").split(/\r?\n/);
|
|
63
|
+
let dim = null;
|
|
64
|
+
let headersSet = false;
|
|
65
|
+
let allowRemote = false;
|
|
66
|
+
let nativeOptIn = false;
|
|
67
|
+
for (const line of lines) {
|
|
68
|
+
const d = lineValue(line, ENC_1B_EMBEDDING_DIM_ENV);
|
|
69
|
+
if (d !== null && d.length > 0)
|
|
70
|
+
dim = d;
|
|
71
|
+
const h = lineValue(line, ENC_1B_EMBEDDING_HEADERS_ENV);
|
|
72
|
+
if (h !== null && h.length > 0)
|
|
73
|
+
headersSet = true;
|
|
74
|
+
const a = lineValue(line, ENC_1B_ALLOW_REMOTE_EMBEDDER_ENV);
|
|
75
|
+
if (a !== null && ["1", "true", "yes"].includes(a.trim().toLowerCase()))
|
|
76
|
+
allowRemote = true;
|
|
77
|
+
const n = lineValue(line, ENC_1B_ENCODER_NATIVE_ENV);
|
|
78
|
+
if (n !== null && ["1", "true", "yes"].includes(n.trim().toLowerCase()))
|
|
79
|
+
nativeOptIn = true;
|
|
80
|
+
}
|
|
81
|
+
return { dim, headersSet, allowRemote, nativeOptIn };
|
|
82
|
+
}
|
|
83
|
+
catch {
|
|
84
|
+
return { dim: null, headersSet: false, allowRemote: false, nativeOptIn: false };
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
/**
|
|
88
|
+
* ENC-1b additive GET status fields. All omitted when flag-off. The Cortex
|
|
89
|
+
* trio (native opt-in + effective backend + demotion reason) is computed here
|
|
90
|
+
* (reader-only): the stored opt-in + current platform drive the EXISTING
|
|
91
|
+
* `selectRuntimeBackend`, whose own demotion reason is surfaced verbatim when
|
|
92
|
+
* the runtime falls back. `modeB` (flag-off selection) is projected to `wasm`
|
|
93
|
+
* for display. Returns `{}` when the flag is off (byte-identical predecessor).
|
|
94
|
+
*/
|
|
95
|
+
export function enc1bStatusFields(stateDir) {
|
|
96
|
+
if (!ENC_1B_ENABLED())
|
|
97
|
+
return {};
|
|
98
|
+
const env = readEnc1bEnv(stateDir);
|
|
99
|
+
const platform = detectPlatform();
|
|
100
|
+
const chosen = selectRuntimeBackend({
|
|
101
|
+
platform: platform ?? "unsupported",
|
|
102
|
+
benchRecord: null,
|
|
103
|
+
nativeOptIn: env.nativeOptIn,
|
|
104
|
+
});
|
|
105
|
+
const backend = chosen.backend === "native" ? "native" : "wasm";
|
|
106
|
+
return {
|
|
107
|
+
...(env.dim !== null ? { embeddingDim: env.dim } : {}),
|
|
108
|
+
embeddingHeadersSet: env.headersSet,
|
|
109
|
+
allowRemoteEmbedder: env.allowRemote,
|
|
110
|
+
encoderNativeOptIn: env.nativeOptIn,
|
|
111
|
+
encoderBackend: backend,
|
|
112
|
+
encoderDemotionReason: chosen.demotionReason,
|
|
113
|
+
};
|
|
114
|
+
}
|
|
115
|
+
/** Upsert the ENC-1b keys into the per-repo `.mega-compact.env`. Creates the
|
|
116
|
+
* file if absent; preserves every unrelated line; never deletes other keys.
|
|
117
|
+
* A `null` entry leaves that key's line untouched. The headers value is
|
|
118
|
+
* wrapped in single quotes so the inner JSON double quotes survive the env
|
|
119
|
+
* loader's outer-quote strip (shell-sourceable + loader-compatible). */
|
|
120
|
+
export function writeEnc1bEnv(stateDir, entries) {
|
|
121
|
+
const p = envPath(stateDir);
|
|
122
|
+
const existingLines = existsSync(p) ? readFileSync(p, "utf8").split(/\r?\n/) : [];
|
|
123
|
+
const out = [];
|
|
124
|
+
const keys = new Set([
|
|
125
|
+
{
|
|
126
|
+
key: ENC_1B_EMBEDDING_DIM_ENV,
|
|
127
|
+
present: () => entries.dim !== null,
|
|
128
|
+
push: () => out.push(`export ${ENC_1B_EMBEDDING_DIM_ENV}="${entries.dim ?? ""}"`),
|
|
129
|
+
},
|
|
130
|
+
{
|
|
131
|
+
key: ENC_1B_EMBEDDING_HEADERS_ENV,
|
|
132
|
+
present: () => entries.headers !== null,
|
|
133
|
+
push: () => out.push(`export ${ENC_1B_EMBEDDING_HEADERS_ENV}='${entries.headers ?? ""}'`),
|
|
134
|
+
},
|
|
135
|
+
{
|
|
136
|
+
key: ENC_1B_ALLOW_REMOTE_EMBEDDER_ENV,
|
|
137
|
+
present: () => entries.allowRemote !== null,
|
|
138
|
+
push: () => out.push(entries.allowRemote
|
|
139
|
+
? `export ${ENC_1B_ALLOW_REMOTE_EMBEDDER_ENV}="1"`
|
|
140
|
+
: `export ${ENC_1B_ALLOW_REMOTE_EMBEDDER_ENV}="0"`),
|
|
141
|
+
},
|
|
142
|
+
{
|
|
143
|
+
key: ENC_1B_ENCODER_NATIVE_ENV,
|
|
144
|
+
present: () => entries.nativeOptIn !== null,
|
|
145
|
+
push: () => out.push(entries.nativeOptIn
|
|
146
|
+
? `export ${ENC_1B_ENCODER_NATIVE_ENV}="1"`
|
|
147
|
+
: `export ${ENC_1B_ENCODER_NATIVE_ENV}="0"`),
|
|
148
|
+
},
|
|
149
|
+
]);
|
|
150
|
+
const written = new Set();
|
|
151
|
+
for (const line of existingLines) {
|
|
152
|
+
let replaced = false;
|
|
153
|
+
for (const k of keys) {
|
|
154
|
+
if (k.present() && lineValue(line, k.key) !== null) {
|
|
155
|
+
k.push();
|
|
156
|
+
written.add(k.key);
|
|
157
|
+
replaced = true;
|
|
158
|
+
break;
|
|
159
|
+
}
|
|
160
|
+
}
|
|
161
|
+
if (!replaced)
|
|
162
|
+
out.push(line);
|
|
163
|
+
}
|
|
164
|
+
for (const k of keys) {
|
|
165
|
+
if (k.present() && !written.has(k.key))
|
|
166
|
+
k.push();
|
|
167
|
+
}
|
|
168
|
+
mkdirSync(stateDir, { recursive: true });
|
|
169
|
+
writeFileSync(p, out.join("\n"), "utf-8");
|
|
170
|
+
return p;
|
|
171
|
+
}
|
|
172
|
+
/** Validate `embeddingDim` as a positive integer string within the ENC-1b cap.
|
|
173
|
+
* Returns `null` when valid, else the error code. Exported so the routes host
|
|
174
|
+
* (combined-payload path) and the aggregator share the same rule. */
|
|
175
|
+
export function validateDim(value) {
|
|
176
|
+
if (typeof value !== "string" || value.trim().length === 0)
|
|
177
|
+
return "invalid_embedding_dim";
|
|
178
|
+
if (!/^\d+$/.test(value))
|
|
179
|
+
return "invalid_embedding_dim";
|
|
180
|
+
const n = Number(value);
|
|
181
|
+
if (!Number.isSafeInteger(n) || n < 1 || n > ENC_1B_MAX_EMBEDDING_DIM) {
|
|
182
|
+
return "invalid_embedding_dim";
|
|
183
|
+
}
|
|
184
|
+
return null;
|
|
185
|
+
}
|
|
186
|
+
/** Validate `embeddingHeaders` as a string that parses to a JSON object.
|
|
187
|
+
* Returns `null` when valid, else the error code. Exported so the routes host
|
|
188
|
+
* (combined-payload path) and the aggregator share the same rule. */
|
|
189
|
+
export function validateHeaders(value) {
|
|
190
|
+
if (typeof value !== "string" || value.trim().length === 0)
|
|
191
|
+
return "invalid_embedding_headers";
|
|
192
|
+
let parsed;
|
|
193
|
+
try {
|
|
194
|
+
parsed = JSON.parse(value);
|
|
195
|
+
}
|
|
196
|
+
catch {
|
|
197
|
+
return "invalid_embedding_headers";
|
|
198
|
+
}
|
|
199
|
+
if (typeof parsed !== "object" || parsed === null || Array.isArray(parsed)) {
|
|
200
|
+
return "invalid_embedding_headers";
|
|
201
|
+
}
|
|
202
|
+
return null;
|
|
203
|
+
}
|
|
204
|
+
/**
|
|
205
|
+
* Combined-payload upsert: after the main embedder write has freshly written
|
|
206
|
+
* the per-repo env, append any ENC-1b keys carried alongside a valid embedder
|
|
207
|
+
* selection (flag-gated, additive). No-op when flag-off or no ENC-1b key.
|
|
208
|
+
*/
|
|
209
|
+
export function tryEnc1bInto(stateDir, body) {
|
|
210
|
+
if (!wantsEnc1b(body))
|
|
211
|
+
return;
|
|
212
|
+
writeEnc1bEnv(stateDir, {
|
|
213
|
+
dim: typeof body.embeddingDim === "string" ? body.embeddingDim : null,
|
|
214
|
+
headers: typeof body.embeddingHeaders === "string" ? body.embeddingHeaders : null,
|
|
215
|
+
allowRemote: typeof body.allowRemoteEmbedder === "boolean" ? body.allowRemoteEmbedder : null,
|
|
216
|
+
nativeOptIn: typeof body.encoderNativeOptIn === "boolean" ? body.encoderNativeOptIn : null,
|
|
217
|
+
});
|
|
218
|
+
}
|
|
219
|
+
/**
|
|
220
|
+
* If the payload is a pure ENC-1b configure (new keys, no embedder selection),
|
|
221
|
+
* validate + write them additively to the per-repo env and reply. Returns true
|
|
222
|
+
* when it fully handled the request. On a validation failure it replies 400
|
|
223
|
+
* with the code and leaves the file byte-unchanged. Flag-off = keys are not
|
|
224
|
+
* recognized and this returns false (byte-identical ENC-1a predecessor).
|
|
225
|
+
*/
|
|
226
|
+
/**
|
|
227
|
+
* Combined-path validation: the standalone `tryEnc1bConfigure` handles the
|
|
228
|
+
* pure-ENC-1b shape; when a payload ALSO carries a valid embedder the sibling
|
|
229
|
+
* writer returns false and the routes host is responsible for running the same
|
|
230
|
+
* dim/headers validation before the combined upsert — returned as the error
|
|
231
|
+
* code string, or `null` if everything passes (or the flag is off).
|
|
232
|
+
*/
|
|
233
|
+
export function enc1bValidateCombined(body) {
|
|
234
|
+
if (!ENC_1B_ENABLED())
|
|
235
|
+
return null;
|
|
236
|
+
if (body.embeddingDim !== undefined) {
|
|
237
|
+
const e = validateDim(body.embeddingDim);
|
|
238
|
+
if (e !== null)
|
|
239
|
+
return e;
|
|
240
|
+
}
|
|
241
|
+
if (body.embeddingHeaders !== undefined) {
|
|
242
|
+
const e = validateHeaders(body.embeddingHeaders);
|
|
243
|
+
if (e !== null)
|
|
244
|
+
return e;
|
|
245
|
+
}
|
|
246
|
+
return null;
|
|
247
|
+
}
|
|
248
|
+
export function tryEnc1bConfigure(body, res, ctx) {
|
|
249
|
+
if (!wantsEnc1b(body))
|
|
250
|
+
return false;
|
|
251
|
+
const embedder = body.embedder;
|
|
252
|
+
const embedderValid = !!embedder &&
|
|
253
|
+
(embedder === "ollama" || embedder === "llama" || embedder === "trigram" ||
|
|
254
|
+
embedder === "custom" || embedder === "onnx");
|
|
255
|
+
if (embedderValid)
|
|
256
|
+
return false; // combined payload — integrated after the embedder write
|
|
257
|
+
// Each key is optional: only validate the ones actually carried in the
|
|
258
|
+
// payload (absent keys are left untouched, never rejected).
|
|
259
|
+
const dimError = body.embeddingDim === undefined ? null : validateDim(body.embeddingDim);
|
|
260
|
+
if (dimError !== null) {
|
|
261
|
+
// guardrails-allow PREVENT-PI-004: loopback dashboard response (local)
|
|
262
|
+
res.writeHead(400, { "Content-Type": "application/json" });
|
|
263
|
+
res.end(JSON.stringify({ error: dimError }));
|
|
264
|
+
return true;
|
|
265
|
+
}
|
|
266
|
+
const headersError = body.embeddingHeaders === undefined ? null : validateHeaders(body.embeddingHeaders);
|
|
267
|
+
if (headersError !== null) {
|
|
268
|
+
// guardrails-allow PREVENT-PI-004: loopback dashboard response (local)
|
|
269
|
+
res.writeHead(400, { "Content-Type": "application/json" });
|
|
270
|
+
res.end(JSON.stringify({ error: headersError }));
|
|
271
|
+
return true;
|
|
272
|
+
}
|
|
273
|
+
try {
|
|
274
|
+
const envPath = writeEnc1bEnv(ctx.stateDir, {
|
|
275
|
+
dim: typeof body.embeddingDim === "string" ? body.embeddingDim : null,
|
|
276
|
+
headers: typeof body.embeddingHeaders === "string" ? body.embeddingHeaders : null,
|
|
277
|
+
allowRemote: typeof body.allowRemoteEmbedder === "boolean" ? body.allowRemoteEmbedder : null,
|
|
278
|
+
nativeOptIn: typeof body.encoderNativeOptIn === "boolean" ? body.encoderNativeOptIn : null,
|
|
279
|
+
});
|
|
280
|
+
const resp = {
|
|
281
|
+
embedder: "custom",
|
|
282
|
+
url: null,
|
|
283
|
+
envPath,
|
|
284
|
+
restartRequired: true,
|
|
285
|
+
alreadyActive: false,
|
|
286
|
+
};
|
|
287
|
+
// guardrails-allow PREVENT-PI-004: loopback dashboard response (local)
|
|
288
|
+
res.writeHead(200, { "Content-Type": "application/json" });
|
|
289
|
+
res.end(JSON.stringify(resp));
|
|
290
|
+
return true;
|
|
291
|
+
}
|
|
292
|
+
catch (e) {
|
|
293
|
+
res.writeHead(500, { "Content-Type": "application/json" });
|
|
294
|
+
res.end(JSON.stringify({ error: `write_failed: ${e instanceof Error ? e.message : String(e)}` }));
|
|
295
|
+
return true;
|
|
296
|
+
}
|
|
297
|
+
}
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* routes-setup-env-upsert.ts — upsert-style write of the per-repo
|
|
3
|
+
* `.mega-compact.env` for the primary embedder selection.
|
|
4
|
+
*
|
|
5
|
+
* Extracted from routes-setup.ts so the route stays under the 300-line soft
|
|
6
|
+
* cap. The writer preserves every unrelated line (ENC-1a's endpoint/key,
|
|
7
|
+
* ENC-1b's dim/headers, operator comments) and replaces only the three keys
|
|
8
|
+
* this primary write owns — MEGACOMPACT_EMBEDDING_URL,
|
|
9
|
+
* MEGACOMPACT_ALLOW_REMOTE_EMBEDDER, MEGACOMPACT_MINILM. URLs already persisted
|
|
10
|
+
* by enc1a/enc1b helpers are NOT clobbered across a later native-opt-in POST
|
|
11
|
+
* (the ENC-1b defect class caught in live review).
|
|
12
|
+
*/
|
|
13
|
+
import { writeFileSync, mkdirSync, readFileSync, existsSync } from "node:fs";
|
|
14
|
+
import { join } from "node:path";
|
|
15
|
+
/** Line-prefix recognizer for an owned key (covers active, commented, and prose forms). */
|
|
16
|
+
function ownsKey(line, key) {
|
|
17
|
+
return (line.startsWith(`export ${key}=`) ||
|
|
18
|
+
line.startsWith(`# export ${key}=`) ||
|
|
19
|
+
line.startsWith(`# ${key} `));
|
|
20
|
+
}
|
|
21
|
+
const OWNED_PREFIXES = [
|
|
22
|
+
"MEGACOMPACT_EMBEDDING_URL",
|
|
23
|
+
"MEGACOMPACT_ALLOW_REMOTE_EMBEDDER",
|
|
24
|
+
"MEGACOMPACT_MINILM",
|
|
25
|
+
];
|
|
26
|
+
const SCAFFOLD_COMMENTS = new Set([
|
|
27
|
+
"# Mega-Compact Embedder Configuration",
|
|
28
|
+
"# trigram: built-in embedder, no URL needed",
|
|
29
|
+
"# unset MEGACOMPACT_EMBEDDING_URL (commented to override any shell-set value)",
|
|
30
|
+
"# MEGACOMPACT_ALLOW_REMOTE_EMBEDDER not set (loopback-only)",
|
|
31
|
+
]);
|
|
32
|
+
function isScaffoldComment(line) {
|
|
33
|
+
return (SCAFFOLD_COMMENTS.has(line) ||
|
|
34
|
+
line.startsWith("# Configured via dashboard Setup tab at "));
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* Write the embedder selection upsert-style into `<stateDir>/.mega-compact.env`.
|
|
38
|
+
* `resolvedUrl === null` selects the trigram (built-in) path — the emitted
|
|
39
|
+
* lines carry only the scaffold comments for that case (the URL/remote lines
|
|
40
|
+
* are intentionally absent, matching the pre-refactor byte shape).
|
|
41
|
+
*/
|
|
42
|
+
export function writeEmbedderEnv(stateDir, resolvedUrl, allowRemote) {
|
|
43
|
+
const envPath = join(stateDir, ".mega-compact.env");
|
|
44
|
+
const existingLines = (() => {
|
|
45
|
+
try {
|
|
46
|
+
return existsSync(envPath) ? readFileSync(envPath, "utf-8").split("\n") : [];
|
|
47
|
+
}
|
|
48
|
+
catch {
|
|
49
|
+
return [];
|
|
50
|
+
}
|
|
51
|
+
})();
|
|
52
|
+
const preserved = existingLines.filter((l) => l.trim().length > 0 &&
|
|
53
|
+
!isScaffoldComment(l) &&
|
|
54
|
+
!OWNED_PREFIXES.some((p) => ownsKey(l, p)));
|
|
55
|
+
const next = [
|
|
56
|
+
"# Mega-Compact Embedder Configuration",
|
|
57
|
+
`# Configured via dashboard Setup tab at ${new Date().toISOString()}`,
|
|
58
|
+
...preserved,
|
|
59
|
+
];
|
|
60
|
+
if (resolvedUrl !== null) {
|
|
61
|
+
next.push(`export MEGACOMPACT_EMBEDDING_URL="${resolvedUrl}"`);
|
|
62
|
+
if (allowRemote) {
|
|
63
|
+
next.push(`export MEGACOMPACT_ALLOW_REMOTE_EMBEDDER="1"`);
|
|
64
|
+
}
|
|
65
|
+
else {
|
|
66
|
+
next.push(`# MEGACOMPACT_ALLOW_REMOTE_EMBEDDER not set (loopback-only)`);
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
else {
|
|
70
|
+
next.push("# trigram: built-in embedder, no URL needed");
|
|
71
|
+
next.push("# unset MEGACOMPACT_EMBEDDING_URL (commented to override any shell-set value)");
|
|
72
|
+
next.push("# export MEGACOMPACT_EMBEDDING_URL=");
|
|
73
|
+
next.push("# export MEGACOMPACT_ALLOW_REMOTE_EMBEDDER=");
|
|
74
|
+
}
|
|
75
|
+
next.push("");
|
|
76
|
+
mkdirSync(stateDir, { recursive: true });
|
|
77
|
+
writeFileSync(envPath, next.join("\n"), "utf-8");
|
|
78
|
+
return envPath;
|
|
79
|
+
}
|
|
@@ -8,10 +8,12 @@
|
|
|
8
8
|
* The detection commands run local subprocesses via spawnSync, NOT network calls.
|
|
9
9
|
* Each decoration line carries a guardrails-allow annotation.
|
|
10
10
|
*/
|
|
11
|
-
import {
|
|
11
|
+
import { readFileSync, existsSync } from "node:fs";
|
|
12
12
|
import { join } from "node:path";
|
|
13
13
|
import { VC9D_ENABLED } from "../../src/config.js";
|
|
14
14
|
import { enc1aStatusFields, writeEnc1aEnv, tryEnc1aConfigure, wantsEnc1a } from "./routes-setup-enc1a.js";
|
|
15
|
+
import { enc1bStatusFields, tryEnc1bConfigure, tryEnc1bInto, enc1bValidateCombined } from "./routes-setup-enc1b.js";
|
|
16
|
+
import { writeEmbedderEnv } from "./routes-setup-env-upsert.js";
|
|
15
17
|
import { detectOllama, detectLlamaCpp, detectOnnx, memoizedDetectOllama, memoizedDetectLlamaCpp, memoizedDetectOnnx, } from "./routes-setup-detect-cache.js";
|
|
16
18
|
// ---------------------------------------------------------------------------
|
|
17
19
|
// handleSetupStatus — "/api/setup-status"
|
|
@@ -68,7 +70,7 @@ export function handleSetupStatus(req, res, ctx) {
|
|
|
68
70
|
embeddingUrl: process.env["MEGACOMPACT_EMBEDDING_URL"] ?? configured.url,
|
|
69
71
|
embedCache: process.env["MEGACOMPACT_EMBED_CACHE"] ?? null,
|
|
70
72
|
minilm: ["1", "true", "yes"].includes((process.env["MEGACOMPACT_MINILM"] ?? "").trim().toLowerCase()),
|
|
71
|
-
...enc1aStatusFields(ctx.stateDir),
|
|
73
|
+
...enc1aStatusFields(ctx.stateDir), ...enc1bStatusFields(ctx.stateDir),
|
|
72
74
|
};
|
|
73
75
|
// guardrails-allow PREVENT-PI-004: loopback dashboard response (local)
|
|
74
76
|
res.writeHead(200, { "Content-Type": "application/json" });
|
|
@@ -176,6 +178,22 @@ export function handleSetupConfigure(req, res, ctx) {
|
|
|
176
178
|
// pre-ENC-1a embedder path below (byte-identical predecessor).
|
|
177
179
|
if (tryEnc1aConfigure(body, res, ctx))
|
|
178
180
|
return;
|
|
181
|
+
if (tryEnc1bConfigure(body, res, ctx))
|
|
182
|
+
return; // pure ENC-1b configure (dim/headers/allow-remote/native)
|
|
183
|
+
// ENC-1b combined-payload validation: when a payload carries a valid
|
|
184
|
+
// embedder PLUS the ENC-1b keys, tryEnc1bConfigure above returned false
|
|
185
|
+
// (it handles only the pure-ENC-1b shape) and tryEnc1bInto below would
|
|
186
|
+
// write WITHOUT validating. Run the same dim/headers validation here so
|
|
187
|
+
// the combined path is rejected with the same 400 codes. Flag-off:
|
|
188
|
+
// enc1bValidateCombined returns null (byte-identical predecessor — the
|
|
189
|
+
// unknown keys fall through untouched).
|
|
190
|
+
const combinedError = enc1bValidateCombined(body);
|
|
191
|
+
if (combinedError !== null) {
|
|
192
|
+
// guardrails-allow PREVENT-PI-004: loopback dashboard response (local)
|
|
193
|
+
res.writeHead(400, { "Content-Type": "application/json" });
|
|
194
|
+
res.end(JSON.stringify({ error: combinedError }));
|
|
195
|
+
return;
|
|
196
|
+
}
|
|
179
197
|
const embedder = body.embedder;
|
|
180
198
|
if (embedder !== "ollama" && embedder !== "llama" && embedder !== "trigram" && embedder !== "custom" && embedder !== "onnx") {
|
|
181
199
|
res.writeHead(400, { "Content-Type": "application/json" });
|
|
@@ -204,32 +222,14 @@ export function handleSetupConfigure(req, res, ctx) {
|
|
|
204
222
|
}
|
|
205
223
|
else
|
|
206
224
|
resolvedUrl = null;
|
|
207
|
-
//
|
|
225
|
+
// Upsert-style write of the per-repo .mega-compact.env (sibling impl):
|
|
226
|
+
// preserves ENC-1a's endpoint/key + ENC-1b's dim/headers lines and any
|
|
227
|
+
// operator comments, replacing only the three keys this primary embedder
|
|
228
|
+
// write owns (URL / ALLOW_REMOTE / MINILM).
|
|
208
229
|
const stateDir = ctx.stateDir;
|
|
209
|
-
|
|
210
|
-
const lines = [
|
|
211
|
-
"# Mega-Compact Embedder Configuration",
|
|
212
|
-
`# Configured via dashboard Setup tab at ${new Date().toISOString()}`,
|
|
213
|
-
];
|
|
214
|
-
if (resolvedUrl) {
|
|
215
|
-
lines.push(`export MEGACOMPACT_EMBEDDING_URL="${resolvedUrl}"`);
|
|
216
|
-
if (allowRemote) {
|
|
217
|
-
lines.push(`export MEGACOMPACT_ALLOW_REMOTE_EMBEDDER="1"`);
|
|
218
|
-
}
|
|
219
|
-
else {
|
|
220
|
-
lines.push(`# MEGACOMPACT_ALLOW_REMOTE_EMBEDDER not set (loopback-only)`);
|
|
221
|
-
}
|
|
222
|
-
}
|
|
223
|
-
else {
|
|
224
|
-
lines.push("# trigram: built-in embedder, no URL needed");
|
|
225
|
-
lines.push("# unset MEGACOMPACT_EMBEDDING_URL (commented to override any shell-set value)");
|
|
226
|
-
lines.push("# export MEGACOMPACT_EMBEDDING_URL=");
|
|
227
|
-
lines.push("# export MEGACOMPACT_ALLOW_REMOTE_EMBEDDER=");
|
|
228
|
-
}
|
|
229
|
-
lines.push("");
|
|
230
|
+
let envPath;
|
|
230
231
|
try {
|
|
231
|
-
|
|
232
|
-
writeFileSync(envPath, lines.join("\n"), "utf-8");
|
|
232
|
+
envPath = writeEmbedderEnv(stateDir, resolvedUrl, allowRemote);
|
|
233
233
|
}
|
|
234
234
|
catch (e) {
|
|
235
235
|
res.writeHead(500, { "Content-Type": "application/json" });
|
|
@@ -246,6 +246,7 @@ export function handleSetupConfigure(req, res, ctx) {
|
|
|
246
246
|
apiKey: typeof body.embeddingApiKey === "string" ? body.embeddingApiKey : null,
|
|
247
247
|
});
|
|
248
248
|
}
|
|
249
|
+
tryEnc1bInto(stateDir, body); // ENC-1b combined upsert (dim/headers/allow-remote/native)
|
|
249
250
|
// Detect if the new config matches what's already active (no restart needed).
|
|
250
251
|
const currentUrl = process.env["MEGACOMPACT_EMBEDDING_URL"];
|
|
251
252
|
const alreadyActive = (resolvedUrl === null && !currentUrl) || (resolvedUrl !== null && currentUrl === resolvedUrl);
|
|
@@ -9,7 +9,7 @@
|
|
|
9
9
|
* Guardrails: PREVENT-PI-004 (local filesystem read only), PREVENT-011 (no
|
|
10
10
|
* `any`), reader-only aggregate (never payloads/prompts/ledger — EVAL-REDACT-002).
|
|
11
11
|
*/
|
|
12
|
-
import { VC0A_ENABLED } from "../../src/config.js";
|
|
12
|
+
import { VC0A_ENABLED, ML5D_ENABLED } from "../../src/config.js";
|
|
13
13
|
import { readEvalRows } from "../../src/vector-cortex/eval/persist.js";
|
|
14
14
|
import { summarizeEvalRows } from "../../src/vector-cortex/eval/reader.js";
|
|
15
15
|
import { sendJson } from "./routes-vector-cortex-shared.js";
|
|
@@ -43,6 +43,9 @@ export function handleVectorCortexEvaluation(req, res, ctx) {
|
|
|
43
43
|
total: summary.histogram.total,
|
|
44
44
|
},
|
|
45
45
|
rejects: [], // VC0C wires live breaker/reject telemetry here
|
|
46
|
+
// ML5-D: additive, present only when the flag is enabled → the client can
|
|
47
|
+
// omit the ModelImprovementCard when off (byte-identical to ML5-C-era tab).
|
|
48
|
+
...(ML5D_ENABLED() ? { ml5dEnabled: true } : {}),
|
|
46
49
|
updatedAt: new Date().toISOString(),
|
|
47
50
|
status: deriveVcStatus({ enabled, hasData: summary.samples > 0 }),
|
|
48
51
|
};
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* config/vector-cortex-enc1b.ts — ENC-1b ONNX runtime backend + embedder API
|
|
3
|
+
* Settings fields.
|
|
4
|
+
*
|
|
5
|
+
* Extracted from vector-cortex.ts so that file stays under the 300-line soft
|
|
6
|
+
* limit (soft-as-hard gate), exactly as the ENC-1a sibling was. vector-cortex.ts
|
|
7
|
+
* re-exports the flag + constants below and root src/config.ts re-exports them,
|
|
8
|
+
* so no consumer import path changes.
|
|
9
|
+
*
|
|
10
|
+
* ENC-1b adds two Settings surfaces. (A) Embedder API completion: the three
|
|
11
|
+
* remaining env vars the runtime reads (src/httpEmbedder.ts:embeddingConfigFromEnv)
|
|
12
|
+
* gain dashboard-visible fields — `MEGACOMPACT_EMBEDDING_DIM` (numeric, validated
|
|
13
|
+
* positive int bounded by `ENC_1B_MAX_EMBEDDING_DIM`), `MEGACOMPACT_EMBEDDING_HEADERS`
|
|
14
|
+
* (JSON object string — secret-bearing, written verbatim to the per-repo
|
|
15
|
+
* `.mega-compact.env`, NEVER echoed raw; the GET reports only a boolean
|
|
16
|
+
* presence marker), and `MEGACOMPACT_ALLOW_REMOTE_EMBEDDER` (boolDirect toggle,
|
|
17
|
+
* default off — a deliberate escape hatch that skips the loopback-only check).
|
|
18
|
+
* (B) ONNX runtime selection surface: `MEGACOMPACT_ENCODER_NATIVE` is persisted
|
|
19
|
+
* to the per-repo env + surfaced as a Settings toggle, and the GET status route
|
|
20
|
+
* computes the current effective backend + demotion reason through the existing
|
|
21
|
+
* `selectRuntimeBackend` (reader-only — no selection literals reimplemented).
|
|
22
|
+
*
|
|
23
|
+
* `MEGACOMPACT_ENC_1B=0` disables: no new GET fields, no writer branch, no new
|
|
24
|
+
* Settings rows or toggle — byte-identical to the ENC-1a predecessor. The flag
|
|
25
|
+
* MUST also be a dashboard SETTINGS toggle (visible in config UI, never in
|
|
26
|
+
* EXCLUDED_SETTINGS).
|
|
27
|
+
*
|
|
28
|
+
* Pi-agnostic, dependency-free (PREVENT-PI-004 / PREVENT-011).
|
|
29
|
+
*/
|
|
30
|
+
import { sprintFlag } from "./vector-cortex-flag.js";
|
|
31
|
+
/** ENC-1b `MEGACOMPACT_EMBEDDING_DIM` upper bound (positive integer string). */
|
|
32
|
+
export const ENC_1B_MAX_EMBEDDING_DIM = 8192;
|
|
33
|
+
/** Persisted env names pinned here so the aggregator scan + the routes share
|
|
34
|
+
* one source of truth (exactly the names embeddingConfigFromEnv reads). */
|
|
35
|
+
export const ENC_1B_EMBEDDING_DIM_ENV = "MEGACOMPACT_EMBEDDING_DIM";
|
|
36
|
+
export const ENC_1B_EMBEDDING_HEADERS_ENV = "MEGACOMPACT_EMBEDDING_HEADERS";
|
|
37
|
+
export const ENC_1B_ALLOW_REMOTE_EMBEDDER_ENV = "MEGACOMPACT_ALLOW_REMOTE_EMBEDDER";
|
|
38
|
+
export const ENC_1B_ENCODER_NATIVE_ENV = "MEGACOMPACT_ENCODER_NATIVE";
|
|
39
|
+
/**
|
|
40
|
+
* ENC-1b — ONNX runtime backend + embedder API Settings fields. Default ON.
|
|
41
|
+
* `MEGACOMPACT_ENC_1B=0` disables and is byte-identical to the ENC-1a
|
|
42
|
+
* predecessor: no new GET fields, no writer branch, no new Settings rows or
|
|
43
|
+
* toggle. This flag MUST also be a dashboard SETTINGS toggle (visible in config
|
|
44
|
+
* UI, never in EXCLUDED_SETTINGS).
|
|
45
|
+
*/
|
|
46
|
+
export const ENC_1B_ENABLED = () => sprintFlag("MEGACOMPACT_ENC_1B");
|
|
@@ -33,5 +33,6 @@ export { ENC_0E_ENABLED } from "./vector-cortex-enc0e.js";
|
|
|
33
33
|
export { ENC_0F_ENABLED } from "./vector-cortex-enc0f.js";
|
|
34
34
|
export { ENC_0G_ENABLED } from "./vector-cortex-enc0g.js";
|
|
35
35
|
export { ENC_1A_ENABLED } from "./vector-cortex-enc1a.js";
|
|
36
|
+
export { ENC_1B_ENABLED, ENC_1B_MAX_EMBEDDING_DIM, ENC_1B_EMBEDDING_DIM_ENV, ENC_1B_EMBEDDING_HEADERS_ENV, ENC_1B_ALLOW_REMOTE_EMBEDDER_ENV, ENC_1B_ENCODER_NATIVE_ENV, } from "./vector-cortex-enc1b.js";
|
|
36
37
|
// Breaker constants (TRIAD_RESILIENCE.md §breaker) extracted to vector-cortex-breakers.ts.
|
|
37
38
|
export { BREAKER_WINDOW_MS, BREAKER_MIN_ATTEMPTS, BREAKER_PERF_FAILURES, BREAKER_PERF_FAILURE_RATE, BREAKER_CORRECTNESS_FAILURES, BREAKER_COOLDOWN_MS, BREAKER_PROBE_COUNT, BREAKER_RETRY_BASE_MS, BREAKER_RETRY_CAP_MS, BREAKER_RETRY_JITTER, BREAKER_HYSTERESIS_FAILURE_RATE, BREAKER_HYSTERESIS_BUDGET_P95_MS, BREAKER_MIN_HEALTHY_RESIDENCE_MS, } from "./vector-cortex-breakers.js";
|
package/dist/src/config.js
CHANGED
|
@@ -114,4 +114,4 @@ export const NEW_UI = () => ragEnabled("MEGACOMPACT_NEW_UI");
|
|
|
114
114
|
// default ON, `=0`/`_DISABLED` off. Re-exported from src/config/vector-cortex.ts
|
|
115
115
|
// so root consumers share one source of truth.
|
|
116
116
|
// ---------------------------------------------------------------------------
|
|
117
|
-
export { VC0A_ENABLED, VC0B_ENABLED, VC1A_ENABLED, VC0C_ENABLED, VC1B_ENABLED, VC1C_ENABLED, VC2A_ENABLED, VC2B_ENABLED, VC2C_ENABLED, VC3A_ENABLED, VC3B_ENABLED, VC3C_ENABLED, VC4A_ENABLED, VC4B_ENABLED, VC4C_ENABLED, VC5A_ENABLED, VC5B_ENABLED, VC5C_ENABLED, VC6A_ENABLED, VC6B_ENABLED, VC6C_ENABLED, VC7A_ENABLED, VC7B_ENABLED, VC7C_ENABLED, VC8A_ENABLED, VC8B_ENABLED, VC8C_ENABLED, VC9A_ENABLED, VC9B_ENABLED, VC9C_ENABLED, VC9D_ENABLED, PCC_ENABLED, ML5A_ENABLED, ML5B_ENABLED, ML5C_ENABLED, ML5D_ENABLED, ML5E_ENABLED, DEDUP_ATTR_ENABLED, ENC_0A_ENABLED, ENC_0B_ENABLED, ENC_0C_ENABLED, ENC_0D_ENABLED, ENC_0E_ENABLED, ENC_0F_ENABLED, ENC_0G_ENABLED, ENC_1A_ENABLED, BREAKER_WINDOW_MS, BREAKER_MIN_ATTEMPTS, BREAKER_PERF_FAILURES, BREAKER_PERF_FAILURE_RATE, BREAKER_CORRECTNESS_FAILURES, BREAKER_COOLDOWN_MS, BREAKER_PROBE_COUNT, BREAKER_RETRY_BASE_MS, BREAKER_RETRY_CAP_MS, BREAKER_RETRY_JITTER, BREAKER_HYSTERESIS_FAILURE_RATE, BREAKER_HYSTERESIS_BUDGET_P95_MS, BREAKER_MIN_HEALTHY_RESIDENCE_MS, } from "./config/vector-cortex.js";
|
|
117
|
+
export { VC0A_ENABLED, VC0B_ENABLED, VC1A_ENABLED, VC0C_ENABLED, VC1B_ENABLED, VC1C_ENABLED, VC2A_ENABLED, VC2B_ENABLED, VC2C_ENABLED, VC3A_ENABLED, VC3B_ENABLED, VC3C_ENABLED, VC4A_ENABLED, VC4B_ENABLED, VC4C_ENABLED, VC5A_ENABLED, VC5B_ENABLED, VC5C_ENABLED, VC6A_ENABLED, VC6B_ENABLED, VC6C_ENABLED, VC7A_ENABLED, VC7B_ENABLED, VC7C_ENABLED, VC8A_ENABLED, VC8B_ENABLED, VC8C_ENABLED, VC9A_ENABLED, VC9B_ENABLED, VC9C_ENABLED, VC9D_ENABLED, PCC_ENABLED, ML5A_ENABLED, ML5B_ENABLED, ML5C_ENABLED, ML5D_ENABLED, ML5E_ENABLED, DEDUP_ATTR_ENABLED, ENC_0A_ENABLED, ENC_0B_ENABLED, ENC_0C_ENABLED, ENC_0D_ENABLED, ENC_0E_ENABLED, ENC_0F_ENABLED, ENC_0G_ENABLED, ENC_1A_ENABLED, ENC_1B_ENABLED, BREAKER_WINDOW_MS, BREAKER_MIN_ATTEMPTS, BREAKER_PERF_FAILURES, BREAKER_PERF_FAILURE_RATE, BREAKER_CORRECTNESS_FAILURES, BREAKER_COOLDOWN_MS, BREAKER_PROBE_COUNT, BREAKER_RETRY_BASE_MS, BREAKER_RETRY_CAP_MS, BREAKER_RETRY_JITTER, BREAKER_HYSTERESIS_FAILURE_RATE, BREAKER_HYSTERESIS_BUDGET_P95_MS, BREAKER_MIN_HEALTHY_RESIDENCE_MS, } from "./config/vector-cortex.js";
|