openclaw-overlay-plugin 0.7.65 → 0.7.67
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/dist/index.d.ts +12 -2
- package/dist/index.js +97 -85
- package/dist/src/compatibility.test.d.ts +4 -0
- package/dist/src/compatibility.test.js +52 -0
- package/dist/src/scripts/baemail/commands.d.ts +18 -47
- package/dist/src/scripts/baemail/commands.js +112 -101
- package/dist/src/scripts/baemail/handler.js +2 -2
- package/dist/src/scripts/services/respond.js +1 -1
- package/dist/src/scripts/utils/storage.js +1 -1
- package/dist/src/test/request-response-flow.test.js +8 -7
- package/index.ts +106 -90
- package/openclaw.plugin.json +14 -50
- package/package.json +1 -1
- package/src/compatibility.test.ts +57 -0
- package/src/scripts/baemail/commands.ts +118 -146
- package/src/scripts/baemail/handler.ts +2 -2
- package/src/scripts/services/respond.ts +1 -1
- package/src/scripts/utils/storage.ts +1 -1
- package/src/test/request-response-flow.test.ts +8 -7
package/dist/index.d.ts
CHANGED
|
@@ -1,2 +1,12 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
/**
|
|
2
|
+
* OpenClaw Overlay Plugin
|
|
3
|
+
* Decentralized agent marketplace with BSV micropayments.
|
|
4
|
+
*/
|
|
5
|
+
export declare const plugin: {
|
|
6
|
+
id: string;
|
|
7
|
+
name: string;
|
|
8
|
+
description: string;
|
|
9
|
+
activate(api: any): Promise<void>;
|
|
10
|
+
register(api: any): void;
|
|
11
|
+
};
|
|
12
|
+
export default plugin;
|
package/dist/index.js
CHANGED
|
@@ -7,9 +7,11 @@ import path from 'node:path';
|
|
|
7
7
|
import os from 'node:os';
|
|
8
8
|
import { fileURLToPath } from 'node:url';
|
|
9
9
|
import fs from 'node:fs';
|
|
10
|
+
import process from 'node:process';
|
|
10
11
|
import { serviceManager } from './src/services/index.js';
|
|
11
12
|
const __filename = fileURLToPath(import.meta.url);
|
|
12
13
|
const __dirname = path.dirname(__filename);
|
|
14
|
+
let isInitialized = false;
|
|
13
15
|
async function ensureCp() {
|
|
14
16
|
if (execFileAsync)
|
|
15
17
|
return;
|
|
@@ -57,7 +59,7 @@ function loadDailySpending(walletDir) {
|
|
|
57
59
|
return { date: today, totalSats: 0, transactions: [] };
|
|
58
60
|
}
|
|
59
61
|
function writeActivityEvent(event) {
|
|
60
|
-
const alertDir = path.join(process['
|
|
62
|
+
const alertDir = path.join(process['env'].HOME || '', '.openclaw', 'openclaw-overlay');
|
|
61
63
|
try {
|
|
62
64
|
fs.mkdirSync(alertDir, { recursive: true });
|
|
63
65
|
fs.appendFileSync(path.join(alertDir, 'activity-feed.jsonl'), JSON.stringify({ ...event, ts: Date.now() }) + '\n');
|
|
@@ -115,7 +117,7 @@ async function startAutoImport(env, cliPath, logger) {
|
|
|
115
117
|
logger?.info?.(`[openclaw-overlay] Auto-imported ${utxo.value} sats from ${utxo.tx_hash}`);
|
|
116
118
|
// Clear onboarding flag since wallet is now funded
|
|
117
119
|
try {
|
|
118
|
-
const onboardingSentFile = path.join(process['
|
|
120
|
+
const onboardingSentFile = path.join(process['env'].HOME || '', '.openclaw', 'openclaw-overlay', 'onboarding-sent.flag');
|
|
119
121
|
if (fs.existsSync(onboardingSentFile)) {
|
|
120
122
|
fs.unlinkSync(onboardingSentFile);
|
|
121
123
|
}
|
|
@@ -125,7 +127,7 @@ async function startAutoImport(env, cliPath, logger) {
|
|
|
125
127
|
wakeAgent(`💰 **Wallet Funded!**\n\nAuto-imported ${utxo.value} sats from transaction ${utxo.tx_hash.slice(0, 16)}...\n\nNotify the user their wallet has been funded.`, logger, { sessionKey: 'hook:openclaw-overlay:import' });
|
|
126
128
|
// Check if registered, auto-register if not
|
|
127
129
|
try {
|
|
128
|
-
const regPath = path.join(process['
|
|
130
|
+
const regPath = path.join(process['env'].HOME || '', '.openclaw', 'openclaw-overlay', 'registration.json');
|
|
129
131
|
if (!fs.existsSync(regPath)) {
|
|
130
132
|
logger?.info?.('[openclaw-overlay] Not yet registered — auto-registering...');
|
|
131
133
|
const regResult = await execFileAsync('node', [cliPath, 'register'], { env, timeout: 60000 });
|
|
@@ -196,7 +198,7 @@ async function autoAdvertiseServices(env, cliPath, logger) {
|
|
|
196
198
|
}
|
|
197
199
|
function wakeAgent(text, logger, options = {}) {
|
|
198
200
|
const sessionKey = options.sessionKey || `hook:openclaw-overlay:${Date.now()}`;
|
|
199
|
-
const gatewayPort = process['
|
|
201
|
+
const gatewayPort = process['env'].OPENCLAW_GATEWAY_PORT || '18789';
|
|
200
202
|
const httpToken = getHooksToken();
|
|
201
203
|
if (!httpToken)
|
|
202
204
|
return;
|
|
@@ -207,7 +209,7 @@ function wakeAgent(text, logger, options = {}) {
|
|
|
207
209
|
}).catch(() => { });
|
|
208
210
|
}
|
|
209
211
|
function getHooksToken() {
|
|
210
|
-
let token = process['
|
|
212
|
+
let token = process['env'].OPENCLAW_HOOKS_TOKEN || null;
|
|
211
213
|
if (!token) {
|
|
212
214
|
try {
|
|
213
215
|
const configPath = path.join(os.homedir(), '.openclaw', 'openclaw.json');
|
|
@@ -262,7 +264,7 @@ function startBackgroundService(env, cliPath, logger) {
|
|
|
262
264
|
}
|
|
263
265
|
const notif = categorizeEvent(event);
|
|
264
266
|
if (notif) {
|
|
265
|
-
const dir = path.join(process['
|
|
267
|
+
const dir = path.join(process['env'].HOME || '', '.openclaw', 'openclaw-overlay');
|
|
266
268
|
fs.mkdirSync(dir, { recursive: true });
|
|
267
269
|
fs.appendFileSync(path.join(dir, 'activity-feed.jsonl'), JSON.stringify(notif) + '\n');
|
|
268
270
|
}
|
|
@@ -291,94 +293,104 @@ function stopBackgroundService() {
|
|
|
291
293
|
wokenRequests.clear();
|
|
292
294
|
stopAutoImport();
|
|
293
295
|
}
|
|
294
|
-
export async function activate(api) {
|
|
295
|
-
return register(api);
|
|
296
|
-
}
|
|
297
|
-
let isInitialized = false;
|
|
298
296
|
function getCliPath() {
|
|
299
297
|
const base = __dirname.endsWith('dist') ? __dirname : path.join(__dirname, 'dist');
|
|
300
298
|
return path.join(base, 'src', 'cli.js');
|
|
301
299
|
}
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
api
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
300
|
+
/**
|
|
301
|
+
* OpenClaw Overlay Plugin
|
|
302
|
+
* Decentralized agent marketplace with BSV micropayments.
|
|
303
|
+
*/
|
|
304
|
+
export const plugin = {
|
|
305
|
+
id: "openclaw-overlay-plugin",
|
|
306
|
+
name: "BSV Overlay Network",
|
|
307
|
+
description: "OpenClaw Overlay — decentralized agent marketplace with BSV micropayments",
|
|
308
|
+
async activate(api) {
|
|
309
|
+
return this.register(api);
|
|
310
|
+
},
|
|
311
|
+
register(api) {
|
|
312
|
+
if (isInitialized)
|
|
313
|
+
return;
|
|
314
|
+
isInitialized = true;
|
|
315
|
+
const entries = api.getConfig?.()?.plugins?.entries || {};
|
|
316
|
+
const entry = entries['openclaw-overlay-plugin'] || entries['openclaw-overlay'] || {};
|
|
317
|
+
const pluginConfig = { ...entry, ...(entry.config || {}), ...(api.config || {}) };
|
|
318
|
+
// 1. Tool
|
|
319
|
+
api.registerTool({
|
|
320
|
+
name: "overlay",
|
|
321
|
+
description: "Access the BSV agent marketplace",
|
|
322
|
+
parameters: {
|
|
323
|
+
type: "object",
|
|
324
|
+
properties: {
|
|
325
|
+
action: { type: "string", enum: ["request", "discover", "balance", "status", "pay", "onboard", "pending-requests", "fulfill", "unregister"] },
|
|
326
|
+
service: { type: "string" },
|
|
327
|
+
input: { type: "object" },
|
|
328
|
+
identityKey: { type: "string" },
|
|
329
|
+
sats: { type: "number" },
|
|
330
|
+
requestId: { type: "string" },
|
|
331
|
+
recipientKey: { type: "string" },
|
|
332
|
+
serviceId: { type: "string" },
|
|
333
|
+
result: { type: "object" }
|
|
334
|
+
},
|
|
335
|
+
required: ["action"]
|
|
325
336
|
},
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
catch (error) {
|
|
333
|
-
return { content: [{ type: "text", text: `Error: ${error.message}` }] };
|
|
334
|
-
}
|
|
335
|
-
}
|
|
336
|
-
});
|
|
337
|
-
// 2. Command
|
|
338
|
-
api.registerCommand({
|
|
339
|
-
name: "overlay",
|
|
340
|
-
description: "BSV Overlay Marketplace commands",
|
|
341
|
-
acceptsArgs: true,
|
|
342
|
-
handler: async (ctx) => {
|
|
343
|
-
try {
|
|
344
|
-
const action = ctx.args?.[0] || 'status';
|
|
345
|
-
if (action === 'help') {
|
|
346
|
-
return { text: `🛰️ **Overlay Help**\n\n**Subcommands**:\n- \`status\`: Show identity and wallet balance\n- \`balance\`: Show current satoshis\n- \`onboard\`: Start discovery setup\n- \`discover <serviceId>\`: Find providers on network\n- \`pending-requests\`: See incoming service jobs\n- \`fulfill\`: Complete a request (Agent only)` };
|
|
337
|
+
async execute(_id, params) {
|
|
338
|
+
try {
|
|
339
|
+
return await executeOverlayAction(params, pluginConfig, api);
|
|
340
|
+
}
|
|
341
|
+
catch (error) {
|
|
342
|
+
return { content: [{ type: "text", text: `Error: ${error.message}` }] };
|
|
347
343
|
}
|
|
348
|
-
const result = await executeOverlayAction({ action }, pluginConfig, api);
|
|
349
|
-
return { text: `**Overlay ${action.toUpperCase()}**\n\n${typeof result === 'string' ? result : JSON.stringify(result, null, 2)}` };
|
|
350
344
|
}
|
|
351
|
-
|
|
352
|
-
|
|
345
|
+
});
|
|
346
|
+
// 2. Command
|
|
347
|
+
api.registerCommand({
|
|
348
|
+
name: "overlay",
|
|
349
|
+
description: "BSV Overlay Marketplace commands",
|
|
350
|
+
acceptsArgs: true,
|
|
351
|
+
requireAuth: true,
|
|
352
|
+
handler: async (ctx) => {
|
|
353
|
+
try {
|
|
354
|
+
const action = ctx.args?.[0] || 'status';
|
|
355
|
+
if (action === 'help') {
|
|
356
|
+
return { text: `🛰️ **Overlay Help**\n\n**Subcommands**:\n- \`status\`: Show identity and wallet balance\n- \`balance\`: Show current satoshis\n- \`onboard\`: Start discovery setup\n- \`discover <serviceId>\`: Find providers on network\n- \`pending-requests\`: See incoming service jobs\n- \`fulfill\`: Complete a request (Agent only)` };
|
|
357
|
+
}
|
|
358
|
+
const result = await executeOverlayAction({ action }, pluginConfig, api);
|
|
359
|
+
return { text: `**Overlay ${action.toUpperCase()}**\n\n${typeof result === 'string' ? result : JSON.stringify(result, null, 2)}` };
|
|
360
|
+
}
|
|
361
|
+
catch (error) {
|
|
362
|
+
return { text: `❌ Error: ${error.message}` };
|
|
363
|
+
}
|
|
353
364
|
}
|
|
354
|
-
}
|
|
355
|
-
});
|
|
356
|
-
// 3. Service
|
|
357
|
-
api.registerService({
|
|
358
|
-
id: "openclaw-overlay-relay",
|
|
359
|
-
start: async () => {
|
|
360
|
-
const env = buildEnvironment(pluginConfig);
|
|
361
|
-
const cliPath = getCliPath();
|
|
362
|
-
startBackgroundService(env, cliPath, api.logger);
|
|
363
|
-
startAutoImport(env, cliPath, api.logger);
|
|
364
|
-
},
|
|
365
|
-
stop: () => stopBackgroundService()
|
|
366
|
-
});
|
|
367
|
-
// 4. CLI
|
|
368
|
-
api.registerCli(({ program }) => {
|
|
369
|
-
const overlay = program.command("overlay").description("BSV Overlay Network management");
|
|
370
|
-
overlay.command("status").action(async () => {
|
|
371
|
-
await ensureCp();
|
|
372
|
-
const result = await handleStatus(buildEnvironment(pluginConfig), getCliPath());
|
|
373
|
-
console.log(JSON.stringify(result, null, 2));
|
|
374
365
|
});
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
366
|
+
// 3. Service
|
|
367
|
+
api.registerService({
|
|
368
|
+
id: "openclaw-overlay-relay",
|
|
369
|
+
start: async () => {
|
|
370
|
+
const env = buildEnvironment(pluginConfig);
|
|
371
|
+
const cliPath = getCliPath();
|
|
372
|
+
startBackgroundService(env, cliPath, api.logger);
|
|
373
|
+
startAutoImport(env, cliPath, api.logger);
|
|
374
|
+
},
|
|
375
|
+
stop: () => stopBackgroundService()
|
|
379
376
|
});
|
|
380
|
-
|
|
381
|
-
}
|
|
377
|
+
// 4. CLI
|
|
378
|
+
api.registerCli(({ program }) => {
|
|
379
|
+
const overlay = program.command("overlay").description("BSV Overlay Network management");
|
|
380
|
+
overlay.command("status").action(async () => {
|
|
381
|
+
await ensureCp();
|
|
382
|
+
const result = await handleStatus(buildEnvironment(pluginConfig), getCliPath());
|
|
383
|
+
console.log(JSON.stringify(result, null, 2));
|
|
384
|
+
});
|
|
385
|
+
overlay.command("balance").action(async () => {
|
|
386
|
+
await ensureCp();
|
|
387
|
+
const result = await handleBalance(buildEnvironment(pluginConfig), getCliPath());
|
|
388
|
+
console.log(JSON.stringify(result, null, 2));
|
|
389
|
+
});
|
|
390
|
+
}, { descriptors: [{ name: "overlay", description: "BSV Overlay Network management" }] });
|
|
391
|
+
}
|
|
392
|
+
};
|
|
393
|
+
export default plugin;
|
|
382
394
|
async function executeOverlayAction(params, config, api) {
|
|
383
395
|
await ensureCp();
|
|
384
396
|
const { action } = params;
|
|
@@ -452,7 +464,7 @@ async function handleFulfill(params, env, cliPath) {
|
|
|
452
464
|
return parseCliOutput(res.stdout).data;
|
|
453
465
|
}
|
|
454
466
|
function buildEnvironment(config) {
|
|
455
|
-
const env = { ...process['
|
|
467
|
+
const env = { ...process['env'] };
|
|
456
468
|
env.BSV_WALLET_DIR = config.walletDir || path.join(os.homedir(), '.openclaw', 'bsv-wallet');
|
|
457
469
|
env.OVERLAY_URL = config.overlayUrl || 'https://clawoverlay.com';
|
|
458
470
|
env.BSV_NETWORK = env.BSV_NETWORK || 'mainnet';
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Compatibility Test for Node 24 and OpenClaw SDK
|
|
3
|
+
*/
|
|
4
|
+
import sqlite3 from 'sqlite3';
|
|
5
|
+
import { plugin } from '../index.js';
|
|
6
|
+
async function testCompatibility() {
|
|
7
|
+
console.log('--- Overlay Compatibility Test ---');
|
|
8
|
+
// 1. Verify SQLite3 Native Bindings
|
|
9
|
+
try {
|
|
10
|
+
const db = new sqlite3.Database(':memory:');
|
|
11
|
+
console.log('✓ SQLite3 native bindings loaded successfully.');
|
|
12
|
+
db.close();
|
|
13
|
+
}
|
|
14
|
+
catch (err) {
|
|
15
|
+
console.error('✗ SQLite3 failed to load bindings:', err.message);
|
|
16
|
+
process.exit(1);
|
|
17
|
+
}
|
|
18
|
+
// 2. Verify Plugin Registration (SDK Descriptors)
|
|
19
|
+
let registeredCli = false;
|
|
20
|
+
let hasDescriptors = false;
|
|
21
|
+
const mockApi = {
|
|
22
|
+
logger: { info: () => { }, warn: () => { }, error: () => { } },
|
|
23
|
+
registerTool: () => { },
|
|
24
|
+
registerCommand: () => { },
|
|
25
|
+
registerService: () => { },
|
|
26
|
+
registerCli: (fn, options) => {
|
|
27
|
+
registeredCli = true;
|
|
28
|
+
if (options && options.descriptors && options.descriptors[0].name === 'overlay') {
|
|
29
|
+
hasDescriptors = true;
|
|
30
|
+
}
|
|
31
|
+
},
|
|
32
|
+
getConfig: () => ({ plugins: { entries: {} } })
|
|
33
|
+
};
|
|
34
|
+
try {
|
|
35
|
+
plugin.register(mockApi);
|
|
36
|
+
if (registeredCli && hasDescriptors) {
|
|
37
|
+
console.log('✓ CLI descriptors registered correctly for Phase 1 discovery.');
|
|
38
|
+
}
|
|
39
|
+
else {
|
|
40
|
+
throw new Error(`CLI registration missing or using old 'commands' array format.`);
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
catch (err) {
|
|
44
|
+
console.error('✗ Plugin registration failed:', err.message);
|
|
45
|
+
process.exit(1);
|
|
46
|
+
}
|
|
47
|
+
console.log('--- All Compatibility Tests Passed ---\n');
|
|
48
|
+
}
|
|
49
|
+
testCompatibility().catch(err => {
|
|
50
|
+
console.error(err);
|
|
51
|
+
process.exit(1);
|
|
52
|
+
});
|
|
@@ -1,63 +1,34 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Baemail commands - paid message forwarding service.
|
|
3
|
-
*/
|
|
4
|
-
export interface BaemailConfig {
|
|
5
|
-
deliveryChannel: string;
|
|
6
|
-
tiers: {
|
|
7
|
-
standard: number;
|
|
8
|
-
priority: number;
|
|
9
|
-
urgent: number;
|
|
10
|
-
};
|
|
11
|
-
maxMessageLength: number;
|
|
12
|
-
blocklist: string[];
|
|
13
|
-
createdAt: string;
|
|
14
|
-
updatedAt: string;
|
|
15
|
-
}
|
|
16
1
|
export interface BaemailLogEntry {
|
|
17
2
|
requestId: string;
|
|
18
3
|
from: string;
|
|
19
|
-
|
|
20
|
-
tier: string;
|
|
4
|
+
to?: string;
|
|
21
5
|
paidSats: number;
|
|
22
|
-
messageLength: number;
|
|
23
|
-
deliveryChannel: string;
|
|
24
6
|
deliverySuccess: boolean;
|
|
25
|
-
|
|
26
|
-
paymentTxid: string;
|
|
27
|
-
refundStatus: string | null;
|
|
7
|
+
refundStatus?: 'pending' | 'completed';
|
|
28
8
|
refundTxid?: string;
|
|
29
|
-
refundedAt?: string;
|
|
30
|
-
timestamp: string;
|
|
31
9
|
_lineIdx?: number;
|
|
10
|
+
ts?: number;
|
|
11
|
+
senderName?: string;
|
|
12
|
+
messageLength?: number;
|
|
13
|
+
tier?: string;
|
|
14
|
+
deliveryChannel?: string;
|
|
15
|
+
deliveryError?: string | null;
|
|
16
|
+
paymentTxid?: string;
|
|
17
|
+
timestamp?: string;
|
|
32
18
|
}
|
|
33
19
|
/**
|
|
34
|
-
*
|
|
35
|
-
*/
|
|
36
|
-
export declare function loadBaemailConfig(): BaemailConfig | null;
|
|
37
|
-
/**
|
|
38
|
-
* Save baemail configuration.
|
|
39
|
-
*/
|
|
40
|
-
export declare function saveBaemailConfig(config: BaemailConfig): void;
|
|
41
|
-
/**
|
|
42
|
-
* Setup baemail service with delivery channel and tier pricing.
|
|
20
|
+
* Log a baemail delivery event.
|
|
43
21
|
*/
|
|
44
|
-
export declare function
|
|
22
|
+
export declare function logBaemailDelivery(entry: BaemailLogEntry): void;
|
|
23
|
+
export declare function loadBaemailConfig(): Promise<any>;
|
|
45
24
|
/**
|
|
46
|
-
*
|
|
47
|
-
*/
|
|
48
|
-
export declare function cmdBaemailConfig(): Promise<never>;
|
|
49
|
-
/**
|
|
50
|
-
* Block a sender from using baemail.
|
|
51
|
-
*/
|
|
52
|
-
export declare function cmdBaemailBlock(identityKey: string | undefined): Promise<never>;
|
|
53
|
-
/**
|
|
54
|
-
* Unblock a sender.
|
|
55
|
-
*/
|
|
56
|
-
export declare function cmdBaemailUnblock(identityKey: string | undefined): Promise<never>;
|
|
57
|
-
/**
|
|
58
|
-
* View baemail delivery log.
|
|
25
|
+
* List recent baemail deliveries.
|
|
59
26
|
*/
|
|
60
27
|
export declare function cmdBaemailLog(limitStr?: string): Promise<never>;
|
|
28
|
+
export declare function cmdBaemailSetup(priceSatsStr: string, prioritySats?: string, urgentSats?: string, channel?: string): Promise<never>;
|
|
29
|
+
export declare function cmdBaemailConfig(): Promise<never>;
|
|
30
|
+
export declare function cmdBaemailBlock(pubkey: string): Promise<never>;
|
|
31
|
+
export declare function cmdBaemailUnblock(pubkey: string): Promise<never>;
|
|
61
32
|
/**
|
|
62
33
|
* Refund a failed baemail delivery.
|
|
63
34
|
*/
|