param( [string]$KeyFile = '' ) # 把本机 server/.env 的 TokenHub / 豆包 ASR 写到两台生产 API,并重启服务。 $ErrorActionPreference = 'Stop' $root = Split-Path -Parent $PSScriptRoot Set-Location $root . (Join-Path $PSScriptRoot 'tencent-prod-env.ps1') $prodEnv = Read-TencentProdEnv -Root $root if (-not $KeyFile) { $KeyFile = Join-Path $root 'deploy\id_rsa_tencent' } if (-not (Test-Path $KeyFile)) { Write-Error "SSH key not found: $KeyFile" } $sshOpts = @('-i', $KeyFile, '-o', 'StrictHostKeyChecking=accept-new', '-o', 'ConnectTimeout=20') $snippet = Join-Path $env:TEMP ('llm.env.snippet.' + [guid]::NewGuid().ToString('N').Substring(0, 8)) $count = Write-LlmEnvSnippet -Root $root -OutFile $snippet Write-Host "Sync $count LLM env keys from local server/.env" -ForegroundColor Cyan $hosts = @( @{ Host = "ubuntu@$($prodEnv.API_IP)"; Name = 'test-api' }, @{ Host = "ubuntu@$($prodEnv.API1_IP)"; Name = 'test-api1' } ) $upsert = Join-Path $root 'scripts\prod-upsert-llm-env.sh' try { foreach ($h in $hosts) { Write-Host "--> $($h.Name) $($h.Host)" -ForegroundColor Yellow & scp @sshOpts $snippet "$($h.Host):/tmp/llm.env.snippet" if ($LASTEXITCODE -ne 0) { throw "scp snippet failed: $($h.Name)" } & scp @sshOpts $upsert "$($h.Host):/tmp/prod-upsert-llm-env.sh" if ($LASTEXITCODE -ne 0) { throw "scp upsert failed: $($h.Name)" } & ssh @sshOpts $h.Host "chmod +x /tmp/prod-upsert-llm-env.sh && bash /tmp/prod-upsert-llm-env.sh /tmp/llm.env.snippet && rm -f /tmp/llm.env.snippet /tmp/prod-upsert-llm-env.sh && sudo systemctl restart ai-fresh-api && sleep 2 && curl -sf http://127.0.0.1:3001/api/health" if ($LASTEXITCODE -ne 0) { throw "upsert/restart failed: $($h.Name)" } Write-Host " health ok" -ForegroundColor Green } } finally { Remove-Item $snippet -Force -ErrorAction SilentlyContinue } Write-Host "Production API now uses local TokenHub LLM env. Voice still needs SPEECH_API_KEY if empty locally." -ForegroundColor Green