File size: 2,621 Bytes
f3cdcbc
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
3c78d60
f3cdcbc
3c78d60
 
 
 
 
 
 
 
 
 
f3cdcbc
3c78d60
f3cdcbc
 
 
 
 
 
 
 
 
 
3c78d60
 
f3cdcbc
 
 
 
b59551d
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
f3cdcbc
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
4549e28
 
e3a08fa
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
#!/bin/bash
set -e

# Start script for Hugging Face Space
# Mounts the OpenSIN-Code repository if available

echo "πŸš€ Starting A2A Cloud Coder Agent..."

# Check for repo in common locations
REPO_PATHS=(
    "/workspace/OpenSIN-Code"
    "/home/user/project/OpenSIN-Code"
    "/home/user/OpenSIN-Code"
    "/project/OpenSIN-Code"
)

for path in "${REPO_PATHS[@]}"; do
    if [ -d "$path" ]; then
        echo "πŸ“ Found repository at $path"
        REPO_DIR="$path"
        break
    fi
done

# If not found, clone it using GITHUB_TOKEN
if [ -z "$REPO_DIR" ]; then
    echo "⚠️  No repository found. Cloning OpenSIN-Code..."
    mkdir -p /workspace
    if [ -n "$GITHUB_TOKEN" ]; then
        echo "πŸ”‘ Using GITHUB_TOKEN for authentication"
        git clone "https://x-access-token:${GITHUB_TOKEN}@github.com/OpenSIN-AI/OpenSIN-Code.git" /workspace/OpenSIN-Code
    else
        echo "❌ GITHUB_TOKEN not set - cannot clone repository"
        echo "   Please set GITHUB_TOKEN in Space secrets"
        exit 1
    fi
    REPO_DIR="/workspace/OpenSIN-Code"
    echo "βœ… Repository cloned to $REPO_DIR"
fi

# Export for Python code
export REPO_DIR

# Create opencode config if not present (uses OCI fallback proxy)
mkdir -p ~/.config/opencode
if [ ! -f ~/.config/opencode/opencode.json ]; then
  cat > ~/.config/opencode/opencode.json << 'EOF'
{
  "model": "opencode/qwen3.6-plus-free",
  "fallback": "opencode/minimax-m2.5-free",
  "provider": {
    "openai": {
      "options": {
        "baseUrl": "http://92.5.60.87:4100/v1"
      },
      "models": {
        "qwen3.6-plus-free": {
          "name": "Qwen 3.5 Plus Free",
          "id": "qwen3.6-plus-free",
          "limit": {
            "context": 32000,
            "output": 8000
          }
        },
        "minimax-m2.5-free": {
          "name": "MiniMax M2.5 Free",
          "id": "minimax-m2.5-free",
          "limit": {
            "context": 32000,
            "output": 8000
          }
        }
      }
    }
  }
}
EOF
  echo "βœ… Created opencode config (using OCI fallback proxy)"
fi

# Check opencode availability
if command -v opencode &> /dev/null; then
    echo "βœ… opencode CLI found"
    opencode --version
else
    echo "❌ opencode CLI not found. Agent will fail to generate code."
fi

# Check GitHub token
if [ -z "$GITHUB_TOKEN" ]; then
    echo "⚠️  GITHUB_TOKEN not set - commits will fail"
else
    echo "βœ… GITHUB_TOKEN set"
fi

# Start the application with uvicorn directly
echo "🎯 Starting uvicorn on port ${PORT:-7860}"
exec python -m uvicorn main:app --host 0.0.0.0 --port ${PORT:-7860} --log-level info