nox-mem 3.1.0 → 3.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (398) hide show
  1. package/README.md +24 -16
  2. package/dist/__tests__/brief-diversity.test.js +266 -0
  3. package/dist/__tests__/brief.test.js +287 -0
  4. package/dist/__tests__/churn.test.js +66 -0
  5. package/dist/__tests__/edge-typing.test.js +99 -0
  6. package/dist/__tests__/ingest-event.test.js +151 -0
  7. package/dist/__tests__/op-audit-e2e.test.js +130 -0
  8. package/dist/__tests__/pragma-alignment.test.js +123 -0
  9. package/dist/__tests__/reranker.test.js +326 -0
  10. package/dist/__tests__/retention.test.js +99 -0
  11. package/dist/__tests__/search-track-access.test.js +49 -0
  12. package/dist/__tests__/spo-injection.test.js +172 -0
  13. package/dist/__tests__/temporal-detector.test.js +103 -0
  14. package/dist/api/wire-up.js +12 -381
  15. package/dist/api-server.js +6 -102
  16. package/dist/db.js +61 -2
  17. package/dist/embed.js +23 -2
  18. package/dist/index.js +3 -23
  19. package/dist/knowledge-graph.js +20 -0
  20. package/dist/lib/answer/__tests__/e2e-gemini.test.js +229 -0
  21. package/dist/lib/answer/__tests__/integration-sqlite.test.js +388 -0
  22. package/dist/lib/answer/__tests__/integration.test.js +347 -0
  23. package/dist/lib/answer/__tests__/prompt.test.js +117 -0
  24. package/dist/lib/answer/__tests__/t5-t10.test.js +501 -0
  25. package/dist/lib/answer/provider.js +29 -4
  26. package/dist/lib/api/__tests__/safe-error-message.test.js +155 -0
  27. package/dist/lib/auth/__tests__/localhost-guard.test.js +144 -0
  28. package/dist/lib/error-sanitizer/__tests__/sanitize.test.js +354 -0
  29. package/dist/lib/events/__tests__/bus.test.js +208 -0
  30. package/dist/lib/ingest-router.js +0 -43
  31. package/dist/lib/op-audit-extension/__tests__/ran-at-guard.test.js +109 -0
  32. package/dist/lib/regex-extract/__tests__/extractor.test.js +197 -0
  33. package/dist/lib/regex-extract/__tests__/frontmatter.test.js +75 -0
  34. package/dist/lib/regex-extract/__tests__/ingest-router-l4.test.js +139 -0
  35. package/dist/lib/regex-extract/__tests__/production-wire.test.js +177 -0
  36. package/dist/lib/regex-extract/__tests__/reconcile.test.js +170 -0
  37. package/dist/lib/regex-extract/__tests__/strip-code.test.js +36 -0
  38. package/dist/mcp-server.js +2 -1
  39. package/dist/privacy/__tests__/filter.test.js +352 -0
  40. package/dist/providers/__tests__/conformance-extended.test.js +249 -0
  41. package/dist/providers/__tests__/conformance.test.js +98 -0
  42. package/dist/providers/__tests__/cost-cap.test.js +151 -0
  43. package/dist/providers/__tests__/e2e-real.test.js +79 -0
  44. package/dist/providers/__tests__/factory.test.js +80 -0
  45. package/dist/providers/__tests__/fallback.test.js +223 -0
  46. package/dist/providers/__tests__/gemini.test.js +191 -0
  47. package/dist/providers/__tests__/health.test.js +128 -0
  48. package/dist/providers/__tests__/telemetry.test.js +219 -0
  49. package/dist/reindex.js +2 -2
  50. package/dist/version.js +22 -0
  51. package/package.json +3 -4
  52. package/dist/api/answer.d.ts +0 -116
  53. package/dist/api/answer.validate-patch.d.ts +0 -72
  54. package/dist/api/brief-diversity.d.ts +0 -64
  55. package/dist/api/brief.d.ts +0 -114
  56. package/dist/api/conflict.d.ts +0 -33
  57. package/dist/api/conflict.js +0 -143
  58. package/dist/api/cors.d.ts +0 -73
  59. package/dist/api/events-stream-limited.d.ts +0 -133
  60. package/dist/api/events-stream-limited.js +0 -217
  61. package/dist/api/events-stream.d.ts +0 -53
  62. package/dist/api/events-stream.js +0 -125
  63. package/dist/api/export.d.ts +0 -42
  64. package/dist/api/export.js +0 -85
  65. package/dist/api/health-confidence-adapter.d.ts +0 -29
  66. package/dist/api/health-confidence-adapter.js +0 -73
  67. package/dist/api/health-confidence.d.ts +0 -36
  68. package/dist/api/health-confidence.js +0 -141
  69. package/dist/api/hooks.d.ts +0 -50
  70. package/dist/api/hooks.js +0 -115
  71. package/dist/api/import.d.ts +0 -38
  72. package/dist/api/import.js +0 -87
  73. package/dist/api/ingest-event.d.ts +0 -65
  74. package/dist/api/mark.d.ts +0 -42
  75. package/dist/api/mark.js +0 -127
  76. package/dist/api/server-deps-a2.d.ts +0 -55
  77. package/dist/api/server-deps-a2.js +0 -138
  78. package/dist/api/server-deps-l2-l3.d.ts +0 -68
  79. package/dist/api/server-deps-l2-l3.js +0 -123
  80. package/dist/api/server-deps-p1.d.ts +0 -84
  81. package/dist/api/server-deps-p2.d.ts +0 -32
  82. package/dist/api/server-deps-p2.js +0 -84
  83. package/dist/api/server-deps-p5.d.ts +0 -66
  84. package/dist/api/server-deps-p5.js +0 -139
  85. package/dist/api/viewer-static.d.ts +0 -30
  86. package/dist/api/viewer-static.js +0 -102
  87. package/dist/api/wire-up.d.ts +0 -54
  88. package/dist/api-impact.d.ts +0 -30
  89. package/dist/api-server.d.ts +0 -2
  90. package/dist/backfill-fts-anchor.d.ts +0 -15
  91. package/dist/backfill-source-type.d.ts +0 -20
  92. package/dist/churn.d.ts +0 -31
  93. package/dist/cli/answer.d.ts +0 -66
  94. package/dist/cli/conflict.d.ts +0 -38
  95. package/dist/cli/conflict.js +0 -282
  96. package/dist/cli/export.d.ts +0 -51
  97. package/dist/cli/export.js +0 -280
  98. package/dist/cli/hooks.d.ts +0 -54
  99. package/dist/cli/hooks.js +0 -133
  100. package/dist/cli/import.d.ts +0 -52
  101. package/dist/cli/import.js +0 -274
  102. package/dist/cli/mark.d.ts +0 -33
  103. package/dist/cli/mark.js +0 -130
  104. package/dist/cli/ocr-batch.d.ts +0 -12
  105. package/dist/cli/ocr-batch.js +0 -411
  106. package/dist/cli/snapshot-main.d.ts +0 -30
  107. package/dist/cli/snapshot-main.js +0 -47
  108. package/dist/cli/viewer.d.ts +0 -35
  109. package/dist/cli/viewer.js +0 -71
  110. package/dist/cli-telemetry.d.ts +0 -36
  111. package/dist/cli-telemetry.js +0 -150
  112. package/dist/compact.d.ts +0 -7
  113. package/dist/consolidate.d.ts +0 -18
  114. package/dist/consolidation.d.ts +0 -32
  115. package/dist/cross-agent-v2.d.ts +0 -45
  116. package/dist/cross-search.d.ts +0 -11
  117. package/dist/crystallize.d.ts +0 -43
  118. package/dist/db.d.ts +0 -11
  119. package/dist/dedup.d.ts +0 -1
  120. package/dist/detect-changes.d.ts +0 -29
  121. package/dist/digest.d.ts +0 -1
  122. package/dist/doctor.d.ts +0 -1
  123. package/dist/embed.d.ts +0 -57
  124. package/dist/evals.d.ts +0 -176
  125. package/dist/evals.js +0 -351
  126. package/dist/generate-user-profile.d.ts +0 -18
  127. package/dist/graphify-ingest.d.ts +0 -18
  128. package/dist/impact.d.ts +0 -39
  129. package/dist/index.d.ts +0 -2
  130. package/dist/ingest-entity.d.ts +0 -44
  131. package/dist/ingest.d.ts +0 -13
  132. package/dist/kg-llm.d.ts +0 -39
  133. package/dist/knowledge-graph.d.ts +0 -72
  134. package/dist/lib/answer/config.d.ts +0 -41
  135. package/dist/lib/answer/index.d.ts +0 -47
  136. package/dist/lib/answer/prompt.d.ts +0 -37
  137. package/dist/lib/answer/provider.d.ts +0 -47
  138. package/dist/lib/answer/retrieval.d.ts +0 -36
  139. package/dist/lib/answer/telemetry.d.ts +0 -99
  140. package/dist/lib/answer/types.d.ts +0 -108
  141. package/dist/lib/api/error-leak-fix.d.ts +0 -54
  142. package/dist/lib/api/safe-error-message.d.ts +0 -70
  143. package/dist/lib/archive/common-passwords.d.ts +0 -37
  144. package/dist/lib/archive/common-passwords.js +0 -753
  145. package/dist/lib/archive/encryption.d.ts +0 -81
  146. package/dist/lib/archive/encryption.js +0 -236
  147. package/dist/lib/archive/enforce-strength.d.ts +0 -54
  148. package/dist/lib/archive/enforce-strength.js +0 -70
  149. package/dist/lib/archive/entropy.d.ts +0 -34
  150. package/dist/lib/archive/entropy.js +0 -180
  151. package/dist/lib/archive/export-locking.d.ts +0 -102
  152. package/dist/lib/archive/export-locking.js +0 -202
  153. package/dist/lib/archive/format.d.ts +0 -20
  154. package/dist/lib/archive/format.js +0 -174
  155. package/dist/lib/archive/index.d.ts +0 -23
  156. package/dist/lib/archive/index.js +0 -17
  157. package/dist/lib/archive/manifest.d.ts +0 -53
  158. package/dist/lib/archive/manifest.js +0 -183
  159. package/dist/lib/archive/migration.d.ts +0 -36
  160. package/dist/lib/archive/migration.js +0 -100
  161. package/dist/lib/archive/migrations/v18_to_v19.d.ts +0 -16
  162. package/dist/lib/archive/migrations/v18_to_v19.js +0 -18
  163. package/dist/lib/archive/orchestrator.d.ts +0 -166
  164. package/dist/lib/archive/orchestrator.js +0 -428
  165. package/dist/lib/archive/serializers/chunks.d.ts +0 -30
  166. package/dist/lib/archive/serializers/chunks.js +0 -113
  167. package/dist/lib/archive/serializers/embeddings.d.ts +0 -36
  168. package/dist/lib/archive/serializers/embeddings.js +0 -115
  169. package/dist/lib/archive/serializers/kg.d.ts +0 -28
  170. package/dist/lib/archive/serializers/kg.js +0 -184
  171. package/dist/lib/archive/serializers/ops_audit.d.ts +0 -21
  172. package/dist/lib/archive/serializers/ops_audit.js +0 -97
  173. package/dist/lib/archive/server-deps.d.ts +0 -131
  174. package/dist/lib/archive/server-deps.js +0 -232
  175. package/dist/lib/archive/strength.d.ts +0 -50
  176. package/dist/lib/archive/strength.js +0 -77
  177. package/dist/lib/archive/types.d.ts +0 -159
  178. package/dist/lib/archive/types.js +0 -45
  179. package/dist/lib/archive/unpack-streaming.d.ts +0 -70
  180. package/dist/lib/archive/unpack-streaming.js +0 -255
  181. package/dist/lib/auth/localhost-guard.d.ts +0 -106
  182. package/dist/lib/confidence/config.d.ts +0 -37
  183. package/dist/lib/confidence/config.js +0 -107
  184. package/dist/lib/confidence/db-shim-singleton.d.ts +0 -20
  185. package/dist/lib/confidence/db-shim-singleton.js +0 -41
  186. package/dist/lib/confidence/db-shim.d.ts +0 -47
  187. package/dist/lib/confidence/db-shim.js +0 -141
  188. package/dist/lib/confidence/mark.d.ts +0 -58
  189. package/dist/lib/confidence/mark.js +0 -168
  190. package/dist/lib/confidence/ranking.d.ts +0 -69
  191. package/dist/lib/confidence/ranking.js +0 -101
  192. package/dist/lib/confidence/search-filter.d.ts +0 -44
  193. package/dist/lib/confidence/search-filter.js +0 -103
  194. package/dist/lib/confidence/types.d.ts +0 -146
  195. package/dist/lib/confidence/types.js +0 -20
  196. package/dist/lib/confidence/write-hooks.d.ts +0 -50
  197. package/dist/lib/confidence/write-hooks.js +0 -159
  198. package/dist/lib/conflict/audit-fk-check.d.ts +0 -72
  199. package/dist/lib/conflict/audit-fk-check.js +0 -131
  200. package/dist/lib/conflict/audit-writer.d.ts +0 -39
  201. package/dist/lib/conflict/audit-writer.js +0 -133
  202. package/dist/lib/conflict/db-singleton.d.ts +0 -28
  203. package/dist/lib/conflict/db-singleton.js +0 -61
  204. package/dist/lib/conflict/db.d.ts +0 -27
  205. package/dist/lib/conflict/db.js +0 -20
  206. package/dist/lib/conflict/detector-direct.d.ts +0 -21
  207. package/dist/lib/conflict/detector-direct.js +0 -105
  208. package/dist/lib/conflict/evidence.d.ts +0 -24
  209. package/dist/lib/conflict/evidence.js +0 -76
  210. package/dist/lib/conflict/index.d.ts +0 -14
  211. package/dist/lib/conflict/index.js +0 -12
  212. package/dist/lib/conflict/scheduler.d.ts +0 -78
  213. package/dist/lib/conflict/scheduler.js +0 -111
  214. package/dist/lib/conflict/shadow.d.ts +0 -75
  215. package/dist/lib/conflict/shadow.js +0 -161
  216. package/dist/lib/conflict/types.d.ts +0 -133
  217. package/dist/lib/conflict/types.js +0 -19
  218. package/dist/lib/cost-cap.d.ts +0 -94
  219. package/dist/lib/deps/deps-registry.d.ts +0 -111
  220. package/dist/lib/error-sanitizer/middleware.d.ts +0 -43
  221. package/dist/lib/error-sanitizer/sanitize.d.ts +0 -78
  222. package/dist/lib/eval-batch.d.ts +0 -34
  223. package/dist/lib/eval-batch.js +0 -103
  224. package/dist/lib/eval-metrics.d.ts +0 -36
  225. package/dist/lib/eval-metrics.js +0 -95
  226. package/dist/lib/eval.d.ts +0 -106
  227. package/dist/lib/eval.js +0 -343
  228. package/dist/lib/events/bus.d.ts +0 -135
  229. package/dist/lib/fts-anchor.d.ts +0 -1
  230. package/dist/lib/hooks/classifier.d.ts +0 -47
  231. package/dist/lib/hooks/classifier.js +0 -129
  232. package/dist/lib/hooks/config.d.ts +0 -49
  233. package/dist/lib/hooks/config.js +0 -106
  234. package/dist/lib/hooks/decorators.d.ts +0 -35
  235. package/dist/lib/hooks/decorators.js +0 -59
  236. package/dist/lib/hooks/pipeline.d.ts +0 -76
  237. package/dist/lib/hooks/pipeline.js +0 -213
  238. package/dist/lib/hooks/privacy-filter-adapter.d.ts +0 -55
  239. package/dist/lib/hooks/privacy-filter-adapter.js +0 -84
  240. package/dist/lib/hooks/rate-limit-constant-time.d.ts +0 -57
  241. package/dist/lib/hooks/rate-limit-constant-time.js +0 -69
  242. package/dist/lib/hooks/rate-limit-dryrun-fix.d.ts +0 -71
  243. package/dist/lib/hooks/rate-limit-dryrun-fix.js +0 -110
  244. package/dist/lib/hooks/rate-limit.d.ts +0 -54
  245. package/dist/lib/hooks/rate-limit.js +0 -122
  246. package/dist/lib/hooks/server-deps.d.ts +0 -61
  247. package/dist/lib/hooks/server-deps.js +0 -92
  248. package/dist/lib/hooks/source-allowlist.d.ts +0 -26
  249. package/dist/lib/hooks/source-allowlist.js +0 -53
  250. package/dist/lib/hooks/types.d.ts +0 -129
  251. package/dist/lib/hooks/types.js +0 -24
  252. package/dist/lib/hooks/worker.d.ts +0 -56
  253. package/dist/lib/hooks/worker.js +0 -150
  254. package/dist/lib/ingest-router.d.ts +0 -25
  255. package/dist/lib/ocr-detector.d.ts +0 -61
  256. package/dist/lib/ocr-detector.js +0 -138
  257. package/dist/lib/ocr-engine-stub.d.ts +0 -48
  258. package/dist/lib/ocr-engine-stub.js +0 -190
  259. package/dist/lib/ocr-engines/google-doc-ai.d.ts +0 -36
  260. package/dist/lib/ocr-engines/google-doc-ai.js +0 -164
  261. package/dist/lib/ocr-jobs.d.ts +0 -67
  262. package/dist/lib/ocr-jobs.js +0 -129
  263. package/dist/lib/op-audit-extension/ran-at-guard.d.ts +0 -86
  264. package/dist/lib/op-audit.d.ts +0 -71
  265. package/dist/lib/privacy-br/detector.d.ts +0 -42
  266. package/dist/lib/privacy-br/detector.js +0 -130
  267. package/dist/lib/privacy-br/index.d.ts +0 -20
  268. package/dist/lib/privacy-br/index.js +0 -20
  269. package/dist/lib/privacy-br/integration.d.ts +0 -71
  270. package/dist/lib/privacy-br/integration.js +0 -74
  271. package/dist/lib/privacy-br/patterns.d.ts +0 -117
  272. package/dist/lib/privacy-br/patterns.js +0 -434
  273. package/dist/lib/privacy-br/redact.d.ts +0 -42
  274. package/dist/lib/privacy-br/redact.js +0 -103
  275. package/dist/lib/privacy-br/types.d.ts +0 -55
  276. package/dist/lib/privacy-br/types.js +0 -25
  277. package/dist/lib/regex-extract/extractor.d.ts +0 -30
  278. package/dist/lib/regex-extract/frontmatter.d.ts +0 -44
  279. package/dist/lib/regex-extract/index.d.ts +0 -14
  280. package/dist/lib/regex-extract/ingest-router-l4.d.ts +0 -76
  281. package/dist/lib/regex-extract/patterns.d.ts +0 -61
  282. package/dist/lib/regex-extract/production-wire.d.ts +0 -128
  283. package/dist/lib/regex-extract/reconcile.d.ts +0 -162
  284. package/dist/lib/regex-extract/strip-code.d.ts +0 -24
  285. package/dist/lib/regex-extract/types.d.ts +0 -48
  286. package/dist/lib/reranker.d.ts +0 -80
  287. package/dist/lib/shadow-tracker.d.ts +0 -191
  288. package/dist/lib/shadow-tracker.js +0 -384
  289. package/dist/lib/spo-injection.d.ts +0 -52
  290. package/dist/lib/telemetry-collector.d.ts +0 -158
  291. package/dist/lib/telemetry-collector.js +0 -249
  292. package/dist/lib/temporal-detector.d.ts +0 -27
  293. package/dist/lib/viewer/auth.d.ts +0 -37
  294. package/dist/lib/viewer/auth.js +0 -70
  295. package/dist/lib/viewer/backpressure.d.ts +0 -59
  296. package/dist/lib/viewer/backpressure.js +0 -100
  297. package/dist/lib/viewer/broadcast-singleton.d.ts +0 -34
  298. package/dist/lib/viewer/broadcast-singleton.js +0 -49
  299. package/dist/lib/viewer/broadcast.d.ts +0 -66
  300. package/dist/lib/viewer/broadcast.js +0 -96
  301. package/dist/lib/viewer/event-types.d.ts +0 -132
  302. package/dist/lib/viewer/event-types.js +0 -74
  303. package/dist/lib/viewer/instrumentation.d.ts +0 -106
  304. package/dist/lib/viewer/instrumentation.js +0 -224
  305. package/dist/lib/viewer/migration.d.ts +0 -23
  306. package/dist/lib/viewer/migration.js +0 -56
  307. package/dist/lib/viewer/redaction.d.ts +0 -44
  308. package/dist/lib/viewer/redaction.js +0 -139
  309. package/dist/lib/viewer/session.d.ts +0 -51
  310. package/dist/lib/viewer/session.js +0 -87
  311. package/dist/mcp/tools/answer.d.ts +0 -94
  312. package/dist/mcp/tools/archive.d.ts +0 -152
  313. package/dist/mcp/tools/archive.js +0 -170
  314. package/dist/mcp/tools/conflict.d.ts +0 -44
  315. package/dist/mcp/tools/conflict.js +0 -130
  316. package/dist/mcp/tools/hooks.d.ts +0 -29
  317. package/dist/mcp/tools/hooks.js +0 -78
  318. package/dist/mcp/tools/mark.d.ts +0 -38
  319. package/dist/mcp/tools/mark.js +0 -82
  320. package/dist/mcp/tools/viewer.d.ts +0 -58
  321. package/dist/mcp/tools/viewer.js +0 -64
  322. package/dist/mcp-server.d.ts +0 -2
  323. package/dist/metrics.d.ts +0 -3
  324. package/dist/noise-filter.d.ts +0 -18
  325. package/dist/notion-sync.d.ts +0 -7
  326. package/dist/notion-sync.js +0 -97
  327. package/dist/observability/adapters/a3-adapter.d.ts +0 -63
  328. package/dist/observability/adapters/a3-adapter.js +0 -83
  329. package/dist/observability/adapters/p1-adapter.d.ts +0 -49
  330. package/dist/observability/adapters/p1-adapter.js +0 -63
  331. package/dist/observability/adapters/p5-adapter.d.ts +0 -36
  332. package/dist/observability/adapters/p5-adapter.js +0 -71
  333. package/dist/observability/cardinality.d.ts +0 -61
  334. package/dist/observability/cardinality.js +0 -300
  335. package/dist/observability/collectors/db-stats.collector.d.ts +0 -9
  336. package/dist/observability/collectors/db-stats.collector.js +0 -88
  337. package/dist/observability/collectors/eventbus.collector.d.ts +0 -6
  338. package/dist/observability/collectors/eventbus.collector.js +0 -50
  339. package/dist/observability/collectors/process.collector.d.ts +0 -7
  340. package/dist/observability/collectors/process.collector.js +0 -93
  341. package/dist/observability/collectors/provider-telemetry.collector.d.ts +0 -11
  342. package/dist/observability/collectors/provider-telemetry.collector.js +0 -112
  343. package/dist/observability/collectors/search-telemetry.collector.d.ts +0 -12
  344. package/dist/observability/collectors/search-telemetry.collector.js +0 -76
  345. package/dist/observability/exporter.d.ts +0 -30
  346. package/dist/observability/exporter.js +0 -182
  347. package/dist/observability/index.d.ts +0 -22
  348. package/dist/observability/index.js +0 -21
  349. package/dist/observability/metrics.d.ts +0 -53
  350. package/dist/observability/metrics.js +0 -213
  351. package/dist/observability/privacy-guard.d.ts +0 -32
  352. package/dist/observability/privacy-guard.js +0 -116
  353. package/dist/observability/record.d.ts +0 -83
  354. package/dist/observability/record.js +0 -217
  355. package/dist/observability/registry.d.ts +0 -60
  356. package/dist/observability/registry.js +0 -93
  357. package/dist/observability/types.d.ts +0 -115
  358. package/dist/observability/types.js +0 -235
  359. package/dist/observability.d.ts +0 -131
  360. package/dist/plugins/nox-hooks/index.d.ts +0 -61
  361. package/dist/plugins/nox-hooks/index.js +0 -99
  362. package/dist/primer.d.ts +0 -1
  363. package/dist/privacy/filter.d.ts +0 -27
  364. package/dist/privacy/patterns.d.ts +0 -29
  365. package/dist/privacy/tag-parser.d.ts +0 -24
  366. package/dist/project-context-gen.d.ts +0 -10
  367. package/dist/providers/embedding/gemini.d.ts +0 -73
  368. package/dist/providers/embedding/openai.d.ts +0 -76
  369. package/dist/providers/embedding/types.d.ts +0 -39
  370. package/dist/providers/embedding/voyage.d.ts +0 -36
  371. package/dist/providers/index.d.ts +0 -116
  372. package/dist/providers/llm/anthropic.d.ts +0 -29
  373. package/dist/providers/llm/chain.d.ts +0 -99
  374. package/dist/providers/llm/gemini.d.ts +0 -48
  375. package/dist/providers/llm/openai.d.ts +0 -64
  376. package/dist/providers/llm/types.d.ts +0 -47
  377. package/dist/providers/telemetry.d.ts +0 -87
  378. package/dist/providers/types.d.ts +0 -42
  379. package/dist/query-entity-count.d.ts +0 -54
  380. package/dist/reflect.d.ts +0 -26
  381. package/dist/reindex-errors.d.ts +0 -7
  382. package/dist/reindex.d.ts +0 -16
  383. package/dist/retention.d.ts +0 -40
  384. package/dist/salience.d.ts +0 -85
  385. package/dist/scripts/migrate-v17-ops-audit.d.ts +0 -17
  386. package/dist/search-dedup.d.ts +0 -44
  387. package/dist/search-expansion.d.ts +0 -20
  388. package/dist/search.d.ts +0 -62
  389. package/dist/seh-detector.d.ts +0 -31
  390. package/dist/self-improve.d.ts +0 -1
  391. package/dist/session-distill.d.ts +0 -29
  392. package/dist/session-update.d.ts +0 -1
  393. package/dist/shared-memory.d.ts +0 -24
  394. package/dist/stats.d.ts +0 -1
  395. package/dist/temporal-retrieval.d.ts +0 -132
  396. package/dist/tier-manager.d.ts +0 -69
  397. package/dist/vectorize.d.ts +0 -16
  398. package/dist/watch.d.ts +0 -8
@@ -1,133 +0,0 @@
1
- /**
2
- * G11 — SSE concurrent connection limit (Wave G)
3
- *
4
- * Extends `openSseStream()` (P5 T3) with three connection-control knobs:
5
- *
6
- * 1. NOX_VIEWER_MAX_CONNECTIONS (default 50)
7
- * Global cap on concurrent SSE clients. New requests above the cap
8
- * receive 503 + `Retry-After: 5` and a JSON `{ error: "sse_capacity" }`.
9
- *
10
- * 2. NOX_VIEWER_MAX_PER_IP (default 5)
11
- * Per-IP cap. Same response as global cap, with `Retry-After: 10`.
12
- *
13
- * 3. NOX_VIEWER_DROP_OLDEST=1 (default off)
14
- * Instead of rejecting new connections, close the oldest one when the
15
- * global cap is exceeded. Useful for ops/admin viewers that prefer
16
- * "newest wins" semantics. Per-IP cap still rejects regardless (a single
17
- * IP shouldn't be able to evict other tenants).
18
- *
19
- * Threat:
20
- * - Without a cap, an attacker can open thousands of SSE connections,
21
- * pin sockets + memory + ring buffer wake-ups, and starve legitimate
22
- * viewers (connection exhaustion DoS — G11 / R-P5-2.1).
23
- *
24
- * Backward compat:
25
- * - All knobs are env-opt-in. Defaults (50 global, 5 per-IP) are generous
26
- * enough that interactive use is unaffected; only abusive bursts hit them.
27
- * - Existing `openSseStream()` from P5 T3 is unchanged. This module wraps it.
28
- *
29
- * Refs:
30
- * - docs/security/THREAT-MODEL.md §7.5 T-P5-2 (DoS / connection exhaustion).
31
- * - PR #58 §14 G11.
32
- */
33
- import type { Broadcaster } from "../lib/viewer/broadcast.js";
34
- import { type OpenSseStreamOptions, type SseStream } from "./events-stream.js";
35
- export interface SseLimitConfig {
36
- /** Global cap on concurrent SSE clients. Default 50. */
37
- maxConnections: number;
38
- /** Per-IP cap. Default 5. */
39
- maxPerIp: number;
40
- /** If true, drop oldest connection instead of rejecting new ones. */
41
- dropOldest: boolean;
42
- }
43
- /**
44
- * Read config from environment. Pure helper — does not mutate process state.
45
- * Each call re-reads `process.env` so tests can stub it.
46
- */
47
- export declare function readSseLimitConfig(env?: NodeJS.ProcessEnv): SseLimitConfig;
48
- interface TrackedClient {
49
- clientId: string;
50
- ip: string;
51
- /** Monotonic open time (ms since epoch). */
52
- openedAt: number;
53
- /** Close hook supplied by `openSseStream()`. */
54
- close: () => void;
55
- }
56
- /**
57
- * Tracks live SSE clients so we can enforce concurrent-connection limits.
58
- * One instance per process (singleton via `getSseTracker()` below).
59
- */
60
- export declare class SseConnectionTracker {
61
- private readonly clients;
62
- private readonly byIp;
63
- /** Total live clients. */
64
- size(): number;
65
- /** Live clients for a single IP. */
66
- sizePerIp(ip: string): number;
67
- /** Snapshot for telemetry / tests. Order = insertion order (oldest first). */
68
- snapshot(): readonly Readonly<TrackedClient>[];
69
- /** Register a new client. Caller must invoke `unregister()` on close. */
70
- register(client: TrackedClient): void;
71
- unregister(clientId: string): void;
72
- /**
73
- * Close + unregister the oldest tracked client.
74
- * Returns the closed clientId, or null when tracker is empty.
75
- */
76
- dropOldest(): string | null;
77
- /** Test helper — reset between cases. */
78
- clear(): void;
79
- }
80
- export declare function getSseTracker(): SseConnectionTracker;
81
- /** Test helper — fresh tracker, callers should restore via `setSseTracker(prev)`. */
82
- export declare function setSseTracker(t: SseConnectionTracker | null): SseConnectionTracker | null;
83
- /** Reject reason. Includes Retry-After hint for clients. */
84
- export interface SseReject {
85
- rejected: true;
86
- status: 503;
87
- retryAfterSeconds: number;
88
- reason: "global_cap" | "per_ip_cap";
89
- body: {
90
- error: "sse_capacity";
91
- reason: string;
92
- max: number;
93
- };
94
- }
95
- export interface SseAccept {
96
- rejected: false;
97
- stream: SseStream;
98
- /** Total live clients AFTER this connection was accepted. */
99
- liveCount: number;
100
- }
101
- export type SseOpenResult = SseAccept | SseReject;
102
- export interface OpenLimitedSseOptions extends OpenSseStreamOptions {
103
- /** Client IP — derived from `X-Forwarded-For` first hop or socket.remoteAddress. */
104
- ip: string;
105
- /** Override config (tests). */
106
- config?: SseLimitConfig;
107
- /** Override tracker (tests). */
108
- tracker?: SseConnectionTracker;
109
- /** Broadcaster reference — required for `openSseStream`. */
110
- broadcaster: Broadcaster;
111
- }
112
- /**
113
- * Open an SSE stream with concurrent-connection limits enforced.
114
- *
115
- * Decision tree:
116
- * 1. If per-IP count >= maxPerIp → reject 503 (per_ip_cap, Retry-After 10s)
117
- * 2. If global count >= maxConnections:
118
- * a. dropOldest=true → close oldest, accept new
119
- * b. dropOldest=false → reject 503 (global_cap, Retry-After 5s)
120
- * 3. Else accept.
121
- */
122
- export declare function openLimitedSseStream(opts: OpenLimitedSseOptions): SseOpenResult;
123
- /**
124
- * Build the HTTP 503 response payload + headers for caller frameworks
125
- * (Express / Fastify / raw http). Keeps SSE accept-side and reject-side
126
- * symmetrical for the host wiring.
127
- */
128
- export declare function rejectionToHttp(reject: SseReject): {
129
- status: 503;
130
- headers: Record<string, string>;
131
- body: SseReject["body"];
132
- };
133
- export {};
@@ -1,217 +0,0 @@
1
- /**
2
- * G11 — SSE concurrent connection limit (Wave G)
3
- *
4
- * Extends `openSseStream()` (P5 T3) with three connection-control knobs:
5
- *
6
- * 1. NOX_VIEWER_MAX_CONNECTIONS (default 50)
7
- * Global cap on concurrent SSE clients. New requests above the cap
8
- * receive 503 + `Retry-After: 5` and a JSON `{ error: "sse_capacity" }`.
9
- *
10
- * 2. NOX_VIEWER_MAX_PER_IP (default 5)
11
- * Per-IP cap. Same response as global cap, with `Retry-After: 10`.
12
- *
13
- * 3. NOX_VIEWER_DROP_OLDEST=1 (default off)
14
- * Instead of rejecting new connections, close the oldest one when the
15
- * global cap is exceeded. Useful for ops/admin viewers that prefer
16
- * "newest wins" semantics. Per-IP cap still rejects regardless (a single
17
- * IP shouldn't be able to evict other tenants).
18
- *
19
- * Threat:
20
- * - Without a cap, an attacker can open thousands of SSE connections,
21
- * pin sockets + memory + ring buffer wake-ups, and starve legitimate
22
- * viewers (connection exhaustion DoS — G11 / R-P5-2.1).
23
- *
24
- * Backward compat:
25
- * - All knobs are env-opt-in. Defaults (50 global, 5 per-IP) are generous
26
- * enough that interactive use is unaffected; only abusive bursts hit them.
27
- * - Existing `openSseStream()` from P5 T3 is unchanged. This module wraps it.
28
- *
29
- * Refs:
30
- * - docs/security/THREAT-MODEL.md §7.5 T-P5-2 (DoS / connection exhaustion).
31
- * - PR #58 §14 G11.
32
- */
33
- import { openSseStream } from "./events-stream.js";
34
- /**
35
- * Read config from environment. Pure helper — does not mutate process state.
36
- * Each call re-reads `process.env` so tests can stub it.
37
- */
38
- export function readSseLimitConfig(env = process.env) {
39
- const parsePositiveInt = (raw, fallback) => {
40
- if (!raw)
41
- return fallback;
42
- const n = Number.parseInt(raw, 10);
43
- return Number.isFinite(n) && n > 0 ? n : fallback;
44
- };
45
- return {
46
- maxConnections: parsePositiveInt(env.NOX_VIEWER_MAX_CONNECTIONS, 50),
47
- maxPerIp: parsePositiveInt(env.NOX_VIEWER_MAX_PER_IP, 5),
48
- dropOldest: env.NOX_VIEWER_DROP_OLDEST === "1",
49
- };
50
- }
51
- /**
52
- * Tracks live SSE clients so we can enforce concurrent-connection limits.
53
- * One instance per process (singleton via `getSseTracker()` below).
54
- */
55
- export class SseConnectionTracker {
56
- clients = new Map();
57
- byIp = new Map();
58
- /** Total live clients. */
59
- size() {
60
- return this.clients.size;
61
- }
62
- /** Live clients for a single IP. */
63
- sizePerIp(ip) {
64
- return this.byIp.get(ip)?.size ?? 0;
65
- }
66
- /** Snapshot for telemetry / tests. Order = insertion order (oldest first). */
67
- snapshot() {
68
- return Array.from(this.clients.values());
69
- }
70
- /** Register a new client. Caller must invoke `unregister()` on close. */
71
- register(client) {
72
- this.clients.set(client.clientId, client);
73
- const ipSet = this.byIp.get(client.ip);
74
- if (ipSet)
75
- ipSet.add(client.clientId);
76
- else
77
- this.byIp.set(client.ip, new Set([client.clientId]));
78
- }
79
- unregister(clientId) {
80
- const c = this.clients.get(clientId);
81
- if (!c)
82
- return;
83
- this.clients.delete(clientId);
84
- const ipSet = this.byIp.get(c.ip);
85
- if (ipSet) {
86
- ipSet.delete(clientId);
87
- if (ipSet.size === 0)
88
- this.byIp.delete(c.ip);
89
- }
90
- }
91
- /**
92
- * Close + unregister the oldest tracked client.
93
- * Returns the closed clientId, or null when tracker is empty.
94
- */
95
- dropOldest() {
96
- const oldest = this.clients.values().next().value;
97
- if (!oldest)
98
- return null;
99
- oldest.close();
100
- this.unregister(oldest.clientId);
101
- return oldest.clientId;
102
- }
103
- /** Test helper — reset between cases. */
104
- clear() {
105
- for (const c of this.clients.values()) {
106
- try {
107
- c.close();
108
- }
109
- catch {
110
- /* swallow — best effort cleanup */
111
- }
112
- }
113
- this.clients.clear();
114
- this.byIp.clear();
115
- }
116
- }
117
- let _trackerSingleton = null;
118
- export function getSseTracker() {
119
- if (!_trackerSingleton)
120
- _trackerSingleton = new SseConnectionTracker();
121
- return _trackerSingleton;
122
- }
123
- /** Test helper — fresh tracker, callers should restore via `setSseTracker(prev)`. */
124
- export function setSseTracker(t) {
125
- const prev = _trackerSingleton;
126
- _trackerSingleton = t;
127
- return prev;
128
- }
129
- /**
130
- * Open an SSE stream with concurrent-connection limits enforced.
131
- *
132
- * Decision tree:
133
- * 1. If per-IP count >= maxPerIp → reject 503 (per_ip_cap, Retry-After 10s)
134
- * 2. If global count >= maxConnections:
135
- * a. dropOldest=true → close oldest, accept new
136
- * b. dropOldest=false → reject 503 (global_cap, Retry-After 5s)
137
- * 3. Else accept.
138
- */
139
- export function openLimitedSseStream(opts) {
140
- const config = opts.config ?? readSseLimitConfig();
141
- const tracker = opts.tracker ?? getSseTracker();
142
- // 1. Per-IP cap — checked BEFORE global, because a single IP shouldn't be
143
- // able to evict legit clients via dropOldest.
144
- if (tracker.sizePerIp(opts.ip) >= config.maxPerIp) {
145
- return {
146
- rejected: true,
147
- status: 503,
148
- retryAfterSeconds: 10,
149
- reason: "per_ip_cap",
150
- body: {
151
- error: "sse_capacity",
152
- reason: "per_ip_cap",
153
- max: config.maxPerIp,
154
- },
155
- };
156
- }
157
- // 2. Global cap.
158
- if (tracker.size() >= config.maxConnections) {
159
- if (config.dropOldest) {
160
- tracker.dropOldest();
161
- }
162
- else {
163
- return {
164
- rejected: true,
165
- status: 503,
166
- retryAfterSeconds: 5,
167
- reason: "global_cap",
168
- body: {
169
- error: "sse_capacity",
170
- reason: "global_cap",
171
- max: config.maxConnections,
172
- },
173
- };
174
- }
175
- }
176
- // 3. Accept — wrap close to unregister from tracker.
177
- const stream = openSseStream(opts);
178
- const wrappedClose = () => {
179
- try {
180
- stream.close();
181
- }
182
- finally {
183
- tracker.unregister(opts.clientId);
184
- }
185
- };
186
- tracker.register({
187
- clientId: opts.clientId,
188
- ip: opts.ip,
189
- openedAt: Date.now(),
190
- close: wrappedClose,
191
- });
192
- return {
193
- rejected: false,
194
- stream: {
195
- headers: stream.headers,
196
- iter: stream.iter,
197
- close: wrappedClose,
198
- },
199
- liveCount: tracker.size(),
200
- };
201
- }
202
- /**
203
- * Build the HTTP 503 response payload + headers for caller frameworks
204
- * (Express / Fastify / raw http). Keeps SSE accept-side and reject-side
205
- * symmetrical for the host wiring.
206
- */
207
- export function rejectionToHttp(reject) {
208
- return {
209
- status: 503,
210
- headers: {
211
- "Content-Type": "application/json; charset=utf-8",
212
- "Retry-After": String(reject.retryAfterSeconds),
213
- "Cache-Control": "no-store",
214
- },
215
- body: reject.body,
216
- };
217
- }
@@ -1,53 +0,0 @@
1
- /**
2
- * T3 — SSE handler (framework-agnostic)
3
- *
4
- * Returns an async iterable of SSE lines + the header set to attach.
5
- * Caller (Express / Fastify / raw http) wires this onto a response stream:
6
- *
7
- * const sse = openSseStream({ broadcaster, clientId, lastEventId });
8
- * res.writeHead(200, sse.headers);
9
- * for await (const chunk of sse.iter) {
10
- * if (!res.write(chunk)) await once(res, "drain");
11
- * }
12
- *
13
- * On client disconnect, caller invokes `sse.close()` to release resources.
14
- */
15
- import { Broadcaster, type BroadcastEnvelope } from "../lib/viewer/broadcast.js";
16
- export interface OpenSseStreamOptions {
17
- broadcaster: Broadcaster;
18
- /** Client id (UUIDv4). Caller mints + injects. */
19
- clientId: string;
20
- /** Last-Event-ID from request header, if any. */
21
- lastEventId?: number;
22
- /** Heartbeat interval ms. Default 15000. */
23
- heartbeatMs?: number;
24
- /** Hook called whenever an envelope is written (for telemetry). */
25
- onWrite?: (env: BroadcastEnvelope) => void;
26
- /** Hook called whenever a drop happens (queue full). */
27
- onDrop?: (count: number) => void;
28
- }
29
- export interface SseStream {
30
- headers: Record<string, string>;
31
- iter: AsyncIterable<string>;
32
- close: () => void;
33
- }
34
- export declare const SSE_HEADERS: Record<string, string>;
35
- /**
36
- * Format a ViewerEvent envelope as a single SSE message.
37
- * Multi-line `data:` is correctly emitted per RFC.
38
- */
39
- export declare function formatSseMessage(env: BroadcastEnvelope): string;
40
- /** Heartbeat is an SSE comment line — ignored by EventSource, keeps proxies alive. */
41
- export declare function formatHeartbeat(ringSize: number, clients: number): string;
42
- /**
43
- * Construct a complete SSE stream:
44
- * - subscribes to the Broadcaster
45
- * - emits SSE-formatted lines via async iterator
46
- * - sends heartbeats on schedule
47
- * - cleans up on `close()`
48
- */
49
- export declare function openSseStream(opts: OpenSseStreamOptions): SseStream;
50
- /**
51
- * Parse the Last-Event-ID header (case-insensitive). Numeric only.
52
- */
53
- export declare function parseLastEventId(headers: Record<string, string | string[] | undefined>): number | undefined;
@@ -1,125 +0,0 @@
1
- /**
2
- * T3 — SSE handler (framework-agnostic)
3
- *
4
- * Returns an async iterable of SSE lines + the header set to attach.
5
- * Caller (Express / Fastify / raw http) wires this onto a response stream:
6
- *
7
- * const sse = openSseStream({ broadcaster, clientId, lastEventId });
8
- * res.writeHead(200, sse.headers);
9
- * for await (const chunk of sse.iter) {
10
- * if (!res.write(chunk)) await once(res, "drain");
11
- * }
12
- *
13
- * On client disconnect, caller invokes `sse.close()` to release resources.
14
- */
15
- import { eventKindLabel } from "../lib/viewer/event-types.js";
16
- export const SSE_HEADERS = {
17
- "Content-Type": "text/event-stream; charset=utf-8",
18
- "Cache-Control": "no-cache, no-transform",
19
- Connection: "keep-alive",
20
- "X-Accel-Buffering": "no", // disable nginx buffering
21
- };
22
- /**
23
- * Format a ViewerEvent envelope as a single SSE message.
24
- * Multi-line `data:` is correctly emitted per RFC.
25
- */
26
- export function formatSseMessage(env) {
27
- const ev = env.ev;
28
- const kindLabel = eventKindLabel(ev);
29
- const payload = JSON.stringify(ev);
30
- // SSE: id, event, data — each on its own line; record terminated by blank line.
31
- return `id: ${env.id}\nevent: ${kindLabel}\ndata: ${payload}\n\n`;
32
- }
33
- /** Heartbeat is an SSE comment line — ignored by EventSource, keeps proxies alive. */
34
- export function formatHeartbeat(ringSize, clients) {
35
- const ts = new Date().toISOString();
36
- return `: heartbeat ${ts} ring=${ringSize} clients=${clients}\n\n`;
37
- }
38
- /**
39
- * Construct a complete SSE stream:
40
- * - subscribes to the Broadcaster
41
- * - emits SSE-formatted lines via async iterator
42
- * - sends heartbeats on schedule
43
- * - cleans up on `close()`
44
- */
45
- export function openSseStream(opts) {
46
- const heartbeatMs = opts.heartbeatMs ?? 15_000;
47
- let closed = false;
48
- let wakeup = null;
49
- let lastReportedDrops = 0;
50
- const wake = () => {
51
- if (wakeup) {
52
- const cb = wakeup;
53
- wakeup = null;
54
- cb();
55
- }
56
- };
57
- const client = opts.broadcaster.addClient(opts.clientId, wake, opts.lastEventId);
58
- let heartbeatDue = false;
59
- const heartbeatTimer = setInterval(() => {
60
- heartbeatDue = true;
61
- if (!closed)
62
- wake();
63
- }, heartbeatMs);
64
- // Don't prevent process exit if forgotten.
65
- if (typeof heartbeatTimer.unref === "function")
66
- heartbeatTimer.unref();
67
- async function* iter() {
68
- // Initial line — tells the client we're connected and arms reconnect.
69
- yield ": connected\n\n";
70
- while (!closed) {
71
- // Drain any queued envelopes first.
72
- const batch = client.queue.drain();
73
- const droppedNow = client.queue.stats().dropped;
74
- if (droppedNow > lastReportedDrops) {
75
- const delta = droppedNow - lastReportedDrops;
76
- lastReportedDrops = droppedNow;
77
- opts.onDrop?.(delta);
78
- }
79
- for (const env of batch) {
80
- client.lastSentId = env.id;
81
- opts.onWrite?.(env);
82
- yield formatSseMessage(env);
83
- }
84
- if (heartbeatDue) {
85
- heartbeatDue = false;
86
- yield formatHeartbeat(opts.broadcaster.ringSnapshot().length, opts.broadcaster.clientCount());
87
- }
88
- if (closed)
89
- break;
90
- // Wait for next wake-up.
91
- await new Promise((resolve) => {
92
- wakeup = resolve;
93
- });
94
- }
95
- }
96
- return {
97
- headers: { ...SSE_HEADERS },
98
- iter: iter(),
99
- close: () => {
100
- if (closed)
101
- return;
102
- closed = true;
103
- clearInterval(heartbeatTimer);
104
- opts.broadcaster.removeClient(opts.clientId);
105
- // Wake the iterator so it exits cleanly.
106
- wake();
107
- },
108
- };
109
- }
110
- /**
111
- * Parse the Last-Event-ID header (case-insensitive). Numeric only.
112
- */
113
- export function parseLastEventId(headers) {
114
- for (const key of Object.keys(headers)) {
115
- if (key.toLowerCase() === "last-event-id") {
116
- const v = headers[key];
117
- const raw = Array.isArray(v) ? v[0] : v;
118
- if (raw === undefined)
119
- return undefined;
120
- const n = Number(raw);
121
- return Number.isFinite(n) && n >= 0 ? n : undefined;
122
- }
123
- }
124
- return undefined;
125
- }
@@ -1,42 +0,0 @@
1
- /**
2
- * T13 — HTTP `POST /api/export` handler (framework-agnostic).
3
- *
4
- * Returns a `{ status, headers, body }` shape so the host server (express,
5
- * fastify, plain http.Server) can adapt without coupling. The actual streaming
6
- * write happens in the caller; we return the archive Buffer plus suggested
7
- * headers (Content-Type, Content-Disposition, Content-Length).
8
- *
9
- * Body schema:
10
- * { unencrypted?: bool,
11
- * passphrase?: string, // accepted ONLY over POST body (TLS-protected)
12
- * project?: string,
13
- * since?: string,
14
- * until?: string,
15
- * exclude_embeddings?: bool }
16
- *
17
- * Auth: the parent API layer enforces middleware (regra #4 — port 18802 +
18
- * existing auth). This module is unauthenticated by design; never expose it
19
- * directly.
20
- */
21
- import { ExportRequest, ProgressEvent } from "../lib/archive/orchestrator.js";
22
- export interface HttpExportBody {
23
- unencrypted?: boolean;
24
- passphrase?: string;
25
- project?: string;
26
- since?: string;
27
- until?: string;
28
- exclude_embeddings?: boolean;
29
- }
30
- export interface HttpResponse {
31
- status: number;
32
- headers: Record<string, string>;
33
- body: Buffer | string;
34
- }
35
- export interface HttpExportDeps {
36
- dbReader: () => Promise<Omit<ExportRequest, "passphrase" | "unencrypted" | "signal" | "onProgress">>;
37
- signal?: AbortSignal;
38
- onProgress?: (ev: ProgressEvent) => void;
39
- /** Optional max archive size guard (defaults to 5 GiB). */
40
- maxBytes?: number;
41
- }
42
- export declare function handleExport(body: HttpExportBody, deps: HttpExportDeps): Promise<HttpResponse>;
@@ -1,85 +0,0 @@
1
- /**
2
- * T13 — HTTP `POST /api/export` handler (framework-agnostic).
3
- *
4
- * Returns a `{ status, headers, body }` shape so the host server (express,
5
- * fastify, plain http.Server) can adapt without coupling. The actual streaming
6
- * write happens in the caller; we return the archive Buffer plus suggested
7
- * headers (Content-Type, Content-Disposition, Content-Length).
8
- *
9
- * Body schema:
10
- * { unencrypted?: bool,
11
- * passphrase?: string, // accepted ONLY over POST body (TLS-protected)
12
- * project?: string,
13
- * since?: string,
14
- * until?: string,
15
- * exclude_embeddings?: bool }
16
- *
17
- * Auth: the parent API layer enforces middleware (regra #4 — port 18802 +
18
- * existing auth). This module is unauthenticated by design; never expose it
19
- * directly.
20
- */
21
- import { runExport, } from "../lib/archive/orchestrator.js";
22
- const DEFAULT_MAX_BYTES = 5 * 1024 * 1024 * 1024;
23
- export async function handleExport(body, deps) {
24
- // Validate
25
- if (!body.unencrypted &&
26
- (typeof body.passphrase !== "string" || body.passphrase.length === 0)) {
27
- return jsonResponse(400, {
28
- error: "passphrase required when not unencrypted (D41 #2 encrypt-by-default)",
29
- });
30
- }
31
- const corpus = await deps.dbReader();
32
- if (body.exclude_embeddings) {
33
- corpus.embeddings = undefined;
34
- }
35
- let result;
36
- try {
37
- result = await runExport({
38
- ...corpus,
39
- filters: {
40
- project: body.project ?? null,
41
- since: body.since ?? null,
42
- until: body.until ?? null,
43
- },
44
- unencrypted: body.unencrypted === true,
45
- passphrase: body.passphrase,
46
- signal: deps.signal,
47
- onProgress: deps.onProgress,
48
- });
49
- }
50
- catch (err) {
51
- const msg = err.message;
52
- if (/cancel/i.test(msg)) {
53
- return jsonResponse(499, { error: "client closed request" });
54
- }
55
- return jsonResponse(500, { error: msg });
56
- }
57
- const max = deps.maxBytes ?? DEFAULT_MAX_BYTES;
58
- if (result.archive.length > max) {
59
- return jsonResponse(413, {
60
- error: `archive too large: ${result.archive.length} > ${max} bytes`,
61
- hint: "use --project / --since filters or split via multiple exports",
62
- });
63
- }
64
- const date = new Date().toISOString().slice(0, 10);
65
- const fileName = `nox-mem-export-${date}.tgz`;
66
- return {
67
- status: 200,
68
- headers: {
69
- "Content-Type": "application/gzip",
70
- "Content-Disposition": `attachment; filename="${fileName}"`,
71
- "Content-Length": String(result.archive.length),
72
- "X-Archive-Encrypted": String(result.manifest.encryption.enabled),
73
- "X-Archive-Chunks": String(result.manifest.counts.chunks),
74
- "X-Archive-Duration-Ms": String(result.duration_ms),
75
- },
76
- body: result.archive,
77
- };
78
- }
79
- function jsonResponse(status, payload) {
80
- return {
81
- status,
82
- headers: { "Content-Type": "application/json" },
83
- body: JSON.stringify(payload),
84
- };
85
- }
@@ -1,29 +0,0 @@
1
- /**
2
- * src/api/health-confidence-adapter.ts — Wave O T4 (L3 health piece).
3
- *
4
- * Wire-up.ts (#92, line 446) does:
5
- *
6
- * const mod = await tryImport("./health-confidence.js");
7
- * if (!mod?.handleHealthConfidence) writeJson(res, ..., 503);
8
- * const out = await mod.handleHealthConfidence();
9
- *
10
- * staged-L3 ships `computeConfidenceHealth(db, rankingMode?)` — not the
11
- * arg-free `handleHealthConfidence()` the wire-up needs. This adapter wraps
12
- * the upstream function with deps-registry's DB singleton.
13
- *
14
- * Apply step appends to staged-L3's `health-confidence.ts`:
15
- *
16
- * export { handleHealthConfidence } from "./health-confidence-adapter.js";
17
- *
18
- * The adapter returns `{status, body}` per the wire-up contract.
19
- */
20
- interface ConfidenceHealthResponse {
21
- status: number;
22
- body: unknown;
23
- }
24
- /**
25
- * Wire-up-shaped handler. No args — pulls DB from registry; returns 503 when
26
- * the L3 health module or the DB is unavailable.
27
- */
28
- export declare function handleHealthConfidence(): Promise<ConfidenceHealthResponse>;
29
- export {};