@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
@@ -2,7 +2,7 @@
2
2
  import { domainToUnicode } from "node:url";
3
3
  import psl from "psl";
4
4
  import { googleDocumentId, trimUrl } from "./google-documents.js";
5
- import { DEFAULT_PHONE_COUNTRIES, nationalPhone } from "./phones.js";
5
+ import { DEFAULT_PHONE_COUNTRIES, nationalPhone, typedPhone } from "./phones.js";
6
6
  import { findPlaces } from "./places.js";
7
7
  export const MENTION_KINDS = ["phone", "email", "url", "document", "person-name", "place"];
8
8
  /** Bumped when a kind's rule changes, so `mentions rebuild` can redo that kind alone. */
@@ -121,6 +121,7 @@ const DATE = /^\d{1,2}[./-]\d{1,2}[./-]\d{2,4}$|^\d{4}[./-]\d{1,2}[./-]\d{1,2}$/
121
121
  const IP = /^\d{1,3}(?:\.\d{1,3}){3}$/;
122
122
  const RUSSIAN_GROUPS = /\d{3}[ \u00a0\-–]\d{2}[ \u00a0\-–]\d{2}$/;
123
123
  const SPANISH_GROUPS = /^[6-9]\d{2}[ \u00a0\-–]\d{3}[ \u00a0\-–]\d{3}$/;
124
+ export { typedPhone } from "./phones.js";
124
125
  /**
125
126
  * Looks like a phone, not a checked one: a wrong guess costs one `dismissed`, a miss a search that finds nothing.
126
127
  * `+` or `00` makes it international. Without them the number is read in the store's countries: grouped or after
@@ -213,21 +214,3 @@ const exactlyOne = (text, options) => {
213
214
  const [one] = findMentions(text, options);
214
215
  return one && one.start === 0 && one.end === text.length ? one.value : undefined;
215
216
  };
216
- /**
217
- * A number typed into a search, read as if a phone word stood before it, and the national number every stored
218
- * spelling of it ends with — at least 8 digits, so a short tail does not match unrelated numbers.
219
- */
220
- export const typedPhone = (typed, { phoneCountries = DEFAULT_PHONE_COUNTRIES } = {}) => {
221
- const text = typed.trim();
222
- if (!/^\+?[\d\s().\-–]+$/.test(text))
223
- return undefined;
224
- const digits = text.replace(/\(0\)/, "").replace(/\D/g, "").replace(/^00/, "");
225
- if (digits.length < 7 || digits.length > 15)
226
- return undefined;
227
- const national = nationalPhone(digits, phoneCountries, { anyType: true });
228
- const tail = national?.national ?? digits.replace(/^0+/, "");
229
- return {
230
- value: text.startsWith("+") || /^00/.test(text) ? `+${digits}` : (national?.value ?? digits),
231
- national: tail.length >= 8 ? tail : null,
232
- };
233
- };
@@ -219,6 +219,8 @@ export interface Button {
219
219
  kind: ButtonKind;
220
220
  text: string;
221
221
  url?: string;
222
+ /** What a `callback` button sends the bot, where the adapter can read it; used to refuse owner-only buttons, never printed. */
223
+ data?: string;
222
224
  }
223
225
  /** Where one attachment's bytes can be fetched. */
224
226
  export interface AttachmentLink {
@@ -1,3 +1,4 @@
1
+ import type { OrderDirection } from "./business.js";
1
2
  import type { FinanceReview } from "./finance.js";
2
3
  export declare const ORDER_STATUSES: readonly ["placed", "shipped", "delivered", "cancelled", "returned"];
3
4
  /** Why it was ordered: for the owner himself, for his business, for a client, or anything else. */
@@ -8,12 +9,18 @@ export interface OrderTitleFields {
8
9
  id: number;
9
10
  number: string | null;
10
11
  supplierName: string;
12
+ direction: OrderDirection;
13
+ /** A sale's title names its customer; the supplier is then the owner. */
14
+ customerName: string | null;
11
15
  total: number | null;
12
16
  currency: string | null;
13
17
  status: OrderStatus;
14
18
  review: FinanceReview;
15
19
  }
16
- /** "12345 · Ozon, 2 499.00 RUB (shipped)": a ref summary's title, which `refLabel` prefixes. */
20
+ /**
21
+ * "12345 · Ozon, 2 499.00 RUB (shipped)", or for a sale "O-55 · to ООО Пример, …": a ref summary's title, which
22
+ * `refLabel` prefixes.
23
+ */
17
24
  export declare const orderLine: (order: OrderTitleFields) => string;
18
25
  /** "Order 12345 · Ozon, 2 499.00 RUB (shipped)". */
19
26
  export declare const orderTitle: (order: OrderTitleFields) => string;
@@ -2,11 +2,15 @@ import { moneyLabel } from "./money.js";
2
2
  export const ORDER_STATUSES = ["placed", "shipped", "delivered", "cancelled", "returned"];
3
3
  /** Why it was ordered: for the owner himself, for his business, for a client, or anything else. */
4
4
  export const ORDER_PURPOSES = ["personal", "business", "client", "other"];
5
- /** "12345 · Ozon, 2 499.00 RUB (shipped)": a ref summary's title, which `refLabel` prefixes. */
5
+ /**
6
+ * "12345 · Ozon, 2 499.00 RUB (shipped)", or for a sale "O-55 · to ООО Пример, …": a ref summary's title, which
7
+ * `refLabel` prefixes.
8
+ */
6
9
  export const orderLine = (order) => {
10
+ const party = order.direction === "sale" && order.customerName !== null ? `to ${order.customerName}` : order.supplierName;
7
11
  const money = order.total === null || order.currency === null ? "" : `, ${moneyLabel(order.total, order.currency)}`;
8
12
  const notes = [order.status, order.review === "confirmed" ? null : order.review].filter(Boolean).join(", ");
9
- return `${order.number ?? `#${order.id}`} · ${order.supplierName}${money} (${notes})`;
13
+ return `${order.number ?? `#${order.id}`} · ${party}${money} (${notes})`;
10
14
  };
11
15
  /** "Order 12345 · Ozon, 2 499.00 RUB (shipped)". */
12
16
  export const orderTitle = (order) => `Order ${orderLine(order)}`;
@@ -20,3 +20,29 @@ export interface NationalPhone {
20
20
  export declare const nationalPhone: (digits: string, countries: readonly string[], { anyType }: {
21
21
  anyType: boolean;
22
22
  }) => NationalPhone | undefined;
23
+ export interface PhoneOptions {
24
+ /** Where a number written without `+` is read, first match first: the store's `phone_countries`. */
25
+ phoneCountries?: readonly string[];
26
+ }
27
+ /**
28
+ * A number typed into a search, read as if a phone word stood before it, and the national number every stored
29
+ * spelling of it ends with — at least 8 digits, so a short tail does not match unrelated numbers.
30
+ */
31
+ export declare const typedPhone: (typed: string, { phoneCountries }?: PhoneOptions) => {
32
+ value: string;
33
+ national: string | null;
34
+ } | undefined;
35
+ /**
36
+ * A phone as a source typed it, as E.164: `null` for a number written without `+` or `00` when no region is given,
37
+ * nothing when it is no phone. Only the source says which country a national number is from: the store's
38
+ * `phone_countries` setting reads `4155550100` as Russian, so it never decides an identifier.
39
+ */
40
+ export declare const e164Of: (phone: string, region: string | undefined) => string | null | undefined;
41
+ /** The messengers that keep a contact's number as bare international digits, the `+` left off. */
42
+ export declare const BARE_INTERNATIONAL_PROVIDERS: readonly string[];
43
+ /**
44
+ * The E.164 number a stored phone column stands for. A number written with `+` or `00` is read however it is spaced;
45
+ * a `phone` identity keeps it whole. Bare digits are international only from a messenger that stores them so; from a
46
+ * CRM or a card they are a national number, whose country nothing names, so they match nothing.
47
+ */
48
+ export declare const storedPhone: (raw: string, provider: string) => string | undefined;
@@ -50,3 +50,51 @@ export const nationalPhone = (digits, countries, { anyType }) => {
50
50
  }
51
51
  return undefined;
52
52
  };
53
+ /**
54
+ * A number typed into a search, read as if a phone word stood before it, and the national number every stored
55
+ * spelling of it ends with — at least 8 digits, so a short tail does not match unrelated numbers.
56
+ */
57
+ export const typedPhone = (typed, { phoneCountries = DEFAULT_PHONE_COUNTRIES } = {}) => {
58
+ const text = typed.trim();
59
+ if (!/^\+?[\d\s().\-–]+$/.test(text))
60
+ return undefined;
61
+ const digits = text.replace(/\(0\)/, "").replace(/\D/g, "").replace(/^00/, "");
62
+ if (digits.length < 7 || digits.length > 15)
63
+ return undefined;
64
+ const national = nationalPhone(digits, phoneCountries, { anyType: true });
65
+ const tail = national?.national ?? digits.replace(/^0+/, "");
66
+ return {
67
+ value: text.startsWith("+") || /^00/.test(text) ? `+${digits}` : (national?.value ?? digits),
68
+ national: tail.length >= 8 ? tail : null,
69
+ };
70
+ };
71
+ /**
72
+ * A phone as a source typed it, as E.164: `null` for a number written without `+` or `00` when no region is given,
73
+ * nothing when it is no phone. Only the source says which country a national number is from: the store's
74
+ * `phone_countries` setting reads `4155550100` as Russian, so it never decides an identifier.
75
+ */
76
+ export const e164Of = (phone, region) => {
77
+ if (/^\s*(\+|00)/.test(phone))
78
+ return typedPhone(phone)?.value;
79
+ if (typedPhone(phone) === undefined)
80
+ return undefined;
81
+ if (region === undefined)
82
+ return null;
83
+ const digits = phone.replace(/\(0\)/, "").replace(/\D/g, "");
84
+ return nationalPhone(digits, [region], { anyType: true })?.value;
85
+ };
86
+ /** The messengers that keep a contact's number as bare international digits, the `+` left off. */
87
+ export const BARE_INTERNATIONAL_PROVIDERS = ["telegram", "max", "whatsapp"];
88
+ /**
89
+ * The E.164 number a stored phone column stands for. A number written with `+` or `00` is read however it is spaced;
90
+ * a `phone` identity keeps it whole. Bare digits are international only from a messenger that stores them so; from a
91
+ * CRM or a card they are a national number, whose country nothing names, so they match nothing.
92
+ */
93
+ export const storedPhone = (raw, provider) => {
94
+ if (/^\s*(\+|00)/.test(raw))
95
+ return typedPhone(raw)?.value;
96
+ if (!BARE_INTERNATIONAL_PROVIDERS.includes(provider))
97
+ return undefined;
98
+ const found = /^([1-9]\d{6,14})$/.exec(raw.trim());
99
+ return found ? `+${found[1]}` : undefined;
100
+ };
@@ -10,7 +10,7 @@ export interface RecordRoleSpec {
10
10
  amount?: boolean;
11
11
  /** A business relationship between entities, by its kind: the relation may carry `as`, the part the target plays. */
12
12
  relationship?: RelationKind;
13
- /** Kept in `record_relations` only, never read to make the entity, so it never makes a record wait (PR 5). */
13
+ /** Never read to make the entity, so it never makes a record wait. */
14
14
  kept?: boolean;
15
15
  /**
16
16
  * A role v1 already had: `fields.<role>` may name a store ref instead of a relation, and its target type is not
@@ -95,6 +95,7 @@ export const RECORD_TYPES = {
95
95
  name: kept("The person's name"),
96
96
  email: kept("E-mail addresses, one or a list: an exact one links the record to the one person who has it"),
97
97
  phone: kept("Phone numbers, one or a list: an exact one, read to E.164, links like an e-mail"),
98
+ position: kept("The job title, kept beside each member-of as its position: never the role"),
98
99
  }),
99
100
  roles: { "member-of": { targets: ORGANIZATION, relationship: "member-of", kept: true } },
100
101
  },
@@ -53,6 +53,11 @@ export interface IngestError {
53
53
  code: string;
54
54
  message: string;
55
55
  key?: string;
56
+ /** The record an entry is about when it is not in this envelope: one of an earlier batch. */
57
+ record?: {
58
+ type: string;
59
+ externalId: string;
60
+ };
56
61
  }
57
62
  /** The v1 envelope as JSON Schema (Draft 2020-12); `schemas/records-envelope.v1.schema.json` is this, written out. */
58
63
  export declare const RECORDS_ENVELOPE_SCHEMA: {
@@ -1,3 +1,5 @@
1
+ import type { Profiles } from "../search/account-list.js";
2
+ import type { AccountKey } from "../store/types.js";
1
3
  import type { RefKindName } from "./references.js";
2
4
  export type RefState = "available" | "deleted" | "unavailable";
3
5
  /** A message or chat of the `email` provider is mail, so it reads as `email` and `email_thread`. */
@@ -27,6 +29,22 @@ export interface RefsStore {
27
29
  summaries(refs: readonly string[], options?: {
28
30
  excerpt?: boolean;
29
31
  }): Promise<Map<string, RefSummary>>;
32
+ /**
33
+ * The accounts the referenced thing belongs to: `[]` when no account brought it (the owner made it), `undefined`
34
+ * when the store holds nothing for the reference or it is not one.
35
+ */
36
+ accounts(ref: string): Promise<{
37
+ provider: string;
38
+ account: string;
39
+ }[] | undefined>;
40
+ /**
41
+ * Each part the thing belongs to, all of which a group must hold: a proposed action (`action:<id>`) is its own
42
+ * account and its target's; a suggested link (`link:<id>`) its two ends; anything else one part, as `accounts`.
43
+ */
44
+ ends(ref: string): Promise<{
45
+ provider: string;
46
+ account: string;
47
+ }[][] | undefined>;
30
48
  }
31
49
  /** The caller's answer to "which profile opens this": one signed in, or the choices and why there is not one. */
32
50
  export type ProfilesFor = (provider: string, account: string | null) => {
@@ -42,6 +60,27 @@ export interface RefOpen {
42
60
  why: string | null;
43
61
  }
44
62
  export declare const PROFILE_PLACEHOLDER = "<profile>";
63
+ export declare const profilesOn: (profiles: Profiles, app: string, key: AccountKey) => string[];
64
+ /** From the store's record, so it answers for any CLI that registered its provider, not only the messengers. */
65
+ export declare const storedProfilesFor: (profiles: Profiles) => ProfilesFor;
66
+ /**
67
+ * Which CLI changes a CRM copy on its server, and as which profile; `profile` is `null` unless exactly one fits.
68
+ * `account` is the row's: the write refuses a row of any other account than its profile's live one.
69
+ */
70
+ export interface WritesWith {
71
+ tool: string | null;
72
+ account: AccountKey;
73
+ profile: string | null;
74
+ profiles: string[];
75
+ why: string | null;
76
+ }
77
+ /**
78
+ * `null` for the owner's own row: memo itself writes it. `allowed` is the caller's profile or group lock: a profile it
79
+ * forbids is never named, and the one profile it leaves is the answer.
80
+ */
81
+ export declare const writesWithOf: (account: AccountKey | null, profilesFor: ProfilesFor, { allowed }?: {
82
+ allowed?: (tool: string, profile: string) => boolean;
83
+ }) => WritesWith | null;
45
84
  /** A title from someone else's text, as one line: a newline in it would break every row it is printed in. */
46
85
  export declare const oneLine: (text: string) => string;
47
86
  /**
@@ -1,6 +1,56 @@
1
1
  import { singleLine } from "@wirecat/cli-base";
2
2
  import { providerNamed } from "./providers.js";
3
3
  export const PROFILE_PLACEHOLDER = "<profile>";
4
+ const unregistered = (provider) => `no CLI has registered ${provider} in this store yet; run its CLI once`;
5
+ export const profilesOn = (profiles, app, key) => Object.entries(profiles[app] ?? {})
6
+ .filter(([, saved]) => saved.provider === key.provider && saved.account === key.account)
7
+ .map(([name]) => name);
8
+ /** From the store's record, so it answers for any CLI that registered its provider, not only the messengers. */
9
+ export const storedProfilesFor = (profiles) => (provider, account) => {
10
+ const tool = providerNamed(provider)?.command;
11
+ if (tool === undefined)
12
+ return { why: unregistered(provider), profiles: [] };
13
+ if (account === null)
14
+ return { why: `${provider} names no account here`, profiles: [] };
15
+ const named = profilesOn(profiles, tool, { provider, account });
16
+ if (named.length === 1)
17
+ return { profile: named[0] };
18
+ return {
19
+ why: named.length === 0
20
+ ? `no ${tool} profile has run on ${provider}:${account} here; run \`${tool} <profile>\` with it once`
21
+ : `${named.length} ${tool} profiles are on ${provider}:${account}: ${named.join(", ")}; the owner chooses one`,
22
+ profiles: named,
23
+ };
24
+ };
25
+ const keyText = (key) => `${key.provider}:${key.account}`;
26
+ /**
27
+ * `null` for the owner's own row: memo itself writes it. `allowed` is the caller's profile or group lock: a profile it
28
+ * forbids is never named, and the one profile it leaves is the answer.
29
+ */
30
+ export const writesWithOf = (account, profilesFor, { allowed } = {}) => {
31
+ if (account === null)
32
+ return null;
33
+ const tool = providerNamed(account.provider)?.command ?? null;
34
+ if (tool === null)
35
+ return { tool, account, profile: null, profiles: [], why: unregistered(account.provider) };
36
+ const asked = profilesFor(account.provider, account.account);
37
+ const named = "profile" in asked ? [asked.profile] : asked.profiles;
38
+ const kept = allowed ? named.filter((profile) => allowed(tool, profile)) : named;
39
+ if (kept.length === 1 && ("profile" in asked || allowed))
40
+ return { tool, account, profile: kept[0], profiles: kept, why: null };
41
+ if (kept.length === named.length && !("profile" in asked))
42
+ return { tool, account, profile: null, profiles: asked.profiles, why: asked.why };
43
+ return {
44
+ tool,
45
+ account,
46
+ profile: null,
47
+ profiles: kept,
48
+ why: kept.length === 0
49
+ ? `no ${tool} profile on ${keyText(account)} is allowed in this run`
50
+ : `${kept.length} ${tool} profiles allowed in this run are on ${keyText(account)}: ${kept.join(", ")}; ` +
51
+ "the owner chooses one",
52
+ };
53
+ };
4
54
  /** A title from someone else's text, as one line: a newline in it would break every row it is printed in. */
5
55
  export const oneLine = (text) => singleLine(text.replace(/\s+/g, " ").trim());
6
56
  /** Mail is a message and a chat to the provider registry: `opens` is keyed by the reference kind. */
@@ -28,9 +78,7 @@ export const openOf = (summary, ports) => {
28
78
  return {
29
79
  argv: null,
30
80
  profiles: [],
31
- why: summary.provider === null
32
- ? `nothing here opens a ${kind}`
33
- : `no CLI has registered ${summary.provider} in this store yet; run its CLI once`,
81
+ why: summary.provider === null ? `nothing here opens a ${kind}` : unregistered(summary.provider),
34
82
  };
35
83
  };
36
84
  const WORDS = {
@@ -1,6 +1,8 @@
1
1
  /** What a person is to an organization; who reports to whom is `reports-to`, and a job title is never a role. */
2
2
  export declare const ORGANIZATION_ROLES: readonly ["employee", "contractor", "founder", "owner", "manager", "adviser", "contact"];
3
3
  export declare const PROJECT_ROLES: readonly ["owner", "manager", "contributor", "client-contact", "approver"];
4
+ /** A contract party's part; a party the list cannot name has none, never a catch-all `other`. */
5
+ export declare const CONTRACT_ROLES: readonly ["customer", "supplier", "signatory", "guarantor"];
4
6
  /** How much the owner deals with a person on a project himself, not how active the person is; absent is unknown. */
5
7
  export declare const ENGAGEMENT_LEVELS: readonly ["none", "low", "medium", "high"];
6
8
  export type Engagement = (typeof ENGAGEMENT_LEVELS)[number];
@@ -12,7 +14,7 @@ export declare const engagementRank: (level: Engagement | null | undefined) => n
12
14
  export declare const byEngagement: <T extends {
13
15
  engagement?: Engagement | null;
14
16
  }>(items: readonly T[]) => T[];
15
- type End = "person" | "organization" | "project" | "task" | "chat" | "email_thread" | "deal" | "lead";
17
+ type End = "person" | "organization" | "project" | "task" | "chat" | "email_thread" | "deal" | "lead" | "contract";
16
18
  interface RelationSpec {
17
19
  from: readonly End[];
18
20
  to: readonly End[];
@@ -57,12 +59,13 @@ export declare const RELATIONS: {
57
59
  readonly symmetric: true;
58
60
  };
59
61
  readonly "related-to": {
60
- readonly from: readonly ["person", "organization", "project", "task", "deal", "lead"];
62
+ readonly from: readonly ["person", "organization", "project", "task", "deal", "lead", "contract"];
61
63
  readonly to: readonly ["person", "organization", "project", "task"];
62
64
  readonly roles: {
63
65
  readonly from: {
64
66
  readonly deal: readonly ["owner", "contact", "decision-maker", "influencer"];
65
67
  readonly lead: readonly ["owner", "contact", "decision-maker", "influencer"];
68
+ readonly contract: readonly ["customer", "supplier", "signatory", "guarantor"];
66
69
  };
67
70
  };
68
71
  };
@@ -81,6 +84,7 @@ export declare const ROLE_LISTS: {
81
84
  readonly organization: readonly ["employee", "contractor", "founder", "owner", "manager", "adviser", "contact"];
82
85
  readonly project: readonly ["owner", "manager", "contributor", "client-contact", "approver"];
83
86
  readonly deal: readonly ["owner", "contact", "decision-maker", "influencer"];
87
+ readonly contract: readonly ["customer", "supplier", "signatory", "guarantor"];
84
88
  };
85
89
  export type RoleList = keyof typeof ROLE_LISTS;
86
90
  /** Which list a relationship's role comes from, or `undefined` where a role is free text. */
@@ -124,6 +128,12 @@ export interface RelationshipColumns {
124
128
  engagement?: Engagement;
125
129
  /** The source's link this owner link overrides (`metadata.overrides`). */
126
130
  overrides?: number;
131
+ /** The source's own words for it, off the role list (`metadata.source_role`), never its role. */
132
+ sourceRoles?: string[];
133
+ /** The source account that reported it, `<provider>:<account>`. */
134
+ account?: string;
135
+ /** How a source made the relationship when it stated none, such as `department-head`. */
136
+ derived?: string;
127
137
  }
128
138
  /** The owner's confirmation outlives a source that stopped reporting it; only its own end date ends it. */
129
139
  export declare const standingOf: (link: StandingFields, now: number) => Standing;
@@ -11,6 +11,8 @@ export const ORGANIZATION_ROLES = [
11
11
  "contact",
12
12
  ];
13
13
  export const PROJECT_ROLES = ["owner", "manager", "contributor", "client-contact", "approver"];
14
+ /** A contract party's part; a party the list cannot name has none, never a catch-all `other`. */
15
+ export const CONTRACT_ROLES = ["customer", "supplier", "signatory", "guarantor"];
14
16
  /** How much the owner deals with a person on a project himself, not how active the person is; absent is unknown. */
15
17
  export const ENGAGEMENT_LEVELS = ["none", "low", "medium", "high"];
16
18
  export const isEngagement = (value) => typeof value === "string" && ENGAGEMENT_LEVELS.includes(value);
@@ -48,9 +50,9 @@ export const RELATIONS = {
48
50
  "customer-of": { from: ["person", "organization"], to: ["organization"], inverse: "supplier of" },
49
51
  "partner-of": { from: ["organization"], to: ["organization"], symmetric: true },
50
52
  "related-to": {
51
- from: ["person", "organization", "project", "task", "deal", "lead"],
53
+ from: ["person", "organization", "project", "task", "deal", "lead", "contract"],
52
54
  to: ["person", "organization", "project", "task"],
53
- roles: { from: { deal: DEAL_ROLES, lead: DEAL_ROLES } },
55
+ roles: { from: { deal: DEAL_ROLES, lead: DEAL_ROLES, contract: CONTRACT_ROLES } },
54
56
  },
55
57
  };
56
58
  export const RELATION_KINDS = Object.keys(RELATIONS);
@@ -58,12 +60,16 @@ const specOf = (kind) => Object.hasOwn(RELATIONS, kind) ? RELATIONS[kind] : unde
58
60
  export const isRelationKind = (kind) => specOf(kind) !== undefined;
59
61
  /** A chat or a mail thread is only ever a project's member: its reference names one account. */
60
62
  const memberOnly = (type) => type === "chat" || type === "email_thread";
63
+ /** A contract's parties are the people and organizations that signed it. */
64
+ const partyOnly = (from, to) => from === "contract" && to !== "person" && to !== "organization";
61
65
  export const checkEnds = (kind, from, to) => {
62
66
  const spec = specOf(kind);
63
67
  if (!spec)
64
68
  throw new CliError("validation_error", `a relationship's kind is one of ${RELATION_KINDS.join(", ")}`);
65
69
  if (memberOnly(from) && (kind !== "member-of" || to !== "project"))
66
70
  throw new CliError("validation_error", `a ${from === "chat" ? "chat" : "mail thread"} is related only as member-of a project`);
71
+ if (partyOnly(from, to))
72
+ throw new CliError("validation_error", "a contract is related only to a person or an organization");
67
73
  if (!spec.from.includes(from) || !spec.to.includes(to))
68
74
  throw new CliError("validation_error", `${kind} joins ${spec.from.join(", ")} to ${spec.to.join(", ")}, not ${from} to ${to}`);
69
75
  return spec;
@@ -79,7 +85,12 @@ export const rolesOf = (kind, from, to) => {
79
85
  return spec?.roles?.from?.[from] ?? spec?.roles?.to?.[to];
80
86
  };
81
87
  /** The role lists the owner may add to; each is a list the registry gives some relationship's ends. */
82
- export const ROLE_LISTS = { organization: ORGANIZATION_ROLES, project: PROJECT_ROLES, deal: DEAL_ROLES };
88
+ export const ROLE_LISTS = {
89
+ organization: ORGANIZATION_ROLES,
90
+ project: PROJECT_ROLES,
91
+ deal: DEAL_ROLES,
92
+ contract: CONTRACT_ROLES,
93
+ };
83
94
  /** Which list a relationship's role comes from, or `undefined` where a role is free text. */
84
95
  export const roleListOf = (kind, from, to) => {
85
96
  const roles = rolesOf(kind, from, to);
@@ -1,4 +1,4 @@
1
- import type { PhoneCountry } from "./phones.js";
1
+ import { type PhoneCountry } from "./phones.js";
2
2
  import type { RecordsEnvelope } from "./records.js";
3
3
  export interface VcardOptions {
4
4
  provider: string;
@@ -19,7 +19,7 @@ export declare const isVcard: (text: string) => boolean;
19
19
  * addresses, and one organization per `ORG` name the person is a member of. Nothing is guessed: a national number
20
20
  * is read only in `region`, and a card says nothing about a person it does not hold.
21
21
  */
22
- export declare const envelopeOfVcard: (text: string, { provider, account, batchId, region }: VcardOptions) => {
22
+ export declare const envelopeOfVcard: (text: string, { provider, account, batchId, region: given }: VcardOptions) => {
23
23
  envelope: RecordsEnvelope;
24
24
  issues: VcardIssue[];
25
25
  };
@@ -1,5 +1,5 @@
1
1
  import { createHash } from "node:crypto";
2
- import { typedPhone } from "./mentions.js";
2
+ import { e164Of } from "./phones.js";
3
3
  import { WORD_BODY } from "./record-types.js";
4
4
  const MAX_ID = 512;
5
5
  const AS_WORD = new RegExp(`^${WORD_BODY}$`);
@@ -108,14 +108,7 @@ const components = (value) => {
108
108
  };
109
109
  const textOf = (property, report) => components(decoded(property, report)).join(";").trim();
110
110
  /** E.164, or `undefined` when the number has no country of its own and none is given. */
111
- const e164 = (typed, region) => {
112
- const text = typed.replace(/^tel:/i, "").replace(/;.*$/, "").trim();
113
- const international = /^(\+|00)/.test(text);
114
- if (!international && region === undefined)
115
- return undefined;
116
- const value = typedPhone(text, region === undefined ? {} : { phoneCountries: [region] })?.value;
117
- return value?.startsWith("+") ? value : undefined;
118
- };
111
+ const e164 = (typed, region) => e164Of(typed.replace(/^tel:/i, "").replace(/;.*$/, "").trim(), region) ?? undefined;
119
112
  const foldedName = (name) => name.normalize("NFKC").toLowerCase().replace(/\s+/g, " ").trim();
120
113
  const hashed = (prefix, parts) => `${prefix}${createHash("sha256").update(parts.join("\n")).digest("hex").slice(0, 32)}`;
121
114
  const organizationId = (name) => {
@@ -174,7 +167,8 @@ const cardsOf = (text) => {
174
167
  * addresses, and one organization per `ORG` name the person is a member of. Nothing is guessed: a national number
175
168
  * is read only in `region`, and a card says nothing about a person it does not hold.
176
169
  */
177
- export const envelopeOfVcard = (text, { provider, account, batchId, region }) => {
170
+ export const envelopeOfVcard = (text, { provider, account, batchId, region: given }) => {
171
+ const region = given?.toLowerCase();
178
172
  const { cards, issues } = cardsOf(text);
179
173
  const people = [];
180
174
  const organizations = new Map();
@@ -15,8 +15,10 @@ export interface TextModel {
15
15
  custom?: boolean;
16
16
  languages: string;
17
17
  licence: string;
18
- /** A licence the user accepts before the model is downloaded, or nothing for an open one. */
18
+ /** The page of a licence with conditions of its own, or nothing for an open one. */
19
19
  terms?: string;
20
+ /** What the licence asks a copy to carry, written beside the model's files as NOTICE. */
21
+ notice?: string;
20
22
  dims: number;
21
23
  /** What the model was trained on; a longer text is cut. */
22
24
  maxTokens: number;
@@ -35,7 +37,9 @@ export interface TextModel {
35
37
  externalData?: string;
36
38
  }
37
39
  export declare const TEXT_MODELS: TextModel[];
38
- export declare const DEFAULT_TEXT_MODEL = "e5-small";
40
+ export declare const DEFAULT_TEXT_MODEL = "embeddinggemma";
41
+ /** The default until 8 Nov 2026: a machine that has it and not EmbeddingGemma keeps embedding and searching with it. */
42
+ export declare const PREVIOUS_DEFAULT_TEXT_MODEL = "e5-small";
39
43
  /** A model the owner adds: the same shape as a built-in one, so it is downloaded, checked and loaded the same way. */
40
44
  export declare const CustomTextModelShape: v.SchemaWithPipe<readonly [v.StrictObjectSchema<{
41
45
  readonly id: v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.RegexAction<string, "is not a model id: a-z, 0-9, . _ -">]>;
@@ -203,7 +207,11 @@ export declare const writeTextModelsSection: (section: TextModelsSection, env?:
203
207
  /** The models this version ships, then the owner's own. */
204
208
  export declare const textModels: (env?: NodeJS.ProcessEnv) => TextModel[];
205
209
  export declare const textModel: (id: string, env?: NodeJS.ProcessEnv) => TextModel;
206
- /** The model every embed and every search by meaning uses when none is named: the owner's `models use`, or e5-small. */
210
+ /**
211
+ * The model every embed and every search by meaning uses when none is named: the owner's `models set`, else
212
+ * EmbeddingGemma. A machine with only e5-small downloaded, the default before, keeps using it, so its search by meaning
213
+ * never stops for a model it lacks; once EmbeddingGemma is downloaded the next syncs embed with it.
214
+ */
207
215
  export declare const chosenTextModel: (env?: NodeJS.ProcessEnv) => {
208
216
  id: string;
209
217
  from: "chosen" | "default";
@@ -1,5 +1,8 @@
1
+ import { existsSync } from "node:fs";
2
+ import { join } from "node:path";
1
3
  import { CliError } from "@wirecat/cli-base";
2
4
  import * as v from "valibot";
5
+ import { filesPresent, sharedModelsDirectory } from "../speech/install.js";
3
6
  import { storePath } from "../store/path.js";
4
7
  import { readSharedSection, sharedConfigPath, writeSharedSection } from "../store/shared-config.js";
5
8
  const huggingFace = (repository, commit) => (name) => `https://huggingface.co/${repository}/resolve/${commit}/${name}`;
@@ -48,9 +51,14 @@ export const TEXT_MODELS = [
48
51
  languages: "over 100 languages — the best of the two on chat, about seven times slower",
49
52
  licence: "Gemma Terms of Use",
50
53
  terms: "https://ai.google.dev/gemma/terms",
54
+ // Gemma Terms of Use §3.1: every copy carries this notice and the use restrictions of §3.2.
55
+ notice: "Gemma is provided under and subject to the Gemma Terms of Use found at ai.google.dev/gemma/terms. Its use is " +
56
+ "restricted by the Gemma Prohibited Use Policy: https://ai.google.dev/gemma/prohibited_use_policy",
51
57
  dims: 768,
52
58
  maxTokens: 2048,
53
- chunksPerSecond: 2,
59
+ // 2026-11-08, 1,200-character chunks, 8 threads on the Ryzen AI 9 HX 470: 8.3 chunks/s against e5-small's 52.7, so
60
+ // 5 on the scale e5-small's 31 sets. It was 2, which held a memo sync to 39 chunks.
61
+ chunksPerSecond: 5,
54
62
  pooling: "sentence_embedding",
55
63
  prefix: { query: "task: search result | query: ", passage: "title: none | text: " },
56
64
  onnx: "onnx/model_q4.onnx",
@@ -117,7 +125,9 @@ export const TEXT_MODELS = [
117
125
  ],
118
126
  },
119
127
  ];
120
- export const DEFAULT_TEXT_MODEL = "e5-small";
128
+ export const DEFAULT_TEXT_MODEL = "embeddinggemma";
129
+ /** The default until 8 Nov 2026: a machine that has it and not EmbeddingGemma keeps embedding and searching with it. */
130
+ export const PREVIOUS_DEFAULT_TEXT_MODEL = "e5-small";
121
131
  const SECTION = "text_models";
122
132
  const slug = v.pipe(v.string(), v.regex(/^[a-z0-9][a-z0-9._-]{0,62}$/, "is not a model id: a-z, 0-9, . _ -"));
123
133
  const words = v.pipe(v.string(), v.trim(), v.minLength(1), v.maxLength(300));
@@ -188,10 +198,24 @@ export const textModel = (id, env = process.env) => {
188
198
  }
189
199
  return found;
190
200
  };
191
- /** The model every embed and every search by meaning uses when none is named: the owner's `models use`, or e5-small. */
201
+ const downloaded = (id, env) => {
202
+ const model = TEXT_MODELS.find((one) => one.id === id);
203
+ const directory = sharedModelsDirectory("text", env);
204
+ return model !== undefined && filesPresent(model.files.map((file) => [file, join(directory, model.id, file.name)]));
205
+ };
206
+ /**
207
+ * The model every embed and every search by meaning uses when none is named: the owner's `models set`, else
208
+ * EmbeddingGemma. A machine with only e5-small downloaded, the default before, keeps using it, so its search by meaning
209
+ * never stops for a model it lacks; once EmbeddingGemma is downloaded the next syncs embed with it.
210
+ */
192
211
  export const chosenTextModel = (env = process.env) => {
193
212
  const use = readTextModelsSection(env).use;
194
- return use === undefined ? { id: DEFAULT_TEXT_MODEL, from: "default" } : { id: use, from: "chosen" };
213
+ if (use !== undefined)
214
+ return { id: use, from: "chosen" };
215
+ // The previous default's folder, not its files: a CLI may run it under its own pinned files.
216
+ const kept = !downloaded(DEFAULT_TEXT_MODEL, env) &&
217
+ existsSync(join(sharedModelsDirectory("text", env), PREVIOUS_DEFAULT_TEXT_MODEL));
218
+ return { id: kept ? PREVIOUS_DEFAULT_TEXT_MODEL : DEFAULT_TEXT_MODEL, from: "default" };
195
219
  };
196
220
  const mmarco = huggingFace("cross-encoder/mmarco-mMiniLMv2-L12-H384-v1", "1427fd652930e4ba29e8149678df786c240d8825");
197
221
  const bge = huggingFace("onnx-community/bge-reranker-v2-m3-ONNX", "6f5ff65298512715a1e669753bc754d2bc8f367b");