aamp-openclaw-plugin 0.1.14 → 0.1.15

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.
@@ -175,6 +175,28 @@ function restartGateway() {
175
175
  }
176
176
  }
177
177
 
178
+ async function fetchJson(url, init, stepLabel) {
179
+ let res
180
+ try {
181
+ res = await fetch(url, init)
182
+ } catch (error) {
183
+ const message = error instanceof Error ? error.message : String(error)
184
+ throw new Error(`${stepLabel} failed for ${url}: ${message}`)
185
+ }
186
+
187
+ if (!res.ok) {
188
+ const text = await res.text().catch(() => '')
189
+ throw new Error(`${stepLabel} failed (${res.status}) for ${url}: ${text || res.statusText}`)
190
+ }
191
+
192
+ try {
193
+ return await res.json()
194
+ } catch (error) {
195
+ const message = error instanceof Error ? error.message : String(error)
196
+ throw new Error(`${stepLabel} returned invalid JSON for ${url}: ${message}`)
197
+ }
198
+ }
199
+
178
200
  async function ensureMailboxIdentity({ aampHost, slug, credentialsFile }) {
179
201
  const resolvedCreds = expandHome(credentialsFile)
180
202
  if (existsSync(resolvedCreds)) {
@@ -182,33 +204,30 @@ async function ensureMailboxIdentity({ aampHost, slug, credentialsFile }) {
182
204
  }
183
205
 
184
206
  const base = normalizeBaseUrl(aampHost)
185
- const registerRes = await fetch(`${base}/api/nodes/self-register`, {
186
- method: 'POST',
187
- headers: { 'Content-Type': 'application/json' },
188
- body: JSON.stringify({
189
- slug,
190
- description: 'OpenClaw AAMP agent node',
191
- }),
192
- })
193
-
194
- if (!registerRes.ok) {
195
- const text = await registerRes.text().catch(() => '')
196
- throw new Error(`AAMP self-register failed (${registerRes.status}): ${text || registerRes.statusText}`)
197
- }
198
-
199
- const registerData = await registerRes.json()
207
+ const registerUrl = `${base}/api/nodes/self-register`
208
+ const registerData = await fetchJson(
209
+ registerUrl,
210
+ {
211
+ method: 'POST',
212
+ headers: { 'Content-Type': 'application/json' },
213
+ body: JSON.stringify({
214
+ slug,
215
+ description: 'OpenClaw AAMP agent node',
216
+ }),
217
+ },
218
+ 'AAMP self-register',
219
+ )
200
220
  const code = registerData?.registrationCode
201
221
  if (!code) {
202
222
  throw new Error('AAMP self-register succeeded but no registrationCode was returned')
203
223
  }
204
224
 
205
- const credRes = await fetch(`${base}/api/nodes/credentials?code=${encodeURIComponent(code)}`)
206
- if (!credRes.ok) {
207
- const text = await credRes.text().catch(() => '')
208
- throw new Error(`AAMP credential exchange failed (${credRes.status}): ${text || credRes.statusText}`)
209
- }
210
-
211
- const credData = await credRes.json()
225
+ const credUrl = `${base}/api/nodes/credentials?code=${encodeURIComponent(code)}`
226
+ const credData = await fetchJson(
227
+ credUrl,
228
+ undefined,
229
+ 'AAMP credential exchange',
230
+ )
212
231
  const identity = {
213
232
  email: credData?.email,
214
233
  jmapToken: credData?.jmap?.token,
package/package.json CHANGED
@@ -7,7 +7,7 @@
7
7
  "skills"
8
8
  ],
9
9
  "license": "MIT",
10
- "version": "0.1.14",
10
+ "version": "0.1.15",
11
11
  "description": "AAMP Agent Mail Protocol — OpenClaw plugin. Gives OpenClaw an AAMP mailbox identity and lets it receive, process and reply to AAMP tasks.",
12
12
  "type": "module",
13
13
  "main": "dist/index.js",