@dench.com/cli 3.12.15-staging.1289 → 3.12.16-staging.1305

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/meetings.ts CHANGED
@@ -11,7 +11,12 @@
11
11
  * uses, so the CLI, `/api/v1/meetings/…` and the UI share one contract.
12
12
  */
13
13
 
14
- import { readFile } from "node:fs/promises";
14
+ import { createWriteStream } from "node:fs";
15
+ import { mkdir, readFile, stat, unlink, writeFile } from "node:fs/promises";
16
+ import { dirname, join } from "node:path";
17
+ import { Readable } from "node:stream";
18
+ import { pipeline } from "node:stream/promises";
19
+ import type { ReadableStream as WebReadableStream } from "node:stream/web";
15
20
  import { makeFunctionReference } from "convex/server";
16
21
  import {
17
22
  applyBatchOpsInChunks,
@@ -29,6 +34,7 @@ import {
29
34
  remapKeys,
30
35
  shift,
31
36
  } from "./crm";
37
+ import { PRODUCTION_API_URL } from "./host";
32
38
  import { getFlag, hasFlag, parseJson } from "./lib/cli-args";
33
39
  import {
34
40
  applyMeetingFieldDefaults,
@@ -108,6 +114,7 @@ export async function runMeetingsCommand(opts: {
108
114
  sessionToken?: string;
109
115
  host?: string;
110
116
  workspaceSlug?: string;
117
+ fetchImpl?: typeof fetch;
111
118
  }): Promise<void> {
112
119
  const args = [...opts.args];
113
120
  const jsonOutput = hasFlag(args, "--json");
@@ -130,6 +137,8 @@ export async function runMeetingsCommand(opts: {
130
137
  return await runList(ctx);
131
138
  case "get":
132
139
  return await runGet(ctx);
140
+ case "recording":
141
+ return await runRecording(ctx, opts.fetchImpl ?? fetch);
133
142
  case "transcript":
134
143
  return await runTranscript(ctx);
135
144
  case "action-items":
@@ -225,6 +234,184 @@ async function runGet(ctx: CrmCliContext): Promise<void> {
225
234
  out(ctx, entry);
226
235
  }
227
236
 
237
+ // ── recording ──────────────────────────────────────────────────────────────
238
+
239
+ type MeetingRecordingPayload = {
240
+ videoUrl: string | null;
241
+ audioUrl: string | null;
242
+ hasRecorder: boolean;
243
+ code: string;
244
+ };
245
+
246
+ /** Drops trailing "/" with a loop to avoid polynomial regex backtracking. */
247
+ function trimTrailingSlashes(value: string): string {
248
+ let end = value.length;
249
+ while (end > 0 && value.charCodeAt(end - 1) === 47) end -= 1;
250
+ return value.slice(0, end);
251
+ }
252
+
253
+ function formatByteSize(bytes: number): string {
254
+ if (bytes < 1024) return `${bytes} B`;
255
+ if (bytes < 1024 * 1024) return `${(bytes / 1024).toFixed(1)} KB`;
256
+ if (bytes < 1024 * 1024 * 1024) {
257
+ return `${(bytes / (1024 * 1024)).toFixed(1)} MB`;
258
+ }
259
+ return `${(bytes / (1024 * 1024 * 1024)).toFixed(2)} GB`;
260
+ }
261
+
262
+ async function resolveDownloadPath(
263
+ dest: string,
264
+ meetingEntryId: string,
265
+ ext: string,
266
+ ): Promise<string> {
267
+ try {
268
+ const info = await stat(dest);
269
+ if (info.isDirectory()) {
270
+ return join(dest, `${meetingEntryId}.${ext}`);
271
+ }
272
+ } catch {
273
+ // Destination does not exist yet; treat as a file path.
274
+ }
275
+ return dest;
276
+ }
277
+
278
+ async function downloadStreamToFile(
279
+ response: Response,
280
+ destPath: string,
281
+ ): Promise<number> {
282
+ await mkdir(dirname(destPath), { recursive: true });
283
+ try {
284
+ if (response.body) {
285
+ await pipeline(
286
+ Readable.fromWeb(response.body as unknown as WebReadableStream),
287
+ createWriteStream(destPath),
288
+ );
289
+ } else {
290
+ const bytes = Buffer.from(await response.arrayBuffer());
291
+ await writeFile(destPath, bytes);
292
+ }
293
+ return (await stat(destPath)).size;
294
+ } catch (error) {
295
+ await unlink(destPath).catch(() => undefined);
296
+ throw error;
297
+ }
298
+ }
299
+
300
+ /**
301
+ * `dench meetings recording <meetingId> [--download <path>] [--audio] [--json]`
302
+ *
303
+ * Calls `/api/v1/meetings/{meetingId}/recording` to mint short-lived signed
304
+ * playback/download URLs for the meeting's video (MP4) and audio.
305
+ */
306
+ async function runRecording(
307
+ ctx: CrmCliContext,
308
+ fetchImpl: typeof fetch,
309
+ ): Promise<void> {
310
+ const meetingEntryId = shift(ctx.args, "meeting id");
311
+ const downloadDest = getFlag(ctx.args, "--download");
312
+ const audioOnly = hasFlag(ctx.args, "--audio");
313
+ assertNoUnknownFlags(ctx.args, "meetings recording");
314
+
315
+ const bearer = ctx.sessionToken?.trim();
316
+ if (!bearer) {
317
+ throw new CrmCliError("Not signed in. Run `dench signin` first.");
318
+ }
319
+ const baseUrl = trimTrailingSlashes(ctx.host?.trim() || PRODUCTION_API_URL);
320
+ const response = await fetchImpl(
321
+ `${baseUrl}/api/v1/meetings/${encodeURIComponent(meetingEntryId)}/recording`,
322
+ {
323
+ method: "GET",
324
+ headers: {
325
+ accept: "application/json",
326
+ authorization: `Bearer ${bearer}`,
327
+ },
328
+ },
329
+ );
330
+ const payload = (await response.json().catch(() => null)) as Record<
331
+ string,
332
+ unknown
333
+ > | null;
334
+ if (!response.ok) {
335
+ const errObj =
336
+ payload && typeof payload.error === "object" && payload.error !== null
337
+ ? (payload.error as Record<string, unknown>)
338
+ : null;
339
+ const message =
340
+ (typeof errObj?.message === "string" && errObj.message) ||
341
+ (typeof payload?.message === "string" && payload.message) ||
342
+ (typeof payload?.error === "string" && payload.error) ||
343
+ `Meeting recording lookup failed with HTTP ${response.status}`;
344
+ throw new CrmCliError(message);
345
+ }
346
+
347
+ const recording: MeetingRecordingPayload = {
348
+ videoUrl: typeof payload?.videoUrl === "string" ? payload.videoUrl : null,
349
+ audioUrl: typeof payload?.audioUrl === "string" ? payload.audioUrl : null,
350
+ hasRecorder: Boolean(payload?.hasRecorder),
351
+ code: typeof payload?.code === "string" ? payload.code : "no_recording",
352
+ };
353
+
354
+ if (downloadDest !== undefined) {
355
+ if (!downloadDest.trim()) {
356
+ throw new CrmCliError("--download requires a file or directory path.");
357
+ }
358
+ const kind = audioOnly ? "audio" : "video";
359
+ const mediaUrl = audioOnly ? recording.audioUrl : recording.videoUrl;
360
+ if (!mediaUrl) {
361
+ if (!audioOnly && recording.audioUrl) {
362
+ throw new CrmCliError(
363
+ `No video recording available for meeting ${meetingEntryId} (${recording.code}). Audio is available — rerun with --audio to download it.`,
364
+ );
365
+ }
366
+ throw new CrmCliError(
367
+ `No ${kind} recording available for meeting ${meetingEntryId} (${recording.code}).`,
368
+ );
369
+ }
370
+ const destPath = await resolveDownloadPath(
371
+ downloadDest,
372
+ meetingEntryId,
373
+ audioOnly ? "mp3" : "mp4",
374
+ );
375
+ const mediaResponse = await fetchImpl(mediaUrl);
376
+ if (!mediaResponse.ok) {
377
+ throw new CrmCliError(
378
+ `Failed to download meeting ${kind} (HTTP ${mediaResponse.status}).`,
379
+ );
380
+ }
381
+ const bytes = await downloadStreamToFile(mediaResponse, destPath);
382
+ if (ctx.jsonOutput) {
383
+ out(ctx, {
384
+ ...recording,
385
+ downloaded: { kind, path: destPath, bytes },
386
+ });
387
+ return;
388
+ }
389
+ console.log(`Downloaded ${kind} -> ${destPath} (${formatByteSize(bytes)})`);
390
+ return;
391
+ }
392
+
393
+ if (ctx.jsonOutput) {
394
+ out(ctx, recording);
395
+ return;
396
+ }
397
+ if (audioOnly) {
398
+ if (recording.audioUrl) {
399
+ console.log(`audio: ${recording.audioUrl}`);
400
+ } else {
401
+ console.log(`(no audio recording available: ${recording.code})`);
402
+ }
403
+ return;
404
+ }
405
+ if (recording.videoUrl) {
406
+ console.log(`video: ${recording.videoUrl}`);
407
+ } else {
408
+ console.log(`video: unavailable (${recording.code})`);
409
+ }
410
+ if (recording.audioUrl) {
411
+ console.log(`audio: ${recording.audioUrl}`);
412
+ }
413
+ }
414
+
228
415
  // ── share ──────────────────────────────────────────────────────────────────
229
416
 
230
417
  /**
@@ -785,6 +972,9 @@ meeting\`. These verbs add the parts that live beside the record:
785
972
  dench meetings list [--limit N | --all] [--shared] [--json]
786
973
  Newest first; --limit defaults to 50, --all lists every meeting.
787
974
  dench meetings get <meetingId> [--json]
975
+ dench meetings recording <meetingId> [--download <path>] [--audio] [--json]
976
+ Mint short-lived signed video (MP4) and audio URLs; pass --download
977
+ <file-or-dir> to save the recording locally (--audio for audio only).
788
978
 
789
979
  You see a meeting if you own it, if you were on the invite, or if it has
790
980
  been shared with the workspace. \`--shared\` narrows the list to the last of
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dench.com/cli",
3
- "version": "3.12.15-staging.1289",
3
+ "version": "3.12.16-staging.1305",
4
4
  "description": "Dench agent workspace CLI.",
5
5
  "type": "module",
6
6
  "bin": {