@wirecat/cli-core 0.619.0 → 0.620.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 +114 -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 +18 -0
- package/dist/cli/search-harder-consents-command.js +83 -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/domain/models.d.ts +2 -0
- 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 +2 -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.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 +118 -24
- package/dist/services/search-harder.d.ts +64 -0
- package/dist/services/search-harder.js +194 -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 +13 -5
- 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/package.json +1 -1
- package/parity.json +26 -12
|
@@ -0,0 +1,133 @@
|
|
|
1
|
+
import { dayBoundary } from "@wirecat/cli-base/query";
|
|
2
|
+
const DAY = 86_400_000;
|
|
3
|
+
const SPAN = { start: 0, end: 0 };
|
|
4
|
+
// `\b` knows only ASCII letters, so Russian words need their own edges.
|
|
5
|
+
const phrase = (source) => new RegExp(`(?<![\\p{L}\\p{N}])(?:${source})(?![\\p{L}\\p{N}])`, "giu");
|
|
6
|
+
const MONTHS = [
|
|
7
|
+
/january|январ\p{L}*/u,
|
|
8
|
+
/february|феврал\p{L}*/u,
|
|
9
|
+
/march|март\p{L}*/u,
|
|
10
|
+
/april|апрел\p{L}*/u,
|
|
11
|
+
/may|ма[йяе]/u,
|
|
12
|
+
/june|июн\p{L}*/u,
|
|
13
|
+
/july|июл\p{L}*/u,
|
|
14
|
+
/august|август\p{L}*/u,
|
|
15
|
+
/september|сентябр\p{L}*/u,
|
|
16
|
+
/october|октябр\p{L}*/u,
|
|
17
|
+
/november|ноябр\p{L}*/u,
|
|
18
|
+
/december|декабр\p{L}*/u,
|
|
19
|
+
];
|
|
20
|
+
const MONTH = MONTHS.map(({ source }) => source).join("|");
|
|
21
|
+
const ORDINAL = "(?:st|nd|rd|th)?";
|
|
22
|
+
const DATED_MONTH = phrase(`(?:(\\d{1,2})${ORDINAL}\\s+(?:of\\s+)?)?(${MONTH})(?:\\s+(\\d{1,2})${ORDINAL}(?!\\p{N}))?(?:,?\\s+(\\d{4}))?`);
|
|
23
|
+
// "May I…" and "it may" are not the month; "in May", "May 5" and "May 2025" are.
|
|
24
|
+
const MONTH_BEFORE_MAY = /(?:in|of|since|during|until|by|early|late|mid|from|through)\s+$/iu;
|
|
25
|
+
const monthOf = (name) => MONTHS.findIndex(({ source }) => new RegExp(`^(?:${source})$`, "iu").test(name));
|
|
26
|
+
const monthDays = (year, month) => [Date.UTC(year, month, 1), Date.UTC(year, month + 1, 0)];
|
|
27
|
+
const weekDays = (day) => {
|
|
28
|
+
const sinceMonday = (new Date(day).getUTCDay() + 6) % 7;
|
|
29
|
+
return [day - sinceMonday * DAY, day + (6 - sinceMonday) * DAY];
|
|
30
|
+
};
|
|
31
|
+
const yearDays = (year) => [Date.UTC(year, 0, 1), Date.UTC(year, 11, 31)];
|
|
32
|
+
const unitDays = (unit, day) => {
|
|
33
|
+
const at = new Date(day);
|
|
34
|
+
if (/^(?:day|дн|день)/iu.test(unit))
|
|
35
|
+
return [day, day];
|
|
36
|
+
if (/^(?:week|недел)/iu.test(unit))
|
|
37
|
+
return weekDays(day);
|
|
38
|
+
if (/^(?:month|месяц)/iu.test(unit))
|
|
39
|
+
return monthDays(at.getUTCFullYear(), at.getUTCMonth());
|
|
40
|
+
return yearDays(at.getUTCFullYear());
|
|
41
|
+
};
|
|
42
|
+
const unitsBack = (unit, count, today) => {
|
|
43
|
+
const at = new Date(today);
|
|
44
|
+
if (/^(?:day|дн|день)/iu.test(unit))
|
|
45
|
+
return today - count * DAY;
|
|
46
|
+
if (/^(?:week|недел)/iu.test(unit))
|
|
47
|
+
return today - 7 * count * DAY;
|
|
48
|
+
if (/^(?:month|месяц)/iu.test(unit))
|
|
49
|
+
return Date.UTC(at.getUTCFullYear(), at.getUTCMonth() - count, 1);
|
|
50
|
+
return Date.UTC(at.getUTCFullYear() - count, 0, 1);
|
|
51
|
+
};
|
|
52
|
+
const RULES = [
|
|
53
|
+
[
|
|
54
|
+
/(?<!\p{N})(\d{4})-(\d{2})-(\d{2})(?!\p{N})/gu,
|
|
55
|
+
(part) => {
|
|
56
|
+
const day = Date.UTC(Number(part(1)), Number(part(2)) - 1, Number(part(3)));
|
|
57
|
+
return [day, day];
|
|
58
|
+
},
|
|
59
|
+
],
|
|
60
|
+
[phrase("today|tonight|сегодня"), (_, today) => [today, today]],
|
|
61
|
+
[phrase("yesterday|вчера"), (_, today) => [today - DAY, today - DAY]],
|
|
62
|
+
[phrase("позавчера"), (_, today) => [today - 2 * DAY, today - 2 * DAY]],
|
|
63
|
+
[
|
|
64
|
+
phrase(/(\d+|an?|one)\s+(days?|weeks?|months?|years?)\s+ago|(\d+)\s+(дн\p{L}*|день|недел\p{L}*|месяц\p{L}*|год\p{L}*|лет)\s+назад/u
|
|
65
|
+
.source),
|
|
66
|
+
(part, today) => {
|
|
67
|
+
const n = Number.parseInt(part(1) || part(3), 10) || 1;
|
|
68
|
+
const word = part(2) || part(4);
|
|
69
|
+
return unitDays(word, unitsBack(word, n, today));
|
|
70
|
+
},
|
|
71
|
+
],
|
|
72
|
+
[
|
|
73
|
+
phrase("(?:last|past)\\s+(\\d+)\\s+days|(?:последние|за\\s+последние)\\s+(\\d+)\\s+дн\\p{L}*"),
|
|
74
|
+
(part, today) => [today - (Number(part(1) || part(2)) - 1) * DAY, today],
|
|
75
|
+
],
|
|
76
|
+
[
|
|
77
|
+
phrase("(last|past|previous|this)\\s+(week|weekend|month|year)"),
|
|
78
|
+
(part, today) => {
|
|
79
|
+
const last = part(1).toLowerCase() !== "this";
|
|
80
|
+
const unit = part(2);
|
|
81
|
+
if (unit.toLowerCase() === "weekend") {
|
|
82
|
+
const [monday] = weekDays(last ? today - 7 * DAY : today);
|
|
83
|
+
return [monday + 5 * DAY, monday + 6 * DAY];
|
|
84
|
+
}
|
|
85
|
+
return unitDays(unit, last ? unitsBack(unit, 1, today) : today);
|
|
86
|
+
},
|
|
87
|
+
],
|
|
88
|
+
[
|
|
89
|
+
phrase(/(?:на|в)\s+(прошл|эт)\p{L}*\s+(недел\p{L}*|месяц\p{L}*|год\p{L}*)/u.source),
|
|
90
|
+
(part, today) => unitDays(part(2), part(1).toLowerCase() === "эт" ? today : unitsBack(part(2), 1, today)),
|
|
91
|
+
],
|
|
92
|
+
[
|
|
93
|
+
DATED_MONTH,
|
|
94
|
+
(part, today, match) => {
|
|
95
|
+
const [name, year] = [part(2), part(4)];
|
|
96
|
+
const day = Number(part(1) || part(3) || 0);
|
|
97
|
+
if (/^may$/iu.test(name) && !day && !year && !MONTH_BEFORE_MAY.test(match.input.slice(0, match.index)))
|
|
98
|
+
return;
|
|
99
|
+
const month = monthOf(name);
|
|
100
|
+
const now = new Date(today);
|
|
101
|
+
// A month without a year is its last one up to today: asked in March, "December" is last December.
|
|
102
|
+
const lastYear = month > now.getUTCMonth() || (month === now.getUTCMonth() && day > now.getUTCDate());
|
|
103
|
+
const y = year ? Number(year) : now.getUTCFullYear() - (lastYear ? 1 : 0);
|
|
104
|
+
const [first, last] = monthDays(y, month);
|
|
105
|
+
if (!day || day > new Date(last).getUTCDate())
|
|
106
|
+
return [first, last];
|
|
107
|
+
return [Date.UTC(y, month, day), Date.UTC(y, month, day)];
|
|
108
|
+
},
|
|
109
|
+
],
|
|
110
|
+
];
|
|
111
|
+
/**
|
|
112
|
+
* The period a question names — a date, a month, "last week", «в прошлом месяце» — from the first day any phrase names
|
|
113
|
+
* to the last; undefined when it names none. Read as `zone`'s calendar on `now`.
|
|
114
|
+
*/
|
|
115
|
+
export const questionPeriod = (text, now, zone) => {
|
|
116
|
+
const today = Date.parse(`${new Intl.DateTimeFormat("en-CA", { timeZone: zone }).format(now)}T00:00:00Z`);
|
|
117
|
+
const found = [];
|
|
118
|
+
for (const [pattern, days] of RULES)
|
|
119
|
+
for (const match of text.matchAll(pattern)) {
|
|
120
|
+
const span = days((n) => match[n] ?? "", today, match);
|
|
121
|
+
if (span)
|
|
122
|
+
found.push(span);
|
|
123
|
+
}
|
|
124
|
+
// "In March this year" means March: a span that holds another one named beside it only gives that one its year.
|
|
125
|
+
const inner = found.filter(([first, last]) => !found.some(([f, l]) => f >= first && l <= last && l - f < last - first));
|
|
126
|
+
if (!inner.length)
|
|
127
|
+
return;
|
|
128
|
+
const iso = (day) => new Date(day).toISOString().slice(0, 10);
|
|
129
|
+
return {
|
|
130
|
+
from: dayBoundary(iso(inner.reduce((min, [first]) => Math.min(min, first), Infinity)), zone, false, SPAN),
|
|
131
|
+
to: dayBoundary(iso(inner.reduce((max, [, last]) => Math.max(max, last), -Infinity)), zone, true, SPAN),
|
|
132
|
+
};
|
|
133
|
+
};
|
package/dist/sends/buttons.d.ts
CHANGED
|
@@ -7,6 +7,8 @@ export interface Pressed {
|
|
|
7
7
|
messageId: Id;
|
|
8
8
|
button: Button;
|
|
9
9
|
}
|
|
10
|
+
/** Callback data of a button only a hand on the owner's own device may press, such as a review decision. */
|
|
11
|
+
export declare const OWNER_HAND_ONLY_PREFIX = "wcr";
|
|
10
12
|
/** The button by its number, counted from 1 across the rows as `messages show` prints them, or by its exact text. */
|
|
11
13
|
export declare const pickButton: (keyboard: Button[][], typed: string) => {
|
|
12
14
|
row: number;
|
package/dist/sends/buttons.js
CHANGED
|
@@ -2,6 +2,8 @@ import { CliError } from "@wirecat/cli-base";
|
|
|
2
2
|
import { capability } from "../ports/messenger.js";
|
|
3
3
|
import { guardedWrite } from "./guarded.js";
|
|
4
4
|
import { newOperationId, newSendId } from "./send-id.js";
|
|
5
|
+
/** Callback data of a button only a hand on the owner's own device may press, such as a review decision. */
|
|
6
|
+
export const OWNER_HAND_ONLY_PREFIX = "wcr";
|
|
5
7
|
const REFUSED = {
|
|
6
8
|
contact: "it would hand your phone number to the bot",
|
|
7
9
|
location: "it would hand your location to the bot",
|
|
@@ -40,9 +42,12 @@ export const guardedPress = async (guard, connection, { chat, message, button: t
|
|
|
40
42
|
throw new CliError("validation_error", `not pressed: "${button.text}" is a ${button.kind} button — ${refused}`);
|
|
41
43
|
if (button.kind !== "callback")
|
|
42
44
|
throw new CliError("validation_error", `not pressed: "${button.text}" is a ${button.kind} button, which this CLI cannot press`);
|
|
45
|
+
if (button.data?.startsWith(OWNER_HAND_ONLY_PREFIX))
|
|
46
|
+
throw new CliError("permission_error", `not pressed: "${button.text}" decides something for the owner — press it by hand in the messenger`, { reason: "press.owner-hand-only" });
|
|
43
47
|
const operationId = newOperationId();
|
|
44
48
|
await guardedWrite(guard, { operationId, chatId, kind: "reaction", messageId: message, key: "messages.press" }, () => press(chatId, message, row, column));
|
|
45
|
-
|
|
49
|
+
const { data: _data, ...shown } = button;
|
|
50
|
+
return { operationId, chatId, messageId: message, button: shown };
|
|
46
51
|
};
|
|
47
52
|
/** Starting a bot sends it a message — its start command — so it is guarded like one. */
|
|
48
53
|
export const guardedStart = async (guard, connection, { chat, payload, sendId }) => {
|
|
@@ -43,6 +43,11 @@ export type EnrichRun = {
|
|
|
43
43
|
reason_id?: EnrichmentReasonId;
|
|
44
44
|
};
|
|
45
45
|
export type KeySource = "keyring" | "file" | "env" | "given";
|
|
46
|
+
/** The provider's key and where it came from; it never leaves this process. */
|
|
47
|
+
export declare const keyLookup: (options: Pick<EnrichOptions, "env" | "app" | "keyring" | "key">, setting: Pick<EnrichmentSetting, "provider" | "base_url">) => {
|
|
48
|
+
key: string;
|
|
49
|
+
source: KeySource;
|
|
50
|
+
} | undefined;
|
|
46
51
|
export declare const keyVariable: (provider: string) => string;
|
|
47
52
|
/**
|
|
48
53
|
* Sends records with no enrichment of their current text to the provider the owner consented to, in batches, and
|
|
@@ -91,7 +91,7 @@ const recordsData = (batch) => JSON.stringify(batch.map((record, i) => ({
|
|
|
91
91
|
text: record.text.slice(0, MAX_INPUT_CHARS),
|
|
92
92
|
})));
|
|
93
93
|
/** The provider's key and where it came from; it never leaves this process. */
|
|
94
|
-
const keyLookup = (options, setting) => {
|
|
94
|
+
export const keyLookup = (options, setting) => {
|
|
95
95
|
if (options.key) {
|
|
96
96
|
const key = options.key(setting.provider);
|
|
97
97
|
return key === undefined ? undefined : { key, source: "given" };
|
package/dist/services/index.d.ts
CHANGED
|
@@ -211,9 +211,11 @@ export { approveAsTask, type ProposalTaskStore, proposalSource } from "./proposa
|
|
|
211
211
|
export { type Decided, type Decision, emptyProposalRegistry, FACT_SUMMARIES, ORGANIZATION_ADD_KIND, ORGANIZATION_RENAME_KIND, type OrganizationProposal, type OrganizationRenameProposal, type ProposalFilter, type ProposalKind, type ProposalRegistry, type ProposalRow, parseProposalIds, proposalRegistry, } from "./proposals/index.js";
|
|
212
212
|
export type { RetentionQuery, RetentionService } from "./retention.js";
|
|
213
213
|
export { retentionService } from "./retention.js";
|
|
214
|
-
export { RESOURCES_SEARCHED, type SearchAllFound, type SearchAllItem, type SearchAllMessenger, type SearchAllRequest, type SearchedResource, searchAll, } from "./search-all.js";
|
|
215
|
-
export { type MeetingSearchCoverage, type MeetingSearchCursor, type
|
|
214
|
+
export { RESOURCES_SEARCHED, type SearchAllFound, type SearchAllItem, type SearchAllMessenger, type SearchAllRecordItem, type SearchAllRequest, type SearchedResource, searchAll, } from "./search-all.js";
|
|
215
|
+
export { type MeetingSearchCoverage, type MeetingSearchCursor, type ResourceWithMeetings, type SearchAllIncludingMeetingsFound, type SearchAllIncludingMeetingsRequest, searchAllIncludingMeetings, } from "./search-all-deprecated.js";
|
|
216
|
+
export { type MeetingAccountCoverage, type MeetingSearchItem, MOST_HITS_PER_MEETING, } from "./search-all-meetings.js";
|
|
216
217
|
export { CATCH_UP_BOUNDS, type CatchUpOptions, type CatchUpResult, catchUpSearch, validateCatchUp, } from "./search-catchup.js";
|
|
218
|
+
export { HARDER_REASON_IDS, type HarderOptions, type HarderReasonId, type HarderResult, readHarderSetting, writeHarderSetting, } from "./search-harder.js";
|
|
217
219
|
export { accountsOfKind, groupLockOf, listContextOf, type SearchKind } from "./search-kind.js";
|
|
218
220
|
export type { SearchRefreshed, SyncOptions } from "./search-refresh.js";
|
|
219
221
|
export { SYNC_BOUNDS, SYNC_KEY } from "./search-refresh.js";
|
package/dist/services/index.js
CHANGED
|
@@ -163,8 +163,10 @@ export { approveAsTask, proposalSource } from "./proposal-tasks.js";
|
|
|
163
163
|
export { emptyProposalRegistry, FACT_SUMMARIES, ORGANIZATION_ADD_KIND, ORGANIZATION_RENAME_KIND, parseProposalIds, proposalRegistry, } from "./proposals/index.js";
|
|
164
164
|
export { retentionService } from "./retention.js";
|
|
165
165
|
export { RESOURCES_SEARCHED, searchAll, } from "./search-all.js";
|
|
166
|
-
export {
|
|
166
|
+
export { searchAllIncludingMeetings, } from "./search-all-deprecated.js";
|
|
167
|
+
export { MOST_HITS_PER_MEETING, } from "./search-all-meetings.js";
|
|
167
168
|
export { CATCH_UP_BOUNDS, catchUpSearch, validateCatchUp, } from "./search-catchup.js";
|
|
169
|
+
export { HARDER_REASON_IDS, readHarderSetting, writeHarderSetting, } from "./search-harder.js";
|
|
168
170
|
export { accountsOfKind, groupLockOf, listContextOf } from "./search-kind.js";
|
|
169
171
|
export { SYNC_BOUNDS, SYNC_KEY } from "./search-refresh.js";
|
|
170
172
|
export { SERVER_BOUNDS, SERVER_SEARCH_KEY, } from "./server-search.js";
|
|
@@ -12,7 +12,6 @@ import type { MeaningSkipped, RerankSkipped } from "./messages-discovery.js";
|
|
|
12
12
|
import type { MessageStats, QueryMetadata, SearchCoverage, StatsGrouping } from "./messages-search.js";
|
|
13
13
|
import type { PictureHit } from "./pictures.js";
|
|
14
14
|
import { type SearchAllFound, type SearchAllRequest } from "./search-all.js";
|
|
15
|
-
import { type SearchAllIncludingMeetingsFound, type SearchAllWithMeetingsRequest } from "./search-all-meetings.js";
|
|
16
15
|
import type { SearchKind } from "./search-kind.js";
|
|
17
16
|
import { type SearchRefreshed, type SyncOptions } from "./search-refresh.js";
|
|
18
17
|
import { type Backend, type HitSource, type ServerOptions, type ServerSearched } from "./server-search.js";
|
|
@@ -222,10 +221,8 @@ export interface MessagesService {
|
|
|
222
221
|
keepDownloaded(chat: string, message: Id, files: readonly DownloadedFile[]): Promise<number>;
|
|
223
222
|
/** From the local store only; never asks the messenger. */
|
|
224
223
|
search(query: SearchQuery): Promise<SearchFound>;
|
|
225
|
-
/**
|
|
224
|
+
/** Every kind the store holds at once; messages with the same server step `search` takes. */
|
|
226
225
|
searchAll(request: SearchAllRequest): Promise<SearchAllFound>;
|
|
227
|
-
/** `searchAll` plus one meeting account's transcripts, chat and summaries. */
|
|
228
|
-
searchAllWithMeetings(request: SearchAllWithMeetingsRequest): Promise<SearchAllIncludingMeetingsFound>;
|
|
229
226
|
/** Counts of what a strict query matches, by chat, sender, day or hour; from the local store only. */
|
|
230
227
|
stats(query: SearchQuery & {
|
|
231
228
|
by: StatsGrouping;
|
|
@@ -16,7 +16,6 @@ import { accountOf, keyOf, searchStore, statsStore, topUp } from "./messages-arc
|
|
|
16
16
|
import { meaningLane } from "./messages-meaning.js";
|
|
17
17
|
import { rerankLane } from "./messages-rerank.js";
|
|
18
18
|
import { searchAll } from "./search-all.js";
|
|
19
|
-
import { searchAllWithMeetings, } from "./search-all-meetings.js";
|
|
20
19
|
import { searchRecordOf } from "./search-record.js";
|
|
21
20
|
import { refreshSearch, withRefresh } from "./search-refresh.js";
|
|
22
21
|
import { searchServer, sourceKey, } from "./server-search.js";
|
|
@@ -269,7 +268,6 @@ export const messagesService = (deps) => {
|
|
|
269
268
|
});
|
|
270
269
|
},
|
|
271
270
|
searchAll: (request) => inStore((store, account) => searchAll(store, account, request, deps.messenger, unifiedMessages(store, account), meaningLane(deps))),
|
|
272
|
-
searchAllWithMeetings: (request) => inStore((store, account) => searchAllWithMeetings(store, account, request, deps.messenger, unifiedMessages(store, account), meaningLane(deps))),
|
|
273
271
|
stats: (query) => inStore(async (store, account) => {
|
|
274
272
|
const refreshed = await refreshSearch(deps, query);
|
|
275
273
|
const stats = await statsStore(store, account, query, deps.messenger);
|
|
@@ -14,12 +14,12 @@ export declare const metadataService: (deps: ServiceDeps) => {
|
|
|
14
14
|
dryRun?: boolean;
|
|
15
15
|
}) => Promise<{
|
|
16
16
|
items: ({
|
|
17
|
+
error?: undefined;
|
|
17
18
|
chatId: string;
|
|
18
19
|
tags: import("../domain/channel-tags.js").ChannelTagMatch[];
|
|
19
20
|
algorithm: string;
|
|
20
21
|
fetchedAt: string | null;
|
|
21
22
|
source: string;
|
|
22
|
-
error?: undefined;
|
|
23
23
|
} | {
|
|
24
24
|
tags?: undefined;
|
|
25
25
|
algorithm?: undefined;
|
|
@@ -100,6 +100,8 @@ export declare const eventsOnce: (store: MessageStore, filter: EventFilter, limi
|
|
|
100
100
|
}>;
|
|
101
101
|
/** The stored accounts of `scopes`, or of the asked account's own scope; the asked account must be stored. */
|
|
102
102
|
export declare const readableAccounts: (store: MessageStore, asked: AccountKey, scopes?: readonly AccountScope[]) => Promise<StoredAccount[]>;
|
|
103
|
+
/** `scopes`, or the asked account's own scope: what a read that belongs to no account may show. */
|
|
104
|
+
export declare const readableScopes: (store: MessageStore, asked: AccountKey, scopes?: readonly AccountScope[]) => Promise<readonly AccountScope[]>;
|
|
103
105
|
/**
|
|
104
106
|
* The accounts each identity is read in, among `readable` only: for the messenger asked, only the account asked
|
|
105
107
|
* about — a second account of the same messenger is somebody else's view; for a linked messenger, every readable
|
|
@@ -123,7 +125,7 @@ export declare const recordContext: (store: MessageStore, record: PersonRecord,
|
|
|
123
125
|
key: AccountKey;
|
|
124
126
|
scope: AccountScope;
|
|
125
127
|
identity: LinkedIdentity;
|
|
126
|
-
}[], readable: readonly StoredAccount[], { messages, bytes, since, now, calendarIds }?: ContextOptions) => Promise<Omit<PersonContext, "person">>;
|
|
128
|
+
}[], readable: readonly StoredAccount[], { messages, bytes, since, now, calendarIds, scopes, }?: ContextOptions) => Promise<Omit<PersonContext, "person">>;
|
|
127
129
|
/** `max:Ana` names a person in another messenger of this store; a reference with no prefix, this one. */
|
|
128
130
|
export declare const identityIn: (store: MessageStore, asked: AccountKey, reference: string) => Promise<IdentityRef>;
|
|
129
131
|
export declare const CHAT_MESSAGES = 20;
|
|
@@ -81,15 +81,20 @@ export const eventsOnce = async (store, filter, limit) => {
|
|
|
81
81
|
return { items, cut: true };
|
|
82
82
|
};
|
|
83
83
|
const nameOf = ({ provider, account }) => `${provider}:${account}`;
|
|
84
|
-
|
|
85
|
-
export const readableAccounts = async (store, asked, scopes) => {
|
|
84
|
+
const allowedOf = async (store, asked, scopes) => {
|
|
86
85
|
const stored = await store.accounts.storedAccounts();
|
|
87
86
|
const own = stored.find((one) => nameOf(one) === nameOf(asked));
|
|
88
87
|
if (!own || (asked.scope !== undefined && asked.scope !== own.scope))
|
|
89
88
|
throw new CliError("not_found", `no ${asked.provider} account ${asked.account} in the store`);
|
|
90
|
-
|
|
89
|
+
return { stored, allowed: scopes ?? [own.scope] };
|
|
90
|
+
};
|
|
91
|
+
/** The stored accounts of `scopes`, or of the asked account's own scope; the asked account must be stored. */
|
|
92
|
+
export const readableAccounts = async (store, asked, scopes) => {
|
|
93
|
+
const { stored, allowed } = await allowedOf(store, asked, scopes);
|
|
91
94
|
return stored.filter((one) => allowed.includes(one.scope));
|
|
92
95
|
};
|
|
96
|
+
/** `scopes`, or the asked account's own scope: what a read that belongs to no account may show. */
|
|
97
|
+
export const readableScopes = async (store, asked, scopes) => (await allowedOf(store, asked, scopes)).allowed;
|
|
93
98
|
/**
|
|
94
99
|
* The accounts each identity is read in, among `readable` only: for the messenger asked, only the account asked
|
|
95
100
|
* about — a second account of the same messenger is somebody else's view; for a linked messenger, every readable
|
|
@@ -123,8 +128,14 @@ export const personContext = async (store, asked, reference, options = {}) => {
|
|
|
123
128
|
* `personContext` of a person already found, read in the identities and accounts `reads` names; their calendar
|
|
124
129
|
* events in every calendar account of `readable`.
|
|
125
130
|
*/
|
|
126
|
-
export const recordContext = async (store, record, reads, readable, { messages = CONTEXT_MESSAGES, bytes = CONTEXT_BYTES, since, now = Date.now(), calendarIds } = {}) => {
|
|
131
|
+
export const recordContext = async (store, record, reads, readable, { messages = CONTEXT_MESSAGES, bytes = CONTEXT_BYTES, since, now = Date.now(), calendarIds, scopes, } = {}) => {
|
|
127
132
|
const recent = (message) => since === undefined || Date.parse(message.timestamp) >= since;
|
|
133
|
+
// A chat pinned to the other side of the owner's life stays out even when its account is readable.
|
|
134
|
+
const allowed = new Set(scopes ?? readable.map((one) => one.scope));
|
|
135
|
+
const inScope = async (key, scope, hits) => {
|
|
136
|
+
const pinned = await store.chats.chatScopes(key, [...new Set(hits.map((hit) => hit.chatId))]);
|
|
137
|
+
return hits.filter((hit) => allowed.has(pinned.get(hit.chatId) ?? scope));
|
|
138
|
+
};
|
|
128
139
|
const shared = [];
|
|
129
140
|
const notRead = [];
|
|
130
141
|
const direct = [];
|
|
@@ -133,8 +144,8 @@ export const recordContext = async (store, record, reads, readable, { messages =
|
|
|
133
144
|
const theirs = [];
|
|
134
145
|
const mentions = [];
|
|
135
146
|
let cut = false;
|
|
136
|
-
for (const { key, identity } of reads) {
|
|
137
|
-
const chats = await store.chats.chatsWith(key, identity.id);
|
|
147
|
+
for (const { key, scope, identity } of reads) {
|
|
148
|
+
const chats = (await store.chats.chatsWith(key, identity.id)).filter((chat) => allowed.has(chat.scope ?? scope));
|
|
138
149
|
for (const chat of chats) {
|
|
139
150
|
shared.push({ ...key, chatId: chat.id, title: chat.title, kind: chat.kind, lastMessageAt: chat.lastMessageAt });
|
|
140
151
|
}
|
|
@@ -175,10 +186,12 @@ export const recordContext = async (store, record, reads, readable, { messages =
|
|
|
175
186
|
cut ||= mail.hasMore;
|
|
176
187
|
}
|
|
177
188
|
const written = await store.messages.find({ account: key, senders: [identity.id], limit: messages });
|
|
178
|
-
theirs.push(...
|
|
189
|
+
theirs.push(...(await inScope(key, scope, written.items))
|
|
190
|
+
.map((hit) => toContext(key, hit, hit.chatTitle ?? null))
|
|
191
|
+
.filter(recent));
|
|
179
192
|
cut ||= written.hasMore;
|
|
180
193
|
const named = await store.messages.mentioning(key, { id: identity.id, username: identity.username }, messages);
|
|
181
|
-
mentions.push(...named.items
|
|
194
|
+
mentions.push(...(await inScope(key, scope, named.items))
|
|
182
195
|
.filter((hit) => hit.senderId !== identity.id)
|
|
183
196
|
.map((hit) => toContext(key, hit, hit.chatTitle ?? null))
|
|
184
197
|
.filter(recent));
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type { Id, Provider } from "../domain/models.js";
|
|
2
2
|
import type { AccountKey, MessageStore, PreparationFact, PreparationNote, PreparationTask } from "../store/store.js";
|
|
3
|
-
import { type ContextMessage, type ContextOptions, type PersonContext } from "./person-context.js";
|
|
3
|
+
import { type AccountScope, type ContextMessage, type ContextOptions, type PersonContext } from "./person-context.js";
|
|
4
4
|
import { type PersonMeetingContextItem } from "./person-meeting-context.js";
|
|
5
5
|
export declare const PREPARE_BYTES: number;
|
|
6
6
|
export interface WaitingDialog {
|
|
@@ -37,13 +37,16 @@ export interface PersonPreparation extends PersonContext {
|
|
|
37
37
|
tasks: SectionCoverage & {
|
|
38
38
|
selection: "open, assigned to them in any role";
|
|
39
39
|
accounts: string[];
|
|
40
|
+
scopes: Scopes;
|
|
40
41
|
};
|
|
41
42
|
facts: SectionCoverage & {
|
|
42
43
|
selection: "accepted, about them or a project they are a member of";
|
|
44
|
+
scopes: Scopes;
|
|
43
45
|
};
|
|
44
46
|
/** `withheld` when the profile denies `contacts.notes.list`. */
|
|
45
47
|
notes: SectionCoverage & {
|
|
46
48
|
selection: "written by you, about them";
|
|
49
|
+
scopes: Scopes;
|
|
47
50
|
withheld?: "contacts.notes.list";
|
|
48
51
|
};
|
|
49
52
|
/** `accounts`: the ones their meetings came from. */
|
|
@@ -55,6 +58,7 @@ export interface PersonPreparation extends PersonContext {
|
|
|
55
58
|
};
|
|
56
59
|
};
|
|
57
60
|
}
|
|
61
|
+
type Scopes = readonly AccountScope[];
|
|
58
62
|
/**
|
|
59
63
|
* `contacts context` and what to know before talking to them: the one-to-one chats where they wrote last, open tasks,
|
|
60
64
|
* accepted facts, your notes and their recent meetings, each item with its reference. The messages keep their own
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { CliError } from "@wirecat/cli-base";
|
|
2
2
|
import { parseMeetingReference } from "../meetings/index.js";
|
|
3
|
-
import { CONTEXT_BYTES, CONTEXT_MESSAGES, personContext, readableAccounts, toContext, } from "./person-context.js";
|
|
3
|
+
import { CONTEXT_BYTES, CONTEXT_MESSAGES, personContext, readableAccounts, readableScopes, toContext, } from "./person-context.js";
|
|
4
4
|
import { personMeetingContext } from "./person-meeting-context.js";
|
|
5
5
|
export const PREPARE_BYTES = 96 * 1024;
|
|
6
6
|
const MEETINGS = 5;
|
|
@@ -51,7 +51,8 @@ export const personPreparation = async (store, asked, reference, options = {}) =
|
|
|
51
51
|
}
|
|
52
52
|
waiting.sort((a, b) => Date.parse(b.message.timestamp) - Date.parse(a.message.timestamp));
|
|
53
53
|
const accounts = context.accounts.map(({ provider, account }) => ({ provider, account }));
|
|
54
|
-
const
|
|
54
|
+
const scopes = await readableScopes(store, asked, options.scopes);
|
|
55
|
+
const held = await store.people.preparation(context.person.uid, { accounts, scopes, limit });
|
|
55
56
|
const readable = await readableAccounts(store, asked, options.scopes);
|
|
56
57
|
const meetings = await meetingsOf(store, context.person.uid, readable, options.since, () => left);
|
|
57
58
|
const sections = {
|
|
@@ -79,11 +80,17 @@ export const personPreparation = async (store, asked, reference, options = {}) =
|
|
|
79
80
|
...sections.tasks.coverage,
|
|
80
81
|
selection: "open, assigned to them in any role",
|
|
81
82
|
accounts: accounts.map(accountName),
|
|
83
|
+
scopes,
|
|
84
|
+
},
|
|
85
|
+
facts: {
|
|
86
|
+
...sections.facts.coverage,
|
|
87
|
+
selection: "accepted, about them or a project they are a member of",
|
|
88
|
+
scopes,
|
|
82
89
|
},
|
|
83
|
-
facts: { ...sections.facts.coverage, selection: "accepted, about them or a project they are a member of" },
|
|
84
90
|
notes: {
|
|
85
91
|
...sections.notes.coverage,
|
|
86
92
|
selection: "written by you, about them",
|
|
93
|
+
scopes,
|
|
87
94
|
...(options.notes === false ? { withheld: "contacts.notes.list" } : {}),
|
|
88
95
|
},
|
|
89
96
|
meetings: {
|
|
@@ -22,6 +22,8 @@ export interface PersonTimeline {
|
|
|
22
22
|
uid: string;
|
|
23
23
|
name: string | null;
|
|
24
24
|
};
|
|
25
|
+
/** The scopes read: the asked account's own, or the caller's `scopes`, narrowed by `scope`. */
|
|
26
|
+
scopes: Scope[];
|
|
25
27
|
items: TimelineItem[];
|
|
26
28
|
limits: {
|
|
27
29
|
items: number;
|
|
@@ -33,6 +35,9 @@ export interface PersonTimeline {
|
|
|
33
35
|
pending: number;
|
|
34
36
|
}
|
|
35
37
|
export interface TimelineOptions {
|
|
38
|
+
/** The scopes the caller may read; the asked account's own scope when absent. */
|
|
39
|
+
scopes?: readonly Scope[];
|
|
40
|
+
/** Narrows the read to one of the scopes the caller may read; another is refused. */
|
|
36
41
|
scope?: Scope;
|
|
37
42
|
/** ms, inclusive. */
|
|
38
43
|
since?: number;
|
|
@@ -46,4 +51,4 @@ export interface TimelineOptions {
|
|
|
46
51
|
* Everything one person took part in, across every identity linked to them, newest first. The index
|
|
47
52
|
* is derived and nothing else keeps it current, so it is rebuilt for this one person first.
|
|
48
53
|
*/
|
|
49
|
-
export declare const personTimeline: (store: MessageStore, asked: AccountKey, reference: string, { scope, since, until, cursor, limit }?: TimelineOptions) => Promise<PersonTimeline>;
|
|
54
|
+
export declare const personTimeline: (store: MessageStore, asked: AccountKey, reference: string, { scopes, scope, since, until, cursor, limit }?: TimelineOptions) => Promise<PersonTimeline>;
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { CliError } from "@wirecat/cli-base";
|
|
2
2
|
import { formatLocator } from "../domain/locator.js";
|
|
3
3
|
import { pickPerson } from "../resolve.js";
|
|
4
|
+
import { readableScopes } from "./person-context.js";
|
|
4
5
|
export const TIMELINE_ITEMS = 50;
|
|
5
6
|
export const TIMELINE_MAX = 500;
|
|
6
7
|
export const SCOPES = ["personal", "work"];
|
|
@@ -17,11 +18,17 @@ const boundOf = (cursor) => {
|
|
|
17
18
|
* Everything one person took part in, across every identity linked to them, newest first. The index
|
|
18
19
|
* is derived and nothing else keeps it current, so it is rebuilt for this one person first.
|
|
19
20
|
*/
|
|
20
|
-
export const personTimeline = async (store, asked, reference, { scope, since, until, cursor, limit = TIMELINE_ITEMS } = {}) => {
|
|
21
|
+
export const personTimeline = async (store, asked, reference, { scopes, scope, since, until, cursor, limit = TIMELINE_ITEMS } = {}) => {
|
|
21
22
|
if (!Number.isSafeInteger(limit) || limit < 1 || limit > TIMELINE_MAX)
|
|
22
23
|
throw new CliError("validation_error", `the limit takes 1–${TIMELINE_MAX}`);
|
|
23
24
|
if (since !== undefined && until !== undefined && since > until)
|
|
24
25
|
throw new CliError("validation_error", "the start of the range is after its end");
|
|
26
|
+
const allowed = await readableScopes(store, asked, scopes);
|
|
27
|
+
if (scope !== undefined && !allowed.includes(scope))
|
|
28
|
+
throw new CliError("permission_error", `this profile reads ${allowed.join(" and ")}, not ${scope}`, {
|
|
29
|
+
reason: "selection.out-of-scope",
|
|
30
|
+
});
|
|
31
|
+
const read = scope === undefined ? [...allowed] : [scope];
|
|
25
32
|
const found = pickPerson(reference, await store.people.people(asked.provider, { account: asked.account }));
|
|
26
33
|
const record = await store.people.personOf({ provider: asked.provider, id: found.id });
|
|
27
34
|
if (!record)
|
|
@@ -29,7 +36,7 @@ export const personTimeline = async (store, asked, reference, { scope, since, un
|
|
|
29
36
|
const personId = Number(record.uid);
|
|
30
37
|
const pending = store.involvements.pending();
|
|
31
38
|
const rows = store.involvements.forPerson(personId, {
|
|
32
|
-
|
|
39
|
+
scopes: read,
|
|
33
40
|
...(since === undefined ? {} : { since }),
|
|
34
41
|
...(until === undefined ? {} : { until }),
|
|
35
42
|
only: asked,
|
|
@@ -41,6 +48,7 @@ export const personTimeline = async (store, asked, reference, { scope, since, un
|
|
|
41
48
|
const hasMore = rows.length > limit;
|
|
42
49
|
return {
|
|
43
50
|
person: { uid: record.uid, name: record.name },
|
|
51
|
+
scopes: read,
|
|
44
52
|
items: shown.map((row) => ({
|
|
45
53
|
at: new Date(row.occurredAt).toISOString(),
|
|
46
54
|
subject: row.subjectType,
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import type { AccountKey, MessageStore } from "../store/store.js";
|
|
2
|
+
import type { SearchFound, SearchQuery } from "./messages.js";
|
|
3
|
+
import type { MeaningLane } from "./messages-discovery.js";
|
|
4
|
+
import { type SearchAllFound, type SearchAllMessenger, type SearchAllRequest, type SearchedResource } from "./search-all.js";
|
|
5
|
+
/** @deprecated use `SearchedResource` — removed once zoom-cli moves (zoom-cli#344) */
|
|
6
|
+
export type ResourceWithMeetings = SearchedResource;
|
|
7
|
+
/** @deprecated meetings are paged by `offset` — removed once zoom-cli moves (zoom-cli#344) */
|
|
8
|
+
export interface MeetingSearchCursor {
|
|
9
|
+
accountId: number;
|
|
10
|
+
query: string;
|
|
11
|
+
meetingOffset: number;
|
|
12
|
+
hitOffset: number;
|
|
13
|
+
}
|
|
14
|
+
/** @deprecated use `SearchAllRequest` — removed once zoom-cli moves (zoom-cli#344) */
|
|
15
|
+
export interface SearchAllIncludingMeetingsRequest extends SearchAllRequest {
|
|
16
|
+
/** Read only this meeting account, as `scope.meetings`. */
|
|
17
|
+
meetingAccount?: AccountKey;
|
|
18
|
+
/** Ignored: every meeting of an account is read through its search index. */
|
|
19
|
+
maxMeetings?: number | "all";
|
|
20
|
+
/** Ignored: the next page is `offset`. */
|
|
21
|
+
meetingCursor?: MeetingSearchCursor;
|
|
22
|
+
}
|
|
23
|
+
/** @deprecated use `MeetingAccountCoverage` — removed once zoom-cli moves (zoom-cli#344) */
|
|
24
|
+
export interface MeetingSearchCoverage {
|
|
25
|
+
accountId: number;
|
|
26
|
+
by: "word-prefixes";
|
|
27
|
+
meetingsScanned: number;
|
|
28
|
+
complete: boolean;
|
|
29
|
+
nextCursor?: MeetingSearchCursor;
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* @deprecated use `SearchAllFound` — removed once zoom-cli moves (zoom-cli#344). `meetings` is never set: the index
|
|
33
|
+
* has no bounded scan to report.
|
|
34
|
+
*/
|
|
35
|
+
export interface SearchAllIncludingMeetingsFound extends Omit<SearchAllFound, "hasMore" | "meetings"> {
|
|
36
|
+
hasMore: boolean | null;
|
|
37
|
+
meetings?: MeetingSearchCoverage;
|
|
38
|
+
}
|
|
39
|
+
/** @deprecated use `searchAll` with `scope.meetings` — removed once zoom-cli moves (zoom-cli#344) */
|
|
40
|
+
export declare const searchAllIncludingMeetings: (store: MessageStore, account: AccountKey, { meetingAccount, maxMeetings: _maxMeetings, meetingCursor: _meetingCursor, ...request }: SearchAllIncludingMeetingsRequest, messenger?: SearchAllMessenger, searchMessages?: (query: SearchQuery) => Promise<SearchFound>, meaning?: MeaningLane) => Promise<SearchAllIncludingMeetingsFound>;
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { searchAll, } from "./search-all.js";
|
|
2
|
+
/** @deprecated use `searchAll` with `scope.meetings` — removed once zoom-cli moves (zoom-cli#344) */
|
|
3
|
+
export const searchAllIncludingMeetings = async (store, account, { meetingAccount, maxMeetings: _maxMeetings, meetingCursor: _meetingCursor, ...request }, messenger = {}, searchMessages, meaning) => {
|
|
4
|
+
const { meetings: _meetings, ...found } = await searchAll(store, account, {
|
|
5
|
+
...request,
|
|
6
|
+
...(meetingAccount === undefined ? {} : { scope: { ...request.scope, meetings: [meetingAccount] } }),
|
|
7
|
+
...(request.only?.includes("meetings") ? { meetingsAsked: true } : {}),
|
|
8
|
+
}, messenger, searchMessages, meaning);
|
|
9
|
+
return found;
|
|
10
|
+
};
|