Spaces:
Sleeping
Sleeping
File size: 2,413 Bytes
e3c39cb 255b3f8 e3c39cb 255b3f8 e3c39cb 5d73280 e3c39cb 019d647 255b3f8 5d73280 255b3f8 eadd45d 019d647 eadd45d 019d647 eadd45d 019d647 e3c39cb 865310c e3c39cb 255b3f8 e3c39cb eadd45d 865310c 8cad116 865310c 5d73280 019d647 5d73280 | 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 | #!/bin/bash
# --- 1. 配置 Git 凭证 ---
echo "Configuring Git credentials..."
git config --global user.email "moltbot@huggingface.co"
git config --global user.name "Moltbot Cloud"
git config --global credential.helper store
echo "https://${GIT_USER}:${GIT_TOKEN}@github.com" > ~/.git-credentials
# --- 2. 准备记忆仓库 ---
echo "Restoring memory from GitHub..."
if [ ! -d "moltbot-memory" ]; then
git clone https://github.com/${GIT_USER}/${GIT_REPO}.git moltbot-memory || echo "Clone failed..."
else
cd moltbot-memory && git pull && cd ..
fi
# --- 3. 记忆植入 (软链接) ---
APP_CONFIG_DIR="$HOME/.clawdbot"
if [ -d "$APP_CONFIG_DIR" ] && [ ! -L "$APP_CONFIG_DIR" ]; then rm -rf "$APP_CONFIG_DIR"; fi
if [ ! -L "$APP_CONFIG_DIR" ]; then ln -s "$(pwd)/moltbot-memory" "$APP_CONFIG_DIR"; fi
# --- 4. 🧠 修正配置注入 ---
echo "⚙️ Configuring Moltbot..."
# 尝试强制写入 OpenAI 兼容配置 (如果 Secrets 存在)
if [ -n "$OPENAI_API_KEY" ]; then
export CLAWDBOT_OPENAI_API_KEY="$OPENAI_API_KEY"
fi
if [ -n "$OPENAI_BASE_URL" ]; then
export CLAWDBOT_OPENAI_BASE_URL="$OPENAI_BASE_URL"
fi
# 尝试修正模型配置 Key
if [ -n "$GATEWAY_AGENT_MODEL" ]; then
echo "Updating Model to: $GATEWAY_AGENT_MODEL"
# 方案 A: 尝试设置全局 agent.model
npm exec -- moltbot config set agent.model "$GATEWAY_AGENT_MODEL" || true
# 方案 B: 尝试设置全局 model (以防万一)
npm exec -- moltbot config set model "$GATEWAY_AGENT_MODEL" || true
fi
# --- 5. 后台自动保存 ---
sync_memory() {
while true; do
sleep 300
if [ -d "moltbot-memory" ]; then
cd moltbot-memory
if [ -n "$(git status --porcelain)" ]; then
git add .
git commit -m "Auto-save: $(date)"
git push
fi
cd ..
fi
done
}
sync_memory &
# --- 6. 启动服务 ---
if [ -z "$GATEWAY_TOKEN" ]; then
export CLAWDBOT_GATEWAY_TOKEN=$(cat /proc/sys/kernel/random/uuid)
echo "⚠️ Random Token: $CLAWDBOT_GATEWAY_TOKEN"
else
export CLAWDBOT_GATEWAY_TOKEN="$GATEWAY_TOKEN"
fi
echo "🚀 Starting Moltbot on internal port 3000..."
# 启动 Moltbot
npm exec -- moltbot gateway --port 3000 --allow-unconfigured &
echo "🌉 Starting Socat Bridge (0.0.0.0:7860 -> 127.0.0.1:3000)..."
exec socat TCP-LISTEN:7860,fork,bind=0.0.0.0 TCP:127.0.0.1:3000 |