@hashgraphonline/standards-sdk 0.1.187 → 0.1.189

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 (196) hide show
  1. package/dist/browser/services/registry-broker/client/agent-network.d.ts +1118 -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 +176 -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 +1118 -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 +471 -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 +1118 -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 +1118 -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 +54 -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.es147.js +3 -3
  46. package/dist/es/standards-sdk.es148.js +1 -1
  47. package/dist/es/standards-sdk.es150.js +24 -15
  48. package/dist/es/standards-sdk.es150.js.map +1 -1
  49. package/dist/es/standards-sdk.es152.js +440 -248
  50. package/dist/es/standards-sdk.es152.js.map +1 -1
  51. package/dist/es/standards-sdk.es153.js +259 -4
  52. package/dist/es/standards-sdk.es153.js.map +1 -1
  53. package/dist/es/standards-sdk.es154.js +4 -81
  54. package/dist/es/standards-sdk.es154.js.map +1 -1
  55. package/dist/es/standards-sdk.es155.js +71 -77
  56. package/dist/es/standards-sdk.es155.js.map +1 -1
  57. package/dist/es/standards-sdk.es156.js +80 -53
  58. package/dist/es/standards-sdk.es156.js.map +1 -1
  59. package/dist/es/standards-sdk.es157.js +59 -2546
  60. package/dist/es/standards-sdk.es157.js.map +1 -1
  61. package/dist/es/standards-sdk.es158.js +2547 -159
  62. package/dist/es/standards-sdk.es158.js.map +1 -1
  63. package/dist/es/standards-sdk.es159.js +159 -7
  64. package/dist/es/standards-sdk.es159.js.map +1 -1
  65. package/dist/es/standards-sdk.es16.js +3 -2
  66. package/dist/es/standards-sdk.es16.js.map +1 -1
  67. package/dist/es/standards-sdk.es160.js +7 -86
  68. package/dist/es/standards-sdk.es160.js.map +1 -1
  69. package/dist/es/standards-sdk.es161.js +64 -43
  70. package/dist/es/standards-sdk.es161.js.map +1 -1
  71. package/dist/es/standards-sdk.es162.js +57 -186
  72. package/dist/es/standards-sdk.es162.js.map +1 -1
  73. package/dist/es/standards-sdk.es163.js +188 -20
  74. package/dist/es/standards-sdk.es163.js.map +1 -1
  75. package/dist/es/standards-sdk.es164.js +22 -54
  76. package/dist/es/standards-sdk.es164.js.map +1 -1
  77. package/dist/es/standards-sdk.es165.js +41 -78
  78. package/dist/es/standards-sdk.es165.js.map +1 -1
  79. package/dist/es/standards-sdk.es166.js +81 -35
  80. package/dist/es/standards-sdk.es166.js.map +1 -1
  81. package/dist/es/standards-sdk.es167.js +36 -191
  82. package/dist/es/standards-sdk.es167.js.map +1 -1
  83. package/dist/es/standards-sdk.es168.js +191 -43
  84. package/dist/es/standards-sdk.es168.js.map +1 -1
  85. package/dist/es/standards-sdk.es169.js +46 -39
  86. package/dist/es/standards-sdk.es169.js.map +1 -1
  87. package/dist/es/standards-sdk.es170.js +37 -44
  88. package/dist/es/standards-sdk.es170.js.map +1 -1
  89. package/dist/es/standards-sdk.es171.js +46 -39
  90. package/dist/es/standards-sdk.es171.js.map +1 -1
  91. package/dist/es/standards-sdk.es172.js +29 -102
  92. package/dist/es/standards-sdk.es172.js.map +1 -1
  93. package/dist/es/standards-sdk.es173.js +104 -36
  94. package/dist/es/standards-sdk.es173.js.map +1 -1
  95. package/dist/es/standards-sdk.es174.js +43 -33
  96. package/dist/es/standards-sdk.es174.js.map +1 -1
  97. package/dist/es/standards-sdk.es175.js +44 -72
  98. package/dist/es/standards-sdk.es175.js.map +1 -1
  99. package/dist/es/standards-sdk.es176.js +65 -61
  100. package/dist/es/standards-sdk.es176.js.map +1 -1
  101. package/dist/es/standards-sdk.es177.js +63 -39
  102. package/dist/es/standards-sdk.es177.js.map +1 -1
  103. package/dist/es/standards-sdk.es178.js +44 -36
  104. package/dist/es/standards-sdk.es178.js.map +1 -1
  105. package/dist/es/standards-sdk.es179.js +36 -30
  106. package/dist/es/standards-sdk.es179.js.map +1 -1
  107. package/dist/es/standards-sdk.es18.js +6 -5
  108. package/dist/es/standards-sdk.es18.js.map +1 -1
  109. package/dist/es/standards-sdk.es180.js +30 -34
  110. package/dist/es/standards-sdk.es180.js.map +1 -1
  111. package/dist/es/standards-sdk.es181.js +34 -48
  112. package/dist/es/standards-sdk.es181.js.map +1 -1
  113. package/dist/es/standards-sdk.es182.js +48 -138
  114. package/dist/es/standards-sdk.es182.js.map +1 -1
  115. package/dist/es/standards-sdk.es183.js +133 -37
  116. package/dist/es/standards-sdk.es183.js.map +1 -1
  117. package/dist/es/standards-sdk.es184.js +34 -12474
  118. package/dist/es/standards-sdk.es184.js.map +1 -1
  119. package/dist/es/standards-sdk.es185.js +12425 -615
  120. package/dist/es/standards-sdk.es185.js.map +1 -1
  121. package/dist/es/standards-sdk.es186.js +47 -102
  122. package/dist/es/standards-sdk.es186.js.map +1 -1
  123. package/dist/es/standards-sdk.es187.js +96 -58
  124. package/dist/es/standards-sdk.es187.js.map +1 -1
  125. package/dist/es/standards-sdk.es188.js +73 -48
  126. package/dist/es/standards-sdk.es188.js.map +1 -1
  127. package/dist/es/standards-sdk.es189.js +180 -61
  128. package/dist/es/standards-sdk.es189.js.map +1 -1
  129. package/dist/es/standards-sdk.es19.js +4 -3
  130. package/dist/es/standards-sdk.es19.js.map +1 -1
  131. package/dist/es/standards-sdk.es190.js +659 -187
  132. package/dist/es/standards-sdk.es190.js.map +1 -1
  133. package/dist/es/standards-sdk.es197.js +71 -15
  134. package/dist/es/standards-sdk.es197.js.map +1 -1
  135. package/dist/es/standards-sdk.es198.js +14 -136
  136. package/dist/es/standards-sdk.es198.js.map +1 -1
  137. package/dist/es/standards-sdk.es199.js +104 -482
  138. package/dist/es/standards-sdk.es199.js.map +1 -1
  139. package/dist/es/standards-sdk.es200.js +480 -222
  140. package/dist/es/standards-sdk.es200.js.map +1 -1
  141. package/dist/es/standards-sdk.es201.js +239 -176
  142. package/dist/es/standards-sdk.es201.js.map +1 -1
  143. package/dist/es/standards-sdk.es202.js +178 -101
  144. package/dist/es/standards-sdk.es202.js.map +1 -1
  145. package/dist/es/standards-sdk.es203.js +75 -108
  146. package/dist/es/standards-sdk.es203.js.map +1 -1
  147. package/dist/es/standards-sdk.es204.js +116 -148
  148. package/dist/es/standards-sdk.es204.js.map +1 -1
  149. package/dist/es/standards-sdk.es205.js +146 -646
  150. package/dist/es/standards-sdk.es205.js.map +1 -1
  151. package/dist/es/standards-sdk.es206.js +661 -162
  152. package/dist/es/standards-sdk.es206.js.map +1 -1
  153. package/dist/es/standards-sdk.es207.js +156 -206
  154. package/dist/es/standards-sdk.es207.js.map +1 -1
  155. package/dist/es/standards-sdk.es208.js +219 -223
  156. package/dist/es/standards-sdk.es208.js.map +1 -1
  157. package/dist/es/standards-sdk.es209.js +242 -0
  158. package/dist/es/standards-sdk.es209.js.map +1 -0
  159. package/dist/es/standards-sdk.es22.js +1 -1
  160. package/dist/es/standards-sdk.es27.js +6 -5
  161. package/dist/es/standards-sdk.es27.js.map +1 -1
  162. package/dist/es/standards-sdk.es30.js +1 -1
  163. package/dist/es/standards-sdk.es31.js +1 -1
  164. package/dist/es/standards-sdk.es35.js +4 -3
  165. package/dist/es/standards-sdk.es35.js.map +1 -1
  166. package/dist/es/standards-sdk.es36.js +3 -3
  167. package/dist/es/standards-sdk.es37.js +1 -1
  168. package/dist/es/standards-sdk.es4.js +1 -1
  169. package/dist/es/standards-sdk.es53.js +1 -1
  170. package/dist/es/standards-sdk.es56.js +1 -1
  171. package/dist/es/standards-sdk.es59.js +1 -1
  172. package/dist/es/standards-sdk.es60.js +1 -1
  173. package/dist/es/standards-sdk.es62.js +1 -1
  174. package/dist/es/standards-sdk.es63.js +2 -2
  175. package/dist/es/standards-sdk.es64.js +1 -1
  176. package/dist/es/standards-sdk.es65.js +1 -1
  177. package/dist/es/standards-sdk.es66.js +1 -1
  178. package/dist/es/standards-sdk.es67.js +4 -3
  179. package/dist/es/standards-sdk.es67.js.map +1 -1
  180. package/dist/es/standards-sdk.es69.js +1 -1
  181. package/dist/es/standards-sdk.es7.js +1 -1
  182. package/dist/es/standards-sdk.es71.js +1 -1
  183. package/dist/es/standards-sdk.es72.js +2 -2
  184. package/dist/es/standards-sdk.es75.js +3 -3
  185. package/dist/es/standards-sdk.es76.js +1 -1
  186. package/dist/es/standards-sdk.es78.js +1 -1
  187. package/dist/es/standards-sdk.es83.js +1 -1
  188. package/dist/es/standards-sdk.es84.js +3 -2
  189. package/dist/es/standards-sdk.es84.js.map +1 -1
  190. package/dist/es/standards-sdk.es85.js +1 -1
  191. package/dist/es/standards-sdk.es88.js +1 -1
  192. package/dist/es/standards-sdk.es90.js +1 -1
  193. package/dist/es/standards-sdk.es94.js +3 -3
  194. package/dist/es/standards-sdk.es98.js +1 -1
  195. package/dist/es/standards-sdk.es99.js +1 -1
  196. package/package.json +1 -1
@@ -1,262 +1,454 @@
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
+ "grok",
6
+ "dot",
7
+ "muse",
8
+ "api",
9
+ "other"
10
+ ]);
11
+ const agentConnectionStateSchema = z.enum([
12
+ "unavailable",
13
+ "pending_pairing",
14
+ "interactive_verified",
15
+ "polling_verified",
16
+ "push_verified",
17
+ "needs_reconnect",
18
+ "paused",
19
+ "degraded"
20
+ ]);
21
+ const agentRegistrationStateSchema = z.enum([
22
+ "unregistered",
23
+ "quote_issued",
24
+ "pending",
25
+ "registered",
26
+ "failed"
27
+ ]);
28
+ const agentRegistrationResultStateSchema = z.enum([
29
+ "registered",
30
+ "pending",
31
+ "linked",
32
+ "unregistered"
33
+ ]);
34
+ const agentReceiveModeSchema = z.enum(["none", "poll", "push"]);
35
+ const agentRequestStateSchema = z.enum([
36
+ "accepted",
37
+ "awaiting_consent",
38
+ "queued",
39
+ "processing",
40
+ "completed",
41
+ "rejected",
42
+ "failed",
43
+ "expired",
44
+ "canceled"
45
+ ]);
46
+ const agentDeliveryStateSchema = z.enum([
47
+ "pending",
48
+ "notifying",
49
+ "provider_accepted",
50
+ "acknowledged",
51
+ "retry_scheduled",
52
+ "permanently_failed"
53
+ ]);
54
+ const agentMessageKindSchema = z.enum(["request", "response", "event"]);
55
+ const isoDate = z.string();
56
+ const agentRuntimeViewSchema = z.object({
57
+ runtimeId: z.string().uuid(),
58
+ uaid: z.string().nullable(),
59
+ ownerType: z.string(),
60
+ ownerId: z.string(),
61
+ declaredProvider: agentNetworkProviderSchema,
62
+ connectionState: agentConnectionStateSchema,
63
+ registrationState: agentRegistrationStateSchema,
64
+ registrationAttemptId: z.string().nullable(),
65
+ receiveMode: agentReceiveModeSchema,
66
+ gatewayUrl: z.string().nullable(),
67
+ paused: z.boolean(),
68
+ allowedPeerUaids: z.array(z.string()).nullable(),
69
+ capabilities: z.array(z.string()),
70
+ lastActivityAt: isoDate.nullable(),
71
+ createdAt: isoDate
72
+ });
73
+ const agentRuntimeQuoteSchema = z.object({
74
+ quoteId: z.string(),
75
+ expiresAt: isoDate,
76
+ registrationFeeCredits: z.number().nullable(),
77
+ gatewayUrl: z.string()
78
+ });
79
+ const agentPairingStartSchema = z.object({
80
+ grantId: z.string().uuid(),
81
+ pairingCode: z.string(),
82
+ expiresAt: isoDate
83
+ });
84
+ const agentPairingCompleteSchema = z.object({
85
+ grantId: z.string().uuid(),
86
+ runtimeId: z.string().uuid(),
87
+ token: z.string(),
88
+ scopes: z.array(z.string())
89
+ });
90
+ const agentMessageViewSchema = z.object({
91
+ messageId: z.string().uuid(),
92
+ conversationId: z.string().uuid(),
93
+ schemaVersion: z.literal("hol-agent-message/1"),
94
+ kind: agentMessageKindSchema,
95
+ senderUaid: z.string(),
96
+ recipientUaid: z.string(),
97
+ inReplyTo: z.string().uuid().nullable(),
98
+ content: z.object({ type: z.literal("text"), text: z.string() }),
99
+ requestState: agentRequestStateSchema,
100
+ createdAt: isoDate,
101
+ expiresAt: isoDate,
102
+ traceId: z.string()
103
+ });
104
+ const agentMessageAcceptedSchema = z.object({
105
+ messageId: z.string().uuid(),
106
+ conversationId: z.string().uuid(),
107
+ requestState: agentRequestStateSchema,
108
+ createdAt: isoDate,
109
+ expiresAt: isoDate,
110
+ deduplicated: z.boolean()
111
+ });
112
+ const agentLeaseViewSchema = z.object({
113
+ leaseId: z.string().uuid(),
114
+ messageId: z.string().uuid(),
115
+ fencingToken: z.number().int(),
116
+ expiresAt: isoDate
117
+ });
118
+ const agentClaimedMessageSchema = z.object({
119
+ message: agentMessageViewSchema,
120
+ lease: agentLeaseViewSchema
121
+ });
122
+ const agentInboxItemSchema = z.object({
123
+ messageId: z.string().uuid(),
124
+ conversationId: z.string().uuid(),
125
+ kind: agentMessageKindSchema,
126
+ senderUaid: z.string(),
127
+ content: z.object({ type: z.literal("text"), text: z.string() }),
128
+ requestState: agentRequestStateSchema,
129
+ deliveryState: agentDeliveryStateSchema,
130
+ acknowledged: z.boolean(),
131
+ leaseId: z.string().uuid().nullable(),
132
+ fencingToken: z.number().int().nullable(),
133
+ createdAt: isoDate,
134
+ expiresAt: isoDate
135
+ });
136
+ const agentInboxListSchema = z.object({
137
+ items: z.array(agentInboxItemSchema),
138
+ nextCursor: z.string().nullable()
139
+ });
140
+ const agentConversationViewSchema = z.object({
141
+ conversationId: z.string().uuid(),
142
+ state: z.enum(["active", "canceled", "expired"]),
143
+ participants: z.array(z.object({ uaid: z.string() })),
144
+ messages: z.array(agentMessageViewSchema),
145
+ nextCursor: z.string().nullable()
146
+ });
147
+ const agentReplyResultSchema = z.object({
148
+ request: agentMessageViewSchema,
149
+ response: agentMessageViewSchema
150
+ });
151
+ const agentRuntimeRegistrationResultSchema = z.object({
152
+ runtime: agentRuntimeViewSchema,
153
+ registration: agentRegistrationResultStateSchema
154
+ });
155
+ const agentProbeResultSchema = z.object({
156
+ nonce: z.string(),
157
+ issuedAt: isoDate
158
+ });
159
+ const agentSubscriptionEventTypeSchema = z.enum([
160
+ "notify_request",
161
+ "notify_event",
162
+ "notify_response"
163
+ ]);
164
+ const agentSubscriptionViewSchema = z.object({
165
+ subscriptionId: z.string().uuid(),
166
+ runtimeId: z.string().uuid(),
167
+ eventType: agentSubscriptionEventTypeSchema,
168
+ callbackUrl: z.string().nullable(),
169
+ state: z.string(),
170
+ expiresAt: isoDate.nullable(),
171
+ createdAt: isoDate
172
+ });
173
+ const agentSubscriptionListSchema = z.object({
174
+ subscriptions: z.array(agentSubscriptionViewSchema)
175
+ });
176
+ const agentSubscriptionCreatedSchema = z.object({
177
+ subscription: agentSubscriptionViewSchema
178
+ });
179
+ const sleep = (ms, signal) => new Promise((resolve, reject) => {
180
+ const t = setTimeout(resolve, ms);
181
+ signal?.addEventListener(
182
+ "abort",
183
+ () => {
184
+ clearTimeout(t);
185
+ reject(new Error("waitForReply aborted"));
186
+ },
187
+ { once: true }
15
188
  );
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");
44
- }
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");
189
+ });
190
+ const bearerHeaders = (token) => ({
191
+ authorization: `Bearer ${token}`
192
+ });
193
+ const encodePath = (value) => encodeURIComponent(value);
194
+ const qs = (params) => {
195
+ const query = new URLSearchParams();
196
+ for (const [k, v] of Object.entries(params)) {
197
+ if (v !== void 0) {
198
+ query.set(k, String(v));
61
199
  }
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
- }
73
- });
74
200
  }
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"
201
+ const s = query.toString();
202
+ return s ? `?${s}` : "";
203
+ };
204
+ function createAgentNetworkApi(client) {
205
+ const json = async (path, schema, init) => {
206
+ const raw = await client.requestJson(`${path}`, {
207
+ method: init.method ?? "GET",
208
+ body: init.body,
209
+ headers: init.token ? bearerHeaders(init.token) : void 0
210
+ });
211
+ const parsed = schema.safeParse(raw);
212
+ if (!parsed.success) {
213
+ throw new RegistryBrokerParseError(
214
+ "Unexpected agent-network response shape",
215
+ JSON.stringify(raw).slice(0, 500)
216
+ );
85
217
  }
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;
218
+ return parsed.data;
219
+ };
220
+ const bot204 = async (path, token, body) => {
221
+ const response = await client.request(`${path}`, {
222
+ method: "POST",
223
+ body,
224
+ headers: bearerHeaders(token)
225
+ });
226
+ return response.status === 204 ? null : response.json();
227
+ };
228
+ return {
229
+ quoteRuntime: () => json("/agent-runtimes/quote", agentRuntimeQuoteSchema, {
230
+ method: "POST"
231
+ }),
232
+ registerRuntime: (input) => json("/agent-runtimes/register", agentRuntimeRegistrationResultSchema, {
233
+ method: "POST",
234
+ body: input
235
+ }),
236
+ listRuntimes: async () => {
237
+ const raw = await client.requestJson("/agent-runtimes", {});
238
+ const parsed = z.object({ runtimes: z.array(agentRuntimeViewSchema) }).safeParse(raw);
239
+ if (!parsed.success) {
240
+ throw new RegistryBrokerParseError(
241
+ "Unexpected runtime list shape",
242
+ JSON.stringify(raw).slice(0, 500)
243
+ );
109
244
  }
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;
245
+ return parsed.data.runtimes;
246
+ },
247
+ updateRuntimePolicy: (runtimeId, input) => json(
248
+ `/agent-runtimes/${encodePath(runtimeId)}`,
249
+ agentRuntimeViewSchema,
250
+ { method: "PATCH", body: input }
251
+ ),
252
+ probeRuntime: async (runtimeId) => await json(
253
+ `/agent-runtimes/${encodePath(runtimeId)}/probe`,
254
+ agentProbeResultSchema,
255
+ { method: "POST" }
256
+ ),
257
+ startAgentConnection: (runtimeId) => json("/agent-connections", agentPairingStartSchema, {
258
+ method: "POST",
259
+ body: { runtimeId }
260
+ }),
261
+ completeAgentPairing: (pairingCode) => json("/agent-connections/pair", agentPairingCompleteSchema, {
262
+ method: "POST",
263
+ body: { pairingCode }
264
+ }),
265
+ revokeAgentConnection: async (grantId) => {
266
+ await client.request(`/agent-connections/${encodePath(grantId)}`, {
267
+ method: "DELETE"
268
+ });
269
+ },
270
+ listRuntimeInbox: (runtimeId, query) => json(
271
+ `/agent-runtimes/${encodePath(runtimeId)}/inbox${qs({
272
+ cursor: query?.cursor,
273
+ limit: query?.limit,
274
+ includeAcknowledged: query?.includeAcknowledged
275
+ })}`,
276
+ agentInboxListSchema,
277
+ {}
278
+ ),
279
+ getRuntimeConversation: (runtimeId, conversationId, query) => json(
280
+ `/agent-runtimes/${encodePath(runtimeId)}/conversations/${encodePath(
281
+ conversationId
282
+ )}${qs({ cursor: query?.cursor, limit: query?.limit })}`,
283
+ agentConversationViewSchema,
284
+ {}
285
+ ),
286
+ createAgentSubscription: async (runtimeId, input) => (await json(
287
+ `/agent-runtimes/${encodePath(runtimeId)}/subscriptions`,
288
+ agentSubscriptionCreatedSchema,
289
+ { method: "POST", body: input }
290
+ )).subscription,
291
+ listAgentSubscriptions: async (runtimeId) => (await json(
292
+ `/agent-runtimes/${encodePath(runtimeId)}/subscriptions`,
293
+ agentSubscriptionListSchema,
294
+ {}
295
+ )).subscriptions,
296
+ revokeAgentSubscription: async (runtimeId, subscriptionId) => {
297
+ await client.request(
298
+ `/agent-runtimes/${encodePath(runtimeId)}/subscriptions/${encodePath(
299
+ subscriptionId
300
+ )}`,
301
+ { method: "DELETE" }
302
+ );
303
+ },
304
+ agentMe: async (token) => {
305
+ const raw = await client.requestJson(
306
+ "/agent-runtimes/me",
307
+ { headers: bearerHeaders(token) }
308
+ );
309
+ const parsed = z.object({ runtime: agentRuntimeViewSchema }).safeParse(raw);
310
+ if (!parsed.success) {
311
+ throw new RegistryBrokerParseError(
312
+ "Unexpected agent-runtimes/me shape",
313
+ JSON.stringify(raw).slice(0, 500)
314
+ );
315
+ }
316
+ return parsed.data.runtime;
317
+ },
318
+ sendAgentMessage: (token, input) => json("/agent-messages", agentMessageAcceptedSchema, {
319
+ method: "POST",
320
+ body: input,
321
+ token
322
+ }),
323
+ getAgentMessage: (token, messageId) => json(
324
+ `/agent-messages/${encodePath(messageId)}`,
325
+ agentMessageViewSchema,
326
+ { token }
327
+ ),
328
+ getAgentConversation: (token, conversationId, query) => json(
329
+ `/agent-conversations/${encodePath(conversationId)}${qs({
330
+ cursor: query?.cursor,
331
+ limit: query?.limit
332
+ })}`,
333
+ agentConversationViewSchema,
334
+ { token }
335
+ ),
336
+ listAgentInbox: (token, query) => json(
337
+ `/agent-inbox${qs({
338
+ cursor: query?.cursor,
339
+ limit: query?.limit,
340
+ includeAcknowledged: query?.includeAcknowledged
341
+ })}`,
342
+ agentInboxListSchema,
343
+ { token }
344
+ ),
345
+ claimAgentMessage: async (token) => {
346
+ const raw = await bot204("/agent-inbox/leases", token, {});
347
+ if (raw === null) {
348
+ return null;
186
349
  }
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
- }
350
+ const parsed = agentClaimedMessageSchema.safeParse(raw);
351
+ if (!parsed.success) {
352
+ throw new RegistryBrokerParseError(
353
+ "Unexpected claim response shape",
354
+ JSON.stringify(raw).slice(0, 500)
355
+ );
356
+ }
357
+ return parsed.data;
358
+ },
359
+ acknowledgeAgentMessage: (token, messageId, lease) => json(
360
+ `/agent-inbox/${encodePath(messageId)}/ack`,
361
+ agentMessageViewSchema,
362
+ { method: "POST", body: lease, token }
363
+ ),
364
+ renewAgentMessageLease: (token, messageId, input) => json(
365
+ `/agent-inbox/${encodePath(messageId)}/lease/renew`,
366
+ agentLeaseViewSchema,
367
+ { method: "POST", body: input, token }
368
+ ),
369
+ replyToAgentMessage: (token, messageId, input) => json(
370
+ `/agent-messages/${encodePath(messageId)}/reply`,
371
+ agentReplyResultSchema,
372
+ { method: "POST", body: input, token }
373
+ ),
374
+ rejectAgentMessage: (token, messageId, input) => json(
375
+ `/agent-messages/${encodePath(messageId)}/reject`,
376
+ agentMessageViewSchema,
377
+ { method: "POST", body: input, token }
378
+ ),
379
+ cancelAgentConversation: async (token, conversationId) => {
380
+ const raw = await client.requestJson(
381
+ `/agent-conversations/${encodePath(conversationId)}/cancel`,
382
+ { method: "POST", body: {}, headers: bearerHeaders(token) }
383
+ );
384
+ const parsed = z.object({
385
+ conversationId: z.string().uuid(),
386
+ canceledMessages: z.number()
387
+ }).safeParse(raw);
388
+ if (!parsed.success) {
389
+ throw new RegistryBrokerParseError(
390
+ "Unexpected cancel response shape",
391
+ JSON.stringify(raw).slice(0, 500)
392
+ );
393
+ }
394
+ return parsed.data;
395
+ },
396
+ waitForAgentReply: async (token, messageId, options) => {
397
+ const timeoutMs = options?.timeoutMs ?? 6e4;
398
+ const interval = Math.max(250, options?.pollIntervalMs ?? 2e3);
399
+ const deadline = Date.now() + timeoutMs;
400
+ while (Date.now() < deadline) {
401
+ const message = await json(
402
+ `/agent-messages/${encodePath(messageId)}`,
403
+ agentMessageViewSchema,
404
+ { token }
405
+ );
406
+ if (message.requestState === "completed") {
407
+ const conversation = await json(
408
+ `/agent-conversations/${encodePath(message.conversationId)}`,
409
+ agentConversationViewSchema,
410
+ { token }
196
411
  );
412
+ return conversation.messages.find(
413
+ (m) => m.inReplyTo === messageId && m.kind === "response"
414
+ ) ?? null;
415
+ }
416
+ if (message.requestState === "rejected" || message.requestState === "failed" || message.requestState === "expired" || message.requestState === "canceled") {
417
+ return null;
197
418
  }
198
- return progress;
419
+ await sleep(Math.min(interval, deadline - Date.now()), options?.signal);
199
420
  }
421
+ return null;
200
422
  }
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
- );
423
+ };
249
424
  }
250
425
  export {
251
- closeUaidConnection,
252
- dashboardStats,
253
- getRegistrationProgress,
254
- getRegistrationQuote,
255
- getUaidConnectionStatus,
256
- registerAgent,
257
- resolveUaid,
258
- updateAgent,
259
- validateUaid,
260
- waitForRegistrationCompletion
426
+ agentClaimedMessageSchema,
427
+ agentConnectionStateSchema,
428
+ agentConversationViewSchema,
429
+ agentDeliveryStateSchema,
430
+ agentInboxItemSchema,
431
+ agentInboxListSchema,
432
+ agentLeaseViewSchema,
433
+ agentMessageAcceptedSchema,
434
+ agentMessageKindSchema,
435
+ agentMessageViewSchema,
436
+ agentNetworkProviderSchema,
437
+ agentPairingCompleteSchema,
438
+ agentPairingStartSchema,
439
+ agentProbeResultSchema,
440
+ agentReceiveModeSchema,
441
+ agentRegistrationResultStateSchema,
442
+ agentRegistrationStateSchema,
443
+ agentReplyResultSchema,
444
+ agentRequestStateSchema,
445
+ agentRuntimeQuoteSchema,
446
+ agentRuntimeRegistrationResultSchema,
447
+ agentRuntimeViewSchema,
448
+ agentSubscriptionCreatedSchema,
449
+ agentSubscriptionEventTypeSchema,
450
+ agentSubscriptionListSchema,
451
+ agentSubscriptionViewSchema,
452
+ createAgentNetworkApi
261
453
  };
262
454
  //# sourceMappingURL=standards-sdk.es152.js.map