@hashgraphonline/standards-sdk 0.1.187 → 0.1.188

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.
Files changed (212) hide show
  1. package/dist/browser/services/registry-broker/client/agent-network.d.ts +974 -0
  2. package/dist/browser/services/registry-broker/client/agent-network.d.ts.map +1 -0
  3. package/dist/browser/services/registry-broker/client/base-client.d.ts +4 -0
  4. package/dist/browser/services/registry-broker/client/base-client.d.ts.map +1 -1
  5. package/dist/browser/services/registry-broker/client.d.ts +1 -0
  6. package/dist/browser/services/registry-broker/client.d.ts.map +1 -1
  7. package/dist/browser/standards-sdk.browser.js +149 -0
  8. package/dist/browser/standards-sdk.browser.js.map +1 -1
  9. package/dist/browser-root/services/registry-broker/client/agent-network.d.ts +974 -0
  10. package/dist/browser-root/services/registry-broker/client/agent-network.d.ts.map +1 -0
  11. package/dist/browser-root/services/registry-broker/client/base-client.d.ts +4 -0
  12. package/dist/browser-root/services/registry-broker/client/base-client.d.ts.map +1 -1
  13. package/dist/browser-root/services/registry-broker/client.d.ts +1 -0
  14. package/dist/browser-root/services/registry-broker/client.d.ts.map +1 -1
  15. package/dist/browser-root/standards-sdk.root-browser.js +404 -15
  16. package/dist/browser-root/standards-sdk.root-browser.js.map +1 -1
  17. package/dist/cjs/services/registry-broker/client/agent-network.d.ts +974 -0
  18. package/dist/cjs/services/registry-broker/client/agent-network.d.ts.map +1 -0
  19. package/dist/cjs/services/registry-broker/client/base-client.d.ts +4 -0
  20. package/dist/cjs/services/registry-broker/client/base-client.d.ts.map +1 -1
  21. package/dist/cjs/services/registry-broker/client.d.ts +1 -0
  22. package/dist/cjs/services/registry-broker/client.d.ts.map +1 -1
  23. package/dist/cjs/standards-sdk.cjs +2 -2
  24. package/dist/cjs/standards-sdk.cjs.map +1 -1
  25. package/dist/es/services/registry-broker/client/agent-network.d.ts +974 -0
  26. package/dist/es/services/registry-broker/client/agent-network.d.ts.map +1 -0
  27. package/dist/es/services/registry-broker/client/base-client.d.ts +4 -0
  28. package/dist/es/services/registry-broker/client/base-client.d.ts.map +1 -1
  29. package/dist/es/services/registry-broker/client.d.ts +1 -0
  30. package/dist/es/services/registry-broker/client.d.ts.map +1 -1
  31. package/dist/es/standards-sdk.es.js +50 -27
  32. package/dist/es/standards-sdk.es.js.map +1 -1
  33. package/dist/es/standards-sdk.es104.js +1 -1
  34. package/dist/es/standards-sdk.es106.js +1 -1
  35. package/dist/es/standards-sdk.es108.js +1 -1
  36. package/dist/es/standards-sdk.es11.js +1 -1
  37. package/dist/es/standards-sdk.es110.js +1 -1
  38. package/dist/es/standards-sdk.es116.js +2 -2
  39. package/dist/es/standards-sdk.es12.js +1 -1
  40. package/dist/es/standards-sdk.es120.js +4 -4
  41. package/dist/es/standards-sdk.es121.js +11 -11
  42. package/dist/es/standards-sdk.es126.js +1 -1
  43. package/dist/es/standards-sdk.es132.js +3 -2
  44. package/dist/es/standards-sdk.es132.js.map +1 -1
  45. package/dist/es/standards-sdk.es133.js +5 -5
  46. package/dist/es/standards-sdk.es143.js +1 -1
  47. package/dist/es/standards-sdk.es144.js +1 -1
  48. package/dist/es/standards-sdk.es145.js +5 -5
  49. package/dist/es/standards-sdk.es147.js +3 -3
  50. package/dist/es/standards-sdk.es148.js +1 -1
  51. package/dist/es/standards-sdk.es150.js +24 -15
  52. package/dist/es/standards-sdk.es150.js.map +1 -1
  53. package/dist/es/standards-sdk.es152.js +372 -248
  54. package/dist/es/standards-sdk.es152.js.map +1 -1
  55. package/dist/es/standards-sdk.es153.js +259 -4
  56. package/dist/es/standards-sdk.es153.js.map +1 -1
  57. package/dist/es/standards-sdk.es154.js +4 -81
  58. package/dist/es/standards-sdk.es154.js.map +1 -1
  59. package/dist/es/standards-sdk.es155.js +71 -77
  60. package/dist/es/standards-sdk.es155.js.map +1 -1
  61. package/dist/es/standards-sdk.es156.js +80 -53
  62. package/dist/es/standards-sdk.es156.js.map +1 -1
  63. package/dist/es/standards-sdk.es157.js +59 -2546
  64. package/dist/es/standards-sdk.es157.js.map +1 -1
  65. package/dist/es/standards-sdk.es158.js +2547 -159
  66. package/dist/es/standards-sdk.es158.js.map +1 -1
  67. package/dist/es/standards-sdk.es159.js +159 -7
  68. package/dist/es/standards-sdk.es159.js.map +1 -1
  69. package/dist/es/standards-sdk.es16.js +3 -2
  70. package/dist/es/standards-sdk.es16.js.map +1 -1
  71. package/dist/es/standards-sdk.es160.js +7 -86
  72. package/dist/es/standards-sdk.es160.js.map +1 -1
  73. package/dist/es/standards-sdk.es161.js +64 -43
  74. package/dist/es/standards-sdk.es161.js.map +1 -1
  75. package/dist/es/standards-sdk.es162.js +57 -186
  76. package/dist/es/standards-sdk.es162.js.map +1 -1
  77. package/dist/es/standards-sdk.es163.js +188 -20
  78. package/dist/es/standards-sdk.es163.js.map +1 -1
  79. package/dist/es/standards-sdk.es164.js +22 -54
  80. package/dist/es/standards-sdk.es164.js.map +1 -1
  81. package/dist/es/standards-sdk.es165.js +41 -78
  82. package/dist/es/standards-sdk.es165.js.map +1 -1
  83. package/dist/es/standards-sdk.es166.js +81 -35
  84. package/dist/es/standards-sdk.es166.js.map +1 -1
  85. package/dist/es/standards-sdk.es167.js +36 -191
  86. package/dist/es/standards-sdk.es167.js.map +1 -1
  87. package/dist/es/standards-sdk.es168.js +191 -43
  88. package/dist/es/standards-sdk.es168.js.map +1 -1
  89. package/dist/es/standards-sdk.es169.js +46 -39
  90. package/dist/es/standards-sdk.es169.js.map +1 -1
  91. package/dist/es/standards-sdk.es170.js +37 -44
  92. package/dist/es/standards-sdk.es170.js.map +1 -1
  93. package/dist/es/standards-sdk.es171.js +46 -39
  94. package/dist/es/standards-sdk.es171.js.map +1 -1
  95. package/dist/es/standards-sdk.es172.js +29 -102
  96. package/dist/es/standards-sdk.es172.js.map +1 -1
  97. package/dist/es/standards-sdk.es173.js +104 -36
  98. package/dist/es/standards-sdk.es173.js.map +1 -1
  99. package/dist/es/standards-sdk.es174.js +43 -33
  100. package/dist/es/standards-sdk.es174.js.map +1 -1
  101. package/dist/es/standards-sdk.es175.js +44 -72
  102. package/dist/es/standards-sdk.es175.js.map +1 -1
  103. package/dist/es/standards-sdk.es176.js +65 -61
  104. package/dist/es/standards-sdk.es176.js.map +1 -1
  105. package/dist/es/standards-sdk.es177.js +63 -39
  106. package/dist/es/standards-sdk.es177.js.map +1 -1
  107. package/dist/es/standards-sdk.es178.js +44 -36
  108. package/dist/es/standards-sdk.es178.js.map +1 -1
  109. package/dist/es/standards-sdk.es179.js +36 -30
  110. package/dist/es/standards-sdk.es179.js.map +1 -1
  111. package/dist/es/standards-sdk.es18.js +6 -5
  112. package/dist/es/standards-sdk.es18.js.map +1 -1
  113. package/dist/es/standards-sdk.es180.js +30 -34
  114. package/dist/es/standards-sdk.es180.js.map +1 -1
  115. package/dist/es/standards-sdk.es181.js +34 -48
  116. package/dist/es/standards-sdk.es181.js.map +1 -1
  117. package/dist/es/standards-sdk.es182.js +48 -138
  118. package/dist/es/standards-sdk.es182.js.map +1 -1
  119. package/dist/es/standards-sdk.es183.js +133 -37
  120. package/dist/es/standards-sdk.es183.js.map +1 -1
  121. package/dist/es/standards-sdk.es184.js +34 -12474
  122. package/dist/es/standards-sdk.es184.js.map +1 -1
  123. package/dist/es/standards-sdk.es185.js +12425 -615
  124. package/dist/es/standards-sdk.es185.js.map +1 -1
  125. package/dist/es/standards-sdk.es186.js +47 -102
  126. package/dist/es/standards-sdk.es186.js.map +1 -1
  127. package/dist/es/standards-sdk.es187.js +96 -58
  128. package/dist/es/standards-sdk.es187.js.map +1 -1
  129. package/dist/es/standards-sdk.es188.js +73 -48
  130. package/dist/es/standards-sdk.es188.js.map +1 -1
  131. package/dist/es/standards-sdk.es189.js +180 -61
  132. package/dist/es/standards-sdk.es189.js.map +1 -1
  133. package/dist/es/standards-sdk.es19.js +4 -3
  134. package/dist/es/standards-sdk.es19.js.map +1 -1
  135. package/dist/es/standards-sdk.es190.js +14 -197
  136. package/dist/es/standards-sdk.es190.js.map +1 -1
  137. package/dist/es/standards-sdk.es191.js +658 -158
  138. package/dist/es/standards-sdk.es191.js.map +1 -1
  139. package/dist/es/standards-sdk.es192.js +139 -289
  140. package/dist/es/standards-sdk.es192.js.map +1 -1
  141. package/dist/es/standards-sdk.es193.js +274 -298
  142. package/dist/es/standards-sdk.es193.js.map +1 -1
  143. package/dist/es/standards-sdk.es194.js +262 -369
  144. package/dist/es/standards-sdk.es194.js.map +1 -1
  145. package/dist/es/standards-sdk.es195.js +316 -194
  146. package/dist/es/standards-sdk.es195.js.map +1 -1
  147. package/dist/es/standards-sdk.es196.js +319 -64
  148. package/dist/es/standards-sdk.es196.js.map +1 -1
  149. package/dist/es/standards-sdk.es197.js +74 -15
  150. package/dist/es/standards-sdk.es197.js.map +1 -1
  151. package/dist/es/standards-sdk.es198.js +60 -126
  152. package/dist/es/standards-sdk.es198.js.map +1 -1
  153. package/dist/es/standards-sdk.es199.js +104 -482
  154. package/dist/es/standards-sdk.es199.js.map +1 -1
  155. package/dist/es/standards-sdk.es200.js +480 -222
  156. package/dist/es/standards-sdk.es200.js.map +1 -1
  157. package/dist/es/standards-sdk.es201.js +239 -176
  158. package/dist/es/standards-sdk.es201.js.map +1 -1
  159. package/dist/es/standards-sdk.es202.js +178 -101
  160. package/dist/es/standards-sdk.es202.js.map +1 -1
  161. package/dist/es/standards-sdk.es203.js +75 -108
  162. package/dist/es/standards-sdk.es203.js.map +1 -1
  163. package/dist/es/standards-sdk.es204.js +116 -148
  164. package/dist/es/standards-sdk.es204.js.map +1 -1
  165. package/dist/es/standards-sdk.es205.js +146 -646
  166. package/dist/es/standards-sdk.es205.js.map +1 -1
  167. package/dist/es/standards-sdk.es206.js +661 -162
  168. package/dist/es/standards-sdk.es206.js.map +1 -1
  169. package/dist/es/standards-sdk.es207.js +156 -206
  170. package/dist/es/standards-sdk.es207.js.map +1 -1
  171. package/dist/es/standards-sdk.es208.js +219 -223
  172. package/dist/es/standards-sdk.es208.js.map +1 -1
  173. package/dist/es/standards-sdk.es209.js +242 -0
  174. package/dist/es/standards-sdk.es209.js.map +1 -0
  175. package/dist/es/standards-sdk.es22.js +1 -1
  176. package/dist/es/standards-sdk.es27.js +6 -5
  177. package/dist/es/standards-sdk.es27.js.map +1 -1
  178. package/dist/es/standards-sdk.es30.js +1 -1
  179. package/dist/es/standards-sdk.es31.js +1 -1
  180. package/dist/es/standards-sdk.es35.js +4 -3
  181. package/dist/es/standards-sdk.es35.js.map +1 -1
  182. package/dist/es/standards-sdk.es36.js +3 -3
  183. package/dist/es/standards-sdk.es37.js +1 -1
  184. package/dist/es/standards-sdk.es4.js +1 -1
  185. package/dist/es/standards-sdk.es53.js +1 -1
  186. package/dist/es/standards-sdk.es56.js +1 -1
  187. package/dist/es/standards-sdk.es59.js +1 -1
  188. package/dist/es/standards-sdk.es60.js +1 -1
  189. package/dist/es/standards-sdk.es62.js +1 -1
  190. package/dist/es/standards-sdk.es63.js +2 -2
  191. package/dist/es/standards-sdk.es64.js +1 -1
  192. package/dist/es/standards-sdk.es65.js +1 -1
  193. package/dist/es/standards-sdk.es66.js +1 -1
  194. package/dist/es/standards-sdk.es67.js +4 -3
  195. package/dist/es/standards-sdk.es67.js.map +1 -1
  196. package/dist/es/standards-sdk.es69.js +1 -1
  197. package/dist/es/standards-sdk.es7.js +1 -1
  198. package/dist/es/standards-sdk.es71.js +1 -1
  199. package/dist/es/standards-sdk.es72.js +2 -2
  200. package/dist/es/standards-sdk.es75.js +3 -3
  201. package/dist/es/standards-sdk.es76.js +1 -1
  202. package/dist/es/standards-sdk.es78.js +1 -1
  203. package/dist/es/standards-sdk.es83.js +1 -1
  204. package/dist/es/standards-sdk.es84.js +3 -2
  205. package/dist/es/standards-sdk.es84.js.map +1 -1
  206. package/dist/es/standards-sdk.es85.js +1 -1
  207. package/dist/es/standards-sdk.es88.js +1 -1
  208. package/dist/es/standards-sdk.es90.js +1 -1
  209. package/dist/es/standards-sdk.es94.js +3 -3
  210. package/dist/es/standards-sdk.es98.js +1 -1
  211. package/dist/es/standards-sdk.es99.js +1 -1
  212. package/package.json +1 -1
@@ -1,262 +1,386 @@
1
- import { dashboardStatsResponseSchema, registrationProgressResponseSchema, registrationQuoteResponseSchema, uaidConnectionStatusSchema, resolveResponseSchema, registerAgentResponseSchema, uaidValidationResponseSchema } from "./standards-sdk.es157.js";
2
- import { purchaseCreditsWithHbar } from "./standards-sdk.es204.js";
3
- import { serialiseAgentRegistrationRequest, DEFAULT_PROGRESS_INTERVAL_MS, DEFAULT_PROGRESS_TIMEOUT_MS, createAbortError, MINIMUM_REGISTRATION_AUTO_TOP_UP_CREDITS } from "./standards-sdk.es208.js";
4
- import { RegistryBrokerError } from "./standards-sdk.es151.js";
5
- async function performRegisterAgent(client, payload) {
6
- const raw = await client.requestJson("/register", {
7
- method: "POST",
8
- body: serialiseAgentRegistrationRequest(payload),
9
- headers: { "content-type": "application/json" }
10
- });
11
- return client.parseWithSchema(
12
- raw,
13
- registerAgentResponseSchema,
14
- "register agent response"
1
+ import { z } from "zod";
2
+ import { RegistryBrokerParseError } from "./standards-sdk.es151.js";
3
+ const agentNetworkProviderSchema = z.enum([
4
+ "openclaw",
5
+ "dot",
6
+ "grok",
7
+ "muse",
8
+ "generic"
9
+ ]);
10
+ const agentConnectionStateSchema = z.enum([
11
+ "unavailable",
12
+ "pending_pairing",
13
+ "interactive_verified",
14
+ "receive_unverified",
15
+ "receive_verified",
16
+ "paused",
17
+ "revoked",
18
+ "needs_reconnect"
19
+ ]);
20
+ const agentRegistrationStateSchema = z.enum([
21
+ "unregistered",
22
+ "pending",
23
+ "registered",
24
+ "linked",
25
+ "failed"
26
+ ]);
27
+ const agentReceiveModeSchema = z.enum(["none", "poll", "push", "events"]);
28
+ const agentRequestStateSchema = z.enum([
29
+ "accepted",
30
+ "awaiting_consent",
31
+ "queued",
32
+ "processing",
33
+ "completed",
34
+ "rejected",
35
+ "failed",
36
+ "expired",
37
+ "canceled"
38
+ ]);
39
+ const agentDeliveryStateSchema = z.enum([
40
+ "pending",
41
+ "notifying",
42
+ "provider_accepted",
43
+ "acknowledged",
44
+ "retry_scheduled",
45
+ "permanently_failed"
46
+ ]);
47
+ const agentMessageKindSchema = z.enum(["request", "response", "event"]);
48
+ const isoDate = z.string();
49
+ const agentRuntimeViewSchema = z.object({
50
+ runtimeId: z.string().uuid(),
51
+ uaid: z.string().nullable(),
52
+ ownerType: z.string(),
53
+ ownerId: z.string(),
54
+ declaredProvider: agentNetworkProviderSchema,
55
+ connectionState: agentConnectionStateSchema,
56
+ registrationState: agentRegistrationStateSchema,
57
+ registrationAttemptId: z.string().nullable(),
58
+ receiveMode: agentReceiveModeSchema,
59
+ gatewayUrl: z.string().nullable(),
60
+ paused: z.boolean(),
61
+ allowedPeerUaids: z.array(z.string()).nullable(),
62
+ capabilities: z.array(z.string()),
63
+ lastActivityAt: isoDate.nullable(),
64
+ createdAt: isoDate
65
+ });
66
+ const agentRuntimeQuoteSchema = z.object({
67
+ quoteId: z.string(),
68
+ expiresAt: isoDate,
69
+ registrationFeeCredits: z.number().nullable(),
70
+ gatewayUrl: z.string()
71
+ });
72
+ const agentPairingStartSchema = z.object({
73
+ grantId: z.string().uuid(),
74
+ pairingCode: z.string(),
75
+ expiresAt: isoDate
76
+ });
77
+ const agentPairingCompleteSchema = z.object({
78
+ grantId: z.string().uuid(),
79
+ runtimeId: z.string().uuid(),
80
+ token: z.string(),
81
+ scopes: z.array(z.string())
82
+ });
83
+ const agentMessageViewSchema = z.object({
84
+ messageId: z.string().uuid(),
85
+ conversationId: z.string().uuid(),
86
+ schemaVersion: z.number().optional(),
87
+ kind: agentMessageKindSchema,
88
+ senderUaid: z.string(),
89
+ recipientUaid: z.string(),
90
+ inReplyTo: z.string().uuid().nullable(),
91
+ content: z.object({ type: z.literal("text"), text: z.string() }),
92
+ requestState: agentRequestStateSchema,
93
+ createdAt: isoDate,
94
+ expiresAt: isoDate,
95
+ traceId: z.string()
96
+ });
97
+ const agentMessageAcceptedSchema = z.object({
98
+ messageId: z.string().uuid(),
99
+ conversationId: z.string().uuid(),
100
+ requestState: agentRequestStateSchema,
101
+ createdAt: isoDate,
102
+ expiresAt: isoDate,
103
+ deduplicated: z.boolean()
104
+ });
105
+ const agentLeaseViewSchema = z.object({
106
+ leaseId: z.string().uuid(),
107
+ messageId: z.string().uuid(),
108
+ fencingToken: z.number().int(),
109
+ expiresAt: isoDate
110
+ });
111
+ const agentClaimedMessageSchema = z.object({
112
+ message: agentMessageViewSchema,
113
+ lease: agentLeaseViewSchema
114
+ });
115
+ const agentInboxItemSchema = z.object({
116
+ messageId: z.string().uuid(),
117
+ conversationId: z.string().uuid(),
118
+ kind: agentMessageKindSchema,
119
+ senderUaid: z.string(),
120
+ content: z.object({ type: z.literal("text"), text: z.string() }),
121
+ requestState: agentRequestStateSchema,
122
+ deliveryState: agentDeliveryStateSchema,
123
+ acknowledged: z.boolean(),
124
+ leaseId: z.string().uuid().nullable(),
125
+ fencingToken: z.number().int().nullable(),
126
+ createdAt: isoDate,
127
+ expiresAt: isoDate
128
+ });
129
+ const agentInboxListSchema = z.object({
130
+ items: z.array(agentInboxItemSchema),
131
+ nextCursor: z.string().nullable()
132
+ });
133
+ const agentConversationViewSchema = z.object({
134
+ conversationId: z.string().uuid(),
135
+ state: z.enum(["active", "canceled", "expired"]),
136
+ participants: z.array(z.object({ uaid: z.string() })),
137
+ messages: z.array(agentMessageViewSchema),
138
+ nextCursor: z.string().nullable()
139
+ });
140
+ const agentReplyResultSchema = z.object({
141
+ request: agentMessageViewSchema,
142
+ response: agentMessageViewSchema
143
+ });
144
+ const agentRuntimeRegistrationResultSchema = z.object({
145
+ runtime: agentRuntimeViewSchema,
146
+ registration: agentRegistrationStateSchema
147
+ });
148
+ const agentProbeResultSchema = z.object({
149
+ nonce: z.string(),
150
+ issuedAt: isoDate
151
+ });
152
+ const sleep = (ms, signal) => new Promise((resolve, reject) => {
153
+ const t = setTimeout(resolve, ms);
154
+ signal?.addEventListener(
155
+ "abort",
156
+ () => {
157
+ clearTimeout(t);
158
+ reject(new Error("waitForReply aborted"));
159
+ },
160
+ { once: true }
15
161
  );
16
- }
17
- function calculateHbarAmount(creditsToPurchase, creditsPerHbar) {
18
- if (creditsPerHbar <= 0) {
19
- throw new Error("creditsPerHbar must be positive");
20
- }
21
- if (creditsToPurchase <= 0) {
22
- throw new Error("creditsToPurchase must be positive");
23
- }
24
- const rawHbar = creditsToPurchase / creditsPerHbar;
25
- const tinybars = Math.ceil(rawHbar * 1e8);
26
- return tinybars / 1e8;
27
- }
28
- function resolveCreditsToPurchase(shortfallCredits) {
29
- if (!Number.isFinite(shortfallCredits) || shortfallCredits <= 0) {
30
- return 0;
31
- }
32
- return Math.max(
33
- Math.ceil(shortfallCredits),
34
- MINIMUM_REGISTRATION_AUTO_TOP_UP_CREDITS
35
- );
36
- }
37
- async function ensureCreditsForRegistration(client, payload, autoTopUp) {
38
- const details = autoTopUp ?? null;
39
- if (!details) {
40
- return;
41
- }
42
- if (!details.accountId || !details.accountId.trim()) {
43
- throw new Error("autoTopUp.accountId is required");
162
+ });
163
+ const bearerHeaders = (token) => ({
164
+ authorization: `Bearer ${token}`
165
+ });
166
+ const encodePath = (value) => encodeURIComponent(value);
167
+ const qs = (params) => {
168
+ const query = new URLSearchParams();
169
+ for (const [k, v] of Object.entries(params)) {
170
+ if (v !== void 0) query.set(k, String(v));
44
171
  }
45
- if (!details.privateKey || !details.privateKey.trim()) {
46
- throw new Error("autoTopUp.privateKey is required");
47
- }
48
- for (let attempt = 0; attempt < 3; attempt += 1) {
49
- const quote = await getRegistrationQuote(client, payload);
50
- const shortfall = quote.shortfallCredits ?? 0;
51
- if (shortfall <= 0) {
52
- return;
53
- }
54
- const creditsToPurchase = resolveCreditsToPurchase(shortfall);
55
- if (creditsToPurchase <= 0) {
56
- return;
57
- }
58
- const creditsPerHbar = quote.creditsPerHbar ?? null;
59
- if (!creditsPerHbar || creditsPerHbar <= 0) {
60
- throw new Error("Unable to determine credits per HBAR for auto top-up");
61
- }
62
- const hbarAmount = calculateHbarAmount(creditsToPurchase, creditsPerHbar);
63
- await purchaseCreditsWithHbar(client, {
64
- accountId: details.accountId.trim(),
65
- privateKey: details.privateKey.trim(),
66
- hbarAmount,
67
- memo: details.memo ?? "Registry Broker auto top-up",
68
- metadata: {
69
- shortfallCredits: shortfall,
70
- requiredCredits: quote.requiredCredits,
71
- purchasedCredits: creditsToPurchase
72
- }
172
+ const s = query.toString();
173
+ return s ? `?${s}` : "";
174
+ };
175
+ function createAgentNetworkApi(client) {
176
+ const json = async (path, schema, init) => {
177
+ const raw = await client.requestJson(`${path}`, {
178
+ method: init.method ?? "GET",
179
+ body: init.body,
180
+ headers: init.token ? bearerHeaders(init.token) : void 0
73
181
  });
74
- }
75
- const finalQuote = await getRegistrationQuote(client, payload);
76
- if ((finalQuote.shortfallCredits ?? 0) > 0) {
77
- throw new Error("Unable to purchase sufficient credits for registration");
78
- }
79
- }
80
- async function resolveUaid(client, uaid) {
81
- const raw = await client.requestJson(
82
- `/resolve/${encodeURIComponent(uaid)}`,
83
- {
84
- method: "GET"
182
+ const parsed = schema.safeParse(raw);
183
+ if (!parsed.success) {
184
+ throw new RegistryBrokerParseError(
185
+ "Unexpected agent-network response shape",
186
+ JSON.stringify(raw).slice(0, 500)
187
+ );
85
188
  }
86
- );
87
- return client.parseWithSchema(
88
- raw,
89
- resolveResponseSchema,
90
- "resolve UAID response"
91
- );
92
- }
93
- async function registerAgent(client, payload, options) {
94
- const autoTopUp = options?.autoTopUp ?? client.registrationAutoTopUp;
95
- if (!autoTopUp) {
96
- return performRegisterAgent(client, payload);
97
- }
98
- await ensureCreditsForRegistration(client, payload, autoTopUp);
99
- let retried = false;
100
- while (true) {
101
- try {
102
- return await performRegisterAgent(client, payload);
103
- } catch (error) {
104
- const shortfall = client.extractInsufficientCreditsDetails(error);
105
- if (shortfall && !retried) {
106
- await ensureCreditsForRegistration(client, payload, autoTopUp);
107
- retried = true;
108
- continue;
189
+ return parsed.data;
190
+ };
191
+ const bot204 = async (path, token, body) => {
192
+ const response = await client.request(`${path}`, {
193
+ method: "POST",
194
+ body,
195
+ headers: bearerHeaders(token)
196
+ });
197
+ return response.status === 204 ? null : response.json();
198
+ };
199
+ return {
200
+ quoteRuntime: () => json("/agent-runtimes/quote", agentRuntimeQuoteSchema, {
201
+ method: "POST"
202
+ }),
203
+ registerRuntime: (input) => json("/agent-runtimes/register", agentRuntimeRegistrationResultSchema, {
204
+ method: "POST",
205
+ body: input
206
+ }),
207
+ listRuntimes: async () => {
208
+ const raw = await client.requestJson("/agent-runtimes", {});
209
+ const parsed = z.object({ runtimes: z.array(agentRuntimeViewSchema) }).safeParse(raw);
210
+ if (!parsed.success) {
211
+ throw new RegistryBrokerParseError(
212
+ "Unexpected runtime list shape",
213
+ JSON.stringify(raw).slice(0, 500)
214
+ );
109
215
  }
110
- throw error;
111
- }
112
- }
113
- }
114
- async function getRegistrationQuote(client, payload) {
115
- const raw = await client.requestJson("/register/quote", {
116
- method: "POST",
117
- body: serialiseAgentRegistrationRequest(payload),
118
- headers: { "content-type": "application/json" }
119
- });
120
- return client.parseWithSchema(
121
- raw,
122
- registrationQuoteResponseSchema,
123
- "registration quote response"
124
- );
125
- }
126
- async function updateAgent(client, uaid, payload) {
127
- const raw = await client.requestJson(
128
- `/register/${encodeURIComponent(uaid)}`,
129
- {
130
- method: "PUT",
131
- body: serialiseAgentRegistrationRequest(payload),
132
- headers: { "content-type": "application/json" }
133
- }
134
- );
135
- return client.parseWithSchema(
136
- raw,
137
- registerAgentResponseSchema,
138
- "update agent response"
139
- );
140
- }
141
- async function getRegistrationProgress(client, attemptId) {
142
- const normalisedAttemptId = attemptId.trim();
143
- if (!normalisedAttemptId) {
144
- throw new Error("attemptId is required");
145
- }
146
- try {
147
- const raw = await client.requestJson(
148
- `/register/progress/${encodeURIComponent(normalisedAttemptId)}`,
149
- { method: "GET" }
150
- );
151
- const parsed = client.parseWithSchema(
152
- raw,
153
- registrationProgressResponseSchema,
154
- "registration progress response"
155
- );
156
- return parsed.progress;
157
- } catch (error) {
158
- if (error instanceof RegistryBrokerError && error.status === 404) {
159
- return null;
160
- }
161
- throw error;
162
- }
163
- }
164
- async function waitForRegistrationCompletion(client, attemptId, options = {}) {
165
- const normalisedAttemptId = attemptId.trim();
166
- if (!normalisedAttemptId) {
167
- throw new Error("attemptId is required");
168
- }
169
- const interval = Math.max(
170
- 250,
171
- options.intervalMs ?? DEFAULT_PROGRESS_INTERVAL_MS
172
- );
173
- const timeoutMs = options.timeoutMs ?? DEFAULT_PROGRESS_TIMEOUT_MS;
174
- const throwOnFailure = options.throwOnFailure ?? true;
175
- const signal = options.signal;
176
- const startedAt = Date.now();
177
- while (true) {
178
- if (signal?.aborted) {
179
- throw createAbortError();
180
- }
181
- const progress = await client.getRegistrationProgress(normalisedAttemptId);
182
- if (progress) {
183
- options.onProgress?.(progress);
184
- if (progress.status === "completed") {
185
- return progress;
216
+ return parsed.data.runtimes;
217
+ },
218
+ updateRuntimePolicy: (runtimeId, input) => json(
219
+ `/agent-runtimes/${encodePath(runtimeId)}`,
220
+ agentRuntimeViewSchema,
221
+ { method: "PATCH", body: input }
222
+ ),
223
+ probeRuntime: async (runtimeId) => await json(
224
+ `/agent-runtimes/${encodePath(runtimeId)}/probe`,
225
+ agentProbeResultSchema,
226
+ { method: "POST" }
227
+ ),
228
+ startAgentConnection: (runtimeId) => json("/agent-connections", agentPairingStartSchema, {
229
+ method: "POST",
230
+ body: { runtimeId }
231
+ }),
232
+ completeAgentPairing: (pairingCode) => json("/agent-connections/pair", agentPairingCompleteSchema, {
233
+ method: "POST",
234
+ body: { pairingCode }
235
+ }),
236
+ revokeAgentConnection: async (grantId) => {
237
+ await client.request(`/agent-connections/${encodePath(grantId)}`, {
238
+ method: "DELETE"
239
+ });
240
+ },
241
+ agentMe: async (token) => {
242
+ const raw = await client.requestJson(
243
+ "/agent-runtimes/me",
244
+ { headers: bearerHeaders(token) }
245
+ );
246
+ const parsed = z.object({ runtime: agentRuntimeViewSchema }).safeParse(raw);
247
+ if (!parsed.success) {
248
+ throw new RegistryBrokerParseError(
249
+ "Unexpected agent-runtimes/me shape",
250
+ JSON.stringify(raw).slice(0, 500)
251
+ );
252
+ }
253
+ return parsed.data.runtime;
254
+ },
255
+ sendAgentMessage: (token, input) => json("/agent-messages", agentMessageAcceptedSchema, {
256
+ method: "POST",
257
+ body: input,
258
+ token
259
+ }),
260
+ getAgentMessage: (token, messageId) => json(
261
+ `/agent-messages/${encodePath(messageId)}`,
262
+ agentMessageViewSchema,
263
+ { token }
264
+ ),
265
+ getAgentConversation: (token, conversationId, query) => json(
266
+ `/agent-conversations/${encodePath(conversationId)}${qs({
267
+ cursor: query?.cursor,
268
+ limit: query?.limit
269
+ })}`,
270
+ agentConversationViewSchema,
271
+ { token }
272
+ ),
273
+ listAgentInbox: (token, query) => json(
274
+ `/agent-inbox${qs({
275
+ cursor: query?.cursor,
276
+ limit: query?.limit,
277
+ includeAcknowledged: query?.includeAcknowledged
278
+ })}`,
279
+ agentInboxListSchema,
280
+ { token }
281
+ ),
282
+ claimAgentMessage: async (token) => {
283
+ const raw = await bot204("/agent-inbox/leases", token, {});
284
+ if (raw === null) {
285
+ return null;
286
+ }
287
+ const parsed = agentClaimedMessageSchema.safeParse(raw);
288
+ if (!parsed.success) {
289
+ throw new RegistryBrokerParseError(
290
+ "Unexpected claim response shape",
291
+ JSON.stringify(raw).slice(0, 500)
292
+ );
186
293
  }
187
- if (progress.status === "partial" || progress.status === "failed") {
188
- if (throwOnFailure) {
189
- throw new RegistryBrokerError(
190
- "Registration did not complete successfully",
191
- {
192
- status: 409,
193
- statusText: progress.status,
194
- body: progress
195
- }
294
+ return parsed.data;
295
+ },
296
+ acknowledgeAgentMessage: (token, messageId, lease) => json(
297
+ `/agent-inbox/${encodePath(messageId)}/ack`,
298
+ agentMessageViewSchema,
299
+ { method: "POST", body: lease, token }
300
+ ),
301
+ renewAgentMessageLease: (token, messageId, input) => json(
302
+ `/agent-inbox/${encodePath(messageId)}/lease/renew`,
303
+ agentLeaseViewSchema,
304
+ { method: "POST", body: input, token }
305
+ ),
306
+ replyToAgentMessage: (token, messageId, input) => json(
307
+ `/agent-messages/${encodePath(messageId)}/reply`,
308
+ agentReplyResultSchema,
309
+ { method: "POST", body: input, token }
310
+ ),
311
+ rejectAgentMessage: (token, messageId, input) => json(
312
+ `/agent-messages/${encodePath(messageId)}/reject`,
313
+ agentMessageViewSchema,
314
+ { method: "POST", body: input, token }
315
+ ),
316
+ cancelAgentConversation: async (token, conversationId) => {
317
+ const raw = await client.requestJson(
318
+ `/agent-conversations/${encodePath(conversationId)}/cancel`,
319
+ { method: "POST", body: {}, headers: bearerHeaders(token) }
320
+ );
321
+ const parsed = z.object({
322
+ conversationId: z.string().uuid(),
323
+ canceledMessages: z.number()
324
+ }).safeParse(raw);
325
+ if (!parsed.success) {
326
+ throw new RegistryBrokerParseError(
327
+ "Unexpected cancel response shape",
328
+ JSON.stringify(raw).slice(0, 500)
329
+ );
330
+ }
331
+ return parsed.data;
332
+ },
333
+ waitForAgentReply: async (token, messageId, options) => {
334
+ const timeoutMs = options?.timeoutMs ?? 6e4;
335
+ const interval = Math.max(250, options?.pollIntervalMs ?? 2e3);
336
+ const deadline = Date.now() + timeoutMs;
337
+ while (Date.now() < deadline) {
338
+ const message = await json(
339
+ `/agent-messages/${encodePath(messageId)}`,
340
+ agentMessageViewSchema,
341
+ { token }
342
+ );
343
+ if (message.requestState === "completed") {
344
+ const conversation = await json(
345
+ `/agent-conversations/${encodePath(message.conversationId)}`,
346
+ agentConversationViewSchema,
347
+ { token }
196
348
  );
349
+ return conversation.messages.find(
350
+ (m) => m.inReplyTo === messageId && m.kind === "response"
351
+ ) ?? null;
352
+ }
353
+ if (message.requestState === "rejected" || message.requestState === "failed" || message.requestState === "expired" || message.requestState === "canceled") {
354
+ return null;
197
355
  }
198
- return progress;
356
+ await sleep(Math.min(interval, deadline - Date.now()), options?.signal);
199
357
  }
358
+ return null;
200
359
  }
201
- if (Date.now() - startedAt >= timeoutMs) {
202
- throw new Error(
203
- `Registration progress polling timed out after ${timeoutMs}ms`
204
- );
205
- }
206
- await client.delay(interval, signal);
207
- }
208
- }
209
- async function validateUaid(client, uaid) {
210
- const raw = await client.requestJson(
211
- `/uaids/validate/${encodeURIComponent(uaid)}`,
212
- {
213
- method: "GET"
214
- }
215
- );
216
- return client.parseWithSchema(
217
- raw,
218
- uaidValidationResponseSchema,
219
- "UAID validation response"
220
- );
221
- }
222
- async function getUaidConnectionStatus(client, uaid) {
223
- const raw = await client.requestJson(
224
- `/uaids/connections/${encodeURIComponent(uaid)}/status`,
225
- {
226
- method: "GET"
227
- }
228
- );
229
- return client.parseWithSchema(
230
- raw,
231
- uaidConnectionStatusSchema,
232
- "UAID connection status"
233
- );
234
- }
235
- async function closeUaidConnection(client, uaid) {
236
- await client.request(`/uaids/connections/${encodeURIComponent(uaid)}`, {
237
- method: "DELETE"
238
- });
239
- }
240
- async function dashboardStats(client) {
241
- const raw = await client.requestJson("/dashboard/stats", {
242
- method: "GET"
243
- });
244
- return client.parseWithSchema(
245
- raw,
246
- dashboardStatsResponseSchema,
247
- "dashboard stats response"
248
- );
360
+ };
249
361
  }
250
362
  export {
251
- closeUaidConnection,
252
- dashboardStats,
253
- getRegistrationProgress,
254
- getRegistrationQuote,
255
- getUaidConnectionStatus,
256
- registerAgent,
257
- resolveUaid,
258
- updateAgent,
259
- validateUaid,
260
- waitForRegistrationCompletion
363
+ agentClaimedMessageSchema,
364
+ agentConnectionStateSchema,
365
+ agentConversationViewSchema,
366
+ agentDeliveryStateSchema,
367
+ agentInboxItemSchema,
368
+ agentInboxListSchema,
369
+ agentLeaseViewSchema,
370
+ agentMessageAcceptedSchema,
371
+ agentMessageKindSchema,
372
+ agentMessageViewSchema,
373
+ agentNetworkProviderSchema,
374
+ agentPairingCompleteSchema,
375
+ agentPairingStartSchema,
376
+ agentProbeResultSchema,
377
+ agentReceiveModeSchema,
378
+ agentRegistrationStateSchema,
379
+ agentReplyResultSchema,
380
+ agentRequestStateSchema,
381
+ agentRuntimeQuoteSchema,
382
+ agentRuntimeRegistrationResultSchema,
383
+ agentRuntimeViewSchema,
384
+ createAgentNetworkApi
261
385
  };
262
386
  //# sourceMappingURL=standards-sdk.es152.js.map