Update channel dispatch UX and harden sidecar startup behavior.

This aligns Weixin/WhatsApp with admin-managed model routing by adding channel/account-level specialist controls, improves OSS startup resilience by skipping missing sidecars gracefully, and refreshes runbook/readme guidance for the new default behavior and Weixin OpenAI-key silent handling.

Made-with: Cursor
This commit is contained in:
oliver 2026-04-28 22:58:50 +08:00
parent b1a0f94cd6
commit 5ab69e88d3
29 changed files with 1226 additions and 100 deletions

View file

@ -4,9 +4,11 @@
[switch]$SkipInstall = $false,
[switch]$Background = $false,
[switch]$WithoutWeixin = $false,
[switch]$WithoutWhatsApp = $false,
[bool]$WithWikiWorker = $true,
[string]$WeixinChannelId = "oclaw-weixin",
[string]$WeixinGatewayBaseUrl = ""
[string]$WeixinGatewayBaseUrl = "",
[string]$WhatsAppChannelId = "whatsapp"
)
$ErrorActionPreference = "Stop"
@ -15,6 +17,10 @@ function Write-Step([string]$msg) {
Write-Host "==> $msg" -ForegroundColor Cyan
}
function Warn([string]$msg) {
Write-Host "[WARN] $msg" -ForegroundColor Yellow
}
$repoRoot = Split-Path -Parent (Split-Path -Parent (Split-Path -Parent $PSScriptRoot))
$repoParent = Split-Path -Parent $repoRoot
Set-Location $repoRoot
@ -43,7 +49,20 @@ if (-not $WithoutWeixin) {
$gwBase = "http://$BindHost`:$Port"
}
Write-Step "Starting weixin sidecar"
& "$PSScriptRoot/weixin_start.ps1" -ChannelId $WeixinChannelId -GatewayBaseUrl $gwBase
try {
& "$PSScriptRoot/weixin_start.ps1" -ChannelId $WeixinChannelId -GatewayBaseUrl $gwBase
} catch {
Warn "weixin sidecar skipped: $($_.Exception.Message)"
}
}
if (-not $WithoutWhatsApp) {
$waBase = "http://$BindHost`:$Port"
Write-Step "Starting whatsapp sidecar"
try {
& "$PSScriptRoot/whatsapp_start.ps1" -ChannelId $WhatsAppChannelId -GatewayBaseUrl $waBase
} catch {
Warn "whatsapp sidecar skipped: $($_.Exception.Message)"
}
}
Write-Host ""
Write-Host "All started." -ForegroundColor Green

View file

@ -2,8 +2,10 @@ param(
[string]$BindHost = "127.0.0.1",
[int]$Port = 8787,
[switch]$WithoutWeixin = $false,
[switch]$WithoutWhatsApp = $false,
[switch]$WithWikiWorker = $false,
[string]$WeixinChannelId = "oclaw-weixin"
[string]$WeixinChannelId = "oclaw-weixin",
[string]$WhatsAppChannelId = "whatsapp"
)
$ErrorActionPreference = "Stop"
@ -127,6 +129,15 @@ if (-not $WithoutWeixin) {
Warn "weixin status failed: $($_.Exception.Message)"
}
}
if (-not $WithoutWhatsApp) {
Write-Host ""
Write-Step "WhatsApp sidecar"
try {
& "$PSScriptRoot/whatsapp_status.ps1" -ChannelId $WhatsAppChannelId
} catch {
Warn "whatsapp status failed: $($_.Exception.Message)"
}
}
if ($WithWikiWorker) {
Write-Host ""

View file

@ -2,8 +2,10 @@ param(
[int]$Port = 8787,
[switch]$Force = $false,
[switch]$WithoutWeixin = $false,
[switch]$WithoutWhatsApp = $false,
[switch]$WithWikiWorker = $false,
[string]$WeixinChannelId = "oclaw-weixin"
[string]$WeixinChannelId = "oclaw-weixin",
[string]$WhatsAppChannelId = "whatsapp"
)
$ErrorActionPreference = "Stop"
@ -34,6 +36,14 @@ if (-not $WithoutWeixin) {
if (-not $Force) { throw }
}
}
if (-not $WithoutWhatsApp) {
Write-Step "Stopping whatsapp sidecar"
try {
& "$PSScriptRoot/whatsapp_stop.ps1" -ChannelId $WhatsAppChannelId -Force:$Force
} catch {
if (-not $Force) { throw }
}
}
if ($WithWikiWorker) {
Write-Step "Stopping wiki worker"
try {

View file

@ -32,8 +32,15 @@ if ($procId -le 0) {
}
try {
# Kill the whole process tree (cmd -> npm -> electron/node)
& taskkill /PID $procId /T /F | Out-Null
# Kill the whole process tree (cmd -> npm -> electron/node).
# Some shells promote native command non-zero exit codes to terminating errors.
$oldNativePref = $PSNativeCommandUseErrorActionPreference
try {
$PSNativeCommandUseErrorActionPreference = $false
& taskkill /PID $procId /T /F 2>$null | Out-Null
} finally {
$PSNativeCommandUseErrorActionPreference = $oldNativePref
}
Write-Host "Stopped PID=$procId (tree)" -ForegroundColor Green
Remove-Item $pidFile -Force -ErrorAction SilentlyContinue
exit 0

View file

@ -37,15 +37,9 @@ function Ensure-OfficialPluginRuntimeDeps {
}
if ($UseOpenclawCli) {
$openclawCmd = Get-Command openclaw -ErrorAction SilentlyContinue
if (-not $openclawCmd) {
throw "openclaw command not found. Install first: npm install -g openclaw"
}
npx -y @tencent-weixin/openclaw-weixin-cli@latest install
if ($LASTEXITCODE -ne 0) {
throw "openclaw-weixin-cli install failed with exit code $LASTEXITCODE"
}
Ensure-OfficialPluginRuntimeDeps
# Do not require a globally-installed openclaw CLI.
# We install openclaw into the sidecar runtime and put node_modules/.bin on PATH
# so the official installer can run `openclaw ...` commands.
Push-Location $sidecarRoot
try {
if (-not (Test-Path (Join-Path $sidecarRoot "package.json"))) {
@ -54,6 +48,21 @@ if ($UseOpenclawCli) {
throw "npm init failed with exit code $LASTEXITCODE"
}
}
npm.cmd install openclaw@latest --save
if ($LASTEXITCODE -ne 0) {
throw "npm install openclaw failed with exit code $LASTEXITCODE"
}
$env:PATH = (Join-Path $sidecarRoot "node_modules\\.bin") + ";" + $env:PATH
npx.cmd -y @tencent-weixin/openclaw-weixin-cli@latest install
if ($LASTEXITCODE -ne 0) {
throw "openclaw-weixin-cli install failed with exit code $LASTEXITCODE"
}
} finally {
Pop-Location
}
Ensure-OfficialPluginRuntimeDeps
Push-Location $sidecarRoot
try {
npm.cmd install openclaw@latest --save tsx@4.21.0 typescript@6.0.3
if ($LASTEXITCODE -ne 0) {
throw "npm install bridge runtime deps failed with exit code $LASTEXITCODE"

View file

@ -27,15 +27,7 @@ try {
npm.cmd exec -- tsx login.ts
exit 0
}
$openclawCmd = Get-Command openclaw -ErrorAction SilentlyContinue
if (-not $openclawCmd) {
throw "official mode requires openclaw command. Install first: npm install -g openclaw"
}
$systemNodeDir = "C:\\Program Files\\nodejs"
if (Test-Path (Join-Path $systemNodeDir "node.exe")) {
$env:PATH = "$systemNodeDir;$env:PATH"
}
openclaw channels login --channel openclaw-weixin
throw "login.ts missing. Re-run weixin_install.ps1 -UseOpenclawCli to install sidecar runtime."
} finally {
Pop-Location
}

View file

@ -42,12 +42,14 @@ function Get-SidecarProcesses {
function Stop-SidecarProcesses {
$procs = @(Get-SidecarProcesses | Sort-Object ProcessId -Descending)
foreach ($proc in $procs) {
try {
taskkill.exe /PID $proc.ProcessId /T /F | Out-Null
} catch {
# Best-effort cleanup; keep going if a process already exited.
$oldNativePref = $PSNativeCommandUseErrorActionPreference
try {
$PSNativeCommandUseErrorActionPreference = $false
foreach ($proc in $procs) {
taskkill.exe /PID $proc.ProcessId /T /F 2>$null | Out-Null
}
} finally {
$PSNativeCommandUseErrorActionPreference = $oldNativePref
}
return $procs.Count
}
@ -112,17 +114,5 @@ if ((Test-Path (Join-Path $sidecarRoot "runner.ts")) -or (Test-Path (Join-Path $
exit 0
}
$openclawCmd = Get-Command openclaw -ErrorAction SilentlyContinue
if (-not $openclawCmd) {
throw "official mode requires openclaw command. Install first: npm install -g openclaw"
}
# Ensure OpenClaw runs on the real Node.js runtime (includes npm layout).
$systemNodeDir = "C:\\Program Files\\nodejs"
if (Test-Path (Join-Path $systemNodeDir "node.exe")) {
$env:PATH = "$systemNodeDir;$env:PATH"
}
$args = @("/c", "openclaw gateway --allow-unconfigured")
$p = Start-Process -FilePath "cmd.exe" -ArgumentList $args -WorkingDirectory $oclawRoot -PassThru -WindowStyle Hidden -RedirectStandardOutput $logPath -RedirectStandardError $errPath
Set-Content -Path $pidFile -Value $p.Id
Write-Host "[ok] started openclaw gateway pid=$($p.Id) cleaned=$cleaned out=$logPath err=$errPath"
throw "No runner.ts/official_runner.ts found in sidecar root. Re-run weixin_install.ps1 -UseOpenclawCli."

View file

@ -69,16 +69,6 @@ if ($exists) {
Write-Host "status=orphaned stale_pid=$procId count=$($sidecarProcs.Count) pids=$pids"
exit 0
}
$openclawCmd = Get-Command openclaw -ErrorAction SilentlyContinue
if ($openclawCmd) {
try {
$txt = (& openclaw channels status --probe) -join "`n"
if ($txt -match "openclaw-weixin .*running") {
Write-Host "status=running mode=official"
exit 0
}
} catch {}
}
Write-Host "status=stale_pid pid=$procId"
}

View file

@ -42,16 +42,22 @@ function Stop-SidecarProcesses {
[switch]$ForceKill
)
$procs = @(Get-SidecarProcesses | Sort-Object ProcessId -Descending)
foreach ($proc in $procs) {
try {
$oldNativePref = $PSNativeCommandUseErrorActionPreference
try {
$PSNativeCommandUseErrorActionPreference = $false
foreach ($proc in $procs) {
if ($ForceKill) {
taskkill.exe /PID $proc.ProcessId /T /F | Out-Null
} else {
taskkill.exe /PID $proc.ProcessId /T | Out-Null
taskkill.exe /PID $proc.ProcessId /T /F 2>$null | Out-Null
continue
}
taskkill.exe /PID $proc.ProcessId /T 2>$null | Out-Null
if ($LASTEXITCODE -ne 0) {
# Some process trees require force kill on Windows.
taskkill.exe /PID $proc.ProcessId /T /F 2>$null | Out-Null
}
} catch {
# Ignore already-exited processes and continue best-effort cleanup.
}
} finally {
$PSNativeCommandUseErrorActionPreference = $oldNativePref
}
return $procs.Count
}
@ -73,21 +79,23 @@ if (-not $procId) {
exit 0
}
$oldNativePref = $PSNativeCommandUseErrorActionPreference
try {
$PSNativeCommandUseErrorActionPreference = $false
if ($Force) {
taskkill.exe /PID $procId /T /F | Out-Null
taskkill.exe /PID $procId /T /F 2>$null | Out-Null
} else {
taskkill.exe /PID $procId /T | Out-Null
taskkill.exe /PID $procId /T 2>$null | Out-Null
if ($LASTEXITCODE -ne 0) {
# Retry with /F to avoid noisy parent/child kill failures.
taskkill.exe /PID $procId /T /F 2>$null | Out-Null
}
}
} catch {
# Ignore if already dead.
} finally {
$PSNativeCommandUseErrorActionPreference = $oldNativePref
}
$killed = Stop-SidecarProcesses -ForceKill:$Force
Remove-Item -Force $pidFile -ErrorAction SilentlyContinue
$openclawCmd = Get-Command openclaw -ErrorAction SilentlyContinue
if ($openclawCmd) {
try { openclaw gateway stop | Out-Null } catch {}
}
Write-Host "[ok] stopped pid=$procId extra_cleaned=$killed"

View file

@ -0,0 +1,52 @@
param(
[string]$ChannelId = "whatsapp"
)
$ErrorActionPreference = "Stop"
$systemNodeDir = "C:\\Program Files\\nodejs"
if (Test-Path (Join-Path $systemNodeDir "node.exe")) {
$env:PATH = "$systemNodeDir;$env:PATH"
}
function Resolve-RepoRoot {
$here = Split-Path -Parent $PSCommandPath
return (Resolve-Path (Join-Path $here "..\\..\\..")).Path
}
$oclawRoot = Resolve-RepoRoot
$sidecarRoot = Join-Path $oclawRoot "data\\channel_sidecar\\$ChannelId"
$stateDir = Join-Path $sidecarRoot "state"
$logDir = Join-Path $sidecarRoot "logs"
$bridgeSrc = Join-Path $oclawRoot "runtime\\operations\\whatsapp_bridge"
New-Item -ItemType Directory -Force -Path $sidecarRoot | Out-Null
New-Item -ItemType Directory -Force -Path $stateDir | Out-Null
New-Item -ItemType Directory -Force -Path $logDir | Out-Null
Push-Location $sidecarRoot
try {
if (-not (Test-Path (Join-Path $sidecarRoot "package.json"))) {
npm.cmd init -y | Out-Null
if ($LASTEXITCODE -ne 0) { throw "npm init failed with exit code $LASTEXITCODE" }
}
npm.cmd install --save @whiskeysockets/baileys@latest qrcode-terminal@latest
if ($LASTEXITCODE -ne 0) { throw "npm install deps failed with exit code $LASTEXITCODE" }
npm.cmd install --save https-proxy-agent@latest
if ($LASTEXITCODE -ne 0) { throw "npm install proxy deps failed with exit code $LASTEXITCODE" }
npm.cmd install --save tsx@latest typescript@latest
if ($LASTEXITCODE -ne 0) { throw "npm install dev deps failed with exit code $LASTEXITCODE" }
} finally {
Pop-Location
}
if (Test-Path $bridgeSrc) {
foreach ($name in @("baileys_runner.ts", "auth.ts", "qr.ts")) {
$srcPath = Join-Path $bridgeSrc $name
if (Test-Path $srcPath) {
Copy-Item -Path $srcPath -Destination (Join-Path $sidecarRoot $name) -Force
}
}
}
Write-Host "[ok] installed whatsapp baileys sidecar runtime into $sidecarRoot"

View file

@ -0,0 +1,32 @@
param(
[string]$ChannelId = "whatsapp"
)
$ErrorActionPreference = "Stop"
$systemNodeDir = "C:\\Program Files\\nodejs"
if (Test-Path (Join-Path $systemNodeDir "node.exe")) {
$env:PATH = "$systemNodeDir;$env:PATH"
}
function Resolve-RepoRoot {
$here = Split-Path -Parent $PSCommandPath
return (Resolve-Path (Join-Path $here "..\\..\\..")).Path
}
$oclawRoot = Resolve-RepoRoot
$sidecarRoot = Join-Path $oclawRoot "data\\channel_sidecar\\$ChannelId"
$stateDir = Join-Path $sidecarRoot "state"
if (-not (Test-Path (Join-Path $sidecarRoot "baileys_runner.ts"))) {
throw "whatsapp sidecar not installed. Run whatsapp_install.ps1 first."
}
Push-Location $sidecarRoot
try {
$env:OCLAW_STATE_DIR = $stateDir
$args = @("/c", "set OCLAW_STATE_DIR=$stateDir&& npx.cmd -y tsx baileys_runner.ts --login")
Start-Process -FilePath "cmd.exe" -ArgumentList $args -WorkingDirectory $sidecarRoot -Wait
} finally {
Pop-Location
}

View file

@ -0,0 +1,57 @@
param(
[string]$ChannelId = "whatsapp",
[string]$GatewayBaseUrl = "http://127.0.0.1:8787",
[int]$GatewayWaitSeconds = 20
)
$ErrorActionPreference = "Stop"
function Resolve-RepoRoot {
$here = Split-Path -Parent $PSCommandPath
return (Resolve-Path (Join-Path $here "..\\..\\..")).Path
}
$oclawRoot = Resolve-RepoRoot
$sidecarRoot = Join-Path $oclawRoot "data\\channel_sidecar\\$ChannelId"
$stateDir = Join-Path $sidecarRoot "state"
$logDir = Join-Path $sidecarRoot "logs"
$sidecarPidFile = Join-Path $sidecarRoot "pid.txt"
New-Item -ItemType Directory -Force -Path $sidecarRoot | Out-Null
New-Item -ItemType Directory -Force -Path $stateDir | Out-Null
New-Item -ItemType Directory -Force -Path $logDir | Out-Null
$logPath = Join-Path $logDir "whatsapp_sidecar.log"
$errPath = Join-Path $logDir "whatsapp_sidecar.err.log"
$systemNodeDir = "C:\\Program Files\\nodejs"
if (Test-Path (Join-Path $systemNodeDir "node.exe")) {
$env:PATH = "$systemNodeDir;$env:PATH"
}
if (-not (Test-Path (Join-Path $sidecarRoot "baileys_runner.ts"))) {
throw "whatsapp sidecar not installed. Run whatsapp_install.ps1 first."
}
$healthUrl = ($GatewayBaseUrl.TrimEnd("/") + "/health")
for ($i = 0; $i -lt $GatewayWaitSeconds; $i++) {
try {
$resp = Invoke-WebRequest -Uri $healthUrl -UseBasicParsing -TimeoutSec 3
if ($resp -and $resp.StatusCode -eq 200) {
break
}
} catch {}
if ($i -lt ($GatewayWaitSeconds - 1)) {
Start-Sleep -Seconds 1
}
}
if (-not $resp -or $resp.StatusCode -ne 200) {
throw "oclaw gateway is not reachable at $healthUrl. Start it first: powershell -ExecutionPolicy Bypass -File .\\scripts\\start_gateway.ps1 -SkipInstall -Background"
}
$args = @(
"/c",
"cd /d $sidecarRoot && set OCLAW_STATE_DIR=$stateDir&& set AIA_GATEWAY_BASE_URL=$GatewayBaseUrl&& npx.cmd -y tsx baileys_runner.ts"
)
$p = Start-Process -FilePath "cmd.exe" -ArgumentList $args -WorkingDirectory $sidecarRoot -PassThru -WindowStyle Hidden -RedirectStandardOutput $logPath -RedirectStandardError $errPath
Set-Content -Path $sidecarPidFile -Value $p.Id
Write-Host "[ok] started whatsapp sidecar pid=$($p.Id) mode=baileys out=$logPath err=$errPath"

View file

@ -0,0 +1,18 @@
param(
[string]$ChannelId = "whatsapp"
)
$ErrorActionPreference = "Stop"
$oclawRoot = (Resolve-Path (Join-Path (Split-Path -Parent $PSCommandPath) "..\\..\\..")).Path
$sidecarRoot = Join-Path $oclawRoot "data\\channel_sidecar\\$ChannelId"
$sidecarPidFile = Join-Path $sidecarRoot "pid.txt"
if (Test-Path $sidecarPidFile) {
$procId = (Get-Content -Path $sidecarPidFile -ErrorAction SilentlyContinue | Select-Object -First 1)
if ($procId -and (Get-Process -Id $procId -ErrorAction SilentlyContinue)) {
Write-Host "status=running mode=baileys channel=$ChannelId"
exit 0
}
}
Write-Host "status=stopped mode=baileys channel=$ChannelId"

View file

@ -0,0 +1,37 @@
param(
[string]$ChannelId = "whatsapp",
[switch]$Force
)
$ErrorActionPreference = "Stop"
function Resolve-RepoRoot {
$here = Split-Path -Parent $PSCommandPath
return (Resolve-Path (Join-Path $here "..\\..\\..")).Path
}
$systemNodeDir = "C:\\Program Files\\nodejs"
if (Test-Path (Join-Path $systemNodeDir "node.exe")) {
$env:PATH = "$systemNodeDir;$env:PATH"
}
$oclawRoot = Resolve-RepoRoot
$sidecarRoot = Join-Path $oclawRoot "data\\channel_sidecar\\$ChannelId"
$sidecarPidFile = Join-Path $sidecarRoot "pid.txt"
if (Test-Path $sidecarPidFile) {
$procId = (Get-Content -Path $sidecarPidFile -ErrorAction SilentlyContinue | Select-Object -First 1)
if ($procId) {
if ($Force) {
taskkill.exe /PID $procId /T /F 2>$null | Out-Null
} else {
taskkill.exe /PID $procId /T 2>$null | Out-Null
if ($LASTEXITCODE -ne 0) {
taskkill.exe /PID $procId /T /F 2>$null | Out-Null
}
}
}
Remove-Item -Force $sidecarPidFile -ErrorAction SilentlyContinue
}
Write-Host "[ok] stopped whatsapp channel=$ChannelId"