@facthouse/mcp 0.26.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/LICENSE +21 -0
- package/README.md +611 -0
- package/dist/cli/index.d.ts +30 -0
- package/dist/cli/index.d.ts.map +1 -0
- package/dist/cli/index.js +785 -0
- package/dist/cli/index.js.map +1 -0
- package/dist/cli/init-backfill.d.ts +26 -0
- package/dist/cli/init-backfill.d.ts.map +1 -0
- package/dist/cli/init-backfill.js +56 -0
- package/dist/cli/init-backfill.js.map +1 -0
- package/dist/cli/init-knobs.d.ts +137 -0
- package/dist/cli/init-knobs.d.ts.map +1 -0
- package/dist/cli/init-knobs.js +400 -0
- package/dist/cli/init-knobs.js.map +1 -0
- package/dist/cli/init-wizard.d.ts +67 -0
- package/dist/cli/init-wizard.d.ts.map +1 -0
- package/dist/cli/init-wizard.js +319 -0
- package/dist/cli/init-wizard.js.map +1 -0
- package/dist/cli/init.d.ts +124 -0
- package/dist/cli/init.d.ts.map +1 -0
- package/dist/cli/init.js +286 -0
- package/dist/cli/init.js.map +1 -0
- package/dist/cli/inspect-html.d.ts +15 -0
- package/dist/cli/inspect-html.d.ts.map +1 -0
- package/dist/cli/inspect-html.js +491 -0
- package/dist/cli/inspect-html.js.map +1 -0
- package/dist/cli/inspect-intelligence.d.ts +8 -0
- package/dist/cli/inspect-intelligence.d.ts.map +1 -0
- package/dist/cli/inspect-intelligence.js +103 -0
- package/dist/cli/inspect-intelligence.js.map +1 -0
- package/dist/cli/inspect-model.d.ts +42 -0
- package/dist/cli/inspect-model.d.ts.map +1 -0
- package/dist/cli/inspect-model.js +108 -0
- package/dist/cli/inspect-model.js.map +1 -0
- package/dist/cli/inspect-payload.d.ts +122 -0
- package/dist/cli/inspect-payload.d.ts.map +1 -0
- package/dist/cli/inspect-payload.js +338 -0
- package/dist/cli/inspect-payload.js.map +1 -0
- package/dist/cli/inspect-theme.d.ts +44 -0
- package/dist/cli/inspect-theme.d.ts.map +1 -0
- package/dist/cli/inspect-theme.js +118 -0
- package/dist/cli/inspect-theme.js.map +1 -0
- package/dist/cli/inspect.d.ts +24 -0
- package/dist/cli/inspect.d.ts.map +1 -0
- package/dist/cli/inspect.js +172 -0
- package/dist/cli/inspect.js.map +1 -0
- package/dist/cli/log-event.d.ts +55 -0
- package/dist/cli/log-event.d.ts.map +1 -0
- package/dist/cli/log-event.js +149 -0
- package/dist/cli/log-event.js.map +1 -0
- package/dist/cli/package-version.d.ts +2 -0
- package/dist/cli/package-version.d.ts.map +1 -0
- package/dist/cli/package-version.js +15 -0
- package/dist/cli/package-version.js.map +1 -0
- package/dist/cli/query.d.ts +53 -0
- package/dist/cli/query.d.ts.map +1 -0
- package/dist/cli/query.js +325 -0
- package/dist/cli/query.js.map +1 -0
- package/dist/cli/record.d.ts +55 -0
- package/dist/cli/record.d.ts.map +1 -0
- package/dist/cli/record.js +149 -0
- package/dist/cli/record.js.map +1 -0
- package/dist/cli/settings.d.ts +26 -0
- package/dist/cli/settings.d.ts.map +1 -0
- package/dist/cli/settings.js +161 -0
- package/dist/cli/settings.js.map +1 -0
- package/dist/cli/spend-dashboard.d.ts +53 -0
- package/dist/cli/spend-dashboard.d.ts.map +1 -0
- package/dist/cli/spend-dashboard.js +297 -0
- package/dist/cli/spend-dashboard.js.map +1 -0
- package/dist/cli/stats-html.d.ts +20 -0
- package/dist/cli/stats-html.d.ts.map +1 -0
- package/dist/cli/stats-html.js +879 -0
- package/dist/cli/stats-html.js.map +1 -0
- package/dist/cli/web.d.ts +60 -0
- package/dist/cli/web.d.ts.map +1 -0
- package/dist/cli/web.js +416 -0
- package/dist/cli/web.js.map +1 -0
- package/dist/config.d.ts +102 -0
- package/dist/config.d.ts.map +1 -0
- package/dist/config.js +302 -0
- package/dist/config.js.map +1 -0
- package/dist/db/connection.d.ts +96 -0
- package/dist/db/connection.d.ts.map +1 -0
- package/dist/db/connection.js +200 -0
- package/dist/db/connection.js.map +1 -0
- package/dist/db/consolidation-lock.d.ts +16 -0
- package/dist/db/consolidation-lock.d.ts.map +1 -0
- package/dist/db/consolidation-lock.js +67 -0
- package/dist/db/consolidation-lock.js.map +1 -0
- package/dist/db/consolidations.d.ts +41 -0
- package/dist/db/consolidations.d.ts.map +1 -0
- package/dist/db/consolidations.js +165 -0
- package/dist/db/consolidations.js.map +1 -0
- package/dist/db/disk-budget.d.ts +44 -0
- package/dist/db/disk-budget.d.ts.map +1 -0
- package/dist/db/disk-budget.js +177 -0
- package/dist/db/disk-budget.js.map +1 -0
- package/dist/db/domains.d.ts +14 -0
- package/dist/db/domains.d.ts.map +1 -0
- package/dist/db/domains.js +37 -0
- package/dist/db/domains.js.map +1 -0
- package/dist/db/embeddings-hnsw.d.ts +30 -0
- package/dist/db/embeddings-hnsw.d.ts.map +1 -0
- package/dist/db/embeddings-hnsw.js +129 -0
- package/dist/db/embeddings-hnsw.js.map +1 -0
- package/dist/db/embeddings.d.ts +68 -0
- package/dist/db/embeddings.d.ts.map +1 -0
- package/dist/db/embeddings.js +139 -0
- package/dist/db/embeddings.js.map +1 -0
- package/dist/db/entities.d.ts +157 -0
- package/dist/db/entities.d.ts.map +1 -0
- package/dist/db/entities.js +489 -0
- package/dist/db/entities.js.map +1 -0
- package/dist/db/extract-watermarks.d.ts +55 -0
- package/dist/db/extract-watermarks.d.ts.map +1 -0
- package/dist/db/extract-watermarks.js +171 -0
- package/dist/db/extract-watermarks.js.map +1 -0
- package/dist/db/facts.d.ts +117 -0
- package/dist/db/facts.d.ts.map +1 -0
- package/dist/db/facts.js +326 -0
- package/dist/db/facts.js.map +1 -0
- package/dist/db/index.d.ts +26 -0
- package/dist/db/index.d.ts.map +1 -0
- package/dist/db/index.js +23 -0
- package/dist/db/index.js.map +1 -0
- package/dist/db/inferences.d.ts +36 -0
- package/dist/db/inferences.d.ts.map +1 -0
- package/dist/db/inferences.js +212 -0
- package/dist/db/inferences.js.map +1 -0
- package/dist/db/intelligence-runs.d.ts +20 -0
- package/dist/db/intelligence-runs.d.ts.map +1 -0
- package/dist/db/intelligence-runs.js +60 -0
- package/dist/db/intelligence-runs.js.map +1 -0
- package/dist/db/pg-backend.d.ts +14 -0
- package/dist/db/pg-backend.d.ts.map +1 -0
- package/dist/db/pg-backend.js +53 -0
- package/dist/db/pg-backend.js.map +1 -0
- package/dist/db/postgres-schema.d.ts +13 -0
- package/dist/db/postgres-schema.d.ts.map +1 -0
- package/dist/db/postgres-schema.js +392 -0
- package/dist/db/postgres-schema.js.map +1 -0
- package/dist/db/postgres.d.ts +30 -0
- package/dist/db/postgres.d.ts.map +1 -0
- package/dist/db/postgres.js +154 -0
- package/dist/db/postgres.js.map +1 -0
- package/dist/db/prune.d.ts +67 -0
- package/dist/db/prune.d.ts.map +1 -0
- package/dist/db/prune.js +113 -0
- package/dist/db/prune.js.map +1 -0
- package/dist/db/scheduler-signal.d.ts +20 -0
- package/dist/db/scheduler-signal.d.ts.map +1 -0
- package/dist/db/scheduler-signal.js +32 -0
- package/dist/db/scheduler-signal.js.map +1 -0
- package/dist/db/schema-version.d.ts +7 -0
- package/dist/db/schema-version.d.ts.map +1 -0
- package/dist/db/schema-version.js +7 -0
- package/dist/db/schema-version.js.map +1 -0
- package/dist/db/schema.d.ts +12 -0
- package/dist/db/schema.d.ts.map +1 -0
- package/dist/db/schema.js +983 -0
- package/dist/db/schema.js.map +1 -0
- package/dist/db/session-facts.d.ts +108 -0
- package/dist/db/session-facts.d.ts.map +1 -0
- package/dist/db/session-facts.js +244 -0
- package/dist/db/session-facts.js.map +1 -0
- package/dist/db/sessions.d.ts +85 -0
- package/dist/db/sessions.d.ts.map +1 -0
- package/dist/db/sessions.js +169 -0
- package/dist/db/sessions.js.map +1 -0
- package/dist/db/sources.d.ts +22 -0
- package/dist/db/sources.d.ts.map +1 -0
- package/dist/db/sources.js +43 -0
- package/dist/db/sources.js.map +1 -0
- package/dist/db/stats.d.ts +94 -0
- package/dist/db/stats.d.ts.map +1 -0
- package/dist/db/stats.js +79 -0
- package/dist/db/stats.js.map +1 -0
- package/dist/db/store.d.ts +19 -0
- package/dist/db/store.d.ts.map +1 -0
- package/dist/db/store.js +58 -0
- package/dist/db/store.js.map +1 -0
- package/dist/db/watermarks.d.ts +20 -0
- package/dist/db/watermarks.d.ts.map +1 -0
- package/dist/db/watermarks.js +30 -0
- package/dist/db/watermarks.js.map +1 -0
- package/dist/embedding/ollama.d.ts +31 -0
- package/dist/embedding/ollama.d.ts.map +1 -0
- package/dist/embedding/ollama.js +148 -0
- package/dist/embedding/ollama.js.map +1 -0
- package/dist/embedding/provider.d.ts +37 -0
- package/dist/embedding/provider.d.ts.map +1 -0
- package/dist/embedding/provider.js +71 -0
- package/dist/embedding/provider.js.map +1 -0
- package/dist/embedding/types.d.ts +61 -0
- package/dist/embedding/types.d.ts.map +1 -0
- package/dist/embedding/types.js +13 -0
- package/dist/embedding/types.js.map +1 -0
- package/dist/embedding/voyage.d.ts +31 -0
- package/dist/embedding/voyage.d.ts.map +1 -0
- package/dist/embedding/voyage.js +105 -0
- package/dist/embedding/voyage.js.map +1 -0
- package/dist/identity.d.ts +32 -0
- package/dist/identity.d.ts.map +1 -0
- package/dist/identity.js +53 -0
- package/dist/identity.js.map +1 -0
- package/dist/index.d.ts +9 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +275 -0
- package/dist/index.js.map +1 -0
- package/dist/intelligence/backing.d.ts +19 -0
- package/dist/intelligence/backing.d.ts.map +1 -0
- package/dist/intelligence/backing.js +88 -0
- package/dist/intelligence/backing.js.map +1 -0
- package/dist/intelligence/cli.d.ts +90 -0
- package/dist/intelligence/cli.d.ts.map +1 -0
- package/dist/intelligence/cli.js +823 -0
- package/dist/intelligence/cli.js.map +1 -0
- package/dist/intelligence/consolidate.d.ts +84 -0
- package/dist/intelligence/consolidate.d.ts.map +1 -0
- package/dist/intelligence/consolidate.js +1234 -0
- package/dist/intelligence/consolidate.js.map +1 -0
- package/dist/intelligence/extract-prompt.d.ts +78 -0
- package/dist/intelligence/extract-prompt.d.ts.map +1 -0
- package/dist/intelligence/extract-prompt.js +146 -0
- package/dist/intelligence/extract-prompt.js.map +1 -0
- package/dist/intelligence/heuristic.d.ts +15 -0
- package/dist/intelligence/heuristic.d.ts.map +1 -0
- package/dist/intelligence/heuristic.js +224 -0
- package/dist/intelligence/heuristic.js.map +1 -0
- package/dist/intelligence/http.d.ts +77 -0
- package/dist/intelligence/http.d.ts.map +1 -0
- package/dist/intelligence/http.js +496 -0
- package/dist/intelligence/http.js.map +1 -0
- package/dist/intelligence/provider-type.d.ts +6 -0
- package/dist/intelligence/provider-type.d.ts.map +1 -0
- package/dist/intelligence/provider-type.js +18 -0
- package/dist/intelligence/provider-type.js.map +1 -0
- package/dist/intelligence/provider.d.ts +49 -0
- package/dist/intelligence/provider.d.ts.map +1 -0
- package/dist/intelligence/provider.js +52 -0
- package/dist/intelligence/provider.js.map +1 -0
- package/dist/intelligence/related-k.d.ts +15 -0
- package/dist/intelligence/related-k.d.ts.map +1 -0
- package/dist/intelligence/related-k.js +57 -0
- package/dist/intelligence/related-k.js.map +1 -0
- package/dist/intelligence/routing-view.d.ts +33 -0
- package/dist/intelligence/routing-view.d.ts.map +1 -0
- package/dist/intelligence/routing-view.js +54 -0
- package/dist/intelligence/routing-view.js.map +1 -0
- package/dist/intelligence/sampling.d.ts +20 -0
- package/dist/intelligence/sampling.d.ts.map +1 -0
- package/dist/intelligence/sampling.js +324 -0
- package/dist/intelligence/sampling.js.map +1 -0
- package/dist/intelligence/stage-router.d.ts +32 -0
- package/dist/intelligence/stage-router.d.ts.map +1 -0
- package/dist/intelligence/stage-router.js +251 -0
- package/dist/intelligence/stage-router.js.map +1 -0
- package/dist/intelligence/steps.d.ts +65 -0
- package/dist/intelligence/steps.d.ts.map +1 -0
- package/dist/intelligence/steps.js +86 -0
- package/dist/intelligence/steps.js.map +1 -0
- package/dist/intelligence/subject.d.ts +42 -0
- package/dist/intelligence/subject.d.ts.map +1 -0
- package/dist/intelligence/subject.js +44 -0
- package/dist/intelligence/subject.js.map +1 -0
- package/dist/intelligence/token-budget.d.ts +86 -0
- package/dist/intelligence/token-budget.d.ts.map +1 -0
- package/dist/intelligence/token-budget.js +312 -0
- package/dist/intelligence/token-budget.js.map +1 -0
- package/dist/intelligence/types.d.ts +179 -0
- package/dist/intelligence/types.d.ts.map +1 -0
- package/dist/intelligence/types.js +7 -0
- package/dist/intelligence/types.js.map +1 -0
- package/dist/intelligence/usage.d.ts +104 -0
- package/dist/intelligence/usage.d.ts.map +1 -0
- package/dist/intelligence/usage.js +233 -0
- package/dist/intelligence/usage.js.map +1 -0
- package/dist/ipc/scheduler-ipc.d.ts +52 -0
- package/dist/ipc/scheduler-ipc.d.ts.map +1 -0
- package/dist/ipc/scheduler-ipc.js +214 -0
- package/dist/ipc/scheduler-ipc.js.map +1 -0
- package/dist/paths.d.ts +29 -0
- package/dist/paths.d.ts.map +1 -0
- package/dist/paths.js +47 -0
- package/dist/paths.js.map +1 -0
- package/dist/scheduler.d.ts +39 -0
- package/dist/scheduler.d.ts.map +1 -0
- package/dist/scheduler.js +93 -0
- package/dist/scheduler.js.map +1 -0
- package/dist/schemas/domains.d.ts +89 -0
- package/dist/schemas/domains.d.ts.map +1 -0
- package/dist/schemas/domains.js +160 -0
- package/dist/schemas/domains.js.map +1 -0
- package/dist/schemas/starter-vocabulary.d.ts +34 -0
- package/dist/schemas/starter-vocabulary.d.ts.map +1 -0
- package/dist/schemas/starter-vocabulary.js +91 -0
- package/dist/schemas/starter-vocabulary.js.map +1 -0
- package/dist/search/ann.d.ts +36 -0
- package/dist/search/ann.d.ts.map +1 -0
- package/dist/search/ann.js +59 -0
- package/dist/search/ann.js.map +1 -0
- package/dist/search/entity.d.ts +43 -0
- package/dist/search/entity.d.ts.map +1 -0
- package/dist/search/entity.js +147 -0
- package/dist/search/entity.js.map +1 -0
- package/dist/search/episodes.d.ts +28 -0
- package/dist/search/episodes.d.ts.map +1 -0
- package/dist/search/episodes.js +102 -0
- package/dist/search/episodes.js.map +1 -0
- package/dist/search/hnsw-graph.d.ts +35 -0
- package/dist/search/hnsw-graph.d.ts.map +1 -0
- package/dist/search/hnsw-graph.js +177 -0
- package/dist/search/hnsw-graph.js.map +1 -0
- package/dist/search/hnsw-ram.d.ts +29 -0
- package/dist/search/hnsw-ram.d.ts.map +1 -0
- package/dist/search/hnsw-ram.js +95 -0
- package/dist/search/hnsw-ram.js.map +1 -0
- package/dist/search/index.d.ts +119 -0
- package/dist/search/index.d.ts.map +1 -0
- package/dist/search/index.js +420 -0
- package/dist/search/index.js.map +1 -0
- package/dist/search/interlocutor-rank.d.ts +10 -0
- package/dist/search/interlocutor-rank.d.ts.map +1 -0
- package/dist/search/interlocutor-rank.js +21 -0
- package/dist/search/interlocutor-rank.js.map +1 -0
- package/dist/search/key-facts.d.ts +34 -0
- package/dist/search/key-facts.d.ts.map +1 -0
- package/dist/search/key-facts.js +43 -0
- package/dist/search/key-facts.js.map +1 -0
- package/dist/search/profile.d.ts +31 -0
- package/dist/search/profile.d.ts.map +1 -0
- package/dist/search/profile.js +43 -0
- package/dist/search/profile.js.map +1 -0
- package/dist/search/vector.d.ts +90 -0
- package/dist/search/vector.d.ts.map +1 -0
- package/dist/search/vector.js +187 -0
- package/dist/search/vector.js.map +1 -0
- package/dist/sources/claude-code.d.ts +35 -0
- package/dist/sources/claude-code.d.ts.map +1 -0
- package/dist/sources/claude-code.js +401 -0
- package/dist/sources/claude-code.js.map +1 -0
- package/dist/sources/copy.d.ts +58 -0
- package/dist/sources/copy.d.ts.map +1 -0
- package/dist/sources/copy.js +104 -0
- package/dist/sources/copy.js.map +1 -0
- package/dist/sources/cursor.d.ts +44 -0
- package/dist/sources/cursor.d.ts.map +1 -0
- package/dist/sources/cursor.js +99 -0
- package/dist/sources/cursor.js.map +1 -0
- package/dist/sources/jsonl-copy.d.ts +58 -0
- package/dist/sources/jsonl-copy.d.ts.map +1 -0
- package/dist/sources/jsonl-copy.js +195 -0
- package/dist/sources/jsonl-copy.js.map +1 -0
- package/dist/sources/jsonl-ingest.d.ts +58 -0
- package/dist/sources/jsonl-ingest.d.ts.map +1 -0
- package/dist/sources/jsonl-ingest.js +195 -0
- package/dist/sources/jsonl-ingest.js.map +1 -0
- package/dist/sources/pull.d.ts +85 -0
- package/dist/sources/pull.d.ts.map +1 -0
- package/dist/sources/pull.js +145 -0
- package/dist/sources/pull.js.map +1 -0
- package/dist/sources/resolve.d.ts +38 -0
- package/dist/sources/resolve.d.ts.map +1 -0
- package/dist/sources/resolve.js +91 -0
- package/dist/sources/resolve.js.map +1 -0
- package/dist/tools/capture-fact-description.d.ts +18 -0
- package/dist/tools/capture-fact-description.d.ts.map +1 -0
- package/dist/tools/capture-fact-description.js +41 -0
- package/dist/tools/capture-fact-description.js.map +1 -0
- package/dist/tools/fact-manager.d.ts +69 -0
- package/dist/tools/fact-manager.d.ts.map +1 -0
- package/dist/tools/fact-manager.js +332 -0
- package/dist/tools/fact-manager.js.map +1 -0
- package/dist/tools/inference-descriptions.d.ts +8 -0
- package/dist/tools/inference-descriptions.d.ts.map +1 -0
- package/dist/tools/inference-descriptions.js +16 -0
- package/dist/tools/inference-descriptions.js.map +1 -0
- package/dist/tools/inferences.d.ts +11 -0
- package/dist/tools/inferences.d.ts.map +1 -0
- package/dist/tools/inferences.js +98 -0
- package/dist/tools/inferences.js.map +1 -0
- package/dist/tools/read-tools.d.ts +21 -0
- package/dist/tools/read-tools.d.ts.map +1 -0
- package/dist/tools/read-tools.js +276 -0
- package/dist/tools/read-tools.js.map +1 -0
- package/dist/tools/resources.d.ts +62 -0
- package/dist/tools/resources.d.ts.map +1 -0
- package/dist/tools/resources.js +199 -0
- package/dist/tools/resources.js.map +1 -0
- package/dist/tools/session-manager.d.ts +44 -0
- package/dist/tools/session-manager.d.ts.map +1 -0
- package/dist/tools/session-manager.js +227 -0
- package/dist/tools/session-manager.js.map +1 -0
- package/dist/types/config.d.ts +400 -0
- package/dist/types/config.d.ts.map +1 -0
- package/dist/types/config.js +105 -0
- package/dist/types/config.js.map +1 -0
- package/dist/types/data.d.ts +357 -0
- package/dist/types/data.d.ts.map +1 -0
- package/dist/types/data.js +36 -0
- package/dist/types/data.js.map +1 -0
- package/dist/types/index.d.ts +6 -0
- package/dist/types/index.d.ts.map +1 -0
- package/dist/types/index.js +6 -0
- package/dist/types/index.js.map +1 -0
- package/dist/types.d.ts +115 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +6 -0
- package/dist/types.js.map +1 -0
- package/dist/warnings.d.ts.map +1 -0
- package/dist/warnings.js.map +1 -0
- package/package.json +62 -0
|
@@ -0,0 +1,171 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Per-conversation extract clock.
|
|
3
|
+
*
|
|
4
|
+
* `consolidations.last_event_sequence` is an audit of what a run believed
|
|
5
|
+
* the global through was. It is not the live clock: a situation satellite
|
|
6
|
+
* or a historical run row can sit above a neighbour’s unexamined events.
|
|
7
|
+
* This table is how far extract has read each conversation, the same idea
|
|
8
|
+
* as `source_watermarks` for pull (two clocks, independent).
|
|
9
|
+
*/
|
|
10
|
+
/**
|
|
11
|
+
* Map an event row to `extract_watermarks`. Alias the events table `e`.
|
|
12
|
+
* Same order as `conversationRef` / prune: client, then mcp, then the row id.
|
|
13
|
+
*/
|
|
14
|
+
export const EXTRACT_WATERMARK_JOIN = `
|
|
15
|
+
LEFT JOIN extract_watermarks w
|
|
16
|
+
ON w.kind = CASE
|
|
17
|
+
WHEN NULLIF(e.client_session_id, '') IS NOT NULL THEN 'client'
|
|
18
|
+
WHEN NULLIF(e.mcp_session_id, '') IS NOT NULL THEN 'mcp'
|
|
19
|
+
ELSE 'unkeyed'
|
|
20
|
+
END
|
|
21
|
+
AND w.conversation_id = CASE
|
|
22
|
+
WHEN NULLIF(e.client_session_id, '') IS NOT NULL THEN e.client_session_id
|
|
23
|
+
WHEN NULLIF(e.mcp_session_id, '') IS NOT NULL THEN e.mcp_session_id
|
|
24
|
+
ELSE e.id
|
|
25
|
+
END`;
|
|
26
|
+
export const UNEXAMINED_EVENT_PREDICATE = "e.sequence > COALESCE(w.last_event_sequence, 0)";
|
|
27
|
+
/**
|
|
28
|
+
* Largest N such that every `session_events.sequence <= N` has been
|
|
29
|
+
* examined or declined for its conversation. Scalar subquery, one definition,
|
|
30
|
+
* used by prune as well as `extractWatermark()`.
|
|
31
|
+
*/
|
|
32
|
+
export const EXTRACT_WATERMARK_SQL = `COALESCE(
|
|
33
|
+
(SELECT MIN(e.sequence) - 1
|
|
34
|
+
FROM session_events e
|
|
35
|
+
${EXTRACT_WATERMARK_JOIN}
|
|
36
|
+
WHERE ${UNEXAMINED_EVENT_PREDICATE}),
|
|
37
|
+
(SELECT MAX(sequence) FROM session_events),
|
|
38
|
+
0
|
|
39
|
+
)`;
|
|
40
|
+
function refKind(ref) {
|
|
41
|
+
return ref.kind;
|
|
42
|
+
}
|
|
43
|
+
function refId(ref) {
|
|
44
|
+
return ref.id;
|
|
45
|
+
}
|
|
46
|
+
/** Per-conversation mark. Missing row = 0. */
|
|
47
|
+
export async function conversationExtractThrough(db, ref) {
|
|
48
|
+
const row = (await db
|
|
49
|
+
.prepare(`SELECT last_event_sequence AS seq
|
|
50
|
+
FROM extract_watermarks
|
|
51
|
+
WHERE kind = ? AND conversation_id = ?`)
|
|
52
|
+
.get(refKind(ref), refId(ref)));
|
|
53
|
+
return row?.seq ?? 0;
|
|
54
|
+
}
|
|
55
|
+
/**
|
|
56
|
+
* Live global through. Not `MAX(consolidations.last_event_sequence)`.
|
|
57
|
+
*/
|
|
58
|
+
export async function extractWatermark(db) {
|
|
59
|
+
const row = (await db
|
|
60
|
+
.prepare(`SELECT ${EXTRACT_WATERMARK_SQL} AS seq`)
|
|
61
|
+
.get());
|
|
62
|
+
return row?.seq ?? 0;
|
|
63
|
+
}
|
|
64
|
+
/** Events not covered by any extract_watermarks row. */
|
|
65
|
+
export async function unexaminedEventCount(db) {
|
|
66
|
+
const row = (await db
|
|
67
|
+
.prepare(`SELECT COUNT(*) AS n
|
|
68
|
+
FROM session_events e
|
|
69
|
+
${EXTRACT_WATERMARK_JOIN}
|
|
70
|
+
WHERE ${UNEXAMINED_EVENT_PREDICATE}`)
|
|
71
|
+
.get());
|
|
72
|
+
return row?.n ?? 0;
|
|
73
|
+
}
|
|
74
|
+
export async function listUnexaminedConversations(db) {
|
|
75
|
+
const rows = (await db
|
|
76
|
+
.prepare(`SELECT
|
|
77
|
+
CASE
|
|
78
|
+
WHEN NULLIF(e.client_session_id, '') IS NOT NULL THEN 'client'
|
|
79
|
+
WHEN NULLIF(e.mcp_session_id, '') IS NOT NULL THEN 'mcp'
|
|
80
|
+
ELSE 'unkeyed'
|
|
81
|
+
END AS kind,
|
|
82
|
+
CASE
|
|
83
|
+
WHEN NULLIF(e.client_session_id, '') IS NOT NULL THEN e.client_session_id
|
|
84
|
+
WHEN NULLIF(e.mcp_session_id, '') IS NOT NULL THEN e.mcp_session_id
|
|
85
|
+
ELSE e.id
|
|
86
|
+
END AS conversation_id,
|
|
87
|
+
MIN(e.sequence) AS min_seq
|
|
88
|
+
FROM session_events e
|
|
89
|
+
${EXTRACT_WATERMARK_JOIN}
|
|
90
|
+
WHERE ${UNEXAMINED_EVENT_PREDICATE}
|
|
91
|
+
GROUP BY 1, 2
|
|
92
|
+
ORDER BY min_seq ASC`)
|
|
93
|
+
.all());
|
|
94
|
+
return rows.map((r) => ({
|
|
95
|
+
kind: r.kind,
|
|
96
|
+
id: r.conversation_id,
|
|
97
|
+
minSequence: r.min_seq,
|
|
98
|
+
}));
|
|
99
|
+
}
|
|
100
|
+
/** Advance a conversation’s mark. Never moves backwards. */
|
|
101
|
+
export async function setConversationExtractThrough(db, ref, sequence) {
|
|
102
|
+
const updated_at = new Date().toISOString();
|
|
103
|
+
await db
|
|
104
|
+
.prepare(`INSERT INTO extract_watermarks
|
|
105
|
+
(kind, conversation_id, last_event_sequence, updated_at)
|
|
106
|
+
VALUES (?, ?, ?, ?)
|
|
107
|
+
ON CONFLICT(kind, conversation_id) DO UPDATE SET
|
|
108
|
+
last_event_sequence = excluded.last_event_sequence,
|
|
109
|
+
updated_at = excluded.updated_at
|
|
110
|
+
WHERE excluded.last_event_sequence > extract_watermarks.last_event_sequence`)
|
|
111
|
+
.run(refKind(ref), refId(ref), sequence, updated_at);
|
|
112
|
+
}
|
|
113
|
+
/**
|
|
114
|
+
* Policy-off / test helper: every conversation is declined through its
|
|
115
|
+
* current max sequence. Does not invent extract. Does not go backwards.
|
|
116
|
+
*/
|
|
117
|
+
export async function advanceExtractMarksToCurrentMax(db) {
|
|
118
|
+
const rows = (await db
|
|
119
|
+
.prepare(`SELECT
|
|
120
|
+
CASE
|
|
121
|
+
WHEN NULLIF(e.client_session_id, '') IS NOT NULL THEN 'client'
|
|
122
|
+
WHEN NULLIF(e.mcp_session_id, '') IS NOT NULL THEN 'mcp'
|
|
123
|
+
ELSE 'unkeyed'
|
|
124
|
+
END AS kind,
|
|
125
|
+
CASE
|
|
126
|
+
WHEN NULLIF(e.client_session_id, '') IS NOT NULL THEN e.client_session_id
|
|
127
|
+
WHEN NULLIF(e.mcp_session_id, '') IS NOT NULL THEN e.mcp_session_id
|
|
128
|
+
ELSE e.id
|
|
129
|
+
END AS conversation_id,
|
|
130
|
+
MAX(e.sequence) AS mx
|
|
131
|
+
FROM session_events e
|
|
132
|
+
GROUP BY 1, 2`)
|
|
133
|
+
.all());
|
|
134
|
+
for (const row of rows) {
|
|
135
|
+
await setConversationExtractThrough(db, { kind: row.kind, id: row.conversation_id }, row.mx);
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
/**
|
|
139
|
+
* v19 seed: the old global MAX still means every event at or below it was
|
|
140
|
+
* examined or declined. Copy that onto per-conversation rows so a finished
|
|
141
|
+
* store is not re-extracted. Reads `MAX(consolidations.last_event_sequence)`
|
|
142
|
+
* once, as history, then never again as a live clock.
|
|
143
|
+
*/
|
|
144
|
+
export async function seedExtractWatermarksFromConsolidations(db) {
|
|
145
|
+
const updated_at = new Date().toISOString();
|
|
146
|
+
await db
|
|
147
|
+
.prepare(`INSERT OR IGNORE INTO extract_watermarks
|
|
148
|
+
(kind, conversation_id, last_event_sequence, updated_at)
|
|
149
|
+
SELECT kind, cid, MAX(sequence), ?
|
|
150
|
+
FROM (
|
|
151
|
+
SELECT
|
|
152
|
+
CASE
|
|
153
|
+
WHEN NULLIF(client_session_id, '') IS NOT NULL THEN 'client'
|
|
154
|
+
WHEN NULLIF(mcp_session_id, '') IS NOT NULL THEN 'mcp'
|
|
155
|
+
ELSE 'unkeyed'
|
|
156
|
+
END AS kind,
|
|
157
|
+
CASE
|
|
158
|
+
WHEN NULLIF(client_session_id, '') IS NOT NULL THEN client_session_id
|
|
159
|
+
WHEN NULLIF(mcp_session_id, '') IS NOT NULL THEN mcp_session_id
|
|
160
|
+
ELSE id
|
|
161
|
+
END AS cid,
|
|
162
|
+
sequence
|
|
163
|
+
FROM session_events
|
|
164
|
+
WHERE sequence <= (
|
|
165
|
+
SELECT COALESCE(MAX(last_event_sequence), 0) FROM consolidations
|
|
166
|
+
)
|
|
167
|
+
)
|
|
168
|
+
GROUP BY kind, cid`)
|
|
169
|
+
.run(updated_at);
|
|
170
|
+
}
|
|
171
|
+
//# sourceMappingURL=extract-watermarks.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"extract-watermarks.js","sourceRoot":"","sources":["../../src/db/extract-watermarks.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AASH;;;GAGG;AACH,MAAM,CAAC,MAAM,sBAAsB,GAAG;;;;;;;;;;;WAW3B,CAAC;AAEZ,MAAM,CAAC,MAAM,0BAA0B,GACrC,iDAAiD,CAAC;AAEpD;;;;GAIG;AACH,MAAM,CAAC,MAAM,qBAAqB,GAAG;;;SAG5B,sBAAsB;cACjB,0BAA0B;;;IAGpC,CAAC;AAQL,SAAS,OAAO,CAAC,GAA2B;IAC1C,OAAO,GAAG,CAAC,IAAI,CAAC;AAClB,CAAC;AAED,SAAS,KAAK,CAAC,GAA2B;IACxC,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AAC,CAAC,CAAC;AACN,CAAC;AAED,4DAA4D;AAC5D,MAAM,CAAC,KAAK,UAAU,6BAA6B,CACjD,EAAM,EACN,GAA2B,EAC3B,QAAgB;IAEhB,MAAM,UAAU,GAAG,IAAI,IAAI,EAAE,CAAC,WAAW,EAAE,CAAC;IAC5C,MAAM,EAAE;SACL,OAAO,CACN;;;;;;mFAM6E,CAC9E;SACA,GAAG,CAAC,OAAO,CAAC,GAAG,CAAC,EAAE,KAAK,CAAC,GAAG,CAAC,EAAE,QAAQ,EAAE,UAAU,CAAC,CAAC;AACzD,CAAC;AAED;;;GAGG;AACH,MAAM,CAAC,KAAK,UAAU,+BAA+B,CAAC,EAAM;IAC1D,MAAM,IAAI,GAAG,CAAC,MAAM,EAAE;SACnB,OAAO,CACN;;;;;;;;;;;;;sBAagB,CACjB;SACA,GAAG,EAAE,CAIN,CAAC;IACH,KAAK,MAAM,GAAG,IAAI,IAAI,EAAE,CAAC;QACvB,MAAM,6BAA6B,CACjC,EAAE,EACF,EAAE,IAAI,EAAE,GAAG,CAAC,IAAI,EAAE,EAAE,EAAE,GAAG,CAAC,eAAe,EAAE,EAC3C,GAAG,CAAC,EAAE,CACP,CAAC;IACJ,CAAC;AACH,CAAC;AAED;;;;;GAKG;AACH,MAAM,CAAC,KAAK,UAAU,uCAAuC,CAC3D,EAAM;IAEN,MAAM,UAAU,GAAG,IAAI,IAAI,EAAE,CAAC,WAAW,EAAE,CAAC;IAC5C,MAAM,EAAE;SACL,OAAO,CACN;;;;;;;;;;;;;;;;;;;;;2BAqBqB,CACtB;SACA,GAAG,CAAC,UAAU,CAAC,CAAC;AACrB,CAAC"}
|
|
@@ -0,0 +1,117 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Data access for integrated facts (DIKW: Knowledge layer).
|
|
3
|
+
*/
|
|
4
|
+
import type { Db, SqlParam } from "./connection.js";
|
|
5
|
+
import type { Fact, EntityFact, SpeakerRole, SourceQuality } from "../types/data.js";
|
|
6
|
+
export interface NewFact {
|
|
7
|
+
content: string;
|
|
8
|
+
domain: string;
|
|
9
|
+
subdomain?: string | null;
|
|
10
|
+
confidence?: number;
|
|
11
|
+
importance?: number;
|
|
12
|
+
source_type: string;
|
|
13
|
+
source_tool?: string | null;
|
|
14
|
+
source_id?: string | null;
|
|
15
|
+
valid_from?: string | null;
|
|
16
|
+
session_id?: string | null;
|
|
17
|
+
capture_context?: string | null;
|
|
18
|
+
/** Which intelligence provider produced this fact. Defaults to 'heuristic'. */
|
|
19
|
+
source_quality?: SourceQuality;
|
|
20
|
+
speaker_role?: SpeakerRole | null;
|
|
21
|
+
speaker?: string | null;
|
|
22
|
+
}
|
|
23
|
+
/** Options for a supersession write. */
|
|
24
|
+
export interface SupersedeOpts {
|
|
25
|
+
/**
|
|
26
|
+
* When true, stamp `system_retired_at` on the old fact (bi-temporal mode).
|
|
27
|
+
* Default false — simple mode never writes the fourth clock.
|
|
28
|
+
*/
|
|
29
|
+
retireSystemTime?: boolean;
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* Optional as-of system-time filter on a fact read.
|
|
33
|
+
*
|
|
34
|
+
* `asOfSystemTime` must already be an ISO 8601 instant (`parseSystemTime`).
|
|
35
|
+
* When set, the query is "what the system believed at T" rather than "what
|
|
36
|
+
* is currently true": `created_at <= T AND (system_retired_at IS NULL OR
|
|
37
|
+
* system_retired_at > T)`. That includes superseded facts the store still
|
|
38
|
+
* held at T, and excludes facts it learned afterwards.
|
|
39
|
+
*/
|
|
40
|
+
export interface FactReadOpts {
|
|
41
|
+
asOfSystemTime?: string;
|
|
42
|
+
}
|
|
43
|
+
/**
|
|
44
|
+
* Normalise an as-of system-time argument to an ISO 8601 instant.
|
|
45
|
+
*
|
|
46
|
+
* Stored clocks are `Date.toISOString()` values. Comparing a date-only string
|
|
47
|
+
* against those lexicographically drops every fact written later that UTC day,
|
|
48
|
+
* so this parses through `Date` and re-emits the same format the columns use.
|
|
49
|
+
*/
|
|
50
|
+
export declare function parseSystemTime(input: string): string;
|
|
51
|
+
/**
|
|
52
|
+
* Currency predicate for a fact read — currently true, or believed at T.
|
|
53
|
+
*
|
|
54
|
+
* One definition. Callers that inlined `status = 'active' AND is_latest = 1`
|
|
55
|
+
* would drift the first time either side of this fork changed.
|
|
56
|
+
*/
|
|
57
|
+
export declare function currencyClause(alias?: string, asOfSystemTime?: string): {
|
|
58
|
+
sql: string;
|
|
59
|
+
params: SqlParam[];
|
|
60
|
+
};
|
|
61
|
+
/** Insert a integrated fact. Returns the created Fact.
|
|
62
|
+
* valid_from defaults to now if not provided. Pass null explicitly for unknown validity start (e.g., historical imports). */
|
|
63
|
+
export declare function insertFact(db: Db, fact: NewFact): Promise<Fact>;
|
|
64
|
+
/** Retrieve a fact by ID. */
|
|
65
|
+
export declare function getFact(db: Db, id: string): Promise<Fact | null>;
|
|
66
|
+
/**
|
|
67
|
+
* Retrieve several facts by id, currently-true only — or believed at T when
|
|
68
|
+
* `opts.asOfSystemTime` is set.
|
|
69
|
+
*
|
|
70
|
+
* For hydrating the winners of a ranked scan: the semantic path scores every
|
|
71
|
+
* stored vector but only needs the top handful of fact rows, and one query
|
|
72
|
+
* beats N round trips through `getFact`.
|
|
73
|
+
*
|
|
74
|
+
* Returns in arbitrary order and silently omits ids that are missing or no
|
|
75
|
+
* longer in the requested set — callers hold their own ranking and re-project
|
|
76
|
+
* through it.
|
|
77
|
+
*/
|
|
78
|
+
export declare function getFactsByIds(db: Db, ids: string[], opts?: FactReadOpts): Promise<Fact[]>;
|
|
79
|
+
/** Get all currently-true facts for a domain — or those believed at T. */
|
|
80
|
+
export declare function getFactsByDomain(db: Db, domain: string, subdomain?: string, opts?: FactReadOpts): Promise<Fact[]>;
|
|
81
|
+
/** Get facts linked to an entity. */
|
|
82
|
+
export declare function getFactsByEntity(db: Db, entityId: string, opts?: FactReadOpts): Promise<EntityFact[]>;
|
|
83
|
+
/**
|
|
84
|
+
* Facts the system believed at instant T.
|
|
85
|
+
*
|
|
86
|
+
* `created_at <= T AND (system_retired_at IS NULL OR system_retired_at > T)`.
|
|
87
|
+
* In simple mode `system_retired_at` is never written, so this is not a
|
|
88
|
+
* meaningful audit — callers that expose it must gate on bi-temporal mode.
|
|
89
|
+
*/
|
|
90
|
+
export declare function getFactsAsOfSystemTime(db: Db, at: string, limit?: number): Promise<Fact[]>;
|
|
91
|
+
/** Supersede a fact: mark old as superseded, insert new. Returns the new Fact.
|
|
92
|
+
* valid_from on the replacement is the stated world-time if given, otherwise
|
|
93
|
+
* now — a preference change becomes true at supersession; a dated correction
|
|
94
|
+
* keeps the day extract resolved.
|
|
95
|
+
* Throws if oldId does not exist.
|
|
96
|
+
* `system_retired_at` is written only when `opts.retireSystemTime` is true
|
|
97
|
+
* (bi-temporal mode). Simple mode — the default — never populates it. */
|
|
98
|
+
export declare function supersedeFact(db: Db, oldId: string, newFact: NewFact, opts?: SupersedeOpts): Promise<Fact>;
|
|
99
|
+
/**
|
|
100
|
+
* Strip FTS5 operators from a query string so it can be safely passed to MATCH.
|
|
101
|
+
* Wraps each whitespace-delimited term in double quotes to force literal matching.
|
|
102
|
+
* Note: this is per-term matching, not phrase matching. "hiking in mountains"
|
|
103
|
+
* becomes three separate term matches, not a phrase.
|
|
104
|
+
* Returns empty string if input is empty/whitespace-only.
|
|
105
|
+
*/
|
|
106
|
+
export declare function sanitiseFtsQuery(query: string): string;
|
|
107
|
+
/** User text for `plainto_tsquery`. Accepts raw or FTS5-quoted sanitiseFtsQuery output. */
|
|
108
|
+
export declare function ftsQueryText(query: string): string | null;
|
|
109
|
+
/** Keyword search via FTS5. Returns facts with BM25 rank.
|
|
110
|
+
* @throws {SqliteError} on malformed FTS5 syntax. Use sanitiseFtsQuery for untrusted input. */
|
|
111
|
+
export declare function keywordSearch(db: Db, query: string, limit?: number, opts?: FactReadOpts): Promise<Array<{
|
|
112
|
+
fact: Fact;
|
|
113
|
+
rank: number;
|
|
114
|
+
}>>;
|
|
115
|
+
/** Increment access_count for a fact. */
|
|
116
|
+
export declare function incrementFactAccess(db: Db, factId: string): Promise<void>;
|
|
117
|
+
//# sourceMappingURL=facts.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"facts.d.ts","sourceRoot":"","sources":["../../src/db/facts.ts"],"names":[],"mappings":"AAAA;;GAEG;AAIH,OAAO,KAAK,EAAE,EAAE,EAAE,QAAQ,EAAE,MAAM,iBAAiB,CAAC;AACpD,OAAO,KAAK,EAAE,IAAI,EAAE,UAAU,EAAE,WAAW,EAAE,aAAa,EAAE,MAAM,kBAAkB,CAAC;AAUrF,MAAM,WAAW,OAAO;IACtB,OAAO,EAAE,MAAM,CAAC;IAChB,MAAM,EAAE,MAAM,CAAC;IACf,SAAS,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IAC1B,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,WAAW,EAAE,MAAM,CAAC;IACpB,WAAW,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IAC5B,SAAS,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IAC1B,UAAU,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IAC3B,UAAU,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IAC3B,eAAe,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IAChC,+EAA+E;IAC/E,cAAc,CAAC,EAAE,aAAa,CAAC;IAC/B,YAAY,CAAC,EAAE,WAAW,GAAG,IAAI,CAAC;IAClC,OAAO,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;CACzB;AAED,wCAAwC;AACxC,MAAM,WAAW,aAAa;IAC5B;;;OAGG;IACH,gBAAgB,CAAC,EAAE,OAAO,CAAC;CAC5B;AAED;;;;;;;;GAQG;AACH,MAAM,WAAW,YAAY;IAC3B,cAAc,CAAC,EAAE,MAAM,CAAC;CACzB;AAYD;;;;;;GAMG;AACH,wBAAgB,eAAe,CAAC,KAAK,EAAE,MAAM,GAA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AE,aAAa,GACnB,OAAO,CAAC,IAAI,CAAC,CA4Ff;AAED;;;;;;GAMG;AACH,wBAAgB,gBAAgB,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,CAItD;AAED,2FAA2F;AAC3F,wBAAgB,YAAY,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,GAAG,IAAI,CAGzD;AAED;gGACgG;AAChG,wBAAsB,aAAa,CACjC,EAAE,EAAE,EAAE,EACN,KAAK,EAAE,MAAM,EACb,KAAK,CAAC,EAAE,MAAM,EACd,IAAI,CAAC,EAAE,YAAY,GAClB,OAAO,CAAC,KAAK,CAAC;IAAE,IAAI,EAAE,IAAI,CAAC;IAAC,IAAI,EAAE,MAAM,CAAA;CAAE,CAAC,CAAC,CAyC9C;AAED,yCAAyC;AACzC,wBAAsB,mBAAmB,CACvC,EAAE,EAAE,EAAE,EACN,MAAM,EAAE,MAAM,GACb,OAAO,CAAC,IAAI,CAAC,CAIf"}
|
package/dist/db/facts.js
ADDED
|
@@ -0,0 +1,326 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Data access for integrated facts (DIKW: Knowledge layer).
|
|
3
|
+
*/
|
|
4
|
+
import { randomUUID } from "node:crypto";
|
|
5
|
+
import { withTransaction } from "./connection.js";
|
|
6
|
+
// The one reserved relationship value. Imported rather than repeated, because a
|
|
7
|
+
// second copy of a magic string is a second definition with its own future.
|
|
8
|
+
import { SUBJECT_OF } from "./entities.js";
|
|
9
|
+
import { speakerNameOf } from "./session-facts.js";
|
|
10
|
+
function mapFact(row) {
|
|
11
|
+
return { ...row, is_latest: row.is_latest === 1 || row.is_latest === true };
|
|
12
|
+
}
|
|
13
|
+
/**
|
|
14
|
+
* Normalise an as-of system-time argument to an ISO 8601 instant.
|
|
15
|
+
*
|
|
16
|
+
* Stored clocks are `Date.toISOString()` values. Comparing a date-only string
|
|
17
|
+
* against those lexicographically drops every fact written later that UTC day,
|
|
18
|
+
* so this parses through `Date` and re-emits the same format the columns use.
|
|
19
|
+
*/
|
|
20
|
+
export function parseSystemTime(input) {
|
|
21
|
+
const trimmed = input.trim();
|
|
22
|
+
if (!/^\d{4}-\d{2}-\d{2}/.test(trimmed)) {
|
|
23
|
+
throw new Error(`Invalid as-of system time '${input}'. Use an ISO 8601 instant, e.g. 2026-03-15T12:00:00Z.`);
|
|
24
|
+
}
|
|
25
|
+
const parsed = new Date(trimmed);
|
|
26
|
+
if (Number.isNaN(parsed.getTime())) {
|
|
27
|
+
throw new Error(`Invalid as-of system time '${input}'. Use an ISO 8601 instant, e.g. 2026-03-15T12:00:00Z.`);
|
|
28
|
+
}
|
|
29
|
+
return parsed.toISOString();
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* Currency predicate for a fact read — currently true, or believed at T.
|
|
33
|
+
*
|
|
34
|
+
* One definition. Callers that inlined `status = 'active' AND is_latest = 1`
|
|
35
|
+
* would drift the first time either side of this fork changed.
|
|
36
|
+
*/
|
|
37
|
+
export function currencyClause(alias = "", asOfSystemTime) {
|
|
38
|
+
const c = alias ? `${alias}.` : "";
|
|
39
|
+
if (asOfSystemTime !== undefined) {
|
|
40
|
+
return {
|
|
41
|
+
sql: `${c}created_at <= ? AND (${c}system_retired_at IS NULL OR ` +
|
|
42
|
+
`${c}system_retired_at > ?)`,
|
|
43
|
+
params: [asOfSystemTime, asOfSystemTime],
|
|
44
|
+
};
|
|
45
|
+
}
|
|
46
|
+
return {
|
|
47
|
+
sql: `${c}status = 'active' AND ${c}is_latest = 1 ` +
|
|
48
|
+
`AND (${c}valid_until IS NULL OR ${c}valid_until > datetime('now'))`,
|
|
49
|
+
params: [],
|
|
50
|
+
};
|
|
51
|
+
}
|
|
52
|
+
/** Insert a integrated fact. Returns the created Fact.
|
|
53
|
+
* valid_from defaults to now if not provided. Pass null explicitly for unknown validity start (e.g., historical imports). */
|
|
54
|
+
export async function insertFact(db, fact) {
|
|
55
|
+
const id = randomUUID();
|
|
56
|
+
const now = new Date().toISOString();
|
|
57
|
+
const confidence = fact.confidence ?? 0.7;
|
|
58
|
+
const importance = fact.importance ?? 0.5;
|
|
59
|
+
const subdomain = fact.subdomain ?? null;
|
|
60
|
+
const sourceTool = fact.source_tool ?? null;
|
|
61
|
+
const sourceId = fact.source_id ?? null;
|
|
62
|
+
const validFrom = fact.valid_from !== undefined ? fact.valid_from : now;
|
|
63
|
+
const sessionId = fact.session_id ?? null;
|
|
64
|
+
const captureContext = fact.capture_context ?? null;
|
|
65
|
+
const sourceQuality = fact.source_quality ?? "heuristic";
|
|
66
|
+
const speakerRole = fact.speaker_role ?? null;
|
|
67
|
+
const speaker = speakerNameOf(fact.speaker);
|
|
68
|
+
const result = await db.prepare(`INSERT INTO facts
|
|
69
|
+
(id, content, domain, subdomain, confidence, importance,
|
|
70
|
+
source_type, source_tool, source_id, status, superseded_by,
|
|
71
|
+
is_latest, created_at, valid_from, valid_until,
|
|
72
|
+
system_retired_at, session_id, capture_context, access_count, source_quality,
|
|
73
|
+
speaker_role, speaker)
|
|
74
|
+
VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, 'active', NULL,
|
|
75
|
+
1, ?, ?, NULL, NULL, ?, ?, 0, ?, ?, ?)`).run(id, fact.content, fact.domain, subdomain, confidence, importance, fact.source_type, sourceTool, sourceId, now, validFrom, sessionId, captureContext, sourceQuality, speakerRole, speaker);
|
|
76
|
+
if (result.changes === 0) {
|
|
77
|
+
throw new Error(`Failed to insert fact '${id}'`);
|
|
78
|
+
}
|
|
79
|
+
return {
|
|
80
|
+
id,
|
|
81
|
+
content: fact.content,
|
|
82
|
+
domain: fact.domain,
|
|
83
|
+
subdomain,
|
|
84
|
+
confidence,
|
|
85
|
+
importance,
|
|
86
|
+
source_type: fact.source_type,
|
|
87
|
+
source_tool: sourceTool,
|
|
88
|
+
source_id: sourceId,
|
|
89
|
+
status: "active",
|
|
90
|
+
superseded_by: null,
|
|
91
|
+
is_latest: true,
|
|
92
|
+
created_at: now,
|
|
93
|
+
valid_from: validFrom,
|
|
94
|
+
valid_until: null,
|
|
95
|
+
system_retired_at: null,
|
|
96
|
+
session_id: sessionId,
|
|
97
|
+
capture_context: captureContext,
|
|
98
|
+
access_count: 0,
|
|
99
|
+
source_quality: sourceQuality,
|
|
100
|
+
speaker_role: speakerRole,
|
|
101
|
+
speaker,
|
|
102
|
+
};
|
|
103
|
+
}
|
|
104
|
+
/** Retrieve a fact by ID. */
|
|
105
|
+
export async function getFact(db, id) {
|
|
106
|
+
const row = (await db.prepare(`SELECT * FROM facts WHERE id = ?`).get(id));
|
|
107
|
+
if (!row)
|
|
108
|
+
return null;
|
|
109
|
+
return mapFact(row);
|
|
110
|
+
}
|
|
111
|
+
/**
|
|
112
|
+
* Retrieve several facts by id, currently-true only — or believed at T when
|
|
113
|
+
* `opts.asOfSystemTime` is set.
|
|
114
|
+
*
|
|
115
|
+
* For hydrating the winners of a ranked scan: the semantic path scores every
|
|
116
|
+
* stored vector but only needs the top handful of fact rows, and one query
|
|
117
|
+
* beats N round trips through `getFact`.
|
|
118
|
+
*
|
|
119
|
+
* Returns in arbitrary order and silently omits ids that are missing or no
|
|
120
|
+
* longer in the requested set — callers hold their own ranking and re-project
|
|
121
|
+
* through it.
|
|
122
|
+
*/
|
|
123
|
+
export async function getFactsByIds(db, ids, opts) {
|
|
124
|
+
if (ids.length === 0)
|
|
125
|
+
return [];
|
|
126
|
+
const placeholders = ids.map(() => "?").join(",");
|
|
127
|
+
const currency = currencyClause("", opts?.asOfSystemTime);
|
|
128
|
+
const rows = (await db
|
|
129
|
+
.prepare(`SELECT * FROM facts
|
|
130
|
+
WHERE id IN (${placeholders})
|
|
131
|
+
AND ${currency.sql}`)
|
|
132
|
+
.all(...ids, ...currency.params));
|
|
133
|
+
return rows.map(mapFact);
|
|
134
|
+
}
|
|
135
|
+
/** Get all currently-true facts for a domain — or those believed at T. */
|
|
136
|
+
export async function getFactsByDomain(db, domain, subdomain, opts) {
|
|
137
|
+
const currency = currencyClause("", opts?.asOfSystemTime);
|
|
138
|
+
let sql = `SELECT * FROM facts
|
|
139
|
+
WHERE domain = ? AND ${currency.sql}`;
|
|
140
|
+
const params = [domain, ...currency.params];
|
|
141
|
+
if (subdomain !== undefined) {
|
|
142
|
+
sql += ` AND subdomain = ?`;
|
|
143
|
+
params.push(subdomain);
|
|
144
|
+
}
|
|
145
|
+
// Deterministic ordering: newest first. Required for stable supersession candidate selection.
|
|
146
|
+
sql += ` ORDER BY created_at DESC`;
|
|
147
|
+
const rows = (await db.prepare(sql).all(...params));
|
|
148
|
+
return rows.map(mapFact);
|
|
149
|
+
}
|
|
150
|
+
/** Get facts linked to an entity. */
|
|
151
|
+
export async function getFactsByEntity(db, entityId, opts) {
|
|
152
|
+
const currency = currencyClause("f", opts?.asOfSystemTime);
|
|
153
|
+
const rows = (await db
|
|
154
|
+
.prepare(
|
|
155
|
+
// Facts *about* this entity come first, then facts that merely name it,
|
|
156
|
+
// and importance orders within each group.
|
|
157
|
+
//
|
|
158
|
+
// Ranking, not filtering. Returning subjects alone would be wrong twice
|
|
159
|
+
// over: "Robin approved Alex's transfer" is worth surfacing when asked
|
|
160
|
+
// about Robin even though it is not about him, and no provider emits
|
|
161
|
+
// subject links yet, so a subject-only query would answer almost every
|
|
162
|
+
// question with nothing. This is the same conclusion the domain gate
|
|
163
|
+
// reached the hard way — a signal that ranks degrades where one that
|
|
164
|
+
// filters fails absolutely.
|
|
165
|
+
//
|
|
166
|
+
// MAX() because an entity can be linked to one fact more than once, with
|
|
167
|
+
// different relationships; the fact is about it if any link says so.
|
|
168
|
+
`SELECT f.*, MAX(fe.relationship = ?) AS is_subject
|
|
169
|
+
FROM facts f
|
|
170
|
+
JOIN fact_entities fe ON f.id = fe.fact_id
|
|
171
|
+
WHERE fe.entity_id = ? AND ${currency.sql}
|
|
172
|
+
GROUP BY f.id
|
|
173
|
+
ORDER BY is_subject DESC, f.importance DESC, f.created_at DESC`)
|
|
174
|
+
.all(SUBJECT_OF, entityId, ...currency.params));
|
|
175
|
+
return rows.map((row) => ({
|
|
176
|
+
...row,
|
|
177
|
+
is_latest: row.is_latest === 1,
|
|
178
|
+
is_subject: row.is_subject === 1,
|
|
179
|
+
}));
|
|
180
|
+
}
|
|
181
|
+
/**
|
|
182
|
+
* Facts the system believed at instant T.
|
|
183
|
+
*
|
|
184
|
+
* `created_at <= T AND (system_retired_at IS NULL OR system_retired_at > T)`.
|
|
185
|
+
* In simple mode `system_retired_at` is never written, so this is not a
|
|
186
|
+
* meaningful audit — callers that expose it must gate on bi-temporal mode.
|
|
187
|
+
*/
|
|
188
|
+
export async function getFactsAsOfSystemTime(db, at, limit = 100) {
|
|
189
|
+
const instant = parseSystemTime(at);
|
|
190
|
+
const currency = currencyClause("", instant);
|
|
191
|
+
const rows = (await db
|
|
192
|
+
.prepare(`SELECT * FROM facts
|
|
193
|
+
WHERE ${currency.sql}
|
|
194
|
+
ORDER BY created_at DESC
|
|
195
|
+
LIMIT ?`)
|
|
196
|
+
.all(...currency.params, limit));
|
|
197
|
+
return rows.map(mapFact);
|
|
198
|
+
}
|
|
199
|
+
/** Supersede a fact: mark old as superseded, insert new. Returns the new Fact.
|
|
200
|
+
* valid_from on the replacement is the stated world-time if given, otherwise
|
|
201
|
+
* now — a preference change becomes true at supersession; a dated correction
|
|
202
|
+
* keeps the day extract resolved.
|
|
203
|
+
* Throws if oldId does not exist.
|
|
204
|
+
* `system_retired_at` is written only when `opts.retireSystemTime` is true
|
|
205
|
+
* (bi-temporal mode). Simple mode — the default — never populates it. */
|
|
206
|
+
export async function supersedeFact(db, oldId, newFact, opts) {
|
|
207
|
+
const newId = randomUUID();
|
|
208
|
+
const now = new Date().toISOString();
|
|
209
|
+
const confidence = newFact.confidence ?? 0.7;
|
|
210
|
+
const importance = newFact.importance ?? 0.5;
|
|
211
|
+
const subdomain = newFact.subdomain ?? null;
|
|
212
|
+
const sourceTool = newFact.source_tool ?? null;
|
|
213
|
+
const sourceId = newFact.source_id ?? null;
|
|
214
|
+
const sessionId = newFact.session_id ?? null;
|
|
215
|
+
const captureContext = newFact.capture_context ?? null;
|
|
216
|
+
const sourceQuality = newFact.source_quality ?? "heuristic";
|
|
217
|
+
const speakerRole = newFact.speaker_role ?? null;
|
|
218
|
+
const speaker = speakerNameOf(newFact.speaker);
|
|
219
|
+
const retireSystemTime = opts?.retireSystemTime === true;
|
|
220
|
+
const validFrom = newFact.valid_from !== undefined && newFact.valid_from !== null
|
|
221
|
+
? newFact.valid_from
|
|
222
|
+
: now;
|
|
223
|
+
const result = await withTransaction(db, async () => {
|
|
224
|
+
const updated = retireSystemTime
|
|
225
|
+
? await db.prepare(`UPDATE facts
|
|
226
|
+
SET status = 'superseded', superseded_by = ?, is_latest = 0,
|
|
227
|
+
valid_until = ?, system_retired_at = ?
|
|
228
|
+
WHERE id = ?`).run(newId, now, now, oldId)
|
|
229
|
+
: await db.prepare(`UPDATE facts
|
|
230
|
+
SET status = 'superseded', superseded_by = ?, is_latest = 0, valid_until = ?
|
|
231
|
+
WHERE id = ?`).run(newId, now, oldId);
|
|
232
|
+
if (updated.changes === 0) {
|
|
233
|
+
throw new Error(`Cannot supersede fact '${oldId}': not found`);
|
|
234
|
+
}
|
|
235
|
+
await db.prepare(`INSERT INTO facts
|
|
236
|
+
(id, content, domain, subdomain, confidence, importance,
|
|
237
|
+
source_type, source_tool, source_id, status, superseded_by,
|
|
238
|
+
is_latest, created_at, valid_from, valid_until,
|
|
239
|
+
system_retired_at, session_id, capture_context, access_count, source_quality,
|
|
240
|
+
speaker_role, speaker)
|
|
241
|
+
VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, 'active', NULL,
|
|
242
|
+
1, ?, ?, NULL, NULL, ?, ?, 0, ?, ?, ?)`).run(newId, newFact.content, newFact.domain, subdomain, confidence, importance, newFact.source_type, sourceTool, sourceId, now, validFrom, sessionId, captureContext, sourceQuality, speakerRole, speaker);
|
|
243
|
+
return {
|
|
244
|
+
id: newId,
|
|
245
|
+
content: newFact.content,
|
|
246
|
+
domain: newFact.domain,
|
|
247
|
+
subdomain,
|
|
248
|
+
confidence,
|
|
249
|
+
importance,
|
|
250
|
+
source_type: newFact.source_type,
|
|
251
|
+
source_tool: sourceTool,
|
|
252
|
+
source_id: sourceId,
|
|
253
|
+
status: "active",
|
|
254
|
+
superseded_by: null,
|
|
255
|
+
is_latest: true,
|
|
256
|
+
created_at: now,
|
|
257
|
+
valid_from: validFrom,
|
|
258
|
+
valid_until: null,
|
|
259
|
+
system_retired_at: null,
|
|
260
|
+
session_id: sessionId,
|
|
261
|
+
capture_context: captureContext,
|
|
262
|
+
access_count: 0,
|
|
263
|
+
source_quality: sourceQuality,
|
|
264
|
+
speaker_role: speakerRole,
|
|
265
|
+
speaker,
|
|
266
|
+
};
|
|
267
|
+
});
|
|
268
|
+
return result;
|
|
269
|
+
}
|
|
270
|
+
/**
|
|
271
|
+
* Strip FTS5 operators from a query string so it can be safely passed to MATCH.
|
|
272
|
+
* Wraps each whitespace-delimited term in double quotes to force literal matching.
|
|
273
|
+
* Note: this is per-term matching, not phrase matching. "hiking in mountains"
|
|
274
|
+
* becomes three separate term matches, not a phrase.
|
|
275
|
+
* Returns empty string if input is empty/whitespace-only.
|
|
276
|
+
*/
|
|
277
|
+
export function sanitiseFtsQuery(query) {
|
|
278
|
+
const terms = query.trim().split(/\s+/).filter(Boolean);
|
|
279
|
+
if (terms.length === 0)
|
|
280
|
+
return "";
|
|
281
|
+
return terms.map((t) => `"${t.replace(/"/g, "")}"`).join(" ");
|
|
282
|
+
}
|
|
283
|
+
/** User text for `plainto_tsquery`. Accepts raw or FTS5-quoted sanitiseFtsQuery output. */
|
|
284
|
+
export function ftsQueryText(query) {
|
|
285
|
+
const text = query.replace(/"/g, " ").replace(/\s+/g, " ").trim();
|
|
286
|
+
return text === "" ? null : text;
|
|
287
|
+
}
|
|
288
|
+
/** Keyword search via FTS5. Returns facts with BM25 rank.
|
|
289
|
+
* @throws {SqliteError} on malformed FTS5 syntax. Use sanitiseFtsQuery for untrusted input. */
|
|
290
|
+
export async function keywordSearch(db, query, limit, opts) {
|
|
291
|
+
const effectiveLimit = limit ?? 20;
|
|
292
|
+
const currency = currencyClause("f", opts?.asOfSystemTime);
|
|
293
|
+
if (db.dialect === "postgres") {
|
|
294
|
+
const text = ftsQueryText(query);
|
|
295
|
+
if (!text)
|
|
296
|
+
return [];
|
|
297
|
+
const rows = (await db
|
|
298
|
+
.prepare(`SELECT f.*, ts_rank(f.content_tsv, q) AS rank
|
|
299
|
+
FROM facts f, plainto_tsquery('simple', ?) q
|
|
300
|
+
WHERE f.content_tsv @@ q AND ${currency.sql}
|
|
301
|
+
ORDER BY rank DESC
|
|
302
|
+
LIMIT ?`)
|
|
303
|
+
.all(text, ...currency.params, effectiveLimit));
|
|
304
|
+
return rows.map((row) => {
|
|
305
|
+
const { rank, ...rest } = row;
|
|
306
|
+
return { fact: mapFact(rest), rank };
|
|
307
|
+
});
|
|
308
|
+
}
|
|
309
|
+
const rows = (await db
|
|
310
|
+
.prepare(`SELECT f.*, fts.rank
|
|
311
|
+
FROM facts_fts fts
|
|
312
|
+
JOIN facts f ON f.rowid = fts.rowid
|
|
313
|
+
WHERE facts_fts MATCH ? AND ${currency.sql}
|
|
314
|
+
ORDER BY fts.rank
|
|
315
|
+
LIMIT ?`)
|
|
316
|
+
.all(query, ...currency.params, effectiveLimit));
|
|
317
|
+
return rows.map((row) => {
|
|
318
|
+
const { rank, ...rest } = row;
|
|
319
|
+
return { fact: mapFact(rest), rank };
|
|
320
|
+
});
|
|
321
|
+
}
|
|
322
|
+
/** Increment access_count for a fact. */
|
|
323
|
+
export async function incrementFactAccess(db, factId) {
|
|
324
|
+
await db.prepare(`UPDATE facts SET access_count = access_count + 1 WHERE id = ?`).run(factId);
|
|
325
|
+
}
|
|
326
|
+
//# sourceMappingURL=facts.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"facts.js","sourceRoot":"","sources":["../../src/db/facts.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,EAAE,UAAU,EAAE,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AAC;QACF,OAAO,IAAI,CAAC,GAAG,CAAC,CAAC,GAAG,EAAE,EAAE;YACtB,MAAM,EAAE,IAAI,EAAE,GAAG,IAAI,EAAE,GAAG,GAAG,CAAC;YAC9B,OAAO,EAAE,IAAI,EAAE,OAAO,CAAC,IAAI,CAAC,EAAE,IAAI,EAAE,CAAC;QACvC,CAAC,CAAC,CAAC;IACL,CAAC;IAED,MAAM,IAAI,GAAG,CAAC,MAAM,EAAE;SACnB,OAAO,CACN;;;qCAG+B,QAAQ,CAAC,GAAG;;eAElC,CACV;SACA,GAAG,CAAC,KAAK,EAAE,GAAG,QAAQ,CAAC,MAAM,EAAE,cAAc,CAAC,CAEhD,CAAC;IAEF,OAAO,IAAI,CAAC,GAAG,CAAC,CAAC,GAAG,EAAE,EAAE;QACtB,MAAM,EAAE,IAAI,EAAE,GAAG,IAAI,EAAE,GAAG,GAAG,CAAC;QAC9B,OAAO,EAAE,IAAI,EAAE,OAAO,CAAC,IAAI,CAAC,EAAE,IAAI,EAAE,CAAC;IACvC,CAAC,CAAC,CAAC;AACL,CAAC;AAED,yCAAyC;AACzC,MAAM,CAAC,KAAK,UAAU,mBAAmB,CACvC,EAAM,EACN,MAAc;IAEd,MAAM,EAAE,CAAC,OAAO,CACd,+DAA+D,CAChE,CAAC,GAAG,CAAC,MAAM,CAAC,CAAC;AAChB,CAAC"}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Barrel re-export for the database layer.
|
|
3
|
+
*/
|
|
4
|
+
export { openDatabase, closeDatabase, withTransaction, pragmaRead, pragmaWrite, } from "./connection.js";
|
|
5
|
+
export type { Db, Dialect } from "./connection.js";
|
|
6
|
+
export { applySchema, getSchemaVersion, SCHEMA_VERSION } from "./schema.js";
|
|
7
|
+
export { attachPostgres, rewriteToPostgres } from "./postgres.js";
|
|
8
|
+
export type { PostgresBackend } from "./postgres.js";
|
|
9
|
+
export { openStore, sqliteMemoryPath, SQLITE_MEMORY_FILENAME } from "./store.js";
|
|
10
|
+
export { createSession, ensureSession, updateLastActivity, getSession, getLatestSession, insertEvent, getEventById, getEvents, getEventCount, conversationRef, } from "./sessions.js";
|
|
11
|
+
export type { NewSession, NewSessionEvent, GetEventsOpts, ConversationRef, } from "./sessions.js";
|
|
12
|
+
export * from "./session-facts.js";
|
|
13
|
+
export * from "./facts.js";
|
|
14
|
+
export * from "./entities.js";
|
|
15
|
+
export * from "./domains.js";
|
|
16
|
+
export * from "./consolidation-lock.js";
|
|
17
|
+
export * from "./sources.js";
|
|
18
|
+
export * from "./watermarks.js";
|
|
19
|
+
export * from "./extract-watermarks.js";
|
|
20
|
+
export * from "./consolidations.js";
|
|
21
|
+
export * from "./stats.js";
|
|
22
|
+
export * from "./intelligence-runs.js";
|
|
23
|
+
export * from "./inferences.js";
|
|
24
|
+
export * from "./disk-budget.js";
|
|
25
|
+
export * from "./prune.js";
|
|
26
|
+
//# sourceMappingURL=index.d.ts.map
|