@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.
Files changed (61) hide show
  1. package/Docs/open-browser-api.d.ts +23 -5
  2. 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
  3. package/README.md +14 -5
  4. package/README.zh-CN.md +16 -5
  5. package/access-registry.mjs +5 -0
  6. package/action-execution.mjs +32 -21
  7. package/api-contract.mjs +14 -2
  8. package/browser-extension/manifest.json +1 -4
  9. package/browser-extension/newtab.css +6 -0
  10. package/browser-extension/newtab.js +53 -2
  11. package/browser-extension/phase-labels.js +1 -1
  12. package/browser-extension/popup.css +1 -1
  13. package/browser-extension/popup.html +14 -4
  14. package/browser-extension/popup.js +101 -20
  15. package/browser-extension/tab-action.js +3 -2
  16. package/browser-extension/worker.js +102 -9
  17. package/build-profile.mjs +23 -0
  18. package/capability-matrix.mjs +3 -3
  19. package/chromium-host.mjs +78 -18
  20. package/chromium-shell.mjs +77 -48
  21. package/cli.mjs +59 -1
  22. package/contract-validation.mjs +1 -1
  23. package/desktop/Info.plist +1 -1
  24. package/desktop/OBControlBar.m +7 -3
  25. package/desktop/WorkspacePanel.m +2 -1
  26. package/desktop/brand-keychain.py +20 -4
  27. package/desktop/build-macos.mjs +26 -10
  28. package/desktop/build-managed-input.mjs +37 -0
  29. package/desktop/build-profile.mjs +6 -0
  30. package/desktop/build.mjs +8 -0
  31. package/desktop/macos-entitlements.plist +12 -0
  32. package/desktop/notarize-macos.mjs +145 -0
  33. package/desktop/package-macos.mjs +54 -0
  34. package/desktop/patches/chromium-managed-input.patch +144 -0
  35. package/desktop/sign.mjs +48 -4
  36. package/desktop/start-profile.mjs +5 -0
  37. package/desktop/start.mjs +25 -3
  38. package/desktop/verify-macos-release.mjs +61 -0
  39. package/diagnostics.mjs +9 -0
  40. package/engine-service.mjs +174 -18
  41. package/managed-input.mjs +138 -0
  42. package/mcp-http.mjs +84 -0
  43. package/mcp-server.mjs +41 -0
  44. package/mcp.mjs +2 -40
  45. package/package.json +22 -2
  46. package/page-activity.mjs +95 -28
  47. package/page-observation.mjs +41 -3
  48. package/paths.mjs +5 -3
  49. package/receipt-store.mjs +9 -2
  50. package/runtime.mjs +10 -1
  51. package/sdk.mjs +32 -15
  52. package/service.mjs +21 -2
  53. package/skill-links.mjs +90 -0
  54. package/skills/open-browser/SKILL.macos.md +112 -0
  55. package/skills/open-browser/SKILL.md +24 -3
  56. package/skills/open-browser/SKILL.windows.md +112 -0
  57. package/skills/open-browser/scripts/bootstrap.mjs +80 -1
  58. package/tab-adoption.mjs +77 -0
  59. package/uploads.mjs +4 -4
  60. package/workspace-lifecycle.mjs +74 -6
  61. package/workspace-state.mjs +14 -2
@@ -1,6 +1,7 @@
1
1
  #!/usr/bin/env node
2
- import { access } from 'node:fs/promises';
2
+ import { access, readFile } from 'node:fs/promises';
3
3
  import { spawn } from 'node:child_process';
4
+ import net from 'node:net';
4
5
  import path from 'node:path';
5
6
  import { pathToFileURL } from 'node:url';
6
7
 
@@ -34,7 +35,25 @@ function detached(command, args, options = {}) {
34
35
  child.unref();
35
36
  }
36
37
 
38
+ async function wakeExisting(root) {
39
+ try {
40
+ const { pidPath, socketPath } = await import(pathToFileURL(path.join(root, 'paths.mjs')).href);
41
+ const pid = Number((await readFile(pidPath, 'utf8')).trim());
42
+ if (!Number.isSafeInteger(pid) || pid <= 0) return false;
43
+ process.kill(pid, 0);
44
+ const active = await new Promise(resolve => {
45
+ const probe = net.connect(socketPath);
46
+ probe.once('connect', () => { probe.destroy(); resolve(true); });
47
+ probe.once('error', () => resolve(false));
48
+ });
49
+ if (!active) return false;
50
+ process.kill(pid, 'SIGUSR2');
51
+ return true;
52
+ } catch { return false; }
53
+ }
54
+
37
55
  async function startLocalBrowser(root) {
56
+ if (await wakeExisting(root)) return;
38
57
  const appBundle = process.platform === 'darwin' && path.basename(root) === 'app'
39
58
  ? path.resolve(root, '../../../')
40
59
  : undefined;
@@ -103,6 +122,56 @@ async function waitForService(node, root) {
103
122
  return false;
104
123
  }
105
124
 
125
+ async function runSession(node, root, args) {
126
+ let probe = await run(node, root, ['capabilities'], '{}\n');
127
+ const errorCode = parseErrorCode(probe.stderr);
128
+ if (probe.code !== 0 && ['SERVICE_UNAVAILABLE', 'not_ready'].includes(errorCode) && process.env.OPEN_BROWSER_AUTOSTART !== '0') {
129
+ if (errorCode === 'SERVICE_UNAVAILABLE') {
130
+ try { await startLocalBrowser(root); } catch { /* return the original service error below */ }
131
+ }
132
+ if (await waitForService(node, root)) probe = { code: 0 };
133
+ }
134
+ if (probe.code !== 0) {
135
+ if (probe.stdout) process.stdout.write(probe.stdout);
136
+ if (probe.stderr) process.stderr.write(probe.stderr);
137
+ return probe.code;
138
+ }
139
+ const child = spawn(node, [path.join(root, 'cli.mjs'), ...args], {
140
+ cwd: root,
141
+ env: process.env,
142
+ stdio: 'inherit',
143
+ });
144
+ return new Promise(resolve => child.once('close', code => resolve(code ?? 1)));
145
+ }
146
+
147
+ async function installSkillLinks(root) {
148
+ if (process.env.OPEN_BROWSER_AUTO_INSTALL_SKILLS === '0') return;
149
+ const installer = path.join(root, 'skill-links.mjs');
150
+ if (!await executable(installer)) return;
151
+ try {
152
+ const { installAgentSkillLinks } = await import(pathToFileURL(installer).href);
153
+ const result = await installAgentSkillLinks({ source: path.join(root, 'skills', 'open-browser') });
154
+ if (process.env.OPEN_BROWSER_SKILLS_VERBOSE === '1') process.stderr.write(JSON.stringify({ skillLinks: result }) + '\n');
155
+ } catch (error) {
156
+ if (process.env.OPEN_BROWSER_SKILLS_VERBOSE === '1') process.stderr.write(JSON.stringify({ skillLinksError: error.message }) + '\n');
157
+ }
158
+ }
159
+
160
+ async function printSkillGuide(root) {
161
+ const platform = process.platform === 'darwin' ? 'macos' : process.platform === 'win32' ? 'windows' : null;
162
+ const candidates = platform
163
+ ? [path.join(root, 'skills', 'open-browser', `SKILL.${platform}.md`), path.join(root, 'skills', 'open-browser', 'SKILL.md')]
164
+ : [path.join(root, 'skills', 'open-browser', 'SKILL.md')];
165
+ for (const guide of candidates) {
166
+ try {
167
+ const { readFile } = await import('node:fs/promises');
168
+ process.stdout.write(await readFile(guide, 'utf8'));
169
+ return;
170
+ } catch {}
171
+ }
172
+ throw Object.assign(new Error(`未找到 Skill 指南。已检查:${candidates.join('、')}`), { code: 'SKILL_GUIDE_NOT_FOUND' });
173
+ }
174
+
106
175
  export async function invoke({ node, root, args, input, start = startLocalBrowser }) {
107
176
  const first = await run(node, root, args, input);
108
177
  if (first.code === 0) return first;
@@ -118,6 +187,16 @@ export async function invoke({ node, root, args, input, start = startLocalBrowse
118
187
  async function main() {
119
188
  const [root, ...args] = process.argv.slice(2);
120
189
  if (!root) throw new Error('OPEN_BROWSER_CLI_ROOT_REQUIRED');
190
+ if (args[0] === 'skill') {
191
+ if (args.length > 1) throw Object.assign(new Error('skill 不接受额外参数。'), { code: 'INVALID_PARAMS' });
192
+ await printSkillGuide(root);
193
+ return;
194
+ }
195
+ await installSkillLinks(root);
196
+ if (args[0] === 'session') {
197
+ process.exitCode = await runSession(process.execPath, root, args);
198
+ return;
199
+ }
121
200
  const chunks = [];
122
201
  for await (const chunk of process.stdin) chunks.push(chunk);
123
202
  const result = await invoke({ node: process.execPath, root, args, input: Buffer.concat(chunks) });
@@ -0,0 +1,77 @@
1
+ import { randomBytes } from 'node:crypto';
2
+ import { fail, webOrigin } from './workspace-state.mjs';
3
+ import { refreshTitle } from './desktop-page.mjs';
4
+
5
+ // Only the packaged extension supplies a target ID. Agent clients receive an
6
+ // expiring capability scoped to one workspace and never enumerate ordinary tabs.
7
+ export async function offerTab(service, ws, {targetId, origin, accountAlias}) {
8
+ if (!service.sharedContext || service.actors.getStore() !== 'desktop') fail('forbidden');
9
+ if (ws.everRegistered || ws.pending || ws.mode !== 'agent') fail('adoption_requires_empty_workspace');
10
+ if (webOrigin(origin) !== origin || typeof targetId !== 'string' ||
11
+ (accountAlias !== undefined && (typeof accountAlias !== 'string' || accountAlias.length > 48))) fail('invalid_params');
12
+ const context = service.sharedContext;
13
+ for (const candidate of context.pages()) {
14
+ if (URL.parse(candidate.url())?.origin !== origin) continue;
15
+ const session = await context.newCDPSession(candidate).catch(() => null);
16
+ if (!session) continue;
17
+ let info;
18
+ try { info = (await session.send('Target.getTargetInfo')).targetInfo; }
19
+ finally { await session.detach().catch(() => {}); }
20
+ if (info.targetId !== targetId) continue;
21
+ if (service.workspaces.get(ws.id) !== ws || ws.mode !== 'agent' || ws.everRegistered) fail('adoption_requires_empty_workspace');
22
+ if (candidate.isClosed() || webOrigin(candidate.url()) !== origin) break;
23
+ if ([...service.workspaces.values()].some(w => [...w.pages.values()].some(t => t.page === candidate)))
24
+ fail('page_already_managed');
25
+ for (const other of service.workspaces.values()) {
26
+ if (other.offer?.page === candidate) other.offer.revoke();
27
+ }
28
+ const token = randomBytes(32).toString('hex');
29
+ ws.offer?.revoke();
30
+ const revoke = () => {
31
+ clearTimeout(timer);
32
+ candidate.off('framenavigated', navigated);
33
+ candidate.off('close', revoke);
34
+ ws.offer = null;
35
+ };
36
+ const navigated = frame => { if (frame === candidate.mainFrame()) revoke(); };
37
+ const timer = setTimeout(revoke, 120_000).unref();
38
+ candidate.on('framenavigated', navigated);
39
+ candidate.once('close', revoke);
40
+ ws.offer = {revoke, page:candidate, origin, token, targetId, accountAlias, expiresAt:Date.now() + 120_000};
41
+ return {adoptionToken:token, workspaceId:ws.id, expiresAt:ws.offer.expiresAt};
42
+ }
43
+ fail('adoption_page_changed');
44
+ }
45
+
46
+ export async function adoptTab(service, ws, params) {
47
+ if (service.actors.getStore() !== ws.owner) fail('forbidden');
48
+ const offer = ws.offer;
49
+ if (!offer || offer.token !== params.adoptionToken || Date.now() >= offer.expiresAt) fail('adoption_expired');
50
+ offer.revoke();
51
+ if (ws.pending || ws.everRegistered || ws.mode !== 'agent') fail('adoption_requires_empty_workspace');
52
+ if (offer.page.isClosed() || URL.parse(offer.page.url())?.origin !== offer.origin) fail('adoption_page_changed');
53
+ ws.singleTab = true;
54
+ ws.networkMode = 'browser';
55
+ ws.origins = new Set([offer.origin]);
56
+ ws.resourceOrigins.clear();
57
+ ws.accountAlias = offer.accountAlias;
58
+ const tab = service.register(ws, offer.page);
59
+ tab.targetId = offer.targetId;
60
+ tab.createdByAgent = false;
61
+ // Bind before yielding so a concurrent redemption cannot claim this page.
62
+ return service.enqueue(ws, async () => {
63
+ await service.setInputGuard?.(ws, tab, true);
64
+ // Extension registration is retryable via reattachPage. Keep the selected
65
+ // page and its capability when only the extension acknowledgement is late.
66
+ try { await service.syncTab(ws, tab); }
67
+ catch (error) { if (error.code !== 'sync_pending') throw error; }
68
+ await refreshTitle(ws, tab);
69
+ service.requireControl(ws, ws.generation);
70
+ if (offer.page.isClosed() || URL.parse(offer.page.url())?.origin !== offer.origin) fail('adoption_page_changed');
71
+ return {workspaceId:ws.id, pageId:tab.id};
72
+ }, {kind:'adoptCurrentTab', pageId:tab.id}).catch(async error => {
73
+ // A concurrent takeover/close owns the release sequence.
74
+ if (ws.mode === 'agent' && !ws.finishing) await service.call('closeWorkspace',{workspaceId:ws.id},ws.owner);
75
+ throw error;
76
+ });
77
+ }
package/uploads.mjs CHANGED
@@ -38,7 +38,7 @@ export class UploadGrants {
38
38
  }
39
39
  }
40
40
 
41
- export async function chooseGrantedFile(ws,tab,el,id,beforeDispatch,check) {
41
+ export async function chooseGrantedFile(ws,tab,el,id,beforeDispatch,dispatch,check) {
42
42
  ws.uploads.get(ws,tab,id);
43
43
  // Register the chooser before dispatch. Many pages create a detached input during click.
44
44
  let receive, timer;
@@ -49,13 +49,13 @@ export async function chooseGrantedFile(ws,tab,el,id,beforeDispatch,check) {
49
49
  });
50
50
  try {
51
51
  beforeDispatch();
52
- const [chooser]=await Promise.all([chosen,el.click({timeout:5000})]);
52
+ const [chooser]=await Promise.all([chosen,dispatch(() => el.click({timeout:5000}))]);
53
53
  const frame=await chooser.element().ownerFrame();
54
54
  if (frame!==tab.page.mainFrame()) fail('file_origin_mismatch');
55
- check();
55
+ (check || (() => {}))();
56
56
  const {payload}=ws.uploads.get(ws,tab,id);
57
57
  ws.uploads.remove(id);
58
- await chooser.setFiles(payload,{timeout:5000});
58
+ await dispatch(() => chooser.setFiles(payload,{timeout:5000}));
59
59
  } finally {
60
60
  clearTimeout(timer);
61
61
  tab.page.off('filechooser',receive);
@@ -9,6 +9,16 @@ export function finishDigest(keepPageIds) {
9
9
  return createHash('sha256').update(JSON.stringify(['finish', [...keepPageIds].sort()])).digest('hex');
10
10
  }
11
11
 
12
+ export function previewFinish(service, ws, keepPageIds) {
13
+ const digest = finishDigest(keepPageIds);
14
+ for (const id of keepPageIds) service.tab(ws, id);
15
+ const keptPageIds = [], closedPageIds = [];
16
+ for (const tab of ws.pages.values())
17
+ (keepPageIds.includes(tab.id) || !tab.createdByAgent ? keptPageIds : closedPageIds).push(tab.id);
18
+ const previewId = createHash('sha256').update(JSON.stringify([ws.id, ws.generation, digest, keptPageIds, closedPageIds])).digest('hex');
19
+ return {previewId, keptPageIds, closedPageIds};
20
+ }
21
+
12
22
  function stopOperations(ws, controlTransferred = false) {
13
23
  ws.uploads?.clear();
14
24
  ws.control.abort();
@@ -19,7 +29,7 @@ function stopOperations(ws, controlTransferred = false) {
19
29
  }
20
30
  }
21
31
 
22
- export async function finish(service, ws, {operationId, keepPageIds, controlGeneration}, trusted = false) {
32
+ export async function finish(service, ws, {operationId, keepPageIds, controlGeneration, previewId}, trusted = false) {
23
33
  stringParam(operationId, 160);
24
34
  const digest = finishDigest(keepPageIds);
25
35
  const past = service.store.get(ws.owner, ws.id, operationId);
@@ -29,8 +39,11 @@ export async function finish(service, ws, {operationId, keepPageIds, controlGene
29
39
  }
30
40
  if (controlGeneration !== undefined && controlGeneration !== ws.generation) fail('stale_control');
31
41
  if (ws.finishing) fail('workspace_finishing');
42
+ if (previewId !== undefined && (ws.pending || ws.inputPending || ws.popupTasks.size ||
43
+ previewFinish(service, ws, keepPageIds).previewId !== previewId)) fail('finish_preview_changed');
32
44
  if (!trusted || ws.mode !== 'human') service.requireControl(ws, ws.generation);
33
45
  for (const id of keepPageIds) service.tab(ws, id);
46
+ ws.offer?.revoke();
34
47
  const keep = new Set(keepPageIds);
35
48
  const receipt = { operationId, state:'running', phase:'running', totalSteps:ws.pages.size, completedSteps:0, keptPageIds:[], closedPageIds:[] };
36
49
  service.store.save(ws.owner, ws.id, digest, receipt);
@@ -51,6 +64,7 @@ export async function finish(service, ws, {operationId, keepPageIds, controlGene
51
64
  service.store.save(ws.owner, ws.id, digest, receipt, true);
52
65
  if (keep.has(tab.id) || !tab.createdByAgent) {
53
66
  await releaseInput(tab);
67
+ await service.setInputGuard?.(ws, tab, false);
54
68
  await service.releaseTab?.(tab.page, ws.id, tab.id);
55
69
  await tab.releasePopups?.();
56
70
  await tab.networkRelease?.();
@@ -83,7 +97,13 @@ export async function finish(service, ws, {operationId, keepPageIds, controlGene
83
97
  receipt.state = 'outcome_unknown';
84
98
  receipt.phase = 'outcome_unknown';
85
99
  receipt.error = 'inspect_before_retry';
86
- ws.mode = 'human';
100
+ ws.mode = 'transferring';
101
+ try {
102
+ await setWorkspaceGuard(service, ws, false);
103
+ ws.mode = 'human';
104
+ } catch {
105
+ ws.unlockPending = true;
106
+ }
87
107
  ws.generation = randomUUID();
88
108
  service.notify(ws);
89
109
  } finally {
@@ -110,6 +130,14 @@ export async function handOff(service, ws, pageId, focus = true, expectedGenerat
110
130
  ws.handoff = (async () => {
111
131
  await Promise.allSettled([ws.tail,...ws.popupTasks]);
112
132
  for (const candidate of ws.pages.values()) clearRefs(candidate);
133
+ try {
134
+ await setWorkspaceGuard(service, ws, false);
135
+ } catch (error) {
136
+ ws.unlockPending = true;
137
+ service.notify(ws);
138
+ throw error;
139
+ }
140
+ ws.unlockPending = false;
113
141
  if (ws.mode !== 'transferring') fail('workspace_closed');
114
142
  ws.mode = 'human';
115
143
  service.store.event(ws.owner, ws.id, 'control', ws.mode);
@@ -122,10 +150,20 @@ export async function handOff(service, ws, pageId, focus = true, expectedGenerat
122
150
  return ws.handoff;
123
151
  }
124
152
 
153
+ async function setWorkspaceGuard(service, ws, enabled) {
154
+ if (!service.setInputGuard) return;
155
+ const results = await Promise.allSettled([...ws.pages.values()].map(async tab => {
156
+ try { await service.setInputGuard(ws, tab, enabled); }
157
+ catch (error) { if (!tab.page.isClosed()) throw error; }
158
+ }));
159
+ const failed = results.find(result => result.status === 'rejected');
160
+ if (failed) throw failed.reason;
161
+ }
162
+
125
163
  async function refreshControlGroups(service, ws) {
126
164
  if (!service.groupTab) return;
127
165
  await Promise.allSettled([...ws.pages.values()].filter(tab => !tab.dialog && !tab.page.isClosed())
128
- .map(async tab => service.groupTab(tab.page, ws.id, ws.name, ws.mode, ws.agentName, tab.id)));
166
+ .map(async tab => service.syncTab(ws, tab)));
129
167
  }
130
168
 
131
169
  export async function returnToAgent(service, ws, expectedGeneration) {
@@ -137,9 +175,30 @@ export async function returnToAgent(service, ws, expectedGeneration) {
137
175
  ws.generation = randomUUID();
138
176
  service.notify(ws);
139
177
  ws.returning = (async () => {
140
- await ws.inputTail;
141
- await Promise.all([...ws.pages.values()].map(releaseInput));
178
+ try {
179
+ await ws.inputTail;
180
+ await Promise.all([...ws.pages.values()].map(releaseInput));
181
+ ws.guardLost = false;
182
+ await setWorkspaceGuard(service, ws, true);
183
+ if (ws.guardLost) fail('input_guard_unavailable');
184
+ } catch (error) {
185
+ try { await setWorkspaceGuard(service, ws, false); }
186
+ catch (rollbackError) {
187
+ ws.unlockPending = true;
188
+ service.notify(ws);
189
+ throw rollbackError;
190
+ }
191
+ if (ws.mode === 'transferring') {
192
+ ws.mode = 'human';
193
+ service.store.event(ws.owner, ws.id, 'control', ws.mode);
194
+ service.notify(ws);
195
+ }
196
+ throw error;
197
+ }
142
198
  if (ws.mode !== 'transferring') fail('workspace_closed');
199
+ // Returning control acknowledges that the user handled the visible site
200
+ // verification. A later navigation or response can raise it again.
201
+ ws.securityChallenge = null;
143
202
  ws.control = new AbortController();
144
203
  ws.mode = 'agent';
145
204
  service.store.event(ws.owner, ws.id, 'control', ws.mode);
@@ -151,6 +210,7 @@ export async function returnToAgent(service, ws, expectedGeneration) {
151
210
  }
152
211
 
153
212
  export async function close(service, ws) {
213
+ ws.offer?.revoke();
154
214
  for (const tab of ws.pages.values()) discardDialog(tab);
155
215
  ws.mode = 'closed';
156
216
  service.store.event(ws.owner, ws.id, 'control', ws.mode);
@@ -160,7 +220,15 @@ export async function close(service, ws) {
160
220
  await ws.downloads?.close();
161
221
  if (service.sharedContext) {
162
222
  await Promise.allSettled([ws.tail, ws.inputTail,...ws.popupTasks]);
163
- await Promise.all([...ws.pages.values()].map(async ({page,id}) => {
223
+ await Promise.all([...ws.pages.values()].map(async tab => {
224
+ const {page, id} = tab;
225
+ if (ws.singleTab) {
226
+ await releaseInput(tab);
227
+ await service.setInputGuard?.(ws, tab, false);
228
+ try { await service.releaseTab?.(page, ws.id, id); }
229
+ finally { tab.unregister(); }
230
+ return;
231
+ }
164
232
  if (!page.isClosed() && service.releaseTab) await service.releaseTab(page,ws.id,id).catch(() => {});
165
233
  await page.close().catch(() => {});
166
234
  }));
@@ -72,6 +72,9 @@ export function workspaceView(ws, includeCredentialRequest = false) {
72
72
  const origin = allowedPageOrigin(ws, tab);
73
73
  return { workspaceId: ws.id, pageId: tab.id, documentId:tab.documentId, origin: origin || 'null',
74
74
  ...(tab.openerPageId && {openerPageId:tab.openerPageId,openedByOperationId:tab.openedByOperationId}),
75
+ ownership:ws.singleTab ? 'user' : tab.createdByAgent ? 'agent' : 'user',
76
+ syncState:!tab.extensionSync ? 'not_required' : tab.syncedGeneration === ws.generation ? 'synced' : 'sync_pending',
77
+ syncRevision:tab.syncRevision || 0, lastSyncedAt:tab.lastSyncedAt || null,
75
78
  title: origin ? redact(ws, tab.title) : '' };
76
79
  });
77
80
  const pending = [...ws.jobs];
@@ -83,13 +86,22 @@ export function workspaceView(ws, includeCredentialRequest = false) {
83
86
  const request = ws.credentialRequests.values().next().value;
84
87
  const recent = operationView(ws.recent);
85
88
  let phase = 'idle';
86
- if (current) phase = current.state;
89
+ if (ws.securityChallenge) phase = 'needs_human_verification';
90
+ else if (current) phase = current.state;
87
91
  else if (request) phase = 'needs_credential';
88
92
  else if (recent && recent.error !== 'credential_required') phase = recent.state;
89
93
  return { workspaceId: ws.id, profileId: serviceProfileId, name: ws.name, agentName: ws.agentName, mode: ws.mode, controlGeneration: ws.generation, pages,
94
+ pageAvailability:pages.length ? 'managed' : current?.kind === 'openPage' ? 'sync_pending' : ws.everRegistered ? 'closed' : 'unregistered',
95
+ scope:ws.singleTab ? 'single_tab' : 'workspace',
96
+ nextAction:pages.length ? (ws.mode === 'agent' ? 'reattachPage' : 'wait_for_agent_control') : current?.kind === 'openPage' ? 'wait_for_sync' : 'request_tab_selection',
97
+ ...(ws.accountAlias && {accountAlias:ws.accountAlias}),
90
98
  ...(includeCredentialRequest && {pendingDialogs: [...ws.pages.values()].flatMap(tab=>tab.dialog ? [tab.dialog.info] : [])}),
91
99
  ...(includeCredentialRequest && { blockedOrigins: [...ws.blockedOrigins.values()] }),
92
- activity: { phase, queued: queued.length, needsCredential: !!request, current, recent,
100
+ ...(ws.mode === 'transferring' && ws.unlockPending && {unlockPending:true}),
101
+ security: { inputGuard: ws.inputGuardMode || 'unavailable' },
102
+ activity: { phase, queued: queued.length, needsCredential: !!request,
103
+ needsHumanVerification: !!ws.securityChallenge,
104
+ ...(ws.securityChallenge && { securityChallenge: { ...ws.securityChallenge } }), current, recent,
93
105
  running: running.map(job => ({ ...operationView(job), ...(ws.pages.has(job.pageId) && {pageId:job.pageId}) })),
94
106
  credentialRequest: request && includeCredentialRequest ? { ...request } : null } };
95
107
  }