feat: use correct DashScope API endpoint for Qwen OAuth
Based on ZeroClaw implementation study: - Change API endpoint from api.qwen.ai to dashscope.aliyuncs.com/compatible-mode/v1 - Update credentials file reference to oauth_creds.json - Add ZeroClaw native qwen-oauth provider documentation - Add API endpoints and models reference table - Update import script with correct endpoint and platform support - Add PicoClaw and NanoClaw platform configurations Key findings from ZeroClaw binary: - Native qwen-oauth provider with auto token refresh - Uses DashScope OpenAI-compatible endpoint - Reads ~/.qwen/oauth_creds.json directly Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -1,99 +1,202 @@
|
||||
#!/bin/bash
|
||||
# import-qwen-oauth.sh - Import Qwen OAuth to any platform
|
||||
# Usage: source import-qwen-oauth.sh && <platform-command>
|
||||
# Import FREE Qwen OAuth to any Claw platform
|
||||
# Usage: source import-qwen-oauth.sh [platform]
|
||||
#
|
||||
# Platforms:
|
||||
# zeroclaw - Native qwen-oauth provider (recommended, auto token refresh)
|
||||
# picoclaw - OpenAI-compatible import
|
||||
# openclaw - OpenAI-compatible import
|
||||
# nanobot - OpenAI-compatible import
|
||||
# nanoclaw - OpenAI-compatible import
|
||||
#
|
||||
# Requirements:
|
||||
# - qwen-code CLI installed: npm install -g @qwen-code/qwen-code@latest
|
||||
# - jq for JSON parsing
|
||||
# - Authenticated: qwen --auth-type qwen-oauth -p "test"
|
||||
|
||||
set -e
|
||||
|
||||
echo "╔═══════════════════════════════════════════════════════════════╗"
|
||||
echo "║ QWEN OAUTH CROSS-PLATFORM IMPORTER ║"
|
||||
echo "║ FREE: 2,000 requests/day, 60 req/min ║"
|
||||
echo "╚═══════════════════════════════════════════════════════════════╝"
|
||||
CREDS_FILE="$HOME/.qwen/oauth_creds.json"
|
||||
PLATFORM="${1:-zeroclaw}"
|
||||
|
||||
# Check if Qwen Code is installed
|
||||
if ! command -v qwen &> /dev/null; then
|
||||
echo "📦 Qwen Code not found. Installing..."
|
||||
npm install -g @qwen-code/qwen-code@latest
|
||||
fi
|
||||
# Colors
|
||||
RED='\033[0;31m'
|
||||
GREEN='\033[0;32m'
|
||||
YELLOW='\033[1;33m'
|
||||
NC='\033[0m' # No Color
|
||||
|
||||
# Check if Qwen Code is authenticated
|
||||
if [ ! -d ~/.qwen ]; then
|
||||
echo "🦞 Claw Setup - Qwen OAuth Import"
|
||||
echo "=================================="
|
||||
echo ""
|
||||
|
||||
# Check for credentials file
|
||||
if [ ! -f "$CREDS_FILE" ]; then
|
||||
echo -e "${RED}Error: Qwen OAuth credentials not found${NC}"
|
||||
echo "File expected at: $CREDS_FILE"
|
||||
echo ""
|
||||
echo "❌ Qwen Code not authenticated."
|
||||
echo "To authenticate, run:"
|
||||
echo " npm install -g @qwen-code/qwen-code@latest"
|
||||
echo " qwen --auth-type qwen-oauth -p 'test'"
|
||||
echo ""
|
||||
echo "Please run:"
|
||||
echo " qwen"
|
||||
echo " /auth # Select 'Qwen OAuth'"
|
||||
echo ""
|
||||
echo "Then run this script again."
|
||||
echo "This will open a browser for FREE OAuth login."
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# Find OAuth token file
|
||||
TOKEN_FILES=$(find ~/.qwen -name "*.json" -type f 2>/dev/null)
|
||||
if [ -z "$TOKEN_FILES" ]; then
|
||||
echo "❌ No OAuth token found in ~/.qwen/"
|
||||
echo " Please authenticate first: qwen && /auth"
|
||||
exit 1
|
||||
# Check for jq
|
||||
if ! command -v jq &> /dev/null; then
|
||||
echo -e "${YELLOW}Warning: jq not found, using grep/sed fallback${NC}"
|
||||
QWEN_TOKEN=$(cat "$CREDS_FILE" | grep -o '"access_token"[[:space:]]*:[[:space:]]*"[^"]*"' | sed 's/.*"access_token"[[:space:]]*:[[:space:]]*"\([^"]*\)".*/\1/')
|
||||
else
|
||||
QWEN_TOKEN=$(cat "$CREDS_FILE" | jq -r '.access_token')
|
||||
fi
|
||||
|
||||
# Try to extract token from various file formats
|
||||
QWEN_TOKEN=""
|
||||
for TOKEN_FILE in $TOKEN_FILES; do
|
||||
# Try different JSON structures
|
||||
QWEN_TOKEN=$(cat "$TOKEN_FILE" | jq -r '.access_token // .token // .accessToken // .credentials?.token // empty' 2>/dev/null)
|
||||
if [ -n "$QWEN_TOKEN" ] && [ "$QWEN_TOKEN" != "null" ]; then
|
||||
echo "✅ Found token in: $TOKEN_FILE"
|
||||
break
|
||||
fi
|
||||
done
|
||||
|
||||
if [ -z "$QWEN_TOKEN" ] || [ "$QWEN_TOKEN" = "null" ]; then
|
||||
echo "❌ Could not extract OAuth token"
|
||||
echo " Token files found but no valid token structure"
|
||||
echo " Try re-authenticating: qwen && /auth"
|
||||
echo -e "${RED}Error: Could not extract access_token from credentials${NC}"
|
||||
echo "Credentials file may be corrupted. Try re-authenticating:"
|
||||
echo " qwen --auth-type qwen-oauth -p 'test'"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# Export environment variables
|
||||
export OPENAI_API_KEY="$QWEN_TOKEN"
|
||||
export OPENAI_BASE_URL="https://api.qwen.ai/v1"
|
||||
export OPENAI_MODEL="qwen3-coder-plus"
|
||||
echo "Platform: $PLATFORM"
|
||||
echo "Token: ${QWEN_TOKEN:0:20}..."
|
||||
echo ""
|
||||
|
||||
# Save to .env for persistence
|
||||
mkdir -p ~/.qwen
|
||||
cat > ~/.qwen/.env << ENVEOF
|
||||
# Qwen OAuth Configuration for Cross-Platform Use
|
||||
# Generated: $(date)
|
||||
OPENAI_API_KEY=$QWEN_TOKEN
|
||||
OPENAI_BASE_URL=https://api.qwen.ai/v1
|
||||
OPENAI_MODEL=qwen3-coder-plus
|
||||
case "$PLATFORM" in
|
||||
zeroclaw)
|
||||
# ZeroClaw uses native qwen-oauth provider
|
||||
CONFIG_FILE="$HOME/.zeroclaw/config.toml"
|
||||
|
||||
# Usage:
|
||||
# source ~/.qwen/.env && openclaw
|
||||
# source ~/.qwen/.env && nanobot gateway
|
||||
# source ~/.qwen/.env && picoclaw gateway
|
||||
# source ~/.qwen/.env && zeroclaw gateway
|
||||
ENVEOF
|
||||
if [ ! -f "$CONFIG_FILE" ]; then
|
||||
echo -e "${YELLOW}ZeroClaw config not found, creating...${NC}"
|
||||
mkdir -p "$HOME/.zeroclaw"
|
||||
cat > "$CONFIG_FILE" << 'EOF'
|
||||
default_provider = "qwen-oauth"
|
||||
default_model = "qwen3-coder-plus"
|
||||
default_temperature = 0.7
|
||||
|
||||
chmod 600 ~/.qwen/.env
|
||||
[autonomy]
|
||||
level = "supervised"
|
||||
workspace_only = true
|
||||
|
||||
[memory]
|
||||
backend = "sqlite"
|
||||
EOF
|
||||
else
|
||||
# Update existing config
|
||||
sed -i 's/^default_provider = .*/default_provider = "qwen-oauth"/' "$CONFIG_FILE"
|
||||
sed -i 's/^default_model = .*/default_model = "qwen3-coder-plus"/' "$CONFIG_FILE"
|
||||
fi
|
||||
|
||||
echo -e "${GREEN}✅ ZeroClaw configured with native qwen-oauth provider${NC}"
|
||||
echo ""
|
||||
echo "ZeroClaw automatically:"
|
||||
echo " • Reads ~/.qwen/oauth_creds.json"
|
||||
echo " • Refreshes expired tokens"
|
||||
echo " • Uses correct DashScope API endpoint"
|
||||
echo ""
|
||||
echo "Test with:"
|
||||
echo " zeroclaw agent -m 'Hello!'"
|
||||
;;
|
||||
|
||||
picoclaw)
|
||||
export OPENAI_API_KEY="$QWEN_TOKEN"
|
||||
export OPENAI_BASE_URL="https://dashscope.aliyuncs.com/compatible-mode/v1"
|
||||
|
||||
echo -e "${GREEN}✅ PicoClaw environment configured${NC}"
|
||||
echo ""
|
||||
echo "Environment variables set:"
|
||||
echo " OPENAI_API_KEY=${QWEN_TOKEN:0:20}..."
|
||||
echo " OPENAI_BASE_URL=https://dashscope.aliyuncs.com/compatible-mode/v1"
|
||||
echo ""
|
||||
echo "Test with:"
|
||||
echo " picoclaw agent -m 'Hello!'"
|
||||
;;
|
||||
|
||||
openclaw)
|
||||
export OPENAI_API_KEY="$QWEN_TOKEN"
|
||||
export OPENAI_BASE_URL="https://dashscope.aliyuncs.com/compatible-mode/v1"
|
||||
|
||||
echo -e "${GREEN}✅ OpenClaw environment configured${NC}"
|
||||
echo ""
|
||||
echo "Environment variables set:"
|
||||
echo " OPENAI_API_KEY=${QWEN_TOKEN:0:20}..."
|
||||
echo " OPENAI_BASE_URL=https://dashscope.aliyuncs.com/compatible-mode/v1"
|
||||
echo ""
|
||||
echo "Test with:"
|
||||
echo " openclaw"
|
||||
;;
|
||||
|
||||
nanobot)
|
||||
export OPENAI_API_KEY="$QWEN_TOKEN"
|
||||
export OPENAI_BASE_URL="https://dashscope.aliyuncs.com/compatible-mode/v1"
|
||||
export OPENAI_MODEL="qwen3-coder-plus"
|
||||
|
||||
echo -e "${GREEN}✅ NanoBot environment configured${NC}"
|
||||
echo ""
|
||||
echo "Environment variables set:"
|
||||
echo " OPENAI_API_KEY=${QWEN_TOKEN:0:20}..."
|
||||
echo " OPENAI_BASE_URL=https://dashscope.aliyuncs.com/compatible-mode/v1"
|
||||
echo " OPENAI_MODEL=qwen3-coder-plus"
|
||||
echo ""
|
||||
echo "Test with:"
|
||||
echo " nanobot"
|
||||
;;
|
||||
|
||||
nanoclaw)
|
||||
export OPENAI_API_KEY="$QWEN_TOKEN"
|
||||
export OPENAI_BASE_URL="https://dashscope.aliyuncs.com/compatible-mode/v1"
|
||||
|
||||
echo -e "${GREEN}✅ NanoClaw environment configured${NC}"
|
||||
echo ""
|
||||
echo "Environment variables set:"
|
||||
echo " OPENAI_API_KEY=${QWEN_TOKEN:0:20}..."
|
||||
echo " OPENAI_BASE_URL=https://dashscope.aliyuncs.com/compatible-mode/v1"
|
||||
echo ""
|
||||
echo "Test with:"
|
||||
echo " nanoclaw"
|
||||
;;
|
||||
|
||||
all)
|
||||
# Configure all platforms
|
||||
echo "Configuring all platforms..."
|
||||
echo ""
|
||||
|
||||
# ZeroClaw
|
||||
CONFIG_FILE="$HOME/.zeroclaw/config.toml"
|
||||
if [ -f "$CONFIG_FILE" ]; then
|
||||
sed -i 's/^default_provider = .*/default_provider = "qwen-oauth"/' "$CONFIG_FILE"
|
||||
sed -i 's/^default_model = .*/default_model = "qwen3-coder-plus"/' "$CONFIG_FILE"
|
||||
echo -e "${GREEN}✅ ZeroClaw${NC}"
|
||||
fi
|
||||
|
||||
# Set environment for other platforms
|
||||
export OPENAI_API_KEY="$QWEN_TOKEN"
|
||||
export OPENAI_BASE_URL="https://dashscope.aliyuncs.com/compatible-mode/v1"
|
||||
|
||||
echo -e "${GREEN}✅ PicoClaw, OpenClaw, NanoBot, NanoClaw${NC}"
|
||||
echo ""
|
||||
echo "Environment exported for current session."
|
||||
echo "Add to ~/.bashrc for persistence:"
|
||||
echo ""
|
||||
echo 'export OPENAI_API_KEY="$(cat ~/.qwen/oauth_creds.json | jq -r '\''.access_token'\'')"' >> ~/.bashrc
|
||||
echo 'export OPENAI_BASE_URL="https://dashscope.aliyuncs.com/compatible-mode/v1"' >> ~/.bashrc
|
||||
;;
|
||||
|
||||
*)
|
||||
# Generic - set environment variables
|
||||
export OPENAI_API_KEY="$QWEN_TOKEN"
|
||||
export OPENAI_BASE_URL="https://dashscope.aliyuncs.com/compatible-mode/v1"
|
||||
|
||||
echo -e "${GREEN}✅ Generic environment configured for $PLATFORM${NC}"
|
||||
echo ""
|
||||
echo "Environment variables set:"
|
||||
echo " OPENAI_API_KEY=${QWEN_TOKEN:0:20}..."
|
||||
echo " OPENAI_BASE_URL=https://dashscope.aliyuncs.com/compatible-mode/v1"
|
||||
;;
|
||||
esac
|
||||
|
||||
echo ""
|
||||
echo "✅ Qwen OAuth imported successfully!"
|
||||
echo ""
|
||||
echo " OPENAI_API_KEY=***${QWEN_TOKEN: -8}"
|
||||
echo " OPENAI_BASE_URL=$OPENAI_BASE_URL"
|
||||
echo " OPENAI_MODEL=$OPENAI_MODEL"
|
||||
echo ""
|
||||
echo "✅ Configuration saved to ~/.qwen/.env"
|
||||
echo ""
|
||||
echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━"
|
||||
echo "Usage with platforms:"
|
||||
echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━"
|
||||
echo ""
|
||||
echo " source ~/.qwen/.env && openclaw"
|
||||
echo " source ~/.qwen/.env && nanobot gateway"
|
||||
echo " source ~/.qwen/.env && picoclaw gateway"
|
||||
echo " source ~/.qwen/.env && zeroclaw gateway"
|
||||
echo ""
|
||||
echo "Free tier limits: 2,000 requests/day, 60 requests/minute"
|
||||
echo ""
|
||||
echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━"
|
||||
echo "FREE Qwen OAuth: 2,000 requests/day, 60 req/min"
|
||||
echo "API Endpoint: https://dashscope.aliyuncs.com/compatible-mode/v1"
|
||||
echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━"
|
||||
|
||||
Reference in New Issue
Block a user