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:
@@ -25,6 +25,7 @@ print_error() {
|
||||
# Default values
|
||||
TEST_ONLY=false
|
||||
SHOW_SETTINGS=false
|
||||
DEFAULT_BASE_URL="https://api2.xcodecli.com"
|
||||
|
||||
# ========== Shell 环境变量配置 ==========
|
||||
# 检测当前 shell 配置文件
|
||||
@@ -179,9 +180,59 @@ backup_config() {
|
||||
fi
|
||||
}
|
||||
|
||||
# Function to test API connection and return working base URL
|
||||
test_api_connection() {
|
||||
local api_key="$1"
|
||||
|
||||
local test_urls=(
|
||||
"https://api2.xcodecli.com"
|
||||
"https://api.xcodecli.com"
|
||||
)
|
||||
|
||||
print_info "Testing API connections..." >&2
|
||||
|
||||
for base_url in "${test_urls[@]}"; do
|
||||
print_info "Testing $base_url..." >&2
|
||||
|
||||
local test_endpoint="$base_url/v1/models"
|
||||
|
||||
local response
|
||||
response=$(curl -s -w "%{http_code}" -o /tmp/codex_test_response \
|
||||
-X GET "$test_endpoint" \
|
||||
-H "Content-Type: application/json" \
|
||||
-H "Authorization: Bearer $api_key" \
|
||||
2>/dev/null || echo "000")
|
||||
|
||||
if [ "$response" = "200" ]; then
|
||||
if grep -qE '"data".*\[|"object"' /tmp/codex_test_response 2>/dev/null; then
|
||||
local model_count
|
||||
model_count=$(grep -oE '"id"[[:space:]]*:' /tmp/codex_test_response | wc -l | tr -d ' ')
|
||||
print_success "API connection successful! Found $model_count models at $base_url" >&2
|
||||
rm -f /tmp/codex_test_response
|
||||
echo "$base_url"
|
||||
return 0
|
||||
else
|
||||
print_warning "API responded but no models found at $base_url" >&2
|
||||
fi
|
||||
elif [ "$response" = "401" ]; then
|
||||
print_warning "API key authentication failed for $base_url" >&2
|
||||
elif [ "$response" = "000" ]; then
|
||||
print_warning "Cannot connect to $base_url" >&2
|
||||
else
|
||||
print_warning "API test failed for $base_url with HTTP status: $response" >&2
|
||||
fi
|
||||
|
||||
rm -f /tmp/codex_test_response
|
||||
done
|
||||
|
||||
print_error "All API connections failed. Please check your API key and internet connection." >&2
|
||||
return 1
|
||||
}
|
||||
|
||||
# Function to create Codex configuration
|
||||
create_codex_config() {
|
||||
local api_key="$1"
|
||||
local base_url="$1"
|
||||
local api_key="$2"
|
||||
|
||||
# Create config directory if it doesn't exist
|
||||
mkdir -p "$HOME/.codex"
|
||||
@@ -189,14 +240,14 @@ create_codex_config() {
|
||||
# Create config.toml
|
||||
cat >"$HOME/.codex/config.toml" <<EOF
|
||||
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 = "${base_url}/v1"
|
||||
wire_api = "responses"
|
||||
requires_openai_auth = true
|
||||
env_key = "XCODECLI_OAI_KEY"
|
||||
@@ -302,42 +353,27 @@ main() {
|
||||
print_info "API Key: $masked_key"
|
||||
echo ""
|
||||
|
||||
# Test API connection with fixed URL
|
||||
local test_url="https://www.xcodecli.com/openai"
|
||||
print_info "Testing API connection to $test_url..."
|
||||
# Test API connection and get working base URL
|
||||
local BASE_URL
|
||||
BASE_URL=$(test_api_connection "$API_KEY")
|
||||
|
||||
local response
|
||||
response=$(curl -s -w "%{http_code}" -o /tmp/codex_test_response \
|
||||
-X GET "$test_url/models" \
|
||||
-H "Content-Type: application/json" \
|
||||
-H "Authorization: Bearer $API_KEY" \
|
||||
2>/dev/null || echo "000")
|
||||
|
||||
if [ "$response" = "200" ]; then
|
||||
print_success "API connection successful!"
|
||||
elif [ "$response" = "401" ]; then
|
||||
print_warning "API key authentication failed"
|
||||
if [ $? -ne 0 ] || [ -z "$BASE_URL" ]; then
|
||||
if [ "$TEST_ONLY" = true ]; then
|
||||
rm -f /tmp/codex_test_response
|
||||
exit 1
|
||||
fi
|
||||
read -p "Continue anyway? (y/N): " -n 1 -r
|
||||
|
||||
read -p "All API tests failed. Continue anyway? (y/N): " -n 1 -r
|
||||
echo
|
||||
if [[ ! $REPLY =~ ^[Yy]$ ]]; then
|
||||
print_info "Setup cancelled"
|
||||
rm -f /tmp/codex_test_response
|
||||
exit 1
|
||||
fi
|
||||
elif [ "$response" = "000" ]; then
|
||||
print_warning "Cannot connect to API endpoint"
|
||||
if [ "$TEST_ONLY" = true ]; then
|
||||
rm -f /tmp/codex_test_response
|
||||
exit 1
|
||||
fi
|
||||
|
||||
BASE_URL="$DEFAULT_BASE_URL"
|
||||
print_warning "Using default URL: $BASE_URL"
|
||||
else
|
||||
print_warning "API test returned HTTP status: $response"
|
||||
print_info "Selected working base URL: $BASE_URL"
|
||||
fi
|
||||
rm -f /tmp/codex_test_response
|
||||
|
||||
# Exit if test only
|
||||
if [ "$TEST_ONLY" = true ]; then
|
||||
@@ -349,7 +385,7 @@ main() {
|
||||
backup_config
|
||||
|
||||
# Create Codex configuration
|
||||
if ! create_codex_config "$API_KEY"; then
|
||||
if ! create_codex_config "$BASE_URL" "$API_KEY"; then
|
||||
print_error "Failed to create Codex configuration"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
Reference in New Issue
Block a user