Private
Public Access
1
0

fix(script): redirect output to stderr and improve JSON creation

This commit is contained in:
2025-11-03 17:26:50 +08:00
parent 82153a5386
commit a2abc11082

View File

@@ -83,10 +83,10 @@ test_api_connection() {
"https://newapi.sususu.cf"
)
print_info "Testing API connections..."
print_info "Testing API connections..." >&2
for base_url in "${test_urls[@]}"; do
print_info "Testing $base_url..."
print_info "Testing $base_url..." >&2
local test_endpoint="$base_url/v1/models"
@@ -102,25 +102,25 @@ test_api_connection() {
local model_count
model_count=$(cat /tmp/claude_test_response | jq -r '.data | length' 2>/dev/null || echo "0")
if [ "$model_count" -gt "0" ]; then
print_success "API connection successful! Found $model_count models at $base_url"
print_success "API connection successful! Found $model_count models at $base_url" >&2
rm -f /tmp/claude_test_response
echo "$base_url"
return 0
else
print_warning "API responded but no models found at $base_url"
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"
print_warning "API key authentication failed for $base_url" >&2
elif [ "$response" = "000" ]; then
print_warning "Cannot connect to $base_url"
print_warning "Cannot connect to $base_url" >&2
else
print_warning "API test failed for $base_url with HTTP status: $response"
print_warning "API test failed for $base_url with HTTP status: $response" >&2
fi
rm -f /tmp/claude_test_response
done
print_error "All API connections failed. Please check your API key and internet connection."
print_error "All API connections failed. Please check your API key and internet connection." >&2
return 1
}
@@ -129,20 +129,21 @@ create_settings() {
local base_url="$1"
local api_key="$2"
# Create JSON using jq to ensure proper escaping
local settings_json
settings_json=$(cat <<EOF
{
settings_json=$(jq -n \
--arg base_url "$base_url" \
--arg api_key "$api_key" \
'{
"env": {
"ANTHROPIC_BASE_URL": "$base_url",
"ANTHROPIC_AUTH_TOKEN": "$api_key",
"ANTHROPIC_BASE_URL": $base_url,
"ANTHROPIC_AUTH_TOKEN": $api_key,
"DISABLE_TELEMETRY": 1,
"DISABLE_ERROR_REPORTING": 1,
"CLAUDE_CODE_DISABLE_NONESSENTIAL_TRAFFIC": 1,
"CLAUDE_CODE_DISABLE_NONESSENTIAL_TRAFFIC": 1
},
"model": "sonnet"
}
EOF
)
}')
# Validate JSON
if ! echo "$settings_json" | jq . > /dev/null 2>&1; then