@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,91 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Phase D — passport feed grouped data-layer query.
|
|
3
|
+
*
|
|
4
|
+
* Returns one row per documentId-with-memories (via `GROUP BY
|
|
5
|
+
* raw_document_id`) plus 1:1 standalone-memory rows (memories whose
|
|
6
|
+
* `raw_document_id IS NULL`), ordered by a unified
|
|
7
|
+
* `(sort_at DESC, sort_id DESC)` cursor.
|
|
8
|
+
*
|
|
9
|
+
* The webapp's `/api/context/passport` route consumes this as the
|
|
10
|
+
* memory-feed stream of its server-side two-stream merge — no
|
|
11
|
+
* webapp-side dedupe, no possibility of a single document spanning
|
|
12
|
+
* pages, no chunk-budget heuristic. A document with N memories
|
|
13
|
+
* appears EXACTLY once on the page that contains its latest
|
|
14
|
+
* chunk.
|
|
15
|
+
*
|
|
16
|
+
* Internal columns (embeddings, audit fields, internal metadata) are
|
|
17
|
+
* NEVER returned by this repository — the SELECT enumerates only the
|
|
18
|
+
* public projection that the route formatter then ships on the wire.
|
|
19
|
+
*
|
|
20
|
+
* Standard `+1 over-fetch` pagination: the route slices the extra
|
|
21
|
+
* row off and encodes its `(sort_at, sort_id)` as `next_cursor`.
|
|
22
|
+
*/
|
|
23
|
+
import type pg from 'pg';
|
|
24
|
+
import { type DocumentListCursor } from './document-list-cursor.js';
|
|
25
|
+
export interface PassportFeedDocumentGroupedRow {
|
|
26
|
+
kind: 'document_grouped';
|
|
27
|
+
documentId: string;
|
|
28
|
+
sortAt: Date;
|
|
29
|
+
sortId: string;
|
|
30
|
+
representative: {
|
|
31
|
+
id: string;
|
|
32
|
+
content: string;
|
|
33
|
+
createdAt: Date;
|
|
34
|
+
sourceSite: string | null;
|
|
35
|
+
};
|
|
36
|
+
chunkCount: number;
|
|
37
|
+
rawStorageStatus: string;
|
|
38
|
+
extractionStatus: string;
|
|
39
|
+
semanticIndexStatus: string;
|
|
40
|
+
lastError: unknown;
|
|
41
|
+
displayName: string | null;
|
|
42
|
+
mimeType: string | null;
|
|
43
|
+
/**
|
|
44
|
+
* Phase 7a wire widening (rev-2 §2): grouped rows carry the
|
|
45
|
+
* document's `storage_provider` + INTERNAL `raw_storage_metadata`
|
|
46
|
+
* blob. The route formatter projects them through
|
|
47
|
+
* `formatPublicRawStorageMetadata` + `getDeleteSemantics` before
|
|
48
|
+
* emitting to the wire — internal `upload_result`, AES-GCM
|
|
49
|
+
* `nonce`/`tag`/`key_id`, etc. are stripped at the formatter
|
|
50
|
+
* boundary.
|
|
51
|
+
*/
|
|
52
|
+
storageProvider: string | null;
|
|
53
|
+
rawStorageMetadata: Record<string, unknown>;
|
|
54
|
+
}
|
|
55
|
+
export interface PassportFeedStandaloneMemoryRow {
|
|
56
|
+
kind: 'standalone_memory';
|
|
57
|
+
sortAt: Date;
|
|
58
|
+
sortId: string;
|
|
59
|
+
memory: {
|
|
60
|
+
id: string;
|
|
61
|
+
content: string;
|
|
62
|
+
createdAt: Date;
|
|
63
|
+
sourceSite: string | null;
|
|
64
|
+
};
|
|
65
|
+
}
|
|
66
|
+
export type PassportFeedRow = PassportFeedDocumentGroupedRow | PassportFeedStandaloneMemoryRow;
|
|
67
|
+
export interface ListPassportFeedInput {
|
|
68
|
+
userId: string;
|
|
69
|
+
limit: number;
|
|
70
|
+
cursor: DocumentListCursor | null;
|
|
71
|
+
}
|
|
72
|
+
export interface ListPassportFeedResult {
|
|
73
|
+
rows: PassportFeedRow[];
|
|
74
|
+
nextCursor: string | null;
|
|
75
|
+
}
|
|
76
|
+
/**
|
|
77
|
+
* Phase D — main passport-feed query. Single SQL statement; one
|
|
78
|
+
* UNION ALL across:
|
|
79
|
+
* (A) one row per documentId with at least one non-deleted memory.
|
|
80
|
+
* Grouped via `GROUP BY raw_document_id`; the latest chunk in
|
|
81
|
+
* each group is the representative (`(created_at DESC, id DESC)`
|
|
82
|
+
* picks it via `ARRAY_AGG(...)`)[1]). Joined to
|
|
83
|
+
* `raw_documents` for the Phase B status envelope; the join
|
|
84
|
+
* also enforces `deleted_at IS NULL` + `user_id` match so
|
|
85
|
+
* cross-user / soft-deleted documents fall out.
|
|
86
|
+
* (B) one row per non-deleted memory whose `raw_document_id IS NULL`.
|
|
87
|
+
* Sort by `(sort_at DESC, sort_id DESC)` over the unioned rows; the
|
|
88
|
+
* route then slices the `+1` over-fetch and encodes the last consumed
|
|
89
|
+
* row's tuple as `next_cursor`.
|
|
90
|
+
*/
|
|
91
|
+
export declare function listPassportFeed(pool: pg.Pool, input: ListPassportFeedInput): Promise<ListPassportFeedResult>;
|
|
@@ -0,0 +1,198 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Phase D — passport feed grouped data-layer query.
|
|
3
|
+
*
|
|
4
|
+
* Returns one row per documentId-with-memories (via `GROUP BY
|
|
5
|
+
* raw_document_id`) plus 1:1 standalone-memory rows (memories whose
|
|
6
|
+
* `raw_document_id IS NULL`), ordered by a unified
|
|
7
|
+
* `(sort_at DESC, sort_id DESC)` cursor.
|
|
8
|
+
*
|
|
9
|
+
* The webapp's `/api/context/passport` route consumes this as the
|
|
10
|
+
* memory-feed stream of its server-side two-stream merge — no
|
|
11
|
+
* webapp-side dedupe, no possibility of a single document spanning
|
|
12
|
+
* pages, no chunk-budget heuristic. A document with N memories
|
|
13
|
+
* appears EXACTLY once on the page that contains its latest
|
|
14
|
+
* chunk.
|
|
15
|
+
*
|
|
16
|
+
* Internal columns (embeddings, audit fields, internal metadata) are
|
|
17
|
+
* NEVER returned by this repository — the SELECT enumerates only the
|
|
18
|
+
* public projection that the route formatter then ships on the wire.
|
|
19
|
+
*
|
|
20
|
+
* Standard `+1 over-fetch` pagination: the route slices the extra
|
|
21
|
+
* row off and encodes its `(sort_at, sort_id)` as `next_cursor`.
|
|
22
|
+
*/
|
|
23
|
+
import { encodeListCursor, } from './document-list-cursor.js';
|
|
24
|
+
const PASSPORT_FEED_DEFAULT_LIMIT = 50;
|
|
25
|
+
const PASSPORT_FEED_MAX_LIMIT = 100;
|
|
26
|
+
/**
|
|
27
|
+
* Phase D — main passport-feed query. Single SQL statement; one
|
|
28
|
+
* UNION ALL across:
|
|
29
|
+
* (A) one row per documentId with at least one non-deleted memory.
|
|
30
|
+
* Grouped via `GROUP BY raw_document_id`; the latest chunk in
|
|
31
|
+
* each group is the representative (`(created_at DESC, id DESC)`
|
|
32
|
+
* picks it via `ARRAY_AGG(...)`)[1]). Joined to
|
|
33
|
+
* `raw_documents` for the Phase B status envelope; the join
|
|
34
|
+
* also enforces `deleted_at IS NULL` + `user_id` match so
|
|
35
|
+
* cross-user / soft-deleted documents fall out.
|
|
36
|
+
* (B) one row per non-deleted memory whose `raw_document_id IS NULL`.
|
|
37
|
+
* Sort by `(sort_at DESC, sort_id DESC)` over the unioned rows; the
|
|
38
|
+
* route then slices the `+1` over-fetch and encodes the last consumed
|
|
39
|
+
* row's tuple as `next_cursor`.
|
|
40
|
+
*/
|
|
41
|
+
export async function listPassportFeed(pool, input) {
|
|
42
|
+
const limit = clampLimit(input.limit);
|
|
43
|
+
const overFetch = limit + 1;
|
|
44
|
+
const params = [input.userId, overFetch];
|
|
45
|
+
const cursorClauseGrouped = buildCursorClause(input.cursor, params, 'grouped');
|
|
46
|
+
const cursorClauseStandalone = buildCursorClause(input.cursor, params, 'standalone');
|
|
47
|
+
const sql = `
|
|
48
|
+
WITH memory_groups AS (
|
|
49
|
+
SELECT m.raw_document_id AS document_id,
|
|
50
|
+
MAX(m.created_at) AS sort_at,
|
|
51
|
+
(ARRAY_AGG(m.id ORDER BY m.created_at DESC, m.id DESC))[1] AS sort_id,
|
|
52
|
+
(ARRAY_AGG(m.id ORDER BY m.created_at DESC, m.id DESC))[1] AS rep_id,
|
|
53
|
+
(ARRAY_AGG(m.content ORDER BY m.created_at DESC, m.id DESC))[1] AS rep_content,
|
|
54
|
+
(ARRAY_AGG(m.created_at ORDER BY m.created_at DESC, m.id DESC))[1] AS rep_created_at,
|
|
55
|
+
(ARRAY_AGG(m.source_site ORDER BY m.created_at DESC, m.id DESC))[1] AS rep_source_site,
|
|
56
|
+
COUNT(*)::INT AS chunk_count
|
|
57
|
+
FROM memories m
|
|
58
|
+
WHERE m.user_id = $1
|
|
59
|
+
AND m.deleted_at IS NULL
|
|
60
|
+
AND m.raw_document_id IS NOT NULL
|
|
61
|
+
GROUP BY m.raw_document_id
|
|
62
|
+
)
|
|
63
|
+
SELECT 'document_grouped'::text AS kind,
|
|
64
|
+
mg.document_id::text AS document_id,
|
|
65
|
+
mg.sort_at, mg.sort_id::text AS sort_id,
|
|
66
|
+
mg.rep_id::text AS rep_id,
|
|
67
|
+
mg.rep_content, mg.rep_created_at, mg.rep_source_site,
|
|
68
|
+
mg.chunk_count,
|
|
69
|
+
rd.raw_storage_status, rd.extraction_status, rd.semantic_index_status,
|
|
70
|
+
rd.last_error, rd.display_name, rd.mime_type,
|
|
71
|
+
rd.storage_provider, rd.raw_storage_metadata
|
|
72
|
+
FROM memory_groups mg
|
|
73
|
+
JOIN raw_documents rd
|
|
74
|
+
ON rd.id = mg.document_id
|
|
75
|
+
AND rd.user_id = $1
|
|
76
|
+
AND rd.deleted_at IS NULL
|
|
77
|
+
WHERE ${cursorClauseGrouped}
|
|
78
|
+
UNION ALL
|
|
79
|
+
SELECT 'standalone_memory'::text AS kind,
|
|
80
|
+
NULL AS document_id,
|
|
81
|
+
m.created_at AS sort_at,
|
|
82
|
+
m.id::text AS sort_id,
|
|
83
|
+
m.id::text AS rep_id,
|
|
84
|
+
m.content AS rep_content,
|
|
85
|
+
m.created_at AS rep_created_at,
|
|
86
|
+
m.source_site AS rep_source_site,
|
|
87
|
+
1 AS chunk_count,
|
|
88
|
+
NULL::text AS raw_storage_status,
|
|
89
|
+
NULL::text AS extraction_status,
|
|
90
|
+
NULL::text AS semantic_index_status,
|
|
91
|
+
NULL::jsonb AS last_error,
|
|
92
|
+
NULL::text AS display_name,
|
|
93
|
+
NULL::text AS mime_type,
|
|
94
|
+
NULL::text AS storage_provider,
|
|
95
|
+
NULL::jsonb AS raw_storage_metadata
|
|
96
|
+
FROM memories m
|
|
97
|
+
WHERE m.user_id = $1
|
|
98
|
+
AND m.deleted_at IS NULL
|
|
99
|
+
AND m.raw_document_id IS NULL
|
|
100
|
+
AND ${cursorClauseStandalone}
|
|
101
|
+
ORDER BY sort_at DESC, sort_id DESC
|
|
102
|
+
LIMIT $2
|
|
103
|
+
`;
|
|
104
|
+
const result = await pool.query(sql, params);
|
|
105
|
+
const all = result.rows.map(toPassportFeedRow);
|
|
106
|
+
return slicePageWithCursor(all, limit);
|
|
107
|
+
}
|
|
108
|
+
function clampLimit(raw) {
|
|
109
|
+
if (raw === undefined || !Number.isFinite(raw))
|
|
110
|
+
return PASSPORT_FEED_DEFAULT_LIMIT;
|
|
111
|
+
return Math.max(1, Math.min(PASSPORT_FEED_MAX_LIMIT, Math.floor(raw)));
|
|
112
|
+
}
|
|
113
|
+
/**
|
|
114
|
+
* Build the cursor predicate fragment for one branch of the UNION.
|
|
115
|
+
* Returns a SQL boolean expression that evaluates to TRUE when the
|
|
116
|
+
* caller did not supply a cursor (first page) or when the row's
|
|
117
|
+
* `(sort_at, sort_id)` is strictly less than the supplied cursor.
|
|
118
|
+
*
|
|
119
|
+
* Each branch references different columns (`mg.sort_at` for the
|
|
120
|
+
* grouped CTE; `m.created_at` for standalone memories), so we
|
|
121
|
+
* assemble the fragment per-branch and append fresh parameter
|
|
122
|
+
* placeholders to `params` for each branch's bind sites.
|
|
123
|
+
*/
|
|
124
|
+
function buildCursorClause(cursor, params, branch) {
|
|
125
|
+
if (cursor === null)
|
|
126
|
+
return 'TRUE';
|
|
127
|
+
params.push(cursor.sortAt, cursor.sortId);
|
|
128
|
+
const atIdx = params.length - 1;
|
|
129
|
+
const idIdx = params.length;
|
|
130
|
+
if (branch === 'grouped') {
|
|
131
|
+
return `(mg.sort_at, mg.sort_id::text) < ($${atIdx}::timestamptz, $${idIdx}::text)`;
|
|
132
|
+
}
|
|
133
|
+
return `(m.created_at, m.id::text) < ($${atIdx}::timestamptz, $${idIdx}::text)`;
|
|
134
|
+
}
|
|
135
|
+
/** Map one Postgres row to the kind-discriminated public shape. */
|
|
136
|
+
function toPassportFeedRow(row) {
|
|
137
|
+
const kind = row.kind;
|
|
138
|
+
if (kind === 'document_grouped') {
|
|
139
|
+
return toDocumentGroupedRow(row);
|
|
140
|
+
}
|
|
141
|
+
return toStandaloneMemoryRow(row);
|
|
142
|
+
}
|
|
143
|
+
function toDocumentGroupedRow(row) {
|
|
144
|
+
return {
|
|
145
|
+
kind: 'document_grouped',
|
|
146
|
+
documentId: row.document_id,
|
|
147
|
+
sortAt: row.sort_at,
|
|
148
|
+
sortId: row.sort_id,
|
|
149
|
+
representative: {
|
|
150
|
+
id: row.rep_id,
|
|
151
|
+
content: row.rep_content,
|
|
152
|
+
createdAt: row.rep_created_at,
|
|
153
|
+
sourceSite: row.rep_source_site ?? null,
|
|
154
|
+
},
|
|
155
|
+
chunkCount: Number(row.chunk_count),
|
|
156
|
+
rawStorageStatus: row.raw_storage_status,
|
|
157
|
+
extractionStatus: row.extraction_status,
|
|
158
|
+
semanticIndexStatus: row.semantic_index_status,
|
|
159
|
+
lastError: row.last_error,
|
|
160
|
+
displayName: row.display_name ?? null,
|
|
161
|
+
mimeType: row.mime_type ?? null,
|
|
162
|
+
storageProvider: row.storage_provider ?? null,
|
|
163
|
+
rawStorageMetadata: row.raw_storage_metadata ?? {},
|
|
164
|
+
};
|
|
165
|
+
}
|
|
166
|
+
function toStandaloneMemoryRow(row) {
|
|
167
|
+
return {
|
|
168
|
+
kind: 'standalone_memory',
|
|
169
|
+
sortAt: row.sort_at,
|
|
170
|
+
sortId: row.sort_id,
|
|
171
|
+
memory: {
|
|
172
|
+
id: row.rep_id,
|
|
173
|
+
content: row.rep_content,
|
|
174
|
+
createdAt: row.rep_created_at,
|
|
175
|
+
sourceSite: row.rep_source_site ?? null,
|
|
176
|
+
},
|
|
177
|
+
};
|
|
178
|
+
}
|
|
179
|
+
/**
|
|
180
|
+
* Cursor-aware page slicer. The repository over-fetches by one row;
|
|
181
|
+
* if we got the full `limit + 1`, the last consumed row's
|
|
182
|
+
* `(sort_at, sort_id)` becomes the next cursor. Otherwise the page
|
|
183
|
+
* exhausts the stream and `nextCursor === null`.
|
|
184
|
+
*/
|
|
185
|
+
function slicePageWithCursor(candidates, limit) {
|
|
186
|
+
if (candidates.length <= limit) {
|
|
187
|
+
return { rows: candidates, nextCursor: null };
|
|
188
|
+
}
|
|
189
|
+
const rows = candidates.slice(0, limit);
|
|
190
|
+
const last = rows[rows.length - 1];
|
|
191
|
+
const sortAt = last.sortAt instanceof Date
|
|
192
|
+
? last.sortAt.toISOString()
|
|
193
|
+
: String(last.sortAt);
|
|
194
|
+
return {
|
|
195
|
+
rows,
|
|
196
|
+
nextCursor: encodeListCursor({ sortAt, sortId: last.sortId }),
|
|
197
|
+
};
|
|
198
|
+
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Postgres-backed EpisodeStore implementation.
|
|
3
|
+
*/
|
|
4
|
+
import type pg from 'pg';
|
|
5
|
+
import type { EpisodeStore } from './stores.js';
|
|
6
|
+
export declare class PgEpisodeStore implements EpisodeStore {
|
|
7
|
+
private pool;
|
|
8
|
+
constructor(pool: pg.Pool);
|
|
9
|
+
storeEpisode(input: {
|
|
10
|
+
userId: string;
|
|
11
|
+
content: string;
|
|
12
|
+
sourceSite: string;
|
|
13
|
+
sourceUrl?: string;
|
|
14
|
+
sessionId?: string;
|
|
15
|
+
workspaceId?: string;
|
|
16
|
+
agentId?: string;
|
|
17
|
+
}): Promise<string>;
|
|
18
|
+
getEpisode(id: string): Promise<import("./repository-types.js").EpisodeRow | null>;
|
|
19
|
+
}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Postgres-backed EpisodeStore implementation.
|
|
3
|
+
*/
|
|
4
|
+
import { getEpisode } from './repository-read.js';
|
|
5
|
+
import { storeEpisode } from './repository-write.js';
|
|
6
|
+
export class PgEpisodeStore {
|
|
7
|
+
pool;
|
|
8
|
+
constructor(pool) {
|
|
9
|
+
this.pool = pool;
|
|
10
|
+
}
|
|
11
|
+
async storeEpisode(input) {
|
|
12
|
+
return storeEpisode(this.pool, input);
|
|
13
|
+
}
|
|
14
|
+
async getEpisode(id) {
|
|
15
|
+
return getEpisode(this.pool, id);
|
|
16
|
+
}
|
|
17
|
+
}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Postgres-backed SemanticLinkStore implementation.
|
|
3
|
+
*/
|
|
4
|
+
import type pg from 'pg';
|
|
5
|
+
import type { SemanticLinkStore } from './stores.js';
|
|
6
|
+
import { type MemoryLink } from './repository-links.js';
|
|
7
|
+
export declare class PgSemanticLinkStore implements SemanticLinkStore {
|
|
8
|
+
private pool;
|
|
9
|
+
constructor(pool: pg.Pool);
|
|
10
|
+
createLinks(links: MemoryLink[]): Promise<number>;
|
|
11
|
+
findLinkCandidates(userId: string, embedding: number[], threshold: number, excludeId: string, limit?: number): Promise<{
|
|
12
|
+
id: string;
|
|
13
|
+
similarity: number;
|
|
14
|
+
}[]>;
|
|
15
|
+
findLinkedMemoryIds(memoryIds: string[], excludeIds: Set<string>, limit: number): Promise<string[]>;
|
|
16
|
+
countLinks(): Promise<number>;
|
|
17
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Postgres-backed SemanticLinkStore implementation.
|
|
3
|
+
*/
|
|
4
|
+
import { createLinks, findLinkCandidates, findLinkedMemoryIds, countLinks, } from './repository-links.js';
|
|
5
|
+
export class PgSemanticLinkStore {
|
|
6
|
+
pool;
|
|
7
|
+
constructor(pool) {
|
|
8
|
+
this.pool = pool;
|
|
9
|
+
}
|
|
10
|
+
async createLinks(links) { return createLinks(this.pool, links); }
|
|
11
|
+
async findLinkCandidates(userId, embedding, threshold, excludeId, limit = 10) { return findLinkCandidates(this.pool, userId, embedding, threshold, excludeId, limit); }
|
|
12
|
+
async findLinkedMemoryIds(memoryIds, excludeIds, limit) { return findLinkedMemoryIds(this.pool, memoryIds, excludeIds, limit); }
|
|
13
|
+
async countLinks() { return countLinks(this.pool); }
|
|
14
|
+
}
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Postgres-backed MemoryStore implementation.
|
|
3
|
+
* Delegates to existing repository-read.ts and repository-write.ts functions.
|
|
4
|
+
*/
|
|
5
|
+
import type pg from 'pg';
|
|
6
|
+
import type { MemoryStore, StoreMemoryInput } from './stores.js';
|
|
7
|
+
import type { CanonicalMemoryObjectLineage } from './repository-types.js';
|
|
8
|
+
export declare class PgMemoryStore implements MemoryStore {
|
|
9
|
+
private pool;
|
|
10
|
+
/**
|
|
11
|
+
* Optional Phase-3 raw-content adapter, threaded through `deleteAll`
|
|
12
|
+
* so the wipe path also cleans up managed-blob bytes. `null` for
|
|
13
|
+
* pointer-only deployments and most tests; no fallback.
|
|
14
|
+
*/
|
|
15
|
+
private readonly rawContentStore;
|
|
16
|
+
/**
|
|
17
|
+
* Phase 4a per-row dispatch registry. See `MemoryRepository` for the
|
|
18
|
+
* thread-through rationale; same fallback behavior — absent registry
|
|
19
|
+
* resolves to `singleStoreRegistry(rawContentStore)` inside
|
|
20
|
+
* `repository-write.deleteAll`.
|
|
21
|
+
*/
|
|
22
|
+
private readonly storeRegistry;
|
|
23
|
+
constructor(pool: pg.Pool, options?: {
|
|
24
|
+
rawContentStore?: import('../storage/raw-content-store.js').RawContentStore | null;
|
|
25
|
+
storeRegistry?: import('../storage/store-registry.js').RawContentStoreRegistry;
|
|
26
|
+
});
|
|
27
|
+
storeMemory(input: StoreMemoryInput): Promise<string>;
|
|
28
|
+
getMemory(id: string, userId?: string): Promise<import("./repository-types.js").MemoryRow | null>;
|
|
29
|
+
getMemoryIncludingDeleted(id: string, userId?: string): Promise<import("./repository-types.js").MemoryRow | null>;
|
|
30
|
+
listMemories(userId: string, limit?: number, offset?: number, sourceSite?: string, episodeId?: string): Promise<import("./repository-types.js").MemoryRow[]>;
|
|
31
|
+
softDeleteMemory(userId: string, id: string): Promise<void>;
|
|
32
|
+
updateMemoryContent(userId: string, id: string, content: string, embedding: number[], importance: number, keywords?: string, trustScore?: number): Promise<void>;
|
|
33
|
+
updateMemoryMetadata(userId: string, id: string, metadata: Record<string, unknown>): Promise<void>;
|
|
34
|
+
expireMemory(userId: string, id: string): Promise<void>;
|
|
35
|
+
touchMemory(id: string): Promise<void>;
|
|
36
|
+
countMemories(userId?: string): Promise<number>;
|
|
37
|
+
getMemoryStats(userId: string): Promise<{
|
|
38
|
+
count: number;
|
|
39
|
+
avgImportance: number;
|
|
40
|
+
sourceDistribution: Record<string, number>;
|
|
41
|
+
}>;
|
|
42
|
+
deleteBySource(userId: string, sourceSite: string): Promise<import("./repository-document-delete.js").DeleteBySourceResult>;
|
|
43
|
+
deleteAll(userId?: string): Promise<void>;
|
|
44
|
+
backdateMemories(ids: string[], timestamp: Date): Promise<void>;
|
|
45
|
+
updateOpinionConfidence(userId: string, memoryId: string, newConfidence: number): Promise<void>;
|
|
46
|
+
countNeedsClarification(userId: string): Promise<number>;
|
|
47
|
+
storeCanonicalMemoryObject(input: {
|
|
48
|
+
userId: string;
|
|
49
|
+
objectFamily: 'ingested_fact';
|
|
50
|
+
payloadFormat?: string;
|
|
51
|
+
canonicalPayload: {
|
|
52
|
+
factText: string;
|
|
53
|
+
factType: string;
|
|
54
|
+
headline: string;
|
|
55
|
+
keywords: string[];
|
|
56
|
+
};
|
|
57
|
+
provenance: {
|
|
58
|
+
episodeId: string | null;
|
|
59
|
+
sourceSite: string;
|
|
60
|
+
sourceUrl: string;
|
|
61
|
+
};
|
|
62
|
+
observedAt?: Date;
|
|
63
|
+
lineage: CanonicalMemoryObjectLineage;
|
|
64
|
+
}): Promise<string>;
|
|
65
|
+
getMemoryInWorkspace(id: string, workspaceId: string, callerAgentId?: string): Promise<import("./repository-types.js").MemoryRow | null>;
|
|
66
|
+
listMemoriesInWorkspace(workspaceId: string, limit?: number, offset?: number, callerAgentId?: string): Promise<import("./repository-types.js").MemoryRow[]>;
|
|
67
|
+
softDeleteMemoryInWorkspace(id: string, workspaceId: string): Promise<void>;
|
|
68
|
+
}
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Postgres-backed MemoryStore implementation.
|
|
3
|
+
* Delegates to existing repository-read.ts and repository-write.ts functions.
|
|
4
|
+
*/
|
|
5
|
+
import { getMemory, getMemoryInWorkspace, getMemoryStats, listMemories, listMemoriesInWorkspace, countMemories, countNeedsClarification, } from './repository-read.js';
|
|
6
|
+
import { backdateMemories, deleteAll, expireMemory, softDeleteMemory, softDeleteMemoryInWorkspace, storeCanonicalMemoryObject, storeMemory, touchMemory, updateMemoryContent, updateMemoryMetadata, updateOpinionConfidence, } from './repository-write.js';
|
|
7
|
+
import { deleteBySource } from './repository-document-delete.js';
|
|
8
|
+
export class PgMemoryStore {
|
|
9
|
+
pool;
|
|
10
|
+
/**
|
|
11
|
+
* Optional Phase-3 raw-content adapter, threaded through `deleteAll`
|
|
12
|
+
* so the wipe path also cleans up managed-blob bytes. `null` for
|
|
13
|
+
* pointer-only deployments and most tests; no fallback.
|
|
14
|
+
*/
|
|
15
|
+
rawContentStore;
|
|
16
|
+
/**
|
|
17
|
+
* Phase 4a per-row dispatch registry. See `MemoryRepository` for the
|
|
18
|
+
* thread-through rationale; same fallback behavior — absent registry
|
|
19
|
+
* resolves to `singleStoreRegistry(rawContentStore)` inside
|
|
20
|
+
* `repository-write.deleteAll`.
|
|
21
|
+
*/
|
|
22
|
+
storeRegistry;
|
|
23
|
+
constructor(pool, options = {}) {
|
|
24
|
+
this.pool = pool;
|
|
25
|
+
this.rawContentStore = options.rawContentStore ?? null;
|
|
26
|
+
this.storeRegistry = options.storeRegistry;
|
|
27
|
+
}
|
|
28
|
+
async storeMemory(input) { return storeMemory(this.pool, input); }
|
|
29
|
+
async getMemory(id, userId) { return getMemory(this.pool, id, userId, false); }
|
|
30
|
+
async getMemoryIncludingDeleted(id, userId) { return getMemory(this.pool, id, userId, true); }
|
|
31
|
+
async listMemories(userId, limit = 20, offset = 0, sourceSite, episodeId) { return listMemories(this.pool, userId, limit, offset, sourceSite, episodeId); }
|
|
32
|
+
async softDeleteMemory(userId, id) { return softDeleteMemory(this.pool, userId, id); }
|
|
33
|
+
async updateMemoryContent(userId, id, content, embedding, importance, keywords, trustScore) { return updateMemoryContent(this.pool, userId, id, content, embedding, importance, keywords, trustScore); }
|
|
34
|
+
async updateMemoryMetadata(userId, id, metadata) { return updateMemoryMetadata(this.pool, userId, id, metadata); }
|
|
35
|
+
async expireMemory(userId, id) { return expireMemory(this.pool, userId, id); }
|
|
36
|
+
async touchMemory(id) { return touchMemory(this.pool, id); }
|
|
37
|
+
async countMemories(userId) { return countMemories(this.pool, userId); }
|
|
38
|
+
async getMemoryStats(userId) { return getMemoryStats(this.pool, userId); }
|
|
39
|
+
async deleteBySource(userId, sourceSite) { return deleteBySource(this.pool, userId, sourceSite); }
|
|
40
|
+
async deleteAll(userId) {
|
|
41
|
+
return deleteAll(this.pool, userId, {
|
|
42
|
+
rawContentStore: this.rawContentStore,
|
|
43
|
+
storeRegistry: this.storeRegistry,
|
|
44
|
+
});
|
|
45
|
+
}
|
|
46
|
+
async backdateMemories(ids, timestamp) { return backdateMemories(this.pool, ids, timestamp); }
|
|
47
|
+
async updateOpinionConfidence(userId, memoryId, newConfidence) { return updateOpinionConfidence(this.pool, userId, memoryId, newConfidence); }
|
|
48
|
+
async countNeedsClarification(userId) { return countNeedsClarification(this.pool, userId); }
|
|
49
|
+
async storeCanonicalMemoryObject(input) { return storeCanonicalMemoryObject(this.pool, input); }
|
|
50
|
+
async getMemoryInWorkspace(id, workspaceId, callerAgentId) { return getMemoryInWorkspace(this.pool, id, workspaceId, callerAgentId); }
|
|
51
|
+
async listMemoriesInWorkspace(workspaceId, limit = 20, offset = 0, callerAgentId) { return listMemoriesInWorkspace(this.pool, workspaceId, limit, offset, callerAgentId); }
|
|
52
|
+
async softDeleteMemoryInWorkspace(id, workspaceId) { return softDeleteMemoryInWorkspace(this.pool, id, workspaceId); }
|
|
53
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Postgres-backed RecapStore (Sprint 3 v1). Delegates to repository-recaps.
|
|
3
|
+
*/
|
|
4
|
+
import type pg from 'pg';
|
|
5
|
+
import type { RecapStore } from './stores.js';
|
|
6
|
+
import { type StoreRecapInput } from './repository-recaps.js';
|
|
7
|
+
export declare class PgRecapStore implements RecapStore {
|
|
8
|
+
private pool;
|
|
9
|
+
constructor(pool: pg.Pool);
|
|
10
|
+
findUnconsolidatedClusters(userId: string, minSize: number, pivot?: 'topic' | 'session'): Promise<import("./repository-recaps.js").UnconsolidatedCluster[]>;
|
|
11
|
+
storeRecap(input: StoreRecapInput): Promise<string>;
|
|
12
|
+
findRecapCandidates(userId: string, queryEmbedding: number[], limit: number): Promise<import("./repository-recaps.js").RecapRow[]>;
|
|
13
|
+
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Postgres-backed RecapStore (Sprint 3 v1). Delegates to repository-recaps.
|
|
3
|
+
*/
|
|
4
|
+
import { findRecapCandidates, findUnconsolidatedClusters, storeRecap, } from './repository-recaps.js';
|
|
5
|
+
export class PgRecapStore {
|
|
6
|
+
pool;
|
|
7
|
+
constructor(pool) {
|
|
8
|
+
this.pool = pool;
|
|
9
|
+
}
|
|
10
|
+
async findUnconsolidatedClusters(userId, minSize, pivot = 'topic') {
|
|
11
|
+
return findUnconsolidatedClusters(this.pool, userId, minSize, pivot);
|
|
12
|
+
}
|
|
13
|
+
async storeRecap(input) {
|
|
14
|
+
return storeRecap(this.pool, input);
|
|
15
|
+
}
|
|
16
|
+
async findRecapCandidates(userId, queryEmbedding, limit) {
|
|
17
|
+
return findRecapCandidates(this.pool, userId, queryEmbedding, limit);
|
|
18
|
+
}
|
|
19
|
+
}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Postgres-backed RepresentationStore implementation.
|
|
3
|
+
* Manages atomic facts and foresight projections.
|
|
4
|
+
*/
|
|
5
|
+
import type pg from 'pg';
|
|
6
|
+
import type { RepresentationStore } from './stores.js';
|
|
7
|
+
import { type StoreAtomicFactInput, type StoreForesightInput } from './repository-representations.js';
|
|
8
|
+
export declare class PgRepresentationStore implements RepresentationStore {
|
|
9
|
+
private pool;
|
|
10
|
+
constructor(pool: pg.Pool);
|
|
11
|
+
storeAtomicFacts(facts: StoreAtomicFactInput[]): Promise<string[]>;
|
|
12
|
+
storeForesight(entries: StoreForesightInput[]): Promise<string[]>;
|
|
13
|
+
listAtomicFactsForMemory(userId: string, parentMemoryId: string): Promise<import("./repository-types.js").AtomicFactRow[]>;
|
|
14
|
+
listForesightForMemory(userId: string, parentMemoryId: string): Promise<import("./repository-types.js").ForesightRow[]>;
|
|
15
|
+
replaceAtomicFactsForMemory(userId: string, parentMemoryId: string, facts: StoreAtomicFactInput[]): Promise<string[]>;
|
|
16
|
+
replaceForesightForMemory(userId: string, parentMemoryId: string, entries: StoreForesightInput[]): Promise<string[]>;
|
|
17
|
+
}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Postgres-backed RepresentationStore implementation.
|
|
3
|
+
* Manages atomic facts and foresight projections.
|
|
4
|
+
*/
|
|
5
|
+
import { listAtomicFactsForMemory, listForesightForMemory, replaceAtomicFactsForMemory, replaceForesightForMemory, storeAtomicFacts, storeForesight, } from './repository-representations.js';
|
|
6
|
+
export class PgRepresentationStore {
|
|
7
|
+
pool;
|
|
8
|
+
constructor(pool) {
|
|
9
|
+
this.pool = pool;
|
|
10
|
+
}
|
|
11
|
+
async storeAtomicFacts(facts) { return storeAtomicFacts(this.pool, facts); }
|
|
12
|
+
async storeForesight(entries) { return storeForesight(this.pool, entries); }
|
|
13
|
+
async listAtomicFactsForMemory(userId, parentMemoryId) { return listAtomicFactsForMemory(this.pool, userId, parentMemoryId); }
|
|
14
|
+
async listForesightForMemory(userId, parentMemoryId) { return listForesightForMemory(this.pool, userId, parentMemoryId); }
|
|
15
|
+
async replaceAtomicFactsForMemory(userId, parentMemoryId, facts) { return replaceAtomicFactsForMemory(this.pool, userId, parentMemoryId, facts); }
|
|
16
|
+
async replaceForesightForMemory(userId, parentMemoryId, entries) { return replaceForesightForMemory(this.pool, userId, parentMemoryId, entries); }
|
|
17
|
+
}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Postgres-backed SearchStore implementation.
|
|
3
|
+
* Delegates to repository-read.ts (vector/hybrid/keyword search) and
|
|
4
|
+
* repository-links.ts (fetchMemoriesByIds).
|
|
5
|
+
*/
|
|
6
|
+
import type pg from 'pg';
|
|
7
|
+
import type { AgentScope } from './repository-types.js';
|
|
8
|
+
import type { SearchStore } from './stores.js';
|
|
9
|
+
export declare class PgSearchStore implements SearchStore {
|
|
10
|
+
private pool;
|
|
11
|
+
constructor(pool: pg.Pool);
|
|
12
|
+
searchSimilar(userId: string, queryEmbedding: number[], limit: number, sourceSite?: string, referenceTime?: Date): Promise<import("./repository-types.js").SearchResult[]>;
|
|
13
|
+
searchHybrid(userId: string, queryText: string, queryEmbedding: number[], limit: number, sourceSite?: string, referenceTime?: Date): Promise<import("./repository-types.js").SearchResult[]>;
|
|
14
|
+
searchKeyword(userId: string, queryText: string, limit: number, sourceSite?: string): Promise<import("./repository-types.js").SearchResult[]>;
|
|
15
|
+
searchAtomicFactsHybrid(userId: string, queryText: string, queryEmbedding: number[], limit: number, sourceSite?: string, referenceTime?: Date): Promise<import("./repository-types.js").SearchResult[]>;
|
|
16
|
+
findNearDuplicates(userId: string, embedding: number[], threshold: number, limit?: number): Promise<import("./repository-vector-search.js").CandidateRow[]>;
|
|
17
|
+
findKeywordCandidates(userId: string, keywords: string[], limit?: number, includeExpired?: boolean): Promise<any[]>;
|
|
18
|
+
findTopicCandidates(userId: string, queryEmbedding: number[], limit: number): Promise<{
|
|
19
|
+
id: string;
|
|
20
|
+
content: string;
|
|
21
|
+
topic_abstraction: string;
|
|
22
|
+
importance: number;
|
|
23
|
+
similarity: number;
|
|
24
|
+
}[]>;
|
|
25
|
+
findTemporalNeighbors(userId: string, anchorTimestamps: Date[], queryEmbedding: number[], windowMinutes: number, excludeIds: Set<string>, limit: number, referenceTime?: Date): Promise<import("./repository-types.js").SearchResult[]>;
|
|
26
|
+
fetchMemoriesByIds(userId: string, ids: string[], queryEmbedding: number[], referenceTime?: Date, includeExpired?: boolean): Promise<import("./repository-types.js").SearchResult[]>;
|
|
27
|
+
searchSimilarInWorkspace(workspaceId: string, queryEmbedding: number[], limit: number, agentScope?: AgentScope, callerAgentId?: string, referenceTime?: Date): Promise<import("./repository-types.js").SearchResult[]>;
|
|
28
|
+
findNearDuplicatesInWorkspace(workspaceId: string, embedding: number[], threshold: number, limit?: number, agentScope?: AgentScope, callerAgentId?: string): Promise<import("./repository-vector-search.js").CandidateRow[]>;
|
|
29
|
+
}
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Postgres-backed SearchStore implementation.
|
|
3
|
+
* Delegates to repository-read.ts (vector/hybrid/keyword search) and
|
|
4
|
+
* repository-links.ts (fetchMemoriesByIds).
|
|
5
|
+
*/
|
|
6
|
+
import { findKeywordCandidates, findNearDuplicates, findNearDuplicatesInWorkspace, findTemporalNeighbors, findTopicCandidates, searchHybridSimilar, searchKeywordSimilar, searchSimilar, searchSimilarInWorkspace, } from './repository-read.js';
|
|
7
|
+
import { searchAtomicFactsHybrid } from './repository-representations.js';
|
|
8
|
+
import { fetchMemoriesByIds } from './repository-links.js';
|
|
9
|
+
export class PgSearchStore {
|
|
10
|
+
pool;
|
|
11
|
+
constructor(pool) {
|
|
12
|
+
this.pool = pool;
|
|
13
|
+
}
|
|
14
|
+
async searchSimilar(userId, queryEmbedding, limit, sourceSite, referenceTime) {
|
|
15
|
+
return searchSimilar(this.pool, userId, queryEmbedding, limit, sourceSite, referenceTime);
|
|
16
|
+
}
|
|
17
|
+
async searchHybrid(userId, queryText, queryEmbedding, limit, sourceSite, referenceTime) {
|
|
18
|
+
return searchHybridSimilar(this.pool, userId, queryText, queryEmbedding, limit, sourceSite, referenceTime);
|
|
19
|
+
}
|
|
20
|
+
async searchKeyword(userId, queryText, limit, sourceSite) {
|
|
21
|
+
return searchKeywordSimilar(this.pool, userId, queryText, limit, sourceSite);
|
|
22
|
+
}
|
|
23
|
+
async searchAtomicFactsHybrid(userId, queryText, queryEmbedding, limit, sourceSite, referenceTime) {
|
|
24
|
+
return searchAtomicFactsHybrid(this.pool, userId, queryText, queryEmbedding, limit, sourceSite, referenceTime);
|
|
25
|
+
}
|
|
26
|
+
async findNearDuplicates(userId, embedding, threshold, limit = 3) {
|
|
27
|
+
return findNearDuplicates(this.pool, userId, embedding, threshold, limit);
|
|
28
|
+
}
|
|
29
|
+
async findKeywordCandidates(userId, keywords, limit = 5, includeExpired = false) {
|
|
30
|
+
return findKeywordCandidates(this.pool, userId, keywords, limit, includeExpired);
|
|
31
|
+
}
|
|
32
|
+
async findTopicCandidates(userId, queryEmbedding, limit) {
|
|
33
|
+
return findTopicCandidates(this.pool, userId, queryEmbedding, limit);
|
|
34
|
+
}
|
|
35
|
+
async findTemporalNeighbors(userId, anchorTimestamps, queryEmbedding, windowMinutes, excludeIds, limit, referenceTime) {
|
|
36
|
+
return findTemporalNeighbors(this.pool, userId, anchorTimestamps, queryEmbedding, windowMinutes, excludeIds, limit, referenceTime);
|
|
37
|
+
}
|
|
38
|
+
async fetchMemoriesByIds(userId, ids, queryEmbedding, referenceTime, includeExpired = false) {
|
|
39
|
+
return fetchMemoriesByIds(this.pool, userId, ids, queryEmbedding, referenceTime, includeExpired);
|
|
40
|
+
}
|
|
41
|
+
async searchSimilarInWorkspace(workspaceId, queryEmbedding, limit, agentScope = 'all', callerAgentId, referenceTime) {
|
|
42
|
+
return searchSimilarInWorkspace(this.pool, workspaceId, queryEmbedding, limit, agentScope, callerAgentId, referenceTime);
|
|
43
|
+
}
|
|
44
|
+
async findNearDuplicatesInWorkspace(workspaceId, embedding, threshold, limit = 3, agentScope = 'all', callerAgentId) {
|
|
45
|
+
return findNearDuplicatesInWorkspace(this.pool, workspaceId, embedding, threshold, limit, agentScope, callerAgentId);
|
|
46
|
+
}
|
|
47
|
+
}
|
package/dist/db/pool.js
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Database connection pool for Postgres+pgvector.
|
|
3
|
+
* Reads DATABASE_URL from environment (loaded by dotenv-cli).
|
|
4
|
+
*/
|
|
5
|
+
import pg from 'pg';
|
|
6
|
+
const DATABASE_URL = process.env.DATABASE_URL;
|
|
7
|
+
if (!DATABASE_URL) {
|
|
8
|
+
throw new Error('DATABASE_URL environment variable is required');
|
|
9
|
+
}
|
|
10
|
+
// max=1 prevents pgvector HNSW index deadlocks: the index takes
|
|
11
|
+
// AccessExclusiveLock during INSERT and AccessShareLock during SELECT.
|
|
12
|
+
// With multiple connections these can deadlock across backend processes.
|
|
13
|
+
export const pool = new pg.Pool({
|
|
14
|
+
connectionString: DATABASE_URL,
|
|
15
|
+
max: 1,
|
|
16
|
+
connectionTimeoutMillis: 30_000,
|
|
17
|
+
idleTimeoutMillis: 60_000,
|
|
18
|
+
});
|
|
19
|
+
pool.on('error', (err) => {
|
|
20
|
+
console.error('[pool] Unexpected idle client error:', err.message);
|
|
21
|
+
});
|