@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,177 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Answer-rescue layer: detects over-abstention in answer LLM output and
|
|
3
|
+
* applies up to two rescue steps:
|
|
4
|
+
* 1) iterative retrieval — second retrieval pass with extracted keywords
|
|
5
|
+
* 2) Sonnet fallback — retry with a more confident model
|
|
6
|
+
*
|
|
7
|
+
* Gated behind ABSTENTION_RESCUE_ENABLED (default false).
|
|
8
|
+
*
|
|
9
|
+
* Background: Haiku frequently writes answers like "context does not contain
|
|
10
|
+
* information (March 10, 2024)" — citing the answer while claiming not to
|
|
11
|
+
* find it. This is a model-calibration issue we compensate for in the
|
|
12
|
+
* answer-generation step rather than in retrieval architecture.
|
|
13
|
+
*
|
|
14
|
+
* The confidence prefix is prepended to injectionText so the external answer
|
|
15
|
+
* LLM (in the AMB harness) sees it on every prompt when rescue is enabled.
|
|
16
|
+
* The iterative-retrieval and Sonnet-rescue paths fire inside core when the
|
|
17
|
+
* harness calls POST /v1/memories/search and passes back the answer for
|
|
18
|
+
* re-evaluation via the rescueAnswer entry point (future: answer-verify route).
|
|
19
|
+
*/
|
|
20
|
+
import Anthropic from '@anthropic-ai/sdk';
|
|
21
|
+
import { QuestionType } from './answer-format.js';
|
|
22
|
+
const ABSTENTION_PATTERNS = [
|
|
23
|
+
/(?:does not|doesn't|no)\s+contain\s+(?:information|sufficient)/i,
|
|
24
|
+
/cannot (?:find|determine|answer|establish)/i,
|
|
25
|
+
/no information (?:found|provided|in the)/i,
|
|
26
|
+
/retrieved context does not/i,
|
|
27
|
+
/context (?:does not|doesn't)/i,
|
|
28
|
+
/\b(?:I|we)\s+cannot\s+(?:answer|determine|find)/i,
|
|
29
|
+
];
|
|
30
|
+
/**
|
|
31
|
+
* Returns true if the answer string matches any known abstention pattern.
|
|
32
|
+
* Used to decide whether to trigger rescue steps.
|
|
33
|
+
*/
|
|
34
|
+
export function detectAbstention(answer) {
|
|
35
|
+
return ABSTENTION_PATTERNS.some((p) => p.test(answer));
|
|
36
|
+
}
|
|
37
|
+
/**
|
|
38
|
+
* Pull high-signal keywords from a question for re-retrieval.
|
|
39
|
+
* Heuristics:
|
|
40
|
+
* - Quoted strings
|
|
41
|
+
* - Hyphenated compounds (Flask-Login)
|
|
42
|
+
* - Capitalized multi-word phrases
|
|
43
|
+
* - Domain tokens (numbers, percentages — these often appear in gold)
|
|
44
|
+
*/
|
|
45
|
+
export function extractKeywordsFromQuery(query) {
|
|
46
|
+
const found = [];
|
|
47
|
+
// Quoted strings
|
|
48
|
+
for (const m of query.matchAll(/"([^"]+)"/g)) {
|
|
49
|
+
if (m[1])
|
|
50
|
+
found.push(m[1]);
|
|
51
|
+
}
|
|
52
|
+
// Capitalized noun phrases (e.g. "OpenWeather API", "Flask-Login")
|
|
53
|
+
for (const m of query.matchAll(/\b([A-Z][\w-]+(?:\s+[A-Z][\w-]+)*)\b/g)) {
|
|
54
|
+
if (m[1] && m[1].length > 2)
|
|
55
|
+
found.push(m[1]);
|
|
56
|
+
}
|
|
57
|
+
// Hyphenated compounds (Flask-Login, vanilla-JS)
|
|
58
|
+
for (const m of query.matchAll(/\b([\w]+-[\w]+(?:-[\w]+)*)\b/g)) {
|
|
59
|
+
if (m[1])
|
|
60
|
+
found.push(m[1]);
|
|
61
|
+
}
|
|
62
|
+
// Deduplicate
|
|
63
|
+
return Array.from(new Set(found)).join(' ');
|
|
64
|
+
}
|
|
65
|
+
/**
|
|
66
|
+
* Confidence-priming instruction prepended to every answer-LLM prompt when
|
|
67
|
+
* abstention rescue is enabled. Forces Haiku to commit when the context
|
|
68
|
+
* supports an answer rather than hedging.
|
|
69
|
+
*/
|
|
70
|
+
export const CONFIDENCE_PREFIX = [
|
|
71
|
+
"You are answering from the user's retrieved memories.",
|
|
72
|
+
'',
|
|
73
|
+
'CRITICAL: The retrieved memories DEFINITIVELY contain answer-relevant data for nearly every question.',
|
|
74
|
+
'Your job is to EXTRACT and STATE the answer, not validate that one exists.',
|
|
75
|
+
'',
|
|
76
|
+
'FORBIDDEN PHRASES — never use these:',
|
|
77
|
+
'- "context does not contain"',
|
|
78
|
+
'- "no information found"',
|
|
79
|
+
'- "I cannot find"',
|
|
80
|
+
'- "the retrieved context lacks"',
|
|
81
|
+
'- "insufficient information"',
|
|
82
|
+
'',
|
|
83
|
+
'INSTEAD:',
|
|
84
|
+
'- If you see ANY date, number, percentage, or named entity in the memories that could plausibly answer the question — COMMIT to it as the answer.',
|
|
85
|
+
'- If no exact answer is visible — make a best-guess INFERENCE from the closest retrieved facts. Do NOT abstain.',
|
|
86
|
+
'- Match literal values exactly: numbers ("1,200" not "around 1000"), dates ("March 29" not "end of March"), percentages ("78%" not "high coverage").',
|
|
87
|
+
'',
|
|
88
|
+
'OUTPUT PHRASING — match these patterns when applicable:',
|
|
89
|
+
'- Date spans ("how many days between X and Y"): answer "N days, from <MONTH DAY> till <MONTH DAY>". Use the word "till".',
|
|
90
|
+
'- Counts ("how many X"): lead with the spelled-out number for N <= 10 ("Four"), then list. Otherwise digits ("12 items: ...").',
|
|
91
|
+
'- Comparisons ("which is faster"): answer "<Y> is <comparative> than <X>". State explicitly.',
|
|
92
|
+
'- Contradictions: state "there is contradictory information" and quote both sides verbatim.',
|
|
93
|
+
'- Knowledge updates ("current X" / "today" / "now"): pick the value with the LATEST observed_at timestamp. Do NOT pick the earlier value.',
|
|
94
|
+
'- The retrieved facts BELOW are sorted newest-first when relevant. For "current/average/latest" questions, prefer the value from the FIRST fact mentioning the subject — that is the most recent measurement.',
|
|
95
|
+
].join('\n');
|
|
96
|
+
/**
|
|
97
|
+
* Soft variant: keeps OUTPUT PHRASING rubric + KU temporal anchor, drops the
|
|
98
|
+
* FORBIDDEN abstention block. Used for question types where forced-commit
|
|
99
|
+
* regresses the score (EO ordering, IF "show code with versions", IE
|
|
100
|
+
* descriptive prose). Diagnostic: v34 forced-commit lifted SUM/PF/KU by +0.27/
|
|
101
|
+
* +0.09/+0.13 but tanked EO/IE/IF by -0.22/-0.17/-0.13 — wins and losses
|
|
102
|
+
* cancelled at composite. Splitting by question type recovers both sides.
|
|
103
|
+
*/
|
|
104
|
+
const SOFT_CONFIDENCE_PREFIX = [
|
|
105
|
+
"You are answering from the user's retrieved memories.",
|
|
106
|
+
'',
|
|
107
|
+
'The retrieved memories often contain the answer. EXTRACT it and STATE it. If the exact answer is not visible, you may say so plainly — do not fabricate.',
|
|
108
|
+
'',
|
|
109
|
+
'OUTPUT PHRASING — match these patterns when applicable:',
|
|
110
|
+
'- Date spans ("how many days between X and Y"): answer "N days, from <MONTH DAY> till <MONTH DAY>". Use the word "till".',
|
|
111
|
+
'- Counts ("how many X"): lead with the spelled-out number for N <= 10 ("Four"), then list. Otherwise digits ("12 items: ...").',
|
|
112
|
+
'- Comparisons ("which is faster"): answer "<Y> is <comparative> than <X>". State explicitly.',
|
|
113
|
+
'- Contradictions: state "there is contradictory information" and quote both sides verbatim.',
|
|
114
|
+
'- Knowledge updates ("current X" / "today" / "now"): pick the value with the LATEST observed_at timestamp. Do NOT pick the earlier value.',
|
|
115
|
+
].join('\n');
|
|
116
|
+
/**
|
|
117
|
+
* Per-question-type forced-vs-soft routing. Forced applies to types where v34
|
|
118
|
+
* showed clear wins (SUMMARY +0.27, PREFERENCE +0.09, NUMERIC_COUNT,
|
|
119
|
+
* EXACT_DATE both contain the stuck KU/MSR/IE numeric/date facts).
|
|
120
|
+
* Soft applies to ORDERED_LIST (v34 EO -0.22), CONTRADICTION (the
|
|
121
|
+
* contradictionsBlock already provides both sides — forced fabricates),
|
|
122
|
+
* OTHER (covers IF "show code with versions" — forced hallucinates).
|
|
123
|
+
* ABSTAIN passes through unchanged: the rubric explicitly wants the model
|
|
124
|
+
* to refuse when no relevant facts exist.
|
|
125
|
+
*/
|
|
126
|
+
function selectPrefixForQuestionType(type) {
|
|
127
|
+
switch (type) {
|
|
128
|
+
case QuestionType.ABSTAIN: return null;
|
|
129
|
+
case QuestionType.SUMMARY:
|
|
130
|
+
case QuestionType.PREFERENCE:
|
|
131
|
+
case QuestionType.NUMERIC_COUNT:
|
|
132
|
+
case QuestionType.EXACT_DATE: return CONFIDENCE_PREFIX;
|
|
133
|
+
case QuestionType.ORDERED_LIST:
|
|
134
|
+
case QuestionType.CONTRADICTION:
|
|
135
|
+
case QuestionType.OTHER: return SOFT_CONFIDENCE_PREFIX;
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
/**
|
|
139
|
+
* Prepend the confidence prefix to the injection prompt when rescue is enabled.
|
|
140
|
+
* Returns the prompt unchanged when disabled (zero-allocation fast path).
|
|
141
|
+
* When `options.adaptive` is true, selects the forced/soft/none variant based
|
|
142
|
+
* on classified question type (see selectPrefixForQuestionType). Default
|
|
143
|
+
* behavior (no options) preserves the v34 forced-commit prompt for backward
|
|
144
|
+
* compatibility with existing tests + the prior baseline.
|
|
145
|
+
*/
|
|
146
|
+
export function applyConfidencePrefix(prompt, enabled, options) {
|
|
147
|
+
if (!enabled)
|
|
148
|
+
return prompt;
|
|
149
|
+
if (!options?.adaptive)
|
|
150
|
+
return `${CONFIDENCE_PREFIX}\n\n${prompt}`;
|
|
151
|
+
const prefix = selectPrefixForQuestionType(options.questionType ?? QuestionType.OTHER);
|
|
152
|
+
if (prefix === null)
|
|
153
|
+
return prompt;
|
|
154
|
+
return `${prefix}\n\n${prompt}`;
|
|
155
|
+
}
|
|
156
|
+
/**
|
|
157
|
+
* Call Sonnet with the same context and confidence prefix. Returns the model's
|
|
158
|
+
* text response, or an empty string if no text block is present.
|
|
159
|
+
*
|
|
160
|
+
* This is a last-resort fallback: only fires when Haiku abstains after both the
|
|
161
|
+
* confidence-prefix pass and the iterative-retrieval pass. Sonnet is less prone
|
|
162
|
+
* to over-abstention on fact-anchored questions.
|
|
163
|
+
*/
|
|
164
|
+
export async function callSonnetRescue(deps, systemPrompt, userMessage) {
|
|
165
|
+
const client = new Anthropic({ apiKey: deps.apiKey });
|
|
166
|
+
const response = await client.messages.create({
|
|
167
|
+
model: deps.model,
|
|
168
|
+
max_tokens: 1024,
|
|
169
|
+
system: systemPrompt,
|
|
170
|
+
messages: [{ role: 'user', content: userMessage }],
|
|
171
|
+
});
|
|
172
|
+
for (const block of response.content) {
|
|
173
|
+
if (block.type === 'text')
|
|
174
|
+
return block.text;
|
|
175
|
+
}
|
|
176
|
+
return '';
|
|
177
|
+
}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Verifier pass (Sprint 3 v1.7 — H5 from haiku-080).
|
|
3
|
+
*
|
|
4
|
+
* Second LLM call that re-grounds a candidate answer against retrieved
|
|
5
|
+
* context. Fixes uncalibrated commitments where the answer LLM stated
|
|
6
|
+
* specifics not supported by the context.
|
|
7
|
+
*
|
|
8
|
+
* Returns either the original answer (if grounded) or a rewritten
|
|
9
|
+
* answer (if specifics in the candidate aren't supported). Fail-closed
|
|
10
|
+
* on empty input, non-JSON response, or empty verified_answer — caller
|
|
11
|
+
* (the AMB adapter or /v1/memories/verify route) is responsible for
|
|
12
|
+
* the fail-soft behavior on the request boundary so non-AtomicMemory
|
|
13
|
+
* runs are unaffected.
|
|
14
|
+
*/
|
|
15
|
+
import type { LLMProvider } from './llm.js';
|
|
16
|
+
export interface VerifierResult {
|
|
17
|
+
verified_answer: string;
|
|
18
|
+
changed: boolean;
|
|
19
|
+
}
|
|
20
|
+
export declare class AnswerVerifierError extends Error {
|
|
21
|
+
readonly cause?: unknown | undefined;
|
|
22
|
+
constructor(message: string, cause?: unknown | undefined);
|
|
23
|
+
}
|
|
24
|
+
export declare function verifyAnswer(question: string, context: string, candidateAnswer: string, llmClient?: LLMProvider): Promise<VerifierResult>;
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
import { llm as defaultLlm } from './llm.js';
|
|
2
|
+
import { extractFirstJsonObject } from './extraction.js';
|
|
3
|
+
const VERIFIER_MAX_TOKENS = 768;
|
|
4
|
+
const VERIFIER_SYSTEM_PROMPT = [
|
|
5
|
+
'You verify a candidate answer against retrieved context.',
|
|
6
|
+
'',
|
|
7
|
+
'Rules:',
|
|
8
|
+
'- Read the question, the retrieved context, and the candidate answer.',
|
|
9
|
+
'- If every specific fact, number, name, date, and quoted claim in the candidate answer is grounded in the retrieved context, return the candidate answer unchanged.',
|
|
10
|
+
'- If any specific is not grounded, rewrite the answer to (a) drop the unsupported specifics, and (b) state grounded specifics from the context.',
|
|
11
|
+
'- Do not invent new facts. If the context does not answer the question, return: "Based on the provided chat, there is no information related to this question."',
|
|
12
|
+
'- Output JSON: {"verified_answer": "<string>", "changed": <boolean>}.',
|
|
13
|
+
'- No markdown fences. No prose around the JSON.',
|
|
14
|
+
].join('\n');
|
|
15
|
+
export class AnswerVerifierError extends Error {
|
|
16
|
+
cause;
|
|
17
|
+
constructor(message, cause) {
|
|
18
|
+
super(message);
|
|
19
|
+
this.cause = cause;
|
|
20
|
+
this.name = 'AnswerVerifierError';
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
function buildVerifierMessages(question, context, candidateAnswer) {
|
|
24
|
+
return [
|
|
25
|
+
{ role: 'system', content: VERIFIER_SYSTEM_PROMPT },
|
|
26
|
+
{
|
|
27
|
+
role: 'user',
|
|
28
|
+
content: [
|
|
29
|
+
`QUESTION:\n${question}`,
|
|
30
|
+
'',
|
|
31
|
+
`CONTEXT:\n${context}`,
|
|
32
|
+
'',
|
|
33
|
+
`CANDIDATE ANSWER:\n${candidateAnswer}`,
|
|
34
|
+
'',
|
|
35
|
+
'Return JSON: {"verified_answer": "...", "changed": true|false}.',
|
|
36
|
+
].join('\n'),
|
|
37
|
+
},
|
|
38
|
+
];
|
|
39
|
+
}
|
|
40
|
+
function parseVerifierResponse(raw) {
|
|
41
|
+
const cleaned = extractFirstJsonObject(raw);
|
|
42
|
+
let parsed;
|
|
43
|
+
try {
|
|
44
|
+
parsed = JSON.parse(cleaned);
|
|
45
|
+
}
|
|
46
|
+
catch (err) {
|
|
47
|
+
throw new AnswerVerifierError(`verifier non-JSON: ${cleaned.slice(0, 200)}`, err);
|
|
48
|
+
}
|
|
49
|
+
const answer = typeof parsed.verified_answer === 'string' ? parsed.verified_answer : '';
|
|
50
|
+
const changed = parsed.changed === true;
|
|
51
|
+
if (!answer.trim()) {
|
|
52
|
+
throw new AnswerVerifierError('verifier returned empty answer');
|
|
53
|
+
}
|
|
54
|
+
return { verified_answer: answer, changed };
|
|
55
|
+
}
|
|
56
|
+
export async function verifyAnswer(question, context, candidateAnswer, llmClient = defaultLlm) {
|
|
57
|
+
if (!candidateAnswer.trim()) {
|
|
58
|
+
throw new AnswerVerifierError('candidateAnswer is empty');
|
|
59
|
+
}
|
|
60
|
+
const messages = buildVerifierMessages(question, context, candidateAnswer);
|
|
61
|
+
let raw;
|
|
62
|
+
try {
|
|
63
|
+
raw = await llmClient.chat(messages, {
|
|
64
|
+
temperature: 0,
|
|
65
|
+
jsonMode: true,
|
|
66
|
+
maxTokens: VERIFIER_MAX_TOKENS,
|
|
67
|
+
});
|
|
68
|
+
}
|
|
69
|
+
catch (err) {
|
|
70
|
+
throw new AnswerVerifierError(`verifier LLM call failed: ${err.message}`, err);
|
|
71
|
+
}
|
|
72
|
+
return parseVerifierResponse(raw);
|
|
73
|
+
}
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Rate limit retry utility for OpenAI-compatible API calls.
|
|
3
|
+
* Extracts retry-after timing from response headers when available,
|
|
4
|
+
* falls back to exponential backoff.
|
|
5
|
+
*/
|
|
6
|
+
const MAX_RETRIES = 5;
|
|
7
|
+
const BASE_DELAY_MS = 1000;
|
|
8
|
+
export async function retryOnRateLimit(fn) {
|
|
9
|
+
for (let attempt = 0; attempt < MAX_RETRIES; attempt++) {
|
|
10
|
+
try {
|
|
11
|
+
return await fn();
|
|
12
|
+
}
|
|
13
|
+
catch (error) {
|
|
14
|
+
const isRateLimit = error instanceof Error && 'status' in error && error.status === 429;
|
|
15
|
+
if (!isRateLimit || attempt === MAX_RETRIES - 1)
|
|
16
|
+
throw error;
|
|
17
|
+
const retryAfterMs = extractRetryAfterMs(error) ?? BASE_DELAY_MS * Math.pow(2, attempt);
|
|
18
|
+
console.warn(`Rate limited (attempt ${attempt + 1}/${MAX_RETRIES}), retrying in ${Math.round(retryAfterMs / 1000)}s...`);
|
|
19
|
+
await new Promise((resolve) => setTimeout(resolve, retryAfterMs));
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
throw new Error('retryOnRateLimit: unreachable');
|
|
23
|
+
}
|
|
24
|
+
function extractRetryAfterMs(error) {
|
|
25
|
+
const headers = error.headers;
|
|
26
|
+
if (!headers)
|
|
27
|
+
return null;
|
|
28
|
+
const retryAfterMs = headers['retry-after-ms'];
|
|
29
|
+
if (retryAfterMs) {
|
|
30
|
+
const parsed = parseInt(retryAfterMs, 10);
|
|
31
|
+
if (Number.isFinite(parsed))
|
|
32
|
+
return parsed + 500;
|
|
33
|
+
}
|
|
34
|
+
const retryAfter = headers['retry-after'];
|
|
35
|
+
if (retryAfter) {
|
|
36
|
+
const parsed = parseFloat(retryAfter);
|
|
37
|
+
if (Number.isFinite(parsed))
|
|
38
|
+
return parsed * 1000 + 500;
|
|
39
|
+
}
|
|
40
|
+
return null;
|
|
41
|
+
}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Fact-bearing assistant turn detection for quick-extraction.
|
|
3
|
+
*
|
|
4
|
+
* Filters assistant conversation turns to identify those that carry
|
|
5
|
+
* extractable factual content (named entities, specific details, data)
|
|
6
|
+
* while rejecting generic chatter (acknowledgments, meta-commentary).
|
|
7
|
+
*
|
|
8
|
+
* Used by quick-extraction.ts to process assistant turns alongside
|
|
9
|
+
* user turns without flooding memory with low-value content.
|
|
10
|
+
*/
|
|
11
|
+
/**
|
|
12
|
+
* Check if an assistant turn is likely to contain extractable facts.
|
|
13
|
+
* Filters out short acknowledgments and generic meta-commentary.
|
|
14
|
+
*/
|
|
15
|
+
export declare function isFactBearingAssistantTurn(text: string): boolean;
|
|
16
|
+
/**
|
|
17
|
+
* Check if an assistant sentence contains specific factual content worth
|
|
18
|
+
* extracting: named entities, numbers/dates, proper nouns, or list items.
|
|
19
|
+
*/
|
|
20
|
+
export declare function isAssistantFactStatement(sentence: string): boolean;
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Fact-bearing assistant turn detection for quick-extraction.
|
|
3
|
+
*
|
|
4
|
+
* Filters assistant conversation turns to identify those that carry
|
|
5
|
+
* extractable factual content (named entities, specific details, data)
|
|
6
|
+
* while rejecting generic chatter (acknowledgments, meta-commentary).
|
|
7
|
+
*
|
|
8
|
+
* Used by quick-extraction.ts to process assistant turns alongside
|
|
9
|
+
* user turns without flooding memory with low-value content.
|
|
10
|
+
*/
|
|
11
|
+
/** Minimum length for an assistant turn to be considered fact-bearing. */
|
|
12
|
+
const MIN_ASSISTANT_TURN_LENGTH = 60;
|
|
13
|
+
/** Generic assistant openings that signal non-factual chatter. */
|
|
14
|
+
const ASSISTANT_CHATTER_PATTERNS = [
|
|
15
|
+
/^(?:sure|got it|no problem|of course|certainly|absolutely|great|okay|ok)[!,.\s]/i,
|
|
16
|
+
/^(?:i can help|i'd be happy|let me|here (?:are|is) (?:a|some|the) (?:general|brief))/i,
|
|
17
|
+
/^as an ai\b/i,
|
|
18
|
+
/^i don't have personal/i,
|
|
19
|
+
/^(?:enjoy|have a great|good luck|feel free)/i,
|
|
20
|
+
/^(?:you're welcome|glad i could help|happy to help)/i,
|
|
21
|
+
];
|
|
22
|
+
import { QUOTED_TEXT_PATTERN, LITERAL_DETAIL_PATTERN, EVENT_DETAIL_PATTERN, hasStandaloneEntity, } from './content-detection.js';
|
|
23
|
+
/** Detect specific content: entities, numbers, proper nouns, structured data. */
|
|
24
|
+
function hasSpecificContent(text) {
|
|
25
|
+
if (hasStandaloneEntity(text))
|
|
26
|
+
return true;
|
|
27
|
+
if (/\b\d{1,2}(?:\s*(?:am|pm|:)\s*\d{0,2})\b/i.test(text))
|
|
28
|
+
return true;
|
|
29
|
+
if (QUOTED_TEXT_PATTERN.test(text))
|
|
30
|
+
return true;
|
|
31
|
+
if (LITERAL_DETAIL_PATTERN.test(text))
|
|
32
|
+
return true;
|
|
33
|
+
if (EVENT_DETAIL_PATTERN.test(text))
|
|
34
|
+
return true;
|
|
35
|
+
if (/\b\d{4}\b/.test(text))
|
|
36
|
+
return true;
|
|
37
|
+
if (/\|.*\|/.test(text))
|
|
38
|
+
return true;
|
|
39
|
+
// Proper noun sequences (e.g., "Miss Bee Providore", "Tangkuban Perahu")
|
|
40
|
+
if (/[A-Z][a-z]+\s+[A-Z][a-z]/.test(text))
|
|
41
|
+
return true;
|
|
42
|
+
return false;
|
|
43
|
+
}
|
|
44
|
+
/**
|
|
45
|
+
* Check if an assistant turn is likely to contain extractable facts.
|
|
46
|
+
* Filters out short acknowledgments and generic meta-commentary.
|
|
47
|
+
*/
|
|
48
|
+
export function isFactBearingAssistantTurn(text) {
|
|
49
|
+
if (text.length < MIN_ASSISTANT_TURN_LENGTH)
|
|
50
|
+
return false;
|
|
51
|
+
const firstLine = text.split('\n')[0];
|
|
52
|
+
if (ASSISTANT_CHATTER_PATTERNS.some((pattern) => pattern.test(firstLine))) {
|
|
53
|
+
return hasSpecificContent(text);
|
|
54
|
+
}
|
|
55
|
+
return true;
|
|
56
|
+
}
|
|
57
|
+
/**
|
|
58
|
+
* Check if an assistant sentence contains specific factual content worth
|
|
59
|
+
* extracting: named entities, numbers/dates, proper nouns, or list items.
|
|
60
|
+
*/
|
|
61
|
+
export function isAssistantFactStatement(sentence) {
|
|
62
|
+
if (sentence.endsWith('?'))
|
|
63
|
+
return false;
|
|
64
|
+
if (sentence.length < 20)
|
|
65
|
+
return false;
|
|
66
|
+
if (ASSISTANT_CHATTER_PATTERNS.some((pattern) => pattern.test(sentence)))
|
|
67
|
+
return false;
|
|
68
|
+
return hasSpecificContent(sentence);
|
|
69
|
+
}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* atomicmem:// URI Resolver — deterministic addressing for memories and namespaces.
|
|
3
|
+
*
|
|
4
|
+
* Implements Phase 3 of the OpenViking integration design (2026-03-20).
|
|
5
|
+
* Supports resolving hierarchical paths to memories, claims, and directories.
|
|
6
|
+
*/
|
|
7
|
+
import { MemoryRepository } from '../db/memory-repository.js';
|
|
8
|
+
import type { MemoryRow } from '../db/repository-types.js';
|
|
9
|
+
import { ClaimRepository } from '../db/claim-repository.js';
|
|
10
|
+
import type { ContextTier } from './tiered-loading.js';
|
|
11
|
+
export interface ResolvedURI {
|
|
12
|
+
uri: string;
|
|
13
|
+
type: 'memory' | 'claim' | 'directory';
|
|
14
|
+
data: MemoryRow | MemoryRow[] | any;
|
|
15
|
+
tier?: ContextTier;
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* Resolver for atomicmem:// URIs.
|
|
19
|
+
*/
|
|
20
|
+
export declare class URIResolver {
|
|
21
|
+
private repo;
|
|
22
|
+
private claims;
|
|
23
|
+
constructor(repo: MemoryRepository, claims: ClaimRepository);
|
|
24
|
+
/**
|
|
25
|
+
* Resolve a atomicmem:// URI to its underlying data.
|
|
26
|
+
*/
|
|
27
|
+
resolve(uri: string, userId: string, tier?: ContextTier): Promise<ResolvedURI | null>;
|
|
28
|
+
private resolveCurrentClaimVersion;
|
|
29
|
+
/**
|
|
30
|
+
* Format a resolved URI into context injection text.
|
|
31
|
+
*/
|
|
32
|
+
format(resolved: ResolvedURI): string;
|
|
33
|
+
}
|
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* atomicmem:// URI Resolver — deterministic addressing for memories and namespaces.
|
|
3
|
+
*
|
|
4
|
+
* Implements Phase 3 of the OpenViking integration design (2026-03-20).
|
|
5
|
+
* Supports resolving hierarchical paths to memories, claims, and directories.
|
|
6
|
+
*/
|
|
7
|
+
import { buildTieredContent } from './tiered-context.js';
|
|
8
|
+
/**
|
|
9
|
+
* Resolver for atomicmem:// URIs.
|
|
10
|
+
*/
|
|
11
|
+
export class URIResolver {
|
|
12
|
+
repo;
|
|
13
|
+
claims;
|
|
14
|
+
constructor(repo, claims) {
|
|
15
|
+
this.repo = repo;
|
|
16
|
+
this.claims = claims;
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* Resolve a atomicmem:// URI to its underlying data.
|
|
20
|
+
*/
|
|
21
|
+
async resolve(uri, userId, tier = 'L1') {
|
|
22
|
+
if (!uri.startsWith('atomicmem://'))
|
|
23
|
+
return null;
|
|
24
|
+
const path = uri.slice(11);
|
|
25
|
+
// 1. Resolve by explicit memory ID: atomicmem://memory/{id}
|
|
26
|
+
if (path.startsWith('memory/')) {
|
|
27
|
+
const memoryId = path.slice(7);
|
|
28
|
+
const memory = await this.repo.getMemory(memoryId, userId);
|
|
29
|
+
if (!memory)
|
|
30
|
+
return null;
|
|
31
|
+
return { uri, type: 'memory', data: memory, tier };
|
|
32
|
+
}
|
|
33
|
+
// 2. Resolve by claim ID: atomicmem://claim/{id}
|
|
34
|
+
if (path.startsWith('claim/')) {
|
|
35
|
+
const { claimId, asOf } = parseClaimPath(path.slice(6));
|
|
36
|
+
const version = asOf
|
|
37
|
+
? await this.claims.getClaimVersionAtTime(claimId, userId, asOf)
|
|
38
|
+
: await this.resolveCurrentClaimVersion(claimId, userId);
|
|
39
|
+
if (!version || !version.memory_id)
|
|
40
|
+
return null;
|
|
41
|
+
const memory = await this.repo.getMemory(version.memory_id, userId);
|
|
42
|
+
if (!memory)
|
|
43
|
+
return null;
|
|
44
|
+
return { uri, type: 'claim', data: memory, tier };
|
|
45
|
+
}
|
|
46
|
+
// 3. Resolve by namespace path: atomicmem://{path}
|
|
47
|
+
// E.g. atomicmem://project/atomicmem/decisions
|
|
48
|
+
const memories = await this.repo.findMemoriesByNamespace(userId, path);
|
|
49
|
+
if (memories.length > 0) {
|
|
50
|
+
return { uri, type: 'directory', data: memories, tier };
|
|
51
|
+
}
|
|
52
|
+
return null;
|
|
53
|
+
}
|
|
54
|
+
async resolveCurrentClaimVersion(claimId, userId) {
|
|
55
|
+
const claim = await this.claims.getClaim(claimId, userId);
|
|
56
|
+
if (!claim || !claim.current_version_id)
|
|
57
|
+
return null;
|
|
58
|
+
return this.claims.getClaimVersion(claim.current_version_id, userId);
|
|
59
|
+
}
|
|
60
|
+
/**
|
|
61
|
+
* Format a resolved URI into context injection text.
|
|
62
|
+
*/
|
|
63
|
+
format(resolved) {
|
|
64
|
+
if (resolved.type === 'directory') {
|
|
65
|
+
const memories = resolved.data;
|
|
66
|
+
return memories.map((m, i) => {
|
|
67
|
+
const tiered = buildTieredContent(m.content, m.summary);
|
|
68
|
+
const content = resolved.tier === 'L0' ? tiered.l0 : (resolved.tier === 'L1' ? (tiered.l1 || tiered.l2) : tiered.l2);
|
|
69
|
+
return `<memory index="${i + 1}" uri="${resolved.uri}/${m.id}" tier="L0">\n${content}\n</memory>`;
|
|
70
|
+
}).join('\n');
|
|
71
|
+
}
|
|
72
|
+
const m = resolved.data;
|
|
73
|
+
const tiered = buildTieredContent(m.content, m.summary);
|
|
74
|
+
const content = resolved.tier === 'L0' ? tiered.l0 : (resolved.tier === 'L1' ? (tiered.l1 || tiered.l2) : tiered.l2);
|
|
75
|
+
return `<memory uri="${resolved.uri}" tier="${resolved.tier}">\n${content}\n</memory>`;
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
function parseClaimPath(path) {
|
|
79
|
+
const atIndex = path.lastIndexOf('@');
|
|
80
|
+
if (atIndex === -1) {
|
|
81
|
+
return { claimId: path, asOf: null };
|
|
82
|
+
}
|
|
83
|
+
const claimId = path.slice(0, atIndex);
|
|
84
|
+
const asOf = path.slice(atIndex + 1);
|
|
85
|
+
return { claimId, asOf: asOf.length > 0 ? asOf : null };
|
|
86
|
+
}
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Structured audit event types for memory operations.
|
|
3
|
+
*
|
|
4
|
+
* Defines the event schema for all security-relevant operations:
|
|
5
|
+
* ingest, retrieval, AUDN decisions, trust scoring, and sanitization.
|
|
6
|
+
*
|
|
7
|
+
* Phase 3 security baseline. Events are emitted as structured JSON to stdout
|
|
8
|
+
* (like retrieval-trace.ts). Persistence to a database audit table is a
|
|
9
|
+
* follow-up task — this module defines the schema and serialization only.
|
|
10
|
+
*/
|
|
11
|
+
/** All auditable operation types. */
|
|
12
|
+
export type AuditAction = 'memory:ingest' | 'memory:retrieve' | 'memory:update' | 'memory:delete' | 'memory:reset-source' | 'memory:supersede' | 'memory:contradiction-preserved' | 'sanitization:block' | 'sanitization:warn' | 'trust:below-threshold' | 'lesson:match' | 'lesson:created' | 'consensus:filter' | 'deferred-audn:reconcile';
|
|
13
|
+
/** A single audit event with structured payload. */
|
|
14
|
+
export interface AuditEvent {
|
|
15
|
+
timestamp: string;
|
|
16
|
+
action: AuditAction;
|
|
17
|
+
userId: string;
|
|
18
|
+
memoryId?: string;
|
|
19
|
+
sourceSite?: string;
|
|
20
|
+
detail: Record<string, unknown>;
|
|
21
|
+
}
|
|
22
|
+
/** Configuration for the audit logger. */
|
|
23
|
+
export interface AuditConfig {
|
|
24
|
+
enabled: boolean;
|
|
25
|
+
logToStdout: boolean;
|
|
26
|
+
}
|
|
27
|
+
/** Set audit logger configuration. */
|
|
28
|
+
export declare function configureAudit(config: Partial<AuditConfig>): void;
|
|
29
|
+
/** Reset audit logger to default configuration. */
|
|
30
|
+
export declare function resetAuditConfig(): void;
|
|
31
|
+
/** Check if audit logging is currently enabled. */
|
|
32
|
+
export declare function isAuditEnabled(): boolean;
|
|
33
|
+
/**
|
|
34
|
+
* Build a structured audit event.
|
|
35
|
+
* Pure function — does not emit or persist, just constructs the event object.
|
|
36
|
+
*/
|
|
37
|
+
export declare function buildAuditEvent(action: AuditAction, userId: string, detail: Record<string, unknown>, options?: AuditEventOptions): AuditEvent;
|
|
38
|
+
/**
|
|
39
|
+
* Serialize an audit event to a single-line JSON string.
|
|
40
|
+
* Prefixed with [AUDIT] for easy grep/filtering in log streams.
|
|
41
|
+
*/
|
|
42
|
+
export declare function serializeAuditEvent(event: AuditEvent): string;
|
|
43
|
+
/**
|
|
44
|
+
* Emit an audit event. Currently writes to stdout as single-line JSON.
|
|
45
|
+
* No-op when audit logging is disabled.
|
|
46
|
+
*/
|
|
47
|
+
/** Options for audit event emission. */
|
|
48
|
+
export interface AuditEventOptions {
|
|
49
|
+
memoryId?: string;
|
|
50
|
+
sourceSite?: string;
|
|
51
|
+
lessonId?: string;
|
|
52
|
+
workspaceId?: string;
|
|
53
|
+
}
|
|
54
|
+
export declare function emitAuditEvent(action: AuditAction, userId: string, detail: Record<string, unknown>, options?: AuditEventOptions): void;
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Structured audit event types for memory operations.
|
|
3
|
+
*
|
|
4
|
+
* Defines the event schema for all security-relevant operations:
|
|
5
|
+
* ingest, retrieval, AUDN decisions, trust scoring, and sanitization.
|
|
6
|
+
*
|
|
7
|
+
* Phase 3 security baseline. Events are emitted as structured JSON to stdout
|
|
8
|
+
* (like retrieval-trace.ts). Persistence to a database audit table is a
|
|
9
|
+
* follow-up task — this module defines the schema and serialization only.
|
|
10
|
+
*/
|
|
11
|
+
const DEFAULT_CONFIG = {
|
|
12
|
+
enabled: true,
|
|
13
|
+
logToStdout: true,
|
|
14
|
+
};
|
|
15
|
+
let currentConfig = { ...DEFAULT_CONFIG };
|
|
16
|
+
/** Set audit logger configuration. */
|
|
17
|
+
export function configureAudit(config) {
|
|
18
|
+
currentConfig = { ...currentConfig, ...config };
|
|
19
|
+
}
|
|
20
|
+
/** Reset audit logger to default configuration. */
|
|
21
|
+
export function resetAuditConfig() {
|
|
22
|
+
currentConfig = { ...DEFAULT_CONFIG };
|
|
23
|
+
}
|
|
24
|
+
/** Check if audit logging is currently enabled. */
|
|
25
|
+
export function isAuditEnabled() {
|
|
26
|
+
return currentConfig.enabled;
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* Build a structured audit event.
|
|
30
|
+
* Pure function — does not emit or persist, just constructs the event object.
|
|
31
|
+
*/
|
|
32
|
+
export function buildAuditEvent(action, userId, detail, options) {
|
|
33
|
+
return {
|
|
34
|
+
timestamp: new Date().toISOString(),
|
|
35
|
+
action,
|
|
36
|
+
userId,
|
|
37
|
+
memoryId: options?.memoryId,
|
|
38
|
+
sourceSite: options?.sourceSite,
|
|
39
|
+
detail,
|
|
40
|
+
};
|
|
41
|
+
}
|
|
42
|
+
/**
|
|
43
|
+
* Serialize an audit event to a single-line JSON string.
|
|
44
|
+
* Prefixed with [AUDIT] for easy grep/filtering in log streams.
|
|
45
|
+
*/
|
|
46
|
+
export function serializeAuditEvent(event) {
|
|
47
|
+
return `[AUDIT] ${JSON.stringify(event)}`;
|
|
48
|
+
}
|
|
49
|
+
export function emitAuditEvent(action, userId, detail, options) {
|
|
50
|
+
if (!currentConfig.enabled)
|
|
51
|
+
return;
|
|
52
|
+
const event = buildAuditEvent(action, userId, detail, options);
|
|
53
|
+
if (currentConfig.logToStdout) {
|
|
54
|
+
console.log(serializeAuditEvent(event));
|
|
55
|
+
}
|
|
56
|
+
}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Chunked extraction — splits conversations into overlapping turn windows
|
|
3
|
+
* before extracting facts. Helps smaller LLMs (e.g. qwen3:8b) that struggle
|
|
4
|
+
* with long contexts by giving them focused 3-4 turn windows instead of the
|
|
5
|
+
* full conversation.
|
|
6
|
+
*
|
|
7
|
+
* Each chunk includes a session date header and overlap with the previous
|
|
8
|
+
* chunk to preserve cross-turn context. Facts are deduplicated across chunks
|
|
9
|
+
* using embedding similarity.
|
|
10
|
+
*/
|
|
11
|
+
import { type ExtractionOptions, type ExtractedFact } from './extraction.js';
|
|
12
|
+
export interface ChunkedExtractionConfig {
|
|
13
|
+
chunkSizeTurns: number;
|
|
14
|
+
chunkOverlapTurns: number;
|
|
15
|
+
extractionCacheEnabled: boolean;
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* Extract facts from each chunk and deduplicate across chunks.
|
|
19
|
+
* Uses embedding similarity to detect duplicate facts from overlapping windows.
|
|
20
|
+
*/
|
|
21
|
+
export declare function chunkedExtractFacts(conversationText: string, options: ExtractionOptions | undefined, chunking: ChunkedExtractionConfig): Promise<ExtractedFact[]>;
|