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 lines11121314151610 unmodified lines# API 鉴权(不设置则不启用,任何人都可访问)API_KEY=# 轮询配置EMAIL_POLL_INTERVAL=3EMAIL_POLL_TIMEOUT=30010 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=300
123456services:autoteam:build: .ports:- "8787:8787"volumes:12345678services:autoteam:build: .extra_hosts:- "host.docker.internal:host-gateway"ports:- "8787:8787"volumes:
16 unmodified lines1718192021222324252616 unmodified lines| `CPA_URL` | CLIProxyAPI 地址 | 否(默认 `http://127.0.0.1:8317`) || `CPA_KEY` | CPA 管理密钥 | 是 || `API_KEY` | Web 面板 / API 鉴权密钥 | 否(首次启动自动生成) || `AUTO_CHECK_THRESHOLD` | 额度低于此百分比触发轮转 | 否(默认 `10`) || `AUTO_CHECK_INTERVAL` | 巡检间隔(秒) | 否(默认 `300`) || `AUTO_CHECK_MIN_LOW` | 至少几个账号低于阈值才触发 | 否(默认 `2`) |### 内联注释`.env` 支持尾部内联注释,例如: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 lines118119120121122123117 unmodified lines直接打开 `http://your-server:8787`,会显示配置向导页面,在浏览器中填写。## 第三步:管理员登录配置完成后,需要先用 ChatGPT Team 管理员账号登录。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 lines40414243444546474849117 unmodified lines16716816917017117239 unmodified lines### Codex OAuth 登录失败:未获取到 authorization code常见原因:1. **IP 被标记** — VPS 的 IP 被 OpenAI / Cloudflare 拦截,建议换住宅代理2. **Cloudflare 验证** — 浏览器环境被检测,需更新 Chromium 或切换网络3. **workspace 选择失败** — 页面结构变化,查看 `screenshots/codex_04_*.png`4. **自动回调不可达** — 如果浏览器和 AutoTeam 不在同一台机器,`localhost:1455` 回调可能不会到达 AutoTeam,此时请改用手动粘贴回调 URL### 登录后 plan 显示 free 而不是 team117 unmodified lines- ./data:/app/data```## Web 面板相关### 页面显示 `JSON parse error`39 unmodified lines4041424344454647484950117 unmodified lines16816917017117217317417517617717817918018118218318418518618718818919019119219319419539 unmodified lines### Codex OAuth 登录失败:未获取到 authorization code常见原因: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 而不是 team117 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 lines74757677787925 unmodified lines10510610710810911011111273 unmodified linesCLOUDMAIL_DOMAIN: str = ""CPA_URL: str = "http://127.0.0.1:8317"CPA_KEY: str = ""API_KEY: str = ""25 unmodified linesif not data.get("API_KEY"):data["API_KEY"] = _secrets.token_urlsafe(24)for key, value in data.items():if value:_write_env(key, value)os.environ[key] = value73 unmodified lines747576777879808125 unmodified lines10710810911011111211311411573 unmodified linesCLOUDMAIL_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 linesif 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 or key in clearable_fields:_write_env(key, value)os.environ[key] = value
16 unmodified lines17181920212291 unmodified lines11411511611711811912012112212316 unmodified linesget_chatgpt_workspace_name,update_admin_state,)from autoteam.textio import read_textlogger = logging.getLogger(__name__)91 unmodified linesdef _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.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",16 unmodified lines1718192021222391 unmodified lines11511611711811912012116 unmodified linesget_chatgpt_workspace_name,update_admin_state,)from autoteam.config import get_playwright_launch_optionsfrom autoteam.textio import read_textlogger = logging.getLogger(__name__)91 unmodified linesdef _launch_browser(self):SCREENSHOT_DIR.mkdir(exist_ok=True)self.playwright = sync_playwright().start()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 lines202122232425239 unmodified lines26526626726826927027127227327419 unmodified linesget_chatgpt_workspace_name,)from autoteam.auth_storage import AUTH_DIR, ensure_auth_dir, ensure_auth_file_permissionsfrom autoteam.textio import write_textlogger = logging.getLogger(__name__)239 unmodified linesauth_code = Nonewith sync_playwright() as p:browser = p.chromium.launch(headless=False,args=["--disable-blink-features=AutomationControlled", "--no-sandbox"],)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",19 unmodified lines20212223242526239 unmodified lines26626726826927027127219 unmodified linesget_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_textlogger = logging.getLogger(__name__)239 unmodified linesauth_code = Nonewith sync_playwright() as p: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 line23456738 unmodified lines4647481 unmodified lineimport osfrom pathlib import Pathfrom autoteam.textio import parse_env_line, parse_env_value, read_text38 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) # 至少几个账号低于阈值才触发,默认 21 unmodified line234567838 unmodified lines47484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081 unmodified lineimport osfrom pathlib import Pathfrom urllib.parse import unquote, urlsplitfrom autoteam.textio import parse_env_line, parse_env_value, read_text38 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 hostnamedef _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 proxydef get_playwright_launch_options():"""统一的 Playwright Chromium 启动参数。"""options = {"headless": False,"args": ["--disable-blink-features=AutomationControlled", "--no-sandbox"],}proxy = Noneif 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_USERNAMEif PLAYWRIGHT_PROXY_PASSWORD:proxy["password"] = PLAYWRIGHT_PROXY_PASSWORDif proxy:if PLAYWRIGHT_PROXY_BYPASS:proxy["bypass"] = PLAYWRIGHT_PROXY_BYPASSoptions["proxy"] = proxyreturn options
25 unmodified lines262728293031371 unmodified lines40340440540640740840941041141225 unmodified linesfrom autoteam.chatgpt_api import ChatGPTTeamAPIfrom autoteam.cloudmail import CloudMailClientlogger = logging.getLogger(__name__)371 unmodified lineslogger.info("[邀请] 开始注册 ChatGPT 账号")with sync_playwright() as p:browser = p.chromium.launch(headless=False,args=["--disable-blink-features=AutomationControlled", "--no-sandbox"],)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",25 unmodified lines26272829303132371 unmodified lines40440540640740840941025 unmodified linesfrom autoteam.chatgpt_api import ChatGPTTeamAPIfrom autoteam.cloudmail import CloudMailClientfrom autoteam.config import get_playwright_launch_optionslogger = logging.getLogger(__name__)371 unmodified lineslogger.info("[邀请] 开始注册 ChatGPT 账号")with sync_playwright() as p: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 lines575859606162602 unmodified lines665666667668669670671672673674465 unmodified lines1140114111421143114411451146114711481149115011511152350 unmodified lines150315041505150615071508150915101511151256 unmodified linesrefresh_main_auth_file,save_auth_file,)from autoteam.cpa_sync import sync_from_cpa, sync_main_codex_to_cpa, sync_to_cpafrom autoteam.textio import read_text, write_text602 unmodified lineslogger.info("[注册] 开始注册 %s...", email)with sync_playwright() as p:browser = p.chromium.launch(headless=False,args=["--disable-blink-features=AutomationControlled", "--no-sandbox"],)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 linessignup_url = "https://chatgpt.com/auth/login"with sync_playwright() as p:launch_kwargs = {"headless": False,"args": ["--disable-blink-features=AutomationControlled", "--no-sandbox"],}if sys.platform.startswith("win"):launch_kwargs["slow_mo"] = 100browser = p.chromium.launch(**launch_kwargs)context = browser.new_context(viewport={"width": 1280, "height": 800},350 unmodified lineschatgpt_api.stop()with sync_playwright() as p:browser = p.chromium.launch(headless=False,args=["--disable-blink-features=AutomationControlled", "--no-sandbox"],)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 lines666667668669670671672465 unmodified lines113811391140114111421143114411451146350 unmodified lines149714981499150015011502150356 unmodified linesrefresh_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_text602 unmodified lineslogger.info("[注册] 开始注册 %s...", email)with sync_playwright() as p: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 linessignup_url = "https://chatgpt.com/auth/login"with sync_playwright() as p:launch_kwargs = get_playwright_launch_options()if sys.platform.startswith("win"):launch_kwargs["slow_mo"] = 100browser = p.chromium.launch(**launch_kwargs)context = browser.new_context(viewport={"width": 1280, "height": 800},350 unmodified lineschatgpt_api.stop()with sync_playwright() as p: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 lines22232425262751 unmodified lines7980818283848521 unmodified lines("CLOUDMAIL_DOMAIN", "CloudMail 邮箱域名(如 @example.com)", "", False),("CPA_URL", "CPA (CLIProxyAPI) 地址", "http://127.0.0.1:8317", True),("CPA_KEY", "CPA 管理密钥", "", False),("API_KEY", "API 鉴权密钥(回车自动生成)", "", True),]51 unmodified linesfor key, prompt, default, optional in REQUIRED_CONFIGS:val = env.get(key, "") or os.environ.get(key, "")if not val:missing.append((key, prompt, default, optional))if not missing:21 unmodified lines222324252627282951 unmodified lines8182838485868721 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 linesfor key, prompt, default, optional in REQUIRED_CONFIGS:val = env.get(key, "") or os.environ.get(key, "")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