@wirecat/cli-core 0.659.0 → 0.661.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 +119 -0
- package/dist/attachments/markup.js +2 -11
- package/dist/calendar/mcp/index.d.ts +12 -12
- package/dist/calendar/mcp/index.js +23 -17
- package/dist/cli/ask-before-write.d.ts +8 -0
- package/dist/cli/ask-before-write.js +28 -0
- package/dist/cli/bot/api-http.d.ts +43 -0
- package/dist/cli/bot/api-http.js +160 -0
- package/dist/cli/index.d.ts +2 -0
- package/dist/cli/index.js +2 -0
- package/dist/cli/messenger/rankings-command.js +2 -1
- package/dist/cli/messenger/serve-command.js +7 -2
- package/dist/cli/messenger/tasks-command.d.ts +7 -2
- package/dist/cli/messenger/tasks-command.js +6 -3
- package/dist/cli/schedule/schedule-command.js +3 -0
- package/dist/domain/html-entities.d.ts +5 -0
- package/dist/domain/html-entities.js +56 -0
- package/dist/domain/locator.js +12 -4
- package/dist/domain/providers.js +1 -1
- package/dist/domain/references.js +11 -3
- package/dist/entities/index.d.ts +33 -93
- package/dist/entities/listings.d.ts +4 -4
- package/dist/entities/listings.js +2 -2
- package/dist/errors/reasons.js +12 -0
- package/dist/index.d.ts +1 -1
- package/dist/index.js +1 -1
- package/dist/mail/headers.js +3 -3
- package/dist/mail/parse.js +9 -8
- package/dist/mail/resume.d.ts +4 -1
- package/dist/mail/resume.js +11 -2
- package/dist/mail/retry.d.ts +2 -1
- package/dist/mail/retry.js +6 -4
- package/dist/mail/sender-scores.js +1 -6
- package/dist/mail/stored.d.ts +4 -1
- package/dist/mail/stored.js +6 -1
- package/dist/mail/sync.js +8 -3
- package/dist/mail/testing/fake.d.ts +2 -0
- package/dist/mail/testing/fake.js +3 -1
- package/dist/mcp/all-profiles.js +8 -18
- package/dist/mcp/app-server.js +1 -16
- package/dist/mcp/bot/server.js +9 -7
- package/dist/mcp/caller.js +2 -1
- package/dist/mcp/prompts.js +17 -2
- package/dist/mcp/server.js +10 -16
- package/dist/mcp/stdio-wire.d.ts +5 -2
- package/dist/mcp/stdio-wire.js +39 -12
- package/dist/mcp/tool.js +3 -1
- package/dist/mcp/tools/messages-photo.js +4 -2
- package/dist/meetings/answers.d.ts +35 -27
- package/dist/meetings/answers.js +3 -2
- package/dist/meetings/cli/index.d.ts +13 -0
- package/dist/meetings/cli/index.js +61 -16
- package/dist/meetings/cli/management.d.ts +16 -0
- package/dist/meetings/cli/management.js +90 -0
- package/dist/meetings/cli/search.js +8 -2
- package/dist/meetings/hit-query.js +11 -6
- package/dist/meetings/index.d.ts +5 -3
- package/dist/meetings/index.js +4 -2
- package/dist/meetings/item.d.ts +33 -19
- package/dist/meetings/item.js +29 -4
- package/dist/meetings/mcp/index.d.ts +15 -15
- package/dist/meetings/pull.d.ts +27 -2
- package/dist/meetings/pull.js +103 -78
- package/dist/meetings/read-through.d.ts +74 -0
- package/dist/meetings/read-through.js +330 -0
- package/dist/meetings/reads.d.ts +1 -0
- package/dist/meetings/reads.js +4 -2
- package/dist/meetings/result-items.d.ts +31 -0
- package/dist/meetings/result-items.js +31 -0
- package/dist/meetings/source.d.ts +47 -0
- package/dist/meetings/store.d.ts +7 -0
- package/dist/meetings/testing/memory.js +8 -1
- package/dist/search/service-query.d.ts +63 -0
- package/dist/search/service-query.js +57 -0
- package/dist/sends/guard.js +7 -1
- package/dist/sends/permissions.js +4 -0
- package/dist/services/listings.js +2 -1
- package/dist/services/message-resolution.js +6 -3
- package/dist/services/messages-search.js +3 -4
- package/dist/services/server-search.d.ts +2 -1
- package/dist/services/server-search.js +36 -32
- package/dist/store/sqlite/meetings.js +15 -1
- package/dist/store/sqlite/mention-drain.d.ts +4 -1
- package/dist/store/sqlite/mention-drain.js +7 -3
- package/dist/store/sqlite/messages.js +12 -1
- package/dist/store/sqlite/query-filter.d.ts +1 -0
- package/dist/store/sqlite/query-filter.js +2 -2
- package/dist/store/sqlite/tags.js +1 -1
- package/package.json +1 -1
|
@@ -0,0 +1,330 @@
|
|
|
1
|
+
import { CliError } from "@wirecat/cli-base";
|
|
2
|
+
import { timezoneOf } from "@wirecat/cli-base/query";
|
|
3
|
+
import { rangeOf, serviceCallsOf, windowOf } from "../search/service-query.js";
|
|
4
|
+
import { saveSourceMeeting, sourceMeetingInput } from "./pull.js";
|
|
5
|
+
import { MeetingError, meetingsList } from "./reads.js";
|
|
6
|
+
import { parseMeetingReference } from "./reference.js";
|
|
7
|
+
/**
|
|
8
|
+
* `meetings list` asks at most `calls` calls of `find`, each up to `pages` pages; past either the answer says it is not
|
|
9
|
+
* complete. The same three calls as messages search.
|
|
10
|
+
*/
|
|
11
|
+
export const MEETING_SERVER_BOUNDS = { calls: 3, pages: 2 };
|
|
12
|
+
// A source that has no live read, or no upcoming meetings, answers in full what it can: only a failed read is partial.
|
|
13
|
+
const ISSUES = {
|
|
14
|
+
offline: ["permission_error", "meetings.server-offline"],
|
|
15
|
+
unreachable: ["network_error", "meetings.server-unreachable"],
|
|
16
|
+
not_signed_in: ["authentication_error", "meetings.server-signed-out"],
|
|
17
|
+
refused: ["permission_error", "meetings.server-refused"],
|
|
18
|
+
failed: ["provider_error", "meetings.server-failed"],
|
|
19
|
+
};
|
|
20
|
+
const metaOf = (reason, provider) => {
|
|
21
|
+
const issue = ISSUES[reason];
|
|
22
|
+
return issue && { complete: false, issues: [{ code: issue[0], reason: issue[1], source: provider }] };
|
|
23
|
+
};
|
|
24
|
+
const WHY = {
|
|
25
|
+
unsupported: (provider) => `${provider} cannot be asked for meetings here — the answer is the store's`,
|
|
26
|
+
offline: () => "--offline: the service was not asked — the answer is the store's",
|
|
27
|
+
unreachable: (provider) => `${provider} could not be reached — the answer is the store's`,
|
|
28
|
+
not_signed_in: (provider) => `not signed in to ${provider} — the answer is the store's`,
|
|
29
|
+
refused: (provider) => `${provider} refused the request — the answer is the store's`,
|
|
30
|
+
failed: (provider) => `${provider} could not be read — the answer is the store's`,
|
|
31
|
+
no_upcoming: (provider) => `${provider} lists no meeting before it starts — upcoming ones are not in the answer`,
|
|
32
|
+
};
|
|
33
|
+
const reasonOf = (error) => {
|
|
34
|
+
const code = error instanceof CliError ? error.code : undefined;
|
|
35
|
+
if (code === "authentication_error")
|
|
36
|
+
return "not_signed_in";
|
|
37
|
+
if (code === "permission_error")
|
|
38
|
+
return "refused";
|
|
39
|
+
if (code === "network_error")
|
|
40
|
+
return "unreachable";
|
|
41
|
+
return "failed";
|
|
42
|
+
};
|
|
43
|
+
const refusal = (reason, provider, error) => error ??
|
|
44
|
+
new CliError("validation_error", `--backend server: ${WHY[reason](provider).replace(/ — .*$/, "")}; use --backend archive or both`, { reason });
|
|
45
|
+
const within = (one, other) => {
|
|
46
|
+
const from = Math.max(one.from ?? -Infinity, other.from ?? -Infinity);
|
|
47
|
+
const to = Math.min(one.to ?? Infinity, other.to ?? Infinity);
|
|
48
|
+
if (from > to)
|
|
49
|
+
return undefined;
|
|
50
|
+
return { ...(Number.isFinite(from) ? { from } : {}), ...(Number.isFinite(to) ? { to } : {}) };
|
|
51
|
+
};
|
|
52
|
+
/** Every `find` takes `started_at` as its window; the rest is what the source declared it reads. */
|
|
53
|
+
const findsOf = (source, zone, now) => ({
|
|
54
|
+
fields: { ...source.finds.fields, started_at: ["term", "range"] },
|
|
55
|
+
negatable: source.finds.negatable?.filter((field) => field !== "started_at") ?? [],
|
|
56
|
+
maxCalls: MEETING_SERVER_BOUNDS.calls,
|
|
57
|
+
all: { window: {}, terms: [] },
|
|
58
|
+
leaf: (predicate, negated) => predicate.field === "started_at"
|
|
59
|
+
? { window: windowOf(rangeOf(predicate, zone, now)), terms: [] }
|
|
60
|
+
: { window: {}, terms: [{ predicate, negated }] },
|
|
61
|
+
both: (one, other) => {
|
|
62
|
+
const window = within(one.window, other.window);
|
|
63
|
+
return window && { window, terms: [...one.terms, ...other.terms] };
|
|
64
|
+
},
|
|
65
|
+
});
|
|
66
|
+
/** A window that reaches past `now`, an open end included: one a source without upcoming meetings cannot answer. */
|
|
67
|
+
const reachesFuture = ({ to }, now) => to === undefined || to > now;
|
|
68
|
+
const storedByExternalId = async (store, accountId, externalId) => {
|
|
69
|
+
if (store.meetingByExternalId)
|
|
70
|
+
return store.meetingByExternalId(accountId, externalId);
|
|
71
|
+
const span = { start: 0, end: 0 };
|
|
72
|
+
const query = {
|
|
73
|
+
version: 1,
|
|
74
|
+
language: "lucene-v1",
|
|
75
|
+
root: { kind: "predicate", field: "provider_id", operator: "term", value: externalId, span },
|
|
76
|
+
};
|
|
77
|
+
const [row] = await store.meetings({ accountId, query, includeDeleted: true, limit: 1 });
|
|
78
|
+
return row ? store.meeting(row.id) : null;
|
|
79
|
+
};
|
|
80
|
+
const peopleKey = (people) => JSON.stringify(people.map(({ email, displayName }) => [email ?? "", displayName ?? ""]).sort());
|
|
81
|
+
/** Whether keeping what the service returned would change nothing the store holds, so nothing is written. */
|
|
82
|
+
const unchanged = (found, stored, accountId) => {
|
|
83
|
+
const participants = found.participants;
|
|
84
|
+
const input = sourceMeetingInput(found.meeting, accountId, participants === undefined ? undefined : (participants?.length ?? null), stored.meeting);
|
|
85
|
+
const row = stored.meeting;
|
|
86
|
+
return (row.deletedAt === null &&
|
|
87
|
+
input.title === row.title &&
|
|
88
|
+
input.description === row.description &&
|
|
89
|
+
input.location === row.location &&
|
|
90
|
+
input.joinUrl === row.joinUrl &&
|
|
91
|
+
input.startedAt === row.startedAt &&
|
|
92
|
+
input.endedAt === row.endedAt &&
|
|
93
|
+
input.timezone === row.timezone &&
|
|
94
|
+
JSON.stringify(input.metadata ?? null) === JSON.stringify(row.metadata ?? null) &&
|
|
95
|
+
(input.series === undefined ||
|
|
96
|
+
(input.series.externalId === stored.series?.externalId && input.series.title === stored.series.title)) &&
|
|
97
|
+
(participants == null ||
|
|
98
|
+
(row.participantsCount === participants.length && peopleKey(participants) === peopleKey(stored.participants))));
|
|
99
|
+
};
|
|
100
|
+
const stepFor = (backend) => ({
|
|
101
|
+
report: {
|
|
102
|
+
backend: backend === "server" ? "server" : "both",
|
|
103
|
+
skipped: null,
|
|
104
|
+
calls: 0,
|
|
105
|
+
returned: 0,
|
|
106
|
+
new: 0,
|
|
107
|
+
failed: 0,
|
|
108
|
+
complete: true,
|
|
109
|
+
},
|
|
110
|
+
found: new Map(),
|
|
111
|
+
missing: [],
|
|
112
|
+
});
|
|
113
|
+
/**
|
|
114
|
+
* Keeps one meeting the service returned and records whether the store held it. What the record leaves empty keeps
|
|
115
|
+
* the stored value; a list's record that changes nothing is not written (`fresh` is a `show`'s full read).
|
|
116
|
+
*/
|
|
117
|
+
const keep = async (source, store, accountId, now, step, found, parts, fresh = false) => {
|
|
118
|
+
const stored = await storedByExternalId(store, accountId, found.meeting.occurrence.id);
|
|
119
|
+
const details = stored && !fresh && unchanged(found, stored, accountId)
|
|
120
|
+
? stored
|
|
121
|
+
: await saveSourceMeeting(source, store, found.meeting, parts, {
|
|
122
|
+
accountId,
|
|
123
|
+
now,
|
|
124
|
+
...(stored ? { kept: stored.meeting } : {}),
|
|
125
|
+
});
|
|
126
|
+
step.found.set(details.meeting.id, stored ? "both" : "server");
|
|
127
|
+
step.report.returned += 1;
|
|
128
|
+
if (!stored)
|
|
129
|
+
step.report.new += 1;
|
|
130
|
+
return details;
|
|
131
|
+
};
|
|
132
|
+
/**
|
|
133
|
+
* Asks the service for the meetings a `meetings list` query may match and keeps them, so the store query that runs
|
|
134
|
+
* next sees them. The service gets only what it can filter (`serviceCallsOf`): a wider set, never a narrower one.
|
|
135
|
+
* Without a typed `--backend server`, a service that cannot be asked leaves the store's answer and a `missing` line.
|
|
136
|
+
*/
|
|
137
|
+
export const askServerForList = async (source, store, accountId, query, access) => {
|
|
138
|
+
const backend = access.backend ?? "both";
|
|
139
|
+
if (backend === "archive")
|
|
140
|
+
return undefined;
|
|
141
|
+
const step = stepFor(backend);
|
|
142
|
+
const provider = source?.name ?? "the service";
|
|
143
|
+
const skip = (reason, error) => {
|
|
144
|
+
if (backend === "server")
|
|
145
|
+
throw refusal(reason, provider, error);
|
|
146
|
+
step.report.skipped = reason;
|
|
147
|
+
step.report.complete = false;
|
|
148
|
+
step.missing.push({ field: "server", why: WHY[reason](provider) });
|
|
149
|
+
const meta = metaOf(reason, provider);
|
|
150
|
+
if (meta)
|
|
151
|
+
step.meta = meta;
|
|
152
|
+
return step;
|
|
153
|
+
};
|
|
154
|
+
if (!source?.find || !source.finds)
|
|
155
|
+
return skip("unsupported");
|
|
156
|
+
if (access.offline)
|
|
157
|
+
return skip("offline");
|
|
158
|
+
const now = access.now ?? Date.now();
|
|
159
|
+
const finds = source.finds;
|
|
160
|
+
const capability = findsOf({ ...source, finds }, timezoneOf(access.timezone), now);
|
|
161
|
+
const { calls, complete } = query
|
|
162
|
+
? serviceCallsOf(query.root, capability)
|
|
163
|
+
: { calls: [capability.all], complete: true };
|
|
164
|
+
let capped = !complete;
|
|
165
|
+
let asked = calls;
|
|
166
|
+
if (finds.upcoming === false) {
|
|
167
|
+
if (calls.some(({ window }) => reachesFuture(window, now)))
|
|
168
|
+
step.missing.push({ field: "upcoming", why: WHY.no_upcoming(provider) });
|
|
169
|
+
asked = calls.flatMap((call) => {
|
|
170
|
+
const window = within(call.window, { to: now });
|
|
171
|
+
return window ? [{ ...call, window }] : [];
|
|
172
|
+
});
|
|
173
|
+
if (!asked.length)
|
|
174
|
+
return skip("no_upcoming");
|
|
175
|
+
}
|
|
176
|
+
const seen = new Set();
|
|
177
|
+
let failure;
|
|
178
|
+
for (const call of asked) {
|
|
179
|
+
let cursor = null;
|
|
180
|
+
for (let page = 0; page < MEETING_SERVER_BOUNDS.pages; page++) {
|
|
181
|
+
step.report.calls += 1;
|
|
182
|
+
let answer;
|
|
183
|
+
try {
|
|
184
|
+
answer = await source.find(call.window, call.terms, cursor);
|
|
185
|
+
}
|
|
186
|
+
catch (error) {
|
|
187
|
+
return skip(reasonOf(error), error);
|
|
188
|
+
}
|
|
189
|
+
for (const found of answer.meetings) {
|
|
190
|
+
if (seen.has(found.meeting.occurrence.id))
|
|
191
|
+
continue;
|
|
192
|
+
seen.add(found.meeting.occurrence.id);
|
|
193
|
+
try {
|
|
194
|
+
await keep(source, store, accountId, now, step, found, { participants: found.participants });
|
|
195
|
+
}
|
|
196
|
+
catch (error) {
|
|
197
|
+
step.report.failed += 1;
|
|
198
|
+
failure ??= error;
|
|
199
|
+
}
|
|
200
|
+
}
|
|
201
|
+
cursor = answer.next;
|
|
202
|
+
if (cursor === null)
|
|
203
|
+
break;
|
|
204
|
+
if (page === MEETING_SERVER_BOUNDS.pages - 1)
|
|
205
|
+
capped = true;
|
|
206
|
+
}
|
|
207
|
+
}
|
|
208
|
+
const issues = [];
|
|
209
|
+
if (step.report.failed) {
|
|
210
|
+
issues.push({
|
|
211
|
+
code: failure instanceof CliError ? failure.code : "provider_error",
|
|
212
|
+
reason: "meetings.server-failed",
|
|
213
|
+
source: provider,
|
|
214
|
+
});
|
|
215
|
+
const why = failure instanceof Error ? `: ${failure.message}` : "";
|
|
216
|
+
step.missing.push({
|
|
217
|
+
field: "server",
|
|
218
|
+
why: `${step.report.failed} meeting(s) ${provider} returned could not be kept${why} — the answer is without them`,
|
|
219
|
+
});
|
|
220
|
+
}
|
|
221
|
+
if (capped) {
|
|
222
|
+
issues.push({ code: "outcome_unknown", reason: "meetings.server-capped", source: provider });
|
|
223
|
+
const { calls, returned } = step.report;
|
|
224
|
+
step.missing.push({
|
|
225
|
+
field: "server",
|
|
226
|
+
why: `${provider} was asked ${calls} time(s) and returned ${returned} meeting(s), not every one that may ` +
|
|
227
|
+
"match — narrow the query by started_at",
|
|
228
|
+
});
|
|
229
|
+
}
|
|
230
|
+
if (issues.length) {
|
|
231
|
+
step.report.complete = false;
|
|
232
|
+
step.meta = { complete: false, issues };
|
|
233
|
+
}
|
|
234
|
+
return step;
|
|
235
|
+
};
|
|
236
|
+
export const meetingsListThrough = async (source, store, filter, access) => {
|
|
237
|
+
const now = access.now ?? Date.now();
|
|
238
|
+
const zoned = { ...filter, timezone: timezoneOf(access.timezone), now };
|
|
239
|
+
const step = await askServerForList(source, store, filter.accountId, filter.query, { ...access, now });
|
|
240
|
+
if (!step)
|
|
241
|
+
return meetingsList(store, zoned);
|
|
242
|
+
const extras = {
|
|
243
|
+
server: step.report,
|
|
244
|
+
...(step.missing.length ? { missing: step.missing } : {}),
|
|
245
|
+
...(step.meta ? { meta: step.meta } : {}),
|
|
246
|
+
};
|
|
247
|
+
const ids = [...step.found.keys()];
|
|
248
|
+
if (access.backend === "server" && !ids.length)
|
|
249
|
+
return { items: [], page: { mode: "page", limit: filter.limit ?? 100, has_more: false }, ...extras };
|
|
250
|
+
const list = await meetingsList(store, access.backend === "server" ? { ...zoned, ids } : zoned);
|
|
251
|
+
return {
|
|
252
|
+
...list,
|
|
253
|
+
items: list.items.map((item) => ({ ...item, found_in: step.found.get(Number(item.id)) ?? "archive" })),
|
|
254
|
+
...extras,
|
|
255
|
+
};
|
|
256
|
+
};
|
|
257
|
+
/** The account's stored meeting `meeting` names: its store number, its `meeting:` ref, or the service's id. */
|
|
258
|
+
const storedMeeting = async (store, accountId, meeting) => {
|
|
259
|
+
const text = meeting.trim();
|
|
260
|
+
const own = (details) => (details?.meeting.accountId === accountId ? details : null);
|
|
261
|
+
if (/^[1-9]\d*$/.test(text) && Number.isSafeInteger(Number(text))) {
|
|
262
|
+
const byNumber = own(await store.meeting(Number(text)));
|
|
263
|
+
if (byNumber)
|
|
264
|
+
return byNumber;
|
|
265
|
+
}
|
|
266
|
+
if (text.startsWith("meeting:")) {
|
|
267
|
+
const reference = parseMeetingReference(text);
|
|
268
|
+
if (reference.accountId !== accountId)
|
|
269
|
+
throw new MeetingError("not_found", "meeting not found");
|
|
270
|
+
return own(await store.meeting(reference.meetingId));
|
|
271
|
+
}
|
|
272
|
+
return store.meetingByExternalId ? own(await store.meetingByExternalId(accountId, text)) : null;
|
|
273
|
+
};
|
|
274
|
+
/**
|
|
275
|
+
* `meetings show`: the stored meeting `meeting` names (store number first, then `meeting:` ref, then the service's
|
|
276
|
+
* id), read again from the service with its people, transcript and Drive documents and kept, as `--backend` says.
|
|
277
|
+
*/
|
|
278
|
+
export const meetingShowThrough = async (source, store, accountId, meeting, access) => {
|
|
279
|
+
if (!meeting.trim())
|
|
280
|
+
throw new MeetingError("validation_error", "name a meeting");
|
|
281
|
+
const stored = await storedMeeting(store, accountId, meeting);
|
|
282
|
+
const backend = access.backend ?? "both";
|
|
283
|
+
const notFound = () => new MeetingError("not_found", "meeting not found");
|
|
284
|
+
if (backend === "archive") {
|
|
285
|
+
if (!stored)
|
|
286
|
+
throw notFound();
|
|
287
|
+
return { details: stored };
|
|
288
|
+
}
|
|
289
|
+
const step = stepFor(backend);
|
|
290
|
+
const provider = source?.name ?? "the service";
|
|
291
|
+
const fromStore = (reason, error) => {
|
|
292
|
+
if (backend === "server")
|
|
293
|
+
throw refusal(reason, provider, error);
|
|
294
|
+
if (!stored)
|
|
295
|
+
throw error instanceof CliError && reason !== "failed" ? error : notFound();
|
|
296
|
+
step.report.skipped = reason;
|
|
297
|
+
step.report.complete = false;
|
|
298
|
+
const meta = metaOf(reason, provider);
|
|
299
|
+
return {
|
|
300
|
+
details: stored,
|
|
301
|
+
foundIn: "archive",
|
|
302
|
+
server: step.report,
|
|
303
|
+
missing: [{ field: "server", why: WHY[reason](provider) }],
|
|
304
|
+
...(meta ? { meta } : {}),
|
|
305
|
+
};
|
|
306
|
+
};
|
|
307
|
+
const providerId = stored?.meeting.externalId ?? (meeting.trim().startsWith("meeting:") ? undefined : meeting.trim());
|
|
308
|
+
if (providerId === undefined)
|
|
309
|
+
throw notFound();
|
|
310
|
+
if (!source?.get)
|
|
311
|
+
return fromStore("unsupported");
|
|
312
|
+
if (access.offline)
|
|
313
|
+
return fromStore("offline");
|
|
314
|
+
step.report.calls = 1;
|
|
315
|
+
let full;
|
|
316
|
+
try {
|
|
317
|
+
full = await source.get(providerId);
|
|
318
|
+
}
|
|
319
|
+
catch (error) {
|
|
320
|
+
return fromStore(reasonOf(error), error);
|
|
321
|
+
}
|
|
322
|
+
if (!full) {
|
|
323
|
+
if (!stored || backend === "server")
|
|
324
|
+
throw notFound();
|
|
325
|
+
return { details: stored, foundIn: "archive", server: step.report };
|
|
326
|
+
}
|
|
327
|
+
const details = await keep(source, store, accountId, access.now ?? Date.now(), step, full, { participants: full.participants, transcript: full.transcript, documents: full.documents }, true);
|
|
328
|
+
const fresh = (await store.meeting(details.meeting.id)) ?? details;
|
|
329
|
+
return { details: fresh, foundIn: step.found.get(details.meeting.id) ?? "server", server: step.report };
|
|
330
|
+
};
|
package/dist/meetings/reads.d.ts
CHANGED
|
@@ -77,6 +77,7 @@ export interface TranscriptReadOptions {
|
|
|
77
77
|
}
|
|
78
78
|
/** `meetings show`: one item, the meeting with its people, chat, transcripts named by `ref` and summaries. */
|
|
79
79
|
export declare const meetingDetailsAnswer: (store: MeetingStore, id: number, accountId?: number) => Promise<MeetingItemBody<MeetingDetailsItem>>;
|
|
80
|
+
export declare const meetingDetailsBody: (store: MeetingStore, details: MeetingDetails) => Promise<MeetingItemBody<MeetingDetailsItem>>;
|
|
80
81
|
export declare const meetingTranscriptAnswer: (store: MeetingStore, id: number, accountId?: number, options?: TranscriptReadOptions) => Promise<MeetingListBody<MeetingTranscriptItem>>;
|
|
81
82
|
export declare const meetingSummaryAnswer: (store: MeetingStore, id: number, accountId?: number) => Promise<MeetingListBody<MeetingSummaryItem>>;
|
|
82
83
|
export declare const meetingsSearch: (store: MeetingStore, query: string, filter?: MeetingFilter) => Promise<{
|
package/dist/meetings/reads.js
CHANGED
|
@@ -127,9 +127,11 @@ const ownerOf = async (store, accountId) => {
|
|
|
127
127
|
};
|
|
128
128
|
/** `meetings show`: one item, the meeting with its people, chat, transcripts named by `ref` and summaries. */
|
|
129
129
|
export const meetingDetailsAnswer = async (store, id, accountId) => {
|
|
130
|
-
|
|
131
|
-
return { item: meetingDetailsItem(details, await ownerOf(store, details.meeting.accountId)) };
|
|
130
|
+
return meetingDetailsBody(store, await meetingShow(store, id, accountId));
|
|
132
131
|
};
|
|
132
|
+
export const meetingDetailsBody = async (store, details) => ({
|
|
133
|
+
item: meetingDetailsItem(details, await ownerOf(store, details.meeting.accountId)),
|
|
134
|
+
});
|
|
133
135
|
export const meetingTranscriptAnswer = async (store, id, accountId, options = {}) => {
|
|
134
136
|
const details = await meetingShow(store, id, accountId);
|
|
135
137
|
return wholeList(details.transcripts
|
|
@@ -1,5 +1,36 @@
|
|
|
1
1
|
import * as v from "valibot";
|
|
2
2
|
export declare const MEETING_RESULT_ENTITIES: {
|
|
3
|
+
readonly meeting_change: v.StrictObjectSchema<{
|
|
4
|
+
readonly action: v.PicklistSchema<["create", "update", "cancel"], undefined>;
|
|
5
|
+
readonly provider: v.StringSchema<undefined>;
|
|
6
|
+
readonly account: v.StringSchema<undefined>;
|
|
7
|
+
readonly id: v.OptionalSchema<v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.MinLengthAction<string, 1, undefined>]>, undefined>;
|
|
8
|
+
readonly occurrence_id: v.OptionalSchema<v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.MinLengthAction<string, 1, undefined>]>, undefined>;
|
|
9
|
+
readonly change: v.OptionalSchema<v.StrictObjectSchema<{
|
|
10
|
+
readonly title: v.OptionalSchema<v.StringSchema<undefined>, undefined>;
|
|
11
|
+
readonly kind: v.OptionalSchema<v.PicklistSchema<["instant", "scheduled"], undefined>, undefined>;
|
|
12
|
+
readonly start_time: v.OptionalSchema<v.StringSchema<undefined>, undefined>;
|
|
13
|
+
readonly duration_minutes: v.OptionalSchema<v.SchemaWithPipe<readonly [v.NumberSchema<undefined>, v.IntegerAction<number, undefined>, v.MinValueAction<number, 0, undefined>]>, undefined>;
|
|
14
|
+
readonly timezone: v.OptionalSchema<v.StringSchema<undefined>, undefined>;
|
|
15
|
+
readonly agenda: v.OptionalSchema<v.StringSchema<undefined>, undefined>;
|
|
16
|
+
}, undefined>, undefined>;
|
|
17
|
+
readonly applied: v.BooleanSchema<undefined>;
|
|
18
|
+
readonly meeting: v.OptionalSchema<v.StrictObjectSchema<{
|
|
19
|
+
readonly id: v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.MinLengthAction<string, 1, undefined>]>;
|
|
20
|
+
readonly title: v.NullableSchema<v.StringSchema<undefined>, undefined>;
|
|
21
|
+
readonly kind: v.NullableSchema<v.PicklistSchema<["instant", "scheduled"], undefined>, undefined>;
|
|
22
|
+
readonly start_time: v.NullableSchema<v.StringSchema<undefined>, undefined>;
|
|
23
|
+
readonly duration_minutes: v.NullableSchema<v.SchemaWithPipe<readonly [v.NumberSchema<undefined>, v.IntegerAction<number, undefined>, v.MinValueAction<number, 0, undefined>]>, undefined>;
|
|
24
|
+
readonly timezone: v.NullableSchema<v.StringSchema<undefined>, undefined>;
|
|
25
|
+
readonly agenda: v.NullableSchema<v.StringSchema<undefined>, undefined>;
|
|
26
|
+
readonly join_url: v.NullableSchema<v.StringSchema<undefined>, undefined>;
|
|
27
|
+
}, undefined>, undefined>;
|
|
28
|
+
}, undefined>;
|
|
29
|
+
readonly meeting_invitation: v.StrictObjectSchema<{
|
|
30
|
+
readonly id: v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.MinLengthAction<string, 1, undefined>]>;
|
|
31
|
+
readonly invitation: v.StringSchema<undefined>;
|
|
32
|
+
readonly untrusted: v.OptionalSchema<v.ArraySchema<v.StringSchema<undefined>, undefined>, undefined>;
|
|
33
|
+
}, undefined>;
|
|
3
34
|
readonly meeting_ingestion: v.StrictObjectSchema<{
|
|
4
35
|
readonly meetings: v.SchemaWithPipe<readonly [v.NumberSchema<undefined>, v.IntegerAction<number, undefined>, v.MinValueAction<number, 0, undefined>]>;
|
|
5
36
|
readonly participants: v.SchemaWithPipe<readonly [v.NumberSchema<undefined>, v.IntegerAction<number, undefined>, v.MinValueAction<number, 0, undefined>]>;
|
|
@@ -123,7 +123,38 @@ const repair = v.strictObject({
|
|
|
123
123
|
transcripts: count,
|
|
124
124
|
languages: v.array(v.strictObject({ language: nullableText, transcripts: count })),
|
|
125
125
|
});
|
|
126
|
+
const kind = v.picklist(["instant", "scheduled"]);
|
|
127
|
+
/** What `meetings create|update|cancel` did on the service, or would do under `--dry-run` (`applied: false`). */
|
|
128
|
+
const managedChange = v.strictObject({
|
|
129
|
+
action: v.picklist(["create", "update", "cancel"]),
|
|
130
|
+
provider: text,
|
|
131
|
+
account: text,
|
|
132
|
+
id: v.optional(identifier),
|
|
133
|
+
occurrence_id: v.optional(identifier),
|
|
134
|
+
change: v.optional(v.strictObject({
|
|
135
|
+
title: v.optional(text),
|
|
136
|
+
kind: v.optional(kind),
|
|
137
|
+
start_time: v.optional(text),
|
|
138
|
+
duration_minutes: v.optional(count),
|
|
139
|
+
timezone: v.optional(text),
|
|
140
|
+
agenda: v.optional(text),
|
|
141
|
+
})),
|
|
142
|
+
applied: flag,
|
|
143
|
+
meeting: v.optional(v.strictObject({
|
|
144
|
+
id: identifier,
|
|
145
|
+
title: nullableText,
|
|
146
|
+
kind: v.nullable(kind),
|
|
147
|
+
start_time: nullableText,
|
|
148
|
+
duration_minutes: v.nullable(count),
|
|
149
|
+
timezone: nullableText,
|
|
150
|
+
agenda: nullableText,
|
|
151
|
+
join_url: nullableText,
|
|
152
|
+
})),
|
|
153
|
+
});
|
|
154
|
+
const invitation = v.strictObject({ id: identifier, invitation: text, untrusted: v.optional(v.array(text)) });
|
|
126
155
|
export const MEETING_RESULT_ENTITIES = {
|
|
156
|
+
meeting_change: managedChange,
|
|
157
|
+
meeting_invitation: invitation,
|
|
127
158
|
meeting_ingestion: run,
|
|
128
159
|
meeting_export: exported,
|
|
129
160
|
meeting_association: meetingChange,
|
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import type { Predicate } from "@wirecat/cli-base/query";
|
|
2
|
+
import type { ServiceOperator } from "../search/service-query.js";
|
|
1
3
|
import type { Metadata, SourceChatLine, SourceMeeting, SummaryContent, TranscriptLine } from "./model.js";
|
|
2
4
|
import type { MeetingDocumentInput, MeetingSave } from "./store.js";
|
|
3
5
|
export interface SourceParticipant {
|
|
@@ -17,6 +19,42 @@ export interface SourceParticipant {
|
|
|
17
19
|
sessions: import("./model.js").JsonValue;
|
|
18
20
|
metadata: Metadata;
|
|
19
21
|
}
|
|
22
|
+
/** When the meetings `find` asks for started, epoch milliseconds, both ends inclusive; an open end is the source's. */
|
|
23
|
+
export interface MeetingWindow {
|
|
24
|
+
from?: number;
|
|
25
|
+
to?: number;
|
|
26
|
+
}
|
|
27
|
+
/** A `meetings list` term `find` declared it reads, besides `started_at`; `negated` only for a negatable field. */
|
|
28
|
+
export interface MeetingTerm {
|
|
29
|
+
predicate: Predicate;
|
|
30
|
+
negated: boolean;
|
|
31
|
+
}
|
|
32
|
+
/** A meeting the service returned, with its participants when the same answer carries them. */
|
|
33
|
+
export interface FoundMeeting {
|
|
34
|
+
meeting: SourceMeeting;
|
|
35
|
+
participants?: SourceParticipant[] | null;
|
|
36
|
+
}
|
|
37
|
+
export interface FoundMeetings {
|
|
38
|
+
meetings: FoundMeeting[];
|
|
39
|
+
/** The next page's cursor; `null` on the last page. */
|
|
40
|
+
next: string | null;
|
|
41
|
+
}
|
|
42
|
+
/** One meeting with what `meetings show` keeps of it: its people, transcript and Drive documents. */
|
|
43
|
+
export interface FullMeeting extends FoundMeeting {
|
|
44
|
+
transcript?: TranscriptLine[] | null;
|
|
45
|
+
documents?: MeetingDocumentInput[] | null;
|
|
46
|
+
}
|
|
47
|
+
/**
|
|
48
|
+
* What `find` filters besides `started_at`, which every `find` takes as its window: `meetings list` fields and the
|
|
49
|
+
* operators the service reads on each (`provider_id: ["term"]`). The store decides the rest of the query.
|
|
50
|
+
*/
|
|
51
|
+
export interface MeetingFinds {
|
|
52
|
+
fields: Readonly<Record<string, readonly ServiceOperator[]>>;
|
|
53
|
+
/** The fields whose NOT the service can send. */
|
|
54
|
+
negatable?: readonly string[];
|
|
55
|
+
/** False for a service that lists no meeting before it starts (Meet: scheduling is Google Calendar's). */
|
|
56
|
+
upcoming?: boolean;
|
|
57
|
+
}
|
|
20
58
|
/** Null means unavailable; it never requests deletion of previously saved data. */
|
|
21
59
|
export interface MeetingSource {
|
|
22
60
|
readonly provider: string;
|
|
@@ -40,4 +78,13 @@ export interface MeetingSource {
|
|
|
40
78
|
files(occurrenceId: string): Promise<NonNullable<MeetingSave["attachments"]> | null>;
|
|
41
79
|
/** The Drive files the service saved for the occurrence: its transcript, recording and notes documents. */
|
|
42
80
|
documents?(occurrenceId: string): Promise<MeetingDocumentInput[] | null>;
|
|
81
|
+
/** What `find` reads of a `meetings list` query; required with `find`. */
|
|
82
|
+
readonly finds?: MeetingFinds;
|
|
83
|
+
/**
|
|
84
|
+
* The meetings that may match, for `meetings list`: one page from `cursor` (`null` first). Each meeting's
|
|
85
|
+
* `occurrence.id` is the one `meetings()` gives, so the row it is kept as is the row `sync` writes.
|
|
86
|
+
*/
|
|
87
|
+
find?(window: MeetingWindow, terms: readonly MeetingTerm[], cursor: string | null): Promise<FoundMeetings>;
|
|
88
|
+
/** One meeting by the service's id, for `meetings show`; `null` when the service has none. */
|
|
89
|
+
get?(id: string): Promise<FullMeeting | null>;
|
|
43
90
|
}
|
package/dist/meetings/store.d.ts
CHANGED
|
@@ -98,6 +98,11 @@ export interface MeetingFilter {
|
|
|
98
98
|
accountId?: number;
|
|
99
99
|
/** A validated `meetings list` query over `MEETING_QUERY`'s fields. */
|
|
100
100
|
query?: QueryAst;
|
|
101
|
+
/** The zone and the instant the query's dates are read in; UTC and the current time without them. */
|
|
102
|
+
timezone?: string;
|
|
103
|
+
now?: number;
|
|
104
|
+
/** Only these stored meetings, by their store id. */
|
|
105
|
+
ids?: readonly number[];
|
|
101
106
|
eventId?: number;
|
|
102
107
|
meetingSeriesId?: number;
|
|
103
108
|
since?: number;
|
|
@@ -158,6 +163,8 @@ export interface MeetingStore {
|
|
|
158
163
|
/** The provider and account a meeting account id stands for; `null` when the store has no such account. */
|
|
159
164
|
account(id: number): Promise<MeetingOwner | null>;
|
|
160
165
|
meeting(id: number): Promise<MeetingDetails | null>;
|
|
166
|
+
/** The account's meeting the provider knows by `externalId` (the occurrence id), deleted or not; `null` when none. */
|
|
167
|
+
meetingByExternalId?(accountId: number, externalId: string): Promise<MeetingDetails | null>;
|
|
161
168
|
participants(query: string, accountId?: number): Promise<Participant[]>;
|
|
162
169
|
search(query: string, filter?: MeetingFilter): Promise<ListResult<SearchHit>>;
|
|
163
170
|
events(): Promise<Event[]>;
|
|
@@ -19,8 +19,12 @@ const filterMeetings = (rows, filter = {}) => {
|
|
|
19
19
|
(filter.meetingSeriesId === undefined || m.meetingSeriesId === filter.meetingSeriesId) &&
|
|
20
20
|
(filter.since === undefined || (m.startedAt !== null && m.startedAt >= filter.since)) &&
|
|
21
21
|
(filter.until === undefined || (m.startedAt !== null && m.startedAt <= filter.until)) &&
|
|
22
|
+
(filter.ids === undefined || filter.ids.includes(m.id)) &&
|
|
22
23
|
(filter.query === undefined ||
|
|
23
|
-
evaluate(filter.query, MEETING_QUERY.fields, meetingItem(m, MEMORY_OWNER(m.accountId))
|
|
24
|
+
evaluate(filter.query, MEETING_QUERY.fields, meetingItem(m, MEMORY_OWNER(m.accountId)), {
|
|
25
|
+
zone: filter.timezone ?? "UTC",
|
|
26
|
+
...(filter.now === undefined ? {} : { now: filter.now }),
|
|
27
|
+
})))
|
|
24
28
|
.sort((a, b) => (b.meeting.startedAt ?? 0) - (a.meeting.startedAt ?? 0) || a.meeting.id - b.meeting.id)
|
|
25
29
|
.slice(filter.offset ?? 0, filter.limit === undefined ? undefined : (filter.offset ?? 0) + filter.limit);
|
|
26
30
|
};
|
|
@@ -93,6 +97,9 @@ export const memoryMeetingStore = () => {
|
|
|
93
97
|
async meeting(id) {
|
|
94
98
|
return structuredClone(state.meetings.find((d) => d.meeting.id === id) ?? null);
|
|
95
99
|
},
|
|
100
|
+
async meetingByExternalId(accountId, externalId) {
|
|
101
|
+
return structuredClone(state.meetings.find((d) => d.meeting.accountId === accountId && d.meeting.externalId === externalId) ?? null);
|
|
102
|
+
},
|
|
96
103
|
async participants(query, accountId) {
|
|
97
104
|
const term = query.toLocaleLowerCase();
|
|
98
105
|
return structuredClone(state.meetings
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
import { type DateRange, type Occur, type Predicate, type Span } from "@wirecat/cli-base/query";
|
|
2
|
+
/**
|
|
3
|
+
* Where a read looks, the one vocabulary of messages, mail, calendar and meetings: the store (`archive`), the
|
|
4
|
+
* service's own search (`server`), or both, with what the service returns kept in the store.
|
|
5
|
+
*/
|
|
6
|
+
export declare const BACKENDS: readonly ["archive", "server", "both"];
|
|
7
|
+
export type Backend = (typeof BACKENDS)[number];
|
|
8
|
+
/** The operators a service's own search may read; patterns and regexes always stay with the store. */
|
|
9
|
+
export type ServiceOperator = "term" | "phrase" | "range";
|
|
10
|
+
/** A parsed query whose leaves may carry what resolving them found, as messages' `ResolvedNode` does. */
|
|
11
|
+
export type QueryTree<P extends Predicate = Predicate> = P | {
|
|
12
|
+
kind: "boolean";
|
|
13
|
+
clauses: {
|
|
14
|
+
occur: Occur;
|
|
15
|
+
node: QueryTree<P>;
|
|
16
|
+
}[];
|
|
17
|
+
span: Span;
|
|
18
|
+
};
|
|
19
|
+
/**
|
|
20
|
+
* What a service's search can filter, and how its call is built. `B` is one call's criteria in the caller's terms. The
|
|
21
|
+
* store answers the whole query afterwards, so a part the service cannot read is left out: that only widens a call.
|
|
22
|
+
*/
|
|
23
|
+
export interface ServiceCapability<P extends Predicate, B> {
|
|
24
|
+
/** The fields the service filters, each with the operators it reads. */
|
|
25
|
+
fields: Readonly<Record<string, readonly ServiceOperator[]>>;
|
|
26
|
+
/** The fields whose NOT the service can send; every other NOT is the store's. */
|
|
27
|
+
negatable?: readonly string[];
|
|
28
|
+
/** At most this many calls; the branches beyond it are not asked and the answer is not complete. */
|
|
29
|
+
maxCalls: number;
|
|
30
|
+
/** Criteria that match everything: where every call starts, and what a part left out becomes. */
|
|
31
|
+
all: B;
|
|
32
|
+
/**
|
|
33
|
+
* One readable leaf as criteria. `undefined` drops the branch it is in: no call can match it (another account's
|
|
34
|
+
* chat). A leaf with nothing to send but that may match returns `all` itself.
|
|
35
|
+
*/
|
|
36
|
+
leaf(predicate: P, negated: boolean): B | undefined;
|
|
37
|
+
/** Both criteria at once; `undefined` when they cannot both hold, so the branch is never asked. */
|
|
38
|
+
both(one: B, other: B): B | undefined;
|
|
39
|
+
/** A service that can OR joins every branch into its one call; without it each OR branch is a call of its own. */
|
|
40
|
+
either?(branches: B[]): B;
|
|
41
|
+
/** Whether a branch is worth a call: messages asks only with words. A branch left out does not count as a call. */
|
|
42
|
+
sends?(branch: B): boolean;
|
|
43
|
+
}
|
|
44
|
+
export interface ServiceCalls<B> {
|
|
45
|
+
calls: B[];
|
|
46
|
+
/** False when the cap left a branch unasked. */
|
|
47
|
+
complete: boolean;
|
|
48
|
+
/** Branches `sends` refused. */
|
|
49
|
+
unsent: number;
|
|
50
|
+
}
|
|
51
|
+
/**
|
|
52
|
+
* Splits a parsed query into the calls a service's search can take: the parts it can read kept, the rest left out,
|
|
53
|
+
* which only widens a call and never loses a hit, since the store answers the whole query after. Each OR branch is a
|
|
54
|
+
* call of its own, up to `maxCalls`, unless the service can OR. `scope` holds in every call (`--chat`).
|
|
55
|
+
*/
|
|
56
|
+
export declare const serviceCallsOf: <P extends Predicate, B>(root: QueryTree<P>, capability: ServiceCapability<P, B>, scope?: B) => ServiceCalls<B>;
|
|
57
|
+
/** A time leaf (`date:`, `started_at:`) as the range it names, in `zone`, at `now`. */
|
|
58
|
+
export declare const rangeOf: (node: Predicate, zone: string, now?: number) => DateRange;
|
|
59
|
+
/** Inclusive bounds in milliseconds, as a service's window takes them; an open side is left out. */
|
|
60
|
+
export declare const windowOf: ({ lower, upper, lower_inclusive, upper_inclusive, }: DateRange) => {
|
|
61
|
+
from?: number;
|
|
62
|
+
to?: number;
|
|
63
|
+
};
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
import { dateRange } from "@wirecat/cli-base/query";
|
|
2
|
+
/**
|
|
3
|
+
* Where a read looks, the one vocabulary of messages, mail, calendar and meetings: the store (`archive`), the
|
|
4
|
+
* service's own search (`server`), or both, with what the service returns kept in the store.
|
|
5
|
+
*/
|
|
6
|
+
export const BACKENDS = ["archive", "server", "both"];
|
|
7
|
+
/** Past this many branches an AND of ORs is not multiplied further: the clause is left to the store. */
|
|
8
|
+
const MAX_BRANCHES = 64;
|
|
9
|
+
// Criteria may be arrays themselves, so a missing one is an empty list and a present one is wrapped.
|
|
10
|
+
const some = (value) => (value === undefined ? [] : [value]);
|
|
11
|
+
const readable = (node, capability) => capability.fields[node.field]?.includes(node.operator) === true;
|
|
12
|
+
const branchesOf = (node, capability, cut) => {
|
|
13
|
+
if (node.kind === "predicate")
|
|
14
|
+
return readable(node, capability) ? some(capability.leaf(node, false)) : [capability.all];
|
|
15
|
+
const must = node.clauses.filter(({ occur }) => occur === "must");
|
|
16
|
+
const not = node.clauses.flatMap(({ occur, node }) => occur === "must_not" &&
|
|
17
|
+
node.kind === "predicate" &&
|
|
18
|
+
capability.negatable?.includes(node.field) &&
|
|
19
|
+
readable(node, capability)
|
|
20
|
+
? some(capability.leaf(node, true))
|
|
21
|
+
: []);
|
|
22
|
+
const should = node.clauses.filter(({ occur }) => occur === "should");
|
|
23
|
+
// Lucene: beside a required clause an optional one only ranks, so only the required ones narrow.
|
|
24
|
+
const base = must.length || !should.length
|
|
25
|
+
? must.reduce((product, { node }) => {
|
|
26
|
+
const next = product.flatMap((one) => branchesOf(node, capability, cut).flatMap((other) => some(capability.both(one, other))));
|
|
27
|
+
// Leaving a required clause out only widens the calls: nothing is lost.
|
|
28
|
+
return next.length > MAX_BRANCHES ? product : next;
|
|
29
|
+
}, [capability.all])
|
|
30
|
+
: should.flatMap(({ node }) => branchesOf(node, capability, cut));
|
|
31
|
+
if (base.length > MAX_BRANCHES)
|
|
32
|
+
cut.branches = true;
|
|
33
|
+
return not.reduce((branches, negated) => branches.flatMap((one) => some(capability.both(one, negated))), base.slice(0, MAX_BRANCHES));
|
|
34
|
+
};
|
|
35
|
+
/**
|
|
36
|
+
* Splits a parsed query into the calls a service's search can take: the parts it can read kept, the rest left out,
|
|
37
|
+
* which only widens a call and never loses a hit, since the store answers the whole query after. Each OR branch is a
|
|
38
|
+
* call of its own, up to `maxCalls`, unless the service can OR. `scope` holds in every call (`--chat`).
|
|
39
|
+
*/
|
|
40
|
+
export const serviceCallsOf = (root, capability, scope) => {
|
|
41
|
+
const cut = { branches: false };
|
|
42
|
+
const all = branchesOf(root, capability, cut).flatMap((branch) => scope === undefined ? [branch] : some(capability.both(scope, branch)));
|
|
43
|
+
const sent = capability.sends ? all.filter((branch) => capability.sends?.(branch)) : all;
|
|
44
|
+
const unique = [...new Map(sent.map((branch) => [JSON.stringify(branch), branch])).values()];
|
|
45
|
+
const unsent = all.length - sent.length;
|
|
46
|
+
if (capability.either && unique.length)
|
|
47
|
+
return { calls: [capability.either(unique)], complete: !cut.branches, unsent };
|
|
48
|
+
const max = Math.max(1, capability.maxCalls);
|
|
49
|
+
return { calls: unique.slice(0, max), complete: !cut.branches && unique.length <= max, unsent };
|
|
50
|
+
};
|
|
51
|
+
/** A time leaf (`date:`, `started_at:`) as the range it names, in `zone`, at `now`. */
|
|
52
|
+
export const rangeOf = (node, zone, now) => dateRange(node.value, node.operator === "range" ? (node.upper ?? "*") : node.value, node.operator === "range" ? node.lower_inclusive === true : true, node.operator === "range" ? node.upper_inclusive === true : true, zone, node.span, now);
|
|
53
|
+
/** Inclusive bounds in milliseconds, as a service's window takes them; an open side is left out. */
|
|
54
|
+
export const windowOf = ({ lower, upper, lower_inclusive, upper_inclusive, }) => ({
|
|
55
|
+
...(lower === undefined ? {} : { from: lower_inclusive ? lower : lower + 1 }),
|
|
56
|
+
...(upper === undefined ? {} : { to: upper_inclusive ? upper : upper - 1 }),
|
|
57
|
+
});
|