nox-mem 3.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/LICENSE +21 -0
- package/README.md +179 -0
- package/dist/api/answer.d.ts +116 -0
- package/dist/api/answer.js +274 -0
- package/dist/api/answer.validate-patch.d.ts +72 -0
- package/dist/api/answer.validate-patch.js +52 -0
- package/dist/api/brief-diversity.d.ts +64 -0
- package/dist/api/brief-diversity.js +91 -0
- package/dist/api/brief.d.ts +114 -0
- package/dist/api/brief.js +524 -0
- package/dist/api/conflict.d.ts +33 -0
- package/dist/api/conflict.js +143 -0
- package/dist/api/cors.d.ts +73 -0
- package/dist/api/cors.js +124 -0
- package/dist/api/events-stream-limited.d.ts +133 -0
- package/dist/api/events-stream-limited.js +217 -0
- package/dist/api/events-stream.d.ts +53 -0
- package/dist/api/events-stream.js +125 -0
- package/dist/api/export.d.ts +42 -0
- package/dist/api/export.js +85 -0
- package/dist/api/health-confidence-adapter.d.ts +29 -0
- package/dist/api/health-confidence-adapter.js +73 -0
- package/dist/api/health-confidence.d.ts +36 -0
- package/dist/api/health-confidence.js +141 -0
- package/dist/api/hooks.d.ts +50 -0
- package/dist/api/hooks.js +115 -0
- package/dist/api/import.d.ts +38 -0
- package/dist/api/import.js +87 -0
- package/dist/api/ingest-event.d.ts +65 -0
- package/dist/api/ingest-event.js +153 -0
- package/dist/api/mark.d.ts +42 -0
- package/dist/api/mark.js +127 -0
- package/dist/api/server-deps-a2.d.ts +55 -0
- package/dist/api/server-deps-a2.js +138 -0
- package/dist/api/server-deps-l2-l3.d.ts +68 -0
- package/dist/api/server-deps-l2-l3.js +123 -0
- package/dist/api/server-deps-p1.d.ts +84 -0
- package/dist/api/server-deps-p1.js +156 -0
- package/dist/api/server-deps-p2.d.ts +32 -0
- package/dist/api/server-deps-p2.js +84 -0
- package/dist/api/server-deps-p5.d.ts +66 -0
- package/dist/api/server-deps-p5.js +139 -0
- package/dist/api/viewer-static.d.ts +30 -0
- package/dist/api/viewer-static.js +102 -0
- package/dist/api/wire-up.d.ts +54 -0
- package/dist/api/wire-up.js +521 -0
- package/dist/api-impact.d.ts +30 -0
- package/dist/api-impact.js +196 -0
- package/dist/api-server.d.ts +2 -0
- package/dist/api-server.js +614 -0
- package/dist/backfill-fts-anchor.d.ts +15 -0
- package/dist/backfill-fts-anchor.js +97 -0
- package/dist/backfill-source-type.d.ts +20 -0
- package/dist/backfill-source-type.js +182 -0
- package/dist/churn.d.ts +31 -0
- package/dist/churn.js +98 -0
- package/dist/cli/answer.d.ts +66 -0
- package/dist/cli/answer.js +287 -0
- package/dist/cli/conflict.d.ts +38 -0
- package/dist/cli/conflict.js +282 -0
- package/dist/cli/export.d.ts +51 -0
- package/dist/cli/export.js +280 -0
- package/dist/cli/hooks.d.ts +54 -0
- package/dist/cli/hooks.js +133 -0
- package/dist/cli/import.d.ts +52 -0
- package/dist/cli/import.js +274 -0
- package/dist/cli/mark.d.ts +33 -0
- package/dist/cli/mark.js +130 -0
- package/dist/cli/ocr-batch.d.ts +12 -0
- package/dist/cli/ocr-batch.js +411 -0
- package/dist/cli/snapshot-main.d.ts +30 -0
- package/dist/cli/snapshot-main.js +47 -0
- package/dist/cli/viewer.d.ts +35 -0
- package/dist/cli/viewer.js +71 -0
- package/dist/cli-telemetry.d.ts +36 -0
- package/dist/cli-telemetry.js +150 -0
- package/dist/compact.d.ts +7 -0
- package/dist/compact.js +147 -0
- package/dist/consolidate.d.ts +18 -0
- package/dist/consolidate.js +475 -0
- package/dist/consolidation.d.ts +32 -0
- package/dist/consolidation.js +212 -0
- package/dist/cross-agent-v2.d.ts +45 -0
- package/dist/cross-agent-v2.js +271 -0
- package/dist/cross-search.d.ts +11 -0
- package/dist/cross-search.js +119 -0
- package/dist/crystallize.d.ts +43 -0
- package/dist/crystallize.js +111 -0
- package/dist/db.d.ts +11 -0
- package/dist/db.js +388 -0
- package/dist/dedup.d.ts +1 -0
- package/dist/dedup.js +106 -0
- package/dist/detect-changes.d.ts +29 -0
- package/dist/detect-changes.js +236 -0
- package/dist/digest.d.ts +1 -0
- package/dist/digest.js +205 -0
- package/dist/doctor.d.ts +1 -0
- package/dist/doctor.js +71 -0
- package/dist/embed.d.ts +45 -0
- package/dist/embed.js +257 -0
- package/dist/evals.d.ts +176 -0
- package/dist/evals.js +351 -0
- package/dist/generate-user-profile.d.ts +18 -0
- package/dist/generate-user-profile.js +163 -0
- package/dist/graphify-ingest.d.ts +18 -0
- package/dist/graphify-ingest.js +158 -0
- package/dist/impact.d.ts +39 -0
- package/dist/impact.js +143 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.js +689 -0
- package/dist/ingest-entity.d.ts +44 -0
- package/dist/ingest-entity.js +197 -0
- package/dist/ingest.d.ts +13 -0
- package/dist/ingest.js +210 -0
- package/dist/kg-llm.d.ts +39 -0
- package/dist/kg-llm.js +295 -0
- package/dist/knowledge-graph.d.ts +72 -0
- package/dist/knowledge-graph.js +507 -0
- package/dist/lib/answer/config.d.ts +41 -0
- package/dist/lib/answer/config.js +70 -0
- package/dist/lib/answer/index.d.ts +47 -0
- package/dist/lib/answer/index.js +221 -0
- package/dist/lib/answer/prompt.d.ts +37 -0
- package/dist/lib/answer/prompt.js +88 -0
- package/dist/lib/answer/provider.d.ts +47 -0
- package/dist/lib/answer/provider.js +101 -0
- package/dist/lib/answer/retrieval.d.ts +36 -0
- package/dist/lib/answer/retrieval.js +92 -0
- package/dist/lib/answer/telemetry.d.ts +99 -0
- package/dist/lib/answer/telemetry.js +154 -0
- package/dist/lib/answer/types.d.ts +108 -0
- package/dist/lib/answer/types.js +1 -0
- package/dist/lib/api/error-leak-fix.d.ts +54 -0
- package/dist/lib/api/error-leak-fix.js +55 -0
- package/dist/lib/api/safe-error-message.d.ts +70 -0
- package/dist/lib/api/safe-error-message.js +122 -0
- package/dist/lib/archive/common-passwords.d.ts +37 -0
- package/dist/lib/archive/common-passwords.js +753 -0
- package/dist/lib/archive/encryption.d.ts +81 -0
- package/dist/lib/archive/encryption.js +236 -0
- package/dist/lib/archive/enforce-strength.d.ts +54 -0
- package/dist/lib/archive/enforce-strength.js +70 -0
- package/dist/lib/archive/entropy.d.ts +34 -0
- package/dist/lib/archive/entropy.js +180 -0
- package/dist/lib/archive/export-locking.d.ts +102 -0
- package/dist/lib/archive/export-locking.js +202 -0
- package/dist/lib/archive/format.d.ts +20 -0
- package/dist/lib/archive/format.js +174 -0
- package/dist/lib/archive/index.d.ts +23 -0
- package/dist/lib/archive/index.js +17 -0
- package/dist/lib/archive/manifest.d.ts +53 -0
- package/dist/lib/archive/manifest.js +183 -0
- package/dist/lib/archive/migration.d.ts +36 -0
- package/dist/lib/archive/migration.js +100 -0
- package/dist/lib/archive/migrations/v18_to_v19.d.ts +16 -0
- package/dist/lib/archive/migrations/v18_to_v19.js +18 -0
- package/dist/lib/archive/orchestrator.d.ts +166 -0
- package/dist/lib/archive/orchestrator.js +428 -0
- package/dist/lib/archive/serializers/chunks.d.ts +30 -0
- package/dist/lib/archive/serializers/chunks.js +113 -0
- package/dist/lib/archive/serializers/embeddings.d.ts +36 -0
- package/dist/lib/archive/serializers/embeddings.js +115 -0
- package/dist/lib/archive/serializers/kg.d.ts +28 -0
- package/dist/lib/archive/serializers/kg.js +184 -0
- package/dist/lib/archive/serializers/ops_audit.d.ts +21 -0
- package/dist/lib/archive/serializers/ops_audit.js +97 -0
- package/dist/lib/archive/server-deps.d.ts +131 -0
- package/dist/lib/archive/server-deps.js +232 -0
- package/dist/lib/archive/strength.d.ts +50 -0
- package/dist/lib/archive/strength.js +77 -0
- package/dist/lib/archive/types.d.ts +159 -0
- package/dist/lib/archive/types.js +45 -0
- package/dist/lib/archive/unpack-streaming.d.ts +70 -0
- package/dist/lib/archive/unpack-streaming.js +255 -0
- package/dist/lib/auth/localhost-guard.d.ts +106 -0
- package/dist/lib/auth/localhost-guard.js +164 -0
- package/dist/lib/confidence/config.d.ts +37 -0
- package/dist/lib/confidence/config.js +107 -0
- package/dist/lib/confidence/db-shim-singleton.d.ts +20 -0
- package/dist/lib/confidence/db-shim-singleton.js +41 -0
- package/dist/lib/confidence/db-shim.d.ts +47 -0
- package/dist/lib/confidence/db-shim.js +141 -0
- package/dist/lib/confidence/mark.d.ts +58 -0
- package/dist/lib/confidence/mark.js +168 -0
- package/dist/lib/confidence/ranking.d.ts +69 -0
- package/dist/lib/confidence/ranking.js +101 -0
- package/dist/lib/confidence/search-filter.d.ts +44 -0
- package/dist/lib/confidence/search-filter.js +103 -0
- package/dist/lib/confidence/types.d.ts +146 -0
- package/dist/lib/confidence/types.js +20 -0
- package/dist/lib/confidence/write-hooks.d.ts +50 -0
- package/dist/lib/confidence/write-hooks.js +159 -0
- package/dist/lib/conflict/audit-fk-check.d.ts +72 -0
- package/dist/lib/conflict/audit-fk-check.js +131 -0
- package/dist/lib/conflict/audit-writer.d.ts +39 -0
- package/dist/lib/conflict/audit-writer.js +133 -0
- package/dist/lib/conflict/db-singleton.d.ts +28 -0
- package/dist/lib/conflict/db-singleton.js +61 -0
- package/dist/lib/conflict/db.d.ts +27 -0
- package/dist/lib/conflict/db.js +20 -0
- package/dist/lib/conflict/detector-direct.d.ts +21 -0
- package/dist/lib/conflict/detector-direct.js +105 -0
- package/dist/lib/conflict/evidence.d.ts +24 -0
- package/dist/lib/conflict/evidence.js +76 -0
- package/dist/lib/conflict/index.d.ts +14 -0
- package/dist/lib/conflict/index.js +12 -0
- package/dist/lib/conflict/scheduler.d.ts +78 -0
- package/dist/lib/conflict/scheduler.js +111 -0
- package/dist/lib/conflict/shadow.d.ts +75 -0
- package/dist/lib/conflict/shadow.js +161 -0
- package/dist/lib/conflict/types.d.ts +133 -0
- package/dist/lib/conflict/types.js +19 -0
- package/dist/lib/cost-cap.d.ts +94 -0
- package/dist/lib/cost-cap.js +129 -0
- package/dist/lib/deps/deps-registry.d.ts +111 -0
- package/dist/lib/deps/deps-registry.js +209 -0
- package/dist/lib/error-sanitizer/middleware.d.ts +43 -0
- package/dist/lib/error-sanitizer/middleware.js +100 -0
- package/dist/lib/error-sanitizer/sanitize.d.ts +78 -0
- package/dist/lib/error-sanitizer/sanitize.js +202 -0
- package/dist/lib/eval-batch.d.ts +34 -0
- package/dist/lib/eval-batch.js +103 -0
- package/dist/lib/eval-metrics.d.ts +36 -0
- package/dist/lib/eval-metrics.js +95 -0
- package/dist/lib/eval.d.ts +106 -0
- package/dist/lib/eval.js +343 -0
- package/dist/lib/events/bus.d.ts +135 -0
- package/dist/lib/events/bus.js +95 -0
- package/dist/lib/fts-anchor.d.ts +1 -0
- package/dist/lib/fts-anchor.js +131 -0
- package/dist/lib/hooks/classifier.d.ts +47 -0
- package/dist/lib/hooks/classifier.js +129 -0
- package/dist/lib/hooks/config.d.ts +49 -0
- package/dist/lib/hooks/config.js +106 -0
- package/dist/lib/hooks/decorators.d.ts +35 -0
- package/dist/lib/hooks/decorators.js +59 -0
- package/dist/lib/hooks/pipeline.d.ts +76 -0
- package/dist/lib/hooks/pipeline.js +213 -0
- package/dist/lib/hooks/privacy-filter-adapter.d.ts +55 -0
- package/dist/lib/hooks/privacy-filter-adapter.js +84 -0
- package/dist/lib/hooks/rate-limit-constant-time.d.ts +57 -0
- package/dist/lib/hooks/rate-limit-constant-time.js +69 -0
- package/dist/lib/hooks/rate-limit-dryrun-fix.d.ts +71 -0
- package/dist/lib/hooks/rate-limit-dryrun-fix.js +110 -0
- package/dist/lib/hooks/rate-limit.d.ts +54 -0
- package/dist/lib/hooks/rate-limit.js +122 -0
- package/dist/lib/hooks/server-deps.d.ts +61 -0
- package/dist/lib/hooks/server-deps.js +92 -0
- package/dist/lib/hooks/source-allowlist.d.ts +26 -0
- package/dist/lib/hooks/source-allowlist.js +53 -0
- package/dist/lib/hooks/types.d.ts +129 -0
- package/dist/lib/hooks/types.js +24 -0
- package/dist/lib/hooks/worker.d.ts +56 -0
- package/dist/lib/hooks/worker.js +150 -0
- package/dist/lib/ingest-router.d.ts +25 -0
- package/dist/lib/ingest-router.js +103 -0
- package/dist/lib/ocr-detector.d.ts +61 -0
- package/dist/lib/ocr-detector.js +138 -0
- package/dist/lib/ocr-engine-stub.d.ts +48 -0
- package/dist/lib/ocr-engine-stub.js +190 -0
- package/dist/lib/ocr-engines/google-doc-ai.d.ts +36 -0
- package/dist/lib/ocr-engines/google-doc-ai.js +164 -0
- package/dist/lib/ocr-jobs.d.ts +67 -0
- package/dist/lib/ocr-jobs.js +129 -0
- package/dist/lib/op-audit-extension/ran-at-guard.d.ts +86 -0
- package/dist/lib/op-audit-extension/ran-at-guard.js +110 -0
- package/dist/lib/op-audit.d.ts +71 -0
- package/dist/lib/op-audit.js +777 -0
- package/dist/lib/privacy-br/detector.d.ts +42 -0
- package/dist/lib/privacy-br/detector.js +130 -0
- package/dist/lib/privacy-br/index.d.ts +20 -0
- package/dist/lib/privacy-br/index.js +20 -0
- package/dist/lib/privacy-br/integration.d.ts +71 -0
- package/dist/lib/privacy-br/integration.js +74 -0
- package/dist/lib/privacy-br/patterns.d.ts +117 -0
- package/dist/lib/privacy-br/patterns.js +434 -0
- package/dist/lib/privacy-br/redact.d.ts +42 -0
- package/dist/lib/privacy-br/redact.js +103 -0
- package/dist/lib/privacy-br/types.d.ts +55 -0
- package/dist/lib/privacy-br/types.js +25 -0
- package/dist/lib/regex-extract/extractor.d.ts +30 -0
- package/dist/lib/regex-extract/extractor.js +91 -0
- package/dist/lib/regex-extract/frontmatter.d.ts +44 -0
- package/dist/lib/regex-extract/frontmatter.js +169 -0
- package/dist/lib/regex-extract/index.d.ts +14 -0
- package/dist/lib/regex-extract/index.js +14 -0
- package/dist/lib/regex-extract/ingest-router-l4.d.ts +76 -0
- package/dist/lib/regex-extract/ingest-router-l4.js +102 -0
- package/dist/lib/regex-extract/patterns.d.ts +61 -0
- package/dist/lib/regex-extract/patterns.js +91 -0
- package/dist/lib/regex-extract/production-wire.d.ts +128 -0
- package/dist/lib/regex-extract/production-wire.js +202 -0
- package/dist/lib/regex-extract/reconcile.d.ts +162 -0
- package/dist/lib/regex-extract/reconcile.js +210 -0
- package/dist/lib/regex-extract/strip-code.d.ts +24 -0
- package/dist/lib/regex-extract/strip-code.js +52 -0
- package/dist/lib/regex-extract/types.d.ts +48 -0
- package/dist/lib/regex-extract/types.js +25 -0
- package/dist/lib/reranker.d.ts +80 -0
- package/dist/lib/reranker.js +324 -0
- package/dist/lib/shadow-tracker.d.ts +191 -0
- package/dist/lib/shadow-tracker.js +384 -0
- package/dist/lib/spo-injection.d.ts +52 -0
- package/dist/lib/spo-injection.js +166 -0
- package/dist/lib/telemetry-collector.d.ts +158 -0
- package/dist/lib/telemetry-collector.js +249 -0
- package/dist/lib/temporal-detector.d.ts +27 -0
- package/dist/lib/temporal-detector.js +81 -0
- package/dist/lib/viewer/auth.d.ts +37 -0
- package/dist/lib/viewer/auth.js +70 -0
- package/dist/lib/viewer/backpressure.d.ts +59 -0
- package/dist/lib/viewer/backpressure.js +100 -0
- package/dist/lib/viewer/broadcast-singleton.d.ts +34 -0
- package/dist/lib/viewer/broadcast-singleton.js +49 -0
- package/dist/lib/viewer/broadcast.d.ts +66 -0
- package/dist/lib/viewer/broadcast.js +96 -0
- package/dist/lib/viewer/event-types.d.ts +132 -0
- package/dist/lib/viewer/event-types.js +74 -0
- package/dist/lib/viewer/instrumentation.d.ts +106 -0
- package/dist/lib/viewer/instrumentation.js +224 -0
- package/dist/lib/viewer/migration.d.ts +23 -0
- package/dist/lib/viewer/migration.js +56 -0
- package/dist/lib/viewer/redaction.d.ts +44 -0
- package/dist/lib/viewer/redaction.js +139 -0
- package/dist/lib/viewer/session.d.ts +51 -0
- package/dist/lib/viewer/session.js +87 -0
- package/dist/mcp/tools/answer.d.ts +94 -0
- package/dist/mcp/tools/answer.js +213 -0
- package/dist/mcp/tools/archive.d.ts +152 -0
- package/dist/mcp/tools/archive.js +170 -0
- package/dist/mcp/tools/conflict.d.ts +44 -0
- package/dist/mcp/tools/conflict.js +130 -0
- package/dist/mcp/tools/hooks.d.ts +29 -0
- package/dist/mcp/tools/hooks.js +78 -0
- package/dist/mcp/tools/mark.d.ts +38 -0
- package/dist/mcp/tools/mark.js +82 -0
- package/dist/mcp/tools/viewer.d.ts +58 -0
- package/dist/mcp/tools/viewer.js +64 -0
- package/dist/mcp-server.d.ts +2 -0
- package/dist/mcp-server.js +395 -0
- package/dist/metrics.d.ts +3 -0
- package/dist/metrics.js +59 -0
- package/dist/noise-filter.d.ts +18 -0
- package/dist/noise-filter.js +142 -0
- package/dist/notion-sync.d.ts +7 -0
- package/dist/notion-sync.js +97 -0
- package/dist/observability/adapters/a3-adapter.d.ts +63 -0
- package/dist/observability/adapters/a3-adapter.js +83 -0
- package/dist/observability/adapters/p1-adapter.d.ts +49 -0
- package/dist/observability/adapters/p1-adapter.js +63 -0
- package/dist/observability/adapters/p5-adapter.d.ts +36 -0
- package/dist/observability/adapters/p5-adapter.js +71 -0
- package/dist/observability/cardinality.d.ts +61 -0
- package/dist/observability/cardinality.js +300 -0
- package/dist/observability/collectors/db-stats.collector.d.ts +9 -0
- package/dist/observability/collectors/db-stats.collector.js +88 -0
- package/dist/observability/collectors/eventbus.collector.d.ts +6 -0
- package/dist/observability/collectors/eventbus.collector.js +50 -0
- package/dist/observability/collectors/process.collector.d.ts +7 -0
- package/dist/observability/collectors/process.collector.js +93 -0
- package/dist/observability/collectors/provider-telemetry.collector.d.ts +11 -0
- package/dist/observability/collectors/provider-telemetry.collector.js +112 -0
- package/dist/observability/collectors/search-telemetry.collector.d.ts +12 -0
- package/dist/observability/collectors/search-telemetry.collector.js +76 -0
- package/dist/observability/exporter.d.ts +30 -0
- package/dist/observability/exporter.js +182 -0
- package/dist/observability/index.d.ts +22 -0
- package/dist/observability/index.js +21 -0
- package/dist/observability/metrics.d.ts +53 -0
- package/dist/observability/metrics.js +213 -0
- package/dist/observability/privacy-guard.d.ts +32 -0
- package/dist/observability/privacy-guard.js +116 -0
- package/dist/observability/record.d.ts +83 -0
- package/dist/observability/record.js +217 -0
- package/dist/observability/registry.d.ts +60 -0
- package/dist/observability/registry.js +93 -0
- package/dist/observability/types.d.ts +115 -0
- package/dist/observability/types.js +235 -0
- package/dist/observability.d.ts +131 -0
- package/dist/observability.js +234 -0
- package/dist/plugins/nox-hooks/index.d.ts +61 -0
- package/dist/plugins/nox-hooks/index.js +99 -0
- package/dist/primer.d.ts +1 -0
- package/dist/primer.js +100 -0
- package/dist/privacy/filter.d.ts +27 -0
- package/dist/privacy/filter.js +74 -0
- package/dist/privacy/patterns.d.ts +29 -0
- package/dist/privacy/patterns.js +178 -0
- package/dist/privacy/tag-parser.d.ts +24 -0
- package/dist/privacy/tag-parser.js +29 -0
- package/dist/project-context-gen.d.ts +10 -0
- package/dist/project-context-gen.js +106 -0
- package/dist/providers/embedding/gemini.d.ts +73 -0
- package/dist/providers/embedding/gemini.js +118 -0
- package/dist/providers/embedding/openai.d.ts +76 -0
- package/dist/providers/embedding/openai.js +123 -0
- package/dist/providers/embedding/types.d.ts +39 -0
- package/dist/providers/embedding/types.js +1 -0
- package/dist/providers/embedding/voyage.d.ts +36 -0
- package/dist/providers/embedding/voyage.js +29 -0
- package/dist/providers/index.d.ts +116 -0
- package/dist/providers/index.js +158 -0
- package/dist/providers/llm/anthropic.d.ts +29 -0
- package/dist/providers/llm/anthropic.js +28 -0
- package/dist/providers/llm/chain.d.ts +99 -0
- package/dist/providers/llm/chain.js +213 -0
- package/dist/providers/llm/gemini.d.ts +48 -0
- package/dist/providers/llm/gemini.js +96 -0
- package/dist/providers/llm/openai.d.ts +64 -0
- package/dist/providers/llm/openai.js +109 -0
- package/dist/providers/llm/types.d.ts +47 -0
- package/dist/providers/llm/types.js +1 -0
- package/dist/providers/telemetry.d.ts +87 -0
- package/dist/providers/telemetry.js +156 -0
- package/dist/providers/types.d.ts +42 -0
- package/dist/providers/types.js +59 -0
- package/dist/query-entity-count.d.ts +54 -0
- package/dist/query-entity-count.js +171 -0
- package/dist/reflect.d.ts +26 -0
- package/dist/reflect.js +290 -0
- package/dist/reindex-errors.d.ts +7 -0
- package/dist/reindex-errors.js +21 -0
- package/dist/reindex.d.ts +16 -0
- package/dist/reindex.js +293 -0
- package/dist/retention.d.ts +40 -0
- package/dist/retention.js +86 -0
- package/dist/salience.d.ts +85 -0
- package/dist/salience.js +245 -0
- package/dist/scripts/migrate-v17-ops-audit.d.ts +17 -0
- package/dist/scripts/migrate-v17-ops-audit.js +70 -0
- package/dist/search-dedup.d.ts +44 -0
- package/dist/search-dedup.js +137 -0
- package/dist/search-expansion.d.ts +20 -0
- package/dist/search-expansion.js +99 -0
- package/dist/search.d.ts +62 -0
- package/dist/search.js +582 -0
- package/dist/seh-detector.d.ts +31 -0
- package/dist/seh-detector.js +201 -0
- package/dist/self-improve.d.ts +1 -0
- package/dist/self-improve.js +189 -0
- package/dist/session-distill.d.ts +29 -0
- package/dist/session-distill.js +325 -0
- package/dist/session-update.d.ts +1 -0
- package/dist/session-update.js +54 -0
- package/dist/shared-memory.d.ts +24 -0
- package/dist/shared-memory.js +104 -0
- package/dist/stats.d.ts +1 -0
- package/dist/stats.js +44 -0
- package/dist/temporal-retrieval.d.ts +132 -0
- package/dist/temporal-retrieval.js +495 -0
- package/dist/tier-manager.d.ts +69 -0
- package/dist/tier-manager.js +225 -0
- package/dist/vectorize.d.ts +16 -0
- package/dist/vectorize.js +91 -0
- package/dist/watch.d.ts +8 -0
- package/dist/watch.js +124 -0
- package/package.json +74 -0
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* src/observability/collectors/search-telemetry.collector.ts
|
|
3
|
+
*
|
|
4
|
+
* Polls `search_telemetry` (post-A0 column set) and translates rows into
|
|
5
|
+
* `nox_search_*` metric increments. Rows are read in batches keyed by an
|
|
6
|
+
* incrementing cursor so we don't double-count.
|
|
7
|
+
*
|
|
8
|
+
* Schema dependency:
|
|
9
|
+
* search_telemetry(id INTEGER PK, ts INTEGER, method TEXT, duration_ms INTEGER,
|
|
10
|
+
* results_count INTEGER, outcome TEXT, …)
|
|
11
|
+
*
|
|
12
|
+
* IMPORTANT: This collector does NOT read query_text — it only consumes the
|
|
13
|
+
* categorical fields. Privacy invariant.
|
|
14
|
+
*/
|
|
15
|
+
import { searchRequestsTotal, searchDurationSeconds, searchResultsReturned, } from "../metrics.js";
|
|
16
|
+
import { guardLabels } from "../privacy-guard.js";
|
|
17
|
+
let intervalHandle;
|
|
18
|
+
let cursor = 0;
|
|
19
|
+
export function startSearchTelemetryCollector(opts) {
|
|
20
|
+
if (intervalHandle)
|
|
21
|
+
return;
|
|
22
|
+
cursor = opts.startId ?? 0;
|
|
23
|
+
const interval = opts.intervalMs ?? 5_000;
|
|
24
|
+
const runOnce = () => {
|
|
25
|
+
try {
|
|
26
|
+
drain(opts.query);
|
|
27
|
+
}
|
|
28
|
+
catch {
|
|
29
|
+
// never crash
|
|
30
|
+
}
|
|
31
|
+
};
|
|
32
|
+
runOnce();
|
|
33
|
+
intervalHandle = setInterval(runOnce, interval);
|
|
34
|
+
intervalHandle.unref?.();
|
|
35
|
+
}
|
|
36
|
+
export function stopSearchTelemetryCollector() {
|
|
37
|
+
if (intervalHandle) {
|
|
38
|
+
clearInterval(intervalHandle);
|
|
39
|
+
intervalHandle = undefined;
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
export function drain(query) {
|
|
43
|
+
const rows = query(`SELECT id, method, duration_ms, results_count, outcome
|
|
44
|
+
FROM search_telemetry
|
|
45
|
+
WHERE id > ?
|
|
46
|
+
ORDER BY id ASC
|
|
47
|
+
LIMIT 1000`, [cursor]);
|
|
48
|
+
for (const r of rows) {
|
|
49
|
+
const id = Number(r.id);
|
|
50
|
+
const method = String(r.method ?? "other");
|
|
51
|
+
const durMs = Number(r.duration_ms ?? 0);
|
|
52
|
+
const count = Number(r.results_count ?? 0);
|
|
53
|
+
const outcome = String(r.outcome ?? "success");
|
|
54
|
+
const reqL = guardLabels("nox_search_requests_total", {
|
|
55
|
+
method,
|
|
56
|
+
outcome,
|
|
57
|
+
}).labels;
|
|
58
|
+
if (reqL)
|
|
59
|
+
searchRequestsTotal.inc(reqL);
|
|
60
|
+
const durL = guardLabels("nox_search_duration_seconds", { method }).labels;
|
|
61
|
+
if (durL)
|
|
62
|
+
searchDurationSeconds.observe(durL, durMs / 1000);
|
|
63
|
+
const resL = guardLabels("nox_search_results_returned", { method }).labels;
|
|
64
|
+
if (resL)
|
|
65
|
+
searchResultsReturned.observe(resL, count);
|
|
66
|
+
if (id > cursor)
|
|
67
|
+
cursor = id;
|
|
68
|
+
}
|
|
69
|
+
return rows.length;
|
|
70
|
+
}
|
|
71
|
+
export function getCursor() {
|
|
72
|
+
return cursor;
|
|
73
|
+
}
|
|
74
|
+
export function resetCursor() {
|
|
75
|
+
cursor = 0;
|
|
76
|
+
}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { type MetricsRegistry, type RegistrySnapshot } from "./registry.js";
|
|
2
|
+
export declare const OPENMETRICS_CONTENT_TYPE = "application/openmetrics-text; version=1.0.0; charset=utf-8";
|
|
3
|
+
export declare const PROMETHEUS_CONTENT_TYPE = "text/plain; version=0.0.4; charset=utf-8";
|
|
4
|
+
/**
|
|
5
|
+
* Render a full snapshot to text. Stable line order:
|
|
6
|
+
* - Sorted by metric name.
|
|
7
|
+
* - For each metric: `# HELP`, `# TYPE`, optional `# UNIT`, samples.
|
|
8
|
+
* - Samples within a metric: sorted by stringified labels.
|
|
9
|
+
*/
|
|
10
|
+
export declare function render(snapshot: RegistrySnapshot): string;
|
|
11
|
+
export interface MetricsRequest {
|
|
12
|
+
/** Lower-cased URL search params for filtering, e.g. ?names=a,b */
|
|
13
|
+
searchParams?: URLSearchParams | Record<string, string>;
|
|
14
|
+
/** Standard HTTP headers as a Record (lower-case keys). */
|
|
15
|
+
headers?: Record<string, string | string[] | undefined>;
|
|
16
|
+
}
|
|
17
|
+
export interface MetricsResponse {
|
|
18
|
+
status: number;
|
|
19
|
+
headers: Record<string, string>;
|
|
20
|
+
/** Body — string or Buffer (when gzipped). */
|
|
21
|
+
body: string | Buffer;
|
|
22
|
+
}
|
|
23
|
+
export interface ExporterOpts {
|
|
24
|
+
registry?: MetricsRegistry;
|
|
25
|
+
/** If set, require `Authorization: Bearer <token>`. */
|
|
26
|
+
token?: string;
|
|
27
|
+
/** Content type — defaults to OpenMetrics. */
|
|
28
|
+
contentType?: string;
|
|
29
|
+
}
|
|
30
|
+
export declare function handle(req: MetricsRequest, opts?: ExporterOpts): MetricsResponse;
|
|
@@ -0,0 +1,182 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* src/observability/exporter.ts — `/metrics` exporter (T5).
|
|
3
|
+
*
|
|
4
|
+
* Serializes the registry snapshot to OpenMetrics text format (Prometheus
|
|
5
|
+
* 0.0.4+ compatible).
|
|
6
|
+
*
|
|
7
|
+
* RESPONSIBILITIES:
|
|
8
|
+
* 1. Render Counter / Gauge / Histogram in canonical order.
|
|
9
|
+
* 2. Filter by `?names=metric1,metric2` (CSV).
|
|
10
|
+
* 3. Optional Bearer-token auth (`NOX_METRICS_TOKEN` env).
|
|
11
|
+
* 4. Gzip the body when Accept-Encoding lists gzip.
|
|
12
|
+
*
|
|
13
|
+
* NEVER expose:
|
|
14
|
+
* - Stack traces
|
|
15
|
+
* - Caller identity
|
|
16
|
+
* - Anything beyond the registered metrics
|
|
17
|
+
*
|
|
18
|
+
* The exporter is designed to be transport-agnostic. The `handle()` function
|
|
19
|
+
* accepts a Request-like input and returns a Response-like output, so it can
|
|
20
|
+
* plug into the existing nox-mem HTTP API (port 18802) or any Node http
|
|
21
|
+
* server.
|
|
22
|
+
*/
|
|
23
|
+
import { gzipSync } from "node:zlib";
|
|
24
|
+
import { getDefaultRegistry } from "./registry.js";
|
|
25
|
+
import { escapeLabelValue, } from "./types.js";
|
|
26
|
+
// ─── Content-type & version ─────────────────────────────────────────────────
|
|
27
|
+
export const OPENMETRICS_CONTENT_TYPE = "application/openmetrics-text; version=1.0.0; charset=utf-8";
|
|
28
|
+
export const PROMETHEUS_CONTENT_TYPE = "text/plain; version=0.0.4; charset=utf-8";
|
|
29
|
+
// ─── Rendering ───────────────────────────────────────────────────────────────
|
|
30
|
+
/**
|
|
31
|
+
* Render a full snapshot to text. Stable line order:
|
|
32
|
+
* - Sorted by metric name.
|
|
33
|
+
* - For each metric: `# HELP`, `# TYPE`, optional `# UNIT`, samples.
|
|
34
|
+
* - Samples within a metric: sorted by stringified labels.
|
|
35
|
+
*/
|
|
36
|
+
export function render(snapshot) {
|
|
37
|
+
const lines = [];
|
|
38
|
+
// Render counters
|
|
39
|
+
for (const c of snapshot.counters) {
|
|
40
|
+
renderCounter(c, lines);
|
|
41
|
+
}
|
|
42
|
+
// Render gauges
|
|
43
|
+
for (const g of snapshot.gauges) {
|
|
44
|
+
renderGauge(g, lines);
|
|
45
|
+
}
|
|
46
|
+
// Render histograms
|
|
47
|
+
for (const h of snapshot.histograms) {
|
|
48
|
+
renderHistogram(h, lines);
|
|
49
|
+
}
|
|
50
|
+
// OpenMetrics EOF terminator (optional in Prometheus mode; safe in both).
|
|
51
|
+
lines.push("# EOF");
|
|
52
|
+
return lines.join("\n") + "\n";
|
|
53
|
+
}
|
|
54
|
+
function renderHeader(meta, lines) {
|
|
55
|
+
lines.push(`# HELP ${meta.name} ${escapeHelp(meta.help)}`);
|
|
56
|
+
lines.push(`# TYPE ${meta.name} ${meta.kind}`);
|
|
57
|
+
if (meta.unit)
|
|
58
|
+
lines.push(`# UNIT ${meta.name} ${meta.unit}`);
|
|
59
|
+
}
|
|
60
|
+
function escapeHelp(s) {
|
|
61
|
+
return s.replace(/\\/g, "\\\\").replace(/\n/g, "\\n");
|
|
62
|
+
}
|
|
63
|
+
function labelsToString(labels) {
|
|
64
|
+
const keys = Object.keys(labels).sort();
|
|
65
|
+
if (keys.length === 0)
|
|
66
|
+
return "";
|
|
67
|
+
const parts = [];
|
|
68
|
+
for (const k of keys) {
|
|
69
|
+
const v = labels[k];
|
|
70
|
+
if (typeof v !== "string")
|
|
71
|
+
continue;
|
|
72
|
+
parts.push(`${k}="${escapeLabelValue(v)}"`);
|
|
73
|
+
}
|
|
74
|
+
if (parts.length === 0)
|
|
75
|
+
return "";
|
|
76
|
+
return `{${parts.join(",")}}`;
|
|
77
|
+
}
|
|
78
|
+
function renderCounter(c, lines) {
|
|
79
|
+
renderHeader(c.meta, lines);
|
|
80
|
+
const samples = sortSamples(c.collect().map((s) => ({ labels: s.labels, value: s.value })));
|
|
81
|
+
for (const s of samples) {
|
|
82
|
+
lines.push(`${c.meta.name}${labelsToString(s.labels)} ${formatValue(s.value)}`);
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
function renderGauge(g, lines) {
|
|
86
|
+
renderHeader(g.meta, lines);
|
|
87
|
+
const samples = sortSamples(g.collect().map((s) => ({ labels: s.labels, value: s.value })));
|
|
88
|
+
for (const s of samples) {
|
|
89
|
+
lines.push(`${g.meta.name}${labelsToString(s.labels)} ${formatValue(s.value)}`);
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
function renderHistogram(h, lines) {
|
|
93
|
+
renderHeader(h.meta, lines);
|
|
94
|
+
for (const s of h.collect()) {
|
|
95
|
+
const base = { ...s.labels };
|
|
96
|
+
for (let i = 0; i < s.buckets.length; i++) {
|
|
97
|
+
const lbl = { ...base, le: formatLe(s.buckets[i]) };
|
|
98
|
+
lines.push(`${h.meta.name}_bucket${labelsToString(lbl)} ${formatValue(s.bucketCounts[i])}`);
|
|
99
|
+
}
|
|
100
|
+
// +Inf bucket
|
|
101
|
+
const inf = { ...base, le: "+Inf" };
|
|
102
|
+
lines.push(`${h.meta.name}_bucket${labelsToString(inf)} ${formatValue(s.count)}`);
|
|
103
|
+
lines.push(`${h.meta.name}_sum${labelsToString(base)} ${formatValue(s.sum)}`);
|
|
104
|
+
lines.push(`${h.meta.name}_count${labelsToString(base)} ${formatValue(s.count)}`);
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
function sortSamples(samples) {
|
|
108
|
+
return [...samples].sort((a, b) => labelsToString(a.labels).localeCompare(labelsToString(b.labels)));
|
|
109
|
+
}
|
|
110
|
+
function formatValue(v) {
|
|
111
|
+
if (Number.isInteger(v))
|
|
112
|
+
return String(v);
|
|
113
|
+
return v.toString();
|
|
114
|
+
}
|
|
115
|
+
function formatLe(v) {
|
|
116
|
+
// Use plain number; Prometheus accepts both "1" and "1.0".
|
|
117
|
+
return v.toString();
|
|
118
|
+
}
|
|
119
|
+
export function handle(req, opts = {}) {
|
|
120
|
+
const token = opts.token ?? process.env.NOX_METRICS_TOKEN;
|
|
121
|
+
if (token) {
|
|
122
|
+
const auth = headerString(req.headers, "authorization");
|
|
123
|
+
if (!auth || !auth.startsWith("Bearer ") || auth.slice(7) !== token) {
|
|
124
|
+
return {
|
|
125
|
+
status: 401,
|
|
126
|
+
headers: {
|
|
127
|
+
"content-type": "text/plain; charset=utf-8",
|
|
128
|
+
"www-authenticate": 'Bearer realm="nox-metrics"',
|
|
129
|
+
},
|
|
130
|
+
body: "unauthorized\n",
|
|
131
|
+
};
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
const reg = opts.registry ?? getDefaultRegistry();
|
|
135
|
+
const snap = reg.collect();
|
|
136
|
+
const names = parseNames(req.searchParams);
|
|
137
|
+
const filtered = names.size === 0 ? snap : filterSnapshot(snap, names);
|
|
138
|
+
const text = render(filtered);
|
|
139
|
+
const acceptEnc = headerString(req.headers, "accept-encoding") ?? "";
|
|
140
|
+
const wantsGzip = /\bgzip\b/i.test(acceptEnc);
|
|
141
|
+
const headers = {
|
|
142
|
+
"content-type": opts.contentType ?? OPENMETRICS_CONTENT_TYPE,
|
|
143
|
+
"cache-control": "no-store",
|
|
144
|
+
"x-metrics-snapshot-at": String(snap.takenAt),
|
|
145
|
+
};
|
|
146
|
+
if (wantsGzip) {
|
|
147
|
+
const body = gzipSync(Buffer.from(text, "utf8"));
|
|
148
|
+
headers["content-encoding"] = "gzip";
|
|
149
|
+
headers["content-length"] = String(body.length);
|
|
150
|
+
return { status: 200, headers, body };
|
|
151
|
+
}
|
|
152
|
+
return { status: 200, headers, body: text };
|
|
153
|
+
}
|
|
154
|
+
function headerString(headers, name) {
|
|
155
|
+
if (!headers)
|
|
156
|
+
return undefined;
|
|
157
|
+
const v = headers[name] ?? headers[name.toLowerCase()];
|
|
158
|
+
if (Array.isArray(v))
|
|
159
|
+
return v[0];
|
|
160
|
+
return v;
|
|
161
|
+
}
|
|
162
|
+
function parseNames(params) {
|
|
163
|
+
if (!params)
|
|
164
|
+
return new Set();
|
|
165
|
+
const raw = params instanceof URLSearchParams
|
|
166
|
+
? params.get("names")
|
|
167
|
+
: params["names"];
|
|
168
|
+
if (!raw)
|
|
169
|
+
return new Set();
|
|
170
|
+
return new Set(raw
|
|
171
|
+
.split(",")
|
|
172
|
+
.map((s) => s.trim())
|
|
173
|
+
.filter((s) => s.length > 0));
|
|
174
|
+
}
|
|
175
|
+
function filterSnapshot(snap, names) {
|
|
176
|
+
return Object.freeze({
|
|
177
|
+
takenAt: snap.takenAt,
|
|
178
|
+
counters: snap.counters.filter((c) => names.has(c.meta.name)),
|
|
179
|
+
gauges: snap.gauges.filter((g) => names.has(g.meta.name)),
|
|
180
|
+
histograms: snap.histograms.filter((h) => names.has(h.meta.name)),
|
|
181
|
+
});
|
|
182
|
+
}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* src/observability/index.ts — Public barrel for the observability package.
|
|
3
|
+
*
|
|
4
|
+
* Importers should prefer this entry over deep paths. The recording API
|
|
5
|
+
* (`recordSearch`, `recordAnswer`, …) is the only thing 99% of callers need.
|
|
6
|
+
*/
|
|
7
|
+
export * from "./types.js";
|
|
8
|
+
export { MetricsRegistry, getDefaultRegistry, resetDefaultRegistry, } from "./registry.js";
|
|
9
|
+
export type { RegistrySnapshot, AnyMetric } from "./registry.js";
|
|
10
|
+
export { ALL_METRIC_NAMES, type MetricName, chunksTotal, embeddingsTotal, kgEntitiesTotal, kgRelationsTotal, searchRequestsTotal, searchDurationSeconds, searchResultsReturned, answerRequestsTotal, answerDurationSeconds, answerTokensTotal, providerCallsTotal, providerDurationSeconds, providerCostUsdTotal, providerTokensTotal, hooksEventsTotal, hooksPipelineDurationSeconds, viewerConnections, viewerEventsTotal, viewerDroppedTotal, dbSizeBytes, chunksActive, chunksStale, auditRowsTotal, processCpuUserSecondsTotal, processCpuSystemSecondsTotal, processResidentMemoryBytes, processOpenFds, nodejsEventloopLagSeconds, } from "./metrics.js";
|
|
11
|
+
export { CardinalityGuard, getDefaultGuard, resetDefaultGuard, applyDefaultPolicies, } from "./cardinality.js";
|
|
12
|
+
export { sanitizeString, sanitizeLabels, sanitizeLabelValue, guardLabels, } from "./privacy-guard.js";
|
|
13
|
+
export { recordSearch, recordAnswer, recordProviderCall, recordChunkIngest, recordEmbedding, recordKgEntity, recordKgRelation, recordHookEvent, recordViewerConnect, recordViewerDisconnect, recordViewerEvent, recordViewerDropped, recordAuditWrite, startTimer, type SearchMethod, type SearchOutcome, type AnswerOutcome, type AnswerTiming, type ProviderKind, type ProviderOutcome, type ProvenanceKind, } from "./record.js";
|
|
14
|
+
export { handle, render, OPENMETRICS_CONTENT_TYPE, PROMETHEUS_CONTENT_TYPE, type MetricsRequest, type MetricsResponse, type ExporterOpts, } from "./exporter.js";
|
|
15
|
+
export { startProcessCollector, stopProcessCollector, collectOnce as collectProcessOnce, } from "./collectors/process.collector.js";
|
|
16
|
+
export { startDbStatsCollector, stopDbStatsCollector, collectDbStats, } from "./collectors/db-stats.collector.js";
|
|
17
|
+
export { startSearchTelemetryCollector, stopSearchTelemetryCollector, drain as drainSearchTelemetry, } from "./collectors/search-telemetry.collector.js";
|
|
18
|
+
export { startProviderTelemetryCollector, stopProviderTelemetryCollector, drain as drainProviderTelemetry, } from "./collectors/provider-telemetry.collector.js";
|
|
19
|
+
export { attachEventBusCollector, detachEventBusCollector, type EventBusLike, } from "./collectors/eventbus.collector.js";
|
|
20
|
+
export { withAnswerMetrics, type AnswerHandler, type AnswerResult, } from "./adapters/p1-adapter.js";
|
|
21
|
+
export { instrumentProviderCall, classifyProviderError, type ProviderCallMeta, type ProviderCallResult, type ProviderInner, } from "./adapters/a3-adapter.js";
|
|
22
|
+
export { wrapBroadcast, trackConnection, reportBackpressureDrop, type BroadcastEvent, type BroadcastFn, type SocketLike, } from "./adapters/p5-adapter.js";
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* src/observability/index.ts — Public barrel for the observability package.
|
|
3
|
+
*
|
|
4
|
+
* Importers should prefer this entry over deep paths. The recording API
|
|
5
|
+
* (`recordSearch`, `recordAnswer`, …) is the only thing 99% of callers need.
|
|
6
|
+
*/
|
|
7
|
+
export * from "./types.js";
|
|
8
|
+
export { MetricsRegistry, getDefaultRegistry, resetDefaultRegistry, } from "./registry.js";
|
|
9
|
+
export { ALL_METRIC_NAMES, chunksTotal, embeddingsTotal, kgEntitiesTotal, kgRelationsTotal, searchRequestsTotal, searchDurationSeconds, searchResultsReturned, answerRequestsTotal, answerDurationSeconds, answerTokensTotal, providerCallsTotal, providerDurationSeconds, providerCostUsdTotal, providerTokensTotal, hooksEventsTotal, hooksPipelineDurationSeconds, viewerConnections, viewerEventsTotal, viewerDroppedTotal, dbSizeBytes, chunksActive, chunksStale, auditRowsTotal, processCpuUserSecondsTotal, processCpuSystemSecondsTotal, processResidentMemoryBytes, processOpenFds, nodejsEventloopLagSeconds, } from "./metrics.js";
|
|
10
|
+
export { CardinalityGuard, getDefaultGuard, resetDefaultGuard, applyDefaultPolicies, } from "./cardinality.js";
|
|
11
|
+
export { sanitizeString, sanitizeLabels, sanitizeLabelValue, guardLabels, } from "./privacy-guard.js";
|
|
12
|
+
export { recordSearch, recordAnswer, recordProviderCall, recordChunkIngest, recordEmbedding, recordKgEntity, recordKgRelation, recordHookEvent, recordViewerConnect, recordViewerDisconnect, recordViewerEvent, recordViewerDropped, recordAuditWrite, startTimer, } from "./record.js";
|
|
13
|
+
export { handle, render, OPENMETRICS_CONTENT_TYPE, PROMETHEUS_CONTENT_TYPE, } from "./exporter.js";
|
|
14
|
+
export { startProcessCollector, stopProcessCollector, collectOnce as collectProcessOnce, } from "./collectors/process.collector.js";
|
|
15
|
+
export { startDbStatsCollector, stopDbStatsCollector, collectDbStats, } from "./collectors/db-stats.collector.js";
|
|
16
|
+
export { startSearchTelemetryCollector, stopSearchTelemetryCollector, drain as drainSearchTelemetry, } from "./collectors/search-telemetry.collector.js";
|
|
17
|
+
export { startProviderTelemetryCollector, stopProviderTelemetryCollector, drain as drainProviderTelemetry, } from "./collectors/provider-telemetry.collector.js";
|
|
18
|
+
export { attachEventBusCollector, detachEventBusCollector, } from "./collectors/eventbus.collector.js";
|
|
19
|
+
export { withAnswerMetrics, } from "./adapters/p1-adapter.js";
|
|
20
|
+
export { instrumentProviderCall, classifyProviderError, } from "./adapters/a3-adapter.js";
|
|
21
|
+
export { wrapBroadcast, trackConnection, reportBackpressureDrop, } from "./adapters/p5-adapter.js";
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* src/observability/metrics.ts — Standard metric catalog (T3).
|
|
3
|
+
*
|
|
4
|
+
* Single source of truth for every metric exported by nox-mem. Each metric is
|
|
5
|
+
* defined as a singleton attached to the default registry on first import.
|
|
6
|
+
*
|
|
7
|
+
* Naming convention (Prometheus + OpenMetrics best practices):
|
|
8
|
+
* - snake_case
|
|
9
|
+
* - prefix `nox_` for nox-mem metrics, `process_` / `nodejs_` for runtime
|
|
10
|
+
* - `_total` suffix for Counter
|
|
11
|
+
* - `_seconds` / `_bytes` for unit-bearing observations
|
|
12
|
+
*
|
|
13
|
+
* Cardinality budget per metric is conservative — see ./cardinality.ts.
|
|
14
|
+
*
|
|
15
|
+
* NOTE: Importing this module is a side-effect: it registers metrics into the
|
|
16
|
+
* default registry. Tests using a fresh `new MetricsRegistry()` must either
|
|
17
|
+
* import this and use the same singletons, or define their own metrics.
|
|
18
|
+
*/
|
|
19
|
+
import { Counter, Gauge, Histogram } from "./types.js";
|
|
20
|
+
export declare const chunksTotal: Counter;
|
|
21
|
+
export declare const embeddingsTotal: Counter;
|
|
22
|
+
export declare const kgEntitiesTotal: Counter;
|
|
23
|
+
export declare const kgRelationsTotal: Counter;
|
|
24
|
+
export declare const searchRequestsTotal: Counter;
|
|
25
|
+
export declare const searchDurationSeconds: Histogram;
|
|
26
|
+
export declare const searchResultsReturned: Histogram;
|
|
27
|
+
export declare const answerRequestsTotal: Counter;
|
|
28
|
+
export declare const answerDurationSeconds: Histogram;
|
|
29
|
+
export declare const answerTokensTotal: Counter;
|
|
30
|
+
export declare const providerCallsTotal: Counter;
|
|
31
|
+
export declare const providerDurationSeconds: Histogram;
|
|
32
|
+
export declare const providerCostUsdTotal: Counter;
|
|
33
|
+
export declare const providerTokensTotal: Counter;
|
|
34
|
+
export declare const hooksEventsTotal: Counter;
|
|
35
|
+
export declare const hooksPipelineDurationSeconds: Histogram;
|
|
36
|
+
export declare const viewerConnections: Gauge;
|
|
37
|
+
export declare const viewerEventsTotal: Counter;
|
|
38
|
+
export declare const viewerDroppedTotal: Counter;
|
|
39
|
+
export declare const dbSizeBytes: Gauge;
|
|
40
|
+
export declare const chunksActive: Gauge;
|
|
41
|
+
export declare const chunksStale: Gauge;
|
|
42
|
+
export declare const auditRowsTotal: Counter;
|
|
43
|
+
export declare const processCpuUserSecondsTotal: Counter;
|
|
44
|
+
export declare const processCpuSystemSecondsTotal: Counter;
|
|
45
|
+
export declare const processResidentMemoryBytes: Gauge;
|
|
46
|
+
export declare const processOpenFds: Gauge;
|
|
47
|
+
export declare const nodejsEventloopLagSeconds: Gauge;
|
|
48
|
+
/**
|
|
49
|
+
* Names of every metric registered by this module.
|
|
50
|
+
* Order: same as registration order above.
|
|
51
|
+
*/
|
|
52
|
+
export declare const ALL_METRIC_NAMES: readonly ["nox_chunks_total", "nox_embeddings_total", "nox_kg_entities_total", "nox_kg_relations_total", "nox_search_requests_total", "nox_search_duration_seconds", "nox_search_results_returned", "nox_answer_requests_total", "nox_answer_duration_seconds", "nox_answer_tokens_total", "nox_provider_calls_total", "nox_provider_duration_seconds", "nox_provider_cost_usd_total", "nox_provider_tokens_total", "nox_hooks_events_total", "nox_hooks_pipeline_duration_seconds", "nox_viewer_connections", "nox_viewer_events_total", "nox_viewer_dropped_total", "nox_db_size_bytes", "nox_chunks_active", "nox_chunks_stale", "nox_audit_rows_total", "process_cpu_user_seconds_total", "process_cpu_system_seconds_total", "process_resident_memory_bytes", "process_open_fds", "nodejs_eventloop_lag_seconds"];
|
|
53
|
+
export type MetricName = (typeof ALL_METRIC_NAMES)[number];
|
|
@@ -0,0 +1,213 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* src/observability/metrics.ts — Standard metric catalog (T3).
|
|
3
|
+
*
|
|
4
|
+
* Single source of truth for every metric exported by nox-mem. Each metric is
|
|
5
|
+
* defined as a singleton attached to the default registry on first import.
|
|
6
|
+
*
|
|
7
|
+
* Naming convention (Prometheus + OpenMetrics best practices):
|
|
8
|
+
* - snake_case
|
|
9
|
+
* - prefix `nox_` for nox-mem metrics, `process_` / `nodejs_` for runtime
|
|
10
|
+
* - `_total` suffix for Counter
|
|
11
|
+
* - `_seconds` / `_bytes` for unit-bearing observations
|
|
12
|
+
*
|
|
13
|
+
* Cardinality budget per metric is conservative — see ./cardinality.ts.
|
|
14
|
+
*
|
|
15
|
+
* NOTE: Importing this module is a side-effect: it registers metrics into the
|
|
16
|
+
* default registry. Tests using a fresh `new MetricsRegistry()` must either
|
|
17
|
+
* import this and use the same singletons, or define their own metrics.
|
|
18
|
+
*/
|
|
19
|
+
import { Counter, Gauge, Histogram, DURATION_BUCKETS_SECONDS, RESULT_COUNT_BUCKETS, } from "./types.js";
|
|
20
|
+
import { getDefaultRegistry } from "./registry.js";
|
|
21
|
+
const R = getDefaultRegistry();
|
|
22
|
+
// ─── Pipeline metrics ────────────────────────────────────────────────────────
|
|
23
|
+
export const chunksTotal = R.register(new Counter({
|
|
24
|
+
name: "nox_chunks_total",
|
|
25
|
+
help: "Total chunks ingested (cumulative).",
|
|
26
|
+
labelKeys: ["provenance_kind"],
|
|
27
|
+
}));
|
|
28
|
+
export const embeddingsTotal = R.register(new Counter({
|
|
29
|
+
name: "nox_embeddings_total",
|
|
30
|
+
help: "Total embeddings created (cumulative).",
|
|
31
|
+
labelKeys: ["provider", "outcome"],
|
|
32
|
+
}));
|
|
33
|
+
export const kgEntitiesTotal = R.register(new Counter({
|
|
34
|
+
name: "nox_kg_entities_total",
|
|
35
|
+
help: "Total KG entities created (cumulative).",
|
|
36
|
+
labelKeys: ["type"],
|
|
37
|
+
}));
|
|
38
|
+
export const kgRelationsTotal = R.register(new Counter({
|
|
39
|
+
name: "nox_kg_relations_total",
|
|
40
|
+
help: "Total KG relations created (cumulative).",
|
|
41
|
+
labelKeys: ["predicate"],
|
|
42
|
+
}));
|
|
43
|
+
// ─── Search metrics ──────────────────────────────────────────────────────────
|
|
44
|
+
export const searchRequestsTotal = R.register(new Counter({
|
|
45
|
+
name: "nox_search_requests_total",
|
|
46
|
+
help: "Total search requests handled.",
|
|
47
|
+
labelKeys: ["method", "outcome"],
|
|
48
|
+
}));
|
|
49
|
+
export const searchDurationSeconds = R.register(new Histogram({
|
|
50
|
+
name: "nox_search_duration_seconds",
|
|
51
|
+
help: "End-to-end search latency in seconds.",
|
|
52
|
+
labelKeys: ["method"],
|
|
53
|
+
unit: "seconds",
|
|
54
|
+
}, DURATION_BUCKETS_SECONDS));
|
|
55
|
+
export const searchResultsReturned = R.register(new Histogram({
|
|
56
|
+
name: "nox_search_results_returned",
|
|
57
|
+
help: "Distribution of result counts returned per search.",
|
|
58
|
+
labelKeys: ["method"],
|
|
59
|
+
}, RESULT_COUNT_BUCKETS));
|
|
60
|
+
// ─── Answer (P1) metrics ─────────────────────────────────────────────────────
|
|
61
|
+
export const answerRequestsTotal = R.register(new Counter({
|
|
62
|
+
name: "nox_answer_requests_total",
|
|
63
|
+
help: "Total /api/answer requests by failure reason.",
|
|
64
|
+
labelKeys: ["failure_reason"], // success | no_chunks | llm_failed | hallucination
|
|
65
|
+
}));
|
|
66
|
+
export const answerDurationSeconds = R.register(new Histogram({
|
|
67
|
+
name: "nox_answer_duration_seconds",
|
|
68
|
+
help: "Answer latency by phase (total | retrieve | rerank | synthesize | verify).",
|
|
69
|
+
labelKeys: ["phase"],
|
|
70
|
+
unit: "seconds",
|
|
71
|
+
}, DURATION_BUCKETS_SECONDS));
|
|
72
|
+
export const answerTokensTotal = R.register(new Counter({
|
|
73
|
+
name: "nox_answer_tokens_total",
|
|
74
|
+
help: "Total tokens consumed by /api/answer (cumulative).",
|
|
75
|
+
labelKeys: ["direction"], // input | output
|
|
76
|
+
}));
|
|
77
|
+
// ─── Provider (A3) metrics ───────────────────────────────────────────────────
|
|
78
|
+
export const providerCallsTotal = R.register(new Counter({
|
|
79
|
+
name: "nox_provider_calls_total",
|
|
80
|
+
help: "Total LLM/embedding provider calls.",
|
|
81
|
+
labelKeys: ["provider", "model", "outcome"], // outcome: success | rate_limit | error | fallback
|
|
82
|
+
}));
|
|
83
|
+
export const providerDurationSeconds = R.register(new Histogram({
|
|
84
|
+
name: "nox_provider_duration_seconds",
|
|
85
|
+
help: "Provider call latency in seconds.",
|
|
86
|
+
labelKeys: ["provider", "kind"], // kind: embedding | llm
|
|
87
|
+
unit: "seconds",
|
|
88
|
+
}, DURATION_BUCKETS_SECONDS));
|
|
89
|
+
export const providerCostUsdTotal = R.register(new Counter({
|
|
90
|
+
name: "nox_provider_cost_usd_total",
|
|
91
|
+
help: "Cumulative provider cost in USD.",
|
|
92
|
+
labelKeys: ["provider", "model"],
|
|
93
|
+
}));
|
|
94
|
+
export const providerTokensTotal = R.register(new Counter({
|
|
95
|
+
name: "nox_provider_tokens_total",
|
|
96
|
+
help: "Cumulative provider tokens by direction.",
|
|
97
|
+
labelKeys: ["provider", "direction"], // direction: input | output
|
|
98
|
+
}));
|
|
99
|
+
// ─── Hooks (P2) metrics ──────────────────────────────────────────────────────
|
|
100
|
+
export const hooksEventsTotal = R.register(new Counter({
|
|
101
|
+
name: "nox_hooks_events_total",
|
|
102
|
+
help: "Total auto-capture hook events by layer + reason.",
|
|
103
|
+
labelKeys: ["layer", "reason"], // reason: captured | filtered | redacted | error
|
|
104
|
+
}));
|
|
105
|
+
export const hooksPipelineDurationSeconds = R.register(new Histogram({
|
|
106
|
+
name: "nox_hooks_pipeline_duration_seconds",
|
|
107
|
+
help: "Hooks capture pipeline latency in seconds.",
|
|
108
|
+
labelKeys: ["layer"],
|
|
109
|
+
unit: "seconds",
|
|
110
|
+
}, DURATION_BUCKETS_SECONDS));
|
|
111
|
+
// ─── Viewer (P5) metrics ─────────────────────────────────────────────────────
|
|
112
|
+
export const viewerConnections = R.register(new Gauge({
|
|
113
|
+
name: "nox_viewer_connections",
|
|
114
|
+
help: "Current count of open viewer SSE connections.",
|
|
115
|
+
labelKeys: [],
|
|
116
|
+
}));
|
|
117
|
+
export const viewerEventsTotal = R.register(new Counter({
|
|
118
|
+
name: "nox_viewer_events_total",
|
|
119
|
+
help: "Total viewer events broadcast by type.",
|
|
120
|
+
labelKeys: ["type"],
|
|
121
|
+
}));
|
|
122
|
+
export const viewerDroppedTotal = R.register(new Counter({
|
|
123
|
+
name: "nox_viewer_dropped_total",
|
|
124
|
+
help: "Total viewer events dropped due to backpressure.",
|
|
125
|
+
labelKeys: ["reason"], // reason: slow_consumer | queue_full | client_gone
|
|
126
|
+
}));
|
|
127
|
+
// ─── System metrics ──────────────────────────────────────────────────────────
|
|
128
|
+
export const dbSizeBytes = R.register(new Gauge({
|
|
129
|
+
name: "nox_db_size_bytes",
|
|
130
|
+
help: "Size of the SQLite DB file in bytes (main + WAL).",
|
|
131
|
+
labelKeys: ["component"], // component: main | wal | shm
|
|
132
|
+
unit: "bytes",
|
|
133
|
+
}));
|
|
134
|
+
export const chunksActive = R.register(new Gauge({
|
|
135
|
+
name: "nox_chunks_active",
|
|
136
|
+
help: "Active chunks (provenance_kind != stale).",
|
|
137
|
+
labelKeys: [],
|
|
138
|
+
}));
|
|
139
|
+
export const chunksStale = R.register(new Gauge({
|
|
140
|
+
name: "nox_chunks_stale",
|
|
141
|
+
help: "Stale chunks (provenance_kind == stale).",
|
|
142
|
+
labelKeys: [],
|
|
143
|
+
}));
|
|
144
|
+
export const auditRowsTotal = R.register(new Counter({
|
|
145
|
+
name: "nox_audit_rows_total",
|
|
146
|
+
help: "Total audit rows written by table.",
|
|
147
|
+
labelKeys: ["table"], // table: ops_audit | provider_telemetry | search_telemetry | agent_events
|
|
148
|
+
}));
|
|
149
|
+
// ─── Process / runtime metrics ───────────────────────────────────────────────
|
|
150
|
+
export const processCpuUserSecondsTotal = R.register(new Counter({
|
|
151
|
+
name: "process_cpu_user_seconds_total",
|
|
152
|
+
help: "Total user CPU time in seconds (cumulative).",
|
|
153
|
+
labelKeys: [],
|
|
154
|
+
unit: "seconds",
|
|
155
|
+
}));
|
|
156
|
+
export const processCpuSystemSecondsTotal = R.register(new Counter({
|
|
157
|
+
name: "process_cpu_system_seconds_total",
|
|
158
|
+
help: "Total system CPU time in seconds (cumulative).",
|
|
159
|
+
labelKeys: [],
|
|
160
|
+
unit: "seconds",
|
|
161
|
+
}));
|
|
162
|
+
export const processResidentMemoryBytes = R.register(new Gauge({
|
|
163
|
+
name: "process_resident_memory_bytes",
|
|
164
|
+
help: "Resident memory in bytes (RSS).",
|
|
165
|
+
labelKeys: [],
|
|
166
|
+
unit: "bytes",
|
|
167
|
+
}));
|
|
168
|
+
export const processOpenFds = R.register(new Gauge({
|
|
169
|
+
name: "process_open_fds",
|
|
170
|
+
help: "Number of open file descriptors (best-effort).",
|
|
171
|
+
labelKeys: [],
|
|
172
|
+
}));
|
|
173
|
+
export const nodejsEventloopLagSeconds = R.register(new Gauge({
|
|
174
|
+
name: "nodejs_eventloop_lag_seconds",
|
|
175
|
+
help: "Event loop lag in seconds (last sample).",
|
|
176
|
+
labelKeys: [],
|
|
177
|
+
unit: "seconds",
|
|
178
|
+
}));
|
|
179
|
+
// ─── Catalog summary (for docs / tests / cardinality budgeting) ─────────────
|
|
180
|
+
/**
|
|
181
|
+
* Names of every metric registered by this module.
|
|
182
|
+
* Order: same as registration order above.
|
|
183
|
+
*/
|
|
184
|
+
export const ALL_METRIC_NAMES = Object.freeze([
|
|
185
|
+
"nox_chunks_total",
|
|
186
|
+
"nox_embeddings_total",
|
|
187
|
+
"nox_kg_entities_total",
|
|
188
|
+
"nox_kg_relations_total",
|
|
189
|
+
"nox_search_requests_total",
|
|
190
|
+
"nox_search_duration_seconds",
|
|
191
|
+
"nox_search_results_returned",
|
|
192
|
+
"nox_answer_requests_total",
|
|
193
|
+
"nox_answer_duration_seconds",
|
|
194
|
+
"nox_answer_tokens_total",
|
|
195
|
+
"nox_provider_calls_total",
|
|
196
|
+
"nox_provider_duration_seconds",
|
|
197
|
+
"nox_provider_cost_usd_total",
|
|
198
|
+
"nox_provider_tokens_total",
|
|
199
|
+
"nox_hooks_events_total",
|
|
200
|
+
"nox_hooks_pipeline_duration_seconds",
|
|
201
|
+
"nox_viewer_connections",
|
|
202
|
+
"nox_viewer_events_total",
|
|
203
|
+
"nox_viewer_dropped_total",
|
|
204
|
+
"nox_db_size_bytes",
|
|
205
|
+
"nox_chunks_active",
|
|
206
|
+
"nox_chunks_stale",
|
|
207
|
+
"nox_audit_rows_total",
|
|
208
|
+
"process_cpu_user_seconds_total",
|
|
209
|
+
"process_cpu_system_seconds_total",
|
|
210
|
+
"process_resident_memory_bytes",
|
|
211
|
+
"process_open_fds",
|
|
212
|
+
"nodejs_eventloop_lag_seconds",
|
|
213
|
+
]);
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* src/observability/privacy-guard.ts — PII / sensitive-text stripper (T9).
|
|
3
|
+
*
|
|
4
|
+
* RULES (non-negotiable):
|
|
5
|
+
* 1. No raw query text in label values — replace with "<redacted-query>".
|
|
6
|
+
* 2. No paths, file names, IPs, emails, phone numbers, BR personal IDs
|
|
7
|
+
* (CPF/CNPJ/CEP/RG), Pix keys, API keys / bearer tokens.
|
|
8
|
+
* 3. Anything not on a strict allowlist of "shapes" → "<redacted>".
|
|
9
|
+
*
|
|
10
|
+
* This module composes with `cardinality.ts` — privacy strips PII *contents*,
|
|
11
|
+
* cardinality enforces *shape* (allowlists) and *budget*.
|
|
12
|
+
*
|
|
13
|
+
* Patterns mirror A1 (privacy filter) and A1.1 (BR PII). Kept self-contained
|
|
14
|
+
* to avoid coupling — the observability layer must function even if the
|
|
15
|
+
* privacy package is later refactored.
|
|
16
|
+
*/
|
|
17
|
+
/** Strip PII from a string. Returns the sanitized string. */
|
|
18
|
+
export declare function sanitizeString(s: string): string;
|
|
19
|
+
export declare function sanitizeLabelValue(name: string, value: string): string;
|
|
20
|
+
/** Sanitize an entire labels object — drop forbidden keys, coerce values. */
|
|
21
|
+
export declare function sanitizeLabels(labels: Record<string, string>): Record<string, string>;
|
|
22
|
+
import { CardinalityGuard } from "./cardinality.js";
|
|
23
|
+
export interface GuardChainResult {
|
|
24
|
+
/** Sanitized + cardinality-checked labels, or null if dropped. */
|
|
25
|
+
labels: Record<string, string> | null;
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* One-call guard for any metric: privacy first, then cardinality.
|
|
29
|
+
*
|
|
30
|
+
* This is the function the recording API uses. Caller should `null`-check.
|
|
31
|
+
*/
|
|
32
|
+
export declare function guardLabels(metricName: string, rawLabels?: Record<string, string>, guard?: CardinalityGuard): GuardChainResult;
|