agentcash 0.4.7 → 0.4.8

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 (29) hide show
  1. package/dist/cjs/run-server.cjs +1044 -1048
  2. package/dist/esm/{chunk-N4XFC6DI.js → chunk-G4TH4S7M.js} +18 -18
  3. package/dist/esm/chunk-G4TH4S7M.js.map +1 -0
  4. package/dist/esm/{chunk-N3Q7WRL7.js → chunk-JT6T6MAR.js} +4 -5
  5. package/dist/esm/chunk-JT6T6MAR.js.map +1 -0
  6. package/dist/esm/{chunk-4VQ2CL7V.js → chunk-OS6MJ6OG.js} +3 -3
  7. package/dist/esm/{chunk-BAN7B27A.js → chunk-W3OHV4AX.js} +2 -5
  8. package/dist/esm/chunk-W3OHV4AX.js.map +1 -0
  9. package/dist/esm/{chunk-NNNL6LXH.js → chunk-Z5TNXY3J.js} +4 -4
  10. package/dist/esm/chunk-Z5TNXY3J.js.map +1 -0
  11. package/dist/esm/{chunk-FQL7T4UN.js → chunk-ZWMDIONA.js} +2 -2
  12. package/dist/esm/{commands-QUGC5OKY.js → commands-MW5VLM2A.js} +7 -7
  13. package/dist/esm/{fund-OG3VIN7O.js → fund-C24TLKK6.js} +4 -4
  14. package/dist/esm/index.js +10 -10
  15. package/dist/esm/{install-44EQVZBD.js → install-MLSX5TXL.js} +5 -6
  16. package/dist/esm/{install-44EQVZBD.js.map → install-MLSX5TXL.js.map} +1 -1
  17. package/dist/esm/{server-JQZYW2CQ.js → server-CWI3TC7Y.js} +8 -8
  18. package/dist/esm/server-CWI3TC7Y.js.map +1 -0
  19. package/dist/esm/shared/operations/index.js +3 -3
  20. package/package.json +1 -1
  21. package/dist/esm/chunk-BAN7B27A.js.map +0 -1
  22. package/dist/esm/chunk-N3Q7WRL7.js.map +0 -1
  23. package/dist/esm/chunk-N4XFC6DI.js.map +0 -1
  24. package/dist/esm/chunk-NNNL6LXH.js.map +0 -1
  25. package/dist/esm/server-JQZYW2CQ.js.map +0 -1
  26. /package/dist/esm/{chunk-4VQ2CL7V.js.map → chunk-OS6MJ6OG.js.map} +0 -0
  27. /package/dist/esm/{chunk-FQL7T4UN.js.map → chunk-ZWMDIONA.js.map} +0 -0
  28. /package/dist/esm/{commands-QUGC5OKY.js.map → commands-MW5VLM2A.js.map} +0 -0
  29. /package/dist/esm/{fund-OG3VIN7O.js.map → fund-C24TLKK6.js.map} +0 -0
@@ -108709,1136 +108709,1135 @@ var tokenStringToNumber = (amount2, decimals2 = 6) => {
108709
108709
 
108710
108710
  // src/shared/balance.ts
108711
108711
  init_cjs_shims();
108712
-
108713
- // src/shared/utils.ts
108714
- init_cjs_shims();
108715
-
108716
- // ../../../node_modules/.pnpm/open@11.0.0/node_modules/open/index.js
108717
- init_cjs_shims();
108718
- var import_node_process8 = __toESM(require("process"), 1);
108719
- var import_node_path = __toESM(require("path"), 1);
108720
- var import_node_url = require("url");
108721
- var import_node_child_process7 = __toESM(require("child_process"), 1);
108722
- var import_promises4 = __toESM(require("fs/promises"), 1);
108723
-
108724
- // ../../../node_modules/.pnpm/wsl-utils@0.3.1/node_modules/wsl-utils/index.js
108725
- init_cjs_shims();
108726
- var import_node_util2 = require("util");
108727
- var import_node_child_process2 = __toESM(require("child_process"), 1);
108728
- var import_promises3 = __toESM(require("fs/promises"), 1);
108729
-
108730
- // ../../../node_modules/.pnpm/is-wsl@3.1.0/node_modules/is-wsl/index.js
108731
- init_cjs_shims();
108732
- var import_node_process2 = __toESM(require("process"), 1);
108733
- var import_node_os = __toESM(require("os"), 1);
108734
- var import_node_fs3 = __toESM(require("fs"), 1);
108735
-
108736
- // ../../../node_modules/.pnpm/is-inside-container@1.0.0/node_modules/is-inside-container/index.js
108737
- init_cjs_shims();
108738
- var import_node_fs2 = __toESM(require("fs"), 1);
108739
-
108740
- // ../../../node_modules/.pnpm/is-docker@3.0.0/node_modules/is-docker/index.js
108741
- init_cjs_shims();
108742
- var import_node_fs = __toESM(require("fs"), 1);
108743
- var isDockerCached;
108744
- function hasDockerEnv() {
108745
- try {
108746
- import_node_fs.default.statSync("/.dockerenv");
108747
- return true;
108748
- } catch {
108749
- return false;
108750
- }
108751
- }
108752
- function hasDockerCGroup() {
108753
- try {
108754
- return import_node_fs.default.readFileSync("/proc/self/cgroup", "utf8").includes("docker");
108755
- } catch {
108756
- return false;
108757
- }
108758
- }
108759
- function isDocker() {
108760
- if (isDockerCached === void 0) {
108761
- isDockerCached = hasDockerEnv() || hasDockerCGroup();
108762
- }
108763
- return isDockerCached;
108764
- }
108765
-
108766
- // ../../../node_modules/.pnpm/is-inside-container@1.0.0/node_modules/is-inside-container/index.js
108767
- var cachedResult;
108768
- var hasContainerEnv = () => {
108769
- try {
108770
- import_node_fs2.default.statSync("/run/.containerenv");
108771
- return true;
108772
- } catch {
108773
- return false;
108774
- }
108775
- };
108776
- function isInsideContainer() {
108777
- if (cachedResult === void 0) {
108778
- cachedResult = hasContainerEnv() || isDocker();
108779
- }
108780
- return cachedResult;
108781
- }
108782
-
108783
- // ../../../node_modules/.pnpm/is-wsl@3.1.0/node_modules/is-wsl/index.js
108784
- var isWsl = () => {
108785
- if (import_node_process2.default.platform !== "linux") {
108786
- return false;
108787
- }
108788
- if (import_node_os.default.release().toLowerCase().includes("microsoft")) {
108789
- if (isInsideContainer()) {
108790
- return false;
108791
- }
108792
- return true;
108793
- }
108794
- try {
108795
- return import_node_fs3.default.readFileSync("/proc/version", "utf8").toLowerCase().includes("microsoft") ? !isInsideContainer() : false;
108796
- } catch {
108797
- return false;
108798
- }
108799
- };
108800
- var is_wsl_default = import_node_process2.default.env.__IS_WSL_TEST__ ? isWsl : isWsl();
108801
-
108802
- // ../../../node_modules/.pnpm/powershell-utils@0.1.0/node_modules/powershell-utils/index.js
108803
- init_cjs_shims();
108804
- var import_node_process3 = __toESM(require("process"), 1);
108805
- var import_node_buffer = require("buffer");
108806
- var import_node_util = require("util");
108807
- var import_node_child_process = __toESM(require("child_process"), 1);
108808
- var import_promises2 = __toESM(require("fs/promises"), 1);
108809
- var execFile = (0, import_node_util.promisify)(import_node_child_process.default.execFile);
108810
- var powerShellPath = () => `${import_node_process3.default.env.SYSTEMROOT || import_node_process3.default.env.windir || String.raw`C:\Windows`}\\System32\\WindowsPowerShell\\v1.0\\powershell.exe`;
108811
- var executePowerShell = async (command, options = {}) => {
108812
- const {
108813
- powerShellPath: psPath,
108814
- ...execFileOptions
108815
- } = options;
108816
- const encodedCommand = executePowerShell.encodeCommand(command);
108817
- return execFile(
108818
- psPath ?? powerShellPath(),
108819
- [
108820
- ...executePowerShell.argumentsPrefix,
108821
- encodedCommand
108822
- ],
108823
- {
108824
- encoding: "utf8",
108825
- ...execFileOptions
108826
- }
108712
+ var X402SCAN_BASE = "https://x402scan.com";
108713
+ var getBalance3 = async ({
108714
+ address,
108715
+ surface: surface2
108716
+ }) => {
108717
+ const url3 = `${X402SCAN_BASE}/api/rpc/balance/${address}`;
108718
+ const res = await safeFetchJson(
108719
+ surface2,
108720
+ new Request(url3, {
108721
+ method: "GET",
108722
+ headers: {
108723
+ accept: "application/json"
108724
+ }
108725
+ }),
108726
+ zod_default.object({
108727
+ chain: zod_default.number(),
108728
+ balance: zod_default.coerce.number()
108729
+ })
108827
108730
  );
108731
+ return res;
108828
108732
  };
108829
- executePowerShell.argumentsPrefix = [
108830
- "-NoProfile",
108831
- "-NonInteractive",
108832
- "-ExecutionPolicy",
108833
- "Bypass",
108834
- "-EncodedCommand"
108835
- ];
108836
- executePowerShell.encodeCommand = (command) => import_node_buffer.Buffer.from(command, "utf16le").toString("base64");
108837
- executePowerShell.escapeArgument = (value) => `'${String(value).replaceAll("'", "''")}'`;
108838
108733
 
108839
- // ../../../node_modules/.pnpm/wsl-utils@0.3.1/node_modules/wsl-utils/utilities.js
108734
+ // src/shared/tempo-balance.ts
108840
108735
  init_cjs_shims();
108841
- function parseMountPointFromConfig(content) {
108842
- for (const line of content.split("\n")) {
108843
- if (/^\s*#/.test(line)) {
108844
- continue;
108845
- }
108846
- const match = /^\s*root\s*=\s*(?<mountPoint>"[^"]*"|'[^']*'|[^#]*)/.exec(line);
108847
- if (!match) {
108848
- continue;
108849
- }
108850
- return match.groups.mountPoint.trim().replaceAll(/^["']|["']$/g, "");
108736
+ var MPPSCAN_BASE = "https://mppscan.com";
108737
+ async function getTempoBalance({
108738
+ address,
108739
+ tokenAddress
108740
+ }) {
108741
+ const url3 = `${MPPSCAN_BASE}/api/balance/${address}`;
108742
+ const res = await fetch(url3, {
108743
+ method: "GET",
108744
+ headers: { accept: "application/json" }
108745
+ });
108746
+ if (!res.ok) {
108747
+ throw new Error(`mppscan balance request failed: ${res.status}`);
108851
108748
  }
108749
+ const data = await res.json();
108750
+ return {
108751
+ chainId: tempo.id,
108752
+ chainName: tempo.name,
108753
+ balance: BigInt(data.balance),
108754
+ tokenAddress
108755
+ };
108852
108756
  }
108853
108757
 
108854
- // ../../../node_modules/.pnpm/wsl-utils@0.3.1/node_modules/wsl-utils/index.js
108855
- var execFile2 = (0, import_node_util2.promisify)(import_node_child_process2.default.execFile);
108856
- var wslDrivesMountPoint = /* @__PURE__ */ (() => {
108857
- const defaultMountPoint = "/mnt/";
108858
- let mountPoint;
108859
- return async function() {
108860
- if (mountPoint) {
108861
- return mountPoint;
108758
+ // src/shared/operations/fetch-with-payment.ts
108759
+ function createFetchWithPayment(options) {
108760
+ const { surface: surface2, clients, paymentMethod, beforePayment, timeout } = options;
108761
+ return async (request) => {
108762
+ const clonedRequest = request.clone();
108763
+ const fallbackRequest = request.clone();
108764
+ const probeResult = await safeFetch(surface2, request, timeout);
108765
+ if (probeResult.isErr()) {
108766
+ return fetchErr(surface2, probeResult.error);
108862
108767
  }
108863
- const configFilePath = "/etc/wsl.conf";
108864
- let isConfigFileExists = false;
108865
- try {
108866
- await import_promises3.default.access(configFilePath, import_promises3.constants.F_OK);
108867
- isConfigFileExists = true;
108868
- } catch {
108768
+ if (probeResult.value.status !== 402) {
108769
+ return probeResult.andThen(
108770
+ (response2) => fetchOk({ response: response2, paymentInfo: null })
108771
+ );
108869
108772
  }
108870
- if (!isConfigFileExists) {
108871
- return defaultMountPoint;
108773
+ const response = probeResult.value;
108774
+ if (paymentMethod !== "auto") {
108775
+ if (paymentMethod === "mpp") {
108776
+ return handleMppPayment(surface2, response, clonedRequest, options);
108777
+ }
108778
+ return handleX402Payment(
108779
+ surface2,
108780
+ response,
108781
+ clonedRequest,
108782
+ clients.x402,
108783
+ beforePayment,
108784
+ timeout
108785
+ );
108872
108786
  }
108873
- const configContent = await import_promises3.default.readFile(configFilePath, { encoding: "utf8" });
108874
- const parsedMountPoint = parseMountPointFromConfig(configContent);
108875
- if (parsedMountPoint === void 0) {
108876
- return defaultMountPoint;
108787
+ const available = detectPaymentProtocols(response);
108788
+ let preferred;
108789
+ if (available.length === 1) {
108790
+ preferred = available[0];
108791
+ } else {
108792
+ preferred = await pickByBalance(surface2, response, options);
108877
108793
  }
108878
- mountPoint = parsedMountPoint;
108879
- mountPoint = mountPoint.endsWith("/") ? mountPoint : `${mountPoint}/`;
108880
- return mountPoint;
108794
+ const fallback = available.length > 1 ? preferred === "mpp" ? "x402" : "mpp" : null;
108795
+ const result = preferred === "mpp" ? await handleMppPayment(surface2, response, clonedRequest, options) : await handleX402Payment(
108796
+ surface2,
108797
+ response,
108798
+ clonedRequest,
108799
+ clients.x402,
108800
+ beforePayment,
108801
+ timeout
108802
+ );
108803
+ if (result.isErr() && fallback) {
108804
+ return fallback === "mpp" ? handleMppPayment(surface2, response, fallbackRequest, options) : handleX402Payment(
108805
+ surface2,
108806
+ response,
108807
+ fallbackRequest,
108808
+ clients.x402,
108809
+ beforePayment,
108810
+ timeout
108811
+ );
108812
+ }
108813
+ return result;
108881
108814
  };
108882
- })();
108883
- var powerShellPathFromWsl = async () => {
108884
- const mountPoint = await wslDrivesMountPoint();
108885
- return `${mountPoint}c/Windows/System32/WindowsPowerShell/v1.0/powershell.exe`;
108886
- };
108887
- var powerShellPath2 = is_wsl_default ? powerShellPathFromWsl : powerShellPath;
108888
- var canAccessPowerShellPromise;
108889
- var canAccessPowerShell = async () => {
108890
- canAccessPowerShellPromise ??= (async () => {
108891
- try {
108892
- const psPath = await powerShellPath2();
108893
- await import_promises3.default.access(psPath, import_promises3.constants.X_OK);
108894
- return true;
108895
- } catch {
108896
- return false;
108815
+ }
108816
+ async function pickByBalance(surface2, response, options) {
108817
+ const { account } = options;
108818
+ const x402BalanceResult = await resultFromPromise(
108819
+ "balance",
108820
+ surface2,
108821
+ getBalance3({
108822
+ address: account.address,
108823
+ surface: surface2
108824
+ }).then((r) => r.isOk() ? r.value.balance : 0),
108825
+ () => ({
108826
+ cause: "x402_balance",
108827
+ message: "Failed to get x402 balance"
108828
+ })
108829
+ );
108830
+ if (x402BalanceResult.isErr()) {
108831
+ log.debug("Balance comparison failed, defaulting to mpp");
108832
+ return "mpp";
108833
+ }
108834
+ const x402Balance = x402BalanceResult.value;
108835
+ let mppBalance = 0;
108836
+ const challengeResult = safeGetMppChallenge(surface2, response);
108837
+ if (challengeResult.isOk()) {
108838
+ const currency = challengeResult.value.request.currency;
108839
+ const decimals2 = challengeResult.value.request.decimals ?? 6;
108840
+ if (currency) {
108841
+ const tempoResult = await resultFromPromise(
108842
+ "tempo",
108843
+ surface2,
108844
+ getTempoBalance({
108845
+ address: account.address,
108846
+ tokenAddress: currency
108847
+ }),
108848
+ () => ({
108849
+ cause: "tempo_balance",
108850
+ message: "Tempo balance check failed"
108851
+ })
108852
+ );
108853
+ if (tempoResult.isOk()) {
108854
+ mppBalance = Number(formatUnits(tempoResult.value.balance, decimals2));
108855
+ }
108897
108856
  }
108898
- })();
108899
- return canAccessPowerShellPromise;
108900
- };
108901
- var wslDefaultBrowser = async () => {
108902
- const psPath = await powerShellPath2();
108903
- const command = String.raw`(Get-ItemProperty -Path "HKCU:\Software\Microsoft\Windows\Shell\Associations\UrlAssociations\http\UserChoice").ProgId`;
108904
- const { stdout } = await executePowerShell(command, { powerShellPath: psPath });
108905
- return stdout.trim();
108906
- };
108907
- var convertWslPathToWindows = async (path2) => {
108908
- if (/^[a-z]+:\/\//i.test(path2)) {
108909
- return path2;
108910
108857
  }
108911
- try {
108912
- const { stdout } = await execFile2("wslpath", ["-aw", path2], { encoding: "utf8" });
108913
- return stdout.trim();
108914
- } catch {
108915
- return path2;
108858
+ log.info(`Protocol selection \u2014 x402: $${x402Balance}, mpp: $${mppBalance}`);
108859
+ return x402Balance >= mppBalance ? "x402" : "mpp";
108860
+ }
108861
+ async function handleX402Payment(surface2, response, clonedRequest, client, beforePayment, timeout) {
108862
+ const paymentRequiredResult = await safeGetPaymentRequired(
108863
+ surface2,
108864
+ client,
108865
+ response
108866
+ );
108867
+ if (paymentRequiredResult.isErr()) {
108868
+ return paymentRequiredResult;
108916
108869
  }
108917
- };
108918
-
108919
- // ../../../node_modules/.pnpm/define-lazy-prop@3.0.0/node_modules/define-lazy-prop/index.js
108920
- init_cjs_shims();
108921
- function defineLazyProperty(object3, propertyName, valueGetter) {
108922
- const define = (value) => Object.defineProperty(object3, propertyName, { value, enumerable: true, writable: true });
108923
- Object.defineProperty(object3, propertyName, {
108924
- configurable: true,
108925
- enumerable: true,
108926
- get() {
108927
- const result = valueGetter();
108928
- define(result);
108929
- return result;
108930
- },
108931
- set(value) {
108932
- define(value);
108870
+ const paymentRequired = paymentRequiredResult.value;
108871
+ if (beforePayment) {
108872
+ const accept = paymentRequired.accepts[0];
108873
+ if (accept) {
108874
+ const amount2 = tokenStringToNumber(accept.amount);
108875
+ const hookResult = await resultFromPromise(
108876
+ "x402",
108877
+ surface2,
108878
+ beforePayment({
108879
+ protocol: "x402",
108880
+ amount: amount2,
108881
+ currency: "USDC",
108882
+ network: accept.network
108883
+ }),
108884
+ (e) => ({
108885
+ cause: "payment_already_attempted",
108886
+ message: e instanceof Error ? e.message : "Before-payment hook failed"
108887
+ })
108888
+ );
108889
+ if (hookResult.isErr()) {
108890
+ return x402Err(surface2, hookResult.error);
108891
+ }
108933
108892
  }
108934
- });
108935
- return object3;
108936
- }
108937
-
108938
- // ../../../node_modules/.pnpm/default-browser@5.5.0/node_modules/default-browser/index.js
108939
- init_cjs_shims();
108940
- var import_node_util6 = require("util");
108941
- var import_node_process6 = __toESM(require("process"), 1);
108942
- var import_node_child_process6 = require("child_process");
108943
-
108944
- // ../../../node_modules/.pnpm/default-browser-id@5.0.1/node_modules/default-browser-id/index.js
108945
- init_cjs_shims();
108946
- var import_node_util3 = require("util");
108947
- var import_node_process4 = __toESM(require("process"), 1);
108948
- var import_node_child_process3 = require("child_process");
108949
- var execFileAsync = (0, import_node_util3.promisify)(import_node_child_process3.execFile);
108950
- async function defaultBrowserId() {
108951
- if (import_node_process4.default.platform !== "darwin") {
108952
- throw new Error("macOS only");
108953
108893
  }
108954
- const { stdout } = await execFileAsync("defaults", ["read", "com.apple.LaunchServices/com.apple.launchservices.secure", "LSHandlers"]);
108955
- const match = /LSHandlerRoleAll = "(?!-)(?<id>[^"]+?)";\s+?LSHandlerURLScheme = (?:http|https);/.exec(stdout);
108956
- const browserId = match?.groups.id ?? "com.apple.Safari";
108957
- if (browserId === "com.apple.safari") {
108958
- return "com.apple.Safari";
108894
+ const paymentPayloadResult = await safeCreatePaymentPayload(
108895
+ surface2,
108896
+ client,
108897
+ paymentRequired
108898
+ );
108899
+ if (paymentPayloadResult.isErr()) {
108900
+ return paymentPayloadResult;
108959
108901
  }
108960
- return browserId;
108961
- }
108962
-
108963
- // ../../../node_modules/.pnpm/bundle-name@4.1.0/node_modules/bundle-name/index.js
108964
- init_cjs_shims();
108965
-
108966
- // ../../../node_modules/.pnpm/run-applescript@7.1.0/node_modules/run-applescript/index.js
108967
- init_cjs_shims();
108968
- var import_node_process5 = __toESM(require("process"), 1);
108969
- var import_node_util4 = require("util");
108970
- var import_node_child_process4 = require("child_process");
108971
- var execFileAsync2 = (0, import_node_util4.promisify)(import_node_child_process4.execFile);
108972
- async function runAppleScript(script, { humanReadableOutput = true, signal } = {}) {
108973
- if (import_node_process5.default.platform !== "darwin") {
108974
- throw new Error("macOS only");
108902
+ const paymentPayload = paymentPayloadResult.value;
108903
+ const paymentHeaders = client.encodePaymentSignatureHeader(paymentPayload);
108904
+ if (clonedRequest.headers.has("PAYMENT-SIGNATURE") || clonedRequest.headers.has("X-PAYMENT")) {
108905
+ return x402Err(surface2, {
108906
+ cause: "payment_already_attempted",
108907
+ message: "Payment already attempted"
108908
+ });
108975
108909
  }
108976
- const outputArguments = humanReadableOutput ? [] : ["-ss"];
108977
- const execOptions = {};
108978
- if (signal) {
108979
- execOptions.signal = signal;
108910
+ for (const [key, value] of Object.entries(paymentHeaders)) {
108911
+ clonedRequest.headers.set(key, value);
108980
108912
  }
108981
- const { stdout } = await execFileAsync2("osascript", ["-e", script, outputArguments], execOptions);
108982
- return stdout.trim();
108983
- }
108984
-
108985
- // ../../../node_modules/.pnpm/bundle-name@4.1.0/node_modules/bundle-name/index.js
108986
- async function bundleName(bundleId) {
108987
- return runAppleScript(`tell application "Finder" to set app_path to application file id "${bundleId}" as string
108988
- tell application "System Events" to get value of property list item "CFBundleName" of property list file (app_path & ":Contents:Info.plist")`);
108913
+ clonedRequest.headers.set(
108914
+ "Access-Control-Expose-Headers",
108915
+ "PAYMENT-RESPONSE,X-PAYMENT-RESPONSE"
108916
+ );
108917
+ return await safeFetch(surface2, clonedRequest, timeout).andThen(
108918
+ (paidResponse) => {
108919
+ const settlementResult = safeGetPaymentSettlement(
108920
+ surface2,
108921
+ client,
108922
+ paidResponse
108923
+ );
108924
+ return x402Ok({
108925
+ response: paidResponse,
108926
+ paymentInfo: {
108927
+ protocol: "x402",
108928
+ price: tokenStringToNumber(
108929
+ paymentPayload.accepted.amount
108930
+ ).toLocaleString("en-US", {
108931
+ style: "currency",
108932
+ currency: "USD"
108933
+ }),
108934
+ ...settlementResult.isOk() ? {
108935
+ payment: {
108936
+ success: settlementResult.value.success,
108937
+ transactionHash: settlementResult.value.transaction
108938
+ }
108939
+ } : {}
108940
+ }
108941
+ });
108942
+ }
108943
+ );
108989
108944
  }
108990
-
108991
- // ../../../node_modules/.pnpm/default-browser@5.5.0/node_modules/default-browser/windows.js
108992
- init_cjs_shims();
108993
- var import_node_util5 = require("util");
108994
- var import_node_child_process5 = require("child_process");
108995
- var execFileAsync3 = (0, import_node_util5.promisify)(import_node_child_process5.execFile);
108996
- var windowsBrowserProgIds = {
108997
- MSEdgeHTM: { name: "Edge", id: "com.microsoft.edge" },
108998
- // The missing `L` is correct.
108999
- MSEdgeBHTML: { name: "Edge Beta", id: "com.microsoft.edge.beta" },
109000
- MSEdgeDHTML: { name: "Edge Dev", id: "com.microsoft.edge.dev" },
109001
- AppXq0fevzme2pys62n3e0fbqa7peapykr8v: { name: "Edge", id: "com.microsoft.edge.old" },
109002
- ChromeHTML: { name: "Chrome", id: "com.google.chrome" },
109003
- ChromeBHTML: { name: "Chrome Beta", id: "com.google.chrome.beta" },
109004
- ChromeDHTML: { name: "Chrome Dev", id: "com.google.chrome.dev" },
109005
- ChromiumHTM: { name: "Chromium", id: "org.chromium.Chromium" },
109006
- BraveHTML: { name: "Brave", id: "com.brave.Browser" },
109007
- BraveBHTML: { name: "Brave Beta", id: "com.brave.Browser.beta" },
109008
- BraveDHTML: { name: "Brave Dev", id: "com.brave.Browser.dev" },
109009
- BraveSSHTM: { name: "Brave Nightly", id: "com.brave.Browser.nightly" },
109010
- FirefoxURL: { name: "Firefox", id: "org.mozilla.firefox" },
109011
- OperaStable: { name: "Opera", id: "com.operasoftware.Opera" },
109012
- VivaldiHTM: { name: "Vivaldi", id: "com.vivaldi.Vivaldi" },
109013
- "IE.HTTP": { name: "Internet Explorer", id: "com.microsoft.ie" }
109014
- };
109015
- var _windowsBrowserProgIdMap = new Map(Object.entries(windowsBrowserProgIds));
109016
- var UnknownBrowserError = class extends Error {
109017
- };
109018
- async function defaultBrowser(_execFileAsync = execFileAsync3) {
109019
- const { stdout } = await _execFileAsync("reg", [
109020
- "QUERY",
109021
- " HKEY_CURRENT_USER\\Software\\Microsoft\\Windows\\Shell\\Associations\\UrlAssociations\\http\\UserChoice",
109022
- "/v",
109023
- "ProgId"
109024
- ]);
109025
- const match = /ProgId\s*REG_SZ\s*(?<id>\S+)/.exec(stdout);
109026
- if (!match) {
109027
- throw new UnknownBrowserError(`Cannot find Windows browser in stdout: ${JSON.stringify(stdout)}`);
108945
+ async function handleMppPayment(surface2, response, clonedRequest, options) {
108946
+ const { clients, beforePayment, timeout } = options;
108947
+ const mppxClient = clients.mpp;
108948
+ if (clonedRequest.headers.has("Authorization")) {
108949
+ return mppErr(surface2, {
108950
+ cause: "mpp_payment_already_attempted",
108951
+ message: "MPP payment already attempted"
108952
+ });
109028
108953
  }
109029
- const { id } = match.groups;
109030
- const dotIndex = id.lastIndexOf(".");
109031
- const hyphenIndex = id.lastIndexOf("-");
109032
- const baseIdByDot = dotIndex === -1 ? void 0 : id.slice(0, dotIndex);
109033
- const baseIdByHyphen = hyphenIndex === -1 ? void 0 : id.slice(0, hyphenIndex);
109034
- return windowsBrowserProgIds[id] ?? windowsBrowserProgIds[baseIdByDot] ?? windowsBrowserProgIds[baseIdByHyphen] ?? { name: id, id };
109035
- }
109036
-
109037
- // ../../../node_modules/.pnpm/default-browser@5.5.0/node_modules/default-browser/index.js
109038
- var execFileAsync4 = (0, import_node_util6.promisify)(import_node_child_process6.execFile);
109039
- var titleize = (string6) => string6.toLowerCase().replaceAll(/(?:^|\s|-)\S/g, (x) => x.toUpperCase());
109040
- async function defaultBrowser2() {
109041
- if (import_node_process6.default.platform === "darwin") {
109042
- const id = await defaultBrowserId();
109043
- const name = await bundleName(id);
109044
- return { name, id };
108954
+ const challengeResult = safeGetMppChallenge(surface2, response);
108955
+ if (challengeResult.isErr()) {
108956
+ return challengeResult;
109045
108957
  }
109046
- if (import_node_process6.default.platform === "linux") {
109047
- const { stdout } = await execFileAsync4("xdg-mime", ["query", "default", "x-scheme-handler/http"]);
109048
- const id = stdout.trim();
109049
- const name = titleize(id.replace(/.desktop$/, "").replace("-", " "));
109050
- return { name, id };
108958
+ const challenge2 = challengeResult.value;
108959
+ const amount2 = challenge2.request.amount;
108960
+ const decimals2 = challenge2.request.decimals ?? 6;
108961
+ const currency = challenge2.request.currency;
108962
+ if (beforePayment && amount2 && currency) {
108963
+ const numericAmount = Number(formatUnits(BigInt(amount2), decimals2));
108964
+ const hookResult = await resultFromPromise(
108965
+ "mpp",
108966
+ surface2,
108967
+ beforePayment({
108968
+ protocol: "mpp",
108969
+ amount: numericAmount,
108970
+ currency,
108971
+ network: `tempo:${challenge2.method}`
108972
+ }),
108973
+ (e) => ({
108974
+ cause: "mpp_payment_already_attempted",
108975
+ message: e instanceof Error ? e.message : "Before-payment hook failed"
108976
+ })
108977
+ );
108978
+ if (hookResult.isErr()) {
108979
+ return mppErr(surface2, hookResult.error);
108980
+ }
109051
108981
  }
109052
- if (import_node_process6.default.platform === "win32") {
109053
- return defaultBrowser();
108982
+ const credentialResult = await safeCreateMppCredential(
108983
+ surface2,
108984
+ mppxClient,
108985
+ response
108986
+ );
108987
+ if (credentialResult.isErr()) {
108988
+ return credentialResult;
109054
108989
  }
109055
- throw new Error("Only macOS, Linux, and Windows are supported");
108990
+ const credential = credentialResult.value;
108991
+ clonedRequest.headers.set("Authorization", credential);
108992
+ return await safeFetch(surface2, clonedRequest, timeout).andThen(
108993
+ (paidResponse) => {
108994
+ const receiptResult = safeGetMppReceipt(surface2, paidResponse);
108995
+ const priceDisplay = amount2 ? Number(formatUnits(BigInt(amount2), decimals2)).toLocaleString(
108996
+ "en-US",
108997
+ {
108998
+ style: "currency",
108999
+ currency: "USD"
109000
+ }
109001
+ ) : void 0;
109002
+ return mppOk({
109003
+ response: paidResponse,
109004
+ paymentInfo: {
109005
+ protocol: "mpp",
109006
+ ...priceDisplay ? { price: priceDisplay } : {},
109007
+ ...receiptResult.isOk() ? {
109008
+ payment: {
109009
+ success: true,
109010
+ transactionHash: receiptResult.value.reference
109011
+ }
109012
+ } : {}
109013
+ }
109014
+ });
109015
+ }
109016
+ );
109056
109017
  }
109057
109018
 
109058
- // ../../../node_modules/.pnpm/is-in-ssh@1.0.0/node_modules/is-in-ssh/index.js
109019
+ // src/server/tools/response/index.ts
109059
109020
  init_cjs_shims();
109060
- var import_node_process7 = __toESM(require("process"), 1);
109061
- var isInSsh = Boolean(import_node_process7.default.env.SSH_CONNECTION || import_node_process7.default.env.SSH_CLIENT || import_node_process7.default.env.SSH_TTY);
109062
- var is_in_ssh_default = isInSsh;
109063
109021
 
109064
- // ../../../node_modules/.pnpm/open@11.0.0/node_modules/open/index.js
109065
- var fallbackAttemptSymbol = /* @__PURE__ */ Symbol("fallbackAttempt");
109066
- var __dirname2 = importMetaUrl ? import_node_path.default.dirname((0, import_node_url.fileURLToPath)(importMetaUrl)) : "";
109067
- var localXdgOpenPath = import_node_path.default.join(__dirname2, "xdg-open");
109068
- var { platform, arch } = import_node_process8.default;
109069
- var tryEachApp = async (apps2, opener) => {
109070
- if (apps2.length === 0) {
109071
- return;
109022
+ // src/server/tools/response/success.ts
109023
+ init_cjs_shims();
109024
+
109025
+ // src/shared/neverthrow/json/index.ts
109026
+ init_cjs_shims();
109027
+ var type3 = "json";
109028
+ var jsonErr = (surface2, error48) => {
109029
+ return err2(type3, surface2, error48);
109030
+ };
109031
+ var safeStringifyJson = (surface2, value) => {
109032
+ return resultFromThrowable(
109033
+ type3,
109034
+ surface2,
109035
+ () => JSON.stringify(value, null, 2),
109036
+ () => ({
109037
+ cause: "stringify",
109038
+ message: "Could not stringify JSON"
109039
+ })
109040
+ );
109041
+ };
109042
+ var toJsonObject = (value) => JSON.parse(JSON.stringify(value));
109043
+ var safeParseJson = (surface2, value) => {
109044
+ return resultFromThrowable(
109045
+ type3,
109046
+ surface2,
109047
+ () => JSON.parse(value),
109048
+ (e) => ({
109049
+ cause: "parse",
109050
+ message: e instanceof Error ? e.message : "Could not parse JSON"
109051
+ })
109052
+ );
109053
+ };
109054
+
109055
+ // src/server/tools/response/error.ts
109056
+ init_cjs_shims();
109057
+
109058
+ // src/server/tools/response/lib.ts
109059
+ init_cjs_shims();
109060
+ var parsedResponseToToolContentPart = (data) => {
109061
+ switch (data.type) {
109062
+ case "json":
109063
+ return {
109064
+ type: "text",
109065
+ text: JSON.stringify(data.data)
109066
+ };
109067
+ case "image":
109068
+ return {
109069
+ type: "image",
109070
+ mimeType: data.mimeType,
109071
+ data: Buffer.from(data.data).toString("base64")
109072
+ };
109073
+ case "audio":
109074
+ return {
109075
+ type: "audio",
109076
+ mimeType: data.mimeType,
109077
+ data: Buffer.from(data.data).toString("base64")
109078
+ };
109079
+ case "text":
109080
+ return { type: "text", text: data.data };
109081
+ default:
109082
+ return {
109083
+ type: "text",
109084
+ text: `Unsupported response type: ${data.type}`
109085
+ };
109072
109086
  }
109073
- const errors = [];
109074
- for (const app of apps2) {
109075
- try {
109076
- return await opener(app);
109077
- } catch (error48) {
109078
- errors.push(error48);
109087
+ };
109088
+
109089
+ // src/server/tools/response/error.ts
109090
+ var buildMcpError = (content) => {
109091
+ return {
109092
+ content,
109093
+ isError: true
109094
+ };
109095
+ };
109096
+ var mcpErrorJson = (error48) => {
109097
+ return safeStringifyJson("mcp-error-json", error48).match(
109098
+ (success3) => buildMcpError([{ type: "text", text: success3 }]),
109099
+ (error49) => buildMcpError([
109100
+ { type: "text", text: JSON.stringify(error49, null, 2) }
109101
+ ])
109102
+ );
109103
+ };
109104
+ var mcpError = async (err3) => {
109105
+ const { error: error48 } = err3;
109106
+ if (isFetchError(error48)) {
109107
+ switch (error48.cause) {
109108
+ case "network":
109109
+ case "parse":
109110
+ return mcpErrorJson({ ...error48 });
109111
+ case "http":
109112
+ const { response, ...rest } = error48;
109113
+ const parseResponseResult = await safeParseResponse(
109114
+ "mcp-error-fetch-parse-response",
109115
+ response
109116
+ );
109117
+ const httpContent = [
109118
+ { type: "text", text: JSON.stringify(rest, null, 2) },
109119
+ ...parseResponseResult.match(
109120
+ (success3) => [parsedResponseToToolContentPart(success3)],
109121
+ () => []
109122
+ )
109123
+ ];
109124
+ return { content: httpContent };
109079
109125
  }
109080
109126
  }
109081
- throw new AggregateError(errors, "Failed to open in all supported apps");
109127
+ return mcpErrorJson({ ...error48 });
109082
109128
  };
109083
- var baseOpen = async (options) => {
109084
- options = {
109085
- wait: false,
109086
- background: false,
109087
- newInstance: false,
109088
- allowNonzeroExitCode: false,
109089
- ...options
109129
+ var mcpErrorFetch = async (surface2, response) => {
109130
+ return mcpError(fetchHttpErr(surface2, response));
109131
+ };
109132
+
109133
+ // src/server/tools/response/success.ts
109134
+ var buildMcpSuccess = (content) => {
109135
+ return {
109136
+ content
109090
109137
  };
109091
- const isFallbackAttempt = options[fallbackAttemptSymbol] === true;
109092
- delete options[fallbackAttemptSymbol];
109093
- if (Array.isArray(options.app)) {
109094
- return tryEachApp(options.app, (singleApp) => baseOpen({
109095
- ...options,
109096
- app: singleApp,
109097
- [fallbackAttemptSymbol]: true
109098
- }));
109099
- }
109100
- let { name: app, arguments: appArguments = [] } = options.app ?? {};
109101
- appArguments = [...appArguments];
109102
- if (Array.isArray(app)) {
109103
- return tryEachApp(app, (appName) => baseOpen({
109104
- ...options,
109105
- app: {
109106
- name: appName,
109107
- arguments: appArguments
109108
- },
109109
- [fallbackAttemptSymbol]: true
109110
- }));
109111
- }
109112
- if (app === "browser" || app === "browserPrivate") {
109113
- const ids = {
109114
- "com.google.chrome": "chrome",
109115
- "google-chrome.desktop": "chrome",
109116
- "com.brave.browser": "brave",
109117
- "org.mozilla.firefox": "firefox",
109118
- "firefox.desktop": "firefox",
109119
- "com.microsoft.msedge": "edge",
109120
- "com.microsoft.edge": "edge",
109121
- "com.microsoft.edgemac": "edge",
109122
- "microsoft-edge.desktop": "edge",
109123
- "com.apple.safari": "safari"
109124
- };
109125
- const flags = {
109126
- chrome: "--incognito",
109127
- brave: "--incognito",
109128
- firefox: "--private-window",
109129
- edge: "--inPrivate"
109130
- // Safari doesn't support private mode via command line
109131
- };
109132
- let browser;
109133
- if (is_wsl_default) {
109134
- const progId = await wslDefaultBrowser();
109135
- const browserInfo = _windowsBrowserProgIdMap.get(progId);
109136
- browser = browserInfo ?? {};
109137
- } else {
109138
- browser = await defaultBrowser2();
109139
- }
109140
- if (browser.id in ids) {
109141
- const browserName = ids[browser.id.toLowerCase()];
109142
- if (app === "browserPrivate") {
109143
- if (browserName === "safari") {
109144
- throw new Error("Safari doesn't support opening in private mode via command line");
109145
- }
109146
- appArguments.push(flags[browserName]);
109147
- }
109148
- return baseOpen({
109149
- ...options,
109150
- app: {
109151
- name: apps[browserName],
109152
- arguments: appArguments
109153
- }
109154
- });
109138
+ };
109139
+ var mcpSuccessJson = (data) => {
109140
+ return safeStringifyJson("mcp-success-text", data).match(
109141
+ (success3) => buildMcpSuccess([{ type: "text", text: success3 }]),
109142
+ (error48) => mcpErrorJson(error48)
109143
+ );
109144
+ };
109145
+ var mcpSuccessStructuredJson = (data) => {
109146
+ return safeStringifyJson("mcp-success-structured", data).match(
109147
+ (success3) => ({
109148
+ content: [{ type: "text", text: success3 }],
109149
+ structuredContent: data
109150
+ }),
109151
+ (error48) => mcpErrorJson(error48)
109152
+ );
109153
+ };
109154
+ var mcpSuccessResponse = (data, extra) => {
109155
+ const parsedExtra = extra ? safeStringifyJson("mcp-success-extra", extra).match(
109156
+ (success3) => success3,
109157
+ () => void 0
109158
+ ) : void 0;
109159
+ return buildMcpSuccess([
109160
+ parsedResponseToToolContentPart(data),
109161
+ ...parsedExtra ? [{ type: "text", text: parsedExtra }] : []
109162
+ ]);
109163
+ };
109164
+
109165
+ // src/server/tools/lib/request.ts
109166
+ init_cjs_shims();
109167
+ var requestSchema = zod_default.object({
109168
+ url: zod_default.url().describe("The endpoint URL"),
109169
+ method: zod_default.enum(["GET", "POST", "PUT", "DELETE", "PATCH"]).optional().describe("HTTP method. Defaults to GET for fetch operations."),
109170
+ body: zod_default.unknown().optional().describe("Request body for POST/PUT/PATCH methods"),
109171
+ headers: zod_default.record(zod_default.string(), zod_default.string()).optional().describe("Additional headers to include").default({}),
109172
+ timeout: zod_default.number().int().positive().optional().describe("Request timeout in milliseconds")
109173
+ });
109174
+ var buildRequest2 = ({
109175
+ input,
109176
+ address,
109177
+ sessionId,
109178
+ provider
109179
+ }) => {
109180
+ return new Request(input.url, {
109181
+ method: input.method ?? "GET",
109182
+ body: input.body ? typeof input.body === "string" ? input.body : JSON.stringify(input.body) : void 0,
109183
+ headers: {
109184
+ ...input.body ? { "Content-Type": "application/json" } : {},
109185
+ ...input.headers,
109186
+ ...address ? { "X-Wallet-Address": address, "X-Client-ID": provider } : {},
109187
+ ...sessionId ? { "X-Session-ID": sessionId } : {}
109155
109188
  }
109156
- throw new Error(`${browser.name} is not supported as a default browser`);
109189
+ });
109190
+ };
109191
+
109192
+ // src/server/tools/lib/check-balance.ts
109193
+ init_cjs_shims();
109194
+
109195
+ // src/shared/utils.ts
109196
+ init_cjs_shims();
109197
+
109198
+ // ../../../node_modules/.pnpm/open@11.0.0/node_modules/open/index.js
109199
+ init_cjs_shims();
109200
+ var import_node_process8 = __toESM(require("process"), 1);
109201
+ var import_node_path = __toESM(require("path"), 1);
109202
+ var import_node_url = require("url");
109203
+ var import_node_child_process7 = __toESM(require("child_process"), 1);
109204
+ var import_promises4 = __toESM(require("fs/promises"), 1);
109205
+
109206
+ // ../../../node_modules/.pnpm/wsl-utils@0.3.1/node_modules/wsl-utils/index.js
109207
+ init_cjs_shims();
109208
+ var import_node_util2 = require("util");
109209
+ var import_node_child_process2 = __toESM(require("child_process"), 1);
109210
+ var import_promises3 = __toESM(require("fs/promises"), 1);
109211
+
109212
+ // ../../../node_modules/.pnpm/is-wsl@3.1.0/node_modules/is-wsl/index.js
109213
+ init_cjs_shims();
109214
+ var import_node_process2 = __toESM(require("process"), 1);
109215
+ var import_node_os = __toESM(require("os"), 1);
109216
+ var import_node_fs3 = __toESM(require("fs"), 1);
109217
+
109218
+ // ../../../node_modules/.pnpm/is-inside-container@1.0.0/node_modules/is-inside-container/index.js
109219
+ init_cjs_shims();
109220
+ var import_node_fs2 = __toESM(require("fs"), 1);
109221
+
109222
+ // ../../../node_modules/.pnpm/is-docker@3.0.0/node_modules/is-docker/index.js
109223
+ init_cjs_shims();
109224
+ var import_node_fs = __toESM(require("fs"), 1);
109225
+ var isDockerCached;
109226
+ function hasDockerEnv() {
109227
+ try {
109228
+ import_node_fs.default.statSync("/.dockerenv");
109229
+ return true;
109230
+ } catch {
109231
+ return false;
109157
109232
  }
109158
- let command;
109159
- const cliArguments = [];
109160
- const childProcessOptions = {};
109161
- let shouldUseWindowsInWsl = false;
109162
- if (is_wsl_default && !isInsideContainer() && !is_in_ssh_default && !app) {
109163
- shouldUseWindowsInWsl = await canAccessPowerShell();
109233
+ }
109234
+ function hasDockerCGroup() {
109235
+ try {
109236
+ return import_node_fs.default.readFileSync("/proc/self/cgroup", "utf8").includes("docker");
109237
+ } catch {
109238
+ return false;
109164
109239
  }
109165
- if (platform === "darwin") {
109166
- command = "open";
109167
- if (options.wait) {
109168
- cliArguments.push("--wait-apps");
109169
- }
109170
- if (options.background) {
109171
- cliArguments.push("--background");
109172
- }
109173
- if (options.newInstance) {
109174
- cliArguments.push("--new");
109175
- }
109176
- if (app) {
109177
- cliArguments.push("-a", app);
109178
- }
109179
- } else if (platform === "win32" || shouldUseWindowsInWsl) {
109180
- command = await powerShellPath2();
109181
- cliArguments.push(...executePowerShell.argumentsPrefix);
109182
- if (!is_wsl_default) {
109183
- childProcessOptions.windowsVerbatimArguments = true;
109184
- }
109185
- if (is_wsl_default && options.target) {
109186
- options.target = await convertWslPathToWindows(options.target);
109187
- }
109188
- const encodedArguments = ["$ProgressPreference = 'SilentlyContinue';", "Start"];
109189
- if (options.wait) {
109190
- encodedArguments.push("-Wait");
109240
+ }
109241
+ function isDocker() {
109242
+ if (isDockerCached === void 0) {
109243
+ isDockerCached = hasDockerEnv() || hasDockerCGroup();
109244
+ }
109245
+ return isDockerCached;
109246
+ }
109247
+
109248
+ // ../../../node_modules/.pnpm/is-inside-container@1.0.0/node_modules/is-inside-container/index.js
109249
+ var cachedResult;
109250
+ var hasContainerEnv = () => {
109251
+ try {
109252
+ import_node_fs2.default.statSync("/run/.containerenv");
109253
+ return true;
109254
+ } catch {
109255
+ return false;
109256
+ }
109257
+ };
109258
+ function isInsideContainer() {
109259
+ if (cachedResult === void 0) {
109260
+ cachedResult = hasContainerEnv() || isDocker();
109261
+ }
109262
+ return cachedResult;
109263
+ }
109264
+
109265
+ // ../../../node_modules/.pnpm/is-wsl@3.1.0/node_modules/is-wsl/index.js
109266
+ var isWsl = () => {
109267
+ if (import_node_process2.default.platform !== "linux") {
109268
+ return false;
109269
+ }
109270
+ if (import_node_os.default.release().toLowerCase().includes("microsoft")) {
109271
+ if (isInsideContainer()) {
109272
+ return false;
109191
109273
  }
109192
- if (app) {
109193
- encodedArguments.push(executePowerShell.escapeArgument(app));
109194
- if (options.target) {
109195
- appArguments.push(options.target);
109196
- }
109197
- } else if (options.target) {
109198
- encodedArguments.push(executePowerShell.escapeArgument(options.target));
109274
+ return true;
109275
+ }
109276
+ try {
109277
+ return import_node_fs3.default.readFileSync("/proc/version", "utf8").toLowerCase().includes("microsoft") ? !isInsideContainer() : false;
109278
+ } catch {
109279
+ return false;
109280
+ }
109281
+ };
109282
+ var is_wsl_default = import_node_process2.default.env.__IS_WSL_TEST__ ? isWsl : isWsl();
109283
+
109284
+ // ../../../node_modules/.pnpm/powershell-utils@0.1.0/node_modules/powershell-utils/index.js
109285
+ init_cjs_shims();
109286
+ var import_node_process3 = __toESM(require("process"), 1);
109287
+ var import_node_buffer = require("buffer");
109288
+ var import_node_util = require("util");
109289
+ var import_node_child_process = __toESM(require("child_process"), 1);
109290
+ var import_promises2 = __toESM(require("fs/promises"), 1);
109291
+ var execFile = (0, import_node_util.promisify)(import_node_child_process.default.execFile);
109292
+ var powerShellPath = () => `${import_node_process3.default.env.SYSTEMROOT || import_node_process3.default.env.windir || String.raw`C:\Windows`}\\System32\\WindowsPowerShell\\v1.0\\powershell.exe`;
109293
+ var executePowerShell = async (command, options = {}) => {
109294
+ const {
109295
+ powerShellPath: psPath,
109296
+ ...execFileOptions
109297
+ } = options;
109298
+ const encodedCommand = executePowerShell.encodeCommand(command);
109299
+ return execFile(
109300
+ psPath ?? powerShellPath(),
109301
+ [
109302
+ ...executePowerShell.argumentsPrefix,
109303
+ encodedCommand
109304
+ ],
109305
+ {
109306
+ encoding: "utf8",
109307
+ ...execFileOptions
109199
109308
  }
109200
- if (appArguments.length > 0) {
109201
- appArguments = appArguments.map((argument) => executePowerShell.escapeArgument(argument));
109202
- encodedArguments.push("-ArgumentList", appArguments.join(","));
109309
+ );
109310
+ };
109311
+ executePowerShell.argumentsPrefix = [
109312
+ "-NoProfile",
109313
+ "-NonInteractive",
109314
+ "-ExecutionPolicy",
109315
+ "Bypass",
109316
+ "-EncodedCommand"
109317
+ ];
109318
+ executePowerShell.encodeCommand = (command) => import_node_buffer.Buffer.from(command, "utf16le").toString("base64");
109319
+ executePowerShell.escapeArgument = (value) => `'${String(value).replaceAll("'", "''")}'`;
109320
+
109321
+ // ../../../node_modules/.pnpm/wsl-utils@0.3.1/node_modules/wsl-utils/utilities.js
109322
+ init_cjs_shims();
109323
+ function parseMountPointFromConfig(content) {
109324
+ for (const line of content.split("\n")) {
109325
+ if (/^\s*#/.test(line)) {
109326
+ continue;
109203
109327
  }
109204
- options.target = executePowerShell.encodeCommand(encodedArguments.join(" "));
109205
- if (!options.wait) {
109206
- childProcessOptions.stdio = "ignore";
109328
+ const match = /^\s*root\s*=\s*(?<mountPoint>"[^"]*"|'[^']*'|[^#]*)/.exec(line);
109329
+ if (!match) {
109330
+ continue;
109207
109331
  }
109208
- } else {
109209
- if (app) {
109210
- command = app;
109211
- } else {
109212
- const isBundled = !__dirname2 || __dirname2 === "/";
109213
- let exeLocalXdgOpen = false;
109214
- try {
109215
- await import_promises4.default.access(localXdgOpenPath, import_promises4.constants.X_OK);
109216
- exeLocalXdgOpen = true;
109217
- } catch {
109218
- }
109219
- const useSystemXdgOpen = import_node_process8.default.versions.electron ?? (platform === "android" || isBundled || !exeLocalXdgOpen);
109220
- command = useSystemXdgOpen ? "xdg-open" : localXdgOpenPath;
109332
+ return match.groups.mountPoint.trim().replaceAll(/^["']|["']$/g, "");
109333
+ }
109334
+ }
109335
+
109336
+ // ../../../node_modules/.pnpm/wsl-utils@0.3.1/node_modules/wsl-utils/index.js
109337
+ var execFile2 = (0, import_node_util2.promisify)(import_node_child_process2.default.execFile);
109338
+ var wslDrivesMountPoint = /* @__PURE__ */ (() => {
109339
+ const defaultMountPoint = "/mnt/";
109340
+ let mountPoint;
109341
+ return async function() {
109342
+ if (mountPoint) {
109343
+ return mountPoint;
109221
109344
  }
109222
- if (appArguments.length > 0) {
109223
- cliArguments.push(...appArguments);
109345
+ const configFilePath = "/etc/wsl.conf";
109346
+ let isConfigFileExists = false;
109347
+ try {
109348
+ await import_promises3.default.access(configFilePath, import_promises3.constants.F_OK);
109349
+ isConfigFileExists = true;
109350
+ } catch {
109224
109351
  }
109225
- if (!options.wait) {
109226
- childProcessOptions.stdio = "ignore";
109227
- childProcessOptions.detached = true;
109352
+ if (!isConfigFileExists) {
109353
+ return defaultMountPoint;
109228
109354
  }
109229
- }
109230
- if (platform === "darwin" && appArguments.length > 0) {
109231
- cliArguments.push("--args", ...appArguments);
109232
- }
109233
- if (options.target) {
109234
- cliArguments.push(options.target);
109235
- }
109236
- const subprocess = import_node_child_process7.default.spawn(command, cliArguments, childProcessOptions);
109237
- if (options.wait) {
109238
- return new Promise((resolve, reject) => {
109239
- subprocess.once("error", reject);
109240
- subprocess.once("close", (exitCode) => {
109241
- if (!options.allowNonzeroExitCode && exitCode !== 0) {
109242
- reject(new Error(`Exited with code ${exitCode}`));
109243
- return;
109244
- }
109245
- resolve(subprocess);
109246
- });
109247
- });
109248
- }
109249
- if (isFallbackAttempt) {
109250
- return new Promise((resolve, reject) => {
109251
- subprocess.once("error", reject);
109252
- subprocess.once("spawn", () => {
109253
- subprocess.once("close", (exitCode) => {
109254
- subprocess.off("error", reject);
109255
- if (exitCode !== 0) {
109256
- reject(new Error(`Exited with code ${exitCode}`));
109257
- return;
109258
- }
109259
- subprocess.unref();
109260
- resolve(subprocess);
109261
- });
109262
- });
109263
- });
109264
- }
109265
- subprocess.unref();
109266
- return new Promise((resolve, reject) => {
109267
- subprocess.once("error", reject);
109268
- subprocess.once("spawn", () => {
109269
- subprocess.off("error", reject);
109270
- resolve(subprocess);
109271
- });
109272
- });
109355
+ const configContent = await import_promises3.default.readFile(configFilePath, { encoding: "utf8" });
109356
+ const parsedMountPoint = parseMountPointFromConfig(configContent);
109357
+ if (parsedMountPoint === void 0) {
109358
+ return defaultMountPoint;
109359
+ }
109360
+ mountPoint = parsedMountPoint;
109361
+ mountPoint = mountPoint.endsWith("/") ? mountPoint : `${mountPoint}/`;
109362
+ return mountPoint;
109363
+ };
109364
+ })();
109365
+ var powerShellPathFromWsl = async () => {
109366
+ const mountPoint = await wslDrivesMountPoint();
109367
+ return `${mountPoint}c/Windows/System32/WindowsPowerShell/v1.0/powershell.exe`;
109273
109368
  };
109274
- var open = (target, options) => {
109275
- if (typeof target !== "string") {
109276
- throw new TypeError("Expected a `target`");
109277
- }
109278
- return baseOpen({
109279
- ...options,
109280
- target
109281
- });
109369
+ var powerShellPath2 = is_wsl_default ? powerShellPathFromWsl : powerShellPath;
109370
+ var canAccessPowerShellPromise;
109371
+ var canAccessPowerShell = async () => {
109372
+ canAccessPowerShellPromise ??= (async () => {
109373
+ try {
109374
+ const psPath = await powerShellPath2();
109375
+ await import_promises3.default.access(psPath, import_promises3.constants.X_OK);
109376
+ return true;
109377
+ } catch {
109378
+ return false;
109379
+ }
109380
+ })();
109381
+ return canAccessPowerShellPromise;
109282
109382
  };
109283
- function detectArchBinary(binary) {
109284
- if (typeof binary === "string" || Array.isArray(binary)) {
109285
- return binary;
109383
+ var wslDefaultBrowser = async () => {
109384
+ const psPath = await powerShellPath2();
109385
+ const command = String.raw`(Get-ItemProperty -Path "HKCU:\Software\Microsoft\Windows\Shell\Associations\UrlAssociations\http\UserChoice").ProgId`;
109386
+ const { stdout } = await executePowerShell(command, { powerShellPath: psPath });
109387
+ return stdout.trim();
109388
+ };
109389
+ var convertWslPathToWindows = async (path2) => {
109390
+ if (/^[a-z]+:\/\//i.test(path2)) {
109391
+ return path2;
109286
109392
  }
109287
- const { [arch]: archBinary } = binary;
109288
- if (!archBinary) {
109289
- throw new Error(`${arch} is not supported`);
109393
+ try {
109394
+ const { stdout } = await execFile2("wslpath", ["-aw", path2], { encoding: "utf8" });
109395
+ return stdout.trim();
109396
+ } catch {
109397
+ return path2;
109290
109398
  }
109291
- return archBinary;
109399
+ };
109400
+
109401
+ // ../../../node_modules/.pnpm/define-lazy-prop@3.0.0/node_modules/define-lazy-prop/index.js
109402
+ init_cjs_shims();
109403
+ function defineLazyProperty(object3, propertyName, valueGetter) {
109404
+ const define = (value) => Object.defineProperty(object3, propertyName, { value, enumerable: true, writable: true });
109405
+ Object.defineProperty(object3, propertyName, {
109406
+ configurable: true,
109407
+ enumerable: true,
109408
+ get() {
109409
+ const result = valueGetter();
109410
+ define(result);
109411
+ return result;
109412
+ },
109413
+ set(value) {
109414
+ define(value);
109415
+ }
109416
+ });
109417
+ return object3;
109292
109418
  }
109293
- function detectPlatformBinary({ [platform]: platformBinary }, { wsl } = {}) {
109294
- if (wsl && is_wsl_default) {
109295
- return detectArchBinary(wsl);
109419
+
109420
+ // ../../../node_modules/.pnpm/default-browser@5.5.0/node_modules/default-browser/index.js
109421
+ init_cjs_shims();
109422
+ var import_node_util6 = require("util");
109423
+ var import_node_process6 = __toESM(require("process"), 1);
109424
+ var import_node_child_process6 = require("child_process");
109425
+
109426
+ // ../../../node_modules/.pnpm/default-browser-id@5.0.1/node_modules/default-browser-id/index.js
109427
+ init_cjs_shims();
109428
+ var import_node_util3 = require("util");
109429
+ var import_node_process4 = __toESM(require("process"), 1);
109430
+ var import_node_child_process3 = require("child_process");
109431
+ var execFileAsync = (0, import_node_util3.promisify)(import_node_child_process3.execFile);
109432
+ async function defaultBrowserId() {
109433
+ if (import_node_process4.default.platform !== "darwin") {
109434
+ throw new Error("macOS only");
109296
109435
  }
109297
- if (!platformBinary) {
109298
- throw new Error(`${platform} is not supported`);
109436
+ const { stdout } = await execFileAsync("defaults", ["read", "com.apple.LaunchServices/com.apple.launchservices.secure", "LSHandlers"]);
109437
+ const match = /LSHandlerRoleAll = "(?!-)(?<id>[^"]+?)";\s+?LSHandlerURLScheme = (?:http|https);/.exec(stdout);
109438
+ const browserId = match?.groups.id ?? "com.apple.Safari";
109439
+ if (browserId === "com.apple.safari") {
109440
+ return "com.apple.Safari";
109299
109441
  }
109300
- return detectArchBinary(platformBinary);
109442
+ return browserId;
109301
109443
  }
109302
- var apps = {
109303
- browser: "browser",
109304
- browserPrivate: "browserPrivate"
109305
- };
109306
- defineLazyProperty(apps, "chrome", () => detectPlatformBinary({
109307
- darwin: "google chrome",
109308
- win32: "chrome",
109309
- // `chromium-browser` is the older deb package name used by Ubuntu/Debian before snap.
109310
- linux: ["google-chrome", "google-chrome-stable", "chromium", "chromium-browser"]
109311
- }, {
109312
- wsl: {
109313
- ia32: "/mnt/c/Program Files (x86)/Google/Chrome/Application/chrome.exe",
109314
- x64: ["/mnt/c/Program Files/Google/Chrome/Application/chrome.exe", "/mnt/c/Program Files (x86)/Google/Chrome/Application/chrome.exe"]
109444
+
109445
+ // ../../../node_modules/.pnpm/bundle-name@4.1.0/node_modules/bundle-name/index.js
109446
+ init_cjs_shims();
109447
+
109448
+ // ../../../node_modules/.pnpm/run-applescript@7.1.0/node_modules/run-applescript/index.js
109449
+ init_cjs_shims();
109450
+ var import_node_process5 = __toESM(require("process"), 1);
109451
+ var import_node_util4 = require("util");
109452
+ var import_node_child_process4 = require("child_process");
109453
+ var execFileAsync2 = (0, import_node_util4.promisify)(import_node_child_process4.execFile);
109454
+ async function runAppleScript(script, { humanReadableOutput = true, signal } = {}) {
109455
+ if (import_node_process5.default.platform !== "darwin") {
109456
+ throw new Error("macOS only");
109315
109457
  }
109316
- }));
109317
- defineLazyProperty(apps, "brave", () => detectPlatformBinary({
109318
- darwin: "brave browser",
109319
- win32: "brave",
109320
- linux: ["brave-browser", "brave"]
109321
- }, {
109322
- wsl: {
109323
- ia32: "/mnt/c/Program Files (x86)/BraveSoftware/Brave-Browser/Application/brave.exe",
109324
- x64: ["/mnt/c/Program Files/BraveSoftware/Brave-Browser/Application/brave.exe", "/mnt/c/Program Files (x86)/BraveSoftware/Brave-Browser/Application/brave.exe"]
109458
+ const outputArguments = humanReadableOutput ? [] : ["-ss"];
109459
+ const execOptions = {};
109460
+ if (signal) {
109461
+ execOptions.signal = signal;
109325
109462
  }
109326
- }));
109327
- defineLazyProperty(apps, "firefox", () => detectPlatformBinary({
109328
- darwin: "firefox",
109329
- win32: String.raw`C:\Program Files\Mozilla Firefox\firefox.exe`,
109330
- linux: "firefox"
109331
- }, {
109332
- wsl: "/mnt/c/Program Files/Mozilla Firefox/firefox.exe"
109333
- }));
109334
- defineLazyProperty(apps, "edge", () => detectPlatformBinary({
109335
- darwin: "microsoft edge",
109336
- win32: "msedge",
109337
- linux: ["microsoft-edge", "microsoft-edge-dev"]
109338
- }, {
109339
- wsl: "/mnt/c/Program Files (x86)/Microsoft/Edge/Application/msedge.exe"
109340
- }));
109341
- defineLazyProperty(apps, "safari", () => detectPlatformBinary({
109342
- darwin: "Safari"
109343
- }));
109344
- var open_default = open;
109463
+ const { stdout } = await execFileAsync2("osascript", ["-e", script, outputArguments], execOptions);
109464
+ return stdout.trim();
109465
+ }
109345
109466
 
109346
- // src/shared/utils.ts
109347
- var getBaseUrl = (dev) => {
109348
- return dev ? "http://localhost:3000" : "https://agentcash.dev";
109349
- };
109350
- var getDepositLink = (address, flags) => {
109351
- return `${getBaseUrl(flags.dev)}/deposit/${address}`;
109352
- };
109353
- var openDepositLink = async (address, flags) => {
109354
- const depositLink = getDepositLink(address, flags);
109355
- await open_default(depositLink);
109467
+ // ../../../node_modules/.pnpm/bundle-name@4.1.0/node_modules/bundle-name/index.js
109468
+ async function bundleName(bundleId) {
109469
+ return runAppleScript(`tell application "Finder" to set app_path to application file id "${bundleId}" as string
109470
+ tell application "System Events" to get value of property list item "CFBundleName" of property list file (app_path & ":Contents:Info.plist")`);
109471
+ }
109472
+
109473
+ // ../../../node_modules/.pnpm/default-browser@5.5.0/node_modules/default-browser/windows.js
109474
+ init_cjs_shims();
109475
+ var import_node_util5 = require("util");
109476
+ var import_node_child_process5 = require("child_process");
109477
+ var execFileAsync3 = (0, import_node_util5.promisify)(import_node_child_process5.execFile);
109478
+ var windowsBrowserProgIds = {
109479
+ MSEdgeHTM: { name: "Edge", id: "com.microsoft.edge" },
109480
+ // The missing `L` is correct.
109481
+ MSEdgeBHTML: { name: "Edge Beta", id: "com.microsoft.edge.beta" },
109482
+ MSEdgeDHTML: { name: "Edge Dev", id: "com.microsoft.edge.dev" },
109483
+ AppXq0fevzme2pys62n3e0fbqa7peapykr8v: { name: "Edge", id: "com.microsoft.edge.old" },
109484
+ ChromeHTML: { name: "Chrome", id: "com.google.chrome" },
109485
+ ChromeBHTML: { name: "Chrome Beta", id: "com.google.chrome.beta" },
109486
+ ChromeDHTML: { name: "Chrome Dev", id: "com.google.chrome.dev" },
109487
+ ChromiumHTM: { name: "Chromium", id: "org.chromium.Chromium" },
109488
+ BraveHTML: { name: "Brave", id: "com.brave.Browser" },
109489
+ BraveBHTML: { name: "Brave Beta", id: "com.brave.Browser.beta" },
109490
+ BraveDHTML: { name: "Brave Dev", id: "com.brave.Browser.dev" },
109491
+ BraveSSHTM: { name: "Brave Nightly", id: "com.brave.Browser.nightly" },
109492
+ FirefoxURL: { name: "Firefox", id: "org.mozilla.firefox" },
109493
+ OperaStable: { name: "Opera", id: "com.operasoftware.Opera" },
109494
+ VivaldiHTM: { name: "Vivaldi", id: "com.vivaldi.Vivaldi" },
109495
+ "IE.HTTP": { name: "Internet Explorer", id: "com.microsoft.ie" }
109356
109496
  };
109357
-
109358
- // src/shared/balance.ts
109359
- var getBalance3 = async ({
109360
- address,
109361
- flags,
109362
- surface: surface2
109363
- }) => {
109364
- const url3 = `${getBaseUrl(flags.dev)}/api/rpc/balance/${address}`;
109365
- const res = await safeFetchJson(
109366
- surface2,
109367
- new Request(url3, {
109368
- method: "GET",
109369
- headers: {
109370
- accept: "application/json"
109371
- }
109372
- }),
109373
- zod_default.object({
109374
- chain: zod_default.number(),
109375
- balance: zod_default.coerce.number()
109376
- })
109377
- );
109378
- return res;
109497
+ var _windowsBrowserProgIdMap = new Map(Object.entries(windowsBrowserProgIds));
109498
+ var UnknownBrowserError = class extends Error {
109379
109499
  };
109500
+ async function defaultBrowser(_execFileAsync = execFileAsync3) {
109501
+ const { stdout } = await _execFileAsync("reg", [
109502
+ "QUERY",
109503
+ " HKEY_CURRENT_USER\\Software\\Microsoft\\Windows\\Shell\\Associations\\UrlAssociations\\http\\UserChoice",
109504
+ "/v",
109505
+ "ProgId"
109506
+ ]);
109507
+ const match = /ProgId\s*REG_SZ\s*(?<id>\S+)/.exec(stdout);
109508
+ if (!match) {
109509
+ throw new UnknownBrowserError(`Cannot find Windows browser in stdout: ${JSON.stringify(stdout)}`);
109510
+ }
109511
+ const { id } = match.groups;
109512
+ const dotIndex = id.lastIndexOf(".");
109513
+ const hyphenIndex = id.lastIndexOf("-");
109514
+ const baseIdByDot = dotIndex === -1 ? void 0 : id.slice(0, dotIndex);
109515
+ const baseIdByHyphen = hyphenIndex === -1 ? void 0 : id.slice(0, hyphenIndex);
109516
+ return windowsBrowserProgIds[id] ?? windowsBrowserProgIds[baseIdByDot] ?? windowsBrowserProgIds[baseIdByHyphen] ?? { name: id, id };
109517
+ }
109380
109518
 
109381
- // src/shared/tempo-balance.ts
109382
- init_cjs_shims();
109383
- var MPPSCAN_BASE = "https://mppscan.com";
109384
- async function getTempoBalance({
109385
- address,
109386
- tokenAddress
109387
- }) {
109388
- const url3 = `${MPPSCAN_BASE}/api/balance/${address}`;
109389
- const res = await fetch(url3, {
109390
- method: "GET",
109391
- headers: { accept: "application/json" }
109392
- });
109393
- if (!res.ok) {
109394
- throw new Error(`mppscan balance request failed: ${res.status}`);
109519
+ // ../../../node_modules/.pnpm/default-browser@5.5.0/node_modules/default-browser/index.js
109520
+ var execFileAsync4 = (0, import_node_util6.promisify)(import_node_child_process6.execFile);
109521
+ var titleize = (string6) => string6.toLowerCase().replaceAll(/(?:^|\s|-)\S/g, (x) => x.toUpperCase());
109522
+ async function defaultBrowser2() {
109523
+ if (import_node_process6.default.platform === "darwin") {
109524
+ const id = await defaultBrowserId();
109525
+ const name = await bundleName(id);
109526
+ return { name, id };
109395
109527
  }
109396
- const data = await res.json();
109397
- return {
109398
- chainId: tempo.id,
109399
- chainName: tempo.name,
109400
- balance: BigInt(data.balance),
109401
- tokenAddress
109402
- };
109528
+ if (import_node_process6.default.platform === "linux") {
109529
+ const { stdout } = await execFileAsync4("xdg-mime", ["query", "default", "x-scheme-handler/http"]);
109530
+ const id = stdout.trim();
109531
+ const name = titleize(id.replace(/.desktop$/, "").replace("-", " "));
109532
+ return { name, id };
109533
+ }
109534
+ if (import_node_process6.default.platform === "win32") {
109535
+ return defaultBrowser();
109536
+ }
109537
+ throw new Error("Only macOS, Linux, and Windows are supported");
109403
109538
  }
109404
109539
 
109405
- // src/shared/operations/fetch-with-payment.ts
109406
- function createFetchWithPayment(options) {
109407
- const { surface: surface2, clients, paymentMethod, beforePayment, timeout } = options;
109408
- return async (request) => {
109409
- const clonedRequest = request.clone();
109410
- const fallbackRequest = request.clone();
109411
- const probeResult = await safeFetch(surface2, request, timeout);
109412
- if (probeResult.isErr()) {
109413
- return fetchErr(surface2, probeResult.error);
109414
- }
109415
- if (probeResult.value.status !== 402) {
109416
- return probeResult.andThen(
109417
- (response2) => fetchOk({ response: response2, paymentInfo: null })
109418
- );
109419
- }
109420
- const response = probeResult.value;
109421
- if (paymentMethod !== "auto") {
109422
- if (paymentMethod === "mpp") {
109423
- return handleMppPayment(surface2, response, clonedRequest, options);
109424
- }
109425
- return handleX402Payment(
109426
- surface2,
109427
- response,
109428
- clonedRequest,
109429
- clients.x402,
109430
- beforePayment,
109431
- timeout
109432
- );
109433
- }
109434
- const available = detectPaymentProtocols(response);
109435
- let preferred;
109436
- if (available.length === 1) {
109437
- preferred = available[0];
109438
- } else {
109439
- preferred = await pickByBalance(surface2, response, options);
109440
- }
109441
- const fallback = available.length > 1 ? preferred === "mpp" ? "x402" : "mpp" : null;
109442
- const result = preferred === "mpp" ? await handleMppPayment(surface2, response, clonedRequest, options) : await handleX402Payment(
109443
- surface2,
109444
- response,
109445
- clonedRequest,
109446
- clients.x402,
109447
- beforePayment,
109448
- timeout
109449
- );
109450
- if (result.isErr() && fallback) {
109451
- return fallback === "mpp" ? handleMppPayment(surface2, response, fallbackRequest, options) : handleX402Payment(
109452
- surface2,
109453
- response,
109454
- fallbackRequest,
109455
- clients.x402,
109456
- beforePayment,
109457
- timeout
109458
- );
109540
+ // ../../../node_modules/.pnpm/is-in-ssh@1.0.0/node_modules/is-in-ssh/index.js
109541
+ init_cjs_shims();
109542
+ var import_node_process7 = __toESM(require("process"), 1);
109543
+ var isInSsh = Boolean(import_node_process7.default.env.SSH_CONNECTION || import_node_process7.default.env.SSH_CLIENT || import_node_process7.default.env.SSH_TTY);
109544
+ var is_in_ssh_default = isInSsh;
109545
+
109546
+ // ../../../node_modules/.pnpm/open@11.0.0/node_modules/open/index.js
109547
+ var fallbackAttemptSymbol = /* @__PURE__ */ Symbol("fallbackAttempt");
109548
+ var __dirname2 = importMetaUrl ? import_node_path.default.dirname((0, import_node_url.fileURLToPath)(importMetaUrl)) : "";
109549
+ var localXdgOpenPath = import_node_path.default.join(__dirname2, "xdg-open");
109550
+ var { platform, arch } = import_node_process8.default;
109551
+ var tryEachApp = async (apps2, opener) => {
109552
+ if (apps2.length === 0) {
109553
+ return;
109554
+ }
109555
+ const errors = [];
109556
+ for (const app of apps2) {
109557
+ try {
109558
+ return await opener(app);
109559
+ } catch (error48) {
109560
+ errors.push(error48);
109459
109561
  }
109460
- return result;
109562
+ }
109563
+ throw new AggregateError(errors, "Failed to open in all supported apps");
109564
+ };
109565
+ var baseOpen = async (options) => {
109566
+ options = {
109567
+ wait: false,
109568
+ background: false,
109569
+ newInstance: false,
109570
+ allowNonzeroExitCode: false,
109571
+ ...options
109461
109572
  };
109462
- }
109463
- async function pickByBalance(surface2, response, options) {
109464
- const { account, flags } = options;
109465
- const x402BalanceResult = await resultFromPromise(
109466
- "balance",
109467
- surface2,
109468
- getBalance3({
109469
- address: account.address,
109470
- flags,
109471
- surface: surface2
109472
- }).then((r) => r.isOk() ? r.value.balance : 0),
109473
- () => ({
109474
- cause: "x402_balance",
109475
- message: "Failed to get x402 balance"
109476
- })
109477
- );
109478
- if (x402BalanceResult.isErr()) {
109479
- log.debug("Balance comparison failed, defaulting to mpp");
109480
- return "mpp";
109573
+ const isFallbackAttempt = options[fallbackAttemptSymbol] === true;
109574
+ delete options[fallbackAttemptSymbol];
109575
+ if (Array.isArray(options.app)) {
109576
+ return tryEachApp(options.app, (singleApp) => baseOpen({
109577
+ ...options,
109578
+ app: singleApp,
109579
+ [fallbackAttemptSymbol]: true
109580
+ }));
109481
109581
  }
109482
- const x402Balance = x402BalanceResult.value;
109483
- let mppBalance = 0;
109484
- const challengeResult = safeGetMppChallenge(surface2, response);
109485
- if (challengeResult.isOk()) {
109486
- const currency = challengeResult.value.request.currency;
109487
- const decimals2 = challengeResult.value.request.decimals ?? 6;
109488
- if (currency) {
109489
- const tempoResult = await resultFromPromise(
109490
- "tempo",
109491
- surface2,
109492
- getTempoBalance({
109493
- address: account.address,
109494
- tokenAddress: currency
109495
- }),
109496
- () => ({
109497
- cause: "tempo_balance",
109498
- message: "Tempo balance check failed"
109499
- })
109500
- );
109501
- if (tempoResult.isOk()) {
109502
- mppBalance = Number(formatUnits(tempoResult.value.balance, decimals2));
109582
+ let { name: app, arguments: appArguments = [] } = options.app ?? {};
109583
+ appArguments = [...appArguments];
109584
+ if (Array.isArray(app)) {
109585
+ return tryEachApp(app, (appName) => baseOpen({
109586
+ ...options,
109587
+ app: {
109588
+ name: appName,
109589
+ arguments: appArguments
109590
+ },
109591
+ [fallbackAttemptSymbol]: true
109592
+ }));
109593
+ }
109594
+ if (app === "browser" || app === "browserPrivate") {
109595
+ const ids = {
109596
+ "com.google.chrome": "chrome",
109597
+ "google-chrome.desktop": "chrome",
109598
+ "com.brave.browser": "brave",
109599
+ "org.mozilla.firefox": "firefox",
109600
+ "firefox.desktop": "firefox",
109601
+ "com.microsoft.msedge": "edge",
109602
+ "com.microsoft.edge": "edge",
109603
+ "com.microsoft.edgemac": "edge",
109604
+ "microsoft-edge.desktop": "edge",
109605
+ "com.apple.safari": "safari"
109606
+ };
109607
+ const flags = {
109608
+ chrome: "--incognito",
109609
+ brave: "--incognito",
109610
+ firefox: "--private-window",
109611
+ edge: "--inPrivate"
109612
+ // Safari doesn't support private mode via command line
109613
+ };
109614
+ let browser;
109615
+ if (is_wsl_default) {
109616
+ const progId = await wslDefaultBrowser();
109617
+ const browserInfo = _windowsBrowserProgIdMap.get(progId);
109618
+ browser = browserInfo ?? {};
109619
+ } else {
109620
+ browser = await defaultBrowser2();
109621
+ }
109622
+ if (browser.id in ids) {
109623
+ const browserName = ids[browser.id.toLowerCase()];
109624
+ if (app === "browserPrivate") {
109625
+ if (browserName === "safari") {
109626
+ throw new Error("Safari doesn't support opening in private mode via command line");
109627
+ }
109628
+ appArguments.push(flags[browserName]);
109503
109629
  }
109630
+ return baseOpen({
109631
+ ...options,
109632
+ app: {
109633
+ name: apps[browserName],
109634
+ arguments: appArguments
109635
+ }
109636
+ });
109504
109637
  }
109638
+ throw new Error(`${browser.name} is not supported as a default browser`);
109505
109639
  }
109506
- log.info(`Protocol selection \u2014 x402: $${x402Balance}, mpp: $${mppBalance}`);
109507
- return x402Balance >= mppBalance ? "x402" : "mpp";
109508
- }
109509
- async function handleX402Payment(surface2, response, clonedRequest, client, beforePayment, timeout) {
109510
- const paymentRequiredResult = await safeGetPaymentRequired(
109511
- surface2,
109512
- client,
109513
- response
109514
- );
109515
- if (paymentRequiredResult.isErr()) {
109516
- return paymentRequiredResult;
109640
+ let command;
109641
+ const cliArguments = [];
109642
+ const childProcessOptions = {};
109643
+ let shouldUseWindowsInWsl = false;
109644
+ if (is_wsl_default && !isInsideContainer() && !is_in_ssh_default && !app) {
109645
+ shouldUseWindowsInWsl = await canAccessPowerShell();
109517
109646
  }
109518
- const paymentRequired = paymentRequiredResult.value;
109519
- if (beforePayment) {
109520
- const accept = paymentRequired.accepts[0];
109521
- if (accept) {
109522
- const amount2 = tokenStringToNumber(accept.amount);
109523
- const hookResult = await resultFromPromise(
109524
- "x402",
109525
- surface2,
109526
- beforePayment({
109527
- protocol: "x402",
109528
- amount: amount2,
109529
- currency: "USDC",
109530
- network: accept.network
109531
- }),
109532
- (e) => ({
109533
- cause: "payment_already_attempted",
109534
- message: e instanceof Error ? e.message : "Before-payment hook failed"
109535
- })
109536
- );
109537
- if (hookResult.isErr()) {
109538
- return x402Err(surface2, hookResult.error);
109647
+ if (platform === "darwin") {
109648
+ command = "open";
109649
+ if (options.wait) {
109650
+ cliArguments.push("--wait-apps");
109651
+ }
109652
+ if (options.background) {
109653
+ cliArguments.push("--background");
109654
+ }
109655
+ if (options.newInstance) {
109656
+ cliArguments.push("--new");
109657
+ }
109658
+ if (app) {
109659
+ cliArguments.push("-a", app);
109660
+ }
109661
+ } else if (platform === "win32" || shouldUseWindowsInWsl) {
109662
+ command = await powerShellPath2();
109663
+ cliArguments.push(...executePowerShell.argumentsPrefix);
109664
+ if (!is_wsl_default) {
109665
+ childProcessOptions.windowsVerbatimArguments = true;
109666
+ }
109667
+ if (is_wsl_default && options.target) {
109668
+ options.target = await convertWslPathToWindows(options.target);
109669
+ }
109670
+ const encodedArguments = ["$ProgressPreference = 'SilentlyContinue';", "Start"];
109671
+ if (options.wait) {
109672
+ encodedArguments.push("-Wait");
109673
+ }
109674
+ if (app) {
109675
+ encodedArguments.push(executePowerShell.escapeArgument(app));
109676
+ if (options.target) {
109677
+ appArguments.push(options.target);
109539
109678
  }
109679
+ } else if (options.target) {
109680
+ encodedArguments.push(executePowerShell.escapeArgument(options.target));
109681
+ }
109682
+ if (appArguments.length > 0) {
109683
+ appArguments = appArguments.map((argument) => executePowerShell.escapeArgument(argument));
109684
+ encodedArguments.push("-ArgumentList", appArguments.join(","));
109685
+ }
109686
+ options.target = executePowerShell.encodeCommand(encodedArguments.join(" "));
109687
+ if (!options.wait) {
109688
+ childProcessOptions.stdio = "ignore";
109689
+ }
109690
+ } else {
109691
+ if (app) {
109692
+ command = app;
109693
+ } else {
109694
+ const isBundled = !__dirname2 || __dirname2 === "/";
109695
+ let exeLocalXdgOpen = false;
109696
+ try {
109697
+ await import_promises4.default.access(localXdgOpenPath, import_promises4.constants.X_OK);
109698
+ exeLocalXdgOpen = true;
109699
+ } catch {
109700
+ }
109701
+ const useSystemXdgOpen = import_node_process8.default.versions.electron ?? (platform === "android" || isBundled || !exeLocalXdgOpen);
109702
+ command = useSystemXdgOpen ? "xdg-open" : localXdgOpenPath;
109703
+ }
109704
+ if (appArguments.length > 0) {
109705
+ cliArguments.push(...appArguments);
109706
+ }
109707
+ if (!options.wait) {
109708
+ childProcessOptions.stdio = "ignore";
109709
+ childProcessOptions.detached = true;
109540
109710
  }
109541
109711
  }
109542
- const paymentPayloadResult = await safeCreatePaymentPayload(
109543
- surface2,
109544
- client,
109545
- paymentRequired
109546
- );
109547
- if (paymentPayloadResult.isErr()) {
109548
- return paymentPayloadResult;
109549
- }
109550
- const paymentPayload = paymentPayloadResult.value;
109551
- const paymentHeaders = client.encodePaymentSignatureHeader(paymentPayload);
109552
- if (clonedRequest.headers.has("PAYMENT-SIGNATURE") || clonedRequest.headers.has("X-PAYMENT")) {
109553
- return x402Err(surface2, {
109554
- cause: "payment_already_attempted",
109555
- message: "Payment already attempted"
109556
- });
109712
+ if (platform === "darwin" && appArguments.length > 0) {
109713
+ cliArguments.push("--args", ...appArguments);
109557
109714
  }
109558
- for (const [key, value] of Object.entries(paymentHeaders)) {
109559
- clonedRequest.headers.set(key, value);
109715
+ if (options.target) {
109716
+ cliArguments.push(options.target);
109560
109717
  }
109561
- clonedRequest.headers.set(
109562
- "Access-Control-Expose-Headers",
109563
- "PAYMENT-RESPONSE,X-PAYMENT-RESPONSE"
109564
- );
109565
- return await safeFetch(surface2, clonedRequest, timeout).andThen(
109566
- (paidResponse) => {
109567
- const settlementResult = safeGetPaymentSettlement(
109568
- surface2,
109569
- client,
109570
- paidResponse
109571
- );
109572
- return x402Ok({
109573
- response: paidResponse,
109574
- paymentInfo: {
109575
- protocol: "x402",
109576
- price: tokenStringToNumber(
109577
- paymentPayload.accepted.amount
109578
- ).toLocaleString("en-US", {
109579
- style: "currency",
109580
- currency: "USD"
109581
- }),
109582
- ...settlementResult.isOk() ? {
109583
- payment: {
109584
- success: settlementResult.value.success,
109585
- transactionHash: settlementResult.value.transaction
109586
- }
109587
- } : {}
109718
+ const subprocess = import_node_child_process7.default.spawn(command, cliArguments, childProcessOptions);
109719
+ if (options.wait) {
109720
+ return new Promise((resolve, reject) => {
109721
+ subprocess.once("error", reject);
109722
+ subprocess.once("close", (exitCode) => {
109723
+ if (!options.allowNonzeroExitCode && exitCode !== 0) {
109724
+ reject(new Error(`Exited with code ${exitCode}`));
109725
+ return;
109588
109726
  }
109727
+ resolve(subprocess);
109589
109728
  });
109590
- }
109591
- );
109592
- }
109593
- async function handleMppPayment(surface2, response, clonedRequest, options) {
109594
- const { clients, beforePayment, timeout } = options;
109595
- const mppxClient = clients.mpp;
109596
- if (clonedRequest.headers.has("Authorization")) {
109597
- return mppErr(surface2, {
109598
- cause: "mpp_payment_already_attempted",
109599
- message: "MPP payment already attempted"
109600
109729
  });
109601
109730
  }
109602
- const challengeResult = safeGetMppChallenge(surface2, response);
109603
- if (challengeResult.isErr()) {
109604
- return challengeResult;
109605
- }
109606
- const challenge2 = challengeResult.value;
109607
- const amount2 = challenge2.request.amount;
109608
- const decimals2 = challenge2.request.decimals ?? 6;
109609
- const currency = challenge2.request.currency;
109610
- if (beforePayment && amount2 && currency) {
109611
- const numericAmount = Number(formatUnits(BigInt(amount2), decimals2));
109612
- const hookResult = await resultFromPromise(
109613
- "mpp",
109614
- surface2,
109615
- beforePayment({
109616
- protocol: "mpp",
109617
- amount: numericAmount,
109618
- currency,
109619
- network: `tempo:${challenge2.method}`
109620
- }),
109621
- (e) => ({
109622
- cause: "mpp_payment_already_attempted",
109623
- message: e instanceof Error ? e.message : "Before-payment hook failed"
109624
- })
109625
- );
109626
- if (hookResult.isErr()) {
109627
- return mppErr(surface2, hookResult.error);
109628
- }
109629
- }
109630
- const credentialResult = await safeCreateMppCredential(
109631
- surface2,
109632
- mppxClient,
109633
- response
109634
- );
109635
- if (credentialResult.isErr()) {
109636
- return credentialResult;
109637
- }
109638
- const credential = credentialResult.value;
109639
- clonedRequest.headers.set("Authorization", credential);
109640
- return await safeFetch(surface2, clonedRequest, timeout).andThen(
109641
- (paidResponse) => {
109642
- const receiptResult = safeGetMppReceipt(surface2, paidResponse);
109643
- const priceDisplay = amount2 ? Number(formatUnits(BigInt(amount2), decimals2)).toLocaleString(
109644
- "en-US",
109645
- {
109646
- style: "currency",
109647
- currency: "USD"
109648
- }
109649
- ) : void 0;
109650
- return mppOk({
109651
- response: paidResponse,
109652
- paymentInfo: {
109653
- protocol: "mpp",
109654
- ...priceDisplay ? { price: priceDisplay } : {},
109655
- ...receiptResult.isOk() ? {
109656
- payment: {
109657
- success: true,
109658
- transactionHash: receiptResult.value.reference
109659
- }
109660
- } : {}
109661
- }
109731
+ if (isFallbackAttempt) {
109732
+ return new Promise((resolve, reject) => {
109733
+ subprocess.once("error", reject);
109734
+ subprocess.once("spawn", () => {
109735
+ subprocess.once("close", (exitCode) => {
109736
+ subprocess.off("error", reject);
109737
+ if (exitCode !== 0) {
109738
+ reject(new Error(`Exited with code ${exitCode}`));
109739
+ return;
109740
+ }
109741
+ subprocess.unref();
109742
+ resolve(subprocess);
109743
+ });
109662
109744
  });
109663
- }
109664
- );
109665
- }
109666
-
109667
- // src/server/tools/response/index.ts
109668
- init_cjs_shims();
109669
-
109670
- // src/server/tools/response/success.ts
109671
- init_cjs_shims();
109672
-
109673
- // src/shared/neverthrow/json/index.ts
109674
- init_cjs_shims();
109675
- var type3 = "json";
109676
- var jsonErr = (surface2, error48) => {
109677
- return err2(type3, surface2, error48);
109678
- };
109679
- var safeStringifyJson = (surface2, value) => {
109680
- return resultFromThrowable(
109681
- type3,
109682
- surface2,
109683
- () => JSON.stringify(value, null, 2),
109684
- () => ({
109685
- cause: "stringify",
109686
- message: "Could not stringify JSON"
109687
- })
109688
- );
109689
- };
109690
- var toJsonObject = (value) => JSON.parse(JSON.stringify(value));
109691
- var safeParseJson = (surface2, value) => {
109692
- return resultFromThrowable(
109693
- type3,
109694
- surface2,
109695
- () => JSON.parse(value),
109696
- (e) => ({
109697
- cause: "parse",
109698
- message: e instanceof Error ? e.message : "Could not parse JSON"
109699
- })
109700
- );
109701
- };
109702
-
109703
- // src/server/tools/response/error.ts
109704
- init_cjs_shims();
109705
-
109706
- // src/server/tools/response/lib.ts
109707
- init_cjs_shims();
109708
- var parsedResponseToToolContentPart = (data) => {
109709
- switch (data.type) {
109710
- case "json":
109711
- return {
109712
- type: "text",
109713
- text: JSON.stringify(data.data)
109714
- };
109715
- case "image":
109716
- return {
109717
- type: "image",
109718
- mimeType: data.mimeType,
109719
- data: Buffer.from(data.data).toString("base64")
109720
- };
109721
- case "audio":
109722
- return {
109723
- type: "audio",
109724
- mimeType: data.mimeType,
109725
- data: Buffer.from(data.data).toString("base64")
109726
- };
109727
- case "text":
109728
- return { type: "text", text: data.data };
109729
- default:
109730
- return {
109731
- type: "text",
109732
- text: `Unsupported response type: ${data.type}`
109733
- };
109745
+ });
109734
109746
  }
109747
+ subprocess.unref();
109748
+ return new Promise((resolve, reject) => {
109749
+ subprocess.once("error", reject);
109750
+ subprocess.once("spawn", () => {
109751
+ subprocess.off("error", reject);
109752
+ resolve(subprocess);
109753
+ });
109754
+ });
109735
109755
  };
109736
-
109737
- // src/server/tools/response/error.ts
109738
- var buildMcpError = (content) => {
109739
- return {
109740
- content,
109741
- isError: true
109742
- };
109743
- };
109744
- var mcpErrorJson = (error48) => {
109745
- return safeStringifyJson("mcp-error-json", error48).match(
109746
- (success3) => buildMcpError([{ type: "text", text: success3 }]),
109747
- (error49) => buildMcpError([
109748
- { type: "text", text: JSON.stringify(error49, null, 2) }
109749
- ])
109750
- );
109751
- };
109752
- var mcpError = async (err3) => {
109753
- const { error: error48 } = err3;
109754
- if (isFetchError(error48)) {
109755
- switch (error48.cause) {
109756
- case "network":
109757
- case "parse":
109758
- return mcpErrorJson({ ...error48 });
109759
- case "http":
109760
- const { response, ...rest } = error48;
109761
- const parseResponseResult = await safeParseResponse(
109762
- "mcp-error-fetch-parse-response",
109763
- response
109764
- );
109765
- const httpContent = [
109766
- { type: "text", text: JSON.stringify(rest, null, 2) },
109767
- ...parseResponseResult.match(
109768
- (success3) => [parsedResponseToToolContentPart(success3)],
109769
- () => []
109770
- )
109771
- ];
109772
- return { content: httpContent };
109773
- }
109756
+ var open = (target, options) => {
109757
+ if (typeof target !== "string") {
109758
+ throw new TypeError("Expected a `target`");
109774
109759
  }
109775
- return mcpErrorJson({ ...error48 });
109760
+ return baseOpen({
109761
+ ...options,
109762
+ target
109763
+ });
109776
109764
  };
109777
- var mcpErrorFetch = async (surface2, response) => {
109778
- return mcpError(fetchHttpErr(surface2, response));
109765
+ function detectArchBinary(binary) {
109766
+ if (typeof binary === "string" || Array.isArray(binary)) {
109767
+ return binary;
109768
+ }
109769
+ const { [arch]: archBinary } = binary;
109770
+ if (!archBinary) {
109771
+ throw new Error(`${arch} is not supported`);
109772
+ }
109773
+ return archBinary;
109774
+ }
109775
+ function detectPlatformBinary({ [platform]: platformBinary }, { wsl } = {}) {
109776
+ if (wsl && is_wsl_default) {
109777
+ return detectArchBinary(wsl);
109778
+ }
109779
+ if (!platformBinary) {
109780
+ throw new Error(`${platform} is not supported`);
109781
+ }
109782
+ return detectArchBinary(platformBinary);
109783
+ }
109784
+ var apps = {
109785
+ browser: "browser",
109786
+ browserPrivate: "browserPrivate"
109779
109787
  };
109788
+ defineLazyProperty(apps, "chrome", () => detectPlatformBinary({
109789
+ darwin: "google chrome",
109790
+ win32: "chrome",
109791
+ // `chromium-browser` is the older deb package name used by Ubuntu/Debian before snap.
109792
+ linux: ["google-chrome", "google-chrome-stable", "chromium", "chromium-browser"]
109793
+ }, {
109794
+ wsl: {
109795
+ ia32: "/mnt/c/Program Files (x86)/Google/Chrome/Application/chrome.exe",
109796
+ x64: ["/mnt/c/Program Files/Google/Chrome/Application/chrome.exe", "/mnt/c/Program Files (x86)/Google/Chrome/Application/chrome.exe"]
109797
+ }
109798
+ }));
109799
+ defineLazyProperty(apps, "brave", () => detectPlatformBinary({
109800
+ darwin: "brave browser",
109801
+ win32: "brave",
109802
+ linux: ["brave-browser", "brave"]
109803
+ }, {
109804
+ wsl: {
109805
+ ia32: "/mnt/c/Program Files (x86)/BraveSoftware/Brave-Browser/Application/brave.exe",
109806
+ x64: ["/mnt/c/Program Files/BraveSoftware/Brave-Browser/Application/brave.exe", "/mnt/c/Program Files (x86)/BraveSoftware/Brave-Browser/Application/brave.exe"]
109807
+ }
109808
+ }));
109809
+ defineLazyProperty(apps, "firefox", () => detectPlatformBinary({
109810
+ darwin: "firefox",
109811
+ win32: String.raw`C:\Program Files\Mozilla Firefox\firefox.exe`,
109812
+ linux: "firefox"
109813
+ }, {
109814
+ wsl: "/mnt/c/Program Files/Mozilla Firefox/firefox.exe"
109815
+ }));
109816
+ defineLazyProperty(apps, "edge", () => detectPlatformBinary({
109817
+ darwin: "microsoft edge",
109818
+ win32: "msedge",
109819
+ linux: ["microsoft-edge", "microsoft-edge-dev"]
109820
+ }, {
109821
+ wsl: "/mnt/c/Program Files (x86)/Microsoft/Edge/Application/msedge.exe"
109822
+ }));
109823
+ defineLazyProperty(apps, "safari", () => detectPlatformBinary({
109824
+ darwin: "Safari"
109825
+ }));
109826
+ var open_default = open;
109780
109827
 
109781
- // src/server/tools/response/success.ts
109782
- var buildMcpSuccess = (content) => {
109783
- return {
109784
- content
109785
- };
109786
- };
109787
- var mcpSuccessJson = (data) => {
109788
- return safeStringifyJson("mcp-success-text", data).match(
109789
- (success3) => buildMcpSuccess([{ type: "text", text: success3 }]),
109790
- (error48) => mcpErrorJson(error48)
109791
- );
109792
- };
109793
- var mcpSuccessStructuredJson = (data) => {
109794
- return safeStringifyJson("mcp-success-structured", data).match(
109795
- (success3) => ({
109796
- content: [{ type: "text", text: success3 }],
109797
- structuredContent: data
109798
- }),
109799
- (error48) => mcpErrorJson(error48)
109800
- );
109828
+ // src/shared/utils.ts
109829
+ var getBaseUrl = (dev) => {
109830
+ return dev ? "http://localhost:3000" : "https://agentcash.dev";
109801
109831
  };
109802
- var mcpSuccessResponse = (data, extra) => {
109803
- const parsedExtra = extra ? safeStringifyJson("mcp-success-extra", extra).match(
109804
- (success3) => success3,
109805
- () => void 0
109806
- ) : void 0;
109807
- return buildMcpSuccess([
109808
- parsedResponseToToolContentPart(data),
109809
- ...parsedExtra ? [{ type: "text", text: parsedExtra }] : []
109810
- ]);
109832
+ var getDepositLink = (address, flags) => {
109833
+ return `${getBaseUrl(flags.dev)}/deposit/${address}`;
109811
109834
  };
109812
-
109813
- // src/server/tools/lib/request.ts
109814
- init_cjs_shims();
109815
- var requestSchema = zod_default.object({
109816
- url: zod_default.url().describe("The endpoint URL"),
109817
- method: zod_default.enum(["GET", "POST", "PUT", "DELETE", "PATCH"]).optional().describe("HTTP method. Defaults to GET for fetch operations."),
109818
- body: zod_default.unknown().optional().describe("Request body for POST/PUT/PATCH methods"),
109819
- headers: zod_default.record(zod_default.string(), zod_default.string()).optional().describe("Additional headers to include").default({}),
109820
- timeout: zod_default.number().int().positive().optional().describe("Request timeout in milliseconds")
109821
- });
109822
- var buildRequest2 = ({
109823
- input,
109824
- address,
109825
- sessionId,
109826
- provider
109827
- }) => {
109828
- return new Request(input.url, {
109829
- method: input.method ?? "GET",
109830
- body: input.body ? typeof input.body === "string" ? input.body : JSON.stringify(input.body) : void 0,
109831
- headers: {
109832
- ...input.body ? { "Content-Type": "application/json" } : {},
109833
- ...input.headers,
109834
- ...address ? { "X-Wallet-Address": address, "X-Client-ID": provider } : {},
109835
- ...sessionId ? { "X-Session-ID": sessionId } : {}
109836
- }
109837
- });
109835
+ var openDepositLink = async (address, flags) => {
109836
+ const depositLink = getDepositLink(address, flags);
109837
+ await open_default(depositLink);
109838
109838
  };
109839
109839
 
109840
109840
  // src/server/tools/lib/check-balance.ts
109841
- init_cjs_shims();
109842
109841
  var checkBalance = async ({
109843
109842
  server,
109844
109843
  address,
@@ -109847,7 +109846,7 @@ var checkBalance = async ({
109847
109846
  flags,
109848
109847
  surface: surface2
109849
109848
  }) => {
109850
- const balanceResult = await getBalance3({ address, flags, surface: surface2 });
109849
+ const balanceResult = await getBalance3({ address, surface: surface2 });
109851
109850
  if (balanceResult.isErr()) {
109852
109851
  log.error(JSON.stringify(balanceResult.error, null, 2));
109853
109852
  return;
@@ -110154,7 +110153,7 @@ init_cjs_shims();
110154
110153
  init_cjs_shims();
110155
110154
  async function getWalletInfo(surface2, address, flags) {
110156
110155
  const [balanceResult, tempoResult] = await Promise.all([
110157
- getBalance3({ address, flags, surface: surface2 }),
110156
+ getBalance3({ address, surface: surface2 }),
110158
110157
  getTempoBalance({ address, tokenAddress: TEMPO_TOKEN_ADDRESS }).then((r) => Number(formatUnits(r.balance, 6))).catch((e) => {
110159
110158
  log.info(`Failed to fetch Tempo balance: ${e}`);
110160
110159
  return null;
@@ -110876,7 +110875,7 @@ var import_path2 = require("path");
110876
110875
  var import_url = require("url");
110877
110876
  function getVersion2() {
110878
110877
  if (true) {
110879
- return "0.4.7";
110878
+ return "0.4.8";
110880
110879
  }
110881
110880
  const __dirname3 = (0, import_path2.dirname)((0, import_url.fileURLToPath)(importMetaUrl));
110882
110881
  const pkg = JSON.parse(
@@ -111617,7 +111616,7 @@ var import_path3 = require("path");
111617
111616
  var import_url2 = require("url");
111618
111617
  function getVersion3() {
111619
111618
  if (true) {
111620
- return "0.4.7";
111619
+ return "0.4.8";
111621
111620
  }
111622
111621
  const __dirname3 = (0, import_path3.dirname)((0, import_url2.fileURLToPath)(importMetaUrl));
111623
111622
  const pkg = JSON.parse(
@@ -111683,19 +111682,16 @@ async function reconcileLegacyWallet(current, isNew) {
111683
111682
  if (legacyAccount.address === current.address) {
111684
111683
  return noChange;
111685
111684
  }
111686
- const flags = { dev: false };
111687
111685
  const balancesResult = await resultFromPromise(
111688
111686
  "wallet",
111689
111687
  reconcileSurface,
111690
111688
  Promise.all([
111691
111689
  getBalance3({
111692
111690
  address: legacyAccount.address,
111693
- flags,
111694
111691
  surface: reconcileSurface
111695
111692
  }),
111696
111693
  getBalance3({
111697
111694
  address: current.address,
111698
- flags,
111699
111695
  surface: reconcileSurface
111700
111696
  })
111701
111697
  ]),