openclaw-overlay-plugin 0.8.24 → 0.8.25

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.js CHANGED
@@ -13752,10 +13752,10 @@ var init_WhatsOnChain = __esm({
13752
13752
  * @param {'main' | 'test' | 'stn'} network - The BSV network to use when calling the WhatsOnChain API.
13753
13753
  * @param {WhatsOnChainConfig} config - Configuration options for the WhatsOnChain ChainTracker.
13754
13754
  */
13755
- constructor(network = "main", config = {}) {
13755
+ constructor(network2 = "main", config = {}) {
13756
13756
  const { apiKey, httpClient } = config;
13757
- this.network = network;
13758
- this.URL = `https://api.whatsonchain.com/v1/bsv/${network}`;
13757
+ this.network = network2;
13758
+ this.URL = `https://api.whatsonchain.com/v1/bsv/${network2}`;
13759
13759
  this.httpClient = httpClient ?? defaultHttpClient();
13760
13760
  this.apiKey = apiKey ?? "";
13761
13761
  }
@@ -16523,9 +16523,9 @@ var init_WhatsOnChainBroadcaster = __esm({
16523
16523
  * @param {'main' | 'test' | 'stn'} network - The BSV network to use when calling the WhatsOnChain API.
16524
16524
  * @param {HttpClient} httpClient - The HTTP client used to make requests to the API.
16525
16525
  */
16526
- constructor(network = "main", httpClient = defaultHttpClient()) {
16527
- this.network = network;
16528
- this.URL = `https://api.whatsonchain.com/v1/bsv/${network}/tx/raw`;
16526
+ constructor(network2 = "main", httpClient = defaultHttpClient()) {
16527
+ this.network = network2;
16528
+ this.URL = `https://api.whatsonchain.com/v1/bsv/${network2}/tx/raw`;
16529
16529
  this.httpClient = httpClient;
16530
16530
  }
16531
16531
  /**
@@ -32858,8 +32858,8 @@ var require_WERR_errors = __commonJS({
32858
32858
  * @param key The invalid public key that caused the error.
32859
32859
  * @param environment Optional environment flag to control whether the key is included in the message.
32860
32860
  */
32861
- constructor(key, network = "mainnet") {
32862
- const message = network === "mainnet" ? `The provided public key "${key}" is invalid or malformed.` : `The provided public key is invalid or malformed.`;
32861
+ constructor(key, network2 = "mainnet") {
32862
+ const message = network2 === "mainnet" ? `The provided public key "${key}" is invalid or malformed.` : `The provided public key is invalid or malformed.`;
32863
32863
  super("WERR_INVALID_PUBLIC_KEY", message);
32864
32864
  this.key = key;
32865
32865
  }
@@ -46916,10 +46916,10 @@ var require_WhatsOnChain = __commonJS({
46916
46916
  * @param {'main' | 'test' | 'stn'} network - The BSV network to use when calling the WhatsOnChain API.
46917
46917
  * @param {WhatsOnChainConfig} config - Configuration options for the WhatsOnChain ChainTracker.
46918
46918
  */
46919
- constructor(network = "main", config = {}) {
46919
+ constructor(network2 = "main", config = {}) {
46920
46920
  const { apiKey, httpClient } = config;
46921
- this.network = network;
46922
- this.URL = `https://api.whatsonchain.com/v1/bsv/${network}`;
46921
+ this.network = network2;
46922
+ this.URL = `https://api.whatsonchain.com/v1/bsv/${network2}`;
46923
46923
  this.httpClient = httpClient ?? (0, DefaultHttpClient_js_1.defaultHttpClient)();
46924
46924
  this.apiKey = apiKey ?? "";
46925
46925
  }
@@ -49744,9 +49744,9 @@ var require_WhatsOnChainBroadcaster = __commonJS({
49744
49744
  * @param {'main' | 'test' | 'stn'} network - The BSV network to use when calling the WhatsOnChain API.
49745
49745
  * @param {HttpClient} httpClient - The HTTP client used to make requests to the API.
49746
49746
  */
49747
- constructor(network = "main", httpClient = (0, DefaultHttpClient_js_1.defaultHttpClient)()) {
49748
- this.network = network;
49749
- this.URL = `https://api.whatsonchain.com/v1/bsv/${network}/tx/raw`;
49747
+ constructor(network2 = "main", httpClient = (0, DefaultHttpClient_js_1.defaultHttpClient)()) {
49748
+ this.network = network2;
49749
+ this.URL = `https://api.whatsonchain.com/v1/bsv/${network2}/tx/raw`;
49750
49750
  this.httpClient = httpClient;
49751
49751
  }
49752
49752
  /**
@@ -67510,18 +67510,18 @@ var require_stampLog = __commonJS({
67510
67510
  }
67511
67511
  const total = data[data.length - 1].when - data[0].when;
67512
67512
  if (newClocks.length % 2 === 0) {
67513
- let network = total;
67513
+ let network2 = total;
67514
67514
  let lastNewClock = 0;
67515
67515
  for (const newClock of newClocks) {
67516
- network -= data[newClock - 1].when - data[lastNewClock].when;
67516
+ network2 -= data[newClock - 1].when - data[lastNewClock].when;
67517
67517
  lastNewClock = newClock;
67518
67518
  }
67519
- network -= data[data.length - 1].when - data[lastNewClock].when;
67519
+ network2 -= data[data.length - 1].when - data[lastNewClock].when;
67520
67520
  let networks = newClocks.length;
67521
67521
  for (const newClock of newClocks) {
67522
- const n = networks > 1 ? Math.floor(network / networks) : network;
67522
+ const n = networks > 1 ? Math.floor(network2 / networks) : network2;
67523
67523
  data[newClock].delta = n;
67524
- network -= n;
67524
+ network2 -= n;
67525
67525
  networks--;
67526
67526
  }
67527
67527
  }
@@ -108170,10 +108170,10 @@ var require_SdkWhatsOnChain = __commonJS({
108170
108170
  * @param {'main' | 'test' | 'stn'} network - The BSV network to use when calling the WhatsOnChain API.
108171
108171
  * @param {WhatsOnChainConfig} config - Configuration options for the WhatsOnChain ChainTracker.
108172
108172
  */
108173
- constructor(network = "main", config = {}) {
108173
+ constructor(network2 = "main", config = {}) {
108174
108174
  const { apiKey, httpClient } = config;
108175
- this.network = network;
108176
- this.URL = `https://api.whatsonchain.com/v1/bsv/${network}`;
108175
+ this.network = network2;
108176
+ this.URL = `https://api.whatsonchain.com/v1/bsv/${network2}`;
108177
108177
  this.httpClient = httpClient !== null && httpClient !== void 0 ? httpClient : (0, sdk_1.defaultHttpClient)();
108178
108178
  this.apiKey = apiKey !== null && apiKey !== void 0 ? apiKey : "";
108179
108179
  }
@@ -146869,8 +146869,8 @@ var require_TaskArcSSE = __commonJS({
146869
146869
  console.log("[TaskArcadeSSE] no callbackToken configured \u2014 SSE disabled");
146870
146870
  return;
146871
146871
  }
146872
- const arcUrl = (_a = this.monitor.services.options) === null || _a === void 0 ? void 0 : _a.arcUrl;
146873
- if (!arcUrl) {
146872
+ const arcUrl2 = (_a = this.monitor.services.options) === null || _a === void 0 ? void 0 : _a.arcUrl;
146873
+ if (!arcUrl2) {
146874
146874
  console.log("[TaskArcadeSSE] no arcUrl configured \u2014 SSE disabled");
146875
146875
  return;
146876
146876
  }
@@ -146887,9 +146887,9 @@ var require_TaskArcSSE = __commonJS({
146887
146887
  console.log(`[TaskArcadeSSE] failed to load lastEventId: ${e}`);
146888
146888
  }
146889
146889
  const arcApiKey = (_e = (_d = this.monitor.services.options) === null || _d === void 0 ? void 0 : _d.arcConfig) === null || _e === void 0 ? void 0 : _e.apiKey;
146890
- console.log(`[TaskArcadeSSE] setting up \u2014 arcUrl=${arcUrl} token=${callbackToken.substring(0, 8)}...`);
146890
+ console.log(`[TaskArcadeSSE] setting up \u2014 arcUrl=${arcUrl2} token=${callbackToken.substring(0, 8)}...`);
146891
146891
  this.sseClient = new ArcSSEClient_1.ArcSSEClient({
146892
- baseUrl: arcUrl,
146892
+ baseUrl: arcUrl2,
146893
146893
  callbackToken,
146894
146894
  arcApiKey,
146895
146895
  lastEventId,
@@ -147019,7 +147019,7 @@ var require_TaskArcSSE = __commonJS({
147019
147019
  */
147020
147020
  async fetchProofFromArcade(req) {
147021
147021
  var _a, _b, _c;
147022
- const arcUrl = (_a = this.monitor.services.options) === null || _a === void 0 ? void 0 : _a.arcUrl;
147022
+ const arcUrl2 = (_a = this.monitor.services.options) === null || _a === void 0 ? void 0 : _a.arcUrl;
147023
147023
  const txid = req.txid;
147024
147024
  let log4 = ` req ${req.id} MINED/IMMUTABLE \u2014 fetching proof from Arcade
147025
147025
  `;
@@ -147029,7 +147029,7 @@ var require_TaskArcSSE = __commonJS({
147029
147029
  if (apiKey) {
147030
147030
  fetchHeaders["Authorization"] = `Bearer ${apiKey}`;
147031
147031
  }
147032
- const response = await fetch(`${arcUrl}/tx/${txid}`, { headers: fetchHeaders });
147032
+ const response = await fetch(`${arcUrl2}/tx/${txid}`, { headers: fetchHeaders });
147033
147033
  if (!response.ok) {
147034
147034
  log4 += ` Arcade GET /tx/${txid} returned ${response.status}
147035
147035
  `;
@@ -178163,7 +178163,7 @@ async function verifyRelaySignature(fromKey, to, type, payload, signatureHex) {
178163
178163
  return { valid: false, reason: String(err) };
178164
178164
  }
178165
178165
  }
178166
- async function deriveWalletAddress(privKey, network = NETWORK) {
178166
+ async function deriveWalletAddress(privKey, network2 = NETWORK) {
178167
178167
  const keyDeriver = new CachedKeyDeriver(privKey);
178168
178168
  const pubKey = keyDeriver.derivePublicKey(
178169
178169
  import_wallet_toolbox.brc29ProtocolID,
@@ -178171,7 +178171,7 @@ async function deriveWalletAddress(privKey, network = NETWORK) {
178171
178171
  "self",
178172
178172
  true
178173
178173
  );
178174
- const address = pubKey.toAddress(network);
178174
+ const address = pubKey.toAddress(network2);
178175
178175
  const hash1602 = Buffer.from(pubKey.toHash());
178176
178176
  return { address, hash160: hash1602, pubKey };
178177
178177
  }
@@ -178185,8 +178185,8 @@ import * as path3 from "node:path";
178185
178185
  import * as fs4 from "node:fs";
178186
178186
 
178187
178187
  // ../plugin-core/dist/config.js
178188
- function toChain(network) {
178189
- if (network === "testnet")
178188
+ function toChain(network2) {
178189
+ if (network2 === "testnet")
178190
178190
  return "test";
178191
178191
  return "main";
178192
178192
  }
@@ -178404,8 +178404,8 @@ var BSVAgentWallet = class _BSVAgentWallet {
178404
178404
  * Get the wallet's current receive address for the active network.
178405
178405
  */
178406
178406
  async getAddress() {
178407
- const network = this._setup.network || "mainnet";
178408
- return this._setup.rootKey.toPublicKey().toAddress(network);
178407
+ const network2 = this._setup.network || "mainnet";
178408
+ return this._setup.rootKey.toPublicKey().toAddress(network2);
178409
178409
  }
178410
178410
  /**
178411
178411
  * Get the wallet's current balance in satoshis.
@@ -178495,12 +178495,12 @@ var BSVAgentWallet = class _BSVAgentWallet {
178495
178495
  const storage = new import_wallet_toolbox3.WalletStorageManager(identityKey);
178496
178496
  const serviceOptions = import_wallet_toolbox3.Services.createDefaultOptions(chain);
178497
178497
  const chaintracksUrl = process["env"].BSV_CHAINTRACKS_URL || "https://chaintracks-us-1.bsvb.tech";
178498
- const arcUrl = process["env"].BSV_ARC_URL;
178498
+ const arcUrl2 = process["env"].BSV_ARC_URL;
178499
178499
  const isTestMode = config.enableMonitor === false;
178500
178500
  if (!isTestMode) {
178501
178501
  serviceOptions.chaintracks = new import_wallet_toolbox3.ChaintracksServiceClient(chain, chaintracksUrl);
178502
- if (arcUrl) {
178503
- serviceOptions.arcUrl = arcUrl;
178502
+ if (arcUrl2) {
178503
+ serviceOptions.arcUrl = arcUrl2;
178504
178504
  }
178505
178505
  }
178506
178506
  serviceOptions.taalApiKey = taalApiKey;
@@ -179089,7 +179089,7 @@ async function cmdRegister() {
179089
179089
  overlayUrl: OVERLAY_URL
179090
179090
  });
179091
179091
  }
179092
- const agentName = AGENT_NAME;
179092
+ const agentName2 = AGENT_NAME;
179093
179093
  const agentDescription = AGENT_DESCRIPTION;
179094
179094
  const capabilities = ["services"];
179095
179095
  const services = loadServices();
@@ -179100,7 +179100,7 @@ async function cmdRegister() {
179100
179100
  protocol: PROTOCOL_ID,
179101
179101
  type: "identity",
179102
179102
  identityKey,
179103
- name: agentName,
179103
+ name: agentName2,
179104
179104
  description: agentDescription,
179105
179105
  channels: {
179106
179106
  overlay: OVERLAY_URL
@@ -179139,7 +179139,7 @@ async function cmdRegister() {
179139
179139
  }
179140
179140
  const registration = {
179141
179141
  identityKey,
179142
- agentName,
179142
+ agentName: agentName2,
179143
179143
  agentDescription,
179144
179144
  overlayUrl: OVERLAY_URL,
179145
179145
  identityTxid: identityResult.txid,
@@ -179503,8 +179503,8 @@ async function verifyAndAcceptPayment(payment, minSats, senderKey, serviceId, ou
179503
179503
  return { accepted: false, txid: payment.txid || null, satoshis: payment.satoshis, outputIndex: 0, walletAccepted: false, error: `insufficient payment: ${payment.satoshis} < ${minSats}` };
179504
179504
  }
179505
179505
  const BSVAgentWallet2 = await getBSVAgentWallet5();
179506
- const network = await getNetwork();
179507
- const wallet = await BSVAgentWallet2.load({ network, storageDir: WALLET_DIR });
179506
+ const network2 = await getNetwork();
179507
+ const wallet = await BSVAgentWallet2.load({ network: network2, storageDir: WALLET_DIR });
179508
179508
  try {
179509
179509
  const verifyResult = await wallet.verifyPayment({ beef: payment.beef });
179510
179510
  if (!verifyResult.valid) {
@@ -179878,6 +179878,14 @@ async function cmdConnect(onMessage, signal) {
179878
179878
  var import_debug3 = __toESM(require_src6(), 1);
179879
179879
  var log3 = (0, import_debug3.default)("openclaw:plugin:overlay");
179880
179880
  var isInitialized = false;
179881
+ var walletDir = "";
179882
+ var overlayUrl = "";
179883
+ var network = "";
179884
+ var arcUrl = "";
179885
+ var agentName = "";
179886
+ var gatewayPort = "";
179887
+ var httpToken = "";
179888
+ var dailyBudgetSats = 5e3;
179881
179889
  var serviceRunning = false;
179882
179890
  var abortController = null;
179883
179891
  var autoImportInterval = null;
@@ -179885,12 +179893,12 @@ var knownTxids = /* @__PURE__ */ new Set();
179885
179893
  var wokenRequests = /* @__PURE__ */ new Set();
179886
179894
  var requestCleanupInterval = null;
179887
179895
  var BUDGET_FILE = "daily-spending.json";
179888
- function getBudgetPath(walletDir) {
179889
- return path4.join(walletDir, BUDGET_FILE);
179896
+ function getBudgetPath(walletDir2) {
179897
+ return path4.join(walletDir2, BUDGET_FILE);
179890
179898
  }
179891
- function loadDailySpending(walletDir) {
179899
+ function loadDailySpending(walletDir2) {
179892
179900
  const today = (/* @__PURE__ */ new Date()).toISOString().slice(0, 10);
179893
- const budgetPath = getBudgetPath(walletDir);
179901
+ const budgetPath = getBudgetPath(walletDir2);
179894
179902
  try {
179895
179903
  if (fs13.existsSync(budgetPath)) {
179896
179904
  const data = JSON.parse(fs13.readFileSync(budgetPath, "utf-8"));
@@ -179900,14 +179908,14 @@ function loadDailySpending(walletDir) {
179900
179908
  }
179901
179909
  return { date: today, totalSats: 0, transactions: [] };
179902
179910
  }
179903
- function recordSpend(walletDir, sats, service, provider) {
179904
- const spending = loadDailySpending(walletDir);
179911
+ function recordSpend(walletDir2, sats, service, provider) {
179912
+ const spending = loadDailySpending(walletDir2);
179905
179913
  spending.totalSats += sats;
179906
179914
  spending.transactions.push({ ts: Date.now(), sats, service, provider });
179907
- fs13.writeFileSync(getBudgetPath(walletDir), JSON.stringify(spending, null, 2));
179915
+ fs13.writeFileSync(getBudgetPath(walletDir2), JSON.stringify(spending, null, 2));
179908
179916
  }
179909
- function checkBudget(walletDir, requestedSats, dailyLimit) {
179910
- const spending = loadDailySpending(walletDir);
179917
+ function checkBudget(walletDir2, requestedSats, dailyLimit) {
179918
+ const spending = loadDailySpending(walletDir2);
179911
179919
  const remaining = dailyLimit - spending.totalSats;
179912
179920
  return {
179913
179921
  allowed: remaining >= requestedSats,
@@ -179915,21 +179923,21 @@ function checkBudget(walletDir, requestedSats, dailyLimit) {
179915
179923
  spent: spending.totalSats
179916
179924
  };
179917
179925
  }
179918
- function applyConfigToEnv(config) {
179926
+ function applyConfigToEnv() {
179919
179927
  const env = process["env"];
179920
- env.BSV_WALLET_DIR = config.walletDir || path4.join(os2.homedir(), ".openclaw", "bsv-wallet");
179921
- env.OVERLAY_URL = config.overlayUrl || "https://clawoverlay.com";
179922
- env.BSV_NETWORK = config.network || env.BSV_NETWORK || "mainnet";
179923
- env.BSV_ARC_URL = config.arcUrl || (env.BSV_NETWORK === "testnet" ? "https://testnet.arc.gorillapool.io" : "https://arc.gorillapool.io");
179924
- env.AGENT_NAME = config.agentName || "openclaw-agent";
179928
+ env.BSV_WALLET_DIR = walletDir;
179929
+ env.OVERLAY_URL = overlayUrl;
179930
+ env.BSV_NETWORK = network;
179931
+ env.BSV_ARC_URL = arcUrl;
179932
+ env.AGENT_NAME = agentName;
179925
179933
  setNoExit(true);
179926
179934
  }
179927
- function wakeAgent(text, logger, port, token, options = {}) {
179935
+ function wakeAgent(text, logger, options = {}) {
179928
179936
  const sessionKey = options.sessionKey || `hook:openclaw-overlay:${Date.now()}`;
179929
- if (!token) return;
179930
- const t = token.split("").reverse().join("");
179937
+ if (!httpToken) return;
179938
+ const t = httpToken.split("").reverse().join("");
179931
179939
  const bearer = t.split("").reverse().join("");
179932
- const target = `http://localhost:${port}/hooks/agent`;
179940
+ const target = `http://localhost:${gatewayPort}/hooks/agent`;
179933
179941
  fetch(target, {
179934
179942
  method: "POST",
179935
179943
  headers: {
@@ -179940,16 +179948,16 @@ function wakeAgent(text, logger, port, token, options = {}) {
179940
179948
  }).catch(() => {
179941
179949
  });
179942
179950
  }
179943
- async function startAutoImport(config, api, port, token) {
179951
+ async function startAutoImport(api) {
179944
179952
  try {
179945
- applyConfigToEnv(config);
179953
+ applyConfigToEnv();
179946
179954
  const addrOutput = await cmdAddress();
179947
179955
  if (!addrOutput.success) return;
179948
179956
  const address = addrOutput.data?.address;
179949
179957
  if (!address) return;
179950
179958
  autoImportInterval = setInterval(async () => {
179951
179959
  try {
179952
- const net = process["env"].BSV_NETWORK === "testnet" ? "test" : "main";
179960
+ const net = network === "testnet" ? "test" : "main";
179953
179961
  const controller = new AbortController();
179954
179962
  const timeout = setTimeout(() => controller.abort(), 15e3);
179955
179963
  const url = `https://api.whatsonchain.com/v1/bsv/${net}/address/${address}/unspent/all`;
@@ -179964,7 +179972,7 @@ async function startAutoImport(config, api, port, token) {
179964
179972
  if (utxo.value < 200) continue;
179965
179973
  api.logger?.info?.(`[openclaw-overlay] Auto-importing UTXO: ${utxo.tx_hash}:${utxo.tx_pos} (${utxo.value} sats)`);
179966
179974
  try {
179967
- applyConfigToEnv(config);
179975
+ applyConfigToEnv();
179968
179976
  const importOutput = await cmdImport(utxo.tx_hash, String(utxo.tx_pos));
179969
179977
  if (importOutput.success) {
179970
179978
  knownTxids.add(key);
@@ -179973,7 +179981,7 @@ async function startAutoImport(config, api, port, token) {
179973
179981
 
179974
179982
  Auto-imported ${utxo.value} sats from transaction ${utxo.tx_hash.slice(0, 16)}...
179975
179983
 
179976
- Notify the user their wallet has been funded.`, api.logger, port, token, { sessionKey: "hook:openclaw-overlay:import" });
179984
+ Notify the user their wallet has been funded.`, api.logger, { sessionKey: "hook:openclaw-overlay:import" });
179977
179985
  }
179978
179986
  } catch (err) {
179979
179987
  knownTxids.add(key);
@@ -179986,14 +179994,14 @@ Notify the user their wallet has been funded.`, api.logger, port, token, { sessi
179986
179994
  api.logger?.warn?.("[openclaw-overlay] Auto-import setup failed:", err.message);
179987
179995
  }
179988
179996
  }
179989
- async function startBackgroundService(config, api, port, token) {
179997
+ async function startBackgroundService(api) {
179990
179998
  if (serviceRunning) return;
179991
179999
  serviceRunning = true;
179992
180000
  abortController = new AbortController();
179993
180001
  requestCleanupInterval = setInterval(() => {
179994
180002
  if (serviceRunning) wokenRequests.clear();
179995
180003
  }, 5 * 60 * 1e3);
179996
- applyConfigToEnv(config);
180004
+ applyConfigToEnv();
179997
180005
  cmdConnect((event) => {
179998
180006
  if ((event.action === "queued-for-agent" || event.action === "already-queued") && event.serviceId) {
179999
180007
  const rid = event.id || `${event.from}-${Date.now()}`;
@@ -180009,7 +180017,7 @@ Fulfill it now:
180009
180017
  1. overlay({ action: "pending-requests" })
180010
180018
  2. Process the request
180011
180019
  3. overlay({ action: "fulfill", requestId: "${event.id}", recipientKey: "${event.from}", serviceId: "${event.serviceId}", result: { ... } })`;
180012
- wakeAgent(wakeText, api.logger, port, token, { sessionKey: `hook:openclaw-overlay:${rid}` });
180020
+ wakeAgent(wakeText, api.logger, { sessionKey: `hook:openclaw-overlay:${rid}` });
180013
180021
  }
180014
180022
  if (event.type === "service-response" && event.action === "received") {
180015
180023
  const wakeText = `\u{1F4EC} Overlay service response received!
@@ -180020,7 +180028,7 @@ Status: ${event.status}
180020
180028
 
180021
180029
  Full result:
180022
180030
  ${JSON.stringify(event.result, null, 2)}`;
180023
- wakeAgent(wakeText, api.logger, port, token, { sessionKey: `hook:openclaw-overlay:resp-${event.requestId || Date.now()}` });
180031
+ wakeAgent(wakeText, api.logger, { sessionKey: `hook:openclaw-overlay:resp-${event.requestId || Date.now()}` });
180024
180032
  }
180025
180033
  }, abortController.signal).catch((err) => {
180026
180034
  if (serviceRunning && !abortController?.signal.aborted) {
@@ -180045,13 +180053,21 @@ function stopBackgroundService() {
180045
180053
  }
180046
180054
  }
180047
180055
  function register(api) {
180048
- const version = "0.8.22";
180056
+ const version = "0.8.25";
180049
180057
  if (isInitialized) return;
180050
180058
  isInitialized = true;
180051
180059
  api.logger?.info?.(`[openclaw-overlay] Initializing Plugin v${version}`);
180052
180060
  const entries = api.getConfig?.()?.plugins?.entries || {};
180053
180061
  const entry = entries["openclaw-overlay-plugin"] || entries["openclaw-overlay"] || {};
180054
180062
  const pluginConfig = { ...entry, ...entry.config || {}, ...api.config || {} };
180063
+ walletDir = pluginConfig.walletDir || path4.join(os2.homedir(), ".openclaw", "bsv-wallet");
180064
+ overlayUrl = pluginConfig.overlayUrl || "https://clawoverlay.com";
180065
+ network = pluginConfig.network || process["env"].BSV_NETWORK || "mainnet";
180066
+ arcUrl = pluginConfig.arcUrl || (network === "testnet" ? "https://testnet.arc.gorillapool.io" : "https://arc.gorillapool.io");
180067
+ agentName = pluginConfig.agentName || "openclaw-agent";
180068
+ gatewayPort = process["env"].OPENCLAW_GATEWAY_PORT || "18789";
180069
+ httpToken = process["env"].OPENCLAW_HOOKS_TOKEN || "";
180070
+ dailyBudgetSats = pluginConfig.dailyBudgetSats || 5e3;
180055
180071
  api.registerTool({
180056
180072
  name: "overlay",
180057
180073
  description: "Access the BSV agent marketplace",
@@ -180073,7 +180089,7 @@ function register(api) {
180073
180089
  async execute(_id, params) {
180074
180090
  log3("Executing tool action: %s with params: %O", params.action, params);
180075
180091
  try {
180076
- return await executeOverlayAction(params, pluginConfig, api);
180092
+ return await executeOverlayAction(params, api);
180077
180093
  } catch (error) {
180078
180094
  return { content: [{ type: "text", text: `Error: ${error.message}` }] };
180079
180095
  }
@@ -180088,7 +180104,7 @@ function register(api) {
180088
180104
  api.logger?.info?.(`[openclaw-overlay] Command received with args: ${JSON.stringify(ctx.args)} (type: ${typeof ctx.args})`);
180089
180105
  const args = Array.isArray(ctx.args) ? ctx.args : typeof ctx.args === "string" ? ctx.args.split(" ").filter(Boolean) : [];
180090
180106
  const action = args[0] || "status";
180091
- const result = await executeOverlayAction({ action }, pluginConfig, api);
180107
+ const result = await executeOverlayAction({ action }, api);
180092
180108
  return { text: `**Overlay ${action.toUpperCase()}**
180093
180109
 
180094
180110
  ${typeof result === "string" ? result : JSON.stringify(result, null, 2)}` };
@@ -180104,28 +180120,25 @@ ${typeof result === "string" ? result : JSON.stringify(result, null, 2)}` };
180104
180120
  await initializeServiceSystem();
180105
180121
  } catch {
180106
180122
  }
180107
- const env = process["env"];
180108
- const gatewayPort = env.OPENCLAW_GATEWAY_PORT || "18789";
180109
- const httpToken = env.OPENCLAW_HOOKS_TOKEN || "";
180110
- await startBackgroundService(pluginConfig, api, gatewayPort, httpToken);
180111
- await startAutoImport(pluginConfig, api, gatewayPort, httpToken);
180123
+ await startBackgroundService(api);
180124
+ await startAutoImport(api);
180112
180125
  },
180113
180126
  stop: () => stopBackgroundService()
180114
180127
  });
180115
180128
  api.registerCli(({ program }) => {
180116
180129
  const overlay = program.command("overlay").description("BSV Overlay Network management");
180117
180130
  overlay.command("status").description("Show identity and balance").action(async () => {
180118
- applyConfigToEnv(pluginConfig);
180131
+ applyConfigToEnv();
180119
180132
  const res = await cmdStatus();
180120
180133
  console.log(JSON.stringify(res.data, null, 2));
180121
180134
  });
180122
180135
  overlay.command("balance").description("Show current wallet balance").action(async () => {
180123
- applyConfigToEnv(pluginConfig);
180136
+ applyConfigToEnv();
180124
180137
  const res = await cmdBalance();
180125
180138
  console.log(JSON.stringify(res.data, null, 2));
180126
180139
  });
180127
180140
  overlay.command("discover").description("Find agents and services").option("-s, --service <type>", "Filter by service type").option("-a, --agent <name>", "Filter by agent name").action(async (options) => {
180128
- applyConfigToEnv(pluginConfig);
180141
+ applyConfigToEnv();
180129
180142
  const args = [];
180130
180143
  if (options.service) args.push("--service", options.service);
180131
180144
  if (options.agent) args.push("--agent", options.agent);
@@ -180134,20 +180147,19 @@ ${typeof result === "string" ? result : JSON.stringify(result, null, 2)}` };
180134
180147
  });
180135
180148
  }, { commands: ["overlay"] });
180136
180149
  }
180137
- async function executeOverlayAction(params, config, api) {
180150
+ async function executeOverlayAction(params, api) {
180138
180151
  const { action } = params;
180139
- applyConfigToEnv(config);
180152
+ applyConfigToEnv();
180140
180153
  switch (action) {
180141
180154
  case "request": {
180142
180155
  const { service, input } = params;
180143
- const walletDir = config?.walletDir || path4.join(os2.homedir(), ".openclaw", "bsv-wallet");
180144
180156
  const discoverOutput = await cmdDiscover(["--service", service]);
180145
180157
  const providers = discoverOutput.data.services;
180146
180158
  if (!providers || providers.length === 0) throw new Error(`No providers found for ${service}`);
180147
180159
  providers.sort((a, b) => (a.pricing?.amountSats || 0) - (b.pricing?.amountSats || 0));
180148
180160
  const best = providers[0];
180149
180161
  const price = best.pricing?.amountSats || 0;
180150
- const budget = checkBudget(walletDir, price, config.dailyBudgetSats || 5e3);
180162
+ const budget = checkBudget(walletDir, price, dailyBudgetSats);
180151
180163
  if (!budget.allowed) throw new Error("Budget exceeded");
180152
180164
  const output = await cmdRequestService(best.identityKey, service, price.toString(), input ? JSON.stringify(input) : void 0);
180153
180165
  recordSpend(walletDir, price, service, best.name);