aamp-openclaw-plugin 0.1.12 → 0.1.14
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/bin/aamp-openclaw-plugin.mjs +66 -44
- package/dist/chunk-W4C7IUCH.js +81 -0
- package/dist/chunk-W4C7IUCH.js.map +7 -0
- package/dist/file-store.js +8 -34
- package/dist/file-store.js.map +3 -3
- package/dist/index.js +16280 -44
- package/dist/index.js.map +4 -4
- package/package.json +1 -1
|
@@ -102,6 +102,12 @@ function parseDispatchContextRules(raw) {
|
|
|
102
102
|
return Object.keys(rules).length ? rules : undefined
|
|
103
103
|
}
|
|
104
104
|
|
|
105
|
+
function isYes(answer, defaultValue = true) {
|
|
106
|
+
const normalized = answer.trim().toLowerCase()
|
|
107
|
+
if (!normalized) return defaultValue
|
|
108
|
+
return ['y', 'yes'].includes(normalized)
|
|
109
|
+
}
|
|
110
|
+
|
|
105
111
|
function packageRootFromEntry(entryPath) {
|
|
106
112
|
let current = dirname(entryPath)
|
|
107
113
|
while (current !== dirname(current)) {
|
|
@@ -136,18 +142,6 @@ function installPluginFiles(credentialsFile = DEFAULT_CREDENTIALS_FILE) {
|
|
|
136
142
|
|
|
137
143
|
writeJsonFile(join(extensionDir, 'package.json'), packageJson)
|
|
138
144
|
|
|
139
|
-
const dependencyPackages = ['aamp-sdk', 'ws', 'nodemailer']
|
|
140
|
-
const nodeModulesDir = join(extensionDir, 'node_modules')
|
|
141
|
-
mkdirSync(nodeModulesDir, { recursive: true })
|
|
142
|
-
|
|
143
|
-
for (const dep of dependencyPackages) {
|
|
144
|
-
const depRoot = join(packageRoot, 'node_modules', dep)
|
|
145
|
-
if (!existsSync(depRoot)) {
|
|
146
|
-
throw new Error(`Missing dependency directory: ${depRoot}`)
|
|
147
|
-
}
|
|
148
|
-
copyIntoDir(depRoot, join(nodeModulesDir, dep))
|
|
149
|
-
}
|
|
150
|
-
|
|
151
145
|
if (existingCredentials) {
|
|
152
146
|
mkdirSync(dirname(credentialsPath), { recursive: true })
|
|
153
147
|
writeFileSync(credentialsPath, existingCredentials)
|
|
@@ -243,58 +237,86 @@ function printHelp() {
|
|
|
243
237
|
}
|
|
244
238
|
|
|
245
239
|
async function runInit() {
|
|
246
|
-
|
|
247
|
-
|
|
240
|
+
const configPath = resolveOpenClawConfigPath()
|
|
241
|
+
const existing = readJsonFile(configPath)
|
|
242
|
+
const previousEntry = existing?.plugins?.entries?.[PLUGIN_ID] ?? existing?.plugins?.entries?.aamp
|
|
243
|
+
const previousConfig = previousEntry?.config && typeof previousEntry.config === 'object'
|
|
244
|
+
? previousEntry.config
|
|
245
|
+
: null
|
|
246
|
+
const previousCredentialsFile = previousConfig?.credentialsFile || DEFAULT_CREDENTIALS_FILE
|
|
247
|
+
const previousSlug = previousConfig?.slug || 'openclaw-agent'
|
|
248
|
+
|
|
249
|
+
let aampHost = previousConfig?.aampHost || DEFAULT_AAMP_HOST
|
|
250
|
+
let senderPolicies = previousConfig?.senderPolicies
|
|
251
|
+
let slug = previousSlug
|
|
252
|
+
let reuseExistingConfig = Boolean(previousConfig)
|
|
248
253
|
|
|
249
254
|
if (input.isTTY) {
|
|
250
255
|
const rl = createInterface({ input, output })
|
|
251
256
|
try {
|
|
252
257
|
output.write('AAMP OpenClaw Plugin Setup\n\n')
|
|
253
258
|
|
|
254
|
-
|
|
255
|
-
|
|
259
|
+
if (previousConfig) {
|
|
260
|
+
output.write(
|
|
261
|
+
[
|
|
262
|
+
'Detected existing plugin config:',
|
|
263
|
+
` aampHost: ${previousConfig.aampHost ?? DEFAULT_AAMP_HOST}`,
|
|
264
|
+
` slug: ${previousConfig.slug ?? 'openclaw-agent'}`,
|
|
265
|
+
` senderPolicies: ${previousConfig.senderPolicies ? JSON.stringify(previousConfig.senderPolicies) : '(allow all)'}`,
|
|
266
|
+
'',
|
|
267
|
+
].join('\n'),
|
|
268
|
+
)
|
|
269
|
+
const reuseAnswer = await rl.question('Reuse current plugin config? [Y/n]: ')
|
|
270
|
+
reuseExistingConfig = isYes(reuseAnswer, true)
|
|
271
|
+
}
|
|
256
272
|
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
'Dispatch context rules for that sender (optional, format: project_key=proj1,proj2; user_key=alice): ',
|
|
273
|
+
if (!reuseExistingConfig) {
|
|
274
|
+
const aampHostAnswer = await rl.question(`AAMP Host (${aampHost}): `)
|
|
275
|
+
aampHost = aampHostAnswer.trim() || aampHost
|
|
276
|
+
|
|
277
|
+
const senderAnswer = await rl.question(
|
|
278
|
+
'Primary trusted dispatch sender (e.g. meegle-bot@meshmail.ai, leave blank to allow all): ',
|
|
264
279
|
)
|
|
265
|
-
const
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
280
|
+
const sender = senderAnswer.trim()
|
|
281
|
+
if (sender) {
|
|
282
|
+
const rulesAnswer = await rl.question(
|
|
283
|
+
'Dispatch context rules for that sender (optional, format: project_key=proj1,proj2; user_key=alice): ',
|
|
284
|
+
)
|
|
285
|
+
const dispatchContextRules = parseDispatchContextRules(rulesAnswer)
|
|
286
|
+
senderPolicies = [{
|
|
287
|
+
sender,
|
|
288
|
+
...(dispatchContextRules ? { dispatchContextRules } : {}),
|
|
289
|
+
}]
|
|
290
|
+
} else {
|
|
291
|
+
senderPolicies = undefined
|
|
292
|
+
}
|
|
270
293
|
}
|
|
271
294
|
} finally {
|
|
272
295
|
rl.close()
|
|
273
296
|
}
|
|
274
297
|
} else {
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
298
|
+
if (!reuseExistingConfig) {
|
|
299
|
+
const [hostLine = '', senderLine = '', rulesLine = ''] = readFileSync(0, 'utf-8').split(/\r?\n/)
|
|
300
|
+
aampHost = hostLine.trim() || aampHost
|
|
301
|
+
const sender = senderLine.trim()
|
|
302
|
+
if (sender) {
|
|
303
|
+
const dispatchContextRules = parseDispatchContextRules(rulesLine)
|
|
304
|
+
senderPolicies = [{
|
|
305
|
+
sender,
|
|
306
|
+
...(dispatchContextRules ? { dispatchContextRules } : {}),
|
|
307
|
+
}]
|
|
308
|
+
} else {
|
|
309
|
+
senderPolicies = undefined
|
|
310
|
+
}
|
|
284
311
|
}
|
|
285
312
|
}
|
|
286
313
|
|
|
287
|
-
const configPath = resolveOpenClawConfigPath()
|
|
288
|
-
const existing = readJsonFile(configPath)
|
|
289
|
-
const previousEntry = existing?.plugins?.entries?.[PLUGIN_ID] ?? existing?.plugins?.entries?.aamp
|
|
290
|
-
const previousCredentialsFile = previousEntry?.config?.credentialsFile || DEFAULT_CREDENTIALS_FILE
|
|
291
|
-
|
|
292
314
|
output.write('\nInstalling OpenClaw plugin files...\n')
|
|
293
315
|
const extensionDir = installPluginFiles(previousCredentialsFile)
|
|
294
316
|
|
|
295
317
|
const next = ensurePluginConfig(existing, {
|
|
296
318
|
aampHost,
|
|
297
|
-
slug
|
|
319
|
+
slug,
|
|
298
320
|
credentialsFile: DEFAULT_CREDENTIALS_FILE,
|
|
299
321
|
...(senderPolicies ? { senderPolicies } : {}),
|
|
300
322
|
})
|
|
@@ -303,7 +325,7 @@ async function runInit() {
|
|
|
303
325
|
|
|
304
326
|
const identityResult = await ensureMailboxIdentity({
|
|
305
327
|
aampHost,
|
|
306
|
-
slug
|
|
328
|
+
slug,
|
|
307
329
|
credentialsFile: DEFAULT_CREDENTIALS_FILE,
|
|
308
330
|
})
|
|
309
331
|
|
|
@@ -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
|
+
}
|
package/dist/file-store.js
CHANGED
|
@@ -1,37 +1,11 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
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,
|
package/dist/file-store.js.map
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
|
-
"sources": [
|
|
4
|
-
"sourcesContent": [
|
|
5
|
-
"mappings": "
|
|
3
|
+
"sources": [],
|
|
4
|
+
"sourcesContent": [],
|
|
5
|
+
"mappings": "",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|