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,300 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* src/observability/cardinality.ts — Cardinality guard (T8).
|
|
3
|
+
*
|
|
4
|
+
* Prevents unbounded label cardinality from blowing up the registry.
|
|
5
|
+
*
|
|
6
|
+
* Failure modes if not enforced:
|
|
7
|
+
* 1. user_id, session_id, query_text in labels → millions of series → OOM
|
|
8
|
+
* 2. Bug: cycled value in label → series count grows forever
|
|
9
|
+
* 3. Adversary input → DoS via metric explosion
|
|
10
|
+
*
|
|
11
|
+
* GUARD STRATEGY:
|
|
12
|
+
* - Per-metric `maxSeries` cap (default 1000).
|
|
13
|
+
* - Per-metric label *value* allowlist (optional): only those values may
|
|
14
|
+
* be reported. Anything else is bucketed as "other".
|
|
15
|
+
* - On overflow: drop the increment + log once per cooldown window.
|
|
16
|
+
*
|
|
17
|
+
* USAGE:
|
|
18
|
+
* const guard = new CardinalityGuard();
|
|
19
|
+
* guard.policy("nox_search_requests_total", {
|
|
20
|
+
* maxSeries: 50,
|
|
21
|
+
* labelAllowlist: { method: ["cli", "api", "mcp"] },
|
|
22
|
+
* });
|
|
23
|
+
* const safe = guard.guard("nox_search_requests_total", { method: payload });
|
|
24
|
+
* if (safe) counter.inc(safe);
|
|
25
|
+
*/
|
|
26
|
+
const DEFAULT_MAX_SERIES = 1000;
|
|
27
|
+
const WARN_COOLDOWN_MS = 60_000; // log dropped overflow at most once per minute per metric
|
|
28
|
+
export class CardinalityGuard {
|
|
29
|
+
policies = new Map();
|
|
30
|
+
seenSeries = new Map();
|
|
31
|
+
drops = new Map();
|
|
32
|
+
log;
|
|
33
|
+
constructor(log = (m) => console.warn(m)) {
|
|
34
|
+
this.log = log;
|
|
35
|
+
}
|
|
36
|
+
/** Configure a per-metric policy. */
|
|
37
|
+
policy(metricName, p) {
|
|
38
|
+
this.policies.set(metricName, {
|
|
39
|
+
maxSeries: p.maxSeries ?? DEFAULT_MAX_SERIES,
|
|
40
|
+
labelAllowlist: p.labelAllowlist ?? {},
|
|
41
|
+
labelDenylist: p.labelDenylist ?? [],
|
|
42
|
+
});
|
|
43
|
+
}
|
|
44
|
+
/**
|
|
45
|
+
* Validate + normalize a label set for a metric.
|
|
46
|
+
* Returns the (possibly rewritten) labels — or `null` if it must be dropped.
|
|
47
|
+
*/
|
|
48
|
+
guard(metricName, labels) {
|
|
49
|
+
const policy = this.policies.get(metricName);
|
|
50
|
+
const max = policy?.maxSeries ?? DEFAULT_MAX_SERIES;
|
|
51
|
+
const allow = policy?.labelAllowlist ?? {};
|
|
52
|
+
const deny = policy?.labelDenylist ?? [];
|
|
53
|
+
// Strip denylisted labels — never let them through.
|
|
54
|
+
const out = {};
|
|
55
|
+
for (const [k, v] of Object.entries(labels)) {
|
|
56
|
+
if (deny.includes(k))
|
|
57
|
+
continue;
|
|
58
|
+
const list = allow[k];
|
|
59
|
+
if (list && list.length > 0 && !list.includes(v)) {
|
|
60
|
+
out[k] = "other";
|
|
61
|
+
}
|
|
62
|
+
else {
|
|
63
|
+
out[k] = v;
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
// Compute a stable series key.
|
|
67
|
+
const seriesKey = stringifyLabels(out);
|
|
68
|
+
let seen = this.seenSeries.get(metricName);
|
|
69
|
+
if (!seen) {
|
|
70
|
+
seen = new Set();
|
|
71
|
+
this.seenSeries.set(metricName, seen);
|
|
72
|
+
}
|
|
73
|
+
if (seen.has(seriesKey)) {
|
|
74
|
+
return out; // already counted; safe to emit
|
|
75
|
+
}
|
|
76
|
+
if (seen.size >= max) {
|
|
77
|
+
this.noteDrop(metricName);
|
|
78
|
+
return null;
|
|
79
|
+
}
|
|
80
|
+
seen.add(seriesKey);
|
|
81
|
+
return out;
|
|
82
|
+
}
|
|
83
|
+
/** Current series count for a metric. */
|
|
84
|
+
seriesCount(metricName) {
|
|
85
|
+
return this.seenSeries.get(metricName)?.size ?? 0;
|
|
86
|
+
}
|
|
87
|
+
/** Number of drops for a metric (since process start). */
|
|
88
|
+
dropCount(metricName) {
|
|
89
|
+
return this.drops.get(metricName)?.count ?? 0;
|
|
90
|
+
}
|
|
91
|
+
/** Reset (test-only). */
|
|
92
|
+
reset() {
|
|
93
|
+
this.seenSeries.clear();
|
|
94
|
+
this.drops.clear();
|
|
95
|
+
}
|
|
96
|
+
noteDrop(metricName) {
|
|
97
|
+
const now = Date.now();
|
|
98
|
+
let d = this.drops.get(metricName);
|
|
99
|
+
if (!d) {
|
|
100
|
+
d = { count: 0, lastWarn: 0 };
|
|
101
|
+
this.drops.set(metricName, d);
|
|
102
|
+
}
|
|
103
|
+
d.count += 1;
|
|
104
|
+
if (now - d.lastWarn > WARN_COOLDOWN_MS) {
|
|
105
|
+
d.lastWarn = now;
|
|
106
|
+
this.log(`[cardinality] dropped label-set for metric ${metricName} ` +
|
|
107
|
+
`(cap reached; total drops=${d.count})`);
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
function stringifyLabels(labels) {
|
|
112
|
+
const keys = Object.keys(labels).sort();
|
|
113
|
+
if (keys.length === 0)
|
|
114
|
+
return "";
|
|
115
|
+
return keys.map((k) => `${k}=${labels[k]}`).join("|");
|
|
116
|
+
}
|
|
117
|
+
// ─── Default process-wide guard ──────────────────────────────────────────────
|
|
118
|
+
let _default;
|
|
119
|
+
export function getDefaultGuard() {
|
|
120
|
+
if (!_default) {
|
|
121
|
+
_default = new CardinalityGuard();
|
|
122
|
+
applyDefaultPolicies(_default);
|
|
123
|
+
}
|
|
124
|
+
return _default;
|
|
125
|
+
}
|
|
126
|
+
export function resetDefaultGuard() {
|
|
127
|
+
_default = undefined;
|
|
128
|
+
}
|
|
129
|
+
/**
|
|
130
|
+
* Apply nox-mem's standard policies. Keep this conservative — anything that
|
|
131
|
+
* could explode (user_id, query_text, paths) must be denylisted everywhere.
|
|
132
|
+
*/
|
|
133
|
+
export function applyDefaultPolicies(g) {
|
|
134
|
+
const FORBIDDEN_LABELS = [
|
|
135
|
+
"user_id",
|
|
136
|
+
"session_id",
|
|
137
|
+
"query",
|
|
138
|
+
"query_text",
|
|
139
|
+
"prompt",
|
|
140
|
+
"response",
|
|
141
|
+
"email",
|
|
142
|
+
"ip",
|
|
143
|
+
"path",
|
|
144
|
+
"filename",
|
|
145
|
+
"chunk_id",
|
|
146
|
+
"entity_id",
|
|
147
|
+
];
|
|
148
|
+
// Apply forbidden-label policy globally by attaching denylist on each metric.
|
|
149
|
+
const ALL = [
|
|
150
|
+
"nox_chunks_total",
|
|
151
|
+
"nox_embeddings_total",
|
|
152
|
+
"nox_kg_entities_total",
|
|
153
|
+
"nox_kg_relations_total",
|
|
154
|
+
"nox_search_requests_total",
|
|
155
|
+
"nox_search_duration_seconds",
|
|
156
|
+
"nox_search_results_returned",
|
|
157
|
+
"nox_answer_requests_total",
|
|
158
|
+
"nox_answer_duration_seconds",
|
|
159
|
+
"nox_answer_tokens_total",
|
|
160
|
+
"nox_provider_calls_total",
|
|
161
|
+
"nox_provider_duration_seconds",
|
|
162
|
+
"nox_provider_cost_usd_total",
|
|
163
|
+
"nox_provider_tokens_total",
|
|
164
|
+
"nox_hooks_events_total",
|
|
165
|
+
"nox_hooks_pipeline_duration_seconds",
|
|
166
|
+
"nox_viewer_connections",
|
|
167
|
+
"nox_viewer_events_total",
|
|
168
|
+
"nox_viewer_dropped_total",
|
|
169
|
+
"nox_db_size_bytes",
|
|
170
|
+
"nox_chunks_active",
|
|
171
|
+
"nox_chunks_stale",
|
|
172
|
+
"nox_audit_rows_total",
|
|
173
|
+
];
|
|
174
|
+
for (const m of ALL) {
|
|
175
|
+
g.policy(m, { labelDenylist: FORBIDDEN_LABELS, maxSeries: 1000 });
|
|
176
|
+
}
|
|
177
|
+
// Tighter caps + allowlists for high-traffic metrics.
|
|
178
|
+
g.policy("nox_search_requests_total", {
|
|
179
|
+
maxSeries: 30,
|
|
180
|
+
labelAllowlist: {
|
|
181
|
+
method: ["cli", "api", "mcp"],
|
|
182
|
+
outcome: ["success", "empty", "error"],
|
|
183
|
+
},
|
|
184
|
+
labelDenylist: FORBIDDEN_LABELS,
|
|
185
|
+
});
|
|
186
|
+
g.policy("nox_search_duration_seconds", {
|
|
187
|
+
maxSeries: 10,
|
|
188
|
+
labelAllowlist: { method: ["cli", "api", "mcp"] },
|
|
189
|
+
labelDenylist: FORBIDDEN_LABELS,
|
|
190
|
+
});
|
|
191
|
+
g.policy("nox_search_results_returned", {
|
|
192
|
+
maxSeries: 10,
|
|
193
|
+
labelAllowlist: { method: ["cli", "api", "mcp"] },
|
|
194
|
+
labelDenylist: FORBIDDEN_LABELS,
|
|
195
|
+
});
|
|
196
|
+
g.policy("nox_answer_requests_total", {
|
|
197
|
+
maxSeries: 10,
|
|
198
|
+
labelAllowlist: {
|
|
199
|
+
failure_reason: [
|
|
200
|
+
"success",
|
|
201
|
+
"no_chunks",
|
|
202
|
+
"llm_failed",
|
|
203
|
+
"hallucination",
|
|
204
|
+
"timeout",
|
|
205
|
+
"cost_cap",
|
|
206
|
+
],
|
|
207
|
+
},
|
|
208
|
+
labelDenylist: FORBIDDEN_LABELS,
|
|
209
|
+
});
|
|
210
|
+
g.policy("nox_answer_duration_seconds", {
|
|
211
|
+
maxSeries: 10,
|
|
212
|
+
labelAllowlist: {
|
|
213
|
+
phase: ["total", "retrieve", "rerank", "synthesize", "verify"],
|
|
214
|
+
},
|
|
215
|
+
labelDenylist: FORBIDDEN_LABELS,
|
|
216
|
+
});
|
|
217
|
+
g.policy("nox_answer_tokens_total", {
|
|
218
|
+
maxSeries: 4,
|
|
219
|
+
labelAllowlist: { direction: ["input", "output"] },
|
|
220
|
+
labelDenylist: FORBIDDEN_LABELS,
|
|
221
|
+
});
|
|
222
|
+
g.policy("nox_provider_calls_total", {
|
|
223
|
+
maxSeries: 200,
|
|
224
|
+
labelAllowlist: {
|
|
225
|
+
provider: ["gemini", "openai", "anthropic", "voyage", "ollama", "other"],
|
|
226
|
+
outcome: ["success", "rate_limit", "error", "fallback"],
|
|
227
|
+
},
|
|
228
|
+
labelDenylist: FORBIDDEN_LABELS,
|
|
229
|
+
});
|
|
230
|
+
g.policy("nox_provider_duration_seconds", {
|
|
231
|
+
maxSeries: 50,
|
|
232
|
+
labelAllowlist: {
|
|
233
|
+
provider: ["gemini", "openai", "anthropic", "voyage", "ollama", "other"],
|
|
234
|
+
kind: ["embedding", "llm"],
|
|
235
|
+
},
|
|
236
|
+
labelDenylist: FORBIDDEN_LABELS,
|
|
237
|
+
});
|
|
238
|
+
g.policy("nox_provider_cost_usd_total", {
|
|
239
|
+
maxSeries: 200,
|
|
240
|
+
labelAllowlist: {
|
|
241
|
+
provider: ["gemini", "openai", "anthropic", "voyage", "ollama", "other"],
|
|
242
|
+
},
|
|
243
|
+
labelDenylist: FORBIDDEN_LABELS,
|
|
244
|
+
});
|
|
245
|
+
g.policy("nox_provider_tokens_total", {
|
|
246
|
+
maxSeries: 30,
|
|
247
|
+
labelAllowlist: {
|
|
248
|
+
provider: ["gemini", "openai", "anthropic", "voyage", "ollama", "other"],
|
|
249
|
+
direction: ["input", "output"],
|
|
250
|
+
},
|
|
251
|
+
labelDenylist: FORBIDDEN_LABELS,
|
|
252
|
+
});
|
|
253
|
+
g.policy("nox_hooks_events_total", {
|
|
254
|
+
maxSeries: 100,
|
|
255
|
+
labelAllowlist: {
|
|
256
|
+
layer: ["pre-tool", "post-tool", "tool-start", "tool-end", "user-prompt"],
|
|
257
|
+
reason: ["captured", "filtered", "redacted", "error", "dropped"],
|
|
258
|
+
},
|
|
259
|
+
labelDenylist: FORBIDDEN_LABELS,
|
|
260
|
+
});
|
|
261
|
+
g.policy("nox_viewer_events_total", {
|
|
262
|
+
maxSeries: 30,
|
|
263
|
+
labelAllowlist: {
|
|
264
|
+
type: [
|
|
265
|
+
"ingest",
|
|
266
|
+
"search",
|
|
267
|
+
"kg_update",
|
|
268
|
+
"answer",
|
|
269
|
+
"provider_call",
|
|
270
|
+
"audit",
|
|
271
|
+
"hook",
|
|
272
|
+
"other",
|
|
273
|
+
],
|
|
274
|
+
},
|
|
275
|
+
labelDenylist: FORBIDDEN_LABELS,
|
|
276
|
+
});
|
|
277
|
+
g.policy("nox_viewer_dropped_total", {
|
|
278
|
+
maxSeries: 10,
|
|
279
|
+
labelAllowlist: { reason: ["slow_consumer", "queue_full", "client_gone"] },
|
|
280
|
+
labelDenylist: FORBIDDEN_LABELS,
|
|
281
|
+
});
|
|
282
|
+
g.policy("nox_db_size_bytes", {
|
|
283
|
+
maxSeries: 5,
|
|
284
|
+
labelAllowlist: { component: ["main", "wal", "shm"] },
|
|
285
|
+
labelDenylist: FORBIDDEN_LABELS,
|
|
286
|
+
});
|
|
287
|
+
g.policy("nox_audit_rows_total", {
|
|
288
|
+
maxSeries: 10,
|
|
289
|
+
labelAllowlist: {
|
|
290
|
+
table: [
|
|
291
|
+
"ops_audit",
|
|
292
|
+
"provider_telemetry",
|
|
293
|
+
"search_telemetry",
|
|
294
|
+
"agent_events",
|
|
295
|
+
"answer_telemetry",
|
|
296
|
+
],
|
|
297
|
+
},
|
|
298
|
+
labelDenylist: FORBIDDEN_LABELS,
|
|
299
|
+
});
|
|
300
|
+
}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
export type DbQueryFn = (sql: string) => Array<Record<string, unknown>>;
|
|
2
|
+
export interface DbStatsCollectorOpts {
|
|
3
|
+
dbPath: string;
|
|
4
|
+
query: DbQueryFn;
|
|
5
|
+
intervalMs?: number;
|
|
6
|
+
}
|
|
7
|
+
export declare function startDbStatsCollector(opts: DbStatsCollectorOpts): void;
|
|
8
|
+
export declare function stopDbStatsCollector(): void;
|
|
9
|
+
export declare function collectDbStats(opts: DbStatsCollectorOpts): void;
|
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* src/observability/collectors/db-stats.collector.ts
|
|
3
|
+
*
|
|
4
|
+
* Periodically samples DB state into gauges (db size, chunk counts).
|
|
5
|
+
*
|
|
6
|
+
* Schema dependencies (nox-mem v3.7):
|
|
7
|
+
* - chunks(id, provenance_kind)
|
|
8
|
+
* - kg_entities, kg_relations (counted via the dedicated collectors)
|
|
9
|
+
*
|
|
10
|
+
* The collector is DB-driver agnostic: callers inject `queryFn`. Production
|
|
11
|
+
* wiring uses better-sqlite3; tests use an in-memory stub.
|
|
12
|
+
*/
|
|
13
|
+
import { statSync } from "node:fs";
|
|
14
|
+
import { dirname, join } from "node:path";
|
|
15
|
+
import { chunksActive, chunksStale, dbSizeBytes } from "../metrics.js";
|
|
16
|
+
let intervalHandle;
|
|
17
|
+
export function startDbStatsCollector(opts) {
|
|
18
|
+
if (intervalHandle)
|
|
19
|
+
return;
|
|
20
|
+
const interval = opts.intervalMs ?? 30_000;
|
|
21
|
+
const runOnce = () => {
|
|
22
|
+
try {
|
|
23
|
+
collectDbStats(opts);
|
|
24
|
+
}
|
|
25
|
+
catch {
|
|
26
|
+
// never crash
|
|
27
|
+
}
|
|
28
|
+
};
|
|
29
|
+
runOnce();
|
|
30
|
+
intervalHandle = setInterval(runOnce, interval);
|
|
31
|
+
intervalHandle.unref?.();
|
|
32
|
+
}
|
|
33
|
+
export function stopDbStatsCollector() {
|
|
34
|
+
if (intervalHandle) {
|
|
35
|
+
clearInterval(intervalHandle);
|
|
36
|
+
intervalHandle = undefined;
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
export function collectDbStats(opts) {
|
|
40
|
+
// 1. DB file sizes (main + WAL + SHM).
|
|
41
|
+
const sizes = readDbSizes(opts.dbPath);
|
|
42
|
+
dbSizeBytes.set({ component: "main" }, sizes.main);
|
|
43
|
+
dbSizeBytes.set({ component: "wal" }, sizes.wal);
|
|
44
|
+
dbSizeBytes.set({ component: "shm" }, sizes.shm);
|
|
45
|
+
// 2. Chunk counts. Provenance enum is small (~5 values) — bucket
|
|
46
|
+
// everything not 'stale' as "active".
|
|
47
|
+
let active = 0;
|
|
48
|
+
let stale = 0;
|
|
49
|
+
try {
|
|
50
|
+
const rows = opts.query(`SELECT provenance_kind, COUNT(*) AS n FROM chunks GROUP BY provenance_kind`);
|
|
51
|
+
for (const r of rows) {
|
|
52
|
+
const kind = String(r.provenance_kind ?? "");
|
|
53
|
+
const n = Number(r.n ?? 0);
|
|
54
|
+
if (kind === "stale")
|
|
55
|
+
stale += n;
|
|
56
|
+
else
|
|
57
|
+
active += n;
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
catch {
|
|
61
|
+
// Schema may not exist yet — keep gauges at last value.
|
|
62
|
+
return;
|
|
63
|
+
}
|
|
64
|
+
chunksActive.set(active);
|
|
65
|
+
chunksStale.set(stale);
|
|
66
|
+
}
|
|
67
|
+
function readDbSizes(dbPath) {
|
|
68
|
+
const base = dbPath;
|
|
69
|
+
const dir = dirname(base);
|
|
70
|
+
// WAL / SHM are sibling files
|
|
71
|
+
return {
|
|
72
|
+
main: safeSize(base),
|
|
73
|
+
wal: safeSize(join(dir, `${baseName(base)}-wal`)),
|
|
74
|
+
shm: safeSize(join(dir, `${baseName(base)}-shm`)),
|
|
75
|
+
};
|
|
76
|
+
}
|
|
77
|
+
function baseName(p) {
|
|
78
|
+
const idx = p.lastIndexOf("/");
|
|
79
|
+
return idx >= 0 ? p.slice(idx + 1) : p;
|
|
80
|
+
}
|
|
81
|
+
function safeSize(p) {
|
|
82
|
+
try {
|
|
83
|
+
return statSync(p).size;
|
|
84
|
+
}
|
|
85
|
+
catch {
|
|
86
|
+
return 0;
|
|
87
|
+
}
|
|
88
|
+
}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
export interface EventBusLike {
|
|
2
|
+
on(event: string, handler: (payload: unknown) => void): void;
|
|
3
|
+
off?(event: string, handler: (payload: unknown) => void): void;
|
|
4
|
+
}
|
|
5
|
+
export declare function attachEventBusCollector(bus: EventBusLike): void;
|
|
6
|
+
export declare function detachEventBusCollector(bus: EventBusLike): void;
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* src/observability/collectors/eventbus.collector.ts
|
|
3
|
+
*
|
|
4
|
+
* Subscribes to the P5 event bus and translates events into viewer metrics.
|
|
5
|
+
*
|
|
6
|
+
* The event bus interface is intentionally minimal:
|
|
7
|
+
*
|
|
8
|
+
* interface EventBus {
|
|
9
|
+
* on(event: string, handler: (payload: { type: string; … }) => void): void;
|
|
10
|
+
* off(event: string, handler: Function): void;
|
|
11
|
+
* }
|
|
12
|
+
*
|
|
13
|
+
* Production wiring imports the actual `EventBus` from P5; tests pass a stub.
|
|
14
|
+
*/
|
|
15
|
+
import { recordViewerConnect, recordViewerDisconnect, recordViewerEvent, recordViewerDropped, } from "../record.js";
|
|
16
|
+
let handlers;
|
|
17
|
+
export function attachEventBusCollector(bus) {
|
|
18
|
+
if (handlers)
|
|
19
|
+
return; // idempotent
|
|
20
|
+
handlers = {
|
|
21
|
+
connect: () => recordViewerConnect(),
|
|
22
|
+
disconnect: () => recordViewerDisconnect(),
|
|
23
|
+
event: (payload) => {
|
|
24
|
+
const type = isObj(payload) && typeof payload.type === "string" ? payload.type : "other";
|
|
25
|
+
recordViewerEvent(type);
|
|
26
|
+
},
|
|
27
|
+
drop: (payload) => {
|
|
28
|
+
const reason = isObj(payload) && typeof payload.reason === "string"
|
|
29
|
+
? payload.reason
|
|
30
|
+
: "queue_full";
|
|
31
|
+
recordViewerDropped(reason);
|
|
32
|
+
},
|
|
33
|
+
};
|
|
34
|
+
bus.on("viewer.connect", handlers.connect);
|
|
35
|
+
bus.on("viewer.disconnect", handlers.disconnect);
|
|
36
|
+
bus.on("viewer.event", handlers.event);
|
|
37
|
+
bus.on("viewer.drop", handlers.drop);
|
|
38
|
+
}
|
|
39
|
+
export function detachEventBusCollector(bus) {
|
|
40
|
+
if (!handlers || !bus.off)
|
|
41
|
+
return;
|
|
42
|
+
bus.off("viewer.connect", handlers.connect);
|
|
43
|
+
bus.off("viewer.disconnect", handlers.disconnect);
|
|
44
|
+
bus.off("viewer.event", handlers.event);
|
|
45
|
+
bus.off("viewer.drop", handlers.drop);
|
|
46
|
+
handlers = undefined;
|
|
47
|
+
}
|
|
48
|
+
function isObj(v) {
|
|
49
|
+
return typeof v === "object" && v !== null;
|
|
50
|
+
}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
export interface ProcessCollectorOpts {
|
|
2
|
+
/** Sampling interval ms. Default 10_000. */
|
|
3
|
+
intervalMs?: number;
|
|
4
|
+
}
|
|
5
|
+
export declare function startProcessCollector(opts?: ProcessCollectorOpts): void;
|
|
6
|
+
export declare function stopProcessCollector(): void;
|
|
7
|
+
export declare function collectOnce(): void;
|
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* src/observability/collectors/process.collector.ts — Node runtime metrics.
|
|
3
|
+
*
|
|
4
|
+
* Periodically samples Node.js process stats into the corresponding gauges
|
|
5
|
+
* and counters. Intended to be wired by the API server bootstrap:
|
|
6
|
+
*
|
|
7
|
+
* import { startProcessCollector } from "./observability/collectors/process.collector.js";
|
|
8
|
+
* startProcessCollector();
|
|
9
|
+
*
|
|
10
|
+
* Sampling cadence is conservative (10s) to minimise CPU overhead.
|
|
11
|
+
*/
|
|
12
|
+
import { performance, monitorEventLoopDelay } from "node:perf_hooks";
|
|
13
|
+
import { processCpuUserSecondsTotal, processCpuSystemSecondsTotal, processResidentMemoryBytes, processOpenFds, nodejsEventloopLagSeconds, } from "../metrics.js";
|
|
14
|
+
let intervalHandle;
|
|
15
|
+
let lastCpu;
|
|
16
|
+
let elMonitor;
|
|
17
|
+
export function startProcessCollector(opts = {}) {
|
|
18
|
+
if (intervalHandle)
|
|
19
|
+
return; // idempotent
|
|
20
|
+
const interval = opts.intervalMs ?? 10_000;
|
|
21
|
+
elMonitor = monitorEventLoopDelay({ resolution: 50 });
|
|
22
|
+
elMonitor.enable();
|
|
23
|
+
lastCpu = process.cpuUsage();
|
|
24
|
+
intervalHandle = setInterval(() => {
|
|
25
|
+
try {
|
|
26
|
+
collectOnce();
|
|
27
|
+
}
|
|
28
|
+
catch {
|
|
29
|
+
// Never throw from a metrics sampler.
|
|
30
|
+
}
|
|
31
|
+
}, interval);
|
|
32
|
+
// Allow process to exit cleanly.
|
|
33
|
+
intervalHandle.unref?.();
|
|
34
|
+
// Take one immediate sample for fresh /metrics.
|
|
35
|
+
collectOnce();
|
|
36
|
+
}
|
|
37
|
+
export function stopProcessCollector() {
|
|
38
|
+
if (intervalHandle) {
|
|
39
|
+
clearInterval(intervalHandle);
|
|
40
|
+
intervalHandle = undefined;
|
|
41
|
+
}
|
|
42
|
+
if (elMonitor) {
|
|
43
|
+
elMonitor.disable();
|
|
44
|
+
elMonitor = undefined;
|
|
45
|
+
}
|
|
46
|
+
lastCpu = undefined;
|
|
47
|
+
}
|
|
48
|
+
export function collectOnce() {
|
|
49
|
+
// CPU — delta since last sample. Counter is monotonic, so we accumulate.
|
|
50
|
+
const cur = process.cpuUsage();
|
|
51
|
+
if (lastCpu) {
|
|
52
|
+
const userDeltaMicros = cur.user - lastCpu.user;
|
|
53
|
+
const sysDeltaMicros = cur.system - lastCpu.system;
|
|
54
|
+
if (userDeltaMicros > 0) {
|
|
55
|
+
processCpuUserSecondsTotal.inc({}, userDeltaMicros / 1e6);
|
|
56
|
+
}
|
|
57
|
+
if (sysDeltaMicros > 0) {
|
|
58
|
+
processCpuSystemSecondsTotal.inc({}, sysDeltaMicros / 1e6);
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
lastCpu = cur;
|
|
62
|
+
// Memory
|
|
63
|
+
const mem = process.memoryUsage();
|
|
64
|
+
processResidentMemoryBytes.set(mem.rss);
|
|
65
|
+
// Open FDs (POSIX-only best effort).
|
|
66
|
+
const fdCount = bestEffortFdCount();
|
|
67
|
+
if (fdCount >= 0)
|
|
68
|
+
processOpenFds.set(fdCount);
|
|
69
|
+
// Event loop lag — use mean since last sample then reset.
|
|
70
|
+
if (elMonitor) {
|
|
71
|
+
const meanNs = elMonitor.mean;
|
|
72
|
+
elMonitor.reset();
|
|
73
|
+
if (Number.isFinite(meanNs)) {
|
|
74
|
+
nodejsEventloopLagSeconds.set(meanNs / 1e9);
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
// Touch performance.now() so V8 doesn't dead-code-elim.
|
|
78
|
+
void performance.now();
|
|
79
|
+
}
|
|
80
|
+
function bestEffortFdCount() {
|
|
81
|
+
try {
|
|
82
|
+
// /proc/self/fd is Linux-specific.
|
|
83
|
+
if (process.platform !== "linux")
|
|
84
|
+
return -1;
|
|
85
|
+
// eslint-disable-next-line @typescript-eslint/no-require-imports
|
|
86
|
+
const fs = require("node:fs");
|
|
87
|
+
const list = fs.readdirSync("/proc/self/fd");
|
|
88
|
+
return list.length;
|
|
89
|
+
}
|
|
90
|
+
catch {
|
|
91
|
+
return -1;
|
|
92
|
+
}
|
|
93
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
export type DbQueryFn = (sql: string, params?: ReadonlyArray<string | number>) => Array<Record<string, unknown>>;
|
|
2
|
+
export interface ProviderTelemetryCollectorOpts {
|
|
3
|
+
query: DbQueryFn;
|
|
4
|
+
intervalMs?: number;
|
|
5
|
+
startId?: number;
|
|
6
|
+
}
|
|
7
|
+
export declare function startProviderTelemetryCollector(opts: ProviderTelemetryCollectorOpts): void;
|
|
8
|
+
export declare function stopProviderTelemetryCollector(): void;
|
|
9
|
+
export declare function drain(query: DbQueryFn): number;
|
|
10
|
+
export declare function getCursor(): number;
|
|
11
|
+
export declare function resetCursor(): void;
|
|
@@ -0,0 +1,112 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* src/observability/collectors/provider-telemetry.collector.ts
|
|
3
|
+
*
|
|
4
|
+
* Reads `provider_telemetry` (schema v11, A3) and translates rows into
|
|
5
|
+
* `nox_provider_*` metric increments.
|
|
6
|
+
*
|
|
7
|
+
* Columns (per A3 telemetry spec):
|
|
8
|
+
* ts, provider_id, model, kind ('embedding'|'llm'),
|
|
9
|
+
* tokens_in, tokens_out, cost_usd, latency_ms, ok (0|1),
|
|
10
|
+
* caller, session_id, error_kind
|
|
11
|
+
*
|
|
12
|
+
* Privacy: `error_kind` is already redacted at write time (see
|
|
13
|
+
* src/providers/telemetry.ts). We do NOT export caller or session_id.
|
|
14
|
+
*/
|
|
15
|
+
import { providerCallsTotal, providerDurationSeconds, providerCostUsdTotal, providerTokensTotal, auditRowsTotal, } from "../metrics.js";
|
|
16
|
+
import { guardLabels } from "../privacy-guard.js";
|
|
17
|
+
let intervalHandle;
|
|
18
|
+
let cursor = 0;
|
|
19
|
+
export function startProviderTelemetryCollector(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 stopProviderTelemetryCollector() {
|
|
37
|
+
if (intervalHandle) {
|
|
38
|
+
clearInterval(intervalHandle);
|
|
39
|
+
intervalHandle = undefined;
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
export function drain(query) {
|
|
43
|
+
const rows = query(`SELECT id, provider_id, model, kind, tokens_in, tokens_out,
|
|
44
|
+
cost_usd, latency_ms, ok
|
|
45
|
+
FROM provider_telemetry
|
|
46
|
+
WHERE id > ?
|
|
47
|
+
ORDER BY id ASC
|
|
48
|
+
LIMIT 1000`, [cursor]);
|
|
49
|
+
for (const r of rows) {
|
|
50
|
+
const id = Number(r.id);
|
|
51
|
+
const provider = String(r.provider_id ?? "other");
|
|
52
|
+
const model = String(r.model ?? "unknown");
|
|
53
|
+
const kind = String(r.kind ?? "llm");
|
|
54
|
+
const tokensIn = Number(r.tokens_in ?? 0);
|
|
55
|
+
const tokensOut = Number(r.tokens_out ?? 0);
|
|
56
|
+
const cost = Number(r.cost_usd ?? 0);
|
|
57
|
+
const latMs = Number(r.latency_ms ?? 0);
|
|
58
|
+
const ok = Number(r.ok ?? 0) === 1;
|
|
59
|
+
const outcome = ok ? "success" : "error";
|
|
60
|
+
const callL = guardLabels("nox_provider_calls_total", {
|
|
61
|
+
provider,
|
|
62
|
+
model,
|
|
63
|
+
outcome,
|
|
64
|
+
}).labels;
|
|
65
|
+
if (callL)
|
|
66
|
+
providerCallsTotal.inc(callL);
|
|
67
|
+
const durL = guardLabels("nox_provider_duration_seconds", {
|
|
68
|
+
provider,
|
|
69
|
+
kind,
|
|
70
|
+
}).labels;
|
|
71
|
+
if (durL)
|
|
72
|
+
providerDurationSeconds.observe(durL, latMs / 1000);
|
|
73
|
+
if (cost > 0) {
|
|
74
|
+
const costL = guardLabels("nox_provider_cost_usd_total", {
|
|
75
|
+
provider,
|
|
76
|
+
model,
|
|
77
|
+
}).labels;
|
|
78
|
+
if (costL)
|
|
79
|
+
providerCostUsdTotal.inc(costL, cost);
|
|
80
|
+
}
|
|
81
|
+
if (tokensIn > 0) {
|
|
82
|
+
const lbl = guardLabels("nox_provider_tokens_total", {
|
|
83
|
+
provider,
|
|
84
|
+
direction: "input",
|
|
85
|
+
}).labels;
|
|
86
|
+
if (lbl)
|
|
87
|
+
providerTokensTotal.inc(lbl, tokensIn);
|
|
88
|
+
}
|
|
89
|
+
if (tokensOut > 0) {
|
|
90
|
+
const lbl = guardLabels("nox_provider_tokens_total", {
|
|
91
|
+
provider,
|
|
92
|
+
direction: "output",
|
|
93
|
+
}).labels;
|
|
94
|
+
if (lbl)
|
|
95
|
+
providerTokensTotal.inc(lbl, tokensOut);
|
|
96
|
+
}
|
|
97
|
+
const auditL = guardLabels("nox_audit_rows_total", {
|
|
98
|
+
table: "provider_telemetry",
|
|
99
|
+
}).labels;
|
|
100
|
+
if (auditL)
|
|
101
|
+
auditRowsTotal.inc(auditL);
|
|
102
|
+
if (id > cursor)
|
|
103
|
+
cursor = id;
|
|
104
|
+
}
|
|
105
|
+
return rows.length;
|
|
106
|
+
}
|
|
107
|
+
export function getCursor() {
|
|
108
|
+
return cursor;
|
|
109
|
+
}
|
|
110
|
+
export function resetCursor() {
|
|
111
|
+
cursor = 0;
|
|
112
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
export type DbQueryFn = (sql: string, params?: ReadonlyArray<string | number>) => Array<Record<string, unknown>>;
|
|
2
|
+
export interface SearchTelemetryCollectorOpts {
|
|
3
|
+
query: DbQueryFn;
|
|
4
|
+
intervalMs?: number;
|
|
5
|
+
/** Initial cursor (id watermark). Default 0. */
|
|
6
|
+
startId?: number;
|
|
7
|
+
}
|
|
8
|
+
export declare function startSearchTelemetryCollector(opts: SearchTelemetryCollectorOpts): void;
|
|
9
|
+
export declare function stopSearchTelemetryCollector(): void;
|
|
10
|
+
export declare function drain(query: DbQueryFn): number;
|
|
11
|
+
export declare function getCursor(): number;
|
|
12
|
+
export declare function resetCursor(): void;
|