vapi-network 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/README.md CHANGED
@@ -24,7 +24,7 @@ vAPI Network is not related to Vapi.ai, the voice AI company.
24
24
 
25
25
  ## Quickstart
26
26
 
27
- This README describes client 0.15.1. `npm view vapi-network version` shows the latest published release.
27
+ This README describes client 0.15.2. `npm view vapi-network version` shows the latest published release.
28
28
  The client needs Node.js 22 or newer.
29
29
 
30
30
  ```bash
package/SKILL.md CHANGED
@@ -1,6 +1,6 @@
1
1
  ---
2
2
  name: vapi
3
- version: 0.15.1
3
+ version: 0.15.2
4
4
  description: >-
5
5
  Pay for one API call at a time, in USDC, from the agent's own wallet. Search
6
6
  vAPI Call before writing a scraper, before asking the user to sign up for an
package/dist/cli.js CHANGED
@@ -43925,7 +43925,7 @@ async function assertPublicUrl(url2, options) {
43925
43925
  options.timeoutMs ?? 5e3
43926
43926
  );
43927
43927
  } catch {
43928
- throw guardError(url2);
43928
+ throw guardError(url2, "unresolved");
43929
43929
  }
43930
43930
  if (addresses.length === 0 || addresses.some(isNonPublicAddress)) {
43931
43931
  throw guardError(url2);
@@ -44080,10 +44080,67 @@ function isNonPublicIpv6(hextets) {
44080
44080
  const isDocumentation = first === 8193 && hextets[1] === 3512;
44081
44081
  return isUnspecified || isLoopback || isUniqueLocal || isLinkLocal || isSiteLocal || isMulticast || isDocumentation;
44082
44082
  }
44083
- function guardError(url2) {
44084
- return new Error(
44085
- `URL hostname ${JSON.stringify(url2.hostname)} is not allowed; private or internal destinations require allowPrivateNetwork true in the vAPI config.`
44083
+ var NetworkGuardError = class extends Error {
44084
+ constructor(message, reason) {
44085
+ super(message);
44086
+ this.reason = reason;
44087
+ this.name = "NetworkGuardError";
44088
+ }
44089
+ reason;
44090
+ };
44091
+ function guardError(url2, reason = "blocked") {
44092
+ return new NetworkGuardError(
44093
+ `URL hostname ${JSON.stringify(url2.hostname)} is not allowed; private or internal destinations require allowPrivateNetwork true in the vAPI config.`,
44094
+ reason
44095
+ );
44096
+ }
44097
+ var PROXY_VARIABLES = {
44098
+ "https:": ["HTTPS_PROXY", "https_proxy"],
44099
+ "http:": ["HTTP_PROXY", "http_proxy"]
44100
+ };
44101
+ var SYSTEM_ERROR_CODE = /^[A-Z][A-Z0-9_]{1,39}$/u;
44102
+ function describeNetworkFailure(error61, url2, env = process.env) {
44103
+ const host = url2.host;
44104
+ let reason;
44105
+ const guard = guardReason(error61);
44106
+ if (guard !== void 0) {
44107
+ reason = guard === "unresolved" ? `the DNS lookup for ${host} failed` : `${host} is not a public address`;
44108
+ } else if (isTimeout(error61)) {
44109
+ reason = `the connection to ${host} timed out`;
44110
+ } else {
44111
+ const code = systemErrorCode(error61);
44112
+ reason = `could not connect to ${host}${code === void 0 ? "" : ` (${code})`}`;
44113
+ }
44114
+ const proxy = (PROXY_VARIABLES[url2.protocol] ?? []).find(
44115
+ (name) => (env[name] ?? "").trim() !== ""
44086
44116
  );
44117
+ let hint = "";
44118
+ if (proxy !== void 0) {
44119
+ if (env.NODE_USE_ENV_PROXY !== "1") {
44120
+ 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.`;
44121
+ } else if (guard === "unresolved") {
44122
+ hint = ` vapi looks ${host} up on this machine before it uses the proxy in ${proxy}, so the name must resolve here too.`;
44123
+ } else if (guard === void 0) {
44124
+ hint = ` NODE_USE_ENV_PROXY=1 and ${proxy} are set, so the proxy may have refused the connection.`;
44125
+ }
44126
+ }
44127
+ return `${reason}.${hint}`;
44128
+ }
44129
+ function guardReason(error61) {
44130
+ if (!(error61 instanceof Error) || error61.name !== "NetworkGuardError") return void 0;
44131
+ const reason = error61.reason;
44132
+ return reason === "blocked" || reason === "unresolved" ? reason : void 0;
44133
+ }
44134
+ function isTimeout(error61) {
44135
+ return error61 instanceof Error && (error61.name === "TimeoutError" || error61.name === "AbortError");
44136
+ }
44137
+ function systemErrorCode(error61) {
44138
+ for (let current = error61, depth = 0; current instanceof Error && depth < 3; depth += 1) {
44139
+ const code = current.code;
44140
+ if (typeof code === "string" && SYSTEM_ERROR_CODE.test(code)) return code;
44141
+ current = current.cause;
44142
+ }
44143
+ return void 0;
44087
44144
  }
44088
44145
 
44089
44146
  // ../core/src/networks.ts
@@ -47202,12 +47259,12 @@ async function removeStaleLock(path) {
47202
47259
  const pid = lockOwnerPid(owner);
47203
47260
  if (pid !== void 0 && processIsAlive(pid)) return;
47204
47261
  await atomicFileTestHooks?.beforeStaleLockBreak?.(path);
47205
- await removeOwnedLock(path, [owner]);
47262
+ await removeOwnedLock(path, [owner], true);
47206
47263
  } catch (error61) {
47207
47264
  if (!hasCode(error61, "ENOENT")) throw error61;
47208
47265
  }
47209
47266
  }
47210
- async function removeOwnedLock(path, owners) {
47267
+ async function removeOwnedLock(path, owners, staleDeadOwner = false) {
47211
47268
  const tombPath = `${path}.stale.${randomBytes2(16).toString("hex")}`;
47212
47269
  try {
47213
47270
  await rename(path, tombPath);
@@ -47216,7 +47273,7 @@ async function removeOwnedLock(path, owners) {
47216
47273
  await removeOwnedTombs(path, owners);
47217
47274
  const currentOwner = await readFile(path, "utf8").catch(() => void 0);
47218
47275
  if (currentOwner !== void 0 && owners.includes(currentOwner)) {
47219
- await removeOwnedLock(path, owners);
47276
+ await removeOwnedLock(path, owners, staleDeadOwner);
47220
47277
  }
47221
47278
  return;
47222
47279
  }
@@ -47225,6 +47282,7 @@ async function removeOwnedLock(path, owners) {
47225
47282
  let pendingError;
47226
47283
  let renamedOwner;
47227
47284
  try {
47285
+ await atomicFileTestHooks?.afterLockRename?.(tombPath);
47228
47286
  renamedOwner = await readFile(tombPath, "utf8");
47229
47287
  if (!owners.includes(renamedOwner) && !lockOwnerReleased(renamedOwner)) {
47230
47288
  await atomicFileTestHooks?.afterMismatchedLockRename?.(path);
@@ -47233,6 +47291,7 @@ async function removeOwnedLock(path, owners) {
47233
47291
  await atomicFileTestHooks?.afterMismatchedLockRestore?.(path);
47234
47292
  }
47235
47293
  } catch (error61) {
47294
+ if (hasCode(error61, "ENOENT")) return;
47236
47295
  pendingError = error61;
47237
47296
  }
47238
47297
  try {
@@ -47241,7 +47300,7 @@ async function removeOwnedLock(path, owners) {
47241
47300
  } catch (error61) {
47242
47301
  if (!tombUnlinkTolerated(
47243
47302
  error61,
47244
- renamedOwner !== void 0 && lockOwnerReleased(renamedOwner) && owners.includes(renamedOwner)
47303
+ renamedOwner !== void 0 && (lockOwnerReleased(renamedOwner) || staleDeadOwner) && owners.includes(renamedOwner)
47245
47304
  ) && pendingError === void 0) {
47246
47305
  pendingError = error61;
47247
47306
  }
@@ -48468,16 +48527,25 @@ function withBearer(init, accessToken) {
48468
48527
  async function safeFetch(fetchImpl, input2, init) {
48469
48528
  try {
48470
48529
  return await fetchImpl(input2, init);
48471
- } catch {
48472
- throw httpError("The vAPI agent link request failed.");
48530
+ } catch (error61) {
48531
+ throw httpError(`The vAPI agent link request failed: ${networkFailure(error61, input2)}`);
48473
48532
  }
48474
48533
  }
48475
48534
  async function safeAgentFetch(fetchImpl, input2, init) {
48476
48535
  try {
48477
48536
  return await fetchImpl(input2, init);
48537
+ } catch (error61) {
48538
+ throw httpError(`The vAPI agent request failed: ${networkFailure(error61, input2)}`);
48539
+ }
48540
+ }
48541
+ function networkFailure(error61, input2) {
48542
+ let url2;
48543
+ try {
48544
+ url2 = new URL(input2 instanceof Request ? input2.url : input2);
48478
48545
  } catch {
48479
- throw httpError("The vAPI agent request failed.");
48546
+ return "the request did not reach vAPI.";
48480
48547
  }
48548
+ return describeNetworkFailure(error61, url2);
48481
48549
  }
48482
48550
  function deviceAuthorizationError(status, payload) {
48483
48551
  const error61 = stringField(payload, "error");
@@ -78590,7 +78658,7 @@ function createRunBudget(args) {
78590
78658
  import { mkdir as mkdir15, writeFile as writeFile7 } from "node:fs/promises";
78591
78659
  import { arch, platform, release } from "node:os";
78592
78660
  import { join as join14 } from "node:path";
78593
- var VAPI_CLIENT_VERSION = "0.15.1";
78661
+ var VAPI_CLIENT_VERSION = "0.15.2";
78594
78662
  async function createSupportReport(options) {
78595
78663
  const message = options.message.trim();
78596
78664
  if (!message) throw new Error("Support report message must not be empty.");
@@ -102582,7 +102650,7 @@ async function readProcessStdin() {
102582
102650
  }
102583
102651
 
102584
102652
  // ../cli/src/version.ts
102585
- var CLI_VERSION = "0.15.1";
102653
+ var CLI_VERSION = "0.15.2";
102586
102654
 
102587
102655
  // ../cli/src/status.ts
102588
102656
  async function statusCommand(argv, json2, io, dependencies) {
@@ -106370,6 +106438,10 @@ ${RUN_USAGE}`
106370
106438
  ${RUN_USAGE}`);
106371
106439
  }
106372
106440
  const environment = getEnvironment(dependencies);
106441
+ const runIo = resultFile === void 0 ? io : {
106442
+ stdout: (message) => io.stdout(redactDetachedRunText(message, environment)),
106443
+ stderr: (message) => io.stderr(redactDetachedRunText(message, environment))
106444
+ };
106373
106445
  const configuredRunId = environmentRunId(environment, "VAPI_RUN_ID");
106374
106446
  const parentRunId = environmentRunId(environment, "VAPI_PARENT_RUN_ID");
106375
106447
  const paths = getVapiPaths();
@@ -106381,8 +106453,8 @@ ${RUN_USAGE}`);
106381
106453
  if (resultFile !== void 0) {
106382
106454
  await writeJsonAtomic(resultFile, { v: 1, exitCode: 1, result: result2 }, { mode: 384 });
106383
106455
  }
106384
- if (json2) io.stdout(JSON.stringify(result2));
106385
- else io.stderr(message);
106456
+ if (json2) runIo.stdout(JSON.stringify(result2));
106457
+ else runIo.stderr(message);
106386
106458
  return 1;
106387
106459
  }
106388
106460
  const runId = configuredRunId ?? createRunId();
@@ -106446,42 +106518,48 @@ ${RUN_USAGE}`);
106446
106518
  ...runMeta === void 0 ? {} : { runMeta },
106447
106519
  approvals: "tty",
106448
106520
  json: json2,
106449
- io,
106521
+ io: runIo,
106450
106522
  dependencies
106451
106523
  });
106452
106524
  const execute = dependencies.agent?.runAgent ?? runAgent;
106453
106525
  const executed = await execute(task, runDependencies);
106454
106526
  const result = resultFile === void 0 ? executed : redactAgentRunResult(executed, environment);
106455
- if (!json2) printAgentRefills(result, io);
106527
+ if (!json2) printAgentRefills(result, runIo, io);
106456
106528
  const exitCode = result.stoppedBecause.reason === "finished" ? 0 : 1;
106457
106529
  if (resultFile !== void 0) {
106458
106530
  await writeJsonAtomic(resultFile, { v: 1, exitCode, result }, { mode: 384 });
106459
106531
  }
106460
106532
  if (json2) {
106461
- io.stdout(JSON.stringify(result));
106533
+ io.stdout(
106534
+ JSON.stringify(resultFile === void 0 ? result : redactAgentRunResult(result, environment))
106535
+ );
106462
106536
  } else if (result.stoppedBecause.reason === "finished") {
106463
- io.stdout(result.answer ?? "");
106537
+ runIo.stdout(result.answer ?? "");
106464
106538
  } else {
106465
- io.stderr(result.stoppedBecause.detail ?? result.stoppedBecause.reason);
106539
+ runIo.stderr(result.stoppedBecause.detail ?? result.stoppedBecause.reason);
106466
106540
  }
106467
106541
  return exitCode;
106468
106542
  }
106543
+ var SETTLEMENT_HASH = /^0x[0-9a-fA-F]{64}$/u;
106469
106544
  function redactAgentRunResult(executed, environment) {
106470
106545
  const result = redactDetachedRunValue(executed, environment);
106471
106546
  for (const [index2, refill] of (executed.refills ?? []).entries()) {
106472
106547
  const transaction2 = refill.receipt.transaction;
106473
106548
  const redacted = result.refills?.[index2];
106474
- if (redacted !== void 0 && transaction2 !== void 0 && /^0x[0-9a-fA-F]{64}$/u.test(transaction2)) {
106549
+ if (redacted !== void 0 && transaction2 !== void 0 && SETTLEMENT_HASH.test(transaction2)) {
106475
106550
  redacted.receipt.transaction = transaction2;
106476
106551
  }
106477
106552
  }
106478
106553
  return result;
106479
106554
  }
106480
- function printAgentRefills(result, io) {
106555
+ function printAgentRefills(result, io, settlementHashIo = io) {
106481
106556
  for (const refill of result.refills ?? []) {
106482
106557
  io.stderr(`Receipt: ${refill.receipt.id}`);
106483
- if (refill.receipt.transaction !== void 0)
106484
- io.stderr(`Transaction: ${refill.receipt.transaction}`);
106558
+ const transaction2 = refill.receipt.transaction;
106559
+ if (transaction2 !== void 0) {
106560
+ const output4 = SETTLEMENT_HASH.test(transaction2) ? settlementHashIo : io;
106561
+ output4.stderr(`Transaction: ${transaction2}`);
106562
+ }
106485
106563
  for (const warning of refill.warnings ?? []) io.stderr(warning.message);
106486
106564
  }
106487
106565
  }
@@ -111082,12 +111160,7 @@ async function runCli(argv = process.argv.slice(2), io = processIo, dependencies
111082
111160
  exitCode = 0;
111083
111161
  break;
111084
111162
  case "agent":
111085
- exitCode = await agentCommand(
111086
- args.slice(1),
111087
- json2,
111088
- args[1] === "run" && args.includes("--bundle-env") ? io : runIo,
111089
- dependencies
111090
- );
111163
+ exitCode = await agentCommand(args.slice(1), json2, io, dependencies);
111091
111164
  break;
111092
111165
  case "dashboard":
111093
111166
  await dashboardCommand(args.slice(1), json2, io, dependencies);