@wirecat/cli-core 1.2.0 → 2.0.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 (150) hide show
  1. package/CHANGELOG.md +170 -0
  2. package/dist/attachments/container.d.ts +1 -1
  3. package/dist/attachments/container.js +16 -7
  4. package/dist/attachments/limits.d.ts +10 -0
  5. package/dist/attachments/limits.js +30 -1
  6. package/dist/attachments/transfer.js +2 -2
  7. package/dist/cli/app-doctor-command.d.ts +61 -7
  8. package/dist/cli/app-doctor-command.js +24 -11
  9. package/dist/cli/contract-templates.js +3 -0
  10. package/dist/cli/documents/file-edit.js +6 -6
  11. package/dist/cli/documents/library.js +4 -2
  12. package/dist/cli/help/first-screen.js +2 -2
  13. package/dist/cli/index.d.ts +7 -6
  14. package/dist/cli/index.js +3 -2
  15. package/dist/cli/messenger/account-command.js +0 -10
  16. package/dist/cli/messenger/accounts.d.ts +1 -1
  17. package/dist/cli/messenger/accounts.js +1 -1
  18. package/dist/cli/messenger/context.d.ts +17 -1
  19. package/dist/cli/messenger/doctor-command.js +16 -1
  20. package/dist/cli/messenger/flooded.js +9 -1
  21. package/dist/cli/messenger/serve-relay.d.ts +2 -0
  22. package/dist/cli/messenger/session-commands.d.ts +1 -1
  23. package/dist/cli/messenger/session-commands.js +1 -1
  24. package/dist/cli/oauth-session.d.ts +3 -2
  25. package/dist/cli/oauth-session.js +19 -3
  26. package/dist/cli/profile-store.d.ts +24 -10
  27. package/dist/cli/profile-store.js +43 -28
  28. package/dist/cli/program.js +2 -2
  29. package/dist/cli/settings.d.ts +3 -3
  30. package/dist/cli/shared-command-exports.d.ts +1 -1
  31. package/dist/cli/token-session.d.ts +21 -2
  32. package/dist/cli/token-session.js +27 -11
  33. package/dist/crm/cli/files.js +7 -7
  34. package/dist/documents.d.ts +1 -1
  35. package/dist/documents.js +1 -1
  36. package/dist/domain/person-kinds.d.ts +7 -3
  37. package/dist/domain/person-kinds.js +7 -3
  38. package/dist/domain/ref-summaries.js +1 -0
  39. package/dist/domain/references.d.ts +3 -2
  40. package/dist/domain/references.js +19 -10
  41. package/dist/entities/deal.d.ts +2 -2
  42. package/dist/entities/deal.js +1 -1
  43. package/dist/entities/fact.d.ts +2 -2
  44. package/dist/entities/fact.js +1 -1
  45. package/dist/entities/fields.d.ts +1 -1
  46. package/dist/entities/fields.js +1 -1
  47. package/dist/entities/index.d.ts +15 -15
  48. package/dist/entities/mail-findings.d.ts +2 -2
  49. package/dist/entities/mail-findings.js +1 -1
  50. package/dist/entities/meeting-findings.d.ts +2 -2
  51. package/dist/entities/meeting-findings.js +1 -1
  52. package/dist/entities/memory.d.ts +1 -1
  53. package/dist/entities/store-maintenance.js +1 -1
  54. package/dist/entities/task-results.d.ts +5 -5
  55. package/dist/entities/task-results.js +1 -1
  56. package/dist/entities/task.d.ts +1 -1
  57. package/dist/entities/task.js +1 -1
  58. package/dist/errors/failures.d.ts +6 -0
  59. package/dist/errors/failures.js +18 -4
  60. package/dist/errors/reasons.js +2 -1
  61. package/dist/errors/store-reasons.js +1 -0
  62. package/dist/fetch/page.js +1 -2
  63. package/dist/mail/headers.d.ts +4 -3
  64. package/dist/mail/headers.js +21 -3
  65. package/dist/mail/sort-rules.d.ts +13 -6
  66. package/dist/mail/sort-rules.js +20 -16
  67. package/dist/mail/sync.js +2 -0
  68. package/dist/mcp/tool.js +2 -2
  69. package/dist/mcp/tools/attachments.js +1 -1
  70. package/dist/office/zip.js +1 -1
  71. package/dist/ports/messenger.d.ts +31 -1
  72. package/dist/runs/recording.js +2 -2
  73. package/dist/services/archive.js +61 -11
  74. package/dist/services/attachments.js +4 -4
  75. package/dist/services/documents/file-text.js +2 -2
  76. package/dist/services/metadata.d.ts +1 -1
  77. package/dist/services/proposals/kinds/shared.d.ts +1 -1
  78. package/dist/services/proposals/kinds/shared.js +2 -2
  79. package/dist/services/proposals/kinds/task-close.js +1 -1
  80. package/dist/store/areas.d.ts +2 -0
  81. package/dist/store/areas.js +1 -0
  82. package/dist/store/decisions.d.ts +1 -1
  83. package/dist/store/decisions.js +4 -4
  84. package/dist/store/evidence-findings.d.ts +2 -2
  85. package/dist/store/index.d.ts +3 -1
  86. package/dist/store/index.js +2 -1
  87. package/dist/store/mail-findings.d.ts +2 -2
  88. package/dist/store/meeting-findings.d.ts +2 -2
  89. package/dist/store/people.d.ts +4 -4
  90. package/dist/store/people.js +2 -1
  91. package/dist/store/project-transfer/manifest.js +3 -3
  92. package/dist/store/public.d.ts +1 -1
  93. package/dist/store/public.js +1 -1
  94. package/dist/store/sqlite/actors.d.ts +1 -1
  95. package/dist/store/sqlite/actors.js +6 -6
  96. package/dist/store/sqlite/agent-actions.js +2 -2
  97. package/dist/store/sqlite/agent-links.js +1 -1
  98. package/dist/store/sqlite/bot-sends.d.ts +19 -0
  99. package/dist/store/sqlite/bot-sends.js +36 -0
  100. package/dist/store/sqlite/business-contracts.js +1 -1
  101. package/dist/store/sqlite/deals.js +1 -1
  102. package/dist/store/sqlite/document-transfer/plan.js +1 -1
  103. package/dist/store/sqlite/document-transfer/snapshot.js +1 -1
  104. package/dist/store/sqlite/email-index.d.ts +11 -2
  105. package/dist/store/sqlite/email-index.js +56 -5
  106. package/dist/store/sqlite/email-types.d.ts +15 -3
  107. package/dist/store/sqlite/email-types.js +32 -1
  108. package/dist/store/sqlite/emails.d.ts +2 -1
  109. package/dist/store/sqlite/emails.js +6 -1
  110. package/dist/store/sqlite/entity-types.d.ts +1 -1
  111. package/dist/store/sqlite/entity-types.js +1 -1
  112. package/dist/store/sqlite/evidence-findings.js +1 -1
  113. package/dist/store/sqlite/facts.js +1 -1
  114. package/dist/store/sqlite/finance.js +2 -2
  115. package/dist/store/sqlite/knowledge.js +1 -0
  116. package/dist/store/sqlite/mail-findings.js +1 -1
  117. package/dist/store/sqlite/mail-sorting.d.ts +1 -1
  118. package/dist/store/sqlite/mail-sorting.js +96 -60
  119. package/dist/store/sqlite/mail-subscriptions.d.ts +70 -0
  120. package/dist/store/sqlite/mail-subscriptions.js +132 -0
  121. package/dist/store/sqlite/manifest.js +45 -0
  122. package/dist/store/sqlite/meeting-findings.js +1 -1
  123. package/dist/store/sqlite/memories.js +3 -3
  124. package/dist/store/sqlite/migrations.generated.js +80 -0
  125. package/dist/store/sqlite/money-transactions.js +1 -1
  126. package/dist/store/sqlite/note-index.d.ts +4 -1
  127. package/dist/store/sqlite/note-index.js +40 -17
  128. package/dist/store/sqlite/orders.js +1 -1
  129. package/dist/store/sqlite/payment-facts.js +2 -2
  130. package/dist/store/sqlite/products.js +1 -1
  131. package/dist/store/sqlite/project-transfer/sources.js +2 -2
  132. package/dist/store/sqlite/proposed-actions.js +3 -3
  133. package/dist/store/sqlite/record-projection.js +1 -1
  134. package/dist/store/sqlite/ref-summaries.js +2 -1
  135. package/dist/store/sqlite/relation-proposals.js +1 -1
  136. package/dist/store/sqlite/reviewed.d.ts +2 -2
  137. package/dist/store/sqlite/reviewed.js +1 -1
  138. package/dist/store/sqlite/sender-bots.d.ts +19 -4
  139. package/dist/store/sqlite/sender-bots.js +48 -4
  140. package/dist/store/sqlite/subscriptions.js +2 -2
  141. package/dist/store/sqlite/task-close.js +1 -1
  142. package/dist/store/sqlite/task-comments.js +1 -1
  143. package/dist/store/sqlite/things.js +1 -1
  144. package/dist/store/sqlite/transaction.d.ts +5 -0
  145. package/dist/store/sqlite/transaction.js +6 -1
  146. package/dist/store/sqlite/wallets.js +1 -1
  147. package/dist/store/sqlite/work-tasks.js +2 -2
  148. package/dist/tracker/tasks.js +4 -2
  149. package/package.json +7 -5
  150. package/parity.json +9 -3
@@ -14,7 +14,7 @@ const rowOf = (task) => {
14
14
  subject: task.ref,
15
15
  object: null,
16
16
  summary: `close as ${suggestion.as}: ${task.title}`,
17
- proposedBy: { type: "bot", id: suggestion.by, name: suggestion.by, kind: "agent" },
17
+ proposedBy: { type: "agent", id: suggestion.by, name: suggestion.by, kind: "agent" },
18
18
  reason: suggestion.reason,
19
19
  evidence: task.source === null ? [] : [task.source],
20
20
  score: suggestion.certainty,
@@ -4,6 +4,7 @@
4
4
  */
5
5
  export { MAIL_TYPES, type MailType } from "../mail/mail-types.js";
6
6
  export { type AddedSource, type AddedSourceContent, type AddedSourceInput, addedSourceKeyOf, } from "./sqlite/added-sources.js";
7
+ export { BOT_SENDS, type BotSends } from "./sqlite/bot-sends.js";
7
8
  export type { ContractFilter } from "./sqlite/business-contracts.js";
8
9
  export type { CatalogEntry, CatalogInput, CatalogQuery } from "./sqlite/catalog.js";
9
10
  export type { CrmChange, CrmChangeKind } from "./sqlite/crm-changes.js";
@@ -17,6 +18,7 @@ export type { Invoice, Payment as FinancePayment } from "./sqlite/finance.js";
17
18
  export type { IdentityRekey } from "./sqlite/identity-rekey.js";
18
19
  export { IMPORTED_DOCUMENT_QUERY } from "./sqlite/imported-documents.js";
19
20
  export { type KnowledgeRelation, type KnowledgeTarget, ORGANIZATION_KINDS, type Organization, PROJECT_TYPES, type Project, SCOPES, } from "./sqlite/knowledge.js";
21
+ export type { MailSubscription, MailSubscriptionFilter, MailSubscriptionList, UnsubscribeTarget, } from "./sqlite/mail-subscriptions.js";
20
22
  export type { MeetingVectors } from "./sqlite/meeting-vectors.js";
21
23
  export type { Author, Memory } from "./sqlite/memories.js";
22
24
  export type { TransactionFilter } from "./sqlite/money-transactions.js";
@@ -4,6 +4,7 @@
4
4
  */
5
5
  export { MAIL_TYPES } from "../mail/mail-types.js";
6
6
  export { addedSourceKeyOf, } from "./sqlite/added-sources.js";
7
+ export { BOT_SENDS } from "./sqlite/bot-sends.js";
7
8
  export { crmIdentityId } from "./sqlite/crm-rows.js";
8
9
  export { crmSettingKey } from "./sqlite/crm-settings.js";
9
10
  export { QUOTE_LIMIT, quoteKept } from "./sqlite/evidence-signature.js";
@@ -9,7 +9,7 @@ export type Proposer = {
9
9
  type: "person";
10
10
  id: string;
11
11
  } | {
12
- type: "bot";
12
+ type: "agent";
13
13
  id: string;
14
14
  name: string;
15
15
  kind: "agent" | "rule";
@@ -44,11 +44,11 @@ row, by, policy = DEFAULT_DECISION_POLICY) => {
44
44
  const proposer = row.proposedBy;
45
45
  if (proposer.type === "unknown")
46
46
  return refuse("permission_error", "proposal.owner-only", "this proposal names no author; only the owner decides it");
47
- if (proposer.type === "bot" && proposer.verified === false)
47
+ if (proposer.type === "agent" && proposer.verified === false)
48
48
  return refuse("permission_error", "proposal.owner-only", `${proposer.name} is named only by an old link's provenance; only the owner decides it`);
49
- if (proposer.type === "bot" && proposer.kind === "rule" && policy.ruleProposalsOwnerOnly)
49
+ if (proposer.type === "agent" && proposer.kind === "rule" && policy.ruleProposalsOwnerOnly)
50
50
  return refuse("permission_error", "proposal.owner-only", `proposed by ${proposer.name}: only the owner decides it`);
51
- if (proposer.type === "bot" && proposer.kind === "agent" && botKey(proposer.name) === botKey(by.bot))
51
+ if (proposer.type === "agent" && proposer.kind === "agent" && botKey(proposer.name) === botKey(by.bot))
52
52
  return refuse("permission_error", "proposal.own", `${by.bot} proposed this; another decider must decide it`);
53
53
  return null;
54
54
  };
@@ -66,7 +66,7 @@ export const assertMayWithdraw = (row, by) => {
66
66
  return;
67
67
  const proposer = row.proposedBy;
68
68
  if (row.proposed &&
69
- proposer.type === "bot" &&
69
+ proposer.type === "agent" &&
70
70
  proposer.kind === "agent" &&
71
71
  proposer.verified !== false &&
72
72
  botKey(proposer.name) === botKey(by.bot))
@@ -32,13 +32,13 @@ export interface EvidenceFindingsBatch {
32
32
  /** Only the owner decides it, whatever `agent_decisions` says: it was staged so, or it records a payment. */
33
33
  ownerOnly: boolean;
34
34
  author: {
35
- type: "person" | "bot";
35
+ type: "person" | "agent";
36
36
  id: string;
37
37
  name: string | null;
38
38
  kind: "agent" | "rule" | null;
39
39
  };
40
40
  decidedBy: {
41
- type: "person" | "bot";
41
+ type: "person" | "agent";
42
42
  id: string;
43
43
  } | null;
44
44
  decidedAt: string | null;
@@ -1,7 +1,7 @@
1
1
  export type { ContextEvidenceItem, ContextEvidencePage, ContextEvidenceReader, ContextEvidenceRequest, ContextEvidenceSender, ContextSource, } from "../context/evidence.js";
2
2
  export { BUSINESS_KINDS, type BusinessKind } from "../domain/business.js";
3
3
  export { FACT_STATUSES, FACT_TYPES, MEMORY_KINDS, MEMORY_SCOPES, MEMORY_STATUSES, TASK_TYPES, WORK_TASK_TYPES, } from "../domain/knowledge.js";
4
- export { type KindSignal, PERSON_KINDS, type PersonKind, SENDER_BOT_PREFIX } from "../domain/person-kinds.js";
4
+ export { type KindSignal, OLD_SENDER_BOT_PREFIX, PERSON_KINDS, type PersonKind, SENDER_BOT_PREFIX, senderBotRef, } from "../domain/person-kinds.js";
5
5
  export type { RefState, RefSummary, RefSummaryKind, RefsStore } from "../domain/ref-summaries.js";
6
6
  export type { TagConsolidationApplyOptions, TagConsolidationOptions, TagConsolidationPreview, TagConsolidationReceipt, TagConsolidationStore, } from "../domain/tag-consolidation.js";
7
7
  export type { TagRedirectIndex, TagRedirectResolution, TagRedirectSnapshot } from "../domain/tag-redirects.js";
@@ -43,6 +43,7 @@ export { resetAttachmentWords } from "./sqlite/attachment-texts.js";
43
43
  export { backfillNormalized, pendingNormalization } from "./sqlite/backfill.js";
44
44
  export type { BaseColumn, BaseScope, BaseSet, BaseStagesStore, MappingFilter, StageMapping, StageName, } from "./sqlite/base-stages.js";
45
45
  export { baseSettingKey } from "./sqlite/base-suggest.js";
46
+ export { BOT_SENDS, type BotSends } from "./sqlite/bot-sends.js";
46
47
  export type { BotUpdate, BotUpdateStore } from "./sqlite/bot-updates.js";
47
48
  export type { Contract, ContractFields, ContractFilter, ContractInput, ContractsStore, ContractUpdate, } from "./sqlite/business-contracts.js";
48
49
  export type { BusinessHit, BusinessSearch, BusinessSearchStore, BusinessSource } from "./sqlite/business-search.js";
@@ -72,6 +73,7 @@ export type { Involvement, InvolvementStore } from "./sqlite/involvements.js";
72
73
  export type { Annotation, KnowledgeRelation, KnowledgeStore, KnowledgeTarget, LabelledType, Organization, Project, Reminder, } from "./sqlite/knowledge.js";
73
74
  export { ORGANIZATION_KINDS, PROJECT_TYPES, SCOPES } from "./sqlite/knowledge.js";
74
75
  export type { MailRule, MailRuleCount, MailRuleInput, MailRulesStore } from "./sqlite/mail-rules.js";
76
+ export type { MailSubscription, MailSubscriptionFilter, MailSubscriptionList, UnsubscribeTarget, } from "./sqlite/mail-subscriptions.js";
75
77
  export { type ListedAccount, MEETING_ROW_KINDS, type MeetingListFilter, type MeetingListing, type MeetingRow, type MeetingRowDocument, type MeetingRowKind, type MeetingRowParticipant, type MeetingRowSource, } from "./sqlite/meeting-listing.js";
76
78
  export type { MeetingProjectLink, MeetingProjectsStore } from "./sqlite/meeting-projects.js";
77
79
  export type { MeetingContextReadCapabilities, MeetingReadCapabilities, MeetingReadScope, TranscriptContextInput, TranscriptContextPage, TranscriptPage, TranscriptReadScope, TranscriptRowPage, } from "./sqlite/meeting-reads.js";
@@ -1,6 +1,6 @@
1
1
  export { BUSINESS_KINDS } from "../domain/business.js";
2
2
  export { FACT_STATUSES, FACT_TYPES, MEMORY_KINDS, MEMORY_SCOPES, MEMORY_STATUSES, TASK_TYPES, WORK_TASK_TYPES, } from "../domain/knowledge.js";
3
- export { PERSON_KINDS, SENDER_BOT_PREFIX } from "../domain/person-kinds.js";
3
+ export { OLD_SENDER_BOT_PREFIX, PERSON_KINDS, SENDER_BOT_PREFIX, senderBotRef, } from "../domain/person-kinds.js";
4
4
  export { createTagRedirectIndex } from "../domain/tag-redirects.js";
5
5
  export { note } from "../entities/note.js";
6
6
  export { PAYMENT_DIRECTIONS, PAYMENT_STATES, paymentTitle, validatePayment } from "../meetings/index.js";
@@ -31,6 +31,7 @@ export { ADDED_KINDS, addedSourceKeyOf, } from "./sqlite/added-sources.js";
31
31
  export { resetAttachmentWords } from "./sqlite/attachment-texts.js";
32
32
  export { backfillNormalized, pendingNormalization } from "./sqlite/backfill.js";
33
33
  export { baseSettingKey } from "./sqlite/base-suggest.js";
34
+ export { BOT_SENDS } from "./sqlite/bot-sends.js";
34
35
  export { BUSINESS_FIND_MAX } from "./sqlite/business-search.js";
35
36
  export { CATALOG_QUERY } from "./sqlite/catalog.js";
36
37
  export { crmIdentityId, } from "./sqlite/crm.js";
@@ -12,13 +12,13 @@ export interface MailFindingsBatch {
12
12
  fingerprint: string;
13
13
  status: "proposed" | "reviewed";
14
14
  author: {
15
- type: "person" | "bot";
15
+ type: "person" | "agent";
16
16
  id: string;
17
17
  name: string | null;
18
18
  kind: "agent" | "rule" | null;
19
19
  };
20
20
  decidedBy: {
21
- type: "person" | "bot";
21
+ type: "person" | "agent";
22
22
  id: string;
23
23
  } | null;
24
24
  decidedAt: string | null;
@@ -9,12 +9,12 @@ export interface MeetingFindingsBatch {
9
9
  fingerprint: string;
10
10
  status: "proposed" | "reviewed";
11
11
  author: {
12
- type: "person" | "bot";
12
+ type: "person" | "agent";
13
13
  id: string;
14
14
  name: string | null;
15
15
  };
16
16
  decidedBy: {
17
- type: "person" | "bot";
17
+ type: "person" | "agent";
18
18
  id: string;
19
19
  } | null;
20
20
  decidedAt: string | null;
@@ -210,15 +210,15 @@ export interface PeopleStore extends AccountPeople {
210
210
  /** Why each `person:<uid>` is shown by default, as `list` gives it; an empty list for one with no tie. */
211
211
  ties(people: readonly string[]): Promise<Record<string, ShownBecause[]>>;
212
212
  /**
213
- * The sender bots: programs that write to the owner, apart from people (`sender-bot:<id>`), by name. `query` looks in
213
+ * The sender bots: programs that write to the owner, apart from people (`bot:<id>`), by name. `query` looks in
214
214
  * their names, addresses and usernames; `organization` (`organization:<id>`) keeps the ones that send for it.
215
215
  * @experimental
216
216
  */
217
217
  listBots(options: BotListOptions): Promise<BotList>;
218
- /** One sender bot (`sender-bot:<id>`), its identities and every move to or from it. @experimental */
218
+ /** One sender bot (`bot:<id>`), its identities and every move to or from it. @experimental */
219
219
  showBot(bot: string): Promise<SenderBotDetails>;
220
220
  /**
221
- * The owner says a sender is a program: a person (`person:<uid>`), a bot (`sender-bot:<id>`) or one identity moves
221
+ * The owner says a sender is a program: a person (`person:<uid>`), a bot (`bot:<id>`) or one identity moves
222
222
  * to a sender bot for its whole history, and no rule gives it back. Its messages keep pointing at the identity. `bot`
223
223
  * joins a stored bot; else a bot already holding it keeps it, or a new one takes it. A person every identity left is
224
224
  * hidden from lists, and a move back gives their uid back. The owner's alone; refused for the owner's own person.
@@ -230,7 +230,7 @@ export interface PeopleStore extends AccountPeople {
230
230
  reason?: string;
231
231
  }): Promise<SenderBot>;
232
232
  /**
233
- * The owner says a sender is a person: a bot (`sender-bot:<id>`) or one identity of it moves to a person for its
233
+ * The owner says a sender is a person: a bot (`bot:<id>`) or one identity of it moves to a person for its
234
234
  * whole history, and no rule makes it a bot again. `person` takes it; else each identity goes back to the person it
235
235
  * came from, or a person of its own. Said of a person, it keeps them one. The owner's alone. @experimental
236
236
  */
@@ -2,6 +2,7 @@ import { CliError } from "@wirecat/cli-base";
2
2
  import { keysOver } from "./keys.js";
3
3
  import { ownerPerson } from "./sqlite/actors.js";
4
4
  import { agentLink, agentMergeOf, agentMerges, linkEvidenceOver } from "./sqlite/agent-links.js";
5
+ import { sendsWhere } from "./sqlite/bot-sends.js";
5
6
  import * as identities from "./sqlite/identities.js";
6
7
  import * as identityProposals from "./sqlite/identity-proposals.js";
7
8
  import { rekeyIdentities } from "./sqlite/identity-rekey.js";
@@ -169,7 +170,7 @@ export const peopleStoreOver = (context, keyed) => {
169
170
  },
170
171
  listBots: async (options) => {
171
172
  storeKinds(database);
172
- return listBots(database, options);
173
+ return listBots(database, options, options.sends === undefined ? undefined : sendsWhere(database, options.sends));
173
174
  },
174
175
  showBot: async (bot) => showBot(database, bot),
175
176
  moveToBot: async (subject, by, options) => {
@@ -32,9 +32,9 @@ export const validateProjectAnnotationsGraph = (manifest, additionalActors = [])
32
32
  if (owned.has(fact.ref))
33
33
  invalid("facts.duplicate");
34
34
  owned.add(fact.ref);
35
- kind(fact.author, ["person", "bot"]);
35
+ kind(fact.author, ["person", "agent"]);
36
36
  if (fact.confirmed_by !== null)
37
- kind(fact.confirmed_by, ["person", "bot"]);
37
+ kind(fact.confirmed_by, ["person", "agent"]);
38
38
  if (fact.updated_at < fact.created_at)
39
39
  invalid("facts.updated_at");
40
40
  if (fact.type !== "decision" && (fact.supersedes !== null || ["superseded", "reversed"].includes(fact.status)))
@@ -61,7 +61,7 @@ export const validateProjectAnnotationsGraph = (manifest, additionalActors = [])
61
61
  kind(manifest.project.organization, ["organization"]);
62
62
  dependency(manifest.project.organization);
63
63
  for (const actor of additionalActors) {
64
- kind(actor, ["person", "bot"]);
64
+ kind(actor, ["person", "agent"]);
65
65
  dependency(actor);
66
66
  }
67
67
  const aliases = new Set([manifest.project.name, manifest.project.key].map(normalizeVocabularyName));
@@ -1,7 +1,7 @@
1
1
  export type { ContextEvidenceItem, ContextEvidencePage, ContextEvidenceReader, ContextEvidenceRequest, ContextEvidenceSender, ContextSource, } from "../context/evidence.js";
2
2
  export { BUSINESS_KINDS, type BusinessKind } from "../domain/business.js";
3
3
  export { FACT_STATUSES, FACT_TYPES, MEMORY_KINDS, MEMORY_SCOPES, MEMORY_STATUSES, TASK_TYPES, WORK_TASK_TYPES, } from "../domain/knowledge.js";
4
- export { type KindSignal, PERSON_KINDS, type PersonKind, SENDER_BOT_PREFIX } from "../domain/person-kinds.js";
4
+ export { type KindSignal, OLD_SENDER_BOT_PREFIX, PERSON_KINDS, type PersonKind, SENDER_BOT_PREFIX, senderBotRef, } from "../domain/person-kinds.js";
5
5
  export type { RefState, RefSummary, RefSummaryKind, RefsStore } from "../domain/ref-summaries.js";
6
6
  export type { TagConsolidationApplyOptions, TagConsolidationOptions, TagConsolidationPreview, TagConsolidationReceipt, TagConsolidationStore, } from "../domain/tag-consolidation.js";
7
7
  export type { TagRedirectIndex, TagRedirectResolution, TagRedirectSnapshot } from "../domain/tag-redirects.js";
@@ -1,6 +1,6 @@
1
1
  export { BUSINESS_KINDS } from "../domain/business.js";
2
2
  export { FACT_STATUSES, FACT_TYPES, MEMORY_KINDS, MEMORY_SCOPES, MEMORY_STATUSES, TASK_TYPES, WORK_TASK_TYPES, } from "../domain/knowledge.js";
3
- export { PERSON_KINDS, SENDER_BOT_PREFIX } from "../domain/person-kinds.js";
3
+ export { OLD_SENDER_BOT_PREFIX, PERSON_KINDS, SENDER_BOT_PREFIX, senderBotRef, } from "../domain/person-kinds.js";
4
4
  export { createTagRedirectIndex } from "../domain/tag-redirects.js";
5
5
  export { note } from "../entities/note.js";
6
6
  export { PAYMENT_DIRECTIONS, PAYMENT_STATES, paymentTitle, validatePayment } from "../meetings/index.js";
@@ -2,7 +2,7 @@ import type { Proposer } from "../decisions.js";
2
2
  import type { CacheDatabase } from "../driver.js";
3
3
  /** Who made or owns something: the store's polymorphic actor pair. */
4
4
  export interface Actor {
5
- type: "person" | "bot";
5
+ type: "person" | "agent";
6
6
  id: number;
7
7
  }
8
8
  /** How the task package names who acted; each maps to one stable actor row. */
@@ -16,11 +16,11 @@ export const botNamed = (database, name, now, kind = "agent") => {
16
16
  throw new CliError("validation_error", `a bot's kind is one of ${BOT_KINDS.join(", ")}`);
17
17
  const found = database.prepare("SELECT id FROM bots WHERE name = ?").get(handle);
18
18
  if (found)
19
- return { type: "bot", id: Number(found.id) };
19
+ return { type: "agent", id: Number(found.id) };
20
20
  const made = database
21
21
  .prepare("INSERT INTO bots (name, kind, created_at, updated_at) VALUES (?, ?, ?, ?) RETURNING id")
22
22
  .get(handle, kind, now, now);
23
- return { type: "bot", id: Number(made?.id) };
23
+ return { type: "agent", id: Number(made?.id) };
24
24
  };
25
25
  /**
26
26
  * The task package's origins as actors: the owner is the owner's person, a rule and an unnamed agent are
@@ -32,7 +32,7 @@ export const actorOfOrigin = (database, origin) => {
32
32
  const found = database.prepare("SELECT id FROM bots WHERE name = ?").get(origin);
33
33
  if (!found)
34
34
  throw new CliError("configuration_error", `the store has no bot ${origin}`);
35
- return { type: "bot", id: Number(found.id) };
35
+ return { type: "agent", id: Number(found.id) };
36
36
  };
37
37
  export const originOfActor = (database, type, id) => {
38
38
  if (type == null || id == null)
@@ -45,19 +45,19 @@ export const originOfActor = (database, type, id) => {
45
45
  export const proposerOf = (database, type, id) => {
46
46
  if (type === "person" && id != null)
47
47
  return { type: "person", id: String(id) };
48
- if (type !== "bot" || id == null)
48
+ if (type !== "agent" || id == null)
49
49
  return { type: "unknown" };
50
50
  const bot = database.prepare("SELECT name, kind FROM bots WHERE id = ?").get(Number(id));
51
51
  if (!bot)
52
52
  return { type: "unknown" };
53
53
  const name = String(bot.name);
54
- return { type: "bot", id: String(id), name, kind: bot.kind === "rule" || name === "rule" ? "rule" : "agent" };
54
+ return { type: "agent", id: String(id), name, kind: bot.kind === "rule" || name === "rule" ? "rule" : "agent" };
55
55
  };
56
56
  /** The SQL that keeps rows whose actor pair matches `by`; the seeded bot `rule` counts as a rule. */
57
57
  export const proposedBySql = (type, id, by) => {
58
58
  if (by === undefined)
59
59
  return { sql: "1", params: [] };
60
- const bot = (condition) => `${type} = 'bot' AND EXISTS (SELECT 1 FROM bots pb WHERE pb.id = ${id} AND ${condition})`;
60
+ const bot = (condition) => `${type} = 'agent' AND EXISTS (SELECT 1 FROM bots pb WHERE pb.id = ${id} AND ${condition})`;
61
61
  if (by === "rule")
62
62
  return { sql: bot("(pb.kind = 'rule' OR pb.name = 'rule')"), params: [] };
63
63
  if (by === "agent")
@@ -5,7 +5,7 @@ import { thingOf } from "./things.js";
5
5
  export const ACTION_TIERS = ["read", "draft", "write-private", "write-public", "destructive", "admin"];
6
6
  export const ACTION_OUTCOMES = ["ok", "refused", "failed"];
7
7
  const CODE = /^[a-z][a-z0-9_]{0,63}$/;
8
- const NAMED = "SELECT a.*, b.name AS actor_name FROM agent_actions a LEFT JOIN bots b ON a.actor_type = 'bot' AND b.id = a.actor_id";
8
+ const NAMED = "SELECT a.*, b.name AS actor_name FROM agent_actions a LEFT JOIN bots b ON a.actor_type = 'agent' AND b.id = a.actor_id";
9
9
  export const agentActionsStoreOver = (context, afterRecord = () => { }) => {
10
10
  const { database, now } = context;
11
11
  const actionOf = (row) => ({
@@ -38,7 +38,7 @@ export const agentActionsStoreOver = (context, afterRecord = () => { }) => {
38
38
  .prepare("INSERT INTO agent_actions (actor_type, actor_id, tool, tier, target_type, target_id, status, error, started_at, finished_at, created_at) " +
39
39
  "VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?) RETURNING id")
40
40
  .get(actor.type, actor.id, input.tool, input.tier, target?.type ?? null, target?.id ?? null, input.status, error, input.startedAt, input.finishedAt, now());
41
- database.prepare("UPDATE bots SET last_seen_at = ? WHERE ? = 'bot' AND id = ?").run(now(), actor.type, actor.id);
41
+ database.prepare("UPDATE bots SET last_seen_at = ? WHERE ? = 'agent' AND id = ?").run(now(), actor.type, actor.id);
42
42
  afterRecord();
43
43
  return actionOf(database.prepare(`${NAMED} WHERE a.id = ?`).get(Number(row?.id)));
44
44
  },
@@ -159,7 +159,7 @@ export const agentMergeOf = (context, merge) => {
159
159
  const proposer = proposerOfAction(action);
160
160
  return {
161
161
  proposal: action.id,
162
- bot: proposer.type === "bot" ? proposer.name : "unknown",
162
+ bot: proposer.type === "agent" ? proposer.name : "unknown",
163
163
  run: payload.run ?? null,
164
164
  reason: action.reason,
165
165
  evidence: payload.strength ?? null,
@@ -0,0 +1,19 @@
1
+ import type { CacheDatabase, SqlValue } from "../driver.js";
2
+ /**
3
+ * What a bot sends, as the Bots tab filters it: the mail types that put a bot under each name. `messenger` is a bot
4
+ * with an account in a messenger, whatever it sends. @experimental
5
+ */
6
+ export declare const BOT_SENDS: {
7
+ readonly alerts: readonly ["security", "system_alert", "account_notice"];
8
+ readonly receipts: readonly ["order", "bill", "shipping"];
9
+ readonly newsletters: readonly ["newsletter"];
10
+ readonly marketing: readonly ["promotion"];
11
+ readonly messenger: null;
12
+ };
13
+ /** @experimental */
14
+ export type BotSends = keyof typeof BOT_SENDS;
15
+ /** Which bots send any of these, over `b`: by the type of their mail, or a messenger account. */
16
+ export declare const sendsWhere: (database: CacheDatabase, sends: readonly BotSends[]) => {
17
+ sql: string;
18
+ params: SqlValue[];
19
+ };
@@ -0,0 +1,36 @@
1
+ import { CliError } from "@wirecat/cli-base";
2
+ import { typeWhere } from "./email-types.js";
3
+ /**
4
+ * What a bot sends, as the Bots tab filters it: the mail types that put a bot under each name. `messenger` is a bot
5
+ * with an account in a messenger, whatever it sends. @experimental
6
+ */
7
+ export const BOT_SENDS = {
8
+ alerts: ["security", "system_alert", "account_notice"],
9
+ receipts: ["order", "bill", "shipping"],
10
+ newsletters: ["newsletter"],
11
+ marketing: ["promotion"],
12
+ messenger: null,
13
+ };
14
+ /** Which bots send any of these, over `b`: by the type of their mail, or a messenger account. */
15
+ export const sendsWhere = (database, sends) => {
16
+ const unknown = sends.filter((name) => !Object.hasOwn(BOT_SENDS, name));
17
+ if (unknown.length > 0 || sends.length === 0)
18
+ throw new CliError("validation_error", `a bot sends one of ${Object.keys(BOT_SENDS).join(", ")}, got "${unknown.join(", ")}"`, { reason: "sender-bot.unknown-sends" });
19
+ const types = [...new Set(sends.flatMap((name) => BOT_SENDS[name] ?? []))];
20
+ const typed = types.length === 0 ? undefined : typeWhere(database, { types });
21
+ const any = [
22
+ ...(typed === undefined
23
+ ? []
24
+ : [
25
+ "EXISTS (SELECT 1 FROM sender_bot_identities s JOIN emails e ON e.from_identity_id = s.identity_id " +
26
+ `WHERE s.bot_id = b.id AND e.deleted_at IS NULL AND e.outgoing IS NOT 1 AND ${typed.sql.join(" AND ")})`,
27
+ ]),
28
+ ...(sends.includes("messenger")
29
+ ? [
30
+ "EXISTS (SELECT 1 FROM sender_bot_identities s JOIN identities i ON i.id = s.identity_id " +
31
+ "WHERE s.bot_id = b.id AND i.provider <> 'email')",
32
+ ]
33
+ : []),
34
+ ];
35
+ return { sql: `(${any.join(" OR ")})`, params: typed?.params ?? [] };
36
+ };
@@ -10,7 +10,7 @@ import { pageOfRows } from "./rows-page.js";
10
10
  import { storedThing } from "./things.js";
11
11
  import { write } from "./transaction.js";
12
12
  const CONTRACTS = "SELECT k.*, b.name AS author_name, b.kind AS author_kind FROM contracts k " +
13
- "LEFT JOIN bots b ON k.author_type = 'bot' AND b.id = k.author_id";
13
+ "LEFT JOIN bots b ON k.author_type = 'agent' AND b.id = k.author_id";
14
14
  const DAY_MS = 86_400_000;
15
15
  const deadlineOf = (expiration, days) => expiration === null || days === null
16
16
  ? null
@@ -26,7 +26,7 @@ const itemsSql = (kind) => "SELECT d.*, s.name AS stage_name, s.pipeline_id, p.n
26
26
  "b.kind AS author_kind, a.provider AS account_provider, a.external_id AS account_external_id, " +
27
27
  "bs.id AS base_stage_ref_id, bs.name AS base_stage_name " +
28
28
  `FROM ${TABLES[kind]} d JOIN pipeline_stages s ON s.id = d.stage_id JOIN pipelines p ON p.id = s.pipeline_id ` +
29
- "LEFT JOIN bots b ON d.author_type = 'bot' AND b.id = d.author_id LEFT JOIN accounts a ON a.id = d.account_id " +
29
+ "LEFT JOIN bots b ON d.author_type = 'agent' AND b.id = d.author_id LEFT JOIN accounts a ON a.id = d.account_id " +
30
30
  "LEFT JOIN pipeline_stages bs ON s.base_confirmed = 1 AND bs.id = s.base_stage_id";
31
31
  const MAX_STAGES = 30;
32
32
  const MAX_PEOPLE = 20;
@@ -78,7 +78,7 @@ export const planTransfer = (database, snapshot, sourceKey, bindings) => {
78
78
  if (bot && bot.kind !== external.bot.kind)
79
79
  conflicts.add(`destination bot kind differs for ${external.reference}`);
80
80
  if (bot)
81
- found = { type: "bot", id: Number(bot.id) };
81
+ found = { type: "agent", id: Number(bot.id) };
82
82
  // A new author handle is created without copying credentials, settings or metadata.
83
83
  else
84
84
  continue;
@@ -158,7 +158,7 @@ export const transferSnapshot = (database, collection) => read(database, () => {
158
158
  if (identity?.person_id != null)
159
159
  depend("person", identity.person_id);
160
160
  }
161
- if (thing.type === "bot") {
161
+ if (thing.type === "agent") {
162
162
  const bot = database.prepare("SELECT name,kind FROM bots WHERE id=?").get(thing.id);
163
163
  if (bot)
164
164
  item.bot = { name: String(bot.name), kind: String(bot.kind) };
@@ -1,6 +1,6 @@
1
1
  import { type Chunk } from "../../conversations/chunks.js";
2
2
  import type { Stemmer, Stemmers } from "../../search/stem.js";
3
- import type { CacheDatabase } from "../driver.js";
3
+ import { type CacheDatabase } from "../driver.js";
4
4
  export declare const titleOf: (subject: string | null) => string | null;
5
5
  /**
6
6
  * Every piece of mail: a stretch of a thread, one email's attachment, or the text a model wrote about one email. A thread piece holds no email of its
@@ -17,4 +17,13 @@ export declare const queueThreads: (database: CacheDatabase, ids: Iterable<numbe
17
17
  export declare const dropAttachmentChunks: (database: CacheDatabase, emailId: number) => string[];
18
18
  /** Each attachment's extracted text, in pieces for search by meaning, as an email's own text is. */
19
19
  export declare const chunkAttachments: (database: CacheDatabase, accountId: number, emailId: number, now: number) => void;
20
- export declare const drainEmailIndex: (database: CacheDatabase, stemmerFor: (stemmers: Stemmers) => Stemmer) => number;
20
+ export declare const drainEmailIndex: (database: CacheDatabase, stemmerFor: (stemmers: Stemmers) => Stemmer, until?: () => boolean) => number;
21
+ /**
22
+ * Indexes and types the mail of these threads inside the save's own write, plus a little of what was queued before,
23
+ * so the first search finds it done. A drain of
24
+ * its own commits every 200 emails, and under a busy disk each commit's sync costs up to a second: 100,000 saved
25
+ * emails took the first search 564 s (cli-testing performance/mail/types).
26
+ */
27
+ export declare const indexSavedMail: (database: CacheDatabase, stemmerFor: (stemmers: Stemmers) => Stemmer, threadIds: readonly number[]) => void;
28
+ /** Every email still waiting for its words, pieces or type, done a short write at a time until `until` answers true. */
29
+ export declare const catchUpMail: (database: CacheDatabase, stemmerFor: (stemmers: Stemmers) => Stemmer, until?: () => boolean) => void;
@@ -1,7 +1,9 @@
1
1
  import { CHUNK_CHARS, chunkHash, cutChunks, splitText } from "../../conversations/chunks.js";
2
2
  import { mailCore } from "../../conversations/mail-text.js";
3
+ import { isQueryOnly } from "../driver.js";
4
+ import { storeMailTypes, typeSavedMail } from "./email-types.js";
3
5
  import { int, str } from "./events.js";
4
- import { CORPORA, drainCorpus } from "./note-index.js";
6
+ import { CORPORA, drainCorpus, indexQueued } from "./note-index.js";
5
7
  import { write } from "./transaction.js";
6
8
  import { dropUnusedVectors } from "./vector-index.js";
7
9
  export const titleOf = (subject) => subject?.replace(/^\s*((re|fwd?|aw|wg)\s*:\s*)+/i, "").trim() || null;
@@ -102,8 +104,8 @@ export const chunkAttachments = (database, accountId, emailId, now) => {
102
104
  const MAIL_CUT = "mail_pieces_cut";
103
105
  // Each change to a piece's text bumps this, so every store cuts its mail again once and re-embeds it.
104
106
  const CUT = "email, sender at the end";
105
- export const drainEmailIndex = (database, stemmerFor) => {
106
- // Mail was once cut without cleaning, then across the emails of a thread, then with its sender before the subject; a store cut any of those ways is cut again.
107
+ // Mail was once cut without cleaning, then across the emails of a thread, then with its sender before the subject; a store cut any of those ways is cut again.
108
+ const cutCurrently = (database) => {
107
109
  if (database.prepare("SELECT value FROM store_settings WHERE key = ?").get(MAIL_CUT)?.value !== CUT)
108
110
  write(database, () => {
109
111
  const single = database
@@ -120,6 +122,13 @@ export const drainEmailIndex = (database, stemmerFor) => {
120
122
  .prepare("INSERT OR REPLACE INTO store_settings (key, value, at) VALUES (?, ?, ?)")
121
123
  .run(MAIL_CUT, CUT, Date.now());
122
124
  });
125
+ };
126
+ /** How long one write of the word drain may go on taking batches: well inside another writer's 5 s wait. */
127
+ const DRAIN_BUDGET_MS = 250;
128
+ export const drainEmailIndex = (database, stemmerFor, until = () => false) => {
129
+ if (isQueryOnly(database))
130
+ return 0;
131
+ cutCurrently(database);
123
132
  const unqueued = `FROM email_index_pending q JOIN emails e ON e.id = q.id
124
133
  WHERE q.indexable_type = 'email' AND e.email_thread_id IS NOT NULL AND NOT EXISTS (SELECT 1 FROM email_index_pending t
125
134
  WHERE t.indexable_type = 'email_thread' AND t.id = e.email_thread_id)`;
@@ -141,11 +150,11 @@ export const drainEmailIndex = (database, stemmerFor) => {
141
150
  dropUnusedVectors(database, before);
142
151
  }
143
152
  });
144
- const emails = drainCorpus(database, CORPORA.email, stemmerFor);
153
+ const emails = drainCorpus(database, CORPORA.email, stemmerFor, { until, budgetMs: DRAIN_BUDGET_MS });
145
154
  const next = database.prepare("SELECT id FROM email_index_pending WHERE indexable_type = 'email_thread' ORDER BY id LIMIT 50");
146
155
  const done = database.prepare("DELETE FROM email_index_pending WHERE indexable_type = 'email_thread' AND id = ?");
147
156
  let threads = 0;
148
- while (next.all().length > 0)
157
+ while (!until() && next.all().length > 0)
149
158
  threads += write(database, () => {
150
159
  const ids = next.all().map(({ id }) => Number(id));
151
160
  for (const id of ids) {
@@ -156,3 +165,45 @@ export const drainEmailIndex = (database, stemmerFor) => {
156
165
  });
157
166
  return emails + threads;
158
167
  };
168
+ /** How many emails, and threads, queued before this save one save also indexes: the queue drains as mail syncs. */
169
+ const EMAIL_BACKLOG_ON_SAVE = 500;
170
+ const THREAD_BACKLOG_ON_SAVE = 50;
171
+ /**
172
+ * Indexes and types the mail of these threads inside the save's own write, plus a little of what was queued before,
173
+ * so the first search finds it done. A drain of
174
+ * its own commits every 200 emails, and under a busy disk each commit's sync costs up to a second: 100,000 saved
175
+ * emails took the first search 564 s (cli-testing performance/mail/types).
176
+ */
177
+ export const indexSavedMail = (database, stemmerFor, threadIds) => {
178
+ cutCurrently(database);
179
+ const ids = (sql, ...params) => database
180
+ .prepare(sql)
181
+ .all(...params)
182
+ .map(({ id }) => Number(id));
183
+ const saved = ids(`SELECT q.id FROM email_index_pending q JOIN emails e ON e.id = q.id
184
+ WHERE q.indexable_type = 'email' AND e.email_thread_id IN (SELECT value FROM json_each(?))`, JSON.stringify(threadIds));
185
+ const backlog = ids("SELECT id FROM email_index_pending WHERE indexable_type = 'email' ORDER BY id LIMIT ?", EMAIL_BACKLOG_ON_SAVE);
186
+ const emails = [...new Set([...saved, ...backlog])];
187
+ // An email's words leave the queue with it, so its thread is queued first, as the drain does.
188
+ database
189
+ .prepare(`INSERT OR IGNORE INTO email_index_pending (indexable_type, id) SELECT DISTINCT 'email_thread', email_thread_id
190
+ FROM emails WHERE id IN (SELECT value FROM json_each(?)) AND email_thread_id IS NOT NULL`)
191
+ .run(JSON.stringify(emails));
192
+ indexQueued(database, CORPORA.email, stemmerFor, emails);
193
+ const threads = new Set([
194
+ ...ids("SELECT id FROM email_index_pending WHERE indexable_type = 'email_thread' AND id IN (SELECT value FROM json_each(?))", JSON.stringify(threadIds)),
195
+ ...ids("SELECT id FROM email_index_pending WHERE indexable_type = 'email_thread' ORDER BY id LIMIT ?", THREAD_BACKLOG_ON_SAVE),
196
+ ]);
197
+ const done = database.prepare("DELETE FROM email_index_pending WHERE indexable_type = 'email_thread' AND id = ?");
198
+ for (const id of threads) {
199
+ chunkThread(database, id, Date.now());
200
+ done.run(id);
201
+ }
202
+ typeSavedMail(database, threadIds);
203
+ };
204
+ /** Every email still waiting for its words, pieces or type, done a short write at a time until `until` answers true. */
205
+ export const catchUpMail = (database, stemmerFor, until = () => false) => {
206
+ drainEmailIndex(database, stemmerFor, until);
207
+ if (!until())
208
+ storeMailTypes(database, until);
209
+ };
@@ -14,7 +14,14 @@ export declare const typesCurrent: (database: CacheDatabase) => boolean;
14
14
  * changed, a batch per write so another process never waits long for the lock. A query-only open keeps nothing.
15
15
  * Answers whether every stored type is current.
16
16
  */
17
- export declare const storeMailTypes: (database: CacheDatabase) => boolean;
17
+ export declare const storeMailTypes: (database: CacheDatabase, until?: () => boolean) => boolean;
18
+ /**
19
+ * Types the mail of these threads inside the save's own write, plus a little of what is untyped from before: a
20
+ * read-only open cannot keep types, so a store typed only by its first search made that search work out every email
21
+ * (1.5–1.8 s of a 2 s limit on 100,000, cli-testing performance/mail/types). Skipped while a rules change waits to
22
+ * clear the stored types: those are typed again in batches by the next filtered read.
23
+ */
24
+ export declare const typeSavedMail: (database: CacheDatabase, threadIds: readonly number[]) => void;
18
25
  /** Each email's stored type, or for one the store has not typed yet, the type worked out for this read. */
19
26
  export declare const withTypes: <T extends {
20
27
  id: number;
@@ -43,7 +50,7 @@ export declare const typeCondition: (database: CacheDatabase, filter: TypeFilter
43
50
  };
44
51
  /** One sender's mail, counted by type and reach: a shop's receipts and its sales side by side. @experimental */
45
52
  export interface SenderMailTypes {
46
- /** `person:<id>`, `sender-bot:<id>`, or `null` when the store links the address to neither. */
53
+ /** `person:<id>`, `bot:<id>`, or `null` when the store links the address to neither. */
47
54
  ref: string | null;
48
55
  /** The addresses it sent from, lower case. */
49
56
  addresses: string[];
@@ -75,6 +82,11 @@ export declare const mailSenders: (database: CacheDatabase, filter: SenderTypesF
75
82
  };
76
83
  /** @experimental */
77
84
  export interface MailTypeStore {
85
+ /**
86
+ * Indexes and types every email still waiting for it, a short write at a time, until `until` answers true. Mail sync
87
+ * calls it once it has saved, so the first search, also on a read-only open, finds the work done.
88
+ */
89
+ catchUp(until?: () => boolean): Promise<void>;
78
90
  /**
79
91
  * Senders of incoming mail with their mail counted by type and reach, most mail first; a sender is listed when any of
80
92
  * its emails passes `types` and `reaches`.
@@ -84,4 +96,4 @@ export interface MailTypeStore {
84
96
  total: number;
85
97
  }>;
86
98
  }
87
- export declare const mailTypeStore: (database: CacheDatabase) => MailTypeStore;
99
+ export declare const mailTypeStore: (database: CacheDatabase) => Omit<MailTypeStore, "catchUp">;