@wirecat/cli-core 0.617.0 → 0.619.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 (306) hide show
  1. package/CHANGELOG.md +406 -1
  2. package/README.md +1 -1
  3. package/THIRD_PARTY_NOTICES +3 -0
  4. package/dist/background/backfill.d.ts +21 -0
  5. package/dist/background/backfill.js +41 -0
  6. package/dist/background/daily-archive-timer.d.ts +1 -1
  7. package/dist/background/deliver.d.ts +5 -2
  8. package/dist/background/deliver.js +30 -12
  9. package/dist/background/report/messages.js +4 -1
  10. package/dist/background/report/render.d.ts +3 -1
  11. package/dist/background/report/render.js +3 -1
  12. package/dist/background/report/view.js +4 -1
  13. package/dist/background/schedules.d.ts +17 -0
  14. package/dist/background/schedules.js +21 -8
  15. package/dist/calendar/cli/answers.d.ts +1 -0
  16. package/dist/calendar/cli/answers.js +6 -1
  17. package/dist/calendar/cli/index.js +2 -14
  18. package/dist/calendar/cli/people-link.d.ts +3 -0
  19. package/dist/calendar/cli/people-link.js +23 -0
  20. package/dist/calendar/index.d.ts +1 -1
  21. package/dist/calendar/index.js +1 -1
  22. package/dist/calendar/mcp/index.d.ts +12 -12
  23. package/dist/cli/base-stages-command.d.ts +22 -0
  24. package/dist/cli/base-stages-command.js +174 -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.d.ts +5 -0
  29. package/dist/cli/context.js +1 -0
  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 +10 -4
  33. package/dist/cli/index.js +10 -4
  34. package/dist/cli/messenger/backfill-command.js +27 -15
  35. package/dist/cli/messenger/contacts-command.js +10 -3
  36. package/dist/cli/messenger/context.js +1 -0
  37. package/dist/cli/messenger/doctor-command.js +3 -1
  38. package/dist/cli/messenger/models-command.js +1 -1
  39. package/dist/cli/messenger/serve-command.js +24 -2
  40. package/dist/cli/messenger/serve-outdated.d.ts +22 -0
  41. package/dist/cli/messenger/serve-outdated.js +100 -0
  42. package/dist/cli/messenger/store-maintenance-command.d.ts +22 -2
  43. package/dist/cli/messenger/store-maintenance-command.js +9 -4
  44. package/dist/cli/model-catalogue-command.d.ts +3 -1
  45. package/dist/cli/model-catalogue-command.js +46 -2
  46. package/dist/cli/profile.d.ts +8 -0
  47. package/dist/cli/profile.js +25 -0
  48. package/dist/cli/program.js +2 -0
  49. package/dist/cli/runs/search-query.d.ts +1 -1
  50. package/dist/cli/runs/search-query.js +4 -0
  51. package/dist/cli/runs/search.d.ts +5 -1
  52. package/dist/cli/runs/search.js +12 -1
  53. package/dist/cli/schedule/schedule-command.d.ts +9 -0
  54. package/dist/cli/schedule/schedule-command.js +13 -0
  55. package/dist/cli/search-left-out.d.ts +6 -1
  56. package/dist/cli/search-left-out.js +9 -4
  57. package/dist/cli/settings.d.ts +8 -0
  58. package/dist/cli/settings.js +17 -2
  59. package/dist/cli/shared-command-exports.d.ts +16 -0
  60. package/dist/cli/store-recover.d.ts +3 -3
  61. package/dist/cli/store-recover.js +47 -23
  62. package/dist/cli/store-settings.d.ts +2 -0
  63. package/dist/cli/store-settings.js +37 -9
  64. package/dist/crm/cli/index.js +38 -6
  65. package/dist/crm/group-hint.d.ts +8 -0
  66. package/dist/crm/group-hint.js +13 -0
  67. package/dist/crm/source.d.ts +12 -1
  68. package/dist/crm/sync.d.ts +31 -2
  69. package/dist/crm/sync.js +110 -3
  70. package/dist/crm/testing/acme-scenario.d.ts +40 -0
  71. package/dist/crm/testing/acme-scenario.js +170 -0
  72. package/dist/crm/testing/index.d.ts +1 -0
  73. package/dist/crm/testing/index.js +1 -0
  74. package/dist/crm/testing/source-contract.js +12 -0
  75. package/dist/crm/testing/source.d.ts +2 -0
  76. package/dist/crm/testing/source.js +1 -0
  77. package/dist/domain/addresses.d.ts +13 -0
  78. package/dist/domain/addresses.js +63 -0
  79. package/dist/domain/categories.d.ts +3 -0
  80. package/dist/domain/categories.js +2 -0
  81. package/dist/domain/crm.d.ts +23 -0
  82. package/dist/domain/crm.js +7 -0
  83. package/dist/domain/links.d.ts +17 -4
  84. package/dist/domain/links.js +20 -7
  85. package/dist/domain/mentions.d.ts +2 -12
  86. package/dist/domain/mentions.js +2 -19
  87. package/dist/domain/orders.d.ts +8 -1
  88. package/dist/domain/orders.js +6 -2
  89. package/dist/domain/phones.d.ts +26 -0
  90. package/dist/domain/phones.js +48 -0
  91. package/dist/domain/record-types.d.ts +1 -1
  92. package/dist/domain/record-types.js +1 -0
  93. package/dist/domain/records.d.ts +5 -0
  94. package/dist/domain/ref-summaries.d.ts +39 -0
  95. package/dist/domain/ref-summaries.js +51 -3
  96. package/dist/domain/relations.d.ts +27 -2
  97. package/dist/domain/relations.js +37 -3
  98. package/dist/domain/vcard.d.ts +2 -2
  99. package/dist/domain/vcard.js +4 -10
  100. package/dist/embeddings/models.d.ts +11 -3
  101. package/dist/embeddings/models.js +28 -4
  102. package/dist/entities/business-context.d.ts +149 -0
  103. package/dist/entities/business-context.js +192 -0
  104. package/dist/entities/contact-activity.d.ts +2 -0
  105. package/dist/entities/contact-activity.js +7 -1
  106. package/dist/entities/contact-context.d.ts +157 -0
  107. package/dist/entities/contact-context.js +2 -0
  108. package/dist/entities/deal.d.ts +10 -0
  109. package/dist/entities/deal.js +2 -0
  110. package/dist/entities/index.d.ts +23 -3
  111. package/dist/entities/index.js +5 -0
  112. package/dist/entities/mention.d.ts +4 -3
  113. package/dist/entities/mention.js +2 -1
  114. package/dist/entities/message-transfer.d.ts +4 -2
  115. package/dist/entities/message-transfer.js +2 -2
  116. package/dist/entities/model.d.ts +2 -2
  117. package/dist/entities/model.js +1 -1
  118. package/dist/entities/relationship.d.ts +4 -0
  119. package/dist/entities/relationship.js +4 -0
  120. package/dist/errors/reasons.js +44 -4
  121. package/dist/fetch/page.js +2 -1
  122. package/dist/index.d.ts +4 -3
  123. package/dist/index.js +4 -3
  124. package/dist/meetings/context-store.d.ts +2 -0
  125. package/dist/meetings/findings-rules.d.ts +4 -0
  126. package/dist/meetings/findings-rules.js +5 -2
  127. package/dist/meetings/mcp/index.d.ts +15 -15
  128. package/dist/meetings/result-items.d.ts +1 -0
  129. package/dist/meetings/result-items.js +1 -0
  130. package/dist/models/index.js +22 -5
  131. package/dist/runs/events.d.ts +11 -1
  132. package/dist/runs/events.js +3 -1
  133. package/dist/runs/log-attributes.js +4 -0
  134. package/dist/runs/log-events.js +2 -0
  135. package/dist/runs/recording.d.ts +3 -0
  136. package/dist/runs/recording.js +36 -12
  137. package/dist/runs/run.d.ts +12 -3
  138. package/dist/runs/run.js +32 -13
  139. package/dist/search/account-list.d.ts +6 -0
  140. package/dist/search/account-list.js +9 -3
  141. package/dist/search/groups.d.ts +68 -0
  142. package/dist/search/groups.js +172 -0
  143. package/dist/services/account-groups.d.ts +28 -0
  144. package/dist/services/account-groups.js +89 -0
  145. package/dist/services/archive.d.ts +7 -1
  146. package/dist/services/archive.js +19 -3
  147. package/dist/services/business-context.d.ts +113 -0
  148. package/dist/services/business-context.js +156 -0
  149. package/dist/services/communications.d.ts +50 -0
  150. package/dist/services/communications.js +140 -0
  151. package/dist/services/deal-context.d.ts +90 -0
  152. package/dist/services/deal-context.js +131 -0
  153. package/dist/services/deps.d.ts +2 -0
  154. package/dist/services/enrichment.d.ts +7 -2
  155. package/dist/services/enrichment.js +46 -5
  156. package/dist/services/events-search.js +2 -1
  157. package/dist/services/group-guard.d.ts +28 -0
  158. package/dist/services/group-guard.js +131 -0
  159. package/dist/services/index.d.ts +15 -2
  160. package/dist/services/index.js +9 -2
  161. package/dist/services/ingest.d.ts +12 -0
  162. package/dist/services/ingest.js +4 -0
  163. package/dist/services/link-scorers/chat-senders.js +39 -29
  164. package/dist/services/link-scorers/member-chats.js +4 -3
  165. package/dist/services/link-scorers/member-dialog.js +5 -7
  166. package/dist/services/link-scorers/scan.js +17 -8
  167. package/dist/services/link-scorers/shared.d.ts +6 -2
  168. package/dist/services/link-scorers/shared.js +6 -2
  169. package/dist/services/link-scorers/types.d.ts +2 -0
  170. package/dist/services/meaning-model.d.ts +7 -0
  171. package/dist/services/meaning-model.js +20 -0
  172. package/dist/services/meeting-context.d.ts +6 -1
  173. package/dist/services/meeting-context.js +12 -5
  174. package/dist/services/message-resolution.js +2 -3
  175. package/dist/services/messages-meaning.js +4 -5
  176. package/dist/services/messages-search.d.ts +5 -1
  177. package/dist/services/messages-search.js +1 -1
  178. package/dist/services/model-downloads.d.ts +1 -1
  179. package/dist/services/model-downloads.js +6 -4
  180. package/dist/services/money-context.d.ts +73 -0
  181. package/dist/services/money-context.js +77 -0
  182. package/dist/services/notes-search.d.ts +4 -1
  183. package/dist/services/notes-search.js +19 -7
  184. package/dist/services/organization-context.d.ts +80 -0
  185. package/dist/services/organization-context.js +154 -0
  186. package/dist/services/people.d.ts +22 -6
  187. package/dist/services/people.js +38 -8
  188. package/dist/services/person-business.d.ts +43 -0
  189. package/dist/services/person-business.js +67 -0
  190. package/dist/services/person-context.d.ts +9 -1
  191. package/dist/services/person-context.js +5 -3
  192. package/dist/services/proposals/kinds/identity-link.d.ts +4 -0
  193. package/dist/services/proposals/kinds/identity-link.js +48 -0
  194. package/dist/services/proposals/kinds/orders.js +1 -1
  195. package/dist/services/proposals/registry.js +2 -0
  196. package/dist/services/search-kind.d.ts +12 -5
  197. package/dist/services/search-kind.js +49 -10
  198. package/dist/services/text-model-choice.js +1 -1
  199. package/dist/store/accounts.d.ts +18 -0
  200. package/dist/store/accounts.js +18 -3
  201. package/dist/store/damage.d.ts +43 -10
  202. package/dist/store/damage.js +119 -36
  203. package/dist/store/decisions.js +3 -1
  204. package/dist/store/evidence-findings.d.ts +14 -0
  205. package/dist/store/evidence-findings.js +2 -0
  206. package/dist/store/exports.d.ts +2 -1
  207. package/dist/store/identity-links.d.ts +92 -0
  208. package/dist/store/identity-links.js +6 -0
  209. package/dist/store/index.d.ts +11 -5
  210. package/dist/store/index.js +5 -2
  211. package/dist/store/journal.d.ts +10 -0
  212. package/dist/store/journal.js +33 -0
  213. package/dist/store/marks.d.ts +19 -1
  214. package/dist/store/marks.js +23 -1
  215. package/dist/store/migrations.d.ts +1 -1
  216. package/dist/store/migrations.js +35 -12
  217. package/dist/store/people.d.ts +22 -0
  218. package/dist/store/people.js +15 -1
  219. package/dist/store/recover.d.ts +34 -0
  220. package/dist/store/recover.js +188 -6
  221. package/dist/store/refill.d.ts +28 -0
  222. package/dist/store/refill.js +120 -0
  223. package/dist/store/sqlite/accounts.js +2 -0
  224. package/dist/store/sqlite/base-stages.d.ts +122 -0
  225. package/dist/store/sqlite/base-stages.js +443 -0
  226. package/dist/store/sqlite/base-suggest.d.ts +13 -0
  227. package/dist/store/sqlite/base-suggest.js +62 -0
  228. package/dist/store/sqlite/business-contracts.js +10 -1
  229. package/dist/store/sqlite/clients.d.ts +7 -3
  230. package/dist/store/sqlite/clients.js +11 -7
  231. package/dist/store/sqlite/crm-settings.d.ts +12 -2
  232. package/dist/store/sqlite/crm-settings.js +56 -13
  233. package/dist/store/sqlite/crm.d.ts +13 -1
  234. package/dist/store/sqlite/crm.js +20 -4
  235. package/dist/store/sqlite/deals.d.ts +33 -0
  236. package/dist/store/sqlite/deals.js +42 -4
  237. package/dist/store/sqlite/decision-requests.js +7 -3
  238. package/dist/store/sqlite/email-index.js +17 -15
  239. package/dist/store/sqlite/evidence-findings.js +29 -5
  240. package/dist/store/sqlite/findings-core.js +4 -2
  241. package/dist/store/sqlite/identity-link-rows.d.ts +50 -0
  242. package/dist/store/sqlite/identity-link-rows.js +146 -0
  243. package/dist/store/sqlite/identity-proposals.d.ts +53 -0
  244. package/dist/store/sqlite/identity-proposals.js +234 -0
  245. package/dist/store/sqlite/knowledge.js +5 -3
  246. package/dist/store/sqlite/link-kinds.d.ts +1 -0
  247. package/dist/store/sqlite/link-kinds.js +1 -0
  248. package/dist/store/sqlite/link-row.d.ts +6 -0
  249. package/dist/store/sqlite/link-row.js +35 -0
  250. package/dist/store/sqlite/link-source.d.ts +10 -0
  251. package/dist/store/sqlite/link-source.js +16 -0
  252. package/dist/store/sqlite/manifest.js +1 -0
  253. package/dist/store/sqlite/meeting-context-links.js +9 -6
  254. package/dist/store/sqlite/memories.js +9 -7
  255. package/dist/store/sqlite/mentions.d.ts +4 -1
  256. package/dist/store/sqlite/mentions.js +14 -9
  257. package/dist/store/sqlite/migrations.generated.js +8 -0
  258. package/dist/store/sqlite/note-index.js +9 -7
  259. package/dist/store/sqlite/notes.d.ts +2 -3
  260. package/dist/store/sqlite/notes.js +6 -29
  261. package/dist/store/sqlite/open-store.js +3 -0
  262. package/dist/store/sqlite/open.js +11 -2
  263. package/dist/store/sqlite/orders.d.ts +2 -0
  264. package/dist/store/sqlite/orders.js +9 -3
  265. package/dist/store/sqlite/organization-categories.d.ts +18 -0
  266. package/dist/store/sqlite/organization-categories.js +34 -0
  267. package/dist/store/sqlite/organizations.d.ts +5 -1
  268. package/dist/store/sqlite/organizations.js +14 -4
  269. package/dist/store/sqlite/person-links.d.ts +19 -4
  270. package/dist/store/sqlite/person-links.js +49 -11
  271. package/dist/store/sqlite/person-match-scan.d.ts +13 -0
  272. package/dist/store/sqlite/person-match-scan.js +251 -0
  273. package/dist/store/sqlite/person-matcher.d.ts +16 -0
  274. package/dist/store/sqlite/person-matcher.js +32 -0
  275. package/dist/store/sqlite/proposed-actions.js +6 -0
  276. package/dist/store/sqlite/record-matching.d.ts +2 -8
  277. package/dist/store/sqlite/record-matching.js +8 -40
  278. package/dist/store/sqlite/record-projectors-phone.js +2 -1
  279. package/dist/store/sqlite/record-relationships.d.ts +52 -0
  280. package/dist/store/sqlite/record-relationships.js +243 -0
  281. package/dist/store/sqlite/record-run.d.ts +5 -0
  282. package/dist/store/sqlite/record-run.js +62 -2
  283. package/dist/store/sqlite/record-writes.d.ts +1 -1
  284. package/dist/store/sqlite/record-writes.js +4 -2
  285. package/dist/store/sqlite/records.js +27 -2
  286. package/dist/store/sqlite/ref-accounts.d.ts +13 -0
  287. package/dist/store/sqlite/ref-accounts.js +117 -0
  288. package/dist/store/sqlite/ref-summaries.js +5 -1
  289. package/dist/store/sqlite/relation-list.d.ts +4 -1
  290. package/dist/store/sqlite/relation-list.js +20 -2
  291. package/dist/store/sqlite/relation-proposals.d.ts +18 -1
  292. package/dist/store/sqlite/relation-proposals.js +53 -11
  293. package/dist/store/sqlite/relation-roles.js +12 -6
  294. package/dist/store/sqlite/reported-relations.d.ts +11 -1
  295. package/dist/store/sqlite/reported-relations.js +59 -18
  296. package/dist/store/sqlite/schema.d.ts +32 -0
  297. package/dist/store/sqlite/schema.js +3 -0
  298. package/dist/store/sqlite/transaction.d.ts +13 -0
  299. package/dist/store/sqlite/transaction.js +33 -15
  300. package/dist/store/store.d.ts +3 -0
  301. package/dist/store/store.js +5 -0
  302. package/dist/store/write-events.d.ts +18 -0
  303. package/dist/store/write-events.js +88 -0
  304. package/package.json +3 -3
  305. package/parity.json +11 -4
  306. package/schemas/records-envelope.v1.schema.json +3 -0
@@ -1,5 +1,6 @@
1
1
  import { type IngestError } from "../domain/records.js";
2
2
  import { type VcardIssue, type VcardOptions } from "../domain/vcard.js";
3
+ import { type RelationshipCounts } from "../store/index.js";
3
4
  import type { MessageStore } from "../store/store.js";
4
5
  export interface IngestOptions {
5
6
  /** The account the caller means; the envelope's `source.account` must be this one. */
@@ -62,6 +63,17 @@ export interface IngestReceipt {
62
63
  pointer: string;
63
64
  reason: string;
64
65
  }[];
66
+ /**
67
+ * The links this import's account reports from the records' relationships: new, held, back after a withdrawal,
68
+ * withdrawn, waiting for review, and left out because the owner rejected that very relationship. An issue with one
69
+ * is in `errors`, code `relationship.*`.
70
+ */
71
+ relationships: RelationshipCounts;
72
+ /**
73
+ * Taken, but not as the source put it: a relationship's word off its role list is kept on a link without a role, as
74
+ * `metadata.source_role` (`relationship.role-unlisted`).
75
+ */
76
+ notices: IngestError[];
65
77
  errors: IngestError[];
66
78
  /** A list stopped at 1000 entries; the counts are exact. */
67
79
  truncated: boolean;
@@ -15,6 +15,8 @@ const emptyReceipt = (dryRun, errors) => ({
15
15
  flagged: [],
16
16
  unmatched: [],
17
17
  ignored: [],
18
+ relationships: { added: 0, kept: 0, restored: 0, withdrawn: 0, proposed: 0, skippedOwnerRejected: 0 },
19
+ notices: [],
18
20
  errors,
19
21
  truncated: false,
20
22
  });
@@ -40,6 +42,8 @@ const receiptOf = (dryRun, source, run) => ({
40
42
  pointer: pointerOf("records", index, ...at),
41
43
  reason,
42
44
  })),
45
+ relationships: run.relationships,
46
+ notices: run.notices,
43
47
  errors: run.errors,
44
48
  truncated: run.truncated,
45
49
  });
@@ -1,5 +1,5 @@
1
1
  import { formatReference, parseReference } from "../../domain/references.js";
2
- import { contactRef, personRefOf, sameAccount } from "./shared.js";
2
+ import { contactRef, personRefOf, remembered, sameAccount } from "./shared.js";
3
3
  const WEIGHT = 0.5;
4
4
  const LARGE_GROUP_WEIGHT = 0.2;
5
5
  const LARGE_GROUP = 30;
@@ -23,7 +23,8 @@ export const chatSenders = {
23
23
  id: "chat-senders",
24
24
  version: 3,
25
25
  spreads: true,
26
- candidates: async ({ store, project, confirmed, sources, since, owner, signal }) => {
26
+ candidates: async (input) => {
27
+ const { project, confirmed, sources, signal } = input;
27
28
  if (!project)
28
29
  return [];
29
30
  const found = [];
@@ -35,34 +36,43 @@ export const chatSenders = {
35
36
  if (!key)
36
37
  continue;
37
38
  signal?.throwIfAborted();
38
- const page = await store.messages.messages(key, reference.chat, { limit: READ_LIMIT, since, outgoing: false });
39
- const senders = new Map();
40
- for (const message of page.items) {
41
- if (message.senderId === null || message.senderIsChat)
42
- continue;
43
- const id = String(message.senderId);
44
- senders.set(id, { count: (senders.get(id)?.count ?? 0) + 1, last: String(message.id) });
45
- }
46
- const size = Math.max((await store.roster.members(key, reference.chat)).length, senders.size);
47
- const weight = size > LARGE_GROUP ? LARGE_GROUP_WEIGHT : WEIGHT;
48
- const where = named(await store.chats.chatTitle(key, reference.chat), chat);
49
- for (const [id, { count, last }] of senders) {
50
- if (size > SMALL_CHAT && count < MIN_MESSAGES)
51
- continue;
52
- const person = await personRefOf(store, key.provider, id);
53
- if (!person || person === owner)
54
- continue;
55
- found.push({
56
- from: person,
57
- to: project.ref,
58
- kind: "member-of",
59
- weight,
60
- why: `wrote ${count} message${count === 1 ? "" : "s"} in ${where} (${size} people) since ${since.slice(0, 10)}`,
61
- evidence: [chat, formatReference({ ...reference, type: "message", message: last })],
62
- identity: contactRef(key.provider, id),
63
- });
64
- }
39
+ for (const one of await remembered(input, `chat-senders\u0000${chat}`, () => sendersOf(input, chat, reference, key)))
40
+ found.push(one);
65
41
  }
66
42
  return found;
67
43
  },
68
44
  };
45
+ const sendersOf = async (input, chat, reference, key) => {
46
+ const { store, project, since, owner } = input;
47
+ if (!project)
48
+ return [];
49
+ const found = [];
50
+ const page = await store.messages.messages(key, reference.chat, { limit: READ_LIMIT, since, outgoing: false });
51
+ const senders = new Map();
52
+ for (const message of page.items) {
53
+ if (message.senderId === null || message.senderIsChat)
54
+ continue;
55
+ const id = String(message.senderId);
56
+ senders.set(id, { count: (senders.get(id)?.count ?? 0) + 1, last: String(message.id) });
57
+ }
58
+ const size = Math.max((await store.roster.members(key, reference.chat)).length, senders.size);
59
+ const weight = size > LARGE_GROUP ? LARGE_GROUP_WEIGHT : WEIGHT;
60
+ const where = named(await store.chats.chatTitle(key, reference.chat), chat);
61
+ for (const [id, { count, last }] of senders) {
62
+ if (size > SMALL_CHAT && count < MIN_MESSAGES)
63
+ continue;
64
+ const person = await personRefOf(input, key.provider, id);
65
+ if (!person || person === owner)
66
+ continue;
67
+ found.push({
68
+ from: person,
69
+ to: project.ref,
70
+ kind: "member-of",
71
+ weight,
72
+ why: `wrote ${count} message${count === 1 ? "" : "s"} in ${where} (${size} people) since ${since.slice(0, 10)}`,
73
+ evidence: [chat, formatReference({ ...reference, type: "message", message: last })],
74
+ identity: contactRef(key.provider, id),
75
+ });
76
+ }
77
+ return found;
78
+ };
@@ -1,11 +1,12 @@
1
- import { chatRef, identitiesIn } from "./shared.js";
1
+ import { chatRef, chatsWithOf, identitiesIn } from "./shared.js";
2
2
  const WEIGHT = 0.5;
3
3
  /** A group or channel where two or more of the project's confirmed person members are members. */
4
4
  export const memberChats = {
5
5
  id: "member-chats",
6
6
  version: 1,
7
7
  spreads: true,
8
- candidates: async ({ store, project, confirmed, sources, owner, signal }) => {
8
+ candidates: async (input) => {
9
+ const { store, project, confirmed, sources, owner, signal } = input;
9
10
  if (!project)
10
11
  return [];
11
12
  const people = confirmed.people.filter((person) => person !== owner);
@@ -14,7 +15,7 @@ export const memberChats = {
14
15
  const members = new Map();
15
16
  for (const { person, id } of await identitiesIn(store, people, key.provider)) {
16
17
  signal?.throwIfAborted();
17
- for (const chat of await store.chats.chatsWith(key, id)) {
18
+ for (const chat of await chatsWithOf(input, key, id)) {
18
19
  if (chat.kind !== "group" && chat.kind !== "channel")
19
20
  continue;
20
21
  const held = members.get(String(chat.id)) ?? new Set();
@@ -1,25 +1,23 @@
1
- import { chatRef, identitiesIn, projectsOf } from "./shared.js";
1
+ import { chatRef, chatsWithOf, identitiesIn, projectsOf, remembered } from "./shared.js";
2
2
  const WEIGHT = 0.6;
3
3
  /** A dialog with a person member, divided by how many projects that person is a member of, this one counted. */
4
4
  export const memberDialog = {
5
5
  id: "member-dialog",
6
6
  version: 2,
7
7
  spreads: true,
8
- candidates: async ({ store, project, confirmed, sources, owner, signal }) => {
8
+ candidates: async (input) => {
9
+ const { store, project, confirmed, sources, owner, signal } = input;
9
10
  if (!project)
10
11
  return [];
11
12
  const people = confirmed.people.filter((person) => person !== owner);
12
- const projects = new Map();
13
13
  const found = [];
14
14
  for (const key of sources)
15
15
  for (const { person, id } of await identitiesIn(store, people, key.provider)) {
16
16
  signal?.throwIfAborted();
17
- for (const chat of await store.chats.chatsWith(key, id)) {
17
+ for (const chat of await chatsWithOf(input, key, id)) {
18
18
  if (chat.kind !== "dialog")
19
19
  continue;
20
- if (!projects.has(person))
21
- projects.set(person, await projectsOf(store, person, project.ref));
22
- const shared = projects.get(person) ?? 1;
20
+ const shared = await remembered(input, `projects-of\u0000${person}`, () => projectsOf(store, person, project.ref));
23
21
  found.push({
24
22
  from: chatRef(key, chat.id),
25
23
  to: project.ref,
@@ -10,7 +10,7 @@ import { emailDomain } from "./email-domain.js";
10
10
  import { mailThread } from "./mail-thread.js";
11
11
  import { memberChats } from "./member-chats.js";
12
12
  import { memberDialog } from "./member-dialog.js";
13
- import { sameAccount } from "./shared.js";
13
+ import { personRefOf, sameAccount } from "./shared.js";
14
14
  /** A new scorer is one file and one line here. */
15
15
  export const SCORERS = [chatTitle, aliasHits, memberChats, memberDialog, chatSenders, mailThread];
16
16
  /** What a scan with no project runs: person ↔ person rules. */
@@ -87,6 +87,7 @@ export const scanProjectLinks = async (store, input) => {
87
87
  purposes: input.purposes ?? BUILT_IN_PURPOSES,
88
88
  owner: owner ? `person:${owner.uid}` : null,
89
89
  ...(input.signal ? { signal: input.signal } : {}),
90
+ remember: rememberer(),
90
91
  };
91
92
  const scorers = input.scorers ?? (project ? SCORERS : PERSON_SCORERS);
92
93
  const skipped = {
@@ -106,13 +107,13 @@ export const scanProjectLinks = async (store, input) => {
106
107
  return held;
107
108
  };
108
109
  let seeds = scorerInput.confirmed;
109
- let collected = await collect(store, scorerInput, scorers, (scorer) => candidatesOf(scorer, seeds));
110
+ let collected = await collect(scorerInput, scorers, (scorer) => candidatesOf(scorer, seeds));
110
111
  for (let hop = 0; hop < MAX_HOPS && scorers.some((one) => one.spreads); hop++) {
111
112
  const grown = await seedsOf(store, seeds, collected.scored, threshold);
112
113
  if (!grown)
113
114
  break;
114
115
  seeds = grown;
115
- collected = await collect(store, scorerInput, scorers, (scorer) => candidatesOf(scorer, seeds));
116
+ collected = await collect(scorerInput, scorers, (scorer) => candidatesOf(scorer, seeds));
116
117
  }
117
118
  skipped.nameOnly = collected.nameOnly;
118
119
  skipped.unresolved = collected.unresolved;
@@ -180,7 +181,7 @@ export const scanProjectLinks = async (store, input) => {
180
181
  return { project: project?.ref ?? null, proposals, skipped };
181
182
  };
182
183
  /** Every scorer's candidates, combined per pair and scored, highest first. */
183
- const collect = async (store, input, scorers, candidatesOf) => {
184
+ const collect = async (input, scorers, candidatesOf) => {
184
185
  const pairs = new Map();
185
186
  const nameOnly = new Set();
186
187
  let unresolved = 0;
@@ -188,7 +189,7 @@ const collect = async (store, input, scorers, candidatesOf) => {
188
189
  input.signal?.throwIfAborted();
189
190
  for (const candidate of await candidatesOf(scorer)) {
190
191
  const key = pairKey(candidate);
191
- const verdict = await admissible(store, input, candidate);
192
+ const verdict = await admissible(input, candidate);
192
193
  if (verdict === "owner")
193
194
  continue;
194
195
  if (verdict === "name-only") {
@@ -254,7 +255,7 @@ const seedsOf = async (store, seeds, scored, threshold) => {
254
255
  return chats.size + people.size === size ? undefined : { chats: [...chats].sort(), people: [...people].sort() };
255
256
  };
256
257
  /** A person candidate stands only on an identity that is that person's; a chat only in a source the scan reads. */
257
- const admissible = async (store, input, candidate) => {
258
+ const admissible = async (input, candidate) => {
258
259
  if (candidate.from === candidate.to || !Number.isFinite(candidate.weight))
259
260
  return "unresolved";
260
261
  if (input.project && candidate.to !== input.project.ref && !candidate.to.startsWith("person:"))
@@ -265,8 +266,7 @@ const admissible = async (store, input, candidate) => {
265
266
  const identity = candidate.identity === undefined ? undefined : referenceOf(candidate.identity);
266
267
  if (identity?.type !== "contact")
267
268
  return "name-only";
268
- const person = await store.people.personOf({ provider: identity.provider, id: identity.id });
269
- return person !== undefined && `person:${person.uid}` === candidate.from ? "ok" : "name-only";
269
+ return (await personRefOf(input, identity.provider, identity.id)) === candidate.from ? "ok" : "name-only";
270
270
  }
271
271
  if (candidate.from.startsWith("chat:")) {
272
272
  const chat = referenceOf(candidate.from);
@@ -274,6 +274,15 @@ const admissible = async (store, input, candidate) => {
274
274
  }
275
275
  return "unresolved";
276
276
  };
277
+ /** The store does not change under a scan until it writes its proposals, after the last pass. */
278
+ const rememberer = () => {
279
+ const held = new Map();
280
+ return (key, read) => {
281
+ const found = held.get(key) ?? read();
282
+ held.set(key, found);
283
+ return found;
284
+ };
285
+ };
277
286
  const referenceOf = (text) => {
278
287
  try {
279
288
  return parseReference(text);
@@ -1,7 +1,7 @@
1
1
  import type { Id } from "../../domain/models.js";
2
2
  import type { MessageStore } from "../../store/store.js";
3
3
  import type { AccountKey } from "../../store/types.js";
4
- import type { ScannedProject } from "./types.js";
4
+ import type { ScannedProject, ScorerInput } from "./types.js";
5
5
  /** A whole-word test, the rule the evidence lanes and meeting candidates use: «Harbour» is not in «Harbourside». */
6
6
  export declare const wholeWords: (term: string) => RegExp;
7
7
  /** The project's name, key and aliases, each once. */
@@ -15,7 +15,7 @@ export declare const sameAccount: (a: AccountKey, b: {
15
15
  account: string;
16
16
  }) => boolean;
17
17
  /** The person an identity is, as `person:<uid>`; `undefined` when the store has no person for it. */
18
- export declare const personRefOf: (store: MessageStore, provider: string, id: Id) => Promise<string | undefined>;
18
+ export declare const personRefOf: (input: Pick<ScorerInput, "store" | "remember">, provider: string, id: Id) => Promise<string | undefined>;
19
19
  /** How many projects a person is a confirmed member of, counting `project` whether confirmed or only found. */
20
20
  export declare const projectsOf: (store: MessageStore, person: string, project: string) => Promise<number>;
21
21
  /** Each confirmed member's identities in one messenger, by member. */
@@ -23,4 +23,8 @@ export declare const identitiesIn: (store: MessageStore, people: readonly string
23
23
  person: string;
24
24
  id: string;
25
25
  }[]>;
26
+ /** What `read` gives, once per scan when the scan remembers. */
27
+ export declare const remembered: <T>(input: Pick<ScorerInput, "remember">, key: string, read: () => Promise<T>) => Promise<T>;
28
+ /** A member's chats in one account, read once per scan by every scorer that asks. */
29
+ export declare const chatsWithOf: (input: Pick<ScorerInput, "store" | "remember">, key: AccountKey, id: string) => Promise<import("../../domain/models.js").Chat[]>;
26
30
  export declare const aborted: (signal: AbortSignal | undefined) => void;
@@ -27,8 +27,8 @@ export const chatRef = (key, chat) => formatReference({ type: "chat", provider:
27
27
  export const contactRef = (provider, id) => formatReference({ type: "contact", provider, id: String(id) });
28
28
  export const sameAccount = (a, b) => a.provider === b.provider && String(a.account) === b.account;
29
29
  /** The person an identity is, as `person:<uid>`; `undefined` when the store has no person for it. */
30
- export const personRefOf = async (store, provider, id) => {
31
- const person = await store.people.personOf({ provider, id });
30
+ export const personRefOf = async (input, provider, id) => {
31
+ const person = await remembered(input, `person-of\u0000${provider}\u0000${String(id)}`, () => input.store.people.personOf({ provider, id }));
32
32
  return person ? `person:${person.uid}` : undefined;
33
33
  };
34
34
  /** How many projects a person is a confirmed member of, counting `project` whether confirmed or only found. */
@@ -49,4 +49,8 @@ export const identitiesIn = async (store, people, provider) => {
49
49
  }
50
50
  return found;
51
51
  };
52
+ /** What `read` gives, once per scan when the scan remembers. */
53
+ export const remembered = (input, key, read) => input.remember ? input.remember(key, read) : read();
54
+ /** A member's chats in one account, read once per scan by every scorer that asks. */
55
+ export const chatsWithOf = (input, key, id) => remembered(input, `chats-with\u0000${key.provider}\u0000${key.account}\u0000${id}`, () => input.store.chats.chatsWith(key, id));
52
56
  export const aborted = (signal) => signal?.throwIfAborted();
@@ -45,6 +45,8 @@ export interface ScorerInput {
45
45
  /** The owner's `person:` reference, never a candidate. */
46
46
  owner: string | null;
47
47
  signal?: AbortSignal;
48
+ /** One scan's memory of a read: a spreading scorer runs again each pass and would read the same chats again. */
49
+ remember?: <T>(key: string, read: () => Promise<T>) => Promise<T>;
48
50
  }
49
51
  export interface LinkScorer {
50
52
  readonly id: string;
@@ -0,0 +1,7 @@
1
+ import type { MessageStore } from "../store/store.js";
2
+ /**
3
+ * The model a search by meaning reads. A model the owner chose, always. With none chosen, the default, unless this
4
+ * store still holds more vectors of the previous default: so after EmbeddingGemma became the default, search keeps
5
+ * reading e5-small's vectors while the syncs embed the store again, and moves to Gemma once it has caught up.
6
+ */
7
+ export declare const meaningModel: (store: MessageStore, env?: NodeJS.ProcessEnv) => Promise<string>;
@@ -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");
@@ -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;