dsh-quay-bot 0.7.4 → 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +105 -28
- package/bin/doctor.mjs +148 -0
- package/botscreen/requirements-offline.txt +11 -0
- package/client.js +1 -2
- package/cordis.patch.yml +1 -1
- package/host/api.js +0 -4
- package/host/remote.js +2 -140
- package/host/screen.js +85 -21
- package/market/index.json +41 -0
- package/package.json +32 -13
- package/vendor/wheels/any/annotated_doc-0.0.7-py3-none-any.whl +0 -0
- package/vendor/wheels/any/annotated_types-0.8.0-py3-none-any.whl +0 -0
- package/vendor/wheels/any/anyio-4.16.0-py3-none-any.whl +0 -0
- package/vendor/wheels/any/certifi-2026.11.20-py3-none-any.whl +0 -0
- package/vendor/wheels/any/click-8.5.1-py3-none-any.whl +0 -0
- package/vendor/wheels/any/fastapi-0.165.0-py3-none-any.whl +0 -0
- package/vendor/wheels/any/h11-0.16.0-py3-none-any.whl +0 -0
- package/vendor/wheels/any/httpcore-1.0.9-py3-none-any.whl +0 -0
- package/vendor/wheels/any/httpx-0.29.0-py3-none-any.whl +0 -0
- package/vendor/wheels/any/idna-3.20-py3-none-any.whl +0 -0
- package/vendor/wheels/any/mss-10.2.0-py3-none-any.whl +0 -0
- package/vendor/wheels/any/opentelemetry_api-1.45.2-py3-none-any.whl +0 -0
- package/vendor/wheels/any/pydantic-2.14.4-py3-none-any.whl +0 -0
- package/vendor/wheels/any/python_multipart-0.0.34-py3-none-any.whl +0 -0
- package/vendor/wheels/any/python_xlib-0.33-py2.py3-none-any.whl +0 -0
- package/vendor/wheels/any/six-1.17.0-py2.py3-none-any.whl +0 -0
- package/vendor/wheels/any/starlette-1.10.0-py3-none-any.whl +0 -0
- package/vendor/wheels/any/typing_extensions-4.16.0-py3-none-any.whl +0 -0
- package/vendor/wheels/any/typing_inspection-0.4.5-py3-none-any.whl +0 -0
- package/vendor/wheels/any/uvicorn-0.54.0-py3-none-any.whl +0 -0
- package/vendor/wheels/linux-aarch64/pillow-12.2.0-cp312-cp312-manylinux2014_aarch64.manylinux_2_17_aarch64.whl +0 -0
- package/vendor/wheels/linux-aarch64/pydantic_core-2.50.5-cp312-cp312-manylinux2014_aarch64.manylinux_2_17_aarch64.whl +0 -0
- package/vendor/wheels/linux-aarch64/websockets-17.4-cp312-cp312-manylinux2014_aarch64.manylinux_2_17_aarch64.manylinux_2_28_aarch64.whl +0 -0
- package/vendor/wheels/linux-x86_64/pillow-12.2.0-cp312-cp312-manylinux2014_x86_64.manylinux_2_17_x86_64.whl +0 -0
- package/vendor/wheels/linux-x86_64/pydantic_core-2.50.5-cp312-cp312-manylinux2014_x86_64.manylinux_2_17_x86_64.whl +0 -0
- package/vendor/wheels/linux-x86_64/websockets-17.4-cp312-cp312-manylinux1_x86_64.manylinux_2_28_x86_64.manylinux_2_5_x86_64.whl +0 -0
- package/botscreen/botscreen/__init__.py +0 -2
- package/botscreen/botscreen/__main__.py +0 -5
- package/botscreen/botscreen/artifacts.py +0 -388
- package/botscreen/botscreen/audit.py +0 -94
- package/botscreen/botscreen/cgroup.py +0 -293
- package/botscreen/botscreen/config.py +0 -320
- package/botscreen/botscreen/desktop/assets/chrome.png +0 -0
- package/botscreen/botscreen/desktop/assets/codex.png +0 -0
- package/botscreen/botscreen/desktop/assets/drive.png +0 -0
- package/botscreen/botscreen/desktop/assets/folder.png +0 -0
- package/botscreen/botscreen/desktop/assets/search.png +0 -0
- package/botscreen/botscreen/desktop/assets/terminal.png +0 -0
- package/botscreen/botscreen/desktop/assets/trash.png +0 -0
- package/botscreen/botscreen/desktop/assets/wallpaper.png +0 -0
- package/botscreen/botscreen/desktop.py +0 -244
- package/botscreen/botscreen/driver.py +0 -832
- package/botscreen/botscreen/gateway.py +0 -2089
- package/botscreen/botscreen/iconlayer.py +0 -841
- package/botscreen/botscreen/mcp_server.py +0 -435
- package/botscreen/botscreen/resources.py +0 -494
- package/botscreen/botscreen/screen.py +0 -1282
- package/botscreen/botscreen/session.py +0 -706
- package/botscreen/botscreen/state.py +0 -330
- package/botscreen/botscreen/streamer.py +0 -388
- package/remote/bin/dsh-remote.mjs +0 -418
- package/remote/package.json +0 -27
- package/remote/src/config.mjs +0 -183
- package/remote/src/crypto.mjs +0 -220
- package/remote/src/keys.mjs +0 -226
- package/remote/src/proxy.mjs +0 -1028
- package/remote/src/sessions.mjs +0 -163
- package/remote/src/shim.js +0 -838
- package/remote/src/supervisor.mjs +0 -207
- package/remote/src/tunnel.mjs +0 -489
- package/remote/src/upstream.mjs +0 -372
- package/remote/src/util.mjs +0 -139
- package/remote/src/ws.mjs +0 -313
- package/requirements.txt +0 -8
|
@@ -1,435 +0,0 @@
|
|
|
1
|
-
"""BotScreen MCP Server(stdio,newline-delimited JSON-RPC 2.0)。
|
|
2
|
-
|
|
3
|
-
暴露给 Agent 的工具:
|
|
4
|
-
screen_screenshot / screen_click / screen_type_text / screen_key /
|
|
5
|
-
request_human_help / screen_status / screen_list / wait_human_release
|
|
6
|
-
|
|
7
|
-
网关只监听 127.0.0.1;本进程从每个 bot 的 runtime/token.json 读取 Agent Token。
|
|
8
|
-
"""
|
|
9
|
-
from __future__ import annotations
|
|
10
|
-
|
|
11
|
-
import base64
|
|
12
|
-
import json
|
|
13
|
-
import os
|
|
14
|
-
import sys
|
|
15
|
-
from typing import Any, Dict, List
|
|
16
|
-
|
|
17
|
-
import httpx
|
|
18
|
-
|
|
19
|
-
GATEWAY = os.environ.get("BOTSCREEN_GATEWAY", "http://127.0.0.1:6200")
|
|
20
|
-
DATA_ROOT = os.environ.get("BOTSCREEN_DATA_ROOT", "/data/botscreen")
|
|
21
|
-
PROTOCOL_VERSION = "2024-11-05"
|
|
22
|
-
|
|
23
|
-
TOOLS: List[Dict[str, Any]] = [
|
|
24
|
-
{
|
|
25
|
-
"name": "screen_screenshot",
|
|
26
|
-
"description": "截取指定 Bot 的虚拟屏(自动唤醒冻结屏)。返回 1280x720 图像。",
|
|
27
|
-
"inputSchema": {
|
|
28
|
-
"type": "object",
|
|
29
|
-
"properties": {
|
|
30
|
-
"bot_id": {"type": "string"},
|
|
31
|
-
"format": {"type": "string", "enum": ["jpeg", "webp", "png"], "default": "jpeg"},
|
|
32
|
-
"lease_epoch": {"type": "integer",
|
|
33
|
-
"description": "上次调用返回的 epoch;控制权被抢占后传旧值会得到 409"},
|
|
34
|
-
},
|
|
35
|
-
"required": ["bot_id"],
|
|
36
|
-
},
|
|
37
|
-
},
|
|
38
|
-
{
|
|
39
|
-
"name": "screen_click",
|
|
40
|
-
"description": "在虚拟屏坐标 (x,y) 上点击。人类接管时返回 423 锁定错误。",
|
|
41
|
-
"inputSchema": {
|
|
42
|
-
"type": "object",
|
|
43
|
-
"properties": {
|
|
44
|
-
"bot_id": {"type": "string"},
|
|
45
|
-
"x": {"type": "integer"},
|
|
46
|
-
"y": {"type": "integer"},
|
|
47
|
-
"button": {"type": "integer", "default": 1},
|
|
48
|
-
"double": {"type": "boolean", "default": False},
|
|
49
|
-
"lease_epoch": {"type": "integer"},
|
|
50
|
-
},
|
|
51
|
-
"required": ["bot_id", "x", "y"],
|
|
52
|
-
},
|
|
53
|
-
},
|
|
54
|
-
{
|
|
55
|
-
"name": "screen_type_text",
|
|
56
|
-
"description": "通过剪贴板粘贴输入文本(支持中文/emoji),可选回车提交。",
|
|
57
|
-
"inputSchema": {
|
|
58
|
-
"type": "object",
|
|
59
|
-
"properties": {
|
|
60
|
-
"bot_id": {"type": "string"},
|
|
61
|
-
"text": {"type": "string"},
|
|
62
|
-
"press_enter": {"type": "boolean", "default": False},
|
|
63
|
-
"lease_epoch": {"type": "integer"},
|
|
64
|
-
},
|
|
65
|
-
"required": ["bot_id", "text"],
|
|
66
|
-
},
|
|
67
|
-
},
|
|
68
|
-
{
|
|
69
|
-
"name": "screen_key",
|
|
70
|
-
"description": "发送快捷键组合,如 ctrl+l、Return、Page_Down、alt+F4。",
|
|
71
|
-
"inputSchema": {
|
|
72
|
-
"type": "object",
|
|
73
|
-
"properties": {
|
|
74
|
-
"bot_id": {"type": "string"},
|
|
75
|
-
"key_combo": {"type": "string"},
|
|
76
|
-
"lease_epoch": {"type": "integer"},
|
|
77
|
-
},
|
|
78
|
-
"required": ["bot_id", "key_combo"],
|
|
79
|
-
},
|
|
80
|
-
},
|
|
81
|
-
{
|
|
82
|
-
"name": "request_human_help",
|
|
83
|
-
"description": "Agent 主动求助(如验证码):状态切 NEED_HUMAN,推送通知等人接管。",
|
|
84
|
-
"inputSchema": {
|
|
85
|
-
"type": "object",
|
|
86
|
-
"properties": {"bot_id": {"type": "string"}, "reason": {"type": "string"}},
|
|
87
|
-
"required": ["bot_id", "reason"],
|
|
88
|
-
},
|
|
89
|
-
},
|
|
90
|
-
{
|
|
91
|
-
"name": "wait_human_release",
|
|
92
|
-
"description": "被 423 挡住后阻塞等待人类交还控制权。",
|
|
93
|
-
"inputSchema": {
|
|
94
|
-
"type": "object",
|
|
95
|
-
"properties": {
|
|
96
|
-
"bot_id": {"type": "string"},
|
|
97
|
-
"timeout": {"type": "number", "default": 60},
|
|
98
|
-
},
|
|
99
|
-
"required": ["bot_id"],
|
|
100
|
-
},
|
|
101
|
-
},
|
|
102
|
-
{
|
|
103
|
-
"name": "screen_status",
|
|
104
|
-
"description": "查询虚拟屏状态:状态机、冻结标记、内存、PID。",
|
|
105
|
-
"inputSchema": {
|
|
106
|
-
"type": "object",
|
|
107
|
-
"properties": {"bot_id": {"type": "string"}},
|
|
108
|
-
"required": ["bot_id"],
|
|
109
|
-
},
|
|
110
|
-
},
|
|
111
|
-
{
|
|
112
|
-
"name": "screen_list",
|
|
113
|
-
"description": "列出所有已分配的虚拟屏。",
|
|
114
|
-
"inputSchema": {"type": "object", "properties": {}},
|
|
115
|
-
},
|
|
116
|
-
{
|
|
117
|
-
"name": "system_info",
|
|
118
|
-
"description": "通过网关获取宿主机系统信息:磁盘占用、内存占用、CPU 占用、开机时长。",
|
|
119
|
-
"inputSchema": {
|
|
120
|
-
"type": "object",
|
|
121
|
-
"properties": {
|
|
122
|
-
"disk_path": {"type": "string", "description": "可选磁盘挂载点路径(多个用逗号分隔,默认 /)"},
|
|
123
|
-
},
|
|
124
|
-
},
|
|
125
|
-
},
|
|
126
|
-
{
|
|
127
|
-
"name": "artifact_publish",
|
|
128
|
-
"description": "将 Agent 回复产物(文本/代码/HTML/JSON/Markdown 或 Base64 二进制)上传发布到网关并返回下载接口地址。",
|
|
129
|
-
"inputSchema": {
|
|
130
|
-
"type": "object",
|
|
131
|
-
"properties": {
|
|
132
|
-
"bot_id": {"type": "string", "description": "Bot ID"},
|
|
133
|
-
"title": {"type": "string", "description": "产物标题"},
|
|
134
|
-
"filename": {"type": "string", "description": "下载文件名(可选)"},
|
|
135
|
-
"content": {"type": "string", "description": "产物内容(UTF-8 文本或 base64 字符串)"},
|
|
136
|
-
"encoding": {"type": "string", "enum": ["utf-8", "base64"], "default": "utf-8"},
|
|
137
|
-
"artifact_type": {"type": "string", "description": "产物类型:html/markdown/json/code/text/file 等"},
|
|
138
|
-
"kind": {"type": "string", "enum": ["artifact", "deliverable", "file", "reply"], "default": "artifact"},
|
|
139
|
-
"mime_type": {"type": "string", "description": "可选 MIME 类型"},
|
|
140
|
-
"room_id": {"type": "string", "description": "可选所属群聊 ID"},
|
|
141
|
-
},
|
|
142
|
-
"required": ["bot_id", "content"],
|
|
143
|
-
},
|
|
144
|
-
},
|
|
145
|
-
{
|
|
146
|
-
"name": "artifact_list",
|
|
147
|
-
"description": "查询网关中已发布的 Agent 回复产物列表及下载地址。",
|
|
148
|
-
"inputSchema": {
|
|
149
|
-
"type": "object",
|
|
150
|
-
"properties": {
|
|
151
|
-
"bot_id": {"type": "string", "description": "可选按 Bot ID 过滤"},
|
|
152
|
-
"room_id": {"type": "string", "description": "可选按群聊 ID 过滤"},
|
|
153
|
-
"limit": {"type": "integer", "default": 50},
|
|
154
|
-
},
|
|
155
|
-
},
|
|
156
|
-
},
|
|
157
|
-
]
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
def agent_token(bot_id: str) -> str:
|
|
161
|
-
path = os.path.join(DATA_ROOT, bot_id, "runtime", "token.json")
|
|
162
|
-
with open(path, encoding="utf-8") as fh:
|
|
163
|
-
return json.load(fh)["token"]
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
def call_gateway(method: str, path: str, bot_id: str | None = None, **kwargs) -> httpx.Response:
|
|
167
|
-
headers = kwargs.pop("headers", {})
|
|
168
|
-
admin_token = os.environ.get("BOTSCREEN_ADMIN_TOKEN", "").strip()
|
|
169
|
-
if admin_token and "X-Admin-Token" not in headers:
|
|
170
|
-
headers["X-Admin-Token"] = admin_token
|
|
171
|
-
if bot_id:
|
|
172
|
-
headers["X-Agent-Token"] = agent_token(bot_id)
|
|
173
|
-
epoch = kwargs.pop("expected_epoch", None)
|
|
174
|
-
if epoch is not None:
|
|
175
|
-
headers["X-Expected-Epoch"] = str(epoch)
|
|
176
|
-
return httpx.request(method, f"{GATEWAY}{path}", headers=headers, timeout=60, **kwargs)
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
def lease_conflict(resp: httpx.Response) -> Dict[str, Any]:
|
|
180
|
-
"""把 409(租约 epoch 变了)翻译成 Agent 能直接照做的指令。"""
|
|
181
|
-
try:
|
|
182
|
-
body = resp.json()
|
|
183
|
-
except Exception: # noqa: BLE001
|
|
184
|
-
body = {}
|
|
185
|
-
return {
|
|
186
|
-
"content": [{
|
|
187
|
-
"type": "text",
|
|
188
|
-
"text": ("ERROR: 409 控制权已切换(租约 epoch "
|
|
189
|
-
f"{body.get('expected_epoch')} → {body.get('current_epoch')})。"
|
|
190
|
-
"重新调用 screen_screenshot 获取当前 X-Lease-Epoch,再决定是否继续。"),
|
|
191
|
-
}],
|
|
192
|
-
"isError": True,
|
|
193
|
-
}
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
def _err(msg: str) -> Dict[str, Any]:
|
|
197
|
-
return {"content": [{"type": "text", "text": f"ERROR: {msg}"}], "isError": True}
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
def tool_screen_screenshot(args: Dict[str, Any]) -> Dict[str, Any]:
|
|
201
|
-
bot_id = args["bot_id"]
|
|
202
|
-
fmt = args.get("format", "webp")
|
|
203
|
-
resp = call_gateway(
|
|
204
|
-
"GET", f"/api/agent/{bot_id}/screenshot", bot_id,
|
|
205
|
-
params={"fmt": fmt}, expected_epoch=args.get("lease_epoch"),
|
|
206
|
-
)
|
|
207
|
-
if resp.status_code == 409:
|
|
208
|
-
return lease_conflict(resp)
|
|
209
|
-
if resp.status_code == 423:
|
|
210
|
-
return _err(
|
|
211
|
-
"423 Locked: 人类正在接管,截图也被拒绝(fail-closed,人可能在输入凭据)。"
|
|
212
|
-
"调用 wait_human_release 等交还。" + resp.text[:200]
|
|
213
|
-
)
|
|
214
|
-
if resp.status_code != 200:
|
|
215
|
-
return _err(f"HTTP {resp.status_code}: {resp.text[:300]}")
|
|
216
|
-
mime = resp.headers.get("content-type", "image/webp").split(";")[0]
|
|
217
|
-
meta = {
|
|
218
|
-
"width": int(resp.headers.get("x-screen-width", 0)),
|
|
219
|
-
"height": int(resp.headers.get("x-screen-height", 0)),
|
|
220
|
-
"state": resp.headers.get("x-screen-state"),
|
|
221
|
-
"resumed_from_long_freeze": resp.headers.get("x-resumed-from-long-freeze") == "true",
|
|
222
|
-
"focused_window": json.loads(resp.headers.get("x-focused-window") or "{}"),
|
|
223
|
-
"lease_epoch": int(resp.headers.get("x-lease-epoch") or 0),
|
|
224
|
-
"lease_holder": resp.headers.get("x-lease-holder"),
|
|
225
|
-
}
|
|
226
|
-
return {
|
|
227
|
-
"content": [
|
|
228
|
-
{"type": "text", "text": json.dumps(meta, ensure_ascii=False)},
|
|
229
|
-
{
|
|
230
|
-
"type": "image",
|
|
231
|
-
"data": base64.b64encode(resp.content).decode(),
|
|
232
|
-
"mimeType": mime,
|
|
233
|
-
},
|
|
234
|
-
]
|
|
235
|
-
}
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
def tool_screen_click(args: Dict[str, Any]) -> Dict[str, Any]:
|
|
239
|
-
bot_id = args["bot_id"]
|
|
240
|
-
payload = {
|
|
241
|
-
"x": int(args["x"]),
|
|
242
|
-
"y": int(args["y"]),
|
|
243
|
-
"button": int(args.get("button", 1)),
|
|
244
|
-
"double": bool(args.get("double", False)),
|
|
245
|
-
}
|
|
246
|
-
resp = call_gateway("POST", f"/api/agent/{bot_id}/click", bot_id, json=payload,
|
|
247
|
-
expected_epoch=args.get("lease_epoch"))
|
|
248
|
-
if resp.status_code == 423:
|
|
249
|
-
return _err(f"423 Locked: 人类正在接管,请调用 wait_human_release。{resp.text[:200]}")
|
|
250
|
-
if resp.status_code != 200:
|
|
251
|
-
return _err(f"HTTP {resp.status_code}: {resp.text[:300]}")
|
|
252
|
-
return {"content": [{"type": "text", "text": resp.text}]}
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
def tool_screen_type(args: Dict[str, Any]) -> Dict[str, Any]:
|
|
256
|
-
bot_id = args["bot_id"]
|
|
257
|
-
payload = {"text": args.get("text", ""), "press_enter": bool(args.get("press_enter", False))}
|
|
258
|
-
resp = call_gateway("POST", f"/api/agent/{bot_id}/type", bot_id, json=payload,
|
|
259
|
-
expected_epoch=args.get("lease_epoch"))
|
|
260
|
-
if resp.status_code == 423:
|
|
261
|
-
return _err("423 Locked: 人类正在接管,请调用 wait_human_release。")
|
|
262
|
-
if resp.status_code != 200:
|
|
263
|
-
return _err(f"HTTP {resp.status_code}: {resp.text[:300]}")
|
|
264
|
-
return {"content": [{"type": "text", "text": resp.text}]}
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
def tool_screen_key(args: Dict[str, Any]) -> Dict[str, Any]:
|
|
268
|
-
bot_id = args["bot_id"]
|
|
269
|
-
payload = {"combo": args["key_combo"]}
|
|
270
|
-
resp = call_gateway("POST", f"/api/agent/{bot_id}/key", bot_id, json=payload,
|
|
271
|
-
expected_epoch=args.get("lease_epoch"))
|
|
272
|
-
if resp.status_code == 423:
|
|
273
|
-
return _err("423 Locked: 人类正在接管,请调用 wait_human_release。")
|
|
274
|
-
if resp.status_code != 200:
|
|
275
|
-
return _err(f"HTTP {resp.status_code}: {resp.text[:300]}")
|
|
276
|
-
return {"content": [{"type": "text", "text": resp.text}]}
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
def tool_request_help(args: Dict[str, Any]) -> Dict[str, Any]:
|
|
280
|
-
bot_id = args["bot_id"]
|
|
281
|
-
resp = call_gateway(
|
|
282
|
-
"POST", f"/api/agent/{bot_id}/request_help", bot_id, json={"reason": args["reason"]}
|
|
283
|
-
)
|
|
284
|
-
if resp.status_code != 200:
|
|
285
|
-
return _err(f"HTTP {resp.status_code}: {resp.text[:300]}")
|
|
286
|
-
return {"content": [{"type": "text", "text": resp.text}]}
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
def tool_wait_release(args: Dict[str, Any]) -> Dict[str, Any]:
|
|
290
|
-
bot_id = args["bot_id"]
|
|
291
|
-
resp = call_gateway(
|
|
292
|
-
"POST",
|
|
293
|
-
f"/api/agent/{bot_id}/wait_release",
|
|
294
|
-
bot_id,
|
|
295
|
-
params={"timeout": float(args.get("timeout", 60))},
|
|
296
|
-
)
|
|
297
|
-
if resp.status_code != 200:
|
|
298
|
-
return _err(f"HTTP {resp.status_code}: {resp.text[:300]}")
|
|
299
|
-
return {"content": [{"type": "text", "text": resp.text}]}
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
def tool_status(args: Dict[str, Any]) -> Dict[str, Any]:
|
|
303
|
-
resp = call_gateway("GET", f"/api/screens/{args['bot_id']}")
|
|
304
|
-
if resp.status_code != 200:
|
|
305
|
-
return _err(f"HTTP {resp.status_code}: {resp.text[:300]}")
|
|
306
|
-
return {"content": [{"type": "text", "text": resp.text}]}
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
def tool_list(_: Dict[str, Any]) -> Dict[str, Any]:
|
|
310
|
-
resp = call_gateway("GET", "/api/screens")
|
|
311
|
-
if resp.status_code != 200:
|
|
312
|
-
return _err(f"HTTP {resp.status_code}: {resp.text[:300]}")
|
|
313
|
-
return {"content": [{"type": "text", "text": resp.text}]}
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
def tool_system_info(args: Dict[str, Any]) -> Dict[str, Any]:
|
|
317
|
-
params = {}
|
|
318
|
-
disk_path = str(args.get("disk_path") or "").strip()
|
|
319
|
-
if disk_path:
|
|
320
|
-
params["disk_path"] = disk_path
|
|
321
|
-
resp = call_gateway("GET", "/api/system", params=params)
|
|
322
|
-
if resp.status_code != 200:
|
|
323
|
-
return _err(f"HTTP {resp.status_code}: {resp.text[:300]}")
|
|
324
|
-
return {"content": [{"type": "text", "text": resp.text}]}
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
def tool_artifact_publish(args: Dict[str, Any]) -> Dict[str, Any]:
|
|
328
|
-
bot_id = str(args["bot_id"]).strip()
|
|
329
|
-
payload = {
|
|
330
|
-
"title": args.get("title", ""),
|
|
331
|
-
"filename": args.get("filename"),
|
|
332
|
-
"content": args["content"],
|
|
333
|
-
"encoding": args.get("encoding", "utf-8"),
|
|
334
|
-
"artifact_type": args.get("artifact_type", ""),
|
|
335
|
-
"kind": args.get("kind", "artifact"),
|
|
336
|
-
"mime_type": args.get("mime_type"),
|
|
337
|
-
"room_id": args.get("room_id", ""),
|
|
338
|
-
}
|
|
339
|
-
resp = call_gateway("POST", f"/api/agent/{bot_id}/artifacts", bot_id, json=payload)
|
|
340
|
-
if resp.status_code != 200:
|
|
341
|
-
return _err(f"HTTP {resp.status_code}: {resp.text[:300]}")
|
|
342
|
-
return {"content": [{"type": "text", "text": resp.text}]}
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
def tool_artifact_list(args: Dict[str, Any]) -> Dict[str, Any]:
|
|
346
|
-
params: Dict[str, Any] = {"limit": int(args.get("limit", 50))}
|
|
347
|
-
bot_id = str(args.get("bot_id") or "").strip()
|
|
348
|
-
room_id = str(args.get("room_id") or "").strip()
|
|
349
|
-
if room_id:
|
|
350
|
-
params["room_id"] = room_id
|
|
351
|
-
if bot_id:
|
|
352
|
-
params["bot_id"] = bot_id
|
|
353
|
-
resp = call_gateway("GET", "/api/artifacts", params=params)
|
|
354
|
-
if resp.status_code != 200:
|
|
355
|
-
return _err(f"HTTP {resp.status_code}: {resp.text[:300]}")
|
|
356
|
-
return {"content": [{"type": "text", "text": resp.text}]}
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
HANDLERS = {
|
|
360
|
-
"screen_screenshot": tool_screen_screenshot,
|
|
361
|
-
"screen_click": tool_screen_click,
|
|
362
|
-
"screen_type_text": tool_screen_type,
|
|
363
|
-
"screen_key": tool_screen_key,
|
|
364
|
-
"request_human_help": tool_request_help,
|
|
365
|
-
"wait_human_release": tool_wait_release,
|
|
366
|
-
"screen_status": tool_status,
|
|
367
|
-
"screen_list": tool_list,
|
|
368
|
-
"system_info": tool_system_info,
|
|
369
|
-
"artifact_publish": tool_artifact_publish,
|
|
370
|
-
"artifact_list": tool_artifact_list,
|
|
371
|
-
}
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
def respond(req_id: Any, result: Any) -> None:
|
|
375
|
-
sys.stdout.write(json.dumps({"jsonrpc": "2.0", "id": req_id, "result": result}) + "\n")
|
|
376
|
-
sys.stdout.flush()
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
def respond_error(req_id: Any, code: int, message: str) -> None:
|
|
380
|
-
sys.stdout.write(
|
|
381
|
-
json.dumps({"jsonrpc": "2.0", "id": req_id, "error": {"code": code, "message": message}}) + "\n"
|
|
382
|
-
)
|
|
383
|
-
sys.stdout.flush()
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
def main() -> None:
|
|
387
|
-
for line in sys.stdin:
|
|
388
|
-
line = line.strip()
|
|
389
|
-
if not line:
|
|
390
|
-
continue
|
|
391
|
-
try:
|
|
392
|
-
msg = json.loads(line)
|
|
393
|
-
except json.JSONDecodeError:
|
|
394
|
-
continue
|
|
395
|
-
method = msg.get("method")
|
|
396
|
-
req_id = msg.get("id")
|
|
397
|
-
params = msg.get("params") or {}
|
|
398
|
-
|
|
399
|
-
try:
|
|
400
|
-
if method == "initialize":
|
|
401
|
-
respond(
|
|
402
|
-
req_id,
|
|
403
|
-
{
|
|
404
|
-
"protocolVersion": PROTOCOL_VERSION,
|
|
405
|
-
"capabilities": {"tools": {"listChanged": False}},
|
|
406
|
-
"serverInfo": {"name": "botscreen", "version": "1.0.0"},
|
|
407
|
-
},
|
|
408
|
-
)
|
|
409
|
-
elif method in ("notifications/initialized", "initialized"):
|
|
410
|
-
continue
|
|
411
|
-
elif method == "ping":
|
|
412
|
-
respond(req_id, {})
|
|
413
|
-
elif method == "tools/list":
|
|
414
|
-
respond(req_id, {"tools": TOOLS})
|
|
415
|
-
elif method == "tools/call":
|
|
416
|
-
name = params.get("name")
|
|
417
|
-
handler = HANDLERS.get(name)
|
|
418
|
-
if handler is None:
|
|
419
|
-
respond_error(req_id, -32602, f"unknown tool: {name}")
|
|
420
|
-
continue
|
|
421
|
-
respond(req_id, handler(params.get("arguments") or {}))
|
|
422
|
-
elif method == "resources/list":
|
|
423
|
-
respond(req_id, {"resources": []})
|
|
424
|
-
elif method == "prompts/list":
|
|
425
|
-
respond(req_id, {"prompts": []})
|
|
426
|
-
else:
|
|
427
|
-
if req_id is not None:
|
|
428
|
-
respond_error(req_id, -32601, f"method not found: {method}")
|
|
429
|
-
except Exception as exc: # noqa: BLE001
|
|
430
|
-
if req_id is not None:
|
|
431
|
-
respond_error(req_id, -32603, f"{type(exc).__name__}: {exc}")
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
if __name__ == "__main__":
|
|
435
|
-
main()
|