pi-mega-compact 0.19.0 → 0.19.1

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.
Files changed (89) hide show
  1. package/dist/config/vector-cortex.js +10 -0
  2. package/dist/config.js +1 -1
  3. package/dist/extensions/dashboard-server/routes-rag-settings-helpers.js +1 -0
  4. package/dist/extensions/dashboard-server/routes-vector-cortex-eval.js +49 -0
  5. package/dist/extensions/dashboard-server/routes-vector-cortex-health.js +233 -0
  6. package/dist/extensions/dashboard-server/routes-vector-cortex-ledger.js +82 -0
  7. package/dist/extensions/dashboard-server/routes-vector-cortex-shared.js +46 -0
  8. package/dist/extensions/dashboard-server/routes-vector-cortex-topology.js +68 -0
  9. package/dist/extensions/dashboard-server/routes-vector-cortex.js +12 -373
  10. package/dist/extensions/dashboard-server/routes.js +1 -1
  11. package/dist/extensions/dashboard-server/server.js +3 -1
  12. package/dist/src/config/vector-cortex.js +10 -0
  13. package/dist/src/config.js +1 -1
  14. package/dist/src/vector-cortex/cortex/sqlite.js +393 -0
  15. package/dist/src/vector-cortex/cortex/store.js +139 -0
  16. package/dist/src/vector-cortex/cortex/types.js +44 -0
  17. package/dist/vector-cortex/cortex/sqlite.js +393 -0
  18. package/dist/vector-cortex/cortex/store.js +139 -0
  19. package/dist/vector-cortex/cortex/types.js +44 -0
  20. package/extensions/dashboard-client/dist/assets/{AreaChart-DywU5SSt.js → AreaChart-B9KYKrUE.js} +2 -2
  21. package/extensions/dashboard-client/dist/assets/{AreaChart-DywU5SSt.js.map → AreaChart-B9KYKrUE.js.map} +1 -1
  22. package/extensions/dashboard-client/dist/assets/{BarChart-But7WN6K.js → BarChart-D1sWkR6j.js} +2 -2
  23. package/extensions/dashboard-client/dist/assets/{BarChart-But7WN6K.js.map → BarChart-D1sWkR6j.js.map} +1 -1
  24. package/extensions/dashboard-client/dist/assets/{CacheTab-7aZWa1DR.js → CacheTab-BR8MYcJq.js} +2 -2
  25. package/extensions/dashboard-client/dist/assets/{CacheTab-7aZWa1DR.js.map → CacheTab-BR8MYcJq.js.map} +1 -1
  26. package/extensions/dashboard-client/dist/assets/{EventsTab-Bf_boNG2.js → EventsTab-BRNpDMvP.js} +2 -2
  27. package/extensions/dashboard-client/dist/assets/{EventsTab-Bf_boNG2.js.map → EventsTab-BRNpDMvP.js.map} +1 -1
  28. package/extensions/dashboard-client/dist/assets/{HealthTab-AbGc1nXP.js → HealthTab-rr5nXpjq.js} +2 -2
  29. package/extensions/dashboard-client/dist/assets/{HealthTab-AbGc1nXP.js.map → HealthTab-rr5nXpjq.js.map} +1 -1
  30. package/extensions/dashboard-client/dist/assets/{MaintenanceTab-BfHHhn5F.js → MaintenanceTab-CtjPWnzN.js} +2 -2
  31. package/extensions/dashboard-client/dist/assets/{MaintenanceTab-BfHHhn5F.js.map → MaintenanceTab-CtjPWnzN.js.map} +1 -1
  32. package/extensions/dashboard-client/dist/assets/{MemoryMapTab-DrcWti0-.js → MemoryMapTab-5SnFDIYc.js} +2 -2
  33. package/extensions/dashboard-client/dist/assets/{MemoryMapTab-DrcWti0-.js.map → MemoryMapTab-5SnFDIYc.js.map} +1 -1
  34. package/extensions/dashboard-client/dist/assets/{MetricsTab-ALiglXQq.js → MetricsTab-4MZfwRhq.js} +2 -2
  35. package/extensions/dashboard-client/dist/assets/{MetricsTab-ALiglXQq.js.map → MetricsTab-4MZfwRhq.js.map} +1 -1
  36. package/extensions/dashboard-client/dist/assets/{OverviewTab-nnaJdNyR.js → OverviewTab-BAKENnbk.js} +2 -2
  37. package/extensions/dashboard-client/dist/assets/{OverviewTab-nnaJdNyR.js.map → OverviewTab-BAKENnbk.js.map} +1 -1
  38. package/extensions/dashboard-client/dist/assets/{ReposTab-BTK0nofM.js → ReposTab-7-z_OmZo.js} +2 -2
  39. package/extensions/dashboard-client/dist/assets/{ReposTab-BTK0nofM.js.map → ReposTab-7-z_OmZo.js.map} +1 -1
  40. package/extensions/dashboard-client/dist/assets/{SessionsTab-RXPNqO6x.js → SessionsTab-D_r2ki0y.js} +2 -2
  41. package/extensions/dashboard-client/dist/assets/{SessionsTab-RXPNqO6x.js.map → SessionsTab-D_r2ki0y.js.map} +1 -1
  42. package/extensions/dashboard-client/dist/assets/{SetupTab-Dab0AVfs.js → SetupTab-DPujtYgv.js} +2 -2
  43. package/extensions/dashboard-client/dist/assets/{SetupTab-Dab0AVfs.js.map → SetupTab-DPujtYgv.js.map} +1 -1
  44. package/extensions/dashboard-client/dist/assets/{TimeSavedCard-DIVG8hdt.js → TimeSavedCard-CLHy30t6.js} +2 -2
  45. package/extensions/dashboard-client/dist/assets/{TimeSavedCard-DIVG8hdt.js.map → TimeSavedCard-CLHy30t6.js.map} +1 -1
  46. package/extensions/dashboard-client/dist/assets/{TurnsTab-9uz2fBwx.js → TurnsTab-Coul6CHc.js} +2 -2
  47. package/extensions/dashboard-client/dist/assets/{TurnsTab-9uz2fBwx.js.map → TurnsTab-Coul6CHc.js.map} +1 -1
  48. package/extensions/dashboard-client/dist/assets/VectorCortexTab-rqBpWc7A.js +2 -0
  49. package/extensions/dashboard-client/dist/assets/VectorCortexTab-rqBpWc7A.js.map +1 -0
  50. package/extensions/dashboard-client/dist/assets/{WikiTab-CpcgaggS.js → WikiTab-hryG5oyY.js} +2 -2
  51. package/extensions/dashboard-client/dist/assets/{WikiTab-CpcgaggS.js.map → WikiTab-hryG5oyY.js.map} +1 -1
  52. package/extensions/dashboard-client/dist/assets/{button-B0Q2fuKY.js → button-Dxo95lRI.js} +2 -2
  53. package/extensions/dashboard-client/dist/assets/{button-B0Q2fuKY.js.map → button-Dxo95lRI.js.map} +1 -1
  54. package/extensions/dashboard-client/dist/assets/{card-Cnik3TFr.js → card-FXwhLF_u.js} +2 -2
  55. package/extensions/dashboard-client/dist/assets/{card-Cnik3TFr.js.map → card-FXwhLF_u.js.map} +1 -1
  56. package/extensions/dashboard-client/dist/assets/{generateCategoricalChart-DrSwgn1V.js → generateCategoricalChart-M-GeRM8U.js} +2 -2
  57. package/extensions/dashboard-client/dist/assets/{generateCategoricalChart-DrSwgn1V.js.map → generateCategoricalChart-M-GeRM8U.js.map} +1 -1
  58. package/extensions/dashboard-client/dist/assets/{index-DraytcOY.js → index-BIZZXvoy.js} +3 -3
  59. package/extensions/dashboard-client/dist/assets/{index-DraytcOY.js.map → index-BIZZXvoy.js.map} +1 -1
  60. package/extensions/dashboard-client/dist/assets/index-CYpzq9Lm.css +1 -0
  61. package/extensions/dashboard-client/dist/assets/{switch-DVQ1aB9b.js → switch-C-d4tkN1.js} +2 -2
  62. package/extensions/dashboard-client/dist/assets/{switch-DVQ1aB9b.js.map → switch-C-d4tkN1.js.map} +1 -1
  63. package/extensions/dashboard-client/dist/assets/{toggle-Dkppx-49.js → toggle-Bfmucdcl.js} +2 -2
  64. package/extensions/dashboard-client/dist/assets/{toggle-Dkppx-49.js.map → toggle-Bfmucdcl.js.map} +1 -1
  65. package/extensions/dashboard-client/dist/assets/{useSSE-CPkjU4Gx.js → useSSE-CxK_wdmk.js} +2 -2
  66. package/extensions/dashboard-client/dist/assets/{useSSE-CPkjU4Gx.js.map → useSSE-CxK_wdmk.js.map} +1 -1
  67. package/extensions/dashboard-client/dist/index.html +2 -2
  68. package/extensions/dashboard-client/src/api/vector-cortex.ts +9 -0
  69. package/extensions/dashboard-client/src/tabs/VectorCortexTab.tsx +34 -0
  70. package/extensions/dashboard-client/src/types/vector-cortex.ts +15 -0
  71. package/extensions/dashboard-server/api-contracts/vector-cortex.ts +23 -0
  72. package/extensions/dashboard-server/routes-rag-settings-helpers.ts +6 -0
  73. package/extensions/dashboard-server/routes-vector-cortex-eval.ts +59 -0
  74. package/extensions/dashboard-server/routes-vector-cortex-health.ts +273 -0
  75. package/extensions/dashboard-server/routes-vector-cortex-ledger.ts +92 -0
  76. package/extensions/dashboard-server/routes-vector-cortex-shared.ts +53 -0
  77. package/extensions/dashboard-server/routes-vector-cortex-topology.ts +83 -0
  78. package/extensions/dashboard-server/routes-vector-cortex.ts +12 -431
  79. package/extensions/dashboard-server/routes.ts +1 -0
  80. package/extensions/dashboard-server/server.ts +2 -0
  81. package/package.json +1 -1
  82. package/src/config/vector-cortex.ts +11 -0
  83. package/src/config.ts +1 -0
  84. package/src/vector-cortex/cortex/sqlite.ts +489 -0
  85. package/src/vector-cortex/cortex/store.ts +202 -0
  86. package/src/vector-cortex/cortex/types.ts +194 -0
  87. package/extensions/dashboard-client/dist/assets/VectorCortexTab-DnKY61EJ.js +0 -2
  88. package/extensions/dashboard-client/dist/assets/VectorCortexTab-DnKY61EJ.js.map +0 -1
  89. package/extensions/dashboard-client/dist/assets/index-CfvziyBi.css +0 -1
@@ -0,0 +1,393 @@
1
+ /**
2
+ * vector-cortex/cortex/sqlite.ts — cortex derived-record SQLite store, Mode A
3
+ * (VC3A).
4
+ *
5
+ * A self-contained, isolated SQLite store (`node:sqlite` `DatabaseSync`) over its
6
+ * OWN database file — NOT the host `sqlite.db` — so the derived cortex store is a
7
+ * separate additive artifact. Holds the immutable derived `cortex_record_v1`
8
+ * rows keyed by `(source_high_water, algorithm_version, id)` (CTX-KEY-002: the
9
+ * same id at a different algorithm version stays DISTINCT) and the
10
+ * `cortex_generation_v1` generation rows (the digest-pinned derived front).
11
+ *
12
+ * Append enforces composite-key immutability: an exact
13
+ * `(source_high_water, algorithm_version, id)` re-append with the SAME
14
+ * `payload_digest` is acknowledged idempotently; the same key with a DIFFERENT
15
+ * digest is a `CTX_KEY_CONFLICT` (immutable derived records never mutate).
16
+ *
17
+ * Rebuild is deterministic: it sorts records by
18
+ * `(source_high_water, algorithm_version, id)`, verifies every `payload_digest`,
19
+ * computes ONE `root_digest` over the canonical sorted key list (order
20
+ * independent, CTX-REBUILD-003), and writes + activates a new generation.
21
+ *
22
+ * PREVENT-002: every query is parameterized. PREVENT-011: no `any`.
23
+ * PREVENT-PI-004: local filesystem only, no network. No console.log.
24
+ */
25
+ import { DatabaseSync } from "node:sqlite";
26
+ import { existsSync, mkdirSync } from "node:fs";
27
+ import { dirname } from "node:path";
28
+ import { createHash } from "node:crypto";
29
+ const SCHEMA = `
30
+ CREATE TABLE IF NOT EXISTS cortex_record_v1 (
31
+ source_high_water INTEGER NOT NULL,
32
+ algorithm_version INTEGER NOT NULL,
33
+ id TEXT NOT NULL,
34
+ kind TEXT NOT NULL,
35
+ payload_digest TEXT NOT NULL,
36
+ payload_bytes BLOB NOT NULL,
37
+ PRIMARY KEY (source_high_water, algorithm_version, id)
38
+ ) STRICT;
39
+
40
+ CREATE TABLE IF NOT EXISTS cortex_generation_v1 (
41
+ id TEXT PRIMARY KEY,
42
+ ordinal INTEGER NOT NULL,
43
+ source_high_water INTEGER NOT NULL,
44
+ record_count INTEGER NOT NULL,
45
+ root_digest TEXT NOT NULL,
46
+ active INTEGER NOT NULL DEFAULT 0
47
+ ) STRICT;
48
+ `;
49
+ /** Default digest for a record when the caller omits one (sha256 over bytes). */
50
+ export function cortexDigest(bytes) {
51
+ return `sha256:${createHash("sha256").update(bytes).digest("hex")}`;
52
+ }
53
+ /**
54
+ * Toggle real storage writability on a cortex store connection. `readOnly=true`
55
+ * sets `PRAGMA query_only`, making SQLite itself refuse every INSERT/UPDATE —
56
+ * the genuine storage-failure (SQLITE_FULL-class) path used by the failure
57
+ * injection tests. Reads (SELECT) remain available, so a read-only store still
58
+ * serves the reader and rebuild recovery.
59
+ */
60
+ export function setStoreReadOnly(db, readOnly) {
61
+ db.exec(readOnly ? "PRAGMA query_only = ON" : "PRAGMA query_only = OFF");
62
+ }
63
+ /** Open (or reuse) the isolated cortex derived-store DB handle. */
64
+ export function openCortexStore(dbPath) {
65
+ const dir = dirname(dbPath);
66
+ if (!existsSync(dir))
67
+ mkdirSync(dir, { recursive: true });
68
+ // readBigInts: return INTEGER columns exceeding Number.MAX_SAFE_INTEGER as BigInt
69
+ // so a caller's `bigint` sourceHighWater/ordinal round-trips exactly (Q06 —
70
+ // never truncate through a `Number()` double).
71
+ const db = new DatabaseSync(dbPath, { readBigInts: true });
72
+ db.exec("PRAGMA journal_mode = WAL");
73
+ db.exec("PRAGMA foreign_keys = ON");
74
+ db.exec(SCHEMA);
75
+ return db;
76
+ }
77
+ function rowToRecord(row) {
78
+ return {
79
+ schema: "cortex-record-v1",
80
+ sourceHighWater: BigInt(row.source_high_water),
81
+ algorithmVersion: Number(row.algorithm_version),
82
+ id: row.id,
83
+ kind: row.kind,
84
+ payloadDigest: row.payload_digest,
85
+ payloadBytes: row.payload_bytes ? Buffer.from(row.payload_bytes) : new Uint8Array(0),
86
+ };
87
+ }
88
+ /** Count accepted derived records. */
89
+ export function countCortexRecords(db) {
90
+ const row = db.prepare(`SELECT COUNT(*) AS cnt FROM cortex_record_v1`).get();
91
+ return typeof row.cnt === "bigint" ? Number(row.cnt) : row.cnt;
92
+ }
93
+ /** Accepted records in ascending (sourceHighWater, algorithmVersion, id). */
94
+ export function readCortexRecords(db) {
95
+ const rows = db
96
+ .prepare(`SELECT source_high_water, algorithm_version, id, kind, payload_digest, payload_bytes
97
+ FROM cortex_record_v1
98
+ ORDER BY source_high_water ASC, algorithm_version ASC, id ASC`)
99
+ .all();
100
+ return rows.map(rowToRecord);
101
+ }
102
+ /** The single record at a composite key, or undefined. */
103
+ export function readCortexRecord(db, sourceHighWater, algorithmVersion, id) {
104
+ const row = db
105
+ .prepare(`SELECT source_high_water, algorithm_version, id, kind, payload_digest, payload_bytes
106
+ FROM cortex_record_v1
107
+ WHERE source_high_water = @hw AND algorithm_version = @av AND id = @id LIMIT 1`)
108
+ .get({
109
+ "@hw": sourceHighWater,
110
+ "@av": algorithmVersion,
111
+ "@id": id,
112
+ });
113
+ return row ? rowToRecord(row) : undefined;
114
+ }
115
+ /** Whether an exact composite-key record already exists. */
116
+ function findRecordByKey(db, sourceHighWater, algorithmVersion, id) {
117
+ return readCortexRecord(db, sourceHighWater, algorithmVersion, id);
118
+ }
119
+ /**
120
+ * Classify an existing-key hit: an exact `(key, digest)` match is an idempotent
121
+ * ack of the immutable record; the same key with a DIFFERENT digest is a
122
+ * `CTX_KEY_CONFLICT` (immutable derived records never mutate).
123
+ */
124
+ function idempotentOrConflict(existing, candidate, payloadDigest) {
125
+ if (existing.payloadDigest === payloadDigest) {
126
+ // Idempotent ack of an identical immutable record.
127
+ return { ok: true, record: existing };
128
+ }
129
+ return { ok: false, code: "CTX_KEY_CONFLICT", rejected: candidate };
130
+ }
131
+ /**
132
+ * Append one derived record. Exact `(sourceHighWater, algorithmVersion, id)`
133
+ * with the SAME payloadDigest is acknowledged idempotently (returning the
134
+ * existing immutable row); the same key with a DIFFERENT digest is a conflict.
135
+ * A storage error is surfaced as `CTX_APPEND_FAILED` so the caller's writer can
136
+ * treat it non-fatally. A concurrent unique-constraint race is classified as an
137
+ * idempotent ack / key-conflict (re-checked against the committed row), never
138
+ * misreported as a storage failure.
139
+ */
140
+ export function insertCortexRecord(db, input) {
141
+ const payloadDigest = input.payloadDigest ?? cortexDigest(input.payloadBytes);
142
+ const record = {
143
+ schema: "cortex-record-v1",
144
+ sourceHighWater: input.sourceHighWater,
145
+ algorithmVersion: input.algorithmVersion,
146
+ id: input.id,
147
+ kind: input.kind,
148
+ payloadDigest,
149
+ payloadBytes: input.payloadBytes,
150
+ };
151
+ const existing = findRecordByKey(db, input.sourceHighWater, input.algorithmVersion, input.id);
152
+ if (existing) {
153
+ return idempotentOrConflict(existing, record, payloadDigest);
154
+ }
155
+ try {
156
+ db.prepare(`INSERT INTO cortex_record_v1
157
+ (source_high_water, algorithm_version, id, kind, payload_digest, payload_bytes)
158
+ VALUES (@hw, @av, @id, @kind, @digest, @bytes)`).run({
159
+ "@hw": input.sourceHighWater,
160
+ "@av": input.algorithmVersion,
161
+ "@id": input.id,
162
+ "@kind": input.kind,
163
+ "@digest": payloadDigest,
164
+ "@bytes": Buffer.from(input.payloadBytes),
165
+ });
166
+ }
167
+ catch {
168
+ // A UNIQUE/PK constraint race (two writers pass the SELECT above, the loser
169
+ // hits the composite PK) is semantically an idempotent ack or a key conflict
170
+ // — NOT a storage failure — so re-check the now-committed row and classify it
171
+ // correctly instead of misreporting CTX_APPEND_FAILED. Any other error is a
172
+ // genuine non-fatal storage failure (e.g. SQLITE_FULL) and surfaces as-is.
173
+ const recheck = readCortexRecord(db, input.sourceHighWater, input.algorithmVersion, input.id);
174
+ if (recheck) {
175
+ return idempotentOrConflict(recheck, record, payloadDigest);
176
+ }
177
+ return { ok: false, code: "CTX_APPEND_FAILED", rejected: record };
178
+ }
179
+ return { ok: true, record };
180
+ }
181
+ /**
182
+ * ONE deterministic root digest over the canonical sorted key list. Records are
183
+ * sorted by `(sourceHighWater, algorithmVersion, id)`; each key contributes
184
+ * `sourceHighWater|algorithmVersion|id|kind|payloadDigest`. Order-independent
185
+ * (CTX-REBUILD-003): shuffled insertion yields an identical root digest.
186
+ */
187
+ export function generationRootDigest(records) {
188
+ const sorted = [...records].sort(cmpRecordKey);
189
+ const h = createHash("sha256");
190
+ for (const r of sorted) {
191
+ h.update(`${r.sourceHighWater.toString()}|${r.algorithmVersion}|${r.id}|${r.kind}|${r.payloadDigest}\n`);
192
+ }
193
+ return h.digest("hex");
194
+ }
195
+ /** Stable record ordering by the composite key. */
196
+ export function cmpRecordKey(a, b) {
197
+ if (a.sourceHighWater < b.sourceHighWater)
198
+ return -1;
199
+ if (a.sourceHighWater > b.sourceHighWater)
200
+ return 1;
201
+ if (a.algorithmVersion < b.algorithmVersion)
202
+ return -1;
203
+ if (a.algorithmVersion > b.algorithmVersion)
204
+ return 1;
205
+ return a.id < b.id ? -1 : a.id > b.id ? 1 : 0;
206
+ }
207
+ /** The active generation, or undefined. */
208
+ export function activeGeneration(db) {
209
+ const row = db
210
+ .prepare(`SELECT id, ordinal, source_high_water, record_count, root_digest, active
211
+ FROM cortex_generation_v1 WHERE active = 1 LIMIT 1`)
212
+ .get();
213
+ return row ? rowToGeneration(row) : undefined;
214
+ }
215
+ /** All generations in ascending ordinal order (evidence retained). */
216
+ export function listCortexGenerations(db) {
217
+ const rows = db
218
+ .prepare(`SELECT id, ordinal, source_high_water, record_count, root_digest, active
219
+ FROM cortex_generation_v1 ORDER BY ordinal ASC`)
220
+ .all();
221
+ return rows.map(rowToGeneration);
222
+ }
223
+ /** A generation by id, or undefined. */
224
+ function generationById(db, generationId) {
225
+ const row = db
226
+ .prepare(`SELECT id, ordinal, source_high_water, record_count, root_digest, active
227
+ FROM cortex_generation_v1 WHERE id = @id LIMIT 1`)
228
+ .get({ "@id": generationId });
229
+ return row ? rowToGeneration(row) : undefined;
230
+ }
231
+ /**
232
+ * The existing generation carrying the SAME rootDigest and recordCount, or
233
+ * undefined. Deterministic rebuild of unchanged inputs must REUSE the identical
234
+ * generation already recorded durably rather than append a fresh duplicate
235
+ * (idempotency) — this scan is what makes that reuse reachable, since the
236
+ * ordinal-derived id is always new in the no-opts flow.
237
+ */
238
+ function generationByRootDigest(db, rootDigest, recordCount) {
239
+ const row = db
240
+ .prepare(`SELECT id, ordinal, source_high_water, record_count, root_digest, active
241
+ FROM cortex_generation_v1
242
+ WHERE root_digest = @digest AND record_count = @count LIMIT 1`)
243
+ .get({ "@digest": rootDigest, "@count": recordCount });
244
+ return row ? rowToGeneration(row) : undefined;
245
+ }
246
+ function rowToGeneration(row) {
247
+ return {
248
+ schema: "cortex-generation-v1",
249
+ id: row.id,
250
+ sourceHighWater: BigInt(row.source_high_water),
251
+ recordCount: typeof row.record_count === "bigint" ? Number(row.record_count) : row.record_count,
252
+ rootDigest: row.root_digest,
253
+ ordinal: BigInt(row.ordinal),
254
+ };
255
+ }
256
+ /**
257
+ * Deterministically rebuild a generation from ALL accepted records. Sorts keys,
258
+ * verifies each payload digest (CTX_PAYLOAD_DIGEST_MISMATCH on corruption),
259
+ * computes ONE root digest, and writes + activates a new generation with an
260
+ * incrementing ordinal. Does NOT delete prior generations (evidence retained).
261
+ *
262
+ * Idempotency (DTST-CORE invariant): a rebuild of UNCHANGED accepted inputs
263
+ * (same sorted set → same rootDigest + recordCount) REUSES the identical
264
+ * generation already recorded durably — it activates and returns that existing
265
+ * generation instead of appending a fresh duplicate row, so repeated rebuilds
266
+ * with no record changes yield one generation, not gen-1, gen-2, ... carrying
267
+ * the same digest.
268
+ *
269
+ * When `opts.authorityHighWater` is supplied, the derived frontier (max record
270
+ * sourceHighWater) must not exceed the contiguous durable authority high-water
271
+ * (normative in CONTRACTS.md); an over-run is rejected with
272
+ * `CTX_HIGH_WATER_EXCEEDED` and NO generation is written.
273
+ *
274
+ * A rebuild only reports `ok:true` when the generation INSERT + activate actually
275
+ * persisted. If the write degrades (any storage failure, e.g. SQLITE_FULL via
276
+ * `PRAGMA query_only`), it returns `ok:false, code:"CTX_REBUILD_FAILED"` — never
277
+ * a fabricated generation that has no durable row. That non-ok result is what
278
+ * prevents the caller from emitting a misleading `vector_cortex_generation_rebuilt`
279
+ * event or exposing a generation id that does not exist.
280
+ *
281
+ * The reuse path (a prior generation already carries the same rootDigest +
282
+ * recordCount) also runs its activation through the SAME error-to-CTX_REBUILD_FAILED
283
+ * conversion: under read-only storage (`PRAGMA query_only`) the activation UPDATE
284
+ * is refused by SQLite, and the rebuild must surface `CTX_REBUILD_FAILED` rather
285
+ * than let a raw SQLITE_READONLY escape to `store.admin().rebuild()` and break
286
+ * the agent loop. Reads remain available, so the durable generation is intact.
287
+ */
288
+ export function rebuildCortexGeneration(db, opts = {}) {
289
+ const records = readCortexRecords(db);
290
+ const sorted = [...records].sort(cmpRecordKey);
291
+ // Verify every record digest against its immutable payload bytes.
292
+ for (const r of sorted) {
293
+ if (r.payloadDigest !== cortexDigest(r.payloadBytes)) {
294
+ return { ok: false, code: "CTX_PAYLOAD_DIGEST_MISMATCH" };
295
+ }
296
+ }
297
+ const rootDigest = generationRootDigest(sorted);
298
+ const sourceHighWater = sorted.length > 0 ? sorted[sorted.length - 1].sourceHighWater : 0n;
299
+ // Normative derived-frontier invariant (CONTRACTS.md): the derived frontier can
300
+ // never exceed the contiguous durable authority high-water. Reject the rebuild
301
+ // (write nothing) when a bound is supplied and the derived records outrun it.
302
+ if (opts.authorityHighWater !== undefined && sourceHighWater > opts.authorityHighWater) {
303
+ return { ok: false, code: "CTX_HIGH_WATER_EXCEEDED" };
304
+ }
305
+ const sortedCount = sorted.length;
306
+ // Deterministic rebuild of unchanged inputs must REUSE the identical generation
307
+ // already recorded durably (idempotent, no duplicate generation bloat). If a
308
+ // prior generation carries the same rootDigest + recordCount, activate it and
309
+ // return it instead of appending a fresh duplicate row.
310
+ const reused = generationByRootDigest(db, rootDigest, sortedCount);
311
+ if (reused) {
312
+ // The generation row ALREADY exists durably (reads still work under
313
+ // `PRAGMA query_only`), but activating it is a write. Guard it the same way
314
+ // as the insert path so a storage failure (e.g. SQLITE_READONLY) degrades to
315
+ // CTX_REBUILD_FAILED instead of escaping uncaught into admin.rebuild().
316
+ try {
317
+ activateGeneration(db, reused.id);
318
+ }
319
+ catch {
320
+ return { ok: false, code: "CTX_REBUILD_FAILED" };
321
+ }
322
+ return { ok: true, generation: reused };
323
+ }
324
+ const existing = listCortexGenerations(db);
325
+ const base = opts.generationOrdinal ?? (existing.length ? existing[existing.length - 1].ordinal + 1n : 1n);
326
+ const ordinal = base > 0n ? base : 1n;
327
+ const generationId = `gen-${ordinal.toString()}`;
328
+ db.exec("SAVEPOINT mc_cortex_gen");
329
+ try {
330
+ db.prepare(`INSERT INTO cortex_generation_v1
331
+ (id, ordinal, source_high_water, record_count, root_digest, active)
332
+ VALUES (@id, @ordinal, @hw, @count, @digest, 0)`).run({
333
+ "@id": generationId,
334
+ "@ordinal": ordinal,
335
+ "@hw": sourceHighWater,
336
+ "@count": sortedCount,
337
+ "@digest": rootDigest,
338
+ });
339
+ activateGeneration(db, generationId);
340
+ db.exec("RELEASE mc_cortex_gen");
341
+ }
342
+ catch {
343
+ try {
344
+ db.exec("ROLLBACK TO mc_cortex_gen");
345
+ }
346
+ catch {
347
+ /* savepoint may already be gone on a failed exec */
348
+ }
349
+ try {
350
+ db.exec("RELEASE mc_cortex_gen");
351
+ }
352
+ catch {
353
+ /* savepoint may already be gone */
354
+ }
355
+ // The generation INSERT/activate did not persist. Report the non-fatal
356
+ // storage failure — never a fabricated generation that has no durable row.
357
+ return { ok: false, code: "CTX_REBUILD_FAILED" };
358
+ }
359
+ const gen = generationById(db, generationId);
360
+ if (!gen) {
361
+ // Defensive: no durable row is visible, so this rebuild did not persist.
362
+ return { ok: false, code: "CTX_REBUILD_FAILED" };
363
+ }
364
+ return { ok: true, generation: gen };
365
+ }
366
+ /** Switch the active generation pointer (evidence retained; nothing deleted). */
367
+ export function switchCortexGeneration(db, generationId) {
368
+ if (!generationById(db, generationId))
369
+ return { ok: false, code: "CTX_GENERATION_NOT_FOUND" };
370
+ // Activating writes to cortex_generation_v1.active; under read-only storage
371
+ // (`PRAGMA query_only`) SQLite refuses the UPDATE. Convert that storage failure
372
+ // into the documented `{ok:false}` result so a caller of the typed admin surface
373
+ // never receives an uncaught SQLITE_READONLY exception (Q02 — every store
374
+ // mutation is non-fatal).
375
+ try {
376
+ activateGeneration(db, generationId);
377
+ }
378
+ catch {
379
+ return { ok: false, code: "CTX_SWITCH_FAILED" };
380
+ }
381
+ return { ok: true };
382
+ }
383
+ function activateGeneration(db, generationId) {
384
+ db.prepare(`UPDATE cortex_generation_v1 SET active = 0 WHERE active = 1`).run();
385
+ db.prepare(`UPDATE cortex_generation_v1 SET active = 1 WHERE id = @id`).run({ "@id": generationId });
386
+ }
387
+ /** Highest sourceHighWater across all accepted records (the derived frontier). */
388
+ export function maxSourceHighWater(db) {
389
+ const row = db
390
+ .prepare(`SELECT MAX(source_high_water) AS m FROM cortex_record_v1`)
391
+ .get();
392
+ return row.m === null ? 0n : BigInt(row.m);
393
+ }
@@ -0,0 +1,139 @@
1
+ /**
2
+ * vector-cortex/cortex/store.ts — VC3A capability-separated cortex store contracts.
3
+ *
4
+ * Owns the `createCortexStore` factory producing `CortexReader` / `CortexWriter`
5
+ * / `CortexAdmin` capability views over the isolated cortex SQLite store. The
6
+ * writer exposes append only, the reader exposes query only, and the admin alone
7
+ * can rebuild/switch generations (task 2). No callbacks or event emitters flow
8
+ * from the store; writes are non-fatal (a failure logs and never breaks the agent
9
+ * loop).
10
+ *
11
+ * The two VC3A events (task 5) are emitted by this store:
12
+ *
13
+ * vector_cortex_record_append_failed — an append was rejected / failed
14
+ * vector_cortex_generation_rebuilt — the admin rebuilt + activated a generation
15
+ *
16
+ * Both are gated on `MEGACOMPACT_VC3A` so the flag-OFF path emits zero events
17
+ * (mode C parity, byte-identical predecessor).
18
+ *
19
+ * Capability gating mirrors the host `asReader/asWriter/asAdmin` and VC1B ledger
20
+ * pattern. Each consumer receives ONLY what it needs. The dashboard reader-only
21
+ * GET is built on the reader surface alone.
22
+ *
23
+ * Pi-agnostic. No console.log. No network (PREVENT-PI-004). No `any`
24
+ * (PREVENT-011).
25
+ */
26
+ import { VC3A_ENABLED } from "../../config/vector-cortex.js";
27
+ import { Logger } from "../../log.js";
28
+ import { openCortexStore, insertCortexRecord, readCortexRecord, countCortexRecords, readCortexRecords, rebuildCortexGeneration, switchCortexGeneration, activeGeneration, listCortexGenerations, maxSourceHighWater, } from "./sqlite.js";
29
+ /** The token that gates closures to a single capability (PREVENT-011-free). */
30
+ const _capability = Symbol("mc-cortex-capability");
31
+ /**
32
+ * Create the capability-separated cortex derived store over its OWN isolated
33
+ * SQLite DB. `emit` is optional; the two VC3A events are only emitted when
34
+ * `VC3A_ENABLED()` and an emitter is supplied (mode-C parity: flag OFF / no
35
+ * emitter => zero observability writes).
36
+ *
37
+ * Normalization: `stateDir` gives the standard daemon location
38
+ * `<stateDir>/vector-cortex/cortex.db`; a bare `dbPath` overrides it
39
+ * (tests/rehearsal isolate the cortex store). An injected `db` (an already-open
40
+ * `DatabaseSync`) is a dependency-injection seam used by the failure-injection
41
+ * tests to drive the REAL storage-refusal path (e.g. `PRAGMA query_only`) through
42
+ * the store's own writer — a genuine store, no mock.
43
+ */
44
+ export function createCortexStore(opts, emit) {
45
+ const db = "db" in opts
46
+ ? opts.db
47
+ : openCortexStore("dbPath" in opts
48
+ ? opts.dbPath
49
+ : `${opts.stateDir}/vector-cortex/cortex.db`);
50
+ // A caller that invokes the writer/admin seam without injecting an emitter gets
51
+ // a REAL default producer (structured logger) so telemetry is never silently
52
+ // dropped — an explicit `emit:` replaces it. The dashboard reader-only route
53
+ // never appends/rebuilds, so it fires nothing regardless; a future writer/admin
54
+ // host integration enjoys default observability out of the box (VC3B wiring).
55
+ const sink = emit ?? defaultEmitFor();
56
+ const fire = (event, fields) => {
57
+ if (!VC3A_ENABLED())
58
+ return;
59
+ try {
60
+ sink(event, fields);
61
+ }
62
+ catch {
63
+ /* non-fatal observability — never break the agent loop */
64
+ }
65
+ };
66
+ const asReader = () => ({
67
+ kind: "CortexReader",
68
+ [_capability]: "reader",
69
+ recordCount: () => countCortexRecords(db),
70
+ readRecords: () => readCortexRecords(db),
71
+ readRecord: (sourceHighWater, algorithmVersion, id) => readCortexRecord(db, sourceHighWater, algorithmVersion, id),
72
+ latestGeneration: () => activeGeneration(db),
73
+ topologySummary: () => topologyOf(db, VC3A_ENABLED()),
74
+ });
75
+ const asWriter = () => ({
76
+ kind: "CortexWriter",
77
+ [_capability]: "writer",
78
+ append(input) {
79
+ const result = insertCortexRecord(db, input);
80
+ // Any rejected/failed append (CTX_KEY_CONFLICT, CTX_APPEND_FAILED, or any
81
+ // future code) surfaces the SAME event; the `code` field distinguishes a
82
+ // key-conflict (rejected append) from a storage failure (CTX_APPEND_FAILED).
83
+ if (!result.ok) {
84
+ fire("vector_cortex_record_append_failed", {
85
+ sourceHighWater: input.sourceHighWater.toString(),
86
+ algorithmVersion: input.algorithmVersion,
87
+ id: input.id,
88
+ kind: input.kind,
89
+ code: result.code,
90
+ });
91
+ }
92
+ return result;
93
+ },
94
+ });
95
+ const asAdmin = () => ({
96
+ kind: "CortexAdmin",
97
+ [_capability]: "admin",
98
+ rebuild(authorityHighWater) {
99
+ const result = rebuildCortexGeneration(db, { authorityHighWater });
100
+ if (result.ok) {
101
+ fire("vector_cortex_generation_rebuilt", {
102
+ generationId: result.generation.id,
103
+ ordinal: result.generation.ordinal.toString(),
104
+ sourceHighWater: result.generation.sourceHighWater.toString(),
105
+ recordCount: result.generation.recordCount,
106
+ rootDigest: result.generation.rootDigest,
107
+ });
108
+ }
109
+ return result;
110
+ },
111
+ switchGeneration: (generationId) => switchCortexGeneration(db, generationId),
112
+ listGenerations: () => listCortexGenerations(db),
113
+ });
114
+ return { reader: asReader, writer: asWriter, admin: asAdmin, close: () => db.close() };
115
+ }
116
+ /** Build the reader-only topology summary (the dashboard GET payload). */
117
+ function topologyOf(db, enabled) {
118
+ const gen = activeGeneration(db);
119
+ return {
120
+ enabled,
121
+ generationId: gen ? gen.id : null,
122
+ rootDigest: gen ? gen.rootDigest : null,
123
+ sourceHighWater: (gen ? gen.sourceHighWater : maxSourceHighWater(db)).toString(),
124
+ recordCount: countCortexRecords(db),
125
+ ordinal: gen ? gen.ordinal.toString() : null,
126
+ };
127
+ }
128
+ /**
129
+ * A deterministic default emitter backed by the structured logger. Supplying an
130
+ * explicit `emit:` replaces it. Making the default a REAL producer means a caller
131
+ * that just invokes the writer/admin seam without injecting an emitter still
132
+ * yields structured telemetry instead of silently dropping every event.
133
+ */
134
+ function defaultEmitFor() {
135
+ const logger = new Logger();
136
+ return (event, fields) => {
137
+ logger.info(event, fields);
138
+ };
139
+ }
@@ -0,0 +1,44 @@
1
+ /**
2
+ * vector-cortex/cortex/types.ts — capability-gated cortex store contract (VC3A).
3
+ *
4
+ * Owns `CortexReader` / `CortexWriter` / `CortexAdmin` and `CortexRecordV1`
5
+ * (the immutable derived record). Consumes only reviewer-accepted predecessor
6
+ * contracts and [common contracts](../../CONTRACTS.md §Store and migration
7
+ * contracts), which are NORMATIVE here: the derived frontier cannot exceed the
8
+ * contiguous durable authority high-water and cannot advance during
9
+ * authority/spool outage.
10
+ *
11
+ * A CortexRecordV1 is a DERIVED record keyed by
12
+ * `(sourceHighWater, algorithmVersion, id)`. The same `id` at a different
13
+ * `algorithmVersion` (or a different `sourceHighWater`) is a DISTINCT record —
14
+ * never collapsed (CTX-KEY-002). Records are immutable: re-appending an exact
15
+ * `(sourceHighWater, algorithmVersion, id)` with the SAME `payloadDigest` is an
16
+ * idempotent acknowledge; the same key with a DIFFERENT digest is a conflict.
17
+ *
18
+ * Capability gating mirrors the host `asReader/asWriter/asAdmin` pattern and the
19
+ * VC1B ledger: the writer exposes append only, the reader exposes query only,
20
+ * and the admin alone can rebuild / switch generations. No callbacks or event
21
+ * emitters flow from the store; writes are non-fatal (failures log and never
22
+ * break the agent loop).
23
+ *
24
+ * Pure type/schema definitions + small pure predicates. No storage, no console,
25
+ * no network, no side effects (PREVENT-PI-004 / PREVENT-011).
26
+ */
27
+ /**
28
+ * Registered CTX conformance ID range (CTX-001..010). The acceptance test reads
29
+ * these rows from the v2 manifest and asserts each returns its manifest bytes or
30
+ * exactly its listed failure code. The three NAMED assertions
31
+ * (CTX-CAP-001 / CTX-KEY-002 / CTX-REBUILD-003) live in the acceptance test.
32
+ */
33
+ export const CTX_IDS = [
34
+ "CTX-001",
35
+ "CTX-002",
36
+ "CTX-003",
37
+ "CTX-004",
38
+ "CTX-005",
39
+ "CTX-006",
40
+ "CTX-007",
41
+ "CTX-008",
42
+ "CTX-009",
43
+ "CTX-010",
44
+ ];
@@ -1,2 +1,2 @@
1
- import{b as R,c as W,m as T,i as C,d as F,A as ie,e as B,h as q,j as oe,k as G,l as se,n as le,u as ue,o as K,G as ce,p as J,q as Q,D as fe,g as pe,X as he,Y as de,f as me}from"./generateCategoricalChart-DrSwgn1V.js";import{R as p,F as ee,r as ve}from"./index-DraytcOY.js";var ye=["layout","type","stroke","connectNulls","isRange","ref"],be=["key"],te;function M(e){"@babel/helpers - typeof";return M=typeof Symbol=="function"&&typeof Symbol.iterator=="symbol"?function(t){return typeof t}:function(t){return t&&typeof Symbol=="function"&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t},M(e)}function ae(e,t){if(e==null)return{};var r=Ae(e,t),a,n;if(Object.getOwnPropertySymbols){var i=Object.getOwnPropertySymbols(e);for(n=0;n<i.length;n++)a=i[n],!(t.indexOf(a)>=0)&&Object.prototype.propertyIsEnumerable.call(e,a)&&(r[a]=e[a])}return r}function Ae(e,t){if(e==null)return{};var r={};for(var a in e)if(Object.prototype.hasOwnProperty.call(e,a)){if(t.indexOf(a)>=0)continue;r[a]=e[a]}return r}function D(){return D=Object.assign?Object.assign.bind():function(e){for(var t=1;t<arguments.length;t++){var r=arguments[t];for(var a in r)Object.prototype.hasOwnProperty.call(r,a)&&(e[a]=r[a])}return e},D.apply(this,arguments)}function U(e,t){var r=Object.keys(e);if(Object.getOwnPropertySymbols){var a=Object.getOwnPropertySymbols(e);t&&(a=a.filter(function(n){return Object.getOwnPropertyDescriptor(e,n).enumerable})),r.push.apply(r,a)}return r}function S(e){for(var t=1;t<arguments.length;t++){var r=arguments[t]!=null?arguments[t]:{};t%2?U(Object(r),!0).forEach(function(a){E(e,a,r[a])}):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(r)):U(Object(r)).forEach(function(a){Object.defineProperty(e,a,Object.getOwnPropertyDescriptor(r,a))})}return e}function ge(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}function Z(e,t){for(var r=0;r<t.length;r++){var a=t[r];a.enumerable=a.enumerable||!1,a.configurable=!0,"value"in a&&(a.writable=!0),Object.defineProperty(e,ne(a.key),a)}}function xe(e,t,r){return t&&Z(e.prototype,t),r&&Z(e,r),Object.defineProperty(e,"prototype",{writable:!1}),e}function Pe(e,t,r){return t=$(t),Oe(e,re()?Reflect.construct(t,r||[],$(e).constructor):t.apply(e,r))}function Oe(e,t){if(t&&(M(t)==="object"||typeof t=="function"))return t;if(t!==void 0)throw new TypeError("Derived constructors may only return object or undefined");return Ee(e)}function Ee(e){if(e===void 0)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return e}function re(){try{var e=!Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],function(){}))}catch{}return(re=function(){return!!e})()}function $(e){return $=Object.setPrototypeOf?Object.getPrototypeOf.bind():function(r){return r.__proto__||Object.getPrototypeOf(r)},$(e)}function we(e,t){if(typeof t!="function"&&t!==null)throw new TypeError("Super expression must either be null or a function");e.prototype=Object.create(t&&t.prototype,{constructor:{value:e,writable:!0,configurable:!0}}),Object.defineProperty(e,"prototype",{writable:!1}),t&&X(e,t)}function X(e,t){return X=Object.setPrototypeOf?Object.setPrototypeOf.bind():function(a,n){return a.__proto__=n,a},X(e,t)}function E(e,t,r){return t=ne(t),t in e?Object.defineProperty(e,t,{value:r,enumerable:!0,configurable:!0,writable:!0}):e[t]=r,e}function ne(e){var t=_e(e,"string");return M(t)=="symbol"?t:t+""}function _e(e,t){if(M(e)!="object"||!e)return e;var r=e[Symbol.toPrimitive];if(r!==void 0){var a=r.call(e,t);if(M(a)!="object")return a;throw new TypeError("@@toPrimitive must return a primitive value.")}return String(e)}var L=function(e){function t(){var r;ge(this,t);for(var a=arguments.length,n=new Array(a),i=0;i<a;i++)n[i]=arguments[i];return r=Pe(this,t,[].concat(n)),E(r,"state",{isAnimationFinished:!0}),E(r,"id",ue("recharts-area-")),E(r,"handleAnimationEnd",function(){var o=r.props.onAnimationEnd;r.setState({isAnimationFinished:!0}),K(o)&&o()}),E(r,"handleAnimationStart",function(){var o=r.props.onAnimationStart;r.setState({isAnimationFinished:!1}),K(o)&&o()}),r}return we(t,e),xe(t,[{key:"renderDots",value:function(a,n,i){var o=this.props.isAnimationActive,s=this.state.isAnimationFinished;if(o&&!s)return null;var u=this.props,l=u.dot,f=u.points,c=u.dataKey,h=R(this.props,!1),A=R(l,!0),g=f.map(function(v,O){var y=S(S(S({key:"dot-".concat(O),r:3},h),A),{},{index:O,cx:v.x,cy:v.y,dataKey:c,value:v.value,payload:v.payload,points:f});return t.renderDotItem(l,y)}),x={clipPath:a?"url(#clipPath-".concat(n?"":"dots-").concat(i,")"):null};return p.createElement(W,D({className:"recharts-area-dots"},x),g)}},{key:"renderHorizontalRect",value:function(a){var n=this.props,i=n.baseLine,o=n.points,s=n.strokeWidth,u=o[0].x,l=o[o.length-1].x,f=a*Math.abs(u-l),c=T(o.map(function(h){return h.y||0}));return C(i)&&typeof i=="number"?c=Math.max(i,c):i&&Array.isArray(i)&&i.length&&(c=Math.max(T(i.map(function(h){return h.y||0})),c)),C(c)?p.createElement("rect",{x:u<l?u:u-f,y:0,width:f,height:Math.floor(c+(s?parseInt("".concat(s),10):1))}):null}},{key:"renderVerticalRect",value:function(a){var n=this.props,i=n.baseLine,o=n.points,s=n.strokeWidth,u=o[0].y,l=o[o.length-1].y,f=a*Math.abs(u-l),c=T(o.map(function(h){return h.x||0}));return C(i)&&typeof i=="number"?c=Math.max(i,c):i&&Array.isArray(i)&&i.length&&(c=Math.max(T(i.map(function(h){return h.x||0})),c)),C(c)?p.createElement("rect",{x:0,y:u<l?u:u-f,width:c+(s?parseInt("".concat(s),10):1),height:Math.floor(f)}):null}},{key:"renderClipRect",value:function(a){var n=this.props.layout;return n==="vertical"?this.renderVerticalRect(a):this.renderHorizontalRect(a)}},{key:"renderAreaStatically",value:function(a,n,i,o){var s=this.props,u=s.layout,l=s.type,f=s.stroke,c=s.connectNulls,h=s.isRange;s.ref;var A=ae(s,ye);return p.createElement(W,{clipPath:i?"url(#clipPath-".concat(o,")"):null},p.createElement(F,D({},R(A,!0),{points:a,connectNulls:c,type:l,baseLine:n,layout:u,stroke:"none",className:"recharts-area-area"})),f!=="none"&&p.createElement(F,D({},R(this.props,!1),{className:"recharts-area-curve",layout:u,type:l,connectNulls:c,fill:"none",points:a})),f!=="none"&&h&&p.createElement(F,D({},R(this.props,!1),{className:"recharts-area-curve",layout:u,type:l,connectNulls:c,fill:"none",points:n})))}},{key:"renderAreaWithAnimation",value:function(a,n){var i=this,o=this.props,s=o.points,u=o.baseLine,l=o.isAnimationActive,f=o.animationBegin,c=o.animationDuration,h=o.animationEasing,A=o.animationId,g=this.state,x=g.prevPoints,v=g.prevBaseLine;return p.createElement(ie,{begin:f,duration:c,isActive:l,easing:h,from:{t:0},to:{t:1},key:"area-".concat(A),onAnimationEnd:this.handleAnimationEnd,onAnimationStart:this.handleAnimationStart},function(O){var y=O.t;if(x){var _=x.length/s.length,d=s.map(function(P,N){var k=Math.floor(N*_);if(x[k]){var j=x[k],I=B(j.x,P.x),V=B(j.y,P.y);return S(S({},P),{},{x:I(y),y:V(y)})}return P}),m;if(C(u)&&typeof u=="number"){var b=B(v,u);m=b(y)}else if(q(u)||oe(u)){var w=B(v,0);m=w(y)}else m=u.map(function(P,N){var k=Math.floor(N*_);if(v[k]){var j=v[k],I=B(j.x,P.x),V=B(j.y,P.y);return S(S({},P),{},{x:I(y),y:V(y)})}return P});return i.renderAreaStatically(d,m,a,n)}return p.createElement(W,null,p.createElement("defs",null,p.createElement("clipPath",{id:"animationClipPath-".concat(n)},i.renderClipRect(y))),p.createElement(W,{clipPath:"url(#animationClipPath-".concat(n,")")},i.renderAreaStatically(s,u,a,n)))})}},{key:"renderArea",value:function(a,n){var i=this.props,o=i.points,s=i.baseLine,u=i.isAnimationActive,l=this.state,f=l.prevPoints,c=l.prevBaseLine,h=l.totalLength;return u&&o&&o.length&&(!f&&h>0||!G(f,o)||!G(c,s))?this.renderAreaWithAnimation(a,n):this.renderAreaStatically(o,s,a,n)}},{key:"render",value:function(){var a,n=this.props,i=n.hide,o=n.dot,s=n.points,u=n.className,l=n.top,f=n.left,c=n.xAxis,h=n.yAxis,A=n.width,g=n.height,x=n.isAnimationActive,v=n.id;if(i||!s||!s.length)return null;var O=this.state.isAnimationFinished,y=s.length===1,_=ee("recharts-area",u),d=c&&c.allowDataOverflow,m=h&&h.allowDataOverflow,b=d||m,w=q(v)?this.id:v,P=(a=R(o,!1))!==null&&a!==void 0?a:{r:3,strokeWidth:2},N=P.r,k=N===void 0?3:N,j=P.strokeWidth,I=j===void 0?2:j,V=se(o)?o:{},Y=V.clipDot,H=Y===void 0?!0:Y,z=k*2+I;return p.createElement(W,{className:_},d||m?p.createElement("defs",null,p.createElement("clipPath",{id:"clipPath-".concat(w)},p.createElement("rect",{x:d?f:f-A/2,y:m?l:l-g/2,width:d?A:A*2,height:m?g:g*2})),!H&&p.createElement("clipPath",{id:"clipPath-dots-".concat(w)},p.createElement("rect",{x:f-z/2,y:l-z/2,width:A+z,height:g+z}))):null,y?null:this.renderArea(b,w),(o||y)&&this.renderDots(b,H,w),(!x||O)&&le.renderCallByParent(this.props,s))}}],[{key:"getDerivedStateFromProps",value:function(a,n){return a.animationId!==n.prevAnimationId?{prevAnimationId:a.animationId,curPoints:a.points,curBaseLine:a.baseLine,prevPoints:n.curPoints,prevBaseLine:n.curBaseLine}:a.points!==n.curPoints||a.baseLine!==n.curBaseLine?{curPoints:a.points,curBaseLine:a.baseLine}:null}}])}(ve.PureComponent);te=L;E(L,"displayName","Area");E(L,"defaultProps",{stroke:"#3182bd",fill:"#3182bd",fillOpacity:.6,xAxisId:0,yAxisId:0,legendType:"line",connectNulls:!1,points:[],dot:!1,activeDot:!0,hide:!1,isAnimationActive:!ce.isSsr,animationBegin:0,animationDuration:1500,animationEasing:"ease"});E(L,"getBaseValue",function(e,t,r,a){var n=e.layout,i=e.baseValue,o=t.props.baseValue,s=o??i;if(C(s)&&typeof s=="number")return s;var u=n==="horizontal"?a:r,l=u.scale.domain();if(u.type==="number"){var f=Math.max(l[0],l[1]),c=Math.min(l[0],l[1]);return s==="dataMin"?c:s==="dataMax"||f<0?f:Math.max(Math.min(l[0],l[1]),0)}return s==="dataMin"?l[0]:s==="dataMax"?l[1]:l[0]});E(L,"getComposedData",function(e){var t=e.props,r=e.item,a=e.xAxis,n=e.yAxis,i=e.xAxisTicks,o=e.yAxisTicks,s=e.bandSize,u=e.dataKey,l=e.stackedData,f=e.dataStartIndex,c=e.displayedData,h=e.offset,A=t.layout,g=l&&l.length,x=te.getBaseValue(t,r,a,n),v=A==="horizontal",O=!1,y=c.map(function(d,m){var b;g?b=l[f+m]:(b=J(d,u),Array.isArray(b)?O=!0:b=[x,b]);var w=b[1]==null||g&&J(d,u)==null;return v?{x:Q({axis:a,ticks:i,bandSize:s,entry:d,index:m}),y:w?null:n.scale(b[1]),value:b,payload:d}:{x:w?null:a.scale(b[1]),y:Q({axis:n,ticks:o,bandSize:s,entry:d,index:m}),value:b,payload:d}}),_;return g||O?_=y.map(function(d){var m=Array.isArray(d.value)?d.value[0]:null;return v?{x:d.x,y:m!=null&&d.y!=null?n.scale(m):null}:{x:m!=null?a.scale(m):null,y:d.y}}):_=v?n.scale(x):a.scale(x),S({points:y,baseLine:_,layout:A,isRange:O},h)});E(L,"renderDotItem",function(e,t){var r;if(p.isValidElement(e))r=p.cloneElement(e,t);else if(K(e))r=e(t);else{var a=ee("recharts-area-dot",typeof e!="boolean"?e.className:""),n=t.key,i=ae(t,be);r=p.createElement(fe,D({},i,{key:n,className:a}))}return r});var ke=pe({chartName:"AreaChart",GraphicalChild:L,axisComponents:[{axisType:"xAxis",AxisComp:he},{axisType:"yAxis",AxisComp:de}],formatAxisMap:me});export{ke as A,L as a};
2
- //# sourceMappingURL=AreaChart-DywU5SSt.js.map
1
+ import{b as R,c as W,m as T,i as C,d as F,A as ie,e as B,h as q,j as oe,k as G,l as se,n as le,u as ue,o as K,G as ce,p as J,q as Q,D as fe,g as pe,X as he,Y as de,f as me}from"./generateCategoricalChart-M-GeRM8U.js";import{R as p,F as ee,r as ve}from"./index-BIZZXvoy.js";var ye=["layout","type","stroke","connectNulls","isRange","ref"],be=["key"],te;function M(e){"@babel/helpers - typeof";return M=typeof Symbol=="function"&&typeof Symbol.iterator=="symbol"?function(t){return typeof t}:function(t){return t&&typeof Symbol=="function"&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t},M(e)}function ae(e,t){if(e==null)return{};var r=Ae(e,t),a,n;if(Object.getOwnPropertySymbols){var i=Object.getOwnPropertySymbols(e);for(n=0;n<i.length;n++)a=i[n],!(t.indexOf(a)>=0)&&Object.prototype.propertyIsEnumerable.call(e,a)&&(r[a]=e[a])}return r}function Ae(e,t){if(e==null)return{};var r={};for(var a in e)if(Object.prototype.hasOwnProperty.call(e,a)){if(t.indexOf(a)>=0)continue;r[a]=e[a]}return r}function D(){return D=Object.assign?Object.assign.bind():function(e){for(var t=1;t<arguments.length;t++){var r=arguments[t];for(var a in r)Object.prototype.hasOwnProperty.call(r,a)&&(e[a]=r[a])}return e},D.apply(this,arguments)}function U(e,t){var r=Object.keys(e);if(Object.getOwnPropertySymbols){var a=Object.getOwnPropertySymbols(e);t&&(a=a.filter(function(n){return Object.getOwnPropertyDescriptor(e,n).enumerable})),r.push.apply(r,a)}return r}function S(e){for(var t=1;t<arguments.length;t++){var r=arguments[t]!=null?arguments[t]:{};t%2?U(Object(r),!0).forEach(function(a){E(e,a,r[a])}):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(r)):U(Object(r)).forEach(function(a){Object.defineProperty(e,a,Object.getOwnPropertyDescriptor(r,a))})}return e}function ge(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}function Z(e,t){for(var r=0;r<t.length;r++){var a=t[r];a.enumerable=a.enumerable||!1,a.configurable=!0,"value"in a&&(a.writable=!0),Object.defineProperty(e,ne(a.key),a)}}function xe(e,t,r){return t&&Z(e.prototype,t),r&&Z(e,r),Object.defineProperty(e,"prototype",{writable:!1}),e}function Pe(e,t,r){return t=$(t),Oe(e,re()?Reflect.construct(t,r||[],$(e).constructor):t.apply(e,r))}function Oe(e,t){if(t&&(M(t)==="object"||typeof t=="function"))return t;if(t!==void 0)throw new TypeError("Derived constructors may only return object or undefined");return Ee(e)}function Ee(e){if(e===void 0)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return e}function re(){try{var e=!Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],function(){}))}catch{}return(re=function(){return!!e})()}function $(e){return $=Object.setPrototypeOf?Object.getPrototypeOf.bind():function(r){return r.__proto__||Object.getPrototypeOf(r)},$(e)}function we(e,t){if(typeof t!="function"&&t!==null)throw new TypeError("Super expression must either be null or a function");e.prototype=Object.create(t&&t.prototype,{constructor:{value:e,writable:!0,configurable:!0}}),Object.defineProperty(e,"prototype",{writable:!1}),t&&X(e,t)}function X(e,t){return X=Object.setPrototypeOf?Object.setPrototypeOf.bind():function(a,n){return a.__proto__=n,a},X(e,t)}function E(e,t,r){return t=ne(t),t in e?Object.defineProperty(e,t,{value:r,enumerable:!0,configurable:!0,writable:!0}):e[t]=r,e}function ne(e){var t=_e(e,"string");return M(t)=="symbol"?t:t+""}function _e(e,t){if(M(e)!="object"||!e)return e;var r=e[Symbol.toPrimitive];if(r!==void 0){var a=r.call(e,t);if(M(a)!="object")return a;throw new TypeError("@@toPrimitive must return a primitive value.")}return String(e)}var L=function(e){function t(){var r;ge(this,t);for(var a=arguments.length,n=new Array(a),i=0;i<a;i++)n[i]=arguments[i];return r=Pe(this,t,[].concat(n)),E(r,"state",{isAnimationFinished:!0}),E(r,"id",ue("recharts-area-")),E(r,"handleAnimationEnd",function(){var o=r.props.onAnimationEnd;r.setState({isAnimationFinished:!0}),K(o)&&o()}),E(r,"handleAnimationStart",function(){var o=r.props.onAnimationStart;r.setState({isAnimationFinished:!1}),K(o)&&o()}),r}return we(t,e),xe(t,[{key:"renderDots",value:function(a,n,i){var o=this.props.isAnimationActive,s=this.state.isAnimationFinished;if(o&&!s)return null;var u=this.props,l=u.dot,f=u.points,c=u.dataKey,h=R(this.props,!1),A=R(l,!0),g=f.map(function(v,O){var y=S(S(S({key:"dot-".concat(O),r:3},h),A),{},{index:O,cx:v.x,cy:v.y,dataKey:c,value:v.value,payload:v.payload,points:f});return t.renderDotItem(l,y)}),x={clipPath:a?"url(#clipPath-".concat(n?"":"dots-").concat(i,")"):null};return p.createElement(W,D({className:"recharts-area-dots"},x),g)}},{key:"renderHorizontalRect",value:function(a){var n=this.props,i=n.baseLine,o=n.points,s=n.strokeWidth,u=o[0].x,l=o[o.length-1].x,f=a*Math.abs(u-l),c=T(o.map(function(h){return h.y||0}));return C(i)&&typeof i=="number"?c=Math.max(i,c):i&&Array.isArray(i)&&i.length&&(c=Math.max(T(i.map(function(h){return h.y||0})),c)),C(c)?p.createElement("rect",{x:u<l?u:u-f,y:0,width:f,height:Math.floor(c+(s?parseInt("".concat(s),10):1))}):null}},{key:"renderVerticalRect",value:function(a){var n=this.props,i=n.baseLine,o=n.points,s=n.strokeWidth,u=o[0].y,l=o[o.length-1].y,f=a*Math.abs(u-l),c=T(o.map(function(h){return h.x||0}));return C(i)&&typeof i=="number"?c=Math.max(i,c):i&&Array.isArray(i)&&i.length&&(c=Math.max(T(i.map(function(h){return h.x||0})),c)),C(c)?p.createElement("rect",{x:0,y:u<l?u:u-f,width:c+(s?parseInt("".concat(s),10):1),height:Math.floor(f)}):null}},{key:"renderClipRect",value:function(a){var n=this.props.layout;return n==="vertical"?this.renderVerticalRect(a):this.renderHorizontalRect(a)}},{key:"renderAreaStatically",value:function(a,n,i,o){var s=this.props,u=s.layout,l=s.type,f=s.stroke,c=s.connectNulls,h=s.isRange;s.ref;var A=ae(s,ye);return p.createElement(W,{clipPath:i?"url(#clipPath-".concat(o,")"):null},p.createElement(F,D({},R(A,!0),{points:a,connectNulls:c,type:l,baseLine:n,layout:u,stroke:"none",className:"recharts-area-area"})),f!=="none"&&p.createElement(F,D({},R(this.props,!1),{className:"recharts-area-curve",layout:u,type:l,connectNulls:c,fill:"none",points:a})),f!=="none"&&h&&p.createElement(F,D({},R(this.props,!1),{className:"recharts-area-curve",layout:u,type:l,connectNulls:c,fill:"none",points:n})))}},{key:"renderAreaWithAnimation",value:function(a,n){var i=this,o=this.props,s=o.points,u=o.baseLine,l=o.isAnimationActive,f=o.animationBegin,c=o.animationDuration,h=o.animationEasing,A=o.animationId,g=this.state,x=g.prevPoints,v=g.prevBaseLine;return p.createElement(ie,{begin:f,duration:c,isActive:l,easing:h,from:{t:0},to:{t:1},key:"area-".concat(A),onAnimationEnd:this.handleAnimationEnd,onAnimationStart:this.handleAnimationStart},function(O){var y=O.t;if(x){var _=x.length/s.length,d=s.map(function(P,N){var k=Math.floor(N*_);if(x[k]){var j=x[k],I=B(j.x,P.x),V=B(j.y,P.y);return S(S({},P),{},{x:I(y),y:V(y)})}return P}),m;if(C(u)&&typeof u=="number"){var b=B(v,u);m=b(y)}else if(q(u)||oe(u)){var w=B(v,0);m=w(y)}else m=u.map(function(P,N){var k=Math.floor(N*_);if(v[k]){var j=v[k],I=B(j.x,P.x),V=B(j.y,P.y);return S(S({},P),{},{x:I(y),y:V(y)})}return P});return i.renderAreaStatically(d,m,a,n)}return p.createElement(W,null,p.createElement("defs",null,p.createElement("clipPath",{id:"animationClipPath-".concat(n)},i.renderClipRect(y))),p.createElement(W,{clipPath:"url(#animationClipPath-".concat(n,")")},i.renderAreaStatically(s,u,a,n)))})}},{key:"renderArea",value:function(a,n){var i=this.props,o=i.points,s=i.baseLine,u=i.isAnimationActive,l=this.state,f=l.prevPoints,c=l.prevBaseLine,h=l.totalLength;return u&&o&&o.length&&(!f&&h>0||!G(f,o)||!G(c,s))?this.renderAreaWithAnimation(a,n):this.renderAreaStatically(o,s,a,n)}},{key:"render",value:function(){var a,n=this.props,i=n.hide,o=n.dot,s=n.points,u=n.className,l=n.top,f=n.left,c=n.xAxis,h=n.yAxis,A=n.width,g=n.height,x=n.isAnimationActive,v=n.id;if(i||!s||!s.length)return null;var O=this.state.isAnimationFinished,y=s.length===1,_=ee("recharts-area",u),d=c&&c.allowDataOverflow,m=h&&h.allowDataOverflow,b=d||m,w=q(v)?this.id:v,P=(a=R(o,!1))!==null&&a!==void 0?a:{r:3,strokeWidth:2},N=P.r,k=N===void 0?3:N,j=P.strokeWidth,I=j===void 0?2:j,V=se(o)?o:{},Y=V.clipDot,H=Y===void 0?!0:Y,z=k*2+I;return p.createElement(W,{className:_},d||m?p.createElement("defs",null,p.createElement("clipPath",{id:"clipPath-".concat(w)},p.createElement("rect",{x:d?f:f-A/2,y:m?l:l-g/2,width:d?A:A*2,height:m?g:g*2})),!H&&p.createElement("clipPath",{id:"clipPath-dots-".concat(w)},p.createElement("rect",{x:f-z/2,y:l-z/2,width:A+z,height:g+z}))):null,y?null:this.renderArea(b,w),(o||y)&&this.renderDots(b,H,w),(!x||O)&&le.renderCallByParent(this.props,s))}}],[{key:"getDerivedStateFromProps",value:function(a,n){return a.animationId!==n.prevAnimationId?{prevAnimationId:a.animationId,curPoints:a.points,curBaseLine:a.baseLine,prevPoints:n.curPoints,prevBaseLine:n.curBaseLine}:a.points!==n.curPoints||a.baseLine!==n.curBaseLine?{curPoints:a.points,curBaseLine:a.baseLine}:null}}])}(ve.PureComponent);te=L;E(L,"displayName","Area");E(L,"defaultProps",{stroke:"#3182bd",fill:"#3182bd",fillOpacity:.6,xAxisId:0,yAxisId:0,legendType:"line",connectNulls:!1,points:[],dot:!1,activeDot:!0,hide:!1,isAnimationActive:!ce.isSsr,animationBegin:0,animationDuration:1500,animationEasing:"ease"});E(L,"getBaseValue",function(e,t,r,a){var n=e.layout,i=e.baseValue,o=t.props.baseValue,s=o??i;if(C(s)&&typeof s=="number")return s;var u=n==="horizontal"?a:r,l=u.scale.domain();if(u.type==="number"){var f=Math.max(l[0],l[1]),c=Math.min(l[0],l[1]);return s==="dataMin"?c:s==="dataMax"||f<0?f:Math.max(Math.min(l[0],l[1]),0)}return s==="dataMin"?l[0]:s==="dataMax"?l[1]:l[0]});E(L,"getComposedData",function(e){var t=e.props,r=e.item,a=e.xAxis,n=e.yAxis,i=e.xAxisTicks,o=e.yAxisTicks,s=e.bandSize,u=e.dataKey,l=e.stackedData,f=e.dataStartIndex,c=e.displayedData,h=e.offset,A=t.layout,g=l&&l.length,x=te.getBaseValue(t,r,a,n),v=A==="horizontal",O=!1,y=c.map(function(d,m){var b;g?b=l[f+m]:(b=J(d,u),Array.isArray(b)?O=!0:b=[x,b]);var w=b[1]==null||g&&J(d,u)==null;return v?{x:Q({axis:a,ticks:i,bandSize:s,entry:d,index:m}),y:w?null:n.scale(b[1]),value:b,payload:d}:{x:w?null:a.scale(b[1]),y:Q({axis:n,ticks:o,bandSize:s,entry:d,index:m}),value:b,payload:d}}),_;return g||O?_=y.map(function(d){var m=Array.isArray(d.value)?d.value[0]:null;return v?{x:d.x,y:m!=null&&d.y!=null?n.scale(m):null}:{x:m!=null?a.scale(m):null,y:d.y}}):_=v?n.scale(x):a.scale(x),S({points:y,baseLine:_,layout:A,isRange:O},h)});E(L,"renderDotItem",function(e,t){var r;if(p.isValidElement(e))r=p.cloneElement(e,t);else if(K(e))r=e(t);else{var a=ee("recharts-area-dot",typeof e!="boolean"?e.className:""),n=t.key,i=ae(t,be);r=p.createElement(fe,D({},i,{key:n,className:a}))}return r});var ke=pe({chartName:"AreaChart",GraphicalChild:L,axisComponents:[{axisType:"xAxis",AxisComp:he},{axisType:"yAxis",AxisComp:de}],formatAxisMap:me});export{ke as A,L as a};
2
+ //# sourceMappingURL=AreaChart-B9KYKrUE.js.map