@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
@@ -0,0 +1,20 @@
1
+ import { isTextModelInstalled, textModelsDirectory } from "../embeddings/embed.js";
2
+ import { chosenTextModel, DEFAULT_TEXT_MODEL, PREVIOUS_DEFAULT_TEXT_MODEL, textModels, vectorModelKey, } from "../embeddings/models.js";
3
+ /**
4
+ * The model a search by meaning reads. A model the owner chose, always. With none chosen, the default, unless this
5
+ * store still holds more vectors of the previous default: so after EmbeddingGemma became the default, search keeps
6
+ * reading e5-small's vectors while the syncs embed the store again, and moves to Gemma once it has caught up.
7
+ */
8
+ export const meaningModel = async (store, env = process.env) => {
9
+ const chosen = chosenTextModel(env);
10
+ if (chosen.from === "chosen" || chosen.id !== DEFAULT_TEXT_MODEL)
11
+ return chosen.id;
12
+ const models = textModels(env);
13
+ const current = models.find(({ id }) => id === DEFAULT_TEXT_MODEL);
14
+ const previous = models.find(({ id }) => id === PREVIOUS_DEFAULT_TEXT_MODEL);
15
+ if (!current || !previous || !isTextModelInstalled(previous, textModelsDirectory(env)))
16
+ return chosen.id;
17
+ const [now, before] = [vectorModelKey(current), vectorModelKey(previous)];
18
+ const counts = await store.vectors.vectorCounts([now, before]);
19
+ return (counts.get(before) ?? 0) > (counts.get(now) ?? 0) ? previous.id : current.id;
20
+ };
@@ -3,9 +3,14 @@ import type { AccountKey, AccountsStore, MessageStore } from "../store/store.js"
3
3
  export type MeetingContextServiceStore = Pick<MessageStore, "meetings" | "notes" | "knowledge" | "memories" | "facts"> & {
4
4
  accounts: Pick<AccountsStore, "storedAccount">;
5
5
  };
6
- /** Reuses the owner's records; scoped meeting references are checked again by each native write. */
6
+ /**
7
+ * Reuses the owner's records; scoped meeting references are checked again by each native write. `author` says who
8
+ * runs it: an agent's participant link, memory and fact wait for the owner as proposals. Left out, the run is taken
9
+ * for an agent's, so a caller that never said who runs it cannot write as the owner.
10
+ */
7
11
  export declare const createMeetingContextService: (store: MeetingContextServiceStore, input: AccountKey, options?: {
8
12
  now?: () => number;
13
+ author?: "owner" | "agent";
9
14
  }) => Promise<{
10
15
  scope: Readonly<import("../meetings/provider.js").MeetingProviderScope>;
11
16
  accountId: number;
@@ -10,9 +10,16 @@ const checkCancelled = (signal) => {
10
10
  const timeout = signal.reason instanceof Error && signal.reason.name === "TimeoutError";
11
11
  throw new CliError(timeout ? "timeout" : "cancelled", "meeting context was interrupted");
12
12
  };
13
- /** Reuses the owner's records; scoped meeting references are checked again by each native write. */
13
+ /**
14
+ * Reuses the owner's records; scoped meeting references are checked again by each native write. `author` says who
15
+ * runs it: an agent's participant link, memory and fact wait for the owner as proposals. Left out, the run is taken
16
+ * for an agent's, so a caller that never said who runs it cannot write as the owner.
17
+ */
14
18
  export const createMeetingContextService = async (store, input, options = {}) => {
15
19
  const now = options.now ?? Date.now;
20
+ const author = options.author ?? "agent";
21
+ // An agent's memory or fact waits as proposed, as the memory and fact stores keep any agent's.
22
+ const writer = author === "owner" ? "owner" : { bot: "agent" };
16
23
  const scope = snapshotMeetingScope(input);
17
24
  const key = Object.freeze({ ...scope, ...(input.scope === undefined ? {} : { scope: input.scope }) });
18
25
  const account = await store.accounts.storedAccount(key);
@@ -59,8 +66,8 @@ export const createMeetingContextService = async (store, input, options = {}) =>
59
66
  scope: change.scope,
60
67
  evidence: meetingReferences(change.evidence),
61
68
  subject: change.subject === undefined ? reference : meetingReferences([change.subject])[0],
62
- status: "confirmed",
63
- author: "owner",
69
+ status: writer === "owner" ? "confirmed" : "proposed",
70
+ author: writer,
64
71
  });
65
72
  case "fact.add":
66
73
  return store.facts.add({
@@ -69,7 +76,7 @@ export const createMeetingContextService = async (store, input, options = {}) =>
69
76
  scope: change.scope,
70
77
  evidence: meetingReferences(change.evidence),
71
78
  subject: change.subject === undefined ? reference : meetingReferences([change.subject])[0],
72
- by: "owner",
79
+ by: writer,
73
80
  });
74
81
  case "event.link":
75
82
  return store.meetings.linkMeetingEvent({
@@ -87,7 +94,7 @@ export const createMeetingContextService = async (store, input, options = {}) =>
87
94
  participantId: change.participantId,
88
95
  personUid: change.personUid,
89
96
  now: now(),
90
- author: "owner",
97
+ author,
91
98
  ...(change.expectedPersonUid === undefined ? {} : { expectedPersonUid: change.expectedPersonUid }),
92
99
  ...(change.targetAccountIds === undefined ? {} : { targetAccountIds: change.targetAccountIds }),
93
100
  ...(operation.signal ? { signal: operation.signal } : {}),
@@ -1,5 +1,6 @@
1
1
  import { CliError, singleLine } from "@wirecat/cli-base";
2
2
  import { chatReferenceOf, ensureAccount } from "../domain/ref-arguments.js";
3
+ import { profilesOn } from "../domain/ref-summaries.js";
3
4
  import { isId, pickChat, pickPerson } from "../resolve.js";
4
5
  import { codeOf } from "../sends/guarded.js";
5
6
  import { nothingStored } from "./deps.js";
@@ -78,9 +79,7 @@ const leftIn = ({ items }) => items.some((one) => one.membershipState === "left"
78
79
  export const profilesOnAccount = (store, app, provider) => async (account) => {
79
80
  if (app === undefined)
80
81
  return undefined;
81
- return Object.entries((await store.accounts.profiles())[app] ?? {})
82
- .filter(([, key]) => key.provider === provider && key.account === account)
83
- .map(([name]) => name);
82
+ return profilesOn(await store.accounts.profiles(), app, { provider, account });
84
83
  };
85
84
  /** `left` is given where a left chat is refused; it lets a numeric id the store does not hold through as typed. */
86
85
  const chatIdAmong = async (messenger, reference, account, { held, renamed, left, profilesOn, }) => {
@@ -1,11 +1,11 @@
1
1
  import { CliError } from "@wirecat/cli-base";
2
2
  import { parseLucene } from "@wirecat/cli-base/query";
3
- import { chosenTextModel } from "../embeddings/models.js";
4
3
  import { meaningWords } from "../search/lucene/meaning-parts.js";
5
4
  import { validateFields } from "../search/lucene/registry.js";
6
5
  import { SEARCH_QUERY } from "../search/lucene/types.js";
7
6
  import { questionLookup, questionText } from "../search/question-plan.js";
8
7
  import { embeddingTarget, withEmbedder } from "./embeddings-maintenance.js";
8
+ import { meaningModel } from "./meaning-model.js";
9
9
  import { MEANING_DEPTH } from "./messages-discovery.js";
10
10
  import { plainWords } from "./pictures.js";
11
11
  // The text notes embed: `search all` compares cosines across sources, so all must embed one text (IDEA-249).
@@ -27,14 +27,13 @@ const meaningText = (question) => {
27
27
  * on disk and vectors exist — never a download, never a remote model — and any failure leaves the words alone.
28
28
  */
29
29
  export const meaningLane = (deps) => async (question, accounts, shared, within) => {
30
- const model = chosenTextModel(deps.env).id;
31
- const target = embeddingTarget(deps, model);
30
+ const store = await deps.store();
31
+ const target = embeddingTarget(deps, await meaningModel(store, deps.env));
32
32
  const skipped = (reason, step) => ({
33
33
  skipped: { reason, model: target.id, ...(step ? { step } : {}) },
34
34
  });
35
35
  if (!target.installed)
36
36
  return skipped(`${target.id} is not downloaded`, "models.download");
37
- const store = await deps.store();
38
37
  const ready = [];
39
38
  const without = [];
40
39
  // Mail keeps its vectors by thread, not by message: its accounts are read through the mail store.
@@ -83,7 +82,7 @@ export const meaningLane = (deps) => async (question, accounts, shared, within)
83
82
  if (shared && !deps.embedders)
84
83
  await lookUp(await shared.get(target.key, () => target.open()));
85
84
  else
86
- await withEmbedder(deps, target, model, {}, lookUp);
85
+ await withEmbedder(deps, target, target.id, {}, lookUp);
87
86
  }
88
87
  if (ranked.length === 0 && without.length === accounts.length)
89
88
  return skipped("no message has a vector yet", "conversations.rebuild");
@@ -102,6 +102,8 @@ export interface Prepared {
102
102
  }
103
103
  export declare const prepareLucene: (store: MessageStore, account: AccountKey, request: SearchQuery, messenger: Partial<Pick<MessengerTraits, "savedChatId" | "app">> & {
104
104
  messageStars?: boolean;
105
+ /** The run's environment, where a group lock is read (WC-ACCT-13). */
106
+ env?: NodeJS.ProcessEnv;
105
107
  }) => Promise<Prepared>;
106
108
  /**
107
109
  * The stemmer a search with stemmed words runs with. While the stems are built, or chosen by a newer
@@ -118,7 +120,9 @@ export declare const coverageOf: (store: MessageStore, { scopeAccounts, selected
118
120
  completeness: (ChatCompleteness & AccountKey)[];
119
121
  coverage: SearchCoverage;
120
122
  }>;
121
- export declare const searchLucene: (store: MessageStore, account: AccountKey, request: SearchQuery, messenger?: Partial<Pick<MessengerTraits, "savedChatId" | "app" | "history" | "provider">>) => Promise<SearchFound>;
123
+ export declare const searchLucene: (store: MessageStore, account: AccountKey, request: SearchQuery, messenger?: Partial<Pick<MessengerTraits, "savedChatId" | "app" | "history" | "provider">> & {
124
+ env?: NodeJS.ProcessEnv;
125
+ }) => Promise<SearchFound>;
122
126
  /**
123
127
  * How many messages the query matches, mail included, each counted no further than `cap + 1`; `undefined` when only
124
128
  * the search itself could tell.
@@ -60,7 +60,7 @@ export const prepareLucene = async (store, account, request, messenger) => {
60
60
  const sources = positiveSources(ast.root).map((value) => sourceOf("in:", value, providers));
61
61
  for (const leaf of leaves.filter(({ field }) => field === "in"))
62
62
  sourceOf("in:", leaf.value, providers);
63
- const listed = await listedAccounts(store, account, request.source, messenger.app, request.kind);
63
+ const listed = await listedAccounts(store, account, request.source, messenger.app, request.kind, messenger.env);
64
64
  const source = request.source === undefined || listed ? undefined : sourceOf("--source", request.source, providers);
65
65
  if (request.accounts !== undefined && (request.source !== undefined || sources.length > 0))
66
66
  throw new CliError("validation_error", "this search reads the accounts it was given — not with in: or --source");
@@ -12,7 +12,6 @@ import type { MeaningSkipped, RerankSkipped } from "./messages-discovery.js";
12
12
  import type { MessageStats, QueryMetadata, SearchCoverage, StatsGrouping } from "./messages-search.js";
13
13
  import type { PictureHit } from "./pictures.js";
14
14
  import { type SearchAllFound, type SearchAllRequest } from "./search-all.js";
15
- import { type SearchAllIncludingMeetingsFound, type SearchAllWithMeetingsRequest } from "./search-all-meetings.js";
16
15
  import type { SearchKind } from "./search-kind.js";
17
16
  import { type SearchRefreshed, type SyncOptions } from "./search-refresh.js";
18
17
  import { type Backend, type HitSource, type ServerOptions, type ServerSearched } from "./server-search.js";
@@ -222,10 +221,8 @@ export interface MessagesService {
222
221
  keepDownloaded(chat: string, message: Id, files: readonly DownloadedFile[]): Promise<number>;
223
222
  /** From the local store only; never asks the messenger. */
224
223
  search(query: SearchQuery): Promise<SearchFound>;
225
- /** Messages, mail and notes at once; messages with the same server step `search` takes. */
224
+ /** Every kind the store holds at once; messages with the same server step `search` takes. */
226
225
  searchAll(request: SearchAllRequest): Promise<SearchAllFound>;
227
- /** `searchAll` plus one meeting account's transcripts, chat and summaries. */
228
- searchAllWithMeetings(request: SearchAllWithMeetingsRequest): Promise<SearchAllIncludingMeetingsFound>;
229
226
  /** Counts of what a strict query matches, by chat, sender, day or hour; from the local store only. */
230
227
  stats(query: SearchQuery & {
231
228
  by: StatsGrouping;
@@ -16,7 +16,6 @@ import { accountOf, keyOf, searchStore, statsStore, topUp } from "./messages-arc
16
16
  import { meaningLane } from "./messages-meaning.js";
17
17
  import { rerankLane } from "./messages-rerank.js";
18
18
  import { searchAll } from "./search-all.js";
19
- import { searchAllWithMeetings, } from "./search-all-meetings.js";
20
19
  import { searchRecordOf } from "./search-record.js";
21
20
  import { refreshSearch, withRefresh } from "./search-refresh.js";
22
21
  import { searchServer, sourceKey, } from "./server-search.js";
@@ -269,7 +268,6 @@ export const messagesService = (deps) => {
269
268
  });
270
269
  },
271
270
  searchAll: (request) => inStore((store, account) => searchAll(store, account, request, deps.messenger, unifiedMessages(store, account), meaningLane(deps))),
272
- searchAllWithMeetings: (request) => inStore((store, account) => searchAllWithMeetings(store, account, request, deps.messenger, unifiedMessages(store, account), meaningLane(deps))),
273
271
  stats: (query) => inStore(async (store, account) => {
274
272
  const refreshed = await refreshSearch(deps, query);
275
273
  const stats = await statsStore(store, account, query, deps.messenger);
@@ -14,12 +14,12 @@ export declare const metadataService: (deps: ServiceDeps) => {
14
14
  dryRun?: boolean;
15
15
  }) => Promise<{
16
16
  items: ({
17
+ error?: undefined;
17
18
  chatId: string;
18
19
  tags: import("../domain/channel-tags.js").ChannelTagMatch[];
19
20
  algorithm: string;
20
21
  fetchedAt: string | null;
21
22
  source: string;
22
- error?: undefined;
23
23
  } | {
24
24
  tags?: undefined;
25
25
  algorithm?: undefined;
@@ -15,7 +15,7 @@ export interface DownloadedModel<M> {
15
15
  * The text embedding model into the shared models folder, checked against the sha256 this version expects and
16
16
  * loaded once on a word. Nothing is downloaded when it is already there; it is still loaded.
17
17
  */
18
- export declare const downloadTextModel: (id: string, { env, progress, bytes, acceptTerms }: ModelDownloadOptions & {
18
+ export declare const downloadTextModel: (id: string, { env, progress, bytes }: ModelDownloadOptions & {
19
19
  acceptTerms?: boolean;
20
20
  }) => Promise<DownloadedModel<TextModel>>;
21
21
  /** A reranker, the same way as {@link downloadTextModel}, into the same folder. */
@@ -1,3 +1,5 @@
1
+ import { writeFileSync } from "node:fs";
2
+ import { join } from "node:path";
1
3
  import { CliError } from "@wirecat/cli-base";
2
4
  import { isTextModelInstalled, placedText, textModelsDirectory } from "../embeddings/embed.js";
3
5
  import { rerankModel, textModel } from "../embeddings/models.js";
@@ -21,16 +23,16 @@ const nativeRuntime = async ({ env, progress = () => { } }) => {
21
23
  * The text embedding model into the shared models folder, checked against the sha256 this version expects and
22
24
  * loaded once on a word. Nothing is downloaded when it is already there; it is still loaded.
23
25
  */
24
- export const downloadTextModel = async (id, { env, progress = () => { }, bytes, acceptTerms = false }) => {
26
+ export const downloadTextModel = async (id, { env, progress = () => { }, bytes }) => {
25
27
  const model = textModel(id, env);
26
- if (model.terms && !acceptTerms) {
27
- throw new CliError("validation_error", `${model.id} comes under the ${model.licence} (${model.terms}): read them, then run this again with --accept-terms`);
28
- }
29
28
  const directory = textModelsDirectory(env);
30
29
  if (!isTextModelInstalled(model, directory)) {
31
30
  progress(`${model.id}: ${megabytes(bytesOf(model))} from Hugging Face`);
32
31
  await installFiles(placedText(model, directory), { progress, ...(bytes ? { bytes } : {}) });
33
32
  }
33
+ // The licence asks for a notice with each copy, not for a click: it is kept beside the files.
34
+ if (model.notice)
35
+ writeFileSync(join(directory, model.id, "NOTICE"), `${model.notice}\n`);
34
36
  await nativeRuntime({ env, progress });
35
37
  progress(`${model.id}: loading it once to check it works`);
36
38
  const { openEmbedder } = await import("../embeddings/embed.js");
@@ -0,0 +1,73 @@
1
+ import type { FinancePayment, Invoice, Order } from "../store/index.js";
2
+ import { type Section } from "./business-context.js";
3
+ /** How a row reached the context: through the project, or as the organization's own invoice or payment. */
4
+ export type LinkedBy = "project" | "counterparty";
5
+ export interface InvoiceLine {
6
+ ref: string;
7
+ title: string;
8
+ direction: Invoice["direction"];
9
+ /** As stored: an invoice is paid only by confirmed payments allocated to it. */
10
+ status: Invoice["status"];
11
+ /** Only confirmed rows are totalled; a proposed one is listed and waits for the owner. */
12
+ review: Invoice["review"];
13
+ currency: string;
14
+ total: string;
15
+ open: string;
16
+ dueDate: string | null;
17
+ linkedBy: LinkedBy[];
18
+ }
19
+ export interface PaymentLine {
20
+ ref: string;
21
+ title: string;
22
+ direction: FinancePayment["direction"];
23
+ review: FinancePayment["review"];
24
+ currency: string;
25
+ amount: string;
26
+ date: string;
27
+ linkedBy: LinkedBy[];
28
+ }
29
+ export interface OrderLine {
30
+ ref: string;
31
+ title: string;
32
+ status: Order["status"];
33
+ review: Order["review"];
34
+ currency: string | null;
35
+ total: string | null;
36
+ /** The organization is the order's customer or its supplier. */
37
+ side: "customer" | "supplier";
38
+ }
39
+ /** Confirmed rows summed per status (or direction) and currency: nothing is converted. */
40
+ export interface FinanceTotal {
41
+ status: string;
42
+ currency: string;
43
+ rows: number;
44
+ total: string;
45
+ /** Of invoices: still owed. */
46
+ open?: string;
47
+ }
48
+ export interface MoneySection {
49
+ invoices: Section<InvoiceLine>;
50
+ payments: Section<PaymentLine>;
51
+ orders?: Section<OrderLine>;
52
+ totals: {
53
+ invoices: FinanceTotal[];
54
+ payments: FinanceTotal[];
55
+ };
56
+ /** Invoices and payments still proposed, of every row read: listed, never totalled. */
57
+ unconfirmed: number;
58
+ /** `false` when a read stopped at the store's page: the totals may leave rows out. */
59
+ complete: boolean;
60
+ }
61
+ /**
62
+ * Invoices and payments as the finance store holds them, totalled per status and currency. A payment is never
63
+ * inferred from an invoice, nor an invoice's state from a deal's stage: only what the store records.
64
+ */
65
+ export declare const moneyOf: (rows: {
66
+ invoices: [Invoice, LinkedBy][];
67
+ payments: [FinancePayment, LinkedBy][];
68
+ orders?: OrderLine[];
69
+ }, limit: number, next: {
70
+ invoices: string | null;
71
+ payments: string | null;
72
+ orders?: string | null;
73
+ }, complete: boolean) => MoneySection;
@@ -0,0 +1,77 @@
1
+ import { formatDecimal, minorUnits, scaleOf } from "../domain/money.js";
2
+ import { sectionOf } from "./business-context.js";
3
+ const invoiceLine = (invoice, linkedBy) => ({
4
+ ref: invoice.ref,
5
+ title: invoice.title,
6
+ direction: invoice.direction,
7
+ status: invoice.status,
8
+ review: invoice.review,
9
+ currency: invoice.currency,
10
+ total: invoice.total,
11
+ open: invoice.open,
12
+ dueDate: invoice.dueDate,
13
+ linkedBy: [linkedBy],
14
+ });
15
+ const paymentLine = (payment, linkedBy) => ({
16
+ ref: payment.ref,
17
+ title: payment.title,
18
+ direction: payment.direction,
19
+ review: payment.review,
20
+ currency: payment.currency,
21
+ amount: payment.amount,
22
+ date: payment.date,
23
+ linkedBy: [linkedBy],
24
+ });
25
+ /** Each row once, with every way it was reached. */
26
+ const merged = (rows) => {
27
+ const byRef = new Map();
28
+ for (const row of rows) {
29
+ const held = byRef.get(row.ref);
30
+ if (!held)
31
+ byRef.set(row.ref, { ...row, linkedBy: [...row.linkedBy] });
32
+ else
33
+ for (const way of row.linkedBy)
34
+ if (!held.linkedBy.includes(way))
35
+ held.linkedBy.push(way);
36
+ }
37
+ return [...byRef.values()];
38
+ };
39
+ const totalled = (rows) => {
40
+ const totals = new Map();
41
+ for (const row of rows) {
42
+ if (!row.confirmed)
43
+ continue;
44
+ const key = `${row.status}|${row.currency}`;
45
+ const held = totals.get(key) ?? { status: row.status, currency: row.currency, rows: 0, units: 0 };
46
+ held.rows += 1;
47
+ held.units += minorUnits(row.amount, row.currency);
48
+ if (row.open !== undefined)
49
+ held.open = (held.open ?? 0) + minorUnits(row.open, row.currency);
50
+ totals.set(key, held);
51
+ }
52
+ return [...totals.values()].map(({ units, open, ...total }) => ({
53
+ ...total,
54
+ total: formatDecimal(units, scaleOf(total.currency)),
55
+ ...(open === undefined ? {} : { open: formatDecimal(open, scaleOf(total.currency)) }),
56
+ }));
57
+ };
58
+ /**
59
+ * Invoices and payments as the finance store holds them, totalled per status and currency. A payment is never
60
+ * inferred from an invoice, nor an invoice's state from a deal's stage: only what the store records.
61
+ */
62
+ export const moneyOf = (rows, limit, next, complete) => {
63
+ const invoices = merged(rows.invoices.map(([invoice, way]) => invoiceLine(invoice, way)));
64
+ const payments = merged(rows.payments.map(([payment, way]) => paymentLine(payment, way)));
65
+ const more = { more: !complete };
66
+ return {
67
+ invoices: sectionOf(invoices, limit, next.invoices, more),
68
+ payments: sectionOf(payments, limit, next.payments, more),
69
+ ...(rows.orders === undefined ? {} : { orders: sectionOf(rows.orders, limit, next.orders ?? null, more) }),
70
+ totals: {
71
+ invoices: totalled(invoices.map((one) => ({ ...one, amount: one.total, confirmed: one.review === "confirmed" }))),
72
+ payments: totalled(payments.map((one) => ({ ...one, status: one.direction, confirmed: one.review === "confirmed" }))),
73
+ },
74
+ unconfirmed: [...invoices, ...payments].filter((one) => one.review !== "confirmed").length,
75
+ complete,
76
+ };
77
+ };
@@ -61,11 +61,13 @@ export interface NotesEmbedded {
61
61
  /** Chunks still without a vector, when `maxChunks` stopped the run, or records still to enrich. */
62
62
  left: boolean;
63
63
  /** What the owner's enrichment did first; absent when it is off. */
64
+ /** The run, or `failed` with no counts when enrichment threw before it could count. */
64
65
  enrichment?: Exclude<EnrichRun, {
65
66
  status: "off";
66
67
  }> | {
67
68
  status: "failed";
68
69
  reason: string;
70
+ reason_id: "enrichment.error";
69
71
  };
70
72
  }
71
73
  export declare const localModel: (choice: string | undefined, env: NodeJS.ProcessEnv | undefined, command: string | undefined) => {
@@ -217,8 +219,9 @@ export interface NotesFoundOf extends NotesFound {
217
219
  * `search notes` with `--source`: the notes accounts the list names — `notes:internal`, `notes:<folder id>`, `notes`
218
220
  * — and every entry naming none of them in `skipped`. Without a list, every notes account `type` leaves in.
219
221
  */
220
- export declare const searchNotesOf: (store: MessageStore, account: AccountKey, text: string, { accounts: list, app, ...query }: Omit<NotesQuery, "folderIds" | "withInternal"> & {
222
+ export declare const searchNotesOf: (store: MessageStore, account: AccountKey, text: string, { accounts: list, app, env, ...query }: Omit<NotesQuery, "folderIds" | "withInternal"> & {
221
223
  accounts?: string;
222
224
  app?: AppIdentity;
225
+ env?: NodeJS.ProcessEnv;
223
226
  }) => Promise<NotesFoundOf>;
224
227
  export {};
@@ -5,7 +5,8 @@ import { normalizeTag } from "../domain/tags.js";
5
5
  import { defaultThreads, isTextModelInstalled, openEmbedder, textModelsDirectory, } from "../embeddings/embed.js";
6
6
  import { chosenTextModel, meaningFloor, textModel, vectorModelKey } from "../embeddings/models.js";
7
7
  import { DEFAULT_IMAGE_MODEL, imageModel } from "../images/picture/models.js";
8
- import { entriesOfList, fitting } from "../search/account-list.js";
8
+ import { entriesOfList, fitting, sourceOf } from "../search/account-list.js";
9
+ import { OWNER_NOTES } from "../search/groups.js";
9
10
  import { fieldsOfQuery as fieldsOf, meaningWords } from "../search/lucene/meaning-parts.js";
10
11
  import { plainQuery } from "../search/lucene/plain.js";
11
12
  import { validateFields } from "../search/lucene/registry.js";
@@ -17,9 +18,10 @@ import { TOTAL_CAP, totalOf } from "../search/total.js";
17
18
  import { openPictureEmbedderFor } from "./document-pictures.js";
18
19
  import { documentSource } from "./document-source.js";
19
20
  import { enrichRecords } from "./enrichment.js";
21
+ import { meaningModel } from "./meaning-model.js";
20
22
  import { plainQueryWords, titleQuery, titleTiers } from "./notes-title-tier.js";
21
23
  import { PICTURE_FLOOR, plainWords } from "./pictures.js";
22
- import { listContextOf } from "./search-kind.js";
24
+ import { groupLockOf, listContextOf } from "./search-kind.js";
23
25
  /**
24
26
  * Text in the query language messages use, parsed for a store search: `date:` read in `timezone`, and the store's
25
27
  * stemmer when a word is stemmed.
@@ -139,7 +141,11 @@ const enrichedFirst = async (store, types, options, embed) => {
139
141
  enrichment = run;
140
142
  }
141
143
  catch (error) {
142
- enrichment = { status: "failed", reason: error instanceof Error ? error.message : "enrichment failed" };
144
+ enrichment = {
145
+ status: "failed",
146
+ reason: error instanceof Error ? error.message : "enrichment failed",
147
+ reason_id: "enrichment.error",
148
+ };
143
149
  }
144
150
  let embedded;
145
151
  try {
@@ -175,7 +181,7 @@ export const nearestNotes = async (store, query, options) => {
175
181
  const queryVector = async (store, query, { model: choice, folderIds, withInternal, source, env, threads, command, embedders }) => {
176
182
  if (!query.trim())
177
183
  throw new CliError("validation_error", "say what to find in the notes");
178
- const { model, directory, key } = localModel(choice, env, command);
184
+ const { model, directory, key } = localModel(choice ?? (await meaningModel(store, env)), env, command);
179
185
  const scope = {
180
186
  ...(folderIds ? { folderIds } : {}),
181
187
  ...(withInternal ? { withInternal: true } : {}),
@@ -556,7 +562,7 @@ export const notesScopeOf = (accounts) => {
556
562
  * `search notes` with `--source`: the notes accounts the list names — `notes:internal`, `notes:<folder id>`, `notes`
557
563
  * — and every entry naming none of them in `skipped`. Without a list, every notes account `type` leaves in.
558
564
  */
559
- export const searchNotesOf = async (store, account, text, { accounts: list, app, ...query }) => {
565
+ export const searchNotesOf = async (store, account, text, { accounts: list, app, env, ...query }) => {
560
566
  text = plainQuery(text);
561
567
  const own = app?.command ?? query.command;
562
568
  const what = `${own === undefined ? "" : `${own} `}search notes`;
@@ -566,9 +572,15 @@ export const searchNotesOf = async (store, account, text, { accounts: list, app,
566
572
  ...(await store.notes.documentsAccounts()).map(({ id }) => ({ provider: "notes", account: id })),
567
573
  ...[await store.notes.addedAccount()].flatMap((added) => (added ? [{ provider: "notes", account: added.id }] : [])),
568
574
  ];
569
- const named = list === undefined
575
+ const lock = groupLockOf(app, env);
576
+ const typedScope = list ?? (lock === undefined ? undefined : `group:${lock}`);
577
+ // memo's own notes are the owner's, so a group reads them beside its folders (WC-ACCT-13).
578
+ const notesScope = typedScope !== undefined && /(^|,)\s*group:/i.test(typedScope)
579
+ ? `${typedScope},${sourceOf(OWNER_NOTES)}`
580
+ : typedScope;
581
+ const named = notesScope === undefined
570
582
  ? { accounts: held, skipped: [] }
571
- : fitting(entriesOfList(list, await listContextOf(store, account, app)), ["notes", "documents"], what);
583
+ : fitting(entriesOfList(notesScope, await listContextOf(store, account, app, undefined, env)), ["notes", "documents"], what);
572
584
  const source = query.source ?? noteSourceOfQuery(text).source;
573
585
  const typed = named.accounts.filter(({ account }) => source === undefined || (account === INTERNAL_NOTES) === (source === "internal"));
574
586
  if (!typed.length && list !== undefined)
@@ -0,0 +1,80 @@
1
+ import { type DealKind } from "../domain/deals.js";
2
+ import type { AccountKey, Deal, MessageStore, Organization } from "../store/index.js";
3
+ import { type Category, type Coverage, type Related, type Section } from "./business-context.js";
4
+ import { type Communications } from "./communications.js";
5
+ import { type MoneySection } from "./money-context.js";
6
+ export interface DealLine {
7
+ ref: string;
8
+ kind: Deal["kind"];
9
+ title: string;
10
+ summary: string;
11
+ stage: string;
12
+ status: Deal["status"];
13
+ currency: string | null;
14
+ amount: string | null;
15
+ closeDate: string | null;
16
+ project: string | null;
17
+ }
18
+ export interface ProjectLine {
19
+ ref: string;
20
+ name: string;
21
+ /** It names the organization, or one of its deals does. */
22
+ via: ("organization" | "deal")[];
23
+ }
24
+ export interface TaskLine {
25
+ ref: string;
26
+ key: string;
27
+ title: string;
28
+ status: string;
29
+ project: string;
30
+ dueAt: string | null;
31
+ }
32
+ export interface OrganizationContext {
33
+ organization: Organization & {
34
+ own: boolean;
35
+ };
36
+ categories: Category[];
37
+ /** Its members, each once with every role and the standing of each; the current ones first. */
38
+ people: Section<Related>;
39
+ /** Who is its customer. */
40
+ customers: Section<Related>;
41
+ /** Whom it is a customer of: "supplier of", read backwards. */
42
+ suppliers: Section<Related>;
43
+ partners: Section<Related>;
44
+ projects: Section<ProjectLine>;
45
+ /** Open deals and leads it is the client of. */
46
+ deals: Section<DealLine>;
47
+ money: MoneySection;
48
+ /** Counts only, through its own people other than the owner, in the accounts read. */
49
+ communications: Communications["counts"] & {
50
+ hasMore: boolean;
51
+ };
52
+ /** Open tasks of its projects. */
53
+ tasks: Section<TaskLine>;
54
+ coverage: Coverage;
55
+ }
56
+ export interface OrganizationContextOptions {
57
+ /** The accounts read: a CRM's relationships and deals, and its people's messages, mail and events. */
58
+ accounts?: AccountKey[];
59
+ /** Items per section. */
60
+ limit?: number;
61
+ /** The kinds the profile denies: none of their rows, titles or counts is answered. */
62
+ deniedKinds?: readonly DealKind[];
63
+ }
64
+ export declare const dealLine: (deal: Deal) => DealLine;
65
+ /** Open tasks of these projects, the soonest due first, and the command that lists them when it is one project's. */
66
+ export declare const openTasksOf: (store: MessageStore, projects: {
67
+ ref: string;
68
+ key: string;
69
+ }[]) => Promise<{
70
+ tasks: TaskLine[];
71
+ full: boolean;
72
+ next: string | null;
73
+ }>;
74
+ /**
75
+ * One answer about an organization from the store: its people, its customers, suppliers and partners, projects,
76
+ * open deals, money and how much the owner talks with its people. Every relationship says its standing; a source
77
+ * nobody confirmed is `reported`, one that stopped is `ended`, one waiting for the owner `proposed`. A CRM's rows
78
+ * outside `accounts` are left out, and `coverage` names that CRM.
79
+ */
80
+ export declare const organizationContext: (store: MessageStore, reference: string, { accounts, limit, deniedKinds }?: OrganizationContextOptions) => Promise<OrganizationContext>;