@blockrun/clawrouter 0.12.104 → 0.12.105

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.
Files changed (2) hide show
  1. package/package.json +1 -1
  2. package/scripts/update.ps1 +223 -0
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@blockrun/clawrouter",
3
- "version": "0.12.104",
3
+ "version": "0.12.105",
4
4
  "description": "Smart LLM router — save 85% on inference costs. 55+ models (11 free), one wallet, x402 micropayments.",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",
@@ -0,0 +1,223 @@
1
+ # ClawRouter Update Script for Windows (PowerShell)
2
+ # Usage: iwr -useb https://blockrun.ai/ClawRouter-update.ps1 | iex
3
+ # or: powershell -ExecutionPolicy Bypass -Command "iwr -useb https://blockrun.ai/ClawRouter-update.ps1 | iex"
4
+ #
5
+ # Run as regular user (no admin needed)
6
+ Set-StrictMode -Version Latest
7
+ $ErrorActionPreference = "Stop"
8
+
9
+ $PLUGIN_DIR = "$env:USERPROFILE\.openclaw\extensions\clawrouter"
10
+ $CONFIG_PATH = "$env:USERPROFILE\.openclaw\openclaw.json"
11
+ $WALLET_FILE = "$env:USERPROFILE\.openclaw\blockrun\wallet.key"
12
+
13
+ function Write-Ok { param($msg) Write-Host " $([char]0x2713) $msg" -ForegroundColor Green }
14
+ function Write-Warn { param($msg) Write-Host " ! $msg" -ForegroundColor Yellow }
15
+ function Write-Err { param($msg) Write-Host " x $msg" -ForegroundColor Red }
16
+ function Write-Step { param($msg) Write-Host "`n-> $msg" }
17
+
18
+ Write-Host ""
19
+ Write-Host "ClawRouter Update (Windows)" -ForegroundColor Cyan
20
+ Write-Host ""
21
+
22
+ # ── Step 1: Back up wallet ────────────────────────────────────
23
+ Write-Step "Backing up wallet..."
24
+ $walletBackup = $null
25
+ if (Test-Path $WALLET_FILE) {
26
+ $walletKey = (Get-Content $WALLET_FILE -Raw).Trim()
27
+ if ($walletKey -match '^0x[0-9a-fA-F]{64}$') {
28
+ $walletBackup = "$WALLET_FILE.bak.$(Get-Date -UFormat '%s')"
29
+ Copy-Item $WALLET_FILE $walletBackup
30
+ Write-Ok "Wallet backed up: $walletBackup"
31
+ } else {
32
+ Write-Warn "Wallet file found but has unexpected format — skipping backup"
33
+ }
34
+ } else {
35
+ Write-Host " i No existing wallet found"
36
+ }
37
+
38
+ # ── Step 2: Stop old proxy ────────────────────────────────────
39
+ Write-Step "Stopping old proxy..."
40
+ try {
41
+ $procs = Get-NetTCPConnection -LocalPort 8402 -ErrorAction SilentlyContinue |
42
+ Select-Object -ExpandProperty OwningProcess -Unique
43
+ foreach ($pid in $procs) {
44
+ if ($pid -gt 0) { Stop-Process -Id $pid -Force -ErrorAction SilentlyContinue }
45
+ }
46
+ Write-Ok "Port 8402 cleared"
47
+ } catch {
48
+ Write-Host " i Could not check port 8402 (normal if proxy was not running)"
49
+ }
50
+
51
+ # ── Step 3: Clean stale config entries ────────────────────────
52
+ Write-Step "Cleaning config..."
53
+ if (Test-Path $CONFIG_PATH) {
54
+ try {
55
+ $cfg = Get-Content $CONFIG_PATH -Raw | ConvertFrom-Json
56
+ $changed = $false
57
+ if ($cfg.plugins -and $cfg.plugins.entries -and $cfg.plugins.entries.PSObject.Properties['clawrouter']) {
58
+ $cfg.plugins.entries.PSObject.Properties.Remove('clawrouter')
59
+ $changed = $true
60
+ }
61
+ if ($cfg.plugins -and $cfg.plugins.installs -and $cfg.plugins.installs.PSObject.Properties['clawrouter']) {
62
+ $cfg.plugins.installs.PSObject.Properties.Remove('clawrouter')
63
+ $changed = $true
64
+ }
65
+ if ($changed) {
66
+ $cfg | ConvertTo-Json -Depth 20 | Set-Content $CONFIG_PATH -Encoding UTF8
67
+ Write-Ok "Removed stale plugin entries"
68
+ } else {
69
+ Write-Ok "Config already clean"
70
+ }
71
+ } catch {
72
+ Write-Warn "Could not parse config: $_"
73
+ }
74
+ }
75
+
76
+ # ── Step 3b: Ensure baseUrl / apiKey ──────────────────────────
77
+ Write-Step "Verifying provider config..."
78
+ if (Test-Path $CONFIG_PATH) {
79
+ try {
80
+ $cfg = Get-Content $CONFIG_PATH -Raw | ConvertFrom-Json
81
+ $provider = $cfg.models?.providers?.blockrun
82
+ if ($provider) {
83
+ $changed = $false
84
+ if (-not $provider.baseUrl) { $provider | Add-Member -NotePropertyName baseUrl -NotePropertyValue 'http://127.0.0.1:8402/v1' -Force; $changed = $true; Write-Ok "Fixed missing baseUrl" }
85
+ if (-not $provider.apiKey) { $provider | Add-Member -NotePropertyName apiKey -NotePropertyValue 'x402-proxy-handles-auth' -Force; $changed = $true; Write-Ok "Fixed missing apiKey" }
86
+ if ($changed) { $cfg | ConvertTo-Json -Depth 20 | Set-Content $CONFIG_PATH -Encoding UTF8 }
87
+ else { Write-Ok "Provider config OK" }
88
+ }
89
+ } catch {
90
+ Write-Warn "Could not verify provider config: $_"
91
+ }
92
+ }
93
+
94
+ # ── Step 4: Get latest version from npm ───────────────────────
95
+ Write-Step "Fetching latest version from npm..."
96
+ try {
97
+ $LATEST_VERSION = (npm view @blockrun/clawrouter@latest version 2>&1).Trim()
98
+ if (-not $LATEST_VERSION -or $LATEST_VERSION -match 'error|ERR') {
99
+ throw "npm view failed: $LATEST_VERSION"
100
+ }
101
+ Write-Ok "Latest: v$LATEST_VERSION"
102
+ } catch {
103
+ Write-Err "Cannot determine latest version: $_"
104
+ Write-Host " Check npm is installed and you have internet access."
105
+ exit 1
106
+ }
107
+
108
+ # ── Step 5: Install directly from npm (bypasses openclaw cache) ───
109
+ Write-Step "Downloading ClawRouter v$LATEST_VERSION from npm..."
110
+
111
+ $tmpDir = Join-Path $env:TEMP "clawrouter-install-$(Get-Random)"
112
+ New-Item -ItemType Directory -Path $tmpDir -Force | Out-Null
113
+
114
+ try {
115
+ npm pack "@blockrun/clawrouter@$LATEST_VERSION" --pack-destination $tmpDir --prefer-online 2>&1 | Out-Null
116
+
117
+ $tarball = Get-ChildItem "$tmpDir\*.tgz" | Select-Object -First 1
118
+ if (-not $tarball) { throw "npm pack produced no tarball in $tmpDir" }
119
+
120
+ # Remove old install
121
+ if (Test-Path $PLUGIN_DIR) {
122
+ Remove-Item -Recurse -Force $PLUGIN_DIR
123
+ }
124
+ New-Item -ItemType Directory -Path $PLUGIN_DIR -Force | Out-Null
125
+
126
+ # Extract (tar is built into Windows 10+ / Server 2019+)
127
+ tar -xzf $tarball.FullName -C $PLUGIN_DIR --strip-components=1
128
+ if ($LASTEXITCODE -ne 0) { throw "tar extraction failed (exit $LASTEXITCODE)" }
129
+
130
+ Write-Ok "Extracted v$LATEST_VERSION to $PLUGIN_DIR"
131
+ } finally {
132
+ Remove-Item -Recurse -Force $tmpDir -ErrorAction SilentlyContinue
133
+ }
134
+
135
+ # ── Step 5b: Install npm dependencies ─────────────────────────
136
+ Write-Step "Installing dependencies (Solana, x402, etc.)..."
137
+ $logFile = Join-Path $env:TEMP "clawrouter-npm-install.log"
138
+ $proc = Start-Process -FilePath "npm" -ArgumentList "install","--omit=dev" -WorkingDirectory $PLUGIN_DIR `
139
+ -RedirectStandardOutput $logFile -RedirectStandardError "$logFile.err" -Wait -PassThru -NoNewWindow
140
+ if ($proc.ExitCode -ne 0) {
141
+ Write-Err "npm install failed. Log: $logFile"
142
+ Get-Content "$logFile.err" -ErrorAction SilentlyContinue | Select-Object -Last 20 | ForEach-Object { Write-Host " $_" -ForegroundColor Red }
143
+ exit 1
144
+ }
145
+ Write-Ok "Dependencies installed"
146
+
147
+ # ── Step 6: Register plugin in openclaw config ────────────────
148
+ Write-Step "Registering plugin..."
149
+ if (Test-Path $CONFIG_PATH) {
150
+ try {
151
+ $cfg = Get-Content $CONFIG_PATH -Raw | ConvertFrom-Json
152
+ if (-not $cfg.plugins) { $cfg | Add-Member -NotePropertyName plugins -NotePropertyValue ([PSCustomObject]@{}) -Force }
153
+ if (-not $cfg.plugins.allow) { $cfg.plugins | Add-Member -NotePropertyName allow -NotePropertyValue @() -Force }
154
+ $allow = [System.Collections.Generic.List[string]]$cfg.plugins.allow
155
+ if (-not $allow.Contains('clawrouter')) {
156
+ $allow.Add('clawrouter')
157
+ $cfg.plugins.allow = $allow.ToArray()
158
+ $cfg | ConvertTo-Json -Depth 20 | Set-Content $CONFIG_PATH -Encoding UTF8
159
+ Write-Ok "Added clawrouter to plugins.allow"
160
+ } else {
161
+ Write-Ok "Plugin already in allow list"
162
+ }
163
+ } catch {
164
+ Write-Warn "Could not update plugins.allow: $_"
165
+ }
166
+ }
167
+
168
+ # ── Step 7: Inject auth profile ───────────────────────────────
169
+ Write-Step "Setting up auth profile..."
170
+ $authDir = "$env:USERPROFILE\.openclaw\agents\main\agent"
171
+ $authPath = "$authDir\auth-profiles.json"
172
+ New-Item -ItemType Directory -Path $authDir -Force | Out-Null
173
+ $store = [PSCustomObject]@{ version = 1; profiles = [PSCustomObject]@{} }
174
+ if (Test-Path $authPath) {
175
+ try { $store = Get-Content $authPath -Raw | ConvertFrom-Json } catch {}
176
+ }
177
+ if (-not $store.profiles.PSObject.Properties['blockrun:default']) {
178
+ $store.profiles | Add-Member -NotePropertyName 'blockrun:default' `
179
+ -NotePropertyValue ([PSCustomObject]@{ type = 'api_key'; provider = 'blockrun'; key = 'x402-proxy-handles-auth' }) -Force
180
+ $store | ConvertTo-Json -Depth 10 | Set-Content $authPath -Encoding UTF8
181
+ Write-Ok "Auth profile created"
182
+ } else {
183
+ Write-Ok "Auth profile already exists"
184
+ }
185
+
186
+ # ── Step 8: Clean models cache ────────────────────────────────
187
+ Write-Step "Cleaning models cache..."
188
+ Get-ChildItem "$env:USERPROFILE\.openclaw\agents\*\agent\models.json" -ErrorAction SilentlyContinue |
189
+ Remove-Item -Force -ErrorAction SilentlyContinue
190
+ Write-Ok "Models cache cleared"
191
+
192
+ # ── Step 9: Verify wallet survived ────────────────────────────
193
+ Write-Step "Verifying wallet integrity..."
194
+ if (Test-Path $WALLET_FILE) {
195
+ $key = (Get-Content $WALLET_FILE -Raw).Trim()
196
+ if ($key -match '^0x[0-9a-fA-F]{64}$') {
197
+ Write-Ok "Wallet key intact"
198
+ } else {
199
+ if ($walletBackup -and (Test-Path $walletBackup)) {
200
+ Copy-Item $walletBackup $WALLET_FILE -Force
201
+ Write-Ok "Wallet restored from backup"
202
+ } else {
203
+ Write-Warn "Wallet file may be corrupted and no backup found"
204
+ }
205
+ }
206
+ } else {
207
+ if ($walletBackup -and (Test-Path $walletBackup)) {
208
+ New-Item -ItemType Directory -Path (Split-Path $WALLET_FILE) -Force | Out-Null
209
+ Copy-Item $walletBackup $WALLET_FILE -Force
210
+ Write-Ok "Wallet restored from backup"
211
+ } else {
212
+ Write-Host " i No wallet found — a new one will be generated on first start"
213
+ }
214
+ }
215
+
216
+ # ── Done ──────────────────────────────────────────────────────
217
+ Write-Host ""
218
+ Write-Host "ClawRouter v$LATEST_VERSION installed successfully!" -ForegroundColor Green
219
+ Write-Host ""
220
+ Write-Host " Run: openclaw gateway restart" -ForegroundColor Cyan
221
+ Write-Host ""
222
+ Write-Host " To verify: npx @blockrun/clawrouter doctor"
223
+ Write-Host ""