@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,156 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @file Document-scoped delete cascades.
|
|
3
|
+
*
|
|
4
|
+
* Owns `softDeleteDocumentCascade` (single-document) and
|
|
5
|
+
* `deleteBySource` (source-reset), plus the Step-7 helpers that
|
|
6
|
+
* soft-delete linked `storage_artifacts` rows in the same
|
|
7
|
+
* transaction. Extracted from `repository-write.ts` to keep that
|
|
8
|
+
* module under the workspace 400-non-comment-LOC cap.
|
|
9
|
+
*/
|
|
10
|
+
import { deleteDocumentsBySourceWithClient, softDeleteRawDocument, } from './raw-document-repository.js';
|
|
11
|
+
import { deleteChunksBySourceWithClient, softDeleteChunksForDocument } from './document-chunk-repository.js';
|
|
12
|
+
import { listManagedBlobsBySourceWithClient, listManagedBlobsForDocumentWithClient, } from './raw-document-blob-repository.js';
|
|
13
|
+
import { softDeleteMemoriesForDocument } from './repository-write.js';
|
|
14
|
+
/**
|
|
15
|
+
* Soft-delete a document together with the chunks + provenance-linked
|
|
16
|
+
* memories materialized from it (Phase 2). Runs in one transaction
|
|
17
|
+
* with a per-document advisory lock so a concurrent index call
|
|
18
|
+
* serializes cleanly. Idempotent: returns `{ removed: false }` when
|
|
19
|
+
* the document was already missing/deleted/owned by a different user.
|
|
20
|
+
*
|
|
21
|
+
* Step 7 — when the document has no managed blob to clean up
|
|
22
|
+
* (pointer-only, or already-terminal managed), the linked
|
|
23
|
+
* `storage_artifacts` row is soft-deleted in the same transaction.
|
|
24
|
+
* The cleanup path handles the managed case via the paired
|
|
25
|
+
* `markCleanupSuccessAndSyncArtifact` helper.
|
|
26
|
+
*/
|
|
27
|
+
export async function softDeleteDocumentCascade(pool, userId, documentId) {
|
|
28
|
+
const client = await pool.connect();
|
|
29
|
+
try {
|
|
30
|
+
await client.query('BEGIN');
|
|
31
|
+
await client.query('SELECT pg_advisory_xact_lock(hashtext($1))', [documentId]);
|
|
32
|
+
const blobs = await listManagedBlobsForDocumentWithClient(client, userId, documentId);
|
|
33
|
+
const memoriesDeleted = await softDeleteMemoriesForDocument(client, userId, documentId);
|
|
34
|
+
const chunksDeleted = await softDeleteChunksForDocument(client, userId, documentId);
|
|
35
|
+
const removed = await softDeleteRawDocument(client, userId, documentId);
|
|
36
|
+
if (removed && blobs.length === 0) {
|
|
37
|
+
await softDeleteLinkedArtifactForDocumentWithClient(client, userId, documentId);
|
|
38
|
+
}
|
|
39
|
+
await client.query('COMMIT');
|
|
40
|
+
return { removed, memoriesDeleted, chunksDeleted, blobs: removed ? blobs : [] };
|
|
41
|
+
}
|
|
42
|
+
catch (err) {
|
|
43
|
+
await client.query('ROLLBACK').catch(() => undefined);
|
|
44
|
+
throw err;
|
|
45
|
+
}
|
|
46
|
+
finally {
|
|
47
|
+
client.release();
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
/**
|
|
51
|
+
* Soft-delete the `storage_artifacts` row linked to a document
|
|
52
|
+
* inside an open transaction. No-op when the document has no link.
|
|
53
|
+
* Owner-scoped on the document side; the artifact's composite FK
|
|
54
|
+
* to `(id, user_id)` already prevents cross-user pairings.
|
|
55
|
+
*
|
|
56
|
+
* Skips rows whose delete lifecycle has already started
|
|
57
|
+
* (`status IN ('deleting', 'deleted', 'delete_failed')`). After the
|
|
58
|
+
* Commit D reorder, `StorageService.deleteArtifact` claims the
|
|
59
|
+
* artifact BEFORE cascading documents — so when this helper runs
|
|
60
|
+
* during a `policy=with_documents` cascade, the artifact is
|
|
61
|
+
* already at `status='deleting'` and the storage service's own
|
|
62
|
+
* finalize step owns the terminal transition. Clobbering the
|
|
63
|
+
* status here would race the finalize CAS and surface
|
|
64
|
+
* `markDeleteSuccess: no matching claim`.
|
|
65
|
+
*/
|
|
66
|
+
async function softDeleteLinkedArtifactForDocumentWithClient(client, userId, documentId) {
|
|
67
|
+
await client.query(`UPDATE storage_artifacts sa
|
|
68
|
+
SET status = 'deleted',
|
|
69
|
+
deleted_at = COALESCE(sa.deleted_at, NOW()),
|
|
70
|
+
delete_attempt_id = NULL,
|
|
71
|
+
updated_at = NOW()
|
|
72
|
+
FROM raw_documents rd
|
|
73
|
+
WHERE rd.id = $1
|
|
74
|
+
AND rd.user_id = $2
|
|
75
|
+
AND rd.storage_artifact_id = sa.id
|
|
76
|
+
AND sa.status NOT IN ('deleting', 'deleted', 'delete_failed')`, [documentId, userId]);
|
|
77
|
+
}
|
|
78
|
+
/**
|
|
79
|
+
* Source-reset variant — soft-deletes any pointer (or already-
|
|
80
|
+
* clean managed) artifact linked to a document under the given
|
|
81
|
+
* source. Managed-blob rows that still need cleanup are left to
|
|
82
|
+
* the post-commit cleanup path.
|
|
83
|
+
*
|
|
84
|
+
* Skips rows whose delete lifecycle has already started
|
|
85
|
+
* (`status IN ('deleting', 'deleted', 'delete_failed')`). Without
|
|
86
|
+
* this guard a source reset racing `StorageService.deleteArtifact`
|
|
87
|
+
* could clobber the artifact's claimed `delete_attempt_id`, causing
|
|
88
|
+
* the storage service's finalize CAS to miss after `backend.delete`
|
|
89
|
+
* runs. Mirrors the same guard on
|
|
90
|
+
* `softDeleteLinkedArtifactForDocumentWithClient`.
|
|
91
|
+
*/
|
|
92
|
+
async function softDeleteLinkedArtifactsForSourceWithClient(client, userId, sourceSite) {
|
|
93
|
+
await client.query(`UPDATE storage_artifacts sa
|
|
94
|
+
SET status = 'deleted',
|
|
95
|
+
deleted_at = COALESCE(sa.deleted_at, NOW()),
|
|
96
|
+
delete_attempt_id = NULL,
|
|
97
|
+
updated_at = NOW()
|
|
98
|
+
FROM raw_documents rd
|
|
99
|
+
JOIN raw_sources rs ON rs.id = rd.raw_source_id
|
|
100
|
+
WHERE rs.user_id = $1
|
|
101
|
+
AND rs.source_site = $2
|
|
102
|
+
AND rd.user_id = $1
|
|
103
|
+
AND rd.storage_artifact_id = sa.id
|
|
104
|
+
AND sa.status NOT IN ('deleting', 'deleted', 'delete_failed')
|
|
105
|
+
AND (rd.storage_uri IS NULL OR rd.raw_storage_status IN ('blob_deleted', 'blob_tombstoned'))`, [userId, sourceSite]);
|
|
106
|
+
}
|
|
107
|
+
/**
|
|
108
|
+
* Delete all data for a given user + source_site combination.
|
|
109
|
+
* Hard-deletes across memory-side tables and soft-deletes
|
|
110
|
+
* (tombstones) matching `raw_documents` in safe referential order
|
|
111
|
+
* within a single transaction. Step 7 — soft-deletes the linked
|
|
112
|
+
* `storage_artifacts` rows for pointer-only / terminal-managed
|
|
113
|
+
* docs in the same transaction, so a source reset cannot leave
|
|
114
|
+
* orphan active artifact links.
|
|
115
|
+
*/
|
|
116
|
+
export async function deleteBySource(pool, userId, sourceSite) {
|
|
117
|
+
const client = await pool.connect();
|
|
118
|
+
try {
|
|
119
|
+
await client.query('BEGIN');
|
|
120
|
+
await client.query(`DELETE FROM memory_evidence
|
|
121
|
+
WHERE claim_version_id IN (
|
|
122
|
+
SELECT id FROM memory_claim_versions WHERE user_id = $1 AND source_site = $2
|
|
123
|
+
)`, [userId, sourceSite]);
|
|
124
|
+
await client.query(`DELETE FROM memory_claim_versions WHERE user_id = $1 AND source_site = $2`, [userId, sourceSite]);
|
|
125
|
+
await client.query(`DELETE FROM memory_claims
|
|
126
|
+
WHERE user_id = $1
|
|
127
|
+
AND id NOT IN (SELECT claim_id FROM memory_claim_versions WHERE user_id = $1)`, [userId]);
|
|
128
|
+
await client.query(`DELETE FROM memory_links
|
|
129
|
+
WHERE source_id IN (SELECT id FROM memories WHERE user_id = $1 AND source_site = $2 AND workspace_id IS NULL)
|
|
130
|
+
OR target_id IN (SELECT id FROM memories WHERE user_id = $1 AND source_site = $2 AND workspace_id IS NULL)`, [userId, sourceSite]);
|
|
131
|
+
await client.query(`DELETE FROM memory_entities
|
|
132
|
+
WHERE memory_id IN (SELECT id FROM memories WHERE user_id = $1 AND source_site = $2 AND workspace_id IS NULL)`, [userId, sourceSite]);
|
|
133
|
+
await client.query(`DELETE FROM memory_atomic_facts WHERE user_id = $1 AND source_site = $2
|
|
134
|
+
AND parent_memory_id IN (SELECT id FROM memories WHERE user_id = $1 AND source_site = $2 AND workspace_id IS NULL)`, [userId, sourceSite]);
|
|
135
|
+
const memResult = await client.query(`DELETE FROM memories WHERE user_id = $1 AND source_site = $2 AND workspace_id IS NULL RETURNING id`, [userId, sourceSite]);
|
|
136
|
+
const epResult = await client.query(`DELETE FROM episodes WHERE user_id = $1 AND source_site = $2 RETURNING id`, [userId, sourceSite]);
|
|
137
|
+
const blobs = await listManagedBlobsBySourceWithClient(client, userId, sourceSite);
|
|
138
|
+
await deleteChunksBySourceWithClient(client, userId, sourceSite);
|
|
139
|
+
const deletedDocuments = await deleteDocumentsBySourceWithClient(client, userId, sourceSite);
|
|
140
|
+
await softDeleteLinkedArtifactsForSourceWithClient(client, userId, sourceSite);
|
|
141
|
+
await client.query('COMMIT');
|
|
142
|
+
return {
|
|
143
|
+
deletedMemories: memResult.rowCount ?? 0,
|
|
144
|
+
deletedEpisodes: epResult.rowCount ?? 0,
|
|
145
|
+
deletedDocuments,
|
|
146
|
+
blobs,
|
|
147
|
+
};
|
|
148
|
+
}
|
|
149
|
+
catch (err) {
|
|
150
|
+
await client.query('ROLLBACK');
|
|
151
|
+
throw err;
|
|
152
|
+
}
|
|
153
|
+
finally {
|
|
154
|
+
client.release();
|
|
155
|
+
}
|
|
156
|
+
}
|
|
@@ -0,0 +1,114 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Entity graph repository — stores structured entities extracted from memories,
|
|
3
|
+
* handles entity resolution (dedup by embedding similarity + type match), and
|
|
4
|
+
* provides entity-aware retrieval expansion for multi-hop queries.
|
|
5
|
+
*/
|
|
6
|
+
import pg from 'pg';
|
|
7
|
+
import { type EntityRow, type EntityRelationRow, type EntityType, type RelationType } from './repository-types.js';
|
|
8
|
+
export interface EntityInput {
|
|
9
|
+
userId: string;
|
|
10
|
+
name: string;
|
|
11
|
+
entityType: EntityType;
|
|
12
|
+
embedding: number[];
|
|
13
|
+
aliasNames?: string[];
|
|
14
|
+
}
|
|
15
|
+
export declare class EntityRepository {
|
|
16
|
+
private pool;
|
|
17
|
+
constructor(pool: pg.Pool);
|
|
18
|
+
/**
|
|
19
|
+
* Shared implementation: run a distinct-ID query and filter out excluded IDs.
|
|
20
|
+
* Both findMemoryIdsByEntities and findRelatedEntityIds delegate here.
|
|
21
|
+
*/
|
|
22
|
+
private findRelatedIdsExcluding;
|
|
23
|
+
/**
|
|
24
|
+
* Resolve-or-create: find an existing entity with the same type and embedding
|
|
25
|
+
* similarity above threshold, or create a new one. Returns the entity ID.
|
|
26
|
+
*/
|
|
27
|
+
resolveEntity(input: EntityInput): Promise<string>;
|
|
28
|
+
resolveEntityWithClient(client: pg.PoolClient, input: EntityInput): Promise<string>;
|
|
29
|
+
findDeterministicEntity(userId: string, entityType: EntityType, name: string, client?: pg.PoolClient | pg.Pool): Promise<EntityRow | null>;
|
|
30
|
+
/**
|
|
31
|
+
* Find the most similar entity of the same type above the resolution threshold.
|
|
32
|
+
*/
|
|
33
|
+
findSimilarEntity(client: pg.PoolClient | pg.Pool, userId: string, entityType: EntityType, embedding: number[]): Promise<EntityRow | null>;
|
|
34
|
+
/**
|
|
35
|
+
* Create a new entity record.
|
|
36
|
+
*/
|
|
37
|
+
createEntity(client: pg.PoolClient | pg.Pool, input: EntityInput): Promise<string>;
|
|
38
|
+
/**
|
|
39
|
+
* Add a name alias to an existing entity if not already present.
|
|
40
|
+
*/
|
|
41
|
+
mergeAlias(client: pg.PoolClient | pg.Pool, entityId: string, alias: string): Promise<void>;
|
|
42
|
+
/**
|
|
43
|
+
* Link a memory to an entity.
|
|
44
|
+
*/
|
|
45
|
+
linkMemoryToEntity(memoryId: string, entityId: string): Promise<void>;
|
|
46
|
+
/**
|
|
47
|
+
* Find all memory IDs linked to a set of entity IDs. Returns unique IDs
|
|
48
|
+
* excluding any in the exclude set.
|
|
49
|
+
*/
|
|
50
|
+
findMemoryIdsByEntities(userId: string, entityIds: string[], excludeIds: Set<string>, limit: number): Promise<string[]>;
|
|
51
|
+
/**
|
|
52
|
+
* Find entities by exact or substring name match (case-insensitive).
|
|
53
|
+
* Used for co-retrieval when a query mentions a known entity by name.
|
|
54
|
+
*/
|
|
55
|
+
findEntitiesByName(userId: string, name: string, limit?: number): Promise<EntityRow[]>;
|
|
56
|
+
/**
|
|
57
|
+
* Find entities matching a query embedding (for query-time entity extraction).
|
|
58
|
+
*/
|
|
59
|
+
searchEntities(userId: string, queryEmbedding: number[], limit: number, minSimilarity?: number): Promise<Array<EntityRow & {
|
|
60
|
+
similarity: number;
|
|
61
|
+
}>>;
|
|
62
|
+
/**
|
|
63
|
+
* Get all entities linked to a specific memory.
|
|
64
|
+
*/
|
|
65
|
+
getEntitiesForMemory(memoryId: string): Promise<EntityRow[]>;
|
|
66
|
+
/**
|
|
67
|
+
* Get an entity by ID.
|
|
68
|
+
*/
|
|
69
|
+
getEntity(id: string): Promise<EntityRow | null>;
|
|
70
|
+
/**
|
|
71
|
+
* Count entities for a user.
|
|
72
|
+
*/
|
|
73
|
+
countEntities(userId: string): Promise<number>;
|
|
74
|
+
/**
|
|
75
|
+
* Create or update a relation between two entities. Upserts on the
|
|
76
|
+
* (source, target, type) unique constraint, updating confidence if higher.
|
|
77
|
+
*/
|
|
78
|
+
upsertRelation(input: {
|
|
79
|
+
userId: string;
|
|
80
|
+
sourceEntityId: string;
|
|
81
|
+
targetEntityId: string;
|
|
82
|
+
relationType: RelationType;
|
|
83
|
+
sourceMemoryId?: string;
|
|
84
|
+
confidence?: number;
|
|
85
|
+
}): Promise<string>;
|
|
86
|
+
/**
|
|
87
|
+
* Find all entities related to a set of entity IDs (1-hop traversal).
|
|
88
|
+
* Follows relations in both directions to find connected entities.
|
|
89
|
+
*/
|
|
90
|
+
findRelatedEntityIds(userId: string, entityIds: string[], excludeIds: Set<string>, limit: number): Promise<string[]>;
|
|
91
|
+
/**
|
|
92
|
+
* Get all relations for an entity (both directions).
|
|
93
|
+
*/
|
|
94
|
+
getRelationsForEntity(entityId: string): Promise<EntityRelationRow[]>;
|
|
95
|
+
/**
|
|
96
|
+
* Get active relations supported by the entities linked to a specific memory.
|
|
97
|
+
* This follows the linked entity set instead of relying solely on the first
|
|
98
|
+
* source_memory_id, so current claims can still recover a slot even when the
|
|
99
|
+
* same relation was first observed in an older memory.
|
|
100
|
+
*/
|
|
101
|
+
getRelationsForMemory(userId: string, memoryId: string): Promise<EntityRelationRow[]>;
|
|
102
|
+
/**
|
|
103
|
+
* Invalidate a relation by setting valid_to.
|
|
104
|
+
*/
|
|
105
|
+
invalidateRelation(relationId: string, validTo?: Date): Promise<void>;
|
|
106
|
+
/**
|
|
107
|
+
* Count active relations for a user.
|
|
108
|
+
*/
|
|
109
|
+
countRelations(userId: string): Promise<number>;
|
|
110
|
+
/**
|
|
111
|
+
* Delete all entities, relations, and memory_entities for a user or all users.
|
|
112
|
+
*/
|
|
113
|
+
deleteAll(userId?: string): Promise<void>;
|
|
114
|
+
}
|
|
@@ -0,0 +1,317 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Entity graph repository — stores structured entities extracted from memories,
|
|
3
|
+
* handles entity resolution (dedup by embedding similarity + type match), and
|
|
4
|
+
* provides entity-aware retrieval expansion for multi-hop queries.
|
|
5
|
+
*/
|
|
6
|
+
import pgvector from 'pgvector/pg';
|
|
7
|
+
import { config } from '../config.js';
|
|
8
|
+
import { normalizeEntityRow, } from './repository-types.js';
|
|
9
|
+
/** Threshold above which two entities with the same type are considered duplicates. */
|
|
10
|
+
const ENTITY_RESOLUTION_THRESHOLD = config.entityResolutionThreshold;
|
|
11
|
+
/**
|
|
12
|
+
* Normalize entity names for deterministic canonicalization before embedding
|
|
13
|
+
* similarity is consulted. This is intentionally conservative: punctuation and
|
|
14
|
+
* spacing differences collapse, but semantic rewrites do not.
|
|
15
|
+
*/
|
|
16
|
+
/** Extract IDs from query rows and filter out excluded ones. */
|
|
17
|
+
function filterExcludedIds(rows, idField, excludeIds) {
|
|
18
|
+
return rows
|
|
19
|
+
.map((r) => r[idField])
|
|
20
|
+
.filter((id) => !excludeIds.has(id));
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* Run a query that returns distinct IDs from a join, then exclude already-seen IDs.
|
|
24
|
+
* Shared by findMemoryIdsByEntities and findRelatedEntityIds.
|
|
25
|
+
*/
|
|
26
|
+
async function queryDistinctIdsWithExclusion(pool, sql, params, idField, excludeIds) {
|
|
27
|
+
const result = await pool.query(sql, params);
|
|
28
|
+
return filterExcludedIds(result.rows, idField, excludeIds);
|
|
29
|
+
}
|
|
30
|
+
function normalizeEntityName(name) {
|
|
31
|
+
const normalized = name
|
|
32
|
+
.normalize('NFKD')
|
|
33
|
+
.replace(/[\u0300-\u036f]/g, '')
|
|
34
|
+
.toLowerCase()
|
|
35
|
+
.replace(/[^a-z0-9+#]+/g, ' ')
|
|
36
|
+
.trim()
|
|
37
|
+
.replace(/\s+/g, ' ');
|
|
38
|
+
return normalized || name.trim().toLowerCase();
|
|
39
|
+
}
|
|
40
|
+
export class EntityRepository {
|
|
41
|
+
pool;
|
|
42
|
+
constructor(pool) {
|
|
43
|
+
this.pool = pool;
|
|
44
|
+
}
|
|
45
|
+
/**
|
|
46
|
+
* Shared implementation: run a distinct-ID query and filter out excluded IDs.
|
|
47
|
+
* Both findMemoryIdsByEntities and findRelatedEntityIds delegate here.
|
|
48
|
+
*/
|
|
49
|
+
async findRelatedIdsExcluding(sql, idField, userId, entityIds, excludeIds, limit) {
|
|
50
|
+
if (entityIds.length === 0)
|
|
51
|
+
return [];
|
|
52
|
+
return queryDistinctIdsWithExclusion(this.pool, sql, [userId, entityIds, limit], idField, excludeIds);
|
|
53
|
+
}
|
|
54
|
+
/**
|
|
55
|
+
* Resolve-or-create: find an existing entity with the same type and embedding
|
|
56
|
+
* similarity above threshold, or create a new one. Returns the entity ID.
|
|
57
|
+
*/
|
|
58
|
+
async resolveEntity(input) {
|
|
59
|
+
return this.resolveEntityWithClient(this.pool, input);
|
|
60
|
+
}
|
|
61
|
+
async resolveEntityWithClient(client, input) {
|
|
62
|
+
const deterministicMatch = await this.findDeterministicEntity(input.userId, input.entityType, input.name, client);
|
|
63
|
+
if (deterministicMatch) {
|
|
64
|
+
await this.mergeAlias(client, deterministicMatch.id, input.name);
|
|
65
|
+
return deterministicMatch.id;
|
|
66
|
+
}
|
|
67
|
+
const match = await this.findSimilarEntity(client, input.userId, input.entityType, input.embedding);
|
|
68
|
+
if (match) {
|
|
69
|
+
await this.mergeAlias(client, match.id, input.name);
|
|
70
|
+
return match.id;
|
|
71
|
+
}
|
|
72
|
+
return this.createEntity(client, input);
|
|
73
|
+
}
|
|
74
|
+
async findDeterministicEntity(userId, entityType, name, client = this.pool) {
|
|
75
|
+
const normalizedName = normalizeEntityName(name);
|
|
76
|
+
const result = await client.query(`SELECT *
|
|
77
|
+
FROM entities
|
|
78
|
+
WHERE user_id = $1
|
|
79
|
+
AND entity_type = $2
|
|
80
|
+
AND (
|
|
81
|
+
normalized_name = $3
|
|
82
|
+
OR $3 = ANY(normalized_alias_names)
|
|
83
|
+
)
|
|
84
|
+
ORDER BY created_at ASC
|
|
85
|
+
LIMIT 1`, [userId, entityType, normalizedName]);
|
|
86
|
+
return result.rows[0] ? normalizeEntityRow(result.rows[0]) : null;
|
|
87
|
+
}
|
|
88
|
+
/**
|
|
89
|
+
* Find the most similar entity of the same type above the resolution threshold.
|
|
90
|
+
*/
|
|
91
|
+
async findSimilarEntity(client, userId, entityType, embedding) {
|
|
92
|
+
const result = await client.query(`SELECT *, 1 - (embedding <=> $1) AS similarity
|
|
93
|
+
FROM entities
|
|
94
|
+
WHERE user_id = $2 AND entity_type = $3
|
|
95
|
+
AND 1 - (embedding <=> $1) >= $4
|
|
96
|
+
ORDER BY similarity DESC
|
|
97
|
+
LIMIT 1`, [pgvector.toSql(embedding), userId, entityType, ENTITY_RESOLUTION_THRESHOLD]);
|
|
98
|
+
return result.rows[0] ? normalizeEntityRow(result.rows[0]) : null;
|
|
99
|
+
}
|
|
100
|
+
/**
|
|
101
|
+
* Create a new entity record.
|
|
102
|
+
*/
|
|
103
|
+
async createEntity(client, input) {
|
|
104
|
+
const normalizedName = normalizeEntityName(input.name);
|
|
105
|
+
const aliasNames = [...new Set((input.aliasNames ?? []).filter((alias) => alias !== input.name))];
|
|
106
|
+
const normalizedAliasNames = [...new Set(aliasNames
|
|
107
|
+
.map(normalizeEntityName)
|
|
108
|
+
.filter((alias) => Boolean(alias) && alias !== normalizedName))];
|
|
109
|
+
const result = await client.query(`INSERT INTO entities (
|
|
110
|
+
user_id, name, normalized_name, entity_type, embedding, alias_names, normalized_alias_names
|
|
111
|
+
)
|
|
112
|
+
VALUES ($1, $2, $3, $4, $5, $6, $7) RETURNING id`, [
|
|
113
|
+
input.userId,
|
|
114
|
+
input.name,
|
|
115
|
+
normalizedName,
|
|
116
|
+
input.entityType,
|
|
117
|
+
pgvector.toSql(input.embedding),
|
|
118
|
+
aliasNames,
|
|
119
|
+
normalizedAliasNames,
|
|
120
|
+
]);
|
|
121
|
+
return result.rows[0].id;
|
|
122
|
+
}
|
|
123
|
+
/**
|
|
124
|
+
* Add a name alias to an existing entity if not already present.
|
|
125
|
+
*/
|
|
126
|
+
async mergeAlias(client, entityId, alias) {
|
|
127
|
+
const normalizedAlias = normalizeEntityName(alias);
|
|
128
|
+
await client.query(`UPDATE entities
|
|
129
|
+
SET alias_names = CASE
|
|
130
|
+
WHEN $2 = ANY(alias_names) OR lower($2) = lower(name) OR $3 = ANY(normalized_alias_names) THEN alias_names
|
|
131
|
+
ELSE array_append(alias_names, $2)
|
|
132
|
+
END,
|
|
133
|
+
normalized_alias_names = CASE
|
|
134
|
+
WHEN $3 = normalized_name OR $3 = ANY(normalized_alias_names) THEN normalized_alias_names
|
|
135
|
+
ELSE array_append(normalized_alias_names, $3)
|
|
136
|
+
END,
|
|
137
|
+
updated_at = NOW()
|
|
138
|
+
WHERE id = $1`, [entityId, alias, normalizedAlias]);
|
|
139
|
+
}
|
|
140
|
+
/**
|
|
141
|
+
* Link a memory to an entity.
|
|
142
|
+
*/
|
|
143
|
+
async linkMemoryToEntity(memoryId, entityId) {
|
|
144
|
+
await this.pool.query(`INSERT INTO memory_entities (memory_id, entity_id)
|
|
145
|
+
VALUES ($1, $2)
|
|
146
|
+
ON CONFLICT DO NOTHING`, [memoryId, entityId]);
|
|
147
|
+
}
|
|
148
|
+
/**
|
|
149
|
+
* Find all memory IDs linked to a set of entity IDs. Returns unique IDs
|
|
150
|
+
* excluding any in the exclude set.
|
|
151
|
+
*/
|
|
152
|
+
async findMemoryIdsByEntities(userId, entityIds, excludeIds, limit) {
|
|
153
|
+
return this.findRelatedIdsExcluding(`SELECT DISTINCT me.memory_id
|
|
154
|
+
FROM memory_entities me
|
|
155
|
+
JOIN memories m ON m.id = me.memory_id AND m.deleted_at IS NULL AND m.expired_at IS NULL AND m.workspace_id IS NULL
|
|
156
|
+
JOIN entities e ON e.id = me.entity_id
|
|
157
|
+
WHERE e.user_id = $1
|
|
158
|
+
AND m.user_id = $1
|
|
159
|
+
AND me.entity_id = ANY($2)
|
|
160
|
+
LIMIT $3`, 'memory_id', userId, entityIds, excludeIds, limit);
|
|
161
|
+
}
|
|
162
|
+
/**
|
|
163
|
+
* Find entities by exact or substring name match (case-insensitive).
|
|
164
|
+
* Used for co-retrieval when a query mentions a known entity by name.
|
|
165
|
+
*/
|
|
166
|
+
async findEntitiesByName(userId, name, limit = 10) {
|
|
167
|
+
const normalizedName = normalizeEntityName(name);
|
|
168
|
+
const result = await this.pool.query(`SELECT * FROM entities
|
|
169
|
+
WHERE user_id = $1
|
|
170
|
+
AND (
|
|
171
|
+
normalized_name = $2
|
|
172
|
+
OR $2 = ANY(normalized_alias_names)
|
|
173
|
+
)
|
|
174
|
+
ORDER BY created_at ASC
|
|
175
|
+
LIMIT $3`, [userId, normalizedName, limit]);
|
|
176
|
+
return result.rows.map(normalizeEntityRow);
|
|
177
|
+
}
|
|
178
|
+
/**
|
|
179
|
+
* Find entities matching a query embedding (for query-time entity extraction).
|
|
180
|
+
*/
|
|
181
|
+
async searchEntities(userId, queryEmbedding, limit, minSimilarity = 0.7) {
|
|
182
|
+
const result = await this.pool.query(`SELECT *, 1 - (embedding <=> $1) AS similarity
|
|
183
|
+
FROM entities
|
|
184
|
+
WHERE user_id = $2
|
|
185
|
+
AND 1 - (embedding <=> $1) >= $4
|
|
186
|
+
ORDER BY similarity DESC
|
|
187
|
+
LIMIT $3`, [pgvector.toSql(queryEmbedding), userId, limit, minSimilarity]);
|
|
188
|
+
return result.rows.map((row) => ({
|
|
189
|
+
...normalizeEntityRow(row),
|
|
190
|
+
similarity: row.similarity,
|
|
191
|
+
}));
|
|
192
|
+
}
|
|
193
|
+
/**
|
|
194
|
+
* Get all entities linked to a specific memory.
|
|
195
|
+
*/
|
|
196
|
+
async getEntitiesForMemory(memoryId) {
|
|
197
|
+
const result = await this.pool.query(`SELECT e.* FROM entities e
|
|
198
|
+
JOIN memory_entities me ON me.entity_id = e.id
|
|
199
|
+
WHERE me.memory_id = $1`, [memoryId]);
|
|
200
|
+
return result.rows.map(normalizeEntityRow);
|
|
201
|
+
}
|
|
202
|
+
/**
|
|
203
|
+
* Get an entity by ID.
|
|
204
|
+
*/
|
|
205
|
+
async getEntity(id) {
|
|
206
|
+
const result = await this.pool.query(`SELECT * FROM entities WHERE id = $1`, [id]);
|
|
207
|
+
return result.rows[0] ? normalizeEntityRow(result.rows[0]) : null;
|
|
208
|
+
}
|
|
209
|
+
/**
|
|
210
|
+
* Count entities for a user.
|
|
211
|
+
*/
|
|
212
|
+
async countEntities(userId) {
|
|
213
|
+
const result = await this.pool.query(`SELECT COUNT(*)::int AS count FROM entities WHERE user_id = $1`, [userId]);
|
|
214
|
+
return result.rows[0].count;
|
|
215
|
+
}
|
|
216
|
+
// ─── Relations ───────────────────────────────────────────────────────
|
|
217
|
+
/**
|
|
218
|
+
* Create or update a relation between two entities. Upserts on the
|
|
219
|
+
* (source, target, type) unique constraint, updating confidence if higher.
|
|
220
|
+
*/
|
|
221
|
+
async upsertRelation(input) {
|
|
222
|
+
const result = await this.pool.query(`INSERT INTO entity_relations
|
|
223
|
+
(user_id, source_entity_id, target_entity_id, relation_type, source_memory_id, confidence)
|
|
224
|
+
VALUES ($1, $2, $3, $4, $5, $6)
|
|
225
|
+
ON CONFLICT (source_entity_id, target_entity_id, relation_type)
|
|
226
|
+
DO UPDATE SET
|
|
227
|
+
confidence = GREATEST(entity_relations.confidence, EXCLUDED.confidence),
|
|
228
|
+
source_memory_id = EXCLUDED.source_memory_id
|
|
229
|
+
RETURNING id`, [
|
|
230
|
+
input.userId,
|
|
231
|
+
input.sourceEntityId,
|
|
232
|
+
input.targetEntityId,
|
|
233
|
+
input.relationType,
|
|
234
|
+
input.sourceMemoryId ?? null,
|
|
235
|
+
input.confidence ?? 1.0,
|
|
236
|
+
]);
|
|
237
|
+
return result.rows[0].id;
|
|
238
|
+
}
|
|
239
|
+
/**
|
|
240
|
+
* Find all entities related to a set of entity IDs (1-hop traversal).
|
|
241
|
+
* Follows relations in both directions to find connected entities.
|
|
242
|
+
*/
|
|
243
|
+
async findRelatedEntityIds(userId, entityIds, excludeIds, limit) {
|
|
244
|
+
return this.findRelatedIdsExcluding(`SELECT DISTINCT entity_id FROM (
|
|
245
|
+
SELECT target_entity_id AS entity_id
|
|
246
|
+
FROM entity_relations
|
|
247
|
+
WHERE user_id = $1 AND source_entity_id = ANY($2) AND valid_to IS NULL
|
|
248
|
+
UNION
|
|
249
|
+
SELECT source_entity_id AS entity_id
|
|
250
|
+
FROM entity_relations
|
|
251
|
+
WHERE user_id = $1 AND target_entity_id = ANY($2) AND valid_to IS NULL
|
|
252
|
+
) AS related
|
|
253
|
+
LIMIT $3`, 'entity_id', userId, entityIds, excludeIds, limit);
|
|
254
|
+
}
|
|
255
|
+
/**
|
|
256
|
+
* Get all relations for an entity (both directions).
|
|
257
|
+
*/
|
|
258
|
+
async getRelationsForEntity(entityId) {
|
|
259
|
+
const result = await this.pool.query(`SELECT * FROM entity_relations
|
|
260
|
+
WHERE (source_entity_id = $1 OR target_entity_id = $1)
|
|
261
|
+
AND valid_to IS NULL
|
|
262
|
+
ORDER BY created_at DESC`, [entityId]);
|
|
263
|
+
return result.rows;
|
|
264
|
+
}
|
|
265
|
+
/**
|
|
266
|
+
* Get active relations supported by the entities linked to a specific memory.
|
|
267
|
+
* This follows the linked entity set instead of relying solely on the first
|
|
268
|
+
* source_memory_id, so current claims can still recover a slot even when the
|
|
269
|
+
* same relation was first observed in an older memory.
|
|
270
|
+
*/
|
|
271
|
+
async getRelationsForMemory(userId, memoryId) {
|
|
272
|
+
const result = await this.pool.query(`SELECT er.*
|
|
273
|
+
FROM entity_relations er
|
|
274
|
+
JOIN memory_entities me_source
|
|
275
|
+
ON me_source.entity_id = er.source_entity_id
|
|
276
|
+
AND me_source.memory_id = $2
|
|
277
|
+
JOIN memory_entities me_target
|
|
278
|
+
ON me_target.entity_id = er.target_entity_id
|
|
279
|
+
AND me_target.memory_id = $2
|
|
280
|
+
WHERE er.user_id = $1
|
|
281
|
+
AND valid_to IS NULL
|
|
282
|
+
ORDER BY (er.source_memory_id = $2) DESC,
|
|
283
|
+
er.relation_type ASC,
|
|
284
|
+
er.source_entity_id ASC,
|
|
285
|
+
er.target_entity_id ASC`, [userId, memoryId]);
|
|
286
|
+
return result.rows;
|
|
287
|
+
}
|
|
288
|
+
/**
|
|
289
|
+
* Invalidate a relation by setting valid_to.
|
|
290
|
+
*/
|
|
291
|
+
async invalidateRelation(relationId, validTo = new Date()) {
|
|
292
|
+
await this.pool.query(`UPDATE entity_relations SET valid_to = $1 WHERE id = $2`, [validTo, relationId]);
|
|
293
|
+
}
|
|
294
|
+
/**
|
|
295
|
+
* Count active relations for a user.
|
|
296
|
+
*/
|
|
297
|
+
async countRelations(userId) {
|
|
298
|
+
const result = await this.pool.query(`SELECT COUNT(*)::int AS count FROM entity_relations
|
|
299
|
+
WHERE user_id = $1 AND valid_to IS NULL`, [userId]);
|
|
300
|
+
return result.rows[0].count;
|
|
301
|
+
}
|
|
302
|
+
/**
|
|
303
|
+
* Delete all entities, relations, and memory_entities for a user or all users.
|
|
304
|
+
*/
|
|
305
|
+
async deleteAll(userId) {
|
|
306
|
+
if (userId) {
|
|
307
|
+
await this.pool.query(`DELETE FROM entity_relations WHERE user_id = $1`, [userId]);
|
|
308
|
+
await this.pool.query(`DELETE FROM memory_entities WHERE entity_id IN (SELECT id FROM entities WHERE user_id = $1)`, [userId]);
|
|
309
|
+
await this.pool.query(`DELETE FROM entities WHERE user_id = $1`, [userId]);
|
|
310
|
+
}
|
|
311
|
+
else {
|
|
312
|
+
await this.pool.query(`DELETE FROM entity_relations`);
|
|
313
|
+
await this.pool.query(`DELETE FROM memory_entities`);
|
|
314
|
+
await this.pool.query(`DELETE FROM entities`);
|
|
315
|
+
}
|
|
316
|
+
}
|
|
317
|
+
}
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Repository for the entity_attributes table (EAI — Sprint 4).
|
|
3
|
+
*
|
|
4
|
+
* Stores (entity, attribute, value) triples. Read path: look up triples
|
|
5
|
+
* for a user by entity_name (fuzzy/lowercase) and/or attribute_key.
|
|
6
|
+
* Write path: bulk insert from the extractor service.
|
|
7
|
+
*/
|
|
8
|
+
import type pg from 'pg';
|
|
9
|
+
export type ValueType = 'number' | 'string' | 'list' | 'boolean' | 'date';
|
|
10
|
+
export interface EntityAttributeRow {
|
|
11
|
+
id: string;
|
|
12
|
+
user_id: string;
|
|
13
|
+
entity_name: string;
|
|
14
|
+
attribute_key: string;
|
|
15
|
+
attribute_value: string;
|
|
16
|
+
value_type: ValueType;
|
|
17
|
+
source_memory_id: string | null;
|
|
18
|
+
observed_at: Date;
|
|
19
|
+
created_at: Date;
|
|
20
|
+
}
|
|
21
|
+
export interface EntityAttributeInput {
|
|
22
|
+
userId: string;
|
|
23
|
+
entityName: string;
|
|
24
|
+
attributeKey: string;
|
|
25
|
+
attributeValue: string;
|
|
26
|
+
valueType: ValueType;
|
|
27
|
+
sourceMemoryId?: string | null;
|
|
28
|
+
observedAt?: Date | null;
|
|
29
|
+
}
|
|
30
|
+
export declare class EntityAttributesRepository {
|
|
31
|
+
private readonly pool;
|
|
32
|
+
constructor(pool: pg.Pool);
|
|
33
|
+
bulkInsert(rows: EntityAttributeInput[]): Promise<number>;
|
|
34
|
+
/** Lookup attributes by entity name (case-insensitive). Returns most-recent first. */
|
|
35
|
+
findByEntity(userId: string, entityName: string, limit?: number): Promise<EntityAttributeRow[]>;
|
|
36
|
+
/** Lookup attributes by attribute key (case-insensitive). Useful for "how many X" queries. */
|
|
37
|
+
findByAttribute(userId: string, attributeKey: string, limit?: number): Promise<EntityAttributeRow[]>;
|
|
38
|
+
/** Combined lookup: entity OR attribute matches; useful when query mentions both. */
|
|
39
|
+
findByEntityOrAttribute(userId: string, tokens: string[], limit?: number): Promise<EntityAttributeRow[]>;
|
|
40
|
+
deleteAllForUser(userId: string): Promise<number>;
|
|
41
|
+
}
|