@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,248 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Deterministic post-processing for LLM-extracted facts.
|
|
3
|
+
* Preserves atomic memory coverage by splitting common multi-clause patterns
|
|
4
|
+
* that the extraction prompt still tends to bundle together.
|
|
5
|
+
*/
|
|
6
|
+
const RECOMMENDATION_MARKERS = [
|
|
7
|
+
', as recommended by ',
|
|
8
|
+
', recommended by ',
|
|
9
|
+
', as suggested by ',
|
|
10
|
+
', suggested by ',
|
|
11
|
+
];
|
|
12
|
+
export function normalizeExtractedFacts(facts) {
|
|
13
|
+
const expanded = facts.flatMap((fact) => splitCompoundFact(fact)
|
|
14
|
+
.flatMap(expandBecauseClause)
|
|
15
|
+
.flatMap(normalizeLiteralAliasFacts));
|
|
16
|
+
return dedupeFacts(expanded);
|
|
17
|
+
}
|
|
18
|
+
function splitCompoundFact(fact) {
|
|
19
|
+
const recommendationSplit = splitRecommendationAttribution(fact);
|
|
20
|
+
if (recommendationSplit)
|
|
21
|
+
return recommendationSplit;
|
|
22
|
+
const transitionSplit = splitStateTransitionFact(fact);
|
|
23
|
+
if (transitionSplit)
|
|
24
|
+
return transitionSplit;
|
|
25
|
+
return [fact];
|
|
26
|
+
}
|
|
27
|
+
function splitRecommendationAttribution(fact) {
|
|
28
|
+
const marker = RECOMMENDATION_MARKERS.find((candidate) => fact.fact.includes(candidate));
|
|
29
|
+
if (!marker)
|
|
30
|
+
return null;
|
|
31
|
+
const parts = fact.fact.split(marker);
|
|
32
|
+
if (parts.length !== 2)
|
|
33
|
+
return null;
|
|
34
|
+
const mainFact = ensurePeriod(parts[0]);
|
|
35
|
+
const recommender = normalizePerson(parts[1]);
|
|
36
|
+
const recommendedObject = extractRecommendedObject(mainFact);
|
|
37
|
+
if (!recommender || !recommendedObject)
|
|
38
|
+
return null;
|
|
39
|
+
const recommendationFact = `${extractTemporalPrefix(mainFact)}${recommender} recommended ${recommendedObject}.`;
|
|
40
|
+
return [
|
|
41
|
+
{ ...fact, fact: mainFact },
|
|
42
|
+
{
|
|
43
|
+
...fact,
|
|
44
|
+
fact: recommendationFact,
|
|
45
|
+
type: 'person',
|
|
46
|
+
importance: clampImportance(Math.min(fact.importance, 0.5)),
|
|
47
|
+
keywords: mergeKeywords(fact.keywords, [recommender]),
|
|
48
|
+
},
|
|
49
|
+
];
|
|
50
|
+
}
|
|
51
|
+
function extractRecommendedObject(text) {
|
|
52
|
+
const withoutPrefix = stripTemporalPrefix(text);
|
|
53
|
+
const patterns = [
|
|
54
|
+
/^user is using (.+)$/i,
|
|
55
|
+
/^user uses (.+)$/i,
|
|
56
|
+
/^user plans to use (.+)$/i,
|
|
57
|
+
/^user will use (.+)$/i,
|
|
58
|
+
/^user is considering (.+)$/i,
|
|
59
|
+
/^user chose (.+)$/i,
|
|
60
|
+
/^user selected (.+)$/i,
|
|
61
|
+
];
|
|
62
|
+
for (const pattern of patterns) {
|
|
63
|
+
const match = withoutPrefix.match(pattern);
|
|
64
|
+
if (!match)
|
|
65
|
+
continue;
|
|
66
|
+
return match[1].trim().replace(/[. ]+$/, '');
|
|
67
|
+
}
|
|
68
|
+
return null;
|
|
69
|
+
}
|
|
70
|
+
function normalizePerson(raw) {
|
|
71
|
+
const cleaned = raw
|
|
72
|
+
.trim()
|
|
73
|
+
.replace(/[. ]+$/, '')
|
|
74
|
+
.replace(/^(their|the)\s+/i, '')
|
|
75
|
+
.replace(/^(colleague|friend|advisor|professor|team lead)\s+/i, '')
|
|
76
|
+
.trim();
|
|
77
|
+
return cleaned || null;
|
|
78
|
+
}
|
|
79
|
+
function splitStateTransitionFact(fact) {
|
|
80
|
+
return splitSwitchAwayFact(fact) ?? splitFromToStateChange(fact);
|
|
81
|
+
}
|
|
82
|
+
function splitSwitchAwayFact(fact) {
|
|
83
|
+
const match = fact.fact.match(/^(As of [^,]+,\s+)?(user|we)\s+switched away from (.+?) and (.+?)[. ]*$/i);
|
|
84
|
+
if (!match)
|
|
85
|
+
return null;
|
|
86
|
+
const prefix = match[1] ?? '';
|
|
87
|
+
const subject = match[2].toLowerCase();
|
|
88
|
+
const previousState = stripTrailingPunctuation(match[3]);
|
|
89
|
+
const currentTarget = normalizeStateTarget(match[4]);
|
|
90
|
+
if (!currentTarget)
|
|
91
|
+
return null;
|
|
92
|
+
return [
|
|
93
|
+
...buildCurrentStateFacts(fact, prefix, subject, currentTarget),
|
|
94
|
+
buildStateFact(fact, buildHistoricalStateText(prefix, subject, `switched away from ${previousState}`), 0.45),
|
|
95
|
+
];
|
|
96
|
+
}
|
|
97
|
+
function splitFromToStateChange(fact) {
|
|
98
|
+
const match = fact.fact.match(/^(As of [^,]+,\s+)?(user|we|project)\s+(?:switched|migrated|moved|changed)\s+from (.+?) to (.+?)[. ]*$/i);
|
|
99
|
+
if (!match)
|
|
100
|
+
return null;
|
|
101
|
+
const prefix = match[1] ?? '';
|
|
102
|
+
const subject = match[2].toLowerCase();
|
|
103
|
+
const previousState = stripTrailingPunctuation(match[3]);
|
|
104
|
+
const currentTarget = normalizeStateTarget(match[4]);
|
|
105
|
+
if (!currentTarget)
|
|
106
|
+
return null;
|
|
107
|
+
return [
|
|
108
|
+
...buildCurrentStateFacts(fact, prefix, subject, currentTarget),
|
|
109
|
+
buildStateFact(fact, buildHistoricalStateText(prefix, subject, `previously used ${previousState}`), 0.45),
|
|
110
|
+
];
|
|
111
|
+
}
|
|
112
|
+
function buildStateFact(fact, text, importance) {
|
|
113
|
+
return {
|
|
114
|
+
...fact,
|
|
115
|
+
fact: text,
|
|
116
|
+
importance: clampImportance(importance ?? fact.importance),
|
|
117
|
+
keywords: filterKeywordsForFact(fact.keywords, text),
|
|
118
|
+
};
|
|
119
|
+
}
|
|
120
|
+
function buildCurrentStateFacts(fact, prefix, subject, target) {
|
|
121
|
+
return [
|
|
122
|
+
buildStateFact(fact, buildCurrentStateText(prefix, subject, target)),
|
|
123
|
+
...buildBackendAliasFacts(fact, prefix, subject, target),
|
|
124
|
+
];
|
|
125
|
+
}
|
|
126
|
+
function buildCurrentStateText(prefix, subject, target) {
|
|
127
|
+
const verb = subject === 'we' ? 'use' : 'uses';
|
|
128
|
+
return formatStateSentence(prefix, `${subject} ${verb} ${target}`);
|
|
129
|
+
}
|
|
130
|
+
function buildHistoricalStateText(prefix, subject, clause) {
|
|
131
|
+
return formatStateSentence(prefix, `${subject} ${clause}`);
|
|
132
|
+
}
|
|
133
|
+
function formatStateSentence(prefix, statement) {
|
|
134
|
+
const sentence = `${prefix}${statement}`.trim();
|
|
135
|
+
return ensurePeriod(prefix ? sentence : capitalize(sentence));
|
|
136
|
+
}
|
|
137
|
+
function normalizeStateTarget(raw) {
|
|
138
|
+
const clause = stripTrailingPunctuation(raw);
|
|
139
|
+
const patterns = [
|
|
140
|
+
/^(?:uses?|using|used|built|build|created|create|adopted|adopt|started using|start using|moved to|move to)\s+(.+)$/i,
|
|
141
|
+
];
|
|
142
|
+
for (const pattern of patterns) {
|
|
143
|
+
const match = clause.match(pattern);
|
|
144
|
+
if (match)
|
|
145
|
+
return stripTrailingPunctuation(match[1]);
|
|
146
|
+
}
|
|
147
|
+
return clause || null;
|
|
148
|
+
}
|
|
149
|
+
function filterKeywordsForFact(keywords, factText) {
|
|
150
|
+
const lowerFact = factText.toLowerCase();
|
|
151
|
+
return keywords.filter((keyword) => lowerFact.includes(keyword.trim().toLowerCase()));
|
|
152
|
+
}
|
|
153
|
+
function buildBackendAliasFacts(fact, prefix, subject, target) {
|
|
154
|
+
if (!isMemoryBackendTarget(target))
|
|
155
|
+
return [];
|
|
156
|
+
const statement = formatStateSentence(prefix, `${subject}'s current memory backend is ${target}`);
|
|
157
|
+
return [{
|
|
158
|
+
...buildStateFact(fact, statement, Math.min(fact.importance, 0.7)),
|
|
159
|
+
keywords: mergeKeywords(filterKeywordsForFact(fact.keywords, statement), ['memory backend', 'backend']),
|
|
160
|
+
}];
|
|
161
|
+
}
|
|
162
|
+
function isMemoryBackendTarget(target) {
|
|
163
|
+
const lower = target.toLowerCase();
|
|
164
|
+
return lower.includes('memory engine') || lower.includes('memory backend');
|
|
165
|
+
}
|
|
166
|
+
function expandBecauseClause(fact) {
|
|
167
|
+
const parts = splitBecauseClause(fact.fact);
|
|
168
|
+
if (!parts)
|
|
169
|
+
return [fact];
|
|
170
|
+
return [buildPrimaryFact(fact, parts.primary), buildReasonFact(fact, parts.reason)];
|
|
171
|
+
}
|
|
172
|
+
function splitBecauseClause(text) {
|
|
173
|
+
const markerIndex = text.toLowerCase().indexOf(' because ');
|
|
174
|
+
if (markerIndex === -1)
|
|
175
|
+
return null;
|
|
176
|
+
const primary = text.slice(0, markerIndex).trim().replace(/[. ]+$/, '');
|
|
177
|
+
const reason = text.slice(markerIndex + ' because '.length).trim().replace(/[. ]+$/, '');
|
|
178
|
+
if (!primary || !reason)
|
|
179
|
+
return null;
|
|
180
|
+
return { primary: `${primary}.`, reason };
|
|
181
|
+
}
|
|
182
|
+
function normalizeLiteralAliasFacts(fact) {
|
|
183
|
+
const namedPetFact = normalizeNamedPetFact(fact);
|
|
184
|
+
return namedPetFact ? [namedPetFact] : [fact];
|
|
185
|
+
}
|
|
186
|
+
function normalizeNamedPetFact(fact) {
|
|
187
|
+
const match = fact.fact.match(/^(As of [^,]+,\s+)?([A-Z][A-Za-z'’.-]+),\s+(?:my|user's)\s+(guinea pig|dog|cat)\.?$/i);
|
|
188
|
+
if (!match)
|
|
189
|
+
return null;
|
|
190
|
+
const temporalPrefix = match[1] ?? '';
|
|
191
|
+
const petName = match[2];
|
|
192
|
+
const petType = match[3].toLowerCase();
|
|
193
|
+
return {
|
|
194
|
+
...fact,
|
|
195
|
+
fact: `${temporalPrefix}user has a ${petType} named ${petName}.`,
|
|
196
|
+
keywords: mergeKeywords(fact.keywords, [petName, petType]),
|
|
197
|
+
type: 'person',
|
|
198
|
+
};
|
|
199
|
+
}
|
|
200
|
+
function buildPrimaryFact(fact, primary) {
|
|
201
|
+
return { ...fact, fact: primary };
|
|
202
|
+
}
|
|
203
|
+
function buildReasonFact(fact, reason) {
|
|
204
|
+
return {
|
|
205
|
+
...fact,
|
|
206
|
+
fact: `User reports that ${capitalize(reason)}.`,
|
|
207
|
+
importance: clampImportance(Math.max(0.2, Math.min(0.4, fact.importance - 0.4))),
|
|
208
|
+
type: 'knowledge',
|
|
209
|
+
};
|
|
210
|
+
}
|
|
211
|
+
function dedupeFacts(facts) {
|
|
212
|
+
const unique = new Map();
|
|
213
|
+
for (const fact of facts) {
|
|
214
|
+
unique.set(`${fact.type}:${fact.fact}`, fact);
|
|
215
|
+
}
|
|
216
|
+
return [...unique.values()];
|
|
217
|
+
}
|
|
218
|
+
function extractTemporalPrefix(text) {
|
|
219
|
+
if (!text.startsWith('As of '))
|
|
220
|
+
return '';
|
|
221
|
+
const userIndex = text.toLowerCase().indexOf('user ');
|
|
222
|
+
if (userIndex === -1)
|
|
223
|
+
return '';
|
|
224
|
+
return text.slice(0, userIndex);
|
|
225
|
+
}
|
|
226
|
+
function ensurePeriod(text) {
|
|
227
|
+
return text.trim().replace(/[. ]+$/, '') + '.';
|
|
228
|
+
}
|
|
229
|
+
function mergeKeywords(existing, additions) {
|
|
230
|
+
return [...new Set([...existing, ...additions].map((keyword) => keyword.trim()).filter(Boolean))];
|
|
231
|
+
}
|
|
232
|
+
function clampImportance(value) {
|
|
233
|
+
return Math.max(0, Math.min(1, value));
|
|
234
|
+
}
|
|
235
|
+
function stripTemporalPrefix(text) {
|
|
236
|
+
if (!text.startsWith('As of '))
|
|
237
|
+
return text;
|
|
238
|
+
const userIndex = text.toLowerCase().indexOf('user ');
|
|
239
|
+
if (userIndex === -1)
|
|
240
|
+
return text;
|
|
241
|
+
return text.slice(userIndex);
|
|
242
|
+
}
|
|
243
|
+
function stripTrailingPunctuation(text) {
|
|
244
|
+
return text.trim().replace(/[. ]+$/, '');
|
|
245
|
+
}
|
|
246
|
+
function capitalize(text) {
|
|
247
|
+
return text.charAt(0).toUpperCase() + text.slice(1);
|
|
248
|
+
}
|
|
@@ -0,0 +1,127 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Structured observability for the Filecoin raw-storage lifecycle.
|
|
3
|
+
*
|
|
4
|
+
* Mirrors the `audit-events.ts` shape: typed event payloads emitted
|
|
5
|
+
* as single-line JSON to stdout, prefixed with `[FILECOIN]` for grep
|
|
6
|
+
* / log-aggregator filtering. No metrics framework is invented — the
|
|
7
|
+
* implementation uses log-based aggregation because core does not
|
|
8
|
+
* have a metrics seam today. Operators can derive counters, gauges,
|
|
9
|
+
* and histograms from the event stream.
|
|
10
|
+
*
|
|
11
|
+
* Sanitization is the load-bearing invariant: events MUST NOT carry
|
|
12
|
+
* UCAN proofs, principal keys, codec keys, AES-GCM nonces / tags, or
|
|
13
|
+
* any other credential surface. The module enforces this two ways:
|
|
14
|
+
*
|
|
15
|
+
* 1. The typed `FilecoinEventPayload` is a CLOSED record over a
|
|
16
|
+
* small set of allow-listed fields. Callers cannot accidentally
|
|
17
|
+
* pass a wire-shape `raw_storage_metadata` blob.
|
|
18
|
+
* 2. `sanitizeErrorMessage` strips UCAN/`did:key:`/base64-key
|
|
19
|
+
* lookalikes before they enter the event stream. The function
|
|
20
|
+
* is exported so the scheduler's `logReconcilerError` and any
|
|
21
|
+
* future call-site share the same redaction rule.
|
|
22
|
+
*
|
|
23
|
+
* `computePendingAgeSeconds(pendingSince)` is the pure helper for
|
|
24
|
+
* pending-age gauges; it carries a single contract (NULL → null;
|
|
25
|
+
* otherwise integer seconds from the timestamp to `now`) so the
|
|
26
|
+
* metric definition stays in one place.
|
|
27
|
+
*/
|
|
28
|
+
export type FilecoinEventName = 'filecoin.upload.started' | 'filecoin.upload.accepted' | 'filecoin.upload.failed' | 'filecoin.reconcile.claimed' | 'filecoin.reconcile.promoted' | 'filecoin.reconcile.archival_failed' | 'filecoin.reconcile.stale_claim_recovered' | 'filecoin.reconcile.failure' | 'filecoin.retrieval.verification_failed' | 'filecoin.delete.tombstoned' | 'filecoin.delete.unpinned' | 'filecoin.hint.malformed';
|
|
29
|
+
/**
|
|
30
|
+
* Closed allowlist of fields that may travel on an event payload.
|
|
31
|
+
* Adding a field here is the EXPLICIT permission to surface it on
|
|
32
|
+
* the wire — credentials/proofs/codec keys do not appear and must
|
|
33
|
+
* never be added without a redaction review.
|
|
34
|
+
*/
|
|
35
|
+
export interface FilecoinEventPayload {
|
|
36
|
+
documentId?: string;
|
|
37
|
+
userId?: string;
|
|
38
|
+
/** Storage provider key as it appears on the row (`'filecoin'`). */
|
|
39
|
+
provider?: string;
|
|
40
|
+
statusBefore?: string;
|
|
41
|
+
statusAfter?: string;
|
|
42
|
+
/** Reconciler claim UUID; never embeds vendor data. */
|
|
43
|
+
claimId?: string;
|
|
44
|
+
/** Categorical, vendor-free (see `FilecoinOnrampErrorCode`). */
|
|
45
|
+
errorCode?: string;
|
|
46
|
+
/** Already-sanitized short message — pass through `sanitizeErrorMessage`. */
|
|
47
|
+
errorMessage?: string;
|
|
48
|
+
/** Operation duration for upload latency aggregation. */
|
|
49
|
+
durationMs?: number;
|
|
50
|
+
/** Reconciler batch size — drives `reconcile_batches_total` aggregation. */
|
|
51
|
+
batchSize?: number;
|
|
52
|
+
/** Reconciler attempt count for the row at the time of the event. */
|
|
53
|
+
reconcileAttempts?: number;
|
|
54
|
+
/** Pending-age gauge sample, computed via `computePendingAgeSeconds`. */
|
|
55
|
+
pendingAgeSeconds?: number;
|
|
56
|
+
/**
|
|
57
|
+
* On-chain `0x…` transaction hash returned by the Synapse SDK's
|
|
58
|
+
* `deletePiece` call (the scheduled-removal tx). Surfaced by the
|
|
59
|
+
* `filecoin.delete.tombstoned` event so operators can correlate
|
|
60
|
+
* a cleanup pass to chain-side gas cost. Internal-only — the
|
|
61
|
+
* field NEVER appears on a route response; the route layer
|
|
62
|
+
* never reads `FilecoinEventPayload`. Phase 7
|
|
63
|
+
* billing/cost-impact-metadata channel for uncertain delete
|
|
64
|
+
* outcomes.
|
|
65
|
+
*/
|
|
66
|
+
deleteTxHash?: string;
|
|
67
|
+
}
|
|
68
|
+
export interface FilecoinEvent {
|
|
69
|
+
event: FilecoinEventName;
|
|
70
|
+
timestamp: string;
|
|
71
|
+
detail: FilecoinEventPayload;
|
|
72
|
+
}
|
|
73
|
+
export interface FilecoinObservabilityConfig {
|
|
74
|
+
enabled: boolean;
|
|
75
|
+
logToStdout: boolean;
|
|
76
|
+
}
|
|
77
|
+
/** Override the module's emission config — used by tests to suppress stdout. */
|
|
78
|
+
export declare function configureFilecoinObservability(config: Partial<FilecoinObservabilityConfig>): void;
|
|
79
|
+
export declare function resetFilecoinObservabilityConfig(): void;
|
|
80
|
+
export declare function isFilecoinObservabilityEnabled(): boolean;
|
|
81
|
+
/**
|
|
82
|
+
* Pure builder — returns the event object without emitting.
|
|
83
|
+
*
|
|
84
|
+
* `detail` is run through `projectPayload` so an object variable carrying extra
|
|
85
|
+
* credential-shaped fields (`raw_storage_metadata`, `proof`,
|
|
86
|
+
* `codec`, …) loses them before the event materialises. Any
|
|
87
|
+
* `errorMessage` is sanitized at the same boundary so call sites
|
|
88
|
+
* are free to pass raw probe/transport messages.
|
|
89
|
+
*/
|
|
90
|
+
export declare function buildFilecoinEvent(event: FilecoinEventName, detail: FilecoinEventPayload): FilecoinEvent;
|
|
91
|
+
export declare function serializeFilecoinEvent(event: FilecoinEvent): string;
|
|
92
|
+
/**
|
|
93
|
+
* Emit a structured event. No-op when observability is disabled.
|
|
94
|
+
* Tests typically call `configureFilecoinObservability({ logToStdout:
|
|
95
|
+
* false })` and spy on `console.log` directly — keeps assertions
|
|
96
|
+
* decoupled from the prefix string.
|
|
97
|
+
*/
|
|
98
|
+
export declare function emitFilecoinEvent(event: FilecoinEventName, detail: FilecoinEventPayload): void;
|
|
99
|
+
/**
|
|
100
|
+
* Bounded-length sanitizer for an error message destined for the
|
|
101
|
+
* event stream. Strips:
|
|
102
|
+
*
|
|
103
|
+
* - `did:key:…` principal-key lookalikes
|
|
104
|
+
* - long base64/base64url runs (UCAN proofs are ~200+ chars)
|
|
105
|
+
* - codec key/nonce/tag JSON fragments
|
|
106
|
+
*
|
|
107
|
+
* Final length-cap protects log volume + acts as a defence in depth
|
|
108
|
+
* if a future error type slips through with a structured payload in
|
|
109
|
+
* its message.
|
|
110
|
+
*/
|
|
111
|
+
export declare function sanitizeErrorMessage(input: unknown): string;
|
|
112
|
+
/**
|
|
113
|
+
* Scheduler error-logger shared by the reconciler's `onError` hook
|
|
114
|
+
* (rev-8 §8). Centralized so a future telemetry sink swap touches
|
|
115
|
+
* one call site.
|
|
116
|
+
*/
|
|
117
|
+
export declare function logReconcilerError(err: unknown): void;
|
|
118
|
+
/**
|
|
119
|
+
* Convert a `raw_storage_pending_since` column value to integer
|
|
120
|
+
* seconds since the row entered `blob_pending`. Rows that never
|
|
121
|
+
* entered `blob_pending` (or were promoted / failed terminally)
|
|
122
|
+
* return `null`.
|
|
123
|
+
*
|
|
124
|
+
* `now` defaults to the wall clock — pass it explicitly in tests for
|
|
125
|
+
* deterministic assertions (no Date.now mocking required).
|
|
126
|
+
*/
|
|
127
|
+
export declare function computePendingAgeSeconds(pendingSince: Date | string | null | undefined, now?: Date): number | null;
|
|
@@ -0,0 +1,200 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Structured observability for the Filecoin raw-storage lifecycle.
|
|
3
|
+
*
|
|
4
|
+
* Mirrors the `audit-events.ts` shape: typed event payloads emitted
|
|
5
|
+
* as single-line JSON to stdout, prefixed with `[FILECOIN]` for grep
|
|
6
|
+
* / log-aggregator filtering. No metrics framework is invented — the
|
|
7
|
+
* implementation uses log-based aggregation because core does not
|
|
8
|
+
* have a metrics seam today. Operators can derive counters, gauges,
|
|
9
|
+
* and histograms from the event stream.
|
|
10
|
+
*
|
|
11
|
+
* Sanitization is the load-bearing invariant: events MUST NOT carry
|
|
12
|
+
* UCAN proofs, principal keys, codec keys, AES-GCM nonces / tags, or
|
|
13
|
+
* any other credential surface. The module enforces this two ways:
|
|
14
|
+
*
|
|
15
|
+
* 1. The typed `FilecoinEventPayload` is a CLOSED record over a
|
|
16
|
+
* small set of allow-listed fields. Callers cannot accidentally
|
|
17
|
+
* pass a wire-shape `raw_storage_metadata` blob.
|
|
18
|
+
* 2. `sanitizeErrorMessage` strips UCAN/`did:key:`/base64-key
|
|
19
|
+
* lookalikes before they enter the event stream. The function
|
|
20
|
+
* is exported so the scheduler's `logReconcilerError` and any
|
|
21
|
+
* future call-site share the same redaction rule.
|
|
22
|
+
*
|
|
23
|
+
* `computePendingAgeSeconds(pendingSince)` is the pure helper for
|
|
24
|
+
* pending-age gauges; it carries a single contract (NULL → null;
|
|
25
|
+
* otherwise integer seconds from the timestamp to `now`) so the
|
|
26
|
+
* metric definition stays in one place.
|
|
27
|
+
*/
|
|
28
|
+
/**
|
|
29
|
+
* TypeScript's `FilecoinEventPayload` shape only narrows callers
|
|
30
|
+
* that pass an object LITERAL. A `detail` variable that satisfies
|
|
31
|
+
* the type but also carries extra credential-shaped fields would
|
|
32
|
+
* otherwise serialize verbatim because TS erases the excess at
|
|
33
|
+
* compile time, not run time. `projectPayload` walks the closed
|
|
34
|
+
* field list and copies ONLY those keys; everything else (planted
|
|
35
|
+
* `raw_storage_metadata`, `proof`, `codec`, etc.) is dropped before
|
|
36
|
+
* the payload ever reaches the event stream. `errorMessage` is
|
|
37
|
+
* additionally run through `sanitizeErrorMessage` here so call sites
|
|
38
|
+
* can pass raw probe/transport messages without re-sanitizing at
|
|
39
|
+
* every emit site.
|
|
40
|
+
*/
|
|
41
|
+
const ALLOWED_PAYLOAD_KEYS = [
|
|
42
|
+
'documentId',
|
|
43
|
+
'userId',
|
|
44
|
+
'provider',
|
|
45
|
+
'statusBefore',
|
|
46
|
+
'statusAfter',
|
|
47
|
+
'claimId',
|
|
48
|
+
'errorCode',
|
|
49
|
+
'errorMessage',
|
|
50
|
+
'durationMs',
|
|
51
|
+
'batchSize',
|
|
52
|
+
'reconcileAttempts',
|
|
53
|
+
'pendingAgeSeconds',
|
|
54
|
+
// Phase 7 billing/cost-impact metadata. Adding this here is
|
|
55
|
+
// the EXPLICIT runtime permission to carry the on-chain
|
|
56
|
+
// `0x…` tx hash on the `filecoin.delete.tombstoned` event —
|
|
57
|
+
// the type-level addition to `FilecoinEventPayload` alone is
|
|
58
|
+
// not enough because `projectPayload` walks the closed
|
|
59
|
+
// runtime list and drops anything not on it. Any other
|
|
60
|
+
// planted field (raw sidecar hints, credentials, vendor
|
|
61
|
+
// responses) still gets stripped.
|
|
62
|
+
'deleteTxHash',
|
|
63
|
+
];
|
|
64
|
+
function projectPayload(detail) {
|
|
65
|
+
const out = {};
|
|
66
|
+
for (const key of ALLOWED_PAYLOAD_KEYS) {
|
|
67
|
+
if (!(key in detail))
|
|
68
|
+
continue;
|
|
69
|
+
const value = detail[key];
|
|
70
|
+
if (value === undefined)
|
|
71
|
+
continue;
|
|
72
|
+
out[key] =
|
|
73
|
+
key === 'errorMessage'
|
|
74
|
+
? sanitizeErrorMessage(value)
|
|
75
|
+
: value;
|
|
76
|
+
}
|
|
77
|
+
return out;
|
|
78
|
+
}
|
|
79
|
+
const DEFAULT_CONFIG = {
|
|
80
|
+
enabled: true,
|
|
81
|
+
logToStdout: true,
|
|
82
|
+
};
|
|
83
|
+
let currentConfig = { ...DEFAULT_CONFIG };
|
|
84
|
+
/** Override the module's emission config — used by tests to suppress stdout. */
|
|
85
|
+
export function configureFilecoinObservability(config) {
|
|
86
|
+
currentConfig = { ...currentConfig, ...config };
|
|
87
|
+
}
|
|
88
|
+
export function resetFilecoinObservabilityConfig() {
|
|
89
|
+
currentConfig = { ...DEFAULT_CONFIG };
|
|
90
|
+
}
|
|
91
|
+
export function isFilecoinObservabilityEnabled() {
|
|
92
|
+
return currentConfig.enabled;
|
|
93
|
+
}
|
|
94
|
+
/**
|
|
95
|
+
* Pure builder — returns the event object without emitting.
|
|
96
|
+
*
|
|
97
|
+
* `detail` is run through `projectPayload` so an object variable carrying extra
|
|
98
|
+
* credential-shaped fields (`raw_storage_metadata`, `proof`,
|
|
99
|
+
* `codec`, …) loses them before the event materialises. Any
|
|
100
|
+
* `errorMessage` is sanitized at the same boundary so call sites
|
|
101
|
+
* are free to pass raw probe/transport messages.
|
|
102
|
+
*/
|
|
103
|
+
export function buildFilecoinEvent(event, detail) {
|
|
104
|
+
return {
|
|
105
|
+
event,
|
|
106
|
+
timestamp: new Date().toISOString(),
|
|
107
|
+
detail: projectPayload(detail),
|
|
108
|
+
};
|
|
109
|
+
}
|
|
110
|
+
export function serializeFilecoinEvent(event) {
|
|
111
|
+
return `[FILECOIN] ${JSON.stringify(event)}`;
|
|
112
|
+
}
|
|
113
|
+
/**
|
|
114
|
+
* Emit a structured event. No-op when observability is disabled.
|
|
115
|
+
* Tests typically call `configureFilecoinObservability({ logToStdout:
|
|
116
|
+
* false })` and spy on `console.log` directly — keeps assertions
|
|
117
|
+
* decoupled from the prefix string.
|
|
118
|
+
*/
|
|
119
|
+
export function emitFilecoinEvent(event, detail) {
|
|
120
|
+
if (!currentConfig.enabled)
|
|
121
|
+
return;
|
|
122
|
+
const built = buildFilecoinEvent(event, detail);
|
|
123
|
+
if (currentConfig.logToStdout) {
|
|
124
|
+
// eslint-disable-next-line no-console
|
|
125
|
+
console.log(serializeFilecoinEvent(built));
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
/**
|
|
129
|
+
* Bounded-length sanitizer for an error message destined for the
|
|
130
|
+
* event stream. Strips:
|
|
131
|
+
*
|
|
132
|
+
* - `did:key:…` principal-key lookalikes
|
|
133
|
+
* - long base64/base64url runs (UCAN proofs are ~200+ chars)
|
|
134
|
+
* - codec key/nonce/tag JSON fragments
|
|
135
|
+
*
|
|
136
|
+
* Final length-cap protects log volume + acts as a defence in depth
|
|
137
|
+
* if a future error type slips through with a structured payload in
|
|
138
|
+
* its message.
|
|
139
|
+
*/
|
|
140
|
+
export function sanitizeErrorMessage(input) {
|
|
141
|
+
const raw = input instanceof Error
|
|
142
|
+
? input.message
|
|
143
|
+
: typeof input === 'string'
|
|
144
|
+
? input
|
|
145
|
+
: '';
|
|
146
|
+
return applyRedactionRules(raw).slice(0, MAX_ERROR_MESSAGE_LEN);
|
|
147
|
+
}
|
|
148
|
+
const MAX_ERROR_MESSAGE_LEN = 200;
|
|
149
|
+
function applyRedactionRules(s) {
|
|
150
|
+
return s
|
|
151
|
+
// `did:key:z…` principal-key identifiers
|
|
152
|
+
.replace(/did:key:[A-Za-z0-9_-]+/g, '[REDACTED_PRINCIPAL]')
|
|
153
|
+
// long base64/base64url runs that look like UCAN proofs
|
|
154
|
+
.replace(/[A-Za-z0-9_+/=-]{40,}/g, '[REDACTED_BASE64]')
|
|
155
|
+
// codec/AES-GCM internal field labels (`key_id`, `nonce`, `tag`)
|
|
156
|
+
// when they appear with a value separator
|
|
157
|
+
.replace(/(key_id|nonce|tag)\s*[:=]\s*\S+/gi, '$1=[REDACTED]')
|
|
158
|
+
// raw-storage env vars that look credential-bearing
|
|
159
|
+
.replace(/RAW_STORAGE_[A-Z0-9_]*(?:PRIVATE_KEY|TOKEN|SECRET|AUTH)[A-Z0-9_]*/g, '[REDACTED_ENV]');
|
|
160
|
+
}
|
|
161
|
+
/**
|
|
162
|
+
* Scheduler error-logger shared by the reconciler's `onError` hook
|
|
163
|
+
* (rev-8 §8). Centralized so a future telemetry sink swap touches
|
|
164
|
+
* one call site.
|
|
165
|
+
*/
|
|
166
|
+
export function logReconcilerError(err) {
|
|
167
|
+
const code = extractErrorCode(err);
|
|
168
|
+
emitFilecoinEvent('filecoin.reconcile.failure', {
|
|
169
|
+
errorCode: code,
|
|
170
|
+
errorMessage: sanitizeErrorMessage(err),
|
|
171
|
+
});
|
|
172
|
+
}
|
|
173
|
+
function extractErrorCode(err) {
|
|
174
|
+
if (err instanceof Error) {
|
|
175
|
+
const candidate = err.code;
|
|
176
|
+
if (typeof candidate === 'string')
|
|
177
|
+
return candidate;
|
|
178
|
+
}
|
|
179
|
+
return 'unknown';
|
|
180
|
+
}
|
|
181
|
+
/**
|
|
182
|
+
* Convert a `raw_storage_pending_since` column value to integer
|
|
183
|
+
* seconds since the row entered `blob_pending`. Rows that never
|
|
184
|
+
* entered `blob_pending` (or were promoted / failed terminally)
|
|
185
|
+
* return `null`.
|
|
186
|
+
*
|
|
187
|
+
* `now` defaults to the wall clock — pass it explicitly in tests for
|
|
188
|
+
* deterministic assertions (no Date.now mocking required).
|
|
189
|
+
*/
|
|
190
|
+
export function computePendingAgeSeconds(pendingSince, now = new Date()) {
|
|
191
|
+
if (pendingSince === null || pendingSince === undefined)
|
|
192
|
+
return null;
|
|
193
|
+
const start = pendingSince instanceof Date ? pendingSince : new Date(pendingSince);
|
|
194
|
+
if (Number.isNaN(start.getTime()))
|
|
195
|
+
return null;
|
|
196
|
+
const ageMs = now.getTime() - start.getTime();
|
|
197
|
+
if (ageMs < 0)
|
|
198
|
+
return 0;
|
|
199
|
+
return Math.floor(ageMs / 1000);
|
|
200
|
+
}
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* First-mention extraction service — produces a chronological list of
|
|
3
|
+
* topic-introduction events from a conversation transcript.
|
|
4
|
+
*
|
|
5
|
+
* One LLM call scans the full transcript and outputs a JSON array of
|
|
6
|
+
* `{topic, turn_id, session_id, anchor_date}` records. The service
|
|
7
|
+
* maps those onto core's stricter `FirstMentionEvent` shape (joining
|
|
8
|
+
* turn_id to memory_id via a caller-supplied map) and persists via
|
|
9
|
+
* `FirstMentionRepository.store`.
|
|
10
|
+
*
|
|
11
|
+
* Best-effort: extraction failures are logged to stderr and produce an
|
|
12
|
+
* empty array. Storage errors are propagated (no silent swallow).
|
|
13
|
+
*
|
|
14
|
+
* Prompts and salvage parser were ported verbatim from the BEAM harness
|
|
15
|
+
* (`atomicmemory-benchmarks/data/exp-stage7-beam-dryrun/lib.ts`) so the
|
|
16
|
+
* core implementation matches the validated extraction behaviour.
|
|
17
|
+
*/
|
|
18
|
+
import { FirstMentionRepository, type FirstMentionEvent } from '../db/repository-first-mentions.js';
|
|
19
|
+
/**
|
|
20
|
+
* Minimal chat-call shape for first-mention extraction.
|
|
21
|
+
*
|
|
22
|
+
* Token usage is intentionally not threaded here: cost telemetry for the
|
|
23
|
+
* underlying LLM call is already emitted from `LLMProvider.chat` (see
|
|
24
|
+
* `src/services/llm.ts` -> `writeCostEvent`). Reading per-call usage at
|
|
25
|
+
* this layer would require widening the LLMProvider.chat return type to
|
|
26
|
+
* include usage and plumbing it through every adapter; until something in
|
|
27
|
+
* the FirstMentionService path actually consumes it, the extra surface
|
|
28
|
+
* area would only invite hardcoded zeros that mislead downstream readers.
|
|
29
|
+
*/
|
|
30
|
+
interface ChatResult {
|
|
31
|
+
text: string;
|
|
32
|
+
}
|
|
33
|
+
type ChatFn = (system: string, user: string, maxTokens: number) => Promise<ChatResult>;
|
|
34
|
+
export declare class FirstMentionService {
|
|
35
|
+
private repo;
|
|
36
|
+
private chatFn;
|
|
37
|
+
constructor(repo: FirstMentionRepository, chatFn: ChatFn);
|
|
38
|
+
/**
|
|
39
|
+
* Extract first-mention events from a conversation transcript and
|
|
40
|
+
* persist them. Returns the parsed events (post-mapping). Best-effort:
|
|
41
|
+
* if the LLM call fails or returns unparseable output the method
|
|
42
|
+
* logs to stderr and returns `[]` without throwing.
|
|
43
|
+
*
|
|
44
|
+
* `memoryIdsByTurnId` provides the mapping the LLM cannot produce —
|
|
45
|
+
* any event whose `turn_id` is not present in the map is dropped.
|
|
46
|
+
*/
|
|
47
|
+
extractAndStore(userId: string, conversationText: string, sourceSite: string, memoryIdsByTurnId: Map<number, string>): Promise<FirstMentionEvent[]>;
|
|
48
|
+
/**
|
|
49
|
+
* Run the extraction LLM call; return parsed array or null on failure.
|
|
50
|
+
*
|
|
51
|
+
* Fail-open by design: a flaky upstream LLM call should not crash the
|
|
52
|
+
* caller's `extractAndStore` invocation; the EO read path treats a
|
|
53
|
+
* missing first-mention list as "no signal" rather than a hard
|
|
54
|
+
* failure. The deliberate fallback is a structured
|
|
55
|
+
* `[first-mention-llm-failed]` log line plus null return so the
|
|
56
|
+
* failure is observable.
|
|
57
|
+
*/
|
|
58
|
+
private invokeLlm;
|
|
59
|
+
/**
|
|
60
|
+
* Map LLM output records onto core's `FirstMentionEvent` shape.
|
|
61
|
+
*
|
|
62
|
+
* `positionInConversation` is the 0-based index in the FINAL turn-id-
|
|
63
|
+
* sorted output, NOT `turn_id` itself. This makes the mapping stable
|
|
64
|
+
* across re-runs even when the LLM emits a slightly different
|
|
65
|
+
* `turn_id` for the same logical topic on a second pass — the
|
|
66
|
+
* `(user_id, memory_id)` UNIQUE constraint in `first_mention_events`
|
|
67
|
+
* skips the duplicate insert, but if `position_in_conversation`
|
|
68
|
+
* tracked `turn_id` directly, an unrelated drift in the second run's
|
|
69
|
+
* turn assignment would mean callers reading the row see whichever
|
|
70
|
+
* turn_id was first written. Encoding position by post-sort index
|
|
71
|
+
* eliminates that variability — read-side ordering is now a stable
|
|
72
|
+
* sequence (0, 1, 2, ...) regardless of which LLM run produced it.
|
|
73
|
+
*/
|
|
74
|
+
private mapToEvents;
|
|
75
|
+
}
|
|
76
|
+
export {};
|