acn-client 0.6.3 → 0.8.0
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/README.md +21 -6
- package/dist/index.d.mts +161 -42
- package/dist/index.d.ts +161 -42
- package/dist/index.js +83 -16
- package/dist/index.mjs +82 -16
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -111,8 +111,8 @@ Options:
|
|
|
111
111
|
|--------|-------------|
|
|
112
112
|
| `listSubnets()` | List all subnets |
|
|
113
113
|
| `getSubnet(subnetId)` | Get subnet by ID |
|
|
114
|
-
| `createSubnet(request)` | Create a new subnet |
|
|
115
|
-
| `deleteSubnet(subnetId
|
|
114
|
+
| `createSubnet(request)` | Create a new subnet (you become the owner) |
|
|
115
|
+
| `deleteSubnet(subnetId)` | Delete a subnet you own |
|
|
116
116
|
| `getSubnetAgents(subnetId)` | Get agents in subnet |
|
|
117
117
|
| `joinSubnet(agentId, subnetId)` | Join agent to subnet |
|
|
118
118
|
| `leaveSubnet(agentId, subnetId)` | Remove agent from subnet |
|
|
@@ -146,13 +146,28 @@ Options:
|
|
|
146
146
|
|
|
147
147
|
| Method | Description |
|
|
148
148
|
|--------|-------------|
|
|
149
|
-
| `discoverPaymentAgents(
|
|
149
|
+
| `discoverPaymentAgents({ method?, network? })` | Find agents accepting payments (lowercase enum values) |
|
|
150
150
|
| `getPaymentCapability(agentId)` | Get agent's payment capability |
|
|
151
|
-
| `setPaymentCapability(agentId, capability)` | Set
|
|
152
|
-
| `
|
|
153
|
-
| `
|
|
151
|
+
| `setPaymentCapability(agentId, capability)` | Set accepted methods/networks/wallets |
|
|
152
|
+
| `getTokenPricing(agentId)` | Get an agent's per-million-token pricing |
|
|
153
|
+
| `setTokenPricing(agentId, { input_price_per_million, output_price_per_million })` | Set OpenAI-style per-million-token pricing (USD) |
|
|
154
|
+
| `createPaymentTask({ from_agent, to_agent, amount, currency, payment_method, network, ... })` | Create a payment task (`from_agent` must equal authenticated agent) |
|
|
155
|
+
| `estimateCost({ agent_id, estimated_input_tokens?, estimated_output_tokens? })` | Estimate cost of calling an agent before invoking |
|
|
156
|
+
| `getAgentPaymentTasks(agentId, { status?, limit? })` | List the payment tasks the agent is involved in |
|
|
157
|
+
| `getPaymentTask(taskId)` | Get a payment task (server requires internal token) |
|
|
154
158
|
| `getPaymentStats(agentId)` | Get payment statistics |
|
|
155
159
|
|
|
160
|
+
> **Migration from 0.6.x → 0.7.0** — `PaymentMethod` and `PaymentNetwork`
|
|
161
|
+
> are now lowercase string-literal unions (e.g. `'usdc'`, `'base'`),
|
|
162
|
+
> aligning with the ACN server. Update any literal comparisons
|
|
163
|
+
> accordingly. `PaymentTask.status` is now `string`; use the new
|
|
164
|
+
> `KNOWN_PAYMENT_TASK_STATUSES` constant for known values.
|
|
165
|
+
> `PaymentTask` and `PaymentCapability` field sets now mirror the server
|
|
166
|
+
> contract (`task_id`/`buyer_agent`/`seller_agent`,
|
|
167
|
+
> `wallet_addresses`/`token_pricing`). `PaymentDiscoveryOptions` no
|
|
168
|
+
> longer accepts `min_amount` / `max_amount` (the server never read
|
|
169
|
+
> them).
|
|
170
|
+
|
|
156
171
|
#### Monitoring Methods
|
|
157
172
|
|
|
158
173
|
| Method | Description |
|
package/dist/index.d.mts
CHANGED
|
@@ -329,50 +329,100 @@ interface PendingSessionsResponse {
|
|
|
329
329
|
count: number;
|
|
330
330
|
sessions: SessionEntry[];
|
|
331
331
|
}
|
|
332
|
-
/**
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
332
|
+
/**
|
|
333
|
+
* Supported payment methods.
|
|
334
|
+
*
|
|
335
|
+
* Values aligned with ACN server `SupportedPaymentMethod` (lowercase).
|
|
336
|
+
*/
|
|
337
|
+
type PaymentMethod = 'credit_card' | 'debit_card' | 'bank_transfer' | 'paypal' | 'apple_pay' | 'google_pay' | 'usdc' | 'usdt' | 'dai' | 'eth' | 'btc' | 'platform_credits';
|
|
338
|
+
/**
|
|
339
|
+
* Supported networks.
|
|
340
|
+
*
|
|
341
|
+
* Values aligned with ACN server `SupportedNetwork` (lowercase).
|
|
342
|
+
*/
|
|
343
|
+
type PaymentNetwork = 'ethereum' | 'base' | 'arbitrum' | 'optimism' | 'polygon' | 'solana' | 'bitcoin';
|
|
344
|
+
/**
|
|
345
|
+
* Payment capability — aligned with ACN `PaymentCapabilityRequest`.
|
|
346
|
+
*
|
|
347
|
+
* Used both as the body for `setPaymentCapability` and the response
|
|
348
|
+
* shape of `getPaymentCapability`.
|
|
349
|
+
*/
|
|
337
350
|
interface PaymentCapability {
|
|
338
|
-
accepts_payment: boolean;
|
|
339
|
-
wallet_address?: string;
|
|
340
351
|
supported_methods: PaymentMethod[];
|
|
341
352
|
supported_networks: PaymentNetwork[];
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
353
|
+
/** Legacy single-address field; prefer `wallet_addresses`. */
|
|
354
|
+
wallet_address?: string;
|
|
355
|
+
/** Per-network wallet addresses, e.g. `{ ethereum: '0x...', base: '0x...' }`. */
|
|
356
|
+
wallet_addresses?: Record<string, string>;
|
|
357
|
+
accepts_payment?: boolean;
|
|
358
|
+
/**
|
|
359
|
+
* Token-based pricing payload, e.g.
|
|
360
|
+
* `{ input_price_per_million: 2.5, output_price_per_million: 10.0, currency: 'USD' }`.
|
|
361
|
+
*/
|
|
362
|
+
token_pricing?: Record<string, unknown> | null;
|
|
363
|
+
api_endpoint?: string;
|
|
364
|
+
webhook_url?: string;
|
|
345
365
|
}
|
|
346
|
-
/**
|
|
347
|
-
|
|
348
|
-
|
|
366
|
+
/**
|
|
367
|
+
* Known ACN payment task status values.
|
|
368
|
+
*
|
|
369
|
+
* `PaymentTask.status` is typed as `string` rather than this union so the
|
|
370
|
+
* SDK does not need a release whenever the server adds a state. Compare
|
|
371
|
+
* against these constants when branching on status.
|
|
372
|
+
*/
|
|
373
|
+
declare const KNOWN_PAYMENT_TASK_STATUSES: readonly ["created", "payment_requested", "payment_pending", "payment_confirmed", "task_in_progress", "task_completed", "payment_released", "in_progress", "disputed", "cancelled", "failed", "payment_failed", "refunded"];
|
|
374
|
+
type PaymentTaskStatus = (typeof KNOWN_PAYMENT_TASK_STATUSES)[number];
|
|
375
|
+
/** Payment task — aligned with ACN server `PaymentTask` (ap2.core). */
|
|
349
376
|
interface PaymentTask {
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
377
|
+
task_id: string;
|
|
378
|
+
payment_id?: string | null;
|
|
379
|
+
buyer_agent: string;
|
|
380
|
+
seller_agent: string;
|
|
381
|
+
task_description: string;
|
|
382
|
+
task_type?: string | null;
|
|
383
|
+
task_metadata?: Record<string, unknown>;
|
|
384
|
+
/** Decimal amount as a string (matches server contract). */
|
|
385
|
+
amount: string;
|
|
386
|
+
currency?: string;
|
|
387
|
+
payment_method?: PaymentMethod | null;
|
|
388
|
+
network?: PaymentNetwork | null;
|
|
389
|
+
recipient_wallet?: string | null;
|
|
390
|
+
/** A `KNOWN_PAYMENT_TASK_STATUSES` value, but typed wide for forward-compat. */
|
|
391
|
+
status: string;
|
|
358
392
|
created_at: string;
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
393
|
+
payment_requested_at?: string | null;
|
|
394
|
+
payment_confirmed_at?: string | null;
|
|
395
|
+
task_completed_at?: string | null;
|
|
396
|
+
payment_released_at?: string | null;
|
|
397
|
+
tx_hash?: string | null;
|
|
398
|
+
dispute?: Record<string, unknown> | null;
|
|
362
399
|
}
|
|
363
|
-
/** Payment discovery options */
|
|
400
|
+
/** Payment discovery options. */
|
|
364
401
|
interface PaymentDiscoveryOptions {
|
|
365
402
|
method?: PaymentMethod;
|
|
366
403
|
network?: PaymentNetwork;
|
|
367
|
-
min_amount?: number;
|
|
368
|
-
max_amount?: number;
|
|
369
404
|
}
|
|
370
|
-
/**
|
|
405
|
+
/**
|
|
406
|
+
* Per-role aggregate within {@link PaymentStats} (`as_buyer` / `as_seller`).
|
|
407
|
+
*
|
|
408
|
+
* `total_amount` is a decimal string (matches server contract).
|
|
409
|
+
*/
|
|
410
|
+
interface PaymentRoleStats {
|
|
411
|
+
count: number;
|
|
412
|
+
total_amount: string;
|
|
413
|
+
}
|
|
414
|
+
/**
|
|
415
|
+
* Payment statistics — aligned with `PaymentTaskManager.get_payment_stats`.
|
|
416
|
+
*
|
|
417
|
+
* The server aggregates per-status counts plus per-role (buyer/seller)
|
|
418
|
+
* totals as decimal strings, rather than flat received/sent floats.
|
|
419
|
+
*/
|
|
371
420
|
interface PaymentStats {
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
421
|
+
total_tasks: number;
|
|
422
|
+
as_buyer: PaymentRoleStats;
|
|
423
|
+
as_seller: PaymentRoleStats;
|
|
424
|
+
by_status: Record<string, number>;
|
|
425
|
+
completed_transactions: number;
|
|
376
426
|
}
|
|
377
427
|
/** System health */
|
|
378
428
|
interface SystemHealth {
|
|
@@ -632,8 +682,8 @@ declare class ACNClient {
|
|
|
632
682
|
}>;
|
|
633
683
|
/** Get subnet by ID */
|
|
634
684
|
getSubnet(subnetId: string): Promise<SubnetInfo>;
|
|
635
|
-
/** Delete a subnet */
|
|
636
|
-
deleteSubnet(subnetId: string
|
|
685
|
+
/** Delete a subnet you own (requires Agent API Key — only the owning agent can delete) */
|
|
686
|
+
deleteSubnet(subnetId: string): Promise<{
|
|
637
687
|
success: boolean;
|
|
638
688
|
}>;
|
|
639
689
|
/** Get agents in a subnet */
|
|
@@ -835,27 +885,96 @@ declare class ACNClient {
|
|
|
835
885
|
* after fetchManifestContent.
|
|
836
886
|
*/
|
|
837
887
|
deleteManifest(agentId: string, mid: string): Promise<Record<string, unknown>>;
|
|
838
|
-
/** Set agent's payment capability */
|
|
888
|
+
/** Set agent's payment capability (requires Agent API Key) */
|
|
839
889
|
setPaymentCapability(agentId: string, capability: PaymentCapability): Promise<{
|
|
840
890
|
success: boolean;
|
|
841
891
|
}>;
|
|
842
|
-
/**
|
|
892
|
+
/**
|
|
893
|
+
* Get agent's payment capability (requires Agent API Key).
|
|
894
|
+
*
|
|
895
|
+
* The ACN server returns this resource using the internal
|
|
896
|
+
* `ap2.core.PaymentCapability` shape, which calls the methods list
|
|
897
|
+
* `payment_methods`. We rewrite it to the request-shaped name
|
|
898
|
+
* `supported_methods` here so callers see the same field on read
|
|
899
|
+
* and on write.
|
|
900
|
+
*/
|
|
843
901
|
getPaymentCapability(agentId: string): Promise<PaymentCapability | null>;
|
|
844
|
-
/**
|
|
902
|
+
/** Set OpenAI-style per-million-token pricing in USD (requires Agent API Key) */
|
|
903
|
+
setTokenPricing(agentId: string, pricing: {
|
|
904
|
+
input_price_per_million: number;
|
|
905
|
+
output_price_per_million: number;
|
|
906
|
+
}): Promise<{
|
|
907
|
+
status: string;
|
|
908
|
+
agent_id: string;
|
|
909
|
+
token_pricing: {
|
|
910
|
+
input_price_per_million: number;
|
|
911
|
+
output_price_per_million: number;
|
|
912
|
+
currency: string;
|
|
913
|
+
};
|
|
914
|
+
network_fee_rate?: number;
|
|
915
|
+
}>;
|
|
916
|
+
/** Get an agent's per-million-token pricing (requires Agent API Key) */
|
|
917
|
+
getTokenPricing(agentId: string): Promise<{
|
|
918
|
+
input_price_per_million: number;
|
|
919
|
+
output_price_per_million: number;
|
|
920
|
+
currency: string;
|
|
921
|
+
} | null>;
|
|
922
|
+
/** Discover agents that accept payments. Filters by lowercase method/network. */
|
|
845
923
|
discoverPaymentAgents(options?: PaymentDiscoveryOptions): Promise<{
|
|
846
924
|
agents: AgentInfo[];
|
|
847
925
|
}>;
|
|
848
|
-
/**
|
|
926
|
+
/**
|
|
927
|
+
* Create a payment task (requires Agent API Key).
|
|
928
|
+
*
|
|
929
|
+
* `from_agent` must equal the authenticated agent — the server rejects
|
|
930
|
+
* spoofed payers with `from_agent_mismatch`. `payment_method` and
|
|
931
|
+
* `network` use ACN lowercase values (e.g. `'usdc'`, `'base'`).
|
|
932
|
+
*/
|
|
933
|
+
createPaymentTask(request: {
|
|
934
|
+
from_agent: string;
|
|
935
|
+
to_agent: string;
|
|
936
|
+
amount: number;
|
|
937
|
+
currency: string;
|
|
938
|
+
payment_method: PaymentMethod;
|
|
939
|
+
network: PaymentNetwork;
|
|
940
|
+
description?: string;
|
|
941
|
+
metadata?: Record<string, unknown>;
|
|
942
|
+
}): Promise<{
|
|
943
|
+
task_id: string;
|
|
944
|
+
status: string;
|
|
945
|
+
}>;
|
|
946
|
+
/**
|
|
947
|
+
* Estimate the cost of calling an agent before invoking its service.
|
|
948
|
+
*
|
|
949
|
+
* Returns `{ agent_id, estimate, note }` where `estimate` includes
|
|
950
|
+
* `total_usd`, `network_fee_usd`, `agent_income_usd` and credit
|
|
951
|
+
* equivalents derived from the target agent's token-pricing.
|
|
952
|
+
*/
|
|
953
|
+
estimateCost(request: {
|
|
954
|
+
agent_id: string;
|
|
955
|
+
estimated_input_tokens?: number;
|
|
956
|
+
estimated_output_tokens?: number;
|
|
957
|
+
}): Promise<{
|
|
958
|
+
agent_id: string;
|
|
959
|
+
estimate: Record<string, number>;
|
|
960
|
+
note?: string;
|
|
961
|
+
}>;
|
|
962
|
+
/**
|
|
963
|
+
* Get a payment task by ID.
|
|
964
|
+
*
|
|
965
|
+
* Note: `GET /payments/tasks/{task_id}` requires the ACN backend's
|
|
966
|
+
* internal token; agents typically use `getAgentPaymentTasks` instead.
|
|
967
|
+
*/
|
|
849
968
|
getPaymentTask(taskId: string): Promise<PaymentTask>;
|
|
850
|
-
/** Get
|
|
969
|
+
/** Get the payment tasks an agent is involved in (requires Agent API Key). */
|
|
851
970
|
getAgentPaymentTasks(agentId: string, options?: {
|
|
852
|
-
role?: 'payer' | 'payee';
|
|
853
971
|
status?: string;
|
|
854
972
|
limit?: number;
|
|
855
973
|
}): Promise<{
|
|
974
|
+
agent_id: string;
|
|
856
975
|
tasks: PaymentTask[];
|
|
857
976
|
}>;
|
|
858
|
-
/** Get agent's payment statistics */
|
|
977
|
+
/** Get an agent's payment statistics (requires Agent API Key). */
|
|
859
978
|
getPaymentStats(agentId: string): Promise<PaymentStats>;
|
|
860
979
|
/** Get Prometheus metrics (text format) */
|
|
861
980
|
getPrometheusMetrics(): Promise<string>;
|
|
@@ -1106,4 +1225,4 @@ declare class ACNRealtime {
|
|
|
1106
1225
|
*/
|
|
1107
1226
|
declare function subscribeToACN<T = unknown>(baseUrl: string, channel: string, handler: WSEventHandler<T>): () => void;
|
|
1108
1227
|
|
|
1109
|
-
export { ACNClient, type ACNClientOptions, ACNError, ACNRealtime, type ActivityEntry, type AgentActivity, type AgentAnalytics, type AgentInfo, type AgentJoinRequest, type AgentJoinResponse, type AgentRegisterRequest, type AgentRegisterResponse, type AgentSearchOptions, type AgentSearchResponse, type AgentStatus, type AllowlistActionResponse, type AllowlistEntry, type AllowlistListResponse, type ApiResponse, type AttentionFee, type AuditEvent, type AuditQueryOptions, type BroadcastBySkillRequest, type BroadcastByTagRequest, type BroadcastRequest, type BroadcastStrategy, type CommunicationPolicyMode, type CommunicationPolicyResponse, type ComponentHealth, type DashboardData, type FollowActionResponse, type FollowCheckResponse, type ManifestContentResponse, type ManifestEntry, type ManifestListResponse, type Message, type MessageType, type MetricsData, type PaymentCapability, type PaymentDiscoveryOptions, type PaymentMethod, type PaymentNetwork, type PaymentStats, type PaymentTask, type PaymentTaskStatus, type SendMessageRequest, type SendMessageResponse, type SubnetCreateRequest, type SubnetCreateResponse, type SubnetInfo, type SystemHealth, type WSConnectionOptions, type WSEventHandler, type WSEventType, type WSMessage, type WSState, subscribeToACN };
|
|
1228
|
+
export { ACNClient, type ACNClientOptions, ACNError, ACNRealtime, type ActivityEntry, type AgentActivity, type AgentAnalytics, type AgentInfo, type AgentJoinRequest, type AgentJoinResponse, type AgentRegisterRequest, type AgentRegisterResponse, type AgentSearchOptions, type AgentSearchResponse, type AgentStatus, type AllowlistActionResponse, type AllowlistEntry, type AllowlistListResponse, type ApiResponse, type AttentionFee, type AuditEvent, type AuditQueryOptions, type BroadcastBySkillRequest, type BroadcastByTagRequest, type BroadcastRequest, type BroadcastStrategy, type CommunicationPolicyMode, type CommunicationPolicyResponse, type ComponentHealth, type DashboardData, type FollowActionResponse, type FollowCheckResponse, KNOWN_PAYMENT_TASK_STATUSES, type ManifestContentResponse, type ManifestEntry, type ManifestListResponse, type Message, type MessageType, type MetricsData, type PaymentCapability, type PaymentDiscoveryOptions, type PaymentMethod, type PaymentNetwork, type PaymentRoleStats, type PaymentStats, type PaymentTask, type PaymentTaskStatus, type SendMessageRequest, type SendMessageResponse, type SubnetCreateRequest, type SubnetCreateResponse, type SubnetInfo, type SystemHealth, type WSConnectionOptions, type WSEventHandler, type WSEventType, type WSMessage, type WSState, subscribeToACN };
|
package/dist/index.d.ts
CHANGED
|
@@ -329,50 +329,100 @@ interface PendingSessionsResponse {
|
|
|
329
329
|
count: number;
|
|
330
330
|
sessions: SessionEntry[];
|
|
331
331
|
}
|
|
332
|
-
/**
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
332
|
+
/**
|
|
333
|
+
* Supported payment methods.
|
|
334
|
+
*
|
|
335
|
+
* Values aligned with ACN server `SupportedPaymentMethod` (lowercase).
|
|
336
|
+
*/
|
|
337
|
+
type PaymentMethod = 'credit_card' | 'debit_card' | 'bank_transfer' | 'paypal' | 'apple_pay' | 'google_pay' | 'usdc' | 'usdt' | 'dai' | 'eth' | 'btc' | 'platform_credits';
|
|
338
|
+
/**
|
|
339
|
+
* Supported networks.
|
|
340
|
+
*
|
|
341
|
+
* Values aligned with ACN server `SupportedNetwork` (lowercase).
|
|
342
|
+
*/
|
|
343
|
+
type PaymentNetwork = 'ethereum' | 'base' | 'arbitrum' | 'optimism' | 'polygon' | 'solana' | 'bitcoin';
|
|
344
|
+
/**
|
|
345
|
+
* Payment capability — aligned with ACN `PaymentCapabilityRequest`.
|
|
346
|
+
*
|
|
347
|
+
* Used both as the body for `setPaymentCapability` and the response
|
|
348
|
+
* shape of `getPaymentCapability`.
|
|
349
|
+
*/
|
|
337
350
|
interface PaymentCapability {
|
|
338
|
-
accepts_payment: boolean;
|
|
339
|
-
wallet_address?: string;
|
|
340
351
|
supported_methods: PaymentMethod[];
|
|
341
352
|
supported_networks: PaymentNetwork[];
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
353
|
+
/** Legacy single-address field; prefer `wallet_addresses`. */
|
|
354
|
+
wallet_address?: string;
|
|
355
|
+
/** Per-network wallet addresses, e.g. `{ ethereum: '0x...', base: '0x...' }`. */
|
|
356
|
+
wallet_addresses?: Record<string, string>;
|
|
357
|
+
accepts_payment?: boolean;
|
|
358
|
+
/**
|
|
359
|
+
* Token-based pricing payload, e.g.
|
|
360
|
+
* `{ input_price_per_million: 2.5, output_price_per_million: 10.0, currency: 'USD' }`.
|
|
361
|
+
*/
|
|
362
|
+
token_pricing?: Record<string, unknown> | null;
|
|
363
|
+
api_endpoint?: string;
|
|
364
|
+
webhook_url?: string;
|
|
345
365
|
}
|
|
346
|
-
/**
|
|
347
|
-
|
|
348
|
-
|
|
366
|
+
/**
|
|
367
|
+
* Known ACN payment task status values.
|
|
368
|
+
*
|
|
369
|
+
* `PaymentTask.status` is typed as `string` rather than this union so the
|
|
370
|
+
* SDK does not need a release whenever the server adds a state. Compare
|
|
371
|
+
* against these constants when branching on status.
|
|
372
|
+
*/
|
|
373
|
+
declare const KNOWN_PAYMENT_TASK_STATUSES: readonly ["created", "payment_requested", "payment_pending", "payment_confirmed", "task_in_progress", "task_completed", "payment_released", "in_progress", "disputed", "cancelled", "failed", "payment_failed", "refunded"];
|
|
374
|
+
type PaymentTaskStatus = (typeof KNOWN_PAYMENT_TASK_STATUSES)[number];
|
|
375
|
+
/** Payment task — aligned with ACN server `PaymentTask` (ap2.core). */
|
|
349
376
|
interface PaymentTask {
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
377
|
+
task_id: string;
|
|
378
|
+
payment_id?: string | null;
|
|
379
|
+
buyer_agent: string;
|
|
380
|
+
seller_agent: string;
|
|
381
|
+
task_description: string;
|
|
382
|
+
task_type?: string | null;
|
|
383
|
+
task_metadata?: Record<string, unknown>;
|
|
384
|
+
/** Decimal amount as a string (matches server contract). */
|
|
385
|
+
amount: string;
|
|
386
|
+
currency?: string;
|
|
387
|
+
payment_method?: PaymentMethod | null;
|
|
388
|
+
network?: PaymentNetwork | null;
|
|
389
|
+
recipient_wallet?: string | null;
|
|
390
|
+
/** A `KNOWN_PAYMENT_TASK_STATUSES` value, but typed wide for forward-compat. */
|
|
391
|
+
status: string;
|
|
358
392
|
created_at: string;
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
393
|
+
payment_requested_at?: string | null;
|
|
394
|
+
payment_confirmed_at?: string | null;
|
|
395
|
+
task_completed_at?: string | null;
|
|
396
|
+
payment_released_at?: string | null;
|
|
397
|
+
tx_hash?: string | null;
|
|
398
|
+
dispute?: Record<string, unknown> | null;
|
|
362
399
|
}
|
|
363
|
-
/** Payment discovery options */
|
|
400
|
+
/** Payment discovery options. */
|
|
364
401
|
interface PaymentDiscoveryOptions {
|
|
365
402
|
method?: PaymentMethod;
|
|
366
403
|
network?: PaymentNetwork;
|
|
367
|
-
min_amount?: number;
|
|
368
|
-
max_amount?: number;
|
|
369
404
|
}
|
|
370
|
-
/**
|
|
405
|
+
/**
|
|
406
|
+
* Per-role aggregate within {@link PaymentStats} (`as_buyer` / `as_seller`).
|
|
407
|
+
*
|
|
408
|
+
* `total_amount` is a decimal string (matches server contract).
|
|
409
|
+
*/
|
|
410
|
+
interface PaymentRoleStats {
|
|
411
|
+
count: number;
|
|
412
|
+
total_amount: string;
|
|
413
|
+
}
|
|
414
|
+
/**
|
|
415
|
+
* Payment statistics — aligned with `PaymentTaskManager.get_payment_stats`.
|
|
416
|
+
*
|
|
417
|
+
* The server aggregates per-status counts plus per-role (buyer/seller)
|
|
418
|
+
* totals as decimal strings, rather than flat received/sent floats.
|
|
419
|
+
*/
|
|
371
420
|
interface PaymentStats {
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
421
|
+
total_tasks: number;
|
|
422
|
+
as_buyer: PaymentRoleStats;
|
|
423
|
+
as_seller: PaymentRoleStats;
|
|
424
|
+
by_status: Record<string, number>;
|
|
425
|
+
completed_transactions: number;
|
|
376
426
|
}
|
|
377
427
|
/** System health */
|
|
378
428
|
interface SystemHealth {
|
|
@@ -632,8 +682,8 @@ declare class ACNClient {
|
|
|
632
682
|
}>;
|
|
633
683
|
/** Get subnet by ID */
|
|
634
684
|
getSubnet(subnetId: string): Promise<SubnetInfo>;
|
|
635
|
-
/** Delete a subnet */
|
|
636
|
-
deleteSubnet(subnetId: string
|
|
685
|
+
/** Delete a subnet you own (requires Agent API Key — only the owning agent can delete) */
|
|
686
|
+
deleteSubnet(subnetId: string): Promise<{
|
|
637
687
|
success: boolean;
|
|
638
688
|
}>;
|
|
639
689
|
/** Get agents in a subnet */
|
|
@@ -835,27 +885,96 @@ declare class ACNClient {
|
|
|
835
885
|
* after fetchManifestContent.
|
|
836
886
|
*/
|
|
837
887
|
deleteManifest(agentId: string, mid: string): Promise<Record<string, unknown>>;
|
|
838
|
-
/** Set agent's payment capability */
|
|
888
|
+
/** Set agent's payment capability (requires Agent API Key) */
|
|
839
889
|
setPaymentCapability(agentId: string, capability: PaymentCapability): Promise<{
|
|
840
890
|
success: boolean;
|
|
841
891
|
}>;
|
|
842
|
-
/**
|
|
892
|
+
/**
|
|
893
|
+
* Get agent's payment capability (requires Agent API Key).
|
|
894
|
+
*
|
|
895
|
+
* The ACN server returns this resource using the internal
|
|
896
|
+
* `ap2.core.PaymentCapability` shape, which calls the methods list
|
|
897
|
+
* `payment_methods`. We rewrite it to the request-shaped name
|
|
898
|
+
* `supported_methods` here so callers see the same field on read
|
|
899
|
+
* and on write.
|
|
900
|
+
*/
|
|
843
901
|
getPaymentCapability(agentId: string): Promise<PaymentCapability | null>;
|
|
844
|
-
/**
|
|
902
|
+
/** Set OpenAI-style per-million-token pricing in USD (requires Agent API Key) */
|
|
903
|
+
setTokenPricing(agentId: string, pricing: {
|
|
904
|
+
input_price_per_million: number;
|
|
905
|
+
output_price_per_million: number;
|
|
906
|
+
}): Promise<{
|
|
907
|
+
status: string;
|
|
908
|
+
agent_id: string;
|
|
909
|
+
token_pricing: {
|
|
910
|
+
input_price_per_million: number;
|
|
911
|
+
output_price_per_million: number;
|
|
912
|
+
currency: string;
|
|
913
|
+
};
|
|
914
|
+
network_fee_rate?: number;
|
|
915
|
+
}>;
|
|
916
|
+
/** Get an agent's per-million-token pricing (requires Agent API Key) */
|
|
917
|
+
getTokenPricing(agentId: string): Promise<{
|
|
918
|
+
input_price_per_million: number;
|
|
919
|
+
output_price_per_million: number;
|
|
920
|
+
currency: string;
|
|
921
|
+
} | null>;
|
|
922
|
+
/** Discover agents that accept payments. Filters by lowercase method/network. */
|
|
845
923
|
discoverPaymentAgents(options?: PaymentDiscoveryOptions): Promise<{
|
|
846
924
|
agents: AgentInfo[];
|
|
847
925
|
}>;
|
|
848
|
-
/**
|
|
926
|
+
/**
|
|
927
|
+
* Create a payment task (requires Agent API Key).
|
|
928
|
+
*
|
|
929
|
+
* `from_agent` must equal the authenticated agent — the server rejects
|
|
930
|
+
* spoofed payers with `from_agent_mismatch`. `payment_method` and
|
|
931
|
+
* `network` use ACN lowercase values (e.g. `'usdc'`, `'base'`).
|
|
932
|
+
*/
|
|
933
|
+
createPaymentTask(request: {
|
|
934
|
+
from_agent: string;
|
|
935
|
+
to_agent: string;
|
|
936
|
+
amount: number;
|
|
937
|
+
currency: string;
|
|
938
|
+
payment_method: PaymentMethod;
|
|
939
|
+
network: PaymentNetwork;
|
|
940
|
+
description?: string;
|
|
941
|
+
metadata?: Record<string, unknown>;
|
|
942
|
+
}): Promise<{
|
|
943
|
+
task_id: string;
|
|
944
|
+
status: string;
|
|
945
|
+
}>;
|
|
946
|
+
/**
|
|
947
|
+
* Estimate the cost of calling an agent before invoking its service.
|
|
948
|
+
*
|
|
949
|
+
* Returns `{ agent_id, estimate, note }` where `estimate` includes
|
|
950
|
+
* `total_usd`, `network_fee_usd`, `agent_income_usd` and credit
|
|
951
|
+
* equivalents derived from the target agent's token-pricing.
|
|
952
|
+
*/
|
|
953
|
+
estimateCost(request: {
|
|
954
|
+
agent_id: string;
|
|
955
|
+
estimated_input_tokens?: number;
|
|
956
|
+
estimated_output_tokens?: number;
|
|
957
|
+
}): Promise<{
|
|
958
|
+
agent_id: string;
|
|
959
|
+
estimate: Record<string, number>;
|
|
960
|
+
note?: string;
|
|
961
|
+
}>;
|
|
962
|
+
/**
|
|
963
|
+
* Get a payment task by ID.
|
|
964
|
+
*
|
|
965
|
+
* Note: `GET /payments/tasks/{task_id}` requires the ACN backend's
|
|
966
|
+
* internal token; agents typically use `getAgentPaymentTasks` instead.
|
|
967
|
+
*/
|
|
849
968
|
getPaymentTask(taskId: string): Promise<PaymentTask>;
|
|
850
|
-
/** Get
|
|
969
|
+
/** Get the payment tasks an agent is involved in (requires Agent API Key). */
|
|
851
970
|
getAgentPaymentTasks(agentId: string, options?: {
|
|
852
|
-
role?: 'payer' | 'payee';
|
|
853
971
|
status?: string;
|
|
854
972
|
limit?: number;
|
|
855
973
|
}): Promise<{
|
|
974
|
+
agent_id: string;
|
|
856
975
|
tasks: PaymentTask[];
|
|
857
976
|
}>;
|
|
858
|
-
/** Get agent's payment statistics */
|
|
977
|
+
/** Get an agent's payment statistics (requires Agent API Key). */
|
|
859
978
|
getPaymentStats(agentId: string): Promise<PaymentStats>;
|
|
860
979
|
/** Get Prometheus metrics (text format) */
|
|
861
980
|
getPrometheusMetrics(): Promise<string>;
|
|
@@ -1106,4 +1225,4 @@ declare class ACNRealtime {
|
|
|
1106
1225
|
*/
|
|
1107
1226
|
declare function subscribeToACN<T = unknown>(baseUrl: string, channel: string, handler: WSEventHandler<T>): () => void;
|
|
1108
1227
|
|
|
1109
|
-
export { ACNClient, type ACNClientOptions, ACNError, ACNRealtime, type ActivityEntry, type AgentActivity, type AgentAnalytics, type AgentInfo, type AgentJoinRequest, type AgentJoinResponse, type AgentRegisterRequest, type AgentRegisterResponse, type AgentSearchOptions, type AgentSearchResponse, type AgentStatus, type AllowlistActionResponse, type AllowlistEntry, type AllowlistListResponse, type ApiResponse, type AttentionFee, type AuditEvent, type AuditQueryOptions, type BroadcastBySkillRequest, type BroadcastByTagRequest, type BroadcastRequest, type BroadcastStrategy, type CommunicationPolicyMode, type CommunicationPolicyResponse, type ComponentHealth, type DashboardData, type FollowActionResponse, type FollowCheckResponse, type ManifestContentResponse, type ManifestEntry, type ManifestListResponse, type Message, type MessageType, type MetricsData, type PaymentCapability, type PaymentDiscoveryOptions, type PaymentMethod, type PaymentNetwork, type PaymentStats, type PaymentTask, type PaymentTaskStatus, type SendMessageRequest, type SendMessageResponse, type SubnetCreateRequest, type SubnetCreateResponse, type SubnetInfo, type SystemHealth, type WSConnectionOptions, type WSEventHandler, type WSEventType, type WSMessage, type WSState, subscribeToACN };
|
|
1228
|
+
export { ACNClient, type ACNClientOptions, ACNError, ACNRealtime, type ActivityEntry, type AgentActivity, type AgentAnalytics, type AgentInfo, type AgentJoinRequest, type AgentJoinResponse, type AgentRegisterRequest, type AgentRegisterResponse, type AgentSearchOptions, type AgentSearchResponse, type AgentStatus, type AllowlistActionResponse, type AllowlistEntry, type AllowlistListResponse, type ApiResponse, type AttentionFee, type AuditEvent, type AuditQueryOptions, type BroadcastBySkillRequest, type BroadcastByTagRequest, type BroadcastRequest, type BroadcastStrategy, type CommunicationPolicyMode, type CommunicationPolicyResponse, type ComponentHealth, type DashboardData, type FollowActionResponse, type FollowCheckResponse, KNOWN_PAYMENT_TASK_STATUSES, type ManifestContentResponse, type ManifestEntry, type ManifestListResponse, type Message, type MessageType, type MetricsData, type PaymentCapability, type PaymentDiscoveryOptions, type PaymentMethod, type PaymentNetwork, type PaymentRoleStats, type PaymentStats, type PaymentTask, type PaymentTaskStatus, type SendMessageRequest, type SendMessageResponse, type SubnetCreateRequest, type SubnetCreateResponse, type SubnetInfo, type SystemHealth, type WSConnectionOptions, type WSEventHandler, type WSEventType, type WSMessage, type WSState, subscribeToACN };
|
package/dist/index.js
CHANGED
|
@@ -33,6 +33,7 @@ __export(index_exports, {
|
|
|
33
33
|
ACNClient: () => ACNClient,
|
|
34
34
|
ACNError: () => ACNError,
|
|
35
35
|
ACNRealtime: () => ACNRealtime,
|
|
36
|
+
KNOWN_PAYMENT_TASK_STATUSES: () => KNOWN_PAYMENT_TASK_STATUSES,
|
|
36
37
|
subscribeToACN: () => subscribeToACN
|
|
37
38
|
});
|
|
38
39
|
module.exports = __toCommonJS(index_exports);
|
|
@@ -209,11 +210,9 @@ var ACNClient = class {
|
|
|
209
210
|
async getSubnet(subnetId) {
|
|
210
211
|
return this.get(`/api/v1/subnets/${subnetId}`);
|
|
211
212
|
}
|
|
212
|
-
/** Delete a subnet */
|
|
213
|
-
async deleteSubnet(subnetId
|
|
214
|
-
return this.request("DELETE", `/api/v1/subnets/${subnetId}
|
|
215
|
-
params: { force }
|
|
216
|
-
});
|
|
213
|
+
/** Delete a subnet you own (requires Agent API Key — only the owning agent can delete) */
|
|
214
|
+
async deleteSubnet(subnetId) {
|
|
215
|
+
return this.request("DELETE", `/api/v1/subnets/${subnetId}`);
|
|
217
216
|
}
|
|
218
217
|
/** Get agents in a subnet */
|
|
219
218
|
async getSubnetAgents(subnetId) {
|
|
@@ -437,32 +436,82 @@ var ACNClient = class {
|
|
|
437
436
|
// ============================================
|
|
438
437
|
// Payment Discovery
|
|
439
438
|
// ============================================
|
|
440
|
-
/** Set agent's payment capability */
|
|
439
|
+
/** Set agent's payment capability (requires Agent API Key) */
|
|
441
440
|
async setPaymentCapability(agentId, capability) {
|
|
442
|
-
return this.post(`/api/v1/
|
|
441
|
+
return this.post(`/api/v1/payments/${agentId}/payment-capability`, capability);
|
|
443
442
|
}
|
|
444
|
-
/**
|
|
443
|
+
/**
|
|
444
|
+
* Get agent's payment capability (requires Agent API Key).
|
|
445
|
+
*
|
|
446
|
+
* The ACN server returns this resource using the internal
|
|
447
|
+
* `ap2.core.PaymentCapability` shape, which calls the methods list
|
|
448
|
+
* `payment_methods`. We rewrite it to the request-shaped name
|
|
449
|
+
* `supported_methods` here so callers see the same field on read
|
|
450
|
+
* and on write.
|
|
451
|
+
*/
|
|
445
452
|
async getPaymentCapability(agentId) {
|
|
446
|
-
|
|
453
|
+
const raw = await this.get(
|
|
454
|
+
`/api/v1/payments/${agentId}/payment-capability`
|
|
455
|
+
);
|
|
456
|
+
if (!raw) return null;
|
|
457
|
+
if (Array.isArray(raw.payment_methods) && raw.supported_methods === void 0) {
|
|
458
|
+
raw.supported_methods = raw.payment_methods;
|
|
459
|
+
}
|
|
460
|
+
return raw;
|
|
447
461
|
}
|
|
448
|
-
/**
|
|
462
|
+
/** Set OpenAI-style per-million-token pricing in USD (requires Agent API Key) */
|
|
463
|
+
async setTokenPricing(agentId, pricing) {
|
|
464
|
+
return this.post(`/api/v1/payments/${agentId}/token-pricing`, pricing);
|
|
465
|
+
}
|
|
466
|
+
/** Get an agent's per-million-token pricing (requires Agent API Key) */
|
|
467
|
+
async getTokenPricing(agentId) {
|
|
468
|
+
return this.get(`/api/v1/payments/${agentId}/token-pricing`);
|
|
469
|
+
}
|
|
470
|
+
/** Discover agents that accept payments. Filters by lowercase method/network. */
|
|
449
471
|
async discoverPaymentAgents(options) {
|
|
450
472
|
return this.get("/api/v1/payments/discover", {
|
|
451
473
|
method: options?.method,
|
|
452
|
-
network: options?.network
|
|
453
|
-
min_amount: options?.min_amount,
|
|
454
|
-
max_amount: options?.max_amount
|
|
474
|
+
network: options?.network
|
|
455
475
|
});
|
|
456
476
|
}
|
|
457
|
-
/**
|
|
477
|
+
/**
|
|
478
|
+
* Create a payment task (requires Agent API Key).
|
|
479
|
+
*
|
|
480
|
+
* `from_agent` must equal the authenticated agent — the server rejects
|
|
481
|
+
* spoofed payers with `from_agent_mismatch`. `payment_method` and
|
|
482
|
+
* `network` use ACN lowercase values (e.g. `'usdc'`, `'base'`).
|
|
483
|
+
*/
|
|
484
|
+
async createPaymentTask(request) {
|
|
485
|
+
return this.post("/api/v1/payments/tasks", request);
|
|
486
|
+
}
|
|
487
|
+
/**
|
|
488
|
+
* Estimate the cost of calling an agent before invoking its service.
|
|
489
|
+
*
|
|
490
|
+
* Returns `{ agent_id, estimate, note }` where `estimate` includes
|
|
491
|
+
* `total_usd`, `network_fee_usd`, `agent_income_usd` and credit
|
|
492
|
+
* equivalents derived from the target agent's token-pricing.
|
|
493
|
+
*/
|
|
494
|
+
async estimateCost(request) {
|
|
495
|
+
return this.post("/api/v1/payments/billing/estimate", {
|
|
496
|
+
agent_id: request.agent_id,
|
|
497
|
+
estimated_input_tokens: request.estimated_input_tokens ?? 0,
|
|
498
|
+
estimated_output_tokens: request.estimated_output_tokens ?? 0
|
|
499
|
+
});
|
|
500
|
+
}
|
|
501
|
+
/**
|
|
502
|
+
* Get a payment task by ID.
|
|
503
|
+
*
|
|
504
|
+
* Note: `GET /payments/tasks/{task_id}` requires the ACN backend's
|
|
505
|
+
* internal token; agents typically use `getAgentPaymentTasks` instead.
|
|
506
|
+
*/
|
|
458
507
|
async getPaymentTask(taskId) {
|
|
459
508
|
return this.get(`/api/v1/payments/tasks/${taskId}`);
|
|
460
509
|
}
|
|
461
|
-
/** Get
|
|
510
|
+
/** Get the payment tasks an agent is involved in (requires Agent API Key). */
|
|
462
511
|
async getAgentPaymentTasks(agentId, options) {
|
|
463
512
|
return this.get(`/api/v1/payments/tasks/agent/${agentId}`, options);
|
|
464
513
|
}
|
|
465
|
-
/** Get agent's payment statistics */
|
|
514
|
+
/** Get an agent's payment statistics (requires Agent API Key). */
|
|
466
515
|
async getPaymentStats(agentId) {
|
|
467
516
|
return this.get(`/api/v1/payments/stats/${agentId}`);
|
|
468
517
|
}
|
|
@@ -953,10 +1002,28 @@ function subscribeToACN(baseUrl, channel, handler) {
|
|
|
953
1002
|
realtime.disconnect();
|
|
954
1003
|
};
|
|
955
1004
|
}
|
|
1005
|
+
|
|
1006
|
+
// src/types.ts
|
|
1007
|
+
var KNOWN_PAYMENT_TASK_STATUSES = [
|
|
1008
|
+
"created",
|
|
1009
|
+
"payment_requested",
|
|
1010
|
+
"payment_pending",
|
|
1011
|
+
"payment_confirmed",
|
|
1012
|
+
"task_in_progress",
|
|
1013
|
+
"task_completed",
|
|
1014
|
+
"payment_released",
|
|
1015
|
+
"in_progress",
|
|
1016
|
+
"disputed",
|
|
1017
|
+
"cancelled",
|
|
1018
|
+
"failed",
|
|
1019
|
+
"payment_failed",
|
|
1020
|
+
"refunded"
|
|
1021
|
+
];
|
|
956
1022
|
// Annotate the CommonJS export names for ESM import in node:
|
|
957
1023
|
0 && (module.exports = {
|
|
958
1024
|
ACNClient,
|
|
959
1025
|
ACNError,
|
|
960
1026
|
ACNRealtime,
|
|
1027
|
+
KNOWN_PAYMENT_TASK_STATUSES,
|
|
961
1028
|
subscribeToACN
|
|
962
1029
|
});
|
package/dist/index.mjs
CHANGED
|
@@ -170,11 +170,9 @@ var ACNClient = class {
|
|
|
170
170
|
async getSubnet(subnetId) {
|
|
171
171
|
return this.get(`/api/v1/subnets/${subnetId}`);
|
|
172
172
|
}
|
|
173
|
-
/** Delete a subnet */
|
|
174
|
-
async deleteSubnet(subnetId
|
|
175
|
-
return this.request("DELETE", `/api/v1/subnets/${subnetId}
|
|
176
|
-
params: { force }
|
|
177
|
-
});
|
|
173
|
+
/** Delete a subnet you own (requires Agent API Key — only the owning agent can delete) */
|
|
174
|
+
async deleteSubnet(subnetId) {
|
|
175
|
+
return this.request("DELETE", `/api/v1/subnets/${subnetId}`);
|
|
178
176
|
}
|
|
179
177
|
/** Get agents in a subnet */
|
|
180
178
|
async getSubnetAgents(subnetId) {
|
|
@@ -398,32 +396,82 @@ var ACNClient = class {
|
|
|
398
396
|
// ============================================
|
|
399
397
|
// Payment Discovery
|
|
400
398
|
// ============================================
|
|
401
|
-
/** Set agent's payment capability */
|
|
399
|
+
/** Set agent's payment capability (requires Agent API Key) */
|
|
402
400
|
async setPaymentCapability(agentId, capability) {
|
|
403
|
-
return this.post(`/api/v1/
|
|
401
|
+
return this.post(`/api/v1/payments/${agentId}/payment-capability`, capability);
|
|
404
402
|
}
|
|
405
|
-
/**
|
|
403
|
+
/**
|
|
404
|
+
* Get agent's payment capability (requires Agent API Key).
|
|
405
|
+
*
|
|
406
|
+
* The ACN server returns this resource using the internal
|
|
407
|
+
* `ap2.core.PaymentCapability` shape, which calls the methods list
|
|
408
|
+
* `payment_methods`. We rewrite it to the request-shaped name
|
|
409
|
+
* `supported_methods` here so callers see the same field on read
|
|
410
|
+
* and on write.
|
|
411
|
+
*/
|
|
406
412
|
async getPaymentCapability(agentId) {
|
|
407
|
-
|
|
413
|
+
const raw = await this.get(
|
|
414
|
+
`/api/v1/payments/${agentId}/payment-capability`
|
|
415
|
+
);
|
|
416
|
+
if (!raw) return null;
|
|
417
|
+
if (Array.isArray(raw.payment_methods) && raw.supported_methods === void 0) {
|
|
418
|
+
raw.supported_methods = raw.payment_methods;
|
|
419
|
+
}
|
|
420
|
+
return raw;
|
|
408
421
|
}
|
|
409
|
-
/**
|
|
422
|
+
/** Set OpenAI-style per-million-token pricing in USD (requires Agent API Key) */
|
|
423
|
+
async setTokenPricing(agentId, pricing) {
|
|
424
|
+
return this.post(`/api/v1/payments/${agentId}/token-pricing`, pricing);
|
|
425
|
+
}
|
|
426
|
+
/** Get an agent's per-million-token pricing (requires Agent API Key) */
|
|
427
|
+
async getTokenPricing(agentId) {
|
|
428
|
+
return this.get(`/api/v1/payments/${agentId}/token-pricing`);
|
|
429
|
+
}
|
|
430
|
+
/** Discover agents that accept payments. Filters by lowercase method/network. */
|
|
410
431
|
async discoverPaymentAgents(options) {
|
|
411
432
|
return this.get("/api/v1/payments/discover", {
|
|
412
433
|
method: options?.method,
|
|
413
|
-
network: options?.network
|
|
414
|
-
min_amount: options?.min_amount,
|
|
415
|
-
max_amount: options?.max_amount
|
|
434
|
+
network: options?.network
|
|
416
435
|
});
|
|
417
436
|
}
|
|
418
|
-
/**
|
|
437
|
+
/**
|
|
438
|
+
* Create a payment task (requires Agent API Key).
|
|
439
|
+
*
|
|
440
|
+
* `from_agent` must equal the authenticated agent — the server rejects
|
|
441
|
+
* spoofed payers with `from_agent_mismatch`. `payment_method` and
|
|
442
|
+
* `network` use ACN lowercase values (e.g. `'usdc'`, `'base'`).
|
|
443
|
+
*/
|
|
444
|
+
async createPaymentTask(request) {
|
|
445
|
+
return this.post("/api/v1/payments/tasks", request);
|
|
446
|
+
}
|
|
447
|
+
/**
|
|
448
|
+
* Estimate the cost of calling an agent before invoking its service.
|
|
449
|
+
*
|
|
450
|
+
* Returns `{ agent_id, estimate, note }` where `estimate` includes
|
|
451
|
+
* `total_usd`, `network_fee_usd`, `agent_income_usd` and credit
|
|
452
|
+
* equivalents derived from the target agent's token-pricing.
|
|
453
|
+
*/
|
|
454
|
+
async estimateCost(request) {
|
|
455
|
+
return this.post("/api/v1/payments/billing/estimate", {
|
|
456
|
+
agent_id: request.agent_id,
|
|
457
|
+
estimated_input_tokens: request.estimated_input_tokens ?? 0,
|
|
458
|
+
estimated_output_tokens: request.estimated_output_tokens ?? 0
|
|
459
|
+
});
|
|
460
|
+
}
|
|
461
|
+
/**
|
|
462
|
+
* Get a payment task by ID.
|
|
463
|
+
*
|
|
464
|
+
* Note: `GET /payments/tasks/{task_id}` requires the ACN backend's
|
|
465
|
+
* internal token; agents typically use `getAgentPaymentTasks` instead.
|
|
466
|
+
*/
|
|
419
467
|
async getPaymentTask(taskId) {
|
|
420
468
|
return this.get(`/api/v1/payments/tasks/${taskId}`);
|
|
421
469
|
}
|
|
422
|
-
/** Get
|
|
470
|
+
/** Get the payment tasks an agent is involved in (requires Agent API Key). */
|
|
423
471
|
async getAgentPaymentTasks(agentId, options) {
|
|
424
472
|
return this.get(`/api/v1/payments/tasks/agent/${agentId}`, options);
|
|
425
473
|
}
|
|
426
|
-
/** Get agent's payment statistics */
|
|
474
|
+
/** Get an agent's payment statistics (requires Agent API Key). */
|
|
427
475
|
async getPaymentStats(agentId) {
|
|
428
476
|
return this.get(`/api/v1/payments/stats/${agentId}`);
|
|
429
477
|
}
|
|
@@ -914,9 +962,27 @@ function subscribeToACN(baseUrl, channel, handler) {
|
|
|
914
962
|
realtime.disconnect();
|
|
915
963
|
};
|
|
916
964
|
}
|
|
965
|
+
|
|
966
|
+
// src/types.ts
|
|
967
|
+
var KNOWN_PAYMENT_TASK_STATUSES = [
|
|
968
|
+
"created",
|
|
969
|
+
"payment_requested",
|
|
970
|
+
"payment_pending",
|
|
971
|
+
"payment_confirmed",
|
|
972
|
+
"task_in_progress",
|
|
973
|
+
"task_completed",
|
|
974
|
+
"payment_released",
|
|
975
|
+
"in_progress",
|
|
976
|
+
"disputed",
|
|
977
|
+
"cancelled",
|
|
978
|
+
"failed",
|
|
979
|
+
"payment_failed",
|
|
980
|
+
"refunded"
|
|
981
|
+
];
|
|
917
982
|
export {
|
|
918
983
|
ACNClient,
|
|
919
984
|
ACNError,
|
|
920
985
|
ACNRealtime,
|
|
986
|
+
KNOWN_PAYMENT_TASK_STATUSES,
|
|
921
987
|
subscribeToACN
|
|
922
988
|
};
|