@clawlabz/clawnetwork 0.1.18 → 0.1.20
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 +47 -32
- 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.20'
|
|
11
11
|
const PLUGIN_ID = 'clawnetwork'
|
|
12
12
|
const GITHUB_REPO = 'clawlabz/claw-network'
|
|
13
13
|
const DEFAULT_RPC_PORT = 9710
|
|
@@ -124,7 +124,10 @@ const fs = require('fs')
|
|
|
124
124
|
const { execFileSync, spawn: nodeSpawn, fork } = require('child_process')
|
|
125
125
|
|
|
126
126
|
function getBaseDir(): string {
|
|
127
|
-
//
|
|
127
|
+
// Gateway sets OPENCLAW_STATE_DIR for named profiles (e.g. ~/.openclaw-ludis)
|
|
128
|
+
// OPENCLAW_DIR is the user-facing alias (used by install.sh)
|
|
129
|
+
const stateDir = process.env.OPENCLAW_STATE_DIR
|
|
130
|
+
if (stateDir) return stateDir
|
|
128
131
|
const envDir = process.env.OPENCLAW_DIR
|
|
129
132
|
if (envDir) return envDir
|
|
130
133
|
return path.join(os.homedir(), '.openclaw')
|
|
@@ -2422,40 +2425,52 @@ export default function register(api: OpenClawApi) {
|
|
|
2422
2425
|
if (state.running) {
|
|
2423
2426
|
api.logger?.info?.(`[clawnetwork] node already running (pid=${state.pid})`)
|
|
2424
2427
|
|
|
2425
|
-
// Check if
|
|
2426
|
-
if
|
|
2428
|
+
// Check if local binary is newer than the running process — restart if so.
|
|
2429
|
+
// Also check GitHub for even newer versions and download if available.
|
|
2430
|
+
try {
|
|
2431
|
+
const binary = findBinary()
|
|
2432
|
+
const localBinaryVersion = binary ? getBinaryVersion(binary) : null
|
|
2433
|
+
|
|
2434
|
+
// Get the RUNNING process version from health endpoint (not the file version)
|
|
2435
|
+
let runningProcessVersion: string | null = null
|
|
2427
2436
|
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)
|
|
2437
|
+
const health = await fetch(`http://localhost:${cfg.rpcPort}/health`)
|
|
2438
|
+
if (health.ok) {
|
|
2439
|
+
const hd = await health.json() as Record<string, unknown>
|
|
2440
|
+
if (typeof hd.version === 'string') runningProcessVersion = hd.version.replace(/^v/, '')
|
|
2441
|
+
}
|
|
2442
|
+
} catch { /* health endpoint not ready */ }
|
|
2443
|
+
|
|
2444
|
+
// Step A: If GitHub has a newer binary than what's on disk, download it first
|
|
2445
|
+
if (cfg.autoDownload && localBinaryVersion) {
|
|
2446
|
+
try {
|
|
2447
|
+
const res = await fetch(`https://api.github.com/repos/${GITHUB_REPO}/releases/latest`)
|
|
2448
|
+
if (res.ok) {
|
|
2449
|
+
const data = await res.json() as Record<string, unknown>
|
|
2450
|
+
const latestVersion = typeof data.tag_name === 'string' ? data.tag_name.replace(/^v/, '') : null
|
|
2451
|
+
if (latestVersion && isVersionOlder(localBinaryVersion, latestVersion)) {
|
|
2452
|
+
api.logger?.info?.(`[clawnetwork] downloading newer binary: ${localBinaryVersion} → ${latestVersion}`)
|
|
2453
|
+
try { await downloadBinary(api) } catch (e: unknown) {
|
|
2454
|
+
api.logger?.warn?.(`[clawnetwork] download failed: ${(e as Error).message}`)
|
|
2455
|
+
}
|
|
2453
2456
|
}
|
|
2454
2457
|
}
|
|
2455
|
-
}
|
|
2456
|
-
}
|
|
2457
|
-
|
|
2458
|
+
} catch { /* network error, skip */ }
|
|
2459
|
+
}
|
|
2460
|
+
|
|
2461
|
+
// Step B: If the local binary is newer than the running process, restart with it
|
|
2462
|
+
const finalBinary = findBinary()
|
|
2463
|
+
const finalBinaryVersion = finalBinary ? getBinaryVersion(finalBinary) : null
|
|
2464
|
+
if (finalBinaryVersion && runningProcessVersion && isVersionOlder(runningProcessVersion, finalBinaryVersion)) {
|
|
2465
|
+
api.logger?.info?.(`[clawnetwork] running node ${runningProcessVersion} is outdated, restarting with ${finalBinaryVersion}...`)
|
|
2466
|
+
stopNode(api)
|
|
2467
|
+
await sleep(3_000)
|
|
2468
|
+
initNode(finalBinary, cfg.network, api)
|
|
2469
|
+
startNodeProcess(finalBinary, cfg, api)
|
|
2470
|
+
api.logger?.info?.(`[clawnetwork] node upgraded to ${finalBinaryVersion}`)
|
|
2458
2471
|
}
|
|
2472
|
+
} catch (e: unknown) {
|
|
2473
|
+
api.logger?.warn?.(`[clawnetwork] upgrade check failed: ${(e as Error).message}`)
|
|
2459
2474
|
}
|
|
2460
2475
|
|
|
2461
2476
|
startHealthCheck(cfg, api)
|
package/openclaw.plugin.json
CHANGED