nox-mem 3.1.1 → 3.2.1
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/README.md +24 -16
- package/dist/__tests__/brief-diversity.test.js +266 -0
- package/dist/__tests__/brief.test.js +287 -0
- package/dist/__tests__/churn.test.js +66 -0
- package/dist/__tests__/edge-typing.test.js +99 -0
- package/dist/__tests__/ingest-event.test.js +151 -0
- package/dist/__tests__/op-audit-e2e.test.js +130 -0
- package/dist/__tests__/pragma-alignment.test.js +123 -0
- package/dist/__tests__/reranker.test.js +326 -0
- package/dist/__tests__/retention.test.js +99 -0
- package/dist/__tests__/search-track-access.test.js +49 -0
- package/dist/__tests__/spo-injection.test.js +172 -0
- package/dist/__tests__/temporal-detector.test.js +103 -0
- package/dist/api/wire-up.js +12 -381
- package/dist/api-server.js +6 -102
- package/dist/crystallize.js +3 -5
- package/dist/db.js +61 -2
- package/dist/embed.js +23 -2
- package/dist/index.js +1 -22
- package/dist/knowledge-graph.js +20 -0
- package/dist/lib/answer/__tests__/e2e-gemini.test.js +229 -0
- package/dist/lib/answer/__tests__/integration-sqlite.test.js +388 -0
- package/dist/lib/answer/__tests__/integration.test.js +347 -0
- package/dist/lib/answer/__tests__/prompt.test.js +117 -0
- package/dist/lib/answer/__tests__/t5-t10.test.js +501 -0
- package/dist/lib/answer/provider.js +29 -4
- package/dist/lib/api/__tests__/safe-error-message.test.js +155 -0
- package/dist/lib/auth/__tests__/localhost-guard.test.js +144 -0
- package/dist/lib/error-sanitizer/__tests__/sanitize.test.js +354 -0
- package/dist/lib/events/__tests__/bus.test.js +208 -0
- package/dist/lib/ingest-router.js +0 -43
- package/dist/lib/op-audit-extension/__tests__/ran-at-guard.test.js +109 -0
- package/dist/lib/regex-extract/__tests__/extractor.test.js +197 -0
- package/dist/lib/regex-extract/__tests__/frontmatter.test.js +75 -0
- package/dist/lib/regex-extract/__tests__/ingest-router-l4.test.js +139 -0
- package/dist/lib/regex-extract/__tests__/production-wire.test.js +177 -0
- package/dist/lib/regex-extract/__tests__/reconcile.test.js +170 -0
- package/dist/lib/regex-extract/__tests__/strip-code.test.js +36 -0
- package/dist/privacy/__tests__/filter.test.js +352 -0
- package/dist/providers/__tests__/conformance-extended.test.js +249 -0
- package/dist/providers/__tests__/conformance.test.js +98 -0
- package/dist/providers/__tests__/cost-cap.test.js +151 -0
- package/dist/providers/__tests__/e2e-real.test.js +79 -0
- package/dist/providers/__tests__/factory.test.js +80 -0
- package/dist/providers/__tests__/fallback.test.js +223 -0
- package/dist/providers/__tests__/gemini.test.js +191 -0
- package/dist/providers/__tests__/health.test.js +128 -0
- package/dist/providers/__tests__/telemetry.test.js +219 -0
- package/dist/reindex.js +2 -2
- package/package.json +3 -4
- package/dist/api/answer.d.ts +0 -116
- package/dist/api/answer.validate-patch.d.ts +0 -72
- package/dist/api/brief-diversity.d.ts +0 -64
- package/dist/api/brief.d.ts +0 -114
- package/dist/api/conflict.d.ts +0 -33
- package/dist/api/conflict.js +0 -143
- package/dist/api/cors.d.ts +0 -73
- package/dist/api/events-stream-limited.d.ts +0 -133
- package/dist/api/events-stream-limited.js +0 -217
- package/dist/api/events-stream.d.ts +0 -53
- package/dist/api/events-stream.js +0 -125
- package/dist/api/export.d.ts +0 -42
- package/dist/api/export.js +0 -85
- package/dist/api/health-confidence-adapter.d.ts +0 -29
- package/dist/api/health-confidence-adapter.js +0 -73
- package/dist/api/health-confidence.d.ts +0 -36
- package/dist/api/health-confidence.js +0 -141
- package/dist/api/hooks.d.ts +0 -50
- package/dist/api/hooks.js +0 -115
- package/dist/api/import.d.ts +0 -38
- package/dist/api/import.js +0 -87
- package/dist/api/ingest-event.d.ts +0 -65
- package/dist/api/mark.d.ts +0 -42
- package/dist/api/mark.js +0 -127
- package/dist/api/server-deps-a2.d.ts +0 -55
- package/dist/api/server-deps-a2.js +0 -138
- package/dist/api/server-deps-l2-l3.d.ts +0 -68
- package/dist/api/server-deps-l2-l3.js +0 -123
- package/dist/api/server-deps-p1.d.ts +0 -84
- package/dist/api/server-deps-p2.d.ts +0 -32
- package/dist/api/server-deps-p2.js +0 -84
- package/dist/api/server-deps-p5.d.ts +0 -66
- package/dist/api/server-deps-p5.js +0 -139
- package/dist/api/viewer-static.d.ts +0 -30
- package/dist/api/viewer-static.js +0 -102
- package/dist/api/wire-up.d.ts +0 -54
- package/dist/api-impact.d.ts +0 -30
- package/dist/api-server.d.ts +0 -2
- package/dist/backfill-fts-anchor.d.ts +0 -15
- package/dist/backfill-source-type.d.ts +0 -20
- package/dist/churn.d.ts +0 -31
- package/dist/cli/answer.d.ts +0 -66
- package/dist/cli/conflict.d.ts +0 -38
- package/dist/cli/conflict.js +0 -282
- package/dist/cli/export.d.ts +0 -51
- package/dist/cli/export.js +0 -280
- package/dist/cli/hooks.d.ts +0 -54
- package/dist/cli/hooks.js +0 -133
- package/dist/cli/import.d.ts +0 -52
- package/dist/cli/import.js +0 -274
- package/dist/cli/mark.d.ts +0 -33
- package/dist/cli/mark.js +0 -130
- package/dist/cli/ocr-batch.d.ts +0 -12
- package/dist/cli/ocr-batch.js +0 -411
- package/dist/cli/snapshot-main.d.ts +0 -30
- package/dist/cli/snapshot-main.js +0 -47
- package/dist/cli/viewer.d.ts +0 -35
- package/dist/cli/viewer.js +0 -71
- package/dist/cli-telemetry.d.ts +0 -36
- package/dist/cli-telemetry.js +0 -150
- package/dist/compact.d.ts +0 -7
- package/dist/consolidate.d.ts +0 -18
- package/dist/consolidation.d.ts +0 -32
- package/dist/cross-agent-v2.d.ts +0 -45
- package/dist/cross-search.d.ts +0 -11
- package/dist/crystallize.d.ts +0 -43
- package/dist/db.d.ts +0 -11
- package/dist/dedup.d.ts +0 -1
- package/dist/detect-changes.d.ts +0 -29
- package/dist/digest.d.ts +0 -1
- package/dist/doctor.d.ts +0 -1
- package/dist/embed.d.ts +0 -57
- package/dist/evals.d.ts +0 -176
- package/dist/evals.js +0 -351
- package/dist/generate-user-profile.d.ts +0 -18
- package/dist/graphify-ingest.d.ts +0 -18
- package/dist/impact.d.ts +0 -39
- package/dist/index.d.ts +0 -2
- package/dist/ingest-entity.d.ts +0 -44
- package/dist/ingest.d.ts +0 -13
- package/dist/kg-llm.d.ts +0 -39
- package/dist/knowledge-graph.d.ts +0 -72
- package/dist/lib/answer/config.d.ts +0 -41
- package/dist/lib/answer/index.d.ts +0 -47
- package/dist/lib/answer/prompt.d.ts +0 -37
- package/dist/lib/answer/provider.d.ts +0 -47
- package/dist/lib/answer/retrieval.d.ts +0 -36
- package/dist/lib/answer/telemetry.d.ts +0 -99
- package/dist/lib/answer/types.d.ts +0 -108
- package/dist/lib/api/error-leak-fix.d.ts +0 -54
- package/dist/lib/api/safe-error-message.d.ts +0 -70
- package/dist/lib/archive/common-passwords.d.ts +0 -37
- package/dist/lib/archive/common-passwords.js +0 -753
- package/dist/lib/archive/encryption.d.ts +0 -81
- package/dist/lib/archive/encryption.js +0 -236
- package/dist/lib/archive/enforce-strength.d.ts +0 -54
- package/dist/lib/archive/enforce-strength.js +0 -70
- package/dist/lib/archive/entropy.d.ts +0 -34
- package/dist/lib/archive/entropy.js +0 -180
- package/dist/lib/archive/export-locking.d.ts +0 -102
- package/dist/lib/archive/export-locking.js +0 -202
- package/dist/lib/archive/format.d.ts +0 -20
- package/dist/lib/archive/format.js +0 -174
- package/dist/lib/archive/index.d.ts +0 -23
- package/dist/lib/archive/index.js +0 -17
- package/dist/lib/archive/manifest.d.ts +0 -53
- package/dist/lib/archive/manifest.js +0 -183
- package/dist/lib/archive/migration.d.ts +0 -36
- package/dist/lib/archive/migration.js +0 -100
- package/dist/lib/archive/migrations/v18_to_v19.d.ts +0 -16
- package/dist/lib/archive/migrations/v18_to_v19.js +0 -18
- package/dist/lib/archive/orchestrator.d.ts +0 -166
- package/dist/lib/archive/orchestrator.js +0 -428
- package/dist/lib/archive/serializers/chunks.d.ts +0 -30
- package/dist/lib/archive/serializers/chunks.js +0 -113
- package/dist/lib/archive/serializers/embeddings.d.ts +0 -36
- package/dist/lib/archive/serializers/embeddings.js +0 -115
- package/dist/lib/archive/serializers/kg.d.ts +0 -28
- package/dist/lib/archive/serializers/kg.js +0 -184
- package/dist/lib/archive/serializers/ops_audit.d.ts +0 -21
- package/dist/lib/archive/serializers/ops_audit.js +0 -97
- package/dist/lib/archive/server-deps.d.ts +0 -131
- package/dist/lib/archive/server-deps.js +0 -232
- package/dist/lib/archive/strength.d.ts +0 -50
- package/dist/lib/archive/strength.js +0 -77
- package/dist/lib/archive/types.d.ts +0 -159
- package/dist/lib/archive/types.js +0 -45
- package/dist/lib/archive/unpack-streaming.d.ts +0 -70
- package/dist/lib/archive/unpack-streaming.js +0 -255
- package/dist/lib/auth/localhost-guard.d.ts +0 -106
- package/dist/lib/confidence/config.d.ts +0 -37
- package/dist/lib/confidence/config.js +0 -107
- package/dist/lib/confidence/db-shim-singleton.d.ts +0 -20
- package/dist/lib/confidence/db-shim-singleton.js +0 -41
- package/dist/lib/confidence/db-shim.d.ts +0 -47
- package/dist/lib/confidence/db-shim.js +0 -141
- package/dist/lib/confidence/mark.d.ts +0 -58
- package/dist/lib/confidence/mark.js +0 -168
- package/dist/lib/confidence/ranking.d.ts +0 -69
- package/dist/lib/confidence/ranking.js +0 -101
- package/dist/lib/confidence/search-filter.d.ts +0 -44
- package/dist/lib/confidence/search-filter.js +0 -103
- package/dist/lib/confidence/types.d.ts +0 -146
- package/dist/lib/confidence/types.js +0 -20
- package/dist/lib/confidence/write-hooks.d.ts +0 -50
- package/dist/lib/confidence/write-hooks.js +0 -159
- package/dist/lib/conflict/audit-fk-check.d.ts +0 -72
- package/dist/lib/conflict/audit-fk-check.js +0 -131
- package/dist/lib/conflict/audit-writer.d.ts +0 -39
- package/dist/lib/conflict/audit-writer.js +0 -133
- package/dist/lib/conflict/db-singleton.d.ts +0 -28
- package/dist/lib/conflict/db-singleton.js +0 -61
- package/dist/lib/conflict/db.d.ts +0 -27
- package/dist/lib/conflict/db.js +0 -20
- package/dist/lib/conflict/detector-direct.d.ts +0 -21
- package/dist/lib/conflict/detector-direct.js +0 -105
- package/dist/lib/conflict/evidence.d.ts +0 -24
- package/dist/lib/conflict/evidence.js +0 -76
- package/dist/lib/conflict/index.d.ts +0 -14
- package/dist/lib/conflict/index.js +0 -12
- package/dist/lib/conflict/scheduler.d.ts +0 -78
- package/dist/lib/conflict/scheduler.js +0 -111
- package/dist/lib/conflict/shadow.d.ts +0 -75
- package/dist/lib/conflict/shadow.js +0 -161
- package/dist/lib/conflict/types.d.ts +0 -133
- package/dist/lib/conflict/types.js +0 -19
- package/dist/lib/cost-cap.d.ts +0 -94
- package/dist/lib/deps/deps-registry.d.ts +0 -111
- package/dist/lib/error-sanitizer/middleware.d.ts +0 -43
- package/dist/lib/error-sanitizer/sanitize.d.ts +0 -78
- package/dist/lib/eval-batch.d.ts +0 -34
- package/dist/lib/eval-batch.js +0 -103
- package/dist/lib/eval-metrics.d.ts +0 -36
- package/dist/lib/eval-metrics.js +0 -95
- package/dist/lib/eval.d.ts +0 -106
- package/dist/lib/eval.js +0 -343
- package/dist/lib/events/bus.d.ts +0 -135
- package/dist/lib/fts-anchor.d.ts +0 -1
- package/dist/lib/hooks/classifier.d.ts +0 -47
- package/dist/lib/hooks/classifier.js +0 -129
- package/dist/lib/hooks/config.d.ts +0 -49
- package/dist/lib/hooks/config.js +0 -106
- package/dist/lib/hooks/decorators.d.ts +0 -35
- package/dist/lib/hooks/decorators.js +0 -59
- package/dist/lib/hooks/pipeline.d.ts +0 -76
- package/dist/lib/hooks/pipeline.js +0 -213
- package/dist/lib/hooks/privacy-filter-adapter.d.ts +0 -55
- package/dist/lib/hooks/privacy-filter-adapter.js +0 -84
- package/dist/lib/hooks/rate-limit-constant-time.d.ts +0 -57
- package/dist/lib/hooks/rate-limit-constant-time.js +0 -69
- package/dist/lib/hooks/rate-limit-dryrun-fix.d.ts +0 -71
- package/dist/lib/hooks/rate-limit-dryrun-fix.js +0 -110
- package/dist/lib/hooks/rate-limit.d.ts +0 -54
- package/dist/lib/hooks/rate-limit.js +0 -122
- package/dist/lib/hooks/server-deps.d.ts +0 -61
- package/dist/lib/hooks/server-deps.js +0 -92
- package/dist/lib/hooks/source-allowlist.d.ts +0 -26
- package/dist/lib/hooks/source-allowlist.js +0 -53
- package/dist/lib/hooks/types.d.ts +0 -129
- package/dist/lib/hooks/types.js +0 -24
- package/dist/lib/hooks/worker.d.ts +0 -56
- package/dist/lib/hooks/worker.js +0 -150
- package/dist/lib/ingest-router.d.ts +0 -25
- package/dist/lib/ocr-detector.d.ts +0 -61
- package/dist/lib/ocr-detector.js +0 -138
- package/dist/lib/ocr-engine-stub.d.ts +0 -48
- package/dist/lib/ocr-engine-stub.js +0 -190
- package/dist/lib/ocr-engines/google-doc-ai.d.ts +0 -36
- package/dist/lib/ocr-engines/google-doc-ai.js +0 -164
- package/dist/lib/ocr-jobs.d.ts +0 -67
- package/dist/lib/ocr-jobs.js +0 -129
- package/dist/lib/op-audit-extension/ran-at-guard.d.ts +0 -86
- package/dist/lib/op-audit.d.ts +0 -71
- package/dist/lib/privacy-br/detector.d.ts +0 -42
- package/dist/lib/privacy-br/detector.js +0 -130
- package/dist/lib/privacy-br/index.d.ts +0 -20
- package/dist/lib/privacy-br/index.js +0 -20
- package/dist/lib/privacy-br/integration.d.ts +0 -71
- package/dist/lib/privacy-br/integration.js +0 -74
- package/dist/lib/privacy-br/patterns.d.ts +0 -117
- package/dist/lib/privacy-br/patterns.js +0 -434
- package/dist/lib/privacy-br/redact.d.ts +0 -42
- package/dist/lib/privacy-br/redact.js +0 -103
- package/dist/lib/privacy-br/types.d.ts +0 -55
- package/dist/lib/privacy-br/types.js +0 -25
- package/dist/lib/regex-extract/extractor.d.ts +0 -30
- package/dist/lib/regex-extract/frontmatter.d.ts +0 -44
- package/dist/lib/regex-extract/index.d.ts +0 -14
- package/dist/lib/regex-extract/ingest-router-l4.d.ts +0 -76
- package/dist/lib/regex-extract/patterns.d.ts +0 -61
- package/dist/lib/regex-extract/production-wire.d.ts +0 -128
- package/dist/lib/regex-extract/reconcile.d.ts +0 -162
- package/dist/lib/regex-extract/strip-code.d.ts +0 -24
- package/dist/lib/regex-extract/types.d.ts +0 -48
- package/dist/lib/reranker.d.ts +0 -80
- package/dist/lib/shadow-tracker.d.ts +0 -191
- package/dist/lib/shadow-tracker.js +0 -384
- package/dist/lib/spo-injection.d.ts +0 -52
- package/dist/lib/telemetry-collector.d.ts +0 -158
- package/dist/lib/telemetry-collector.js +0 -249
- package/dist/lib/temporal-detector.d.ts +0 -27
- package/dist/lib/viewer/auth.d.ts +0 -37
- package/dist/lib/viewer/auth.js +0 -70
- package/dist/lib/viewer/backpressure.d.ts +0 -59
- package/dist/lib/viewer/backpressure.js +0 -100
- package/dist/lib/viewer/broadcast-singleton.d.ts +0 -34
- package/dist/lib/viewer/broadcast-singleton.js +0 -49
- package/dist/lib/viewer/broadcast.d.ts +0 -66
- package/dist/lib/viewer/broadcast.js +0 -96
- package/dist/lib/viewer/event-types.d.ts +0 -132
- package/dist/lib/viewer/event-types.js +0 -74
- package/dist/lib/viewer/instrumentation.d.ts +0 -106
- package/dist/lib/viewer/instrumentation.js +0 -224
- package/dist/lib/viewer/migration.d.ts +0 -23
- package/dist/lib/viewer/migration.js +0 -56
- package/dist/lib/viewer/redaction.d.ts +0 -44
- package/dist/lib/viewer/redaction.js +0 -139
- package/dist/lib/viewer/session.d.ts +0 -51
- package/dist/lib/viewer/session.js +0 -87
- package/dist/mcp/tools/answer.d.ts +0 -94
- package/dist/mcp/tools/archive.d.ts +0 -152
- package/dist/mcp/tools/archive.js +0 -170
- package/dist/mcp/tools/conflict.d.ts +0 -44
- package/dist/mcp/tools/conflict.js +0 -130
- package/dist/mcp/tools/hooks.d.ts +0 -29
- package/dist/mcp/tools/hooks.js +0 -78
- package/dist/mcp/tools/mark.d.ts +0 -38
- package/dist/mcp/tools/mark.js +0 -82
- package/dist/mcp/tools/viewer.d.ts +0 -58
- package/dist/mcp/tools/viewer.js +0 -64
- package/dist/mcp-server.d.ts +0 -2
- package/dist/metrics.d.ts +0 -3
- package/dist/noise-filter.d.ts +0 -18
- package/dist/notion-sync.d.ts +0 -7
- package/dist/notion-sync.js +0 -97
- package/dist/observability/adapters/a3-adapter.d.ts +0 -63
- package/dist/observability/adapters/a3-adapter.js +0 -83
- package/dist/observability/adapters/p1-adapter.d.ts +0 -49
- package/dist/observability/adapters/p1-adapter.js +0 -63
- package/dist/observability/adapters/p5-adapter.d.ts +0 -36
- package/dist/observability/adapters/p5-adapter.js +0 -71
- package/dist/observability/cardinality.d.ts +0 -61
- package/dist/observability/cardinality.js +0 -300
- package/dist/observability/collectors/db-stats.collector.d.ts +0 -9
- package/dist/observability/collectors/db-stats.collector.js +0 -88
- package/dist/observability/collectors/eventbus.collector.d.ts +0 -6
- package/dist/observability/collectors/eventbus.collector.js +0 -50
- package/dist/observability/collectors/process.collector.d.ts +0 -7
- package/dist/observability/collectors/process.collector.js +0 -93
- package/dist/observability/collectors/provider-telemetry.collector.d.ts +0 -11
- package/dist/observability/collectors/provider-telemetry.collector.js +0 -112
- package/dist/observability/collectors/search-telemetry.collector.d.ts +0 -12
- package/dist/observability/collectors/search-telemetry.collector.js +0 -76
- package/dist/observability/exporter.d.ts +0 -30
- package/dist/observability/exporter.js +0 -182
- package/dist/observability/index.d.ts +0 -22
- package/dist/observability/index.js +0 -21
- package/dist/observability/metrics.d.ts +0 -53
- package/dist/observability/metrics.js +0 -213
- package/dist/observability/privacy-guard.d.ts +0 -32
- package/dist/observability/privacy-guard.js +0 -116
- package/dist/observability/record.d.ts +0 -83
- package/dist/observability/record.js +0 -217
- package/dist/observability/registry.d.ts +0 -60
- package/dist/observability/registry.js +0 -93
- package/dist/observability/types.d.ts +0 -115
- package/dist/observability/types.js +0 -235
- package/dist/observability.d.ts +0 -131
- package/dist/plugins/nox-hooks/index.d.ts +0 -61
- package/dist/plugins/nox-hooks/index.js +0 -99
- package/dist/primer.d.ts +0 -1
- package/dist/privacy/filter.d.ts +0 -27
- package/dist/privacy/patterns.d.ts +0 -29
- package/dist/privacy/tag-parser.d.ts +0 -24
- package/dist/project-context-gen.d.ts +0 -10
- package/dist/providers/embedding/gemini.d.ts +0 -73
- package/dist/providers/embedding/openai.d.ts +0 -76
- package/dist/providers/embedding/types.d.ts +0 -39
- package/dist/providers/embedding/voyage.d.ts +0 -36
- package/dist/providers/index.d.ts +0 -116
- package/dist/providers/llm/anthropic.d.ts +0 -29
- package/dist/providers/llm/chain.d.ts +0 -99
- package/dist/providers/llm/gemini.d.ts +0 -48
- package/dist/providers/llm/openai.d.ts +0 -64
- package/dist/providers/llm/types.d.ts +0 -47
- package/dist/providers/telemetry.d.ts +0 -87
- package/dist/providers/types.d.ts +0 -42
- package/dist/query-entity-count.d.ts +0 -54
- package/dist/reflect.d.ts +0 -26
- package/dist/reindex-errors.d.ts +0 -7
- package/dist/reindex.d.ts +0 -16
- package/dist/retention.d.ts +0 -40
- package/dist/salience.d.ts +0 -85
- package/dist/scripts/migrate-v17-ops-audit.d.ts +0 -17
- package/dist/search-dedup.d.ts +0 -44
- package/dist/search-expansion.d.ts +0 -20
- package/dist/search.d.ts +0 -62
- package/dist/seh-detector.d.ts +0 -31
- package/dist/self-improve.d.ts +0 -1
- package/dist/session-distill.d.ts +0 -29
- package/dist/session-update.d.ts +0 -1
- package/dist/shared-memory.d.ts +0 -24
- package/dist/stats.d.ts +0 -1
- package/dist/temporal-retrieval.d.ts +0 -132
- package/dist/tier-manager.d.ts +0 -69
- package/dist/vectorize.d.ts +0 -16
- package/dist/version.d.ts +0 -1
- package/dist/watch.d.ts +0 -8
|
@@ -1,63 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* src/observability/adapters/p1-adapter.ts — P1 /api/answer instrumentation.
|
|
3
|
-
*
|
|
4
|
-
* Wraps the answer handler so every call emits:
|
|
5
|
-
* - nox_answer_requests_total{failure_reason}
|
|
6
|
-
* - nox_answer_duration_seconds{phase}
|
|
7
|
-
* - nox_answer_tokens_total{direction}
|
|
8
|
-
*
|
|
9
|
-
* Wiring example (in src/api/answer.ts):
|
|
10
|
-
*
|
|
11
|
-
* import { withAnswerMetrics } from "../observability/adapters/p1-adapter.js";
|
|
12
|
-
*
|
|
13
|
-
* export const answerHandler = withAnswerMetrics(async (req, res) => {
|
|
14
|
-
* // … existing logic
|
|
15
|
-
* return { outcome: "success", tokensIn, tokensOut, phases };
|
|
16
|
-
* });
|
|
17
|
-
*
|
|
18
|
-
* The wrapper expects the inner handler to return an `AnswerOutcome` object.
|
|
19
|
-
* That keeps metrics emission *external* to business logic — easy to unit
|
|
20
|
-
* test, easy to remove.
|
|
21
|
-
*/
|
|
22
|
-
import { recordAnswer, startTimer } from "../record.js";
|
|
23
|
-
/**
|
|
24
|
-
* Wrap an answer handler so it emits metrics on every call.
|
|
25
|
-
* The wrapped handler returns the same `AnswerResult` so callers can keep
|
|
26
|
-
* threading metadata to upstream layers.
|
|
27
|
-
*
|
|
28
|
-
* The wrapper never swallows the inner handler's errors — it just emits a
|
|
29
|
-
* "llm_failed" metric and re-throws.
|
|
30
|
-
*/
|
|
31
|
-
export function withAnswerMetrics(inner) {
|
|
32
|
-
return async (...args) => {
|
|
33
|
-
const end = startTimer();
|
|
34
|
-
try {
|
|
35
|
-
const result = await inner(...args);
|
|
36
|
-
recordAnswer({
|
|
37
|
-
outcome: result.outcome,
|
|
38
|
-
timing: { ...(result.timing ?? {}), total: result.timing?.total ?? end() },
|
|
39
|
-
tokensIn: result.tokensIn,
|
|
40
|
-
tokensOut: result.tokensOut,
|
|
41
|
-
});
|
|
42
|
-
return result;
|
|
43
|
-
}
|
|
44
|
-
catch (err) {
|
|
45
|
-
recordAnswer({
|
|
46
|
-
outcome: "llm_failed",
|
|
47
|
-
timing: { total: end() },
|
|
48
|
-
});
|
|
49
|
-
throw err;
|
|
50
|
-
}
|
|
51
|
-
};
|
|
52
|
-
}
|
|
53
|
-
/**
|
|
54
|
-
* Example — replace the existing /api/answer registration:
|
|
55
|
-
*
|
|
56
|
-
* // before:
|
|
57
|
-
* app.get("/api/answer", answerHandler);
|
|
58
|
-
*
|
|
59
|
-
* // after:
|
|
60
|
-
* app.get("/api/answer", withAnswerMetrics(answerHandler));
|
|
61
|
-
*
|
|
62
|
-
* Total integration footprint: 1 import + 1 wrapping call.
|
|
63
|
-
*/
|
|
@@ -1,36 +0,0 @@
|
|
|
1
|
-
export interface BroadcastEvent {
|
|
2
|
-
type: string;
|
|
3
|
-
[k: string]: unknown;
|
|
4
|
-
}
|
|
5
|
-
export type BroadcastFn = (event: BroadcastEvent) => void | Promise<void>;
|
|
6
|
-
/**
|
|
7
|
-
* Wrap a broadcast function so every emitted event is counted.
|
|
8
|
-
* If the inner broadcast throws, the event is counted as dropped/error and
|
|
9
|
-
* the error re-thrown.
|
|
10
|
-
*/
|
|
11
|
-
export declare function wrapBroadcast(inner: BroadcastFn): BroadcastFn;
|
|
12
|
-
export interface SocketLike {
|
|
13
|
-
on(event: "close" | "error" | string, listener: () => void): unknown;
|
|
14
|
-
}
|
|
15
|
-
/**
|
|
16
|
-
* Track a viewer SSE/WS connection lifecycle. Increments the gauge on entry
|
|
17
|
-
* and decrements when the socket closes (or errors).
|
|
18
|
-
*/
|
|
19
|
-
export declare function trackConnection(socket: SocketLike): void;
|
|
20
|
-
/**
|
|
21
|
-
* Manual backpressure reporting helper for upstream code paths that drop
|
|
22
|
-
* events without going through `wrapBroadcast`.
|
|
23
|
-
*/
|
|
24
|
-
export declare function reportBackpressureDrop(reason: "slow_consumer" | "queue_full" | "client_gone"): void;
|
|
25
|
-
/**
|
|
26
|
-
* Example — minimal wiring inside an existing SSE server:
|
|
27
|
-
*
|
|
28
|
-
* import { trackConnection, wrapBroadcast } from "./observability/adapters/p5-adapter.js";
|
|
29
|
-
*
|
|
30
|
-
* const broadcast = wrapBroadcast(rawBroadcast);
|
|
31
|
-
*
|
|
32
|
-
* sseRouter.get("/events", (req, res) => {
|
|
33
|
-
* trackConnection(res);
|
|
34
|
-
* subscribe((evt) => broadcast(evt));
|
|
35
|
-
* });
|
|
36
|
-
*/
|
|
@@ -1,71 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* src/observability/adapters/p5-adapter.ts — Viewer (P5) instrumentation.
|
|
3
|
-
*
|
|
4
|
-
* Two entry points:
|
|
5
|
-
* 1. `wrapBroadcast(broadcast)` — instruments the broadcast pipeline so
|
|
6
|
-
* every event emitted is counted by type.
|
|
7
|
-
* 2. `trackConnection(socket)` — increments/decrements the open
|
|
8
|
-
* connection gauge for the lifetime of the SSE/WS socket.
|
|
9
|
-
*
|
|
10
|
-
* Wiring example (in src/lib/viewer/broadcast.ts):
|
|
11
|
-
*
|
|
12
|
-
* import { wrapBroadcast, trackConnection } from "../../observability/adapters/p5-adapter.js";
|
|
13
|
-
*
|
|
14
|
-
* const safeBroadcast = wrapBroadcast(rawBroadcast);
|
|
15
|
-
* server.on("connection", (sock) => trackConnection(sock));
|
|
16
|
-
*
|
|
17
|
-
* The wiring is ~5 LOC at the integration site.
|
|
18
|
-
*/
|
|
19
|
-
import { recordViewerConnect, recordViewerDisconnect, recordViewerEvent, recordViewerDropped, } from "../record.js";
|
|
20
|
-
/**
|
|
21
|
-
* Wrap a broadcast function so every emitted event is counted.
|
|
22
|
-
* If the inner broadcast throws, the event is counted as dropped/error and
|
|
23
|
-
* the error re-thrown.
|
|
24
|
-
*/
|
|
25
|
-
export function wrapBroadcast(inner) {
|
|
26
|
-
return async (event) => {
|
|
27
|
-
try {
|
|
28
|
-
await inner(event);
|
|
29
|
-
recordViewerEvent(event.type);
|
|
30
|
-
}
|
|
31
|
-
catch (err) {
|
|
32
|
-
recordViewerDropped("queue_full");
|
|
33
|
-
throw err;
|
|
34
|
-
}
|
|
35
|
-
};
|
|
36
|
-
}
|
|
37
|
-
/**
|
|
38
|
-
* Track a viewer SSE/WS connection lifecycle. Increments the gauge on entry
|
|
39
|
-
* and decrements when the socket closes (or errors).
|
|
40
|
-
*/
|
|
41
|
-
export function trackConnection(socket) {
|
|
42
|
-
recordViewerConnect();
|
|
43
|
-
let decremented = false;
|
|
44
|
-
const onClose = () => {
|
|
45
|
-
if (decremented)
|
|
46
|
-
return;
|
|
47
|
-
decremented = true;
|
|
48
|
-
recordViewerDisconnect();
|
|
49
|
-
};
|
|
50
|
-
socket.on("close", onClose);
|
|
51
|
-
socket.on("error", onClose);
|
|
52
|
-
}
|
|
53
|
-
/**
|
|
54
|
-
* Manual backpressure reporting helper for upstream code paths that drop
|
|
55
|
-
* events without going through `wrapBroadcast`.
|
|
56
|
-
*/
|
|
57
|
-
export function reportBackpressureDrop(reason) {
|
|
58
|
-
recordViewerDropped(reason);
|
|
59
|
-
}
|
|
60
|
-
/**
|
|
61
|
-
* Example — minimal wiring inside an existing SSE server:
|
|
62
|
-
*
|
|
63
|
-
* import { trackConnection, wrapBroadcast } from "./observability/adapters/p5-adapter.js";
|
|
64
|
-
*
|
|
65
|
-
* const broadcast = wrapBroadcast(rawBroadcast);
|
|
66
|
-
*
|
|
67
|
-
* sseRouter.get("/events", (req, res) => {
|
|
68
|
-
* trackConnection(res);
|
|
69
|
-
* subscribe((evt) => broadcast(evt));
|
|
70
|
-
* });
|
|
71
|
-
*/
|
|
@@ -1,61 +0,0 @@
|
|
|
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
|
-
export interface MetricPolicy {
|
|
27
|
-
/** Max distinct label-tuple series allowed. Default 1000. */
|
|
28
|
-
maxSeries?: number;
|
|
29
|
-
/** Per-label allowlist of values. Unknown values → "other". */
|
|
30
|
-
labelAllowlist?: Record<string, readonly string[]>;
|
|
31
|
-
/** Per-label hard drop list (e.g. "user_id" must never appear). */
|
|
32
|
-
labelDenylist?: readonly string[];
|
|
33
|
-
}
|
|
34
|
-
export declare class CardinalityGuard {
|
|
35
|
-
private readonly policies;
|
|
36
|
-
private readonly seenSeries;
|
|
37
|
-
private readonly drops;
|
|
38
|
-
private readonly log;
|
|
39
|
-
constructor(log?: (msg: string) => void);
|
|
40
|
-
/** Configure a per-metric policy. */
|
|
41
|
-
policy(metricName: string, p: MetricPolicy): void;
|
|
42
|
-
/**
|
|
43
|
-
* Validate + normalize a label set for a metric.
|
|
44
|
-
* Returns the (possibly rewritten) labels — or `null` if it must be dropped.
|
|
45
|
-
*/
|
|
46
|
-
guard(metricName: string, labels: Record<string, string>): Record<string, string> | null;
|
|
47
|
-
/** Current series count for a metric. */
|
|
48
|
-
seriesCount(metricName: string): number;
|
|
49
|
-
/** Number of drops for a metric (since process start). */
|
|
50
|
-
dropCount(metricName: string): number;
|
|
51
|
-
/** Reset (test-only). */
|
|
52
|
-
reset(): void;
|
|
53
|
-
private noteDrop;
|
|
54
|
-
}
|
|
55
|
-
export declare function getDefaultGuard(): CardinalityGuard;
|
|
56
|
-
export declare function resetDefaultGuard(): void;
|
|
57
|
-
/**
|
|
58
|
-
* Apply nox-mem's standard policies. Keep this conservative — anything that
|
|
59
|
-
* could explode (user_id, query_text, paths) must be denylisted everywhere.
|
|
60
|
-
*/
|
|
61
|
-
export declare function applyDefaultPolicies(g: CardinalityGuard): void;
|
|
@@ -1,300 +0,0 @@
|
|
|
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
|
-
}
|
|
@@ -1,9 +0,0 @@
|
|
|
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;
|
|
@@ -1,88 +0,0 @@
|
|
|
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
|
-
}
|
|
@@ -1,6 +0,0 @@
|
|
|
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;
|
|
@@ -1,50 +0,0 @@
|
|
|
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
|
-
}
|