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,106 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* project-context-gen.ts - Auto-generate PROJECT_CONTEXT.md from memory chunks
|
|
3
|
+
* Each project gets status extracted from latest memory entries
|
|
4
|
+
*/
|
|
5
|
+
import fs from "fs";
|
|
6
|
+
import path from "path";
|
|
7
|
+
import { getDb } from "./db.js";
|
|
8
|
+
const _ws_pcg = process.env.OPENCLAW_WORKSPACE ?? "/root/.openclaw/workspace";
|
|
9
|
+
const PROJECTS_DIR = process.env.NOX_PROJECTS_DIR ?? (_ws_pcg + "/projects");
|
|
10
|
+
// NOX_KNOWN_PROJECTS: comma-separated project slugs for this operator.
|
|
11
|
+
// Default is empty — no personal project names ship in the open-source build.
|
|
12
|
+
// On the origin VPS set NOX_KNOWN_PROJECTS to restore original project list.
|
|
13
|
+
const KNOWN_PROJECTS = process.env.NOX_KNOWN_PROJECTS
|
|
14
|
+
? process.env.NOX_KNOWN_PROJECTS.split(",").map((s) => s.trim()).filter(Boolean)
|
|
15
|
+
: [];
|
|
16
|
+
function extractProjectData(projectName) {
|
|
17
|
+
const db = getDb();
|
|
18
|
+
const chunks = db.prepare(`SELECT chunk_text, source_date, chunk_type FROM chunks
|
|
19
|
+
WHERE chunk_type = 'project' AND source_file LIKE ?
|
|
20
|
+
ORDER BY source_date DESC LIMIT 10`).all(`%${projectName}%`);
|
|
21
|
+
const data = {
|
|
22
|
+
name: projectName.replace(/-/g, " ").toUpperCase(),
|
|
23
|
+
status: "—",
|
|
24
|
+
phase: "—",
|
|
25
|
+
};
|
|
26
|
+
if (chunks.length > 0) {
|
|
27
|
+
const lastChunk = chunks[0].chunk_text;
|
|
28
|
+
if (lastChunk.includes("due diligence"))
|
|
29
|
+
data.phase = "Due Diligence";
|
|
30
|
+
else if (lastChunk.includes("estruturação"))
|
|
31
|
+
data.phase = "Estruturação";
|
|
32
|
+
else if (lastChunk.includes("operacional"))
|
|
33
|
+
data.phase = "Operacional";
|
|
34
|
+
else if (lastChunk.includes("ativo"))
|
|
35
|
+
data.phase = "Ativo";
|
|
36
|
+
data.lastUpdate = chunks[0].source_date || undefined;
|
|
37
|
+
}
|
|
38
|
+
return data;
|
|
39
|
+
}
|
|
40
|
+
function generateProjectMarkdown(data) {
|
|
41
|
+
return `# PROJECT_CONTEXT — ${data.name}
|
|
42
|
+
|
|
43
|
+
> Atualizar ao final de cada sessão com avanços relevantes.
|
|
44
|
+
|
|
45
|
+
## Status atual
|
|
46
|
+
- **Fase:** ${data.phase}
|
|
47
|
+
- **Última atualização:** ${data.lastUpdate ? new Date(data.lastUpdate).toLocaleDateString("pt-BR") : "—"}
|
|
48
|
+
|
|
49
|
+
## Progresso
|
|
50
|
+
|
|
51
|
+
| Item | Status | Responsável | Prazo |
|
|
52
|
+
|------|--------|-------------|-------|
|
|
53
|
+
| — | — | — | — |
|
|
54
|
+
|
|
55
|
+
## Decisões tomadas
|
|
56
|
+
<!-- Adicionar com data: YYYY-MM-DD: descrição -->
|
|
57
|
+
|
|
58
|
+
## Pendências
|
|
59
|
+
<!-- Adicionar com owner e prazo -->
|
|
60
|
+
|
|
61
|
+
## Histórico de atualizações
|
|
62
|
+
<!-- Formato: YYYY-MM-DD: o que mudou -->
|
|
63
|
+
`;
|
|
64
|
+
}
|
|
65
|
+
export function syncProjectContexts() {
|
|
66
|
+
let updated = 0;
|
|
67
|
+
let created = 0;
|
|
68
|
+
let errors = 0;
|
|
69
|
+
for (const project of KNOWN_PROJECTS) {
|
|
70
|
+
try {
|
|
71
|
+
const projectDir = path.join(PROJECTS_DIR, project);
|
|
72
|
+
const contextPath = path.join(projectDir, "PROJECT_CONTEXT.md");
|
|
73
|
+
if (!fs.existsSync(projectDir)) {
|
|
74
|
+
fs.mkdirSync(projectDir, { recursive: true });
|
|
75
|
+
}
|
|
76
|
+
const data = extractProjectData(project);
|
|
77
|
+
const markdown = generateProjectMarkdown(data);
|
|
78
|
+
if (fs.existsSync(contextPath)) {
|
|
79
|
+
const existing = fs.readFileSync(contextPath, "utf-8");
|
|
80
|
+
if (existing !== markdown) {
|
|
81
|
+
fs.writeFileSync(contextPath, markdown);
|
|
82
|
+
updated++;
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
else {
|
|
86
|
+
fs.writeFileSync(contextPath, markdown);
|
|
87
|
+
created++;
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
catch (err) {
|
|
91
|
+
console.error(`[ERROR] Failed to sync project ${project}:`, err.message);
|
|
92
|
+
errors++;
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
return { updated, created, errors };
|
|
96
|
+
}
|
|
97
|
+
export function listProjects() {
|
|
98
|
+
console.log("\nProjects:\n");
|
|
99
|
+
const db = getDb();
|
|
100
|
+
for (const project of KNOWN_PROJECTS) {
|
|
101
|
+
const lastChunk = db.prepare(`SELECT source_date FROM chunks WHERE chunk_type = 'project' AND source_file LIKE ? ORDER BY source_date DESC LIMIT 1`).get(`%${project}%`);
|
|
102
|
+
const dateStr = lastChunk?.source_date ? new Date(lastChunk.source_date).toLocaleDateString("pt-BR") : "—";
|
|
103
|
+
console.log(` • ${project.replace(/-/g, " ")} — última menção: ${dateStr}`);
|
|
104
|
+
}
|
|
105
|
+
console.log();
|
|
106
|
+
}
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* src/providers/embedding/gemini.ts — Gemini embedding provider (T3).
|
|
3
|
+
*
|
|
4
|
+
* Real impl wrapping `generativelanguage.googleapis.com/v1beta`.
|
|
5
|
+
* D41 default model: `gemini-embedding-001` at 3072 dimensions.
|
|
6
|
+
*
|
|
7
|
+
* Design notes:
|
|
8
|
+
* - Uses `fetch` (Node 18+) — no SDK dependency. The live `src/embedder.ts`
|
|
9
|
+
* in prod uses the official SDK; this staged path mirrors its wire shape
|
|
10
|
+
* so behaviour is byte-equivalent for the same model + input.
|
|
11
|
+
* - `apiKey` resolved from `GEMINI_API_KEY` env at construction. Stored
|
|
12
|
+
* privately and NEVER echoed in errors (regex-blocked).
|
|
13
|
+
* - `fetchFn` is injectable for tests — production passes nothing and the
|
|
14
|
+
* global `fetch` is used. Tests pass a stub to avoid network calls.
|
|
15
|
+
* - `healthCheck()` calls the `:embedContent` endpoint with a 1-token input
|
|
16
|
+
* ("ping") — cheapest possible probe per spec §4 (T9 conformance: probes
|
|
17
|
+
* never cost > $0.01).
|
|
18
|
+
* - All errors redacted: never include the API key value, never echo upstream
|
|
19
|
+
* 401/403 body verbatim (some Gemini errors echo bearer prefix).
|
|
20
|
+
*/
|
|
21
|
+
import type { EmbeddingProvider } from "./types.js";
|
|
22
|
+
import type { HealthStatus } from "../types.js";
|
|
23
|
+
/** Default model + dim per D41. */
|
|
24
|
+
export declare const GEMINI_EMBED_DEFAULT_MODEL = "gemini-embedding-001";
|
|
25
|
+
export declare const GEMINI_EMBED_DEFAULT_DIM = 3072;
|
|
26
|
+
/** Public list price (USD per 1M tokens) — gemini-embedding-001 as of 2026-05. */
|
|
27
|
+
export declare const GEMINI_EMBED_COST_PER_M_TOKENS = 0.15;
|
|
28
|
+
/** Per-input token ceiling (Gemini hard limit ~2048 input tokens / item). */
|
|
29
|
+
export declare const GEMINI_EMBED_MAX_TOKENS = 2048;
|
|
30
|
+
/** Minimal fetch type compatible with Node 18+ global fetch (avoid lib.dom dep). */
|
|
31
|
+
export type FetchLike = (input: string, init?: {
|
|
32
|
+
method?: string;
|
|
33
|
+
headers?: Record<string, string>;
|
|
34
|
+
body?: string;
|
|
35
|
+
signal?: AbortSignal;
|
|
36
|
+
}) => Promise<{
|
|
37
|
+
ok: boolean;
|
|
38
|
+
status: number;
|
|
39
|
+
statusText: string;
|
|
40
|
+
text: () => Promise<string>;
|
|
41
|
+
json: () => Promise<unknown>;
|
|
42
|
+
}>;
|
|
43
|
+
export interface GeminiEmbeddingOpts {
|
|
44
|
+
/** Override model (e.g., 'text-embedding-004'). Default: gemini-embedding-001. */
|
|
45
|
+
model?: string;
|
|
46
|
+
/** Override dimensions. Default: 3072. */
|
|
47
|
+
dimensions?: number;
|
|
48
|
+
/** Override API key (else read GEMINI_API_KEY env). */
|
|
49
|
+
apiKey?: string;
|
|
50
|
+
/** Injected fetch for tests; defaults to globalThis.fetch. */
|
|
51
|
+
fetchFn?: FetchLike;
|
|
52
|
+
/** Base URL override (lets tests point at fixture server). */
|
|
53
|
+
baseUrl?: string;
|
|
54
|
+
}
|
|
55
|
+
export declare class GeminiEmbeddingProvider implements EmbeddingProvider {
|
|
56
|
+
readonly name = "gemini";
|
|
57
|
+
readonly dimensions: number;
|
|
58
|
+
readonly maxTokens: number;
|
|
59
|
+
readonly costPerMillionTokens: number;
|
|
60
|
+
readonly model: string;
|
|
61
|
+
private readonly apiKey;
|
|
62
|
+
private readonly fetchFn;
|
|
63
|
+
private readonly baseUrl;
|
|
64
|
+
constructor(opts?: GeminiEmbeddingOpts);
|
|
65
|
+
embed(texts: string[]): Promise<Float32Array[]>;
|
|
66
|
+
healthCheck(): Promise<HealthStatus>;
|
|
67
|
+
}
|
|
68
|
+
/**
|
|
69
|
+
* Strip anything that looks like an API key from error text before surfacing.
|
|
70
|
+
* Gemini keys are typically 39 chars starting "AIza"; we also catch generic
|
|
71
|
+
* long base64-ish tokens to be defensive (covers OpenAI sk-... etc).
|
|
72
|
+
*/
|
|
73
|
+
export declare function redactSecrets(s: string): string;
|
|
@@ -0,0 +1,118 @@
|
|
|
1
|
+
import { MissingKeyError } from "../types.js";
|
|
2
|
+
/** Default model + dim per D41. */
|
|
3
|
+
export const GEMINI_EMBED_DEFAULT_MODEL = "gemini-embedding-001";
|
|
4
|
+
export const GEMINI_EMBED_DEFAULT_DIM = 3072;
|
|
5
|
+
/** Public list price (USD per 1M tokens) — gemini-embedding-001 as of 2026-05. */
|
|
6
|
+
export const GEMINI_EMBED_COST_PER_M_TOKENS = 0.15;
|
|
7
|
+
/** Per-input token ceiling (Gemini hard limit ~2048 input tokens / item). */
|
|
8
|
+
export const GEMINI_EMBED_MAX_TOKENS = 2048;
|
|
9
|
+
const DEFAULT_BASE_URL = "https://generativelanguage.googleapis.com/v1beta";
|
|
10
|
+
export class GeminiEmbeddingProvider {
|
|
11
|
+
name = "gemini";
|
|
12
|
+
dimensions;
|
|
13
|
+
maxTokens = GEMINI_EMBED_MAX_TOKENS;
|
|
14
|
+
costPerMillionTokens = GEMINI_EMBED_COST_PER_M_TOKENS;
|
|
15
|
+
model;
|
|
16
|
+
apiKey;
|
|
17
|
+
fetchFn;
|
|
18
|
+
baseUrl;
|
|
19
|
+
constructor(opts = {}) {
|
|
20
|
+
this.model = opts.model ?? GEMINI_EMBED_DEFAULT_MODEL;
|
|
21
|
+
this.dimensions = opts.dimensions ?? GEMINI_EMBED_DEFAULT_DIM;
|
|
22
|
+
this.baseUrl = opts.baseUrl ?? DEFAULT_BASE_URL;
|
|
23
|
+
const resolvedKey = opts.apiKey ?? process.env.GEMINI_API_KEY ?? "";
|
|
24
|
+
if (!resolvedKey) {
|
|
25
|
+
throw new MissingKeyError("gemini", "GEMINI_API_KEY");
|
|
26
|
+
}
|
|
27
|
+
this.apiKey = resolvedKey;
|
|
28
|
+
const f = opts.fetchFn ?? globalThis.fetch;
|
|
29
|
+
if (!f) {
|
|
30
|
+
throw new Error("GeminiEmbeddingProvider: no fetch available (Node<18?). Pass opts.fetchFn explicitly.");
|
|
31
|
+
}
|
|
32
|
+
this.fetchFn = f;
|
|
33
|
+
}
|
|
34
|
+
async embed(texts) {
|
|
35
|
+
if (texts.length === 0)
|
|
36
|
+
return [];
|
|
37
|
+
// Gemini v1beta batchEmbedContents — array of request objects.
|
|
38
|
+
const url = `${this.baseUrl}/models/${encodeURIComponent(this.model)}:batchEmbedContents` +
|
|
39
|
+
`?key=${encodeURIComponent(this.apiKey)}`;
|
|
40
|
+
const body = JSON.stringify({
|
|
41
|
+
requests: texts.map((t) => ({
|
|
42
|
+
model: `models/${this.model}`,
|
|
43
|
+
content: { parts: [{ text: t }] },
|
|
44
|
+
outputDimensionality: this.dimensions,
|
|
45
|
+
})),
|
|
46
|
+
});
|
|
47
|
+
const res = await this.fetchFn(url, {
|
|
48
|
+
method: "POST",
|
|
49
|
+
headers: { "content-type": "application/json" },
|
|
50
|
+
body,
|
|
51
|
+
});
|
|
52
|
+
if (!res.ok) {
|
|
53
|
+
const safeStatus = `${res.status} ${res.statusText}`;
|
|
54
|
+
// Do NOT echo response body verbatim — providers can leak partial key
|
|
55
|
+
// in 401/403 error envelopes. Read first 200 chars after key-regex strip.
|
|
56
|
+
const raw = await res.text().catch(() => "");
|
|
57
|
+
const redacted = redactSecrets(raw).slice(0, 200);
|
|
58
|
+
throw new Error(`GeminiEmbeddingProvider: HTTP ${safeStatus} — ${redacted}`);
|
|
59
|
+
}
|
|
60
|
+
const parsed = (await res.json());
|
|
61
|
+
if (!parsed.embeddings || !Array.isArray(parsed.embeddings)) {
|
|
62
|
+
throw new Error("GeminiEmbeddingProvider: malformed response (no embeddings[])");
|
|
63
|
+
}
|
|
64
|
+
const out = [];
|
|
65
|
+
for (let i = 0; i < parsed.embeddings.length; i++) {
|
|
66
|
+
const e = parsed.embeddings[i];
|
|
67
|
+
const values = e?.values;
|
|
68
|
+
if (!values || values.length !== this.dimensions) {
|
|
69
|
+
throw new Error(`GeminiEmbeddingProvider: response index ${i} dim mismatch ` +
|
|
70
|
+
`(got ${values?.length ?? 0}, expected ${this.dimensions})`);
|
|
71
|
+
}
|
|
72
|
+
// Copy values into a fresh Float32Array. Do NOT use Buffer.from then view —
|
|
73
|
+
// lesson 2026-05-03: Node Buffer pool aliasing corrupts typed arrays under GC.
|
|
74
|
+
const f32 = new Float32Array(this.dimensions);
|
|
75
|
+
for (let j = 0; j < this.dimensions; j++) {
|
|
76
|
+
f32[j] = values[j] ?? 0;
|
|
77
|
+
}
|
|
78
|
+
out.push(f32);
|
|
79
|
+
}
|
|
80
|
+
return out;
|
|
81
|
+
}
|
|
82
|
+
async healthCheck() {
|
|
83
|
+
const t0 = Date.now();
|
|
84
|
+
try {
|
|
85
|
+
// Cheapest probe: list models endpoint (no token billing) — or 1-input embed.
|
|
86
|
+
// We use the metadata `:get` endpoint per A3 spec §T9 (no token consumption).
|
|
87
|
+
const url = `${this.baseUrl}/models/${encodeURIComponent(this.model)}` +
|
|
88
|
+
`?key=${encodeURIComponent(this.apiKey)}`;
|
|
89
|
+
const res = await this.fetchFn(url, { method: "GET" });
|
|
90
|
+
const latencyMs = Date.now() - t0;
|
|
91
|
+
if (!res.ok) {
|
|
92
|
+
return {
|
|
93
|
+
ok: false,
|
|
94
|
+
latencyMs,
|
|
95
|
+
error: `health: HTTP ${res.status} ${res.statusText}`,
|
|
96
|
+
};
|
|
97
|
+
}
|
|
98
|
+
return { ok: true, latencyMs };
|
|
99
|
+
}
|
|
100
|
+
catch (err) {
|
|
101
|
+
const latencyMs = Date.now() - t0;
|
|
102
|
+
const msg = err instanceof Error ? err.message : String(err);
|
|
103
|
+
return { ok: false, latencyMs, error: `health: ${redactSecrets(msg)}` };
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
/**
|
|
108
|
+
* Strip anything that looks like an API key from error text before surfacing.
|
|
109
|
+
* Gemini keys are typically 39 chars starting "AIza"; we also catch generic
|
|
110
|
+
* long base64-ish tokens to be defensive (covers OpenAI sk-... etc).
|
|
111
|
+
*/
|
|
112
|
+
export function redactSecrets(s) {
|
|
113
|
+
return s
|
|
114
|
+
.replace(/AIza[0-9A-Za-z_-]{20,}/g, "AIza<REDACTED>")
|
|
115
|
+
.replace(/sk-[A-Za-z0-9_-]{20,}/g, "sk-<REDACTED>")
|
|
116
|
+
.replace(/Bearer\s+[A-Za-z0-9._-]{20,}/g, "Bearer <REDACTED>")
|
|
117
|
+
.replace(/key=[A-Za-z0-9_-]{20,}/g, "key=<REDACTED>");
|
|
118
|
+
}
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* src/providers/embedding/openai.ts — OpenAI-compatible embedding provider (A3.1, real).
|
|
3
|
+
*
|
|
4
|
+
* Talks the OpenAI Embeddings wire shape:
|
|
5
|
+
* POST {baseUrl}/embeddings
|
|
6
|
+
* Authorization: Bearer <apiKey>
|
|
7
|
+
* body: { model, input: string[], dimensions? }
|
|
8
|
+
* parse: data[].embedding (sorted by data[].index to preserve input order)
|
|
9
|
+
*
|
|
10
|
+
* Single class drives any OpenAI-compatible embedding endpoint via `baseUrl`:
|
|
11
|
+
*
|
|
12
|
+
* | Backend | baseUrl | example model |
|
|
13
|
+
* |-------------|----------------------------------------|--------------------------|
|
|
14
|
+
* | OpenAI | https://api.openai.com/v1 (default) | text-embedding-3-small |
|
|
15
|
+
* | Together | https://api.together.xyz/v1 | BAAI/bge-large-en-v1.5 |
|
|
16
|
+
* | OpenRouter | https://openrouter.ai/api/v1 | (varies by listing) |
|
|
17
|
+
* | DeepInfra | https://api.deepinfra.com/v1/openai | BAAI/bge-m3 |
|
|
18
|
+
* | local | http://127.0.0.1:11434/v1 (ollama) | nomic-embed-text |
|
|
19
|
+
*
|
|
20
|
+
* ⚠ EMBEDDING DIMENSION CAVEAT (read before switching):
|
|
21
|
+
* The DB / sqlite-vec virtual table is fixed at the dim it was created with
|
|
22
|
+
* (nox-mem prod = 3072, from gemini-embedding-001). Mixing dims, or even the
|
|
23
|
+
* same dim from a different model, corrupts semantic search — vectors are not
|
|
24
|
+
* comparable across models. To swap to OpenAI you MUST re-embed the whole
|
|
25
|
+
* corpus with a single model at a single dim, and that dim MUST equal the
|
|
26
|
+
* vec0 table dim. `text-embedding-3-large` supports dimensions=3072 (parity
|
|
27
|
+
* with the existing table); `text-embedding-3-small` defaults to 1536 and is
|
|
28
|
+
* only safe on a fresh 1536-dim table. Set `NOX_EMBEDDING_MODEL` +
|
|
29
|
+
* `NOX_EMBEDDING_DIM` deliberately.
|
|
30
|
+
*
|
|
31
|
+
* Design parity with GeminiEmbeddingProvider:
|
|
32
|
+
* - `fetch` (Node 18+), no SDK. `fetchFn` injectable for tests.
|
|
33
|
+
* - Key from constructor arg → OPENAI_API_KEY env. Stored privately, redacted
|
|
34
|
+
* from all error text.
|
|
35
|
+
* - Construction is NON-throwing when no key present (factory conformance). The
|
|
36
|
+
* missing key surfaces as MissingKeyError on the first embed()/healthCheck().
|
|
37
|
+
* - Returns Float32Array[] (one per input, in input order), each length = dim.
|
|
38
|
+
* Per-vector copy into a fresh Float32Array (no Buffer aliasing — lesson
|
|
39
|
+
* 2026-05-03).
|
|
40
|
+
*/
|
|
41
|
+
import type { EmbeddingProvider } from "./types.js";
|
|
42
|
+
import type { HealthStatus } from "../types.js";
|
|
43
|
+
import { type FetchLike } from "./gemini.js";
|
|
44
|
+
export declare const OPENAI_EMBED_DEFAULT_MODEL = "text-embedding-3-small";
|
|
45
|
+
/** Default dim for `text-embedding-3-small`. `text-embedding-3-large` supports 3072. */
|
|
46
|
+
export declare const OPENAI_EMBED_DEFAULT_DIM = 1536;
|
|
47
|
+
/** Per OpenAI public pricing 2026-05: $0.02 / 1M for 3-small, $0.13 / 1M for 3-large. */
|
|
48
|
+
export declare const OPENAI_EMBED_DEFAULT_COST = 0.02;
|
|
49
|
+
export declare const OPENAI_EMBED_MAX_TOKENS = 8191;
|
|
50
|
+
/** Default endpoint. Override for Together/OpenRouter/DeepInfra/local. */
|
|
51
|
+
export declare const OPENAI_EMBED_DEFAULT_BASE_URL = "https://api.openai.com/v1";
|
|
52
|
+
export interface OpenAIEmbeddingOpts {
|
|
53
|
+
/** Override model. Default: text-embedding-3-small. */
|
|
54
|
+
model?: string;
|
|
55
|
+
/** Override output dimensions. Default: 1536. MUST equal the vec0 table dim. */
|
|
56
|
+
dimensions?: number;
|
|
57
|
+
/** Override API key. Else read OPENAI_API_KEY. */
|
|
58
|
+
apiKey?: string;
|
|
59
|
+
/** Injected fetch for tests; defaults to globalThis.fetch. */
|
|
60
|
+
fetchFn?: FetchLike;
|
|
61
|
+
/** Base URL override (no trailing slash). Default https://api.openai.com/v1. */
|
|
62
|
+
baseUrl?: string;
|
|
63
|
+
}
|
|
64
|
+
export declare class OpenAIEmbeddingProvider implements EmbeddingProvider {
|
|
65
|
+
readonly name = "openai";
|
|
66
|
+
readonly model: string;
|
|
67
|
+
readonly dimensions: number;
|
|
68
|
+
readonly maxTokens: number;
|
|
69
|
+
readonly costPerMillionTokens: number;
|
|
70
|
+
private readonly apiKey;
|
|
71
|
+
private readonly baseUrl;
|
|
72
|
+
private readonly fetchFn;
|
|
73
|
+
constructor(opts?: OpenAIEmbeddingOpts);
|
|
74
|
+
embed(texts: string[]): Promise<Float32Array[]>;
|
|
75
|
+
healthCheck(): Promise<HealthStatus>;
|
|
76
|
+
}
|
|
@@ -0,0 +1,123 @@
|
|
|
1
|
+
import { MissingKeyError } from "../types.js";
|
|
2
|
+
import { redactSecrets } from "./gemini.js";
|
|
3
|
+
export const OPENAI_EMBED_DEFAULT_MODEL = "text-embedding-3-small";
|
|
4
|
+
/** Default dim for `text-embedding-3-small`. `text-embedding-3-large` supports 3072. */
|
|
5
|
+
export const OPENAI_EMBED_DEFAULT_DIM = 1536;
|
|
6
|
+
/** Per OpenAI public pricing 2026-05: $0.02 / 1M for 3-small, $0.13 / 1M for 3-large. */
|
|
7
|
+
export const OPENAI_EMBED_DEFAULT_COST = 0.02;
|
|
8
|
+
export const OPENAI_EMBED_MAX_TOKENS = 8191;
|
|
9
|
+
/** Default endpoint. Override for Together/OpenRouter/DeepInfra/local. */
|
|
10
|
+
export const OPENAI_EMBED_DEFAULT_BASE_URL = "https://api.openai.com/v1";
|
|
11
|
+
export class OpenAIEmbeddingProvider {
|
|
12
|
+
name = "openai";
|
|
13
|
+
model;
|
|
14
|
+
dimensions;
|
|
15
|
+
maxTokens = OPENAI_EMBED_MAX_TOKENS;
|
|
16
|
+
costPerMillionTokens = OPENAI_EMBED_DEFAULT_COST;
|
|
17
|
+
apiKey;
|
|
18
|
+
baseUrl;
|
|
19
|
+
fetchFn;
|
|
20
|
+
constructor(opts = {}) {
|
|
21
|
+
this.model = opts.model ?? OPENAI_EMBED_DEFAULT_MODEL;
|
|
22
|
+
this.dimensions = opts.dimensions ?? OPENAI_EMBED_DEFAULT_DIM;
|
|
23
|
+
this.baseUrl = stripTrailingSlash(opts.baseUrl ?? OPENAI_EMBED_DEFAULT_BASE_URL);
|
|
24
|
+
// NON-throwing at construction (factory conformance). Key validated lazily.
|
|
25
|
+
this.apiKey = opts.apiKey ?? process.env.OPENAI_API_KEY ?? "";
|
|
26
|
+
const f = opts.fetchFn ?? globalThis.fetch;
|
|
27
|
+
if (!f) {
|
|
28
|
+
throw new Error("OpenAIEmbeddingProvider: no fetch available (Node<18?). Pass opts.fetchFn explicitly.");
|
|
29
|
+
}
|
|
30
|
+
this.fetchFn = f;
|
|
31
|
+
}
|
|
32
|
+
async embed(texts) {
|
|
33
|
+
if (texts.length === 0)
|
|
34
|
+
return [];
|
|
35
|
+
if (!this.apiKey) {
|
|
36
|
+
throw new MissingKeyError("openai", "OPENAI_API_KEY");
|
|
37
|
+
}
|
|
38
|
+
const url = `${this.baseUrl}/embeddings`;
|
|
39
|
+
// `dimensions` is honoured by OpenAI text-embedding-3-* and most compatible
|
|
40
|
+
// backends. Backends that ignore it must be paired with a matching model so
|
|
41
|
+
// the returned length still equals `this.dimensions` (validated below).
|
|
42
|
+
const body = JSON.stringify({
|
|
43
|
+
model: this.model,
|
|
44
|
+
input: texts,
|
|
45
|
+
dimensions: this.dimensions,
|
|
46
|
+
});
|
|
47
|
+
const res = await this.fetchFn(url, {
|
|
48
|
+
method: "POST",
|
|
49
|
+
headers: {
|
|
50
|
+
"content-type": "application/json",
|
|
51
|
+
authorization: `Bearer ${this.apiKey}`,
|
|
52
|
+
},
|
|
53
|
+
body,
|
|
54
|
+
});
|
|
55
|
+
if (!res.ok) {
|
|
56
|
+
const raw = await res.text().catch(() => "");
|
|
57
|
+
const redacted = redactSecrets(raw).slice(0, 200);
|
|
58
|
+
throw new Error(`OpenAIEmbeddingProvider: HTTP ${res.status} ${res.statusText} — ${redacted}`);
|
|
59
|
+
}
|
|
60
|
+
const parsed = (await res.json());
|
|
61
|
+
if (!parsed.data || !Array.isArray(parsed.data)) {
|
|
62
|
+
throw new Error("OpenAIEmbeddingProvider: malformed response (no data[])");
|
|
63
|
+
}
|
|
64
|
+
if (parsed.data.length !== texts.length) {
|
|
65
|
+
throw new Error(`OpenAIEmbeddingProvider: response count mismatch ` +
|
|
66
|
+
`(got ${parsed.data.length}, expected ${texts.length})`);
|
|
67
|
+
}
|
|
68
|
+
// OpenAI may return data out of order; sort by `index` to align with inputs.
|
|
69
|
+
const ordered = [...parsed.data].sort((a, b) => (a.index ?? 0) - (b.index ?? 0));
|
|
70
|
+
const out = [];
|
|
71
|
+
for (let i = 0; i < ordered.length; i++) {
|
|
72
|
+
const values = ordered[i]?.embedding;
|
|
73
|
+
if (!values || values.length !== this.dimensions) {
|
|
74
|
+
throw new Error(`OpenAIEmbeddingProvider: response index ${i} dim mismatch ` +
|
|
75
|
+
`(got ${values?.length ?? 0}, expected ${this.dimensions}). ` +
|
|
76
|
+
`Set NOX_EMBEDDING_DIM/model to match the vec0 table dim.`);
|
|
77
|
+
}
|
|
78
|
+
// Fresh Float32Array copy — never Buffer-view (Node pool aliasing corrupts
|
|
79
|
+
// typed arrays under GC; lesson 2026-05-03).
|
|
80
|
+
const f32 = new Float32Array(this.dimensions);
|
|
81
|
+
for (let j = 0; j < this.dimensions; j++) {
|
|
82
|
+
f32[j] = values[j] ?? 0;
|
|
83
|
+
}
|
|
84
|
+
out.push(f32);
|
|
85
|
+
}
|
|
86
|
+
return out;
|
|
87
|
+
}
|
|
88
|
+
async healthCheck() {
|
|
89
|
+
const t0 = Date.now();
|
|
90
|
+
if (!this.apiKey) {
|
|
91
|
+
return {
|
|
92
|
+
ok: false,
|
|
93
|
+
latencyMs: 0,
|
|
94
|
+
error: "health: OPENAI_API_KEY unset (provider selected but no credentials)",
|
|
95
|
+
};
|
|
96
|
+
}
|
|
97
|
+
try {
|
|
98
|
+
// Cheapest real probe: GET /models (no token billing).
|
|
99
|
+
const url = `${this.baseUrl}/models`;
|
|
100
|
+
const res = await this.fetchFn(url, {
|
|
101
|
+
method: "GET",
|
|
102
|
+
headers: { authorization: `Bearer ${this.apiKey}` },
|
|
103
|
+
});
|
|
104
|
+
const latencyMs = Date.now() - t0;
|
|
105
|
+
if (!res.ok) {
|
|
106
|
+
return {
|
|
107
|
+
ok: false,
|
|
108
|
+
latencyMs,
|
|
109
|
+
error: `health: HTTP ${res.status} ${res.statusText}`,
|
|
110
|
+
};
|
|
111
|
+
}
|
|
112
|
+
return { ok: true, latencyMs };
|
|
113
|
+
}
|
|
114
|
+
catch (err) {
|
|
115
|
+
const latencyMs = Date.now() - t0;
|
|
116
|
+
const msg = err instanceof Error ? err.message : String(err);
|
|
117
|
+
return { ok: false, latencyMs, error: `health: ${redactSecrets(msg)}` };
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
function stripTrailingSlash(u) {
|
|
122
|
+
return u.endsWith("/") ? u.slice(0, -1) : u;
|
|
123
|
+
}
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* src/providers/embedding/types.ts — EmbeddingProvider interface (T1).
|
|
3
|
+
*
|
|
4
|
+
* A3 spec §3 (locked from user task description):
|
|
5
|
+
* readonly name, dimensions, maxTokens, costPerMillionTokens
|
|
6
|
+
* embed(texts: string[]): Promise<Float32Array[]>
|
|
7
|
+
* healthCheck(): Promise<HealthStatus>
|
|
8
|
+
*
|
|
9
|
+
* Notes:
|
|
10
|
+
* - `Float32Array[]` — one vector per input text. Avoid Buffer typed-array aliasing
|
|
11
|
+
* (lesson 2026-05-03: Node Buffer pool corrupts Float32Array views; cache impls
|
|
12
|
+
* must copy via Uint8Array intermediate).
|
|
13
|
+
* - Implementations may also expose `task_type` (retrieval.query|document) via
|
|
14
|
+
* provider-specific options; this base interface keeps the signature minimal
|
|
15
|
+
* per the locked spec to keep the swap surface narrow.
|
|
16
|
+
* - Stubs may throw "not implemented" from `embed()`; `healthCheck()` MUST still
|
|
17
|
+
* return a deterministic shape so the registry's boot-time ping is uniform.
|
|
18
|
+
*/
|
|
19
|
+
import type { HealthStatus } from "../types.js";
|
|
20
|
+
export interface EmbeddingProvider {
|
|
21
|
+
/** Provider id: 'gemini' | 'openai' | 'voyage' | future ids. */
|
|
22
|
+
readonly name: string;
|
|
23
|
+
/** Output vector dimensionality. Pre-A3.1: must match active corpus dim. */
|
|
24
|
+
readonly dimensions: number;
|
|
25
|
+
/** Max input tokens per single embed() input element (provider-side limit). */
|
|
26
|
+
readonly maxTokens: number;
|
|
27
|
+
/** Public list price in USD per 1,000,000 input tokens. */
|
|
28
|
+
readonly costPerMillionTokens: number;
|
|
29
|
+
/**
|
|
30
|
+
* Compute embeddings for an ordered batch of texts.
|
|
31
|
+
* Returns one Float32Array (length = `dimensions`) per input, in order.
|
|
32
|
+
*/
|
|
33
|
+
embed(texts: string[]): Promise<Float32Array[]>;
|
|
34
|
+
/**
|
|
35
|
+
* Boot-time / on-demand health probe.
|
|
36
|
+
* MUST be cheap (no token consumption) and complete within ~5s.
|
|
37
|
+
*/
|
|
38
|
+
healthCheck(): Promise<HealthStatus>;
|
|
39
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* src/providers/embedding/voyage.ts — Voyage embedding stub (T7).
|
|
3
|
+
*
|
|
4
|
+
* Interface conformance only — throws `NotImplementedError` on `embed()`.
|
|
5
|
+
* Real impl deferred to A3.1.
|
|
6
|
+
*
|
|
7
|
+
* Models reserved:
|
|
8
|
+
* - voyage-3 (1024d) ← default
|
|
9
|
+
* - voyage-3-large (1024d)
|
|
10
|
+
* - voyage-code-2 (1536d) ← code-aware retrieval
|
|
11
|
+
*
|
|
12
|
+
* Note: 1024d ≠ Gemini's 3072d — swap to Voyage requires A3.1 reembed.
|
|
13
|
+
* Stub `healthCheck()` flags this to surface as a clear error before any
|
|
14
|
+
* user accidentally points the corpus at a dim-mismatched provider.
|
|
15
|
+
*/
|
|
16
|
+
import type { EmbeddingProvider } from "./types.js";
|
|
17
|
+
import type { HealthStatus } from "../types.js";
|
|
18
|
+
export declare const VOYAGE_EMBED_DEFAULT_MODEL = "voyage-3";
|
|
19
|
+
export declare const VOYAGE_EMBED_DEFAULT_DIM = 1024;
|
|
20
|
+
export declare const VOYAGE_EMBED_DEFAULT_COST = 0.06;
|
|
21
|
+
export declare const VOYAGE_EMBED_MAX_TOKENS = 32000;
|
|
22
|
+
export interface VoyageEmbeddingOpts {
|
|
23
|
+
model?: string;
|
|
24
|
+
dimensions?: number;
|
|
25
|
+
apiKey?: string;
|
|
26
|
+
}
|
|
27
|
+
export declare class VoyageEmbeddingProvider implements EmbeddingProvider {
|
|
28
|
+
readonly name = "voyage";
|
|
29
|
+
readonly model: string;
|
|
30
|
+
readonly dimensions: number;
|
|
31
|
+
readonly maxTokens: number;
|
|
32
|
+
readonly costPerMillionTokens: number;
|
|
33
|
+
constructor(opts?: VoyageEmbeddingOpts);
|
|
34
|
+
embed(_texts: string[]): Promise<Float32Array[]>;
|
|
35
|
+
healthCheck(): Promise<HealthStatus>;
|
|
36
|
+
}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { NotImplementedError } from "../types.js";
|
|
2
|
+
export const VOYAGE_EMBED_DEFAULT_MODEL = "voyage-3";
|
|
3
|
+
export const VOYAGE_EMBED_DEFAULT_DIM = 1024;
|
|
4
|
+
export const VOYAGE_EMBED_DEFAULT_COST = 0.06;
|
|
5
|
+
export const VOYAGE_EMBED_MAX_TOKENS = 32_000;
|
|
6
|
+
export class VoyageEmbeddingProvider {
|
|
7
|
+
name = "voyage";
|
|
8
|
+
model;
|
|
9
|
+
dimensions;
|
|
10
|
+
maxTokens = VOYAGE_EMBED_MAX_TOKENS;
|
|
11
|
+
costPerMillionTokens = VOYAGE_EMBED_DEFAULT_COST;
|
|
12
|
+
constructor(opts = {}) {
|
|
13
|
+
this.model = opts.model ?? VOYAGE_EMBED_DEFAULT_MODEL;
|
|
14
|
+
this.dimensions = opts.dimensions ?? VOYAGE_EMBED_DEFAULT_DIM;
|
|
15
|
+
}
|
|
16
|
+
async embed(_texts) {
|
|
17
|
+
void _texts;
|
|
18
|
+
throw new NotImplementedError("voyage", "embed");
|
|
19
|
+
}
|
|
20
|
+
async healthCheck() {
|
|
21
|
+
return {
|
|
22
|
+
ok: false,
|
|
23
|
+
latencyMs: 0,
|
|
24
|
+
error: "Voyage embedding provider is a stub (interface conformance only). " +
|
|
25
|
+
"Implement in A3.1 before activating NOX_EMBEDDING_PROVIDER=voyage. " +
|
|
26
|
+
"Note: Voyage default dim is 1024 — swap requires A3.1 reembed.",
|
|
27
|
+
};
|
|
28
|
+
}
|
|
29
|
+
}
|