@wirecat/cli-core 0.619.0 → 0.621.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 +144 -0
- package/dist/background/daily-archive-timer.d.ts +1 -1
- package/dist/calendar/cli/search-all.d.ts +1 -1
- package/dist/calendar/cli/search-all.js +9 -10
- package/dist/calendar/prepare.js +1 -0
- package/dist/cli/base-stages-command.d.ts +1 -1
- package/dist/cli/base-stages-command.js +1 -1
- package/dist/cli/bot/buttons.d.ts +3 -0
- package/dist/cli/bot/buttons.js +24 -0
- package/dist/cli/bot/messages.js +14 -1
- package/dist/cli/bot/port.d.ts +8 -0
- package/dist/cli/contract-templates.js +31 -2
- package/dist/cli/messenger/contacts-command.js +2 -1
- package/dist/cli/messenger/conversations-command.js +2 -1
- package/dist/cli/messenger/message-items.js +1 -1
- package/dist/cli/messenger/search-answers.d.ts +5 -5
- package/dist/cli/messenger/search-answers.js +9 -20
- package/dist/cli/messenger/search-command.d.ts +2 -2
- package/dist/cli/messenger/search-command.js +8 -18
- package/dist/cli/model-catalogue-command.js +3 -1
- package/dist/cli/search-harder-consents-command.d.ts +21 -0
- package/dist/cli/search-harder-consents-command.js +112 -0
- package/dist/cli/steps.js +0 -6
- package/dist/cli/templates-command.js +4 -4
- package/dist/crm/cli/index.js +2 -2
- package/dist/crm/cli/search-all.js +7 -6
- package/dist/crm/source.d.ts +8 -0
- package/dist/crm/sync.d.ts +1 -1
- package/dist/crm/sync.js +13 -1
- package/dist/domain/models.d.ts +2 -0
- package/dist/domain/relations.d.ts +1 -0
- package/dist/domain/relations.js +5 -1
- package/dist/entities/contact-context.d.ts +3 -0
- package/dist/entities/contact-context.js +4 -0
- package/dist/entities/hit.d.ts +9 -2
- package/dist/entities/hit.js +6 -2
- package/dist/entities/index.d.ts +9 -1
- package/dist/errors/reasons.js +3 -0
- package/dist/meetings/hit-query.d.ts +1 -1
- package/dist/meetings/hit-query.js +2 -2
- package/dist/meetings/index.d.ts +1 -0
- package/dist/meetings/index.js +1 -0
- package/dist/meetings/store.d.ts +4 -0
- package/dist/meetings/store.js +2 -1
- package/dist/models/anthropic.js +5 -0
- package/dist/search/question-period.d.ts +10 -0
- package/dist/search/question-period.js +133 -0
- package/dist/sends/buttons.d.ts +2 -0
- package/dist/sends/buttons.js +6 -1
- package/dist/services/enrichment-setting.d.ts +6 -0
- package/dist/services/enrichment-setting.js +5 -1
- package/dist/services/enrichment.d.ts +5 -0
- package/dist/services/enrichment.js +1 -1
- package/dist/services/index.d.ts +4 -2
- package/dist/services/index.js +3 -1
- package/dist/services/messages.d.ts +1 -4
- package/dist/services/messages.js +0 -2
- package/dist/services/metadata.d.ts +1 -1
- package/dist/services/person-context.d.ts +3 -1
- package/dist/services/person-context.js +21 -8
- package/dist/services/person-preparation.d.ts +5 -1
- package/dist/services/person-preparation.js +10 -3
- package/dist/services/person-timeline.d.ts +6 -1
- package/dist/services/person-timeline.js +10 -2
- package/dist/services/search-all-deprecated.d.ts +40 -0
- package/dist/services/search-all-deprecated.js +10 -0
- package/dist/services/search-all-meetings.d.ts +50 -52
- package/dist/services/search-all-meetings.js +265 -272
- package/dist/services/search-all.d.ts +34 -6
- package/dist/services/search-all.js +119 -24
- package/dist/services/search-harder.d.ts +90 -0
- package/dist/services/search-harder.js +264 -0
- package/dist/store/chats.d.ts +3 -1
- package/dist/store/chats.js +6 -0
- package/dist/store/people.d.ts +6 -2
- package/dist/store/sqlite/added-sources.d.ts +15 -3
- package/dist/store/sqlite/added-sources.js +26 -5
- package/dist/store/sqlite/chats.d.ts +2 -0
- package/dist/store/sqlite/chats.js +6 -0
- package/dist/store/sqlite/involvements.d.ts +1 -1
- package/dist/store/sqlite/involvements.js +4 -2
- package/dist/store/sqlite/meeting-hit-query.d.ts +5 -0
- package/dist/store/sqlite/meeting-hit-query.js +33 -0
- package/dist/store/sqlite/meeting-hit-search.js +10 -8
- package/dist/store/sqlite/meetings.js +1 -1
- package/dist/store/sqlite/notes.d.ts +7 -0
- package/dist/store/sqlite/notes.js +23 -7
- package/dist/store/sqlite/person-preparation.d.ts +7 -3
- package/dist/store/sqlite/person-preparation.js +20 -6
- package/dist/store/sqlite/relation-list.js +4 -2
- package/dist/store/sqlite/reported-relations.d.ts +0 -1
- package/dist/store/sqlite/reported-relations.js +1 -4
- package/package.json +1 -1
- package/parity.json +26 -12
|
@@ -1,290 +1,283 @@
|
|
|
1
1
|
import { CliError } from "@wirecat/cli-base";
|
|
2
|
-
import {
|
|
3
|
-
import { formatMeetingReference } from "../meetings/index.js";
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
6
|
-
import {
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
const
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
2
|
+
import { holdsKind } from "../domain/providers.js";
|
|
3
|
+
import { formatMeetingReference, liftMeetingFields, parseMeetingQuery, READ_BUDGET_EXCEEDED, } from "../meetings/index.js";
|
|
4
|
+
import { fold } from "../store/normalize.js";
|
|
5
|
+
import { excerpt } from "./excerpt.js";
|
|
6
|
+
import { resolveMeetingSelection } from "./meeting-hit-search.js";
|
|
7
|
+
/** More passages of one meeting would crowd out every other source. */
|
|
8
|
+
export const MOST_HITS_PER_MEETING = 3;
|
|
9
|
+
/** Rows per page: the store refuses a page past 4 MB of text, which would skip the whole account. */
|
|
10
|
+
const PAGE_ROWS = 200;
|
|
11
|
+
const MOST_PAGES = 25;
|
|
12
|
+
const exactly = (node) => node.kind === "boolean"
|
|
13
|
+
? { ...node, clauses: node.clauses.map((clause) => ({ ...clause, node: exactly(clause.node) })) }
|
|
14
|
+
: node.field === "text"
|
|
15
|
+
? { ...node, field: "exact" }
|
|
16
|
+
: node;
|
|
17
|
+
const positive = (node) => node.kind === "predicate" || node.clauses.some(({ occur, node }) => occur !== "must_not" && positive(node));
|
|
18
|
+
/** A word or phrase as the start of a title's word, as the passage index matches word starts. */
|
|
19
|
+
const titleNode = (node) => {
|
|
20
|
+
if (node.kind === "boolean") {
|
|
21
|
+
const clauses = node.clauses.map((clause) => ({ ...clause, node: titleNode(clause.node) }));
|
|
22
|
+
return clauses.every((clause) => clause.node) ? { ...node, clauses: clauses } : undefined;
|
|
23
|
+
}
|
|
24
|
+
if ((node.field !== "text" && node.field !== "exact") ||
|
|
25
|
+
(node.operator !== "term" && node.operator !== "phrase") ||
|
|
26
|
+
node.slop !== undefined)
|
|
27
|
+
return undefined;
|
|
28
|
+
const word = node.value.replace(/[\\*?[]/gu, "\\$&");
|
|
29
|
+
const starting = (value) => ({ ...node, field: "title", operator: "wildcard", value });
|
|
30
|
+
return {
|
|
31
|
+
kind: "boolean",
|
|
32
|
+
span: node.span,
|
|
33
|
+
clauses: [
|
|
34
|
+
{ occur: "should", node: starting(`${word}*`) },
|
|
35
|
+
{ occur: "should", node: starting(`* ${word}*`) },
|
|
36
|
+
],
|
|
37
|
+
};
|
|
16
38
|
};
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
39
|
+
/** A question finds passages by any of its words; a title holding one of them is no answer, so it needs them all. */
|
|
40
|
+
const everyWord = (node) => node.kind === "boolean"
|
|
41
|
+
? {
|
|
42
|
+
...node,
|
|
43
|
+
clauses: node.clauses.map((clause) => (clause.occur === "should" ? { ...clause, occur: "must" } : clause)),
|
|
44
|
+
}
|
|
45
|
+
: node;
|
|
46
|
+
/**
|
|
47
|
+
* The query's words as a `meetings list` query over the folded title, or `undefined` when a title cannot answer it:
|
|
48
|
+
* a speaker or nearness is about what was said, and project and tag are not title filters.
|
|
49
|
+
*/
|
|
50
|
+
const titleQuery = (query, input, question) => {
|
|
51
|
+
if (input.projectId !== undefined || input.tagId !== undefined || !positive(query.root))
|
|
52
|
+
return undefined;
|
|
53
|
+
const root = titleNode(question ? everyWord(query.root) : query.root);
|
|
54
|
+
return root && { ...query, root };
|
|
20
55
|
};
|
|
21
|
-
const
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
const
|
|
26
|
-
const
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
56
|
+
const titleWords = (title) => fold(title).match(/[\p{L}\p{N}]+/gu) ?? [];
|
|
57
|
+
/** The SQL matches word starts; an exact word must be a whole word of the title. */
|
|
58
|
+
const holdsExactly = (node, words) => {
|
|
59
|
+
if (node.kind === "boolean") {
|
|
60
|
+
const must = node.clauses.filter(({ occur }) => occur === "must");
|
|
61
|
+
const should = node.clauses.filter(({ occur }) => occur === "should");
|
|
62
|
+
return (must.every((clause) => holdsExactly(clause.node, words)) &&
|
|
63
|
+
!node.clauses.some(({ occur, node }) => occur === "must_not" && holdsExactly(node, words)) &&
|
|
64
|
+
(must.length > 0 || should.length === 0 || should.some((clause) => holdsExactly(clause.node, words))));
|
|
65
|
+
}
|
|
66
|
+
const wanted = titleWords(node.value);
|
|
67
|
+
if (node.field !== "exact")
|
|
68
|
+
return wanted.every((one) => words.some((word) => word.startsWith(one)));
|
|
69
|
+
return ` ${words.join(" ")} `.includes(` ${wanted.join(" ")} `);
|
|
70
|
+
};
|
|
71
|
+
const sameAccount = (one, other) => one.provider === other.provider && one.account === other.account;
|
|
72
|
+
/**
|
|
73
|
+
* The caller's stored account's scope, as a person's context reads: a work profile never reads personal meetings.
|
|
74
|
+
* A caller the store does not hold reads its stated scope, or none.
|
|
75
|
+
*/
|
|
76
|
+
const callerScopes = async (all, caller) => {
|
|
77
|
+
const own = all.find((one) => sameAccount(one, caller));
|
|
78
|
+
if (own && caller.scope !== undefined && caller.scope !== own.scope)
|
|
79
|
+
throw new CliError("not_found", `no ${caller.provider} account ${caller.account} in the store`);
|
|
80
|
+
const scope = own?.scope ?? caller.scope;
|
|
81
|
+
return scope === undefined ? [] : [scope];
|
|
82
|
+
};
|
|
83
|
+
/**
|
|
84
|
+
* Meetings for `search all`, from each meeting account's search index: never refreshed here, since search all only
|
|
85
|
+
* reads. A query meetings cannot answer is refused before any account is read; a failure of one account is that
|
|
86
|
+
* account's skip, and the others still answer.
|
|
87
|
+
*/
|
|
88
|
+
export const meetingLane = async (store, caller, request) => {
|
|
89
|
+
const all = await store.accounts.storedAccounts();
|
|
90
|
+
const scopes = request.scopes ?? (await callerScopes(all, caller));
|
|
91
|
+
const unknownCaller = request.scopes === undefined && !all.some((one) => sameAccount(one, caller));
|
|
92
|
+
const meetings = all.filter((one) => holdsKind(one.provider, "meetings"));
|
|
93
|
+
const stored = meetings.filter((one) => scopes.includes(one.scope));
|
|
94
|
+
const chosen = request.accounts;
|
|
95
|
+
const read = chosen ? stored.filter((one) => chosen.some((key) => sameAccount(key, one))) : stored;
|
|
96
|
+
const skipped = (chosen ?? [])
|
|
97
|
+
.filter((key) => !read.some((one) => sameAccount(key, one)))
|
|
98
|
+
.map(({ provider, account }) => {
|
|
99
|
+
const other = meetings.find((one) => sameAccount({ provider, account }, one));
|
|
100
|
+
return {
|
|
101
|
+
source: `${provider}:${account}`,
|
|
102
|
+
code: "not_found",
|
|
103
|
+
reason: !other
|
|
104
|
+
? "no meetings stored for it"
|
|
105
|
+
: unknownCaller
|
|
106
|
+
? "this account is not in the store yet, so no scope is read"
|
|
107
|
+
: `a ${other.scope} account; this run reads ${scopes.join(" and ")} accounts`,
|
|
33
108
|
};
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
109
|
+
});
|
|
110
|
+
const [first] = read;
|
|
111
|
+
// Like events, meetings the store does not hold are no gap in an answer that did not ask for them.
|
|
112
|
+
if (!first) {
|
|
113
|
+
if (!skipped.length && request.asked)
|
|
114
|
+
skipped.push({
|
|
115
|
+
resource: "meetings",
|
|
116
|
+
code: "not_found",
|
|
117
|
+
reason: !meetings.length
|
|
118
|
+
? "no meeting account stored"
|
|
119
|
+
: unknownCaller
|
|
120
|
+
? "this account is not in the store yet"
|
|
121
|
+
: "no meeting account in this scope",
|
|
122
|
+
});
|
|
123
|
+
return { items: [], hasMore: false, read, skipped, coverage: [] };
|
|
39
124
|
}
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
125
|
+
const lifted = liftMeetingFields(request.text, { accountId: first.id }, undefined, request.timezone);
|
|
126
|
+
const parsed = parseMeetingQuery(lifted.query);
|
|
127
|
+
const query = request.exact ? { ...parsed, root: exactly(parsed.root) } : parsed;
|
|
128
|
+
const { input } = await resolveMeetingSelection(store, {
|
|
129
|
+
...lifted.request,
|
|
130
|
+
...(request.signal ? { signal: request.signal } : {}),
|
|
131
|
+
});
|
|
132
|
+
const lists = [];
|
|
133
|
+
const coverage = [];
|
|
134
|
+
const answered = [];
|
|
135
|
+
for (const account of read) {
|
|
136
|
+
try {
|
|
137
|
+
const found = await accountHits(store, account, query, { ...input, accountId: account.id }, request);
|
|
138
|
+
lists.push(found.ranked);
|
|
139
|
+
coverage.push({ provider: account.provider, account: account.account, ...found.coverage });
|
|
140
|
+
answered.push(account);
|
|
141
|
+
}
|
|
142
|
+
catch (error) {
|
|
143
|
+
if (!(error instanceof CliError) || error.code === "cancelled")
|
|
144
|
+
throw error;
|
|
145
|
+
skipped.push({ source: `${account.provider}:${account.account}`, code: error.code, reason: error.message });
|
|
146
|
+
}
|
|
44
147
|
}
|
|
148
|
+
return { items: merged(lists), hasMore: coverage.some((one) => one.hasMore), read: answered, skipped, coverage };
|
|
45
149
|
};
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
items: [],
|
|
61
|
-
coverage: { accountId: selected.id, by: "word-prefixes", meetingsScanned: 0, complete: false },
|
|
62
|
-
after: position(),
|
|
63
|
-
};
|
|
64
|
-
const seen = new Set();
|
|
65
|
-
const most = request.maxMeetings === "all" ? Number.POSITIVE_INFINITY : (request.maxMeetings ?? 100);
|
|
66
|
-
while (collected.coverage.meetingsScanned < most) {
|
|
67
|
-
cancelled(request.signal);
|
|
68
|
-
const page = await store.meetings.meetings({ accountId: selected.id, limit: 2, offset: meetingOffset });
|
|
69
|
-
cancelled(request.signal);
|
|
70
|
-
const meeting = page[0];
|
|
71
|
-
if (!meeting) {
|
|
72
|
-
collected.coverage.complete = true;
|
|
73
|
-
break;
|
|
150
|
+
/**
|
|
151
|
+
* Every account's hits as one list, each account's own order kept: the better head goes first, so an account with
|
|
152
|
+
* many hits cannot push another's newer or closer ones off the page.
|
|
153
|
+
*/
|
|
154
|
+
const merged = (lists) => {
|
|
155
|
+
const heads = lists.map((list) => ({ list, at: 0 }));
|
|
156
|
+
const items = [];
|
|
157
|
+
for (;;) {
|
|
158
|
+
let best;
|
|
159
|
+
for (const one of heads) {
|
|
160
|
+
const head = one.list[one.at];
|
|
161
|
+
const leader = best?.list[best.at];
|
|
162
|
+
if (head && (!leader || head.tier < leader.tier || (head.tier === leader.tier && head.started > leader.started)))
|
|
163
|
+
best = one;
|
|
74
164
|
}
|
|
75
|
-
const
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
},
|
|
165
|
+
const next = best?.list[best.at];
|
|
166
|
+
if (!best || !next)
|
|
167
|
+
return items;
|
|
168
|
+
items.push(next.item);
|
|
169
|
+
best.at++;
|
|
170
|
+
}
|
|
171
|
+
};
|
|
172
|
+
const accountHits = async (store, account, query, input, { text, window, signal, question, exact }) => {
|
|
173
|
+
const ranked = [];
|
|
174
|
+
const perMeeting = new Map();
|
|
175
|
+
const keep = (one) => {
|
|
176
|
+
const seen = perMeeting.get(one.item.meetingId) ?? 0;
|
|
177
|
+
if (seen >= MOST_HITS_PER_MEETING)
|
|
178
|
+
return false;
|
|
179
|
+
perMeeting.set(one.item.meetingId, seen + 1);
|
|
180
|
+
ranked.push(one);
|
|
181
|
+
return true;
|
|
182
|
+
};
|
|
183
|
+
let indexing = "ready";
|
|
184
|
+
let hasMore = false;
|
|
185
|
+
let passages = 0;
|
|
186
|
+
const titles = titleQuery(query, input, question === true);
|
|
187
|
+
if (titles)
|
|
188
|
+
for (const meeting of await store.meetings.meetings({
|
|
189
|
+
accountId: account.id,
|
|
190
|
+
query: titles,
|
|
191
|
+
...(input.since === undefined ? {} : { since: input.since }),
|
|
192
|
+
...(input.until === undefined ? {} : { until: input.until }),
|
|
193
|
+
limit: window + 1,
|
|
194
|
+
}))
|
|
195
|
+
if (!exact || holdsExactly(query.root, titleWords(meeting.title ?? "")))
|
|
196
|
+
keep({ item: titleItem(account, meeting, text), tier: 1, started: meeting.startedAt ?? 0 });
|
|
197
|
+
let after;
|
|
198
|
+
let rows = Math.min(PAGE_ROWS, window + 1);
|
|
199
|
+
for (let page = 1;; page++) {
|
|
200
|
+
let found;
|
|
201
|
+
try {
|
|
202
|
+
found = await store.meetings.searchHits(query, {
|
|
203
|
+
...input,
|
|
204
|
+
limit: rows,
|
|
205
|
+
...(after === undefined ? {} : { after }),
|
|
116
206
|
});
|
|
117
|
-
if (collected.items.length > request.limit) {
|
|
118
|
-
hitOffset++;
|
|
119
|
-
break;
|
|
120
|
-
}
|
|
121
207
|
}
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
208
|
+
catch (error) {
|
|
209
|
+
// Long summaries can pass the store's byte budget in a few rows; fewer rows a page still reads the account.
|
|
210
|
+
if (!(error instanceof CliError) || error.message !== READ_BUDGET_EXCEEDED || rows === 1)
|
|
211
|
+
throw error;
|
|
212
|
+
rows = Math.ceil(rows / 2);
|
|
213
|
+
page--;
|
|
214
|
+
continue;
|
|
127
215
|
}
|
|
128
|
-
|
|
129
|
-
if (
|
|
216
|
+
signal?.throwIfAborted();
|
|
217
|
+
if (found.coverage.indexing === "pending")
|
|
218
|
+
indexing = "pending";
|
|
219
|
+
for (const hit of found.items)
|
|
220
|
+
if (keep({
|
|
221
|
+
item: meetingItem(account, hit, text),
|
|
222
|
+
tier: hit.match === "corrected" ? 2 : 1,
|
|
223
|
+
started: hit.source?.startedAt ?? 0,
|
|
224
|
+
}))
|
|
225
|
+
passages++;
|
|
226
|
+
// Titles rank among the passages, so the passages alone must reach past the page.
|
|
227
|
+
if (passages > window || !found.hasMore || found.nextCursor === null)
|
|
130
228
|
break;
|
|
229
|
+
if (page === MOST_PAGES) {
|
|
230
|
+
hasMore = true;
|
|
231
|
+
break;
|
|
232
|
+
}
|
|
233
|
+
after = found.nextCursor;
|
|
131
234
|
}
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
/** Opt-in fusion of the existing unified ranking and one explicitly scoped meeting archive. */
|
|
135
|
-
export const searchAllIncludingMeetings = async (store, account, request, messenger = {}, searchMessages, meaning) => {
|
|
136
|
-
whole(request.limit, 1, 1000, "limit");
|
|
137
|
-
if (request.maxMeetings !== "all")
|
|
138
|
-
whole(request.maxMeetings ?? 100, 1, Number.MAX_SAFE_INTEGER, "maxMeetings");
|
|
139
|
-
const only = request.only ?? RESOURCES_SEARCHED_WITH_MEETINGS;
|
|
140
|
-
if (!only.length ||
|
|
141
|
-
only.some((resource) => !RESOURCES_SEARCHED_WITH_MEETINGS.includes(resource)))
|
|
142
|
-
throw new CliError("validation_error", "only takes messages, mail, notes, events and meetings");
|
|
143
|
-
if (request.meetingCursor) {
|
|
144
|
-
if (only.length !== 1 || only[0] !== "meetings")
|
|
145
|
-
throw new CliError("validation_error", "meeting cursor requires only: [meetings]");
|
|
146
|
-
whole(request.meetingCursor.accountId, 1, Number.MAX_SAFE_INTEGER, "cursor account id");
|
|
147
|
-
whole(request.meetingCursor.meetingOffset, 0, Number.MAX_SAFE_INTEGER - 2, "cursor meeting offset");
|
|
148
|
-
whole(request.meetingCursor.hitOffset, 0, Number.MAX_SAFE_INTEGER, "cursor hit offset");
|
|
149
|
-
}
|
|
150
|
-
cancelled(request.signal);
|
|
151
|
-
const others = { ...request, only: only.filter((one) => one !== "meetings") };
|
|
152
|
-
if (!only.includes("meetings")) {
|
|
153
|
-
const found = await searchAll(store, account, others, messenger, searchMessages, meaning);
|
|
154
|
-
cancelled(request.signal);
|
|
155
|
-
return found;
|
|
156
|
-
}
|
|
157
|
-
// Meetings rank with the rest, so a later page is the same merge read deeper, then cut.
|
|
158
|
-
const offset = request.offset ?? 0;
|
|
159
|
-
const window = offset + request.limit;
|
|
160
|
-
const legacy = await searchAll(store, account, { ...others, offset: 0, limit: window }, messenger, searchMessages, meaning);
|
|
161
|
-
cancelled(request.signal);
|
|
162
|
-
const compiled = meetingQuery(request.text, request.exact);
|
|
163
|
-
if ("reason" in compiled)
|
|
164
|
-
return {
|
|
165
|
-
...legacy,
|
|
166
|
-
items: legacy.items.slice(offset),
|
|
167
|
-
skipped: [...legacy.skipped, { resource: "meetings", code: "validation_error", reason: compiled.reason }],
|
|
168
|
-
};
|
|
169
|
-
let meetings;
|
|
170
|
-
const meetingAccount = request.meetingAccount ?? account;
|
|
171
|
-
try {
|
|
172
|
-
meetings = await collectMeetings(store, meetingAccount, { ...request, limit: window }, compiled.query);
|
|
173
|
-
}
|
|
174
|
-
catch (error) {
|
|
175
|
-
if (codeOf(error) !== "not_found")
|
|
176
|
-
throw error;
|
|
177
|
-
return {
|
|
178
|
-
...legacy,
|
|
179
|
-
items: legacy.items.slice(offset),
|
|
180
|
-
skipped: [
|
|
181
|
-
...legacy.skipped,
|
|
182
|
-
{ resource: "meetings", code: "not_found", reason: "the selected meeting account is not stored" },
|
|
183
|
-
],
|
|
184
|
-
};
|
|
185
|
-
}
|
|
186
|
-
const ranked = new Map();
|
|
187
|
-
for (const list of [legacy.items, meetings.items.map(({ item }) => item)])
|
|
188
|
-
list.forEach((item, rank) => {
|
|
189
|
-
const key = item.kind === "meeting"
|
|
190
|
-
? JSON.stringify([item.kind, item.accountId, item.meetingId, item.scope, item.id])
|
|
191
|
-
: item.ref;
|
|
192
|
-
const held = ranked.get(key) ?? { item, score: 0 };
|
|
193
|
-
held.score += 1 / (RRF_K + rank + 1);
|
|
194
|
-
ranked.set(key, held);
|
|
195
|
-
});
|
|
196
|
-
const ordered = [...ranked.values()].sort((a, b) => b.score - a.score).map(({ item }) => item);
|
|
197
|
-
const items = ordered.slice(offset, window);
|
|
198
|
-
const returnedMeetings = ordered.slice(0, window).filter((item) => item.kind === "meeting").length;
|
|
199
|
-
const nextCursor = meetings.items[returnedMeetings]?.before ?? (!meetings.coverage.complete ? meetings.after : undefined);
|
|
200
|
-
const more = legacy.hasMore || ordered.length > window;
|
|
201
|
-
const { nextOffset: _, ...rest } = legacy;
|
|
235
|
+
// A title hit ranks as a passage that holds the words: by tier, then the newer meeting; sort keeps it before its own.
|
|
236
|
+
ranked.sort((one, other) => one.tier - other.tier || other.started - one.started);
|
|
202
237
|
return {
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
hasMore: more ? true : meetings.coverage.complete ? false : null,
|
|
206
|
-
...(more && window <= MAX_SEARCH_OFFSET ? { nextOffset: window } : {}),
|
|
207
|
-
searched: [...legacy.searched, "meetings"],
|
|
208
|
-
accounts: [
|
|
209
|
-
...legacy.accounts,
|
|
210
|
-
{ resource: "meetings", provider: meetingAccount.provider, account: meetingAccount.account },
|
|
211
|
-
],
|
|
212
|
-
meetings: { ...meetings.coverage, ...(nextCursor ? { nextCursor } : {}) },
|
|
238
|
+
ranked: ranked.slice(0, window),
|
|
239
|
+
coverage: { indexing, hasMore: hasMore || ranked.length > window },
|
|
213
240
|
};
|
|
214
241
|
};
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
242
|
+
const meetingItem = (account, hit, query) => ({
|
|
243
|
+
kind: "meeting",
|
|
244
|
+
ref: formatMeetingReference({ type: "meeting", accountId: account.id, meetingId: hit.meetingId }),
|
|
245
|
+
provider: account.provider,
|
|
246
|
+
account: account.account,
|
|
247
|
+
accountId: account.id,
|
|
248
|
+
title: hit.source?.title ?? null,
|
|
249
|
+
timestamp: typeof hit.source?.startedAt === "number" ? new Date(hit.source.startedAt).toISOString() : null,
|
|
250
|
+
// Centred on the words the index matched: another form, a garbled spelling, never a word only under NOT.
|
|
251
|
+
text: hit.matchedWords?.length
|
|
252
|
+
? excerpt(hit.text, hit.matchedWords.join(" "), 240, { literal: true })
|
|
253
|
+
: excerpt(hit.text, query),
|
|
254
|
+
meetingId: hit.meetingId,
|
|
255
|
+
scope: hit.scope,
|
|
256
|
+
id: hit.id,
|
|
257
|
+
startMs: hit.startMs,
|
|
258
|
+
foundBy: ["words"],
|
|
259
|
+
...(hit.match === "corrected" ? { match: hit.match, corrections: hit.corrections ?? [] } : {}),
|
|
260
|
+
...(hit.scope === "transcript"
|
|
228
261
|
? {
|
|
229
|
-
|
|
230
|
-
|
|
262
|
+
cueRef: hit.ref,
|
|
263
|
+
speakerName: hit.speakerName ?? null,
|
|
264
|
+
language: hit.language ?? null,
|
|
265
|
+
...(hit.line === undefined ? {} : { line: hit.line, linesTotal: hit.linesTotal }),
|
|
231
266
|
}
|
|
232
|
-
:
|
|
233
|
-
};
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
const entries = entriesOfList(source, await listContextOf(store, account, messenger.app));
|
|
250
|
-
// Any provider's import may write business data, so its accounts are the ones that hold some, whatever their kind.
|
|
251
|
-
const imported = only.includes("business") ? new Set((await store.business.accounts()).map(keyOf)) : new Set();
|
|
252
|
-
const holdsBusiness = (one) => imported.has(keyOf(one));
|
|
253
|
-
const { skipped } = fitting(entries, only.filter((one) => one !== "business"), "search all", (kind) => `--only leaves ${kind} out`, holdsBusiness);
|
|
254
|
-
const named = (resource) => [
|
|
255
|
-
...new Map(entries
|
|
256
|
-
.flatMap(({ accounts }) => accounts)
|
|
257
|
-
.filter((one) => (resource === "business" ? holdsBusiness(one) : listedHolds(one, resource)))
|
|
258
|
-
.map(({ provider, account }) => [`${provider}\u0000${account}`, { provider, account }])).values(),
|
|
259
|
-
];
|
|
260
|
-
const meetings = await holdingMeetings(store, named("meetings"));
|
|
261
|
-
const empty = named("meetings")
|
|
262
|
-
.filter((one) => !meetings.some(({ provider, account }) => provider === one.provider && account === one.account))
|
|
263
|
-
.map(({ provider, account }) => ({
|
|
264
|
-
source: `${provider}:${account}`,
|
|
265
|
-
code: "not_found",
|
|
266
|
-
reason: "no meetings stored for it",
|
|
267
|
-
}));
|
|
268
|
-
if (only.includes("meetings") && meetings.length > 1)
|
|
269
|
-
throw new CliError("validation_error", `--source names several meeting accounts; search all reads one: ${meetings.map(({ provider, account }) => `${provider}:${account}`).join(", ")}`);
|
|
270
|
-
const read = only.filter((resource) => named(resource).length > 0);
|
|
271
|
-
if (read.includes("meetings") && request.offset !== undefined)
|
|
272
|
-
throw new CliError("validation_error", "--offset pages messages, mail and notes; not with a meeting account yet");
|
|
273
|
-
const found = await searchAllIncludingMeetings(store, account, {
|
|
274
|
-
...request,
|
|
275
|
-
only: read,
|
|
276
|
-
scope: {
|
|
277
|
-
messages: named("messages"),
|
|
278
|
-
mail: named("mail"),
|
|
279
|
-
notes: named("notes"),
|
|
280
|
-
events: named("events"),
|
|
281
|
-
crm: named("crm"),
|
|
282
|
-
business: named("business"),
|
|
283
|
-
},
|
|
284
|
-
...(meetings[0] ? { meetingAccount: meetings[0] } : {}),
|
|
285
|
-
}, messenger, searchMessages, meaning);
|
|
286
|
-
const unnamed = only
|
|
287
|
-
.filter((resource) => !read.includes(resource))
|
|
288
|
-
.map((resource) => ({ resource, code: "not_found", reason: `--source names no ${resource} account` }));
|
|
289
|
-
return { ...found, skipped: [...skipped, ...empty, ...unnamed, ...found.skipped] };
|
|
290
|
-
};
|
|
267
|
+
: {}),
|
|
268
|
+
});
|
|
269
|
+
const titleItem = (account, meeting, query) => ({
|
|
270
|
+
kind: "meeting",
|
|
271
|
+
ref: formatMeetingReference({ type: "meeting", accountId: account.id, meetingId: meeting.id }),
|
|
272
|
+
provider: account.provider,
|
|
273
|
+
account: account.account,
|
|
274
|
+
accountId: account.id,
|
|
275
|
+
title: meeting.title,
|
|
276
|
+
timestamp: meeting.startedAt === null ? null : new Date(meeting.startedAt).toISOString(),
|
|
277
|
+
text: excerpt(meeting.title ?? "", query),
|
|
278
|
+
meetingId: meeting.id,
|
|
279
|
+
scope: "title",
|
|
280
|
+
id: meeting.id,
|
|
281
|
+
startMs: null,
|
|
282
|
+
foundBy: ["title"],
|
|
283
|
+
});
|