import {
  getWalletInfo
} from "./chunk-TVSACMMH.js";
import "./chunk-6XGAIMNK.js";
import "./chunk-DJLERI6R.js";
import {
  getWalletOrExit
} from "./chunk-QOYH6AOG.js";
import "./chunk-HFEYSQRZ.js";
import "./chunk-NPJV7AMV.js";
import "./chunk-LNQRIXFK.js";
import {
  discoverResources
} from "./chunk-HOGMCHWI.js";
import "./chunk-Y4VZACTC.js";
import "./chunk-EMQMCXIC.js";
import "./chunk-VDBUUHJF.js";
import "./chunk-ITCDZXBZ.js";
import "./chunk-QZBSRYSW.js";
import "./chunk-NROPRHIC.js";
import "./chunk-FB5CMO3J.js";
import {
  outputAndExit,
  successResponse
} from "./chunk-7EBJ4BCH.js";
import "./chunk-C7KWYVS3.js";

// src/cli/commands/try.ts
var surface = "cli:try";
var tryCommand = async (args) => {
  const wallets = await getWalletOrExit(args);
  const discoverResult = await discoverResources(surface, args);
  const walletInfo = await getWalletInfo(surface, wallets, args);
  const onboardingCta = walletInfo.onboardingCta;
  if (!discoverResult.found) {
    const origin = "origin" in discoverResult ? discoverResult.origin : args.url;
    return outputAndExit(
      successResponse({
        ...onboardingCta ? {
          onboardMessage: onboardingCta.message,
          onboardLink: onboardingCta.onboardLink
        } : {},
        notice: `No endpoints found for ${origin}. The origin may not support x402 or SIWX.`,
        resources: `Browse supported APIs at https://agentcash.dev/resources`
      }),
      args
    );
  }
  const paidEndpoints = discoverResult.endpoints.filter(
    (e) => e.authMode === "paid"
  );
  const sampleEndpoints = (paidEndpoints.length > 0 ? paidEndpoints : discoverResult.endpoints).slice(0, 3);
  const totalCount = discoverResult.endpoints.length;
  const title = discoverResult.info?.title ?? discoverResult.origin;
  const description = discoverResult.info?.description;
  const sampleLines = sampleEndpoints.map((e) => {
    const price = e.price ? ` (${e.price})` : "";
    return `  - ${e.summary}${price}`;
  });
  const originSummary = [
    `${title}${description ? ` \u2014 ${description}` : ""}`,
    "",
    "Sample endpoints:",
    ...sampleLines,
    ...totalCount > sampleEndpoints.length ? [
      `  ...and ${totalCount - sampleEndpoints.length} more. Run \`npx agentcash discover ${discoverResult.origin}\` to see all endpoints.`
    ] : []
  ].join("\n");
  const firstEndpoint = discoverResult.endpoints.find((e) => e.authMode === "paid") ?? discoverResult.endpoints[0];
  let callToAction;
  if (firstEndpoint) {
    const endpointUrl = `${discoverResult.origin}${firstEndpoint.path}`;
    callToAction = [
      `To call your first endpoint:`,
      `  1. Run \`npx agentcash check "${endpointUrl}"\` to get the input schema and pricing.`,
      `  2. Run \`npx agentcash fetch "${endpointUrl}" -m ${firstEndpoint.method}\` with the required body to make the call.`,
      `If you have the AgentCash MCP installed, you can also call this directly using the check_endpoint_schema and fetch tools.`
    ].join("\n");
  }
  const modelInstructions = [
    `Present the originSummary to the user, then ask them what they would like to do \u2014 e.g. "What would you like to do with ${title}?"`,
    ...onboardingCta ? [
      `IMPORTANT: The user has not yet onboarded. Show the onboard link VERBATIM as a clickable URL so the user can click it: ${onboardingCta.onboardLink}`
    ] : []
  ].join("\n");
  return outputAndExit(
    successResponse({
      ...onboardingCta ? {
        onboardMessage: onboardingCta.message,
        onboardLink: onboardingCta.onboardLink
      } : {},
      originSummary,
      callToAction,
      modelInstructions
    }),
    args
  );
};
export {
  tryCommand
};
//# sourceMappingURL=try-2KUOYSRY.js.map