@graphrefly/graphrefly 0.47.1 → 0.48.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/base/composition/index.cjs +28 -19
- package/dist/base/composition/index.cjs.map +1 -1
- package/dist/base/composition/index.d.cts +14 -5
- package/dist/base/composition/index.d.ts +14 -5
- package/dist/base/composition/index.js +9 -9
- package/dist/base/index.cjs +294 -164
- package/dist/base/index.cjs.map +1 -1
- package/dist/base/index.d.cts +2 -2
- package/dist/base/index.d.ts +2 -2
- package/dist/base/index.js +77 -72
- package/dist/base/io/index.cjs +145 -85
- package/dist/base/io/index.cjs.map +1 -1
- package/dist/base/io/index.d.cts +32 -5
- package/dist/base/io/index.d.ts +32 -5
- package/dist/base/io/index.js +5 -5
- package/dist/base/mutation/index.cjs +21 -0
- package/dist/base/mutation/index.cjs.map +1 -1
- package/dist/base/mutation/index.d.cts +23 -1
- package/dist/base/mutation/index.d.ts +23 -1
- package/dist/base/mutation/index.js +3 -1
- package/dist/base/sources/browser/index.cjs +18 -12
- package/dist/base/sources/browser/index.cjs.map +1 -1
- package/dist/base/sources/browser/index.d.cts +20 -2
- package/dist/base/sources/browser/index.d.ts +20 -2
- package/dist/base/sources/browser/index.js +18 -12
- package/dist/base/sources/browser/index.js.map +1 -1
- package/dist/base/sources/event/index.cjs +29 -1
- package/dist/base/sources/event/index.cjs.map +1 -1
- package/dist/base/sources/event/index.d.cts +67 -3
- package/dist/base/sources/event/index.d.ts +67 -3
- package/dist/base/sources/event/index.js +5 -2
- package/dist/base/sources/index.cjs +96 -50
- package/dist/base/sources/index.cjs.map +1 -1
- package/dist/base/sources/index.d.cts +1 -1
- package/dist/base/sources/index.d.ts +1 -1
- package/dist/base/sources/index.js +7 -4
- package/dist/base/sources/node/index.cjs +43 -37
- package/dist/base/sources/node/index.cjs.map +1 -1
- package/dist/base/sources/node/index.js +43 -37
- package/dist/base/sources/node/index.js.map +1 -1
- package/dist/{chunk-J5WFUEO4.js → chunk-23MAWVOJ.js} +3 -3
- package/dist/{chunk-YXCPV26R.js → chunk-3REMCHSS.js} +39 -27
- package/dist/chunk-3REMCHSS.js.map +1 -0
- package/dist/{chunk-CEVNQ74M.js → chunk-3YGXPUHW.js} +2 -2
- package/dist/{chunk-CEVNQ74M.js.map → chunk-3YGXPUHW.js.map} +1 -1
- package/dist/{chunk-EVYY4X5A.js → chunk-46X2EFQH.js} +16 -5
- package/dist/chunk-46X2EFQH.js.map +1 -0
- package/dist/{chunk-NY2PYHNC.js → chunk-5UY3PNFY.js} +12 -5
- package/dist/chunk-5UY3PNFY.js.map +1 -0
- package/dist/{chunk-RGMTUZCL.js → chunk-65OM4XLQ.js} +50 -4
- package/dist/chunk-65OM4XLQ.js.map +1 -0
- package/dist/{chunk-3PSLNJDU.js → chunk-6DQYBIHW.js} +314 -49
- package/dist/chunk-6DQYBIHW.js.map +1 -0
- package/dist/{chunk-LDCSZ72P.js → chunk-6YBER5UP.js} +3 -3
- package/dist/{chunk-LDCSZ72P.js.map → chunk-6YBER5UP.js.map} +1 -1
- package/dist/{chunk-7EGRP2VX.js → chunk-7BULJTL6.js} +2 -2
- package/dist/{chunk-7EGRP2VX.js.map → chunk-7BULJTL6.js.map} +1 -1
- package/dist/{chunk-VLAGJZSL.js → chunk-7T7WLEPM.js} +25 -4
- package/dist/chunk-7T7WLEPM.js.map +1 -0
- package/dist/{chunk-PKPO3JTZ.js → chunk-AQAKDE7F.js} +29 -11
- package/dist/chunk-AQAKDE7F.js.map +1 -0
- package/dist/{chunk-2OB3CEJS.js → chunk-B5Y5GPD5.js} +2 -2
- package/dist/{chunk-BXGZFGZ4.js → chunk-C5QD5DQX.js} +22 -1
- package/dist/chunk-C5QD5DQX.js.map +1 -0
- package/dist/{chunk-4XCHZRUJ.js → chunk-D5YGR4TP.js} +58 -7
- package/dist/chunk-D5YGR4TP.js.map +1 -0
- package/dist/{chunk-NPRP3MCV.js → chunk-DHDCOOJU.js} +2 -2
- package/dist/chunk-DHDCOOJU.js.map +1 -0
- package/dist/{chunk-MTTRCEJT.js → chunk-DVTDF5OI.js} +2 -2
- package/dist/{chunk-SOOKUYVM.js → chunk-F7EKHR32.js} +13 -9
- package/dist/chunk-F7EKHR32.js.map +1 -0
- package/dist/{chunk-A7KV5UK4.js → chunk-G7H6PN7P.js} +2 -2
- package/dist/{chunk-OCUDSN63.js → chunk-GGKHHG5Y.js} +110 -64
- package/dist/chunk-GGKHHG5Y.js.map +1 -0
- package/dist/{chunk-RAGGHLCV.js → chunk-GUNIRPEJ.js} +8 -6
- package/dist/{chunk-RAGGHLCV.js.map → chunk-GUNIRPEJ.js.map} +1 -1
- package/dist/{chunk-YJ4U2D2C.js → chunk-J5TBZFBD.js} +9 -7
- package/dist/chunk-J5TBZFBD.js.map +1 -0
- package/dist/{chunk-Y52CS6YA.js → chunk-JA67ZQG2.js} +2 -2
- package/dist/{chunk-Y52CS6YA.js.map → chunk-JA67ZQG2.js.map} +1 -1
- package/dist/{chunk-U225SKB4.js → chunk-K4ZYJ4EM.js} +569 -424
- package/dist/chunk-K4ZYJ4EM.js.map +1 -0
- package/dist/{chunk-Z4YXAUDN.js → chunk-KUFXLAEY.js} +11 -7
- package/dist/{chunk-Z4YXAUDN.js.map → chunk-KUFXLAEY.js.map} +1 -1
- package/dist/{chunk-IHTWQEDR.js → chunk-LTSI7ULC.js} +3 -3
- package/dist/{chunk-IHTWQEDR.js.map → chunk-LTSI7ULC.js.map} +1 -1
- package/dist/{chunk-DKNHAICT.js → chunk-MMHGYX44.js} +25 -9
- package/dist/chunk-MMHGYX44.js.map +1 -0
- package/dist/{chunk-K7PDZYQE.js → chunk-MQMTRKY3.js} +129 -50
- package/dist/chunk-MQMTRKY3.js.map +1 -0
- package/dist/{chunk-42FQ27MQ.js → chunk-MTODGQBR.js} +44 -179
- package/dist/chunk-MTODGQBR.js.map +1 -0
- package/dist/{chunk-O3MT7DYI.js → chunk-N6MNJNHB.js} +2 -2
- package/dist/{chunk-FVINAAKA.js → chunk-NBK6QQMG.js} +14 -13
- package/dist/{chunk-FVINAAKA.js.map → chunk-NBK6QQMG.js.map} +1 -1
- package/dist/{chunk-DM4OMPWK.js → chunk-NSA5K5G2.js} +2 -2
- package/dist/{chunk-MLTPJMH6.js → chunk-QQYULEZL.js} +2 -2
- package/dist/chunk-QSW4DFKE.js +31 -0
- package/dist/chunk-QSW4DFKE.js.map +1 -0
- package/dist/{chunk-PZWISPIQ.js → chunk-S7HN5FHL.js} +17 -11
- package/dist/chunk-S7HN5FHL.js.map +1 -0
- package/dist/{chunk-4S53H2KR.js → chunk-SUNCHMML.js} +2 -2
- package/dist/{chunk-4GYMCUDZ.js → chunk-T2U6N3FV.js} +7 -7
- package/dist/{chunk-RJOG4IJU.js → chunk-T5URUIIY.js} +50 -35
- package/dist/chunk-T5URUIIY.js.map +1 -0
- package/dist/{chunk-B4AKFXGE.js → chunk-TPTZZV25.js} +6 -6
- package/dist/chunk-TPTZZV25.js.map +1 -0
- package/dist/{chunk-BU3SEFA5.js → chunk-V46JWFGV.js} +7 -6
- package/dist/chunk-V46JWFGV.js.map +1 -0
- package/dist/{chunk-IJRR6YAI.js → chunk-VLDRAMP7.js} +18 -12
- package/dist/chunk-VLDRAMP7.js.map +1 -0
- package/dist/{chunk-6XZYT4SW.js → chunk-X6ESZDR6.js} +8 -9
- package/dist/chunk-X6ESZDR6.js.map +1 -0
- package/dist/{chunk-E5OZPDIW.js → chunk-X7BA5PWG.js} +7 -5
- package/dist/chunk-X7BA5PWG.js.map +1 -0
- package/dist/{chunk-CXANAIZU.js → chunk-XEWV254I.js} +3 -3
- package/dist/{chunk-CXANAIZU.js.map → chunk-XEWV254I.js.map} +1 -1
- package/dist/{chunk-V4Y3TM7U.js → chunk-YBJVKMTM.js} +38 -16
- package/dist/chunk-YBJVKMTM.js.map +1 -0
- package/dist/{chunk-7ADWWI2T.js → chunk-ZW32BPXV.js} +17 -6
- package/dist/chunk-ZW32BPXV.js.map +1 -0
- package/dist/compat/index.cjs +52 -5
- package/dist/compat/index.cjs.map +1 -1
- package/dist/compat/index.d.cts +1 -1
- package/dist/compat/index.d.ts +1 -1
- package/dist/compat/index.js +7 -7
- package/dist/compat/nestjs/index.cjs +52 -5
- package/dist/compat/nestjs/index.cjs.map +1 -1
- package/dist/compat/nestjs/index.d.cts +1 -1
- package/dist/compat/nestjs/index.d.ts +1 -1
- package/dist/compat/nestjs/index.js +4 -4
- package/dist/{fallback-Bx46zqky.d.cts → fallback-BROR6ZhO.d.cts} +1 -1
- package/dist/{fallback-pIWW8A2d.d.ts → fallback-DO80aM_3.d.ts} +1 -1
- package/dist/{index-B_p8tnvf.d.cts → index-D1z3XcF9.d.cts} +1 -0
- package/dist/{index-_HDSmPyp.d.ts → index-DZ6yua0Q.d.ts} +1 -0
- package/dist/index.cjs +2387 -1707
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +10 -10
- package/dist/index.d.ts +10 -10
- package/dist/index.js +173 -150
- package/dist/index.js.map +1 -1
- package/dist/presets/ai/index.cjs +88 -26
- package/dist/presets/ai/index.cjs.map +1 -1
- package/dist/presets/ai/index.js +14 -14
- package/dist/presets/harness/index.cjs +183 -51
- package/dist/presets/harness/index.cjs.map +1 -1
- package/dist/presets/harness/index.d.cts +15 -5
- package/dist/presets/harness/index.d.ts +15 -5
- package/dist/presets/harness/index.js +26 -26
- package/dist/presets/index.cjs +298 -101
- package/dist/presets/index.cjs.map +1 -1
- package/dist/presets/index.d.cts +2 -2
- package/dist/presets/index.d.ts +2 -2
- package/dist/presets/index.js +49 -49
- package/dist/presets/inspect/index.cjs +63 -14
- package/dist/presets/inspect/index.cjs.map +1 -1
- package/dist/presets/inspect/index.d.cts +1 -1
- package/dist/presets/inspect/index.d.ts +1 -1
- package/dist/presets/inspect/index.js +6 -6
- package/dist/presets/resilience/index.cjs +64 -44
- package/dist/presets/resilience/index.cjs.map +1 -1
- package/dist/presets/resilience/index.d.cts +12 -8
- package/dist/presets/resilience/index.d.ts +12 -8
- package/dist/presets/resilience/index.js +6 -6
- package/dist/{rate-limiter-DpVbSYdH.d.cts → rate-limiter-DC26FM8J.d.cts} +10 -1
- package/dist/{rate-limiter-CEALq4N1.d.ts → rate-limiter-DyWpwpQP.d.ts} +10 -1
- package/dist/{reactive-layout-fswlBUvX.d.ts → reactive-layout-BBBWH0V_.d.cts} +85 -4
- package/dist/{reactive-layout-fswlBUvX.d.cts → reactive-layout-BBBWH0V_.d.ts} +85 -4
- package/dist/solutions/index.cjs +239 -92
- package/dist/solutions/index.cjs.map +1 -1
- package/dist/solutions/index.d.cts +2 -2
- package/dist/solutions/index.d.ts +2 -2
- package/dist/solutions/index.js +32 -32
- package/dist/{spawnable-5mDY501F.d.cts → spawnable-B2IlW60f.d.cts} +23 -2
- package/dist/{spawnable-D3lR0oQu.d.ts → spawnable-tttFz2Nh.d.ts} +23 -2
- package/dist/testing/index.cjs +94 -0
- package/dist/testing/index.cjs.map +1 -0
- package/dist/testing/index.d.cts +59 -0
- package/dist/testing/index.d.ts +59 -0
- package/dist/testing/index.js +73 -0
- package/dist/testing/index.js.map +1 -0
- package/dist/{timeout-U5O4ESK3.js → timeout-BEABACRP.js} +2 -2
- package/dist/utils/ai/browser.cjs.map +1 -1
- package/dist/utils/ai/browser.d.cts +2 -2
- package/dist/utils/ai/browser.d.ts +2 -2
- package/dist/utils/ai/browser.js +10 -10
- package/dist/utils/ai/browser.js.map +1 -1
- package/dist/utils/ai/index.cjs +291 -191
- package/dist/utils/ai/index.cjs.map +1 -1
- package/dist/utils/ai/index.d.cts +108 -12
- package/dist/utils/ai/index.d.ts +108 -12
- package/dist/utils/ai/index.js +23 -21
- package/dist/utils/ai/node.cjs.map +1 -1
- package/dist/utils/ai/node.d.cts +5 -5
- package/dist/utils/ai/node.d.ts +5 -5
- package/dist/utils/ai/node.js +3 -3
- package/dist/utils/ai/node.js.map +1 -1
- package/dist/utils/cqrs/index.cjs +29 -3
- package/dist/utils/cqrs/index.cjs.map +1 -1
- package/dist/utils/cqrs/index.d.cts +12 -7
- package/dist/utils/cqrs/index.d.ts +12 -7
- package/dist/utils/cqrs/index.js +2 -2
- package/dist/utils/demo-shell/index.cjs +45 -19
- package/dist/utils/demo-shell/index.cjs.map +1 -1
- package/dist/utils/demo-shell/index.d.cts +1 -1
- package/dist/utils/demo-shell/index.d.ts +1 -1
- package/dist/utils/demo-shell/index.js +2 -2
- package/dist/utils/domain-templates/index.cjs +1 -1
- package/dist/utils/domain-templates/index.cjs.map +1 -1
- package/dist/utils/domain-templates/index.js +3 -3
- package/dist/utils/graphspec/index.cjs +1 -1
- package/dist/utils/graphspec/index.cjs.map +1 -1
- package/dist/utils/graphspec/index.js +3 -3
- package/dist/utils/harness/index.cjs +16 -10
- package/dist/utils/harness/index.cjs.map +1 -1
- package/dist/utils/harness/index.js +1 -1
- package/dist/utils/index.cjs +1692 -1192
- package/dist/utils/index.cjs.map +1 -1
- package/dist/utils/index.d.cts +7 -7
- package/dist/utils/index.d.ts +7 -7
- package/dist/utils/index.js +77 -59
- package/dist/utils/inspect/index.cjs +52 -4
- package/dist/utils/inspect/index.cjs.map +1 -1
- package/dist/utils/inspect/index.d.cts +32 -3
- package/dist/utils/inspect/index.d.ts +32 -3
- package/dist/utils/inspect/index.js +4 -4
- package/dist/utils/job-queue/index.cjs +46 -9
- package/dist/utils/job-queue/index.cjs.map +1 -1
- package/dist/utils/job-queue/index.d.cts +33 -3
- package/dist/utils/job-queue/index.d.ts +33 -3
- package/dist/utils/job-queue/index.js +2 -2
- package/dist/utils/memory/index.cjs +570 -425
- package/dist/utils/memory/index.cjs.map +1 -1
- package/dist/utils/memory/index.d.cts +261 -33
- package/dist/utils/memory/index.d.ts +261 -33
- package/dist/utils/memory/index.js +10 -2
- package/dist/utils/messaging/index.cjs.map +1 -1
- package/dist/utils/messaging/index.d.cts +4 -3
- package/dist/utils/messaging/index.d.ts +4 -3
- package/dist/utils/messaging/index.js +2 -2
- package/dist/utils/orchestration/index.cjs +14 -3
- package/dist/utils/orchestration/index.cjs.map +1 -1
- package/dist/utils/orchestration/index.js +3 -3
- package/dist/utils/process/index.cjs +32 -2
- package/dist/utils/process/index.cjs.map +1 -1
- package/dist/utils/process/index.d.cts +4 -3
- package/dist/utils/process/index.d.ts +4 -3
- package/dist/utils/process/index.js +3 -3
- package/dist/utils/reactive-layout/index.cjs +184 -55
- package/dist/utils/reactive-layout/index.cjs.map +1 -1
- package/dist/utils/reactive-layout/index.d.cts +128 -3
- package/dist/utils/reactive-layout/index.d.ts +128 -3
- package/dist/utils/reactive-layout/index.js +16 -8
- package/dist/utils/reduction/index.cjs +1 -1
- package/dist/utils/reduction/index.cjs.map +1 -1
- package/dist/utils/reduction/index.js +2 -2
- package/dist/utils/resilience/index.cjs +64 -43
- package/dist/utils/resilience/index.cjs.map +1 -1
- package/dist/utils/resilience/index.d.cts +1 -1
- package/dist/utils/resilience/index.d.ts +1 -1
- package/dist/utils/resilience/index.js +5 -5
- package/dist/utils/surface/index.cjs +1 -1
- package/dist/utils/surface/index.cjs.map +1 -1
- package/dist/utils/surface/index.js +4 -4
- package/package.json +15 -3
- package/dist/chunk-3PSLNJDU.js.map +0 -1
- package/dist/chunk-42FQ27MQ.js.map +0 -1
- package/dist/chunk-4XCHZRUJ.js.map +0 -1
- package/dist/chunk-6XZYT4SW.js.map +0 -1
- package/dist/chunk-7ADWWI2T.js.map +0 -1
- package/dist/chunk-B4AKFXGE.js.map +0 -1
- package/dist/chunk-BU3SEFA5.js.map +0 -1
- package/dist/chunk-BXGZFGZ4.js.map +0 -1
- package/dist/chunk-DKNHAICT.js.map +0 -1
- package/dist/chunk-E5OZPDIW.js.map +0 -1
- package/dist/chunk-EVYY4X5A.js.map +0 -1
- package/dist/chunk-IJRR6YAI.js.map +0 -1
- package/dist/chunk-K7PDZYQE.js.map +0 -1
- package/dist/chunk-NPRP3MCV.js.map +0 -1
- package/dist/chunk-NY2PYHNC.js.map +0 -1
- package/dist/chunk-OCUDSN63.js.map +0 -1
- package/dist/chunk-PKPO3JTZ.js.map +0 -1
- package/dist/chunk-PZWISPIQ.js.map +0 -1
- package/dist/chunk-RGMTUZCL.js.map +0 -1
- package/dist/chunk-RJOG4IJU.js.map +0 -1
- package/dist/chunk-SOOKUYVM.js.map +0 -1
- package/dist/chunk-U225SKB4.js.map +0 -1
- package/dist/chunk-V4Y3TM7U.js.map +0 -1
- package/dist/chunk-VLAGJZSL.js.map +0 -1
- package/dist/chunk-W2BOPXTI.js +0 -1
- package/dist/chunk-YJ4U2D2C.js.map +0 -1
- package/dist/chunk-YXCPV26R.js.map +0 -1
- package/dist/timeout-U5O4ESK3.js.map +0 -1
- /package/dist/{chunk-J5WFUEO4.js.map → chunk-23MAWVOJ.js.map} +0 -0
- /package/dist/{chunk-2OB3CEJS.js.map → chunk-B5Y5GPD5.js.map} +0 -0
- /package/dist/{chunk-MTTRCEJT.js.map → chunk-DVTDF5OI.js.map} +0 -0
- /package/dist/{chunk-A7KV5UK4.js.map → chunk-G7H6PN7P.js.map} +0 -0
- /package/dist/{chunk-O3MT7DYI.js.map → chunk-N6MNJNHB.js.map} +0 -0
- /package/dist/{chunk-DM4OMPWK.js.map → chunk-NSA5K5G2.js.map} +0 -0
- /package/dist/{chunk-MLTPJMH6.js.map → chunk-QQYULEZL.js.map} +0 -0
- /package/dist/{chunk-4S53H2KR.js.map → chunk-SUNCHMML.js.map} +0 -0
- /package/dist/{chunk-4GYMCUDZ.js.map → chunk-T2U6N3FV.js.map} +0 -0
- /package/dist/{chunk-W2BOPXTI.js.map → timeout-BEABACRP.js.map} +0 -0
|
@@ -20,6 +20,9 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
|
|
|
20
20
|
// src/utils/memory/index.ts
|
|
21
21
|
var memory_exports = {};
|
|
22
22
|
__export(memory_exports, {
|
|
23
|
+
DEFAULT_DECAY_HALF_LIFE_NS: () => DEFAULT_DECAY_HALF_LIFE_NS,
|
|
24
|
+
DEFAULT_DECAY_PERIOD_MS: () => DEFAULT_DECAY_PERIOD_MS,
|
|
25
|
+
ReactiveFactStoreGraph: () => ReactiveFactStoreGraph,
|
|
23
26
|
admissionLlmJudge: () => admissionLlmJudge,
|
|
24
27
|
bitemporalQuery: () => bitemporalQuery,
|
|
25
28
|
collection: () => collection,
|
|
@@ -33,10 +36,11 @@ __export(memory_exports, {
|
|
|
33
36
|
reactiveFactStore: () => reactiveFactStore,
|
|
34
37
|
scoringByOutcome: () => scoringByOutcome,
|
|
35
38
|
shardByTenant: () => shardByTenant,
|
|
39
|
+
simpleFactStore: () => simpleFactStore,
|
|
36
40
|
vectorIndex: () => vectorIndex
|
|
37
41
|
});
|
|
38
42
|
module.exports = __toCommonJS(memory_exports);
|
|
39
|
-
var
|
|
43
|
+
var import_core11 = require("@graphrefly/pure-ts/core");
|
|
40
44
|
var import_extra8 = require("@graphrefly/pure-ts/extra");
|
|
41
45
|
var import_graph3 = require("@graphrefly/pure-ts/graph");
|
|
42
46
|
|
|
@@ -242,428 +246,534 @@ function currentlyValid(f, asOf) {
|
|
|
242
246
|
function lastOf(batch2, prev) {
|
|
243
247
|
return batch2 != null && batch2.length > 0 ? batch2.at(-1) : prev;
|
|
244
248
|
}
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
249
|
+
var ReactiveFactStoreGraph = class extends import_graph2.Graph {
|
|
250
|
+
// ④ Topic outputs (caller subscribes for custom processing).
|
|
251
|
+
/** Per-shard `state<FactStore<T>>` nodes (length = shard count). */
|
|
252
|
+
shards;
|
|
253
|
+
/** Unified read view across all shards (derived). */
|
|
254
|
+
factStore;
|
|
255
|
+
dependentsIndex;
|
|
256
|
+
answer;
|
|
257
|
+
cascade;
|
|
258
|
+
cascadeOverflow;
|
|
259
|
+
review;
|
|
260
|
+
consolidated;
|
|
261
|
+
events;
|
|
262
|
+
/**
|
|
263
|
+
* Payload-carrying, replayable log of every committed fragment. Present iff
|
|
264
|
+
* {@link ReactiveFactStoreConfig.recordIngest} is `true`. Unlike
|
|
265
|
+
* {@link ReactiveFactStoreGraph.events} (action-only audit), each entry is
|
|
266
|
+
* the full {@link MemoryFragment} — `attachStorage` it for a durable,
|
|
267
|
+
* replayable projection source (see `recordIngest` docs for the recipe).
|
|
268
|
+
*/
|
|
269
|
+
ingestLog;
|
|
270
|
+
constructor(config) {
|
|
271
|
+
const shardCount = Math.max(1, config.shardCount ?? 4);
|
|
272
|
+
const maxIterations = Math.max(1, config.cascadeMaxIterations ?? 8);
|
|
273
|
+
const reviewThreshold = config.reviewThreshold ?? 0.3;
|
|
274
|
+
const shardBy = config.shardBy ?? ((f) => fnv1a(String(f.id)) % shardCount);
|
|
275
|
+
let cascadeIteration = 0;
|
|
276
|
+
const processedRoots = /* @__PURE__ */ new Set();
|
|
277
|
+
super("reactive_fact_store");
|
|
278
|
+
const events = createAuditLog({
|
|
279
|
+
name: "events",
|
|
280
|
+
retainedLimit: 1024,
|
|
281
|
+
graph: this
|
|
269
282
|
});
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
const key = shardBy(f);
|
|
276
|
-
const n = typeof key === "number" ? key : fnv1a(String(key));
|
|
277
|
-
const idx = (n % shardCount + shardCount) % shardCount;
|
|
278
|
-
return idx;
|
|
279
|
-
};
|
|
280
|
-
const findShardOf = (id) => {
|
|
283
|
+
const seqCursor = registerCursor(this, "seq", 0);
|
|
284
|
+
const ingestLog = config.recordIngest ? (0, import_extra2.reactiveLog)([], { name: "ingest_log" }) : void 0;
|
|
285
|
+
if (ingestLog) this.addDisposer(() => ingestLog.dispose());
|
|
286
|
+
const emptyStore = () => ({ byId: /* @__PURE__ */ new Map() });
|
|
287
|
+
const shards = [];
|
|
281
288
|
for (let s = 0; s < shardCount; s += 1) {
|
|
282
|
-
const
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
if (!fs) continue;
|
|
292
|
-
for (const [k, v] of fs.byId) out2.set(k, v);
|
|
293
|
-
}
|
|
294
|
-
return out2;
|
|
295
|
-
};
|
|
296
|
-
const commitFragment = (f) => {
|
|
297
|
-
const idx = shardIndexFor(f);
|
|
298
|
-
const cur = shards[idx].cache ?? emptyStore();
|
|
299
|
-
const next = new Map(cur.byId);
|
|
300
|
-
next.set(f.id, f);
|
|
301
|
-
shards[idx].emit({ byId: next });
|
|
302
|
-
};
|
|
303
|
-
const replaceFragment = (id, mut) => {
|
|
304
|
-
const idx = findShardOf(id);
|
|
305
|
-
if (idx < 0) return false;
|
|
306
|
-
const cur = shards[idx].cache;
|
|
307
|
-
const prev = cur.byId.get(id);
|
|
308
|
-
if (!prev) return false;
|
|
309
|
-
const next = new Map(cur.byId);
|
|
310
|
-
next.set(id, mut(prev));
|
|
311
|
-
shards[idx].emit({ byId: next });
|
|
312
|
-
return true;
|
|
313
|
-
};
|
|
314
|
-
const dependentsIndex = (0, import_core2.node)([], {
|
|
315
|
-
initial: /* @__PURE__ */ new Map(),
|
|
316
|
-
name: "dependents_index",
|
|
317
|
-
describeKind: "state",
|
|
318
|
-
meta: factMeta("factstore", { role: "dependents_index" })
|
|
319
|
-
});
|
|
320
|
-
graph.add(dependentsIndex, { name: "dependents_index" });
|
|
321
|
-
graph.addDisposer((0, import_extra2.keepalive)(dependentsIndex));
|
|
322
|
-
const indexFragment = (f, deps) => {
|
|
323
|
-
const cur = dependentsIndex.cache;
|
|
324
|
-
const next = /* @__PURE__ */ new Map();
|
|
325
|
-
for (const [k, v] of cur) next.set(k, [...v]);
|
|
326
|
-
for (const src of deps) {
|
|
327
|
-
const bucket = next.get(src) ?? [];
|
|
328
|
-
if (!bucket.includes(f.id)) bucket.push(f.id);
|
|
329
|
-
next.set(src, bucket);
|
|
289
|
+
const shard = (0, import_core2.node)([], {
|
|
290
|
+
initial: emptyStore(),
|
|
291
|
+
name: `shard_${s}`,
|
|
292
|
+
describeKind: "state",
|
|
293
|
+
meta: factMeta("factstore", { shard: s })
|
|
294
|
+
});
|
|
295
|
+
this.add(shard, { name: `shard_${s}` });
|
|
296
|
+
this.addDisposer((0, import_extra2.keepalive)(shard));
|
|
297
|
+
shards.push(shard);
|
|
330
298
|
}
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
name: "fact_store",
|
|
342
|
-
describeKind: "derived",
|
|
343
|
-
initial: emptyStore(),
|
|
344
|
-
meta: factMeta("factstore", { role: "read_view" }),
|
|
345
|
-
// F10a: `allFacts()` builds a fresh Map every detector retrigger.
|
|
346
|
-
// Fragments are immutable (replaced wholesale on mutation), so a
|
|
347
|
-
// same-size + per-key-identity check is a sound structural equality
|
|
348
|
-
// that stops `factStore` (and its `review` dependent) from re-firing
|
|
349
|
-
// every cascade wave when nothing actually changed.
|
|
350
|
-
equals: (a, b) => {
|
|
351
|
-
if (a === b) return true;
|
|
352
|
-
if (a.byId.size !== b.byId.size) return false;
|
|
353
|
-
for (const [k, v] of a.byId) {
|
|
354
|
-
if (b.byId.get(k) !== v) return false;
|
|
355
|
-
}
|
|
356
|
-
return true;
|
|
299
|
+
const shardIndexFor = (f) => {
|
|
300
|
+
const key = shardBy(f);
|
|
301
|
+
const n = typeof key === "number" ? key : fnv1a(String(key));
|
|
302
|
+
const idx = (n % shardCount + shardCount) % shardCount;
|
|
303
|
+
return idx;
|
|
304
|
+
};
|
|
305
|
+
const findShardOf = (id) => {
|
|
306
|
+
for (let s = 0; s < shardCount; s += 1) {
|
|
307
|
+
const fs = shards[s].cache;
|
|
308
|
+
if (fs?.byId.has(id)) return s;
|
|
357
309
|
}
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
if (f == null) {
|
|
367
|
-
actions.emit(null);
|
|
368
|
-
return;
|
|
310
|
+
return -1;
|
|
311
|
+
};
|
|
312
|
+
const allFacts = () => {
|
|
313
|
+
const out = /* @__PURE__ */ new Map();
|
|
314
|
+
for (const sh of shards) {
|
|
315
|
+
const fs = sh.cache;
|
|
316
|
+
if (!fs) continue;
|
|
317
|
+
for (const [k, v] of fs.byId) out.set(k, v);
|
|
369
318
|
}
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
319
|
+
return out;
|
|
320
|
+
};
|
|
321
|
+
const commitFragment = (f) => {
|
|
322
|
+
const idx = shardIndexFor(f);
|
|
323
|
+
const cur = shards[idx].cache ?? emptyStore();
|
|
324
|
+
const next = new Map(cur.byId);
|
|
325
|
+
next.set(f.id, f);
|
|
326
|
+
shards[idx].emit({ byId: next });
|
|
327
|
+
};
|
|
328
|
+
const replaceFragment = (id, mut) => {
|
|
329
|
+
const idx = findShardOf(id);
|
|
330
|
+
if (idx < 0) return false;
|
|
331
|
+
const cur = shards[idx].cache;
|
|
332
|
+
const prev = cur.byId.get(id);
|
|
333
|
+
if (!prev) return false;
|
|
334
|
+
const next = new Map(cur.byId);
|
|
335
|
+
next.set(id, mut(prev));
|
|
336
|
+
shards[idx].emit({ byId: next });
|
|
337
|
+
return true;
|
|
338
|
+
};
|
|
339
|
+
const dependentsIndex = (0, import_core2.node)([], {
|
|
340
|
+
initial: /* @__PURE__ */ new Map(),
|
|
341
|
+
name: "dependents_index",
|
|
342
|
+
describeKind: "state",
|
|
343
|
+
meta: factMeta("factstore", { role: "dependents_index" })
|
|
344
|
+
});
|
|
345
|
+
this.add(dependentsIndex, { name: "dependents_index" });
|
|
346
|
+
this.addDisposer((0, import_extra2.keepalive)(dependentsIndex));
|
|
347
|
+
const indexFragment = (f, deps) => {
|
|
348
|
+
const cur = dependentsIndex.cache;
|
|
349
|
+
const next = /* @__PURE__ */ new Map();
|
|
350
|
+
for (const [k, v] of cur) next.set(k, [...v]);
|
|
351
|
+
for (const src of deps) {
|
|
352
|
+
const bucket = next.get(src) ?? [];
|
|
353
|
+
if (!bucket.includes(f.id)) bucket.push(f.id);
|
|
354
|
+
next.set(src, bucket);
|
|
355
|
+
}
|
|
356
|
+
dependentsIndex.emit(next);
|
|
357
|
+
};
|
|
358
|
+
const factStore = (0, import_core2.node)(
|
|
359
|
+
shards,
|
|
360
|
+
(batchData, actions, ctx) => {
|
|
361
|
+
void batchData;
|
|
362
|
+
void ctx;
|
|
363
|
+
actions.emit({ byId: allFacts() });
|
|
364
|
+
},
|
|
365
|
+
{
|
|
366
|
+
name: "fact_store",
|
|
367
|
+
describeKind: "derived",
|
|
368
|
+
initial: emptyStore(),
|
|
369
|
+
meta: factMeta("factstore", { role: "read_view" }),
|
|
370
|
+
// F10a: `allFacts()` builds a fresh Map every detector retrigger.
|
|
371
|
+
// Fragments are immutable (replaced wholesale on mutation), so a
|
|
372
|
+
// same-size + per-key-identity check is a sound structural equality
|
|
373
|
+
// that stops `factStore` (and its `review` dependent) from re-firing
|
|
374
|
+
// every cascade wave when nothing actually changed.
|
|
375
|
+
equals: (a, b) => {
|
|
376
|
+
if (a === b) return true;
|
|
377
|
+
if (a.byId.size !== b.byId.size) return false;
|
|
378
|
+
for (const [k, v] of a.byId) {
|
|
379
|
+
if (b.byId.get(k) !== v) return false;
|
|
380
|
+
}
|
|
381
|
+
return true;
|
|
382
|
+
}
|
|
383
|
+
}
|
|
384
|
+
);
|
|
385
|
+
this.add(factStore, { name: "fact_store" });
|
|
386
|
+
this.addDisposer((0, import_extra2.keepalive)(factStore));
|
|
387
|
+
const extractOp = (0, import_core2.node)(
|
|
388
|
+
config.admissionFilter ? [config.ingest, config.admissionFilter] : [config.ingest],
|
|
389
|
+
(batchData, actions, ctx) => {
|
|
390
|
+
const f = lastOf(batchData[0], ctx.prevData[0]);
|
|
391
|
+
if (f == null) {
|
|
373
392
|
actions.emit(null);
|
|
374
393
|
return;
|
|
375
394
|
}
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
actions.emit(f);
|
|
383
|
-
},
|
|
384
|
-
{
|
|
385
|
-
name: "extract_op",
|
|
386
|
-
describeKind: "derived",
|
|
387
|
-
meta: factMeta("extract")
|
|
388
|
-
}
|
|
389
|
-
);
|
|
390
|
-
graph.add(extractOp, { name: "extract_op" });
|
|
391
|
-
graph.addDisposer((0, import_extra2.keepalive)(extractOp));
|
|
392
|
-
const invalidationDetector = (0, import_core2.node)(
|
|
393
|
-
[...shards],
|
|
394
|
-
(batchData, actions, ctx) => {
|
|
395
|
-
void batchData;
|
|
396
|
-
void ctx;
|
|
397
|
-
const facts = allFacts();
|
|
398
|
-
const index = dependentsIndex.cache;
|
|
399
|
-
const out2 = [];
|
|
400
|
-
const seen = /* @__PURE__ */ new Set();
|
|
401
|
-
for (const f of facts.values()) {
|
|
402
|
-
const obsolete = f.validTo !== void 0;
|
|
403
|
-
if (!obsolete) continue;
|
|
404
|
-
if (processedRoots.has(f.id)) continue;
|
|
405
|
-
const dependents = index.get(f.id) ?? [];
|
|
406
|
-
for (const dep of dependents) {
|
|
407
|
-
const depFact = facts.get(dep);
|
|
408
|
-
if (!depFact || depFact.validTo !== void 0) continue;
|
|
409
|
-
const k = `${f.id}->${dep}`;
|
|
410
|
-
if (seen.has(k)) continue;
|
|
411
|
-
seen.add(k);
|
|
412
|
-
out2.push({
|
|
413
|
-
factId: dep,
|
|
414
|
-
rootFactId: f.id,
|
|
415
|
-
reason: "obsolete",
|
|
416
|
-
// `obsolete` guard above guarantees `f.validTo` is set.
|
|
417
|
-
rootValidTo: f.validTo,
|
|
418
|
-
iteration: cascadeIteration + 1,
|
|
419
|
-
causalReason: `dependentsIndex[${f.id}] \u2192 ${dep} (obsolete: validTo set)`
|
|
420
|
-
});
|
|
395
|
+
if (config.admissionFilter) {
|
|
396
|
+
const filter = lastOf(batchData[1], ctx.prevData[1]);
|
|
397
|
+
if (filter && !filter(f)) {
|
|
398
|
+
actions.emit(null);
|
|
399
|
+
return;
|
|
400
|
+
}
|
|
421
401
|
}
|
|
422
|
-
|
|
423
|
-
}
|
|
424
|
-
if (out2.length === 0) {
|
|
402
|
+
const deps = config.extractDependencies(f);
|
|
425
403
|
cascadeIteration = 0;
|
|
404
|
+
processedRoots.delete(f.id);
|
|
405
|
+
commitFragment(f);
|
|
406
|
+
indexFragment(f, deps);
|
|
407
|
+
actions.emit(f);
|
|
408
|
+
},
|
|
409
|
+
{
|
|
410
|
+
name: "extract_op",
|
|
411
|
+
describeKind: "derived",
|
|
412
|
+
meta: factMeta("extract")
|
|
426
413
|
}
|
|
427
|
-
|
|
428
|
-
}
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
414
|
+
);
|
|
415
|
+
this.add(extractOp, { name: "extract_op" });
|
|
416
|
+
this.addDisposer((0, import_extra2.keepalive)(extractOp));
|
|
417
|
+
const invalidationDetector = (0, import_core2.node)(
|
|
418
|
+
[...shards],
|
|
419
|
+
(batchData, actions, ctx) => {
|
|
420
|
+
void batchData;
|
|
421
|
+
void ctx;
|
|
422
|
+
const facts = allFacts();
|
|
423
|
+
const index = dependentsIndex.cache;
|
|
424
|
+
const out = [];
|
|
425
|
+
const seen = /* @__PURE__ */ new Set();
|
|
426
|
+
for (const f of facts.values()) {
|
|
427
|
+
const obsolete = f.validTo !== void 0;
|
|
428
|
+
if (!obsolete) continue;
|
|
429
|
+
if (processedRoots.has(f.id)) continue;
|
|
430
|
+
const dependents = index.get(f.id) ?? [];
|
|
431
|
+
for (const dep of dependents) {
|
|
432
|
+
const depFact = facts.get(dep);
|
|
433
|
+
if (!depFact || depFact.validTo !== void 0) continue;
|
|
434
|
+
const k = `${f.id}->${dep}`;
|
|
435
|
+
if (seen.has(k)) continue;
|
|
436
|
+
seen.add(k);
|
|
437
|
+
out.push({
|
|
438
|
+
factId: dep,
|
|
439
|
+
rootFactId: f.id,
|
|
440
|
+
reason: "obsolete",
|
|
441
|
+
// `obsolete` guard above guarantees `f.validTo` is set.
|
|
442
|
+
rootValidTo: f.validTo,
|
|
443
|
+
iteration: cascadeIteration + 1,
|
|
444
|
+
causalReason: `dependentsIndex[${f.id}] \u2192 ${dep} (obsolete: validTo set)`
|
|
445
|
+
});
|
|
446
|
+
}
|
|
447
|
+
processedRoots.add(f.id);
|
|
448
|
+
}
|
|
449
|
+
if (out.length === 0) {
|
|
450
|
+
cascadeIteration = 0;
|
|
451
|
+
}
|
|
452
|
+
actions.emit(out);
|
|
453
|
+
},
|
|
454
|
+
{
|
|
455
|
+
name: "invalidation_detector",
|
|
456
|
+
describeKind: "derived",
|
|
457
|
+
initial: [],
|
|
458
|
+
meta: factMeta("invalidation", { cycle: "cascade" })
|
|
468
459
|
}
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
id: rootFactId,
|
|
484
|
-
t_ns: (0, import_core2.wallClockNs)(),
|
|
485
|
-
seq: bumpCursor(seqCursor)
|
|
486
|
-
});
|
|
487
|
-
actions.emit([]);
|
|
488
|
-
return;
|
|
460
|
+
);
|
|
461
|
+
this.add(invalidationDetector, { name: "invalidation_detector" });
|
|
462
|
+
this.addDisposer((0, import_extra2.keepalive)(invalidationDetector));
|
|
463
|
+
const cascade = (0, import_core2.node)(
|
|
464
|
+
[invalidationDetector],
|
|
465
|
+
(batchData, actions, ctx) => {
|
|
466
|
+
const evts = lastOf(batchData[0], ctx.prevData[0]) ?? [];
|
|
467
|
+
actions.emit(evts);
|
|
468
|
+
},
|
|
469
|
+
{
|
|
470
|
+
name: "cascade",
|
|
471
|
+
describeKind: "derived",
|
|
472
|
+
initial: [],
|
|
473
|
+
meta: factMeta("cascade_topic", { cycle: "cascade" })
|
|
489
474
|
}
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
475
|
+
);
|
|
476
|
+
this.add(cascade, { name: "cascade" });
|
|
477
|
+
this.addDisposer((0, import_extra2.keepalive)(cascade));
|
|
478
|
+
const cascadeOverflow = (0, import_core2.node)([], {
|
|
479
|
+
initial: null,
|
|
480
|
+
name: "cascade_overflow",
|
|
481
|
+
describeKind: "state",
|
|
482
|
+
meta: factMeta("cascade_overflow")
|
|
483
|
+
});
|
|
484
|
+
this.add(cascadeOverflow, { name: "cascade_overflow" });
|
|
485
|
+
this.addDisposer((0, import_extra2.keepalive)(cascadeOverflow));
|
|
486
|
+
const cascadeProcessor = (0, import_core2.node)(
|
|
487
|
+
[cascade],
|
|
488
|
+
(batchData, actions, ctx) => {
|
|
489
|
+
const evts = lastOf(batchData[0], ctx.prevData[0]) ?? [];
|
|
490
|
+
if (evts.length === 0) {
|
|
491
|
+
actions.emit([]);
|
|
492
|
+
return;
|
|
493
|
+
}
|
|
494
|
+
const byId = /* @__PURE__ */ new Map();
|
|
495
|
+
for (const e of evts) if (!byId.has(e.factId)) byId.set(e.factId, e);
|
|
496
|
+
cascadeIteration += 1;
|
|
497
|
+
if (cascadeIteration > maxIterations) {
|
|
498
|
+
const sample = [...byId.keys()].slice(0, OVERFLOW_SAMPLE_SIZE);
|
|
499
|
+
const rootFactId = evts[0]?.rootFactId ?? "";
|
|
500
|
+
cascadeOverflow.emit({
|
|
501
|
+
droppedCount: byId.size,
|
|
502
|
+
sample,
|
|
503
|
+
rootFactId
|
|
504
|
+
});
|
|
505
|
+
events.append({
|
|
506
|
+
action: "overflow",
|
|
507
|
+
reason: "cascade",
|
|
508
|
+
id: rootFactId,
|
|
509
|
+
t_ns: (0, import_core2.wallClockNs)(),
|
|
510
|
+
seq: bumpCursor(seqCursor)
|
|
511
|
+
});
|
|
512
|
+
actions.emit([]);
|
|
513
|
+
return;
|
|
514
|
+
}
|
|
515
|
+
for (const [id, e] of byId) {
|
|
516
|
+
replaceFragment(
|
|
517
|
+
id,
|
|
518
|
+
(prev) => prev.validTo !== void 0 ? prev : { ...prev, validTo: e.rootValidTo }
|
|
519
|
+
);
|
|
520
|
+
}
|
|
521
|
+
actions.emit([...byId.values()]);
|
|
522
|
+
},
|
|
523
|
+
{
|
|
524
|
+
name: "cascade_processor",
|
|
525
|
+
describeKind: "derived",
|
|
526
|
+
initial: [],
|
|
527
|
+
meta: factMeta("cascade_processor", { cycle: "cascade" })
|
|
495
528
|
}
|
|
496
|
-
|
|
497
|
-
}
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
529
|
+
);
|
|
530
|
+
this.add(cascadeProcessor, { name: "cascade_processor" });
|
|
531
|
+
this.addDisposer((0, import_extra2.keepalive)(cascadeProcessor));
|
|
532
|
+
const review = (0, import_core2.node)(
|
|
533
|
+
[factStore],
|
|
534
|
+
(batchData, actions, ctx) => {
|
|
535
|
+
const fs = lastOf(batchData[0], ctx.prevData[0]);
|
|
536
|
+
if (fs == null) {
|
|
537
|
+
actions.emit(null);
|
|
538
|
+
return;
|
|
539
|
+
}
|
|
540
|
+
for (const f of fs.byId.values()) {
|
|
541
|
+
if (f.confidence < reviewThreshold && f.validTo === void 0) {
|
|
542
|
+
actions.emit({
|
|
543
|
+
factId: f.id,
|
|
544
|
+
confidence: f.confidence,
|
|
545
|
+
threshold: reviewThreshold
|
|
546
|
+
});
|
|
547
|
+
return;
|
|
548
|
+
}
|
|
549
|
+
}
|
|
512
550
|
actions.emit(null);
|
|
513
|
-
|
|
551
|
+
},
|
|
552
|
+
{
|
|
553
|
+
name: "review",
|
|
554
|
+
describeKind: "derived",
|
|
555
|
+
initial: null,
|
|
556
|
+
meta: factMeta("review"),
|
|
557
|
+
// F10a: dedupe on the requested factId (null === no request) so a
|
|
558
|
+
// stable low-confidence fact does not re-emit a review every wave.
|
|
559
|
+
equals: (a, b) => (a?.factId ?? null) === (b?.factId ?? null)
|
|
514
560
|
}
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
|
|
561
|
+
);
|
|
562
|
+
this.add(review, { name: "review" });
|
|
563
|
+
this.addDisposer((0, import_extra2.keepalive)(review));
|
|
564
|
+
if (config.outcome) {
|
|
565
|
+
const outcomeProcessor = (0, import_core2.node)(
|
|
566
|
+
config.scoring ? [config.outcome, config.scoring] : [config.outcome],
|
|
567
|
+
(batchData, actions, ctx) => {
|
|
568
|
+
const sig = lastOf(batchData[0], ctx.prevData[0]);
|
|
569
|
+
if (sig == null) {
|
|
570
|
+
actions.emit(null);
|
|
571
|
+
return;
|
|
572
|
+
}
|
|
573
|
+
replaceFragment(sig.factId, (prev) => {
|
|
574
|
+
let nextConf = prev.confidence;
|
|
575
|
+
if (config.scoring) {
|
|
576
|
+
const policy2 = lastOf(batchData[1], ctx.prevData[1]);
|
|
577
|
+
if (policy2) {
|
|
578
|
+
nextConf = policy2(prev, makeReadHandle(allFacts()));
|
|
579
|
+
}
|
|
580
|
+
} else {
|
|
581
|
+
nextConf = Math.max(0, Math.min(1, prev.confidence + sig.reward));
|
|
582
|
+
}
|
|
583
|
+
return { ...prev, confidence: nextConf };
|
|
521
584
|
});
|
|
522
|
-
|
|
585
|
+
actions.emit(sig);
|
|
586
|
+
},
|
|
587
|
+
{
|
|
588
|
+
name: "outcome_processor",
|
|
589
|
+
describeKind: "derived",
|
|
590
|
+
initial: null,
|
|
591
|
+
meta: factMeta("outcome")
|
|
523
592
|
}
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
{
|
|
528
|
-
name: "review",
|
|
529
|
-
describeKind: "derived",
|
|
530
|
-
initial: null,
|
|
531
|
-
meta: factMeta("review"),
|
|
532
|
-
// F10a: dedupe on the requested factId (null === no request) so a
|
|
533
|
-
// stable low-confidence fact does not re-emit a review every wave.
|
|
534
|
-
equals: (a, b) => (a?.factId ?? null) === (b?.factId ?? null)
|
|
593
|
+
);
|
|
594
|
+
this.add(outcomeProcessor, { name: "outcome_processor" });
|
|
595
|
+
this.addDisposer((0, import_extra2.keepalive)(outcomeProcessor));
|
|
535
596
|
}
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
graph.addDisposer((0, import_extra2.keepalive)(review));
|
|
539
|
-
if (config.outcome) {
|
|
540
|
-
const outcomeProcessor = (0, import_core2.node)(
|
|
541
|
-
config.scoring ? [config.outcome, config.scoring] : [config.outcome],
|
|
597
|
+
const answer = (0, import_core2.node)(
|
|
598
|
+
config.query ? [config.query, factStore] : [factStore],
|
|
542
599
|
(batchData, actions, ctx) => {
|
|
543
|
-
|
|
544
|
-
if (sig == null) {
|
|
600
|
+
if (!config.query) {
|
|
545
601
|
actions.emit(null);
|
|
546
602
|
return;
|
|
547
603
|
}
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
|
|
551
|
-
|
|
552
|
-
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
|
|
556
|
-
|
|
604
|
+
const q = lastOf(batchData[0], ctx.prevData[0]);
|
|
605
|
+
const fs = lastOf(batchData[1], ctx.prevData[1]);
|
|
606
|
+
if (q == null) {
|
|
607
|
+
actions.emit(null);
|
|
608
|
+
return;
|
|
609
|
+
}
|
|
610
|
+
const store = fs ?? emptyStore();
|
|
611
|
+
let results = [...store.byId.values()].filter((f) => {
|
|
612
|
+
if (q.tags && q.tags.length > 0 && !q.tags.some((t) => f.tags.includes(t))) {
|
|
613
|
+
return false;
|
|
557
614
|
}
|
|
558
|
-
|
|
615
|
+
if (q.minConfidence !== void 0 && f.confidence < q.minConfidence) return false;
|
|
616
|
+
if (!currentlyValid(f, q.asOf)) return false;
|
|
617
|
+
return true;
|
|
559
618
|
});
|
|
560
|
-
|
|
619
|
+
results.sort((a, b) => b.confidence - a.confidence || Number(b.t_ns - a.t_ns));
|
|
620
|
+
if (q.limit !== void 0) results = results.slice(0, Math.max(0, q.limit));
|
|
621
|
+
actions.emit({ query: q, results });
|
|
561
622
|
},
|
|
562
623
|
{
|
|
563
|
-
name: "
|
|
624
|
+
name: "answer",
|
|
564
625
|
describeKind: "derived",
|
|
565
626
|
initial: null,
|
|
566
|
-
meta: factMeta("
|
|
627
|
+
meta: factMeta("query", { role: "output" })
|
|
567
628
|
}
|
|
568
629
|
);
|
|
569
|
-
|
|
570
|
-
|
|
571
|
-
|
|
572
|
-
|
|
573
|
-
|
|
574
|
-
|
|
575
|
-
|
|
576
|
-
|
|
577
|
-
|
|
578
|
-
|
|
579
|
-
const q = lastOf(batchData[0], ctx.prevData[0]);
|
|
580
|
-
const fs = lastOf(batchData[1], ctx.prevData[1]);
|
|
581
|
-
if (q == null) {
|
|
582
|
-
actions.emit(null);
|
|
583
|
-
return;
|
|
584
|
-
}
|
|
585
|
-
const store = fs ?? emptyStore();
|
|
586
|
-
let results = [...store.byId.values()].filter((f) => {
|
|
587
|
-
if (q.tags && q.tags.length > 0 && !q.tags.some((t) => f.tags.includes(t))) {
|
|
588
|
-
return false;
|
|
630
|
+
this.add(answer, { name: "answer" });
|
|
631
|
+
this.addDisposer((0, import_extra2.keepalive)(answer));
|
|
632
|
+
const consolidated = (0, import_core2.node)(
|
|
633
|
+
config.consolidateTrigger ? [config.consolidateTrigger] : [],
|
|
634
|
+
(batchData, actions, ctx) => {
|
|
635
|
+
void batchData;
|
|
636
|
+
void ctx;
|
|
637
|
+
if (!config.consolidateTrigger || !config.consolidate) {
|
|
638
|
+
actions.emit([]);
|
|
639
|
+
return;
|
|
589
640
|
}
|
|
590
|
-
|
|
591
|
-
|
|
592
|
-
|
|
593
|
-
|
|
594
|
-
|
|
595
|
-
|
|
596
|
-
|
|
597
|
-
|
|
598
|
-
|
|
599
|
-
|
|
600
|
-
|
|
601
|
-
|
|
602
|
-
|
|
603
|
-
|
|
604
|
-
|
|
605
|
-
|
|
606
|
-
|
|
607
|
-
|
|
608
|
-
|
|
609
|
-
|
|
610
|
-
|
|
611
|
-
|
|
612
|
-
|
|
613
|
-
|
|
614
|
-
|
|
615
|
-
|
|
616
|
-
|
|
617
|
-
|
|
618
|
-
|
|
619
|
-
|
|
620
|
-
|
|
621
|
-
|
|
622
|
-
|
|
623
|
-
action: "consolidate",
|
|
624
|
-
id: f.id,
|
|
625
|
-
t_ns: (0, import_core2.wallClockNs)(),
|
|
626
|
-
seq: bumpCursor(seqCursor)
|
|
627
|
-
});
|
|
641
|
+
const fragments = config.consolidate(makeReadHandle(allFacts()));
|
|
642
|
+
for (const f of fragments) {
|
|
643
|
+
const deps = config.extractDependencies(f);
|
|
644
|
+
processedRoots.delete(f.id);
|
|
645
|
+
commitFragment(f);
|
|
646
|
+
indexFragment(f, deps);
|
|
647
|
+
events.append({
|
|
648
|
+
action: "consolidate",
|
|
649
|
+
id: f.id,
|
|
650
|
+
t_ns: (0, import_core2.wallClockNs)(),
|
|
651
|
+
seq: bumpCursor(seqCursor)
|
|
652
|
+
});
|
|
653
|
+
}
|
|
654
|
+
actions.emit(fragments);
|
|
655
|
+
},
|
|
656
|
+
{
|
|
657
|
+
name: "consolidated",
|
|
658
|
+
describeKind: "derived",
|
|
659
|
+
initial: [],
|
|
660
|
+
// Inspection completeness (COMPOSITION-GUIDE §24 "make the
|
|
661
|
+
// invisible edge visible"): `consolidated` write-backs feed the
|
|
662
|
+
// bounded cascade store (commit → shard emit →
|
|
663
|
+
// `invalidationDetector`) exactly like `cascadeProcessor`, but
|
|
664
|
+
// is NOT a cascade-cycle node. `feeds:"cascade"` surfaces it as
|
|
665
|
+
// a cascade-store mutator in `describe()`/`explain()`;
|
|
666
|
+
// `drivesRoot:false` — by the consolidator contract successors
|
|
667
|
+
// are fresh live facts (no `validTo`), so on the contract path
|
|
668
|
+
// they do not root the cascade. (An out-of-contract `consolidate`
|
|
669
|
+
// that emits a `validTo`-set fragment WOULD root it via the
|
|
670
|
+
// detector — the tag reflects the documented contract, not a
|
|
671
|
+
// structural impossibility. Contrast `decay_processor` below,
|
|
672
|
+
// whose `drivesRoot:false` IS structurally provable.)
|
|
673
|
+
meta: factMeta("consolidator", { feeds: "cascade", drivesRoot: false })
|
|
628
674
|
}
|
|
629
|
-
|
|
630
|
-
}
|
|
631
|
-
|
|
632
|
-
|
|
633
|
-
|
|
634
|
-
|
|
635
|
-
|
|
675
|
+
);
|
|
676
|
+
this.add(consolidated, { name: "consolidated" });
|
|
677
|
+
this.addDisposer((0, import_extra2.keepalive)(consolidated));
|
|
678
|
+
if (config.decayTrigger) {
|
|
679
|
+
const decayProcessor = (0, import_core2.node)(
|
|
680
|
+
config.decay ? [config.decayTrigger, config.decay] : [config.decayTrigger],
|
|
681
|
+
(batchData, actions, ctx) => {
|
|
682
|
+
const policy2 = config.decay ? lastOf(batchData[1], ctx.prevData[1]) : void 0;
|
|
683
|
+
if (!policy2) {
|
|
684
|
+
actions.emit([]);
|
|
685
|
+
return;
|
|
686
|
+
}
|
|
687
|
+
const now = BigInt((0, import_core2.monotonicNs)());
|
|
688
|
+
const changes = [];
|
|
689
|
+
for (const f of allFacts().values()) {
|
|
690
|
+
if (f.validTo !== void 0) continue;
|
|
691
|
+
const ageNs = now - f.t_ns;
|
|
692
|
+
const raw = policy2(f.confidence, ageNs);
|
|
693
|
+
if (!Number.isFinite(raw)) continue;
|
|
694
|
+
const next = raw < 0 ? 0 : raw > 1 ? 1 : raw;
|
|
695
|
+
if (next === f.confidence) continue;
|
|
696
|
+
changes.push({ id: f.id, next });
|
|
697
|
+
}
|
|
698
|
+
const decayed = [];
|
|
699
|
+
for (const { id, next } of changes) {
|
|
700
|
+
const idx = findShardOf(id);
|
|
701
|
+
const fs = idx < 0 ? void 0 : shards[idx].cache;
|
|
702
|
+
const live = fs?.byId.get(id);
|
|
703
|
+
if (!live || live.validTo !== void 0) continue;
|
|
704
|
+
replaceFragment(
|
|
705
|
+
id,
|
|
706
|
+
(prev) => prev.validTo !== void 0 ? prev : { ...prev, confidence: next }
|
|
707
|
+
);
|
|
708
|
+
decayed.push({ ...live, confidence: next });
|
|
709
|
+
}
|
|
710
|
+
if (decayed.length > 0) {
|
|
711
|
+
events.append({
|
|
712
|
+
action: "decay",
|
|
713
|
+
t_ns: (0, import_core2.wallClockNs)(),
|
|
714
|
+
seq: bumpCursor(seqCursor),
|
|
715
|
+
count: decayed.length
|
|
716
|
+
});
|
|
717
|
+
}
|
|
718
|
+
actions.emit(decayed);
|
|
719
|
+
},
|
|
720
|
+
{
|
|
721
|
+
name: "decay_processor",
|
|
722
|
+
describeKind: "derived",
|
|
723
|
+
initial: [],
|
|
724
|
+
// Inspection completeness (same convention as `consolidated`
|
|
725
|
+
// above — kept uniform): `decay_processor` write-backs feed
|
|
726
|
+
// the cascade store via `replaceFragment` → shard emit →
|
|
727
|
+
// `invalidationDetector`. `feeds:"cascade"` surfaces it as a
|
|
728
|
+
// cascade-store mutator; `drivesRoot:false` — decay only
|
|
729
|
+
// mutates `confidence`, never `validTo`, and the detector
|
|
730
|
+
// roots on `validTo` only, so it provably cannot root.
|
|
731
|
+
meta: factMeta("decay", { feeds: "cascade", drivesRoot: false })
|
|
732
|
+
}
|
|
733
|
+
);
|
|
734
|
+
this.add(decayProcessor, { name: "decay_processor" });
|
|
735
|
+
this.addDisposer((0, import_extra2.keepalive)(decayProcessor));
|
|
636
736
|
}
|
|
637
|
-
|
|
638
|
-
|
|
639
|
-
|
|
640
|
-
|
|
641
|
-
|
|
642
|
-
|
|
643
|
-
|
|
644
|
-
|
|
645
|
-
|
|
646
|
-
|
|
647
|
-
|
|
648
|
-
|
|
649
|
-
|
|
650
|
-
|
|
651
|
-
|
|
737
|
+
const ingestAudit = (0, import_core2.node)(
|
|
738
|
+
[extractOp],
|
|
739
|
+
(batchData, actions, ctx) => {
|
|
740
|
+
const f = lastOf(batchData[0], ctx.prevData[0]);
|
|
741
|
+
if (f != null) {
|
|
742
|
+
events.append({
|
|
743
|
+
action: "ingest",
|
|
744
|
+
id: f.id,
|
|
745
|
+
t_ns: (0, import_core2.wallClockNs)(),
|
|
746
|
+
seq: bumpCursor(seqCursor)
|
|
747
|
+
});
|
|
748
|
+
ingestLog?.append(f);
|
|
749
|
+
}
|
|
750
|
+
actions.emit(f ?? null);
|
|
751
|
+
},
|
|
752
|
+
{
|
|
753
|
+
name: "_ingest_audit",
|
|
754
|
+
describeKind: "derived",
|
|
755
|
+
initial: null,
|
|
756
|
+
meta: factMeta("audit")
|
|
652
757
|
}
|
|
653
|
-
|
|
654
|
-
}
|
|
655
|
-
|
|
656
|
-
|
|
657
|
-
|
|
658
|
-
|
|
659
|
-
|
|
660
|
-
|
|
661
|
-
|
|
662
|
-
|
|
663
|
-
|
|
664
|
-
|
|
758
|
+
);
|
|
759
|
+
this.add(ingestAudit, { name: "_ingest_audit" });
|
|
760
|
+
this.addDisposer((0, import_extra2.keepalive)(ingestAudit));
|
|
761
|
+
this.shards = shards;
|
|
762
|
+
this.factStore = factStore;
|
|
763
|
+
this.dependentsIndex = dependentsIndex;
|
|
764
|
+
this.answer = answer;
|
|
765
|
+
this.cascade = cascade;
|
|
766
|
+
this.cascadeOverflow = cascadeOverflow;
|
|
767
|
+
this.review = review;
|
|
768
|
+
this.consolidated = consolidated;
|
|
769
|
+
this.events = events;
|
|
770
|
+
if (ingestLog) this.ingestLog = ingestLog;
|
|
771
|
+
}
|
|
772
|
+
// ── itemNode reactive read ───────────────────────────────────────────
|
|
773
|
+
/** Reactive read: a single fact by id (SENTINEL until the fact exists). */
|
|
774
|
+
itemNode(id) {
|
|
665
775
|
return (0, import_core2.node)(
|
|
666
|
-
[factStore],
|
|
776
|
+
[this.factStore],
|
|
667
777
|
(batchData, actions, ctx) => {
|
|
668
778
|
const fs = lastOf(batchData[0], ctx.prevData[0]);
|
|
669
779
|
actions.emit(fs?.byId.get(id));
|
|
@@ -675,20 +785,9 @@ function reactiveFactStore(config) {
|
|
|
675
785
|
}
|
|
676
786
|
);
|
|
677
787
|
}
|
|
678
|
-
|
|
679
|
-
|
|
680
|
-
|
|
681
|
-
dependentsIndex,
|
|
682
|
-
answer,
|
|
683
|
-
cascade,
|
|
684
|
-
cascadeOverflow,
|
|
685
|
-
review,
|
|
686
|
-
consolidated,
|
|
687
|
-
events,
|
|
688
|
-
...ingestLog ? { ingestLog } : {},
|
|
689
|
-
itemNode
|
|
690
|
-
});
|
|
691
|
-
return out;
|
|
788
|
+
};
|
|
789
|
+
function reactiveFactStore(config) {
|
|
790
|
+
return new ReactiveFactStoreGraph(config);
|
|
692
791
|
}
|
|
693
792
|
|
|
694
793
|
// src/utils/memory/persistent-fact-store.ts
|
|
@@ -1107,14 +1206,60 @@ function shardByTenant(tenantOf, opts = {}) {
|
|
|
1107
1206
|
return { shardBy: (f) => tenantOf(f), shardCount };
|
|
1108
1207
|
}
|
|
1109
1208
|
|
|
1209
|
+
// src/utils/memory/simple-fact-store.ts
|
|
1210
|
+
var import_core10 = require("@graphrefly/pure-ts/core");
|
|
1211
|
+
var DEFAULT_DECAY_HALF_LIFE_NS = 604800000000000n;
|
|
1212
|
+
var DEFAULT_DECAY_PERIOD_MS = 36e5;
|
|
1213
|
+
function simpleFactStore(opts = {}) {
|
|
1214
|
+
const ingest = (0, import_core10.node)([], { initial: void 0 });
|
|
1215
|
+
const extractDependencies = opts.extractDependencies ?? (() => []);
|
|
1216
|
+
const consolidationCfg = opts.consolidate ? consolidationRem(opts.consolidate) : void 0;
|
|
1217
|
+
const baseCfg = {
|
|
1218
|
+
ingest,
|
|
1219
|
+
extractDependencies,
|
|
1220
|
+
...consolidationCfg ?? {}
|
|
1221
|
+
};
|
|
1222
|
+
const mem = opts.storage ? persistentReactiveFactStore({
|
|
1223
|
+
...baseCfg,
|
|
1224
|
+
storage: opts.storage,
|
|
1225
|
+
...opts.persistName !== void 0 ? { persistName: opts.persistName } : {},
|
|
1226
|
+
...opts.codec !== void 0 ? { codec: opts.codec } : {}
|
|
1227
|
+
}) : reactiveFactStore(baseCfg);
|
|
1228
|
+
if (opts.decay !== false) {
|
|
1229
|
+
const d = opts.decay ?? {};
|
|
1230
|
+
decayExponential(mem, ingest, {
|
|
1231
|
+
...d,
|
|
1232
|
+
halfLifeNs: d.halfLifeNs ?? DEFAULT_DECAY_HALF_LIFE_NS,
|
|
1233
|
+
periodMs: d.periodMs ?? DEFAULT_DECAY_PERIOD_MS
|
|
1234
|
+
});
|
|
1235
|
+
}
|
|
1236
|
+
const remember = (id, payload, ro) => {
|
|
1237
|
+
const fragment = {
|
|
1238
|
+
id,
|
|
1239
|
+
payload,
|
|
1240
|
+
t_ns: BigInt((0, import_core10.monotonicNs)()),
|
|
1241
|
+
confidence: ro?.confidence ?? 1,
|
|
1242
|
+
tags: ro?.tags ?? [],
|
|
1243
|
+
sources: ro?.sources ?? [],
|
|
1244
|
+
...ro?.validTo !== void 0 ? { validTo: ro.validTo } : {},
|
|
1245
|
+
...ro?.validFrom !== void 0 ? { validFrom: ro.validFrom } : {},
|
|
1246
|
+
...ro?.provenance !== void 0 ? { provenance: ro.provenance } : {}
|
|
1247
|
+
};
|
|
1248
|
+
ingest.emit(fragment);
|
|
1249
|
+
};
|
|
1250
|
+
const out = mem;
|
|
1251
|
+
out.remember = remember;
|
|
1252
|
+
return out;
|
|
1253
|
+
}
|
|
1254
|
+
|
|
1110
1255
|
// src/utils/memory/index.ts
|
|
1111
1256
|
var NS_PER_SEC = 1e9;
|
|
1112
1257
|
function memoryMeta(kind, extra) {
|
|
1113
1258
|
return domainMeta("memory", kind, extra);
|
|
1114
1259
|
}
|
|
1115
1260
|
function toNode(v, name) {
|
|
1116
|
-
if (v instanceof
|
|
1117
|
-
return (0,
|
|
1261
|
+
if (v instanceof import_core11.NodeImpl) return v;
|
|
1262
|
+
return (0, import_core11.node)([], { initial: v, ...name ? { name } : void 0 });
|
|
1118
1263
|
}
|
|
1119
1264
|
function ageSeconds(now, lastNs) {
|
|
1120
1265
|
return (now - lastNs) / NS_PER_SEC;
|
|
@@ -1168,13 +1313,13 @@ function collection(name, opts = {}) {
|
|
|
1168
1313
|
}
|
|
1169
1314
|
const scoreFnDefault = () => ranked ? 1 : 0;
|
|
1170
1315
|
const scoreInput = opts.score ?? scoreFnDefault;
|
|
1171
|
-
const scoreNode = ranked && scoreInput instanceof
|
|
1316
|
+
const scoreNode = ranked && scoreInput instanceof import_core11.NodeImpl ? scoreInput : void 0;
|
|
1172
1317
|
const readScoreFn = () => {
|
|
1173
1318
|
if (scoreNode) return scoreNode.cache ?? scoreFnDefault;
|
|
1174
1319
|
return scoreInput;
|
|
1175
1320
|
};
|
|
1176
1321
|
const graph = new import_graph3.Graph(name);
|
|
1177
|
-
const retentionScore = (_k, v) => ranked ? decay(v.baseScore, ageSeconds((0,
|
|
1322
|
+
const retentionScore = (_k, v) => ranked ? decay(v.baseScore, ageSeconds((0, import_core11.monotonicNs)(), v.lastAccessNs), decayRate, minScore) : v.lastAccessNs;
|
|
1178
1323
|
const items = (0, import_extra8.reactiveMap)({
|
|
1179
1324
|
name: "items",
|
|
1180
1325
|
...maxSize !== void 0 ? { retention: { score: retentionScore, maxSize } } : {}
|
|
@@ -1184,15 +1329,15 @@ function collection(name, opts = {}) {
|
|
|
1184
1329
|
if (ranked && decayRate > 0) {
|
|
1185
1330
|
const intervalMs = opts.refreshIntervalMs ?? Math.max(1, 1e3 * Math.LN2 / (10 * decayRate));
|
|
1186
1331
|
const tickCounter = (0, import_extra8.fromTimer)(intervalMs, { period: intervalMs });
|
|
1187
|
-
refreshTick = (0,
|
|
1332
|
+
refreshTick = (0, import_core11.node)(
|
|
1188
1333
|
[tickCounter],
|
|
1189
1334
|
(_batchData, actions) => {
|
|
1190
|
-
actions.emit((0,
|
|
1335
|
+
actions.emit((0, import_core11.monotonicNs)());
|
|
1191
1336
|
},
|
|
1192
1337
|
{
|
|
1193
1338
|
name: "refresh_tick_ns",
|
|
1194
1339
|
describeKind: "derived",
|
|
1195
|
-
initial: (0,
|
|
1340
|
+
initial: (0, import_core11.monotonicNs)(),
|
|
1196
1341
|
meta: memoryMeta("clock")
|
|
1197
1342
|
}
|
|
1198
1343
|
);
|
|
@@ -1203,7 +1348,7 @@ function collection(name, opts = {}) {
|
|
|
1203
1348
|
const rankedDeps = [items.entries];
|
|
1204
1349
|
if (refreshTick) rankedDeps.push(refreshTick);
|
|
1205
1350
|
if (scoreNode) rankedDeps.push(scoreNode);
|
|
1206
|
-
rankedNode = (0,
|
|
1351
|
+
rankedNode = (0, import_core11.node)(
|
|
1207
1352
|
rankedDeps,
|
|
1208
1353
|
(batchData, actions, ctx) => {
|
|
1209
1354
|
const values = batchData.map(
|
|
@@ -1213,9 +1358,9 @@ function collection(name, opts = {}) {
|
|
|
1213
1358
|
let now;
|
|
1214
1359
|
if (refreshTick) {
|
|
1215
1360
|
const tickValue = values[1];
|
|
1216
|
-
now = typeof tickValue === "number" ? tickValue : (0,
|
|
1361
|
+
now = typeof tickValue === "number" ? tickValue : (0, import_core11.monotonicNs)();
|
|
1217
1362
|
} else {
|
|
1218
|
-
now = (0,
|
|
1363
|
+
now = (0, import_core11.monotonicNs)();
|
|
1219
1364
|
}
|
|
1220
1365
|
if (!snapshot || snapshot.size === 0) {
|
|
1221
1366
|
actions.emit([]);
|
|
@@ -1240,7 +1385,7 @@ function collection(name, opts = {}) {
|
|
|
1240
1385
|
);
|
|
1241
1386
|
graph.add(rankedNode, { name: "ranked" });
|
|
1242
1387
|
} else {
|
|
1243
|
-
rankedNode = (0,
|
|
1388
|
+
rankedNode = (0, import_core11.node)([], {
|
|
1244
1389
|
initial: [],
|
|
1245
1390
|
name: "ranked",
|
|
1246
1391
|
describeKind: "state",
|
|
@@ -1248,7 +1393,7 @@ function collection(name, opts = {}) {
|
|
|
1248
1393
|
});
|
|
1249
1394
|
graph.add(rankedNode, { name: "ranked" });
|
|
1250
1395
|
}
|
|
1251
|
-
const size = (0,
|
|
1396
|
+
const size = (0, import_core11.node)(
|
|
1252
1397
|
[items.entries],
|
|
1253
1398
|
(batchData, actions, ctx) => {
|
|
1254
1399
|
const data = batchData.map(
|
|
@@ -1273,7 +1418,7 @@ function collection(name, opts = {}) {
|
|
|
1273
1418
|
});
|
|
1274
1419
|
const seqCursor = registerCursor(graph, "seq", 0);
|
|
1275
1420
|
const upsertImpl = (id, value, _opts) => {
|
|
1276
|
-
const now = (0,
|
|
1421
|
+
const now = (0, import_core11.monotonicNs)();
|
|
1277
1422
|
const prev = items.get(id);
|
|
1278
1423
|
const baseScore = _opts?.score ?? readScoreFn()(value);
|
|
1279
1424
|
items.set(id, {
|
|
@@ -1329,7 +1474,7 @@ function collection(name, opts = {}) {
|
|
|
1329
1474
|
});
|
|
1330
1475
|
function itemNode(id) {
|
|
1331
1476
|
const idN = toNode(id, "id");
|
|
1332
|
-
return (0,
|
|
1477
|
+
return (0, import_core11.node)(
|
|
1333
1478
|
[items.entries, idN],
|
|
1334
1479
|
(batchData, actions, ctx) => {
|
|
1335
1480
|
const data = batchData.map(
|
|
@@ -1347,7 +1492,7 @@ function collection(name, opts = {}) {
|
|
|
1347
1492
|
}
|
|
1348
1493
|
function hasNode(id) {
|
|
1349
1494
|
const idN = toNode(id, "id");
|
|
1350
|
-
return (0,
|
|
1495
|
+
return (0, import_core11.node)(
|
|
1351
1496
|
[items.entries, idN],
|
|
1352
1497
|
(batchData, actions, ctx) => {
|
|
1353
1498
|
const data = batchData.map(
|
|
@@ -1434,7 +1579,7 @@ function vectorIndex(opts = {}) {
|
|
|
1434
1579
|
events.append({
|
|
1435
1580
|
action: "evict",
|
|
1436
1581
|
id: key,
|
|
1437
|
-
t_ns: (0,
|
|
1582
|
+
t_ns: (0, import_core11.wallClockNs)(),
|
|
1438
1583
|
seq: bumpCursor(seqCursor)
|
|
1439
1584
|
});
|
|
1440
1585
|
}
|
|
@@ -1459,7 +1604,7 @@ function vectorIndex(opts = {}) {
|
|
|
1459
1604
|
id,
|
|
1460
1605
|
vector: [...vector],
|
|
1461
1606
|
...copiedMeta !== void 0 ? { meta: copiedMeta } : {},
|
|
1462
|
-
upsertedAtNs: (0,
|
|
1607
|
+
upsertedAtNs: (0, import_core11.monotonicNs)()
|
|
1463
1608
|
};
|
|
1464
1609
|
entries.set(id, record);
|
|
1465
1610
|
};
|
|
@@ -1515,7 +1660,7 @@ function vectorIndex(opts = {}) {
|
|
|
1515
1660
|
});
|
|
1516
1661
|
function searchNode(query, k = 5) {
|
|
1517
1662
|
const kN = toNode(k, "k");
|
|
1518
|
-
return (0,
|
|
1663
|
+
return (0, import_core11.node)(
|
|
1519
1664
|
[entries.entries, query, kN],
|
|
1520
1665
|
(batchData, actions, ctx) => {
|
|
1521
1666
|
const values = batchData.map(
|
|
@@ -1631,7 +1776,7 @@ function knowledgeGraph(name, opts = {}) {
|
|
|
1631
1776
|
});
|
|
1632
1777
|
graph.add(entitiesMap.entries, { name: "entities" });
|
|
1633
1778
|
graph.add(edgesMap.entries, { name: "edges" });
|
|
1634
|
-
const adjacencyOut = (0,
|
|
1779
|
+
const adjacencyOut = (0, import_core11.node)(
|
|
1635
1780
|
[edgesMap.entries],
|
|
1636
1781
|
(batchData, actions, ctx) => {
|
|
1637
1782
|
const data = batchData.map(
|
|
@@ -1648,7 +1793,7 @@ function knowledgeGraph(name, opts = {}) {
|
|
|
1648
1793
|
meta: memoryMeta("adjacency_out")
|
|
1649
1794
|
}
|
|
1650
1795
|
);
|
|
1651
|
-
const adjacencyIn = (0,
|
|
1796
|
+
const adjacencyIn = (0, import_core11.node)(
|
|
1652
1797
|
[edgesMap.entries],
|
|
1653
1798
|
(batchData, actions, ctx) => {
|
|
1654
1799
|
const data = batchData.map(
|
|
@@ -1669,7 +1814,7 @@ function knowledgeGraph(name, opts = {}) {
|
|
|
1669
1814
|
graph.add(adjacencyIn, { name: "adjacencyIn" });
|
|
1670
1815
|
graph.addDisposer((0, import_extra8.keepalive)(adjacencyOut));
|
|
1671
1816
|
graph.addDisposer((0, import_extra8.keepalive)(adjacencyIn));
|
|
1672
|
-
const entityCount = (0,
|
|
1817
|
+
const entityCount = (0, import_core11.node)(
|
|
1673
1818
|
[entitiesMap.entries],
|
|
1674
1819
|
(batchData, actions, ctx) => {
|
|
1675
1820
|
const data = batchData.map(
|
|
@@ -1680,7 +1825,7 @@ function knowledgeGraph(name, opts = {}) {
|
|
|
1680
1825
|
},
|
|
1681
1826
|
{ name: "entityCount", describeKind: "derived", initial: 0, meta: memoryMeta("entity_count") }
|
|
1682
1827
|
);
|
|
1683
|
-
const edgeCount = (0,
|
|
1828
|
+
const edgeCount = (0, import_core11.node)(
|
|
1684
1829
|
[edgesMap.entries],
|
|
1685
1830
|
(batchData, actions, ctx) => {
|
|
1686
1831
|
const data = batchData.map(
|
|
@@ -1717,7 +1862,7 @@ function knowledgeGraph(name, opts = {}) {
|
|
|
1717
1862
|
events.append({
|
|
1718
1863
|
action: "orphanRemove",
|
|
1719
1864
|
id: candidate,
|
|
1720
|
-
t_ns: (0,
|
|
1865
|
+
t_ns: (0, import_core11.wallClockNs)(),
|
|
1721
1866
|
seq: bumpCursor(seqCursor)
|
|
1722
1867
|
});
|
|
1723
1868
|
}
|
|
@@ -1812,7 +1957,7 @@ function knowledgeGraph(name, opts = {}) {
|
|
|
1812
1957
|
const idN = toNode(id, "id");
|
|
1813
1958
|
const relN = relation !== void 0 ? toNode(relation, "relation") : void 0;
|
|
1814
1959
|
const deps = relN ? [adjacencyOut, adjacencyIn, idN, relN] : [adjacencyOut, adjacencyIn, idN];
|
|
1815
|
-
return (0,
|
|
1960
|
+
return (0, import_core11.node)(
|
|
1816
1961
|
deps,
|
|
1817
1962
|
(batchData, actions, ctx) => {
|
|
1818
1963
|
const values = batchData.map(
|