@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,425 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* /v1/documents — multi-phase document pipeline router.
|
|
3
|
+
*
|
|
4
|
+
* Routes the document registry + lifecycle surface, layered up through
|
|
5
|
+
* the rev-18 hardening plan:
|
|
6
|
+
* - Phase 1: pointer-only registration, get-by-id, legacy
|
|
7
|
+
* `/list` (offset/limit + source_site), soft-delete.
|
|
8
|
+
* - Phase 2: `POST /:id/index` chunks + embeds supplied text.
|
|
9
|
+
* - Phase 3: `PUT /:id/raw` managed-blob upload (when
|
|
10
|
+
* `RAW_STORAGE_MODE=managed_blob` is configured); the post-upload
|
|
11
|
+
* row promotion sets `storage_mode='managed_blob'` and
|
|
12
|
+
* `raw_storage_status='blob_stored'`.
|
|
13
|
+
* - Phase B/C: per-layer status + `last_error` envelope + the
|
|
14
|
+
* constrained-transition routes
|
|
15
|
+
* `POST /:id/extraction-failure` and `POST /:id/index-failure`.
|
|
16
|
+
* - Phase D: cursor-paginated `GET /` (root list),
|
|
17
|
+
* `GET /without-memories` (recovery-status filter), and
|
|
18
|
+
* `GET /passport-feed` (data-layer grouped feed) on top of
|
|
19
|
+
* `GET /limits` for the runtime preflight surface.
|
|
20
|
+
*
|
|
21
|
+
* Validation + response-shape conventions match `/v1/memories`
|
|
22
|
+
* (`createMemoryRouter`, `validateBody`, `validateResponse`).
|
|
23
|
+
*
|
|
24
|
+
* `POST /v1/documents` (register) still only accepts
|
|
25
|
+
* `storage_mode='pointer_only'` on the wire — the `managed_blob` /
|
|
26
|
+
* `inline_small_text` modes are populated by `PUT /:id/raw` (and a
|
|
27
|
+
* future inline-text path) rather than declared at register time.
|
|
28
|
+
*
|
|
29
|
+
* See `Atomicmemory-research/docs/core-repo/design/large-file-ingestion-and-raw-storage-plan-2026-05-08.md`
|
|
30
|
+
* and the rev-18 hardening plan.
|
|
31
|
+
*/
|
|
32
|
+
import express, { Router } from 'express';
|
|
33
|
+
import { handleRouteError } from './route-errors.js';
|
|
34
|
+
import { validateBody, validateQuery, validateParams } from '../middleware/validate.js';
|
|
35
|
+
import { validateResponse } from '../middleware/validate-response.js';
|
|
36
|
+
import { DOCUMENT_RESPONSE_SCHEMAS } from './response-schema-map.js';
|
|
37
|
+
import { DocumentByIdQuerySchema, DocumentIdParamSchema, ExtractionFailureBodySchema, IndexDocumentBodySchema, IndexFailureBodySchema, INDEX_BODY_PARSER_LIMIT, ListDocumentsQuerySchema, RegisterDocumentBodySchema, UploadRawDocumentQuerySchema, } from '../schemas/documents.js';
|
|
38
|
+
import { DocumentListRootQuerySchema, ListDocumentsWithoutMemoriesQuerySchema, PassportFeedQuerySchema, } from '../schemas/document-list-schemas.js';
|
|
39
|
+
import { formatDeleteDocumentResponse, formatDocumentFailureMarkerResponse, formatDocumentLimitsResponse, formatDocumentListRootResponse, formatPassportFeedResponse, formatIndexDocumentResponse, formatListDocumentsResponse, formatRawDocument, formatRegisterDocumentResponse, formatUploadRawDocumentResponse, } from './document-response-formatters.js';
|
|
40
|
+
import { DocumentNotFoundError, IndexInputError, IndexInvalidStateError, IndexSemanticValidationError, } from '../services/document-indexer.js';
|
|
41
|
+
import { InvalidDocumentListCursorError } from '../services/document-service.js';
|
|
42
|
+
import { ManagedStorageDisabledError, UploadDocumentConflictError, UploadDocumentNotFoundError, } from '../services/document-upload.js';
|
|
43
|
+
import { ArtifactNotLinkableError } from '../db/storage-artifact-repository.js';
|
|
44
|
+
import { ExtractionFailureInvalidStateError, FailureMarkerDocumentNotFoundError, IndexFailureInvalidStateError, } from '../services/document-failure-markers.js';
|
|
45
|
+
/** Router-level JSON-body cap for register / delete / limits / etc. */
|
|
46
|
+
const ROUTER_JSON_BODY_LIMIT = '1mb';
|
|
47
|
+
/**
|
|
48
|
+
* Build the documents router with composition-owned limits.
|
|
49
|
+
*
|
|
50
|
+
* Body-parser ordering inside this router (deliberate — see
|
|
51
|
+
* `Atomicmemory-research/docs/core-repo/design/document-ingest-audit.md`
|
|
52
|
+
* and the rev-18 hardening plan):
|
|
53
|
+
* 1. validate-response (response-shape contract).
|
|
54
|
+
* 2. Query-only GETs first (`/limits`, `/list`) so they can never be
|
|
55
|
+
* shadowed by `/:id` and never need a body parser.
|
|
56
|
+
* 3. Per-route large parsers (`POST /:id/index` → 25 MiB JSON,
|
|
57
|
+
* `PUT /:id/raw` → raw bytes), registered BEFORE the router-level
|
|
58
|
+
* JSON middleware so the larger cap wins for that single path.
|
|
59
|
+
* 4. Router-level `express.json({ limit: '1mb' })` fallthrough for the
|
|
60
|
+
* remaining JSON-body routes.
|
|
61
|
+
* 5. Remaining JSON-body routes (`POST /`, `DELETE /:id`).
|
|
62
|
+
* 6. `GET /:id` LAST so it cannot shadow `/limits`, `/list`, etc.
|
|
63
|
+
*
|
|
64
|
+
* The router takes ownership of body parsing — `create-app.ts` mounts
|
|
65
|
+
* the documents router WITHOUT an upstream `express.json` so the
|
|
66
|
+
* larger `/index` parser is not silently overridden.
|
|
67
|
+
*/
|
|
68
|
+
export function createDocumentRouter(service, options) {
|
|
69
|
+
const router = Router();
|
|
70
|
+
router.use(validateResponse(DOCUMENT_RESPONSE_SCHEMAS));
|
|
71
|
+
// Step 2 — query-only GETs first.
|
|
72
|
+
registerLimitsRoute(router, options.limits);
|
|
73
|
+
registerListRoute(router, service);
|
|
74
|
+
registerListRootRoute(router, service);
|
|
75
|
+
registerWithoutMemoriesRoute(router, service);
|
|
76
|
+
registerPassportFeedRoute(router, service);
|
|
77
|
+
// Step 3 — per-route body parsers.
|
|
78
|
+
registerIndexRoute(router, service);
|
|
79
|
+
registerUploadRoute(router, service, options.rawUploadMaxBytes);
|
|
80
|
+
// Step 4 — router-level JSON parser for the remaining JSON-body routes.
|
|
81
|
+
router.use(express.json({ limit: ROUTER_JSON_BODY_LIMIT }));
|
|
82
|
+
// Step 5 — JSON-body routes. The Phase C failure-marker routes
|
|
83
|
+
// (`/:id/extraction-failure`, `/:id/index-failure`) live with the
|
|
84
|
+
// other 1 MiB-bounded JSON-body routes — small constrained-
|
|
85
|
+
// transition payloads, not raw text.
|
|
86
|
+
registerRegisterRoute(router, service);
|
|
87
|
+
registerExtractionFailureRoute(router, service);
|
|
88
|
+
registerIndexFailureRoute(router, service);
|
|
89
|
+
registerDeleteRoute(router, service);
|
|
90
|
+
// Step 6 — `GET /:id` registered LAST so it never shadows the
|
|
91
|
+
// query-only GETs above.
|
|
92
|
+
registerGetRoute(router, service);
|
|
93
|
+
return router;
|
|
94
|
+
}
|
|
95
|
+
function registerLimitsRoute(router, limits) {
|
|
96
|
+
// Public, non-PII preflight surface — clients call this to read
|
|
97
|
+
// byte caps and raw-storage capability before attempting an upload.
|
|
98
|
+
// Auth posture: intentionally public (mirrors `/health`); no
|
|
99
|
+
// per-user state.
|
|
100
|
+
router.get('/limits', (_req, res) => {
|
|
101
|
+
res.json(formatDocumentLimitsResponse(limits));
|
|
102
|
+
});
|
|
103
|
+
}
|
|
104
|
+
function registerRegisterRoute(router, service) {
|
|
105
|
+
router.post('/', validateBody(RegisterDocumentBodySchema), async (req, res) => {
|
|
106
|
+
try {
|
|
107
|
+
const body = req.body;
|
|
108
|
+
const result = await service.register(body);
|
|
109
|
+
// Idempotent re-register returns 200 with the existing row;
|
|
110
|
+
// a fresh insert returns 201.
|
|
111
|
+
res.status(result.created ? 201 : 200).json(formatRegisterDocumentResponse(result, service.getStoreRegistry()));
|
|
112
|
+
}
|
|
113
|
+
catch (err) {
|
|
114
|
+
handleRouteError(res, 'POST /v1/documents', err);
|
|
115
|
+
}
|
|
116
|
+
});
|
|
117
|
+
}
|
|
118
|
+
function registerListRoute(router, service) {
|
|
119
|
+
router.get('/list', validateQuery(ListDocumentsQuerySchema), async (req, res) => {
|
|
120
|
+
try {
|
|
121
|
+
const q = req.query;
|
|
122
|
+
const documents = await service.list({
|
|
123
|
+
userId: q.userId,
|
|
124
|
+
sourceSite: q.sourceSite,
|
|
125
|
+
limit: q.limit,
|
|
126
|
+
offset: q.offset,
|
|
127
|
+
});
|
|
128
|
+
res.json(formatListDocumentsResponse(documents, service.getStoreRegistry()));
|
|
129
|
+
}
|
|
130
|
+
catch (err) {
|
|
131
|
+
handleRouteError(res, 'GET /v1/documents/list', err);
|
|
132
|
+
}
|
|
133
|
+
});
|
|
134
|
+
}
|
|
135
|
+
/**
|
|
136
|
+
* Phase D — `GET /v1/documents`. Cursor-paginated, status-bucket
|
|
137
|
+
* filtered. Registered alongside `/list`, before `/:id`, so it does
|
|
138
|
+
* not conflict with the legacy offset/limit list endpoint and so
|
|
139
|
+
* `:id` cannot shadow the root list.
|
|
140
|
+
*/
|
|
141
|
+
function registerListRootRoute(router, service) {
|
|
142
|
+
router.get('/', validateQuery(DocumentListRootQuerySchema), async (req, res) => {
|
|
143
|
+
try {
|
|
144
|
+
const q = req.query;
|
|
145
|
+
const result = await service.listForUser(q);
|
|
146
|
+
res.json(formatDocumentListRootResponse(result, service.getStoreRegistry()));
|
|
147
|
+
}
|
|
148
|
+
catch (err) {
|
|
149
|
+
if (err instanceof InvalidDocumentListCursorError) {
|
|
150
|
+
res.status(400).json({ error: 'invalid_cursor', message: err.message });
|
|
151
|
+
return;
|
|
152
|
+
}
|
|
153
|
+
handleRouteError(res, 'GET /v1/documents', err);
|
|
154
|
+
}
|
|
155
|
+
});
|
|
156
|
+
}
|
|
157
|
+
/**
|
|
158
|
+
* Phase D — `GET /v1/documents/passport-feed`. Memory-backed feed:
|
|
159
|
+
* one row per documentId-with-memories (grouped + status-enveloped)
|
|
160
|
+
* plus 1:1 standalone-memory rows, ordered by
|
|
161
|
+
* `(sort_at DESC, sort_id DESC)`. The webapp's
|
|
162
|
+
* `/api/context/passport` consumes this as the memory-feed stream
|
|
163
|
+
* of its server-side two-stream merge. Registered BEFORE `/:id`.
|
|
164
|
+
*/
|
|
165
|
+
function registerPassportFeedRoute(router, service) {
|
|
166
|
+
router.get('/passport-feed', validateQuery(PassportFeedQuerySchema), async (req, res) => {
|
|
167
|
+
try {
|
|
168
|
+
const q = req.query;
|
|
169
|
+
const result = await service.listPassportFeed(q);
|
|
170
|
+
res.json(formatPassportFeedResponse(result, service.getStoreRegistry()));
|
|
171
|
+
}
|
|
172
|
+
catch (err) {
|
|
173
|
+
if (err instanceof InvalidDocumentListCursorError) {
|
|
174
|
+
res.status(400).json({ error: 'invalid_cursor', message: err.message });
|
|
175
|
+
return;
|
|
176
|
+
}
|
|
177
|
+
handleRouteError(res, 'GET /v1/documents/passport-feed', err);
|
|
178
|
+
}
|
|
179
|
+
});
|
|
180
|
+
}
|
|
181
|
+
/**
|
|
182
|
+
* Phase D — `GET /v1/documents/without-memories`. Layer-aware
|
|
183
|
+
* recovery filter; backs the passport server-side merge document-only
|
|
184
|
+
* stream and any UI surface that wants to show "uploaded but no
|
|
185
|
+
* indexed content yet" rows. Registered BEFORE `/:id` so the literal
|
|
186
|
+
* path can never be matched as a UUID.
|
|
187
|
+
*/
|
|
188
|
+
function registerWithoutMemoriesRoute(router, service) {
|
|
189
|
+
router.get('/without-memories', validateQuery(ListDocumentsWithoutMemoriesQuerySchema), async (req, res) => {
|
|
190
|
+
try {
|
|
191
|
+
const q = req.query;
|
|
192
|
+
const result = await service.listWithoutMemoriesForUser(q);
|
|
193
|
+
res.json(formatDocumentListRootResponse(result, service.getStoreRegistry()));
|
|
194
|
+
}
|
|
195
|
+
catch (err) {
|
|
196
|
+
if (err instanceof InvalidDocumentListCursorError) {
|
|
197
|
+
res.status(400).json({ error: 'invalid_cursor', message: err.message });
|
|
198
|
+
return;
|
|
199
|
+
}
|
|
200
|
+
handleRouteError(res, 'GET /v1/documents/without-memories', err);
|
|
201
|
+
}
|
|
202
|
+
});
|
|
203
|
+
}
|
|
204
|
+
function registerGetRoute(router, service) {
|
|
205
|
+
router.get('/:id', validateParams(DocumentIdParamSchema), validateQuery(DocumentByIdQuerySchema), async (req, res) => {
|
|
206
|
+
try {
|
|
207
|
+
const { id } = req.params;
|
|
208
|
+
const { userId } = req.query;
|
|
209
|
+
const document = await service.get(userId, id);
|
|
210
|
+
if (!document) {
|
|
211
|
+
res.status(404).json({ error: 'Document not found' });
|
|
212
|
+
return;
|
|
213
|
+
}
|
|
214
|
+
res.json(formatRawDocument(document, service.getStoreRegistry()));
|
|
215
|
+
}
|
|
216
|
+
catch (err) {
|
|
217
|
+
handleRouteError(res, 'GET /v1/documents/:id', err);
|
|
218
|
+
}
|
|
219
|
+
});
|
|
220
|
+
}
|
|
221
|
+
function registerIndexRoute(router, service) {
|
|
222
|
+
// Per-route JSON parser sized to `INDEX_BODY_PARSER_LIMIT`
|
|
223
|
+
// (`MAX_INDEX_TEXT_BYTES` plus a 64 KiB headroom for the JSON
|
|
224
|
+
// wrapper + escape encoding). Registered BEFORE the router-level
|
|
225
|
+
// 1 MiB JSON parser (in `createDocumentRouter`), so the larger cap
|
|
226
|
+
// wins for this one path. Express's body-parser is a no-op when
|
|
227
|
+
// `req.body` is already populated; pairing the larger parser
|
|
228
|
+
// earlier in the chain ensures it owns the body for `/:id/index`.
|
|
229
|
+
//
|
|
230
|
+
// Phase B durable-failure contract: the parser deliberately
|
|
231
|
+
// ADMITS bodies whose `text` field is over `MAX_INDEX_TEXT_BYTES`
|
|
232
|
+
// (up to the 64 KiB headroom) so the indexer's `semanticValidate`
|
|
233
|
+
// can run and mark `semantic_index_status='failed'` +
|
|
234
|
+
// `last_error.code='index_text_too_large'` BEFORE the route
|
|
235
|
+
// returns 413. The cap-sized happy-path body
|
|
236
|
+
// (`text` exactly `MAX_INDEX_TEXT_BYTES`) reaches the handler and
|
|
237
|
+
// succeeds; any text over the cap fails durably; bodies far above
|
|
238
|
+
// the headroom still get rejected by the parser as truly
|
|
239
|
+
// oversized payloads. The Zod schema does NOT pre-empt with a
|
|
240
|
+
// refine - see `IndexDocumentBodySchema` in
|
|
241
|
+
// `src/schemas/documents.ts`.
|
|
242
|
+
const indexJsonParser = express.json({ limit: INDEX_BODY_PARSER_LIMIT });
|
|
243
|
+
router.post('/:id/index', indexJsonParser, validateParams(DocumentIdParamSchema), validateBody(IndexDocumentBodySchema), async (req, res) => {
|
|
244
|
+
try {
|
|
245
|
+
const { id } = req.params;
|
|
246
|
+
const body = req.body;
|
|
247
|
+
const result = await service.indexText({
|
|
248
|
+
documentId: id,
|
|
249
|
+
userId: body.userId,
|
|
250
|
+
text: body.text,
|
|
251
|
+
});
|
|
252
|
+
res.json(formatIndexDocumentResponse(result));
|
|
253
|
+
}
|
|
254
|
+
catch (err) {
|
|
255
|
+
if (err instanceof DocumentNotFoundError) {
|
|
256
|
+
res.status(404).json({ error: 'Document not found' });
|
|
257
|
+
return;
|
|
258
|
+
}
|
|
259
|
+
if (err instanceof IndexInputError) {
|
|
260
|
+
res.status(400).json({ error: err.message });
|
|
261
|
+
return;
|
|
262
|
+
}
|
|
263
|
+
if (err instanceof IndexInvalidStateError) {
|
|
264
|
+
// Phase B — concurrent writer / `not_required` row. The
|
|
265
|
+
// catch path inside the indexer deliberately did NOT mark
|
|
266
|
+
// the row failed for this case (it would clobber another
|
|
267
|
+
// writer's state); we surface 409 with the current status
|
|
268
|
+
// so the caller can decide whether to retry.
|
|
269
|
+
res.status(409).json({
|
|
270
|
+
error: 'Invalid index state transition',
|
|
271
|
+
current: err.currentStatus,
|
|
272
|
+
documentId: err.documentId,
|
|
273
|
+
});
|
|
274
|
+
return;
|
|
275
|
+
}
|
|
276
|
+
if (err instanceof IndexSemanticValidationError) {
|
|
277
|
+
// Phase B — known-document semantic failure (text too
|
|
278
|
+
// large / empty). The indexer wrote durable
|
|
279
|
+
// `semantic_index_status='failed'` + `last_error.code`
|
|
280
|
+
// before this catch ran, so the row is recoverable via
|
|
281
|
+
// `GET /api/context/documents/:id`. Echo the documentId
|
|
282
|
+
// in the body so callers can navigate to it.
|
|
283
|
+
const status = err.code === 'index_text_too_large' ? 413 : 400;
|
|
284
|
+
res.status(status).json({
|
|
285
|
+
error: err.message,
|
|
286
|
+
code: err.code,
|
|
287
|
+
documentId: err.documentId,
|
|
288
|
+
});
|
|
289
|
+
return;
|
|
290
|
+
}
|
|
291
|
+
handleRouteError(res, 'POST /v1/documents/:id/index', err);
|
|
292
|
+
}
|
|
293
|
+
});
|
|
294
|
+
}
|
|
295
|
+
function registerUploadRoute(router, service, rawUploadMaxBytes) {
|
|
296
|
+
// Mount the raw-body parser ONLY on this route. The global JSON
|
|
297
|
+
// parser stays unaffected. `type: '*/*'` accepts any content-type
|
|
298
|
+
// (callers may send application/octet-stream, application/pdf, etc.);
|
|
299
|
+
// the limit is supplied by the composition root, so the route layer
|
|
300
|
+
// does not import the config singleton.
|
|
301
|
+
const rawParser = express.raw({ type: '*/*', limit: rawUploadMaxBytes });
|
|
302
|
+
router.put('/:id/raw', rawParser, validateParams(DocumentIdParamSchema), validateQuery(UploadRawDocumentQuerySchema), async (req, res) => {
|
|
303
|
+
try {
|
|
304
|
+
const { id } = req.params;
|
|
305
|
+
const q = req.query;
|
|
306
|
+
const body = req.body;
|
|
307
|
+
if (!Buffer.isBuffer(body) || body.length === 0) {
|
|
308
|
+
res.status(400).json({ error: 'request body is required' });
|
|
309
|
+
return;
|
|
310
|
+
}
|
|
311
|
+
const result = await service.uploadRaw({
|
|
312
|
+
documentId: id,
|
|
313
|
+
userId: q.userId,
|
|
314
|
+
body,
|
|
315
|
+
contentType: q.contentType,
|
|
316
|
+
});
|
|
317
|
+
res.json(formatUploadRawDocumentResponse(result, service.getStoreRegistry()));
|
|
318
|
+
}
|
|
319
|
+
catch (err) {
|
|
320
|
+
if (err instanceof UploadDocumentNotFoundError) {
|
|
321
|
+
res.status(404).json({ error: 'Document not found' });
|
|
322
|
+
return;
|
|
323
|
+
}
|
|
324
|
+
if (err instanceof UploadDocumentConflictError) {
|
|
325
|
+
res.status(409).json({ error: err.message });
|
|
326
|
+
return;
|
|
327
|
+
}
|
|
328
|
+
if (err instanceof ArtifactNotLinkableError) {
|
|
329
|
+
// The doc's prior artifact entered a delete lifecycle
|
|
330
|
+
// between our upload claim and the swap; the bytes have
|
|
331
|
+
// already been compensated (see `compensateOrphanedBlob`
|
|
332
|
+
// in `document-upload.ts`). Surface as 409 so the
|
|
333
|
+
// caller retries after the in-flight delete settles.
|
|
334
|
+
res.status(409).json({
|
|
335
|
+
error_code: 'artifact_not_linkable',
|
|
336
|
+
error: err.message,
|
|
337
|
+
artifact_id: err.artifactId,
|
|
338
|
+
artifact_status: err.status,
|
|
339
|
+
});
|
|
340
|
+
return;
|
|
341
|
+
}
|
|
342
|
+
if (err instanceof ManagedStorageDisabledError) {
|
|
343
|
+
res.status(503).json({ error: err.message });
|
|
344
|
+
return;
|
|
345
|
+
}
|
|
346
|
+
handleRouteError(res, 'PUT /v1/documents/:id/raw', err);
|
|
347
|
+
}
|
|
348
|
+
});
|
|
349
|
+
}
|
|
350
|
+
function registerExtractionFailureRoute(router, service) {
|
|
351
|
+
router.post('/:id/extraction-failure', validateParams(DocumentIdParamSchema), validateBody(ExtractionFailureBodySchema), async (req, res) => {
|
|
352
|
+
try {
|
|
353
|
+
const { id } = req.params;
|
|
354
|
+
const body = req.body;
|
|
355
|
+
const result = await service.markExtractionFailure({
|
|
356
|
+
userId: body.userId,
|
|
357
|
+
documentId: id,
|
|
358
|
+
errorCode: body.errorCode,
|
|
359
|
+
errorMessage: body.errorMessage,
|
|
360
|
+
});
|
|
361
|
+
res.json(formatDocumentFailureMarkerResponse(result, service.getStoreRegistry()));
|
|
362
|
+
}
|
|
363
|
+
catch (err) {
|
|
364
|
+
if (err instanceof FailureMarkerDocumentNotFoundError) {
|
|
365
|
+
res.status(404).json({ error: 'Document not found' });
|
|
366
|
+
return;
|
|
367
|
+
}
|
|
368
|
+
if (err instanceof ExtractionFailureInvalidStateError) {
|
|
369
|
+
// Phase C - 409 echoes the row's current per-layer state so
|
|
370
|
+
// the caller can decide whether to retry, reset, or
|
|
371
|
+
// surface the conflict to a human.
|
|
372
|
+
res.status(409).json({
|
|
373
|
+
error: 'Invalid extraction state transition',
|
|
374
|
+
documentId: err.documentId,
|
|
375
|
+
current: err.current,
|
|
376
|
+
});
|
|
377
|
+
return;
|
|
378
|
+
}
|
|
379
|
+
handleRouteError(res, 'POST /v1/documents/:id/extraction-failure', err);
|
|
380
|
+
}
|
|
381
|
+
});
|
|
382
|
+
}
|
|
383
|
+
function registerIndexFailureRoute(router, service) {
|
|
384
|
+
router.post('/:id/index-failure', validateParams(DocumentIdParamSchema), validateBody(IndexFailureBodySchema), async (req, res) => {
|
|
385
|
+
try {
|
|
386
|
+
const { id } = req.params;
|
|
387
|
+
const body = req.body;
|
|
388
|
+
const result = await service.markIndexFailure({
|
|
389
|
+
userId: body.userId,
|
|
390
|
+
documentId: id,
|
|
391
|
+
errorCode: body.errorCode,
|
|
392
|
+
errorMessage: body.errorMessage,
|
|
393
|
+
});
|
|
394
|
+
res.json(formatDocumentFailureMarkerResponse(result, service.getStoreRegistry()));
|
|
395
|
+
}
|
|
396
|
+
catch (err) {
|
|
397
|
+
if (err instanceof FailureMarkerDocumentNotFoundError) {
|
|
398
|
+
res.status(404).json({ error: 'Document not found' });
|
|
399
|
+
return;
|
|
400
|
+
}
|
|
401
|
+
if (err instanceof IndexFailureInvalidStateError) {
|
|
402
|
+
res.status(409).json({
|
|
403
|
+
error: 'Invalid index state transition',
|
|
404
|
+
documentId: err.documentId,
|
|
405
|
+
current: err.current,
|
|
406
|
+
});
|
|
407
|
+
return;
|
|
408
|
+
}
|
|
409
|
+
handleRouteError(res, 'POST /v1/documents/:id/index-failure', err);
|
|
410
|
+
}
|
|
411
|
+
});
|
|
412
|
+
}
|
|
413
|
+
function registerDeleteRoute(router, service) {
|
|
414
|
+
router.delete('/:id', validateParams(DocumentIdParamSchema), validateQuery(DocumentByIdQuerySchema), async (req, res) => {
|
|
415
|
+
try {
|
|
416
|
+
const { id } = req.params;
|
|
417
|
+
const { userId } = req.query;
|
|
418
|
+
const result = await service.delete(userId, id);
|
|
419
|
+
res.json(formatDeleteDocumentResponse(result));
|
|
420
|
+
}
|
|
421
|
+
catch (err) {
|
|
422
|
+
handleRouteError(res, 'DELETE /v1/documents/:id', err);
|
|
423
|
+
}
|
|
424
|
+
});
|
|
425
|
+
}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Memory API routes for ingest, search, listing, stats, config, and deletion.
|
|
3
|
+
* Keeps the existing `/v1/memories/ingest` and `/v1/memories/search` contract stable.
|
|
4
|
+
*
|
|
5
|
+
* Request validation for every route is delegated to the Zod-based
|
|
6
|
+
* validators in `src/middleware/validate.ts` using schemas authored in
|
|
7
|
+
* `src/schemas/memories.ts`. `validateBody` / `validateQuery` /
|
|
8
|
+
* `validateParams` replace the hand-written `parseIngestBody` /
|
|
9
|
+
* `parseSearchBody` / `requireBodyString` helpers this file previously
|
|
10
|
+
* exported. The 400 response envelope `{ error: string }` is
|
|
11
|
+
* preserved byte-for-byte by `formatZodIssues`.
|
|
12
|
+
*/
|
|
13
|
+
import { Router } from 'express';
|
|
14
|
+
import { type RuntimeConfig } from '../config.js';
|
|
15
|
+
import { type RuntimeConfigRouteSnapshot } from '../app/runtime-config-route-snapshot.js';
|
|
16
|
+
import { MemoryService } from '../services/memory-service.js';
|
|
17
|
+
interface RuntimeConfigRouteAdapter {
|
|
18
|
+
base(): RuntimeConfig;
|
|
19
|
+
current(): RuntimeConfigRouteSnapshot;
|
|
20
|
+
update(updates: RuntimeConfigRouteUpdates): string[];
|
|
21
|
+
}
|
|
22
|
+
interface RuntimeConfigRouteUpdates {
|
|
23
|
+
similarityThreshold?: number;
|
|
24
|
+
audnCandidateThreshold?: number;
|
|
25
|
+
clarificationConflictThreshold?: number;
|
|
26
|
+
maxSearchResults?: number;
|
|
27
|
+
}
|
|
28
|
+
export declare function createMemoryRouter(service: MemoryService, configRouteAdapter?: RuntimeConfigRouteAdapter): Router;
|
|
29
|
+
export {};
|