acn-client 0.6.2 → 0.7.1

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/index.d.ts CHANGED
@@ -329,50 +329,100 @@ interface PendingSessionsResponse {
329
329
  count: number;
330
330
  sessions: SessionEntry[];
331
331
  }
332
- /** Supported payment methods */
333
- type PaymentMethod = 'USDC' | 'USDT' | 'ETH' | 'DAI' | 'CREDIT_CARD' | 'BANK_TRANSFER' | 'PLATFORM_CREDITS';
334
- /** Supported networks */
335
- type PaymentNetwork = 'ETHEREUM' | 'POLYGON' | 'BASE' | 'ARBITRUM' | 'OPTIMISM' | 'SOLANA';
336
- /** Payment capability */
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
- min_amount?: number;
343
- max_amount?: number;
344
- currency?: string;
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
- /** Payment task status */
347
- type PaymentTaskStatus = 'pending' | 'in_progress' | 'completed' | 'failed' | 'cancelled';
348
- /** Payment task */
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
- id: string;
351
- payer_agent_id: string;
352
- payee_agent_id: string;
353
- amount: number;
354
- currency: string;
355
- method: PaymentMethod;
356
- network?: PaymentNetwork;
357
- status: PaymentTaskStatus;
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
- updated_at: string;
360
- transaction_hash?: string;
361
- metadata?: Record<string, unknown>;
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
- /** Payment statistics */
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
- total_received: number;
373
- total_sent: number;
374
- transaction_count: number;
375
- avg_amount: number;
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 {
@@ -489,6 +539,53 @@ interface ApiResponse<T> {
489
539
  error?: string;
490
540
  message?: string;
491
541
  }
542
+ /** Result of a follow or unfollow action */
543
+ interface FollowActionResponse {
544
+ follower_id: string;
545
+ followee_id: string;
546
+ /** Post-state: true after follow, false after unfollow */
547
+ following: boolean;
548
+ /** Whether this call actually mutated state (false on idempotent repeat) */
549
+ changed: boolean;
550
+ }
551
+ /** Result of a follow-status check */
552
+ interface FollowCheckResponse {
553
+ follower_id: string;
554
+ followee_id: string;
555
+ following: boolean;
556
+ }
557
+ type CommunicationPolicyMode = 'open' | 'closed' | 'manifest' | 'allowlist';
558
+ interface CommunicationPolicyResponse {
559
+ agent_id: string;
560
+ communication_policy: {
561
+ mode: CommunicationPolicyMode;
562
+ reject_reason?: string;
563
+ };
564
+ }
565
+ /** Result of an allowlist add/remove action */
566
+ interface AllowlistActionResponse {
567
+ /** The allowlist owner's agent ID */
568
+ owner_id: string;
569
+ target_id: string;
570
+ /** Post-state: true after add, false after remove */
571
+ allowlisted: boolean;
572
+ /** Whether this call actually mutated state */
573
+ changed: boolean;
574
+ }
575
+ /** Single allowlist entry (as returned by GET listing) */
576
+ interface AllowlistEntry {
577
+ target_id: string;
578
+ reason?: string;
579
+ /** ISO-8601 UTC timestamp of when the entry was added */
580
+ created_at: string;
581
+ }
582
+ /** GET /allowlist response */
583
+ interface AllowlistListResponse {
584
+ /** The allowlist owner's agent ID */
585
+ owner_id: string;
586
+ entries: AllowlistEntry[];
587
+ total: number;
588
+ }
492
589
 
493
590
  /**
494
591
  * ACN HTTP Client
@@ -585,8 +682,8 @@ declare class ACNClient {
585
682
  }>;
586
683
  /** Get subnet by ID */
587
684
  getSubnet(subnetId: string): Promise<SubnetInfo>;
588
- /** Delete a subnet */
589
- deleteSubnet(subnetId: string, force?: boolean): Promise<{
685
+ /** Delete a subnet you own (requires Agent API Key — only the owning agent can delete) */
686
+ deleteSubnet(subnetId: string): Promise<{
590
687
  success: boolean;
591
688
  }>;
592
689
  /** Get agents in a subnet */
@@ -788,27 +885,96 @@ declare class ACNClient {
788
885
  * after fetchManifestContent.
789
886
  */
790
887
  deleteManifest(agentId: string, mid: string): Promise<Record<string, unknown>>;
791
- /** Set agent's payment capability */
888
+ /** Set agent's payment capability (requires Agent API Key) */
792
889
  setPaymentCapability(agentId: string, capability: PaymentCapability): Promise<{
793
890
  success: boolean;
794
891
  }>;
795
- /** Get agent's payment capability */
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
+ */
796
901
  getPaymentCapability(agentId: string): Promise<PaymentCapability | null>;
797
- /** Discover agents that accept payments */
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. */
798
923
  discoverPaymentAgents(options?: PaymentDiscoveryOptions): Promise<{
799
924
  agents: AgentInfo[];
800
925
  }>;
801
- /** Get payment task by ID */
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
+ */
802
968
  getPaymentTask(taskId: string): Promise<PaymentTask>;
803
- /** Get agent's payment tasks */
969
+ /** Get the payment tasks an agent is involved in (requires Agent API Key). */
804
970
  getAgentPaymentTasks(agentId: string, options?: {
805
- role?: 'payer' | 'payee';
806
971
  status?: string;
807
972
  limit?: number;
808
973
  }): Promise<{
974
+ agent_id: string;
809
975
  tasks: PaymentTask[];
810
976
  }>;
811
- /** Get agent's payment statistics */
977
+ /** Get an agent's payment statistics (requires Agent API Key). */
812
978
  getPaymentStats(agentId: string): Promise<PaymentStats>;
813
979
  /** Get Prometheus metrics (text format) */
814
980
  getPrometheusMetrics(): Promise<string>;
@@ -874,13 +1040,99 @@ declare class ACNClient {
874
1040
  start_time?: string;
875
1041
  end_time?: string;
876
1042
  }): Promise<Record<string, unknown>>;
1043
+ /**
1044
+ * Follow another agent.
1045
+ *
1046
+ * Idempotent — re-following returns `changed: false`.
1047
+ * @param agentId The follower (must match the authenticated agent).
1048
+ * @param targetId The agent to follow.
1049
+ */
1050
+ follow(agentId: string, targetId: string): Promise<FollowActionResponse>;
1051
+ /**
1052
+ * Unfollow an agent.
1053
+ *
1054
+ * Idempotent — unfollowing a non-followed agent returns `changed: false`.
1055
+ * @param agentId The follower (must match the authenticated agent).
1056
+ * @param targetId The agent to unfollow.
1057
+ */
1058
+ unfollow(agentId: string, targetId: string): Promise<FollowActionResponse>;
1059
+ /**
1060
+ * Check whether `agentId` is following `targetId` (public endpoint).
1061
+ */
1062
+ checkFollow(agentId: string, targetId: string): Promise<FollowCheckResponse>;
1063
+ /**
1064
+ * List agents that `agentId` follows (public endpoint).
1065
+ */
1066
+ listFollows(agentId: string, options?: {
1067
+ limit?: number;
1068
+ offset?: number;
1069
+ }): Promise<AgentSearchResponse>;
1070
+ /**
1071
+ * List agents that follow `agentId` (public endpoint).
1072
+ */
1073
+ listFollowers(agentId: string, options?: {
1074
+ limit?: number;
1075
+ offset?: number;
1076
+ }): Promise<AgentSearchResponse>;
1077
+ /**
1078
+ * Get the authenticated agent's current communication policy (owner only).
1079
+ */
1080
+ getPolicy(agentId: string): Promise<CommunicationPolicyResponse>;
1081
+ /**
1082
+ * Update the agent's inbound communication policy (owner only).
1083
+ *
1084
+ * @param agentId Must match the authenticated agent.
1085
+ * @param mode `open` | `closed` | `manifest` | `allowlist`
1086
+ * @param rejectReason Optional message shown to rejected senders (closed mode).
1087
+ */
1088
+ updatePolicy(agentId: string, mode: CommunicationPolicyMode, rejectReason?: string): Promise<CommunicationPolicyResponse>;
1089
+ /**
1090
+ * Add an agent to the allowlist (owner only).
1091
+ *
1092
+ * Only effective when `communication_policy.mode = 'allowlist'`.
1093
+ * Idempotent — re-adding returns `changed: false`.
1094
+ *
1095
+ * @param agentId Must match the authenticated agent.
1096
+ * @param targetId Agent to trust.
1097
+ * @param reason Optional free-form note (≤ 200 chars).
1098
+ */
1099
+ addToAllowlist(agentId: string, targetId: string, reason?: string): Promise<AllowlistActionResponse>;
1100
+ /**
1101
+ * Remove an agent from the allowlist (owner only).
1102
+ *
1103
+ * Idempotent — removing a non-member returns `changed: false`.
1104
+ */
1105
+ removeFromAllowlist(agentId: string, targetId: string): Promise<AllowlistActionResponse>;
1106
+ /**
1107
+ * List the authenticated agent's allowlist (owner only).
1108
+ */
1109
+ listAllowlist(agentId: string, options?: {
1110
+ limit?: number;
1111
+ offset?: number;
1112
+ }): Promise<AllowlistListResponse>;
877
1113
  }
878
1114
  /**
879
1115
  * ACN API Error
1116
+ *
1117
+ * Three body shapes are normalised here:
1118
+ * - 4xx with string detail → `{ detail: "..." }`
1119
+ * - 422 validation (FastAPI) → `{ detail: [{loc, msg, type}, ...] }`
1120
+ * - 5xx sanitised (H4) → `{ error: "...", message: "...", request_id: "..." }`
1121
+ *
1122
+ * `errorCode` and `requestId` mirror the Python SDK's ACNError so
1123
+ * callers can branch on the error code and quote request_id in support
1124
+ * tickets without extra parsing.
880
1125
  */
881
1126
  declare class ACNError extends Error {
882
1127
  status: number;
883
- constructor(status: number, message: string);
1128
+ /** ACN internal error code (present on sanitised 5xx responses) */
1129
+ errorCode?: string;
1130
+ /** Request ID minted by ACN for 5xx responses (useful for support) */
1131
+ requestId?: string;
1132
+ constructor(status: number, message: string, options?: {
1133
+ errorCode?: string;
1134
+ requestId?: string;
1135
+ });
884
1136
  }
885
1137
 
886
1138
  /**
@@ -973,4 +1225,4 @@ declare class ACNRealtime {
973
1225
  */
974
1226
  declare function subscribeToACN<T = unknown>(baseUrl: string, channel: string, handler: WSEventHandler<T>): () => void;
975
1227
 
976
- 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 ApiResponse, type AttentionFee, type AuditEvent, type AuditQueryOptions, type BroadcastBySkillRequest, type BroadcastByTagRequest, type BroadcastRequest, type BroadcastStrategy, type ComponentHealth, type DashboardData, 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 };