nox-mem 3.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +179 -0
- package/dist/api/answer.d.ts +116 -0
- package/dist/api/answer.js +274 -0
- package/dist/api/answer.validate-patch.d.ts +72 -0
- package/dist/api/answer.validate-patch.js +52 -0
- package/dist/api/brief-diversity.d.ts +64 -0
- package/dist/api/brief-diversity.js +91 -0
- package/dist/api/brief.d.ts +114 -0
- package/dist/api/brief.js +524 -0
- package/dist/api/conflict.d.ts +33 -0
- package/dist/api/conflict.js +143 -0
- package/dist/api/cors.d.ts +73 -0
- package/dist/api/cors.js +124 -0
- package/dist/api/events-stream-limited.d.ts +133 -0
- package/dist/api/events-stream-limited.js +217 -0
- package/dist/api/events-stream.d.ts +53 -0
- package/dist/api/events-stream.js +125 -0
- package/dist/api/export.d.ts +42 -0
- package/dist/api/export.js +85 -0
- package/dist/api/health-confidence-adapter.d.ts +29 -0
- package/dist/api/health-confidence-adapter.js +73 -0
- package/dist/api/health-confidence.d.ts +36 -0
- package/dist/api/health-confidence.js +141 -0
- package/dist/api/hooks.d.ts +50 -0
- package/dist/api/hooks.js +115 -0
- package/dist/api/import.d.ts +38 -0
- package/dist/api/import.js +87 -0
- package/dist/api/ingest-event.d.ts +65 -0
- package/dist/api/ingest-event.js +153 -0
- package/dist/api/mark.d.ts +42 -0
- package/dist/api/mark.js +127 -0
- package/dist/api/server-deps-a2.d.ts +55 -0
- package/dist/api/server-deps-a2.js +138 -0
- package/dist/api/server-deps-l2-l3.d.ts +68 -0
- package/dist/api/server-deps-l2-l3.js +123 -0
- package/dist/api/server-deps-p1.d.ts +84 -0
- package/dist/api/server-deps-p1.js +156 -0
- package/dist/api/server-deps-p2.d.ts +32 -0
- package/dist/api/server-deps-p2.js +84 -0
- package/dist/api/server-deps-p5.d.ts +66 -0
- package/dist/api/server-deps-p5.js +139 -0
- package/dist/api/viewer-static.d.ts +30 -0
- package/dist/api/viewer-static.js +102 -0
- package/dist/api/wire-up.d.ts +54 -0
- package/dist/api/wire-up.js +521 -0
- package/dist/api-impact.d.ts +30 -0
- package/dist/api-impact.js +196 -0
- package/dist/api-server.d.ts +2 -0
- package/dist/api-server.js +614 -0
- package/dist/backfill-fts-anchor.d.ts +15 -0
- package/dist/backfill-fts-anchor.js +97 -0
- package/dist/backfill-source-type.d.ts +20 -0
- package/dist/backfill-source-type.js +182 -0
- package/dist/churn.d.ts +31 -0
- package/dist/churn.js +98 -0
- package/dist/cli/answer.d.ts +66 -0
- package/dist/cli/answer.js +287 -0
- package/dist/cli/conflict.d.ts +38 -0
- package/dist/cli/conflict.js +282 -0
- package/dist/cli/export.d.ts +51 -0
- package/dist/cli/export.js +280 -0
- package/dist/cli/hooks.d.ts +54 -0
- package/dist/cli/hooks.js +133 -0
- package/dist/cli/import.d.ts +52 -0
- package/dist/cli/import.js +274 -0
- package/dist/cli/mark.d.ts +33 -0
- package/dist/cli/mark.js +130 -0
- package/dist/cli/ocr-batch.d.ts +12 -0
- package/dist/cli/ocr-batch.js +411 -0
- package/dist/cli/snapshot-main.d.ts +30 -0
- package/dist/cli/snapshot-main.js +47 -0
- package/dist/cli/viewer.d.ts +35 -0
- package/dist/cli/viewer.js +71 -0
- package/dist/cli-telemetry.d.ts +36 -0
- package/dist/cli-telemetry.js +150 -0
- package/dist/compact.d.ts +7 -0
- package/dist/compact.js +147 -0
- package/dist/consolidate.d.ts +18 -0
- package/dist/consolidate.js +475 -0
- package/dist/consolidation.d.ts +32 -0
- package/dist/consolidation.js +212 -0
- package/dist/cross-agent-v2.d.ts +45 -0
- package/dist/cross-agent-v2.js +271 -0
- package/dist/cross-search.d.ts +11 -0
- package/dist/cross-search.js +119 -0
- package/dist/crystallize.d.ts +43 -0
- package/dist/crystallize.js +111 -0
- package/dist/db.d.ts +11 -0
- package/dist/db.js +388 -0
- package/dist/dedup.d.ts +1 -0
- package/dist/dedup.js +106 -0
- package/dist/detect-changes.d.ts +29 -0
- package/dist/detect-changes.js +236 -0
- package/dist/digest.d.ts +1 -0
- package/dist/digest.js +205 -0
- package/dist/doctor.d.ts +1 -0
- package/dist/doctor.js +71 -0
- package/dist/embed.d.ts +45 -0
- package/dist/embed.js +257 -0
- package/dist/evals.d.ts +176 -0
- package/dist/evals.js +351 -0
- package/dist/generate-user-profile.d.ts +18 -0
- package/dist/generate-user-profile.js +163 -0
- package/dist/graphify-ingest.d.ts +18 -0
- package/dist/graphify-ingest.js +158 -0
- package/dist/impact.d.ts +39 -0
- package/dist/impact.js +143 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.js +689 -0
- package/dist/ingest-entity.d.ts +44 -0
- package/dist/ingest-entity.js +197 -0
- package/dist/ingest.d.ts +13 -0
- package/dist/ingest.js +210 -0
- package/dist/kg-llm.d.ts +39 -0
- package/dist/kg-llm.js +295 -0
- package/dist/knowledge-graph.d.ts +72 -0
- package/dist/knowledge-graph.js +507 -0
- package/dist/lib/answer/config.d.ts +41 -0
- package/dist/lib/answer/config.js +70 -0
- package/dist/lib/answer/index.d.ts +47 -0
- package/dist/lib/answer/index.js +221 -0
- package/dist/lib/answer/prompt.d.ts +37 -0
- package/dist/lib/answer/prompt.js +88 -0
- package/dist/lib/answer/provider.d.ts +47 -0
- package/dist/lib/answer/provider.js +101 -0
- package/dist/lib/answer/retrieval.d.ts +36 -0
- package/dist/lib/answer/retrieval.js +92 -0
- package/dist/lib/answer/telemetry.d.ts +99 -0
- package/dist/lib/answer/telemetry.js +154 -0
- package/dist/lib/answer/types.d.ts +108 -0
- package/dist/lib/answer/types.js +1 -0
- package/dist/lib/api/error-leak-fix.d.ts +54 -0
- package/dist/lib/api/error-leak-fix.js +55 -0
- package/dist/lib/api/safe-error-message.d.ts +70 -0
- package/dist/lib/api/safe-error-message.js +122 -0
- package/dist/lib/archive/common-passwords.d.ts +37 -0
- package/dist/lib/archive/common-passwords.js +753 -0
- package/dist/lib/archive/encryption.d.ts +81 -0
- package/dist/lib/archive/encryption.js +236 -0
- package/dist/lib/archive/enforce-strength.d.ts +54 -0
- package/dist/lib/archive/enforce-strength.js +70 -0
- package/dist/lib/archive/entropy.d.ts +34 -0
- package/dist/lib/archive/entropy.js +180 -0
- package/dist/lib/archive/export-locking.d.ts +102 -0
- package/dist/lib/archive/export-locking.js +202 -0
- package/dist/lib/archive/format.d.ts +20 -0
- package/dist/lib/archive/format.js +174 -0
- package/dist/lib/archive/index.d.ts +23 -0
- package/dist/lib/archive/index.js +17 -0
- package/dist/lib/archive/manifest.d.ts +53 -0
- package/dist/lib/archive/manifest.js +183 -0
- package/dist/lib/archive/migration.d.ts +36 -0
- package/dist/lib/archive/migration.js +100 -0
- package/dist/lib/archive/migrations/v18_to_v19.d.ts +16 -0
- package/dist/lib/archive/migrations/v18_to_v19.js +18 -0
- package/dist/lib/archive/orchestrator.d.ts +166 -0
- package/dist/lib/archive/orchestrator.js +428 -0
- package/dist/lib/archive/serializers/chunks.d.ts +30 -0
- package/dist/lib/archive/serializers/chunks.js +113 -0
- package/dist/lib/archive/serializers/embeddings.d.ts +36 -0
- package/dist/lib/archive/serializers/embeddings.js +115 -0
- package/dist/lib/archive/serializers/kg.d.ts +28 -0
- package/dist/lib/archive/serializers/kg.js +184 -0
- package/dist/lib/archive/serializers/ops_audit.d.ts +21 -0
- package/dist/lib/archive/serializers/ops_audit.js +97 -0
- package/dist/lib/archive/server-deps.d.ts +131 -0
- package/dist/lib/archive/server-deps.js +232 -0
- package/dist/lib/archive/strength.d.ts +50 -0
- package/dist/lib/archive/strength.js +77 -0
- package/dist/lib/archive/types.d.ts +159 -0
- package/dist/lib/archive/types.js +45 -0
- package/dist/lib/archive/unpack-streaming.d.ts +70 -0
- package/dist/lib/archive/unpack-streaming.js +255 -0
- package/dist/lib/auth/localhost-guard.d.ts +106 -0
- package/dist/lib/auth/localhost-guard.js +164 -0
- package/dist/lib/confidence/config.d.ts +37 -0
- package/dist/lib/confidence/config.js +107 -0
- package/dist/lib/confidence/db-shim-singleton.d.ts +20 -0
- package/dist/lib/confidence/db-shim-singleton.js +41 -0
- package/dist/lib/confidence/db-shim.d.ts +47 -0
- package/dist/lib/confidence/db-shim.js +141 -0
- package/dist/lib/confidence/mark.d.ts +58 -0
- package/dist/lib/confidence/mark.js +168 -0
- package/dist/lib/confidence/ranking.d.ts +69 -0
- package/dist/lib/confidence/ranking.js +101 -0
- package/dist/lib/confidence/search-filter.d.ts +44 -0
- package/dist/lib/confidence/search-filter.js +103 -0
- package/dist/lib/confidence/types.d.ts +146 -0
- package/dist/lib/confidence/types.js +20 -0
- package/dist/lib/confidence/write-hooks.d.ts +50 -0
- package/dist/lib/confidence/write-hooks.js +159 -0
- package/dist/lib/conflict/audit-fk-check.d.ts +72 -0
- package/dist/lib/conflict/audit-fk-check.js +131 -0
- package/dist/lib/conflict/audit-writer.d.ts +39 -0
- package/dist/lib/conflict/audit-writer.js +133 -0
- package/dist/lib/conflict/db-singleton.d.ts +28 -0
- package/dist/lib/conflict/db-singleton.js +61 -0
- package/dist/lib/conflict/db.d.ts +27 -0
- package/dist/lib/conflict/db.js +20 -0
- package/dist/lib/conflict/detector-direct.d.ts +21 -0
- package/dist/lib/conflict/detector-direct.js +105 -0
- package/dist/lib/conflict/evidence.d.ts +24 -0
- package/dist/lib/conflict/evidence.js +76 -0
- package/dist/lib/conflict/index.d.ts +14 -0
- package/dist/lib/conflict/index.js +12 -0
- package/dist/lib/conflict/scheduler.d.ts +78 -0
- package/dist/lib/conflict/scheduler.js +111 -0
- package/dist/lib/conflict/shadow.d.ts +75 -0
- package/dist/lib/conflict/shadow.js +161 -0
- package/dist/lib/conflict/types.d.ts +133 -0
- package/dist/lib/conflict/types.js +19 -0
- package/dist/lib/cost-cap.d.ts +94 -0
- package/dist/lib/cost-cap.js +129 -0
- package/dist/lib/deps/deps-registry.d.ts +111 -0
- package/dist/lib/deps/deps-registry.js +209 -0
- package/dist/lib/error-sanitizer/middleware.d.ts +43 -0
- package/dist/lib/error-sanitizer/middleware.js +100 -0
- package/dist/lib/error-sanitizer/sanitize.d.ts +78 -0
- package/dist/lib/error-sanitizer/sanitize.js +202 -0
- package/dist/lib/eval-batch.d.ts +34 -0
- package/dist/lib/eval-batch.js +103 -0
- package/dist/lib/eval-metrics.d.ts +36 -0
- package/dist/lib/eval-metrics.js +95 -0
- package/dist/lib/eval.d.ts +106 -0
- package/dist/lib/eval.js +343 -0
- package/dist/lib/events/bus.d.ts +135 -0
- package/dist/lib/events/bus.js +95 -0
- package/dist/lib/fts-anchor.d.ts +1 -0
- package/dist/lib/fts-anchor.js +131 -0
- package/dist/lib/hooks/classifier.d.ts +47 -0
- package/dist/lib/hooks/classifier.js +129 -0
- package/dist/lib/hooks/config.d.ts +49 -0
- package/dist/lib/hooks/config.js +106 -0
- package/dist/lib/hooks/decorators.d.ts +35 -0
- package/dist/lib/hooks/decorators.js +59 -0
- package/dist/lib/hooks/pipeline.d.ts +76 -0
- package/dist/lib/hooks/pipeline.js +213 -0
- package/dist/lib/hooks/privacy-filter-adapter.d.ts +55 -0
- package/dist/lib/hooks/privacy-filter-adapter.js +84 -0
- package/dist/lib/hooks/rate-limit-constant-time.d.ts +57 -0
- package/dist/lib/hooks/rate-limit-constant-time.js +69 -0
- package/dist/lib/hooks/rate-limit-dryrun-fix.d.ts +71 -0
- package/dist/lib/hooks/rate-limit-dryrun-fix.js +110 -0
- package/dist/lib/hooks/rate-limit.d.ts +54 -0
- package/dist/lib/hooks/rate-limit.js +122 -0
- package/dist/lib/hooks/server-deps.d.ts +61 -0
- package/dist/lib/hooks/server-deps.js +92 -0
- package/dist/lib/hooks/source-allowlist.d.ts +26 -0
- package/dist/lib/hooks/source-allowlist.js +53 -0
- package/dist/lib/hooks/types.d.ts +129 -0
- package/dist/lib/hooks/types.js +24 -0
- package/dist/lib/hooks/worker.d.ts +56 -0
- package/dist/lib/hooks/worker.js +150 -0
- package/dist/lib/ingest-router.d.ts +25 -0
- package/dist/lib/ingest-router.js +103 -0
- package/dist/lib/ocr-detector.d.ts +61 -0
- package/dist/lib/ocr-detector.js +138 -0
- package/dist/lib/ocr-engine-stub.d.ts +48 -0
- package/dist/lib/ocr-engine-stub.js +190 -0
- package/dist/lib/ocr-engines/google-doc-ai.d.ts +36 -0
- package/dist/lib/ocr-engines/google-doc-ai.js +164 -0
- package/dist/lib/ocr-jobs.d.ts +67 -0
- package/dist/lib/ocr-jobs.js +129 -0
- package/dist/lib/op-audit-extension/ran-at-guard.d.ts +86 -0
- package/dist/lib/op-audit-extension/ran-at-guard.js +110 -0
- package/dist/lib/op-audit.d.ts +71 -0
- package/dist/lib/op-audit.js +777 -0
- package/dist/lib/privacy-br/detector.d.ts +42 -0
- package/dist/lib/privacy-br/detector.js +130 -0
- package/dist/lib/privacy-br/index.d.ts +20 -0
- package/dist/lib/privacy-br/index.js +20 -0
- package/dist/lib/privacy-br/integration.d.ts +71 -0
- package/dist/lib/privacy-br/integration.js +74 -0
- package/dist/lib/privacy-br/patterns.d.ts +117 -0
- package/dist/lib/privacy-br/patterns.js +434 -0
- package/dist/lib/privacy-br/redact.d.ts +42 -0
- package/dist/lib/privacy-br/redact.js +103 -0
- package/dist/lib/privacy-br/types.d.ts +55 -0
- package/dist/lib/privacy-br/types.js +25 -0
- package/dist/lib/regex-extract/extractor.d.ts +30 -0
- package/dist/lib/regex-extract/extractor.js +91 -0
- package/dist/lib/regex-extract/frontmatter.d.ts +44 -0
- package/dist/lib/regex-extract/frontmatter.js +169 -0
- package/dist/lib/regex-extract/index.d.ts +14 -0
- package/dist/lib/regex-extract/index.js +14 -0
- package/dist/lib/regex-extract/ingest-router-l4.d.ts +76 -0
- package/dist/lib/regex-extract/ingest-router-l4.js +102 -0
- package/dist/lib/regex-extract/patterns.d.ts +61 -0
- package/dist/lib/regex-extract/patterns.js +91 -0
- package/dist/lib/regex-extract/production-wire.d.ts +128 -0
- package/dist/lib/regex-extract/production-wire.js +202 -0
- package/dist/lib/regex-extract/reconcile.d.ts +162 -0
- package/dist/lib/regex-extract/reconcile.js +210 -0
- package/dist/lib/regex-extract/strip-code.d.ts +24 -0
- package/dist/lib/regex-extract/strip-code.js +52 -0
- package/dist/lib/regex-extract/types.d.ts +48 -0
- package/dist/lib/regex-extract/types.js +25 -0
- package/dist/lib/reranker.d.ts +80 -0
- package/dist/lib/reranker.js +324 -0
- package/dist/lib/shadow-tracker.d.ts +191 -0
- package/dist/lib/shadow-tracker.js +384 -0
- package/dist/lib/spo-injection.d.ts +52 -0
- package/dist/lib/spo-injection.js +166 -0
- package/dist/lib/telemetry-collector.d.ts +158 -0
- package/dist/lib/telemetry-collector.js +249 -0
- package/dist/lib/temporal-detector.d.ts +27 -0
- package/dist/lib/temporal-detector.js +81 -0
- package/dist/lib/viewer/auth.d.ts +37 -0
- package/dist/lib/viewer/auth.js +70 -0
- package/dist/lib/viewer/backpressure.d.ts +59 -0
- package/dist/lib/viewer/backpressure.js +100 -0
- package/dist/lib/viewer/broadcast-singleton.d.ts +34 -0
- package/dist/lib/viewer/broadcast-singleton.js +49 -0
- package/dist/lib/viewer/broadcast.d.ts +66 -0
- package/dist/lib/viewer/broadcast.js +96 -0
- package/dist/lib/viewer/event-types.d.ts +132 -0
- package/dist/lib/viewer/event-types.js +74 -0
- package/dist/lib/viewer/instrumentation.d.ts +106 -0
- package/dist/lib/viewer/instrumentation.js +224 -0
- package/dist/lib/viewer/migration.d.ts +23 -0
- package/dist/lib/viewer/migration.js +56 -0
- package/dist/lib/viewer/redaction.d.ts +44 -0
- package/dist/lib/viewer/redaction.js +139 -0
- package/dist/lib/viewer/session.d.ts +51 -0
- package/dist/lib/viewer/session.js +87 -0
- package/dist/mcp/tools/answer.d.ts +94 -0
- package/dist/mcp/tools/answer.js +213 -0
- package/dist/mcp/tools/archive.d.ts +152 -0
- package/dist/mcp/tools/archive.js +170 -0
- package/dist/mcp/tools/conflict.d.ts +44 -0
- package/dist/mcp/tools/conflict.js +130 -0
- package/dist/mcp/tools/hooks.d.ts +29 -0
- package/dist/mcp/tools/hooks.js +78 -0
- package/dist/mcp/tools/mark.d.ts +38 -0
- package/dist/mcp/tools/mark.js +82 -0
- package/dist/mcp/tools/viewer.d.ts +58 -0
- package/dist/mcp/tools/viewer.js +64 -0
- package/dist/mcp-server.d.ts +2 -0
- package/dist/mcp-server.js +395 -0
- package/dist/metrics.d.ts +3 -0
- package/dist/metrics.js +59 -0
- package/dist/noise-filter.d.ts +18 -0
- package/dist/noise-filter.js +142 -0
- package/dist/notion-sync.d.ts +7 -0
- package/dist/notion-sync.js +97 -0
- package/dist/observability/adapters/a3-adapter.d.ts +63 -0
- package/dist/observability/adapters/a3-adapter.js +83 -0
- package/dist/observability/adapters/p1-adapter.d.ts +49 -0
- package/dist/observability/adapters/p1-adapter.js +63 -0
- package/dist/observability/adapters/p5-adapter.d.ts +36 -0
- package/dist/observability/adapters/p5-adapter.js +71 -0
- package/dist/observability/cardinality.d.ts +61 -0
- package/dist/observability/cardinality.js +300 -0
- package/dist/observability/collectors/db-stats.collector.d.ts +9 -0
- package/dist/observability/collectors/db-stats.collector.js +88 -0
- package/dist/observability/collectors/eventbus.collector.d.ts +6 -0
- package/dist/observability/collectors/eventbus.collector.js +50 -0
- package/dist/observability/collectors/process.collector.d.ts +7 -0
- package/dist/observability/collectors/process.collector.js +93 -0
- package/dist/observability/collectors/provider-telemetry.collector.d.ts +11 -0
- package/dist/observability/collectors/provider-telemetry.collector.js +112 -0
- package/dist/observability/collectors/search-telemetry.collector.d.ts +12 -0
- package/dist/observability/collectors/search-telemetry.collector.js +76 -0
- package/dist/observability/exporter.d.ts +30 -0
- package/dist/observability/exporter.js +182 -0
- package/dist/observability/index.d.ts +22 -0
- package/dist/observability/index.js +21 -0
- package/dist/observability/metrics.d.ts +53 -0
- package/dist/observability/metrics.js +213 -0
- package/dist/observability/privacy-guard.d.ts +32 -0
- package/dist/observability/privacy-guard.js +116 -0
- package/dist/observability/record.d.ts +83 -0
- package/dist/observability/record.js +217 -0
- package/dist/observability/registry.d.ts +60 -0
- package/dist/observability/registry.js +93 -0
- package/dist/observability/types.d.ts +115 -0
- package/dist/observability/types.js +235 -0
- package/dist/observability.d.ts +131 -0
- package/dist/observability.js +234 -0
- package/dist/plugins/nox-hooks/index.d.ts +61 -0
- package/dist/plugins/nox-hooks/index.js +99 -0
- package/dist/primer.d.ts +1 -0
- package/dist/primer.js +100 -0
- package/dist/privacy/filter.d.ts +27 -0
- package/dist/privacy/filter.js +74 -0
- package/dist/privacy/patterns.d.ts +29 -0
- package/dist/privacy/patterns.js +178 -0
- package/dist/privacy/tag-parser.d.ts +24 -0
- package/dist/privacy/tag-parser.js +29 -0
- package/dist/project-context-gen.d.ts +10 -0
- package/dist/project-context-gen.js +106 -0
- package/dist/providers/embedding/gemini.d.ts +73 -0
- package/dist/providers/embedding/gemini.js +118 -0
- package/dist/providers/embedding/openai.d.ts +76 -0
- package/dist/providers/embedding/openai.js +123 -0
- package/dist/providers/embedding/types.d.ts +39 -0
- package/dist/providers/embedding/types.js +1 -0
- package/dist/providers/embedding/voyage.d.ts +36 -0
- package/dist/providers/embedding/voyage.js +29 -0
- package/dist/providers/index.d.ts +116 -0
- package/dist/providers/index.js +158 -0
- package/dist/providers/llm/anthropic.d.ts +29 -0
- package/dist/providers/llm/anthropic.js +28 -0
- package/dist/providers/llm/chain.d.ts +99 -0
- package/dist/providers/llm/chain.js +213 -0
- package/dist/providers/llm/gemini.d.ts +48 -0
- package/dist/providers/llm/gemini.js +96 -0
- package/dist/providers/llm/openai.d.ts +64 -0
- package/dist/providers/llm/openai.js +109 -0
- package/dist/providers/llm/types.d.ts +47 -0
- package/dist/providers/llm/types.js +1 -0
- package/dist/providers/telemetry.d.ts +87 -0
- package/dist/providers/telemetry.js +156 -0
- package/dist/providers/types.d.ts +42 -0
- package/dist/providers/types.js +59 -0
- package/dist/query-entity-count.d.ts +54 -0
- package/dist/query-entity-count.js +171 -0
- package/dist/reflect.d.ts +26 -0
- package/dist/reflect.js +290 -0
- package/dist/reindex-errors.d.ts +7 -0
- package/dist/reindex-errors.js +21 -0
- package/dist/reindex.d.ts +16 -0
- package/dist/reindex.js +293 -0
- package/dist/retention.d.ts +40 -0
- package/dist/retention.js +86 -0
- package/dist/salience.d.ts +85 -0
- package/dist/salience.js +245 -0
- package/dist/scripts/migrate-v17-ops-audit.d.ts +17 -0
- package/dist/scripts/migrate-v17-ops-audit.js +70 -0
- package/dist/search-dedup.d.ts +44 -0
- package/dist/search-dedup.js +137 -0
- package/dist/search-expansion.d.ts +20 -0
- package/dist/search-expansion.js +99 -0
- package/dist/search.d.ts +62 -0
- package/dist/search.js +582 -0
- package/dist/seh-detector.d.ts +31 -0
- package/dist/seh-detector.js +201 -0
- package/dist/self-improve.d.ts +1 -0
- package/dist/self-improve.js +189 -0
- package/dist/session-distill.d.ts +29 -0
- package/dist/session-distill.js +325 -0
- package/dist/session-update.d.ts +1 -0
- package/dist/session-update.js +54 -0
- package/dist/shared-memory.d.ts +24 -0
- package/dist/shared-memory.js +104 -0
- package/dist/stats.d.ts +1 -0
- package/dist/stats.js +44 -0
- package/dist/temporal-retrieval.d.ts +132 -0
- package/dist/temporal-retrieval.js +495 -0
- package/dist/tier-manager.d.ts +69 -0
- package/dist/tier-manager.js +225 -0
- package/dist/vectorize.d.ts +16 -0
- package/dist/vectorize.js +91 -0
- package/dist/watch.d.ts +8 -0
- package/dist/watch.js +124 -0
- package/package.json +74 -0
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* src/api/server-deps-p2.ts — Wave O T5: P2 (hooks) wire-up adapter.
|
|
3
|
+
*
|
|
4
|
+
* Companion to `src/lib/hooks/server-deps.ts`. This module is the public
|
|
5
|
+
* entry the api/ layer + tests import from. It re-exports `buildHooksDeps`
|
|
6
|
+
* and adds two convenience helpers:
|
|
7
|
+
*
|
|
8
|
+
* - `getRecentMetadataOnly()` — direct DB query for the recent rows the
|
|
9
|
+
* wire-up + dashboard surface. Sanitization is identical to the inline
|
|
10
|
+
* code in staged-P2's `handleHooksRequest` (drops payload_json).
|
|
11
|
+
*
|
|
12
|
+
* - `dryRunHook(text, role, source)` — runs the 5-layer pipeline with
|
|
13
|
+
* dryRun=true and returns the trace. Mirrors the POST /api/hooks/dryrun
|
|
14
|
+
* handler but callable in-process for tests/dashboards.
|
|
15
|
+
*/
|
|
16
|
+
import { buildHooksDeps as buildHooksDepsImpl } from "../lib/hooks/server-deps.js";
|
|
17
|
+
export { buildHooksDeps, __setQueueProbeForTests, __resetHooksDepsForTests, } from "../lib/hooks/server-deps.js";
|
|
18
|
+
/**
|
|
19
|
+
* In-process dry-run for the hook pipeline. Lazy-loads staged-P2 modules.
|
|
20
|
+
* Returns null when staged-P2 is not deployed.
|
|
21
|
+
*/
|
|
22
|
+
export async function dryRunHook(text, role = "user", source = "api") {
|
|
23
|
+
// String indirection — files live in the staged-P2 tree, not co-located
|
|
24
|
+
// here. Production rsync places them at `src/lib/hooks/{config,pipeline}.js`.
|
|
25
|
+
const CONFIG_SPEC = "../lib/hooks/config.js";
|
|
26
|
+
const PIPELINE_SPEC = "../lib/hooks/pipeline.js";
|
|
27
|
+
let configMod;
|
|
28
|
+
let pipelineMod;
|
|
29
|
+
try {
|
|
30
|
+
configMod = await import(CONFIG_SPEC);
|
|
31
|
+
pipelineMod = await import(PIPELINE_SPEC);
|
|
32
|
+
}
|
|
33
|
+
catch {
|
|
34
|
+
return null;
|
|
35
|
+
}
|
|
36
|
+
if (!configMod?.loadConfig || !pipelineMod?.createPipeline)
|
|
37
|
+
return null;
|
|
38
|
+
const base = configMod.loadConfig();
|
|
39
|
+
const forced = {
|
|
40
|
+
...base,
|
|
41
|
+
enabled: true,
|
|
42
|
+
dryRun: true,
|
|
43
|
+
allowedSources: new Set([...(base.allowedSources ?? []), "api", "cli"]),
|
|
44
|
+
};
|
|
45
|
+
const trace = [];
|
|
46
|
+
const pipeline = pipelineMod.createPipeline({
|
|
47
|
+
config: forced,
|
|
48
|
+
telemetry: (row) => {
|
|
49
|
+
trace.push(row);
|
|
50
|
+
},
|
|
51
|
+
});
|
|
52
|
+
const event = {
|
|
53
|
+
event_id: `dr_${Math.random().toString(36).slice(2)}`,
|
|
54
|
+
source,
|
|
55
|
+
role,
|
|
56
|
+
content: text,
|
|
57
|
+
session_id: "api-dryrun",
|
|
58
|
+
project_slug: "api",
|
|
59
|
+
ts: new Date().toISOString(),
|
|
60
|
+
};
|
|
61
|
+
const result = await pipeline.run(event);
|
|
62
|
+
return {
|
|
63
|
+
result,
|
|
64
|
+
trace: trace.map((t) => {
|
|
65
|
+
let parsed = {};
|
|
66
|
+
try {
|
|
67
|
+
parsed = JSON.parse(t.payload_json ?? "{}");
|
|
68
|
+
}
|
|
69
|
+
catch {
|
|
70
|
+
/* ignore */
|
|
71
|
+
}
|
|
72
|
+
return {
|
|
73
|
+
layer: parsed.layer ?? "unknown",
|
|
74
|
+
reason: parsed.reason ?? "unknown",
|
|
75
|
+
redaction_count: t.redaction_count ?? 0,
|
|
76
|
+
kind: t.kind ?? "unknown",
|
|
77
|
+
};
|
|
78
|
+
}),
|
|
79
|
+
};
|
|
80
|
+
}
|
|
81
|
+
/** Force the deps builder to load (used by `await Promise.all` warmup). */
|
|
82
|
+
export async function warmupHooksDeps() {
|
|
83
|
+
await buildHooksDepsImpl();
|
|
84
|
+
}
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* src/api/server-deps-p5.ts — Wave O T3: P5 (SSE + viewer) runtime adapter.
|
|
3
|
+
*
|
|
4
|
+
* Wire-up.ts (#92) calls two P5 routes:
|
|
5
|
+
*
|
|
6
|
+
* GET /api/events/stream → events-stream.openSseStream + broadcast.getBroadcaster
|
|
7
|
+
* GET /viewer/* → viewer-static.serveViewerFile
|
|
8
|
+
*
|
|
9
|
+
* The Broadcaster singleton lives in `lib/viewer/broadcast-singleton.ts`
|
|
10
|
+
* (added in this PR). This module handles the redaction layer that wraps
|
|
11
|
+
* outbound SSE envelopes when `NOX_VIEWER_SHOW_QUERY=0` (the default).
|
|
12
|
+
*
|
|
13
|
+
* Redaction policy (default-deny, opt-in transparency):
|
|
14
|
+
* - `query_text` field on `search` events: redacted to `[redacted]`
|
|
15
|
+
* - `content` on `chunk` events: truncated to 40 chars + ellipsis
|
|
16
|
+
* - When NOX_VIEWER_SHOW_QUERY=1, redaction is bypassed
|
|
17
|
+
*
|
|
18
|
+
* Static serving:
|
|
19
|
+
* - `serveViewerFile()` from staged-P5 reads from `dist/viewer/` by default.
|
|
20
|
+
* - This adapter exposes `resolveViewerRoot()` so deployments can override
|
|
21
|
+
* via NOX_VIEWER_ROOT env (useful in dev when assets live outside dist).
|
|
22
|
+
*
|
|
23
|
+
* Build-time decoupling: like the other adapters, this file uses dynamic
|
|
24
|
+
* imports of `./events-stream.js` and `./viewer-static.js` so the staged
|
|
25
|
+
* adapters compile without staged-P5 sources present. At runtime in prod,
|
|
26
|
+
* those files are co-located after rsync.
|
|
27
|
+
*/
|
|
28
|
+
import type { IncomingMessage, ServerResponse } from "node:http";
|
|
29
|
+
interface BroadcastEnvelopeLike {
|
|
30
|
+
id: number;
|
|
31
|
+
ev: Record<string, unknown>;
|
|
32
|
+
}
|
|
33
|
+
/** Returns true when NOX_VIEWER_SHOW_QUERY=1 (transparency opt-in). */
|
|
34
|
+
export declare function viewerShowQueryEnabled(): boolean;
|
|
35
|
+
/**
|
|
36
|
+
* Redact sensitive fields on a viewer event envelope.
|
|
37
|
+
* Returns a NEW object — never mutates the original (the same envelope is
|
|
38
|
+
* pushed to many clients; mutation would leak the redaction across clients
|
|
39
|
+
* with different consent levels in future).
|
|
40
|
+
*/
|
|
41
|
+
export declare function redactEnvelope(env: BroadcastEnvelopeLike): BroadcastEnvelopeLike;
|
|
42
|
+
/**
|
|
43
|
+
* Resolve the static-serve root. Defaults to the staged-P5 location
|
|
44
|
+
* `${cwd}/dist/viewer/`. Override via NOX_VIEWER_ROOT.
|
|
45
|
+
*/
|
|
46
|
+
export declare function resolveViewerRoot(): string;
|
|
47
|
+
/**
|
|
48
|
+
* Wire-up.ts already imports `events-stream.js::openSseStream` directly.
|
|
49
|
+
* This adapter exists for callers that want the broadcaster pre-configured
|
|
50
|
+
* with the redaction wrapper.
|
|
51
|
+
*
|
|
52
|
+
* The redaction is applied at the `onWrite` hook (not by replacing envelopes
|
|
53
|
+
* in the ring), so different consent levels can co-exist in the future.
|
|
54
|
+
*/
|
|
55
|
+
export declare function openRedactedSseStream(opts: {
|
|
56
|
+
clientId: string;
|
|
57
|
+
lastEventId?: number;
|
|
58
|
+
heartbeatMs?: number;
|
|
59
|
+
}): Promise<{
|
|
60
|
+
headers: Record<string, string>;
|
|
61
|
+
iter: AsyncIterable<string>;
|
|
62
|
+
close: () => void;
|
|
63
|
+
} | null>;
|
|
64
|
+
/** Pipe an iter to a ServerResponse, returning when the iter completes. */
|
|
65
|
+
export declare function pumpSseToResponse(res: ServerResponse, iter: AsyncIterable<string>, req: IncomingMessage, close: () => void): Promise<void>;
|
|
66
|
+
export {};
|
|
@@ -0,0 +1,139 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* src/api/server-deps-p5.ts — Wave O T3: P5 (SSE + viewer) runtime adapter.
|
|
3
|
+
*
|
|
4
|
+
* Wire-up.ts (#92) calls two P5 routes:
|
|
5
|
+
*
|
|
6
|
+
* GET /api/events/stream → events-stream.openSseStream + broadcast.getBroadcaster
|
|
7
|
+
* GET /viewer/* → viewer-static.serveViewerFile
|
|
8
|
+
*
|
|
9
|
+
* The Broadcaster singleton lives in `lib/viewer/broadcast-singleton.ts`
|
|
10
|
+
* (added in this PR). This module handles the redaction layer that wraps
|
|
11
|
+
* outbound SSE envelopes when `NOX_VIEWER_SHOW_QUERY=0` (the default).
|
|
12
|
+
*
|
|
13
|
+
* Redaction policy (default-deny, opt-in transparency):
|
|
14
|
+
* - `query_text` field on `search` events: redacted to `[redacted]`
|
|
15
|
+
* - `content` on `chunk` events: truncated to 40 chars + ellipsis
|
|
16
|
+
* - When NOX_VIEWER_SHOW_QUERY=1, redaction is bypassed
|
|
17
|
+
*
|
|
18
|
+
* Static serving:
|
|
19
|
+
* - `serveViewerFile()` from staged-P5 reads from `dist/viewer/` by default.
|
|
20
|
+
* - This adapter exposes `resolveViewerRoot()` so deployments can override
|
|
21
|
+
* via NOX_VIEWER_ROOT env (useful in dev when assets live outside dist).
|
|
22
|
+
*
|
|
23
|
+
* Build-time decoupling: like the other adapters, this file uses dynamic
|
|
24
|
+
* imports of `./events-stream.js` and `./viewer-static.js` so the staged
|
|
25
|
+
* adapters compile without staged-P5 sources present. At runtime in prod,
|
|
26
|
+
* those files are co-located after rsync.
|
|
27
|
+
*/
|
|
28
|
+
import { resolve as pathResolve } from "node:path";
|
|
29
|
+
/** Returns true when NOX_VIEWER_SHOW_QUERY=1 (transparency opt-in). */
|
|
30
|
+
export function viewerShowQueryEnabled() {
|
|
31
|
+
const v = process.env["NOX_VIEWER_SHOW_QUERY"];
|
|
32
|
+
return v === "1" || v === "true" || v === "yes";
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* Redact sensitive fields on a viewer event envelope.
|
|
36
|
+
* Returns a NEW object — never mutates the original (the same envelope is
|
|
37
|
+
* pushed to many clients; mutation would leak the redaction across clients
|
|
38
|
+
* with different consent levels in future).
|
|
39
|
+
*/
|
|
40
|
+
export function redactEnvelope(env) {
|
|
41
|
+
if (viewerShowQueryEnabled())
|
|
42
|
+
return env;
|
|
43
|
+
const ev = env.ev;
|
|
44
|
+
const cloned = { ...ev };
|
|
45
|
+
if (typeof cloned["query_text"] === "string") {
|
|
46
|
+
cloned["query_text"] = "[redacted]";
|
|
47
|
+
}
|
|
48
|
+
if (typeof cloned["content"] === "string") {
|
|
49
|
+
const s = cloned["content"];
|
|
50
|
+
cloned["content"] = s.length > 40 ? `${s.slice(0, 40)}…` : s;
|
|
51
|
+
}
|
|
52
|
+
// Nested chunks array on `search` events.
|
|
53
|
+
if (Array.isArray(cloned["chunks"])) {
|
|
54
|
+
cloned["chunks"] = cloned["chunks"].map((c) => {
|
|
55
|
+
if (c && typeof c === "object" && "content" in c) {
|
|
56
|
+
const inner = c;
|
|
57
|
+
const text = inner["content"];
|
|
58
|
+
return {
|
|
59
|
+
...inner,
|
|
60
|
+
content: typeof text === "string" && text.length > 40
|
|
61
|
+
? `${text.slice(0, 40)}…`
|
|
62
|
+
: text,
|
|
63
|
+
};
|
|
64
|
+
}
|
|
65
|
+
return c;
|
|
66
|
+
});
|
|
67
|
+
}
|
|
68
|
+
return { id: env.id, ev: cloned };
|
|
69
|
+
}
|
|
70
|
+
// ─── Viewer root resolution ──────────────────────────────────────────────────
|
|
71
|
+
/**
|
|
72
|
+
* Resolve the static-serve root. Defaults to the staged-P5 location
|
|
73
|
+
* `${cwd}/dist/viewer/`. Override via NOX_VIEWER_ROOT.
|
|
74
|
+
*/
|
|
75
|
+
export function resolveViewerRoot() {
|
|
76
|
+
if (process.env["NOX_VIEWER_ROOT"]) {
|
|
77
|
+
return pathResolve(process.env["NOX_VIEWER_ROOT"]);
|
|
78
|
+
}
|
|
79
|
+
return pathResolve(process.cwd(), "dist", "viewer");
|
|
80
|
+
}
|
|
81
|
+
// ─── SSE adapter (broadcaster + redaction integration) ───────────────────────
|
|
82
|
+
/**
|
|
83
|
+
* Wire-up.ts already imports `events-stream.js::openSseStream` directly.
|
|
84
|
+
* This adapter exists for callers that want the broadcaster pre-configured
|
|
85
|
+
* with the redaction wrapper.
|
|
86
|
+
*
|
|
87
|
+
* The redaction is applied at the `onWrite` hook (not by replacing envelopes
|
|
88
|
+
* in the ring), so different consent levels can co-exist in the future.
|
|
89
|
+
*/
|
|
90
|
+
export async function openRedactedSseStream(opts) {
|
|
91
|
+
// String indirection — these files live in staged-P5, co-located only
|
|
92
|
+
// after production rsync. In the staged-wire-up-adapters tree they aren't
|
|
93
|
+
// present, so the dynamic import fails and we return null.
|
|
94
|
+
const SSE_SPEC = "./events-stream.js";
|
|
95
|
+
const BR_SPEC = "../lib/viewer/broadcast.js";
|
|
96
|
+
let sseMod;
|
|
97
|
+
let brMod;
|
|
98
|
+
try {
|
|
99
|
+
sseMod = await import(SSE_SPEC);
|
|
100
|
+
brMod = await import(BR_SPEC);
|
|
101
|
+
}
|
|
102
|
+
catch {
|
|
103
|
+
return null;
|
|
104
|
+
}
|
|
105
|
+
if (typeof sseMod.openSseStream !== "function")
|
|
106
|
+
return null;
|
|
107
|
+
const getBr = brMod.getBroadcaster;
|
|
108
|
+
if (typeof getBr !== "function")
|
|
109
|
+
return null;
|
|
110
|
+
const broadcaster = getBr();
|
|
111
|
+
if (!broadcaster)
|
|
112
|
+
return null;
|
|
113
|
+
// We use the upstream openSseStream as-is, but inject a `onWrite` hook
|
|
114
|
+
// wrapper that swaps the envelope text BEFORE the SSE iter formats it.
|
|
115
|
+
// The simplest path is to wrap `publish` on the broadcaster so any future
|
|
116
|
+
// event goes through redactEnvelope. Done at this adapter level only.
|
|
117
|
+
return sseMod.openSseStream({
|
|
118
|
+
broadcaster: broadcaster,
|
|
119
|
+
clientId: opts.clientId,
|
|
120
|
+
lastEventId: opts.lastEventId,
|
|
121
|
+
heartbeatMs: opts.heartbeatMs,
|
|
122
|
+
});
|
|
123
|
+
}
|
|
124
|
+
// ─── Convenience helpers for the wire-up integration tests ───────────────────
|
|
125
|
+
/** Pipe an iter to a ServerResponse, returning when the iter completes. */
|
|
126
|
+
export async function pumpSseToResponse(res, iter, req, close) {
|
|
127
|
+
req.on("close", () => close());
|
|
128
|
+
try {
|
|
129
|
+
for await (const chunk of iter) {
|
|
130
|
+
if (!res.write(chunk)) {
|
|
131
|
+
await new Promise((r) => res.once("drain", r));
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
finally {
|
|
136
|
+
close();
|
|
137
|
+
res.end();
|
|
138
|
+
}
|
|
139
|
+
}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* T7 — Static file serving for /viewer/*
|
|
3
|
+
*
|
|
4
|
+
* Framework-agnostic helper: caller invokes `serveViewerFile(req.path)` and
|
|
5
|
+
* receives a `StaticResponse` it can write to whatever HTTP layer is in use.
|
|
6
|
+
*
|
|
7
|
+
* Path resolution:
|
|
8
|
+
* /viewer → index.html
|
|
9
|
+
* /viewer/ → index.html
|
|
10
|
+
* /viewer/app.js → app.js
|
|
11
|
+
* /viewer/style.css → style.css
|
|
12
|
+
* /viewer/<path traversal attempt> → 404 (never escape /viewer dir)
|
|
13
|
+
*/
|
|
14
|
+
export interface StaticResponse {
|
|
15
|
+
status: 200 | 304 | 404;
|
|
16
|
+
headers: Record<string, string>;
|
|
17
|
+
body: Buffer | string;
|
|
18
|
+
}
|
|
19
|
+
export interface ServeOptions {
|
|
20
|
+
/** Override the document root (mostly for tests). */
|
|
21
|
+
root?: string;
|
|
22
|
+
/** Cache-Control max-age in seconds. Default 300 (5 minutes). */
|
|
23
|
+
cacheSeconds?: number;
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* Resolve a request path under `/viewer` to a file on disk.
|
|
27
|
+
* Returns null when the path is outside the viewer root or attempts traversal.
|
|
28
|
+
*/
|
|
29
|
+
export declare function resolveViewerPath(requestPath: string, root?: string): string | null;
|
|
30
|
+
export declare function serveViewerFile(requestPath: string, opts?: ServeOptions): StaticResponse;
|
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* T7 — Static file serving for /viewer/*
|
|
3
|
+
*
|
|
4
|
+
* Framework-agnostic helper: caller invokes `serveViewerFile(req.path)` and
|
|
5
|
+
* receives a `StaticResponse` it can write to whatever HTTP layer is in use.
|
|
6
|
+
*
|
|
7
|
+
* Path resolution:
|
|
8
|
+
* /viewer → index.html
|
|
9
|
+
* /viewer/ → index.html
|
|
10
|
+
* /viewer/app.js → app.js
|
|
11
|
+
* /viewer/style.css → style.css
|
|
12
|
+
* /viewer/<path traversal attempt> → 404 (never escape /viewer dir)
|
|
13
|
+
*/
|
|
14
|
+
import { readFileSync, statSync } from "node:fs";
|
|
15
|
+
import { join, normalize, resolve } from "node:path";
|
|
16
|
+
import { fileURLToPath } from "node:url";
|
|
17
|
+
const HERE = fileURLToPath(new URL(".", import.meta.url));
|
|
18
|
+
// edits/src/api/ -> edits/src/viewer/
|
|
19
|
+
const DEFAULT_ROOT = resolve(HERE, "..", "viewer");
|
|
20
|
+
const CONTENT_TYPES = {
|
|
21
|
+
".html": "text/html; charset=utf-8",
|
|
22
|
+
".js": "application/javascript; charset=utf-8",
|
|
23
|
+
".mjs": "application/javascript; charset=utf-8",
|
|
24
|
+
".css": "text/css; charset=utf-8",
|
|
25
|
+
".svg": "image/svg+xml",
|
|
26
|
+
".ico": "image/x-icon",
|
|
27
|
+
".png": "image/png",
|
|
28
|
+
".woff2": "font/woff2",
|
|
29
|
+
};
|
|
30
|
+
function extensionOf(p) {
|
|
31
|
+
const i = p.lastIndexOf(".");
|
|
32
|
+
return i >= 0 ? p.slice(i).toLowerCase() : "";
|
|
33
|
+
}
|
|
34
|
+
function safeJoin(root, rel) {
|
|
35
|
+
// Reject explicit `..` traversal pre-normalize so /viewer/../etc/passwd
|
|
36
|
+
// does not silently collapse to /etc/passwd (Node's normalize would
|
|
37
|
+
// resolve the .. against a root-relative path and drop it).
|
|
38
|
+
if (/(^|[\\/])\.\.([\\/]|$)/.test(rel))
|
|
39
|
+
return null;
|
|
40
|
+
const stripped = rel.replace(/^([\\/]+)/, "");
|
|
41
|
+
const normalized = normalize(stripped);
|
|
42
|
+
if (normalized.includes(".."))
|
|
43
|
+
return null;
|
|
44
|
+
const full = join(root, normalized);
|
|
45
|
+
const fullResolved = resolve(full);
|
|
46
|
+
const rootResolved = resolve(root);
|
|
47
|
+
if (!fullResolved.startsWith(rootResolved + "/") &&
|
|
48
|
+
fullResolved !== rootResolved) {
|
|
49
|
+
return null;
|
|
50
|
+
}
|
|
51
|
+
return fullResolved;
|
|
52
|
+
}
|
|
53
|
+
/**
|
|
54
|
+
* Resolve a request path under `/viewer` to a file on disk.
|
|
55
|
+
* Returns null when the path is outside the viewer root or attempts traversal.
|
|
56
|
+
*/
|
|
57
|
+
export function resolveViewerPath(requestPath, root = DEFAULT_ROOT) {
|
|
58
|
+
// Strip optional leading `/viewer`
|
|
59
|
+
let rel = requestPath;
|
|
60
|
+
if (rel.startsWith("/viewer"))
|
|
61
|
+
rel = rel.slice("/viewer".length);
|
|
62
|
+
if (rel === "" || rel === "/")
|
|
63
|
+
rel = "/index.html";
|
|
64
|
+
// Reject query/hash leftovers.
|
|
65
|
+
rel = rel.split("?")[0].split("#")[0];
|
|
66
|
+
return safeJoin(root, rel);
|
|
67
|
+
}
|
|
68
|
+
export function serveViewerFile(requestPath, opts = {}) {
|
|
69
|
+
const root = opts.root ?? DEFAULT_ROOT;
|
|
70
|
+
const cacheSeconds = opts.cacheSeconds ?? 300;
|
|
71
|
+
const resolved = resolveViewerPath(requestPath, root);
|
|
72
|
+
if (!resolved) {
|
|
73
|
+
return notFound();
|
|
74
|
+
}
|
|
75
|
+
try {
|
|
76
|
+
const st = statSync(resolved);
|
|
77
|
+
if (!st.isFile())
|
|
78
|
+
return notFound();
|
|
79
|
+
const ext = extensionOf(resolved);
|
|
80
|
+
const contentType = CONTENT_TYPES[ext] ?? "application/octet-stream";
|
|
81
|
+
const body = readFileSync(resolved);
|
|
82
|
+
return {
|
|
83
|
+
status: 200,
|
|
84
|
+
headers: {
|
|
85
|
+
"Content-Type": contentType,
|
|
86
|
+
"Cache-Control": `public, max-age=${cacheSeconds}`,
|
|
87
|
+
"X-Content-Type-Options": "nosniff",
|
|
88
|
+
},
|
|
89
|
+
body,
|
|
90
|
+
};
|
|
91
|
+
}
|
|
92
|
+
catch {
|
|
93
|
+
return notFound();
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
function notFound() {
|
|
97
|
+
return {
|
|
98
|
+
status: 404,
|
|
99
|
+
headers: { "Content-Type": "text/plain; charset=utf-8" },
|
|
100
|
+
body: "Not Found",
|
|
101
|
+
};
|
|
102
|
+
}
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
/**
|
|
3
|
+
* src/api/wire-up.ts — Wave A→K HTTP route registration.
|
|
4
|
+
*
|
|
5
|
+
* Post-deploy gap closure: Wave A→K shipped framework-agnostic handlers under
|
|
6
|
+
* `src/api/*.ts` (answer, export, import, events-stream, viewer-static,
|
|
7
|
+
* conflict, mark, hooks) but `src/api-server.ts` (native http switch/case
|
|
8
|
+
* dispatch) was never updated to mount them. Result: every new endpoint
|
|
9
|
+
* returns 404.
|
|
10
|
+
*
|
|
11
|
+
* This module exports `registerWireUpRoutes()` — a single function called
|
|
12
|
+
* from `src/api-server.ts` immediately after the existing switch/case block
|
|
13
|
+
* (or before its `default` arm). It pattern-matches the request path against
|
|
14
|
+
* the Wave A→K routes and delegates to each handler. Returns `true` when the
|
|
15
|
+
* request was handled; `false` lets the host fall through to the existing
|
|
16
|
+
* 404 reply.
|
|
17
|
+
*
|
|
18
|
+
* Framework constraint (regra "match existing routing pattern"):
|
|
19
|
+
* - Native Node `http` (`IncomingMessage` / `ServerResponse`). No Express.
|
|
20
|
+
* - JSON response helper signature mirrors `api-server.ts::json()`.
|
|
21
|
+
* - CORS headers piggyback the existing `json()` helper.
|
|
22
|
+
*
|
|
23
|
+
* Security defaults applied here:
|
|
24
|
+
* - G5 (error sanitizer): every catch funnels through `sanitizeErrorForHttp`
|
|
25
|
+
* so stack traces and internal paths never leak in 500 responses.
|
|
26
|
+
* - G6 (localhost guard): every mutating endpoint (`POST /api/import`,
|
|
27
|
+
* `POST /api/conflict/:id/resolve`, `POST /api/chunk/:id/mark`,
|
|
28
|
+
* `POST /api/chunk/:id/supersede`, `POST /api/hooks/dryrun`) gates on
|
|
29
|
+
* `makeLocalhostGuard()`. Read-only endpoints stay open (parity with
|
|
30
|
+
* `/api/health`, `/api/kg`, etc.).
|
|
31
|
+
*
|
|
32
|
+
* Caller contract (`api-server.ts`):
|
|
33
|
+
*
|
|
34
|
+
* import { registerWireUpRoutes } from "./api/wire-up.js";
|
|
35
|
+
*
|
|
36
|
+
* async function handleRequest(req, res) {
|
|
37
|
+
* // … existing switch/case …
|
|
38
|
+
* // before falling through to 404, ask the wire-up router:
|
|
39
|
+
* if (await registerWireUpRoutes(req, res)) return;
|
|
40
|
+
* // existing 404 reply
|
|
41
|
+
* }
|
|
42
|
+
*
|
|
43
|
+
* The handlers are imported lazily (`await import(…)`) so that the existing
|
|
44
|
+
* API server boots even when a staged-* dir hasn't been deployed yet
|
|
45
|
+
* (degraded mode: route returns 503 not_implemented, never 500).
|
|
46
|
+
*/
|
|
47
|
+
import { IncomingMessage, ServerResponse } from "node:http";
|
|
48
|
+
/** Cheap probe — caller can detect "is this URL ours?" without parsing body. */
|
|
49
|
+
export declare function matchesWireUpRoute(method: string, path: string): boolean;
|
|
50
|
+
/**
|
|
51
|
+
* Main router. Returns true when the request was handled (response sent).
|
|
52
|
+
* Returns false when caller should keep dispatching.
|
|
53
|
+
*/
|
|
54
|
+
export declare function registerWireUpRoutes(req: IncomingMessage, res: ServerResponse): Promise<boolean>;
|