nox-mem 3.1.1 → 3.2.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/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/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,224 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* T2 — Event source instrumentation
|
|
3
|
-
*
|
|
4
|
-
* Adapter layer: subscribes to the P5a internal bus (`bus` singleton from
|
|
5
|
-
* `lib/events/bus.ts`) and converts each raw payload into a redacted
|
|
6
|
-
* `ViewerEvent` ready for the SSE feed.
|
|
7
|
-
*
|
|
8
|
-
* Design:
|
|
9
|
-
* - Single subscriber per kind — fan-out happens downstream (broadcast.ts).
|
|
10
|
-
* - Pure conversion: no I/O, no DB calls, no async — keep emit→adapter <1ms.
|
|
11
|
-
* - Output goes through `redactEvent()` so default-deny is enforced once.
|
|
12
|
-
*
|
|
13
|
-
* The bus dependency is injected as `BusLike` for tests so we can swap a
|
|
14
|
-
* mock EventEmitter without touching globals.
|
|
15
|
-
*/
|
|
16
|
-
import { EventEmitter } from "node:events";
|
|
17
|
-
import { nowIso, } from "./event-types.js";
|
|
18
|
-
import { redactEvent, queryHash, nameHash, safeBasename } from "./redaction.js";
|
|
19
|
-
// Event kind strings from P5a bus (must match `EventKind` in bus.ts).
|
|
20
|
-
const BUS_KINDS = {
|
|
21
|
-
CHUNK_CREATED: "chunk.created",
|
|
22
|
-
CHUNK_DELETED: "chunk.deleted",
|
|
23
|
-
KG_ENTITY_CREATED: "kg.entity.created",
|
|
24
|
-
KG_RELATION_CREATED: "kg.relation.created",
|
|
25
|
-
SEARCH_EXECUTED: "search.executed",
|
|
26
|
-
PROVIDER_CALL: "provider.call",
|
|
27
|
-
OP_AUDIT_STARTED: "op_audit.started",
|
|
28
|
-
OP_AUDIT_COMPLETED: "op_audit.completed",
|
|
29
|
-
HEALTH_WARNING: "health.warning",
|
|
30
|
-
};
|
|
31
|
-
// ─── Mappers (pure functions) ───────────────────────────────────────────────
|
|
32
|
-
export function mapChunkCreated(p) {
|
|
33
|
-
return {
|
|
34
|
-
ts: nowIso(),
|
|
35
|
-
type: "ingest",
|
|
36
|
-
source: "ingest-router",
|
|
37
|
-
summary: `chunk ${p.chunk_id} created (${p.type ?? "unknown"})`,
|
|
38
|
-
details: {
|
|
39
|
-
chunk_id: p.chunk_id,
|
|
40
|
-
chunk_kind: p.type ?? "unknown",
|
|
41
|
-
length: p.length ?? p.token_count ?? 0,
|
|
42
|
-
redaction_count: p.redaction_count ?? 0,
|
|
43
|
-
section: p.section ?? null,
|
|
44
|
-
retention_days: p.retention_days ?? null,
|
|
45
|
-
pain: p.pain ?? 0.2,
|
|
46
|
-
source_basename: safeBasename(p.source_file),
|
|
47
|
-
},
|
|
48
|
-
};
|
|
49
|
-
}
|
|
50
|
-
export function mapChunkDeleted(p) {
|
|
51
|
-
return {
|
|
52
|
-
ts: nowIso(),
|
|
53
|
-
type: "ingest",
|
|
54
|
-
source: "ingest-router",
|
|
55
|
-
summary: `chunk ${p.chunk_id} deleted`,
|
|
56
|
-
details: {
|
|
57
|
-
chunk_id: p.chunk_id,
|
|
58
|
-
chunk_kind: "deleted",
|
|
59
|
-
length: 0,
|
|
60
|
-
redaction_count: 0,
|
|
61
|
-
section: null,
|
|
62
|
-
retention_days: null,
|
|
63
|
-
pain: 0,
|
|
64
|
-
},
|
|
65
|
-
};
|
|
66
|
-
}
|
|
67
|
-
export function mapKgEntityCreated(p) {
|
|
68
|
-
return {
|
|
69
|
-
ts: nowIso(),
|
|
70
|
-
type: "kg",
|
|
71
|
-
source: "kg-extract",
|
|
72
|
-
summary: `KG entity ${p.entity_type} created`,
|
|
73
|
-
details: {
|
|
74
|
-
kg_kind: "entity_created",
|
|
75
|
-
entity_id: p.entity_id,
|
|
76
|
-
entity_type: p.entity_type,
|
|
77
|
-
name_hash: nameHash(p.name),
|
|
78
|
-
confidence: p.confidence ?? 1,
|
|
79
|
-
},
|
|
80
|
-
};
|
|
81
|
-
}
|
|
82
|
-
export function mapKgRelationCreated(p) {
|
|
83
|
-
return {
|
|
84
|
-
ts: nowIso(),
|
|
85
|
-
type: "kg",
|
|
86
|
-
source: "kg-extract",
|
|
87
|
-
summary: `KG relation ${p.relation_type} created`,
|
|
88
|
-
details: {
|
|
89
|
-
kg_kind: "relation_created",
|
|
90
|
-
relation_id: p.relation_id,
|
|
91
|
-
source_entity_id: p.source_entity_id,
|
|
92
|
-
target_entity_id: p.target_entity_id,
|
|
93
|
-
relation_type: p.relation_type,
|
|
94
|
-
confidence: p.confidence ?? 1,
|
|
95
|
-
},
|
|
96
|
-
};
|
|
97
|
-
}
|
|
98
|
-
export function mapSearchExecuted(p) {
|
|
99
|
-
const raw = p.query ?? "";
|
|
100
|
-
return {
|
|
101
|
-
ts: nowIso(),
|
|
102
|
-
type: "search",
|
|
103
|
-
source: "search-hybrid",
|
|
104
|
-
summary: `search ${p.mode ?? "hybrid"} ${p.latency_ms}ms`,
|
|
105
|
-
details: {
|
|
106
|
-
query_hash: p.query_hash ?? (raw ? queryHash(raw) : ""),
|
|
107
|
-
query: raw, // will be redacted unless NOX_VIEWER_SHOW_QUERY=1
|
|
108
|
-
latency_ms: p.latency_ms,
|
|
109
|
-
top_k: p.top_k,
|
|
110
|
-
result_count: p.result_count,
|
|
111
|
-
mode: p.mode ?? "hybrid",
|
|
112
|
-
hybrid_breakdown: {
|
|
113
|
-
bm25: p.bm25_score ?? 0,
|
|
114
|
-
vec: p.vec_score ?? 0,
|
|
115
|
-
kg: p.kg_score ?? 0,
|
|
116
|
-
},
|
|
117
|
-
},
|
|
118
|
-
};
|
|
119
|
-
}
|
|
120
|
-
export function mapOpAuditStarted(p) {
|
|
121
|
-
return {
|
|
122
|
-
ts: nowIso(),
|
|
123
|
-
type: "op_audit",
|
|
124
|
-
source: "op-audit",
|
|
125
|
-
summary: `${p.op_type} started`,
|
|
126
|
-
details: {
|
|
127
|
-
op_id: p.op_id,
|
|
128
|
-
op: p.op_type,
|
|
129
|
-
status: "started",
|
|
130
|
-
dry_run: p.dry_run ?? false,
|
|
131
|
-
},
|
|
132
|
-
};
|
|
133
|
-
}
|
|
134
|
-
export function mapOpAuditCompleted(p) {
|
|
135
|
-
return {
|
|
136
|
-
ts: nowIso(),
|
|
137
|
-
type: "op_audit",
|
|
138
|
-
source: "op-audit",
|
|
139
|
-
summary: `${p.op_type} ${p.status} in ${p.duration_ms}ms`,
|
|
140
|
-
details: {
|
|
141
|
-
op_id: p.op_id,
|
|
142
|
-
op: p.op_type,
|
|
143
|
-
status: p.status,
|
|
144
|
-
dry_run: false,
|
|
145
|
-
duration_ms: p.duration_ms,
|
|
146
|
-
rows_affected: p.rows_affected,
|
|
147
|
-
},
|
|
148
|
-
};
|
|
149
|
-
}
|
|
150
|
-
// ─── Crystallize emit helper (called directly by crystallize.ts) ─────────────
|
|
151
|
-
export function buildCrystallizeEvent(status, target_entity_id, source_chunk_count, duration_ms, redaction_count = 0) {
|
|
152
|
-
const out = {
|
|
153
|
-
ts: nowIso(),
|
|
154
|
-
type: "crystallize",
|
|
155
|
-
source: "crystallize",
|
|
156
|
-
summary: `crystallize entity ${target_entity_id} ${status}`,
|
|
157
|
-
details: {
|
|
158
|
-
source_chunk_count,
|
|
159
|
-
target_entity_id,
|
|
160
|
-
redaction_count,
|
|
161
|
-
status,
|
|
162
|
-
},
|
|
163
|
-
};
|
|
164
|
-
if (typeof duration_ms === "number")
|
|
165
|
-
out.details.duration_ms = duration_ms;
|
|
166
|
-
return out;
|
|
167
|
-
}
|
|
168
|
-
/**
|
|
169
|
-
* Attach to the P5a bus. Every relevant bus event is mapped and forwarded
|
|
170
|
-
* through `redactEvent()` to the consumer.
|
|
171
|
-
*/
|
|
172
|
-
export function attachInstrumentation(bus, opts) {
|
|
173
|
-
let count = 0;
|
|
174
|
-
const emit = (ev) => {
|
|
175
|
-
const safe = redactEvent(ev, { showQuery: opts.showQuery });
|
|
176
|
-
count += 1;
|
|
177
|
-
opts.onEvent(safe);
|
|
178
|
-
};
|
|
179
|
-
const handlers = [
|
|
180
|
-
[
|
|
181
|
-
BUS_KINDS.CHUNK_CREATED,
|
|
182
|
-
(p) => emit(mapChunkCreated(p)),
|
|
183
|
-
],
|
|
184
|
-
[
|
|
185
|
-
BUS_KINDS.CHUNK_DELETED,
|
|
186
|
-
(p) => emit(mapChunkDeleted(p)),
|
|
187
|
-
],
|
|
188
|
-
[
|
|
189
|
-
BUS_KINDS.KG_ENTITY_CREATED,
|
|
190
|
-
(p) => emit(mapKgEntityCreated(p)),
|
|
191
|
-
],
|
|
192
|
-
[
|
|
193
|
-
BUS_KINDS.KG_RELATION_CREATED,
|
|
194
|
-
(p) => emit(mapKgRelationCreated(p)),
|
|
195
|
-
],
|
|
196
|
-
[
|
|
197
|
-
BUS_KINDS.SEARCH_EXECUTED,
|
|
198
|
-
(p) => emit(mapSearchExecuted(p)),
|
|
199
|
-
],
|
|
200
|
-
[
|
|
201
|
-
BUS_KINDS.OP_AUDIT_STARTED,
|
|
202
|
-
(p) => emit(mapOpAuditStarted(p)),
|
|
203
|
-
],
|
|
204
|
-
[
|
|
205
|
-
BUS_KINDS.OP_AUDIT_COMPLETED,
|
|
206
|
-
(p) => emit(mapOpAuditCompleted(p)),
|
|
207
|
-
],
|
|
208
|
-
];
|
|
209
|
-
for (const [kind, fn] of handlers) {
|
|
210
|
-
bus.on(kind, fn);
|
|
211
|
-
}
|
|
212
|
-
return {
|
|
213
|
-
detach: () => {
|
|
214
|
-
for (const [kind, fn] of handlers) {
|
|
215
|
-
bus.off(kind, fn);
|
|
216
|
-
}
|
|
217
|
-
},
|
|
218
|
-
emitted: () => count,
|
|
219
|
-
};
|
|
220
|
-
}
|
|
221
|
-
/** Convenience: create a fresh isolated EventEmitter for tests. */
|
|
222
|
-
export function makeTestBus() {
|
|
223
|
-
return new EventEmitter();
|
|
224
|
-
}
|
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* T5 — Migration runner helper
|
|
3
|
-
*
|
|
4
|
-
* Reads `migrations/v20-viewer-telemetry.sql` and applies it to a
|
|
5
|
-
* better-sqlite3-compatible Database. Pure helper so tests can run with
|
|
6
|
-
* an in-memory shim and prod uses the real driver.
|
|
7
|
-
*/
|
|
8
|
-
export interface SqlExec {
|
|
9
|
-
exec(sql: string): void;
|
|
10
|
-
prepare(sql: string): {
|
|
11
|
-
all(...args: unknown[]): unknown[];
|
|
12
|
-
get(...args: unknown[]): unknown;
|
|
13
|
-
};
|
|
14
|
-
}
|
|
15
|
-
export interface MigrationResult {
|
|
16
|
-
applied: boolean;
|
|
17
|
-
/** user_version after migration. */
|
|
18
|
-
user_version: number;
|
|
19
|
-
/** True if tables / indexes were already present (idempotent run). */
|
|
20
|
-
idempotent_skip: boolean;
|
|
21
|
-
}
|
|
22
|
-
export declare function loadMigrationSql(): string;
|
|
23
|
-
export declare function applyMigration(db: SqlExec): MigrationResult;
|
|
@@ -1,56 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* T5 — Migration runner helper
|
|
3
|
-
*
|
|
4
|
-
* Reads `migrations/v20-viewer-telemetry.sql` and applies it to a
|
|
5
|
-
* better-sqlite3-compatible Database. Pure helper so tests can run with
|
|
6
|
-
* an in-memory shim and prod uses the real driver.
|
|
7
|
-
*/
|
|
8
|
-
import { readFileSync, existsSync } from "node:fs";
|
|
9
|
-
import { fileURLToPath } from "node:url";
|
|
10
|
-
import { dirname, join, resolve } from "node:path";
|
|
11
|
-
export function loadMigrationSql() {
|
|
12
|
-
const here = dirname(fileURLToPath(import.meta.url));
|
|
13
|
-
// Try multiple candidate locations:
|
|
14
|
-
// - source layout: edits/src/lib/viewer -> ../../../migrations/...
|
|
15
|
-
// - compiled layout (no edits in path): dist/src/lib/viewer -> ../../../../edits/migrations/...
|
|
16
|
-
const candidates = [
|
|
17
|
-
join(here, "..", "..", "..", "..", "migrations", "v20-viewer-telemetry.sql"),
|
|
18
|
-
join(here, "..", "..", "..", "..", "edits", "migrations", "v20-viewer-telemetry.sql"),
|
|
19
|
-
join(here, "..", "..", "..", "migrations", "v20-viewer-telemetry.sql"),
|
|
20
|
-
// Fallback: walk up looking for `migrations/v20-...` next to a package.json
|
|
21
|
-
findUpwards(here, "migrations/v20-viewer-telemetry.sql"),
|
|
22
|
-
].filter(Boolean);
|
|
23
|
-
for (const p of candidates) {
|
|
24
|
-
if (existsSync(p))
|
|
25
|
-
return readFileSync(p, "utf8");
|
|
26
|
-
}
|
|
27
|
-
throw new Error(`v20-viewer-telemetry.sql not found; searched: ${candidates.join(", ")}`);
|
|
28
|
-
}
|
|
29
|
-
function findUpwards(start, rel) {
|
|
30
|
-
let cur = resolve(start);
|
|
31
|
-
for (let i = 0; i < 8; i += 1) {
|
|
32
|
-
const candidate = join(cur, rel);
|
|
33
|
-
if (existsSync(candidate))
|
|
34
|
-
return candidate;
|
|
35
|
-
const editsCandidate = join(cur, "edits", rel);
|
|
36
|
-
if (existsSync(editsCandidate))
|
|
37
|
-
return editsCandidate;
|
|
38
|
-
const next = dirname(cur);
|
|
39
|
-
if (next === cur)
|
|
40
|
-
break;
|
|
41
|
-
cur = next;
|
|
42
|
-
}
|
|
43
|
-
return null;
|
|
44
|
-
}
|
|
45
|
-
export function applyMigration(db) {
|
|
46
|
-
const sql = loadMigrationSql();
|
|
47
|
-
// Detect if already applied by querying sqlite_master.
|
|
48
|
-
const present = db.prepare("SELECT name FROM sqlite_master WHERE type='table' AND name='viewer_telemetry'").get()?.name;
|
|
49
|
-
db.exec(sql);
|
|
50
|
-
const versionRow = db.prepare("PRAGMA user_version").get();
|
|
51
|
-
return {
|
|
52
|
-
applied: true,
|
|
53
|
-
user_version: versionRow?.user_version ?? 0,
|
|
54
|
-
idempotent_skip: Boolean(present),
|
|
55
|
-
};
|
|
56
|
-
}
|
|
@@ -1,44 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* T4 — Redaction / NOX_VIEWER_SHOW_QUERY opt-in
|
|
3
|
-
*
|
|
4
|
-
* Default-deny philosophy: SearchEvent.query, content fields, embeddings, and
|
|
5
|
-
* raw entity names are all redacted by default. Opt-IN via env var only.
|
|
6
|
-
*
|
|
7
|
-
* Env vars handled here:
|
|
8
|
-
* - NOX_VIEWER_SHOW_QUERY=1 → SearchEvent.query carries raw query text
|
|
9
|
-
*
|
|
10
|
-
* Boot-time WARN must be emitted by `viewerStartupWarnings()` whenever ANY
|
|
11
|
-
* privacy-loosening env is set so operators don't forget it on prod.
|
|
12
|
-
*/
|
|
13
|
-
import { type ViewerEvent } from "./event-types.js";
|
|
14
|
-
export declare const REDACTED = "<redacted>";
|
|
15
|
-
/** Stable, non-reversible label for a query string. */
|
|
16
|
-
export declare function queryHash(raw: string): string;
|
|
17
|
-
/** Stable, non-reversible label for an entity name. */
|
|
18
|
-
export declare function nameHash(raw: string): string;
|
|
19
|
-
/** Reduce an absolute path to just the basename. */
|
|
20
|
-
export declare function safeBasename(path: string | undefined | null): string | undefined;
|
|
21
|
-
export interface RedactionOptions {
|
|
22
|
-
/** Default reads NOX_VIEWER_SHOW_QUERY env. Pass explicit boolean for tests. */
|
|
23
|
-
showQuery?: boolean;
|
|
24
|
-
}
|
|
25
|
-
/**
|
|
26
|
-
* Apply redaction pass to a ViewerEvent before it leaves the process.
|
|
27
|
-
* Returns a NEW object — input is not mutated.
|
|
28
|
-
*
|
|
29
|
-
* Invariants:
|
|
30
|
-
* - SearchEvent.details.query MUST be `REDACTED` unless `showQuery` opts say otherwise.
|
|
31
|
-
* - No `content`, `body`, `text`, `embedding`, or `prompt` fields anywhere.
|
|
32
|
-
* - Absolute paths anywhere -> basename only.
|
|
33
|
-
*/
|
|
34
|
-
export declare function redactEvent(raw: ViewerEvent, opts?: RedactionOptions): ViewerEvent;
|
|
35
|
-
/**
|
|
36
|
-
* Recursively strip forbidden field names. Also reduces any string field
|
|
37
|
-
* that looks like an absolute path to its basename via heuristic.
|
|
38
|
-
*/
|
|
39
|
-
export declare function stripForbiddenFields(node: unknown): void;
|
|
40
|
-
/**
|
|
41
|
-
* Strings to print at boot when env flags expose more than default.
|
|
42
|
-
* Caller does the `console.warn` so it can route to logger of choice.
|
|
43
|
-
*/
|
|
44
|
-
export declare function viewerStartupWarnings(env?: NodeJS.ProcessEnv): string[];
|
|
@@ -1,139 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* T4 — Redaction / NOX_VIEWER_SHOW_QUERY opt-in
|
|
3
|
-
*
|
|
4
|
-
* Default-deny philosophy: SearchEvent.query, content fields, embeddings, and
|
|
5
|
-
* raw entity names are all redacted by default. Opt-IN via env var only.
|
|
6
|
-
*
|
|
7
|
-
* Env vars handled here:
|
|
8
|
-
* - NOX_VIEWER_SHOW_QUERY=1 → SearchEvent.query carries raw query text
|
|
9
|
-
*
|
|
10
|
-
* Boot-time WARN must be emitted by `viewerStartupWarnings()` whenever ANY
|
|
11
|
-
* privacy-loosening env is set so operators don't forget it on prod.
|
|
12
|
-
*/
|
|
13
|
-
import { createHash } from "node:crypto";
|
|
14
|
-
import { isSearchEvent, } from "./event-types.js";
|
|
15
|
-
export const REDACTED = "<redacted>";
|
|
16
|
-
/** Stable, non-reversible label for a query string. */
|
|
17
|
-
export function queryHash(raw) {
|
|
18
|
-
return createHash("sha256").update(raw).digest("hex").slice(0, 16);
|
|
19
|
-
}
|
|
20
|
-
/** Stable, non-reversible label for an entity name. */
|
|
21
|
-
export function nameHash(raw) {
|
|
22
|
-
return createHash("sha1").update(raw).digest("hex").slice(0, 8);
|
|
23
|
-
}
|
|
24
|
-
/** Reduce an absolute path to just the basename. */
|
|
25
|
-
export function safeBasename(path) {
|
|
26
|
-
if (!path)
|
|
27
|
-
return undefined;
|
|
28
|
-
const idx = Math.max(path.lastIndexOf("/"), path.lastIndexOf("\\"));
|
|
29
|
-
return idx >= 0 ? path.slice(idx + 1) : path;
|
|
30
|
-
}
|
|
31
|
-
/** Truthy env check tolerant of unset/null. */
|
|
32
|
-
function envOn(name) {
|
|
33
|
-
const v = (typeof process !== "undefined" ? process.env[name] : undefined) ?? "";
|
|
34
|
-
return v === "1" || v.toLowerCase() === "true" || v.toLowerCase() === "yes";
|
|
35
|
-
}
|
|
36
|
-
function showQueryEnabled(opts = {}) {
|
|
37
|
-
if (typeof opts.showQuery === "boolean")
|
|
38
|
-
return opts.showQuery;
|
|
39
|
-
return envOn("NOX_VIEWER_SHOW_QUERY");
|
|
40
|
-
}
|
|
41
|
-
/**
|
|
42
|
-
* Apply redaction pass to a ViewerEvent before it leaves the process.
|
|
43
|
-
* Returns a NEW object — input is not mutated.
|
|
44
|
-
*
|
|
45
|
-
* Invariants:
|
|
46
|
-
* - SearchEvent.details.query MUST be `REDACTED` unless `showQuery` opts say otherwise.
|
|
47
|
-
* - No `content`, `body`, `text`, `embedding`, or `prompt` fields anywhere.
|
|
48
|
-
* - Absolute paths anywhere -> basename only.
|
|
49
|
-
*/
|
|
50
|
-
export function redactEvent(raw, opts = {}) {
|
|
51
|
-
const showQuery = showQueryEnabled(opts);
|
|
52
|
-
// Deep-clone via structured pass (events are small POJOs).
|
|
53
|
-
const cloned = JSON.parse(JSON.stringify(raw));
|
|
54
|
-
if (isSearchEvent(cloned)) {
|
|
55
|
-
const details = cloned.details;
|
|
56
|
-
if (!showQuery) {
|
|
57
|
-
details.query = REDACTED;
|
|
58
|
-
}
|
|
59
|
-
}
|
|
60
|
-
// Strip universally forbidden fields if any sneaked in.
|
|
61
|
-
stripForbiddenFields(cloned);
|
|
62
|
-
return cloned;
|
|
63
|
-
}
|
|
64
|
-
const FORBIDDEN_FIELDS = new Set([
|
|
65
|
-
"content",
|
|
66
|
-
"body",
|
|
67
|
-
"text",
|
|
68
|
-
"raw_text",
|
|
69
|
-
"prompt",
|
|
70
|
-
"response",
|
|
71
|
-
"embedding",
|
|
72
|
-
"embedding_vector",
|
|
73
|
-
"vector",
|
|
74
|
-
"password",
|
|
75
|
-
"token",
|
|
76
|
-
"api_key",
|
|
77
|
-
"secret",
|
|
78
|
-
]);
|
|
79
|
-
/**
|
|
80
|
-
* Recursively strip forbidden field names. Also reduces any string field
|
|
81
|
-
* that looks like an absolute path to its basename via heuristic.
|
|
82
|
-
*/
|
|
83
|
-
export function stripForbiddenFields(node) {
|
|
84
|
-
if (!node || typeof node !== "object")
|
|
85
|
-
return;
|
|
86
|
-
if (Array.isArray(node)) {
|
|
87
|
-
for (let i = 0; i < node.length; i += 1) {
|
|
88
|
-
const v = node[i];
|
|
89
|
-
if (typeof v === "string" && looksLikeAbsolutePath(v)) {
|
|
90
|
-
node[i] = safeBasename(v);
|
|
91
|
-
}
|
|
92
|
-
else if (v && typeof v === "object") {
|
|
93
|
-
stripForbiddenFields(v);
|
|
94
|
-
}
|
|
95
|
-
}
|
|
96
|
-
return;
|
|
97
|
-
}
|
|
98
|
-
const obj = node;
|
|
99
|
-
for (const key of Object.keys(obj)) {
|
|
100
|
-
if (FORBIDDEN_FIELDS.has(key)) {
|
|
101
|
-
delete obj[key];
|
|
102
|
-
continue;
|
|
103
|
-
}
|
|
104
|
-
const val = obj[key];
|
|
105
|
-
if (typeof val === "string" && looksLikeAbsolutePath(val)) {
|
|
106
|
-
obj[key] = safeBasename(val);
|
|
107
|
-
}
|
|
108
|
-
else if (val && typeof val === "object") {
|
|
109
|
-
stripForbiddenFields(val);
|
|
110
|
-
}
|
|
111
|
-
}
|
|
112
|
-
}
|
|
113
|
-
function looksLikeAbsolutePath(s) {
|
|
114
|
-
// Match Unix absolute or Windows drive letter; require at least one slash
|
|
115
|
-
// and a few chars to dodge false positives on URLs / hashes / general text.
|
|
116
|
-
if (s.length < 4)
|
|
117
|
-
return false;
|
|
118
|
-
if (s.startsWith("/") && s.includes("/", 1) && !s.startsWith("//"))
|
|
119
|
-
return true;
|
|
120
|
-
if (/^[A-Za-z]:[\\\/]/.test(s))
|
|
121
|
-
return true;
|
|
122
|
-
return false;
|
|
123
|
-
}
|
|
124
|
-
/**
|
|
125
|
-
* Strings to print at boot when env flags expose more than default.
|
|
126
|
-
* Caller does the `console.warn` so it can route to logger of choice.
|
|
127
|
-
*/
|
|
128
|
-
export function viewerStartupWarnings(env = process.env) {
|
|
129
|
-
const out = [];
|
|
130
|
-
if (env.NOX_VIEWER_SHOW_QUERY === "1") {
|
|
131
|
-
out.push("[WARN] NOX_VIEWER_SHOW_QUERY=1 — raw queries visible on /api/events/stream. " +
|
|
132
|
-
"Do NOT enable in shared environments.");
|
|
133
|
-
}
|
|
134
|
-
if (env.NOX_VIEWER_BIND === "0.0.0.0" && !env.NOX_VIEWER_AUTH_TOKEN) {
|
|
135
|
-
out.push("[WARN] NOX_VIEWER_BIND=0.0.0.0 without NOX_VIEWER_AUTH_TOKEN — viewer reachable from network. " +
|
|
136
|
-
"Set NOX_VIEWER_AUTH_TOKEN or restrict bind.");
|
|
137
|
-
}
|
|
138
|
-
return out;
|
|
139
|
-
}
|
|
@@ -1,51 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* T8 — Client ID + session tracking
|
|
3
|
-
*
|
|
4
|
-
* Each SSE connection gets a UUIDv4 client_id (or accepts one from header
|
|
5
|
-
* `X-Viewer-Client-Id` / cookie `nox_viewer_id`). A session row is opened
|
|
6
|
-
* in `viewer_telemetry` on connect and finalized on disconnect.
|
|
7
|
-
*
|
|
8
|
-
* The actual DB write is delegated to a `SessionStore` interface so this
|
|
9
|
-
* module stays decoupled from the storage layer. The default in-memory
|
|
10
|
-
* store is suitable for tests and unit-test environments.
|
|
11
|
-
*/
|
|
12
|
-
export interface ViewerSessionRow {
|
|
13
|
-
id?: number;
|
|
14
|
-
client_id: string;
|
|
15
|
-
ts_start: string;
|
|
16
|
-
ts_last_event: string | null;
|
|
17
|
-
ts_end: string | null;
|
|
18
|
-
events_consumed: number;
|
|
19
|
-
events_dropped: number;
|
|
20
|
-
remote_label: string | null;
|
|
21
|
-
}
|
|
22
|
-
export interface SessionStore {
|
|
23
|
-
open(row: Omit<ViewerSessionRow, "id">): Promise<number>;
|
|
24
|
-
update(id: number, patch: Partial<ViewerSessionRow>): Promise<void>;
|
|
25
|
-
close(id: number, patch: Partial<ViewerSessionRow>): Promise<void>;
|
|
26
|
-
list(): Promise<readonly ViewerSessionRow[]>;
|
|
27
|
-
}
|
|
28
|
-
export declare class InMemorySessionStore implements SessionStore {
|
|
29
|
-
private rows;
|
|
30
|
-
open(row: Omit<ViewerSessionRow, "id">): Promise<number>;
|
|
31
|
-
update(id: number, patch: Partial<ViewerSessionRow>): Promise<void>;
|
|
32
|
-
close(id: number, patch: Partial<ViewerSessionRow>): Promise<void>;
|
|
33
|
-
list(): Promise<readonly ViewerSessionRow[]>;
|
|
34
|
-
}
|
|
35
|
-
export interface ClientIdSources {
|
|
36
|
-
headerXViewer?: string;
|
|
37
|
-
cookieHeader?: string;
|
|
38
|
-
}
|
|
39
|
-
export declare function extractClientId(src: ClientIdSources): string | null;
|
|
40
|
-
export declare function mintClientId(): string;
|
|
41
|
-
export declare function clientIdCookie(id: string, maxAgeSec?: number): string;
|
|
42
|
-
export declare function isValidUuid(s: string): boolean;
|
|
43
|
-
export interface SessionContext {
|
|
44
|
-
rowId: number;
|
|
45
|
-
client_id: string;
|
|
46
|
-
events_consumed: number;
|
|
47
|
-
events_dropped: number;
|
|
48
|
-
}
|
|
49
|
-
export declare function openSession(store: SessionStore, client_id: string, remote_label?: string | null): Promise<SessionContext>;
|
|
50
|
-
export declare function recordEvent(store: SessionStore, ctx: SessionContext, droppedDelta?: number): Promise<void>;
|
|
51
|
-
export declare function closeSession(store: SessionStore, ctx: SessionContext): Promise<void>;
|
|
@@ -1,87 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* T8 — Client ID + session tracking
|
|
3
|
-
*
|
|
4
|
-
* Each SSE connection gets a UUIDv4 client_id (or accepts one from header
|
|
5
|
-
* `X-Viewer-Client-Id` / cookie `nox_viewer_id`). A session row is opened
|
|
6
|
-
* in `viewer_telemetry` on connect and finalized on disconnect.
|
|
7
|
-
*
|
|
8
|
-
* The actual DB write is delegated to a `SessionStore` interface so this
|
|
9
|
-
* module stays decoupled from the storage layer. The default in-memory
|
|
10
|
-
* store is suitable for tests and unit-test environments.
|
|
11
|
-
*/
|
|
12
|
-
import { randomUUID } from "node:crypto";
|
|
13
|
-
import { nowIso } from "./event-types.js";
|
|
14
|
-
export class InMemorySessionStore {
|
|
15
|
-
rows = [];
|
|
16
|
-
async open(row) {
|
|
17
|
-
const id = this.rows.length + 1;
|
|
18
|
-
this.rows.push({ ...row, id });
|
|
19
|
-
return id;
|
|
20
|
-
}
|
|
21
|
-
async update(id, patch) {
|
|
22
|
-
const row = this.rows.find((r) => r.id === id);
|
|
23
|
-
if (row)
|
|
24
|
-
Object.assign(row, patch);
|
|
25
|
-
}
|
|
26
|
-
async close(id, patch) {
|
|
27
|
-
const row = this.rows.find((r) => r.id === id);
|
|
28
|
-
if (row)
|
|
29
|
-
Object.assign(row, patch, { ts_end: nowIso() });
|
|
30
|
-
}
|
|
31
|
-
async list() {
|
|
32
|
-
return this.rows.slice();
|
|
33
|
-
}
|
|
34
|
-
}
|
|
35
|
-
const COOKIE_NAME = "nox_viewer_id";
|
|
36
|
-
export function extractClientId(src) {
|
|
37
|
-
if (src.headerXViewer && isValidUuid(src.headerXViewer)) {
|
|
38
|
-
return src.headerXViewer;
|
|
39
|
-
}
|
|
40
|
-
if (src.cookieHeader) {
|
|
41
|
-
const parts = src.cookieHeader.split(/;\s*/);
|
|
42
|
-
for (const p of parts) {
|
|
43
|
-
const [k, v] = p.split("=");
|
|
44
|
-
if (k === COOKIE_NAME && v && isValidUuid(v))
|
|
45
|
-
return v;
|
|
46
|
-
}
|
|
47
|
-
}
|
|
48
|
-
return null;
|
|
49
|
-
}
|
|
50
|
-
export function mintClientId() {
|
|
51
|
-
return randomUUID();
|
|
52
|
-
}
|
|
53
|
-
export function clientIdCookie(id, maxAgeSec = 86400) {
|
|
54
|
-
return `${COOKIE_NAME}=${id}; Max-Age=${maxAgeSec}; Path=/; SameSite=Lax; HttpOnly`;
|
|
55
|
-
}
|
|
56
|
-
const UUID_RE = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i;
|
|
57
|
-
export function isValidUuid(s) {
|
|
58
|
-
return UUID_RE.test(s);
|
|
59
|
-
}
|
|
60
|
-
export async function openSession(store, client_id, remote_label = null) {
|
|
61
|
-
const row = {
|
|
62
|
-
client_id,
|
|
63
|
-
ts_start: nowIso(),
|
|
64
|
-
ts_last_event: null,
|
|
65
|
-
ts_end: null,
|
|
66
|
-
events_consumed: 0,
|
|
67
|
-
events_dropped: 0,
|
|
68
|
-
remote_label,
|
|
69
|
-
};
|
|
70
|
-
const rowId = await store.open(row);
|
|
71
|
-
return { rowId, client_id, events_consumed: 0, events_dropped: 0 };
|
|
72
|
-
}
|
|
73
|
-
export async function recordEvent(store, ctx, droppedDelta = 0) {
|
|
74
|
-
ctx.events_consumed += 1;
|
|
75
|
-
ctx.events_dropped += droppedDelta;
|
|
76
|
-
await store.update(ctx.rowId, {
|
|
77
|
-
ts_last_event: nowIso(),
|
|
78
|
-
events_consumed: ctx.events_consumed,
|
|
79
|
-
events_dropped: ctx.events_dropped,
|
|
80
|
-
});
|
|
81
|
-
}
|
|
82
|
-
export async function closeSession(store, ctx) {
|
|
83
|
-
await store.close(ctx.rowId, {
|
|
84
|
-
events_consumed: ctx.events_consumed,
|
|
85
|
-
events_dropped: ctx.events_dropped,
|
|
86
|
-
});
|
|
87
|
-
}
|