@vapi-network/cli 0.15.1 → 0.15.2

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/agent.d.ts CHANGED
@@ -14,7 +14,11 @@ export type AgentCommandDependencies = {
14
14
  export declare function agentCommand(argv: string[], json: boolean, io: CliIo, dependencies: CliDependencies): Promise<number>;
15
15
  /** Redact all strings, then restore only public EVM settlement references. */
16
16
  export declare function redactAgentRunResult(executed: RunAgentResult, environment: NodeJS.ProcessEnv): RunAgentResult;
17
- export declare function printAgentRefills(result: RunAgentResult, io: CliIo): void;
17
+ /**
18
+ * Prints each refill's receipt, transaction and warnings. When `io` redacts its lines, pass the
19
+ * plain output as `settlementHashIo`: a transaction that is a settlement hash is printed there.
20
+ */
21
+ export declare function printAgentRefills(result: RunAgentResult, io: CliIo, settlementHashIo?: CliIo): void;
18
22
  export declare function buildAgentRunDeps(input: {
19
23
  profile: AgentProfile;
20
24
  runId: string;
package/dist/cli.js CHANGED
@@ -43926,7 +43926,7 @@ async function assertPublicUrl(url2, options) {
43926
43926
  options.timeoutMs ?? 5e3
43927
43927
  );
43928
43928
  } catch {
43929
- throw guardError(url2);
43929
+ throw guardError(url2, "unresolved");
43930
43930
  }
43931
43931
  if (addresses.length === 0 || addresses.some(isNonPublicAddress)) {
43932
43932
  throw guardError(url2);
@@ -44081,10 +44081,67 @@ function isNonPublicIpv6(hextets) {
44081
44081
  const isDocumentation = first === 8193 && hextets[1] === 3512;
44082
44082
  return isUnspecified || isLoopback || isUniqueLocal || isLinkLocal || isSiteLocal || isMulticast || isDocumentation;
44083
44083
  }
44084
- function guardError(url2) {
44085
- return new Error(
44086
- `URL hostname ${JSON.stringify(url2.hostname)} is not allowed; private or internal destinations require allowPrivateNetwork true in the vAPI config.`
44084
+ var NetworkGuardError = class extends Error {
44085
+ constructor(message, reason) {
44086
+ super(message);
44087
+ this.reason = reason;
44088
+ this.name = "NetworkGuardError";
44089
+ }
44090
+ reason;
44091
+ };
44092
+ function guardError(url2, reason = "blocked") {
44093
+ return new NetworkGuardError(
44094
+ `URL hostname ${JSON.stringify(url2.hostname)} is not allowed; private or internal destinations require allowPrivateNetwork true in the vAPI config.`,
44095
+ reason
44096
+ );
44097
+ }
44098
+ var PROXY_VARIABLES = {
44099
+ "https:": ["HTTPS_PROXY", "https_proxy"],
44100
+ "http:": ["HTTP_PROXY", "http_proxy"]
44101
+ };
44102
+ var SYSTEM_ERROR_CODE = /^[A-Z][A-Z0-9_]{1,39}$/u;
44103
+ function describeNetworkFailure(error61, url2, env = process.env) {
44104
+ const host = url2.host;
44105
+ let reason;
44106
+ const guard = guardReason(error61);
44107
+ if (guard !== void 0) {
44108
+ reason = guard === "unresolved" ? `the DNS lookup for ${host} failed` : `${host} is not a public address`;
44109
+ } else if (isTimeout(error61)) {
44110
+ reason = `the connection to ${host} timed out`;
44111
+ } else {
44112
+ const code = systemErrorCode(error61);
44113
+ reason = `could not connect to ${host}${code === void 0 ? "" : ` (${code})`}`;
44114
+ }
44115
+ const proxy = (PROXY_VARIABLES[url2.protocol] ?? []).find(
44116
+ (name) => (env[name] ?? "").trim() !== ""
44087
44117
  );
44118
+ let hint = "";
44119
+ if (proxy !== void 0) {
44120
+ if (env.NODE_USE_ENV_PROXY !== "1") {
44121
+ hint = ` ${proxy} is set, but Node.js uses it only with NODE_USE_ENV_PROXY=1 (Node.js 22.21 or later): run the command again with NODE_USE_ENV_PROXY=1.`;
44122
+ } else if (guard === "unresolved") {
44123
+ hint = ` vapi looks ${host} up on this machine before it uses the proxy in ${proxy}, so the name must resolve here too.`;
44124
+ } else if (guard === void 0) {
44125
+ hint = ` NODE_USE_ENV_PROXY=1 and ${proxy} are set, so the proxy may have refused the connection.`;
44126
+ }
44127
+ }
44128
+ return `${reason}.${hint}`;
44129
+ }
44130
+ function guardReason(error61) {
44131
+ if (!(error61 instanceof Error) || error61.name !== "NetworkGuardError") return void 0;
44132
+ const reason = error61.reason;
44133
+ return reason === "blocked" || reason === "unresolved" ? reason : void 0;
44134
+ }
44135
+ function isTimeout(error61) {
44136
+ return error61 instanceof Error && (error61.name === "TimeoutError" || error61.name === "AbortError");
44137
+ }
44138
+ function systemErrorCode(error61) {
44139
+ for (let current = error61, depth = 0; current instanceof Error && depth < 3; depth += 1) {
44140
+ const code = current.code;
44141
+ if (typeof code === "string" && SYSTEM_ERROR_CODE.test(code)) return code;
44142
+ current = current.cause;
44143
+ }
44144
+ return void 0;
44088
44145
  }
44089
44146
 
44090
44147
  // ../core/src/networks.ts
@@ -47203,12 +47260,12 @@ async function removeStaleLock(path) {
47203
47260
  const pid = lockOwnerPid(owner);
47204
47261
  if (pid !== void 0 && processIsAlive(pid)) return;
47205
47262
  await atomicFileTestHooks?.beforeStaleLockBreak?.(path);
47206
- await removeOwnedLock(path, [owner]);
47263
+ await removeOwnedLock(path, [owner], true);
47207
47264
  } catch (error61) {
47208
47265
  if (!hasCode(error61, "ENOENT")) throw error61;
47209
47266
  }
47210
47267
  }
47211
- async function removeOwnedLock(path, owners) {
47268
+ async function removeOwnedLock(path, owners, staleDeadOwner = false) {
47212
47269
  const tombPath = `${path}.stale.${randomBytes2(16).toString("hex")}`;
47213
47270
  try {
47214
47271
  await rename(path, tombPath);
@@ -47217,7 +47274,7 @@ async function removeOwnedLock(path, owners) {
47217
47274
  await removeOwnedTombs(path, owners);
47218
47275
  const currentOwner = await readFile(path, "utf8").catch(() => void 0);
47219
47276
  if (currentOwner !== void 0 && owners.includes(currentOwner)) {
47220
- await removeOwnedLock(path, owners);
47277
+ await removeOwnedLock(path, owners, staleDeadOwner);
47221
47278
  }
47222
47279
  return;
47223
47280
  }
@@ -47226,6 +47283,7 @@ async function removeOwnedLock(path, owners) {
47226
47283
  let pendingError;
47227
47284
  let renamedOwner;
47228
47285
  try {
47286
+ await atomicFileTestHooks?.afterLockRename?.(tombPath);
47229
47287
  renamedOwner = await readFile(tombPath, "utf8");
47230
47288
  if (!owners.includes(renamedOwner) && !lockOwnerReleased(renamedOwner)) {
47231
47289
  await atomicFileTestHooks?.afterMismatchedLockRename?.(path);
@@ -47234,6 +47292,7 @@ async function removeOwnedLock(path, owners) {
47234
47292
  await atomicFileTestHooks?.afterMismatchedLockRestore?.(path);
47235
47293
  }
47236
47294
  } catch (error61) {
47295
+ if (hasCode(error61, "ENOENT")) return;
47237
47296
  pendingError = error61;
47238
47297
  }
47239
47298
  try {
@@ -47242,7 +47301,7 @@ async function removeOwnedLock(path, owners) {
47242
47301
  } catch (error61) {
47243
47302
  if (!tombUnlinkTolerated(
47244
47303
  error61,
47245
- renamedOwner !== void 0 && lockOwnerReleased(renamedOwner) && owners.includes(renamedOwner)
47304
+ renamedOwner !== void 0 && (lockOwnerReleased(renamedOwner) || staleDeadOwner) && owners.includes(renamedOwner)
47246
47305
  ) && pendingError === void 0) {
47247
47306
  pendingError = error61;
47248
47307
  }
@@ -48469,16 +48528,25 @@ function withBearer(init, accessToken) {
48469
48528
  async function safeFetch(fetchImpl, input2, init) {
48470
48529
  try {
48471
48530
  return await fetchImpl(input2, init);
48472
- } catch {
48473
- throw httpError("The vAPI agent link request failed.");
48531
+ } catch (error61) {
48532
+ throw httpError(`The vAPI agent link request failed: ${networkFailure(error61, input2)}`);
48474
48533
  }
48475
48534
  }
48476
48535
  async function safeAgentFetch(fetchImpl, input2, init) {
48477
48536
  try {
48478
48537
  return await fetchImpl(input2, init);
48538
+ } catch (error61) {
48539
+ throw httpError(`The vAPI agent request failed: ${networkFailure(error61, input2)}`);
48540
+ }
48541
+ }
48542
+ function networkFailure(error61, input2) {
48543
+ let url2;
48544
+ try {
48545
+ url2 = new URL(input2 instanceof Request ? input2.url : input2);
48479
48546
  } catch {
48480
- throw httpError("The vAPI agent request failed.");
48547
+ return "the request did not reach vAPI.";
48481
48548
  }
48549
+ return describeNetworkFailure(error61, url2);
48482
48550
  }
48483
48551
  function deviceAuthorizationError(status, payload) {
48484
48552
  const error61 = stringField(payload, "error");
@@ -78591,7 +78659,7 @@ function createRunBudget(args) {
78591
78659
  import { mkdir as mkdir15, writeFile as writeFile7 } from "node:fs/promises";
78592
78660
  import { arch, platform, release } from "node:os";
78593
78661
  import { join as join14 } from "node:path";
78594
- var VAPI_CLIENT_VERSION = "0.15.1";
78662
+ var VAPI_CLIENT_VERSION = "0.15.2";
78595
78663
  async function createSupportReport(options) {
78596
78664
  const message = options.message.trim();
78597
78665
  if (!message) throw new Error("Support report message must not be empty.");
@@ -102586,7 +102654,7 @@ async function readProcessStdin() {
102586
102654
  }
102587
102655
 
102588
102656
  // src/version.ts
102589
- var CLI_VERSION = "0.15.1";
102657
+ var CLI_VERSION = "0.15.2";
102590
102658
 
102591
102659
  // src/status.ts
102592
102660
  async function statusCommand(argv, json2, io, dependencies) {
@@ -106374,6 +106442,10 @@ ${RUN_USAGE}`
106374
106442
  ${RUN_USAGE}`);
106375
106443
  }
106376
106444
  const environment = getEnvironment(dependencies);
106445
+ const runIo = resultFile === void 0 ? io : {
106446
+ stdout: (message) => io.stdout(redactDetachedRunText(message, environment)),
106447
+ stderr: (message) => io.stderr(redactDetachedRunText(message, environment))
106448
+ };
106377
106449
  const configuredRunId = environmentRunId(environment, "VAPI_RUN_ID");
106378
106450
  const parentRunId = environmentRunId(environment, "VAPI_PARENT_RUN_ID");
106379
106451
  const paths = getVapiPaths();
@@ -106385,8 +106457,8 @@ ${RUN_USAGE}`);
106385
106457
  if (resultFile !== void 0) {
106386
106458
  await writeJsonAtomic(resultFile, { v: 1, exitCode: 1, result: result2 }, { mode: 384 });
106387
106459
  }
106388
- if (json2) io.stdout(JSON.stringify(result2));
106389
- else io.stderr(message);
106460
+ if (json2) runIo.stdout(JSON.stringify(result2));
106461
+ else runIo.stderr(message);
106390
106462
  return 1;
106391
106463
  }
106392
106464
  const runId = configuredRunId ?? createRunId();
@@ -106450,42 +106522,48 @@ ${RUN_USAGE}`);
106450
106522
  ...runMeta === void 0 ? {} : { runMeta },
106451
106523
  approvals: "tty",
106452
106524
  json: json2,
106453
- io,
106525
+ io: runIo,
106454
106526
  dependencies
106455
106527
  });
106456
106528
  const execute = dependencies.agent?.runAgent ?? runAgent;
106457
106529
  const executed = await execute(task, runDependencies);
106458
106530
  const result = resultFile === void 0 ? executed : redactAgentRunResult(executed, environment);
106459
- if (!json2) printAgentRefills(result, io);
106531
+ if (!json2) printAgentRefills(result, runIo, io);
106460
106532
  const exitCode = result.stoppedBecause.reason === "finished" ? 0 : 1;
106461
106533
  if (resultFile !== void 0) {
106462
106534
  await writeJsonAtomic(resultFile, { v: 1, exitCode, result }, { mode: 384 });
106463
106535
  }
106464
106536
  if (json2) {
106465
- io.stdout(JSON.stringify(result));
106537
+ io.stdout(
106538
+ JSON.stringify(resultFile === void 0 ? result : redactAgentRunResult(result, environment))
106539
+ );
106466
106540
  } else if (result.stoppedBecause.reason === "finished") {
106467
- io.stdout(result.answer ?? "");
106541
+ runIo.stdout(result.answer ?? "");
106468
106542
  } else {
106469
- io.stderr(result.stoppedBecause.detail ?? result.stoppedBecause.reason);
106543
+ runIo.stderr(result.stoppedBecause.detail ?? result.stoppedBecause.reason);
106470
106544
  }
106471
106545
  return exitCode;
106472
106546
  }
106547
+ var SETTLEMENT_HASH = /^0x[0-9a-fA-F]{64}$/u;
106473
106548
  function redactAgentRunResult(executed, environment) {
106474
106549
  const result = redactDetachedRunValue(executed, environment);
106475
106550
  for (const [index2, refill] of (executed.refills ?? []).entries()) {
106476
106551
  const transaction2 = refill.receipt.transaction;
106477
106552
  const redacted = result.refills?.[index2];
106478
- if (redacted !== void 0 && transaction2 !== void 0 && /^0x[0-9a-fA-F]{64}$/u.test(transaction2)) {
106553
+ if (redacted !== void 0 && transaction2 !== void 0 && SETTLEMENT_HASH.test(transaction2)) {
106479
106554
  redacted.receipt.transaction = transaction2;
106480
106555
  }
106481
106556
  }
106482
106557
  return result;
106483
106558
  }
106484
- function printAgentRefills(result, io) {
106559
+ function printAgentRefills(result, io, settlementHashIo = io) {
106485
106560
  for (const refill of result.refills ?? []) {
106486
106561
  io.stderr(`Receipt: ${refill.receipt.id}`);
106487
- if (refill.receipt.transaction !== void 0)
106488
- io.stderr(`Transaction: ${refill.receipt.transaction}`);
106562
+ const transaction2 = refill.receipt.transaction;
106563
+ if (transaction2 !== void 0) {
106564
+ const output4 = SETTLEMENT_HASH.test(transaction2) ? settlementHashIo : io;
106565
+ output4.stderr(`Transaction: ${transaction2}`);
106566
+ }
106489
106567
  for (const warning of refill.warnings ?? []) io.stderr(warning.message);
106490
106568
  }
106491
106569
  }
@@ -111086,12 +111164,7 @@ async function runCli(argv = process.argv.slice(2), io = processIo, dependencies
111086
111164
  exitCode = 0;
111087
111165
  break;
111088
111166
  case "agent":
111089
- exitCode = await agentCommand(
111090
- args.slice(1),
111091
- json2,
111092
- args[1] === "run" && args.includes("--bundle-env") ? io : runIo,
111093
- dependencies
111094
- );
111167
+ exitCode = await agentCommand(args.slice(1), json2, io, dependencies);
111095
111168
  break;
111096
111169
  case "dashboard":
111097
111170
  await dashboardCommand(args.slice(1), json2, io, dependencies);