@seekskyworld/open-browser 0.1.0 → 0.2.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/Docs/open-browser-api.d.ts +23 -5
- package/Docs//350/267/250/345/271/263/345/217/260/350/257/225/347/224/250/344/270/216/345/217/221/350/241/214.md +51 -3
- package/README.md +14 -5
- package/README.zh-CN.md +16 -5
- package/access-registry.mjs +5 -0
- package/action-execution.mjs +32 -21
- package/api-contract.mjs +14 -2
- package/browser-extension/manifest.json +1 -4
- package/browser-extension/newtab.css +6 -0
- package/browser-extension/newtab.js +53 -2
- package/browser-extension/phase-labels.js +1 -1
- package/browser-extension/popup.css +1 -1
- package/browser-extension/popup.html +14 -4
- package/browser-extension/popup.js +101 -20
- package/browser-extension/tab-action.js +3 -2
- package/browser-extension/worker.js +102 -9
- package/build-profile.mjs +23 -0
- package/capability-matrix.mjs +3 -3
- package/chromium-host.mjs +78 -18
- package/chromium-shell.mjs +77 -48
- package/cli.mjs +59 -1
- package/contract-validation.mjs +1 -1
- package/desktop/Info.plist +1 -1
- package/desktop/OBControlBar.m +7 -3
- package/desktop/WorkspacePanel.m +2 -1
- package/desktop/brand-keychain.py +20 -4
- package/desktop/build-macos.mjs +26 -10
- package/desktop/build-managed-input.mjs +37 -0
- package/desktop/build-profile.mjs +6 -0
- package/desktop/build.mjs +8 -0
- package/desktop/macos-entitlements.plist +12 -0
- package/desktop/notarize-macos.mjs +145 -0
- package/desktop/package-macos.mjs +54 -0
- package/desktop/patches/chromium-managed-input.patch +144 -0
- package/desktop/sign.mjs +48 -4
- package/desktop/start-profile.mjs +5 -0
- package/desktop/start.mjs +25 -3
- package/desktop/verify-macos-release.mjs +61 -0
- package/diagnostics.mjs +9 -0
- package/engine-service.mjs +174 -18
- package/managed-input.mjs +138 -0
- package/mcp-http.mjs +84 -0
- package/mcp-server.mjs +41 -0
- package/mcp.mjs +2 -40
- package/package.json +22 -2
- package/page-activity.mjs +95 -28
- package/page-observation.mjs +41 -3
- package/paths.mjs +5 -3
- package/receipt-store.mjs +9 -2
- package/runtime.mjs +10 -1
- package/sdk.mjs +32 -15
- package/service.mjs +21 -2
- package/skill-links.mjs +90 -0
- package/skills/open-browser/SKILL.macos.md +112 -0
- package/skills/open-browser/SKILL.md +24 -3
- package/skills/open-browser/SKILL.windows.md +112 -0
- package/skills/open-browser/scripts/bootstrap.mjs +80 -1
- package/tab-adoption.mjs +77 -0
- package/uploads.mjs +4 -4
- package/workspace-lifecycle.mjs +74 -6
- package/workspace-state.mjs +14 -2
|
@@ -18,11 +18,16 @@ function notify(message) {
|
|
|
18
18
|
|
|
19
19
|
function friendlyError(error) {
|
|
20
20
|
const code = error?.message || '';
|
|
21
|
-
if (code === 'host_unavailable' || code === 'host_timeout') return
|
|
21
|
+
if (code === 'host_unavailable' || code === 'host_timeout') return code === 'host_timeout'
|
|
22
|
+
? 'open-browser 已收到请求,但服务响应超时,请检查应用后重试。'
|
|
23
|
+
: 'open-browser 服务未连接,请先启动应用后点击刷新。';
|
|
24
|
+
if (code === 'extension_worker_timeout') return 'open-browser 扩展响应超时,请重新加载扩展或重启应用。';
|
|
25
|
+
if (code === 'extension_unavailable') return 'open-browser 工作区扩展未运行,请重新启动应用。';
|
|
22
26
|
return code || '暂时无法读取 Agent 状态,请点击刷新重试。';
|
|
23
27
|
}
|
|
24
28
|
|
|
25
29
|
function stateLabel(workspace) {
|
|
30
|
+
if (workspace.activity?.needsHumanVerification) return '需要人工验证';
|
|
26
31
|
if (workspace.activity?.needsCredential) return '等待凭据';
|
|
27
32
|
return modes[workspace.mode] || phases[workspace.activity?.current?.phase] || phases[workspace.activity?.phase] || '待命';
|
|
28
33
|
}
|
|
@@ -37,6 +42,42 @@ function line(text, className = '') {
|
|
|
37
42
|
return node;
|
|
38
43
|
}
|
|
39
44
|
|
|
45
|
+
function eventLabel(event) {
|
|
46
|
+
const state = event.state || 'unknown';
|
|
47
|
+
const steps = Number.isInteger(event.completedSteps) ? ` · ${event.completedSteps} 步` : '';
|
|
48
|
+
const operation = event.operationId ? ` · ${event.operationId.slice(0, 8)}` : '';
|
|
49
|
+
return `${event.kind || '事件'} · ${phases[state] || state}${steps}${operation}`;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
async function showEvents(workspaceId, host) {
|
|
53
|
+
const timeline = host.querySelector('.timeline');
|
|
54
|
+
if (!timeline) return;
|
|
55
|
+
if (!timeline.hidden) {
|
|
56
|
+
timeline.hidden = true;
|
|
57
|
+
return;
|
|
58
|
+
}
|
|
59
|
+
timeline.hidden = false;
|
|
60
|
+
timeline.replaceChildren(line('正在读取记录…', 'detail'));
|
|
61
|
+
try {
|
|
62
|
+
const result = await call('listEvents', { workspaceId, after: 0, limit: 24 });
|
|
63
|
+
const events = result?.events || [];
|
|
64
|
+
timeline.replaceChildren(...(events.length
|
|
65
|
+
? events.map(event => line(eventLabel(event), 'timeline-row'))
|
|
66
|
+
: [line('暂无可显示的脱敏事件。', 'detail')]));
|
|
67
|
+
} catch (error) {
|
|
68
|
+
timeline.replaceChildren(line(friendlyError(error), 'detail'));
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
function recordButton(workspaceId, host) {
|
|
73
|
+
const button = document.createElement('button');
|
|
74
|
+
button.type = 'button';
|
|
75
|
+
button.className = 'quiet record-button';
|
|
76
|
+
button.textContent = '查看记录';
|
|
77
|
+
button.onclick = () => void showEvents(workspaceId, host);
|
|
78
|
+
return button;
|
|
79
|
+
}
|
|
80
|
+
|
|
40
81
|
function renderWorkspaces(items) {
|
|
41
82
|
el('workspace-count').textContent = items.length ? `${items.length} 个` : '';
|
|
42
83
|
el('empty').hidden = items.length > 0;
|
|
@@ -53,6 +94,10 @@ function renderWorkspaces(items) {
|
|
|
53
94
|
const agent = line(workspace.agentName || 'Agent', 'agent-name');
|
|
54
95
|
card.append(title, agent, status, detail);
|
|
55
96
|
if (needsTaskName(workspace)) card.append(line('请为此任务命名', 'name-hint'));
|
|
97
|
+
const timeline = document.createElement('div');
|
|
98
|
+
timeline.className = 'timeline';
|
|
99
|
+
timeline.hidden = true;
|
|
100
|
+
card.append(recordButton(workspace.workspaceId, card), timeline);
|
|
56
101
|
return card;
|
|
57
102
|
}));
|
|
58
103
|
}
|
|
@@ -83,7 +128,13 @@ function renderHistory(items) {
|
|
|
83
128
|
meta.append(line(phases[item.state] || item.state || '已完成', `history-state ${item.state || ''}`));
|
|
84
129
|
const time = formatTime(item.updatedAt || item.createdAt);
|
|
85
130
|
if (time) meta.append(line(time, 'detail'));
|
|
86
|
-
|
|
131
|
+
const timeline = document.createElement('div');
|
|
132
|
+
timeline.className = 'timeline';
|
|
133
|
+
timeline.hidden = true;
|
|
134
|
+
const actions = document.createElement('div');
|
|
135
|
+
actions.className = 'history-actions';
|
|
136
|
+
actions.append(recordButton(item.workspaceId, row));
|
|
137
|
+
row.append(main, meta, actions, timeline);
|
|
87
138
|
return row;
|
|
88
139
|
}));
|
|
89
140
|
}
|
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
globalThis.openBrowserPhaseLabels = Object.freeze({
|
|
4
4
|
idle: '等待指令', queued: '已排队', running: '执行中', actionability: '检查目标',
|
|
5
5
|
dispatching: '正在派发', waiting: '等待页面', verifying: '核对结果',
|
|
6
|
-
needs_credential: '等待凭据', completed: '已完成', failed: '失败',
|
|
6
|
+
needs_credential: '等待凭据', needs_human_verification: '需要人工验证', completed: '已完成', failed: '失败',
|
|
7
7
|
cancelled: '已取消', outcome_unknown: '结果待核实',
|
|
8
8
|
});
|
|
9
9
|
globalThis.openBrowserModeLabels = Object.freeze({ agent: 'Agent 控制', human: '人工接管', transferring: '交接中' });
|
|
@@ -8,7 +8,7 @@ strong { font-size: 17px; letter-spacing: -.3px; }
|
|
|
8
8
|
main { padding: 0 16px 14px; } section, form, details { margin-top: 14px; }
|
|
9
9
|
h2 { font-size: 14px; margin: 0 0 3px; } p { margin: 8px 0; overflow-wrap: anywhere; }
|
|
10
10
|
label { display: block; margin: 8px 0 3px; }
|
|
11
|
-
select, input[type=password] { width: 100%; height: 30px; font: inherit; }
|
|
11
|
+
select, #adoption input, input[type=password] { width: 100%; height: 30px; font: inherit; }
|
|
12
12
|
input[type=password] { padding: 3px 6px; }
|
|
13
13
|
button { font: inherit; border: 1px solid transparent; border-radius: 5px; padding: 4px 10px; background: #176244; color: white; cursor: pointer; }
|
|
14
14
|
button.secondary { background: ButtonFace; color: ButtonText; border-color: color-mix(in srgb, ButtonText 25%, transparent); }
|
|
@@ -14,9 +14,19 @@
|
|
|
14
14
|
<header><strong><img src="icons/open-browser-48.png" width="24" height="24" alt="">open-browser</strong><span id="status" role="status">正在连接…</span></header>
|
|
15
15
|
<main>
|
|
16
16
|
<p id="empty" hidden>当前没有活动任务。新标签页会显示 Agent 控制台。</p>
|
|
17
|
+
<section id="adoption" hidden>
|
|
18
|
+
<p id="adopt-site"></p>
|
|
19
|
+
<label for="adopt-task">授权给哪个 Agent 任务</label><select id="adopt-task"></select>
|
|
20
|
+
<label for="adopt-alias">账号别名(选填)</label><input id="adopt-alias" maxlength="48" placeholder="例如:工作账号">
|
|
21
|
+
<div class="action"><button id="adopt" type="button">让 Agent 操作此页</button></div>
|
|
22
|
+
<label id="adopt-result" hidden>将以下授权交给所选 Agent,两分钟内有效<input id="adopt-token" readonly></label>
|
|
23
|
+
</section>
|
|
17
24
|
<section id="workspace" hidden>
|
|
25
|
+
<div id="context-selection" hidden>
|
|
18
26
|
<label for="workspaces">工作区</label><select id="workspaces"></select>
|
|
19
27
|
<label for="pages">标签页</label><select id="pages"></select>
|
|
28
|
+
</div>
|
|
29
|
+
<p id="page-details"></p>
|
|
20
30
|
<div class="action"><button id="control" type="button"></button></div>
|
|
21
31
|
<div id="dialogs"></div>
|
|
22
32
|
<div id="blocked"></div>
|
|
@@ -24,10 +34,10 @@
|
|
|
24
34
|
<input id="upload-file" type="file"><div id="upload-list"></div></details>
|
|
25
35
|
<details id="downloads" hidden><summary>任务下载</summary><div id="download-list"></div></details>
|
|
26
36
|
<p id="visual-status" hidden></p>
|
|
27
|
-
<details><summary
|
|
28
|
-
<
|
|
29
|
-
<button id="diagnostic-
|
|
30
|
-
<
|
|
37
|
+
<details><summary>导出错误日志</summary>
|
|
38
|
+
<p>导出当前任务的脱敏失败记录,便于排查问题。</p>
|
|
39
|
+
<button id="diagnostic-export-button" type="button" class="secondary">导出错误日志</button>
|
|
40
|
+
<a id="diagnostic-export" download="open-browser-error-log.json" hidden>下载错误日志</a>
|
|
31
41
|
</details>
|
|
32
42
|
<details id="delivery"><summary>结束任务</summary>
|
|
33
43
|
<p>勾选要留给自己的标签,其余任务标签将关闭。</p>
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
3
|
const el = id => document.getElementById(id);
|
|
4
|
-
let selected = '', detail, request, selectedTab = '', revision = 0, busy = false, refreshing = false;
|
|
4
|
+
let selected = '', detail, request, selectedTab = '', revision = 0, busy = false, refreshing = false, contextTab = false;
|
|
5
5
|
const phases = globalThis.openBrowserPhaseLabels;
|
|
6
6
|
|
|
7
7
|
async function call(method, params = {}) {
|
|
@@ -16,6 +16,7 @@ function notify(text = '') {
|
|
|
16
16
|
}
|
|
17
17
|
|
|
18
18
|
function describe(w) {
|
|
19
|
+
if (w.activity?.needsHumanVerification) return '需要人工验证';
|
|
19
20
|
if (w.mode === 'human') return '人工接管';
|
|
20
21
|
if (w.mode === 'transferring') return '交接中';
|
|
21
22
|
if (w.activity?.needsCredential) return '等待凭据';
|
|
@@ -44,6 +45,24 @@ function showCredential(next) {
|
|
|
44
45
|
el('save').textContent = '绑定凭据';
|
|
45
46
|
}
|
|
46
47
|
|
|
48
|
+
let popupTabId, ordinaryTarget, tokenTimer, standalone = false;
|
|
49
|
+
function clearToken() {
|
|
50
|
+
clearTimeout(tokenTimer);
|
|
51
|
+
el('adopt-token').value = '';
|
|
52
|
+
el('adopt-result').hidden = true;
|
|
53
|
+
}
|
|
54
|
+
el('adopt-task').onchange = () => { clearToken(); el('adopt').disabled = !el('adopt-task').value; };
|
|
55
|
+
el('adopt').onclick = () => perform(async () => {
|
|
56
|
+
clearToken();
|
|
57
|
+
const {id:targetId, origin} = ordinaryTarget;
|
|
58
|
+
const reply = await call('offerCurrentTab',{workspaceId:el('adopt-task').value, tabId:popupTabId,
|
|
59
|
+
targetId, origin, accountAlias:el('adopt-alias').value.trim()});
|
|
60
|
+
el('adopt-token').value = JSON.stringify({workspaceId:reply.workspaceId,adoptionToken:reply.adoptionToken});
|
|
61
|
+
el('adopt-result').hidden = false;
|
|
62
|
+
el('adopt-token').select();
|
|
63
|
+
tokenTimer = setTimeout(clearToken, Math.max(0, reply.expiresAt - Date.now()));
|
|
64
|
+
});
|
|
65
|
+
|
|
47
66
|
let deliveryKey = '', finishId;
|
|
48
67
|
function renderDelivery(w) {
|
|
49
68
|
const originLabels = {resource:'加载静态资源',navigation:'允许导航与页面操作'};
|
|
@@ -66,6 +85,7 @@ function renderDelivery(w) {
|
|
|
66
85
|
const label = document.createElement('label'), input = document.createElement('input');
|
|
67
86
|
input.type = 'checkbox';
|
|
68
87
|
input.checked = true;
|
|
88
|
+
input.disabled = p.ownership === 'user';
|
|
69
89
|
input.value = p.pageId;
|
|
70
90
|
input.onchange = () => { finishId = crypto.randomUUID(); };
|
|
71
91
|
label.append(input, ' ' + (p.title || p.origin || '页面'));
|
|
@@ -86,39 +106,54 @@ function clearDiagnostic() {
|
|
|
86
106
|
if (link.hasAttribute('href')) URL.revokeObjectURL(link.href);
|
|
87
107
|
link.removeAttribute('href');
|
|
88
108
|
link.hidden = true;
|
|
89
|
-
el('diagnostic-data').textContent = '';
|
|
90
109
|
}
|
|
91
|
-
el('diagnostic-
|
|
92
|
-
el('diagnostic-preview').onclick = () => perform(async () => {
|
|
110
|
+
el('diagnostic-export-button').onclick = () => perform(async () => {
|
|
93
111
|
clearDiagnostic();
|
|
94
|
-
const workspaceId = selected
|
|
95
|
-
const
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
112
|
+
const workspaceId = selected;
|
|
113
|
+
const [operations, events] = await Promise.all([
|
|
114
|
+
call('listOperations', {workspaceId, after: 0, limit: 100}),
|
|
115
|
+
call('listEvents', {workspaceId, after: 0, limit: 100}),
|
|
116
|
+
]);
|
|
117
|
+
const text = JSON.stringify({ version: 1, workspaceId, exportedAt: new Date().toISOString(),
|
|
118
|
+
operations: (operations.operations || []).filter(item => item.error || ['failed', 'outcome_unknown', 'cancelled'].includes(item.state)),
|
|
119
|
+
events: events.events || [] }, null, 2) + '\n';
|
|
99
120
|
const link = el('diagnostic-export');
|
|
100
121
|
link.href = URL.createObjectURL(new Blob([text], {type:'application/json'}));
|
|
101
122
|
link.hidden = false;
|
|
123
|
+
link.textContent = '下载错误日志';
|
|
124
|
+
link.click();
|
|
102
125
|
});
|
|
103
126
|
|
|
104
127
|
function render(w) {
|
|
105
128
|
if (detail?.workspaceId !== w?.workspaceId) {
|
|
106
129
|
clearDiagnostic();
|
|
107
|
-
el('diagnostic-operation').value = '';
|
|
108
130
|
}
|
|
109
131
|
|
|
110
132
|
detail = w;
|
|
111
133
|
el('workspace').hidden = !w;
|
|
112
134
|
el('empty').hidden = !!w;
|
|
135
|
+
el('context-selection').hidden = contextTab || !w;
|
|
113
136
|
el('status').textContent = w ? describe(w) + ' · 资料 ' + w.profileId : '暂无工作区';
|
|
114
137
|
if (!w) { showCredential(null); return; }
|
|
115
138
|
renderDialogs(w);
|
|
116
139
|
renderDelivery(w);
|
|
117
140
|
const pages = w.pages || [];
|
|
118
|
-
if (
|
|
141
|
+
if (standalone && !selectedTab) selectedTab = pages[0]?.pageId || '';
|
|
142
|
+
const page = pages.find(p => p.pageId === selectedTab);
|
|
119
143
|
options(el('pages'), pages.map((p, i) => [p.pageId, (i+1) + ' · ' + (p.title || p.origin || '页面')]), selectedTab);
|
|
120
|
-
|
|
121
|
-
|
|
144
|
+
if (!page) {
|
|
145
|
+
el('workspace').hidden = !standalone;
|
|
146
|
+
el('control').disabled = true;
|
|
147
|
+
el('uploads').hidden = true;
|
|
148
|
+
el('page-details').textContent = '';
|
|
149
|
+
el('status').textContent = '原标签页已关闭或解绑';
|
|
150
|
+
showCredential(null);
|
|
151
|
+
return;
|
|
152
|
+
}
|
|
153
|
+
const sync = page.lastSyncedAt ? '上次同步 ' + new Date(page.lastSyncedAt).toLocaleTimeString() : '';
|
|
154
|
+
el('page-details').textContent = [page.origin, w.accountAlias, page.syncState === 'sync_pending' ? '同步中' : sync].filter(Boolean).join(' · ');
|
|
155
|
+
el('control').textContent = w.unlockPending ? '重试人工接管' : w.mode === 'human' ? '交回 Agent' : w.scope === 'single_tab' ? '接管此页' : '接管工作区';
|
|
156
|
+
el('control').disabled = busy || (w.mode === 'transferring' && !w.unlockPending) || (!selectedTab && w.mode !== 'human');
|
|
122
157
|
el('uploads').hidden = w.mode!=='agent' || !selectedTab;
|
|
123
158
|
el('upload-origin').textContent = pages.find(p=>p.pageId===selectedTab)?.origin || '';
|
|
124
159
|
showCredential(w.mode === 'agent' ? w.activity?.credentialRequest || null : null);
|
|
@@ -129,9 +164,42 @@ async function sync() {
|
|
|
129
164
|
refreshing = true;
|
|
130
165
|
const serial = revision;
|
|
131
166
|
try {
|
|
132
|
-
|
|
167
|
+
if (Number.isInteger(popupTabId)) {
|
|
168
|
+
const key = 'tab:' + popupTabId;
|
|
169
|
+
const mapping = (await chrome.storage.session.get(key))[key];
|
|
170
|
+
if (!contextTab && mapping) {
|
|
171
|
+
contextTab = true;
|
|
172
|
+
selected = mapping.workspaceId;
|
|
173
|
+
selectedTab = mapping.pageId;
|
|
174
|
+
clearToken();
|
|
175
|
+
}
|
|
176
|
+
}
|
|
177
|
+
el('adoption').hidden = true;
|
|
178
|
+
if (!contextTab && !standalone) {
|
|
179
|
+
const list = await call('listWorkspaces');
|
|
180
|
+
const target = (await chrome.debugger.getTargets()).find(t => t.type === 'page' && t.tabId === popupTabId);
|
|
181
|
+
const origin = URL.parse(target?.url);
|
|
182
|
+
if (serial !== revision) return;
|
|
183
|
+
render(null);
|
|
184
|
+
if (!origin || !['http:', 'https:'].includes(origin.protocol)) return;
|
|
185
|
+
if (ordinaryTarget?.id !== target.id || ordinaryTarget?.origin !== origin.origin) clearToken();
|
|
186
|
+
ordinaryTarget = {id:target.id, origin:origin.origin};
|
|
187
|
+
const tasks = list.filter(w => w.pageAvailability === 'unregistered' && w.mode === 'agent');
|
|
188
|
+
el('adoption').hidden = false;
|
|
189
|
+
el('empty').hidden = true;
|
|
190
|
+
el('status').textContent = '普通标签页';
|
|
191
|
+
el('adopt-site').textContent = origin.origin + (tasks.length ? '' : ' · 请让 Agent 先创建一个命名工作区');
|
|
192
|
+
const chooser = el('adopt-task');
|
|
193
|
+
options(chooser, tasks.map(w => [w.workspaceId, workspaceTitle(w) + ' · ' + w.workspaceId.slice(0,8)]),
|
|
194
|
+
tasks.some(w => w.workspaceId === chooser.value) ? chooser.value : tasks.length === 1 ? tasks[0].workspaceId : '');
|
|
195
|
+
el('adopt').disabled = !chooser.value;
|
|
196
|
+
return;
|
|
197
|
+
}
|
|
198
|
+
const list = contextTab ? (selected ? [await call('getWorkspace', {workspaceId: selected })] : []) : await call('listWorkspaces');
|
|
133
199
|
if (serial !== revision) return;
|
|
200
|
+
if (contextTab && !list.some(w => w.workspaceId === selected)) { render(null); return; }
|
|
134
201
|
if (!list.some(w => w.workspaceId === selected)) {
|
|
202
|
+
selectedTab = '';
|
|
135
203
|
selected = (list.find(w => w.activity?.needsCredential) || list[0])?.workspaceId || '';
|
|
136
204
|
}
|
|
137
205
|
const titles = list.map(workspaceTitle);
|
|
@@ -142,7 +210,7 @@ async function sync() {
|
|
|
142
210
|
return [w.workspaceId, title + suffix + ' · ' + describe(w)];
|
|
143
211
|
});
|
|
144
212
|
options(el('workspaces'), entries, selected);
|
|
145
|
-
const w = selected ? await call('getWorkspace', { workspaceId: selected }) : null;
|
|
213
|
+
const w = contextTab ? list[0] || null : selected ? await call('getWorkspace', { workspaceId: selected }) : null;
|
|
146
214
|
const [captureReply, downloads, uploads] = w ? await Promise.all([
|
|
147
215
|
call('visualStatus',{workspaceId:selected}).catch(()=>({})),
|
|
148
216
|
call('listDownloads',{workspaceId:selected}),
|
|
@@ -164,7 +232,16 @@ async function sync() {
|
|
|
164
232
|
capture.clip.x+', '+capture.clip.y+') '+capture.clip.width+' × '+capture.clip.height;
|
|
165
233
|
}
|
|
166
234
|
} catch (error) {
|
|
167
|
-
if (serial === revision) {
|
|
235
|
+
if (serial === revision) {
|
|
236
|
+
render(null);
|
|
237
|
+
if (contextTab && error.message === 'workspace_not_found') {
|
|
238
|
+
el('status').textContent = '原任务已结束或服务已重启';
|
|
239
|
+
notify('请在需要授权的标签页重新打开扩展。');
|
|
240
|
+
} else {
|
|
241
|
+
el('status').textContent = '连接失败';
|
|
242
|
+
notify(error.message);
|
|
243
|
+
}
|
|
244
|
+
}
|
|
168
245
|
} finally {
|
|
169
246
|
refreshing = false;
|
|
170
247
|
if (!busy && serial !== revision) void sync();
|
|
@@ -230,11 +307,12 @@ async function perform(action) {
|
|
|
230
307
|
busy = true;
|
|
231
308
|
revision++;
|
|
232
309
|
notify();
|
|
233
|
-
|
|
310
|
+
const enabled = [...document.querySelectorAll('button:enabled, select:enabled, input:enabled')];
|
|
311
|
+
for (const element of enabled) element.disabled = true;
|
|
234
312
|
try { await action(); } catch (error) { notify(error.message); }
|
|
235
313
|
finally {
|
|
236
314
|
busy = false;
|
|
237
|
-
for (const element of
|
|
315
|
+
for (const element of enabled) element.disabled = false;
|
|
238
316
|
render(detail);
|
|
239
317
|
void sync();
|
|
240
318
|
}
|
|
@@ -283,7 +361,8 @@ el('upload-file').onchange = event => {
|
|
|
283
361
|
});
|
|
284
362
|
};
|
|
285
363
|
el('control').onclick = () => perform(async () => {
|
|
286
|
-
if (detail.
|
|
364
|
+
if (!detail?.pages.some(p => p.pageId === selectedTab)) return;
|
|
365
|
+
if (detail.mode === 'human') await call('returnToAgent', { workspaceId: selected, pageId:selectedTab, controlGeneration: detail.controlGeneration });
|
|
287
366
|
else await call('takeControl', { workspaceId: selected, pageId: selectedTab, controlGeneration: detail.controlGeneration });
|
|
288
367
|
});
|
|
289
368
|
el('credential').onsubmit = event => {
|
|
@@ -304,10 +383,12 @@ el('credential').onsubmit = event => {
|
|
|
304
383
|
|
|
305
384
|
async function open() {
|
|
306
385
|
const explicit = /^#tab-(\d+)(-delivery)?$/.exec(location.hash);
|
|
307
|
-
|
|
386
|
+
standalone = !explicit && !!(await chrome.tabs.getCurrent());
|
|
387
|
+
const tabId = popupTabId = standalone ? undefined : explicit ? Number(explicit[1]) : (await chrome.tabs.query({ active: true, lastFocusedWindow: true }))[0]?.id;
|
|
308
388
|
if (Number.isInteger(tabId)) {
|
|
309
389
|
const key = 'tab:' + tabId;
|
|
310
390
|
const owned = (await chrome.storage.session.get(key))[key];
|
|
391
|
+
contextTab = Boolean(owned);
|
|
311
392
|
if (owned) { selected = owned.workspaceId; selectedTab = owned.pageId; }
|
|
312
393
|
}
|
|
313
394
|
await sync();
|
|
@@ -28,6 +28,7 @@ const actionStates = {
|
|
|
28
28
|
waiting: ['…', '#6757a4', '等待页面'],
|
|
29
29
|
verifying: ['✓', '#526675', '核对结果'],
|
|
30
30
|
needs_credential: ['!', '#a72f24', '等待凭据'],
|
|
31
|
+
needs_human_verification: ['!', '#a75d08', '需要人工验证'],
|
|
31
32
|
completed: ['✓', '#526675', '已完成'],
|
|
32
33
|
failed: ['!', '#a72f24', '执行失败'],
|
|
33
34
|
outcome_unknown: ['?', '#a75d08', '结果待核实'],
|
|
@@ -51,10 +52,10 @@ async function writeAction(tabId, record) {
|
|
|
51
52
|
return;
|
|
52
53
|
}
|
|
53
54
|
await chrome.storage.session.set({ [key]: record });
|
|
54
|
-
const phase = record.mode !== 'agent' ? record.mode : record.needsCredential ? 'needs_credential' : record.phase;
|
|
55
|
+
const phase = record.mode !== 'agent' ? record.mode : record.needsHumanVerification ? 'needs_human_verification' : record.needsCredential ? 'needs_credential' : record.phase;
|
|
55
56
|
showRunning(tabId, ['running', 'actionability', 'dispatching', 'waiting', 'verifying'].includes(phase));
|
|
56
57
|
const [text, color, status] = actionStates[phase] || actionStates.idle;
|
|
57
|
-
const panel = phase === 'needs_credential' || phase === 'transferring' || !record.controlGeneration;
|
|
58
|
+
const panel = phase === 'needs_credential' || phase === 'needs_human_verification' || phase === 'transferring' || !record.controlGeneration;
|
|
58
59
|
const steps = { click: '点击', fill: '填写', fillCredential: '填写凭据' };
|
|
59
60
|
const step = phase === 'running' && record.dispatchState ? (record.dispatchState === 'dispatched' ? '已派发' : '等待页面') : phase === 'running' ? steps[record.stepKind] : '';
|
|
60
61
|
const hint = record.mode === 'human' ? '点击交回 Agent' : panel ? '点击打开工作区面板' : '点击接管';
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
3
|
importScripts('workspace-title.js', 'tab-action.js');
|
|
4
|
-
globalThis.openBrowserGroupVersion =
|
|
4
|
+
globalThis.openBrowserGroupVersion = 12;
|
|
5
5
|
|
|
6
6
|
const groupsInProgress = new Map();
|
|
7
7
|
|
|
@@ -10,6 +10,11 @@ async function groupPage(state) {
|
|
|
10
10
|
const target = (await chrome.debugger.getTargets()).find(t => t.type === 'page' && t.id === targetId);
|
|
11
11
|
if (!Number.isInteger(target?.tabId)) throw new Error('target_not_found');
|
|
12
12
|
const tab = await chrome.tabs.get(target.tabId);
|
|
13
|
+
if (state.preserveGroup) {
|
|
14
|
+
await registerAction(tab.id, state);
|
|
15
|
+
await chrome.storage.session.set({ ['page:' + workspaceId + ':' + state.pageId]: { tabId: tab.id } });
|
|
16
|
+
return { tabId:tab.id };
|
|
17
|
+
}
|
|
13
18
|
const key = 'group:' + workspaceId + ':' + tab.windowId;
|
|
14
19
|
const stored = (await chrome.storage.session.get(key))[key];
|
|
15
20
|
const group = Number.isInteger(stored) ? await chrome.tabGroups.get(stored).catch(() => null) : null;
|
|
@@ -36,8 +41,8 @@ function agentColor(name = 'Agent') {
|
|
|
36
41
|
}
|
|
37
42
|
|
|
38
43
|
async function updateGroup(groupId, group, state) {
|
|
39
|
-
const { mode, phase, needsCredential } = state;
|
|
40
|
-
const attention = needsCredential || ['failed', 'outcome_unknown', 'needs_credential'].includes(phase);
|
|
44
|
+
const { mode, phase, needsCredential, needsHumanVerification } = state;
|
|
45
|
+
const attention = needsCredential || needsHumanVerification || ['failed', 'outcome_unknown', 'needs_credential', 'needs_human_verification'].includes(phase);
|
|
41
46
|
const color = mode === 'human' ? 'green' : mode === 'transferring' ? 'yellow' : attention ? 'red' : agentColor(state.agentName);
|
|
42
47
|
const title = workspaceTitle(state);
|
|
43
48
|
if (group?.color !== color || group?.title !== title) await chrome.tabGroups.update(groupId, { title, color });
|
|
@@ -75,6 +80,7 @@ globalThis.openBrowserRelease = ({workspaceId,pageId}) => forWorkspace(workspace
|
|
|
75
80
|
await chrome.storage.session.remove(mappingKey);
|
|
76
81
|
});
|
|
77
82
|
|
|
83
|
+
let inputHint;
|
|
78
84
|
globalThis.openBrowserFrontTab = async function () {
|
|
79
85
|
// A single browser snapshot keeps the active tab and its native window bounds together.
|
|
80
86
|
const win = await chrome.windows.getLastFocused({ populate: true }).catch(() => null);
|
|
@@ -89,10 +95,63 @@ globalThis.openBrowserFrontTab = async function () {
|
|
|
89
95
|
!record.pageId || !record.controlGeneration) return null;
|
|
90
96
|
const { workspaceId, pageId, controlGeneration, mode, agentName, phase } = record;
|
|
91
97
|
return { workspaceId, pageId, controlGeneration, mode, agentName: agentName || 'Agent', phase: phase || 'idle',
|
|
98
|
+
...(inputHint?.pageId === pageId && inputHint.generation === controlGeneration &&
|
|
99
|
+
mode === 'agent' && inputHint.until > Date.now() && { inputBlocked: true }),
|
|
92
100
|
dispatchState: record.dispatchState || null,
|
|
93
101
|
windowId, left, top, width, height, viewportWidth: tab.width };
|
|
94
102
|
};
|
|
95
103
|
|
|
104
|
+
globalThis.openBrowserInputHint = async function (pageId) {
|
|
105
|
+
const front = await globalThis.openBrowserFrontTab();
|
|
106
|
+
if (front?.pageId !== pageId || front.mode !== 'agent' || front.inputBlocked) return;
|
|
107
|
+
const hint = {pageId, generation:front.controlGeneration, until:Date.now() + 1500};
|
|
108
|
+
inputHint = hint;
|
|
109
|
+
markFrontTabChanged();
|
|
110
|
+
const [tab] = await chrome.tabs.query({active:true, windowId:front.windowId});
|
|
111
|
+
const record = tab && (await chrome.storage.session.get(tabKey(tab.id)))[tabKey(tab.id)];
|
|
112
|
+
if (record?.pageId === pageId && record.mode === 'agent') {
|
|
113
|
+
showRunning(tab.id, false);
|
|
114
|
+
await chrome.action.setBadgeText({tabId:tab.id, text:'接管'}).catch(() => {});
|
|
115
|
+
}
|
|
116
|
+
setTimeout(async () => {
|
|
117
|
+
if (hint === inputHint) inputHint = null;
|
|
118
|
+
markFrontTabChanged();
|
|
119
|
+
if (record) await forWorkspace(record.workspaceId, async () => {
|
|
120
|
+
const current = (await chrome.storage.session.get(tabKey(tab.id)))[tabKey(tab.id)];
|
|
121
|
+
if (current?.pageId === pageId) await writeAction(tab.id, current);
|
|
122
|
+
}).catch(() => {});
|
|
123
|
+
}, 1500);
|
|
124
|
+
};
|
|
125
|
+
|
|
126
|
+
let frontTabRevision = 0;
|
|
127
|
+
const frontTabWaiters = new Set();
|
|
128
|
+
function markFrontTabChanged() {
|
|
129
|
+
frontTabRevision++;
|
|
130
|
+
for (const resolve of frontTabWaiters) resolve(frontTabRevision);
|
|
131
|
+
frontTabWaiters.clear();
|
|
132
|
+
}
|
|
133
|
+
chrome.tabs.onActivated.addListener(markFrontTabChanged);
|
|
134
|
+
chrome.windows.onFocusChanged.addListener(markFrontTabChanged);
|
|
135
|
+
chrome.tabs.onRemoved.addListener(markFrontTabChanged);
|
|
136
|
+
chrome.tabs.onUpdated.addListener((tabId, changeInfo) => {
|
|
137
|
+
if (changeInfo.status || changeInfo.groupId !== undefined || changeInfo.windowId !== undefined) markFrontTabChanged();
|
|
138
|
+
});
|
|
139
|
+
globalThis.openBrowserWaitFrontTabChange = function (after) {
|
|
140
|
+
if (!Number.isSafeInteger(after) || frontTabRevision !== after) return Promise.resolve(frontTabRevision);
|
|
141
|
+
return new Promise(resolve => {
|
|
142
|
+
const timer = setTimeout(() => {
|
|
143
|
+
frontTabWaiters.delete(done);
|
|
144
|
+
resolve(frontTabRevision);
|
|
145
|
+
}, 3000);
|
|
146
|
+
const done = value => {
|
|
147
|
+
clearTimeout(timer);
|
|
148
|
+
frontTabWaiters.delete(done);
|
|
149
|
+
resolve(value);
|
|
150
|
+
};
|
|
151
|
+
frontTabWaiters.add(done);
|
|
152
|
+
});
|
|
153
|
+
};
|
|
154
|
+
|
|
96
155
|
globalThis.openBrowserDelivery = async target => {
|
|
97
156
|
const [tab] = await chrome.tabs.query({active:true,windowId:target.windowId});
|
|
98
157
|
if (!tab) return;
|
|
@@ -126,12 +185,26 @@ globalThis.openBrowserShow = async function () {
|
|
|
126
185
|
return (await chrome.windows.create({ focused: true })).id;
|
|
127
186
|
};
|
|
128
187
|
|
|
129
|
-
const newtabMethods = new Set(['listWorkspaces', 'listAgentHistory']);
|
|
130
|
-
const methods = new Set(['listUploads','grantUpload','revokeUpload','respondDialog','listDownloads','cancelDownload','keepDownload','visualStatus','
|
|
188
|
+
const newtabMethods = new Set(['listWorkspaces', 'listAgentHistory', 'listEvents']);
|
|
189
|
+
const methods = new Set(['offerCurrentTab','listUploads','grantUpload','revokeUpload','respondDialog','listDownloads','cancelDownload','keepDownload','visualStatus','listOperations','listEvents', 'listWorkspaces', 'getWorkspace', 'takeControl', 'returnToAgent', 'grantOrigin', 'resolveCredential', 'finishWorkspace']);
|
|
131
190
|
const pending = new Map();
|
|
132
191
|
const queued = [];
|
|
133
192
|
let waiting;
|
|
134
193
|
|
|
194
|
+
function hostFailure(request) {
|
|
195
|
+
if (request?.dispatchedAt) return {
|
|
196
|
+
code: 'host_timeout',
|
|
197
|
+
message: 'open-browser 扩展已收到请求,但本机服务未在时限内返回。请检查服务状态后重试。',
|
|
198
|
+
};
|
|
199
|
+
return {
|
|
200
|
+
code: 'host_unavailable',
|
|
201
|
+
message: 'open-browser 扩展未连接到本机服务,请先启动应用后重试。',
|
|
202
|
+
};
|
|
203
|
+
}
|
|
204
|
+
|
|
205
|
+
// Kept on the worker for the new-tab diagnostics and focused integration tests.
|
|
206
|
+
globalThis.openBrowserClassifyHostFailure = hostFailure;
|
|
207
|
+
|
|
135
208
|
chrome.runtime.onMessage.addListener((message, sender, respond) => {
|
|
136
209
|
const source = sender.url?.split('#')[0];
|
|
137
210
|
const popup = source === chrome.runtime.getURL('popup.html');
|
|
@@ -143,7 +216,17 @@ chrome.runtime.onMessage.addListener((message, sender, respond) => {
|
|
|
143
216
|
respond({ error: 'invalid_request' });
|
|
144
217
|
return false;
|
|
145
218
|
}
|
|
146
|
-
|
|
219
|
+
const dispatch = async () => {
|
|
220
|
+
if (message.method !== 'offerCurrentTab') return hostRequest(message.method, message.params);
|
|
221
|
+
const {tabId, targetId, origin, workspaceId, accountAlias} = message.params;
|
|
222
|
+
const [active] = await chrome.tabs.query({active:true,lastFocusedWindow:true});
|
|
223
|
+
if (active?.id !== tabId || !Number.isInteger(tabId)) throw Error('adoption_page_changed');
|
|
224
|
+
const target = (await chrome.debugger.getTargets()).find(t => t.type === 'page' && t.tabId === tabId);
|
|
225
|
+
if (!target || target.id !== targetId || new URL(target.url).origin !== origin)
|
|
226
|
+
throw Error('adoption_page_changed');
|
|
227
|
+
return hostRequest('offerCurrentTab', {workspaceId, targetId, origin, accountAlias});
|
|
228
|
+
};
|
|
229
|
+
dispatch().then(result => respond({ result }), error => respond({ error: error.message }));
|
|
147
230
|
return true;
|
|
148
231
|
});
|
|
149
232
|
|
|
@@ -155,17 +238,27 @@ function hostRequest(method, params) {
|
|
|
155
238
|
pending.delete(id);
|
|
156
239
|
const index = queued.findIndex(request => request.id === id);
|
|
157
240
|
if (index >= 0) queued.splice(index, 1);
|
|
158
|
-
|
|
241
|
+
const failure = hostFailure(request);
|
|
242
|
+
const error = new Error(failure.message);
|
|
243
|
+
error.code = failure.code;
|
|
244
|
+
reject(error);
|
|
159
245
|
}, 60_000);
|
|
160
246
|
pending.set(id, { resolve, reject, timer });
|
|
161
247
|
const request = { id, method, params };
|
|
162
|
-
if (waiting)
|
|
248
|
+
if (waiting) {
|
|
249
|
+
request.dispatchedAt = Date.now();
|
|
250
|
+
waiting(request);
|
|
251
|
+
}
|
|
163
252
|
else queued.push(request);
|
|
164
253
|
});
|
|
165
254
|
}
|
|
166
255
|
|
|
167
256
|
globalThis.openBrowserNext = function () {
|
|
168
|
-
if (queued.length)
|
|
257
|
+
if (queued.length) {
|
|
258
|
+
const request = queued.shift();
|
|
259
|
+
request.dispatchedAt = Date.now();
|
|
260
|
+
return request;
|
|
261
|
+
}
|
|
169
262
|
if (waiting) waiting(null);
|
|
170
263
|
return new Promise(resolve => {
|
|
171
264
|
const timer = setTimeout(() => waiting(null), 3000);
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import path from 'node:path';
|
|
2
|
+
import { readFileSync } from 'node:fs';
|
|
3
|
+
import { fileURLToPath } from 'node:url';
|
|
4
|
+
|
|
5
|
+
const allowedProfiles = new Set(['dev', 'stable']);
|
|
6
|
+
|
|
7
|
+
function packagedProfile() {
|
|
8
|
+
try { return readFileSync(fileURLToPath(new URL('./.open-browser-build-profile', import.meta.url)), 'utf8').trim().toLowerCase(); }
|
|
9
|
+
catch { return undefined; }
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
export const buildProfile = (process.env.OPEN_BROWSER_BUILD_PROFILE || packagedProfile() || 'stable').trim().toLowerCase();
|
|
13
|
+
|
|
14
|
+
if (!allowedProfiles.has(buildProfile)) {
|
|
15
|
+
throw new Error('OPEN_BROWSER_BUILD_PROFILE must be dev or stable');
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
export const isDevelopmentBuild = buildProfile === 'dev';
|
|
19
|
+
|
|
20
|
+
export function scopedBuildRoot(base, profile = buildProfile) {
|
|
21
|
+
if (!allowedProfiles.has(profile)) throw new Error('build profile must be dev or stable');
|
|
22
|
+
return profile === 'dev' ? path.join(base, 'dev') : base;
|
|
23
|
+
}
|
package/capability-matrix.mjs
CHANGED
|
@@ -3,16 +3,16 @@
|
|
|
3
3
|
// service workers cannot import the Node ESM runtime.
|
|
4
4
|
export const readCapabilities = Object.freeze([
|
|
5
5
|
'getWorkspace', 'diagnoseOperation', 'getOperation', 'getRecoverySummary',
|
|
6
|
-
'listOperations', 'listEvents', 'eventCursor', 'waitForEvent',
|
|
6
|
+
'previewFinish', 'listOperations', 'listEvents', 'eventCursor', 'waitForEvent',
|
|
7
7
|
'listDownloads', 'listOutputs', 'readOutput', 'observe', 'captureVisual',
|
|
8
8
|
]);
|
|
9
9
|
|
|
10
10
|
export const desktopCapabilities = Object.freeze([
|
|
11
|
-
'listUploads', 'grantUpload', 'revokeUpload', 'respondDialog',
|
|
11
|
+
'offerCurrentTab', 'listUploads', 'grantUpload', 'revokeUpload', 'respondDialog',
|
|
12
12
|
'listDownloads', 'cancelDownload', 'keepDownload', 'visualStatus',
|
|
13
13
|
'diagnoseOperation', 'listWorkspaces', 'getWorkspace', 'takeControl',
|
|
14
14
|
'returnToAgent', 'resolveCredential', 'grantOrigin', 'finishWorkspace',
|
|
15
|
-
'listOperations', 'listAgentHistory', 'closeWorkspace', 'showPage',
|
|
15
|
+
'listOperations', 'listEvents', 'eventCursor', 'listAgentHistory', 'closeWorkspace', 'showPage',
|
|
16
16
|
]);
|
|
17
17
|
|
|
18
18
|
export const capabilityProfiles = Object.freeze({
|