dsh-plugin-browser4agent 0.0.0-stage → 0.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/LICENSE +21 -0
- package/README.md +54 -2
- package/cordis.patch.yml +3 -0
- package/icon.svg +9 -0
- package/lib/client.js +888 -0
- package/lib/index.js +218 -0
- package/lib/setup.js +902 -0
- package/locale/en.json +6 -0
- package/locale/zh.json +6 -0
- package/package.json +67 -4
package/lib/client.js
ADDED
|
@@ -0,0 +1,888 @@
|
|
|
1
|
+
window.__ModuleLoader__.load({
|
|
2
|
+
id: 'dsh-plugin-browser4agent',
|
|
3
|
+
factory: (require) => {
|
|
4
|
+
const module = { exports: {} };
|
|
5
|
+
const exports = module.exports;
|
|
6
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
7
|
+
|
|
8
|
+
const React = require('react');
|
|
9
|
+
const { useCallback, useEffect, useRef, useState } = React;
|
|
10
|
+
const h = React.createElement;
|
|
11
|
+
|
|
12
|
+
const NS = 'settings.browser4agent';
|
|
13
|
+
const STYLE_TAG_ID = 'dsh-plugin-browser4agent/styles.css';
|
|
14
|
+
|
|
15
|
+
const STORE_LINKS = {
|
|
16
|
+
chrome:
|
|
17
|
+
'https://chromewebstore.google.com/detail/cddjomjjojijahpjngcfebapepdecaff',
|
|
18
|
+
edge: 'https://microsoftedge.microsoft.com/addons/detail/kgofhkkibnooojbchfppjblmajdcboib',
|
|
19
|
+
firefox:
|
|
20
|
+
'https://addons.mozilla.org/firefox/addon/browser4agent@xianqiao.wang',
|
|
21
|
+
releases: 'https://github.com/mantou132/browser4agent/releases/latest',
|
|
22
|
+
repo: 'https://github.com/mantou132/browser4agent',
|
|
23
|
+
};
|
|
24
|
+
|
|
25
|
+
const DICTIONARIES = {
|
|
26
|
+
en: {
|
|
27
|
+
nav: 'Browser4Agent',
|
|
28
|
+
title: 'Browser4Agent',
|
|
29
|
+
subtitle:
|
|
30
|
+
'Let DeepSeek Harness use your real browser — existing tabs, logged-in sessions, site-specific page tools, and CDP debugging.',
|
|
31
|
+
loading: 'Checking Browser4Agent status…',
|
|
32
|
+
provisioningChecking: 'Checking local Browser4Agent setup…',
|
|
33
|
+
provisioningDownloading: 'Downloading Browser4Agent CLI…',
|
|
34
|
+
provisioningConfiguring:
|
|
35
|
+
'Configuring Native Messaging Host & DSH Skill…',
|
|
36
|
+
provisioningVerifying: 'Verifying setup…',
|
|
37
|
+
provisioningHint:
|
|
38
|
+
'First-time setup installs the Browser4Agent binary, registers browser Native Messaging Hosts, and installs the Skill automatically.',
|
|
39
|
+
errorTitle: 'Setup failed',
|
|
40
|
+
btnRetry: 'Retry Setup',
|
|
41
|
+
statusReady: 'Ready',
|
|
42
|
+
statusActionNeeded: 'Extension Needed',
|
|
43
|
+
statusSetupNeeded: 'Setup Incomplete',
|
|
44
|
+
statusToolError: 'Connection Error',
|
|
45
|
+
readyTitle: 'Browser is connected and ready',
|
|
46
|
+
readyDescTabs:
|
|
47
|
+
'Connected to your browser ({count} open tabs detected). DeepSeek Harness can now use Browser4Agent.',
|
|
48
|
+
readyDescSimple:
|
|
49
|
+
'Connected to your browser. DeepSeek Harness can now use Browser4Agent.',
|
|
50
|
+
notConnectedTitle: 'Install the browser extension to finish',
|
|
51
|
+
notConnectedDesc:
|
|
52
|
+
'Local setup is complete. Install the Browser4Agent extension in Chrome, Edge, or Firefox and keep your browser open — this page will detect it automatically.',
|
|
53
|
+
notConnectedTip:
|
|
54
|
+
'If you already installed the extension before this plugin finished setup, reload the extension or restart your browser once.',
|
|
55
|
+
watchingExtension: 'Waiting for browser extension connection…',
|
|
56
|
+
setupIncompleteTitle: 'Local setup is not complete yet',
|
|
57
|
+
setupIncompleteDesc:
|
|
58
|
+
'Click Re-run Setup below to automatically install the Browser4Agent CLI, Native Messaging Host, and DSH Skill.',
|
|
59
|
+
toolErrorTitle: 'Extension responded with an error',
|
|
60
|
+
installExtTitle: 'Install Browser Extension',
|
|
61
|
+
linkChrome: 'Chrome Web Store',
|
|
62
|
+
linkEdge: 'Edge Add-ons',
|
|
63
|
+
linkFirefox: 'Firefox Add-ons',
|
|
64
|
+
linkReleases: 'Manual Download',
|
|
65
|
+
linkDocs: 'GitHub',
|
|
66
|
+
checklistTitle: 'Local Environment',
|
|
67
|
+
btnRerunSetup: 'Re-run Setup',
|
|
68
|
+
btnWorking: 'Working…',
|
|
69
|
+
rowCliTitle: 'Browser4Agent CLI',
|
|
70
|
+
rowCliMissing: 'Not installed yet.',
|
|
71
|
+
rowNativeTitle: 'Native Messaging Host',
|
|
72
|
+
rowNativeOk: 'Registered for {browsers}',
|
|
73
|
+
rowNativeMissing: 'Not registered for any browser yet.',
|
|
74
|
+
rowSkillTitle: 'DSH Skill',
|
|
75
|
+
rowSkillMissing: 'Skill file not found.',
|
|
76
|
+
badgeOk: 'Installed',
|
|
77
|
+
badgeConfigured: 'Configured',
|
|
78
|
+
badgeMissing: 'Missing',
|
|
79
|
+
},
|
|
80
|
+
zh: {
|
|
81
|
+
nav: 'Browser4Agent 浏览器',
|
|
82
|
+
title: 'Browser4Agent 浏览器控制',
|
|
83
|
+
subtitle:
|
|
84
|
+
'让 DeepSeek Harness 直接使用你的真实浏览器——复用已登录会话、现有标签页、站点 Page Tools 与 CDP 调试。',
|
|
85
|
+
loading: '正在检测 Browser4Agent 状态…',
|
|
86
|
+
provisioningChecking: '正在检查本地 Browser4Agent 环境…',
|
|
87
|
+
provisioningDownloading: '正在自动下载 Browser4Agent CLI…',
|
|
88
|
+
provisioningConfiguring: '正在自动配置 Native Messaging Host 与 Skill…',
|
|
89
|
+
provisioningVerifying: '正在校验安装结果…',
|
|
90
|
+
provisioningHint:
|
|
91
|
+
'首次安装会自动下载 Browser4Agent、注册浏览器 Native Messaging Host 并写入 DSH Skill,无需手动敲命令。',
|
|
92
|
+
errorTitle: '自动初始化失败',
|
|
93
|
+
btnRetry: '重试',
|
|
94
|
+
statusReady: '已就绪',
|
|
95
|
+
statusActionNeeded: '请安装扩展',
|
|
96
|
+
statusSetupNeeded: '待配置',
|
|
97
|
+
statusToolError: '连接异常',
|
|
98
|
+
readyTitle: '浏览器扩展已连接,可以开始使用',
|
|
99
|
+
readyDescTabs:
|
|
100
|
+
'已成功连接本地浏览器(检测到 {count} 个打开的标签页),现在可以直接让 DeepSeek Harness 操作浏览器了。',
|
|
101
|
+
readyDescSimple:
|
|
102
|
+
'已成功连接本地浏览器,现在可以直接让 DeepSeek Harness 操作浏览器了。',
|
|
103
|
+
notConnectedTitle: '请安装浏览器扩展以完成连接',
|
|
104
|
+
notConnectedDesc:
|
|
105
|
+
'本地环境已自动配置完成。请前往下方商店为 Chrome、Edge 或 Firefox 安装 Browser4Agent 扩展并保持浏览器打开,安装后此处会自动检测并变为就绪。',
|
|
106
|
+
notConnectedTip:
|
|
107
|
+
'如果此前已装好扩展但仍未连接,请重新加载扩展或重启一次浏览器。',
|
|
108
|
+
watchingExtension: '正在自动检测浏览器扩展连接…',
|
|
109
|
+
setupIncompleteTitle: '本地组件尚未完成配置',
|
|
110
|
+
setupIncompleteDesc:
|
|
111
|
+
'点击下方「重新配置」自动安装 Browser4Agent CLI、Native Messaging Host 与 DSH Skill。',
|
|
112
|
+
toolErrorTitle: '已连接到扩展,但工具调用返回错误',
|
|
113
|
+
installExtTitle: '安装浏览器扩展',
|
|
114
|
+
linkChrome: 'Chrome 商店',
|
|
115
|
+
linkEdge: 'Edge 商店',
|
|
116
|
+
linkFirefox: 'Firefox 商店',
|
|
117
|
+
linkReleases: '手动下载',
|
|
118
|
+
linkDocs: 'GitHub',
|
|
119
|
+
checklistTitle: '本地组件状态',
|
|
120
|
+
btnRerunSetup: '重新配置',
|
|
121
|
+
btnWorking: '处理中…',
|
|
122
|
+
rowCliTitle: 'Browser4Agent CLI',
|
|
123
|
+
rowCliMissing: '尚未安装。',
|
|
124
|
+
rowNativeTitle: 'Native Messaging Host',
|
|
125
|
+
rowNativeOk: '已注册:{browsers}',
|
|
126
|
+
rowNativeMissing: '尚未注册浏览器通信配置。',
|
|
127
|
+
rowSkillTitle: 'DSH Skill',
|
|
128
|
+
rowSkillMissing: '尚未写入 Skill 文件。',
|
|
129
|
+
badgeOk: '已安装',
|
|
130
|
+
badgeConfigured: '已配置',
|
|
131
|
+
badgeMissing: '未配置',
|
|
132
|
+
},
|
|
133
|
+
};
|
|
134
|
+
|
|
135
|
+
const CSS_TEXT = `
|
|
136
|
+
.b4a-root {
|
|
137
|
+
display: flex;
|
|
138
|
+
flex-direction: column;
|
|
139
|
+
gap: 16px;
|
|
140
|
+
padding: 4px 0 24px;
|
|
141
|
+
color: var(--dsw-alias-label-primary, #111827);
|
|
142
|
+
font-size: 13px;
|
|
143
|
+
line-height: 1.5;
|
|
144
|
+
}
|
|
145
|
+
.b4a-title {
|
|
146
|
+
margin: 0 0 4px;
|
|
147
|
+
font-size: 16px;
|
|
148
|
+
font-weight: 600;
|
|
149
|
+
color: var(--dsw-alias-label-primary, #111827);
|
|
150
|
+
}
|
|
151
|
+
.b4a-subtitle {
|
|
152
|
+
margin: 0;
|
|
153
|
+
font-size: 13px;
|
|
154
|
+
color: var(--dsw-alias-label-secondary, #4b5563);
|
|
155
|
+
}
|
|
156
|
+
.b4a-card {
|
|
157
|
+
border-radius: var(--dsw-radius-xl, 14px);
|
|
158
|
+
background: var(--dsw-alias-settings-card-fill, rgba(127, 127, 127, 0.06));
|
|
159
|
+
border: 1px solid var(--dsw-alias-settings-card-stroke, rgba(127, 127, 127, 0.16));
|
|
160
|
+
padding: 16px;
|
|
161
|
+
display: flex;
|
|
162
|
+
flex-direction: column;
|
|
163
|
+
gap: 14px;
|
|
164
|
+
}
|
|
165
|
+
.b4a-desc {
|
|
166
|
+
margin: 0;
|
|
167
|
+
font-size: 12.5px;
|
|
168
|
+
color: var(--dsw-alias-label-tertiary, #6b7280);
|
|
169
|
+
word-break: break-word;
|
|
170
|
+
}
|
|
171
|
+
.b4a-desc code {
|
|
172
|
+
font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
|
|
173
|
+
font-size: 11.5px;
|
|
174
|
+
color: var(--dsw-alias-label-secondary, #374151);
|
|
175
|
+
background: var(--dsw-alias-interactive-bg-hover, rgba(127, 127, 127, 0.1));
|
|
176
|
+
padding: 1px 5px;
|
|
177
|
+
border-radius: 4px;
|
|
178
|
+
}
|
|
179
|
+
.b4a-provisioning {
|
|
180
|
+
display: flex;
|
|
181
|
+
flex-direction: column;
|
|
182
|
+
gap: 6px;
|
|
183
|
+
padding: 4px 0;
|
|
184
|
+
}
|
|
185
|
+
.b4a-provisioning-title {
|
|
186
|
+
display: flex;
|
|
187
|
+
align-items: center;
|
|
188
|
+
gap: 8px;
|
|
189
|
+
font-size: 13.5px;
|
|
190
|
+
font-weight: 500;
|
|
191
|
+
}
|
|
192
|
+
.b4a-watching {
|
|
193
|
+
display: inline-flex;
|
|
194
|
+
align-items: center;
|
|
195
|
+
gap: 7px;
|
|
196
|
+
margin-top: 2px;
|
|
197
|
+
font-size: 12px;
|
|
198
|
+
color: var(--dsw-alias-label-secondary, #4b5563);
|
|
199
|
+
}
|
|
200
|
+
.b4a-spinner {
|
|
201
|
+
width: 13px;
|
|
202
|
+
height: 13px;
|
|
203
|
+
border-radius: 999px;
|
|
204
|
+
border: 2px solid var(--dsw-alias-border-l3, rgba(127, 127, 127, 0.3));
|
|
205
|
+
border-top-color: var(--dsw-alias-button-primary-fill, #2563eb);
|
|
206
|
+
animation: b4a-spin 0.8s linear infinite;
|
|
207
|
+
flex-shrink: 0;
|
|
208
|
+
}
|
|
209
|
+
@keyframes b4a-spin {
|
|
210
|
+
to { transform: rotate(360deg); }
|
|
211
|
+
}
|
|
212
|
+
.b4a-banner {
|
|
213
|
+
border-radius: var(--dsw-radius-md, 8px);
|
|
214
|
+
padding: 10px 12px;
|
|
215
|
+
font-size: 12.5px;
|
|
216
|
+
line-height: 1.5;
|
|
217
|
+
display: flex;
|
|
218
|
+
align-items: center;
|
|
219
|
+
justify-content: space-between;
|
|
220
|
+
gap: 10px;
|
|
221
|
+
flex-wrap: wrap;
|
|
222
|
+
}
|
|
223
|
+
.b4a-banner-err {
|
|
224
|
+
background: rgba(239, 68, 68, 0.12);
|
|
225
|
+
border: 1px solid rgba(239, 68, 68, 0.32);
|
|
226
|
+
color: #ef4444;
|
|
227
|
+
}
|
|
228
|
+
.b4a-hero {
|
|
229
|
+
display: flex;
|
|
230
|
+
flex-direction: column;
|
|
231
|
+
gap: 6px;
|
|
232
|
+
}
|
|
233
|
+
.b4a-hero-title {
|
|
234
|
+
display: flex;
|
|
235
|
+
align-items: center;
|
|
236
|
+
gap: 8px;
|
|
237
|
+
font-size: 14px;
|
|
238
|
+
font-weight: 600;
|
|
239
|
+
color: var(--dsw-alias-label-primary, #111827);
|
|
240
|
+
flex-wrap: wrap;
|
|
241
|
+
}
|
|
242
|
+
.b4a-section-head {
|
|
243
|
+
display: flex;
|
|
244
|
+
align-items: center;
|
|
245
|
+
justify-content: space-between;
|
|
246
|
+
gap: 8px;
|
|
247
|
+
}
|
|
248
|
+
.b4a-section-title {
|
|
249
|
+
font-size: 13px;
|
|
250
|
+
font-weight: 600;
|
|
251
|
+
color: var(--dsw-alias-label-primary, #111827);
|
|
252
|
+
}
|
|
253
|
+
.b4a-rows {
|
|
254
|
+
display: flex;
|
|
255
|
+
flex-direction: column;
|
|
256
|
+
}
|
|
257
|
+
.b4a-row {
|
|
258
|
+
display: flex;
|
|
259
|
+
align-items: center;
|
|
260
|
+
justify-content: space-between;
|
|
261
|
+
gap: 12px;
|
|
262
|
+
padding: 10px 0;
|
|
263
|
+
border-bottom: 1px solid var(--dsw-alias-border-l2, rgba(127, 127, 127, 0.15));
|
|
264
|
+
flex-wrap: wrap;
|
|
265
|
+
}
|
|
266
|
+
.b4a-row:first-child {
|
|
267
|
+
padding-top: 2px;
|
|
268
|
+
}
|
|
269
|
+
.b4a-row:last-child {
|
|
270
|
+
border-bottom: none;
|
|
271
|
+
padding-bottom: 2px;
|
|
272
|
+
}
|
|
273
|
+
.b4a-row-main {
|
|
274
|
+
display: flex;
|
|
275
|
+
flex-direction: column;
|
|
276
|
+
gap: 3px;
|
|
277
|
+
min-width: 0;
|
|
278
|
+
flex: 1;
|
|
279
|
+
}
|
|
280
|
+
.b4a-row-label {
|
|
281
|
+
display: flex;
|
|
282
|
+
align-items: center;
|
|
283
|
+
gap: 8px;
|
|
284
|
+
font-weight: 500;
|
|
285
|
+
color: var(--dsw-alias-label-primary, #111827);
|
|
286
|
+
}
|
|
287
|
+
.b4a-badge {
|
|
288
|
+
display: inline-flex;
|
|
289
|
+
align-items: center;
|
|
290
|
+
padding: 1px 8px;
|
|
291
|
+
border-radius: 999px;
|
|
292
|
+
font-size: 11.5px;
|
|
293
|
+
font-weight: 500;
|
|
294
|
+
white-space: nowrap;
|
|
295
|
+
}
|
|
296
|
+
.b4a-badge-ok {
|
|
297
|
+
background: rgba(16, 185, 129, 0.14);
|
|
298
|
+
color: #10b981;
|
|
299
|
+
}
|
|
300
|
+
.b4a-badge-warn {
|
|
301
|
+
background: rgba(245, 158, 11, 0.16);
|
|
302
|
+
color: #d97706;
|
|
303
|
+
}
|
|
304
|
+
.b4a-badge-err {
|
|
305
|
+
background: rgba(239, 68, 68, 0.14);
|
|
306
|
+
color: #ef4444;
|
|
307
|
+
}
|
|
308
|
+
.b4a-badge-muted {
|
|
309
|
+
background: rgba(127, 127, 127, 0.14);
|
|
310
|
+
color: var(--dsw-alias-label-secondary, #6b7280);
|
|
311
|
+
}
|
|
312
|
+
.b4a-btn {
|
|
313
|
+
display: inline-flex;
|
|
314
|
+
align-items: center;
|
|
315
|
+
justify-content: center;
|
|
316
|
+
gap: 6px;
|
|
317
|
+
height: 28px;
|
|
318
|
+
padding: 0 12px;
|
|
319
|
+
border-radius: var(--dsw-radius-md, 8px);
|
|
320
|
+
font-size: 12px;
|
|
321
|
+
font-weight: 500;
|
|
322
|
+
font-family: inherit;
|
|
323
|
+
cursor: pointer;
|
|
324
|
+
border: 1px solid transparent;
|
|
325
|
+
transition: background-color 0.15s ease, opacity 0.15s ease;
|
|
326
|
+
}
|
|
327
|
+
.b4a-btn:disabled {
|
|
328
|
+
opacity: 0.55;
|
|
329
|
+
cursor: not-allowed;
|
|
330
|
+
}
|
|
331
|
+
.b4a-btn-primary {
|
|
332
|
+
background: var(--dsw-alias-button-primary-fill, #2563eb);
|
|
333
|
+
color: var(--dsw-alias-label-primary-foreground, #ffffff);
|
|
334
|
+
}
|
|
335
|
+
.b4a-btn-primary:hover:not(:disabled) {
|
|
336
|
+
background: var(--dsw-alias-button-primary-hover, #1d4ed8);
|
|
337
|
+
}
|
|
338
|
+
.b4a-btn-secondary {
|
|
339
|
+
background: transparent;
|
|
340
|
+
border-color: var(--dsw-alias-border-l3, rgba(127, 127, 127, 0.25));
|
|
341
|
+
color: var(--dsw-alias-label-primary, #111827);
|
|
342
|
+
}
|
|
343
|
+
.b4a-btn-secondary:hover:not(:disabled) {
|
|
344
|
+
background: var(--dsw-alias-interactive-bg-hover, rgba(127, 127, 127, 0.1));
|
|
345
|
+
}
|
|
346
|
+
.b4a-links {
|
|
347
|
+
display: flex;
|
|
348
|
+
align-items: center;
|
|
349
|
+
gap: 8px;
|
|
350
|
+
flex-wrap: wrap;
|
|
351
|
+
padding-top: 12px;
|
|
352
|
+
border-top: 1px solid var(--dsw-alias-border-l2, rgba(127, 127, 127, 0.15));
|
|
353
|
+
}
|
|
354
|
+
.b4a-links-label {
|
|
355
|
+
font-size: 12px;
|
|
356
|
+
font-weight: 500;
|
|
357
|
+
color: var(--dsw-alias-label-secondary, #4b5563);
|
|
358
|
+
margin-right: 4px;
|
|
359
|
+
}
|
|
360
|
+
.b4a-link {
|
|
361
|
+
display: inline-flex;
|
|
362
|
+
align-items: center;
|
|
363
|
+
height: 28px;
|
|
364
|
+
padding: 0 10px;
|
|
365
|
+
border-radius: var(--dsw-radius-md, 8px);
|
|
366
|
+
border: 1px solid var(--dsw-alias-border-l3, rgba(127, 127, 127, 0.24));
|
|
367
|
+
color: var(--dsw-alias-label-primary, #111827);
|
|
368
|
+
text-decoration: none;
|
|
369
|
+
font-size: 12px;
|
|
370
|
+
font-weight: 500;
|
|
371
|
+
transition: background-color 0.15s ease, border-color 0.15s ease;
|
|
372
|
+
}
|
|
373
|
+
.b4a-link:hover {
|
|
374
|
+
background: var(--dsw-alias-interactive-bg-hover, rgba(127, 127, 127, 0.1));
|
|
375
|
+
}
|
|
376
|
+
.b4a-link-emphasis {
|
|
377
|
+
border-color: var(--dsw-alias-button-primary-fill, #2563eb);
|
|
378
|
+
color: var(--dsw-alias-button-primary-fill, #2563eb);
|
|
379
|
+
}
|
|
380
|
+
.b4a-link-emphasis:hover {
|
|
381
|
+
background: rgba(37, 99, 235, 0.08);
|
|
382
|
+
}
|
|
383
|
+
`;
|
|
384
|
+
|
|
385
|
+
function injectStyles() {
|
|
386
|
+
if (typeof document === 'undefined') return;
|
|
387
|
+
if (
|
|
388
|
+
document.querySelector(
|
|
389
|
+
`style[data-plugin-css=${JSON.stringify(STYLE_TAG_ID)}]`,
|
|
390
|
+
) !== null
|
|
391
|
+
) {
|
|
392
|
+
return;
|
|
393
|
+
}
|
|
394
|
+
const tag = document.createElement('style');
|
|
395
|
+
tag.dataset.plugin = 'dsh-plugin-browser4agent';
|
|
396
|
+
tag.dataset.pluginCss = STYLE_TAG_ID;
|
|
397
|
+
tag.textContent = CSS_TEXT;
|
|
398
|
+
document.head.appendChild(tag);
|
|
399
|
+
}
|
|
400
|
+
|
|
401
|
+
function BrowserIcon(props) {
|
|
402
|
+
const size = props?.size ?? 16;
|
|
403
|
+
return h(
|
|
404
|
+
'svg',
|
|
405
|
+
{
|
|
406
|
+
width: size,
|
|
407
|
+
height: size,
|
|
408
|
+
viewBox: '0 0 24 24',
|
|
409
|
+
fill: 'none',
|
|
410
|
+
stroke: 'currentColor',
|
|
411
|
+
strokeWidth: 1.8,
|
|
412
|
+
strokeLinecap: 'round',
|
|
413
|
+
strokeLinejoin: 'round',
|
|
414
|
+
'aria-hidden': 'true',
|
|
415
|
+
},
|
|
416
|
+
h('rect', { x: 2.5, y: 4, width: 19, height: 16, rx: 2.5 }),
|
|
417
|
+
h('path', { d: 'M2.5 9H21.5' }),
|
|
418
|
+
h('path', { d: 'M9.5 13L12 15L9.5 17' }),
|
|
419
|
+
h('path', { d: 'M13.5 17H16' }),
|
|
420
|
+
);
|
|
421
|
+
}
|
|
422
|
+
|
|
423
|
+
function formatTemplate(str, vars) {
|
|
424
|
+
return String(str).replace(/\{(\w+)\}/g, (_, k) =>
|
|
425
|
+
vars[k] !== undefined && vars[k] !== null ? String(vars[k]) : '',
|
|
426
|
+
);
|
|
427
|
+
}
|
|
428
|
+
|
|
429
|
+
function Browser4AgentSettingsSection(props) {
|
|
430
|
+
const t = props.t || ((k) => DICTIONARIES.en[k] || k);
|
|
431
|
+
|
|
432
|
+
const [status, setStatus] = useState(null);
|
|
433
|
+
const [error, setError] = useState(null);
|
|
434
|
+
const [busy, setBusy] = useState(false);
|
|
435
|
+
const inflightRef = useRef(false);
|
|
436
|
+
|
|
437
|
+
const loadStatus = useCallback(async () => {
|
|
438
|
+
if (inflightRef.current) return;
|
|
439
|
+
inflightRef.current = true;
|
|
440
|
+
try {
|
|
441
|
+
const res = await fetch('api/browser4agent/status', {
|
|
442
|
+
cache: 'no-store',
|
|
443
|
+
});
|
|
444
|
+
const data = await res.json();
|
|
445
|
+
if (!res.ok) throw new Error(data?.error || `HTTP ${res.status}`);
|
|
446
|
+
setStatus(data);
|
|
447
|
+
setError(null);
|
|
448
|
+
} catch (err) {
|
|
449
|
+
setError(err instanceof Error ? err.message : String(err));
|
|
450
|
+
} finally {
|
|
451
|
+
inflightRef.current = false;
|
|
452
|
+
}
|
|
453
|
+
}, []);
|
|
454
|
+
|
|
455
|
+
useEffect(() => {
|
|
456
|
+
loadStatus();
|
|
457
|
+
}, [loadStatus]);
|
|
458
|
+
|
|
459
|
+
// Automatically re-check when user returns to DSH after installing the extension
|
|
460
|
+
useEffect(() => {
|
|
461
|
+
const onFocus = () => {
|
|
462
|
+
loadStatus();
|
|
463
|
+
};
|
|
464
|
+
const onVisibility = () => {
|
|
465
|
+
if (typeof document !== 'undefined' && document.visibilityState === 'visible') {
|
|
466
|
+
loadStatus();
|
|
467
|
+
}
|
|
468
|
+
};
|
|
469
|
+
window.addEventListener('focus', onFocus);
|
|
470
|
+
document.addEventListener('visibilitychange', onVisibility);
|
|
471
|
+
return () => {
|
|
472
|
+
window.removeEventListener('focus', onFocus);
|
|
473
|
+
document.removeEventListener('visibilitychange', onVisibility);
|
|
474
|
+
};
|
|
475
|
+
}, [loadStatus]);
|
|
476
|
+
|
|
477
|
+
const isProvisioning = status?.provisioning?.state === 'running';
|
|
478
|
+
const isReady = Boolean(status?.ready);
|
|
479
|
+
const setupComplete = Boolean(status?.setupComplete);
|
|
480
|
+
const needsExtension = setupComplete && !isReady;
|
|
481
|
+
|
|
482
|
+
// Auto-poll during background setup (1.2s) and while waiting for the
|
|
483
|
+
// browser extension to connect (2.5s), pausing when tab is hidden.
|
|
484
|
+
useEffect(() => {
|
|
485
|
+
if (!isProvisioning && !needsExtension) return undefined;
|
|
486
|
+
const intervalMs = isProvisioning ? 1200 : 2500;
|
|
487
|
+
const timer = setTimeout(() => {
|
|
488
|
+
if (typeof document === 'undefined' || document.visibilityState === 'visible') {
|
|
489
|
+
loadStatus();
|
|
490
|
+
}
|
|
491
|
+
}, intervalMs);
|
|
492
|
+
return () => clearTimeout(timer);
|
|
493
|
+
}, [isProvisioning, needsExtension, status, loadStatus]);
|
|
494
|
+
|
|
495
|
+
const runSetup = useCallback(async (body = {}) => {
|
|
496
|
+
setBusy(true);
|
|
497
|
+
setError(null);
|
|
498
|
+
try {
|
|
499
|
+
const res = await fetch('api/browser4agent/setup', {
|
|
500
|
+
method: 'POST',
|
|
501
|
+
headers: { 'content-type': 'application/json' },
|
|
502
|
+
body: JSON.stringify(body),
|
|
503
|
+
});
|
|
504
|
+
const data = await res.json();
|
|
505
|
+
if (data?.status) setStatus(data.status);
|
|
506
|
+
if (!res.ok || !data?.ok) {
|
|
507
|
+
throw new Error(data?.error || `HTTP ${res.status}`);
|
|
508
|
+
}
|
|
509
|
+
} catch (err) {
|
|
510
|
+
setError(err instanceof Error ? err.message : String(err));
|
|
511
|
+
} finally {
|
|
512
|
+
setBusy(false);
|
|
513
|
+
}
|
|
514
|
+
}, []);
|
|
515
|
+
|
|
516
|
+
const provisionError = status?.provisioning?.error || null;
|
|
517
|
+
const anyBusy = busy || isProvisioning;
|
|
518
|
+
const stepKey = (() => {
|
|
519
|
+
switch (status?.provisioning?.step) {
|
|
520
|
+
case 'downloading':
|
|
521
|
+
return 'provisioningDownloading';
|
|
522
|
+
case 'configuring':
|
|
523
|
+
return 'provisioningConfiguring';
|
|
524
|
+
case 'verifying':
|
|
525
|
+
return 'provisioningVerifying';
|
|
526
|
+
default:
|
|
527
|
+
return 'provisioningChecking';
|
|
528
|
+
}
|
|
529
|
+
})();
|
|
530
|
+
|
|
531
|
+
const extReason = status?.extension?.reason || 'not_connected';
|
|
532
|
+
const tabCount = status?.extension?.tabCount;
|
|
533
|
+
|
|
534
|
+
const heroBadge = isReady
|
|
535
|
+
? { cls: 'b4a-badge-ok', text: t('statusReady') }
|
|
536
|
+
: !setupComplete
|
|
537
|
+
? { cls: 'b4a-badge-warn', text: t('statusSetupNeeded') }
|
|
538
|
+
: extReason === 'tool_error' || extReason === 'invalid_response'
|
|
539
|
+
? { cls: 'b4a-badge-err', text: t('statusToolError') }
|
|
540
|
+
: { cls: 'b4a-badge-warn', text: t('statusActionNeeded') };
|
|
541
|
+
|
|
542
|
+
const heroTitle = isReady
|
|
543
|
+
? t('readyTitle')
|
|
544
|
+
: !setupComplete
|
|
545
|
+
? t('setupIncompleteTitle')
|
|
546
|
+
: extReason === 'tool_error' || extReason === 'invalid_response'
|
|
547
|
+
? t('toolErrorTitle')
|
|
548
|
+
: t('notConnectedTitle');
|
|
549
|
+
|
|
550
|
+
const heroDesc = isReady
|
|
551
|
+
? typeof tabCount === 'number'
|
|
552
|
+
? formatTemplate(t('readyDescTabs'), { count: tabCount })
|
|
553
|
+
: t('readyDescSimple')
|
|
554
|
+
: !setupComplete
|
|
555
|
+
? t('setupIncompleteDesc')
|
|
556
|
+
: extReason === 'tool_error' || extReason === 'invalid_response'
|
|
557
|
+
? status?.extension?.error || t('notConnectedDesc')
|
|
558
|
+
: t('notConnectedDesc');
|
|
559
|
+
|
|
560
|
+
const linkClass = needsExtension
|
|
561
|
+
? 'b4a-link b4a-link-emphasis'
|
|
562
|
+
: 'b4a-link';
|
|
563
|
+
|
|
564
|
+
return h(
|
|
565
|
+
'div',
|
|
566
|
+
{ className: 'b4a-root' },
|
|
567
|
+
h(
|
|
568
|
+
'div',
|
|
569
|
+
null,
|
|
570
|
+
h('h2', { className: 'b4a-title' }, t('title')),
|
|
571
|
+
h('p', { className: 'b4a-subtitle' }, t('subtitle')),
|
|
572
|
+
),
|
|
573
|
+
|
|
574
|
+
!status && !error
|
|
575
|
+
? h('div', { className: 'b4a-card' }, t('loading'))
|
|
576
|
+
: null,
|
|
577
|
+
|
|
578
|
+
error || provisionError
|
|
579
|
+
? h(
|
|
580
|
+
'div',
|
|
581
|
+
{ className: 'b4a-banner b4a-banner-err' },
|
|
582
|
+
h('span', null, `${t('errorTitle')}: ${error || provisionError}`),
|
|
583
|
+
h(
|
|
584
|
+
'button',
|
|
585
|
+
{
|
|
586
|
+
type: 'button',
|
|
587
|
+
className: 'b4a-btn b4a-btn-primary',
|
|
588
|
+
disabled: anyBusy,
|
|
589
|
+
onClick: () => runSetup({}),
|
|
590
|
+
},
|
|
591
|
+
t('btnRetry'),
|
|
592
|
+
),
|
|
593
|
+
)
|
|
594
|
+
: null,
|
|
595
|
+
|
|
596
|
+
status
|
|
597
|
+
? h(
|
|
598
|
+
React.Fragment,
|
|
599
|
+
null,
|
|
600
|
+
// Card 1: Automatic Readiness Status & Browser Extension Store Links
|
|
601
|
+
h(
|
|
602
|
+
'section',
|
|
603
|
+
{ className: 'b4a-card' },
|
|
604
|
+
isProvisioning
|
|
605
|
+
? h(
|
|
606
|
+
'div',
|
|
607
|
+
{ className: 'b4a-provisioning' },
|
|
608
|
+
h(
|
|
609
|
+
'div',
|
|
610
|
+
{ className: 'b4a-provisioning-title' },
|
|
611
|
+
h('span', { className: 'b4a-spinner' }),
|
|
612
|
+
h('span', null, t(stepKey)),
|
|
613
|
+
),
|
|
614
|
+
h('p', { className: 'b4a-desc' }, t('provisioningHint')),
|
|
615
|
+
)
|
|
616
|
+
: h(
|
|
617
|
+
'div',
|
|
618
|
+
{ className: 'b4a-hero' },
|
|
619
|
+
h(
|
|
620
|
+
'div',
|
|
621
|
+
{ className: 'b4a-hero-title' },
|
|
622
|
+
h('span', null, heroTitle),
|
|
623
|
+
h(
|
|
624
|
+
'span',
|
|
625
|
+
{ className: `b4a-badge ${heroBadge.cls}` },
|
|
626
|
+
heroBadge.text,
|
|
627
|
+
),
|
|
628
|
+
),
|
|
629
|
+
h('p', { className: 'b4a-desc' }, heroDesc),
|
|
630
|
+
needsExtension
|
|
631
|
+
? h(
|
|
632
|
+
React.Fragment,
|
|
633
|
+
null,
|
|
634
|
+
extReason === 'not_connected'
|
|
635
|
+
? h(
|
|
636
|
+
'p',
|
|
637
|
+
{ className: 'b4a-desc' },
|
|
638
|
+
t('notConnectedTip'),
|
|
639
|
+
)
|
|
640
|
+
: null,
|
|
641
|
+
h(
|
|
642
|
+
'div',
|
|
643
|
+
{ className: 'b4a-watching' },
|
|
644
|
+
h('span', { className: 'b4a-spinner' }),
|
|
645
|
+
h('span', null, t('watchingExtension')),
|
|
646
|
+
),
|
|
647
|
+
)
|
|
648
|
+
: null,
|
|
649
|
+
),
|
|
650
|
+
|
|
651
|
+
// Browser Extension Store Links
|
|
652
|
+
h(
|
|
653
|
+
'div',
|
|
654
|
+
{ className: 'b4a-links' },
|
|
655
|
+
h(
|
|
656
|
+
'span',
|
|
657
|
+
{ className: 'b4a-links-label' },
|
|
658
|
+
t('installExtTitle'),
|
|
659
|
+
),
|
|
660
|
+
h(
|
|
661
|
+
'a',
|
|
662
|
+
{
|
|
663
|
+
className: linkClass,
|
|
664
|
+
href: STORE_LINKS.chrome,
|
|
665
|
+
target: '_blank',
|
|
666
|
+
rel: 'noreferrer noopener',
|
|
667
|
+
},
|
|
668
|
+
t('linkChrome'),
|
|
669
|
+
),
|
|
670
|
+
h(
|
|
671
|
+
'a',
|
|
672
|
+
{
|
|
673
|
+
className: linkClass,
|
|
674
|
+
href: STORE_LINKS.edge,
|
|
675
|
+
target: '_blank',
|
|
676
|
+
rel: 'noreferrer noopener',
|
|
677
|
+
},
|
|
678
|
+
t('linkEdge'),
|
|
679
|
+
),
|
|
680
|
+
h(
|
|
681
|
+
'a',
|
|
682
|
+
{
|
|
683
|
+
className: linkClass,
|
|
684
|
+
href: STORE_LINKS.firefox,
|
|
685
|
+
target: '_blank',
|
|
686
|
+
rel: 'noreferrer noopener',
|
|
687
|
+
},
|
|
688
|
+
t('linkFirefox'),
|
|
689
|
+
),
|
|
690
|
+
h(
|
|
691
|
+
'a',
|
|
692
|
+
{
|
|
693
|
+
className: 'b4a-link',
|
|
694
|
+
href: STORE_LINKS.releases,
|
|
695
|
+
target: '_blank',
|
|
696
|
+
rel: 'noreferrer noopener',
|
|
697
|
+
},
|
|
698
|
+
t('linkReleases'),
|
|
699
|
+
),
|
|
700
|
+
h(
|
|
701
|
+
'a',
|
|
702
|
+
{
|
|
703
|
+
className: 'b4a-link',
|
|
704
|
+
href: STORE_LINKS.repo,
|
|
705
|
+
target: '_blank',
|
|
706
|
+
rel: 'noreferrer noopener',
|
|
707
|
+
},
|
|
708
|
+
t('linkDocs'),
|
|
709
|
+
),
|
|
710
|
+
),
|
|
711
|
+
),
|
|
712
|
+
|
|
713
|
+
// Card 2: Local Environment Checklist
|
|
714
|
+
h(
|
|
715
|
+
'section',
|
|
716
|
+
{ className: 'b4a-card' },
|
|
717
|
+
h(
|
|
718
|
+
'div',
|
|
719
|
+
{ className: 'b4a-section-head' },
|
|
720
|
+
h(
|
|
721
|
+
'span',
|
|
722
|
+
{ className: 'b4a-section-title' },
|
|
723
|
+
t('checklistTitle'),
|
|
724
|
+
),
|
|
725
|
+
h(
|
|
726
|
+
'button',
|
|
727
|
+
{
|
|
728
|
+
type: 'button',
|
|
729
|
+
className: 'b4a-btn b4a-btn-secondary',
|
|
730
|
+
disabled: anyBusy,
|
|
731
|
+
onClick: () => runSetup({}),
|
|
732
|
+
},
|
|
733
|
+
busy ? t('btnWorking') : t('btnRerunSetup'),
|
|
734
|
+
),
|
|
735
|
+
),
|
|
736
|
+
h(
|
|
737
|
+
'div',
|
|
738
|
+
{ className: 'b4a-rows' },
|
|
739
|
+
// Row 1: CLI
|
|
740
|
+
h(
|
|
741
|
+
'div',
|
|
742
|
+
{ className: 'b4a-row' },
|
|
743
|
+
h(
|
|
744
|
+
'div',
|
|
745
|
+
{ className: 'b4a-row-main' },
|
|
746
|
+
h(
|
|
747
|
+
'div',
|
|
748
|
+
{ className: 'b4a-row-label' },
|
|
749
|
+
h('span', null, t('rowCliTitle')),
|
|
750
|
+
h(
|
|
751
|
+
'span',
|
|
752
|
+
{
|
|
753
|
+
className: `b4a-badge ${status.binary?.installed ? 'b4a-badge-ok' : 'b4a-badge-muted'}`,
|
|
754
|
+
},
|
|
755
|
+
status.binary?.installed
|
|
756
|
+
? status.binary.version
|
|
757
|
+
? `v${status.binary.version}`
|
|
758
|
+
: t('badgeOk')
|
|
759
|
+
: t('badgeMissing'),
|
|
760
|
+
),
|
|
761
|
+
),
|
|
762
|
+
h(
|
|
763
|
+
'p',
|
|
764
|
+
{ className: 'b4a-desc' },
|
|
765
|
+
status.binary?.path
|
|
766
|
+
? h('code', null, status.binary.path)
|
|
767
|
+
: t('rowCliMissing'),
|
|
768
|
+
),
|
|
769
|
+
),
|
|
770
|
+
),
|
|
771
|
+
|
|
772
|
+
// Row 2: Native Messaging Host
|
|
773
|
+
h(
|
|
774
|
+
'div',
|
|
775
|
+
{ className: 'b4a-row' },
|
|
776
|
+
h(
|
|
777
|
+
'div',
|
|
778
|
+
{ className: 'b4a-row-main' },
|
|
779
|
+
h(
|
|
780
|
+
'div',
|
|
781
|
+
{ className: 'b4a-row-label' },
|
|
782
|
+
h('span', null, t('rowNativeTitle')),
|
|
783
|
+
h(
|
|
784
|
+
'span',
|
|
785
|
+
{
|
|
786
|
+
className: `b4a-badge ${status.nativeHost?.configured ? 'b4a-badge-ok' : 'b4a-badge-muted'}`,
|
|
787
|
+
},
|
|
788
|
+
status.nativeHost?.configured
|
|
789
|
+
? t('badgeConfigured')
|
|
790
|
+
: t('badgeMissing'),
|
|
791
|
+
),
|
|
792
|
+
),
|
|
793
|
+
h(
|
|
794
|
+
'p',
|
|
795
|
+
{ className: 'b4a-desc' },
|
|
796
|
+
status.nativeHost?.configured
|
|
797
|
+
? formatTemplate(t('rowNativeOk'), {
|
|
798
|
+
browsers: (status.nativeHost.browsers || []).join(
|
|
799
|
+
', ',
|
|
800
|
+
),
|
|
801
|
+
})
|
|
802
|
+
: t('rowNativeMissing'),
|
|
803
|
+
),
|
|
804
|
+
),
|
|
805
|
+
),
|
|
806
|
+
|
|
807
|
+
// Row 3: DSH Skill
|
|
808
|
+
h(
|
|
809
|
+
'div',
|
|
810
|
+
{ className: 'b4a-row' },
|
|
811
|
+
h(
|
|
812
|
+
'div',
|
|
813
|
+
{ className: 'b4a-row-main' },
|
|
814
|
+
h(
|
|
815
|
+
'div',
|
|
816
|
+
{ className: 'b4a-row-label' },
|
|
817
|
+
h('span', null, t('rowSkillTitle')),
|
|
818
|
+
h(
|
|
819
|
+
'span',
|
|
820
|
+
{
|
|
821
|
+
className: `b4a-badge ${status.skill?.installed ? 'b4a-badge-ok' : 'b4a-badge-muted'}`,
|
|
822
|
+
},
|
|
823
|
+
status.skill?.installed
|
|
824
|
+
? t('badgeOk')
|
|
825
|
+
: t('badgeMissing'),
|
|
826
|
+
),
|
|
827
|
+
),
|
|
828
|
+
h(
|
|
829
|
+
'p',
|
|
830
|
+
{ className: 'b4a-desc' },
|
|
831
|
+
status.skill?.installed
|
|
832
|
+
? h('code', null, status.skill.path)
|
|
833
|
+
: t('rowSkillMissing'),
|
|
834
|
+
),
|
|
835
|
+
),
|
|
836
|
+
),
|
|
837
|
+
),
|
|
838
|
+
),
|
|
839
|
+
)
|
|
840
|
+
: null,
|
|
841
|
+
);
|
|
842
|
+
}
|
|
843
|
+
|
|
844
|
+
function apply(ctx) {
|
|
845
|
+
injectStyles();
|
|
846
|
+
const t = ctx.locale.bind(NS);
|
|
847
|
+
ctx.effect(
|
|
848
|
+
() => ctx.locale.register(NS, DICTIONARIES),
|
|
849
|
+
'browser4agent: dictionaries',
|
|
850
|
+
);
|
|
851
|
+
ctx.effect(
|
|
852
|
+
() =>
|
|
853
|
+
ctx.slots.inject('settings.section.icon', () =>
|
|
854
|
+
ctx.slots.register(
|
|
855
|
+
{
|
|
856
|
+
name: 'settings.section.icon',
|
|
857
|
+
id: 'browser4agent',
|
|
858
|
+
locale: NS,
|
|
859
|
+
},
|
|
860
|
+
BrowserIcon,
|
|
861
|
+
),
|
|
862
|
+
),
|
|
863
|
+
'browser4agent: settings section icon',
|
|
864
|
+
);
|
|
865
|
+
ctx.effect(
|
|
866
|
+
() =>
|
|
867
|
+
ctx.slots.inject('settings.section', () =>
|
|
868
|
+
ctx.slots.register(
|
|
869
|
+
{
|
|
870
|
+
name: 'settings.section',
|
|
871
|
+
id: 'browser4agent',
|
|
872
|
+
order: 66,
|
|
873
|
+
label: () => t('nav'),
|
|
874
|
+
locale: NS,
|
|
875
|
+
},
|
|
876
|
+
Browser4AgentSettingsSection,
|
|
877
|
+
),
|
|
878
|
+
),
|
|
879
|
+
'browser4agent: settings section',
|
|
880
|
+
);
|
|
881
|
+
}
|
|
882
|
+
|
|
883
|
+
exports.name = 'browser4agent-settings';
|
|
884
|
+
exports.inject = ['slots', 'locale'];
|
|
885
|
+
exports.apply = apply;
|
|
886
|
+
return module.exports;
|
|
887
|
+
},
|
|
888
|
+
});
|