dsh-builtin-browser 0.5.5 → 0.5.7
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 +143 -1
- package/README.en.md +67 -97
- package/README.md +67 -98
- package/client.js +618 -263
- package/desktop-bridge/install.mjs +122 -33
- package/desktop-bridge/plugin-browser-bridge.js +9 -4
- package/docs/development.md +10 -0
- package/docs/tool-reference.md +20 -1
- package/docs/user-guide.md +16 -4
- package/lib/browser/runtime.d.ts +3 -1
- package/lib/browser/runtime.js +9 -0
- package/lib/browser/types.d.ts +42 -0
- package/lib/browser-electron/authenticated-route.d.ts +27 -0
- package/lib/browser-electron/authenticated-route.js +39 -0
- package/lib/browser-electron/bridge-connection.d.ts +8 -0
- package/lib/browser-electron/bridge-connection.js +8 -0
- package/lib/browser-electron/bridge-endpoint.d.ts +30 -0
- package/lib/browser-electron/bridge-endpoint.js +130 -0
- package/lib/browser-electron/bridge-install.d.ts +48 -0
- package/lib/browser-electron/bridge-install.js +98 -0
- package/lib/browser-electron/bridge-status.js +21 -2
- package/lib/browser-electron/desktop-bridge-host.d.ts +30 -27
- package/lib/browser-electron/desktop-bridge-host.js +71 -50
- package/lib/browser-electron/electron-provision.d.ts +35 -2
- package/lib/browser-electron/electron-provision.js +83 -20
- package/lib/browser-electron/entry.js +144 -7
- package/lib/browser-electron/host-main.js +48 -27
- package/lib/browser-electron/json-reply.d.ts +21 -0
- package/lib/browser-electron/json-reply.js +17 -0
- package/lib/browser-electron/preview-route.js +1 -12
- package/lib/browser-electron/provider.d.ts +9 -2
- package/lib/browser-electron/provider.js +76 -6
- package/lib/browser-electron/remote-host.js +10 -9
- package/lib/browser-electron/runtime-route.d.ts +55 -0
- package/lib/browser-electron/runtime-route.js +66 -0
- package/lib/browser-electron/runtime-status.d.ts +102 -0
- package/lib/browser-electron/runtime-status.js +88 -0
- package/lib/browser-electron/settings-route.d.ts +5 -18
- package/lib/browser-electron/settings-route.js +4 -14
- package/lib/browser-electron/settings-store.d.ts +17 -0
- package/lib/browser-electron/settings-store.js +24 -0
- package/lib/browser-electron/system-browser.d.ts +5 -2
- package/lib/browser-electron/system-browser.js +12 -4
- package/lib/tool-browser/index.js +1041 -4
- package/lib/tool-browser/page-probe.d.ts +86 -0
- package/lib/tool-browser/page-probe.js +460 -0
- package/package.json +5 -3
- package/scripts/consumer-install-check.mjs +72 -0
- package/scripts/verify-runtime-status.mjs +179 -0
- package/skills/dsh-builtin-browser/SKILL.md +64 -0
- package/skills/dsh-builtin-browser/references/batch.md +23 -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/src/browser/runtime.ts +11 -0
- package/src/browser/types.ts +19 -0
- package/src/browser-electron/authenticated-route.ts +56 -0
- package/src/browser-electron/bridge-connection.ts +9 -0
- package/src/browser-electron/bridge-endpoint.ts +146 -0
- package/src/browser-electron/bridge-install.ts +122 -0
- package/src/browser-electron/bridge-status.ts +22 -2
- package/src/browser-electron/desktop-bridge-host.ts +68 -50
- package/src/browser-electron/electron-provision.ts +103 -20
- package/src/browser-electron/entry.ts +141 -7
- package/src/browser-electron/host-main.ts +41 -22
- package/src/browser-electron/json-reply.ts +32 -0
- package/src/browser-electron/preview-route.ts +1 -12
- package/src/browser-electron/provider.ts +90 -6
- package/src/browser-electron/remote-host.ts +10 -9
- package/src/browser-electron/runtime-route.ts +104 -0
- package/src/browser-electron/runtime-status.ts +188 -0
- package/src/browser-electron/settings-route.ts +9 -32
- package/src/browser-electron/settings-store.ts +39 -0
- package/src/browser-electron/system-browser.ts +9 -3
- package/src/tool-browser/index.ts +991 -7
- package/src/tool-browser/page-probe.ts +474 -0
package/client.js
CHANGED
|
@@ -34,6 +34,13 @@ window.__ModuleLoader__.load({ id: "dsh-builtin-browser", factory: (require) =>
|
|
|
34
34
|
* host without one.
|
|
35
35
|
*/
|
|
36
36
|
let refreshWatchEntry = () => {}
|
|
37
|
+
/**
|
|
38
|
+
* Re-apply the locale to the watch panel's static labels.
|
|
39
|
+
*
|
|
40
|
+
* Set by `installWatchPanel`, called from the locale subscription in `apply()`. Separate from
|
|
41
|
+
* {@link refreshWatchEntry} because a language switch must not re-probe or re-mount anything.
|
|
42
|
+
*/
|
|
43
|
+
let refreshWatchLabels = () => {}
|
|
37
44
|
|
|
38
45
|
const zh = {
|
|
39
46
|
nav: "浏览器",
|
|
@@ -50,55 +57,84 @@ window.__ModuleLoader__.load({ id: "dsh-builtin-browser", factory: (require) =>
|
|
|
50
57
|
"watch.noPage": "该任务尚未打开浏览器",
|
|
51
58
|
"watch.bridgeStale": "桌面端升级后 bridge 已失效,请重跑安装:",
|
|
52
59
|
"watch.bridgeMissing": "桌面 bridge 未安装,侧栏载体不可用。安装命令:",
|
|
53
|
-
title: "浏览器
|
|
54
|
-
|
|
60
|
+
title: "浏览器",
|
|
61
|
+
"settings.advanced": "高级设置",
|
|
62
|
+
"settings.saving": "正在保存…",
|
|
63
|
+
"settings.details": "配置文件",
|
|
64
|
+
"browser.profile": "保留登录状态",
|
|
65
|
+
"browser.headless": "窗口模式",
|
|
66
|
+
"browser.headless.hint": "重启 DSH 后生效",
|
|
67
|
+
"browser.headless.auto": "自动检测显示环境",
|
|
68
|
+
"browser.headless.windowed": "显示窗口",
|
|
69
|
+
"browser.headless.headless": "无头运行",
|
|
70
|
+
"delivery.save": "保存交付设置",
|
|
71
|
+
"delivery.invalid": "检查工具名、参数模板和站点规则。参数必须是字符串值的 JSON 对象,站点规则每行填写一个 host=工具名。",
|
|
55
72
|
loading: "读取设置…",
|
|
56
73
|
failed: "读取设置失败:",
|
|
57
74
|
retry: "重试",
|
|
58
75
|
saved: "已保存",
|
|
59
|
-
path: "设置文件",
|
|
60
|
-
"history.title": "浏览历史",
|
|
61
76
|
"history.enabled": "保留浏览历史",
|
|
62
|
-
"history.hint": "记录访问过的页面;关闭浏览器后仍可查询并重新打开,关闭此开关后不再记录新访问。",
|
|
63
|
-
"cookies.title": "登录状态",
|
|
64
|
-
"cookies.persist": "保留 cookies",
|
|
65
|
-
"cookies.hint": "仅控制本机 Chrome / Edge 的独立 profile:关闭后下次启动使用临时 profile;需重新选择载体或重启 DSH。内置 Electron 与桌面侧栏的登录态由各自载体保存。",
|
|
66
77
|
"ui.title": "展示",
|
|
67
78
|
"ui.autoExpandOnce": "侧栏自动展开(每轮一次)",
|
|
68
|
-
"ui.autoExpandOnce.hint": "Agent 首次操作时自动展开;你手动收起后,本轮不再打扰。",
|
|
69
79
|
"ui.closeWithSession": "会话结束时关闭浏览器",
|
|
70
|
-
"ui.
|
|
71
|
-
"ui.virtualCursor": "显示可视化鼠标",
|
|
72
|
-
"ui.virtualCursor.hint": "让 Agent 正在操作的位置可见(出现即代表它在接管该标签页)。",
|
|
80
|
+
"ui.virtualCursor": "显示 Agent 光标",
|
|
73
81
|
"ui.quiet": "安静模式",
|
|
74
|
-
"ui.quiet.hint": "
|
|
75
|
-
"vision.
|
|
76
|
-
"vision.
|
|
77
|
-
"vision.
|
|
78
|
-
"vision.nonVisual": "纯非视觉(拒绝坐标点击,只用 DOM / 无障碍树定位)",
|
|
79
|
-
"vision.hint": "纯非视觉下,坐标点击会被明确拒绝并提示改用语义定位,避免靠猜坐标点错。两种策略下 DOM、无障碍树、文本提取与结构化抓取的能力完全一致 —— 不需要图像输入也能完整操作页面。",
|
|
80
|
-
"credentials.title": "凭据",
|
|
82
|
+
"ui.quiet.hint": "保留当前窗口和标签。新启动的 Chrome / Edge 在后台运行。",
|
|
83
|
+
"vision.strategy": "页面定位",
|
|
84
|
+
"vision.auto": "自动",
|
|
85
|
+
"vision.nonVisual": "仅按页面结构",
|
|
81
86
|
"credentials.allowRead": "允许 Agent 读取 cookies / 导出登录状态",
|
|
82
|
-
"browser.
|
|
83
|
-
"browser.
|
|
84
|
-
"browser.
|
|
85
|
-
"browser.bundled": "内置 Electron(随插件提供,无需安装)",
|
|
87
|
+
"browser.channel": "默认浏览器",
|
|
88
|
+
"browser.sidebar": "DSH 侧栏",
|
|
89
|
+
"browser.bundled": "内置浏览器",
|
|
86
90
|
"browser.chrome": "本机 Chrome",
|
|
87
91
|
"browser.edge": "本机 Edge",
|
|
88
|
-
"browser.auto": "自动
|
|
89
|
-
"
|
|
90
|
-
"credentials.hint": "关闭后 dsh_browser_auth 的导出会被拒绝,报 BROWSER_AUTH_DISABLED —— 导出读的是整台机器共享的 cookie 罐(按当前页所属站点收敛)。它只管**读**:写入登录状态(restore)归下面「Agent 能做什么」里的写入开关。桌面端请注意:Agent 驱动的是侧栏里那一个页面(人机同页),因此它与该页面共用同一个 partition —— 这也正是它能读到登录态的原因,属于有意接受的沙箱边界变化;关闭本项即拒绝读取。",
|
|
91
|
-
"actions.title": "Agent 能做什么",
|
|
92
|
-
"actions.lead": "与 dsh_browser_restrict 不同:那一层是模型自己设的软护栏,它随时可以解除;这里的三项由你在设置里决定,模型手里的工具改不了它们。",
|
|
92
|
+
"browser.auto": "自动",
|
|
93
|
+
"actions.title": "Agent 权限",
|
|
93
94
|
"actions.allowExecute": "允许在页面里执行脚本",
|
|
94
|
-
"actions.allowExecute.hint": "dsh_browser_execute 能在当前页面里运行任意 JavaScript —— 它的能力上限就是这个页面能做的事。关闭后该工具一律被拒(BROWSER_EXECUTE_DISABLED),模型手里的工具没有一个能改这项设置。但也别把它当成锁:设置文档由本机 HTTP 端点读写,同源页面可以写它 —— 这不是凭据系统。",
|
|
95
95
|
"actions.allowDownload": "允许下载文件到磁盘",
|
|
96
|
-
"actions.allowDownload.hint": "dsh_browser_download 会把 URL 下载到 downloadDir 内(带登录态;仍需通过目录准入,不覆盖已有文件)。关闭后一律被拒(BROWSER_DOWNLOAD_DISABLED)。截图另存走的是同一套目录准入,不受此项影响。",
|
|
97
96
|
"actions.allowCredentialWrite": "允许写入登录状态",
|
|
98
|
-
"actions.allowCredentialWrite.hint": "
|
|
99
|
-
"remoteView.
|
|
100
|
-
"remoteView.enabled": "
|
|
101
|
-
"
|
|
97
|
+
"actions.allowCredentialWrite.hint": "可向任意域写入 cookies。",
|
|
98
|
+
"remoteView.enabled": "允许远程观看",
|
|
99
|
+
"remoteView.enabled.hint": "共享只读画面,可能包含敏感信息。",
|
|
100
|
+
"readiness.title": "就绪状态",
|
|
101
|
+
"readiness.loading": "检测中…",
|
|
102
|
+
"readiness.failed": "读取就绪状态失败:",
|
|
103
|
+
"readiness.channel": "配置的载体",
|
|
104
|
+
"readiness.details": "诊断",
|
|
105
|
+
"readiness.electron": "内置浏览器运行时",
|
|
106
|
+
"readiness.bridge": "桌面侧栏 bridge",
|
|
107
|
+
"readiness.recheck": "重新检测",
|
|
108
|
+
"readiness.prepare": "准备内置浏览器",
|
|
109
|
+
"readiness.preparing": "正在准备…",
|
|
110
|
+
"readiness.fix": "修复命令",
|
|
111
|
+
"readiness.carrier.sidebar": "桌面侧栏",
|
|
112
|
+
"readiness.carrier.bundled": "内置 Electron",
|
|
113
|
+
"readiness.carrier.system": "本机 Chrome / Edge",
|
|
114
|
+
"readiness.carrier.auto": "自动",
|
|
115
|
+
"readiness.state.ready": "可用",
|
|
116
|
+
"readiness.state.blocked": "尚不可用",
|
|
117
|
+
"readiness.state.unknown": "需实际启动才能确定",
|
|
118
|
+
"readiness.electron.present": "已就绪",
|
|
119
|
+
"readiness.electron.ready": "已就绪",
|
|
120
|
+
"readiness.electron.preparing": "正在下载",
|
|
121
|
+
"readiness.electron.idle": "尚未开始准备",
|
|
122
|
+
"readiness.electron.skipped": "已跳过(设置了 ELECTRON_SKIP_BINARY_DOWNLOAD)",
|
|
123
|
+
"readiness.electron.failed": "准备失败",
|
|
124
|
+
"readiness.bridge.installed": "已安装",
|
|
125
|
+
"readiness.bridge.installedRunning": "已安装(桌面端正在运行)",
|
|
126
|
+
"readiness.bridge.installedNotRunning": "已安装,但桌面端没在运行",
|
|
127
|
+
"readiness.bridge.missing": "未安装",
|
|
128
|
+
"readiness.bridge.stale": "已失效(桌面端升级后需重装)",
|
|
129
|
+
"readiness.bridge.absent": "本机没有桌面端",
|
|
130
|
+
"delivery.title": "交付",
|
|
131
|
+
"delivery.tool": "接手下载的工具(MCP 工具名,留空=只存本地)",
|
|
132
|
+
"delivery.args": "参数模板(JSON)",
|
|
133
|
+
"delivery.args.hint": "占位 {path} {name} {size}。",
|
|
134
|
+
"delivery.onFail": "远程失败时",
|
|
135
|
+
"delivery.onFail.keep": "保留本地文件并报告两边结果",
|
|
136
|
+
"delivery.onFail.stop": "按失败处理",
|
|
137
|
+
"delivery.sites": "按站点覆盖(每行 host=工具名)",
|
|
102
138
|
}
|
|
103
139
|
|
|
104
140
|
const en = {
|
|
@@ -116,55 +152,84 @@ window.__ModuleLoader__.load({ id: "dsh-builtin-browser", factory: (require) =>
|
|
|
116
152
|
"watch.noPage": "This task has not opened a browser",
|
|
117
153
|
"watch.bridgeStale": "A desktop update invalidated the bridge; re-run:",
|
|
118
154
|
"watch.bridgeMissing": "The desktop bridge is not installed, so the sidebar carrier cannot work:",
|
|
119
|
-
title: "Browser
|
|
120
|
-
|
|
155
|
+
title: "Browser",
|
|
156
|
+
"settings.advanced": "Advanced settings",
|
|
157
|
+
"settings.saving": "Saving…",
|
|
158
|
+
"settings.details": "Configuration file",
|
|
159
|
+
"browser.profile": "Keep sign-ins",
|
|
160
|
+
"browser.headless": "Window mode",
|
|
161
|
+
"browser.headless.hint": "Requires restarting DSH",
|
|
162
|
+
"browser.headless.auto": "Detect display automatically",
|
|
163
|
+
"browser.headless.windowed": "Show a window",
|
|
164
|
+
"browser.headless.headless": "Run headless",
|
|
165
|
+
"delivery.save": "Save delivery settings",
|
|
166
|
+
"delivery.invalid": "Check tool names, the argument template, and site rules. Use a JSON object with string values and one host=tool rule per line.",
|
|
121
167
|
loading: "Loading settings…",
|
|
122
168
|
failed: "Could not load settings:",
|
|
123
169
|
retry: "Retry",
|
|
124
170
|
saved: "Saved",
|
|
125
|
-
path: "Settings file",
|
|
126
|
-
"history.title": "Browsing history",
|
|
127
171
|
"history.enabled": "Keep browsing history",
|
|
128
|
-
"history.hint": "Records visited pages so they can be found and reopened after the browser is closed; off means no new visits are recorded.",
|
|
129
|
-
"cookies.title": "Login state",
|
|
130
|
-
"cookies.persist": "Keep cookies",
|
|
131
|
-
"cookies.hint": "Controls only the separate Chrome / Edge profile: off uses a temporary profile on the next launch. Reselect the carrier or restart DSH. Bundled Electron and the desktop sidebar retain login state through their own carrier.",
|
|
132
172
|
"ui.title": "Presentation",
|
|
133
173
|
"ui.autoExpandOnce": "Auto-expand the side panel (once per task)",
|
|
134
|
-
"ui.autoExpandOnce.hint": "Expands when the agent first operates; after you collapse it, this task stays quiet.",
|
|
135
174
|
"ui.closeWithSession": "Close the browser when the session ends",
|
|
136
|
-
"ui.
|
|
137
|
-
"ui.virtualCursor": "Show the synthetic cursor",
|
|
138
|
-
"ui.virtualCursor.hint": "Makes the agent's operating position visible (its presence means the agent has taken over that tab).",
|
|
175
|
+
"ui.virtualCursor": "Show agent cursor",
|
|
139
176
|
"ui.quiet": "Quiet mode",
|
|
140
|
-
"ui.quiet.hint": "
|
|
141
|
-
"vision.
|
|
142
|
-
"vision.
|
|
143
|
-
"vision.
|
|
144
|
-
"vision.nonVisual": "Non-visual only (coordinate clicks refused; locate via DOM / a11y tree)",
|
|
145
|
-
"vision.hint": "Under non-visual, a coordinate click is refused outright and the error says to use a semantic target — so nothing is clicked on a guessed position. DOM lookup, the accessibility tree, text extraction and structured scraping behave identically in both strategies: the whole page stays operable without image input.",
|
|
146
|
-
"credentials.title": "Credentials",
|
|
177
|
+
"ui.quiet.hint": "Keeps your current window and tab. New Chrome / Edge instances run in the background.",
|
|
178
|
+
"vision.strategy": "Page targeting",
|
|
179
|
+
"vision.auto": "Automatic",
|
|
180
|
+
"vision.nonVisual": "Page structure only",
|
|
147
181
|
"credentials.allowRead": "Allow the agent to read cookies / export login state",
|
|
148
|
-
"browser.
|
|
149
|
-
"browser.
|
|
150
|
-
|
|
151
|
-
"browser.bundled": "Bundled Electron (ships with the plugin, nothing to install)",
|
|
182
|
+
"browser.channel": "Default browser",
|
|
183
|
+
"browser.sidebar": "DSH sidebar",
|
|
184
|
+
"browser.bundled": "Bundled browser",
|
|
152
185
|
"browser.chrome": "Installed Chrome",
|
|
153
186
|
"browser.edge": "Installed Edge",
|
|
154
|
-
"browser.auto": "Automatic
|
|
155
|
-
"
|
|
156
|
-
"credentials.hint": "Off makes dsh_browser_auth refuse the export, reporting BROWSER_AUTH_DISABLED — an export reads the machine-wide shared cookie jar (narrowed to the current page's site). It governs READING only: writing login state (restore) answers to the write switch under \"What the agent may do\" below. On the desktop, note that the agent drives the sidebar's own page (one page for both parties), so it shares that page's partition — which is exactly why it can reach the login state. That is a deliberate sandbox-boundary change; this switch is how you refuse it.",
|
|
157
|
-
"actions.title": "What the agent may do",
|
|
158
|
-
"actions.lead": "Unlike dsh_browser_restrict, which is the model's own soft guardrail and can be lifted by the model at any time, these three are yours: the model's own tools cannot change them.",
|
|
187
|
+
"browser.auto": "Automatic",
|
|
188
|
+
"actions.title": "Agent permissions",
|
|
159
189
|
"actions.allowExecute": "Run scripts in the page",
|
|
160
|
-
"actions.allowExecute.hint": "dsh_browser_execute runs arbitrary JavaScript in the active tab — its reach is everything that page can do. Off refuses the tool outright (BROWSER_EXECUTE_DISABLED), and no tool the model holds can change this setting. Do not read that as a lock, though: the document is served over a local HTTP endpoint and a same-origin page can write it. This is not a credential system.",
|
|
161
190
|
"actions.allowDownload": "Download files to disk",
|
|
162
|
-
"actions.allowDownload.hint": "dsh_browser_download fetches a URL into downloadDir (with login state; still subject to the directory admission gate, never overwriting an existing file). Off refuses it outright (BROWSER_DOWNLOAD_DISABLED). Saving a screenshot goes through the same directory gate and is not covered by this switch.",
|
|
163
191
|
"actions.allowCredentialWrite": "Write login state",
|
|
164
|
-
"actions.allowCredentialWrite.hint": "
|
|
165
|
-
"remoteView.
|
|
166
|
-
"remoteView.enabled": "
|
|
167
|
-
"
|
|
192
|
+
"actions.allowCredentialWrite.hint": "Write cookies to any domain.",
|
|
193
|
+
"remoteView.enabled": "Allow remote viewing",
|
|
194
|
+
"remoteView.enabled.hint": "Shares a read-only view that may contain sensitive information.",
|
|
195
|
+
"readiness.title": "Readiness",
|
|
196
|
+
"readiness.loading": "Checking…",
|
|
197
|
+
"readiness.failed": "Could not read readiness:",
|
|
198
|
+
"readiness.channel": "Configured carrier",
|
|
199
|
+
"readiness.details": "Diagnostics",
|
|
200
|
+
"readiness.electron": "Bundled browser runtime",
|
|
201
|
+
"readiness.bridge": "Desktop sidebar bridge",
|
|
202
|
+
"readiness.recheck": "Check again",
|
|
203
|
+
"readiness.prepare": "Prepare the bundled browser",
|
|
204
|
+
"readiness.preparing": "Preparing…",
|
|
205
|
+
"readiness.fix": "Repair command",
|
|
206
|
+
"readiness.carrier.sidebar": "Desktop sidebar",
|
|
207
|
+
"readiness.carrier.bundled": "Bundled Electron",
|
|
208
|
+
"readiness.carrier.system": "Installed Chrome / Edge",
|
|
209
|
+
"readiness.carrier.auto": "Automatic",
|
|
210
|
+
"readiness.state.ready": "Ready",
|
|
211
|
+
"readiness.state.blocked": "Not ready yet",
|
|
212
|
+
"readiness.state.unknown": "Only a real launch can tell",
|
|
213
|
+
"readiness.electron.present": "Ready",
|
|
214
|
+
"readiness.electron.ready": "Ready",
|
|
215
|
+
"readiness.electron.preparing": "Downloading",
|
|
216
|
+
"readiness.electron.idle": "Not prepared yet",
|
|
217
|
+
"readiness.electron.skipped": "Skipped (ELECTRON_SKIP_BINARY_DOWNLOAD is set)",
|
|
218
|
+
"readiness.electron.failed": "Preparation failed",
|
|
219
|
+
"readiness.bridge.installed": "Installed",
|
|
220
|
+
"readiness.bridge.installedRunning": "Installed (the desktop app is running)",
|
|
221
|
+
"readiness.bridge.installedNotRunning": "Installed, but the desktop app is not running",
|
|
222
|
+
"readiness.bridge.missing": "Not installed",
|
|
223
|
+
"readiness.bridge.stale": "Stale (a desktop update needs a reinstall)",
|
|
224
|
+
"readiness.bridge.absent": "No desktop install on this machine",
|
|
225
|
+
"delivery.title": "Delivery",
|
|
226
|
+
"delivery.tool": "Tool that takes the download (MCP tool name; empty = local only)",
|
|
227
|
+
"delivery.args": "Argument template (JSON)",
|
|
228
|
+
"delivery.args.hint": "Placeholders: {path} {name} {size}.",
|
|
229
|
+
"delivery.onFail": "When the remote side fails",
|
|
230
|
+
"delivery.onFail.keep": "Keep the local file and report both outcomes",
|
|
231
|
+
"delivery.onFail.stop": "Treat it as a failure",
|
|
232
|
+
"delivery.sites": "Per-site override (one host=tool per line)",
|
|
168
233
|
}
|
|
169
234
|
|
|
170
235
|
/**
|
|
@@ -202,6 +267,78 @@ window.__ModuleLoader__.load({ id: "dsh-builtin-browser", factory: (require) =>
|
|
|
202
267
|
* under a third-party theme, and an unstyled row is worse than a slightly-off one.
|
|
203
268
|
*/
|
|
204
269
|
const CSS = `
|
|
270
|
+
.dsh-bb-settings .dsh-bb-row {
|
|
271
|
+
min-height: 36px;
|
|
272
|
+
align-items: center;
|
|
273
|
+
justify-content: space-between;
|
|
274
|
+
padding: 8px 0;
|
|
275
|
+
border-bottom: .5px solid var(--dsw-alias-border-l2, GrayText);
|
|
276
|
+
border-radius: 0;
|
|
277
|
+
background: transparent;
|
|
278
|
+
}
|
|
279
|
+
.dsh-bb-settings { font-size: 14px; line-height: 22px; }
|
|
280
|
+
.dsh-bb-settings .dsh-bb-diagnostics { margin-top: 4px; }
|
|
281
|
+
.dsh-bb-diagnostics code { display: block; }
|
|
282
|
+
.dsh-bb-toggle { justify-content: space-between; cursor: pointer; }
|
|
283
|
+
.dsh-bb-toggle:has(:disabled) { cursor: default; }
|
|
284
|
+
.dsh-bb-switch {
|
|
285
|
+
appearance: none;
|
|
286
|
+
position: relative;
|
|
287
|
+
flex: 0 0 36px;
|
|
288
|
+
width: 36px;
|
|
289
|
+
height: 20px;
|
|
290
|
+
margin: 0;
|
|
291
|
+
box-sizing: border-box;
|
|
292
|
+
border: 0;
|
|
293
|
+
border-radius: 999px;
|
|
294
|
+
corner-shape: round;
|
|
295
|
+
background: var(--dsw-alias-border-l3, GrayText);
|
|
296
|
+
color: var(--dsw-alias-switch-thumb, Canvas);
|
|
297
|
+
cursor: inherit;
|
|
298
|
+
}
|
|
299
|
+
.dsh-bb-switch::after {
|
|
300
|
+
content: "";
|
|
301
|
+
position: absolute;
|
|
302
|
+
inset: 2px auto auto 2px;
|
|
303
|
+
width: 16px;
|
|
304
|
+
height: 16px;
|
|
305
|
+
border-radius: 50%;
|
|
306
|
+
corner-shape: round;
|
|
307
|
+
background: currentColor;
|
|
308
|
+
}
|
|
309
|
+
.dsh-bb-switch:checked {
|
|
310
|
+
background: var(--dsw-alias-brand-primary, Highlight);
|
|
311
|
+
color: var(--dsw-alias-label-primary-foreground, HighlightText);
|
|
312
|
+
}
|
|
313
|
+
.dsh-bb-switch:checked::after { transform: translateX(16px); }
|
|
314
|
+
.dsh-bb-switch:disabled { opacity: .6; }
|
|
315
|
+
.dsh-bb-settings :is(button, input, textarea, select, summary):focus-visible {
|
|
316
|
+
outline: var(--dsw-focus-ring-width, 2px) solid var(--dsw-focus-ring-color, Highlight);
|
|
317
|
+
outline-offset: 2px;
|
|
318
|
+
}
|
|
319
|
+
.dsh-bb-settings summary { cursor: pointer; padding: 5px 0; }
|
|
320
|
+
.dsh-bb-settings .dsh-bb-dd { flex: 0 1 auto; margin: 0; }
|
|
321
|
+
.dsh-bb-settings .dsh-bb-dd-btn {
|
|
322
|
+
min-height: 36px;
|
|
323
|
+
padding: 0 14px;
|
|
324
|
+
border: 0;
|
|
325
|
+
border-radius: var(--dsw-radius-md, 8px);
|
|
326
|
+
background: var(--dsw-alias-bg-module-platform, ButtonFace);
|
|
327
|
+
}
|
|
328
|
+
.dsh-bb-settings .dsh-bb-dd-list { left: auto; right: 0; }
|
|
329
|
+
.dsh-bb-settings .dsh-bb-input {
|
|
330
|
+
box-sizing: border-box;
|
|
331
|
+
width: 100%;
|
|
332
|
+
min-height: 34px;
|
|
333
|
+
padding: 6px 8px;
|
|
334
|
+
border: 1px solid var(--dsw-alias-border, GrayText);
|
|
335
|
+
border-radius: 7px;
|
|
336
|
+
background: var(--dsw-alias-bg-layer-1, Canvas);
|
|
337
|
+
color: var(--dsw-alias-label-primary, CanvasText);
|
|
338
|
+
font: inherit;
|
|
339
|
+
}
|
|
340
|
+
.dsh-bb-settings fieldset { min-inline-size: 0; }
|
|
341
|
+
.dsh-bb-settings textarea { resize: vertical; }
|
|
205
342
|
.dsh-bb-row {
|
|
206
343
|
border-radius: 8px;
|
|
207
344
|
padding: 7px 9px;
|
|
@@ -358,18 +495,29 @@ window.__ModuleLoader__.load({ id: "dsh-builtin-browser", factory: (require) =>
|
|
|
358
495
|
}
|
|
359
496
|
|
|
360
497
|
const styles = {
|
|
361
|
-
wrap: { display: "flex", flexDirection: "column", gap: "
|
|
498
|
+
wrap: { display: "flex", flexDirection: "column", gap: "12px" },
|
|
362
499
|
lead: { opacity: 0.75, lineHeight: 1.6, margin: 0 },
|
|
363
|
-
group: {
|
|
364
|
-
groupTitle: { margin: "0 0
|
|
500
|
+
group: { minWidth: 0 },
|
|
501
|
+
groupTitle: { margin: "0 0 2px", fontSize: "14px", fontWeight: 600, color: "var(--dsw-alias-label-primary, inherit)" },
|
|
365
502
|
row: { display: "flex", gap: "10px", alignItems: "flex-start" },
|
|
366
|
-
box: { marginTop: "2px" },
|
|
367
503
|
label: { display: "flex", flexDirection: "column", gap: "2px", cursor: "pointer" },
|
|
368
|
-
hint: {
|
|
504
|
+
hint: { color: "var(--dsw-alias-label-tertiary, inherit)", fontSize: "12px", lineHeight: 1.5 },
|
|
369
505
|
status: { opacity: 0.7, minHeight: "18px" },
|
|
370
|
-
error: { color: "#
|
|
506
|
+
error: { color: "var(--dsw-alias-label-error, #c9342c)" },
|
|
371
507
|
pathLine: { opacity: 0.6, wordBreak: "break-all", lineHeight: 1.5 },
|
|
372
|
-
button: { padding: "
|
|
508
|
+
button: { minHeight: "32px", padding: "5px 12px", borderRadius: "8px", border: "1px solid var(--dsw-alias-border, rgba(128,128,128,.4))", background: "transparent", color: "inherit", font: "inherit", cursor: "pointer" },
|
|
509
|
+
// Readiness: one headline state, three one-line facts, and at most two buttons. The colours are
|
|
510
|
+
// the only place this panel states an opinion, which is why they carry no text of their own —
|
|
511
|
+
// the label next to them is always a locale string.
|
|
512
|
+
badge: { display: "inline-block", padding: "1px 8px", marginRight: "8px", borderRadius: "10px", fontSize: "11px", lineHeight: 1.6, border: "1px solid transparent" },
|
|
513
|
+
badgeOk: { color: "#2f9e44", borderColor: "rgba(47,158,68,.5)", background: "rgba(47,158,68,.12)" },
|
|
514
|
+
badgeWarn: { color: "#e5534b", borderColor: "rgba(229,83,75,.5)", background: "rgba(229,83,75,.12)" },
|
|
515
|
+
badgeUnknown: { color: "#a0a0a8", borderColor: "rgba(160,160,168,.5)", background: "rgba(160,160,168,.12)" },
|
|
516
|
+
kv: { display: "grid", gridTemplateColumns: "auto 1fr", gap: "3px 12px", margin: "8px 0 0", fontSize: "12px" },
|
|
517
|
+
kvKey: { opacity: 0.68 },
|
|
518
|
+
kvVal: { lineHeight: 1.5 },
|
|
519
|
+
mono: { fontFamily: "ui-monospace, SFMono-Regular, Consolas, monospace", fontSize: "11px", whiteSpace: "pre-wrap", wordBreak: "break-all", background: "var(--dsw-alias-bg-layer-2, rgba(0,0,0,.22))", borderRadius: "5px", padding: "4px 6px", marginTop: "4px" },
|
|
520
|
+
buttons: { display: "flex", gap: "8px", alignItems: "center", marginTop: "10px", flexWrap: "wrap" },
|
|
373
521
|
}
|
|
374
522
|
|
|
375
523
|
/**
|
|
@@ -438,14 +586,18 @@ window.__ModuleLoader__.load({ id: "dsh-builtin-browser", factory: (require) =>
|
|
|
438
586
|
type: "button",
|
|
439
587
|
ref: buttonRef,
|
|
440
588
|
className: "dsh-bb-dd-btn",
|
|
589
|
+
"aria-label": props.label + ": " + (current?.label ?? ""),
|
|
441
590
|
disabled: props.disabled,
|
|
442
591
|
"aria-haspopup": "listbox",
|
|
443
592
|
"aria-expanded": open ? "true" : "false",
|
|
593
|
+
onBlur: event => {
|
|
594
|
+
if (!rootRef.current?.contains(event.relatedTarget)) setOpen(false)
|
|
595
|
+
},
|
|
444
596
|
onClick: () => { setOpen(o => !o); setActive(-1) },
|
|
445
597
|
onKeyDown,
|
|
446
598
|
}, [
|
|
447
599
|
h("span", { key: "v" }, current === undefined ? "" : current.label),
|
|
448
|
-
h("span", { key: "c", className: "dsh-bb-dd-caret", "aria-hidden": "true" }, "
|
|
600
|
+
h("span", { key: "c", className: "dsh-bb-dd-caret", "aria-hidden": "true" }, "\u25be"),
|
|
449
601
|
]),
|
|
450
602
|
open ? h("div", {
|
|
451
603
|
key: "l",
|
|
@@ -457,7 +609,9 @@ window.__ModuleLoader__.load({ id: "dsh-builtin-browser", factory: (require) =>
|
|
|
457
609
|
type: "button",
|
|
458
610
|
className: "dsh-bb-dd-opt",
|
|
459
611
|
role: "option",
|
|
612
|
+
tabIndex: -1,
|
|
460
613
|
"aria-selected": option.value === props.value ? "true" : "false",
|
|
614
|
+
onMouseDown: event => event.preventDefault(),
|
|
461
615
|
"data-active": index === active ? "true" : "false",
|
|
462
616
|
onMouseEnter: () => setActive(index),
|
|
463
617
|
onClick: () => commit(index),
|
|
@@ -468,30 +622,251 @@ window.__ModuleLoader__.load({ id: "dsh-builtin-browser", factory: (require) =>
|
|
|
468
622
|
/** One boolean switch bound to a settings path. */
|
|
469
623
|
function Toggle(props) {
|
|
470
624
|
const t = translate
|
|
471
|
-
return h("
|
|
625
|
+
return h("label", { style: styles.row, className: "dsh-bb-row dsh-bb-toggle" }, [
|
|
626
|
+
h("span", { key: "l", style: styles.label }, [
|
|
627
|
+
h("span", { key: "t" }, t(props.labelKey)),
|
|
628
|
+
props.hintKey ? h("span", { key: "h", style: styles.hint }, t(props.hintKey)) : null,
|
|
629
|
+
]),
|
|
472
630
|
h("input", {
|
|
473
631
|
key: "i",
|
|
474
632
|
type: "checkbox",
|
|
475
|
-
|
|
633
|
+
className: "dsh-bb-switch",
|
|
634
|
+
role: "switch",
|
|
635
|
+
"aria-label": t(props.labelKey),
|
|
476
636
|
checked: props.checked,
|
|
477
637
|
disabled: props.busy,
|
|
478
638
|
onChange: event => props.onChange(event.target.checked),
|
|
479
639
|
}),
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
640
|
+
])
|
|
641
|
+
}
|
|
642
|
+
|
|
643
|
+
/**
|
|
644
|
+
* Re-render this component when the interface language changes at run time.
|
|
645
|
+
*
|
|
646
|
+
* `translate` is a module-level binding that `apply()` re-binds on every locale snapshot, but
|
|
647
|
+
* React has no idea that happened: every label rendered so far keeps the language it was rendered
|
|
648
|
+
* in, which is exactly the defect the watch panel hit (#40) and the one commit `666cbff` fixed for
|
|
649
|
+
* that panel's DOM. The settings section is rendered by React, so it needs the notification rather
|
|
650
|
+
* than a text pass.
|
|
651
|
+
*/
|
|
652
|
+
let localeVersion = 0
|
|
653
|
+
const localeWatchers = new Set()
|
|
654
|
+
function useLocaleVersion() {
|
|
655
|
+
const [, setVersion] = useState(localeVersion)
|
|
656
|
+
useEffect(() => {
|
|
657
|
+
const update = () => setVersion(localeVersion)
|
|
658
|
+
localeWatchers.add(update)
|
|
659
|
+
return () => { localeWatchers.delete(update) }
|
|
660
|
+
}, [])
|
|
661
|
+
}
|
|
662
|
+
|
|
663
|
+
/**
|
|
664
|
+
* Readiness: can the browser serve a call right now, and what is missing if not.
|
|
665
|
+
*
|
|
666
|
+
* This is the "it works once you install it" promise, made visible. The bundled runtime downloads
|
|
667
|
+
* on first need (issue #41 moved the download out of `postinstall`), so on a fresh install the
|
|
668
|
+
* honest answer for the first minute is "a download is running" — a state that used to exist only
|
|
669
|
+
* in a log line. Everything shown here comes from `GET /runtime-status`; the button starts the
|
|
670
|
+
* same one background attempt the plugin makes on its own, which is why pressing it is never
|
|
671
|
+
* harmful and never starts a second download.
|
|
672
|
+
*/
|
|
673
|
+
function Readiness({ channel } = {}) {
|
|
674
|
+
useLocaleVersion()
|
|
675
|
+
const t = translate
|
|
676
|
+
const [runtime, setRuntime] = useState(null)
|
|
677
|
+
const [error, setError] = useState("")
|
|
678
|
+
const [unsupported, setUnsupported] = useState(false)
|
|
679
|
+
const [busy, setBusy] = useState(false)
|
|
680
|
+
const alive = useRef(true)
|
|
681
|
+
|
|
682
|
+
const read = useCallback(async () => {
|
|
683
|
+
try {
|
|
684
|
+
const response = await fetch("/dsh-builtin-browser/runtime-status", { headers: { accept: "application/json" } })
|
|
685
|
+
// A host that predates this route answers 404, and that is a version skew rather than a
|
|
686
|
+
// fault: after an update the client bundle is read at request time while the host's code is
|
|
687
|
+
// what started with the process. Rendering "could not read readiness: HTTP 404" at a user who
|
|
688
|
+
// simply has not restarted yet would be reporting the skew as their problem — so the section
|
|
689
|
+
// stays out of the way, exactly like a document with no `actions` section.
|
|
690
|
+
if (response.status === 404) {
|
|
691
|
+
if (alive.current) { setUnsupported(true); setRuntime(null); setError("") }
|
|
692
|
+
return null
|
|
693
|
+
}
|
|
694
|
+
if (!response.ok) throw new Error(`HTTP ${response.status}`)
|
|
695
|
+
const data = await response.json()
|
|
696
|
+
if (!alive.current) return null
|
|
697
|
+
setUnsupported(false)
|
|
698
|
+
setRuntime(data && data.runtime ? data.runtime : null)
|
|
699
|
+
setError("")
|
|
700
|
+
return data && data.runtime ? data.runtime : null
|
|
701
|
+
} catch (failure) {
|
|
702
|
+
if (!alive.current) return null
|
|
703
|
+
setError(String(failure && failure.message ? failure.message : failure))
|
|
704
|
+
return null
|
|
705
|
+
}
|
|
706
|
+
}, [])
|
|
707
|
+
|
|
708
|
+
useEffect(() => {
|
|
709
|
+
alive.current = true
|
|
710
|
+
void read()
|
|
711
|
+
return () => { alive.current = false }
|
|
712
|
+
}, [read, channel])
|
|
713
|
+
|
|
714
|
+
// Poll only while a download is running: that is the one state that changes on its own, and a
|
|
715
|
+
// poll in any other state would be a background request per panel per two seconds forever.
|
|
716
|
+
const preparing = runtime !== null && runtime.electron.state === "preparing"
|
|
717
|
+
useEffect(() => {
|
|
718
|
+
if (!preparing) return undefined
|
|
719
|
+
const timer = setTimeout(() => { void read() }, 2000)
|
|
720
|
+
return () => clearTimeout(timer)
|
|
721
|
+
}, [preparing, runtime, read])
|
|
722
|
+
|
|
723
|
+
const prepare = async () => {
|
|
724
|
+
setBusy(true)
|
|
725
|
+
setError("")
|
|
726
|
+
try {
|
|
727
|
+
const response = await fetch("/dsh-builtin-browser/runtime-provision", {
|
|
728
|
+
method: "POST",
|
|
729
|
+
headers: { accept: "application/json" },
|
|
730
|
+
})
|
|
731
|
+
const data = await response.json().catch(() => ({}))
|
|
732
|
+
if (!response.ok) throw new Error((data && data.error) || `HTTP ${response.status}`)
|
|
733
|
+
if (alive.current && data && data.runtime) setRuntime(data.runtime)
|
|
734
|
+
} catch (failure) {
|
|
735
|
+
if (alive.current) setError(String(failure && failure.message ? failure.message : failure))
|
|
736
|
+
} finally {
|
|
737
|
+
if (alive.current) setBusy(false)
|
|
738
|
+
void read()
|
|
739
|
+
}
|
|
740
|
+
}
|
|
741
|
+
|
|
742
|
+
if (unsupported) return null
|
|
743
|
+
if (runtime === null) {
|
|
744
|
+
return h("div", { style: styles.wrap }, [
|
|
745
|
+
h("p", { key: "l", style: styles.lead }, error === "" ? t("readiness.loading") : `${t("readiness.failed")} ${error}`),
|
|
746
|
+
])
|
|
747
|
+
}
|
|
748
|
+
|
|
749
|
+
const tone = runtime.readiness === "ready" ? styles.badgeOk
|
|
750
|
+
: runtime.readiness === "blocked" ? styles.badgeWarn : styles.badgeUnknown
|
|
751
|
+
const row = (key, label, value) => [
|
|
752
|
+
h("span", { key: `${key}-k`, style: styles.kvKey }, label),
|
|
753
|
+
h("span", { key: `${key}-v`, style: styles.kvVal }, value),
|
|
754
|
+
]
|
|
755
|
+
// "Installed" and "running" are different facts, and the gap between them is the most common
|
|
756
|
+
// broken state there is (the desktop app is simply closed). The row says which one it means —
|
|
757
|
+
// and when the host does not report the running half at all, it says the plain truth rather
|
|
758
|
+
// than inferring "not running" from an absent field.
|
|
759
|
+
const bridgeLabel = runtime.bridge.state !== "installed"
|
|
760
|
+
? t(`readiness.bridge.${runtime.bridge.state}`)
|
|
761
|
+
: runtime.bridge.running === true
|
|
762
|
+
? t("readiness.bridge.installedRunning")
|
|
763
|
+
: runtime.bridge.running === false
|
|
764
|
+
? t("readiness.bridge.installedNotRunning")
|
|
765
|
+
: t("readiness.bridge.installed")
|
|
766
|
+
|
|
767
|
+
return h("div", { style: styles.group }, [
|
|
768
|
+
h("div", { key: "head", className: "dsh-bb-row", style: styles.row }, [
|
|
769
|
+
h("span", { key: "title" }, t("readiness.title")),
|
|
770
|
+
h("span", { key: "state", role: "status", style: { ...styles.badge, ...tone } }, t(`readiness.state.${runtime.readiness}`)),
|
|
483
771
|
]),
|
|
772
|
+
h("details", { key: "diagnostics", className: "dsh-bb-diagnostics" }, [
|
|
773
|
+
h("summary", { key: "title", style: styles.hint }, t("readiness.details")),
|
|
774
|
+
h("div", { key: "kv", style: styles.kv }, [
|
|
775
|
+
...row("carrier", t("readiness.channel"), t(`readiness.carrier.${runtime.carrier}`)),
|
|
776
|
+
...row("electron", t("readiness.electron"), t(`readiness.electron.${runtime.electron.state}`)),
|
|
777
|
+
...row("bridge", t("readiness.bridge"), bridgeLabel),
|
|
778
|
+
]),
|
|
779
|
+
runtime.electron.state === "failed" || runtime.electron.state === "skipped"
|
|
780
|
+
? h("p", { key: "edetail", style: styles.hint }, runtime.electron.detail) : null,
|
|
781
|
+
runtime.bridge.state === "installed" && runtime.bridge.running === false
|
|
782
|
+
? h("p", { key: "bdetail", style: styles.hint }, runtime.bridge.runningDetail ?? runtime.bridge.detail) : null,
|
|
783
|
+
runtime.bridge.command && runtime.bridge.state !== "installed"
|
|
784
|
+
? h("p", { key: "command", style: styles.hint }, [
|
|
785
|
+
h("span", { key: "label" }, t("readiness.fix")),
|
|
786
|
+
h("code", { key: "value", style: styles.mono }, runtime.bridge.command),
|
|
787
|
+
]) : null,
|
|
788
|
+
h("button", {
|
|
789
|
+
key: "recheck",
|
|
790
|
+
type: "button",
|
|
791
|
+
style: styles.button,
|
|
792
|
+
disabled: busy || preparing,
|
|
793
|
+
onClick: () => { void read() },
|
|
794
|
+
}, t("readiness.recheck")),
|
|
795
|
+
]),
|
|
796
|
+
runtime.canProvision || preparing
|
|
797
|
+
? h("div", { key: "buttons", style: styles.buttons }, [
|
|
798
|
+
preparing ? h("span", { key: "progress", role: "status", style: styles.hint }, t("readiness.preparing")) : null,
|
|
799
|
+
runtime.canProvision ? h("button", { key: "prepare", type: "button", style: styles.button, disabled: busy, onClick: () => { void prepare() } }, t("readiness.prepare")) : null,
|
|
800
|
+
]) : null,
|
|
801
|
+
error !== "" ? h("p", { key: "error", role: "alert", style: styles.error }, t("readiness.failed") + " " + error) : null,
|
|
802
|
+
])
|
|
803
|
+
}
|
|
804
|
+
|
|
805
|
+
/** Save the delivery fields together so moving focus never writes a partial template. */
|
|
806
|
+
function DeliverySettings({ delivery, busy, onSave }) {
|
|
807
|
+
const t = translate
|
|
808
|
+
const [invalid, setInvalid] = useState(false)
|
|
809
|
+
const toolPattern = /^[A-Za-z0-9_.-]+$/
|
|
810
|
+
const submit = event => {
|
|
811
|
+
event.preventDefault()
|
|
812
|
+
const fields = event.currentTarget.elements
|
|
813
|
+
const tool = fields.namedItem("tool").value.trim()
|
|
814
|
+
const onFail = fields.namedItem("onFail").value
|
|
815
|
+
const rules = fields.namedItem("sites").value.split("\n").filter(line => line.trim() !== "")
|
|
816
|
+
const entries = rules.map(line => line.split("=").map(value => value.trim()))
|
|
817
|
+
let args
|
|
818
|
+
try {
|
|
819
|
+
args = JSON.parse(fields.namedItem("args").value)
|
|
820
|
+
} catch {
|
|
821
|
+
setInvalid(true)
|
|
822
|
+
return
|
|
823
|
+
}
|
|
824
|
+
if ((tool !== "" && !toolPattern.test(tool))
|
|
825
|
+
|| args === null || typeof args !== "object" || Array.isArray(args)
|
|
826
|
+
|| Object.values(args).some(value => typeof value !== "string")
|
|
827
|
+
|| entries.some(entry => entry.length !== 2 || !/^[A-Za-z0-9.-]+$/.test(entry[0]) || !toolPattern.test(entry[1]))) {
|
|
828
|
+
setInvalid(true)
|
|
829
|
+
return
|
|
830
|
+
}
|
|
831
|
+
const sites = Object.fromEntries(entries.map(([host, name]) => [host.toLowerCase(), name]))
|
|
832
|
+
if (Object.keys(sites).length !== entries.length) {
|
|
833
|
+
setInvalid(true)
|
|
834
|
+
return
|
|
835
|
+
}
|
|
836
|
+
setInvalid(false)
|
|
837
|
+
onSave({ tool, args, onFail, sites })
|
|
838
|
+
}
|
|
839
|
+
const field = (name, control) => h("label", { key: name, style: styles.label }, [
|
|
840
|
+
h("span", { key: "label" }, t("delivery." + name)),
|
|
841
|
+
control,
|
|
842
|
+
name === "args" ? h("span", { key: "hint", style: styles.hint }, t("delivery.args.hint")) : null,
|
|
843
|
+
])
|
|
844
|
+
return h("form", { onSubmit: submit }, [
|
|
845
|
+
h("fieldset", { key: "fields", disabled: busy, style: { border: 0, margin: 0, padding: 0, display: "grid", gap: "10px" } }, [
|
|
846
|
+
field("tool", h("input", { key: "control", name: "tool", className: "dsh-bb-input", defaultValue: delivery?.tool ?? "", placeholder: "lark_drive_upload" })),
|
|
847
|
+
field("args", h("textarea", { key: "control", name: "args", className: "dsh-bb-input", rows: 3, defaultValue: JSON.stringify(delivery?.args ?? { file_path: "{path}" }, null, 2) })),
|
|
848
|
+
field("onFail", h("select", { key: "control", name: "onFail", className: "dsh-bb-input", defaultValue: delivery?.onFail ?? "keep-local" }, [
|
|
849
|
+
h("option", { key: "keep", value: "keep-local" }, t("delivery.onFail.keep")),
|
|
850
|
+
h("option", { key: "stop", value: "stop" }, t("delivery.onFail.stop")),
|
|
851
|
+
])),
|
|
852
|
+
field("sites", h("textarea", { key: "control", name: "sites", className: "dsh-bb-input", rows: 3, defaultValue: Object.entries(delivery?.sites ?? {}).map(([host, tool]) => host + "=" + tool).join("\n") })),
|
|
853
|
+
h("div", { key: "actions" }, h("button", { type: "submit", style: styles.button }, t("delivery.save"))),
|
|
854
|
+
]),
|
|
855
|
+
invalid ? h("p", { key: "error", role: "alert", style: styles.error }, t("delivery.invalid")) : null,
|
|
484
856
|
])
|
|
485
857
|
}
|
|
486
858
|
|
|
487
859
|
/** The settings page section. */
|
|
488
860
|
function SettingsRoot() {
|
|
861
|
+
useLocaleVersion()
|
|
489
862
|
const t = translate
|
|
490
863
|
const [rawSettings, setSettings] = useState(null)
|
|
491
864
|
const [meta, setMeta] = useState({ path: "" })
|
|
492
865
|
const [error, setError] = useState("")
|
|
493
866
|
const [busy, setBusy] = useState(false)
|
|
494
867
|
const [saved, setSaved] = useState(false)
|
|
868
|
+
const saving = useRef(false)
|
|
869
|
+
const savedTimer = useRef(null)
|
|
495
870
|
|
|
496
871
|
const load = useCallback(() => {
|
|
497
872
|
setError("")
|
|
@@ -502,22 +877,31 @@ window.__ModuleLoader__.load({ id: "dsh-builtin-browser", factory: (require) =>
|
|
|
502
877
|
}, [])
|
|
503
878
|
|
|
504
879
|
useEffect(() => { load() }, [load])
|
|
880
|
+
useEffect(() => () => clearTimeout(savedTimer.current), [])
|
|
505
881
|
|
|
506
882
|
const patch = useCallback(next => {
|
|
883
|
+
if (saving.current) return
|
|
884
|
+
saving.current = true
|
|
885
|
+
clearTimeout(savedTimer.current)
|
|
886
|
+
setSaved(false)
|
|
507
887
|
setBusy(true)
|
|
508
888
|
setError("")
|
|
509
889
|
callSettings(next).then(data => {
|
|
510
890
|
setSettings(data.settings)
|
|
511
891
|
setSaved(true)
|
|
512
|
-
setTimeout(() => setSaved(false),
|
|
892
|
+
savedTimer.current = setTimeout(() => setSaved(false), 1800)
|
|
513
893
|
}).catch(failure => setError(String(failure && failure.message ? failure.message : failure)))
|
|
514
|
-
.
|
|
894
|
+
.finally(() => {
|
|
895
|
+
saving.current = false
|
|
896
|
+
setBusy(false)
|
|
897
|
+
})
|
|
515
898
|
}, [])
|
|
516
899
|
|
|
517
900
|
if (rawSettings === null) {
|
|
518
901
|
return h("div", { style: styles.wrap }, [
|
|
519
|
-
h("p", { key: "l", style: styles.lead }, t("loading")),
|
|
902
|
+
error === "" ? h("p", { key: "l", role: "status", style: styles.lead }, t("loading")) : null,
|
|
520
903
|
error !== "" ? h("p", { key: "e", style: styles.error }, `${t("failed")} ${error}`) : null,
|
|
904
|
+
error !== "" ? h("button", { key: "retry", type: "button", style: styles.button, onClick: load }, t("retry")) : null,
|
|
521
905
|
])
|
|
522
906
|
}
|
|
523
907
|
|
|
@@ -531,174 +915,76 @@ window.__ModuleLoader__.load({ id: "dsh-builtin-browser", factory: (require) =>
|
|
|
531
915
|
? { ...rawSettings, actions: { allowExecute: true, allowDownload: true, allowCredentialWrite: true } }
|
|
532
916
|
: rawSettings
|
|
533
917
|
|
|
534
|
-
const
|
|
535
|
-
|
|
918
|
+
const toggle = (group, key, labelKey = group + "." + key, hintKey) => h(Toggle, {
|
|
919
|
+
key,
|
|
920
|
+
labelKey,
|
|
921
|
+
hintKey,
|
|
922
|
+
checked: settings[group]?.[key] ?? (group === "cookies" && key === "persist"),
|
|
923
|
+
busy,
|
|
924
|
+
onChange: value => patch({ [group]: { [key]: value } }),
|
|
925
|
+
})
|
|
926
|
+
const selector = (labelKey, value, options, onChange, hintKey) => h("div", {
|
|
927
|
+
key: labelKey,
|
|
928
|
+
className: "dsh-bb-row",
|
|
929
|
+
style: styles.row,
|
|
930
|
+
}, [
|
|
931
|
+
h("span", { key: "text", style: styles.label }, [
|
|
932
|
+
h("span", { key: "label" }, t(labelKey)),
|
|
933
|
+
hintKey ? h("span", { key: "hint", style: styles.hint }, t(hintKey)) : null,
|
|
934
|
+
]),
|
|
935
|
+
h(Dropdown, { key: "select", label: t(labelKey), value, options, disabled: busy, onChange }),
|
|
936
|
+
])
|
|
937
|
+
const options = (prefix, values) => values.map(value => ({ value, label: t(prefix + value) }))
|
|
938
|
+
const section = (titleKey, children) => h("section", { key: titleKey, style: styles.group }, [
|
|
939
|
+
h("h3", { key: "title", style: styles.groupTitle }, t(titleKey)),
|
|
536
940
|
...children,
|
|
537
941
|
])
|
|
942
|
+
const systemBrowser = settings.browser.channel === "chrome" || settings.browser.channel === "edge"
|
|
538
943
|
|
|
539
|
-
return h("div", { style: styles.wrap }, [
|
|
540
|
-
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
key: "enabled",
|
|
545
|
-
labelKey: "history.enabled",
|
|
546
|
-
hintKey: "history.hint",
|
|
547
|
-
checked: settings.history.enabled,
|
|
548
|
-
busy,
|
|
549
|
-
onChange: value => patch({ history: { enabled: value } }),
|
|
550
|
-
}),
|
|
551
|
-
]),
|
|
552
|
-
|
|
553
|
-
section("cookies.title", [
|
|
554
|
-
h(Toggle, {
|
|
555
|
-
key: "persist",
|
|
556
|
-
labelKey: "cookies.persist",
|
|
557
|
-
hintKey: "cookies.hint",
|
|
558
|
-
checked: settings.cookies.persist,
|
|
559
|
-
busy,
|
|
560
|
-
onChange: value => patch({ cookies: { persist: value } }),
|
|
561
|
-
}),
|
|
562
|
-
]),
|
|
563
|
-
|
|
944
|
+
return h("div", { style: styles.wrap, className: "dsh-bb-settings" }, [
|
|
945
|
+
selector("browser.channel", settings.browser.channel,
|
|
946
|
+
options("browser.", ["bundled", "sidebar", "auto", "chrome", "edge"]),
|
|
947
|
+
channel => patch({ browser: { channel } })),
|
|
948
|
+
h(Readiness, { key: "readiness", channel: settings.browser.channel }),
|
|
564
949
|
section("ui.title", [
|
|
565
|
-
|
|
566
|
-
|
|
567
|
-
|
|
568
|
-
|
|
569
|
-
|
|
570
|
-
busy,
|
|
571
|
-
onChange: value => patch({ ui: { autoExpandOnce: value } }),
|
|
572
|
-
}),
|
|
573
|
-
h(Toggle, {
|
|
574
|
-
key: "closeWithSession",
|
|
575
|
-
labelKey: "ui.closeWithSession",
|
|
576
|
-
hintKey: "ui.closeWithSession.hint",
|
|
577
|
-
checked: settings.ui.closeWithSession,
|
|
578
|
-
busy,
|
|
579
|
-
onChange: value => patch({ ui: { closeWithSession: value } }),
|
|
580
|
-
}),
|
|
581
|
-
h(Toggle, {
|
|
582
|
-
key: "virtualCursor",
|
|
583
|
-
labelKey: "ui.virtualCursor",
|
|
584
|
-
hintKey: "ui.virtualCursor.hint",
|
|
585
|
-
checked: settings.ui.virtualCursor,
|
|
586
|
-
busy,
|
|
587
|
-
onChange: value => patch({ ui: { virtualCursor: value } }),
|
|
588
|
-
}),
|
|
589
|
-
h(Toggle, {
|
|
590
|
-
key: "quiet",
|
|
591
|
-
labelKey: "ui.quiet",
|
|
592
|
-
hintKey: "ui.quiet.hint",
|
|
593
|
-
checked: settings.ui.quiet,
|
|
594
|
-
busy,
|
|
595
|
-
onChange: value => patch({ ui: { quiet: value } }),
|
|
596
|
-
}),
|
|
597
|
-
]),
|
|
598
|
-
|
|
599
|
-
section("vision.title", [
|
|
600
|
-
h("div", { key: "row", style: styles.row, className: "dsh-bb-row" }, [
|
|
601
|
-
h("label", { key: "l", style: styles.label }, [
|
|
602
|
-
h("span", { key: "t" }, t("vision.strategy")),
|
|
603
|
-
h(Dropdown, {
|
|
604
|
-
key: "s",
|
|
605
|
-
label: t("vision.strategy"),
|
|
606
|
-
value: settings.vision.strategy,
|
|
607
|
-
disabled: busy,
|
|
608
|
-
onChange: value => patch({ vision: { strategy: value } }),
|
|
609
|
-
options: [
|
|
610
|
-
{ value: "auto", label: t("vision.auto") },
|
|
611
|
-
{ value: "nonVisual", label: t("vision.nonVisual") },
|
|
612
|
-
],
|
|
613
|
-
}),
|
|
614
|
-
h("span", { key: "h", style: styles.hint }, t("vision.hint")),
|
|
615
|
-
]),
|
|
616
|
-
]),
|
|
617
|
-
]),
|
|
618
|
-
|
|
619
|
-
section("browser.title", [
|
|
620
|
-
h("div", { key: "row", style: styles.row, className: "dsh-bb-row" }, [
|
|
621
|
-
h("label", { key: "l", style: styles.label }, [
|
|
622
|
-
h("span", { key: "t" }, t("browser.channel")),
|
|
623
|
-
h(Dropdown, {
|
|
624
|
-
key: "s",
|
|
625
|
-
label: t("browser.channel"),
|
|
626
|
-
value: settings.browser.channel,
|
|
627
|
-
disabled: busy,
|
|
628
|
-
onChange: value => patch({ browser: { channel: value } }),
|
|
629
|
-
options: [
|
|
630
|
-
{ value: "sidebar", label: t("browser.sidebar") },
|
|
631
|
-
{ value: "bundled", label: t("browser.bundled") },
|
|
632
|
-
{ value: "auto", label: t("browser.auto") },
|
|
633
|
-
{ value: "chrome", label: t("browser.chrome") },
|
|
634
|
-
{ value: "edge", label: t("browser.edge") },
|
|
635
|
-
],
|
|
636
|
-
}),
|
|
637
|
-
h("span", { key: "h", style: styles.hint }, t("browser.hint")),
|
|
638
|
-
]),
|
|
639
|
-
]),
|
|
950
|
+
toggle("ui", "quiet", "ui.quiet", "ui.quiet.hint"),
|
|
951
|
+
toggle("ui", "autoExpandOnce"),
|
|
952
|
+
toggle("ui", "closeWithSession"),
|
|
953
|
+
toggle("ui", "virtualCursor"),
|
|
954
|
+
toggle("remoteView", "enabled", "remoteView.enabled", "remoteView.enabled.hint"),
|
|
640
955
|
]),
|
|
641
|
-
|
|
642
956
|
section("actions.title", [
|
|
643
|
-
|
|
644
|
-
|
|
645
|
-
|
|
646
|
-
|
|
647
|
-
hintKey: "actions.allowExecute.hint",
|
|
648
|
-
checked: settings.actions.allowExecute,
|
|
649
|
-
busy,
|
|
650
|
-
onChange: value => patch({ actions: { allowExecute: value } }),
|
|
651
|
-
}),
|
|
652
|
-
h(Toggle, {
|
|
653
|
-
key: "allowDownload",
|
|
654
|
-
labelKey: "actions.allowDownload",
|
|
655
|
-
hintKey: "actions.allowDownload.hint",
|
|
656
|
-
checked: settings.actions.allowDownload,
|
|
657
|
-
busy,
|
|
658
|
-
onChange: value => patch({ actions: { allowDownload: value } }),
|
|
659
|
-
}),
|
|
660
|
-
h(Toggle, {
|
|
661
|
-
key: "allowCredentialWrite",
|
|
662
|
-
labelKey: "actions.allowCredentialWrite",
|
|
663
|
-
hintKey: "actions.allowCredentialWrite.hint",
|
|
664
|
-
checked: settings.actions.allowCredentialWrite,
|
|
665
|
-
busy,
|
|
666
|
-
onChange: value => patch({ actions: { allowCredentialWrite: value } }),
|
|
667
|
-
}),
|
|
668
|
-
]),
|
|
669
|
-
|
|
670
|
-
section("credentials.title", [
|
|
671
|
-
h(Toggle, {
|
|
672
|
-
key: "allowRead",
|
|
673
|
-
labelKey: "credentials.allowRead",
|
|
674
|
-
hintKey: "credentials.hint",
|
|
675
|
-
checked: settings.credentials.allowRead,
|
|
676
|
-
busy,
|
|
677
|
-
onChange: value => patch({ credentials: { allowRead: value } }),
|
|
678
|
-
}),
|
|
957
|
+
toggle("actions", "allowExecute"),
|
|
958
|
+
toggle("actions", "allowDownload"),
|
|
959
|
+
toggle("credentials", "allowRead"),
|
|
960
|
+
toggle("actions", "allowCredentialWrite", "actions.allowCredentialWrite", "actions.allowCredentialWrite.hint"),
|
|
679
961
|
]),
|
|
680
|
-
|
|
681
|
-
|
|
682
|
-
|
|
683
|
-
|
|
684
|
-
|
|
685
|
-
|
|
686
|
-
|
|
687
|
-
|
|
688
|
-
|
|
689
|
-
|
|
690
|
-
|
|
691
|
-
|
|
692
|
-
|
|
962
|
+
h("details", { key: "advanced", style: styles.group }, [
|
|
963
|
+
h("summary", { key: "title", style: styles.groupTitle }, t("settings.advanced")),
|
|
964
|
+
toggle("history", "enabled"),
|
|
965
|
+
selector("vision.strategy", settings.vision.strategy, [
|
|
966
|
+
{ value: "auto", label: t("vision.auto") },
|
|
967
|
+
{ value: "nonVisual", label: t("vision.nonVisual") },
|
|
968
|
+
], strategy => patch({ vision: { strategy } })),
|
|
969
|
+
systemBrowser ? toggle("cookies", "persist", "browser.profile") : null,
|
|
970
|
+
systemBrowser ? selector("browser.headless", settings.browser.headless ?? "auto",
|
|
971
|
+
options("browser.headless.", ["auto", "windowed", "headless"]),
|
|
972
|
+
headless => patch({ browser: { headless } }), "browser.headless.hint") : null,
|
|
973
|
+
settings.delivery ? section("delivery.title", [
|
|
974
|
+
h(DeliverySettings, {
|
|
975
|
+
key: JSON.stringify(settings.delivery),
|
|
976
|
+
delivery: settings.delivery,
|
|
977
|
+
busy,
|
|
978
|
+
onSave: delivery => patch({ delivery }),
|
|
979
|
+
}),
|
|
980
|
+
]) : null,
|
|
981
|
+
meta.path !== "" ? h("p", { key: "path", style: styles.pathLine }, t("settings.details") + " · " + meta.path) : null,
|
|
693
982
|
]),
|
|
694
|
-
|
|
695
|
-
|
|
696
|
-
saved ? h("span", { key: "s" }, t("saved")) : null,
|
|
983
|
+
h("div", { key: "status", style: styles.status, role: "status" }, [
|
|
984
|
+
busy || saved ? h("span", { key: "s" }, t(busy ? "settings.saving" : "saved")) : null,
|
|
697
985
|
error !== "" ? h("span", { key: "e", style: styles.error }, ` ${t("failed")} ${error} `) : null,
|
|
698
|
-
error !== "" ? h("button", { key: "r", style: styles.button, onClick: load }, t("retry")) : null,
|
|
986
|
+
error !== "" ? h("button", { key: "r", type: "button", style: styles.button, onClick: load }, t("retry")) : null,
|
|
699
987
|
]),
|
|
700
|
-
|
|
701
|
-
meta.path !== "" ? h("div", { key: "path", style: styles.pathLine }, `${t("path")}: ${meta.path}`) : null,
|
|
702
988
|
])
|
|
703
989
|
}
|
|
704
990
|
|
|
@@ -809,10 +1095,11 @@ window.__ModuleLoader__.load({ id: "dsh-builtin-browser", factory: (require) =>
|
|
|
809
1095
|
}
|
|
810
1096
|
|
|
811
1097
|
/** Read this conversation's current guest, preferring the one actually drawn. */
|
|
812
|
-
function guestStateFor(sessionId) {
|
|
1098
|
+
function guestStateFor(sessionId, tabId) {
|
|
813
1099
|
const roots = panelRootsFor(sessionId)
|
|
814
1100
|
if (roots === undefined ? tabStripFor(sessionId) === null : roots.length === 0) return { panel: false, guestId: null, url: "" }
|
|
815
|
-
const guests = guestsInPanel(sessionId)
|
|
1101
|
+
const guests = guestsInPanel(sessionId).filter(view => tabId === undefined
|
|
1102
|
+
|| tabIdOfElement(view, new Set([tabId]), roots) === tabId)
|
|
816
1103
|
if (guests.length === 0) return { panel: true, guestId: null, url: "" }
|
|
817
1104
|
// A sidebar keeps every tab mounted (`keepMounted`), so a background tab's guest is
|
|
818
1105
|
// in the tree too. Prefer the one with a drawn box; fall back to the newest.
|
|
@@ -864,6 +1151,7 @@ window.__ModuleLoader__.load({ id: "dsh-builtin-browser", factory: (require) =>
|
|
|
864
1151
|
*/
|
|
865
1152
|
function installPanelService(ctx) {
|
|
866
1153
|
let sidebarRight = null
|
|
1154
|
+
const pendingTabs = new Map()
|
|
867
1155
|
/** The shell's own navigation service: `openSession` is how it is asked to DISPLAY a conversation. */
|
|
868
1156
|
let uiWorkspace = null
|
|
869
1157
|
// `inject` is how a client plugin waits for a service to appear. A host that does not offer it
|
|
@@ -873,9 +1161,13 @@ window.__ModuleLoader__.load({ id: "dsh-builtin-browser", factory: (require) =>
|
|
|
873
1161
|
// with it, which is exactly the shape of regression this file has been bitten by before.
|
|
874
1162
|
if (typeof ctx.inject === "function") {
|
|
875
1163
|
ctx.inject(["sidebarRight"], (scope) => {
|
|
1164
|
+
if (sidebarRight !== scope.sidebarRight) pendingTabs.clear()
|
|
876
1165
|
sidebarRight = scope.sidebarRight
|
|
877
1166
|
scope.effect(() => () => {
|
|
878
|
-
if (sidebarRight === scope.sidebarRight)
|
|
1167
|
+
if (sidebarRight === scope.sidebarRight) {
|
|
1168
|
+
sidebarRight = null
|
|
1169
|
+
pendingTabs.clear()
|
|
1170
|
+
}
|
|
879
1171
|
}, "dsh-builtin-browser: conversation panel binding")
|
|
880
1172
|
})
|
|
881
1173
|
// A separate inject, deliberately: waiting for both services in one call would take the
|
|
@@ -963,7 +1255,7 @@ window.__ModuleLoader__.load({ id: "dsh-builtin-browser", factory: (require) =>
|
|
|
963
1255
|
* @returns what was asked for, so a caller can tell "expanded" from "already visible", and
|
|
964
1256
|
* `displayed` so it can tell "the shell is showing this conversation" from "it is not".
|
|
965
1257
|
*/
|
|
966
|
-
function revealPlacedPanel(sessionId, state) {
|
|
1258
|
+
function revealPlacedPanel(sessionId, state, tabId) {
|
|
967
1259
|
if (state.guestId !== null || sidebarRight === null) return {}
|
|
968
1260
|
const done = {}
|
|
969
1261
|
// Which conversation is the shell DISPLAYING? `screen()` answers it, and it is the question
|
|
@@ -1001,7 +1293,7 @@ window.__ModuleLoader__.load({ id: "dsh-builtin-browser", factory: (require) =>
|
|
|
1001
1293
|
}
|
|
1002
1294
|
try {
|
|
1003
1295
|
const tabs = typeof sidebarRight.tabsIn === "function" ? sidebarRight.tabsIn(sessionId) : []
|
|
1004
|
-
const page = Array.isArray(tabs) ? tabs.find(entry => entry !== null && typeof entry === "object" && entry.kind === "browser") : undefined
|
|
1296
|
+
const page = Array.isArray(tabs) ? tabs.find(entry => entry !== null && typeof entry === "object" && entry.kind === "browser" && entry.id === tabId) : undefined
|
|
1005
1297
|
if (page !== undefined && typeof sidebarRight.focus === "function") {
|
|
1006
1298
|
sidebarRight.focus(page.id)
|
|
1007
1299
|
done.focused = String(page.id)
|
|
@@ -1022,7 +1314,9 @@ window.__ModuleLoader__.load({ id: "dsh-builtin-browser", factory: (require) =>
|
|
|
1022
1314
|
if (sidebarRight === null || typeof sidebarRight.openTabIn !== "function") {
|
|
1023
1315
|
return { ok: false, reason: "the shell's sidebar service is not available", panel: false, guestId: null }
|
|
1024
1316
|
}
|
|
1025
|
-
const
|
|
1317
|
+
const address = url ? String(url) : ""
|
|
1318
|
+
const pending = pendingTabs.get(wanted)
|
|
1319
|
+
const state = guestStateFor(wanted, pending?.url === address && pending.scoped ? pending.id : undefined)
|
|
1026
1320
|
if (state.guestId !== null) {
|
|
1027
1321
|
return { ok: true, created: false, panel: true, guestId: state.guestId, url: state.url }
|
|
1028
1322
|
}
|
|
@@ -1042,15 +1336,37 @@ window.__ModuleLoader__.load({ id: "dsh-builtin-browser", factory: (require) =>
|
|
|
1042
1336
|
// (a public method) is what says whether it actually landed: `openTabIn` SILENTLY ignores a
|
|
1043
1337
|
// conversation whose store was never minted, and a silent no-op must never be reported as
|
|
1044
1338
|
// success.
|
|
1045
|
-
let
|
|
1046
|
-
try {
|
|
1047
|
-
|
|
1048
|
-
|
|
1049
|
-
|
|
1050
|
-
|
|
1339
|
+
let beforeTabs = []
|
|
1340
|
+
try { beforeTabs = Array.from(sidebarRight.tabsIn(wanted)) } catch {}
|
|
1341
|
+
const before = beforeTabs.length
|
|
1342
|
+
const beforeIds = new Set(beforeTabs.map(tab => tab.id))
|
|
1343
|
+
const remembered = pending?.url === address
|
|
1344
|
+
? beforeTabs.find(tab => tab.kind === "browser" && tab.id === pending.id)
|
|
1345
|
+
: undefined
|
|
1346
|
+
if (remembered === undefined) {
|
|
1347
|
+
try {
|
|
1348
|
+
sidebarRight.openTabIn(wanted, "browser", address ? { params: { url: address } } : {})
|
|
1349
|
+
} catch (error) {
|
|
1350
|
+
return { ok: false, reason: String((error && error.message) || error), panel: state.panel, guestId: null }
|
|
1351
|
+
}
|
|
1352
|
+
}
|
|
1353
|
+
let placedTabs = beforeTabs
|
|
1354
|
+
try { placedTabs = Array.from(sidebarRight.tabsIn(wanted)) } catch {}
|
|
1355
|
+
const placed = placedTabs.length
|
|
1356
|
+
const browserTabs = placedTabs.filter(tab => tab !== null && typeof tab === "object" && tab.kind === "browser")
|
|
1357
|
+
const added = browserTabs.filter(tab => !beforeIds.has(tab.id))
|
|
1358
|
+
const matching = browserTabs.filter(tab => address !== "" && (tab.params?.url === address || tab.url === address))
|
|
1359
|
+
// Multiple browser tabs use separate ids. Correlate this placement before revealing it.
|
|
1360
|
+
// Older shells deduplicate the browser kind, so their sole browser is unambiguous.
|
|
1361
|
+
const page = remembered
|
|
1362
|
+
?? (added.length === 1 ? added[0] : undefined)
|
|
1363
|
+
?? (matching.length === 1 ? matching[0] : undefined)
|
|
1364
|
+
?? (browserTabs.length === 1 ? browserTabs[0] : undefined)
|
|
1365
|
+
const scoped = browserTabs.length > 1 || panelRootsFor(wanted) !== undefined
|
|
1366
|
+
if (page !== undefined) pendingTabs.set(wanted, { id: page.id, url: address, scoped })
|
|
1367
|
+
if (page === undefined && browserTabs.length > 1) {
|
|
1368
|
+
return { ok: false, reason: "the shell did not identify which browser tab was placed", panel: state.panel, guestId: null }
|
|
1051
1369
|
}
|
|
1052
|
-
let placed = 0
|
|
1053
|
-
try { placed = sidebarRight.tabsIn(wanted).length } catch (error) { placed = before }
|
|
1054
1370
|
// `openTabIn` DEDUPLICATES, so "the count grew" is the wrong test for "is this
|
|
1055
1371
|
// conversation's surface mounted".
|
|
1056
1372
|
//
|
|
@@ -1085,20 +1401,24 @@ window.__ModuleLoader__.load({ id: "dsh-builtin-browser", factory: (require) =>
|
|
|
1085
1401
|
// Placing is not showing: ask the shell to expand the column and focus that tab, so the
|
|
1086
1402
|
// body (and with it the `<webview>`) actually gets created. Without this the caller polls
|
|
1087
1403
|
// a panel that can never answer, which is exactly what "produced no page" used to mean.
|
|
1088
|
-
const revealed = revealPlacedPanel(wanted, state)
|
|
1404
|
+
const revealed = revealPlacedPanel(wanted, state, page?.id)
|
|
1089
1405
|
return {
|
|
1090
1406
|
ok: true,
|
|
1091
1407
|
created: placed > before,
|
|
1092
1408
|
panel: state.panel,
|
|
1093
1409
|
guestId: null,
|
|
1094
1410
|
tabs: placed,
|
|
1411
|
+
...page === undefined || !scoped ? {} : { tabId: String(page.id) },
|
|
1095
1412
|
...switched ? { switched: true } : {},
|
|
1096
1413
|
...revealed,
|
|
1097
1414
|
}
|
|
1098
1415
|
},
|
|
1099
1416
|
/** Read-only: this conversation's current guest, if it has one. */
|
|
1100
|
-
panelGuest(sessionId) {
|
|
1101
|
-
return guestStateFor(
|
|
1417
|
+
panelGuest(sessionId, tabId) {
|
|
1418
|
+
return guestStateFor(
|
|
1419
|
+
typeof sessionId === "string" ? sessionId : "",
|
|
1420
|
+
typeof tabId === "string" && tabId !== "" ? tabId : undefined,
|
|
1421
|
+
)
|
|
1102
1422
|
},
|
|
1103
1423
|
/** All guest ids verified inside this conversation, including shell-created popup tabs. */
|
|
1104
1424
|
panelGuests(sessionId) {
|
|
@@ -1224,16 +1544,22 @@ window.__ModuleLoader__.load({ id: "dsh-builtin-browser", factory: (require) =>
|
|
|
1224
1544
|
// control and a permanent diagnostic call.
|
|
1225
1545
|
|
|
1226
1546
|
/** Localized text, falling back to the key so a missing entry is visible rather than blank. */
|
|
1547
|
+
// Localized text.
|
|
1548
|
+
//
|
|
1549
|
+
// The try/catch that used to sit here was dead code, as Mzy123l pointed out on #40: the locale
|
|
1550
|
+
// service does not throw on a missing entry — it returns the key. So a miss shows the key, which
|
|
1551
|
+
// is diagnostic, and an empty answer is the only case worth substituting.
|
|
1227
1552
|
const say = key => {
|
|
1228
|
-
|
|
1553
|
+
const text = translate(key)
|
|
1554
|
+
return typeof text === "string" && text !== "" ? text : key
|
|
1229
1555
|
}
|
|
1230
1556
|
|
|
1231
1557
|
/**
|
|
1232
1558
|
* Apply the current locale to every static label.
|
|
1233
1559
|
*
|
|
1234
|
-
* Called at mount and again once the dictionaries are bound. The panel
|
|
1235
|
-
* once, inside `apply()`, *before* `locale.register` had run — so the
|
|
1236
|
-
* `watch.title` as its title and the key was never replaced (issue #40).
|
|
1560
|
+
* Called at mount, after a locale change, and again once the dictionaries are bound. The panel
|
|
1561
|
+
* used to set these exactly once, inside `apply()`, *before* `locale.register` had run — so the
|
|
1562
|
+
* shipped build showed `watch.title` as its title and the key was never replaced (issue #40).
|
|
1237
1563
|
*/
|
|
1238
1564
|
const relabel = () => {
|
|
1239
1565
|
openLabel.textContent = say("watch.open")
|
|
@@ -1243,6 +1569,10 @@ window.__ModuleLoader__.load({ id: "dsh-builtin-browser", factory: (require) =>
|
|
|
1243
1569
|
openButton.title = say("watch.open")
|
|
1244
1570
|
}
|
|
1245
1571
|
relabel()
|
|
1572
|
+
// A runtime language switch must reach labels that are already on screen. `subscribe` fires on
|
|
1573
|
+
// every locale snapshot change — a switch, and also a late dictionary registration — which is
|
|
1574
|
+
// exactly the set of moments these four strings can go stale.
|
|
1575
|
+
refreshWatchLabels = () => { relabel() }
|
|
1246
1576
|
|
|
1247
1577
|
let mounted = false
|
|
1248
1578
|
/** Put the entry on the page. Idempotent, so a second enable cannot stack copies. */
|
|
@@ -1391,6 +1721,7 @@ window.__ModuleLoader__.load({ id: "dsh-builtin-browser", factory: (require) =>
|
|
|
1391
1721
|
stop()
|
|
1392
1722
|
unmount()
|
|
1393
1723
|
refreshWatchEntry = () => {}
|
|
1724
|
+
refreshWatchLabels = () => {}
|
|
1394
1725
|
}, "dsh-builtin-browser: live view panel")
|
|
1395
1726
|
|
|
1396
1727
|
/**
|
|
@@ -1468,7 +1799,31 @@ window.__ModuleLoader__.load({ id: "dsh-builtin-browser", factory: (require) =>
|
|
|
1468
1799
|
ctx.effect(() => ctx.locale.register(NS, { zh, en }), "dsh-builtin-browser: dictionaries")
|
|
1469
1800
|
const t = ctx.locale.bind(NS)
|
|
1470
1801
|
translate = t
|
|
1802
|
+
// A language switch has to reach text that is already on screen. `subscribe` fires on every
|
|
1803
|
+
// locale snapshot change (switch, and late dictionary registration); guarded, because a host
|
|
1804
|
+
// without it must still get the panel — the labels then simply keep their first language.
|
|
1805
|
+
if (typeof ctx.locale.subscribe === "function") {
|
|
1806
|
+
ctx.effect(() => {
|
|
1807
|
+
const off = ctx.locale.subscribe(() => {
|
|
1808
|
+
translate = ctx.locale.bind(NS)
|
|
1809
|
+
// Two audiences, one notification: the vanilla watch panel rewrites its own text, and the
|
|
1810
|
+
// React settings section re-renders (see `useLocaleVersion`). Bumping the counter here is
|
|
1811
|
+
// what makes `t()` inside a mounted component return the new language at all.
|
|
1812
|
+
localeVersion += 1
|
|
1813
|
+
for (const update of localeWatchers) update()
|
|
1814
|
+
refreshWatchLabels()
|
|
1815
|
+
})
|
|
1816
|
+
return () => { if (typeof off === "function") off() }
|
|
1817
|
+
}, "dsh-builtin-browser: locale changes")
|
|
1818
|
+
}
|
|
1471
1819
|
installWatchPanel(ctx)
|
|
1820
|
+
// Test seam. The readiness section is composed by the settings component, so a harness that
|
|
1821
|
+
// renders that component can see the element but never run it — and running it is what proves a
|
|
1822
|
+
// user reads a state label rather than `readiness.electron.failed`. Exported on the module rather
|
|
1823
|
+
// than published on `globalThis` (where the product's own `__dshBuiltinBrowser` lives, for the
|
|
1824
|
+
// shell's benefit): nothing in the product reads this name, and a page-level global would be a
|
|
1825
|
+
// side effect of shipping a test.
|
|
1826
|
+
exports.__readinessSection = Readiness
|
|
1472
1827
|
ctx.slots.inject("settings.section", () => ctx.slots.register({
|
|
1473
1828
|
name: "settings.section",
|
|
1474
1829
|
id: "dsh-builtin-browser",
|