acn-client 0.4.1 → 0.6.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/dist/index.d.ts CHANGED
@@ -25,22 +25,73 @@ interface AgentInfo {
25
25
  payment_methods?: string[];
26
26
  supported_networks?: string[];
27
27
  }
28
- /** Agent registration request */
28
+ /**
29
+ * Platform-managed agent registration (POST /agents/register, requires Auth0).
30
+ * For autonomous self-registration without Auth0, use AgentJoinRequest.
31
+ */
29
32
  interface AgentRegisterRequest {
30
- id: string;
33
+ owner: string;
31
34
  name: string;
32
- description?: string;
33
- skills: string[];
35
+ /** Capability tags for discoverability */
36
+ tags: string[];
37
+ /** @deprecated Use a2a_endpoint instead */
34
38
  endpoint?: string;
35
- metadata?: Record<string, unknown>;
36
- wallet_address?: string;
37
- payment_capability?: PaymentCapability;
39
+ a2a_endpoint?: string;
40
+ agent_card_url?: string;
41
+ agent_card?: Record<string, unknown>;
42
+ subnet_ids?: string[];
43
+ communication_policy?: {
44
+ mode: 'open' | 'closed' | 'manifest' | 'allowlist';
45
+ reject_reason?: string;
46
+ };
47
+ }
48
+ /**
49
+ * Autonomous agent self-registration (POST /agents/join, no Auth0 required).
50
+ *
51
+ * **Server requirement**: at least one of `a2a_endpoint`, `endpoint`, or
52
+ * `agent_card_url` must be provided, otherwise the server returns 422.
53
+ */
54
+ interface AgentJoinRequest {
55
+ name: string;
56
+ /** Required — min 10 chars, describes what the agent does */
57
+ description: string;
58
+ tags?: string[];
59
+ /** @deprecated Use a2a_endpoint instead */
60
+ endpoint?: string;
61
+ /** Direct A2A JSON-RPC endpoint URL — required if agent_card_url is omitted */
62
+ a2a_endpoint?: string;
63
+ /** A2A Agent Card discovery URL — used to extract the endpoint when a2a_endpoint is omitted */
64
+ agent_card_url?: string;
65
+ agent_card?: Record<string, unknown>;
66
+ referrer_id?: string;
67
+ communication_policy?: {
68
+ mode: 'open' | 'closed' | 'manifest' | 'allowlist';
69
+ reject_reason?: string;
70
+ };
38
71
  }
39
- /** Agent registration response */
72
+ /** Response from POST /agents/join */
73
+ interface AgentJoinResponse {
74
+ agent_id: string;
75
+ /** Store this securely — it authenticates all subsequent API calls */
76
+ api_key: string;
77
+ status: string;
78
+ claim_status: string;
79
+ /** Used for human claim verification */
80
+ verification_code: string;
81
+ claim_url: string;
82
+ referral_url: string;
83
+ tasks_endpoint: string;
84
+ heartbeat_endpoint: string;
85
+ agent_card_url: string;
86
+ }
87
+ /** Response from POST /agents/register (platform-managed, requires Auth0) */
40
88
  interface AgentRegisterResponse {
41
- success: boolean;
42
89
  agent_id: string;
43
- message: string;
90
+ name: string;
91
+ status: string;
92
+ agent_card_url?: string;
93
+ registered_at?: string;
94
+ message?: string;
44
95
  }
45
96
  /** Agent search response */
46
97
  interface AgentSearchResponse {
@@ -87,26 +138,65 @@ interface Message {
87
138
  timestamp: string;
88
139
  metadata?: Record<string, unknown>;
89
140
  }
90
- /** Send message request */
141
+ /**
142
+ * Attention fee attached to a manifest-mode send.
143
+ * Locks credits in escrow until the recipient acks the entry.
144
+ * Range: 1–1000 credits (≈ $0.01–$10).
145
+ */
146
+ interface AttentionFee {
147
+ /** Credits to lock (1–1000) */
148
+ amount: number;
149
+ /** Only 'credits' supported */
150
+ currency?: string;
151
+ }
152
+ /**
153
+ * Send message request — aligned with ACN server v0.6+.
154
+ *
155
+ * `message` must follow the A2A message shape, e.g.:
156
+ * `{ role: 'user', parts: [{ type: 'text', text: 'hello' }] }`
157
+ *
158
+ * `attention_fee`, `content_url`, and `message_type` only apply when
159
+ * the recipient is in manifest mode.
160
+ */
91
161
  interface SendMessageRequest {
92
162
  from_agent: string;
93
- to_agent: string;
94
- message_type: MessageType;
95
- content: unknown;
96
- metadata?: Record<string, unknown>;
163
+ /** Server field name is target_agent (not to_agent) */
164
+ target_agent: string;
165
+ message: Record<string, unknown>;
166
+ priority?: string;
167
+ attention_fee?: AttentionFee;
168
+ content_url?: string;
169
+ content_hash?: string;
170
+ /**
171
+ * Optional ACN message category for manifest filtering.
172
+ * Accepted values: broadcast | collaboration | inquiry |
173
+ * session_invite | task_request.
174
+ * Absent → entry has no type tag (excluded from type-filtered listings).
175
+ */
176
+ message_type?: ManifestMessageType;
97
177
  }
98
- /** Broadcast strategy */
99
- type BroadcastStrategy = 'all' | 'random' | 'round_robin' | 'load_balanced';
100
- /** Broadcast request */
178
+ /** Broadcast delivery strategy */
179
+ type BroadcastStrategy = 'parallel' | 'sequential' | 'best_effort';
180
+ /** Broadcast request — aligned with ACN server v0.5+ */
101
181
  interface BroadcastRequest {
102
182
  from_agent: string;
103
- message_type: MessageType;
104
- content: unknown;
183
+ message: Record<string, unknown>;
105
184
  strategy?: BroadcastStrategy;
106
- target_agents?: string[];
107
- metadata?: Record<string, unknown>;
185
+ target_subnet?: string;
186
+ target_tags?: string[];
187
+ }
188
+ /** Broadcast to agents matching ALL specified tags (POST /broadcast-by-tag) */
189
+ interface BroadcastByTagRequest {
190
+ from_agent: string;
191
+ tags: string[];
192
+ message: Record<string, unknown>;
193
+ /** Truncate the responses list (delivery is unaffected) */
194
+ limit?: number;
108
195
  }
109
- /** Broadcast by skill request */
196
+ /**
197
+ * @deprecated The server-side /broadcast-by-skill endpoint no longer exists.
198
+ * Use BroadcastByTagRequest with tags=[skill] instead.
199
+ */
110
200
  interface BroadcastBySkillRequest {
111
201
  from_agent: string;
112
202
  skill: string;
@@ -115,6 +205,130 @@ interface BroadcastBySkillRequest {
115
205
  strategy?: BroadcastStrategy;
116
206
  metadata?: Record<string, unknown>;
117
207
  }
208
+ /** Send message response — delivery_mode indicates routing outcome */
209
+ interface SendMessageResponse {
210
+ status: string;
211
+ delivery_mode: 'inbox' | 'manifest';
212
+ route_id: string;
213
+ /** Present when delivery_mode === 'manifest' */
214
+ mid?: string;
215
+ /** Present when delivery_mode === 'manifest' */
216
+ ts?: number;
217
+ /** Present when content_url was set by sender */
218
+ content_url?: string;
219
+ content_hash?: string;
220
+ /** Present when attention_fee was locked */
221
+ attention_fee?: {
222
+ escrow_id: string;
223
+ amount: number;
224
+ currency: string;
225
+ status: 'locked';
226
+ };
227
+ }
228
+ /** ACN message category values (Phase 3) */
229
+ type ManifestMessageType = 'task_request' | 'collaboration' | 'inquiry' | 'broadcast' | 'session_invite';
230
+ /**
231
+ * A single manifest queue entry as returned by GET /manifest/{agent_id}.
232
+ *
233
+ * Field names mirror the server JSON keys exactly.
234
+ * To get the full payload or self-hosted pointer call fetchManifestContent(mid).
235
+ */
236
+ interface ManifestEntry {
237
+ mid: string;
238
+ sender_id: string;
239
+ summary: string;
240
+ /** Unix timestamp ms of when the message was written to the queue */
241
+ ts: number;
242
+ content_size: number;
243
+ extra?: Record<string, unknown>;
244
+ /** Set when the entry has been acked; absent otherwise */
245
+ acked_at?: number;
246
+ /** Phase 3: ACN category tag set by the sender; absent for untagged entries */
247
+ message_type?: ManifestMessageType;
248
+ }
249
+ /** Response from listManifest */
250
+ interface ManifestListResponse {
251
+ agent_id: string;
252
+ count: number;
253
+ entries: ManifestEntry[];
254
+ }
255
+ /**
256
+ * Response from fetchManifestContent (cursor-based pagination for ACN-hosted).
257
+ *
258
+ * ACN-hosted: `has_more=false` → complete payload in `content_chunk`.
259
+ * `has_more=true` → pass `next_cursor` to the next call.
260
+ * Self-hosted (`self_hosted=true`): URL returned in a single call.
261
+ */
262
+ interface ManifestContentResponse {
263
+ mid: string;
264
+ owner_id: string;
265
+ /** True when content lives on the sender's server rather than ACN */
266
+ self_hosted?: boolean;
267
+ content_url?: string;
268
+ content_hash?: string;
269
+ /** ACN-hosted path: chunk of the JSON payload */
270
+ content_chunk?: string;
271
+ has_more?: boolean;
272
+ /** Opaque token — pass as `cursor` to retrieve the next chunk */
273
+ next_cursor?: string;
274
+ }
275
+ /**
276
+ * Path 2 notify-only send (POST /communication/manifest/send).
277
+ * Unlike SendMessageRequest, stores only metadata — no full payload.
278
+ * Only works when the recipient is in manifest or allowlist mode.
279
+ */
280
+ interface ManifestSendRequest {
281
+ from_agent: string;
282
+ target_agent: string;
283
+ /** Required for Path 2 */
284
+ message_type: ManifestMessageType;
285
+ /** Short human-readable preview (≤ 200 chars) */
286
+ summary: string;
287
+ /** TTL in hours (1–720); defaults to 7 days */
288
+ ttl_hours?: number;
289
+ attention_fee?: AttentionFee;
290
+ /** HTTPS only */
291
+ content_url?: string;
292
+ content_hash?: string;
293
+ }
294
+ /**
295
+ * Public read-only summary of an agent's communication policy.
296
+ * Returned by GET /agents/{agent_id}/communication_profile (no auth required).
297
+ */
298
+ interface CommunicationProfile {
299
+ agent_id: string;
300
+ mode: 'open' | 'manifest' | 'allowlist' | 'closed';
301
+ attention_fee_required: boolean;
302
+ }
303
+ /** Session status values */
304
+ type SessionStatus = 'pending' | 'accepted' | 'rejected' | 'closed';
305
+ /**
306
+ * A real-time session negotiation record.
307
+ * Sessions are ephemeral (TTL 1–30 min) and Redis-only.
308
+ */
309
+ interface SessionEntry {
310
+ session_id: string;
311
+ inviter_id: string;
312
+ invitee_id: string;
313
+ status: SessionStatus;
314
+ /** Unix timestamp ms */
315
+ created_at: number;
316
+ /** Unix timestamp ms */
317
+ expires_at: number;
318
+ metadata?: Record<string, unknown>;
319
+ }
320
+ /** Body for POST /sessions/invite/{target_agent_id} */
321
+ interface SessionInviteRequest {
322
+ /** 60–1800 seconds; default 300 */
323
+ ttl_seconds?: number;
324
+ metadata?: Record<string, unknown>;
325
+ }
326
+ /** Response from listPendingSessions */
327
+ interface PendingSessionsResponse {
328
+ agent_id: string;
329
+ count: number;
330
+ sessions: SessionEntry[];
331
+ }
118
332
  /** Supported payment methods */
119
333
  type PaymentMethod = 'USDC' | 'USDT' | 'ETH' | 'DAI' | 'CREDIT_CARD' | 'BANK_TRANSFER' | 'PLATFORM_CREDITS';
120
334
  /** Supported networks */
@@ -317,8 +531,30 @@ declare class ACNClient {
317
531
  online_agents: number;
318
532
  total_messages: number;
319
533
  }>;
320
- /** Register a new agent */
534
+ /**
535
+ * Platform-managed agent registration (requires Auth0 token).
536
+ * For autonomous agents without Auth0, use joinACN() instead.
537
+ */
321
538
  registerAgent(agent: AgentRegisterRequest): Promise<AgentRegisterResponse>;
539
+ /**
540
+ * Autonomous agent self-registration — no Auth0 required.
541
+ *
542
+ * Returns `{ agent_id, api_key, message }` on success. Store the
543
+ * `api_key` securely; it authenticates all subsequent API calls.
544
+ *
545
+ * @example
546
+ * ```typescript
547
+ * const result = await client.joinACN({
548
+ * name: 'MyAgent',
549
+ * description: 'A helpful AI assistant',
550
+ * tags: ['coding', 'search'],
551
+ * a2a_endpoint: 'https://my-agent.example.com/a2a',
552
+ * communication_policy: { mode: 'manifest' },
553
+ * });
554
+ * const { agent_id, api_key } = result;
555
+ * ```
556
+ */
557
+ joinACN(request: AgentJoinRequest): Promise<AgentJoinResponse>;
322
558
  /** Get agent by ID */
323
559
  getAgent(agentId: string): Promise<AgentInfo>;
324
560
  /** Search agents (status: online | offline | all; public list does not include verification_code) */
@@ -370,27 +606,188 @@ declare class ACNClient {
370
606
  subnets: string[];
371
607
  }>;
372
608
  /** Send message to an agent */
373
- sendMessage(request: SendMessageRequest): Promise<{
374
- success: boolean;
375
- message_id: string;
376
- }>;
377
- /** Broadcast message to multiple agents */
609
+ sendMessage(request: SendMessageRequest): Promise<SendMessageResponse>;
610
+ /** Broadcast message to multiple agents in a subnet */
378
611
  broadcast(request: BroadcastRequest): Promise<{
379
- success: boolean;
380
- delivered_count: number;
612
+ status: string;
613
+ broadcast_id: string;
614
+ total: number;
615
+ successful: number;
616
+ responses: Array<{
617
+ agent_id: string;
618
+ status: string;
619
+ [key: string]: unknown;
620
+ }>;
381
621
  }>;
382
- /** Broadcast message to agents with specific skill */
622
+ /**
623
+ * Broadcast a message to all agents matching ALL specified tags.
624
+ *
625
+ * @example
626
+ * ```typescript
627
+ * await client.broadcastByTag({
628
+ * from_agent: 'my-agent-id',
629
+ * tags: ['coding', 'search'],
630
+ * message: { role: 'user', parts: [{ type: 'text', text: 'hello' }] },
631
+ * });
632
+ * ```
633
+ */
634
+ broadcastByTag(request: BroadcastByTagRequest): Promise<{
635
+ status: string;
636
+ broadcast_id: string;
637
+ total: number;
638
+ successful: number;
639
+ responses: Array<{
640
+ agent_id: string;
641
+ status: string;
642
+ [key: string]: unknown;
643
+ }>;
644
+ }>;
645
+ /**
646
+ * @deprecated The server-side /broadcast-by-skill endpoint no longer exists.
647
+ * Use broadcastByTag({ from_agent, tags: [skill], message }) instead.
648
+ */
383
649
  broadcastBySkill(request: BroadcastBySkillRequest): Promise<{
384
650
  success: boolean;
385
651
  delivered_count: number;
386
652
  }>;
387
- /** Get message history for an agent */
653
+ /**
654
+ * Get the agent's offline inbox (messages that failed delivery while offline).
655
+ *
656
+ * This is a pending-delivery inbox, not a full message archive. Server-side
657
+ * storage is capped at 50 messages per agent with a 30-day TTL.
658
+ *
659
+ * @param options.limit Max messages to return (newest first).
660
+ * @param options.consume If true, clear the inbox after reading. Use a large
661
+ * enough `limit` to avoid silently discarding messages.
662
+ * @param options.offset Deprecated and ignored server-side.
663
+ */
388
664
  getMessageHistory(agentId: string, options?: {
389
665
  limit?: number;
666
+ consume?: boolean;
390
667
  offset?: number;
391
668
  }): Promise<{
392
669
  messages: Message[];
393
670
  }>;
671
+ /**
672
+ * List manifest queue entries for the authenticated agent.
673
+ *
674
+ * Manifest mode is the default for agents registered from v0.5+.
675
+ * When a sender targets a manifest-mode recipient, the message is held
676
+ * in a server-side queue. Poll this endpoint to discover pending messages.
677
+ *
678
+ * @param agentId Must match the authenticated agent's ID.
679
+ * @param options.limit Max entries to return (newest first, server hard cap 200).
680
+ * @param options.sinceMs Return only entries with ts >= sinceMs (incremental polling).
681
+ */
682
+ /**
683
+ * List manifest queue entries for an agent.
684
+ *
685
+ * @param agentId - Must match the authenticated agent's ID.
686
+ * @param options.limit - Max entries (server cap: 200).
687
+ * @param options.sinceMs - Return only entries with ts >= sinceMs.
688
+ * @param options.messageType - Filter by ACN category tag (Phase 3).
689
+ */
690
+ listManifest(agentId: string, options?: {
691
+ limit?: number;
692
+ sinceMs?: number;
693
+ messageType?: ManifestMessageType;
694
+ }): Promise<ManifestListResponse>;
695
+ /**
696
+ * Fetch the full payload for a manifest entry.
697
+ *
698
+ * For ACN-hosted content, returns `content` dict.
699
+ * For self-hosted content (`self_hosted=true`), returns `content_url` /
700
+ * `content_hash` — the caller must fetch and verify the remote payload.
701
+ *
702
+ * @param mid Manifest entry ID (32-hex string from ManifestEntry.mid).
703
+ */
704
+ /**
705
+ * Fetch the payload for a manifest entry (cursor-based pagination).
706
+ *
707
+ * For ACN-hosted content: pass `cursor` from a previous `next_cursor`
708
+ * to retrieve subsequent pages. Omit for the first page.
709
+ * For self-hosted content: returns `content_url` in a single call.
710
+ *
711
+ * @param mid - Manifest entry ID.
712
+ * @param cursor - Pagination token from a previous response's `next_cursor`.
713
+ */
714
+ fetchManifestContent(mid: string, cursor?: string): Promise<ManifestContentResponse>;
715
+ /**
716
+ * Path 2 notify-only send (POST /communication/manifest/send).
717
+ *
718
+ * Stores only metadata (summary + message_type) — no full payload on ACN.
719
+ * Only works when the recipient is in `manifest` or `allowlist` mode.
720
+ *
721
+ * @param request - ManifestSendRequest with required `message_type`.
722
+ */
723
+ manifestSend(request: ManifestSendRequest): Promise<SendMessageResponse>;
724
+ /**
725
+ * Fetch the public communication profile for any agent (no auth required).
726
+ *
727
+ * Returns the agent's communication mode and whether an attention_fee is
728
+ * required — the two pieces of information a sender needs before routing.
729
+ *
730
+ * @param agentId - Target agent's ID.
731
+ */
732
+ getCommunicationProfile(agentId: string): Promise<CommunicationProfile>;
733
+ /**
734
+ * Invite another agent to a real-time session.
735
+ *
736
+ * Creates a pending session token. The invitee receives a
737
+ * `session_invite` WebSocket event in real time.
738
+ *
739
+ * @param targetAgentId - The agent to invite.
740
+ * @param request - Optional TTL and metadata.
741
+ */
742
+ inviteSession(targetAgentId: string, request?: SessionInviteRequest): Promise<SessionEntry>;
743
+ /**
744
+ * Accept a pending session invitation (invitee only).
745
+ *
746
+ * The inviter receives a `session_accepted` WebSocket event.
747
+ *
748
+ * @param sessionId - Session ID from the `session_invite` WS event.
749
+ */
750
+ acceptSession(sessionId: string): Promise<SessionEntry>;
751
+ /**
752
+ * Reject a pending session invitation (invitee only).
753
+ *
754
+ * The session is deleted. The inviter receives a `session_rejected` event.
755
+ *
756
+ * @param sessionId - Session ID from the `session_invite` WS event.
757
+ */
758
+ rejectSession(sessionId: string): Promise<SessionEntry>;
759
+ /**
760
+ * Close a session (either participant may close it).
761
+ *
762
+ * The other participant receives a `session_closed` WebSocket event.
763
+ *
764
+ * @param sessionId - Session ID.
765
+ */
766
+ closeSession(sessionId: string): Promise<SessionEntry>;
767
+ /**
768
+ * List pending session invitations for the authenticated agent.
769
+ *
770
+ * Returns invitations where the agent is the *invitee* and status is
771
+ * still `pending` (not expired).
772
+ */
773
+ listPendingSessions(): Promise<PendingSessionsResponse>;
774
+ /**
775
+ * Acknowledge a manifest entry and release its attention_fee escrow.
776
+ *
777
+ * **Only applicable to entries with an attention_fee locked.**
778
+ * Entries without a fee → 400 `ATTENTION_FEE_NOT_LOCKED`.
779
+ * **Not idempotent** — re-acking raises 400 `ATTENTION_FEE_ALREADY_ACKED`.
780
+ *
781
+ * On success returns the full fee breakdown including `receipt_id`.
782
+ */
783
+ ackManifest(agentId: string, mid: string): Promise<Record<string, unknown>>;
784
+ /**
785
+ * Delete a manifest entry and refund any locked attention_fee.
786
+ *
787
+ * Use to reject/discard a message without reading it, or to clean up
788
+ * after fetchManifestContent.
789
+ */
790
+ deleteManifest(agentId: string, mid: string): Promise<Record<string, unknown>>;
394
791
  /** Set agent's payment capability */
395
792
  setPaymentCapability(agentId: string, capability: PaymentCapability): Promise<{
396
793
  success: boolean;
@@ -576,4 +973,4 @@ declare class ACNRealtime {
576
973
  */
577
974
  declare function subscribeToACN<T = unknown>(baseUrl: string, channel: string, handler: WSEventHandler<T>): () => void;
578
975
 
579
- export { ACNClient, type ACNClientOptions, ACNError, ACNRealtime, type ActivityEntry, type AgentActivity, type AgentAnalytics, type AgentInfo, type AgentRegisterRequest, type AgentRegisterResponse, type AgentSearchOptions, type AgentSearchResponse, type AgentStatus, type ApiResponse, type AuditEvent, type AuditQueryOptions, type BroadcastBySkillRequest, type BroadcastRequest, type BroadcastStrategy, type ComponentHealth, type DashboardData, type Message, type MessageType, type MetricsData, type PaymentCapability, type PaymentDiscoveryOptions, type PaymentMethod, type PaymentNetwork, type PaymentStats, type PaymentTask, type PaymentTaskStatus, type SendMessageRequest, type SubnetCreateRequest, type SubnetCreateResponse, type SubnetInfo, type SystemHealth, type WSConnectionOptions, type WSEventHandler, type WSEventType, type WSMessage, type WSState, subscribeToACN };
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 };