@wirecat/cli-core 1.3.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.
- package/CHANGELOG.md +145 -0
- package/dist/attachments/container.d.ts +1 -1
- package/dist/attachments/container.js +16 -7
- package/dist/attachments/limits.d.ts +10 -0
- package/dist/attachments/limits.js +30 -1
- package/dist/attachments/transfer.js +2 -2
- package/dist/cli/app-doctor-command.d.ts +61 -7
- package/dist/cli/app-doctor-command.js +24 -11
- package/dist/cli/documents/file-edit.js +6 -6
- package/dist/cli/documents/library.js +4 -2
- package/dist/cli/index.d.ts +6 -5
- package/dist/cli/index.js +2 -1
- package/dist/cli/messenger/context.d.ts +16 -0
- package/dist/cli/messenger/doctor-command.js +16 -1
- package/dist/cli/messenger/flooded.js +9 -1
- package/dist/cli/messenger/serve-relay.d.ts +2 -0
- package/dist/cli/oauth-session.d.ts +3 -2
- package/dist/cli/oauth-session.js +19 -3
- package/dist/cli/profile-store.d.ts +24 -10
- package/dist/cli/profile-store.js +43 -28
- package/dist/cli/shared-command-exports.d.ts +1 -1
- package/dist/cli/token-session.d.ts +21 -2
- package/dist/cli/token-session.js +27 -11
- package/dist/crm/cli/files.js +7 -7
- package/dist/documents.d.ts +1 -1
- package/dist/documents.js +1 -1
- package/dist/domain/person-kinds.d.ts +7 -3
- package/dist/domain/person-kinds.js +7 -3
- package/dist/domain/ref-summaries.js +1 -0
- package/dist/domain/references.d.ts +3 -2
- package/dist/domain/references.js +19 -10
- package/dist/entities/deal.d.ts +2 -2
- package/dist/entities/deal.js +1 -1
- package/dist/entities/fact.d.ts +2 -2
- package/dist/entities/fact.js +1 -1
- package/dist/entities/fields.d.ts +1 -1
- package/dist/entities/fields.js +1 -1
- package/dist/entities/index.d.ts +15 -15
- package/dist/entities/mail-findings.d.ts +2 -2
- package/dist/entities/mail-findings.js +1 -1
- package/dist/entities/meeting-findings.d.ts +2 -2
- package/dist/entities/meeting-findings.js +1 -1
- package/dist/entities/memory.d.ts +1 -1
- package/dist/entities/task-results.d.ts +5 -5
- package/dist/entities/task-results.js +1 -1
- package/dist/entities/task.d.ts +1 -1
- package/dist/entities/task.js +1 -1
- package/dist/errors/reasons.js +2 -1
- package/dist/fetch/page.js +1 -2
- package/dist/mail/headers.d.ts +4 -3
- package/dist/mail/headers.js +21 -3
- package/dist/mail/sort-rules.d.ts +13 -6
- package/dist/mail/sort-rules.js +20 -16
- package/dist/mail/sync.js +2 -0
- package/dist/mcp/tools/attachments.js +1 -1
- package/dist/office/zip.js +1 -1
- package/dist/ports/messenger.d.ts +31 -1
- package/dist/services/archive.js +61 -11
- package/dist/services/attachments.js +4 -4
- package/dist/services/documents/file-text.js +2 -2
- package/dist/services/metadata.d.ts +1 -1
- package/dist/services/proposals/kinds/shared.d.ts +1 -1
- package/dist/services/proposals/kinds/shared.js +2 -2
- package/dist/services/proposals/kinds/task-close.js +1 -1
- package/dist/store/areas.d.ts +2 -0
- package/dist/store/areas.js +1 -0
- package/dist/store/decisions.d.ts +1 -1
- package/dist/store/decisions.js +4 -4
- package/dist/store/evidence-findings.d.ts +2 -2
- package/dist/store/index.d.ts +3 -1
- package/dist/store/index.js +2 -1
- package/dist/store/mail-findings.d.ts +2 -2
- package/dist/store/meeting-findings.d.ts +2 -2
- package/dist/store/people.d.ts +4 -4
- package/dist/store/people.js +2 -1
- package/dist/store/project-transfer/manifest.js +3 -3
- package/dist/store/public.d.ts +1 -1
- package/dist/store/public.js +1 -1
- package/dist/store/sqlite/actors.d.ts +1 -1
- package/dist/store/sqlite/actors.js +6 -6
- package/dist/store/sqlite/agent-actions.js +2 -2
- package/dist/store/sqlite/agent-links.js +1 -1
- package/dist/store/sqlite/bot-sends.d.ts +19 -0
- package/dist/store/sqlite/bot-sends.js +36 -0
- package/dist/store/sqlite/business-contracts.js +1 -1
- package/dist/store/sqlite/deals.js +1 -1
- package/dist/store/sqlite/document-transfer/plan.js +1 -1
- package/dist/store/sqlite/document-transfer/snapshot.js +1 -1
- package/dist/store/sqlite/email-index.d.ts +11 -2
- package/dist/store/sqlite/email-index.js +56 -5
- package/dist/store/sqlite/email-types.d.ts +15 -3
- package/dist/store/sqlite/email-types.js +32 -1
- package/dist/store/sqlite/emails.d.ts +2 -1
- package/dist/store/sqlite/emails.js +6 -1
- package/dist/store/sqlite/entity-types.d.ts +1 -1
- package/dist/store/sqlite/entity-types.js +1 -1
- package/dist/store/sqlite/evidence-findings.js +1 -1
- package/dist/store/sqlite/facts.js +1 -1
- package/dist/store/sqlite/finance.js +2 -2
- package/dist/store/sqlite/knowledge.js +1 -0
- package/dist/store/sqlite/mail-findings.js +1 -1
- package/dist/store/sqlite/mail-sorting.d.ts +1 -1
- package/dist/store/sqlite/mail-sorting.js +96 -60
- package/dist/store/sqlite/mail-subscriptions.d.ts +70 -0
- package/dist/store/sqlite/mail-subscriptions.js +132 -0
- package/dist/store/sqlite/manifest.js +45 -0
- package/dist/store/sqlite/meeting-findings.js +1 -1
- package/dist/store/sqlite/memories.js +3 -3
- package/dist/store/sqlite/migrations.generated.js +80 -0
- package/dist/store/sqlite/money-transactions.js +1 -1
- package/dist/store/sqlite/note-index.d.ts +4 -1
- package/dist/store/sqlite/note-index.js +40 -17
- package/dist/store/sqlite/orders.js +1 -1
- package/dist/store/sqlite/payment-facts.js +2 -2
- package/dist/store/sqlite/products.js +1 -1
- package/dist/store/sqlite/project-transfer/sources.js +2 -2
- package/dist/store/sqlite/proposed-actions.js +3 -3
- package/dist/store/sqlite/record-projection.js +1 -1
- package/dist/store/sqlite/ref-summaries.js +2 -1
- package/dist/store/sqlite/relation-proposals.js +1 -1
- package/dist/store/sqlite/reviewed.d.ts +2 -2
- package/dist/store/sqlite/reviewed.js +1 -1
- package/dist/store/sqlite/sender-bots.d.ts +19 -4
- package/dist/store/sqlite/sender-bots.js +48 -4
- package/dist/store/sqlite/subscriptions.js +2 -2
- package/dist/store/sqlite/task-close.js +1 -1
- package/dist/store/sqlite/task-comments.js +1 -1
- package/dist/store/sqlite/things.js +1 -1
- package/dist/store/sqlite/transaction.d.ts +5 -0
- package/dist/store/sqlite/transaction.js +6 -1
- package/dist/store/sqlite/wallets.js +1 -1
- package/dist/store/sqlite/work-tasks.js +2 -2
- package/dist/tracker/tasks.js +4 -2
- package/package.json +7 -5
|
@@ -2190,5 +2190,85 @@ export const GENERATED = [
|
|
|
2190
2190
|
"CREATE TRIGGER mail_sort_checked_au AFTER UPDATE OF mail_type ON emails\nWHEN NEW.mail_type IS NULL AND NEW.sort_checked IS NOT NULL BEGIN\n UPDATE emails SET sort_checked = NULL WHERE id = NEW.id;\nEND;",
|
|
2191
2191
|
"CREATE TRIGGER mail_sort_effects_identity_ad AFTER DELETE ON identities BEGIN\n DELETE FROM mail_sort_effects WHERE identity_id = OLD.id;\nEND;"
|
|
2192
2192
|
]
|
|
2193
|
+
},
|
|
2194
|
+
{
|
|
2195
|
+
"name": "20261125231505_version-78-agent-refs",
|
|
2196
|
+
"statements": [
|
|
2197
|
+
"-- Until version 78 `bot` named the agents of the `bots` table, in every pointer pair and ref. Sender bots take\n-- `bot:` now, so the agents' values move to `agent` first, and `sender-bot:` refs become `bot:` after. Whole values\n-- only: a text replace would turn `sender-bot:5` and `telegram-bot:` into something else.\nUPDATE agent_actions SET actor_type = 'agent' WHERE actor_type = 'bot';",
|
|
2198
|
+
"UPDATE agent_actions SET target_type = 'agent' WHERE target_type = 'bot';",
|
|
2199
|
+
"UPDATE aliases SET aliasable_type = 'agent' WHERE aliasable_type = 'bot';",
|
|
2200
|
+
"UPDATE attachments SET attachable_type = 'agent' WHERE attachable_type = 'bot';",
|
|
2201
|
+
"UPDATE catalog_items SET supplier_type = 'agent' WHERE supplier_type = 'bot';",
|
|
2202
|
+
"UPDATE catalog_items SET author_type = 'agent' WHERE author_type = 'bot';",
|
|
2203
|
+
"UPDATE contracts SET author_type = 'agent' WHERE author_type = 'bot';",
|
|
2204
|
+
"UPDATE contracts SET confirmed_by_type = 'agent' WHERE confirmed_by_type = 'bot';",
|
|
2205
|
+
"UPDATE deals SET author_type = 'agent' WHERE author_type = 'bot';",
|
|
2206
|
+
"UPDATE decisions SET confirmed_by_type = 'agent' WHERE confirmed_by_type = 'bot';",
|
|
2207
|
+
"UPDATE enrichments SET subject_type = 'agent' WHERE subject_type = 'bot';",
|
|
2208
|
+
"UPDATE entity_link_events SET linkable_type = 'agent' WHERE linkable_type = 'bot';",
|
|
2209
|
+
"UPDATE facts SET subject_type = 'agent' WHERE subject_type = 'bot';",
|
|
2210
|
+
"UPDATE facts SET author_type = 'agent' WHERE author_type = 'bot';",
|
|
2211
|
+
"UPDATE facts SET confirmed_by_type = 'agent' WHERE confirmed_by_type = 'bot';",
|
|
2212
|
+
"UPDATE financial_accounts SET holder_type = 'agent' WHERE holder_type = 'bot';",
|
|
2213
|
+
"UPDATE financial_accounts SET author_type = 'agent' WHERE author_type = 'bot';",
|
|
2214
|
+
"UPDATE financial_transactions SET counterparty_type = 'agent' WHERE counterparty_type = 'bot';",
|
|
2215
|
+
"UPDATE financial_transactions SET author_type = 'agent' WHERE author_type = 'bot';",
|
|
2216
|
+
"UPDATE financial_transactions SET confirmed_by_type = 'agent' WHERE confirmed_by_type = 'bot';",
|
|
2217
|
+
"UPDATE invoices SET issuer_type = 'agent' WHERE issuer_type = 'bot';",
|
|
2218
|
+
"UPDATE invoices SET counterparty_type = 'agent' WHERE counterparty_type = 'bot';",
|
|
2219
|
+
"UPDATE invoices SET author_type = 'agent' WHERE author_type = 'bot';",
|
|
2220
|
+
"UPDATE invoices SET confirmed_by_type = 'agent' WHERE confirmed_by_type = 'bot';",
|
|
2221
|
+
"UPDATE involvements SET subject_type = 'agent' WHERE subject_type = 'bot';",
|
|
2222
|
+
"UPDATE leads SET author_type = 'agent' WHERE author_type = 'bot';",
|
|
2223
|
+
"UPDATE link_reviews SET linkable_type = 'agent' WHERE linkable_type = 'bot';",
|
|
2224
|
+
"UPDATE links SET from_type = 'agent' WHERE from_type = 'bot';",
|
|
2225
|
+
"UPDATE links SET to_type = 'agent' WHERE to_type = 'bot';",
|
|
2226
|
+
"UPDATE memories SET subject_type = 'agent' WHERE subject_type = 'bot';",
|
|
2227
|
+
"UPDATE memories SET author_type = 'agent' WHERE author_type = 'bot';",
|
|
2228
|
+
"UPDATE mentions SET source_type = 'agent' WHERE source_type = 'bot';",
|
|
2229
|
+
"UPDATE mentions SET target_type = 'agent' WHERE target_type = 'bot';",
|
|
2230
|
+
"UPDATE notes SET notable_type = 'agent' WHERE notable_type = 'bot';",
|
|
2231
|
+
"UPDATE notes SET author_type = 'agent' WHERE author_type = 'bot';",
|
|
2232
|
+
"UPDATE orders SET customer_type = 'agent' WHERE customer_type = 'bot';",
|
|
2233
|
+
"UPDATE orders SET supplier_type = 'agent' WHERE supplier_type = 'bot';",
|
|
2234
|
+
"UPDATE orders SET author_type = 'agent' WHERE author_type = 'bot';",
|
|
2235
|
+
"UPDATE orders SET confirmed_by_type = 'agent' WHERE confirmed_by_type = 'bot';",
|
|
2236
|
+
"UPDATE payment_allocations SET author_type = 'agent' WHERE author_type = 'bot';",
|
|
2237
|
+
"UPDATE payments SET payer_type = 'agent' WHERE payer_type = 'bot';",
|
|
2238
|
+
"UPDATE payments SET payee_type = 'agent' WHERE payee_type = 'bot';",
|
|
2239
|
+
"UPDATE payments SET author_type = 'agent' WHERE author_type = 'bot';",
|
|
2240
|
+
"UPDATE payments SET confirmed_by_type = 'agent' WHERE confirmed_by_type = 'bot';",
|
|
2241
|
+
"UPDATE pipeline_stage_changes SET item_type = 'agent' WHERE item_type = 'bot';",
|
|
2242
|
+
"UPDATE projects SET owner_type = 'agent' WHERE owner_type = 'bot';",
|
|
2243
|
+
"UPDATE proposed_actions SET target_type = 'agent' WHERE target_type = 'bot';",
|
|
2244
|
+
"UPDATE proposed_actions SET proposed_by_type = 'agent' WHERE proposed_by_type = 'bot';",
|
|
2245
|
+
"UPDATE proposed_actions SET decided_by_type = 'agent' WHERE decided_by_type = 'bot';",
|
|
2246
|
+
"UPDATE record_relations SET target_type = 'agent' WHERE target_type = 'bot';",
|
|
2247
|
+
"UPDATE records SET entity_type = 'agent' WHERE entity_type = 'bot';",
|
|
2248
|
+
"UPDATE subscription_prices SET author_type = 'agent' WHERE author_type = 'bot';",
|
|
2249
|
+
"UPDATE subscription_prices SET confirmed_by_type = 'agent' WHERE confirmed_by_type = 'bot';",
|
|
2250
|
+
"UPDATE subscriptions SET supplier_type = 'agent' WHERE supplier_type = 'bot';",
|
|
2251
|
+
"UPDATE subscriptions SET customer_type = 'agent' WHERE customer_type = 'bot';",
|
|
2252
|
+
"UPDATE subscriptions SET author_type = 'agent' WHERE author_type = 'bot';",
|
|
2253
|
+
"UPDATE subscriptions SET confirmed_by_type = 'agent' WHERE confirmed_by_type = 'bot';",
|
|
2254
|
+
"UPDATE tag_consolidations SET actor_type = 'agent' WHERE actor_type = 'bot';",
|
|
2255
|
+
"UPDATE taggings SET taggable_type = 'agent' WHERE taggable_type = 'bot';",
|
|
2256
|
+
"UPDATE taggings SET author_type = 'agent' WHERE author_type = 'bot';",
|
|
2257
|
+
"UPDATE task_assignments SET assignee_type = 'agent' WHERE assignee_type = 'bot';",
|
|
2258
|
+
"UPDATE task_events SET actor_type = 'agent' WHERE actor_type = 'bot';",
|
|
2259
|
+
"UPDATE task_pairs SET decided_by_type = 'agent' WHERE decided_by_type = 'bot';",
|
|
2260
|
+
"UPDATE tasks SET closed_by_type = 'agent' WHERE closed_by_type = 'bot';",
|
|
2261
|
+
"UPDATE tasks SET author_type = 'agent' WHERE author_type = 'bot';",
|
|
2262
|
+
"UPDATE tasks SET close_suggested_by_type = 'agent' WHERE close_suggested_by_type = 'bot';",
|
|
2263
|
+
"UPDATE links SET target_text = 'agent:' || substr(target_text, 5) WHERE target_text LIKE 'bot:%';",
|
|
2264
|
+
"UPDATE links SET metadata = json_set(metadata, '$.gone', 'agent') WHERE json_valid(metadata) AND json_extract(metadata, '$.gone') = 'bot';",
|
|
2265
|
+
"UPDATE record_relations SET target_external_id = 'agent:' || substr(target_external_id, 5) WHERE target_type = 'ref' AND target_external_id LIKE 'bot:%';",
|
|
2266
|
+
"UPDATE proposed_actions SET payload = json_set(payload, '$.from', 'agent:' || substr(json_extract(payload, '$.from'), 5)) WHERE json_valid(payload) AND json_type(payload, '$.from') = 'text' AND json_extract(payload, '$.from') LIKE 'bot:%';",
|
|
2267
|
+
"UPDATE proposed_actions SET payload = json_set(payload, '$.to', 'agent:' || substr(json_extract(payload, '$.to'), 5)) WHERE json_valid(payload) AND json_type(payload, '$.to') = 'text' AND json_extract(payload, '$.to') LIKE 'bot:%';",
|
|
2268
|
+
"UPDATE proposed_actions SET payload = json_set(payload, '$.ref', 'agent:' || substr(json_extract(payload, '$.ref'), 5)) WHERE json_valid(payload) AND json_type(payload, '$.ref') = 'text' AND json_extract(payload, '$.ref') LIKE 'bot:%';",
|
|
2269
|
+
"UPDATE document_annotation_transfers SET reference_map = (SELECT json_group_object(key, CASE WHEN type = 'text' AND value LIKE 'bot:%' THEN 'agent:' || substr(value, 5) ELSE value END) FROM json_each(document_annotation_transfers.reference_map)) WHERE json_valid(reference_map) AND reference_map LIKE '%\"bot:%'\n AND NOT EXISTS (SELECT 1 FROM json_each(document_annotation_transfers.reference_map) WHERE type NOT IN ('text', 'null'));",
|
|
2270
|
+
"UPDATE mail_sort_effects SET \"before\" = 'bot:' || substr(\"before\", 12) WHERE \"before\" LIKE 'sender-bot:%';",
|
|
2271
|
+
"UPDATE mail_sort_effects SET \"after\" = 'bot:' || substr(\"after\", 12) WHERE \"after\" LIKE 'sender-bot:%';"
|
|
2272
|
+
]
|
|
2193
2273
|
}
|
|
2194
2274
|
];
|
|
@@ -12,7 +12,7 @@ import { write } from "./transaction.js";
|
|
|
12
12
|
const TRANSACTIONS = "SELECT t.*, w.name AS wallet_name, b.name AS author_name, b.kind AS author_kind, " +
|
|
13
13
|
"(SELECT coalesce(sum(amount), 0) FROM transaction_splits WHERE transaction_id = t.id) AS split " +
|
|
14
14
|
"FROM financial_transactions t JOIN financial_accounts w ON w.id = t.financial_account_id " +
|
|
15
|
-
"LEFT JOIN bots b ON t.author_type = '
|
|
15
|
+
"LEFT JOIN bots b ON t.author_type = 'agent' AND b.id = t.author_id";
|
|
16
16
|
const MAX_SPLITS = 100;
|
|
17
17
|
export const transactionOperationsOver = (context) => {
|
|
18
18
|
const { database, now } = context;
|
|
@@ -123,10 +123,13 @@ export declare const noteIndexState: (database: CacheDatabase) => NoteIndexState
|
|
|
123
123
|
* Indexes one corpus's rows written since the last drain, in short write transactions. These corpora are
|
|
124
124
|
* small, so a change of stemmer choices simply queues every row again instead of waiting for `store rebuild`.
|
|
125
125
|
*/
|
|
126
|
-
export declare const drainCorpus: (database: CacheDatabase, corpus: Corpus, stemmerFor: (stemmers: Stemmers) => Stemmer, { batch, until }?: {
|
|
126
|
+
export declare const drainCorpus: (database: CacheDatabase, corpus: Corpus, stemmerFor: (stemmers: Stemmers) => Stemmer, { batch, until, budgetMs }?: {
|
|
127
127
|
batch?: number;
|
|
128
128
|
until?: () => boolean;
|
|
129
|
+
budgetMs?: number;
|
|
129
130
|
}) => number;
|
|
131
|
+
/** Indexes these queued rows now, inside the caller's write, so they share its commit. */
|
|
132
|
+
export declare const indexQueued: (database: CacheDatabase, corpus: Corpus, stemmerFor: (stemmers: Stemmers) => Stemmer, ids: readonly number[]) => number;
|
|
130
133
|
/** Documents, then notes: what a notes search reads; then the trigrams still to fill. */
|
|
131
134
|
export declare const drainNoteIndex: (database: CacheDatabase, stemmerFor: (stemmers: Stemmers) => Stemmer, options?: {
|
|
132
135
|
batch?: number;
|
|
@@ -266,13 +266,8 @@ const writer = (database, corpus, stemmer) => {
|
|
|
266
266
|
statements.dequeue.run(queuedAs(corpus), id);
|
|
267
267
|
};
|
|
268
268
|
};
|
|
269
|
-
/**
|
|
270
|
-
|
|
271
|
-
* small, so a change of stemmer choices simply queues every row again instead of waiting for `store rebuild`.
|
|
272
|
-
*/
|
|
273
|
-
export const drainCorpus = (database, corpus, stemmerFor, { batch = 200, until = () => false } = {}) => {
|
|
274
|
-
if (isQueryOnly(database))
|
|
275
|
-
return 0;
|
|
269
|
+
/** The corpus's writer once its index state is set up, or `undefined` when the store wants no index for it. */
|
|
270
|
+
const readyWriter = (database, corpus, stemmerFor) => {
|
|
276
271
|
// Pieces written before they carried their account get it, once: purge and vector search filter by it.
|
|
277
272
|
if ((corpus.type === "email" || corpus.type === "document") &&
|
|
278
273
|
database.prepare("SELECT 1 FROM chunks WHERE chunkable_type = ? AND account_id IS NULL LIMIT 1").get(corpus.type))
|
|
@@ -287,31 +282,48 @@ export const drainCorpus = (database, corpus, stemmerFor, { batch = 200, until =
|
|
|
287
282
|
.run(corpus.index));
|
|
288
283
|
const state = corpusIndexState(database, corpus);
|
|
289
284
|
if (state.wanted === null)
|
|
290
|
-
return
|
|
285
|
+
return undefined;
|
|
291
286
|
const stemmer = stemmerFor(savedStemmers(database) ?? DEFAULT_STEMMERS);
|
|
292
|
-
const queue = `${corpus.type}_index_pending`;
|
|
293
287
|
if (state.built !== stemmer.identity) {
|
|
294
288
|
write(database, () => {
|
|
295
289
|
if (state.built !== null)
|
|
296
290
|
database
|
|
297
|
-
.prepare(`INSERT OR IGNORE INTO ${
|
|
291
|
+
.prepare(`INSERT OR IGNORE INTO ${corpus.type}_index_pending (indexable_type, id) SELECT ?, id FROM ${corpus.table}`)
|
|
298
292
|
.run(queuedAs(corpus));
|
|
299
293
|
database.prepare("UPDATE search_index_state SET analyzer = ? WHERE name = ?").run(stemmer.identity, corpus.index);
|
|
300
294
|
});
|
|
301
295
|
}
|
|
302
|
-
if (state.pending === 0
|
|
296
|
+
else if (state.pending === 0)
|
|
297
|
+
return undefined;
|
|
298
|
+
return writer(database, corpus, stemmer);
|
|
299
|
+
};
|
|
300
|
+
/**
|
|
301
|
+
* Indexes one corpus's rows written since the last drain, in short write transactions. These corpora are
|
|
302
|
+
* small, so a change of stemmer choices simply queues every row again instead of waiting for `store rebuild`.
|
|
303
|
+
*/
|
|
304
|
+
export const drainCorpus = (database, corpus, stemmerFor, { batch = 200, until = () => false, budgetMs = 0 } = {}) => {
|
|
305
|
+
if (isQueryOnly(database))
|
|
303
306
|
return 0;
|
|
304
|
-
const
|
|
305
|
-
|
|
307
|
+
const index = readyWriter(database, corpus, stemmerFor);
|
|
308
|
+
if (index === undefined)
|
|
309
|
+
return 0;
|
|
310
|
+
const next = database.prepare(`SELECT id FROM ${corpus.type}_index_pending WHERE indexable_type = ? ORDER BY id LIMIT ?`);
|
|
306
311
|
let done = 0;
|
|
307
312
|
for (;;) {
|
|
308
313
|
if (until())
|
|
309
314
|
break;
|
|
315
|
+
// Batches go on in one write until the budget is spent: each commit syncs to disk, which under load costs more
|
|
316
|
+
// than indexing 200 short emails (cli-testing performance/mail/types).
|
|
310
317
|
const count = write(database, () => {
|
|
311
|
-
const
|
|
312
|
-
for (
|
|
313
|
-
|
|
314
|
-
|
|
318
|
+
const started = performance.now();
|
|
319
|
+
for (let indexed = 0;;) {
|
|
320
|
+
const ids = next.all(queuedAs(corpus), batch).map((row) => Number(row.id));
|
|
321
|
+
for (const id of ids)
|
|
322
|
+
index(id);
|
|
323
|
+
indexed += ids.length;
|
|
324
|
+
if (ids.length < batch || performance.now() - started >= budgetMs)
|
|
325
|
+
return indexed;
|
|
326
|
+
}
|
|
315
327
|
});
|
|
316
328
|
if (count === 0)
|
|
317
329
|
break;
|
|
@@ -319,6 +331,17 @@ export const drainCorpus = (database, corpus, stemmerFor, { batch = 200, until =
|
|
|
319
331
|
}
|
|
320
332
|
return done;
|
|
321
333
|
};
|
|
334
|
+
/** Indexes these queued rows now, inside the caller's write, so they share its commit. */
|
|
335
|
+
export const indexQueued = (database, corpus, stemmerFor, ids) => {
|
|
336
|
+
if (ids.length === 0)
|
|
337
|
+
return 0;
|
|
338
|
+
const index = readyWriter(database, corpus, stemmerFor);
|
|
339
|
+
if (index === undefined)
|
|
340
|
+
return 0;
|
|
341
|
+
for (const id of ids)
|
|
342
|
+
index(id);
|
|
343
|
+
return ids.length;
|
|
344
|
+
};
|
|
322
345
|
/** Documents, then notes: what a notes search reads; then the trigrams still to fill. */
|
|
323
346
|
export const drainNoteIndex = (database, stemmerFor, options = {}) => drainCorpus(database, CORPORA.document, stemmerFor, options) +
|
|
324
347
|
drainCorpus(database, CORPORA.note, stemmerFor, options) +
|
|
@@ -13,7 +13,7 @@ import { isoDate, limitOf, oneOf, refuse, reviewedRowsOver, text, } from "./revi
|
|
|
13
13
|
import { pageOfRows } from "./rows-page.js";
|
|
14
14
|
import { write } from "./transaction.js";
|
|
15
15
|
const ORDERS = "SELECT o.*, b.name AS author_name, b.kind AS author_kind FROM orders o " +
|
|
16
|
-
"LEFT JOIN bots b ON o.author_type = '
|
|
16
|
+
"LEFT JOIN bots b ON o.author_type = 'agent' AND b.id = o.author_id";
|
|
17
17
|
export const orderOperationsOver = (context) => {
|
|
18
18
|
const { database, now } = context;
|
|
19
19
|
const { partyOf, partyThing, reviewedOf, written, keepEvidence, ownerOnly, linkedId, decideRow, mayChangeParts } = reviewedRowsOver(context);
|
|
@@ -28,7 +28,7 @@ export const movePaymentFacts = (context) => {
|
|
|
28
28
|
return write(database, () => {
|
|
29
29
|
const rows = database
|
|
30
30
|
.prepare("SELECT f.*, b.name AS bot_name, b.kind AS bot_kind FROM facts f " +
|
|
31
|
-
"LEFT JOIN bots b ON f.author_type = '
|
|
31
|
+
"LEFT JOIN bots b ON f.author_type = 'agent' AND b.id = f.author_id WHERE f.type = 'payment' ORDER BY f.id")
|
|
32
32
|
.all();
|
|
33
33
|
const nextState = (id) => paymentOf(database
|
|
34
34
|
.prepare("SELECT metadata FROM facts WHERE supersedes_id = ? AND type = 'payment' ORDER BY id DESC LIMIT 1")
|
|
@@ -47,7 +47,7 @@ export const movePaymentFacts = (context) => {
|
|
|
47
47
|
const payment = paymentOf(row.metadata);
|
|
48
48
|
if (!payment)
|
|
49
49
|
continue;
|
|
50
|
-
const by = row.author_type === "
|
|
50
|
+
const by = row.author_type === "agent" && row.bot_name != null
|
|
51
51
|
? {
|
|
52
52
|
bot: String(row.bot_name),
|
|
53
53
|
kind: row.bot_kind === "rule" ? "rule" : "agent",
|
|
@@ -7,7 +7,7 @@ import { iso, isoDate, limitOf, oneOf, refuse, reviewedRowsOver, text, } from ".
|
|
|
7
7
|
import { pageOfRows } from "./rows-page.js";
|
|
8
8
|
import { write } from "./transaction.js";
|
|
9
9
|
const PRODUCTS = "SELECT c.*, b.name AS author_name, b.kind AS author_kind FROM catalog_items c " +
|
|
10
|
-
"LEFT JOIN bots b ON c.author_type = '
|
|
10
|
+
"LEFT JOIN bots b ON c.author_type = 'agent' AND b.id = c.author_id";
|
|
11
11
|
export const productOperationsOver = (context) => {
|
|
12
12
|
const { database, now } = context;
|
|
13
13
|
const { partyOf, partyThing } = reviewedRowsOver(context);
|
|
@@ -6,7 +6,7 @@ const invalid = () => {
|
|
|
6
6
|
};
|
|
7
7
|
const scalar = new Set([
|
|
8
8
|
"person",
|
|
9
|
-
"
|
|
9
|
+
"agent",
|
|
10
10
|
"organization",
|
|
11
11
|
"project",
|
|
12
12
|
"fact",
|
|
@@ -23,7 +23,7 @@ const scalar = new Set([
|
|
|
23
23
|
"meeting_transcript",
|
|
24
24
|
"meeting_transcript_row",
|
|
25
25
|
]);
|
|
26
|
-
const noText = new Set(["person", "
|
|
26
|
+
const noText = new Set(["person", "agent", "organization", "project", "chat", "identity", "account"]);
|
|
27
27
|
const texts = {
|
|
28
28
|
document: {
|
|
29
29
|
table: "documents",
|
|
@@ -23,14 +23,14 @@ const json = (value) => (value == null ? null : JSON.parse(String(value)));
|
|
|
23
23
|
const STATUS = `CASE WHEN p.status = 'approved' AND p.kind IN ('${MEETING_FINDINGS_KIND}', '${EVIDENCE_FINDINGS_KIND}', '${MAIL_FINDINGS_KIND}') ` +
|
|
24
24
|
"AND json_array_length(p.result, '$.accepted') = 0 THEN 'rejected' ELSE p.status END";
|
|
25
25
|
const NAMED = `SELECT p.*, ${STATUS} AS shown_status, b.name AS proposer_name, b.kind AS proposer_kind FROM proposed_actions p ` +
|
|
26
|
-
"LEFT JOIN bots b ON p.proposed_by_type = '
|
|
26
|
+
"LEFT JOIN bots b ON p.proposed_by_type = 'agent' AND b.id = p.proposed_by_id";
|
|
27
27
|
/** Who proposed an action, for `mayDecide`. */
|
|
28
28
|
export const proposerOfAction = ({ proposedBy, payload }) => proposedBy.type === "person"
|
|
29
29
|
? { type: "person", id: proposedBy.id }
|
|
30
30
|
: proposedBy.name === null
|
|
31
31
|
? { type: "unknown" }
|
|
32
32
|
: {
|
|
33
|
-
type: "
|
|
33
|
+
type: "agent",
|
|
34
34
|
id: proposedBy.id,
|
|
35
35
|
name: proposedBy.name,
|
|
36
36
|
kind: proposedBy.kind ?? "agent",
|
|
@@ -58,7 +58,7 @@ export const proposalOperationsOver = (context) => {
|
|
|
58
58
|
type: row.proposed_by_type,
|
|
59
59
|
id: String(row.proposed_by_id),
|
|
60
60
|
name: row.proposer_name == null ? null : String(row.proposer_name),
|
|
61
|
-
kind: row.proposed_by_type !== "
|
|
61
|
+
kind: row.proposed_by_type !== "agent"
|
|
62
62
|
? null
|
|
63
63
|
: row.proposer_kind === "rule" || row.proposer_name === "rule"
|
|
64
64
|
? "rule"
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { CliError } from "@wirecat/cli-base";
|
|
2
2
|
export const IMPORTER = { bot: "import" };
|
|
3
3
|
/** A proposal the import made that the owner has not decided yet: the import may still change it. */
|
|
4
|
-
export const importersProposal = (entity) => entity.review === "proposed" && entity.author.type === "
|
|
4
|
+
export const importersProposal = (entity) => entity.review === "proposed" && entity.author.type === "agent" && entity.author.name === IMPORTER.bot;
|
|
5
5
|
/** The stable word a store refusal carries, for the receipt. */
|
|
6
6
|
export const codeOf = (error) => {
|
|
7
7
|
const reason = error.details?.reason;
|
|
@@ -196,7 +196,8 @@ const READERS = {
|
|
|
196
196
|
deleted: "x.deleted_at",
|
|
197
197
|
body: bodyOr(body, "x.statement"),
|
|
198
198
|
})),
|
|
199
|
-
|
|
199
|
+
agent: byId("agent", "bots", () => ({ title: "x.name" })),
|
|
200
|
+
bot: byId("bot", "sender_bots", () => ({ title: "x.name" })),
|
|
200
201
|
// Money is formatted with its currency's scale in JS, so SQL hands `titleOf` the fields as JSON.
|
|
201
202
|
invoice: byId("invoice", "invoices", () => ({
|
|
202
203
|
title: "json_object('id', x.id, 'number', x.number, 'direction', x.direction, 'total', x.total, " +
|
|
@@ -157,7 +157,7 @@ export const relationProposalsOver = (context) => {
|
|
|
157
157
|
*/
|
|
158
158
|
const rescored = (action, input, scored, by) => {
|
|
159
159
|
const proposer = proposerOfAction(action);
|
|
160
|
-
const own = proposer.type === "
|
|
160
|
+
const own = proposer.type === "agent" && proposer.kind === "rule" && botKey(proposer.name) === botKey(by.bot);
|
|
161
161
|
const before = action.payload;
|
|
162
162
|
const payload = own
|
|
163
163
|
? {
|
|
@@ -85,7 +85,7 @@ export declare const reviewedRowsOver: (context: StoreContext) => {
|
|
|
85
85
|
model: string | null;
|
|
86
86
|
source: string;
|
|
87
87
|
review: string;
|
|
88
|
-
confirmedType: "
|
|
88
|
+
confirmedType: "agent" | "person" | null;
|
|
89
89
|
confirmedId: number | null;
|
|
90
90
|
metadata: string | null;
|
|
91
91
|
project: number | null;
|
|
@@ -97,7 +97,7 @@ export declare const reviewedRowsOver: (context: StoreContext) => {
|
|
|
97
97
|
model: string | null;
|
|
98
98
|
source: string;
|
|
99
99
|
review: string;
|
|
100
|
-
confirmedType: "
|
|
100
|
+
confirmedType: "agent" | "person" | null;
|
|
101
101
|
confirmedId: number | null;
|
|
102
102
|
metadata: string | null;
|
|
103
103
|
project: number | null;
|
|
@@ -97,7 +97,7 @@ export const decisionsOver = (context) => {
|
|
|
97
97
|
const mayChangeParts = (row, by, message, reason = "finance.owner-only") => {
|
|
98
98
|
if (by === "owner")
|
|
99
99
|
return;
|
|
100
|
-
const own = row.author_type === "
|
|
100
|
+
const own = row.author_type === "agent" && row.author_name != null && botKey(String(row.author_name)) === botKey(by.bot);
|
|
101
101
|
if (row.review !== "proposed" || !own)
|
|
102
102
|
throw new CliError("permission_error", message, { reason });
|
|
103
103
|
};
|
|
@@ -1,5 +1,6 @@
|
|
|
1
|
-
import type { CacheDatabase } from "../driver.js";
|
|
1
|
+
import type { CacheDatabase, SqlValue } from "../driver.js";
|
|
2
2
|
import type { IdentityRef, PersonRecord } from "../types.js";
|
|
3
|
+
import type { BotSends } from "./bot-sends.js";
|
|
3
4
|
import type { StoreContext } from "./open.js";
|
|
4
5
|
import { type Reach, type SenderSignal } from "./sender-signals.js";
|
|
5
6
|
export type BotAuthor = "rules" | "owner";
|
|
@@ -12,7 +13,7 @@ export interface BotIdentity {
|
|
|
12
13
|
}
|
|
13
14
|
/** A program that writes to the owner, apart from people: it has no ties, no tasks and no merge review. @experimental */
|
|
14
15
|
export interface SenderBot {
|
|
15
|
-
/** `
|
|
16
|
+
/** `bot:<id>`. */
|
|
16
17
|
bot: string;
|
|
17
18
|
/** The owner's name for it; `displayName` falls back to its identities'. */
|
|
18
19
|
name: string | null;
|
|
@@ -33,7 +34,7 @@ export interface SenderBot {
|
|
|
33
34
|
/** One move of an identity between a person and a bot. @experimental */
|
|
34
35
|
export interface BotMove {
|
|
35
36
|
identity: IdentityRef;
|
|
36
|
-
/** `person:<uid>` or `
|
|
37
|
+
/** `person:<uid>` or `bot:<id>`; `null` for none. */
|
|
37
38
|
from: string | null;
|
|
38
39
|
to: string | null;
|
|
39
40
|
author: BotAuthor;
|
|
@@ -51,6 +52,8 @@ export interface BotListOptions {
|
|
|
51
52
|
query?: string;
|
|
52
53
|
/** `organization:<id>`: the bots that send for it. */
|
|
53
54
|
organization?: string;
|
|
55
|
+
/** Only bots that send any of these (`BOT_SENDS`). */
|
|
56
|
+
sends?: readonly BotSends[];
|
|
54
57
|
limit: number;
|
|
55
58
|
offset?: number;
|
|
56
59
|
}
|
|
@@ -93,7 +96,11 @@ export declare const hasLegacyBots: (database: CacheDatabase) => boolean;
|
|
|
93
96
|
*/
|
|
94
97
|
export declare const settleLegacyBots: (database: CacheDatabase, at: number) => void;
|
|
95
98
|
/** The sender bots, by name; a bot a build before version 75 sorted shows once a list has settled it. */
|
|
96
|
-
|
|
99
|
+
/** `sent` is `sendsWhere` of `options.sends`, worked out before the read: it may keep mail types. */
|
|
100
|
+
export declare const listBots: (database: CacheDatabase, options: BotListOptions, sent?: {
|
|
101
|
+
sql: string;
|
|
102
|
+
params: SqlValue[];
|
|
103
|
+
}) => BotList;
|
|
97
104
|
/** One sender bot with its identities and every move to or from it. */
|
|
98
105
|
export declare const showBot: (database: CacheDatabase, ref: string) => SenderBotDetails;
|
|
99
106
|
/**
|
|
@@ -115,3 +122,11 @@ export declare const moveToPerson: (context: StoreContext, subject: string | Ide
|
|
|
115
122
|
person?: string;
|
|
116
123
|
reason?: string;
|
|
117
124
|
}) => PersonRecord;
|
|
125
|
+
/** Who put an identity where it is: its bot's author, else its last move's; `rules` when nothing moved it. */
|
|
126
|
+
export declare const holdingAuthorOf: (database: CacheDatabase, identity: number) => BotAuthor;
|
|
127
|
+
/**
|
|
128
|
+
* Puts an identity back where it was held, `person:<id>` or `bot:<id>`, under the author that put it there: a
|
|
129
|
+
* removed sorting rule leaves no owner's mark the owner never made, so the program may sort it again. A bot gone with
|
|
130
|
+
* its last identity comes back as a new one. The caller holds the write lock.
|
|
131
|
+
*/
|
|
132
|
+
export declare const putBack: (context: StoreContext, identity: number, holder: string, author: BotAuthor) => void;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { CliError } from "@wirecat/cli-base";
|
|
2
2
|
import { displayName } from "../../domain/display-names.js";
|
|
3
|
-
import { SENDER_BOT_PREFIX } from "../../domain/person-kinds.js";
|
|
3
|
+
import { SENDER_BOT_PREFIX, senderBotRef } from "../../domain/person-kinds.js";
|
|
4
4
|
import { fold } from "../normalize.js";
|
|
5
5
|
import { groupByDomain, releaseDomainHolds } from "./domain-organizations.js";
|
|
6
6
|
import { currentPerson } from "./merged-persons.js";
|
|
@@ -220,7 +220,8 @@ export const settleLegacyBots = (database, at) => {
|
|
|
220
220
|
database.prepare("DELETE FROM sender_bots WHERE id = ?").run(bot);
|
|
221
221
|
}
|
|
222
222
|
};
|
|
223
|
-
const botIdOf = (database,
|
|
223
|
+
const botIdOf = (database, given) => {
|
|
224
|
+
const ref = senderBotRef(given);
|
|
224
225
|
const id = ref.startsWith(SENDER_BOT_PREFIX) ? ref.slice(SENDER_BOT_PREFIX.length) : "";
|
|
225
226
|
const row = /^[1-9]\d*$/.test(id)
|
|
226
227
|
? database.prepare("SELECT id FROM sender_bots WHERE id = ?").get(Number(id))
|
|
@@ -246,7 +247,7 @@ const identityIdOf = (database, { provider, id }) => {
|
|
|
246
247
|
const subjectOf = (database, subject) => {
|
|
247
248
|
if (typeof subject !== "string")
|
|
248
249
|
return { identities: [identityIdOf(database, subject)] };
|
|
249
|
-
if (subject.startsWith(SENDER_BOT_PREFIX)) {
|
|
250
|
+
if (senderBotRef(subject).startsWith(SENDER_BOT_PREFIX)) {
|
|
250
251
|
const bot = botIdOf(database, subject);
|
|
251
252
|
return { bot, identities: botIdentitiesOf(database, bot) };
|
|
252
253
|
}
|
|
@@ -355,7 +356,8 @@ const detailsOf = (database, bot) => {
|
|
|
355
356
|
return { ...found, moves: movesOf(database, bot) };
|
|
356
357
|
};
|
|
357
358
|
/** The sender bots, by name; a bot a build before version 75 sorted shows once a list has settled it. */
|
|
358
|
-
|
|
359
|
+
/** `sent` is `sendsWhere` of `options.sends`, worked out before the read: it may keep mail types. */
|
|
360
|
+
export const listBots = (database, options, sent) => {
|
|
359
361
|
const { limit, offset = 0 } = options;
|
|
360
362
|
const where = [HOLDS];
|
|
361
363
|
const params = [];
|
|
@@ -378,6 +380,11 @@ export const listBots = (database, options) => {
|
|
|
378
380
|
where.push("b.organization_id = ?");
|
|
379
381
|
params.push(Number(id));
|
|
380
382
|
}
|
|
383
|
+
if (sent !== undefined) {
|
|
384
|
+
where.push(sent.sql);
|
|
385
|
+
for (const param of sent.params)
|
|
386
|
+
params.push(param);
|
|
387
|
+
}
|
|
381
388
|
return read(database, () => {
|
|
382
389
|
const filter = where.join(" AND ");
|
|
383
390
|
const total = Number(database.prepare(`SELECT count(*) AS n FROM sender_bots b WHERE ${filter}`).get(...params)?.n);
|
|
@@ -468,3 +475,40 @@ export const moveToPerson = (context, subject, options = {}) => {
|
|
|
468
475
|
return recordOf(context, first ?? target ?? chosen.person);
|
|
469
476
|
});
|
|
470
477
|
};
|
|
478
|
+
/** Who put an identity where it is: its bot's author, else its last move's; `rules` when nothing moved it. */
|
|
479
|
+
export const holdingAuthorOf = (database, identity) => {
|
|
480
|
+
const { bot } = holderOf(database, identity);
|
|
481
|
+
const row = bot === undefined
|
|
482
|
+
? database
|
|
483
|
+
.prepare("SELECT author FROM sender_bot_moves WHERE identity_id = ? ORDER BY id DESC LIMIT 1")
|
|
484
|
+
.get(identity)
|
|
485
|
+
: database.prepare("SELECT author FROM sender_bots WHERE id = ?").get(bot);
|
|
486
|
+
return row?.author === "owner" ? "owner" : "rules";
|
|
487
|
+
};
|
|
488
|
+
/**
|
|
489
|
+
* Puts an identity back where it was held, `person:<id>` or `bot:<id>`, under the author that put it there: a
|
|
490
|
+
* removed sorting rule leaves no owner's mark the owner never made, so the program may sort it again. A bot gone with
|
|
491
|
+
* its last identity comes back as a new one. The caller holds the write lock.
|
|
492
|
+
*/
|
|
493
|
+
export const putBack = (context, identity, holder, author) => {
|
|
494
|
+
const { database } = context;
|
|
495
|
+
const at = context.now();
|
|
496
|
+
const log = { author, reason: "a mail sorting rule was removed", at };
|
|
497
|
+
if (holder.startsWith(SENDER_BOT_PREFIX)) {
|
|
498
|
+
const kept = Number(holder.slice(SENDER_BOT_PREFIX.length));
|
|
499
|
+
const bot = database.prepare("SELECT 1 FROM sender_bots WHERE id = ?").get(kept) === undefined
|
|
500
|
+
? createBot(database, log)
|
|
501
|
+
: kept;
|
|
502
|
+
for (const [person, gone] of intoBot(database, [identity], bot, log))
|
|
503
|
+
if (identitiesOf(database, person).length > 0)
|
|
504
|
+
renameAfterLeaving(context, person, gone);
|
|
505
|
+
groupByDomain(database, [{ id: bot, displayName: null, holds: true, bot: true }], at);
|
|
506
|
+
return;
|
|
507
|
+
}
|
|
508
|
+
const person = Number(holder.slice("person:".length));
|
|
509
|
+
const target = database.prepare("SELECT 1 FROM persons WHERE id = ?").get(person) === undefined
|
|
510
|
+
? undefined
|
|
511
|
+
: currentPerson(database, person);
|
|
512
|
+
outOfBot(database, [identity], target, log);
|
|
513
|
+
releaseDomainHolds(database, [identity]);
|
|
514
|
+
};
|
|
@@ -9,9 +9,9 @@ import { iso, isoDate, limitOf, oneOf, reasonOf, refuse, reviewedRowsOver, text,
|
|
|
9
9
|
import { pageOfRows } from "./rows-page.js";
|
|
10
10
|
import { write } from "./transaction.js";
|
|
11
11
|
const SUBSCRIPTIONS = "SELECT s.*, b.name AS author_name, b.kind AS author_kind FROM subscriptions s " +
|
|
12
|
-
"LEFT JOIN bots b ON s.author_type = '
|
|
12
|
+
"LEFT JOIN bots b ON s.author_type = 'agent' AND b.id = s.author_id";
|
|
13
13
|
const PRICES = "SELECT p.*, b.name AS author_name, b.kind AS author_kind FROM subscription_prices p " +
|
|
14
|
-
"LEFT JOIN bots b ON p.author_type = '
|
|
14
|
+
"LEFT JOIN bots b ON p.author_type = 'agent' AND b.id = p.author_id";
|
|
15
15
|
const PRICE_REF = /^subscription_price:([1-9]\d{0,15})$/;
|
|
16
16
|
export const subscriptionOperationsOver = (context) => {
|
|
17
17
|
const { database, now } = context;
|
|
@@ -44,7 +44,7 @@ export const saveAgentClose = (database, change, now) => {
|
|
|
44
44
|
export const closeSuggestionOf = (database, row) => {
|
|
45
45
|
if (row.close_suggested_as == null)
|
|
46
46
|
return null;
|
|
47
|
-
const name = row.close_suggested_by_type === "
|
|
47
|
+
const name = row.close_suggested_by_type === "agent"
|
|
48
48
|
? database.prepare("SELECT name FROM bots WHERE id = ?").get(Number(row.close_suggested_by_id))?.name
|
|
49
49
|
: "owner";
|
|
50
50
|
return {
|
|
@@ -4,7 +4,7 @@ export const authorNamed = (database, row) => {
|
|
|
4
4
|
if (row.author_type == null)
|
|
5
5
|
return null;
|
|
6
6
|
const named = database
|
|
7
|
-
.prepare(row.author_type === "
|
|
7
|
+
.prepare(row.author_type === "agent"
|
|
8
8
|
? "SELECT name, 0 AS owner FROM bots WHERE id = ?"
|
|
9
9
|
: "SELECT name, owner FROM persons WHERE id = ?")
|
|
10
10
|
.get(Number(row.author_id));
|
|
@@ -14,7 +14,7 @@ const REFERABLE = {
|
|
|
14
14
|
task: { tombstone: true },
|
|
15
15
|
memory: { tombstone: true },
|
|
16
16
|
fact: { tombstone: true },
|
|
17
|
-
|
|
17
|
+
agent: { tombstone: false },
|
|
18
18
|
event: { tombstone: true },
|
|
19
19
|
message: { tombstone: true },
|
|
20
20
|
email: { tombstone: true },
|
|
@@ -29,6 +29,11 @@ export declare const write: <T>(database: CacheDatabase, body: () => T, { before
|
|
|
29
29
|
* process's `write` a gap of microseconds, and it misses that gap until its 5 s wait runs out.
|
|
30
30
|
*/
|
|
31
31
|
export declare const writeBatch: <T>(database: CacheDatabase, body: () => T) => T;
|
|
32
|
+
/**
|
|
33
|
+
* A short pause between two writes of one loop: another process waiting for the lock tries every millisecond, and a
|
|
34
|
+
* loop that begins again at once leaves it a gap of microseconds, so it waits out its 5 s however short each write is.
|
|
35
|
+
*/
|
|
36
|
+
export declare const letWaitersIn: () => void;
|
|
32
37
|
/** Whether a dry run holds a connection of this process now. */
|
|
33
38
|
export declare const rehearsing: () => boolean;
|
|
34
39
|
/** Calls `call` outside any dry run: a statement it runs is refused while one holds the connection. */
|
|
@@ -72,6 +72,11 @@ export const write = (database, body, { beforeCommit } = {}) => transact(databas
|
|
|
72
72
|
*/
|
|
73
73
|
export const writeBatch = (database, body) => transact(database, body, false);
|
|
74
74
|
const BATCH_PAUSE_MS = 2;
|
|
75
|
+
/**
|
|
76
|
+
* A short pause between two writes of one loop: another process waiting for the lock tries every millisecond, and a
|
|
77
|
+
* loop that begins again at once leaves it a gap of microseconds, so it waits out its 5 s however short each write is.
|
|
78
|
+
*/
|
|
79
|
+
export const letWaitersIn = () => void Atomics.wait(pause, 0, 0, BATCH_PAUSE_MS);
|
|
75
80
|
const transact = (database, body, drain, beforeCommit) => {
|
|
76
81
|
const connection = connectionOf(database);
|
|
77
82
|
if (connection.reading)
|
|
@@ -100,7 +105,7 @@ const transact = (database, body, drain, beforeCommit) => {
|
|
|
100
105
|
// A write that had to wait has others waiting behind it, and its caller's next write would begin before they see
|
|
101
106
|
// the lock free. Pausing only then costs an uncontended write nothing.
|
|
102
107
|
if (outer && (waited || !drain))
|
|
103
|
-
|
|
108
|
+
letWaitersIn();
|
|
104
109
|
return result;
|
|
105
110
|
}
|
|
106
111
|
catch (error) {
|
|
@@ -7,7 +7,7 @@ import { iso, isoDate, limitOf, oneOf, refuse, reviewedRowsOver, text, } from ".
|
|
|
7
7
|
import { pageOfRows } from "./rows-page.js";
|
|
8
8
|
import { write } from "./transaction.js";
|
|
9
9
|
const WALLETS = "SELECT w.*, b.name AS author_name, b.kind AS author_kind FROM financial_accounts w " +
|
|
10
|
-
"LEFT JOIN bots b ON w.author_type = '
|
|
10
|
+
"LEFT JOIN bots b ON w.author_type = 'agent' AND b.id = w.author_id";
|
|
11
11
|
const SIGNED = "CASE t.direction WHEN 'in' THEN t.amount ELSE -t.amount END";
|
|
12
12
|
export const walletOperationsOver = (context) => {
|
|
13
13
|
const { database, now } = context;
|
|
@@ -645,9 +645,9 @@ export const workTaskOperationsOver = (context) => {
|
|
|
645
645
|
comments: async (id) => commentsOf(database, required(id)),
|
|
646
646
|
events: async (id) => database
|
|
647
647
|
.prepare("SELECT e.actor_type, e.actor_id, e.kind, e.changes, e.created_at, " +
|
|
648
|
-
"CASE e.actor_type WHEN 'person' THEN p.name WHEN '
|
|
648
|
+
"CASE e.actor_type WHEN 'person' THEN p.name WHEN 'agent' THEN b.name END AS actor_name FROM task_events e " +
|
|
649
649
|
"LEFT JOIN persons p ON e.actor_type = 'person' AND p.id = e.actor_id " +
|
|
650
|
-
"LEFT JOIN bots b ON e.actor_type = '
|
|
650
|
+
"LEFT JOIN bots b ON e.actor_type = 'agent' AND b.id = e.actor_id WHERE e.task_id = ? ORDER BY e.id")
|
|
651
651
|
.all(required(id))
|
|
652
652
|
.map((row) => ({
|
|
653
653
|
kind: row.kind,
|
package/dist/tracker/tasks.js
CHANGED
|
@@ -73,13 +73,15 @@ const PICKED = "tracker:owner-picks";
|
|
|
73
73
|
*/
|
|
74
74
|
const lastClose = async (store, id) => {
|
|
75
75
|
const statuses = (await store.tasks.events(id)).filter((event) => event.kind === "status");
|
|
76
|
-
const at = statuses.findLastIndex((event) => event.actor?.type === "
|
|
76
|
+
const at = statuses.findLastIndex((event) => event.actor?.type === "agent" &&
|
|
77
|
+
event.actor.name === SYNC.bot &&
|
|
78
|
+
isClosedState(String(event.changes?.status?.[1])));
|
|
77
79
|
if (at < 0)
|
|
78
80
|
return undefined;
|
|
79
81
|
const from = statuses[at]?.changes?.status?.[0];
|
|
80
82
|
return {
|
|
81
83
|
from: typeof from === "string" && !isClosedState(from) ? from : "open",
|
|
82
|
-
owner: statuses.slice(at + 1).find((event) => event.actor?.type !== "
|
|
84
|
+
owner: statuses.slice(at + 1).find((event) => event.actor?.type !== "agent")?.at,
|
|
83
85
|
};
|
|
84
86
|
};
|
|
85
87
|
/**
|