@nite07/websearch-mcp 0.2.1 → 0.2.3
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/README.md +29 -5
- package/README.zh.md +15 -0
- package/config.example.json +149 -3
- package/dist/live.d.ts +5 -0
- package/dist/live.js +14 -0
- package/dist/sdk.js +26 -2
- package/dist/tools.d.ts +7 -0
- package/dist/tools.js +39 -10
- package/dist/ui/page.html +460 -104
- package/dist/ui/server.js +22 -1
- package/dist/ui/state.d.ts +19 -1
- package/dist/ui/state.js +20 -1
- package/package.json +2 -2
package/dist/ui/page.html
CHANGED
|
@@ -106,10 +106,12 @@
|
|
|
106
106
|
border-radius: .5rem; max-height: 16rem; overflow: auto; white-space: pre-wrap; word-break: break-word;
|
|
107
107
|
font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: .8rem;
|
|
108
108
|
}
|
|
109
|
-
#issues {
|
|
110
|
-
#issues
|
|
111
|
-
#issues
|
|
109
|
+
#issues { position: fixed; top: 3.75rem; right: 1.25rem; z-index: 45; width: min(32rem, calc(100vw - 2.5rem)); }
|
|
110
|
+
#issues:empty { display: none; }
|
|
111
|
+
#issues .panel { border-color: var(--bad); box-shadow: 0 10px 30px rgba(16, 24, 40, .18); }
|
|
112
|
+
#issues ul { margin: .4rem 0 0; padding-left: 1.1rem; max-height: 40vh; overflow: auto; }
|
|
112
113
|
#issues li { font-size: .85rem; }
|
|
114
|
+
#issues .head { display: flex; align-items: center; justify-content: space-between; gap: .75rem; }
|
|
113
115
|
#banner .panel { border-color: var(--warn); }
|
|
114
116
|
.toast {
|
|
115
117
|
position: fixed; left: 50%; bottom: 1.5rem; transform: translate(-50%, 1rem); opacity: 0;
|
|
@@ -120,6 +122,24 @@
|
|
|
120
122
|
.toast.show { opacity: 1; transform: translate(-50%, 0); }
|
|
121
123
|
footer { max-width: 1180px; margin: 0 auto; padding: 0 1.25rem 2.5rem; color: var(--muted); font-size: .8rem; }
|
|
122
124
|
.hidden { display: none !important; }
|
|
125
|
+
.tabs { display: flex; flex-wrap: wrap; gap: .5rem; margin: 0 0 1.25rem; }
|
|
126
|
+
.tabs .tab { border-radius: 999px; padding: .35rem .9rem; }
|
|
127
|
+
.tabs .tab.is-active { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
|
|
128
|
+
.route { border: 1px solid var(--line); border-radius: .7rem; padding: .75rem; margin-bottom: .75rem; background: var(--panel); }
|
|
129
|
+
.rule { border: 1px dashed var(--line); border-radius: .6rem; padding: .4rem .6rem; margin: .45rem 0; }
|
|
130
|
+
.rule > summary.rule-head { display: flex; align-items: center; gap: .6rem; cursor: pointer; list-style: none; }
|
|
131
|
+
.rule > summary.rule-head::-webkit-details-marker { display: none; }
|
|
132
|
+
.rule > summary.rule-head::before { content: '▸'; color: var(--muted); font-size: .8rem; }
|
|
133
|
+
.rule[open] > summary.rule-head::before { content: '▾'; }
|
|
134
|
+
.rule > summary.rule-head .chip { margin-left: auto; }
|
|
135
|
+
.rule > summary.rule-head button { margin-left: .5rem; }
|
|
136
|
+
.rule-body { padding: .35rem 0 .1rem .9rem; }
|
|
137
|
+
.rule-head { display: flex; flex-wrap: wrap; gap: .5rem; align-items: center; justify-content: space-between; }
|
|
138
|
+
.condition { display: grid; grid-template-columns: repeat(auto-fit, minmax(140px, 1fr)); gap: .4rem .6rem; align-items: center; margin: .4rem 0; }
|
|
139
|
+
.condition input, .condition select { font: inherit; min-width: 0; padding: .25rem .4rem; border: 1px solid var(--line); border-radius: .4rem; background: var(--bg); color: var(--ink); }
|
|
140
|
+
.problems { margin: 0 0 .75rem; padding-left: 1.1rem; font-size: .85rem; color: var(--warn); }
|
|
141
|
+
.ok-line { font-size: .85rem; color: var(--ok); }
|
|
142
|
+
@media (max-width: 640px) { .condition { grid-template-columns: 1fr; } }
|
|
123
143
|
</style>
|
|
124
144
|
</head>
|
|
125
145
|
<body>
|
|
@@ -133,7 +153,6 @@
|
|
|
133
153
|
</div>
|
|
134
154
|
<div class="path mono" id="configPath">—</div>
|
|
135
155
|
<div class="actions">
|
|
136
|
-
<button class="ghost" id="lang">EN</button>
|
|
137
156
|
<button class="ghost" id="reload">重新加载</button>
|
|
138
157
|
<button class="primary" id="save">保存</button>
|
|
139
158
|
</div>
|
|
@@ -144,20 +163,19 @@
|
|
|
144
163
|
<footer id="foot"></footer>
|
|
145
164
|
<div class="toast" id="toast"></div>
|
|
146
165
|
<script type="module">
|
|
147
|
-
const
|
|
148
|
-
|
|
166
|
+
const TEXT = {
|
|
167
|
+
|
|
149
168
|
save: '保存', reload: '重新加载', dirty: '有未保存的更改', clean: '已保存',
|
|
150
169
|
saved: '已保存并热重载', savedNoChange: '没有需要保存的更改', reloaded: '已从磁盘重新加载',
|
|
151
170
|
loadError: '磁盘上的配置无法解析,页面暂时显示默认值;保存后即覆盖。',
|
|
171
|
+
sectionFailed: '这个分区无法显示,其它分区不受影响。',
|
|
152
172
|
sessionExpired: '会话已过期,请用 --print-url 重新打开链接。',
|
|
153
|
-
strategy: '检索策略', mode: '模式', parallel: '并行(全部启用后端)', single: '单后端',
|
|
154
|
-
singleBackend: '单后端选择', singleBackendHint: 'single 模式下唯一使用的后端',
|
|
155
173
|
maxResults: '结果上限', concurrency: '并发', overallTimeout: '总超时 (ms)', backendTimeout: '超时 (ms)',
|
|
156
|
-
|
|
174
|
+
language: '语言', region: '地区', recency: '时效', dedup: '去重', fusion: '融合',
|
|
157
175
|
safeSearch: '安全搜索', includeDomains: '包含域名', excludeDomains: '排除域名',
|
|
158
176
|
none: '不限制', any: '不限', day: '一天', week: '一周', month: '一月', year: '一年',
|
|
159
177
|
url: '按 URL', urlTitle: '按 URL + 标题', rrf: 'RRF', ordered: '按顺序拼接',
|
|
160
|
-
|
|
178
|
+
retry: '重试', cache: '缓存', breaker: '熔断', diagnostics: '诊断记录',
|
|
161
179
|
browser: '共享浏览器', tools: '输出', compactDefault: '默认精简输出(只返回 URL / 标题 / 日期)',
|
|
162
180
|
webSearchPlus: '启用 web_search_plus 兼容字段',
|
|
163
181
|
enabled: '启用', retryEnabled: '启用重试', statuses: '重试状态码', maxRetries: '最多重试次数',
|
|
@@ -183,59 +201,68 @@ const I18N = {
|
|
|
183
201
|
cleared: '凭证已清除', credSaved: '凭证已保存', missingCred: '缺凭证',
|
|
184
202
|
credBrowserNote: '读取走共享浏览器:端点与令牌在「共享浏览器」一节填写。',
|
|
185
203
|
credAnonymousNote: '当前模式不需要凭证;切换到 key / oauth / session 模式后这里会出现凭证输入框。',
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
204
|
+
tabsLabel: '设置分区', tabBehavior: '行为', tabReliability: '可靠性', tabDiagnostics: '诊断',
|
|
205
|
+
tabBackends: '搜索后端', tabBrowser: '浏览器', tabFetch: '页面抓取',
|
|
206
|
+
helpBehavior: '这些值决定每次搜索的默认行为:返回多少、用什么语言和地区、结果怎么去重和融合。单个调用可以覆盖它们。',
|
|
207
|
+
helpReliability: '超时、重试、缓存与熔断:一次搜索在失败或变慢时怎么处理。',
|
|
208
|
+
helpDiagnostics: '记录每次调用的诊断信息,用来回答“为什么这次搜索变慢了”而不是“这次搜到了什么”。',
|
|
209
|
+
helpBackends: '每个搜索服务端一张卡:启用、访问模式、端点、限流,以及它自己的凭证。',
|
|
210
|
+
helpBrowser: '你自己托管的浏览器。小红书读取和页面抓取的浏览器路径都用它,令牌只保护这个端点。',
|
|
211
|
+
helpFetch: '一次抓取按下面三条路径的顺序尝试,规则决定什么时候继续下一条;服务商与凭证沿用搜索侧的配置。',
|
|
212
|
+
groupSearchDefaults: '检索默认值', groupQueryDefaults: '查询默认值', groupOutput: '输出',
|
|
213
|
+
groupTimeout: '超时', groupRetry: '重试', groupCache: '缓存', groupBreaker: '熔断',
|
|
214
|
+
groupRecord: '记录', groupConnection: '连接', groupSession: '会话', groupLimits: '并发',
|
|
215
|
+
'route.http': 'HTTP 直取', 'route.browser': '浏览器', 'route.provider': '服务商',
|
|
216
|
+
'routeHelp.http': '最快,但拿不到需要执行脚本才出现的页面',
|
|
217
|
+
'routeHelp.browser': '真实浏览器渲染,慢一些,能看到脚本生成的内容',
|
|
218
|
+
'routeHelp.provider': '交给搜索服务商抓取,按它的额度计费',
|
|
219
|
+
'condition.status': '目标状态码', 'condition.api-status': '服务商接口状态码', 'condition.network': '网络错误',
|
|
220
|
+
'condition.timeout': '超时', 'condition.error': '失败类型', 'condition.match': '内容匹配',
|
|
221
|
+
'failure.network': '网络错误', 'failure.timeout': '超时', 'failure.http': 'HTTP 错误',
|
|
222
|
+
'failure.provider': '服务商失败', 'failure.authentication': '凭证无效', 'failure.protocol': '协议错误',
|
|
223
|
+
'failure.conversion': '转换失败', 'failure.unsupported-content': '无可用内容', 'failure.limit': '超出上限',
|
|
224
|
+
webExtract: '允许使用 web_extract 工具', webExtractHelp: '关闭后该工具不会注册;抓取配置、凭证和本页仍然可用。',
|
|
225
|
+
fetchReadyTitle: '抓取可用性', fetchReady: '保存的抓取链可以运行。', fetchReadyHelp: '只根据配置与已存凭证判断,不会发起请求。',
|
|
226
|
+
problem: { fetchNoRoutes: '没有启用任何路由,所有页面抓取都会失败。', fetchDelegatedOff: '已启用浏览器或服务商路由,但没有打开委托抓取开关。', fetchBrowserNoEndpoint: '已启用浏览器路由,但没有设置共享浏览器端点。', fetchProviderMissing: '已启用服务商路由,但没有选择支持抓取的服务商。', fetchProviderMode: '{{provider}} 在 {{mode}} 模式下不支持抓取。', fetchProviderEndpoint: '{{provider}} 没有配置抓取端点。', fetchProviderCredential: '{{provider}} 的抓取模式需要已保存的凭证。' },
|
|
227
|
+
routesTitle: '路由顺序', routesHelp: '每种路由各一条,按顺序串行执行;关闭的会跳过,命中回退规则时继续下一条。',
|
|
228
|
+
route: { http: 'HTTP 直连', browser: '浏览器渲染', provider: '服务商' },
|
|
229
|
+
routeHelp: { http: '直接请求,解码响应 HTML。', browser: '共享浏览器渲染后的 DOM。', provider: '单个服务商,原生 Markdown。' },
|
|
230
|
+
moveUp: '上移', moveDown: '下移', enabled: '启用', timeout: '路由超时 (ms)',
|
|
231
|
+
rulesTitle: '回退规则', rulesHelp: '规则间是「或」,同一规则内条件是「且」;字段缺失算不可用,不当作空字符串。',
|
|
232
|
+
rulesCount: (count, max) => `{{count}} / {{max}}`.replace('{{count}}', count).replace('{{max}}', max),
|
|
233
|
+
addRule: '添加规则', addCondition: '添加条件', removeRule: '删除规则',
|
|
234
|
+
addStatusPreset: '添加状态码预设', addChallengePreset: '添加验证页预设', restoreDefaultRules: '恢复默认规则',
|
|
235
|
+
presetsHelp: '预设就是普通的可编辑规则;验证页预设只看标题与 HTML 标记的组合,不会仅凭 “cloudflare” 触发,也不会替你通过验证。',
|
|
236
|
+
conditionType: '条件类型', conditionStatuses: '状态码,逗号分隔', conditionKinds: '错误类型', conditionField: '字段', conditionOperator: '运算符', conditionValue: '匹配值', conditionCase: '区分大小写',
|
|
237
|
+
condition: { network: '网络错误', timeout: '路由超时', status: '目标状态码属于', 'api-status': '服务商 API 状态码属于', error: '运行错误属于', match: '内容匹配' },
|
|
238
|
+
matchField: { title: '标题', html: 'HTML', text: '正文文本', markdown: 'Markdown' },
|
|
239
|
+
matchOperator: { contains: '包含', equals: '等于', regex: '正则' },
|
|
240
|
+
providerTitle: '抓取服务商', providerHelp: '选择服务商不会改变它是否参与搜索,也不会自行发起请求。', providerNone: '未选择',
|
|
241
|
+
providerServes: (formats) => `可返回 ${formats}`, providerMarkdownOnly: '该服务商只返回 Markdown;请求 HTML 时会跳过并不发请求,由下一条启用的路由提供页面。',
|
|
242
|
+
providerFields: '服务商不返回的字段(标题、目标状态码或 HTML)会让相关条件不可用,测试结果里会逐一列出。',
|
|
243
|
+
fetchMode: '抓取接入模式', fetchEndpoint: '抓取端点', providerTimeout: '服务商调用超时 (ms)', providerCredentialRequired: '该模式需要凭证', providerCredentialOptional: '该模式不需要凭证',
|
|
244
|
+
limitsTitle: '安全与上限',
|
|
245
|
+
fetchOverallTimeout: '抓取总期限 (ms)', maxRedirects: '最大重定向次数', maxBodyBytes: '最大下载字节数', maxOutputChars: '输出最大字符数', maxRuleScanChars: '规则扫描字符数',
|
|
246
|
+
allowPrivateNetworks: '允许私有网络目标', browserContext: '浏览器上下文', contextIsolated: '隔离', contextSession: '会话',
|
|
247
|
+
challengeSolver: 'Cloudflare 挑战处理', solverAuto: '尝试一次', solverOff: '不尝试',
|
|
248
|
+
settleMs: '等待稳定延迟 (ms)', selectorWait: '等待的选择器',
|
|
249
|
+
fetchTest: '页面抓取测试', fetchTestHelp: '针对已保存配置的手动测试,会访问网络且服务商可能计费;不会自动执行。', runFetchTest: '执行抓取测试',
|
|
250
|
+
formatMarkdown: 'Markdown(阅读)', formatHtml: 'HTML(结构)', fetchTestResult: '测试结果', saveFirst: '请先保存再测试。',
|
|
251
|
+
provCredOk: '已存储凭证', provCredMissing: '尚未存储凭证',
|
|
252
|
+
failure: { network: '网络', timeout: '超时', http: 'HTTP', provider: '服务商', authentication: '认证', protocol: '协议', conversion: '转换', 'unsupported-content': '内容不支持', limit: '上限' },
|
|
226
253
|
};
|
|
227
254
|
|
|
228
255
|
const state = {
|
|
229
256
|
snap: null, draft: null, dirty: false,
|
|
230
|
-
|
|
257
|
+
tab: 'behavior', fetchUrl: '', fetchFormat: 'markdown', fetchResult: null, fetchBusy: false,
|
|
231
258
|
filter: '', onlyEnabled: false, open: new Set(), closed: new Set(), results: {}, issues: [], probeQuery: '', compactByDefault: false,
|
|
232
259
|
};
|
|
233
260
|
const t = (key, ...args) => {
|
|
234
|
-
const
|
|
235
|
-
const value = table[key] ?? I18N.zh[key] ?? key;
|
|
261
|
+
const value = TEXT[key] ?? key;
|
|
236
262
|
return typeof value === 'function' ? value(...args) : value;
|
|
237
263
|
};
|
|
238
|
-
|
|
264
|
+
// Catalog metadata carries both languages; this page is Chinese, so it asks for that one.
|
|
265
|
+
const local = (field) => (field && typeof field === 'object' ? (field.zh ?? field.en ?? '') : String(field ?? ''));
|
|
239
266
|
const clone = (value) => structuredClone(value);
|
|
240
267
|
|
|
241
268
|
function h(tag, props = {}, ...kids) {
|
|
@@ -276,6 +303,44 @@ function toast(message, tone = '') {
|
|
|
276
303
|
toast.timer = setTimeout(() => { node.className = 'toast'; }, 3200);
|
|
277
304
|
}
|
|
278
305
|
|
|
306
|
+
function touch() { markDirty(); render(); }
|
|
307
|
+
function problemText(problem) {
|
|
308
|
+
const raw = (TEXT.problem && TEXT.problem[problem.key]) ?? problem.key;
|
|
309
|
+
return String(raw).replace(/\{\{(\w+)\}\}/g, (_match, name) => String((problem.vars || {})[name] ?? ''));
|
|
310
|
+
}
|
|
311
|
+
function nextId(rules, base) {
|
|
312
|
+
let candidate = base; let counter = 2;
|
|
313
|
+
while (rules.some(rule => rule.id === candidate)) { candidate = `${base}-${counter}`; counter += 1; }
|
|
314
|
+
return candidate;
|
|
315
|
+
}
|
|
316
|
+
function checkbox(checked, onChange) {
|
|
317
|
+
const input = h('input', { type: 'checkbox' });
|
|
318
|
+
input.checked = checked === true;
|
|
319
|
+
input.addEventListener('change', () => onChange(input.checked));
|
|
320
|
+
return input;
|
|
321
|
+
}
|
|
322
|
+
function textInput(value, onInput) {
|
|
323
|
+
const input = h('input', { type: 'text', value: value ?? '' });
|
|
324
|
+
input.addEventListener('input', () => onInput(input.value));
|
|
325
|
+
return input;
|
|
326
|
+
}
|
|
327
|
+
function selectInput(options, value, onChange) {
|
|
328
|
+
const node = h('select', {});
|
|
329
|
+
for (const [optionValue, label] of options) node.append(h('option', { value: optionValue, selected: String(value) === String(optionValue) }, label));
|
|
330
|
+
node.addEventListener('change', () => onChange(node.value));
|
|
331
|
+
return node;
|
|
332
|
+
}
|
|
333
|
+
function numberInput(value, onChange, min, max) {
|
|
334
|
+
const input = h('input', { type: 'number', value: value ?? '', min, max, step: 1 });
|
|
335
|
+
input.addEventListener('input', () => { const next = Number(input.value); if (Number.isInteger(next)) onChange(next); });
|
|
336
|
+
return input;
|
|
337
|
+
}
|
|
338
|
+
function defaultCondition(type) {
|
|
339
|
+
if (type === 'status' || type === 'api-status') return { type, statuses: [404] };
|
|
340
|
+
if (type === 'error') return { type: 'error', kinds: ['protocol'] };
|
|
341
|
+
if (type === 'match') return { type: 'match', field: 'text', operator: 'contains', value: '', caseSensitive: false };
|
|
342
|
+
return { type: type === 'timeout' ? 'timeout' : 'network' };
|
|
343
|
+
}
|
|
279
344
|
function markDirty() {
|
|
280
345
|
state.dirty = true;
|
|
281
346
|
document.getElementById('dirty').classList.add('on');
|
|
@@ -345,29 +410,42 @@ function onModeChange(backendPath, mode) {
|
|
|
345
410
|
render();
|
|
346
411
|
}
|
|
347
412
|
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
const
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
))
|
|
369
|
-
|
|
370
|
-
|
|
413
|
+
/**
|
|
414
|
+
* One tab, one subject. Each section is a plain column of panels: a heading that says what the subject
|
|
415
|
+
* decides, then the fields. Nothing is nested two levels deep, because every setting on this page is
|
|
416
|
+
* something a person came here to change, not to dig out.
|
|
417
|
+
*/
|
|
418
|
+
function group(title, ...children) {
|
|
419
|
+
return h('div', { class: 'panel pad' }, h('h3', {}, title), h('div', { class: 'grid', style: 'margin-top:.6rem' }, children));
|
|
420
|
+
}
|
|
421
|
+
|
|
422
|
+
function behaviorSection() {
|
|
423
|
+
const defaults = group(t('groupSearchDefaults'),
|
|
424
|
+
field({ path: 'maxResults', type: 'number', label: t('maxResults'), min: 1, max: 50 }),
|
|
425
|
+
field({ path: 'concurrency', type: 'number', label: t('concurrency'), min: 1, max: 20 }));
|
|
426
|
+
|
|
427
|
+
const query = group(t('groupQueryDefaults'),
|
|
428
|
+
field({ path: 'language', type: 'select', label: t('language'), options: [['', t('none')], ...(state.snap.languages || []).map(code => [code, code])] }),
|
|
429
|
+
field({ path: 'region', type: 'select', label: t('region'), options: [['', t('none')], ...(state.snap.regions || []).map(code => [code, code])] }),
|
|
430
|
+
field({ path: 'recency', type: 'select', label: t('recency'), options: [['any', t('any')], ['day', t('day')], ['week', t('week')], ['month', t('month')], ['year', t('year')]] }),
|
|
431
|
+
field({ path: 'dedup', type: 'select', label: t('dedup'), options: [['url', t('url')], ['url-title', t('urlTitle')]] }),
|
|
432
|
+
field({ path: 'fusion', type: 'select', label: t('fusion'), options: [['rrf', t('rrf')], ['ordered', t('ordered')]] }),
|
|
433
|
+
field({ path: 'safeSearch', type: 'check', label: t('safeSearch') }),
|
|
434
|
+
field({ path: 'includeDomains', type: 'list', label: t('includeDomains'), placeholder: 'example.com, docs.example.org' }),
|
|
435
|
+
field({ path: 'excludeDomains', type: 'list', label: t('excludeDomains'), placeholder: 'spam.example' }));
|
|
436
|
+
|
|
437
|
+
const output = group(t('groupOutput'),
|
|
438
|
+
topLevelCheck(t('compactDefault')),
|
|
439
|
+
field({ path: 'tools.webSearchPlus', type: 'check', label: t('webSearchPlus') }));
|
|
440
|
+
|
|
441
|
+
return tabSection(t('tabBehavior'), t('helpBehavior'), defaults, query, output);
|
|
442
|
+
}
|
|
443
|
+
|
|
444
|
+
function reliabilitySection() {
|
|
445
|
+
const timeout = group(t('groupTimeout'),
|
|
446
|
+
field({ path: 'overallTimeoutMs', type: 'number', label: t('overallTimeout'), min: 1000, max: 180000, step: 1000 }));
|
|
447
|
+
|
|
448
|
+
const retry = group(t('groupRetry'),
|
|
371
449
|
field({ path: 'retry.enabled', type: 'check', label: t('retryEnabled') }),
|
|
372
450
|
field({ path: 'retry.maxRetries', type: 'number', label: t('maxRetries'), min: 0, max: 5 }),
|
|
373
451
|
field({ path: 'retry.initialDelayMs', type: 'number', label: t('initialDelay'), min: 0, max: 60000 }),
|
|
@@ -376,38 +454,46 @@ function overview() {
|
|
|
376
454
|
field({ path: 'retry.networkErrors', type: 'check', label: t('networkErrors') }),
|
|
377
455
|
field({ path: 'retry.timeouts', type: 'check', label: t('timeouts') }));
|
|
378
456
|
|
|
379
|
-
const cache =
|
|
457
|
+
const cache = group(t('groupCache'),
|
|
380
458
|
field({ path: 'cache.enabled', type: 'check', label: t('cacheEnabled') }),
|
|
381
459
|
field({ path: 'cache.ttlSeconds', type: 'number', label: t('ttl'), min: 1, max: 86400 }),
|
|
382
460
|
field({ path: 'cache.maxEntries', type: 'number', label: t('maxEntries'), min: 1, max: 1000 }));
|
|
383
461
|
|
|
384
|
-
const breaker =
|
|
462
|
+
const breaker = group(t('groupBreaker'),
|
|
385
463
|
field({ path: 'breaker.enabled', type: 'check', label: t('breakerEnabled') }),
|
|
386
464
|
field({ path: 'breaker.threshold', type: 'number', label: t('threshold'), min: 1, max: 100 }),
|
|
387
465
|
field({ path: 'breaker.cooldownMs', type: 'number', label: t('cooldown'), min: 1000, max: 3600000 }));
|
|
388
466
|
|
|
389
|
-
|
|
467
|
+
return tabSection(t('tabReliability'), t('helpReliability'), timeout, retry, cache, breaker);
|
|
468
|
+
}
|
|
469
|
+
|
|
470
|
+
function diagnosticsSection() {
|
|
471
|
+
const record = group(t('groupRecord'),
|
|
390
472
|
field({ path: 'diagnostics.enabled', type: 'check', label: t('diagEnabled') }),
|
|
391
473
|
field({ path: 'diagnostics.maxEntries', type: 'number', label: t('diagEntries'), min: 1, max: 500 }));
|
|
474
|
+
return tabSection(t('tabDiagnostics'), t('helpDiagnostics'), record);
|
|
475
|
+
}
|
|
392
476
|
|
|
393
|
-
|
|
477
|
+
function browserSection() {
|
|
478
|
+
const connection = group(t('groupConnection'),
|
|
394
479
|
field({ path: 'browser.endpoint', type: 'text', label: t('browserEndpoint'), placeholder: 'ws://127.0.0.1:3030/ws' }),
|
|
395
|
-
field({ path: 'browser.
|
|
396
|
-
|
|
397
|
-
field({ path: 'browser.
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
480
|
+
field({ path: 'browser.timeoutMs', type: 'number', label: t('browserTimeout'), min: 1000, max: 120000 }));
|
|
481
|
+
const session = group(t('groupSession'),
|
|
482
|
+
field({ path: 'browser.statePath', type: 'text', label: t('statePath'), placeholder: '~/.config/dsh-search/browser/state.json' }));
|
|
483
|
+
const limits = group(t('groupLimits'),
|
|
484
|
+
field({ path: 'browser.maxConcurrentReads', type: 'number', label: t('maxReads'), min: 1, max: 8 }));
|
|
485
|
+
// credentialRow renders the name, the state chip and the note itself; adding the note here again
|
|
486
|
+
// printed the same sentence twice.
|
|
487
|
+
const token = h('div', { class: 'panel pad' }, credentialRow('browser', state.snap.browser, t('browserToken'), t('browserTokenNote')));
|
|
488
|
+
return tabSection(t('tabBrowser'), t('helpBrowser'), connection, session, limits, token);
|
|
489
|
+
}
|
|
403
490
|
|
|
491
|
+
/** A tab: what this section decides, then its groups. */
|
|
492
|
+
function tabSection(title, help, ...groups) {
|
|
404
493
|
return h('section', {},
|
|
405
|
-
h('h2', {},
|
|
406
|
-
h('
|
|
407
|
-
|
|
408
|
-
h('div', { class: 'cards' }, query),
|
|
409
|
-
h('h2', { style: 'margin-top:1.25rem' }, t('advanced')),
|
|
410
|
-
h('div', { class: 'cards' }, retry, cache, breaker, diagnostics, browser, tools));
|
|
494
|
+
h('h2', {}, title),
|
|
495
|
+
h('p', { class: 'note', style: 'margin:-.35rem 0 1rem' }, help),
|
|
496
|
+
...groups);
|
|
411
497
|
}
|
|
412
498
|
|
|
413
499
|
function details(key, title, ...children) {
|
|
@@ -573,7 +659,8 @@ function backendsSection() {
|
|
|
573
659
|
const list = h('div', { class: 'cards', id: 'cards' });
|
|
574
660
|
const summary = h('span', { class: 'chip' }, t('summary', enabled, state.snap.catalog.length, missing));
|
|
575
661
|
const section = h('section', {},
|
|
576
|
-
h('h2', {}, t('
|
|
662
|
+
h('h2', {}, t('tabBackends'), ' ', summary),
|
|
663
|
+
h('p', { class: 'note', style: 'margin:-.35rem 0 1rem' }, t('helpBackends')),
|
|
577
664
|
h('div', { class: 'toolbar' }, search, h('label', { class: 'check' }, only, t('onlyEnabled')), probe),
|
|
578
665
|
list);
|
|
579
666
|
fillCards(list);
|
|
@@ -605,6 +692,260 @@ function renderBanner() {
|
|
|
605
692
|
target.replaceChildren(...pieces);
|
|
606
693
|
}
|
|
607
694
|
|
|
695
|
+
|
|
696
|
+
/** The same six subjects the DSH plugin settings page is split into. */
|
|
697
|
+
const TABS = ['behavior', 'reliability', 'diagnostics', 'backends', 'browser', 'fetch'];
|
|
698
|
+
const TAB_LABELS = {
|
|
699
|
+
behavior: 'tabBehavior', reliability: 'tabReliability', diagnostics: 'tabDiagnostics',
|
|
700
|
+
backends: 'tabBackends', browser: 'tabBrowser', fetch: 'tabFetch',
|
|
701
|
+
};
|
|
702
|
+
|
|
703
|
+
function tabBar() {
|
|
704
|
+
const bar = h('div', { class: 'tabs', role: 'tablist', 'aria-label': t('tabsLabel') });
|
|
705
|
+
for (const id of TABS) {
|
|
706
|
+
const button = h('button', { type: 'button', role: 'tab', class: state.tab === id ? 'tab is-active' : 'tab', 'aria-selected': state.tab === id ? 'true' : 'false' }, t(TAB_LABELS[id]));
|
|
707
|
+
button.addEventListener('click', () => { state.tab = id; localStorage.setItem('wsm.tab', id); render(); });
|
|
708
|
+
bar.append(button);
|
|
709
|
+
}
|
|
710
|
+
return bar;
|
|
711
|
+
}
|
|
712
|
+
|
|
713
|
+
function fetchSection() {
|
|
714
|
+
const tool = h('div', { class: 'panel pad' }, h('h3', {}, t('webExtract')),
|
|
715
|
+
h('div', { class: 'note', style: 'margin:.35rem 0 .6rem' }, t('webExtractHelp')),
|
|
716
|
+
field({ path: 'tools.webExtract', type: 'check', label: t('webExtract') }));
|
|
717
|
+
return h('section', {},
|
|
718
|
+
h('h2', {}, t('tabFetch')),
|
|
719
|
+
h('p', { class: 'note', style: 'margin:-.35rem 0 1rem' }, t('helpFetch')),
|
|
720
|
+
tool,
|
|
721
|
+
fetchReadyPanel(),
|
|
722
|
+
fetchRoutesSection(),
|
|
723
|
+
fetchProviderPanel(),
|
|
724
|
+
fetchLimitsPanel(),
|
|
725
|
+
fetchTestPanel());
|
|
726
|
+
}
|
|
727
|
+
|
|
728
|
+
function fetchReadyPanel() {
|
|
729
|
+
const box = h('div', { class: 'panel pad' }, h('h2', {}, t('fetchReadyTitle')));
|
|
730
|
+
if (state.snap.fetch.ready) box.append(h('div', { class: 'ok-line' }, t('fetchReady')));
|
|
731
|
+
else {
|
|
732
|
+
const list = h('ul', { class: 'problems' });
|
|
733
|
+
for (const problem of state.snap.fetch.problems) list.append(h('li', {}, problemText(problem)));
|
|
734
|
+
box.append(list);
|
|
735
|
+
}
|
|
736
|
+
box.append(h('div', { class: 'note' }, t('fetchReadyHelp')));
|
|
737
|
+
return box;
|
|
738
|
+
}
|
|
739
|
+
|
|
740
|
+
function fetchRoutesSection() {
|
|
741
|
+
const routes = state.draft.pageFetch.routes;
|
|
742
|
+
const section = h('section', {}, h('h2', {}, t('routesTitle')),
|
|
743
|
+
h('p', { class: 'note', style: 'margin:-.35rem 0 .5rem' }, t('routesHelp')),
|
|
744
|
+
h('p', { class: 'note', style: 'margin:0 0 .5rem' }, t('rulesHelp')),
|
|
745
|
+
h('p', { class: 'note', style: 'margin:0 0 .75rem' }, t('presetsHelp')));
|
|
746
|
+
routes.forEach((route, index) => section.append(routeCard(route, index, routes)));
|
|
747
|
+
return section;
|
|
748
|
+
}
|
|
749
|
+
|
|
750
|
+
function routeCard(route, index, routes) {
|
|
751
|
+
const up = h('button', { class: 'ghost small', type: 'button', disabled: index === 0, 'aria-label': t('moveUp') }, '↑');
|
|
752
|
+
up.addEventListener('click', () => {
|
|
753
|
+
const next = routes.slice();
|
|
754
|
+
const target = index - 1;
|
|
755
|
+
const current = next[index];
|
|
756
|
+
next[index] = next[target];
|
|
757
|
+
next[target] = current;
|
|
758
|
+
state.draft.pageFetch.routes = next;
|
|
759
|
+
touch();
|
|
760
|
+
});
|
|
761
|
+
const down = h('button', { class: 'ghost small', type: 'button', disabled: index === routes.length - 1, 'aria-label': t('moveDown') }, '↓');
|
|
762
|
+
down.addEventListener('click', () => {
|
|
763
|
+
const next = routes.slice();
|
|
764
|
+
const target = index + 1;
|
|
765
|
+
const current = next[index];
|
|
766
|
+
next[index] = next[target];
|
|
767
|
+
next[target] = current;
|
|
768
|
+
state.draft.pageFetch.routes = next;
|
|
769
|
+
touch();
|
|
770
|
+
});
|
|
771
|
+
const toggle = checkbox(route.enabled, value => { route.enabled = value; touch(); });
|
|
772
|
+
const timeout = numberInput(route.timeoutMs, value => { route.timeoutMs = value; markDirty(); }, state.snap.fetch.bounds.routeTimeoutMs.min, state.snap.fetch.bounds.routeTimeoutMs.max);
|
|
773
|
+
return h('article', { class: 'route' },
|
|
774
|
+
h('div', { class: 'rule-head' },
|
|
775
|
+
h('label', { class: 'switch' }, toggle, h('span')),
|
|
776
|
+
h('div', { class: 'badges' }, h('strong', {}, t('route.' + route.kind)), h('span', { class: 'badge' }, t('routeHelp.' + route.kind)), h('span', { class: 'badge' }, route.enabled ? t('enabled') : '—')),
|
|
777
|
+
h('div', { class: 'actions' }, up, down)),
|
|
778
|
+
h('label', { class: 'field' }, h('span', {}, t('timeout')), timeout),
|
|
779
|
+
rulesEditor(route));
|
|
780
|
+
}
|
|
781
|
+
|
|
782
|
+
function rulesEditor(route) {
|
|
783
|
+
const bounds = state.snap.fetch.bounds;
|
|
784
|
+
const rules = route.rules;
|
|
785
|
+
const box = h('div', {}, h('span', { class: 'chip' }, t('rulesCount', rules.length, bounds.rulesPerRoute)));
|
|
786
|
+
rules.forEach((rule, index) => box.append(ruleCard(route, rule, index)));
|
|
787
|
+
const canAdd = rules.length < bounds.rulesPerRoute;
|
|
788
|
+
const actions = h('div', { class: 'toolbar' });
|
|
789
|
+
const add = h('button', { class: 'small', type: 'button', disabled: !canAdd }, t('addRule'));
|
|
790
|
+
add.addEventListener('click', () => { rules.push({ id: nextId(rules, 'custom'), enabled: true, conditions: [{ type: 'network' }] }); touch(); });
|
|
791
|
+
const addStatus = h('button', { class: 'small', type: 'button', disabled: !canAdd }, t('addStatusPreset'));
|
|
792
|
+
addStatus.addEventListener('click', () => { const preset = clone(state.snap.fetch.presets.status); preset.id = nextId(rules, preset.id); rules.push(preset); touch(); });
|
|
793
|
+
const addChallenge = h('button', { class: 'small', type: 'button', disabled: !canAdd }, t('addChallengePreset'));
|
|
794
|
+
addChallenge.addEventListener('click', () => { const preset = clone(state.snap.fetch.presets.cloudflare); preset.id = nextId(rules, preset.id); rules.push(preset); touch(); });
|
|
795
|
+
const restore = h('button', { class: 'small ghost', type: 'button' }, t('restoreDefaultRules'));
|
|
796
|
+
restore.addEventListener('click', () => { rules.splice(0, rules.length, ...clone(state.snap.fetch.presets.defaults)); touch(); });
|
|
797
|
+
actions.append(add, addStatus, addChallenge, restore);
|
|
798
|
+
box.append(actions);
|
|
799
|
+
return box;
|
|
800
|
+
}
|
|
801
|
+
|
|
802
|
+
/**
|
|
803
|
+
* A rule folds to one row: its name, whether it is on, and how many conditions it carries. Conditions are
|
|
804
|
+
* the noisy part — three routes times three rules times a condition editor is what made this page a wall.
|
|
805
|
+
*/
|
|
806
|
+
function ruleCard(route, rule, index) {
|
|
807
|
+
const remove = h('button', { class: 'ghost small', type: 'button' }, t('removeRule'));
|
|
808
|
+
remove.addEventListener('click', event => { event.preventDefault(); route.rules.splice(index, 1); touch(); });
|
|
809
|
+
// The summary has to be a direct child of the details element, or the browser renders its own
|
|
810
|
+
// "Details" label and folds everything below it.
|
|
811
|
+
const summary = h('summary', { class: 'rule-head' },
|
|
812
|
+
h('label', { class: 'check' }, checkbox(rule.enabled, value => { rule.enabled = value; touch(); }), h('code', {}, rule.id)),
|
|
813
|
+
h('span', { class: 'chip' }, t('rulesCount', rule.conditions.length, state.snap.fetch.bounds.conditionsPerRule)),
|
|
814
|
+
remove);
|
|
815
|
+
const body = h('div', { class: 'rule-body' });
|
|
816
|
+
rule.conditions.forEach((condition, conditionIndex) => body.append(conditionEditor(route, rule, conditionIndex)));
|
|
817
|
+
const addCondition = h('button', { class: 'ghost small', type: 'button', disabled: rule.conditions.length >= state.snap.fetch.bounds.conditionsPerRule }, t('addCondition'));
|
|
818
|
+
addCondition.addEventListener('click', () => { rule.conditions.push({ type: 'network' }); touch(); });
|
|
819
|
+
body.append(addCondition);
|
|
820
|
+
const key = `${route.kind}:${rule.id}`;
|
|
821
|
+
const card = h('details', { class: 'rule', open: state.open.has(key) }, summary, body);
|
|
822
|
+
card.addEventListener('toggle', () => { if (card.open) state.open.add(key); else state.open.delete(key); });
|
|
823
|
+
return card;
|
|
824
|
+
}
|
|
825
|
+
|
|
826
|
+
function conditionEditor(route, rule, index) {
|
|
827
|
+
const condition = rule.conditions[index];
|
|
828
|
+
const wrap = h('div', { class: 'condition' });
|
|
829
|
+
const types = state.snap.fetch.conditionTypes.filter(type => type !== 'api-status' || route.kind === 'provider');
|
|
830
|
+
wrap.append(selectInput(types.map(type => [type, t('condition.' + type)]), condition.type, value => { rule.conditions[index] = defaultCondition(value); touch(); }));
|
|
831
|
+
if (condition.type === 'status' || condition.type === 'api-status') {
|
|
832
|
+
wrap.append(textInput(condition.statuses.join(', '), value => {
|
|
833
|
+
condition.statuses = value.split(',').map(part => Number(part.trim())).filter(Number.isInteger);
|
|
834
|
+
markDirty();
|
|
835
|
+
}));
|
|
836
|
+
}
|
|
837
|
+
if (condition.type === 'error') {
|
|
838
|
+
const kinds = h('span', { class: 'badges' });
|
|
839
|
+
for (const kind of state.snap.fetch.failureKinds) {
|
|
840
|
+
kinds.append(h('label', { class: 'check' }, checkbox(condition.kinds.includes(kind), value => {
|
|
841
|
+
condition.kinds = value ? [...condition.kinds, kind] : condition.kinds.filter(item => item !== kind);
|
|
842
|
+
touch();
|
|
843
|
+
}), t('failure.' + kind)));
|
|
844
|
+
}
|
|
845
|
+
wrap.append(kinds);
|
|
846
|
+
}
|
|
847
|
+
if (condition.type === 'match') {
|
|
848
|
+
wrap.append(selectInput(state.snap.fetch.conditionFields.map(name => [name, t('matchField.' + name)]), condition.field, value => { condition.field = value; touch(); }));
|
|
849
|
+
wrap.append(selectInput(state.snap.fetch.matchOperators.map(name => [name, t('matchOperator.' + name)]), condition.operator, value => { condition.operator = value; touch(); }));
|
|
850
|
+
wrap.append(textInput(condition.value, value => { condition.value = value; markDirty(); }));
|
|
851
|
+
wrap.append(h('label', { class: 'check' }, checkbox(condition.caseSensitive, value => { condition.caseSensitive = value; touch(); }), t('conditionCase')));
|
|
852
|
+
}
|
|
853
|
+
const remove = h('button', { class: 'ghost small', type: 'button' }, t('removeRule'));
|
|
854
|
+
remove.addEventListener('click', () => { rule.conditions.splice(index, 1); touch(); });
|
|
855
|
+
wrap.append(remove);
|
|
856
|
+
return wrap;
|
|
857
|
+
}
|
|
858
|
+
|
|
859
|
+
function fetchOptionField(providerId, option) {
|
|
860
|
+
const path = `backends.${providerId}.fetch.options.${option.key}`;
|
|
861
|
+
const spec = { path, label: `${local(option.label)} (${option.key})`, hint: local(option.help) };
|
|
862
|
+
if (option.choices) return field({ ...spec, type: 'select', options: option.choices.map(choice => [choice, choice]) });
|
|
863
|
+
if (option.type === 'boolean') return field({ ...spec, type: 'check' });
|
|
864
|
+
if (option.type === 'number') return field({ ...spec, type: 'number', min: option.min ?? 0, max: option.max ?? 1000000 });
|
|
865
|
+
return field({ ...spec, type: 'text' });
|
|
866
|
+
}
|
|
867
|
+
|
|
868
|
+
function fetchProviderPanel() {
|
|
869
|
+
const providers = state.snap.fetch.providers || [];
|
|
870
|
+
const selected = state.draft.pageFetch.providerId;
|
|
871
|
+
const picker = selectInput([['', t('providerNone')], ...providers.map(provider => [provider.id, `${provider.title} · ${provider.serves.join('/')}`])], selected, value => { state.draft.pageFetch.providerId = value; touch(); });
|
|
872
|
+
const panel = h('div', { class: 'panel pad' }, h('label', { class: 'field' }, h('span', {}, t('providerTitle')), picker));
|
|
873
|
+
const provider = providers.find(item => item.id === selected);
|
|
874
|
+
// The readiness entry says whether a provider can be used; the catalog entry carries what its fetch
|
|
875
|
+
// operation offers. Reading the first one for `options` threw, and a section that throws takes the
|
|
876
|
+
// whole tab with it — which is how this tab stopped opening at all.
|
|
877
|
+
const operation = state.snap.catalog.find(item => item.id === provider?.id)?.fetch;
|
|
878
|
+
if (!provider) return h('section', {}, h('h2', {}, t('providerTitle')), h('p', { class: 'note' }, t('providerHelp')), panel);
|
|
879
|
+
const origin = [provider.serves.join(', '), operation?.docs, operation?.verifiedAt].filter(Boolean).join(' · ');
|
|
880
|
+
panel.append(h('div', { class: 'note' }, t('providerServes', origin)));
|
|
881
|
+
panel.append(h('div', { class: 'note' }, provider.credentialRequired ? (provider.credentialConfigured ? t('provCredOk') : t('provCredMissing')) : t('providerCredentialOptional')));
|
|
882
|
+
panel.append(h('div', { class: 'note' }, t('providerMarkdownOnly')));
|
|
883
|
+
panel.append(h('div', { class: 'note' }, t('providerFields')));
|
|
884
|
+
panel.append(h('div', { class: 'row' },
|
|
885
|
+
field({ path: `backends.${provider.id}.fetch.mode`, type: 'select', label: t('fetchMode'), options: provider.modes.map(mode => [mode, mode]) }),
|
|
886
|
+
field({ path: `backends.${provider.id}.fetch.endpoint`, type: 'text', label: t('fetchEndpoint') }),
|
|
887
|
+
field({ path: `backends.${provider.id}.fetch.timeoutMs`, type: 'number', label: t('providerTimeout'), min: state.snap.fetch.bounds.routeTimeoutMs.min, max: state.snap.fetch.bounds.routeTimeoutMs.max })));
|
|
888
|
+
const options = operation?.options ?? [];
|
|
889
|
+
if (options.length) {
|
|
890
|
+
const grid = h('div', { class: 'row' });
|
|
891
|
+
for (const option of options) grid.append(fetchOptionField(provider.id, option));
|
|
892
|
+
panel.append(grid);
|
|
893
|
+
}
|
|
894
|
+
return h('section', {}, h('h2', {}, t('providerTitle')), h('p', { class: 'note' }, t('providerHelp')), panel);
|
|
895
|
+
}
|
|
896
|
+
|
|
897
|
+
function fetchLimitsPanel() {
|
|
898
|
+
const bounds = state.snap.fetch.bounds;
|
|
899
|
+
return h('section', {}, h('h2', {}, t('limitsTitle')), h('div', { class: 'panel pad' }, h('div', { class: 'row' },
|
|
900
|
+
field({ path: 'pageFetch.overallTimeoutMs', type: 'number', label: t('fetchOverallTimeout'), min: bounds.overallTimeoutMs.min, max: bounds.overallTimeoutMs.max }),
|
|
901
|
+
field({ path: 'pageFetch.maxRedirects', type: 'number', label: t('maxRedirects'), min: bounds.maxRedirects.min, max: bounds.maxRedirects.max }),
|
|
902
|
+
field({ path: 'pageFetch.maxBodyBytes', type: 'number', label: t('maxBodyBytes'), min: bounds.maxBodyBytes.min, max: bounds.maxBodyBytes.max }),
|
|
903
|
+
field({ path: 'pageFetch.maxOutputChars', type: 'number', label: t('maxOutputChars'), min: bounds.maxOutputChars.min, max: bounds.maxOutputChars.max }),
|
|
904
|
+
field({ path: 'pageFetch.maxRuleScanChars', type: 'number', label: t('maxRuleScanChars'), min: bounds.maxRuleScanChars.min, max: bounds.maxRuleScanChars.max }),
|
|
905
|
+
field({ path: 'pageFetch.allowPrivateNetworks', type: 'check', label: t('allowPrivateNetworks') }),
|
|
906
|
+
field({ path: 'pageFetch.browser.context', type: 'select', label: t('browserContext'), options: [['isolated', t('contextIsolated')], ['session', t('contextSession')]] }),
|
|
907
|
+
field({ path: 'pageFetch.browser.settleMs', type: 'number', label: t('settleMs'), min: bounds.settleMs.min, max: bounds.settleMs.max }),
|
|
908
|
+
field({ path: 'pageFetch.browser.challengeSolver', type: 'select', label: t('challengeSolver'), options: [['auto', t('solverAuto')], ['off', t('solverOff')]] }),
|
|
909
|
+
field({ path: 'pageFetch.browser.selectorWait', type: 'text', label: t('selectorWait') }))));
|
|
910
|
+
}
|
|
911
|
+
|
|
912
|
+
function fetchTestPanel() {
|
|
913
|
+
const url = textInput(state.fetchUrl || '', value => { state.fetchUrl = value; });
|
|
914
|
+
url.placeholder = 'https://example.com/page';
|
|
915
|
+
const format = selectInput([['markdown', t('formatMarkdown')], ['html', t('formatHtml')]], state.fetchFormat, value => { state.fetchFormat = value; });
|
|
916
|
+
const run = h('button', { class: 'primary', type: 'button', disabled: state.fetchBusy || !String(state.fetchUrl || '').trim() }, state.fetchBusy ? t('testing') : t('runFetchTest'));
|
|
917
|
+
run.addEventListener('click', () => void runFetchTest());
|
|
918
|
+
const panel = h('div', { class: 'panel pad' },
|
|
919
|
+
h('p', { class: 'note' }, t('fetchTestHelp')),
|
|
920
|
+
h('div', { class: 'row' },
|
|
921
|
+
h('label', { class: 'field' }, h('span', {}, t('fetchTest')), url),
|
|
922
|
+
h('label', { class: 'field' }, h('span', {}, t('fetchTestResult')), format)),
|
|
923
|
+
h('div', { class: 'toolbar' }, run, state.dirty ? h('span', { class: 'note' }, t('saveFirst')) : null));
|
|
924
|
+
if (state.fetchResult) panel.append(h('div', { class: 'panel pad' }, h('strong', {}, t('fetchTestResult')), h('pre', { class: 'out' }, state.fetchResult.text || state.fetchResult.error || '')));
|
|
925
|
+
return h('section', {}, h('h2', {}, t('fetchTest')), panel);
|
|
926
|
+
}
|
|
927
|
+
|
|
928
|
+
async function runFetchTest() {
|
|
929
|
+
const url = String(state.fetchUrl || '').trim();
|
|
930
|
+
if (!url) return;
|
|
931
|
+
state.fetchBusy = true;
|
|
932
|
+
state.fetchResult = { text: t('testing') };
|
|
933
|
+
render();
|
|
934
|
+
try {
|
|
935
|
+
const response = await fetch('/api/fetch-test', {
|
|
936
|
+
method: 'POST',
|
|
937
|
+
headers: { 'Content-Type': 'application/json' },
|
|
938
|
+
body: JSON.stringify({ url, format: state.fetchFormat }),
|
|
939
|
+
});
|
|
940
|
+
const data = await response.json().catch(() => ({}));
|
|
941
|
+
state.fetchResult = data.ok ? { text: data.text } : { error: data.error || 'fetch failed' };
|
|
942
|
+
} catch (error) {
|
|
943
|
+
state.fetchResult = { error: String(error) };
|
|
944
|
+
}
|
|
945
|
+
state.fetchBusy = false;
|
|
946
|
+
render();
|
|
947
|
+
}
|
|
948
|
+
|
|
608
949
|
function render() {
|
|
609
950
|
document.getElementById('version').textContent = state.snap.version || 'dev';
|
|
610
951
|
document.getElementById('revision').textContent = state.snap.revision;
|
|
@@ -613,17 +954,35 @@ function render() {
|
|
|
613
954
|
authChip.hidden = !noAuth;
|
|
614
955
|
if (noAuth) authChip.textContent = t('noAuth');
|
|
615
956
|
document.getElementById('configPath').textContent = state.snap.configPath;
|
|
616
|
-
document.getElementById('lang').textContent = state.lang === 'zh' ? 'EN' : '中文';
|
|
617
957
|
document.getElementById('reload').textContent = t('reload');
|
|
618
958
|
document.getElementById('save').textContent = t('save');
|
|
619
959
|
const companion = state.snap.companion?.active
|
|
620
960
|
? ` · ${t('companionOn')} ${state.snap.companion.path}`
|
|
621
961
|
: '';
|
|
622
962
|
document.getElementById('foot').textContent = `${t('foot', state.snap.bound?.host ?? '', state.snap.bound?.port ?? '')}${companion}`;
|
|
623
|
-
document.documentElement.lang = state.lang === 'zh' ? 'zh-CN' : 'en';
|
|
624
963
|
renderBanner();
|
|
625
964
|
const app = document.getElementById('app');
|
|
626
|
-
|
|
965
|
+
const sections = {
|
|
966
|
+
behavior: behaviorSection,
|
|
967
|
+
reliability: reliabilitySection,
|
|
968
|
+
diagnostics: diagnosticsSection,
|
|
969
|
+
backends: backendsSection,
|
|
970
|
+
browser: browserSection,
|
|
971
|
+
fetch: fetchSection,
|
|
972
|
+
};
|
|
973
|
+
// A section that throws must not leave the reader on the previous tab wondering why the button did
|
|
974
|
+
// nothing: the tab still switches and the failure is visible, with its message.
|
|
975
|
+
let body;
|
|
976
|
+
try {
|
|
977
|
+
body = (sections[state.tab] || behaviorSection)();
|
|
978
|
+
} catch (error) {
|
|
979
|
+
const message = error instanceof Error ? `${error.name}: ${error.message}` : String(error);
|
|
980
|
+
console.error(`section ${state.tab} failed`, error);
|
|
981
|
+
body = h('section', {}, h('h2', {}, t(TAB_LABELS[state.tab] || 'tabBehavior')),
|
|
982
|
+
h('div', { class: 'panel pad' }, h('strong', {}, t('sectionFailed')),
|
|
983
|
+
h('pre', { class: 'out', style: 'margin-top:.5rem' }, message)));
|
|
984
|
+
}
|
|
985
|
+
app.replaceChildren(tabBar(), body);
|
|
627
986
|
bindFields(app);
|
|
628
987
|
for (const issue of state.issues) {
|
|
629
988
|
const input = app.querySelector(`[data-path="${issue.path}"]`);
|
|
@@ -678,13 +1037,10 @@ async function save() {
|
|
|
678
1037
|
}
|
|
679
1038
|
|
|
680
1039
|
function boot() {
|
|
1040
|
+
const remembered = localStorage.getItem('wsm.tab');
|
|
1041
|
+
if (remembered && TABS.includes(remembered)) state.tab = remembered;
|
|
681
1042
|
document.getElementById('save').addEventListener('click', save);
|
|
682
1043
|
document.getElementById('reload').addEventListener('click', async () => { state.issues = []; await refresh(); markClean(); toast(t('reloaded')); });
|
|
683
|
-
document.getElementById('lang').addEventListener('click', () => {
|
|
684
|
-
state.lang = state.lang === 'zh' ? 'en' : 'zh';
|
|
685
|
-
localStorage.setItem('wsm.lang', state.lang);
|
|
686
|
-
render();
|
|
687
|
-
});
|
|
688
1044
|
refresh();
|
|
689
1045
|
}
|
|
690
1046
|
|