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/README.md +21 -6
- package/dist/index.d.mts +295 -43
- package/dist/index.d.ts +295 -43
- package/dist/index.js +213 -19
- package/dist/index.mjs +212 -19
- package/package.json +1 -1
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);
|
|
@@ -81,8 +82,32 @@ var ACNClient = class {
|
|
|
81
82
|
signal: controller.signal
|
|
82
83
|
});
|
|
83
84
|
if (!response.ok) {
|
|
84
|
-
|
|
85
|
-
|
|
85
|
+
let body = {};
|
|
86
|
+
try {
|
|
87
|
+
const parsed = await response.json();
|
|
88
|
+
if (parsed && typeof parsed === "object") body = parsed;
|
|
89
|
+
} catch {
|
|
90
|
+
}
|
|
91
|
+
let message;
|
|
92
|
+
const rawDetail = body.detail;
|
|
93
|
+
if (typeof rawDetail === "string") {
|
|
94
|
+
message = rawDetail;
|
|
95
|
+
} else if (Array.isArray(rawDetail) && rawDetail.length > 0) {
|
|
96
|
+
message = rawDetail.slice(0, 5).map((item) => {
|
|
97
|
+
if (item && typeof item === "object") {
|
|
98
|
+
const i = item;
|
|
99
|
+
const loc = Array.isArray(i.loc) ? i.loc.slice(1).join(".") : "";
|
|
100
|
+
const msg = String(i.msg ?? i.type ?? item);
|
|
101
|
+
return loc ? `${loc}: ${msg}` : msg;
|
|
102
|
+
}
|
|
103
|
+
return String(item);
|
|
104
|
+
}).join("; ");
|
|
105
|
+
} else {
|
|
106
|
+
message = String(body.message ?? response.statusText ?? `HTTP ${response.status}`);
|
|
107
|
+
}
|
|
108
|
+
const errorCode = typeof body.error === "string" ? body.error : void 0;
|
|
109
|
+
const requestId = typeof body.request_id === "string" ? body.request_id : response.headers.get("X-Request-ID") ?? void 0;
|
|
110
|
+
throw new ACNError(response.status, message, { errorCode, requestId });
|
|
86
111
|
}
|
|
87
112
|
if (response.status === 204) {
|
|
88
113
|
return void 0;
|
|
@@ -185,11 +210,9 @@ var ACNClient = class {
|
|
|
185
210
|
async getSubnet(subnetId) {
|
|
186
211
|
return this.get(`/api/v1/subnets/${subnetId}`);
|
|
187
212
|
}
|
|
188
|
-
/** Delete a subnet */
|
|
189
|
-
async deleteSubnet(subnetId
|
|
190
|
-
return this.request("DELETE", `/api/v1/subnets/${subnetId}
|
|
191
|
-
params: { force }
|
|
192
|
-
});
|
|
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}`);
|
|
193
216
|
}
|
|
194
217
|
/** Get agents in a subnet */
|
|
195
218
|
async getSubnetAgents(subnetId) {
|
|
@@ -413,32 +436,82 @@ var ACNClient = class {
|
|
|
413
436
|
// ============================================
|
|
414
437
|
// Payment Discovery
|
|
415
438
|
// ============================================
|
|
416
|
-
/** Set agent's payment capability */
|
|
439
|
+
/** Set agent's payment capability (requires Agent API Key) */
|
|
417
440
|
async setPaymentCapability(agentId, capability) {
|
|
418
|
-
return this.post(`/api/v1/
|
|
441
|
+
return this.post(`/api/v1/payments/${agentId}/payment-capability`, capability);
|
|
419
442
|
}
|
|
420
|
-
/**
|
|
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
|
+
*/
|
|
421
452
|
async getPaymentCapability(agentId) {
|
|
422
|
-
|
|
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;
|
|
461
|
+
}
|
|
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);
|
|
423
465
|
}
|
|
424
|
-
/**
|
|
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. */
|
|
425
471
|
async discoverPaymentAgents(options) {
|
|
426
472
|
return this.get("/api/v1/payments/discover", {
|
|
427
473
|
method: options?.method,
|
|
428
|
-
network: options?.network
|
|
429
|
-
|
|
430
|
-
|
|
474
|
+
network: options?.network
|
|
475
|
+
});
|
|
476
|
+
}
|
|
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
|
|
431
499
|
});
|
|
432
500
|
}
|
|
433
|
-
/**
|
|
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
|
+
*/
|
|
434
507
|
async getPaymentTask(taskId) {
|
|
435
508
|
return this.get(`/api/v1/payments/tasks/${taskId}`);
|
|
436
509
|
}
|
|
437
|
-
/** Get
|
|
510
|
+
/** Get the payment tasks an agent is involved in (requires Agent API Key). */
|
|
438
511
|
async getAgentPaymentTasks(agentId, options) {
|
|
439
512
|
return this.get(`/api/v1/payments/tasks/agent/${agentId}`, options);
|
|
440
513
|
}
|
|
441
|
-
/** Get agent's payment statistics */
|
|
514
|
+
/** Get an agent's payment statistics (requires Agent API Key). */
|
|
442
515
|
async getPaymentStats(agentId) {
|
|
443
516
|
return this.get(`/api/v1/payments/stats/${agentId}`);
|
|
444
517
|
}
|
|
@@ -622,13 +695,116 @@ var ACNClient = class {
|
|
|
622
695
|
async getAuditStats(options) {
|
|
623
696
|
return this.get("/api/v1/audit/stats", options);
|
|
624
697
|
}
|
|
698
|
+
// ============================================
|
|
699
|
+
// Social Graph (Follow)
|
|
700
|
+
// ============================================
|
|
701
|
+
/**
|
|
702
|
+
* Follow another agent.
|
|
703
|
+
*
|
|
704
|
+
* Idempotent — re-following returns `changed: false`.
|
|
705
|
+
* @param agentId The follower (must match the authenticated agent).
|
|
706
|
+
* @param targetId The agent to follow.
|
|
707
|
+
*/
|
|
708
|
+
async follow(agentId, targetId) {
|
|
709
|
+
return this.post(`/api/v1/agents/${agentId}/follows/${targetId}`);
|
|
710
|
+
}
|
|
711
|
+
/**
|
|
712
|
+
* Unfollow an agent.
|
|
713
|
+
*
|
|
714
|
+
* Idempotent — unfollowing a non-followed agent returns `changed: false`.
|
|
715
|
+
* @param agentId The follower (must match the authenticated agent).
|
|
716
|
+
* @param targetId The agent to unfollow.
|
|
717
|
+
*/
|
|
718
|
+
async unfollow(agentId, targetId) {
|
|
719
|
+
return this.delete(`/api/v1/agents/${agentId}/follows/${targetId}`);
|
|
720
|
+
}
|
|
721
|
+
/**
|
|
722
|
+
* Check whether `agentId` is following `targetId` (public endpoint).
|
|
723
|
+
*/
|
|
724
|
+
async checkFollow(agentId, targetId) {
|
|
725
|
+
return this.get(`/api/v1/agents/${agentId}/follows/${targetId}`);
|
|
726
|
+
}
|
|
727
|
+
/**
|
|
728
|
+
* List agents that `agentId` follows (public endpoint).
|
|
729
|
+
*/
|
|
730
|
+
async listFollows(agentId, options) {
|
|
731
|
+
return this.get(`/api/v1/agents/${agentId}/follows`, options);
|
|
732
|
+
}
|
|
733
|
+
/**
|
|
734
|
+
* List agents that follow `agentId` (public endpoint).
|
|
735
|
+
*/
|
|
736
|
+
async listFollowers(agentId, options) {
|
|
737
|
+
return this.get(`/api/v1/agents/${agentId}/followers`, options);
|
|
738
|
+
}
|
|
739
|
+
// ============================================
|
|
740
|
+
// Communication Policy
|
|
741
|
+
// ============================================
|
|
742
|
+
/**
|
|
743
|
+
* Get the authenticated agent's current communication policy (owner only).
|
|
744
|
+
*/
|
|
745
|
+
async getPolicy(agentId) {
|
|
746
|
+
return this.get(`/api/v1/agents/${agentId}/policy`);
|
|
747
|
+
}
|
|
748
|
+
/**
|
|
749
|
+
* Update the agent's inbound communication policy (owner only).
|
|
750
|
+
*
|
|
751
|
+
* @param agentId Must match the authenticated agent.
|
|
752
|
+
* @param mode `open` | `closed` | `manifest` | `allowlist`
|
|
753
|
+
* @param rejectReason Optional message shown to rejected senders (closed mode).
|
|
754
|
+
*/
|
|
755
|
+
async updatePolicy(agentId, mode, rejectReason) {
|
|
756
|
+
const policy = { mode };
|
|
757
|
+
if (rejectReason !== void 0) policy.reject_reason = rejectReason;
|
|
758
|
+
return this.request("PATCH", `/api/v1/agents/${agentId}/policy`, {
|
|
759
|
+
body: { communication_policy: policy }
|
|
760
|
+
});
|
|
761
|
+
}
|
|
762
|
+
// ============================================
|
|
763
|
+
// Allowlist
|
|
764
|
+
// ============================================
|
|
765
|
+
/**
|
|
766
|
+
* Add an agent to the allowlist (owner only).
|
|
767
|
+
*
|
|
768
|
+
* Only effective when `communication_policy.mode = 'allowlist'`.
|
|
769
|
+
* Idempotent — re-adding returns `changed: false`.
|
|
770
|
+
*
|
|
771
|
+
* @param agentId Must match the authenticated agent.
|
|
772
|
+
* @param targetId Agent to trust.
|
|
773
|
+
* @param reason Optional free-form note (≤ 200 chars).
|
|
774
|
+
*/
|
|
775
|
+
async addToAllowlist(agentId, targetId, reason) {
|
|
776
|
+
return this.post(
|
|
777
|
+
`/api/v1/agents/${agentId}/allowlist/${targetId}`,
|
|
778
|
+
reason !== void 0 ? { reason } : void 0
|
|
779
|
+
);
|
|
780
|
+
}
|
|
781
|
+
/**
|
|
782
|
+
* Remove an agent from the allowlist (owner only).
|
|
783
|
+
*
|
|
784
|
+
* Idempotent — removing a non-member returns `changed: false`.
|
|
785
|
+
*/
|
|
786
|
+
async removeFromAllowlist(agentId, targetId) {
|
|
787
|
+
return this.delete(`/api/v1/agents/${agentId}/allowlist/${targetId}`);
|
|
788
|
+
}
|
|
789
|
+
/**
|
|
790
|
+
* List the authenticated agent's allowlist (owner only).
|
|
791
|
+
*/
|
|
792
|
+
async listAllowlist(agentId, options) {
|
|
793
|
+
return this.get(`/api/v1/agents/${agentId}/allowlist`, options);
|
|
794
|
+
}
|
|
625
795
|
};
|
|
626
796
|
var ACNError = class extends Error {
|
|
627
|
-
constructor(status, message) {
|
|
797
|
+
constructor(status, message, options) {
|
|
628
798
|
super(message);
|
|
629
799
|
this.status = status;
|
|
630
800
|
this.name = "ACNError";
|
|
801
|
+
this.errorCode = options?.errorCode;
|
|
802
|
+
this.requestId = options?.requestId;
|
|
631
803
|
}
|
|
804
|
+
/** ACN internal error code (present on sanitised 5xx responses) */
|
|
805
|
+
errorCode;
|
|
806
|
+
/** Request ID minted by ACN for 5xx responses (useful for support) */
|
|
807
|
+
requestId;
|
|
632
808
|
};
|
|
633
809
|
|
|
634
810
|
// src/realtime.ts
|
|
@@ -826,10 +1002,28 @@ function subscribeToACN(baseUrl, channel, handler) {
|
|
|
826
1002
|
realtime.disconnect();
|
|
827
1003
|
};
|
|
828
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
|
+
];
|
|
829
1022
|
// Annotate the CommonJS export names for ESM import in node:
|
|
830
1023
|
0 && (module.exports = {
|
|
831
1024
|
ACNClient,
|
|
832
1025
|
ACNError,
|
|
833
1026
|
ACNRealtime,
|
|
1027
|
+
KNOWN_PAYMENT_TASK_STATUSES,
|
|
834
1028
|
subscribeToACN
|
|
835
1029
|
});
|
package/dist/index.mjs
CHANGED
|
@@ -42,8 +42,32 @@ var ACNClient = class {
|
|
|
42
42
|
signal: controller.signal
|
|
43
43
|
});
|
|
44
44
|
if (!response.ok) {
|
|
45
|
-
|
|
46
|
-
|
|
45
|
+
let body = {};
|
|
46
|
+
try {
|
|
47
|
+
const parsed = await response.json();
|
|
48
|
+
if (parsed && typeof parsed === "object") body = parsed;
|
|
49
|
+
} catch {
|
|
50
|
+
}
|
|
51
|
+
let message;
|
|
52
|
+
const rawDetail = body.detail;
|
|
53
|
+
if (typeof rawDetail === "string") {
|
|
54
|
+
message = rawDetail;
|
|
55
|
+
} else if (Array.isArray(rawDetail) && rawDetail.length > 0) {
|
|
56
|
+
message = rawDetail.slice(0, 5).map((item) => {
|
|
57
|
+
if (item && typeof item === "object") {
|
|
58
|
+
const i = item;
|
|
59
|
+
const loc = Array.isArray(i.loc) ? i.loc.slice(1).join(".") : "";
|
|
60
|
+
const msg = String(i.msg ?? i.type ?? item);
|
|
61
|
+
return loc ? `${loc}: ${msg}` : msg;
|
|
62
|
+
}
|
|
63
|
+
return String(item);
|
|
64
|
+
}).join("; ");
|
|
65
|
+
} else {
|
|
66
|
+
message = String(body.message ?? response.statusText ?? `HTTP ${response.status}`);
|
|
67
|
+
}
|
|
68
|
+
const errorCode = typeof body.error === "string" ? body.error : void 0;
|
|
69
|
+
const requestId = typeof body.request_id === "string" ? body.request_id : response.headers.get("X-Request-ID") ?? void 0;
|
|
70
|
+
throw new ACNError(response.status, message, { errorCode, requestId });
|
|
47
71
|
}
|
|
48
72
|
if (response.status === 204) {
|
|
49
73
|
return void 0;
|
|
@@ -146,11 +170,9 @@ var ACNClient = class {
|
|
|
146
170
|
async getSubnet(subnetId) {
|
|
147
171
|
return this.get(`/api/v1/subnets/${subnetId}`);
|
|
148
172
|
}
|
|
149
|
-
/** Delete a subnet */
|
|
150
|
-
async deleteSubnet(subnetId
|
|
151
|
-
return this.request("DELETE", `/api/v1/subnets/${subnetId}
|
|
152
|
-
params: { force }
|
|
153
|
-
});
|
|
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}`);
|
|
154
176
|
}
|
|
155
177
|
/** Get agents in a subnet */
|
|
156
178
|
async getSubnetAgents(subnetId) {
|
|
@@ -374,32 +396,82 @@ var ACNClient = class {
|
|
|
374
396
|
// ============================================
|
|
375
397
|
// Payment Discovery
|
|
376
398
|
// ============================================
|
|
377
|
-
/** Set agent's payment capability */
|
|
399
|
+
/** Set agent's payment capability (requires Agent API Key) */
|
|
378
400
|
async setPaymentCapability(agentId, capability) {
|
|
379
|
-
return this.post(`/api/v1/
|
|
401
|
+
return this.post(`/api/v1/payments/${agentId}/payment-capability`, capability);
|
|
380
402
|
}
|
|
381
|
-
/**
|
|
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
|
+
*/
|
|
382
412
|
async getPaymentCapability(agentId) {
|
|
383
|
-
|
|
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;
|
|
421
|
+
}
|
|
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);
|
|
384
425
|
}
|
|
385
|
-
/**
|
|
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. */
|
|
386
431
|
async discoverPaymentAgents(options) {
|
|
387
432
|
return this.get("/api/v1/payments/discover", {
|
|
388
433
|
method: options?.method,
|
|
389
|
-
network: options?.network
|
|
390
|
-
|
|
391
|
-
|
|
434
|
+
network: options?.network
|
|
435
|
+
});
|
|
436
|
+
}
|
|
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
|
|
392
459
|
});
|
|
393
460
|
}
|
|
394
|
-
/**
|
|
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
|
+
*/
|
|
395
467
|
async getPaymentTask(taskId) {
|
|
396
468
|
return this.get(`/api/v1/payments/tasks/${taskId}`);
|
|
397
469
|
}
|
|
398
|
-
/** Get
|
|
470
|
+
/** Get the payment tasks an agent is involved in (requires Agent API Key). */
|
|
399
471
|
async getAgentPaymentTasks(agentId, options) {
|
|
400
472
|
return this.get(`/api/v1/payments/tasks/agent/${agentId}`, options);
|
|
401
473
|
}
|
|
402
|
-
/** Get agent's payment statistics */
|
|
474
|
+
/** Get an agent's payment statistics (requires Agent API Key). */
|
|
403
475
|
async getPaymentStats(agentId) {
|
|
404
476
|
return this.get(`/api/v1/payments/stats/${agentId}`);
|
|
405
477
|
}
|
|
@@ -583,13 +655,116 @@ var ACNClient = class {
|
|
|
583
655
|
async getAuditStats(options) {
|
|
584
656
|
return this.get("/api/v1/audit/stats", options);
|
|
585
657
|
}
|
|
658
|
+
// ============================================
|
|
659
|
+
// Social Graph (Follow)
|
|
660
|
+
// ============================================
|
|
661
|
+
/**
|
|
662
|
+
* Follow another agent.
|
|
663
|
+
*
|
|
664
|
+
* Idempotent — re-following returns `changed: false`.
|
|
665
|
+
* @param agentId The follower (must match the authenticated agent).
|
|
666
|
+
* @param targetId The agent to follow.
|
|
667
|
+
*/
|
|
668
|
+
async follow(agentId, targetId) {
|
|
669
|
+
return this.post(`/api/v1/agents/${agentId}/follows/${targetId}`);
|
|
670
|
+
}
|
|
671
|
+
/**
|
|
672
|
+
* Unfollow an agent.
|
|
673
|
+
*
|
|
674
|
+
* Idempotent — unfollowing a non-followed agent returns `changed: false`.
|
|
675
|
+
* @param agentId The follower (must match the authenticated agent).
|
|
676
|
+
* @param targetId The agent to unfollow.
|
|
677
|
+
*/
|
|
678
|
+
async unfollow(agentId, targetId) {
|
|
679
|
+
return this.delete(`/api/v1/agents/${agentId}/follows/${targetId}`);
|
|
680
|
+
}
|
|
681
|
+
/**
|
|
682
|
+
* Check whether `agentId` is following `targetId` (public endpoint).
|
|
683
|
+
*/
|
|
684
|
+
async checkFollow(agentId, targetId) {
|
|
685
|
+
return this.get(`/api/v1/agents/${agentId}/follows/${targetId}`);
|
|
686
|
+
}
|
|
687
|
+
/**
|
|
688
|
+
* List agents that `agentId` follows (public endpoint).
|
|
689
|
+
*/
|
|
690
|
+
async listFollows(agentId, options) {
|
|
691
|
+
return this.get(`/api/v1/agents/${agentId}/follows`, options);
|
|
692
|
+
}
|
|
693
|
+
/**
|
|
694
|
+
* List agents that follow `agentId` (public endpoint).
|
|
695
|
+
*/
|
|
696
|
+
async listFollowers(agentId, options) {
|
|
697
|
+
return this.get(`/api/v1/agents/${agentId}/followers`, options);
|
|
698
|
+
}
|
|
699
|
+
// ============================================
|
|
700
|
+
// Communication Policy
|
|
701
|
+
// ============================================
|
|
702
|
+
/**
|
|
703
|
+
* Get the authenticated agent's current communication policy (owner only).
|
|
704
|
+
*/
|
|
705
|
+
async getPolicy(agentId) {
|
|
706
|
+
return this.get(`/api/v1/agents/${agentId}/policy`);
|
|
707
|
+
}
|
|
708
|
+
/**
|
|
709
|
+
* Update the agent's inbound communication policy (owner only).
|
|
710
|
+
*
|
|
711
|
+
* @param agentId Must match the authenticated agent.
|
|
712
|
+
* @param mode `open` | `closed` | `manifest` | `allowlist`
|
|
713
|
+
* @param rejectReason Optional message shown to rejected senders (closed mode).
|
|
714
|
+
*/
|
|
715
|
+
async updatePolicy(agentId, mode, rejectReason) {
|
|
716
|
+
const policy = { mode };
|
|
717
|
+
if (rejectReason !== void 0) policy.reject_reason = rejectReason;
|
|
718
|
+
return this.request("PATCH", `/api/v1/agents/${agentId}/policy`, {
|
|
719
|
+
body: { communication_policy: policy }
|
|
720
|
+
});
|
|
721
|
+
}
|
|
722
|
+
// ============================================
|
|
723
|
+
// Allowlist
|
|
724
|
+
// ============================================
|
|
725
|
+
/**
|
|
726
|
+
* Add an agent to the allowlist (owner only).
|
|
727
|
+
*
|
|
728
|
+
* Only effective when `communication_policy.mode = 'allowlist'`.
|
|
729
|
+
* Idempotent — re-adding returns `changed: false`.
|
|
730
|
+
*
|
|
731
|
+
* @param agentId Must match the authenticated agent.
|
|
732
|
+
* @param targetId Agent to trust.
|
|
733
|
+
* @param reason Optional free-form note (≤ 200 chars).
|
|
734
|
+
*/
|
|
735
|
+
async addToAllowlist(agentId, targetId, reason) {
|
|
736
|
+
return this.post(
|
|
737
|
+
`/api/v1/agents/${agentId}/allowlist/${targetId}`,
|
|
738
|
+
reason !== void 0 ? { reason } : void 0
|
|
739
|
+
);
|
|
740
|
+
}
|
|
741
|
+
/**
|
|
742
|
+
* Remove an agent from the allowlist (owner only).
|
|
743
|
+
*
|
|
744
|
+
* Idempotent — removing a non-member returns `changed: false`.
|
|
745
|
+
*/
|
|
746
|
+
async removeFromAllowlist(agentId, targetId) {
|
|
747
|
+
return this.delete(`/api/v1/agents/${agentId}/allowlist/${targetId}`);
|
|
748
|
+
}
|
|
749
|
+
/**
|
|
750
|
+
* List the authenticated agent's allowlist (owner only).
|
|
751
|
+
*/
|
|
752
|
+
async listAllowlist(agentId, options) {
|
|
753
|
+
return this.get(`/api/v1/agents/${agentId}/allowlist`, options);
|
|
754
|
+
}
|
|
586
755
|
};
|
|
587
756
|
var ACNError = class extends Error {
|
|
588
|
-
constructor(status, message) {
|
|
757
|
+
constructor(status, message, options) {
|
|
589
758
|
super(message);
|
|
590
759
|
this.status = status;
|
|
591
760
|
this.name = "ACNError";
|
|
761
|
+
this.errorCode = options?.errorCode;
|
|
762
|
+
this.requestId = options?.requestId;
|
|
592
763
|
}
|
|
764
|
+
/** ACN internal error code (present on sanitised 5xx responses) */
|
|
765
|
+
errorCode;
|
|
766
|
+
/** Request ID minted by ACN for 5xx responses (useful for support) */
|
|
767
|
+
requestId;
|
|
593
768
|
};
|
|
594
769
|
|
|
595
770
|
// src/realtime.ts
|
|
@@ -787,9 +962,27 @@ function subscribeToACN(baseUrl, channel, handler) {
|
|
|
787
962
|
realtime.disconnect();
|
|
788
963
|
};
|
|
789
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
|
+
];
|
|
790
982
|
export {
|
|
791
983
|
ACNClient,
|
|
792
984
|
ACNError,
|
|
793
985
|
ACNRealtime,
|
|
986
|
+
KNOWN_PAYMENT_TASK_STATUSES,
|
|
794
987
|
subscribeToACN
|
|
795
988
|
};
|