@seekskyworld/open-browser 0.0.0-stage → 0.1.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/CONTRIBUTING.md +15 -0
- package/Docs/Agent/346/265/217/350/247/210/345/231/250/346/200/273/344/275/223/346/236/266/346/236/204.md +58 -0
- package/Docs/THIRD-PARTY-NOTICES.md +12 -0
- package/Docs/open-browser-api.d.ts +273 -0
- package/Docs/open-browser/344/273/273/345/212/241/350/257/204/346/265/213/346/214/207/345/215/227.md +59 -0
- package/Docs/open-browser/351/232/220/347/247/201/344/270/216/345/274/200/346/272/220/345/256/241/350/256/241.md +37 -0
- package/Docs//346/216/247/345/210/266/345/217/260/345/210/206/347/273/204/344/270/216/346/216/245/347/256/241/346/226/271/346/241/210.md +31 -0
- 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 +36 -0
- package/LICENSE +200 -0
- package/README.md +150 -2
- package/README.zh-CN.md +155 -0
- package/SECURITY.md +9 -0
- package/access-registry.mjs +151 -0
- package/action-execution.mjs +374 -0
- package/activity-notifier.mjs +34 -0
- package/api-contract.mjs +122 -0
- package/browser-extension/icons/open-browser-128.png +0 -0
- package/browser-extension/icons/open-browser-16.png +0 -0
- package/browser-extension/icons/open-browser-32.png +0 -0
- package/browser-extension/icons/open-browser-48.png +0 -0
- package/browser-extension/icons/open-browser-wordmark.png +0 -0
- package/browser-extension/manifest.json +38 -0
- package/browser-extension/newtab.css +20 -0
- package/browser-extension/newtab.html +19 -0
- package/browser-extension/newtab.js +123 -0
- package/browser-extension/phase-labels.js +9 -0
- package/browser-extension/popup.css +19 -0
- package/browser-extension/popup.html +46 -0
- package/browser-extension/popup.js +324 -0
- package/browser-extension/tab-action.js +137 -0
- package/browser-extension/worker.js +188 -0
- package/browser-extension/workspace-title.js +15 -0
- package/capability-matrix.mjs +21 -0
- package/chromium-host.mjs +149 -0
- package/chromium-shell.mjs +150 -0
- package/cli.mjs +83 -0
- package/contract-validation.mjs +27 -0
- package/control.mjs +107 -0
- package/desktop/Info.plist +13 -0
- package/desktop/Launcher.m +117 -0
- package/desktop/OBControlBar.h +7 -0
- package/desktop/OBControlBar.m +213 -0
- package/desktop/OBPageView.h +6 -0
- package/desktop/OBPageView.m +348 -0
- package/desktop/WorkspacePanel.h +16 -0
- package/desktop/WorkspacePanel.m +915 -0
- package/desktop/archive-release.py +129 -0
- package/desktop/brand-keychain.py +95 -0
- package/desktop/brand-locales.py +93 -0
- package/desktop/brand-macos-icons.py +24 -0
- package/desktop/brand-windows-icons.mjs +48 -0
- package/desktop/build-macos.mjs +96 -0
- package/desktop/build-portable.mjs +95 -0
- package/desktop/build.mjs +5 -0
- package/desktop/create-shortcut.ps1 +9 -0
- package/desktop/generate-icons.py +39 -0
- package/desktop/icons/open-browser.icns +0 -0
- package/desktop/icons/open-browser.ico +0 -0
- package/desktop/install-menu-entry.mjs +24 -0
- package/desktop/package-assets.mjs +34 -0
- package/desktop/patches/chromium-macos-keychain-service.patch +18 -0
- package/desktop/portable-archive.py +22 -0
- package/desktop/sign.mjs +33 -0
- package/desktop/smoke-portable.mjs +65 -0
- package/desktop/start.mjs +12 -0
- package/desktop/verify-upgrade.mjs +74 -0
- package/desktop/verify-version.mjs +12 -0
- package/desktop-page.mjs +211 -0
- package/diagnostics.mjs +28 -0
- package/downloads.mjs +110 -0
- package/engine-service.mjs +1002 -0
- package/hosted/README.md +74 -0
- package/hosted/cli.mjs +17 -0
- package/hosted/directory.mjs +261 -0
- package/hosted/init.mjs +37 -0
- package/hosted/server.mjs +129 -0
- package/managed-popup.mjs +54 -0
- package/mcp.mjs +43 -0
- package/network-policy.mjs +107 -0
- package/output-store.mjs +96 -0
- package/package.json +57 -4
- package/page-activity.mjs +121 -0
- package/page-dialogs.mjs +53 -0
- package/page-observation.mjs +280 -0
- package/paths.mjs +20 -0
- package/privacy-config.mjs +95 -0
- package/receipt-store.mjs +191 -0
- package/runtime.mjs +44 -0
- package/scheduler.mjs +70 -0
- package/sdk.mjs +176 -0
- package/service.mjs +271 -0
- package/site-workflow.mjs +115 -0
- package/skills/open-browser/SKILL.md +86 -0
- package/skills/open-browser/scripts/bootstrap.mjs +134 -0
- package/skills/open-browser/scripts/open-browser +21 -0
- package/skills/open-browser/scripts/open-browser.cmd +9 -0
- package/skills/open-browser/workflows/login-export.json +10 -0
- package/skills/open-browser/workflows/upload-verify.json +8 -0
- package/studio/demo-site.mjs +111 -0
- package/studio/demo.css +1 -0
- package/studio/index.html +66 -0
- package/studio/index.mjs +57 -0
- package/studio/native-demo.mjs +124 -0
- package/studio/studio.css +119 -0
- package/studio/studio.js +438 -0
- package/uploads.mjs +63 -0
- package/visual-page.mjs +306 -0
- package/workspace-lifecycle.mjs +170 -0
- package/workspace-state.mjs +95 -0
|
@@ -0,0 +1,324 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
const el = id => document.getElementById(id);
|
|
4
|
+
let selected = '', detail, request, selectedTab = '', revision = 0, busy = false, refreshing = false;
|
|
5
|
+
const phases = globalThis.openBrowserPhaseLabels;
|
|
6
|
+
|
|
7
|
+
async function call(method, params = {}) {
|
|
8
|
+
const reply = await chrome.runtime.sendMessage({ method, params });
|
|
9
|
+
if (!reply || reply.error) throw new Error(reply?.error || 'host_unavailable');
|
|
10
|
+
return reply.result;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
function notify(text = '') {
|
|
14
|
+
el('notice').textContent = text;
|
|
15
|
+
el('notice').hidden = !text;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
function describe(w) {
|
|
19
|
+
if (w.mode === 'human') return '人工接管';
|
|
20
|
+
if (w.mode === 'transferring') return '交接中';
|
|
21
|
+
if (w.activity?.needsCredential) return '等待凭据';
|
|
22
|
+
const current = w.activity?.current;
|
|
23
|
+
const stage = current?.dispatchState;
|
|
24
|
+
if (stage) return stage === 'dispatched' ? '已派发' : '等待页面';
|
|
25
|
+
return phases[current?.phase] || phases[w.activity?.phase] || 'Agent 控制';
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
function options(node, entries, value) {
|
|
29
|
+
const signature = JSON.stringify(entries);
|
|
30
|
+
if (node.dataset.signature !== signature) {
|
|
31
|
+
node.replaceChildren(...entries.map(([id, title]) => new Option(title, id)));
|
|
32
|
+
node.dataset.signature = signature;
|
|
33
|
+
}
|
|
34
|
+
node.value = value;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
function showCredential(next) {
|
|
38
|
+
const previous = JSON.stringify(request);
|
|
39
|
+
request = next;
|
|
40
|
+
if (previous !== JSON.stringify(next)) el('secret').value = '';
|
|
41
|
+
el('credential').hidden = !next;
|
|
42
|
+
if (!next) return;
|
|
43
|
+
el('credential-target').textContent = next.origin + ' · ' + next.credentialRef;
|
|
44
|
+
el('save').textContent = '绑定凭据';
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
let deliveryKey = '', finishId;
|
|
48
|
+
function renderDelivery(w) {
|
|
49
|
+
const originLabels = {resource:'加载静态资源',navigation:'允许导航与页面操作'};
|
|
50
|
+
const blocks = (w.blockedOrigins || []).filter(item => originLabels[item.scope]);
|
|
51
|
+
el('blocked').replaceChildren(...blocks.map(item => {
|
|
52
|
+
const button = document.createElement('button');
|
|
53
|
+
button.type = 'button';
|
|
54
|
+
button.className = 'secondary';
|
|
55
|
+
button.textContent = '本次' + originLabels[item.scope] + ' · ' + item.origin;
|
|
56
|
+
button.onclick = () => perform(() => call('grantOrigin',{workspaceId:w.workspaceId,
|
|
57
|
+
controlGeneration:w.controlGeneration,origin:item.origin,scope:item.scope}));
|
|
58
|
+
return button;
|
|
59
|
+
}));
|
|
60
|
+
const key = JSON.stringify([w.workspaceId, w.controlGeneration, w.pages.map(p => p.pageId)]);
|
|
61
|
+
if (deliveryKey === key) return;
|
|
62
|
+
deliveryKey = key;
|
|
63
|
+
finishId = crypto.randomUUID();
|
|
64
|
+
el('delivery').open = false;
|
|
65
|
+
el('keep').replaceChildren(...w.pages.map(p => {
|
|
66
|
+
const label = document.createElement('label'), input = document.createElement('input');
|
|
67
|
+
input.type = 'checkbox';
|
|
68
|
+
input.checked = true;
|
|
69
|
+
input.value = p.pageId;
|
|
70
|
+
input.onchange = () => { finishId = crypto.randomUUID(); };
|
|
71
|
+
label.append(input, ' ' + (p.title || p.origin || '页面'));
|
|
72
|
+
return label;
|
|
73
|
+
}));
|
|
74
|
+
}
|
|
75
|
+
el('finish').onclick = () => perform(async () => {
|
|
76
|
+
const keepPageIds = [...el('keep').querySelectorAll('input:checked')].map(input => input.value);
|
|
77
|
+
const receipt = await call('finishWorkspace',{workspaceId:selected,keepPageIds,operationId:finishId,
|
|
78
|
+
controlGeneration:detail.controlGeneration});
|
|
79
|
+
if (receipt.state !== 'completed') { notify('交付待核实 · ' + receipt.operationId); return; }
|
|
80
|
+
notify('已保留 ' + receipt.keptPageIds.length + ' 页,已关闭 ' + receipt.closedPageIds.length + ' 页。');
|
|
81
|
+
render(null);
|
|
82
|
+
});
|
|
83
|
+
|
|
84
|
+
function clearDiagnostic() {
|
|
85
|
+
const link = el('diagnostic-export');
|
|
86
|
+
if (link.hasAttribute('href')) URL.revokeObjectURL(link.href);
|
|
87
|
+
link.removeAttribute('href');
|
|
88
|
+
link.hidden = true;
|
|
89
|
+
el('diagnostic-data').textContent = '';
|
|
90
|
+
}
|
|
91
|
+
el('diagnostic-operation').oninput = clearDiagnostic;
|
|
92
|
+
el('diagnostic-preview').onclick = () => perform(async () => {
|
|
93
|
+
clearDiagnostic();
|
|
94
|
+
const workspaceId = selected, operationId = el('diagnostic-operation').value;
|
|
95
|
+
const data = await call('diagnoseOperation', {workspaceId, operationId});
|
|
96
|
+
if (workspaceId !== selected || operationId !== el('diagnostic-operation').value) return;
|
|
97
|
+
const text = JSON.stringify(data, null, 2);
|
|
98
|
+
el('diagnostic-data').textContent = text;
|
|
99
|
+
const link = el('diagnostic-export');
|
|
100
|
+
link.href = URL.createObjectURL(new Blob([text], {type:'application/json'}));
|
|
101
|
+
link.hidden = false;
|
|
102
|
+
});
|
|
103
|
+
|
|
104
|
+
function render(w) {
|
|
105
|
+
if (detail?.workspaceId !== w?.workspaceId) {
|
|
106
|
+
clearDiagnostic();
|
|
107
|
+
el('diagnostic-operation').value = '';
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
detail = w;
|
|
111
|
+
el('workspace').hidden = !w;
|
|
112
|
+
el('empty').hidden = !!w;
|
|
113
|
+
el('status').textContent = w ? describe(w) + ' · 资料 ' + w.profileId : '暂无工作区';
|
|
114
|
+
if (!w) { showCredential(null); return; }
|
|
115
|
+
renderDialogs(w);
|
|
116
|
+
renderDelivery(w);
|
|
117
|
+
const pages = w.pages || [];
|
|
118
|
+
if (!pages.some(p => p.pageId === selectedTab)) selectedTab = pages.at(-1)?.pageId || '';
|
|
119
|
+
options(el('pages'), pages.map((p, i) => [p.pageId, (i+1) + ' · ' + (p.title || p.origin || '页面')]), selectedTab);
|
|
120
|
+
el('control').textContent = w.mode === 'human' ? '交回 Agent' : '接管此页';
|
|
121
|
+
el('control').disabled = busy || w.mode === 'transferring' || (!selectedTab && w.mode !== 'human');
|
|
122
|
+
el('uploads').hidden = w.mode!=='agent' || !selectedTab;
|
|
123
|
+
el('upload-origin').textContent = pages.find(p=>p.pageId===selectedTab)?.origin || '';
|
|
124
|
+
showCredential(w.mode === 'agent' ? w.activity?.credentialRequest || null : null);
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
async function sync() {
|
|
128
|
+
if (refreshing || busy) return;
|
|
129
|
+
refreshing = true;
|
|
130
|
+
const serial = revision;
|
|
131
|
+
try {
|
|
132
|
+
const list = await call('listWorkspaces');
|
|
133
|
+
if (serial !== revision) return;
|
|
134
|
+
if (!list.some(w => w.workspaceId === selected)) {
|
|
135
|
+
selected = (list.find(w => w.activity?.needsCredential) || list[0])?.workspaceId || '';
|
|
136
|
+
}
|
|
137
|
+
const titles = list.map(workspaceTitle);
|
|
138
|
+
const entries = list.map((w, index) => {
|
|
139
|
+
const title = titles[index];
|
|
140
|
+
const duplicate = titles.indexOf(title) !== titles.lastIndexOf(title);
|
|
141
|
+
const suffix = duplicate ? ' · ' + w.workspaceId.slice(0, 8) : '';
|
|
142
|
+
return [w.workspaceId, title + suffix + ' · ' + describe(w)];
|
|
143
|
+
});
|
|
144
|
+
options(el('workspaces'), entries, selected);
|
|
145
|
+
const w = selected ? await call('getWorkspace', { workspaceId: selected }) : null;
|
|
146
|
+
const [captureReply, downloads, uploads] = w ? await Promise.all([
|
|
147
|
+
call('visualStatus',{workspaceId:selected}).catch(()=>({})),
|
|
148
|
+
call('listDownloads',{workspaceId:selected}),
|
|
149
|
+
call('listUploads',{workspaceId:selected}),
|
|
150
|
+
]) : [{}, [], []];
|
|
151
|
+
const capture = captureReply.lastCapture;
|
|
152
|
+
if (serial === revision) {
|
|
153
|
+
render(w);
|
|
154
|
+
el('upload-list').replaceChildren(...uploads.map(file=>{
|
|
155
|
+
const button=document.createElement('button');
|
|
156
|
+
button.textContent='撤销 '+file.name+' · '+file.origin;
|
|
157
|
+
button.onclick=()=>perform(()=>call('revokeUpload',{workspaceId:w.workspaceId,fileId:file.fileId}));
|
|
158
|
+
return button;
|
|
159
|
+
}));
|
|
160
|
+
renderDownloads(downloads);
|
|
161
|
+
const status=el('visual-status');
|
|
162
|
+
status.hidden=!capture;
|
|
163
|
+
if(capture) status.textContent='最近画面采集 · '+capture.principalId+' · '+capture.origin+' · ('+
|
|
164
|
+
capture.clip.x+', '+capture.clip.y+') '+capture.clip.width+' × '+capture.clip.height;
|
|
165
|
+
}
|
|
166
|
+
} catch (error) {
|
|
167
|
+
if (serial === revision) { render(null); el('status').textContent = '连接失败'; notify(error.message); }
|
|
168
|
+
} finally {
|
|
169
|
+
refreshing = false;
|
|
170
|
+
if (!busy && serial !== revision) void sync();
|
|
171
|
+
}
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
function renderDialogs(w) {
|
|
175
|
+
const panel = el('dialogs'), items = w.pendingDialogs || [];
|
|
176
|
+
const signature = JSON.stringify([w.workspaceId,w.mode,w.controlGeneration,items]);
|
|
177
|
+
if (panel.dataset.signature === signature) return;
|
|
178
|
+
panel.dataset.signature = signature;
|
|
179
|
+
panel.replaceChildren(...items.map(item => {
|
|
180
|
+
const row = document.createElement('div');
|
|
181
|
+
row.textContent = item.origin + ' · ' + item.type + ' · ' + item.message;
|
|
182
|
+
if (w.mode === 'agent') {
|
|
183
|
+
const take = document.createElement('button');
|
|
184
|
+
take.textContent = '接管并处理';
|
|
185
|
+
take.onclick = () => {
|
|
186
|
+
take.disabled = true;
|
|
187
|
+
void call('takeControl',{workspaceId:w.workspaceId,pageId:item.pageId,controlGeneration:w.controlGeneration})
|
|
188
|
+
.catch(error=>notify(error.message)).finally(()=>void sync());
|
|
189
|
+
};
|
|
190
|
+
row.append(take);
|
|
191
|
+
return row;
|
|
192
|
+
}
|
|
193
|
+
const input = document.createElement('input');
|
|
194
|
+
if (item.type === 'prompt') { input.placeholder = '回复'; input.maxLength = 2048; row.append(input); }
|
|
195
|
+
for (const accept of [true,false]) {
|
|
196
|
+
const button = document.createElement('button');
|
|
197
|
+
button.textContent = accept ? '确定' : '取消';
|
|
198
|
+
button.onclick = () => perform(() => call('respondDialog',{workspaceId:w.workspaceId,pageId:item.pageId,
|
|
199
|
+
dialogId:item.dialogId,controlGeneration:w.controlGeneration,accept,
|
|
200
|
+
...(accept && item.type === 'prompt' && {text:input.value})}));
|
|
201
|
+
row.append(button);
|
|
202
|
+
}
|
|
203
|
+
return row;
|
|
204
|
+
}));
|
|
205
|
+
}
|
|
206
|
+
|
|
207
|
+
function renderDownloads(items) {
|
|
208
|
+
el('downloads').hidden = !items.length;
|
|
209
|
+
const labels = {receiving:'下载中',ready:'待保留',failed:'失败',cancelled:'已取消',kept:'已保留'};
|
|
210
|
+
el('download-list').replaceChildren(...items.map(item => {
|
|
211
|
+
const row = document.createElement('p');
|
|
212
|
+
row.textContent = item.filename + ' · ' + labels[item.state] + ' ';
|
|
213
|
+
function button(label, handler) {
|
|
214
|
+
const action = document.createElement('button');
|
|
215
|
+
action.type = 'button';
|
|
216
|
+
action.textContent = label;
|
|
217
|
+
action.onclick = () => perform(handler);
|
|
218
|
+
row.append(action);
|
|
219
|
+
}
|
|
220
|
+
const params = {workspaceId:item.workspaceId,downloadId:item.downloadId};
|
|
221
|
+
if (item.state === 'ready' || item.state === 'kept')
|
|
222
|
+
button(item.state === 'kept' ? '查看保存位置' : '保留文件', async () => notify((await call('keepDownload',params)).path));
|
|
223
|
+
if (item.state === 'receiving' || item.state === 'ready') button('取消', () => call('cancelDownload',params));
|
|
224
|
+
return row;
|
|
225
|
+
}));
|
|
226
|
+
}
|
|
227
|
+
|
|
228
|
+
async function perform(action) {
|
|
229
|
+
if (busy) return;
|
|
230
|
+
busy = true;
|
|
231
|
+
revision++;
|
|
232
|
+
notify();
|
|
233
|
+
for (const element of document.querySelectorAll('button, select, input')) element.disabled = true;
|
|
234
|
+
try { await action(); } catch (error) { notify(error.message); }
|
|
235
|
+
finally {
|
|
236
|
+
busy = false;
|
|
237
|
+
for (const element of document.querySelectorAll('button, select, input')) element.disabled = false;
|
|
238
|
+
render(detail);
|
|
239
|
+
void sync();
|
|
240
|
+
}
|
|
241
|
+
}
|
|
242
|
+
|
|
243
|
+
el('workspaces').onchange = event => {
|
|
244
|
+
selected = event.target.value;
|
|
245
|
+
selectedTab = '';
|
|
246
|
+
revision++;
|
|
247
|
+
render(null);
|
|
248
|
+
void sync();
|
|
249
|
+
};
|
|
250
|
+
el('pages').onchange = event => { selectedTab = event.target.value; render(detail); };
|
|
251
|
+
let uploadTarget;
|
|
252
|
+
function selectedUploadTarget() {
|
|
253
|
+
const target = detail?.pages.find(page=>page.pageId===selectedTab);
|
|
254
|
+
if (!target || detail.mode!=='agent' || detail.workspaceId!==selected || target.origin==='null') return null;
|
|
255
|
+
return {workspaceId:detail.workspaceId,pageId:target.pageId,controlGeneration:detail.controlGeneration,
|
|
256
|
+
documentId:target.documentId,origin:target.origin};
|
|
257
|
+
}
|
|
258
|
+
el('upload-file').onclick = event => {
|
|
259
|
+
uploadTarget = selectedUploadTarget();
|
|
260
|
+
if (!uploadTarget) event.preventDefault();
|
|
261
|
+
};
|
|
262
|
+
el('upload-file').onchange = event => {
|
|
263
|
+
const file=event.target.files[0];
|
|
264
|
+
event.target.value='';
|
|
265
|
+
if (!file) return;
|
|
266
|
+
const target=uploadTarget, current=selectedUploadTarget();
|
|
267
|
+
uploadTarget=null;
|
|
268
|
+
if (!target || !current || Object.keys(target).some(key=>target[key]!==current[key])) {
|
|
269
|
+
notify('页面或控制权已变更,请重新选择文件。');
|
|
270
|
+
return;
|
|
271
|
+
}
|
|
272
|
+
const params={...target,name:file.name,mimeType:file.type};
|
|
273
|
+
void perform(async()=>{
|
|
274
|
+
if (file.size>8*1024*1024) throw Error('单文件上限 8 MiB');
|
|
275
|
+
const data=await new Promise((resolve,reject)=>{
|
|
276
|
+
const reader=new FileReader();
|
|
277
|
+
reader.onload=()=>resolve(reader.result.split(',')[1]);
|
|
278
|
+
reader.onerror=()=>reject(Error('文件读取失败'));
|
|
279
|
+
reader.readAsDataURL(file);
|
|
280
|
+
});
|
|
281
|
+
await call('grantUpload',{...params,data});
|
|
282
|
+
notify('已向 '+params.origin+' 授权 '+file.name+',有效期五分钟。');
|
|
283
|
+
});
|
|
284
|
+
};
|
|
285
|
+
el('control').onclick = () => perform(async () => {
|
|
286
|
+
if (detail.mode === 'human') await call('returnToAgent', { workspaceId: selected, controlGeneration: detail.controlGeneration });
|
|
287
|
+
else await call('takeControl', { workspaceId: selected, pageId: selectedTab, controlGeneration: detail.controlGeneration });
|
|
288
|
+
});
|
|
289
|
+
el('credential').onsubmit = event => {
|
|
290
|
+
event.preventDefault();
|
|
291
|
+
const value = el('secret').value;
|
|
292
|
+
el('secret').value = '';
|
|
293
|
+
if (!value || !request) return;
|
|
294
|
+
const pending = request, workspaceId = selected, generation = detail.controlGeneration;
|
|
295
|
+
void perform(async () => {
|
|
296
|
+
const w = await call('getWorkspace', { workspaceId });
|
|
297
|
+
const fresh = w.activity?.credentialRequest;
|
|
298
|
+
if (w.mode !== 'agent' || generation !== w.controlGeneration || !fresh ||
|
|
299
|
+
['pageId', 'origin', 'credentialRef', 'operationId'].some(k => fresh[k] !== pending[k])) throw new Error('凭据请求已变化');
|
|
300
|
+
await call('resolveCredential', { workspaceId, ...pending, value });
|
|
301
|
+
notify('已绑定凭据,调用方可以重试。');
|
|
302
|
+
});
|
|
303
|
+
};
|
|
304
|
+
|
|
305
|
+
async function open() {
|
|
306
|
+
const explicit = /^#tab-(\d+)(-delivery)?$/.exec(location.hash);
|
|
307
|
+
const tabId = explicit ? Number(explicit[1]) : (await chrome.tabs.query({ active: true, lastFocusedWindow: true }))[0]?.id;
|
|
308
|
+
if (Number.isInteger(tabId)) {
|
|
309
|
+
const key = 'tab:' + tabId;
|
|
310
|
+
const owned = (await chrome.storage.session.get(key))[key];
|
|
311
|
+
if (owned) { selected = owned.workspaceId; selectedTab = owned.pageId; }
|
|
312
|
+
}
|
|
313
|
+
await sync();
|
|
314
|
+
if (explicit?.[2] && detail) el('delivery').open = true;
|
|
315
|
+
}
|
|
316
|
+
void open().catch(() => sync());
|
|
317
|
+
chrome.runtime.onMessage.addListener((message, sender) => {
|
|
318
|
+
if (sender.id === chrome.runtime.id && message?.event === 'workspaceChanged') {
|
|
319
|
+
if (refreshing) revision++;
|
|
320
|
+
else void sync();
|
|
321
|
+
}
|
|
322
|
+
});
|
|
323
|
+
// Recover after a worker restart and refresh ancillary details such as file grants.
|
|
324
|
+
setInterval(sync, 5000);
|
|
@@ -0,0 +1,137 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
const defaultPopup = 'popup.html';
|
|
4
|
+
const tabKey = tabId => 'tab:' + tabId;
|
|
5
|
+
const runningTabs = new Set();
|
|
6
|
+
const activityFrames = ['▶', '▸', '▹', '▸'];
|
|
7
|
+
let animation, frame = 0;
|
|
8
|
+
|
|
9
|
+
function showRunning(tabId, running) {
|
|
10
|
+
if (running) runningTabs.add(tabId);
|
|
11
|
+
else runningTabs.delete(tabId);
|
|
12
|
+
if (runningTabs.size && !animation) {
|
|
13
|
+
animation = setInterval(() => {
|
|
14
|
+
frame = (frame + 1) % activityFrames.length;
|
|
15
|
+
for (const id of runningTabs) {
|
|
16
|
+
chrome.action.setBadgeText({ tabId: id, text: activityFrames[frame] }).catch(() => showRunning(id, false));
|
|
17
|
+
}
|
|
18
|
+
}, 480);
|
|
19
|
+
}
|
|
20
|
+
if (!runningTabs.size && animation) { clearInterval(animation); animation = undefined; }
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
const actionStates = {
|
|
24
|
+
running: ['▶', '#1556b0', '执行中'],
|
|
25
|
+
queued: ['…', '#6757a4', '排队中'],
|
|
26
|
+
actionability: ['⌁', '#1556b0', '检查目标'],
|
|
27
|
+
dispatching: ['▶', '#1556b0', '正在派发'],
|
|
28
|
+
waiting: ['…', '#6757a4', '等待页面'],
|
|
29
|
+
verifying: ['✓', '#526675', '核对结果'],
|
|
30
|
+
needs_credential: ['!', '#a72f24', '等待凭据'],
|
|
31
|
+
completed: ['✓', '#526675', '已完成'],
|
|
32
|
+
failed: ['!', '#a72f24', '执行失败'],
|
|
33
|
+
outcome_unknown: ['?', '#a75d08', '结果待核实'],
|
|
34
|
+
cancelled: ['−', '#626977', '已取消'],
|
|
35
|
+
idle: ['·', '#626977', '等待指令'],
|
|
36
|
+
human: ['人', '#176344', '人工控制'],
|
|
37
|
+
transferring: ['↔', '#926407', '交接中'],
|
|
38
|
+
};
|
|
39
|
+
|
|
40
|
+
async function writeAction(tabId, record) {
|
|
41
|
+
const key = tabKey(tabId);
|
|
42
|
+
if (!record) {
|
|
43
|
+
showRunning(tabId, false);
|
|
44
|
+
await chrome.storage.session.remove(key);
|
|
45
|
+
if (!await chrome.tabs.get(tabId).catch(() => null)) return;
|
|
46
|
+
await Promise.all([
|
|
47
|
+
chrome.action.setPopup({ tabId, popup: defaultPopup }),
|
|
48
|
+
chrome.action.setTitle({ tabId, title: 'open-browser 工作区' }),
|
|
49
|
+
chrome.action.setBadgeText({ tabId, text: '' }),
|
|
50
|
+
]);
|
|
51
|
+
return;
|
|
52
|
+
}
|
|
53
|
+
await chrome.storage.session.set({ [key]: record });
|
|
54
|
+
const phase = record.mode !== 'agent' ? record.mode : record.needsCredential ? 'needs_credential' : record.phase;
|
|
55
|
+
showRunning(tabId, ['running', 'actionability', 'dispatching', 'waiting', 'verifying'].includes(phase));
|
|
56
|
+
const [text, color, status] = actionStates[phase] || actionStates.idle;
|
|
57
|
+
const panel = phase === 'needs_credential' || phase === 'transferring' || !record.controlGeneration;
|
|
58
|
+
const steps = { click: '点击', fill: '填写', fillCredential: '填写凭据' };
|
|
59
|
+
const step = phase === 'running' && record.dispatchState ? (record.dispatchState === 'dispatched' ? '已派发' : '等待页面') : phase === 'running' ? steps[record.stepKind] : '';
|
|
60
|
+
const hint = record.mode === 'human' ? '点击交回 Agent' : panel ? '点击打开工作区面板' : '点击接管';
|
|
61
|
+
await Promise.all([
|
|
62
|
+
chrome.action.setBadgeText({ tabId, text }),
|
|
63
|
+
chrome.action.setBadgeBackgroundColor({ tabId, color }),
|
|
64
|
+
chrome.action.setTitle({ tabId, title: (record.agentName || 'Agent') + ' · ' + (step || status) + ' · ' + hint }),
|
|
65
|
+
chrome.action.setPopup({ tabId, popup: panel ? defaultPopup : '' }),
|
|
66
|
+
]);
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
async function registerAction(tabId, state) {
|
|
70
|
+
if (!state.pageId) return;
|
|
71
|
+
const key = tabKey(tabId);
|
|
72
|
+
const existing = (await chrome.storage.session.get(key))[key];
|
|
73
|
+
const same = existing?.targetId === state.targetId && existing?.workspaceId === state.workspaceId && existing?.pageId === state.pageId;
|
|
74
|
+
const record = { ...(same ? existing : {}), ...state, tabId };
|
|
75
|
+
if (same && existing.mode !== state.mode && !state.controlGeneration) delete record.controlGeneration;
|
|
76
|
+
await writeAction(tabId, record);
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
// Reconcile only records registered by the host, independent of user tab-group edits.
|
|
80
|
+
async function syncTabActions(byId, slots) {
|
|
81
|
+
await Promise.all(Object.entries(slots).filter(([key]) => key.startsWith('tab:')).map(([key, previous]) =>
|
|
82
|
+
forWorkspace(previous.workspaceId, async () => {
|
|
83
|
+
const current = (await chrome.storage.session.get(key))[key];
|
|
84
|
+
if (!current || current.targetId !== previous.targetId) return;
|
|
85
|
+
const state = byId.get(current.workspaceId);
|
|
86
|
+
const pageIds = state?.pageIds || state?.pages?.map(p => typeof p === 'string' ? p : p.pageId);
|
|
87
|
+
if (!state || (pageIds && !pageIds.includes(current.pageId))) return writeAction(current.tabId, null);
|
|
88
|
+
const working = ['running', 'queued'].includes(state.phase);
|
|
89
|
+
const running = state.running?.find(job => job.pageId === current.pageId);
|
|
90
|
+
const phase = running ? (running.phase || 'running') : working && current.pageId !== state.currentPageId ? 'idle' : state.phase;
|
|
91
|
+
const record = { ...current, mode: state.mode, agentName: state.agentName, phase,
|
|
92
|
+
stepKind: running ? (running.stepKind || state.stepKind) : null,
|
|
93
|
+
dispatchState: running ? (running.dispatchState || state.dispatchState) : null,
|
|
94
|
+
needsCredential: state.needsCredential, controlGeneration: state.controlGeneration };
|
|
95
|
+
if (JSON.stringify(record) !== JSON.stringify(current)) await writeAction(current.tabId, record);
|
|
96
|
+
})));
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
chrome.tabs.onRemoved.addListener(tabId => {
|
|
100
|
+
showRunning(tabId, false);
|
|
101
|
+
void chrome.storage.session.remove(tabKey(tabId));
|
|
102
|
+
});
|
|
103
|
+
|
|
104
|
+
async function openWorkspacePanel(tabId, delivery = false) {
|
|
105
|
+
const url = chrome.runtime.getURL(defaultPopup) + (Number.isInteger(tabId) ? '#tab-' + tabId + (delivery ? '-delivery' : '') : '');
|
|
106
|
+
await chrome.windows.create({ url, type: 'popup', width: 380, height: 510, focused: true });
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
const toggling = new Set();
|
|
110
|
+
|
|
111
|
+
async function clickTabAction(tab) {
|
|
112
|
+
const key = tabKey(tab.id);
|
|
113
|
+
const record = (await chrome.storage.session.get(key))[key];
|
|
114
|
+
if (!record) return openWorkspacePanel(tab.id);
|
|
115
|
+
if (toggling.has(record.workspaceId)) return;
|
|
116
|
+
toggling.add(record.workspaceId);
|
|
117
|
+
try {
|
|
118
|
+
const workspace = await hostRequest('getWorkspace', { workspaceId: record.workspaceId });
|
|
119
|
+
if (!workspace.pages.some(p => p.pageId === record.pageId) || workspace.mode !== record.mode ||
|
|
120
|
+
workspace.controlGeneration !== record.controlGeneration || workspace.mode === 'transferring' ||
|
|
121
|
+
(workspace.mode === 'agent' && workspace.activity?.needsCredential)) return openWorkspacePanel(tab.id);
|
|
122
|
+
const target = { workspaceId: record.workspaceId, pageId: record.pageId, controlGeneration: record.controlGeneration };
|
|
123
|
+
await hostRequest(workspace.mode === 'human' ? 'returnToAgent' : 'takeControl', target);
|
|
124
|
+
} catch {
|
|
125
|
+
await openWorkspacePanel(tab.id);
|
|
126
|
+
} finally {
|
|
127
|
+
toggling.delete(record.workspaceId);
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
chrome.action.onClicked.addListener(clickTabAction);
|
|
132
|
+
chrome.runtime.onInstalled.addListener(() => {
|
|
133
|
+
chrome.contextMenus.create({ id: 'workspace-panel', title: '工作区面板', contexts: ['action'] });
|
|
134
|
+
});
|
|
135
|
+
chrome.contextMenus.onClicked.addListener((info, tab) => {
|
|
136
|
+
if (info.menuItemId === 'workspace-panel') void openWorkspacePanel(tab?.id);
|
|
137
|
+
});
|
|
@@ -0,0 +1,188 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
importScripts('workspace-title.js', 'tab-action.js');
|
|
4
|
+
globalThis.openBrowserGroupVersion = 10;
|
|
5
|
+
|
|
6
|
+
const groupsInProgress = new Map();
|
|
7
|
+
|
|
8
|
+
async function groupPage(state) {
|
|
9
|
+
const { targetId, workspaceId } = state;
|
|
10
|
+
const target = (await chrome.debugger.getTargets()).find(t => t.type === 'page' && t.id === targetId);
|
|
11
|
+
if (!Number.isInteger(target?.tabId)) throw new Error('target_not_found');
|
|
12
|
+
const tab = await chrome.tabs.get(target.tabId);
|
|
13
|
+
const key = 'group:' + workspaceId + ':' + tab.windowId;
|
|
14
|
+
const stored = (await chrome.storage.session.get(key))[key];
|
|
15
|
+
const group = Number.isInteger(stored) ? await chrome.tabGroups.get(stored).catch(() => null) : null;
|
|
16
|
+
let groupId;
|
|
17
|
+
if (group && group.windowId === tab.windowId) {
|
|
18
|
+
groupId = group.id;
|
|
19
|
+
if (groupId !== tab.groupId) await chrome.tabs.group({ groupId, tabIds: tab.id });
|
|
20
|
+
} else {
|
|
21
|
+
groupId = await chrome.tabs.group({ tabIds: tab.id, createProperties: { windowId: tab.windowId } });
|
|
22
|
+
await chrome.storage.session.set({ [key]: groupId });
|
|
23
|
+
}
|
|
24
|
+
await updateGroup(groupId, group, state);
|
|
25
|
+
await registerAction(tab.id, state);
|
|
26
|
+
await chrome.storage.session.set({ ['page:' + workspaceId + ':' + state.pageId]: { tabId: tab.id } });
|
|
27
|
+
return { groupId, tabId: tab.id };
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
const agentColors = ['blue', 'purple', 'cyan', 'orange', 'pink'];
|
|
31
|
+
|
|
32
|
+
function agentColor(name = 'Agent') {
|
|
33
|
+
let hash = 0;
|
|
34
|
+
for (const character of name) hash = (Math.imul(hash, 31) + character.codePointAt(0)) >>> 0;
|
|
35
|
+
return agentColors[hash % agentColors.length];
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
async function updateGroup(groupId, group, state) {
|
|
39
|
+
const { mode, phase, needsCredential } = state;
|
|
40
|
+
const attention = needsCredential || ['failed', 'outcome_unknown', 'needs_credential'].includes(phase);
|
|
41
|
+
const color = mode === 'human' ? 'green' : mode === 'transferring' ? 'yellow' : attention ? 'red' : agentColor(state.agentName);
|
|
42
|
+
const title = workspaceTitle(state);
|
|
43
|
+
if (group?.color !== color || group?.title !== title) await chrome.tabGroups.update(groupId, { title, color });
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
// Called in this worker's isolated extension context through the app-owned pipe.
|
|
47
|
+
function forWorkspace(key, operation) {
|
|
48
|
+
const preceding = groupsInProgress.get(key) || Promise.resolve();
|
|
49
|
+
const result = preceding.catch(() => {}).then(operation);
|
|
50
|
+
groupsInProgress.set(key, result);
|
|
51
|
+
const cleanup = () => { if (groupsInProgress.get(key) === result) groupsInProgress.delete(key); };
|
|
52
|
+
result.then(cleanup, cleanup);
|
|
53
|
+
return result;
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
globalThis.openBrowserGroup = params => forWorkspace(params.workspaceId, () => groupPage(params));
|
|
57
|
+
|
|
58
|
+
globalThis.openBrowserRelease = ({workspaceId,pageId}) => forWorkspace(workspaceId, async () => {
|
|
59
|
+
const mappingKey = 'page:' + workspaceId + ':' + pageId;
|
|
60
|
+
const mapping = (await chrome.storage.session.get(mappingKey))[mappingKey];
|
|
61
|
+
let tabId = mapping?.tabId;
|
|
62
|
+
if (!Number.isInteger(tabId)) {
|
|
63
|
+
// Compatibility fallback for profiles created before the page index.
|
|
64
|
+
const slots = await chrome.storage.session.get(null);
|
|
65
|
+
tabId = Object.entries(slots).find(([key,tab]) => key.startsWith('tab:') &&
|
|
66
|
+
tab.workspaceId === workspaceId && tab.pageId === pageId)?.[1]?.tabId;
|
|
67
|
+
}
|
|
68
|
+
if (!Number.isInteger(tabId)) return;
|
|
69
|
+
const tab = await chrome.tabs.get(tabId).catch(() => null);
|
|
70
|
+
const groupKey = 'group:' + workspaceId + ':' + tab?.windowId;
|
|
71
|
+
const group = (await chrome.storage.session.get(groupKey))[groupKey];
|
|
72
|
+
if (tab && tab.groupId >= 0 && group === tab.groupId)
|
|
73
|
+
await chrome.tabs.ungroup(tabId);
|
|
74
|
+
await writeAction(tabId,null);
|
|
75
|
+
await chrome.storage.session.remove(mappingKey);
|
|
76
|
+
});
|
|
77
|
+
|
|
78
|
+
globalThis.openBrowserFrontTab = async function () {
|
|
79
|
+
// A single browser snapshot keeps the active tab and its native window bounds together.
|
|
80
|
+
const win = await chrome.windows.getLastFocused({ populate: true }).catch(() => null);
|
|
81
|
+
if (!win?.focused || win.type !== 'normal' || win.state === 'minimized') return null;
|
|
82
|
+
const tab = win.tabs?.find(item => item.active && item.windowId === win.id);
|
|
83
|
+
if (!Number.isInteger(tab?.id) || !Number.isFinite(tab.width) || tab.width <= 0) return null;
|
|
84
|
+
const { id: windowId, left, top, width, height } = win;
|
|
85
|
+
if (![left, top, width, height].every(Number.isFinite) || width <= 0 || height <= 0) return null;
|
|
86
|
+
const key = tabKey(tab.id);
|
|
87
|
+
const record = (await chrome.storage.session.get(key))[key];
|
|
88
|
+
if (record?.tabId !== tab.id || !record.targetId || !record.workspaceId ||
|
|
89
|
+
!record.pageId || !record.controlGeneration) return null;
|
|
90
|
+
const { workspaceId, pageId, controlGeneration, mode, agentName, phase } = record;
|
|
91
|
+
return { workspaceId, pageId, controlGeneration, mode, agentName: agentName || 'Agent', phase: phase || 'idle',
|
|
92
|
+
dispatchState: record.dispatchState || null,
|
|
93
|
+
windowId, left, top, width, height, viewportWidth: tab.width };
|
|
94
|
+
};
|
|
95
|
+
|
|
96
|
+
globalThis.openBrowserDelivery = async target => {
|
|
97
|
+
const [tab] = await chrome.tabs.query({active:true,windowId:target.windowId});
|
|
98
|
+
if (!tab) return;
|
|
99
|
+
const key = tabKey(tab.id);
|
|
100
|
+
const row = (await chrome.storage.session.get(key))[key];
|
|
101
|
+
if (row?.workspaceId === target.workspaceId && row.pageId === target.pageId &&
|
|
102
|
+
row.controlGeneration === target.controlGeneration) await openWorkspacePanel(tab.id,true);
|
|
103
|
+
};
|
|
104
|
+
|
|
105
|
+
globalThis.openBrowserSync = async function (states) {
|
|
106
|
+
const byId = new Map(states.map(state => [state.workspaceId, state]));
|
|
107
|
+
const slots = await chrome.storage.session.get(null);
|
|
108
|
+
await syncTabActions(byId, slots);
|
|
109
|
+
await Promise.all(Object.entries(slots).filter(([key]) => key.startsWith('group:')).map(([key, id]) => {
|
|
110
|
+
const wsId = key.slice(6, key.lastIndexOf(':'));
|
|
111
|
+
return forWorkspace(wsId, async () => {
|
|
112
|
+
if ((await chrome.storage.session.get(key))[key] !== id) return;
|
|
113
|
+
const state = byId.get(wsId);
|
|
114
|
+
const group = state && await chrome.tabGroups.get(id).catch(() => null);
|
|
115
|
+
if (group) await updateGroup(id, group, state);
|
|
116
|
+
else await chrome.storage.session.remove(key);
|
|
117
|
+
});
|
|
118
|
+
}));
|
|
119
|
+
void chrome.runtime.sendMessage({event:'workspaceChanged'}).catch(() => {});
|
|
120
|
+
};
|
|
121
|
+
|
|
122
|
+
globalThis.openBrowserShow = async function () {
|
|
123
|
+
const windows = await chrome.windows.getAll({ windowTypes: ['normal'] });
|
|
124
|
+
const current = windows.find(w => w.focused) || await chrome.windows.getLastFocused({ windowTypes: ['normal'] }).catch(() => null);
|
|
125
|
+
if (current) return (await chrome.windows.update(current.id, { focused: true, ...(current.state === 'minimized' ? { state: 'normal' } : {}) })).id;
|
|
126
|
+
return (await chrome.windows.create({ focused: true })).id;
|
|
127
|
+
};
|
|
128
|
+
|
|
129
|
+
const newtabMethods = new Set(['listWorkspaces', 'listAgentHistory']);
|
|
130
|
+
const methods = new Set(['listUploads','grantUpload','revokeUpload','respondDialog','listDownloads','cancelDownload','keepDownload','visualStatus','diagnoseOperation', 'listWorkspaces', 'getWorkspace', 'takeControl', 'returnToAgent', 'grantOrigin', 'resolveCredential', 'finishWorkspace']);
|
|
131
|
+
const pending = new Map();
|
|
132
|
+
const queued = [];
|
|
133
|
+
let waiting;
|
|
134
|
+
|
|
135
|
+
chrome.runtime.onMessage.addListener((message, sender, respond) => {
|
|
136
|
+
const source = sender.url?.split('#')[0];
|
|
137
|
+
const popup = source === chrome.runtime.getURL('popup.html');
|
|
138
|
+
const newtab = source === chrome.runtime.getURL('newtab.html');
|
|
139
|
+
if (sender.id !== chrome.runtime.id || (!popup && !newtab) ||
|
|
140
|
+
(sender.frameId !== undefined && sender.frameId !== 0)) return false;
|
|
141
|
+
const allowed = newtab ? newtabMethods : methods;
|
|
142
|
+
if (!allowed.has(message?.method) || !message.params || typeof message.params !== 'object' || Array.isArray(message.params)) {
|
|
143
|
+
respond({ error: 'invalid_request' });
|
|
144
|
+
return false;
|
|
145
|
+
}
|
|
146
|
+
hostRequest(message.method, message.params).then(result => respond({ result }), error => respond({ error: error.message }));
|
|
147
|
+
return true;
|
|
148
|
+
});
|
|
149
|
+
|
|
150
|
+
function hostRequest(method, params) {
|
|
151
|
+
if (pending.size >= 64) return Promise.reject(new Error('queue_full'));
|
|
152
|
+
return new Promise((resolve, reject) => {
|
|
153
|
+
const id = crypto.randomUUID();
|
|
154
|
+
const timer = setTimeout(() => {
|
|
155
|
+
pending.delete(id);
|
|
156
|
+
const index = queued.findIndex(request => request.id === id);
|
|
157
|
+
if (index >= 0) queued.splice(index, 1);
|
|
158
|
+
reject(new Error('host_timeout'));
|
|
159
|
+
}, 60_000);
|
|
160
|
+
pending.set(id, { resolve, reject, timer });
|
|
161
|
+
const request = { id, method, params };
|
|
162
|
+
if (waiting) waiting(request);
|
|
163
|
+
else queued.push(request);
|
|
164
|
+
});
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
globalThis.openBrowserNext = function () {
|
|
168
|
+
if (queued.length) return queued.shift();
|
|
169
|
+
if (waiting) waiting(null);
|
|
170
|
+
return new Promise(resolve => {
|
|
171
|
+
const timer = setTimeout(() => waiting(null), 3000);
|
|
172
|
+
waiting = request => {
|
|
173
|
+
clearTimeout(timer);
|
|
174
|
+
waiting = undefined;
|
|
175
|
+
resolve(request);
|
|
176
|
+
};
|
|
177
|
+
});
|
|
178
|
+
};
|
|
179
|
+
|
|
180
|
+
globalThis.openBrowserReply = function ({ id, result, error }) {
|
|
181
|
+
const call = pending.get(id);
|
|
182
|
+
if (!call) return false;
|
|
183
|
+
pending.delete(id);
|
|
184
|
+
clearTimeout(call.timer);
|
|
185
|
+
if (error) call.reject(new Error(error));
|
|
186
|
+
else call.resolve(result);
|
|
187
|
+
return true;
|
|
188
|
+
};
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
function workspaceTitle({ agentName, name, mode }) {
|
|
4
|
+
const agent = agentName || 'Agent';
|
|
5
|
+
const task = typeof name === 'string' && name.trim() ? name.trim() : '未命名任务';
|
|
6
|
+
const title = agent + ' · ' + task;
|
|
7
|
+
return mode === 'human' ? '人工 · ' + title : title;
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
function workspaceNeedsName({ name }) {
|
|
11
|
+
return !(typeof name === 'string' && name.trim());
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
globalThis.openBrowserWorkspaceTitle = workspaceTitle;
|
|
15
|
+
globalThis.openBrowserWorkspaceNeedsName = workspaceNeedsName;
|