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
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
/// <reference path="../css-modules.d.ts" />
|
|
2
|
-
import { GUEST_ROUTE } from '../../../assets/browser-policy.mjs'
|
|
2
|
+
import { GUEST_ROUTE, RELAXED_BROWSER_SANDBOX, WEB_BROWSER_SANDBOX } from '../../../assets/browser-policy.mjs'
|
|
3
3
|
/** Iframe DOM and revision-tagged load observations. */
|
|
4
4
|
import type { BrowserTarget } from '../browser/url.ts'
|
|
5
5
|
import type { BrowserPresentation } from './BrowserPresentation.ts'
|
|
6
6
|
import css from './Browser.module.css'
|
|
7
|
+
import { GuestFrameHistory } from '../browser/frame-history.ts'
|
|
7
8
|
import { registerIframePage, registerIframeReference, type GuestReferenceCommand } from '../browser/iframe-reference.ts'
|
|
8
9
|
import { connectWebReferenceSource } from '../browser/web-reference-source.ts'
|
|
9
10
|
import { registerTakeoverSummary } from '../browser/takeover-channel.ts'
|
|
@@ -32,10 +33,6 @@ function capturedSourceUrl(value: unknown): unknown {
|
|
|
32
33
|
return value
|
|
33
34
|
}
|
|
34
35
|
|
|
35
|
-
/** Opaque guest documents cannot access the application's origin or open native windows. */
|
|
36
|
-
export const WEB_BROWSER_SANDBOX = 'allow-scripts allow-forms'
|
|
37
|
-
const RELAXED_BROWSER_SANDBOX = `${WEB_BROWSER_SANDBOX} allow-downloads allow-modals allow-pointer-lock allow-orientation-lock allow-presentation allow-storage-access-by-user-activation`
|
|
38
|
-
|
|
39
36
|
interface IframeDocument {
|
|
40
37
|
readonly target: BrowserTarget
|
|
41
38
|
readonly revision: number
|
|
@@ -72,7 +69,7 @@ export class IframePresentation implements BrowserPresentation {
|
|
|
72
69
|
private element: HTMLIFrameElement | undefined
|
|
73
70
|
private document: IframeDocument | undefined
|
|
74
71
|
private rendered = false
|
|
75
|
-
private
|
|
72
|
+
private readonly frameHistory = new GuestFrameHistory()
|
|
76
73
|
private loadId: number | undefined
|
|
77
74
|
private documentId: string | undefined
|
|
78
75
|
private loadedId: number | undefined
|
|
@@ -82,7 +79,12 @@ export class IframePresentation implements BrowserPresentation {
|
|
|
82
79
|
private identityTimer: ReturnType<typeof setTimeout> | undefined
|
|
83
80
|
private identityRetried = false
|
|
84
81
|
private readonly receive = (event: MessageEvent): void => {
|
|
85
|
-
|
|
82
|
+
// A sandboxed guest posts from the opaque origin `null`. A carrier that granted the guest its
|
|
83
|
+
// own origin (storage-compatible mode) posts from this application's origin instead. Both can
|
|
84
|
+
// only be this frame's own document; the source check is what proves it, and any other origin
|
|
85
|
+
// is a different frame and is dropped.
|
|
86
|
+
const ownOrigin = event.origin === 'null' || event.origin === location.origin
|
|
87
|
+
if (!ownOrigin || event.source !== this.element?.contentWindow) return
|
|
86
88
|
const data = event.data
|
|
87
89
|
if (data?.type === 'dsh.browser.guest.child.request') {
|
|
88
90
|
if (this.loadId === undefined || data.loadId !== this.loadId || !Number.isSafeInteger(data.requestId)
|
|
@@ -128,6 +130,7 @@ export class IframePresentation implements BrowserPresentation {
|
|
|
128
130
|
if (data.documentId !== this.documentId) {
|
|
129
131
|
const nativeLoaded = this.documentId === undefined && this.nativeLoadId === this.loadId
|
|
130
132
|
this.invalidateGuest()
|
|
133
|
+
this.frameHistory.noteDocumentChange()
|
|
131
134
|
this.loadId = ++this.nextLoadId
|
|
132
135
|
this.documentId = data.documentId
|
|
133
136
|
if (nativeLoaded) this.nativeLoadId = this.loadId
|
|
@@ -143,7 +146,11 @@ export class IframePresentation implements BrowserPresentation {
|
|
|
143
146
|
clearTimeout(this.identityTimer)
|
|
144
147
|
this.identityTimer = undefined
|
|
145
148
|
this.identityRetried = false
|
|
146
|
-
this.
|
|
149
|
+
this.frameHistory.record({
|
|
150
|
+
depth: Number.isSafeInteger(data.depth) && data.depth > 0 ? data.depth : 1,
|
|
151
|
+
reason: typeof data.reason === 'string' ? data.reason : undefined,
|
|
152
|
+
navigationType: typeof data.navigationType === 'string' ? data.navigationType : undefined,
|
|
153
|
+
})
|
|
147
154
|
if (data.ready === true) this.markLoaded()
|
|
148
155
|
this.observedUrl = data.url
|
|
149
156
|
this.events.observed(this.document.revision, data.url)
|
|
@@ -153,9 +160,11 @@ export class IframePresentation implements BrowserPresentation {
|
|
|
153
160
|
}
|
|
154
161
|
if (data.ready === true) this.events.guestReady?.(this.document.revision, this.pageId)
|
|
155
162
|
}
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
constructor(
|
|
163
|
+
private readonly events: IframePresentationEvents
|
|
164
|
+
private readonly owner?: string
|
|
165
|
+
constructor(events: IframePresentationEvents, owner?: string) {
|
|
166
|
+
this.events = events
|
|
167
|
+
this.owner = owner
|
|
159
168
|
if (owner !== undefined) this.sourceLifetime.signal.addEventListener('abort', registerTakeoverSummary(this.pageId, owner, async signal => {
|
|
160
169
|
const result = await this.command('summary', { maxChars: 1500, legacy: false }, signal, this.observedUrl ?? '', this.loadId)
|
|
161
170
|
return result as unknown as TakeoverSummary
|
|
@@ -225,19 +234,25 @@ export class IframePresentation implements BrowserPresentation {
|
|
|
225
234
|
|
|
226
235
|
/** Request history movement in the guest without reading its cross-origin window. */
|
|
227
236
|
historyStep(delta: number): boolean {
|
|
237
|
+
if (!this.frameHistory.canStep(delta)) return false
|
|
228
238
|
const win = this.element?.contentWindow
|
|
229
239
|
if (win === undefined || win === null) return false
|
|
230
240
|
try {
|
|
231
241
|
win.postMessage({ type: 'dsh.browser.guest.history', delta: delta < 0 ? -1 : 1 }, '*')
|
|
232
|
-
return true
|
|
233
242
|
} catch {
|
|
234
243
|
return false
|
|
235
244
|
}
|
|
245
|
+
return this.frameHistory.step(delta)
|
|
236
246
|
}
|
|
237
247
|
|
|
238
|
-
/**
|
|
248
|
+
/** Entries this guest iframe itself added, counting the current one; the joint session history is excluded. */
|
|
239
249
|
historyDepth(): number {
|
|
240
|
-
return this.depth
|
|
250
|
+
return this.frameHistory.depth()
|
|
251
|
+
}
|
|
252
|
+
|
|
253
|
+
/** Whether the guest iframe has a forward entry of its own. */
|
|
254
|
+
canGoForward(): boolean {
|
|
255
|
+
return this.frameHistory.canGoForward()
|
|
241
256
|
}
|
|
242
257
|
|
|
243
258
|
/** @param viewportId - mounted placeholder. @returns removes only the iframe presentation. */
|
|
@@ -296,7 +311,13 @@ export class IframePresentation implements BrowserPresentation {
|
|
|
296
311
|
this.identityTimer = setTimeout(() => {
|
|
297
312
|
this.identityTimer = undefined
|
|
298
313
|
if (revision === undefined || this.document?.revision !== revision) return
|
|
299
|
-
|
|
314
|
+
// Nothing answers this handshake today: the guest overlay listens for `dsh-browser-ref:intent`
|
|
315
|
+
// and never posts a `dsh.browser.guest.navigation` identity, and a directly loaded document
|
|
316
|
+
// carries no overlay at all. Failing the document here painted a five-second "load failed"
|
|
317
|
+
// banner over a page that had already loaded, and `guestFailed` also marked the whole carrier
|
|
318
|
+
// unusable. Report the document as loaded instead; the reference channel stays unavailable,
|
|
319
|
+
// which is what the states actually are.
|
|
320
|
+
this.markLoaded()
|
|
300
321
|
}, 5000)
|
|
301
322
|
}
|
|
302
323
|
|
|
@@ -335,7 +356,7 @@ export class IframePresentation implements BrowserPresentation {
|
|
|
335
356
|
element.addEventListener('error', () => {
|
|
336
357
|
if (this.element === element) { this.invalidateGuest(); this.events.failed(current.revision) }
|
|
337
358
|
})
|
|
338
|
-
this.
|
|
359
|
+
this.frameHistory.reset(history.length)
|
|
339
360
|
this.loadId = ++this.nextLoadId
|
|
340
361
|
this.element = element
|
|
341
362
|
this.rendered = true
|
|
@@ -10,6 +10,7 @@ import type { TranslateNS } from '@deepseek-ai/dsh-client-ui-slots'
|
|
|
10
10
|
import type { ContextMenuBindings } from '@deepseek-ai/dsh-client-ui-context-menu/client'
|
|
11
11
|
import type { SessionId } from '@deepseek-ai/dsh-session/types'
|
|
12
12
|
import type { TabId } from '@deepseek-ai/dsh-client-ui-dockkit'
|
|
13
|
+
import type { SIDEBAR_BROWSER_LOCALE_NS } from '../locales.ts'
|
|
13
14
|
import type { BrowserStartPageInjected } from '../startpage/binding.ts'
|
|
14
15
|
import type { StartPageSnapshot, StartPageWriteResult } from '../startpage/controller.ts'
|
|
15
16
|
import type { SearchEngineDraft, ShortcutDraft, StartPageEngineView, StartPageFailure, StartPageShortcutView } from '../startpage/model.ts'
|
|
@@ -17,7 +18,7 @@ import { MAX_ENGINE_EXTRA_PARAMETERS } from '../startpage/model.ts'
|
|
|
17
18
|
import type { BrowserShortcut } from '../../startpage-settings.ts'
|
|
18
19
|
import css from './Browser.module.css'
|
|
19
20
|
|
|
20
|
-
type Translate = TranslateNS<
|
|
21
|
+
type Translate = TranslateNS<typeof SIDEBAR_BROWSER_LOCALE_NS>
|
|
21
22
|
|
|
22
23
|
const UNDO_MS = 8000
|
|
23
24
|
|
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Runtime feature probes for the DSH host, in one place.
|
|
3
|
+
*
|
|
4
|
+
* Host lines are not comparable by version string (the official 0.2.3-alpha.2 and a community
|
|
5
|
+
* shell's 0.14.0 share nothing), so every check here asks the running host what it offers instead.
|
|
6
|
+
* Dependency-free on purpose: both the Node host half and the browser client half import it.
|
|
7
|
+
* @module dsh-browser/compat/host-features
|
|
8
|
+
*/
|
|
9
|
+
import type { DesktopBrowserBridge, DesktopBrowserChildTabs, DesktopNativeChildTabs, DesktopNativeViews } from '../types.ts'
|
|
10
|
+
|
|
11
|
+
interface ServiceLookup { readonly get?: (name: string) => unknown }
|
|
12
|
+
interface ToolRegistry { readonly register: (tool: never, options?: never) => unknown }
|
|
13
|
+
|
|
14
|
+
interface ScopedExecutors { readonly selectExecutor?: (scope?: unknown) => { readonly describe?: (tools: readonly never[]) => { readonly knownNames?: readonly string[] } } }
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* Whether DSH's PTC executor is active, so `run_code` already batches every tool.
|
|
18
|
+
*
|
|
19
|
+
* Since 0.2.2-rc.5 dsh-base mounts the `ptcRuntime` provider in every mode and only the PTC
|
|
20
|
+
* overlay selects its executor, so a registry that selects executors per scope is asked which
|
|
21
|
+
* one the calling agent gets; an older registry has no selector and the service alone decides.
|
|
22
|
+
* @param ctx - the plugin context.
|
|
23
|
+
* @param scope - the tool-activation context (`{ agent }`) a conditional registration receives.
|
|
24
|
+
* @returns true when the agent's executor exposes `run_code`, or, without a selector, when `ptcRuntime` is present.
|
|
25
|
+
*/
|
|
26
|
+
export function ptcRuntimeActive(ctx: unknown, scope?: { readonly agent?: unknown }): boolean {
|
|
27
|
+
try {
|
|
28
|
+
if ((ctx as ServiceLookup).get?.('ptcRuntime') === undefined) return false
|
|
29
|
+
const tools = (ctx as { readonly tools?: ScopedExecutors }).tools
|
|
30
|
+
if (typeof tools?.selectExecutor !== 'function') return true
|
|
31
|
+
return tools.selectExecutor(scope?.agent)?.describe?.([])?.knownNames?.includes('run_code') === true
|
|
32
|
+
} catch { return false }
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
/**
|
|
36
|
+
* Register a tool, visible only while `when` holds.
|
|
37
|
+
*
|
|
38
|
+
* Registration options arrived with DSH 0.2.2; an older registry ignores the second argument and
|
|
39
|
+
* keeps the tool always visible, which is the safe fallback for every caller here.
|
|
40
|
+
* @param registry - `ctx.tools`.
|
|
41
|
+
* @param tool - the tool definition.
|
|
42
|
+
* @param when - visibility predicate; omitted registers unconditionally.
|
|
43
|
+
* @returns whatever the registry returns.
|
|
44
|
+
*/
|
|
45
|
+
export function registerTool<C>(registry: ToolRegistry, tool: unknown, when?: (context?: C) => boolean): unknown {
|
|
46
|
+
const register = registry.register as (tool: unknown, options?: { when: (context?: C) => boolean }) => unknown
|
|
47
|
+
return when === undefined ? register.call(registry, tool) : register.call(registry, tool, { when })
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
interface DesktopCarrier { readonly protocolVersion?: unknown; readonly browser?: DesktopBrowserBridge }
|
|
51
|
+
|
|
52
|
+
/**
|
|
53
|
+
* The renderer's narrow desktop browser bridge (`window.dshDesktop`, protocol 1).
|
|
54
|
+
* @param scope - the global object; injectable for tests.
|
|
55
|
+
* @returns the bridge, or undefined outside a desktop shell that speaks protocol 1.
|
|
56
|
+
*/
|
|
57
|
+
export function desktopBrowserBridge(scope: object = globalThis): DesktopBrowserBridge | undefined {
|
|
58
|
+
const carrier = (scope as { dshDesktop?: DesktopCarrier | null }).dshDesktop
|
|
59
|
+
return carrier !== null && typeof carrier === 'object' && carrier.protocolVersion === 1 ? carrier.browser : undefined
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
/**
|
|
63
|
+
* Native views (protocol 1) of the desktop bridge.
|
|
64
|
+
* @param scope - the global object, or the bridge itself.
|
|
65
|
+
* @returns the native views API, or undefined when the shell does not offer protocol 1.
|
|
66
|
+
*/
|
|
67
|
+
export function nativeViews(scope: object = globalThis): DesktopNativeViews | undefined {
|
|
68
|
+
const views = (scope as { browser?: { nativeViews?: DesktopNativeViews } }).browser?.nativeViews
|
|
69
|
+
?? (scope as { dshDesktop?: { browser?: { nativeViews?: DesktopNativeViews } } | null }).dshDesktop?.browser?.nativeViews
|
|
70
|
+
?? (scope as { nativeViews?: DesktopNativeViews }).nativeViews
|
|
71
|
+
return views?.protocolVersion === 1 ? views : undefined
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
/**
|
|
75
|
+
* URL-only child tab requests (protocol 1).
|
|
76
|
+
* @param bridge - the desktop browser bridge.
|
|
77
|
+
* @returns the API, or undefined when the shell offers another protocol or none.
|
|
78
|
+
*/
|
|
79
|
+
export function urlChildTabs(bridge: Pick<DesktopBrowserBridge, 'childTabs'> | undefined): DesktopBrowserChildTabs | undefined {
|
|
80
|
+
const tabs = bridge?.childTabs
|
|
81
|
+
return tabs?.protocolVersion === 1 ? tabs : undefined
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
/**
|
|
85
|
+
* Native opener child tabs (protocol 2).
|
|
86
|
+
* @param bridge - the desktop browser bridge.
|
|
87
|
+
* @returns the API, or undefined when the shell offers another protocol or none.
|
|
88
|
+
*/
|
|
89
|
+
export function nativeChildTabs(bridge: Pick<DesktopBrowserBridge, 'childTabs'> | undefined): DesktopNativeChildTabs | undefined {
|
|
90
|
+
const tabs = bridge?.childTabs
|
|
91
|
+
return tabs?.protocolVersion === 2 ? tabs : undefined
|
|
92
|
+
}
|
package/src/reference-source.ts
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
export
|
|
1
|
+
export { WEB_SOURCE_ROUTE } from '../assets/browser-policy.mjs'
|
|
2
2
|
export const WEB_REVEAL_STATUSES = ['revealed', 'partial', 'ambiguous', 'missing', 'not-found', 'page-mismatch', 'unavailable'] as const
|
|
3
3
|
export type WebRevealStatus = typeof WEB_REVEAL_STATUSES[number]
|
package/src/reference-text.ts
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import { GUEST_ROUTE } from '../assets/browser-policy.mjs'
|
|
2
|
+
|
|
1
3
|
export const MAX_REFERENCE_TEXT = 20_000
|
|
2
4
|
|
|
3
5
|
export type ReferenceTextNode =
|
|
@@ -65,6 +67,26 @@ function escapeMarkdown(text: string): string {
|
|
|
65
67
|
return text.replace(/[\\`*_{}[\]<>!|#]/gu, '\\$&')
|
|
66
68
|
}
|
|
67
69
|
|
|
70
|
+
/**
|
|
71
|
+
* A captured href comes from the guest document, where the proxy rewrote every link to its own
|
|
72
|
+
* route (`<GUEST_ROUTE>?u=<real>`). The projection must show the site's URL, never this machine's.
|
|
73
|
+
*
|
|
74
|
+
* The captured text is what the model reads and what the composer renders, so a proxy URL here
|
|
75
|
+
* showed up as a blue `http://127.0.0.1:<port>/…` link inside the user's own message.
|
|
76
|
+
* @param href - the href recorded in the snapshot.
|
|
77
|
+
* @returns the site's URL, or the input when it is not a guest-proxy link.
|
|
78
|
+
*/
|
|
79
|
+
function realHref(href: string): string {
|
|
80
|
+
const marker = `${GUEST_ROUTE}?`
|
|
81
|
+
if (!href.includes(marker)) return href
|
|
82
|
+
try {
|
|
83
|
+
const raw = new URL(href).searchParams.get('u')
|
|
84
|
+
return raw === null || raw === '' ? href : raw
|
|
85
|
+
} catch {
|
|
86
|
+
return href
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
|
|
68
90
|
export function referenceTextContent(nodes: readonly ReferenceTextNode[]): string {
|
|
69
91
|
return nodes.map(node => node.type === 'text' ? node.text : node.type === 'math' ? node.latex : node.type === 'rule' ? '\n---\n' : node.type === 'break' ? '\n' : referenceTextContent(node.children)).join('')
|
|
70
92
|
}
|
|
@@ -107,7 +129,7 @@ export function renderReferenceText(nodes: readonly ReferenceTextNode[]): string
|
|
|
107
129
|
case 'ruby-text': return `<rt>${text}</rt>`
|
|
108
130
|
case 'strong': return `**${text}**`
|
|
109
131
|
case 'emphasis': return `*${text}*`
|
|
110
|
-
case 'link': return `[${text}](${node.href.replace(/[\s()<>\\]/gu, char => encodeURIComponent(char).replace(/[()]/gu, token => `%${token.charCodeAt(0).toString(16).toUpperCase()}`))})`
|
|
132
|
+
case 'link': return `[${text}](${realHref(node.href).replace(/[\s()<>\\]/gu, char => encodeURIComponent(char).replace(/[()]/gu, token => `%${token.charCodeAt(0).toString(16).toUpperCase()}`))})`
|
|
111
133
|
case 'blockquote': return text.trim().split('\n').map(line => `> ${line}`).join('\n')
|
|
112
134
|
case 'list-item': return text
|
|
113
135
|
case 'list': {
|
package/src/takeover-protocol.ts
CHANGED
|
@@ -1,7 +1,16 @@
|
|
|
1
|
-
export
|
|
1
|
+
export { TAKEOVER_ROUTE } from '../assets/browser-policy.mjs'
|
|
2
2
|
export const TAKEOVER_TOOL = 'dsh_browser_request_takeover'
|
|
3
3
|
|
|
4
|
-
|
|
4
|
+
/**
|
|
5
|
+
* What the tool reports back to the model.
|
|
6
|
+
*
|
|
7
|
+
* `unavailable` is its own outcome on purpose: it means this host has no way to reach a person
|
|
8
|
+
* (no approval channel and no sidebar card), which is a property of the host, not something the
|
|
9
|
+
* person decided. Folding it into `cancelled` told the model that a human had declined, and since
|
|
10
|
+
* the takeover guidance forbids solving a challenge alone, the only reachable answer became "not
|
|
11
|
+
* success" — a dead end rather than a decision.
|
|
12
|
+
*/
|
|
13
|
+
export type TakeoverOutcome = 'done' | 'skipped' | 'cancelled' | 'unavailable'
|
|
5
14
|
export type TakeoverDecision = 'allowed-once' | 'rejected' | 'cancelled' | 'unavailable'
|
|
6
15
|
|
|
7
16
|
export interface TakeoverSummary {
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The tool-facing half of anti-bot handling: one output schema and one projection for a blocked
|
|
3
|
+
* page's verdict, so every tool that reports a challenge reports the same fields — what blocked
|
|
4
|
+
* it, what to do, and the public routes to the same information.
|
|
5
|
+
* @module dsh-browser/tool-browser/block-recovery
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
import { fallbackRoutes, recoveryAdvice, type FallbackRoute } from '../browser/anti-bot.ts'
|
|
9
|
+
import type { BrowserChallenge } from '../browser/types.ts'
|
|
10
|
+
|
|
11
|
+
/** A verdict as tools return it. */
|
|
12
|
+
export interface ChallengeReport {
|
|
13
|
+
blocked: boolean
|
|
14
|
+
kind?: string
|
|
15
|
+
reason?: string
|
|
16
|
+
recovery?: NonNullable<BrowserChallenge['recovery']>
|
|
17
|
+
status?: number
|
|
18
|
+
/** Set when the open already made its one paced retry in a fresh session. */
|
|
19
|
+
retried?: boolean
|
|
20
|
+
advice?: string
|
|
21
|
+
fallbacks?: FallbackRoute[]
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
/** Output schema shared by dsh_browser_open, dsh_browser_snapshot and dsh_browser_challenge. */
|
|
25
|
+
export const CHALLENGE_SCHEMA = {
|
|
26
|
+
type: 'object',
|
|
27
|
+
additionalProperties: false,
|
|
28
|
+
properties: {
|
|
29
|
+
blocked: { type: 'boolean', required: true },
|
|
30
|
+
kind: { type: 'string' },
|
|
31
|
+
reason: { type: 'string' },
|
|
32
|
+
recovery: { type: 'string', enum: ['takeover', 'wait', 'retry', 'environment'] },
|
|
33
|
+
status: { type: 'number' },
|
|
34
|
+
retried: { type: 'boolean' },
|
|
35
|
+
advice: { type: 'string' },
|
|
36
|
+
fallbacks: {
|
|
37
|
+
type: 'array',
|
|
38
|
+
items: {
|
|
39
|
+
type: 'object',
|
|
40
|
+
additionalProperties: false,
|
|
41
|
+
properties: {
|
|
42
|
+
kind: { type: 'string', required: true, enum: ['api', 'search', 'archive'] },
|
|
43
|
+
url: { type: 'string', required: true },
|
|
44
|
+
note: { type: 'string', required: true },
|
|
45
|
+
},
|
|
46
|
+
},
|
|
47
|
+
},
|
|
48
|
+
},
|
|
49
|
+
} as const
|
|
50
|
+
|
|
51
|
+
/**
|
|
52
|
+
* Project a verdict for a tool result: a clean page stays `{ blocked: false }`; a blocked one gains
|
|
53
|
+
* the advice for its kind and the fallback routes for its URL.
|
|
54
|
+
* @param challenge - the provider's verdict.
|
|
55
|
+
* @param url - the page it is about.
|
|
56
|
+
* @param retried - whether the open already retried once.
|
|
57
|
+
* @returns the report.
|
|
58
|
+
*/
|
|
59
|
+
export function reportChallenge(challenge: BrowserChallenge, url: string, retried = false): ChallengeReport {
|
|
60
|
+
if (challenge.blocked !== true) return { blocked: false }
|
|
61
|
+
const fallbacks = fallbackRoutes(url)
|
|
62
|
+
return {
|
|
63
|
+
blocked: true,
|
|
64
|
+
...challenge.kind !== undefined ? { kind: challenge.kind } : {},
|
|
65
|
+
...challenge.reason !== undefined ? { reason: challenge.reason } : {},
|
|
66
|
+
...challenge.recovery !== undefined ? { recovery: challenge.recovery } : {},
|
|
67
|
+
...typeof challenge.status === 'number' ? { status: challenge.status } : {},
|
|
68
|
+
...retried ? { retried: true } : {},
|
|
69
|
+
advice: recoveryAdvice(challenge),
|
|
70
|
+
...fallbacks.length > 0 ? { fallbacks } : {},
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
/**
|
|
75
|
+
* The banner a rendered result ends with when the page is blocked.
|
|
76
|
+
* @param report - the tool's challenge report.
|
|
77
|
+
* @returns the banner text, or '' for a clean page.
|
|
78
|
+
*/
|
|
79
|
+
export function challengeBanner(report: ChallengeReport | undefined): string {
|
|
80
|
+
if (report?.blocked !== true) return ''
|
|
81
|
+
const head = `CHALLENGE (${report.kind ?? 'blocked'}${report.status !== undefined ? `, HTTP ${report.status}` : ''}): ${report.reason ?? 'human-verification'}.`
|
|
82
|
+
const retried = report.retried === true ? ' Already retried once in a fresh session after a pause.' : ''
|
|
83
|
+
const routes = (report.fallbacks ?? []).map(route => `\n - ${route.kind}: ${route.url} (${route.note})`).join('')
|
|
84
|
+
return `\n\n${head}${retried} ${report.advice ?? recoveryAdvice({ blocked: true })}${routes === '' ? '' : `\nFallback routes:${routes}`}`
|
|
85
|
+
}
|