# WEVIA Migration v5 - DEFINITIVE FIX $ErrorActionPreference = 'Continue' $STAMP = Get-Date -Format 'yyyyMMdd-HHmmss' $NEW_BASE = "https://weval-consulting.com/api/wevia-anthropic" $FAKE_KEY = "sk-ant-wevia-fake-not-checked" Write-Host "" Write-Host "=========================================" -ForegroundColor Cyan Write-Host " WEVIA Migration v5 - DEFINITIVE" -ForegroundColor Cyan Write-Host "=========================================" -ForegroundColor Cyan Write-Host " ANTHROPIC_BASE_URL: $NEW_BASE" -ForegroundColor Yellow Write-Host " Hostname: $env:COMPUTERNAME / User: $env:USERNAME" -ForegroundColor Gray $modified=0; $created=0; $backups=0 # Step 1: Cursor settings.json Write-Host "" Write-Host "[1/5] Cursor settings.json..." -ForegroundColor Cyan $cursorPath = "$env:APPDATA\Cursor\User\settings.json" $cursorDir = Split-Path $cursorPath if (-not (Test-Path $cursorDir)) { New-Item -Type Directory -Path $cursorDir -Force | Out-Null } if (Test-Path $cursorPath) { $content = Get-Content $cursorPath -Raw -Encoding UTF8 Copy-Item $cursorPath "$cursorPath.WEVIA-BAK-$STAMP" -Force $backups++ Write-Host " BACKUP saved" -ForegroundColor Gray $json = $null try { $json = $content | ConvertFrom-Json -ErrorAction Stop } catch {} if ($null -ne $json) { $json | Add-Member -NotePropertyName "anthropic.apiKey" -NotePropertyValue $FAKE_KEY -Force $json | Add-Member -NotePropertyName "anthropic.baseURL" -NotePropertyValue $NEW_BASE -Force Set-Content $cursorPath -Value ($json | ConvertTo-Json -Depth 10) -Force -Encoding UTF8 $modified++ Write-Host " ADDED: anthropic.apiKey + anthropic.baseURL" -ForegroundColor Green } else { $content = $content -replace 'https?://api\.anthropic\.com', $NEW_BASE Set-Content $cursorPath -Value $content -Force -Encoding UTF8 $modified++ } } else { @{"anthropic.apiKey"=$FAKE_KEY; "anthropic.baseURL"=$NEW_BASE} | ConvertTo-Json | Set-Content $cursorPath -Encoding UTF8 $created++ Write-Host " CREATED: $cursorPath" -ForegroundColor Green } # Step 2: Claude Desktop Write-Host "" Write-Host "[2/5] Claude Desktop config..." -ForegroundColor Cyan $claudePath = "$env:APPDATA\Claude\claude_desktop_config.json" if (-not (Test-Path (Split-Path $claudePath))) { New-Item -Type Directory -Path (Split-Path $claudePath) -Force | Out-Null } if (Test-Path $claudePath) { Copy-Item $claudePath "$claudePath.WEVIA-BAK-$STAMP" -Force $backups++ $json = $null try { $json = Get-Content $claudePath -Raw -Encoding UTF8 | ConvertFrom-Json -ErrorAction Stop } catch {} if ($null -eq $json) { $json = [PSCustomObject]@{} } $json | Add-Member -NotePropertyName "anthropicApiKey" -NotePropertyValue $FAKE_KEY -Force $json | Add-Member -NotePropertyName "anthropicBaseUrl" -NotePropertyValue $NEW_BASE -Force Set-Content $claudePath -Value ($json | ConvertTo-Json -Depth 10) -Force -Encoding UTF8 $modified++ Write-Host " MODIFIED Claude Desktop config" -ForegroundColor Green } else { @{"anthropicApiKey"=$FAKE_KEY; "anthropicBaseUrl"=$NEW_BASE} | ConvertTo-Json | Set-Content $claudePath -Encoding UTF8 $created++ Write-Host " CREATED Claude Desktop config (download Claude Desktop si non installe)" -ForegroundColor Green } # Step 3: Env vars Write-Host "" Write-Host "[3/5] Environment variables..." -ForegroundColor Cyan [Environment]::SetEnvironmentVariable('ANTHROPIC_BASE_URL', $NEW_BASE, 'User') [Environment]::SetEnvironmentVariable('ANTHROPIC_API_KEY', $FAKE_KEY, 'User') $env:ANTHROPIC_BASE_URL = $NEW_BASE $env:ANTHROPIC_API_KEY = $FAKE_KEY Write-Host " SET ANTHROPIC_BASE_URL + ANTHROPIC_API_KEY (User scope)" -ForegroundColor Green # Step 4: Verify with claude-haiku-4-5 (verified 1.4s) Write-Host "" Write-Host "[4/5] Verifying proxy LIVE..." -ForegroundColor Cyan $verifyOK = $false try { $body = @{model="claude-haiku-4-5-20251001"; max_tokens=25; messages=@(@{role="user"; content="VERIFIED"})} | ConvertTo-Json -Depth 5 -Compress $headers = @{"x-api-key"=$FAKE_KEY; "anthropic-version"="2023-06-01"; "Content-Type"="application/json"} $resp = Invoke-RestMethod -Uri "$NEW_BASE/v1/messages" -Method Post -Headers $headers -Body $body -TimeoutSec 60 if ($resp.content) { Write-Host " PROXY OK: $($resp.content[0].text)" -ForegroundColor Green $verifyOK = $true } } catch { Write-Host " Proxy verify WARN: $($_.Exception.Message) (retry plus tard)" -ForegroundColor Yellow } # Step 5: Restart with Sleep 5s Write-Host "" Write-Host "[5/5] Restarting Cursor + Claude Desktop..." -ForegroundColor Cyan $restarted = 0 foreach ($appName in @("Cursor","Claude")) { $procs = Get-Process -Name $appName -ErrorAction SilentlyContinue if ($procs) { $exePath = $procs[0].Path Write-Host " Killing $appName..." -ForegroundColor Gray Stop-Process -Name $appName -Force -ErrorAction SilentlyContinue Start-Sleep -Seconds 5 if ($exePath -and (Test-Path $exePath)) { try { Start-Process $exePath -ErrorAction Stop; Write-Host " Restarted $appName" -ForegroundColor Green; $restarted++ } catch { Write-Host " Manual relaunch needed for $appName (config saved)" -ForegroundColor Yellow } } } else { Write-Host " $appName not running (config picked up next launch)" -ForegroundColor Gray } } Write-Host "" Write-Host "=========================================" -ForegroundColor Green Write-Host " WEVIA GO v5 COMPLETE!" -ForegroundColor Green Write-Host "=========================================" -ForegroundColor Green Write-Host " Files modified: $modified | created: $created | backups: $backups | restarted: $restarted" -ForegroundColor White Write-Host " Proxy verify: $(if ($verifyOK) {'OK'} else {'WARN'})" -ForegroundColor White Write-Host " ECONOMIE: ~EUR 421/mois cascade gratuite" -ForegroundColor Green Write-Host " ROLLBACK: restore *.WEVIA-BAK-$STAMP files" -ForegroundColor Gray Write-Host ""