@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,449 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @file Zod schemas for /v1/documents/*.
|
|
3
|
+
*
|
|
4
|
+
* Wire format is snake_case (matching /v1/memories/*); each schema
|
|
5
|
+
* `.transform()`s to camelCase for handlers. Covers register
|
|
6
|
+
* (pointer-only at the wire layer), index, raw upload, the
|
|
7
|
+
* constrained-transition bodies, the query schemas in
|
|
8
|
+
* `document-list-schemas.ts`, and the runtime preflight + path-param
|
|
9
|
+
* helpers shared across the routes.
|
|
10
|
+
*
|
|
11
|
+
* Wire-layer mode invariant: `POST /v1/documents` (register) still
|
|
12
|
+
* only accepts `storage_mode='pointer_only'`. The `managed_blob`
|
|
13
|
+
* mode is populated server-side by the post-upload row-promotion in
|
|
14
|
+
* `raw-document-blob-repository.ts:updateRawDocumentBlobStorageWithClient`
|
|
15
|
+
* `inline_small_text` is reserved for a future inline-
|
|
16
|
+
* text path and is rejected with a "not yet supported" message even
|
|
17
|
+
* though the SQL CHECK accepts it.
|
|
18
|
+
*/
|
|
19
|
+
import { z } from './zod-setup.js';
|
|
20
|
+
import { requiredStringBody } from './common.js';
|
|
21
|
+
const MAX_METADATA_SERIALIZED_BYTES = 32 * 1024;
|
|
22
|
+
const MAX_LIST_LIMIT = 100;
|
|
23
|
+
const DEFAULT_LIST_LIMIT = 20;
|
|
24
|
+
const UUID_REGEX = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i;
|
|
25
|
+
// ---------------------------------------------------------------------------
|
|
26
|
+
// Document-specific field schemas (shared helpers come from ./common.js)
|
|
27
|
+
// ---------------------------------------------------------------------------
|
|
28
|
+
/**
|
|
29
|
+
* Optional string body field that also accepts an explicit `null`. Most
|
|
30
|
+
* /v1/documents/* fields use this — they map to nullable Postgres columns
|
|
31
|
+
* where the wire client wants to distinguish "absent" (do not change) from
|
|
32
|
+
* "explicitly null" (clear the field).
|
|
33
|
+
*
|
|
34
|
+
* Modeled as a real `string | null | undefined` union so the generated
|
|
35
|
+
* OpenAPI emits `type: ["string", "null"]` (3.1) instead of pretending
|
|
36
|
+
* the field is string-only. Wire inputs that are neither string nor
|
|
37
|
+
* null are rejected with a 400 from Zod — that's stricter than the
|
|
38
|
+
* `OptionalBodyString` soft-coerce pattern, but the wire contract here
|
|
39
|
+
* is genuinely nullable + brand new, so strictness is the right call.
|
|
40
|
+
*/
|
|
41
|
+
const OptionalNullableBodyString = z.string().nullable().optional();
|
|
42
|
+
const OptionalPositiveBigInt = z
|
|
43
|
+
.unknown()
|
|
44
|
+
.superRefine((v, ctx) => {
|
|
45
|
+
if (v === undefined || v === null)
|
|
46
|
+
return;
|
|
47
|
+
if (typeof v !== 'number' || !Number.isFinite(v) || v < 0 || !Number.isInteger(v)) {
|
|
48
|
+
ctx.addIssue({ code: 'custom', message: 'size_bytes must be a non-negative integer' });
|
|
49
|
+
}
|
|
50
|
+
})
|
|
51
|
+
.transform(v => (typeof v === 'number' ? v : undefined))
|
|
52
|
+
.openapi({ type: 'integer', minimum: 0 });
|
|
53
|
+
const OptionalIsoTimestamp = z
|
|
54
|
+
.unknown()
|
|
55
|
+
.superRefine((v, ctx) => {
|
|
56
|
+
if (v === undefined || v === null || v === '')
|
|
57
|
+
return;
|
|
58
|
+
if (typeof v !== 'string') {
|
|
59
|
+
ctx.addIssue({ code: 'custom', message: 'source_modified_at must be an ISO 8601 string' });
|
|
60
|
+
return;
|
|
61
|
+
}
|
|
62
|
+
if (Number.isNaN(Date.parse(v))) {
|
|
63
|
+
ctx.addIssue({ code: 'custom', message: 'source_modified_at must be a valid ISO 8601 timestamp' });
|
|
64
|
+
}
|
|
65
|
+
})
|
|
66
|
+
.transform(v => (typeof v === 'string' && v.length > 0 ? new Date(v) : undefined))
|
|
67
|
+
.openapi({ type: 'string', format: 'date-time' });
|
|
68
|
+
/** storage_mode: only `pointer_only` is accepted on registration. */
|
|
69
|
+
const PointerOnlyStorageMode = z
|
|
70
|
+
.unknown()
|
|
71
|
+
.superRefine((v, ctx) => {
|
|
72
|
+
if (v === undefined || v === null || v === 'pointer_only')
|
|
73
|
+
return;
|
|
74
|
+
if (v === 'managed_blob' || v === 'inline_small_text') {
|
|
75
|
+
ctx.addIssue({
|
|
76
|
+
code: 'custom',
|
|
77
|
+
message: `storage_mode '${v}' is not supported by document registration; use pointer_only`,
|
|
78
|
+
});
|
|
79
|
+
return;
|
|
80
|
+
}
|
|
81
|
+
ctx.addIssue({ code: 'custom', message: 'storage_mode must be "pointer_only"' });
|
|
82
|
+
})
|
|
83
|
+
.transform(() => 'pointer_only')
|
|
84
|
+
.openapi({ type: 'string', enum: ['pointer_only'] });
|
|
85
|
+
/**
|
|
86
|
+
* status-layer — restricted set of `extraction_status` values clients are
|
|
87
|
+
* allowed to declare on register. Service-owned transitions handle
|
|
88
|
+
* `'running'` / `'complete'` / `'failed'`; clients that try to
|
|
89
|
+
* smuggle those values get a 400. The wire contract is uniform:
|
|
90
|
+
* extraction-layer state changes flow through the upload pipeline
|
|
91
|
+
* (failure-transition) and core-side endpoints, not through register-body
|
|
92
|
+
* fields.
|
|
93
|
+
*/
|
|
94
|
+
const RegisterableExtractionStatus = z
|
|
95
|
+
.enum(['pending', 'not_required', 'unsupported'])
|
|
96
|
+
.openapi({
|
|
97
|
+
type: 'string',
|
|
98
|
+
enum: ['pending', 'not_required', 'unsupported'],
|
|
99
|
+
description: 'Initial extraction-layer state at register time. ' +
|
|
100
|
+
"'pending' = caller intends to extract; 'not_required' = pointer-only flow " +
|
|
101
|
+
"(default); 'unsupported' = caller knows the file type cannot be extracted. " +
|
|
102
|
+
"Service-owned values ('running', 'complete', 'failed') are rejected.",
|
|
103
|
+
});
|
|
104
|
+
/**
|
|
105
|
+
* status-layer — restricted set of `semantic_index_status` values for
|
|
106
|
+
* register-time declarations. The same trust model: clients may flag
|
|
107
|
+
* a row as `'pending'` (the upload pipeline will index next) or
|
|
108
|
+
* `'not_required'` (pointer-only / non-indexable). All transitions
|
|
109
|
+
* to `'running'` / `'complete'` / `'failed'` are service-owned.
|
|
110
|
+
*/
|
|
111
|
+
const RegisterableSemanticIndexStatus = z
|
|
112
|
+
.enum(['pending', 'not_required'])
|
|
113
|
+
.openapi({
|
|
114
|
+
type: 'string',
|
|
115
|
+
enum: ['pending', 'not_required'],
|
|
116
|
+
description: 'Initial semantic-index-layer state at register time. ' +
|
|
117
|
+
"'pending' = caller intends to index; 'not_required' = no indexing planned. " +
|
|
118
|
+
"Service-owned transitions handle 'running', 'complete', 'failed', 'stale'.",
|
|
119
|
+
});
|
|
120
|
+
const FreeFormJsonObject = z
|
|
121
|
+
.record(z.string(), z.unknown())
|
|
122
|
+
.openapi({ type: 'object', additionalProperties: true });
|
|
123
|
+
// ---------------------------------------------------------------------------
|
|
124
|
+
// POST /v1/documents — register
|
|
125
|
+
// ---------------------------------------------------------------------------
|
|
126
|
+
export const RegisterDocumentBodySchema = z
|
|
127
|
+
.object({
|
|
128
|
+
user_id: requiredStringBody('user_id'),
|
|
129
|
+
source_site: requiredStringBody('source_site'),
|
|
130
|
+
provider: requiredStringBody('provider'),
|
|
131
|
+
external_id: requiredStringBody('external_id'),
|
|
132
|
+
account_id: OptionalNullableBodyString,
|
|
133
|
+
external_uri: OptionalNullableBodyString,
|
|
134
|
+
display_name: OptionalNullableBodyString,
|
|
135
|
+
mime_type: OptionalNullableBodyString,
|
|
136
|
+
size_bytes: OptionalPositiveBigInt,
|
|
137
|
+
content_hash: OptionalNullableBodyString,
|
|
138
|
+
provider_version: OptionalNullableBodyString,
|
|
139
|
+
source_modified_at: OptionalIsoTimestamp,
|
|
140
|
+
storage_mode: PointerOnlyStorageMode,
|
|
141
|
+
retention_policy: FreeFormJsonObject.optional(),
|
|
142
|
+
consent_policy: FreeFormJsonObject.optional(),
|
|
143
|
+
metadata: FreeFormJsonObject.optional(),
|
|
144
|
+
extraction_status: RegisterableExtractionStatus.optional(),
|
|
145
|
+
semantic_index_status: RegisterableSemanticIndexStatus.optional(),
|
|
146
|
+
})
|
|
147
|
+
// `last_error` is intentionally absent from the schema. Failure
|
|
148
|
+
// envelopes are written by service-owned transitions only — accepting
|
|
149
|
+
// them on register would let clients smuggle arbitrary failure state
|
|
150
|
+
// onto a fresh row.
|
|
151
|
+
.strict()
|
|
152
|
+
.refine(metadataWithinSizeCap, {
|
|
153
|
+
message: `metadata exceeds max serialized size of ${MAX_METADATA_SERIALIZED_BYTES} bytes (utf-8)`,
|
|
154
|
+
})
|
|
155
|
+
.transform(toRegisterDocumentInternal)
|
|
156
|
+
.openapi({
|
|
157
|
+
description: 'Register a document pointer. Document registration accepts pointer_only mode; ' +
|
|
158
|
+
'managed_blob and inline_small_text return 400.',
|
|
159
|
+
});
|
|
160
|
+
// ---------------------------------------------------------------------------
|
|
161
|
+
// Path params
|
|
162
|
+
// ---------------------------------------------------------------------------
|
|
163
|
+
export const DocumentIdParamSchema = z
|
|
164
|
+
.object({
|
|
165
|
+
id: z
|
|
166
|
+
.string()
|
|
167
|
+
.regex(UUID_REGEX, 'id must be a valid UUID')
|
|
168
|
+
.openapi({ type: 'string', format: 'uuid' }),
|
|
169
|
+
})
|
|
170
|
+
.transform(p => ({ id: p.id }));
|
|
171
|
+
// ---------------------------------------------------------------------------
|
|
172
|
+
// Query schemas
|
|
173
|
+
// ---------------------------------------------------------------------------
|
|
174
|
+
/**
|
|
175
|
+
* Exported (private-by-convention) so the cursor-list query-schema module
|
|
176
|
+
* (`document-list-schemas.ts`) can reuse the same wire contract for
|
|
177
|
+
* the cursor-paginated routes without re-defining the helper.
|
|
178
|
+
*/
|
|
179
|
+
export const RequiredQueryString = z.string().min(1);
|
|
180
|
+
export const DocumentByIdQuerySchema = z
|
|
181
|
+
.object({ user_id: RequiredQueryString })
|
|
182
|
+
.transform(q => ({ userId: q.user_id }));
|
|
183
|
+
export const ListDocumentsQuerySchema = z
|
|
184
|
+
.object({
|
|
185
|
+
user_id: RequiredQueryString,
|
|
186
|
+
source_site: z.string().optional(),
|
|
187
|
+
limit: z.string().optional(),
|
|
188
|
+
offset: z.string().optional(),
|
|
189
|
+
})
|
|
190
|
+
.transform(q => ({
|
|
191
|
+
userId: q.user_id,
|
|
192
|
+
sourceSite: typeof q.source_site === 'string' && q.source_site.length > 0 ? q.source_site : undefined,
|
|
193
|
+
limit: clampInt(q.limit, DEFAULT_LIST_LIMIT, 1, MAX_LIST_LIMIT),
|
|
194
|
+
offset: clampInt(q.offset, 0, 0, Number.MAX_SAFE_INTEGER),
|
|
195
|
+
}));
|
|
196
|
+
// ---------------------------------------------------------------------------
|
|
197
|
+
// POST /v1/documents/:id/index — the upload implementation text indexing
|
|
198
|
+
// ---------------------------------------------------------------------------
|
|
199
|
+
/**
|
|
200
|
+
* Hard ceiling on the indexed-text body. Deterministic (no env knob)
|
|
201
|
+
* so the wire contract stays predictable: clients can size their
|
|
202
|
+
* extracted-text payloads against a known fixed value.
|
|
203
|
+
*
|
|
204
|
+
* 25 MiB accommodates the webapp manual-upload pipeline, which allows
|
|
205
|
+
* 50 MiB input files and feeds the *extracted* text (typically a
|
|
206
|
+
* fraction of the source size — e.g. a 50 MiB PDF extracts to ≈ 5 MiB
|
|
207
|
+
* of text).
|
|
208
|
+
*
|
|
209
|
+
* status-layer durable-failure contract: the indexer's `semanticValidate`
|
|
210
|
+
* (in `services/document-indexer.ts`) is the authoritative gate for
|
|
211
|
+
* whitespace-only and oversized-text inputs. Both checks fire AFTER
|
|
212
|
+
* the document is loaded and the running CAS lands, so the row is
|
|
213
|
+
* durably marked `semantic_index_status='failed'` + `last_error`
|
|
214
|
+
* before the route returns 413/400. The route's body-parser limit
|
|
215
|
+
* (`INDEX_BODY_PARSER_LIMIT` below) is a defense-in-depth bound that
|
|
216
|
+
* lets a body containing exactly `MAX_INDEX_TEXT_BYTES` of text reach
|
|
217
|
+
* the handler with reasonable JSON-wrapper headroom while still
|
|
218
|
+
* rejecting truly multi-GB request bodies.
|
|
219
|
+
*
|
|
220
|
+
* `IndexDocumentBodySchema` deliberately does NOT refine on whitespace
|
|
221
|
+
* or byte length — those are durable-failure checks owned by the
|
|
222
|
+
* indexer. The schema only enforces structural shape (string fields
|
|
223
|
+
* are present and typed correctly) so callers that send a malformed
|
|
224
|
+
* body (no `user_id`, missing `text`, wrong type) still get a clean
|
|
225
|
+
* pre-document-known 400 with no row touched.
|
|
226
|
+
*/
|
|
227
|
+
export const MAX_INDEX_TEXT_BYTES = 25 * 1024 * 1024;
|
|
228
|
+
/**
|
|
229
|
+
* Per-route HTTP body-parser limit for `POST /v1/documents/:id/index`.
|
|
230
|
+
* Adds a 64 KiB headroom on top of `MAX_INDEX_TEXT_BYTES` so a body
|
|
231
|
+
* containing the cap-sized text plus the JSON wrapper
|
|
232
|
+
* (`{"user_id":"<uuid>","text":"…"}`) and modest amounts of escape
|
|
233
|
+
* encoding still fits. Truly huge request bodies (multi-GB scrape
|
|
234
|
+
* dumps, malformed clients, attack payloads) still get rejected by
|
|
235
|
+
* Express's body parser with 413 BEFORE the handler runs.
|
|
236
|
+
*
|
|
237
|
+
* Pathological JSON-escape encodings that double the encoded text
|
|
238
|
+
* size will exceed this cap and surface as 413 from the body-parser
|
|
239
|
+
* — that is the right behavior; the runtime semantic-validation
|
|
240
|
+
* limit is on the parsed UTF-8 string, not the wire-encoded bytes,
|
|
241
|
+
* and a caller can re-encode to fit.
|
|
242
|
+
*/
|
|
243
|
+
export const INDEX_BODY_PARSER_LIMIT = MAX_INDEX_TEXT_BYTES + 64 * 1024;
|
|
244
|
+
export const IndexDocumentBodySchema = z
|
|
245
|
+
.object({
|
|
246
|
+
user_id: requiredStringBody('user_id'),
|
|
247
|
+
// status-layer: structural-only validation. Whitespace + byte-cap
|
|
248
|
+
// checks are owned by `semanticValidate` in the indexer so the
|
|
249
|
+
// failure transitions get persisted on the durable row instead
|
|
250
|
+
// of leaving direct SDK callers with a stuck `pending` state.
|
|
251
|
+
text: requiredStringBody('text'),
|
|
252
|
+
})
|
|
253
|
+
.transform((b) => ({
|
|
254
|
+
userId: b.user_id,
|
|
255
|
+
text: b.text,
|
|
256
|
+
}))
|
|
257
|
+
.openapi({
|
|
258
|
+
description: 'Chunk + embed the supplied text for the registered document, ' +
|
|
259
|
+
'creating one provenance-linked memory per chunk. Idempotent on ' +
|
|
260
|
+
'byte-identical text under the current chunker_version.',
|
|
261
|
+
});
|
|
262
|
+
// ---------------------------------------------------------------------------
|
|
263
|
+
// POST /v1/documents/:id/extraction-failure - failure-transition constrained transition
|
|
264
|
+
// ---------------------------------------------------------------------------
|
|
265
|
+
/**
|
|
266
|
+
* failure-transition - bounded enum of extraction-layer failure codes accepted on
|
|
267
|
+
* `POST /v1/documents/:id/extraction-failure`. The set deliberately
|
|
268
|
+
* mirrors the audit's "things a parser does when it gives up" list;
|
|
269
|
+
* adding a new code requires updating this enum AND the route's
|
|
270
|
+
* `ExtractionErrorCode` SDK type so the wire stays in lockstep.
|
|
271
|
+
*/
|
|
272
|
+
const ExtractionErrorCodeSchema = z.enum([
|
|
273
|
+
'parser_threw',
|
|
274
|
+
'parser_timeout',
|
|
275
|
+
'parser_oom',
|
|
276
|
+
'unsupported_encoding',
|
|
277
|
+
'corrupt_input',
|
|
278
|
+
'unknown',
|
|
279
|
+
]).openapi({
|
|
280
|
+
type: 'string',
|
|
281
|
+
enum: ['parser_threw', 'parser_timeout', 'parser_oom', 'unsupported_encoding', 'corrupt_input', 'unknown'],
|
|
282
|
+
description: 'Bounded extraction-layer failure code. Open-ended exception messages ' +
|
|
283
|
+
'ride on `error_message`; this code is what the UI / metrics layer ' +
|
|
284
|
+
'pivots on.',
|
|
285
|
+
});
|
|
286
|
+
/**
|
|
287
|
+
* failure-transition - request body for the constrained extraction-failure
|
|
288
|
+
* transition. The route service-truncates / sanitises `error_message`
|
|
289
|
+
* before persisting (see `sanitizeLastErrorMessage` +
|
|
290
|
+
* `MAX_LAST_ERROR_MESSAGE_CHARS` in
|
|
291
|
+
* `src/db/raw-document-status-repository.ts`); the schema enforces
|
|
292
|
+
* upper-bound shape only. Service-owned status fields are NOT
|
|
293
|
+
* accepted - clients can declare *that* extraction failed and *what
|
|
294
|
+
* category*, but cannot put a document into arbitrary status
|
|
295
|
+
* combinations.
|
|
296
|
+
*/
|
|
297
|
+
export const ExtractionFailureBodySchema = z.object({
|
|
298
|
+
user_id: requiredStringBody('user_id'),
|
|
299
|
+
error_code: ExtractionErrorCodeSchema,
|
|
300
|
+
error_message: z.string(),
|
|
301
|
+
}).strict().transform((b) => ({
|
|
302
|
+
userId: b.user_id,
|
|
303
|
+
errorCode: b.error_code,
|
|
304
|
+
errorMessage: b.error_message,
|
|
305
|
+
})).openapi({
|
|
306
|
+
description: 'Constrained transition body for the extraction-failure route. ' +
|
|
307
|
+
'The route loads the row under a per-document advisory lock, ' +
|
|
308
|
+
'verifies the current state is one of the allowed source states, ' +
|
|
309
|
+
'and writes `extraction_status=\"failed\"` + ' +
|
|
310
|
+
'`semantic_index_status=\"not_required\"` + a sanitised ' +
|
|
311
|
+
'`last_error.layer=\"extraction\"`. 409 on invalid transitions; ' +
|
|
312
|
+
'idempotent on repeat for already-failed rows.',
|
|
313
|
+
});
|
|
314
|
+
// ---------------------------------------------------------------------------
|
|
315
|
+
// POST /v1/documents/:id/index-failure - failure-transition constrained transition
|
|
316
|
+
// ---------------------------------------------------------------------------
|
|
317
|
+
/**
|
|
318
|
+
* failure-transition - bounded enum of semantic-index-layer failure codes
|
|
319
|
+
* accepted on `POST /v1/documents/:id/index-failure`. The
|
|
320
|
+
* `index_text_too_large` code is special: when paired with a row in
|
|
321
|
+
* `extraction_status='pending'`, the route atomically advances
|
|
322
|
+
* extraction to `'complete'` (text-in-hand implies extraction
|
|
323
|
+
* succeeded) AND marks semantic_index `'failed'` so the durable row
|
|
324
|
+
* reflects the upload pipeline's actual sequence.
|
|
325
|
+
*/
|
|
326
|
+
const IndexErrorCodeSchema = z.enum([
|
|
327
|
+
'index_text_too_large',
|
|
328
|
+
'extraction_empty',
|
|
329
|
+
'unknown',
|
|
330
|
+
]).openapi({
|
|
331
|
+
type: 'string',
|
|
332
|
+
enum: ['index_text_too_large', 'extraction_empty', 'unknown'],
|
|
333
|
+
description: 'Bounded semantic-index-layer failure code. `index_text_too_large` ' +
|
|
334
|
+
'is the upload-pipeline shortcut for the case where extracted text ' +
|
|
335
|
+
'exceeded the index byte cap before reaching `POST /:id/index`.',
|
|
336
|
+
});
|
|
337
|
+
/**
|
|
338
|
+
* failure-transition - request body for the constrained index-failure
|
|
339
|
+
* transition. Service ownership rules match
|
|
340
|
+
* `ExtractionFailureBodySchema`: the message is sanitised + truncated
|
|
341
|
+
* server-side; status fields cannot be smuggled in.
|
|
342
|
+
*/
|
|
343
|
+
export const IndexFailureBodySchema = z.object({
|
|
344
|
+
user_id: requiredStringBody('user_id'),
|
|
345
|
+
error_code: IndexErrorCodeSchema,
|
|
346
|
+
error_message: z.string(),
|
|
347
|
+
}).strict().transform((b) => ({
|
|
348
|
+
userId: b.user_id,
|
|
349
|
+
errorCode: b.error_code,
|
|
350
|
+
errorMessage: b.error_message,
|
|
351
|
+
})).openapi({
|
|
352
|
+
description: 'Constrained transition body for the index-failure route. ' +
|
|
353
|
+
'Permitted transitions: ' +
|
|
354
|
+
'(a) `extraction_status=\"complete\"` + ' +
|
|
355
|
+
'`semantic_index_status=\"pending\"` -> writes ' +
|
|
356
|
+
'`semantic_index_status=\"failed\"`; ' +
|
|
357
|
+
'(b) `extraction_status=\"pending\"` + ' +
|
|
358
|
+
'`semantic_index_status=\"pending\"` AND ' +
|
|
359
|
+
'`error_code=\"index_text_too_large\"` -> atomically writes ' +
|
|
360
|
+
'`extraction_status=\"complete\"` + ' +
|
|
361
|
+
'`semantic_index_status=\"failed\"`; ' +
|
|
362
|
+
'(c) idempotent retry on already-failed rows. Any other state ' +
|
|
363
|
+
'returns 409.',
|
|
364
|
+
});
|
|
365
|
+
// ---------------------------------------------------------------------------
|
|
366
|
+
// PUT /v1/documents/:id/raw — raw-content managed-blob upload
|
|
367
|
+
// ---------------------------------------------------------------------------
|
|
368
|
+
/**
|
|
369
|
+
* Query schema for the raw-upload route. The body is the file bytes
|
|
370
|
+
* themselves (Content-Type: application/octet-stream); identifying
|
|
371
|
+
* fields ride on the query string so we don't have to multipart-parse.
|
|
372
|
+
*/
|
|
373
|
+
export const UploadRawDocumentQuerySchema = z
|
|
374
|
+
.object({
|
|
375
|
+
user_id: RequiredQueryString,
|
|
376
|
+
content_type: z.string().optional(),
|
|
377
|
+
})
|
|
378
|
+
.transform((q) => ({
|
|
379
|
+
userId: q.user_id,
|
|
380
|
+
contentType: typeof q.content_type === 'string' && q.content_type.length > 0 ? q.content_type : undefined,
|
|
381
|
+
}));
|
|
382
|
+
/**
|
|
383
|
+
* Exported for the cursor-list query-schema module
|
|
384
|
+
* (`document-list-schemas.ts`) so the cursor-paginated routes share
|
|
385
|
+
* the same parse-and-clamp semantics for `limit`. Returns
|
|
386
|
+
* `defaultVal` for missing / non-numeric input; clamps to
|
|
387
|
+
* `[min, max]` otherwise.
|
|
388
|
+
*/
|
|
389
|
+
export function clampInt(raw, defaultVal, min, max) {
|
|
390
|
+
const parsed = raw === undefined ? defaultVal : parseInt(raw, 10);
|
|
391
|
+
if (!Number.isFinite(parsed))
|
|
392
|
+
return defaultVal;
|
|
393
|
+
return Math.max(min, Math.min(max, Math.floor(parsed)));
|
|
394
|
+
}
|
|
395
|
+
function metadataWithinSizeCap(b) {
|
|
396
|
+
if (!b.metadata)
|
|
397
|
+
return true;
|
|
398
|
+
return Buffer.byteLength(JSON.stringify(b.metadata), 'utf8') <= MAX_METADATA_SERIALIZED_BYTES;
|
|
399
|
+
}
|
|
400
|
+
/** Required identifying fields — always present on a validated body. */
|
|
401
|
+
function toRegisterDocumentIdentity(b) {
|
|
402
|
+
return {
|
|
403
|
+
userId: b.user_id,
|
|
404
|
+
sourceSite: b.source_site,
|
|
405
|
+
provider: b.provider,
|
|
406
|
+
externalId: b.external_id,
|
|
407
|
+
accountId: b.account_id ?? null,
|
|
408
|
+
};
|
|
409
|
+
}
|
|
410
|
+
/** Optional source/upstream metadata. */
|
|
411
|
+
function toRegisterDocumentSourceMeta(b) {
|
|
412
|
+
return {
|
|
413
|
+
externalUri: b.external_uri ?? null,
|
|
414
|
+
displayName: b.display_name ?? null,
|
|
415
|
+
mimeType: b.mime_type ?? null,
|
|
416
|
+
sizeBytes: b.size_bytes ?? null,
|
|
417
|
+
contentHash: b.content_hash ?? null,
|
|
418
|
+
providerVersion: b.provider_version ?? null,
|
|
419
|
+
sourceModifiedAt: b.source_modified_at ?? null,
|
|
420
|
+
};
|
|
421
|
+
}
|
|
422
|
+
/** Storage + policy + metadata bag. */
|
|
423
|
+
function toRegisterDocumentPolicy(b) {
|
|
424
|
+
return {
|
|
425
|
+
storageMode: b.storage_mode,
|
|
426
|
+
retentionPolicy: b.retention_policy ?? {},
|
|
427
|
+
consentPolicy: b.consent_policy ?? {},
|
|
428
|
+
metadata: b.metadata ?? {},
|
|
429
|
+
};
|
|
430
|
+
}
|
|
431
|
+
/**
|
|
432
|
+
* status-layer — restricted-initial-state status fields. Defaults match
|
|
433
|
+
* the column defaults (`'not_required'`); callers opt into the
|
|
434
|
+
* document pipeline by passing `'pending'`.
|
|
435
|
+
*/
|
|
436
|
+
function toRegisterDocumentLayerStatus(b) {
|
|
437
|
+
return {
|
|
438
|
+
extractionStatus: b.extraction_status,
|
|
439
|
+
semanticIndexStatus: b.semantic_index_status,
|
|
440
|
+
};
|
|
441
|
+
}
|
|
442
|
+
function toRegisterDocumentInternal(b) {
|
|
443
|
+
return {
|
|
444
|
+
...toRegisterDocumentIdentity(b),
|
|
445
|
+
...toRegisterDocumentSourceMeta(b),
|
|
446
|
+
...toRegisterDocumentPolicy(b),
|
|
447
|
+
...toRegisterDocumentLayerStatus(b),
|
|
448
|
+
};
|
|
449
|
+
}
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @file Zod schemas for HTTP error envelopes.
|
|
3
|
+
*
|
|
4
|
+
* The canonical envelope across the API is `{ error: string }`:
|
|
5
|
+
* - 400: emitted by the Zod `validateBody` / `validateQuery` /
|
|
6
|
+
* `validateParams` middleware in `src/middleware/validate.ts`
|
|
7
|
+
* when request input fails schema validation.
|
|
8
|
+
* - 500: emitted by `handleRouteError` in `src/routes/route-errors.ts`
|
|
9
|
+
* for uncaught service-layer exceptions.
|
|
10
|
+
*
|
|
11
|
+
* Two routes have richer envelopes:
|
|
12
|
+
* - `PUT /v1/memories/config` — 400 with `{ error, detail, rejected[] }`
|
|
13
|
+
* when startup-only fields are mutated at runtime.
|
|
14
|
+
* - `PUT /v1/memories/config` — 410 with `{ error, detail }` when
|
|
15
|
+
* runtime config mutation is disabled.
|
|
16
|
+
*
|
|
17
|
+
* Routes that call upstream AI providers can also emit a richer
|
|
18
|
+
* envelope on 502 / 503 — see `ErrorUpstreamProviderSchema`.
|
|
19
|
+
*
|
|
20
|
+
* These schemas are the source of truth for the OpenAPI spec's response
|
|
21
|
+
* components.
|
|
22
|
+
*/
|
|
23
|
+
import { z } from './zod-setup.js';
|
|
24
|
+
/** Standard error envelope used by every route for 400 (validation) and 500 (uncaught). */
|
|
25
|
+
export declare const ErrorBasicSchema: z.ZodObject<{
|
|
26
|
+
error: z.ZodString;
|
|
27
|
+
}, z.core.$strip>;
|
|
28
|
+
export type ErrorBasic = z.infer<typeof ErrorBasicSchema>;
|
|
29
|
+
/**
|
|
30
|
+
* Richer 400 envelope returned by `PUT /v1/memories/config` when a
|
|
31
|
+
* request body includes startup-only fields that cannot be mutated at
|
|
32
|
+
* runtime (embedding/LLM provider + model).
|
|
33
|
+
*/
|
|
34
|
+
export declare const ErrorConfig400Schema: z.ZodObject<{
|
|
35
|
+
error: z.ZodString;
|
|
36
|
+
detail: z.ZodString;
|
|
37
|
+
rejected: z.ZodArray<z.ZodString>;
|
|
38
|
+
}, z.core.$strip>;
|
|
39
|
+
export type ErrorConfig400 = z.infer<typeof ErrorConfig400Schema>;
|
|
40
|
+
/**
|
|
41
|
+
* 410 envelope returned by `PUT /v1/memories/config` when runtime
|
|
42
|
+
* config mutation is disabled (production default).
|
|
43
|
+
*/
|
|
44
|
+
export declare const ErrorConfig410Schema: z.ZodObject<{
|
|
45
|
+
error: z.ZodString;
|
|
46
|
+
detail: z.ZodString;
|
|
47
|
+
}, z.core.$strip>;
|
|
48
|
+
export type ErrorConfig410 = z.infer<typeof ErrorConfig410Schema>;
|
|
49
|
+
/**
|
|
50
|
+
* Sanitized envelope emitted by `handleRouteError` when an upstream AI
|
|
51
|
+
* provider (LLM or embedding) failure is classified by
|
|
52
|
+
* `classifyUpstreamProviderFailure` in `src/routes/upstream-provider-errors.ts`.
|
|
53
|
+
*
|
|
54
|
+
* - 502 Bad Gateway: provider auth (401/403) or non-retryable 4xx.
|
|
55
|
+
* - 503 Service Unavailable: provider rate limit / quota exhausted
|
|
56
|
+
* (429), or provider 5xx where retry is meaningful.
|
|
57
|
+
*
|
|
58
|
+
* `retryable` tells the caller whether a retry can succeed without
|
|
59
|
+
* operator intervention. `details` is a length-capped string sanitized
|
|
60
|
+
* of API keys and bearer tokens.
|
|
61
|
+
*/
|
|
62
|
+
export declare const ErrorUpstreamProviderSchema: z.ZodObject<{
|
|
63
|
+
error_code: z.ZodEnum<{
|
|
64
|
+
upstream_provider_quota_exceeded: "upstream_provider_quota_exceeded";
|
|
65
|
+
upstream_provider_rate_limited: "upstream_provider_rate_limited";
|
|
66
|
+
upstream_provider_auth_failed: "upstream_provider_auth_failed";
|
|
67
|
+
upstream_provider_error: "upstream_provider_error";
|
|
68
|
+
}>;
|
|
69
|
+
error: z.ZodString;
|
|
70
|
+
message: z.ZodString;
|
|
71
|
+
provider_status: z.ZodNumber;
|
|
72
|
+
retryable: z.ZodBoolean;
|
|
73
|
+
details: z.ZodString;
|
|
74
|
+
}, z.core.$strip>;
|
|
75
|
+
export type ErrorUpstreamProvider = z.infer<typeof ErrorUpstreamProviderSchema>;
|
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @file Zod schemas for HTTP error envelopes.
|
|
3
|
+
*
|
|
4
|
+
* The canonical envelope across the API is `{ error: string }`:
|
|
5
|
+
* - 400: emitted by the Zod `validateBody` / `validateQuery` /
|
|
6
|
+
* `validateParams` middleware in `src/middleware/validate.ts`
|
|
7
|
+
* when request input fails schema validation.
|
|
8
|
+
* - 500: emitted by `handleRouteError` in `src/routes/route-errors.ts`
|
|
9
|
+
* for uncaught service-layer exceptions.
|
|
10
|
+
*
|
|
11
|
+
* Two routes have richer envelopes:
|
|
12
|
+
* - `PUT /v1/memories/config` — 400 with `{ error, detail, rejected[] }`
|
|
13
|
+
* when startup-only fields are mutated at runtime.
|
|
14
|
+
* - `PUT /v1/memories/config` — 410 with `{ error, detail }` when
|
|
15
|
+
* runtime config mutation is disabled.
|
|
16
|
+
*
|
|
17
|
+
* Routes that call upstream AI providers can also emit a richer
|
|
18
|
+
* envelope on 502 / 503 — see `ErrorUpstreamProviderSchema`.
|
|
19
|
+
*
|
|
20
|
+
* These schemas are the source of truth for the OpenAPI spec's response
|
|
21
|
+
* components.
|
|
22
|
+
*/
|
|
23
|
+
import { z } from './zod-setup.js';
|
|
24
|
+
/** Standard error envelope used by every route for 400 (validation) and 500 (uncaught). */
|
|
25
|
+
export const ErrorBasicSchema = z
|
|
26
|
+
.object({
|
|
27
|
+
error: z.string(),
|
|
28
|
+
})
|
|
29
|
+
.openapi({
|
|
30
|
+
description: 'Standard error envelope. 400 for input validation errors, 500 for uncaught exceptions.',
|
|
31
|
+
example: { error: 'user_id is required' },
|
|
32
|
+
});
|
|
33
|
+
/**
|
|
34
|
+
* Richer 400 envelope returned by `PUT /v1/memories/config` when a
|
|
35
|
+
* request body includes startup-only fields that cannot be mutated at
|
|
36
|
+
* runtime (embedding/LLM provider + model).
|
|
37
|
+
*/
|
|
38
|
+
export const ErrorConfig400Schema = z
|
|
39
|
+
.object({
|
|
40
|
+
error: z.string(),
|
|
41
|
+
detail: z.string(),
|
|
42
|
+
rejected: z.array(z.string()),
|
|
43
|
+
})
|
|
44
|
+
.openapi({
|
|
45
|
+
description: 'Richer 400 envelope for PUT /v1/memories/config when startup-only fields are included.',
|
|
46
|
+
example: {
|
|
47
|
+
error: 'Provider/model selection is startup-only',
|
|
48
|
+
detail: 'Fields embedding_provider cannot be mutated at runtime — the embedding/LLM provider caches are fixed at first use.',
|
|
49
|
+
rejected: ['embedding_provider'],
|
|
50
|
+
},
|
|
51
|
+
});
|
|
52
|
+
/**
|
|
53
|
+
* 410 envelope returned by `PUT /v1/memories/config` when runtime
|
|
54
|
+
* config mutation is disabled (production default).
|
|
55
|
+
*/
|
|
56
|
+
export const ErrorConfig410Schema = z
|
|
57
|
+
.object({
|
|
58
|
+
error: z.string(),
|
|
59
|
+
detail: z.string(),
|
|
60
|
+
})
|
|
61
|
+
.openapi({
|
|
62
|
+
description: '410 Gone envelope for PUT /v1/memories/config when runtime mutation is disabled.',
|
|
63
|
+
example: {
|
|
64
|
+
error: 'PUT /v1/memories/config is deprecated for production',
|
|
65
|
+
detail: 'Set CORE_RUNTIME_CONFIG_MUTATION_ENABLED=true to enable runtime mutation in dev/test environments.',
|
|
66
|
+
},
|
|
67
|
+
});
|
|
68
|
+
/**
|
|
69
|
+
* Sanitized envelope emitted by `handleRouteError` when an upstream AI
|
|
70
|
+
* provider (LLM or embedding) failure is classified by
|
|
71
|
+
* `classifyUpstreamProviderFailure` in `src/routes/upstream-provider-errors.ts`.
|
|
72
|
+
*
|
|
73
|
+
* - 502 Bad Gateway: provider auth (401/403) or non-retryable 4xx.
|
|
74
|
+
* - 503 Service Unavailable: provider rate limit / quota exhausted
|
|
75
|
+
* (429), or provider 5xx where retry is meaningful.
|
|
76
|
+
*
|
|
77
|
+
* `retryable` tells the caller whether a retry can succeed without
|
|
78
|
+
* operator intervention. `details` is a length-capped string sanitized
|
|
79
|
+
* of API keys and bearer tokens.
|
|
80
|
+
*/
|
|
81
|
+
export const ErrorUpstreamProviderSchema = z
|
|
82
|
+
.object({
|
|
83
|
+
error_code: z.enum([
|
|
84
|
+
'upstream_provider_auth_failed',
|
|
85
|
+
'upstream_provider_rate_limited',
|
|
86
|
+
'upstream_provider_quota_exceeded',
|
|
87
|
+
'upstream_provider_error',
|
|
88
|
+
]),
|
|
89
|
+
error: z.string(),
|
|
90
|
+
message: z.string(),
|
|
91
|
+
provider_status: z.number().int(),
|
|
92
|
+
retryable: z.boolean(),
|
|
93
|
+
details: z.string(),
|
|
94
|
+
})
|
|
95
|
+
.openapi({
|
|
96
|
+
description: 'Upstream AI provider failure envelope (502 / 503).',
|
|
97
|
+
example: {
|
|
98
|
+
error_code: 'upstream_provider_auth_failed',
|
|
99
|
+
error: 'Upstream provider authentication failed',
|
|
100
|
+
message: 'The configured AI provider rejected the request credentials. Check the provider API key and account access.',
|
|
101
|
+
provider_status: 401,
|
|
102
|
+
retryable: false,
|
|
103
|
+
details: 'Incorrect API key provided: [REDACTED_API_KEY].',
|
|
104
|
+
},
|
|
105
|
+
});
|