@agentcomms/whatsapp 0.8.0 → 0.10.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.
package/dist/cli.mjs CHANGED
@@ -1,10 +1,10 @@
1
1
  #!/usr/bin/env node
2
- import { $ as withFileLock, A as CommsError, B as installExitStatus, C as checkStorePath, F as canPrompt, G as paint, H as lookupName, I as channelManifest, J as runCommand, K as renderInstall, L as colorEnabled, M as agentMarker, N as approvalKind, O as CHANNELS, P as approveChangeAtTerminal, Q as truncateDisplay, R as escapeForDisplay, S as storeIdentity, T as expandSource, U as nameAvailable, V as isCommsError, W as nameShapeProblem, X as serverPruneChange, Y as serverInstallChange, _ as chatRefOf, a as listChats, b as requireAccount, c as Presenter, d as draftMessage, et as writeResult, f as Visibility, g as requireSupportedNode, h as WhatsAppIndex, i as CHAT_KINDS, j as EXIT_CODES, k as CHANNEL_SERVERS, l as innerText, m as WhatsAppContext, n as whatsappStatus, o as readChat, p as listKey, q as renderPrune, r as probeStore, s as searchMessages, t as syncAccount, tt as VERSION, v as PLATFORM, w as defaultStorePath, x as requireNamedConfig, y as newWhatsAppAccount, z as gatedChangeAtTerminal } from "./sync-BcshklLi.mjs";
2
+ import { $ as renderPrune, A as CommsError, B as colorEnabled, C as checkStorePath, F as approvalsOf, G as installExitStatus, H as escapeForDisplay, I as approveChangeAtTerminal, J as nameAvailable, K as isCommsError, L as canPrompt, M as absoluteSearchPath, N as agentMarker, O as CHANNELS, P as approvalKind, Q as renderInstall, R as channelManifest, S as storeIdentity, T as expandSource, U as exemptFromUpdateGate, V as commandPathOf, W as gatedChangeAtTerminal, X as openCore, Y as nameShapeProblem, Z as paint, _ as chatRefOf, a as listChats, at as updateGateAtTerminal, b as requireAccount, c as Presenter, ct as withFileLock, d as draftMessage, et as runCommand, f as Visibility, g as requireSupportedNode, h as WhatsAppIndex, i as CHAT_KINDS, it as truncateDisplay, j as EXIT_CODES, k as CHANNEL_SERVERS, l as innerText, lt as writeResult, m as WhatsAppContext, n as whatsappStatus, nt as serverPruneChange, o as readChat, p as listKey, q as lookupName, r as probeStore, s as searchMessages, st as windowsSystemProgram, t as syncAccount, tt as serverInstallChange, ut as VERSION, v as PLATFORM, w as defaultStorePath, x as requireNamedConfig, y as newWhatsAppAccount, z as childEnvironment } from "./sync-C7h-yFy_.mjs";
3
3
  import { rm } from "node:fs/promises";
4
- import path from "node:path";
5
- import { stripVTControlCharacters } from "node:util";
4
+ import path, { delimiter, join } from "node:path";
6
5
  import childProcess, { spawn } from "node:child_process";
7
- import fs from "node:fs";
6
+ import { stripVTControlCharacters } from "node:util";
7
+ import fs, { accessSync, constants as constants$1 } from "node:fs";
8
8
  import process$1 from "node:process";
9
9
  import { EventEmitter } from "node:events";
10
10
  //#region ../../node_modules/.pnpm/commander@15.0.0/node_modules/commander/lib/error.js
@@ -3161,18 +3161,17 @@ function clearChats(context, request) {
3161
3161
  }
3162
3162
  //#endregion
3163
3163
  //#region src/cli/opener.ts
3164
- function openLink(url, platform = process.platform) {
3164
+ function openLink(url, platform = process.platform, deps = {}) {
3165
3165
  if (!/^(?:whatsapp:\/\/send\?|https:\/\/wa\.me\/)/.test(url)) return false;
3166
- const [command, args] = platform === "darwin" ? ["open", [url]] : platform === "win32" ? ["cmd", [
3167
- "/c",
3168
- "start",
3169
- "",
3170
- url
3171
- ]] : ["xdg-open", [url]];
3166
+ const env = deps.env ?? process.env;
3167
+ const command = linkOpener(platform, env);
3168
+ if (command === null) return false;
3169
+ const args = platform === "win32" ? ["url.dll,FileProtocolHandler", url] : [url];
3172
3170
  try {
3173
- const child = spawn(command, args, {
3171
+ const child = (deps.spawn ?? spawn)(command, args, {
3174
3172
  stdio: "ignore",
3175
- detached: true
3173
+ detached: true,
3174
+ env: childEnvironment(env, platform)
3176
3175
  });
3177
3176
  child.on("error", () => void 0);
3178
3177
  child.unref();
@@ -3181,6 +3180,19 @@ function openLink(url, platform = process.platform) {
3181
3180
  return false;
3182
3181
  }
3183
3182
  }
3183
+ /** The opener's full path, or null when there is none that can be named without looking in the current folder. */
3184
+ function linkOpener(platform, env) {
3185
+ if (platform === "win32") return windowsSystemProgram("rundll32.exe", env);
3186
+ if (platform === "darwin") return "/usr/bin/open";
3187
+ for (const directory of absoluteSearchPath((env.PATH ?? "").split(delimiter), platform)) {
3188
+ const candidate = join(directory, "xdg-open");
3189
+ try {
3190
+ accessSync(candidate, constants$1.X_OK);
3191
+ return candidate;
3192
+ } catch {}
3193
+ }
3194
+ return null;
3195
+ }
3184
3196
  //#endregion
3185
3197
  //#region src/cli/render.ts
3186
3198
  /**
@@ -3345,7 +3357,8 @@ Getting started (a person, in a terminal):
3345
3357
 
3346
3358
  Nothing here connects to WhatsApp or any other server, and nothing here can send. Needs Node 22.16 or newer.
3347
3359
 
3348
- Exit codes: 0 ok · 1 unexpected · 10 only a person may do that, or a change needs approval · 64 usage
3360
+ Exit codes: 0 ok · 1 unexpected · 10 only a person may do that, or a change needs approval · 11 an update
3361
+ is out: update first, or put it off (agentcomms update, agentcomms update --later) · 64 usage
3349
3362
  · 65 bad data (a store whose layout changed) · 66 not found · 69 unavailable · 75 temporary (retry;
3350
3363
  a macOS dialog may be waiting) · 77 permission needed (macOS privacy) · 78 configuration problem.`).exitOverride();
3351
3364
  const output = () => {
@@ -3360,9 +3373,35 @@ a macOS dialog may be waiting) · 77 permission needed (macOS privacy) · 78 con
3360
3373
  * start — where the result *is* the output and `--json` must still print one envelope.
3361
3374
  */
3362
3375
  let softExit = null;
3376
+ let gated = null;
3377
+ program.hook("preAction", async (_program, command) => {
3378
+ const path = commandPathOf(command);
3379
+ if (exemptFromUpdateGate(path, ["status"])) return;
3380
+ const core = openCore({ env });
3381
+ let ended = null;
3382
+ const code = await runCommand(output(), async () => {
3383
+ ended = await updateGateAtTerminal({
3384
+ core,
3385
+ env,
3386
+ binary: "agent-whatsapp",
3387
+ channel: "whatsapp",
3388
+ running: VERSION,
3389
+ output: output(),
3390
+ noInput: false,
3391
+ streams,
3392
+ approveCommand: "agent-whatsapp approve",
3393
+ approvals: approvalsOf(command)
3394
+ });
3395
+ }, streams);
3396
+ gated = code !== 0 ? code : ended;
3397
+ });
3363
3398
  const act = (body) => async (...args) => {
3364
3399
  ran = true;
3365
3400
  softExit = null;
3401
+ if (gated !== null) {
3402
+ exitCode = gated;
3403
+ return;
3404
+ }
3366
3405
  exitCode = await runCommand(output(), async () => {
3367
3406
  requireSupportedNode();
3368
3407
  await body(new WhatsAppContext({
@@ -3495,7 +3534,7 @@ a macOS dialog may be waiting) · 77 permission needed (macOS privacy) · 78 con
3495
3534
  ran = true;
3496
3535
  exitCode = await runCommand(output(), async () => {
3497
3536
  requireSupportedNode();
3498
- const { startWhatsAppStdioServer } = await import("./stdio-entry-Dmwsi_a0.mjs");
3537
+ const { startWhatsAppStdioServer } = await import("./stdio-entry-CgOrCDc-.mjs");
3499
3538
  await startWhatsAppStdioServer({
3500
3539
  env,
3501
3540
  ...flags.account ? { account: String(flags.account) } : {}
package/dist/index.mjs CHANGED
@@ -1,5 +1,5 @@
1
- import { tt as VERSION, u as composeDraft } from "./sync-BcshklLi.mjs";
2
- import { t as createWhatsAppMcpServer } from "./server-BZiPPNbS.mjs";
1
+ import { u as composeDraft, ut as VERSION } from "./sync-C7h-yFy_.mjs";
2
+ import { t as createWhatsAppMcpServer } from "./server-Br7LepI8.mjs";
3
3
  //#region src/index.ts
4
4
  /**
5
5
  * The library entry of `@agentcomms/whatsapp`.
@@ -1,4 +1,4 @@
1
- import { D as strictToolArguments, E as UNTRUSTED_NOTICE, Z as toCommsError, a as listChats, d as draftMessage, i as CHAT_KINDS, m as WhatsAppContext, n as whatsappStatus, o as readChat, s as searchMessages, t as syncAccount, tt as VERSION } from "./sync-BcshklLi.mjs";
1
+ import { D as strictToolArguments, E as UNTRUSTED_NOTICE, a as listChats, d as draftMessage, i as CHAT_KINDS, m as WhatsAppContext, n as whatsappStatus, o as readChat, ot as updateToolGate, rt as toCommsError, s as searchMessages, t as syncAccount, ut as VERSION } from "./sync-C7h-yFy_.mjs";
2
2
  import { c as boolean, h as number, x as string } from "./schemas-DiGKNDNq.mjs";
3
3
  import { t as McpServer } from "./mcp-DXXb3Vv3-Co5BzjYe.mjs";
4
4
  //#region src/mcp/server.ts
@@ -70,7 +70,15 @@ async function createWhatsAppMcpServer(options = {}) {
70
70
  }]
71
71
  };
72
72
  };
73
- strictToolArguments(server, fail);
73
+ strictToolArguments(server, fail, updateToolGate({
74
+ core: context.core,
75
+ env: context.env,
76
+ server: "agent-whatsapp",
77
+ channel: "whatsapp",
78
+ running: VERSION,
79
+ exempt: ["whatsapp_status"],
80
+ now: context.now
81
+ }));
74
82
  const readsLocal = {
75
83
  readOnlyHint: true,
76
84
  openWorldHint: false
@@ -1,4 +1,4 @@
1
- import { t as createWhatsAppMcpServer } from "./server-BZiPPNbS.mjs";
1
+ import { t as createWhatsAppMcpServer } from "./server-Br7LepI8.mjs";
2
2
  //#region src/mcp/stdio-entry.ts
3
3
  /**
4
4
  * Starting the stdio server. On stdio, stdout is the protocol, so the console is redirected to stderr first — the