@agent-wechat/cli 0.7.10 → 0.8.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.
Files changed (2) hide show
  1. package/dist/cli.js +55 -1
  2. package/package.json +1 -1
package/dist/cli.js CHANGED
@@ -3565,6 +3565,13 @@ var WeChatClient = class {
3565
3565
  async openChat(chatId, clearUnreads) {
3566
3566
  return this.post(`/api/chats/${encodeURIComponent(chatId)}/open${qs({ clearUnreads })}`);
3567
3567
  }
3568
+ // ---- Contacts ----
3569
+ async listContacts(limit, offset) {
3570
+ return this.get(`/api/contacts${qs({ limit, offset })}`);
3571
+ }
3572
+ async findContacts(name) {
3573
+ return this.get(`/api/contacts/find${qs({ name })}`);
3574
+ }
3568
3575
  // ---- Messages ----
3569
3576
  async listMessages(chatId, limit, offset) {
3570
3577
  return this.get(`/api/messages/${encodeURIComponent(chatId)}${qs({ limit, offset })}`);
@@ -7904,7 +7911,7 @@ import qrTerminal from "qrcode-terminal";
7904
7911
  import os from "os";
7905
7912
  import path from "path";
7906
7913
  import { fileURLToPath } from "url";
7907
- var VERSION = "0.7.10";
7914
+ var VERSION = "0.8.1";
7908
7915
  var CONTAINER_NAME = "agent-wechat";
7909
7916
  var GHCR_IMAGE = "ghcr.io/thisnick/agent-wechat";
7910
7917
  var DEFAULT_PORT = 6174;
@@ -8032,6 +8039,13 @@ chatsCmd.command("find <name>").description("Find chat by name").action(async (n
8032
8039
  chatsCmd.command("open <chatId>").description("Open a chat in WeChat UI (triggers media downloads + clears unread)").option("--clear-unreads", "Clear unread count after opening").action(async (chatId, opts) => {
8033
8040
  await cmdChatOpen(getClient(), chatId, opts.clearUnreads);
8034
8041
  });
8042
+ var contactsCmd = program2.command("contacts").description("Contact management commands");
8043
+ contactsCmd.command("list").description("List all contacts from WeChat address book").option("-l, --limit <number>", "Maximum number of contacts", "200").option("-o, --offset <number>", "Skip first N contacts", "0").option("-j, --json", "Output as JSON").action(async (opts) => {
8044
+ await cmdContacts(getClient(), parseInt(opts.limit, 10), parseInt(opts.offset, 10), opts.json ?? false);
8045
+ });
8046
+ contactsCmd.command("find <name>").description("Search contacts by name").option("-j, --json", "Output as JSON").action(async (name, opts) => {
8047
+ await cmdContactsFind(getClient(), name, opts.json ?? false);
8048
+ });
8035
8049
  var messagesCmd = program2.command("messages").description("Message commands");
8036
8050
  messagesCmd.command("list <chatId>").description("List messages for a chat").option("-l, --limit <number>", "Maximum number of messages", "50").option("-o, --offset <number>", "Skip first N messages", "0").option("-j, --json", "Output as JSON").action(async (chatId, opts) => {
8037
8051
  await cmdMessages(getClient(), chatId, parseInt(opts.limit, 10), parseInt(opts.offset, 10), opts.json ?? false);
@@ -8315,6 +8329,46 @@ async function cmdChatOpen(client, chatId, clearUnreads) {
8315
8329
  process.exit(1);
8316
8330
  }
8317
8331
  }
8332
+ async function cmdContacts(client, limit = 200, offset = 0, json = false) {
8333
+ const contacts = await client.listContacts(limit, offset);
8334
+ if (json) {
8335
+ console.log(JSON.stringify(contacts, null, 2));
8336
+ return;
8337
+ }
8338
+ if (contacts.length === 0) {
8339
+ console.log("No contacts found. Make sure you're logged in.");
8340
+ return;
8341
+ }
8342
+ console.log(`Found ${contacts.length} contact(s):
8343
+ `);
8344
+ const maxIdLen = Math.max(10, ...contacts.map((c) => c.username.length));
8345
+ const idHeader = "Username".padEnd(maxIdLen);
8346
+ console.log(`${idHeader} Type Name`);
8347
+ console.log("-".repeat(maxIdLen + 30));
8348
+ for (const c of contacts) {
8349
+ const id = c.username.padEnd(maxIdLen);
8350
+ const type = c.contactType.padEnd(10);
8351
+ const name = c.remark ? `${c.nickName} (${c.remark})` : c.nickName;
8352
+ console.log(`${id} ${type} ${name}`);
8353
+ }
8354
+ }
8355
+ async function cmdContactsFind(client, name, json = false) {
8356
+ const contacts = await client.findContacts(name);
8357
+ if (json) {
8358
+ console.log(JSON.stringify(contacts, null, 2));
8359
+ return;
8360
+ }
8361
+ if (contacts.length === 0) {
8362
+ console.log(`No contacts found matching "${name}"`);
8363
+ return;
8364
+ }
8365
+ console.log(`Found ${contacts.length} matching contact(s):
8366
+ `);
8367
+ for (const c of contacts) {
8368
+ const name2 = c.remark ? `${c.nickName} (${c.remark})` : c.nickName;
8369
+ console.log(` ${c.username}: ${name2} [${c.contactType}]`);
8370
+ }
8371
+ }
8318
8372
  async function cmdSend(client, chatId, text, image, file) {
8319
8373
  const what = file ? `file "${file.filename}"` : image ? "image" : "message";
8320
8374
  console.log(`Sending ${what} to ${chatId}...`);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@agent-wechat/cli",
3
- "version": "0.7.10",
3
+ "version": "0.8.1",
4
4
  "type": "module",
5
5
  "bin": {
6
6
  "wx": "./dist/cli.js"