aamp-openclaw-plugin 0.1.13 → 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.
@@ -3,7 +3,6 @@
3
3
  import { cpSync, existsSync, mkdirSync, readFileSync, rmSync, writeFileSync } from 'node:fs'
4
4
  import { homedir } from 'node:os'
5
5
  import { dirname, join } from 'node:path'
6
- import { createRequire } from 'node:module'
7
6
  import { createInterface } from 'node:readline/promises'
8
7
  import { stdin as input, stdout as output, stderr } from 'node:process'
9
8
  import { spawnSync } from 'node:child_process'
@@ -122,12 +121,6 @@ function copyIntoDir(src, dest) {
122
121
  cpSync(src, dest, { recursive: true, force: true })
123
122
  }
124
123
 
125
- function resolveInstalledPackageRoot(packageRoot, specifier) {
126
- const packageRequire = createRequire(join(packageRoot, 'package.json'))
127
- const resolvedEntry = packageRequire.resolve(specifier)
128
- return packageRootFromEntry(resolvedEntry)
129
- }
130
-
131
124
  function installPluginFiles(credentialsFile = DEFAULT_CREDENTIALS_FILE) {
132
125
  const extensionDir = resolveExtensionDir()
133
126
  const packageRoot = packageRootFromEntry(fileURLToPath(import.meta.url))
@@ -149,18 +142,6 @@ function installPluginFiles(credentialsFile = DEFAULT_CREDENTIALS_FILE) {
149
142
 
150
143
  writeJsonFile(join(extensionDir, 'package.json'), packageJson)
151
144
 
152
- const dependencyPackages = ['aamp-sdk', 'ws', 'nodemailer']
153
- const nodeModulesDir = join(extensionDir, 'node_modules')
154
- mkdirSync(nodeModulesDir, { recursive: true })
155
-
156
- for (const dep of dependencyPackages) {
157
- const depRoot = resolveInstalledPackageRoot(packageRoot, dep)
158
- if (!existsSync(depRoot)) {
159
- throw new Error(`Missing dependency directory: ${depRoot}`)
160
- }
161
- copyIntoDir(depRoot, join(nodeModulesDir, dep))
162
- }
163
-
164
145
  if (existingCredentials) {
165
146
  mkdirSync(dirname(credentialsPath), { recursive: true })
166
147
  writeFileSync(credentialsPath, existingCredentials)
@@ -194,6 +175,28 @@ function restartGateway() {
194
175
  }
195
176
  }
196
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
+
197
200
  async function ensureMailboxIdentity({ aampHost, slug, credentialsFile }) {
198
201
  const resolvedCreds = expandHome(credentialsFile)
199
202
  if (existsSync(resolvedCreds)) {
@@ -201,33 +204,30 @@ async function ensureMailboxIdentity({ aampHost, slug, credentialsFile }) {
201
204
  }
202
205
 
203
206
  const base = normalizeBaseUrl(aampHost)
204
- const registerRes = await fetch(`${base}/api/nodes/self-register`, {
205
- method: 'POST',
206
- headers: { 'Content-Type': 'application/json' },
207
- body: JSON.stringify({
208
- slug,
209
- description: 'OpenClaw AAMP agent node',
210
- }),
211
- })
212
-
213
- if (!registerRes.ok) {
214
- const text = await registerRes.text().catch(() => '')
215
- throw new Error(`AAMP self-register failed (${registerRes.status}): ${text || registerRes.statusText}`)
216
- }
217
-
218
- 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
+ )
219
220
  const code = registerData?.registrationCode
220
221
  if (!code) {
221
222
  throw new Error('AAMP self-register succeeded but no registrationCode was returned')
222
223
  }
223
224
 
224
- const credRes = await fetch(`${base}/api/nodes/credentials?code=${encodeURIComponent(code)}`)
225
- if (!credRes.ok) {
226
- const text = await credRes.text().catch(() => '')
227
- throw new Error(`AAMP credential exchange failed (${credRes.status}): ${text || credRes.statusText}`)
228
- }
229
-
230
- 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
+ )
231
231
  const identity = {
232
232
  email: credData?.email,
233
233
  jmapToken: credData?.jmap?.token,
@@ -0,0 +1,81 @@
1
+ var __create = Object.create;
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __getProtoOf = Object.getPrototypeOf;
6
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
7
+ var __require = /* @__PURE__ */ ((x) => typeof require !== "undefined" ? require : typeof Proxy !== "undefined" ? new Proxy(x, {
8
+ get: (a, b) => (typeof require !== "undefined" ? require : a)[b]
9
+ }) : x)(function(x) {
10
+ if (typeof require !== "undefined")
11
+ return require.apply(this, arguments);
12
+ throw Error('Dynamic require of "' + x + '" is not supported');
13
+ });
14
+ var __commonJS = (cb, mod) => function __require2() {
15
+ return mod || (0, cb[__getOwnPropNames(cb)[0]])((mod = { exports: {} }).exports, mod), mod.exports;
16
+ };
17
+ var __copyProps = (to, from, except, desc) => {
18
+ if (from && typeof from === "object" || typeof from === "function") {
19
+ for (let key of __getOwnPropNames(from))
20
+ if (!__hasOwnProp.call(to, key) && key !== except)
21
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
22
+ }
23
+ return to;
24
+ };
25
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
26
+ // If the importer is in node compatibility mode or this is not an ESM
27
+ // file that has been converted to a CommonJS file using a Babel-
28
+ // compatible transform (i.e. "__esModule" has not been set), then set
29
+ // "default" to the CommonJS "module.exports" for node compatibility.
30
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
31
+ mod
32
+ ));
33
+
34
+ // src/file-store.ts
35
+ import { existsSync, mkdirSync, readFileSync, writeFileSync } from "node:fs";
36
+ import { dirname, join } from "node:path";
37
+ import { homedir } from "node:os";
38
+ function defaultCredentialsPath() {
39
+ return join(homedir(), ".openclaw", "extensions", "aamp-openclaw-plugin", ".credentials.json");
40
+ }
41
+ function loadCachedIdentity(file) {
42
+ const resolved = file ?? defaultCredentialsPath();
43
+ if (!existsSync(resolved))
44
+ return null;
45
+ try {
46
+ const parsed = JSON.parse(readFileSync(resolved, "utf-8"));
47
+ if (!parsed.email || !parsed.jmapToken || !parsed.smtpPassword)
48
+ return null;
49
+ return parsed;
50
+ } catch {
51
+ return null;
52
+ }
53
+ }
54
+ function saveCachedIdentity(identity, file) {
55
+ const resolved = file ?? defaultCredentialsPath();
56
+ mkdirSync(dirname(resolved), { recursive: true });
57
+ writeFileSync(resolved, JSON.stringify(identity, null, 2), "utf-8");
58
+ }
59
+ function ensureDir(dir) {
60
+ mkdirSync(dir, { recursive: true });
61
+ }
62
+ function readBinaryFile(path) {
63
+ return readFileSync(path);
64
+ }
65
+ function writeBinaryFile(path, content) {
66
+ mkdirSync(dirname(path), { recursive: true });
67
+ writeFileSync(path, content);
68
+ }
69
+
70
+ export {
71
+ __require,
72
+ __commonJS,
73
+ __toESM,
74
+ defaultCredentialsPath,
75
+ loadCachedIdentity,
76
+ saveCachedIdentity,
77
+ ensureDir,
78
+ readBinaryFile,
79
+ writeBinaryFile
80
+ };
81
+ //# sourceMappingURL=chunk-W4C7IUCH.js.map
@@ -0,0 +1,7 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../src/file-store.ts"],
4
+ "sourcesContent": ["import { existsSync, mkdirSync, readFileSync, writeFileSync } from 'node:fs'\nimport { dirname, join } from 'node:path'\nimport { homedir } from 'node:os'\n\nexport interface Identity {\n email: string\n jmapToken: string\n smtpPassword: string\n}\n\nexport function defaultCredentialsPath(): string {\n return join(homedir(), '.openclaw', 'extensions', 'aamp-openclaw-plugin', '.credentials.json')\n}\n\nexport function loadCachedIdentity(file?: string): Identity | null {\n const resolved = file ?? defaultCredentialsPath()\n if (!existsSync(resolved)) return null\n try {\n const parsed = JSON.parse(readFileSync(resolved, 'utf-8')) as Partial<Identity>\n if (!parsed.email || !parsed.jmapToken || !parsed.smtpPassword) return null\n return parsed as Identity\n } catch {\n return null\n }\n}\n\nexport function saveCachedIdentity(identity: Identity, file?: string): void {\n const resolved = file ?? defaultCredentialsPath()\n mkdirSync(dirname(resolved), { recursive: true })\n writeFileSync(resolved, JSON.stringify(identity, null, 2), 'utf-8')\n}\n\nexport function ensureDir(dir: string): void {\n mkdirSync(dir, { recursive: true })\n}\n\nexport function readBinaryFile(path: string): Buffer {\n return readFileSync(path)\n}\n\nexport function writeBinaryFile(path: string, content: Uint8Array | Buffer): void {\n mkdirSync(dirname(path), { recursive: true })\n writeFileSync(path, content)\n}\n"],
5
+ "mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,SAAS,YAAY,WAAW,cAAc,qBAAqB;AACnE,SAAS,SAAS,YAAY;AAC9B,SAAS,eAAe;AAQjB,SAAS,yBAAiC;AAC/C,SAAO,KAAK,QAAQ,GAAG,aAAa,cAAc,wBAAwB,mBAAmB;AAC/F;AAEO,SAAS,mBAAmB,MAAgC;AACjE,QAAM,WAAW,QAAQ,uBAAuB;AAChD,MAAI,CAAC,WAAW,QAAQ;AAAG,WAAO;AAClC,MAAI;AACF,UAAM,SAAS,KAAK,MAAM,aAAa,UAAU,OAAO,CAAC;AACzD,QAAI,CAAC,OAAO,SAAS,CAAC,OAAO,aAAa,CAAC,OAAO;AAAc,aAAO;AACvE,WAAO;AAAA,EACT,QAAQ;AACN,WAAO;AAAA,EACT;AACF;AAEO,SAAS,mBAAmB,UAAoB,MAAqB;AAC1E,QAAM,WAAW,QAAQ,uBAAuB;AAChD,YAAU,QAAQ,QAAQ,GAAG,EAAE,WAAW,KAAK,CAAC;AAChD,gBAAc,UAAU,KAAK,UAAU,UAAU,MAAM,CAAC,GAAG,OAAO;AACpE;AAEO,SAAS,UAAU,KAAmB;AAC3C,YAAU,KAAK,EAAE,WAAW,KAAK,CAAC;AACpC;AAEO,SAAS,eAAe,MAAsB;AACnD,SAAO,aAAa,IAAI;AAC1B;AAEO,SAAS,gBAAgB,MAAc,SAAoC;AAChF,YAAU,QAAQ,IAAI,GAAG,EAAE,WAAW,KAAK,CAAC;AAC5C,gBAAc,MAAM,OAAO;AAC7B;",
6
+ "names": []
7
+ }
@@ -1,37 +1,11 @@
1
- import { existsSync, mkdirSync, readFileSync, writeFileSync } from "node:fs";
2
- import { dirname, join } from "node:path";
3
- import { homedir } from "node:os";
4
- function defaultCredentialsPath() {
5
- return join(homedir(), ".openclaw", "extensions", "aamp-openclaw-plugin", ".credentials.json");
6
- }
7
- function loadCachedIdentity(file) {
8
- const resolved = file ?? defaultCredentialsPath();
9
- if (!existsSync(resolved))
10
- return null;
11
- try {
12
- const parsed = JSON.parse(readFileSync(resolved, "utf-8"));
13
- if (!parsed.email || !parsed.jmapToken || !parsed.smtpPassword)
14
- return null;
15
- return parsed;
16
- } catch {
17
- return null;
18
- }
19
- }
20
- function saveCachedIdentity(identity, file) {
21
- const resolved = file ?? defaultCredentialsPath();
22
- mkdirSync(dirname(resolved), { recursive: true });
23
- writeFileSync(resolved, JSON.stringify(identity, null, 2), "utf-8");
24
- }
25
- function ensureDir(dir) {
26
- mkdirSync(dir, { recursive: true });
27
- }
28
- function readBinaryFile(path) {
29
- return readFileSync(path);
30
- }
31
- function writeBinaryFile(path, content) {
32
- mkdirSync(dirname(path), { recursive: true });
33
- writeFileSync(path, content);
34
- }
1
+ import {
2
+ defaultCredentialsPath,
3
+ ensureDir,
4
+ loadCachedIdentity,
5
+ readBinaryFile,
6
+ saveCachedIdentity,
7
+ writeBinaryFile
8
+ } from "./chunk-W4C7IUCH.js";
35
9
  export {
36
10
  defaultCredentialsPath,
37
11
  ensureDir,
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
- "sources": ["../src/file-store.ts"],
4
- "sourcesContent": ["import { existsSync, mkdirSync, readFileSync, writeFileSync } from 'node:fs'\nimport { dirname, join } from 'node:path'\nimport { homedir } from 'node:os'\n\nexport interface Identity {\n email: string\n jmapToken: string\n smtpPassword: string\n}\n\nexport function defaultCredentialsPath(): string {\n return join(homedir(), '.openclaw', 'extensions', 'aamp-openclaw-plugin', '.credentials.json')\n}\n\nexport function loadCachedIdentity(file?: string): Identity | null {\n const resolved = file ?? defaultCredentialsPath()\n if (!existsSync(resolved)) return null\n try {\n const parsed = JSON.parse(readFileSync(resolved, 'utf-8')) as Partial<Identity>\n if (!parsed.email || !parsed.jmapToken || !parsed.smtpPassword) return null\n return parsed as Identity\n } catch {\n return null\n }\n}\n\nexport function saveCachedIdentity(identity: Identity, file?: string): void {\n const resolved = file ?? defaultCredentialsPath()\n mkdirSync(dirname(resolved), { recursive: true })\n writeFileSync(resolved, JSON.stringify(identity, null, 2), 'utf-8')\n}\n\nexport function ensureDir(dir: string): void {\n mkdirSync(dir, { recursive: true })\n}\n\nexport function readBinaryFile(path: string): Buffer {\n return readFileSync(path)\n}\n\nexport function writeBinaryFile(path: string, content: Uint8Array | Buffer): void {\n mkdirSync(dirname(path), { recursive: true })\n writeFileSync(path, content)\n}\n"],
5
- "mappings": "AAAA,SAAS,YAAY,WAAW,cAAc,qBAAqB;AACnE,SAAS,SAAS,YAAY;AAC9B,SAAS,eAAe;AAQjB,SAAS,yBAAiC;AAC/C,SAAO,KAAK,QAAQ,GAAG,aAAa,cAAc,wBAAwB,mBAAmB;AAC/F;AAEO,SAAS,mBAAmB,MAAgC;AACjE,QAAM,WAAW,QAAQ,uBAAuB;AAChD,MAAI,CAAC,WAAW,QAAQ;AAAG,WAAO;AAClC,MAAI;AACF,UAAM,SAAS,KAAK,MAAM,aAAa,UAAU,OAAO,CAAC;AACzD,QAAI,CAAC,OAAO,SAAS,CAAC,OAAO,aAAa,CAAC,OAAO;AAAc,aAAO;AACvE,WAAO;AAAA,EACT,QAAQ;AACN,WAAO;AAAA,EACT;AACF;AAEO,SAAS,mBAAmB,UAAoB,MAAqB;AAC1E,QAAM,WAAW,QAAQ,uBAAuB;AAChD,YAAU,QAAQ,QAAQ,GAAG,EAAE,WAAW,KAAK,CAAC;AAChD,gBAAc,UAAU,KAAK,UAAU,UAAU,MAAM,CAAC,GAAG,OAAO;AACpE;AAEO,SAAS,UAAU,KAAmB;AAC3C,YAAU,KAAK,EAAE,WAAW,KAAK,CAAC;AACpC;AAEO,SAAS,eAAe,MAAsB;AACnD,SAAO,aAAa,IAAI;AAC1B;AAEO,SAAS,gBAAgB,MAAc,SAAoC;AAChF,YAAU,QAAQ,IAAI,GAAG,EAAE,WAAW,KAAK,CAAC;AAC5C,gBAAc,MAAM,OAAO;AAC7B;",
3
+ "sources": [],
4
+ "sourcesContent": [],
5
+ "mappings": "",
6
6
  "names": []
7
7
  }