@meet-ai/cli 0.0.9 → 0.0.10
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/dist/index.js +110 -27
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -19,22 +19,22 @@ async function withRetry(fn, options) {
|
|
|
19
19
|
const maxRetries = options?.maxRetries ?? 3;
|
|
20
20
|
const baseDelay = options?.baseDelay ?? 1000;
|
|
21
21
|
const shouldRetry = options?.shouldRetry ?? isRetryable;
|
|
22
|
-
let lastError;
|
|
22
|
+
let lastError = new Error("withRetry: no attempts made");
|
|
23
23
|
for (let attempt = 0;attempt <= maxRetries; attempt++) {
|
|
24
24
|
try {
|
|
25
25
|
return await fn();
|
|
26
|
-
} catch (
|
|
27
|
-
lastError =
|
|
28
|
-
if (attempt >= maxRetries || !shouldRetry(
|
|
29
|
-
throw
|
|
26
|
+
} catch (error) {
|
|
27
|
+
lastError = error instanceof Error ? error : new Error(String(error));
|
|
28
|
+
if (attempt >= maxRetries || !shouldRetry(error))
|
|
29
|
+
throw lastError;
|
|
30
30
|
const delay = baseDelay * 2 ** attempt;
|
|
31
31
|
console.error(JSON.stringify({
|
|
32
32
|
event: "retry",
|
|
33
33
|
attempt: attempt + 1,
|
|
34
34
|
delay_ms: delay,
|
|
35
|
-
error:
|
|
35
|
+
error: lastError.message
|
|
36
36
|
}));
|
|
37
|
-
await new Promise((
|
|
37
|
+
await new Promise((resolve) => setTimeout(resolve, delay));
|
|
38
38
|
}
|
|
39
39
|
}
|
|
40
40
|
throw lastError;
|
|
@@ -43,7 +43,7 @@ var ATTACHMENTS_DIR = "/tmp/meet-ai-attachments";
|
|
|
43
43
|
var MAX_AGE_MS = 5 * 60 * 1000;
|
|
44
44
|
function cleanupOldAttachments() {
|
|
45
45
|
try {
|
|
46
|
-
const { readdirSync, statSync, unlinkSync } = __require("fs");
|
|
46
|
+
const { readdirSync, statSync, unlinkSync } = __require("node:fs");
|
|
47
47
|
const now = Date.now();
|
|
48
48
|
for (const entry of readdirSync(ATTACHMENTS_DIR)) {
|
|
49
49
|
try {
|
|
@@ -263,7 +263,7 @@ function createClient(baseUrl, apiKey) {
|
|
|
263
263
|
const err = await res.json().catch(() => ({}));
|
|
264
264
|
throw new Error(err.error ?? `HTTP ${res.status}`);
|
|
265
265
|
}
|
|
266
|
-
const { mkdirSync, writeFileSync } = await import("fs");
|
|
266
|
+
const { mkdirSync, writeFileSync } = await import("node:fs");
|
|
267
267
|
const dir = "/tmp/meet-ai-attachments";
|
|
268
268
|
mkdirSync(dir, { recursive: true });
|
|
269
269
|
const localPath = `${dir}/${attachmentId}-${filename}`;
|
|
@@ -281,13 +281,23 @@ function createClient(baseUrl, apiKey) {
|
|
|
281
281
|
throw new Error(err.error ?? `HTTP ${res.status}`);
|
|
282
282
|
}
|
|
283
283
|
return res.json();
|
|
284
|
+
},
|
|
285
|
+
async deleteRoom(roomId) {
|
|
286
|
+
const res = await fetch(`${baseUrl}/api/rooms/${roomId}`, {
|
|
287
|
+
method: "DELETE",
|
|
288
|
+
headers: headers()
|
|
289
|
+
});
|
|
290
|
+
if (!res.ok) {
|
|
291
|
+
const err = await res.json().catch(() => ({}));
|
|
292
|
+
throw new Error(err.error ?? `HTTP ${res.status}`);
|
|
293
|
+
}
|
|
284
294
|
}
|
|
285
295
|
};
|
|
286
296
|
}
|
|
287
297
|
|
|
288
298
|
// src/inbox-router.ts
|
|
289
|
-
import { readFileSync, writeFileSync, mkdirSync, statSync } from "fs";
|
|
290
|
-
import { dirname } from "path";
|
|
299
|
+
import { readFileSync, writeFileSync, mkdirSync, statSync } from "node:fs";
|
|
300
|
+
import { dirname } from "node:path";
|
|
291
301
|
var IDLE_CHECK_INTERVAL_MS = 60000;
|
|
292
302
|
var IDLE_THRESHOLD_MS = 5 * 60 * 1000;
|
|
293
303
|
function appendToInbox(path, entry) {
|
|
@@ -353,8 +363,8 @@ async function downloadMessageAttachments(roomId, messageId) {
|
|
|
353
363
|
try {
|
|
354
364
|
const localPath = await client.downloadAttachment(att.id, att.filename);
|
|
355
365
|
paths.push(localPath);
|
|
356
|
-
} catch (
|
|
357
|
-
console.error(JSON.stringify({ event: "attachment_download_error", attachmentId: att.id, error:
|
|
366
|
+
} catch (error) {
|
|
367
|
+
console.error(JSON.stringify({ event: "attachment_download_error", attachmentId: att.id, error: error instanceof Error ? error.message : String(error) }));
|
|
358
368
|
}
|
|
359
369
|
}
|
|
360
370
|
return paths;
|
|
@@ -375,24 +385,65 @@ function parseFlags(args2) {
|
|
|
375
385
|
}
|
|
376
386
|
return { positional, flags };
|
|
377
387
|
}
|
|
388
|
+
function rejectFlagLikeArgs(positional, usage) {
|
|
389
|
+
for (const arg of positional) {
|
|
390
|
+
if (arg.startsWith("--")) {
|
|
391
|
+
console.error(`Unknown flag: ${arg}`);
|
|
392
|
+
console.error(`Usage: ${usage}`);
|
|
393
|
+
process.exit(1);
|
|
394
|
+
}
|
|
395
|
+
}
|
|
396
|
+
}
|
|
378
397
|
switch (command) {
|
|
379
398
|
case "create-room": {
|
|
380
|
-
|
|
399
|
+
if (args.includes("--help")) {
|
|
400
|
+
console.log("Usage: meet-ai create-room <room-name>");
|
|
401
|
+
process.exit(0);
|
|
402
|
+
}
|
|
403
|
+
const { positional, flags } = parseFlags(args);
|
|
404
|
+
const unknownFlags = Object.keys(flags);
|
|
405
|
+
if (unknownFlags.length > 0) {
|
|
406
|
+
console.error(`Unknown flag: --${unknownFlags[0]}`);
|
|
407
|
+
console.error("Usage: meet-ai create-room <room-name>");
|
|
408
|
+
process.exit(1);
|
|
409
|
+
}
|
|
410
|
+
rejectFlagLikeArgs(positional, "meet-ai create-room <room-name>");
|
|
411
|
+
const name = positional[0];
|
|
381
412
|
if (!name) {
|
|
382
|
-
console.error("Usage:
|
|
413
|
+
console.error("Usage: meet-ai create-room <room-name>");
|
|
383
414
|
process.exit(1);
|
|
384
415
|
}
|
|
385
416
|
const room = await client.createRoom(name);
|
|
386
417
|
console.log(`Room created: ${room.id} (${room.name})`);
|
|
387
418
|
break;
|
|
388
419
|
}
|
|
420
|
+
case "delete-room": {
|
|
421
|
+
if (args.includes("--help")) {
|
|
422
|
+
console.log("Usage: meet-ai delete-room <roomId>");
|
|
423
|
+
process.exit(0);
|
|
424
|
+
}
|
|
425
|
+
rejectFlagLikeArgs(args, "meet-ai delete-room <roomId>");
|
|
426
|
+
const roomId = args[0];
|
|
427
|
+
if (!roomId) {
|
|
428
|
+
console.error("Usage: meet-ai delete-room <roomId>");
|
|
429
|
+
process.exit(1);
|
|
430
|
+
}
|
|
431
|
+
await client.deleteRoom(roomId);
|
|
432
|
+
console.log(`Room deleted: ${roomId}`);
|
|
433
|
+
break;
|
|
434
|
+
}
|
|
389
435
|
case "send-message": {
|
|
436
|
+
if (args.includes("--help")) {
|
|
437
|
+
console.log("Usage: meet-ai send-message <roomId> <sender> <content> [--color <color>]");
|
|
438
|
+
process.exit(0);
|
|
439
|
+
}
|
|
390
440
|
const { positional: smPos, flags: smFlags } = parseFlags(args);
|
|
441
|
+
rejectFlagLikeArgs(smPos, "meet-ai send-message <roomId> <sender> <content> [--color <color>]");
|
|
391
442
|
const [roomId, sender, ...rest] = smPos;
|
|
392
443
|
const content = rest.join(" ").replace(/\\n/g, `
|
|
393
444
|
`);
|
|
394
445
|
if (!roomId || !sender || !content) {
|
|
395
|
-
console.error("Usage:
|
|
446
|
+
console.error("Usage: meet-ai send-message <roomId> <sender> <content> [--color <color>]");
|
|
396
447
|
process.exit(1);
|
|
397
448
|
}
|
|
398
449
|
const msg = await client.sendMessage(roomId, sender, content, smFlags.color);
|
|
@@ -400,10 +451,15 @@ switch (command) {
|
|
|
400
451
|
break;
|
|
401
452
|
}
|
|
402
453
|
case "poll": {
|
|
454
|
+
if (args.includes("--help")) {
|
|
455
|
+
console.log("Usage: meet-ai poll <roomId> [--after <messageId>] [--exclude <sender>] [--sender-type <type>]");
|
|
456
|
+
process.exit(0);
|
|
457
|
+
}
|
|
403
458
|
const { positional, flags } = parseFlags(args);
|
|
459
|
+
rejectFlagLikeArgs(positional, "meet-ai poll <roomId> [--after <messageId>] [--exclude <sender>] [--sender-type <type>]");
|
|
404
460
|
const roomId = positional[0];
|
|
405
461
|
if (!roomId) {
|
|
406
|
-
console.error("Usage:
|
|
462
|
+
console.error("Usage: meet-ai poll <roomId> [--after <messageId>] [--exclude <sender>] [--sender-type <type>]");
|
|
407
463
|
process.exit(1);
|
|
408
464
|
}
|
|
409
465
|
const messages = await client.getMessages(roomId, {
|
|
@@ -423,7 +479,7 @@ switch (command) {
|
|
|
423
479
|
if (!inboxDir)
|
|
424
480
|
return;
|
|
425
481
|
const entry = {
|
|
426
|
-
from:
|
|
482
|
+
from: `meet-ai:${msg.sender}`,
|
|
427
483
|
text: msg.content,
|
|
428
484
|
timestamp: new Date().toISOString(),
|
|
429
485
|
read: false
|
|
@@ -448,10 +504,15 @@ switch (command) {
|
|
|
448
504
|
}
|
|
449
505
|
process.exit(0);
|
|
450
506
|
};
|
|
507
|
+
if (args.includes("--help")) {
|
|
508
|
+
console.log("Usage: meet-ai listen <roomId> [--exclude <sender>] [--sender-type <type>] [--team <name> --inbox <agent>]");
|
|
509
|
+
process.exit(0);
|
|
510
|
+
}
|
|
451
511
|
const { positional, flags } = parseFlags(args);
|
|
512
|
+
rejectFlagLikeArgs(positional, "meet-ai listen <roomId> [--exclude <sender>] [--sender-type <type>] [--team <name> --inbox <agent>]");
|
|
452
513
|
const roomId = positional[0];
|
|
453
514
|
if (!roomId) {
|
|
454
|
-
console.error("Usage:
|
|
515
|
+
console.error("Usage: meet-ai listen <roomId> [--exclude <sender>] [--sender-type <type>] [--team <name> --inbox <agent>]");
|
|
455
516
|
process.exit(1);
|
|
456
517
|
}
|
|
457
518
|
const team = flags.team;
|
|
@@ -502,12 +563,17 @@ switch (command) {
|
|
|
502
563
|
break;
|
|
503
564
|
}
|
|
504
565
|
case "send-log": {
|
|
566
|
+
if (args.includes("--help")) {
|
|
567
|
+
console.log("Usage: meet-ai send-log <roomId> <sender> <content> [--color <color>] [--message-id <id>]");
|
|
568
|
+
process.exit(0);
|
|
569
|
+
}
|
|
505
570
|
const { positional: slPos, flags: slFlags } = parseFlags(args);
|
|
571
|
+
rejectFlagLikeArgs(slPos, "meet-ai send-log <roomId> <sender> <content> [--color <color>] [--message-id <id>]");
|
|
506
572
|
const [slRoomId, slSender, ...slRest] = slPos;
|
|
507
573
|
const slContent = slRest.join(" ").replace(/\\n/g, `
|
|
508
574
|
`);
|
|
509
575
|
if (!slRoomId || !slSender || !slContent) {
|
|
510
|
-
console.error("Usage:
|
|
576
|
+
console.error("Usage: meet-ai send-log <roomId> <sender> <content> [--color <color>] [--message-id <id>]");
|
|
511
577
|
process.exit(1);
|
|
512
578
|
}
|
|
513
579
|
const log = await client.sendLog(slRoomId, slSender, slContent, slFlags.color, slFlags["message-id"]);
|
|
@@ -515,9 +581,14 @@ switch (command) {
|
|
|
515
581
|
break;
|
|
516
582
|
}
|
|
517
583
|
case "send-team-info": {
|
|
584
|
+
if (args.includes("--help")) {
|
|
585
|
+
console.log("Usage: meet-ai send-team-info <roomId> '<json-payload>'");
|
|
586
|
+
process.exit(0);
|
|
587
|
+
}
|
|
588
|
+
rejectFlagLikeArgs(args, "meet-ai send-team-info <roomId> '<json-payload>'");
|
|
518
589
|
const [tiRoomId, tiPayload] = args;
|
|
519
590
|
if (!tiRoomId || !tiPayload) {
|
|
520
|
-
console.error("Usage:
|
|
591
|
+
console.error("Usage: meet-ai send-team-info <roomId> '<json-payload>'");
|
|
521
592
|
process.exit(1);
|
|
522
593
|
}
|
|
523
594
|
try {
|
|
@@ -531,9 +602,14 @@ switch (command) {
|
|
|
531
602
|
break;
|
|
532
603
|
}
|
|
533
604
|
case "send-tasks": {
|
|
605
|
+
if (args.includes("--help")) {
|
|
606
|
+
console.log("Usage: meet-ai send-tasks <roomId> '<json-payload>'");
|
|
607
|
+
process.exit(0);
|
|
608
|
+
}
|
|
609
|
+
rejectFlagLikeArgs(args, "meet-ai send-tasks <roomId> '<json-payload>'");
|
|
534
610
|
const [stRoomId, stPayload] = args;
|
|
535
611
|
if (!stRoomId || !stPayload) {
|
|
536
|
-
console.error("Usage:
|
|
612
|
+
console.error("Usage: meet-ai send-tasks <roomId> '<json-payload>'");
|
|
537
613
|
process.exit(1);
|
|
538
614
|
}
|
|
539
615
|
try {
|
|
@@ -547,9 +623,14 @@ switch (command) {
|
|
|
547
623
|
break;
|
|
548
624
|
}
|
|
549
625
|
case "download-attachment": {
|
|
626
|
+
if (args.includes("--help")) {
|
|
627
|
+
console.log("Usage: meet-ai download-attachment <attachmentId>");
|
|
628
|
+
process.exit(0);
|
|
629
|
+
}
|
|
630
|
+
rejectFlagLikeArgs(args, "meet-ai download-attachment <attachmentId>");
|
|
550
631
|
const attachmentId = args[0];
|
|
551
632
|
if (!attachmentId) {
|
|
552
|
-
console.error("Usage:
|
|
633
|
+
console.error("Usage: meet-ai download-attachment <attachmentId>");
|
|
553
634
|
process.exit(1);
|
|
554
635
|
}
|
|
555
636
|
try {
|
|
@@ -565,15 +646,15 @@ switch (command) {
|
|
|
565
646
|
const disposition = res.headers.get("Content-Disposition") || "";
|
|
566
647
|
const filenameMatch = disposition.match(/filename="(.+?)"/);
|
|
567
648
|
const filename = filenameMatch?.[1] || attachmentId;
|
|
568
|
-
const { mkdirSync: mkdirSync2, writeFileSync: writeFileSync2 } = await import("fs");
|
|
649
|
+
const { mkdirSync: mkdirSync2, writeFileSync: writeFileSync2 } = await import("node:fs");
|
|
569
650
|
const dir = "/tmp/meet-ai-attachments";
|
|
570
651
|
mkdirSync2(dir, { recursive: true });
|
|
571
652
|
const localPath = `${dir}/${attachmentId}-${filename}`;
|
|
572
653
|
const buffer = Buffer.from(await res.arrayBuffer());
|
|
573
654
|
writeFileSync2(localPath, buffer);
|
|
574
655
|
console.log(localPath);
|
|
575
|
-
} catch (
|
|
576
|
-
console.error(
|
|
656
|
+
} catch (error) {
|
|
657
|
+
console.error(error instanceof Error ? error.message : String(error));
|
|
577
658
|
process.exit(1);
|
|
578
659
|
}
|
|
579
660
|
break;
|
|
@@ -584,7 +665,7 @@ switch (command) {
|
|
|
584
665
|
console.log(`Prefix: ${result.prefix}`);
|
|
585
666
|
break;
|
|
586
667
|
}
|
|
587
|
-
default:
|
|
668
|
+
default: {
|
|
588
669
|
console.log(`meet-ai CLI
|
|
589
670
|
|
|
590
671
|
Environment variables:
|
|
@@ -593,6 +674,7 @@ Environment variables:
|
|
|
593
674
|
|
|
594
675
|
Commands:
|
|
595
676
|
create-room <name> Create a new chat room
|
|
677
|
+
delete-room <roomId> Delete a room and all its messages
|
|
596
678
|
send-message <roomId> <sender> <content> Send a message to a room
|
|
597
679
|
--color <color> Set sender name color (e.g. #ff0000, red)
|
|
598
680
|
send-log <roomId> <sender> <content> Send a log entry to a room
|
|
@@ -611,4 +693,5 @@ Commands:
|
|
|
611
693
|
send-team-info <roomId> '<json>' Send team info to a room
|
|
612
694
|
send-tasks <roomId> '<json>' Send tasks info to a room
|
|
613
695
|
generate-key Generate a new API key`);
|
|
696
|
+
}
|
|
614
697
|
}
|