@dench.com/cli 2.9.1 → 2.9.2
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/crm.ts +9 -5
- package/dench.ts +49 -0
- package/lib/api-schemas.ts +81 -0
- package/lib/command-registry.ts +167 -12
- package/lib/meetings-import.ts +426 -0
- package/meetings.ts +701 -0
- package/package.json +2 -1
package/meetings.ts
ADDED
|
@@ -0,0 +1,701 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `dench meetings …`
|
|
3
|
+
*
|
|
4
|
+
* A meeting is an ordinary CRM record (`dench crm entries … meeting`), so
|
|
5
|
+
* this module only adds what the CRM verbs cannot reach: the transcript,
|
|
6
|
+
* the action-item checklist and the attendance roster, which live in side
|
|
7
|
+
* tables on the server (`convex/functions/meetings/importer.ts`), plus
|
|
8
|
+
* `import`, which stitches a CSV/JSONL of calls into all of them at once.
|
|
9
|
+
*
|
|
10
|
+
* Every write here goes through the same Convex functions the Meetings tab
|
|
11
|
+
* uses, so the CLI, `/api/v1/meetings/…` and the UI share one contract.
|
|
12
|
+
*/
|
|
13
|
+
|
|
14
|
+
import { readFile } from "node:fs/promises";
|
|
15
|
+
import { makeFunctionReference } from "convex/server";
|
|
16
|
+
import {
|
|
17
|
+
applyBatchOpsInChunks,
|
|
18
|
+
assertNoUnknownFlags,
|
|
19
|
+
type CrmBatchOp,
|
|
20
|
+
type CrmCliContext,
|
|
21
|
+
CrmCliError,
|
|
22
|
+
callMutation,
|
|
23
|
+
callQuery,
|
|
24
|
+
countResultStatuses,
|
|
25
|
+
importSeedKeyForRow,
|
|
26
|
+
out,
|
|
27
|
+
parseCsv,
|
|
28
|
+
parseOnConflictFlag,
|
|
29
|
+
remapKeys,
|
|
30
|
+
shift,
|
|
31
|
+
} from "./crm";
|
|
32
|
+
import { getFlag, hasFlag, parseJson } from "./lib/cli-args";
|
|
33
|
+
import {
|
|
34
|
+
applyMeetingFieldDefaults,
|
|
35
|
+
type ImportedActionItem,
|
|
36
|
+
type ImportedAttendee,
|
|
37
|
+
type ImportedSegment,
|
|
38
|
+
type MeetingImportRow,
|
|
39
|
+
normalizeActionItems,
|
|
40
|
+
normalizeAttendees,
|
|
41
|
+
normalizeTranscript,
|
|
42
|
+
parseDateMs,
|
|
43
|
+
parseTranscriptText,
|
|
44
|
+
splitMeetingImportRow,
|
|
45
|
+
} from "./lib/meetings-import";
|
|
46
|
+
|
|
47
|
+
const api = {
|
|
48
|
+
library: {
|
|
49
|
+
listMeetings: makeFunctionReference<"query">(
|
|
50
|
+
"functions/meetings/library:listMeetings",
|
|
51
|
+
),
|
|
52
|
+
},
|
|
53
|
+
entries: {
|
|
54
|
+
get: makeFunctionReference<"query">("functions/crm/entries:get"),
|
|
55
|
+
},
|
|
56
|
+
transcripts: {
|
|
57
|
+
list: makeFunctionReference<"query">(
|
|
58
|
+
"functions/meetings/transcripts:listMeetingTranscript",
|
|
59
|
+
),
|
|
60
|
+
},
|
|
61
|
+
actionItems: {
|
|
62
|
+
list: makeFunctionReference<"query">(
|
|
63
|
+
"functions/meetings/actionItems:listActionItems",
|
|
64
|
+
),
|
|
65
|
+
setDone: makeFunctionReference<"mutation">(
|
|
66
|
+
"functions/meetings/actionItems:setActionItemDone",
|
|
67
|
+
),
|
|
68
|
+
remove: makeFunctionReference<"mutation">(
|
|
69
|
+
"functions/meetings/actionItems:deleteActionItem",
|
|
70
|
+
),
|
|
71
|
+
},
|
|
72
|
+
participants: {
|
|
73
|
+
roster: makeFunctionReference<"query">(
|
|
74
|
+
"functions/meetings/participantLinks:listMeetingParticipantRoster",
|
|
75
|
+
),
|
|
76
|
+
},
|
|
77
|
+
importer: {
|
|
78
|
+
clearTranscript: makeFunctionReference<"mutation">(
|
|
79
|
+
"functions/meetings/importer:clearTranscript",
|
|
80
|
+
),
|
|
81
|
+
appendTranscriptSegments: makeFunctionReference<"mutation">(
|
|
82
|
+
"functions/meetings/importer:appendTranscriptSegments",
|
|
83
|
+
),
|
|
84
|
+
addActionItems: makeFunctionReference<"mutation">(
|
|
85
|
+
"functions/meetings/importer:addActionItems",
|
|
86
|
+
),
|
|
87
|
+
setParticipants: makeFunctionReference<"mutation">(
|
|
88
|
+
"functions/meetings/importer:setParticipants",
|
|
89
|
+
),
|
|
90
|
+
},
|
|
91
|
+
};
|
|
92
|
+
|
|
93
|
+
/** Server cap on `appendTranscriptSegments`; keep in sync with importer.ts. */
|
|
94
|
+
const SEGMENT_CHUNK = 500;
|
|
95
|
+
const TRANSCRIPT_PAGE = 500;
|
|
96
|
+
|
|
97
|
+
export async function runMeetingsCommand(opts: {
|
|
98
|
+
convex: CrmCliContext["convex"];
|
|
99
|
+
args: string[];
|
|
100
|
+
sessionToken?: string;
|
|
101
|
+
host?: string;
|
|
102
|
+
workspaceSlug?: string;
|
|
103
|
+
}): Promise<void> {
|
|
104
|
+
const args = [...opts.args];
|
|
105
|
+
const jsonOutput = hasFlag(args, "--json");
|
|
106
|
+
const ctx: CrmCliContext = {
|
|
107
|
+
convex: opts.convex,
|
|
108
|
+
args,
|
|
109
|
+
jsonOutput,
|
|
110
|
+
sessionToken: opts.sessionToken,
|
|
111
|
+
runId: process.env.DENCH_RUN_ID?.trim() || undefined,
|
|
112
|
+
host: opts.host,
|
|
113
|
+
workspaceSlug: opts.workspaceSlug,
|
|
114
|
+
};
|
|
115
|
+
const subcommand = args.shift();
|
|
116
|
+
if (!subcommand || subcommand === "help" || subcommand === "--help") {
|
|
117
|
+
meetingsHelp();
|
|
118
|
+
return;
|
|
119
|
+
}
|
|
120
|
+
switch (subcommand) {
|
|
121
|
+
case "list":
|
|
122
|
+
return await runList(ctx);
|
|
123
|
+
case "get":
|
|
124
|
+
return await runGet(ctx);
|
|
125
|
+
case "transcript":
|
|
126
|
+
return await runTranscript(ctx);
|
|
127
|
+
case "action-items":
|
|
128
|
+
case "actions":
|
|
129
|
+
return await runActionItems(ctx);
|
|
130
|
+
case "participants":
|
|
131
|
+
case "attendees":
|
|
132
|
+
return await runParticipants(ctx);
|
|
133
|
+
case "import":
|
|
134
|
+
return await runImport(ctx);
|
|
135
|
+
default:
|
|
136
|
+
throw new CrmCliError(
|
|
137
|
+
`Unknown meetings subcommand: ${subcommand}. Run \`dench meetings help\`.`,
|
|
138
|
+
);
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
// ── list / get ─────────────────────────────────────────────────────────────
|
|
143
|
+
|
|
144
|
+
async function runList(ctx: CrmCliContext): Promise<void> {
|
|
145
|
+
const limitRaw = getFlag(ctx.args, "--limit");
|
|
146
|
+
assertNoUnknownFlags(ctx.args, "meetings list");
|
|
147
|
+
const numItems = limitRaw ? Number(limitRaw) : 50;
|
|
148
|
+
if (!Number.isFinite(numItems) || numItems <= 0) {
|
|
149
|
+
throw new CrmCliError("--limit must be a positive number");
|
|
150
|
+
}
|
|
151
|
+
const result = (await callQuery(ctx, api.library.listMeetings, {
|
|
152
|
+
paginationOpts: { numItems, cursor: null },
|
|
153
|
+
})) as { page?: unknown[] } | null;
|
|
154
|
+
out(ctx, result?.page ?? []);
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
async function runGet(ctx: CrmCliContext): Promise<void> {
|
|
158
|
+
const entryId = shift(ctx.args, "meeting id");
|
|
159
|
+
assertNoUnknownFlags(ctx.args, "meetings get");
|
|
160
|
+
const entry = await callQuery(ctx, api.entries.get, {
|
|
161
|
+
objectName: "meeting",
|
|
162
|
+
entryId,
|
|
163
|
+
});
|
|
164
|
+
if (!entry) throw new CrmCliError(`Meeting not found: ${entryId}`);
|
|
165
|
+
out(ctx, entry);
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
// ── transcript ─────────────────────────────────────────────────────────────
|
|
169
|
+
|
|
170
|
+
async function runTranscript(ctx: CrmCliContext): Promise<void> {
|
|
171
|
+
const verb = shift(ctx.args, "transcript verb (get|set|clear)");
|
|
172
|
+
switch (verb) {
|
|
173
|
+
case "get":
|
|
174
|
+
return await runTranscriptGet(ctx);
|
|
175
|
+
case "set":
|
|
176
|
+
return await runTranscriptSet(ctx);
|
|
177
|
+
case "clear":
|
|
178
|
+
return await runTranscriptClear(ctx);
|
|
179
|
+
default:
|
|
180
|
+
throw new CrmCliError(
|
|
181
|
+
`dench meetings transcript <get|set|clear> <meetingId> … (got "${verb}")`,
|
|
182
|
+
);
|
|
183
|
+
}
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
async function fetchTranscript(
|
|
187
|
+
ctx: CrmCliContext,
|
|
188
|
+
meetingEntryId: string,
|
|
189
|
+
): Promise<
|
|
190
|
+
Array<{
|
|
191
|
+
seq: number;
|
|
192
|
+
speakerName: string | null;
|
|
193
|
+
startMs: number;
|
|
194
|
+
endMs: number;
|
|
195
|
+
text: string;
|
|
196
|
+
}>
|
|
197
|
+
> {
|
|
198
|
+
const rows: Array<{
|
|
199
|
+
seq: number;
|
|
200
|
+
speakerName: string | null;
|
|
201
|
+
startMs: number;
|
|
202
|
+
endMs: number;
|
|
203
|
+
text: string;
|
|
204
|
+
}> = [];
|
|
205
|
+
let cursor: string | null = null;
|
|
206
|
+
for (;;) {
|
|
207
|
+
const page = (await callQuery(ctx, api.transcripts.list, {
|
|
208
|
+
meetingEntryId,
|
|
209
|
+
paginationOpts: { numItems: TRANSCRIPT_PAGE, cursor },
|
|
210
|
+
})) as {
|
|
211
|
+
page: typeof rows;
|
|
212
|
+
isDone: boolean;
|
|
213
|
+
continueCursor: string;
|
|
214
|
+
};
|
|
215
|
+
rows.push(...page.page);
|
|
216
|
+
if (page.isDone || page.page.length === 0) break;
|
|
217
|
+
cursor = page.continueCursor;
|
|
218
|
+
}
|
|
219
|
+
return rows;
|
|
220
|
+
}
|
|
221
|
+
|
|
222
|
+
function formatOffset(ms: number): string {
|
|
223
|
+
const total = Math.floor(ms / 1000);
|
|
224
|
+
const h = Math.floor(total / 3600);
|
|
225
|
+
const m = Math.floor((total % 3600) / 60);
|
|
226
|
+
const s = total % 60;
|
|
227
|
+
const mm = String(m).padStart(2, "0");
|
|
228
|
+
const ss = String(s).padStart(2, "0");
|
|
229
|
+
return h > 0 ? `${h}:${mm}:${ss}` : `${mm}:${ss}`;
|
|
230
|
+
}
|
|
231
|
+
|
|
232
|
+
async function runTranscriptGet(ctx: CrmCliContext): Promise<void> {
|
|
233
|
+
const meetingEntryId = shift(ctx.args, "meeting id");
|
|
234
|
+
const asText = hasFlag(ctx.args, "--text");
|
|
235
|
+
assertNoUnknownFlags(ctx.args, "meetings transcript get");
|
|
236
|
+
const rows = await fetchTranscript(ctx, meetingEntryId);
|
|
237
|
+
if (ctx.jsonOutput && !asText) {
|
|
238
|
+
out(ctx, rows);
|
|
239
|
+
return;
|
|
240
|
+
}
|
|
241
|
+
const timed = rows.some((row) => row.startMs > 0);
|
|
242
|
+
for (const row of rows) {
|
|
243
|
+
const prefix = timed ? `[${formatOffset(row.startMs)}] ` : "";
|
|
244
|
+
const speaker = row.speakerName ? `${row.speakerName}: ` : "";
|
|
245
|
+
console.log(`${prefix}${speaker}${row.text}`);
|
|
246
|
+
}
|
|
247
|
+
if (rows.length === 0) console.log("(no transcript)");
|
|
248
|
+
}
|
|
249
|
+
|
|
250
|
+
async function readSegmentsFromFlags(
|
|
251
|
+
ctx: CrmCliContext,
|
|
252
|
+
command: string,
|
|
253
|
+
): Promise<ImportedSegment[]> {
|
|
254
|
+
const jsonlPath = getFlag(ctx.args, "--jsonl");
|
|
255
|
+
const jsonPath = getFlag(ctx.args, "--file");
|
|
256
|
+
const textPath = getFlag(ctx.args, "--text");
|
|
257
|
+
assertNoUnknownFlags(ctx.args, command);
|
|
258
|
+
const given = [jsonlPath, jsonPath, textPath].filter(Boolean).length;
|
|
259
|
+
if (given !== 1) {
|
|
260
|
+
throw new CrmCliError(
|
|
261
|
+
`${command} needs exactly one of --jsonl <path>, --file <path> (JSON array) or --text <path>`,
|
|
262
|
+
);
|
|
263
|
+
}
|
|
264
|
+
if (textPath) {
|
|
265
|
+
return parseTranscriptText(await readFile(textPath, "utf-8"));
|
|
266
|
+
}
|
|
267
|
+
if (jsonPath) {
|
|
268
|
+
const parsed = JSON.parse(await readFile(jsonPath, "utf-8"));
|
|
269
|
+
const segments = normalizeTranscript(parsed);
|
|
270
|
+
if (!segments) throw new CrmCliError(`${jsonPath} is not a transcript`);
|
|
271
|
+
return segments;
|
|
272
|
+
}
|
|
273
|
+
const rows: unknown[] = [];
|
|
274
|
+
for (const line of (await readFile(jsonlPath as string, "utf-8")).split(
|
|
275
|
+
"\n",
|
|
276
|
+
)) {
|
|
277
|
+
const trimmed = line.trim();
|
|
278
|
+
if (!trimmed || trimmed.startsWith("#")) continue;
|
|
279
|
+
rows.push(JSON.parse(trimmed));
|
|
280
|
+
}
|
|
281
|
+
return normalizeTranscript(rows) ?? [];
|
|
282
|
+
}
|
|
283
|
+
|
|
284
|
+
async function clearTranscriptFully(
|
|
285
|
+
ctx: CrmCliContext,
|
|
286
|
+
meetingEntryId: string,
|
|
287
|
+
): Promise<number> {
|
|
288
|
+
let deleted = 0;
|
|
289
|
+
for (;;) {
|
|
290
|
+
const result = (await callMutation(ctx, api.importer.clearTranscript, {
|
|
291
|
+
meetingEntryId,
|
|
292
|
+
})) as { deleted: number; done: boolean };
|
|
293
|
+
deleted += result.deleted;
|
|
294
|
+
if (result.done) return deleted;
|
|
295
|
+
}
|
|
296
|
+
}
|
|
297
|
+
|
|
298
|
+
async function appendTranscript(
|
|
299
|
+
ctx: CrmCliContext,
|
|
300
|
+
meetingEntryId: string,
|
|
301
|
+
segments: ImportedSegment[],
|
|
302
|
+
): Promise<{ inserted: number; linkedPeople: number }> {
|
|
303
|
+
let inserted = 0;
|
|
304
|
+
let linkedPeople = 0;
|
|
305
|
+
for (let index = 0; index < segments.length; index += SEGMENT_CHUNK) {
|
|
306
|
+
const chunk = segments.slice(index, index + SEGMENT_CHUNK);
|
|
307
|
+
const result = (await callMutation(
|
|
308
|
+
ctx,
|
|
309
|
+
api.importer.appendTranscriptSegments,
|
|
310
|
+
{ meetingEntryId, segments: chunk },
|
|
311
|
+
)) as { inserted: number; linkedPeople: number };
|
|
312
|
+
inserted += result.inserted;
|
|
313
|
+
linkedPeople += result.linkedPeople;
|
|
314
|
+
}
|
|
315
|
+
return { inserted, linkedPeople };
|
|
316
|
+
}
|
|
317
|
+
|
|
318
|
+
async function runTranscriptSet(ctx: CrmCliContext): Promise<void> {
|
|
319
|
+
const meetingEntryId = shift(ctx.args, "meeting id");
|
|
320
|
+
const append = hasFlag(ctx.args, "--append");
|
|
321
|
+
const segments = await readSegmentsFromFlags(ctx, "meetings transcript set");
|
|
322
|
+
if (segments.length === 0) {
|
|
323
|
+
throw new CrmCliError("No transcript lines were parsed from the file.");
|
|
324
|
+
}
|
|
325
|
+
const deleted = append ? 0 : await clearTranscriptFully(ctx, meetingEntryId);
|
|
326
|
+
const result = await appendTranscript(ctx, meetingEntryId, segments);
|
|
327
|
+
out(ctx, {
|
|
328
|
+
meetingEntryId,
|
|
329
|
+
parsed: segments.length,
|
|
330
|
+
replaced: deleted,
|
|
331
|
+
...result,
|
|
332
|
+
timed: segments.some((segment) => (segment.startMs ?? 0) > 0),
|
|
333
|
+
});
|
|
334
|
+
}
|
|
335
|
+
|
|
336
|
+
async function runTranscriptClear(ctx: CrmCliContext): Promise<void> {
|
|
337
|
+
const meetingEntryId = shift(ctx.args, "meeting id");
|
|
338
|
+
assertNoUnknownFlags(ctx.args, "meetings transcript clear");
|
|
339
|
+
const deleted = await clearTranscriptFully(ctx, meetingEntryId);
|
|
340
|
+
out(ctx, { meetingEntryId, deleted });
|
|
341
|
+
}
|
|
342
|
+
|
|
343
|
+
// ── action items ───────────────────────────────────────────────────────────
|
|
344
|
+
|
|
345
|
+
async function runActionItems(ctx: CrmCliContext): Promise<void> {
|
|
346
|
+
const verb = shift(ctx.args, "action-items verb (list|add|set|done|delete)");
|
|
347
|
+
switch (verb) {
|
|
348
|
+
case "list": {
|
|
349
|
+
const meetingEntryId = shift(ctx.args, "meeting id");
|
|
350
|
+
assertNoUnknownFlags(ctx.args, "meetings action-items list");
|
|
351
|
+
out(ctx, await callQuery(ctx, api.actionItems.list, { meetingEntryId }));
|
|
352
|
+
return;
|
|
353
|
+
}
|
|
354
|
+
case "add": {
|
|
355
|
+
const meetingEntryId = shift(ctx.args, "meeting id");
|
|
356
|
+
const text = shift(ctx.args, "action item text");
|
|
357
|
+
const ownerName = getFlag(ctx.args, "--owner");
|
|
358
|
+
const done = hasFlag(ctx.args, "--done");
|
|
359
|
+
assertNoUnknownFlags(ctx.args, "meetings action-items add");
|
|
360
|
+
const result = await callMutation(ctx, api.importer.addActionItems, {
|
|
361
|
+
meetingEntryId,
|
|
362
|
+
items: [{ text, ...(ownerName ? { ownerName } : {}), done }],
|
|
363
|
+
});
|
|
364
|
+
out(ctx, result);
|
|
365
|
+
return;
|
|
366
|
+
}
|
|
367
|
+
case "set": {
|
|
368
|
+
const meetingEntryId = shift(ctx.args, "meeting id");
|
|
369
|
+
const items = await readItemsFromFlags(ctx, "meetings action-items set");
|
|
370
|
+
const replace = !hasFlag(ctx.args, "--append");
|
|
371
|
+
assertNoUnknownFlags(ctx.args, "meetings action-items set");
|
|
372
|
+
const result = await callMutation(ctx, api.importer.addActionItems, {
|
|
373
|
+
meetingEntryId,
|
|
374
|
+
items,
|
|
375
|
+
replace,
|
|
376
|
+
});
|
|
377
|
+
out(ctx, result);
|
|
378
|
+
return;
|
|
379
|
+
}
|
|
380
|
+
case "done":
|
|
381
|
+
case "undone": {
|
|
382
|
+
const itemId = shift(ctx.args, "action item id");
|
|
383
|
+
assertNoUnknownFlags(ctx.args, `meetings action-items ${verb}`);
|
|
384
|
+
await callMutation(ctx, api.actionItems.setDone, {
|
|
385
|
+
itemId,
|
|
386
|
+
done: verb === "done",
|
|
387
|
+
});
|
|
388
|
+
out(ctx, { itemId, done: verb === "done" });
|
|
389
|
+
return;
|
|
390
|
+
}
|
|
391
|
+
case "delete": {
|
|
392
|
+
const itemId = shift(ctx.args, "action item id");
|
|
393
|
+
assertNoUnknownFlags(ctx.args, "meetings action-items delete");
|
|
394
|
+
await callMutation(ctx, api.actionItems.remove, { itemId });
|
|
395
|
+
out(ctx, { itemId, deleted: true });
|
|
396
|
+
return;
|
|
397
|
+
}
|
|
398
|
+
default:
|
|
399
|
+
throw new CrmCliError(
|
|
400
|
+
`dench meetings action-items <list|add|set|done|undone|delete> … (got "${verb}")`,
|
|
401
|
+
);
|
|
402
|
+
}
|
|
403
|
+
}
|
|
404
|
+
|
|
405
|
+
async function readItemsFromFlags(
|
|
406
|
+
ctx: CrmCliContext,
|
|
407
|
+
command: string,
|
|
408
|
+
): Promise<ImportedActionItem[]> {
|
|
409
|
+
const inline = getFlag(ctx.args, "--items");
|
|
410
|
+
const filePath = getFlag(ctx.args, "--file");
|
|
411
|
+
if ((inline ? 1 : 0) + (filePath ? 1 : 0) !== 1) {
|
|
412
|
+
throw new CrmCliError(
|
|
413
|
+
`${command} needs exactly one of --items '<json array or lines>' or --file <path> (JSON, JSONL or markdown checklist)`,
|
|
414
|
+
);
|
|
415
|
+
}
|
|
416
|
+
const raw = inline ?? (await readFile(filePath as string, "utf-8"));
|
|
417
|
+
const items = normalizeActionItems(
|
|
418
|
+
looksLikeJsonl(raw) ? parseJsonl(raw) : raw,
|
|
419
|
+
);
|
|
420
|
+
if (!items || items.length === 0) {
|
|
421
|
+
throw new CrmCliError("No action items were parsed.");
|
|
422
|
+
}
|
|
423
|
+
return items;
|
|
424
|
+
}
|
|
425
|
+
|
|
426
|
+
// ── participants ───────────────────────────────────────────────────────────
|
|
427
|
+
|
|
428
|
+
async function runParticipants(ctx: CrmCliContext): Promise<void> {
|
|
429
|
+
const verb = shift(ctx.args, "participants verb (list|set)");
|
|
430
|
+
switch (verb) {
|
|
431
|
+
case "list": {
|
|
432
|
+
const meetingEntryId = shift(ctx.args, "meeting id");
|
|
433
|
+
assertNoUnknownFlags(ctx.args, "meetings participants list");
|
|
434
|
+
const roster = (await callQuery(ctx, api.participants.roster, {
|
|
435
|
+
meetingEntryId,
|
|
436
|
+
})) as { participants?: unknown[] } | null;
|
|
437
|
+
out(ctx, roster?.participants ?? []);
|
|
438
|
+
return;
|
|
439
|
+
}
|
|
440
|
+
case "set":
|
|
441
|
+
case "add": {
|
|
442
|
+
const meetingEntryId = shift(ctx.args, "meeting id");
|
|
443
|
+
const inline = getFlag(ctx.args, "--people");
|
|
444
|
+
const filePath = getFlag(ctx.args, "--file");
|
|
445
|
+
const replace = verb === "set" && hasFlag(ctx.args, "--replace");
|
|
446
|
+
assertNoUnknownFlags(ctx.args, `meetings participants ${verb}`);
|
|
447
|
+
if ((inline ? 1 : 0) + (filePath ? 1 : 0) !== 1) {
|
|
448
|
+
throw new CrmCliError(
|
|
449
|
+
`dench meetings participants ${verb} <meetingId> --people 'Name <email>; other@x.com' | --file <path> [--replace]`,
|
|
450
|
+
);
|
|
451
|
+
}
|
|
452
|
+
const raw = inline ?? (await readFile(filePath as string, "utf-8"));
|
|
453
|
+
const participants: ImportedAttendee[] | null = normalizeAttendees(
|
|
454
|
+
looksLikeJsonl(raw) ? parseJsonl(raw) : raw,
|
|
455
|
+
);
|
|
456
|
+
if (!participants || participants.length === 0) {
|
|
457
|
+
throw new CrmCliError("No participants were parsed.");
|
|
458
|
+
}
|
|
459
|
+
const result = await callMutation(ctx, api.importer.setParticipants, {
|
|
460
|
+
meetingEntryId,
|
|
461
|
+
participants,
|
|
462
|
+
replace,
|
|
463
|
+
});
|
|
464
|
+
out(ctx, result);
|
|
465
|
+
return;
|
|
466
|
+
}
|
|
467
|
+
default:
|
|
468
|
+
throw new CrmCliError(
|
|
469
|
+
`dench meetings participants <list|set|add> … (got "${verb}")`,
|
|
470
|
+
);
|
|
471
|
+
}
|
|
472
|
+
}
|
|
473
|
+
|
|
474
|
+
function looksLikeJsonl(raw: string): boolean {
|
|
475
|
+
const lines = raw.split("\n").filter((line) => line.trim());
|
|
476
|
+
return (
|
|
477
|
+
lines.length > 1 &&
|
|
478
|
+
lines.every((line) => {
|
|
479
|
+
const t = line.trim();
|
|
480
|
+
return t.startsWith("{") && t.endsWith("}");
|
|
481
|
+
})
|
|
482
|
+
);
|
|
483
|
+
}
|
|
484
|
+
|
|
485
|
+
function parseJsonl(raw: string): unknown[] {
|
|
486
|
+
return raw
|
|
487
|
+
.split("\n")
|
|
488
|
+
.map((line) => line.trim())
|
|
489
|
+
.filter((line) => line && !line.startsWith("#"))
|
|
490
|
+
.map((line) => JSON.parse(line));
|
|
491
|
+
}
|
|
492
|
+
|
|
493
|
+
// ── import ─────────────────────────────────────────────────────────────────
|
|
494
|
+
|
|
495
|
+
type RowOutcome = {
|
|
496
|
+
row: number;
|
|
497
|
+
entryId: string | null;
|
|
498
|
+
status: "created" | "already_existed" | "updated" | "error";
|
|
499
|
+
title: string | null;
|
|
500
|
+
transcriptSegments: number;
|
|
501
|
+
actionItems: number;
|
|
502
|
+
attendees: number;
|
|
503
|
+
linkedPeople: number;
|
|
504
|
+
warnings: string[];
|
|
505
|
+
error?: string;
|
|
506
|
+
};
|
|
507
|
+
|
|
508
|
+
/**
|
|
509
|
+
* `dench meetings import --csv calls.csv | --jsonl calls.jsonl`
|
|
510
|
+
*
|
|
511
|
+
* Two phases. First every row's meeting FIELDS go through the same
|
|
512
|
+
* `batch.apply` path as `dench crm import` — same `--map`, same
|
|
513
|
+
* `--dedupe-key`, same `--on-conflict` semantics, same seed keys — so the
|
|
514
|
+
* CRM-IMPORT playbook's verification steps apply unchanged. Then each
|
|
515
|
+
* created (or, with `--on-conflict update`, updated) meeting receives its
|
|
516
|
+
* transcript, action items and attendees. A skipped row is left entirely
|
|
517
|
+
* alone, side tables included.
|
|
518
|
+
*/
|
|
519
|
+
async function runImport(ctx: CrmCliContext): Promise<void> {
|
|
520
|
+
const csvPath = getFlag(ctx.args, "--csv");
|
|
521
|
+
const jsonlPath = getFlag(ctx.args, "--jsonl");
|
|
522
|
+
const mapJson = getFlag(ctx.args, "--map");
|
|
523
|
+
const dedupeColumn = getFlag(ctx.args, "--dedupe-key");
|
|
524
|
+
const onConflict = parseOnConflictFlag(getFlag(ctx.args, "--on-conflict"));
|
|
525
|
+
const allowUnknown = hasFlag(ctx.args, "--allow-unknown");
|
|
526
|
+
assertNoUnknownFlags(ctx.args, "meetings import");
|
|
527
|
+
if (!csvPath && !jsonlPath) {
|
|
528
|
+
throw new CrmCliError(
|
|
529
|
+
"dench meetings import requires --csv <path> or --jsonl <path>",
|
|
530
|
+
);
|
|
531
|
+
}
|
|
532
|
+
const colMap = mapJson ? (parseJson(mapJson) as Record<string, string>) : {};
|
|
533
|
+
const sourceRows: Record<string, unknown>[] = [];
|
|
534
|
+
if (csvPath) {
|
|
535
|
+
sourceRows.push(...parseCsv(await readFile(csvPath, "utf-8"), colMap));
|
|
536
|
+
}
|
|
537
|
+
if (jsonlPath) {
|
|
538
|
+
for (const parsed of parseJsonl(await readFile(jsonlPath, "utf-8"))) {
|
|
539
|
+
if (parsed && typeof parsed === "object" && !Array.isArray(parsed)) {
|
|
540
|
+
sourceRows.push(remapKeys(parsed as Record<string, unknown>, colMap));
|
|
541
|
+
}
|
|
542
|
+
}
|
|
543
|
+
}
|
|
544
|
+
|
|
545
|
+
const rows: MeetingImportRow[] = sourceRows.map((row) => {
|
|
546
|
+
const split = splitMeetingImportRow(row);
|
|
547
|
+
return { ...split, fields: applyMeetingFieldDefaults(split.fields) };
|
|
548
|
+
});
|
|
549
|
+
|
|
550
|
+
const { createHash } = await import("node:crypto");
|
|
551
|
+
const sha256 = (input: string) =>
|
|
552
|
+
createHash("sha256").update(input).digest("hex");
|
|
553
|
+
// The seed key hashes the meeting fields only: a corrected transcript
|
|
554
|
+
// must upsert the same meeting, not mint a second one.
|
|
555
|
+
const ops: CrmBatchOp[] = rows.map((row, index) => ({
|
|
556
|
+
type: "entries.create",
|
|
557
|
+
objectName: "meeting",
|
|
558
|
+
data: row.fields,
|
|
559
|
+
seedKey: importSeedKeyForRow({
|
|
560
|
+
objectName: "meeting",
|
|
561
|
+
row: row.fields,
|
|
562
|
+
rowIndex: index,
|
|
563
|
+
dedupeColumn,
|
|
564
|
+
sha256,
|
|
565
|
+
}),
|
|
566
|
+
rowIndex: index + 1,
|
|
567
|
+
}));
|
|
568
|
+
const { results } = await applyBatchOpsInChunks(
|
|
569
|
+
ctx,
|
|
570
|
+
ops,
|
|
571
|
+
undefined,
|
|
572
|
+
allowUnknown,
|
|
573
|
+
onConflict,
|
|
574
|
+
);
|
|
575
|
+
|
|
576
|
+
const outcomes: RowOutcome[] = [];
|
|
577
|
+
for (const [index, row] of rows.entries()) {
|
|
578
|
+
const result = results[index] as
|
|
579
|
+
| { entryId?: string; status?: string }
|
|
580
|
+
| undefined;
|
|
581
|
+
const entryId = result?.entryId ?? null;
|
|
582
|
+
const status = (result?.status ?? "created") as RowOutcome["status"];
|
|
583
|
+
const title =
|
|
584
|
+
typeof row.fields.Title === "string" ? row.fields.Title : null;
|
|
585
|
+
const outcome: RowOutcome = {
|
|
586
|
+
row: index + 1,
|
|
587
|
+
entryId,
|
|
588
|
+
status,
|
|
589
|
+
title,
|
|
590
|
+
transcriptSegments: 0,
|
|
591
|
+
actionItems: 0,
|
|
592
|
+
attendees: 0,
|
|
593
|
+
linkedPeople: 0,
|
|
594
|
+
warnings: [],
|
|
595
|
+
};
|
|
596
|
+
if (parseDateMs(row.fields["Started At"]) === null) {
|
|
597
|
+
outcome.warnings.push(
|
|
598
|
+
"no Started At — the meeting will not appear on a day in Meetings",
|
|
599
|
+
);
|
|
600
|
+
}
|
|
601
|
+
outcomes.push(outcome);
|
|
602
|
+
if (!entryId || status === "already_existed") continue;
|
|
603
|
+
const replacing = status === "updated";
|
|
604
|
+
try {
|
|
605
|
+
if (row.transcript && row.transcript.length > 0) {
|
|
606
|
+
if (replacing) await clearTranscriptFully(ctx, entryId);
|
|
607
|
+
const appended = await appendTranscript(ctx, entryId, row.transcript);
|
|
608
|
+
outcome.transcriptSegments = appended.inserted;
|
|
609
|
+
outcome.linkedPeople += appended.linkedPeople;
|
|
610
|
+
}
|
|
611
|
+
if (row.actionItems && row.actionItems.length > 0) {
|
|
612
|
+
const added = (await callMutation(ctx, api.importer.addActionItems, {
|
|
613
|
+
meetingEntryId: entryId,
|
|
614
|
+
items: row.actionItems,
|
|
615
|
+
replace: replacing,
|
|
616
|
+
})) as { inserted: number };
|
|
617
|
+
outcome.actionItems = added.inserted;
|
|
618
|
+
}
|
|
619
|
+
if (row.attendees && row.attendees.length > 0) {
|
|
620
|
+
const set = (await callMutation(ctx, api.importer.setParticipants, {
|
|
621
|
+
meetingEntryId: entryId,
|
|
622
|
+
participants: row.attendees,
|
|
623
|
+
})) as { upserted: number; linkedPeople: number };
|
|
624
|
+
outcome.attendees = set.upserted;
|
|
625
|
+
outcome.linkedPeople += set.linkedPeople;
|
|
626
|
+
}
|
|
627
|
+
} catch (error) {
|
|
628
|
+
outcome.status = "error";
|
|
629
|
+
outcome.error = error instanceof Error ? error.message : String(error);
|
|
630
|
+
}
|
|
631
|
+
}
|
|
632
|
+
|
|
633
|
+
const counts = countResultStatuses(results);
|
|
634
|
+
const errors = outcomes.filter((o) => o.status === "error");
|
|
635
|
+
out(ctx, {
|
|
636
|
+
objectName: "meeting",
|
|
637
|
+
sourceRowsParsed: rows.length,
|
|
638
|
+
imported: counts.created,
|
|
639
|
+
skipped: counts.alreadyExisted,
|
|
640
|
+
updated: counts.updated,
|
|
641
|
+
errors: errors.length,
|
|
642
|
+
onConflict,
|
|
643
|
+
transcriptSegments: outcomes.reduce((n, o) => n + o.transcriptSegments, 0),
|
|
644
|
+
actionItems: outcomes.reduce((n, o) => n + o.actionItems, 0),
|
|
645
|
+
attendees: outcomes.reduce((n, o) => n + o.attendees, 0),
|
|
646
|
+
linkedPeople: outcomes.reduce((n, o) => n + o.linkedPeople, 0),
|
|
647
|
+
rows: outcomes,
|
|
648
|
+
});
|
|
649
|
+
}
|
|
650
|
+
|
|
651
|
+
// ── help ───────────────────────────────────────────────────────────────────
|
|
652
|
+
|
|
653
|
+
function meetingsHelp(): void {
|
|
654
|
+
console.log(`Usage: dench meetings <subcommand>
|
|
655
|
+
|
|
656
|
+
A meeting is an ordinary CRM record on the protected \`meeting\` object —
|
|
657
|
+
create, update and delete it with \`dench crm entries … meeting\`, query it
|
|
658
|
+
with \`dench crm query meeting\`, list its fields with \`dench crm fields list
|
|
659
|
+
meeting\`. These verbs add the parts that live beside the record:
|
|
660
|
+
|
|
661
|
+
dench meetings list [--limit N] [--json]
|
|
662
|
+
dench meetings get <meetingId> [--json]
|
|
663
|
+
|
|
664
|
+
Transcript (meetingTranscriptSegments):
|
|
665
|
+
dench meetings transcript get <meetingId> [--json|--text]
|
|
666
|
+
dench meetings transcript set <meetingId> --text notes.txt | --jsonl segments.jsonl | --file segments.json [--append]
|
|
667
|
+
--text lines look like "[00:01:05] Speaker: what they said"; the
|
|
668
|
+
timestamp and the speaker are both optional. JSON rows carry
|
|
669
|
+
{speaker|speakerName, email?, start|startMs, end|endMs, text}
|
|
670
|
+
(un-suffixed start/end are seconds). Default REPLACES the transcript.
|
|
671
|
+
dench meetings transcript clear <meetingId>
|
|
672
|
+
|
|
673
|
+
Action items (meetingActionItems):
|
|
674
|
+
dench meetings action-items list <meetingId>
|
|
675
|
+
dench meetings action-items add <meetingId> "Send the deck" [--owner Hank] [--done]
|
|
676
|
+
dench meetings action-items set <meetingId> --items '- [x] Send deck (Hank)\\n- Book follow-up' | --file items.md [--append]
|
|
677
|
+
dench meetings action-items done|undone <itemId>
|
|
678
|
+
dench meetings action-items delete <itemId>
|
|
679
|
+
|
|
680
|
+
Attendance (meetingParticipants):
|
|
681
|
+
dench meetings participants list <meetingId>
|
|
682
|
+
dench meetings participants set <meetingId> --people 'Hank <hank@globex.com>; ada@acme.com' [--replace]
|
|
683
|
+
Known members and existing people are linked by exact email and the
|
|
684
|
+
meeting's Participants / Companies relations follow. Nobody is created.
|
|
685
|
+
|
|
686
|
+
Import many calls at once:
|
|
687
|
+
dench meetings import --csv calls.csv [--map '{"Summary":"Overview"}'] [--dedupe-key "Granola ID"] [--on-conflict skip|update|error] [--json]
|
|
688
|
+
dench meetings import --jsonl calls.jsonl …
|
|
689
|
+
Each row is meeting fields (Title, Started At, Ended At, Outcome,
|
|
690
|
+
Overview, Outline, Decisions, Next Actions, Open Questions, Playbook,
|
|
691
|
+
Platform, Meeting URL, …) plus optional reserved columns:
|
|
692
|
+
transcript text, JSON array, or JSONL-in-a-cell
|
|
693
|
+
actionItems lines / markdown checklist / JSON array
|
|
694
|
+
attendees "Name <email>; other@x.com" or JSON array
|
|
695
|
+
Status defaults to Completed. Fields go through the same batch path as
|
|
696
|
+
\`dench crm import\` (same seed keys, same --on-conflict), then each
|
|
697
|
+
created/updated meeting gets its transcript, items and attendees.
|
|
698
|
+
Run it as a signed-in member: meetings are owner-scoped records.
|
|
699
|
+
|
|
700
|
+
Read public/references/CRM-IMPORT.md ("Importing meetings") before a bulk import.`);
|
|
701
|
+
}
|