@atomicmemory/core 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +27 -0
- package/LICENSE +201 -0
- package/README.md +314 -0
- package/dist/app/bind-ephemeral.d.ts +18 -0
- package/dist/app/bind-ephemeral.js +22 -0
- package/dist/app/cors-headers.d.ts +12 -0
- package/dist/app/cors-headers.js +18 -0
- package/dist/app/create-app.d.ts +25 -0
- package/dist/app/create-app.js +156 -0
- package/dist/app/runtime-config-route-snapshot.d.ts +27 -0
- package/dist/app/runtime-config-route-snapshot.js +27 -0
- package/dist/app/runtime-container.d.ts +281 -0
- package/dist/app/runtime-container.js +297 -0
- package/dist/app/startup-checks.d.ts +28 -0
- package/dist/app/startup-checks.js +45 -0
- package/dist/bin.d.ts +17 -0
- package/dist/bin.js +128 -0
- package/dist/config.d.ts +680 -0
- package/dist/config.js +808 -0
- package/dist/db/agent-trust-repository.d.ts +49 -0
- package/dist/db/agent-trust-repository.js +66 -0
- package/dist/db/belief-edges-repository.d.ts +68 -0
- package/dist/db/belief-edges-repository.js +124 -0
- package/dist/db/claim-repository.d.ts +6 -0
- package/dist/db/claim-repository.js +4 -0
- package/dist/db/contradictions-repository.d.ts +56 -0
- package/dist/db/contradictions-repository.js +88 -0
- package/dist/db/document-chunk-repository.d.ts +48 -0
- package/dist/db/document-chunk-repository.js +145 -0
- package/dist/db/document-chunk-types.d.ts +35 -0
- package/dist/db/document-chunk-types.js +9 -0
- package/dist/db/document-list-cursor.d.ts +45 -0
- package/dist/db/document-list-cursor.js +111 -0
- package/dist/db/document-list-repository.d.ts +103 -0
- package/dist/db/document-list-repository.js +204 -0
- package/dist/db/entity-cards-repository.d.ts +37 -0
- package/dist/db/entity-cards-repository.js +46 -0
- package/dist/db/entity-values-repository.d.ts +26 -0
- package/dist/db/entity-values-repository.js +57 -0
- package/dist/db/link-repository.d.ts +30 -0
- package/dist/db/link-repository.js +54 -0
- package/dist/db/memory-repository.d.ts +163 -0
- package/dist/db/memory-repository.js +232 -0
- package/dist/db/migrate.d.ts +6 -0
- package/dist/db/migrate.js +36 -0
- package/dist/db/mmr.d.ts +14 -0
- package/dist/db/mmr.js +57 -0
- package/dist/db/passport-feed-repository.d.ts +91 -0
- package/dist/db/passport-feed-repository.js +198 -0
- package/dist/db/pg-episode-store.d.ts +19 -0
- package/dist/db/pg-episode-store.js +17 -0
- package/dist/db/pg-link-store.d.ts +17 -0
- package/dist/db/pg-link-store.js +14 -0
- package/dist/db/pg-memory-store.d.ts +68 -0
- package/dist/db/pg-memory-store.js +53 -0
- package/dist/db/pg-recap-store.d.ts +13 -0
- package/dist/db/pg-recap-store.js +19 -0
- package/dist/db/pg-representation-store.d.ts +17 -0
- package/dist/db/pg-representation-store.js +17 -0
- package/dist/db/pg-search-store.d.ts +29 -0
- package/dist/db/pg-search-store.js +47 -0
- package/dist/db/pool.d.ts +5 -0
- package/dist/db/pool.js +21 -0
- package/dist/db/ppr.d.ts +56 -0
- package/dist/db/ppr.js +178 -0
- package/dist/db/query-helpers.d.ts +44 -0
- package/dist/db/query-helpers.js +60 -0
- package/dist/db/raw-doc-artifact-sync.d.ts +128 -0
- package/dist/db/raw-doc-artifact-sync.js +259 -0
- package/dist/db/raw-document-blob-repository.d.ts +148 -0
- package/dist/db/raw-document-blob-repository.js +300 -0
- package/dist/db/raw-document-repository.d.ts +104 -0
- package/dist/db/raw-document-repository.js +410 -0
- package/dist/db/raw-document-status-repository.d.ts +122 -0
- package/dist/db/raw-document-status-repository.js +183 -0
- package/dist/db/raw-document-types.d.ts +236 -0
- package/dist/db/raw-document-types.js +10 -0
- package/dist/db/raw-storage-reconciliation-repository.d.ts +110 -0
- package/dist/db/raw-storage-reconciliation-repository.js +200 -0
- package/dist/db/reflection-jobs-repository.d.ts +33 -0
- package/dist/db/reflection-jobs-repository.js +48 -0
- package/dist/db/reflections-repository.d.ts +41 -0
- package/dist/db/reflections-repository.js +83 -0
- package/dist/db/repository-claims.d.ts +141 -0
- package/dist/db/repository-claims.js +376 -0
- package/dist/db/repository-deferred-audn.d.ts +33 -0
- package/dist/db/repository-deferred-audn.js +69 -0
- package/dist/db/repository-document-delete.d.ts +53 -0
- package/dist/db/repository-document-delete.js +156 -0
- package/dist/db/repository-entities.d.ts +114 -0
- package/dist/db/repository-entities.js +317 -0
- package/dist/db/repository-entity-attributes.d.ts +41 -0
- package/dist/db/repository-entity-attributes.js +65 -0
- package/dist/db/repository-entity-graph.d.ts +32 -0
- package/dist/db/repository-entity-graph.js +87 -0
- package/dist/db/repository-first-mentions.d.ts +41 -0
- package/dist/db/repository-first-mentions.js +79 -0
- package/dist/db/repository-lessons.d.ts +51 -0
- package/dist/db/repository-lessons.js +90 -0
- package/dist/db/repository-links.d.ts +26 -0
- package/dist/db/repository-links.js +105 -0
- package/dist/db/repository-observation.d.ts +26 -0
- package/dist/db/repository-observation.js +51 -0
- package/dist/db/repository-read.d.ts +56 -0
- package/dist/db/repository-read.js +271 -0
- package/dist/db/repository-recaps.d.ts +59 -0
- package/dist/db/repository-recaps.js +158 -0
- package/dist/db/repository-representations.d.ts +48 -0
- package/dist/db/repository-representations.js +162 -0
- package/dist/db/repository-temporal-state.d.ts +35 -0
- package/dist/db/repository-temporal-state.js +46 -0
- package/dist/db/repository-tll.d.ts +88 -0
- package/dist/db/repository-tll.js +179 -0
- package/dist/db/repository-types.d.ts +313 -0
- package/dist/db/repository-types.js +142 -0
- package/dist/db/repository-user-profiles.d.ts +17 -0
- package/dist/db/repository-user-profiles.js +28 -0
- package/dist/db/repository-vector-search.d.ts +33 -0
- package/dist/db/repository-vector-search.js +373 -0
- package/dist/db/repository-wipe.d.ts +34 -0
- package/dist/db/repository-wipe.js +94 -0
- package/dist/db/repository-write.d.ts +61 -0
- package/dist/db/repository-write.js +279 -0
- package/dist/db/schema.sql +1355 -0
- package/dist/db/storage-artifact-delete-tx.d.ts +56 -0
- package/dist/db/storage-artifact-delete-tx.js +123 -0
- package/dist/db/storage-artifact-providers.d.ts +21 -0
- package/dist/db/storage-artifact-providers.js +21 -0
- package/dist/db/storage-artifact-recovery-repository.d.ts +66 -0
- package/dist/db/storage-artifact-recovery-repository.js +58 -0
- package/dist/db/storage-artifact-repository.d.ts +329 -0
- package/dist/db/storage-artifact-repository.js +497 -0
- package/dist/db/stores.d.ts +220 -0
- package/dist/db/stores.js +12 -0
- package/dist/db/summaries-repository.d.ts +74 -0
- package/dist/db/summaries-repository.js +125 -0
- package/dist/eval/beam-10m-loader.d.ts +98 -0
- package/dist/eval/beam-10m-loader.js +128 -0
- package/dist/index.d.ts +18 -0
- package/dist/index.js +17 -0
- package/dist/middleware/require-bearer.d.ts +27 -0
- package/dist/middleware/require-bearer.js +60 -0
- package/dist/middleware/validate-response.d.ts +33 -0
- package/dist/middleware/validate-response.js +55 -0
- package/dist/middleware/validate.d.ts +43 -0
- package/dist/middleware/validate.js +85 -0
- package/dist/routes/agents.d.ts +13 -0
- package/dist/routes/agents.js +89 -0
- package/dist/routes/document-response-formatters.d.ts +98 -0
- package/dist/routes/document-response-formatters.js +243 -0
- package/dist/routes/documents.d.ts +74 -0
- package/dist/routes/documents.js +425 -0
- package/dist/routes/memories.d.ts +29 -0
- package/dist/routes/memories.js +725 -0
- package/dist/routes/memory-response-formatters.d.ts +179 -0
- package/dist/routes/memory-response-formatters.js +210 -0
- package/dist/routes/public-raw-storage-metadata.d.ts +54 -0
- package/dist/routes/public-raw-storage-metadata.js +56 -0
- package/dist/routes/reflect.d.ts +14 -0
- package/dist/routes/reflect.js +19 -0
- package/dist/routes/response-schema-map.d.ts +14 -0
- package/dist/routes/response-schema-map.js +69 -0
- package/dist/routes/route-errors.d.ts +12 -0
- package/dist/routes/route-errors.js +30 -0
- package/dist/routes/storage-error-handlers.d.ts +34 -0
- package/dist/routes/storage-error-handlers.js +185 -0
- package/dist/routes/storage-response-formatters.d.ts +44 -0
- package/dist/routes/storage-response-formatters.js +155 -0
- package/dist/routes/storage.d.ts +38 -0
- package/dist/routes/storage.js +369 -0
- package/dist/routes/upstream-provider-errors.d.ts +19 -0
- package/dist/routes/upstream-provider-errors.js +95 -0
- package/dist/schemas/agents.d.ts +79 -0
- package/dist/schemas/agents.js +126 -0
- package/dist/schemas/common.d.ts +110 -0
- package/dist/schemas/common.js +190 -0
- package/dist/schemas/document-list-responses.d.ts +102 -0
- package/dist/schemas/document-list-responses.js +87 -0
- package/dist/schemas/document-list-schemas.d.ts +123 -0
- package/dist/schemas/document-list-schemas.js +174 -0
- package/dist/schemas/document-response-schemas.d.ts +610 -0
- package/dist/schemas/document-response-schemas.js +264 -0
- package/dist/schemas/document-status-envelope.d.ts +48 -0
- package/dist/schemas/document-status-envelope.js +54 -0
- package/dist/schemas/documents.d.ts +292 -0
- package/dist/schemas/documents.js +449 -0
- package/dist/schemas/errors.d.ts +75 -0
- package/dist/schemas/errors.js +105 -0
- package/dist/schemas/memories.d.ts +378 -0
- package/dist/schemas/memories.js +542 -0
- package/dist/schemas/openapi.d.ts +24 -0
- package/dist/schemas/openapi.js +1038 -0
- package/dist/schemas/response-scalars.d.ts +10 -0
- package/dist/schemas/response-scalars.js +10 -0
- package/dist/schemas/responses.d.ts +536 -0
- package/dist/schemas/responses.js +350 -0
- package/dist/schemas/search-response-parts.d.ts +97 -0
- package/dist/schemas/search-response-parts.js +103 -0
- package/dist/schemas/storage-schemas.d.ts +175 -0
- package/dist/schemas/storage-schemas.js +277 -0
- package/dist/schemas/zod-setup.d.ts +15 -0
- package/dist/schemas/zod-setup.js +17 -0
- package/dist/server.d.ts +13 -0
- package/dist/server.js +57 -0
- package/dist/services/abstract-query-policy.d.ts +13 -0
- package/dist/services/abstract-query-policy.js +50 -0
- package/dist/services/affinity-clustering.d.ts +66 -0
- package/dist/services/affinity-clustering.js +125 -0
- package/dist/services/agentic-retrieval.d.ts +38 -0
- package/dist/services/agentic-retrieval.js +126 -0
- package/dist/services/answer-format.d.ts +56 -0
- package/dist/services/answer-format.js +118 -0
- package/dist/services/answer-rescue.d.ts +72 -0
- package/dist/services/answer-rescue.js +177 -0
- package/dist/services/answer-verifier.d.ts +24 -0
- package/dist/services/answer-verifier.js +73 -0
- package/dist/services/api-retry.d.ts +6 -0
- package/dist/services/api-retry.js +41 -0
- package/dist/services/assistant-turn-filter.d.ts +20 -0
- package/dist/services/assistant-turn-filter.js +69 -0
- package/dist/services/atomicmem-uri.d.ts +33 -0
- package/dist/services/atomicmem-uri.js +86 -0
- package/dist/services/audit-events.d.ts +54 -0
- package/dist/services/audit-events.js +56 -0
- package/dist/services/chunked-extraction.d.ts +21 -0
- package/dist/services/chunked-extraction.js +108 -0
- package/dist/services/claim-slotting.d.ts +27 -0
- package/dist/services/claim-slotting.js +38 -0
- package/dist/services/claude-code-llm.d.ts +19 -0
- package/dist/services/claude-code-llm.js +96 -0
- package/dist/services/composite-dedup.d.ts +50 -0
- package/dist/services/composite-dedup.js +153 -0
- package/dist/services/composite-grouping.d.ts +41 -0
- package/dist/services/composite-grouping.js +111 -0
- package/dist/services/composite-staleness.d.ts +20 -0
- package/dist/services/composite-staleness.js +50 -0
- package/dist/services/conciseness-preference.d.ts +14 -0
- package/dist/services/conciseness-preference.js +42 -0
- package/dist/services/conflict-policy.d.ts +20 -0
- package/dist/services/conflict-policy.js +335 -0
- package/dist/services/consensus-extraction.d.ts +39 -0
- package/dist/services/consensus-extraction.js +147 -0
- package/dist/services/consensus-validation.d.ts +52 -0
- package/dist/services/consensus-validation.js +206 -0
- package/dist/services/consolidation-service.d.ts +60 -0
- package/dist/services/consolidation-service.js +171 -0
- package/dist/services/content-detection.d.ts +18 -0
- package/dist/services/content-detection.js +25 -0
- package/dist/services/contradiction-surfacing.d.ts +62 -0
- package/dist/services/contradiction-surfacing.js +111 -0
- package/dist/services/cost-telemetry.d.ts +39 -0
- package/dist/services/cost-telemetry.js +58 -0
- package/dist/services/counter-evidence.d.ts +34 -0
- package/dist/services/counter-evidence.js +92 -0
- package/dist/services/current-state-ranking.d.ts +21 -0
- package/dist/services/current-state-ranking.js +152 -0
- package/dist/services/deferred-audn.d.ts +47 -0
- package/dist/services/deferred-audn.js +162 -0
- package/dist/services/document-chunker.d.ts +50 -0
- package/dist/services/document-chunker.js +153 -0
- package/dist/services/document-failure-markers.d.ts +91 -0
- package/dist/services/document-failure-markers.js +305 -0
- package/dist/services/document-indexer.d.ts +122 -0
- package/dist/services/document-indexer.js +405 -0
- package/dist/services/document-service.d.ts +245 -0
- package/dist/services/document-service.js +325 -0
- package/dist/services/document-upload-artifact-sync.d.ts +80 -0
- package/dist/services/document-upload-artifact-sync.js +162 -0
- package/dist/services/document-upload-beta2-recovery.d.ts +72 -0
- package/dist/services/document-upload-beta2-recovery.js +94 -0
- package/dist/services/document-upload.d.ts +44 -0
- package/dist/services/document-upload.js +353 -0
- package/dist/services/embedding.d.ts +57 -0
- package/dist/services/embedding.js +416 -0
- package/dist/services/entity-attribute-extractor.d.ts +34 -0
- package/dist/services/entity-attribute-extractor.js +117 -0
- package/dist/services/entity-card-synthesis.d.ts +54 -0
- package/dist/services/entity-card-synthesis.js +92 -0
- package/dist/services/entity-dedup.d.ts +9 -0
- package/dist/services/entity-dedup.js +14 -0
- package/dist/services/entity-graph.d.ts +17 -0
- package/dist/services/entity-graph.js +135 -0
- package/dist/services/entropy-gate.d.ts +52 -0
- package/dist/services/entropy-gate.js +56 -0
- package/dist/services/episode-fetcher.d.ts +47 -0
- package/dist/services/episode-fetcher.js +128 -0
- package/dist/services/event-anchor-facts.d.ts +8 -0
- package/dist/services/event-anchor-facts.js +205 -0
- package/dist/services/event-chain-detector.d.ts +52 -0
- package/dist/services/event-chain-detector.js +83 -0
- package/dist/services/extraction-cache.d.ts +9 -0
- package/dist/services/extraction-cache.js +54 -0
- package/dist/services/extraction-enrichment.d.ts +9 -0
- package/dist/services/extraction-enrichment.js +223 -0
- package/dist/services/extraction.d.ts +69 -0
- package/dist/services/extraction.js +596 -0
- package/dist/services/fact-normalization.d.ts +12 -0
- package/dist/services/fact-normalization.js +248 -0
- package/dist/services/filecoin-observability.d.ts +127 -0
- package/dist/services/filecoin-observability.js +200 -0
- package/dist/services/first-mention-service.d.ts +76 -0
- package/dist/services/first-mention-service.js +186 -0
- package/dist/services/hierarchical-retrieval.d.ts +49 -0
- package/dist/services/hierarchical-retrieval.js +50 -0
- package/dist/services/ingest-fact-pipeline.d.ts +32 -0
- package/dist/services/ingest-fact-pipeline.js +212 -0
- package/dist/services/ingest-post-write.d.ts +50 -0
- package/dist/services/ingest-post-write.js +117 -0
- package/dist/services/ingest-trace.d.ts +32 -0
- package/dist/services/ingest-trace.js +60 -0
- package/dist/services/input-sanitizer.d.ts +41 -0
- package/dist/services/input-sanitizer.js +135 -0
- package/dist/services/iterative-retrieval.d.ts +26 -0
- package/dist/services/iterative-retrieval.js +139 -0
- package/dist/services/keyword-expansion.d.ts +10 -0
- package/dist/services/keyword-expansion.js +26 -0
- package/dist/services/lesson-service.d.ts +68 -0
- package/dist/services/lesson-service.js +178 -0
- package/dist/services/literal-extractor.d.ts +16 -0
- package/dist/services/literal-extractor.js +74 -0
- package/dist/services/literal-list-protection.d.ts +17 -0
- package/dist/services/literal-list-protection.js +134 -0
- package/dist/services/literal-query-expansion.d.ts +20 -0
- package/dist/services/literal-query-expansion.js +181 -0
- package/dist/services/llm.d.ts +61 -0
- package/dist/services/llm.js +265 -0
- package/dist/services/memcell-projection.d.ts +17 -0
- package/dist/services/memcell-projection.js +41 -0
- package/dist/services/memory-audn.d.ts +43 -0
- package/dist/services/memory-audn.js +419 -0
- package/dist/services/memory-crud.d.ts +93 -0
- package/dist/services/memory-crud.js +255 -0
- package/dist/services/memory-ingest.d.ts +21 -0
- package/dist/services/memory-ingest.js +249 -0
- package/dist/services/memory-lifecycle.d.ts +75 -0
- package/dist/services/memory-lifecycle.js +108 -0
- package/dist/services/memory-lineage.d.ts +181 -0
- package/dist/services/memory-lineage.js +232 -0
- package/dist/services/memory-network.d.ts +40 -0
- package/dist/services/memory-network.js +75 -0
- package/dist/services/memory-search-types.d.ts +25 -0
- package/dist/services/memory-search-types.js +10 -0
- package/dist/services/memory-search.d.ts +48 -0
- package/dist/services/memory-search.js +505 -0
- package/dist/services/memory-service-types.d.ts +371 -0
- package/dist/services/memory-service-types.js +8 -0
- package/dist/services/memory-service.d.ts +152 -0
- package/dist/services/memory-service.js +225 -0
- package/dist/services/memory-storage.d.ts +33 -0
- package/dist/services/memory-storage.js +328 -0
- package/dist/services/msr-aggregator.d.ts +38 -0
- package/dist/services/msr-aggregator.js +97 -0
- package/dist/services/msr-detector.d.ts +35 -0
- package/dist/services/msr-detector.js +65 -0
- package/dist/services/namespace-retrieval.d.ts +60 -0
- package/dist/services/namespace-retrieval.js +180 -0
- package/dist/services/observation-date-extraction.d.ts +12 -0
- package/dist/services/observation-date-extraction.js +50 -0
- package/dist/services/observation-service.d.ts +27 -0
- package/dist/services/observation-service.js +84 -0
- package/dist/services/packaging-observability.d.ts +29 -0
- package/dist/services/packaging-observability.js +146 -0
- package/dist/services/query-expansion.d.ts +83 -0
- package/dist/services/query-expansion.js +242 -0
- package/dist/services/query-keyword-matches.d.ts +6 -0
- package/dist/services/query-keyword-matches.js +56 -0
- package/dist/services/query-term-visibility.d.ts +28 -0
- package/dist/services/query-term-visibility.js +100 -0
- package/dist/services/quick-extraction.d.ts +25 -0
- package/dist/services/quick-extraction.js +431 -0
- package/dist/services/quoted-entity-extraction.d.ts +10 -0
- package/dist/services/quoted-entity-extraction.js +161 -0
- package/dist/services/raw-storage-reconciler-backoff.d.ts +8 -0
- package/dist/services/raw-storage-reconciler-backoff.js +14 -0
- package/dist/services/raw-storage-reconciler-scheduler.d.ts +29 -0
- package/dist/services/raw-storage-reconciler-scheduler.js +43 -0
- package/dist/services/raw-storage-reconciler.d.ts +71 -0
- package/dist/services/raw-storage-reconciler.js +278 -0
- package/dist/services/recap-builder.d.ts +49 -0
- package/dist/services/recap-builder.js +157 -0
- package/dist/services/reflect-jobs.d.ts +23 -0
- package/dist/services/reflect-jobs.js +36 -0
- package/dist/services/reflect-prompts.d.ts +71 -0
- package/dist/services/reflect-prompts.js +99 -0
- package/dist/services/reflect-retrieval.d.ts +33 -0
- package/dist/services/reflect-retrieval.js +30 -0
- package/dist/services/reflect.d.ts +49 -0
- package/dist/services/reflect.js +84 -0
- package/dist/services/relative-temporal.d.ts +14 -0
- package/dist/services/relative-temporal.js +163 -0
- package/dist/services/relevance-policy.d.ts +37 -0
- package/dist/services/relevance-policy.js +109 -0
- package/dist/services/rerank.d.ts +32 -0
- package/dist/services/rerank.js +118 -0
- package/dist/services/reranker.d.ts +20 -0
- package/dist/services/reranker.js +99 -0
- package/dist/services/retrieval-channel-rules.d.ts +34 -0
- package/dist/services/retrieval-channel-rules.js +41 -0
- package/dist/services/retrieval-config-overlay.d.ts +36 -0
- package/dist/services/retrieval-config-overlay.js +44 -0
- package/dist/services/retrieval-format.d.ts +119 -0
- package/dist/services/retrieval-format.js +559 -0
- package/dist/services/retrieval-policy.d.ts +69 -0
- package/dist/services/retrieval-policy.js +275 -0
- package/dist/services/retrieval-profiles.d.ts +37 -0
- package/dist/services/retrieval-profiles.js +90 -0
- package/dist/services/retrieval-side-effects.d.ts +14 -0
- package/dist/services/retrieval-side-effects.js +26 -0
- package/dist/services/retrieval-trace.d.ts +108 -0
- package/dist/services/retrieval-trace.js +147 -0
- package/dist/services/rrf-fusion.d.ts +18 -0
- package/dist/services/rrf-fusion.js +34 -0
- package/dist/services/search-pipeline.d.ts +71 -0
- package/dist/services/search-pipeline.js +788 -0
- package/dist/services/session-date.d.ts +20 -0
- package/dist/services/session-date.js +61 -0
- package/dist/services/session-packaging.d.ts +53 -0
- package/dist/services/session-packaging.js +182 -0
- package/dist/services/session-summary-generator.d.ts +53 -0
- package/dist/services/session-summary-generator.js +134 -0
- package/dist/services/specialists/cr-specialist.d.ts +52 -0
- package/dist/services/specialists/cr-specialist.js +121 -0
- package/dist/services/specialists/dispatch.d.ts +53 -0
- package/dist/services/specialists/dispatch.js +102 -0
- package/dist/services/specialists/ie-ku-specialist.d.ts +37 -0
- package/dist/services/specialists/ie-ku-specialist.js +63 -0
- package/dist/services/specialists/msr-specialist.d.ts +61 -0
- package/dist/services/specialists/msr-specialist.js +162 -0
- package/dist/services/specialists/tr-specialist.d.ts +37 -0
- package/dist/services/specialists/tr-specialist.js +146 -0
- package/dist/services/storage-key-prefix.d.ts +42 -0
- package/dist/services/storage-key-prefix.js +45 -0
- package/dist/services/storage-put-recovery.d.ts +71 -0
- package/dist/services/storage-put-recovery.js +269 -0
- package/dist/services/storage-service-errors.d.ts +124 -0
- package/dist/services/storage-service-errors.js +189 -0
- package/dist/services/storage-service.d.ts +176 -0
- package/dist/services/storage-service.js +423 -0
- package/dist/services/subject-aware-ranking.d.ts +19 -0
- package/dist/services/subject-aware-ranking.js +161 -0
- package/dist/services/supplemental-extraction.d.ts +7 -0
- package/dist/services/supplemental-extraction.js +116 -0
- package/dist/services/tbc-execution.d.ts +49 -0
- package/dist/services/tbc-execution.js +284 -0
- package/dist/services/temporal-classifier.d.ts +56 -0
- package/dist/services/temporal-classifier.js +94 -0
- package/dist/services/temporal-endpoint-evidence.d.ts +12 -0
- package/dist/services/temporal-endpoint-evidence.js +313 -0
- package/dist/services/temporal-fingerprint.d.ts +6 -0
- package/dist/services/temporal-fingerprint.js +12 -0
- package/dist/services/temporal-format.d.ts +9 -0
- package/dist/services/temporal-format.js +21 -0
- package/dist/services/temporal-intent.d.ts +39 -0
- package/dist/services/temporal-intent.js +78 -0
- package/dist/services/temporal-query-constraints.d.ts +16 -0
- package/dist/services/temporal-query-constraints.js +107 -0
- package/dist/services/temporal-query-expansion.d.ts +14 -0
- package/dist/services/temporal-query-expansion.js +131 -0
- package/dist/services/temporal-rerank.d.ts +22 -0
- package/dist/services/temporal-rerank.js +47 -0
- package/dist/services/temporal-result-protection.d.ts +7 -0
- package/dist/services/temporal-result-protection.js +60 -0
- package/dist/services/temporal-state-write.d.ts +57 -0
- package/dist/services/temporal-state-write.js +45 -0
- package/dist/services/tiered-context.d.ts +87 -0
- package/dist/services/tiered-context.js +214 -0
- package/dist/services/tiered-loading.d.ts +88 -0
- package/dist/services/tiered-loading.js +263 -0
- package/dist/services/timeline-pack.d.ts +36 -0
- package/dist/services/timeline-pack.js +50 -0
- package/dist/services/timing.d.ts +13 -0
- package/dist/services/timing.js +72 -0
- package/dist/services/tll-augmentation.d.ts +20 -0
- package/dist/services/tll-augmentation.js +125 -0
- package/dist/services/tll-retrieval.d.ts +55 -0
- package/dist/services/tll-retrieval.js +101 -0
- package/dist/services/topic-abstraction.d.ts +36 -0
- package/dist/services/topic-abstraction.js +105 -0
- package/dist/services/trust-scoring.d.ts +43 -0
- package/dist/services/trust-scoring.js +89 -0
- package/dist/services/typed-belief-calculus.d.ts +126 -0
- package/dist/services/typed-belief-calculus.js +204 -0
- package/dist/services/upload-config.d.ts +34 -0
- package/dist/services/upload-config.js +23 -0
- package/dist/services/upload-decision.d.ts +65 -0
- package/dist/services/upload-decision.js +98 -0
- package/dist/services/upload-helpers.d.ts +107 -0
- package/dist/services/upload-helpers.js +148 -0
- package/dist/services/user-profile-builder.d.ts +22 -0
- package/dist/services/user-profile-builder.js +109 -0
- package/dist/services/voyage-embedding.d.ts +22 -0
- package/dist/services/voyage-embedding.js +77 -0
- package/dist/services/write-security.d.ts +31 -0
- package/dist/services/write-security.js +64 -0
- package/dist/storage/artifact-public-redaction.d.ts +34 -0
- package/dist/storage/artifact-public-redaction.js +83 -0
- package/dist/storage/cleanup.d.ts +103 -0
- package/dist/storage/cleanup.js +138 -0
- package/dist/storage/codec-factory.d.ts +17 -0
- package/dist/storage/codec-factory.js +33 -0
- package/dist/storage/codecs/aes-gcm-codec.d.ts +44 -0
- package/dist/storage/codecs/aes-gcm-codec.js +108 -0
- package/dist/storage/codecs/noop-codec.d.ts +16 -0
- package/dist/storage/codecs/noop-codec.js +23 -0
- package/dist/storage/factory.d.ts +44 -0
- package/dist/storage/factory.js +99 -0
- package/dist/storage/filecoin-cid-validation.d.ts +82 -0
- package/dist/storage/filecoin-cid-validation.js +122 -0
- package/dist/storage/filecoin-public-metadata.d.ts +73 -0
- package/dist/storage/filecoin-public-metadata.js +110 -0
- package/dist/storage/local-fs-store.d.ts +39 -0
- package/dist/storage/local-fs-store.js +145 -0
- package/dist/storage/pointer-uri-allowlist.d.ts +38 -0
- package/dist/storage/pointer-uri-allowlist.js +70 -0
- package/dist/storage/provider-metadata-projection.d.ts +27 -0
- package/dist/storage/provider-metadata-projection.js +68 -0
- package/dist/storage/providers/filecoin/backend.d.ts +42 -0
- package/dist/storage/providers/filecoin/backend.js +250 -0
- package/dist/storage/providers/filecoin/config.d.ts +70 -0
- package/dist/storage/providers/filecoin/config.js +275 -0
- package/dist/storage/providers/filecoin/errors.d.ts +45 -0
- package/dist/storage/providers/filecoin/errors.js +56 -0
- package/dist/storage/providers/filecoin/filecoin-pin-car.d.ts +78 -0
- package/dist/storage/providers/filecoin/filecoin-pin-car.js +155 -0
- package/dist/storage/providers/filecoin/filecoin-pin-client.d.ts +92 -0
- package/dist/storage/providers/filecoin/filecoin-pin-client.js +199 -0
- package/dist/storage/providers/filecoin/filecoin-pin-mapping.d.ts +58 -0
- package/dist/storage/providers/filecoin/filecoin-pin-mapping.js +103 -0
- package/dist/storage/providers/filecoin/filecoin-pin-timeout.d.ts +30 -0
- package/dist/storage/providers/filecoin/filecoin-pin-timeout.js +53 -0
- package/dist/storage/providers/filecoin/filecoin-pin-vendor.d.ts +111 -0
- package/dist/storage/providers/filecoin/filecoin-pin-vendor.js +87 -0
- package/dist/storage/providers/filecoin/hints.d.ts +71 -0
- package/dist/storage/providers/filecoin/hints.js +123 -0
- package/dist/storage/providers/filecoin/index.d.ts +51 -0
- package/dist/storage/providers/filecoin/index.js +103 -0
- package/dist/storage/providers/filecoin/ipfs-cid.d.ts +50 -0
- package/dist/storage/providers/filecoin/ipfs-cid.js +64 -0
- package/dist/storage/providers/filecoin/metadata.d.ts +72 -0
- package/dist/storage/providers/filecoin/metadata.js +137 -0
- package/dist/storage/providers/filecoin/piece-cid.d.ts +48 -0
- package/dist/storage/providers/filecoin/piece-cid.js +57 -0
- package/dist/storage/providers/filecoin/provider-client.d.ts +234 -0
- package/dist/storage/providers/filecoin/provider-client.js +27 -0
- package/dist/storage/providers/filecoin/readiness.d.ts +62 -0
- package/dist/storage/providers/filecoin/readiness.js +85 -0
- package/dist/storage/providers/filecoin/retriever.d.ts +82 -0
- package/dist/storage/providers/filecoin/retriever.js +63 -0
- package/dist/storage/providers/filecoin/skeleton-client.d.ts +36 -0
- package/dist/storage/providers/filecoin/skeleton-client.js +55 -0
- package/dist/storage/providers/filecoin/synapse-client.d.ts +169 -0
- package/dist/storage/providers/filecoin/synapse-client.js +343 -0
- package/dist/storage/providers/filecoin/synapse-construction.d.ts +26 -0
- package/dist/storage/providers/filecoin/synapse-construction.js +47 -0
- package/dist/storage/providers/filecoin/synapse-error-mapping.d.ts +23 -0
- package/dist/storage/providers/filecoin/synapse-error-mapping.js +49 -0
- package/dist/storage/providers/filecoin/synapse-readiness.d.ts +37 -0
- package/dist/storage/providers/filecoin/synapse-readiness.js +231 -0
- package/dist/storage/providers/filecoin/uri.d.ts +49 -0
- package/dist/storage/providers/filecoin/uri.js +84 -0
- package/dist/storage/providers/filecoin/verified-fetch-lifecycle.d.ts +77 -0
- package/dist/storage/providers/filecoin/verified-fetch-lifecycle.js +196 -0
- package/dist/storage/providers/filecoin/verified-fetch-retriever.d.ts +54 -0
- package/dist/storage/providers/filecoin/verified-fetch-retriever.js +81 -0
- package/dist/storage/providers/filecoin/verified-fetch-vendor.d.ts +71 -0
- package/dist/storage/providers/filecoin/verified-fetch-vendor.js +94 -0
- package/dist/storage/raw-content-codec.d.ts +89 -0
- package/dist/storage/raw-content-codec.js +47 -0
- package/dist/storage/raw-content-store-backend-adapter.d.ts +28 -0
- package/dist/storage/raw-content-store-backend-adapter.js +67 -0
- package/dist/storage/raw-content-store.d.ts +228 -0
- package/dist/storage/raw-content-store.js +27 -0
- package/dist/storage/s3-store.d.ts +42 -0
- package/dist/storage/s3-store.js +181 -0
- package/dist/storage/storage-backend-registry.d.ts +58 -0
- package/dist/storage/storage-backend-registry.js +56 -0
- package/dist/storage/storage-backend.d.ts +82 -0
- package/dist/storage/storage-backend.js +14 -0
- package/dist/storage/storage-capabilities.d.ts +56 -0
- package/dist/storage/storage-capabilities.js +170 -0
- package/dist/storage/store-registry.d.ts +67 -0
- package/dist/storage/store-registry.js +77 -0
- package/dist/vector-math.d.ts +15 -0
- package/dist/vector-math.js +31 -0
- package/dist/xml-escape.d.ts +5 -0
- package/dist/xml-escape.js +7 -0
- package/openapi.json +15395 -0
- package/openapi.yaml +10794 -0
- package/package.json +119 -0
|
@@ -0,0 +1,225 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Core memory service facade -- delegates to memory-ingest, memory-search, and memory-crud.
|
|
3
|
+
* Preserves the public API (routes call service.search(), service.quickIngest(), etc.)
|
|
4
|
+
* while keeping each concern in a focused, testable module.
|
|
5
|
+
*/
|
|
6
|
+
import { config } from '../config.js';
|
|
7
|
+
import { URIResolver } from './atomicmem-uri.js';
|
|
8
|
+
import { performIngest, performQuickIngest, performStoreVerbatim, performWorkspaceIngest } from './memory-ingest.js';
|
|
9
|
+
import { performSearch, performFastSearch, performWorkspaceSearch } from './memory-search.js';
|
|
10
|
+
import * as crud from './memory-crud.js';
|
|
11
|
+
/**
|
|
12
|
+
* Materialize the {@link MemoryServiceDeps} bundle from constructor
|
|
13
|
+
* inputs. Extracted so the constructor stays under the workspace
|
|
14
|
+
* cyclomatic-complexity threshold; the optional-with-fallback chain
|
|
15
|
+
* lives here, the constructor is just plumbing.
|
|
16
|
+
*/
|
|
17
|
+
function buildDefaultStores(bag) {
|
|
18
|
+
const { repo, claims } = bag;
|
|
19
|
+
return {
|
|
20
|
+
memory: repo,
|
|
21
|
+
episode: repo,
|
|
22
|
+
recap: null,
|
|
23
|
+
search: repo,
|
|
24
|
+
link: repo,
|
|
25
|
+
representation: repo,
|
|
26
|
+
claim: claims,
|
|
27
|
+
entity: bag.entities ?? null,
|
|
28
|
+
lesson: bag.lessons ?? null,
|
|
29
|
+
summaries: null,
|
|
30
|
+
userProfile: null,
|
|
31
|
+
entityAttributes: null,
|
|
32
|
+
reflections: null,
|
|
33
|
+
reflectionJobs: null,
|
|
34
|
+
entityCards: null,
|
|
35
|
+
contradictions: null,
|
|
36
|
+
beliefEdges: null,
|
|
37
|
+
entityValues: null,
|
|
38
|
+
pool: typeof repo.getPool === 'function' ? repo.getPool() : {},
|
|
39
|
+
};
|
|
40
|
+
}
|
|
41
|
+
// fallow-ignore-next-line complexity
|
|
42
|
+
function buildMemoryServiceDeps(bag) {
|
|
43
|
+
return {
|
|
44
|
+
config: bag.runtimeConfig ?? config,
|
|
45
|
+
stores: bag.stores ?? buildDefaultStores(bag),
|
|
46
|
+
observationService: bag.observationService ?? null,
|
|
47
|
+
tllRepository: bag.tllRepository ?? null,
|
|
48
|
+
firstMentionService: bag.firstMentionService ?? null,
|
|
49
|
+
uriResolver: new URIResolver(bag.repo, bag.claims),
|
|
50
|
+
reflectionJobs: bag.stores?.reflectionJobs ?? undefined,
|
|
51
|
+
reflectEnabled: bag.runtimeConfig?.reflectEnabled ?? false,
|
|
52
|
+
rawContentStore: bag.rawContentStore ?? null,
|
|
53
|
+
storeRegistry: bag.storeRegistry,
|
|
54
|
+
};
|
|
55
|
+
}
|
|
56
|
+
export class MemoryService {
|
|
57
|
+
repo;
|
|
58
|
+
claims;
|
|
59
|
+
deps;
|
|
60
|
+
constructor(repo, claims, entities, lessons, observationService, runtimeConfig, stores, tllRepository, firstMentionService,
|
|
61
|
+
/**
|
|
62
|
+
* Phase-3 raw-content adapter. Optional so existing call sites and
|
|
63
|
+
* pointer-only deployments stay unchanged; supplied at composition
|
|
64
|
+
* time when `rawStorageMode='managed_blob'`.
|
|
65
|
+
*/
|
|
66
|
+
rawContentStore,
|
|
67
|
+
/**
|
|
68
|
+
* Phase 4a per-row dispatch registry. Optional for existing
|
|
69
|
+
* call sites; composition-root code passes it when
|
|
70
|
+
* `RAW_STORAGE_LEGACY_PROVIDERS` is set. Falls back to
|
|
71
|
+
* `singleStoreRegistry(rawContentStore)` inside `resetBySource`
|
|
72
|
+
* when absent.
|
|
73
|
+
*/
|
|
74
|
+
storeRegistry) {
|
|
75
|
+
this.repo = repo;
|
|
76
|
+
this.claims = claims;
|
|
77
|
+
this.deps = buildMemoryServiceDeps({
|
|
78
|
+
repo, claims, entities, lessons, observationService, runtimeConfig,
|
|
79
|
+
stores, tllRepository, firstMentionService, rawContentStore, storeRegistry,
|
|
80
|
+
});
|
|
81
|
+
}
|
|
82
|
+
/**
|
|
83
|
+
* Build a request-scoped deps bundle that swaps in the effective config
|
|
84
|
+
* for the duration of a single call. Returns the shared `this.deps`
|
|
85
|
+
* unchanged when no override is supplied (zero-allocation fast path).
|
|
86
|
+
* All per-fact/per-pipeline helpers already read `deps.config`, so
|
|
87
|
+
* replacing it at the entry point propagates through the service layer
|
|
88
|
+
* without mutating shared state.
|
|
89
|
+
*/
|
|
90
|
+
depsFor(effectiveConfig) {
|
|
91
|
+
if (!effectiveConfig)
|
|
92
|
+
return this.deps;
|
|
93
|
+
return { ...this.deps, config: effectiveConfig };
|
|
94
|
+
}
|
|
95
|
+
// --- Ingest ---
|
|
96
|
+
async ingest(userId, conversationText, sourceSite, sourceUrl = '', sessionTimestamp, effectiveConfig) {
|
|
97
|
+
return performIngest(this.depsFor(effectiveConfig), userId, conversationText, sourceSite, sourceUrl, sessionTimestamp);
|
|
98
|
+
}
|
|
99
|
+
async quickIngest(userId, conversationText, sourceSite, sourceUrl = '', sessionTimestamp, effectiveConfig) {
|
|
100
|
+
return performQuickIngest(this.depsFor(effectiveConfig), userId, conversationText, sourceSite, sourceUrl, sessionTimestamp);
|
|
101
|
+
}
|
|
102
|
+
/**
|
|
103
|
+
* Store content as a single memory without fact extraction.
|
|
104
|
+
* Used for user-created contexts (text/file uploads) where
|
|
105
|
+
* the content should remain as one canonical memory record.
|
|
106
|
+
*/
|
|
107
|
+
async storeVerbatim(userId, content, sourceSite, sourceUrl = '', metadata, effectiveConfig) {
|
|
108
|
+
return performStoreVerbatim(this.depsFor(effectiveConfig), userId, content, sourceSite, sourceUrl, metadata);
|
|
109
|
+
}
|
|
110
|
+
async workspaceIngest(userId, conversationText, sourceSite, sourceUrl = '', workspace, sessionTimestamp, effectiveConfig) {
|
|
111
|
+
return performWorkspaceIngest(this.depsFor(effectiveConfig), userId, conversationText, sourceSite, sourceUrl, workspace, sessionTimestamp);
|
|
112
|
+
}
|
|
113
|
+
// --- Search (scope-dispatching) ---
|
|
114
|
+
/** Scope-dispatching search: routes to user or workspace search based on scope.kind. */
|
|
115
|
+
async scopedSearch(scope, query, options = {}) {
|
|
116
|
+
const deps = this.depsFor(options.effectiveConfig);
|
|
117
|
+
if (scope.kind === 'workspace') {
|
|
118
|
+
const ws = { workspaceId: scope.workspaceId, agentId: scope.agentId };
|
|
119
|
+
return performWorkspaceSearch(deps, scope.userId, query, ws, {
|
|
120
|
+
agentScope: scope.agentScope,
|
|
121
|
+
limit: options.limit,
|
|
122
|
+
referenceTime: options.referenceTime,
|
|
123
|
+
retrievalOptions: options.retrievalOptions,
|
|
124
|
+
});
|
|
125
|
+
}
|
|
126
|
+
if (options.fast) {
|
|
127
|
+
return performFastSearch(deps, scope.userId, query, options.sourceSite, options.limit, options.namespaceScope, options.retrievalOptions);
|
|
128
|
+
}
|
|
129
|
+
return performSearch(deps, scope.userId, query, options.sourceSite, options.limit, options.asOf, options.referenceTime, options.namespaceScope, options.retrievalOptions);
|
|
130
|
+
}
|
|
131
|
+
/** Scope-dispatching expand with agent visibility enforcement for workspace operations. */
|
|
132
|
+
async scopedExpand(scope, memoryIds) {
|
|
133
|
+
if (scope.kind === 'workspace')
|
|
134
|
+
return crud.expandMemoriesInWorkspace(this.deps, scope.workspaceId, memoryIds, scope.agentId);
|
|
135
|
+
return crud.expandMemories(this.deps, scope.userId, memoryIds);
|
|
136
|
+
}
|
|
137
|
+
/** Scope-dispatching get with agent visibility enforcement for workspace operations. */
|
|
138
|
+
async scopedGet(scope, id) {
|
|
139
|
+
if (scope.kind === 'workspace')
|
|
140
|
+
return crud.getMemoryInWorkspace(this.deps, id, scope.workspaceId, scope.agentId);
|
|
141
|
+
return crud.getMemory(this.deps, id, scope.userId);
|
|
142
|
+
}
|
|
143
|
+
/** Scope-dispatching delete with agent visibility enforcement. Returns false if not found/not visible. */
|
|
144
|
+
async scopedDelete(scope, id) {
|
|
145
|
+
if (scope.kind === 'workspace')
|
|
146
|
+
return crud.deleteMemoryInWorkspace(this.deps, id, scope.workspaceId, scope.agentId);
|
|
147
|
+
await crud.deleteMemory(this.deps, id, scope.userId);
|
|
148
|
+
return true;
|
|
149
|
+
}
|
|
150
|
+
/** Scope-dispatching list with agent visibility enforcement for workspace operations. */
|
|
151
|
+
async scopedList(scope, limit = 20, offset = 0, sourceSite, episodeId) {
|
|
152
|
+
if (scope.kind === 'workspace')
|
|
153
|
+
return crud.listMemoriesInWorkspace(this.deps, scope.workspaceId, limit, offset, scope.agentId);
|
|
154
|
+
return crud.listMemories(this.deps, scope.userId, limit, offset, sourceSite, episodeId);
|
|
155
|
+
}
|
|
156
|
+
// --- Search (legacy, prefer scopedSearch) ---
|
|
157
|
+
/** @deprecated Use scopedSearch instead. */
|
|
158
|
+
async search(userId, query, sourceSite, limit, asOf, referenceTime, namespaceScope, retrievalOptions) {
|
|
159
|
+
return performSearch(this.deps, userId, query, sourceSite, limit, asOf, referenceTime, namespaceScope, retrievalOptions);
|
|
160
|
+
}
|
|
161
|
+
/** @deprecated Use scopedSearch instead. */
|
|
162
|
+
async fastSearch(userId, query, sourceSite, limit, namespaceScope) {
|
|
163
|
+
return performFastSearch(this.deps, userId, query, sourceSite, limit, namespaceScope);
|
|
164
|
+
}
|
|
165
|
+
/** @deprecated Use scopedSearch instead. */
|
|
166
|
+
async workspaceSearch(userId, query, workspace, options = {}) {
|
|
167
|
+
return performWorkspaceSearch(this.deps, userId, query, workspace, options);
|
|
168
|
+
}
|
|
169
|
+
// --- CRUD ---
|
|
170
|
+
async list(userId, limit = 20, offset = 0, sourceSite, episodeId) { return crud.listMemories(this.deps, userId, limit, offset, sourceSite, episodeId); }
|
|
171
|
+
async get(id, userId) { return crud.getMemory(this.deps, id, userId); }
|
|
172
|
+
async expand(userId, memoryIds) { return crud.expandMemories(this.deps, userId, memoryIds); }
|
|
173
|
+
async delete(id, userId) { return crud.deleteMemory(this.deps, id, userId); }
|
|
174
|
+
async resetBySource(userId, sourceSite) { return crud.resetBySource(this.deps, userId, sourceSite); }
|
|
175
|
+
async getStats(userId) { return crud.getStats(this.deps, userId); }
|
|
176
|
+
// --- Consolidation / Lifecycle ---
|
|
177
|
+
async consolidate(userId) { return crud.consolidate(this.deps, userId); }
|
|
178
|
+
async executeConsolidation(userId) { return crud.performExecuteConsolidation(this.deps, userId); }
|
|
179
|
+
async reconcileDeferred(userId) { return crud.reconcileDeferred(this.deps, userId); }
|
|
180
|
+
async reconcileDeferredAll() { return crud.reconcileDeferredAll(this.deps); }
|
|
181
|
+
async getDeferredStatus(userId) { return crud.getDeferredStatus(this.deps, userId); }
|
|
182
|
+
async evaluateDecay(userId, referenceTime) { return crud.evaluateDecay(this.deps, userId, referenceTime); }
|
|
183
|
+
async archiveDecayed(userId, memoryIds) { return crud.archiveDecayed(this.deps, userId, memoryIds); }
|
|
184
|
+
async checkCap(userId) { return crud.checkCap(this.deps, userId); }
|
|
185
|
+
// --- Audit / Mutations ---
|
|
186
|
+
async getAuditTrail(userId, memoryId) { return crud.getAuditTrail(this.deps, userId, memoryId); }
|
|
187
|
+
async getMutationSummary(userId) { return crud.getMutationSummary(this.deps, userId); }
|
|
188
|
+
async getRecentMutations(userId, limit = 20) { return crud.getRecentMutations(this.deps, userId, limit); }
|
|
189
|
+
async backfillClaimSlots(userId) { return crud.backfillClaimSlots(this.deps, userId); }
|
|
190
|
+
async getReversalChain(userId, versionId) { return crud.getReversalChain(this.deps, userId, versionId); }
|
|
191
|
+
// --- Lessons ---
|
|
192
|
+
async getLessons(userId) { return crud.getLessons(this.deps, userId); }
|
|
193
|
+
async getLessonStats(userId) { return crud.getLessonStats(this.deps, userId); }
|
|
194
|
+
async reportLesson(userId, pattern, sourceMemoryIds, severity) { return crud.reportLesson(this.deps, userId, pattern, sourceMemoryIds, severity); }
|
|
195
|
+
async deactivateLesson(userId, lessonId) { return crud.deactivateLesson(this.deps, userId, lessonId); }
|
|
196
|
+
// --- First-mention events (chronological topic-introduction list) ---
|
|
197
|
+
/**
|
|
198
|
+
* Extract first-mention events from a conversation transcript and persist
|
|
199
|
+
* them to `first_mention_events`. Caller supplies the turn-id-to-memory-id
|
|
200
|
+
* mapping (the ingest pipeline does not retain turn structure, so the
|
|
201
|
+
* caller knows the mapping). Returns the parsed events. Best-effort: if
|
|
202
|
+
* the underlying LLM call fails or the service is not wired, returns `[]`
|
|
203
|
+
* without throwing.
|
|
204
|
+
*/
|
|
205
|
+
async extractFirstMentions(userId, conversationText, sourceSite, memoryIdsByTurnId) {
|
|
206
|
+
const svc = this.deps.firstMentionService;
|
|
207
|
+
if (!svc)
|
|
208
|
+
return [];
|
|
209
|
+
return svc.extractAndStore(userId, conversationText, sourceSite, memoryIdsByTurnId);
|
|
210
|
+
}
|
|
211
|
+
// --- Event chains (TLL read API) ---
|
|
212
|
+
/**
|
|
213
|
+
* Retrieve per-entity chronological event chains from the Temporal Linkage
|
|
214
|
+
* List. Used by `GET /v1/memories/event-chains` and by EO-shaped read paths
|
|
215
|
+
* that need content alongside chain position. Returns one entry per entity
|
|
216
|
+
* with an ordered list of events (memoryId, content, observationDate,
|
|
217
|
+
* positionInChain). Entities without events are dropped from the result.
|
|
218
|
+
*/
|
|
219
|
+
async getEventChains(userId, entityIds) {
|
|
220
|
+
const tll = this.deps.tllRepository;
|
|
221
|
+
if (!tll)
|
|
222
|
+
return [];
|
|
223
|
+
return tll.chainEventsForEntities(userId, entityIds);
|
|
224
|
+
}
|
|
225
|
+
}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Canonical fact storage, projection writing, entity linking, and claim slot resolution.
|
|
3
|
+
* These helpers are used by both the ingest pipeline and the AUDN decision executor.
|
|
4
|
+
*/
|
|
5
|
+
import { type ClaimSlotInput } from '../db/claim-repository.js';
|
|
6
|
+
import { type ExtractedEntity } from './extraction.js';
|
|
7
|
+
import { type CandidateMemory } from './conflict-policy.js';
|
|
8
|
+
import { type TemporalStateClassification } from './temporal-state-write.js';
|
|
9
|
+
import type { AudnFactContext, ClaimTarget, FactInput, MemoryServiceDeps, Outcome } from './memory-service-types.js';
|
|
10
|
+
interface StoreProjectionOptions {
|
|
11
|
+
cmoId?: string;
|
|
12
|
+
logicalTimestamp?: Date;
|
|
13
|
+
workspace?: import('../db/repository-types.js').WorkspaceContext;
|
|
14
|
+
/** BEAM v38: temporal-state classification to land on the new row. */
|
|
15
|
+
temporal?: TemporalStateClassification | null;
|
|
16
|
+
}
|
|
17
|
+
/** Store a new canonical fact: CMO, projection, claim, evidence, entities. */
|
|
18
|
+
export declare function storeCanonicalFact(deps: MemoryServiceDeps, ctx: AudnFactContext): Promise<{
|
|
19
|
+
outcome: Outcome;
|
|
20
|
+
memoryId: string | null;
|
|
21
|
+
}>;
|
|
22
|
+
export declare function storeProjection(deps: MemoryServiceDeps, userId: string, fact: FactInput, embedding: number[], sourceSite: string, sourceUrl: string, episodeId: string, trustScore: number, options?: StoreProjectionOptions): Promise<string | null>;
|
|
23
|
+
export declare function resolveDeterministicClaimSlot(deps: MemoryServiceDeps, userId: string, fact: FactInput): Promise<ClaimSlotInput | null>;
|
|
24
|
+
/**
|
|
25
|
+
* Entity-scoped dedup: if AUDN proposed UPDATE or NOOP targeting a memory
|
|
26
|
+
* that shares no entities with the new fact, promote to ADD.
|
|
27
|
+
*/
|
|
28
|
+
export declare function applyEntityScopedDedup(deps: MemoryServiceDeps, decision: import('./extraction.js').AUDNDecision, userId: string, factEntities: ExtractedEntity[]): Promise<import('./extraction.js').AUDNDecision>;
|
|
29
|
+
/** Ensure a claim target exists for the given memory, creating one if needed. */
|
|
30
|
+
export declare function ensureClaimTarget(deps: MemoryServiceDeps, userId: string, memoryId: string): Promise<ClaimTarget>;
|
|
31
|
+
export declare function findConflictCandidates(deps: MemoryServiceDeps, userId: string, factText: string, embedding: number[]): Promise<CandidateMemory[]>;
|
|
32
|
+
export declare function findSlotConflictCandidates(deps: MemoryServiceDeps, userId: string, claimSlot: ClaimSlotInput | null): Promise<CandidateMemory[]>;
|
|
33
|
+
export {};
|
|
@@ -0,0 +1,328 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Canonical fact storage, projection writing, entity linking, and claim slot resolution.
|
|
3
|
+
* These helpers are used by both the ingest pipeline and the AUDN decision executor.
|
|
4
|
+
*/
|
|
5
|
+
import { embedTexts } from './embedding.js';
|
|
6
|
+
import { classifyNetwork } from './memory-network.js';
|
|
7
|
+
import { buildRelationClaimSlot } from './claim-slotting.js';
|
|
8
|
+
import { extractConflictKeywords, mergeCandidates } from './conflict-policy.js';
|
|
9
|
+
import { buildAtomicFactProjection, buildForesightProjections } from './memcell-projection.js';
|
|
10
|
+
import { inferNamespace, classifyNamespace } from './namespace-retrieval.js';
|
|
11
|
+
import { generateL1Overview } from './tiered-context.js';
|
|
12
|
+
import { emitAuditEvent } from './audit-events.js';
|
|
13
|
+
import { derivePersistedClaimSlot } from './memory-crud.js';
|
|
14
|
+
import { emitLineageEvent } from './memory-lineage.js';
|
|
15
|
+
import { classifyTemporalStateForWrite, supersedeAfterStore, } from './temporal-state-write.js';
|
|
16
|
+
/** Store a new canonical fact: CMO, projection, claim, evidence, entities. */
|
|
17
|
+
export async function storeCanonicalFact(deps, ctx) {
|
|
18
|
+
const { userId, fact, embedding, sourceSite, sourceUrl, episodeId, trustScore, claimSlot, logicalTimestamp, workspace } = ctx;
|
|
19
|
+
// BEAM v38: classify temporal state BEFORE storing so we can land
|
|
20
|
+
// `state_key` / `event_start` on the new row's first INSERT. Fails closed.
|
|
21
|
+
const temporal = await maybeClassifyTemporalForFact(deps, ctx);
|
|
22
|
+
const lineage = await emitLineageEvent({ claims: deps.stores.claim, repo: deps.stores.memory, config: deps.config }, {
|
|
23
|
+
kind: 'canonical-add',
|
|
24
|
+
userId,
|
|
25
|
+
fact,
|
|
26
|
+
embedding,
|
|
27
|
+
sourceSite,
|
|
28
|
+
sourceUrl,
|
|
29
|
+
episodeId,
|
|
30
|
+
logicalTimestamp,
|
|
31
|
+
claimSlot: claimSlot ?? null,
|
|
32
|
+
createProjection: async (cmoId) => storeProjection(deps, userId, fact, embedding, sourceSite, sourceUrl, episodeId, trustScore, {
|
|
33
|
+
cmoId,
|
|
34
|
+
logicalTimestamp,
|
|
35
|
+
workspace,
|
|
36
|
+
temporal,
|
|
37
|
+
}),
|
|
38
|
+
});
|
|
39
|
+
if (!lineage?.memoryId)
|
|
40
|
+
return { outcome: 'skipped', memoryId: null };
|
|
41
|
+
const memoryId = lineage.memoryId;
|
|
42
|
+
// BEAM v38: close prior memory windows for this state_key. Fails closed.
|
|
43
|
+
if (temporal) {
|
|
44
|
+
await supersedeAfterStore({
|
|
45
|
+
pool: deps.stores.pool,
|
|
46
|
+
userId,
|
|
47
|
+
stateKey: temporal.stateKey,
|
|
48
|
+
newMemoryId: memoryId,
|
|
49
|
+
eventStart: temporal.eventStart,
|
|
50
|
+
});
|
|
51
|
+
}
|
|
52
|
+
if (deps.config.entityGraphEnabled && deps.stores.entity) {
|
|
53
|
+
await resolveAndLinkEntities(deps, userId, memoryId, fact.entities, fact.relations, embedding, logicalTimestamp);
|
|
54
|
+
if (!claimSlot) {
|
|
55
|
+
const persistedSlot = await derivePersistedClaimSlot(deps, userId, memoryId);
|
|
56
|
+
if (persistedSlot) {
|
|
57
|
+
await deps.stores.claim.updateClaimSlot(userId, lineage.claimId, persistedSlot);
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
if (deps.observationService && fact.entities.length > 0) {
|
|
62
|
+
const subjects = fact.entities.map((e) => e.name);
|
|
63
|
+
deps.observationService.markDirty(userId, subjects).catch((err) => console.error('[observation] markDirty failed:', err));
|
|
64
|
+
}
|
|
65
|
+
return { outcome: 'stored', memoryId };
|
|
66
|
+
}
|
|
67
|
+
/**
|
|
68
|
+
* BEAM v38: run the temporal-state classifier when the flag is on.
|
|
69
|
+
* Returns null when the flag is off, when the memory is non-stateful,
|
|
70
|
+
* or when the classifier rejects the LLM output. Re-throws on LLM
|
|
71
|
+
* transport errors so the ingest fails closed.
|
|
72
|
+
*/
|
|
73
|
+
async function maybeClassifyTemporalForFact(deps, ctx) {
|
|
74
|
+
if (!deps.config.temporalStateEnabled)
|
|
75
|
+
return null;
|
|
76
|
+
const observedAt = ctx.logicalTimestamp ?? new Date();
|
|
77
|
+
return classifyTemporalStateForWrite({
|
|
78
|
+
userId: ctx.userId,
|
|
79
|
+
memoryText: ctx.fact.fact,
|
|
80
|
+
observedAt,
|
|
81
|
+
model: deps.config.llmModel,
|
|
82
|
+
});
|
|
83
|
+
}
|
|
84
|
+
export async function storeProjection(deps, userId, fact, embedding, sourceSite, sourceUrl, episodeId, trustScore, options = {}) {
|
|
85
|
+
const namespace = deps.config.namespaceClassificationEnabled
|
|
86
|
+
? await classifyNamespace(fact.fact, sourceSite, fact.keywords)
|
|
87
|
+
: inferNamespace(fact.fact, sourceSite, fact.keywords);
|
|
88
|
+
const overview = generateL1Overview(fact.fact);
|
|
89
|
+
const network = fact.network ?? classifyNetwork(fact).network;
|
|
90
|
+
const memoryId = await deps.stores.memory.storeMemory({
|
|
91
|
+
userId, content: fact.fact, embedding,
|
|
92
|
+
memoryType: fact.type === 'knowledge' ? 'semantic' : 'episodic',
|
|
93
|
+
importance: fact.importance, sourceSite, sourceUrl, episodeId,
|
|
94
|
+
metadata: options.cmoId ? { cmo_id: options.cmoId } : undefined,
|
|
95
|
+
keywords: fact.keywords.join(' '),
|
|
96
|
+
namespace: namespace ?? undefined,
|
|
97
|
+
summary: fact.headline,
|
|
98
|
+
overview: overview !== fact.fact ? overview : '',
|
|
99
|
+
trustScore, network,
|
|
100
|
+
opinionConfidence: fact.opinionConfidence ?? null,
|
|
101
|
+
workspaceId: options.workspace?.workspaceId,
|
|
102
|
+
agentId: options.workspace?.agentId,
|
|
103
|
+
visibility: options.workspace?.visibility,
|
|
104
|
+
createdAt: options.logicalTimestamp,
|
|
105
|
+
observedAt: options.logicalTimestamp,
|
|
106
|
+
stateKey: options.temporal?.stateKey,
|
|
107
|
+
eventStart: options.temporal?.eventStart,
|
|
108
|
+
eventEnd: options.temporal?.eventEnd ?? null,
|
|
109
|
+
});
|
|
110
|
+
const atomicFact = buildAtomicFactProjection(fact, embedding);
|
|
111
|
+
await deps.stores.representation.storeAtomicFacts([{
|
|
112
|
+
userId, parentMemoryId: memoryId,
|
|
113
|
+
factText: atomicFact.factText, embedding: atomicFact.embedding,
|
|
114
|
+
factType: atomicFact.factType, importance: atomicFact.importance,
|
|
115
|
+
sourceSite, sourceUrl, episodeId,
|
|
116
|
+
keywords: atomicFact.keywords.join(' '), metadata: atomicFact.metadata,
|
|
117
|
+
workspaceId: options.workspace?.workspaceId, agentId: options.workspace?.agentId,
|
|
118
|
+
}]);
|
|
119
|
+
const foresight = buildForesightProjections(fact, embedding);
|
|
120
|
+
if (foresight.length > 0) {
|
|
121
|
+
await deps.stores.representation.storeForesight(foresight.map((entry) => ({
|
|
122
|
+
userId, parentMemoryId: memoryId,
|
|
123
|
+
content: entry.content, embedding: entry.embedding, foresightType: entry.foresightType,
|
|
124
|
+
sourceSite, sourceUrl, episodeId,
|
|
125
|
+
metadata: entry.metadata, validFrom: entry.validFrom, validTo: entry.validTo,
|
|
126
|
+
workspaceId: options.workspace?.workspaceId, agentId: options.workspace?.agentId,
|
|
127
|
+
})));
|
|
128
|
+
}
|
|
129
|
+
if (deps.config.auditLoggingEnabled) {
|
|
130
|
+
emitAuditEvent('memory:ingest', userId, {
|
|
131
|
+
factType: fact.type, importance: fact.importance, trustScore,
|
|
132
|
+
}, { memoryId, sourceSite });
|
|
133
|
+
}
|
|
134
|
+
return memoryId;
|
|
135
|
+
}
|
|
136
|
+
export async function resolveDeterministicClaimSlot(deps, userId, fact) {
|
|
137
|
+
if (!deps.stores.entity || fact.entities.length === 0 || fact.relations.length === 0) {
|
|
138
|
+
return null;
|
|
139
|
+
}
|
|
140
|
+
const canonicalEntries = await Promise.all(fact.entities.map(async (entity) => {
|
|
141
|
+
const match = await deps.stores.entity.findDeterministicEntity(userId, entity.type, entity.name);
|
|
142
|
+
if (!match)
|
|
143
|
+
return null;
|
|
144
|
+
return [
|
|
145
|
+
entity.name.toLowerCase(),
|
|
146
|
+
{
|
|
147
|
+
extractedName: entity.name,
|
|
148
|
+
entityId: match.id,
|
|
149
|
+
canonicalName: match.name,
|
|
150
|
+
entityType: match.entity_type,
|
|
151
|
+
},
|
|
152
|
+
];
|
|
153
|
+
}));
|
|
154
|
+
const canonicalMap = new Map(canonicalEntries.filter((entry) => entry !== null));
|
|
155
|
+
return buildRelationClaimSlot(fact.relations, canonicalMap);
|
|
156
|
+
}
|
|
157
|
+
/**
|
|
158
|
+
* Entity-scoped dedup: if AUDN proposed UPDATE or NOOP targeting a memory
|
|
159
|
+
* that shares no entities with the new fact, promote to ADD.
|
|
160
|
+
*/
|
|
161
|
+
export async function applyEntityScopedDedup(deps, decision, userId, factEntities) {
|
|
162
|
+
if (decision.action !== 'UPDATE' && decision.action !== 'NOOP')
|
|
163
|
+
return decision;
|
|
164
|
+
if (!decision.targetMemoryId || !deps.stores.entity || factEntities.length === 0)
|
|
165
|
+
return decision;
|
|
166
|
+
const existingEntities = await deps.stores.entity.getEntitiesForMemory(decision.targetMemoryId);
|
|
167
|
+
if (existingEntities.length === 0)
|
|
168
|
+
return decision;
|
|
169
|
+
const factEntityNames = new Set(factEntities.map((e) => e.name.toLowerCase()));
|
|
170
|
+
const hasSharedEntity = existingEntities.some((e) => factEntityNames.has(e.name.toLowerCase()) ||
|
|
171
|
+
e.alias_names.some((a) => factEntityNames.has(a.toLowerCase())));
|
|
172
|
+
if (!hasSharedEntity) {
|
|
173
|
+
return { ...decision, action: 'ADD', targetMemoryId: null, updatedContent: null };
|
|
174
|
+
}
|
|
175
|
+
return decision;
|
|
176
|
+
}
|
|
177
|
+
/**
|
|
178
|
+
* Resolve extracted entities (dedup by embedding + type), link them to the
|
|
179
|
+
* memory, then store any extracted relations between entities.
|
|
180
|
+
*/
|
|
181
|
+
async function resolveAndLinkEntities(deps, userId, memoryId, entities, relations, factEmbedding, logicalTimestamp) {
|
|
182
|
+
if (!deps.stores.entity || entities.length === 0)
|
|
183
|
+
return;
|
|
184
|
+
const entityEmbeddings = await embedTexts(entities.map((e) => e.name));
|
|
185
|
+
const nameToEntityId = await resolveEntities(deps, userId, memoryId, entities, entityEmbeddings);
|
|
186
|
+
await storeRelations(deps, userId, memoryId, relations, nameToEntityId);
|
|
187
|
+
await maybeAppendTll(deps, userId, memoryId, nameToEntityId, logicalTimestamp);
|
|
188
|
+
}
|
|
189
|
+
/**
|
|
190
|
+
* Phase 4 — TLL append: per-entity event-chain extension. Each new memory
|
|
191
|
+
* referencing an entity becomes the new tip of that entity's chain. Used at
|
|
192
|
+
* retrieval-time for EO/MSR/TR queries. Best-effort, fire-and-forget to
|
|
193
|
+
* keep ingest hot path fast.
|
|
194
|
+
*
|
|
195
|
+
* The chain orders by observation_date ASC, so we use the memory's
|
|
196
|
+
* observed_at (the conversation timestamp) instead of new Date() (the
|
|
197
|
+
* ingest-arrival timestamp). Otherwise out-of-order or backfilled
|
|
198
|
+
* conversations would chain by ingest time, breaking event ordering.
|
|
199
|
+
*/
|
|
200
|
+
async function maybeAppendTll(deps, userId, memoryId, nameToEntityId, logicalTimestamp) {
|
|
201
|
+
if (!deps.tllRepository)
|
|
202
|
+
return;
|
|
203
|
+
const entityIds = [...nameToEntityId.values()];
|
|
204
|
+
if (entityIds.length === 0)
|
|
205
|
+
return;
|
|
206
|
+
const observationDate = await resolveTllObservationDate(deps, userId, memoryId, logicalTimestamp);
|
|
207
|
+
// Fire-and-forget: TLL append is best-effort augmentation of the
|
|
208
|
+
// ingest hot path. A failure here should NOT block ingest, which is
|
|
209
|
+
// why we deliberately drop the promise. The `[tll-append-failed]`
|
|
210
|
+
// structured prefix is what observability tooling greps for; pair
|
|
211
|
+
// with `tll_expansion_failed` on the read path.
|
|
212
|
+
deps.tllRepository
|
|
213
|
+
.append(userId, memoryId, entityIds, observationDate)
|
|
214
|
+
.catch((err) => console.error('[tll-append-failed]', err instanceof Error ? err.message : String(err)));
|
|
215
|
+
}
|
|
216
|
+
/**
|
|
217
|
+
* Resolve the observation_date used for TLL chain ordering. Prefers the
|
|
218
|
+
* caller-supplied logical timestamp (the canonical conversation time);
|
|
219
|
+
* falls back to the memory row's observed_at column when the caller didn't
|
|
220
|
+
* supply one. Last-resort fallback to new Date() only fires if the row
|
|
221
|
+
* lookup fails — never silently drop the append.
|
|
222
|
+
*/
|
|
223
|
+
async function resolveTllObservationDate(deps, userId, memoryId, logicalTimestamp) {
|
|
224
|
+
if (logicalTimestamp)
|
|
225
|
+
return logicalTimestamp;
|
|
226
|
+
try {
|
|
227
|
+
const memory = await deps.stores.memory.getMemory(memoryId, userId);
|
|
228
|
+
if (memory?.observed_at)
|
|
229
|
+
return memory.observed_at;
|
|
230
|
+
}
|
|
231
|
+
catch (err) {
|
|
232
|
+
console.error('[tll] failed to resolve observed_at:', err instanceof Error ? err.message : err);
|
|
233
|
+
}
|
|
234
|
+
return new Date();
|
|
235
|
+
}
|
|
236
|
+
/** Resolve each extracted entity and link it to the memory. */
|
|
237
|
+
async function resolveEntities(deps, userId, memoryId, entities, entityEmbeddings) {
|
|
238
|
+
const nameToEntityId = new Map();
|
|
239
|
+
for (let i = 0; i < entities.length; i++) {
|
|
240
|
+
try {
|
|
241
|
+
const entityId = await deps.stores.entity.resolveEntity({
|
|
242
|
+
userId,
|
|
243
|
+
name: entities[i].name,
|
|
244
|
+
entityType: entities[i].type,
|
|
245
|
+
embedding: entityEmbeddings[i],
|
|
246
|
+
});
|
|
247
|
+
await deps.stores.entity.linkMemoryToEntity(memoryId, entityId);
|
|
248
|
+
nameToEntityId.set(entities[i].name.toLowerCase(), entityId);
|
|
249
|
+
}
|
|
250
|
+
catch (err) {
|
|
251
|
+
console.error(`Entity resolution failed for "${entities[i].name}": ${err instanceof Error ? err.message : err}`);
|
|
252
|
+
}
|
|
253
|
+
}
|
|
254
|
+
return nameToEntityId;
|
|
255
|
+
}
|
|
256
|
+
/** Store extracted relations between resolved entities. */
|
|
257
|
+
async function storeRelations(deps, userId, memoryId, relations, nameToEntityId) {
|
|
258
|
+
for (const relation of relations) {
|
|
259
|
+
const sourceId = nameToEntityId.get(relation.source.toLowerCase());
|
|
260
|
+
const targetId = nameToEntityId.get(relation.target.toLowerCase());
|
|
261
|
+
if (!sourceId || !targetId || sourceId === targetId)
|
|
262
|
+
continue;
|
|
263
|
+
try {
|
|
264
|
+
await deps.stores.entity.upsertRelation({
|
|
265
|
+
userId,
|
|
266
|
+
sourceEntityId: sourceId,
|
|
267
|
+
targetEntityId: targetId,
|
|
268
|
+
relationType: relation.type,
|
|
269
|
+
sourceMemoryId: memoryId,
|
|
270
|
+
});
|
|
271
|
+
}
|
|
272
|
+
catch (err) {
|
|
273
|
+
console.error(`Relation storage failed for "${relation.source}" -> "${relation.target}": ${err instanceof Error ? err.message : err}`);
|
|
274
|
+
}
|
|
275
|
+
}
|
|
276
|
+
}
|
|
277
|
+
/** Ensure a claim target exists for the given memory, creating one if needed. */
|
|
278
|
+
export async function ensureClaimTarget(deps, userId, memoryId) {
|
|
279
|
+
const memory = await deps.stores.memory.getMemoryIncludingDeleted(memoryId, userId);
|
|
280
|
+
if (!memory)
|
|
281
|
+
throw new Error(`Target memory not found: ${memoryId}`);
|
|
282
|
+
const cmoId = typeof memory.metadata.cmo_id === 'string' ? memory.metadata.cmo_id : null;
|
|
283
|
+
const version = await deps.stores.claim.getClaimVersionByMemoryId(userId, memoryId);
|
|
284
|
+
if (version)
|
|
285
|
+
return { claimId: version.claim_id, versionId: version.id, memoryId, cmoId };
|
|
286
|
+
const lineage = await emitLineageEvent({ claims: deps.stores.claim, config: deps.config }, {
|
|
287
|
+
kind: 'claim-backfill',
|
|
288
|
+
userId,
|
|
289
|
+
memory: {
|
|
290
|
+
id: memory.id,
|
|
291
|
+
content: memory.content,
|
|
292
|
+
embedding: memory.embedding,
|
|
293
|
+
importance: memory.importance,
|
|
294
|
+
sourceSite: memory.source_site,
|
|
295
|
+
sourceUrl: memory.source_url,
|
|
296
|
+
episodeId: memory.episode_id ?? undefined,
|
|
297
|
+
createdAt: memory.created_at,
|
|
298
|
+
memoryType: memory.memory_type,
|
|
299
|
+
cmoId,
|
|
300
|
+
},
|
|
301
|
+
});
|
|
302
|
+
if (!lineage)
|
|
303
|
+
throw new Error(`Claim backfill unexpectedly skipped for memory: ${memory.id}`);
|
|
304
|
+
return { claimId: lineage.claimId, versionId: lineage.versionId, memoryId: memory.id, cmoId };
|
|
305
|
+
}
|
|
306
|
+
export async function findConflictCandidates(deps, userId, factText, embedding) {
|
|
307
|
+
const [vectorCandidates, keywordCandidates] = await Promise.all([
|
|
308
|
+
deps.stores.search.findNearDuplicates(userId, embedding, deps.config.audnCandidateThreshold),
|
|
309
|
+
deps.stores.search.findKeywordCandidates(userId, extractConflictKeywords(factText)),
|
|
310
|
+
]);
|
|
311
|
+
return mergeCandidates(vectorCandidates, keywordCandidates);
|
|
312
|
+
}
|
|
313
|
+
export async function findSlotConflictCandidates(deps, userId, claimSlot) {
|
|
314
|
+
if (!claimSlot)
|
|
315
|
+
return [];
|
|
316
|
+
const target = await deps.stores.claim.getActiveClaimTargetBySlot(userId, claimSlot.slotKey);
|
|
317
|
+
if (!target)
|
|
318
|
+
return [];
|
|
319
|
+
const memory = await deps.stores.memory.getMemory(target.memoryId, userId);
|
|
320
|
+
if (!memory)
|
|
321
|
+
return [];
|
|
322
|
+
return [{
|
|
323
|
+
id: memory.id,
|
|
324
|
+
content: memory.content,
|
|
325
|
+
similarity: 1,
|
|
326
|
+
importance: memory.importance,
|
|
327
|
+
}];
|
|
328
|
+
}
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* MSR cross-conversation aggregator.
|
|
3
|
+
*
|
|
4
|
+
* Retrieval-side intervention for multi-session-reasoning queries. v39-multihop
|
|
5
|
+
* diagnostic on v26 MSR failures: gold facts WERE in the top-K but spread
|
|
6
|
+
* across 2-4 conversations; the answer LLM could not synthesize them and
|
|
7
|
+
* returned inflated counts ("Twenty-three" vs gold "Four").
|
|
8
|
+
*
|
|
9
|
+
* Strategy: group retrieved memories by `episode_id` (= conversation id in
|
|
10
|
+
* BEAM). For each group with >=2 memories, emit a 1-sentence summary via the
|
|
11
|
+
* configured chat LLM (cheap — defaults to Haiku). Groups with a single
|
|
12
|
+
* memory pass through verbatim (no LLM call). The concatenated
|
|
13
|
+
* `## CONVERSATION N SUMMARY` blocks become an additional channel BEFORE
|
|
14
|
+
* the standard OBSERVATIONS / TIMELINE / ENTITY_STATE blocks.
|
|
15
|
+
*
|
|
16
|
+
* Fail-closed: any LLM error during summarization throws — no silent
|
|
17
|
+
* fallback to raw text. Matches the AUDN mutation invariant.
|
|
18
|
+
*/
|
|
19
|
+
import type { SearchResult } from '../db/memory-repository.js';
|
|
20
|
+
import type { LLMProvider } from './llm.js';
|
|
21
|
+
/** Caller-supplied dependencies. Decoupled from MemoryServiceDeps for testability. */
|
|
22
|
+
export interface MsrAggregatorDeps {
|
|
23
|
+
/** Chat LLM provider — shared singleton in production, mocked in tests. */
|
|
24
|
+
llm: LLMProvider;
|
|
25
|
+
/** Model used for per-conversation summary calls. Default Haiku-cheap. */
|
|
26
|
+
model: string;
|
|
27
|
+
/** Optional override for the per-summary token budget. Default 80. */
|
|
28
|
+
maxTokensPerSummary?: number;
|
|
29
|
+
}
|
|
30
|
+
/**
|
|
31
|
+
* Build the per-conversation aggregated string. Groups are 1-indexed by
|
|
32
|
+
* first-seen episode order. Multi-memory groups go through the LLM; single-
|
|
33
|
+
* memory groups pass through verbatim.
|
|
34
|
+
*
|
|
35
|
+
* Returns an empty string when there are no retrieved memories — caller
|
|
36
|
+
* should treat that as "no MSR channel to add" and skip the prefix.
|
|
37
|
+
*/
|
|
38
|
+
export declare function aggregateByConversation(memories: ReadonlyArray<SearchResult>, query: string, deps: MsrAggregatorDeps): Promise<string>;
|