@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,179 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Wire-format response shapers for the memory API.
|
|
3
|
+
*
|
|
4
|
+
* Internal service types use camelCase; HTTP wire convention is snake_case.
|
|
5
|
+
* These formatters translate at the route boundary so internal types and
|
|
6
|
+
* the public contract can evolve independently.
|
|
7
|
+
*
|
|
8
|
+
* Database rows (MemoryRow, LessonRow, ClaimVersionRow) already use
|
|
9
|
+
* snake_case column names and pass through unchanged.
|
|
10
|
+
*/
|
|
11
|
+
import type { IngestResult, MemoryScope, RetrievalObservability } from '../services/memory-service-types.js';
|
|
12
|
+
import type { ConsolidationResult, ConsolidationExecutionResult } from '../services/consolidation-service.js';
|
|
13
|
+
import type { DecayResult, CapCheckResult } from '../services/memory-lifecycle.js';
|
|
14
|
+
import type { ReconciliationResult } from '../services/deferred-audn.js';
|
|
15
|
+
import type { MutationSummary, AuditTrailEntry } from '../db/repository-types.js';
|
|
16
|
+
export declare function formatIngestResponse(result: IngestResult): {
|
|
17
|
+
ingest_trace_id?: string | undefined;
|
|
18
|
+
episode_id: string;
|
|
19
|
+
facts_extracted: number;
|
|
20
|
+
memories_stored: number;
|
|
21
|
+
memories_updated: number;
|
|
22
|
+
memories_deleted: number;
|
|
23
|
+
memories_skipped: number;
|
|
24
|
+
stored_memory_ids: string[];
|
|
25
|
+
updated_memory_ids: string[];
|
|
26
|
+
links_created: number;
|
|
27
|
+
composites_created: number;
|
|
28
|
+
};
|
|
29
|
+
export declare function formatScope(scope: MemoryScope): {
|
|
30
|
+
kind: "user";
|
|
31
|
+
user_id: string;
|
|
32
|
+
} | {
|
|
33
|
+
agent_scope?: import("../db/repository-types.js").AgentScope | undefined;
|
|
34
|
+
kind: "workspace";
|
|
35
|
+
user_id: string;
|
|
36
|
+
workspace_id: string;
|
|
37
|
+
agent_id: string;
|
|
38
|
+
};
|
|
39
|
+
export declare function formatStatsResponse(stats: {
|
|
40
|
+
count: number;
|
|
41
|
+
avgImportance: number;
|
|
42
|
+
sourceDistribution: Record<string, number>;
|
|
43
|
+
}): {
|
|
44
|
+
count: number;
|
|
45
|
+
avg_importance: number;
|
|
46
|
+
source_distribution: Record<string, number>;
|
|
47
|
+
};
|
|
48
|
+
export declare function formatConsolidateResponse(result: ConsolidationResult): {
|
|
49
|
+
memories_scanned: number;
|
|
50
|
+
clusters_found: number;
|
|
51
|
+
memories_in_clusters: number;
|
|
52
|
+
clusters: {
|
|
53
|
+
member_ids: string[];
|
|
54
|
+
member_contents: string[];
|
|
55
|
+
avg_affinity: number;
|
|
56
|
+
member_count: number;
|
|
57
|
+
}[];
|
|
58
|
+
};
|
|
59
|
+
export declare function formatConsolidateExecuteResponse(result: ConsolidationExecutionResult): {
|
|
60
|
+
clusters_consolidated: number;
|
|
61
|
+
memories_archived: number;
|
|
62
|
+
memories_created: number;
|
|
63
|
+
consolidated_memory_ids: string[];
|
|
64
|
+
};
|
|
65
|
+
export declare function formatDecayResponse(result: DecayResult, archived: number): {
|
|
66
|
+
memories_evaluated: number;
|
|
67
|
+
candidates_for_archival: {
|
|
68
|
+
id: string;
|
|
69
|
+
content: string;
|
|
70
|
+
retention_score: number;
|
|
71
|
+
importance: number;
|
|
72
|
+
days_since_access: number;
|
|
73
|
+
access_count: number;
|
|
74
|
+
}[];
|
|
75
|
+
retention_threshold: number;
|
|
76
|
+
avg_retention_score: number;
|
|
77
|
+
archived: number;
|
|
78
|
+
};
|
|
79
|
+
export declare function formatCapResponse(result: CapCheckResult): {
|
|
80
|
+
active_memories: number;
|
|
81
|
+
max_memories: number;
|
|
82
|
+
status: import("../services/memory-lifecycle.js").CapStatus;
|
|
83
|
+
usage_ratio: number;
|
|
84
|
+
recommendation: import("../services/memory-lifecycle.js").CapRecommendation;
|
|
85
|
+
};
|
|
86
|
+
export declare function formatLessonStatsResponse(stats: {
|
|
87
|
+
totalActive: number;
|
|
88
|
+
byType: Record<string, number>;
|
|
89
|
+
}): {
|
|
90
|
+
total_active: number;
|
|
91
|
+
by_type: Record<string, number>;
|
|
92
|
+
};
|
|
93
|
+
export declare function formatReconciliationResponse(result: ReconciliationResult): {
|
|
94
|
+
processed: number;
|
|
95
|
+
resolved: number;
|
|
96
|
+
noops: number;
|
|
97
|
+
updates: number;
|
|
98
|
+
supersedes: number;
|
|
99
|
+
deletes: number;
|
|
100
|
+
adds: number;
|
|
101
|
+
errors: number;
|
|
102
|
+
duration_ms: number;
|
|
103
|
+
};
|
|
104
|
+
export declare function formatResetSourceResponse(result: {
|
|
105
|
+
deletedMemories: number;
|
|
106
|
+
deletedEpisodes: number;
|
|
107
|
+
deletedDocuments: number;
|
|
108
|
+
}): {
|
|
109
|
+
success: boolean;
|
|
110
|
+
deleted_memories: number;
|
|
111
|
+
deleted_episodes: number;
|
|
112
|
+
deleted_documents: number;
|
|
113
|
+
};
|
|
114
|
+
export declare function formatMutationSummaryResponse(summary: MutationSummary): {
|
|
115
|
+
total_versions: number;
|
|
116
|
+
active_versions: number;
|
|
117
|
+
superseded_versions: number;
|
|
118
|
+
total_claims: number;
|
|
119
|
+
by_mutation_type: Record<string, number>;
|
|
120
|
+
};
|
|
121
|
+
export declare function formatObservability(observability: RetrievalObservability): {
|
|
122
|
+
assembly?: {
|
|
123
|
+
final_ids: string[];
|
|
124
|
+
final_token_cost: number;
|
|
125
|
+
token_budget: number | null;
|
|
126
|
+
primary_evidence_position: number | null;
|
|
127
|
+
blocks: string[];
|
|
128
|
+
} | undefined;
|
|
129
|
+
packaging?: {
|
|
130
|
+
package_type: import("../services/retrieval-trace.js").PackagingType;
|
|
131
|
+
included_ids: string[];
|
|
132
|
+
dropped_ids: string[];
|
|
133
|
+
evidence_roles: Record<string, import("../services/retrieval-trace.js").PackagingEvidenceRole>;
|
|
134
|
+
episode_count: number;
|
|
135
|
+
date_count: number;
|
|
136
|
+
has_current_marker: boolean;
|
|
137
|
+
has_conflict_block: boolean;
|
|
138
|
+
token_cost: number;
|
|
139
|
+
} | undefined;
|
|
140
|
+
retrieval?: {
|
|
141
|
+
stage_names?: string[] | undefined;
|
|
142
|
+
stage_count?: number | undefined;
|
|
143
|
+
trace_id?: string | undefined;
|
|
144
|
+
filter_decisions?: {
|
|
145
|
+
id: string;
|
|
146
|
+
source_site: string;
|
|
147
|
+
source_kind: "local" | "integration";
|
|
148
|
+
namespace: string | null;
|
|
149
|
+
semantic_similarity: number;
|
|
150
|
+
ranking_score: number;
|
|
151
|
+
relevance: number;
|
|
152
|
+
threshold: number | null;
|
|
153
|
+
decision: "filtered" | "kept";
|
|
154
|
+
reason: string;
|
|
155
|
+
}[] | undefined;
|
|
156
|
+
filtered_candidate_ids?: string[] | undefined;
|
|
157
|
+
relevance_filter_reason?: string | undefined;
|
|
158
|
+
relevance_filter_source?: string | undefined;
|
|
159
|
+
relevance_threshold?: number | null | undefined;
|
|
160
|
+
candidate_ids: string[];
|
|
161
|
+
candidate_count: number;
|
|
162
|
+
query_text: string;
|
|
163
|
+
skip_repair: boolean;
|
|
164
|
+
} | undefined;
|
|
165
|
+
};
|
|
166
|
+
export declare function formatAuditTrailEntry(entry: AuditTrailEntry): {
|
|
167
|
+
version_id: string;
|
|
168
|
+
claim_id: string;
|
|
169
|
+
content: string;
|
|
170
|
+
mutation_type: import("../db/repository-types.js").MutationType | null;
|
|
171
|
+
mutation_reason: string | null;
|
|
172
|
+
actor_model: string | null;
|
|
173
|
+
contradiction_confidence: number | null;
|
|
174
|
+
previous_version_id: string | null;
|
|
175
|
+
superseded_by_version_id: string | null;
|
|
176
|
+
valid_from: Date;
|
|
177
|
+
valid_to: Date | null;
|
|
178
|
+
memory_id: string | null;
|
|
179
|
+
};
|
|
@@ -0,0 +1,210 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Wire-format response shapers for the memory API.
|
|
3
|
+
*
|
|
4
|
+
* Internal service types use camelCase; HTTP wire convention is snake_case.
|
|
5
|
+
* These formatters translate at the route boundary so internal types and
|
|
6
|
+
* the public contract can evolve independently.
|
|
7
|
+
*
|
|
8
|
+
* Database rows (MemoryRow, LessonRow, ClaimVersionRow) already use
|
|
9
|
+
* snake_case column names and pass through unchanged.
|
|
10
|
+
*/
|
|
11
|
+
export function formatIngestResponse(result) {
|
|
12
|
+
return {
|
|
13
|
+
episode_id: result.episodeId,
|
|
14
|
+
facts_extracted: result.factsExtracted,
|
|
15
|
+
memories_stored: result.memoriesStored,
|
|
16
|
+
memories_updated: result.memoriesUpdated,
|
|
17
|
+
memories_deleted: result.memoriesDeleted,
|
|
18
|
+
memories_skipped: result.memoriesSkipped,
|
|
19
|
+
stored_memory_ids: result.storedMemoryIds,
|
|
20
|
+
updated_memory_ids: result.updatedMemoryIds,
|
|
21
|
+
links_created: result.linksCreated,
|
|
22
|
+
composites_created: result.compositesCreated,
|
|
23
|
+
...(result.ingestTraceId ? { ingest_trace_id: result.ingestTraceId } : {}),
|
|
24
|
+
};
|
|
25
|
+
}
|
|
26
|
+
export function formatScope(scope) {
|
|
27
|
+
if (scope.kind === 'user') {
|
|
28
|
+
return { kind: 'user', user_id: scope.userId };
|
|
29
|
+
}
|
|
30
|
+
return {
|
|
31
|
+
kind: 'workspace',
|
|
32
|
+
user_id: scope.userId,
|
|
33
|
+
workspace_id: scope.workspaceId,
|
|
34
|
+
agent_id: scope.agentId,
|
|
35
|
+
...(scope.agentScope !== undefined ? { agent_scope: scope.agentScope } : {}),
|
|
36
|
+
};
|
|
37
|
+
}
|
|
38
|
+
export function formatStatsResponse(stats) {
|
|
39
|
+
return {
|
|
40
|
+
count: stats.count,
|
|
41
|
+
avg_importance: stats.avgImportance,
|
|
42
|
+
source_distribution: stats.sourceDistribution,
|
|
43
|
+
};
|
|
44
|
+
}
|
|
45
|
+
function formatClusterCandidate(cluster) {
|
|
46
|
+
return {
|
|
47
|
+
member_ids: cluster.memberIds,
|
|
48
|
+
member_contents: cluster.memberContents,
|
|
49
|
+
avg_affinity: cluster.avgAffinity,
|
|
50
|
+
member_count: cluster.memberCount,
|
|
51
|
+
};
|
|
52
|
+
}
|
|
53
|
+
export function formatConsolidateResponse(result) {
|
|
54
|
+
return {
|
|
55
|
+
memories_scanned: result.memoriesScanned,
|
|
56
|
+
clusters_found: result.clustersFound,
|
|
57
|
+
memories_in_clusters: result.memoriesInClusters,
|
|
58
|
+
clusters: result.clusters.map(formatClusterCandidate),
|
|
59
|
+
};
|
|
60
|
+
}
|
|
61
|
+
export function formatConsolidateExecuteResponse(result) {
|
|
62
|
+
return {
|
|
63
|
+
clusters_consolidated: result.clustersConsolidated,
|
|
64
|
+
memories_archived: result.memoriesArchived,
|
|
65
|
+
memories_created: result.memoriesCreated,
|
|
66
|
+
consolidated_memory_ids: result.consolidatedMemoryIds,
|
|
67
|
+
};
|
|
68
|
+
}
|
|
69
|
+
function formatDecayCandidate(candidate) {
|
|
70
|
+
return {
|
|
71
|
+
id: candidate.id,
|
|
72
|
+
content: candidate.content,
|
|
73
|
+
retention_score: candidate.retentionScore,
|
|
74
|
+
importance: candidate.importance,
|
|
75
|
+
days_since_access: candidate.daysSinceAccess,
|
|
76
|
+
access_count: candidate.accessCount,
|
|
77
|
+
};
|
|
78
|
+
}
|
|
79
|
+
export function formatDecayResponse(result, archived) {
|
|
80
|
+
return {
|
|
81
|
+
memories_evaluated: result.memoriesEvaluated,
|
|
82
|
+
candidates_for_archival: result.candidatesForArchival.map(formatDecayCandidate),
|
|
83
|
+
retention_threshold: result.retentionThreshold,
|
|
84
|
+
avg_retention_score: result.avgRetentionScore,
|
|
85
|
+
archived,
|
|
86
|
+
};
|
|
87
|
+
}
|
|
88
|
+
export function formatCapResponse(result) {
|
|
89
|
+
return {
|
|
90
|
+
active_memories: result.activeMemories,
|
|
91
|
+
max_memories: result.maxMemories,
|
|
92
|
+
status: result.status,
|
|
93
|
+
usage_ratio: result.usageRatio,
|
|
94
|
+
recommendation: result.recommendation,
|
|
95
|
+
};
|
|
96
|
+
}
|
|
97
|
+
export function formatLessonStatsResponse(stats) {
|
|
98
|
+
return {
|
|
99
|
+
total_active: stats.totalActive,
|
|
100
|
+
by_type: stats.byType,
|
|
101
|
+
};
|
|
102
|
+
}
|
|
103
|
+
export function formatReconciliationResponse(result) {
|
|
104
|
+
return {
|
|
105
|
+
processed: result.processed,
|
|
106
|
+
resolved: result.resolved,
|
|
107
|
+
noops: result.noops,
|
|
108
|
+
updates: result.updates,
|
|
109
|
+
supersedes: result.supersedes,
|
|
110
|
+
deletes: result.deletes,
|
|
111
|
+
adds: result.adds,
|
|
112
|
+
errors: result.errors,
|
|
113
|
+
duration_ms: result.durationMs,
|
|
114
|
+
};
|
|
115
|
+
}
|
|
116
|
+
export function formatResetSourceResponse(result) {
|
|
117
|
+
return {
|
|
118
|
+
success: true,
|
|
119
|
+
deleted_memories: result.deletedMemories,
|
|
120
|
+
deleted_episodes: result.deletedEpisodes,
|
|
121
|
+
deleted_documents: result.deletedDocuments,
|
|
122
|
+
};
|
|
123
|
+
}
|
|
124
|
+
export function formatMutationSummaryResponse(summary) {
|
|
125
|
+
return {
|
|
126
|
+
total_versions: summary.totalVersions,
|
|
127
|
+
active_versions: summary.activeVersions,
|
|
128
|
+
superseded_versions: summary.supersededVersions,
|
|
129
|
+
total_claims: summary.totalClaims,
|
|
130
|
+
by_mutation_type: summary.byMutationType,
|
|
131
|
+
};
|
|
132
|
+
}
|
|
133
|
+
function formatRetrievalTrace(summary) {
|
|
134
|
+
return {
|
|
135
|
+
candidate_ids: summary.candidateIds,
|
|
136
|
+
candidate_count: summary.candidateCount,
|
|
137
|
+
query_text: summary.queryText,
|
|
138
|
+
skip_repair: summary.skipRepair,
|
|
139
|
+
...(summary.relevanceThreshold !== undefined ? { relevance_threshold: summary.relevanceThreshold } : {}),
|
|
140
|
+
...(summary.relevanceFilterSource ? { relevance_filter_source: summary.relevanceFilterSource } : {}),
|
|
141
|
+
...(summary.relevanceFilterReason ? { relevance_filter_reason: summary.relevanceFilterReason } : {}),
|
|
142
|
+
...(summary.filteredCandidateIds ? { filtered_candidate_ids: summary.filteredCandidateIds } : {}),
|
|
143
|
+
...(summary.filterDecisions ? {
|
|
144
|
+
filter_decisions: summary.filterDecisions.map(formatFilterDecision),
|
|
145
|
+
} : {}),
|
|
146
|
+
...(summary.traceId ? { trace_id: summary.traceId } : {}),
|
|
147
|
+
...(summary.stageCount !== undefined ? { stage_count: summary.stageCount } : {}),
|
|
148
|
+
...(summary.stageNames ? { stage_names: summary.stageNames } : {}),
|
|
149
|
+
};
|
|
150
|
+
}
|
|
151
|
+
function formatFilterDecision(decision) {
|
|
152
|
+
return {
|
|
153
|
+
id: decision.id,
|
|
154
|
+
source_site: decision.sourceSite,
|
|
155
|
+
source_kind: decision.sourceKind,
|
|
156
|
+
namespace: decision.namespace,
|
|
157
|
+
semantic_similarity: decision.semanticSimilarity,
|
|
158
|
+
ranking_score: decision.rankingScore,
|
|
159
|
+
relevance: decision.relevance,
|
|
160
|
+
threshold: decision.threshold,
|
|
161
|
+
decision: decision.decision,
|
|
162
|
+
reason: decision.reason,
|
|
163
|
+
};
|
|
164
|
+
}
|
|
165
|
+
function formatPackagingTrace(summary) {
|
|
166
|
+
return {
|
|
167
|
+
package_type: summary.packageType,
|
|
168
|
+
included_ids: summary.includedIds,
|
|
169
|
+
dropped_ids: summary.droppedIds,
|
|
170
|
+
// evidenceRoles keys are memory IDs (opaque); values are role enum strings.
|
|
171
|
+
evidence_roles: summary.evidenceRoles,
|
|
172
|
+
episode_count: summary.episodeCount,
|
|
173
|
+
date_count: summary.dateCount,
|
|
174
|
+
has_current_marker: summary.hasCurrentMarker,
|
|
175
|
+
has_conflict_block: summary.hasConflictBlock,
|
|
176
|
+
token_cost: summary.tokenCost,
|
|
177
|
+
};
|
|
178
|
+
}
|
|
179
|
+
function formatAssemblyTrace(summary) {
|
|
180
|
+
return {
|
|
181
|
+
final_ids: summary.finalIds,
|
|
182
|
+
final_token_cost: summary.finalTokenCost,
|
|
183
|
+
token_budget: summary.tokenBudget,
|
|
184
|
+
primary_evidence_position: summary.primaryEvidencePosition,
|
|
185
|
+
blocks: summary.blocks,
|
|
186
|
+
};
|
|
187
|
+
}
|
|
188
|
+
export function formatObservability(observability) {
|
|
189
|
+
return {
|
|
190
|
+
...(observability.retrieval ? { retrieval: formatRetrievalTrace(observability.retrieval) } : {}),
|
|
191
|
+
...(observability.packaging ? { packaging: formatPackagingTrace(observability.packaging) } : {}),
|
|
192
|
+
...(observability.assembly ? { assembly: formatAssemblyTrace(observability.assembly) } : {}),
|
|
193
|
+
};
|
|
194
|
+
}
|
|
195
|
+
export function formatAuditTrailEntry(entry) {
|
|
196
|
+
return {
|
|
197
|
+
version_id: entry.versionId,
|
|
198
|
+
claim_id: entry.claimId,
|
|
199
|
+
content: entry.content,
|
|
200
|
+
mutation_type: entry.mutationType,
|
|
201
|
+
mutation_reason: entry.mutationReason,
|
|
202
|
+
actor_model: entry.actorModel,
|
|
203
|
+
contradiction_confidence: entry.contradictionConfidence,
|
|
204
|
+
previous_version_id: entry.previousVersionId,
|
|
205
|
+
superseded_by_version_id: entry.supersededByVersionId,
|
|
206
|
+
valid_from: entry.validFrom,
|
|
207
|
+
valid_to: entry.validTo,
|
|
208
|
+
memory_id: entry.memoryId,
|
|
209
|
+
};
|
|
210
|
+
}
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @file Public projection of `raw_documents.raw_storage_metadata`.
|
|
3
|
+
*
|
|
4
|
+
* The upload and reconciler pipeline writes an internal
|
|
5
|
+
* shape `{ codec, filecoin?, upload_result? }` into the JSONB
|
|
6
|
+
* column. This module is the SINGLE wire-side redaction seam:
|
|
7
|
+
* internal sidecars (`upload_result`, AES-GCM `nonce`/`tag`/`key_id`
|
|
8
|
+
* /`encoded_content_hash`/`encoded_size_bytes`) NEVER appear on the
|
|
9
|
+
* wire; the Filecoin sidecar is projected through the shared
|
|
10
|
+
* storage/public metadata module
|
|
11
|
+
* (`src/storage/filecoin-public-metadata.ts`) so document and
|
|
12
|
+
* storage_artifact paths emit one consistent shape without
|
|
13
|
+
* importing `providers/filecoin/*` from the route layer.
|
|
14
|
+
*
|
|
15
|
+
* The Filecoin public shape is `{ ipfs_cid, piece_cid,
|
|
16
|
+
* copy_count, provider_ids, copy_statuses }` (Phase 4 renamed
|
|
17
|
+
* the previous ambiguous `cid` slot to `ipfs_cid`). Legacy
|
|
18
|
+
* onramp keys (`onramp`, `gateway_url`, `deal_ids`,
|
|
19
|
+
* `onramp_status`, `deal_status`, `retrieval_verified_at`,
|
|
20
|
+
* `last_verified_at`) and the legacy `cid` slot are NOT emitted
|
|
21
|
+
* by this projector — adversarial / pre-migration values are
|
|
22
|
+
* silently dropped at the shape gate (and rejected at the
|
|
23
|
+
* deny-by-default Zod schema if they somehow reach the response
|
|
24
|
+
* validator).
|
|
25
|
+
*/
|
|
26
|
+
import { type FilecoinPublicMetadata } from '../storage/filecoin-public-metadata.js';
|
|
27
|
+
/** Public-facing codec shape — `name` + `version` only. */
|
|
28
|
+
export interface PublicCodecMetadata {
|
|
29
|
+
name: string;
|
|
30
|
+
version: number;
|
|
31
|
+
}
|
|
32
|
+
/**
|
|
33
|
+
* Re-export of the Synapse-shaped public filecoin shape produced
|
|
34
|
+
* by `src/storage/filecoin-public-metadata.ts`. Routes consume
|
|
35
|
+
* the projected fields directly (e.g. `metadata.filecoin?.ipfs_cid`,
|
|
36
|
+
* `metadata.filecoin?.piece_cid`) — see that module for the
|
|
37
|
+
* canonical key list.
|
|
38
|
+
*/
|
|
39
|
+
export type PublicFilecoinMetadata = FilecoinPublicMetadata;
|
|
40
|
+
export interface PublicRawStorageMetadata {
|
|
41
|
+
codec?: PublicCodecMetadata;
|
|
42
|
+
filecoin?: PublicFilecoinMetadata;
|
|
43
|
+
}
|
|
44
|
+
/**
|
|
45
|
+
* Strip internal-only sidecars from a `raw_storage_metadata` JSONB
|
|
46
|
+
* blob. Pure projection — idempotent and side-effect free.
|
|
47
|
+
*
|
|
48
|
+
* - `codec` keeps only `{ name, version }`.
|
|
49
|
+
* - `filecoin` is projected via `projectFilecoinPublicMetadata`
|
|
50
|
+
* so the wire shape matches the storage-side allowlist.
|
|
51
|
+
* - `upload_result` and any other top-level
|
|
52
|
+
* keys are dropped.
|
|
53
|
+
*/
|
|
54
|
+
export declare function formatPublicRawStorageMetadata(internal: Record<string, unknown>): PublicRawStorageMetadata;
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @file Public projection of `raw_documents.raw_storage_metadata`.
|
|
3
|
+
*
|
|
4
|
+
* The upload and reconciler pipeline writes an internal
|
|
5
|
+
* shape `{ codec, filecoin?, upload_result? }` into the JSONB
|
|
6
|
+
* column. This module is the SINGLE wire-side redaction seam:
|
|
7
|
+
* internal sidecars (`upload_result`, AES-GCM `nonce`/`tag`/`key_id`
|
|
8
|
+
* /`encoded_content_hash`/`encoded_size_bytes`) NEVER appear on the
|
|
9
|
+
* wire; the Filecoin sidecar is projected through the shared
|
|
10
|
+
* storage/public metadata module
|
|
11
|
+
* (`src/storage/filecoin-public-metadata.ts`) so document and
|
|
12
|
+
* storage_artifact paths emit one consistent shape without
|
|
13
|
+
* importing `providers/filecoin/*` from the route layer.
|
|
14
|
+
*
|
|
15
|
+
* The Filecoin public shape is `{ ipfs_cid, piece_cid,
|
|
16
|
+
* copy_count, provider_ids, copy_statuses }` (Phase 4 renamed
|
|
17
|
+
* the previous ambiguous `cid` slot to `ipfs_cid`). Legacy
|
|
18
|
+
* onramp keys (`onramp`, `gateway_url`, `deal_ids`,
|
|
19
|
+
* `onramp_status`, `deal_status`, `retrieval_verified_at`,
|
|
20
|
+
* `last_verified_at`) and the legacy `cid` slot are NOT emitted
|
|
21
|
+
* by this projector — adversarial / pre-migration values are
|
|
22
|
+
* silently dropped at the shape gate (and rejected at the
|
|
23
|
+
* deny-by-default Zod schema if they somehow reach the response
|
|
24
|
+
* validator).
|
|
25
|
+
*/
|
|
26
|
+
import { projectFilecoinPublicMetadata, } from '../storage/filecoin-public-metadata.js';
|
|
27
|
+
/**
|
|
28
|
+
* Strip internal-only sidecars from a `raw_storage_metadata` JSONB
|
|
29
|
+
* blob. Pure projection — idempotent and side-effect free.
|
|
30
|
+
*
|
|
31
|
+
* - `codec` keeps only `{ name, version }`.
|
|
32
|
+
* - `filecoin` is projected via `projectFilecoinPublicMetadata`
|
|
33
|
+
* so the wire shape matches the storage-side allowlist.
|
|
34
|
+
* - `upload_result` and any other top-level
|
|
35
|
+
* keys are dropped.
|
|
36
|
+
*/
|
|
37
|
+
export function formatPublicRawStorageMetadata(internal) {
|
|
38
|
+
const out = {};
|
|
39
|
+
const codec = projectCodec(internal['codec']);
|
|
40
|
+
if (codec)
|
|
41
|
+
out.codec = codec;
|
|
42
|
+
const filecoin = projectFilecoinPublicMetadata(internal['filecoin']);
|
|
43
|
+
if (Object.keys(filecoin).length > 0)
|
|
44
|
+
out.filecoin = filecoin;
|
|
45
|
+
return out;
|
|
46
|
+
}
|
|
47
|
+
function projectCodec(value) {
|
|
48
|
+
if (!value || typeof value !== 'object')
|
|
49
|
+
return null;
|
|
50
|
+
const record = value;
|
|
51
|
+
const name = record['name'];
|
|
52
|
+
const version = record['version'];
|
|
53
|
+
if (typeof name !== 'string' || typeof version !== 'number')
|
|
54
|
+
return null;
|
|
55
|
+
return { name, version };
|
|
56
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Synchronous reflect-flush endpoint for benchmark / eval mode.
|
|
3
|
+
*
|
|
4
|
+
* POST /v1/reflect/flush — drains all pending reflection_jobs serially and
|
|
5
|
+
* returns the count of jobs processed. Returns 503 if Reflect is disabled.
|
|
6
|
+
*
|
|
7
|
+
* This endpoint is intentionally synchronous (it blocks until the queue is
|
|
8
|
+
* empty or the 1 000-job safety cap is hit) so benchmarking harnesses can
|
|
9
|
+
* call it once after ingest and be guaranteed all reflections are written
|
|
10
|
+
* before issuing queries.
|
|
11
|
+
*/
|
|
12
|
+
import type { Request, Response } from 'express';
|
|
13
|
+
import type { JobsWorkerDeps } from '../services/reflect-jobs.js';
|
|
14
|
+
export declare function makeReflectFlushHandler(deps: JobsWorkerDeps, enabled: boolean): (req: Request, res: Response) => Promise<void>;
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { processOnePendingJob } from '../services/reflect-jobs.js';
|
|
2
|
+
const FLUSH_JOB_CAP = 1000;
|
|
3
|
+
export function makeReflectFlushHandler(deps, enabled) {
|
|
4
|
+
return async (_req, res) => {
|
|
5
|
+
if (!enabled) {
|
|
6
|
+
res.status(503).json({ error: 'reflect_disabled' });
|
|
7
|
+
return;
|
|
8
|
+
}
|
|
9
|
+
let processed = 0;
|
|
10
|
+
let remaining = FLUSH_JOB_CAP;
|
|
11
|
+
while (remaining-- > 0) {
|
|
12
|
+
const did = await processOnePendingJob(deps);
|
|
13
|
+
if (!did)
|
|
14
|
+
break;
|
|
15
|
+
processed++;
|
|
16
|
+
}
|
|
17
|
+
res.json({ processed });
|
|
18
|
+
};
|
|
19
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @file Route→schema maps consumed by `validate-response` middleware.
|
|
3
|
+
*
|
|
4
|
+
* Keyed by Express's router-relative `${method} ${route.path}` format
|
|
5
|
+
* (method lowercase, path matches what Express stores in `req.route.path`).
|
|
6
|
+
* When a new route is added, add a corresponding entry here; the
|
|
7
|
+
* validator is a no-op for routes not in the map (so new routes
|
|
8
|
+
* ship without a hard dependency on a schema existing yet).
|
|
9
|
+
*/
|
|
10
|
+
import type { ResponseSchemaMap } from '../middleware/validate-response.js';
|
|
11
|
+
export declare const MEMORY_RESPONSE_SCHEMAS: ResponseSchemaMap;
|
|
12
|
+
export declare const AGENT_RESPONSE_SCHEMAS: ResponseSchemaMap;
|
|
13
|
+
export declare const DOCUMENT_RESPONSE_SCHEMAS: ResponseSchemaMap;
|
|
14
|
+
export declare const STORAGE_RESPONSE_SCHEMAS: ResponseSchemaMap;
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @file Route→schema maps consumed by `validate-response` middleware.
|
|
3
|
+
*
|
|
4
|
+
* Keyed by Express's router-relative `${method} ${route.path}` format
|
|
5
|
+
* (method lowercase, path matches what Express stores in `req.route.path`).
|
|
6
|
+
* When a new route is added, add a corresponding entry here; the
|
|
7
|
+
* validator is a no-op for routes not in the map (so new routes
|
|
8
|
+
* ship without a hard dependency on a schema existing yet).
|
|
9
|
+
*/
|
|
10
|
+
import * as R from '../schemas/responses.js';
|
|
11
|
+
import { PassportFeedResponseSchema } from '../schemas/document-list-responses.js';
|
|
12
|
+
import { DeleteArtifactResultSchema, StorageCapabilitiesResponseSchema, StoredArtifactResponseSchema, VerifyArtifactResultSchema, } from '../schemas/storage-schemas.js';
|
|
13
|
+
export const MEMORY_RESPONSE_SCHEMAS = {
|
|
14
|
+
'post /ingest': R.IngestResponseSchema,
|
|
15
|
+
'post /ingest/quick': R.IngestResponseSchema,
|
|
16
|
+
'post /search': R.SearchResponseSchema,
|
|
17
|
+
'post /search/fast': R.SearchResponseSchema,
|
|
18
|
+
'post /expand': R.ExpandResponseSchema,
|
|
19
|
+
'post /verify': R.VerifyResponseSchema,
|
|
20
|
+
'get /list': R.ListResponseSchema,
|
|
21
|
+
'get /stats': R.StatsResponseSchema,
|
|
22
|
+
'get /health': R.HealthResponseSchema,
|
|
23
|
+
'put /config': R.ConfigUpdateResponseSchema,
|
|
24
|
+
'get /event-chains': R.EventChainsResponseSchema,
|
|
25
|
+
'post /first-mentions/extract': R.FirstMentionsExtractResponseSchema,
|
|
26
|
+
'post /consolidate': R.ConsolidateResponseSchema,
|
|
27
|
+
'post /decay': R.DecayResponseSchema,
|
|
28
|
+
'get /cap': R.CapResponseSchema,
|
|
29
|
+
'get /lessons': R.LessonsListResponseSchema,
|
|
30
|
+
'get /lessons/stats': R.LessonStatsResponseSchema,
|
|
31
|
+
'post /lessons/report': R.LessonReportResponseSchema,
|
|
32
|
+
'delete /lessons/:id': R.SuccessResponseSchema,
|
|
33
|
+
'post /reconcile': R.ReconciliationResponseSchema,
|
|
34
|
+
'get /reconcile/status': R.ReconcileStatusResponseSchema,
|
|
35
|
+
'post /reset-source': R.ResetSourceResponseSchema,
|
|
36
|
+
'get /:id': R.GetMemoryResponseSchema,
|
|
37
|
+
'delete /:id': R.SuccessResponseSchema,
|
|
38
|
+
'get /audit/summary': R.MutationSummaryResponseSchema,
|
|
39
|
+
'get /audit/recent': R.AuditRecentResponseSchema,
|
|
40
|
+
'get /:id/audit': R.AuditTrailResponseSchema,
|
|
41
|
+
};
|
|
42
|
+
export const AGENT_RESPONSE_SCHEMAS = {
|
|
43
|
+
'put /trust': R.TrustResponseSchema,
|
|
44
|
+
'get /trust': R.TrustResponseSchema,
|
|
45
|
+
'get /conflicts': R.ConflictsListResponseSchema,
|
|
46
|
+
'put /conflicts/:id/resolve': R.ResolveConflictResponseSchema,
|
|
47
|
+
'post /conflicts/auto-resolve': R.AutoResolveConflictsResponseSchema,
|
|
48
|
+
};
|
|
49
|
+
export const DOCUMENT_RESPONSE_SCHEMAS = {
|
|
50
|
+
'post /': R.RegisterDocumentResponseSchema,
|
|
51
|
+
'get /': R.DocumentListRootResponseSchema,
|
|
52
|
+
'get /limits': R.DocumentLimitsResponseSchema,
|
|
53
|
+
'get /list': R.ListDocumentsResponseSchema,
|
|
54
|
+
'get /without-memories': R.DocumentListRootResponseSchema,
|
|
55
|
+
'get /passport-feed': PassportFeedResponseSchema,
|
|
56
|
+
'post /:id/index': R.IndexDocumentResponseSchema,
|
|
57
|
+
'post /:id/extraction-failure': R.DocumentFailureMarkerResponseSchema,
|
|
58
|
+
'post /:id/index-failure': R.DocumentFailureMarkerResponseSchema,
|
|
59
|
+
'put /:id/raw': R.UploadRawDocumentResponseSchema,
|
|
60
|
+
'get /:id': R.RawDocumentResponseSchema,
|
|
61
|
+
'delete /:id': R.DeleteDocumentResponseSchema,
|
|
62
|
+
};
|
|
63
|
+
export const STORAGE_RESPONSE_SCHEMAS = {
|
|
64
|
+
'get /capabilities': StorageCapabilitiesResponseSchema,
|
|
65
|
+
'post /artifacts': StoredArtifactResponseSchema,
|
|
66
|
+
'get /artifacts/:id': StoredArtifactResponseSchema,
|
|
67
|
+
'delete /artifacts/:id': DeleteArtifactResultSchema,
|
|
68
|
+
'post /artifacts/:id/verify': VerifyArtifactResultSchema,
|
|
69
|
+
};
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Shared error handling utilities for Express route handlers.
|
|
3
|
+
*
|
|
4
|
+
* Request-input validation is performed by the Zod-based
|
|
5
|
+
* `validateBody` / `validateQuery` / `validateParams` middleware in
|
|
6
|
+
* `src/middleware/validate.ts`, which emits 400 responses directly.
|
|
7
|
+
* Most uncaught service-layer failures stay 500. Upstream AI provider
|
|
8
|
+
* failures get a sanitized operator-facing envelope.
|
|
9
|
+
*/
|
|
10
|
+
import type { Response } from 'express';
|
|
11
|
+
/** Log the error and send the public JSON error response. */
|
|
12
|
+
export declare function handleRouteError(res: Response, context: string, err: unknown): void;
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Shared error handling utilities for Express route handlers.
|
|
3
|
+
*
|
|
4
|
+
* Request-input validation is performed by the Zod-based
|
|
5
|
+
* `validateBody` / `validateQuery` / `validateParams` middleware in
|
|
6
|
+
* `src/middleware/validate.ts`, which emits 400 responses directly.
|
|
7
|
+
* Most uncaught service-layer failures stay 500. Upstream AI provider
|
|
8
|
+
* failures get a sanitized operator-facing envelope.
|
|
9
|
+
*/
|
|
10
|
+
import { classifyUpstreamProviderFailure, routeErrorMessage, } from './upstream-provider-errors.js';
|
|
11
|
+
/** Log the error and send the public JSON error response. */
|
|
12
|
+
export function handleRouteError(res, context, err) {
|
|
13
|
+
const internalMessage = routeErrorMessage(err);
|
|
14
|
+
const stack = err instanceof Error ? err.stack : undefined;
|
|
15
|
+
const upstream = classifyUpstreamProviderFailure(err);
|
|
16
|
+
if (upstream) {
|
|
17
|
+
console.error(`${context} error: [${upstream.status}] upstream provider ${upstream.providerStatus}: ${internalMessage}${stack ? `\n${stack}` : ''}`);
|
|
18
|
+
res.status(upstream.status).json({
|
|
19
|
+
error_code: upstream.errorCode,
|
|
20
|
+
error: upstream.error,
|
|
21
|
+
message: upstream.message,
|
|
22
|
+
provider_status: upstream.providerStatus,
|
|
23
|
+
retryable: upstream.retryable,
|
|
24
|
+
details: upstream.details,
|
|
25
|
+
});
|
|
26
|
+
return;
|
|
27
|
+
}
|
|
28
|
+
console.error(`${context} error: [500] ${internalMessage}${stack ? `\n${stack}` : ''}`);
|
|
29
|
+
res.status(500).json({ error: 'Internal server error' });
|
|
30
|
+
}
|