@remnic/core 1.0.0
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/dist/abstraction-nodes.d.ts +52 -0
- package/dist/abstraction-nodes.js +15 -0
- package/dist/abstraction-nodes.js.map +1 -0
- package/dist/access-cli.d.ts +5 -0
- package/dist/access-cli.js +308 -0
- package/dist/access-cli.js.map +1 -0
- package/dist/access-http.d.ts +158 -0
- package/dist/access-http.js +32 -0
- package/dist/access-http.js.map +1 -0
- package/dist/access-idempotency.d.ts +31 -0
- package/dist/access-idempotency.js +11 -0
- package/dist/access-idempotency.js.map +1 -0
- package/dist/access-mcp.d.ts +76 -0
- package/dist/access-mcp.js +8 -0
- package/dist/access-mcp.js.map +1 -0
- package/dist/access-schema.d.ts +266 -0
- package/dist/access-schema.js +29 -0
- package/dist/access-schema.js.map +1 -0
- package/dist/access-service.d.ts +614 -0
- package/dist/access-service.js +32 -0
- package/dist/access-service.js.map +1 -0
- package/dist/behavior-learner.d.ts +16 -0
- package/dist/behavior-learner.js +124 -0
- package/dist/behavior-learner.js.map +1 -0
- package/dist/behavior-signals.d.ts +15 -0
- package/dist/behavior-signals.js +11 -0
- package/dist/behavior-signals.js.map +1 -0
- package/dist/bootstrap.d.ts +46 -0
- package/dist/bootstrap.js +9 -0
- package/dist/bootstrap.js.map +1 -0
- package/dist/boxes.d.ts +93 -0
- package/dist/boxes.js +14 -0
- package/dist/boxes.js.map +1 -0
- package/dist/buffer.d.ts +22 -0
- package/dist/buffer.js +9 -0
- package/dist/buffer.js.map +1 -0
- package/dist/calibration.d.ts +81 -0
- package/dist/calibration.js +239 -0
- package/dist/calibration.js.map +1 -0
- package/dist/causal-behavior.d.ts +79 -0
- package/dist/causal-behavior.js +190 -0
- package/dist/causal-behavior.js.map +1 -0
- package/dist/causal-chain.d.ts +61 -0
- package/dist/causal-chain.js +24 -0
- package/dist/causal-chain.js.map +1 -0
- package/dist/causal-consolidation.d.ts +71 -0
- package/dist/causal-consolidation.js +211 -0
- package/dist/causal-consolidation.js.map +1 -0
- package/dist/causal-retrieval.d.ts +44 -0
- package/dist/causal-retrieval.js +184 -0
- package/dist/causal-retrieval.js.map +1 -0
- package/dist/causal-trajectory-graph.d.ts +13 -0
- package/dist/causal-trajectory-graph.js +59 -0
- package/dist/causal-trajectory-graph.js.map +1 -0
- package/dist/causal-trajectory.d.ts +68 -0
- package/dist/causal-trajectory.js +18 -0
- package/dist/causal-trajectory.js.map +1 -0
- package/dist/chunk-2CJCWDMR.js +87 -0
- package/dist/chunk-2CJCWDMR.js.map +1 -0
- package/dist/chunk-2NMMFZ5T.js +216 -0
- package/dist/chunk-2NMMFZ5T.js.map +1 -0
- package/dist/chunk-2PO5ZRKV.js +103 -0
- package/dist/chunk-2PO5ZRKV.js.map +1 -0
- package/dist/chunk-3QKK7QOS.js +154 -0
- package/dist/chunk-3QKK7QOS.js.map +1 -0
- package/dist/chunk-3SLRNYNG.js +26 -0
- package/dist/chunk-3SLRNYNG.js.map +1 -0
- package/dist/chunk-4A24LIM2.js +68 -0
- package/dist/chunk-4A24LIM2.js.map +1 -0
- package/dist/chunk-6HZ6AO2P.js +164 -0
- package/dist/chunk-6HZ6AO2P.js.map +1 -0
- package/dist/chunk-763GUIOU.js +302 -0
- package/dist/chunk-763GUIOU.js.map +1 -0
- package/dist/chunk-AAI7JARD.js +173 -0
- package/dist/chunk-AAI7JARD.js.map +1 -0
- package/dist/chunk-B7LOFDVE.js +112 -0
- package/dist/chunk-B7LOFDVE.js.map +1 -0
- package/dist/chunk-BDFZXRSO.js +318 -0
- package/dist/chunk-BDFZXRSO.js.map +1 -0
- package/dist/chunk-BOUYNNYD.js +707 -0
- package/dist/chunk-BOUYNNYD.js.map +1 -0
- package/dist/chunk-BRK4ODMI.js +60 -0
- package/dist/chunk-BRK4ODMI.js.map +1 -0
- package/dist/chunk-C6QPK5GG.js +111 -0
- package/dist/chunk-C6QPK5GG.js.map +1 -0
- package/dist/chunk-C7VW7C3F.js +117 -0
- package/dist/chunk-C7VW7C3F.js.map +1 -0
- package/dist/chunk-CDW777AI.js +621 -0
- package/dist/chunk-CDW777AI.js.map +1 -0
- package/dist/chunk-CULXMQJH.js +185 -0
- package/dist/chunk-CULXMQJH.js.map +1 -0
- package/dist/chunk-CXWFUJR2.js +1203 -0
- package/dist/chunk-CXWFUJR2.js.map +1 -0
- package/dist/chunk-DGXUHMOV.js +61 -0
- package/dist/chunk-DGXUHMOV.js.map +1 -0
- package/dist/chunk-DM2T26WE.js +61 -0
- package/dist/chunk-DM2T26WE.js.map +1 -0
- package/dist/chunk-DORBM6OB.js +81 -0
- package/dist/chunk-DORBM6OB.js.map +1 -0
- package/dist/chunk-DT5TVLJE.js +32 -0
- package/dist/chunk-DT5TVLJE.js.map +1 -0
- package/dist/chunk-EEQLFRUM.js +89 -0
- package/dist/chunk-EEQLFRUM.js.map +1 -0
- package/dist/chunk-EQINRHYR.js +672 -0
- package/dist/chunk-EQINRHYR.js.map +1 -0
- package/dist/chunk-ESSMF2FR.js +146 -0
- package/dist/chunk-ESSMF2FR.js.map +1 -0
- package/dist/chunk-ETOW6ACV.js +158 -0
- package/dist/chunk-ETOW6ACV.js.map +1 -0
- package/dist/chunk-FYIYMQ5N.js +221 -0
- package/dist/chunk-FYIYMQ5N.js.map +1 -0
- package/dist/chunk-G3AG3KZN.js +78 -0
- package/dist/chunk-G3AG3KZN.js.map +1 -0
- package/dist/chunk-GJR6D6KC.js +61 -0
- package/dist/chunk-GJR6D6KC.js.map +1 -0
- package/dist/chunk-GPGBSNKM.js +380 -0
- package/dist/chunk-GPGBSNKM.js.map +1 -0
- package/dist/chunk-H63EDPFJ.js +57 -0
- package/dist/chunk-H63EDPFJ.js.map +1 -0
- package/dist/chunk-HG2NKWR2.js +185 -0
- package/dist/chunk-HG2NKWR2.js.map +1 -0
- package/dist/chunk-HL4DB7TO.js +13 -0
- package/dist/chunk-HL4DB7TO.js.map +1 -0
- package/dist/chunk-HLBYLYRD.js +346 -0
- package/dist/chunk-HLBYLYRD.js.map +1 -0
- package/dist/chunk-HLXVTBF3.js +109 -0
- package/dist/chunk-HLXVTBF3.js.map +1 -0
- package/dist/chunk-IFFFR3MR.js +68 -0
- package/dist/chunk-IFFFR3MR.js.map +1 -0
- package/dist/chunk-ISY75RLM.js +1027 -0
- package/dist/chunk-ISY75RLM.js.map +1 -0
- package/dist/chunk-IZME7KW2.js +1886 -0
- package/dist/chunk-IZME7KW2.js.map +1 -0
- package/dist/chunk-J3BT33K7.js +720 -0
- package/dist/chunk-J3BT33K7.js.map +1 -0
- package/dist/chunk-J47FNDR7.js +113 -0
- package/dist/chunk-J47FNDR7.js.map +1 -0
- package/dist/chunk-JWPLJLDU.js +63 -0
- package/dist/chunk-JWPLJLDU.js.map +1 -0
- package/dist/chunk-K6WK37A6.js +865 -0
- package/dist/chunk-K6WK37A6.js.map +1 -0
- package/dist/chunk-KL4CP4SB.js +130 -0
- package/dist/chunk-KL4CP4SB.js.map +1 -0
- package/dist/chunk-KT4NEUNF.js +315 -0
- package/dist/chunk-KT4NEUNF.js.map +1 -0
- package/dist/chunk-KWBU5S5U.js +42 -0
- package/dist/chunk-KWBU5S5U.js.map +1 -0
- package/dist/chunk-L5RPWGFK.js +59 -0
- package/dist/chunk-L5RPWGFK.js.map +1 -0
- package/dist/chunk-L7WO3MZ4.js +128 -0
- package/dist/chunk-L7WO3MZ4.js.map +1 -0
- package/dist/chunk-LIRZNNUP.js +74 -0
- package/dist/chunk-LIRZNNUP.js.map +1 -0
- package/dist/chunk-LK6SGL53.js +22 -0
- package/dist/chunk-LK6SGL53.js.map +1 -0
- package/dist/chunk-LOBRX7VD.js +200 -0
- package/dist/chunk-LOBRX7VD.js.map +1 -0
- package/dist/chunk-LPSF4OQH.js +47 -0
- package/dist/chunk-LPSF4OQH.js.map +1 -0
- package/dist/chunk-LU3GQNDQ.js +152 -0
- package/dist/chunk-LU3GQNDQ.js.map +1 -0
- package/dist/chunk-M5KEYE5E.js +350 -0
- package/dist/chunk-M5KEYE5E.js.map +1 -0
- package/dist/chunk-M62O4P4T.js +41 -0
- package/dist/chunk-M62O4P4T.js.map +1 -0
- package/dist/chunk-MARWOCVP.js +48 -0
- package/dist/chunk-MARWOCVP.js.map +1 -0
- package/dist/chunk-MDDAA2AO.js +925 -0
- package/dist/chunk-MDDAA2AO.js.map +1 -0
- package/dist/chunk-MWGVGUIS.js +198 -0
- package/dist/chunk-MWGVGUIS.js.map +1 -0
- package/dist/chunk-N5AKDXAI.js +74 -0
- package/dist/chunk-N5AKDXAI.js.map +1 -0
- package/dist/chunk-NGAVDO7E.js +115 -0
- package/dist/chunk-NGAVDO7E.js.map +1 -0
- package/dist/chunk-NTTLPF7F.js +283 -0
- package/dist/chunk-NTTLPF7F.js.map +1 -0
- package/dist/chunk-ONRU4L2N.js +240 -0
- package/dist/chunk-ONRU4L2N.js.map +1 -0
- package/dist/chunk-ORZMT74A.js +209 -0
- package/dist/chunk-ORZMT74A.js.map +1 -0
- package/dist/chunk-OTAVQCSF.js +268 -0
- package/dist/chunk-OTAVQCSF.js.map +1 -0
- package/dist/chunk-PGK3VUHN.js +160 -0
- package/dist/chunk-PGK3VUHN.js.map +1 -0
- package/dist/chunk-Q6FETXJA.js +1362 -0
- package/dist/chunk-Q6FETXJA.js.map +1 -0
- package/dist/chunk-QANCTXQF.js +271 -0
- package/dist/chunk-QANCTXQF.js.map +1 -0
- package/dist/chunk-QCCCQT3O.js +189 -0
- package/dist/chunk-QCCCQT3O.js.map +1 -0
- package/dist/chunk-QDOSNLB4.js +1048 -0
- package/dist/chunk-QDOSNLB4.js.map +1 -0
- package/dist/chunk-QFQVZOGA.js +2168 -0
- package/dist/chunk-QFQVZOGA.js.map +1 -0
- package/dist/chunk-QPKFPHOO.js +178 -0
- package/dist/chunk-QPKFPHOO.js.map +1 -0
- package/dist/chunk-QSVPYQPG.js +268 -0
- package/dist/chunk-QSVPYQPG.js.map +1 -0
- package/dist/chunk-QWUUMMIK.js +3045 -0
- package/dist/chunk-QWUUMMIK.js.map +1 -0
- package/dist/chunk-QY2BHY5O.js +2378 -0
- package/dist/chunk-QY2BHY5O.js.map +1 -0
- package/dist/chunk-SCHEKPYH.js +349 -0
- package/dist/chunk-SCHEKPYH.js.map +1 -0
- package/dist/chunk-SCU65EZI.js +15 -0
- package/dist/chunk-SCU65EZI.js.map +1 -0
- package/dist/chunk-T4WRIV2C.js +170 -0
- package/dist/chunk-T4WRIV2C.js.map +1 -0
- package/dist/chunk-TKO4HZCK.js +1852 -0
- package/dist/chunk-TKO4HZCK.js.map +1 -0
- package/dist/chunk-TP4FZJIZ.js +93 -0
- package/dist/chunk-TP4FZJIZ.js.map +1 -0
- package/dist/chunk-TPB3I2AC.js +403 -0
- package/dist/chunk-TPB3I2AC.js.map +1 -0
- package/dist/chunk-TVVVQQAK.js +1431 -0
- package/dist/chunk-TVVVQQAK.js.map +1 -0
- package/dist/chunk-U4PV25RD.js +14 -0
- package/dist/chunk-U4PV25RD.js.map +1 -0
- package/dist/chunk-UCYSTFZR.js +284 -0
- package/dist/chunk-UCYSTFZR.js.map +1 -0
- package/dist/chunk-UHGBNIOS.js +205 -0
- package/dist/chunk-UHGBNIOS.js.map +1 -0
- package/dist/chunk-UIYZ5T3I.js +108 -0
- package/dist/chunk-UIYZ5T3I.js.map +1 -0
- package/dist/chunk-UV2FO7J4.js +747 -0
- package/dist/chunk-UV2FO7J4.js.map +1 -0
- package/dist/chunk-UZB5KHKX.js +63 -0
- package/dist/chunk-UZB5KHKX.js.map +1 -0
- package/dist/chunk-V3RXWQIE.js +626 -0
- package/dist/chunk-V3RXWQIE.js.map +1 -0
- package/dist/chunk-V4YC4LUK.js +444 -0
- package/dist/chunk-V4YC4LUK.js.map +1 -0
- package/dist/chunk-VEWZZM3H.js +133 -0
- package/dist/chunk-VEWZZM3H.js.map +1 -0
- package/dist/chunk-WWIQTB2Y.js +98 -0
- package/dist/chunk-WWIQTB2Y.js.map +1 -0
- package/dist/chunk-X7XN6YU4.js +24 -0
- package/dist/chunk-X7XN6YU4.js.map +1 -0
- package/dist/chunk-XKECPATV.js +202 -0
- package/dist/chunk-XKECPATV.js.map +1 -0
- package/dist/chunk-XYIK4LF6.js +75 -0
- package/dist/chunk-XYIK4LF6.js.map +1 -0
- package/dist/chunk-Y27UJK6V.js +39 -0
- package/dist/chunk-Y27UJK6V.js.map +1 -0
- package/dist/chunk-Y4Z4I6WK.js +9 -0
- package/dist/chunk-Y4Z4I6WK.js.map +1 -0
- package/dist/chunk-YAPUAHAY.js +10761 -0
- package/dist/chunk-YAPUAHAY.js.map +1 -0
- package/dist/chunk-YAZNBMNF.js +92 -0
- package/dist/chunk-YAZNBMNF.js.map +1 -0
- package/dist/chunk-YCN4BVDK.js +66 -0
- package/dist/chunk-YCN4BVDK.js.map +1 -0
- package/dist/chunk-YNCQ7E4M.js +388 -0
- package/dist/chunk-YNCQ7E4M.js.map +1 -0
- package/dist/chunk-YNI4S5WT.js +143 -0
- package/dist/chunk-YNI4S5WT.js.map +1 -0
- package/dist/chunk-YRMVARQP.js +406 -0
- package/dist/chunk-YRMVARQP.js.map +1 -0
- package/dist/chunk-Z5AAYHUC.js +79 -0
- package/dist/chunk-Z5AAYHUC.js.map +1 -0
- package/dist/chunk-Z5LAYHGJ.js +15 -0
- package/dist/chunk-Z5LAYHGJ.js.map +1 -0
- package/dist/chunk-ZJLY4QSU.js +823 -0
- package/dist/chunk-ZJLY4QSU.js.map +1 -0
- package/dist/chunk-ZKYI7UVO.js +276 -0
- package/dist/chunk-ZKYI7UVO.js.map +1 -0
- package/dist/chunk-ZPKBYX2F.js +297 -0
- package/dist/chunk-ZPKBYX2F.js.map +1 -0
- package/dist/chunking.d.ts +48 -0
- package/dist/chunking.js +11 -0
- package/dist/chunking.js.map +1 -0
- package/dist/cli.d.ts +1162 -0
- package/dist/cli.js +7187 -0
- package/dist/cli.js.map +1 -0
- package/dist/commitment-ledger.d.ts +83 -0
- package/dist/commitment-ledger.js +19 -0
- package/dist/commitment-ledger.js.map +1 -0
- package/dist/compression-optimizer.d.ts +37 -0
- package/dist/compression-optimizer.js +13 -0
- package/dist/compression-optimizer.js.map +1 -0
- package/dist/config.d.ts +6 -0
- package/dist/config.js +12 -0
- package/dist/config.js.map +1 -0
- package/dist/cue-anchors.d.ts +50 -0
- package/dist/cue-anchors.js +15 -0
- package/dist/cue-anchors.js.map +1 -0
- package/dist/dashboard-runtime.d.ts +46 -0
- package/dist/dashboard-runtime.js +10 -0
- package/dist/dashboard-runtime.js.map +1 -0
- package/dist/day-summary.d.ts +6 -0
- package/dist/day-summary.js +10 -0
- package/dist/day-summary.js.map +1 -0
- package/dist/delinearize.d.ts +34 -0
- package/dist/delinearize.js +11 -0
- package/dist/delinearize.js.map +1 -0
- package/dist/embedding-fallback.d.ts +22 -0
- package/dist/embedding-fallback.js +8 -0
- package/dist/embedding-fallback.js.map +1 -0
- package/dist/engine-P26JFSVY.js +19 -0
- package/dist/engine-P26JFSVY.js.map +1 -0
- package/dist/entity-retrieval.d.ts +23 -0
- package/dist/entity-retrieval.js +24 -0
- package/dist/entity-retrieval.js.map +1 -0
- package/dist/evals.d.ts +282 -0
- package/dist/evals.js +32 -0
- package/dist/evals.js.map +1 -0
- package/dist/explicit-capture.d.ts +60 -0
- package/dist/explicit-capture.js +23 -0
- package/dist/explicit-capture.js.map +1 -0
- package/dist/extraction.d.ts +141 -0
- package/dist/extraction.js +22 -0
- package/dist/extraction.js.map +1 -0
- package/dist/fallback-llm.d.ts +95 -0
- package/dist/fallback-llm.js +12 -0
- package/dist/fallback-llm.js.map +1 -0
- package/dist/graph-dashboard-diff.d.ts +12 -0
- package/dist/graph-dashboard-diff.js +8 -0
- package/dist/graph-dashboard-diff.js.map +1 -0
- package/dist/graph-dashboard-key.d.ts +5 -0
- package/dist/graph-dashboard-key.js +7 -0
- package/dist/graph-dashboard-key.js.map +1 -0
- package/dist/graph-dashboard-parser.d.ts +20 -0
- package/dist/graph-dashboard-parser.js +8 -0
- package/dist/graph-dashboard-parser.js.map +1 -0
- package/dist/graph.d.ts +157 -0
- package/dist/graph.js +27 -0
- package/dist/graph.js.map +1 -0
- package/dist/harmonic-retrieval.d.ts +27 -0
- package/dist/harmonic-retrieval.js +12 -0
- package/dist/harmonic-retrieval.js.map +1 -0
- package/dist/himem.d.ts +23 -0
- package/dist/himem.js +7 -0
- package/dist/himem.js.map +1 -0
- package/dist/hygiene.d.ts +24 -0
- package/dist/hygiene.js +9 -0
- package/dist/hygiene.js.map +1 -0
- package/dist/identity-continuity.d.ts +17 -0
- package/dist/identity-continuity.js +19 -0
- package/dist/identity-continuity.js.map +1 -0
- package/dist/importance.d.ts +25 -0
- package/dist/importance.js +11 -0
- package/dist/importance.js.map +1 -0
- package/dist/index.d.ts +923 -0
- package/dist/index.js +2512 -0
- package/dist/index.js.map +1 -0
- package/dist/intent.d.ts +8 -0
- package/dist/intent.js +13 -0
- package/dist/intent.js.map +1 -0
- package/dist/json-extract.d.ts +14 -0
- package/dist/json-extract.js +9 -0
- package/dist/json-extract.js.map +1 -0
- package/dist/json-store.d.ts +5 -0
- package/dist/json-store.js +11 -0
- package/dist/json-store.js.map +1 -0
- package/dist/legacy-hook-compat.d.ts +3 -0
- package/dist/legacy-hook-compat.js +35 -0
- package/dist/legacy-hook-compat.js.map +1 -0
- package/dist/lifecycle.d.ts +52 -0
- package/dist/lifecycle.js +21 -0
- package/dist/lifecycle.js.map +1 -0
- package/dist/local-llm.d.ts +154 -0
- package/dist/local-llm.js +10 -0
- package/dist/local-llm.js.map +1 -0
- package/dist/logger.d.ts +15 -0
- package/dist/logger.js +9 -0
- package/dist/logger.js.map +1 -0
- package/dist/memory-action-policy.d.ts +13 -0
- package/dist/memory-action-policy.js +7 -0
- package/dist/memory-action-policy.js.map +1 -0
- package/dist/memory-cache.d.ts +35 -0
- package/dist/memory-cache.js +37 -0
- package/dist/memory-cache.js.map +1 -0
- package/dist/memory-lifecycle-ledger-utils.d.ts +13 -0
- package/dist/memory-lifecycle-ledger-utils.js +23 -0
- package/dist/memory-lifecycle-ledger-utils.js.map +1 -0
- package/dist/memory-projection-format.d.ts +4 -0
- package/dist/memory-projection-format.js +9 -0
- package/dist/memory-projection-format.js.map +1 -0
- package/dist/memory-projection-store-NxMkbocT.d.ts +221 -0
- package/dist/memory-projection-store.d.ts +3 -0
- package/dist/memory-projection-store.js +31 -0
- package/dist/memory-projection-store.js.map +1 -0
- package/dist/model-registry.d.ts +60 -0
- package/dist/model-registry.js +8 -0
- package/dist/model-registry.js.map +1 -0
- package/dist/native-knowledge.d.ts +94 -0
- package/dist/native-knowledge.js +26 -0
- package/dist/native-knowledge.js.map +1 -0
- package/dist/negative.d.ts +26 -0
- package/dist/negative.js +8 -0
- package/dist/negative.js.map +1 -0
- package/dist/objective-state-writers.d.ts +22 -0
- package/dist/objective-state-writers.js +313 -0
- package/dist/objective-state-writers.js.map +1 -0
- package/dist/objective-state.d.ts +75 -0
- package/dist/objective-state.js +17 -0
- package/dist/objective-state.js.map +1 -0
- package/dist/openai-chat-compat.d.ts +13 -0
- package/dist/openai-chat-compat.js +11 -0
- package/dist/openai-chat-compat.js.map +1 -0
- package/dist/operator-toolkit.d.ts +304 -0
- package/dist/operator-toolkit.js +41 -0
- package/dist/operator-toolkit.js.map +1 -0
- package/dist/opik-exporter.d.ts +72 -0
- package/dist/opik-exporter.js +361 -0
- package/dist/opik-exporter.js.map +1 -0
- package/dist/orchestrator-zTa-Qo-1.d.ts +1104 -0
- package/dist/orchestrator.d.ts +21 -0
- package/dist/orchestrator.js +145 -0
- package/dist/orchestrator.js.map +1 -0
- package/dist/policy-runtime.d.ts +37 -0
- package/dist/policy-runtime.js +13 -0
- package/dist/policy-runtime.js.map +1 -0
- package/dist/port-C1GZFv8h.d.ts +41 -0
- package/dist/profiling.d.ts +80 -0
- package/dist/profiling.js +10 -0
- package/dist/profiling.js.map +1 -0
- package/dist/qmd-recall-cache.d.ts +29 -0
- package/dist/qmd-recall-cache.js +13 -0
- package/dist/qmd-recall-cache.js.map +1 -0
- package/dist/qmd.d.ts +105 -0
- package/dist/qmd.js +13 -0
- package/dist/qmd.js.map +1 -0
- package/dist/recall-qos.d.ts +33 -0
- package/dist/recall-qos.js +10 -0
- package/dist/recall-qos.js.map +1 -0
- package/dist/recall-query-policy.d.ts +20 -0
- package/dist/recall-query-policy.js +11 -0
- package/dist/recall-query-policy.js.map +1 -0
- package/dist/recall-state.d.ts +113 -0
- package/dist/recall-state.js +12 -0
- package/dist/recall-state.js.map +1 -0
- package/dist/recall-tokenization.d.ts +4 -0
- package/dist/recall-tokenization.js +9 -0
- package/dist/recall-tokenization.js.map +1 -0
- package/dist/reconstruct.d.ts +16 -0
- package/dist/reconstruct.js +7 -0
- package/dist/reconstruct.js.map +1 -0
- package/dist/release-changelog.d.ts +7 -0
- package/dist/release-changelog.js +30 -0
- package/dist/release-changelog.js.map +1 -0
- package/dist/relevance.d.ts +18 -0
- package/dist/relevance.js +8 -0
- package/dist/relevance.js.map +1 -0
- package/dist/rerank.d.ts +57 -0
- package/dist/rerank.js +11 -0
- package/dist/rerank.js.map +1 -0
- package/dist/resolve-provider-secret.d.ts +16 -0
- package/dist/resolve-provider-secret.js +11 -0
- package/dist/resolve-provider-secret.js.map +1 -0
- package/dist/resume-bundles.d.ts +66 -0
- package/dist/resume-bundles.js +27 -0
- package/dist/resume-bundles.js.map +1 -0
- package/dist/retrieval-agents.d.ts +129 -0
- package/dist/retrieval-agents.js +23 -0
- package/dist/retrieval-agents.js.map +1 -0
- package/dist/retrieval.d.ts +19 -0
- package/dist/retrieval.js +10 -0
- package/dist/retrieval.js.map +1 -0
- package/dist/sanitize.d.ts +9 -0
- package/dist/sanitize.js +9 -0
- package/dist/sanitize.js.map +1 -0
- package/dist/schemas.d.ts +688 -0
- package/dist/schemas.js +51 -0
- package/dist/schemas.js.map +1 -0
- package/dist/sdk-compat.d.ts +21 -0
- package/dist/sdk-compat.js +28 -0
- package/dist/sdk-compat.js.map +1 -0
- package/dist/semantic-consolidation.d.ts +42 -0
- package/dist/semantic-consolidation.js +12 -0
- package/dist/semantic-consolidation.js.map +1 -0
- package/dist/semantic-rule-promotion.d.ts +28 -0
- package/dist/semantic-rule-promotion.js +17 -0
- package/dist/semantic-rule-promotion.js.map +1 -0
- package/dist/semantic-rule-verifier.d.ts +19 -0
- package/dist/semantic-rule-verifier.js +18 -0
- package/dist/semantic-rule-verifier.js.map +1 -0
- package/dist/session-integrity.d.ts +67 -0
- package/dist/session-integrity.js +11 -0
- package/dist/session-integrity.js.map +1 -0
- package/dist/session-observer-bands.d.ts +6 -0
- package/dist/session-observer-bands.js +9 -0
- package/dist/session-observer-bands.js.map +1 -0
- package/dist/session-observer-state.d.ts +40 -0
- package/dist/session-observer-state.js +11 -0
- package/dist/session-observer-state.js.map +1 -0
- package/dist/signal.d.ts +6 -0
- package/dist/signal.js +9 -0
- package/dist/signal.js.map +1 -0
- package/dist/storage.d.ts +453 -0
- package/dist/storage.js +24 -0
- package/dist/storage.js.map +1 -0
- package/dist/store-contract.d.ts +10 -0
- package/dist/store-contract.js +21 -0
- package/dist/store-contract.js.map +1 -0
- package/dist/summarizer.d.ts +35 -0
- package/dist/summarizer.js +17 -0
- package/dist/summarizer.js.map +1 -0
- package/dist/summary-snapshot.d.ts +8 -0
- package/dist/summary-snapshot.js +13 -0
- package/dist/summary-snapshot.js.map +1 -0
- package/dist/temporal-index.d.ts +139 -0
- package/dist/temporal-index.js +29 -0
- package/dist/temporal-index.js.map +1 -0
- package/dist/threading.d.ts +62 -0
- package/dist/threading.js +8 -0
- package/dist/threading.js.map +1 -0
- package/dist/tier-migration.d.ts +44 -0
- package/dist/tier-migration.js +7 -0
- package/dist/tier-migration.js.map +1 -0
- package/dist/tier-routing.d.ts +21 -0
- package/dist/tier-routing.js +10 -0
- package/dist/tier-routing.js.map +1 -0
- package/dist/tmt.d.ts +79 -0
- package/dist/tmt.js +29 -0
- package/dist/tmt.js.map +1 -0
- package/dist/tokens.d.ts +24 -0
- package/dist/tokens.js +21 -0
- package/dist/tokens.js.map +1 -0
- package/dist/topics.d.ts +29 -0
- package/dist/topics.js +9 -0
- package/dist/topics.js.map +1 -0
- package/dist/transcript.d.ts +171 -0
- package/dist/transcript.js +9 -0
- package/dist/transcript.js.map +1 -0
- package/dist/trust-zones.d.ts +170 -0
- package/dist/trust-zones.js +32 -0
- package/dist/trust-zones.js.map +1 -0
- package/dist/types.d.ts +1243 -0
- package/dist/types.js +9 -0
- package/dist/types.js.map +1 -0
- package/dist/utility-learner.d.ts +59 -0
- package/dist/utility-learner.js +17 -0
- package/dist/utility-learner.js.map +1 -0
- package/dist/utility-runtime.d.ts +21 -0
- package/dist/utility-runtime.js +16 -0
- package/dist/utility-runtime.js.map +1 -0
- package/dist/utility-telemetry.d.ts +68 -0
- package/dist/utility-telemetry.js +17 -0
- package/dist/utility-telemetry.js.map +1 -0
- package/dist/verified-recall.d.ts +17 -0
- package/dist/verified-recall.js +19 -0
- package/dist/verified-recall.js.map +1 -0
- package/dist/version-utils.d.ts +4 -0
- package/dist/version-utils.js +7 -0
- package/dist/version-utils.js.map +1 -0
- package/dist/work-product-ledger.d.ts +65 -0
- package/dist/work-product-ledger.js +18 -0
- package/dist/work-product-ledger.js.map +1 -0
- package/package.json +58 -0
|
@@ -0,0 +1,823 @@
|
|
|
1
|
+
import {
|
|
2
|
+
EngramMcpServer
|
|
3
|
+
} from "./chunk-CXWFUJR2.js";
|
|
4
|
+
import {
|
|
5
|
+
validateRequest
|
|
6
|
+
} from "./chunk-PGK3VUHN.js";
|
|
7
|
+
import {
|
|
8
|
+
EngramAccessInputError
|
|
9
|
+
} from "./chunk-QY2BHY5O.js";
|
|
10
|
+
import {
|
|
11
|
+
isTrustZoneName
|
|
12
|
+
} from "./chunk-EQINRHYR.js";
|
|
13
|
+
import {
|
|
14
|
+
log
|
|
15
|
+
} from "./chunk-KWBU5S5U.js";
|
|
16
|
+
|
|
17
|
+
// src/access-http.ts
|
|
18
|
+
import { createServer } from "http";
|
|
19
|
+
import { randomUUID, timingSafeEqual } from "crypto";
|
|
20
|
+
import { AsyncLocalStorage } from "async_hooks";
|
|
21
|
+
import { existsSync } from "fs";
|
|
22
|
+
import { readFile } from "fs/promises";
|
|
23
|
+
import path from "path";
|
|
24
|
+
import { fileURLToPath, URL } from "url";
|
|
25
|
+
|
|
26
|
+
// src/adapters/types.ts
|
|
27
|
+
function headerValue(headers, key) {
|
|
28
|
+
const raw = headers[key];
|
|
29
|
+
const value = Array.isArray(raw) ? raw[0] : raw;
|
|
30
|
+
return typeof value === "string" && value.trim().length > 0 ? value.trim() : void 0;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
// src/adapters/claude-code.ts
|
|
34
|
+
var ClaudeCodeAdapter = class {
|
|
35
|
+
id = "claude-code";
|
|
36
|
+
matches(context) {
|
|
37
|
+
if (context.clientInfo?.name === "claude-code") return true;
|
|
38
|
+
const ua = headerValue(context.headers, "user-agent");
|
|
39
|
+
if (ua && ua.toLowerCase().startsWith("claude-code/")) return true;
|
|
40
|
+
const clientId = headerValue(context.headers, "x-engram-client-id");
|
|
41
|
+
if (clientId?.toLowerCase() === "claude-code") return true;
|
|
42
|
+
return false;
|
|
43
|
+
}
|
|
44
|
+
resolveIdentity(context) {
|
|
45
|
+
const mcpSessionId = headerValue(context.headers, "mcp-session-id");
|
|
46
|
+
const principal = headerValue(context.headers, "x-engram-principal") || "claude-code";
|
|
47
|
+
const namespace = headerValue(context.headers, "x-engram-namespace") || "claude-code";
|
|
48
|
+
return {
|
|
49
|
+
namespace,
|
|
50
|
+
principal,
|
|
51
|
+
sessionKey: mcpSessionId ?? context.sessionKey,
|
|
52
|
+
adapterId: this.id
|
|
53
|
+
};
|
|
54
|
+
}
|
|
55
|
+
};
|
|
56
|
+
|
|
57
|
+
// src/adapters/codex.ts
|
|
58
|
+
var CodexAdapter = class {
|
|
59
|
+
id = "codex";
|
|
60
|
+
matches(context) {
|
|
61
|
+
if (context.clientInfo?.name === "codex-mcp-client") return true;
|
|
62
|
+
const clientName = context.clientInfo?.name?.toLowerCase() ?? "";
|
|
63
|
+
if (clientName.includes("codex") && clientName !== "codex-mcp-client") return true;
|
|
64
|
+
const clientId = headerValue(context.headers, "x-engram-client-id");
|
|
65
|
+
if (clientId?.toLowerCase() === "codex") return true;
|
|
66
|
+
return false;
|
|
67
|
+
}
|
|
68
|
+
resolveIdentity(context) {
|
|
69
|
+
const mcpSessionId = headerValue(context.headers, "mcp-session-id");
|
|
70
|
+
const principal = headerValue(context.headers, "x-engram-principal") || "codex";
|
|
71
|
+
const namespace = headerValue(context.headers, "x-engram-namespace") || "codex";
|
|
72
|
+
return {
|
|
73
|
+
namespace,
|
|
74
|
+
principal,
|
|
75
|
+
sessionKey: mcpSessionId ?? context.sessionKey,
|
|
76
|
+
adapterId: this.id
|
|
77
|
+
};
|
|
78
|
+
}
|
|
79
|
+
};
|
|
80
|
+
|
|
81
|
+
// src/adapters/replit.ts
|
|
82
|
+
var ReplitAdapter = class {
|
|
83
|
+
id = "replit";
|
|
84
|
+
matches(context) {
|
|
85
|
+
const clientId = headerValue(context.headers, "x-engram-client-id");
|
|
86
|
+
if (clientId?.toLowerCase() === "replit") return true;
|
|
87
|
+
const clientName = context.clientInfo?.name?.toLowerCase() ?? "";
|
|
88
|
+
if (clientName.includes("replit")) return true;
|
|
89
|
+
return false;
|
|
90
|
+
}
|
|
91
|
+
resolveIdentity(context) {
|
|
92
|
+
const mcpSessionId = headerValue(context.headers, "mcp-session-id");
|
|
93
|
+
const principal = headerValue(context.headers, "x-engram-principal") || "replit-agent";
|
|
94
|
+
const namespace = headerValue(context.headers, "x-engram-namespace") || "replit";
|
|
95
|
+
return {
|
|
96
|
+
namespace,
|
|
97
|
+
principal,
|
|
98
|
+
sessionKey: mcpSessionId ?? context.sessionKey,
|
|
99
|
+
adapterId: this.id
|
|
100
|
+
};
|
|
101
|
+
}
|
|
102
|
+
};
|
|
103
|
+
|
|
104
|
+
// src/adapters/hermes.ts
|
|
105
|
+
var HermesAdapter = class {
|
|
106
|
+
id = "hermes";
|
|
107
|
+
matches(context) {
|
|
108
|
+
if (headerValue(context.headers, "x-hermes-session-id")) return true;
|
|
109
|
+
const clientId = headerValue(context.headers, "x-engram-client-id");
|
|
110
|
+
if (clientId?.toLowerCase() === "hermes") return true;
|
|
111
|
+
const clientName = context.clientInfo?.name?.toLowerCase() ?? "";
|
|
112
|
+
if (clientName.includes("hermes")) return true;
|
|
113
|
+
return false;
|
|
114
|
+
}
|
|
115
|
+
resolveIdentity(context) {
|
|
116
|
+
const sessionId = headerValue(context.headers, "x-hermes-session-id");
|
|
117
|
+
const principal = headerValue(context.headers, "x-engram-principal") || "hermes-agent";
|
|
118
|
+
const namespace = headerValue(context.headers, "x-engram-namespace") || "hermes";
|
|
119
|
+
return {
|
|
120
|
+
namespace,
|
|
121
|
+
principal,
|
|
122
|
+
sessionKey: sessionId ?? context.sessionKey,
|
|
123
|
+
adapterId: this.id
|
|
124
|
+
};
|
|
125
|
+
}
|
|
126
|
+
};
|
|
127
|
+
|
|
128
|
+
// src/adapters/registry.ts
|
|
129
|
+
var AdapterRegistry = class {
|
|
130
|
+
adapters;
|
|
131
|
+
constructor(adapters) {
|
|
132
|
+
this.adapters = adapters ?? [
|
|
133
|
+
new HermesAdapter(),
|
|
134
|
+
new ReplitAdapter(),
|
|
135
|
+
new CodexAdapter(),
|
|
136
|
+
new ClaudeCodeAdapter()
|
|
137
|
+
];
|
|
138
|
+
}
|
|
139
|
+
/**
|
|
140
|
+
* Try each adapter in order. Return the first match, or null if
|
|
141
|
+
* no adapter recognizes the request context.
|
|
142
|
+
*/
|
|
143
|
+
resolve(context) {
|
|
144
|
+
for (const adapter of this.adapters) {
|
|
145
|
+
if (adapter.matches(context)) {
|
|
146
|
+
return adapter.resolveIdentity(context);
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
return null;
|
|
150
|
+
}
|
|
151
|
+
/** List registered adapter IDs */
|
|
152
|
+
list() {
|
|
153
|
+
return this.adapters.map((a) => a.id);
|
|
154
|
+
}
|
|
155
|
+
};
|
|
156
|
+
|
|
157
|
+
// src/access-http.ts
|
|
158
|
+
function resolveDefaultAdminConsolePublicDir() {
|
|
159
|
+
const candidates = [
|
|
160
|
+
fileURLToPath(new URL("../admin-console/public", import.meta.url)),
|
|
161
|
+
fileURLToPath(new URL("./admin-console/public", import.meta.url))
|
|
162
|
+
];
|
|
163
|
+
return candidates.find((candidate) => existsSync(candidate)) ?? candidates[0];
|
|
164
|
+
}
|
|
165
|
+
var defaultAdminConsolePublicDir = resolveDefaultAdminConsolePublicDir();
|
|
166
|
+
var correlationIdStore = new AsyncLocalStorage();
|
|
167
|
+
var WRITE_RATE_LIMIT_WINDOW_MS = 6e4;
|
|
168
|
+
var WRITE_RATE_LIMIT_MAX_REQUESTS = 30;
|
|
169
|
+
var TRUST_ZONE_RECORD_KINDS = ["memory", "artifact", "state", "trajectory", "external"];
|
|
170
|
+
var TRUST_ZONE_SOURCE_CLASSES = ["tool_output", "web_content", "subagent_trace", "system_memory", "user_input", "manual"];
|
|
171
|
+
var HttpError = class extends Error {
|
|
172
|
+
constructor(status, message, code, details) {
|
|
173
|
+
super(message);
|
|
174
|
+
this.status = status;
|
|
175
|
+
this.code = code ?? `http_${status}`;
|
|
176
|
+
this.details = details;
|
|
177
|
+
}
|
|
178
|
+
status;
|
|
179
|
+
code;
|
|
180
|
+
details;
|
|
181
|
+
};
|
|
182
|
+
function hostToUrlAuthority(host) {
|
|
183
|
+
if (host.includes(":") && !host.startsWith("[") && !host.endsWith("]")) {
|
|
184
|
+
return `[${host}]`;
|
|
185
|
+
}
|
|
186
|
+
return host;
|
|
187
|
+
}
|
|
188
|
+
function parseTrustZoneKindFilter(raw) {
|
|
189
|
+
if (raw === null) return void 0;
|
|
190
|
+
if (TRUST_ZONE_RECORD_KINDS.includes(raw)) {
|
|
191
|
+
return raw;
|
|
192
|
+
}
|
|
193
|
+
throw new HttpError(400, `kind must be one of ${TRUST_ZONE_RECORD_KINDS.join("|")}`, "invalid_kind_filter");
|
|
194
|
+
}
|
|
195
|
+
function parseTrustZoneSourceClassFilter(raw) {
|
|
196
|
+
if (raw === null) return void 0;
|
|
197
|
+
if (TRUST_ZONE_SOURCE_CLASSES.includes(raw)) {
|
|
198
|
+
return raw;
|
|
199
|
+
}
|
|
200
|
+
throw new HttpError(400, `sourceClass must be one of ${TRUST_ZONE_SOURCE_CLASSES.join("|")}`, "invalid_source_class_filter");
|
|
201
|
+
}
|
|
202
|
+
function parseTrustZoneFilter(raw) {
|
|
203
|
+
if (raw === null) return void 0;
|
|
204
|
+
if (isTrustZoneName(raw)) {
|
|
205
|
+
return raw;
|
|
206
|
+
}
|
|
207
|
+
throw new HttpError(400, "zone must be one of quarantine|working|trusted", "invalid_zone_filter");
|
|
208
|
+
}
|
|
209
|
+
var EngramAccessHttpServer = class {
|
|
210
|
+
service;
|
|
211
|
+
host;
|
|
212
|
+
requestedPort;
|
|
213
|
+
authToken;
|
|
214
|
+
authTokens;
|
|
215
|
+
authTokensGetter;
|
|
216
|
+
authenticatedPrincipal;
|
|
217
|
+
maxBodyBytes;
|
|
218
|
+
adminConsoleEnabled;
|
|
219
|
+
adminConsolePublicDir;
|
|
220
|
+
trustPrincipalHeader;
|
|
221
|
+
adapterRegistry;
|
|
222
|
+
writeRequestTimestamps = [];
|
|
223
|
+
mcpServer;
|
|
224
|
+
server = null;
|
|
225
|
+
boundPort = 0;
|
|
226
|
+
constructor(options) {
|
|
227
|
+
this.service = options.service;
|
|
228
|
+
this.host = options.host?.trim() || "127.0.0.1";
|
|
229
|
+
this.requestedPort = Number.isFinite(options.port) ? Math.max(0, Math.floor(options.port ?? 0)) : 0;
|
|
230
|
+
this.authToken = options.authToken?.trim() || void 0;
|
|
231
|
+
this.authTokens = (options.authTokens ?? []).map((t) => t.trim()).filter(Boolean);
|
|
232
|
+
this.authTokensGetter = options.authTokensGetter;
|
|
233
|
+
this.authenticatedPrincipal = options.principal?.trim() || void 0;
|
|
234
|
+
this.maxBodyBytes = Number.isFinite(options.maxBodyBytes) ? Math.max(1, Math.floor(options.maxBodyBytes ?? 131072)) : 131072;
|
|
235
|
+
this.adminConsoleEnabled = options.adminConsoleEnabled !== false;
|
|
236
|
+
this.adminConsolePublicDir = options.adminConsolePublicDir ?? defaultAdminConsolePublicDir;
|
|
237
|
+
this.trustPrincipalHeader = options.trustPrincipalHeader === true;
|
|
238
|
+
this.adapterRegistry = options.enableAdapters !== false ? options.adapterRegistry ?? new AdapterRegistry() : null;
|
|
239
|
+
this.mcpServer = new EngramMcpServer(this.service, { principal: options.principal });
|
|
240
|
+
}
|
|
241
|
+
async start() {
|
|
242
|
+
if (!this.authToken && this.authTokens.length === 0 && !this.authTokensGetter) {
|
|
243
|
+
throw new Error("engram access HTTP requires authToken or authTokens");
|
|
244
|
+
}
|
|
245
|
+
if (this.server) return this.status();
|
|
246
|
+
const server = createServer((req, res) => {
|
|
247
|
+
const correlationId = randomUUID();
|
|
248
|
+
correlationIdStore.run(correlationId, () => {
|
|
249
|
+
void this.handle(req, res, correlationId).catch((err) => {
|
|
250
|
+
log.debug(`engram access HTTP request failed [${correlationId}]: ${err}`);
|
|
251
|
+
if (err instanceof HttpError) {
|
|
252
|
+
const payload = { error: err.message, code: err.code };
|
|
253
|
+
if (err.details) payload.details = err.details;
|
|
254
|
+
this.respondJson(res, err.status, payload);
|
|
255
|
+
return;
|
|
256
|
+
}
|
|
257
|
+
if (err instanceof EngramAccessInputError) {
|
|
258
|
+
this.respondJson(res, 400, { error: err.message, code: "input_error" });
|
|
259
|
+
return;
|
|
260
|
+
}
|
|
261
|
+
if (res.headersSent) {
|
|
262
|
+
res.destroy(err);
|
|
263
|
+
return;
|
|
264
|
+
}
|
|
265
|
+
this.respondJson(res, 500, { error: "internal_error", code: "internal_error" });
|
|
266
|
+
});
|
|
267
|
+
});
|
|
268
|
+
});
|
|
269
|
+
try {
|
|
270
|
+
await new Promise((resolve, reject) => {
|
|
271
|
+
const onError = (err) => {
|
|
272
|
+
server.off("listening", onListening);
|
|
273
|
+
reject(err);
|
|
274
|
+
};
|
|
275
|
+
const onListening = () => {
|
|
276
|
+
server.off("error", onError);
|
|
277
|
+
resolve();
|
|
278
|
+
};
|
|
279
|
+
server.once("error", onError);
|
|
280
|
+
server.once("listening", onListening);
|
|
281
|
+
server.listen(this.requestedPort, this.host);
|
|
282
|
+
});
|
|
283
|
+
} catch (err) {
|
|
284
|
+
server.close();
|
|
285
|
+
throw err;
|
|
286
|
+
}
|
|
287
|
+
this.server = server;
|
|
288
|
+
const address = server.address();
|
|
289
|
+
this.boundPort = typeof address === "object" && address ? address.port : this.requestedPort;
|
|
290
|
+
return this.status();
|
|
291
|
+
}
|
|
292
|
+
async stop() {
|
|
293
|
+
if (!this.server) return;
|
|
294
|
+
const server = this.server;
|
|
295
|
+
this.server = null;
|
|
296
|
+
this.boundPort = 0;
|
|
297
|
+
await new Promise((resolve, reject) => {
|
|
298
|
+
server.close((err) => err ? reject(err) : resolve());
|
|
299
|
+
});
|
|
300
|
+
}
|
|
301
|
+
status() {
|
|
302
|
+
return {
|
|
303
|
+
running: this.server !== null,
|
|
304
|
+
host: this.host,
|
|
305
|
+
port: this.boundPort,
|
|
306
|
+
maxBodyBytes: this.maxBodyBytes
|
|
307
|
+
};
|
|
308
|
+
}
|
|
309
|
+
/**
|
|
310
|
+
* Resolve the adapter identity for the incoming request.
|
|
311
|
+
* Includes MCP clientInfo from the last initialize handshake if available.
|
|
312
|
+
* Returns null if no adapter matches or adapters are disabled.
|
|
313
|
+
*/
|
|
314
|
+
resolveAdapterIdentity(req) {
|
|
315
|
+
if (!this.adapterRegistry) return null;
|
|
316
|
+
const sessionId = (() => {
|
|
317
|
+
const raw = req.headers["mcp-session-id"];
|
|
318
|
+
return typeof raw === "string" ? raw.trim() : void 0;
|
|
319
|
+
})();
|
|
320
|
+
return this.adapterRegistry.resolve({
|
|
321
|
+
headers: req.headers,
|
|
322
|
+
clientInfo: this.mcpServer.getClientInfo(sessionId)
|
|
323
|
+
});
|
|
324
|
+
}
|
|
325
|
+
/** Cache for per-request identity resolution (avoids double adapter resolution) */
|
|
326
|
+
identityCache = /* @__PURE__ */ new WeakMap();
|
|
327
|
+
/** Resolve principal and namespace from request headers and adapter identity */
|
|
328
|
+
resolveRequestIdentity(req) {
|
|
329
|
+
const cached = this.identityCache.get(req);
|
|
330
|
+
if (cached) return cached;
|
|
331
|
+
let principal;
|
|
332
|
+
let namespace;
|
|
333
|
+
if (this.trustPrincipalHeader) {
|
|
334
|
+
const headerVal = req.headers["x-engram-principal"];
|
|
335
|
+
const raw = Array.isArray(headerVal) ? headerVal[0] : headerVal;
|
|
336
|
+
if (typeof raw === "string") {
|
|
337
|
+
const trimmed = raw.trim();
|
|
338
|
+
if (trimmed.length > 0) {
|
|
339
|
+
principal = trimmed;
|
|
340
|
+
}
|
|
341
|
+
}
|
|
342
|
+
}
|
|
343
|
+
const adapterIdentity = this.resolveAdapterIdentity(req);
|
|
344
|
+
if (adapterIdentity) {
|
|
345
|
+
if (!principal) {
|
|
346
|
+
principal = adapterIdentity.principal;
|
|
347
|
+
}
|
|
348
|
+
namespace = adapterIdentity.namespace;
|
|
349
|
+
}
|
|
350
|
+
if (!principal) {
|
|
351
|
+
principal = this.authenticatedPrincipal;
|
|
352
|
+
}
|
|
353
|
+
const result = { principal, namespace };
|
|
354
|
+
this.identityCache.set(req, result);
|
|
355
|
+
return result;
|
|
356
|
+
}
|
|
357
|
+
resolveRequestPrincipal(req) {
|
|
358
|
+
return this.resolveRequestIdentity(req).principal;
|
|
359
|
+
}
|
|
360
|
+
/** Resolve namespace: only use the explicit body value. Adapter-inferred namespace
|
|
361
|
+
* is intentionally NOT used as a fallback for REST requests — omitting namespace
|
|
362
|
+
* should default to the server's global namespace, not silently scope to an adapter. */
|
|
363
|
+
resolveNamespace(_req, bodyNamespace) {
|
|
364
|
+
return bodyNamespace || void 0;
|
|
365
|
+
}
|
|
366
|
+
async handle(req, res, correlationId) {
|
|
367
|
+
const parsed = new URL(req.url ?? "/", `http://${hostToUrlAuthority(this.host)}`);
|
|
368
|
+
const pathname = parsed.pathname;
|
|
369
|
+
if (this.adminConsoleEnabled && await this.handleAdminConsole(req, res, pathname)) {
|
|
370
|
+
return;
|
|
371
|
+
}
|
|
372
|
+
if (!this.isAuthorized(req)) {
|
|
373
|
+
const body = JSON.stringify({ error: "unauthorized", code: "unauthorized" });
|
|
374
|
+
res.writeHead(401, {
|
|
375
|
+
"content-type": "application/json; charset=utf-8",
|
|
376
|
+
"www-authenticate": "Bearer",
|
|
377
|
+
"x-request-id": correlationId
|
|
378
|
+
});
|
|
379
|
+
res.end(body);
|
|
380
|
+
return;
|
|
381
|
+
}
|
|
382
|
+
if (req.method === "POST" && pathname === "/mcp") {
|
|
383
|
+
await this.handleMcpRequest(req, res);
|
|
384
|
+
return;
|
|
385
|
+
}
|
|
386
|
+
if (req.method === "GET" && pathname === "/engram/v1/health") {
|
|
387
|
+
this.respondJson(res, 200, await this.service.health());
|
|
388
|
+
return;
|
|
389
|
+
}
|
|
390
|
+
if (req.method === "GET" && pathname === "/engram/v1/adapters") {
|
|
391
|
+
const identity = this.resolveAdapterIdentity(req);
|
|
392
|
+
this.respondJson(res, 200, {
|
|
393
|
+
adaptersEnabled: this.adapterRegistry !== null,
|
|
394
|
+
registered: this.adapterRegistry?.list() ?? [],
|
|
395
|
+
resolved: identity
|
|
396
|
+
});
|
|
397
|
+
return;
|
|
398
|
+
}
|
|
399
|
+
if (req.method === "POST" && pathname === "/engram/v1/recall") {
|
|
400
|
+
const body = await this.readValidatedBody(req, "recall");
|
|
401
|
+
const response = await this.service.recall({
|
|
402
|
+
query: body.query ?? "",
|
|
403
|
+
sessionKey: body.sessionKey,
|
|
404
|
+
namespace: this.resolveNamespace(req, body.namespace),
|
|
405
|
+
topK: body.topK,
|
|
406
|
+
mode: body.mode,
|
|
407
|
+
includeDebug: body.includeDebug === true
|
|
408
|
+
});
|
|
409
|
+
this.respondJson(res, 200, response);
|
|
410
|
+
return;
|
|
411
|
+
}
|
|
412
|
+
if (req.method === "POST" && pathname === "/engram/v1/recall/explain") {
|
|
413
|
+
const body = await this.readValidatedBody(req, "recallExplain");
|
|
414
|
+
const response = await this.service.recallExplain({
|
|
415
|
+
sessionKey: body.sessionKey,
|
|
416
|
+
namespace: this.resolveNamespace(req, body.namespace)
|
|
417
|
+
});
|
|
418
|
+
this.respondJson(res, 200, response);
|
|
419
|
+
return;
|
|
420
|
+
}
|
|
421
|
+
if (req.method === "POST" && pathname === "/engram/v1/observe") {
|
|
422
|
+
const body = await this.readValidatedBody(req, "observe");
|
|
423
|
+
this.ensureWriteRateLimitAvailable();
|
|
424
|
+
const response = await this.service.observe({
|
|
425
|
+
sessionKey: body.sessionKey,
|
|
426
|
+
messages: body.messages,
|
|
427
|
+
namespace: this.resolveNamespace(req, body.namespace),
|
|
428
|
+
authenticatedPrincipal: this.resolveRequestPrincipal(req),
|
|
429
|
+
skipExtraction: body.skipExtraction === true
|
|
430
|
+
});
|
|
431
|
+
this.recordWriteRateLimitHit();
|
|
432
|
+
this.respondJson(res, 202, response);
|
|
433
|
+
return;
|
|
434
|
+
}
|
|
435
|
+
if (req.method === "POST" && pathname === "/engram/v1/lcm/search") {
|
|
436
|
+
const body = await this.readValidatedBody(req, "lcmSearch");
|
|
437
|
+
const response = await this.service.lcmSearch({
|
|
438
|
+
query: body.query,
|
|
439
|
+
sessionKey: body.sessionKey,
|
|
440
|
+
namespace: this.resolveNamespace(req, body.namespace),
|
|
441
|
+
authenticatedPrincipal: this.resolveRequestPrincipal(req),
|
|
442
|
+
limit: body.limit
|
|
443
|
+
});
|
|
444
|
+
this.respondJson(res, 200, response);
|
|
445
|
+
return;
|
|
446
|
+
}
|
|
447
|
+
if (req.method === "GET" && pathname === "/engram/v1/lcm/status") {
|
|
448
|
+
this.respondJson(res, 200, await this.service.lcmStatus());
|
|
449
|
+
return;
|
|
450
|
+
}
|
|
451
|
+
if (req.method === "POST" && pathname === "/engram/v1/memories") {
|
|
452
|
+
const body = await this.readValidatedBody(req, "memoryStore");
|
|
453
|
+
const request = {
|
|
454
|
+
schemaVersion: body.schemaVersion,
|
|
455
|
+
idempotencyKey: body.idempotencyKey,
|
|
456
|
+
dryRun: body.dryRun === true,
|
|
457
|
+
sessionKey: body.sessionKey,
|
|
458
|
+
authenticatedPrincipal: this.resolveRequestPrincipal(req),
|
|
459
|
+
content: body.content,
|
|
460
|
+
category: body.category,
|
|
461
|
+
confidence: body.confidence,
|
|
462
|
+
namespace: this.resolveNamespace(req, body.namespace),
|
|
463
|
+
tags: body.tags,
|
|
464
|
+
entityRef: body.entityRef,
|
|
465
|
+
ttl: body.ttl,
|
|
466
|
+
sourceReason: body.sourceReason
|
|
467
|
+
};
|
|
468
|
+
const idempotencyStatus = await this.service.peekMemoryStoreIdempotency(request);
|
|
469
|
+
if (idempotencyStatus === "miss" && request.dryRun !== true) {
|
|
470
|
+
this.ensureWriteRateLimitAvailable();
|
|
471
|
+
}
|
|
472
|
+
const response = await this.service.memoryStore(request);
|
|
473
|
+
if (this.shouldCountWriteRateLimit(response)) {
|
|
474
|
+
this.recordWriteRateLimitHit();
|
|
475
|
+
}
|
|
476
|
+
this.respondJson(res, this.writeResponseStatus(response), response);
|
|
477
|
+
return;
|
|
478
|
+
}
|
|
479
|
+
if (req.method === "POST" && pathname === "/engram/v1/suggestions") {
|
|
480
|
+
const body = await this.readValidatedBody(req, "suggestionSubmit");
|
|
481
|
+
const request = {
|
|
482
|
+
schemaVersion: body.schemaVersion,
|
|
483
|
+
idempotencyKey: body.idempotencyKey,
|
|
484
|
+
dryRun: body.dryRun === true,
|
|
485
|
+
sessionKey: body.sessionKey,
|
|
486
|
+
authenticatedPrincipal: this.resolveRequestPrincipal(req),
|
|
487
|
+
content: body.content,
|
|
488
|
+
category: body.category,
|
|
489
|
+
confidence: body.confidence,
|
|
490
|
+
namespace: this.resolveNamespace(req, body.namespace),
|
|
491
|
+
tags: body.tags,
|
|
492
|
+
entityRef: body.entityRef,
|
|
493
|
+
ttl: body.ttl,
|
|
494
|
+
sourceReason: body.sourceReason
|
|
495
|
+
};
|
|
496
|
+
const idempotencyStatus = await this.service.peekSuggestionSubmitIdempotency(request);
|
|
497
|
+
if (idempotencyStatus === "miss" && request.dryRun !== true) {
|
|
498
|
+
this.ensureWriteRateLimitAvailable();
|
|
499
|
+
}
|
|
500
|
+
const response = await this.service.suggestionSubmit(request);
|
|
501
|
+
if (this.shouldCountWriteRateLimit(response)) {
|
|
502
|
+
this.recordWriteRateLimitHit();
|
|
503
|
+
}
|
|
504
|
+
this.respondJson(res, this.writeResponseStatus(response), response);
|
|
505
|
+
return;
|
|
506
|
+
}
|
|
507
|
+
if (req.method === "GET" && pathname === "/engram/v1/memories") {
|
|
508
|
+
const limitRaw = parseInt(parsed.searchParams.get("limit") ?? "50", 10);
|
|
509
|
+
const offsetRaw = parseInt(parsed.searchParams.get("offset") ?? "0", 10);
|
|
510
|
+
const sortParam = parsed.searchParams.get("sort") ?? void 0;
|
|
511
|
+
const sort = sortParam === "updated_desc" || sortParam === "updated_asc" || sortParam === "created_desc" || sortParam === "created_asc" ? sortParam : void 0;
|
|
512
|
+
const response = await this.service.memoryBrowse({
|
|
513
|
+
query: parsed.searchParams.get("q") ?? void 0,
|
|
514
|
+
status: parsed.searchParams.get("status") ?? void 0,
|
|
515
|
+
category: parsed.searchParams.get("category") ?? void 0,
|
|
516
|
+
namespace: parsed.searchParams.get("namespace") ?? void 0,
|
|
517
|
+
sort,
|
|
518
|
+
limit: Number.isFinite(limitRaw) ? limitRaw : 50,
|
|
519
|
+
offset: Number.isFinite(offsetRaw) ? offsetRaw : 0
|
|
520
|
+
});
|
|
521
|
+
this.respondJson(res, 200, response);
|
|
522
|
+
return;
|
|
523
|
+
}
|
|
524
|
+
const memoryMatch = pathname.match(/^\/engram\/v1\/memories\/([^/]+)$/);
|
|
525
|
+
if (req.method === "GET" && memoryMatch) {
|
|
526
|
+
const memoryId = decodeURIComponent(memoryMatch[1] ?? "");
|
|
527
|
+
const namespace = parsed.searchParams.get("namespace") ?? void 0;
|
|
528
|
+
const response = await this.service.memoryGet(memoryId, namespace, this.resolveRequestPrincipal(req));
|
|
529
|
+
this.respondJson(res, response.found ? 200 : 404, response);
|
|
530
|
+
return;
|
|
531
|
+
}
|
|
532
|
+
const timelineMatch = pathname.match(/^\/engram\/v1\/memories\/([^/]+)\/timeline$/);
|
|
533
|
+
if (req.method === "GET" && timelineMatch) {
|
|
534
|
+
const memoryId = decodeURIComponent(timelineMatch[1] ?? "");
|
|
535
|
+
const namespace = parsed.searchParams.get("namespace") ?? void 0;
|
|
536
|
+
const limitRaw = parseInt(parsed.searchParams.get("limit") ?? "200", 10);
|
|
537
|
+
const limit = Number.isFinite(limitRaw) ? limitRaw : 200;
|
|
538
|
+
const response = await this.service.memoryTimeline(memoryId, namespace, limit, this.resolveRequestPrincipal(req));
|
|
539
|
+
this.respondJson(res, response.found ? 200 : 404, response);
|
|
540
|
+
return;
|
|
541
|
+
}
|
|
542
|
+
if (req.method === "GET" && pathname === "/engram/v1/entities") {
|
|
543
|
+
const limitRaw = parseInt(parsed.searchParams.get("limit") ?? "50", 10);
|
|
544
|
+
const offsetRaw = parseInt(parsed.searchParams.get("offset") ?? "0", 10);
|
|
545
|
+
const response = await this.service.entityList({
|
|
546
|
+
namespace: parsed.searchParams.get("namespace") ?? void 0,
|
|
547
|
+
query: parsed.searchParams.get("q") ?? void 0,
|
|
548
|
+
limit: Number.isFinite(limitRaw) ? limitRaw : 50,
|
|
549
|
+
offset: Number.isFinite(offsetRaw) ? offsetRaw : 0
|
|
550
|
+
});
|
|
551
|
+
this.respondJson(res, 200, response);
|
|
552
|
+
return;
|
|
553
|
+
}
|
|
554
|
+
const entityMatch = pathname.match(/^\/engram\/v1\/entities\/([^/]+)$/);
|
|
555
|
+
if (req.method === "GET" && entityMatch) {
|
|
556
|
+
const entityName = decodeURIComponent(entityMatch[1] ?? "");
|
|
557
|
+
const namespace = parsed.searchParams.get("namespace") ?? void 0;
|
|
558
|
+
const response = await this.service.entityGet(entityName, namespace);
|
|
559
|
+
this.respondJson(res, response.found ? 200 : 404, response);
|
|
560
|
+
return;
|
|
561
|
+
}
|
|
562
|
+
if (req.method === "GET" && pathname === "/engram/v1/review-queue") {
|
|
563
|
+
const response = await this.service.reviewQueue(
|
|
564
|
+
parsed.searchParams.get("runId") ?? void 0,
|
|
565
|
+
parsed.searchParams.get("namespace") ?? void 0,
|
|
566
|
+
this.resolveRequestPrincipal(req)
|
|
567
|
+
);
|
|
568
|
+
this.respondJson(res, 200, response);
|
|
569
|
+
return;
|
|
570
|
+
}
|
|
571
|
+
if (req.method === "GET" && pathname === "/engram/v1/maintenance") {
|
|
572
|
+
this.respondJson(res, 200, await this.service.maintenance(parsed.searchParams.get("namespace") ?? void 0, this.resolveRequestPrincipal(req)));
|
|
573
|
+
return;
|
|
574
|
+
}
|
|
575
|
+
if (req.method === "GET" && pathname === "/engram/v1/quality") {
|
|
576
|
+
this.respondJson(res, 200, await this.service.quality(parsed.searchParams.get("namespace") ?? void 0, this.resolveRequestPrincipal(req)));
|
|
577
|
+
return;
|
|
578
|
+
}
|
|
579
|
+
if (req.method === "GET" && pathname === "/engram/v1/trust-zones/status") {
|
|
580
|
+
this.respondJson(
|
|
581
|
+
res,
|
|
582
|
+
200,
|
|
583
|
+
await this.service.trustZoneStatus(parsed.searchParams.get("namespace") ?? void 0, this.resolveRequestPrincipal(req))
|
|
584
|
+
);
|
|
585
|
+
return;
|
|
586
|
+
}
|
|
587
|
+
if (req.method === "GET" && pathname === "/engram/v1/trust-zones/records") {
|
|
588
|
+
const limitRaw = parseInt(parsed.searchParams.get("limit") ?? "25", 10);
|
|
589
|
+
const offsetRaw = parseInt(parsed.searchParams.get("offset") ?? "0", 10);
|
|
590
|
+
const response = await this.service.trustZoneBrowse({
|
|
591
|
+
query: parsed.searchParams.get("q") ?? void 0,
|
|
592
|
+
zone: parseTrustZoneFilter(parsed.searchParams.get("zone")),
|
|
593
|
+
kind: parseTrustZoneKindFilter(parsed.searchParams.get("kind")),
|
|
594
|
+
sourceClass: parseTrustZoneSourceClassFilter(parsed.searchParams.get("sourceClass")),
|
|
595
|
+
namespace: parsed.searchParams.get("namespace") ?? void 0,
|
|
596
|
+
limit: Number.isFinite(limitRaw) ? limitRaw : 25,
|
|
597
|
+
offset: Number.isFinite(offsetRaw) ? offsetRaw : 0
|
|
598
|
+
}, this.resolveRequestPrincipal(req));
|
|
599
|
+
this.respondJson(res, 200, response);
|
|
600
|
+
return;
|
|
601
|
+
}
|
|
602
|
+
if (req.method === "POST" && pathname === "/engram/v1/review-disposition") {
|
|
603
|
+
const body = await this.readValidatedBody(req, "reviewDisposition");
|
|
604
|
+
this.ensureWriteRateLimitAvailable();
|
|
605
|
+
const response = await this.service.reviewDisposition({
|
|
606
|
+
memoryId: body.memoryId,
|
|
607
|
+
status: body.status,
|
|
608
|
+
reasonCode: body.reasonCode,
|
|
609
|
+
namespace: this.resolveNamespace(req, body.namespace),
|
|
610
|
+
authenticatedPrincipal: this.resolveRequestPrincipal(req)
|
|
611
|
+
});
|
|
612
|
+
if (this.shouldCountWriteRateLimit(response)) {
|
|
613
|
+
this.recordWriteRateLimitHit();
|
|
614
|
+
}
|
|
615
|
+
this.respondJson(res, 200, response);
|
|
616
|
+
return;
|
|
617
|
+
}
|
|
618
|
+
if (req.method === "POST" && pathname === "/engram/v1/trust-zones/promote") {
|
|
619
|
+
const body = await this.readValidatedBody(req, "trustZonePromote");
|
|
620
|
+
const dryRun = body.dryRun === true;
|
|
621
|
+
if (!dryRun) {
|
|
622
|
+
this.ensureWriteRateLimitAvailable();
|
|
623
|
+
}
|
|
624
|
+
const response = await this.service.trustZonePromote({
|
|
625
|
+
recordId: body.recordId,
|
|
626
|
+
targetZone: body.targetZone,
|
|
627
|
+
promotionReason: body.promotionReason,
|
|
628
|
+
recordedAt: body.recordedAt,
|
|
629
|
+
summary: body.summary,
|
|
630
|
+
dryRun,
|
|
631
|
+
namespace: this.resolveNamespace(req, body.namespace),
|
|
632
|
+
authenticatedPrincipal: this.resolveRequestPrincipal(req)
|
|
633
|
+
});
|
|
634
|
+
if (this.shouldCountWriteRateLimit(response)) {
|
|
635
|
+
this.recordWriteRateLimitHit();
|
|
636
|
+
}
|
|
637
|
+
this.respondJson(res, response.dryRun ? 200 : 201, response);
|
|
638
|
+
return;
|
|
639
|
+
}
|
|
640
|
+
if (req.method === "POST" && pathname === "/engram/v1/trust-zones/demo-seed") {
|
|
641
|
+
const body = await this.readValidatedBody(req, "trustZoneDemoSeed");
|
|
642
|
+
const dryRun = body.dryRun === true;
|
|
643
|
+
if (!dryRun) {
|
|
644
|
+
this.ensureWriteRateLimitAvailable();
|
|
645
|
+
}
|
|
646
|
+
const response = await this.service.trustZoneDemoSeed({
|
|
647
|
+
scenario: body.scenario,
|
|
648
|
+
recordedAt: body.recordedAt,
|
|
649
|
+
dryRun,
|
|
650
|
+
namespace: this.resolveNamespace(req, body.namespace),
|
|
651
|
+
authenticatedPrincipal: this.resolveRequestPrincipal(req)
|
|
652
|
+
});
|
|
653
|
+
if (this.shouldCountWriteRateLimit(response)) {
|
|
654
|
+
this.recordWriteRateLimitHit();
|
|
655
|
+
}
|
|
656
|
+
this.respondJson(res, response.dryRun ? 200 : 201, response);
|
|
657
|
+
return;
|
|
658
|
+
}
|
|
659
|
+
this.respondJson(res, 404, { error: "not_found", code: "not_found" });
|
|
660
|
+
}
|
|
661
|
+
async handleMcpRequest(req, res) {
|
|
662
|
+
const body = await this.readJsonBody(req);
|
|
663
|
+
const request = body;
|
|
664
|
+
const isMcpWrite = request.method === "tools/call" && typeof request.params?.name === "string" && (request.params.name === "engram.memory_store" || request.params.name === "engram.suggestion_submit" || request.params.name === "engram.observe");
|
|
665
|
+
if (isMcpWrite) {
|
|
666
|
+
this.ensureWriteRateLimitAvailable();
|
|
667
|
+
}
|
|
668
|
+
const sessionId = (() => {
|
|
669
|
+
const raw = req.headers["mcp-session-id"];
|
|
670
|
+
return typeof raw === "string" ? raw.trim() : void 0;
|
|
671
|
+
})();
|
|
672
|
+
const mcpCorrelationId = correlationIdStore.getStore() ?? randomUUID();
|
|
673
|
+
const response = await this.mcpServer.handleRequest(request, {
|
|
674
|
+
principalOverride: this.resolveRequestPrincipal(req),
|
|
675
|
+
sessionId,
|
|
676
|
+
correlationId: mcpCorrelationId
|
|
677
|
+
});
|
|
678
|
+
if (isMcpWrite && response !== null) {
|
|
679
|
+
const result = response.result;
|
|
680
|
+
const isError = result?.isError === true;
|
|
681
|
+
const structured = result?.structuredContent;
|
|
682
|
+
if (!isError && structured && this.shouldCountWriteRateLimit(structured)) {
|
|
683
|
+
this.recordWriteRateLimitHit();
|
|
684
|
+
}
|
|
685
|
+
}
|
|
686
|
+
if (response === null) {
|
|
687
|
+
res.statusCode = 202;
|
|
688
|
+
res.end();
|
|
689
|
+
return;
|
|
690
|
+
}
|
|
691
|
+
const assignedSessionId = this.mcpServer.popInitSessionId(mcpCorrelationId);
|
|
692
|
+
if (assignedSessionId) {
|
|
693
|
+
res.setHeader("mcp-session-id", assignedSessionId);
|
|
694
|
+
}
|
|
695
|
+
this.respondJson(res, 200, response);
|
|
696
|
+
}
|
|
697
|
+
respondJson(res, status, payload) {
|
|
698
|
+
const body = JSON.stringify(payload, null, 2);
|
|
699
|
+
res.statusCode = status;
|
|
700
|
+
res.setHeader("content-type", "application/json; charset=utf-8");
|
|
701
|
+
res.setHeader("content-length", String(Buffer.byteLength(body)));
|
|
702
|
+
const cid = correlationIdStore.getStore();
|
|
703
|
+
if (cid) {
|
|
704
|
+
res.setHeader("x-request-id", cid);
|
|
705
|
+
}
|
|
706
|
+
res.end(body);
|
|
707
|
+
}
|
|
708
|
+
async handleAdminConsole(req, res, pathname) {
|
|
709
|
+
if (req.method !== "GET") return false;
|
|
710
|
+
if (pathname === "/engram/ui" || pathname === "/engram/ui/") {
|
|
711
|
+
await this.respondStatic(res, path.join(this.adminConsolePublicDir, "index.html"), "text/html; charset=utf-8");
|
|
712
|
+
return true;
|
|
713
|
+
}
|
|
714
|
+
if (pathname === "/engram/ui/app.js") {
|
|
715
|
+
await this.respondStatic(res, path.join(this.adminConsolePublicDir, "app.js"), "application/javascript; charset=utf-8");
|
|
716
|
+
return true;
|
|
717
|
+
}
|
|
718
|
+
return false;
|
|
719
|
+
}
|
|
720
|
+
async respondStatic(res, filePath, contentType) {
|
|
721
|
+
try {
|
|
722
|
+
const body = await readFile(filePath, "utf-8");
|
|
723
|
+
res.statusCode = 200;
|
|
724
|
+
res.setHeader("content-type", contentType);
|
|
725
|
+
res.setHeader("content-length", String(Buffer.byteLength(body)));
|
|
726
|
+
res.end(body);
|
|
727
|
+
} catch {
|
|
728
|
+
this.respondJson(res, 404, { error: "not_found" });
|
|
729
|
+
}
|
|
730
|
+
}
|
|
731
|
+
async readJsonBody(req) {
|
|
732
|
+
const chunks = [];
|
|
733
|
+
let total = 0;
|
|
734
|
+
for await (const chunk of req) {
|
|
735
|
+
const buffer = Buffer.isBuffer(chunk) ? chunk : Buffer.from(chunk);
|
|
736
|
+
total += buffer.length;
|
|
737
|
+
if (total > this.maxBodyBytes) {
|
|
738
|
+
throw new HttpError(413, "request_body_too_large", "request_body_too_large");
|
|
739
|
+
}
|
|
740
|
+
chunks.push(buffer);
|
|
741
|
+
}
|
|
742
|
+
if (chunks.length === 0) return {};
|
|
743
|
+
const raw = Buffer.concat(chunks).toString("utf-8").trim();
|
|
744
|
+
if (raw.length === 0) return {};
|
|
745
|
+
let parsed;
|
|
746
|
+
try {
|
|
747
|
+
parsed = JSON.parse(raw);
|
|
748
|
+
} catch {
|
|
749
|
+
throw new HttpError(400, "invalid_json", "invalid_json");
|
|
750
|
+
}
|
|
751
|
+
if (!parsed || typeof parsed !== "object" || Array.isArray(parsed)) {
|
|
752
|
+
throw new HttpError(400, "invalid_json_object", "invalid_json_object");
|
|
753
|
+
}
|
|
754
|
+
return parsed;
|
|
755
|
+
}
|
|
756
|
+
async readValidatedBody(req, schemaName) {
|
|
757
|
+
const raw = await this.readJsonBody(req);
|
|
758
|
+
const result = validateRequest(schemaName, raw);
|
|
759
|
+
if (!result.success) {
|
|
760
|
+
throw new HttpError(400, result.error.error, "validation_error", result.error.details);
|
|
761
|
+
}
|
|
762
|
+
return result.data;
|
|
763
|
+
}
|
|
764
|
+
isAuthorized(req) {
|
|
765
|
+
if (!this.authToken && this.authTokens.length === 0 && !this.authTokensGetter) return false;
|
|
766
|
+
const raw = req.headers.authorization;
|
|
767
|
+
if (!raw) return false;
|
|
768
|
+
const separator = raw.indexOf(" ");
|
|
769
|
+
if (separator <= 0) return false;
|
|
770
|
+
const scheme = raw.slice(0, separator).toLowerCase();
|
|
771
|
+
if (scheme !== "bearer") return false;
|
|
772
|
+
const token = raw.slice(separator + 1).trim();
|
|
773
|
+
if (this.authToken && this.timingSafeStringEqual(token, this.authToken)) return true;
|
|
774
|
+
for (const valid of this.authTokens) {
|
|
775
|
+
if (this.timingSafeStringEqual(token, valid)) return true;
|
|
776
|
+
}
|
|
777
|
+
if (this.authTokensGetter) {
|
|
778
|
+
for (const valid of this.authTokensGetter()) {
|
|
779
|
+
if (this.timingSafeStringEqual(token, valid)) return true;
|
|
780
|
+
}
|
|
781
|
+
}
|
|
782
|
+
return false;
|
|
783
|
+
}
|
|
784
|
+
timingSafeStringEqual(a, b) {
|
|
785
|
+
const left = this.encodeSecret(a);
|
|
786
|
+
const right = this.encodeSecret(b);
|
|
787
|
+
if (!left || !right) return false;
|
|
788
|
+
return timingSafeEqual(left, right);
|
|
789
|
+
}
|
|
790
|
+
encodeSecret(value) {
|
|
791
|
+
const encoded = Buffer.from(value, "utf-8");
|
|
792
|
+
if (encoded.length > 1024) return null;
|
|
793
|
+
const out = Buffer.alloc(2 + 1024);
|
|
794
|
+
out.writeUInt16BE(encoded.length, 0);
|
|
795
|
+
encoded.copy(out, 2);
|
|
796
|
+
return out;
|
|
797
|
+
}
|
|
798
|
+
writeResponseStatus(response) {
|
|
799
|
+
if (response.dryRun === true) return 200;
|
|
800
|
+
if (response.status === "stored" || response.status === "queued_for_review") return 201;
|
|
801
|
+
return 200;
|
|
802
|
+
}
|
|
803
|
+
ensureWriteRateLimitAvailable() {
|
|
804
|
+
const now = Date.now();
|
|
805
|
+
while (this.writeRequestTimestamps.length > 0 && now - (this.writeRequestTimestamps[0] ?? 0) > WRITE_RATE_LIMIT_WINDOW_MS) {
|
|
806
|
+
this.writeRequestTimestamps.shift();
|
|
807
|
+
}
|
|
808
|
+
if (this.writeRequestTimestamps.length >= WRITE_RATE_LIMIT_MAX_REQUESTS) {
|
|
809
|
+
throw new HttpError(429, "write_rate_limited", "write_rate_limited");
|
|
810
|
+
}
|
|
811
|
+
}
|
|
812
|
+
recordWriteRateLimitHit() {
|
|
813
|
+
this.writeRequestTimestamps.push(Date.now());
|
|
814
|
+
}
|
|
815
|
+
shouldCountWriteRateLimit(response) {
|
|
816
|
+
return response.dryRun !== true && response.idempotencyReplay !== true;
|
|
817
|
+
}
|
|
818
|
+
};
|
|
819
|
+
|
|
820
|
+
export {
|
|
821
|
+
EngramAccessHttpServer
|
|
822
|
+
};
|
|
823
|
+
//# sourceMappingURL=chunk-ZJLY4QSU.js.map
|