@clawlabz/clawnetwork 0.1.15 → 0.1.16
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 +29 -15
- package/openclaw.plugin.json +1 -1
- package/package.json +1 -1
package/index.ts
CHANGED
|
@@ -2396,25 +2396,39 @@ export default function register(api: OpenClawApi) {
|
|
|
2396
2396
|
if (state.running) {
|
|
2397
2397
|
api.logger?.info?.(`[clawnetwork] node already running (pid=${state.pid})`)
|
|
2398
2398
|
|
|
2399
|
-
// Check if
|
|
2399
|
+
// Check if a newer binary is available on GitHub — if so, download + restart
|
|
2400
2400
|
if (cfg.autoDownload) {
|
|
2401
|
-
|
|
2402
|
-
|
|
2403
|
-
const
|
|
2404
|
-
if (
|
|
2405
|
-
|
|
2406
|
-
|
|
2407
|
-
await sleep(3_000)
|
|
2401
|
+
try {
|
|
2402
|
+
const binary = findBinary()
|
|
2403
|
+
const runningVersion = binary ? getBinaryVersion(binary) : null
|
|
2404
|
+
if (runningVersion) {
|
|
2405
|
+
// Fetch latest version from GitHub
|
|
2406
|
+
let latestVersion: string | null = null
|
|
2408
2407
|
try {
|
|
2409
|
-
const
|
|
2410
|
-
|
|
2411
|
-
|
|
2412
|
-
|
|
2413
|
-
|
|
2414
|
-
|
|
2415
|
-
|
|
2408
|
+
const res = await fetch(`https://api.github.com/repos/${GITHUB_REPO}/releases/latest`)
|
|
2409
|
+
if (res.ok) {
|
|
2410
|
+
const data = await res.json() as Record<string, unknown>
|
|
2411
|
+
if (typeof data.tag_name === 'string') latestVersion = data.tag_name.replace(/^v/, '')
|
|
2412
|
+
}
|
|
2413
|
+
} catch { /* network error, skip */ }
|
|
2414
|
+
|
|
2415
|
+
if (latestVersion && isVersionOlder(runningVersion, latestVersion)) {
|
|
2416
|
+
api.logger?.info?.(`[clawnetwork] node ${runningVersion} → ${latestVersion} available, upgrading...`)
|
|
2417
|
+
stopNodeProcess(api)
|
|
2418
|
+
await sleep(3_000)
|
|
2419
|
+
try {
|
|
2420
|
+
const newBinary = await downloadBinary(api)
|
|
2421
|
+
initNode(newBinary, cfg.network, api)
|
|
2422
|
+
startNodeProcess(newBinary, cfg, api)
|
|
2423
|
+
api.logger?.info?.(`[clawnetwork] node upgraded to ${latestVersion} and restarted`)
|
|
2424
|
+
} catch (e: unknown) {
|
|
2425
|
+
api.logger?.warn?.(`[clawnetwork] auto-upgrade failed: ${(e as Error).message}, restarting old binary`)
|
|
2426
|
+
startNodeProcess(binary, cfg, api)
|
|
2427
|
+
}
|
|
2416
2428
|
}
|
|
2417
2429
|
}
|
|
2430
|
+
} catch (e: unknown) {
|
|
2431
|
+
api.logger?.warn?.(`[clawnetwork] upgrade check failed: ${(e as Error).message}`)
|
|
2418
2432
|
}
|
|
2419
2433
|
}
|
|
2420
2434
|
|
package/openclaw.plugin.json
CHANGED