@pmate/cli 0.27.0 → 0.28.1

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.d.ts CHANGED
@@ -438,6 +438,14 @@ type AccountCommandArgs = {
438
438
  app: string;
439
439
  baseUrl?: string;
440
440
  json: boolean;
441
+ } | {
442
+ type: Command.Account;
443
+ action: "bot-rename";
444
+ app: string;
445
+ name: string;
446
+ newName: string;
447
+ baseUrl?: string;
448
+ json: boolean;
441
449
  } | {
442
450
  type: Command.Account;
443
451
  action: "bot-login";
@@ -614,6 +622,15 @@ type CollectCommandArgs = {
614
622
  action: "reply";
615
623
  thread: string;
616
624
  text: string;
625
+ file?: string;
626
+ dryRun: boolean;
627
+ } | {
628
+ type: Command.Collect;
629
+ action: "react";
630
+ thread: string;
631
+ emoji: string;
632
+ message?: string;
633
+ remove: boolean;
617
634
  dryRun: boolean;
618
635
  };
619
636
  type ChatRoomCommonArgs = {
package/dist/index.js CHANGED
@@ -16866,10 +16866,18 @@ var Im1BotClient = class {
16866
16866
  body: JSON.stringify({
16867
16867
  thread: input.thread,
16868
16868
  text: input.text,
16869
- dryRun: input.dryRun ?? false
16869
+ dryRun: input.dryRun ?? false,
16870
+ attachment: input.attachment
16870
16871
  })
16871
16872
  });
16872
16873
  }
16874
+ async reactToMessage(input) {
16875
+ return this.request("/messages/react", {
16876
+ method: "POST",
16877
+ headers: { "content-type": "application/json" },
16878
+ body: JSON.stringify(input)
16879
+ });
16880
+ }
16873
16881
  async resolveThread(thread) {
16874
16882
  const exact = await this.request(
16875
16883
  `/threads/${encodeURIComponent(thread)}`
@@ -17050,6 +17058,29 @@ function normalizeStoredMessage(message) {
17050
17058
  }
17051
17059
 
17052
17060
  // src/commands/CollectCommandHandler.ts
17061
+ async function readOutgoingAttachment(filePath) {
17062
+ const resolved = import_node_path19.default.resolve(filePath);
17063
+ const data = await import_node_fs13.promises.readFile(resolved);
17064
+ const extension = import_node_path19.default.extname(resolved).toLowerCase();
17065
+ const contentTypes = {
17066
+ ".png": "image/png",
17067
+ ".jpg": "image/jpeg",
17068
+ ".jpeg": "image/jpeg",
17069
+ ".gif": "image/gif",
17070
+ ".webp": "image/webp",
17071
+ ".pdf": "application/pdf",
17072
+ ".txt": "text/plain",
17073
+ ".mp4": "video/mp4",
17074
+ ".mp3": "audio/mpeg",
17075
+ ".wav": "audio/wav"
17076
+ };
17077
+ return {
17078
+ base64: data.toString("base64"),
17079
+ fileName: import_node_path19.default.basename(resolved),
17080
+ contentType: contentTypes[extension] ?? "application/octet-stream",
17081
+ size: data.byteLength
17082
+ };
17083
+ }
17053
17084
  var CollectCommandHandler = class {
17054
17085
  async handle(args) {
17055
17086
  if (args.action === "health") {
@@ -17068,6 +17099,10 @@ var CollectCommandHandler = class {
17068
17099
  await this.handleBotReply(args);
17069
17100
  return;
17070
17101
  }
17102
+ if (args.action === "react") {
17103
+ await this.handleBotReact(args);
17104
+ return;
17105
+ }
17071
17106
  if (args.source === "cc" && !args.endpoint) {
17072
17107
  throw new Error(
17073
17108
  'CC sync has moved to cc-bot. Start ~/dev/pcs/cc-bot and use "pmate im1 threads", "pmate im1 messages", or "pmate im1 reply".'
@@ -17105,13 +17140,20 @@ var CollectCommandHandler = class {
17105
17140
  }
17106
17141
  async handleBotReply(args) {
17107
17142
  const client = new Im1BotClient();
17143
+ const attachment = args.file ? await readOutgoingAttachment(args.file) : void 0;
17108
17144
  const result = await client.sendMessage({
17109
17145
  thread: args.thread,
17110
17146
  text: args.text,
17111
- dryRun: args.dryRun
17147
+ dryRun: args.dryRun,
17148
+ attachment
17112
17149
  });
17113
17150
  ui.plain(JSON.stringify(result, null, 2));
17114
17151
  }
17152
+ async handleBotReact(args) {
17153
+ const client = new Im1BotClient();
17154
+ const result = await client.reactToMessage(args);
17155
+ ui.plain(JSON.stringify(result, null, 2));
17156
+ }
17115
17157
  async handleSync(args) {
17116
17158
  let browser = null;
17117
17159
  try {
@@ -27374,6 +27416,9 @@ function parseIm1Args(tokens) {
27374
27416
  if (action === "reply") {
27375
27417
  return parseIm1ReplyArgs(rest);
27376
27418
  }
27419
+ if (action === "react") {
27420
+ return parseIm1ReactArgs(rest);
27421
+ }
27377
27422
  throw new Error(`Unknown im1 action: ${action}`);
27378
27423
  }
27379
27424
  function parseIm1HealthArgs(tokens) {
@@ -27456,6 +27501,7 @@ function parseIm1ReplyArgs(tokens) {
27456
27501
  const rest = [...tokens];
27457
27502
  let thread;
27458
27503
  let text;
27504
+ let file;
27459
27505
  let dryRun = false;
27460
27506
  while (rest.length > 0) {
27461
27507
  const token = rest.shift();
@@ -27466,6 +27512,10 @@ function parseIm1ReplyArgs(tokens) {
27466
27512
  case "--text":
27467
27513
  text = requireValue11(rest, token);
27468
27514
  break;
27515
+ case "--file":
27516
+ case "--image":
27517
+ file = requireValue11(rest, token);
27518
+ break;
27469
27519
  case "--dryrun":
27470
27520
  case "--dry-run":
27471
27521
  dryRun = true;
@@ -27474,17 +27524,53 @@ function parseIm1ReplyArgs(tokens) {
27474
27524
  throw new Error(`Unknown im1 reply option: ${token}`);
27475
27525
  }
27476
27526
  }
27477
- if (!thread || !text) {
27478
- throw new Error("Usage: im1 reply --thread <name|conversation-id> --text <text>");
27527
+ if (!thread || !text && !file) {
27528
+ throw new Error("Usage: im1 reply --thread <name|conversation-id> [--text <text>] [--file <path>]");
27479
27529
  }
27480
27530
  return {
27481
27531
  type: "collect" /* Collect */,
27482
27532
  action: "reply",
27483
27533
  thread,
27484
- text,
27534
+ text: text ?? "",
27535
+ file,
27485
27536
  dryRun
27486
27537
  };
27487
27538
  }
27539
+ function parseIm1ReactArgs(tokens) {
27540
+ const rest = [...tokens];
27541
+ let thread;
27542
+ let emoji;
27543
+ let message;
27544
+ let remove = false;
27545
+ let dryRun = false;
27546
+ while (rest.length > 0) {
27547
+ const token = rest.shift();
27548
+ switch (token) {
27549
+ case "--thread":
27550
+ thread = requireValue11(rest, token);
27551
+ break;
27552
+ case "--emoji":
27553
+ emoji = requireValue11(rest, token);
27554
+ break;
27555
+ case "--message":
27556
+ message = requireValue11(rest, token);
27557
+ break;
27558
+ case "--remove":
27559
+ remove = true;
27560
+ break;
27561
+ case "--dryrun":
27562
+ case "--dry-run":
27563
+ dryRun = true;
27564
+ break;
27565
+ default:
27566
+ throw new Error(`Unknown im1 react option: ${token}`);
27567
+ }
27568
+ }
27569
+ if (!thread || !emoji) {
27570
+ throw new Error("Usage: im1 react --thread <name|conversation-id> --emoji <emoji> [--message <id-or-timestamp>] [--remove]");
27571
+ }
27572
+ return { type: "collect" /* Collect */, action: "react", thread, emoji, message, remove, dryRun };
27573
+ }
27488
27574
  function requireValue11(tokens, optionName) {
27489
27575
  const value = tokens.shift();
27490
27576
  if (!value || value.startsWith("--")) {
@@ -27720,11 +27806,12 @@ var HELP_TEXT = [
27720
27806
  ` ${import_chalk4.default.gray(" [--length <n>] [--charset base64url|hex|alnum|ascii]")}`,
27721
27807
  ` ${import_chalk4.default.gray(" [--count <n>]")}`,
27722
27808
  ` ${import_chalk4.default.gray(" --easy [--words <n>] [--digits <n>] [--separator <s>] [--count <n>]")}`,
27723
- ` ${import_chalk4.default.cyan("im1")} Read and reply to local CC messages through cc-bot`,
27809
+ ` ${import_chalk4.default.cyan("im1")} Read, reply, attach files, and react through local cc-bot`,
27724
27810
  ` ${import_chalk4.default.gray(" health [--json]")}`,
27725
27811
  ` ${import_chalk4.default.gray(" threads [--q <keyword>] [--search <title>] [--limit <n>] [--json|--text]")}`,
27726
27812
  ` ${import_chalk4.default.gray(" messages --thread <name|conversation-id> [--limit <n>] [--json|--text]")}`,
27727
- ` ${import_chalk4.default.gray(" reply --thread <name|conversation-id> --text <text> [--dryrun]")}`,
27813
+ ` ${import_chalk4.default.gray(" reply --thread <name|conversation-id> [--text <text>] [--file|--image <path>] [--dryrun]")}`,
27814
+ ` ${import_chalk4.default.gray(" react --thread <name|conversation-id> --emoji <emoji> [--message <id|timestamp>] [--remove] [--dryrun]")}`,
27728
27815
  ` ${import_chalk4.default.cyan("collect")} Legacy alias for CC/yelling collection`,
27729
27816
  ` ${import_chalk4.default.gray(" sync [--thread <name|conversation-id>] (--source <cc|yelling> | --endpoint <url>)")}`,
27730
27817
  ` ${import_chalk4.default.cyan("chat-room")} Run social chat regression commands with PMate bot key JSON`,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@pmate/cli",
3
- "version": "0.27.0",
3
+ "version": "0.28.1",
4
4
  "description": "CLI utilities for the pMate project",
5
5
  "license": "MIT",
6
6
  "bin": {