@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,116 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Supplemental extraction coverage for high-signal deterministic facts.
|
|
3
|
+
* Merges quick extractor output into the main LLM extraction result when the
|
|
4
|
+
* supplemental fact adds missing entities, relations, or temporal detail.
|
|
5
|
+
*/
|
|
6
|
+
import { normalizeExtractedFacts } from './fact-normalization.js';
|
|
7
|
+
import { quickExtractFacts } from './quick-extraction.js';
|
|
8
|
+
import { containsRelativeTemporalPhrase } from './relative-temporal.js';
|
|
9
|
+
const LITERAL_DETAIL_PATTERN = /\b(?:necklace|book|books|song|songs|music|musicians|fan|painting|paintings|photo|poster|posters|library|store|decor|furniture|flooring|pet|pets|cat|cats|dog|dogs|guinea pig|turtle|turtles|snake|snakes|workshop|poetry reading|sign|slipper|bowl)\b/i;
|
|
10
|
+
const QUOTED_TEXT_PATTERN = /["“”][^"“”]{2,}["“”]/;
|
|
11
|
+
const TEMPORAL_DETAIL_PATTERN = /\b(last year|last month|last week|last [a-z]+|today|tomorrow|first|second|before|after|deadline|deadlines|timeline|relative to|months later|weeks later|few days ago|for \d+ years?|for three years?|for two years?|for four years?|for five years?)\b/i;
|
|
12
|
+
const EVENT_DETAIL_PATTERN = /\b(?:accepted|interview|internship|mentor(?:ed|ing)?|network(?:ing)?|social media|competition|investor(?:s)?|fashion editors|analytics tools|video presentation|website|collaborat(?:e|ion)|dance class|Shia Labeouf|trip|travel(?:ed|ling)?|retreat|phuket|doctor|doc|check-up|appointment|blog|car mods?|restor(?:e|ed|ing|ation))\b/i;
|
|
13
|
+
export function mergeSupplementalFacts(primaryFacts, conversationText) {
|
|
14
|
+
const merged = [...primaryFacts];
|
|
15
|
+
const supplementalFacts = normalizeExtractedFacts(quickExtractFacts(conversationText));
|
|
16
|
+
for (const fact of supplementalFacts) {
|
|
17
|
+
const upgradeIndex = findUpgradeableFactIndex(merged, fact);
|
|
18
|
+
if (upgradeIndex >= 0) {
|
|
19
|
+
merged[upgradeIndex] = fact;
|
|
20
|
+
continue;
|
|
21
|
+
}
|
|
22
|
+
if (shouldIncludeSupplementalFact(merged, fact)) {
|
|
23
|
+
merged.push(fact);
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
return dedupeByNormalizedFact(merged);
|
|
27
|
+
}
|
|
28
|
+
function shouldIncludeSupplementalFact(existingFacts, candidate) {
|
|
29
|
+
const normalizedFact = normalizeFact(candidate.fact);
|
|
30
|
+
if (existingFacts.some((fact) => normalizeFact(fact.fact) === normalizedFact)) {
|
|
31
|
+
return false;
|
|
32
|
+
}
|
|
33
|
+
const candidateEntities = listNonUserEntities(candidate);
|
|
34
|
+
const candidateShape = buildCoverageShape(candidate);
|
|
35
|
+
const candidateAddsTemporalDetail = hasRelativeTemporalDetail(candidate.fact);
|
|
36
|
+
const candidateAddsLiteralDetail = hasLiteralDetail(candidate.fact);
|
|
37
|
+
const candidateAddsEventDetail = hasEventDetail(candidate.fact);
|
|
38
|
+
if (candidateEntities.length === 0 && !candidateAddsTemporalDetail && !candidateAddsLiteralDetail && !candidateAddsEventDetail) {
|
|
39
|
+
return false;
|
|
40
|
+
}
|
|
41
|
+
const shapeMatches = existingFacts.filter((fact) => buildCoverageShape(fact) === candidateShape);
|
|
42
|
+
if (shapeMatches.length === 0) {
|
|
43
|
+
return true;
|
|
44
|
+
}
|
|
45
|
+
if (!candidateAddsTemporalDetail && !candidateAddsLiteralDetail && !candidateAddsEventDetail) {
|
|
46
|
+
return false;
|
|
47
|
+
}
|
|
48
|
+
if (candidateAddsTemporalDetail) {
|
|
49
|
+
return shapeMatches.every((fact) => !hasRelativeTemporalDetail(fact.fact));
|
|
50
|
+
}
|
|
51
|
+
if (candidateAddsLiteralDetail) {
|
|
52
|
+
return shapeMatches.every((fact) => !hasLiteralDetail(fact.fact));
|
|
53
|
+
}
|
|
54
|
+
if (candidateAddsEventDetail) {
|
|
55
|
+
return shapeMatches.every((fact) => !hasEventDetail(fact.fact));
|
|
56
|
+
}
|
|
57
|
+
return false;
|
|
58
|
+
}
|
|
59
|
+
function findUpgradeableFactIndex(existingFacts, candidate) {
|
|
60
|
+
const candidateEntities = new Set(listNonUserEntities(candidate));
|
|
61
|
+
const candidateRelations = new Set(candidate.relations.map((relation) => relation.type));
|
|
62
|
+
const candidateAddsTemporalDetail = hasRelativeTemporalDetail(candidate.fact);
|
|
63
|
+
const candidateAddsLiteralDetail = hasLiteralDetail(candidate.fact);
|
|
64
|
+
const candidateAddsEventDetail = hasEventDetail(candidate.fact);
|
|
65
|
+
return existingFacts.findIndex((fact) => {
|
|
66
|
+
const existingEntities = listNonUserEntities(fact);
|
|
67
|
+
if (existingEntities.length === 0 || candidateEntities.size <= existingEntities.length) {
|
|
68
|
+
return false;
|
|
69
|
+
}
|
|
70
|
+
const entitiesCovered = existingEntities.every((entity) => candidateEntities.has(entity));
|
|
71
|
+
if (!entitiesCovered) {
|
|
72
|
+
return false;
|
|
73
|
+
}
|
|
74
|
+
const existingRelations = fact.relations.map((relation) => relation.type);
|
|
75
|
+
const relationsCovered = existingRelations.every((relation) => candidateRelations.has(relation));
|
|
76
|
+
if (!relationsCovered) {
|
|
77
|
+
return false;
|
|
78
|
+
}
|
|
79
|
+
if (candidate.fact.length <= fact.fact.length + 10) {
|
|
80
|
+
return false;
|
|
81
|
+
}
|
|
82
|
+
return candidateAddsTemporalDetail
|
|
83
|
+
|| candidateAddsLiteralDetail
|
|
84
|
+
|| candidateAddsEventDetail
|
|
85
|
+
|| !hasRelativeTemporalDetail(fact.fact);
|
|
86
|
+
});
|
|
87
|
+
}
|
|
88
|
+
function buildCoverageShape(fact) {
|
|
89
|
+
const entities = listNonUserEntities(fact).join('|');
|
|
90
|
+
const relations = fact.relations.map((relation) => relation.type).sort().join('|');
|
|
91
|
+
return `${entities}::${relations}`;
|
|
92
|
+
}
|
|
93
|
+
function listNonUserEntities(fact) {
|
|
94
|
+
return [...new Set(fact.entities
|
|
95
|
+
.map((entity) => entity.name.trim().toLowerCase())
|
|
96
|
+
.filter((name) => name && name !== 'user'))].sort();
|
|
97
|
+
}
|
|
98
|
+
function hasRelativeTemporalDetail(text) {
|
|
99
|
+
return TEMPORAL_DETAIL_PATTERN.test(text) || containsRelativeTemporalPhrase(text);
|
|
100
|
+
}
|
|
101
|
+
function hasLiteralDetail(text) {
|
|
102
|
+
return LITERAL_DETAIL_PATTERN.test(text) || QUOTED_TEXT_PATTERN.test(text);
|
|
103
|
+
}
|
|
104
|
+
function hasEventDetail(text) {
|
|
105
|
+
return EVENT_DETAIL_PATTERN.test(text);
|
|
106
|
+
}
|
|
107
|
+
function dedupeByNormalizedFact(facts) {
|
|
108
|
+
const unique = new Map();
|
|
109
|
+
for (const fact of facts) {
|
|
110
|
+
unique.set(normalizeFact(fact.fact), fact);
|
|
111
|
+
}
|
|
112
|
+
return [...unique.values()];
|
|
113
|
+
}
|
|
114
|
+
function normalizeFact(text) {
|
|
115
|
+
return text.toLowerCase().replace(/\s+/g, ' ').trim();
|
|
116
|
+
}
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Typed Belief Calculus (TBC) — Phase 2 executor.
|
|
3
|
+
*
|
|
4
|
+
* Bridges a `BeliefOperationDecision` produced by `decideBeliefOperator`
|
|
5
|
+
* to the existing AUDN ingest pipeline. Affirm / Update / Retract /
|
|
6
|
+
* Supersede route to the standard AUDN executor (`executeAudnDecision`).
|
|
7
|
+
* Promote / Demote / EvidenceFor / Counter are TBC-only and are handled
|
|
8
|
+
* inline against `MemoryStore.updateMemoryMetadata` — no schema change in
|
|
9
|
+
* this phase.
|
|
10
|
+
*
|
|
11
|
+
* Fail-closed: if the LLM resolver throws, the error propagates to the
|
|
12
|
+
* caller. We never fall back to `ADD` silently, matching AUDN semantics.
|
|
13
|
+
*
|
|
14
|
+
* Schema rule: Phase 2 writes belief state into existing JSONB metadata
|
|
15
|
+
* only. No new columns or tables are touched.
|
|
16
|
+
*/
|
|
17
|
+
import { type AudnTraceContext } from './memory-audn.js';
|
|
18
|
+
import { BeliefOperator, type BeliefOperationDecision } from './typed-belief-calculus.js';
|
|
19
|
+
import type { CandidateMemory } from './conflict-policy.js';
|
|
20
|
+
import type { AudnFactContext, FactResult, MemoryServiceDeps, Outcome } from './memory-service-types.js';
|
|
21
|
+
export type BeliefTier = 'standard' | 'directive' | 'demoted' | 'retracted';
|
|
22
|
+
export interface DualWriteEdgeInput {
|
|
23
|
+
userId: string;
|
|
24
|
+
sourceId: string;
|
|
25
|
+
targetId: string;
|
|
26
|
+
edgeType: 'evidence_for' | 'counter' | 'supersedes' | 'promotes' | 'demotes';
|
|
27
|
+
weight: number;
|
|
28
|
+
rationale: string;
|
|
29
|
+
}
|
|
30
|
+
export interface DualWriteColumnUpdate {
|
|
31
|
+
userId: string;
|
|
32
|
+
memoryId: string;
|
|
33
|
+
confidence?: number;
|
|
34
|
+
beliefTier?: BeliefTier;
|
|
35
|
+
mutationType?: BeliefOperator;
|
|
36
|
+
}
|
|
37
|
+
export interface BeliefDualWriteHook {
|
|
38
|
+
appendEdge(input: DualWriteEdgeInput): Promise<void>;
|
|
39
|
+
updateColumns(input: DualWriteColumnUpdate): Promise<void>;
|
|
40
|
+
}
|
|
41
|
+
/** Install a dual-write hook. Pass `undefined` to clear (e.g., in tests). */
|
|
42
|
+
export declare function setBeliefDualWriteHook(hook: BeliefDualWriteHook | undefined): void;
|
|
43
|
+
/** Resolve a TBC decision via the LLM resolver and execute it. */
|
|
44
|
+
export declare function resolveAndExecuteTbc(deps: MemoryServiceDeps, ctx: AudnFactContext, candidates: readonly CandidateMemory[], candidateIds: Set<string>, supersededTargets: Set<string>, traceContext: AudnTraceContext): Promise<FactResult>;
|
|
45
|
+
/** Dispatch a TBC decision to the right executor branch. */
|
|
46
|
+
export declare function executeTbcDecision(deps: MemoryServiceDeps, decision: BeliefOperationDecision, ctx: AudnFactContext, candidateIds: Set<string>): Promise<{
|
|
47
|
+
outcome: Outcome;
|
|
48
|
+
memoryId: string | null;
|
|
49
|
+
}>;
|
|
@@ -0,0 +1,284 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Typed Belief Calculus (TBC) — Phase 2 executor.
|
|
3
|
+
*
|
|
4
|
+
* Bridges a `BeliefOperationDecision` produced by `decideBeliefOperator`
|
|
5
|
+
* to the existing AUDN ingest pipeline. Affirm / Update / Retract /
|
|
6
|
+
* Supersede route to the standard AUDN executor (`executeAudnDecision`).
|
|
7
|
+
* Promote / Demote / EvidenceFor / Counter are TBC-only and are handled
|
|
8
|
+
* inline against `MemoryStore.updateMemoryMetadata` — no schema change in
|
|
9
|
+
* this phase.
|
|
10
|
+
*
|
|
11
|
+
* Fail-closed: if the LLM resolver throws, the error propagates to the
|
|
12
|
+
* caller. We never fall back to `ADD` silently, matching AUDN semantics.
|
|
13
|
+
*
|
|
14
|
+
* Schema rule: Phase 2 writes belief state into existing JSONB metadata
|
|
15
|
+
* only. No new columns or tables are touched.
|
|
16
|
+
*/
|
|
17
|
+
import { timed } from './timing.js';
|
|
18
|
+
// fallow-ignore-next-line circular-dependencies
|
|
19
|
+
import { executeAudnDecision } from './memory-audn.js';
|
|
20
|
+
import { storeCanonicalFact } from './memory-storage.js';
|
|
21
|
+
import { BeliefOperator, decideBeliefOperator, } from './typed-belief-calculus.js';
|
|
22
|
+
const DEMOTE_DELTA_FLOOR = -1.0;
|
|
23
|
+
let dualWriteHook;
|
|
24
|
+
/** Install a dual-write hook. Pass `undefined` to clear (e.g., in tests). */
|
|
25
|
+
export function setBeliefDualWriteHook(hook) {
|
|
26
|
+
dualWriteHook = hook;
|
|
27
|
+
}
|
|
28
|
+
async function dualWriteEdge(input) {
|
|
29
|
+
if (!dualWriteHook)
|
|
30
|
+
return;
|
|
31
|
+
await dualWriteHook.appendEdge(input);
|
|
32
|
+
}
|
|
33
|
+
async function dualWriteColumns(input) {
|
|
34
|
+
if (!dualWriteHook)
|
|
35
|
+
return;
|
|
36
|
+
await dualWriteHook.updateColumns(input);
|
|
37
|
+
}
|
|
38
|
+
/** Resolve a TBC decision via the LLM resolver and execute it. */
|
|
39
|
+
export async function resolveAndExecuteTbc(deps, ctx, candidates, candidateIds, supersededTargets, traceContext) {
|
|
40
|
+
const decision = await timed('ingest.fact.tbc', () => decideBeliefOperator(ctx.fact, candidates));
|
|
41
|
+
const executed = await executeTbcDecision(deps, decision, ctx, candidateIds);
|
|
42
|
+
if (decision.operator === BeliefOperator.Supersede && executed.memoryId) {
|
|
43
|
+
supersededTargets.add(executed.memoryId);
|
|
44
|
+
}
|
|
45
|
+
return {
|
|
46
|
+
...executed,
|
|
47
|
+
embedding: ctx.embedding,
|
|
48
|
+
trace: buildTbcTrace(traceContext, decision, executed),
|
|
49
|
+
};
|
|
50
|
+
}
|
|
51
|
+
/** Dispatch a TBC decision to the right executor branch. */
|
|
52
|
+
export async function executeTbcDecision(deps, decision, ctx, candidateIds) {
|
|
53
|
+
switch (decision.operator) {
|
|
54
|
+
case BeliefOperator.Affirm:
|
|
55
|
+
case BeliefOperator.Update:
|
|
56
|
+
case BeliefOperator.Retract:
|
|
57
|
+
case BeliefOperator.Supersede:
|
|
58
|
+
return executeAudnDecision(deps, toAudnDecision(decision, ctx), candidateIds, ctx);
|
|
59
|
+
case BeliefOperator.Promote:
|
|
60
|
+
return executePromote(deps, decision, ctx);
|
|
61
|
+
case BeliefOperator.Demote:
|
|
62
|
+
return executeDemote(deps, decision, ctx);
|
|
63
|
+
case BeliefOperator.EvidenceFor:
|
|
64
|
+
return executeEdge(deps, decision, ctx, 'evidence_for');
|
|
65
|
+
case BeliefOperator.Counter:
|
|
66
|
+
return executeEdge(deps, decision, ctx, 'counter');
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
/** Build an AUDN-shape decision from a TBC decision for the four shared operators. */
|
|
70
|
+
function toAudnDecision(decision, ctx) {
|
|
71
|
+
const action = mapToAudnAction(decision.operator);
|
|
72
|
+
const targetMemoryId = decision.target_claim_id ?? null;
|
|
73
|
+
const updatedContent = action === 'UPDATE' ? ctx.fact.fact : null;
|
|
74
|
+
return { action, targetMemoryId, updatedContent, contradictionConfidence: null, clarificationNote: null };
|
|
75
|
+
}
|
|
76
|
+
function mapToAudnAction(operator) {
|
|
77
|
+
if (operator === BeliefOperator.Affirm)
|
|
78
|
+
return 'NOOP';
|
|
79
|
+
if (operator === BeliefOperator.Update)
|
|
80
|
+
return 'UPDATE';
|
|
81
|
+
if (operator === BeliefOperator.Retract)
|
|
82
|
+
return 'DELETE';
|
|
83
|
+
if (operator === BeliefOperator.Supersede)
|
|
84
|
+
return 'SUPERSEDE';
|
|
85
|
+
throw new Error(`mapToAudnAction: ${operator} is TBC-only`);
|
|
86
|
+
}
|
|
87
|
+
/** Promote: write directive flag + mutation_type into existing target metadata. */
|
|
88
|
+
async function executePromote(deps, decision, ctx) {
|
|
89
|
+
const targetId = requireTarget(decision, BeliefOperator.Promote);
|
|
90
|
+
const target = await deps.stores.memory.getMemory(targetId, ctx.userId);
|
|
91
|
+
if (!target) {
|
|
92
|
+
return storeCanonicalFact(deps, ctx);
|
|
93
|
+
}
|
|
94
|
+
const current = readBeliefMetadata(target.metadata);
|
|
95
|
+
const nextConfidence = clamp(currentConfidence(current) + Math.max(0, decision.confidence_delta));
|
|
96
|
+
const nextHistory = appendRevision(current.revision_history, {
|
|
97
|
+
operator: BeliefOperator.Promote,
|
|
98
|
+
confidence: nextConfidence,
|
|
99
|
+
content: target.content,
|
|
100
|
+
recordedAt: new Date().toISOString(),
|
|
101
|
+
rationale: decision.rationale,
|
|
102
|
+
});
|
|
103
|
+
await deps.stores.memory.updateMemoryMetadata(ctx.userId, targetId, {
|
|
104
|
+
...target.metadata,
|
|
105
|
+
mutation_type: BeliefOperator.Promote,
|
|
106
|
+
directive: true,
|
|
107
|
+
confidence: nextConfidence,
|
|
108
|
+
revision_history: nextHistory,
|
|
109
|
+
});
|
|
110
|
+
// Phase 3 dual-write: column update + promotes edge from new claim → target
|
|
111
|
+
await dualWriteColumns({
|
|
112
|
+
userId: ctx.userId,
|
|
113
|
+
memoryId: targetId,
|
|
114
|
+
confidence: nextConfidence,
|
|
115
|
+
beliefTier: 'directive',
|
|
116
|
+
mutationType: BeliefOperator.Promote,
|
|
117
|
+
});
|
|
118
|
+
await dualWriteEdge({
|
|
119
|
+
userId: ctx.userId,
|
|
120
|
+
sourceId: targetId,
|
|
121
|
+
targetId,
|
|
122
|
+
edgeType: 'promotes',
|
|
123
|
+
weight: clamp(Math.max(0, decision.confidence_delta), 0, 1),
|
|
124
|
+
rationale: decision.rationale,
|
|
125
|
+
});
|
|
126
|
+
return { outcome: 'updated', memoryId: targetId };
|
|
127
|
+
}
|
|
128
|
+
/** Demote: lower confidence and record the soft-conflict revision. */
|
|
129
|
+
async function executeDemote(deps, decision, ctx) {
|
|
130
|
+
const targetId = requireTarget(decision, BeliefOperator.Demote);
|
|
131
|
+
const target = await deps.stores.memory.getMemory(targetId, ctx.userId);
|
|
132
|
+
if (!target) {
|
|
133
|
+
return storeCanonicalFact(deps, ctx);
|
|
134
|
+
}
|
|
135
|
+
const current = readBeliefMetadata(target.metadata);
|
|
136
|
+
const delta = Math.min(0, Math.max(DEMOTE_DELTA_FLOOR, decision.confidence_delta));
|
|
137
|
+
const nextConfidence = clamp(currentConfidence(current) + delta);
|
|
138
|
+
const nextHistory = appendRevision(current.revision_history, {
|
|
139
|
+
operator: BeliefOperator.Demote,
|
|
140
|
+
confidence: nextConfidence,
|
|
141
|
+
content: target.content,
|
|
142
|
+
recordedAt: new Date().toISOString(),
|
|
143
|
+
rationale: decision.rationale,
|
|
144
|
+
});
|
|
145
|
+
await deps.stores.memory.updateMemoryMetadata(ctx.userId, targetId, {
|
|
146
|
+
...target.metadata,
|
|
147
|
+
mutation_type: BeliefOperator.Demote,
|
|
148
|
+
confidence: nextConfidence,
|
|
149
|
+
revision_history: nextHistory,
|
|
150
|
+
});
|
|
151
|
+
// Phase 3 dual-write: column update + demotes edge with negative weight
|
|
152
|
+
await dualWriteColumns({
|
|
153
|
+
userId: ctx.userId,
|
|
154
|
+
memoryId: targetId,
|
|
155
|
+
confidence: nextConfidence,
|
|
156
|
+
beliefTier: 'demoted',
|
|
157
|
+
mutationType: BeliefOperator.Demote,
|
|
158
|
+
});
|
|
159
|
+
await dualWriteEdge({
|
|
160
|
+
userId: ctx.userId,
|
|
161
|
+
sourceId: targetId,
|
|
162
|
+
targetId,
|
|
163
|
+
edgeType: 'demotes',
|
|
164
|
+
weight: -clamp(Math.abs(delta), 0, 1),
|
|
165
|
+
rationale: decision.rationale,
|
|
166
|
+
});
|
|
167
|
+
return { outcome: 'updated', memoryId: targetId };
|
|
168
|
+
}
|
|
169
|
+
/** EvidenceFor / Counter: append a graph-only edge into the target's metadata. */
|
|
170
|
+
async function executeEdge(deps, decision, ctx, edgeType) {
|
|
171
|
+
const operator = edgeType === 'evidence_for' ? BeliefOperator.EvidenceFor : BeliefOperator.Counter;
|
|
172
|
+
const targetId = requireTarget(decision, operator);
|
|
173
|
+
const target = await deps.stores.memory.getMemory(targetId, ctx.userId);
|
|
174
|
+
if (!target) {
|
|
175
|
+
return storeCanonicalFact(deps, ctx);
|
|
176
|
+
}
|
|
177
|
+
const current = readBeliefMetadata(target.metadata);
|
|
178
|
+
const weight = edgeType === 'evidence_for'
|
|
179
|
+
? clamp(Math.max(0, decision.confidence_delta), 0, 1)
|
|
180
|
+
: -clamp(Math.abs(Math.min(0, decision.confidence_delta)), 0, 1);
|
|
181
|
+
const entry = {
|
|
182
|
+
operator,
|
|
183
|
+
confidence: currentConfidence(current),
|
|
184
|
+
content: null,
|
|
185
|
+
recordedAt: new Date().toISOString(),
|
|
186
|
+
rationale: decision.rationale,
|
|
187
|
+
weight,
|
|
188
|
+
};
|
|
189
|
+
const nextEdges = appendRevision(current.belief_edges, entry);
|
|
190
|
+
await deps.stores.memory.updateMemoryMetadata(ctx.userId, targetId, {
|
|
191
|
+
...target.metadata,
|
|
192
|
+
mutation_type: operator,
|
|
193
|
+
belief_edges: nextEdges,
|
|
194
|
+
});
|
|
195
|
+
// Phase 3 dual-write: typed edge into belief_edges + mutation_type column.
|
|
196
|
+
// Source is the new claim (not yet stored as a row) — for now we record
|
|
197
|
+
// target → target with the rationale; Phase 4 will store the source claim
|
|
198
|
+
// first and link the edge to the new memory row.
|
|
199
|
+
await dualWriteColumns({
|
|
200
|
+
userId: ctx.userId,
|
|
201
|
+
memoryId: targetId,
|
|
202
|
+
mutationType: operator,
|
|
203
|
+
});
|
|
204
|
+
await dualWriteEdge({
|
|
205
|
+
userId: ctx.userId,
|
|
206
|
+
sourceId: targetId,
|
|
207
|
+
targetId,
|
|
208
|
+
edgeType,
|
|
209
|
+
weight,
|
|
210
|
+
rationale: decision.rationale,
|
|
211
|
+
});
|
|
212
|
+
return { outcome: 'updated', memoryId: targetId };
|
|
213
|
+
}
|
|
214
|
+
function readBeliefMetadata(metadata) {
|
|
215
|
+
return metadata;
|
|
216
|
+
}
|
|
217
|
+
function currentConfidence(meta) {
|
|
218
|
+
return typeof meta.confidence === 'number' && Number.isFinite(meta.confidence) ? meta.confidence : 1.0;
|
|
219
|
+
}
|
|
220
|
+
function appendRevision(prior, entry) {
|
|
221
|
+
return [entry, ...(prior ?? [])];
|
|
222
|
+
}
|
|
223
|
+
function clamp(value, min = 0, max = 1) {
|
|
224
|
+
if (!Number.isFinite(value))
|
|
225
|
+
return min;
|
|
226
|
+
return Math.max(min, Math.min(max, value));
|
|
227
|
+
}
|
|
228
|
+
function requireTarget(decision, operator) {
|
|
229
|
+
if (!decision.target_claim_id) {
|
|
230
|
+
throw new Error(`TBC ${operator} requires target_claim_id but resolver returned none`);
|
|
231
|
+
}
|
|
232
|
+
return decision.target_claim_id;
|
|
233
|
+
}
|
|
234
|
+
function reasonCodeForOperator(operator) {
|
|
235
|
+
const map = {
|
|
236
|
+
[BeliefOperator.Affirm]: 'tbc-affirm',
|
|
237
|
+
[BeliefOperator.Update]: 'tbc-update',
|
|
238
|
+
[BeliefOperator.Retract]: 'tbc-retract',
|
|
239
|
+
[BeliefOperator.Supersede]: 'tbc-supersede',
|
|
240
|
+
[BeliefOperator.Promote]: 'tbc-promote',
|
|
241
|
+
[BeliefOperator.Demote]: 'tbc-demote',
|
|
242
|
+
[BeliefOperator.EvidenceFor]: 'tbc-evidence-for',
|
|
243
|
+
[BeliefOperator.Counter]: 'tbc-counter',
|
|
244
|
+
};
|
|
245
|
+
return map[operator];
|
|
246
|
+
}
|
|
247
|
+
function actionForOperator(operator) {
|
|
248
|
+
if (operator === BeliefOperator.Affirm)
|
|
249
|
+
return 'NOOP';
|
|
250
|
+
if (operator === BeliefOperator.Update)
|
|
251
|
+
return 'UPDATE';
|
|
252
|
+
if (operator === BeliefOperator.Retract)
|
|
253
|
+
return 'DELETE';
|
|
254
|
+
if (operator === BeliefOperator.Supersede)
|
|
255
|
+
return 'SUPERSEDE';
|
|
256
|
+
return 'UPDATE';
|
|
257
|
+
}
|
|
258
|
+
function buildTbcTrace(traceContext, decision, result) {
|
|
259
|
+
return {
|
|
260
|
+
factText: traceContext.fact.fact,
|
|
261
|
+
headline: traceContext.fact.headline,
|
|
262
|
+
factType: traceContext.fact.type,
|
|
263
|
+
importance: traceContext.fact.importance,
|
|
264
|
+
...(traceContext.logicalTimestamp ? { logicalTimestamp: traceContext.logicalTimestamp.toISOString() } : {}),
|
|
265
|
+
writeSecurity: {
|
|
266
|
+
allowed: traceContext.writeSecurity.allowed,
|
|
267
|
+
blockedBy: traceContext.writeSecurity.blockedBy,
|
|
268
|
+
trustScore: traceContext.writeSecurity.trust.score,
|
|
269
|
+
},
|
|
270
|
+
...(traceContext.entropyResult ? { entropyGate: traceContext.entropyResult } : {}),
|
|
271
|
+
candidates: traceContext.candidates,
|
|
272
|
+
decision: {
|
|
273
|
+
source: 'tbc',
|
|
274
|
+
action: actionForOperator(decision.operator),
|
|
275
|
+
reasonCode: reasonCodeForOperator(decision.operator),
|
|
276
|
+
targetMemoryId: decision.target_claim_id ?? null,
|
|
277
|
+
candidateIds: traceContext.candidates.map((candidate) => candidate.id),
|
|
278
|
+
beliefOperator: decision.operator,
|
|
279
|
+
},
|
|
280
|
+
outcome: result.outcome,
|
|
281
|
+
memoryId: result.memoryId,
|
|
282
|
+
beliefOperator: decision.operator,
|
|
283
|
+
};
|
|
284
|
+
}
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* BEAM v38: write-time temporal classifier.
|
|
3
|
+
*
|
|
4
|
+
* Given a freshly-extracted memory text plus its observed timestamp, the
|
|
5
|
+
* classifier returns either:
|
|
6
|
+
* - { stateKey, eventStart, eventEnd: null } for stateful facts
|
|
7
|
+
* (e.g. "user lives in Austin", "API response time is 200ms")
|
|
8
|
+
* - null for non-stateful memories (events, one-time mentions)
|
|
9
|
+
*
|
|
10
|
+
* The classifier is a thin LLM wrapper that uses Anthropic forced
|
|
11
|
+
* tool-use for a deterministic JSON output. The prompt is small and
|
|
12
|
+
* cache-friendly. The classifier fails CLOSED — when the LLM call
|
|
13
|
+
* throws, the caller decides whether to abort the ingest or fall
|
|
14
|
+
* through; this module never silently returns null on a transport
|
|
15
|
+
* error. (See `classifyTemporalState` for the exact contract.)
|
|
16
|
+
*/
|
|
17
|
+
/** Output of the classifier when the memory describes a stateful fact. */
|
|
18
|
+
export interface TemporalStateClassification {
|
|
19
|
+
/** Stable identifier for the evolving fact (e.g. `user:1:location`). */
|
|
20
|
+
stateKey: string;
|
|
21
|
+
/** When the fact became true (ISO string at the in-LLM API surface). */
|
|
22
|
+
eventStart: Date;
|
|
23
|
+
/**
|
|
24
|
+
* When the fact stopped being true. Always `null` at classification
|
|
25
|
+
* time — supersede logic lives in `memory-storage.ts`. Kept on the
|
|
26
|
+
* type for callers that destructure the row shape directly.
|
|
27
|
+
*/
|
|
28
|
+
eventEnd: null;
|
|
29
|
+
}
|
|
30
|
+
/** Input bag for `classifyTemporalState`. */
|
|
31
|
+
export interface TemporalClassifyInput {
|
|
32
|
+
/** Extracted memory text (`FactInput.fact`). */
|
|
33
|
+
memoryText: string;
|
|
34
|
+
/**
|
|
35
|
+
* Resolved observed_at for the conversation turn (logical timestamp).
|
|
36
|
+
* Used as the default eventStart when the model does not surface one.
|
|
37
|
+
*/
|
|
38
|
+
observedAt: Date;
|
|
39
|
+
/**
|
|
40
|
+
* Stable per-user namespace used to scope the state_key. The classifier
|
|
41
|
+
* prepends `user:<userId>:` to the model-emitted key so two users with
|
|
42
|
+
* the same key string ("location") don't collide.
|
|
43
|
+
*/
|
|
44
|
+
userId: string;
|
|
45
|
+
/** Anthropic model ID. Pinned by the caller (typically the reflect model). */
|
|
46
|
+
model: string;
|
|
47
|
+
}
|
|
48
|
+
/**
|
|
49
|
+
* Classify a single memory. Returns `null` for non-stateful memories or
|
|
50
|
+
* when the classifier rejects the model output (empty/invalid key).
|
|
51
|
+
*
|
|
52
|
+
* Throws on transport / API failures so the caller can fail closed.
|
|
53
|
+
*/
|
|
54
|
+
export declare function classifyTemporalState(input: TemporalClassifyInput): Promise<TemporalStateClassification | null>;
|
|
55
|
+
/** Scope an LLM-emitted slug into the per-user namespace. */
|
|
56
|
+
export declare function scopedKey(userId: string, slug: string): string;
|
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* BEAM v38: write-time temporal classifier.
|
|
3
|
+
*
|
|
4
|
+
* Given a freshly-extracted memory text plus its observed timestamp, the
|
|
5
|
+
* classifier returns either:
|
|
6
|
+
* - { stateKey, eventStart, eventEnd: null } for stateful facts
|
|
7
|
+
* (e.g. "user lives in Austin", "API response time is 200ms")
|
|
8
|
+
* - null for non-stateful memories (events, one-time mentions)
|
|
9
|
+
*
|
|
10
|
+
* The classifier is a thin LLM wrapper that uses Anthropic forced
|
|
11
|
+
* tool-use for a deterministic JSON output. The prompt is small and
|
|
12
|
+
* cache-friendly. The classifier fails CLOSED — when the LLM call
|
|
13
|
+
* throws, the caller decides whether to abort the ingest or fall
|
|
14
|
+
* through; this module never silently returns null on a transport
|
|
15
|
+
* error. (See `classifyTemporalState` for the exact contract.)
|
|
16
|
+
*/
|
|
17
|
+
import { callAnthropicTool } from './llm.js';
|
|
18
|
+
const SYSTEM_PROMPT = `You are a temporal-state classifier. Given one extracted memory and the date it was observed, decide whether the memory describes a STATEFUL fact (an evolving value of some attribute for some subject) or a NON_STATEFUL event/mention/summary.
|
|
19
|
+
|
|
20
|
+
STATEFUL examples:
|
|
21
|
+
"User lives in Austin, TX" → { kind: stateful, state_key: "location" }
|
|
22
|
+
"Alice's job title is Staff Engineer" → { kind: stateful, state_key: "job.title" }
|
|
23
|
+
"Dashboard API response time is 200ms" → { kind: stateful, state_key: "api.dashboard.response_time" }
|
|
24
|
+
"User's current diet is vegetarian" → { kind: stateful, state_key: "diet" }
|
|
25
|
+
"Project lead is Bob" → { kind: stateful, state_key: "project.lead" }
|
|
26
|
+
|
|
27
|
+
NON_STATEFUL examples:
|
|
28
|
+
"User flew to Tokyo last week" → { kind: non_stateful } (one-time event)
|
|
29
|
+
"Asked about pricing on March 3rd" → { kind: non_stateful }
|
|
30
|
+
"Discussed AUDN architecture in the standup" → { kind: non_stateful }
|
|
31
|
+
"Mentioned that Q3 was tough" → { kind: non_stateful }
|
|
32
|
+
|
|
33
|
+
Rules:
|
|
34
|
+
- state_key must be a slug: lowercase ascii letters, digits, underscores, and dots only.
|
|
35
|
+
- state_key names the ATTRIBUTE, not the value. "lives in Austin" → "location", not "austin".
|
|
36
|
+
- event_start_iso, when surfaced, must be ISO-8601 with timezone. Leave empty when unsure.
|
|
37
|
+
- Be conservative: prefer non_stateful when the memory could be either.`;
|
|
38
|
+
const TOOL_SCHEMA = {
|
|
39
|
+
name: 'emit_temporal_state',
|
|
40
|
+
description: 'Emit the classifier output as structured JSON.',
|
|
41
|
+
input_schema: {
|
|
42
|
+
type: 'object',
|
|
43
|
+
properties: {
|
|
44
|
+
kind: { type: 'string', enum: ['stateful', 'non_stateful'] },
|
|
45
|
+
state_key: { type: 'string' },
|
|
46
|
+
event_start_iso: { type: 'string' },
|
|
47
|
+
rationale: { type: 'string' },
|
|
48
|
+
},
|
|
49
|
+
required: ['kind', 'state_key', 'event_start_iso', 'rationale'],
|
|
50
|
+
},
|
|
51
|
+
};
|
|
52
|
+
// Slug: lowercase ascii + digits + underscore, joined by dots.
|
|
53
|
+
const SLUG_PATTERN = /^[a-z0-9_]+(?:\.[a-z0-9_]+)*$/;
|
|
54
|
+
/**
|
|
55
|
+
* Classify a single memory. Returns `null` for non-stateful memories or
|
|
56
|
+
* when the classifier rejects the model output (empty/invalid key).
|
|
57
|
+
*
|
|
58
|
+
* Throws on transport / API failures so the caller can fail closed.
|
|
59
|
+
*/
|
|
60
|
+
export async function classifyTemporalState(input) {
|
|
61
|
+
const userMessage = buildUserMessage(input);
|
|
62
|
+
const output = await callAnthropicTool(input.model, SYSTEM_PROMPT, userMessage, TOOL_SCHEMA);
|
|
63
|
+
return interpretToolOutput(output, input);
|
|
64
|
+
}
|
|
65
|
+
function buildUserMessage(input) {
|
|
66
|
+
const isoObserved = input.observedAt.toISOString();
|
|
67
|
+
return `Observed at: ${isoObserved}\nMemory: ${input.memoryText}\n\nReturn STATEFUL only when this memory describes a value that can later change. Otherwise NON_STATEFUL.`;
|
|
68
|
+
}
|
|
69
|
+
function interpretToolOutput(output, input) {
|
|
70
|
+
if (output.kind !== 'stateful')
|
|
71
|
+
return null;
|
|
72
|
+
const rawKey = (output.state_key ?? '').trim().toLowerCase();
|
|
73
|
+
if (!rawKey || !SLUG_PATTERN.test(rawKey))
|
|
74
|
+
return null;
|
|
75
|
+
const eventStart = parseIso(output.event_start_iso) ?? input.observedAt;
|
|
76
|
+
return {
|
|
77
|
+
stateKey: scopedKey(input.userId, rawKey),
|
|
78
|
+
eventStart,
|
|
79
|
+
eventEnd: null,
|
|
80
|
+
};
|
|
81
|
+
}
|
|
82
|
+
function parseIso(value) {
|
|
83
|
+
if (!value)
|
|
84
|
+
return null;
|
|
85
|
+
const trimmed = value.trim();
|
|
86
|
+
if (!trimmed)
|
|
87
|
+
return null;
|
|
88
|
+
const date = new Date(trimmed);
|
|
89
|
+
return Number.isNaN(date.getTime()) ? null : date;
|
|
90
|
+
}
|
|
91
|
+
/** Scope an LLM-emitted slug into the per-user namespace. */
|
|
92
|
+
export function scopedKey(userId, slug) {
|
|
93
|
+
return `user:${userId}:${slug}`;
|
|
94
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Query-aware temporal evidence formatting.
|
|
3
|
+
*
|
|
4
|
+
* Produces compact date-bearing evidence blocks for temporal questions. For
|
|
5
|
+
* repeated-event comparisons it emits explicit first/second endpoints; for
|
|
6
|
+
* broader temporal questions it emits a small set of high-overlap candidate
|
|
7
|
+
* memories with their dates.
|
|
8
|
+
*/
|
|
9
|
+
import type { SearchResult } from '../db/memory-repository.js';
|
|
10
|
+
export declare function buildTemporalEvidenceBlock(memories: SearchResult[], query: string): string;
|
|
11
|
+
/** Build endpoint lines for repeated-event temporal comparisons. */
|
|
12
|
+
export declare function buildRepeatedEventEndpointBlock(memories: SearchResult[], query: string): string;
|