@agent-wechat/cli 0.14.0 → 0.15.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.
Files changed (2) hide show
  1. package/dist/cli.js +58 -4
  2. package/package.json +2 -2
package/dist/cli.js CHANGED
@@ -3582,6 +3582,23 @@ var WeChatClient = class {
3582
3582
  async sendMessage(params) {
3583
3583
  return this.post("/api/messages/send", params);
3584
3584
  }
3585
+ async createVoiceJob(chatId, audio, idempotencyKey) {
3586
+ const form = new FormData();
3587
+ form.set("chatId", chatId);
3588
+ form.set("audio", new Blob([new Uint8Array(audio)]), "voice-audio");
3589
+ const headers = { ...this.headers, "Idempotency-Key": idempotencyKey };
3590
+ delete headers["Content-Type"];
3591
+ const res = await fetch(`${this.base}/api/messages/voice`, { method: "POST", headers, body: form });
3592
+ if (!res.ok)
3593
+ throw new Error(`${res.status} ${res.statusText}: ${await res.text()}`);
3594
+ return res.json();
3595
+ }
3596
+ async getVoiceJob(jobId) {
3597
+ return this.get(`/api/messages/voice/${encodeURIComponent(jobId)}`);
3598
+ }
3599
+ async cancelVoiceJob(jobId) {
3600
+ return this.post(`/api/messages/voice/${encodeURIComponent(jobId)}/cancel`);
3601
+ }
3585
3602
  // ---- Debug ----
3586
3603
  async screenshot() {
3587
3604
  return this.get("/api/debug/screenshot");
@@ -7912,7 +7929,7 @@ import qrTerminal from "qrcode-terminal";
7912
7929
  import os from "os";
7913
7930
  import path from "path";
7914
7931
  import { fileURLToPath } from "url";
7915
- var VERSION = "0.14.0";
7932
+ var VERSION = "0.15.0";
7916
7933
  var CONTAINER_NAME = "agent-wechat";
7917
7934
  var GHCR_IMAGE = "ghcr.io/thisnick/agent-wechat";
7918
7935
  var DEFAULT_PORT = 6174;
@@ -8061,11 +8078,20 @@ messagesCmd.command("list <chatId>").description("List messages for a chat").opt
8061
8078
  messagesCmd.command("media <chatId> <localId>").description("Save a media attachment (full-resolution image, file, or voice)").option("--thumbnail", "Retrieve an image thumbnail instead of full resolution").option("-o, --output <path>", "Output file path").action(async (chatId, localIdStr, opts) => {
8062
8079
  await cmdMedia(getClient(), chatId, parseInt(localIdStr, 10), opts.output, opts.thumbnail);
8063
8080
  });
8064
- messagesCmd.command("send <chatId>").description("Send a message to a chat").option("--text <text>", "Text message to send").option("--image <path>", "Image file to send").option("--file <path>", "File to send").action(async (chatId, opts) => {
8065
- if (!opts.text && !opts.image && !opts.file) {
8066
- console.error("Must provide --text, --image, or --file");
8081
+ messagesCmd.command("send <chatId>").description("Send a message to a chat").option("--text <text>", "Text message to send").option("--image <path>", "Image file to send").option("--file <path>", "File to send").option("--voice <path>", "Record audio as one or more voice notes").option("--detach", "Return after the voice job is queued").action(async (chatId, opts) => {
8082
+ if (!opts.text && !opts.image && !opts.file && !opts.voice) {
8083
+ console.error("Must provide --text, --image, --file, or --voice");
8067
8084
  process.exit(1);
8068
8085
  }
8086
+ if (opts.voice) {
8087
+ if (opts.text || opts.image || opts.file) throw new Error("--voice must be sent on its own");
8088
+ const audio = fs.readFileSync(opts.voice);
8089
+ const job = await getClient().createVoiceJob(chatId, audio, randomBytes(16).toString("hex"));
8090
+ console.log(`Voice job: ${job.jobId}`);
8091
+ if (!opts.detach) await waitVoiceJob(getClient(), job.jobId);
8092
+ return;
8093
+ }
8094
+ if (opts.detach) throw new Error("--detach requires --voice");
8069
8095
  let image;
8070
8096
  if (opts.image) {
8071
8097
  if (!fs.existsSync(opts.image)) {
@@ -8088,6 +8114,34 @@ messagesCmd.command("send <chatId>").description("Send a message to a chat").opt
8088
8114
  }
8089
8115
  await cmdSend(getClient(), chatId, opts.text, image, file);
8090
8116
  });
8117
+ var voiceCmd = messagesCmd.command("voice").description("Inspect or cancel voice jobs");
8118
+ voiceCmd.command("status <jobId>").action(async (jobId) => {
8119
+ console.log(JSON.stringify(await getClient().getVoiceJob(jobId), null, 2));
8120
+ });
8121
+ voiceCmd.command("cancel <jobId>").action(async (jobId) => {
8122
+ const job = await getClient().cancelVoiceJob(jobId);
8123
+ console.log(`Cancellation requested for ${job.jobId}`);
8124
+ });
8125
+ async function waitVoiceJob(client, jobId) {
8126
+ let lastProgress = "";
8127
+ for (; ; ) {
8128
+ const job = await client.getVoiceJob(jobId);
8129
+ const verified = job.chunks.filter((chunk) => chunk.status === "verified").length;
8130
+ const progress = `${job.status}: ${verified}/${job.chunks.length} notes verified`;
8131
+ if (progress !== lastProgress) {
8132
+ console.log(progress);
8133
+ lastProgress = progress;
8134
+ }
8135
+ if (job.status === "completed") {
8136
+ console.log(`Message IDs: ${job.chunks.map((chunk) => chunk.messageId).join(", ")}`);
8137
+ return;
8138
+ }
8139
+ if (["failed", "cancelled", "needs_review"].includes(job.status)) {
8140
+ throw new Error(`${job.status}: ${job.error ?? "No further details"}. Job ${jobId}; do not resend the whole recording.`);
8141
+ }
8142
+ await new Promise((resolve) => setTimeout(resolve, 1e3));
8143
+ }
8144
+ }
8091
8145
  program2.command("update").description("Update the agent-server binary in the running container to match CLI version").action(cmdUpdate);
8092
8146
  program2.command("screenshot").description("Save screenshot to file").argument("[file]", "Output file path", "screenshot.png").action(async (file) => {
8093
8147
  await cmdScreenshot(getClient(), file);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@agent-wechat/cli",
3
- "version": "0.14.0",
3
+ "version": "0.15.0",
4
4
  "type": "module",
5
5
  "bin": {
6
6
  "wx": "./dist/cli.js"
@@ -17,7 +17,7 @@
17
17
  "@types/node": "^22",
18
18
  "@types/qrcode-terminal": "^0.12.2",
19
19
  "typescript": "^5.4.5",
20
- "@agent-wechat/shared": "0.2.0"
20
+ "@agent-wechat/shared": "0.3.0"
21
21
  },
22
22
  "publishConfig": {
23
23
  "access": "public",