@wirecat/cli-core 0.618.0 → 0.620.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 (335) hide show
  1. package/CHANGELOG.md +453 -1
  2. package/README.md +1 -1
  3. package/THIRD_PARTY_NOTICES +3 -0
  4. package/dist/background/deliver.d.ts +5 -2
  5. package/dist/background/deliver.js +30 -12
  6. package/dist/background/report/render.d.ts +3 -1
  7. package/dist/background/report/render.js +3 -1
  8. package/dist/calendar/cli/answers.d.ts +1 -0
  9. package/dist/calendar/cli/answers.js +6 -1
  10. package/dist/calendar/cli/index.js +2 -14
  11. package/dist/calendar/cli/people-link.d.ts +3 -0
  12. package/dist/calendar/cli/people-link.js +23 -0
  13. package/dist/calendar/cli/search-all.d.ts +1 -1
  14. package/dist/calendar/cli/search-all.js +9 -10
  15. package/dist/calendar/index.d.ts +1 -1
  16. package/dist/calendar/index.js +1 -1
  17. package/dist/calendar/mcp/index.d.ts +12 -12
  18. package/dist/calendar/prepare.js +1 -0
  19. package/dist/cli/base-stages-command.d.ts +22 -0
  20. package/dist/cli/base-stages-command.js +174 -0
  21. package/dist/cli/bot/buttons.d.ts +3 -0
  22. package/dist/cli/bot/buttons.js +24 -0
  23. package/dist/cli/bot/messages.js +14 -1
  24. package/dist/cli/bot/port.d.ts +8 -0
  25. package/dist/cli/command-runs.d.ts +2 -0
  26. package/dist/cli/command-runs.js +3 -1
  27. package/dist/cli/config-command.js +6 -1
  28. package/dist/cli/context.js +1 -0
  29. package/dist/cli/contract-templates.js +31 -2
  30. package/dist/cli/group-lock.d.ts +42 -0
  31. package/dist/cli/group-lock.js +130 -0
  32. package/dist/cli/index.d.ts +7 -2
  33. package/dist/cli/index.js +7 -2
  34. package/dist/cli/messenger/backfill-command.js +27 -15
  35. package/dist/cli/messenger/contacts-command.js +12 -4
  36. package/dist/cli/messenger/context.js +1 -0
  37. package/dist/cli/messenger/conversations-command.js +2 -1
  38. package/dist/cli/messenger/doctor-command.js +3 -1
  39. package/dist/cli/messenger/message-items.js +1 -1
  40. package/dist/cli/messenger/models-command.js +1 -1
  41. package/dist/cli/messenger/search-answers.d.ts +5 -5
  42. package/dist/cli/messenger/search-answers.js +9 -20
  43. package/dist/cli/messenger/search-command.d.ts +2 -2
  44. package/dist/cli/messenger/search-command.js +8 -18
  45. package/dist/cli/messenger/store-maintenance-command.d.ts +22 -2
  46. package/dist/cli/messenger/store-maintenance-command.js +9 -4
  47. package/dist/cli/model-catalogue-command.d.ts +3 -1
  48. package/dist/cli/model-catalogue-command.js +48 -2
  49. package/dist/cli/profile.d.ts +8 -0
  50. package/dist/cli/profile.js +25 -0
  51. package/dist/cli/program.js +2 -0
  52. package/dist/cli/runs/search-query.d.ts +1 -1
  53. package/dist/cli/runs/search-query.js +4 -0
  54. package/dist/cli/runs/search.d.ts +5 -1
  55. package/dist/cli/runs/search.js +12 -1
  56. package/dist/cli/search-harder-consents-command.d.ts +18 -0
  57. package/dist/cli/search-harder-consents-command.js +83 -0
  58. package/dist/cli/search-left-out.d.ts +6 -1
  59. package/dist/cli/search-left-out.js +9 -4
  60. package/dist/cli/settings.d.ts +8 -0
  61. package/dist/cli/settings.js +17 -2
  62. package/dist/cli/shared-command-exports.d.ts +16 -0
  63. package/dist/cli/steps.js +0 -6
  64. package/dist/cli/store-recover.d.ts +3 -3
  65. package/dist/cli/store-recover.js +26 -26
  66. package/dist/cli/store-settings.d.ts +2 -0
  67. package/dist/cli/store-settings.js +37 -9
  68. package/dist/cli/templates-command.js +4 -4
  69. package/dist/crm/cli/index.js +40 -8
  70. package/dist/crm/cli/search-all.js +7 -6
  71. package/dist/crm/group-hint.d.ts +8 -0
  72. package/dist/crm/group-hint.js +13 -0
  73. package/dist/crm/source.d.ts +12 -1
  74. package/dist/crm/sync.d.ts +31 -2
  75. package/dist/crm/sync.js +110 -3
  76. package/dist/crm/testing/acme-scenario.d.ts +40 -0
  77. package/dist/crm/testing/acme-scenario.js +170 -0
  78. package/dist/crm/testing/index.d.ts +1 -0
  79. package/dist/crm/testing/index.js +1 -0
  80. package/dist/crm/testing/source-contract.js +12 -0
  81. package/dist/crm/testing/source.d.ts +2 -0
  82. package/dist/crm/testing/source.js +1 -0
  83. package/dist/domain/addresses.d.ts +13 -0
  84. package/dist/domain/addresses.js +63 -0
  85. package/dist/domain/categories.d.ts +3 -0
  86. package/dist/domain/categories.js +2 -0
  87. package/dist/domain/crm.d.ts +23 -0
  88. package/dist/domain/crm.js +7 -0
  89. package/dist/domain/mentions.d.ts +2 -12
  90. package/dist/domain/mentions.js +2 -19
  91. package/dist/domain/models.d.ts +2 -0
  92. package/dist/domain/orders.d.ts +8 -1
  93. package/dist/domain/orders.js +6 -2
  94. package/dist/domain/phones.d.ts +26 -0
  95. package/dist/domain/phones.js +48 -0
  96. package/dist/domain/record-types.d.ts +1 -1
  97. package/dist/domain/record-types.js +1 -0
  98. package/dist/domain/records.d.ts +5 -0
  99. package/dist/domain/ref-summaries.d.ts +39 -0
  100. package/dist/domain/ref-summaries.js +51 -3
  101. package/dist/domain/relations.d.ts +12 -2
  102. package/dist/domain/relations.js +14 -3
  103. package/dist/domain/vcard.d.ts +2 -2
  104. package/dist/domain/vcard.js +4 -10
  105. package/dist/embeddings/models.d.ts +11 -3
  106. package/dist/embeddings/models.js +28 -4
  107. package/dist/entities/business-context.d.ts +149 -0
  108. package/dist/entities/business-context.js +192 -0
  109. package/dist/entities/contact-activity.d.ts +2 -0
  110. package/dist/entities/contact-activity.js +7 -1
  111. package/dist/entities/contact-context.d.ts +160 -0
  112. package/dist/entities/contact-context.js +6 -0
  113. package/dist/entities/deal.d.ts +10 -0
  114. package/dist/entities/deal.js +2 -0
  115. package/dist/entities/hit.d.ts +9 -2
  116. package/dist/entities/hit.js +6 -2
  117. package/dist/entities/index.d.ts +32 -4
  118. package/dist/entities/index.js +5 -0
  119. package/dist/entities/mention.d.ts +4 -3
  120. package/dist/entities/mention.js +2 -1
  121. package/dist/entities/message-transfer.d.ts +4 -2
  122. package/dist/entities/message-transfer.js +2 -2
  123. package/dist/entities/model.d.ts +2 -2
  124. package/dist/entities/model.js +1 -1
  125. package/dist/entities/relationship.d.ts +4 -0
  126. package/dist/entities/relationship.js +4 -0
  127. package/dist/errors/reasons.js +39 -4
  128. package/dist/fetch/page.js +2 -1
  129. package/dist/index.d.ts +3 -2
  130. package/dist/index.js +3 -2
  131. package/dist/meetings/context-store.d.ts +2 -0
  132. package/dist/meetings/findings-rules.d.ts +4 -0
  133. package/dist/meetings/findings-rules.js +5 -2
  134. package/dist/meetings/hit-query.d.ts +1 -1
  135. package/dist/meetings/hit-query.js +2 -2
  136. package/dist/meetings/index.d.ts +1 -0
  137. package/dist/meetings/index.js +1 -0
  138. package/dist/meetings/result-items.d.ts +1 -0
  139. package/dist/meetings/result-items.js +1 -0
  140. package/dist/meetings/store.d.ts +4 -0
  141. package/dist/meetings/store.js +2 -1
  142. package/dist/models/anthropic.js +5 -0
  143. package/dist/models/index.js +22 -5
  144. package/dist/runs/events.d.ts +11 -1
  145. package/dist/runs/events.js +3 -1
  146. package/dist/runs/log-attributes.js +4 -0
  147. package/dist/runs/log-events.js +2 -0
  148. package/dist/runs/recording.d.ts +3 -0
  149. package/dist/runs/recording.js +36 -12
  150. package/dist/runs/run.d.ts +12 -3
  151. package/dist/runs/run.js +32 -13
  152. package/dist/search/account-list.d.ts +6 -0
  153. package/dist/search/account-list.js +9 -3
  154. package/dist/search/groups.d.ts +68 -0
  155. package/dist/search/groups.js +172 -0
  156. package/dist/search/question-period.d.ts +10 -0
  157. package/dist/search/question-period.js +133 -0
  158. package/dist/sends/buttons.d.ts +2 -0
  159. package/dist/sends/buttons.js +6 -1
  160. package/dist/services/account-groups.d.ts +28 -0
  161. package/dist/services/account-groups.js +89 -0
  162. package/dist/services/archive.d.ts +7 -1
  163. package/dist/services/archive.js +19 -3
  164. package/dist/services/business-context.d.ts +113 -0
  165. package/dist/services/business-context.js +156 -0
  166. package/dist/services/communications.d.ts +50 -0
  167. package/dist/services/communications.js +140 -0
  168. package/dist/services/deal-context.d.ts +90 -0
  169. package/dist/services/deal-context.js +131 -0
  170. package/dist/services/deps.d.ts +2 -0
  171. package/dist/services/enrichment.d.ts +12 -2
  172. package/dist/services/enrichment.js +47 -6
  173. package/dist/services/events-search.js +2 -1
  174. package/dist/services/group-guard.d.ts +28 -0
  175. package/dist/services/group-guard.js +131 -0
  176. package/dist/services/index.d.ts +19 -4
  177. package/dist/services/index.js +12 -3
  178. package/dist/services/ingest.d.ts +12 -0
  179. package/dist/services/ingest.js +4 -0
  180. package/dist/services/meaning-model.d.ts +7 -0
  181. package/dist/services/meaning-model.js +20 -0
  182. package/dist/services/meeting-context.d.ts +6 -1
  183. package/dist/services/meeting-context.js +12 -5
  184. package/dist/services/message-resolution.js +2 -3
  185. package/dist/services/messages-meaning.js +4 -5
  186. package/dist/services/messages-search.d.ts +5 -1
  187. package/dist/services/messages-search.js +1 -1
  188. package/dist/services/messages.d.ts +1 -4
  189. package/dist/services/messages.js +0 -2
  190. package/dist/services/metadata.d.ts +1 -1
  191. package/dist/services/model-downloads.d.ts +1 -1
  192. package/dist/services/model-downloads.js +6 -4
  193. package/dist/services/money-context.d.ts +73 -0
  194. package/dist/services/money-context.js +77 -0
  195. package/dist/services/notes-search.d.ts +4 -1
  196. package/dist/services/notes-search.js +19 -7
  197. package/dist/services/organization-context.d.ts +80 -0
  198. package/dist/services/organization-context.js +154 -0
  199. package/dist/services/people.d.ts +22 -6
  200. package/dist/services/people.js +38 -8
  201. package/dist/services/person-business.d.ts +43 -0
  202. package/dist/services/person-business.js +67 -0
  203. package/dist/services/person-context.d.ts +11 -1
  204. package/dist/services/person-context.js +25 -10
  205. package/dist/services/person-preparation.d.ts +5 -1
  206. package/dist/services/person-preparation.js +10 -3
  207. package/dist/services/person-timeline.d.ts +6 -1
  208. package/dist/services/person-timeline.js +10 -2
  209. package/dist/services/proposals/kinds/identity-link.d.ts +4 -0
  210. package/dist/services/proposals/kinds/identity-link.js +48 -0
  211. package/dist/services/proposals/kinds/orders.js +1 -1
  212. package/dist/services/proposals/registry.js +2 -0
  213. package/dist/services/search-all-deprecated.d.ts +40 -0
  214. package/dist/services/search-all-deprecated.js +10 -0
  215. package/dist/services/search-all-meetings.d.ts +50 -52
  216. package/dist/services/search-all-meetings.js +265 -272
  217. package/dist/services/search-all.d.ts +34 -6
  218. package/dist/services/search-all.js +118 -24
  219. package/dist/services/search-harder.d.ts +64 -0
  220. package/dist/services/search-harder.js +194 -0
  221. package/dist/services/search-kind.d.ts +12 -5
  222. package/dist/services/search-kind.js +49 -10
  223. package/dist/services/text-model-choice.js +1 -1
  224. package/dist/store/accounts.d.ts +18 -0
  225. package/dist/store/accounts.js +18 -3
  226. package/dist/store/chats.d.ts +3 -1
  227. package/dist/store/chats.js +6 -0
  228. package/dist/store/damage.d.ts +43 -10
  229. package/dist/store/damage.js +119 -36
  230. package/dist/store/decisions.js +3 -1
  231. package/dist/store/evidence-findings.d.ts +14 -0
  232. package/dist/store/evidence-findings.js +2 -0
  233. package/dist/store/exports.d.ts +2 -1
  234. package/dist/store/identity-links.d.ts +92 -0
  235. package/dist/store/identity-links.js +6 -0
  236. package/dist/store/index.d.ts +11 -5
  237. package/dist/store/index.js +5 -2
  238. package/dist/store/journal.d.ts +10 -0
  239. package/dist/store/journal.js +33 -0
  240. package/dist/store/marks.d.ts +19 -1
  241. package/dist/store/marks.js +23 -1
  242. package/dist/store/people.d.ts +28 -2
  243. package/dist/store/people.js +15 -1
  244. package/dist/store/sqlite/accounts.js +2 -0
  245. package/dist/store/sqlite/added-sources.d.ts +15 -3
  246. package/dist/store/sqlite/added-sources.js +26 -5
  247. package/dist/store/sqlite/base-stages.d.ts +122 -0
  248. package/dist/store/sqlite/base-stages.js +443 -0
  249. package/dist/store/sqlite/base-suggest.d.ts +13 -0
  250. package/dist/store/sqlite/base-suggest.js +62 -0
  251. package/dist/store/sqlite/business-contracts.js +10 -1
  252. package/dist/store/sqlite/chats.d.ts +2 -0
  253. package/dist/store/sqlite/chats.js +6 -0
  254. package/dist/store/sqlite/crm-settings.d.ts +12 -2
  255. package/dist/store/sqlite/crm-settings.js +56 -13
  256. package/dist/store/sqlite/crm.d.ts +13 -1
  257. package/dist/store/sqlite/crm.js +20 -4
  258. package/dist/store/sqlite/deals.d.ts +33 -0
  259. package/dist/store/sqlite/deals.js +42 -4
  260. package/dist/store/sqlite/decision-requests.js +7 -3
  261. package/dist/store/sqlite/email-index.js +8 -4
  262. package/dist/store/sqlite/evidence-findings.js +29 -5
  263. package/dist/store/sqlite/findings-core.js +4 -2
  264. package/dist/store/sqlite/identity-link-rows.d.ts +50 -0
  265. package/dist/store/sqlite/identity-link-rows.js +146 -0
  266. package/dist/store/sqlite/identity-proposals.d.ts +53 -0
  267. package/dist/store/sqlite/identity-proposals.js +234 -0
  268. package/dist/store/sqlite/involvements.d.ts +1 -1
  269. package/dist/store/sqlite/involvements.js +4 -2
  270. package/dist/store/sqlite/knowledge.js +2 -2
  271. package/dist/store/sqlite/link-kinds.d.ts +1 -0
  272. package/dist/store/sqlite/link-kinds.js +1 -0
  273. package/dist/store/sqlite/link-row.d.ts +6 -0
  274. package/dist/store/sqlite/link-row.js +35 -0
  275. package/dist/store/sqlite/link-source.d.ts +10 -0
  276. package/dist/store/sqlite/link-source.js +16 -0
  277. package/dist/store/sqlite/manifest.js +1 -0
  278. package/dist/store/sqlite/meeting-context-links.js +9 -6
  279. package/dist/store/sqlite/meeting-hit-query.d.ts +5 -0
  280. package/dist/store/sqlite/meeting-hit-query.js +33 -0
  281. package/dist/store/sqlite/meeting-hit-search.js +10 -8
  282. package/dist/store/sqlite/meetings.js +1 -1
  283. package/dist/store/sqlite/memories.js +9 -7
  284. package/dist/store/sqlite/mentions.d.ts +4 -1
  285. package/dist/store/sqlite/mentions.js +14 -9
  286. package/dist/store/sqlite/migrations.generated.js +8 -0
  287. package/dist/store/sqlite/notes.d.ts +8 -2
  288. package/dist/store/sqlite/notes.js +17 -34
  289. package/dist/store/sqlite/open-store.js +3 -0
  290. package/dist/store/sqlite/open.js +11 -2
  291. package/dist/store/sqlite/orders.d.ts +2 -0
  292. package/dist/store/sqlite/orders.js +9 -3
  293. package/dist/store/sqlite/organization-categories.d.ts +18 -0
  294. package/dist/store/sqlite/organization-categories.js +34 -0
  295. package/dist/store/sqlite/organizations.d.ts +5 -1
  296. package/dist/store/sqlite/organizations.js +14 -4
  297. package/dist/store/sqlite/person-links.d.ts +19 -4
  298. package/dist/store/sqlite/person-links.js +49 -11
  299. package/dist/store/sqlite/person-match-scan.d.ts +13 -0
  300. package/dist/store/sqlite/person-match-scan.js +251 -0
  301. package/dist/store/sqlite/person-matcher.d.ts +16 -0
  302. package/dist/store/sqlite/person-matcher.js +32 -0
  303. package/dist/store/sqlite/person-preparation.d.ts +7 -3
  304. package/dist/store/sqlite/person-preparation.js +20 -6
  305. package/dist/store/sqlite/proposed-actions.js +6 -0
  306. package/dist/store/sqlite/record-matching.d.ts +2 -8
  307. package/dist/store/sqlite/record-matching.js +8 -40
  308. package/dist/store/sqlite/record-projectors-phone.js +2 -1
  309. package/dist/store/sqlite/record-relationships.d.ts +52 -0
  310. package/dist/store/sqlite/record-relationships.js +243 -0
  311. package/dist/store/sqlite/record-run.d.ts +5 -0
  312. package/dist/store/sqlite/record-run.js +62 -2
  313. package/dist/store/sqlite/record-writes.d.ts +1 -1
  314. package/dist/store/sqlite/record-writes.js +4 -2
  315. package/dist/store/sqlite/records.js +27 -2
  316. package/dist/store/sqlite/ref-accounts.d.ts +13 -0
  317. package/dist/store/sqlite/ref-accounts.js +117 -0
  318. package/dist/store/sqlite/ref-summaries.js +5 -1
  319. package/dist/store/sqlite/relation-list.d.ts +4 -1
  320. package/dist/store/sqlite/relation-list.js +22 -4
  321. package/dist/store/sqlite/relation-proposals.d.ts +6 -0
  322. package/dist/store/sqlite/relation-proposals.js +3 -0
  323. package/dist/store/sqlite/relation-roles.js +12 -6
  324. package/dist/store/sqlite/reported-relations.d.ts +11 -1
  325. package/dist/store/sqlite/reported-relations.js +59 -18
  326. package/dist/store/sqlite/schema.d.ts +32 -0
  327. package/dist/store/sqlite/schema.js +3 -0
  328. package/dist/store/sqlite/transaction.js +11 -1
  329. package/dist/store/store.d.ts +3 -0
  330. package/dist/store/store.js +5 -0
  331. package/dist/store/write-events.d.ts +18 -0
  332. package/dist/store/write-events.js +88 -0
  333. package/package.json +3 -3
  334. package/parity.json +37 -16
  335. package/schemas/records-envelope.v1.schema.json +3 -0
@@ -1,290 +1,283 @@
1
1
  import { CliError } from "@wirecat/cli-base";
2
- import { parseLucene } from "@wirecat/cli-base/query";
3
- import { formatMeetingReference } from "../meetings/index.js";
4
- import { entriesOfList, fitting, listedHolds } from "../search/account-list.js";
5
- import { SEARCH_QUERY } from "../search/lucene/types.js";
6
- import { codeOf } from "../sends/guarded.js";
7
- import { MAX_SEARCH_OFFSET } from "./messages-archive-search.js";
8
- import { RRF_K } from "./notes-search.js";
9
- import { RESOURCES_SEARCHED, searchAll, } from "./search-all.js";
10
- import { listContextOf } from "./search-kind.js";
11
- export const RESOURCES_SEARCHED_WITH_MEETINGS = [...RESOURCES_SEARCHED, "meetings"];
12
- const whole = (value, minimum, maximum, label) => {
13
- if (!Number.isSafeInteger(value) || value < minimum || value > maximum)
14
- throw new CliError("validation_error", `${label} must be an integer from ${minimum} through ${maximum}`);
15
- return value;
2
+ import { holdsKind } from "../domain/providers.js";
3
+ import { formatMeetingReference, liftMeetingFields, parseMeetingQuery, READ_BUDGET_EXCEEDED, } from "../meetings/index.js";
4
+ import { fold } from "../store/normalize.js";
5
+ import { excerpt } from "./excerpt.js";
6
+ import { resolveMeetingSelection } from "./meeting-hit-search.js";
7
+ /** More passages of one meeting would crowd out every other source. */
8
+ export const MOST_HITS_PER_MEETING = 3;
9
+ /** Rows per page: the store refuses a page past 4 MB of text, which would skip the whole account. */
10
+ const PAGE_ROWS = 200;
11
+ const MOST_PAGES = 25;
12
+ const exactly = (node) => node.kind === "boolean"
13
+ ? { ...node, clauses: node.clauses.map((clause) => ({ ...clause, node: exactly(clause.node) })) }
14
+ : node.field === "text"
15
+ ? { ...node, field: "exact" }
16
+ : node;
17
+ const positive = (node) => node.kind === "predicate" || node.clauses.some(({ occur, node }) => occur !== "must_not" && positive(node));
18
+ /** A word or phrase as the start of a title's word, as the passage index matches word starts. */
19
+ const titleNode = (node) => {
20
+ if (node.kind === "boolean") {
21
+ const clauses = node.clauses.map((clause) => ({ ...clause, node: titleNode(clause.node) }));
22
+ return clauses.every((clause) => clause.node) ? { ...node, clauses: clauses } : undefined;
23
+ }
24
+ if ((node.field !== "text" && node.field !== "exact") ||
25
+ (node.operator !== "term" && node.operator !== "phrase") ||
26
+ node.slop !== undefined)
27
+ return undefined;
28
+ const word = node.value.replace(/[\\*?[]/gu, "\\$&");
29
+ const starting = (value) => ({ ...node, field: "title", operator: "wildcard", value });
30
+ return {
31
+ kind: "boolean",
32
+ span: node.span,
33
+ clauses: [
34
+ { occur: "should", node: starting(`${word}*`) },
35
+ { occur: "should", node: starting(`* ${word}*`) },
36
+ ],
37
+ };
16
38
  };
17
- const cancelled = (signal) => {
18
- if (signal?.aborted)
19
- throw new CliError("cancelled", "search was cancelled", { complete: false });
39
+ /** A question finds passages by any of its words; a title holding one of them is no answer, so it needs them all. */
40
+ const everyWord = (node) => node.kind === "boolean"
41
+ ? {
42
+ ...node,
43
+ clauses: node.clauses.map((clause) => (clause.occur === "should" ? { ...clause, occur: "must" } : clause)),
44
+ }
45
+ : node;
46
+ /**
47
+ * The query's words as a `meetings list` query over the folded title, or `undefined` when a title cannot answer it:
48
+ * a speaker or nearness is about what was said, and project and tag are not title filters.
49
+ */
50
+ const titleQuery = (query, input, question) => {
51
+ if (input.projectId !== undefined || input.tagId !== undefined || !positive(query.root))
52
+ return undefined;
53
+ const root = titleNode(question ? everyWord(query.root) : query.root);
54
+ return root && { ...query, root };
20
55
  };
21
- const meetingQuery = (text, exact) => {
22
- if (exact)
23
- return { reason: "meetings use word prefixes and cannot answer --exact" };
24
- try {
25
- const terms = [];
26
- const supported = (node) => {
27
- if (node.kind === "boolean")
28
- return node.clauses.every(({ occur, node }) => occur === "must" && supported(node));
29
- if (node.field !== "text" || node.operator !== "term" || !/^[\p{L}\p{N}]+$/u.test(node.value))
30
- return false;
31
- terms.push(node.value);
32
- return true;
56
+ const titleWords = (title) => fold(title).match(/[\p{L}\p{N}]+/gu) ?? [];
57
+ /** The SQL matches word starts; an exact word must be a whole word of the title. */
58
+ const holdsExactly = (node, words) => {
59
+ if (node.kind === "boolean") {
60
+ const must = node.clauses.filter(({ occur }) => occur === "must");
61
+ const should = node.clauses.filter(({ occur }) => occur === "should");
62
+ return (must.every((clause) => holdsExactly(clause.node, words)) &&
63
+ !node.clauses.some(({ occur, node }) => occur === "must_not" && holdsExactly(node, words)) &&
64
+ (must.length > 0 || should.length === 0 || should.some((clause) => holdsExactly(clause.node, words))));
65
+ }
66
+ const wanted = titleWords(node.value);
67
+ if (node.field !== "exact")
68
+ return wanted.every((one) => words.some((word) => word.startsWith(one)));
69
+ return ` ${words.join(" ")} `.includes(` ${wanted.join(" ")} `);
70
+ };
71
+ const sameAccount = (one, other) => one.provider === other.provider && one.account === other.account;
72
+ /**
73
+ * The caller's stored account's scope, as a person's context reads: a work profile never reads personal meetings.
74
+ * A caller the store does not hold reads its stated scope, or none.
75
+ */
76
+ const callerScopes = async (all, caller) => {
77
+ const own = all.find((one) => sameAccount(one, caller));
78
+ if (own && caller.scope !== undefined && caller.scope !== own.scope)
79
+ throw new CliError("not_found", `no ${caller.provider} account ${caller.account} in the store`);
80
+ const scope = own?.scope ?? caller.scope;
81
+ return scope === undefined ? [] : [scope];
82
+ };
83
+ /**
84
+ * Meetings for `search all`, from each meeting account's search index: never refreshed here, since search all only
85
+ * reads. A query meetings cannot answer is refused before any account is read; a failure of one account is that
86
+ * account's skip, and the others still answer.
87
+ */
88
+ export const meetingLane = async (store, caller, request) => {
89
+ const all = await store.accounts.storedAccounts();
90
+ const scopes = request.scopes ?? (await callerScopes(all, caller));
91
+ const unknownCaller = request.scopes === undefined && !all.some((one) => sameAccount(one, caller));
92
+ const meetings = all.filter((one) => holdsKind(one.provider, "meetings"));
93
+ const stored = meetings.filter((one) => scopes.includes(one.scope));
94
+ const chosen = request.accounts;
95
+ const read = chosen ? stored.filter((one) => chosen.some((key) => sameAccount(key, one))) : stored;
96
+ const skipped = (chosen ?? [])
97
+ .filter((key) => !read.some((one) => sameAccount(key, one)))
98
+ .map(({ provider, account }) => {
99
+ const other = meetings.find((one) => sameAccount({ provider, account }, one));
100
+ return {
101
+ source: `${provider}:${account}`,
102
+ code: "not_found",
103
+ reason: !other
104
+ ? "no meetings stored for it"
105
+ : unknownCaller
106
+ ? "this account is not in the store yet, so no scope is read"
107
+ : `a ${other.scope} account; this run reads ${scopes.join(" and ")} accounts`,
33
108
  };
34
- if (!supported(parseLucene(text, SEARCH_QUERY).root) || !terms.length)
35
- return {
36
- reason: "meetings support letter/digit words joined by AND; phrases, OR/NOT, patterns and filters are unsupported",
37
- };
38
- return { query: terms.join(" ") };
109
+ });
110
+ const [first] = read;
111
+ // Like events, meetings the store does not hold are no gap in an answer that did not ask for them.
112
+ if (!first) {
113
+ if (!skipped.length && request.asked)
114
+ skipped.push({
115
+ resource: "meetings",
116
+ code: "not_found",
117
+ reason: !meetings.length
118
+ ? "no meeting account stored"
119
+ : unknownCaller
120
+ ? "this account is not in the store yet"
121
+ : "no meeting account in this scope",
122
+ });
123
+ return { items: [], hasMore: false, read, skipped, coverage: [] };
39
124
  }
40
- catch (error) {
41
- if (codeOf(error) !== "validation_error")
42
- throw error;
43
- return { reason: error instanceof Error ? error.message : "invalid meeting search query" };
125
+ const lifted = liftMeetingFields(request.text, { accountId: first.id }, undefined, request.timezone);
126
+ const parsed = parseMeetingQuery(lifted.query);
127
+ const query = request.exact ? { ...parsed, root: exactly(parsed.root) } : parsed;
128
+ const { input } = await resolveMeetingSelection(store, {
129
+ ...lifted.request,
130
+ ...(request.signal ? { signal: request.signal } : {}),
131
+ });
132
+ const lists = [];
133
+ const coverage = [];
134
+ const answered = [];
135
+ for (const account of read) {
136
+ try {
137
+ const found = await accountHits(store, account, query, { ...input, accountId: account.id }, request);
138
+ lists.push(found.ranked);
139
+ coverage.push({ provider: account.provider, account: account.account, ...found.coverage });
140
+ answered.push(account);
141
+ }
142
+ catch (error) {
143
+ if (!(error instanceof CliError) || error.code === "cancelled")
144
+ throw error;
145
+ skipped.push({ source: `${account.provider}:${account.account}`, code: error.code, reason: error.message });
146
+ }
44
147
  }
148
+ return { items: merged(lists), hasMore: coverage.some((one) => one.hasMore), read: answered, skipped, coverage };
45
149
  };
46
- const collectMeetings = async (store, account, request, query) => {
47
- cancelled(request.signal);
48
- const selected = await store.accounts.storedAccount(account);
49
- cancelled(request.signal);
50
- whole(selected.id, 1, Number.MAX_SAFE_INTEGER, "meeting account id");
51
- if (account.scope !== undefined && selected.scope !== account.scope)
52
- throw new CliError("not_found", "the selected meeting account has a different scope");
53
- const cursor = request.meetingCursor;
54
- if (cursor && (cursor.accountId !== selected.id || cursor.query !== query))
55
- throw new CliError("validation_error", "meeting cursor belongs to a different account or query");
56
- let meetingOffset = cursor?.meetingOffset ?? 0;
57
- let hitOffset = cursor?.hitOffset ?? 0;
58
- const position = () => ({ accountId: selected.id, query, meetingOffset, hitOffset });
59
- const collected = {
60
- items: [],
61
- coverage: { accountId: selected.id, by: "word-prefixes", meetingsScanned: 0, complete: false },
62
- after: position(),
63
- };
64
- const seen = new Set();
65
- const most = request.maxMeetings === "all" ? Number.POSITIVE_INFINITY : (request.maxMeetings ?? 100);
66
- while (collected.coverage.meetingsScanned < most) {
67
- cancelled(request.signal);
68
- const page = await store.meetings.meetings({ accountId: selected.id, limit: 2, offset: meetingOffset });
69
- cancelled(request.signal);
70
- const meeting = page[0];
71
- if (!meeting) {
72
- collected.coverage.complete = true;
73
- break;
150
+ /**
151
+ * Every account's hits as one list, each account's own order kept: the better head goes first, so an account with
152
+ * many hits cannot push another's newer or closer ones off the page.
153
+ */
154
+ const merged = (lists) => {
155
+ const heads = lists.map((list) => ({ list, at: 0 }));
156
+ const items = [];
157
+ for (;;) {
158
+ let best;
159
+ for (const one of heads) {
160
+ const head = one.list[one.at];
161
+ const leader = best?.list[best.at];
162
+ if (head && (!leader || head.tier < leader.tier || (head.tier === leader.tier && head.started > leader.started)))
163
+ best = one;
74
164
  }
75
- const hits = await store.meetings.search(query, { accountId: selected.id, limit: 1, offset: meetingOffset });
76
- cancelled(request.signal);
77
- if (meeting.accountId !== selected.id ||
78
- meeting.deletedAt !== null ||
79
- hits.some((hit) => hit.meetingId !== meeting.id))
80
- throw new CliError("validation_error", "meeting archive changed during search; restart from the first page", {
81
- complete: false,
82
- });
83
- if (hitOffset > hits.length)
84
- throw new CliError("validation_error", "meeting cursor is past the current hit list; restart from the first page");
85
- collected.coverage.meetingsScanned++;
86
- for (; hitOffset < hits.length; hitOffset++) {
87
- const hit = hits[hitOffset];
88
- const key = JSON.stringify([selected.id, hit.meetingId, hit.scope, hit.id]);
89
- if (seen.has(key))
90
- continue;
91
- seen.add(key);
92
- collected.items.push({
93
- before: position(),
94
- item: {
95
- kind: "meeting",
96
- ref: formatMeetingReference({ type: "meeting", accountId: selected.id, meetingId: hit.meetingId }),
97
- provider: selected.provider,
98
- account: selected.account,
99
- accountId: selected.id,
100
- title: meeting.title,
101
- timestamp: meeting.startedAt === null ? null : new Date(meeting.startedAt).toISOString(),
102
- text: hit.text.slice(0, 2000),
103
- meetingId: hit.meetingId,
104
- scope: hit.scope,
105
- id: hit.id,
106
- startMs: hit.startMs,
107
- ...(hit.scope === "transcript" && hit.ref !== undefined
108
- ? {
109
- cueRef: hit.ref,
110
- speakerName: hit.speakerName ?? null,
111
- language: hit.language ?? null,
112
- ...(hit.line === undefined ? {} : { line: hit.line, linesTotal: hit.linesTotal }),
113
- }
114
- : {}),
115
- },
165
+ const next = best?.list[best.at];
166
+ if (!best || !next)
167
+ return items;
168
+ items.push(next.item);
169
+ best.at++;
170
+ }
171
+ };
172
+ const accountHits = async (store, account, query, input, { text, window, signal, question, exact }) => {
173
+ const ranked = [];
174
+ const perMeeting = new Map();
175
+ const keep = (one) => {
176
+ const seen = perMeeting.get(one.item.meetingId) ?? 0;
177
+ if (seen >= MOST_HITS_PER_MEETING)
178
+ return false;
179
+ perMeeting.set(one.item.meetingId, seen + 1);
180
+ ranked.push(one);
181
+ return true;
182
+ };
183
+ let indexing = "ready";
184
+ let hasMore = false;
185
+ let passages = 0;
186
+ const titles = titleQuery(query, input, question === true);
187
+ if (titles)
188
+ for (const meeting of await store.meetings.meetings({
189
+ accountId: account.id,
190
+ query: titles,
191
+ ...(input.since === undefined ? {} : { since: input.since }),
192
+ ...(input.until === undefined ? {} : { until: input.until }),
193
+ limit: window + 1,
194
+ }))
195
+ if (!exact || holdsExactly(query.root, titleWords(meeting.title ?? "")))
196
+ keep({ item: titleItem(account, meeting, text), tier: 1, started: meeting.startedAt ?? 0 });
197
+ let after;
198
+ let rows = Math.min(PAGE_ROWS, window + 1);
199
+ for (let page = 1;; page++) {
200
+ let found;
201
+ try {
202
+ found = await store.meetings.searchHits(query, {
203
+ ...input,
204
+ limit: rows,
205
+ ...(after === undefined ? {} : { after }),
116
206
  });
117
- if (collected.items.length > request.limit) {
118
- hitOffset++;
119
- break;
120
- }
121
207
  }
122
- if (hitOffset === hits.length) {
123
- meetingOffset++;
124
- hitOffset = 0;
125
- if (page.length < 2)
126
- collected.coverage.complete = true;
208
+ catch (error) {
209
+ // Long summaries can pass the store's byte budget in a few rows; fewer rows a page still reads the account.
210
+ if (!(error instanceof CliError) || error.message !== READ_BUDGET_EXCEEDED || rows === 1)
211
+ throw error;
212
+ rows = Math.ceil(rows / 2);
213
+ page--;
214
+ continue;
127
215
  }
128
- collected.after = position();
129
- if (collected.coverage.complete || collected.items.length > request.limit)
216
+ signal?.throwIfAborted();
217
+ if (found.coverage.indexing === "pending")
218
+ indexing = "pending";
219
+ for (const hit of found.items)
220
+ if (keep({
221
+ item: meetingItem(account, hit, text),
222
+ tier: hit.match === "corrected" ? 2 : 1,
223
+ started: hit.source?.startedAt ?? 0,
224
+ }))
225
+ passages++;
226
+ // Titles rank among the passages, so the passages alone must reach past the page.
227
+ if (passages > window || !found.hasMore || found.nextCursor === null)
130
228
  break;
229
+ if (page === MOST_PAGES) {
230
+ hasMore = true;
231
+ break;
232
+ }
233
+ after = found.nextCursor;
131
234
  }
132
- return collected;
133
- };
134
- /** Opt-in fusion of the existing unified ranking and one explicitly scoped meeting archive. */
135
- export const searchAllIncludingMeetings = async (store, account, request, messenger = {}, searchMessages, meaning) => {
136
- whole(request.limit, 1, 1000, "limit");
137
- if (request.maxMeetings !== "all")
138
- whole(request.maxMeetings ?? 100, 1, Number.MAX_SAFE_INTEGER, "maxMeetings");
139
- const only = request.only ?? RESOURCES_SEARCHED_WITH_MEETINGS;
140
- if (!only.length ||
141
- only.some((resource) => !RESOURCES_SEARCHED_WITH_MEETINGS.includes(resource)))
142
- throw new CliError("validation_error", "only takes messages, mail, notes, events and meetings");
143
- if (request.meetingCursor) {
144
- if (only.length !== 1 || only[0] !== "meetings")
145
- throw new CliError("validation_error", "meeting cursor requires only: [meetings]");
146
- whole(request.meetingCursor.accountId, 1, Number.MAX_SAFE_INTEGER, "cursor account id");
147
- whole(request.meetingCursor.meetingOffset, 0, Number.MAX_SAFE_INTEGER - 2, "cursor meeting offset");
148
- whole(request.meetingCursor.hitOffset, 0, Number.MAX_SAFE_INTEGER, "cursor hit offset");
149
- }
150
- cancelled(request.signal);
151
- const others = { ...request, only: only.filter((one) => one !== "meetings") };
152
- if (!only.includes("meetings")) {
153
- const found = await searchAll(store, account, others, messenger, searchMessages, meaning);
154
- cancelled(request.signal);
155
- return found;
156
- }
157
- // Meetings rank with the rest, so a later page is the same merge read deeper, then cut.
158
- const offset = request.offset ?? 0;
159
- const window = offset + request.limit;
160
- const legacy = await searchAll(store, account, { ...others, offset: 0, limit: window }, messenger, searchMessages, meaning);
161
- cancelled(request.signal);
162
- const compiled = meetingQuery(request.text, request.exact);
163
- if ("reason" in compiled)
164
- return {
165
- ...legacy,
166
- items: legacy.items.slice(offset),
167
- skipped: [...legacy.skipped, { resource: "meetings", code: "validation_error", reason: compiled.reason }],
168
- };
169
- let meetings;
170
- const meetingAccount = request.meetingAccount ?? account;
171
- try {
172
- meetings = await collectMeetings(store, meetingAccount, { ...request, limit: window }, compiled.query);
173
- }
174
- catch (error) {
175
- if (codeOf(error) !== "not_found")
176
- throw error;
177
- return {
178
- ...legacy,
179
- items: legacy.items.slice(offset),
180
- skipped: [
181
- ...legacy.skipped,
182
- { resource: "meetings", code: "not_found", reason: "the selected meeting account is not stored" },
183
- ],
184
- };
185
- }
186
- const ranked = new Map();
187
- for (const list of [legacy.items, meetings.items.map(({ item }) => item)])
188
- list.forEach((item, rank) => {
189
- const key = item.kind === "meeting"
190
- ? JSON.stringify([item.kind, item.accountId, item.meetingId, item.scope, item.id])
191
- : item.ref;
192
- const held = ranked.get(key) ?? { item, score: 0 };
193
- held.score += 1 / (RRF_K + rank + 1);
194
- ranked.set(key, held);
195
- });
196
- const ordered = [...ranked.values()].sort((a, b) => b.score - a.score).map(({ item }) => item);
197
- const items = ordered.slice(offset, window);
198
- const returnedMeetings = ordered.slice(0, window).filter((item) => item.kind === "meeting").length;
199
- const nextCursor = meetings.items[returnedMeetings]?.before ?? (!meetings.coverage.complete ? meetings.after : undefined);
200
- const more = legacy.hasMore || ordered.length > window;
201
- const { nextOffset: _, ...rest } = legacy;
235
+ // A title hit ranks as a passage that holds the words: by tier, then the newer meeting; sort keeps it before its own.
236
+ ranked.sort((one, other) => one.tier - other.tier || other.started - one.started);
202
237
  return {
203
- ...rest,
204
- items,
205
- hasMore: more ? true : meetings.coverage.complete ? false : null,
206
- ...(more && window <= MAX_SEARCH_OFFSET ? { nextOffset: window } : {}),
207
- searched: [...legacy.searched, "meetings"],
208
- accounts: [
209
- ...legacy.accounts,
210
- { resource: "meetings", provider: meetingAccount.provider, account: meetingAccount.account },
211
- ],
212
- meetings: { ...meetings.coverage, ...(nextCursor ? { nextCursor } : {}) },
238
+ ranked: ranked.slice(0, window),
239
+ coverage: { indexing, hasMore: hasMore || ranked.length > window },
213
240
  };
214
241
  };
215
- /** Meetings have no index to search every account at once, so they are read only when named. */
216
- export const MEETINGS_UNNAMED = "meetings are searched only when --source names a meeting account, zoom or meetings";
217
- /** `search all`: every kind but meetings, unless `--source` names a meeting account. */
218
- export const searchAllWithMeetings = async (store, account, request, messenger = {}, searchMessages, meaning) => {
219
- if (request.source !== undefined)
220
- return searchAllOfSource(store, account, request.source, request, messenger, searchMessages, meaning);
221
- const only = request.only ?? RESOURCES_SEARCHED_WITH_MEETINGS;
222
- if (only.length === 1 && only[0] === "meetings")
223
- throw new CliError("validation_error", `--only meetings: ${MEETINGS_UNNAMED}`);
224
- if (request.maxMeetings !== undefined)
225
- throw new CliError("validation_error", `--max-meetings: ${MEETINGS_UNNAMED}`);
226
- const found = await searchAll(store, account, { ...request, only: only.filter((resource) => resource !== "meetings") }, messenger, searchMessages, meaning);
227
- return only.includes("meetings")
242
+ const meetingItem = (account, hit, query) => ({
243
+ kind: "meeting",
244
+ ref: formatMeetingReference({ type: "meeting", accountId: account.id, meetingId: hit.meetingId }),
245
+ provider: account.provider,
246
+ account: account.account,
247
+ accountId: account.id,
248
+ title: hit.source?.title ?? null,
249
+ timestamp: typeof hit.source?.startedAt === "number" ? new Date(hit.source.startedAt).toISOString() : null,
250
+ // Centred on the words the index matched: another form, a garbled spelling, never a word only under NOT.
251
+ text: hit.matchedWords?.length
252
+ ? excerpt(hit.text, hit.matchedWords.join(" "), 240, { literal: true })
253
+ : excerpt(hit.text, query),
254
+ meetingId: hit.meetingId,
255
+ scope: hit.scope,
256
+ id: hit.id,
257
+ startMs: hit.startMs,
258
+ foundBy: ["words"],
259
+ ...(hit.match === "corrected" ? { match: hit.match, corrections: hit.corrections ?? [] } : {}),
260
+ ...(hit.scope === "transcript"
228
261
  ? {
229
- ...found,
230
- skipped: [...found.skipped, { resource: "meetings", code: "validation_error", reason: MEETINGS_UNNAMED }],
262
+ cueRef: hit.ref,
263
+ speakerName: hit.speakerName ?? null,
264
+ language: hit.language ?? null,
265
+ ...(hit.line === undefined ? {} : { line: hit.line, linesTotal: hit.linesTotal }),
231
266
  }
232
- : found;
233
- };
234
- /** Of several meeting accounts, the ones that hold meetings: a bare `zoom` names every row, signed in or not. */
235
- const holdingMeetings = async (store, named) => {
236
- if (named.length < 2)
237
- return named;
238
- const holding = [];
239
- for (const key of named) {
240
- const { id } = await store.accounts.storedAccount(key);
241
- if ((await store.meetings.meetings({ accountId: id, limit: 1 })).length)
242
- holding.push(key);
243
- }
244
- return holding.length ? holding : named;
245
- };
246
- const keyOf = ({ provider, account }) => `${provider}\u0000${account}`;
247
- const searchAllOfSource = async (store, account, source, request, messenger, searchMessages, meaning) => {
248
- const only = request.only ?? RESOURCES_SEARCHED_WITH_MEETINGS;
249
- const entries = entriesOfList(source, await listContextOf(store, account, messenger.app));
250
- // Any provider's import may write business data, so its accounts are the ones that hold some, whatever their kind.
251
- const imported = only.includes("business") ? new Set((await store.business.accounts()).map(keyOf)) : new Set();
252
- const holdsBusiness = (one) => imported.has(keyOf(one));
253
- const { skipped } = fitting(entries, only.filter((one) => one !== "business"), "search all", (kind) => `--only leaves ${kind} out`, holdsBusiness);
254
- const named = (resource) => [
255
- ...new Map(entries
256
- .flatMap(({ accounts }) => accounts)
257
- .filter((one) => (resource === "business" ? holdsBusiness(one) : listedHolds(one, resource)))
258
- .map(({ provider, account }) => [`${provider}\u0000${account}`, { provider, account }])).values(),
259
- ];
260
- const meetings = await holdingMeetings(store, named("meetings"));
261
- const empty = named("meetings")
262
- .filter((one) => !meetings.some(({ provider, account }) => provider === one.provider && account === one.account))
263
- .map(({ provider, account }) => ({
264
- source: `${provider}:${account}`,
265
- code: "not_found",
266
- reason: "no meetings stored for it",
267
- }));
268
- if (only.includes("meetings") && meetings.length > 1)
269
- throw new CliError("validation_error", `--source names several meeting accounts; search all reads one: ${meetings.map(({ provider, account }) => `${provider}:${account}`).join(", ")}`);
270
- const read = only.filter((resource) => named(resource).length > 0);
271
- if (read.includes("meetings") && request.offset !== undefined)
272
- throw new CliError("validation_error", "--offset pages messages, mail and notes; not with a meeting account yet");
273
- const found = await searchAllIncludingMeetings(store, account, {
274
- ...request,
275
- only: read,
276
- scope: {
277
- messages: named("messages"),
278
- mail: named("mail"),
279
- notes: named("notes"),
280
- events: named("events"),
281
- crm: named("crm"),
282
- business: named("business"),
283
- },
284
- ...(meetings[0] ? { meetingAccount: meetings[0] } : {}),
285
- }, messenger, searchMessages, meaning);
286
- const unnamed = only
287
- .filter((resource) => !read.includes(resource))
288
- .map((resource) => ({ resource, code: "not_found", reason: `--source names no ${resource} account` }));
289
- return { ...found, skipped: [...skipped, ...empty, ...unnamed, ...found.skipped] };
290
- };
267
+ : {}),
268
+ });
269
+ const titleItem = (account, meeting, query) => ({
270
+ kind: "meeting",
271
+ ref: formatMeetingReference({ type: "meeting", accountId: account.id, meetingId: meeting.id }),
272
+ provider: account.provider,
273
+ account: account.account,
274
+ accountId: account.id,
275
+ title: meeting.title,
276
+ timestamp: meeting.startedAt === null ? null : new Date(meeting.startedAt).toISOString(),
277
+ text: excerpt(meeting.title ?? "", query),
278
+ meetingId: meeting.id,
279
+ scope: "title",
280
+ id: meeting.id,
281
+ startMs: null,
282
+ foundBy: ["title"],
283
+ });