fix: 恢复 Codex 动态端点测试
- base_url: 恢复动态测试 api2.xcodecli.com 和 api.xcodecli.com - model: 恢复为 gpt-5.1-codex - 保留其他新配置项 (disable_response_storage, requires_openai_auth 等) - 保留 XCODECLI_OAI_KEY 环境变量 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
@@ -14,6 +14,7 @@ param(
|
||||
if (-not $ApiKey -and (Test-Path Variable:key)) { $ApiKey = $key }
|
||||
|
||||
# Configuration
|
||||
$DefaultBaseUrl = "https://api2.xcodecli.com"
|
||||
$CodexConfigDir = "$env:USERPROFILE\.codex"
|
||||
$CodexConfigFile = "$CodexConfigDir\config.toml"
|
||||
|
||||
@@ -127,31 +128,74 @@ function Test-ApiKey {
|
||||
}
|
||||
}
|
||||
|
||||
# Function to test API connection and return working base URL
|
||||
function Test-ApiConnection {
|
||||
param([string]$ApiKey)
|
||||
|
||||
$testUrls = @(
|
||||
"https://api2.xcodecli.com",
|
||||
"https://api.xcodecli.com"
|
||||
)
|
||||
|
||||
Write-Info "Testing API connections..."
|
||||
|
||||
foreach ($baseUrl in $testUrls) {
|
||||
Write-Info "Testing $baseUrl..."
|
||||
|
||||
try {
|
||||
$headers = @{
|
||||
"Content-Type" = "application/json"
|
||||
"Authorization" = "Bearer $ApiKey"
|
||||
}
|
||||
|
||||
$testEndpoint = "$baseUrl/v1/models"
|
||||
$response = Invoke-RestMethod -Uri $testEndpoint -Method Get -Headers $headers -ErrorAction Stop
|
||||
|
||||
if ($response.data) {
|
||||
$modelCount = $response.data.Count
|
||||
Write-Success "API connection successful! Found $modelCount models at $baseUrl"
|
||||
return $baseUrl
|
||||
} else {
|
||||
Write-Warning "API responded but no models found at $baseUrl"
|
||||
}
|
||||
}
|
||||
catch {
|
||||
if ($_.Exception.Response -and $_.Exception.Response.StatusCode -eq 401) {
|
||||
Write-Warning "API key authentication failed for $baseUrl"
|
||||
} elseif ($_.Exception.Message -like "*Unable to connect*" -or $_.Exception.Message -like "*could not be resolved*") {
|
||||
Write-Warning "Cannot connect to $baseUrl"
|
||||
} else {
|
||||
Write-Warning "API test failed for $baseUrl`: $($_.Exception.Message)"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Write-Error "All API connections failed. Please check your API key and internet connection."
|
||||
return $null
|
||||
}
|
||||
|
||||
# Function to create Codex configuration
|
||||
function New-Settings {
|
||||
param(
|
||||
[string]$BaseUrl,
|
||||
[string]$ApiKey
|
||||
)
|
||||
|
||||
$config = @"
|
||||
model_provider = "xcodecli"
|
||||
model = "gpt-5-codex"
|
||||
model = "gpt-5.1-codex"
|
||||
model_reasoning_effort = "high"
|
||||
disable_response_storage = true
|
||||
preferred_auth_method = "apikey"
|
||||
|
||||
[model_providers.xcodecli]
|
||||
name = "xcodecli"
|
||||
base_url = "https://www.xcodecli.com/openai"
|
||||
base_url = "$BaseUrl/v1"
|
||||
wire_api = "responses"
|
||||
requires_openai_auth = true
|
||||
env_key = "XCODECLI_OAI_KEY"
|
||||
"@
|
||||
|
||||
$authJson = @{
|
||||
OPENAI_API_KEY = $null
|
||||
}
|
||||
|
||||
try {
|
||||
Set-Content -Path $CodexConfigFile -Value $config -Encoding UTF8
|
||||
Write-Success "Codex configuration written to: $CodexConfigFile"
|
||||
@@ -258,34 +302,24 @@ function Main {
|
||||
Write-Info "API Key: $maskedKey"
|
||||
Write-Host ""
|
||||
|
||||
# Test API connection with fixed URL
|
||||
$testUrl = "https://www.xcodecli.com/openai"
|
||||
Write-Info "Testing API connection to $testUrl..."
|
||||
|
||||
try {
|
||||
$headers = @{
|
||||
"Content-Type" = "application/json"
|
||||
"Authorization" = "Bearer $ApiKey"
|
||||
}
|
||||
$response = Invoke-RestMethod -Uri "$testUrl/models" -Method Get -Headers $headers -ErrorAction Stop
|
||||
Write-Success "API connection successful!"
|
||||
}
|
||||
catch {
|
||||
if ($_.Exception.Response -and $_.Exception.Response.StatusCode -eq 401) {
|
||||
Write-Warning "API key authentication failed"
|
||||
} else {
|
||||
Write-Warning "API test failed: $($_.Exception.Message)"
|
||||
}
|
||||
# Test API connection and get working base URL
|
||||
$BaseUrl = Test-ApiConnection -ApiKey $ApiKey
|
||||
|
||||
if (-not $BaseUrl) {
|
||||
if ($Test) {
|
||||
exit 1
|
||||
}
|
||||
|
||||
$continue = Read-Host "Continue anyway? (y/N)"
|
||||
$continue = Read-Host "All API tests failed. Continue anyway? (y/N)"
|
||||
if ($continue -notmatch '^[Yy]$') {
|
||||
Write-Info "Setup cancelled"
|
||||
exit 1
|
||||
}
|
||||
|
||||
$BaseUrl = $DefaultBaseUrl
|
||||
Write-Warning "Using default URL: $BaseUrl"
|
||||
} else {
|
||||
Write-Info "Selected working base URL: $BaseUrl"
|
||||
}
|
||||
|
||||
# Exit if test only
|
||||
@@ -301,7 +335,7 @@ function Main {
|
||||
Backup-Settings
|
||||
|
||||
# Create new settings
|
||||
if (New-Settings -ApiKey $ApiKey) {
|
||||
if (New-Settings -BaseUrl $BaseUrl -ApiKey $ApiKey) {
|
||||
Write-Host ""
|
||||
Write-Success "Codex has been configured successfully!"
|
||||
Write-Info "You can now use Codex with your XCodeCLI API router."
|
||||
|
||||
Reference in New Issue
Block a user