Spaces:
Paused
Paused
Zhi Yang commited on
Commit ·
fcb2d84
1
Parent(s): 9af49ff
feat: support Playwright proxy configuration
Browse filesFiles changed (12)
- .env.example+6
- docker-compose.yml+2
- docs/configuration.md+24
- docs/getting-started.md+20
- docs/troubleshooting.md+24-1
- src/autoteam/api.py+4-1
- src/autoteam/chatgpt_api.py+2-4
- src/autoteam/codex_auth.py+2-4
- src/autoteam/config.py+60
- src/autoteam/invite.py+2-4
- src/autoteam/manager.py+4-13
- src/autoteam/setup_wizard.py+3-1
10 unmodified lines11121314151617181920212210 unmodified lines# API 鉴权(不设置则不启用,任何人都可访问)API_KEY=
# Playwright 浏览器代理(可选)# 示例:socks5://user:pass@host.docker.internal:1080PLAYWRIGHT_PROXY_URL=# 示例:localhost,127.0.0.1PLAYWRIGHT_PROXY_BYPASS=
# 轮询配置EMAIL_POLL_INTERVAL=3EMAIL_POLL_TIMEOUT=30012345678services: autoteam: build: . extra_hosts: - "host.docker.internal:host-gateway" ports: - "8787:8787" volumes:16 unmodified lines1718192021222324252627282930313233343536373839404142434445464748495016 unmodified lines| `CPA_URL` | CLIProxyAPI 地址 | 否(默认 `http://127.0.0.1:8317`) || `CPA_KEY` | CPA 管理密钥 | 是 || `API_KEY` | Web 面板 / API 鉴权密钥 | 否(首次启动自动生成) || `PLAYWRIGHT_PROXY_URL` | Playwright 浏览器代理 URL,如 `socks5://user:pass@host:port` | 否 || `PLAYWRIGHT_PROXY_BYPASS` | Playwright 代理绕过列表,如 `localhost,127.0.0.1` | 否 || `AUTO_CHECK_THRESHOLD` | 额度低于此百分比触发轮转 | 否(默认 `10`) || `AUTO_CHECK_INTERVAL` | 巡检间隔(秒) | 否(默认 `300`) || `AUTO_CHECK_MIN_LOW` | 至少几个账号低于阈值才触发 | 否(默认 `2`) |
## Playwright 代理
AutoTeam 的浏览器流量(ChatGPT 登录、邀请接受、Codex OAuth 等)现在支持单独配置代理。
推荐优先使用一个环境变量:
```dotenvPLAYWRIGHT_PROXY_URL=socks5://host.docker.internal:1080PLAYWRIGHT_PROXY_BYPASS=localhost,127.0.0.1```
如果代理需要认证,也可以直接写进 URL:
```dotenvPLAYWRIGHT_PROXY_URL=socks5://username:password@host.docker.internal:1080```
说明:
- `PLAYWRIGHT_PROXY_URL` 会被解析为 Playwright 所需的 `server` / `username` / `password` 字段- `PLAYWRIGHT_PROXY_BYPASS` 建议至少包含 `localhost,127.0.0.1`,避免本地回调或容器内本地服务误走代理
### 内联注释
`.env` 支持尾部内联注释,例如:117 unmodified lines118119120121122123124125126127128129130131132133134135136137138139140141142143117 unmodified lines
直接打开 `http://your-server:8787`,会显示配置向导页面,在浏览器中填写。
如果你需要让浏览器流量走宿主机 SOCKS5 代理,在 Linux Docker 下还需要给容器增加:
```yamlextra_hosts: - "host.docker.internal:host-gateway"```
然后在 `data/.env` 中加入:
```dotenvPLAYWRIGHT_PROXY_URL=socks5://host.docker.internal:1080PLAYWRIGHT_PROXY_BYPASS=localhost,127.0.0.1```
如果代理需要认证,可以写成:
```dotenvPLAYWRIGHT_PROXY_URL=socks5://username:password@host.docker.internal:1080```
## 第三步:管理员登录
配置完成后,需要先用 ChatGPT Team 管理员账号登录。39 unmodified lines404142434344454647484950117 unmodified lines16816917017117217317417517617717817918018118218318418518618718818919019119219319419539 unmodified lines### Codex OAuth 登录失败:未获取到 authorization code
常见原因:1. **IP 被标记** — VPS 的 IP 被 OpenAI / Cloudflare 拦截,建议换住宅代理1. **IP 被标记** — VPS 的 IP 被 OpenAI/Cloudflare 拦截,建议换住宅代理2. **Cloudflare 验证** — 浏览器环境被检测,需更新 Chromium 或切换网络3. **workspace 选择失败** — 页面结构变化,查看 `screenshots/codex_04_*.png`4. **自动回调不可达** — 如果浏览器和 AutoTeam 不在同一台机器,`localhost:1455` 回调可能不会到达 AutoTeam,此时请改用手动粘贴回调 URL5. **本地回调被代理拦截** — 如果启用了 `PLAYWRIGHT_PROXY_URL`,建议同时设置 `PLAYWRIGHT_PROXY_BYPASS=localhost,127.0.0.1`
### 登录后 plan 显示 free 而不是 team
117 unmodified lines - ./data:/app/data```
### 容器里访问不到宿主机 SOCKS5 代理
如果代理在宿主机上,比如 `host.docker.internal:1080`,Linux Docker 需要给容器补一条 host-gateway 映射:
```yamlextra_hosts: - "host.docker.internal:host-gateway"```
然后在 `data/.env` 中配置:
```dotenvPLAYWRIGHT_PROXY_URL=socks5://host.docker.internal:1080PLAYWRIGHT_PROXY_BYPASS=localhost,127.0.0.1```
如果代理需要认证,可以直接写成:
```dotenvPLAYWRIGHT_PROXY_URL=socks5://username:password@host.docker.internal:1080```
## Web 面板相关
### 页面显示 `JSON parse error`73 unmodified lines747576777879808125 unmodified lines10710810911011110911211311411573 unmodified lines CLOUDMAIL_DOMAIN: str = "" CPA_URL: str = "http://127.0.0.1:8317" CPA_KEY: str = "" PLAYWRIGHT_PROXY_URL: str = "" PLAYWRIGHT_PROXY_BYPASS: str = "" API_KEY: str = ""
25 unmodified lines if not data.get("API_KEY"): data["API_KEY"] = _secrets.token_urlsafe(24)
clearable_fields = {"PLAYWRIGHT_PROXY_URL", "PLAYWRIGHT_PROXY_BYPASS"} for key, value in data.items(): if value: if value or key in clearable_fields: _write_env(key, value) os.environ[key] = value
16 unmodified lines1718192021222391 unmodified lines11511611711711811912011811912012116 unmodified lines get_chatgpt_workspace_name, update_admin_state,)from autoteam.config import get_playwright_launch_optionsfrom autoteam.textio import read_text
logger = logging.getLogger(__name__)91 unmodified lines def _launch_browser(self): SCREENSHOT_DIR.mkdir(exist_ok=True) self.playwright = sync_playwright().start() self.browser = self.playwright.chromium.launch( headless=False, args=["--disable-blink-features=AutomationControlled", "--no-sandbox"], ) self.browser = self.playwright.chromium.launch(**get_playwright_launch_options()) self.context = self.browser.new_context( viewport={"width": 1280, "height": 800}, user_agent="Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/146.0.0.0 Safari/537.36",19 unmodified lines20212223242526239 unmodified lines26626726826826927027126927027127219 unmodified lines get_chatgpt_workspace_name,)from autoteam.auth_storage import AUTH_DIR, ensure_auth_dir, ensure_auth_file_permissionsfrom autoteam.config import get_playwright_launch_optionsfrom autoteam.textio import write_text
logger = logging.getLogger(__name__)239 unmodified lines auth_code = None
with sync_playwright() as p: browser = p.chromium.launch( headless=False, args=["--disable-blink-features=AutomationControlled", "--no-sandbox"], ) browser = p.chromium.launch(**get_playwright_launch_options()) context = browser.new_context( viewport={"width": 1280, "height": 800}, user_agent="Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/146.0.0.0 Safari/537.36",1 unmodified line234567838 unmodified lines47484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081 unmodified line
import osfrom pathlib import Pathfrom urllib.parse import unquote, urlsplit
from autoteam.textio import parse_env_line, parse_env_value, read_text
38 unmodified linesAUTO_CHECK_INTERVAL = _get_int_env("AUTO_CHECK_INTERVAL", 300) # 巡检间隔(秒),默认 5 分钟AUTO_CHECK_THRESHOLD = _get_int_env("AUTO_CHECK_THRESHOLD", 10) # 额度低于此百分比触发轮转,默认 10%AUTO_CHECK_MIN_LOW = _get_int_env("AUTO_CHECK_MIN_LOW", 2) # 至少几个账号低于阈值才触发,默认 2
# Playwright 代理配置PLAYWRIGHT_PROXY_URL = os.environ.get("PLAYWRIGHT_PROXY_URL", "").strip()PLAYWRIGHT_PROXY_SERVER = os.environ.get("PLAYWRIGHT_PROXY_SERVER", "").strip()PLAYWRIGHT_PROXY_USERNAME = os.environ.get("PLAYWRIGHT_PROXY_USERNAME", "").strip()PLAYWRIGHT_PROXY_PASSWORD = os.environ.get("PLAYWRIGHT_PROXY_PASSWORD", "").strip()PLAYWRIGHT_PROXY_BYPASS = os.environ.get("PLAYWRIGHT_PROXY_BYPASS", "").strip()
def _format_proxy_host(hostname: str) -> str: if ":" in hostname and not hostname.startswith("["): return f"[{hostname}]" return hostname
def _parse_proxy_url(proxy_url: str): if "://" not in proxy_url: return {"server": proxy_url}
parsed = urlsplit(proxy_url) if not parsed.scheme or not parsed.hostname: return {"server": proxy_url}
host = _format_proxy_host(parsed.hostname) server = f"{parsed.scheme}://{host}" if parsed.port: server = f"{server}:{parsed.port}"
proxy = {"server": server} if parsed.username: proxy["username"] = unquote(parsed.username) if parsed.password: proxy["password"] = unquote(parsed.password) return proxy
def get_playwright_launch_options(): """统一的 Playwright Chromium 启动参数。""" options = { "headless": False, "args": ["--disable-blink-features=AutomationControlled", "--no-sandbox"], }
proxy = None if PLAYWRIGHT_PROXY_URL: proxy = _parse_proxy_url(PLAYWRIGHT_PROXY_URL) elif PLAYWRIGHT_PROXY_SERVER: proxy = {"server": PLAYWRIGHT_PROXY_SERVER} if PLAYWRIGHT_PROXY_USERNAME: proxy["username"] = PLAYWRIGHT_PROXY_USERNAME if PLAYWRIGHT_PROXY_PASSWORD: proxy["password"] = PLAYWRIGHT_PROXY_PASSWORD
if proxy: if PLAYWRIGHT_PROXY_BYPASS: proxy["bypass"] = PLAYWRIGHT_PROXY_BYPASS options["proxy"] = proxy
return options25 unmodified lines26272829303132371 unmodified lines40440540640640740840940740840941025 unmodified lines
from autoteam.chatgpt_api import ChatGPTTeamAPIfrom autoteam.cloudmail import CloudMailClientfrom autoteam.config import get_playwright_launch_options
logger = logging.getLogger(__name__)
371 unmodified lines logger.info("[邀请] 开始注册 ChatGPT 账号")
with sync_playwright() as p: browser = p.chromium.launch( headless=False, args=["--disable-blink-features=AutomationControlled", "--no-sandbox"], ) browser = p.chromium.launch(**get_playwright_launch_options()) context = browser.new_context( viewport={"width": 1280, "height": 800}, user_agent="Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/146.0.0.0 Safari/537.36",56 unmodified lines57585960616263602 unmodified lines666667668668669670671669670671672465 unmodified lines11381139114011431144114511461141114211431149114411451146350 unmodified lines1497149814991506150715081509150015011502150356 unmodified lines refresh_main_auth_file, save_auth_file,)from autoteam.config import get_playwright_launch_optionsfrom autoteam.cpa_sync import sync_from_cpa, sync_main_codex_to_cpa, sync_to_cpafrom autoteam.textio import read_text, write_text
602 unmodified lines
logger.info("[注册] 开始注册 %s...", email) with sync_playwright() as p: browser = p.chromium.launch( headless=False, args=["--disable-blink-features=AutomationControlled", "--no-sandbox"], ) browser = p.chromium.launch(**get_playwright_launch_options()) context = browser.new_context( viewport={"width": 1280, "height": 800}, user_agent="Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/146.0.0.0 Safari/537.36",465 unmodified lines signup_url = "https://chatgpt.com/auth/login"
with sync_playwright() as p: launch_kwargs = { "headless": False, "args": ["--disable-blink-features=AutomationControlled", "--no-sandbox"], } launch_kwargs = get_playwright_launch_options() if sys.platform.startswith("win"): launch_kwargs["slow_mo"] = 100
browser = p.chromium.launch(**launch_kwargs) context = browser.new_context( viewport={"width": 1280, "height": 800},350 unmodified lines chatgpt_api.stop()
with sync_playwright() as p: browser = p.chromium.launch( headless=False, args=["--disable-blink-features=AutomationControlled", "--no-sandbox"], ) browser = p.chromium.launch(**get_playwright_launch_options()) context = browser.new_context( viewport={"width": 1280, "height": 800}, user_agent="Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/146.0.0.0 Safari/537.36",21 unmodified lines222324252627282951 unmodified lines818283828485868721 unmodified lines ("CLOUDMAIL_DOMAIN", "CloudMail 邮箱域名(如 @example.com)", "", False), ("CPA_URL", "CPA (CLIProxyAPI) 地址", "http://127.0.0.1:8317", True), ("CPA_KEY", "CPA 管理密钥", "", False), ("PLAYWRIGHT_PROXY_URL", "Playwright 浏览器代理 URL(可选,如 socks5://host:port)", "", True), ("PLAYWRIGHT_PROXY_BYPASS", "Playwright 代理绕过列表(可选,如 localhost,127.0.0.1)", "", True), ("API_KEY", "API 鉴权密钥(回车自动生成)", "", True),]
51 unmodified lines
for key, prompt, default, optional in REQUIRED_CONFIGS: val = env.get(key, "") or os.environ.get(key, "") if not val: if not val and not optional: missing.append((key, prompt, default, optional))
if not missing:.env.example+6
docker-compose.yml+2
docs/configuration.md+24
docs/getting-started.md+20
docs/troubleshooting.md+24-1
src/autoteam/api.py+4-1
src/autoteam/chatgpt_api.py+2-4
src/autoteam/codex_auth.py+2-4
src/autoteam/config.py+60
src/autoteam/invite.py+2-4
src/autoteam/manager.py+4-13
src/autoteam/setup_wizard.py+3-1