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,78 +0,0 @@
1
- /**
2
- * src/mcp/tools/hooks.ts — T13: MCP tool wrappers around the CLI/HTTP API.
3
- *
4
- * Exposes 4 tools to MCP clients (Claude Desktop, Claude Code, etc.):
5
- *
6
- * nox_hooks_status → { config, queue_depth }
7
- * nox_hooks_recent → { rows[] } (metadata only, no content)
8
- * nox_hooks_dryrun → { result, trace } (input: { text, role?, source? })
9
- * nox_hooks_stats → { last_24h, last_7d } (counters)
10
- *
11
- * Schema follows the Anthropic MCP spec (JSON schema for inputs/outputs).
12
- * Implementation defers to the same handlers as HTTP (T12) and CLI (T11)
13
- * to keep one source of truth per verb.
14
- */
15
- import { handleHooksRequest } from "../../api/hooks.js";
16
- import { runHooksCommand } from "../../cli/hooks.js";
17
- export const HOOK_TOOLS = [
18
- {
19
- name: "nox_hooks_status",
20
- description: "Return current nox-mem hooks pipeline config + queue depth.",
21
- inputSchema: { type: "object", properties: {}, additionalProperties: false },
22
- },
23
- {
24
- name: "nox_hooks_recent",
25
- description: "Return last N captured events (metadata only — never raw content). Default N=20.",
26
- inputSchema: {
27
- type: "object",
28
- properties: { limit: { type: "integer", minimum: 1, maximum: 100 } },
29
- additionalProperties: false,
30
- },
31
- },
32
- {
33
- name: "nox_hooks_dryrun",
34
- description: "Run a single text through all 5 hook layers in dry-run mode. Returns per-layer trace and final decision. Does NOT persist anything.",
35
- inputSchema: {
36
- type: "object",
37
- properties: {
38
- text: { type: "string", minLength: 1 },
39
- role: { type: "string", enum: ["user", "assistant", "system", "tool", "unknown"] },
40
- source: { type: "string", enum: ["openclaw", "cli", "manual", "mcp", "api", "unknown"] },
41
- },
42
- required: ["text"],
43
- additionalProperties: false,
44
- },
45
- },
46
- {
47
- name: "nox_hooks_stats",
48
- description: "Return aggregate counters of captures/rejections over last 24h and 7d.",
49
- inputSchema: { type: "object", properties: {}, additionalProperties: false },
50
- },
51
- ];
52
- /** Dispatch a single MCP tool call by name. */
53
- export async function callHookTool(name, args, deps) {
54
- switch (name) {
55
- case "nox_hooks_status": {
56
- const resp = await handleHooksRequest({ method: "GET", path: "/api/hooks/status" }, deps);
57
- return { ok: resp.status === 200, content: resp.body };
58
- }
59
- case "nox_hooks_recent": {
60
- const limit = typeof args["limit"] === "number" ? String(args["limit"]) : "20";
61
- const resp = await handleHooksRequest({ method: "GET", path: "/api/hooks/recent", query: { limit } }, deps);
62
- return { ok: resp.status === 200, content: resp.body };
63
- }
64
- case "nox_hooks_dryrun": {
65
- const resp = await handleHooksRequest({ method: "POST", path: "/api/hooks/dryrun", body: args }, deps);
66
- return { ok: resp.status === 200, content: resp.body };
67
- }
68
- case "nox_hooks_stats": {
69
- const result = await runHooksCommand(["stats"], {
70
- readRecent: deps.readRecent,
71
- readStats: deps.readStats,
72
- });
73
- return { ok: result.ok, content: result.data ?? { output: result.output } };
74
- }
75
- default:
76
- return { ok: false, content: { error: `unknown tool: ${name}` } };
77
- }
78
- }
@@ -1,38 +0,0 @@
1
- /**
2
- * src/mcp/tools/mark.ts — MCP tool definitions for L3 mark workflow.
3
- *
4
- * Two tools surfaced:
5
- * chunk_mark(id, kind, notes?) → MarkResult
6
- * chunk_supersede(id, by_id, notes?, reason?) → MarkResult
7
- *
8
- * MCP tool descriptors are returned by listMarkTools() so the main MCP server
9
- * can register them alongside its existing 16 tools.
10
- *
11
- * Spec ref: specs/2026-05-17-L3-confidence-field.md §7 (MCP).
12
- */
13
- import type { Db } from "../../lib/confidence/db-shim.js";
14
- import type { MarkKind, MarkResult, SupersedeReason } from "../../lib/confidence/types.js";
15
- export interface McpTool {
16
- name: string;
17
- description: string;
18
- inputSchema: {
19
- type: "object";
20
- properties: Record<string, unknown>;
21
- required: string[];
22
- };
23
- }
24
- export declare function listMarkTools(): McpTool[];
25
- interface MarkInput {
26
- id: number;
27
- kind: MarkKind;
28
- notes?: string;
29
- }
30
- interface SupersedeInput {
31
- id: number;
32
- by_id: number;
33
- notes?: string;
34
- reason?: SupersedeReason;
35
- }
36
- export declare function callChunkMark(db: Db, input: MarkInput): MarkResult;
37
- export declare function callChunkSupersede(db: Db, input: SupersedeInput): MarkResult;
38
- export {};
@@ -1,82 +0,0 @@
1
- /**
2
- * src/mcp/tools/mark.ts — MCP tool definitions for L3 mark workflow.
3
- *
4
- * Two tools surfaced:
5
- * chunk_mark(id, kind, notes?) → MarkResult
6
- * chunk_supersede(id, by_id, notes?, reason?) → MarkResult
7
- *
8
- * MCP tool descriptors are returned by listMarkTools() so the main MCP server
9
- * can register them alongside its existing 16 tools.
10
- *
11
- * Spec ref: specs/2026-05-17-L3-confidence-field.md §7 (MCP).
12
- */
13
- import { markChunk, supersedeChunk, } from "../../lib/confidence/mark.js";
14
- import { resolveConfig } from "../../lib/confidence/config.js";
15
- export function listMarkTools() {
16
- return [
17
- {
18
- name: "chunk_mark",
19
- description: "Mark a chunk as canonical (operator-affirmed), refuted (operator-negated), or stale (no longer trustworthy). Updates chunks.confidence + chunks.provenance_kind. Appends ops_audit row. Use when the operator reviews a fact and wants it elevated (canonical) or demoted (refuted/stale).",
20
- inputSchema: {
21
- type: "object",
22
- properties: {
23
- id: { type: "number", description: "Chunk id to mark." },
24
- kind: {
25
- type: "string",
26
- enum: ["canonical", "refuted", "stale"],
27
- description: "Mark kind. canonical=1.0 conf, refuted=0.05 conf, stale=conf unchanged but provenance=user-marked.",
28
- },
29
- notes: {
30
- type: "string",
31
- description: "Optional free-text note logged to ops_audit.details.",
32
- },
33
- },
34
- required: ["id", "kind"],
35
- },
36
- },
37
- {
38
- name: "chunk_supersede",
39
- description: "Mark a chunk as superseded by a newer chunk. Sets chunks.superseded_by FK. Useful when a fact has been replaced (e.g. 'gemini-2.5-flash → gemini-2.5-flash-lite as default model'). Older chunk remains in DB for audit; ranking integration de-prioritizes superseded chunks when NOX_RANKING_CONFIDENCE=active.",
40
- inputSchema: {
41
- type: "object",
42
- properties: {
43
- id: { type: "number", description: "Older chunk id (the one being replaced)." },
44
- by_id: {
45
- type: "number",
46
- description: "Newer chunk id (the one replacing it).",
47
- },
48
- notes: { type: "string", description: "Optional context." },
49
- reason: {
50
- type: "string",
51
- enum: [
52
- "auto_supersede_temporal",
53
- "manual_resolution",
54
- "stale_link_reconciliation",
55
- "dismiss",
56
- ],
57
- description: "Why this supersession is happening (mirrors kg_relations.superseded_reason).",
58
- },
59
- },
60
- required: ["id", "by_id"],
61
- },
62
- },
63
- ];
64
- }
65
- export function callChunkMark(db, input) {
66
- return markChunk({
67
- db,
68
- chunk_id: input.id,
69
- kind: input.kind,
70
- notes: input.notes,
71
- cfg: resolveConfig(),
72
- });
73
- }
74
- export function callChunkSupersede(db, input) {
75
- return supersedeChunk({
76
- db,
77
- chunk_id: input.id,
78
- by_chunk_id: input.by_id,
79
- notes: input.notes,
80
- reason: input.reason,
81
- });
82
- }
@@ -1,58 +0,0 @@
1
- /**
2
- * T13 — MCP tool: viewer_recent_events
3
- *
4
- * Lets Claude (or any MCP client) peek at recent viewer events without
5
- * opening an SSE connection. Backed by the same Broadcaster's ring buffer.
6
- *
7
- * Inputs:
8
- * - limit: 1..200 (default 50)
9
- * - type_filter: optional ViewerEventKind | "all"
10
- *
11
- * Output: array of envelopes (id + event), newest last.
12
- */
13
- import { Broadcaster } from "../../lib/viewer/broadcast.js";
14
- import { type ViewerEventKind, type ViewerEvent } from "../../lib/viewer/event-types.js";
15
- export declare const VIEWER_MCP_TOOL_NAME = "viewer_recent_events";
16
- export interface ViewerMcpInput {
17
- limit?: number;
18
- type_filter?: ViewerEventKind | "all";
19
- }
20
- export interface ViewerMcpItem {
21
- id: number;
22
- ev: ViewerEvent;
23
- }
24
- export interface ViewerMcpOutput {
25
- count: number;
26
- items: ViewerMcpItem[];
27
- ring_size: number;
28
- filter: ViewerEventKind | "all";
29
- }
30
- export declare function validateInput(input: ViewerMcpInput): {
31
- limit: number;
32
- filter: ViewerEventKind | "all";
33
- };
34
- export declare function recentEvents(broadcaster: Broadcaster, input?: ViewerMcpInput): ViewerMcpOutput;
35
- /** MCP-style tool descriptor. The host wires this into the tools registry. */
36
- export declare const VIEWER_MCP_DESCRIPTOR: {
37
- readonly name: "viewer_recent_events";
38
- readonly description: string;
39
- readonly inputSchema: {
40
- readonly type: "object";
41
- readonly properties: {
42
- readonly limit: {
43
- readonly type: "integer";
44
- readonly minimum: 1;
45
- readonly maximum: 200;
46
- readonly default: 50;
47
- readonly description: "Max events to return (1..200).";
48
- };
49
- readonly type_filter: {
50
- readonly type: "string";
51
- readonly enum: readonly ["ingest", "search", "kg", "crystallize", "op_audit", "all"];
52
- readonly default: "all";
53
- readonly description: "Restrict by event type.";
54
- };
55
- };
56
- readonly additionalProperties: false;
57
- };
58
- };
@@ -1,64 +0,0 @@
1
- /**
2
- * T13 — MCP tool: viewer_recent_events
3
- *
4
- * Lets Claude (or any MCP client) peek at recent viewer events without
5
- * opening an SSE connection. Backed by the same Broadcaster's ring buffer.
6
- *
7
- * Inputs:
8
- * - limit: 1..200 (default 50)
9
- * - type_filter: optional ViewerEventKind | "all"
10
- *
11
- * Output: array of envelopes (id + event), newest last.
12
- */
13
- export const VIEWER_MCP_TOOL_NAME = "viewer_recent_events";
14
- const DEFAULT_LIMIT = 50;
15
- const MAX_LIMIT = 200;
16
- export function validateInput(input) {
17
- let limit = input.limit ?? DEFAULT_LIMIT;
18
- if (!Number.isFinite(limit) || limit <= 0)
19
- limit = DEFAULT_LIMIT;
20
- if (limit > MAX_LIMIT)
21
- limit = MAX_LIMIT;
22
- const filter = input.type_filter ?? "all";
23
- return { limit: Math.floor(limit), filter };
24
- }
25
- export function recentEvents(broadcaster, input = {}) {
26
- const { limit, filter } = validateInput(input);
27
- const ring = broadcaster.ringSnapshot();
28
- const filtered = filter === "all"
29
- ? ring.slice()
30
- : ring.filter((env) => env.ev.type === filter);
31
- const tail = filtered.slice(-limit);
32
- return {
33
- count: tail.length,
34
- items: tail.map((env) => ({ id: env.id, ev: env.ev })),
35
- ring_size: ring.length,
36
- filter,
37
- };
38
- }
39
- /** MCP-style tool descriptor. The host wires this into the tools registry. */
40
- export const VIEWER_MCP_DESCRIPTOR = {
41
- name: VIEWER_MCP_TOOL_NAME,
42
- description: "Returns the last N viewer events from the in-memory ring buffer. " +
43
- "Useful for peeking at recent ingest/search/KG activity without opening " +
44
- "an SSE connection. All events are post-redaction.",
45
- inputSchema: {
46
- type: "object",
47
- properties: {
48
- limit: {
49
- type: "integer",
50
- minimum: 1,
51
- maximum: MAX_LIMIT,
52
- default: DEFAULT_LIMIT,
53
- description: "Max events to return (1..200).",
54
- },
55
- type_filter: {
56
- type: "string",
57
- enum: ["ingest", "search", "kg", "crystallize", "op_audit", "all"],
58
- default: "all",
59
- description: "Restrict by event type.",
60
- },
61
- },
62
- additionalProperties: false,
63
- },
64
- };
@@ -1,2 +0,0 @@
1
- #!/usr/bin/env node
2
- export {};
package/dist/metrics.d.ts DELETED
@@ -1,3 +0,0 @@
1
- export declare function ensureMetricsTable(): void;
2
- export declare function incrementMetric(metric: string, amount?: number): void;
3
- export declare function getMetrics(days?: number): string;
@@ -1,18 +0,0 @@
1
- import Database from "better-sqlite3";
2
- /**
3
- * Returns true if `text` is considered noise (not worth sending to LLM).
4
- */
5
- export declare function isNoise(text: string, db?: Database.Database): boolean;
6
- /**
7
- * Add a learned prototype (when LLM returns zero results from a short text).
8
- * Max 200 learned (non-builtin) prototypes to avoid unbounded growth.
9
- */
10
- export declare function learnNoise(text: string, db?: Database.Database): void;
11
- /**
12
- * Get stats about the noise filter.
13
- */
14
- export declare function getNoiseStats(db?: Database.Database): {
15
- builtin: number;
16
- learned: number;
17
- totalHits: number;
18
- };
@@ -1,7 +0,0 @@
1
- import type { NotionItem } from "./consolidate.js";
2
- export declare function saveSyncLog(items: NotionItem[]): void;
3
- export declare function loadSyncLog(): NotionItem[];
4
- export declare function syncToNotion(items: NotionItem[]): Promise<{
5
- synced: number;
6
- failed: number;
7
- }>;
@@ -1,97 +0,0 @@
1
- import { readFileSync, writeFileSync, existsSync } from "fs";
2
- import { resolve, dirname } from "path";
3
- import { fileURLToPath } from "url";
4
- const __dirname = dirname(fileURLToPath(import.meta.url));
5
- const NOTION_API = "https://api.notion.com/v1/pages";
6
- const NOTION_VERSION = "2025-09-03";
7
- const DATABASE_ID = "31d8e29911ab8163b718d7af565f2fcc";
8
- const SYNC_LOG_PATH = resolve(__dirname, "..", "last-sync.json");
9
- function getNotionToken() {
10
- // Token can also be supplied directly via NOX_NOTION_TOKEN env var
11
- if (process.env.NOX_NOTION_TOKEN)
12
- return process.env.NOX_NOTION_TOKEN.trim();
13
- const tokenPath = process.env.NOX_NOTION_TOKEN_PATH ?? "/root/.config/notion/api_key";
14
- try {
15
- return readFileSync(tokenPath, "utf-8").trim();
16
- }
17
- catch {
18
- console.error(`[WARN] Notion token not found at ${tokenPath} (set NOX_NOTION_TOKEN or NOX_NOTION_TOKEN_PATH)`);
19
- return null;
20
- }
21
- }
22
- async function createNotionPage(token, item) {
23
- try {
24
- const body = {
25
- parent: { database_id: DATABASE_ID },
26
- properties: {
27
- "Título": { title: [{ text: { content: item.title.substring(0, 100) } }] },
28
- "Data": { date: { start: item.date } },
29
- "Categoria": { select: { name: item.category } },
30
- "Conteúdo": { rich_text: [{ text: { content: item.content.substring(0, 2000) } }] },
31
- "Fonte": { rich_text: [{ text: { content: item.source } }] },
32
- },
33
- };
34
- const response = await fetch(NOTION_API, {
35
- method: "POST",
36
- headers: {
37
- Authorization: `Bearer ${token}`,
38
- "Content-Type": "application/json",
39
- "Notion-Version": NOTION_VERSION,
40
- },
41
- body: JSON.stringify(body),
42
- signal: AbortSignal.timeout(10_000),
43
- });
44
- if (!response.ok) {
45
- const err = await response.text();
46
- console.error(`[WARN] Notion API ${response.status}: ${err.substring(0, 200)}`);
47
- return false;
48
- }
49
- return true;
50
- }
51
- catch (err) {
52
- console.error(`[WARN] Notion sync failed: ${err instanceof Error ? err.message : err}`);
53
- return false;
54
- }
55
- }
56
- function sleep(ms) {
57
- return new Promise((resolve) => setTimeout(resolve, ms));
58
- }
59
- // Save items to log for manual sync-notion command
60
- export function saveSyncLog(items) {
61
- writeFileSync(SYNC_LOG_PATH, JSON.stringify(items, null, 2), "utf-8");
62
- }
63
- // Load items from last consolidation for manual sync
64
- export function loadSyncLog() {
65
- if (!existsSync(SYNC_LOG_PATH))
66
- return [];
67
- try {
68
- return JSON.parse(readFileSync(SYNC_LOG_PATH, "utf-8"));
69
- }
70
- catch {
71
- return [];
72
- }
73
- }
74
- export async function syncToNotion(items) {
75
- if (items.length === 0)
76
- return { synced: 0, failed: 0 };
77
- // Save items for manual re-sync
78
- saveSyncLog(items);
79
- const token = getNotionToken();
80
- if (!token)
81
- return { synced: 0, failed: items.length };
82
- let synced = 0;
83
- let failed = 0;
84
- for (const item of items) {
85
- const ok = await createNotionPage(token, item);
86
- if (ok) {
87
- synced++;
88
- console.log(`[INFO] Notion: "${item.title.substring(0, 50)}..." → ${item.category}`);
89
- }
90
- else {
91
- failed++;
92
- }
93
- await sleep(350); // Rate limit ~3 req/s
94
- }
95
- console.log(`[INFO] Notion sync: ${synced} synced, ${failed} failed`);
96
- return { synced, failed };
97
- }
@@ -1,63 +0,0 @@
1
- /**
2
- * src/observability/adapters/a3-adapter.ts — Provider call instrumentation.
3
- *
4
- * Wraps any provider call (LLM or embedding) with:
5
- * - nox_provider_calls_total{provider, model, outcome}
6
- * - nox_provider_duration_seconds{provider, kind}
7
- * - nox_provider_cost_usd_total{provider, model}
8
- * - nox_provider_tokens_total{provider, direction}
9
- *
10
- * Composes with the existing `provider_telemetry` write path (kept intact).
11
- * Metrics are *live* per-call; telemetry is durable per-row.
12
- *
13
- * Wiring example (in src/providers/llm/chain.ts):
14
- *
15
- * import { instrumentProviderCall } from "../observability/adapters/a3-adapter.js";
16
- *
17
- * const result = await instrumentProviderCall(
18
- * { provider: "gemini", model: "gemini-2.5-flash-lite", kind: "llm" },
19
- * () => callGeminiAPI(prompt),
20
- * );
21
- *
22
- * `instrumentProviderCall` returns the inner result + a `metricsCost` field
23
- * for the caller to inspect.
24
- */
25
- import { type ProviderKind, type ProviderOutcome } from "../record.js";
26
- export interface ProviderCallMeta {
27
- provider: string;
28
- model: string;
29
- kind: ProviderKind;
30
- }
31
- export interface ProviderCallResult<T> {
32
- result: T;
33
- costUsd?: number;
34
- tokensIn?: number;
35
- tokensOut?: number;
36
- }
37
- export type ProviderInner<T> = () => Promise<ProviderCallResult<T>>;
38
- /**
39
- * Run an inner provider call. Always emits metrics, regardless of success.
40
- * Errors propagate; the outcome label maps to:
41
- * - "rate_limit" if err.status === 429
42
- * - "fallback" if err.code === "FALLBACK"
43
- * - "error" otherwise
44
- */
45
- export declare function instrumentProviderCall<T>(meta: ProviderCallMeta, inner: ProviderInner<T>): Promise<T>;
46
- export declare function classifyProviderError(err: unknown): ProviderOutcome;
47
- /**
48
- * Example — adding metrics to an existing provider call:
49
- *
50
- * // before:
51
- * const out = await callGemini(input);
52
- *
53
- * // after:
54
- * const out = await instrumentProviderCall(
55
- * { provider: "gemini", model, kind: "llm" },
56
- * async () => {
57
- * const r = await callGemini(input);
58
- * return { result: r, tokensIn: r.usage.in, tokensOut: r.usage.out, costUsd: estimateCost(r) };
59
- * },
60
- * );
61
- *
62
- * Total integration footprint: 1 import + 3-4 LOC at the call site.
63
- */
@@ -1,83 +0,0 @@
1
- /**
2
- * src/observability/adapters/a3-adapter.ts — Provider call instrumentation.
3
- *
4
- * Wraps any provider call (LLM or embedding) with:
5
- * - nox_provider_calls_total{provider, model, outcome}
6
- * - nox_provider_duration_seconds{provider, kind}
7
- * - nox_provider_cost_usd_total{provider, model}
8
- * - nox_provider_tokens_total{provider, direction}
9
- *
10
- * Composes with the existing `provider_telemetry` write path (kept intact).
11
- * Metrics are *live* per-call; telemetry is durable per-row.
12
- *
13
- * Wiring example (in src/providers/llm/chain.ts):
14
- *
15
- * import { instrumentProviderCall } from "../observability/adapters/a3-adapter.js";
16
- *
17
- * const result = await instrumentProviderCall(
18
- * { provider: "gemini", model: "gemini-2.5-flash-lite", kind: "llm" },
19
- * () => callGeminiAPI(prompt),
20
- * );
21
- *
22
- * `instrumentProviderCall` returns the inner result + a `metricsCost` field
23
- * for the caller to inspect.
24
- */
25
- import { recordProviderCall, startTimer } from "../record.js";
26
- /**
27
- * Run an inner provider call. Always emits metrics, regardless of success.
28
- * Errors propagate; the outcome label maps to:
29
- * - "rate_limit" if err.status === 429
30
- * - "fallback" if err.code === "FALLBACK"
31
- * - "error" otherwise
32
- */
33
- export async function instrumentProviderCall(meta, inner) {
34
- const end = startTimer();
35
- try {
36
- const { result, costUsd, tokensIn, tokensOut } = await inner();
37
- recordProviderCall({
38
- ...meta,
39
- outcome: "success",
40
- durationSeconds: end(),
41
- costUsd,
42
- tokensIn,
43
- tokensOut,
44
- });
45
- return result;
46
- }
47
- catch (err) {
48
- const outcome = classifyProviderError(err);
49
- recordProviderCall({
50
- ...meta,
51
- outcome,
52
- durationSeconds: end(),
53
- });
54
- throw err;
55
- }
56
- }
57
- export function classifyProviderError(err) {
58
- if (!err || typeof err !== "object")
59
- return "error";
60
- const e = err;
61
- if (e.status === 429)
62
- return "rate_limit";
63
- if (e.code === "FALLBACK" || e.code === "PROVIDER_FALLBACK")
64
- return "fallback";
65
- return "error";
66
- }
67
- /**
68
- * Example — adding metrics to an existing provider call:
69
- *
70
- * // before:
71
- * const out = await callGemini(input);
72
- *
73
- * // after:
74
- * const out = await instrumentProviderCall(
75
- * { provider: "gemini", model, kind: "llm" },
76
- * async () => {
77
- * const r = await callGemini(input);
78
- * return { result: r, tokensIn: r.usage.in, tokensOut: r.usage.out, costUsd: estimateCost(r) };
79
- * },
80
- * );
81
- *
82
- * Total integration footprint: 1 import + 3-4 LOC at the call site.
83
- */
@@ -1,49 +0,0 @@
1
- /**
2
- * src/observability/adapters/p1-adapter.ts — P1 /api/answer instrumentation.
3
- *
4
- * Wraps the answer handler so every call emits:
5
- * - nox_answer_requests_total{failure_reason}
6
- * - nox_answer_duration_seconds{phase}
7
- * - nox_answer_tokens_total{direction}
8
- *
9
- * Wiring example (in src/api/answer.ts):
10
- *
11
- * import { withAnswerMetrics } from "../observability/adapters/p1-adapter.js";
12
- *
13
- * export const answerHandler = withAnswerMetrics(async (req, res) => {
14
- * // … existing logic
15
- * return { outcome: "success", tokensIn, tokensOut, phases };
16
- * });
17
- *
18
- * The wrapper expects the inner handler to return an `AnswerOutcome` object.
19
- * That keeps metrics emission *external* to business logic — easy to unit
20
- * test, easy to remove.
21
- */
22
- import { type AnswerOutcome, type AnswerTiming } from "../record.js";
23
- export interface AnswerResult {
24
- outcome: AnswerOutcome;
25
- tokensIn?: number;
26
- tokensOut?: number;
27
- timing?: AnswerTiming;
28
- }
29
- export type AnswerHandler<Args extends unknown[]> = (...args: Args) => Promise<AnswerResult>;
30
- /**
31
- * Wrap an answer handler so it emits metrics on every call.
32
- * The wrapped handler returns the same `AnswerResult` so callers can keep
33
- * threading metadata to upstream layers.
34
- *
35
- * The wrapper never swallows the inner handler's errors — it just emits a
36
- * "llm_failed" metric and re-throws.
37
- */
38
- export declare function withAnswerMetrics<Args extends unknown[]>(inner: AnswerHandler<Args>): AnswerHandler<Args>;
39
- /**
40
- * Example — replace the existing /api/answer registration:
41
- *
42
- * // before:
43
- * app.get("/api/answer", answerHandler);
44
- *
45
- * // after:
46
- * app.get("/api/answer", withAnswerMetrics(answerHandler));
47
- *
48
- * Total integration footprint: 1 import + 1 wrapping call.
49
- */