@wirecat/cli-core 0.656.0 → 0.658.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 +22 -0
- package/dist/background/daily-archive-timer.d.ts +1 -1
- package/dist/calendar/index.d.ts +1 -1
- package/dist/calendar/index.js +1 -1
- package/dist/calendar/reads.d.ts +1 -0
- package/dist/calendar/reads.js +1 -1
- package/dist/cli/index.d.ts +2 -0
- package/dist/cli/index.js +2 -0
- package/dist/cli/listings.d.ts +46 -0
- package/dist/cli/listings.js +188 -0
- package/dist/cli/messenger/serve-relay.d.ts +1 -1
- package/dist/entities/listings.d.ts +514 -0
- package/dist/entities/listings.js +154 -0
- package/dist/errors/reasons.js +4 -0
- package/dist/mail/meeting-notes.d.ts +9 -2
- package/dist/mail/meeting-notes.js +18 -5
- package/dist/meetings/mcp/index.d.ts +15 -15
- package/dist/services/index.d.ts +1 -0
- package/dist/services/index.js +1 -0
- package/dist/services/listings.d.ts +74 -0
- package/dist/services/listings.js +285 -0
- package/dist/services/metadata.d.ts +1 -1
- package/dist/store/index.d.ts +2 -0
- package/dist/store/index.js +2 -0
- package/dist/store/sqlite/calendar-events.d.ts +10 -0
- package/dist/store/sqlite/calendar-events.js +18 -8
- package/dist/store/sqlite/document-listing.d.ts +99 -0
- package/dist/store/sqlite/document-listing.js +292 -0
- package/dist/store/sqlite/files.d.ts +2 -0
- package/dist/store/sqlite/files.js +7 -3
- package/dist/store/sqlite/meeting-listing.d.ts +108 -0
- package/dist/store/sqlite/meeting-listing.js +431 -0
- package/dist/store/store.d.ts +4 -0
- package/dist/store/store.js +6 -0
- package/package.json +1 -1
|
@@ -0,0 +1,285 @@
|
|
|
1
|
+
import { CliError } from "@wirecat/cli-base";
|
|
2
|
+
import { eventIdOf } from "../calendar/index.js";
|
|
3
|
+
import { providerLabel } from "../domain/providers.js";
|
|
4
|
+
import { formatMeetingReference, parseMeetingReference } from "../meetings/index.js";
|
|
5
|
+
import { TOTAL_CAP } from "../search/total.js";
|
|
6
|
+
import { storeQuery } from "./notes-search.js";
|
|
7
|
+
/** How many documents a text term may match before the list counts them as "at least". */
|
|
8
|
+
export const DOCUMENT_TEXT_CANDIDATES = 2_000;
|
|
9
|
+
const iso = (ms) => (ms === null ? null : new Date(ms).toISOString());
|
|
10
|
+
const sourceName = ({ provider, account }) => `${provider}:${account}`;
|
|
11
|
+
const sourceOf = (account) => ({
|
|
12
|
+
provider: account.provider,
|
|
13
|
+
account: account.account,
|
|
14
|
+
source: sourceName(account),
|
|
15
|
+
label: `${providerLabel(account.provider)} · ${account.name ?? account.account}`,
|
|
16
|
+
});
|
|
17
|
+
/**
|
|
18
|
+
* The accounts `source:` terms name, among those holding what is listed: `provider:account`, or every account of a
|
|
19
|
+
* provider. One that names none is refused with the choices, never dropped.
|
|
20
|
+
*/
|
|
21
|
+
const chosenAccounts = (held, sources, what) => {
|
|
22
|
+
if (!sources?.length)
|
|
23
|
+
return held;
|
|
24
|
+
const chosen = new Map();
|
|
25
|
+
for (const wanted of sources) {
|
|
26
|
+
const found = held.filter((account) => sourceName(account) === wanted || account.provider === wanted);
|
|
27
|
+
if (found.length === 0)
|
|
28
|
+
throw new CliError("not_found", `source:${wanted} names no account holding ${what} — the store holds ${held.map(sourceName).join(", ") || "none"}`, { reason: "listing.source-not-found" });
|
|
29
|
+
for (const account of found)
|
|
30
|
+
chosen.set(account.id, account);
|
|
31
|
+
}
|
|
32
|
+
return [...chosen.values()];
|
|
33
|
+
};
|
|
34
|
+
const documentItem = (row, accounts) => ({
|
|
35
|
+
ref: `document:${row.id}`,
|
|
36
|
+
id: String(row.id),
|
|
37
|
+
title: row.title,
|
|
38
|
+
file_name: row.fileName,
|
|
39
|
+
kind: row.kind,
|
|
40
|
+
mime: row.mime,
|
|
41
|
+
size: row.size,
|
|
42
|
+
source: sourceOf(accounts.get(row.accountId) ?? { provider: row.provider, account: row.account, name: row.accountName }),
|
|
43
|
+
folder: row.folder,
|
|
44
|
+
path: row.path,
|
|
45
|
+
url: row.url,
|
|
46
|
+
local_path: row.localPath,
|
|
47
|
+
source_modified_at: iso(row.modifiedAt),
|
|
48
|
+
stored_at: new Date(row.storedAt).toISOString(),
|
|
49
|
+
has_text: row.hasText,
|
|
50
|
+
untrusted: ["title", "file_name", "folder", "path"],
|
|
51
|
+
});
|
|
52
|
+
/** Every document of every account, or of the `source:` accounts, newest change first; a text term ranks nothing. */
|
|
53
|
+
export const listDocuments = async (store, request) => {
|
|
54
|
+
const held = await store.listings.documentAccounts();
|
|
55
|
+
const accounts = chosenAccounts(held, request.sources, "documents");
|
|
56
|
+
const narrowed = request.sources?.length ? accounts.map(({ id }) => id) : undefined;
|
|
57
|
+
let ids;
|
|
58
|
+
let capped = false;
|
|
59
|
+
if (request.text?.trim()) {
|
|
60
|
+
const { root, stemmer } = await storeQuery(store, request.text, request.zone ? { timezone: request.zone } : {});
|
|
61
|
+
const found = await store.notes.matchingRefs({
|
|
62
|
+
root,
|
|
63
|
+
limit: DOCUMENT_TEXT_CANDIDATES,
|
|
64
|
+
source: "file",
|
|
65
|
+
...(narrowed ? { folderIds: narrowed.map(String) } : {}),
|
|
66
|
+
...(stemmer ? { stemmer } : {}),
|
|
67
|
+
});
|
|
68
|
+
ids = found.refs.flatMap((ref) => (ref.startsWith("document:") ? [Number(ref.slice(9))] : []));
|
|
69
|
+
capped = found.hasMore;
|
|
70
|
+
}
|
|
71
|
+
const page = await store.listings.documents({
|
|
72
|
+
...(narrowed ? { accountIds: narrowed } : {}),
|
|
73
|
+
...(request.query ? { query: request.query } : {}),
|
|
74
|
+
...(ids ? { ids } : {}),
|
|
75
|
+
...(request.zone ? { zone: request.zone } : {}),
|
|
76
|
+
...(request.now ? { now: request.now } : {}),
|
|
77
|
+
limit: request.limit,
|
|
78
|
+
offset: request.offset,
|
|
79
|
+
});
|
|
80
|
+
const byId = new Map(held.map((account) => [account.id, account]));
|
|
81
|
+
return {
|
|
82
|
+
items: page.items.map((row) => documentItem(row, byId)),
|
|
83
|
+
total: page.total > TOTAL_CAP || capped
|
|
84
|
+
? { value: Math.min(page.total, TOTAL_CAP), relation: "gte" }
|
|
85
|
+
: { value: page.total, relation: "eq" },
|
|
86
|
+
accounts: accounts.map(sourceName),
|
|
87
|
+
};
|
|
88
|
+
};
|
|
89
|
+
/** The accounts holding documents, each with its folders flattened parents first, for a page's left panel. */
|
|
90
|
+
export const listDocumentSources = async (store, { sources, depth }) => {
|
|
91
|
+
const held = await store.listings.documentAccounts();
|
|
92
|
+
const accounts = chosenAccounts(held, sources, "documents");
|
|
93
|
+
const tree = await store.listings.documentSources({
|
|
94
|
+
...(sources?.length ? { accountIds: accounts.map(({ id }) => id) } : {}),
|
|
95
|
+
depth,
|
|
96
|
+
});
|
|
97
|
+
const flat = (nodes, level) => nodes.flatMap((node) => [
|
|
98
|
+
{ path: node.path, name: node.name, depth: level, count: node.count },
|
|
99
|
+
...flat(node.folders, level + 1),
|
|
100
|
+
]);
|
|
101
|
+
return tree.map((account) => ({
|
|
102
|
+
...sourceOf(account),
|
|
103
|
+
name: account.name,
|
|
104
|
+
count: account.count,
|
|
105
|
+
loose: account.loose,
|
|
106
|
+
folders: flat(account.folders, 1),
|
|
107
|
+
}));
|
|
108
|
+
};
|
|
109
|
+
const documentId = (reference) => {
|
|
110
|
+
const match = /^document:([1-9]\d*)$/u.exec(reference.trim());
|
|
111
|
+
if (!match)
|
|
112
|
+
throw new CliError("validation_error", `${reference} is not a document; give its document:<id>`);
|
|
113
|
+
return Number(match[1]);
|
|
114
|
+
};
|
|
115
|
+
/** One document with `limit` characters of its text from `offset`, its tags, people, meetings and events. */
|
|
116
|
+
export const showDocument = async (store, reference, text) => {
|
|
117
|
+
const found = await store.listings.document(documentId(reference), text);
|
|
118
|
+
if (!found)
|
|
119
|
+
throw new CliError("not_found", `no document ${reference} in the store`, { reason: "document.not-found" });
|
|
120
|
+
const accounts = new Map((await store.listings.documentAccounts()).map((account) => [account.id, account]));
|
|
121
|
+
return {
|
|
122
|
+
...documentItem(found, accounts),
|
|
123
|
+
text: found.text,
|
|
124
|
+
text_offset: Math.min(text.offset, found.textLength),
|
|
125
|
+
text_length: found.textLength,
|
|
126
|
+
has_more: found.text !== null && text.offset + found.text.length < found.textLength,
|
|
127
|
+
extraction: found.extraction,
|
|
128
|
+
extraction_error: found.extractionError,
|
|
129
|
+
language: found.language,
|
|
130
|
+
tags: found.tags,
|
|
131
|
+
people: found.people,
|
|
132
|
+
meetings: found.meetings.map(({ ref, title, at, role }) => ({ ref, title, at: iso(at), role })),
|
|
133
|
+
events: found.events.map(({ ref, title, at, role }) => ({ ref, title, at: iso(at), role })),
|
|
134
|
+
untrusted: ["title", "file_name", "folder", "path", "text", "meetings.title", "events.title"],
|
|
135
|
+
};
|
|
136
|
+
};
|
|
137
|
+
const ref = ({ id, accountId }) => formatMeetingReference({ type: "meeting", accountId, meetingId: id });
|
|
138
|
+
const meetingItem = (row, accounts) => {
|
|
139
|
+
const meetings = row.meetings.map(({ id, accountId }) => ref({ id, accountId }));
|
|
140
|
+
const named = (provider, account) => accounts.get(`${provider}:${account}`) ?? { provider, account, name: null };
|
|
141
|
+
return {
|
|
142
|
+
ref: row.type === "event" ? `event:${row.id}` : meetings[0],
|
|
143
|
+
kind: row.kind,
|
|
144
|
+
title: row.title,
|
|
145
|
+
started_at: iso(row.startsAt),
|
|
146
|
+
ended_at: iso(row.endsAt),
|
|
147
|
+
duration_ms: row.startsAt !== null && row.endsAt !== null && row.endsAt >= row.startsAt ? row.endsAt - row.startsAt : null,
|
|
148
|
+
all_day: row.allDay,
|
|
149
|
+
timezone: row.timezone,
|
|
150
|
+
status: row.status,
|
|
151
|
+
url: row.url,
|
|
152
|
+
links: row.links,
|
|
153
|
+
sources: row.sources.map((source) => ({
|
|
154
|
+
...sourceOf(named(source.provider, source.account)),
|
|
155
|
+
via: source.via,
|
|
156
|
+
calendar: source.calendar,
|
|
157
|
+
ref: source.ref,
|
|
158
|
+
})),
|
|
159
|
+
meetings,
|
|
160
|
+
participants: row.participants,
|
|
161
|
+
participants_count: row.participants.length,
|
|
162
|
+
has_recording: row.hasRecording,
|
|
163
|
+
has_transcript: row.hasTranscript,
|
|
164
|
+
has_summary: row.hasSummary,
|
|
165
|
+
documents: row.documents,
|
|
166
|
+
pending_findings: row.pendingFindings,
|
|
167
|
+
untrusted: ["title", "participants.name", "sources.calendar", "documents.title"],
|
|
168
|
+
};
|
|
169
|
+
};
|
|
170
|
+
const personIdOf = (value) => {
|
|
171
|
+
const match = /^(?:person:)?([1-9]\d*)$/u.exec(value.trim());
|
|
172
|
+
if (!match)
|
|
173
|
+
throw new CliError("validation_error", `person:${value} is not a person; give person:<id>`);
|
|
174
|
+
return Number(match[1]);
|
|
175
|
+
};
|
|
176
|
+
/**
|
|
177
|
+
* Meetings, calls and calendar events of every account (or the `source:` ones) as one row per real meeting, in a
|
|
178
|
+
* time window. A calendar event and its Zoom or Meet record share a row when the store linked them or their rooms
|
|
179
|
+
* (`join_key`) are the same and their times overlap.
|
|
180
|
+
*/
|
|
181
|
+
export const listMeetingEntries = async (store, request) => {
|
|
182
|
+
const held = await store.listings.meetingAccounts();
|
|
183
|
+
const accounts = chosenAccounts(held, request.sources, "calendars or meetings");
|
|
184
|
+
const page = await store.listings.meetingRows({
|
|
185
|
+
...(request.sources?.length ? { accountIds: accounts.map(({ id }) => id) } : {}),
|
|
186
|
+
...(request.kinds?.length ? { kinds: request.kinds } : {}),
|
|
187
|
+
...(request.person === undefined ? {} : { personId: personIdOf(request.person) }),
|
|
188
|
+
...(request.hasTranscript === undefined ? {} : { hasTranscript: request.hasTranscript }),
|
|
189
|
+
...(request.titleWords?.length ? { titleWords: request.titleWords } : {}),
|
|
190
|
+
...(request.from === undefined ? {} : { from: request.from }),
|
|
191
|
+
...(request.to === undefined ? {} : { to: request.to }),
|
|
192
|
+
...(request.fromDate === undefined ? {} : { fromDate: request.fromDate }),
|
|
193
|
+
...(request.toDate === undefined ? {} : { toDate: request.toDate }),
|
|
194
|
+
...(request.newest === undefined ? {} : { newest: request.newest }),
|
|
195
|
+
limit: request.limit,
|
|
196
|
+
offset: request.offset,
|
|
197
|
+
});
|
|
198
|
+
const byName = new Map(held.map((account) => [sourceName(account), account]));
|
|
199
|
+
return {
|
|
200
|
+
items: page.items.map((row) => meetingItem(row, byName)),
|
|
201
|
+
total: { value: page.total, relation: "eq" },
|
|
202
|
+
accounts: accounts.map(sourceName),
|
|
203
|
+
read: accounts,
|
|
204
|
+
};
|
|
205
|
+
};
|
|
206
|
+
const targetOf = (reference) => {
|
|
207
|
+
const text = reference.trim();
|
|
208
|
+
if (text.startsWith("event:"))
|
|
209
|
+
return { event: eventIdOf(text) };
|
|
210
|
+
if (text.startsWith("meeting:") && text.split("/").length === 2)
|
|
211
|
+
return parseMeetingReference(text);
|
|
212
|
+
throw new CliError("validation_error", `${reference} is not a meeting; give its event:<id> or meeting:<account>/<id>`);
|
|
213
|
+
};
|
|
214
|
+
/**
|
|
215
|
+
* One row as `listMeetingEntries` shows it, with the calendar's text, every meeting's summaries, the findings citing
|
|
216
|
+
* them and `limit` transcript lines from `offset` of its first meeting with a transcript.
|
|
217
|
+
*/
|
|
218
|
+
export const showMeetingEntry = async (store, reference, lines) => {
|
|
219
|
+
const target = targetOf(reference);
|
|
220
|
+
const row = await store.listings.meetingRow("event" in target ? target : { meeting: target.meetingId });
|
|
221
|
+
const asked = (one) => "meetingId" in target && one.id === target.meetingId && one.accountId === target.accountId;
|
|
222
|
+
if (!row || ("meetingId" in target && !row.meetings.some(asked)))
|
|
223
|
+
throw new CliError("not_found", `no meeting ${reference} in the store`, { reason: "meeting.not-found" });
|
|
224
|
+
const byName = new Map((await store.listings.meetingAccounts()).map((account) => [sourceName(account), account]));
|
|
225
|
+
const event = row.type === "event" ? await store.calendar.event(row.id) : null;
|
|
226
|
+
const details = [];
|
|
227
|
+
for (const { id } of row.meetings) {
|
|
228
|
+
const one = await store.meetings.meeting(id);
|
|
229
|
+
if (one)
|
|
230
|
+
details.push(one);
|
|
231
|
+
}
|
|
232
|
+
const live = event?.entries.find(({ deletedAt }) => deletedAt === null) ?? event?.entries[0];
|
|
233
|
+
const first = details[0]?.meeting;
|
|
234
|
+
const spoken = details.flatMap((one) => one.transcripts
|
|
235
|
+
.filter(({ transcript }) => transcript.deletedAt === null && transcript.supersededAt === null)
|
|
236
|
+
.map((transcript) => ({ meeting: one, ...transcript })))[0];
|
|
237
|
+
const people = new Map((spoken?.meeting.participants ?? []).map((participant) => [participant.id, participant.person ?? null]));
|
|
238
|
+
return {
|
|
239
|
+
...meetingItem(row, byName),
|
|
240
|
+
description: live?.description ?? event?.event.description ?? first?.description ?? null,
|
|
241
|
+
location: live?.location ?? event?.event.location ?? first?.location ?? null,
|
|
242
|
+
summaries: details.flatMap((one) => one.summaries.map((summary) => ({
|
|
243
|
+
meeting: ref(one.meeting),
|
|
244
|
+
source: summary.source,
|
|
245
|
+
title: summary.title,
|
|
246
|
+
overview: summary.overview,
|
|
247
|
+
sections: summary.sections,
|
|
248
|
+
next_steps: summary.nextSteps,
|
|
249
|
+
url: summary.docUrl,
|
|
250
|
+
}))),
|
|
251
|
+
transcript: spoken
|
|
252
|
+
? {
|
|
253
|
+
meeting: ref(spoken.meeting.meeting),
|
|
254
|
+
source: spoken.transcript.source,
|
|
255
|
+
language: spoken.transcript.language,
|
|
256
|
+
offset: lines.offset,
|
|
257
|
+
total: spoken.rows.length,
|
|
258
|
+
has_more: lines.offset + lines.limit < spoken.rows.length,
|
|
259
|
+
lines: spoken.rows.slice(lines.offset, lines.offset + lines.limit).map((line) => {
|
|
260
|
+
const person = line.speakerParticipantId === null ? null : (people.get(line.speakerParticipantId) ?? null);
|
|
261
|
+
return {
|
|
262
|
+
position: line.position,
|
|
263
|
+
offset_ms: line.startMs,
|
|
264
|
+
end_ms: line.endMs,
|
|
265
|
+
speaker: line.speakerName,
|
|
266
|
+
person: person === null ? null : { ref: `person:${person.uid}`, name: person.name ?? null },
|
|
267
|
+
text: line.text,
|
|
268
|
+
};
|
|
269
|
+
}),
|
|
270
|
+
}
|
|
271
|
+
: null,
|
|
272
|
+
findings: row.findings,
|
|
273
|
+
untrusted: [
|
|
274
|
+
"title",
|
|
275
|
+
"description",
|
|
276
|
+
"location",
|
|
277
|
+
"participants.name",
|
|
278
|
+
"sources.calendar",
|
|
279
|
+
"documents.title",
|
|
280
|
+
"summaries",
|
|
281
|
+
"transcript.lines.speaker",
|
|
282
|
+
"transcript.lines.text",
|
|
283
|
+
],
|
|
284
|
+
};
|
|
285
|
+
};
|
|
@@ -14,12 +14,12 @@ export declare const metadataService: (deps: ServiceDeps) => {
|
|
|
14
14
|
dryRun?: boolean;
|
|
15
15
|
}) => Promise<{
|
|
16
16
|
items: ({
|
|
17
|
-
error?: undefined;
|
|
18
17
|
chatId: string;
|
|
19
18
|
tags: import("../domain/channel-tags.js").ChannelTagMatch[];
|
|
20
19
|
algorithm: string;
|
|
21
20
|
fetchedAt: string | null;
|
|
22
21
|
source: string;
|
|
22
|
+
error?: undefined;
|
|
23
23
|
} | {
|
|
24
24
|
tags?: undefined;
|
|
25
25
|
algorithm?: undefined;
|
package/dist/store/index.d.ts
CHANGED
|
@@ -54,6 +54,7 @@ export { type CrmContactsRemoved, type CrmCopies, type CrmRelationIssue, type Cr
|
|
|
54
54
|
export { COMPANY_TYPE_MEANINGS, type CompanyTypeMeaning, CRM_LINK_MODES, type CrmLinkMode, type CrmStageMove, type CrmStageTasks, crmSettingKey, type StageTaskRule, } from "./sqlite/crm-settings.js";
|
|
55
55
|
export type { Deal, DealFilter, DealInput, DealPerson, DealScope, DealsStore, FunnelStage, Pipeline, PipelineInput, PipelineReport, PipelineStage, StageChange, } from "./sqlite/deals.js";
|
|
56
56
|
export type { DecisionMessage, DecisionPress, DecisionRefusal, DecisionRequest, DecisionRequestInput, DecisionRequestStore, TakeResult, } from "./sqlite/decision-requests.js";
|
|
57
|
+
export { DOCUMENT_KINDS, type DocumentDetail, type DocumentFolderNode, type DocumentKind, type DocumentLink, type DocumentListFilter, type DocumentListing, type DocumentListRow, type DocumentSourceNode, } from "./sqlite/document-listing.js";
|
|
57
58
|
export type { Email, EmailAddress, EmailAttachment, EmailFacts, EmailFilter, EmailInput, EmailInThread, EmailLocationInput, EmailRecipient, EmailRef, EmailThread, EmailVectorHit, FolderEmail, Mailbox, MailboxInput, MailFilter, MailStore, PartialEmail, SenderScore, ThreadDetails, ThreadSave, } from "./sqlite/emails.js";
|
|
58
59
|
export { EVENT_FIELDS, type EventChunkToEmbed, type EventHit, type EventQuery, type EventSearch, type NearestEvent, } from "./sqlite/event-search.js";
|
|
59
60
|
export type { EvidenceInput, EvidenceMetadata } from "./sqlite/evidence-signature.js";
|
|
@@ -67,6 +68,7 @@ export type { Involvement, InvolvementStore } from "./sqlite/involvements.js";
|
|
|
67
68
|
export type { Annotation, KnowledgeRelation, KnowledgeStore, KnowledgeTarget, LabelledType, Organization, Project, Reminder, } from "./sqlite/knowledge.js";
|
|
68
69
|
export { ORGANIZATION_KINDS, PROJECT_TYPES, SCOPES } from "./sqlite/knowledge.js";
|
|
69
70
|
export type { MailRule, MailRuleCount, MailRuleInput, MailRulesStore } from "./sqlite/mail-rules.js";
|
|
71
|
+
export { type ListedAccount, MEETING_ROW_KINDS, type MeetingListFilter, type MeetingListing, type MeetingRow, type MeetingRowDocument, type MeetingRowKind, type MeetingRowParticipant, type MeetingRowSource, } from "./sqlite/meeting-listing.js";
|
|
70
72
|
export type { MeetingProjectLink, MeetingProjectsStore } from "./sqlite/meeting-projects.js";
|
|
71
73
|
export type { MeetingContextReadCapabilities, MeetingReadCapabilities, MeetingReadScope, TranscriptContextInput, TranscriptContextPage, TranscriptPage, TranscriptReadScope, TranscriptRowPage, } from "./sqlite/meeting-reads.js";
|
|
72
74
|
export type { MeetingVectorHit, MeetingVectors } from "./sqlite/meeting-vectors.js";
|
package/dist/store/index.js
CHANGED
|
@@ -35,10 +35,12 @@ export { BUSINESS_FIND_MAX } from "./sqlite/business-search.js";
|
|
|
35
35
|
export { CATALOG_QUERY } from "./sqlite/catalog.js";
|
|
36
36
|
export { crmIdentityId, } from "./sqlite/crm.js";
|
|
37
37
|
export { COMPANY_TYPE_MEANINGS, CRM_LINK_MODES, crmSettingKey, } from "./sqlite/crm-settings.js";
|
|
38
|
+
export { DOCUMENT_KINDS, } from "./sqlite/document-listing.js";
|
|
38
39
|
export { EVENT_FIELDS, } from "./sqlite/event-search.js";
|
|
39
40
|
export { QUOTE_LIMIT, quoteKept } from "./sqlite/evidence-signature.js";
|
|
40
41
|
export { IMPORTED_DOCUMENT_QUERY } from "./sqlite/imported-documents.js";
|
|
41
42
|
export { ORGANIZATION_KINDS, PROJECT_TYPES, SCOPES } from "./sqlite/knowledge.js";
|
|
43
|
+
export { MEETING_ROW_KINDS, } from "./sqlite/meeting-listing.js";
|
|
42
44
|
export { NOTE_FIELDS, } from "./sqlite/note-search.js";
|
|
43
45
|
export { DEFAULT_OWNER_LANGUAGES, ownerLanguages } from "./sqlite/owner-languages.js";
|
|
44
46
|
export { PEOPLE_SORTS, } from "./sqlite/people-list.js";
|
|
@@ -1,4 +1,14 @@
|
|
|
1
1
|
import type { Event, EventFilter } from "../../meetings/index.js";
|
|
2
2
|
import type { CacheDatabase } from "../driver.js";
|
|
3
|
+
type WindowFilter = Pick<EventFilter, "from" | "fromDate" | "to" | "toDate" | "startsFrom" | "startsFromDate">;
|
|
4
|
+
/**
|
|
5
|
+
* The SQL over `events e` for a filter's time bounds: timed events by instant, all-day ones by their local days, plus
|
|
6
|
+
* bounds on `starts_at` alone so SQLite can seek its index.
|
|
7
|
+
*/
|
|
8
|
+
export declare const eventWindow: (database: CacheDatabase, filter: WindowFilter) => {
|
|
9
|
+
clauses: string[];
|
|
10
|
+
params: (string | number)[];
|
|
11
|
+
};
|
|
3
12
|
/** The events of a filter, earliest first (`EventStore.events`). */
|
|
4
13
|
export declare const listEvents: (database: CacheDatabase, filter: EventFilter) => Event[];
|
|
14
|
+
export {};
|
|
@@ -11,11 +11,15 @@ const accountsOf = (filter) => {
|
|
|
11
11
|
throw new CliError("validation_error", "accountIds names no account");
|
|
12
12
|
return filter.accountIds ?? (filter.accountId === undefined ? undefined : [filter.accountId]);
|
|
13
13
|
};
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
14
|
+
const longestEvent = (database) => Number(database.prepare("SELECT coalesce(max(ends_at - starts_at), 0) AS ms FROM events WHERE deleted_at IS NULL").get()
|
|
15
|
+
?.ms ?? 0);
|
|
16
|
+
/**
|
|
17
|
+
* The SQL over `events e` for a filter's time bounds: timed events by instant, all-day ones by their local days, plus
|
|
18
|
+
* bounds on `starts_at` alone so SQLite can seek its index.
|
|
19
|
+
*/
|
|
20
|
+
export const eventWindow = (database, filter) => {
|
|
21
|
+
const clauses = [];
|
|
17
22
|
const params = [];
|
|
18
|
-
const entries = (extra) => `EXISTS (SELECT 1 FROM calendar_entries ce JOIN calendars c ON c.id = ce.calendar_id WHERE ce.event_id = e.id AND ${extra})`;
|
|
19
23
|
const dated = (column, date, instant, at) => {
|
|
20
24
|
if (at === undefined)
|
|
21
25
|
return;
|
|
@@ -32,11 +36,9 @@ export const listEvents = (database, filter) => {
|
|
|
32
36
|
dated("start_date >= ?", filter.startsFromDate, "e.starts_at >= ?", filter.startsFrom);
|
|
33
37
|
// Bounds on starts_at alone let SQLite seek its index; the CASE above cannot. They are wider than the CASE: by the
|
|
34
38
|
// longest stored event back, and by a day each way for an all-day event's zone.
|
|
35
|
-
const longest = () => Number(database.prepare("SELECT coalesce(max(ends_at - starts_at), 0) AS ms FROM events WHERE deleted_at IS NULL").get()
|
|
36
|
-
?.ms ?? 0);
|
|
37
39
|
if (filter.from !== undefined) {
|
|
38
40
|
clauses.push("e.starts_at >= ?");
|
|
39
|
-
params.push(filter.from -
|
|
41
|
+
params.push(filter.from - longestEvent(database) - DAY);
|
|
40
42
|
}
|
|
41
43
|
if (filter.to !== undefined && filter.toDate !== undefined) {
|
|
42
44
|
clauses.push("e.starts_at < ?");
|
|
@@ -46,6 +48,14 @@ export const listEvents = (database, filter) => {
|
|
|
46
48
|
clauses.push("e.starts_at >= ?");
|
|
47
49
|
params.push(filter.startsFrom - DAY);
|
|
48
50
|
}
|
|
51
|
+
return { clauses, params };
|
|
52
|
+
};
|
|
53
|
+
/** The events of a filter, earliest first (`EventStore.events`). */
|
|
54
|
+
export const listEvents = (database, filter) => {
|
|
55
|
+
const window = eventWindow(database, filter);
|
|
56
|
+
const clauses = ["e.deleted_at IS NULL", ...window.clauses];
|
|
57
|
+
const params = [...window.params];
|
|
58
|
+
const entries = (extra) => `EXISTS (SELECT 1 FROM calendar_entries ce JOIN calendars c ON c.id = ce.calendar_id WHERE ce.event_id = e.id AND ${extra})`;
|
|
49
59
|
if (filter.id !== undefined) {
|
|
50
60
|
clauses.push("e.id = ?");
|
|
51
61
|
params.push(filter.id);
|
|
@@ -107,7 +117,7 @@ export const listEvents = (database, filter) => {
|
|
|
107
117
|
AND coalesce(bce.transparency, '') <> 'transparent'
|
|
108
118
|
AND coalesce(bce.event_type, '') <> 'working-location')`;
|
|
109
119
|
const own = busy("e");
|
|
110
|
-
params.push(
|
|
120
|
+
params.push(longestEvent(database));
|
|
111
121
|
const clash = `${own} AND EXISTS (SELECT 1 FROM events e2 WHERE e2.id <> e.id AND e2.starts_at < e.ends_at
|
|
112
122
|
AND e2.ends_at > e.starts_at AND e2.starts_at >= e.starts_at - ? AND ${busy("e2")})`;
|
|
113
123
|
clauses.push(filter.overlapping ? clash : `NOT (${clash})`);
|
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
import type { QueryAst } from "@wirecat/cli-base/query";
|
|
2
|
+
import { type ListedAccount } from "./meeting-listing.js";
|
|
3
|
+
import type { StoreContext } from "./open.js";
|
|
4
|
+
/** What a document is to a person, from its MIME type and file name: the Documents page filters and shows by it. */
|
|
5
|
+
export declare const DOCUMENT_KINDS: readonly ["transcript", "doc", "sheet", "slides", "pdf", "docx", "xlsx", "pptx", "csv", "md", "txt", "html", "page", "image", "other"];
|
|
6
|
+
export type DocumentKind = (typeof DOCUMENT_KINDS)[number];
|
|
7
|
+
export declare const DOCUMENT_KIND_SQL: string;
|
|
8
|
+
export interface DocumentListFilter {
|
|
9
|
+
/** Stored account ids; every account when left out. */
|
|
10
|
+
accountIds?: readonly number[];
|
|
11
|
+
/** The rest of the list's query, over `DOCUMENT_LIST_COLUMNS`' fields. */
|
|
12
|
+
query?: QueryAst;
|
|
13
|
+
/** Only these documents, in this order: what a text search found, best first. */
|
|
14
|
+
ids?: readonly number[];
|
|
15
|
+
zone?: string;
|
|
16
|
+
now?: number;
|
|
17
|
+
limit: number;
|
|
18
|
+
offset: number;
|
|
19
|
+
}
|
|
20
|
+
export interface DocumentListRow {
|
|
21
|
+
id: number;
|
|
22
|
+
accountId: number;
|
|
23
|
+
provider: string;
|
|
24
|
+
account: string;
|
|
25
|
+
accountName: string | null;
|
|
26
|
+
title: string | null;
|
|
27
|
+
fileName: string | null;
|
|
28
|
+
kind: DocumentKind;
|
|
29
|
+
mime: string | null;
|
|
30
|
+
size: number | null;
|
|
31
|
+
url: string | null;
|
|
32
|
+
/** A copy the store keeps of an added file, or a local file's own path when the writer kept one. */
|
|
33
|
+
localPath: string | null;
|
|
34
|
+
/** Where the source keeps it, relative to the account: a Drive folder path, a notes folder's path. */
|
|
35
|
+
path: string | null;
|
|
36
|
+
folder: string | null;
|
|
37
|
+
modifiedAt: number | null;
|
|
38
|
+
storedAt: number;
|
|
39
|
+
hasText: boolean;
|
|
40
|
+
}
|
|
41
|
+
export interface DocumentFolderNode {
|
|
42
|
+
name: string;
|
|
43
|
+
path: string;
|
|
44
|
+
/** Documents in it and in every folder under it. */
|
|
45
|
+
count: number;
|
|
46
|
+
folders: DocumentFolderNode[];
|
|
47
|
+
}
|
|
48
|
+
export interface DocumentSourceNode {
|
|
49
|
+
accountId: number;
|
|
50
|
+
provider: string;
|
|
51
|
+
account: string;
|
|
52
|
+
name: string | null;
|
|
53
|
+
count: number;
|
|
54
|
+
/** Documents kept at the top, in no folder. */
|
|
55
|
+
loose: number;
|
|
56
|
+
folders: DocumentFolderNode[];
|
|
57
|
+
}
|
|
58
|
+
export interface DocumentLink {
|
|
59
|
+
ref: string;
|
|
60
|
+
title: string | null;
|
|
61
|
+
at: number | null;
|
|
62
|
+
role: string | null;
|
|
63
|
+
}
|
|
64
|
+
export interface DocumentDetail extends DocumentListRow {
|
|
65
|
+
text: string | null;
|
|
66
|
+
/** The text's length in characters, all of it, whatever part `text` holds. */
|
|
67
|
+
textLength: number;
|
|
68
|
+
extraction: string | null;
|
|
69
|
+
extractionError: string | null;
|
|
70
|
+
language: string | null;
|
|
71
|
+
tags: string[];
|
|
72
|
+
people: {
|
|
73
|
+
ref: string;
|
|
74
|
+
name: string | null;
|
|
75
|
+
kind: string;
|
|
76
|
+
}[];
|
|
77
|
+
meetings: DocumentLink[];
|
|
78
|
+
events: DocumentLink[];
|
|
79
|
+
}
|
|
80
|
+
export interface DocumentListing {
|
|
81
|
+
/** Every account holding a listed document: what a list reads when no source narrows it. */
|
|
82
|
+
documentAccounts(): Promise<ListedAccount[]>;
|
|
83
|
+
/** One page of every document the filter takes, newest change first (or in `ids`' order). */
|
|
84
|
+
documents(filter: DocumentListFilter): Promise<{
|
|
85
|
+
items: DocumentListRow[];
|
|
86
|
+
total: number;
|
|
87
|
+
}>;
|
|
88
|
+
/** Provider → account → folder, with how many documents each holds, for the accounts given or all of them. */
|
|
89
|
+
documentSources(filter: {
|
|
90
|
+
accountIds?: readonly number[];
|
|
91
|
+
depth: number;
|
|
92
|
+
}): Promise<DocumentSourceNode[]>;
|
|
93
|
+
/** One listed document with a part of its text, from `offset` for `limit` characters. */
|
|
94
|
+
document(id: number, text: {
|
|
95
|
+
offset: number;
|
|
96
|
+
limit: number;
|
|
97
|
+
}): Promise<DocumentDetail | undefined>;
|
|
98
|
+
}
|
|
99
|
+
export declare const documentListingOver: (context: StoreContext) => DocumentListing;
|