@ampersend_ai/ampersend-sdk 0.0.9 → 0.0.10-beta.20260304

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.
@@ -0,0 +1,51 @@
1
+ import { z } from "zod";
2
+ /**
3
+ * Environment configuration for Ampersend smart account wallets.
4
+ *
5
+ * Supports two formats:
6
+ * 1. Combined: AMPERSEND_AGENT_KEY="address:::session_key"
7
+ * 2. Separate: AMPERSEND_SMART_ACCOUNT_ADDRESS + AMPERSEND_SESSION_KEY
8
+ *
9
+ * The combined format is checked first. Error if both formats are present.
10
+ */
11
+ /** Supported networks (Ampersend smart accounts only support Base) */
12
+ export declare const NETWORKS: readonly ["base", "base-sepolia"];
13
+ export type Network = (typeof NETWORKS)[number];
14
+ /**
15
+ * Zod schema for validated config (after resolving AGENT_KEY)
16
+ */
17
+ declare const configSchema: z.ZodObject<{
18
+ SMART_ACCOUNT_ADDRESS: z.ZodEffects<z.ZodString, string, string>;
19
+ SESSION_KEY: z.ZodEffects<z.ZodString, string, string>;
20
+ VALIDATOR_ADDRESS: z.ZodDefault<z.ZodEffects<z.ZodString, string, string>>;
21
+ NETWORK: z.ZodDefault<z.ZodEnum<["base", "base-sepolia"]>>;
22
+ API_URL: z.ZodOptional<z.ZodString>;
23
+ }, "strip", z.ZodTypeAny, {
24
+ SMART_ACCOUNT_ADDRESS: string;
25
+ SESSION_KEY: string;
26
+ VALIDATOR_ADDRESS: string;
27
+ NETWORK: "base-sepolia" | "base";
28
+ API_URL?: string | undefined;
29
+ }, {
30
+ SMART_ACCOUNT_ADDRESS: string;
31
+ SESSION_KEY: string;
32
+ VALIDATOR_ADDRESS?: string | undefined;
33
+ NETWORK?: "base-sepolia" | "base" | undefined;
34
+ API_URL?: string | undefined;
35
+ }>;
36
+ /**
37
+ * Ampersend environment configuration
38
+ */
39
+ export type AmpersendEnvConfig = z.infer<typeof configSchema>;
40
+ /**
41
+ * Reads and validates Ampersend environment variables.
42
+ *
43
+ * Checks AMPERSEND_AGENT_KEY first (combined format), then falls back to
44
+ * separate AMPERSEND_SMART_ACCOUNT_ADDRESS + AMPERSEND_SESSION_KEY.
45
+ *
46
+ * @returns Validated environment configuration
47
+ * @throws Error if configuration is invalid or missing
48
+ */
49
+ export declare function parseEnvConfig(): AmpersendEnvConfig;
50
+ export {};
51
+ //# sourceMappingURL=env.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"env.d.ts","sourceRoot":"","sources":["../../src/ampersend/env.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAA;AAIvB;;;;;;;;GAQG;AAEH,sEAAsE;AACtE,eAAO,MAAM,QAAQ,mCAAoC,CAAA;AAEzD,MAAM,MAAM,OAAO,GAAG,CAAC,OAAO,QAAQ,CAAC,CAAC,MAAM,CAAC,CAAA;AAyB/C;;GAEG;AACH,QAAA,MAAM,YAAY;;;;;;;;;;;;;;;;;;EAehB,CAAA;AAEF;;GAEG;AACH,MAAM,MAAM,kBAAkB,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,YAAY,CAAC,CAAA;AAE7D;;;;;;;;GAQG;AACH,wBAAgB,cAAc,IAAI,kBAAkB,CA4CnD"}
@@ -0,0 +1,98 @@
1
+ import { z } from "zod";
2
+ import { OWNABLE_VALIDATOR } from "../smart-account/constants.js";
3
+ /**
4
+ * Environment configuration for Ampersend smart account wallets.
5
+ *
6
+ * Supports two formats:
7
+ * 1. Combined: AMPERSEND_AGENT_KEY="address:::session_key"
8
+ * 2. Separate: AMPERSEND_SMART_ACCOUNT_ADDRESS + AMPERSEND_SESSION_KEY
9
+ *
10
+ * The combined format is checked first. Error if both formats are present.
11
+ */
12
+ /** Supported networks (Ampersend smart accounts only support Base) */
13
+ export const NETWORKS = ["base", "base-sepolia"];
14
+ /** Separator for AMPERSEND_AGENT_KEY format */
15
+ const AGENT_KEY_SEPARATOR = ":::";
16
+ /**
17
+ * Parse AMPERSEND_AGENT_KEY format: "address:::session_key"
18
+ */
19
+ function parseAgentKey(agentKey) {
20
+ const parts = agentKey.split(AGENT_KEY_SEPARATOR);
21
+ if (parts.length !== 2) {
22
+ throw new Error(`Invalid AMPERSEND_AGENT_KEY format. Expected "address${AGENT_KEY_SEPARATOR}session_key", got ${parts.length} parts`);
23
+ }
24
+ const [address, sessionKey] = parts;
25
+ if (!address.startsWith("0x")) {
26
+ throw new Error(`Invalid AMPERSEND_AGENT_KEY: address must start with 0x`);
27
+ }
28
+ if (!sessionKey.startsWith("0x")) {
29
+ throw new Error(`Invalid AMPERSEND_AGENT_KEY: session key must start with 0x`);
30
+ }
31
+ return { address, sessionKey };
32
+ }
33
+ /**
34
+ * Zod schema for validated config (after resolving AGENT_KEY)
35
+ */
36
+ const configSchema = z.object({
37
+ SMART_ACCOUNT_ADDRESS: z.string().refine((val) => val.startsWith("0x"), {
38
+ message: "SMART_ACCOUNT_ADDRESS must start with 0x",
39
+ }),
40
+ SESSION_KEY: z.string().refine((val) => val.startsWith("0x"), {
41
+ message: "SESSION_KEY must start with 0x",
42
+ }),
43
+ VALIDATOR_ADDRESS: z
44
+ .string()
45
+ .refine((val) => val.startsWith("0x"), {
46
+ message: "VALIDATOR_ADDRESS must start with 0x",
47
+ })
48
+ .default(OWNABLE_VALIDATOR),
49
+ NETWORK: z.enum(NETWORKS).default("base"),
50
+ API_URL: z.string().url().optional(),
51
+ });
52
+ /**
53
+ * Reads and validates Ampersend environment variables.
54
+ *
55
+ * Checks AMPERSEND_AGENT_KEY first (combined format), then falls back to
56
+ * separate AMPERSEND_SMART_ACCOUNT_ADDRESS + AMPERSEND_SESSION_KEY.
57
+ *
58
+ * @returns Validated environment configuration
59
+ * @throws Error if configuration is invalid or missing
60
+ */
61
+ export function parseEnvConfig() {
62
+ const agentKey = process.env.AMPERSEND_AGENT_KEY;
63
+ const smartAccountAddress = process.env.AMPERSEND_SMART_ACCOUNT_ADDRESS;
64
+ const sessionKey = process.env.AMPERSEND_SESSION_KEY;
65
+ // Check for conflicting configuration
66
+ if (agentKey && (smartAccountAddress || sessionKey)) {
67
+ throw new Error("Cannot use both AMPERSEND_AGENT_KEY and AMPERSEND_SMART_ACCOUNT_ADDRESS/AMPERSEND_SESSION_KEY. Use one or the other.");
68
+ }
69
+ let address;
70
+ let key;
71
+ if (agentKey) {
72
+ // Parse combined format
73
+ const parsed = parseAgentKey(agentKey);
74
+ address = parsed.address;
75
+ key = parsed.sessionKey;
76
+ }
77
+ else {
78
+ // Use separate env vars
79
+ address = smartAccountAddress;
80
+ key = sessionKey;
81
+ }
82
+ // Check required fields
83
+ if (!address || !key) {
84
+ throw new Error("Missing wallet configuration. Provide either:\n" +
85
+ " AMPERSEND_AGENT_KEY=address:::session_key\n" +
86
+ "or:\n" +
87
+ " AMPERSEND_SMART_ACCOUNT_ADDRESS + AMPERSEND_SESSION_KEY");
88
+ }
89
+ // Build and validate config
90
+ return configSchema.parse({
91
+ SMART_ACCOUNT_ADDRESS: address,
92
+ SESSION_KEY: key,
93
+ VALIDATOR_ADDRESS: process.env.AMPERSEND_VALIDATOR_ADDRESS,
94
+ NETWORK: process.env.AMPERSEND_NETWORK,
95
+ API_URL: process.env.AMPERSEND_API_URL,
96
+ });
97
+ }
98
+ //# sourceMappingURL=env.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"env.js","sourceRoot":"","sources":["../../src/ampersend/env.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAA;AAEvB,OAAO,EAAE,iBAAiB,EAAE,MAAM,+BAA+B,CAAA;AAEjE;;;;;;;;GAQG;AAEH,sEAAsE;AACtE,MAAM,CAAC,MAAM,QAAQ,GAAG,CAAC,MAAM,EAAE,cAAc,CAAU,CAAA;AAIzD,+CAA+C;AAC/C,MAAM,mBAAmB,GAAG,KAAK,CAAA;AAEjC;;GAEG;AACH,SAAS,aAAa,CAAC,QAAgB;IACrC,MAAM,KAAK,GAAG,QAAQ,CAAC,KAAK,CAAC,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,EAAE,OAAO,CAAC,GAAG,CAAC,iBAAiB;KACvC,CAAC,CAAA;AACJ,CAAC"}
@@ -0,0 +1,116 @@
1
+ import { Schema } from "effect";
2
+ import type { Address, Hex } from "viem";
3
+ declare const AgentInitData_base: Schema.Class<AgentInitData, {
4
+ address: Schema.optional<typeof Schema.String>;
5
+ factory: Schema.optional<typeof Schema.String>;
6
+ factoryData: Schema.optional<typeof Schema.String>;
7
+ intentExecutorInstalled: Schema.optional<typeof Schema.Boolean>;
8
+ }, Schema.Struct.Encoded<{
9
+ address: Schema.optional<typeof Schema.String>;
10
+ factory: Schema.optional<typeof Schema.String>;
11
+ factoryData: Schema.optional<typeof Schema.String>;
12
+ intentExecutorInstalled: Schema.optional<typeof Schema.Boolean>;
13
+ }>, never, {
14
+ readonly address?: string | undefined;
15
+ } & {
16
+ readonly factory?: string | undefined;
17
+ } & {
18
+ readonly factoryData?: string | undefined;
19
+ } & {
20
+ readonly intentExecutorInstalled?: boolean | undefined;
21
+ }, {}, {}>;
22
+ export declare class AgentInitData extends AgentInitData_base {
23
+ }
24
+ declare const AgentResponse_base: Schema.Class<AgentResponse, {
25
+ address: Schema.refine<string, typeof Schema.NonEmptyTrimmedString>;
26
+ name: typeof Schema.NonEmptyTrimmedString;
27
+ user_id: typeof Schema.String;
28
+ balance: typeof Schema.String;
29
+ init_data: typeof AgentInitData;
30
+ nonce: typeof Schema.String;
31
+ created_at: typeof Schema.Number;
32
+ updated_at: typeof Schema.Number;
33
+ }, Schema.Struct.Encoded<{
34
+ address: Schema.refine<string, typeof Schema.NonEmptyTrimmedString>;
35
+ name: typeof Schema.NonEmptyTrimmedString;
36
+ user_id: typeof Schema.String;
37
+ balance: typeof Schema.String;
38
+ init_data: typeof AgentInitData;
39
+ nonce: typeof Schema.String;
40
+ created_at: typeof Schema.Number;
41
+ updated_at: typeof Schema.Number;
42
+ }>, never, {
43
+ readonly nonce: string;
44
+ } & {
45
+ readonly address: string;
46
+ } & {
47
+ readonly name: string;
48
+ } & {
49
+ readonly user_id: string;
50
+ } & {
51
+ readonly balance: string;
52
+ } & {
53
+ readonly init_data: AgentInitData;
54
+ } & {
55
+ readonly created_at: number;
56
+ } & {
57
+ readonly updated_at: number;
58
+ }, {}, {}>;
59
+ export declare class AgentResponse extends AgentResponse_base {
60
+ }
61
+ export interface SpendConfig {
62
+ autoTopupAllowed?: boolean;
63
+ dailyLimit?: bigint;
64
+ monthlyLimit?: bigint;
65
+ perTransactionLimit?: bigint;
66
+ }
67
+ export interface CreateAgentOptions {
68
+ name: string;
69
+ privateKey: Hex;
70
+ spendConfig?: SpendConfig;
71
+ authorizedSellers?: Array<Address>;
72
+ }
73
+ /**
74
+ * Client for managing agents via API key authentication.
75
+ *
76
+ * The private key is used only locally to derive the agent key address;
77
+ * it is never sent to the server. The server deploys the agent account
78
+ * using an ephemeral key pattern with atomic owner swap.
79
+ *
80
+ * @example
81
+ * ```typescript
82
+ * const client = new AmpersendManagementClient({ apiKey: "sk_test_..." })
83
+ * const agent = await client.createAgent({
84
+ * name: "my-agent",
85
+ * privateKey: "0x...",
86
+ * })
87
+ * ```
88
+ */
89
+ export declare class AmpersendManagementClient {
90
+ private apiKey;
91
+ private baseUrl;
92
+ private timeout;
93
+ constructor(options: {
94
+ apiKey: string;
95
+ apiUrl?: string;
96
+ timeout?: number;
97
+ });
98
+ /**
99
+ * Create and deploy a new agent on-chain.
100
+ *
101
+ * The server handles deployment using an ephemeral key pattern:
102
+ * 1. Generates ephemeral key for deployment signing
103
+ * 2. Deploys account with ephemeral key as sole owner
104
+ * 3. Atomically adds agent key + recovery address as owners
105
+ * 4. Removes ephemeral key in same transaction (zero security window)
106
+ */
107
+ createAgent(options: CreateAgentOptions): Promise<AgentResponse>;
108
+ /**
109
+ * List all agents belonging to the authenticated user.
110
+ */
111
+ listAgents(): Promise<Array<AgentResponse>>;
112
+ private fetch;
113
+ private fetchRaw;
114
+ }
115
+ export {};
116
+ //# sourceMappingURL=management.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"management.d.ts","sourceRoot":"","sources":["../../src/ampersend/management.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAA;AAC/B,OAAO,KAAK,EAAE,OAAO,EAAE,GAAG,EAAE,MAAM,MAAM,CAAA;;;;;;;;;;;;;;;;;;;;AASxC,qBAAa,aAAc,SAAQ,kBAKjC;CAAG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAEL,qBAAa,aAAc,SAAQ,kBASjC;CAAG;AAIL,MAAM,WAAW,WAAW;IAC1B,gBAAgB,CAAC,EAAE,OAAO,CAAA;IAC1B,UAAU,CAAC,EAAE,MAAM,CAAA;IACnB,YAAY,CAAC,EAAE,MAAM,CAAA;IACrB,mBAAmB,CAAC,EAAE,MAAM,CAAA;CAC7B;AAED,MAAM,WAAW,kBAAkB;IACjC,IAAI,EAAE,MAAM,CAAA;IACZ,UAAU,EAAE,GAAG,CAAA;IACf,WAAW,CAAC,EAAE,WAAW,CAAA;IACzB,iBAAiB,CAAC,EAAE,KAAK,CAAC,OAAO,CAAC,CAAA;CACnC;AAaD;;;;;;;;;;;;;;;GAeG;AACH,qBAAa,yBAAyB;IACpC,OAAO,CAAC,MAAM,CAAQ;IACtB,OAAO,CAAC,OAAO,CAAQ;IACvB,OAAO,CAAC,OAAO,CAAQ;gBAEX,OAAO,EAAE;QAAE,MAAM,EAAE,MAAM,CAAC;QAAC,MAAM,CAAC,EAAE,MAAM,CAAC;QAAC,OAAO,CAAC,EAAE,MAAM,CAAA;KAAE;IAM1E;;;;;;;;OAQG;IACG,WAAW,CAAC,OAAO,EAAE,kBAAkB,GAAG,OAAO,CAAC,aAAa,CAAC;IActE;;OAEG;IACG,UAAU,IAAI,OAAO,CAAC,KAAK,CAAC,aAAa,CAAC,CAAC;YAKnC,KAAK;YAKL,QAAQ;CAwCvB"}
@@ -0,0 +1,129 @@
1
+ import { Schema } from "effect";
2
+ import { privateKeyToAccount } from "viem/accounts";
3
+ import { Address as AddressSchema, ApiError } from "./types.js";
4
+ const DEFAULT_API_URL = "https://api.ampersend.ai";
5
+ // ============ Response Schemas ============
6
+ export class AgentInitData extends Schema.Class("AgentInitData")({
7
+ address: Schema.optional(Schema.String),
8
+ factory: Schema.optional(Schema.String),
9
+ factoryData: Schema.optional(Schema.String),
10
+ intentExecutorInstalled: Schema.optional(Schema.Boolean),
11
+ }) {
12
+ }
13
+ export class AgentResponse extends Schema.Class("AgentResponse")({
14
+ address: AddressSchema,
15
+ name: Schema.NonEmptyTrimmedString,
16
+ user_id: Schema.String,
17
+ balance: Schema.String,
18
+ init_data: AgentInitData,
19
+ nonce: Schema.String,
20
+ created_at: Schema.Number,
21
+ updated_at: Schema.Number,
22
+ }) {
23
+ }
24
+ // ============ Helpers ============
25
+ function serializeSpendConfig(sc) {
26
+ return {
27
+ auto_topup_allowed: sc.autoTopupAllowed ?? false,
28
+ daily_limit: sc.dailyLimit != null ? String(sc.dailyLimit) : null,
29
+ monthly_limit: sc.monthlyLimit != null ? String(sc.monthlyLimit) : null,
30
+ per_transaction_limit: sc.perTransactionLimit != null ? String(sc.perTransactionLimit) : null,
31
+ };
32
+ }
33
+ /**
34
+ * Client for managing agents via API key authentication.
35
+ *
36
+ * The private key is used only locally to derive the agent key address;
37
+ * it is never sent to the server. The server deploys the agent account
38
+ * using an ephemeral key pattern with atomic owner swap.
39
+ *
40
+ * @example
41
+ * ```typescript
42
+ * const client = new AmpersendManagementClient({ apiKey: "sk_test_..." })
43
+ * const agent = await client.createAgent({
44
+ * name: "my-agent",
45
+ * privateKey: "0x...",
46
+ * })
47
+ * ```
48
+ */
49
+ export class AmpersendManagementClient {
50
+ apiKey;
51
+ baseUrl;
52
+ timeout;
53
+ constructor(options) {
54
+ this.apiKey = options.apiKey;
55
+ this.baseUrl = (options.apiUrl ?? DEFAULT_API_URL).replace(/\/$/, "");
56
+ this.timeout = options.timeout ?? 30000;
57
+ }
58
+ /**
59
+ * Create and deploy a new agent on-chain.
60
+ *
61
+ * The server handles deployment using an ephemeral key pattern:
62
+ * 1. Generates ephemeral key for deployment signing
63
+ * 2. Deploys account with ephemeral key as sole owner
64
+ * 3. Atomically adds agent key + recovery address as owners
65
+ * 4. Removes ephemeral key in same transaction (zero security window)
66
+ */
67
+ async createAgent(options) {
68
+ const account = privateKeyToAccount(options.privateKey);
69
+ const agentKeyAddress = account.address;
70
+ const payload = {
71
+ agent_key_address: agentKeyAddress,
72
+ name: options.name,
73
+ spend_config: options.spendConfig ? serializeSpendConfig(options.spendConfig) : null,
74
+ authorized_sellers: options.authorizedSellers ?? null,
75
+ };
76
+ return this.fetch("POST", "/api/v1/sdk/agents", payload, AgentResponse);
77
+ }
78
+ /**
79
+ * List all agents belonging to the authenticated user.
80
+ */
81
+ async listAgents() {
82
+ const data = await this.fetchRaw("GET", "/api/v1/sdk/agents");
83
+ return data.map((agent) => Schema.decodeUnknownSync(AgentResponse)(agent));
84
+ }
85
+ async fetch(method, path, body, schema) {
86
+ const data = await this.fetchRaw(method, path, body);
87
+ return Schema.decodeUnknownSync(schema)(data);
88
+ }
89
+ async fetchRaw(method, path, body) {
90
+ const url = `${this.baseUrl}${path}`;
91
+ const headers = {
92
+ Authorization: `Bearer ${this.apiKey}`,
93
+ };
94
+ if (body != null) {
95
+ headers["Content-Type"] = "application/json";
96
+ }
97
+ try {
98
+ const init = { method, headers, signal: AbortSignal.timeout(this.timeout) };
99
+ if (body != null) {
100
+ init.body = JSON.stringify(body);
101
+ }
102
+ const response = await globalThis.fetch(url, init);
103
+ if (!response.ok) {
104
+ let errorMessage = `HTTP ${response.status} ${response.statusText}`;
105
+ try {
106
+ const errorBody = await response.text();
107
+ if (errorBody) {
108
+ errorMessage += `: ${errorBody}`;
109
+ }
110
+ }
111
+ catch {
112
+ // Ignore error body parsing failures
113
+ }
114
+ throw new ApiError(errorMessage, response.status, response);
115
+ }
116
+ return response.json();
117
+ }
118
+ catch (error) {
119
+ if (error instanceof ApiError) {
120
+ throw error;
121
+ }
122
+ if (error instanceof Error && error.name === "AbortError") {
123
+ throw new ApiError(`Request timeout after ${this.timeout}ms`);
124
+ }
125
+ throw new ApiError(`Request failed: ${error}`);
126
+ }
127
+ }
128
+ }
129
+ //# sourceMappingURL=management.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"management.js","sourceRoot":"","sources":["../../src/ampersend/management.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAA;AAE/B,OAAO,EAAE,mBAAmB,EAAE,MAAM,eAAe,CAAA;AAEnD,OAAO,EAAE,OAAO,IAAI,aAAa,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAA;AAE/D,MAAM,eAAe,GAAG,0BAA0B,CAAA;AAElD,6CAA6C;AAE7C,MAAM,OAAO,aAAc,SAAQ,MAAM,CAAC,KAAK,CAAgB,eAAe,CAAC,CAAC;IAC9E,OAAO,EAAE,MAAM,CAAC,QAAQ,CAAC,MAAM,CAAC,MAAM,CAAC;IACvC,OAAO,EAAE,MAAM,CAAC,QAAQ,CAAC,MAAM,CAAC,MAAM,CAAC;IACvC,WAAW,EAAE,MAAM,CAAC,QAAQ,CAAC,MAAM,CAAC,MAAM,CAAC;IAC3C,uBAAuB,EAAE,MAAM,CAAC,QAAQ,CAAC,MAAM,CAAC,OAAO,CAAC;CACzD,CAAC;CAAG;AAEL,MAAM,OAAO,aAAc,SAAQ,MAAM,CAAC,KAAK,CAAgB,eAAe,CAAC,CAAC;IAC9E,OAAO,EAAE,aAAa;IACtB,IAAI,EAAE,MAAM,CAAC,qBAAqB;IAClC,OAAO,EAAE,MAAM,CAAC,MAAM;IACtB,OAAO,EAAE,MAAM,CAAC,MAAM;IACtB,SAAS,EAAE,aAAa;IACxB,KAAK,EAAE,MAAM,CAAC,MAAM;IACpB,UAAU,EAAE,MAAM,CAAC,MAAM;IACzB,UAAU,EAAE,MAAM,CAAC,MAAM;CAC1B,CAAC;CAAG;AAkBL,oCAAoC;AAEpC,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**
12
+ * Inspect mode: fetch URL and display payment requirements without paying
13
+ */
14
+ declare function runInspect(url: string, options: CliOptions): Promise<void>;
15
+ /**
16
+ * Main execution: fetch URL with automatic payment handling
17
+ */
18
+ declare function runFetch(url: string, options: CliOptions): Promise<void>;
19
+ declare function main(): Promise<void>;
20
+ export { main, runFetch, runInspect };
21
+ //# sourceMappingURL=asndurl.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"asndurl.d.ts","sourceRoot":"","sources":["../../src/cli/asndurl.ts"],"names":[],"mappings":";AAQA,UAAU,UAAU;IAClB,MAAM,EAAE,MAAM,CAAA;IACd,MAAM,CAAC,EAAE,KAAK,CAAC,MAAM,CAAC,CAAA;IACtB,IAAI,CAAC,EAAE,MAAM,CAAA;IACb,OAAO,EAAE,OAAO,CAAA;IAChB,GAAG,EAAE,OAAO,CAAA;IACZ,OAAO,EAAE,OAAO,CAAA;IAChB,KAAK,EAAE,OAAO,CAAA;CACf;AAsED;;GAEG;AACH,iBAAe,UAAU,CAAC,GAAG,EAAE,MAAM,EAAE,OAAO,EAAE,UAAU,GAAG,OAAO,CAAC,IAAI,CAAC,CAkEzE;AA+BD;;GAEG;AACH,iBAAe,QAAQ,CAAC,GAAG,EAAE,MAAM,EAAE,OAAO,EAAE,UAAU,GAAG,OAAO,CAAC,IAAI,CAAC,CA2DvE;AAED,iBAAe,IAAI,IAAI,OAAO,CAAC,IAAI,CAAC,CA6DnC;AAWD,OAAO,EAAE,IAAI,EAAE,QAAQ,EAAE,UAAU,EAAE,CAAA"}