nox-mem 3.1.1 → 3.2.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
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/crystallize.js +3 -5
  17. package/dist/db.js +61 -2
  18. package/dist/embed.js +23 -2
  19. package/dist/index.js +1 -22
  20. package/dist/knowledge-graph.js +20 -0
  21. package/dist/lib/answer/__tests__/e2e-gemini.test.js +229 -0
  22. package/dist/lib/answer/__tests__/integration-sqlite.test.js +388 -0
  23. package/dist/lib/answer/__tests__/integration.test.js +347 -0
  24. package/dist/lib/answer/__tests__/prompt.test.js +117 -0
  25. package/dist/lib/answer/__tests__/t5-t10.test.js +501 -0
  26. package/dist/lib/answer/provider.js +29 -4
  27. package/dist/lib/api/__tests__/safe-error-message.test.js +155 -0
  28. package/dist/lib/auth/__tests__/localhost-guard.test.js +144 -0
  29. package/dist/lib/error-sanitizer/__tests__/sanitize.test.js +354 -0
  30. package/dist/lib/events/__tests__/bus.test.js +208 -0
  31. package/dist/lib/ingest-router.js +0 -43
  32. package/dist/lib/op-audit-extension/__tests__/ran-at-guard.test.js +109 -0
  33. package/dist/lib/regex-extract/__tests__/extractor.test.js +197 -0
  34. package/dist/lib/regex-extract/__tests__/frontmatter.test.js +75 -0
  35. package/dist/lib/regex-extract/__tests__/ingest-router-l4.test.js +139 -0
  36. package/dist/lib/regex-extract/__tests__/production-wire.test.js +177 -0
  37. package/dist/lib/regex-extract/__tests__/reconcile.test.js +170 -0
  38. package/dist/lib/regex-extract/__tests__/strip-code.test.js +36 -0
  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/package.json +3 -4
  51. package/dist/api/answer.d.ts +0 -116
  52. package/dist/api/answer.validate-patch.d.ts +0 -72
  53. package/dist/api/brief-diversity.d.ts +0 -64
  54. package/dist/api/brief.d.ts +0 -114
  55. package/dist/api/conflict.d.ts +0 -33
  56. package/dist/api/conflict.js +0 -143
  57. package/dist/api/cors.d.ts +0 -73
  58. package/dist/api/events-stream-limited.d.ts +0 -133
  59. package/dist/api/events-stream-limited.js +0 -217
  60. package/dist/api/events-stream.d.ts +0 -53
  61. package/dist/api/events-stream.js +0 -125
  62. package/dist/api/export.d.ts +0 -42
  63. package/dist/api/export.js +0 -85
  64. package/dist/api/health-confidence-adapter.d.ts +0 -29
  65. package/dist/api/health-confidence-adapter.js +0 -73
  66. package/dist/api/health-confidence.d.ts +0 -36
  67. package/dist/api/health-confidence.js +0 -141
  68. package/dist/api/hooks.d.ts +0 -50
  69. package/dist/api/hooks.js +0 -115
  70. package/dist/api/import.d.ts +0 -38
  71. package/dist/api/import.js +0 -87
  72. package/dist/api/ingest-event.d.ts +0 -65
  73. package/dist/api/mark.d.ts +0 -42
  74. package/dist/api/mark.js +0 -127
  75. package/dist/api/server-deps-a2.d.ts +0 -55
  76. package/dist/api/server-deps-a2.js +0 -138
  77. package/dist/api/server-deps-l2-l3.d.ts +0 -68
  78. package/dist/api/server-deps-l2-l3.js +0 -123
  79. package/dist/api/server-deps-p1.d.ts +0 -84
  80. package/dist/api/server-deps-p2.d.ts +0 -32
  81. package/dist/api/server-deps-p2.js +0 -84
  82. package/dist/api/server-deps-p5.d.ts +0 -66
  83. package/dist/api/server-deps-p5.js +0 -139
  84. package/dist/api/viewer-static.d.ts +0 -30
  85. package/dist/api/viewer-static.js +0 -102
  86. package/dist/api/wire-up.d.ts +0 -54
  87. package/dist/api-impact.d.ts +0 -30
  88. package/dist/api-server.d.ts +0 -2
  89. package/dist/backfill-fts-anchor.d.ts +0 -15
  90. package/dist/backfill-source-type.d.ts +0 -20
  91. package/dist/churn.d.ts +0 -31
  92. package/dist/cli/answer.d.ts +0 -66
  93. package/dist/cli/conflict.d.ts +0 -38
  94. package/dist/cli/conflict.js +0 -282
  95. package/dist/cli/export.d.ts +0 -51
  96. package/dist/cli/export.js +0 -280
  97. package/dist/cli/hooks.d.ts +0 -54
  98. package/dist/cli/hooks.js +0 -133
  99. package/dist/cli/import.d.ts +0 -52
  100. package/dist/cli/import.js +0 -274
  101. package/dist/cli/mark.d.ts +0 -33
  102. package/dist/cli/mark.js +0 -130
  103. package/dist/cli/ocr-batch.d.ts +0 -12
  104. package/dist/cli/ocr-batch.js +0 -411
  105. package/dist/cli/snapshot-main.d.ts +0 -30
  106. package/dist/cli/snapshot-main.js +0 -47
  107. package/dist/cli/viewer.d.ts +0 -35
  108. package/dist/cli/viewer.js +0 -71
  109. package/dist/cli-telemetry.d.ts +0 -36
  110. package/dist/cli-telemetry.js +0 -150
  111. package/dist/compact.d.ts +0 -7
  112. package/dist/consolidate.d.ts +0 -18
  113. package/dist/consolidation.d.ts +0 -32
  114. package/dist/cross-agent-v2.d.ts +0 -45
  115. package/dist/cross-search.d.ts +0 -11
  116. package/dist/crystallize.d.ts +0 -43
  117. package/dist/db.d.ts +0 -11
  118. package/dist/dedup.d.ts +0 -1
  119. package/dist/detect-changes.d.ts +0 -29
  120. package/dist/digest.d.ts +0 -1
  121. package/dist/doctor.d.ts +0 -1
  122. package/dist/embed.d.ts +0 -57
  123. package/dist/evals.d.ts +0 -176
  124. package/dist/evals.js +0 -351
  125. package/dist/generate-user-profile.d.ts +0 -18
  126. package/dist/graphify-ingest.d.ts +0 -18
  127. package/dist/impact.d.ts +0 -39
  128. package/dist/index.d.ts +0 -2
  129. package/dist/ingest-entity.d.ts +0 -44
  130. package/dist/ingest.d.ts +0 -13
  131. package/dist/kg-llm.d.ts +0 -39
  132. package/dist/knowledge-graph.d.ts +0 -72
  133. package/dist/lib/answer/config.d.ts +0 -41
  134. package/dist/lib/answer/index.d.ts +0 -47
  135. package/dist/lib/answer/prompt.d.ts +0 -37
  136. package/dist/lib/answer/provider.d.ts +0 -47
  137. package/dist/lib/answer/retrieval.d.ts +0 -36
  138. package/dist/lib/answer/telemetry.d.ts +0 -99
  139. package/dist/lib/answer/types.d.ts +0 -108
  140. package/dist/lib/api/error-leak-fix.d.ts +0 -54
  141. package/dist/lib/api/safe-error-message.d.ts +0 -70
  142. package/dist/lib/archive/common-passwords.d.ts +0 -37
  143. package/dist/lib/archive/common-passwords.js +0 -753
  144. package/dist/lib/archive/encryption.d.ts +0 -81
  145. package/dist/lib/archive/encryption.js +0 -236
  146. package/dist/lib/archive/enforce-strength.d.ts +0 -54
  147. package/dist/lib/archive/enforce-strength.js +0 -70
  148. package/dist/lib/archive/entropy.d.ts +0 -34
  149. package/dist/lib/archive/entropy.js +0 -180
  150. package/dist/lib/archive/export-locking.d.ts +0 -102
  151. package/dist/lib/archive/export-locking.js +0 -202
  152. package/dist/lib/archive/format.d.ts +0 -20
  153. package/dist/lib/archive/format.js +0 -174
  154. package/dist/lib/archive/index.d.ts +0 -23
  155. package/dist/lib/archive/index.js +0 -17
  156. package/dist/lib/archive/manifest.d.ts +0 -53
  157. package/dist/lib/archive/manifest.js +0 -183
  158. package/dist/lib/archive/migration.d.ts +0 -36
  159. package/dist/lib/archive/migration.js +0 -100
  160. package/dist/lib/archive/migrations/v18_to_v19.d.ts +0 -16
  161. package/dist/lib/archive/migrations/v18_to_v19.js +0 -18
  162. package/dist/lib/archive/orchestrator.d.ts +0 -166
  163. package/dist/lib/archive/orchestrator.js +0 -428
  164. package/dist/lib/archive/serializers/chunks.d.ts +0 -30
  165. package/dist/lib/archive/serializers/chunks.js +0 -113
  166. package/dist/lib/archive/serializers/embeddings.d.ts +0 -36
  167. package/dist/lib/archive/serializers/embeddings.js +0 -115
  168. package/dist/lib/archive/serializers/kg.d.ts +0 -28
  169. package/dist/lib/archive/serializers/kg.js +0 -184
  170. package/dist/lib/archive/serializers/ops_audit.d.ts +0 -21
  171. package/dist/lib/archive/serializers/ops_audit.js +0 -97
  172. package/dist/lib/archive/server-deps.d.ts +0 -131
  173. package/dist/lib/archive/server-deps.js +0 -232
  174. package/dist/lib/archive/strength.d.ts +0 -50
  175. package/dist/lib/archive/strength.js +0 -77
  176. package/dist/lib/archive/types.d.ts +0 -159
  177. package/dist/lib/archive/types.js +0 -45
  178. package/dist/lib/archive/unpack-streaming.d.ts +0 -70
  179. package/dist/lib/archive/unpack-streaming.js +0 -255
  180. package/dist/lib/auth/localhost-guard.d.ts +0 -106
  181. package/dist/lib/confidence/config.d.ts +0 -37
  182. package/dist/lib/confidence/config.js +0 -107
  183. package/dist/lib/confidence/db-shim-singleton.d.ts +0 -20
  184. package/dist/lib/confidence/db-shim-singleton.js +0 -41
  185. package/dist/lib/confidence/db-shim.d.ts +0 -47
  186. package/dist/lib/confidence/db-shim.js +0 -141
  187. package/dist/lib/confidence/mark.d.ts +0 -58
  188. package/dist/lib/confidence/mark.js +0 -168
  189. package/dist/lib/confidence/ranking.d.ts +0 -69
  190. package/dist/lib/confidence/ranking.js +0 -101
  191. package/dist/lib/confidence/search-filter.d.ts +0 -44
  192. package/dist/lib/confidence/search-filter.js +0 -103
  193. package/dist/lib/confidence/types.d.ts +0 -146
  194. package/dist/lib/confidence/types.js +0 -20
  195. package/dist/lib/confidence/write-hooks.d.ts +0 -50
  196. package/dist/lib/confidence/write-hooks.js +0 -159
  197. package/dist/lib/conflict/audit-fk-check.d.ts +0 -72
  198. package/dist/lib/conflict/audit-fk-check.js +0 -131
  199. package/dist/lib/conflict/audit-writer.d.ts +0 -39
  200. package/dist/lib/conflict/audit-writer.js +0 -133
  201. package/dist/lib/conflict/db-singleton.d.ts +0 -28
  202. package/dist/lib/conflict/db-singleton.js +0 -61
  203. package/dist/lib/conflict/db.d.ts +0 -27
  204. package/dist/lib/conflict/db.js +0 -20
  205. package/dist/lib/conflict/detector-direct.d.ts +0 -21
  206. package/dist/lib/conflict/detector-direct.js +0 -105
  207. package/dist/lib/conflict/evidence.d.ts +0 -24
  208. package/dist/lib/conflict/evidence.js +0 -76
  209. package/dist/lib/conflict/index.d.ts +0 -14
  210. package/dist/lib/conflict/index.js +0 -12
  211. package/dist/lib/conflict/scheduler.d.ts +0 -78
  212. package/dist/lib/conflict/scheduler.js +0 -111
  213. package/dist/lib/conflict/shadow.d.ts +0 -75
  214. package/dist/lib/conflict/shadow.js +0 -161
  215. package/dist/lib/conflict/types.d.ts +0 -133
  216. package/dist/lib/conflict/types.js +0 -19
  217. package/dist/lib/cost-cap.d.ts +0 -94
  218. package/dist/lib/deps/deps-registry.d.ts +0 -111
  219. package/dist/lib/error-sanitizer/middleware.d.ts +0 -43
  220. package/dist/lib/error-sanitizer/sanitize.d.ts +0 -78
  221. package/dist/lib/eval-batch.d.ts +0 -34
  222. package/dist/lib/eval-batch.js +0 -103
  223. package/dist/lib/eval-metrics.d.ts +0 -36
  224. package/dist/lib/eval-metrics.js +0 -95
  225. package/dist/lib/eval.d.ts +0 -106
  226. package/dist/lib/eval.js +0 -343
  227. package/dist/lib/events/bus.d.ts +0 -135
  228. package/dist/lib/fts-anchor.d.ts +0 -1
  229. package/dist/lib/hooks/classifier.d.ts +0 -47
  230. package/dist/lib/hooks/classifier.js +0 -129
  231. package/dist/lib/hooks/config.d.ts +0 -49
  232. package/dist/lib/hooks/config.js +0 -106
  233. package/dist/lib/hooks/decorators.d.ts +0 -35
  234. package/dist/lib/hooks/decorators.js +0 -59
  235. package/dist/lib/hooks/pipeline.d.ts +0 -76
  236. package/dist/lib/hooks/pipeline.js +0 -213
  237. package/dist/lib/hooks/privacy-filter-adapter.d.ts +0 -55
  238. package/dist/lib/hooks/privacy-filter-adapter.js +0 -84
  239. package/dist/lib/hooks/rate-limit-constant-time.d.ts +0 -57
  240. package/dist/lib/hooks/rate-limit-constant-time.js +0 -69
  241. package/dist/lib/hooks/rate-limit-dryrun-fix.d.ts +0 -71
  242. package/dist/lib/hooks/rate-limit-dryrun-fix.js +0 -110
  243. package/dist/lib/hooks/rate-limit.d.ts +0 -54
  244. package/dist/lib/hooks/rate-limit.js +0 -122
  245. package/dist/lib/hooks/server-deps.d.ts +0 -61
  246. package/dist/lib/hooks/server-deps.js +0 -92
  247. package/dist/lib/hooks/source-allowlist.d.ts +0 -26
  248. package/dist/lib/hooks/source-allowlist.js +0 -53
  249. package/dist/lib/hooks/types.d.ts +0 -129
  250. package/dist/lib/hooks/types.js +0 -24
  251. package/dist/lib/hooks/worker.d.ts +0 -56
  252. package/dist/lib/hooks/worker.js +0 -150
  253. package/dist/lib/ingest-router.d.ts +0 -25
  254. package/dist/lib/ocr-detector.d.ts +0 -61
  255. package/dist/lib/ocr-detector.js +0 -138
  256. package/dist/lib/ocr-engine-stub.d.ts +0 -48
  257. package/dist/lib/ocr-engine-stub.js +0 -190
  258. package/dist/lib/ocr-engines/google-doc-ai.d.ts +0 -36
  259. package/dist/lib/ocr-engines/google-doc-ai.js +0 -164
  260. package/dist/lib/ocr-jobs.d.ts +0 -67
  261. package/dist/lib/ocr-jobs.js +0 -129
  262. package/dist/lib/op-audit-extension/ran-at-guard.d.ts +0 -86
  263. package/dist/lib/op-audit.d.ts +0 -71
  264. package/dist/lib/privacy-br/detector.d.ts +0 -42
  265. package/dist/lib/privacy-br/detector.js +0 -130
  266. package/dist/lib/privacy-br/index.d.ts +0 -20
  267. package/dist/lib/privacy-br/index.js +0 -20
  268. package/dist/lib/privacy-br/integration.d.ts +0 -71
  269. package/dist/lib/privacy-br/integration.js +0 -74
  270. package/dist/lib/privacy-br/patterns.d.ts +0 -117
  271. package/dist/lib/privacy-br/patterns.js +0 -434
  272. package/dist/lib/privacy-br/redact.d.ts +0 -42
  273. package/dist/lib/privacy-br/redact.js +0 -103
  274. package/dist/lib/privacy-br/types.d.ts +0 -55
  275. package/dist/lib/privacy-br/types.js +0 -25
  276. package/dist/lib/regex-extract/extractor.d.ts +0 -30
  277. package/dist/lib/regex-extract/frontmatter.d.ts +0 -44
  278. package/dist/lib/regex-extract/index.d.ts +0 -14
  279. package/dist/lib/regex-extract/ingest-router-l4.d.ts +0 -76
  280. package/dist/lib/regex-extract/patterns.d.ts +0 -61
  281. package/dist/lib/regex-extract/production-wire.d.ts +0 -128
  282. package/dist/lib/regex-extract/reconcile.d.ts +0 -162
  283. package/dist/lib/regex-extract/strip-code.d.ts +0 -24
  284. package/dist/lib/regex-extract/types.d.ts +0 -48
  285. package/dist/lib/reranker.d.ts +0 -80
  286. package/dist/lib/shadow-tracker.d.ts +0 -191
  287. package/dist/lib/shadow-tracker.js +0 -384
  288. package/dist/lib/spo-injection.d.ts +0 -52
  289. package/dist/lib/telemetry-collector.d.ts +0 -158
  290. package/dist/lib/telemetry-collector.js +0 -249
  291. package/dist/lib/temporal-detector.d.ts +0 -27
  292. package/dist/lib/viewer/auth.d.ts +0 -37
  293. package/dist/lib/viewer/auth.js +0 -70
  294. package/dist/lib/viewer/backpressure.d.ts +0 -59
  295. package/dist/lib/viewer/backpressure.js +0 -100
  296. package/dist/lib/viewer/broadcast-singleton.d.ts +0 -34
  297. package/dist/lib/viewer/broadcast-singleton.js +0 -49
  298. package/dist/lib/viewer/broadcast.d.ts +0 -66
  299. package/dist/lib/viewer/broadcast.js +0 -96
  300. package/dist/lib/viewer/event-types.d.ts +0 -132
  301. package/dist/lib/viewer/event-types.js +0 -74
  302. package/dist/lib/viewer/instrumentation.d.ts +0 -106
  303. package/dist/lib/viewer/instrumentation.js +0 -224
  304. package/dist/lib/viewer/migration.d.ts +0 -23
  305. package/dist/lib/viewer/migration.js +0 -56
  306. package/dist/lib/viewer/redaction.d.ts +0 -44
  307. package/dist/lib/viewer/redaction.js +0 -139
  308. package/dist/lib/viewer/session.d.ts +0 -51
  309. package/dist/lib/viewer/session.js +0 -87
  310. package/dist/mcp/tools/answer.d.ts +0 -94
  311. package/dist/mcp/tools/archive.d.ts +0 -152
  312. package/dist/mcp/tools/archive.js +0 -170
  313. package/dist/mcp/tools/conflict.d.ts +0 -44
  314. package/dist/mcp/tools/conflict.js +0 -130
  315. package/dist/mcp/tools/hooks.d.ts +0 -29
  316. package/dist/mcp/tools/hooks.js +0 -78
  317. package/dist/mcp/tools/mark.d.ts +0 -38
  318. package/dist/mcp/tools/mark.js +0 -82
  319. package/dist/mcp/tools/viewer.d.ts +0 -58
  320. package/dist/mcp/tools/viewer.js +0 -64
  321. package/dist/mcp-server.d.ts +0 -2
  322. package/dist/metrics.d.ts +0 -3
  323. package/dist/noise-filter.d.ts +0 -18
  324. package/dist/notion-sync.d.ts +0 -7
  325. package/dist/notion-sync.js +0 -97
  326. package/dist/observability/adapters/a3-adapter.d.ts +0 -63
  327. package/dist/observability/adapters/a3-adapter.js +0 -83
  328. package/dist/observability/adapters/p1-adapter.d.ts +0 -49
  329. package/dist/observability/adapters/p1-adapter.js +0 -63
  330. package/dist/observability/adapters/p5-adapter.d.ts +0 -36
  331. package/dist/observability/adapters/p5-adapter.js +0 -71
  332. package/dist/observability/cardinality.d.ts +0 -61
  333. package/dist/observability/cardinality.js +0 -300
  334. package/dist/observability/collectors/db-stats.collector.d.ts +0 -9
  335. package/dist/observability/collectors/db-stats.collector.js +0 -88
  336. package/dist/observability/collectors/eventbus.collector.d.ts +0 -6
  337. package/dist/observability/collectors/eventbus.collector.js +0 -50
  338. package/dist/observability/collectors/process.collector.d.ts +0 -7
  339. package/dist/observability/collectors/process.collector.js +0 -93
  340. package/dist/observability/collectors/provider-telemetry.collector.d.ts +0 -11
  341. package/dist/observability/collectors/provider-telemetry.collector.js +0 -112
  342. package/dist/observability/collectors/search-telemetry.collector.d.ts +0 -12
  343. package/dist/observability/collectors/search-telemetry.collector.js +0 -76
  344. package/dist/observability/exporter.d.ts +0 -30
  345. package/dist/observability/exporter.js +0 -182
  346. package/dist/observability/index.d.ts +0 -22
  347. package/dist/observability/index.js +0 -21
  348. package/dist/observability/metrics.d.ts +0 -53
  349. package/dist/observability/metrics.js +0 -213
  350. package/dist/observability/privacy-guard.d.ts +0 -32
  351. package/dist/observability/privacy-guard.js +0 -116
  352. package/dist/observability/record.d.ts +0 -83
  353. package/dist/observability/record.js +0 -217
  354. package/dist/observability/registry.d.ts +0 -60
  355. package/dist/observability/registry.js +0 -93
  356. package/dist/observability/types.d.ts +0 -115
  357. package/dist/observability/types.js +0 -235
  358. package/dist/observability.d.ts +0 -131
  359. package/dist/plugins/nox-hooks/index.d.ts +0 -61
  360. package/dist/plugins/nox-hooks/index.js +0 -99
  361. package/dist/primer.d.ts +0 -1
  362. package/dist/privacy/filter.d.ts +0 -27
  363. package/dist/privacy/patterns.d.ts +0 -29
  364. package/dist/privacy/tag-parser.d.ts +0 -24
  365. package/dist/project-context-gen.d.ts +0 -10
  366. package/dist/providers/embedding/gemini.d.ts +0 -73
  367. package/dist/providers/embedding/openai.d.ts +0 -76
  368. package/dist/providers/embedding/types.d.ts +0 -39
  369. package/dist/providers/embedding/voyage.d.ts +0 -36
  370. package/dist/providers/index.d.ts +0 -116
  371. package/dist/providers/llm/anthropic.d.ts +0 -29
  372. package/dist/providers/llm/chain.d.ts +0 -99
  373. package/dist/providers/llm/gemini.d.ts +0 -48
  374. package/dist/providers/llm/openai.d.ts +0 -64
  375. package/dist/providers/llm/types.d.ts +0 -47
  376. package/dist/providers/telemetry.d.ts +0 -87
  377. package/dist/providers/types.d.ts +0 -42
  378. package/dist/query-entity-count.d.ts +0 -54
  379. package/dist/reflect.d.ts +0 -26
  380. package/dist/reindex-errors.d.ts +0 -7
  381. package/dist/reindex.d.ts +0 -16
  382. package/dist/retention.d.ts +0 -40
  383. package/dist/salience.d.ts +0 -85
  384. package/dist/scripts/migrate-v17-ops-audit.d.ts +0 -17
  385. package/dist/search-dedup.d.ts +0 -44
  386. package/dist/search-expansion.d.ts +0 -20
  387. package/dist/search.d.ts +0 -62
  388. package/dist/seh-detector.d.ts +0 -31
  389. package/dist/self-improve.d.ts +0 -1
  390. package/dist/session-distill.d.ts +0 -29
  391. package/dist/session-update.d.ts +0 -1
  392. package/dist/shared-memory.d.ts +0 -24
  393. package/dist/stats.d.ts +0 -1
  394. package/dist/temporal-retrieval.d.ts +0 -132
  395. package/dist/tier-manager.d.ts +0 -69
  396. package/dist/vectorize.d.ts +0 -16
  397. package/dist/version.d.ts +0 -1
  398. package/dist/watch.d.ts +0 -8
package/dist/api/mark.js DELETED
@@ -1,127 +0,0 @@
1
- /**
2
- * src/api/mark.ts — HTTP routes for L3 mark workflow.
3
- *
4
- * Routes:
5
- * POST /api/chunk/:id/mark body { kind: "canonical"|"refuted"|"stale", notes?: string }
6
- * POST /api/chunk/:id/supersede body { by_chunk_id: number, notes?: string, reason?: string }
7
- *
8
- * Returns 200 + JSON on success, 400 on bad request, 404 on missing chunk,
9
- * 500 on unexpected.
10
- *
11
- * Framework-agnostic: exposes request/response handlers that take a minimal
12
- * Request shape. Production caller (Express/Fastify/native http) wires them
13
- * via `handleMarkRequest()` and `handleSupersedeRequest()`.
14
- */
15
- import { markChunk, supersedeChunk, } from "../lib/confidence/mark.js";
16
- import { resolveConfig } from "../lib/confidence/config.js";
17
- function validateKind(raw) {
18
- return raw === "canonical" || raw === "refuted" || raw === "stale";
19
- }
20
- function validateReason(raw) {
21
- return (raw === "auto_supersede_temporal" ||
22
- raw === "manual_resolution" ||
23
- raw === "stale_link_reconciliation" ||
24
- raw === "dismiss");
25
- }
26
- function parseChunkId(idStr) {
27
- const id = parseInt(idStr, 10);
28
- if (!Number.isFinite(id) || id <= 0)
29
- return null;
30
- return id;
31
- }
32
- /**
33
- * handleMarkRequest(db, idStr, body) → ApiResponse<MarkResult>
34
- */
35
- export function handleMarkRequest(db, idStr, body) {
36
- const chunk_id = parseChunkId(idStr);
37
- if (chunk_id === null) {
38
- return {
39
- status: 400,
40
- body: { ok: false, error: `invalid chunk id: ${idStr}`, code: "bad_id" },
41
- };
42
- }
43
- if (!body || typeof body !== "object") {
44
- return {
45
- status: 400,
46
- body: { ok: false, error: "missing JSON body", code: "bad_body" },
47
- };
48
- }
49
- if (!validateKind(body.kind)) {
50
- return {
51
- status: 400,
52
- body: {
53
- ok: false,
54
- error: `invalid kind: ${String(body.kind)} — expected canonical|refuted|stale`,
55
- code: "bad_kind",
56
- },
57
- };
58
- }
59
- try {
60
- const result = markChunk({
61
- db,
62
- chunk_id,
63
- kind: body.kind,
64
- notes: body.notes,
65
- cfg: resolveConfig(),
66
- });
67
- return { status: 200, body: result };
68
- }
69
- catch (err) {
70
- const msg = err instanceof Error ? err.message : String(err);
71
- const status = /not found/i.test(msg) ? 404 : 500;
72
- return {
73
- status,
74
- body: { ok: false, error: msg, code: status === 404 ? "not_found" : "runtime" },
75
- };
76
- }
77
- }
78
- /**
79
- * handleSupersedeRequest(db, idStr, body) → ApiResponse<MarkResult>
80
- */
81
- export function handleSupersedeRequest(db, idStr, body) {
82
- const chunk_id = parseChunkId(idStr);
83
- if (chunk_id === null) {
84
- return {
85
- status: 400,
86
- body: { ok: false, error: `invalid chunk id: ${idStr}`, code: "bad_id" },
87
- };
88
- }
89
- if (!body || typeof body !== "object") {
90
- return {
91
- status: 400,
92
- body: { ok: false, error: "missing JSON body", code: "bad_body" },
93
- };
94
- }
95
- const by_chunk_id = typeof body.by_chunk_id === "number" ? body.by_chunk_id : NaN;
96
- if (!Number.isFinite(by_chunk_id) || by_chunk_id <= 0) {
97
- return {
98
- status: 400,
99
- body: {
100
- ok: false,
101
- error: `invalid by_chunk_id: ${String(body.by_chunk_id)}`,
102
- code: "bad_by_id",
103
- },
104
- };
105
- }
106
- const reason = validateReason(body.reason)
107
- ? body.reason
108
- : "manual_resolution";
109
- try {
110
- const result = supersedeChunk({
111
- db,
112
- chunk_id,
113
- by_chunk_id,
114
- notes: body.notes,
115
- reason,
116
- });
117
- return { status: 200, body: result };
118
- }
119
- catch (err) {
120
- const msg = err instanceof Error ? err.message : String(err);
121
- const status = /missing|not found/i.test(msg) ? 404 : 500;
122
- return {
123
- status,
124
- body: { ok: false, error: msg, code: status === 404 ? "not_found" : "runtime" },
125
- };
126
- }
127
- }
@@ -1,55 +0,0 @@
1
- /**
2
- * src/api/server-deps-a2.ts — Wave O T2: A2 (export/import) wire-up adapter.
3
- *
4
- * Companion to `src/lib/archive/server-deps.ts`. This module re-exports the
5
- * deps builders under the `/api/*` path used by tests + provides convenience
6
- * helpers for streaming + multipart parsing that the wire-up.ts router
7
- * intentionally does NOT couple to (keeping wire-up framework-agnostic).
8
- *
9
- * Two streaming concerns are handled here:
10
- *
11
- * 1. Export response: when the archive size > NOX_EXPORT_STREAM_THRESHOLD
12
- * (default 16 MiB), we set `Transfer-Encoding: chunked` and write the
13
- * buffer in 1 MiB slices, yielding to the event loop between writes so
14
- * we don't starve other requests (regra de ouro #4 — Node single-thread).
15
- *
16
- * 2. Import request: the wire-up.ts contract is JSON body with
17
- * `archive_b64`. We also accept `multipart/form-data` when
18
- * `Content-Type` starts with `multipart/`, parsing the first file part
19
- * out as the binary archive (no @types/formidable dep — minimal parser).
20
- * This lets curl users `--data-binary @file.tgz` upload directly.
21
- *
22
- * Singleton DB resolution stays in deps-registry. This module is pure
23
- * stream/parsing glue.
24
- */
25
- import type { ServerResponse, IncomingMessage } from "node:http";
26
- export { buildExportDeps, buildImportDeps, type HttpExportDeps, type HttpImportDeps, } from "../lib/archive/server-deps.js";
27
- /**
28
- * Write a Buffer back to the response. Small payloads get a single `end()`;
29
- * large payloads stream via `Transfer-Encoding: chunked` to avoid blocking
30
- * the event loop.
31
- *
32
- * Returns a promise that resolves when the response is fully drained.
33
- */
34
- export declare function writeExportResponse(res: ServerResponse, body: Buffer, baseHeaders: Record<string, string>, threshold?: number): Promise<void>;
35
- export interface MultipartFile {
36
- name: string;
37
- filename: string;
38
- contentType: string;
39
- content: Buffer;
40
- }
41
- /**
42
- * Parse a multipart/form-data body. Returns the first file part found.
43
- * This is a minimal RFC 7578 implementation — no dependency on `busboy` /
44
- * `formidable`. For payloads <64 MiB (wire-up.ts cap) this is plenty.
45
- *
46
- * Returns `null` when the content-type isn't multipart or when no file part
47
- * is present. Throws on malformed boundary structure.
48
- */
49
- export declare function parseMultipartFirstFile(rawBody: Buffer, contentType: string): MultipartFile | null;
50
- /**
51
- * Collect the request body as a Buffer (binary-safe). Wire-up's `readBody()`
52
- * decodes to UTF-8 which mangles archives. Adapter callers must use this
53
- * helper when the route can receive multipart/binary payloads.
54
- */
55
- export declare function readRequestBodyBuffer(req: IncomingMessage, limit?: number): Promise<Buffer>;
@@ -1,138 +0,0 @@
1
- /**
2
- * src/api/server-deps-a2.ts — Wave O T2: A2 (export/import) wire-up adapter.
3
- *
4
- * Companion to `src/lib/archive/server-deps.ts`. This module re-exports the
5
- * deps builders under the `/api/*` path used by tests + provides convenience
6
- * helpers for streaming + multipart parsing that the wire-up.ts router
7
- * intentionally does NOT couple to (keeping wire-up framework-agnostic).
8
- *
9
- * Two streaming concerns are handled here:
10
- *
11
- * 1. Export response: when the archive size > NOX_EXPORT_STREAM_THRESHOLD
12
- * (default 16 MiB), we set `Transfer-Encoding: chunked` and write the
13
- * buffer in 1 MiB slices, yielding to the event loop between writes so
14
- * we don't starve other requests (regra de ouro #4 — Node single-thread).
15
- *
16
- * 2. Import request: the wire-up.ts contract is JSON body with
17
- * `archive_b64`. We also accept `multipart/form-data` when
18
- * `Content-Type` starts with `multipart/`, parsing the first file part
19
- * out as the binary archive (no @types/formidable dep — minimal parser).
20
- * This lets curl users `--data-binary @file.tgz` upload directly.
21
- *
22
- * Singleton DB resolution stays in deps-registry. This module is pure
23
- * stream/parsing glue.
24
- */
25
- export { buildExportDeps, buildImportDeps, } from "../lib/archive/server-deps.js";
26
- // ─── Streaming export response ───────────────────────────────────────────────
27
- const DEFAULT_STREAM_THRESHOLD = 16 * 1024 * 1024; // 16 MiB
28
- const CHUNK_SIZE = 1 * 1024 * 1024; // 1 MiB slices
29
- /**
30
- * Write a Buffer back to the response. Small payloads get a single `end()`;
31
- * large payloads stream via `Transfer-Encoding: chunked` to avoid blocking
32
- * the event loop.
33
- *
34
- * Returns a promise that resolves when the response is fully drained.
35
- */
36
- export async function writeExportResponse(res, body, baseHeaders, threshold = DEFAULT_STREAM_THRESHOLD) {
37
- if (body.length <= threshold) {
38
- res.writeHead(200, baseHeaders);
39
- res.end(body);
40
- return;
41
- }
42
- // Strip Content-Length (chunked encoding requires it absent).
43
- const { ["Content-Length"]: _drop, ...rest } = baseHeaders;
44
- const headers = { ...rest, "Transfer-Encoding": "chunked" };
45
- res.writeHead(200, headers);
46
- for (let off = 0; off < body.length; off += CHUNK_SIZE) {
47
- const slice = body.subarray(off, Math.min(off + CHUNK_SIZE, body.length));
48
- const ok = res.write(slice);
49
- if (!ok) {
50
- await new Promise((r) => res.once("drain", r));
51
- }
52
- // Yield to the event loop so other requests aren't starved.
53
- await new Promise((r) => setImmediate(r));
54
- }
55
- res.end();
56
- }
57
- /**
58
- * Parse a multipart/form-data body. Returns the first file part found.
59
- * This is a minimal RFC 7578 implementation — no dependency on `busboy` /
60
- * `formidable`. For payloads <64 MiB (wire-up.ts cap) this is plenty.
61
- *
62
- * Returns `null` when the content-type isn't multipart or when no file part
63
- * is present. Throws on malformed boundary structure.
64
- */
65
- export function parseMultipartFirstFile(rawBody, contentType) {
66
- if (!/^multipart\/form-data/i.test(contentType))
67
- return null;
68
- const m = /boundary=("?)([^";\s]+)\1/.exec(contentType);
69
- if (!m)
70
- throw new Error("missing boundary in multipart Content-Type");
71
- const boundary = `--${m[2]}`;
72
- const boundaryBuf = Buffer.from(boundary);
73
- const closeBuf = Buffer.from(`${boundary}--`);
74
- let off = 0;
75
- while (off < rawBody.length) {
76
- const start = rawBody.indexOf(boundaryBuf, off);
77
- if (start < 0)
78
- return null;
79
- // Move past boundary + CRLF
80
- let cursor = start + boundaryBuf.length;
81
- if (rawBody[cursor] === 0x2d /* '-' */ &&
82
- rawBody[cursor + 1] === 0x2d /* '-' */) {
83
- return null; // final boundary
84
- }
85
- if (rawBody[cursor] === 0x0d /* CR */)
86
- cursor += 2;
87
- // Read part headers until \r\n\r\n
88
- const headerEnd = rawBody.indexOf(Buffer.from("\r\n\r\n"), cursor);
89
- if (headerEnd < 0)
90
- return null;
91
- const headerText = rawBody.slice(cursor, headerEnd).toString("utf-8");
92
- const bodyStart = headerEnd + 4;
93
- const nextBoundary = rawBody.indexOf(boundaryBuf, bodyStart);
94
- if (nextBoundary < 0)
95
- return null;
96
- // Strip the trailing CRLF before the next boundary marker.
97
- const bodyEnd = nextBoundary - 2;
98
- const partBody = rawBody.subarray(bodyStart, bodyEnd);
99
- // Inspect headers for filename + name.
100
- const dispMatch = /Content-Disposition:\s*form-data;\s*name="([^"]+)"(?:;\s*filename="([^"]*)")?/i.exec(headerText);
101
- const typeMatch = /Content-Type:\s*([^\r\n]+)/i.exec(headerText);
102
- if (dispMatch && dispMatch[2]) {
103
- return {
104
- name: dispMatch[1] ?? "",
105
- filename: dispMatch[2] ?? "",
106
- contentType: typeMatch?.[1]?.trim() ?? "application/octet-stream",
107
- content: Buffer.from(partBody),
108
- };
109
- }
110
- off = nextBoundary;
111
- if (rawBody.indexOf(closeBuf, off) === off)
112
- return null;
113
- }
114
- return null;
115
- }
116
- // ─── Body collector (Buffer-typed, replaces wire-up's string-mode reader) ────
117
- /**
118
- * Collect the request body as a Buffer (binary-safe). Wire-up's `readBody()`
119
- * decodes to UTF-8 which mangles archives. Adapter callers must use this
120
- * helper when the route can receive multipart/binary payloads.
121
- */
122
- export function readRequestBodyBuffer(req, limit = 64 * 1024 * 1024) {
123
- return new Promise((resolve, reject) => {
124
- const chunks = [];
125
- let size = 0;
126
- req.on("data", (chunk) => {
127
- size += chunk.length;
128
- if (size > limit) {
129
- reject(new Error("Payload too large"));
130
- req.destroy();
131
- return;
132
- }
133
- chunks.push(chunk);
134
- });
135
- req.on("end", () => resolve(Buffer.concat(chunks)));
136
- req.on("error", reject);
137
- });
138
- }
@@ -1,68 +0,0 @@
1
- /**
2
- * src/api/server-deps-l2-l3.ts — Wave O T4: L2 + L3 combined runtime adapter.
3
- *
4
- * Closes the 503 gap for:
5
- *
6
- * L2: GET /api/conflict
7
- * L2: GET /api/conflict/:id
8
- * L2: POST /api/conflict/:id/resolve
9
- * L3: POST /api/chunk/:id/mark
10
- * L3: POST /api/chunk/:id/supersede
11
- * L3: GET /api/health/confidence
12
- *
13
- * Wire-up.ts already lazy-imports each pillar separately:
14
- *
15
- * const dbMod = await tryImport("../lib/conflict/db.js");
16
- * const shimMod = await tryImport("../lib/confidence/db-shim.js");
17
- * const healthMod = await tryImport("./health-confidence.js");
18
- *
19
- * The work in this adapter:
20
- * - Re-export the singletons (`getConflictDb`, `getConfidenceDb`,
21
- * `handleHealthConfidence`) under a single import path so callers /
22
- * deploy scripts can validate "L2+L3 deps present" with one require.
23
- * - Validate that `conflict_audit` + `chunks.confidence`/`chunks.provenance_kind`
24
- * columns exist before exposing the DB. When schema v18/v19 hasn't
25
- * migrated, return `null` so wire-up surfaces 503 not_implemented.
26
- *
27
- * The two pillars share `nox-mem.db` (singleton from deps-registry) — there
28
- * is exactly ONE DB connection across L2 + L3.
29
- */
30
- export { getConflictDb, ensureConflictDb, resetConflictDbForTests, __setConflictDbForTests, } from "../lib/conflict/db-singleton.js";
31
- export { getConfidenceDb, ensureConfidenceDb, resetConfidenceDbForTests, __setConfidenceDbForTests, } from "../lib/confidence/db-shim-singleton.js";
32
- export { handleHealthConfidence } from "./health-confidence-adapter.js";
33
- /**
34
- * Await this during API server boot (before the first request) to pre-warm the
35
- * L2 singleton. Mirrors the `buildP1Deps()` pattern used by /api/answer.
36
- *
37
- * What it does:
38
- * 1. Opens the better-sqlite3 connection via deps-registry (shared handle).
39
- * 2. Runs a schema readiness probe — warns to console if conflict_audit is
40
- * missing (migration v18 hasn't run) so the operator sees it in logs.
41
- * 3. Returns { db, l2Ready } so api-server.ts can decide whether to mount
42
- * the /api/conflict routes or skip them with a startup log line.
43
- *
44
- * If the boot call is skipped, getConflictDb() returns null on the first
45
- * synchronous call (warmup() is async, fires but hasn't settled yet) and
46
- * wire-up emits 503 not_implemented. Calling buildConflictDeps() once at
47
- * boot ensures the singleton is ready before any request arrives.
48
- */
49
- export declare function buildConflictDeps(): Promise<{
50
- db: unknown | null;
51
- l2Ready: boolean;
52
- }>;
53
- export interface SchemaReadiness {
54
- l2_ready: boolean;
55
- l3_ready: boolean;
56
- details: {
57
- has_conflict_audit: boolean;
58
- has_confidence_col: boolean;
59
- has_provenance_col: boolean;
60
- has_superseded_by_col: boolean;
61
- schema_version: number;
62
- };
63
- }
64
- /**
65
- * Check whether L2 + L3 tables/columns are present in the live DB.
66
- * Used by `/api/health` extension + deploy validation.
67
- */
68
- export declare function probeSchemaReadiness(): Promise<SchemaReadiness>;
@@ -1,123 +0,0 @@
1
- /**
2
- * src/api/server-deps-l2-l3.ts — Wave O T4: L2 + L3 combined runtime adapter.
3
- *
4
- * Closes the 503 gap for:
5
- *
6
- * L2: GET /api/conflict
7
- * L2: GET /api/conflict/:id
8
- * L2: POST /api/conflict/:id/resolve
9
- * L3: POST /api/chunk/:id/mark
10
- * L3: POST /api/chunk/:id/supersede
11
- * L3: GET /api/health/confidence
12
- *
13
- * Wire-up.ts already lazy-imports each pillar separately:
14
- *
15
- * const dbMod = await tryImport("../lib/conflict/db.js");
16
- * const shimMod = await tryImport("../lib/confidence/db-shim.js");
17
- * const healthMod = await tryImport("./health-confidence.js");
18
- *
19
- * The work in this adapter:
20
- * - Re-export the singletons (`getConflictDb`, `getConfidenceDb`,
21
- * `handleHealthConfidence`) under a single import path so callers /
22
- * deploy scripts can validate "L2+L3 deps present" with one require.
23
- * - Validate that `conflict_audit` + `chunks.confidence`/`chunks.provenance_kind`
24
- * columns exist before exposing the DB. When schema v18/v19 hasn't
25
- * migrated, return `null` so wire-up surfaces 503 not_implemented.
26
- *
27
- * The two pillars share `nox-mem.db` (singleton from deps-registry) — there
28
- * is exactly ONE DB connection across L2 + L3.
29
- */
30
- import { getDb } from "../lib/deps/deps-registry.js";
31
- export { getConflictDb, ensureConflictDb, resetConflictDbForTests, __setConflictDbForTests, } from "../lib/conflict/db-singleton.js";
32
- export { getConfidenceDb, ensureConfidenceDb, resetConfidenceDbForTests, __setConfidenceDbForTests, } from "../lib/confidence/db-shim-singleton.js";
33
- export { handleHealthConfidence } from "./health-confidence-adapter.js";
34
- // ─── Boot-time warm-up ────────────────────────────────────────────────────────
35
- /**
36
- * Await this during API server boot (before the first request) to pre-warm the
37
- * L2 singleton. Mirrors the `buildP1Deps()` pattern used by /api/answer.
38
- *
39
- * What it does:
40
- * 1. Opens the better-sqlite3 connection via deps-registry (shared handle).
41
- * 2. Runs a schema readiness probe — warns to console if conflict_audit is
42
- * missing (migration v18 hasn't run) so the operator sees it in logs.
43
- * 3. Returns { db, l2Ready } so api-server.ts can decide whether to mount
44
- * the /api/conflict routes or skip them with a startup log line.
45
- *
46
- * If the boot call is skipped, getConflictDb() returns null on the first
47
- * synchronous call (warmup() is async, fires but hasn't settled yet) and
48
- * wire-up emits 503 not_implemented. Calling buildConflictDeps() once at
49
- * boot ensures the singleton is ready before any request arrives.
50
- */
51
- export async function buildConflictDeps() {
52
- const { ensureConflictDb } = await import("../lib/conflict/db-singleton.js");
53
- const db = await ensureConflictDb();
54
- if (!db) {
55
- return { db: null, l2Ready: false };
56
- }
57
- const readiness = await probeSchemaReadiness();
58
- if (!readiness.l2_ready) {
59
- console.warn("[nox-mem] /api/conflict: conflict_audit table not found " +
60
- "(schema v18 migration pending). Endpoints will return 503 until migrated.");
61
- }
62
- return { db, l2Ready: readiness.l2_ready };
63
- }
64
- /**
65
- * Check whether L2 + L3 tables/columns are present in the live DB.
66
- * Used by `/api/health` extension + deploy validation.
67
- */
68
- export async function probeSchemaReadiness() {
69
- const db = await getDb();
70
- if (!db) {
71
- return {
72
- l2_ready: false,
73
- l3_ready: false,
74
- details: {
75
- has_conflict_audit: false,
76
- has_confidence_col: false,
77
- has_provenance_col: false,
78
- has_superseded_by_col: false,
79
- schema_version: 0,
80
- },
81
- };
82
- }
83
- let conflictAudit = false;
84
- try {
85
- const row = db
86
- .prepare("SELECT name FROM sqlite_master WHERE type='table' AND name='conflict_audit'")
87
- .get();
88
- conflictAudit = !!row;
89
- }
90
- catch {
91
- /* ignore */
92
- }
93
- let chunkCols = [];
94
- try {
95
- chunkCols = db.prepare("PRAGMA table_info(chunks)").all();
96
- }
97
- catch {
98
- /* ignore */
99
- }
100
- const hasConf = chunkCols.some((c) => c.name === "confidence");
101
- const hasProv = chunkCols.some((c) => c.name === "provenance_kind");
102
- const hasSup = chunkCols.some((c) => c.name === "superseded_by");
103
- let schemaVer = 0;
104
- try {
105
- const r = db.prepare("PRAGMA user_version").get();
106
- if (r && typeof r.user_version === "number")
107
- schemaVer = r.user_version;
108
- }
109
- catch {
110
- /* ignore */
111
- }
112
- return {
113
- l2_ready: conflictAudit,
114
- l3_ready: hasConf && hasProv && hasSup,
115
- details: {
116
- has_conflict_audit: conflictAudit,
117
- has_confidence_col: hasConf,
118
- has_provenance_col: hasProv,
119
- has_superseded_by_col: hasSup,
120
- schema_version: schemaVer,
121
- },
122
- };
123
- }
@@ -1,84 +0,0 @@
1
- /**
2
- * src/api/server-deps-p1.ts — Wave O T1: P1 (answer) runtime adapter.
3
- *
4
- * Closes the 503 gap for `POST /api/answer`. The staged-P1 handler
5
- * (`src/api/answer.ts::handleAnswerRequest`) is framework-agnostic but expects
6
- * a `TelemetryStore` injected via `args.telemetryStore`. Without that
7
- * injection, telemetry rows are silently dropped — and the wire-up.ts
8
- * currently passes only `{body, headers}`.
9
- *
10
- * This adapter exposes `buildAnswerHandler()` that returns a thin closure
11
- * the wire-up can call as a drop-in replacement: same input shape, but
12
- * pre-configured with:
13
- *
14
- * - A live `TelemetryStore` backed by better-sqlite3 (writes to
15
- * `answer_telemetry` table, schema v11).
16
- * - A `sessionId` derived from `X-Session-Id` header (when present).
17
- * - The real `answer()` pipeline from staged-P1.
18
- *
19
- * Why this module is a separate file from `wire-up.ts`:
20
- * - Keeps wire-up.ts framework-only (route table). Adapter knows about DB.
21
- * - Singleton DB acquisition happens via `deps-registry.ts` — one connection
22
- * shared across all five adapters (regra de ouro #2).
23
- * - `__setHandlerForTests()` lets unit tests stub the inner pipeline so
24
- * they don't need an actual Gemini key.
25
- *
26
- * Apply step (production): rsync this file + deps-registry.ts to
27
- * ${NM}/src/api/server-deps-p1.ts and rebuild — the wire-up's
28
- * `await import("./answer.js")` already finds the existing `answer.ts`;
29
- * the only change is that `answer.ts` (staged-P1) gets re-exported with
30
- * the adapter's wrapper on top, so the wire-up doesn't need patching.
31
- *
32
- * NOTE: this module does NOT modify wire-up.ts. The wire-up imports
33
- * `./answer.js` directly; our adapter sits in front and the answer.js shim
34
- * (also in this PR) chains here. See `./answer-bridge.ts`.
35
- */
36
- import type { IncomingMessage } from "node:http";
37
- export interface AnswerArgs {
38
- body: unknown;
39
- headers?: Record<string, string | string[] | undefined>;
40
- /** Set by upstream auth middleware; passed through to telemetry. */
41
- sessionId?: string | null;
42
- }
43
- export interface AnswerOutput {
44
- status: number;
45
- headers: Record<string, string>;
46
- body: unknown;
47
- }
48
- interface SchemaTelemetryRow {
49
- question_hash: string;
50
- session_id: string | null;
51
- timestamp_ms: number;
52
- provider: string;
53
- model: string;
54
- retrieval_count: number;
55
- citation_count: number;
56
- tokens_in: number | null;
57
- tokens_out: number | null;
58
- latency_ms: number;
59
- fallback_used: 0 | 1;
60
- failed_reason: string | null;
61
- cost_estimate_usd: number;
62
- }
63
- interface TelemetryStore {
64
- insert(row: SchemaTelemetryRow): void;
65
- }
66
- /**
67
- * Bridge `wire-up.ts`'s call signature `(req, body)` to the staged-P1
68
- * `handleAnswerRequest({body, headers, telemetryStore, sessionId})`.
69
- *
70
- * Returns the same `{status, headers, body}` shape wire-up.ts already writes
71
- * via `writeJson(res, out.body, out.status, out.headers)`.
72
- */
73
- export declare function buildAnswerDeps(args: AnswerArgs): Promise<{
74
- telemetryStore: TelemetryStore;
75
- sessionId: string | null;
76
- }>;
77
- /**
78
- * Public adapter — used by `./answer.js` bridge (also in this PR) and tests.
79
- * Lazy-imports the P1 pipeline. Falls back to 503 on missing handler.
80
- */
81
- export declare function handleAnswerWithDeps(args: AnswerArgs): Promise<AnswerOutput>;
82
- /** Helper for the wire-up integration — extracts headers off IncomingMessage. */
83
- export declare function headersFromReq(req: IncomingMessage): Record<string, string | string[] | undefined>;
84
- export {};
@@ -1,32 +0,0 @@
1
- /**
2
- * src/api/server-deps-p2.ts — Wave O T5: P2 (hooks) wire-up adapter.
3
- *
4
- * Companion to `src/lib/hooks/server-deps.ts`. This module is the public
5
- * entry the api/ layer + tests import from. It re-exports `buildHooksDeps`
6
- * and adds two convenience helpers:
7
- *
8
- * - `getRecentMetadataOnly()` — direct DB query for the recent rows the
9
- * wire-up + dashboard surface. Sanitization is identical to the inline
10
- * code in staged-P2's `handleHooksRequest` (drops payload_json).
11
- *
12
- * - `dryRunHook(text, role, source)` — runs the 5-layer pipeline with
13
- * dryRun=true and returns the trace. Mirrors the POST /api/hooks/dryrun
14
- * handler but callable in-process for tests/dashboards.
15
- */
16
- export { buildHooksDeps, __setQueueProbeForTests, __resetHooksDepsForTests, type HooksApiDeps, type HookRecentRow, type HookTelemetryRow, } from "../lib/hooks/server-deps.js";
17
- export interface DryRunResult {
18
- result: unknown;
19
- trace: Array<{
20
- layer: string;
21
- reason: string;
22
- redaction_count: number;
23
- kind: string;
24
- }>;
25
- }
26
- /**
27
- * In-process dry-run for the hook pipeline. Lazy-loads staged-P2 modules.
28
- * Returns null when staged-P2 is not deployed.
29
- */
30
- export declare function dryRunHook(text: string, role?: "user" | "assistant" | "system" | "tool" | "unknown", source?: "openclaw" | "cli" | "manual" | "mcp" | "api" | "unknown"): Promise<DryRunResult | null>;
31
- /** Force the deps builder to load (used by `await Promise.all` warmup). */
32
- export declare function warmupHooksDeps(): Promise<void>;