@ampersend_ai/ampersend-sdk 0.0.21 → 0.0.25
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/ampersend/agent-client.d.ts +81 -0
- package/dist/ampersend/agent-client.d.ts.map +1 -0
- package/dist/ampersend/agent-client.js +104 -0
- package/dist/ampersend/agent-client.js.map +1 -0
- package/dist/ampersend/agent.d.ts +119 -0
- package/dist/ampersend/agent.d.ts.map +1 -0
- package/dist/ampersend/agent.js +99 -0
- package/dist/ampersend/agent.js.map +1 -0
- package/dist/ampersend/client.d.ts +32 -8
- package/dist/ampersend/client.d.ts.map +1 -1
- package/dist/ampersend/client.js +81 -3
- package/dist/ampersend/client.js.map +1 -1
- package/dist/ampersend/curated-agent.d.ts +117 -0
- package/dist/ampersend/curated-agent.d.ts.map +1 -0
- package/dist/ampersend/curated-agent.js +149 -0
- package/dist/ampersend/curated-agent.js.map +1 -0
- package/dist/ampersend/env.d.ts +0 -15
- package/dist/ampersend/env.d.ts.map +1 -1
- package/dist/ampersend/env.js +0 -4
- package/dist/ampersend/env.js.map +1 -1
- package/dist/ampersend/index.d.ts +4 -0
- package/dist/ampersend/index.d.ts.map +1 -1
- package/dist/ampersend/index.js +6 -0
- package/dist/ampersend/index.js.map +1 -1
- package/dist/ampersend/marketplace.d.ts +53 -0
- package/dist/ampersend/marketplace.d.ts.map +1 -0
- package/dist/ampersend/marketplace.js +65 -0
- package/dist/ampersend/marketplace.js.map +1 -0
- package/dist/ampersend/treasurer.d.ts +4 -0
- package/dist/ampersend/treasurer.d.ts.map +1 -1
- package/dist/ampersend/treasurer.js +2 -2
- package/dist/ampersend/treasurer.js.map +1 -1
- package/dist/ampersend/types.d.ts +39 -6
- package/dist/ampersend/types.d.ts.map +1 -1
- package/dist/ampersend/types.js +19 -1
- package/dist/ampersend/types.js.map +1 -1
- package/dist/cli/ampersend.js +47 -2
- package/dist/cli/ampersend.js.map +1 -1
- package/dist/cli/commands/agent.d.ts +22 -0
- package/dist/cli/commands/agent.d.ts.map +1 -0
- package/dist/cli/commands/agent.js +144 -0
- package/dist/cli/commands/agent.js.map +1 -0
- package/dist/cli/commands/card.d.ts +125 -0
- package/dist/cli/commands/card.d.ts.map +1 -0
- package/dist/cli/commands/card.js +399 -0
- package/dist/cli/commands/card.js.map +1 -0
- package/dist/cli/commands/config.d.ts.map +1 -1
- package/dist/cli/commands/config.js +2 -21
- package/dist/cli/commands/config.js.map +1 -1
- package/dist/cli/commands/fetch.d.ts +76 -2
- package/dist/cli/commands/fetch.d.ts.map +1 -1
- package/dist/cli/commands/fetch.js +208 -133
- package/dist/cli/commands/fetch.js.map +1 -1
- package/dist/cli/commands/fund.d.ts +3 -0
- package/dist/cli/commands/fund.d.ts.map +1 -0
- package/dist/cli/commands/fund.js +22 -0
- package/dist/cli/commands/fund.js.map +1 -0
- package/dist/cli/commands/marketplace.d.ts +22 -0
- package/dist/cli/commands/marketplace.d.ts.map +1 -0
- package/dist/cli/commands/marketplace.js +136 -0
- package/dist/cli/commands/marketplace.js.map +1 -0
- package/dist/cli/commands/version.d.ts +3 -0
- package/dist/cli/commands/version.d.ts.map +1 -0
- package/dist/cli/commands/version.js +12 -0
- package/dist/cli/commands/version.js.map +1 -0
- package/dist/cli/config.d.ts +58 -10
- package/dist/cli/config.d.ts.map +1 -1
- package/dist/cli/config.js +110 -31
- package/dist/cli/config.js.map +1 -1
- package/dist/index.d.ts +2 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -0
- package/dist/index.js.map +1 -1
- package/dist/mcp/proxy/cli.js +1 -0
- package/dist/mcp/proxy/cli.js.map +1 -1
- package/dist/mcp/proxy/factory.d.ts +2 -0
- package/dist/mcp/proxy/factory.d.ts.map +1 -1
- package/dist/mcp/proxy/factory.js +10 -1
- package/dist/mcp/proxy/factory.js.map +1 -1
- package/dist/mcp/proxy/server/init.js +1 -1
- package/dist/mcp/proxy/server/init.js.map +1 -1
- package/dist/mcp/proxy/server/server.d.ts +3 -1
- package/dist/mcp/proxy/server/server.d.ts.map +1 -1
- package/dist/mcp/proxy/server/server.js +5 -2
- package/dist/mcp/proxy/server/server.js.map +1 -1
- package/dist/mcp/proxy/types.d.ts +7 -0
- package/dist/mcp/proxy/types.d.ts.map +1 -1
- package/dist/mcp/proxy/types.js.map +1 -1
- package/dist/version.d.ts +3 -1
- package/dist/version.d.ts.map +1 -1
- package/dist/version.js +3 -1
- package/dist/version.js.map +1 -1
- package/dist/x402/http/factory.d.ts +2 -2
- package/dist/x402/http/factory.d.ts.map +1 -1
- package/dist/x402/http/factory.js +14 -8
- package/dist/x402/http/factory.js.map +1 -1
- package/dist/x402/index.d.ts +2 -0
- package/dist/x402/index.d.ts.map +1 -1
- package/dist/x402/index.js +2 -0
- package/dist/x402/index.js.map +1 -1
- package/dist/x402/siwx.d.ts +55 -0
- package/dist/x402/siwx.d.ts.map +1 -0
- package/dist/x402/siwx.js +122 -0
- package/dist/x402/siwx.js.map +1 -0
- package/dist/x402/wallets/smart-account/cosigned.d.ts +9 -2
- package/dist/x402/wallets/smart-account/cosigned.d.ts.map +1 -1
- package/dist/x402/wallets/smart-account/cosigned.js +13 -4
- package/dist/x402/wallets/smart-account/cosigned.js.map +1 -1
- package/package.json +3 -2
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
import { AgentActivityResponse, AgentAutoCollectConfigDTO, AgentFundingLinkDTO, AgentOwnerDTO, AgentSelfDTO, AgentSelfPaymentDTO, AgentSelfSpendConfigDTO } from "./agent.ts";
|
|
2
|
+
import { ApiClient } from "./client.ts";
|
|
3
|
+
import { Address, type ApiClientOptions } from "./types.ts";
|
|
4
|
+
export interface AgentReadClientOptions extends ApiClientOptions {
|
|
5
|
+
}
|
|
6
|
+
/**
|
|
7
|
+
* Read-only client for an agent's own state on the Ampersend service.
|
|
8
|
+
*
|
|
9
|
+
* Wraps the `/v1/agents/self/*` endpoints. Auth is the standard
|
|
10
|
+
* agent SIWE session token, reused from {@link ApiClient}; the session
|
|
11
|
+
* pins which agent the server will answer for, so none of these methods
|
|
12
|
+
* take an agent address.
|
|
13
|
+
*
|
|
14
|
+
* Each response is decoded against the canonical DTO from `./agent.ts`.
|
|
15
|
+
* The server imports those same DTOs, so there is no drift surface
|
|
16
|
+
* between client and server for the agent-led read endpoints.
|
|
17
|
+
*
|
|
18
|
+
* @example
|
|
19
|
+
* ```ts
|
|
20
|
+
* const agent = new AgentReadClient({
|
|
21
|
+
* baseUrl: "https://api.ampersend.ai",
|
|
22
|
+
* agentAddress,
|
|
23
|
+
* sessionKeyPrivateKey,
|
|
24
|
+
* })
|
|
25
|
+
* const snapshot = await agent.getSelf()
|
|
26
|
+
* const limits = await agent.getSpendConfig()
|
|
27
|
+
* const payments = await agent.getPayments({ preset: "30d" })
|
|
28
|
+
* ```
|
|
29
|
+
*/
|
|
30
|
+
export declare class AgentReadClient {
|
|
31
|
+
private api;
|
|
32
|
+
/**
|
|
33
|
+
* Construct from credentials (production path) or from an existing
|
|
34
|
+
* `ApiClient` (test path / sharing auth state with another SDK client).
|
|
35
|
+
* Discriminates on shape, not `instanceof` — test doubles never satisfy
|
|
36
|
+
* `instanceof ApiClient` but do expose `getAuthorized`.
|
|
37
|
+
*/
|
|
38
|
+
constructor(input: AgentReadClientOptions | ApiClient);
|
|
39
|
+
/** Full snapshot: agent record + live USDC balance. */
|
|
40
|
+
getSelf(): Promise<AgentSelfDTO>;
|
|
41
|
+
/**
|
|
42
|
+
* Spend policy (per-tx / daily / monthly limits, auto-topup) plus live
|
|
43
|
+
* remaining budgets. Throws `ApiError` with `status === 404` when no
|
|
44
|
+
* spend policy exists for this agent.
|
|
45
|
+
*/
|
|
46
|
+
getSpendConfig(): Promise<AgentSelfSpendConfigDTO>;
|
|
47
|
+
/**
|
|
48
|
+
* Auto-collect (earnings sweep) configuration. Throws `ApiError` with
|
|
49
|
+
* `status === 404` when no auto-collect configuration exists for this
|
|
50
|
+
* agent.
|
|
51
|
+
*/
|
|
52
|
+
getAutoCollectConfig(): Promise<AgentAutoCollectConfigDTO>;
|
|
53
|
+
/** Seller allowlist this agent is permitted to pay. */
|
|
54
|
+
getAuthorizedSellers(): Promise<ReadonlyArray<Address>>;
|
|
55
|
+
/** Outgoing payments. `preset` selects the timerange (default: 30d). */
|
|
56
|
+
getPayments(params?: {
|
|
57
|
+
preset?: "1d" | "30d" | "all";
|
|
58
|
+
}): Promise<ReadonlyArray<AgentSelfPaymentDTO>>;
|
|
59
|
+
/** Unified spend + earn activity, paginated. */
|
|
60
|
+
getActivity(params?: {
|
|
61
|
+
preset?: string;
|
|
62
|
+
limit?: number;
|
|
63
|
+
page?: number;
|
|
64
|
+
}): Promise<AgentActivityResponse>;
|
|
65
|
+
/** Narrow owner projection: `{ user_id, wallet_address }`. */
|
|
66
|
+
getOwner(): Promise<AgentOwnerDTO>;
|
|
67
|
+
/**
|
|
68
|
+
* Build a dashboard `/fund` URL the user can open to add USDC. The server
|
|
69
|
+
* is a pure URL formatter — no DB row, no token, no side effects. The
|
|
70
|
+
* returned URL preselects the calling agent (`destination: "agent"`, default)
|
|
71
|
+
* or the owner's main account (`destination: "main"`).
|
|
72
|
+
*
|
|
73
|
+
* `amount` is a decimal USDC string, strictly validated server-side as
|
|
74
|
+
* positive, ≤6 fractional digits, no leading zeros.
|
|
75
|
+
*/
|
|
76
|
+
getFundingLink(params?: {
|
|
77
|
+
amount?: string;
|
|
78
|
+
destination?: "agent" | "main";
|
|
79
|
+
}): Promise<AgentFundingLinkDTO>;
|
|
80
|
+
}
|
|
81
|
+
//# sourceMappingURL=agent-client.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"agent-client.d.ts","sourceRoot":"","sources":["../../src/ampersend/agent-client.ts"],"names":[],"mappings":"AAEA,OAAO,EACL,qBAAqB,EACrB,yBAAyB,EACzB,mBAAmB,EACnB,aAAa,EACb,YAAY,EACZ,mBAAmB,EACnB,uBAAuB,EACxB,MAAM,YAAY,CAAA;AACnB,OAAO,E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ponse, AgentAutoCollectConfigDTO, AgentFundingLinkDTO, AgentOwnerDTO, AgentSelfDTO, AgentSelfPaymentDTO, AgentSelfSpendConfigDTO, } from "./agent.js";
|
|
3
|
+
import { ApiClient } from "./client.js";
|
|
4
|
+
import { Address } from "./types.js";
|
|
5
|
+
/**
|
|
6
|
+
* Read-only client for an agent's own state on the Ampersend service.
|
|
7
|
+
*
|
|
8
|
+
* Wraps the `/v1/agents/self/*` endpoints. Auth is the standard
|
|
9
|
+
* agent SIWE session token, reused from {@link ApiClient}; the session
|
|
10
|
+
* pins which agent the server will answer for, so none of these methods
|
|
11
|
+
* take an agent address.
|
|
12
|
+
*
|
|
13
|
+
* Each response is decoded against the canonical DTO from `./agent.ts`.
|
|
14
|
+
* The server imports those same DTOs, so there is no drift surface
|
|
15
|
+
* between client and server for the agent-led read endpoints.
|
|
16
|
+
*
|
|
17
|
+
* @example
|
|
18
|
+
* ```ts
|
|
19
|
+
* const agent = new AgentReadClient({
|
|
20
|
+
* baseUrl: "https://api.ampersend.ai",
|
|
21
|
+
* agentAddress,
|
|
22
|
+
* sessionKeyPrivateKey,
|
|
23
|
+
* })
|
|
24
|
+
* const snapshot = await agent.getSelf()
|
|
25
|
+
* const limits = await agent.getSpendConfig()
|
|
26
|
+
* const payments = await agent.getPayments({ preset: "30d" })
|
|
27
|
+
* ```
|
|
28
|
+
*/
|
|
29
|
+
export class AgentReadClient {
|
|
30
|
+
api;
|
|
31
|
+
/**
|
|
32
|
+
* Construct from credentials (production path) or from an existing
|
|
33
|
+
* `ApiClient` (test path / sharing auth state with another SDK client).
|
|
34
|
+
* Discriminates on shape, not `instanceof` — test doubles never satisfy
|
|
35
|
+
* `instanceof ApiClient` but do expose `getAuthorized`.
|
|
36
|
+
*/
|
|
37
|
+
constructor(input) {
|
|
38
|
+
this.api = "getAuthorized" in input ? input : new ApiClient(input);
|
|
39
|
+
}
|
|
40
|
+
/** Full snapshot: agent record + live USDC balance. */
|
|
41
|
+
getSelf() {
|
|
42
|
+
return this.api.getAuthorized("/api/v1/agents/self", AgentSelfDTO);
|
|
43
|
+
}
|
|
44
|
+
/**
|
|
45
|
+
* Spend policy (per-tx / daily / monthly limits, auto-topup) plus live
|
|
46
|
+
* remaining budgets. Throws `ApiError` with `status === 404` when no
|
|
47
|
+
* spend policy exists for this agent.
|
|
48
|
+
*/
|
|
49
|
+
getSpendConfig() {
|
|
50
|
+
return this.api.getAuthorized("/api/v1/agents/self/spend-config", AgentSelfSpendConfigDTO);
|
|
51
|
+
}
|
|
52
|
+
/**
|
|
53
|
+
* Auto-collect (earnings sweep) configuration. Throws `ApiError` with
|
|
54
|
+
* `status === 404` when no auto-collect configuration exists for this
|
|
55
|
+
* agent.
|
|
56
|
+
*/
|
|
57
|
+
getAutoCollectConfig() {
|
|
58
|
+
return this.api.getAuthorized("/api/v1/agents/self/auto-collect-config", AgentAutoCollectConfigDTO);
|
|
59
|
+
}
|
|
60
|
+
/** Seller allowlist this agent is permitted to pay. */
|
|
61
|
+
getAuthorizedSellers() {
|
|
62
|
+
return this.api.getAuthorized("/api/v1/agents/self/authorized-sellers", Schema.Array(Address));
|
|
63
|
+
}
|
|
64
|
+
/** Outgoing payments. `preset` selects the timerange (default: 30d). */
|
|
65
|
+
getPayments(params = {}) {
|
|
66
|
+
const qs = params.preset ? `?preset=${params.preset}` : "";
|
|
67
|
+
return this.api.getAuthorized(`/api/v1/agents/self/payments${qs}`, Schema.Array(AgentSelfPaymentDTO));
|
|
68
|
+
}
|
|
69
|
+
/** Unified spend + earn activity, paginated. */
|
|
70
|
+
getActivity(params = {}) {
|
|
71
|
+
const qs = new URLSearchParams();
|
|
72
|
+
if (params.preset)
|
|
73
|
+
qs.set("preset", params.preset);
|
|
74
|
+
if (params.limit != null)
|
|
75
|
+
qs.set("limit", String(params.limit));
|
|
76
|
+
if (params.page != null)
|
|
77
|
+
qs.set("page", String(params.page));
|
|
78
|
+
const suffix = qs.toString();
|
|
79
|
+
return this.api.getAuthorized(`/api/v1/agents/self/activity${suffix ? `?${suffix}` : ""}`, AgentActivityResponse);
|
|
80
|
+
}
|
|
81
|
+
/** Narrow owner projection: `{ user_id, wallet_address }`. */
|
|
82
|
+
getOwner() {
|
|
83
|
+
return this.api.getAuthorized("/api/v1/agents/self/owner", AgentOwnerDTO);
|
|
84
|
+
}
|
|
85
|
+
/**
|
|
86
|
+
* Build a dashboard `/fund` URL the user can open to add USDC. The server
|
|
87
|
+
* is a pure URL formatter — no DB row, no token, no side effects. The
|
|
88
|
+
* returned URL preselects the calling agent (`destination: "agent"`, default)
|
|
89
|
+
* or the owner's main account (`destination: "main"`).
|
|
90
|
+
*
|
|
91
|
+
* `amount` is a decimal USDC string, strictly validated server-side as
|
|
92
|
+
* positive, ≤6 fractional digits, no leading zeros.
|
|
93
|
+
*/
|
|
94
|
+
getFundingLink(params = {}) {
|
|
95
|
+
const qs = new URLSearchParams();
|
|
96
|
+
if (params.amount != null)
|
|
97
|
+
qs.set("amount", params.amount);
|
|
98
|
+
if (params.destination != null)
|
|
99
|
+
qs.set("destination", params.destination);
|
|
100
|
+
const suffix = qs.toString();
|
|
101
|
+
return this.api.getAuthorized(`/api/v1/agents/self/funding-link${suffix ? `?${suffix}` : ""}`, AgentFundingLinkDTO);
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
//# sourceMappingURL=agent-client.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"agent-client.js","sourceRoot":"","sources":["../../src/ampersend/agent-client.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAA;AAE/B,OAAO,EACL,qBAAqB,EACrB,yBAAyB,EACzB,mBAAmB,EACnB,aAAa,EACb,YAAY,EACZ,mBAAmB,EACnB,uBAAuB,GACxB,MAAM,YAAY,CAAA;AACnB,OAAO,EAAE,SAAS,EAAE,MAAM,aAAa,CAAA;AACvC,OAAO,EAAE,OAAO,EAAyB,MAAM,YAAY,CAAA;AAI3D;;;;;;;;;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schema } from "effect";
|
|
2
|
+
/**
|
|
3
|
+
* Full agent snapshot with live USDC balance.
|
|
4
|
+
*
|
|
5
|
+
* All bigint amounts on `AgentSelf*` DTOs are micro-USDC (1 USDC = 10^6). The
|
|
6
|
+
* `_usdc_micro` suffix makes the unit explicit at the wire-format boundary.
|
|
7
|
+
* Note: parent DTOs shared with the dashboard (`AgentSpendConfigDTO`,
|
|
8
|
+
* `AgentAutoCollectConfigDTO`) keep their unsuffixed names to avoid breaking
|
|
9
|
+
* existing dashboard consumers; new agent-facing fields adopt the convention.
|
|
10
|
+
*/
|
|
11
|
+
export declare const AgentSelfDTO: Schema.Struct<{
|
|
12
|
+
address: Schema.refine<string, typeof Schema.NonEmptyTrimmedString>;
|
|
13
|
+
name: typeof Schema.NonEmptyTrimmedString;
|
|
14
|
+
slug: Schema.NullOr<typeof Schema.NonEmptyTrimmedString>;
|
|
15
|
+
status: Schema.Literal<["deploying", "deployed", "failed"]>;
|
|
16
|
+
published: typeof Schema.Boolean;
|
|
17
|
+
registry_id: Schema.NullOr<typeof Schema.NonEmptyTrimmedString>;
|
|
18
|
+
registry_uri: Schema.NullOr<typeof Schema.NonEmptyTrimmedString>;
|
|
19
|
+
balance_usdc_micro: typeof Schema.BigInt;
|
|
20
|
+
}>;
|
|
21
|
+
export type AgentSelfDTO = typeof AgentSelfDTO.Type;
|
|
22
|
+
/** Spend policy (per-tx / daily / monthly limits, auto-topup). */
|
|
23
|
+
export declare const AgentSpendConfigDTO: Schema.Struct<{
|
|
24
|
+
agent_address: Schema.refine<string, typeof Schema.NonEmptyTrimmedString>;
|
|
25
|
+
daily_limit: Schema.NullOr<typeof Schema.BigInt>;
|
|
26
|
+
monthly_limit: Schema.NullOr<typeof Schema.BigInt>;
|
|
27
|
+
per_transaction_limit: Schema.NullOr<typeof Schema.BigInt>;
|
|
28
|
+
auto_topup_allowed: typeof Schema.Boolean;
|
|
29
|
+
created_at: Schema.Union<[Schema.refine<number, typeof Schema.NonNegative>, Schema.filter<Schema.filter<typeof Schema.NumberFromString>>]>;
|
|
30
|
+
updated_at: Schema.Union<[Schema.refine<number, typeof Schema.NonNegative>, Schema.filter<Schema.filter<typeof Schema.NumberFromString>>]>;
|
|
31
|
+
}>;
|
|
32
|
+
export type AgentSpendConfigDTO = typeof AgentSpendConfigDTO.Type;
|
|
33
|
+
/**
|
|
34
|
+
* Spend policy plus live remaining-budget figures for the calling agent.
|
|
35
|
+
* `daily_remaining` / `monthly_remaining` are `null` when the corresponding
|
|
36
|
+
* `*_limit` isn't set (i.e. unlimited).
|
|
37
|
+
*/
|
|
38
|
+
export declare const AgentSelfSpendConfigDTO: Schema.extend<Schema.Struct<{
|
|
39
|
+
agent_address: Schema.refine<string, typeof Schema.NonEmptyTrimmedString>;
|
|
40
|
+
daily_limit: Schema.NullOr<typeof Schema.BigInt>;
|
|
41
|
+
monthly_limit: Schema.NullOr<typeof Schema.BigInt>;
|
|
42
|
+
per_transaction_limit: Schema.NullOr<typeof Schema.BigInt>;
|
|
43
|
+
auto_topup_allowed: typeof Schema.Boolean;
|
|
44
|
+
created_at: Schema.Union<[Schema.refine<number, typeof Schema.NonNegative>, Schema.filter<Schema.filter<typeof Schema.NumberFromString>>]>;
|
|
45
|
+
updated_at: Schema.Union<[Schema.refine<number, typeof Schema.NonNegative>, Schema.filter<Schema.filter<typeof Schema.NumberFromString>>]>;
|
|
46
|
+
}>, Schema.Struct<{
|
|
47
|
+
daily_remaining_usdc_micro: Schema.NullOr<typeof Schema.BigInt>;
|
|
48
|
+
monthly_remaining_usdc_micro: Schema.NullOr<typeof Schema.BigInt>;
|
|
49
|
+
}>>;
|
|
50
|
+
export type AgentSelfSpendConfigDTO = typeof AgentSelfSpendConfigDTO.Type;
|
|
51
|
+
/** Auto-collect (earnings sweep) configuration. */
|
|
52
|
+
export declare const AgentAutoCollectConfigDTO: Schema.Struct<{
|
|
53
|
+
agent_address: Schema.refine<string, typeof Schema.NonEmptyTrimmedString>;
|
|
54
|
+
enabled: typeof Schema.Boolean;
|
|
55
|
+
target_address: Schema.NullOr<Schema.refine<string, typeof Schema.NonEmptyTrimmedString>>;
|
|
56
|
+
threshold: typeof Schema.BigInt;
|
|
57
|
+
minimum_remaining: Schema.NullOr<typeof Schema.BigInt>;
|
|
58
|
+
created_at: Schema.Union<[Schema.refine<number, typeof Schema.NonNegative>, Schema.filter<Schema.filter<typeof Schema.NumberFromString>>]>;
|
|
59
|
+
updated_at: Schema.Union<[Schema.refine<number, typeof Schema.NonNegative>, Schema.filter<Schema.filter<typeof Schema.NumberFromString>>]>;
|
|
60
|
+
}>;
|
|
61
|
+
export type AgentAutoCollectConfigDTO = typeof AgentAutoCollectConfigDTO.Type;
|
|
62
|
+
/** Outgoing payment as exposed to the calling agent (excludes signature, EIP-3009 nonce, internal row id, signing-key details). */
|
|
63
|
+
export declare const AgentSelfPaymentDTO: Schema.Struct<{
|
|
64
|
+
seller_address: Schema.refine<string, typeof Schema.NonEmptyTrimmedString>;
|
|
65
|
+
amount_usdc_micro: typeof Schema.BigInt;
|
|
66
|
+
scheme: Schema.NullOr<Schema.Literal<["exact", "deferred"]>>;
|
|
67
|
+
status: Schema.Literal<["requested", "authorized", "denied", "settled", "expired", "unmanaged", "success", "failure", "pending"]>;
|
|
68
|
+
tx_hash: Schema.NullOr<Schema.filter<typeof Schema.NonEmptyTrimmedString>>;
|
|
69
|
+
chain_caip2id: Schema.NullOr<Schema.filter<typeof Schema.NonEmptyTrimmedString>>;
|
|
70
|
+
created_at: Schema.Union<[Schema.refine<number, typeof Schema.NonNegative>, Schema.filter<Schema.filter<typeof Schema.NumberFromString>>]>;
|
|
71
|
+
expires_at: Schema.NullOr<Schema.Union<[Schema.refine<number, typeof Schema.NonNegative>, Schema.filter<Schema.filter<typeof Schema.NumberFromString>>]>>;
|
|
72
|
+
}>;
|
|
73
|
+
export type AgentSelfPaymentDTO = typeof AgentSelfPaymentDTO.Type;
|
|
74
|
+
/** Single row in the unified spend + earn activity feed. */
|
|
75
|
+
export declare const UnifiedAgentActivityDTO: Schema.Struct<{
|
|
76
|
+
type: Schema.Literal<["earn", "spend"]>;
|
|
77
|
+
id: typeof Schema.String;
|
|
78
|
+
agent_address: Schema.refine<string, typeof Schema.NonEmptyTrimmedString>;
|
|
79
|
+
receiver: Schema.refine<string, typeof Schema.NonEmptyTrimmedString>;
|
|
80
|
+
amount: Schema.Union<[typeof Schema.Number, typeof Schema.NumberFromString]>;
|
|
81
|
+
status: Schema.Literal<["received", "settled", "authorized", "failed", "denied"]>;
|
|
82
|
+
timestamp: typeof Schema.BigInt;
|
|
83
|
+
tx_hash: Schema.NullOr<typeof Schema.String>;
|
|
84
|
+
chain_caip2id: Schema.NullOr<typeof Schema.String>;
|
|
85
|
+
}>;
|
|
86
|
+
export type UnifiedAgentActivityDTO = typeof UnifiedAgentActivityDTO.Type;
|
|
87
|
+
/** Paginated unified spend + earn activity response. */
|
|
88
|
+
export declare const AgentActivityResponse: Schema.Struct<{
|
|
89
|
+
activity: Schema.Array$<Schema.Struct<{
|
|
90
|
+
type: Schema.Literal<["earn", "spend"]>;
|
|
91
|
+
id: typeof Schema.String;
|
|
92
|
+
agent_address: Schema.refine<string, typeof Schema.NonEmptyTrimmedString>;
|
|
93
|
+
receiver: Schema.refine<string, typeof Schema.NonEmptyTrimmedString>;
|
|
94
|
+
amount: Schema.Union<[typeof Schema.Number, typeof Schema.NumberFromString]>;
|
|
95
|
+
status: Schema.Literal<["received", "settled", "authorized", "failed", "denied"]>;
|
|
96
|
+
timestamp: typeof Schema.BigInt;
|
|
97
|
+
tx_hash: Schema.NullOr<typeof Schema.String>;
|
|
98
|
+
chain_caip2id: Schema.NullOr<typeof Schema.String>;
|
|
99
|
+
}>>;
|
|
100
|
+
hasNextPage: typeof Schema.Boolean;
|
|
101
|
+
totalCount: Schema.refine<number, typeof Schema.NonNegative>;
|
|
102
|
+
}>;
|
|
103
|
+
export type AgentActivityResponse = typeof AgentActivityResponse.Type;
|
|
104
|
+
/** Narrow owner projection: `{ user_id, wallet_address }` — no email, sibling agents, or cross-agent aggregates. */
|
|
105
|
+
export declare const AgentOwnerDTO: Schema.Struct<{
|
|
106
|
+
user_id: Schema.brand<typeof Schema.UUID, "ID">;
|
|
107
|
+
wallet_address: Schema.refine<string, typeof Schema.NonEmptyTrimmedString>;
|
|
108
|
+
}>;
|
|
109
|
+
export type AgentOwnerDTO = typeof AgentOwnerDTO.Type;
|
|
110
|
+
/**
|
|
111
|
+
* Funding link the agent can present to its owner. The URL points at the
|
|
112
|
+
* dashboard's `/fund` page, prefilled per the requested destination. Pure
|
|
113
|
+
* URL formatter on the server — no DB row, no token, no side effects.
|
|
114
|
+
*/
|
|
115
|
+
export declare const AgentFundingLinkDTO: Schema.Struct<{
|
|
116
|
+
url: typeof Schema.String;
|
|
117
|
+
}>;
|
|
118
|
+
export type AgentFundingLinkDTO = typeof AgentFundingLinkDTO.Type;
|
|
119
|
+
//# sourceMappingURL=agent.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"agent.d.ts","sourceRoot":"","sources":["../../src/ampersend/agent.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAA;AAY/B;;;;;;;;GAQG;AACH,eAAO,MAAM,YAAY;;;;;;;;;EASvB,CAAA;AACF,MAAM,MAAM,YAAY,GAAG,OAAO,YAAY,CAAC,IAAI,CAAA;AAEnD,kEAAkE;AAClE,eAAO,MAAM,mBAAmB;;;;;;;;EAQ9B,CAAA;AACF,MAAM,MAAM,mBAAmB,GAAG,OAAO,mBAAmB,CAAC,IAAI,CAAA;AAEjE;;;;GAIG;AACH,eAAO,MAAM,uBAAuB;;;;;;;;;;;GAMnC,CAAA;AACD,MAAM,MAAM,uBAAuB,GAAG,OAAO,uBAAuB,CAAC,IAAI,CAAA;AAEzE,mDAAmD;AACnD,eAAO,MAAM,yBAAyB;;;;;;;;EAQpC,CAAA;AACF,MAAM,MAAM,yBAAyB,GAAG,OAAO,yBAAyB,CAAC,IAAI,CAAA;AAE7E,mIAAmI;AACnI,eAAO,MAAM,mBAAmB;;;;;;;;;EAmB9B,CAAA;AACF,MAAM,MAAM,mBAAmB,GAAG,OAAO,mBAAmB,CAAC,IAAI,CAAA;AAEjE,4DAA4D;AAC5D,eAAO,MAAM,uBAAuB;;;;;;;;;;EAUlC,CAAA;AACF,MAAM,MAAM,uBAAuB,GAAG,OAAO,uBAAuB,CAAC,IAAI,CAAA;AAEzE,wDAAwD;AACxD,eAAO,MAAM,qBAAqB;;;;;;;;;;;;;;EAIhC,CAAA;AACF,MAAM,MAAM,qBAAqB,GAAG,OAAO,qBAAqB,CAAC,IAAI,CAAA;AAErE,oHAAoH;AACpH,eAAO,MAAM,aAAa;;;EAGxB,CAAA;AACF,MAAM,MAAM,aAAa,GAAG,OAAO,aAAa,CAAC,IAAI,CAAA;AAErD;;;;GAIG;AACH,eAAO,MAAM,mBAAmB;;EAE9B,CAAA;AACF,MAAM,MAAM,mBAAmB,GAAG,OAAO,mBAAmB,CAAC,IAAI,CAAA"}
|
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
import { Schema } from "effect";
|
|
2
|
+
import { Address, Caip2ID, ConvertedTimestamp, ID, Scheme, TxHash } from "./types.js";
|
|
3
|
+
// Response DTOs for `/v1/agents/self/*`. These are the canonical wire shapes
|
|
4
|
+
// for the agent-led read surface: the closed-source server imports them from
|
|
5
|
+
// this file (via `@ampersend_ai/ampersend-sdk/ampersend`) rather than defining
|
|
6
|
+
// its own copies. Keep field sets stable — adding/removing a field here is a
|
|
7
|
+
// breaking change for both SDK consumers and server callers.
|
|
8
|
+
const DeploymentStatus = Schema.Literal("deploying", "deployed", "failed");
|
|
9
|
+
/**
|
|
10
|
+
* Full agent snapshot with live USDC balance.
|
|
11
|
+
*
|
|
12
|
+
* All bigint amounts on `AgentSelf*` DTOs are micro-USDC (1 USDC = 10^6). The
|
|
13
|
+
* `_usdc_micro` suffix makes the unit explicit at the wire-format boundary.
|
|
14
|
+
* Note: parent DTOs shared with the dashboard (`AgentSpendConfigDTO`,
|
|
15
|
+
* `AgentAutoCollectConfigDTO`) keep their unsuffixed names to avoid breaking
|
|
16
|
+
* existing dashboard consumers; new agent-facing fields adopt the convention.
|
|
17
|
+
*/
|
|
18
|
+
export const AgentSelfDTO = Schema.Struct({
|
|
19
|
+
address: Address,
|
|
20
|
+
name: Schema.NonEmptyTrimmedString,
|
|
21
|
+
slug: Schema.NullOr(Schema.NonEmptyTrimmedString),
|
|
22
|
+
status: DeploymentStatus,
|
|
23
|
+
published: Schema.Boolean,
|
|
24
|
+
registry_id: Schema.NullOr(Schema.NonEmptyTrimmedString),
|
|
25
|
+
registry_uri: Schema.NullOr(Schema.NonEmptyTrimmedString),
|
|
26
|
+
balance_usdc_micro: Schema.BigInt,
|
|
27
|
+
});
|
|
28
|
+
/** Spend policy (per-tx / daily / monthly limits, auto-topup). */
|
|
29
|
+
export const AgentSpendConfigDTO = Schema.Struct({
|
|
30
|
+
agent_address: Address,
|
|
31
|
+
daily_limit: Schema.NullOr(Schema.BigInt),
|
|
32
|
+
monthly_limit: Schema.NullOr(Schema.BigInt),
|
|
33
|
+
per_transaction_limit: Schema.NullOr(Schema.BigInt),
|
|
34
|
+
auto_topup_allowed: Schema.Boolean,
|
|
35
|
+
created_at: ConvertedTimestamp,
|
|
36
|
+
updated_at: ConvertedTimestamp,
|
|
37
|
+
});
|
|
38
|
+
/**
|
|
39
|
+
* Spend policy plus live remaining-budget figures for the calling agent.
|
|
40
|
+
* `daily_remaining` / `monthly_remaining` are `null` when the corresponding
|
|
41
|
+
* `*_limit` isn't set (i.e. unlimited).
|
|
42
|
+
*/
|
|
43
|
+
export const AgentSelfSpendConfigDTO = Schema.extend(AgentSpendConfigDTO, Schema.Struct({
|
|
44
|
+
daily_remaining_usdc_micro: Schema.NullOr(Schema.BigInt),
|
|
45
|
+
monthly_remaining_usdc_micro: Schema.NullOr(Schema.BigInt),
|
|
46
|
+
}));
|
|
47
|
+
/** Auto-collect (earnings sweep) configuration. */
|
|
48
|
+
export const AgentAutoCollectConfigDTO = Schema.Struct({
|
|
49
|
+
agent_address: Address,
|
|
50
|
+
enabled: Schema.Boolean,
|
|
51
|
+
target_address: Schema.NullOr(Address),
|
|
52
|
+
threshold: Schema.BigInt,
|
|
53
|
+
minimum_remaining: Schema.NullOr(Schema.BigInt),
|
|
54
|
+
created_at: ConvertedTimestamp,
|
|
55
|
+
updated_at: ConvertedTimestamp,
|
|
56
|
+
});
|
|
57
|
+
/** Outgoing payment as exposed to the calling agent (excludes signature, EIP-3009 nonce, internal row id, signing-key details). */
|
|
58
|
+
export const AgentSelfPaymentDTO = Schema.Struct({
|
|
59
|
+
seller_address: Address,
|
|
60
|
+
amount_usdc_micro: Schema.BigInt,
|
|
61
|
+
scheme: Schema.NullOr(Scheme),
|
|
62
|
+
status: Schema.Literal("requested", "authorized", "denied", "settled", "expired", "unmanaged", "success", "failure", "pending"),
|
|
63
|
+
tx_hash: Schema.NullOr(TxHash),
|
|
64
|
+
chain_caip2id: Schema.NullOr(Caip2ID),
|
|
65
|
+
created_at: ConvertedTimestamp,
|
|
66
|
+
expires_at: Schema.NullOr(ConvertedTimestamp),
|
|
67
|
+
});
|
|
68
|
+
/** Single row in the unified spend + earn activity feed. */
|
|
69
|
+
export const UnifiedAgentActivityDTO = Schema.Struct({
|
|
70
|
+
type: Schema.Literal("earn", "spend"),
|
|
71
|
+
id: Schema.String,
|
|
72
|
+
agent_address: Address,
|
|
73
|
+
receiver: Address,
|
|
74
|
+
amount: Schema.Union(Schema.Number, Schema.NumberFromString),
|
|
75
|
+
status: Schema.Literal("received", "settled", "authorized", "failed", "denied"),
|
|
76
|
+
timestamp: Schema.BigInt,
|
|
77
|
+
tx_hash: Schema.NullOr(Schema.String),
|
|
78
|
+
chain_caip2id: Schema.NullOr(Schema.String),
|
|
79
|
+
});
|
|
80
|
+
/** Paginated unified spend + earn activity response. */
|
|
81
|
+
export const AgentActivityResponse = Schema.Struct({
|
|
82
|
+
activity: Schema.Array(UnifiedAgentActivityDTO),
|
|
83
|
+
hasNextPage: Schema.Boolean,
|
|
84
|
+
totalCount: Schema.NonNegativeInt,
|
|
85
|
+
});
|
|
86
|
+
/** Narrow owner projection: `{ user_id, wallet_address }` — no email, sibling agents, or cross-agent aggregates. */
|
|
87
|
+
export const AgentOwnerDTO = Schema.Struct({
|
|
88
|
+
user_id: ID,
|
|
89
|
+
wallet_address: Address,
|
|
90
|
+
});
|
|
91
|
+
/**
|
|
92
|
+
* Funding link the agent can present to its owner. The URL points at the
|
|
93
|
+
* dashboard's `/fund` page, prefilled per the requested destination. Pure
|
|
94
|
+
* URL formatter on the server — no DB row, no token, no side effects.
|
|
95
|
+
*/
|
|
96
|
+
export const AgentFundingLinkDTO = Schema.Struct({
|
|
97
|
+
url: Schema.String,
|
|
98
|
+
});
|
|
99
|
+
//# sourceMappingURL=agent.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"agent.js","sourceRoot":"","sources":["../../src/ampersend/agent.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAA;AAE/B,OAAO,EAAE,OAAO,EAAE,OAAO,EAAE,kBAAkB,EAAE,EAAE,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,YAAY,CAAA;AAErF,6EAA6E;AAC7E,6EAA6E;AAC7E,+EAA+E;AAC/E,6EAA6E;AAC7E,6DAA6D;AAE7D,MAAM,gBAAgB,GAAG,MAAM,CAAC,OAAO,CAAC,WAAW,EAAE,UAAU,EAAE,QAAQ,CAAC,CAAA;AAE1E;;;;;;;;GAQG;AACH,MAAM,CAAC,MAAM,YAAY,GAAG,MAAM,CAAC,MAAM,CAAC;IACxC,OAAO,EAAE,OAAO;IAChB,IAAI,EAAE,MAAM,CAAC,qBAAqB;IAClC,IAAI,EAAE,MAAM,CAAC,MAAM,CAAC,MAAM,CAAC,qBAAqB,CAAC;IACjD,MAAM,EAAE,gBAAgB;IACxB,SAA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;AACxD,MAAM,CAAC,MAAM,qBAAqB,GAAG,MAAM,CAAC,MAAM,CAAC;IACjD,QAAQ,EAAE,MAAM,CAAC,KAAK,CAAC,uBAAuB,CAAC;IAC/C,WAAW,EAAE,MAAM,CAAC,OAAO;IAC3B,UAAU,EAAE,MAAM,CAAC,cAAc;CAClC,CAAC,CAAA;AAGF,oHAAoH;AACpH,MAAM,CAAC,MAAM,aAAa,GAAG,MAAM,CAAC,MAAM,CAAC;IACzC,OAAO,EAAE,EAAE;IACX,cAAc,EAAE,OAAO;CACxB,CAAC,CAAA;AAGF;;;;GAIG;AACH,MAAM,CAAC,MAAM,mBAAmB,GAAG,MAAM,CAAC,MAAM,CAAC;IAC/C,GAAG,EAAE,MAAM,CAAC,MAAM;CACnB,CAAC,CAAA"}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
|
+
import { Schema } from "effect";
|
|
1
2
|
import type { PaymentAuthorization, PaymentRequest } from "../x402/envelopes.ts";
|
|
2
|
-
import { AgentAuthorizeRequest, AgentAuthorizeResponse, AgentPaymentEventResponse, type Address, type ApiClientOptions, type PaymentEvent } from "./types.js";
|
|
3
|
+
import { AgentAuthorizeRequest, AgentAuthorizeResponse, AgentPaymentEventResponse, SignSiwxResponse, type Address, type ApiClientOptions, type PaymentEvent } from "./types.js";
|
|
3
4
|
export * from "./types.js";
|
|
4
5
|
/**
|
|
5
6
|
* TypeScript SDK for the API
|
|
@@ -8,10 +9,17 @@ export * from "./types.js";
|
|
|
8
9
|
* including SIWE authentication and payment lifecycle management.
|
|
9
10
|
*/
|
|
10
11
|
export declare class ApiClient {
|
|
11
|
-
private baseUrl;
|
|
12
|
-
private sessionKeyPrivateKey;
|
|
13
|
-
private agentAddress;
|
|
14
|
-
private timeout;
|
|
12
|
+
private readonly baseUrl;
|
|
13
|
+
private readonly sessionKeyPrivateKey;
|
|
14
|
+
private readonly agentAddress;
|
|
15
|
+
private readonly timeout;
|
|
16
|
+
/**
|
|
17
|
+
* `Ampersend-Client` header value sent on every authenticated request.
|
|
18
|
+
* Format: `<name>/<version>`. Used by the API for product-analytics
|
|
19
|
+
* client attribution. Defaults to `sdk-typescript/<VERSION>`; the
|
|
20
|
+
* `ampersend` CLI overrides `clientName` to `ampersend-cli`.
|
|
21
|
+
*/
|
|
22
|
+
private clientHeader;
|
|
15
23
|
private authMutex;
|
|
16
24
|
private auth;
|
|
17
25
|
constructor(options: ApiClientOptions);
|
|
@@ -20,15 +28,31 @@ export declare class ApiClient {
|
|
|
20
28
|
*/
|
|
21
29
|
private performAuthentication;
|
|
22
30
|
authorizePayment(paymentRequest: PaymentRequest, context?: AgentAuthorizeRequest["context"]): Promise<typeof AgentAuthorizeResponse.Type>;
|
|
31
|
+
/**
|
|
32
|
+
* Ask the Ampersend API to co-sign a Sign-In-With-X (CAIP-122 / EIP-4361)
|
|
33
|
+
* message. The service parses the message, verifies it claims this agent's
|
|
34
|
+
* smart account, and signs `hashMessage(message)` with the service key.
|
|
35
|
+
*
|
|
36
|
+
* The buyer concatenates this with its own session-key signature and wraps
|
|
37
|
+
* via CoSignerValidator for ERC-1271 verification.
|
|
38
|
+
*/
|
|
39
|
+
signSiwxChallenge(message: string): Promise<typeof SignSiwxResponse.Type>;
|
|
23
40
|
reportPaymentEvent(eventId: string, payment: PaymentAuthorization, event: PaymentEvent): Promise<AgentPaymentEventResponse>;
|
|
41
|
+
/**
|
|
42
|
+
* Authenticated GET against a path on the API. Performs SIWE auth first
|
|
43
|
+
* if needed, then decodes the response against `schema`. Use this from
|
|
44
|
+
* read-only clients that share auth with the rest of the SDK.
|
|
45
|
+
*/
|
|
46
|
+
getAuthorized<A, I>(path: string, schema: Schema.Schema<A, I>): Promise<A>;
|
|
24
47
|
/**
|
|
25
48
|
* Clear the current authentication state
|
|
26
49
|
*/
|
|
27
50
|
clearAuth(): void;
|
|
28
51
|
/**
|
|
29
|
-
* Get the configured agent address
|
|
52
|
+
* Get the configured agent address, or `undefined` if the client was
|
|
53
|
+
* constructed for unauthenticated reads only.
|
|
30
54
|
*/
|
|
31
|
-
getAgentAddress(): Address;
|
|
55
|
+
getAgentAddress(): Address | undefined;
|
|
32
56
|
/**
|
|
33
57
|
* Check if currently authenticated and token is valid
|
|
34
58
|
*/
|
|
@@ -40,6 +64,6 @@ export declare class ApiClient {
|
|
|
40
64
|
/**
|
|
41
65
|
* Internal fetch wrapper with error handling and schema decoding
|
|
42
66
|
*/
|
|
43
|
-
|
|
67
|
+
fetch<A, I>(path: string, init: RequestInit, schema: Schema.Schema<A, I>): Promise<A>;
|
|
44
68
|
}
|
|
45
69
|
//# sourceMappingURL=client.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"client.d.ts","sourceRoot":"","sources":["../../src/ampersend/client.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"client.d.ts","sourceRoot":"","sources":["../../src/ampersend/client.ts"],"names":[],"mappings":"AACA,OAAO,EAAY,MAAM,EAAE,MAAM,QAAQ,CAAA;AAKzC,OAAO,KAAK,EAAE,oBAAoB,EAAE,cAAc,EAAE,MAAM,sBAAsB,CAAA;AAChF,OAAO,EACL,qBAAqB,EACrB,sBAAsB,EAEtB,yBAAyB,EAEzB,gBAAgB,EAGhB,KAAK,OAAO,EACZ,KAAK,gBAAgB,EAErB,KAAK,YAAY,EAElB,MAAM,YAAY,CAAA;AAEnB,cAAc,YAAY,CAAA;AA2B1B;;;;;GAKG;AACH,qBAAa,SAAS;IACpB,OAAO,CAAC,QAAQ,CAAC,OAAO,CAAQ;IAChC,OAAO,CAAC,QAAQ,CAAC,oBAAoB,CAA2B;IAChE,OAAO,CAAC,QAAQ,CAAC,YAAY,CAAqB;IAClD,OAAO,CAAC,QAAQ,CAAC,OAAO,CAAQ;IAChC;;;;;OAKG;IACH,OAAO,CAAC,YAAY,CAAQ;IAC5B,OAAO,CAAC,SAAS,CAAc;IAC/B,OAAO,CAAC,IAAI,CAGX;gBAEW,OAAO,EAAE,gBAAgB;IASrC;;OAEG;YACW,qBAAqB;IAsE7B,gBAAgB,CACpB,cAAc,EAAE,cAAc,EAC9B,OAAO,CAAC,EAAE,qBAAqB,CAAC,SAAS,CAAC,GACzC,OAAO,CAAC,OAAO,sBAAsB,CAAC,IAAI,CAAC;IAoC9C;;;;;;;OAOG;IACG,iBAAiB,CAAC,OAAO,EAAE,MAAM,GAAG,OAAO,CAAC,OAAO,gBAAgB,CAAC,IAAI,CAAC;IAiBzE,kBAAkB,CACtB,OAAO,EAAE,MAAM,EACf,OAAO,EAAE,oBAAoB,EAC7B,KAAK,EAAE,YAAY,GAClB,OAAO,CAAC,yBAAyB,CAAC;IAoBrC;;;;OAIG;IACG,aAAa,CAAC,CAAC,EAAE,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,CAAC,MAAM,CAAC,CAAC,EAAE,CAAC,CAAC,GAAG,OAAO,CAAC,CAAC,CAAC;IAYhF;;OAEG;IACH,SAAS,IAAI,IAAI;IAOjB;;;OAGG;IACH,eAAe,IAAI,OAAO,GAAG,SAAS;IAItC;;OAEG;IACH,eAAe,IAAI,OAAO;IAI1B;;OAEG;YACW,mBAAmB;IAQjC;;OAEG;IACG,KAAK,CAAC,CAAC,EAAE,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,WAAW,EAAE,MAAM,EAAE,MAAM,CAAC,MAAM,CAAC,CAAC,EAAE,CAAC,CAAC,GAAG,OAAO,CAAC,CAAC,CAAC;CA2C5F"}
|
package/dist/ampersend/client.js
CHANGED
|
@@ -2,8 +2,34 @@ import { Mutex } from "async-mutex";
|
|
|
2
2
|
import { DateTime, Schema } from "effect";
|
|
3
3
|
import { SiweMessage } from "siwe";
|
|
4
4
|
import { privateKeyToAccount } from "viem/accounts";
|
|
5
|
-
import {
|
|
5
|
+
import { VERSION } from "../version.js";
|
|
6
|
+
import { AgentAuthorizeRequest, AgentAuthorizeResponse, AgentPaymentEventReport, AgentPaymentEventResponse, ApiError, SignSiwxResponse, SIWELoginResponse, SIWENonceResponse, } from "./types.js";
|
|
6
7
|
export * from "./types.js";
|
|
8
|
+
/**
|
|
9
|
+
* Best-effort summary of an HTTP error body. The server emits Effect Schema
|
|
10
|
+
* decode errors as JSON like `{ _tag: "HttpApiDecodeError", issues: [{ path,
|
|
11
|
+
* message }, ...], message: "<long indented blob>" }`. The raw `message` is
|
|
12
|
+
* unreadable; collapse `issues[]` into a flat string instead. For anything
|
|
13
|
+
* we don't recognise — including non-JSON bodies — return the body verbatim.
|
|
14
|
+
*/
|
|
15
|
+
function formatServerErrorBody(body) {
|
|
16
|
+
try {
|
|
17
|
+
const { issues, message } = JSON.parse(body);
|
|
18
|
+
if (Array.isArray(issues) && issues.length > 0) {
|
|
19
|
+
return issues
|
|
20
|
+
.map((i) => {
|
|
21
|
+
const path = Array.isArray(i?.path) && i.path.length > 0 ? i.path.join(".") : null;
|
|
22
|
+
const msg = typeof i?.message === "string" ? i.message : "validation failed";
|
|
23
|
+
return path ? `${path}: ${msg}` : msg;
|
|
24
|
+
})
|
|
25
|
+
.join("; ");
|
|
26
|
+
}
|
|
27
|
+
return typeof message === "string" ? message : body;
|
|
28
|
+
}
|
|
29
|
+
catch {
|
|
30
|
+
return body;
|
|
31
|
+
}
|
|
32
|
+
}
|
|
7
33
|
/**
|
|
8
34
|
* TypeScript SDK for the API
|
|
9
35
|
*
|
|
@@ -15,6 +41,13 @@ export class ApiClient {
|
|
|
15
41
|
sessionKeyPrivateKey;
|
|
16
42
|
agentAddress;
|
|
17
43
|
timeout;
|
|
44
|
+
/**
|
|
45
|
+
* `Ampersend-Client` header value sent on every authenticated request.
|
|
46
|
+
* Format: `<name>/<version>`. Used by the API for product-analytics
|
|
47
|
+
* client attribution. Defaults to `sdk-typescript/<VERSION>`; the
|
|
48
|
+
* `ampersend` CLI overrides `clientName` to `ampersend-cli`.
|
|
49
|
+
*/
|
|
50
|
+
clientHeader;
|
|
18
51
|
authMutex = new Mutex();
|
|
19
52
|
auth = {
|
|
20
53
|
token: null,
|
|
@@ -25,6 +58,8 @@ export class ApiClient {
|
|
|
25
58
|
this.sessionKeyPrivateKey = options.sessionKeyPrivateKey;
|
|
26
59
|
this.agentAddress = options.agentAddress;
|
|
27
60
|
this.timeout = options.timeout ?? 30000;
|
|
61
|
+
const clientName = options.clientName ?? "sdk-typescript";
|
|
62
|
+
this.clientHeader = `${clientName}/${VERSION}`;
|
|
28
63
|
}
|
|
29
64
|
/**
|
|
30
65
|
* Internal method to perform authentication without mutex (for use within mutex)
|
|
@@ -33,6 +68,9 @@ export class ApiClient {
|
|
|
33
68
|
if (!this.sessionKeyPrivateKey) {
|
|
34
69
|
throw new ApiError("Session key private key is required for authentication");
|
|
35
70
|
}
|
|
71
|
+
if (!this.agentAddress) {
|
|
72
|
+
throw new ApiError("Agent address is required for authentication");
|
|
73
|
+
}
|
|
36
74
|
try {
|
|
37
75
|
const account = privateKeyToAccount(this.sessionKeyPrivateKey);
|
|
38
76
|
const sessionKeyAddress = account.address;
|
|
@@ -112,6 +150,25 @@ export class ApiClient {
|
|
|
112
150
|
checkIndex(rej.acceptsIndex, "rejected");
|
|
113
151
|
return response;
|
|
114
152
|
}
|
|
153
|
+
/**
|
|
154
|
+
* Ask the Ampersend API to co-sign a Sign-In-With-X (CAIP-122 / EIP-4361)
|
|
155
|
+
* message. The service parses the message, verifies it claims this agent's
|
|
156
|
+
* smart account, and signs `hashMessage(message)` with the service key.
|
|
157
|
+
*
|
|
158
|
+
* The buyer concatenates this with its own session-key signature and wraps
|
|
159
|
+
* via CoSignerValidator for ERC-1271 verification.
|
|
160
|
+
*/
|
|
161
|
+
async signSiwxChallenge(message) {
|
|
162
|
+
await this.ensureAuthenticated();
|
|
163
|
+
return this.fetch(`/api/v1/agents/${this.agentAddress}/auth/sign-siwx`, {
|
|
164
|
+
method: "POST",
|
|
165
|
+
headers: {
|
|
166
|
+
"Content-Type": "application/json",
|
|
167
|
+
Authorization: `Bearer ${this.auth.token}`,
|
|
168
|
+
},
|
|
169
|
+
body: JSON.stringify({ message }),
|
|
170
|
+
}, SignSiwxResponse);
|
|
171
|
+
}
|
|
115
172
|
async reportPaymentEvent(eventId, payment, event) {
|
|
116
173
|
await this.ensureAuthenticated();
|
|
117
174
|
const report = { id: eventId, payment, event };
|
|
@@ -125,6 +182,18 @@ export class ApiClient {
|
|
|
125
182
|
body: JSON.stringify(wireBody),
|
|
126
183
|
}, AgentPaymentEventResponse);
|
|
127
184
|
}
|
|
185
|
+
/**
|
|
186
|
+
* Authenticated GET against a path on the API. Performs SIWE auth first
|
|
187
|
+
* if needed, then decodes the response against `schema`. Use this from
|
|
188
|
+
* read-only clients that share auth with the rest of the SDK.
|
|
189
|
+
*/
|
|
190
|
+
async getAuthorized(path, schema) {
|
|
191
|
+
await this.ensureAuthenticated();
|
|
192
|
+
return this.fetch(path, {
|
|
193
|
+
method: "GET",
|
|
194
|
+
headers: { Authorization: `Bearer ${this.auth.token}` },
|
|
195
|
+
}, schema);
|
|
196
|
+
}
|
|
128
197
|
/**
|
|
129
198
|
* Clear the current authentication state
|
|
130
199
|
*/
|
|
@@ -135,7 +204,8 @@ export class ApiClient {
|
|
|
135
204
|
};
|
|
136
205
|
}
|
|
137
206
|
/**
|
|
138
|
-
* Get the configured agent address
|
|
207
|
+
* Get the configured agent address, or `undefined` if the client was
|
|
208
|
+
* constructed for unauthenticated reads only.
|
|
139
209
|
*/
|
|
140
210
|
getAgentAddress() {
|
|
141
211
|
return this.agentAddress;
|
|
@@ -162,8 +232,16 @@ export class ApiClient {
|
|
|
162
232
|
async fetch(path, init, schema) {
|
|
163
233
|
const url = `${this.baseUrl}${path}`;
|
|
164
234
|
try {
|
|
235
|
+
// Merge in the Ampersend-Client header so the API can attribute
|
|
236
|
+
// product-analytics events to SDK vs CLI vs library callers.
|
|
237
|
+
// Caller-supplied headers win on conflict.
|
|
238
|
+
const headers = new Headers(init.headers);
|
|
239
|
+
if (!headers.has("Ampersend-Client")) {
|
|
240
|
+
headers.set("Ampersend-Client", this.clientHeader);
|
|
241
|
+
}
|
|
165
242
|
const response = await fetch(url, {
|
|
166
243
|
...init,
|
|
244
|
+
headers,
|
|
167
245
|
signal: AbortSignal.timeout(this.timeout),
|
|
168
246
|
});
|
|
169
247
|
if (!response.ok) {
|
|
@@ -171,7 +249,7 @@ export class ApiClient {
|
|
|
171
249
|
try {
|
|
172
250
|
const errorBody = await response.text();
|
|
173
251
|
if (errorBody) {
|
|
174
|
-
errorMessage += `: ${errorBody}`;
|
|
252
|
+
errorMessage += `: ${formatServerErrorBody(errorBody)}`;
|
|
175
253
|
}
|
|
176
254
|
}
|
|
177
255
|
catch {
|