dsh-builtin-browser 1.0.3 → 1.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +16 -1
- package/README.en.md +89 -0
- package/browser-extension/constants.mjs +20 -0
- package/browser-extension/controller.mjs +293 -0
- package/browser-extension/locales.mjs +15 -0
- package/browser-extension/manifest.json +12 -0
- package/browser-extension/options.html +14 -0
- package/browser-extension/options.mjs +9 -0
- package/browser-extension/permission-guard.mjs +13 -0
- package/browser-extension/worker.mjs +74 -0
- package/desktop-bridge/desktop-identity.json +10 -2
- package/desktop-bridge/install.mjs +28 -2
- package/docs/issue-replies-2026-11-28.md +141 -0
- package/dsh-host-patch/apply.mjs +1 -1
- package/dsh-host-patch/rc3.json +4 -4
- package/dsh-host-patch/rc5.json +4 -4
- package/dsh-host-patch/v023-alpha2.json +2 -2
- package/lib/browser-electron/bridge-status.js +24 -1
- package/lib/browser-electron/desktop-identity.js +47 -8
- package/lib/client.js +2 -1
- package/native-host/install.mjs +5 -0
- package/package.json +20 -2
- package/scripts/build-client.mjs +305 -0
- package/scripts/build.mjs +69 -0
- package/scripts/bundle-host.mjs +28 -0
- package/scripts/fix-exports.mjs +40 -0
- package/scripts/install-electron.mjs +101 -0
- package/scripts/pack.mjs +99 -0
- package/scripts/publish-manifest.mjs +56 -0
- package/scripts/verify-exports.mjs +58 -0
- package/scripts/verify-preview-sdk.mjs +93 -0
- package/skills/dsh-builtin-browser/SKILL.md +98 -0
- package/skills/dsh-builtin-browser/references/batch.md +68 -0
- package/skills/dsh-builtin-browser/references/deliver.md +31 -0
- package/skills/dsh-builtin-browser/references/locate.md +11 -0
- package/skills/dsh-builtin-browser/references/recover.md +11 -0
- package/skills/dsh-builtin-browser/references/verify.md +13 -0
- package/skills/dsh-debug-host/SKILL.md +56 -0
- package/skills/dsh-debug-self/SKILL.md +50 -0
- package/src/bridge-compatibility.ts +39 -0
- package/src/browser/anti-bot.ts +251 -0
- package/src/browser/deep-dom.ts +40 -0
- package/src/browser/handles.ts +89 -0
- package/src/browser/runtime.ts +578 -0
- package/src/browser/takeover-target.ts +45 -0
- package/src/browser/types.ts +870 -0
- package/src/browser-electron/authenticated-route.ts +109 -0
- package/src/browser-electron/automatic-maintenance.ts +736 -0
- package/src/browser-electron/bridge-auto.ts +159 -0
- package/src/browser-electron/bridge-connection.ts +386 -0
- package/src/browser-electron/bridge-endpoint.ts +129 -0
- package/src/browser-electron/bridge-install.ts +290 -0
- package/src/browser-electron/bridge-maintenance.ts +189 -0
- package/src/browser-electron/bridge-status.ts +412 -0
- package/src/browser-electron/desktop-bridge-host.ts +253 -0
- package/src/browser-electron/desktop-identity.ts +400 -0
- package/src/browser-electron/desktop-shell.ts +100 -0
- package/src/browser-electron/document-readiness.ts +45 -0
- package/src/browser-electron/electron-provision.ts +347 -0
- package/src/browser-electron/entry.ts +1378 -0
- package/src/browser-electron/ephemeral-profile.ts +189 -0
- package/src/browser-electron/extension-browser.ts +230 -0
- package/src/browser-electron/extension-setup.ts +67 -0
- package/src/browser-electron/file-write.ts +31 -0
- package/src/browser-electron/foreground-watch.ts +142 -0
- package/src/browser-electron/guest-cookie-jar.ts +177 -0
- package/src/browser-electron/guest-cookie-store.ts +59 -0
- package/src/browser-electron/guest-css-runtime.ts +76 -0
- package/src/browser-electron/guest-css.ts +68 -0
- package/src/browser-electron/guest-route.ts +716 -0
- package/src/browser-electron/guest-runtime.ts +408 -0
- package/src/browser-electron/guest-storage-runtime.ts +54 -0
- package/src/browser-electron/guest-storage.ts +120 -0
- package/src/browser-electron/history-store.ts +224 -0
- package/src/browser-electron/host-main.ts +1385 -0
- package/src/browser-electron/host-patch-maintenance.ts +121 -0
- package/src/browser-electron/http-body.ts +65 -0
- package/src/browser-electron/json-reply.ts +47 -0
- package/src/browser-electron/maintenance-broker.ts +166 -0
- package/src/browser-electron/maintenance-lifecycle.ts +91 -0
- package/src/browser-electron/maintenance-route.ts +68 -0
- package/src/browser-electron/missing-system-browser.ts +114 -0
- package/src/browser-electron/open-slot.ts +49 -0
- package/src/browser-electron/paths.ts +25 -0
- package/src/browser-electron/preferred-browser.ts +130 -0
- package/src/browser-electron/preview-route.ts +215 -0
- package/src/browser-electron/process-ownership.ts +174 -0
- package/src/browser-electron/process.ts +23 -0
- package/src/browser-electron/profile-checkpoint.ts +187 -0
- package/src/browser-electron/profile-command.ts +47 -0
- package/src/browser-electron/profile-extension.ts +129 -0
- package/src/browser-electron/profile-lease.ts +211 -0
- package/src/browser-electron/profile-residue.ts +49 -0
- 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 +666 -0
- package/src/browser-electron/reference-route.ts +598 -0
- package/src/browser-electron/remote-host.ts +1538 -0
- package/src/browser-electron/rpc-input.ts +13 -0
- package/src/browser-electron/rpc-ops.ts +41 -0
- package/src/browser-electron/runtime-diagnostics.ts +38 -0
- package/src/browser-electron/runtime-route.ts +105 -0
- package/src/browser-electron/runtime-status.ts +309 -0
- package/src/browser-electron/settings-route.ts +64 -0
- package/src/browser-electron/settings-store.ts +593 -0
- package/src/browser-electron/shortcuts-route.ts +112 -0
- package/src/browser-electron/sidebar-only-host.ts +300 -0
- package/src/browser-electron/startpage-shortcuts.ts +213 -0
- package/src/browser-electron/system-browser.ts +1850 -0
- package/src/browser-electron/tauri-host.ts +194 -0
- package/src/browser-electron/timing.ts +16 -0
- package/src/browser-electron/virtual-cursor.ts +162 -0
- package/src/browser-electron/windows-system.ts +24 -0
- package/src/browser-reference/delivery.ts +384 -0
- package/src/browser-reference/entry.ts +631 -0
- package/src/browser-reference/export.ts +339 -0
- package/src/browser-reference/import.ts +303 -0
- package/src/browser-reference/page-script.ts +1537 -0
- package/src/browser-reference/service.ts +1346 -0
- package/src/browser-reference/store.ts +172 -0
- package/src/browser-reference/text-quote.ts +219 -0
- package/src/browser-reference/types.ts +195 -0
- package/src/browser-reference/visible.ts +367 -0
- package/src/browser-reference/web-sources.ts +106 -0
- package/src/client/apply-guard.ts +22 -0
- package/src/client/browser/BrowserController.ts +693 -0
- package/src/client/browser/BrowserFrame.ts +78 -0
- package/src/client/browser/BrowserNavigation.ts +169 -0
- package/src/client/browser/BrowserPage.ts +23 -0
- package/src/client/browser/BrowserPersistence.ts +44 -0
- package/src/client/browser/IframeImpl.ts +182 -0
- package/src/client/browser/child-tabs.ts +14 -0
- package/src/client/browser/frame-history.ts +125 -0
- package/src/client/browser/frame-state.ts +27 -0
- package/src/client/browser/iframe-reference.ts +67 -0
- package/src/client/browser/initialization.ts +262 -0
- package/src/client/browser/omnibox.ts +243 -0
- package/src/client/browser/store.ts +38 -0
- package/src/client/browser/takeover-channel.ts +72 -0
- package/src/client/browser/url.ts +46 -0
- package/src/client/browser/web-reference-source.ts +56 -0
- package/src/client/css-modules.d.ts +4 -0
- package/src/client/definition.tsx +36 -0
- package/src/client/electron/ElectronWebViewImpl.ts +371 -0
- package/src/client/electron/ElectronWebviewPresentation.ts +140 -0
- package/src/client/electron/NativeChildPresentation.ts +53 -0
- package/src/client/electron/NativeViewPage.ts +265 -0
- package/src/client/electron/pages.ts +23 -0
- package/src/client/electron/reference-overlay.ts +53 -0
- package/src/client/electron/workspace.ts +33 -0
- package/src/client/index.ts +333 -0
- package/src/client/locales.ts +860 -0
- package/src/client/pages.ts +28 -0
- package/src/client/reference/client/BrowserRefLink.tsx +142 -0
- package/src/client/reference/client/draft-reference.ts +167 -0
- package/src/client/reference/client/index.ts +7 -0
- package/src/client/reference/client/ordered-submission.ts +108 -0
- package/src/client/reference/client/pending-delivery.ts +216 -0
- package/src/client/reference/client/plugin.ts +208 -0
- package/src/client/reference/client/production/ReferenceCapsules.tsx +345 -0
- package/src/client/reference/client/production/ReferenceDock.module.css +193 -0
- package/src/client/reference/client/production/ReferenceDock.tsx +6 -0
- package/src/client/reference/client/production/ReferenceFeedback.tsx +15 -0
- package/src/client/reference/client/production/ReferenceMath.tsx +44 -0
- package/src/client/reference/client/production/ReferenceText.tsx +36 -0
- package/src/client/reference/client/production/assembly.ts +447 -0
- package/src/client/reference/client/production/asset-store.ts +144 -0
- package/src/client/reference/client/production/availability.ts +72 -0
- package/src/client/reference/client/production/bytes.ts +36 -0
- package/src/client/reference/client/production/composer-attachments.ts +44 -0
- package/src/client/reference/client/production/delivery-client.ts +211 -0
- package/src/client/reference/client/production/draft-adapter.ts +512 -0
- package/src/client/reference/client/production/http-transport.ts +212 -0
- package/src/client/reference/client/production/production-submission.ts +70 -0
- package/src/client/reference/client/production/protocol.ts +234 -0
- package/src/client/reference/client/production/reference-card.ts +240 -0
- package/src/client/reference/client/production/reference-labels.ts +29 -0
- package/src/client/reference/client/production/reply-link-bridge.ts +222 -0
- package/src/client/reference/client/production/reveal.ts +215 -0
- package/src/client/reference/client/production/runtime.ts +1056 -0
- package/src/client/reference/client/production/snapshot-adapter.ts +154 -0
- package/src/client/reference/client/production/source-marker.ts +99 -0
- package/src/client/reference/client/production/source-opener.ts +55 -0
- package/src/client/reference/client/production/styles.ts +104 -0
- package/src/client/reference/client/production/user-text-rule.ts +67 -0
- package/src/client/reference/client/reveal.ts +109 -0
- package/src/client/reference/client/scheme.ts +114 -0
- package/src/client/reference/client/session-schedule.ts +36 -0
- package/src/client/reference/client/types.ts +168 -0
- package/src/client/reference/css-modules.d.ts +4 -0
- package/src/client/reference/index.ts +11 -0
- package/src/client/reference-capture-owner.ts +162 -0
- package/src/client/reference-intents.ts +36 -0
- package/src/client/settings/index.ts +42 -0
- package/src/client/settings/mount-guard.ts +31 -0
- package/src/client/settings/panel.ts +2773 -0
- package/src/client/shortcut-open.ts +30 -0
- package/src/client/startpage/binding.ts +99 -0
- package/src/client/startpage/controller.ts +300 -0
- package/src/client/startpage/model.ts +279 -0
- package/src/client/view/Browser.module.css +751 -0
- package/src/client/view/BrowserBody.tsx +315 -0
- package/src/client/view/BrowserPresentation.ts +9 -0
- package/src/client/view/BrowserTitle.tsx +17 -0
- package/src/client/view/IframePresentation.ts +365 -0
- package/src/client/view/StartPage.tsx +598 -0
- package/src/client/view/TakeoverBanner.tsx +21 -0
- package/src/compat/host-features.ts +92 -0
- package/src/index.ts +110 -0
- package/src/reference-owner.ts +5 -0
- package/src/reference-page.ts +9 -0
- package/src/reference-source.ts +3 -0
- package/src/reference-text.ts +219 -0
- package/src/startpage-settings.ts +103 -0
- package/src/startpage.ts +71 -0
- package/src/takeover-protocol.ts +28 -0
- package/src/tool-browser/block-recovery.ts +85 -0
- package/src/tool-browser/code-tool.ts +555 -0
- package/src/tool-browser/code-worker.ts +725 -0
- package/src/tool-browser/element-fields.ts +167 -0
- package/src/tool-browser/errors.ts +40 -0
- package/src/tool-browser/index.ts +265 -0
- package/src/tool-browser/page-probe.ts +675 -0
- package/src/tool-browser/panel-page.ts +126 -0
- package/src/tool-browser/probe-client.ts +183 -0
- package/src/tool-browser/screenshot-annotations.ts +131 -0
- package/src/tool-browser/screenshot-image.ts +49 -0
- package/src/tool-browser/state.ts +375 -0
- package/src/tool-browser/takeover.ts +199 -0
- 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/types/electron-shim.d.ts +144 -0
- package/src/types.ts +85 -0
- package/src/web-guest.ts +35 -0
- package/tools/accept-desktop.mjs +148 -0
- 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/dsh-builtin-browser-1.0.3-publish.tgz +0 -0
- package/dsh-builtin-browser-1.0.3.tgz +0 -0
- package/dsh-host-patch/sources/main/0001-feat-sidebar-right-add-session-rendering-holds.patch.gz +0 -0
- package/dsh-host-patch/sources/main/0002-feat-desktop-load-trusted-profile-main-extensions.patch.gz +0 -0
- package/dsh-host-patch/sources/main/0003-feat-desktop-report-resolved-and-running-main-extens.patch.gz +0 -0
- package/dsh-host-patch/sources/main/0004-feat-desktop-compose-admitted-native-sidebar-views.patch.gz +0 -0
- package/dsh-host-patch/sources/main/0005-fix-client-admit-coded-browser-errors-in-native-comp.patch.gz +0 -0
- package/dsh-host-patch/sources/main/0006-fix-desktop-acknowledge-native-same-document-navigat.patch.gz +0 -0
- package/dsh-host-patch/sources/main/0007-fix-desktop-restore-auth-in-the-native-lease-partiti.patch.gz +0 -0
- package/dsh-host-patch/sources/main/0008-feat-desktop-adopt-native-children-in-admitted-sideb.patch.gz +0 -0
- package/dsh-host-patch/sources/main/0009-fix-desktop-publish-complete-native-child-close-reco.patch.gz +0 -0
- package/dsh-host-patch/sources/main/0010-fix-desktop-bundle-structured-errors-in-sandboxed-pr.patch.gz +0 -0
- package/dsh-host-patch/sources/main/0011-feat-desktop-offer-persistent-Sidebar-sessions-per-D.patch.gz +0 -0
- package/dsh-host-patch/sources/main/0012-feat-desktop-retain-sidebar-session-cookies-across-r.patch.gz +0 -0
- package/dsh-host-patch/sources/main/0013-fix-desktop-honor-sidebar-session-cookie-sidecar-con.patch.gz +0 -0
- package/dsh-host-patch/sources/main/0014-fix-desktop-retry-cookie-protection-without-failing-.patch.gz +0 -0
- package/dsh-host-patch/sources/main/0015-fix-desktop-preserve-host-only-cookie-identity-in-se.patch.gz +0 -0
- package/dsh-host-patch/sources/main/0016-fix-desktop-restore-session-cookies-before-checkpoin.patch.gz +0 -0
- package/dsh-host-patch/sources/main/0017-fix-desktop-restore-sidebar-cookies-once-before-gues.patch.gz +0 -0
- package/dsh-host-patch/sources/main/0018-fix-sidebar-right-follow-animated-native-slot-placem.patch.gz +0 -0
- package/dsh-host-patch/sources/manifest.json +0 -218
- package/dsh-host-patch/sources/rc3/0001-feat-sidebar-right-add-session-rendering-holds.patch.gz +0 -0
- package/dsh-host-patch/sources/rc3/0002-feat-desktop-load-trusted-profile-main-extensions.patch.gz +0 -0
- package/dsh-host-patch/sources/rc3/0003-feat-desktop-report-resolved-and-running-main-extens.patch.gz +0 -0
- package/dsh-host-patch/sources/rc3/0004-feat-desktop-compose-admitted-native-sidebar-views.patch.gz +0 -0
- package/dsh-host-patch/sources/rc3/0005-fix-client-admit-coded-browser-errors-in-native-comp.patch.gz +0 -0
- package/dsh-host-patch/sources/rc3/0006-fix-desktop-acknowledge-native-same-document-navigat.patch.gz +0 -0
- package/dsh-host-patch/sources/rc3/0007-fix-desktop-restore-auth-in-the-native-lease-partiti.patch.gz +0 -0
- package/dsh-host-patch/sources/rc3/0008-feat-desktop-adopt-native-children-in-admitted-sideb.patch.gz +0 -0
- package/dsh-host-patch/sources/rc3/0009-fix-desktop-publish-complete-native-child-close-reco.patch.gz +0 -0
- package/dsh-host-patch/sources/rc3/0010-fix-desktop-bundle-structured-errors-in-sandboxed-pr.patch.gz +0 -0
- package/dsh-host-patch/sources/rc3/0011-feat-desktop-offer-persistent-Sidebar-sessions-per-D.patch.gz +0 -0
- package/dsh-host-patch/sources/rc3/0012-feat-desktop-retain-sidebar-session-cookies-across-r.patch.gz +0 -0
- package/dsh-host-patch/sources/rc3/0013-fix-desktop-honor-sidebar-session-cookie-sidecar-con.patch.gz +0 -0
- package/dsh-host-patch/sources/rc3/0014-fix-desktop-retry-cookie-protection-without-failing-.patch.gz +0 -0
- package/dsh-host-patch/sources/rc3/0015-fix-desktop-preserve-host-only-cookie-identity-in-se.patch.gz +0 -0
- package/dsh-host-patch/sources/rc3/0016-fix-desktop-restore-session-cookies-before-checkpoin.patch.gz +0 -0
- package/dsh-host-patch/sources/rc3/0017-fix-desktop-restore-sidebar-cookies-once-before-gues.patch.gz +0 -0
- package/dsh-host-patch/sources/rc3/0018-fix-sidebar-right-follow-animated-native-slot-placem.patch.gz +0 -0
- package/dsh-host-patch/sources/rc5/0001-feat-sidebar-right-add-session-rendering-holds.patch.gz +0 -0
- package/dsh-host-patch/sources/rc5/0002-feat-desktop-load-trusted-profile-main-extensions.patch.gz +0 -0
- package/dsh-host-patch/sources/rc5/0003-feat-desktop-report-resolved-and-running-main-extens.patch.gz +0 -0
- package/dsh-host-patch/sources/rc5/0004-feat-desktop-compose-admitted-native-sidebar-views.patch.gz +0 -0
- package/dsh-host-patch/sources/rc5/0005-fix-client-admit-coded-browser-errors-in-native-comp.patch.gz +0 -0
- package/dsh-host-patch/sources/rc5/0006-fix-desktop-acknowledge-native-same-document-navigat.patch.gz +0 -0
- package/dsh-host-patch/sources/rc5/0007-fix-desktop-restore-auth-in-the-native-lease-partiti.patch.gz +0 -0
- package/dsh-host-patch/sources/rc5/0008-feat-desktop-adopt-native-children-in-admitted-sideb.patch.gz +0 -0
- package/dsh-host-patch/sources/rc5/0009-fix-desktop-publish-complete-native-child-close-reco.patch.gz +0 -0
- package/dsh-host-patch/sources/rc5/0010-fix-desktop-bundle-structured-errors-in-sandboxed-pr.patch.gz +0 -0
- package/dsh-host-patch/sources/rc5/0011-feat-desktop-offer-persistent-Sidebar-sessions-per-D.patch.gz +0 -0
- package/dsh-host-patch/sources/rc5/0012-feat-desktop-retain-sidebar-session-cookies-across-r.patch.gz +0 -0
- package/dsh-host-patch/sources/rc5/0013-fix-desktop-honor-sidebar-session-cookie-sidecar-con.patch.gz +0 -0
- package/dsh-host-patch/sources/rc5/0014-fix-desktop-retry-cookie-protection-without-failing-.patch.gz +0 -0
- package/dsh-host-patch/sources/rc5/0015-fix-desktop-preserve-host-only-cookie-identity-in-se.patch.gz +0 -0
- package/dsh-host-patch/sources/rc5/0016-fix-desktop-restore-session-cookies-before-checkpoin.patch.gz +0 -0
- package/dsh-host-patch/sources/rc5/0017-fix-desktop-restore-sidebar-cookies-once-before-gues.patch.gz +0 -0
- package/dsh-host-patch/sources/rc5/0018-fix-sidebar-right-follow-animated-native-slot-placem.patch.gz +0 -0
- package/dsh-host-patch/sources/series.json +0 -260
|
@@ -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/index.ts
ADDED
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* dsh-builtin-browser plugin entry: aggregates the shared-browser capability
|
|
3
|
+
* pieces. The cordis.patch.yml rows reference subpath exports:
|
|
4
|
+
* - `dsh-builtin-browser/browser` -> the ctx.browser seam (Service)
|
|
5
|
+
* - `dsh-builtin-browser/browser-electron` -> the Electron CDP provider
|
|
6
|
+
* - `dsh-builtin-browser/tool-browser` -> the model-facing dsh_browser_* tools
|
|
7
|
+
* The capability itself is composed by those rows; this root entry exists for
|
|
8
|
+
* programmatic imports AND because the host's client-module scan identifies a
|
|
9
|
+
* package's browser half through a loader row whose specifier resolves to the
|
|
10
|
+
* PACKAGE ROOT. A row named after a subpath (`dsh-builtin-browser/browser`) is
|
|
11
|
+
* not a package specifier and is skipped by design, which is why the patch also
|
|
12
|
+
* registers a row under the bare package name — see cordis.patch.yml.
|
|
13
|
+
* @module dsh-builtin-browser
|
|
14
|
+
*/
|
|
15
|
+
|
|
16
|
+
/** Plugin identity for the root row (the composition surface is the subpath rows). */
|
|
17
|
+
|
|
18
|
+
import type { Context } from '@deepseek-ai/cordis'
|
|
19
|
+
|
|
20
|
+
export const name = 'dsh-builtin-browser'
|
|
21
|
+
|
|
22
|
+
/**
|
|
23
|
+
* Inert application for the root row: the browser seam, the Electron provider and
|
|
24
|
+
* the tools are mounted by the subpath rows, so this one only exists to give the
|
|
25
|
+
* package a loader row named after the package itself. Without it the host's
|
|
26
|
+
* client scan finds no row to resolve `dsh.client` from, and the settings panel
|
|
27
|
+
* never reaches the browser (the plugin works, its client half is invisible).
|
|
28
|
+
*/
|
|
29
|
+
import { registerWebGuest } from './web-guest.ts'
|
|
30
|
+
|
|
31
|
+
/**
|
|
32
|
+
* 根行只做与载体无关的装配:侧栏 guest 代理必须始终存在,不能依赖 Electron 行。
|
|
33
|
+
* @param ctx - 插件容器。
|
|
34
|
+
*/
|
|
35
|
+
export function apply(ctx: Context): void {
|
|
36
|
+
registerWebGuest(ctx)
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
|
|
40
|
+
export { BrowserError } from './browser/types.ts'
|
|
41
|
+
export type {
|
|
42
|
+
BrowserA11yNode,
|
|
43
|
+
BrowserA11yRequest,
|
|
44
|
+
BrowserA11yResult,
|
|
45
|
+
BrowserChallenge,
|
|
46
|
+
BrowserCheckRequest,
|
|
47
|
+
BrowserClearRequest,
|
|
48
|
+
BrowserClickRequest,
|
|
49
|
+
BrowserContentFormat,
|
|
50
|
+
BrowserContentRequest,
|
|
51
|
+
BrowserContentResult,
|
|
52
|
+
BrowserElementTarget,
|
|
53
|
+
BrowserExecuteRequest,
|
|
54
|
+
BrowserExecuteResult,
|
|
55
|
+
BrowserFillField,
|
|
56
|
+
BrowserFillRequest,
|
|
57
|
+
BrowserFillResult,
|
|
58
|
+
BrowserGetValueRequest,
|
|
59
|
+
BrowserGetValueResult,
|
|
60
|
+
BrowserNavigateRequest,
|
|
61
|
+
BrowserOpenRequest,
|
|
62
|
+
BrowserProvider,
|
|
63
|
+
BrowserScrapeField,
|
|
64
|
+
BrowserScrapeRequest,
|
|
65
|
+
BrowserScrapeResult,
|
|
66
|
+
BrowserScreenshotRequest,
|
|
67
|
+
BrowserScreenshotResult,
|
|
68
|
+
BrowserSelectRequest,
|
|
69
|
+
BrowserSelectResult,
|
|
70
|
+
BrowserSessionId,
|
|
71
|
+
BrowserSetValueRequest,
|
|
72
|
+
BrowserSetValueResult,
|
|
73
|
+
BrowserSnapshotElement,
|
|
74
|
+
BrowserSnapshotResult,
|
|
75
|
+
BrowserTab,
|
|
76
|
+
BrowserTypeRequest,
|
|
77
|
+
ExportedCookie,
|
|
78
|
+
} from './browser/types.ts'
|
|
79
|
+
export { BrowserRuntime } from './browser/runtime.ts'
|
|
80
|
+
export { BrowserReferenceService, createReferenceService, summarizeReference } from './browser-reference/service.ts'
|
|
81
|
+
export type {
|
|
82
|
+
BrowserReferenceDraftAdapter,
|
|
83
|
+
CaptureFailure,
|
|
84
|
+
CaptureOutcome,
|
|
85
|
+
CaptureRequest,
|
|
86
|
+
ReferenceHost,
|
|
87
|
+
ReferenceSummary,
|
|
88
|
+
RevealOutcome,
|
|
89
|
+
RevealPartResult,
|
|
90
|
+
} from './browser-reference/service.ts'
|
|
91
|
+
export type {
|
|
92
|
+
BrowserReference,
|
|
93
|
+
BrowserReferenceCarrier,
|
|
94
|
+
BrowserReferenceEntry,
|
|
95
|
+
BrowserReferenceOrigin,
|
|
96
|
+
BrowserReferencePart,
|
|
97
|
+
ImageAnchor,
|
|
98
|
+
ImageReferencePart,
|
|
99
|
+
TableAnchor,
|
|
100
|
+
TableCellRun,
|
|
101
|
+
TableCellSnapshot,
|
|
102
|
+
TableReferencePart,
|
|
103
|
+
TableSnapshot,
|
|
104
|
+
TextQuoteAnchor,
|
|
105
|
+
TextReferencePart,
|
|
106
|
+
} from './browser-reference/types.ts'
|
|
107
|
+
export { manifestHashOf, ReferenceStore, referenceStorePath } from './browser-reference/store.ts'
|
|
108
|
+
export { buildTextAnchor, findTextQuote } from './browser-reference/text-quote.ts'
|
|
109
|
+
export { ElectronBrowserProvider } from './browser-electron/provider.ts'
|
|
110
|
+
export type { ElectronBrowserViewHost, ElectronViewHandle } from './browser-electron/provider.ts'
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
export function sameReferenceDocument(left: string, right: string): boolean {
|
|
2
|
+
try {
|
|
3
|
+
const current = new URL(left)
|
|
4
|
+
const source = new URL(right)
|
|
5
|
+
current.hash = ''
|
|
6
|
+
source.hash = ''
|
|
7
|
+
return current.href === source.href
|
|
8
|
+
} catch { return left === right }
|
|
9
|
+
}
|
|
@@ -0,0 +1,219 @@
|
|
|
1
|
+
import { GUEST_ROUTE } from '../assets/browser-policy.mjs'
|
|
2
|
+
|
|
3
|
+
export const MAX_REFERENCE_TEXT = 20_000
|
|
4
|
+
|
|
5
|
+
export type ReferenceTextNode =
|
|
6
|
+
| { readonly type: 'text'; readonly text: string }
|
|
7
|
+
| { readonly type: 'break' }
|
|
8
|
+
| { readonly type: 'rule' }
|
|
9
|
+
| { readonly type: 'math'; readonly latex: string; readonly display: boolean; readonly mathml?: string }
|
|
10
|
+
| { readonly type: 'heading'; readonly level: number; readonly children: readonly ReferenceTextNode[] }
|
|
11
|
+
| { readonly type: 'pre'; readonly language?: string; readonly children: readonly ReferenceTextNode[] }
|
|
12
|
+
| { readonly type: 'list-item'; readonly value?: number; readonly children: readonly ReferenceTextNode[] }
|
|
13
|
+
| { readonly type: 'block' | 'paragraph' | 'strong' | 'emphasis' | 'code' | 'blockquote' | 'definition-list' | 'term' | 'definition' | 'sup' | 'sub' | 'ruby' | 'ruby-text'; readonly children: readonly ReferenceTextNode[] }
|
|
14
|
+
| { readonly type: 'link'; readonly href: string; readonly children: readonly ReferenceTextNode[] }
|
|
15
|
+
| { readonly type: 'list'; readonly ordered: boolean; readonly start: number; readonly children: readonly ReferenceTextNode[] }
|
|
16
|
+
|
|
17
|
+
/** Accept only bounded semantic data, never page HTML or arbitrary attributes. */
|
|
18
|
+
export function isReferenceText(value: unknown, maxLength = MAX_REFERENCE_TEXT): value is readonly ReferenceTextNode[] {
|
|
19
|
+
let count = 0
|
|
20
|
+
let mathmlCharacters = 0
|
|
21
|
+
const visit = (nodes: unknown, depth: number): boolean => Array.isArray(nodes) && depth <= 64 && nodes.every(node => {
|
|
22
|
+
if (++count > 4096 || typeof node !== 'object' || node === null) return false
|
|
23
|
+
if (node.type === 'text') {
|
|
24
|
+
if (typeof node.text !== 'string') return false
|
|
25
|
+
return node.text.length <= maxLength
|
|
26
|
+
}
|
|
27
|
+
if (node.type === 'break' || node.type === 'rule') return true
|
|
28
|
+
if (node.type === 'math') {
|
|
29
|
+
if (typeof node.latex !== 'string' || node.latex.length === 0 || typeof node.display !== 'boolean') return false
|
|
30
|
+
if (node.mathml !== undefined && (typeof node.mathml !== 'string' || node.mathml.length > 64_000)) return false
|
|
31
|
+
mathmlCharacters += node.mathml?.length ?? 0
|
|
32
|
+
return node.latex.length <= maxLength && mathmlCharacters <= 64_000
|
|
33
|
+
}
|
|
34
|
+
if (!['block', 'paragraph', 'strong', 'emphasis', 'code', 'pre', 'list-item', 'blockquote', 'link', 'list', 'heading', 'definition-list', 'term', 'definition', 'sup', 'sub', 'ruby', 'ruby-text'].includes(node.type)) return false
|
|
35
|
+
if (node.type === 'heading' && (!Number.isInteger(node.level) || node.level < 1 || node.level > 6)) return false
|
|
36
|
+
if (node.type === 'pre' && node.language !== undefined && (typeof node.language !== 'string' || !/^[\w+-]{1,64}$/u.test(node.language))) return false
|
|
37
|
+
if (node.type === 'list-item' && node.value !== undefined && (!Number.isSafeInteger(node.value) || Math.abs(node.value) > 1_000_000)) return false
|
|
38
|
+
if (node.type === 'link' && (typeof node.href !== 'string' || node.href.length > 4000 || !/^https?:\/\//iu.test(node.href))) return false
|
|
39
|
+
if (node.type === 'list' && (typeof node.ordered !== 'boolean' || !Number.isSafeInteger(node.start) || Math.abs(node.start) > 1_000_000)) return false
|
|
40
|
+
return visit(node.children, depth + 1)
|
|
41
|
+
})
|
|
42
|
+
return visit(value, 0) && renderReferenceText(value as readonly ReferenceTextNode[]).length <= maxLength
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
/** Optional preview structure must not consume the model-facing quote budget. */
|
|
46
|
+
export function normalizeReferenceText(value: unknown, maxLength = MAX_REFERENCE_TEXT): readonly ReferenceTextNode[] | undefined {
|
|
47
|
+
let count = 0
|
|
48
|
+
let remainingMathML = 64_000
|
|
49
|
+
const visit = (nodes: unknown, depth: number): unknown => {
|
|
50
|
+
if (!Array.isArray(nodes) || depth > 64) return undefined
|
|
51
|
+
return nodes.map(node => {
|
|
52
|
+
if (++count > 4096 || typeof node !== 'object' || node === null) return undefined
|
|
53
|
+
if (node.type === 'math') {
|
|
54
|
+
const { mathml, ...source } = node
|
|
55
|
+
if (typeof mathml !== 'string' || mathml.length > remainingMathML) return source
|
|
56
|
+
remainingMathML -= mathml.length
|
|
57
|
+
return { ...source, mathml }
|
|
58
|
+
}
|
|
59
|
+
return 'children' in node ? { ...node, children: visit(node.children, depth + 1) } : node
|
|
60
|
+
})
|
|
61
|
+
}
|
|
62
|
+
const normalized = visit(value, 0)
|
|
63
|
+
return isReferenceText(normalized, maxLength) ? normalized : undefined
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
function escapeMarkdown(text: string): string {
|
|
67
|
+
return text.replace(/[\\`*_{}[\]<>!|#]/gu, '\\$&')
|
|
68
|
+
}
|
|
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
|
+
|
|
90
|
+
export function referenceTextContent(nodes: readonly ReferenceTextNode[]): string {
|
|
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('')
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
/** The host accepts text content parts; encode the frozen semantics as Markdown. */
|
|
95
|
+
export function renderReferenceText(nodes: readonly ReferenceTextNode[]): string {
|
|
96
|
+
const render = (items: readonly ReferenceTextNode[]): string => {
|
|
97
|
+
let result = ''
|
|
98
|
+
for (const node of items) {
|
|
99
|
+
const text = renderNode(node)
|
|
100
|
+
if (['block', 'paragraph', 'pre', 'blockquote', 'list', 'heading', 'definition-list', 'term', 'definition', 'rule'].includes(node.type) || (node.type === 'math' && node.display)) {
|
|
101
|
+
if (result && !result.endsWith('\n\n')) result += result.endsWith('\n') ? '\n' : '\n\n'
|
|
102
|
+
result += `${text}\n\n`
|
|
103
|
+
} else result += text
|
|
104
|
+
}
|
|
105
|
+
return result
|
|
106
|
+
}
|
|
107
|
+
const renderNode = (node: ReferenceTextNode): string => {
|
|
108
|
+
if (node.type === 'text') return escapeMarkdown(node.text)
|
|
109
|
+
if (node.type === 'break') return ' \n'
|
|
110
|
+
if (node.type === 'rule') return '---'
|
|
111
|
+
if (node.type === 'math') return node.display ? `$$\n${node.latex}\n$$` : `$${node.latex}$`
|
|
112
|
+
if (node.type === 'code' || node.type === 'pre') {
|
|
113
|
+
const text = referenceTextContent(node.children)
|
|
114
|
+
const size = Math.max(node.type === 'pre' ? 3 : 1, ...[...text.matchAll(/`+/gu)].map(match => match[0].length + 1))
|
|
115
|
+
const fence = '`'.repeat(size)
|
|
116
|
+
return node.type === 'pre' ? `${fence}${node.language ?? ''}\n${text}\n${fence}` : `${fence} ${text} ${fence}`
|
|
117
|
+
}
|
|
118
|
+
const text = render(node.children)
|
|
119
|
+
switch (node.type) {
|
|
120
|
+
case 'block':
|
|
121
|
+
case 'paragraph': return text.trim()
|
|
122
|
+
case 'heading': return `${'#'.repeat(node.level)} ${text.trim()}`
|
|
123
|
+
case 'definition-list': return text.trim()
|
|
124
|
+
case 'term': return text.trim()
|
|
125
|
+
case 'definition': return `: ${text.trim()}`
|
|
126
|
+
case 'sup': return `<sup>${text}</sup>`
|
|
127
|
+
case 'sub': return `<sub>${text}</sub>`
|
|
128
|
+
case 'ruby': return `<ruby>${text}</ruby>`
|
|
129
|
+
case 'ruby-text': return `<rt>${text}</rt>`
|
|
130
|
+
case 'strong': return `**${text}**`
|
|
131
|
+
case 'emphasis': return `*${text}*`
|
|
132
|
+
case 'link': return `[${text}](${realHref(node.href).replace(/[\s()<>\\]/gu, char => encodeURIComponent(char).replace(/[()]/gu, token => `%${token.charCodeAt(0).toString(16).toUpperCase()}`))})`
|
|
133
|
+
case 'blockquote': return text.trim().split('\n').map(line => `> ${line}`).join('\n')
|
|
134
|
+
case 'list-item': return text
|
|
135
|
+
case 'list': {
|
|
136
|
+
let next = node.start
|
|
137
|
+
return node.children.map(child => {
|
|
138
|
+
if (child.type === 'list-item' && child.value !== undefined) next = child.value
|
|
139
|
+
const prefix = node.ordered ? `${next++}. ` : '- '
|
|
140
|
+
const lines = render([child]).trim().split('\n')
|
|
141
|
+
return prefix + lines.join(`\n${' '.repeat(prefix.length)}`)
|
|
142
|
+
}).join('\n')
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
return render(nodes).trim()
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
export interface ReferenceTable {
|
|
150
|
+
readonly columnCount?: number
|
|
151
|
+
readonly cells: readonly {
|
|
152
|
+
readonly row: number
|
|
153
|
+
readonly column: number
|
|
154
|
+
readonly rowSpan: number
|
|
155
|
+
readonly columnSpan: number
|
|
156
|
+
readonly role: 'header' | 'data'
|
|
157
|
+
readonly text: string
|
|
158
|
+
readonly content?: readonly ReferenceTextNode[]
|
|
159
|
+
}[]
|
|
160
|
+
readonly caption?: string
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
export function isReferenceTable(value: unknown): value is ReferenceTable {
|
|
164
|
+
if (typeof value !== 'object' || value === null) return false
|
|
165
|
+
const table = value as ReferenceTable
|
|
166
|
+
return (table.caption === undefined || (typeof table.caption === 'string' && table.caption.length <= MAX_REFERENCE_TEXT))
|
|
167
|
+
&& (table.columnCount === undefined || (Number.isSafeInteger(table.columnCount) && table.columnCount >= 0))
|
|
168
|
+
&& Array.isArray(table.cells) && table.cells.length <= 20_000
|
|
169
|
+
&& table.cells.every(cell => cell && typeof cell.text === 'string' && cell.text.length <= MAX_REFERENCE_TEXT
|
|
170
|
+
&& (cell.content === undefined || isReferenceText(cell.content))
|
|
171
|
+
&& (cell.role === 'header' || cell.role === 'data')
|
|
172
|
+
&& [cell.row, cell.column].every(n => Number.isSafeInteger(n) && n >= 0)
|
|
173
|
+
&& [cell.rowSpan, cell.columnSpan].every(n => Number.isSafeInteger(n) && n > 0))
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
export function renderReferenceTable(table: ReferenceTable): string {
|
|
177
|
+
const escape = (text: string): string => text.replace(/&/gu, '&').replace(/</gu, '<').replace(/>/gu, '>').replace(/\r?\n/gu, '<br>')
|
|
178
|
+
const caption = table.caption === undefined ? '' : `<caption>${escape(table.caption)}</caption>\n`
|
|
179
|
+
return `<table>\n${caption}${referenceTableRows(table).map(({ cells }) => `<tr>${cells.map(({ value: cell, columnSpan, rowSpan }) => {
|
|
180
|
+
if (cell === undefined) return `<td colspan="${columnSpan}"></td>`
|
|
181
|
+
const tag = cell.role === 'header' ? 'th' : 'td'
|
|
182
|
+
return `<${tag} rowspan="${rowSpan}" colspan="${columnSpan}">${escape(cell.text)}</${tag}>`
|
|
183
|
+
}).join('')}</tr>`).join('\n')}\n</table>`
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
export function renderReferenceMarkdownTable(table: ReferenceTable): string {
|
|
187
|
+
if (table.cells.length === 0) return ''
|
|
188
|
+
const rows = [...new Set(table.cells.map(cell => cell.row))].sort((a, b) => a - b)
|
|
189
|
+
const width = Math.min(200, table.cells.reduce((max, cell) => Math.max(max, cell.column + cell.columnSpan), table.columnCount ?? 0))
|
|
190
|
+
const escape = (text: string): string => text.replace(/\\/gu, '\\\\').replace(/\|/gu, '\\|').replace(/</gu, '<').replace(/>/gu, '>').replace(/\r?\n/gu, '<br>')
|
|
191
|
+
const line = (values: readonly string[]): string => `| ${values.join(' | ')} |`
|
|
192
|
+
const values = rows.map(row => Array.from({ length: width }, (_, column) => {
|
|
193
|
+
const cell = table.cells.find(cell => cell.row <= row && cell.row + cell.rowSpan > row && cell.column <= column && cell.column + cell.columnSpan > column)
|
|
194
|
+
return cell?.content === undefined ? escape(cell?.text ?? '') : renderReferenceText(cell.content).replace(/\\?\|/gu, '\\|').replace(/\r?\n/gu, '<br>')
|
|
195
|
+
}))
|
|
196
|
+
const header = table.cells.some(cell => cell.row === rows[0] && cell.role === 'header') ? values.shift()! : Array.from({ length: width }, () => '')
|
|
197
|
+
return [table.caption, line(header), line(Array.from({ length: width }, () => '---')), ...values.map(line)].filter(value => value !== undefined && value !== '').join('\n')
|
|
198
|
+
}
|
|
199
|
+
|
|
200
|
+
export function referenceTableRows<T extends ReferenceTable['cells'][number]>(table: { readonly cells: readonly T[]; readonly columnCount?: number }): {
|
|
201
|
+
row: number; cells: { column: number; columnSpan: number; rowSpan: number; value?: T }[]
|
|
202
|
+
}[] {
|
|
203
|
+
const rows = [...new Set(table.cells.map(cell => cell.row))].sort((a, b) => a - b)
|
|
204
|
+
const width = table.cells.reduce((max, cell) => Math.max(max, cell.column + cell.columnSpan), table.columnCount ?? 0)
|
|
205
|
+
return rows.map(row => {
|
|
206
|
+
const slots = table.cells.filter(cell => cell.row <= row && cell.row + cell.rowSpan > row)
|
|
207
|
+
.sort((a, b) => a.column - b.column)
|
|
208
|
+
const cells: { column: number; columnSpan: number; rowSpan: number; value?: T }[] = []
|
|
209
|
+
let column = 0
|
|
210
|
+
for (const cell of slots) {
|
|
211
|
+
if (cell.column > column) cells.push({ column, columnSpan: cell.column - column, rowSpan: 1 })
|
|
212
|
+
if (cell.row === row) cells.push({ column: cell.column, columnSpan: cell.columnSpan,
|
|
213
|
+
rowSpan: rows.filter(index => index >= row && index < row + cell.rowSpan).length, value: cell })
|
|
214
|
+
column = Math.max(column, cell.column + cell.columnSpan)
|
|
215
|
+
}
|
|
216
|
+
if (column < width) cells.push({ column, columnSpan: width - column, rowSpan: 1 })
|
|
217
|
+
return { row, cells }
|
|
218
|
+
})
|
|
219
|
+
}
|
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
/** Shared, schema-independent Sidebar Browser start-page preference model. */
|
|
2
|
+
|
|
3
|
+
/** Settings namespace owned by the start-page Host companion. */
|
|
4
|
+
export const BROWSER_STARTPAGE_NAMESPACE = 'browser-startpage'
|
|
5
|
+
|
|
6
|
+
/** Persisted preference layout version. */
|
|
7
|
+
export const BROWSER_STARTPAGE_VERSION = 1
|
|
8
|
+
|
|
9
|
+
/** Maximum stored shortcut entries. */
|
|
10
|
+
export const MAX_STARTPAGE_SHORTCUTS = 48
|
|
11
|
+
|
|
12
|
+
/** Maximum stored search engines. */
|
|
13
|
+
export const MAX_STARTPAGE_ENGINES = 12
|
|
14
|
+
|
|
15
|
+
/** Maximum stored URL length; shorter than the address-bar bound to keep patches readable. */
|
|
16
|
+
export const MAX_STARTPAGE_URL_LENGTH = 2048
|
|
17
|
+
|
|
18
|
+
/** Maximum shortcut display title length. */
|
|
19
|
+
export const MAX_SHORTCUT_TITLE_LENGTH = 80
|
|
20
|
+
|
|
21
|
+
/** Maximum search-engine display label length. */
|
|
22
|
+
export const MAX_ENGINE_LABEL_LENGTH = 48
|
|
23
|
+
|
|
24
|
+
/** Maximum shortcut icon key length; keys select local glyphs only. */
|
|
25
|
+
export const MAX_SHORTCUT_ICON_KEY_LENGTH = 32
|
|
26
|
+
|
|
27
|
+
/** One user-visible website entry. */
|
|
28
|
+
export interface BrowserShortcut {
|
|
29
|
+
readonly id: string
|
|
30
|
+
readonly title: string
|
|
31
|
+
readonly url: string
|
|
32
|
+
readonly iconKey?: string
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
/** One fixed search endpoint; no template syntax is interpreted. */
|
|
36
|
+
export interface BrowserSearchEngine {
|
|
37
|
+
readonly id: string
|
|
38
|
+
readonly label: string
|
|
39
|
+
readonly homeUrl: string
|
|
40
|
+
readonly searchUrl: string
|
|
41
|
+
readonly queryParameter: string
|
|
42
|
+
readonly extraParameters?: Readonly<Record<string, string>>
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
/** The complete shared start-page section. Array order is display order. */
|
|
46
|
+
export interface BrowserStartPagePreferences {
|
|
47
|
+
readonly version: number
|
|
48
|
+
readonly defaultSearchEngineId: string
|
|
49
|
+
readonly searchEngines: readonly BrowserSearchEngine[]
|
|
50
|
+
readonly shortcuts: readonly BrowserShortcut[]
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
/** Initial default engine. */
|
|
54
|
+
export const DEFAULT_SEARCH_ENGINE_ID = 'bing'
|
|
55
|
+
|
|
56
|
+
/** Initial search endpoints; replaceable by the user. */
|
|
57
|
+
export const DEFAULT_SEARCH_ENGINES: readonly BrowserSearchEngine[] = Object.freeze([
|
|
58
|
+
{
|
|
59
|
+
id: 'bing', label: 'Bing', homeUrl: 'https://www.bing.com/',
|
|
60
|
+
searchUrl: 'https://www.bing.com/search', queryParameter: 'q', extraParameters: {},
|
|
61
|
+
},
|
|
62
|
+
{
|
|
63
|
+
id: 'baidu', label: '百度', homeUrl: 'https://www.baidu.com/',
|
|
64
|
+
searchUrl: 'https://www.baidu.com/s', queryParameter: 'wd', extraParameters: {},
|
|
65
|
+
},
|
|
66
|
+
])
|
|
67
|
+
|
|
68
|
+
/** Initial website entries; editable, deletable, and never re-added after removal. */
|
|
69
|
+
export const DEFAULT_SHORTCUTS: readonly BrowserShortcut[] = Object.freeze([
|
|
70
|
+
...DEFAULT_SEARCH_ENGINES.map(({ id, label, homeUrl }) => ({ id, title: label, url: homeUrl, iconKey: id })),
|
|
71
|
+
{ id: 'deepseek', title: 'DeepSeek', url: 'https://chat.deepseek.com/', iconKey: 'deepseek' },
|
|
72
|
+
])
|
|
73
|
+
|
|
74
|
+
/**
|
|
75
|
+
* Build a detached initial preference section.
|
|
76
|
+
* @returns defaults safe for schema defaults and first-run display.
|
|
77
|
+
*/
|
|
78
|
+
export function defaultStartPagePreferences(): BrowserStartPagePreferences {
|
|
79
|
+
return {
|
|
80
|
+
version: BROWSER_STARTPAGE_VERSION,
|
|
81
|
+
defaultSearchEngineId: DEFAULT_SEARCH_ENGINE_ID,
|
|
82
|
+
searchEngines: DEFAULT_SEARCH_ENGINES.map(engine => ({ ...engine })),
|
|
83
|
+
shortcuts: DEFAULT_SHORTCUTS.map(shortcut => ({ ...shortcut })),
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
/**
|
|
88
|
+
* Whether a value can be a stable preference identifier.
|
|
89
|
+
* @param value - candidate id.
|
|
90
|
+
* @returns true for lowercase alphanumeric ids with inner dashes.
|
|
91
|
+
*/
|
|
92
|
+
export function isPreferenceId(value: string): boolean {
|
|
93
|
+
return /^[a-z0-9][a-z0-9-]{0,47}$/u.test(value)
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
/**
|
|
97
|
+
* Whether a value can name a URL query parameter.
|
|
98
|
+
* @param value - candidate parameter name.
|
|
99
|
+
* @returns true for a bounded plain name.
|
|
100
|
+
*/
|
|
101
|
+
export function isQueryParameterName(value: string): boolean {
|
|
102
|
+
return /^[A-Za-z][A-Za-z0-9_.-]{0,31}$/u.test(value)
|
|
103
|
+
}
|
package/src/startpage.ts
ADDED
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
/** Host registration for shared Sidebar Browser start-page preferences. */
|
|
2
|
+
import type { Context, Volatile } from '@deepseek-ai/cordis'
|
|
3
|
+
import type {} from '@deepseek-ai/dsh-settings'
|
|
4
|
+
import z from '@deepseek-ai/schemastery'
|
|
5
|
+
import {
|
|
6
|
+
BROWSER_STARTPAGE_VERSION, DEFAULT_SEARCH_ENGINE_ID, DEFAULT_SEARCH_ENGINES, DEFAULT_SHORTCUTS,
|
|
7
|
+
MAX_ENGINE_LABEL_LENGTH, MAX_SHORTCUT_ICON_KEY_LENGTH,
|
|
8
|
+
MAX_SHORTCUT_TITLE_LENGTH, MAX_STARTPAGE_ENGINES, MAX_STARTPAGE_SHORTCUTS,
|
|
9
|
+
MAX_STARTPAGE_URL_LENGTH,
|
|
10
|
+
} from './startpage-settings.ts'
|
|
11
|
+
import type { BrowserSearchEngine, BrowserShortcut } from './startpage-settings.ts'
|
|
12
|
+
|
|
13
|
+
const identifier = z.string().pattern(/^[a-z0-9][a-z0-9-]{0,47}$/u).required()
|
|
14
|
+
const httpUrl = z.string().max(MAX_STARTPAGE_URL_LENGTH).pattern(/^https?:\/\/\S+$/u).required()
|
|
15
|
+
|
|
16
|
+
const shortcutSchema = z.object({
|
|
17
|
+
id: identifier,
|
|
18
|
+
title: z.string().max(MAX_SHORTCUT_TITLE_LENGTH).required(),
|
|
19
|
+
url: httpUrl,
|
|
20
|
+
iconKey: z.string().max(MAX_SHORTCUT_ICON_KEY_LENGTH).default(''),
|
|
21
|
+
})
|
|
22
|
+
|
|
23
|
+
const searchEngineSchema = z.object({
|
|
24
|
+
id: identifier,
|
|
25
|
+
label: z.string().max(MAX_ENGINE_LABEL_LENGTH).required(),
|
|
26
|
+
homeUrl: httpUrl,
|
|
27
|
+
searchUrl: httpUrl,
|
|
28
|
+
queryParameter: z.string().pattern(/^[A-Za-z][A-Za-z0-9_.-]{0,31}$/u).required(),
|
|
29
|
+
extraParameters: z.dict(z.string().max(200)).default({}),
|
|
30
|
+
})
|
|
31
|
+
|
|
32
|
+
/** Live start-page preferences projected to every client of this Host. */
|
|
33
|
+
export interface Config {
|
|
34
|
+
/** Persisted layout version. */
|
|
35
|
+
version: Volatile<number>
|
|
36
|
+
/** Selected search engine id. */
|
|
37
|
+
defaultSearchEngineId: Volatile<string>
|
|
38
|
+
/** Search endpoints in display order. */
|
|
39
|
+
searchEngines: Volatile<BrowserSearchEngine[]>
|
|
40
|
+
/** Website entries in display order. */
|
|
41
|
+
shortcuts: Volatile<BrowserShortcut[]>
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
const DEFAULT_ENGINE_OBJECTS = DEFAULT_SEARCH_ENGINES.map(engine => ({ ...engine, extraParameters: { ...engine.extraParameters } }))
|
|
45
|
+
const DEFAULT_SHORTCUT_OBJECTS = DEFAULT_SHORTCUTS.map(shortcut => ({ ...shortcut }))
|
|
46
|
+
|
|
47
|
+
/**
|
|
48
|
+
* Volatile-only config: preference writes update values without remounting the browser.
|
|
49
|
+
*
|
|
50
|
+
* 显式标注类型:schemastery 的 `z.object(...)` 推导类型在本仓库的声明生成里会引入无法命名的
|
|
51
|
+
* `Dict` 引用(`TS2883`),导致 `target/dts` 里缺少本文件的 `.d.ts`,进而被发布前检查判为
|
|
52
|
+
* 「声明缺失」。标注 `z<Config>` 只影响类型,运行期对象一字未改。
|
|
53
|
+
*/
|
|
54
|
+
export const Config: z<Config> = z.object({
|
|
55
|
+
version: z.number().default(BROWSER_STARTPAGE_VERSION).volatile(),
|
|
56
|
+
defaultSearchEngineId: z.string().default(DEFAULT_SEARCH_ENGINE_ID).volatile(),
|
|
57
|
+
searchEngines: z.array(searchEngineSchema).max(MAX_STARTPAGE_ENGINES)
|
|
58
|
+
.default(DEFAULT_ENGINE_OBJECTS).volatile(),
|
|
59
|
+
shortcuts: z.array(shortcutSchema).max(MAX_STARTPAGE_SHORTCUTS)
|
|
60
|
+
.default(DEFAULT_SHORTCUT_OBJECTS).volatile(),
|
|
61
|
+
}) as z<Config>
|
|
62
|
+
|
|
63
|
+
/**
|
|
64
|
+
* Keep preference writes live instead of reloading the owning entry.
|
|
65
|
+
* @param ctx - the start-page Host companion's context.
|
|
66
|
+
*/
|
|
67
|
+
export function apply(ctx: Context): void {
|
|
68
|
+
ctx.inject(['settings'], (child) => {
|
|
69
|
+
child.effect(() => child.settings.configure({ auto: false }, ctx.fiber), 'browser-startpage: live preferences')
|
|
70
|
+
})
|
|
71
|
+
}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
export { TAKEOVER_ROUTE } from '../assets/browser-policy.mjs'
|
|
2
|
+
export const TAKEOVER_TOOL = 'dsh_browser_request_takeover'
|
|
3
|
+
|
|
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'
|
|
14
|
+
export type TakeoverDecision = 'allowed-once' | 'rejected' | 'cancelled' | 'unavailable'
|
|
15
|
+
|
|
16
|
+
export interface TakeoverSummary {
|
|
17
|
+
readonly url: string
|
|
18
|
+
readonly title: string
|
|
19
|
+
readonly snapshotHint: string
|
|
20
|
+
readonly fresh: boolean
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
export interface TakeoverNotice {
|
|
24
|
+
readonly id: string
|
|
25
|
+
readonly reason: string
|
|
26
|
+
readonly instructions?: string
|
|
27
|
+
readonly phase: 'waiting' | 'summary'
|
|
28
|
+
}
|