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,213 +0,0 @@
1
- /**
2
- * src/observability/metrics.ts — Standard metric catalog (T3).
3
- *
4
- * Single source of truth for every metric exported by nox-mem. Each metric is
5
- * defined as a singleton attached to the default registry on first import.
6
- *
7
- * Naming convention (Prometheus + OpenMetrics best practices):
8
- * - snake_case
9
- * - prefix `nox_` for nox-mem metrics, `process_` / `nodejs_` for runtime
10
- * - `_total` suffix for Counter
11
- * - `_seconds` / `_bytes` for unit-bearing observations
12
- *
13
- * Cardinality budget per metric is conservative — see ./cardinality.ts.
14
- *
15
- * NOTE: Importing this module is a side-effect: it registers metrics into the
16
- * default registry. Tests using a fresh `new MetricsRegistry()` must either
17
- * import this and use the same singletons, or define their own metrics.
18
- */
19
- import { Counter, Gauge, Histogram, DURATION_BUCKETS_SECONDS, RESULT_COUNT_BUCKETS, } from "./types.js";
20
- import { getDefaultRegistry } from "./registry.js";
21
- const R = getDefaultRegistry();
22
- // ─── Pipeline metrics ────────────────────────────────────────────────────────
23
- export const chunksTotal = R.register(new Counter({
24
- name: "nox_chunks_total",
25
- help: "Total chunks ingested (cumulative).",
26
- labelKeys: ["provenance_kind"],
27
- }));
28
- export const embeddingsTotal = R.register(new Counter({
29
- name: "nox_embeddings_total",
30
- help: "Total embeddings created (cumulative).",
31
- labelKeys: ["provider", "outcome"],
32
- }));
33
- export const kgEntitiesTotal = R.register(new Counter({
34
- name: "nox_kg_entities_total",
35
- help: "Total KG entities created (cumulative).",
36
- labelKeys: ["type"],
37
- }));
38
- export const kgRelationsTotal = R.register(new Counter({
39
- name: "nox_kg_relations_total",
40
- help: "Total KG relations created (cumulative).",
41
- labelKeys: ["predicate"],
42
- }));
43
- // ─── Search metrics ──────────────────────────────────────────────────────────
44
- export const searchRequestsTotal = R.register(new Counter({
45
- name: "nox_search_requests_total",
46
- help: "Total search requests handled.",
47
- labelKeys: ["method", "outcome"],
48
- }));
49
- export const searchDurationSeconds = R.register(new Histogram({
50
- name: "nox_search_duration_seconds",
51
- help: "End-to-end search latency in seconds.",
52
- labelKeys: ["method"],
53
- unit: "seconds",
54
- }, DURATION_BUCKETS_SECONDS));
55
- export const searchResultsReturned = R.register(new Histogram({
56
- name: "nox_search_results_returned",
57
- help: "Distribution of result counts returned per search.",
58
- labelKeys: ["method"],
59
- }, RESULT_COUNT_BUCKETS));
60
- // ─── Answer (P1) metrics ─────────────────────────────────────────────────────
61
- export const answerRequestsTotal = R.register(new Counter({
62
- name: "nox_answer_requests_total",
63
- help: "Total /api/answer requests by failure reason.",
64
- labelKeys: ["failure_reason"], // success | no_chunks | llm_failed | hallucination
65
- }));
66
- export const answerDurationSeconds = R.register(new Histogram({
67
- name: "nox_answer_duration_seconds",
68
- help: "Answer latency by phase (total | retrieve | rerank | synthesize | verify).",
69
- labelKeys: ["phase"],
70
- unit: "seconds",
71
- }, DURATION_BUCKETS_SECONDS));
72
- export const answerTokensTotal = R.register(new Counter({
73
- name: "nox_answer_tokens_total",
74
- help: "Total tokens consumed by /api/answer (cumulative).",
75
- labelKeys: ["direction"], // input | output
76
- }));
77
- // ─── Provider (A3) metrics ───────────────────────────────────────────────────
78
- export const providerCallsTotal = R.register(new Counter({
79
- name: "nox_provider_calls_total",
80
- help: "Total LLM/embedding provider calls.",
81
- labelKeys: ["provider", "model", "outcome"], // outcome: success | rate_limit | error | fallback
82
- }));
83
- export const providerDurationSeconds = R.register(new Histogram({
84
- name: "nox_provider_duration_seconds",
85
- help: "Provider call latency in seconds.",
86
- labelKeys: ["provider", "kind"], // kind: embedding | llm
87
- unit: "seconds",
88
- }, DURATION_BUCKETS_SECONDS));
89
- export const providerCostUsdTotal = R.register(new Counter({
90
- name: "nox_provider_cost_usd_total",
91
- help: "Cumulative provider cost in USD.",
92
- labelKeys: ["provider", "model"],
93
- }));
94
- export const providerTokensTotal = R.register(new Counter({
95
- name: "nox_provider_tokens_total",
96
- help: "Cumulative provider tokens by direction.",
97
- labelKeys: ["provider", "direction"], // direction: input | output
98
- }));
99
- // ─── Hooks (P2) metrics ──────────────────────────────────────────────────────
100
- export const hooksEventsTotal = R.register(new Counter({
101
- name: "nox_hooks_events_total",
102
- help: "Total auto-capture hook events by layer + reason.",
103
- labelKeys: ["layer", "reason"], // reason: captured | filtered | redacted | error
104
- }));
105
- export const hooksPipelineDurationSeconds = R.register(new Histogram({
106
- name: "nox_hooks_pipeline_duration_seconds",
107
- help: "Hooks capture pipeline latency in seconds.",
108
- labelKeys: ["layer"],
109
- unit: "seconds",
110
- }, DURATION_BUCKETS_SECONDS));
111
- // ─── Viewer (P5) metrics ─────────────────────────────────────────────────────
112
- export const viewerConnections = R.register(new Gauge({
113
- name: "nox_viewer_connections",
114
- help: "Current count of open viewer SSE connections.",
115
- labelKeys: [],
116
- }));
117
- export const viewerEventsTotal = R.register(new Counter({
118
- name: "nox_viewer_events_total",
119
- help: "Total viewer events broadcast by type.",
120
- labelKeys: ["type"],
121
- }));
122
- export const viewerDroppedTotal = R.register(new Counter({
123
- name: "nox_viewer_dropped_total",
124
- help: "Total viewer events dropped due to backpressure.",
125
- labelKeys: ["reason"], // reason: slow_consumer | queue_full | client_gone
126
- }));
127
- // ─── System metrics ──────────────────────────────────────────────────────────
128
- export const dbSizeBytes = R.register(new Gauge({
129
- name: "nox_db_size_bytes",
130
- help: "Size of the SQLite DB file in bytes (main + WAL).",
131
- labelKeys: ["component"], // component: main | wal | shm
132
- unit: "bytes",
133
- }));
134
- export const chunksActive = R.register(new Gauge({
135
- name: "nox_chunks_active",
136
- help: "Active chunks (provenance_kind != stale).",
137
- labelKeys: [],
138
- }));
139
- export const chunksStale = R.register(new Gauge({
140
- name: "nox_chunks_stale",
141
- help: "Stale chunks (provenance_kind == stale).",
142
- labelKeys: [],
143
- }));
144
- export const auditRowsTotal = R.register(new Counter({
145
- name: "nox_audit_rows_total",
146
- help: "Total audit rows written by table.",
147
- labelKeys: ["table"], // table: ops_audit | provider_telemetry | search_telemetry | agent_events
148
- }));
149
- // ─── Process / runtime metrics ───────────────────────────────────────────────
150
- export const processCpuUserSecondsTotal = R.register(new Counter({
151
- name: "process_cpu_user_seconds_total",
152
- help: "Total user CPU time in seconds (cumulative).",
153
- labelKeys: [],
154
- unit: "seconds",
155
- }));
156
- export const processCpuSystemSecondsTotal = R.register(new Counter({
157
- name: "process_cpu_system_seconds_total",
158
- help: "Total system CPU time in seconds (cumulative).",
159
- labelKeys: [],
160
- unit: "seconds",
161
- }));
162
- export const processResidentMemoryBytes = R.register(new Gauge({
163
- name: "process_resident_memory_bytes",
164
- help: "Resident memory in bytes (RSS).",
165
- labelKeys: [],
166
- unit: "bytes",
167
- }));
168
- export const processOpenFds = R.register(new Gauge({
169
- name: "process_open_fds",
170
- help: "Number of open file descriptors (best-effort).",
171
- labelKeys: [],
172
- }));
173
- export const nodejsEventloopLagSeconds = R.register(new Gauge({
174
- name: "nodejs_eventloop_lag_seconds",
175
- help: "Event loop lag in seconds (last sample).",
176
- labelKeys: [],
177
- unit: "seconds",
178
- }));
179
- // ─── Catalog summary (for docs / tests / cardinality budgeting) ─────────────
180
- /**
181
- * Names of every metric registered by this module.
182
- * Order: same as registration order above.
183
- */
184
- export const ALL_METRIC_NAMES = Object.freeze([
185
- "nox_chunks_total",
186
- "nox_embeddings_total",
187
- "nox_kg_entities_total",
188
- "nox_kg_relations_total",
189
- "nox_search_requests_total",
190
- "nox_search_duration_seconds",
191
- "nox_search_results_returned",
192
- "nox_answer_requests_total",
193
- "nox_answer_duration_seconds",
194
- "nox_answer_tokens_total",
195
- "nox_provider_calls_total",
196
- "nox_provider_duration_seconds",
197
- "nox_provider_cost_usd_total",
198
- "nox_provider_tokens_total",
199
- "nox_hooks_events_total",
200
- "nox_hooks_pipeline_duration_seconds",
201
- "nox_viewer_connections",
202
- "nox_viewer_events_total",
203
- "nox_viewer_dropped_total",
204
- "nox_db_size_bytes",
205
- "nox_chunks_active",
206
- "nox_chunks_stale",
207
- "nox_audit_rows_total",
208
- "process_cpu_user_seconds_total",
209
- "process_cpu_system_seconds_total",
210
- "process_resident_memory_bytes",
211
- "process_open_fds",
212
- "nodejs_eventloop_lag_seconds",
213
- ]);
@@ -1,32 +0,0 @@
1
- /**
2
- * src/observability/privacy-guard.ts — PII / sensitive-text stripper (T9).
3
- *
4
- * RULES (non-negotiable):
5
- * 1. No raw query text in label values — replace with "<redacted-query>".
6
- * 2. No paths, file names, IPs, emails, phone numbers, BR personal IDs
7
- * (CPF/CNPJ/CEP/RG), Pix keys, API keys / bearer tokens.
8
- * 3. Anything not on a strict allowlist of "shapes" → "<redacted>".
9
- *
10
- * This module composes with `cardinality.ts` — privacy strips PII *contents*,
11
- * cardinality enforces *shape* (allowlists) and *budget*.
12
- *
13
- * Patterns mirror A1 (privacy filter) and A1.1 (BR PII). Kept self-contained
14
- * to avoid coupling — the observability layer must function even if the
15
- * privacy package is later refactored.
16
- */
17
- /** Strip PII from a string. Returns the sanitized string. */
18
- export declare function sanitizeString(s: string): string;
19
- export declare function sanitizeLabelValue(name: string, value: string): string;
20
- /** Sanitize an entire labels object — drop forbidden keys, coerce values. */
21
- export declare function sanitizeLabels(labels: Record<string, string>): Record<string, string>;
22
- import { CardinalityGuard } from "./cardinality.js";
23
- export interface GuardChainResult {
24
- /** Sanitized + cardinality-checked labels, or null if dropped. */
25
- labels: Record<string, string> | null;
26
- }
27
- /**
28
- * One-call guard for any metric: privacy first, then cardinality.
29
- *
30
- * This is the function the recording API uses. Caller should `null`-check.
31
- */
32
- export declare function guardLabels(metricName: string, rawLabels?: Record<string, string>, guard?: CardinalityGuard): GuardChainResult;
@@ -1,116 +0,0 @@
1
- /**
2
- * src/observability/privacy-guard.ts — PII / sensitive-text stripper (T9).
3
- *
4
- * RULES (non-negotiable):
5
- * 1. No raw query text in label values — replace with "<redacted-query>".
6
- * 2. No paths, file names, IPs, emails, phone numbers, BR personal IDs
7
- * (CPF/CNPJ/CEP/RG), Pix keys, API keys / bearer tokens.
8
- * 3. Anything not on a strict allowlist of "shapes" → "<redacted>".
9
- *
10
- * This module composes with `cardinality.ts` — privacy strips PII *contents*,
11
- * cardinality enforces *shape* (allowlists) and *budget*.
12
- *
13
- * Patterns mirror A1 (privacy filter) and A1.1 (BR PII). Kept self-contained
14
- * to avoid coupling — the observability layer must function even if the
15
- * privacy package is later refactored.
16
- */
17
- // ─── PII / secret patterns ───────────────────────────────────────────────────
18
- const PATTERNS = [
19
- // Emails
20
- { re: /[\w.+-]+@[\w-]+\.[\w.-]+/gi, label: "<redacted-email>" },
21
- // Bearer tokens / Bearer + JWT-ish
22
- { re: /Bearer\s+[A-Za-z0-9._-]{16,}/gi, label: "<redacted-bearer>" },
23
- // OpenAI / Anthropic / Gemini-ish API keys
24
- { re: /sk-[A-Za-z0-9_-]{20,}/g, label: "<redacted-key>" },
25
- { re: /AIza[0-9A-Za-z_-]{20,}/g, label: "<redacted-key>" },
26
- { re: /\bgsk_[A-Za-z0-9]{20,}/g, label: "<redacted-key>" },
27
- // Generic high-entropy hex/uuid in the wild (32+ chars hex)
28
- { re: /\b[A-Fa-f0-9]{32,}\b/g, label: "<redacted-hex>" },
29
- // UUID
30
- {
31
- re: /\b[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}\b/gi,
32
- label: "<redacted-uuid>",
33
- },
34
- // IPv4
35
- { re: /\b\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}\b/g, label: "<redacted-ip>" },
36
- // CPF (Brazilian personal ID) — 000.000.000-00 or 11 digits
37
- { re: /\b\d{3}\.\d{3}\.\d{3}-\d{2}\b/g, label: "<redacted-cpf>" },
38
- // CNPJ — 00.000.000/0000-00
39
- {
40
- re: /\b\d{2}\.\d{3}\.\d{3}\/\d{4}-\d{2}\b/g,
41
- label: "<redacted-cnpj>",
42
- },
43
- // CEP — 00000-000
44
- { re: /\b\d{5}-\d{3}\b/g, label: "<redacted-cep>" },
45
- // Phone — generic E.164 + BR
46
- { re: /\+?\d{1,3}[\s-]?\(?\d{2,4}\)?[\s-]?\d{4,5}[\s-]?\d{4}/g, label: "<redacted-phone>" },
47
- // Absolute path (Unix or Windows)
48
- { re: /(?:[A-Za-z]:)?(?:\/[\w.\-+@]+){2,}/g, label: "<redacted-path>" },
49
- // URL
50
- { re: /https?:\/\/[\w.\-/?&=%#:]+/gi, label: "<redacted-url>" },
51
- ];
52
- /** Strip PII from a string. Returns the sanitized string. */
53
- export function sanitizeString(s) {
54
- if (!s)
55
- return s;
56
- let out = s;
57
- for (const { re, label } of PATTERNS) {
58
- out = out.replace(re, label);
59
- }
60
- return out;
61
- }
62
- /**
63
- * Validate a label value: it must be either a known short shape (alphanum,
64
- * snake_case, enum-style), or it gets coerced to "<redacted>".
65
- *
66
- * The intent is that *label values* are categorical (small set of low-entropy
67
- * strings). Anything longer than 64 chars or containing PII patterns is
68
- * automatically dropped.
69
- */
70
- const SAFE_VALUE_RE = /^[A-Za-z0-9_:\-.+]{1,64}$/;
71
- const FORBIDDEN_NAME_HINTS = [
72
- "query",
73
- "prompt",
74
- "response",
75
- "user",
76
- "email",
77
- "ip",
78
- "path",
79
- "file",
80
- ];
81
- export function sanitizeLabelValue(name, value) {
82
- // First, hard-strip PII patterns.
83
- const stripped = sanitizeString(value);
84
- // If the name itself looks like it carries content (query, prompt, …),
85
- // collapse the value to a constant.
86
- if (FORBIDDEN_NAME_HINTS.some((h) => name.toLowerCase().includes(h))) {
87
- return "<redacted>";
88
- }
89
- // If after stripping it doesn't match safe shape, redact.
90
- if (!SAFE_VALUE_RE.test(stripped)) {
91
- return "<redacted>";
92
- }
93
- return stripped;
94
- }
95
- /** Sanitize an entire labels object — drop forbidden keys, coerce values. */
96
- export function sanitizeLabels(labels) {
97
- const out = {};
98
- for (const [k, v] of Object.entries(labels)) {
99
- if (typeof v !== "string")
100
- continue;
101
- out[k] = sanitizeLabelValue(k, v);
102
- }
103
- return out;
104
- }
105
- // ─── Composable guard: privacy → cardinality ────────────────────────────────
106
- import { getDefaultGuard } from "./cardinality.js";
107
- /**
108
- * One-call guard for any metric: privacy first, then cardinality.
109
- *
110
- * This is the function the recording API uses. Caller should `null`-check.
111
- */
112
- export function guardLabels(metricName, rawLabels = {}, guard = getDefaultGuard()) {
113
- const sanitized = sanitizeLabels(rawLabels);
114
- const checked = guard.guard(metricName, sanitized);
115
- return { labels: checked };
116
- }
@@ -1,83 +0,0 @@
1
- /**
2
- * src/observability/record.ts — High-level recording API (T6).
3
- *
4
- * Convenience wrappers around the metric primitives. Callers in P1/A3/P5
5
- * should use these — NOT `counter.inc()` directly — so that:
6
- * 1. Cardinality + privacy guards are applied consistently.
7
- * 2. Future schema changes only touch one file.
8
- * 3. The recording is *fire-and-forget*: never throws, never blocks.
9
- *
10
- * All functions in this module catch + swallow errors. The hot path must
11
- * not be affected by observability failures.
12
- */
13
- export type SearchMethod = "cli" | "api" | "mcp";
14
- export type SearchOutcome = "success" | "empty" | "error";
15
- export declare function recordSearch(opts: {
16
- method: SearchMethod;
17
- durationSeconds: number;
18
- resultsCount: number;
19
- outcome: SearchOutcome;
20
- }): void;
21
- export type AnswerOutcome = "success" | "no_chunks" | "llm_failed" | "hallucination" | "timeout" | "cost_cap";
22
- export interface AnswerTiming {
23
- total?: number;
24
- retrieve?: number;
25
- rerank?: number;
26
- synthesize?: number;
27
- verify?: number;
28
- }
29
- export declare function recordAnswer(opts: {
30
- outcome: AnswerOutcome;
31
- timing: AnswerTiming;
32
- tokensIn?: number;
33
- tokensOut?: number;
34
- }): void;
35
- export type ProviderOutcome = "success" | "rate_limit" | "error" | "fallback";
36
- export type ProviderKind = "embedding" | "llm";
37
- export declare function recordProviderCall(opts: {
38
- provider: string;
39
- model: string;
40
- kind: ProviderKind;
41
- durationSeconds: number;
42
- outcome: ProviderOutcome;
43
- costUsd?: number;
44
- tokensIn?: number;
45
- tokensOut?: number;
46
- }): void;
47
- export type ProvenanceKind = "fresh" | "stale" | "compiled" | "frontmatter" | "timeline";
48
- export declare function recordChunkIngest(opts: {
49
- provenanceKind: ProvenanceKind;
50
- count?: number;
51
- redactionsApplied?: number;
52
- }): void;
53
- export declare function recordEmbedding(opts: {
54
- provider: string;
55
- outcome: "success" | "error";
56
- count?: number;
57
- }): void;
58
- export declare function recordKgEntity(opts: {
59
- type: string;
60
- count?: number;
61
- }): void;
62
- export declare function recordKgRelation(opts: {
63
- predicate: string;
64
- count?: number;
65
- }): void;
66
- export declare function recordHookEvent(opts: {
67
- layer: string;
68
- reason: "captured" | "filtered" | "redacted" | "error" | "dropped";
69
- durationSeconds?: number;
70
- }): void;
71
- export declare function recordViewerConnect(): void;
72
- export declare function recordViewerDisconnect(): void;
73
- export declare function recordViewerEvent(type: string): void;
74
- export declare function recordViewerDropped(reason: "slow_consumer" | "queue_full" | "client_gone"): void;
75
- export declare function recordAuditWrite(table: string, count?: number): void;
76
- /**
77
- * Start a high-resolution timer that returns elapsed seconds when called.
78
- * Use:
79
- * const end = startTimer();
80
- * // ... work
81
- * recordSearch({ method: "api", durationSeconds: end(), … });
82
- */
83
- export declare function startTimer(): () => number;
@@ -1,217 +0,0 @@
1
- /**
2
- * src/observability/record.ts — High-level recording API (T6).
3
- *
4
- * Convenience wrappers around the metric primitives. Callers in P1/A3/P5
5
- * should use these — NOT `counter.inc()` directly — so that:
6
- * 1. Cardinality + privacy guards are applied consistently.
7
- * 2. Future schema changes only touch one file.
8
- * 3. The recording is *fire-and-forget*: never throws, never blocks.
9
- *
10
- * All functions in this module catch + swallow errors. The hot path must
11
- * not be affected by observability failures.
12
- */
13
- import { chunksTotal, embeddingsTotal, kgEntitiesTotal, kgRelationsTotal, searchRequestsTotal, searchDurationSeconds, searchResultsReturned, answerRequestsTotal, answerDurationSeconds, answerTokensTotal, providerCallsTotal, providerDurationSeconds, providerCostUsdTotal, providerTokensTotal, hooksEventsTotal, hooksPipelineDurationSeconds, viewerConnections, viewerEventsTotal, viewerDroppedTotal, auditRowsTotal, } from "./metrics.js";
14
- import { guardLabels } from "./privacy-guard.js";
15
- // ─── helpers ─────────────────────────────────────────────────────────────────
16
- function safe(fn) {
17
- try {
18
- return fn();
19
- }
20
- catch {
21
- return undefined;
22
- }
23
- }
24
- export function recordSearch(opts) {
25
- safe(() => {
26
- const reqLabels = guardLabels("nox_search_requests_total", {
27
- method: opts.method,
28
- outcome: opts.outcome,
29
- }).labels;
30
- if (reqLabels)
31
- searchRequestsTotal.inc(reqLabels);
32
- const durLabels = guardLabels("nox_search_duration_seconds", {
33
- method: opts.method,
34
- }).labels;
35
- if (durLabels)
36
- searchDurationSeconds.observe(durLabels, opts.durationSeconds);
37
- const resLabels = guardLabels("nox_search_results_returned", {
38
- method: opts.method,
39
- }).labels;
40
- if (resLabels)
41
- searchResultsReturned.observe(resLabels, opts.resultsCount);
42
- });
43
- }
44
- export function recordAnswer(opts) {
45
- safe(() => {
46
- const reqLabels = guardLabels("nox_answer_requests_total", {
47
- failure_reason: opts.outcome,
48
- }).labels;
49
- if (reqLabels)
50
- answerRequestsTotal.inc(reqLabels);
51
- for (const phase of [
52
- "total",
53
- "retrieve",
54
- "rerank",
55
- "synthesize",
56
- "verify",
57
- ]) {
58
- const v = opts.timing[phase];
59
- if (typeof v === "number" && Number.isFinite(v)) {
60
- const lbl = guardLabels("nox_answer_duration_seconds", { phase }).labels;
61
- if (lbl)
62
- answerDurationSeconds.observe(lbl, v);
63
- }
64
- }
65
- if (typeof opts.tokensIn === "number" && opts.tokensIn > 0) {
66
- const lbl = guardLabels("nox_answer_tokens_total", {
67
- direction: "input",
68
- }).labels;
69
- if (lbl)
70
- answerTokensTotal.inc(lbl, opts.tokensIn);
71
- }
72
- if (typeof opts.tokensOut === "number" && opts.tokensOut > 0) {
73
- const lbl = guardLabels("nox_answer_tokens_total", {
74
- direction: "output",
75
- }).labels;
76
- if (lbl)
77
- answerTokensTotal.inc(lbl, opts.tokensOut);
78
- }
79
- });
80
- }
81
- export function recordProviderCall(opts) {
82
- safe(() => {
83
- const callLabels = guardLabels("nox_provider_calls_total", {
84
- provider: opts.provider,
85
- model: opts.model,
86
- outcome: opts.outcome,
87
- }).labels;
88
- if (callLabels)
89
- providerCallsTotal.inc(callLabels);
90
- const durLabels = guardLabels("nox_provider_duration_seconds", {
91
- provider: opts.provider,
92
- kind: opts.kind,
93
- }).labels;
94
- if (durLabels)
95
- providerDurationSeconds.observe(durLabels, opts.durationSeconds);
96
- if (typeof opts.costUsd === "number" && opts.costUsd > 0) {
97
- const lbl = guardLabels("nox_provider_cost_usd_total", {
98
- provider: opts.provider,
99
- model: opts.model,
100
- }).labels;
101
- if (lbl)
102
- providerCostUsdTotal.inc(lbl, opts.costUsd);
103
- }
104
- if (typeof opts.tokensIn === "number" && opts.tokensIn > 0) {
105
- const lbl = guardLabels("nox_provider_tokens_total", {
106
- provider: opts.provider,
107
- direction: "input",
108
- }).labels;
109
- if (lbl)
110
- providerTokensTotal.inc(lbl, opts.tokensIn);
111
- }
112
- if (typeof opts.tokensOut === "number" && opts.tokensOut > 0) {
113
- const lbl = guardLabels("nox_provider_tokens_total", {
114
- provider: opts.provider,
115
- direction: "output",
116
- }).labels;
117
- if (lbl)
118
- providerTokensTotal.inc(lbl, opts.tokensOut);
119
- }
120
- });
121
- }
122
- export function recordChunkIngest(opts) {
123
- safe(() => {
124
- const lbl = guardLabels("nox_chunks_total", {
125
- provenance_kind: opts.provenanceKind,
126
- }).labels;
127
- if (lbl)
128
- chunksTotal.inc(lbl, opts.count ?? 1);
129
- });
130
- }
131
- export function recordEmbedding(opts) {
132
- safe(() => {
133
- const lbl = guardLabels("nox_embeddings_total", {
134
- provider: opts.provider,
135
- outcome: opts.outcome,
136
- }).labels;
137
- if (lbl)
138
- embeddingsTotal.inc(lbl, opts.count ?? 1);
139
- });
140
- }
141
- export function recordKgEntity(opts) {
142
- safe(() => {
143
- const lbl = guardLabels("nox_kg_entities_total", {
144
- type: opts.type,
145
- }).labels;
146
- if (lbl)
147
- kgEntitiesTotal.inc(lbl, opts.count ?? 1);
148
- });
149
- }
150
- export function recordKgRelation(opts) {
151
- safe(() => {
152
- const lbl = guardLabels("nox_kg_relations_total", {
153
- predicate: opts.predicate,
154
- }).labels;
155
- if (lbl)
156
- kgRelationsTotal.inc(lbl, opts.count ?? 1);
157
- });
158
- }
159
- // ─── Hooks (P2) ──────────────────────────────────────────────────────────────
160
- export function recordHookEvent(opts) {
161
- safe(() => {
162
- const evtLabels = guardLabels("nox_hooks_events_total", {
163
- layer: opts.layer,
164
- reason: opts.reason,
165
- }).labels;
166
- if (evtLabels)
167
- hooksEventsTotal.inc(evtLabels);
168
- if (typeof opts.durationSeconds === "number") {
169
- const dur = guardLabels("nox_hooks_pipeline_duration_seconds", {
170
- layer: opts.layer,
171
- }).labels;
172
- if (dur)
173
- hooksPipelineDurationSeconds.observe(dur, opts.durationSeconds);
174
- }
175
- });
176
- }
177
- // ─── Viewer (P5) ─────────────────────────────────────────────────────────────
178
- export function recordViewerConnect() {
179
- safe(() => viewerConnections.inc());
180
- }
181
- export function recordViewerDisconnect() {
182
- safe(() => viewerConnections.dec());
183
- }
184
- export function recordViewerEvent(type) {
185
- safe(() => {
186
- const lbl = guardLabels("nox_viewer_events_total", { type }).labels;
187
- if (lbl)
188
- viewerEventsTotal.inc(lbl);
189
- });
190
- }
191
- export function recordViewerDropped(reason) {
192
- safe(() => {
193
- const lbl = guardLabels("nox_viewer_dropped_total", { reason }).labels;
194
- if (lbl)
195
- viewerDroppedTotal.inc(lbl);
196
- });
197
- }
198
- // ─── Audit ───────────────────────────────────────────────────────────────────
199
- export function recordAuditWrite(table, count = 1) {
200
- safe(() => {
201
- const lbl = guardLabels("nox_audit_rows_total", { table }).labels;
202
- if (lbl)
203
- auditRowsTotal.inc(lbl, count);
204
- });
205
- }
206
- // ─── Timer helper ────────────────────────────────────────────────────────────
207
- /**
208
- * Start a high-resolution timer that returns elapsed seconds when called.
209
- * Use:
210
- * const end = startTimer();
211
- * // ... work
212
- * recordSearch({ method: "api", durationSeconds: end(), … });
213
- */
214
- export function startTimer() {
215
- const start = process.hrtime.bigint();
216
- return () => Number(process.hrtime.bigint() - start) / 1e9;
217
- }