@wirecat/cli-core 0.658.0 → 0.660.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 +72 -0
- package/dist/cli/ask-before-write.d.ts +8 -0
- package/dist/cli/ask-before-write.js +28 -0
- package/dist/cli/config-command.js +2 -9
- package/dist/cli/config-issues.js +1 -1
- package/dist/cli/index.d.ts +1 -0
- package/dist/cli/index.js +1 -0
- package/dist/cli/messenger/messages-delete-command.d.ts +2 -1
- package/dist/cli/messenger/messages-delete-command.js +2 -1
- package/dist/{cli → domain}/config-repair.d.ts +7 -0
- package/dist/{cli → domain}/config-repair.js +53 -0
- package/dist/domain/providers.js +1 -1
- package/dist/entities/index.d.ts +33 -93
- package/dist/errors/reasons.js +12 -0
- package/dist/index.d.ts +1 -1
- package/dist/index.js +1 -1
- package/dist/kit/sync-after-install.js +5 -0
- 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/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/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/replies/rules.d.ts +1 -1
- package/dist/replies/rules.js +1 -1
- package/dist/search/service-query.d.ts +63 -0
- package/dist/search/service-query.js +57 -0
- package/dist/sends/permissions.js +9 -4
- 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/shared-config.d.ts +2 -0
- package/dist/store/shared-config.js +38 -8
- package/dist/store/sqlite/meetings.js +15 -1
- package/package.json +1 -1
package/dist/meetings/pull.js
CHANGED
|
@@ -17,6 +17,107 @@ const participantInput = (p, provider, occurrenceId, position, accountId) => {
|
|
|
17
17
|
},
|
|
18
18
|
};
|
|
19
19
|
};
|
|
20
|
+
const participantInputs = (provider, occurrenceId, list, accountId) => list.map((p, i) => participantInput(p, provider, occurrenceId, i, accountId));
|
|
21
|
+
/**
|
|
22
|
+
* The meetings row of a meeting the service returned. With `kept`, the stored row, a field the record leaves empty
|
|
23
|
+
* keeps the stored value and the metadata merges: a live read's record may be thinner than what sync stored.
|
|
24
|
+
*/
|
|
25
|
+
export const sourceMeetingInput = (m, accountId, participantsCount, kept) => {
|
|
26
|
+
const startedAt = timestamp(m.occurrence.startedAt);
|
|
27
|
+
const given = m.occurrence.endedAt === null ? null : timestamp(m.occurrence.endedAt);
|
|
28
|
+
if (given !== null && given < startedAt)
|
|
29
|
+
throw new Error("Meeting ends before it starts");
|
|
30
|
+
const keptEnd = kept?.endedAt ?? null;
|
|
31
|
+
const endedAt = given ?? (keptEnd !== null && keptEnd >= startedAt ? keptEnd : null);
|
|
32
|
+
const count = participantsCount === null && kept ? kept.participantsCount : participantsCount;
|
|
33
|
+
const metadata = kept?.metadata && m.metadata ? { ...kept.metadata, ...m.metadata } : (m.metadata ?? kept?.metadata ?? null);
|
|
34
|
+
const meeting = {
|
|
35
|
+
accountId,
|
|
36
|
+
externalId: m.occurrence.id,
|
|
37
|
+
title: m.occurrence.title,
|
|
38
|
+
description: m.description ?? kept?.description ?? null,
|
|
39
|
+
location: m.location ?? kept?.location ?? null,
|
|
40
|
+
joinUrl: m.joinUrl ?? m.series?.joinUrl ?? kept?.joinUrl ?? null,
|
|
41
|
+
startedAt,
|
|
42
|
+
endedAt,
|
|
43
|
+
durationMs: endedAt === null ? null : endedAt - startedAt,
|
|
44
|
+
timezone: m.timezone ?? kept?.timezone ?? null,
|
|
45
|
+
hostIdentityId: kept?.hostIdentityId ?? null,
|
|
46
|
+
...(count === undefined ? {} : { participantsCount: count }),
|
|
47
|
+
metadata,
|
|
48
|
+
deletedAt: null,
|
|
49
|
+
};
|
|
50
|
+
if (m.series)
|
|
51
|
+
meeting.series = {
|
|
52
|
+
externalId: m.series.id,
|
|
53
|
+
title: m.series.title,
|
|
54
|
+
description: null,
|
|
55
|
+
kind: m.series.kind ?? null,
|
|
56
|
+
recurrence: m.series.recurrence ?? null,
|
|
57
|
+
hostIdentityId: null,
|
|
58
|
+
joinUrl: m.series.joinUrl ?? null,
|
|
59
|
+
metadata: null,
|
|
60
|
+
deletedAt: null,
|
|
61
|
+
};
|
|
62
|
+
return meeting;
|
|
63
|
+
};
|
|
64
|
+
/**
|
|
65
|
+
* Saves one meeting as `meetings sync` does, keyed by its occurrence id, and links its event: `sync` and the reads that
|
|
66
|
+
* keep what the service returned write the same row. It never moves the sync's cursor. A live read passes `kept`, the
|
|
67
|
+
* stored row, so a thinner record does not empty what sync stored (`sourceMeetingInput`).
|
|
68
|
+
*/
|
|
69
|
+
export const saveSourceMeeting = async (source, store, m, parts, { accountId, now, kept }) => {
|
|
70
|
+
const id = m.occurrence.id;
|
|
71
|
+
const { participants: sourceParticipants, transcript: lines, chat, summary } = parts;
|
|
72
|
+
const participants = participantInputs(source.provider, id, sourceParticipants ?? [], accountId);
|
|
73
|
+
const meeting = sourceMeetingInput(m, accountId, sourceParticipants === undefined ? undefined : (sourceParticipants?.length ?? null), kept);
|
|
74
|
+
const linked = sourceParticipants !== undefined;
|
|
75
|
+
const format = source.transcriptFormat ?? null;
|
|
76
|
+
const transcripts = lines && linked ? [await transcriptInput(lines, participants, source.name, undefined, format)] : undefined;
|
|
77
|
+
const details = await store.saveMeeting({
|
|
78
|
+
meeting,
|
|
79
|
+
participants: sourceParticipants ? participants : undefined,
|
|
80
|
+
transcripts,
|
|
81
|
+
chat: chat?.map((line) => ({
|
|
82
|
+
externalId: null,
|
|
83
|
+
sentAt: timestamp(line.sentAt),
|
|
84
|
+
senderParticipantPosition: speakerPosition(line.sender, participants),
|
|
85
|
+
senderName: line.sender,
|
|
86
|
+
recipient: null,
|
|
87
|
+
text: line.text,
|
|
88
|
+
normalizedText: null,
|
|
89
|
+
metadata: null,
|
|
90
|
+
})),
|
|
91
|
+
summaries: summary
|
|
92
|
+
? [
|
|
93
|
+
{
|
|
94
|
+
...summary,
|
|
95
|
+
source: summary.source ?? source.name,
|
|
96
|
+
content: summary.content ?? null,
|
|
97
|
+
docUrl: summary.docUrl ?? null,
|
|
98
|
+
externalCreatedAt: summary.externalCreatedAt ?? null,
|
|
99
|
+
externalUpdatedAt: summary.externalUpdatedAt ?? null,
|
|
100
|
+
metadata: summary.metadata ?? null,
|
|
101
|
+
},
|
|
102
|
+
]
|
|
103
|
+
: undefined,
|
|
104
|
+
attachments: parts.files ?? undefined,
|
|
105
|
+
documents: parts.documents ?? undefined,
|
|
106
|
+
now,
|
|
107
|
+
});
|
|
108
|
+
// Without participants the rows cannot be linked: they are saved only when the meeting has no current
|
|
109
|
+
// transcript to downgrade, under a distinct hash so the retry that reads participants is not a replay.
|
|
110
|
+
if (lines &&
|
|
111
|
+
!linked &&
|
|
112
|
+
!details.transcripts.some((t) => t.transcript.source === source.name && t.transcript.supersededAt === null))
|
|
113
|
+
await store.saveMeeting({
|
|
114
|
+
meeting,
|
|
115
|
+
transcripts: [await transcriptInput(lines, [], source.name, `${JSON.stringify(lines)}\nunlinked`, format)],
|
|
116
|
+
now,
|
|
117
|
+
});
|
|
118
|
+
await linkEvent(store, details, now, { create: source.createsEvents !== false });
|
|
119
|
+
return details;
|
|
120
|
+
};
|
|
20
121
|
/** A start that does not parse sorts last; its own save reports it. */
|
|
21
122
|
const startOf = (m) => {
|
|
22
123
|
const at = Date.parse(m.occurrence.startedAt);
|
|
@@ -84,7 +185,7 @@ export const pull = async (source, store, options) => {
|
|
|
84
185
|
};
|
|
85
186
|
try {
|
|
86
187
|
const sourceParticipants = await read("participants", () => source.participants(id));
|
|
87
|
-
const participants = (
|
|
188
|
+
const participants = participantInputs(source.provider, id, sourceParticipants ?? [], options.accountId);
|
|
88
189
|
const names = new Map();
|
|
89
190
|
for (const p of participants)
|
|
90
191
|
if (p.displayName !== null) {
|
|
@@ -100,83 +201,7 @@ export const pull = async (source, store, options) => {
|
|
|
100
201
|
const attachments = await read("files", () => source.files(id));
|
|
101
202
|
const listDocuments = source.documents?.bind(source);
|
|
102
203
|
const documents = listDocuments ? await read("documents", () => listDocuments(id)) : undefined;
|
|
103
|
-
|
|
104
|
-
const endedAt = m.occurrence.endedAt === null ? null : timestamp(m.occurrence.endedAt);
|
|
105
|
-
if (endedAt !== null && endedAt < startedAt)
|
|
106
|
-
throw new Error("Meeting ends before it starts");
|
|
107
|
-
const meeting = {
|
|
108
|
-
accountId: options.accountId,
|
|
109
|
-
externalId: id,
|
|
110
|
-
title: m.occurrence.title,
|
|
111
|
-
description: m.description ?? null,
|
|
112
|
-
location: m.location ?? null,
|
|
113
|
-
joinUrl: m.joinUrl ?? m.series?.joinUrl ?? null,
|
|
114
|
-
startedAt,
|
|
115
|
-
endedAt,
|
|
116
|
-
durationMs: endedAt === null ? null : endedAt - startedAt,
|
|
117
|
-
timezone: m.timezone ?? null,
|
|
118
|
-
hostIdentityId: null,
|
|
119
|
-
...(sourceParticipants === undefined ? {} : { participantsCount: sourceParticipants?.length ?? null }),
|
|
120
|
-
metadata: m.metadata ?? null,
|
|
121
|
-
deletedAt: null,
|
|
122
|
-
};
|
|
123
|
-
if (m.series)
|
|
124
|
-
meeting.series = {
|
|
125
|
-
externalId: m.series.id,
|
|
126
|
-
title: m.series.title,
|
|
127
|
-
description: null,
|
|
128
|
-
kind: m.series.kind ?? null,
|
|
129
|
-
recurrence: m.series.recurrence ?? null,
|
|
130
|
-
hostIdentityId: null,
|
|
131
|
-
joinUrl: m.series.joinUrl ?? null,
|
|
132
|
-
metadata: null,
|
|
133
|
-
deletedAt: null,
|
|
134
|
-
};
|
|
135
|
-
const linked = sourceParticipants !== undefined;
|
|
136
|
-
const format = source.transcriptFormat ?? null;
|
|
137
|
-
const transcripts = lines && linked ? [await transcriptInput(lines, participants, source.name, undefined, format)] : undefined;
|
|
138
|
-
const details = await store.saveMeeting({
|
|
139
|
-
meeting,
|
|
140
|
-
participants: sourceParticipants ? participants : undefined,
|
|
141
|
-
transcripts,
|
|
142
|
-
chat: chat?.map((line) => ({
|
|
143
|
-
externalId: null,
|
|
144
|
-
sentAt: timestamp(line.sentAt),
|
|
145
|
-
senderParticipantPosition: speakerPosition(line.sender, participants),
|
|
146
|
-
senderName: line.sender,
|
|
147
|
-
recipient: null,
|
|
148
|
-
text: line.text,
|
|
149
|
-
normalizedText: null,
|
|
150
|
-
metadata: null,
|
|
151
|
-
})),
|
|
152
|
-
summaries: summary
|
|
153
|
-
? [
|
|
154
|
-
{
|
|
155
|
-
...summary,
|
|
156
|
-
source: summary.source ?? source.name,
|
|
157
|
-
content: summary.content ?? null,
|
|
158
|
-
docUrl: summary.docUrl ?? null,
|
|
159
|
-
externalCreatedAt: summary.externalCreatedAt ?? null,
|
|
160
|
-
externalUpdatedAt: summary.externalUpdatedAt ?? null,
|
|
161
|
-
metadata: summary.metadata ?? null,
|
|
162
|
-
},
|
|
163
|
-
]
|
|
164
|
-
: undefined,
|
|
165
|
-
attachments: attachments ?? undefined,
|
|
166
|
-
documents: documents ?? undefined,
|
|
167
|
-
now,
|
|
168
|
-
});
|
|
169
|
-
// Without participants the rows cannot be linked: they are saved only when the meeting has no current
|
|
170
|
-
// transcript to downgrade, under a distinct hash so the retry that reads participants is not a replay.
|
|
171
|
-
if (lines &&
|
|
172
|
-
!linked &&
|
|
173
|
-
!details.transcripts.some((t) => t.transcript.source === source.name && t.transcript.supersededAt === null))
|
|
174
|
-
await store.saveMeeting({
|
|
175
|
-
meeting,
|
|
176
|
-
transcripts: [await transcriptInput(lines, [], source.name, `${JSON.stringify(lines)}\nunlinked`, format)],
|
|
177
|
-
now,
|
|
178
|
-
});
|
|
179
|
-
await linkEvent(store, details, now, { create: source.createsEvents !== false });
|
|
204
|
+
await saveSourceMeeting(source, store, m, { participants: sourceParticipants, transcript: lines, chat, summary, files: attachments, documents }, { accountId: options.accountId, now });
|
|
180
205
|
for (const p of participants)
|
|
181
206
|
if (p.identity.phone)
|
|
182
207
|
callers.add(p.identity.externalId);
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
import { type QueryAst } from "@wirecat/cli-base/query";
|
|
2
|
+
import type { Meta, Missing } from "@wirecat/cli-base/standards";
|
|
3
|
+
import { type Backend } from "../search/service-query.js";
|
|
4
|
+
import type { MeetingItem } from "./item.js";
|
|
5
|
+
import { type MeetingList } from "./reads.js";
|
|
6
|
+
import type { MeetingSource } from "./source.js";
|
|
7
|
+
import type { MeetingDetails, MeetingFilter, MeetingStore } from "./store.js";
|
|
8
|
+
/**
|
|
9
|
+
* `meetings list` asks at most `calls` calls of `find`, each up to `pages` pages; past either the answer says it is not
|
|
10
|
+
* complete. The same three calls as messages search.
|
|
11
|
+
*/
|
|
12
|
+
export declare const MEETING_SERVER_BOUNDS: {
|
|
13
|
+
calls: number;
|
|
14
|
+
pages: number;
|
|
15
|
+
};
|
|
16
|
+
export type MeetingServerSkip = "unsupported" | "offline" | "unreachable" | "not_signed_in" | "refused" | "failed" | "no_upcoming";
|
|
17
|
+
/** What asking the service did, as messages search's `server` says it. */
|
|
18
|
+
export interface MeetingServerReport {
|
|
19
|
+
backend: "server" | "both";
|
|
20
|
+
skipped: MeetingServerSkip | null;
|
|
21
|
+
calls: number;
|
|
22
|
+
returned: number;
|
|
23
|
+
/** Meetings the store did not hold before this read. */
|
|
24
|
+
new: number;
|
|
25
|
+
/** Meetings the service returned that could not be kept, so the store's answer cannot have them. */
|
|
26
|
+
failed: number;
|
|
27
|
+
complete: boolean;
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* Where a read may look and what stops it asking the service; `backend` as typed, so its absence means `both`.
|
|
31
|
+
* `timezone` and `now` read the query's dates the same way on both sides: the service's window and the store's query.
|
|
32
|
+
*/
|
|
33
|
+
export interface MeetingServerAccess {
|
|
34
|
+
backend?: Backend;
|
|
35
|
+
offline?: boolean;
|
|
36
|
+
now?: number;
|
|
37
|
+
timezone?: string;
|
|
38
|
+
}
|
|
39
|
+
type FoundIn = NonNullable<MeetingItem["found_in"]>;
|
|
40
|
+
interface ServerStep {
|
|
41
|
+
report: MeetingServerReport;
|
|
42
|
+
/** Store meeting id → whether the store held it before the service returned it. */
|
|
43
|
+
found: Map<number, Exclude<FoundIn, "archive">>;
|
|
44
|
+
missing: Missing[];
|
|
45
|
+
/** What the host's `meta` says of it: not complete when the service could not be read, cut at the call cap. */
|
|
46
|
+
meta?: Partial<Meta>;
|
|
47
|
+
}
|
|
48
|
+
/**
|
|
49
|
+
* Asks the service for the meetings a `meetings list` query may match and keeps them, so the store query that runs
|
|
50
|
+
* next sees them. The service gets only what it can filter (`serviceCallsOf`): a wider set, never a narrower one.
|
|
51
|
+
* Without a typed `--backend server`, a service that cannot be asked leaves the store's answer and a `missing` line.
|
|
52
|
+
*/
|
|
53
|
+
export declare const askServerForList: (source: MeetingSource | undefined, store: MeetingStore, accountId: number, query: QueryAst | undefined, access: MeetingServerAccess) => Promise<ServerStep | undefined>;
|
|
54
|
+
/** `meetings list` with the service asked first, as `--backend` says; the store's query and paging decide. */
|
|
55
|
+
export type MeetingListThrough = MeetingList & {
|
|
56
|
+
server?: MeetingServerReport;
|
|
57
|
+
meta?: Partial<Meta>;
|
|
58
|
+
};
|
|
59
|
+
export declare const meetingsListThrough: (source: MeetingSource | undefined, store: MeetingStore, filter: MeetingFilter & {
|
|
60
|
+
accountId: number;
|
|
61
|
+
}, access: MeetingServerAccess) => Promise<MeetingListThrough>;
|
|
62
|
+
export interface MeetingShowThrough {
|
|
63
|
+
details: MeetingDetails;
|
|
64
|
+
foundIn?: FoundIn;
|
|
65
|
+
server?: MeetingServerReport;
|
|
66
|
+
missing?: Missing[];
|
|
67
|
+
meta?: Partial<Meta>;
|
|
68
|
+
}
|
|
69
|
+
/**
|
|
70
|
+
* `meetings show`: the stored meeting `meeting` names (store number first, then `meeting:` ref, then the service's
|
|
71
|
+
* id), read again from the service with its people, transcript and Drive documents and kept, as `--backend` says.
|
|
72
|
+
*/
|
|
73
|
+
export declare const meetingShowThrough: (source: MeetingSource | undefined, store: MeetingStore, accountId: number, meeting: string, access: MeetingServerAccess) => Promise<MeetingShowThrough>;
|
|
74
|
+
export {};
|
|
@@ -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>]>;
|