@wirecat/cli-core 0.599.0 → 0.601.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 (65) hide show
  1. package/CHANGELOG.md +70 -0
  2. package/dist/background/deliver.js +1 -1
  3. package/dist/background/schedules.d.ts +1 -1
  4. package/dist/calendar/cli/search-all.js +9 -2
  5. package/dist/cli/app-doctor-command.js +18 -10
  6. package/dist/cli/bot/api-input.js +8 -2
  7. package/dist/cli/context.d.ts +2 -0
  8. package/dist/cli/contract-templates.js +2 -1
  9. package/dist/cli/effects.d.ts +5 -0
  10. package/dist/cli/effects.js +5 -0
  11. package/dist/cli/index.d.ts +2 -1
  12. package/dist/cli/index.js +2 -1
  13. package/dist/cli/messenger/search-answers.d.ts +5 -1
  14. package/dist/cli/messenger/search-answers.js +4 -1
  15. package/dist/cli/new-file.d.ts +2 -0
  16. package/dist/cli/new-file.js +13 -0
  17. package/dist/cli/program.js +3 -0
  18. package/dist/cli/schedule/schedule-command.js +10 -8
  19. package/dist/cli/search-left-out.d.ts +27 -0
  20. package/dist/cli/search-left-out.js +31 -0
  21. package/dist/crm/cli/index.js +2 -7
  22. package/dist/crm/cli/search-all.js +17 -2
  23. package/dist/crm/index.d.ts +1 -1
  24. package/dist/crm/index.js +1 -1
  25. package/dist/crm/writes.d.ts +17 -0
  26. package/dist/crm/writes.js +31 -16
  27. package/dist/entities/index.d.ts +1 -1
  28. package/dist/entities/list-results.d.ts +1 -1
  29. package/dist/entities/list-results.js +1 -1
  30. package/dist/errors/reasons.js +15 -0
  31. package/dist/index.d.ts +1 -1
  32. package/dist/index.js +1 -1
  33. package/dist/meetings/cli/index.d.ts +14 -0
  34. package/dist/meetings/cli/index.js +18 -6
  35. package/dist/meetings/index.d.ts +1 -1
  36. package/dist/meetings/mcp/index.d.ts +15 -15
  37. package/dist/meetings/pull.d.ts +13 -1
  38. package/dist/meetings/pull.js +34 -8
  39. package/dist/meetings/source.d.ts +5 -0
  40. package/dist/resolve.d.ts +2 -2
  41. package/dist/resolve.js +4 -3
  42. package/dist/services/search-all.d.ts +3 -0
  43. package/dist/services/search-all.js +1 -0
  44. package/dist/speech/local.d.ts +2 -1
  45. package/dist/speech/local.js +12 -1
  46. package/dist/speech/recognize.d.ts +2 -0
  47. package/dist/speech/recognize.js +15 -0
  48. package/dist/store/decision-requests.d.ts +10 -0
  49. package/dist/store/decision-requests.js +16 -0
  50. package/dist/store/index.d.ts +2 -0
  51. package/dist/store/index.js +1 -0
  52. package/dist/store/sqlite/deals.d.ts +3 -1
  53. package/dist/store/sqlite/deals.js +2 -2
  54. package/dist/store/sqlite/decision-requests.d.ts +59 -0
  55. package/dist/store/sqlite/decision-requests.js +111 -0
  56. package/dist/store/sqlite/manifest.js +2 -0
  57. package/dist/store/sqlite/migrations.generated.js +12 -0
  58. package/dist/store/sqlite/schema/decision-requests.d.ts +233 -0
  59. package/dist/store/sqlite/schema/decision-requests.js +20 -0
  60. package/dist/store/sqlite/schema.d.ts +1 -0
  61. package/dist/store/sqlite/schema.js +1 -0
  62. package/dist/store/store.d.ts +3 -0
  63. package/dist/store/store.js +5 -0
  64. package/package.json +4 -4
  65. package/parity.json +14 -10
@@ -13,6 +13,7 @@ export interface LocalSpeechRecognitionModel {
13
13
  export interface LocalSpeechBackend {
14
14
  recognize(pcm: Float32Array): string;
15
15
  pieces?(pcm: Float32Array): TimedText[];
16
+ piecesUntil?(pcm: Float32Array, signal: AbortSignal): Promise<TimedText[]>;
16
17
  free(): void;
17
18
  }
18
19
  export interface LocalSpeechRecognizer extends LocalSpeechRecognitionModel {
@@ -34,6 +35,6 @@ export declare const localSpeechRecognitionModel: (id: string) => Readonly<Local
34
35
  * A whole recording, one channel of it, cut at pauses by the voice detector: each piece's text with where it lies,
35
36
  * in seconds. Two channels heard this way merge into a dialogue by `start`. Existing installed models only.
36
37
  */
37
- export declare const recognizeLocalPieces: (id: string, audio: Pcm, options?: Pick<LocalSpeechRecognizerOptions, "directory" | "env" | "open">) => Promise<TimedText[]>;
38
+ export declare const recognizeLocalPieces: (id: string, audio: Pcm, options?: Pick<LocalSpeechRecognizerOptions, "directory" | "env" | "open" | "signal">) => Promise<TimedText[]>;
38
39
  /** Existing installed models only. Synchronous inference cancels between bounded windows. */
39
40
  export declare const openLocalSpeechRecognizer: (id: string, input?: LocalSpeechRecognizerOptions) => Promise<LocalSpeechRecognizer>;
@@ -47,7 +47,18 @@ export const recognizeLocalPieces = async (id, audio, options = {}) => {
47
47
  try {
48
48
  if (!engine.pieces)
49
49
  throw new CliError("configuration_error", "this speech backend gives no timed pieces");
50
- return engine.pieces(toModelRate(audio.samples, audio.rate));
50
+ const pcm = toModelRate(audio.samples, audio.rate);
51
+ const { signal } = options;
52
+ if (!signal)
53
+ return engine.pieces(pcm);
54
+ cancelled(signal);
55
+ try {
56
+ return engine.piecesUntil ? await engine.piecesUntil(pcm, signal) : engine.pieces(pcm);
57
+ }
58
+ catch (error) {
59
+ cancelled(signal);
60
+ throw error;
61
+ }
51
62
  }
52
63
  finally {
53
64
  engine.free();
@@ -10,6 +10,8 @@ export interface Recognizer {
10
10
  recognize(pcm: Float32Array): string;
11
11
  /** Each stretch of speech the voice detector cut, with where it lies; the same input as `recognize`. */
12
12
  pieces?(pcm: Float32Array): TimedText[];
13
+ /** `pieces`, giving the event loop a turn between pieces, so `signal` can stop a long recording between two. */
14
+ piecesUntil?(pcm: Float32Array, signal: AbortSignal): Promise<TimedText[]>;
13
15
  free(): void;
14
16
  }
15
17
  export declare const SAMPLE_RATE = 16000;
@@ -152,11 +152,26 @@ export const openRecognizer = (model, path, vadModel) => {
152
152
  });
153
153
  return heard;
154
154
  };
155
+ // Decoding is synchronous: without a turn of the event loop between pieces no abort could ever be seen.
156
+ const piecesUntil = async (pcm, signal) => {
157
+ const spans = [];
158
+ cut(vad, pcm, (span) => spans.push(span));
159
+ const heard = [];
160
+ for (const { start, end, samples } of spans) {
161
+ await new Promise((resolve) => setImmediate(resolve));
162
+ signal.throwIfAborted();
163
+ const text = piece(samples);
164
+ if (text)
165
+ heard.push({ start, end, text });
166
+ }
167
+ return heard;
168
+ };
155
169
  return {
156
170
  recognize: (pcm) => pieces(pcm)
157
171
  .map(({ text }) => text)
158
172
  .join(" "),
159
173
  pieces,
174
+ piecesUntil,
160
175
  free: () => {
161
176
  vad.free();
162
177
  engine.free();
@@ -0,0 +1,10 @@
1
+ export declare const DECISION_ACTIONS: readonly ["confirm", "reject", "ask-confirm", "ask-reject", "back", "later"];
2
+ export type DecisionAction = (typeof DECISION_ACTIONS)[number];
3
+ /** Seventy-two hours: a press after that finds nothing to take. */
4
+ export declare const DECISION_TTL_MS: number;
5
+ export declare const CALLBACK_PREFIX = "wcr1:";
6
+ export declare const isDecisionToken: (value: unknown) => value is string;
7
+ /** The 27 bytes a button carries: Telegram allows 64. */
8
+ export declare const callbackDataOf: (token: string) => string;
9
+ /** The token in a button's data, or `undefined` for anything else; the data is only ever looked up, never read further. */
10
+ export declare const parseCallbackData: (data: unknown) => string | undefined;
@@ -0,0 +1,16 @@
1
+ export const DECISION_ACTIONS = ["confirm", "reject", "ask-confirm", "ask-reject", "back", "later"];
2
+ /** Seventy-two hours: a press after that finds nothing to take. */
3
+ export const DECISION_TTL_MS = 72 * 60 * 60 * 1000;
4
+ export const CALLBACK_PREFIX = "wcr1:";
5
+ // 16 random bytes in base64url are 22 characters, and the last one carries 2 data bits: only these four can end a token.
6
+ const TOKEN = /^[A-Za-z0-9_-]{21}[AQgw]$/;
7
+ const CALLBACK = /^wcr1:([A-Za-z0-9_-]{21}[AQgw])$/;
8
+ export const isDecisionToken = (value) => typeof value === "string" && TOKEN.test(value);
9
+ /** The 27 bytes a button carries: Telegram allows 64. */
10
+ export const callbackDataOf = (token) => {
11
+ if (!isDecisionToken(token))
12
+ throw new TypeError("not a decision token");
13
+ return `${CALLBACK_PREFIX}${token}`;
14
+ };
15
+ /** The token in a button's data, or `undefined` for anything else; the data is only ever looked up, never read further. */
16
+ export const parseCallbackData = (data) => typeof data === "string" ? CALLBACK.exec(data)?.[1] : undefined;
@@ -10,6 +10,7 @@ export { PAYMENT_DIRECTIONS, PAYMENT_STATES, type Payment, paymentTitle, validat
10
10
  export { CLOSED_STATES, isClosedState, PRIORITY_LABELS, type PriorityLabel, priorityLabel, priorityOf, priorityOption, TASK_STATES, type TaskState, } from "../tasks/index.js";
11
11
  export type { AccountMail, AccountMeetings, AccountStore } from "./account-store.js";
12
12
  export { type DamageExplanation, explainDamage } from "./damage.js";
13
+ export { CALLBACK_PREFIX, callbackDataOf, DECISION_ACTIONS, DECISION_TTL_MS, type DecisionAction, isDecisionToken, parseCallbackData, } from "./decision-requests.js";
13
14
  export { assertMayDecide, DEFAULT_DECISION_POLICY, type Decider, type DecisionPolicy, isOwnerOnlyKind, mayDecide, type Proposer, type Refusal, } from "./decisions.js";
14
15
  export type { DocumentTransferOptions, DocumentTransferPreview, DocumentTransferReceipt, } from "./document-transfer/index.js";
15
16
  export { applyDocumentTransfer, previewDocumentTransfer } from "./document-transfer/index.js";
@@ -38,6 +39,7 @@ export { CATALOG_QUERY } from "./sqlite/catalog.js";
38
39
  export type { ChatMetadata } from "./sqlite/chats.js";
39
40
  export { type CrmCopies, type CrmSaved, type CrmSkipped, crmIdentityId } from "./sqlite/crm.js";
40
41
  export type { Deal, DealFilter, DealInput, DealPerson, DealScope, DealsStore, FunnelStage, Pipeline, PipelineInput, PipelineReport, PipelineStage, } from "./sqlite/deals.js";
42
+ export type { DecisionMessage, DecisionPress, DecisionRefusal, DecisionRequest, DecisionRequestInput, DecisionRequestStore, TakeResult, } from "./sqlite/decision-requests.js";
41
43
  export type { Email, EmailAddress, EmailAttachment, EmailFacts, EmailFilter, EmailInput, EmailInThread, EmailLocationInput, EmailRecipient, EmailRef, EmailThread, EmailVectorHit, FolderEmail, Mailbox, MailboxInput, MailFilter, MailStore, PartialEmail, SenderScore, ThreadDetails, ThreadSave, } from "./sqlite/emails.js";
42
44
  export { EVENT_FIELDS, type EventChunkToEmbed, type EventHit, type EventQuery, type EventSearch, type NearestEvent, } from "./sqlite/event-search.js";
43
45
  export type { EvidenceSource } from "./sqlite/evidence-sources.js";
@@ -4,6 +4,7 @@ export { note } from "../entities/note.js";
4
4
  export { PAYMENT_DIRECTIONS, PAYMENT_STATES, paymentTitle, validatePayment } from "../meetings/index.js";
5
5
  export { CLOSED_STATES, isClosedState, PRIORITY_LABELS, priorityLabel, priorityOf, priorityOption, TASK_STATES, } from "../tasks/index.js";
6
6
  export { explainDamage } from "./damage.js";
7
+ export { CALLBACK_PREFIX, callbackDataOf, DECISION_ACTIONS, DECISION_TTL_MS, isDecisionToken, parseCallbackData, } from "./decision-requests.js";
7
8
  export { assertMayDecide, DEFAULT_DECISION_POLICY, isOwnerOnlyKind, mayDecide, } from "./decisions.js";
8
9
  export { applyDocumentTransfer, previewDocumentTransfer } from "./document-transfer/index.js";
9
10
  export { PRAGMAS } from "./driver.js";
@@ -153,6 +153,8 @@ export interface DealSearch {
153
153
  anyWord?: boolean;
154
154
  /** Only the copies of these CRM accounts; absent, every account's and the owner's own. */
155
155
  accounts?: AccountKey[];
156
+ /** Only these kinds; absent, deals and leads. */
157
+ kinds?: readonly DealKind[];
156
158
  /** 1–500, 100 by default. */
157
159
  limit?: number;
158
160
  }
@@ -217,7 +219,7 @@ export declare const dealOperationsOver: (context: StoreContext) => {
217
219
  add: (input: DealInput) => Deal;
218
220
  get: (reference: string) => Deal;
219
221
  list: (filter?: DealFilter) => Deal[];
220
- find: ({ words, anyWord, accounts, limit }: DealSearch) => Deal[];
222
+ find: ({ words, anyWord, accounts, kinds, limit }: DealSearch) => Deal[];
221
223
  move: (reference: string, { stage, by }: {
222
224
  stage: string;
223
225
  by: Author;
@@ -367,14 +367,14 @@ export const dealOperationsOver = (context) => {
367
367
  .all(status, status, project, project, stage, stage, pipeline, pipeline, organization?.id ?? null, organization?.id ?? null, own, provider, provider, account, ...by.params, limit, Math.max(0, Math.trunc(filter.offset ?? 0)))
368
368
  .map(itemOf(kind));
369
369
  },
370
- find: ({ words, anyWord, accounts, limit }) => {
370
+ find: ({ words, anyWord, accounts, kinds = DEAL_KINDS, limit }) => {
371
371
  const wanted = [...new Set(words.map((word) => fold(word).trim()).filter(Boolean))];
372
372
  if (!wanted.length)
373
373
  return [];
374
374
  const most = Math.min(Math.max(limit ?? 100, 1), 500);
375
375
  const within = accounts?.map(({ provider, account }) => `${provider}\u0000${account}`);
376
376
  // Titles are short and a CRM holds thousands, not millions: folding them here is cheaper than a word index.
377
- const found = DEAL_KINDS.flatMap((kind) => database
377
+ const found = kinds.flatMap((kind) => database
378
378
  .prepare(`SELECT d.id, d.title, d.updated_at, a.provider, a.external_id AS account FROM ${TABLES[kind]} d ` +
379
379
  "LEFT JOIN accounts a ON a.id = d.account_id WHERE d.deleted_at IS NULL")
380
380
  .all()
@@ -0,0 +1,59 @@
1
+ import { type DecisionAction } from "../decision-requests.js";
2
+ import type { StoreContext } from "./open.js";
3
+ /** The message a set of buttons is on. */
4
+ export interface DecisionMessage {
5
+ channel: string;
6
+ botProfile: string;
7
+ chatId: string;
8
+ messageId: string;
9
+ }
10
+ export interface DecisionRequestInput extends DecisionMessage {
11
+ proposalId: string;
12
+ batchDigest: string;
13
+ ownerUserId: string;
14
+ /** One button each, in this order; no action twice. */
15
+ actions: readonly DecisionAction[];
16
+ }
17
+ export interface DecisionRequest extends DecisionMessage {
18
+ proposalId: string;
19
+ action: DecisionAction;
20
+ batchDigest: string;
21
+ ownerUserId: string;
22
+ createdAt: number;
23
+ expiresAt: number;
24
+ }
25
+ /** Where and by whom the press came; every part must equal what the button was sent with. */
26
+ export interface DecisionPress {
27
+ botProfile: string;
28
+ chatId: string;
29
+ messageId: string;
30
+ ownerUserId: string;
31
+ }
32
+ export type DecisionRefusal = "decision.token-unknown" | "decision.token-used" | "decision.token-cancelled" | "decision.token-expired" | "decision.token-mismatch";
33
+ export type TakeResult = {
34
+ ok: true;
35
+ request: DecisionRequest;
36
+ cancelled: number;
37
+ } | {
38
+ ok: false;
39
+ reason: DecisionRefusal;
40
+ };
41
+ export interface DecisionRequestStore {
42
+ /** One token per action, for one message; the tokens are returned once and kept only as digests. */
43
+ create(input: DecisionRequestInput): {
44
+ action: DecisionAction;
45
+ token: string;
46
+ }[];
47
+ /**
48
+ * Uses a token once and cancels the message's other open tokens in the same transaction. A token for another
49
+ * bot, chat, message or owner is refused as a mismatch before its state is looked at, and stays open.
50
+ */
51
+ take(token: string, expect: DecisionPress): TakeResult;
52
+ /** Cancels every open token, of one bot when given; for turning the feature off. Returns how many. */
53
+ cancelOpen(scope?: Partial<Pick<DecisionMessage, "channel" | "botProfile">>): number;
54
+ /** Deletes rows that expired, were used or were cancelled more than 30 days before `at`; returns how many. */
55
+ prune(at?: number): number;
56
+ /** The open (unused, uncancelled, unexpired) buttons of a message, oldest first. */
57
+ open(message: DecisionMessage): DecisionRequest[];
58
+ }
59
+ export declare const decisionRequestStoreOver: ({ database, now }: StoreContext) => DecisionRequestStore;
@@ -0,0 +1,111 @@
1
+ import { createHash, randomBytes } from "node:crypto";
2
+ import { CliError } from "@wirecat/cli-base";
3
+ import { DECISION_ACTIONS, DECISION_TTL_MS, isDecisionToken } from "../decision-requests.js";
4
+ import { write } from "./transaction.js";
5
+ const digestOf = (token) => createHash("sha256").update(token).digest("hex");
6
+ const newToken = () => randomBytes(16).toString("base64url");
7
+ const requestOf = (row) => ({
8
+ proposalId: row.proposal_id,
9
+ action: row.action,
10
+ batchDigest: row.batch_digest,
11
+ channel: row.channel,
12
+ botProfile: row.bot_profile,
13
+ chatId: row.chat_id,
14
+ messageId: row.message_id,
15
+ ownerUserId: row.owner_user_id,
16
+ createdAt: row.created_at,
17
+ expiresAt: row.expires_at,
18
+ });
19
+ const PRUNE_AFTER_MS = 30 * 24 * 60 * 60 * 1000;
20
+ const SAME_MESSAGE = "channel=? AND bot_profile=? AND chat_id=? AND message_id=?";
21
+ const OPEN = "used_at IS NULL AND cancelled_at IS NULL";
22
+ export const decisionRequestStoreOver = ({ database, now }) => {
23
+ const refusal = (row, at) => {
24
+ if (!row)
25
+ return "decision.token-unknown";
26
+ if (row.used_at !== null)
27
+ return "decision.token-used";
28
+ if (row.cancelled_at !== null)
29
+ return "decision.token-cancelled";
30
+ if (row.expires_at <= at)
31
+ return "decision.token-expired";
32
+ return undefined;
33
+ };
34
+ return {
35
+ create: (input) => {
36
+ const { actions, ...fields } = input;
37
+ const text = [
38
+ fields.proposalId,
39
+ fields.batchDigest,
40
+ fields.channel,
41
+ fields.botProfile,
42
+ fields.chatId,
43
+ fields.messageId,
44
+ fields.ownerUserId,
45
+ ];
46
+ if (text.some((value) => typeof value !== "string" || value === ""))
47
+ throw new CliError("validation_error", "a decision request needs its batch, message and owner", {
48
+ reason: "decision.request-invalid",
49
+ });
50
+ if (actions.length === 0 ||
51
+ new Set(actions).size !== actions.length ||
52
+ actions.some((action) => !DECISION_ACTIONS.includes(action)))
53
+ throw new CliError("validation_error", "a decision request needs distinct, known actions", {
54
+ reason: "decision.request-invalid",
55
+ });
56
+ const at = now();
57
+ return write(database, () => actions.map((action) => {
58
+ const token = newToken();
59
+ database
60
+ .prepare(`INSERT INTO decision_requests (token_digest, proposal_id, action, batch_digest, channel, bot_profile,
61
+ chat_id, message_id, owner_user_id, created_at, expires_at) VALUES (?,?,?,?,?,?,?,?,?,?,?)`)
62
+ .run(digestOf(token), fields.proposalId, action, fields.batchDigest, fields.channel, fields.botProfile, fields.chatId, fields.messageId, fields.ownerUserId, at, at + DECISION_TTL_MS);
63
+ return { action, token };
64
+ }));
65
+ },
66
+ take: (token, expect) => {
67
+ if (!isDecisionToken(token))
68
+ return { ok: false, reason: "decision.token-unknown" };
69
+ const digest = digestOf(token);
70
+ return write(database, () => {
71
+ const at = now();
72
+ const row = database.prepare("SELECT * FROM decision_requests WHERE token_digest=?").get(digest);
73
+ if (!row)
74
+ return { ok: false, reason: "decision.token-unknown" };
75
+ if (expect.botProfile !== row.bot_profile ||
76
+ expect.chatId !== row.chat_id ||
77
+ expect.messageId !== row.message_id ||
78
+ expect.ownerUserId !== row.owner_user_id)
79
+ return { ok: false, reason: "decision.token-mismatch" };
80
+ const reason = refusal(row, at);
81
+ if (reason)
82
+ return { ok: false, reason };
83
+ database.prepare("UPDATE decision_requests SET used_at=? WHERE id=?").run(at, row.id);
84
+ const { changes } = database
85
+ .prepare(`UPDATE decision_requests SET cancelled_at=? WHERE ${SAME_MESSAGE} AND id<>? AND ${OPEN}`)
86
+ .run(at, row.channel, row.bot_profile, row.chat_id, row.message_id, row.id);
87
+ return { ok: true, request: requestOf(row), cancelled: Number(changes) };
88
+ });
89
+ },
90
+ cancelOpen: (scope = {}) => {
91
+ const filters = [];
92
+ const values = [];
93
+ if (scope.channel !== undefined) {
94
+ filters.push("channel=?");
95
+ values.push(scope.channel);
96
+ }
97
+ if (scope.botProfile !== undefined) {
98
+ filters.push("bot_profile=?");
99
+ values.push(scope.botProfile);
100
+ }
101
+ const where = [OPEN, ...filters].join(" AND ");
102
+ return write(database, () => Number(database.prepare(`UPDATE decision_requests SET cancelled_at=? WHERE ${where}`).run(now(), ...values).changes));
103
+ },
104
+ prune: (at = now()) => write(database, () => Number(database
105
+ .prepare(`DELETE FROM decision_requests WHERE expires_at < ?1 OR used_at < ?1 OR cancelled_at < ?1`)
106
+ .run(at - PRUNE_AFTER_MS).changes)),
107
+ open: (message) => database
108
+ .prepare(`SELECT * FROM decision_requests WHERE ${SAME_MESSAGE} AND ${OPEN} AND expires_at>? ORDER BY id`)
109
+ .all(message.channel, message.botProfile, message.chatId, message.messageId, now()).map(requestOf),
110
+ };
111
+ };
@@ -111,6 +111,8 @@ export const MANIFEST = [
111
111
  { name: "20261106010507_version-52-deals-rules", version: 52, minCompatible: 34 },
112
112
  { name: "20261106165009_version-53-crm-pipelines", version: 53, minCompatible: 34 },
113
113
  { name: "20261106225547_version-54-crm-fields", version: 54, minCompatible: 34 },
114
+ { name: "20261107032742_version-55-decision-requests", version: 55, minCompatible: 34 },
115
+ { name: "20261107043407_version-55-decision-requests-index", version: 55, minCompatible: 34 },
114
116
  ];
115
117
  export const generatedMigrations = (manifest = MANIFEST, generated = GENERATED) => {
116
118
  const migrations = [];
@@ -1048,5 +1048,17 @@ export const GENERATED = [
1048
1048
  "statements": [
1049
1049
  "CREATE TABLE `crm_fields` (\n\t`id` integer PRIMARY KEY,\n\t`account_id` integer NOT NULL,\n\t`kind` text NOT NULL,\n\t`code` text NOT NULL,\n\t`label` text,\n\t`type` text NOT NULL,\n\t`multiple` integer NOT NULL,\n\t`filterable` integer NOT NULL,\n\t`options` text,\n\t`position` integer NOT NULL,\n\t`created_at` integer NOT NULL,\n\t`updated_at` integer NOT NULL,\n\t`deleted_at` integer,\n\tCONSTRAINT `fk_crm_fields_account_id_accounts_id_fk` FOREIGN KEY (`account_id`) REFERENCES `accounts`(`id`),\n\tCONSTRAINT `crm_fields_account_id_kind_code_unique` UNIQUE(`account_id`,`kind`,`code`)\n);"
1050
1050
  ]
1051
+ },
1052
+ {
1053
+ "name": "20261107032742_version-55-decision-requests",
1054
+ "statements": [
1055
+ "CREATE TABLE `decision_requests` (\n\t`id` integer PRIMARY KEY,\n\t`token_digest` text NOT NULL UNIQUE,\n\t`proposal_id` text NOT NULL,\n\t`action` text NOT NULL,\n\t`batch_digest` text NOT NULL,\n\t`channel` text NOT NULL,\n\t`bot_profile` text NOT NULL,\n\t`chat_id` text NOT NULL,\n\t`message_id` text NOT NULL,\n\t`owner_user_id` text NOT NULL,\n\t`created_at` integer NOT NULL,\n\t`expires_at` integer NOT NULL,\n\t`used_at` integer,\n\t`cancelled_at` integer\n);"
1056
+ ]
1057
+ },
1058
+ {
1059
+ "name": "20261107043407_version-55-decision-requests-index",
1060
+ "statements": [
1061
+ "CREATE INDEX `decision_requests_by_channel_bot_profile_chat_id_message_id` ON `decision_requests` (`channel`,`bot_profile`,`chat_id`,`message_id`);"
1062
+ ]
1051
1063
  }
1052
1064
  ];
@@ -0,0 +1,233 @@
1
+ /** One button of a message that asks the owner to decide a batch; only the token's digest is kept. */
2
+ export declare const decisionRequests: import("drizzle-orm/sqlite-core").SQLiteTableWithColumns<{
3
+ name: "decision_requests";
4
+ schema: undefined;
5
+ columns: {
6
+ id: import("drizzle-orm/sqlite-core").SQLiteColumn<{
7
+ name: string;
8
+ tableName: "decision_requests";
9
+ dataType: "number int53";
10
+ data: number;
11
+ driverParam: number;
12
+ notNull: true;
13
+ hasDefault: true;
14
+ isPrimaryKey: true;
15
+ isAutoincrement: false;
16
+ hasRuntimeDefault: false;
17
+ enumValues: undefined;
18
+ baseColumn: never;
19
+ identity: undefined;
20
+ generated: undefined;
21
+ }, {}>;
22
+ tokenDigest: import("drizzle-orm/sqlite-core").SQLiteColumn<{
23
+ name: string;
24
+ tableName: "decision_requests";
25
+ dataType: "string";
26
+ data: string;
27
+ driverParam: string;
28
+ notNull: true;
29
+ hasDefault: false;
30
+ isPrimaryKey: false;
31
+ isAutoincrement: false;
32
+ hasRuntimeDefault: false;
33
+ enumValues: [string, ...string[]];
34
+ baseColumn: never;
35
+ identity: undefined;
36
+ generated: undefined;
37
+ }, {}>;
38
+ proposalId: import("drizzle-orm/sqlite-core").SQLiteColumn<{
39
+ name: string;
40
+ tableName: "decision_requests";
41
+ dataType: "string";
42
+ data: string;
43
+ driverParam: string;
44
+ notNull: true;
45
+ hasDefault: false;
46
+ isPrimaryKey: false;
47
+ isAutoincrement: false;
48
+ hasRuntimeDefault: false;
49
+ enumValues: [string, ...string[]];
50
+ baseColumn: never;
51
+ identity: undefined;
52
+ generated: undefined;
53
+ }, {}>;
54
+ action: import("drizzle-orm/sqlite-core").SQLiteColumn<{
55
+ name: string;
56
+ tableName: "decision_requests";
57
+ dataType: "string";
58
+ data: string;
59
+ driverParam: string;
60
+ notNull: true;
61
+ hasDefault: false;
62
+ isPrimaryKey: false;
63
+ isAutoincrement: false;
64
+ hasRuntimeDefault: false;
65
+ enumValues: [string, ...string[]];
66
+ baseColumn: never;
67
+ identity: undefined;
68
+ generated: undefined;
69
+ }, {}>;
70
+ batchDigest: import("drizzle-orm/sqlite-core").SQLiteColumn<{
71
+ name: string;
72
+ tableName: "decision_requests";
73
+ dataType: "string";
74
+ data: string;
75
+ driverParam: string;
76
+ notNull: true;
77
+ hasDefault: false;
78
+ isPrimaryKey: false;
79
+ isAutoincrement: false;
80
+ hasRuntimeDefault: false;
81
+ enumValues: [string, ...string[]];
82
+ baseColumn: never;
83
+ identity: undefined;
84
+ generated: undefined;
85
+ }, {}>;
86
+ channel: import("drizzle-orm/sqlite-core").SQLiteColumn<{
87
+ name: string;
88
+ tableName: "decision_requests";
89
+ dataType: "string";
90
+ data: string;
91
+ driverParam: string;
92
+ notNull: true;
93
+ hasDefault: false;
94
+ isPrimaryKey: false;
95
+ isAutoincrement: false;
96
+ hasRuntimeDefault: false;
97
+ enumValues: [string, ...string[]];
98
+ baseColumn: never;
99
+ identity: undefined;
100
+ generated: undefined;
101
+ }, {}>;
102
+ botProfile: import("drizzle-orm/sqlite-core").SQLiteColumn<{
103
+ name: string;
104
+ tableName: "decision_requests";
105
+ dataType: "string";
106
+ data: string;
107
+ driverParam: string;
108
+ notNull: true;
109
+ hasDefault: false;
110
+ isPrimaryKey: false;
111
+ isAutoincrement: false;
112
+ hasRuntimeDefault: false;
113
+ enumValues: [string, ...string[]];
114
+ baseColumn: never;
115
+ identity: undefined;
116
+ generated: undefined;
117
+ }, {}>;
118
+ chatId: import("drizzle-orm/sqlite-core").SQLiteColumn<{
119
+ name: string;
120
+ tableName: "decision_requests";
121
+ dataType: "string";
122
+ data: string;
123
+ driverParam: string;
124
+ notNull: true;
125
+ hasDefault: false;
126
+ isPrimaryKey: false;
127
+ isAutoincrement: false;
128
+ hasRuntimeDefault: false;
129
+ enumValues: [string, ...string[]];
130
+ baseColumn: never;
131
+ identity: undefined;
132
+ generated: undefined;
133
+ }, {}>;
134
+ messageId: import("drizzle-orm/sqlite-core").SQLiteColumn<{
135
+ name: string;
136
+ tableName: "decision_requests";
137
+ dataType: "string";
138
+ data: string;
139
+ driverParam: string;
140
+ notNull: true;
141
+ hasDefault: false;
142
+ isPrimaryKey: false;
143
+ isAutoincrement: false;
144
+ hasRuntimeDefault: false;
145
+ enumValues: [string, ...string[]];
146
+ baseColumn: never;
147
+ identity: undefined;
148
+ generated: undefined;
149
+ }, {}>;
150
+ ownerUserId: import("drizzle-orm/sqlite-core").SQLiteColumn<{
151
+ name: string;
152
+ tableName: "decision_requests";
153
+ dataType: "string";
154
+ data: string;
155
+ driverParam: string;
156
+ notNull: true;
157
+ hasDefault: false;
158
+ isPrimaryKey: false;
159
+ isAutoincrement: false;
160
+ hasRuntimeDefault: false;
161
+ enumValues: [string, ...string[]];
162
+ baseColumn: never;
163
+ identity: undefined;
164
+ generated: undefined;
165
+ }, {}>;
166
+ createdAt: import("drizzle-orm/sqlite-core").SQLiteColumn<{
167
+ name: string;
168
+ tableName: "decision_requests";
169
+ dataType: "number int53";
170
+ data: number;
171
+ driverParam: number;
172
+ notNull: true;
173
+ hasDefault: false;
174
+ isPrimaryKey: false;
175
+ isAutoincrement: false;
176
+ hasRuntimeDefault: false;
177
+ enumValues: undefined;
178
+ baseColumn: never;
179
+ identity: undefined;
180
+ generated: undefined;
181
+ }, {}>;
182
+ expiresAt: import("drizzle-orm/sqlite-core").SQLiteColumn<{
183
+ name: string;
184
+ tableName: "decision_requests";
185
+ dataType: "number int53";
186
+ data: number;
187
+ driverParam: number;
188
+ notNull: true;
189
+ hasDefault: false;
190
+ isPrimaryKey: false;
191
+ isAutoincrement: false;
192
+ hasRuntimeDefault: false;
193
+ enumValues: undefined;
194
+ baseColumn: never;
195
+ identity: undefined;
196
+ generated: undefined;
197
+ }, {}>;
198
+ usedAt: import("drizzle-orm/sqlite-core").SQLiteColumn<{
199
+ name: string;
200
+ tableName: "decision_requests";
201
+ dataType: "number int53";
202
+ data: number;
203
+ driverParam: number;
204
+ notNull: false;
205
+ hasDefault: false;
206
+ isPrimaryKey: false;
207
+ isAutoincrement: false;
208
+ hasRuntimeDefault: false;
209
+ enumValues: undefined;
210
+ baseColumn: never;
211
+ identity: undefined;
212
+ generated: undefined;
213
+ }, {}>;
214
+ cancelledAt: import("drizzle-orm/sqlite-core").SQLiteColumn<{
215
+ name: string;
216
+ tableName: "decision_requests";
217
+ dataType: "number int53";
218
+ data: number;
219
+ driverParam: number;
220
+ notNull: false;
221
+ hasDefault: false;
222
+ isPrimaryKey: false;
223
+ isAutoincrement: false;
224
+ hasRuntimeDefault: false;
225
+ enumValues: undefined;
226
+ baseColumn: never;
227
+ identity: undefined;
228
+ generated: undefined;
229
+ }, {}>;
230
+ };
231
+ dialect: 'sqlite';
232
+ isAlias: false;
233
+ }>;
@@ -0,0 +1,20 @@
1
+ import { index, integer, sqliteTable, text } from "../drizzle/core.js";
2
+ /** One button of a message that asks the owner to decide a batch; only the token's digest is kept. */
3
+ export const decisionRequests = sqliteTable("decision_requests", {
4
+ id: integer("id").primaryKey(),
5
+ tokenDigest: text("token_digest").notNull().unique(),
6
+ proposalId: text("proposal_id").notNull(),
7
+ action: text("action").notNull(),
8
+ batchDigest: text("batch_digest").notNull(),
9
+ channel: text("channel").notNull(),
10
+ botProfile: text("bot_profile").notNull(),
11
+ chatId: text("chat_id").notNull(),
12
+ messageId: text("message_id").notNull(),
13
+ ownerUserId: text("owner_user_id").notNull(),
14
+ createdAt: integer("created_at").notNull(),
15
+ expiresAt: integer("expires_at").notNull(),
16
+ usedAt: integer("used_at"),
17
+ cancelledAt: integer("cancelled_at"),
18
+ }, (table) => [
19
+ index("decision_requests_by_channel_bot_profile_chat_id_message_id").on(table.channel, table.botProfile, table.chatId, table.messageId),
20
+ ]);
@@ -16759,6 +16759,7 @@ export declare const crmFields: import("drizzle-orm/sqlite-core").SQLiteTableWit
16759
16759
  dialect: 'sqlite';
16760
16760
  isAlias: false;
16761
16761
  }>;
16762
+ export { decisionRequests } from "./schema/decision-requests.js";
16762
16763
  /** What a source said about one of its records, as it said it: the layer under the entity an import makes. */
16763
16764
  export declare const records: import("drizzle-orm/sqlite-core").SQLiteTableWithColumns<{
16764
16765
  name: "records";
@@ -1679,6 +1679,7 @@ export const crmFields = sqliteTable("crm_fields", {
1679
1679
  updatedAt: integer("updated_at").notNull(),
1680
1680
  deletedAt: integer("deleted_at"),
1681
1681
  }, (table) => [unique().on(table.accountId, table.kind, table.code)]);
1682
+ export { decisionRequests } from "./schema/decision-requests.js";
1682
1683
  /** What a source said about one of its records, as it said it: the layer under the entity an import makes. */
1683
1684
  export const records = sqliteTable("records", {
1684
1685
  id: integer("id").primaryKey(),
@@ -24,6 +24,7 @@ import { type BotUpdateStore } from "./sqlite/bot-updates.js";
24
24
  import { type CatalogStore } from "./sqlite/catalog.js";
25
25
  import { type CrmCopies } from "./sqlite/crm.js";
26
26
  import { type DealsStore } from "./sqlite/deals.js";
27
+ import { type DecisionRequestStore } from "./sqlite/decision-requests.js";
27
28
  import { type MailStore } from "./sqlite/emails.js";
28
29
  import { type EventSearch } from "./sqlite/event-search.js";
29
30
  import { type FactsStore } from "./sqlite/facts.js";
@@ -111,6 +112,8 @@ export interface MessageStore {
111
112
  readonly deals: DealsStore;
112
113
  /** A CRM account's pipelines, deals, leads, contacts and companies, written as the CRM has them. */
113
114
  readonly crm: CrmCopies;
115
+ /** The one-time keys behind the buttons of a message that asks the owner to decide a batch. */
116
+ readonly decisionRequests: DecisionRequestStore;
114
117
  /** What each import said, by the source's identity; `ingest` (services) is the way in. */
115
118
  readonly records: RecordStore;
116
119
  /** What agents concluded: summaries, digests, facts, preferences, each with evidence and a scope. */