@jayyuen66/dsh-scrapling 0.1.0 → 0.1.2
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 +113 -0
- package/LICENSE +1 -1
- package/README.md +252 -547
- package/README.zh-CN.md +246 -395
- package/client.js +3 -1384
- package/host.js +28 -22
- package/package.json +41 -40
- package/py/adapters.py +77 -26
- package/py/bridge.py +29 -2
- package/py/crawl.py +71 -7
- package/py/guard.py +44 -18
package/client.js
CHANGED
|
@@ -5,826 +5,7 @@ window.__ModuleLoader__.load({
|
|
|
5
5
|
"use strict";
|
|
6
6
|
var module = { exports: {} };
|
|
7
7
|
var exports = module.exports;
|
|
8
|
-
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
9
|
-
let react = require("react");
|
|
10
|
-
//#region node_modules/.pnpm/@jayyuen66+dsh-plugin-shared@0.1.6_e9e956f77cb41a293465ea365a86fee3/node_modules/@jayyuen66/dsh-plugin-shared/dist/card-apply.js
|
|
11
|
-
function e$1(e, t, n) {
|
|
12
|
-
let r = globalThis;
|
|
13
|
-
if (Object.hasOwn(r, t) && r[t] === !0) return !1;
|
|
14
|
-
r[t] = !0;
|
|
15
|
-
try {
|
|
16
|
-
e.effect(() => () => {
|
|
17
|
-
r[t] = void 0;
|
|
18
|
-
}, n);
|
|
19
|
-
} catch (e) {
|
|
20
|
-
throw r[t] = void 0, e;
|
|
21
|
-
}
|
|
22
|
-
return !0;
|
|
23
|
-
}
|
|
24
|
-
//#endregion
|
|
25
|
-
//#region node_modules/.pnpm/@jayyuen66+dsh-plugin-shared@0.1.6_e9e956f77cb41a293465ea365a86fee3/node_modules/@jayyuen66/dsh-plugin-shared/dist/record.js
|
|
26
|
-
function e(e) {
|
|
27
|
-
return typeof e == `object` && !!e && !Array.isArray(e);
|
|
28
|
-
}
|
|
29
|
-
//#endregion
|
|
30
|
-
//#region src/settings-fields.ts
|
|
31
|
-
/** 设置卡对应的 Host 条目 id(cordis.patch.yml 里 `insert` 的 `id`),也是设置命名空间。 */
|
|
32
|
-
const SETTINGS_ENTRY_ID = "scrapling";
|
|
33
|
-
/** 本包在插件管理器里的包名,也就是 `plugins.bundle.config` 这张 keyed slot 的键。 */
|
|
34
|
-
const BUNDLE_PACKAGE_NAME = "@jayyuen66/dsh-scrapling";
|
|
35
|
-
/** 字段表。顺序即卡上的呈现顺序,按「先让用户认出东西、再调细节」排。 */
|
|
36
|
-
const SETTINGS_GROUPS = [
|
|
37
|
-
{
|
|
38
|
-
id: "runtime",
|
|
39
|
-
title: {
|
|
40
|
-
zh: "运行环境",
|
|
41
|
-
en: "Runtime"
|
|
42
|
-
},
|
|
43
|
-
note: {
|
|
44
|
-
zh: "Python 与数据目录。装完 scrapling 之后这里一般不用动。",
|
|
45
|
-
en: "Python and the data directory. Usually untouched once scrapling is installed."
|
|
46
|
-
},
|
|
47
|
-
fields: [
|
|
48
|
-
{
|
|
49
|
-
key: "pythonBin",
|
|
50
|
-
kind: "text",
|
|
51
|
-
label: {
|
|
52
|
-
zh: "Python 解释器",
|
|
53
|
-
en: "Python interpreter"
|
|
54
|
-
},
|
|
55
|
-
hint: {
|
|
56
|
-
zh: "留空用 PATH 上的 python3;装了 pyenv/conda 时填绝对路径。",
|
|
57
|
-
en: "Leave empty to use python3 from PATH; give an absolute path under pyenv/conda."
|
|
58
|
-
},
|
|
59
|
-
fallback: ""
|
|
60
|
-
},
|
|
61
|
-
{
|
|
62
|
-
key: "failFastOnMissingPython",
|
|
63
|
-
kind: "boolean",
|
|
64
|
-
label: {
|
|
65
|
-
zh: "Python 缺失时拒绝加载",
|
|
66
|
-
en: "Fail fast without Python"
|
|
67
|
-
},
|
|
68
|
-
hint: {
|
|
69
|
-
zh: "开:Python 起不来就不注册任何工具并报错。关:只警告,工具全部消失。",
|
|
70
|
-
en: "On: register nothing and error out. Off: warn and register nothing."
|
|
71
|
-
},
|
|
72
|
-
fallback: true
|
|
73
|
-
},
|
|
74
|
-
{
|
|
75
|
-
key: "dataDir",
|
|
76
|
-
kind: "text",
|
|
77
|
-
label: {
|
|
78
|
-
zh: "数据目录",
|
|
79
|
-
en: "Data directory"
|
|
80
|
-
},
|
|
81
|
-
hint: {
|
|
82
|
-
zh: "留空用 ~/.dsh-scrapling;选择器自愈的指纹库落在这里,需要可写。",
|
|
83
|
-
en: "Leave empty for ~/.dsh-scrapling; the adaptive selector store lives here and must be writable."
|
|
84
|
-
},
|
|
85
|
-
fallback: ""
|
|
86
|
-
}
|
|
87
|
-
]
|
|
88
|
-
},
|
|
89
|
-
{
|
|
90
|
-
id: "tools",
|
|
91
|
-
title: {
|
|
92
|
-
zh: "工具开关",
|
|
93
|
-
en: "Tools"
|
|
94
|
-
},
|
|
95
|
-
note: {
|
|
96
|
-
zh: "关掉的工具不会注册给模型,也不会在会话提示里占位置。",
|
|
97
|
-
en: "A disabled tool is never registered with the model and leaves the system prompt too."
|
|
98
|
-
},
|
|
99
|
-
fields: [
|
|
100
|
-
{
|
|
101
|
-
key: "fetchEnabled",
|
|
102
|
-
kind: "boolean",
|
|
103
|
-
label: {
|
|
104
|
-
zh: "scrapling_fetch",
|
|
105
|
-
en: "scrapling_fetch"
|
|
106
|
-
},
|
|
107
|
-
hint: {
|
|
108
|
-
zh: "curl_cffi 静态抓取。",
|
|
109
|
-
en: "Static fetching over curl_cffi."
|
|
110
|
-
},
|
|
111
|
-
fallback: true
|
|
112
|
-
},
|
|
113
|
-
{
|
|
114
|
-
key: "extractEnabled",
|
|
115
|
-
kind: "boolean",
|
|
116
|
-
label: {
|
|
117
|
-
zh: "scrapling_extract",
|
|
118
|
-
en: "scrapling_extract"
|
|
119
|
-
},
|
|
120
|
-
hint: {
|
|
121
|
-
zh: "对给定 HTML 做选择器抽取,不发请求。",
|
|
122
|
-
en: "Extract from given HTML without any request."
|
|
123
|
-
},
|
|
124
|
-
fallback: true
|
|
125
|
-
},
|
|
126
|
-
{
|
|
127
|
-
key: "renderEnabled",
|
|
128
|
-
kind: "boolean",
|
|
129
|
-
label: {
|
|
130
|
-
zh: "scrapling_render",
|
|
131
|
-
en: "scrapling_render"
|
|
132
|
-
},
|
|
133
|
-
hint: {
|
|
134
|
-
zh: "Playwright 渲染,能读 SPA。",
|
|
135
|
-
en: "Playwright rendering; reads SPAs."
|
|
136
|
-
},
|
|
137
|
-
fallback: true
|
|
138
|
-
},
|
|
139
|
-
{
|
|
140
|
-
key: "captureXhrEnabled",
|
|
141
|
-
kind: "boolean",
|
|
142
|
-
label: {
|
|
143
|
-
zh: "scrapling_capture_xhr",
|
|
144
|
-
en: "scrapling_capture_xhr"
|
|
145
|
-
},
|
|
146
|
-
hint: {
|
|
147
|
-
zh: "只回传 XHR 的 URL/状态/字节数;站点数据在接口里时用它找那个接口。",
|
|
148
|
-
en: "Returns XHR url/status/bytes only — use it to locate the JSON endpoint."
|
|
149
|
-
},
|
|
150
|
-
fallback: true
|
|
151
|
-
},
|
|
152
|
-
{
|
|
153
|
-
key: "networkEnabled",
|
|
154
|
-
kind: "boolean",
|
|
155
|
-
label: {
|
|
156
|
-
zh: "scrapling_session_network",
|
|
157
|
-
en: "scrapling_session_network"
|
|
158
|
-
},
|
|
159
|
-
hint: {
|
|
160
|
-
zh: "读已开会话攒下的网络历史;会话需先用 recordNetwork 打开记录。",
|
|
161
|
-
en: "Read a session's recorded network history; the session must have recordNetwork on."
|
|
162
|
-
},
|
|
163
|
-
fallback: true
|
|
164
|
-
},
|
|
165
|
-
{
|
|
166
|
-
key: "sessionEnabled",
|
|
167
|
-
kind: "boolean",
|
|
168
|
-
label: {
|
|
169
|
-
zh: "scrapling_session_*",
|
|
170
|
-
en: "scrapling_session_*"
|
|
171
|
-
},
|
|
172
|
-
hint: {
|
|
173
|
-
zh: "跨请求复用 cookie 与浏览器实例。",
|
|
174
|
-
en: "Reuse cookies and the browser across requests."
|
|
175
|
-
},
|
|
176
|
-
fallback: true
|
|
177
|
-
},
|
|
178
|
-
{
|
|
179
|
-
key: "sessionStateEnabled",
|
|
180
|
-
kind: "boolean",
|
|
181
|
-
label: {
|
|
182
|
-
zh: "scrapling_session_state_*",
|
|
183
|
-
en: "scrapling_session_state_*"
|
|
184
|
-
},
|
|
185
|
-
hint: {
|
|
186
|
-
zh: "存/取浏览器登录态;需部署侧配好 sessionStateDir。",
|
|
187
|
-
en: "Save/load browser login state; needs a deployment-side sessionStateDir."
|
|
188
|
-
},
|
|
189
|
-
fallback: true
|
|
190
|
-
},
|
|
191
|
-
{
|
|
192
|
-
key: "crawlEnabled",
|
|
193
|
-
kind: "boolean",
|
|
194
|
-
label: {
|
|
195
|
-
zh: "scrapling_crawl",
|
|
196
|
-
en: "scrapling_crawl"
|
|
197
|
-
},
|
|
198
|
-
hint: {
|
|
199
|
-
zh: "后台 Spider 作业,只守起始域;需 profile 带作业后端。",
|
|
200
|
-
en: "Background spider jobs confined to the start domain; needs a jobs backend."
|
|
201
|
-
},
|
|
202
|
-
fallback: true
|
|
203
|
-
},
|
|
204
|
-
{
|
|
205
|
-
key: "answerEnabled",
|
|
206
|
-
kind: "boolean",
|
|
207
|
-
label: {
|
|
208
|
-
zh: "scrapling_answer",
|
|
209
|
-
en: "scrapling_answer"
|
|
210
|
-
},
|
|
211
|
-
hint: {
|
|
212
|
-
zh: "抓完页面交给模型问答。",
|
|
213
|
-
en: "Answer a question over a fetched page."
|
|
214
|
-
},
|
|
215
|
-
fallback: true
|
|
216
|
-
}
|
|
217
|
-
]
|
|
218
|
-
},
|
|
219
|
-
{
|
|
220
|
-
id: "output",
|
|
221
|
-
title: {
|
|
222
|
-
zh: "抽取与输出",
|
|
223
|
-
en: "Extraction & output"
|
|
224
|
-
},
|
|
225
|
-
note: {
|
|
226
|
-
zh: "这几个数字直接决定模型每轮看到多少 token。",
|
|
227
|
-
en: "These numbers are the per-call token bill the model pays."
|
|
228
|
-
},
|
|
229
|
-
fields: [
|
|
230
|
-
{
|
|
231
|
-
key: "extractionType",
|
|
232
|
-
kind: "enum",
|
|
233
|
-
label: {
|
|
234
|
-
zh: "默认抽取形态",
|
|
235
|
-
en: "Default extraction"
|
|
236
|
-
},
|
|
237
|
-
hint: {
|
|
238
|
-
zh: "markdown 最省 token;html 保留标签;text 只留文字。",
|
|
239
|
-
en: "markdown is cheapest; html keeps tags; text keeps words only."
|
|
240
|
-
},
|
|
241
|
-
fallback: "markdown",
|
|
242
|
-
options: [
|
|
243
|
-
"markdown",
|
|
244
|
-
"html",
|
|
245
|
-
"text"
|
|
246
|
-
]
|
|
247
|
-
},
|
|
248
|
-
{
|
|
249
|
-
key: "mainContentOnly",
|
|
250
|
-
kind: "boolean",
|
|
251
|
-
label: {
|
|
252
|
-
zh: "只保留正文",
|
|
253
|
-
en: "Main content only"
|
|
254
|
-
},
|
|
255
|
-
hint: {
|
|
256
|
-
zh: "去掉导航、页脚、侧栏。开:更短更干净;关:抓页面控件类目标需要它。",
|
|
257
|
-
en: "Drop nav/footer/sidebar. On for shorter output; off when you need page chrome."
|
|
258
|
-
},
|
|
259
|
-
fallback: true
|
|
260
|
-
},
|
|
261
|
-
{
|
|
262
|
-
key: "fetchMaxOutputChars",
|
|
263
|
-
kind: "number",
|
|
264
|
-
label: {
|
|
265
|
-
zh: "静态抓取正文上限",
|
|
266
|
-
en: "fetch output cap"
|
|
267
|
-
},
|
|
268
|
-
hint: {
|
|
269
|
-
zh: "字符数,超出部分截断并标注。",
|
|
270
|
-
en: "Characters; the payload is clipped and flagged."
|
|
271
|
-
},
|
|
272
|
-
fallback: 2e5
|
|
273
|
-
},
|
|
274
|
-
{
|
|
275
|
-
key: "extractMaxOutputChars",
|
|
276
|
-
kind: "number",
|
|
277
|
-
label: {
|
|
278
|
-
zh: "抽取结果上限",
|
|
279
|
-
en: "extract output cap"
|
|
280
|
-
},
|
|
281
|
-
hint: {
|
|
282
|
-
zh: "字符数。",
|
|
283
|
-
en: "Characters."
|
|
284
|
-
},
|
|
285
|
-
fallback: 2e5
|
|
286
|
-
},
|
|
287
|
-
{
|
|
288
|
-
key: "renderMaxOutputChars",
|
|
289
|
-
kind: "number",
|
|
290
|
-
label: {
|
|
291
|
-
zh: "渲染结果上限",
|
|
292
|
-
en: "render output cap"
|
|
293
|
-
},
|
|
294
|
-
hint: {
|
|
295
|
-
zh: "字符数;会话类工具共用这一档。",
|
|
296
|
-
en: "Characters; the session tools share this budget."
|
|
297
|
-
},
|
|
298
|
-
fallback: 2e5
|
|
299
|
-
},
|
|
300
|
-
{
|
|
301
|
-
key: "xhrMaxOutputChars",
|
|
302
|
-
kind: "number",
|
|
303
|
-
label: {
|
|
304
|
-
zh: "XHR 快照上限",
|
|
305
|
-
en: "XHR snapshot cap"
|
|
306
|
-
},
|
|
307
|
-
hint: {
|
|
308
|
-
zh: "字符数。",
|
|
309
|
-
en: "Characters."
|
|
310
|
-
},
|
|
311
|
-
fallback: 12e4
|
|
312
|
-
},
|
|
313
|
-
{
|
|
314
|
-
key: "crawlMaxItems",
|
|
315
|
-
kind: "number",
|
|
316
|
-
label: {
|
|
317
|
-
zh: "爬虫默认页数上限",
|
|
318
|
-
en: "Crawl page cap"
|
|
319
|
-
},
|
|
320
|
-
hint: {
|
|
321
|
-
zh: "爬虫工具每次调用的默认上限,模型可按次调小。",
|
|
322
|
-
en: "Default per-call page cap; the model may lower it per call."
|
|
323
|
-
},
|
|
324
|
-
fallback: 1e3
|
|
325
|
-
},
|
|
326
|
-
{
|
|
327
|
-
key: "stripInlineImages",
|
|
328
|
-
kind: "boolean",
|
|
329
|
-
label: {
|
|
330
|
-
zh: "剥掉内嵌 base64 图片",
|
|
331
|
-
en: "Strip inline base64 images"
|
|
332
|
-
},
|
|
333
|
-
hint: {
|
|
334
|
-
zh: "默认开。内嵌 data: URI 图片对模型是纯 token 噪音——模型从 base64 里读不出任何图形信息,只留 alt 文本;代码围栏内的原样保留。没有内联图的页面不受影响。要从 base64 里取配色或指纹这类原始数据时才关掉。",
|
|
335
|
-
en: "On by default. Inline data: URI images are pure token noise - the model cannot read a shape out of base64, so only the alt text is kept; ones inside code fences are left alone. Pages without inline images are unaffected. Turn it off to read the raw base64 (colours, fingerprints)."
|
|
336
|
-
},
|
|
337
|
-
fallback: true
|
|
338
|
-
}
|
|
339
|
-
]
|
|
340
|
-
},
|
|
341
|
-
{
|
|
342
|
-
id: "browser",
|
|
343
|
-
title: {
|
|
344
|
-
zh: "浏览器行为",
|
|
345
|
-
en: "Browser behaviour"
|
|
346
|
-
},
|
|
347
|
-
note: {
|
|
348
|
-
zh: "只在渲染 / XHR 两条路径上生效。",
|
|
349
|
-
en: "Only affects the render / XHR paths."
|
|
350
|
-
},
|
|
351
|
-
fields: [
|
|
352
|
-
{
|
|
353
|
-
key: "headless",
|
|
354
|
-
kind: "boolean",
|
|
355
|
-
label: {
|
|
356
|
-
zh: "无头运行",
|
|
357
|
-
en: "Headless"
|
|
358
|
-
},
|
|
359
|
-
hint: {
|
|
360
|
-
zh: "关掉会弹出浏览器窗口,反检测站点上成功率更高。",
|
|
361
|
-
en: "Off shows a window and beats more anti-bot checks."
|
|
362
|
-
},
|
|
363
|
-
fallback: true
|
|
364
|
-
},
|
|
365
|
-
{
|
|
366
|
-
key: "networkIdle",
|
|
367
|
-
kind: "boolean",
|
|
368
|
-
label: {
|
|
369
|
-
zh: "等网络静默",
|
|
370
|
-
en: "Wait for network idle"
|
|
371
|
-
},
|
|
372
|
-
hint: {
|
|
373
|
-
zh: "等到没有在途请求再返回。更准,但慢;埋了长连接的站点可能一直等不到。",
|
|
374
|
-
en: "Wait until no requests are in flight. Slower, and pages with long-lived sockets never settle."
|
|
375
|
-
},
|
|
376
|
-
fallback: false
|
|
377
|
-
},
|
|
378
|
-
{
|
|
379
|
-
key: "blockAds",
|
|
380
|
-
kind: "boolean",
|
|
381
|
-
label: {
|
|
382
|
-
zh: "拦截广告与追踪",
|
|
383
|
-
en: "Block ads and trackers"
|
|
384
|
-
},
|
|
385
|
-
hint: {
|
|
386
|
-
zh: "约 3500 个已知广告域。省流量,偶尔误伤。",
|
|
387
|
-
en: "~3,500 known ad domains. Saves bandwidth, occasionally over-blocks."
|
|
388
|
-
},
|
|
389
|
-
fallback: true
|
|
390
|
-
},
|
|
391
|
-
{
|
|
392
|
-
key: "pierceShadow",
|
|
393
|
-
kind: "boolean",
|
|
394
|
-
label: {
|
|
395
|
-
zh: "穿透 Shadow DOM",
|
|
396
|
-
en: "Pierce Shadow DOM"
|
|
397
|
-
},
|
|
398
|
-
hint: {
|
|
399
|
-
zh: "把 open shadow root 里的内容并进正文,默认关;页面把正文封进 shadow DOM 时才打开。",
|
|
400
|
-
en: "Merge open shadow root content into the body; off by default. On when a page hides its content in shadow DOM."
|
|
401
|
-
},
|
|
402
|
-
fallback: false
|
|
403
|
-
},
|
|
404
|
-
{
|
|
405
|
-
key: "waitSelectorState",
|
|
406
|
-
kind: "enum",
|
|
407
|
-
label: {
|
|
408
|
-
zh: "等待选择器的状态",
|
|
409
|
-
en: "Wait selector state"
|
|
410
|
-
},
|
|
411
|
-
hint: {
|
|
412
|
-
zh: "配 waitSelector 用;attached 最宽松。",
|
|
413
|
-
en: "Used with waitSelector; attached is the loosest."
|
|
414
|
-
},
|
|
415
|
-
fallback: "attached",
|
|
416
|
-
options: [
|
|
417
|
-
"attached",
|
|
418
|
-
"detached",
|
|
419
|
-
"hidden",
|
|
420
|
-
"visible"
|
|
421
|
-
]
|
|
422
|
-
}
|
|
423
|
-
]
|
|
424
|
-
},
|
|
425
|
-
{
|
|
426
|
-
id: "timeouts",
|
|
427
|
-
title: {
|
|
428
|
-
zh: "超时与回收",
|
|
429
|
-
en: "Timeouts & teardown"
|
|
430
|
-
},
|
|
431
|
-
note: {
|
|
432
|
-
zh: "抓取慢若不在这几项里,先看页面上要等的东西。",
|
|
433
|
-
en: "If a fetch is slow for a reason other than these, look at what the page waits for."
|
|
434
|
-
},
|
|
435
|
-
fields: [
|
|
436
|
-
{
|
|
437
|
-
key: "fetchTimeoutMs",
|
|
438
|
-
kind: "number",
|
|
439
|
-
label: {
|
|
440
|
-
zh: "单次抓取超时(毫秒)",
|
|
441
|
-
en: "Per-fetch timeout (ms)"
|
|
442
|
-
},
|
|
443
|
-
hint: {
|
|
444
|
-
zh: "同时是工具的超时预算与 Python 侧的请求上限。",
|
|
445
|
-
en: "Also the tool budget and the Python-side request cap."
|
|
446
|
-
},
|
|
447
|
-
fallback: 12e4
|
|
448
|
-
},
|
|
449
|
-
{
|
|
450
|
-
key: "sidecarHandshakeTimeoutMs",
|
|
451
|
-
kind: "number",
|
|
452
|
-
label: {
|
|
453
|
-
zh: "sidecar 握手超时(毫秒)",
|
|
454
|
-
en: "Handshake timeout (ms)"
|
|
455
|
-
},
|
|
456
|
-
hint: {
|
|
457
|
-
zh: "冷启动要拉起一个 Python 进程并导入 Scrapling。",
|
|
458
|
-
en: "Cold start spawns a Python process and imports Scrapling."
|
|
459
|
-
},
|
|
460
|
-
fallback: 3e4
|
|
461
|
-
},
|
|
462
|
-
{
|
|
463
|
-
key: "sidecarGraceMs",
|
|
464
|
-
kind: "number",
|
|
465
|
-
label: {
|
|
466
|
-
zh: "退出宽限(毫秒)",
|
|
467
|
-
en: "Shutdown grace (ms)"
|
|
468
|
-
},
|
|
469
|
-
hint: {
|
|
470
|
-
zh: "插件卸载后等 Python 收尾的时间。",
|
|
471
|
-
en: "How long Python gets to finish after the plugin unloads."
|
|
472
|
-
},
|
|
473
|
-
fallback: 5e3
|
|
474
|
-
}
|
|
475
|
-
]
|
|
476
|
-
},
|
|
477
|
-
{
|
|
478
|
-
id: "network",
|
|
479
|
-
title: {
|
|
480
|
-
zh: "网络与安全",
|
|
481
|
-
en: "Network & safety"
|
|
482
|
-
},
|
|
483
|
-
note: {
|
|
484
|
-
zh: "通常什么都不用填:TUN 模式的代理由系统接管,环境里的 HTTPS_PROXY 与 macOS / Windows 的「系统代理」都会被自动接上。",
|
|
485
|
-
en: "Usually nothing to fill: a TUN-mode proxy is taken from the system, and both HTTPS_PROXY in the environment and the macOS / Windows system proxy are picked up automatically."
|
|
486
|
-
},
|
|
487
|
-
fields: [
|
|
488
|
-
{
|
|
489
|
-
key: "proxyUrl",
|
|
490
|
-
kind: "text",
|
|
491
|
-
secret: true,
|
|
492
|
-
label: {
|
|
493
|
-
zh: "代理地址",
|
|
494
|
-
en: "Proxy URL"
|
|
495
|
-
},
|
|
496
|
-
hint: {
|
|
497
|
-
zh: "如 http://127.0.0.1:7890 或 socks5://127.0.0.1:7890,可带 user:pass@。留空=依次跟随环境变量与系统代理设置;填了就压过那两者。值按密码遮罩显示,点「显示」可查看。",
|
|
498
|
-
en: "e.g. http://127.0.0.1:7890 or socks5://127.0.0.1:7890, user:pass@ allowed. Empty follows the environment and then the OS proxy settings; setting it outranks both. Masked like a password; press Show to reveal it."
|
|
499
|
-
},
|
|
500
|
-
fallback: ""
|
|
501
|
-
},
|
|
502
|
-
{
|
|
503
|
-
key: "proxyBypass",
|
|
504
|
-
kind: "text",
|
|
505
|
-
label: {
|
|
506
|
-
zh: "代理绕过清单",
|
|
507
|
-
en: "Proxy bypass"
|
|
508
|
-
},
|
|
509
|
-
hint: {
|
|
510
|
-
zh: "逗号分隔的主机名,命中即直连;内网站点要填。整台机器直连填 *。浏览器会话不逐条生效(它的代理在开场时定死)。",
|
|
511
|
-
en: "Comma-separated hostnames that connect directly; list your internal sites. Use * for the whole machine. Not applied per URL inside a browser session (its proxy is fixed at open)."
|
|
512
|
-
},
|
|
513
|
-
fallback: ""
|
|
514
|
-
},
|
|
515
|
-
{
|
|
516
|
-
key: "syntheticDnsRanges",
|
|
517
|
-
kind: "text",
|
|
518
|
-
label: {
|
|
519
|
-
zh: "合成 DNS 段(兜底)",
|
|
520
|
-
en: "Synthetic DNS ranges (fallback)"
|
|
521
|
-
},
|
|
522
|
-
hint: {
|
|
523
|
-
zh: "平时留空:fake-ip 型代理由系统自动认出,这里只用于识别失灵时。列进来的段等于放弃对它们的 SSRF 防护。",
|
|
524
|
-
en: "Leave empty: fake-ip resolvers are detected automatically. Only for detection failures. Listed ranges give up SSRF protection."
|
|
525
|
-
},
|
|
526
|
-
fallback: ""
|
|
527
|
-
},
|
|
528
|
-
{
|
|
529
|
-
key: "allowedHosts",
|
|
530
|
-
kind: "text",
|
|
531
|
-
label: {
|
|
532
|
-
zh: "额外放行的内网主机",
|
|
533
|
-
en: "Extra allowed hosts"
|
|
534
|
-
},
|
|
535
|
-
hint: {
|
|
536
|
-
zh: "逗号分隔。指到内网等于主动放弃对那些目标的 SSRF 防护,只在真要抓自建站点时填。",
|
|
537
|
-
en: "Comma-separated. Pointing these at internal hosts gives up SSRF protection for them — only for self-hosted targets."
|
|
538
|
-
},
|
|
539
|
-
fallback: ""
|
|
540
|
-
},
|
|
541
|
-
{
|
|
542
|
-
key: "nat64Prefixes",
|
|
543
|
-
kind: "text",
|
|
544
|
-
label: {
|
|
545
|
-
zh: "额外 NAT64 前缀",
|
|
546
|
-
en: "Extra NAT64 prefixes"
|
|
547
|
-
},
|
|
548
|
-
hint: {
|
|
549
|
-
zh: "用运营商自建 NAT64 的网络才需要,形如 2001:4860:4860::/96。",
|
|
550
|
-
en: "Only for carrier-grade NAT64 networks, e.g. 2001:4860:4860::/96."
|
|
551
|
-
},
|
|
552
|
-
fallback: ""
|
|
553
|
-
},
|
|
554
|
-
{
|
|
555
|
-
key: "provideWebFetch",
|
|
556
|
-
kind: "boolean",
|
|
557
|
-
label: {
|
|
558
|
-
zh: "接管内置 web_fetch",
|
|
559
|
-
en: "Provide the built-in web_fetch"
|
|
560
|
-
},
|
|
561
|
-
hint: {
|
|
562
|
-
zh: "默认开;部署配置里仍要写 fetchProvider: \"scrapling\",否则 base bundle 那条 fetchProvider: http 仍然赢。",
|
|
563
|
-
en: "On by default; the deployment config still needs fetchProvider: \"scrapling\", otherwise the base bundle's fetchProvider: http wins."
|
|
564
|
-
},
|
|
565
|
-
fallback: true
|
|
566
|
-
},
|
|
567
|
-
{
|
|
568
|
-
key: "provideWebSearch",
|
|
569
|
-
kind: "boolean",
|
|
570
|
-
label: {
|
|
571
|
-
zh: "接管内置 web_search",
|
|
572
|
-
en: "Provide the built-in web_search"
|
|
573
|
-
},
|
|
574
|
-
hint: {
|
|
575
|
-
zh: "默认开;还需要配 searchEndpoint(SearXNG 兼容接口)与 searchProvider,否则不会接管。",
|
|
576
|
-
en: "On by default; still needs a SearXNG-compatible searchEndpoint and searchProvider, otherwise it does not take over."
|
|
577
|
-
},
|
|
578
|
-
fallback: true
|
|
579
|
-
}
|
|
580
|
-
]
|
|
581
|
-
},
|
|
582
|
-
{
|
|
583
|
-
id: "answer",
|
|
584
|
-
title: {
|
|
585
|
-
zh: "页面问答",
|
|
586
|
-
en: "Page Q&A"
|
|
587
|
-
},
|
|
588
|
-
note: {
|
|
589
|
-
zh: "三项都留空就跟随当前会话用的模型,不额外烧一份额度。",
|
|
590
|
-
en: "All blank follows the session's own model, costing no extra quota."
|
|
591
|
-
},
|
|
592
|
-
fields: [
|
|
593
|
-
{
|
|
594
|
-
key: "answerProvider",
|
|
595
|
-
kind: "text",
|
|
596
|
-
label: {
|
|
597
|
-
zh: "回答用 provider",
|
|
598
|
-
en: "Answer provider"
|
|
599
|
-
},
|
|
600
|
-
hint: {
|
|
601
|
-
zh: "留空跟随会话模型。",
|
|
602
|
-
en: "Blank follows the session model."
|
|
603
|
-
},
|
|
604
|
-
fallback: ""
|
|
605
|
-
},
|
|
606
|
-
{
|
|
607
|
-
key: "answerModel",
|
|
608
|
-
kind: "text",
|
|
609
|
-
label: {
|
|
610
|
-
zh: "回答用模型 id",
|
|
611
|
-
en: "Answer model id"
|
|
612
|
-
},
|
|
613
|
-
hint: {
|
|
614
|
-
zh: "与 provider 一起生效。",
|
|
615
|
-
en: "Takes effect together with the provider."
|
|
616
|
-
},
|
|
617
|
-
fallback: ""
|
|
618
|
-
},
|
|
619
|
-
{
|
|
620
|
-
key: "answerMaxTokens",
|
|
621
|
-
kind: "number",
|
|
622
|
-
label: {
|
|
623
|
-
zh: "单次回答 token 上限",
|
|
624
|
-
en: "Answer token cap"
|
|
625
|
-
},
|
|
626
|
-
hint: {
|
|
627
|
-
zh: "一次回答的输出预算。",
|
|
628
|
-
en: "Output budget per answer."
|
|
629
|
-
},
|
|
630
|
-
fallback: 2e3
|
|
631
|
-
}
|
|
632
|
-
]
|
|
633
|
-
}
|
|
634
|
-
];
|
|
635
|
-
/** 展平后的字段表,顺序与卡上一致。 */
|
|
636
|
-
const SETTINGS_FIELDS = SETTINGS_GROUPS.flatMap((group) => group.fields);
|
|
637
|
-
SETTINGS_FIELDS.map((field) => field.key);
|
|
638
|
-
/** 本包 Client 半注册的字典命名空间。 */
|
|
639
|
-
const LOCALE_NS = "dshScrapling";
|
|
640
|
-
/** 设置卡自身的文案:按钮、状态行与读屏提示。字段标签不在这里 —— 它们由字段表摊出来。 */
|
|
641
|
-
const CHROME = {
|
|
642
|
-
zh: {
|
|
643
|
-
save: "保存",
|
|
644
|
-
saving: "保存中…",
|
|
645
|
-
undo: "撤销",
|
|
646
|
-
reveal: "显示",
|
|
647
|
-
conceal: "隐藏",
|
|
648
|
-
revealHint: "这一项按密码遮罩显示",
|
|
649
|
-
statusLoading: "正在读取设置…",
|
|
650
|
-
statusReadonly: "这个连接以只读方式运行,设置改不了。",
|
|
651
|
-
statusClean: "没有未保存的改动",
|
|
652
|
-
statusChanged: "已改动 {count} 项,未保存",
|
|
653
|
-
statusInvalid: "有 {count} 项填的不是合法数字,改好后才能保存",
|
|
654
|
-
rejected: "保存被宿主拒绝了,设置未改动",
|
|
655
|
-
stale: "设置已经被别处改过,请重新打开这张卡再保存",
|
|
656
|
-
failed: "保存失败:{reason}"
|
|
657
|
-
},
|
|
658
|
-
en: {
|
|
659
|
-
save: "Save",
|
|
660
|
-
saving: "Saving…",
|
|
661
|
-
undo: "Undo",
|
|
662
|
-
reveal: "Show",
|
|
663
|
-
conceal: "Hide",
|
|
664
|
-
revealHint: "this field is masked like a password",
|
|
665
|
-
statusLoading: "Reading settings…",
|
|
666
|
-
statusReadonly: "This connection runs read-only; settings cannot be changed here.",
|
|
667
|
-
statusClean: "No unsaved changes",
|
|
668
|
-
statusChanged: "{count} change(s) not saved yet",
|
|
669
|
-
statusInvalid: "{count} field(s) are not valid numbers; fix them to save",
|
|
670
|
-
rejected: "The host refused the save; nothing changed",
|
|
671
|
-
stale: "Settings changed elsewhere; reopen this page before saving",
|
|
672
|
-
failed: "Save failed: {reason}"
|
|
673
|
-
}
|
|
674
|
-
};
|
|
675
|
-
/** 结果行那一行的文案:字段名与那一个「看详情」的入口。 */
|
|
676
|
-
const ROW_CHROME = {
|
|
677
|
-
zh: {
|
|
678
|
-
"row.url": "URL",
|
|
679
|
-
"row.http": "HTTP",
|
|
680
|
-
"row.body": "正文",
|
|
681
|
-
"row.matched": "匹配",
|
|
682
|
-
"row.sessionCount": "会话数",
|
|
683
|
-
"row.session": "会话",
|
|
684
|
-
"row.type": "类型",
|
|
685
|
-
"row.start": "起始",
|
|
686
|
-
"row.pageCap": "上限",
|
|
687
|
-
"row.job": "作业",
|
|
688
|
-
"row.inspect": "在轨迹里查看",
|
|
689
|
-
"row.truncated": "已截断"
|
|
690
|
-
},
|
|
691
|
-
en: {
|
|
692
|
-
"row.url": "URL",
|
|
693
|
-
"row.http": "HTTP",
|
|
694
|
-
"row.body": "Body",
|
|
695
|
-
"row.matched": "Matched",
|
|
696
|
-
"row.sessionCount": "Sessions",
|
|
697
|
-
"row.session": "Session",
|
|
698
|
-
"row.type": "Type",
|
|
699
|
-
"row.start": "Start",
|
|
700
|
-
"row.pageCap": "Page cap",
|
|
701
|
-
"row.job": "Job",
|
|
702
|
-
"row.inspect": "Inspect this call",
|
|
703
|
-
"row.truncated": "Truncated"
|
|
704
|
-
}
|
|
705
|
-
};
|
|
706
|
-
/**
|
|
707
|
-
* 把字段表与卡面文案摊成宿主 locale 服务要的字典。
|
|
708
|
-
*
|
|
709
|
-
* 键的形状:字段是 `field.<key>.label` / `field.<key>.hint`,分组是
|
|
710
|
-
* `group.<id>.title` / `group.<id>.note`,卡面文案直接用自己的键。键从字段表推出来,
|
|
711
|
-
* 所以往表里加一个字段就自动多出两条词典项 —— 不需要在这里再抄一遍。
|
|
712
|
-
*
|
|
713
|
-
* @returns 语言 → 键值表;两份的键集相等
|
|
714
|
-
*/
|
|
715
|
-
function localeDictionaries() {
|
|
716
|
-
const result = {
|
|
717
|
-
zh: {
|
|
718
|
-
...CHROME.zh,
|
|
719
|
-
...ROW_CHROME.zh
|
|
720
|
-
},
|
|
721
|
-
en: {
|
|
722
|
-
...CHROME.en,
|
|
723
|
-
...ROW_CHROME.en
|
|
724
|
-
}
|
|
725
|
-
};
|
|
726
|
-
for (const group of SETTINGS_GROUPS) {
|
|
727
|
-
result.zh[`group.${group.id}.title`] = group.title.zh;
|
|
728
|
-
result.zh[`group.${group.id}.note`] = group.note.zh;
|
|
729
|
-
result.en[`group.${group.id}.title`] = group.title.en;
|
|
730
|
-
result.en[`group.${group.id}.note`] = group.note.en;
|
|
731
|
-
for (const field of group.fields) {
|
|
732
|
-
result.zh[`field.${field.key}.label`] = field.label.zh;
|
|
733
|
-
result.zh[`field.${field.key}.hint`] = field.hint.zh;
|
|
734
|
-
result.en[`field.${field.key}.label`] = field.label.en;
|
|
735
|
-
result.en[`field.${field.key}.hint`] = field.hint.en;
|
|
736
|
-
}
|
|
737
|
-
}
|
|
738
|
-
return result;
|
|
739
|
-
}
|
|
740
|
-
//#endregion
|
|
741
|
-
//#region src/settings-card.ts
|
|
742
|
-
/** 没给值面时读到的那一版:既不在线也不可写,于是卡片画出一张锁住的空表。 */
|
|
743
|
-
const LOADING_STATE = {
|
|
744
|
-
status: "loading",
|
|
745
|
-
writable: false
|
|
746
|
-
};
|
|
747
|
-
/** 值面缺席时的 getSnapshot:永远返回同一个引用,订阅因此不会被反复重建。 */
|
|
748
|
-
function loadingSnapshot() {
|
|
749
|
-
return LOADING_STATE;
|
|
750
|
-
}
|
|
751
|
-
/** 值面缺席时的 subscribe:永远不通知,回收是空操作。 */
|
|
752
|
-
function loadingSubscribe() {
|
|
753
|
-
return () => void 0;
|
|
754
|
-
}
|
|
755
|
-
/** 把任意设置值转成控件能显示的字符串;结构值给空串而不是 `[object Object]`。 */
|
|
756
|
-
function textOf(value) {
|
|
757
|
-
if (typeof value === "string") return value;
|
|
758
|
-
if (typeof value === "number" || typeof value === "boolean") return String(value);
|
|
759
|
-
return "";
|
|
760
|
-
}
|
|
761
|
-
/**
|
|
762
|
-
* 控件里显示的字符串。草稿优先,其次宿主值,最后字段表里的默认值。
|
|
763
|
-
*
|
|
764
|
-
* @param field - 字段描述
|
|
765
|
-
* @param host - 宿主给的值
|
|
766
|
-
* @param draft - 用户改过但还没保存的值
|
|
767
|
-
* @returns 控件该显示的字符串
|
|
768
|
-
*/
|
|
769
|
-
function displayValue(field, host, draft) {
|
|
770
|
-
const edited = draft[field.key];
|
|
771
|
-
if (edited !== void 0) return textOf(edited);
|
|
772
|
-
const current = host?.[field.key];
|
|
773
|
-
return current === void 0 ? String(field.fallback) : textOf(current);
|
|
774
|
-
}
|
|
775
|
-
/**
|
|
776
|
-
* 把控件里敲进去的一串字翻成设置值。
|
|
777
|
-
*
|
|
778
|
-
* 清空 = 交回默认值,所以空串给 `clear`。数字字段按 schema 的下界夹住;非数字、零、负数与
|
|
779
|
-
* 小数一律给 `invalid` 而不是 `clear`。早先把它们当成清除,用户填错一个数就会把自己原来
|
|
780
|
-
* 那条覆盖静默删掉,而且界面上看不出发生过什么 —— 非法输入留在控件里、保存按钮因此不可用,
|
|
781
|
-
* 比悄悄改掉用户的配置好。
|
|
782
|
-
*
|
|
783
|
-
* @param field - 字段描述
|
|
784
|
-
* @param raw - 控件里的原始字符串
|
|
785
|
-
* @returns 解析结果
|
|
786
|
-
*/
|
|
787
|
-
function parseInput(field, raw) {
|
|
788
|
-
if (field.kind === "boolean") return {
|
|
789
|
-
kind: "value",
|
|
790
|
-
value: raw === "true"
|
|
791
|
-
};
|
|
792
|
-
const text = raw.trim();
|
|
793
|
-
if (text === "") return { kind: "clear" };
|
|
794
|
-
if (field.kind === "number") return /^[1-9]\d*$/u.test(text) ? {
|
|
795
|
-
kind: "value",
|
|
796
|
-
value: Number(text)
|
|
797
|
-
} : { kind: "invalid" };
|
|
798
|
-
return {
|
|
799
|
-
kind: "value",
|
|
800
|
-
value: text
|
|
801
|
-
};
|
|
802
|
-
}
|
|
803
|
-
/**
|
|
804
|
-
* 把草稿翻成一串写入操作。
|
|
805
|
-
*
|
|
806
|
-
* 与默认值相同的项走 unset:用户层里「显式写了默认值」和「没写」在将来改默认值时行为完全
|
|
807
|
-
* 不同,只有 unset 能保住这个区别。顺序跟字段表一致,于是同一份草稿每次生成同样的操作串,
|
|
808
|
-
* 宿主按 revision 拒绝时也不会因为顺序抖动而给出不同的理由。非法字段不出现在串里。
|
|
809
|
-
*
|
|
810
|
-
* @param draft - 用户改过的字段(只有改过的在里面)
|
|
811
|
-
* @returns 写入操作
|
|
812
|
-
*/
|
|
813
|
-
function buildOps(draft) {
|
|
814
|
-
return SETTINGS_FIELDS.filter((field) => Object.hasOwn(draft, field.key)).filter((field) => draft[field.key] !== void 0).map((field) => {
|
|
815
|
-
const value = draft[field.key];
|
|
816
|
-
return value === null || value === field.fallback ? {
|
|
817
|
-
op: "unset",
|
|
818
|
-
path: [field.key]
|
|
819
|
-
} : {
|
|
820
|
-
op: "set",
|
|
821
|
-
path: [field.key],
|
|
822
|
-
value
|
|
823
|
-
};
|
|
824
|
-
});
|
|
825
|
-
}
|
|
826
|
-
/** 卡片样式。跟着宿主的语义色走,因此明暗两套主题都成立。 */
|
|
827
|
-
const CARD_CSS = `
|
|
8
|
+
Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});let e=require("react");const t=e=>e.length>0&&!(e in Object.prototype);function n(e,t,n){n===void 0?e[t]=void 0:Object.defineProperty(e,t,n)}function r(e,r,i){if(!t(r))throw Error(`claimApply 的 flag 不得为空、也不得命中 Object.prototype 的成员(__proto__ 一类会让占位静默失灵或遮蔽全局成员):${r}`);let a=globalThis,o=Object.hasOwn(a,r)?a[r]:void 0;if(o===!0||typeof o==`symbol`)return!1;let s=Object.getOwnPropertyDescriptor(a,r),c=Symbol(r);a[r]=c;try{e.effect(()=>()=>{a[r]===c&&n(a,r,s)},i)}catch(e){throw a[r]===c&&n(a,r,s),e}return!0}function i(e){return typeof e==`object`&&!!e&&!Array.isArray(e)}const a=[{id:`runtime`,title:{zh:`运行环境`,en:`Runtime`},note:{zh:`Python 与数据目录。装完 scrapling 之后这里一般不用动。`,en:`Python and the data directory. Usually untouched once scrapling is installed.`},fields:[{key:`pythonBin`,kind:`text`,label:{zh:`Python 解释器`,en:`Python interpreter`},hint:{zh:`留空:先用仓内 _env/.venv(装了才用),否则用 PATH 上的 python3;装了 pyenv/conda 时填绝对路径。`,en:`Empty: use the repo's _env/.venv when it exists, else python3 from PATH; give an absolute path under pyenv/conda.`},fallback:``},{key:`failFastOnMissingPython`,kind:`boolean`,label:{zh:`Python 缺失时拒绝加载`,en:`Fail fast without Python`},hint:{zh:`开:Python 起不来就不注册任何工具并报错。关:只警告,工具全部消失。`,en:`On: register nothing and error out. Off: warn and register nothing.`},fallback:!0},{key:`dataDir`,kind:`text`,label:{zh:`数据目录`,en:`Data directory`},hint:{zh:`留空用 ~/.dsh-scrapling;选择器自愈的指纹库落在这里,需要可写。`,en:`Leave empty for ~/.dsh-scrapling; the adaptive selector store lives here and must be writable.`},fallback:``}]},{id:`tools`,title:{zh:`工具开关`,en:`Tools`},note:{zh:`关掉的工具不会注册给模型,也不会在会话提示里占位置。`,en:`A disabled tool is never registered with the model and leaves the system prompt too.`},fields:[{key:`fetchEnabled`,kind:`boolean`,label:{zh:`scrapling_fetch`,en:`scrapling_fetch`},hint:{zh:`curl_cffi 静态抓取。`,en:`Static fetching over curl_cffi.`},fallback:!0},{key:`extractEnabled`,kind:`boolean`,label:{zh:`scrapling_extract`,en:`scrapling_extract`},hint:{zh:`对给定 HTML 做选择器抽取,不发请求。`,en:`Extract from given HTML without any request.`},fallback:!0},{key:`renderEnabled`,kind:`boolean`,label:{zh:`scrapling_render`,en:`scrapling_render`},hint:{zh:`Playwright 渲染,能读 SPA。`,en:`Playwright rendering; reads SPAs.`},fallback:!0},{key:`captureXhrEnabled`,kind:`boolean`,label:{zh:`scrapling_capture_xhr`,en:`scrapling_capture_xhr`},hint:{zh:`只回传 XHR 的 URL/状态/字节数;站点数据在接口里时用它找那个接口。`,en:`Returns XHR url/status/bytes only — use it to locate the JSON endpoint.`},fallback:!0},{key:`networkEnabled`,kind:`boolean`,label:{zh:`scrapling_session_network`,en:`scrapling_session_network`},hint:{zh:`读已开会话攒下的网络历史;会话需先用 recordNetwork 打开记录。`,en:`Read a session's recorded network history; the session must have recordNetwork on.`},fallback:!0},{key:`sessionEnabled`,kind:`boolean`,label:{zh:`scrapling_session_*`,en:`scrapling_session_*`},hint:{zh:`跨请求复用 cookie 与浏览器实例,只管 open / fetch / list / close 这一组;network 与 state_* 各自有独立开关。`,en:`Reuse cookies and the browser across requests; covers open / fetch / list / close only. The network and state_* groups have their own switches.`},fallback:!0},{key:`sessionStateEnabled`,kind:`boolean`,label:{zh:`scrapling_session_state_*`,en:`scrapling_session_state_*`},hint:{zh:`存/取浏览器登录态;需部署侧配好 sessionStateDir。`,en:`Save/load browser login state; needs a deployment-side sessionStateDir.`},fallback:!0},{key:`crawlEnabled`,kind:`boolean`,label:{zh:`scrapling_crawl`,en:`scrapling_crawl`},hint:{zh:`后台 Spider 作业,只守起始域;需 profile 带作业后端。`,en:`Background spider jobs confined to the start domain; needs a jobs backend.`},fallback:!0},{key:`answerEnabled`,kind:`boolean`,label:{zh:`scrapling_answer`,en:`scrapling_answer`},hint:{zh:`抓完页面交给模型问答。`,en:`Answer a question over a fetched page.`},fallback:!0}]},{id:`output`,title:{zh:`抽取与输出`,en:`Extraction & output`},note:{zh:`这几个数字直接决定模型每轮看到多少 token。`,en:`These numbers are the per-call token bill the model pays.`},fields:[{key:`extractionType`,kind:`enum`,label:{zh:`默认抽取形态`,en:`Default extraction`},hint:{zh:`markdown 最省 token;html 保留标签;text 只留文字。`,en:`markdown is cheapest; html keeps tags; text keeps words only.`},fallback:`markdown`,options:[`markdown`,`html`,`text`]},{key:`mainContentOnly`,kind:`boolean`,label:{zh:`只保留正文`,en:`Main content only`},hint:{zh:`去掉导航、页脚、侧栏。开:更短更干净;关:要连同导航、按钮这类页面控件一起抓时用。`,en:`Drop nav/footer/sidebar. On for shorter output; off when you need page chrome.`},fallback:!0},{key:`fetchMaxOutputChars`,kind:`number`,label:{zh:`静态抓取正文上限`,en:`fetch output cap`},hint:{zh:`字符数,超出部分截断并标注。`,en:`Characters; the payload is clipped and flagged.`},fallback:2e5},{key:`extractMaxOutputChars`,kind:`number`,label:{zh:`抽取结果上限`,en:`extract output cap`},hint:{zh:`字符数。`,en:`Characters.`},fallback:2e5},{key:`renderMaxOutputChars`,kind:`number`,label:{zh:`渲染结果上限`,en:`render output cap`},hint:{zh:`字符数;会话类工具共用这一档。`,en:`Characters; the session tools share this budget.`},fallback:2e5},{key:`xhrMaxOutputChars`,kind:`number`,label:{zh:`XHR 快照上限`,en:`XHR snapshot cap`},hint:{zh:`字符数。`,en:`Characters.`},fallback:12e4},{key:`crawlMaxItems`,kind:`number`,label:{zh:`爬虫默认页数上限`,en:`Crawl page cap`},hint:{zh:`爬虫工具每次调用的默认上限,模型可按次调小。`,en:`Default per-call page cap; the model may lower it per call.`},fallback:1e3},{key:`stripInlineImages`,kind:`boolean`,label:{zh:`剥掉内嵌 base64 图片`,en:`Strip inline base64 images`},hint:{zh:`默认开。内嵌 data: URI 图片对模型是纯 token 噪音——模型从 base64 里读不出任何图形信息,只留 alt 文本;代码围栏内的原样保留。没有内联图的页面不受影响。要从 base64 里取配色或指纹这类原始数据时才关掉。`,en:`On by default. Inline data: URI images are pure token noise - the model cannot read a shape out of base64, so only the alt text is kept; ones inside code fences are left alone. Pages without inline images are unaffected. Turn it off to read the raw base64 (colours, fingerprints).`},fallback:!0}]},{id:`browser`,title:{zh:`浏览器行为`,en:`Browser behaviour`},note:{zh:`只在渲染 / XHR 两条路径上生效。`,en:`Only affects the render / XHR paths.`},fields:[{key:`headless`,kind:`boolean`,label:{zh:`无头运行`,en:`Headless`},hint:{zh:`关掉会弹出浏览器窗口,反检测站点上成功率更高。`,en:`Off shows a window and beats more anti-bot checks.`},fallback:!0},{key:`networkIdle`,kind:`boolean`,label:{zh:`等网络静默`,en:`Wait for network idle`},hint:{zh:`等到没有在途请求再返回。更准,但慢;埋了长连接的站点可能一直等不到。`,en:`Wait until no requests are in flight. Slower, and pages with long-lived sockets never settle.`},fallback:!1},{key:`blockAds`,kind:`boolean`,label:{zh:`拦截广告与追踪`,en:`Block ads and trackers`},hint:{zh:`约 3500 个已知广告域。省流量,偶尔误伤。`,en:`~3,500 known ad domains. Saves bandwidth, occasionally over-blocks.`},fallback:!0},{key:`pierceShadow`,kind:`boolean`,label:{zh:`穿透 Shadow DOM`,en:`Pierce Shadow DOM`},hint:{zh:`把 open shadow root 里的内容并进正文,默认关;页面把正文封进 shadow DOM 时才打开。`,en:`Merge open shadow root content into the body; off by default. On when a page hides its content in shadow DOM.`},fallback:!1},{key:`waitSelectorState`,kind:`enum`,label:{zh:`等待选择器的状态`,en:`Wait selector state`},hint:{zh:`配 waitSelector 用;attached 最宽松。`,en:`Used with waitSelector; attached is the loosest.`},fallback:`attached`,options:[`attached`,`detached`,`hidden`,`visible`]}]},{id:`timeouts`,title:{zh:`超时与回收`,en:`Timeouts & teardown`},note:{zh:`抓取慢若不在这几项里,先看页面上要等的东西。`,en:`If a fetch is slow for a reason other than these, look at what the page waits for.`},fields:[{key:`fetchTimeoutMs`,kind:`number`,label:{zh:`单次抓取超时(毫秒)`,en:`Per-fetch timeout (ms)`},hint:{zh:`同时是工具的超时预算与 Python 侧的请求上限。`,en:`Also the tool budget and the Python-side request cap.`},fallback:12e4},{key:`sidecarHandshakeTimeoutMs`,kind:`number`,label:{zh:`sidecar 握手超时(毫秒)`,en:`Handshake timeout (ms)`},hint:{zh:`冷启动要拉起一个 Python 进程并导入 Scrapling。`,en:`Cold start spawns a Python process and imports Scrapling.`},fallback:3e4},{key:`sidecarGraceMs`,kind:`number`,label:{zh:`退出宽限(毫秒)`,en:`Shutdown grace (ms)`},hint:{zh:`插件卸载后等 Python 收尾的时间。`,en:`How long Python gets to finish after the plugin unloads.`},fallback:5e3}]},{id:`network`,title:{zh:`网络与安全`,en:`Network & safety`},note:{zh:`通常什么都不用填:TUN 模式的代理由系统接管,环境里的 HTTPS_PROXY 与 macOS / Windows 的「系统代理」都会被自动接上。`,en:`Usually nothing to fill: a TUN-mode proxy is taken from the system, and both HTTPS_PROXY in the environment and the macOS / Windows system proxy are picked up automatically.`},fields:[{key:`proxyUrl`,kind:`text`,secret:!0,label:{zh:`代理地址`,en:`Proxy URL`},hint:{zh:`如 http://127.0.0.1:7890 或 socks5://127.0.0.1:7890,可带 user:pass@。留空=依次跟随环境变量与系统代理设置;填了就压过那两者。值按密码遮罩显示,点「显示」可查看。`,en:`e.g. http://127.0.0.1:7890 or socks5://127.0.0.1:7890, user:pass@ allowed. Empty follows the environment and then the OS proxy settings; setting it outranks both. Masked like a password; press Show to reveal it.`},fallback:``},{key:`proxyBypass`,kind:`text`,label:{zh:`代理绕过清单`,en:`Proxy bypass`},hint:{zh:`逗号分隔的主机名,命中即直连;内网站点要填。整台机器直连填 *。浏览器会话不逐条生效(它的代理在开场时定死)。`,en:`Comma-separated hostnames that connect directly; list your internal sites. Use * for the whole machine. Not applied per URL inside a browser session (its proxy is fixed at open).`},fallback:``},{key:`syntheticDnsRanges`,kind:`text`,label:{zh:`合成 DNS 段(兜底)`,en:`Synthetic DNS ranges (fallback)`},hint:{zh:`平时留空:fake-ip 型代理由系统自动认出,这里只用于识别失灵时。列进来的段等于放弃对它们的 SSRF 防护。`,en:`Leave empty: fake-ip resolvers are detected automatically. Only for detection failures. Listed ranges give up SSRF protection.`},fallback:``},{key:`allowedHosts`,kind:`text`,label:{zh:`额外放行的内网主机`,en:`Extra allowed hosts`},hint:{zh:`逗号分隔。指到内网等于主动放弃对那些目标的 SSRF 防护,只在真要抓自建站点时填。`,en:`Comma-separated. Pointing these at internal hosts gives up SSRF protection for them — only for self-hosted targets.`},fallback:``},{key:`nat64Prefixes`,kind:`text`,label:{zh:`额外 NAT64 前缀`,en:`Extra NAT64 prefixes`},hint:{zh:`用运营商自建 NAT64 的网络才需要,形如 2001:4860:4860::/96。`,en:`Only for carrier-grade NAT64 networks, e.g. 2001:4860:4860::/96.`},fallback:``},{key:`provideWebFetch`,kind:`boolean`,label:{zh:`接管内置 web_fetch`,en:`Provide the built-in web_fetch`},hint:{zh:`默认开;部署配置里仍要写 fetchProvider: "scrapling",否则 base bundle 那条 fetchProvider: http 仍然赢。`,en:`On by default; the deployment config still needs fetchProvider: "scrapling", otherwise the base bundle's fetchProvider: http wins.`},fallback:!0},{key:`provideWebSearch`,kind:`boolean`,label:{zh:`接管内置 web_search`,en:`Provide the built-in web_search`},hint:{zh:`默认开;还需要配 searchEndpoint(SearXNG 兼容接口)与 searchProvider,否则不会接管。`,en:`On by default; still needs a SearXNG-compatible searchEndpoint and searchProvider, otherwise it does not take over.`},fallback:!0}]},{id:`answer`,title:{zh:`页面问答`,en:`Page Q&A`},note:{zh:`provider 与 model 留空跟随当前会话用的模型,不额外烧一份额度;token 上限留空用默认值。`,en:`provider and model blank follow the session's own model, costing no extra quota; the token cap falls back to its default.`},fields:[{key:`answerProvider`,kind:`text`,label:{zh:`回答用 provider`,en:`Answer provider`},hint:{zh:`留空跟随会话模型。`,en:`Blank follows the session model.`},fallback:``},{key:`answerModel`,kind:`text`,label:{zh:`回答用模型 id`,en:`Answer model id`},hint:{zh:`与 provider 一起生效。`,en:`Takes effect together with the provider.`},fallback:``},{key:`answerMaxTokens`,kind:`number`,label:{zh:`单次回答 token 上限`,en:`Answer token cap`},hint:{zh:`一次回答的输出预算。`,en:`Output budget per answer.`},fallback:2e3}]}],o=a.flatMap(e=>e.fields);o.map(e=>e.key);const s=`dshScrapling`,c={zh:{save:`保存`,saving:`保存中…`,undo:`撤销`,reveal:`显示`,conceal:`隐藏`,statusLoading:`正在读取设置…`,statusReadonly:`这个连接以只读方式运行,设置改不了。`,statusClean:`没有未保存的改动`,statusChanged:`已改动 {count} 项,未保存`,statusInvalid:`有 {count} 项填的不是合法数字,改好后才能保存`,rejected:`保存被宿主拒绝了,设置未改动`,stale:`设置已经被别处改过,请重新打开这张卡再保存`,failed:`保存失败:{reason}`},en:{save:`Save`,saving:`Saving…`,undo:`Undo`,reveal:`Show`,conceal:`Hide`,statusLoading:`Reading settings…`,statusReadonly:`This connection runs read-only; settings cannot be changed here.`,statusClean:`No unsaved changes`,statusChanged:`{count} change(s) not saved yet`,statusInvalid:`{count} field(s) are not valid numbers; fix them to save`,rejected:`The host refused the save; nothing changed`,stale:`Settings changed elsewhere; reopen this page before saving`,failed:`Save failed: {reason}`}},l={zh:{"row.url":`URL`,"row.http":`HTTP`,"row.body":`正文`,"row.matched":`匹配`,"row.sessionCount":`会话数`,"row.session":`会话`,"row.name":`名称`,"row.type":`类型`,"row.start":`起始`,"row.pageCap":`上限`,"row.job":`作业`,"row.inspect":`在轨迹里查看`,"row.truncated":`已截断`},en:{"row.url":`URL`,"row.http":`HTTP`,"row.body":`Body`,"row.matched":`Matched`,"row.sessionCount":`Sessions`,"row.session":`Session`,"row.name":`Name`,"row.type":`Type`,"row.start":`Start`,"row.pageCap":`Page cap`,"row.job":`Job`,"row.inspect":`Inspect this call`,"row.truncated":`Truncated`}};function u(){let e={zh:{...c.zh,...l.zh},en:{...c.en,...l.en}};for(let t of a){e.zh[`group.${t.id}.title`]=t.title.zh,e.zh[`group.${t.id}.note`]=t.note.zh,e.en[`group.${t.id}.title`]=t.title.en,e.en[`group.${t.id}.note`]=t.note.en;for(let n of t.fields)e.zh[`field.${n.key}.label`]=n.label.zh,e.zh[`field.${n.key}.hint`]=n.hint.zh,e.en[`field.${n.key}.label`]=n.label.en,e.en[`field.${n.key}.hint`]=n.hint.en}return e}const d={status:`loading`,writable:!1};function f(){return d}function p(){return()=>void 0}function m(e){return typeof e==`string`?e:typeof e==`number`||typeof e==`boolean`?String(e):``}function h(e,t,n,r={}){let i=r[e.key];if(i!==void 0)return i;let a=n[e.key];if(a!==void 0)return m(a);let o=t?.[e.key];return o===void 0?String(e.fallback):m(o)}function g(e,t){if(e.kind===`boolean`)return{kind:`value`,value:t===`true`};let n=t.trim();return n===``?{kind:`clear`}:e.kind===`number`?/^[1-9]\d*$/u.test(n)?{kind:`value`,value:Number(n)}:{kind:`invalid`}:{kind:`value`,value:n}}function _(e){return o.filter(t=>Object.hasOwn(e,t.key)).filter(t=>e[t.key]!==void 0).map(t=>{let n=e[t.key];return n===null||n===t.fallback?{op:`unset`,path:[t.key]}:{op:`set`,path:[t.key],value:n}})}function v(e){if(typeof e!=`object`||!e)return!1;let t=Reflect.get(e,`head`);return typeof Reflect.get(e,`querySelector`)==`function`&&typeof Reflect.get(e,`createElement`)==`function`&&typeof t==`object`&&!!t&&typeof Reflect.get(t,`append`)==`function`}function y(){let e=Reflect.get(globalThis,`document`);return v(e)?e:void 0}function b(e,t,n){if(e.querySelector(`#${t}`)!=null)return()=>void 0;let r=e.createElement(`style`);return r.id=t,r.textContent=n,e.head.append(r),()=>{r.remove()}}function x(e){return b(e,`dsh-scrapling-settings-css`,`
|
|
828
9
|
.dss-card{display:flex;flex-direction:column;gap:16px;color:var(--dsw-alias-label-primary)}
|
|
829
10
|
.dss-group{display:flex;flex-direction:column;gap:10px}
|
|
830
11
|
.dss-group+.dss-group{border-top:.5px solid var(--dsw-alias-border-l2);padding-top:16px}
|
|
@@ -852,446 +33,7 @@ const CARD_CSS = `
|
|
|
852
33
|
.dss-status{margin:0;color:var(--dsw-alias-label-tertiary);font-size:12px}
|
|
853
34
|
.dss-status[data-error=true]{color:var(--dsw-alias-state-error-primary)}
|
|
854
35
|
@media (max-width:560px){.dss-field{grid-template-columns:minmax(0,1fr)}.dss-hint,.dss-control{grid-column:1}}
|
|
855
|
-
|
|
856
|
-
/** 这个值是不是一个带本卡所需那点 API 的 document。类型守卫而不是断言。 */
|
|
857
|
-
function isDocumentFace(value) {
|
|
858
|
-
if (typeof value !== "object" || value === null) return false;
|
|
859
|
-
const head = Reflect.get(value, "head");
|
|
860
|
-
return typeof Reflect.get(value, "querySelector") === "function" && typeof Reflect.get(value, "createElement") === "function" && typeof head === "object" && head !== null && typeof Reflect.get(head, "append") === "function";
|
|
861
|
-
}
|
|
862
|
-
/** 宿主浏览器里的 document;Node 侧(测试、打包)没有,返回 undefined。
|
|
863
|
-
*
|
|
864
|
-
* 导出是为了能被直接测:这一层的两条分支(是 / 不是 document)在真浏览器里各要一次挂载
|
|
865
|
-
* 才走得到,而把它藏在组件里就只能靠渲染来覆盖。`test/settings-card.test.ts` 直接打它。
|
|
866
|
-
*/
|
|
867
|
-
function browserDocument() {
|
|
868
|
-
const candidate = Reflect.get(globalThis, "document");
|
|
869
|
-
return isDocumentFace(candidate) ? candidate : void 0;
|
|
870
|
-
}
|
|
871
|
-
/**
|
|
872
|
-
* 把一段样式挂进文档,返回摘掉它的函数。同一 id 只会有一段,重复调用是空操作。
|
|
873
|
-
*
|
|
874
|
-
* **由 apply 注册在 ctx.effect 里,不在组件的 render 里调**:渲染期改 DOM 是 React 明令
|
|
875
|
-
* 禁止的副作用,并发渲染与 StrictMode 的双调用都会让注入时机不可预测,而同一段 `<style>`
|
|
876
|
-
* 重复注入就会叠两份规则。文档里已经有它时返回的函数也就不该把别人的摘掉。
|
|
877
|
-
*
|
|
878
|
-
* 导出是为了能被直接测 —— 同 :func:`browserDocument` 的理由。
|
|
879
|
-
*
|
|
880
|
-
* @param doc - 宿主文档
|
|
881
|
-
* @param id - 样式元素的 id,也是「已经挂过没有」的判据
|
|
882
|
-
* @param css - 样式正文
|
|
883
|
-
* @returns 摘掉本次注入的样式;没有注入时是空操作
|
|
884
|
-
*/
|
|
885
|
-
function installStyle(doc, id, css) {
|
|
886
|
-
const present = doc.querySelector(`#${id}`);
|
|
887
|
-
if (present !== void 0 && present !== null) return () => void 0;
|
|
888
|
-
const tag = doc.createElement("style");
|
|
889
|
-
tag.id = id;
|
|
890
|
-
tag.textContent = css;
|
|
891
|
-
doc.head.append(tag);
|
|
892
|
-
return () => {
|
|
893
|
-
tag.remove();
|
|
894
|
-
};
|
|
895
|
-
}
|
|
896
|
-
/**
|
|
897
|
-
* 把设置卡的样式挂进文档。
|
|
898
|
-
*
|
|
899
|
-
* @param doc - 宿主文档
|
|
900
|
-
* @returns 摘掉本次注入的样式
|
|
901
|
-
*/
|
|
902
|
-
function installStyles(doc) {
|
|
903
|
-
return installStyle(doc, "dsh-scrapling-settings-css", CARD_CSS);
|
|
904
|
-
}
|
|
905
|
-
/**
|
|
906
|
-
* 文本类控件的 input type。
|
|
907
|
-
*
|
|
908
|
-
* 凭据型字段默认走 ``password``:浏览器只画圆点,值本身丝毫不动 —— 编辑、草稿、保存全都
|
|
909
|
-
* 按原串走,遮住的只是屏幕上那一份。导出为纯函数是为了能被直接测:这一层的两条分支在
|
|
910
|
-
* 真浏览器里各要一次点击才走得到,藏在组件里就只能靠渲染来覆盖。
|
|
911
|
-
*
|
|
912
|
-
* @param field - 字段描述
|
|
913
|
-
* @param revealed - 用户是否已经点过「显示」
|
|
914
|
-
* @returns input 的 type
|
|
915
|
-
*/
|
|
916
|
-
function controlType(field, revealed) {
|
|
917
|
-
return field.secret === true && !revealed ? "password" : "text";
|
|
918
|
-
}
|
|
919
|
-
/** 一个字段的控件。 */
|
|
920
|
-
function renderControl(props) {
|
|
921
|
-
const { field, label, shown, disabled, revealed, onReveal, t, onChange } = props;
|
|
922
|
-
if (field.kind === "boolean") return (0, react.createElement)("input", {
|
|
923
|
-
type: "checkbox",
|
|
924
|
-
className: "dss-switch",
|
|
925
|
-
role: "switch",
|
|
926
|
-
checked: shown === "true",
|
|
927
|
-
disabled,
|
|
928
|
-
"aria-label": label,
|
|
929
|
-
onChange: (event) => {
|
|
930
|
-
onChange(String(event.target.checked));
|
|
931
|
-
}
|
|
932
|
-
});
|
|
933
|
-
if (field.kind === "enum") return (0, react.createElement)("select", {
|
|
934
|
-
disabled,
|
|
935
|
-
value: shown,
|
|
936
|
-
"aria-label": label,
|
|
937
|
-
onChange: (event) => {
|
|
938
|
-
onChange(event.target.value);
|
|
939
|
-
}
|
|
940
|
-
}, (field.options ?? []).map((option) => (0, react.createElement)("option", {
|
|
941
|
-
key: option,
|
|
942
|
-
value: option
|
|
943
|
-
}, option)));
|
|
944
|
-
const input = (0, react.createElement)("input", {
|
|
945
|
-
type: field.kind === "number" ? "number" : controlType(field, revealed),
|
|
946
|
-
value: shown,
|
|
947
|
-
disabled,
|
|
948
|
-
...field.secret === true ? {
|
|
949
|
-
autoComplete: "off",
|
|
950
|
-
spellCheck: false
|
|
951
|
-
} : {},
|
|
952
|
-
min: field.kind === "number" ? 1 : void 0,
|
|
953
|
-
step: field.kind === "number" ? 1 : void 0,
|
|
954
|
-
"aria-label": label,
|
|
955
|
-
onChange: (event) => {
|
|
956
|
-
onChange(event.target.value);
|
|
957
|
-
}
|
|
958
|
-
});
|
|
959
|
-
if (field.secret !== true) return input;
|
|
960
|
-
return (0, react.createElement)("span", { className: "dss-secret" }, input, (0, react.createElement)("button", {
|
|
961
|
-
type: "button",
|
|
962
|
-
className: "dss-button dss-reveal",
|
|
963
|
-
disabled,
|
|
964
|
-
"aria-pressed": revealed,
|
|
965
|
-
"aria-label": label,
|
|
966
|
-
onClick: () => {
|
|
967
|
-
onReveal();
|
|
968
|
-
}
|
|
969
|
-
}, t(revealed ? "conceal" : "reveal")));
|
|
970
|
-
}
|
|
971
|
-
/** 一行:左边标签与说明,右边控件。 */
|
|
972
|
-
function renderFieldRow(props) {
|
|
973
|
-
const { field, t, shown, disabled, revealed, onReveal, onChange } = props;
|
|
974
|
-
const label = t(`field.${field.key}.label`);
|
|
975
|
-
const control = renderControl({
|
|
976
|
-
field,
|
|
977
|
-
label,
|
|
978
|
-
shown,
|
|
979
|
-
disabled,
|
|
980
|
-
revealed,
|
|
981
|
-
onReveal,
|
|
982
|
-
t,
|
|
983
|
-
onChange
|
|
984
|
-
});
|
|
985
|
-
const caption = (0, react.createElement)("div", { className: "dss-label" }, label, (0, react.createElement)("p", { className: "dss-hint" }, t(`field.${field.key}.hint`)));
|
|
986
|
-
return (0, react.createElement)("div", {
|
|
987
|
-
className: "dss-field",
|
|
988
|
-
key: field.key
|
|
989
|
-
}, caption, (0, react.createElement)("div", { className: "dss-control" }, control));
|
|
990
|
-
}
|
|
991
|
-
/** 一组字段。 */
|
|
992
|
-
function renderGroup(props) {
|
|
993
|
-
const { group, t, shown, disabled, revealed, onReveal, onChange } = props;
|
|
994
|
-
return (0, react.createElement)("section", {
|
|
995
|
-
className: "dss-group",
|
|
996
|
-
key: group.id
|
|
997
|
-
}, (0, react.createElement)("h3", { className: "dss-groupTitle" }, t(`group.${group.id}.title`)), (0, react.createElement)("p", { className: "dss-note" }, t(`group.${group.id}.note`)), (0, react.createElement)("div", { className: "dss-fields" }, group.fields.map((field) => renderFieldRow({
|
|
998
|
-
field,
|
|
999
|
-
t,
|
|
1000
|
-
shown: shown(field),
|
|
1001
|
-
disabled,
|
|
1002
|
-
revealed: revealed(field),
|
|
1003
|
-
onReveal: () => {
|
|
1004
|
-
onReveal(field);
|
|
1005
|
-
},
|
|
1006
|
-
onChange: (raw) => {
|
|
1007
|
-
onChange(field, raw);
|
|
1008
|
-
}
|
|
1009
|
-
}))));
|
|
1010
|
-
}
|
|
1011
|
-
/** 顶部那行状态说明。拆成函数是为了不在 JSX 里套三元。 */
|
|
1012
|
-
function statusLine(t, state, changed, invalid) {
|
|
1013
|
-
if (state.status === "loading") return t("statusLoading");
|
|
1014
|
-
if (invalid > 0) return t("statusInvalid", { count: invalid });
|
|
1015
|
-
if (state.status === "unavailable" || !state.writable) return t("statusReadonly");
|
|
1016
|
-
return changed === 0 ? t("statusClean") : t("statusChanged", { count: changed });
|
|
1017
|
-
}
|
|
1018
|
-
const EMPTY_DRAFT = {
|
|
1019
|
-
values: {},
|
|
1020
|
-
baseRevision: void 0,
|
|
1021
|
-
invalid: []
|
|
1022
|
-
};
|
|
1023
|
-
/** 底部那一行按钮。 */
|
|
1024
|
-
function renderActions(props) {
|
|
1025
|
-
const { t, saving, editable, blocked, changed, onSave, onUndo } = props;
|
|
1026
|
-
const idle = changed === 0;
|
|
1027
|
-
return (0, react.createElement)("div", { className: "dss-actions" }, (0, react.createElement)("button", {
|
|
1028
|
-
type: "button",
|
|
1029
|
-
className: "dss-button",
|
|
1030
|
-
"data-primary": "true",
|
|
1031
|
-
disabled: idle || blocked || saving || !editable,
|
|
1032
|
-
onClick: onSave
|
|
1033
|
-
}, saving ? t("saving") : t("save")), (0, react.createElement)("button", {
|
|
1034
|
-
type: "button",
|
|
1035
|
-
className: "dss-button",
|
|
1036
|
-
disabled: idle || blocked || saving,
|
|
1037
|
-
onClick: onUndo
|
|
1038
|
-
}, t("undo")));
|
|
1039
|
-
}
|
|
1040
|
-
/** 设置卡本体。导出为常量而非函数声明:它是 React 组件,不是可 new 的类。 */
|
|
1041
|
-
function SettingsCard(props) {
|
|
1042
|
-
const { form, t } = props;
|
|
1043
|
-
const [draft, setDraft] = (0, react.useState)(EMPTY_DRAFT);
|
|
1044
|
-
const [failure, setFailure] = (0, react.useState)("");
|
|
1045
|
-
const [saving, setSaving] = (0, react.useState)(false);
|
|
1046
|
-
const [revealed, setRevealed] = (0, react.useState)([]);
|
|
1047
|
-
const state = (0, react.useSyncExternalStore)(form === void 0 ? loadingSubscribe : form.subscribe, form === void 0 ? loadingSnapshot : form.getSnapshot);
|
|
1048
|
-
if (props.view !== "page" || form === void 0) return (0, react.createElement)("div", { className: "dss-card" });
|
|
1049
|
-
const editable = state.writable && state.status === "ready";
|
|
1050
|
-
const ops = buildOps(draft.values);
|
|
1051
|
-
const save = async () => {
|
|
1052
|
-
setSaving(true);
|
|
1053
|
-
setFailure("");
|
|
1054
|
-
try {
|
|
1055
|
-
if (await form.mutate(ops, draft.baseRevision)) setDraft((previous) => {
|
|
1056
|
-
const values = { ...previous.values };
|
|
1057
|
-
for (const op of ops) {
|
|
1058
|
-
const [key] = op.path;
|
|
1059
|
-
Reflect.deleteProperty(values, key);
|
|
1060
|
-
}
|
|
1061
|
-
return Object.keys(values).length === 0 ? EMPTY_DRAFT : {
|
|
1062
|
-
...previous,
|
|
1063
|
-
values
|
|
1064
|
-
};
|
|
1065
|
-
});
|
|
1066
|
-
else setFailure(draft.baseRevision !== void 0 && draft.baseRevision !== state.revision ? t("stale") : t("rejected"));
|
|
1067
|
-
} catch (error) {
|
|
1068
|
-
setFailure(t("failed", { reason: String(error) }));
|
|
1069
|
-
} finally {
|
|
1070
|
-
setSaving(false);
|
|
1071
|
-
}
|
|
1072
|
-
};
|
|
1073
|
-
const onFieldChange = (field, raw) => {
|
|
1074
|
-
setFailure("");
|
|
1075
|
-
const parsed = parseInput(field, raw);
|
|
1076
|
-
setDraft((previous) => {
|
|
1077
|
-
const values = { ...previous.values };
|
|
1078
|
-
const invalid = previous.invalid.filter((key) => key !== field.key);
|
|
1079
|
-
const baseRevision = previous.baseRevision ?? state.revision;
|
|
1080
|
-
if (parsed.kind === "invalid") return {
|
|
1081
|
-
values,
|
|
1082
|
-
baseRevision,
|
|
1083
|
-
invalid: [...invalid, field.key]
|
|
1084
|
-
};
|
|
1085
|
-
values[field.key] = parsed.kind === "clear" ? null : parsed.value;
|
|
1086
|
-
return {
|
|
1087
|
-
values,
|
|
1088
|
-
baseRevision,
|
|
1089
|
-
invalid
|
|
1090
|
-
};
|
|
1091
|
-
});
|
|
1092
|
-
};
|
|
1093
|
-
const groups = SETTINGS_GROUPS.map((group) => renderGroup({
|
|
1094
|
-
group,
|
|
1095
|
-
t,
|
|
1096
|
-
shown: (field) => displayValue(field, state.value, draft.values),
|
|
1097
|
-
disabled: !editable || saving,
|
|
1098
|
-
revealed: (field) => revealed.includes(field.key),
|
|
1099
|
-
onReveal: (field) => {
|
|
1100
|
-
setRevealed((previous) => previous.includes(field.key) ? previous.filter((key) => key !== field.key) : [...previous, field.key]);
|
|
1101
|
-
},
|
|
1102
|
-
onChange: onFieldChange
|
|
1103
|
-
}));
|
|
1104
|
-
const actions = renderActions({
|
|
1105
|
-
t,
|
|
1106
|
-
saving,
|
|
1107
|
-
editable,
|
|
1108
|
-
blocked: draft.invalid.length > 0,
|
|
1109
|
-
changed: ops.length,
|
|
1110
|
-
onSave: () => {
|
|
1111
|
-
save();
|
|
1112
|
-
},
|
|
1113
|
-
onUndo: () => {
|
|
1114
|
-
setDraft(EMPTY_DRAFT);
|
|
1115
|
-
setFailure("");
|
|
1116
|
-
}
|
|
1117
|
-
});
|
|
1118
|
-
const status = (0, react.createElement)("p", {
|
|
1119
|
-
className: "dss-status",
|
|
1120
|
-
"data-error": "false",
|
|
1121
|
-
role: "status",
|
|
1122
|
-
"aria-live": "polite"
|
|
1123
|
-
}, statusLine(t, state, ops.length, draft.invalid.length));
|
|
1124
|
-
const reported = failure === "" ? null : (0, react.createElement)("p", {
|
|
1125
|
-
className: "dss-status",
|
|
1126
|
-
"data-error": "true",
|
|
1127
|
-
role: "alert",
|
|
1128
|
-
"aria-live": "assertive"
|
|
1129
|
-
}, failure);
|
|
1130
|
-
return (0, react.createElement)("div", { className: "dss-card" }, status, reported, ...groups, actions);
|
|
1131
|
-
}
|
|
1132
|
-
//#endregion
|
|
1133
|
-
//#region src/client-entry.ts
|
|
1134
|
-
/**
|
|
1135
|
-
* 需要专用结果行的工具。
|
|
1136
|
-
*
|
|
1137
|
-
* 每个工具一个 key:slot 按 key 派发,漏掉一个只是那一个不画行,不会连累别的。这份清单
|
|
1138
|
-
* 必须与 `host.ts` 的 `TOOL_SPECS` 对齐 —— 少登记一个,用户看到的就是宿主那条不带本包
|
|
1139
|
-
* 摘要信息的通用行。
|
|
1140
|
-
*/
|
|
1141
|
-
const ROW_TOOLS = [
|
|
1142
|
-
"scrapling_fetch",
|
|
1143
|
-
"scrapling_extract",
|
|
1144
|
-
"scrapling_render",
|
|
1145
|
-
"scrapling_capture_xhr",
|
|
1146
|
-
"scrapling_stealth_fetch",
|
|
1147
|
-
"scrapling_answer",
|
|
1148
|
-
"scrapling_session_open",
|
|
1149
|
-
"scrapling_session_fetch",
|
|
1150
|
-
"scrapling_session_list",
|
|
1151
|
-
"scrapling_session_close",
|
|
1152
|
-
"scrapling_crawl"
|
|
1153
|
-
];
|
|
1154
|
-
/** 把任意值转成字符串;非字符串/非数字一律给空串。 */
|
|
1155
|
-
function text(value) {
|
|
1156
|
-
if (typeof value === "string") return value;
|
|
1157
|
-
if (typeof value === "number" || typeof value === "boolean") return String(value);
|
|
1158
|
-
return "";
|
|
1159
|
-
}
|
|
1160
|
-
/** 取第一个非空字符串候选。 */
|
|
1161
|
-
function firstText(...candidates) {
|
|
1162
|
-
for (const candidate of candidates) {
|
|
1163
|
-
const value = text(candidate);
|
|
1164
|
-
if (value !== "") return value;
|
|
1165
|
-
}
|
|
1166
|
-
return "";
|
|
1167
|
-
}
|
|
1168
|
-
/**
|
|
1169
|
-
* 从一次工具调用的参数与投影里抽出要展示的行。
|
|
1170
|
-
*
|
|
1171
|
-
* 两侧都按「可能缺字段」处理:卡片的输入是别的进程拼出来的载荷,少一个字段就少展示
|
|
1172
|
-
* 一项,而不是抛错把整行画没了。
|
|
1173
|
-
*
|
|
1174
|
-
* @param tool 工具名
|
|
1175
|
-
* @param args 调用参数
|
|
1176
|
-
* @param meta Host 侧 presentationMeta 投影(可能缺席)
|
|
1177
|
-
* @returns 行规格
|
|
1178
|
-
*/
|
|
1179
|
-
function buildRow(tool, args, meta) {
|
|
1180
|
-
const parameters = e(args) ? args : {};
|
|
1181
|
-
const projected = e(meta) ? meta : {};
|
|
1182
|
-
const url = firstText(projected["url"], parameters["url"]);
|
|
1183
|
-
if (tool === "scrapling_extract") {
|
|
1184
|
-
const selector = text(parameters["selector"]);
|
|
1185
|
-
return {
|
|
1186
|
-
tool,
|
|
1187
|
-
title: selector === "" ? tool : `${tool} ${selector}`,
|
|
1188
|
-
fields: [{
|
|
1189
|
-
labelKey: "row.matched",
|
|
1190
|
-
value: text(projected["count"])
|
|
1191
|
-
}]
|
|
1192
|
-
};
|
|
1193
|
-
}
|
|
1194
|
-
if (tool === "scrapling_session_list") return {
|
|
1195
|
-
tool,
|
|
1196
|
-
title: tool,
|
|
1197
|
-
fields: [{
|
|
1198
|
-
labelKey: "row.sessionCount",
|
|
1199
|
-
value: text(projected["count"])
|
|
1200
|
-
}]
|
|
1201
|
-
};
|
|
1202
|
-
if (tool === "scrapling_session_open") return {
|
|
1203
|
-
tool,
|
|
1204
|
-
title: tool,
|
|
1205
|
-
fields: [{
|
|
1206
|
-
labelKey: "row.type",
|
|
1207
|
-
value: text(parameters["sessionType"])
|
|
1208
|
-
}, {
|
|
1209
|
-
labelKey: "row.session",
|
|
1210
|
-
value: text(projected["sessionId"])
|
|
1211
|
-
}]
|
|
1212
|
-
};
|
|
1213
|
-
if (tool === "scrapling_session_close") return {
|
|
1214
|
-
tool,
|
|
1215
|
-
title: tool,
|
|
1216
|
-
fields: [{
|
|
1217
|
-
labelKey: "row.session",
|
|
1218
|
-
value: text(parameters["sessionId"])
|
|
1219
|
-
}]
|
|
1220
|
-
};
|
|
1221
|
-
if (tool === "scrapling_crawl") return {
|
|
1222
|
-
tool,
|
|
1223
|
-
title: tool,
|
|
1224
|
-
fields: [
|
|
1225
|
-
{
|
|
1226
|
-
labelKey: "row.start",
|
|
1227
|
-
value: url
|
|
1228
|
-
},
|
|
1229
|
-
{
|
|
1230
|
-
labelKey: "row.pageCap",
|
|
1231
|
-
value: text(parameters["maxPages"])
|
|
1232
|
-
},
|
|
1233
|
-
{
|
|
1234
|
-
labelKey: "row.job",
|
|
1235
|
-
value: text(projected["jobId"])
|
|
1236
|
-
}
|
|
1237
|
-
]
|
|
1238
|
-
};
|
|
1239
|
-
const fields = [];
|
|
1240
|
-
if (url !== "") fields.push({
|
|
1241
|
-
labelKey: "row.url",
|
|
1242
|
-
value: url
|
|
1243
|
-
});
|
|
1244
|
-
const status = projected["statusCode"];
|
|
1245
|
-
if (typeof status === "number") fields.push({
|
|
1246
|
-
labelKey: "row.http",
|
|
1247
|
-
value: String(status)
|
|
1248
|
-
});
|
|
1249
|
-
if (projected["truncated"] === true) fields.push({
|
|
1250
|
-
labelKey: "row.body",
|
|
1251
|
-
value: "",
|
|
1252
|
-
valueKey: "row.truncated"
|
|
1253
|
-
});
|
|
1254
|
-
return {
|
|
1255
|
-
tool,
|
|
1256
|
-
title: tool,
|
|
1257
|
-
fields
|
|
1258
|
-
};
|
|
1259
|
-
}
|
|
1260
|
-
/** 结果行用得到的参数键。视图是惰性的,只挑这几个读才不会物化整段参数 JSON。 */
|
|
1261
|
-
const ARG_KEYS = [
|
|
1262
|
-
"url",
|
|
1263
|
-
"selector",
|
|
1264
|
-
"sessionType",
|
|
1265
|
-
"sessionId",
|
|
1266
|
-
"maxPages"
|
|
1267
|
-
];
|
|
1268
|
-
/**
|
|
1269
|
-
* 把宿主的参数视图摊成 buildRow 认得的普通对象。
|
|
1270
|
-
*
|
|
1271
|
-
* @param args - 宿主给的参数视图
|
|
1272
|
-
* @returns 普通对象;视图缺席时是空对象
|
|
1273
|
-
*/
|
|
1274
|
-
function readArgs(args) {
|
|
1275
|
-
if (args === void 0) return {};
|
|
1276
|
-
const values = {};
|
|
1277
|
-
for (const key of ARG_KEYS) {
|
|
1278
|
-
const asValue = args.text(key) ?? args.value(key);
|
|
1279
|
-
if (asValue !== void 0) values[key] = asValue;
|
|
1280
|
-
}
|
|
1281
|
-
return values;
|
|
1282
|
-
}
|
|
1283
|
-
/**
|
|
1284
|
-
* 结果侧投影只在 `phase === "result"` 那一支上有:宿主的 toolview props 把阶段写在**顶层**,
|
|
1285
|
-
* `block` 是按阶段变形的联合(preparing / start / result 各一种节点),meta 只挂在落定的那一支。
|
|
1286
|
-
*
|
|
1287
|
-
* @param props - 宿主给的 owner props
|
|
1288
|
-
* @returns 结果侧投影;没落定时是 undefined
|
|
1289
|
-
*/
|
|
1290
|
-
function resultMetaOf(props) {
|
|
1291
|
-
return props.phase === "result" ? props.block.meta : void 0;
|
|
1292
|
-
}
|
|
1293
|
-
/** 结果行自己的样式。跟着宿主的语义色走,明暗两套主题都成立。 */
|
|
1294
|
-
const ROW_CSS = `
|
|
36
|
+
`)}function S(e,t){return e.secret===!0&&!t?`password`:`text`}function C(t){let{field:n,label:r,shown:i,disabled:a,revealed:o,onReveal:s,t:c,onChange:l}=t;if(n.kind===`boolean`)return(0,e.createElement)(`input`,{type:`checkbox`,className:`dss-switch`,role:`switch`,checked:i===`true`,disabled:a,"aria-label":r,onChange:e=>{l(String(e.target.checked))}});if(n.kind===`enum`)return(0,e.createElement)(`select`,{disabled:a,value:i,"aria-label":r,onChange:e=>{l(e.target.value)}},(n.options??[]).map(t=>(0,e.createElement)(`option`,{key:t,value:t},t)));let u=(0,e.createElement)(`input`,{type:S(n,o),value:i,disabled:a,...n.kind===`number`?{inputMode:`numeric`}:{},...n.secret===!0?{autoComplete:`off`,spellCheck:!1}:{},"aria-label":r,onChange:e=>{l(e.target.value)}});return n.secret===!0?(0,e.createElement)(`span`,{className:`dss-secret`},u,(0,e.createElement)(`button`,{type:`button`,className:`dss-button dss-reveal`,disabled:a,"aria-pressed":o,"aria-label":r,onClick:()=>{s()}},c(o?`conceal`:`reveal`))):u}function w(t){let{field:n,t:r,shown:i,disabled:a,revealed:o,onReveal:s,onChange:c}=t,l=r(`field.${n.key}.label`),u=C({field:n,label:l,shown:i,disabled:a,revealed:o,onReveal:s,t:r,onChange:c}),d=(0,e.createElement)(`div`,{className:`dss-label`},l,(0,e.createElement)(`p`,{className:`dss-hint`},r(`field.${n.key}.hint`)));return(0,e.createElement)(`div`,{className:`dss-field`,key:n.key},d,(0,e.createElement)(`div`,{className:`dss-control`},u))}function T(t){let{group:n,t:r,shown:i,disabled:a,revealed:o,onReveal:s,onChange:c}=t;return(0,e.createElement)(`section`,{className:`dss-group`,key:n.id},(0,e.createElement)(`h3`,{className:`dss-groupTitle`},r(`group.${n.id}.title`)),(0,e.createElement)(`p`,{className:`dss-note`},r(`group.${n.id}.note`)),(0,e.createElement)(`div`,{className:`dss-fields`},n.fields.map(e=>w({field:e,t:r,shown:i(e),disabled:a,revealed:o(e),onReveal:()=>{s(e)},onChange:t=>{c(e,t)}}))))}function E(e,t,n,r){return t.status===`loading`?e(`statusLoading`):r>0?e(`statusInvalid`,{count:r}):t.status===`unavailable`||!t.writable?e(`statusReadonly`):n===0?e(`statusClean`):e(`statusChanged`,{count:n})}const D={values:{},baseRevision:void 0,invalid:[],invalidText:{}};function O(t){let{t:n,saving:r,editable:i,blocked:a,changed:o,onSave:s,onUndo:c}=t,l=o===0;return(0,e.createElement)(`div`,{className:`dss-actions`},(0,e.createElement)(`button`,{type:`button`,className:`dss-button`,"data-primary":`true`,disabled:l||a||r||!i,onClick:s},n(r?`saving`:`save`)),(0,e.createElement)(`button`,{type:`button`,className:`dss-button`,disabled:l||a||r,onClick:c},n(`undo`)))}function k(t){let{form:n,t:r}=t,[i,o]=(0,e.useState)(D),[s,c]=(0,e.useState)(``),[l,u]=(0,e.useState)(!1),[d,m]=(0,e.useState)([]),v=(0,e.useSyncExternalStore)(n===void 0?p:n.subscribe,n===void 0?f:n.getSnapshot);if(t.view!==`page`||n===void 0)return(0,e.createElement)(`div`,{className:`dss-card`});let y=v.writable&&v.status===`ready`,b=_(i.values),x=async()=>{u(!0),c(``);try{await n.mutate(b,i.baseRevision)?o(e=>{let t={...e.values};for(let e of b){let[n]=e.path;Reflect.deleteProperty(t,n)}return Object.keys(t).length===0?D:{...e,values:t}}):c(i.baseRevision!==void 0&&i.baseRevision!==v.revision?r(`stale`):r(`rejected`))}catch(e){c(r(`failed`,{reason:String(e)}))}finally{u(!1)}},S=(e,t)=>{c(``);let n=g(e,t);o(r=>{let i={...r.values},a={...r.invalidText},o=r.invalid.filter(t=>t!==e.key),s=r.baseRevision??v.revision;return n.kind===`invalid`?(Reflect.deleteProperty(i,e.key),a[e.key]=t,{values:i,baseRevision:s,invalid:[...o,e.key],invalidText:a}):(Reflect.deleteProperty(a,e.key),i[e.key]=n.kind===`clear`?null:n.value,{values:i,baseRevision:s,invalid:o,invalidText:a})})},C=a.map(e=>T({group:e,t:r,shown:e=>h(e,v.value,i.values,i.invalidText),disabled:!y||l,revealed:e=>d.includes(e.key),onReveal:e=>{m(t=>t.includes(e.key)?t.filter(t=>t!==e.key):[...t,e.key])},onChange:S})),w=O({t:r,saving:l,editable:y,blocked:i.invalid.length>0,changed:b.length,onSave:()=>{x()},onUndo:()=>{o(D),c(``)}}),k=(0,e.createElement)(`p`,{className:`dss-status`,"data-error":`false`,role:`status`,"aria-live":`polite`},E(r,v,b.length,i.invalid.length)),A=s===``?null:(0,e.createElement)(`p`,{className:`dss-status`,"data-error":`true`,role:`alert`,"aria-live":`assertive`},s);return(0,e.createElement)(`div`,{className:`dss-card`},k,A,...C,w)}const A=`row.session`,j=[`scrapling_fetch`,`scrapling_extract`,`scrapling_render`,`scrapling_capture_xhr`,`scrapling_answer`,`scrapling_session_open`,`scrapling_session_fetch`,`scrapling_session_network`,`scrapling_session_state_save`,`scrapling_session_state_load`,`scrapling_session_list`,`scrapling_session_close`,`scrapling_crawl`];function M(e){return typeof e==`string`?e:typeof e==`number`||typeof e==`boolean`?String(e):``}function N(...e){for(let t of e){let e=M(t);if(e!==``)return e}return``}function P(e,t,n){let r=i(t)?t:{},a=i(n)?n:{},o=N(a.url,r.url);if(e===`scrapling_extract`){let t=M(r.selector);return{tool:e,title:t===``?e:`${e} ${t}`,fields:[{labelKey:`row.matched`,value:M(a.count)}]}}if(e===`scrapling_session_list`)return{tool:e,title:e,fields:[{labelKey:`row.sessionCount`,value:M(a.count)}]};if(e===`scrapling_session_open`)return{tool:e,title:e,fields:[{labelKey:`row.type`,value:M(r.sessionType)},{labelKey:A,value:M(a.sessionId)}]};if(e===`scrapling_session_close`)return{tool:e,title:e,fields:[{labelKey:A,value:M(r.sessionId)}]};if(e===`scrapling_session_network`||e===`scrapling_session_state_save`||e===`scrapling_session_state_load`){let t=[{labelKey:A,value:M(r.sessionId)}],n=M(r.name);return n!==``&&t.push({labelKey:`row.name`,value:n}),{tool:e,title:e,fields:t}}if(e===`scrapling_crawl`)return{tool:e,title:e,fields:[{labelKey:`row.start`,value:o},{labelKey:`row.pageCap`,value:M(r.maxPages)},{labelKey:`row.job`,value:M(a.jobId)}]};let s=[];o!==``&&s.push({labelKey:`row.url`,value:o});let c=a.statusCode;return typeof c==`number`&&s.push({labelKey:`row.http`,value:String(c)}),a.truncated===!0&&s.push({labelKey:`row.body`,value:``,valueKey:`row.truncated`}),{tool:e,title:e,fields:s}}const F=[`url`,`selector`,`sessionType`,`sessionId`,`name`,`maxPages`];function I(e){if(e===void 0)return{};let t={};for(let n of F){let r=e.text(n)??e.value(n);r!==void 0&&(t[n]=r)}return t}function L(e){return e.phase===`result`?e.block.meta:void 0}function R(t){let{toolName:n,block:r,inspect:i,t:a}=t,o=L(t),s=P(n,I(r.args),o),c=[(0,e.createElement)(`div`,{className:`dsh-scrapling-rowTitle`,key:`title`},s.title)];return s.fields.length>0&&c.push((0,e.createElement)(`ul`,{className:`dsh-scrapling-rowFields`,key:`fields`},s.fields.map(t=>(0,e.createElement)(`li`,{className:`dsh-scrapling-rowField`,key:t.labelKey},(0,e.createElement)(`span`,{className:`dsh-scrapling-rowLabel`},a(t.labelKey)),(0,e.createElement)(`span`,{className:`dsh-scrapling-rowValue`},t.valueKey===void 0?t.value:a(t.valueKey)))))),i!==void 0&&c.push((0,e.createElement)(`button`,{type:`button`,className:`dsh-scrapling-rowButton`,key:`inspect`,onClick:()=>{i()}},a(`row.inspect`))),(0,e.createElement)(`div`,{className:`dsh-scrapling-row`,"data-tool":n},...c)}const z=[`slots`,`configForms`,`locale`];function B(t){let n=t.locale.bind(s),r=[];for(let i of j)r.push(t.slots.register({name:`tool.call.toolview`,key:i,locale:s},t=>(0,e.createElement)(R,{...t,t:n})));return()=>{for(let e of r)e()}}function V(t){r(t,`__dshScraplingToolviewApplied`,`dsh-scrapling toolview`)&&(t.effect(()=>{let e=y();if(e===void 0)return()=>void 0;let t=x(e),n=b(e,`dsh-scrapling-row-css`,`
|
|
1295
37
|
.dsh-scrapling-row{display:flex;flex-direction:column;gap:2px;min-width:0}
|
|
1296
38
|
.dsh-scrapling-rowTitle{color:var(--dsw-alias-label-primary);font-size:13px;line-height:20px;overflow:hidden;text-overflow:ellipsis;white-space:nowrap}
|
|
1297
39
|
.dsh-scrapling-rowFields{display:flex;flex-wrap:wrap;gap:2px 12px;margin:0;padding:0;list-style:none}
|
|
@@ -1301,130 +43,7 @@ const ROW_CSS = `
|
|
|
1301
43
|
.dsh-scrapling-rowButton{align-self:flex-start;border:0;background:0 0;padding:0;color:var(--dsw-alias-label-tertiary);font:inherit;font-size:12px;cursor:pointer}
|
|
1302
44
|
.dsh-scrapling-rowButton:hover{color:var(--dsw-alias-label-primary)}
|
|
1303
45
|
.dsh-scrapling-rowButton:focus-visible{outline:var(--dsw-focus-ring-width) solid var(--dsw-focus-ring-color,var(--dsw-alias-state-business-primary));outline-offset:1px}
|
|
1304
|
-
|
|
1305
|
-
/**
|
|
1306
|
-
* 一行结果的渲染。
|
|
1307
|
-
*
|
|
1308
|
-
* 入参走 `block.args`,结果侧的投影走顶层 `phase` 选出的 `block.meta`;两者都按「可能还没到」处理 ——
|
|
1309
|
-
* 调用刚发出时既没有 meta 也没有完整入参,这一行就只画标题。
|
|
1310
|
-
*/
|
|
1311
|
-
function RowView(props) {
|
|
1312
|
-
const { toolName, block, inspect, t } = props;
|
|
1313
|
-
const meta = resultMetaOf(props);
|
|
1314
|
-
const spec = buildRow(toolName, readArgs(block.args), meta);
|
|
1315
|
-
const children = [(0, react.createElement)("div", {
|
|
1316
|
-
className: "dsh-scrapling-rowTitle",
|
|
1317
|
-
key: "title"
|
|
1318
|
-
}, spec.title)];
|
|
1319
|
-
if (spec.fields.length > 0) children.push((0, react.createElement)("ul", {
|
|
1320
|
-
className: "dsh-scrapling-rowFields",
|
|
1321
|
-
key: "fields"
|
|
1322
|
-
}, spec.fields.map((field) => (0, react.createElement)("li", {
|
|
1323
|
-
className: "dsh-scrapling-rowField",
|
|
1324
|
-
key: field.labelKey
|
|
1325
|
-
}, (0, react.createElement)("span", { className: "dsh-scrapling-rowLabel" }, t(field.labelKey)), (0, react.createElement)("span", { className: "dsh-scrapling-rowValue" }, field.valueKey ?? field.value)))));
|
|
1326
|
-
if (inspect !== void 0) children.push((0, react.createElement)("button", {
|
|
1327
|
-
type: "button",
|
|
1328
|
-
className: "dsh-scrapling-rowButton",
|
|
1329
|
-
key: "inspect",
|
|
1330
|
-
onClick: () => {
|
|
1331
|
-
inspect();
|
|
1332
|
-
}
|
|
1333
|
-
}, t("row.inspect")));
|
|
1334
|
-
return (0, react.createElement)("div", {
|
|
1335
|
-
className: "dsh-scrapling-row",
|
|
1336
|
-
"data-tool": toolName
|
|
1337
|
-
}, ...children);
|
|
1338
|
-
}
|
|
1339
|
-
/** 本 Client 半注入的服务。三个都得在这儿 —— 见文件头第二条。 */
|
|
1340
|
-
const inject = [
|
|
1341
|
-
"slots",
|
|
1342
|
-
"configForms",
|
|
1343
|
-
"locale"
|
|
1344
|
-
];
|
|
1345
|
-
/**
|
|
1346
|
-
* 给每个需要专用结果行的工具登记一行视图。
|
|
1347
|
-
*
|
|
1348
|
-
* @param ctx - 已就绪 slots 与 locale 的上下文
|
|
1349
|
-
* @returns 注销全部登记的函数
|
|
1350
|
-
*/
|
|
1351
|
-
function registerToolViews(ctx) {
|
|
1352
|
-
const t = ctx.locale.bind(LOCALE_NS);
|
|
1353
|
-
const disposers = [];
|
|
1354
|
-
for (const tool of ROW_TOOLS) disposers.push(ctx.slots.register({
|
|
1355
|
-
name: "tool.call.toolview",
|
|
1356
|
-
key: tool,
|
|
1357
|
-
locale: LOCALE_NS
|
|
1358
|
-
}, (props) => (0, react.createElement)(RowView, {
|
|
1359
|
-
...props,
|
|
1360
|
-
t
|
|
1361
|
-
})));
|
|
1362
|
-
return () => {
|
|
1363
|
-
for (const dispose of disposers) dispose();
|
|
1364
|
-
};
|
|
1365
|
-
}
|
|
1366
|
-
/**
|
|
1367
|
-
* Client 插件入口:给每个工具注册一行结果视图,并把设置卡挂上插件详情页。
|
|
1368
|
-
*
|
|
1369
|
-
* @param ctx - 客户端上下文
|
|
1370
|
-
*/
|
|
1371
|
-
function apply(ctx) {
|
|
1372
|
-
if (!e$1(ctx, "__dshScraplingToolviewApplied", "dsh-scrapling toolview")) return;
|
|
1373
|
-
ctx.effect(() => {
|
|
1374
|
-
const doc = browserDocument();
|
|
1375
|
-
if (doc === void 0) return () => void 0;
|
|
1376
|
-
const disposeCard = installStyles(doc);
|
|
1377
|
-
const disposeRow = installStyle(doc, "dsh-scrapling-row-css", ROW_CSS);
|
|
1378
|
-
return () => {
|
|
1379
|
-
disposeCard();
|
|
1380
|
-
disposeRow();
|
|
1381
|
-
};
|
|
1382
|
-
}, "dsh-scrapling: client styles");
|
|
1383
|
-
ctx.effect(() => {
|
|
1384
|
-
const dictionaries = localeDictionaries();
|
|
1385
|
-
const disposers = [ctx.locale.register(LOCALE_NS, "zh", dictionaries.zh), ctx.locale.register(LOCALE_NS, "en", dictionaries.en)];
|
|
1386
|
-
let disposeRows;
|
|
1387
|
-
ctx.slots.inject("tool.call.toolview", () => {
|
|
1388
|
-
disposeRows = registerToolViews(ctx);
|
|
1389
|
-
});
|
|
1390
|
-
return () => {
|
|
1391
|
-
disposeRows?.();
|
|
1392
|
-
for (const dispose of disposers) dispose();
|
|
1393
|
-
};
|
|
1394
|
-
}, "dsh-scrapling: dictionaries and tool rows");
|
|
1395
|
-
ctx.effect(() => {
|
|
1396
|
-
const form = ctx.configForms.get(SETTINGS_ENTRY_ID);
|
|
1397
|
-
const t = ctx.locale.bind(LOCALE_NS);
|
|
1398
|
-
const source = {
|
|
1399
|
-
getSnapshot: () => form.getSnapshot(),
|
|
1400
|
-
subscribe: (listener) => form.subscribe(listener),
|
|
1401
|
-
mutate: (operations, revision) => form.mutate(operations, revision)
|
|
1402
|
-
};
|
|
1403
|
-
let disposeCard;
|
|
1404
|
-
ctx.slots.inject("plugins.bundle.config", () => {
|
|
1405
|
-
disposeCard = ctx.slots.register({
|
|
1406
|
-
name: "plugins.bundle.config",
|
|
1407
|
-
key: BUNDLE_PACKAGE_NAME,
|
|
1408
|
-
locale: LOCALE_NS
|
|
1409
|
-
}, (props) => (0, react.createElement)(SettingsCard, {
|
|
1410
|
-
...props,
|
|
1411
|
-
t,
|
|
1412
|
-
form: source
|
|
1413
|
-
}));
|
|
1414
|
-
});
|
|
1415
|
-
return () => {
|
|
1416
|
-
disposeCard?.();
|
|
1417
|
-
};
|
|
1418
|
-
}, "dsh-scrapling: settings card");
|
|
1419
|
-
}
|
|
1420
|
-
//#endregion
|
|
1421
|
-
exports.ROW_TOOLS = ROW_TOOLS;
|
|
1422
|
-
exports.apply = apply;
|
|
1423
|
-
exports.buildRow = buildRow;
|
|
1424
|
-
exports.inject = inject;
|
|
1425
|
-
exports.readArgs = readArgs;
|
|
1426
|
-
exports.resultMetaOf = resultMetaOf;
|
|
1427
|
-
|
|
46
|
+
`);return()=>{t(),n()}},`dsh-scrapling: client styles`),t.effect(()=>{let e=u(),n=[t.locale.register(s,`zh`,e.zh),t.locale.register(s,`en`,e.en)],r;return t.slots.inject(`tool.call.toolview`,()=>{r=B(t)}),()=>{r?.();for(let e of n)e()}},`dsh-scrapling: dictionaries and tool rows`),t.effect(()=>{let n=t.configForms.get(`scrapling`),r=t.locale.bind(s),i={getSnapshot:()=>n.getSnapshot(),subscribe:e=>n.subscribe(e),mutate:(e,t)=>n.mutate(e,t)},a;return t.slots.inject(`plugins.bundle.config`,()=>{a=t.slots.register({name:`plugins.bundle.config`,key:`@jayyuen66/dsh-scrapling`,locale:s},t=>(0,e.createElement)(k,{...t,t:r,form:i}))}),()=>{a?.()}},`dsh-scrapling: settings card`))}exports.ROW_TOOLS=j,exports.apply=V,exports.buildRow=P,exports.inject=z,exports.readArgs=I,exports.resultMetaOf=L;
|
|
1428
47
|
return module.exports;
|
|
1429
48
|
},
|
|
1430
49
|
});
|