acn-client 0.12.0 → 0.13.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
@@ -4,8 +4,20 @@
4
4
  * Type definitions synced with ACN API models.
5
5
  * @see https://github.com/ACNet-AI/ACN
6
6
  */
7
- /** Agent status */
8
- type AgentStatus = 'online' | 'offline' | 'busy';
7
+ /**
8
+ * Agent status.
9
+ *
10
+ * The server emits exactly `'online'` or `'offline'`, derived from the
11
+ * Redis `acn:agents:{id}:alive` TTL key (the single source of truth
12
+ * since the 2026-05 alive-as-SSOT refactor — see ACN
13
+ * `docs/agent-registry-removal.md`).
14
+ *
15
+ * Historical note: this union used to include `'busy'`. The server has
16
+ * not emitted that value for some time; the literal was narrowed out
17
+ * in SDK 0.13 to match the on-wire contract. Code paths handling
18
+ * `'busy'` were unreachable.
19
+ */
20
+ type AgentStatus = 'online' | 'offline';
9
21
  /** Agent list filter status (includes "all" for discovery) */
10
22
  type AgentSearchStatus = AgentStatus | 'all';
11
23
  /** Agent information */
@@ -107,18 +119,73 @@ interface AgentSearchOptions {
107
119
  }
108
120
  /** Subnet information */
109
121
  interface SubnetInfo {
122
+ /**
123
+ * Subnet identifier. The server wire field is `subnet_id`; some
124
+ * older responses may also surface `id`. Prefer `subnet_id` when
125
+ * present, falling back to `id`.
126
+ */
110
127
  id: string;
128
+ /** Wire-side identifier (ADR-0003+ servers always emit this). */
129
+ subnet_id?: string;
111
130
  name: string;
112
131
  description?: string;
113
- created_at: string;
114
- agent_count: number;
132
+ created_at?: string;
133
+ agent_count?: number;
115
134
  metadata?: Record<string, unknown>;
135
+ owner?: string;
136
+ harness_url?: string;
137
+ harness_registered?: boolean;
138
+ /** ADR-0003 — parent subnet when this is a nested child. */
139
+ parent_subnet_id?: string | null;
140
+ /** ADR-0003 — defaults to `'persistent'` on the server. */
141
+ lifecycle?: SubnetLifecycle;
142
+ /** ADR-0003 — bound task when `lifecycle === 'task_scoped'`. */
143
+ linked_task_id?: string | null;
144
+ [key: string]: unknown;
145
+ }
146
+ /** Response from `GET /api/v1/subnets/{id}/children` (ADR-0003). */
147
+ interface SubnetChildrenListResponse {
148
+ count: number;
149
+ subnets: SubnetInfo[];
116
150
  }
151
+ /**
152
+ * Subnet lifecycle (ADR-0003). `'persistent'` is the legacy default —
153
+ * the subnet survives until manually deleted. `'task_scoped'` binds
154
+ * the subnet to a task: the server auto-dissolves it when that task
155
+ * reaches a terminal state. Only valid together with `linked_task_id`.
156
+ */
157
+ type SubnetLifecycle = 'persistent' | 'task_scoped';
117
158
  /** Subnet creation request */
118
159
  interface SubnetCreateRequest {
119
160
  name: string;
120
161
  description?: string;
121
162
  metadata?: Record<string, unknown>;
163
+ /**
164
+ * ADR-0003 nested-subnet parent. When set, the new subnet becomes a
165
+ * child of `parent_subnet_id`. Single-layer cap: the parent itself
166
+ * must be top-level. Immutable after creation.
167
+ */
168
+ parent_subnet_id?: string;
169
+ /**
170
+ * ADR-0003 lifecycle. Defaults to `'persistent'` when omitted.
171
+ * `'task_scoped'` requires `linked_task_id` and the subnet
172
+ * auto-dissolves when that task terminates.
173
+ */
174
+ lifecycle?: SubnetLifecycle;
175
+ /**
176
+ * ADR-0003 task binding. Required when `lifecycle === 'task_scoped'`,
177
+ * ignored otherwise.
178
+ */
179
+ linked_task_id?: string;
180
+ /**
181
+ * ADR-0004 admission policy. When omitted the server defaults to
182
+ * `'open'` (legacy unrestricted self-join). `'approval'` opts the
183
+ * subnet into the admission state machine — joins are gated by
184
+ * allowlist / join_request / invitation.
185
+ *
186
+ * Immutable post-creation.
187
+ */
188
+ join_policy?: SubnetJoinPolicy;
122
189
  }
123
190
  /** Subnet creation response */
124
191
  interface SubnetCreateResponse {
@@ -126,6 +193,96 @@ interface SubnetCreateResponse {
126
193
  subnet_id: string;
127
194
  message: string;
128
195
  }
196
+ /** Subnet join-policy values. Immutable post-creation. */
197
+ type SubnetJoinPolicy = 'open' | 'approval';
198
+ /** Single allowlist entry (returned by `subnetAllowlistAdd`). */
199
+ interface SubnetAllowlistEntry {
200
+ agent_id: string;
201
+ added_by: string;
202
+ added_at: string;
203
+ [key: string]: unknown;
204
+ }
205
+ /** Response envelope for `subnetAllowlistList` (owner only). */
206
+ interface SubnetAllowlistListResponse {
207
+ subnet_id: string;
208
+ entries: SubnetAllowlistEntry[];
209
+ [key: string]: unknown;
210
+ }
211
+ /**
212
+ * Audit row covering the three ADR-0004 row kinds. The same shape
213
+ * is returned for join_request approve/reject/withdraw,
214
+ * invitation accept/reject/cancel, and the allowlist_auto rows
215
+ * synthesised on allowlist-hit joins. `agent_id` is the applicant
216
+ * for join_requests / allowlist_auto and the invitee for
217
+ * invitations.
218
+ */
219
+ interface SubnetJoinRequestRow {
220
+ request_id: string;
221
+ subnet_id: string;
222
+ kind: 'join_request' | 'allowlist_auto' | 'invitation';
223
+ status: 'pending' | 'approved' | 'rejected' | 'withdrawn';
224
+ initiated_by: string;
225
+ agent_id: string;
226
+ decided_by?: string | null;
227
+ decided_at?: string | null;
228
+ note?: string | null;
229
+ created_at: string;
230
+ [key: string]: unknown;
231
+ }
232
+ /** Response envelope for `subnetJoinRequestList` (owner only). */
233
+ interface SubnetJoinRequestListResponse {
234
+ subnet_id: string;
235
+ items: SubnetJoinRequestRow[];
236
+ [key: string]: unknown;
237
+ }
238
+ /** Response envelope for `subnetInvitationList` (owner only). */
239
+ interface SubnetInvitationListResponse {
240
+ subnet_id: string;
241
+ items: SubnetJoinRequestRow[];
242
+ [key: string]: unknown;
243
+ }
244
+ /** Response envelope for `agentSubnetInvitations` (self only). */
245
+ interface AgentSubnetInvitationsResponse {
246
+ agent_id: string;
247
+ items: SubnetJoinRequestRow[];
248
+ [key: string]: unknown;
249
+ }
250
+ /**
251
+ * Discriminated union for `subnetInvitationSend`. The server
252
+ * returns 202 + the normal-path shape when the target has no
253
+ * pending join_request, and 200 + the merge-path shape when an
254
+ * existing pending join_request is auto-approved by the invite.
255
+ *
256
+ * Discriminate on `auto_resolved` (absent | true) to dispatch.
257
+ */
258
+ type SubnetInvitationSendResponse = {
259
+ invitation_id: string;
260
+ status: 'pending';
261
+ auto_resolved?: undefined;
262
+ [key: string]: unknown;
263
+ } | {
264
+ auto_resolved: true;
265
+ resolved_kind: 'join_request';
266
+ request_id: string;
267
+ [key: string]: unknown;
268
+ };
269
+ /** Pagination + filter options for the two list endpoints. */
270
+ interface SubnetJoinRequestListOptions {
271
+ /**
272
+ * Defaults to `'join_request'` server-side. Pass `'allowlist_auto'`
273
+ * to inspect synthesised audit rows. `'invitation'` is rejected
274
+ * with 400 INVALID_KIND_FILTER — use `subnetInvitationList`.
275
+ */
276
+ kind?: 'join_request' | 'allowlist_auto';
277
+ status?: 'pending' | 'approved' | 'rejected' | 'withdrawn';
278
+ limit?: number;
279
+ offset?: number;
280
+ }
281
+ interface SubnetInvitationListOptions {
282
+ status?: 'pending' | 'approved' | 'rejected' | 'withdrawn';
283
+ limit?: number;
284
+ offset?: number;
285
+ }
129
286
  /** Message types */
130
287
  type MessageType = 'text' | 'data' | 'notification' | 'task' | 'result';
131
288
  /** A2A Message */
@@ -294,11 +451,23 @@ interface ManifestSendRequest {
294
451
  /**
295
452
  * Public read-only summary of an agent's communication policy.
296
453
  * Returned by GET /agents/{agent_id}/communication_profile (no auth required).
454
+ *
455
+ * `unread_manifest_count` surfaces queue buildup so platform tooling
456
+ * and senders can detect agents in `manifest` / `allowlist` mode that
457
+ * have stopped polling. Current ACN releases always populate it.
297
458
  */
298
459
  interface CommunicationProfile {
299
460
  agent_id: string;
300
461
  mode: 'open' | 'manifest' | 'allowlist' | 'closed';
301
462
  attention_fee_required: boolean;
463
+ /**
464
+ * Number of pending manifest entries that have not yet been
465
+ * acked by this agent. A non-zero (or growing) value signals
466
+ * that the agent is keeping mail in escrow but not actively
467
+ * polling — senders should treat them as effectively
468
+ * unreachable in `manifest` / `allowlist` mode.
469
+ */
470
+ unread_manifest_count: number;
302
471
  }
303
472
  /** Session status values */
304
473
  type SessionStatus = 'pending' | 'accepted' | 'rejected' | 'closed';
@@ -651,6 +820,17 @@ interface CommunicationPolicyResponse {
651
820
  mode: CommunicationPolicyMode;
652
821
  reject_reason?: string;
653
822
  };
823
+ /**
824
+ * Conditionally present when the post-update `mode` is
825
+ * `'manifest'` or `'allowlist'`. Carries a human-readable
826
+ * reminder that messages from non-trusted senders divert to
827
+ * the manifest queue and require the agent to actively poll
828
+ * `GET /communication/manifest/{id}` — otherwise those
829
+ * messages expire after the configured TTL (default 7 days).
830
+ * Surface this in agent CLIs / dashboards so operators don't
831
+ * silently lock themselves out.
832
+ */
833
+ warning?: string;
654
834
  }
655
835
  /** Result of an allowlist add/remove action */
656
836
  interface AllowlistActionResponse {
@@ -809,6 +989,22 @@ declare class ACNClient {
809
989
  }>;
810
990
  /** Get subnet by ID */
811
991
  getSubnet(subnetId: string): Promise<SubnetInfo>;
992
+ /**
993
+ * List immediate children of a subnet (ADR-0003).
994
+ *
995
+ * Wraps `GET /api/v1/subnets/{parentSubnetId}/children`. Returns
996
+ * `SUBNET_NOT_FOUND` when the parent does not exist. Visibility
997
+ * matches `listSubnets` — private children you cannot see are
998
+ * omitted from the result set.
999
+ */
1000
+ listChildren(parentSubnetId: string): Promise<SubnetInfo[]>;
1001
+ /**
1002
+ * Promote a `task_scoped` subnet to `persistent` (ADR-0003).
1003
+ *
1004
+ * Owner-only. Idempotent — promoting an already-persistent subnet
1005
+ * returns its current state unchanged.
1006
+ */
1007
+ promoteSubnet(subnetId: string): Promise<SubnetInfo>;
812
1008
  /** Delete a subnet you own (requires Agent API Key — only the owning agent can delete) */
813
1009
  deleteSubnet(subnetId: string): Promise<{
814
1010
  success: boolean;
@@ -829,6 +1025,138 @@ declare class ACNClient {
829
1025
  getAgentSubnets(agentId: string): Promise<{
830
1026
  subnets: string[];
831
1027
  }>;
1028
+ /**
1029
+ * Pre-authorise `agentId` on `subnetId`'s allowlist (owner only).
1030
+ *
1031
+ * Allowlisted agents skip the approval queue: their next
1032
+ * `joinSubnet` lands in branch 4 (allowlist hit) and becomes an
1033
+ * immediate member with an `allowlist_auto` audit row.
1034
+ *
1035
+ * Server returns 201 with the persisted entry; duplicate adds
1036
+ * return 409 ALREADY_ON_ALLOWLIST (raised as an error, never
1037
+ * silently no-op'd).
1038
+ */
1039
+ subnetAllowlistAdd(subnetId: string, agentId: string): Promise<SubnetAllowlistEntry>;
1040
+ /**
1041
+ * Remove `agentId` from `subnetId`'s allowlist (owner only).
1042
+ *
1043
+ * Idempotent — removing an entry that doesn't exist still
1044
+ * returns 204. Per ADR-0004 §"Allowlist mutation does not
1045
+ * affect agents who already joined", this does NOT revoke
1046
+ * membership for agents already admitted via the allowlist.
1047
+ */
1048
+ subnetAllowlistRemove(subnetId: string, agentId: string): Promise<void>;
1049
+ /**
1050
+ * List `subnetId`'s allowlist entries (owner only).
1051
+ *
1052
+ * Owner-only by design — the allowlist is a privacy-sensitive
1053
+ * trust signal and exposing it publicly would leak relationship
1054
+ * metadata.
1055
+ */
1056
+ subnetAllowlistList(subnetId: string, options?: {
1057
+ limit?: number;
1058
+ offset?: number;
1059
+ }): Promise<SubnetAllowlistListResponse>;
1060
+ /**
1061
+ * Owner approves a pending join_request (CAS pending → approved).
1062
+ *
1063
+ * Side effects: applicant added to `subnet.member_agent_ids` and
1064
+ * the `subnet.join_approved` webhook fires. The applicant is
1065
+ * still expected to call `joinSubnet` to register the
1066
+ * `agent.subnet_ids` back-reference (per ADR-0004 §"State
1067
+ * machine edges").
1068
+ *
1069
+ * Optional `note` (≤500 chars) is recorded on the audit row.
1070
+ */
1071
+ subnetJoinRequestApprove(subnetId: string, requestId: string, options?: {
1072
+ note?: string;
1073
+ }): Promise<SubnetJoinRequestRow>;
1074
+ /**
1075
+ * Owner rejects a pending join_request (CAS pending → rejected).
1076
+ *
1077
+ * No membership change. `subnet.join_rejected` webhook fires.
1078
+ */
1079
+ subnetJoinRequestReject(subnetId: string, requestId: string, options?: {
1080
+ note?: string;
1081
+ }): Promise<SubnetJoinRequestRow>;
1082
+ /**
1083
+ * Applicant withdraws their own pending join_request.
1084
+ *
1085
+ * Self-only — caller must be the agent who originally created
1086
+ * the request. `subnet.join_withdrawn` webhook fires.
1087
+ */
1088
+ subnetJoinRequestWithdraw(subnetId: string, requestId: string, options?: {
1089
+ note?: string;
1090
+ }): Promise<SubnetJoinRequestRow>;
1091
+ /**
1092
+ * Owner lists join_request / allowlist_auto rows for `subnetId`.
1093
+ *
1094
+ * `kind` defaults to `'join_request'`; pass `'allowlist_auto'`
1095
+ * to inspect synthesised allowlist-hit audit rows. Server
1096
+ * rejects `kind='invitation'` with 400 INVALID_KIND_FILTER —
1097
+ * use `subnetInvitationList` instead.
1098
+ */
1099
+ subnetJoinRequestList(subnetId: string, options?: SubnetJoinRequestListOptions): Promise<SubnetJoinRequestListResponse>;
1100
+ /**
1101
+ * Owner sends an invitation to `agentId` (or merges into a
1102
+ * pending join_request from the same target).
1103
+ *
1104
+ * Two response shapes per ADR-0004 §"Invitation merge path":
1105
+ *
1106
+ * - **Normal path** (server returns 202): `{ invitation_id, status: 'pending' }`.
1107
+ * - **Merge path** (server returns 200, request auto-approved):
1108
+ * `{ auto_resolved: true, resolved_kind: 'join_request', request_id }`.
1109
+ *
1110
+ * Discriminate on `auto_resolved` to dispatch.
1111
+ */
1112
+ subnetInvitationSend(subnetId: string, agentId: string, options?: {
1113
+ note?: string;
1114
+ }): Promise<SubnetInvitationSendResponse>;
1115
+ /**
1116
+ * Invitee accepts a pending invitation (CAS pending → approved).
1117
+ *
1118
+ * Self-only against the row's `agent_id`. Side effects: invitee
1119
+ * added to `subnet.member_agent_ids`, the agent's `subnet_ids`
1120
+ * gains the back-reference, and `subnet.invitation_accepted`
1121
+ * webhook fires.
1122
+ */
1123
+ subnetInvitationAccept(subnetId: string, requestId: string, options?: {
1124
+ note?: string;
1125
+ }): Promise<SubnetJoinRequestRow>;
1126
+ /**
1127
+ * Invitee rejects a pending invitation (CAS pending → rejected).
1128
+ *
1129
+ * No membership change. `subnet.invitation_rejected` webhook
1130
+ * fires.
1131
+ */
1132
+ subnetInvitationReject(subnetId: string, requestId: string, options?: {
1133
+ note?: string;
1134
+ }): Promise<SubnetJoinRequestRow>;
1135
+ /**
1136
+ * Owner cancels a pending invitation (CAS pending → withdrawn).
1137
+ *
1138
+ * Owner-only counterpart to applicant withdraw. The row goes to
1139
+ * `withdrawn` (not `rejected`) — distinct audit token so
1140
+ * consumers can tell "owner gave up" from "invitee said no".
1141
+ */
1142
+ subnetInvitationCancel(subnetId: string, requestId: string, options?: {
1143
+ note?: string;
1144
+ }): Promise<SubnetJoinRequestRow>;
1145
+ /**
1146
+ * Owner lists invitation rows for `subnetId`.
1147
+ *
1148
+ * Owner-only — invitees use `agentSubnetInvitations` for their
1149
+ * own cross-subnet view.
1150
+ */
1151
+ subnetInvitationList(subnetId: string, options?: SubnetInvitationListOptions): Promise<SubnetInvitationListResponse>;
1152
+ /**
1153
+ * Invitee's cross-subnet pending-invitation list (self only).
1154
+ *
1155
+ * Returns only `status='pending'` rows. Historical decisions
1156
+ * are queryable per-subnet through the owner-only
1157
+ * `subnetInvitationList`.
1158
+ */
1159
+ agentSubnetInvitations(agentId: string): Promise<AgentSubnetInvitationsResponse>;
832
1160
  /** Send message to an agent */
833
1161
  sendMessage(request: SendMessageRequest): Promise<SendMessageResponse>;
834
1162
  /** Broadcast message to multiple agents in a subnet */
@@ -1387,4 +1715,4 @@ declare class ACNRealtime {
1387
1715
  */
1388
1716
  declare function subscribeToACN<T = unknown>(baseUrl: string, channel: string, handler: WSEventHandler<T>): () => void;
1389
1717
 
1390
- 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 Participation, type ParticipationListResponse, 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 SubnetHarnessRequest, type SubnetInfo, type SystemHealth, type Task, type TaskAcceptResponse, type TaskCreateRequest, type TaskListOptions, type TaskListResponse, type TaskStatus, type WSConnectionOptions, type WSEventHandler, type WSEventType, type WSMessage, type WSState, subscribeToACN };
1718
+ 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 AgentSearchStatus, type AgentStatus, type AgentSubnetInvitationsResponse, 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 CommunicationProfile, type ComponentHealth, type DashboardData, type FollowActionResponse, type FollowCheckResponse, KNOWN_PAYMENT_TASK_STATUSES, type ManifestContentResponse, type ManifestEntry, type ManifestListResponse, type ManifestMessageType, type ManifestSendRequest, type Message, type MessageType, type MetricsData, type Participation, type ParticipationListResponse, type PaymentCapability, type PaymentDiscoveryOptions, type PaymentMethod, type PaymentNetwork, type PaymentRoleStats, type PaymentStats, type PaymentTask, type PaymentTaskStatus, type PendingSessionsResponse, type SendMessageRequest, type SendMessageResponse, type SessionEntry, type SessionInviteRequest, type SessionStatus, type SubnetAllowlistEntry, type SubnetAllowlistListResponse, type SubnetChildrenListResponse, type SubnetCreateRequest, type SubnetCreateResponse, type SubnetHarnessRequest, type SubnetInfo, type SubnetInvitationListOptions, type SubnetInvitationListResponse, type SubnetInvitationSendResponse, type SubnetJoinPolicy, type SubnetJoinRequestListOptions, type SubnetJoinRequestListResponse, type SubnetJoinRequestRow, type SubnetLifecycle, type SystemHealth, type Task, type TaskAcceptResponse, type TaskCreateRequest, type TaskListOptions, type TaskListResponse, type TaskStatus, type WSConnectionOptions, type WSEventHandler, type WSEventType, type WSMessage, type WSState, subscribeToACN };
package/dist/index.js CHANGED
@@ -242,6 +242,29 @@ var ACNClient = class {
242
242
  async getSubnet(subnetId) {
243
243
  return this.get(`/api/v1/subnets/${subnetId}`);
244
244
  }
245
+ /**
246
+ * List immediate children of a subnet (ADR-0003).
247
+ *
248
+ * Wraps `GET /api/v1/subnets/{parentSubnetId}/children`. Returns
249
+ * `SUBNET_NOT_FOUND` when the parent does not exist. Visibility
250
+ * matches `listSubnets` — private children you cannot see are
251
+ * omitted from the result set.
252
+ */
253
+ async listChildren(parentSubnetId) {
254
+ const data = await this.get(
255
+ `/api/v1/subnets/${parentSubnetId}/children`
256
+ );
257
+ return data.subnets;
258
+ }
259
+ /**
260
+ * Promote a `task_scoped` subnet to `persistent` (ADR-0003).
261
+ *
262
+ * Owner-only. Idempotent — promoting an already-persistent subnet
263
+ * returns its current state unchanged.
264
+ */
265
+ async promoteSubnet(subnetId) {
266
+ return this.post(`/api/v1/subnets/${subnetId}/promote`);
267
+ }
245
268
  /** Delete a subnet you own (requires Agent API Key — only the owning agent can delete) */
246
269
  async deleteSubnet(subnetId) {
247
270
  return this.request("DELETE", `/api/v1/subnets/${subnetId}`);
@@ -275,6 +298,207 @@ var ACNClient = class {
275
298
  return this.get(`/api/v1/agents/${agentId}/subnets`);
276
299
  }
277
300
  // ============================================
301
+ // ADR-0004 Subnet Admission
302
+ // ============================================
303
+ //
304
+ // 13 verbs gated by `subnet.join_policy === 'approval'`:
305
+ // - Allowlist (3): owner pre-authorisation.
306
+ // - Join requests (4): applicant-initiated path.
307
+ // - Invitations (5): owner-initiated path.
308
+ // - Agent-side (1): invitee's cross-subnet pending view.
309
+ //
310
+ // The plain `joinSubnet` verb dispatches the six-branch decision
311
+ // tree on the server side — these methods are the admin-side
312
+ // controls used by subnet owners and the per-row decisions used
313
+ // by applicants and invitees.
314
+ //
315
+ // Method names use the `subnet*` prefix to avoid colliding with
316
+ // the existing inbox `addToAllowlist` surface (which lives at
317
+ // `/api/v1/agents/{a}/allowlist/{target}` and is unrelated).
318
+ // ----- Allowlist (owner-only, 3 verbs) ---------------------------------
319
+ /**
320
+ * Pre-authorise `agentId` on `subnetId`'s allowlist (owner only).
321
+ *
322
+ * Allowlisted agents skip the approval queue: their next
323
+ * `joinSubnet` lands in branch 4 (allowlist hit) and becomes an
324
+ * immediate member with an `allowlist_auto` audit row.
325
+ *
326
+ * Server returns 201 with the persisted entry; duplicate adds
327
+ * return 409 ALREADY_ON_ALLOWLIST (raised as an error, never
328
+ * silently no-op'd).
329
+ */
330
+ async subnetAllowlistAdd(subnetId, agentId) {
331
+ return this.post(`/api/v1/subnets/${subnetId}/allowlist`, {
332
+ agent_id: agentId
333
+ });
334
+ }
335
+ /**
336
+ * Remove `agentId` from `subnetId`'s allowlist (owner only).
337
+ *
338
+ * Idempotent — removing an entry that doesn't exist still
339
+ * returns 204. Per ADR-0004 §"Allowlist mutation does not
340
+ * affect agents who already joined", this does NOT revoke
341
+ * membership for agents already admitted via the allowlist.
342
+ */
343
+ async subnetAllowlistRemove(subnetId, agentId) {
344
+ await this.delete(`/api/v1/subnets/${subnetId}/allowlist/${agentId}`);
345
+ }
346
+ /**
347
+ * List `subnetId`'s allowlist entries (owner only).
348
+ *
349
+ * Owner-only by design — the allowlist is a privacy-sensitive
350
+ * trust signal and exposing it publicly would leak relationship
351
+ * metadata.
352
+ */
353
+ async subnetAllowlistList(subnetId, options) {
354
+ const params = {
355
+ limit: options?.limit ?? 100,
356
+ offset: options?.offset ?? 0
357
+ };
358
+ return this.get(`/api/v1/subnets/${subnetId}/allowlist`, params);
359
+ }
360
+ // ----- Join requests (4 verbs: 3 owner-side + 1 applicant-side) --------
361
+ /**
362
+ * Owner approves a pending join_request (CAS pending → approved).
363
+ *
364
+ * Side effects: applicant added to `subnet.member_agent_ids` and
365
+ * the `subnet.join_approved` webhook fires. The applicant is
366
+ * still expected to call `joinSubnet` to register the
367
+ * `agent.subnet_ids` back-reference (per ADR-0004 §"State
368
+ * machine edges").
369
+ *
370
+ * Optional `note` (≤500 chars) is recorded on the audit row.
371
+ */
372
+ async subnetJoinRequestApprove(subnetId, requestId, options) {
373
+ return this.post(
374
+ `/api/v1/subnets/${subnetId}/join-requests/${requestId}/approve`,
375
+ options?.note !== void 0 ? { note: options.note } : void 0
376
+ );
377
+ }
378
+ /**
379
+ * Owner rejects a pending join_request (CAS pending → rejected).
380
+ *
381
+ * No membership change. `subnet.join_rejected` webhook fires.
382
+ */
383
+ async subnetJoinRequestReject(subnetId, requestId, options) {
384
+ return this.post(
385
+ `/api/v1/subnets/${subnetId}/join-requests/${requestId}/reject`,
386
+ options?.note !== void 0 ? { note: options.note } : void 0
387
+ );
388
+ }
389
+ /**
390
+ * Applicant withdraws their own pending join_request.
391
+ *
392
+ * Self-only — caller must be the agent who originally created
393
+ * the request. `subnet.join_withdrawn` webhook fires.
394
+ */
395
+ async subnetJoinRequestWithdraw(subnetId, requestId, options) {
396
+ return this.request(
397
+ "DELETE",
398
+ `/api/v1/subnets/${subnetId}/join-requests/${requestId}`,
399
+ options?.note !== void 0 ? { body: { note: options.note } } : void 0
400
+ );
401
+ }
402
+ /**
403
+ * Owner lists join_request / allowlist_auto rows for `subnetId`.
404
+ *
405
+ * `kind` defaults to `'join_request'`; pass `'allowlist_auto'`
406
+ * to inspect synthesised allowlist-hit audit rows. Server
407
+ * rejects `kind='invitation'` with 400 INVALID_KIND_FILTER —
408
+ * use `subnetInvitationList` instead.
409
+ */
410
+ async subnetJoinRequestList(subnetId, options) {
411
+ const params = {
412
+ kind: options?.kind ?? "join_request",
413
+ limit: options?.limit ?? 100,
414
+ offset: options?.offset ?? 0
415
+ };
416
+ if (options?.status !== void 0) params.status = options.status;
417
+ return this.get(`/api/v1/subnets/${subnetId}/join-requests`, params);
418
+ }
419
+ // ----- Invitations (5 + 1 verbs) ---------------------------------------
420
+ /**
421
+ * Owner sends an invitation to `agentId` (or merges into a
422
+ * pending join_request from the same target).
423
+ *
424
+ * Two response shapes per ADR-0004 §"Invitation merge path":
425
+ *
426
+ * - **Normal path** (server returns 202): `{ invitation_id, status: 'pending' }`.
427
+ * - **Merge path** (server returns 200, request auto-approved):
428
+ * `{ auto_resolved: true, resolved_kind: 'join_request', request_id }`.
429
+ *
430
+ * Discriminate on `auto_resolved` to dispatch.
431
+ */
432
+ async subnetInvitationSend(subnetId, agentId, options) {
433
+ const body = { agent_id: agentId };
434
+ if (options?.note !== void 0) body.note = options.note;
435
+ return this.post(`/api/v1/subnets/${subnetId}/invitations`, body);
436
+ }
437
+ /**
438
+ * Invitee accepts a pending invitation (CAS pending → approved).
439
+ *
440
+ * Self-only against the row's `agent_id`. Side effects: invitee
441
+ * added to `subnet.member_agent_ids`, the agent's `subnet_ids`
442
+ * gains the back-reference, and `subnet.invitation_accepted`
443
+ * webhook fires.
444
+ */
445
+ async subnetInvitationAccept(subnetId, requestId, options) {
446
+ return this.post(
447
+ `/api/v1/subnets/${subnetId}/invitations/${requestId}/accept`,
448
+ options?.note !== void 0 ? { note: options.note } : void 0
449
+ );
450
+ }
451
+ /**
452
+ * Invitee rejects a pending invitation (CAS pending → rejected).
453
+ *
454
+ * No membership change. `subnet.invitation_rejected` webhook
455
+ * fires.
456
+ */
457
+ async subnetInvitationReject(subnetId, requestId, options) {
458
+ return this.post(
459
+ `/api/v1/subnets/${subnetId}/invitations/${requestId}/reject`,
460
+ options?.note !== void 0 ? { note: options.note } : void 0
461
+ );
462
+ }
463
+ /**
464
+ * Owner cancels a pending invitation (CAS pending → withdrawn).
465
+ *
466
+ * Owner-only counterpart to applicant withdraw. The row goes to
467
+ * `withdrawn` (not `rejected`) — distinct audit token so
468
+ * consumers can tell "owner gave up" from "invitee said no".
469
+ */
470
+ async subnetInvitationCancel(subnetId, requestId, options) {
471
+ return this.request(
472
+ "DELETE",
473
+ `/api/v1/subnets/${subnetId}/invitations/${requestId}`,
474
+ options?.note !== void 0 ? { body: { note: options.note } } : void 0
475
+ );
476
+ }
477
+ /**
478
+ * Owner lists invitation rows for `subnetId`.
479
+ *
480
+ * Owner-only — invitees use `agentSubnetInvitations` for their
481
+ * own cross-subnet view.
482
+ */
483
+ async subnetInvitationList(subnetId, options) {
484
+ const params = {
485
+ limit: options?.limit ?? 100,
486
+ offset: options?.offset ?? 0
487
+ };
488
+ if (options?.status !== void 0) params.status = options.status;
489
+ return this.get(`/api/v1/subnets/${subnetId}/invitations`, params);
490
+ }
491
+ /**
492
+ * Invitee's cross-subnet pending-invitation list (self only).
493
+ *
494
+ * Returns only `status='pending'` rows. Historical decisions
495
+ * are queryable per-subnet through the owner-only
496
+ * `subnetInvitationList`.
497
+ */
498
+ async agentSubnetInvitations(agentId) {
499
+ return this.get(`/api/v1/agents/${agentId}/subnet-invitations`);
500
+ }
501
+ // ============================================
278
502
  // Communication
279
503
  // ============================================
280
504
  /** Send message to an agent */
@@ -920,6 +1144,7 @@ var ACNError = class extends Error {
920
1144
  this.errorCode = options?.errorCode;
921
1145
  this.requestId = options?.requestId;
922
1146
  }
1147
+ status;
923
1148
  /** ACN internal error code (present on sanitised 5xx responses) */
924
1149
  errorCode;
925
1150
  /** Request ID minted by ACN for 5xx responses (useful for support) */