openclaw-overlay-plugin 0.7.66 → 0.7.68

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.
@@ -97,7 +97,7 @@ export function readJsonl(filePath) {
97
97
  if (!fs.existsSync(filePath))
98
98
  return [];
99
99
  const lines = fs.readFileSync(filePath, 'utf-8').trim().split('\n').filter(Boolean);
100
- return lines.map(line => {
100
+ return lines.map((line) => {
101
101
  try {
102
102
  return JSON.parse(line);
103
103
  }
@@ -3,6 +3,7 @@
3
3
  */
4
4
  import fs from 'node:fs';
5
5
  import path from 'node:path';
6
+ import process from 'node:process';
6
7
  // Simple test runner (matching existing pattern)
7
8
  let passed = 0;
8
9
  let failed = 0;
@@ -106,12 +107,12 @@ async function run() {
106
107
  mockCleanupServiceQueue(24 * 60 * 60 * 1000, 2 * 60 * 60 * 1000);
107
108
  // Check remaining entries
108
109
  const lines = fs.readFileSync(TEST_PATHS.serviceQueue, 'utf-8').trim().split('\n').filter(Boolean);
109
- const remaining = lines.map(line => JSON.parse(line));
110
+ const remaining = lines.map((line) => JSON.parse(line));
110
111
  assert(remaining.length === 2, `Expected 2 remaining entries, got ${remaining.length}`);
111
- assert(remaining.find(e => e.requestId === 'pending-1') !== undefined, 'Should keep recent pending');
112
- assert(remaining.find(e => e.requestId === 'recent-fulfilled') !== undefined, 'Should keep recent fulfilled');
113
- assert(remaining.find(e => e.requestId === 'old-fulfilled') === undefined, 'Should remove old fulfilled');
114
- assert(remaining.find(e => e.requestId === 'old-rejected') === undefined, 'Should remove old rejected');
112
+ assert(remaining.find((e) => e.requestId === 'pending-1') !== undefined, 'Should keep recent pending');
113
+ assert(remaining.find((e) => e.requestId === 'recent-fulfilled') !== undefined, 'Should keep recent fulfilled');
114
+ assert(remaining.find((e) => e.requestId === 'old-fulfilled') === undefined, 'Should remove old fulfilled');
115
+ assert(remaining.find((e) => e.requestId === 'old-rejected') === undefined, 'Should remove old rejected');
115
116
  cleanupTestEnv();
116
117
  });
117
118
  await test('updateServiceQueueStatus updates request status atomically', async () => {
@@ -131,7 +132,7 @@ async function run() {
131
132
  return false;
132
133
  const lines = fs.readFileSync(TEST_PATHS.serviceQueue, 'utf-8').trim().split('\n').filter(Boolean);
133
134
  let updated = false;
134
- const updatedLines = lines.map(line => {
135
+ const updatedLines = lines.map((line) => {
135
136
  try {
136
137
  const entryData = JSON.parse(line);
137
138
  if (entryData.requestId === requestId) {
@@ -178,7 +179,7 @@ async function run() {
178
179
  return false;
179
180
  const lines = fs.readFileSync(TEST_PATHS.serviceQueue, 'utf-8').trim().split('\n').filter(Boolean);
180
181
  let updated = false;
181
- lines.map(line => {
182
+ lines.map((line) => {
182
183
  try {
183
184
  const entry = JSON.parse(line);
184
185
  if (entry.requestId === requestId) {
package/index.ts CHANGED
@@ -9,10 +9,15 @@ import path from 'node:path';
9
9
  import os from 'node:os';
10
10
  import { fileURLToPath } from 'node:url';
11
11
  import fs from 'node:fs';
12
+ import process from 'node:process';
13
+ import { Buffer } from 'node:buffer';
12
14
  import { initializeServiceSystem, serviceManager } from './src/services/index.js';
15
+
13
16
  const __filename = fileURLToPath(import.meta.url);
14
17
  const __dirname = path.dirname(__filename);
15
18
 
19
+ let isInitialized = false;
20
+
16
21
  async function ensureCp() {
17
22
  if (execFileAsync) return;
18
23
  // @ts-ignore
@@ -71,7 +76,7 @@ function loadDailySpending(walletDir: string): DailySpending {
71
76
  }
72
77
 
73
78
  function writeActivityEvent(event: any) {
74
- const alertDir = path.join((process as any)['en' + 'v'].HOME || '', '.openclaw', 'openclaw-overlay');
79
+ const alertDir = path.join((process as any)['env'].HOME || '', '.openclaw', 'openclaw-overlay');
75
80
  try {
76
81
  fs.mkdirSync(alertDir, { recursive: true });
77
82
  fs.appendFileSync(path.join(alertDir, 'activity-feed.jsonl'), JSON.stringify({ ...event, ts: Date.now() }) + '\n');
@@ -130,7 +135,7 @@ async function startAutoImport(env: any, cliPath: string, logger: any) {
130
135
 
131
136
  // Clear onboarding flag since wallet is now funded
132
137
  try {
133
- const onboardingSentFile = path.join((process as any)['en' + 'v'].HOME || '', '.openclaw', 'openclaw-overlay', 'onboarding-sent.flag');
138
+ const onboardingSentFile = path.join((process as any)['env'].HOME || '', '.openclaw', 'openclaw-overlay', 'onboarding-sent.flag');
134
139
  if (fs.existsSync(onboardingSentFile)) {
135
140
  fs.unlinkSync(onboardingSentFile);
136
141
  }
@@ -141,7 +146,7 @@ async function startAutoImport(env: any, cliPath: string, logger: any) {
141
146
 
142
147
  // Check if registered, auto-register if not
143
148
  try {
144
- const regPath = path.join((process as any)['en' + 'v'].HOME || '', '.openclaw', 'openclaw-overlay', 'registration.json');
149
+ const regPath = path.join((process as any)['env'].HOME || '', '.openclaw', 'openclaw-overlay', 'registration.json');
145
150
  if (!fs.existsSync(regPath)) {
146
151
  logger?.info?.('[openclaw-overlay] Not yet registered — auto-registering...');
147
152
  const regResult = await execFileAsync('node', [cliPath, 'register'], { env, timeout: 60000 });
@@ -208,7 +213,7 @@ async function autoAdvertiseServices(env: any, cliPath: string, logger: any) {
208
213
 
209
214
  function wakeAgent(text: string, logger: any, options: { sessionKey?: string } = {}) {
210
215
  const sessionKey = options.sessionKey || `hook:openclaw-overlay:${Date.now()}`;
211
- const gatewayPort = (process as any)['en' + 'v'].OPENCLAW_GATEWAY_PORT || '18789';
216
+ const gatewayPort = (process as any)['env'].OPENCLAW_GATEWAY_PORT || '18789';
212
217
  const httpToken = getHooksToken();
213
218
  if (!httpToken) return;
214
219
 
@@ -220,7 +225,7 @@ function wakeAgent(text: string, logger: any, options: { sessionKey?: string } =
220
225
  }
221
226
 
222
227
  function getHooksToken(): string | null {
223
- let token = (process as any)['en' + 'v'].OPENCLAW_HOOKS_TOKEN || null;
228
+ let token = (process as any)['env'].OPENCLAW_HOOKS_TOKEN || null;
224
229
  if (!token) {
225
230
  try {
226
231
  const configPath = path.join(os.homedir(), '.openclaw', 'openclaw.json');
@@ -275,7 +280,7 @@ function startBackgroundService(env: any, cliPath: string, logger: any) {
275
280
  }
276
281
  const notif = categorizeEvent(event);
277
282
  if (notif) {
278
- const dir = path.join((process as any)['en' + 'v'].HOME || '', '.openclaw', 'openclaw-overlay');
283
+ const dir = path.join((process as any)['env'].HOME || '', '.openclaw', 'openclaw-overlay');
279
284
  fs.mkdirSync(dir, { recursive: true });
280
285
  fs.appendFileSync(path.join(dir, 'activity-feed.jsonl'), JSON.stringify(notif) + '\n');
281
286
  }
@@ -299,102 +304,112 @@ function stopBackgroundService() {
299
304
  stopAutoImport();
300
305
  }
301
306
 
302
- export async function activate(api: any) {
303
- return register(api);
304
- }
305
-
306
- let isInitialized = false;
307
-
308
307
  function getCliPath() {
309
308
  const base = __dirname.endsWith('dist') ? __dirname : path.join(__dirname, 'dist');
310
309
  return path.join(base, 'src', 'cli.js');
311
310
  }
312
311
 
313
- export default function register(api: any) {
314
- if (isInitialized) return;
315
- isInitialized = true;
316
-
317
- const entries = api.getConfig?.()?.plugins?.entries || {};
318
- const entry = entries['openclaw-overlay-plugin'] || entries['openclaw-overlay'] || {};
319
- const pluginConfig = { ...entry, ...(entry.config || {}), ...(api.config || {}) };
320
-
321
- // 1. Tool
322
- api.registerTool({
323
- name: "overlay",
324
- description: "Access the BSV agent marketplace",
325
- parameters: {
326
- type: "object",
327
- properties: {
328
- action: { type: "string", enum: ["request", "discover", "balance", "status", "pay", "onboard", "pending-requests", "fulfill", "unregister"] },
329
- service: { type: "string" },
330
- input: { type: "object" },
331
- identityKey: { type: "string" },
332
- sats: { type: "number" },
333
- requestId: { type: "string" },
334
- recipientKey: { type: "string" },
335
- serviceId: { type: "string" },
336
- result: { type: "object" }
312
+ /**
313
+ * OpenClaw Overlay Plugin
314
+ * Decentralized agent marketplace with BSV micropayments.
315
+ */
316
+ export const plugin = {
317
+ id: "openclaw-overlay-plugin",
318
+ name: "BSV Overlay Network",
319
+ description: "OpenClaw Overlay — decentralized agent marketplace with BSV micropayments",
320
+
321
+ async activate(api: any) {
322
+ return this.register(api);
323
+ },
324
+
325
+ register(api: any) {
326
+ if (isInitialized) return;
327
+ isInitialized = true;
328
+
329
+ const entries = api.getConfig?.()?.plugins?.entries || {};
330
+ const entry = entries['openclaw-overlay-plugin'] || entries['openclaw-overlay'] || {};
331
+ const pluginConfig = { ...entry, ...(entry.config || {}), ...(api.config || {}) };
332
+
333
+ // 1. Tool
334
+ api.registerTool({
335
+ name: "overlay",
336
+ description: "Access the BSV agent marketplace",
337
+ parameters: {
338
+ type: "object",
339
+ properties: {
340
+ action: { type: "string", enum: ["request", "discover", "balance", "status", "pay", "onboard", "pending-requests", "fulfill", "unregister"] },
341
+ service: { type: "string" },
342
+ input: { type: "object" },
343
+ identityKey: { type: "string" },
344
+ sats: { type: "number" },
345
+ requestId: { type: "string" },
346
+ recipientKey: { type: "string" },
347
+ serviceId: { type: "string" },
348
+ result: { type: "object" }
349
+ },
350
+ required: ["action"]
337
351
  },
338
- required: ["action"]
339
- },
340
- async execute(_id: string, params: any) {
341
- try {
342
- return await executeOverlayAction(params, pluginConfig, api);
343
- } catch (error: any) {
344
- return { content: [{ type: "text", text: `Error: ${error.message}` }] };
352
+ async execute(_id: string, params: any) {
353
+ try {
354
+ return await executeOverlayAction(params, pluginConfig, api);
355
+ } catch (error: any) {
356
+ return { content: [{ type: "text", text: `Error: ${error.message}` }] };
357
+ }
345
358
  }
346
- }
347
- });
348
-
349
- // 2. Command
350
- api.registerCommand({
351
- name: "overlay",
352
- description: "BSV Overlay Marketplace commands",
353
- acceptsArgs: true,
354
- requireAuth: true,
355
- handler: async (ctx: any) => {
356
- try {
357
- const action = ctx.args?.[0] || 'status';
359
+ });
358
360
 
359
- if (action === 'help') {
360
- 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)` };
361
- }
361
+ // 2. Command
362
+ api.registerCommand({
363
+ name: "overlay",
364
+ description: "BSV Overlay Marketplace commands",
365
+ acceptsArgs: true,
366
+ requireAuth: true,
367
+ handler: async (ctx: any) => {
368
+ try {
369
+ const action = ctx.args?.[0] || 'status';
362
370
 
363
- const result = await executeOverlayAction({ action }, pluginConfig, api);
364
- return { text: `**Overlay ${action.toUpperCase()}**\n\n${typeof result === 'string' ? result : JSON.stringify(result, null, 2)}` };
365
- } catch (error: any) {
366
- return { text: `❌ Error: ${error.message}` };
371
+ if (action === 'help') {
372
+ 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)` };
373
+ }
374
+
375
+ const result = await executeOverlayAction({ action }, pluginConfig, api);
376
+ return { text: `**Overlay ${action.toUpperCase()}**\n\n${typeof result === 'string' ? result : JSON.stringify(result, null, 2)}` };
377
+ } catch (error: any) {
378
+ return { text: `❌ Error: ${error.message}` };
379
+ }
367
380
  }
368
- }
369
- });
370
-
371
- // 3. Service
372
- api.registerService({
373
- id: "openclaw-overlay-relay",
374
- start: async () => {
375
- const env = buildEnvironment(pluginConfig);
376
- const cliPath = getCliPath();
377
- startBackgroundService(env, cliPath, api.logger);
378
- startAutoImport(env, cliPath, api.logger);
379
- },
380
- stop: () => stopBackgroundService()
381
- });
382
-
383
- // 4. CLI
384
- api.registerCli(({ program }: any) => {
385
- const overlay = program.command("overlay").description("BSV Overlay Network management");
386
- overlay.command("status").action(async () => {
387
- await ensureCp();
388
- const result = await handleStatus(buildEnvironment(pluginConfig), getCliPath());
389
- console.log(JSON.stringify(result, null, 2));
390
381
  });
391
- overlay.command("balance").action(async () => {
392
- await ensureCp();
393
- const result = await handleBalance(buildEnvironment(pluginConfig), getCliPath());
394
- console.log(JSON.stringify(result, null, 2));
382
+
383
+ // 3. Service
384
+ api.registerService({
385
+ id: "openclaw-overlay-relay",
386
+ start: async () => {
387
+ const env = buildEnvironment(pluginConfig);
388
+ const cliPath = getCliPath();
389
+ startBackgroundService(env, cliPath, api.logger);
390
+ startAutoImport(env, cliPath, api.logger);
391
+ },
392
+ stop: () => stopBackgroundService()
395
393
  });
396
- }, { descriptors: [{ name: "overlay", description: "BSV Overlay Network management" }] });
397
- }
394
+
395
+ // 4. CLI
396
+ api.registerCli(({ program }: any) => {
397
+ const overlay = program.command("overlay").description("BSV Overlay Network management");
398
+ overlay.command("status").action(async () => {
399
+ await ensureCp();
400
+ const result = await handleStatus(buildEnvironment(pluginConfig), getCliPath());
401
+ console.log(JSON.stringify(result, null, 2));
402
+ });
403
+ overlay.command("balance").action(async () => {
404
+ await ensureCp();
405
+ const result = await handleBalance(buildEnvironment(pluginConfig), getCliPath());
406
+ console.log(JSON.stringify(result, null, 2));
407
+ });
408
+ }, { descriptors: [{ name: "overlay", description: "BSV Overlay Network management" }] });
409
+ }
410
+ };
411
+
412
+ export default plugin;
398
413
 
399
414
  async function executeOverlayAction(params: any, config: any, api: any) {
400
415
  await ensureCp();
@@ -473,7 +488,7 @@ async function handleFulfill(params: any, env: any, cliPath: string) {
473
488
  }
474
489
 
475
490
  function buildEnvironment(config: any) {
476
- const env = { ...(process as any)['en' + 'v'] };
491
+ const env = { ...(process as any)['env'] };
477
492
  env.BSV_WALLET_DIR = config.walletDir || path.join(os.homedir(), '.openclaw', 'bsv-wallet');
478
493
  env.OVERLAY_URL = config.overlayUrl || 'https://clawoverlay.com';
479
494
  env.BSV_NETWORK = env.BSV_NETWORK || 'mainnet';
@@ -2,10 +2,22 @@
2
2
  "id": "openclaw-overlay-plugin",
3
3
  "name": "BSV Overlay Network",
4
4
  "description": "OpenClaw Overlay — decentralized agent marketplace with BSV micropayments",
5
- "version": "0.7.66",
5
+ "version": "0.7.67",
6
6
  "skills": [
7
7
  "./SKILL.md"
8
8
  ],
9
+ "providerAuthEnvVars": {
10
+ "OVERLAY_URL": "Overlay server URL (defaults to https://clawoverlay.com)",
11
+ "BSV_NETWORK": "BSV network to use (mainnet/testnet)",
12
+ "BSV_WALLET_DIR": "Path to the shared BSV wallet directory"
13
+ },
14
+ "providerAuthChoices": [
15
+ {
16
+ "id": "standard-wallet",
17
+ "label": "Standard BSV Wallet (~/.openclaw/bsv-wallet)",
18
+ "description": "Uses the default shared agent identity key"
19
+ }
20
+ ],
9
21
  "commands": [
10
22
  {
11
23
  "name": "overlay",
@@ -23,56 +35,8 @@
23
35
  },
24
36
  "configSchema": {
25
37
  "type": "object",
26
- "additionalProperties": true,
38
+ "additionalProperties": false,
27
39
  "properties": {
28
- "enabled": {
29
- "type": "boolean"
30
- },
31
- "config": {
32
- "type": "object",
33
- "additionalProperties": true,
34
- "properties": {
35
- "overlayUrl": {
36
- "type": "string"
37
- },
38
- "network": {
39
- "type": "string"
40
- },
41
- "chaintracksUrl": {
42
- "type": "string"
43
- },
44
- "arcUrl": {
45
- "type": "string"
46
- },
47
- "agentName": {
48
- "type": "string"
49
- },
50
- "agentDescription": {
51
- "type": "string"
52
- },
53
- "walletDir": {
54
- "type": "string"
55
- },
56
- "maxAutoPaySats": {
57
- "type": "number"
58
- },
59
- "dailyBudgetSats": {
60
- "type": "number"
61
- },
62
- "autoAcceptPayments": {
63
- "type": "boolean"
64
- },
65
- "preferCheapest": {
66
- "type": "boolean"
67
- },
68
- "services": {
69
- "type": "array",
70
- "items": {
71
- "type": "string"
72
- }
73
- }
74
- }
75
- },
76
40
  "overlayUrl": {
77
41
  "type": "string",
78
42
  "default": "https://clawoverlay.com",
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "openclaw-overlay-plugin",
3
- "version": "0.7.66",
3
+ "version": "0.7.68",
4
4
  "description": "Openclaw BSV Overlay — agent discovery, service marketplace, and micropayments on the BSV blockchain",
5
5
  "publishConfig": {
6
6
  "access": "public"
@@ -27,9 +27,9 @@
27
27
  "dependencies": {
28
28
  "@bsv/sdk": "^2.0.13",
29
29
  "@bsv/wallet-toolbox": "^2.1.17",
30
- "sqlite3": "^6.0.1",
31
30
  "dotenv": "^17.3.1",
32
- "knex": "^3.2.8"
31
+ "knex": "^3.2.8",
32
+ "sqlite3": "^5.1.7"
33
33
  },
34
34
  "devDependencies": {
35
35
  "@types/node": "^25.5.0",
@@ -3,7 +3,7 @@
3
3
  */
4
4
 
5
5
  import sqlite3 from 'sqlite3';
6
- import register from '../index.js';
6
+ import { plugin } from '../index.js';
7
7
 
8
8
  async function testCompatibility() {
9
9
  console.log('--- Overlay Compatibility Test ---');
@@ -37,7 +37,7 @@ async function testCompatibility() {
37
37
  };
38
38
 
39
39
  try {
40
- register(mockApi);
40
+ plugin.register(mockApi);
41
41
  if (registeredCli && hasDescriptors) {
42
42
  console.log('✓ CLI descriptors registered correctly for Phase 1 discovery.');
43
43
  } else {