跳到主要内容

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

浏览文件

macos_phone_desktop.go

79 行 · 2.6 KB历史下载
1package workbench
2
3import (
4 "bytes"
5 "context"
6 "encoding/base64"
7 "encoding/json"
8 "image/jpeg"
9 "net/http"
10)
11
12// The phone uses its own host-generated secret on the private signed GUI agent.
13// The ordinary desktop window endpoint cannot submit these actions.
14func (s *Server) macOSPhoneDesktop(ctx context.Context, token, op string, input phoneSurfaceInput) ([]byte, int, error) {
15 if token == "" {
16 return nil, http.StatusGone, nil
17 }
18 out, err := s.macOSWindowCall(ctx, macOSWindowRequest{Action: "phone-" + op, Phone: &input, PhoneToken: token})
19 if err != nil {
20 return nil, http.StatusBadGateway, err
21 }
22 return macOSPhoneDesktopReply(out, op, input.ID)
23}
24
25func macOSPhoneDesktopReply(out []byte, op, id string) ([]byte, int, error) {
26 limit := 4096
27 if op == "frame" {
28 limit = 3 << 20
29 }
30 var reply struct {
31 Error string `json:"error"`
32 ID string `json:"id"`
33 Document string `json:"document"`
34 Image string `json:"image"`
35 Width int `json:"width"`
36 Height int `json:"height"`
37 ContentWidth float64 `json:"content_width"`
38 ContentHeight float64 `json:"content_height"`
39 }
40 if len(out) > limit || json.Unmarshal(out, &reply) != nil {
41 return nil, http.StatusBadGateway, nil
42 }
43 if reply.Error != "" {
44 status := http.StatusBadGateway
45 switch reply.Error {
46 case "phone_session_ended", "gui_session_changed", "requires_gui_login":
47 status = http.StatusGone
48 case "window_changed", "phone_document_changed", "phone_focus_changed", "not_running", "no_visible_window":
49 status = http.StatusConflict
50 case "screen_recording_permission", "accessibility_permission":
51 status = http.StatusForbidden
52 case "invalid_input":
53 status = http.StatusBadRequest
54 case "not_installed":
55 status = http.StatusNotImplemented
56 }
57 return nil, status, nil
58 }
59 if reply.ID != id {
60 return nil, http.StatusBadGateway, nil
61 }
62 if op == "frame" {
63 if reply.Document == "" || len(reply.Document) > 128 || reply.Width < 240 || reply.Width > 1440 || reply.Height < 160 || reply.Height > 1600 {
64 return nil, http.StatusBadGateway, nil
65 }
66 if reply.ContentWidth <= 0 || reply.ContentWidth > 2560 || reply.ContentHeight <= 0 || reply.ContentHeight > 1600 {
67 return nil, http.StatusBadGateway, nil
68 }
69 image, err := base64.StdEncoding.DecodeString(reply.Image)
70 if err != nil {
71 return nil, http.StatusBadGateway, nil
72 }
73 config, err := jpeg.DecodeConfig(bytes.NewReader(image))
74 if err != nil || config.Width < 1 || config.Height < 1 || config.Width > 5120 || config.Height > 3200 {
75 return nil, http.StatusBadGateway, nil
76 }
77 }
78 return out, http.StatusOK, nil
79}