@glittering0717/ai-browser 2.4.5 → 2.5.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/README.md +25 -7
- package/examples/AGENT_INSTRUCTIONS.md +4 -2
- package/llms-install.md +8 -5
- package/package.json +4 -2
- package/skills/ai-browser/SKILL.md +1 -1
- package/skills/ai-browser/references/tabs.md +16 -0
- package/src/main/download_monitor.js +23 -1
- package/src/main/mcp_server.js +4 -3
- package/src/main/mcp_ws.js +14 -3
- package/src/main/page_manager.js +130 -71
- package/src/main/ws_server.js +99 -14
- package/src/preload/bridge.cjs +15 -24
- package/src/shared/eval_route.cjs +63 -0
- package/src/shared/ipc_guard.cjs +45 -0
- package/src/shared/tool_timeout.js +54 -0
- package/src/shared/tree_focus.cjs +58 -0
- package/src/shared/upload_guard.cjs +104 -0
- package/src/shared/version.js +1 -1
- package/src/shared/wrapper_hint.js +1 -1
- package/src/shared/protocol.js +0 -152
package/src/shared/protocol.js
DELETED
|
@@ -1,152 +0,0 @@
|
|
|
1
|
-
// shared/protocol.js — JSON-RPC 2.0 subset for AI Browser
|
|
2
|
-
// Used by both main process (WS server) and preload (IPC bridge)
|
|
3
|
-
|
|
4
|
-
/**
|
|
5
|
-
* Create a JSON-RPC request string
|
|
6
|
-
*/
|
|
7
|
-
export function createRequest(id, method, params = {}) {
|
|
8
|
-
return JSON.stringify({ jsonrpc: '2.0', id, method, params });
|
|
9
|
-
}
|
|
10
|
-
|
|
11
|
-
/**
|
|
12
|
-
* Create a JSON-RPC success response string
|
|
13
|
-
*/
|
|
14
|
-
export function createResponse(id, result) {
|
|
15
|
-
return JSON.stringify({ jsonrpc: '2.0', id, result });
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
/**
|
|
19
|
-
* Create a JSON-RPC error response string
|
|
20
|
-
*/
|
|
21
|
-
export function createError(id, code, message, data = null) {
|
|
22
|
-
const error = { code, message };
|
|
23
|
-
if (data) error.data = data;
|
|
24
|
-
return JSON.stringify({ jsonrpc: '2.0', id, error });
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
/**
|
|
28
|
-
* Create a server-pushed event (no id — notification per JSON-RPC)
|
|
29
|
-
*/
|
|
30
|
-
export function createEvent(event, data) {
|
|
31
|
-
return JSON.stringify({ jsonrpc: '2.0', method: event, params: data });
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
/**
|
|
35
|
-
* Parse a JSON-RPC message string into object
|
|
36
|
-
*/
|
|
37
|
-
export function parseMessage(msg) {
|
|
38
|
-
try {
|
|
39
|
-
const obj = JSON.parse(msg);
|
|
40
|
-
if (obj.jsonrpc !== '2.0') {
|
|
41
|
-
throw new Error('Invalid JSON-RPC version');
|
|
42
|
-
}
|
|
43
|
-
return obj;
|
|
44
|
-
} catch (e) {
|
|
45
|
-
throw new Error(`Failed to parse JSON-RPC message: ${e.message}`);
|
|
46
|
-
}
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
/**
|
|
50
|
-
* Every ui.* method the WebSocket server actually dispatches.
|
|
51
|
-
*
|
|
52
|
-
* This list had drifted badly: it named 7 methods while the server served 28,
|
|
53
|
-
* so anyone reading it would conclude most of the API did not exist. A
|
|
54
|
-
* machine-readable contract that lies is worse than no contract — so
|
|
55
|
-
* `tests/test_protocol.js` now derives the real set from the `case 'ui.x':`
|
|
56
|
-
* labels in `src/main/ws_server.js` and fails if the two diverge. Add a method
|
|
57
|
-
* to the server and this list must follow, or the suite breaks.
|
|
58
|
-
*/
|
|
59
|
-
export const VALID_METHODS = [
|
|
60
|
-
'ui.get_tree',
|
|
61
|
-
'ui.act',
|
|
62
|
-
'ui.auth_state',
|
|
63
|
-
// 视口截图(P0-1):操作失败时的第一诊断手段,弥补元素树看不见的
|
|
64
|
-
// 浮层/canvas/遮挡/渲染错位。返回 base64,默认 png。
|
|
65
|
-
'ui.screenshot',
|
|
66
|
-
'ui.navigate',
|
|
67
|
-
'ui.repaint',
|
|
68
|
-
// "这一页到底画出来了没有"—— 只读观测,heal:true 才走自救阶梯。
|
|
69
|
-
// 与 ui.repaint 的区别:repaint 是"外面的人说窗口不对,重画一次";
|
|
70
|
-
// paint_check 是"工具自己看一眼,白的话按阶梯救,救不动就如实上报"。
|
|
71
|
-
'ui.paint_check',
|
|
72
|
-
// 窗口/视图几何(读 + 改)。布局类缺陷需要它才能复现与回归。
|
|
73
|
-
'ui.window_bounds',
|
|
74
|
-
// 窗口可见性 / 最小化(读 + 改)。后台运行(无头式无人值守)的开关:
|
|
75
|
-
// 隐藏是一个**稳定状态**,不会因为 agent 的下一次操作自己弹回来。
|
|
76
|
-
'ui.window',
|
|
77
|
-
'ui.snapshot',
|
|
78
|
-
'ui.diff',
|
|
79
|
-
'ui.capabilities',
|
|
80
|
-
// 「这个画布应用的对象模型在哪、里面有什么」。
|
|
81
|
-
// capabilities 扫的是 window:实例关在闭包里时它会给出**假阴性**(实测
|
|
82
|
-
// suxieban=fabric、yunser=DrawBoard 都被判成"没有模型")。这条补那一步,
|
|
83
|
-
// 也作为 capabilities{deep:true} 的实现。
|
|
84
|
-
'ui.app_model',
|
|
85
|
-
'ui.evaluate',
|
|
86
|
-
'ui.subscribe',
|
|
87
|
-
'ui.unsubscribe',
|
|
88
|
-
'ui.downloads',
|
|
89
|
-
// "把当前页存下来"。浏览器的显示/下载是两条路:图片、视频、PDF 被显示出来
|
|
90
|
-
// (见 shared/media_doc.cjs),所以要留下文件时得有一条明确的入口,
|
|
91
|
-
// 否则等于把"下载"这个能力从这类页面上拿掉了。
|
|
92
|
-
'ui.download',
|
|
93
|
-
// 主进程错误日志(只读)。界面弹过"js 崩溃"原生框、或某个动作莫名失败时,
|
|
94
|
-
// 这里是唯一能查到 stack 与"出错那一刻在调什么"的地方 —— 此前这类异常只活在
|
|
95
|
-
// 那个框里,点掉即永久丢失。
|
|
96
|
-
'ui.errors',
|
|
97
|
-
'ui.get_focused',
|
|
98
|
-
'ui.peek',
|
|
99
|
-
'ui.wait',
|
|
100
|
-
'ui.scroll',
|
|
101
|
-
'ui.new_tab',
|
|
102
|
-
'ui.close_tab',
|
|
103
|
-
'ui.list_tabs',
|
|
104
|
-
'ui.set_active_tab',
|
|
105
|
-
// 窗口首次显示的时刻与当时页面状态。白屏类缺陷的根因是"窗口显示了但渲染器
|
|
106
|
-
// 还没画出第一帧",而这只能从窗口侧观测(WS 端口比 showInitialWindow 早开),
|
|
107
|
-
// 所以留一个查询口;见 e2e/nav_ws.cjs NV-A。
|
|
108
|
-
'ui.window_shown',
|
|
109
|
-
// 服务端进程身份(pid + 启动时刻)。调用方据此核对"我连上的是不是我拉起的
|
|
110
|
-
// 那个实例" —— 连错实例时结果毫无意义但不会报错,是最难查的一类。
|
|
111
|
-
'ui.server_info',
|
|
112
|
-
// 连接自报家门(label / auto_workspace)。声明自己是 agent 的连接会拿到一块
|
|
113
|
-
// 自己的标签组与自动工作区 —— 这是"agent 的操作与人的操作隔离"的入口。
|
|
114
|
-
'ui.hello',
|
|
115
|
-
'ui.canvas_configure',
|
|
116
|
-
'ui.canvas_list',
|
|
117
|
-
'ui.canvas_read',
|
|
118
|
-
'ui.canvas_capture',
|
|
119
|
-
'ui.network_list',
|
|
120
|
-
'ui.network_get',
|
|
121
|
-
'ui.network_clear',
|
|
122
|
-
'ui.network_configure',
|
|
123
|
-
'ui.network_body',
|
|
124
|
-
'ui.quit',
|
|
125
|
-
];
|
|
126
|
-
|
|
127
|
-
/**
|
|
128
|
-
* Standard JSON-RPC error codes
|
|
129
|
-
*/
|
|
130
|
-
export const ERROR_CODES = {
|
|
131
|
-
PARSE_ERROR: -32700,
|
|
132
|
-
INVALID_REQUEST: -32600,
|
|
133
|
-
METHOD_NOT_FOUND: -32601,
|
|
134
|
-
INVALID_PARAMS: -32602,
|
|
135
|
-
INTERNAL_ERROR: -32603,
|
|
136
|
-
ACTION_FAILED: -32001,
|
|
137
|
-
TARGET_NOT_FOUND: -32002,
|
|
138
|
-
INVALID_ACTION: -32003,
|
|
139
|
-
};
|
|
140
|
-
|
|
141
|
-
// For CJS compatibility in Electron preload
|
|
142
|
-
if (typeof module !== 'undefined' && module.exports) {
|
|
143
|
-
module.exports = {
|
|
144
|
-
createRequest,
|
|
145
|
-
createResponse,
|
|
146
|
-
createError,
|
|
147
|
-
createEvent,
|
|
148
|
-
parseMessage,
|
|
149
|
-
VALID_METHODS,
|
|
150
|
-
ERROR_CODES,
|
|
151
|
-
};
|
|
152
|
-
}
|