@wirecat/cli-core 0.662.0 → 0.663.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 +88 -0
- package/dist/background/daily-archive-timer.d.ts +1 -1
- package/dist/calendar/cli/bodies.js +2 -1
- package/dist/calendar/cli/index.js +13 -10
- package/dist/calendar/mcp/index.d.ts +3 -1
- package/dist/calendar/mcp/index.js +4 -4
- package/dist/cli/call-stats-command.d.ts +18 -0
- package/dist/cli/call-stats-command.js +52 -0
- package/dist/cli/contract-templates.js +2 -0
- package/dist/cli/envelope.d.ts +0 -5
- package/dist/cli/envelope.js +25 -0
- package/dist/cli/index.d.ts +2 -1
- package/dist/cli/index.js +2 -1
- package/dist/cli/meeting-batch.d.ts +2 -1
- package/dist/cli/meeting-batch.js +7 -5
- package/dist/cli/meeting-preparation-command.js +5 -5
- package/dist/cli/meeting-preparation-read.d.ts +5 -5
- package/dist/cli/meeting-preparation-read.js +13 -21
- package/dist/cli/meeting-series-inventory-command.js +2 -2
- package/dist/cli/meeting-series-inventory-read.d.ts +2 -2
- package/dist/cli/meeting-series-inventory-read.js +7 -15
- package/dist/cli/messenger/admin-statistics-command.js +2 -2
- package/dist/cli/messenger/counters-command.js +2 -2
- package/dist/cli/messenger/media-archive-command.js +5 -4
- package/dist/cli/messenger/media-archive-move-command.js +1 -1
- package/dist/cli/messenger/media-archive-timer-command.js +5 -4
- package/dist/cli/messenger/metadata-command.js +3 -3
- package/dist/cli/messenger/rankings-command.js +3 -3
- package/dist/cli/messenger/tags-command.js +7 -2
- package/dist/cli/messenger/tasks-command.js +2 -2
- package/dist/cli/paging.d.ts +10 -0
- package/dist/cli/paging.js +29 -0
- package/dist/cli/runs/command.js +6 -4
- package/dist/cli/runs/search-command.js +9 -5
- package/dist/cli/schedule/schedule-command.js +1 -5
- package/dist/domain/moment.d.ts +29 -0
- package/dist/domain/moment.js +58 -0
- package/dist/domain/providers.d.ts +6 -4
- package/dist/domain/providers.js +10 -5
- package/dist/domain/send-time.d.ts +3 -4
- package/dist/domain/send-time.js +10 -24
- package/dist/entities/fields.d.ts +2 -2
- package/dist/entities/fields.js +2 -2
- package/dist/entities/index.d.ts +92 -1
- package/dist/entities/index.js +3 -2
- package/dist/entities/meeting.d.ts +1 -1
- package/dist/entities/meeting.js +1 -1
- package/dist/errors/reasons.js +0 -1
- package/dist/mail/cli/index.js +4 -2
- package/dist/mail/facts.d.ts +5 -2
- package/dist/mail/facts.js +6 -3
- package/dist/mail/index.d.ts +1 -1
- package/dist/mail/meeting-notes.js +1 -1
- package/dist/mail/probe.d.ts +5 -2
- package/dist/mail/probe.js +9 -5
- package/dist/mail/server-search.js +1 -1
- package/dist/mail/sync.js +1 -1
- package/dist/mcp/meeting-preparation.js +1 -1
- package/dist/mcp/meeting-series-inventory.js +1 -1
- package/dist/mcp/prompts.js +6 -9
- package/dist/meetings/call-answers.d.ts +106 -0
- package/dist/meetings/call-answers.js +171 -0
- package/dist/meetings/call-stats.d.ts +121 -0
- package/dist/meetings/call-stats.js +211 -0
- package/dist/meetings/calls.d.ts +76 -0
- package/dist/meetings/calls.js +78 -0
- package/dist/meetings/cli/index.d.ts +8 -0
- package/dist/meetings/cli/index.js +10 -22
- package/dist/meetings/cli/search.d.ts +9 -2
- package/dist/meetings/cli/search.js +16 -26
- package/dist/meetings/index.d.ts +3 -0
- package/dist/meetings/index.js +3 -0
- package/dist/meetings/mcp/index.d.ts +6 -3
- package/dist/meetings/mcp/index.js +2 -4
- package/dist/meetings/mcp/search.d.ts +6 -1
- package/dist/meetings/mcp/search.js +3 -3
- package/dist/meetings/read-through.d.ts +2 -1
- package/dist/meetings/read-through.js +10 -1
- package/dist/meetings/stats.d.ts +3 -0
- package/dist/meetings/stats.js +3 -3
- package/dist/meetings/testing/index.d.ts +1 -0
- package/dist/meetings/testing/index.js +1 -0
- package/dist/meetings/testing/paging.d.ts +6 -0
- package/dist/meetings/testing/paging.js +5 -0
- package/dist/moderation/rules.d.ts +2 -0
- package/dist/moderation/rules.js +16 -2
- package/dist/search/fusion.d.ts +17 -0
- package/dist/search/fusion.js +17 -0
- package/dist/search/lucene/resolved.d.ts +2 -0
- package/dist/search/question-plan.d.ts +2 -0
- package/dist/search/question-plan.js +5 -0
- package/dist/search/service-query.d.ts +6 -1
- package/dist/search/service-query.js +9 -1
- package/dist/services/agenda-mail.js +2 -1
- package/dist/services/agenda.js +5 -3
- package/dist/services/attachments.js +4 -2
- package/dist/services/call-stats.d.ts +17 -0
- package/dist/services/call-stats.js +41 -0
- package/dist/services/chats.js +4 -2
- package/dist/services/conversations.js +4 -2
- package/dist/services/deps.d.ts +1 -1
- package/dist/services/document-source.d.ts +1 -1
- package/dist/services/document-source.js +4 -3
- package/dist/services/documents/ingestion.js +11 -40
- package/dist/services/documents/plan.d.ts +1 -1
- package/dist/services/documents/plan.js +30 -17
- package/dist/services/documents/ports.d.ts +5 -0
- package/dist/services/documents/sync.js +1 -1
- package/dist/services/embeddings-search.js +20 -4
- package/dist/services/events-search.js +2 -1
- package/dist/services/index.d.ts +1 -0
- package/dist/services/index.js +1 -0
- package/dist/services/mail-search.d.ts +1 -1
- package/dist/services/mail-search.js +10 -11
- package/dist/services/media-archive-move.js +2 -4
- package/dist/services/media-archive.d.ts +0 -1
- package/dist/services/media-archive.js +2 -12
- package/dist/services/meeting-combined.js +1 -1
- package/dist/services/messages-combined.js +15 -4
- package/dist/services/moderation.js +10 -2
- package/dist/services/moment.d.ts +4 -10
- package/dist/services/moment.js +16 -44
- package/dist/services/notes-search.d.ts +0 -2
- package/dist/services/notes-search.js +1 -2
- package/dist/services/search-all.js +2 -1
- package/dist/services/tags.js +4 -2
- package/dist/services/task-stats.js +2 -2
- package/dist/services/tasks.js +2 -2
- package/dist/store/accounts.js +2 -1
- package/dist/store/sqlite/account-purge.d.ts +3 -0
- package/dist/store/sqlite/account-purge.js +143 -0
- package/dist/store/sqlite/accounts.d.ts +0 -2
- package/dist/store/sqlite/accounts.js +2 -134
- package/dist/store/sqlite/calendar.d.ts +1 -0
- package/dist/store/sqlite/calendar.js +5 -5
- package/dist/store/sqlite/catalog.js +2 -16
- package/dist/store/sqlite/chats.js +2 -1
- package/dist/store/sqlite/context-document-source.d.ts +3 -3
- package/dist/store/sqlite/context-document-source.js +9 -7
- package/dist/store/sqlite/context-evidence.js +9 -3
- package/dist/store/sqlite/document-listing.js +2 -1
- package/dist/store/sqlite/events.js +2 -1
- package/dist/store/sqlite/file-note.d.ts +6 -0
- package/dist/store/sqlite/file-note.js +15 -0
- package/dist/store/sqlite/files.d.ts +3 -2
- package/dist/store/sqlite/files.js +5 -3
- package/dist/store/sqlite/identities.js +2 -1
- package/dist/store/sqlite/imported-documents.js +2 -2
- package/dist/store/sqlite/knowledge.js +19 -19
- package/dist/store/sqlite/lucene-fields.js +8 -12
- package/dist/store/sqlite/mail-rules.js +2 -1
- package/dist/store/sqlite/meeting-calls.d.ts +4 -0
- package/dist/store/sqlite/meeting-calls.js +66 -0
- package/dist/store/sqlite/meetings.d.ts +2 -2
- package/dist/store/sqlite/meetings.js +4 -1
- package/dist/store/sqlite/mention-sources.js +2 -1
- package/dist/store/sqlite/mentions.js +2 -2
- package/dist/store/sqlite/messages.js +6 -1
- package/dist/store/sqlite/note-search.js +8 -11
- package/dist/store/sqlite/notes.d.ts +2 -0
- package/dist/store/sqlite/notes.js +24 -13
- package/dist/store/sqlite/organizations.js +2 -2
- package/dist/store/sqlite/people-list.js +3 -3
- package/dist/store/sqlite/query-filter.d.ts +3 -3
- package/dist/store/sqlite/query-filter.js +3 -3
- package/dist/store/sqlite/reads.d.ts +4 -4
- package/dist/store/sqlite/reads.js +4 -4
- package/dist/store/sqlite/search.js +11 -7
- package/dist/store/sqlite/test-accounts.js +1 -1
- package/dist/store/sqlite/trigram-match.d.ts +9 -0
- package/dist/store/sqlite/trigram-match.js +28 -0
- package/dist/store/sqlite/work-tasks.js +1 -1
- package/package.json +3 -3
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { CliError } from "@wirecat/cli-base";
|
|
2
|
-
import { defineQuery, validateQuery, walkQuery } from "@wirecat/cli-base/query";
|
|
2
|
+
import { defineQuery, timezoneOf, validateQuery, walkQuery, } from "@wirecat/cli-base/query";
|
|
3
3
|
import { normalizeTag } from "../../domain/tags.js";
|
|
4
4
|
import { fold } from "../normalize.js";
|
|
5
5
|
import { syncFile } from "./files.js";
|
|
@@ -78,17 +78,6 @@ export const catalogStoreOver = ({ database, now }) => {
|
|
|
78
78
|
throw new CliError("not_found", "catalog account is not in the local store");
|
|
79
79
|
return Number(id);
|
|
80
80
|
};
|
|
81
|
-
const bound = (id, includeInactive = false) => {
|
|
82
|
-
const scope = "account_id = ? AND json_type(metadata, '$.catalog') = 'object'" +
|
|
83
|
-
(includeInactive ? "" : " AND json_extract(metadata, '$.catalog.active') = 1 AND deleted_at IS NULL");
|
|
84
|
-
const budget = database
|
|
85
|
-
.prepare(`SELECT count(*) AS entries, sum(length(metadata)) AS bytes FROM documents WHERE ${scope}`)
|
|
86
|
-
.get(id);
|
|
87
|
-
if (Number(budget?.bytes ?? 0) > 32 * 1024 * 1024)
|
|
88
|
-
throw new CliError("validation_error", "catalog scope exceeds its metadata budget");
|
|
89
|
-
if (Number(budget?.entries ?? 0) > 10000)
|
|
90
|
-
throw new CliError("validation_error", "catalog scope exceeds 10000 entries");
|
|
91
|
-
};
|
|
92
81
|
return {
|
|
93
82
|
upsert: async (accountId, inputs) => {
|
|
94
83
|
const id = account(accountId);
|
|
@@ -177,8 +166,6 @@ export const catalogStoreOver = ({ database, now }) => {
|
|
|
177
166
|
},
|
|
178
167
|
reconcile: async (accountId, externalIds) => {
|
|
179
168
|
const id = account(accountId);
|
|
180
|
-
if (externalIds.length > 10000)
|
|
181
|
-
throw new CliError("validation_error", "catalog scope exceeds 10000 entries");
|
|
182
169
|
const current = [...new Set(externalIds.map((key) => field(key)))];
|
|
183
170
|
return write(database, () => {
|
|
184
171
|
const retired = database
|
|
@@ -265,11 +252,10 @@ export const catalogStoreOver = ({ database, now }) => {
|
|
|
265
252
|
person: { where: person },
|
|
266
253
|
tag: { where: (node) => ({ sql: `EXISTS(${tagSql})`, params: [tag(node.value)] }) },
|
|
267
254
|
};
|
|
268
|
-
const compiled = queryFilter(ast, columns);
|
|
255
|
+
const compiled = queryFilter(ast, columns, { zone: timezoneOf() });
|
|
269
256
|
if (compiled.sql)
|
|
270
257
|
add(compiled.sql, ...compiled.params);
|
|
271
258
|
}
|
|
272
|
-
bound(id, query.includeInactive);
|
|
273
259
|
const found = database
|
|
274
260
|
.prepare(`SELECT d.id, d.external_id, d.title, d.front_matter, d.metadata, d.deleted_at, d.body IS NOT NULL AS has_body FROM documents d WHERE ${clauses.join(" AND ")} ORDER BY d.external_id LIMIT ? OFFSET ?`)
|
|
275
261
|
.all(...params, limit + 1, offset);
|
|
@@ -7,6 +7,7 @@ import { identityPk } from "./identities.js";
|
|
|
7
7
|
import { bound } from "./query-filter.js";
|
|
8
8
|
import { chatEventPeople, chatEvents, chatMembers, chats, chunks, fetchLeases, identities, involvements, memberCounts, memberObservationMembers, memberObservations, memberStays, messageReactions, messageRevisions, messages, messageTranscripts, pollVotes, syncRanges, } from "./schema.js";
|
|
9
9
|
import { ensureTag } from "./tags.js";
|
|
10
|
+
import { trigramPart } from "./trigram-match.js";
|
|
10
11
|
import { parsed, present, toIso, toMs } from "./values.js";
|
|
11
12
|
import { dropUnusedVectors } from "./vector-index.js";
|
|
12
13
|
/** The chat's own id, when the store key is a chat of this account. */
|
|
@@ -379,7 +380,7 @@ export const CHAT_COLUMNS = {
|
|
|
379
380
|
? { sql: "chats.title IS NOT NULL AND chats.title <> ''", params: [] }
|
|
380
381
|
: {
|
|
381
382
|
sql: "chats.id IN (SELECT rowid FROM chats_fts WHERE chats_fts MATCH ?)",
|
|
382
|
-
params: [
|
|
383
|
+
params: [trigramPart(titlePart(node.value))],
|
|
383
384
|
},
|
|
384
385
|
},
|
|
385
386
|
kind: { type: "enum", sql: "chats.kind" },
|
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
export declare const contextDocumentTime: string;
|
|
2
|
-
export declare const contextDocumentTimeKind: string;
|
|
3
|
-
export declare const contextDocumentUrl: string;
|
|
1
|
+
export declare const contextDocumentTime: () => string;
|
|
2
|
+
export declare const contextDocumentTimeKind: () => string;
|
|
3
|
+
export declare const contextDocumentUrl: () => string;
|
|
@@ -1,13 +1,15 @@
|
|
|
1
|
+
import { documentAccountProvidersSql } from "../../domain/providers.js";
|
|
1
2
|
import { PREFERRED_FILE } from "./files.js";
|
|
3
|
+
// Rendered per query: a documents provider joins the registry when its CLI opens the store, after this module loads.
|
|
2
4
|
// A document's preferred file holds its link and edit time; rows without one keep them in front matter.
|
|
3
|
-
const
|
|
4
|
-
const field = (name) => `CASE WHEN (${
|
|
5
|
+
const remote = () => `CASE WHEN json_valid(n.front_matter) THEN json_extract(n.front_matter,'$.source') IN (${documentAccountProvidersSql()}) ELSE 0 END`;
|
|
6
|
+
const field = (name) => `CASE WHEN (${remote()}) THEN
|
|
5
7
|
CASE WHEN json_type(n.front_matter,'$.${name}')='text' THEN json_extract(n.front_matter,'$.${name}') END END`;
|
|
6
8
|
const preferred = (column) => `(SELECT f.${column} FROM files f JOIN documents d ON d.id = f.document_id WHERE f.document_id = n.id
|
|
7
9
|
ORDER BY ${PREFERRED_FILE} LIMIT 1)`;
|
|
8
|
-
const modified = `round(unixepoch(${field("modifiedAt")},'subsec')*1000)`;
|
|
9
|
-
const remoteTime = `coalesce(${preferred("external_updated_at")},n.external_updated_at,${modified})`;
|
|
10
|
-
export const contextDocumentTime = `coalesce(${remoteTime},n.updated_at)`;
|
|
11
|
-
export const contextDocumentTimeKind = `CASE WHEN (${remoteTime}) IS NOT NULL
|
|
10
|
+
const modified = () => `round(unixepoch(${field("modifiedAt")},'subsec')*1000)`;
|
|
11
|
+
const remoteTime = () => `coalesce(${preferred("external_updated_at")},n.external_updated_at,${modified()})`;
|
|
12
|
+
export const contextDocumentTime = () => `coalesce(${remoteTime()},n.updated_at)`;
|
|
13
|
+
export const contextDocumentTimeKind = () => `CASE WHEN (${remoteTime()}) IS NOT NULL
|
|
12
14
|
THEN 'source-modified' ELSE 'stored-update' END`;
|
|
13
|
-
export const contextDocumentUrl = `coalesce(${preferred("url")},n.url,${field("sourceUrl")})`;
|
|
15
|
+
export const contextDocumentUrl = () => `coalesce(${preferred("url")},n.url,${field("sourceUrl")})`;
|
|
@@ -45,11 +45,17 @@ const corpora = {
|
|
|
45
45
|
index: "document_words",
|
|
46
46
|
title: "n.title",
|
|
47
47
|
body: "n.body",
|
|
48
|
-
url
|
|
49
|
-
|
|
48
|
+
get url() {
|
|
49
|
+
return contextDocumentUrl();
|
|
50
|
+
},
|
|
51
|
+
get at() {
|
|
52
|
+
return contextDocumentTime();
|
|
53
|
+
},
|
|
50
54
|
revision: "n.revision",
|
|
51
55
|
chat: "NULL",
|
|
52
|
-
timeKind
|
|
56
|
+
get timeKind() {
|
|
57
|
+
return contextDocumentTimeKind();
|
|
58
|
+
},
|
|
53
59
|
join: "",
|
|
54
60
|
where: "n.body IS NOT NULL AND CASE WHEN json_valid(n.metadata) THEN coalesce(json_extract(n.metadata, '$.catalog.active'),1) ELSE 1 END=1",
|
|
55
61
|
chats: null,
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { CliError } from "@wirecat/cli-base";
|
|
2
|
+
import { timezoneOf } from "@wirecat/cli-base/query";
|
|
2
3
|
import { normalizeTag } from "../../domain/tags.js";
|
|
3
4
|
import { PREFERRED_FILE, subtreeOf } from "./files.js";
|
|
4
5
|
import { accountOf } from "./meeting-listing.js";
|
|
@@ -183,7 +184,7 @@ const treeOf = (paths, depth) => {
|
|
|
183
184
|
};
|
|
184
185
|
export const documentListingOver = (context) => {
|
|
185
186
|
const { database } = context;
|
|
186
|
-
const whereOf = (query, zone, now) => query && queryFilter(query, columns(context), {
|
|
187
|
+
const whereOf = (query, zone, now) => query && queryFilter(query, columns(context), { zone: timezoneOf(zone), ...(now ? { now } : {}) });
|
|
187
188
|
return {
|
|
188
189
|
documentAccounts: async () => database
|
|
189
190
|
.prepare(`SELECT id, provider, external_id, name FROM accounts WHERE id IN (SELECT d.account_id FROM documents d ` +
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { timezoneOf } from "@wirecat/cli-base/query";
|
|
1
2
|
import { joinKeyOf, } from "../../meetings/index.js";
|
|
2
3
|
import { queryFilter } from "./query-filter.js";
|
|
3
4
|
import { write } from "./transaction.js";
|
|
@@ -51,7 +52,7 @@ export const events = (database, query) => {
|
|
|
51
52
|
ends_at: { type: "time", sql: "ends_at" },
|
|
52
53
|
created_at: { type: "time", sql: "created_at" },
|
|
53
54
|
updated_at: { type: "time", sql: "updated_at" },
|
|
54
|
-
});
|
|
55
|
+
}, { zone: timezoneOf() });
|
|
55
56
|
return database
|
|
56
57
|
.prepare(`SELECT * FROM events WHERE deleted_at IS NULL${where ? ` AND (${where.sql})` : ""} ORDER BY id`)
|
|
57
58
|
.all(...(where?.params ?? []))
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import type { CacheDatabase } from "../driver.js";
|
|
2
|
+
/**
|
|
3
|
+
* The document row of the live file at `path` in an account, shaped as `notes({ folderId })` lists it. A local folder
|
|
4
|
+
* names its files by their own path; any other account by its document's key.
|
|
5
|
+
*/
|
|
6
|
+
export declare const fileNoteRow: (database: CacheDatabase, account: number, local: boolean, path: string) => Record<string, unknown> | undefined;
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
const LIVE = "f.deleted_at IS NULL AND d.deleted_at IS NULL AND coalesce(json_extract(d.metadata, '$.catalog.active'), 1)=1";
|
|
2
|
+
/**
|
|
3
|
+
* The document row of the live file at `path` in an account, shaped as `notes({ folderId })` lists it. A local folder
|
|
4
|
+
* names its files by their own path; any other account by its document's key.
|
|
5
|
+
*/
|
|
6
|
+
export const fileNoteRow = (database, account, local, path) => database
|
|
7
|
+
.prepare(local
|
|
8
|
+
? "SELECT d.*, f.account_id AS account_id, f.external_id AS external_id, " +
|
|
9
|
+
"coalesce(f.external_updated_at, d.external_updated_at) AS external_updated_at FROM files f " +
|
|
10
|
+
`JOIN documents d ON d.id = f.document_id WHERE f.account_id = ? AND f.external_id = ? AND ${LIVE} ` +
|
|
11
|
+
"ORDER BY d.created_at, d.id LIMIT 1"
|
|
12
|
+
: "SELECT d.*, f.account_id AS account_id, coalesce(f.external_updated_at, d.external_updated_at) AS " +
|
|
13
|
+
"external_updated_at FROM documents d JOIN files f ON f.document_id = d.id AND f.account_id = d.account_id " +
|
|
14
|
+
`WHERE d.account_id = ? AND d.external_id = ? AND ${LIVE} LIMIT 1`)
|
|
15
|
+
.get(account, path);
|
|
@@ -20,8 +20,9 @@ export declare const driveFileTarget: (fileId: string) => string;
|
|
|
20
20
|
/** The document of the Drive file with this id; `null` when no Drive account holds it, or two do. */
|
|
21
21
|
export declare const driveDocumentOf: (database: CacheDatabase, fileId: string) => number | null;
|
|
22
22
|
/**
|
|
23
|
-
* Writes the `files` row of one document from the document as it is now: the document's source record. A
|
|
24
|
-
* document (catalog metadata or
|
|
23
|
+
* Writes the `files` row of one document from the document as it is now: the document's source record. A documents
|
|
24
|
+
* provider's document (catalog metadata, or front matter whose `source` names the provider) is keyed by its file id
|
|
25
|
+
* (`fileId` in the front matter, else its own key) and placed under its first parent;
|
|
25
26
|
* a local one by its path, under folder rows made from that path. `seen` marks a sync or import that returned it.
|
|
26
27
|
* `place` names a local file of the document other than the one its own columns name: a copy in another folder.
|
|
27
28
|
*/
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { CliError } from "@wirecat/cli-base";
|
|
2
|
+
import { isDocumentAccountProvider } from "../../domain/providers.js";
|
|
2
3
|
import { fold } from "../normalize.js";
|
|
3
4
|
import { write, writeBatch } from "./transaction.js";
|
|
4
5
|
const isObject = (value) => value !== null && typeof value === "object" && !Array.isArray(value);
|
|
@@ -79,8 +80,9 @@ const movePaths = (database, accountId, from, to) => {
|
|
|
79
80
|
.run(to, from.length + 1, accountId, from.length + 1, `${from}/`);
|
|
80
81
|
};
|
|
81
82
|
/**
|
|
82
|
-
* Writes the `files` row of one document from the document as it is now: the document's source record. A
|
|
83
|
-
* document (catalog metadata or
|
|
83
|
+
* Writes the `files` row of one document from the document as it is now: the document's source record. A documents
|
|
84
|
+
* provider's document (catalog metadata, or front matter whose `source` names the provider) is keyed by its file id
|
|
85
|
+
* (`fileId` in the front matter, else its own key) and placed under its first parent;
|
|
84
86
|
* a local one by its path, under folder rows made from that path. `seen` marks a sync or import that returned it.
|
|
85
87
|
* `place` names a local file of the document other than the one its own columns name: a copy in another folder.
|
|
86
88
|
*/
|
|
@@ -93,7 +95,7 @@ export const syncFile = (database, now, documentId, { seen = true, depth = 0, pl
|
|
|
93
95
|
const catalog = place ? undefined : objectOf(objectOf(doc.metadata)?.catalog);
|
|
94
96
|
const provider = database.prepare("SELECT provider FROM accounts WHERE id = ?").get(accountId)?.provider;
|
|
95
97
|
// A vault file may carry an exported Drive file's front matter and still be a file on disk.
|
|
96
|
-
const remote = catalog !== undefined || (front?.source
|
|
98
|
+
const remote = catalog !== undefined || (isDocumentAccountProvider(front?.source) && !LOCAL.has(String(provider)));
|
|
97
99
|
const externalId = (remote && stringOf(front?.fileId)) || (place?.path ?? String(doc.external_id));
|
|
98
100
|
const kind = doc.kind === "folder" ? "folder" : doc.kind === "page" ? "page" : "file";
|
|
99
101
|
let name;
|
|
@@ -7,6 +7,7 @@ import { holdingText } from "./note-index.js";
|
|
|
7
7
|
import { resolvePersonLinks } from "./person-resolution.js";
|
|
8
8
|
import { bound } from "./query-filter.js";
|
|
9
9
|
import { accountIdentities, accounts, aliases, chatMembers, chats, identities, identityLinkEvents, identityLinks, identityRevisions, messages, persons, } from "./schema.js";
|
|
10
|
+
import { trigramPart } from "./trigram-match.js";
|
|
10
11
|
import { toIso } from "./values.js";
|
|
11
12
|
/** The source's every phone and address as a JSON patch of `metadata`; `undefined` when it gave no list. */
|
|
12
13
|
const contactsOf = ({ phones, emails }) => {
|
|
@@ -244,7 +245,7 @@ const contactsWhere = (accountKey, key, { query, notes, email, phone }) => {
|
|
|
244
245
|
WHERE ${chatMembers.identityId} = ${identities.id} AND ${chats.accountId} = ${accountIdentities.accountId}
|
|
245
246
|
AND ${chats.kind} = 'dialog')`, query === undefined
|
|
246
247
|
? undefined
|
|
247
|
-
: sql `(${identities.id} IN (SELECT rowid FROM identities_fts WHERE identities_fts MATCH ${
|
|
248
|
+
: sql `(${identities.id} IN (SELECT rowid FROM identities_fts WHERE identities_fts MATCH ${trigramPart(query.trim())}) OR EXISTS (SELECT 1 FROM aliases ca WHERE ca.aliasable_type='identity' AND ca.display=1 AND ca.account_id=${accountKey} AND ca.aliasable_id=${identities.id} AND instr(ca.name_folded, ${fold(query.trim())}) > 0))`, notes === undefined
|
|
248
249
|
? undefined
|
|
249
250
|
: sql `EXISTS (SELECT 1 FROM notes n WHERE n.notable_type='identity' AND n.notable_id=${identities.id} AND n.deleted_at IS NULL${noted ? sql ` AND ${bound(noted)}` : sql ``})`, email === undefined
|
|
250
251
|
? undefined
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { defineQuery, validateQuery } from "@wirecat/cli-base/query";
|
|
1
|
+
import { defineQuery, timezoneOf, validateQuery } from "@wirecat/cli-base/query";
|
|
2
2
|
import { normalizeTag } from "../../domain/tags.js";
|
|
3
3
|
import { idsOf } from "./merged-persons.js";
|
|
4
4
|
import { queryFilter } from "./query-filter.js";
|
|
@@ -51,5 +51,5 @@ export const importedDocumentWhere = (database, query) => {
|
|
|
51
51
|
},
|
|
52
52
|
},
|
|
53
53
|
};
|
|
54
|
-
return queryFilter(validateQuery(query, IMPORTED_DOCUMENT_QUERY), columns);
|
|
54
|
+
return queryFilter(validateQuery(query, IMPORTED_DOCUMENT_QUERY), columns, { zone: timezoneOf() });
|
|
55
55
|
};
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { CliError } from "@wirecat/cli-base";
|
|
2
|
-
import { walkQuery } from "@wirecat/cli-base/query";
|
|
2
|
+
import { timezoneOf, walkQuery } from "@wirecat/cli-base/query";
|
|
3
3
|
import { parseLocator } from "../../domain/locator.js";
|
|
4
4
|
import { isBusinessType } from "../../domain/record-types.js";
|
|
5
5
|
import { formatReference, parseReference } from "../../domain/references.js";
|
|
@@ -64,6 +64,22 @@ const oneOf = (value, allowed, what) => {
|
|
|
64
64
|
/** What a relationship may connect; a deal or a lead only as the end its people hang from. */
|
|
65
65
|
const RELATED = ["person", "organization", "project", "task"];
|
|
66
66
|
const DEALS = ["deal", "lead"];
|
|
67
|
+
const PROJECT_COLUMNS = {
|
|
68
|
+
id: { type: "kw", sql: "CAST(id AS TEXT)" },
|
|
69
|
+
key: { type: "kw", sql: "key" },
|
|
70
|
+
name: { type: "kw", sql: "name_folded", folded: true },
|
|
71
|
+
kind: { type: "enum", sql: `CASE WHEN length(key) = ${INBOX_KEY_LENGTH} THEN 'inbox' ELSE 'project' END` },
|
|
72
|
+
type: { type: "enum", sql: "type" },
|
|
73
|
+
organization_id: { type: "kw", sql: "CAST(organization_id AS TEXT)" },
|
|
74
|
+
scope: { type: "enum", sql: "scope" },
|
|
75
|
+
created_at: { type: "time", sql: "created_at" },
|
|
76
|
+
};
|
|
77
|
+
const REMINDER_COLUMNS = {
|
|
78
|
+
id: { type: "kw", sql: "CAST(id AS TEXT)" },
|
|
79
|
+
state: { type: "enum", sql: "state" },
|
|
80
|
+
due_at: { type: "time", sql: "due_at" },
|
|
81
|
+
revision: { type: "num", sql: "revision" },
|
|
82
|
+
};
|
|
67
83
|
export const knowledgeStoreOver = (context) => {
|
|
68
84
|
const { database, now } = context;
|
|
69
85
|
const ids = (thing) => thing ? idsOf(database, thing.type, thing.id) : null;
|
|
@@ -455,17 +471,7 @@ export const knowledgeStoreOver = (context) => {
|
|
|
455
471
|
addProject: async (input) => write(database, () => projectOf(insertProject(context, input))),
|
|
456
472
|
projects: async (query) => {
|
|
457
473
|
const asksKind = query !== undefined && walkQuery(query.root).some((node) => node.field === "kind");
|
|
458
|
-
const where = query &&
|
|
459
|
-
queryFilter(query, {
|
|
460
|
-
id: { type: "kw", sql: "CAST(id AS TEXT)" },
|
|
461
|
-
key: { type: "kw", sql: "key" },
|
|
462
|
-
name: { type: "kw", sql: "name_folded", folded: true },
|
|
463
|
-
kind: { type: "enum", sql: `CASE WHEN length(key) = ${INBOX_KEY_LENGTH} THEN 'inbox' ELSE 'project' END` },
|
|
464
|
-
type: { type: "enum", sql: "type" },
|
|
465
|
-
organization_id: { type: "kw", sql: "CAST(organization_id AS TEXT)" },
|
|
466
|
-
scope: { type: "enum", sql: "scope" },
|
|
467
|
-
created_at: { type: "time", sql: "created_at" },
|
|
468
|
-
});
|
|
474
|
+
const where = query && queryFilter(query, PROJECT_COLUMNS, { zone: timezoneOf() });
|
|
469
475
|
return database
|
|
470
476
|
.prepare(`SELECT * FROM projects WHERE deleted_at IS NULL${asksKind ? "" : ` AND length(key) <> ${INBOX_KEY_LENGTH}`}${where ? ` AND (${where.sql})` : ""} ORDER BY name, id LIMIT 500`)
|
|
471
477
|
.all(...(where?.params ?? []))
|
|
@@ -579,13 +585,7 @@ export const knowledgeStoreOver = (context) => {
|
|
|
579
585
|
return reminder(key, String(made?.id));
|
|
580
586
|
},
|
|
581
587
|
reminders: async (key, query) => {
|
|
582
|
-
const where = query &&
|
|
583
|
-
queryFilter(query, {
|
|
584
|
-
id: { type: "kw", sql: "CAST(id AS TEXT)" },
|
|
585
|
-
state: { type: "enum", sql: "state" },
|
|
586
|
-
due_at: { type: "time", sql: "due_at" },
|
|
587
|
-
revision: { type: "num", sql: "revision" },
|
|
588
|
-
});
|
|
588
|
+
const where = query && queryFilter(query, REMINDER_COLUMNS, { zone: timezoneOf() });
|
|
589
589
|
return database
|
|
590
590
|
.prepare(`SELECT * FROM reminders WHERE account_id=?${where ? ` AND (${where.sql})` : ""} ORDER BY due_at, id LIMIT 500`)
|
|
591
591
|
.all(account(key), ...(where?.params ?? []))
|
|
@@ -13,6 +13,7 @@ import { fold, normalize } from "../normalize.js";
|
|
|
13
13
|
import { linkMatch } from "./mention-links.js";
|
|
14
14
|
import { valueMatch } from "./phone-countries.js";
|
|
15
15
|
import { canonicalTagNamed } from "./tags.js";
|
|
16
|
+
import { yoSpellings } from "./trigram-match.js";
|
|
16
17
|
/**
|
|
17
18
|
* A voice note's transcript is its attachment's text, whoever wrote it: speech recognition (`speech:<model>`) or an
|
|
18
19
|
* agent, which writes the text of a voice attachment as `agent`. The voice attachment is the one
|
|
@@ -181,17 +182,6 @@ const literalRuns = (value) => {
|
|
|
181
182
|
}
|
|
182
183
|
return runs.filter(Boolean);
|
|
183
184
|
};
|
|
184
|
-
const MOST_YO_SPELLINGS = 64;
|
|
185
|
-
/** Every spelling of `run` with each е or ё as either: the trigram index keeps the text as written. */
|
|
186
|
-
const yoSpellings = (run) => {
|
|
187
|
-
let spellings = [""];
|
|
188
|
-
for (const c of run) {
|
|
189
|
-
spellings = spellings.flatMap((start) => (c === "е" || c === "ё" ? [`${start}е`, `${start}ё`] : [`${start}${c}`]));
|
|
190
|
-
if (spellings.length > MOST_YO_SPELLINGS)
|
|
191
|
-
return undefined;
|
|
192
|
-
}
|
|
193
|
-
return spellings;
|
|
194
|
-
};
|
|
195
185
|
/**
|
|
196
186
|
* A pattern with no start to read the word list from (`*договор*`, `*ость`), in chat messages: the trigram index of
|
|
197
187
|
* their text finds where its longest part occurs, so a large store does not refuse it: the whole search took 0.5–1 s at
|
|
@@ -243,8 +233,14 @@ const words = (node, scope) => {
|
|
|
243
233
|
const terms = scope.database
|
|
244
234
|
.prepare(`SELECT term FROM ${corpus.vocab} WHERE col='normalized_text'${prefix ? " AND term>=? AND term<=?" : ""} ORDER BY term LIMIT ?`)
|
|
245
235
|
.all(...(prefix ? [prefix, `${prefix}\u{10ffff}`] : []), QUERY_LIMITS.expansions + 1);
|
|
246
|
-
if (scope.expand(terms.length) > QUERY_LIMITS.expansions)
|
|
236
|
+
if (scope.expand(terms.length) > QUERY_LIMITS.expansions) {
|
|
237
|
+
if (node.widened) {
|
|
238
|
+
scope.expand(-terms.length);
|
|
239
|
+
const { widened: _, ...typed } = node;
|
|
240
|
+
return words({ ...typed, operator: "term", value: node.value.replace(/\*$/u, "") }, scope);
|
|
241
|
+
}
|
|
247
242
|
tooManyWords(node, terms.length > QUERY_LIMITS.expansions, prefix, scope.mail);
|
|
243
|
+
}
|
|
248
244
|
const matches = terms.flatMap(({ term }) => {
|
|
249
245
|
scope.check();
|
|
250
246
|
return automaton.test(String(term), scope.budget) ? [quoted(String(term))] : [];
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { timezoneOf } from "@wirecat/cli-base/query";
|
|
1
2
|
import { queryFilter } from "./query-filter.js";
|
|
2
3
|
import { write } from "./transaction.js";
|
|
3
4
|
const sorted = (value) => Array.isArray(value)
|
|
@@ -30,7 +31,7 @@ export const mailRulesOver = (database) => ({
|
|
|
30
31
|
id: { type: "num", sql: "id" },
|
|
31
32
|
protected: { type: "bool", sql: "protected" },
|
|
32
33
|
source: { type: "kw", sql: "source" },
|
|
33
|
-
});
|
|
34
|
+
}, { zone: timezoneOf() });
|
|
34
35
|
return database
|
|
35
36
|
.prepare(`SELECT * FROM mail_rules WHERE account_id = ?${where ? ` AND (${where.sql})` : ""} ORDER BY id`)
|
|
36
37
|
.all(accountId, ...(where?.params ?? []))
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import type { MeetingCallsStore } from "../../meetings/index.js";
|
|
2
|
+
import type { StoreContext } from "./open.js";
|
|
3
|
+
/** The selected meetings with their metadata and people, through the same filters as meeting search and stats. */
|
|
4
|
+
export declare const meetingCallsOver: ({ database }: StoreContext) => MeetingCallsStore;
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
import { CliError } from "@wirecat/cli-base";
|
|
2
|
+
import { int, str } from "./events.js";
|
|
3
|
+
import { checkMeetingCancelled } from "./meeting-operation.js";
|
|
4
|
+
import { positiveReadInteger } from "./meeting-reads.js";
|
|
5
|
+
import { meetingSelectionSql } from "./meeting-selection.js";
|
|
6
|
+
import { read } from "./transaction.js";
|
|
7
|
+
const MOST_CALLS = 200_000;
|
|
8
|
+
// The store keeps what the provider wrote; one unreadable value must not fail the whole report.
|
|
9
|
+
const parsed = (value) => {
|
|
10
|
+
if (typeof value !== "string")
|
|
11
|
+
return null;
|
|
12
|
+
try {
|
|
13
|
+
return JSON.parse(value);
|
|
14
|
+
}
|
|
15
|
+
catch {
|
|
16
|
+
return null;
|
|
17
|
+
}
|
|
18
|
+
};
|
|
19
|
+
/** The selected meetings with their metadata and people, through the same filters as meeting search and stats. */
|
|
20
|
+
export const meetingCallsOver = ({ database }) => ({
|
|
21
|
+
async meetingCalls(input) {
|
|
22
|
+
checkMeetingCancelled(input.signal);
|
|
23
|
+
positiveReadInteger(input.accountId, "accountId");
|
|
24
|
+
const maxRows = input.maxRows ?? MOST_CALLS;
|
|
25
|
+
if (!Number.isSafeInteger(maxRows) || maxRows < 1 || maxRows > MOST_CALLS)
|
|
26
|
+
throw new CliError("validation_error", `call stats read 1 through ${MOST_CALLS} calls`);
|
|
27
|
+
return read(database, () => {
|
|
28
|
+
const { clauses, params } = meetingSelectionSql(input);
|
|
29
|
+
const meetings = database
|
|
30
|
+
.prepare(`SELECT m.id, m.started_at, coalesce(m.duration_ms, m.ended_at - m.started_at) AS duration_ms, m.metadata
|
|
31
|
+
FROM meetings m WHERE ${clauses.join(" AND ")} ORDER BY m.started_at, m.id LIMIT ?`)
|
|
32
|
+
.all(...params, maxRows + 1);
|
|
33
|
+
if (meetings.length > maxRows)
|
|
34
|
+
throw new CliError("validation_error", `the selection has more than ${maxRows} meetings; narrow it`);
|
|
35
|
+
checkMeetingCancelled(input.signal);
|
|
36
|
+
const people = new Map();
|
|
37
|
+
const rows = database
|
|
38
|
+
.prepare(`SELECT p.meeting_id, p.identity_id, i.external_id AS identity_key, p.role,
|
|
39
|
+
coalesce(p.display_name, i.name) AS name, p.external_id
|
|
40
|
+
FROM meeting_participants p JOIN identities i ON i.id = p.identity_id
|
|
41
|
+
WHERE p.meeting_id IN (SELECT m.id FROM meetings m WHERE ${clauses.join(" AND ")})
|
|
42
|
+
ORDER BY p.id`)
|
|
43
|
+
.all(...params);
|
|
44
|
+
for (const row of rows) {
|
|
45
|
+
const meetingId = Number(row.meeting_id);
|
|
46
|
+
people.set(meetingId, [
|
|
47
|
+
...(people.get(meetingId) ?? []),
|
|
48
|
+
{
|
|
49
|
+
identityId: Number(row.identity_id),
|
|
50
|
+
identityKey: String(row.identity_key),
|
|
51
|
+
role: str(row.role),
|
|
52
|
+
name: str(row.name),
|
|
53
|
+
externalId: str(row.external_id),
|
|
54
|
+
},
|
|
55
|
+
]);
|
|
56
|
+
}
|
|
57
|
+
return meetings.map((row) => ({
|
|
58
|
+
meetingId: Number(row.id),
|
|
59
|
+
startedAt: int(row.started_at),
|
|
60
|
+
durationMs: int(row.duration_ms),
|
|
61
|
+
metadata: parsed(row.metadata),
|
|
62
|
+
participants: people.get(Number(row.id)) ?? [],
|
|
63
|
+
}));
|
|
64
|
+
});
|
|
65
|
+
},
|
|
66
|
+
});
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { Attachment, MeetingChatLinesStore, MeetingContextStore, MeetingParticipantSearchStore, MeetingPreparationContextStore, MeetingPreparationKnowledgeStore, MeetingPreparationNotesStore, MeetingRelatedHistoryStore, MeetingReviewStore, MeetingSearchIndexStore, MeetingSearchStore, MeetingSeriesHistoryStore, MeetingStatsStore, MeetingStore, MeetingTranscriptDocumentStore, MeetingTranscriptReceiptStore, MeetingTranscriptStore, NewRecord } from "../../meetings/index.js";
|
|
1
|
+
import type { Attachment, MeetingCallsStore, MeetingChatLinesStore, MeetingContextStore, MeetingParticipantSearchStore, MeetingPreparationContextStore, MeetingPreparationKnowledgeStore, MeetingPreparationNotesStore, MeetingRelatedHistoryStore, MeetingReviewStore, MeetingSearchIndexStore, MeetingSearchStore, MeetingSeriesHistoryStore, MeetingStatsStore, MeetingStore, MeetingTranscriptDocumentStore, MeetingTranscriptReceiptStore, MeetingTranscriptStore, NewRecord } from "../../meetings/index.js";
|
|
2
2
|
import type { CacheDatabase } from "../driver.js";
|
|
3
3
|
import { type MeetingLanguageStore } from "./meeting-languages.js";
|
|
4
4
|
import { type MeetingContextReadCapabilities, type MeetingReadCapabilities } from "./meeting-reads.js";
|
|
@@ -12,7 +12,7 @@ export declare const saveAttachment: (database: CacheDatabase, type: string, par
|
|
|
12
12
|
export declare const drainMeetingIndex: (database: CacheDatabase, batch?: number) => number;
|
|
13
13
|
/** Each word of the query, as a prefix, all required. */
|
|
14
14
|
export declare const wordsQuery: (query: string) => string | null;
|
|
15
|
-
export type StoredMeetings = MeetingStore & MeetingPreparationContextStore & MeetingPreparationKnowledgeStore & MeetingPreparationNotesStore & MeetingRelatedHistoryStore & MeetingSeriesHistoryStore & MeetingTranscriptStore & MeetingReadCapabilities & MeetingContextReadCapabilities & MeetingParticipantSearchStore & MeetingSearchStore & MeetingTranscriptReceiptStore & MeetingContextStore & MeetingSearchIndexStore & MeetingStatsStore & MeetingReviewStore & MeetingChatLinesStore & MeetingLanguageStore & MeetingTranscriptDocumentStore;
|
|
15
|
+
export type StoredMeetings = MeetingStore & MeetingPreparationContextStore & MeetingPreparationKnowledgeStore & MeetingPreparationNotesStore & MeetingRelatedHistoryStore & MeetingSeriesHistoryStore & MeetingTranscriptStore & MeetingReadCapabilities & MeetingContextReadCapabilities & MeetingParticipantSearchStore & MeetingSearchStore & MeetingTranscriptReceiptStore & MeetingContextStore & MeetingSearchIndexStore & MeetingStatsStore & MeetingCallsStore & MeetingReviewStore & MeetingChatLinesStore & MeetingLanguageStore & MeetingTranscriptDocumentStore;
|
|
16
16
|
/** The `MeetingStore` of `src/meetings/` over the shared store. */
|
|
17
17
|
export declare const meetingStoreOver: (context: StoreContext) => StoredMeetings;
|
|
18
18
|
export {};
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { CliError } from "@wirecat/cli-base";
|
|
2
|
+
import { timezoneOf } from "@wirecat/cli-base/query";
|
|
2
3
|
import { formatMeetingReference, joinKeyOf, MeetingError } from "../../meetings/index.js";
|
|
3
4
|
import { normalize } from "../normalize.js";
|
|
4
5
|
import * as eventQueries from "./events.js";
|
|
@@ -6,6 +7,7 @@ import { fromJson, int, page, str, toJson } from "./events.js";
|
|
|
6
7
|
import { folded } from "./folded.js";
|
|
7
8
|
import { meetingIdentityPk } from "./identities.js";
|
|
8
9
|
import { reviewLink } from "./link-reviews.js";
|
|
10
|
+
import { meetingCallsOver } from "./meeting-calls.js";
|
|
9
11
|
import { meetingChatLinesOver } from "./meeting-chat-lines.js";
|
|
10
12
|
import { meetingContextLinksOver } from "./meeting-context-links.js";
|
|
11
13
|
import { attachListedDocument, attachTranscriptFile, meetingDocumentsOf, meetingTranscriptDocumentsOver, } from "./meeting-documents.js";
|
|
@@ -459,7 +461,7 @@ const filtered = (filter = {}) => {
|
|
|
459
461
|
if (filter.query !== undefined) {
|
|
460
462
|
const compiled = queryFilter(filter.query, MEETING_COLUMNS, {
|
|
461
463
|
command: "meetings list",
|
|
462
|
-
|
|
464
|
+
zone: timezoneOf(filter.timezone),
|
|
463
465
|
...(filter.now === undefined ? {} : { now: filter.now }),
|
|
464
466
|
});
|
|
465
467
|
where.push(`(${compiled.sql})`);
|
|
@@ -621,6 +623,7 @@ export const meetingStoreOver = (context) => {
|
|
|
621
623
|
...meetingRelatedHistoryOver(context),
|
|
622
624
|
...meetingHitSearchOver(context),
|
|
623
625
|
...meetingStatsOver(context),
|
|
626
|
+
...meetingCallsOver(context),
|
|
624
627
|
...meetingReviewOver(context),
|
|
625
628
|
...meetingChatLinesOver(context),
|
|
626
629
|
...meetingParticipantSearchOver(context),
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { CliError } from "@wirecat/cli-base";
|
|
2
|
+
import { timezoneOf } from "@wirecat/cli-base/query";
|
|
2
3
|
import { findAccountPk } from "./accounts.js";
|
|
3
4
|
import { candidatesOf, columnsOf, confirmMention, mentionOwner, rejectMention, } from "./mentions.js";
|
|
4
5
|
import { queryFilter } from "./query-filter.js";
|
|
@@ -67,7 +68,7 @@ export const sourceMentionStoreOver = (context) => {
|
|
|
67
68
|
const where = [scope.sql];
|
|
68
69
|
let params = scope.params;
|
|
69
70
|
if (query) {
|
|
70
|
-
const compiled = queryFilter(query, columnsOf(database));
|
|
71
|
+
const compiled = queryFilter(query, columnsOf(database), { zone: timezoneOf() });
|
|
71
72
|
if (compiled.sql) {
|
|
72
73
|
where.push(`AND (${compiled.sql}) `);
|
|
73
74
|
params = params.concat(compiled.params);
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { CliError } from "@wirecat/cli-base";
|
|
2
|
-
import { defineQuery } from "@wirecat/cli-base/query";
|
|
2
|
+
import { defineQuery, timezoneOf } from "@wirecat/cli-base/query";
|
|
3
3
|
import { MENTION_KINDS, siteOf } from "../../domain/mentions.js";
|
|
4
4
|
import { findNames, nameIndex } from "../../domain/person-names.js";
|
|
5
5
|
import { createStemmer } from "../../search/stem.js";
|
|
@@ -130,7 +130,7 @@ export const listMentions = (database, accountPk, query, { limit, offset, foundA
|
|
|
130
130
|
params.push(foundAfter);
|
|
131
131
|
}
|
|
132
132
|
if (query) {
|
|
133
|
-
const compiled = queryFilter(query, columnsOf(database));
|
|
133
|
+
const compiled = queryFilter(query, columnsOf(database), { zone: timezoneOf() });
|
|
134
134
|
if (compiled.sql) {
|
|
135
135
|
where.push(`(${compiled.sql})`);
|
|
136
136
|
params.push(...compiled.params);
|
|
@@ -188,8 +188,13 @@ export const upsertMessage = (context, key, accountKey, chatKey, received, via,
|
|
|
188
188
|
orm.update(messages).set({ text: message.text }).where(eq(messages.id, pk)).run();
|
|
189
189
|
purgeVectorsOf(context, pk);
|
|
190
190
|
}
|
|
191
|
+
// Saved anew for `changes`: a reader told it was deleted must hear that it is back.
|
|
191
192
|
if (revived)
|
|
192
|
-
orm
|
|
193
|
+
orm
|
|
194
|
+
.update(messages)
|
|
195
|
+
.set({ deletedAt: null, text: message.text, createdAt: now() })
|
|
196
|
+
.where(eq(messages.id, pk))
|
|
197
|
+
.run();
|
|
193
198
|
}
|
|
194
199
|
const derived = derivedReactions(context, chatKey, message.id);
|
|
195
200
|
if (derived)
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { CliError } from "@wirecat/cli-base";
|
|
2
2
|
import { tagOf } from "../../domain/tags.js";
|
|
3
|
+
import { fuseRanked } from "../../search/fusion.js";
|
|
3
4
|
import { compileAutomaton, foldRegex, wildcardPattern, } from "../../search/lucene/automaton.js";
|
|
4
5
|
import { isStemmed } from "../../search/lucene/resolved.js";
|
|
5
6
|
import { exhausted, outOfTime, QUERY_LIMITS, searchError } from "../../search/lucene/types.js";
|
|
@@ -44,7 +45,9 @@ const CORPORA = [
|
|
|
44
45
|
type: "document",
|
|
45
46
|
noun: "note",
|
|
46
47
|
fields: NOTE_FIELDS,
|
|
47
|
-
view
|
|
48
|
+
get view() {
|
|
49
|
+
return `(SELECT n.id, n.account_id AS folder_id, n.external_id AS path, n.title, coalesce(n.body, '') AS text, n.metadata, ${contextDocumentTime()} AS at, n.deleted_at FROM documents n)`;
|
|
50
|
+
},
|
|
48
51
|
words: "document_words",
|
|
49
52
|
stems: "document_stems",
|
|
50
53
|
live: "coalesce(json_extract(n.metadata, '$.catalog.active'), 1)=1",
|
|
@@ -68,21 +71,15 @@ const matchedRows = (context, query) => {
|
|
|
68
71
|
const chosen = CORPORA.filter(({ type }) => (query.source === undefined || (query.source === "file") === (type === "document")) &&
|
|
69
72
|
(!query.folderIds?.length || query.withInternal === true || type === "document"));
|
|
70
73
|
const idsOf = (type) => query.refs?.flatMap((ref) => (ref.startsWith(`${type}:`) ? [Number(ref.slice(type.length + 1))] : []));
|
|
71
|
-
const
|
|
74
|
+
const lists = chosen.map((corpus) => {
|
|
72
75
|
const ids = idsOf(corpus.type);
|
|
73
76
|
if (ids?.length === 0)
|
|
74
77
|
return [];
|
|
75
78
|
return searchCorpus(context, { ...query, ...(query.folderIds ? { accountIds: query.folderIds } : {}), ...(ids ? { ids } : {}) }, corpus);
|
|
76
79
|
});
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
: (exactFirst ? Number(b.exact === true) - Number(a.exact === true) : 0) ||
|
|
81
|
-
Number(a.relevance === null) - Number(b.relevance === null) ||
|
|
82
|
-
(a.relevance ?? 0) - (b.relevance ?? 0) ||
|
|
83
|
-
(b.at ?? 0) - (a.at ?? 0) ||
|
|
84
|
-
a.id - b.id);
|
|
85
|
-
return rows;
|
|
80
|
+
if (query.newest)
|
|
81
|
+
return lists.flat().sort((a, b) => (b.at ?? 0) - (a.at ?? 0) || a.id - b.id);
|
|
82
|
+
return fuseRanked(lists, (row) => ({ exact: row.exact, ranked: row.relevance !== null, at: row.at ?? 0 }));
|
|
86
83
|
};
|
|
87
84
|
/** Notes matching a parsed query, by the same language as messages: files and written notes, merged. */
|
|
88
85
|
export const searchNotes = (context, query) => {
|
|
@@ -155,6 +155,8 @@ export interface NotesStore extends NoteSearch, ImportedDocuments, AddedSources
|
|
|
155
155
|
note(reference: string): Promise<Note>;
|
|
156
156
|
resolveNote(reference: string): Promise<Note | undefined>;
|
|
157
157
|
noteReferences(reference: string): Promise<string[]>;
|
|
158
|
+
/** The live file note at this path of a folder or documents account, as `notes({ folderId })` lists it. */
|
|
159
|
+
fileNote(folderId: string, path: string): Promise<Note | undefined>;
|
|
158
160
|
notes(options?: {
|
|
159
161
|
folderId?: string;
|
|
160
162
|
source?: Note["source"];
|