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,154 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Pure adapter from the plugin's FROZEN `BrowserReference` snapshot to the
|
|
3
|
+
* additive package's `OrderedReferenceGroup` contract and to card/send content.
|
|
4
|
+
*
|
|
5
|
+
* Nothing here re-fetches the page: the snapshot already carries ordered parts,
|
|
6
|
+
* long text verbatim, table cells (with merges / role / completeness / partial
|
|
7
|
+
* selection) and image asset keys. Two projections are deliberately kept:
|
|
8
|
+
* - the lossy `OrderedReferenceGroup` (for `createSubmissionProjector`);
|
|
9
|
+
* - the full snapshot (for the dock card and reveal), retained alongside the
|
|
10
|
+
* group by the draft adapter so no cell or byte is lost on recovery.
|
|
11
|
+
*
|
|
12
|
+
* @module dsh-browser-reference/production/snapshot-adapter
|
|
13
|
+
*/
|
|
14
|
+
import type { BrowserReferencePart as ContractPart, OrderedReferenceGroup } from '../types.ts'
|
|
15
|
+
import type {
|
|
16
|
+
BrowserReferencePart,
|
|
17
|
+
FrozenSnapshot,
|
|
18
|
+
TableSnapshot,
|
|
19
|
+
} from './protocol.ts'
|
|
20
|
+
|
|
21
|
+
/** A source description a card can render without re-reading the page. */
|
|
22
|
+
export interface SourceDescription {
|
|
23
|
+
readonly host: string
|
|
24
|
+
readonly title: string
|
|
25
|
+
readonly pageUrl: string
|
|
26
|
+
readonly capturedAt: string
|
|
27
|
+
readonly frameUrl?: string
|
|
28
|
+
readonly frameRoute?: 'main' | 'frame'
|
|
29
|
+
readonly frameSelector?: string
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
/** Extract the host of a page URL without throwing on unusual schemes. */
|
|
33
|
+
export function sourceOf(snapshot: FrozenSnapshot): SourceDescription {
|
|
34
|
+
const { source } = snapshot
|
|
35
|
+
let host = source.pageUrl
|
|
36
|
+
try {
|
|
37
|
+
host = new URL(source.pageUrl).host || source.pageUrl
|
|
38
|
+
} catch { /* an unparseable pageUrl keeps its literal value */ }
|
|
39
|
+
return {
|
|
40
|
+
host,
|
|
41
|
+
title: source.title,
|
|
42
|
+
pageUrl: source.pageUrl,
|
|
43
|
+
capturedAt: source.capturedAt,
|
|
44
|
+
...(source.frameUrl === undefined ? {} : { frameUrl: source.frameUrl }),
|
|
45
|
+
...(source.frameRoute === undefined ? {} : { frameRoute: source.frameRoute }),
|
|
46
|
+
...(source.frameSelector === undefined ? {} : { frameSelector: source.frameSelector }),
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
export type ContentType = 'text' | 'image' | 'table' | 'mixed'
|
|
51
|
+
|
|
52
|
+
/** `mixed` is derived from parts with more than one kind (never reordered). */
|
|
53
|
+
export function contentTypeOf(snapshot: FrozenSnapshot): ContentType {
|
|
54
|
+
const first = snapshot.parts[0]?.type
|
|
55
|
+
if (first === undefined) return 'text'
|
|
56
|
+
return snapshot.parts.every(part => part.type === first) ? first : 'mixed'
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
/**
|
|
60
|
+
* Deterministic, lossless-enough text projection of a table snapshot for the
|
|
61
|
+
* model block. Every cell's `text` is included verbatim; merges, role,
|
|
62
|
+
* completeness and partial-selection facts are annotated so a unit test (and a
|
|
63
|
+
* reader) can see the structure that Markdown/TSV would otherwise flatten.
|
|
64
|
+
*/
|
|
65
|
+
export function projectTableText(table: TableSnapshot, caption?: string): string {
|
|
66
|
+
const lines: string[] = []
|
|
67
|
+
lines.push(`[table ${table.rowCount}x${table.columnCount} completeness=${table.completeness} norm=${table.normalizationVersion}]`)
|
|
68
|
+
if (caption !== undefined && caption !== '') lines.push(`caption: ${caption}`)
|
|
69
|
+
for (const cell of table.cells) {
|
|
70
|
+
const span = `${cell.rowSpan}r x ${cell.columnSpan}c`
|
|
71
|
+
const flags = [
|
|
72
|
+
cell.role,
|
|
73
|
+
cell.includedAs,
|
|
74
|
+
cell.partialText ? 'partial-text' : 'full-text',
|
|
75
|
+
].join(',')
|
|
76
|
+
const images = (cell.inlineContent ?? [])
|
|
77
|
+
.filter((run): run is Extract<typeof run, { type: 'image' }> => run.type === 'image')
|
|
78
|
+
.map(run => `${run.partId}@${run.assetKey}`)
|
|
79
|
+
.join(',')
|
|
80
|
+
lines.push(`[${cell.row},${cell.column}] (${span}; ${flags})${images === '' ? '' : ` images=[${images}]`}: ${cell.text}`)
|
|
81
|
+
}
|
|
82
|
+
return lines.join('\n')
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
/** One part of a frozen snapshot -> one contract part (capture order preserved). */
|
|
86
|
+
function projectPart(part: BrowserReferencePart, referenceId: string): ContractPart {
|
|
87
|
+
switch (part.type) {
|
|
88
|
+
case 'text':
|
|
89
|
+
return {
|
|
90
|
+
kind: 'text',
|
|
91
|
+
partId: part.partId,
|
|
92
|
+
referenceId,
|
|
93
|
+
text: part.text,
|
|
94
|
+
...(part.content === undefined ? {} : { content: part.content }),
|
|
95
|
+
label: part.anchor.exact,
|
|
96
|
+
}
|
|
97
|
+
case 'image':
|
|
98
|
+
return {
|
|
99
|
+
kind: 'image',
|
|
100
|
+
partId: part.partId,
|
|
101
|
+
referenceId,
|
|
102
|
+
assetKey: part.assetKey,
|
|
103
|
+
...((part.alt ?? part.caption) === undefined ? {} : { text: [part.alt === undefined ? undefined : `Image: ${part.alt}`, part.caption].filter(value => value !== undefined).join('\n') }),
|
|
104
|
+
...(part.alt === undefined ? {} : { label: part.alt }),
|
|
105
|
+
// No `mimeType`: the contract field is a real MIME type, and a frozen
|
|
106
|
+
// snapshot does not carry one (bytes and their sidecar do). Claiming
|
|
107
|
+
// `image` here would be a value no consumer could rely on.
|
|
108
|
+
}
|
|
109
|
+
case 'table':
|
|
110
|
+
return {
|
|
111
|
+
kind: 'table',
|
|
112
|
+
partId: part.partId,
|
|
113
|
+
referenceId,
|
|
114
|
+
text: projectTableText(part.table, part.table.caption ?? part.anchor.caption),
|
|
115
|
+
table: part.table,
|
|
116
|
+
}
|
|
117
|
+
default: {
|
|
118
|
+
const exhaustive: never = part
|
|
119
|
+
throw new Error(`unhandled snapshot part: ${JSON.stringify(exhaustive)}`)
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
/** Convert a frozen snapshot into the additive ordered group. */
|
|
125
|
+
export function toOrderedGroup(snapshot: FrozenSnapshot): OrderedReferenceGroup {
|
|
126
|
+
return {
|
|
127
|
+
referenceId: snapshot.referenceId,
|
|
128
|
+
parts: snapshot.parts.map(part => projectPart(part, snapshot.referenceId)),
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
/**
|
|
133
|
+
* All image asset keys a reference needs, including inline images inside table
|
|
134
|
+
* cells. Mirrors the plugin's `imageAssetKeys()` so the client ACK carries the
|
|
135
|
+
* exact same set the server checks. Order-stable and deduplicated.
|
|
136
|
+
*/
|
|
137
|
+
export function requiredAssetKeys(snapshot: FrozenSnapshot): readonly string[] {
|
|
138
|
+
const keys: string[] = []
|
|
139
|
+
const visit = (part: BrowserReferencePart): void => {
|
|
140
|
+
if (part.type === 'image') {
|
|
141
|
+
keys.push(part.assetKey)
|
|
142
|
+
return
|
|
143
|
+
}
|
|
144
|
+
if (part.type === 'table') {
|
|
145
|
+
for (const cell of part.table.cells) {
|
|
146
|
+
for (const run of cell.inlineContent ?? []) {
|
|
147
|
+
if (run.type === 'image') keys.push(run.assetKey)
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
for (const part of snapshot.parts) visit(part)
|
|
153
|
+
return [...new Set(keys)]
|
|
154
|
+
}
|
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
import { encodeBrowserRefUri, parseBrowserRefUri } from '../scheme.ts'
|
|
2
|
+
|
|
3
|
+
export const SOURCE_LINK_LABEL = '引用来源'
|
|
4
|
+
const QUOTE_OPEN = '<dsh-browser-quote length="'
|
|
5
|
+
const QUOTE_CLOSE = '</dsh-browser-quote>'
|
|
6
|
+
|
|
7
|
+
export function submissionQuote(text: string): string {
|
|
8
|
+
return `${QUOTE_OPEN}${text.length}">${text}${QUOTE_CLOSE}\n`
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
export function readSubmissionQuote(text: string, from: number) {
|
|
12
|
+
const header = /<dsh-browser-quote length="(\d+)">/gu
|
|
13
|
+
header.lastIndex = from
|
|
14
|
+
for (let match = header.exec(text); match !== null; match = header.exec(text)) {
|
|
15
|
+
const length = Number(match[1])
|
|
16
|
+
if (!Number.isSafeInteger(length)) continue
|
|
17
|
+
const close = header.lastIndex + length
|
|
18
|
+
if (text.slice(close, close + QUOTE_CLOSE.length) !== QUOTE_CLOSE) continue
|
|
19
|
+
let end = close + QUOTE_CLOSE.length
|
|
20
|
+
if (text[end] === '\n') end += 1
|
|
21
|
+
return { start: match.index, end, body: text.slice(header.lastIndex, close) }
|
|
22
|
+
}
|
|
23
|
+
return undefined
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
export function sourceMarker(referenceId: string, index: number, title?: string): string {
|
|
27
|
+
const cleaned = (title ?? '').replace(/[\r\n\t]+/gu, ' ')
|
|
28
|
+
.replace(/[\[\]()\\`<>*_]/gu, '').replace(/\s+/gu, ' ').trim()
|
|
29
|
+
const displayTitle = Array.from(cleaned).slice(0, 80).join('').trim()
|
|
30
|
+
const rawLabel = `${SOURCE_LINK_LABEL} ${index + 1}${displayTitle === '' ? '' : `:${displayTitle}`}`
|
|
31
|
+
const label = typeof rawLabel.toWellFormed === 'function' ? rawLabel.toWellFormed() : rawLabel
|
|
32
|
+
// The label travels readable: the host renders this attribute as the capsule's visible text and
|
|
33
|
+
// does not decode it, so percent-encoding showed `%E5%BC%95…` instead of the source title. The
|
|
34
|
+
// sanitizer above removed every character that could close the attribute (`"`, `<`, `>`, `\`,
|
|
35
|
+
// newlines); spaces are allowed by the reader below. A literal `%` is the one sequence the reader
|
|
36
|
+
// still decodes, so it is escaped here and restored on read.
|
|
37
|
+
return `<dsh-browser-reference uri="${encodeBrowserRefUri({ referenceId })}" label="${label.replaceAll('%', '%25')}"/>`
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
export function readSourceMarker(text: string, from: number) {
|
|
41
|
+
// `[^"\s]*` used to be enough while labels were percent-encoded; a readable label contains
|
|
42
|
+
// spaces, so the body allows any non-quote character and percent-decodes only legacy labels.
|
|
43
|
+
const marker = /<dsh-browser-reference uri="(dsh-browser-ref:[^"\s]+)" label="([^"]*)"\/>|\[([^\]\r\n]*)\]\((dsh-browser-ref:[^()\s]+)\)/gu
|
|
44
|
+
marker.lastIndex = from
|
|
45
|
+
for (let candidate = marker.exec(text); candidate !== null; candidate = marker.exec(text)) {
|
|
46
|
+
const uri = (candidate[1] ?? candidate[4])!
|
|
47
|
+
const reference = parseBrowserRefUri(uri)
|
|
48
|
+
if (reference === undefined) continue
|
|
49
|
+
let label = candidate[3] ?? uri
|
|
50
|
+
if (candidate[2] !== undefined) {
|
|
51
|
+
const raw = candidate[2]
|
|
52
|
+
// Earlier builds wrote encodeURIComponent(label); decode only that shape so a title that
|
|
53
|
+
// happens to contain a percent sign is not mangled.
|
|
54
|
+
if (/%[0-9A-Fa-f]{2}/u.test(raw)) {
|
|
55
|
+
try { label = decodeURIComponent(raw) } catch { continue }
|
|
56
|
+
} else {
|
|
57
|
+
label = raw
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
return { start: candidate.index, end: candidate.index + candidate[0].length,
|
|
61
|
+
uri, label, ...reference }
|
|
62
|
+
}
|
|
63
|
+
return undefined
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
const COMPOSER_OPEN = '<dsh-browser-quote>'
|
|
67
|
+
const COMPOSER_CLOSE = '</dsh-browser-quote>'
|
|
68
|
+
const QUOTE_PREFIX = /^ {0,3}>[ \t]?/u
|
|
69
|
+
|
|
70
|
+
/** The editor quote for one reference: its projected body framed by tags, then its source marker. */
|
|
71
|
+
export function composerQuote(body: string, marker: string): string {
|
|
72
|
+
const normalized = body.replace(/\r\n?/gu, '\n').replace(/\n+$/u, '')
|
|
73
|
+
return `${COMPOSER_OPEN}\n${normalized}\n${COMPOSER_CLOSE}\n${marker}`
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
/**
|
|
77
|
+
* Find a composer quote in sent text. The host prefixes every quoted line with `> `, so the frame
|
|
78
|
+
* lines, the body lines and the marker line are matched with or without that prefix.
|
|
79
|
+
*/
|
|
80
|
+
export function readComposerQuote(text: string, from: number) {
|
|
81
|
+
const open = /(^|\n)( {0,3}>[ \t]?)?<dsh-browser-quote>\n/gu
|
|
82
|
+
open.lastIndex = Math.max(0, from - 1)
|
|
83
|
+
for (let match = open.exec(text); match !== null; match = open.exec(text)) {
|
|
84
|
+
const start = match.index + match[1]!.length
|
|
85
|
+
const bodyStart = open.lastIndex
|
|
86
|
+
open.lastIndex = bodyStart - 1
|
|
87
|
+
if (start < from) continue
|
|
88
|
+
const close = /\n( {0,3}>[ \t]?)?<\/dsh-browser-quote>\n/gu
|
|
89
|
+
close.lastIndex = bodyStart - 1
|
|
90
|
+
const closed = close.exec(text)
|
|
91
|
+
if (closed === null) return undefined
|
|
92
|
+
const marker = readSourceMarker(text, close.lastIndex)
|
|
93
|
+
if (marker === undefined || !/^( {0,3}>[ \t]?)?$/u.test(text.slice(close.lastIndex, marker.start))) continue
|
|
94
|
+
const body = text.slice(bodyStart, closed.index).split('\n').map(line => line.replace(QUOTE_PREFIX, '')).join('\n')
|
|
95
|
+
const markerLine = text.lastIndexOf('\n', marker.start - 1) + 1
|
|
96
|
+
return { start, end: marker.end, markerLine, body, marker }
|
|
97
|
+
}
|
|
98
|
+
return undefined
|
|
99
|
+
}
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
import type { TabId } from '@deepseek-ai/dsh-client-ui-dockkit'
|
|
2
|
+
import type { BrowserInitializationReader, BrowserInitReceipt } from '../../../browser/initialization.ts'
|
|
3
|
+
import { sameReferenceDocument } from '../../../../reference-page.ts'
|
|
4
|
+
import { iframeReferenceSource, type ReferenceSourcePage } from '../../../browser/iframe-reference.ts'
|
|
5
|
+
|
|
6
|
+
export interface SourceSidebar {
|
|
7
|
+
openTabIn(sessionId: string, kind: string, options: { readonly params: { readonly url: string } }): unknown
|
|
8
|
+
tabsIn(sessionId: string): readonly { readonly id: string; readonly kind: string }[]
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
export async function openReferenceSource(sidebar: SourceSidebar, reader: BrowserInitializationReader,
|
|
12
|
+
owner: string, url: string, signal: AbortSignal): Promise<ReferenceSourcePage> {
|
|
13
|
+
if (!owner || typeof sidebar?.openTabIn !== 'function' || typeof sidebar.tabsIn !== 'function'
|
|
14
|
+
|| typeof reader?.wait !== 'function') throw new Error('acknowledged sidebar initialization unavailable')
|
|
15
|
+
signal.throwIfAborted()
|
|
16
|
+
const sessionId = owner
|
|
17
|
+
const sourcePage = (pageId: string): ReferenceSourcePage => {
|
|
18
|
+
const iframe = iframeReferenceSource(pageId, owner)
|
|
19
|
+
if (iframe !== undefined) return iframe
|
|
20
|
+
if (pageId.startsWith('iframe:')) throw new Error('source iframe is no longer owned by this conversation')
|
|
21
|
+
return { pageId }
|
|
22
|
+
}
|
|
23
|
+
const previous = new Map(sidebar.tabsIn(sessionId).map(tab => [tab.id,
|
|
24
|
+
reader.read({ sessionId, tabId: tab.id as TabId, url })?.requestId]))
|
|
25
|
+
const existing = sidebar.tabsIn(sessionId).filter(tab => tab.kind === 'browser')
|
|
26
|
+
for (const tab of existing) {
|
|
27
|
+
const page = reader.current({ sessionId, tabId: tab.id as TabId })
|
|
28
|
+
if (page !== undefined && sameReferenceDocument(page.url, url)) {
|
|
29
|
+
if (!page.guestId) throw new Error('source highlighting requires a controllable sidebar guest')
|
|
30
|
+
return sourcePage(page.guestId)
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
let tabId: TabId
|
|
34
|
+
let afterRequestId: string | undefined
|
|
35
|
+
if (existing.length === 1) {
|
|
36
|
+
tabId = existing[0]!.id as TabId
|
|
37
|
+
afterRequestId = previous.get(tabId)
|
|
38
|
+
if (reader.navigate?.({ sessionId, tabId, url }) !== true) throw new Error('acknowledged sidebar navigation unavailable')
|
|
39
|
+
} else {
|
|
40
|
+
await sidebar.openTabIn(sessionId, 'browser', { params: { url } })
|
|
41
|
+
const created = sidebar.tabsIn(sessionId).filter(tab => tab.kind === 'browser' && !previous.has(tab.id))
|
|
42
|
+
if (created.length !== 1) throw new Error('sidebar did not identify one source tab')
|
|
43
|
+
tabId = created[0]!.id as TabId
|
|
44
|
+
}
|
|
45
|
+
signal.throwIfAborted()
|
|
46
|
+
const waiting = new AbortController()
|
|
47
|
+
const abort = (): void => { waiting.abort(signal.reason) }
|
|
48
|
+
signal.addEventListener('abort', abort, { once: true })
|
|
49
|
+
const timer = setTimeout(() => { waiting.abort(new Error('GUEST_SOURCE_TIMEOUT: source page did not become ready')) }, 15000)
|
|
50
|
+
let receipt: BrowserInitReceipt
|
|
51
|
+
try { receipt = await reader.wait({ sessionId, tabId, url, afterRequestId }, waiting.signal) }
|
|
52
|
+
finally { clearTimeout(timer); signal.removeEventListener('abort', abort) }
|
|
53
|
+
if (!receipt.guestId) throw new Error('source highlighting requires a controllable sidebar guest')
|
|
54
|
+
return sourcePage(receipt.guestId)
|
|
55
|
+
}
|
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Reply-side link styling.
|
|
3
|
+
*
|
|
4
|
+
* The composer rail styles itself through `ReferenceDock.module.css`; the only
|
|
5
|
+
* rule that has to live in the host document concerns anchors an OLDER markdown
|
|
6
|
+
* bundle renders for `dsh-browser-ref:` destinations. The link bridge upgrades
|
|
7
|
+
* them in place, so they only need to look like a link until it does.
|
|
8
|
+
*
|
|
9
|
+
* Injected once per document, under a single id, and tolerant of a non-DOM host.
|
|
10
|
+
*
|
|
11
|
+
* @module dsh-browser-reference/production/styles
|
|
12
|
+
*/
|
|
13
|
+
|
|
14
|
+
export const DOCK_STYLE_ID = 'dsh-browser-reference-styles'
|
|
15
|
+
|
|
16
|
+
/** Stylesheet text installed by {@link ensureDockStyles}. */
|
|
17
|
+
export const DOCK_CSS = `
|
|
18
|
+
/* Reply-side dsh-browser-ref: destinations rendered by an older markdown
|
|
19
|
+
bundle are ordinary anchors. The link bridge intercepts them; these rules
|
|
20
|
+
only make the affordance readable and never change the host's own links. */
|
|
21
|
+
/* The sent message shows the SAME pill the composer showed: a reference must not
|
|
22
|
+
lose its shape once submitted. Values mirror ReferenceDock.module.css .chip —
|
|
23
|
+
26px tall, 999px radius, the same two theme tokens — so the two surfaces read
|
|
24
|
+
as one control. */
|
|
25
|
+
a[data-dsh-browser-ref] {
|
|
26
|
+
display: inline-flex; align-items: center; gap: 6px;
|
|
27
|
+
height: 26px; padding: 0 10px; box-sizing: border-box;
|
|
28
|
+
max-width: 100%; vertical-align: middle;
|
|
29
|
+
border: .5px solid var(--dsw-alias-border-l2, rgba(127,127,127,.35));
|
|
30
|
+
border-radius: 999px;
|
|
31
|
+
background: var(--dsw-alias-bg-multi-select, rgba(127,127,127,.14));
|
|
32
|
+
color: inherit; font: inherit; text-decoration: none;
|
|
33
|
+
cursor: pointer; transition: background 120ms ease, border-color 120ms ease;
|
|
34
|
+
}
|
|
35
|
+
a[data-dsh-browser-ref]:hover {
|
|
36
|
+
background: var(--dsw-alias-bg-layer-3, rgba(127,127,127,.22));
|
|
37
|
+
border-color: var(--dsw-alias-border-l3, rgba(127,127,127,.5));
|
|
38
|
+
text-decoration: none;
|
|
39
|
+
}
|
|
40
|
+
/* Sent messages render the source through BrowserRefLink, a button carrying this class. It gets
|
|
41
|
+
the SAME pill the composer chip uses (26px, 999px radius, one border + one fill token), so a
|
|
42
|
+
reference does not change shape when it is submitted. */
|
|
43
|
+
button.dsh-browser-ref-link {
|
|
44
|
+
display: inline-flex; align-items: center; gap: 6px;
|
|
45
|
+
height: 26px; padding: 0 10px; margin: 0 2px; box-sizing: border-box;
|
|
46
|
+
max-width: 100%; vertical-align: middle;
|
|
47
|
+
border: .5px solid var(--dsw-alias-border-l2, rgba(127,127,127,.35));
|
|
48
|
+
border-radius: 999px;
|
|
49
|
+
background: var(--dsw-alias-bg-multi-select, rgba(127,127,127,.14));
|
|
50
|
+
color: inherit; font: inherit; text-decoration: none;
|
|
51
|
+
cursor: pointer; transition: background 120ms ease, border-color 120ms ease;
|
|
52
|
+
}
|
|
53
|
+
button.dsh-browser-ref-link:hover {
|
|
54
|
+
background: var(--dsw-alias-bg-layer-3, rgba(127,127,127,.22));
|
|
55
|
+
border-color: var(--dsw-alias-border-l3, rgba(127,127,127,.5));
|
|
56
|
+
}
|
|
57
|
+
button.dsh-browser-ref-link:disabled { opacity: .6; cursor: not-allowed; }
|
|
58
|
+
button.dsh-browser-ref-link:focus-visible { outline: 2px solid color-mix(in srgb, #3b82f6 65%, transparent);
|
|
59
|
+
outline-offset: 2px; }
|
|
60
|
+
/* The numbered badge is the half the composer chip had and the sent pill did not. Same metrics as
|
|
61
|
+
ReferenceDock.module.css .badge: 18px pill, 11px semibold number, inverted label colour. */
|
|
62
|
+
button.dsh-browser-ref-link .dsh-browser-ref-badge {
|
|
63
|
+
flex: none; display: inline-grid; place-items: center; box-sizing: border-box;
|
|
64
|
+
min-width: 18px; height: 18px; padding: 0 5px; border-radius: 999px;
|
|
65
|
+
background: var(--dsw-alias-state-business-primary, #3b82f6);
|
|
66
|
+
color: var(--dsw-alias-label-primary-inverted, #fff);
|
|
67
|
+
font-size: 11px; font-weight: 600; line-height: 1;
|
|
68
|
+
}
|
|
69
|
+
button.dsh-browser-ref-link .dsh-browser-ref-label { min-width: 0; overflow: hidden;
|
|
70
|
+
text-overflow: ellipsis; white-space: nowrap; }
|
|
71
|
+
a[data-dsh-browser-ref="unavailable"] { cursor: not-allowed; opacity: .6; }
|
|
72
|
+
a[data-dsh-browser-ref]:focus-visible { outline: 2px solid color-mix(in srgb, #3b82f6 65%, transparent);
|
|
73
|
+
outline-offset: 2px; }
|
|
74
|
+
`
|
|
75
|
+
|
|
76
|
+
/**
|
|
77
|
+
* Install the stylesheet once per document.
|
|
78
|
+
*
|
|
79
|
+
* @param doc - the host document; omitted in a non-DOM host (tests, SSR).
|
|
80
|
+
*/
|
|
81
|
+
export function ensureDockStyles(doc: Document | undefined = typeof document === 'undefined' ? undefined : document): void {
|
|
82
|
+
if (doc === undefined) return
|
|
83
|
+
if (doc.getElementById(DOCK_STYLE_ID) !== null) return
|
|
84
|
+
const style = doc.createElement('style')
|
|
85
|
+
style.id = DOCK_STYLE_ID
|
|
86
|
+
style.textContent = DOCK_CSS
|
|
87
|
+
// A host UI served under `style-src 'nonce-…'` refuses an inline style element
|
|
88
|
+
// without the nonce; borrowing the document's own keeps the dock styled there.
|
|
89
|
+
let nonce: string | undefined
|
|
90
|
+
try {
|
|
91
|
+
const reference = typeof doc.querySelector === 'function'
|
|
92
|
+
? doc.querySelector('style[nonce], script[nonce]') as (HTMLElement & { nonce?: string }) | null
|
|
93
|
+
: null
|
|
94
|
+
nonce = reference?.nonce ?? reference?.getAttribute('nonce') ?? undefined
|
|
95
|
+
} catch {
|
|
96
|
+
nonce = undefined
|
|
97
|
+
}
|
|
98
|
+
if (nonce !== undefined && nonce !== '') style.setAttribute('nonce', nonce)
|
|
99
|
+
try {
|
|
100
|
+
;(doc.head ?? doc.documentElement).appendChild(style)
|
|
101
|
+
} catch {
|
|
102
|
+
// A document that refuses the node simply stays unstyled; never break the dock.
|
|
103
|
+
}
|
|
104
|
+
}
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
/** Browser-source markers are parsed by the host text registry, preserving React-owned nodes. */
|
|
2
|
+
import type { UserTextRule } from '@deepseek-ai/dsh-client-ui-conversation/client'
|
|
3
|
+
import { readComposerQuote, readSourceMarker, readSubmissionQuote } from './source-marker.ts'
|
|
4
|
+
|
|
5
|
+
declare module '@deepseek-ai/dsh-client-ui-conversation/client' {
|
|
6
|
+
interface UserTextDataMap {
|
|
7
|
+
'browser-ref': { readonly uri: string; readonly label: string }
|
|
8
|
+
}
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
function nearestMarkerForQuote(text: string, quoteStart: number, nextMarker: ReturnType<typeof readSourceMarker>) {
|
|
12
|
+
let previous: ReturnType<typeof readSourceMarker>
|
|
13
|
+
for (let cursor = 0; cursor < quoteStart;) {
|
|
14
|
+
const found = readSourceMarker(text, cursor)
|
|
15
|
+
if (found === undefined || found.start >= quoteStart) break
|
|
16
|
+
previous = found
|
|
17
|
+
cursor = found.end
|
|
18
|
+
}
|
|
19
|
+
return previous ?? nextMarker
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
/**
|
|
23
|
+
* Build the canonical source marker rule. When `hasDetail` is supplied, a quote whose
|
|
24
|
+
* archived reference was evicted keeps its readable body instead of collapsing to empty text.
|
|
25
|
+
*/
|
|
26
|
+
export function createBrowserSourceRule(
|
|
27
|
+
hasDetail?: (referenceId: string) => boolean,
|
|
28
|
+
): UserTextRule<'browser-ref'> {
|
|
29
|
+
return {
|
|
30
|
+
id: 'browser-ref',
|
|
31
|
+
order: -20,
|
|
32
|
+
match(text, from) {
|
|
33
|
+
const marker = readSourceMarker(text, from)
|
|
34
|
+
const composed = readComposerQuote(text, from)
|
|
35
|
+
if (composed !== undefined && (marker === undefined || composed.start <= marker.start)) {
|
|
36
|
+
if (hasDetail !== undefined && !hasDetail(composed.marker.referenceId)) {
|
|
37
|
+
return { id: 'text', start: composed.start, end: composed.markerLine,
|
|
38
|
+
data: { text: text.slice(composed.start, composed.markerLine), display: composed.body } }
|
|
39
|
+
}
|
|
40
|
+
return { id: 'browser-ref', start: composed.start, end: composed.end,
|
|
41
|
+
data: { uri: composed.marker.uri, label: composed.marker.label } }
|
|
42
|
+
}
|
|
43
|
+
const quote = readSubmissionQuote(text, from)
|
|
44
|
+
if (quote !== undefined && (marker === undefined || quote.start < marker.start)) {
|
|
45
|
+
let display = ''
|
|
46
|
+
if (hasDetail !== undefined) {
|
|
47
|
+
const associated = nearestMarkerForQuote(text, quote.start, marker)
|
|
48
|
+
if (associated === undefined || !hasDetail(associated.referenceId)) {
|
|
49
|
+
display = quote.body
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
return { id: 'text', start: quote.start, end: quote.end,
|
|
53
|
+
data: { text: text.slice(quote.start, quote.end), display } }
|
|
54
|
+
}
|
|
55
|
+
if (marker === undefined) return undefined
|
|
56
|
+
const line = text.lastIndexOf('\n', marker.start - 1) + 1
|
|
57
|
+
const start = line >= from && /^ {0,3}>[ \t]?$/u.test(text.slice(line, marker.start)) ? line : marker.start
|
|
58
|
+
return {
|
|
59
|
+
id: 'browser-ref', start, end: marker.end,
|
|
60
|
+
data: { uri: marker.uri, label: marker.label },
|
|
61
|
+
}
|
|
62
|
+
},
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
/** Match the next canonical source marker without changing the logged message. */
|
|
67
|
+
export const browserSourceRule: UserTextRule<'browser-ref'> = createBrowserSourceRule()
|
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Waitable, cancellable source-reveal contract (§14.1, B30/B37).
|
|
3
|
+
*
|
|
4
|
+
* Deliberately separate from `openUrl` / `Page.navigate`: the injected adapter
|
|
5
|
+
* only selects/locates/highlights an existing tab and must never reload the
|
|
6
|
+
* page. It does NOT reuse the synchronous `navigateTabIn` helper. A monotonic
|
|
7
|
+
* intent token guarantees a late result from an older click cannot steal the
|
|
8
|
+
* tab or scroll position back (B37).
|
|
9
|
+
*/
|
|
10
|
+
import type { RevealRequest, RevealResult, RevealStatus } from './types.ts'
|
|
11
|
+
|
|
12
|
+
export type RevealValidation = 'ok' | 'unknown-reference' | 'session-mismatch'
|
|
13
|
+
|
|
14
|
+
export interface RevealLocation {
|
|
15
|
+
readonly tabId?: string
|
|
16
|
+
readonly frameId?: string
|
|
17
|
+
readonly detail?: string
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
export interface RevealAdapter {
|
|
21
|
+
/** Cheap synchronous validation of session + reference ownership. */
|
|
22
|
+
validate(request: RevealRequest): RevealValidation
|
|
23
|
+
/** Async, abortable lookup; must not mutate page state. */
|
|
24
|
+
locate(request: RevealRequest, signal: AbortSignal): Promise<RevealLocation>
|
|
25
|
+
/** The only step allowed to switch/scroll/highlight; never calls openUrl/Page.navigate. */
|
|
26
|
+
apply(request: RevealRequest, location: RevealLocation): void | Promise<void>
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
export interface Revealer {
|
|
30
|
+
reveal(request: RevealRequest): Promise<RevealResult>
|
|
31
|
+
dispose(): void
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
export interface RevealerOptions {
|
|
35
|
+
readonly adapter: RevealAdapter
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
/**
|
|
39
|
+
* A locate failure that already knows which status it stands for.
|
|
40
|
+
*
|
|
41
|
+
* The plugin answers with a reason ("page-mismatch", "session-unavailable",
|
|
42
|
+
* "missing", …) that the person needs to act on; without carrying it through
|
|
43
|
+
* the generic `unavailable` branch every one of those read as "the sidebar is
|
|
44
|
+
* broken".
|
|
45
|
+
*/
|
|
46
|
+
export class RevealFailed extends Error {
|
|
47
|
+
readonly status: RevealStatus
|
|
48
|
+
constructor(status: RevealStatus, message?: string) {
|
|
49
|
+
super(message ?? status)
|
|
50
|
+
this.status = status
|
|
51
|
+
this.name = 'RevealFailed'
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
/**
|
|
56
|
+
* Read through a function: the signal may abort during `await`, so a prior
|
|
57
|
+
* `=== true` check must not be narrowed into "always false" for later reads.
|
|
58
|
+
*/
|
|
59
|
+
function isAborted(signal: AbortSignal | undefined): boolean {
|
|
60
|
+
return signal?.aborted === true
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
export function createRevealer(options: RevealerOptions): Revealer {
|
|
64
|
+
const adapter = options.adapter
|
|
65
|
+
let latest = 0
|
|
66
|
+
let disposed = false
|
|
67
|
+
|
|
68
|
+
return {
|
|
69
|
+
async reveal(request) {
|
|
70
|
+
if (disposed) return { status: 'unavailable', reason: 'revealer disposed' }
|
|
71
|
+
const callerSignal = request.signal
|
|
72
|
+
if (isAborted(callerSignal)) return { status: 'cancelled' }
|
|
73
|
+
const validation = adapter.validate(request)
|
|
74
|
+
if (validation !== 'ok') return { status: validation }
|
|
75
|
+
|
|
76
|
+
const token = ++latest
|
|
77
|
+
const controller = new AbortController()
|
|
78
|
+
const forward = (): void => { controller.abort() }
|
|
79
|
+
callerSignal?.addEventListener('abort', forward, { once: true })
|
|
80
|
+
|
|
81
|
+
let location: RevealLocation
|
|
82
|
+
try {
|
|
83
|
+
location = await adapter.locate(request, controller.signal)
|
|
84
|
+
} catch (cause: unknown) {
|
|
85
|
+
if (isAborted(controller.signal) || isAborted(callerSignal)) return { status: 'cancelled' }
|
|
86
|
+
// A typed failure names its own cause; anything else stays generic.
|
|
87
|
+
if (cause instanceof RevealFailed) return { status: cause.status, reason: cause.message }
|
|
88
|
+
return { status: 'unavailable', reason: cause instanceof Error ? cause.message : 'locate failed' }
|
|
89
|
+
} finally {
|
|
90
|
+
callerSignal?.removeEventListener('abort', forward)
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
// A newer intent or a cancellation invalidates this late result: do NOT
|
|
94
|
+
// call apply, so an old async result cannot switch or scroll the page.
|
|
95
|
+
if (token !== latest) return { status: 'superseded' }
|
|
96
|
+
if (isAborted(controller.signal) || isAborted(callerSignal)) return { status: 'cancelled' }
|
|
97
|
+
try {
|
|
98
|
+
await adapter.apply(request, location)
|
|
99
|
+
} catch (cause: unknown) {
|
|
100
|
+
return { status: 'unavailable', reason: cause instanceof Error ? cause.message : 'apply failed' }
|
|
101
|
+
}
|
|
102
|
+
return { status: 'revealed' }
|
|
103
|
+
},
|
|
104
|
+
dispose() {
|
|
105
|
+
disposed = true
|
|
106
|
+
latest += 1
|
|
107
|
+
},
|
|
108
|
+
}
|
|
109
|
+
}
|