@blockrun/clawrouter 0.10.6 → 0.10.7

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@blockrun/clawrouter",
3
- "version": "0.10.6",
3
+ "version": "0.10.7",
4
4
  "description": "Smart LLM router — save 92% on inference costs. 41+ models, one wallet, x402 micropayments.",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",
@@ -24,26 +24,6 @@
24
24
  "scripts",
25
25
  "openclaw.plugin.json"
26
26
  ],
27
- "scripts": {
28
- "build": "tsup",
29
- "dev": "tsup --watch",
30
- "test": "vitest run",
31
- "test:watch": "vitest",
32
- "typecheck": "tsc --noEmit",
33
- "lint": "eslint src/",
34
- "format": "prettier --write .",
35
- "format:check": "prettier --check .",
36
- "test:resilience:errors": "tsx test/resilience-errors.ts",
37
- "test:resilience:stability": "DURATION_MINUTES=5 tsx test/resilience-stability.ts",
38
- "test:resilience:stability:full": "DURATION_MINUTES=240 tsx test/resilience-stability.ts",
39
- "test:resilience:lifecycle": "tsx test/resilience-lifecycle.ts",
40
- "test:resilience:quick": "npm run test:resilience:errors && npm run test:resilience:lifecycle",
41
- "test:resilience:full": "npm run test:resilience:errors && npm run test:resilience:lifecycle && npm run test:resilience:stability:full",
42
- "test:e2e:tool-ids": "tsx test/e2e-tool-id-sanitization.ts",
43
- "test:docker:install": "bash test/run-docker-test.sh",
44
- "test:docker:edge-cases": "bash test/docker/run-edge-cases.sh",
45
- "test:docker:integration": "docker compose -f test/integration/docker-compose.yml up --build --abort-on-container-exit --exit-code-from integration"
46
- },
47
27
  "keywords": [
48
28
  "llm",
49
29
  "router",
@@ -91,5 +71,25 @@
91
71
  },
92
72
  "engines": {
93
73
  "node": ">=20"
74
+ },
75
+ "scripts": {
76
+ "build": "tsup",
77
+ "dev": "tsup --watch",
78
+ "test": "vitest run",
79
+ "test:watch": "vitest",
80
+ "typecheck": "tsc --noEmit",
81
+ "lint": "eslint src/",
82
+ "format": "prettier --write .",
83
+ "format:check": "prettier --check .",
84
+ "test:resilience:errors": "tsx test/resilience-errors.ts",
85
+ "test:resilience:stability": "DURATION_MINUTES=5 tsx test/resilience-stability.ts",
86
+ "test:resilience:stability:full": "DURATION_MINUTES=240 tsx test/resilience-stability.ts",
87
+ "test:resilience:lifecycle": "tsx test/resilience-lifecycle.ts",
88
+ "test:resilience:quick": "npm run test:resilience:errors && npm run test:resilience:lifecycle",
89
+ "test:resilience:full": "npm run test:resilience:errors && npm run test:resilience:lifecycle && npm run test:resilience:stability:full",
90
+ "test:e2e:tool-ids": "tsx test/e2e-tool-id-sanitization.ts",
91
+ "test:docker:install": "bash test/run-docker-test.sh",
92
+ "test:docker:edge-cases": "bash test/docker/run-edge-cases.sh",
93
+ "test:docker:integration": "docker compose -f test/integration/docker-compose.yml up --build --abort-on-container-exit --exit-code-from integration"
94
94
  }
95
- }
95
+ }
@@ -28,6 +28,27 @@ kill_port_processes() {
28
28
  echo "🦞 ClawRouter Reinstall"
29
29
  echo ""
30
30
 
31
+ # 0. Back up wallet key BEFORE removing anything
32
+ WALLET_FILE="$HOME/.openclaw/blockrun/wallet.key"
33
+ WALLET_BACKUP=""
34
+
35
+ echo "→ Backing up wallet..."
36
+ if [ -f "$WALLET_FILE" ]; then
37
+ WALLET_KEY=$(cat "$WALLET_FILE" | tr -d '[:space:]')
38
+ KEY_LEN=${#WALLET_KEY}
39
+ if [[ "$WALLET_KEY" == 0x* ]] && [ "$KEY_LEN" -eq 66 ]; then
40
+ WALLET_BACKUP="$HOME/.openclaw/blockrun/wallet.key.bak.$(date +%s)"
41
+ cp "$WALLET_FILE" "$WALLET_BACKUP"
42
+ chmod 600 "$WALLET_BACKUP"
43
+ echo " ✓ Wallet backed up to: $WALLET_BACKUP"
44
+ else
45
+ echo " ⚠ Wallet file exists but has invalid format — skipping backup"
46
+ fi
47
+ else
48
+ echo " ℹ No existing wallet found"
49
+ fi
50
+ echo ""
51
+
31
52
  # 1. Remove plugin files
32
53
  echo "→ Removing plugin files..."
33
54
  rm -rf ~/.openclaw/extensions/clawrouter
@@ -291,6 +312,29 @@ if (fs.existsSync(configPath)) {
291
312
  }
292
313
  "
293
314
 
315
+ # Final: verify wallet survived reinstall
316
+ echo "→ Verifying wallet integrity..."
317
+ if [ -f "$WALLET_FILE" ]; then
318
+ CURRENT_KEY=$(cat "$WALLET_FILE" | tr -d '[:space:]')
319
+ CURRENT_LEN=${#CURRENT_KEY}
320
+ if [[ "$CURRENT_KEY" == 0x* ]] && [ "$CURRENT_LEN" -eq 66 ]; then
321
+ echo " ✓ Wallet key intact"
322
+ else
323
+ if [ -n "$WALLET_BACKUP" ] && [ -f "$WALLET_BACKUP" ]; then
324
+ cp "$WALLET_BACKUP" "$WALLET_FILE"
325
+ chmod 600 "$WALLET_FILE"
326
+ echo " ✓ Wallet restored from backup"
327
+ fi
328
+ fi
329
+ else
330
+ if [ -n "$WALLET_BACKUP" ] && [ -f "$WALLET_BACKUP" ]; then
331
+ mkdir -p "$(dirname "$WALLET_FILE")"
332
+ cp "$WALLET_BACKUP" "$WALLET_FILE"
333
+ chmod 600 "$WALLET_FILE"
334
+ echo " ✓ Wallet restored from backup: $WALLET_BACKUP"
335
+ fi
336
+ fi
337
+
294
338
  echo ""
295
339
  echo "✓ Done! Smart routing enabled by default."
296
340
  echo ""
@@ -0,0 +1,168 @@
1
+ #!/bin/bash
2
+ set -e
3
+
4
+ # ─────────────────────────────────────────────────────────────
5
+ # ClawRouter Update Script
6
+ # Safe update: backs up wallet key BEFORE touching anything,
7
+ # restores it if the update process somehow wiped it.
8
+ # ─────────────────────────────────────────────────────────────
9
+
10
+ WALLET_FILE="$HOME/.openclaw/blockrun/wallet.key"
11
+ WALLET_BACKUP=""
12
+
13
+ # ── Step 1: Back up wallet key ─────────────────────────────────
14
+ echo "🦞 ClawRouter Update"
15
+ echo ""
16
+ echo "→ Checking wallet..."
17
+
18
+ if [ -f "$WALLET_FILE" ]; then
19
+ # Validate the key looks correct before backing up
20
+ WALLET_KEY=$(cat "$WALLET_FILE" | tr -d '[:space:]')
21
+ KEY_LEN=${#WALLET_KEY}
22
+
23
+ if [[ "$WALLET_KEY" == 0x* ]] && [ "$KEY_LEN" -eq 66 ]; then
24
+ # Derive wallet address via node (viem is available post-install)
25
+ WALLET_ADDRESS=$(node -e "
26
+ try {
27
+ const { privateKeyToAccount } = require('$HOME/.openclaw/extensions/clawrouter/node_modules/viem/accounts/index.js');
28
+ const acct = privateKeyToAccount('$WALLET_KEY');
29
+ console.log(acct.address);
30
+ } catch {
31
+ // viem not available yet (fresh install path), skip address check
32
+ console.log('(address check skipped)');
33
+ }
34
+ " 2>/dev/null || echo "(address check skipped)")
35
+
36
+ WALLET_BACKUP="$HOME/.openclaw/blockrun/wallet.key.bak.$(date +%s)"
37
+ cp "$WALLET_FILE" "$WALLET_BACKUP"
38
+ chmod 600 "$WALLET_BACKUP"
39
+
40
+ echo " ✓ Wallet backed up to: $WALLET_BACKUP"
41
+ echo " ✓ Wallet address: $WALLET_ADDRESS"
42
+ else
43
+ echo " ⚠ Wallet file exists but has invalid format (len=$KEY_LEN)"
44
+ echo " ⚠ Skipping backup — you should restore your wallet manually"
45
+ fi
46
+ else
47
+ echo " ℹ No existing wallet found (first install or already lost)"
48
+ fi
49
+
50
+ echo ""
51
+
52
+ # ── Step 2: Kill old proxy ──────────────────────────────────────
53
+ echo "→ Stopping old proxy..."
54
+ kill_port_processes() {
55
+ local port="$1"
56
+ local pids=""
57
+ if command -v lsof >/dev/null 2>&1; then
58
+ pids="$(lsof -ti :"$port" 2>/dev/null || true)"
59
+ elif command -v fuser >/dev/null 2>&1; then
60
+ pids="$(fuser "$port"/tcp 2>/dev/null || true)"
61
+ fi
62
+ if [ -n "$pids" ]; then
63
+ echo "$pids" | xargs kill -9 2>/dev/null || true
64
+ fi
65
+ }
66
+ kill_port_processes 8402
67
+
68
+ # ── Step 3: Remove old plugin files ────────────────────────────
69
+ echo "→ Removing old plugin files..."
70
+ rm -rf ~/.openclaw/extensions/clawrouter
71
+
72
+ # ── Step 4: Install latest version ─────────────────────────────
73
+ echo "→ Installing latest ClawRouter..."
74
+ openclaw plugins install @blockrun/clawrouter
75
+
76
+ # ── Step 5: Verify wallet survived ─────────────────────────────
77
+ echo ""
78
+ echo "→ Verifying wallet integrity..."
79
+
80
+ if [ -f "$WALLET_FILE" ]; then
81
+ CURRENT_KEY=$(cat "$WALLET_FILE" | tr -d '[:space:]')
82
+ CURRENT_LEN=${#CURRENT_KEY}
83
+
84
+ if [[ "$CURRENT_KEY" == 0x* ]] && [ "$CURRENT_LEN" -eq 66 ]; then
85
+ echo " ✓ Wallet key intact at $WALLET_FILE"
86
+ else
87
+ echo " ✗ Wallet file corrupted after update!"
88
+ if [ -n "$WALLET_BACKUP" ] && [ -f "$WALLET_BACKUP" ]; then
89
+ cp "$WALLET_BACKUP" "$WALLET_FILE"
90
+ chmod 600 "$WALLET_FILE"
91
+ echo " ✓ Restored from backup: $WALLET_BACKUP"
92
+ else
93
+ echo " ✗ No backup available — wallet key is lost"
94
+ echo " Restore manually: set BLOCKRUN_WALLET_KEY env var"
95
+ fi
96
+ fi
97
+ else
98
+ echo " ✗ Wallet file missing after update!"
99
+ if [ -n "$WALLET_BACKUP" ] && [ -f "$WALLET_BACKUP" ]; then
100
+ mkdir -p "$(dirname "$WALLET_FILE")"
101
+ cp "$WALLET_BACKUP" "$WALLET_FILE"
102
+ chmod 600 "$WALLET_FILE"
103
+ echo " ✓ Restored from backup: $WALLET_BACKUP"
104
+ else
105
+ echo " ℹ New wallet will be generated on next gateway start"
106
+ fi
107
+ fi
108
+
109
+ # ── Step 6: Inject auth profile ─────────────────────────────────
110
+ echo "→ Refreshing auth profile..."
111
+ node -e "
112
+ const os = require('os');
113
+ const fs = require('fs');
114
+ const path = require('path');
115
+ const authDir = path.join(os.homedir(), '.openclaw', 'agents', 'main', 'agent');
116
+ const authPath = path.join(authDir, 'auth-profiles.json');
117
+
118
+ fs.mkdirSync(authDir, { recursive: true });
119
+
120
+ let store = { version: 1, profiles: {} };
121
+ if (fs.existsSync(authPath)) {
122
+ try {
123
+ const existing = JSON.parse(fs.readFileSync(authPath, 'utf8'));
124
+ if (existing.version && existing.profiles) store = existing;
125
+ } catch {}
126
+ }
127
+
128
+ const profileKey = 'blockrun:default';
129
+ if (!store.profiles[profileKey]) {
130
+ store.profiles[profileKey] = { type: 'api_key', provider: 'blockrun', key: 'x402-proxy-handles-auth' };
131
+ fs.writeFileSync(authPath, JSON.stringify(store, null, 2));
132
+ console.log(' Auth profile created');
133
+ } else {
134
+ console.log(' Auth profile already exists');
135
+ }
136
+ "
137
+
138
+ # ── Step 7: Clean models cache ──────────────────────────────────
139
+ echo "→ Cleaning models cache..."
140
+ rm -f ~/.openclaw/agents/*/agent/models.json 2>/dev/null || true
141
+
142
+ # ── Summary ─────────────────────────────────────────────────────
143
+ echo ""
144
+ echo "✓ ClawRouter updated successfully!"
145
+ echo ""
146
+
147
+ # Show final wallet address
148
+ if [ -f "$WALLET_FILE" ]; then
149
+ FINAL_KEY=$(cat "$WALLET_FILE" | tr -d '[:space:]')
150
+ FINAL_ADDRESS=$(node -e "
151
+ try {
152
+ const { privateKeyToAccount } = require('$HOME/.openclaw/extensions/clawrouter/node_modules/viem/accounts/index.js');
153
+ console.log(privateKeyToAccount('$FINAL_KEY').address);
154
+ } catch { console.log('(run /wallet in OpenClaw to see your address)'); }
155
+ " 2>/dev/null || echo "(run /wallet in OpenClaw to see your address)")
156
+
157
+ echo " Wallet: $FINAL_ADDRESS"
158
+ echo " Key file: $WALLET_FILE"
159
+ if [ -n "$WALLET_BACKUP" ]; then
160
+ echo " Backup: $WALLET_BACKUP"
161
+ fi
162
+ fi
163
+
164
+ echo ""
165
+ echo " Run: openclaw gateway restart"
166
+ echo ""
167
+ echo " ⚠ Back up your wallet key: /wallet export (in OpenClaw)"
168
+ echo ""