跳到主要内容

Claude Cage · 面向 Claude 的隔离开发环境,支持桌面工作台、多账号、远程部署与移动端连接。上游 Lee-xeo/Claude-Cage 完整源码镜像,非灵栈原创;主许可 MIT,第三方组件遵循各自许可。来源:https://github.com/Lee-xeo/Claude-Cage 。手动同步,不附带 Release 安装包。

浏览文件

guest-wait-services.py

32 行 · 1.3 KB历史下载
1import json
2import time
3import urllib.error
4import urllib.request
5from pathlib import Path
6
7
8def wait(config_path='/etc/claude-cage/browser-control.json', endpoints=None, timeout=60):
9 token = json.loads(Path(config_path).read_text())['token']
10 endpoints = endpoints or (
11 ('http://127.0.0.1:18080/healthz', False),
12 ('http://127.0.0.1:16080/vnc.html', False),
13 ('http://127.0.0.1:18500/health', True),
14 )
15 opener = urllib.request.build_opener(urllib.request.ProxyHandler({}))
16 deadline = time.monotonic() + timeout
17 while time.monotonic() < deadline:
18 try:
19 for address, browser in endpoints:
20 headers = {'Authorization': 'Bearer ' + token} if browser else {}
21 request = urllib.request.Request(address, headers=headers)
22 with opener.open(request, timeout=2) as response:
23 if browser and json.loads(response.read(1024)).get('ready') is not True:
24 raise ValueError('Browser is starting')
25 return
26 except (OSError, ValueError, urllib.error.URLError):
27 time.sleep(1)
28 raise SystemExit('Cage browser, editor or display service did not become ready. Inspect the guest service logs and retry.')
29
30
31if __name__ == '__main__':
32 wait()