dsh-builtin-browser 1.0.1 → 1.0.4
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/CHANGELOG.md +55 -0
- package/README.md +1 -1
- package/assets/browser-panel-locales.mjs +37 -5
- package/assets/browser-policy.d.mts +29 -0
- package/assets/browser-policy.mjs +40 -0
- package/desktop-bridge/desktop-discovery.d.mts +1 -1
- package/desktop-bridge/desktop-discovery.mjs +59 -9
- package/desktop-bridge/desktop-identity.json +12 -0
- package/desktop-bridge/install.mjs +14 -7
- package/desktop-bridge/plugin-browser-bridge.js +19 -7
- package/docs/acceptance-2026-11-27.md +67 -0
- package/docs/architecture.md +1 -1
- package/docs/development.md +33 -4
- package/docs/dsh-0.2.3-host-patch-task.md +34 -0
- package/docs/hardcoding-audit.md +28 -8
- package/docs/known-issues.md +26 -0
- package/docs/limitations.md +6 -2
- package/docs/tool-reference.md +1 -1
- package/docs/v1.1.0-bu-data-batching-task.md +66 -0
- package/docs/v1.1.0-compat-hardcoding-task.md +85 -0
- package/dsh-host-patch/README.md +4 -0
- package/dsh-host-patch/apply.mjs +61 -13
- package/dsh-host-patch/rc3-revision9.json.gz +0 -0
- package/dsh-host-patch/rc5-revision9.json.gz +0 -0
- package/dsh-host-patch/tauri/desktop-main.cjs +62 -0
- package/dsh-host-patch/tauri/sidebar-session.cjs +104 -0
- package/dsh-host-patch/tauri-revision1.json +39 -0
- package/dsh-host-patch/tauri.json +43 -0
- package/dsh-host-patch/v023-alpha2.json +153 -0
- package/lib/browser/anti-bot.js +215 -0
- package/lib/browser/deep-dom.js +39 -0
- package/lib/browser/runtime.js +15 -0
- package/lib/browser/takeover-target.js +13 -6
- package/lib/browser/types.js +30 -1
- package/lib/browser-electron/authenticated-route.js +16 -2
- package/lib/browser-electron/automatic-maintenance.js +16 -10
- package/lib/browser-electron/bridge-connection.js +3 -8
- package/lib/browser-electron/bridge-install.js +2 -1
- package/lib/browser-electron/bridge-status.js +55 -26
- package/lib/browser-electron/desktop-bridge-host.js +7 -6
- package/lib/browser-electron/desktop-identity.js +28 -5
- package/lib/browser-electron/desktop-shell.js +64 -0
- package/lib/browser-electron/electron-provision.js +105 -18
- package/lib/browser-electron/entry.js +129 -44
- package/lib/browser-electron/extension-browser.js +4 -4
- package/lib/browser-electron/foreground-watch.js +134 -0
- package/lib/browser-electron/guest-cookie-jar.js +13 -13
- package/lib/browser-electron/guest-route.js +181 -32
- package/lib/browser-electron/guest-runtime.js +61 -10
- package/lib/browser-electron/guest-storage.js +2 -2
- package/lib/browser-electron/history-store.js +1 -5
- package/lib/browser-electron/host-main.js +8 -4
- package/lib/browser-electron/host-patch-maintenance.js +14 -8
- package/lib/browser-electron/maintenance-route.js +2 -1
- package/lib/browser-electron/missing-system-browser.js +5 -9
- package/lib/browser-electron/preferred-browser.js +7 -3
- package/lib/browser-electron/preview-route.js +9 -13
- package/lib/browser-electron/process-ownership.js +1 -1
- package/lib/browser-electron/profile-command.js +2 -1
- package/lib/browser-electron/profile-extension.js +5 -0
- package/lib/browser-electron/profile-lease.js +152 -47
- package/lib/browser-electron/provider-core.js +527 -0
- package/lib/browser-electron/provider-interaction.js +963 -0
- package/lib/browser-electron/provider-media.js +518 -0
- package/lib/browser-electron/provider-navigation.js +301 -0
- package/lib/browser-electron/provider-observation.js +623 -0
- package/lib/browser-electron/provider-tabs.js +372 -0
- package/lib/browser-electron/provider.js +150 -3301
- package/lib/browser-electron/reference-route.js +9 -18
- package/lib/browser-electron/remote-host.js +79 -34
- package/lib/browser-electron/runtime-status.js +56 -6
- package/lib/browser-electron/settings-store.js +3 -6
- package/lib/browser-electron/sidebar-only-host.js +1 -1
- package/lib/browser-electron/system-browser.js +539 -172
- package/lib/browser-electron/tauri-host.js +208 -0
- package/lib/browser-electron/virtual-cursor.js +23 -13
- package/lib/browser-reference/service.js +22 -4
- package/lib/browser-reference/web-sources.js +1 -1
- package/lib/client.js +43409 -0
- package/lib/compat/host-features.js +75 -0
- package/lib/reference-source.js +1 -1
- package/lib/reference-text.js +23 -1
- package/lib/takeover-protocol.js +1 -1
- package/lib/tool-browser/block-recovery.js +69 -0
- package/lib/tool-browser/code-tool.js +170 -19
- package/lib/tool-browser/code-worker.js +115 -20
- package/lib/tool-browser/errors.js +34 -0
- package/lib/tool-browser/index.js +66 -3593
- package/lib/tool-browser/page-probe.js +227 -28
- package/lib/tool-browser/panel-page.js +2 -1
- package/lib/tool-browser/probe-client.js +157 -0
- package/lib/tool-browser/screenshot-annotations.js +108 -0
- package/lib/tool-browser/state.js +337 -0
- package/lib/tool-browser/takeover.js +1 -1
- package/lib/tool-browser/tools-debug.js +862 -0
- package/lib/tool-browser/tools-interaction.js +993 -0
- package/lib/tool-browser/tools-navigation.js +807 -0
- package/lib/tool-browser/tools-observation.js +461 -0
- package/lib/tool-browser/tools-reference.js +293 -0
- package/lib/web-guest.js +1 -0
- package/package.json +16 -36
- package/scripts/build-client.mjs +305 -0
- package/scripts/build.mjs +15 -12
- package/scripts/fix-exports.mjs +6 -16
- package/scripts/install-electron.mjs +55 -5
- package/scripts/pack.mjs +99 -0
- package/scripts/publish-manifest.mjs +56 -0
- package/scripts/verify-exports.mjs +26 -15
- package/skills/dsh-builtin-browser/SKILL.md +27 -2
- package/skills/dsh-builtin-browser/references/batch.md +15 -0
- package/src/browser/anti-bot.ts +251 -0
- package/src/browser/deep-dom.ts +40 -0
- package/src/browser/runtime.ts +18 -0
- package/src/browser/takeover-target.ts +16 -7
- package/src/browser/types.ts +56 -3
- package/src/browser-electron/authenticated-route.ts +29 -4
- package/src/browser-electron/automatic-maintenance.ts +23 -13
- package/src/browser-electron/bridge-connection.ts +11 -10
- package/src/browser-electron/bridge-install.ts +2 -1
- package/src/browser-electron/bridge-status.ts +61 -22
- package/src/browser-electron/desktop-bridge-host.ts +9 -7
- package/src/browser-electron/desktop-identity.ts +38 -5
- package/src/browser-electron/desktop-shell.ts +100 -0
- package/src/browser-electron/electron-provision.ts +104 -18
- package/src/browser-electron/entry.ts +1378 -1299
- package/src/browser-electron/extension-browser.ts +11 -4
- package/src/browser-electron/foreground-watch.ts +142 -0
- package/src/browser-electron/guest-cookie-jar.ts +3 -2
- package/src/browser-electron/guest-route.ts +180 -32
- package/src/browser-electron/guest-runtime.ts +61 -10
- package/src/browser-electron/guest-storage.ts +5 -2
- package/src/browser-electron/history-store.ts +3 -6
- package/src/browser-electron/host-main.ts +8 -4
- package/src/browser-electron/host-patch-maintenance.ts +18 -9
- package/src/browser-electron/maintenance-route.ts +2 -1
- package/src/browser-electron/missing-system-browser.ts +11 -10
- package/src/browser-electron/preferred-browser.ts +13 -3
- package/src/browser-electron/preview-route.ts +9 -12
- package/src/browser-electron/process-ownership.ts +9 -3
- package/src/browser-electron/profile-command.ts +2 -1
- package/src/browser-electron/profile-extension.ts +5 -0
- package/src/browser-electron/profile-lease.ts +131 -35
- package/src/browser-electron/provider-core.ts +1107 -0
- package/src/browser-electron/provider-interaction.ts +1034 -0
- package/src/browser-electron/provider-media.ts +589 -0
- package/src/browser-electron/provider-navigation.ts +323 -0
- package/src/browser-electron/provider-observation.ts +664 -0
- package/src/browser-electron/provider-tabs.ts +372 -0
- package/src/browser-electron/provider.ts +158 -4063
- package/src/browser-electron/reference-route.ts +598 -608
- package/src/browser-electron/remote-host.ts +118 -42
- package/src/browser-electron/runtime-status.ts +80 -13
- package/src/browser-electron/settings-store.ts +10 -6
- package/src/browser-electron/sidebar-only-host.ts +4 -2
- package/src/browser-electron/system-browser.ts +537 -184
- package/src/browser-electron/tauri-host.ts +194 -0
- package/src/browser-electron/virtual-cursor.ts +24 -14
- package/src/browser-reference/service.ts +38 -7
- package/src/browser-reference/web-sources.ts +4 -1
- package/src/client/apply-guard.ts +22 -0
- package/src/client/browser/BrowserController.ts +3 -3
- package/src/client/browser/IframeImpl.ts +182 -176
- package/src/client/browser/frame-history.ts +125 -0
- package/src/client/browser/frame-state.ts +27 -0
- package/src/client/browser/web-reference-source.ts +5 -1
- package/src/client/definition.tsx +36 -30
- package/src/client/electron/ElectronWebViewImpl.ts +20 -13
- package/src/client/electron/ElectronWebviewPresentation.ts +4 -2
- package/src/client/electron/NativeChildPresentation.ts +11 -3
- package/src/client/electron/NativeViewPage.ts +19 -5
- package/src/client/index.ts +333 -293
- package/src/client/locales.ts +9 -6
- package/src/client/reference/client/plugin.ts +21 -2
- package/src/client/reference/client/production/ReferenceCapsules.tsx +3 -3
- package/src/client/reference/client/production/assembly.ts +4 -28
- package/src/client/reference/client/production/availability.ts +0 -2
- package/src/client/reference/client/production/composer-attachments.ts +44 -0
- package/src/client/reference/client/production/draft-adapter.ts +4 -0
- package/src/client/reference/client/production/http-transport.ts +0 -5
- package/src/client/reference/client/production/production-submission.ts +50 -290
- package/src/client/reference/client/production/protocol.ts +7 -4
- package/src/client/reference/client/production/runtime.ts +41 -86
- package/src/client/reference/client/production/source-marker.ts +49 -13
- package/src/client/reference/client/production/user-text-rule.ts +10 -1
- package/src/client/reference/client/reveal.ts +3 -1
- package/src/client/reference/client/session-schedule.ts +36 -0
- package/src/client/settings/index.ts +8 -0
- package/src/client/settings/mount-guard.ts +31 -0
- package/src/client/settings/panel.ts +163 -52
- package/src/client/startpage/controller.ts +3 -6
- package/src/client/view/BrowserBody.tsx +2 -1
- package/src/client/view/IframePresentation.ts +37 -16
- package/src/client/view/StartPage.tsx +2 -1
- package/src/compat/host-features.ts +92 -0
- package/src/reference-source.ts +1 -1
- package/src/reference-text.ts +23 -1
- package/src/takeover-protocol.ts +11 -2
- package/src/tool-browser/block-recovery.ts +85 -0
- package/src/tool-browser/code-tool.ts +173 -19
- package/src/tool-browser/code-worker.ts +101 -15
- package/src/tool-browser/errors.ts +40 -0
- package/src/tool-browser/index.ts +66 -3534
- package/src/tool-browser/page-probe.ts +229 -28
- package/src/tool-browser/panel-page.ts +3 -1
- package/src/tool-browser/probe-client.ts +183 -0
- package/src/tool-browser/screenshot-annotations.ts +131 -0
- package/src/tool-browser/state.ts +375 -0
- package/src/tool-browser/takeover.ts +3 -2
- package/src/tool-browser/tools-debug.ts +806 -0
- package/src/tool-browser/tools-interaction.ts +956 -0
- package/src/tool-browser/tools-navigation.ts +786 -0
- package/src/tool-browser/tools-observation.ts +474 -0
- package/src/tool-browser/tools-reference.ts +294 -0
- package/src/web-guest.ts +35 -34
- package/dist/client.cjs +0 -43167
- package/dist/client.d.cts +0 -516
- package/dist/client.d.mts +0 -516
- package/dist/index.cjs +0 -92
- package/dist/index.d.mts +0 -2960
- package/dist/index.mjs +0 -24
- package/lib/browser-reference/submission-receipts.js +0 -139
- package/src/browser-reference/submission-receipts.ts +0 -122
|
@@ -0,0 +1,131 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Annotated screenshots: numbered boxes over the interactive elements in the viewport, drawn into
|
|
3
|
+
* the page just for the capture and removed right after it. The same numbers come back as
|
|
4
|
+
* `{ id, x, y, role, label }` rows, with x/y the element's centre in viewport CSS pixels, the
|
|
5
|
+
* coordinates click({x, y}) takes. Elements inside open shadow roots and same-origin iframes are
|
|
6
|
+
* included; cross-origin frames stay opaque.
|
|
7
|
+
* @module dsh-browser/tool-browser/screenshot-annotations
|
|
8
|
+
*/
|
|
9
|
+
import type { Context } from '@deepseek-ai/cordis'
|
|
10
|
+
import type { BrowserSessionId } from '../browser/types.ts'
|
|
11
|
+
import { DEEP_DOM_SOURCE } from '../browser/deep-dom.ts'
|
|
12
|
+
|
|
13
|
+
/** One numbered element on an annotated screenshot. */
|
|
14
|
+
export interface ScreenshotAnnotation {
|
|
15
|
+
readonly id: number
|
|
16
|
+
readonly x: number
|
|
17
|
+
readonly y: number
|
|
18
|
+
readonly role: string
|
|
19
|
+
readonly label: string
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
const OVERLAY_ID = '__dsh_annotations__'
|
|
23
|
+
export const MAX_ANNOTATIONS = 80
|
|
24
|
+
|
|
25
|
+
/** Page script: draw the overlay and return the rows. Resolves after the overlay has painted. */
|
|
26
|
+
export const ANNOTATE_SCRIPT = `(async () => {${DEEP_DOM_SOURCE}
|
|
27
|
+
const OVERLAY_ID = ${JSON.stringify(OVERLAY_ID)}
|
|
28
|
+
const old = document.getElementById(OVERLAY_ID)
|
|
29
|
+
if (old) old.remove()
|
|
30
|
+
const SELECTOR = 'a[href], button, input:not([type=hidden]), textarea, select, summary, [role=button], [role=link], [role=checkbox], [role=radio], [role=tab], [role=menuitem], [role=option], [role=switch], [role=combobox], [role=searchbox], [role=textbox], [contenteditable=""], [contenteditable=true], [tabindex]:not([tabindex="-1"])'
|
|
31
|
+
const implicit = (el) => {
|
|
32
|
+
const tag = el.tagName.toLowerCase()
|
|
33
|
+
if (tag === 'a') return 'link'
|
|
34
|
+
if (tag === 'button' || tag === 'summary') return 'button'
|
|
35
|
+
if (tag === 'select') return el.multiple ? 'listbox' : 'combobox'
|
|
36
|
+
if (tag === 'textarea') return 'textbox'
|
|
37
|
+
if (tag === 'input') {
|
|
38
|
+
const type = (el.getAttribute('type') || 'text').toLowerCase()
|
|
39
|
+
if (type === 'checkbox' || type === 'radio') return type
|
|
40
|
+
if (type === 'submit' || type === 'button' || type === 'reset' || type === 'image') return 'button'
|
|
41
|
+
if (type === 'range') return 'slider'
|
|
42
|
+
if (type === 'search') return 'searchbox'
|
|
43
|
+
return 'textbox'
|
|
44
|
+
}
|
|
45
|
+
if (el.isContentEditable) return 'textbox'
|
|
46
|
+
return 'generic'
|
|
47
|
+
}
|
|
48
|
+
const labelOf = (el) => {
|
|
49
|
+
const root = el.getRootNode()
|
|
50
|
+
const byIds = (el.getAttribute('aria-labelledby') || '').split(/\\s+/).filter(Boolean)
|
|
51
|
+
.map(id => { const n = root.getElementById ? root.getElementById(id) : null; return n ? n.textContent : '' }).join(' ')
|
|
52
|
+
let text = el.getAttribute('aria-label') || byIds
|
|
53
|
+
if (!text && el.labels && el.labels.length) text = el.labels[0].textContent
|
|
54
|
+
// A field's value is what the user typed (possibly a password), never its label; only button inputs name themselves by value.
|
|
55
|
+
const buttonValue = el.tagName === 'INPUT' && /^(submit|button|reset)$/i.test(el.getAttribute('type') || '') ? el.value : ''
|
|
56
|
+
if (!text) text = el.innerText || buttonValue || el.getAttribute('placeholder') || el.getAttribute('title') || el.getAttribute('alt') || el.getAttribute('name') || ''
|
|
57
|
+
return String(text).replace(/\\s+/g, ' ').trim().slice(0, 80)
|
|
58
|
+
}
|
|
59
|
+
const vw = window.innerWidth, vh = window.innerHeight
|
|
60
|
+
// The element's box in top-viewport coordinates, clipped by every enclosing iframe's viewport.
|
|
61
|
+
const visibleBox = (el) => {
|
|
62
|
+
const r = el.getBoundingClientRect()
|
|
63
|
+
let box = { left: r.left, top: r.top, right: r.right, bottom: r.bottom }
|
|
64
|
+
let doc = el.ownerDocument
|
|
65
|
+
while (doc && doc.defaultView && doc.defaultView.frameElement) {
|
|
66
|
+
const view = doc.defaultView
|
|
67
|
+
box = { left: Math.max(box.left, 0), top: Math.max(box.top, 0), right: Math.min(box.right, view.innerWidth), bottom: Math.min(box.bottom, view.innerHeight) }
|
|
68
|
+
const f = view.frameElement.getBoundingClientRect()
|
|
69
|
+
box = { left: box.left + f.left, top: box.top + f.top, right: box.right + f.left, bottom: box.bottom + f.top }
|
|
70
|
+
doc = view.frameElement.ownerDocument
|
|
71
|
+
}
|
|
72
|
+
return { left: Math.max(box.left, 0), top: Math.max(box.top, 0), right: Math.min(box.right, vw), bottom: Math.min(box.bottom, vh) }
|
|
73
|
+
}
|
|
74
|
+
const rows = []
|
|
75
|
+
const boxes = []
|
|
76
|
+
for (const root of __dshRoots()) {
|
|
77
|
+
for (const el of root.querySelectorAll(SELECTOR)) {
|
|
78
|
+
if (rows.length >= ${MAX_ANNOTATIONS}) break
|
|
79
|
+
if (el.disabled) continue
|
|
80
|
+
const r = el.getBoundingClientRect()
|
|
81
|
+
if (r.width < 2 || r.height < 2) continue
|
|
82
|
+
const style = el.ownerDocument.defaultView.getComputedStyle(el)
|
|
83
|
+
if (style.visibility === 'hidden' || style.display === 'none' || Number(style.opacity) === 0) continue
|
|
84
|
+
const v = visibleBox(el)
|
|
85
|
+
if (v.right - v.left < 2 || v.bottom - v.top < 2) continue
|
|
86
|
+
const x = Math.round((v.left + v.right) / 2)
|
|
87
|
+
const y = Math.round((v.top + v.bottom) / 2)
|
|
88
|
+
const id = rows.length + 1
|
|
89
|
+
rows.push({ id, x, y, role: el.getAttribute('role') || implicit(el), label: labelOf(el) })
|
|
90
|
+
boxes.push({ id, left: v.left, top: v.top, width: v.right - v.left, height: v.bottom - v.top })
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
const host = document.createElement('div')
|
|
94
|
+
host.id = OVERLAY_ID
|
|
95
|
+
host.setAttribute('aria-hidden', 'true')
|
|
96
|
+
host.style.cssText = 'position:fixed;inset:0;pointer-events:none;z-index:2147483647;'
|
|
97
|
+
const shadow = host.attachShadow ? host.attachShadow({ mode: 'closed' }) : host
|
|
98
|
+
const colors = ['#e6194b', '#3cb44b', '#4363d8', '#f58231', '#911eb4', '#008080', '#9a6324', '#800000']
|
|
99
|
+
for (const b of boxes) {
|
|
100
|
+
const color = colors[(b.id - 1) % colors.length]
|
|
101
|
+
const box = document.createElement('div')
|
|
102
|
+
box.style.cssText = 'position:fixed;box-sizing:border-box;border:2px solid ' + color + ';left:' + b.left + 'px;top:' + b.top + 'px;width:' + b.width + 'px;height:' + b.height + 'px;'
|
|
103
|
+
const tag = document.createElement('span')
|
|
104
|
+
tag.textContent = String(b.id)
|
|
105
|
+
tag.style.cssText = 'position:absolute;left:-2px;top:' + (b.top >= 14 ? '-14px' : '0') + ';background:' + color + ';color:#fff;font:bold 11px/13px monospace;padding:0 3px;'
|
|
106
|
+
box.appendChild(tag)
|
|
107
|
+
shadow.appendChild(box)
|
|
108
|
+
}
|
|
109
|
+
;(document.body || document.documentElement).appendChild(host)
|
|
110
|
+
await new Promise(done => requestAnimationFrame(() => requestAnimationFrame(done)))
|
|
111
|
+
return rows
|
|
112
|
+
})()`
|
|
113
|
+
|
|
114
|
+
export const CLEAR_ANNOTATIONS_SCRIPT = `(() => { const el = document.getElementById(${JSON.stringify(OVERLAY_ID)}); if (el) el.remove(); return true })()`
|
|
115
|
+
|
|
116
|
+
type Browser = NonNullable<Context['browser']>
|
|
117
|
+
|
|
118
|
+
export async function drawAnnotations(browser: Browser, session: BrowserSessionId, signal?: AbortSignal): Promise<readonly ScreenshotAnnotation[]> {
|
|
119
|
+
const result = await browser.execute(session, { script: ANNOTATE_SCRIPT }, signal)
|
|
120
|
+
if (!result.ok) throw new Error(`browser: could not annotate the page (${result.exception})`)
|
|
121
|
+
return Array.isArray(result.value) ? result.value as ScreenshotAnnotation[] : []
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
export async function clearAnnotations(browser: Browser, session: BrowserSessionId): Promise<void> {
|
|
125
|
+
try { await browser.execute(session, { script: CLEAR_ANNOTATIONS_SCRIPT }) } catch { /* the page navigated away; nothing to clear */ }
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
/** Text lines naming each numbered element. */
|
|
129
|
+
export function annotationLines(rows: readonly ScreenshotAnnotation[]): string[] {
|
|
130
|
+
return rows.map(row => ` [${row.id}] ${row.role}${row.label !== '' ? ` "${row.label}"` : ''} @ ${row.x},${row.y}`)
|
|
131
|
+
}
|
|
@@ -0,0 +1,375 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Per-apply browser tool state: task sessions, the allow-list restriction, and surface rules.
|
|
3
|
+
* @module dsh-browser/tool-browser/state
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
import type { Context } from '@deepseek-ai/cordis'
|
|
7
|
+
import { BrowserTakeovers } from './takeover.ts'
|
|
8
|
+
import { readFileSync } from 'node:fs'
|
|
9
|
+
import type { defineTool } from '@deepseek-ai/dsh-tools'
|
|
10
|
+
import { SettingsStore, settingsPath } from '../browser-electron/settings-store.ts'
|
|
11
|
+
import { assertCapability, CDP_CARRIER_CAPABILITIES, WEB_PANEL_CAPABILITIES, type BrowserSessionId, type CarrierCapabilities } from '../browser/types.ts'
|
|
12
|
+
import { MAX_FILL_FIELDS, TOOL_WAIT_MIN_MS, TOOL_WAIT_RESERVE_MS } from '../../assets/browser-policy.mjs'
|
|
13
|
+
import type { Config } from './index.ts'
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* Register a cleanup that runs once when the process exits.
|
|
17
|
+
*
|
|
18
|
+
* A single hook per process, holding a list of callbacks, rather than one listener per
|
|
19
|
+
* session: sessions come and go, listeners do not, and Node warns when a listener count
|
|
20
|
+
* passes ten.
|
|
21
|
+
*/
|
|
22
|
+
export const exitCleanups = new Set<() => void>()
|
|
23
|
+
let exitHookInstalled = false
|
|
24
|
+
export function registerExitCleanup(cleanup: () => void): void {
|
|
25
|
+
exitCleanups.add(cleanup)
|
|
26
|
+
if (exitHookInstalled) return
|
|
27
|
+
exitHookInstalled = true
|
|
28
|
+
process.on('exit', () => {
|
|
29
|
+
for (const run of exitCleanups) {
|
|
30
|
+
try { run() } catch { /* exiting; nothing useful to do */ }
|
|
31
|
+
}
|
|
32
|
+
})
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
/**
|
|
36
|
+
* Which surface an open should use.
|
|
37
|
+
*
|
|
38
|
+
* "panel" - place the page in the DSH sidebar and open nothing else (the normal Web behaviour).
|
|
39
|
+
* "builtin"- drive the plugin's own Electron browser or the explicitly selected installed Chrome/Edge.
|
|
40
|
+
* @returns the configured surface, defaulting to "panel".
|
|
41
|
+
*/
|
|
42
|
+
export function readSurface(): 'panel' | 'builtin' {
|
|
43
|
+
// A host that already resolved the surface declares it; otherwise the plugin's own settings file under
|
|
44
|
+
// the live DSH_HOME decides. No machine-specific path is consulted.
|
|
45
|
+
const declared = (globalThis as unknown as Record<string, unknown>).__dshBrowserSurface
|
|
46
|
+
if (declared === 'builtin') return 'builtin'
|
|
47
|
+
try {
|
|
48
|
+
const raw = readFileSync(settingsPath(), 'utf8').replace(/^\uFEFF/u, '')
|
|
49
|
+
const parsed = JSON.parse(raw) as { browser?: { surface?: unknown; channel?: unknown } }
|
|
50
|
+
const surface = parsed.browser?.surface
|
|
51
|
+
if (surface === 'builtin' || surface === 'panel') return surface
|
|
52
|
+
// Issue #106 & Scheme C: an explicit installed browser channel (chrome / edge) or standalone
|
|
53
|
+
// Electron channel (electron) must drive that browser carrier rather than falling into the
|
|
54
|
+
// Web iframe / Desktop sidebar panel by default.
|
|
55
|
+
const channel = parsed.browser?.channel
|
|
56
|
+
if (channel === 'chrome' || channel === 'edge' || channel === 'electron') return 'builtin'
|
|
57
|
+
} catch { /* no settings yet */ }
|
|
58
|
+
if (declared === 'panel') return 'panel'
|
|
59
|
+
return 'panel'
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
/**
|
|
63
|
+
* Keep the built-in browser for DSH itself.
|
|
64
|
+
*
|
|
65
|
+
* "builtin" exists to debug DSH: a client bundle, the settings panel, the sidebar UI. Using it for an
|
|
66
|
+
* ordinary site opens a window the reader did not ask for — measured as "why did you open the built-in
|
|
67
|
+
* browser again". A non-loopback target therefore degrades to "panel" silently; the caller's intent does
|
|
68
|
+
* not override the rule.
|
|
69
|
+
* @param surface - the requested surface.
|
|
70
|
+
* @param url - the page being opened.
|
|
71
|
+
* @returns the surface that will actually be used.
|
|
72
|
+
*/
|
|
73
|
+
export function enforceSurface(surface: 'panel' | 'builtin', _url: string): 'panel' | 'builtin' {
|
|
74
|
+
// The caller decides the surface. An earlier version degraded "builtin" to "panel" for anything but a
|
|
75
|
+
// loopback URL, which also blocked the agent from driving the human's OWN browser — the opposite of what
|
|
76
|
+
// the setting is for. Which window appears is decided by the carrier (bundled Electron vs. the human's
|
|
77
|
+
// Edge), not by the URL. Keeping ordinary tests on the sidebar is a working rule, not a code constraint.
|
|
78
|
+
return surface
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
/**
|
|
82
|
+
* Refuse a request that cannot work BEFORE anything is opened.
|
|
83
|
+
*
|
|
84
|
+
* The sidebar renders pages through a same-origin proxy, so asking it to load this machine answers with a
|
|
85
|
+
* network-level failure that reads like a bug in the page. Reporting that afterwards is useless — the call
|
|
86
|
+
* already happened. The rule is therefore enforced up front: a loopback target on the panel surface is
|
|
87
|
+
* refused, and the message names the surface that does work.
|
|
88
|
+
* @param surface - the surface this call would use.
|
|
89
|
+
* @param url - the page being opened.
|
|
90
|
+
*/
|
|
91
|
+
export function assertSurfaceCanHost(surface: 'panel' | 'builtin', url: string): void {
|
|
92
|
+
if (surface !== 'panel') return
|
|
93
|
+
let host: string
|
|
94
|
+
try { host = new URL(url).hostname.toLowerCase() } catch { return }
|
|
95
|
+
const local = host === 'localhost' || host === '127.0.0.1' || host === '::1' || host === '[::1]' || /^127\./u.test(host)
|
|
96
|
+
if (!local) return
|
|
97
|
+
throw new Error('dsh-builtin-browser: the sidebar cannot host this machine (' + host
|
|
98
|
+
+ '). It proxies pages through itself, so loading DSH there is the proxy fetching its own server. '
|
|
99
|
+
+ '调试 DSH 请用 surface: "builtin"(内置浏览器),普通网页才走侧栏。')
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
/** Per-apply (per-context) tool state: sessions, in-flight opens, restriction. */
|
|
103
|
+
export interface ToolBrowserState {
|
|
104
|
+
/** Per-task browser sessions, keyed by the calling DSH session id. */
|
|
105
|
+
readonly sessionsByTask: Map<string, BrowserSessionId>
|
|
106
|
+
/** In-flight first-open per task key, so concurrent first calls share one session. */
|
|
107
|
+
readonly pendingOpens: Map<string, Promise<BrowserSessionId>>
|
|
108
|
+
/**
|
|
109
|
+
* Action restriction per task, plus one from the plugin's own configuration.
|
|
110
|
+
*
|
|
111
|
+
* Two different things share this policy. A restriction from `cordis.patch.yml` is an
|
|
112
|
+
* operator decision about the whole plugin, so it applies to everyone and lives in
|
|
113
|
+
* `configRestrictedTo`. One set by `dsh_browser_restrict` is a decision by one task about
|
|
114
|
+
* its own work, so it is keyed by task — a single shared value let one task lock the
|
|
115
|
+
* browser tools of every other task, which is not what any caller asks for. Sessions
|
|
116
|
+
* beside it were already keyed this way; this was not.
|
|
117
|
+
*/
|
|
118
|
+
configRestrictedTo: readonly string[] | undefined
|
|
119
|
+
restrictedByTask: Map<string, readonly string[]>
|
|
120
|
+
/** Active panel opens, including Web iframes that cannot be driven over CDP. */
|
|
121
|
+
panelUrlByTask: Map<string, string>
|
|
122
|
+
pendingPanelOpens: Map<string, Promise<void>>
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
export function createState(): ToolBrowserState {
|
|
126
|
+
return {
|
|
127
|
+
sessionsByTask: new Map(), pendingOpens: new Map(), configRestrictedTo: undefined,
|
|
128
|
+
restrictedByTask: new Map(), panelUrlByTask: new Map(), pendingPanelOpens: new Map(),
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
/** Every live state, for the test hook (introspection only, never shared). */
|
|
133
|
+
export const liveStates = new Set<ToolBrowserState>()
|
|
134
|
+
|
|
135
|
+
/**
|
|
136
|
+
* Tools that only observe, plus the ones that undo a restriction.
|
|
137
|
+
*
|
|
138
|
+
* Never subject to an allow-list: restricting what the agent may *do* must not also
|
|
139
|
+
* blind it or trap it, and the tool descriptions promise as much. dsh_browser_restrict
|
|
140
|
+
* is in here so a task that restricted everything can still lift it.
|
|
141
|
+
*/
|
|
142
|
+
export const READ_ONLY_TOOLS: ReadonlySet<string> = new Set([
|
|
143
|
+
// Tools that only observe.
|
|
144
|
+
'dsh_browser_snapshot', 'dsh_browser_a11y', 'dsh_browser_content', 'dsh_browser_scrape',
|
|
145
|
+
'dsh_browser_screenshot', 'dsh_browser_get_value', 'dsh_browser_wait', 'dsh_browser_challenge',
|
|
146
|
+
'dsh_browser_list_tabs', 'dsh_browser_session', 'dsh_browser_history', 'dsh_browser_visited',
|
|
147
|
+
// Observation added in 0.5.7: console lines, network responses, an assertion, a self-check and the
|
|
148
|
+
// help index. All five only read (the probe's buffers belong to the page, not to the task), so an
|
|
149
|
+
// allow-list must not blind a task that restricted itself.
|
|
150
|
+
'dsh_browser_console', 'dsh_browser_network', 'dsh_browser_wait_for_response',
|
|
151
|
+
'dsh_browser_assert', 'dsh_browser_doctor', 'dsh_browser_help',
|
|
152
|
+
// Reading the page's own digest and searching its text: observation like the rest.
|
|
153
|
+
'dsh_browser_find', 'dsh_browser_state',
|
|
154
|
+
// Where the page keeps its data: shapes of what the page already holds, never a request.
|
|
155
|
+
'dsh_browser_data_sources',
|
|
156
|
+
// References read the page the human already has open and write only this plugin's own store;
|
|
157
|
+
// restricting an agent's actions must not stop it from recording what it was told to read.
|
|
158
|
+
'dsh_browser_reference_capture', 'dsh_browser_reference_reveal', 'dsh_browser_reference_list',
|
|
159
|
+
// dsh_browser_auth reads cookies out of the browser: an observation, and one the
|
|
160
|
+
// credentials switch gates on its own (see credentials.allowRead in the settings).
|
|
161
|
+
// dsh_browser_auth is deliberately NOT here. It reads cookies on "flush" but WRITES them on
|
|
162
|
+
// "restore", to arbitrary domains, which is an action like any other — exempting the tool
|
|
163
|
+
// would let a task that restricted its own actions rewrite the shared browser's logins.
|
|
164
|
+
//
|
|
165
|
+
// Getting out of a bad state, or lifting the restriction itself. Without these a task
|
|
166
|
+
// that restricted everything could neither recover nor be released.
|
|
167
|
+
'dsh_browser_restrict', 'dsh_browser_reset_session', 'dsh_browser_reset',
|
|
168
|
+
])
|
|
169
|
+
|
|
170
|
+
/**
|
|
171
|
+
* Guard one browser tool call against the active restriction. Refuses calls
|
|
172
|
+
* not on the allow-list when a restriction is in effect.
|
|
173
|
+
* @param state - the calling context's tool state.
|
|
174
|
+
* @param toolName - the browser tool about to run.
|
|
175
|
+
*/
|
|
176
|
+
export function assertAllowed(state: ToolBrowserState, toolName: string, task: string): void {
|
|
177
|
+
// dsh_browser_restrict must stay usable, or a task that restricted everything
|
|
178
|
+
// could never lift it again.
|
|
179
|
+
// An allow-list is a statement about ACTIONS, so it must not take away the ability to
|
|
180
|
+
// look, or to get out of a bad state. The tool description and both READMEs promise
|
|
181
|
+
// that read-only tools are never blocked; before this they were, because only
|
|
182
|
+
// dsh_browser_restrict itself was exempt — a narrow list then locked dsh_browser_history,
|
|
183
|
+
// dsh_browser_reset_session and dsh_browser_auth away with no way back.
|
|
184
|
+
if (READ_ONLY_TOOLS.has(toolName) || toolName === 'dsh_browser_restrict') return
|
|
185
|
+
const config = state.configRestrictedTo
|
|
186
|
+
if (config !== undefined && !config.includes(toolName)) {
|
|
187
|
+
throw new Error(`browser action "${toolName}" is restricted by the plugin configuration (allow-list: ${config.join(', ')})`)
|
|
188
|
+
}
|
|
189
|
+
const allowed = state.restrictedByTask.get(task)
|
|
190
|
+
if (allowed === undefined || allowed.includes(toolName)) return
|
|
191
|
+
throw new Error(`browser action "${toolName}" is restricted (allow-list: ${allowed.join(', ')})`)
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
/** The agent view a tool execution carries (id + agent-scoped context). */
|
|
195
|
+
export interface ExecAgent {
|
|
196
|
+
readonly id?: string
|
|
197
|
+
/** Agent-scoped Cordis context; its effects unwind on agent disposal. */
|
|
198
|
+
readonly ctx?: Context
|
|
199
|
+
}
|
|
200
|
+
|
|
201
|
+
/** Extract the agent from a tool-execution context, when one exists. */
|
|
202
|
+
export function agentOf(exec: unknown): ExecAgent | undefined {
|
|
203
|
+
return (exec as { agent?: ExecAgent } | undefined)?.agent
|
|
204
|
+
}
|
|
205
|
+
|
|
206
|
+
/**
|
|
207
|
+
* The task key for a tool call: the calling DSH session id, or the shared
|
|
208
|
+
* default key when the call carries no agent context (CLI probes, tests).
|
|
209
|
+
* @param exec - the tool-execution context; only its optional agent id is read.
|
|
210
|
+
*/
|
|
211
|
+
export function taskKey(exec: { agent?: { id?: string } } | undefined): string {
|
|
212
|
+
return exec?.agent?.id ?? 'default'
|
|
213
|
+
}
|
|
214
|
+
|
|
215
|
+
/** Whether this task's page was placed in the DSH sidebar panel rather than a plugin-owned window. */
|
|
216
|
+
export function panelBound(state: ToolBrowserState, key: string): boolean {
|
|
217
|
+
return state.panelUrlByTask.has(key)
|
|
218
|
+
}
|
|
219
|
+
|
|
220
|
+
/**
|
|
221
|
+
* What the task's current carrier can do. A panel placement without a live CDP session is the Web
|
|
222
|
+
* iframe panel: it can only be navigated. Everything else is a CDP-backed page.
|
|
223
|
+
*/
|
|
224
|
+
export function carrierCapabilities(browser: NonNullable<Context['browser']>, state: ToolBrowserState, key: string): CarrierCapabilities {
|
|
225
|
+
const session = state.sessionsByTask.get(key)
|
|
226
|
+
return panelBound(state, key) && (session === undefined || !browser.exists(session)) ? WEB_PANEL_CAPABILITIES : CDP_CARRIER_CAPABILITIES
|
|
227
|
+
}
|
|
228
|
+
|
|
229
|
+
export function rememberSession(browser: NonNullable<Context['browser']>, state: ToolBrowserState, key: string, agent: ExecAgent | undefined, session: BrowserSessionId | undefined, panelUrl?: string): void {
|
|
230
|
+
const previous = state.sessionsByTask.get(key)
|
|
231
|
+
const previousPanelUrl = state.panelUrlByTask.get(key)
|
|
232
|
+
if (session === undefined) state.sessionsByTask.delete(key)
|
|
233
|
+
else state.sessionsByTask.set(key, session)
|
|
234
|
+
if (panelUrl === undefined) state.panelUrlByTask.delete(key)
|
|
235
|
+
else state.panelUrlByTask.set(key, panelUrl)
|
|
236
|
+
if (previous === session && (previousPanelUrl !== undefined) === (panelUrl !== undefined)) return
|
|
237
|
+
const cleanup = (): void => {
|
|
238
|
+
if (state.sessionsByTask.get(key) !== session || state.panelUrlByTask.has(key) !== (panelUrl !== undefined)) return
|
|
239
|
+
state.sessionsByTask.delete(key)
|
|
240
|
+
state.panelUrlByTask.delete(key)
|
|
241
|
+
if (session !== undefined) void browser.close(session).catch(() => {})
|
|
242
|
+
}
|
|
243
|
+
try {
|
|
244
|
+
if (agent?.ctx !== undefined) agent.ctx.effect(() => cleanup)
|
|
245
|
+
else if (key === 'default' && session !== undefined) registerExitCleanup(() => browser.close(session).catch(() => {}))
|
|
246
|
+
} catch (error) {
|
|
247
|
+
cleanup()
|
|
248
|
+
if (previous !== undefined) state.sessionsByTask.set(key, previous)
|
|
249
|
+
if (previousPanelUrl !== undefined) state.panelUrlByTask.set(key, previousPanelUrl)
|
|
250
|
+
throw error
|
|
251
|
+
}
|
|
252
|
+
if (previous !== undefined && previous !== session) void browser.close(previous).catch(() => {})
|
|
253
|
+
}
|
|
254
|
+
|
|
255
|
+
/**
|
|
256
|
+
* Resolve the calling task's browser session, opening one on first use.
|
|
257
|
+
* Concurrent first calls for the same key share a single open. When the call
|
|
258
|
+
* carries an agent, the session's lifetime is tied to the agent's scoped
|
|
259
|
+
* context: it closes automatically when the agent (DSH session) is disposed,
|
|
260
|
+
* so sessions and their windows never leak after a task ends.
|
|
261
|
+
* @param browser - the seam service.
|
|
262
|
+
* @param state - the calling context's tool state.
|
|
263
|
+
* @param key - the task key (see {@link taskKey}).
|
|
264
|
+
* @param agent - the calling agent, when any (its ctx owns the session).
|
|
265
|
+
* @returns the task's session id.
|
|
266
|
+
*/
|
|
267
|
+
export async function ensureSession(browser: NonNullable<Context['browser']>, state: ToolBrowserState, key: string, agent?: ExecAgent, create = false): Promise<BrowserSessionId> {
|
|
268
|
+
await state.pendingPanelOpens.get(key)
|
|
269
|
+
const existing = state.sessionsByTask.get(key)
|
|
270
|
+
if (existing !== undefined) {
|
|
271
|
+
// The human closing a browser window ends that session, so a cached id can
|
|
272
|
+
// be stale: never hand a dead session back to a tool call.
|
|
273
|
+
if (browser.exists(existing)) return existing
|
|
274
|
+
state.sessionsByTask.delete(key)
|
|
275
|
+
}
|
|
276
|
+
const pending = state.pendingOpens.get(key)
|
|
277
|
+
if (pending !== undefined) return pending
|
|
278
|
+
assertCapability(carrierCapabilities(browser, state, key), 'cdp',
|
|
279
|
+
'dsh-builtin-browser: the panel surface has no live CDP session for this operation. '
|
|
280
|
+
+ 'Use the CDP-backed DSH desktop sidebar with a connected desktop bridge and call dsh_browser_open again. '
|
|
281
|
+
+ 'The Web iframe panel cannot provide live snapshots, a11y, content, scrape, screenshots, interactions, '
|
|
282
|
+
+ 'uploads, downloads, or reference capture. Reading tools never start a separate browser.')
|
|
283
|
+
// Starting a browser is `dsh_browser_open`'s job and nobody else's. A read tool asking "what is on
|
|
284
|
+
// screen" used to start one — which, with the human's own Edge already running, handed the command over
|
|
285
|
+
// and opened yet another window, reported as "one look, two Edge windows". A reader with nothing open
|
|
286
|
+
// reports that instead of launching anything.
|
|
287
|
+
if (!create) {
|
|
288
|
+
throw new Error('dsh-builtin-browser: nothing is open in this task yet — call dsh_browser_open first. '
|
|
289
|
+
+ 'Reading tools never start a browser.')
|
|
290
|
+
}
|
|
291
|
+
// The task key rides along as the session label so the window title shows
|
|
292
|
+
// which task's page is currently visible to the human.
|
|
293
|
+
const opening = browser.open(key).then(
|
|
294
|
+
session => {
|
|
295
|
+
state.pendingOpens.delete(key)
|
|
296
|
+
rememberSession(browser, state, key, agent, session)
|
|
297
|
+
return session
|
|
298
|
+
},
|
|
299
|
+
error => { state.pendingOpens.delete(key); throw error },
|
|
300
|
+
)
|
|
301
|
+
state.pendingOpens.set(key, opening)
|
|
302
|
+
return opening
|
|
303
|
+
}
|
|
304
|
+
|
|
305
|
+
/** What every tool module closes over: the apply's context, settings and per-apply state. */
|
|
306
|
+
export interface ToolScope {
|
|
307
|
+
readonly ctx: Context
|
|
308
|
+
readonly config: Config
|
|
309
|
+
readonly state: ToolBrowserState
|
|
310
|
+
readonly takeovers: BrowserTakeovers
|
|
311
|
+
readonly settingsStore: SettingsStore
|
|
312
|
+
readonly timeoutMs: number
|
|
313
|
+
readonly maxWaitMs: number
|
|
314
|
+
readonly maxFillFields: number
|
|
315
|
+
readonly surface: NonNullable<Config['surface']>
|
|
316
|
+
}
|
|
317
|
+
|
|
318
|
+
/** One tool definition, as `defineTool` returns it. */
|
|
319
|
+
export type ToolDefinition = ReturnType<typeof defineTool>
|
|
320
|
+
|
|
321
|
+
/**
|
|
322
|
+
* Longest wait `dsh_browser_wait` may poll for, leaving room for the tool call itself to
|
|
323
|
+
* finish and report.
|
|
324
|
+
*
|
|
325
|
+
* `dsh_browser_wait` promises a VERDICT — `{ready:false, reason}` — and the enclosing tool
|
|
326
|
+
* call aborts at `timeoutMs`. A caller-supplied budget longer than that aborted the call
|
|
327
|
+
* instead, so the documented verdict never arrived. Clamping to just inside the budget is
|
|
328
|
+
* what keeps the promise: the polling stops, the reason is returned.
|
|
329
|
+
*/
|
|
330
|
+
export function maxWaitFor(timeoutMs: number): number {
|
|
331
|
+
return Math.max(TOOL_WAIT_MIN_MS, timeoutMs - TOOL_WAIT_RESERVE_MS)
|
|
332
|
+
}
|
|
333
|
+
|
|
334
|
+
/**
|
|
335
|
+
* Most fields `dsh_browser_fill` accepts in one batch.
|
|
336
|
+
*
|
|
337
|
+
* The batch runs as ONE page evaluation, so hundreds of fields do not produce hundreds of
|
|
338
|
+
* per-field verdicts — they produce a single evaluate that exceeds the tool budget and
|
|
339
|
+
* throws, which is the opposite of the documented "per-field failures are reported instead
|
|
340
|
+
* of throwing". Real forms are far smaller than this; anything larger should be split.
|
|
341
|
+
*/
|
|
342
|
+
export { MAX_FILL_FIELDS }
|
|
343
|
+
|
|
344
|
+
/** Every tool, in the order the entry registers it (and the code tool's catalog lists it). */
|
|
345
|
+
export const REGISTRATION_ORDER: readonly string[] = [
|
|
346
|
+
'dsh_browser_request_takeover', 'dsh_browser_shortcuts', 'dsh_browser_open', 'dsh_browser_snapshot',
|
|
347
|
+
'dsh_browser_a11y', 'dsh_browser_challenge', 'dsh_browser_wait', 'dsh_browser_execute',
|
|
348
|
+
'dsh_browser_content', 'dsh_browser_scrape', 'dsh_browser_click', 'dsh_browser_click_sequence',
|
|
349
|
+
'dsh_browser_type', 'dsh_browser_scroll', 'dsh_browser_back', 'dsh_browser_forward', 'dsh_browser_refresh',
|
|
350
|
+
'dsh_browser_key', 'dsh_browser_fill', 'dsh_browser_set_value', 'dsh_browser_check', 'dsh_browser_select',
|
|
351
|
+
'dsh_browser_clear', 'dsh_browser_get_value', 'dsh_browser_screenshot', 'dsh_browser_list_tabs',
|
|
352
|
+
'dsh_browser_switch_tab', 'dsh_browser_close_tab', 'dsh_browser_reset', 'dsh_browser_history',
|
|
353
|
+
'dsh_browser_visited', 'dsh_browser_replay', 'dsh_browser_download', 'dsh_browser_session',
|
|
354
|
+
'dsh_browser_reset_session', 'dsh_browser_restrict', 'dsh_browser_auth', 'dsh_browser_console',
|
|
355
|
+
'dsh_browser_network', 'dsh_browser_dialog', 'dsh_browser_wait_for_response', 'dsh_browser_assert',
|
|
356
|
+
'dsh_browser_drag', 'dsh_browser_doctor', 'dsh_browser_help', 'dsh_browser_do', 'dsh_browser_upload',
|
|
357
|
+
'dsh_browser_hover', 'dsh_browser_find', 'dsh_browser_state', 'dsh_browser_reference_capture',
|
|
358
|
+
'dsh_browser_reference_reveal', 'dsh_browser_reference_list', 'dsh_browser_data_sources', 'dsh_browser_fetch_json',
|
|
359
|
+
]
|
|
360
|
+
|
|
361
|
+
/** Test hook: inspect and reset session mappings across every live plugin apply. */
|
|
362
|
+
export const internals = {
|
|
363
|
+
/** A copy of every live apply's per-task session map (task key -> provider session id). */
|
|
364
|
+
get sessions(): ReadonlyMap<string, BrowserSessionId> {
|
|
365
|
+
const merged = new Map<string, BrowserSessionId>()
|
|
366
|
+
for (const state of liveStates) {
|
|
367
|
+
for (const [key, session] of state.sessionsByTask) merged.set(key, session)
|
|
368
|
+
}
|
|
369
|
+
return merged
|
|
370
|
+
},
|
|
371
|
+
/** Drop one task's mapping (across live applies) without closing the provider session. */
|
|
372
|
+
clearSession(key = 'default'): void {
|
|
373
|
+
for (const state of liveStates) state.sessionsByTask.delete(key)
|
|
374
|
+
},
|
|
375
|
+
}
|
|
@@ -11,6 +11,7 @@ import { TAKEOVER_ROUTE, TAKEOVER_TOOL, type TakeoverDecision, type TakeoverNoti
|
|
|
11
11
|
|
|
12
12
|
interface Page {
|
|
13
13
|
readonly connected?: () => boolean
|
|
14
|
+
readonly reveal?: (until?: AbortSignal) => Promise<boolean>
|
|
14
15
|
readonly owner: string
|
|
15
16
|
readonly tabId: string
|
|
16
17
|
readonly pageId: string
|
|
@@ -191,8 +192,8 @@ export function installTakeovers(ctx: Context, takeovers: BrowserTakeovers): voi
|
|
|
191
192
|
ctx.on?.('approval/request' as never, ((request: { toolName: string; signal?: AbortSignal }, next: () => Promise<TakeoverDecision>) => takeovers.listen(request, next)) as never, { prepend: true })
|
|
192
193
|
ctx.effect(() => () => { takeovers.dispose() })
|
|
193
194
|
ctx.inject?.(['webServer'] as never, (host: Context) => {
|
|
194
|
-
const server = host.get('webServer' as never) as unknown as { register(spec: { kind: 'exact'; path: string; handler: BrowserHttpHandler }): () => void }
|
|
195
|
-
host.effect(() => server.register({ kind: 'exact', path: TAKEOVER_ROUTE, handler: pairedRoute(
|
|
195
|
+
const server = host.get('webServer' as never) as unknown as { register(spec: { kind: 'exact'; path: string; auth?: 'anonymous' | 'required' | 'deny'; handler: BrowserHttpHandler }): () => void }
|
|
196
|
+
host.effect(() => server.register({ kind: 'exact', path: TAKEOVER_ROUTE, auth: 'required', handler: pairedRoute(
|
|
196
197
|
() => ctx.get('connection' as never) as unknown as BrowserPairingConnection | undefined, takeovers.handler) }))
|
|
197
198
|
})
|
|
198
199
|
}
|