@vapi-network/core 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.
@@ -1,5 +1,5 @@
1
1
  import { type LookupFn } from "./net-guard.js";
2
- export declare const VAPI_CLIENT_VERSION = "0.15.1";
2
+ export declare const VAPI_CLIENT_VERSION = "0.15.2";
3
3
  export type SupportSystemInfo = {
4
4
  platform: string;
5
5
  release: string;
package/dist/tasks.js CHANGED
@@ -37742,12 +37742,12 @@ async function removeStaleLock(path) {
37742
37742
  const pid = lockOwnerPid(owner);
37743
37743
  if (pid !== void 0 && processIsAlive(pid)) return;
37744
37744
  await atomicFileTestHooks?.beforeStaleLockBreak?.(path);
37745
- await removeOwnedLock(path, [owner]);
37745
+ await removeOwnedLock(path, [owner], true);
37746
37746
  } catch (error61) {
37747
37747
  if (!hasCode(error61, "ENOENT")) throw error61;
37748
37748
  }
37749
37749
  }
37750
- async function removeOwnedLock(path, owners) {
37750
+ async function removeOwnedLock(path, owners, staleDeadOwner = false) {
37751
37751
  const tombPath = `${path}.stale.${randomBytes2(16).toString("hex")}`;
37752
37752
  try {
37753
37753
  await rename(path, tombPath);
@@ -37756,7 +37756,7 @@ async function removeOwnedLock(path, owners) {
37756
37756
  await removeOwnedTombs(path, owners);
37757
37757
  const currentOwner = await readFile(path, "utf8").catch(() => void 0);
37758
37758
  if (currentOwner !== void 0 && owners.includes(currentOwner)) {
37759
- await removeOwnedLock(path, owners);
37759
+ await removeOwnedLock(path, owners, staleDeadOwner);
37760
37760
  }
37761
37761
  return;
37762
37762
  }
@@ -37765,6 +37765,7 @@ async function removeOwnedLock(path, owners) {
37765
37765
  let pendingError;
37766
37766
  let renamedOwner;
37767
37767
  try {
37768
+ await atomicFileTestHooks?.afterLockRename?.(tombPath);
37768
37769
  renamedOwner = await readFile(tombPath, "utf8");
37769
37770
  if (!owners.includes(renamedOwner) && !lockOwnerReleased(renamedOwner)) {
37770
37771
  await atomicFileTestHooks?.afterMismatchedLockRename?.(path);
@@ -37773,6 +37774,7 @@ async function removeOwnedLock(path, owners) {
37773
37774
  await atomicFileTestHooks?.afterMismatchedLockRestore?.(path);
37774
37775
  }
37775
37776
  } catch (error61) {
37777
+ if (hasCode(error61, "ENOENT")) return;
37776
37778
  pendingError = error61;
37777
37779
  }
37778
37780
  try {
@@ -37781,7 +37783,7 @@ async function removeOwnedLock(path, owners) {
37781
37783
  } catch (error61) {
37782
37784
  if (!tombUnlinkTolerated(
37783
37785
  error61,
37784
- renamedOwner !== void 0 && lockOwnerReleased(renamedOwner) && owners.includes(renamedOwner)
37786
+ renamedOwner !== void 0 && (lockOwnerReleased(renamedOwner) || staleDeadOwner) && owners.includes(renamedOwner)
37785
37787
  ) && pendingError === void 0) {
37786
37788
  pendingError = error61;
37787
37789
  }
@@ -37961,7 +37963,7 @@ async function assertPublicUrl(url2, options) {
37961
37963
  options.timeoutMs ?? 5e3
37962
37964
  );
37963
37965
  } catch {
37964
- throw guardError(url2);
37966
+ throw guardError(url2, "unresolved");
37965
37967
  }
37966
37968
  if (addresses.length === 0 || addresses.some(isNonPublicAddress)) {
37967
37969
  throw guardError(url2);
@@ -38116,10 +38118,67 @@ function isNonPublicIpv6(hextets) {
38116
38118
  const isDocumentation = first === 8193 && hextets[1] === 3512;
38117
38119
  return isUnspecified || isLoopback || isUniqueLocal || isLinkLocal || isSiteLocal || isMulticast || isDocumentation;
38118
38120
  }
38119
- function guardError(url2) {
38120
- return new Error(
38121
- `URL hostname ${JSON.stringify(url2.hostname)} is not allowed; private or internal destinations require allowPrivateNetwork true in the vAPI config.`
38121
+ var NetworkGuardError = class extends Error {
38122
+ constructor(message, reason) {
38123
+ super(message);
38124
+ this.reason = reason;
38125
+ this.name = "NetworkGuardError";
38126
+ }
38127
+ reason;
38128
+ };
38129
+ function guardError(url2, reason = "blocked") {
38130
+ return new NetworkGuardError(
38131
+ `URL hostname ${JSON.stringify(url2.hostname)} is not allowed; private or internal destinations require allowPrivateNetwork true in the vAPI config.`,
38132
+ reason
38133
+ );
38134
+ }
38135
+ var PROXY_VARIABLES = {
38136
+ "https:": ["HTTPS_PROXY", "https_proxy"],
38137
+ "http:": ["HTTP_PROXY", "http_proxy"]
38138
+ };
38139
+ var SYSTEM_ERROR_CODE = /^[A-Z][A-Z0-9_]{1,39}$/u;
38140
+ function describeNetworkFailure(error61, url2, env = process.env) {
38141
+ const host = url2.host;
38142
+ let reason;
38143
+ const guard = guardReason(error61);
38144
+ if (guard !== void 0) {
38145
+ reason = guard === "unresolved" ? `the DNS lookup for ${host} failed` : `${host} is not a public address`;
38146
+ } else if (isTimeout(error61)) {
38147
+ reason = `the connection to ${host} timed out`;
38148
+ } else {
38149
+ const code = systemErrorCode(error61);
38150
+ reason = `could not connect to ${host}${code === void 0 ? "" : ` (${code})`}`;
38151
+ }
38152
+ const proxy = (PROXY_VARIABLES[url2.protocol] ?? []).find(
38153
+ (name) => (env[name] ?? "").trim() !== ""
38122
38154
  );
38155
+ let hint = "";
38156
+ if (proxy !== void 0) {
38157
+ if (env.NODE_USE_ENV_PROXY !== "1") {
38158
+ 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.`;
38159
+ } else if (guard === "unresolved") {
38160
+ hint = ` vapi looks ${host} up on this machine before it uses the proxy in ${proxy}, so the name must resolve here too.`;
38161
+ } else if (guard === void 0) {
38162
+ hint = ` NODE_USE_ENV_PROXY=1 and ${proxy} are set, so the proxy may have refused the connection.`;
38163
+ }
38164
+ }
38165
+ return `${reason}.${hint}`;
38166
+ }
38167
+ function guardReason(error61) {
38168
+ if (!(error61 instanceof Error) || error61.name !== "NetworkGuardError") return void 0;
38169
+ const reason = error61.reason;
38170
+ return reason === "blocked" || reason === "unresolved" ? reason : void 0;
38171
+ }
38172
+ function isTimeout(error61) {
38173
+ return error61 instanceof Error && (error61.name === "TimeoutError" || error61.name === "AbortError");
38174
+ }
38175
+ function systemErrorCode(error61) {
38176
+ for (let current = error61, depth = 0; current instanceof Error && depth < 3; depth += 1) {
38177
+ const code = current.code;
38178
+ if (typeof code === "string" && SYSTEM_ERROR_CODE.test(code)) return code;
38179
+ current = current.cause;
38180
+ }
38181
+ return void 0;
38123
38182
  }
38124
38183
 
38125
38184
  // src/tasks/types.ts
@@ -42980,9 +43039,18 @@ function parseTokens(value) {
42980
43039
  async function safeFetch(fetchImpl, input2, init) {
42981
43040
  try {
42982
43041
  return await fetchImpl(input2, init);
43042
+ } catch (error61) {
43043
+ throw httpError(`The vAPI agent link request failed: ${networkFailure(error61, input2)}`);
43044
+ }
43045
+ }
43046
+ function networkFailure(error61, input2) {
43047
+ let url2;
43048
+ try {
43049
+ url2 = new URL(input2 instanceof Request ? input2.url : input2);
42983
43050
  } catch {
42984
- throw httpError("The vAPI agent link request failed.");
43051
+ return "the request did not reach vAPI.";
42985
43052
  }
43053
+ return describeNetworkFailure(error61, url2);
42986
43054
  }
42987
43055
  function notLinkedError() {
42988
43056
  return new AgentLinkError("not_linked", "Run vapi login first.");