@wirecat/cli-core 0.270.0 → 0.271.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 (639) hide show
  1. package/dist/cli/bot/admins.d.ts.map +1 -1
  2. package/dist/cli/bot/admins.js +5 -5
  3. package/dist/cli/bot/admins.js.map +1 -1
  4. package/dist/cli/bot/api.d.ts.map +1 -1
  5. package/dist/cli/bot/api.js +5 -1
  6. package/dist/cli/bot/api.js.map +1 -1
  7. package/dist/cli/bot/command.d.ts.map +1 -1
  8. package/dist/cli/bot/command.js +15 -18
  9. package/dist/cli/bot/command.js.map +1 -1
  10. package/dist/cli/bot/mcp.d.ts.map +1 -1
  11. package/dist/cli/bot/mcp.js +4 -2
  12. package/dist/cli/bot/mcp.js.map +1 -1
  13. package/dist/cli/bot/messages.d.ts.map +1 -1
  14. package/dist/cli/bot/messages.js +7 -6
  15. package/dist/cli/bot/messages.js.map +1 -1
  16. package/dist/cli/bot/moderation.d.ts.map +1 -1
  17. package/dist/cli/bot/moderation.js +5 -5
  18. package/dist/cli/bot/moderation.js.map +1 -1
  19. package/dist/cli/bot/people.d.ts.map +1 -1
  20. package/dist/cli/bot/people.js +6 -4
  21. package/dist/cli/bot/people.js.map +1 -1
  22. package/dist/cli/bot/port.d.ts +1 -1
  23. package/dist/cli/bot/port.d.ts.map +1 -1
  24. package/dist/cli/bot/setup.d.ts.map +1 -1
  25. package/dist/cli/bot/setup.js +8 -9
  26. package/dist/cli/bot/setup.js.map +1 -1
  27. package/dist/cli/bot/store.d.ts.map +1 -1
  28. package/dist/cli/bot/store.js +3 -2
  29. package/dist/cli/bot/store.js.map +1 -1
  30. package/dist/cli/bot/watch.d.ts.map +1 -1
  31. package/dist/cli/bot/watch.js +3 -1
  32. package/dist/cli/bot/watch.js.map +1 -1
  33. package/dist/cli/command-contract.d.ts +2 -2
  34. package/dist/cli/command-contract.d.ts.map +1 -1
  35. package/dist/cli/command-contract.js +2 -4
  36. package/dist/cli/command-contract.js.map +1 -1
  37. package/dist/cli/commands-command.d.ts +1 -1
  38. package/dist/cli/commands-command.d.ts.map +1 -1
  39. package/dist/cli/commands-command.js +8 -7
  40. package/dist/cli/commands-command.js.map +1 -1
  41. package/dist/cli/config-command.d.ts.map +1 -1
  42. package/dist/cli/config-command.js +4 -4
  43. package/dist/cli/config-command.js.map +1 -1
  44. package/dist/cli/effects.d.ts +20 -0
  45. package/dist/cli/effects.d.ts.map +1 -0
  46. package/dist/cli/effects.js +28 -0
  47. package/dist/cli/effects.js.map +1 -0
  48. package/dist/cli/envelope.d.ts +68 -23
  49. package/dist/cli/envelope.d.ts.map +1 -1
  50. package/dist/cli/envelope.js +36 -10
  51. package/dist/cli/envelope.js.map +1 -1
  52. package/dist/cli/index.d.ts +7 -4
  53. package/dist/cli/index.d.ts.map +1 -1
  54. package/dist/cli/index.js +6 -3
  55. package/dist/cli/index.js.map +1 -1
  56. package/dist/cli/messenger/account-command.d.ts.map +1 -1
  57. package/dist/cli/messenger/account-command.js +4 -3
  58. package/dist/cli/messenger/account-command.js.map +1 -1
  59. package/dist/cli/messenger/account-sessions-command.d.ts.map +1 -1
  60. package/dist/cli/messenger/account-sessions-command.js +4 -3
  61. package/dist/cli/messenger/account-sessions-command.js.map +1 -1
  62. package/dist/cli/messenger/admin-commands.d.ts.map +1 -1
  63. package/dist/cli/messenger/admin-commands.js +15 -15
  64. package/dist/cli/messenger/admin-commands.js.map +1 -1
  65. package/dist/cli/messenger/admin-contacts-command.d.ts.map +1 -1
  66. package/dist/cli/messenger/admin-contacts-command.js +4 -3
  67. package/dist/cli/messenger/admin-contacts-command.js.map +1 -1
  68. package/dist/cli/messenger/admin-folders-command.d.ts.map +1 -1
  69. package/dist/cli/messenger/admin-folders-command.js +8 -7
  70. package/dist/cli/messenger/admin-folders-command.js.map +1 -1
  71. package/dist/cli/messenger/admin-moderation-command.d.ts.map +1 -1
  72. package/dist/cli/messenger/admin-moderation-command.js +5 -5
  73. package/dist/cli/messenger/admin-moderation-command.js.map +1 -1
  74. package/dist/cli/messenger/admin-statistics-command.d.ts.map +1 -1
  75. package/dist/cli/messenger/admin-statistics-command.js +5 -1
  76. package/dist/cli/messenger/admin-statistics-command.js.map +1 -1
  77. package/dist/cli/messenger/archive-commands.d.ts.map +1 -1
  78. package/dist/cli/messenger/archive-commands.js +5 -3
  79. package/dist/cli/messenger/archive-commands.js.map +1 -1
  80. package/dist/cli/messenger/attachments-command.d.ts.map +1 -1
  81. package/dist/cli/messenger/attachments-command.js +6 -5
  82. package/dist/cli/messenger/attachments-command.js.map +1 -1
  83. package/dist/cli/messenger/backfill-command.d.ts.map +1 -1
  84. package/dist/cli/messenger/backfill-command.js +7 -9
  85. package/dist/cli/messenger/backfill-command.js.map +1 -1
  86. package/dist/cli/messenger/chats-bots-command.d.ts.map +1 -1
  87. package/dist/cli/messenger/chats-bots-command.js +3 -2
  88. package/dist/cli/messenger/chats-bots-command.js.map +1 -1
  89. package/dist/cli/messenger/chats-command.d.ts.map +1 -1
  90. package/dist/cli/messenger/chats-command.js +6 -7
  91. package/dist/cli/messenger/chats-command.js.map +1 -1
  92. package/dist/cli/messenger/chats-documents-command.d.ts.map +1 -1
  93. package/dist/cli/messenger/chats-documents-command.js +3 -1
  94. package/dist/cli/messenger/chats-documents-command.js.map +1 -1
  95. package/dist/cli/messenger/chats-members-command.d.ts.map +1 -1
  96. package/dist/cli/messenger/chats-members-command.js +7 -6
  97. package/dist/cli/messenger/chats-members-command.js.map +1 -1
  98. package/dist/cli/messenger/chats-read-command.d.ts.map +1 -1
  99. package/dist/cli/messenger/chats-read-command.js +2 -1
  100. package/dist/cli/messenger/chats-read-command.js.map +1 -1
  101. package/dist/cli/messenger/chats-stats-command.d.ts.map +1 -1
  102. package/dist/cli/messenger/chats-stats-command.js +2 -1
  103. package/dist/cli/messenger/chats-stats-command.js.map +1 -1
  104. package/dist/cli/messenger/chats-tracking-command.d.ts.map +1 -1
  105. package/dist/cli/messenger/chats-tracking-command.js +5 -6
  106. package/dist/cli/messenger/chats-tracking-command.js.map +1 -1
  107. package/dist/cli/messenger/complete-command.d.ts.map +1 -1
  108. package/dist/cli/messenger/complete-command.js +3 -2
  109. package/dist/cli/messenger/complete-command.js.map +1 -1
  110. package/dist/cli/messenger/contacts-command.d.ts.map +1 -1
  111. package/dist/cli/messenger/contacts-command.js +12 -18
  112. package/dist/cli/messenger/contacts-command.js.map +1 -1
  113. package/dist/cli/messenger/context.d.ts +1 -1
  114. package/dist/cli/messenger/context.d.ts.map +1 -1
  115. package/dist/cli/messenger/context.js.map +1 -1
  116. package/dist/cli/messenger/conversations-command.d.ts.map +1 -1
  117. package/dist/cli/messenger/conversations-command.js +19 -29
  118. package/dist/cli/messenger/conversations-command.js.map +1 -1
  119. package/dist/cli/messenger/counters-command.d.ts.map +1 -1
  120. package/dist/cli/messenger/counters-command.js +3 -2
  121. package/dist/cli/messenger/counters-command.js.map +1 -1
  122. package/dist/cli/messenger/doctor-command.d.ts.map +1 -1
  123. package/dist/cli/messenger/doctor-command.js +7 -4
  124. package/dist/cli/messenger/doctor-command.js.map +1 -1
  125. package/dist/cli/messenger/download-command.d.ts.map +1 -1
  126. package/dist/cli/messenger/download-command.js +3 -2
  127. package/dist/cli/messenger/download-command.js.map +1 -1
  128. package/dist/cli/messenger/flood-command.d.ts.map +1 -1
  129. package/dist/cli/messenger/flood-command.js +3 -1
  130. package/dist/cli/messenger/flood-command.js.map +1 -1
  131. package/dist/cli/messenger/flooded.d.ts +1 -1
  132. package/dist/cli/messenger/flooded.d.ts.map +1 -1
  133. package/dist/cli/messenger/flooded.js +1 -1
  134. package/dist/cli/messenger/flooded.js.map +1 -1
  135. package/dist/cli/messenger/gaps-command.d.ts.map +1 -1
  136. package/dist/cli/messenger/gaps-command.js +4 -4
  137. package/dist/cli/messenger/gaps-command.js.map +1 -1
  138. package/dist/cli/messenger/guard-commands.d.ts.map +1 -1
  139. package/dist/cli/messenger/guard-commands.js +6 -6
  140. package/dist/cli/messenger/guard-commands.js.map +1 -1
  141. package/dist/cli/messenger/images-command.d.ts.map +1 -1
  142. package/dist/cli/messenger/images-command.js +3 -2
  143. package/dist/cli/messenger/images-command.js.map +1 -1
  144. package/dist/cli/messenger/inbox.d.ts.map +1 -1
  145. package/dist/cli/messenger/inbox.js +6 -1
  146. package/dist/cli/messenger/inbox.js.map +1 -1
  147. package/dist/cli/messenger/mcp-command.d.ts.map +1 -1
  148. package/dist/cli/messenger/mcp-command.js +5 -4
  149. package/dist/cli/messenger/mcp-command.js.map +1 -1
  150. package/dist/cli/messenger/mentions-command.d.ts.map +1 -1
  151. package/dist/cli/messenger/mentions-command.js +23 -11
  152. package/dist/cli/messenger/mentions-command.js.map +1 -1
  153. package/dist/cli/messenger/message-items.d.ts +1 -1
  154. package/dist/cli/messenger/message-items.d.ts.map +1 -1
  155. package/dist/cli/messenger/message-writes.d.ts +5 -6
  156. package/dist/cli/messenger/message-writes.d.ts.map +1 -1
  157. package/dist/cli/messenger/message-writes.js +7 -8
  158. package/dist/cli/messenger/message-writes.js.map +1 -1
  159. package/dist/cli/messenger/messages-command.d.ts.map +1 -1
  160. package/dist/cli/messenger/messages-command.js +5 -5
  161. package/dist/cli/messenger/messages-command.js.map +1 -1
  162. package/dist/cli/messenger/messages-comments-command.d.ts.map +1 -1
  163. package/dist/cli/messenger/messages-comments-command.js +3 -1
  164. package/dist/cli/messenger/messages-comments-command.js.map +1 -1
  165. package/dist/cli/messenger/messages-delete-command.d.ts.map +1 -1
  166. package/dist/cli/messenger/messages-delete-command.js +2 -1
  167. package/dist/cli/messenger/messages-delete-command.js.map +1 -1
  168. package/dist/cli/messenger/messages-edit-command.d.ts.map +1 -1
  169. package/dist/cli/messenger/messages-edit-command.js +2 -1
  170. package/dist/cli/messenger/messages-edit-command.js.map +1 -1
  171. package/dist/cli/messenger/messages-evidence-command.d.ts.map +1 -1
  172. package/dist/cli/messenger/messages-evidence-command.js +3 -1
  173. package/dist/cli/messenger/messages-evidence-command.js.map +1 -1
  174. package/dist/cli/messenger/messages-forward-command.d.ts.map +1 -1
  175. package/dist/cli/messenger/messages-forward-command.js +4 -3
  176. package/dist/cli/messenger/messages-forward-command.js.map +1 -1
  177. package/dist/cli/messenger/messages-link-command.d.ts.map +1 -1
  178. package/dist/cli/messenger/messages-link-command.js +2 -1
  179. package/dist/cli/messenger/messages-link-command.js.map +1 -1
  180. package/dist/cli/messenger/messages-pin-command.d.ts.map +1 -1
  181. package/dist/cli/messenger/messages-pin-command.js +3 -2
  182. package/dist/cli/messenger/messages-pin-command.js.map +1 -1
  183. package/dist/cli/messenger/messages-press-command.d.ts.map +1 -1
  184. package/dist/cli/messenger/messages-press-command.js +2 -1
  185. package/dist/cli/messenger/messages-press-command.js.map +1 -1
  186. package/dist/cli/messenger/messages-scheduled-command.d.ts.map +1 -1
  187. package/dist/cli/messenger/messages-scheduled-command.js +3 -2
  188. package/dist/cli/messenger/messages-scheduled-command.js.map +1 -1
  189. package/dist/cli/messenger/messages-search-command.d.ts.map +1 -1
  190. package/dist/cli/messenger/messages-search-command.js +3 -0
  191. package/dist/cli/messenger/messages-search-command.js.map +1 -1
  192. package/dist/cli/messenger/messages-send-command.d.ts.map +1 -1
  193. package/dist/cli/messenger/messages-send-command.js +4 -3
  194. package/dist/cli/messenger/messages-send-command.js.map +1 -1
  195. package/dist/cli/messenger/messages-stats-command.d.ts.map +1 -1
  196. package/dist/cli/messenger/messages-stats-command.js +2 -1
  197. package/dist/cli/messenger/messages-stats-command.js.map +1 -1
  198. package/dist/cli/messenger/metadata-command.d.ts.map +1 -1
  199. package/dist/cli/messenger/metadata-command.js +3 -3
  200. package/dist/cli/messenger/metadata-command.js.map +1 -1
  201. package/dist/cli/messenger/models-command.d.ts.map +1 -1
  202. package/dist/cli/messenger/models-command.js +9 -9
  203. package/dist/cli/messenger/models-command.js.map +1 -1
  204. package/dist/cli/messenger/observed.d.ts +1 -1
  205. package/dist/cli/messenger/observed.d.ts.map +1 -1
  206. package/dist/cli/messenger/observed.js +1 -1
  207. package/dist/cli/messenger/observed.js.map +1 -1
  208. package/dist/cli/messenger/official-stats-command.d.ts.map +1 -1
  209. package/dist/cli/messenger/official-stats-command.js +3 -2
  210. package/dist/cli/messenger/official-stats-command.js.map +1 -1
  211. package/dist/cli/messenger/polls-command.d.ts.map +1 -1
  212. package/dist/cli/messenger/polls-command.js +9 -9
  213. package/dist/cli/messenger/polls-command.js.map +1 -1
  214. package/dist/cli/messenger/private-people-command.d.ts.map +1 -1
  215. package/dist/cli/messenger/private-people-command.js +10 -6
  216. package/dist/cli/messenger/private-people-command.js.map +1 -1
  217. package/dist/cli/messenger/rankings-command.d.ts.map +1 -1
  218. package/dist/cli/messenger/rankings-command.js +3 -2
  219. package/dist/cli/messenger/rankings-command.js.map +1 -1
  220. package/dist/cli/messenger/reactions-command.d.ts.map +1 -1
  221. package/dist/cli/messenger/reactions-command.js +3 -2
  222. package/dist/cli/messenger/reactions-command.js.map +1 -1
  223. package/dist/cli/messenger/records-command.d.ts.map +1 -1
  224. package/dist/cli/messenger/records-command.js +12 -13
  225. package/dist/cli/messenger/records-command.js.map +1 -1
  226. package/dist/cli/messenger/replies-command.d.ts.map +1 -1
  227. package/dist/cli/messenger/replies-command.js +8 -7
  228. package/dist/cli/messenger/replies-command.js.map +1 -1
  229. package/dist/cli/messenger/replies-consents-command.d.ts.map +1 -1
  230. package/dist/cli/messenger/replies-consents-command.js +4 -4
  231. package/dist/cli/messenger/replies-consents-command.js.map +1 -1
  232. package/dist/cli/messenger/replies-edit-command.d.ts.map +1 -1
  233. package/dist/cli/messenger/replies-edit-command.js +5 -4
  234. package/dist/cli/messenger/replies-edit-command.js.map +1 -1
  235. package/dist/cli/messenger/retention-command.d.ts.map +1 -1
  236. package/dist/cli/messenger/retention-command.js +2 -1
  237. package/dist/cli/messenger/retention-command.js.map +1 -1
  238. package/dist/cli/messenger/review.d.ts.map +1 -1
  239. package/dist/cli/messenger/review.js +6 -1
  240. package/dist/cli/messenger/review.js.map +1 -1
  241. package/dist/cli/messenger/schedule-command.d.ts.map +1 -1
  242. package/dist/cli/messenger/schedule-command.js +8 -12
  243. package/dist/cli/messenger/schedule-command.js.map +1 -1
  244. package/dist/cli/messenger/search-answers.d.ts +1 -1
  245. package/dist/cli/messenger/search-answers.d.ts.map +1 -1
  246. package/dist/cli/messenger/search-answers.js +5 -3
  247. package/dist/cli/messenger/search-answers.js.map +1 -1
  248. package/dist/cli/messenger/search-command.d.ts.map +1 -1
  249. package/dist/cli/messenger/search-command.js +3 -2
  250. package/dist/cli/messenger/search-command.js.map +1 -1
  251. package/dist/cli/messenger/searches-command.d.ts.map +1 -1
  252. package/dist/cli/messenger/searches-command.js +9 -7
  253. package/dist/cli/messenger/searches-command.js.map +1 -1
  254. package/dist/cli/messenger/serve-command.d.ts.map +1 -1
  255. package/dist/cli/messenger/serve-command.js +3 -1
  256. package/dist/cli/messenger/serve-command.js.map +1 -1
  257. package/dist/cli/messenger/serve-notice.js +5 -5
  258. package/dist/cli/messenger/serve-notice.js.map +1 -1
  259. package/dist/cli/messenger/server-command.d.ts.map +1 -1
  260. package/dist/cli/messenger/server-command.js +9 -14
  261. package/dist/cli/messenger/server-command.js.map +1 -1
  262. package/dist/cli/messenger/stats-answers.d.ts.map +1 -1
  263. package/dist/cli/messenger/stats-answers.js +1 -0
  264. package/dist/cli/messenger/stats-answers.js.map +1 -1
  265. package/dist/cli/messenger/stats-command.d.ts.map +1 -1
  266. package/dist/cli/messenger/stats-command.js +2 -1
  267. package/dist/cli/messenger/stats-command.js.map +1 -1
  268. package/dist/cli/messenger/store-maintenance-command.d.ts.map +1 -1
  269. package/dist/cli/messenger/store-maintenance-command.js +12 -10
  270. package/dist/cli/messenger/store-maintenance-command.js.map +1 -1
  271. package/dist/cli/messenger/stored.d.ts +1 -1
  272. package/dist/cli/messenger/stored.d.ts.map +1 -1
  273. package/dist/cli/messenger/stored.js +1 -1
  274. package/dist/cli/messenger/stored.js.map +1 -1
  275. package/dist/cli/messenger/tags-command.d.ts.map +1 -1
  276. package/dist/cli/messenger/tags-command.js +5 -6
  277. package/dist/cli/messenger/tags-command.js.map +1 -1
  278. package/dist/cli/messenger/tasks-command.d.ts.map +1 -1
  279. package/dist/cli/messenger/tasks-command.js +9 -15
  280. package/dist/cli/messenger/tasks-command.js.map +1 -1
  281. package/dist/cli/messenger/topics-command.d.ts.map +1 -1
  282. package/dist/cli/messenger/topics-command.js +12 -12
  283. package/dist/cli/messenger/topics-command.js.map +1 -1
  284. package/dist/cli/messenger/transcribe-command.d.ts.map +1 -1
  285. package/dist/cli/messenger/transcribe-command.js +3 -2
  286. package/dist/cli/messenger/transcribe-command.js.map +1 -1
  287. package/dist/cli/messenger/watch-command.d.ts +1 -1
  288. package/dist/cli/messenger/watch-command.d.ts.map +1 -1
  289. package/dist/cli/messenger/watch-command.js +3 -1
  290. package/dist/cli/messenger/watch-command.js.map +1 -1
  291. package/dist/cli/preview.d.ts.map +1 -1
  292. package/dist/cli/preview.js +3 -1
  293. package/dist/cli/preview.js.map +1 -1
  294. package/dist/cli/program.d.ts.map +1 -1
  295. package/dist/cli/program.js +10 -2
  296. package/dist/cli/program.js.map +1 -1
  297. package/dist/cli/reasons.d.ts +1 -1
  298. package/dist/cli/reasons.d.ts.map +1 -1
  299. package/dist/cli/reasons.js +2 -1
  300. package/dist/cli/reasons.js.map +1 -1
  301. package/dist/cli/runs/command.d.ts.map +1 -1
  302. package/dist/cli/runs/command.js +7 -9
  303. package/dist/cli/runs/command.js.map +1 -1
  304. package/dist/cli/runs/log-events.d.ts +10 -0
  305. package/dist/cli/runs/log-events.d.ts.map +1 -0
  306. package/dist/cli/runs/log-events.js +31 -0
  307. package/dist/cli/runs/log-events.js.map +1 -0
  308. package/dist/cli/runs/recording.d.ts +1 -1
  309. package/dist/cli/runs/recording.d.ts.map +1 -1
  310. package/dist/cli/runs/recording.js +6 -4
  311. package/dist/cli/runs/recording.js.map +1 -1
  312. package/dist/cli/runs/scope.d.ts +5 -0
  313. package/dist/cli/runs/scope.d.ts.map +1 -1
  314. package/dist/cli/runs/scope.js +7 -0
  315. package/dist/cli/runs/scope.js.map +1 -1
  316. package/dist/cli/skill-command.d.ts.map +1 -1
  317. package/dist/cli/skill-command.js +12 -4
  318. package/dist/cli/skill-command.js.map +1 -1
  319. package/dist/cli/steps.d.ts +21 -4
  320. package/dist/cli/steps.d.ts.map +1 -1
  321. package/dist/cli/steps.js +20 -4
  322. package/dist/cli/steps.js.map +1 -1
  323. package/dist/cli/upgrade-command.d.ts.map +1 -1
  324. package/dist/cli/upgrade-command.js +3 -1
  325. package/dist/cli/upgrade-command.js.map +1 -1
  326. package/dist/domain/calendar.d.ts +2 -0
  327. package/dist/domain/calendar.d.ts.map +1 -0
  328. package/dist/domain/calendar.js +14 -0
  329. package/dist/domain/calendar.js.map +1 -0
  330. package/dist/domain/mentions.d.ts +1 -1
  331. package/dist/domain/mentions.d.ts.map +1 -1
  332. package/dist/domain/mentions.js +8 -2
  333. package/dist/domain/mentions.js.map +1 -1
  334. package/dist/domain/person-names.d.ts +30 -0
  335. package/dist/domain/person-names.d.ts.map +1 -0
  336. package/dist/domain/person-names.js +120 -0
  337. package/dist/domain/person-names.js.map +1 -0
  338. package/dist/embeddings/models.d.ts +2 -0
  339. package/dist/embeddings/models.d.ts.map +1 -1
  340. package/dist/embeddings/models.js +2 -0
  341. package/dist/embeddings/models.js.map +1 -1
  342. package/dist/entities/index.d.ts +9 -3
  343. package/dist/entities/index.d.ts.map +1 -1
  344. package/dist/kit/contract.d.ts +1 -1
  345. package/dist/kit/contract.d.ts.map +1 -1
  346. package/dist/kit/contract.js +1 -1
  347. package/dist/kit/contract.js.map +1 -1
  348. package/dist/kit/fake.d.ts +1 -1
  349. package/dist/kit/fake.d.ts.map +1 -1
  350. package/dist/mcp/instructions.js +1 -1
  351. package/dist/mcp/instructions.js.map +1 -1
  352. package/dist/mcp/resources.js +1 -1
  353. package/dist/mcp/resources.js.map +1 -1
  354. package/dist/mcp/server.d.ts.map +1 -1
  355. package/dist/mcp/server.js +3 -0
  356. package/dist/mcp/server.js.map +1 -1
  357. package/dist/mcp/session.d.ts +1 -1
  358. package/dist/mcp/session.d.ts.map +1 -1
  359. package/dist/mcp/tool.d.ts +10 -3
  360. package/dist/mcp/tool.d.ts.map +1 -1
  361. package/dist/mcp/tool.js +24 -10
  362. package/dist/mcp/tool.js.map +1 -1
  363. package/dist/mcp/tools/account.js +1 -1
  364. package/dist/mcp/tools/account.js.map +1 -1
  365. package/dist/mcp/tools/admin.js.map +1 -1
  366. package/dist/mcp/tools/attachments.d.ts.map +1 -1
  367. package/dist/mcp/tools/attachments.js +2 -0
  368. package/dist/mcp/tools/attachments.js.map +1 -1
  369. package/dist/mcp/tools/contacts.d.ts.map +1 -1
  370. package/dist/mcp/tools/contacts.js +3 -2
  371. package/dist/mcp/tools/contacts.js.map +1 -1
  372. package/dist/mcp/tools/folders.js.map +1 -1
  373. package/dist/mcp/tools/messages-actions.js +3 -3
  374. package/dist/mcp/tools/messages-actions.js.map +1 -1
  375. package/dist/mcp/tools/messages-photo.js +1 -1
  376. package/dist/mcp/tools/messages-photo.js.map +1 -1
  377. package/dist/mcp/tools/messages-send.js +3 -3
  378. package/dist/mcp/tools/messages-send.js.map +1 -1
  379. package/dist/mcp/tools/messages.d.ts.map +1 -1
  380. package/dist/mcp/tools/messages.js +3 -1
  381. package/dist/mcp/tools/messages.js.map +1 -1
  382. package/dist/mcp/tools/polls.js +4 -4
  383. package/dist/mcp/tools/polls.js.map +1 -1
  384. package/dist/mcp/tools/rankings.js +1 -1
  385. package/dist/mcp/tools/rankings.js.map +1 -1
  386. package/dist/mcp/tools/search-tools.js +5 -5
  387. package/dist/mcp/tools/search-tools.js.map +1 -1
  388. package/dist/mcp/tools/search.d.ts.map +1 -1
  389. package/dist/mcp/tools/search.js +1 -1
  390. package/dist/mcp/tools/search.js.map +1 -1
  391. package/dist/mcp/tools/store.d.ts.map +1 -1
  392. package/dist/mcp/tools/store.js +2 -0
  393. package/dist/mcp/tools/store.js.map +1 -1
  394. package/dist/mcp/tools/topics.js +4 -4
  395. package/dist/mcp/tools/topics.js.map +1 -1
  396. package/dist/meetings/answers.d.ts +7 -2
  397. package/dist/meetings/answers.d.ts.map +1 -1
  398. package/dist/meetings/answers.js +7 -2
  399. package/dist/meetings/answers.js.map +1 -1
  400. package/dist/meetings/cli/passage.js +1 -1
  401. package/dist/meetings/cli/passage.js.map +1 -1
  402. package/dist/meetings/cli/project-evidence.js +1 -1
  403. package/dist/meetings/cli/project-evidence.js.map +1 -1
  404. package/dist/meetings/cli/search.d.ts.map +1 -1
  405. package/dist/meetings/cli/search.js +6 -2
  406. package/dist/meetings/cli/search.js.map +1 -1
  407. package/dist/meetings/mcp/index.d.ts +13 -2
  408. package/dist/meetings/mcp/index.d.ts.map +1 -1
  409. package/dist/meetings/mcp/index.js +1 -1
  410. package/dist/meetings/mcp/index.js.map +1 -1
  411. package/dist/meetings/mcp/passage.d.ts +13 -2
  412. package/dist/meetings/mcp/passage.d.ts.map +1 -1
  413. package/dist/meetings/mcp/passage.js +1 -1
  414. package/dist/meetings/mcp/passage.js.map +1 -1
  415. package/dist/meetings/mcp/project-evidence.d.ts +13 -2
  416. package/dist/meetings/mcp/project-evidence.d.ts.map +1 -1
  417. package/dist/meetings/mcp/project-evidence.js +1 -1
  418. package/dist/meetings/mcp/project-evidence.js.map +1 -1
  419. package/dist/meetings/mcp/search.d.ts +13 -2
  420. package/dist/meetings/mcp/search.d.ts.map +1 -1
  421. package/dist/meetings/mcp/search.js +1 -1
  422. package/dist/meetings/mcp/search.js.map +1 -1
  423. package/dist/meetings/project-evidence-answer.d.ts +9 -3
  424. package/dist/meetings/project-evidence-answer.d.ts.map +1 -1
  425. package/dist/meetings/project-evidence-answer.js +6 -1
  426. package/dist/meetings/project-evidence-answer.js.map +1 -1
  427. package/dist/meetings/reads.d.ts +11 -3
  428. package/dist/meetings/reads.d.ts.map +1 -1
  429. package/dist/meetings/reads.js +2 -2
  430. package/dist/meetings/reads.js.map +1 -1
  431. package/dist/moderation/check.d.ts +1 -1
  432. package/dist/moderation/check.d.ts.map +1 -1
  433. package/dist/parity/deep.js +1 -1
  434. package/dist/parity/manifest.js +1 -1
  435. package/dist/parity/manifest.js.map +1 -1
  436. package/dist/{cli/messenger/port.d.ts → ports/messenger.d.ts} +7 -7
  437. package/dist/ports/messenger.d.ts.map +1 -0
  438. package/dist/{cli/messenger/port.js → ports/messenger.js} +1 -1
  439. package/dist/ports/messenger.js.map +1 -0
  440. package/dist/search/account-list.d.ts +3 -0
  441. package/dist/search/account-list.d.ts.map +1 -1
  442. package/dist/search/account-list.js +3 -1
  443. package/dist/search/account-list.js.map +1 -1
  444. package/dist/search/lucene/registry.d.ts.map +1 -1
  445. package/dist/search/lucene/registry.js +15 -0
  446. package/dist/search/lucene/registry.js.map +1 -1
  447. package/dist/sends/buttons.d.ts +1 -1
  448. package/dist/sends/buttons.d.ts.map +1 -1
  449. package/dist/sends/buttons.js +1 -1
  450. package/dist/sends/buttons.js.map +1 -1
  451. package/dist/sends/guard.js +2 -2
  452. package/dist/sends/guard.js.map +1 -1
  453. package/dist/sends/guarded.d.ts.map +1 -1
  454. package/dist/sends/guarded.js +5 -2
  455. package/dist/sends/guarded.js.map +1 -1
  456. package/dist/sends/journal.d.ts.map +1 -1
  457. package/dist/sends/journal.js +7 -3
  458. package/dist/sends/journal.js.map +1 -1
  459. package/dist/sends/polls.d.ts +1 -1
  460. package/dist/sends/polls.d.ts.map +1 -1
  461. package/dist/sends/polls.js +1 -1
  462. package/dist/sends/polls.js.map +1 -1
  463. package/dist/sends/send-as.d.ts +1 -1
  464. package/dist/sends/send-as.d.ts.map +1 -1
  465. package/dist/sends/send-as.js +1 -1
  466. package/dist/sends/send-as.js.map +1 -1
  467. package/dist/services/account.d.ts +1 -1
  468. package/dist/services/account.d.ts.map +1 -1
  469. package/dist/services/account.js +1 -1
  470. package/dist/services/account.js.map +1 -1
  471. package/dist/services/admin-statistics.js +1 -1
  472. package/dist/services/admin-statistics.js.map +1 -1
  473. package/dist/services/admin.d.ts.map +1 -1
  474. package/dist/services/admin.js +1 -1
  475. package/dist/services/admin.js.map +1 -1
  476. package/dist/services/archive-gaps.js +1 -1
  477. package/dist/services/archive-gaps.js.map +1 -1
  478. package/dist/services/archive.d.ts.map +1 -1
  479. package/dist/services/archive.js +2 -2
  480. package/dist/services/archive.js.map +1 -1
  481. package/dist/services/attachments.js +1 -1
  482. package/dist/services/attachments.js.map +1 -1
  483. package/dist/services/chat-documents.js +1 -1
  484. package/dist/services/chat-documents.js.map +1 -1
  485. package/dist/services/chat-stats.d.ts.map +1 -1
  486. package/dist/services/chat-stats.js +2 -2
  487. package/dist/services/chat-stats.js.map +1 -1
  488. package/dist/services/chats.d.ts.map +1 -1
  489. package/dist/services/chats.js +2 -2
  490. package/dist/services/chats.js.map +1 -1
  491. package/dist/services/conversations.js +1 -1
  492. package/dist/services/conversations.js.map +1 -1
  493. package/dist/services/deps.d.ts +1 -1
  494. package/dist/services/deps.d.ts.map +1 -1
  495. package/dist/services/embeddings-maintenance.d.ts +51 -0
  496. package/dist/services/embeddings-maintenance.d.ts.map +1 -0
  497. package/dist/services/embeddings-maintenance.js +309 -0
  498. package/dist/services/embeddings-maintenance.js.map +1 -0
  499. package/dist/services/embeddings-search.d.ts +4 -0
  500. package/dist/services/embeddings-search.d.ts.map +1 -0
  501. package/dist/services/embeddings-search.js +329 -0
  502. package/dist/services/embeddings-search.js.map +1 -0
  503. package/dist/services/embeddings.d.ts +5 -12
  504. package/dist/services/embeddings.d.ts.map +1 -1
  505. package/dist/services/embeddings.js +7 -630
  506. package/dist/services/embeddings.js.map +1 -1
  507. package/dist/services/evidence-read.js +1 -1
  508. package/dist/services/evidence-read.js.map +1 -1
  509. package/dist/services/file-download.d.ts +1 -1
  510. package/dist/services/file-download.d.ts.map +1 -1
  511. package/dist/services/folders.d.ts.map +1 -1
  512. package/dist/services/folders.js +1 -1
  513. package/dist/services/folders.js.map +1 -1
  514. package/dist/services/inbox.d.ts +1 -2
  515. package/dist/services/inbox.d.ts.map +1 -1
  516. package/dist/services/inbox.js +2 -3
  517. package/dist/services/inbox.js.map +1 -1
  518. package/dist/services/index.d.ts +7 -3
  519. package/dist/services/index.d.ts.map +1 -1
  520. package/dist/services/index.js +5 -2
  521. package/dist/services/index.js.map +1 -1
  522. package/dist/services/meeting-model.d.ts +1 -1
  523. package/dist/services/meeting-model.d.ts.map +1 -1
  524. package/dist/services/meeting-model.js +1 -2
  525. package/dist/services/meeting-model.js.map +1 -1
  526. package/dist/services/mentions.d.ts +4 -0
  527. package/dist/services/mentions.d.ts.map +1 -1
  528. package/dist/services/mentions.js +2 -2
  529. package/dist/services/mentions.js.map +1 -1
  530. package/dist/services/message-query-validation.d.ts +3 -0
  531. package/dist/services/message-query-validation.d.ts.map +1 -0
  532. package/dist/services/message-query-validation.js +14 -0
  533. package/dist/services/message-query-validation.js.map +1 -0
  534. package/dist/services/message-resolution.d.ts +36 -0
  535. package/dist/services/message-resolution.d.ts.map +1 -0
  536. package/dist/services/message-resolution.js +171 -0
  537. package/dist/services/message-resolution.js.map +1 -0
  538. package/dist/services/messages-archive-search.d.ts +24 -0
  539. package/dist/services/messages-archive-search.d.ts.map +1 -0
  540. package/dist/services/messages-archive-search.js +123 -0
  541. package/dist/services/messages-archive-search.js.map +1 -0
  542. package/dist/services/messages-search.d.ts +1 -2
  543. package/dist/services/messages-search.d.ts.map +1 -1
  544. package/dist/services/messages-search.js +2 -14
  545. package/dist/services/messages-search.js.map +1 -1
  546. package/dist/services/messages.d.ts +5 -50
  547. package/dist/services/messages.d.ts.map +1 -1
  548. package/dist/services/messages.js +8 -302
  549. package/dist/services/messages.js.map +1 -1
  550. package/dist/services/metadata.js +2 -2
  551. package/dist/services/metadata.js.map +1 -1
  552. package/dist/services/moderation.d.ts.map +1 -1
  553. package/dist/services/moderation.js +1 -1
  554. package/dist/services/moderation.js.map +1 -1
  555. package/dist/services/notes-search.d.ts.map +1 -1
  556. package/dist/services/notes-search.js +1 -2
  557. package/dist/services/notes-search.js.map +1 -1
  558. package/dist/services/people.d.ts.map +1 -1
  559. package/dist/services/people.js +3 -3
  560. package/dist/services/people.js.map +1 -1
  561. package/dist/services/pictures.d.ts +1 -1
  562. package/dist/services/pictures.d.ts.map +1 -1
  563. package/dist/services/pictures.js +2 -2
  564. package/dist/services/pictures.js.map +1 -1
  565. package/dist/services/rankings.d.ts.map +1 -1
  566. package/dist/services/rankings.js +1 -1
  567. package/dist/services/rankings.js.map +1 -1
  568. package/dist/services/retention.d.ts +26 -26
  569. package/dist/services/retention.d.ts.map +1 -1
  570. package/dist/services/retention.js +1 -1
  571. package/dist/services/retention.js.map +1 -1
  572. package/dist/services/search-all-meetings.d.ts.map +1 -1
  573. package/dist/services/search-all-meetings.js +18 -5
  574. package/dist/services/search-all-meetings.js.map +1 -1
  575. package/dist/services/search-all.d.ts +6 -4
  576. package/dist/services/search-all.d.ts.map +1 -1
  577. package/dist/services/search-all.js +2 -2
  578. package/dist/services/search-all.js.map +1 -1
  579. package/dist/services/search-catchup.d.ts +1 -1
  580. package/dist/services/search-catchup.d.ts.map +1 -1
  581. package/dist/services/search-catchup.js +2 -2
  582. package/dist/services/search-catchup.js.map +1 -1
  583. package/dist/services/search-record.d.ts +29 -0
  584. package/dist/services/search-record.d.ts.map +1 -0
  585. package/dist/services/search-record.js +20 -0
  586. package/dist/services/search-record.js.map +1 -0
  587. package/dist/services/search-refresh.d.ts +1 -1
  588. package/dist/services/search-refresh.d.ts.map +1 -1
  589. package/dist/services/search-refresh.js +2 -1
  590. package/dist/services/search-refresh.js.map +1 -1
  591. package/dist/services/searches.d.ts +2 -27
  592. package/dist/services/searches.d.ts.map +1 -1
  593. package/dist/services/searches.js +3 -19
  594. package/dist/services/searches.js.map +1 -1
  595. package/dist/services/server-search.d.ts.map +1 -1
  596. package/dist/services/server-search.js +1 -1
  597. package/dist/services/server-search.js.map +1 -1
  598. package/dist/services/tags.js +1 -1
  599. package/dist/services/tags.js.map +1 -1
  600. package/dist/services/tasks.js +1 -1
  601. package/dist/services/tasks.js.map +1 -1
  602. package/dist/services/topics.d.ts +0 -1
  603. package/dist/services/topics.d.ts.map +1 -1
  604. package/dist/services/topics.js +2 -2
  605. package/dist/services/topics.js.map +1 -1
  606. package/dist/speech/hearing.d.ts +1 -1
  607. package/dist/speech/hearing.d.ts.map +1 -1
  608. package/dist/speech/transcribe.d.ts +1 -1
  609. package/dist/speech/transcribe.d.ts.map +1 -1
  610. package/dist/speech/transcribe.js +1 -1
  611. package/dist/speech/transcribe.js.map +1 -1
  612. package/dist/store/sqlite/lucene.d.ts.map +1 -1
  613. package/dist/store/sqlite/lucene.js +29 -0
  614. package/dist/store/sqlite/lucene.js.map +1 -1
  615. package/dist/store/sqlite/meeting-hit-index.js +1 -1
  616. package/dist/store/sqlite/meeting-hit-index.js.map +1 -1
  617. package/dist/store/sqlite/meeting-hit-search.js +1 -1
  618. package/dist/store/sqlite/meeting-hit-search.js.map +1 -1
  619. package/dist/store/sqlite/meeting-index-values.d.ts +19 -0
  620. package/dist/store/sqlite/meeting-index-values.d.ts.map +1 -0
  621. package/dist/store/sqlite/meeting-index-values.js +37 -0
  622. package/dist/store/sqlite/meeting-index-values.js.map +1 -0
  623. package/dist/store/sqlite/meetings.d.ts +0 -12
  624. package/dist/store/sqlite/meetings.d.ts.map +1 -1
  625. package/dist/store/sqlite/meetings.js +1 -35
  626. package/dist/store/sqlite/meetings.js.map +1 -1
  627. package/dist/store/sqlite/mentions.d.ts +3 -0
  628. package/dist/store/sqlite/mentions.d.ts.map +1 -1
  629. package/dist/store/sqlite/mentions.js +99 -22
  630. package/dist/store/sqlite/mentions.js.map +1 -1
  631. package/dist/store/sqlite/retention.d.ts.map +1 -1
  632. package/dist/store/sqlite/retention.js +1 -1
  633. package/dist/store/sqlite/retention.js.map +1 -1
  634. package/dist/store/store.d.ts +1 -0
  635. package/dist/store/store.d.ts.map +1 -1
  636. package/package.json +3 -3
  637. package/parity.json +8 -8
  638. package/dist/cli/messenger/port.d.ts.map +0 -1
  639. package/dist/cli/messenger/port.js.map +0 -1
@@ -1,631 +1,8 @@
1
- import { CliError } from "@wirecat/cli-base";
2
- import { CHUNK_CHARS, chunkHash, chunkTextOf } from "../conversations/chunks.js";
3
- import { RULES_VERSION } from "../conversations/link.js";
4
- import { formatLocator, parseLocator } from "../domain/locator.js";
5
- import { defaultThreads, isTextModelInstalled, textModelsDirectory } from "../embeddings/embed.js";
6
- import { DEFAULT_TEXT_MODEL, meaningFloor, textModel } from "../embeddings/models.js";
7
- import { remoteKey } from "../embeddings/remote.js";
8
- import { CONTEXT_MESSAGES, CONTEXT_MINUTES } from "../images/context/index.js";
9
- import { registeredImageProviders } from "../images/registry.js";
10
- import { QUERY_LIMITS, searchError } from "../search/lucene/types.js";
11
- import { threadConversation, } from "../store/store.js";
12
- import { conversationsService } from "./conversations.js";
13
- import { storedChatId } from "./messages.js";
14
- import { prepareLucene } from "./messages-search.js";
15
- import { MAIL } from "./search-kind.js";
16
- import { refreshSearch } from "./search-refresh.js";
17
- /** How much one run without `--chat` does at most, by default. */
18
- export const REFRESH_BOUNDS = { maxChats: 20, maxChunks: 2_000 };
19
- /** A vector's model: the provider, the model and its size — vectors of two of them never mix. */
20
- export const vectorModelKey = (model) => `local:${model.id}:${model.dims}`;
21
- /** Chunks per batch for one local session; one short transaction writes each batch. */
22
- const PER_SESSION = 8;
23
- /** Texts per remote request; `concurrency` of them run at once. */
24
- const PER_REQUEST = 256;
25
- /** How deep each list is read before the two are merged. */
26
- const CANDIDATES = 50;
27
- /** Messages the word search reads: one long thread can hold many of them. */
28
- const WORD_HITS = 200;
29
- /** Reciprocal rank fusion's usual constant (phase 5 E9). */
30
- const RRF_K = 60;
31
- /** e5's tokenizer reads ~3.7 characters a token in Russian; 3 keeps the bound above the real count. */
32
- const CHARS_PER_TOKEN_AT_LEAST = 3;
33
- export const embeddingsService = (deps) => {
34
- const command = deps.messenger.app.command;
35
- const notDownloaded = (id) => new CliError("not_found", `${id} is not downloaded — \`${command} models text download ${id}\``, {
36
- reason: "model.not-downloaded",
37
- model: id,
38
- });
39
- const notBuiltError = (chatId) => new CliError("not_found", `chat ${chatId} has no conversations yet — \`${command} conversations build --chat ${chatId}\``);
40
- const resolve = (choice = DEFAULT_TEXT_MODEL) => {
41
- if (typeof choice !== "string") {
42
- const { remote, apiKey, concurrency = 4 } = choice;
43
- return {
44
- id: `${remote.provider}:${remote.model}`,
45
- key: remoteKey(remote),
46
- dims: remote.dims,
47
- speed: null,
48
- price: remote.price,
49
- installed: true,
50
- perBatch: (_workers) => PER_REQUEST * concurrency,
51
- open: async () => (await import("../embeddings/remote.js")).openRemote(remote, apiKey, { concurrency }),
52
- };
53
- }
54
- const model = textModel(choice);
55
- const directory = textModelsDirectory(deps.env);
56
- return {
57
- id: model.id,
58
- key: vectorModelKey(model),
59
- dims: model.dims,
60
- speed: model.chunksPerSecond,
61
- price: undefined,
62
- installed: isTextModelInstalled(model, directory),
63
- perBatch: (workers) => PER_SESSION * Math.max(1, workers),
64
- open: async ({ workers = 1, threads, apart = false, } = {}) => {
65
- if (!isTextModelInstalled(model, directory))
66
- throw notDownloaded(model.id);
67
- if (apart) {
68
- const { openProcess } = await import("../embeddings/process.js");
69
- return openProcess(model, directory, { threads: threads ?? defaultThreads() });
70
- }
71
- const { openPool } = await import("../embeddings/pool.js");
72
- return openPool(model, directory, { workers, ...(threads ? { threads } : {}) });
73
- },
74
- };
75
- };
76
- /**
77
- * The conversations holding messages that share a word with the query, best message first. Every word
78
- * is one side of an OR, so a sentence ranks what shares any of it, and nothing in it is read as a filter.
79
- * Only whole words and their beginnings count: a corrected spelling or a piece of a word would pass a
80
- * near-miss off as a match, which is what the meaning half is for.
81
- */
82
- const byWords = async (query, prepared, conversations, since) => {
83
- const words = [...new Set(query.toLowerCase().match(/[\p{L}\p{N}]+/gu) ?? [])];
84
- const outside = new Map();
85
- if (!words.length || !prepared.scopeAccounts.length)
86
- return { hits: [], outside, sources: new Map() };
87
- const store = await deps.store();
88
- const lexical = await prepareLucene(store, await deps.account(), {
89
- text: words.map((word) => (word.length >= 3 ? `${word}*` : `"${word}"`)).join(" OR "),
90
- accounts: prepared.scopeAccounts,
91
- limit: WORD_HITS,
92
- }, deps.messenger);
93
- if (!store.matchQuery)
94
- throw new CliError("validation_error", "the store does not support strict search");
95
- const { items } = await store.matchQuery({
96
- ...lexical.execution,
97
- ...(prepared.selectedChat ? { chat: prepared.selectedChat } : {}),
98
- ...(conversations === undefined ? {} : { conversationIds: conversations }),
99
- ...(since === undefined ? {} : { conversationSince: Date.parse(since) }),
100
- });
101
- const summaries = new Map();
102
- const sources = new Map();
103
- for (const account of prepared.scopeAccounts) {
104
- const refs = items.flatMap((hit, index) => {
105
- const at = parseLocator(hit.locator);
106
- return at.provider === account.provider && at.account === account.account ? [{ hit, index }] : [];
107
- });
108
- const found = await store.conversationsOfMessages(account, refs.map(({ hit }) => ({ chatId: hit.chatId, messageId: hit.id })));
109
- const chats = new Set();
110
- refs.forEach(({ hit, index }, at) => {
111
- const summary = found[at];
112
- if (summary) {
113
- summaries.set(index, summary);
114
- sources.set(summary.id, account);
115
- }
116
- else
117
- chats.add(hit.chatId);
118
- });
119
- outside.set(JSON.stringify(account), { account, chats });
120
- }
121
- const ranked = items.flatMap(({ id, score }, index) => {
122
- const summary = summaries.get(index);
123
- return summary ? [{ summary, chunk: { firstMessageId: id, lastMessageId: id }, score }] : [];
124
- });
125
- // Mail in its own tables has no conversations: each email answers as its thread, ranked with the messages.
126
- const mailAccounts = prepared.scopeAccounts.filter(({ provider }) => provider === MAIL);
127
- if (mailAccounts.length && conversations === undefined) {
128
- const mail = await store
129
- .matchQuery({
130
- ...lexical.execution,
131
- accounts: mailAccounts,
132
- corpus: "mail",
133
- ...(prepared.selectedChat ? { chat: prepared.selectedChat } : {}),
134
- })
135
- .catch((error) => {
136
- if (error instanceof CliError && error.code === "validation_error")
137
- return { items: [] };
138
- throw error;
139
- });
140
- for (const account of mailAccounts) {
141
- const found = mail.items.filter((hit) => {
142
- const at = parseLocator(hit.locator);
143
- return at.account === account.account && (since === undefined || hit.timestamp >= since);
144
- });
145
- if (!found.length)
146
- continue;
147
- const { id } = await store.storedAccount(account);
148
- const places = new Map((await store.mail.inThreads(id, found.map((hit) => hit.id))).map((place) => [place.externalId, place]));
149
- for (const hit of found) {
150
- const place = places.get(hit.id);
151
- if (!place)
152
- continue;
153
- const summary = threadConversation(place, Date.now());
154
- sources.set(summary.id, account);
155
- ranked.push({ summary, chunk: { firstMessageId: hit.id, lastMessageId: hit.id }, score: hit.score });
156
- }
157
- }
158
- ranked.sort((a, b) => (b.score ?? Number.NEGATIVE_INFINITY) - (a.score ?? Number.NEGATIVE_INFINITY));
159
- }
160
- const seen = new Set();
161
- const hits = ranked.flatMap(({ summary, chunk }) => {
162
- if (seen.has(summary.id))
163
- return [];
164
- seen.add(summary.id);
165
- return [{ summary, chunk }];
166
- });
167
- return { hits, outside, sources };
168
- };
169
- const readinessOf = async (chatId, key) => {
170
- const store = await deps.store();
171
- const account = await deps.account();
172
- return (await store.readiness(account, { ...(chatId === undefined ? {} : { chatId }), model: key })).map(shaped);
173
- };
174
- const found = async (chat) => {
175
- const store = await deps.store();
176
- const account = await deps.account();
177
- const chatId = await storedChatId(deps.messenger, chat, store, account);
178
- if (!(await store.conversationState(account, chatId))?.builtAt)
179
- throw notBuiltError(chatId);
180
- return { store, account, chatId };
181
- };
182
- /** The server's warm model when there is one, kept open after; otherwise opened here and closed. */
183
- const withEmbedder = async (target, choice, { workers = 1, threads }, work) => {
184
- const warm = typeof choice !== "object" ? deps.embedders : undefined;
185
- const embedder = warm
186
- ? await warm.get(target.key, () => target.open({ apart: true }))
187
- : await target.open({ workers, ...(threads ? { threads } : {}) });
188
- try {
189
- return await work(embedder);
190
- }
191
- finally {
192
- if (!warm)
193
- await embedder.close();
194
- }
195
- };
196
- const embedInto = async (chatId, target, embedder, { workers = 1, maxChunks = Number.POSITIVE_INFINITY, progress, check, }) => {
197
- const store = await deps.store();
198
- const account = await deps.account();
199
- let embedded = 0;
200
- let skipped = 0;
201
- let left = (await store.vectorStatus(account, chatId, target.key)).chunks;
202
- let after;
203
- while (embedded + skipped < maxChunks) {
204
- check?.();
205
- const batch = await store.chunksToEmbed(account, chatId, target.key, {
206
- limit: Math.min(target.perBatch(workers), maxChunks - embedded - skipped),
207
- ...(after ? { after } : {}),
208
- });
209
- if (batch.length === 0)
210
- break;
211
- after = batch.at(-1)?.hash;
212
- const ready = batch.flatMap(({ hash, lines }) => {
213
- const text = chunkTextOf(lines);
214
- return chunkHash(text) === hash ? [{ hash, text }] : [];
215
- });
216
- skipped += batch.length - ready.length;
217
- const vectors = await embedder.embed(ready.map(({ text }) => text), "passage");
218
- check?.();
219
- await store.saveVectors(target.key, target.dims, ready.map(({ hash }, index) => ({ hash, vector: vectors[index] })));
220
- embedded += ready.length;
221
- left = Math.max(0, left - batch.length);
222
- progress?.(embedded, left);
223
- }
224
- embedded += await embedImages(chatId, target, embedder, check);
225
- return { chat: chatId, model: target.id, embedded, skipped };
226
- };
227
- /**
228
- * One chunk per image of the chat: the text its first image provider gives it, embedded like a message. The
229
- * chunk's hash names the provider and its version, so a newer provider describes every image again.
230
- */
231
- const embedImages = async (chatId, target, embedder, check) => {
232
- const providers = registeredImageProviders();
233
- if (providers.length === 0)
234
- return 0;
235
- const store = await deps.store();
236
- const account = await deps.account();
237
- const images = await store.imagesToDescribe(account, chatId, {
238
- messages: CONTEXT_MESSAGES,
239
- withinMs: CONTEXT_MINUTES * 60_000,
240
- });
241
- const described = [];
242
- for (const image of images) {
243
- check?.();
244
- for (const provider of providers) {
245
- const { text } = await provider.describe({ kind: image.kind, name: image.name, mime: image.mime, localPath: image.localPath }, {
246
- chatTitle: image.chatTitle,
247
- sender: image.sender,
248
- caption: image.caption,
249
- sentAt: image.sentAt,
250
- before: image.before,
251
- after: image.after,
252
- });
253
- if (text?.trim()) {
254
- described.push({
255
- attachmentPk: image.attachmentPk,
256
- hash: chunkHash(`${provider.id}:${provider.version}\n${text}`),
257
- text,
258
- occurredAt: image.sentAt,
259
- });
260
- break;
261
- }
262
- }
263
- }
264
- const have = await store.embeddedHashes(target.key, described.map(({ hash }) => hash));
265
- const missing = [...new Map(described.filter(({ hash }) => !have.has(hash)).map((one) => [one.hash, one])).values()];
266
- for (let at = 0; at < missing.length; at += PER_REQUEST) {
267
- const batch = missing.slice(at, at + PER_REQUEST);
268
- const vectors = await embedder.embed(batch.map(({ text }) => text), "passage");
269
- check?.();
270
- await store.saveVectors(target.key, target.dims, batch.map(({ hash }, index) => ({ hash, vector: vectors[index] })));
271
- }
272
- await store.saveImageChunks(account, chatId, described.map(({ attachmentPk, hash, text, occurredAt }) => ({
273
- attachmentPk,
274
- hash,
275
- length: text.length,
276
- occurredAt,
277
- })), described.map(({ attachmentPk }) => attachmentPk));
278
- return missing.length;
279
- };
280
- return {
281
- status: async (chat, choice) => {
282
- const { store, account, chatId } = await found(chat);
283
- const target = resolve(choice);
284
- const { chunks, embedded } = await store.vectorStatus(account, chatId, target.key);
285
- const left = chunks - embedded;
286
- const tokensAtMost = Math.ceil((left * CHUNK_CHARS) / CHARS_PER_TOKEN_AT_LEAST);
287
- return {
288
- chat: chatId,
289
- model: target.id,
290
- chunks,
291
- embedded,
292
- left,
293
- estimateSeconds: target.speed === null ? null : Math.ceil(left / target.speed),
294
- tokensAtMost,
295
- ...(target.price
296
- ? { priceAtMost: { usd: (tokensAtMost / 1e6) * target.price.perMillion, read: target.price.read } }
297
- : {}),
298
- };
299
- },
300
- embed: async (chat, { model: choice, workers = 1, threads, maxChunks, progress }) => {
301
- const { chatId } = await found(chat);
302
- const target = resolve(choice);
303
- return withEmbedder(target, choice, { workers, threads }, (embedder) => embedInto(chatId, target, embedder, { workers, maxChunks, progress }));
304
- },
305
- search: async (query, { chat, model: choice, since, limit, filter, source, timezone, syncFirst, signal, refresh }) => {
306
- if (!query.trim())
307
- searchError("query.invalid-syntax", { start: 0, end: query.length }, "give words to search for");
308
- if (new TextEncoder().encode(query).length > QUERY_LIMITS.bytes)
309
- searchError("query.too-large", { start: 0, end: query.length }, "query is longer than 8 KiB");
310
- const refreshed = await refreshSearch(deps, {
311
- chat,
312
- limit,
313
- syncFirst,
314
- signal,
315
- language: "lucene",
316
- text: filter,
317
- source,
318
- timezone,
319
- });
320
- const locallyRefreshed = refresh ? await embeddingsService(deps).refresh(refresh) : undefined;
321
- const store = await deps.store();
322
- const account = await deps.account();
323
- const target = resolve(choice);
324
- const stop = Date.now() + 200;
325
- await store.fillSearchIndex({ until: () => Date.now() >= stop });
326
- await store.fillStems({ until: () => Date.now() >= stop });
327
- const prepared = await prepareLucene(store, account, {
328
- ...(filter === undefined ? {} : { text: filter }),
329
- ...(source === undefined ? {} : { source }),
330
- ...(chat === undefined ? {} : { chat }),
331
- ...(timezone === undefined ? {} : { timezone }),
332
- limit,
333
- }, deps.messenger);
334
- if (filter !== undefined && !store.conversationEligibility)
335
- throw new CliError("validation_error", "the store does not support conversation filters — upgrade cli-core");
336
- const eligibility = filter === undefined ? undefined : await store.conversationEligibility?.(prepared.execution);
337
- const selected = prepared.selectedChat;
338
- const scopeOf = (one) => selected
339
- ? selected.account.provider === one.provider && selected.account.account === one.account
340
- ? { chatId: selected.chatId }
341
- : null
342
- : {};
343
- const words = await byWords(query, prepared, eligibility?.conversations, since);
344
- const meaning = [];
345
- const sources = words.sources;
346
- if (target.installed && prepared.scopeAccounts.length && eligibility?.conversations.length !== 0) {
347
- await withEmbedder(target, choice, {}, async (embedder) => {
348
- const [vector] = await embedder.embed([query], "query");
349
- for (const one of prepared.scopeAccounts) {
350
- const scope = scopeOf(one);
351
- if (scope === null)
352
- continue;
353
- const hits = await store.nearestConversations(one, {
354
- ...scope,
355
- ...(since === undefined ? {} : { since }),
356
- model: target.key,
357
- limit: Math.max(limit, CANDIDATES),
358
- query: vector,
359
- ...(eligibility ? { conversations: eligibility.conversations } : {}),
360
- });
361
- for (const hit of hits)
362
- sources.set(hit.summary.id, one);
363
- meaning.push(...hits);
364
- const images = await store.nearestImages(one, {
365
- ...scope,
366
- ...(since === undefined ? {} : { since }),
367
- model: target.key,
368
- limit: Math.max(limit, CANDIDATES),
369
- query: vector,
370
- });
371
- for (const hit of images) {
372
- if (eligibility && !eligibility.conversations.includes(hit.summary.id))
373
- continue;
374
- sources.set(hit.summary.id, one);
375
- meaning.push(hit);
376
- }
377
- }
378
- });
379
- }
380
- meaning.sort((a, b) => b.score - a.score);
381
- const scoped = [];
382
- const elsewhere = [];
383
- for (const one of prepared.scopeAccounts) {
384
- const scope = scopeOf(one);
385
- if (scope === null)
386
- continue;
387
- const eligibleChats = eligibility?.chats
388
- .filter(({ account }) => account.provider === one.provider && account.account === one.account)
389
- .map(({ chat }) => chat);
390
- const rows = eligibleChats === undefined
391
- ? await store.readiness(one, { ...scope, model: target.key })
392
- : (await Promise.all(eligibleChats.map((chatId) => store.readiness(one, { chatId, model: target.key })))).flat();
393
- const readiness = searchReadiness(rows.map(shaped), target.installed, words.outside.get(JSON.stringify(one))?.chats ?? new Set());
394
- scoped.push({ source: one, readiness });
395
- const other = await store.embeddedOnlyElsewhere(one, { ...scope, model: target.key });
396
- elsewhere.push(...other
397
- .filter((id) => eligibleChats === undefined || eligibleChats.includes(id))
398
- .map((id) => prepared.scopeAccounts.length > 1
399
- ? [one.provider, one.account, id].map(encodeURIComponent).join("/")
400
- : id));
401
- }
402
- const readiness = { searchedByMeaning: [], wordsOnly: [], partial: [], stale: [], notBuilt: [] };
403
- for (const key of ["searchedByMeaning", "wordsOnly", "partial", "stale", "notBuilt"])
404
- readiness[key] = [
405
- ...new Set(scoped.flatMap(({ source, readiness }) => readiness[key].map((id) => scoped.length > 1 ? [source.provider, source.account, id].map(encodeURIComponent).join("/") : id))),
406
- ].sort();
407
- if (scoped.length > 1)
408
- readiness.scopes = scoped;
409
- return {
410
- accounts: prepared.scopeAccounts,
411
- model: target.id,
412
- meaning: target.installed ? "searched" : "unavailable",
413
- hits: fused(meaning, words.hits, meaningFloor(target.key))
414
- .slice(0, limit)
415
- .map((hit) => {
416
- const source = sources.get(hit.summary.id);
417
- return {
418
- ...hit,
419
- source,
420
- locator: formatLocator({ ...source, chat: hit.summary.chatId, message: hit.chunk.firstMessageId }),
421
- };
422
- }),
423
- readiness,
424
- ...(locallyRefreshed ? { prepared: locallyRefreshed } : {}),
425
- ...(refreshed
426
- ? { refreshed, coverage: { state: refreshed.complete ? "partial" : "stale" } }
427
- : {}),
428
- embeddedOnlyElsewhere: elsewhere,
429
- };
430
- },
431
- related: async (chat, message, { model: choice, limit }) => {
432
- const store = await deps.store();
433
- const account = await deps.account();
434
- const target = resolve(choice);
435
- const chatId = await storedChatId(deps.messenger, chat, store, account);
436
- const [source] = await store.conversationsOfMessages(account, [{ chatId, messageId: message }]);
437
- if (!source) {
438
- if (!(await store.conversationState(account, chatId))?.builtAt)
439
- throw notBuiltError(chatId);
440
- throw new CliError("not_found", `message ${message} is in no conversation of chat ${chatId}`);
441
- }
442
- const { vectors } = await store.conversationVectors(account, source.id, target.key);
443
- if (vectors.length === 0) {
444
- const [own] = await readinessOf(chatId, target.key);
445
- const step = own && isStale(own) ? "build" : "embed";
446
- throw new CliError("not_found", `conversation ${source.id} has no vector of ${target.id} that matches its messages now — ` +
447
- `\`${command} conversations ${step} --chat ${chatId}\``);
448
- }
449
- const hits = await store.nearestConversations(account, {
450
- model: target.key,
451
- limit: Math.max(limit, CANDIDATES),
452
- query: meanOf(vectors),
453
- exclude: source.id,
454
- });
455
- return {
456
- model: target.id,
457
- source,
458
- hits: hits
459
- .slice(0, limit)
460
- .map(({ summary, chunk, score, stale }) => ({ summary, chunk, score, by: ["meaning"], stale })),
461
- readiness: searchReadiness(await readinessOf(undefined, target.key), true, new Set()),
462
- };
463
- },
464
- readiness: async ({ chat, model: choice }) => {
465
- const store = await deps.store();
466
- const account = await deps.account();
467
- const target = resolve(choice);
468
- const chatId = chat === undefined ? undefined : await storedChatId(deps.messenger, chat, store, account);
469
- const chats = await readinessOf(chatId, target.key);
470
- if (chatId !== undefined)
471
- return { model: target.id, chats };
472
- return { model: target.id, chats, unbuiltGroups: (await store.unbuiltGroups(account)).length };
473
- },
474
- refresh: async ({ chat, model: choice = DEFAULT_TEXT_MODEL, build = true, embed = true, maxChats = REFRESH_BOUNDS.maxChats, maxChunks = REFRESH_BOUNDS.maxChunks, workers, threads, progress, maxMessages, check, }) => {
475
- check?.();
476
- const store = await deps.store();
477
- const account = await deps.account();
478
- const target = resolve(choice);
479
- if (embed && !build && !target.installed)
480
- throw notDownloaded(target.id);
481
- const chatId = chat === undefined ? undefined : await storedChatId(deps.messenger, chat, store, account);
482
- const scan = async () => ({
483
- chats: (await readinessOf(chatId, target.key)).sort(byOldestBuild),
484
- unbuilt: chatId === undefined ? await store.unbuiltGroups(account) : [],
485
- });
486
- const built = [];
487
- if (build) {
488
- const { chats, unbuilt } = await scan();
489
- const queue = [...chats.filter(needsBuild).map(({ chat }) => chat), ...unbuilt].slice(0, maxChats);
490
- const conversations = conversationsService(deps);
491
- for (const id of queue) {
492
- try {
493
- check?.();
494
- const one = await conversations.build(id, { maxMessages, check });
495
- built.push(one);
496
- progress?.(`chat ${id}: ${one.messages} messages → ${one.conversations} conversations`);
497
- }
498
- catch (error) {
499
- // Every message of a once-built chat deleted: nothing to build, and it stays in `left`.
500
- if (!(error instanceof CliError && error.code === "not_found"))
501
- throw error;
502
- }
503
- }
504
- }
505
- const embedded = [];
506
- if (embed && target.installed) {
507
- const fresh = new Set(built.map(({ chat }) => chat));
508
- const queue = (await scan()).chats
509
- .filter(needsEmbed)
510
- .sort((a, b) => Number(fresh.has(b.chat)) - Number(fresh.has(a.chat)))
511
- .slice(0, maxChats);
512
- if (queue.length > 0) {
513
- await withEmbedder(target, choice, { workers, threads }, async (embedder) => {
514
- let budget = maxChunks;
515
- for (const { chat } of queue) {
516
- if (budget <= 0)
517
- break;
518
- check?.();
519
- const done = await embedInto(chat, target, embedder, { workers, maxChunks: budget, check });
520
- budget -= done.embedded + done.skipped;
521
- embedded.push(done);
522
- progress?.(`chat ${chat}: ${done.embedded} chunks embedded with ${target.id}`);
523
- }
524
- });
525
- }
526
- }
527
- const after = await scan();
528
- const rebuild = build ? [...after.chats.filter(needsBuild).map(({ chat }) => chat), ...after.unbuilt] : [];
529
- const pending = new Set(rebuild);
530
- return {
531
- model: target.id,
532
- modelAvailable: target.installed,
533
- built,
534
- embedded,
535
- left: [
536
- ...rebuild.map((chat) => ({ chat, needs: "build" })),
537
- ...(embed
538
- ? after.chats
539
- .filter((one) => needsEmbed(one) && !pending.has(one.chat))
540
- .map(({ chat }) => ({ chat, needs: "embed" }))
541
- : []),
542
- ],
543
- };
544
- },
545
- clear: async (chat, choice) => {
546
- const store = await deps.store();
547
- const account = await deps.account();
548
- const chatId = await storedChatId(deps.messenger, chat, store, account);
549
- const cleared = await store.clearVectors(account, chatId, choice === undefined ? undefined : resolve(choice).key);
550
- return { chat: chatId, cleared };
551
- },
552
- };
553
- };
554
- /** Reciprocal rank fusion of the two lists: each conversation scores 1 / (k + rank) in every list it is in. */
555
- const fused = (meaning, words, minimumCosine) => {
556
- const merged = new Map();
557
- meaning
558
- .filter(({ score }) => score > minimumCosine)
559
- .forEach(({ summary, chunk, score, stale, matchedIn }, index) => {
560
- merged.set(matchedIn ? `${summary.id}#${chunk.firstMessageId}` : summary.id, {
561
- summary,
562
- chunk,
563
- score,
564
- by: ["meaning"],
565
- stale,
566
- ...(matchedIn ? { matchedIn } : {}),
567
- fused: 1 / (RRF_K + index + 1),
568
- });
569
- });
570
- words.forEach(({ summary, chunk }, index) => {
571
- const share = 1 / (RRF_K + index + 1);
572
- const held = merged.get(summary.id);
573
- if (held) {
574
- held.fused += share;
575
- held.by.push("words");
576
- }
577
- else
578
- merged.set(summary.id, { summary, chunk, score: null, by: ["words"], stale: false, fused: share });
579
- });
580
- return [...merged.values()]
581
- .sort((a, b) => b.fused - a.fused || (b.score ?? -2) - (a.score ?? -2))
582
- .map(({ fused: _, ...hit }) => hit);
583
- };
584
- const needsBuild = (one) => one.graph === null || isStale(one);
585
- const needsEmbed = (one) => one.graph !== null && one.vectors.missing > 0;
586
- /** Never finished first, then the oldest build: the longest-waiting change goes first. */
587
- const byOldestBuild = (a, b) => (a.graph?.builtAt ?? "").localeCompare(b.graph?.builtAt ?? "");
588
- /** The chats in readiness by how a meaning search with these vectors could see them, and the word matches outside any. */
589
- const searchReadiness = (chats, meaning, outside) => {
590
- const built = new Set(chats.filter(({ state }) => state !== "not-built").map(({ chat }) => chat));
591
- const ids = (keep) => chats.filter(keep).map(({ chat }) => chat);
592
- const byMeaning = (one) => meaning && built.has(one.chat) && one.state !== "words-only" && one.vectors.chunks > 0;
593
- return {
594
- searchedByMeaning: ids(byMeaning),
595
- wordsOnly: ids((one) => built.has(one.chat) && !byMeaning(one)),
596
- partial: ids((one) => byMeaning(one) && one.vectors.missing > 0),
597
- stale: ids((one) => built.has(one.chat) && isStale(one)),
598
- notBuilt: [
599
- ...new Set([...ids((one) => one.state === "not-built"), ...[...outside].filter((id) => !built.has(id))]),
600
- ].sort(),
601
- };
602
- };
603
- /** Unit vectors' mean, made unit length again so the dot product stays a cosine. */
604
- const meanOf = (vectors) => {
605
- const mean = new Float32Array(vectors[0]?.length ?? 0);
606
- for (const vector of vectors) {
607
- for (let index = 0; index < mean.length; index++)
608
- mean[index] = mean[index] + vector[index];
609
- }
610
- const length = Math.hypot(...mean) || 1;
611
- return mean.map((value) => value / length);
612
- };
613
- const isStale = ({ graph, pending, vectors }) => Boolean(graph?.outdatedRules) || pending.new + pending.edited + pending.deleted > 0 || vectors.stale > 0;
614
- const shaped = ({ chatId, builtAt, algorithmVersion, pending, vectors }) => {
615
- const { embedded, ...counts } = vectors;
616
- const graph = builtAt === null
617
- ? null
618
- : { builtAt, rulesVersion: algorithmVersion, outdatedRules: algorithmVersion !== RULES_VERSION };
619
- const one = { chat: chatId, state: "ready", graph, pending, vectors: counts };
620
- const state = graph === null
621
- ? "not-built"
622
- : counts.chunks > 0 && embedded === 0
623
- ? "words-only"
624
- : isStale(one)
625
- ? "stale"
626
- : counts.missing > 0
627
- ? "partial"
628
- : "ready";
629
- return { ...one, state };
630
- };
1
+ import { embeddingsMaintenance } from "./embeddings-maintenance.js";
2
+ import { embeddingsSearch } from "./embeddings-search.js";
3
+ export { REFRESH_BOUNDS } from "./embeddings-maintenance.js";
4
+ export const embeddingsService = (deps) => ({
5
+ ...embeddingsMaintenance(deps),
6
+ ...embeddingsSearch(deps),
7
+ });
631
8
  //# sourceMappingURL=embeddings.js.map