@clawlabz/clawnetwork 0.1.17 → 0.1.19
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/index.ts +52 -40
- package/openclaw.plugin.json +1 -1
- package/package.json +1 -1
package/index.ts
CHANGED
|
@@ -7,7 +7,7 @@ declare function setInterval(fn: () => void, ms: number): unknown
|
|
|
7
7
|
declare function clearInterval(id: unknown): void
|
|
8
8
|
declare function fetch(url: string, init?: Record<string, unknown>): Promise<{ status: number; ok: boolean; text: () => Promise<string>; json: () => Promise<unknown> }>
|
|
9
9
|
|
|
10
|
-
const VERSION = '0.1.
|
|
10
|
+
const VERSION = '0.1.19'
|
|
11
11
|
const PLUGIN_ID = 'clawnetwork'
|
|
12
12
|
const GITHUB_REPO = 'clawlabz/claw-network'
|
|
13
13
|
const DEFAULT_RPC_PORT = 9710
|
|
@@ -1466,12 +1466,12 @@ const fs = require('fs');
|
|
|
1466
1466
|
const os = require('os');
|
|
1467
1467
|
const path = require('path');
|
|
1468
1468
|
|
|
1469
|
-
// OPENCLAW_BASE_DIR and PLUGIN_VERSION are injected by startUiServer()
|
|
1470
|
-
//
|
|
1471
|
-
|
|
1472
|
-
|
|
1473
|
-
const OC_WORKSPACE = path.join(
|
|
1474
|
-
const OC_BIN_DIR = path.join(
|
|
1469
|
+
// OPENCLAW_BASE_DIR and PLUGIN_VERSION are injected as const by startUiServer() prepend.
|
|
1470
|
+
// Use global lookup to avoid const/var redeclaration conflict.
|
|
1471
|
+
const _BASE = (typeof OPENCLAW_BASE_DIR !== 'undefined') ? OPENCLAW_BASE_DIR : path.join(os.homedir(), '.openclaw');
|
|
1472
|
+
const _PVER = (typeof PLUGIN_VERSION !== 'undefined') ? PLUGIN_VERSION : 'unknown';
|
|
1473
|
+
const OC_WORKSPACE = path.join(_BASE, 'workspace', 'clawnetwork');
|
|
1474
|
+
const OC_BIN_DIR = path.join(_BASE, 'bin');
|
|
1475
1475
|
const OC_WALLET_PATH = path.join(OC_WORKSPACE, 'wallet.json');
|
|
1476
1476
|
const OC_PID_FILE = path.join(OC_WORKSPACE, 'node.pid');
|
|
1477
1477
|
const OC_CONFIG_PATH = path.join(OC_WORKSPACE, 'config.json');
|
|
@@ -1481,7 +1481,7 @@ const OC_LOG_PATH_DEFAULT = path.join(OC_WORKSPACE, 'node.log');
|
|
|
1481
1481
|
const PORT = parseInt(process.argv[2] || '19877', 10);
|
|
1482
1482
|
const RPC_PORT = parseInt(process.argv[3] || '9710', 10);
|
|
1483
1483
|
const LOG_PATH = process.argv[4] || OC_LOG_PATH_DEFAULT;
|
|
1484
|
-
const PORT_FILE = path.join(
|
|
1484
|
+
const PORT_FILE = path.join(_BASE, 'clawnetwork-ui-port');
|
|
1485
1485
|
const MAX_RETRIES = 10;
|
|
1486
1486
|
|
|
1487
1487
|
async function fetchJson(url) {
|
|
@@ -1583,7 +1583,7 @@ async function handle(req, res) {
|
|
|
1583
1583
|
rpcUrl: 'http://localhost:' + RPC_PORT,
|
|
1584
1584
|
walletAddress,
|
|
1585
1585
|
binaryVersion: h.version,
|
|
1586
|
-
pluginVersion:
|
|
1586
|
+
pluginVersion: _PVER,
|
|
1587
1587
|
uptime: h.uptime_secs,
|
|
1588
1588
|
uptimeFormatted: h.uptime_secs < 60 ? h.uptime_secs + 's' : h.uptime_secs < 3600 ? Math.floor(h.uptime_secs/60) + 'm' : Math.floor(h.uptime_secs/3600) + 'h ' + Math.floor((h.uptime_secs%3600)/60) + 'm',
|
|
1589
1589
|
restartCount: 0, dataDir: path.join(os.homedir(), '.clawnetwork'), balance, agentName, syncing: h.status === 'degraded', peerless: h.peer_count === 0, lastBlockAgeSecs: h.last_block_age_secs,
|
|
@@ -1591,7 +1591,7 @@ async function handle(req, res) {
|
|
|
1591
1591
|
});
|
|
1592
1592
|
} catch {
|
|
1593
1593
|
const walletAddr = (() => { try { return JSON.parse(fs.readFileSync(OC_WALLET_PATH, 'utf8')).address; } catch { return ''; } })();
|
|
1594
|
-
json(200, { running: false, blockHeight: null, peerCount: null, walletAddress: walletAddr, network: 'mainnet', syncMode: 'light', rpcUrl: 'http://localhost:' + RPC_PORT, pluginVersion:
|
|
1594
|
+
json(200, { running: false, blockHeight: null, peerCount: null, walletAddress: walletAddr, network: 'mainnet', syncMode: 'light', rpcUrl: 'http://localhost:' + RPC_PORT, pluginVersion: _PVER, restartCount: 0, dataDir: path.join(os.homedir(), '.clawnetwork'), balance: '', agentName: '', syncing: false, uptimeFormatted: '—', pid: null, upgradeLevel: 'unknown', latestVersion: '', releaseUrl: '', changelog: '', announcement: null });
|
|
1595
1595
|
}
|
|
1596
1596
|
return;
|
|
1597
1597
|
}
|
|
@@ -2422,40 +2422,52 @@ export default function register(api: OpenClawApi) {
|
|
|
2422
2422
|
if (state.running) {
|
|
2423
2423
|
api.logger?.info?.(`[clawnetwork] node already running (pid=${state.pid})`)
|
|
2424
2424
|
|
|
2425
|
-
// Check if
|
|
2426
|
-
if
|
|
2425
|
+
// Check if local binary is newer than the running process — restart if so.
|
|
2426
|
+
// Also check GitHub for even newer versions and download if available.
|
|
2427
|
+
try {
|
|
2428
|
+
const binary = findBinary()
|
|
2429
|
+
const localBinaryVersion = binary ? getBinaryVersion(binary) : null
|
|
2430
|
+
|
|
2431
|
+
// Get the RUNNING process version from health endpoint (not the file version)
|
|
2432
|
+
let runningProcessVersion: string | null = null
|
|
2427
2433
|
try {
|
|
2428
|
-
const
|
|
2429
|
-
|
|
2430
|
-
|
|
2431
|
-
|
|
2432
|
-
|
|
2433
|
-
|
|
2434
|
-
|
|
2435
|
-
|
|
2436
|
-
|
|
2437
|
-
|
|
2438
|
-
|
|
2439
|
-
|
|
2440
|
-
|
|
2441
|
-
|
|
2442
|
-
|
|
2443
|
-
|
|
2444
|
-
|
|
2445
|
-
|
|
2446
|
-
|
|
2447
|
-
initNode(newBinary, cfg.network, api)
|
|
2448
|
-
startNodeProcess(newBinary, cfg, api)
|
|
2449
|
-
api.logger?.info?.(`[clawnetwork] node upgraded to ${latestVersion} and restarted`)
|
|
2450
|
-
} catch (e: unknown) {
|
|
2451
|
-
api.logger?.warn?.(`[clawnetwork] auto-upgrade failed: ${(e as Error).message}, restarting old binary`)
|
|
2452
|
-
startNodeProcess(binary, cfg, api)
|
|
2434
|
+
const health = await fetch(`http://localhost:${cfg.rpcPort}/health`)
|
|
2435
|
+
if (health.ok) {
|
|
2436
|
+
const hd = await health.json() as Record<string, unknown>
|
|
2437
|
+
if (typeof hd.version === 'string') runningProcessVersion = hd.version.replace(/^v/, '')
|
|
2438
|
+
}
|
|
2439
|
+
} catch { /* health endpoint not ready */ }
|
|
2440
|
+
|
|
2441
|
+
// Step A: If GitHub has a newer binary than what's on disk, download it first
|
|
2442
|
+
if (cfg.autoDownload && localBinaryVersion) {
|
|
2443
|
+
try {
|
|
2444
|
+
const res = await fetch(`https://api.github.com/repos/${GITHUB_REPO}/releases/latest`)
|
|
2445
|
+
if (res.ok) {
|
|
2446
|
+
const data = await res.json() as Record<string, unknown>
|
|
2447
|
+
const latestVersion = typeof data.tag_name === 'string' ? data.tag_name.replace(/^v/, '') : null
|
|
2448
|
+
if (latestVersion && isVersionOlder(localBinaryVersion, latestVersion)) {
|
|
2449
|
+
api.logger?.info?.(`[clawnetwork] downloading newer binary: ${localBinaryVersion} → ${latestVersion}`)
|
|
2450
|
+
try { await downloadBinary(api) } catch (e: unknown) {
|
|
2451
|
+
api.logger?.warn?.(`[clawnetwork] download failed: ${(e as Error).message}`)
|
|
2452
|
+
}
|
|
2453
2453
|
}
|
|
2454
2454
|
}
|
|
2455
|
-
}
|
|
2456
|
-
}
|
|
2457
|
-
|
|
2455
|
+
} catch { /* network error, skip */ }
|
|
2456
|
+
}
|
|
2457
|
+
|
|
2458
|
+
// Step B: If the local binary is newer than the running process, restart with it
|
|
2459
|
+
const finalBinary = findBinary()
|
|
2460
|
+
const finalBinaryVersion = finalBinary ? getBinaryVersion(finalBinary) : null
|
|
2461
|
+
if (finalBinaryVersion && runningProcessVersion && isVersionOlder(runningProcessVersion, finalBinaryVersion)) {
|
|
2462
|
+
api.logger?.info?.(`[clawnetwork] running node ${runningProcessVersion} is outdated, restarting with ${finalBinaryVersion}...`)
|
|
2463
|
+
stopNode(api)
|
|
2464
|
+
await sleep(3_000)
|
|
2465
|
+
initNode(finalBinary, cfg.network, api)
|
|
2466
|
+
startNodeProcess(finalBinary, cfg, api)
|
|
2467
|
+
api.logger?.info?.(`[clawnetwork] node upgraded to ${finalBinaryVersion}`)
|
|
2458
2468
|
}
|
|
2469
|
+
} catch (e: unknown) {
|
|
2470
|
+
api.logger?.warn?.(`[clawnetwork] upgrade check failed: ${(e as Error).message}`)
|
|
2459
2471
|
}
|
|
2460
2472
|
|
|
2461
2473
|
startHealthCheck(cfg, api)
|
package/openclaw.plugin.json
CHANGED