@wirecat/cli-core 0.686.0 → 0.687.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.
- package/CHANGELOG.md +58 -0
- package/dist/cli/account-remove.js +21 -3
- package/dist/cli/documents/testing/source-contract.js +18 -9
- package/dist/cli/messenger/store-maintenance-command.js +3 -2
- package/dist/crm/files.d.ts +16 -0
- package/dist/crm/files.js +56 -0
- package/dist/crm/foreign-contacts.d.ts +16 -4
- package/dist/crm/foreign-contacts.js +8 -4
- package/dist/crm/index.d.ts +2 -1
- package/dist/crm/index.js +2 -0
- package/dist/crm/source.d.ts +37 -0
- package/dist/crm/source.js +2 -1
- package/dist/crm/testing/index.d.ts +1 -1
- package/dist/crm/testing/index.js +1 -1
- package/dist/crm/testing/source.d.ts +31 -1
- package/dist/crm/testing/source.js +53 -1
- package/dist/crm/values.d.ts +2 -1
- package/dist/crm/values.js +4 -2
- package/dist/meetings/cli/index.d.ts +1 -1
- package/dist/meetings/cli/index.js +10 -6
- package/dist/meetings/mcp/index.d.ts +15 -15
- package/dist/meetings/read-through.d.ts +2 -0
- package/dist/meetings/read-through.js +7 -2
- package/dist/meetings/source.d.ts +2 -2
- package/dist/oauth/storage.js +21 -4
- package/dist/search/lucene/resolved.d.ts +2 -0
- package/dist/services/documents/plan.js +26 -5
- package/dist/services/documents/sync.js +4 -1
- package/dist/services/embeddings-search.js +33 -11
- package/dist/store/accounts.d.ts +2 -1
- package/dist/store/exports.d.ts +1 -0
- package/dist/store/exports.js +1 -0
- package/dist/store/recover.js +2 -0
- package/dist/store/sqlite/account-purge.js +1 -0
- package/dist/store/sqlite/crm-files.d.ts +67 -0
- package/dist/store/sqlite/crm-files.js +172 -0
- package/dist/store/sqlite/lucene.js +11 -5
- package/dist/store/sqlite/manifest.js +2 -0
- package/dist/store/sqlite/migrations.generated.js +17 -0
- package/dist/store/sqlite/schema.d.ts +329 -0
- package/dist/store/sqlite/schema.js +28 -0
- package/dist/store/store.d.ts +3 -0
- package/dist/store/store.js +5 -0
- package/package.json +2 -2
|
@@ -0,0 +1,172 @@
|
|
|
1
|
+
import { sep } from "node:path";
|
|
2
|
+
import { fold, normalize } from "../normalize.js";
|
|
3
|
+
import { accountPk, findAccountPk } from "./accounts.js";
|
|
4
|
+
import { pageOfRows } from "./rows-page.js";
|
|
5
|
+
import { write } from "./transaction.js";
|
|
6
|
+
const MOST = 500;
|
|
7
|
+
const CURRENTLY = (table) => `EXISTS (SELECT 1 FROM ${table} r WHERE r.account_id = f.account_id AND r.external_id = f.owner_id ` +
|
|
8
|
+
"AND r.deleted_at IS NULL AND json_extract(r.metadata, '$.assignee') = ?)";
|
|
9
|
+
const EXCERPT = 240;
|
|
10
|
+
const COLUMNS = "f.external_id, f.owner_kind, f.owner_id, f.owner_assignee, f.source, f.name, f.mime, f.size, " +
|
|
11
|
+
"f.external_created_at, f.local_path, f.content_sha256, f.extraction, f.extraction_error, f.downloaded_by, " +
|
|
12
|
+
"f.downloaded_at";
|
|
13
|
+
const text = (value) => (value === null || value === undefined ? null : String(value));
|
|
14
|
+
const number = (value) => (value === null || value === undefined ? null : Number(value));
|
|
15
|
+
const rowOf = (row) => ({
|
|
16
|
+
externalId: String(row.external_id),
|
|
17
|
+
ownerKind: String(row.owner_kind),
|
|
18
|
+
ownerId: String(row.owner_id),
|
|
19
|
+
ownerAssignee: text(row.owner_assignee),
|
|
20
|
+
source: String(row.source),
|
|
21
|
+
name: String(row.name),
|
|
22
|
+
mime: text(row.mime),
|
|
23
|
+
size: number(row.size),
|
|
24
|
+
externalCreatedAt: number(row.external_created_at),
|
|
25
|
+
localPath: text(row.local_path),
|
|
26
|
+
contentSha256: text(row.content_sha256),
|
|
27
|
+
extraction: text(row.extraction),
|
|
28
|
+
extractionError: text(row.extraction_error),
|
|
29
|
+
downloadedBy: text(row.downloaded_by),
|
|
30
|
+
downloadedAt: Number(row.downloaded_at),
|
|
31
|
+
});
|
|
32
|
+
/** One FTS5 phrase per word, quoted so no word is read as syntax; a word may start a longer one unless `exact`. */
|
|
33
|
+
const matchOf = (words, anyWord, exact) => {
|
|
34
|
+
const phrases = words
|
|
35
|
+
.map((word) => normalize(word).trim())
|
|
36
|
+
.filter(Boolean)
|
|
37
|
+
.map((word) => {
|
|
38
|
+
const quoted = `"${word.replaceAll('"', '""')}"`;
|
|
39
|
+
return exact || /\s/u.test(word) || word.length < 3 ? quoted : `${quoted}*`;
|
|
40
|
+
});
|
|
41
|
+
return phrases.length ? [...new Set(phrases)].join(anyWord ? " OR " : " AND ") : undefined;
|
|
42
|
+
};
|
|
43
|
+
const excerptOf = (body, words) => {
|
|
44
|
+
const folded = fold(body);
|
|
45
|
+
const at = words
|
|
46
|
+
.map((word) => folded.indexOf(fold(word).trim()))
|
|
47
|
+
.filter((index) => index >= 0)
|
|
48
|
+
.sort((a, b) => a - b)[0];
|
|
49
|
+
const start = Math.max(0, (at ?? 0) - EXCERPT / 4);
|
|
50
|
+
return body
|
|
51
|
+
.slice(start, start + EXCERPT)
|
|
52
|
+
.replace(/\s+/gu, " ")
|
|
53
|
+
.trim();
|
|
54
|
+
};
|
|
55
|
+
/** `store rebuild`: the normalized copies follow the current normalizer, then the word index is filled again. */
|
|
56
|
+
export const resetCrmFileWords = (database) => {
|
|
57
|
+
if (!database.prepare("SELECT 1 FROM sqlite_master WHERE name = 'crm_file_words'").get())
|
|
58
|
+
return 0;
|
|
59
|
+
return write(database, () => {
|
|
60
|
+
const update = database.prepare("UPDATE crm_files SET normalized_text = ? WHERE id = ?");
|
|
61
|
+
for (const row of database
|
|
62
|
+
.prepare("SELECT id, text, normalized_text FROM crm_files WHERE text IS NOT NULL")
|
|
63
|
+
.all()) {
|
|
64
|
+
const normalized = normalize(String(row.text));
|
|
65
|
+
if (normalized !== row.normalized_text)
|
|
66
|
+
update.run(normalized, Number(row.id));
|
|
67
|
+
}
|
|
68
|
+
database.exec("INSERT INTO crm_file_words (crm_file_words) VALUES ('delete-all')");
|
|
69
|
+
const { changes } = database
|
|
70
|
+
.prepare("INSERT INTO crm_file_words (rowid, normalized_text) SELECT id, normalized_text FROM crm_files " +
|
|
71
|
+
"WHERE normalized_text <> ''")
|
|
72
|
+
.run();
|
|
73
|
+
return Number(changes);
|
|
74
|
+
});
|
|
75
|
+
};
|
|
76
|
+
export const crmFilesOver = (context) => {
|
|
77
|
+
const { database } = context;
|
|
78
|
+
const under = "substr(f.local_path, 1, length(?)) = ?";
|
|
79
|
+
// `…/portal` must not take in `…/portal2/…`: the folder is matched with its separator.
|
|
80
|
+
const inside = (folder) => (folder.endsWith(sep) ? folder : `${folder}${sep}`);
|
|
81
|
+
const save = (key, file) => write(database, () => {
|
|
82
|
+
const accountId = accountPk(context, key);
|
|
83
|
+
database
|
|
84
|
+
.prepare("INSERT INTO crm_files (account_id, external_id, owner_kind, owner_id, owner_assignee, source, name, " +
|
|
85
|
+
"name_folded, mime, size, external_created_at, local_path, content_sha256, text, normalized_text, " +
|
|
86
|
+
"extraction, extraction_error, downloaded_by, downloaded_at) " +
|
|
87
|
+
"VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?) " +
|
|
88
|
+
"ON CONFLICT (account_id, external_id) DO UPDATE SET owner_assignee = excluded.owner_assignee, " +
|
|
89
|
+
"source = excluded.source, name = excluded.name, name_folded = excluded.name_folded, " +
|
|
90
|
+
"mime = excluded.mime, size = excluded.size, external_created_at = excluded.external_created_at, " +
|
|
91
|
+
"local_path = excluded.local_path, content_sha256 = excluded.content_sha256, text = excluded.text, " +
|
|
92
|
+
"normalized_text = excluded.normalized_text, extraction = excluded.extraction, " +
|
|
93
|
+
"extraction_error = excluded.extraction_error, downloaded_by = excluded.downloaded_by, " +
|
|
94
|
+
"downloaded_at = excluded.downloaded_at")
|
|
95
|
+
.run(accountId, file.externalId, file.ownerKind, file.ownerId, file.ownerAssignee, file.source, file.name, fold(file.name), file.mime, file.size, file.externalCreatedAt, file.localPath, file.contentSha256, file.text, file.text === null ? null : normalize(file.text), file.extraction, file.extractionError, file.downloadedBy, file.downloadedAt);
|
|
96
|
+
});
|
|
97
|
+
const rowsOf = (key, columns, where, ...params) => {
|
|
98
|
+
const accountId = findAccountPk(context, key);
|
|
99
|
+
if (accountId === undefined)
|
|
100
|
+
return [];
|
|
101
|
+
return database
|
|
102
|
+
.prepare(`SELECT ${columns} FROM crm_files f WHERE f.account_id = ? AND ${where}`)
|
|
103
|
+
.all(accountId, ...params);
|
|
104
|
+
};
|
|
105
|
+
const find = ({ words, anyWord = false, exact = false, accounts, viewers = [], limit }) => {
|
|
106
|
+
const match = matchOf(words, anyWord, exact);
|
|
107
|
+
if (!match)
|
|
108
|
+
return { items: [], hasMore: false };
|
|
109
|
+
const most = Math.min(Math.max(limit ?? 100, 1), MOST);
|
|
110
|
+
const scoped = accounts?.map((one) => findAccountPk(context, one)).filter((one) => one !== undefined) ?? [];
|
|
111
|
+
if (accounts !== undefined && !scoped.length)
|
|
112
|
+
return { items: [], hasMore: false };
|
|
113
|
+
// A viewer limits only its own account; another account's rows pass it, as `seenBy` lets them.
|
|
114
|
+
const limits = viewers.flatMap((viewer) => {
|
|
115
|
+
const id = findAccountPk(context, viewer.account);
|
|
116
|
+
return id === undefined ? [] : [{ id, assignee: viewer.assignee }];
|
|
117
|
+
});
|
|
118
|
+
const params = [match];
|
|
119
|
+
let sql = `SELECT ${COLUMNS}, f.text, a.provider, a.external_id AS account FROM crm_files f ` +
|
|
120
|
+
"JOIN accounts a ON a.id = f.account_id " +
|
|
121
|
+
"JOIN (SELECT rowid, rank FROM crm_file_words WHERE crm_file_words MATCH ?) w ON w.rowid = f.id WHERE 1";
|
|
122
|
+
if (accounts !== undefined) {
|
|
123
|
+
sql += ` AND f.account_id IN (${scoped.map(() => "?").join(", ")})`;
|
|
124
|
+
for (const id of scoped)
|
|
125
|
+
params.push(id);
|
|
126
|
+
}
|
|
127
|
+
for (const one of limits) {
|
|
128
|
+
if (one.assignee === null) {
|
|
129
|
+
sql += " AND f.account_id <> ?";
|
|
130
|
+
params.push(one.id);
|
|
131
|
+
continue;
|
|
132
|
+
}
|
|
133
|
+
// A deal's or lead's file follows the copy's current assignee, so a reassigned deal takes its files along.
|
|
134
|
+
sql +=
|
|
135
|
+
" AND (f.account_id <> ? OR CASE f.owner_kind " +
|
|
136
|
+
`WHEN 'deal' THEN ${CURRENTLY("deals")} WHEN 'lead' THEN ${CURRENTLY("leads")} ` +
|
|
137
|
+
"ELSE f.owner_assignee = ? END)";
|
|
138
|
+
params.push(one.id, one.assignee, one.assignee, one.assignee);
|
|
139
|
+
}
|
|
140
|
+
sql += " ORDER BY w.rank, f.downloaded_at DESC, f.id DESC LIMIT ?";
|
|
141
|
+
params.push(most + 1);
|
|
142
|
+
const hits = database
|
|
143
|
+
.prepare(sql)
|
|
144
|
+
.all(...params)
|
|
145
|
+
.map((row) => ({
|
|
146
|
+
account: { provider: String(row.provider), account: String(row.account) },
|
|
147
|
+
file: rowOf(row),
|
|
148
|
+
excerpt: excerptOf(String(row.text ?? ""), words),
|
|
149
|
+
}));
|
|
150
|
+
return pageOfRows(hits, most);
|
|
151
|
+
};
|
|
152
|
+
return {
|
|
153
|
+
save: async (key, file) => save(key, file),
|
|
154
|
+
get: async (key, externalId) => {
|
|
155
|
+
const [row] = rowsOf(key, `${COLUMNS}, f.text`, "f.external_id = ?", externalId);
|
|
156
|
+
return row ? { ...rowOf(row), text: text(row.text) } : undefined;
|
|
157
|
+
},
|
|
158
|
+
ofOwner: async (key, kind, id) => rowsOf(key, COLUMNS, "f.owner_kind = ? AND f.owner_id = ? ORDER BY f.downloaded_at DESC, f.id DESC", kind, id).map(rowOf),
|
|
159
|
+
storedBytes: async (key, folder) => rowsOf(key, "coalesce(sum(f.size), 0) AS bytes", `f.local_path IS NOT NULL AND ${under}`, inside(folder), inside(folder)).reduce((sum, row) => sum + Number(row.bytes), 0),
|
|
160
|
+
droppable: async (key, folder) => rowsOf(key, COLUMNS, `f.local_path IS NOT NULL AND ${under} AND coalesce(f.text, '') <> '' ORDER BY f.downloaded_at, f.id`, inside(folder), inside(folder)).map(rowOf),
|
|
161
|
+
savedPaths: async (key) => rowsOf(key, "f.local_path", "f.local_path IS NOT NULL ORDER BY f.id").map((row) => String(row.local_path)),
|
|
162
|
+
forgetFile: async (key, externalId) => {
|
|
163
|
+
const accountId = findAccountPk(context, key);
|
|
164
|
+
if (accountId === undefined)
|
|
165
|
+
return;
|
|
166
|
+
write(database, () => database
|
|
167
|
+
.prepare("UPDATE crm_files SET local_path = NULL WHERE account_id = ? AND external_id = ?")
|
|
168
|
+
.run(accountId, externalId));
|
|
169
|
+
},
|
|
170
|
+
find: async (search) => find(search),
|
|
171
|
+
};
|
|
172
|
+
};
|
|
@@ -347,7 +347,7 @@ const compileQuery = (context, execution, boundedAttachments = false) => {
|
|
|
347
347
|
? ""
|
|
348
348
|
: rankMatch
|
|
349
349
|
? "f.rank,"
|
|
350
|
-
: `${exactTier ? "
|
|
350
|
+
: `${exactTier ? "m.id IN (SELECT id FROM x) DESC," : ""}${ranking ? `f.rank IS NULL, ${placeTier}f.rank,` : placeTier}`;
|
|
351
351
|
const order = `${tiers}m.sent_at DESC, ac.provider, ac.external_id, c.external_id, m.external_id DESC`;
|
|
352
352
|
const leaves = [...fragments.values()];
|
|
353
353
|
const exact = leaves.filter(({ test }) => test === undefined);
|
|
@@ -482,7 +482,8 @@ const runCompiled = async (context, execution, by) => {
|
|
|
482
482
|
return grouped(by, where.sql, [...ranked.params, ...where.params], from, withRanking);
|
|
483
483
|
// Exact forms come first, so a page they fill needs neither the stems nor their bm25: for a word in a few
|
|
484
484
|
// percent of messages that was most of the cost (PERF-9). The exact tier is ranked as exact search ranks it.
|
|
485
|
-
|
|
485
|
+
const { newest, perChat } = execution;
|
|
486
|
+
if (stemmed && exactTier && driver && !newest && !perChat && leaves.every(({ test }) => !test)) {
|
|
486
487
|
const exactRows = database
|
|
487
488
|
.prepare(`SELECT m.id AS id, w.rank AS relevance ${baseFrom.replace(rowsFrom, `FROM ${corpus.words} w CROSS JOIN ${corpus.rows} m`)} WHERE ${corpus.words} MATCH ? AND w.rank MATCH 'bm25(1.0, 0.0)' AND m.id=w.rowid AND ${filtered.sql} ORDER BY w.rank, m.sent_at DESC, ac.provider, ac.external_id, c.external_id, m.external_id DESC LIMIT ?`)
|
|
488
489
|
.all(`normalized_text : (${exactTier})`, ...filtered.params, execution.limit + 1);
|
|
@@ -511,7 +512,9 @@ const runCompiled = async (context, execution, by) => {
|
|
|
511
512
|
}
|
|
512
513
|
if (leaves.every(({ test }) => !test)) {
|
|
513
514
|
const rows = database
|
|
514
|
-
.prepare(
|
|
515
|
+
.prepare(perChat === undefined
|
|
516
|
+
? `${withRanking}SELECT m.id AS id, ${relevance} AS relevance${exactColumn} ${rankedFrom} WHERE ${where.sql} ORDER BY ${order} LIMIT ?`
|
|
517
|
+
: `${withRanking}SELECT id, relevance${exactColumn ? ", exact" : ""} FROM (SELECT m.id AS id, ${relevance} AS relevance${exactColumn}, ROW_NUMBER() OVER (PARTITION BY m.chat_id ORDER BY ${order}) AS in_chat, ROW_NUMBER() OVER (ORDER BY ${order}) AS place ${rankedFrom} WHERE ${where.sql}) WHERE in_chat <= ${perChat} ORDER BY place LIMIT ?`)
|
|
515
518
|
.all(...ranked.params, ...where.params, execution.limit + 1);
|
|
516
519
|
await new Promise((resolve) => setImmediate(resolve));
|
|
517
520
|
check();
|
|
@@ -525,7 +528,7 @@ const runCompiled = async (context, execution, by) => {
|
|
|
525
528
|
};
|
|
526
529
|
}
|
|
527
530
|
const candidates = database
|
|
528
|
-
.prepare(`${withRanking}SELECT m.id AS id, ${relevance} AS relevance${exactColumn}, length(cast(m.text AS BLOB)) AS bytes ${rankedFrom} WHERE ${where.sql} ORDER BY ${order} LIMIT ?`)
|
|
531
|
+
.prepare(`${withRanking}SELECT m.id AS id, m.chat_id AS chat, ${relevance} AS relevance${exactColumn}, length(cast(m.text AS BLOB)) AS bytes ${rankedFrom} WHERE ${where.sql} ORDER BY ${order} LIMIT ?`)
|
|
529
532
|
.all(...ranked.params, ...where.params, QUERY_LIMITS.candidates + 1);
|
|
530
533
|
await new Promise((resolve) => setImmediate(resolve));
|
|
531
534
|
check();
|
|
@@ -539,6 +542,8 @@ const runCompiled = async (context, execution, by) => {
|
|
|
539
542
|
const found = [];
|
|
540
543
|
const scores = new Map(candidates.map((row) => [Number(row.id), row.relevance == null ? null : -Number(row.relevance)]));
|
|
541
544
|
const exactness = new Map(candidates.map((row) => [Number(row.id), Number(row.exact) === 1]));
|
|
545
|
+
const [chatOf, inChat] = [new Map(candidates.map((row) => [Number(row.id), Number(row.chat)])), new Map()];
|
|
546
|
+
const roomInChat = (chat) => (inChat.set(chat, (inChat.get(chat) ?? 0) + 1).get(chat) ?? 0) <= (by || !perChat ? Infinity : perChat);
|
|
542
547
|
for (let offset = 0; offset < candidates.length; offset += 500) {
|
|
543
548
|
if (offset > 0)
|
|
544
549
|
await new Promise((resolve) => setImmediate(resolve));
|
|
@@ -556,7 +561,8 @@ const runCompiled = async (context, execution, by) => {
|
|
|
556
561
|
check();
|
|
557
562
|
const row = byPk.get(id);
|
|
558
563
|
const attachments = JSON.parse(String(row.attachment_kinds));
|
|
559
|
-
if (evaluate(execution.root, row, String(row.body), Array.isArray(attachments) ? attachments.map(String) : [])
|
|
564
|
+
if (evaluate(execution.root, row, String(row.body), Array.isArray(attachments) ? attachments.map(String) : []) &&
|
|
565
|
+
roomInChat(chatOf.get(id)))
|
|
560
566
|
found.push(id);
|
|
561
567
|
if (!by && found.length > execution.limit)
|
|
562
568
|
break;
|
|
@@ -132,6 +132,8 @@ export const MANIFEST = [
|
|
|
132
132
|
{ name: "20261110182602_version-65-found-task-titles", version: 65, minCompatible: 56 },
|
|
133
133
|
{ name: "20261110233711_version-66-identity-name-trigger", version: 66, minCompatible: 56 },
|
|
134
134
|
{ name: "20261113154357_version-67-fact-removals-call-fields", version: 67, minCompatible: 56 },
|
|
135
|
+
{ name: "20261116204138_version-68-crm-files", version: 68, minCompatible: 56 },
|
|
136
|
+
{ name: "20261116204204_version-68-crm-file-words", version: 68, minCompatible: 56 },
|
|
135
137
|
];
|
|
136
138
|
export const generatedMigrations = (manifest = MANIFEST, generated = GENERATED) => {
|
|
137
139
|
const migrations = [];
|
|
@@ -1344,5 +1344,22 @@ export const GENERATED = [
|
|
|
1344
1344
|
"ALTER TABLE `meetings` ADD `client_phone` text;",
|
|
1345
1345
|
"CREATE INDEX `fact_removals_by_removed_at` ON `fact_removals` (`removed_at`);"
|
|
1346
1346
|
]
|
|
1347
|
+
},
|
|
1348
|
+
{
|
|
1349
|
+
"name": "20261116204138_version-68-crm-files",
|
|
1350
|
+
"statements": [
|
|
1351
|
+
"CREATE TABLE `crm_files` (\n\t`id` integer PRIMARY KEY,\n\t`account_id` integer NOT NULL,\n\t`external_id` text NOT NULL,\n\t`owner_kind` text NOT NULL,\n\t`owner_id` text NOT NULL,\n\t`owner_assignee` text,\n\t`source` text NOT NULL,\n\t`name` text NOT NULL,\n\t`name_folded` text NOT NULL,\n\t`mime` text,\n\t`size` integer,\n\t`external_created_at` integer,\n\t`local_path` text,\n\t`content_sha256` text,\n\t`text` text,\n\t`normalized_text` text,\n\t`extraction` text,\n\t`extraction_error` text,\n\t`downloaded_by` text,\n\t`downloaded_at` integer NOT NULL,\n\tCONSTRAINT `fk_crm_files_account_id_accounts_id_fk` FOREIGN KEY (`account_id`) REFERENCES `accounts`(`id`),\n\tCONSTRAINT `crm_files_account_id_external_id_unique` UNIQUE(`account_id`,`external_id`)\n);",
|
|
1352
|
+
"CREATE INDEX `crm_files_by_account_id_owner_kind_owner_id` ON `crm_files` (`account_id`,`owner_kind`,`owner_id`);"
|
|
1353
|
+
]
|
|
1354
|
+
},
|
|
1355
|
+
{
|
|
1356
|
+
"name": "20261116204204_version-68-crm-file-words",
|
|
1357
|
+
"statements": [
|
|
1358
|
+
"-- Words of a downloaded CRM file's text, rowid = crm_files.id. Apart from attachment_words, so no generic\n-- reader of attachments finds a colleague's file: only CRM code reads it, under the copy's viewer rule.\nCREATE VIRTUAL TABLE crm_file_words USING fts5(\n normalized_text,\n content = '', contentless_delete = 1,\n tokenize = 'unicode61 remove_diacritics 2', prefix = '3');",
|
|
1359
|
+
"CREATE VIRTUAL TABLE crm_file_words_vocab USING fts5vocab(crm_file_words, 'col');",
|
|
1360
|
+
"CREATE TRIGGER crm_file_words_ai AFTER INSERT ON crm_files WHEN new.normalized_text <> '' BEGIN\n INSERT INTO crm_file_words (rowid, normalized_text) VALUES (new.id, new.normalized_text);\nEND;",
|
|
1361
|
+
"CREATE TRIGGER crm_file_words_au AFTER UPDATE OF normalized_text ON crm_files\n WHEN old.normalized_text IS NOT new.normalized_text BEGIN\n DELETE FROM crm_file_words WHERE rowid = old.id;\n INSERT INTO crm_file_words (rowid, normalized_text)\n SELECT new.id, new.normalized_text WHERE new.normalized_text <> '';\nEND;",
|
|
1362
|
+
"CREATE TRIGGER crm_file_words_ad AFTER DELETE ON crm_files BEGIN\n DELETE FROM crm_file_words WHERE rowid = old.id;\nEND;"
|
|
1363
|
+
]
|
|
1347
1364
|
}
|
|
1348
1365
|
];
|
|
@@ -17169,6 +17169,335 @@ export declare const crmFields: import("drizzle-orm/sqlite-core").SQLiteTableWit
|
|
|
17169
17169
|
dialect: 'sqlite';
|
|
17170
17170
|
isAlias: false;
|
|
17171
17171
|
}>;
|
|
17172
|
+
/** A downloaded file of a CRM record with its text; never a download link. Only CRM code reads it, under the viewer. */
|
|
17173
|
+
export declare const crmFiles: import("drizzle-orm/sqlite-core").SQLiteTableWithColumns<{
|
|
17174
|
+
name: "crm_files";
|
|
17175
|
+
schema: undefined;
|
|
17176
|
+
columns: {
|
|
17177
|
+
id: import("drizzle-orm/sqlite-core").SQLiteColumn<{
|
|
17178
|
+
name: string;
|
|
17179
|
+
tableName: "crm_files";
|
|
17180
|
+
dataType: "number int53";
|
|
17181
|
+
data: number;
|
|
17182
|
+
driverParam: number;
|
|
17183
|
+
notNull: true;
|
|
17184
|
+
hasDefault: true;
|
|
17185
|
+
isPrimaryKey: true;
|
|
17186
|
+
isAutoincrement: false;
|
|
17187
|
+
hasRuntimeDefault: false;
|
|
17188
|
+
enumValues: undefined;
|
|
17189
|
+
baseColumn: never;
|
|
17190
|
+
identity: undefined;
|
|
17191
|
+
generated: undefined;
|
|
17192
|
+
}, {}>;
|
|
17193
|
+
accountId: import("drizzle-orm/sqlite-core").SQLiteColumn<{
|
|
17194
|
+
name: string;
|
|
17195
|
+
tableName: "crm_files";
|
|
17196
|
+
dataType: "number int53";
|
|
17197
|
+
data: number;
|
|
17198
|
+
driverParam: number;
|
|
17199
|
+
notNull: true;
|
|
17200
|
+
hasDefault: false;
|
|
17201
|
+
isPrimaryKey: false;
|
|
17202
|
+
isAutoincrement: false;
|
|
17203
|
+
hasRuntimeDefault: false;
|
|
17204
|
+
enumValues: undefined;
|
|
17205
|
+
baseColumn: never;
|
|
17206
|
+
identity: undefined;
|
|
17207
|
+
generated: undefined;
|
|
17208
|
+
}, {}>;
|
|
17209
|
+
externalId: import("drizzle-orm/sqlite-core").SQLiteColumn<{
|
|
17210
|
+
name: string;
|
|
17211
|
+
tableName: "crm_files";
|
|
17212
|
+
dataType: "string";
|
|
17213
|
+
data: string;
|
|
17214
|
+
driverParam: string;
|
|
17215
|
+
notNull: true;
|
|
17216
|
+
hasDefault: false;
|
|
17217
|
+
isPrimaryKey: false;
|
|
17218
|
+
isAutoincrement: false;
|
|
17219
|
+
hasRuntimeDefault: false;
|
|
17220
|
+
enumValues: [string, ...string[]];
|
|
17221
|
+
baseColumn: never;
|
|
17222
|
+
identity: undefined;
|
|
17223
|
+
generated: undefined;
|
|
17224
|
+
}, {}>;
|
|
17225
|
+
ownerKind: import("drizzle-orm/sqlite-core").SQLiteColumn<{
|
|
17226
|
+
name: string;
|
|
17227
|
+
tableName: "crm_files";
|
|
17228
|
+
dataType: "string";
|
|
17229
|
+
data: string;
|
|
17230
|
+
driverParam: string;
|
|
17231
|
+
notNull: true;
|
|
17232
|
+
hasDefault: false;
|
|
17233
|
+
isPrimaryKey: false;
|
|
17234
|
+
isAutoincrement: false;
|
|
17235
|
+
hasRuntimeDefault: false;
|
|
17236
|
+
enumValues: [string, ...string[]];
|
|
17237
|
+
baseColumn: never;
|
|
17238
|
+
identity: undefined;
|
|
17239
|
+
generated: undefined;
|
|
17240
|
+
}, {}>;
|
|
17241
|
+
ownerId: import("drizzle-orm/sqlite-core").SQLiteColumn<{
|
|
17242
|
+
name: string;
|
|
17243
|
+
tableName: "crm_files";
|
|
17244
|
+
dataType: "string";
|
|
17245
|
+
data: string;
|
|
17246
|
+
driverParam: string;
|
|
17247
|
+
notNull: true;
|
|
17248
|
+
hasDefault: false;
|
|
17249
|
+
isPrimaryKey: false;
|
|
17250
|
+
isAutoincrement: false;
|
|
17251
|
+
hasRuntimeDefault: false;
|
|
17252
|
+
enumValues: [string, ...string[]];
|
|
17253
|
+
baseColumn: never;
|
|
17254
|
+
identity: undefined;
|
|
17255
|
+
generated: undefined;
|
|
17256
|
+
}, {}>;
|
|
17257
|
+
ownerAssignee: import("drizzle-orm/sqlite-core").SQLiteColumn<{
|
|
17258
|
+
name: string;
|
|
17259
|
+
tableName: "crm_files";
|
|
17260
|
+
dataType: "string";
|
|
17261
|
+
data: string;
|
|
17262
|
+
driverParam: string;
|
|
17263
|
+
notNull: false;
|
|
17264
|
+
hasDefault: false;
|
|
17265
|
+
isPrimaryKey: false;
|
|
17266
|
+
isAutoincrement: false;
|
|
17267
|
+
hasRuntimeDefault: false;
|
|
17268
|
+
enumValues: [string, ...string[]];
|
|
17269
|
+
baseColumn: never;
|
|
17270
|
+
identity: undefined;
|
|
17271
|
+
generated: undefined;
|
|
17272
|
+
}, {}>;
|
|
17273
|
+
source: import("drizzle-orm/sqlite-core").SQLiteColumn<{
|
|
17274
|
+
name: string;
|
|
17275
|
+
tableName: "crm_files";
|
|
17276
|
+
dataType: "string";
|
|
17277
|
+
data: string;
|
|
17278
|
+
driverParam: string;
|
|
17279
|
+
notNull: true;
|
|
17280
|
+
hasDefault: false;
|
|
17281
|
+
isPrimaryKey: false;
|
|
17282
|
+
isAutoincrement: false;
|
|
17283
|
+
hasRuntimeDefault: false;
|
|
17284
|
+
enumValues: [string, ...string[]];
|
|
17285
|
+
baseColumn: never;
|
|
17286
|
+
identity: undefined;
|
|
17287
|
+
generated: undefined;
|
|
17288
|
+
}, {}>;
|
|
17289
|
+
name: import("drizzle-orm/sqlite-core").SQLiteColumn<{
|
|
17290
|
+
name: string;
|
|
17291
|
+
tableName: "crm_files";
|
|
17292
|
+
dataType: "string";
|
|
17293
|
+
data: string;
|
|
17294
|
+
driverParam: string;
|
|
17295
|
+
notNull: true;
|
|
17296
|
+
hasDefault: false;
|
|
17297
|
+
isPrimaryKey: false;
|
|
17298
|
+
isAutoincrement: false;
|
|
17299
|
+
hasRuntimeDefault: false;
|
|
17300
|
+
enumValues: [string, ...string[]];
|
|
17301
|
+
baseColumn: never;
|
|
17302
|
+
identity: undefined;
|
|
17303
|
+
generated: undefined;
|
|
17304
|
+
}, {}>;
|
|
17305
|
+
nameFolded: import("drizzle-orm/sqlite-core").SQLiteColumn<{
|
|
17306
|
+
name: string;
|
|
17307
|
+
tableName: "crm_files";
|
|
17308
|
+
dataType: "string";
|
|
17309
|
+
data: string;
|
|
17310
|
+
driverParam: string;
|
|
17311
|
+
notNull: true;
|
|
17312
|
+
hasDefault: false;
|
|
17313
|
+
isPrimaryKey: false;
|
|
17314
|
+
isAutoincrement: false;
|
|
17315
|
+
hasRuntimeDefault: false;
|
|
17316
|
+
enumValues: [string, ...string[]];
|
|
17317
|
+
baseColumn: never;
|
|
17318
|
+
identity: undefined;
|
|
17319
|
+
generated: undefined;
|
|
17320
|
+
}, {}>;
|
|
17321
|
+
mime: import("drizzle-orm/sqlite-core").SQLiteColumn<{
|
|
17322
|
+
name: string;
|
|
17323
|
+
tableName: "crm_files";
|
|
17324
|
+
dataType: "string";
|
|
17325
|
+
data: string;
|
|
17326
|
+
driverParam: string;
|
|
17327
|
+
notNull: false;
|
|
17328
|
+
hasDefault: false;
|
|
17329
|
+
isPrimaryKey: false;
|
|
17330
|
+
isAutoincrement: false;
|
|
17331
|
+
hasRuntimeDefault: false;
|
|
17332
|
+
enumValues: [string, ...string[]];
|
|
17333
|
+
baseColumn: never;
|
|
17334
|
+
identity: undefined;
|
|
17335
|
+
generated: undefined;
|
|
17336
|
+
}, {}>;
|
|
17337
|
+
size: import("drizzle-orm/sqlite-core").SQLiteColumn<{
|
|
17338
|
+
name: string;
|
|
17339
|
+
tableName: "crm_files";
|
|
17340
|
+
dataType: "number int53";
|
|
17341
|
+
data: number;
|
|
17342
|
+
driverParam: number;
|
|
17343
|
+
notNull: false;
|
|
17344
|
+
hasDefault: false;
|
|
17345
|
+
isPrimaryKey: false;
|
|
17346
|
+
isAutoincrement: false;
|
|
17347
|
+
hasRuntimeDefault: false;
|
|
17348
|
+
enumValues: undefined;
|
|
17349
|
+
baseColumn: never;
|
|
17350
|
+
identity: undefined;
|
|
17351
|
+
generated: undefined;
|
|
17352
|
+
}, {}>;
|
|
17353
|
+
externalCreatedAt: import("drizzle-orm/sqlite-core").SQLiteColumn<{
|
|
17354
|
+
name: string;
|
|
17355
|
+
tableName: "crm_files";
|
|
17356
|
+
dataType: "number int53";
|
|
17357
|
+
data: number;
|
|
17358
|
+
driverParam: number;
|
|
17359
|
+
notNull: false;
|
|
17360
|
+
hasDefault: false;
|
|
17361
|
+
isPrimaryKey: false;
|
|
17362
|
+
isAutoincrement: false;
|
|
17363
|
+
hasRuntimeDefault: false;
|
|
17364
|
+
enumValues: undefined;
|
|
17365
|
+
baseColumn: never;
|
|
17366
|
+
identity: undefined;
|
|
17367
|
+
generated: undefined;
|
|
17368
|
+
}, {}>;
|
|
17369
|
+
localPath: import("drizzle-orm/sqlite-core").SQLiteColumn<{
|
|
17370
|
+
name: string;
|
|
17371
|
+
tableName: "crm_files";
|
|
17372
|
+
dataType: "string";
|
|
17373
|
+
data: string;
|
|
17374
|
+
driverParam: string;
|
|
17375
|
+
notNull: false;
|
|
17376
|
+
hasDefault: false;
|
|
17377
|
+
isPrimaryKey: false;
|
|
17378
|
+
isAutoincrement: false;
|
|
17379
|
+
hasRuntimeDefault: false;
|
|
17380
|
+
enumValues: [string, ...string[]];
|
|
17381
|
+
baseColumn: never;
|
|
17382
|
+
identity: undefined;
|
|
17383
|
+
generated: undefined;
|
|
17384
|
+
}, {}>;
|
|
17385
|
+
contentSha256: import("drizzle-orm/sqlite-core").SQLiteColumn<{
|
|
17386
|
+
name: string;
|
|
17387
|
+
tableName: "crm_files";
|
|
17388
|
+
dataType: "string";
|
|
17389
|
+
data: string;
|
|
17390
|
+
driverParam: string;
|
|
17391
|
+
notNull: false;
|
|
17392
|
+
hasDefault: false;
|
|
17393
|
+
isPrimaryKey: false;
|
|
17394
|
+
isAutoincrement: false;
|
|
17395
|
+
hasRuntimeDefault: false;
|
|
17396
|
+
enumValues: [string, ...string[]];
|
|
17397
|
+
baseColumn: never;
|
|
17398
|
+
identity: undefined;
|
|
17399
|
+
generated: undefined;
|
|
17400
|
+
}, {}>;
|
|
17401
|
+
text: import("drizzle-orm/sqlite-core").SQLiteColumn<{
|
|
17402
|
+
name: string;
|
|
17403
|
+
tableName: "crm_files";
|
|
17404
|
+
dataType: "string";
|
|
17405
|
+
data: string;
|
|
17406
|
+
driverParam: string;
|
|
17407
|
+
notNull: false;
|
|
17408
|
+
hasDefault: false;
|
|
17409
|
+
isPrimaryKey: false;
|
|
17410
|
+
isAutoincrement: false;
|
|
17411
|
+
hasRuntimeDefault: false;
|
|
17412
|
+
enumValues: [string, ...string[]];
|
|
17413
|
+
baseColumn: never;
|
|
17414
|
+
identity: undefined;
|
|
17415
|
+
generated: undefined;
|
|
17416
|
+
}, {}>;
|
|
17417
|
+
normalizedText: import("drizzle-orm/sqlite-core").SQLiteColumn<{
|
|
17418
|
+
name: string;
|
|
17419
|
+
tableName: "crm_files";
|
|
17420
|
+
dataType: "string";
|
|
17421
|
+
data: string;
|
|
17422
|
+
driverParam: string;
|
|
17423
|
+
notNull: false;
|
|
17424
|
+
hasDefault: false;
|
|
17425
|
+
isPrimaryKey: false;
|
|
17426
|
+
isAutoincrement: false;
|
|
17427
|
+
hasRuntimeDefault: false;
|
|
17428
|
+
enumValues: [string, ...string[]];
|
|
17429
|
+
baseColumn: never;
|
|
17430
|
+
identity: undefined;
|
|
17431
|
+
generated: undefined;
|
|
17432
|
+
}, {}>;
|
|
17433
|
+
extraction: import("drizzle-orm/sqlite-core").SQLiteColumn<{
|
|
17434
|
+
name: string;
|
|
17435
|
+
tableName: "crm_files";
|
|
17436
|
+
dataType: "string";
|
|
17437
|
+
data: string;
|
|
17438
|
+
driverParam: string;
|
|
17439
|
+
notNull: false;
|
|
17440
|
+
hasDefault: false;
|
|
17441
|
+
isPrimaryKey: false;
|
|
17442
|
+
isAutoincrement: false;
|
|
17443
|
+
hasRuntimeDefault: false;
|
|
17444
|
+
enumValues: [string, ...string[]];
|
|
17445
|
+
baseColumn: never;
|
|
17446
|
+
identity: undefined;
|
|
17447
|
+
generated: undefined;
|
|
17448
|
+
}, {}>;
|
|
17449
|
+
extractionError: import("drizzle-orm/sqlite-core").SQLiteColumn<{
|
|
17450
|
+
name: string;
|
|
17451
|
+
tableName: "crm_files";
|
|
17452
|
+
dataType: "string";
|
|
17453
|
+
data: string;
|
|
17454
|
+
driverParam: string;
|
|
17455
|
+
notNull: false;
|
|
17456
|
+
hasDefault: false;
|
|
17457
|
+
isPrimaryKey: false;
|
|
17458
|
+
isAutoincrement: false;
|
|
17459
|
+
hasRuntimeDefault: false;
|
|
17460
|
+
enumValues: [string, ...string[]];
|
|
17461
|
+
baseColumn: never;
|
|
17462
|
+
identity: undefined;
|
|
17463
|
+
generated: undefined;
|
|
17464
|
+
}, {}>;
|
|
17465
|
+
downloadedBy: import("drizzle-orm/sqlite-core").SQLiteColumn<{
|
|
17466
|
+
name: string;
|
|
17467
|
+
tableName: "crm_files";
|
|
17468
|
+
dataType: "string";
|
|
17469
|
+
data: string;
|
|
17470
|
+
driverParam: string;
|
|
17471
|
+
notNull: false;
|
|
17472
|
+
hasDefault: false;
|
|
17473
|
+
isPrimaryKey: false;
|
|
17474
|
+
isAutoincrement: false;
|
|
17475
|
+
hasRuntimeDefault: false;
|
|
17476
|
+
enumValues: [string, ...string[]];
|
|
17477
|
+
baseColumn: never;
|
|
17478
|
+
identity: undefined;
|
|
17479
|
+
generated: undefined;
|
|
17480
|
+
}, {}>;
|
|
17481
|
+
downloadedAt: import("drizzle-orm/sqlite-core").SQLiteColumn<{
|
|
17482
|
+
name: string;
|
|
17483
|
+
tableName: "crm_files";
|
|
17484
|
+
dataType: "number int53";
|
|
17485
|
+
data: number;
|
|
17486
|
+
driverParam: number;
|
|
17487
|
+
notNull: true;
|
|
17488
|
+
hasDefault: false;
|
|
17489
|
+
isPrimaryKey: false;
|
|
17490
|
+
isAutoincrement: false;
|
|
17491
|
+
hasRuntimeDefault: false;
|
|
17492
|
+
enumValues: undefined;
|
|
17493
|
+
baseColumn: never;
|
|
17494
|
+
identity: undefined;
|
|
17495
|
+
generated: undefined;
|
|
17496
|
+
}, {}>;
|
|
17497
|
+
};
|
|
17498
|
+
dialect: 'sqlite';
|
|
17499
|
+
isAlias: false;
|
|
17500
|
+
}>;
|
|
17172
17501
|
/** What the owner or a supplier sells, a product or a service; a line copies its price and never reads it back. */
|
|
17173
17502
|
export declare const catalogItems: import("drizzle-orm/sqlite-core").SQLiteTableWithColumns<{
|
|
17174
17503
|
name: "catalog_items";
|
|
@@ -1723,6 +1723,34 @@ export const crmFields = sqliteTable("crm_fields", {
|
|
|
1723
1723
|
updatedAt: integer("updated_at").notNull(),
|
|
1724
1724
|
deletedAt: integer("deleted_at"),
|
|
1725
1725
|
}, (table) => [unique().on(table.accountId, table.kind, table.code)]);
|
|
1726
|
+
/** A downloaded file of a CRM record with its text; never a download link. Only CRM code reads it, under the viewer. */
|
|
1727
|
+
export const crmFiles = sqliteTable("crm_files", {
|
|
1728
|
+
id: integer("id").primaryKey(),
|
|
1729
|
+
accountId: integer("account_id")
|
|
1730
|
+
.notNull()
|
|
1731
|
+
.references(() => accounts.id),
|
|
1732
|
+
externalId: text("external_id").notNull(),
|
|
1733
|
+
ownerKind: text("owner_kind").notNull(),
|
|
1734
|
+
ownerId: text("owner_id").notNull(),
|
|
1735
|
+
ownerAssignee: text("owner_assignee"),
|
|
1736
|
+
source: text("source").notNull(),
|
|
1737
|
+
name: text("name").notNull(),
|
|
1738
|
+
nameFolded: text("name_folded").notNull(),
|
|
1739
|
+
mime: text("mime"),
|
|
1740
|
+
size: integer("size"),
|
|
1741
|
+
externalCreatedAt: integer("external_created_at"),
|
|
1742
|
+
localPath: text("local_path"),
|
|
1743
|
+
contentSha256: text("content_sha256"),
|
|
1744
|
+
text: text("text"),
|
|
1745
|
+
normalizedText: text("normalized_text"),
|
|
1746
|
+
extraction: text("extraction"),
|
|
1747
|
+
extractionError: text("extraction_error"),
|
|
1748
|
+
downloadedBy: text("downloaded_by"),
|
|
1749
|
+
downloadedAt: integer("downloaded_at").notNull(),
|
|
1750
|
+
}, (table) => [
|
|
1751
|
+
unique().on(table.accountId, table.externalId),
|
|
1752
|
+
index("crm_files_by_account_id_owner_kind_owner_id").on(table.accountId, table.ownerKind, table.ownerId),
|
|
1753
|
+
]);
|
|
1726
1754
|
/** What the owner or a supplier sells, a product or a service; a line copies its price and never reads it back. */
|
|
1727
1755
|
export const catalogItems = sqliteTable("catalog_items", {
|
|
1728
1756
|
id: integer("id").primaryKey(),
|
package/dist/store/store.d.ts
CHANGED
|
@@ -26,6 +26,7 @@ import { type ContractsStore } from "./sqlite/business-contracts.js";
|
|
|
26
26
|
import { type BusinessSearchStore } from "./sqlite/business-search.js";
|
|
27
27
|
import { type CatalogStore } from "./sqlite/catalog.js";
|
|
28
28
|
import { type CrmCopies } from "./sqlite/crm.js";
|
|
29
|
+
import { type CrmFileStore } from "./sqlite/crm-files.js";
|
|
29
30
|
import { type DealsStore } from "./sqlite/deals.js";
|
|
30
31
|
import { type DecisionRequestStore } from "./sqlite/decision-requests.js";
|
|
31
32
|
import { type DocumentListing } from "./sqlite/document-listing.js";
|
|
@@ -139,6 +140,8 @@ export interface MessageStore {
|
|
|
139
140
|
readonly business: BusinessSearchStore;
|
|
140
141
|
/** A CRM account's pipelines, deals, leads, contacts and companies, written as the CRM has them. */
|
|
141
142
|
readonly crm: CrmCopies;
|
|
143
|
+
/** The CRM files the owner downloaded, with their text; only CRM code reads them, under the copy's viewer rule. */
|
|
144
|
+
readonly crmFiles: CrmFileStore;
|
|
142
145
|
/** Relationships a source account reports, written as a diff that never overrides the owner's. */
|
|
143
146
|
readonly relations: RelationsStore;
|
|
144
147
|
/** The one-time keys behind the buttons of a message that asks the owner to decide a batch. */
|