ကိုယ်တိုင် သိမ်းချင်ရင် အောက်က script ကို copy ကူးပြီး pi-windows-setup.ps1 အဖြစ် သိမ်းပါ။
<#
.SYNOPSIS
Pi.dev (Windows) + custom relay one-shot setup.
Installs Pi if missing, saves your relay API key (prompted locally,
never leaves this machine), and writes the relay as a custom provider
in Pi's models.json.
.USAGE
Right-click -> "Run with PowerShell", or in PowerShell:
.\pi-windows-setup.ps1
With a different relay:
.\pi-windows-setup.ps1 -BaseUrl "https://your-relay/v1" -Provider "myrelay" -EnvVar "MYRELAY_API_KEY"
Or direct from the web (defaults):
irm https://pi-win.kmnapps.xyz/pi-windows-setup.ps1 | iex
#>
param(
[string]$BaseUrl = "https://sapi.zly168.cn/v1",
[string]$Provider = "zly168",
[string]$EnvVar = "ZLY168_API_KEY"
)
$ErrorActionPreference = "Stop"
function Write-Step($msg) { Write-Host "`n==> $msg" -ForegroundColor Cyan }
# ---------------------------------------------------------------- 1. Node check
Write-Step "Checking Node.js (Pi needs 22.19+)..."
$nodeOk = $false
try {
$v = (node --version) 2>$null
if ($v -match 'v(\d+)\.') { if ([int]$Matches[1] -ge 22) { $nodeOk = $true; Write-Host "Node $v found." -ForegroundColor Green } }
} catch { }
if (-not $nodeOk) {
Write-Host "Node 22+ not found. Installing Node 22 LTS via winget..." -ForegroundColor Yellow
winget install --id OpenJS.NodeJS.LTS -e --accept-source-agreements --accept-package-agreements
Write-Host "Node installed. Close and re-open PowerShell, then run this script again." -ForegroundColor Yellow
exit 1
}
# ---------------------------------------------------------------- 2. Pi install
Write-Step "Checking Pi..."
if (-not (Get-Command pi -ErrorAction SilentlyContinue)) {
Write-Host "Installing Pi.dev (official installer)..." -ForegroundColor Yellow
irm https://pi.dev/install.ps1 | iex
if (-not (Get-Command pi -ErrorAction SilentlyContinue)) {
Write-Host "Pi did not land on PATH. Open a NEW PowerShell and run this script again." -ForegroundColor Red
exit 1
}
}
Write-Host "Pi is ready: $(pi --version 2>$null)" -ForegroundColor Green
# ---------------------------------------------------------------- 3. API key
Write-Step "Relay API key ($BaseUrl)..."
$existing = [Environment]::GetEnvironmentVariable($EnvVar, "User")
if ($existing) {
$ans = Read-Host "API key already saved. Replace with a new one? (y/N)"
if ($ans -eq 'y' -or $ans -eq 'Y') { $existing = $null }
}
if ($existing) {
Write-Host "$EnvVar already saved (user env). Keeping it." -ForegroundColor Green
$key = $existing
} else {
Write-Host "Paste your API key for $BaseUrl below. It is stored ONLY in your" -ForegroundColor Yellow
Write-Host "Windows user environment (registry) - never sent anywhere." -ForegroundColor Yellow
$sec = Read-Host "API key" -AsSecureString
$bstr = [Runtime.InteropServices.Marshal]::SecureStringToBSTR($sec)
try { $key = [Runtime.InteropServices.Marshal]::PtrToStringAuto($bstr) }
finally { [Runtime.InteropServices.Marshal]::ZeroFreeBSTR($bstr) }
if (-not $key) { Write-Host "No key entered. Aborting." -ForegroundColor Red; exit 1 }
[Environment]::SetEnvironmentVariable($EnvVar, $key, "User")
Set-Item -Path "env:$EnvVar" -Value $key
Write-Host "Key saved to user environment (persistent)." -ForegroundColor Green
}
# ---------------------------------------------------------------- 4. models.json
Write-Step "Writing Pi provider config..."
$dir = Join-Path $env:USERPROFILE ".pi\agent"
New-Item -ItemType Directory -Force -Path $dir | Out-Null
$target = Join-Path $dir "models.json"
if (Test-Path $target) {
$bak = "$target.bak-$(Get-Date -Format 'yyyyMMdd-HHmmss')"
Copy-Item $target $bak
Write-Host "Existing models.json backed up to $bak" -ForegroundColor Yellow
}
$modelsJson = @"
{
"providers": {
"$Provider": {
"baseUrl": "$BaseUrl",
"api": "openai-completions",
"apiKey": "`$$EnvVar",
"compat": { "supportsDeveloperRole": false },
"models": [
{ "id": "gpt-6", "name": "GPT 6 (latest)" },
{ "id": "gpt-5.6-sol", "name": "GPT 5.6 Sol (verified)" },
{ "id": "gpt-5.5", "name": "GPT 5.5" },
{ "id": "claude-opus-5[次]", "name": "Claude Opus 5 (latest)" },
{ "id": "claude-sonnet-5[次]", "name": "Claude Sonnet 5 (latest)" },
{ "id": "claude-fable-5[次]", "name": "Claude Fable 5" },
{ "id": "gemini-3.8-flash-high", "name": "Gemini 3.8 Flash High" },
{ "id": "gemini-3.8-flash", "name": "Gemini 3.8 Flash (verified)" },
{ "id": "grok-4.7", "name": "Grok 4.7 (latest)" },
{ "id": "grok-4.5", "name": "Grok 4.5" },
{ "id": "glm-5.2", "name": "GLM 5.2" },
{ "id": "mimo-v2.5-pro", "name": "Mimo V2.5 Pro" }
]
}
}
}
"@
$modelsJson | Out-File -FilePath $target -Encoding utf8 -NoNewline
Write-Host "Wrote $target" -ForegroundColor Green
# ---------------------------------------------------------------- 5. verify
Write-Step "Verifying Pi sees the $Provider provider..."
$list = pi --list-models 2>&1 | Out-String
$hits = [regex]::Matches($list, [regex]::Escape($Provider) + '/[A-Za-z0-9._-]+') | ForEach-Object { $_.Value } | Sort-Object -Unique
if ($hits.Count -gt 0) {
Write-Host "Found $($hits.Count) $Provider models:" -ForegroundColor Green
$hits | ForEach-Object { Write-Host " - $_" }
} else {
Write-Host "WARNING: no $Provider/* entries in 'pi --list-models'." -ForegroundColor Yellow
Write-Host "Open a NEW PowerShell (to pick up the env var) and run: pi --list-models" -ForegroundColor Yellow
}
Write-Host @"
==============================================================
DONE. Next steps:
1. Open a NEW PowerShell (picks up $EnvVar).
2. cd to your project folder, then run: pi
3. Inside Pi type: /model
-> pick a $Provider/* model
-> press Ctrl+S to save it as your default.
4. Just describe what you want - Pi will code with your API.
To add more models later, edit:
$target
(/model reloads the file every time it opens.)
==============================================================
"@ -ForegroundColor Cyan