@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
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Public API surface of the AtomicMemory memory engine.
|
|
3
|
+
* Consumed by the standalone memory service and evaluation harness.
|
|
4
|
+
*/
|
|
5
|
+
export { MemoryService, type IngestResult, type RetrievalResult } from './services/memory-service.js';
|
|
6
|
+
export { MemoryRepository, type MemoryRow, type SearchResult, type EpisodeRow, type MemoryMetadata } from './db/memory-repository.js';
|
|
7
|
+
export { ClaimRepository } from './db/claim-repository.js';
|
|
8
|
+
export { pool } from './db/pool.js';
|
|
9
|
+
export { config, applyRuntimeConfigUpdates, updateRuntimeConfig, SUPPORTED_RUNTIME_CONFIG_FIELDS, INTERNAL_POLICY_CONFIG_FIELDS, type RuntimeConfig, type RuntimeConfigUpdates, type EmbeddingProviderName, type LLMProviderName, type VectorBackendName, type SupportedRuntimeConfigField, type InternalPolicyConfigField, type SupportedRuntimeConfig, type InternalPolicyConfig, } from './config.js';
|
|
10
|
+
export { createMemoryRouter } from './routes/memories.js';
|
|
11
|
+
export { type RetrievalCitation } from './services/retrieval-format.js';
|
|
12
|
+
export { getRetrievalProfile, parseRetrievalProfile, type RetrievalProfile, type RetrievalProfileName, } from './services/retrieval-profiles.js';
|
|
13
|
+
export { createCoreRuntime, type CoreRuntime, type CoreRuntimeDeps, type CoreRuntimeConfig, type CoreRuntimeRepos, type CoreRuntimeServices, type CoreRuntimeConfigRouteAdapter, } from './app/runtime-container.js';
|
|
14
|
+
export { createApp } from './app/create-app.js';
|
|
15
|
+
export { checkEmbeddingDimensions, type EmbeddingDimensionCheckResult, } from './app/startup-checks.js';
|
|
16
|
+
export { bindEphemeral, type BootedApp } from './app/bind-ephemeral.js';
|
|
17
|
+
export { initEmbedding, type EmbeddingConfig } from './services/embedding.js';
|
|
18
|
+
export { initLlm, type LLMConfig } from './services/llm.js';
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Public API surface of the AtomicMemory memory engine.
|
|
3
|
+
* Consumed by the standalone memory service and evaluation harness.
|
|
4
|
+
*/
|
|
5
|
+
export { MemoryService } from './services/memory-service.js';
|
|
6
|
+
export { MemoryRepository } from './db/memory-repository.js';
|
|
7
|
+
export { ClaimRepository } from './db/claim-repository.js';
|
|
8
|
+
export { pool } from './db/pool.js';
|
|
9
|
+
export { config, applyRuntimeConfigUpdates, updateRuntimeConfig, SUPPORTED_RUNTIME_CONFIG_FIELDS, INTERNAL_POLICY_CONFIG_FIELDS, } from './config.js';
|
|
10
|
+
export { createMemoryRouter } from './routes/memories.js';
|
|
11
|
+
export { getRetrievalProfile, parseRetrievalProfile, } from './services/retrieval-profiles.js';
|
|
12
|
+
export { createCoreRuntime, } from './app/runtime-container.js';
|
|
13
|
+
export { createApp } from './app/create-app.js';
|
|
14
|
+
export { checkEmbeddingDimensions, } from './app/startup-checks.js';
|
|
15
|
+
export { bindEphemeral } from './app/bind-ephemeral.js';
|
|
16
|
+
export { initEmbedding } from './services/embedding.js';
|
|
17
|
+
export { initLlm } from './services/llm.js';
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @file `requireBearer` — Express middleware that validates the
|
|
3
|
+
* `Authorization: Bearer <token>` header against a configured shared
|
|
4
|
+
* key in constant time.
|
|
5
|
+
*
|
|
6
|
+
* Mounted in front of every SDK-facing `/v1/*` router by
|
|
7
|
+
* `src/app/create-app.ts`. Public probes (`/health`, `/openapi.json`)
|
|
8
|
+
* stay outside the protected scope.
|
|
9
|
+
*
|
|
10
|
+
* Failure response:
|
|
11
|
+
*
|
|
12
|
+
* 401 { error_code: 'unauthenticated', error: '<reason>' }
|
|
13
|
+
*
|
|
14
|
+
* The wire envelope intentionally distinguishes "missing header"
|
|
15
|
+
* from "wrong key" only by `error` text; both share the same
|
|
16
|
+
* `error_code` so caller logic does not branch on the difference
|
|
17
|
+
* (preventing oracle-style probing of valid header shape).
|
|
18
|
+
*/
|
|
19
|
+
import type { RequestHandler } from 'express';
|
|
20
|
+
/**
|
|
21
|
+
* Build a middleware that admits a request only when its
|
|
22
|
+
* `Authorization` header carries the configured shared key. The
|
|
23
|
+
* expected key is captured at construction time so a config rotation
|
|
24
|
+
* requires a server restart (matches the rest of the runtime-config
|
|
25
|
+
* model).
|
|
26
|
+
*/
|
|
27
|
+
export declare function requireBearer(expectedApiKey: string): RequestHandler;
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @file `requireBearer` — Express middleware that validates the
|
|
3
|
+
* `Authorization: Bearer <token>` header against a configured shared
|
|
4
|
+
* key in constant time.
|
|
5
|
+
*
|
|
6
|
+
* Mounted in front of every SDK-facing `/v1/*` router by
|
|
7
|
+
* `src/app/create-app.ts`. Public probes (`/health`, `/openapi.json`)
|
|
8
|
+
* stay outside the protected scope.
|
|
9
|
+
*
|
|
10
|
+
* Failure response:
|
|
11
|
+
*
|
|
12
|
+
* 401 { error_code: 'unauthenticated', error: '<reason>' }
|
|
13
|
+
*
|
|
14
|
+
* The wire envelope intentionally distinguishes "missing header"
|
|
15
|
+
* from "wrong key" only by `error` text; both share the same
|
|
16
|
+
* `error_code` so caller logic does not branch on the difference
|
|
17
|
+
* (preventing oracle-style probing of valid header shape).
|
|
18
|
+
*/
|
|
19
|
+
import { timingSafeEqual } from 'node:crypto';
|
|
20
|
+
const BEARER_PREFIX = 'Bearer ';
|
|
21
|
+
/**
|
|
22
|
+
* Build a middleware that admits a request only when its
|
|
23
|
+
* `Authorization` header carries the configured shared key. The
|
|
24
|
+
* expected key is captured at construction time so a config rotation
|
|
25
|
+
* requires a server restart (matches the rest of the runtime-config
|
|
26
|
+
* model).
|
|
27
|
+
*/
|
|
28
|
+
export function requireBearer(expectedApiKey) {
|
|
29
|
+
if (typeof expectedApiKey !== 'string' || expectedApiKey.length === 0) {
|
|
30
|
+
throw new Error('requireBearer: expectedApiKey must be a non-empty string');
|
|
31
|
+
}
|
|
32
|
+
const expectedBuffer = Buffer.from(expectedApiKey, 'utf8');
|
|
33
|
+
return (req, res, next) => {
|
|
34
|
+
const headerValue = readAuthorizationHeader(req);
|
|
35
|
+
if (headerValue === null) {
|
|
36
|
+
respondUnauthenticated(res, 'missing or malformed Authorization header');
|
|
37
|
+
return;
|
|
38
|
+
}
|
|
39
|
+
const providedBuffer = Buffer.from(headerValue, 'utf8');
|
|
40
|
+
if (providedBuffer.length !== expectedBuffer.length) {
|
|
41
|
+
respondUnauthenticated(res, 'invalid api key');
|
|
42
|
+
return;
|
|
43
|
+
}
|
|
44
|
+
if (!timingSafeEqual(providedBuffer, expectedBuffer)) {
|
|
45
|
+
respondUnauthenticated(res, 'invalid api key');
|
|
46
|
+
return;
|
|
47
|
+
}
|
|
48
|
+
next();
|
|
49
|
+
};
|
|
50
|
+
}
|
|
51
|
+
function readAuthorizationHeader(req) {
|
|
52
|
+
const raw = req.headers['authorization'];
|
|
53
|
+
if (typeof raw !== 'string' || !raw.startsWith(BEARER_PREFIX))
|
|
54
|
+
return null;
|
|
55
|
+
const token = raw.slice(BEARER_PREFIX.length).trim();
|
|
56
|
+
return token.length > 0 ? token : null;
|
|
57
|
+
}
|
|
58
|
+
function respondUnauthenticated(res, reason) {
|
|
59
|
+
res.status(401).json({ error_code: 'unauthenticated', error: reason });
|
|
60
|
+
}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @file Dev/test-mode response validator.
|
|
3
|
+
*
|
|
4
|
+
* Wraps `res.json()` to parse the outgoing body against a route→schema
|
|
5
|
+
* map declared alongside the OpenAPI response schemas. Catches the
|
|
6
|
+
* formatter↔schema drift that `check:openapi` alone can't see: if a
|
|
7
|
+
* formatter in `routes/memory-response-formatters.ts` changes a field
|
|
8
|
+
* name or shape without the corresponding update in
|
|
9
|
+
* `schemas/responses.ts`, tests fail loudly at the point of emission.
|
|
10
|
+
*
|
|
11
|
+
* No-op in production. Enabled by default everywhere else (tests,
|
|
12
|
+
* `NODE_ENV=development`) so the check is on in the only environments
|
|
13
|
+
* that actually run tests or local dev.
|
|
14
|
+
*
|
|
15
|
+
* Route keys follow Express's router-relative `${method} ${route.path}`
|
|
16
|
+
* format (e.g. `post /ingest`, `get /:id`). `req.route.path` is set by
|
|
17
|
+
* the time `res.json()` is called inside the handler, so the lookup
|
|
18
|
+
* resolves correctly even for parameterized paths.
|
|
19
|
+
*
|
|
20
|
+
* Error-path responses (4xx/5xx) are not validated — each route emits
|
|
21
|
+
* its own error envelope that's already schema-checked by the
|
|
22
|
+
* `validateBody` middleware on the way in, and runtime error shapes
|
|
23
|
+
* are intentionally less strict than success bodies.
|
|
24
|
+
*/
|
|
25
|
+
import type { RequestHandler } from 'express';
|
|
26
|
+
import type { z } from 'zod';
|
|
27
|
+
export type ResponseSchemaMap = Record<string, z.ZodTypeAny>;
|
|
28
|
+
/**
|
|
29
|
+
* Build a middleware that validates 2xx JSON response bodies against
|
|
30
|
+
* the supplied schema map. Returns a pass-through no-op when
|
|
31
|
+
* NODE_ENV is `production`, so prod has zero per-request cost.
|
|
32
|
+
*/
|
|
33
|
+
export declare function validateResponse(schemaMap: ResponseSchemaMap): RequestHandler;
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @file Dev/test-mode response validator.
|
|
3
|
+
*
|
|
4
|
+
* Wraps `res.json()` to parse the outgoing body against a route→schema
|
|
5
|
+
* map declared alongside the OpenAPI response schemas. Catches the
|
|
6
|
+
* formatter↔schema drift that `check:openapi` alone can't see: if a
|
|
7
|
+
* formatter in `routes/memory-response-formatters.ts` changes a field
|
|
8
|
+
* name or shape without the corresponding update in
|
|
9
|
+
* `schemas/responses.ts`, tests fail loudly at the point of emission.
|
|
10
|
+
*
|
|
11
|
+
* No-op in production. Enabled by default everywhere else (tests,
|
|
12
|
+
* `NODE_ENV=development`) so the check is on in the only environments
|
|
13
|
+
* that actually run tests or local dev.
|
|
14
|
+
*
|
|
15
|
+
* Route keys follow Express's router-relative `${method} ${route.path}`
|
|
16
|
+
* format (e.g. `post /ingest`, `get /:id`). `req.route.path` is set by
|
|
17
|
+
* the time `res.json()` is called inside the handler, so the lookup
|
|
18
|
+
* resolves correctly even for parameterized paths.
|
|
19
|
+
*
|
|
20
|
+
* Error-path responses (4xx/5xx) are not validated — each route emits
|
|
21
|
+
* its own error envelope that's already schema-checked by the
|
|
22
|
+
* `validateBody` middleware on the way in, and runtime error shapes
|
|
23
|
+
* are intentionally less strict than success bodies.
|
|
24
|
+
*/
|
|
25
|
+
/**
|
|
26
|
+
* Build a middleware that validates 2xx JSON response bodies against
|
|
27
|
+
* the supplied schema map. Returns a pass-through no-op when
|
|
28
|
+
* NODE_ENV is `production`, so prod has zero per-request cost.
|
|
29
|
+
*/
|
|
30
|
+
export function validateResponse(schemaMap) {
|
|
31
|
+
if (process.env.NODE_ENV === 'production') {
|
|
32
|
+
return (_req, _res, next) => next();
|
|
33
|
+
}
|
|
34
|
+
return (req, res, next) => {
|
|
35
|
+
const originalJson = res.json.bind(res);
|
|
36
|
+
res.json = function patchedJson(body) {
|
|
37
|
+
if (res.statusCode >= 200 && res.statusCode < 300 && req.route?.path) {
|
|
38
|
+
const key = `${req.method.toLowerCase()} ${req.route.path}`;
|
|
39
|
+
const schema = schemaMap[key];
|
|
40
|
+
if (schema) {
|
|
41
|
+
const result = schema.safeParse(body);
|
|
42
|
+
if (!result.success) {
|
|
43
|
+
throw new Error(`Response body for ${key} violates declared schema.\n`
|
|
44
|
+
+ `Formatter output does not match ${key}'s OpenAPI response schema. `
|
|
45
|
+
+ `Either update the formatter, or if the change is intentional, update `
|
|
46
|
+
+ `src/schemas/responses.ts and regenerate the OpenAPI spec.\n`
|
|
47
|
+
+ `Zod issues:\n${JSON.stringify(result.error.issues, null, 2)}`);
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
return originalJson(body);
|
|
52
|
+
};
|
|
53
|
+
next();
|
|
54
|
+
};
|
|
55
|
+
}
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @file Express request validators built on Zod schemas.
|
|
3
|
+
*
|
|
4
|
+
* `validateBody` / `validateQuery` / `validateParams` replace the hand-
|
|
5
|
+
* written `parseIngestBody` / `parseSearchBody` / `requireBodyString`
|
|
6
|
+
* helpers that used to live in `src/routes/*`. On failure they emit
|
|
7
|
+
* the existing 400 response envelope verbatim — `{ error: string }`
|
|
8
|
+
* — so HTTP clients see no change. Zod's structured issues are
|
|
9
|
+
* flattened into a single descriptive string via {@link formatZodIssues}
|
|
10
|
+
* matching the style of the prior parsers' thrown messages.
|
|
11
|
+
*
|
|
12
|
+
* On success the parsed-and-transformed value replaces the original
|
|
13
|
+
* `req.body` / `req.query` / `req.params` so handlers see camelCase
|
|
14
|
+
* fields regardless of the snake_case wire format.
|
|
15
|
+
*/
|
|
16
|
+
import type { RequestHandler } from 'express';
|
|
17
|
+
import type { z, ZodIssue, ZodTypeAny } from 'zod';
|
|
18
|
+
/**
|
|
19
|
+
* Flatten Zod issues into a single human-readable string.
|
|
20
|
+
*
|
|
21
|
+
* Example output:
|
|
22
|
+
* "user_id is required; conversation must be ≤ 100000 characters"
|
|
23
|
+
*
|
|
24
|
+
* The format mirrors the ad-hoc messages produced by the route
|
|
25
|
+
* handlers' inline validators today, so clients that regex-match error
|
|
26
|
+
* text continue to work.
|
|
27
|
+
*/
|
|
28
|
+
export declare function formatZodIssues(issues: ZodIssue[]): string;
|
|
29
|
+
/** Validate `req.body` against a Zod schema. */
|
|
30
|
+
export declare function validateBody<T extends ZodTypeAny>(schema: T): RequestHandler;
|
|
31
|
+
/** Validate `req.query` against a Zod schema. */
|
|
32
|
+
export declare function validateQuery<T extends ZodTypeAny>(schema: T): RequestHandler;
|
|
33
|
+
/** Validate `req.params` against a Zod schema. */
|
|
34
|
+
export declare function validateParams<T extends ZodTypeAny>(schema: T): RequestHandler;
|
|
35
|
+
/**
|
|
36
|
+
* Assert that a response payload matches `schema`, throwing in non-
|
|
37
|
+
* production. Used as a lightweight runtime contract check on handler
|
|
38
|
+
* outputs; in production it is a no-op so there is no perf impact.
|
|
39
|
+
*
|
|
40
|
+
* Callers should invoke `assertResponse(Schema, payload)` immediately
|
|
41
|
+
* before `res.json(payload)` on non-trivial routes.
|
|
42
|
+
*/
|
|
43
|
+
export declare function assertResponse<T extends ZodTypeAny>(schema: T, payload: unknown): asserts payload is z.infer<T>;
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @file Express request validators built on Zod schemas.
|
|
3
|
+
*
|
|
4
|
+
* `validateBody` / `validateQuery` / `validateParams` replace the hand-
|
|
5
|
+
* written `parseIngestBody` / `parseSearchBody` / `requireBodyString`
|
|
6
|
+
* helpers that used to live in `src/routes/*`. On failure they emit
|
|
7
|
+
* the existing 400 response envelope verbatim — `{ error: string }`
|
|
8
|
+
* — so HTTP clients see no change. Zod's structured issues are
|
|
9
|
+
* flattened into a single descriptive string via {@link formatZodIssues}
|
|
10
|
+
* matching the style of the prior parsers' thrown messages.
|
|
11
|
+
*
|
|
12
|
+
* On success the parsed-and-transformed value replaces the original
|
|
13
|
+
* `req.body` / `req.query` / `req.params` so handlers see camelCase
|
|
14
|
+
* fields regardless of the snake_case wire format.
|
|
15
|
+
*/
|
|
16
|
+
/**
|
|
17
|
+
* Flatten Zod issues into a single human-readable string.
|
|
18
|
+
*
|
|
19
|
+
* Example output:
|
|
20
|
+
* "user_id is required; conversation must be ≤ 100000 characters"
|
|
21
|
+
*
|
|
22
|
+
* The format mirrors the ad-hoc messages produced by the route
|
|
23
|
+
* handlers' inline validators today, so clients that regex-match error
|
|
24
|
+
* text continue to work.
|
|
25
|
+
*/
|
|
26
|
+
export function formatZodIssues(issues) {
|
|
27
|
+
return issues
|
|
28
|
+
.map(issue => {
|
|
29
|
+
const path = issue.path.join('.');
|
|
30
|
+
return path ? `${path}: ${issue.message}` : issue.message;
|
|
31
|
+
})
|
|
32
|
+
.join('; ');
|
|
33
|
+
}
|
|
34
|
+
function respond400(res, error) {
|
|
35
|
+
res.status(400).json({ error: formatZodIssues(error.issues) });
|
|
36
|
+
}
|
|
37
|
+
function makeValidator(schema, source) {
|
|
38
|
+
return (req, res, next) => {
|
|
39
|
+
const result = schema.safeParse(req[source]);
|
|
40
|
+
if (!result.success) {
|
|
41
|
+
respond400(res, result.error);
|
|
42
|
+
return;
|
|
43
|
+
}
|
|
44
|
+
// Express 5 exposes `req.query` (and `req.params`) as getter-only
|
|
45
|
+
// properties on Request.prototype — plain `req.query = ...`
|
|
46
|
+
// silently no-ops. Define an own property to shadow the prototype
|
|
47
|
+
// accessor so handlers see the parsed-and-transformed value.
|
|
48
|
+
Object.defineProperty(req, source, {
|
|
49
|
+
value: result.data,
|
|
50
|
+
writable: true,
|
|
51
|
+
configurable: true,
|
|
52
|
+
enumerable: true,
|
|
53
|
+
});
|
|
54
|
+
next();
|
|
55
|
+
};
|
|
56
|
+
}
|
|
57
|
+
/** Validate `req.body` against a Zod schema. */
|
|
58
|
+
export function validateBody(schema) {
|
|
59
|
+
return makeValidator(schema, 'body');
|
|
60
|
+
}
|
|
61
|
+
/** Validate `req.query` against a Zod schema. */
|
|
62
|
+
export function validateQuery(schema) {
|
|
63
|
+
return makeValidator(schema, 'query');
|
|
64
|
+
}
|
|
65
|
+
/** Validate `req.params` against a Zod schema. */
|
|
66
|
+
export function validateParams(schema) {
|
|
67
|
+
return makeValidator(schema, 'params');
|
|
68
|
+
}
|
|
69
|
+
/**
|
|
70
|
+
* Assert that a response payload matches `schema`, throwing in non-
|
|
71
|
+
* production. Used as a lightweight runtime contract check on handler
|
|
72
|
+
* outputs; in production it is a no-op so there is no perf impact.
|
|
73
|
+
*
|
|
74
|
+
* Callers should invoke `assertResponse(Schema, payload)` immediately
|
|
75
|
+
* before `res.json(payload)` on non-trivial routes.
|
|
76
|
+
*/
|
|
77
|
+
export function assertResponse(schema, payload) {
|
|
78
|
+
if (process.env.NODE_ENV === 'production')
|
|
79
|
+
return;
|
|
80
|
+
const result = schema.safeParse(payload);
|
|
81
|
+
if (result.success)
|
|
82
|
+
return;
|
|
83
|
+
const message = formatZodIssues(result.error.issues);
|
|
84
|
+
throw new Error(`[assertResponse] payload failed schema: ${message}`);
|
|
85
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Agent trust and conflict resolution API routes.
|
|
3
|
+
* Provides endpoints for managing agent trust levels and resolving
|
|
4
|
+
* cross-agent memory conflicts.
|
|
5
|
+
*
|
|
6
|
+
* Request validation is delegated to the Zod schemas in
|
|
7
|
+
* `src/schemas/agents.ts` via the `validateBody` / `validateQuery` /
|
|
8
|
+
* `validateParams` middleware. Error messages are preserved byte-for-
|
|
9
|
+
* byte from the pre-refactor inline validators.
|
|
10
|
+
*/
|
|
11
|
+
import { Router } from 'express';
|
|
12
|
+
import { AgentTrustRepository } from '../db/agent-trust-repository.js';
|
|
13
|
+
export declare function createAgentRouter(trustRepo: AgentTrustRepository): Router;
|
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Agent trust and conflict resolution API routes.
|
|
3
|
+
* Provides endpoints for managing agent trust levels and resolving
|
|
4
|
+
* cross-agent memory conflicts.
|
|
5
|
+
*
|
|
6
|
+
* Request validation is delegated to the Zod schemas in
|
|
7
|
+
* `src/schemas/agents.ts` via the `validateBody` / `validateQuery` /
|
|
8
|
+
* `validateParams` middleware. Error messages are preserved byte-for-
|
|
9
|
+
* byte from the pre-refactor inline validators.
|
|
10
|
+
*/
|
|
11
|
+
import { Router } from 'express';
|
|
12
|
+
import { handleRouteError } from './route-errors.js';
|
|
13
|
+
import { validateBody, validateQuery, validateParams } from '../middleware/validate.js';
|
|
14
|
+
import { validateResponse } from '../middleware/validate-response.js';
|
|
15
|
+
import { AGENT_RESPONSE_SCHEMAS } from './response-schema-map.js';
|
|
16
|
+
import { SetTrustBodySchema, GetTrustQuerySchema, UserIdFromQuerySchema, UserIdFromBodySchema, ConflictIdParamSchema, ResolveConflictBodySchema, } from '../schemas/agents.js';
|
|
17
|
+
export function createAgentRouter(trustRepo) {
|
|
18
|
+
const router = Router();
|
|
19
|
+
// Dev/test-mode response validator: no-op in production, throws loudly
|
|
20
|
+
// if any 2xx body violates the schema declared in responses.ts.
|
|
21
|
+
router.use(validateResponse(AGENT_RESPONSE_SCHEMAS));
|
|
22
|
+
registerSetTrustRoute(router, trustRepo);
|
|
23
|
+
registerGetTrustRoute(router, trustRepo);
|
|
24
|
+
registerListConflictsRoute(router, trustRepo);
|
|
25
|
+
registerResolveConflictRoute(router, trustRepo);
|
|
26
|
+
registerAutoResolveRoute(router, trustRepo);
|
|
27
|
+
return router;
|
|
28
|
+
}
|
|
29
|
+
function registerSetTrustRoute(router, trustRepo) {
|
|
30
|
+
router.put('/trust', validateBody(SetTrustBodySchema), async (req, res) => {
|
|
31
|
+
try {
|
|
32
|
+
const { agentId, userId, trustLevel, displayName } = req.body;
|
|
33
|
+
await trustRepo.setTrustLevel(agentId, userId, trustLevel, displayName);
|
|
34
|
+
res.json({ agent_id: agentId, trust_level: trustLevel });
|
|
35
|
+
}
|
|
36
|
+
catch (err) {
|
|
37
|
+
handleRouteError(res, 'PUT /v1/agents/trust', err);
|
|
38
|
+
}
|
|
39
|
+
});
|
|
40
|
+
}
|
|
41
|
+
function registerGetTrustRoute(router, trustRepo) {
|
|
42
|
+
router.get('/trust', validateQuery(GetTrustQuerySchema), async (req, res) => {
|
|
43
|
+
try {
|
|
44
|
+
const { agentId, userId } = req.query;
|
|
45
|
+
const trustLevel = await trustRepo.getTrustLevel(agentId, userId);
|
|
46
|
+
res.json({ agent_id: agentId, trust_level: trustLevel });
|
|
47
|
+
}
|
|
48
|
+
catch (err) {
|
|
49
|
+
handleRouteError(res, 'GET /v1/agents/trust', err);
|
|
50
|
+
}
|
|
51
|
+
});
|
|
52
|
+
}
|
|
53
|
+
function registerListConflictsRoute(router, trustRepo) {
|
|
54
|
+
router.get('/conflicts', validateQuery(UserIdFromQuerySchema), async (req, res) => {
|
|
55
|
+
try {
|
|
56
|
+
const { userId } = req.query;
|
|
57
|
+
const conflicts = await trustRepo.listOpenConflicts(userId);
|
|
58
|
+
res.json({ conflicts, count: conflicts.length });
|
|
59
|
+
}
|
|
60
|
+
catch (err) {
|
|
61
|
+
handleRouteError(res, 'GET /v1/agents/conflicts', err);
|
|
62
|
+
}
|
|
63
|
+
});
|
|
64
|
+
}
|
|
65
|
+
function registerResolveConflictRoute(router, trustRepo) {
|
|
66
|
+
router.put('/conflicts/:id/resolve', validateParams(ConflictIdParamSchema), validateBody(ResolveConflictBodySchema), async (req, res) => {
|
|
67
|
+
try {
|
|
68
|
+
const { id: conflictId } = req.params;
|
|
69
|
+
const { resolution } = req.body;
|
|
70
|
+
await trustRepo.resolveConflict(conflictId, resolution);
|
|
71
|
+
res.json({ id: conflictId, status: resolution });
|
|
72
|
+
}
|
|
73
|
+
catch (err) {
|
|
74
|
+
handleRouteError(res, 'PUT /v1/agents/conflicts/:id/resolve', err);
|
|
75
|
+
}
|
|
76
|
+
});
|
|
77
|
+
}
|
|
78
|
+
function registerAutoResolveRoute(router, trustRepo) {
|
|
79
|
+
router.post('/conflicts/auto-resolve', validateBody(UserIdFromBodySchema), async (req, res) => {
|
|
80
|
+
try {
|
|
81
|
+
const { userId } = req.body;
|
|
82
|
+
const resolved = await trustRepo.autoResolveExpiredConflicts(userId);
|
|
83
|
+
res.json({ resolved });
|
|
84
|
+
}
|
|
85
|
+
catch (err) {
|
|
86
|
+
handleRouteError(res, 'POST /v1/agents/conflicts/auto-resolve', err);
|
|
87
|
+
}
|
|
88
|
+
});
|
|
89
|
+
}
|
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Wire-format formatters for /v1/documents/* responses.
|
|
3
|
+
*
|
|
4
|
+
* Mirrors the snake_case envelope the rest of the API uses: handlers
|
|
5
|
+
* emit camelCase shapes from the service layer, this module flattens
|
|
6
|
+
* them to the on-the-wire JSON.
|
|
7
|
+
*/
|
|
8
|
+
import type { RawDocumentRow } from '../db/raw-document-types.js';
|
|
9
|
+
import type { ListPassportFeedResult } from '../db/passport-feed-repository.js';
|
|
10
|
+
import { type RawContentStoreRegistry } from '../storage/store-registry.js';
|
|
11
|
+
export declare function formatRawDocument(row: RawDocumentRow, registry: RawContentStoreRegistry): Record<string, unknown>;
|
|
12
|
+
export declare function formatRegisterDocumentResponse(result: {
|
|
13
|
+
document: RawDocumentRow;
|
|
14
|
+
created: boolean;
|
|
15
|
+
}, registry: RawContentStoreRegistry): Record<string, unknown>;
|
|
16
|
+
export declare function formatListDocumentsResponse(documents: RawDocumentRow[], registry: RawContentStoreRegistry): Record<string, unknown>;
|
|
17
|
+
/**
|
|
18
|
+
* Cursor-paginated document list. Mirrors
|
|
19
|
+
* `DocumentListRootResponseSchema` in `schemas/responses.ts`.
|
|
20
|
+
*/
|
|
21
|
+
export declare function formatDocumentListRootResponse(result: {
|
|
22
|
+
documents: RawDocumentRow[];
|
|
23
|
+
nextCursor: string | null;
|
|
24
|
+
}, registry: RawContentStoreRegistry): Record<string, unknown>;
|
|
25
|
+
/**
|
|
26
|
+
* Passport-feed envelope formatter. Maps the discriminated
|
|
27
|
+
* repository result to the public snake_case wire shape.
|
|
28
|
+
*/
|
|
29
|
+
export declare function formatPassportFeedResponse(result: ListPassportFeedResult, registry: RawContentStoreRegistry): Record<string, unknown>;
|
|
30
|
+
export declare function formatDeleteDocumentResponse(result: {
|
|
31
|
+
success: true;
|
|
32
|
+
alreadyDeleted: boolean;
|
|
33
|
+
}): Record<string, unknown>;
|
|
34
|
+
export declare function formatUploadRawDocumentResponse(result: {
|
|
35
|
+
documentId: string;
|
|
36
|
+
storageProvider: string;
|
|
37
|
+
storageUri: string;
|
|
38
|
+
contentHash: string;
|
|
39
|
+
sizeBytes: number;
|
|
40
|
+
rawStorageStatus: 'blob_stored' | 'blob_pending' | 'blob_available';
|
|
41
|
+
storageMode: 'managed_blob';
|
|
42
|
+
/**
|
|
43
|
+
* INTERNAL metadata shape `{ codec, filecoin?, upload_result }`
|
|
44
|
+
* — the wire response strips `upload_result` and AES-GCM
|
|
45
|
+
* internals via `formatPublicRawStorageMetadata`. The Filecoin
|
|
46
|
+
* sidecar is projected through the shared
|
|
47
|
+
* `projectFilecoinPublicMetadata` helper into the Synapse-backed
|
|
48
|
+
* public shape (`copy_count` / `provider_ids` / `copy_statuses`).
|
|
49
|
+
*/
|
|
50
|
+
rawStorageMetadata: Record<string, unknown>;
|
|
51
|
+
idempotentSkip: boolean;
|
|
52
|
+
}, registry: RawContentStoreRegistry): Record<string, unknown>;
|
|
53
|
+
export declare function formatIndexDocumentResponse(result: {
|
|
54
|
+
documentId: string;
|
|
55
|
+
indexedContentHash: string;
|
|
56
|
+
chunksCreated: number;
|
|
57
|
+
memoriesCreated: number;
|
|
58
|
+
idempotentSkip: boolean;
|
|
59
|
+
chunkerVersion: string;
|
|
60
|
+
parserVersion: string;
|
|
61
|
+
}): Record<string, unknown>;
|
|
62
|
+
export declare function formatDocumentFailureMarkerResponse(result: {
|
|
63
|
+
document: RawDocumentRow;
|
|
64
|
+
idempotent: boolean;
|
|
65
|
+
}, registry: RawContentStoreRegistry): Record<string, unknown>;
|
|
66
|
+
/**
|
|
67
|
+
* Filecoin lifecycle refactor (Slice 4): `capabilities` is the
|
|
68
|
+
* internal camelCase shape `RawContentStore.capabilities`
|
|
69
|
+
* advertises. The snapshot composition root (`create-app.ts`)
|
|
70
|
+
* sources it from the active store; this formatter is the ONLY
|
|
71
|
+
* place that flips the four capability keys
|
|
72
|
+
* (`addressing`, `retrievalConsistency`, `deleteSemantics`,
|
|
73
|
+
* `supportsHead`, `supportsGet`) to their snake_case wire form.
|
|
74
|
+
* Internal code MUST NOT receive the snake_case names; wire code
|
|
75
|
+
* MUST NOT see the camelCase names.
|
|
76
|
+
*
|
|
77
|
+
* `provider` echoes `RawContentStore.provider` (`local_fs`, `s3`,
|
|
78
|
+
* `filecoin`, ...). Omitted alongside `capabilities` when
|
|
79
|
+
* `mode = 'pointer_only'` (no store).
|
|
80
|
+
*/
|
|
81
|
+
export interface DocumentLimitsSnapshot {
|
|
82
|
+
rawUploadMaxBytes: number;
|
|
83
|
+
indexMaxTextBytes: number;
|
|
84
|
+
rawStorage: {
|
|
85
|
+
enabled: boolean;
|
|
86
|
+
mode: 'pointer_only' | 'managed_blob';
|
|
87
|
+
reason?: string;
|
|
88
|
+
provider?: string;
|
|
89
|
+
capabilities?: {
|
|
90
|
+
addressing: 'location' | 'content';
|
|
91
|
+
retrievalConsistency: 'immediate' | 'eventual';
|
|
92
|
+
deleteSemantics: 'delete' | 'unpin' | 'tombstone';
|
|
93
|
+
supportsHead: boolean;
|
|
94
|
+
supportsGet: boolean;
|
|
95
|
+
};
|
|
96
|
+
};
|
|
97
|
+
}
|
|
98
|
+
export declare function formatDocumentLimitsResponse(snapshot: DocumentLimitsSnapshot): Record<string, unknown>;
|