@jayyuen66/dsh-scrapling 0.1.4 → 0.1.5
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 +40 -0
- package/README.md +1 -1
- package/README.zh-CN.md +1 -1
- package/THIRD_PARTY_NOTICES.md +1 -0
- package/bin/dsh-scrapling.mjs +119 -10
- package/client.js +110 -35
- package/docs/DETAIL.md +41 -0
- package/docs/DETAIL.zh.md +41 -0
- package/host.js +7 -9
- package/locale/en.json +7 -0
- package/locale/zh.json +7 -0
- package/package.json +54 -45
package/client.js
CHANGED
|
@@ -5,43 +5,118 @@ 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`});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(Windows 上是 python);装了 pyenv/conda 时填绝对路径。`,en:`Empty: use the repo's _env/.venv when it exists, else python3 from PATH (python on Windows); 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:`locateEnabled`,kind:`boolean`,label:{zh:`scrapling_locate`,en:`scrapling_locate`},hint:{zh:`按文本、正则或相似元素定位,返回可复用的选择器。`,en:`Locate by text, regex, or similar elements and return reusable selectors.`},fallback:!0},{key:`linksEnabled`,kind:`boolean`,label:{zh:`scrapling_links`,en:`scrapling_links`},hint:{zh:`列出页面链接与下一页候选。`,en:`List page links and next-page candidates.`},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},{key:`sessionReadEnabled`,kind:`boolean`,label:{zh:`scrapling_session_read`,en:`scrapling_session_read`},hint:{zh:`读浏览器会话当前页,不再发请求。`,en:`Read the current page of a browser session without another request.`},fallback:!0},{key:`sessionActionsEnabled`,kind:`boolean`,label:{zh:`scrapling_session_act`,en:`scrapling_session_act`},hint:{zh:`结构化浏览器动作;还要部署侧打开 allowBrowserActions。`,en:`Structured browser actions; the deployment must also set allowBrowserActions.`},fallback:!0},{key:`downloadEnabled`,kind:`boolean`,label:{zh:`scrapling_download`,en:`scrapling_download`},hint:{zh:`下载文件到插件目录;还要部署侧打开 allowFileDownloads。`,en:`Download files into the plugin directory; the deployment must also set allowFileDownloads.`},fallback:!0},{key:`screenshotEnabled`,kind:`boolean`,label:{zh:`scrapling_screenshot`,en:`scrapling_screenshot`},hint:{zh:`页面截图;没有 attachment 服务时不注册。`,en:`Page screenshots; not registered when no attachment service is mounted.`},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:`预算按 UTF-8 字节计,超出部分截断并标注;同一数值也作为 sidecar 的字符上限,最终取更紧的一档。`,en:`UTF-8 bytes; the payload is clipped and flagged. The same value also caps sidecar characters, so the tighter limit wins.`},fallback:2e5},{key:`extractMaxOutputChars`,kind:`number`,label:{zh:`抽取结果上限`,en:`extract output cap`},hint:{zh:`预算按 UTF-8 字节计;同一数值也作为 sidecar 的字符上限。`,en:`UTF-8 bytes; the same value also caps sidecar characters.`},fallback:2e5},{key:`renderMaxOutputChars`,kind:`number`,label:{zh:`渲染结果上限`,en:`render output cap`},hint:{zh:`预算按 UTF-8 字节计;会话类工具共用这一档,同一数值也作为 sidecar 的字符上限。`,en:`UTF-8 bytes; the session tools share this budget, and the same value also caps sidecar characters.`},fallback:2e5},{key:`xhrMaxOutputChars`,kind:`number`,label:{zh:`XHR 快照上限`,en:`XHR snapshot cap`},hint:{zh:`预算按 UTF-8 字节计;同一数值也作为 sidecar 的字符上限。`,en:`UTF-8 bytes; the same value also caps sidecar 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:`默认开;部署配置里仍要写 searchProvider: "scrapling",否则不会接管。`,en:`On by default; the deployment config still needs searchProvider: "scrapling", otherwise it does not take over.`},fallback:!0},{key:`searchBackend`,kind:`enum`,options:[`auto`,`tavily`,`bing`,`brave`,`serper`,`duckduckgo`,`searxng`],label:{zh:`搜索发现后端`,en:`Search discovery backend`},hint:{zh:`auto 有 Tavily key 走 Tavily、配了 SearXNG 走 SearXNG;两者都没有时,只有打开「允许公共搜索回退」才走公共引擎(DuckDuckGo → Bing)。只有 Tavily 与 Bing 打过真实端点;其余四条按文档形状实现,真实 key 未验。`,en:`auto uses Tavily when a key is set, SearXNG when an instance is configured; with neither, only "Allow public search fallback" routes to public engines (DuckDuckGo → Bing). Only Tavily and Bing have been run against the real endpoints; the other four follow their documented shapes and are unverified with real keys.`},fallback:`auto`},{key:`searchPublicFallback`,kind:`boolean`,label:{zh:`允许公共搜索回退`,en:`Allow public search fallback`},hint:{zh:`默认关。打开后 auto 后端在没配 key、也没配 SearXNG 时会回落到 DuckDuckGo/Bing —— 查询词会发给公共引擎。`,en:`Off by default. When enabled, the auto backend falls back to DuckDuckGo/Bing if no API key or SearXNG is configured — queries are then sent to public engines.`},fallback:!1},{key:`tavilyApiKey`,kind:`text`,secret:!0,label:{zh:`Tavily API key`,en:`Tavily API key`},hint:{zh:`Tavily 后端必填;没配时 search 报 SEARCH_AUTH,不会静默换后端。`,en:`Required by the Tavily backend; without it search reports SEARCH_AUTH instead of silently switching backends.`},fallback:``},{key:`braveApiKey`,kind:`text`,secret:!0,label:{zh:`Brave Search API key`,en:`Brave Search API key`},hint:{zh:`Brave 后端必填;没配时 search 报 SEARCH_AUTH。`,en:`Required by the Brave backend; without it search reports SEARCH_AUTH.`},fallback:``},{key:`serperApiKey`,kind:`text`,secret:!0,label:{zh:`Serper API key`,en:`Serper API key`},hint:{zh:`Serper 后端必填;没配时 search 报 SEARCH_AUTH。`,en:`Required by the Serper backend; without it search reports SEARCH_AUTH.`},fallback:``},{key:`searxngEndpoint`,kind:`text`,label:{zh:`SearXNG 实例地址`,en:`SearXNG instance URL`},hint:{zh:`SearXNG 后端必填,例如 https://searx.example.com;会拼上 /search?format=json。留空表示这条后端不可用。`,en:`Required by the SearXNG backend, e.g. https://searx.example.com; /search?format=json is appended. Empty means the backend is unusable.`},fallback:``}]},{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}`,runtimeTitle:`运行环境`,runtimeHint:`能力包装在数据目录的 runtime/ 下;安装是后台作业,关掉这张卡也会继续。`,runtimeUnavailable:`宿主没有提供远程读面;请在终端运行:`,runtimeJobsMissing:`这个 profile 没有作业后端;请在终端运行:`,runtimeInstall:`安装`,runtimeRepair:`修复`,runtimeCancel:`取消`,runtimePython:`解释器`,runtimeDataDir:`数据目录`,runtimeJobRunning:`正在安装 {pack}…`,runtimeJobEnded:`安装结束:{status}`,runtimeError:`安装失败:{reason}`,"runtime.state.ready":`就绪`,"runtime.state.missing":`未安装`,"runtime.state.corrupt":`文件缺失`,"runtime.state.installing":`安装中`,"runtime.state.blocked":`暂不提供`,"runtime.pack.core":`核心(Python + Scrapling)`,"runtime.pack.browser":`完整 Chromium`,"runtime.pack.search":`搜索发现`,"runtime.pack.media":`截图与下载`,"runtime.pack.adaptive-redis":`自适应存储(Redis)`,"runtime.pack.mcp":`MCP(未验证)`},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}`,runtimeTitle:`Runtime`,runtimeHint:`Capability packs live under runtime/ in the data directory; installs run as background jobs and keep going when this page closes.`,runtimeUnavailable:`The host offers no remote surface; run this in a terminal:`,runtimeJobsMissing:`This profile has no jobs backend; run this in a terminal:`,runtimeInstall:`Install`,runtimeRepair:`Repair`,runtimeCancel:`Cancel`,runtimePython:`Interpreter`,runtimeDataDir:`Data directory`,runtimeJobRunning:`Installing {pack}…`,runtimeJobEnded:`Install finished: {status}`,runtimeError:`Install failed: {reason}`,"runtime.state.ready":`Ready`,"runtime.state.missing":`Not installed`,"runtime.state.corrupt":`Files missing`,"runtime.state.installing":`Installing`,"runtime.state.blocked":`Unavailable`,"runtime.pack.core":`Core (Python + Scrapling)`,"runtime.pack.browser":`Full Chromium`,"runtime.pack.search":`Search discovery`,"runtime.pack.media":`Screenshots & downloads`,"runtime.pack.adaptive-redis":`Adaptive storage (Redis)`,"runtime.pack.mcp":`MCP (unverified)`}},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=[`core`,`browser`,`search`,`media`,`adaptive-redis`,`mcp`],f=new Set(d);function p(e){return typeof e==`string`&&f.has(e)}function m(e){return`runtime.state.${e}`}function h(e){return`runtime.pack.${e}`}const g={status:`loading`,writable:!1};function _(){return g}function v(){return()=>void 0}function y(e){return typeof e==`string`?e:typeof e==`number`||typeof e==`boolean`?String(e):``}function b(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 y(a);let o=t?.[e.key];return o===void 0?String(e.fallback):y(o)}function x(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 S(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}})}const C=`dss-button`,w=`dss-status`;function T(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 E(){let e=Reflect.get(globalThis,`document`);return T(e)?e:void 0}function D(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 O(e){return D(e,`dsh-scrapling-settings-css`,`
|
|
9
|
-
|
|
10
|
-
.
|
|
11
|
-
|
|
12
|
-
.
|
|
13
|
-
|
|
14
|
-
.
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
.
|
|
19
|
-
|
|
20
|
-
.
|
|
21
|
-
|
|
22
|
-
.
|
|
23
|
-
|
|
24
|
-
.
|
|
25
|
-
|
|
26
|
-
.
|
|
27
|
-
|
|
28
|
-
.
|
|
29
|
-
|
|
30
|
-
.
|
|
31
|
-
|
|
32
|
-
.
|
|
33
|
-
.dss-
|
|
34
|
-
.dss-
|
|
35
|
-
.dss-runtime{display:flex;flex-direction:column;gap:10px;border-top:.5px solid var(--dsw-alias-border-l2);padding-top:16px}
|
|
36
|
-
.dss-runtimeInfo{margin:0;color:var(--dsw-alias-label-tertiary);font-size:12px;line-height:18px;word-break:break-all}
|
|
8
|
+
Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});let e=require("react"),t=require("zod");const n=e=>e.length>0&&!(e in Object.prototype);function r(e,t,n){n===void 0?e[t]=void 0:Object.defineProperty(e,t,n)}function i(e,t,i){if(!n(t))throw Error(`claimApply 的 flag 不得为空、也不得命中 Object.prototype 的成员(__proto__ 一类会让占位静默失灵或遮蔽全局成员):${t}`);let a=globalThis,o=Object.hasOwn(a,t)?a[t]:void 0;if(o===!0||typeof o==`symbol`)return!1;let s=Object.getOwnPropertyDescriptor(a,t),c=Symbol(t);a[t]=c;try{e.effect(()=>()=>{a[t]===c&&r(a,t,s)},i)}catch(e){throw a[t]===c&&r(a,t,s),e}return!0}function a(e){return typeof e==`object`&&!!e&&!Array.isArray(e)}const o=[{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(Windows 上是 python);装了 pyenv/conda 时填绝对路径。`,en:`Empty: use the repo's _env/.venv when it exists, else python3 from PATH (python on Windows); 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:`locateEnabled`,kind:`boolean`,label:{zh:`scrapling_locate`,en:`scrapling_locate`},hint:{zh:`按文本、正则或相似元素定位,返回可复用的选择器。`,en:`Locate by text, regex, or similar elements and return reusable selectors.`},fallback:!0},{key:`linksEnabled`,kind:`boolean`,label:{zh:`scrapling_links`,en:`scrapling_links`},hint:{zh:`列出页面链接与下一页候选。`,en:`List page links and next-page candidates.`},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},{key:`sessionReadEnabled`,kind:`boolean`,label:{zh:`scrapling_session_read`,en:`scrapling_session_read`},hint:{zh:`读浏览器会话当前页,不再发请求。`,en:`Read the current page of a browser session without another request.`},fallback:!0},{key:`sessionActionsEnabled`,kind:`boolean`,label:{zh:`scrapling_session_act`,en:`scrapling_session_act`},hint:{zh:`结构化浏览器动作;还要部署侧打开 allowBrowserActions。`,en:`Structured browser actions; the deployment must also set allowBrowserActions.`},fallback:!0},{key:`downloadEnabled`,kind:`boolean`,label:{zh:`scrapling_download`,en:`scrapling_download`},hint:{zh:`下载文件到插件目录;还要部署侧打开 allowFileDownloads。`,en:`Download files into the plugin directory; the deployment must also set allowFileDownloads.`},fallback:!0},{key:`screenshotEnabled`,kind:`boolean`,label:{zh:`scrapling_screenshot`,en:`scrapling_screenshot`},hint:{zh:`页面截图;没有 attachment 服务时不注册。`,en:`Page screenshots; not registered when no attachment service is mounted.`},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:`预算按 UTF-8 字节计,超出部分截断并标注;同一数值也作为 sidecar 的字符上限,最终取更紧的一档。`,en:`UTF-8 bytes; the payload is clipped and flagged. The same value also caps sidecar characters, so the tighter limit wins.`},fallback:2e5},{key:`extractMaxOutputChars`,kind:`number`,label:{zh:`抽取结果上限`,en:`extract output cap`},hint:{zh:`预算按 UTF-8 字节计;同一数值也作为 sidecar 的字符上限。`,en:`UTF-8 bytes; the same value also caps sidecar characters.`},fallback:2e5},{key:`renderMaxOutputChars`,kind:`number`,label:{zh:`渲染结果上限`,en:`render output cap`},hint:{zh:`预算按 UTF-8 字节计;会话类工具共用这一档,同一数值也作为 sidecar 的字符上限。`,en:`UTF-8 bytes; the session tools share this budget, and the same value also caps sidecar characters.`},fallback:2e5},{key:`xhrMaxOutputChars`,kind:`number`,label:{zh:`XHR 快照上限`,en:`XHR snapshot cap`},hint:{zh:`预算按 UTF-8 字节计;同一数值也作为 sidecar 的字符上限。`,en:`UTF-8 bytes; the same value also caps sidecar 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`,format:`url`,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:`默认开;部署配置里仍要写 searchProvider: "scrapling",否则不会接管。`,en:`On by default; the deployment config still needs searchProvider: "scrapling", otherwise it does not take over.`},fallback:!0},{key:`searchBackend`,kind:`enum`,options:[`auto`,`tavily`,`bing`,`brave`,`serper`,`duckduckgo`,`searxng`],label:{zh:`搜索发现后端`,en:`Search discovery backend`},hint:{zh:`auto 有 Tavily key 走 Tavily、配了 SearXNG 走 SearXNG;两者都没有时,只有打开「允许公共搜索回退」才走公共引擎(DuckDuckGo → Bing)。只有 Tavily 与 Bing 打过真实端点;其余四条按文档形状实现,真实 key 未验。`,en:`auto uses Tavily when a key is set, SearXNG when an instance is configured; with neither, only "Allow public search fallback" routes to public engines (DuckDuckGo → Bing). Only Tavily and Bing have been run against the real endpoints; the other four follow their documented shapes and are unverified with real keys.`},fallback:`auto`},{key:`searchPublicFallback`,kind:`boolean`,label:{zh:`允许公共搜索回退`,en:`Allow public search fallback`},hint:{zh:`默认关。打开后 auto 后端在没配 key、也没配 SearXNG 时会回落到 DuckDuckGo/Bing —— 查询词会发给公共引擎。`,en:`Off by default. When enabled, the auto backend falls back to DuckDuckGo/Bing if no API key or SearXNG is configured — queries are then sent to public engines.`},fallback:!1},{key:`tavilyApiKey`,kind:`text`,secret:!0,label:{zh:`Tavily API key`,en:`Tavily API key`},hint:{zh:`Tavily 后端必填;没配时 search 报 SEARCH_AUTH,不会静默换后端。`,en:`Required by the Tavily backend; without it search reports SEARCH_AUTH instead of silently switching backends.`},fallback:``},{key:`braveApiKey`,kind:`text`,secret:!0,label:{zh:`Brave Search API key`,en:`Brave Search API key`},hint:{zh:`Brave 后端必填;没配时 search 报 SEARCH_AUTH。`,en:`Required by the Brave backend; without it search reports SEARCH_AUTH.`},fallback:``},{key:`serperApiKey`,kind:`text`,secret:!0,label:{zh:`Serper API key`,en:`Serper API key`},hint:{zh:`Serper 后端必填;没配时 search 报 SEARCH_AUTH。`,en:`Required by the Serper backend; without it search reports SEARCH_AUTH.`},fallback:``},{key:`searxngEndpoint`,kind:`text`,format:`url`,label:{zh:`SearXNG 实例地址`,en:`SearXNG instance URL`},hint:{zh:`SearXNG 后端必填,例如 https://searx.example.com;会拼上 /search?format=json。留空表示这条后端不可用。`,en:`Required by the SearXNG backend, e.g. https://searx.example.com; /search?format=json is appended. Empty means the backend is unusable.`},fallback:``}]},{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}]}],s=o.flatMap(e=>e.fields);s.map(e=>e.key);const c=`dshScrapling`,l={zh:{save:`保存`,saving:`保存中…`,undo:`撤销`,reveal:`显示`,conceal:`隐藏`,statusLoading:`正在读取设置…`,statusReadonly:`这个连接以只读方式运行,设置改不了。`,statusClean:`没有未保存的改动`,statusChanged:`已改动 {count} 项,未保存`,statusInvalid:`有 {count} 项填的不是合法数字,改好后才能保存`,rejected:`保存被宿主拒绝了,设置未改动`,stale:`设置已经被别处改过,请重新打开这张卡再保存`,failed:`保存失败:{reason}`,runtimeTitle:`运行环境`,runtimeHint:`能力包装在数据目录的 runtime/ 下;安装是后台作业,关掉这张卡也会继续。`,runtimeUnavailable:`宿主没有提供远程读面;请在终端运行:`,runtimeJobsMissing:`这个 profile 没有作业后端;请在终端运行:`,runtimeInstall:`安装`,runtimeRepair:`修复`,runtimeCancel:`取消`,runtimePython:`解释器`,runtimeDataDir:`数据目录`,runtimeJobRunning:`正在安装 {pack}…`,runtimeJobEnded:`安装结束:{status}`,runtimeError:`安装失败:{reason}`,"runtime.state.ready":`就绪`,"runtime.state.missing":`未安装`,"runtime.state.corrupt":`文件缺失`,"runtime.state.installing":`安装中`,"runtime.state.blocked":`暂不提供`,"runtime.pack.core":`核心(Python + Scrapling)`,"runtime.pack.browser":`完整 Chromium`,"runtime.pack.search":`搜索发现`,"runtime.pack.media":`截图与下载`,"runtime.pack.adaptive-redis":`自适应存储(Redis)`,"runtime.pack.mcp":`MCP(未验证)`},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}`,runtimeTitle:`Runtime`,runtimeHint:`Capability packs live under runtime/ in the data directory; installs run as background jobs and keep going when this page closes.`,runtimeUnavailable:`The host offers no remote surface; run this in a terminal:`,runtimeJobsMissing:`This profile has no jobs backend; run this in a terminal:`,runtimeInstall:`Install`,runtimeRepair:`Repair`,runtimeCancel:`Cancel`,runtimePython:`Interpreter`,runtimeDataDir:`Data directory`,runtimeJobRunning:`Installing {pack}…`,runtimeJobEnded:`Install finished: {status}`,runtimeError:`Install failed: {reason}`,"runtime.state.ready":`Ready`,"runtime.state.missing":`Not installed`,"runtime.state.corrupt":`Files missing`,"runtime.state.installing":`Installing`,"runtime.state.blocked":`Unavailable`,"runtime.pack.core":`Core (Python + Scrapling)`,"runtime.pack.browser":`Full Chromium`,"runtime.pack.search":`Search discovery`,"runtime.pack.media":`Screenshots & downloads`,"runtime.pack.adaptive-redis":`Adaptive storage (Redis)`,"runtime.pack.mcp":`MCP (unverified)`}},u={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 d(){let e={zh:{...l.zh,...u.zh},en:{...l.en,...u.en}};for(let t of o){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 f=[`core`,`browser`,`search`,`media`,`adaptive-redis`,`mcp`];new Set(f);function p(e){return`runtime.state.${e}`}function m(e){return`runtime.pack.${e}`}function h(e,t=30){return e.length<=t?{hint:e}:{detail:e}}function g(t){return(0,e.createElement)(`div`,{className:`dsu-form`},t.children)}function _(t){return(0,e.createElement)(`section`,{className:`dsu-section`},(0,e.createElement)(`h2`,{className:`dsu-sectionTitle`},t.title),t.hint===void 0?null:(0,e.createElement)(`p`,{className:`dsu-sectionHint`},t.hint),t.children)}function v(t){if(t.items.length===0)return null;let n=t.items.map((t,n)=>(0,e.createElement)(`span`,{key:n},n===0?t:`· ${t}`));return(0,e.createElement)(`div`,{className:`dsu-statusbar`},...n)}function y(t){let n=(0,e.useId)(),[r,i]=(0,e.useState)(!1),[a,o]=(0,e.useState)(!1),s=(0,e.useRef)(!1),c=(0,e.useRef)(!1),l=(0,e.useRef)(!1),u=(0,e.useRef)(null),d=(0,e.useRef)(null),f=(0,e.useRef)(null),p=(0,e.useCallback)(()=>{f.current!==null&&(clearTimeout(f.current),f.current=null)},[]),m=(0,e.useCallback)(()=>{let e=u.current,t=d.current;
|
|
9
|
+
/* v8 ignore next 3 -- place 只在 open 的 layout effect 与挂载期监听器里调用;refs 为空只可能是卸载竞态 */
|
|
10
|
+
if(e===null||t===null)return;let n=e.getBoundingClientRect(),r=t.offsetWidth,i=t.offsetHeight,{left:a}=n,o=n.bottom+8;o+i>window.innerHeight-8&&(o=n.top-i-8),a+r>window.innerWidth-8&&(a=window.innerWidth-r-8);let s=Math.max(8,window.innerWidth-r-8),c=Math.max(8,window.innerHeight-i-8);t.style.left=`${Math.min(Math.max(8,a),s)}px`,t.style.top=`${Math.min(Math.max(8,o),c)}px`},[]),h=(0,e.useCallback)(()=>{p(),l.current=!1,o(!1),i(!1)},[p]),g=(0,e.useCallback)(()=>{p(),i(!0)},[p]),_=(0,e.useCallback)(()=>{p(),!(s.current||c.current||l.current)&&(f.current=setTimeout(()=>{
|
|
11
|
+
/* v8 ignore next 3 -- 任何重新进入/钉住都会 cancelHide;这次复查只防未来的异步路径 */
|
|
12
|
+
f.current=null,s.current||c.current||l.current||i(!1)},120))},[p]),v=(0,e.useCallback)(e=>{l.current=e,o(e)},[]);(0,e.useLayoutEffect)(()=>{if(!r)return()=>{};m();let e=e=>{let{target:t}=e;t instanceof Node&&d.current?.contains(t)===!0||(l.current?m():h())},t=()=>{m()};return window.addEventListener(`scroll`,e,!0),window.addEventListener(`resize`,t),()=>{window.removeEventListener(`scroll`,e,!0),window.removeEventListener(`resize`,t)}},[r,t.detail,m,h]),(0,e.useEffect)(()=>{if(!r)return()=>{};let e=e=>{e.key===`Escape`&&h()};return document.addEventListener(`keydown`,e),()=>{document.removeEventListener(`keydown`,e)}},[r,h]),(0,e.useEffect)(()=>p,[p]);let y=(0,e.createElement)(`button`,{ref:u,type:`button`,className:`dsu-helpBtn`,"aria-label":`${t.label} 说明`,"aria-describedby":n,"aria-pressed":a,onClick:()=>{l.current?h():(v(!0),g())}},(0,e.createElement)(`svg`,{width:12,height:12,viewBox:`0 0 14 14`,"aria-hidden":!0},(0,e.createElement)(`circle`,{cx:7,cy:7,r:6,fill:`none`,stroke:`currentColor`,strokeWidth:1.2}),(0,e.createElement)(`path`,{d:`M7 6.2v4`,stroke:`currentColor`,strokeWidth:1.3,strokeLinecap:`round`}),(0,e.createElement)(`circle`,{cx:7,cy:4.3,r:.8,fill:`currentColor`}))),b=(0,e.createElement)(`div`,{ref:d,id:n,role:`tooltip`,className:`dsu-tip`,hidden:!r},t.detail),x=t.showLabel===!1?null:(0,e.createElement)(`span`,{className:`dsu-label${t.compact===!0?` dsu-labelMono`:``}`},t.label);return(0,e.createElement)(`span`,{className:`dsu-help`,onMouseEnter:()=>{s.current=!0,g()},onMouseLeave:()=>{s.current=!1,_()},onFocus:()=>{c.current=!0,g()},onBlur:e=>{let t=e.relatedTarget;t instanceof Node&&e.currentTarget.contains(t)||(c.current=!1,_())}},x,y,b)}function b(t){let n=`dsu-label${t.compact===!0?` dsu-labelMono`:``}`,r=t.controlId===void 0?(0,e.createElement)(`span`,{className:n},t.label):(0,e.createElement)(`label`,{className:n,htmlFor:t.controlId},t.label);return(0,e.createElement)(`div`,{className:`dsu-labelRow`},r,t.detail===void 0?null:(0,e.createElement)(y,{label:t.label,detail:t.detail,showLabel:!1}))}function x(t){let n=t.controlId===void 0?void 0:`${t.controlId}-hint`;return(0,e.createElement)(`div`,{className:`dsu-field${t.wide===!0?` dsu-fieldWide`:``}`},(0,e.createElement)(`div`,{className:`dsu-fieldMeta`},(0,e.createElement)(b,{label:t.label,detail:t.detail,compact:t.compact,controlId:t.controlId}),t.hint===void 0?null:(0,e.createElement)(`p`,{className:`dsu-hint`,id:n},t.hint)),(0,e.createElement)(`div`,{className:`dsu-control`},t.children))}function S(t){let n=(0,e.useId)(),r=t.hint===void 0?void 0:`${n}-hint`;return(0,e.createElement)(x,{...t,controlId:n},(0,e.createElement)(`button`,{type:`button`,role:`switch`,id:n,className:`dsu-switch`,"aria-checked":t.checked,"aria-describedby":r,"data-field":t.field,disabled:t.disabled===!0,onClick:()=>{t.onChange(!t.checked)}},(0,e.createElement)(`span`,{className:`dsu-knob`})))}function C(t){let[n,r]=(0,e.useState)(t.value),[i,a]=(0,e.useState)(!1),o=(0,e.useId)(),s=t.hint===void 0?void 0:`${o}-hint`;(0,e.useEffect)(()=>{i||r(t.value)},[t.value,i]);let c={id:o,className:`dsu-input${t.multiline===!0?` dsu-textarea`:``}${t.monospace===!0?` dsu-mono`:``}`,value:n,placeholder:t.placeholder,"aria-describedby":s,"data-field":t.field,disabled:t.disabled===!0,onFocus:()=>{a(!0)},onBlur:()=>{a(!1)},onChange:e=>{r(e.target.value),t.onChange(e.target.value)}};return(0,e.createElement)(x,{...t,controlId:o},t.multiline===!0?(0,e.createElement)(`textarea`,c):(0,e.createElement)(`input`,c))}function w(t){let[n,r]=(0,e.useState)(!1),[i,a]=(0,e.useState)(0),o=(0,e.useRef)(null),s=(0,e.useRef)(null),c=(0,e.useId)(),l=(0,e.useId)(),u=t.hint===void 0?void 0:`${l}-hint`,{disabled:d,value:f,options:p,onChange:m}=t,h=(0,e.useMemo)(()=>p.map((e,t)=>({option:e,index:t})).filter(e=>e.option.disabled!==!0),[p]),g=p.find(e=>e.value===f)?.label??f,_=p[i],v=_!==void 0&&_.disabled!==!0,y=(0,e.useCallback)(()=>{let e=o.current,t=s.current;
|
|
13
|
+
/* v8 ignore next 3 -- place 只在 open 的 layout effect 里调用;refs 为空只可能是卸载竞态 */
|
|
14
|
+
if(e===null||t===null)return;let n=e.getBoundingClientRect(),r=Math.min(n.width,window.innerWidth-16),{left:i}=n;i+r>window.innerWidth-8&&(i=window.innerWidth-r-8);let a=t.offsetHeight,c=n.bottom+6;c+a>window.innerHeight-8&&(c=n.top-a-6);let l=Math.max(8,window.innerWidth-r-8),u=Math.max(8,window.innerHeight-a-8);t.style.width=`${r}px`,t.style.left=`${Math.min(Math.max(8,i),l)}px`,t.style.top=`${Math.min(Math.max(8,c),u)}px`},[]),b=(0,e.useCallback)(()=>{r(!1)},[]),S=(0,e.useCallback)(()=>{if(d===!0)return;let e=h.find(e=>e.option.value===f)??h.at(0);e!==void 0&&(a(e.index),r(!0))},[d,f,h]),C=(0,e.useCallback)(e=>{
|
|
15
|
+
/* v8 ignore next 3 -- 浮层只能经由 openMenu 打开;组件禁用时打不开 */
|
|
16
|
+
if(d===!0)return;let t=p[e];
|
|
17
|
+
/* v8 ignore next 3 -- disabled 选项在浏览器里不派发 click;越界下标由调用面保证 */
|
|
18
|
+
t!==void 0&&t.disabled!==!0&&(m(t.value),b(),o.current?.focus())},[d,p,m,b]),w=(0,e.useCallback)(e=>{let t=h.findIndex(e=>e.index===i);
|
|
19
|
+
/* v8 ignore next 5 -- open 时归一 effect 已保证 enabled 非空且 active 落在可用项上 */
|
|
20
|
+
if(t===-1||h.length===0)return;let n=(t+e+h.length)%h.length,r=h[n];
|
|
21
|
+
/* v8 ignore next 3 -- next 由取模保证在界内 */
|
|
22
|
+
r!==void 0&&a(r.index)},[i,h]);(0,e.useLayoutEffect)(()=>{if(!n)return()=>{};y();let e=e=>{let t=e.target;s.current?.contains(t)!==!0&&o.current?.contains(t)!==!0&&b()},t=e=>{let{target:t}=e;t instanceof Node&&s.current?.contains(t)===!0||b()},r=()=>{y()};return document.addEventListener(`pointerdown`,e,!0),window.addEventListener(`scroll`,t,!0),window.addEventListener(`resize`,r),()=>{document.removeEventListener(`pointerdown`,e,!0),window.removeEventListener(`scroll`,t,!0),window.removeEventListener(`resize`,r)}},[n,t.options,y,b]),(0,e.useEffect)(()=>{if(!n)return;if(d===!0||h.length===0){b();return}if(h.some(e=>e.index===i))return;let e=h.find(e=>e.option.value===f)??h.at(0);
|
|
23
|
+
/* v8 ignore next 3 -- enabled 非空在上一分支已保证 */
|
|
24
|
+
e!==void 0&&a(e.index)},[n,d,f,p,i,b,h]),(0,e.useLayoutEffect)(()=>{if(!n)return;let e=s.current;
|
|
25
|
+
/* v8 ignore next 2 -- 同上,menu 在 open 的 commit 之后必然已挂上 */
|
|
26
|
+
if(e===null)return;let t=e.querySelector(`[data-active="true"]`);
|
|
27
|
+
/* v8 ignore next 2 -- active 已由归一 effect 保证落在可用项上 */
|
|
28
|
+
t!==null&&(t.offsetTop<e.scrollTop?e.scrollTop=t.offsetTop:t.offsetTop+t.offsetHeight>e.scrollTop+e.clientHeight&&(e.scrollTop=t.offsetTop+t.offsetHeight-e.clientHeight))},[n,i,p]);let T=e=>{if(e.key===`ArrowDown`||e.key===`ArrowUp`){if(e.preventDefault(),!n){S();return}w(e.key===`ArrowDown`?1:-1)}else if(e.key===`Home`||e.key===`End`){if(e.preventDefault(),n||S(),h.length===0)return;let t=e.key===`Home`?h.at(0):h.at(-1);
|
|
29
|
+
/* v8 ignore next 3 -- enabled 为空已在上一条返回 */
|
|
30
|
+
if(t===void 0)return;a(t.index)}else if(e.key===`Enter`||e.key===` `){if(e.preventDefault(),!n){S();return}C(i)}else(e.key===`Tab`||e.key===`Escape`)&&b()},E=[],D;for(let[n,r]of p.entries())r.group!==D&&(r.group!==void 0&&E.push((0,e.createElement)(`div`,{key:`group-${n}-${r.group}`,className:`dsu-optionGroup`,role:`presentation`},r.group)),D=r.group),E.push((0,e.createElement)(`button`,{key:`option-${r.value}`,type:`button`,role:`option`,id:`${c}-${n}`,className:`dsu-option`,tabIndex:-1,"aria-selected":r.value===t.value,"data-active":n===i,disabled:r.disabled===!0,onMouseDown:e=>{e.preventDefault()},onClick:()=>{C(n)},onMouseEnter:()=>{
|
|
31
|
+
/* v8 ignore next -- happy-dom 对 disabled 元素不派发 mouse 事件;浏览器实现各有差异,保留禁用检查 */
|
|
32
|
+
r.disabled!==!0&&a(n)}},(0,e.createElement)(`span`,null,r.label),(0,e.createElement)(`svg`,{className:`dsu-check`,width:14,height:14,viewBox:`0 0 14 14`,"aria-hidden":!0},(0,e.createElement)(`path`,{d:`M2.5 7.5l3 3 6-7`,fill:`none`,stroke:`currentColor`,strokeWidth:1.5,strokeLinecap:`round`,strokeLinejoin:`round`}))));return(0,e.createElement)(x,{...t,controlId:l},(0,e.createElement)(`div`,{className:`dsu-selectWrap`,onBlur:e=>{let t=e.relatedTarget;t instanceof Node&&e.currentTarget.contains(t)||b()}},(0,e.createElement)(`button`,{ref:o,type:`button`,id:l,className:`dsu-select dsu-input`,role:`combobox`,"aria-haspopup":`listbox`,"aria-expanded":n,"aria-controls":`${c}-list`,"aria-activedescendant":n&&v?`${c}-${i}`:void 0,"aria-describedby":u,"data-field":t.field,disabled:d===!0||p.length===0,onClick:()=>{n?b():S()},onKeyDown:T},(0,e.createElement)(`span`,{className:`dsu-selectValue`},g),(0,e.createElement)(`svg`,{className:`dsu-chevron`,width:14,height:14,viewBox:`0 0 14 14`,"aria-hidden":!0},(0,e.createElement)(`path`,{d:`M3 5l4 4 4-4`,fill:`none`,stroke:`currentColor`,strokeWidth:1.5,strokeLinecap:`round`,strokeLinejoin:`round`}))),(0,e.createElement)(`div`,{ref:s,id:`${c}-list`,role:`listbox`,className:`dsu-menu`,"aria-label":t.label,hidden:!n},...E)))}function T(t){let n=!t.writable||t.busy||!t.dirty,r;return r=t.error===null?t.writable?t.dirty?t.dirtyLabel:t.cleanLabel:t.readOnlyLabel:t.error,(0,e.createElement)(`div`,{className:`dsu-savebar`,"data-dirty":t.dirty},(0,e.createElement)(`button`,{type:`button`,className:`dsu-btn dsu-btnPrimary`,"data-field":`save`,disabled:n,onClick:t.onSave},t.busy?t.savingLabel:t.saveLabel),(0,e.createElement)(`button`,{type:`button`,className:`dsu-btn`,"data-field":`discard`,disabled:n,onClick:t.onDiscard},t.revertLabel),(0,e.createElement)(`span`,{className:t.error===null?`dsu-status`:`dsu-status dsu-statusError`},r))}const E={status:`loading`,writable:!1};function D(){return E}function ee(){return()=>void 0}function O(e){return typeof e==`string`?e:typeof e==`number`||typeof e==`boolean`?String(e):``}function te(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 O(a);let o=t?.[e.key];return o===void 0?String(e.fallback):O(o)}const ne=t.z.enum([`true`,`false`]),re=t.z.string().regex(/^[1-9]\d*$/u).transform(Number);function k(e,n){if(e.kind===`boolean`){let e=ne.safeParse(n);return e.success?{kind:`value`,value:e.data===`true`}:{kind:`invalid`}}let r=n.trim();if(r===``)return{kind:`clear`};if(e.kind===`number`){let e=re.safeParse(r);return e.success?{kind:`value`,value:e.data}:{kind:`invalid`}}if(e.kind===`enum`){let n=t.z.string().refine(t=>(e.options??[]).includes(t),{error:`取值不在字段选项内`}).safeParse(r);return n.success?{kind:`value`,value:n.data}:{kind:`invalid`}}if(e.format===`url`){let e=t.z.url().safeParse(r);return e.success?{kind:`value`,value:e.data}:{kind:`invalid`}}return{kind:`value`,value:r}}function ie(e){return s.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}})}const A=`dsu-btn`,j=`dsu-hint`;function ae(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 oe(){let e=Reflect.get(globalThis,`document`);return ae(e)?e:void 0}function M(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 se(e){return M(e,`dsh-scrapling-settings-css`,`
|
|
33
|
+
.dss-secret{display:flex;gap:8px;align-items:center;width:100%}
|
|
34
|
+
.dss-reveal{flex:none;white-space:nowrap}
|
|
37
35
|
.dss-packs{display:flex;flex-direction:column;gap:8px}
|
|
38
36
|
.dss-pack{display:grid;grid-template-columns:minmax(0,1fr) auto;gap:4px 12px;align-items:center}
|
|
39
|
-
.dss-packState{margin:0;color:var(--dsw-alias-label-tertiary);font-size:12px}
|
|
40
37
|
.dss-packActions{display:flex;gap:6px;grid-column:2;justify-content:flex-end}
|
|
41
|
-
.dss-command{display:block;border:.5px solid var(--dsw-alias-border-l3);border-radius:var(--dsw-radius-
|
|
42
|
-
.dss-job{margin:0;max-height:180px;overflow:auto;border:.5px solid var(--dsw-alias-border-l3);border-radius:var(--dsw-radius-
|
|
43
|
-
|
|
44
|
-
`)}function k(e,t){return e.secret===!0&&!t?`password`:`text`}function ee(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:k(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 te(t){let{field:n,t:r,shown:i,disabled:a,revealed:o,onReveal:s,onChange:c}=t,l=r(`field.${n.key}.label`),u=ee({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 A(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=>te({field:e,t:r,shown:i(e),disabled:a,revealed:o(e),onReveal:()=>{s(e)},onChange:t=>{c(e,t)}}))))}function j(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 M={values:{},baseRevision:void 0,invalid:[],invalidText:{}};function N(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:C,"data-primary":`true`,disabled:l||a||r||!i,onClick:s},n(r?`saving`:`save`)),(0,e.createElement)(`button`,{type:`button`,className:C,disabled:l||a||r,onClick:c},n(`undo`)))}function P(t){let[n,r]=(0,e.useState)(null),[i,a]=(0,e.useState)(``),[o,s]=(0,e.useState)(``),c=(0,e.useCallback)(async()=>{if(t!==void 0)try{r(await t.status()),s(``)}catch(e){s(String(e))}},[t]),l=n?.job?.status===`running`||n?.job?.status===`stopping`;return(0,e.useEffect)(()=>{t!==void 0&&c()},[t,c]),(0,e.useEffect)(()=>{let e;return t!==void 0&&l&&(e=setInterval(()=>{c()},2e3)),()=>{e!==void 0&&clearInterval(e)}},[t,l,c]),{snapshot:n,busy:i,failure:o,act:(0,e.useCallback)((e,n)=>{t!==void 0&&(a(e),s(``),(async()=>{try{let r=n===`repair`?await t.repair(e):await t.install(e);r.ok?await c():s(r.error)}catch(e){s(String(e))}finally{a(``)}})())},[t,c]),cancel:(0,e.useCallback)(()=>{let e=n?.job;t!==void 0&&e!=null&&(a(`cancel`),s(``),(async()=>{try{let n=await t.cancel(e.id);n.ok?await c():s(n.error)}catch(e){s(String(e))}finally{a(``)}})())},[t,c,n])}}function F(t){let{pack:n,state:r,t:i,disabled:a,running:o,activePack:s,onAct:c,onCancel:l}=t,u=i(r===null?`statusLoading`:m(r)),d=i(h(n)),f=a||r===null||r===`blocked`||r===`installing`,p=[(0,e.createElement)(`button`,{type:`button`,className:C,key:`install`,disabled:f||r===`ready`,onClick:()=>{c(n,`install`)}},i(`runtimeInstall`)),(0,e.createElement)(`button`,{type:`button`,className:C,key:`repair`,disabled:f||r===`missing`,onClick:()=>{c(n,`repair`)}},i(`runtimeRepair`))];return o&&s===n&&p.push((0,e.createElement)(`button`,{type:`button`,className:C,key:`cancel`,disabled:a,onClick:l},i(`runtimeCancel`))),(0,e.createElement)(`div`,{className:`dss-pack`,key:n},(0,e.createElement)(`div`,null,(0,e.createElement)(`div`,{className:`dss-label`},d),(0,e.createElement)(`p`,{className:`dss-packState`},u)),(0,e.createElement)(`div`,{className:`dss-packActions`},...p))}function ne(t){let{reader:n,t:r,snapshot:i,busy:a,failure:o,onAct:s,onCancel:c}=t,l=(0,e.createElement)(`h3`,{className:`dss-groupTitle`},r(`runtimeTitle`)),u=(0,e.createElement)(`p`,{className:`dss-note`},r(`runtimeHint`)),f=(0,e.createElement)(`code`,{className:`dss-command`},`dsh-scrapling setup --feature <pack> --apply`),p=o===``?null:(0,e.createElement)(`p`,{className:w,"data-error":`true`,role:`alert`},r(`runtimeError`,{reason:o}));if(n===void 0)return(0,e.createElement)(`section`,{className:`dss-runtime`},l,u,(0,e.createElement)(`p`,{className:w},r(`runtimeUnavailable`)),f);let m=i?.jobsReady??!1,g=i?.job??null,_=g!==null&&(g.status===`running`||g.status===`stopping`),v=i===null?null:(0,e.createElement)(`p`,{className:`dss-runtimeInfo`},`${r(`runtimePython`)}: ${i.python.path} (${i.python.via})`,(0,e.createElement)(`br`),`${r(`runtimeDataDir`)}: ${i.dataDir}`),y=g===null?``:r(h(g.pack)),b=g===null?null:(0,e.createElement)(`p`,{className:w},_?r(`runtimeJobRunning`,{pack:y}):r(`runtimeJobEnded`,{status:g.status})),x=g===null||g.output===``?null:(0,e.createElement)(`pre`,{className:`dss-job`},g.output),S=a!==``||!m||i===null,C=d.map(e=>F({pack:e,state:i?.packs[e]??null,t:r,disabled:S,running:_,activePack:g?.pack??null,onAct:s,onCancel:c})),T=i!==null&&!m?(0,e.createElement)(`div`,null,(0,e.createElement)(`p`,{className:w},r(`runtimeJobsMissing`)),f):null;return(0,e.createElement)(`section`,{className:`dss-runtime`},l,u,v,p,b,x,(0,e.createElement)(`div`,{className:`dss-packs`},...C),T)}async function re(e){let{form:t,draft:n,ops:r,state:i,t:a,setDraft:o,setFailure:s,setSaving:c}=e;c(!0),s(``);try{await t.mutate(r,n.baseRevision)?o(e=>{let t={...e.values};for(let e of r){let[n]=e.path;Reflect.deleteProperty(t,n)}return Object.keys(t).length===0?M:{...e,values:t}}):s(n.baseRevision!==void 0&&n.baseRevision!==i.revision?a(`stale`):a(`rejected`))}catch(e){s(a(`failed`,{reason:String(e)}))}finally{c(!1)}}function ie(t){let{form:n,t:r}=t,[i,o]=(0,e.useState)(M),[s,c]=(0,e.useState)(``),[l,u]=(0,e.useState)(!1),[d,f]=(0,e.useState)([]),p=(0,e.useSyncExternalStore)(n===void 0?v:n.subscribe,n===void 0?_:n.getSnapshot),m=P(t.runtime);if(t.view!==`page`||n===void 0)return(0,e.createElement)(`div`,{className:`dss-card`});let h=p.writable&&p.status===`ready`,g=S(i.values),y=async()=>{await re({form:n,draft:i,ops:g,state:p,t:r,setDraft:o,setFailure:c,setSaving:u})},C=(e,t)=>{c(``);let n=x(e,t);o(r=>{let i={...r.values},a={...r.invalidText},o=r.invalid.filter(t=>t!==e.key),s=r.baseRevision??p.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})})},T=a.map(e=>A({group:e,t:r,shown:e=>b(e,p.value,i.values,i.invalidText),disabled:!h||l,revealed:e=>d.includes(e.key),onReveal:e=>{f(t=>t.includes(e.key)?t.filter(t=>t!==e.key):[...t,e.key])},onChange:C})),E=N({t:r,saving:l,editable:h,blocked:i.invalid.length>0,changed:g.length,onSave:()=>{y()},onUndo:()=>{o(M),c(``)}}),D=(0,e.createElement)(`p`,{className:w,"data-error":`false`,role:`status`,"aria-live":`polite`},j(r,p,g.length,i.invalid.length)),O=s===``?null:(0,e.createElement)(`p`,{className:w,"data-error":`true`,role:`alert`,"aria-live":`assertive`},s);return(0,e.createElement)(`div`,{className:`dss-card`},D,O,...T,ne({reader:t.runtime,t:r,snapshot:m.snapshot,busy:m.busy,failure:m.failure,onAct:m.act,onCancel:m.cancel}),E)}const I=`@jayyuen66/dsh-scrapling`;function L(e,t){return e[t]}const R=`scraplingRuntime`,z=`remote.${R}`,B={mode:`strict`,typeSymbol:`${I}#runtime-pack-request`,create:()=>({parse(e){let t=i(e)?L(e,`pack`):void 0;if(!p(t))throw TypeError(`runtime request requires a known pack`);return{pack:t}}})},V=[{id:`${I}#${R}/status`,service:R,namespace:R,method:`status`,invocation:{kind:`direct`},parameters:[],result:{mode:`src-json`}},{id:`${I}#${R}/installPack`,service:R,namespace:R,method:`installPack`,invocation:{kind:`direct`},parameters:[{name:`request`,wire:`request`,source:`json`,codec:B}],result:{mode:`src-json`}},{id:`${I}#${R}/repairPack`,service:R,namespace:R,method:`repairPack`,invocation:{kind:`direct`},parameters:[{name:`request`,wire:`request`,source:`json`,codec:B}],result:{mode:`src-json`}},{id:`${I}#${R}/cancelJob`,service:R,namespace:R,method:`cancelJob`,invocation:{kind:`direct`},parameters:[{name:`request`,wire:`request`,source:`json`,codec:{mode:`strict`,typeSymbol:`${I}#runtime-cancel-request`,create:()=>({parse(e){let t=i(e)?L(e,`jobId`):void 0;if(typeof t!=`string`||t.length===0)throw TypeError(`runtime cancel requires a jobId`);return{jobId:t}}})}}],result:{mode:`src-json`}}];function H(e){return i(e)&&typeof L(e,`$mount`)==`function`}function U(e){return i(e)?typeof L(e,`status`)==`function`&&typeof L(e,`installPack`)==`function`&&typeof L(e,`repairPack`)==`function`&&typeof L(e,`cancelJob`)==`function`:!1}async function W(e){let t=await e;if(t.ok)return t.value;throw Error(`${t.error.code}: ${t.error.message}`)}function G(e){let t,n=async()=>{let n=e.get?.(`remote`);if(!H(n))throw Error(`运行环境读面不可用:宿主网关没有提供 remote 服务`);try{t??=n.$mount({package:I,descriptors:V}),await t}catch(e){throw t=void 0,e}let r=e.get?.(z,!1);if(!U(r))throw Error(`${z} 未提供:宿主网关没有挂上这枚命名空间`);return r};return{async status(){return W((await n()).status())},async install(e){return W((await n()).installPack({pack:e}))},async repair(e){return W((await n()).repairPack({pack:e}))},async cancel(e){return W((await n()).cancelJob({jobId:e}))}}}function K(e){return typeof e.get==`function`?G(e):void 0}const q=`row.session`,J=[`scrapling_fetch`,`scrapling_extract`,`scrapling_locate`,`scrapling_links`,`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`,`scrapling_session_read`,`scrapling_session_act`,`scrapling_download`,`scrapling_screenshot`];function Y(e){return typeof e==`string`?e:typeof e==`number`||typeof e==`boolean`?String(e):``}function ae(...e){for(let t of e){let e=Y(t);if(e!==``)return e}return``}function oe(e,t,n){let r=Y(t.selector);return{tool:e,title:r===``?e:`${e} ${r}`,fields:[{labelKey:`row.matched`,value:Y(n.count)}]}}function se(e,t,n){let r=[],i=Y(t.baseUrl);return i!==``&&r.push({labelKey:`row.url`,value:i}),r.push({labelKey:`row.matched`,value:Y(n.count)}),{tool:e,title:e,fields:r}}function X(e,t,n){let r=i(t)?t:{},a=i(n)?n:{},o=ae(a.url,r.url);if(e===`scrapling_extract`||e===`scrapling_locate`)return oe(e,r,a);if(e===`scrapling_links`)return se(e,r,a);if(e===`scrapling_session_list`)return{tool:e,title:e,fields:[{labelKey:`row.sessionCount`,value:Y(a.count)}]};if(e===`scrapling_session_open`)return{tool:e,title:e,fields:[{labelKey:`row.type`,value:Y(r.sessionType)},{labelKey:q,value:Y(a.sessionId)}]};if(e===`scrapling_session_close`)return{tool:e,title:e,fields:[{labelKey:q,value:Y(r.sessionId)}]};if(e===`scrapling_session_network`||e===`scrapling_session_state_save`||e===`scrapling_session_state_load`){let t=[{labelKey:q,value:Y(r.sessionId)}],n=Y(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:Y(r.maxPages)},{labelKey:`row.job`,value:Y(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 ce=[`url`,`baseUrl`,`selector`,`sessionType`,`sessionId`,`name`,`maxPages`];function Z(e){if(e===void 0)return{};let t={};for(let n of ce){let r=e.text(n)??e.value(n);r!==void 0&&(t[n]=r)}return t}function Q(e){return e.phase===`result`?e.block.meta:void 0}function le(t){let{toolName:n,block:r,inspect:i,t:a}=t,o=Q(t),s=X(n,Z(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 $=[`slots`,`configForms`,`locale`];function ue(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)(le,{...t,t:n})));return()=>{for(let e of r)e()}}function de(t){r(t,`__dshScraplingToolviewApplied`,`dsh-scrapling toolview`)&&(t.effect(()=>{let e=E();if(e===void 0)return()=>void 0;let t=O(e),n=D(e,`dsh-scrapling-row-css`,`
|
|
38
|
+
.dss-command{display:block;border:.5px solid var(--dsw-alias-border-l3);border-radius:var(--dsw-radius-md);background:var(--dsw-alias-bg-layer-3);padding:6px 8px;font-family:ui-monospace,SFMono-Regular,Menlo,monospace;font-size:12px;word-break:break-all}
|
|
39
|
+
.dss-job{margin:0;max-height:180px;overflow:auto;border:.5px solid var(--dsw-alias-border-l3);border-radius:var(--dsw-radius-md);background:var(--dsw-alias-bg-layer-3);padding:6px 8px;font-family:ui-monospace,SFMono-Regular,Menlo,monospace;font-size:12px;white-space:pre-wrap}
|
|
40
|
+
|
|
41
|
+
|
|
42
|
+
.dsu-form{display:flex;flex-direction:column}
|
|
43
|
+
.dsu-section{margin-top:24px;padding-top:24px;border-top:.5px solid var(--dsw-alias-border-l1)}
|
|
44
|
+
.dsu-form>.dsu-section:first-child{margin-top:0;padding-top:0;border-top:0}
|
|
45
|
+
.dsu-sectionTitle{margin:0;font-size:15px;font-weight:600;line-height:1.4;color:var(--dsw-alias-label-primary)}
|
|
46
|
+
.dsu-sectionHint{margin:4px 0 0;font-size:12px;line-height:1.5;color:var(--dsw-alias-label-tertiary)}
|
|
47
|
+
.dsu-statusbar{display:flex;flex-wrap:wrap;gap:4px 8px;margin-top:8px;font-size:12px;line-height:1.5;color:var(--dsw-alias-label-tertiary)}
|
|
48
|
+
.dsu-field{display:grid;grid-template-columns:minmax(0,1fr) minmax(240px,360px);column-gap:32px;align-items:center;padding:12px 0;border-top:.5px solid var(--dsw-alias-border-l2)}
|
|
49
|
+
.dsu-fieldMeta{display:flex;flex-direction:column;gap:4px;min-width:0}
|
|
50
|
+
.dsu-labelRow{display:flex;align-items:center;gap:6px;min-width:0}
|
|
51
|
+
.dsu-label{font-size:13px;font-weight:500;line-height:1.5;color:var(--dsw-alias-label-primary)}
|
|
52
|
+
.dsu-labelMono{font-family:ui-monospace,SFMono-Regular,Menlo,Consolas,monospace;font-size:12px}
|
|
53
|
+
.dsu-hint{margin:0;font-size:12px;line-height:1.5;color:var(--dsw-alias-label-tertiary)}
|
|
54
|
+
.dsu-control{min-width:0;display:flex;align-items:center;gap:8px}
|
|
55
|
+
.dsu-fieldWide{grid-template-columns:minmax(0,1fr);align-items:start}
|
|
56
|
+
.dsu-fieldWide .dsu-control{width:100%;max-width:720px;margin-top:2px}
|
|
57
|
+
.dsu-help{display:inline-flex;align-items:center;gap:6px;min-width:0}
|
|
58
|
+
.dsu-helpBtn{appearance:none;border:0;background:transparent;padding:0;width:16px;height:16px;display:inline-flex;align-items:center;justify-content:center;color:var(--dsw-alias-label-tertiary);cursor:help;border-radius:50%;flex:none}
|
|
59
|
+
.dsu-help:hover .dsu-helpBtn,.dsu-helpBtn:focus-visible{color:var(--dsw-alias-label-primary)}
|
|
60
|
+
.dsu-helpBtn:focus-visible{outline:2px solid var(--dsw-alias-state-business-primary);outline-offset:1px}
|
|
61
|
+
.dsu-tip{position:fixed;z-index:60;box-sizing:border-box;max-width:min(340px,calc(100vw - 16px));max-height:calc(100vh - 16px);overflow:auto;overflow-wrap:anywhere;padding:10px 12px;border-radius:10px;background:var(--dsw-alias-bg-layer-2);border:.5px solid var(--dsw-alias-border-l3);box-shadow:0 12px 32px rgb(0 0 0 / 45%);font-size:12px;line-height:1.6;font-weight:400;color:var(--dsw-alias-label-secondary)}
|
|
62
|
+
.dsu-input{width:100%;height:34px;padding:0 12px;border:.5px solid var(--dsw-alias-border-l4);border-radius:var(--dsw-radius-md);background:var(--dsw-alias-bg-layer-3);color:var(--dsw-alias-label-primary);font:inherit;font-size:13px}
|
|
63
|
+
.dsu-input:focus-visible{outline:none;border-color:var(--dsw-alias-state-business-primary)}
|
|
64
|
+
.dsu-input[aria-invalid="true"]{border-color:var(--dsw-alias-state-error-primary)}
|
|
65
|
+
.dsu-input:disabled{color:var(--dsw-alias-label-tertiary);cursor:default}
|
|
66
|
+
.dsu-input::placeholder{color:var(--dsw-alias-label-tertiary)}
|
|
67
|
+
.dsu-textarea{height:auto;min-height:96px;padding:8px 12px;line-height:1.6;resize:vertical}
|
|
68
|
+
.dsu-mono{font-family:ui-monospace,SFMono-Regular,Menlo,Consolas,monospace}
|
|
69
|
+
.dsu-numberWrap{display:flex;flex-direction:column;gap:4px;width:100%;min-width:0}
|
|
70
|
+
.dsu-number{display:flex;align-items:center;gap:8px;min-width:0}
|
|
71
|
+
.dsu-number .dsu-input{min-width:0}
|
|
72
|
+
.dsu-unit{flex:none;font-size:12px;color:var(--dsw-alias-label-tertiary)}
|
|
73
|
+
.dsu-error{margin:0;font-size:12px;line-height:1.5;color:var(--dsw-alias-state-error-primary)}
|
|
74
|
+
.dsu-switch{appearance:none;width:36px;height:20px;border-radius:999px;border:0;padding:2px;background:var(--dsw-alias-border-l3);display:flex;align-items:center;cursor:pointer;flex:none;transition:background-color .16s}
|
|
75
|
+
.dsu-knob{width:16px;height:16px;border-radius:50%;background:var(--dsw-alias-label-primary);transition:transform .16s,background-color .16s}
|
|
76
|
+
.dsu-switch[aria-checked="true"]{background:var(--dsw-alias-label-primary)}
|
|
77
|
+
.dsu-switch[aria-checked="true"] .dsu-knob{transform:translateX(16px);background:var(--dsw-alias-label-primary-foreground)}
|
|
78
|
+
.dsu-switch:disabled{opacity:.4;cursor:not-allowed}
|
|
79
|
+
.dsu-switch:focus-visible{outline:2px solid var(--dsw-alias-state-business-primary);outline-offset:2px}
|
|
80
|
+
.dsu-selectWrap{position:relative;width:100%;min-width:0}
|
|
81
|
+
.dsu-select{display:flex;align-items:center;justify-content:space-between;gap:8px;text-align:left;cursor:pointer}
|
|
82
|
+
.dsu-select[aria-expanded="true"]{border-color:var(--dsw-alias-state-business-primary)}
|
|
83
|
+
.dsu-selectValue{overflow:hidden;text-overflow:ellipsis;white-space:nowrap}
|
|
84
|
+
.dsu-chevron{flex:none;color:var(--dsw-alias-label-tertiary);transition:transform .16s}
|
|
85
|
+
.dsu-select[aria-expanded="true"] .dsu-chevron{transform:rotate(180deg)}
|
|
86
|
+
.dsu-menu{position:fixed;z-index:70;padding:4px;background:var(--dsw-alias-bg-layer-2);border:.5px solid var(--dsw-alias-border-l3);border-radius:12px;box-shadow:0 12px 32px rgb(0 0 0 / 50%);max-height:280px;overflow:auto}
|
|
87
|
+
.dsu-option{appearance:none;border:0;background:transparent;color:var(--dsw-alias-label-primary);font:inherit;font-size:13px;line-height:1.4;width:100%;display:flex;align-items:center;justify-content:space-between;gap:12px;padding:8px 10px;border-radius:8px;cursor:pointer;text-align:left}
|
|
88
|
+
.dsu-option:hover,.dsu-option[data-active="true"]{background:var(--dsw-alias-bg-layer-3)}
|
|
89
|
+
.dsu-option:disabled{color:var(--dsw-alias-label-tertiary);cursor:not-allowed}
|
|
90
|
+
.dsu-option:focus-visible{outline:2px solid var(--dsw-alias-state-business-primary);outline-offset:-2px}
|
|
91
|
+
.dsu-optionGroup{padding:6px 10px 2px;font-size:11px;font-weight:600;color:var(--dsw-alias-label-tertiary)}
|
|
92
|
+
.dsu-check{opacity:0;flex:none}
|
|
93
|
+
.dsu-option[aria-selected="true"] .dsu-check{opacity:1}
|
|
94
|
+
.dsu-savebar{display:flex;align-items:center;gap:8px;padding:12px 0;margin-top:24px;border-top:.5px solid var(--dsw-alias-border-l2);background:var(--dsw-alias-bg-base)}
|
|
95
|
+
.dsu-savebar[data-dirty="true"]{position:sticky;bottom:0;z-index:2;box-shadow:0 -12px 24px rgb(0 0 0 / 35%)}
|
|
96
|
+
.dsu-btn{appearance:none;border:.5px solid var(--dsw-alias-border-l2);background:transparent;color:var(--dsw-alias-label-primary);font:inherit;font-size:13px;line-height:1.5;border-radius:var(--dsw-radius-md);padding:5px 14px;cursor:pointer;transition:background-color .12s,border-color .12s,color .12s,filter .12s}
|
|
97
|
+
.dsu-btn:hover:not(:disabled){background:var(--dsw-alias-bg-layer-2);border-color:var(--dsw-alias-border-l3)}
|
|
98
|
+
.dsu-btn:active:not(:disabled){background:var(--dsw-alias-bg-layer-1)}
|
|
99
|
+
.dsu-btn:focus-visible{outline:2px solid var(--dsw-alias-state-business-primary);outline-offset:1px}
|
|
100
|
+
.dsu-btn:disabled{opacity:.4;cursor:not-allowed}
|
|
101
|
+
.dsu-btnPrimary{background:var(--dsw-alias-label-primary);border-color:var(--dsw-alias-label-primary);color:var(--dsw-alias-bg-layer-3)}
|
|
102
|
+
.dsu-btnPrimary:hover:not(:disabled){background:var(--dsw-alias-label-primary);border-color:var(--dsw-alias-label-primary);filter:brightness(.9)}
|
|
103
|
+
.dsu-btnPrimary:active:not(:disabled){background:var(--dsw-alias-label-primary);border-color:var(--dsw-alias-label-primary);filter:brightness(.84)}
|
|
104
|
+
.dsu-btnDanger{color:var(--dsw-alias-state-error-primary)}
|
|
105
|
+
.dsu-btnDanger:hover:not(:disabled){color:var(--dsw-alias-state-error-primary);border-color:var(--dsw-alias-state-error-primary);background:var(--dsw-alias-bg-layer-2)}
|
|
106
|
+
.dsu-status{margin-left:auto;font-size:12px;color:var(--dsw-alias-label-tertiary)}
|
|
107
|
+
.dsu-statusError{color:var(--dsw-alias-state-error-primary)}
|
|
108
|
+
.dsu-grid{display:grid;grid-template-columns:repeat(auto-fit,minmax(min(200px,100%),1fr));gap:0 24px}
|
|
109
|
+
.dsu-grid>.dsu-field{display:flex;flex-direction:column;align-items:stretch;gap:6px;padding:10px 0;border-top:.5px solid var(--dsw-alias-border-l1)}
|
|
110
|
+
.dsu-grid>.dsu-field .dsu-control{width:100%}
|
|
111
|
+
@media (max-width:640px){
|
|
112
|
+
.dsu-field{grid-template-columns:minmax(0,1fr);align-items:start}
|
|
113
|
+
.dsu-control{width:100%;max-width:720px}
|
|
114
|
+
.dsu-section{margin-top:20px;padding-top:20px}
|
|
115
|
+
}
|
|
116
|
+
@media (prefers-reduced-motion:reduce){
|
|
117
|
+
.dsu-switch,.dsu-knob,.dsu-chevron,.dsu-btn{transition:none}
|
|
118
|
+
}
|
|
119
|
+
`)}function ce(e,t){return e.secret===!0&&!t?`password`:`text`}function le(t){let{field:n,label:r,shown:i,disabled:a,revealed:o,onReveal:s,t:c,onChange:l}=t,u=(0,e.createElement)(`input`,{type:ce(n,o),autoComplete:`off`,spellCheck:!1,className:`dsu-input`,value:i,disabled:a,"data-field":n.key,"aria-label":r,onChange:e=>{l(e.target.value)}}),d=(0,e.createElement)(`button`,{type:`button`,className:`dsu-btn dss-reveal`,disabled:a,"aria-pressed":o,"aria-label":r,onClick:()=>{s()}},c(o?`conceal`:`reveal`));return(0,e.createElement)(`div`,{className:`dss-secret`},u,d)}function ue(t){let{field:n,label:r,shown:i,disabled:a,onChange:o}=t;return(0,e.createElement)(`input`,{type:`text`,inputMode:`numeric`,className:`dsu-input`,value:i,disabled:a,"data-field":n.key,"aria-label":r,onChange:e=>{o(e.target.value)}})}function de(t){let{field:n,t:r,shown:i,disabled:a,revealed:o,onReveal:s,onChange:c}=t,l=r(`field.${n.key}.label`),u={label:l,...h(r(`field.${n.key}.hint`)),field:n.key,disabled:a};return n.kind===`boolean`?(0,e.createElement)(S,{...u,checked:i===`true`,onChange:e=>{c(String(e))}}):n.kind===`enum`?(0,e.createElement)(w,{...u,value:i,options:(n.options??[]).map(e=>({value:e,label:e})),onChange:c}):n.secret===!0?(0,e.createElement)(x,u,le({field:n,label:l,shown:i,disabled:a,revealed:o,onReveal:s,t:r,onChange:c})):n.kind===`number`?(0,e.createElement)(x,u,ue({field:n,label:l,shown:i,disabled:a,onChange:c})):(0,e.createElement)(C,{...u,value:i,onChange:c})}function fe(t){let{group:n,t:r,shown:i,disabled:a,revealed:o,onReveal:s,onChange:c}=t;return(0,e.createElement)(_,{title:r(`group.${n.id}.title`),hint:r(`group.${n.id}.note`)},n.fields.map(e=>de({field:e,t:r,shown:i(e),disabled:a,revealed:o(e),onReveal:()=>{s(e)},onChange:t=>{c(e,t)}})))}function pe(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 N={values:{},baseRevision:void 0,invalid:[],invalidText:{}};function me(t){let{t:n,saving:r,editable:i,changed:a,invalid:o,onSave:s,onUndo:c}=t;return(0,e.createElement)(T,{dirty:a>0&&o===0,busy:r,writable:i,error:o>0?n(`statusInvalid`,{count:o}):null,saveLabel:n(`save`),savingLabel:n(`saving`),revertLabel:n(`undo`),dirtyLabel:n(`statusChanged`,{count:a}),cleanLabel:n(`statusClean`),readOnlyLabel:n(`statusReadonly`),onSave:s,onDiscard:c})}function he(t){let[n,r]=(0,e.useState)(null),[i,a]=(0,e.useState)(``),[o,s]=(0,e.useState)(``),c=(0,e.useCallback)(async()=>{if(t!==void 0)try{r(await t.status()),s(``)}catch(e){s(String(e))}},[t]),l=n?.job?.status===`running`||n?.job?.status===`stopping`;return(0,e.useEffect)(()=>{t!==void 0&&c()},[t,c]),(0,e.useEffect)(()=>{let e;return t!==void 0&&l&&(e=setInterval(()=>{c()},2e3)),()=>{e!==void 0&&clearInterval(e)}},[t,l,c]),{snapshot:n,busy:i,failure:o,act:(0,e.useCallback)((e,n)=>{t!==void 0&&(a(e),s(``),(async()=>{try{let r=n===`repair`?await t.repair(e):await t.install(e);r.ok?await c():s(r.error)}catch(e){s(String(e))}finally{a(``)}})())},[t,c]),cancel:(0,e.useCallback)(()=>{let e=n?.job;t!==void 0&&e!=null&&(a(`cancel`),s(``),(async()=>{try{let n=await t.cancel(e.id);n.ok?await c():s(n.error)}catch(e){s(String(e))}finally{a(``)}})())},[t,c,n])}}function ge(t){let{pack:n,state:r,t:i,disabled:a,running:o,activePack:s,onAct:c,onCancel:l}=t,u=i(r===null?`statusLoading`:p(r)),d=i(m(n)),f=a||r===null||r===`blocked`||r===`installing`,h=[(0,e.createElement)(`button`,{type:`button`,className:A,key:`install`,disabled:f||r===`ready`,onClick:()=>{c(n,`install`)}},i(`runtimeInstall`)),(0,e.createElement)(`button`,{type:`button`,className:A,key:`repair`,disabled:f||r===`missing`,onClick:()=>{c(n,`repair`)}},i(`runtimeRepair`))];return o&&s===n&&h.push((0,e.createElement)(`button`,{type:`button`,className:A,key:`cancel`,disabled:a,onClick:l},i(`runtimeCancel`))),(0,e.createElement)(`div`,{className:`dss-pack`,key:n},(0,e.createElement)(`div`,null,(0,e.createElement)(`div`,{className:`dsu-label`},d),(0,e.createElement)(`p`,{className:j},u)),(0,e.createElement)(`div`,{className:`dss-packActions`},...h))}function _e(t){let{reader:n,t:r,snapshot:i,busy:a,failure:o,onAct:s,onCancel:c}=t,l=(0,e.createElement)(`code`,{className:`dss-command`},`dsh-scrapling setup --feature <pack> --apply`),u=o===``?null:(0,e.createElement)(`p`,{className:`${j} dsu-error`,role:`alert`},r(`runtimeError`,{reason:o}));if(n===void 0)return(0,e.createElement)(_,{title:r(`runtimeTitle`),hint:r(`runtimeHint`)},(0,e.createElement)(`p`,{className:j},r(`runtimeUnavailable`)),l);let d=i?.jobsReady??!1,p=i?.job??null,h=p!==null&&(p.status===`running`||p.status===`stopping`),g=i===null?null:(0,e.createElement)(`p`,{className:j},`${r(`runtimePython`)}: ${i.python.path} (${i.python.via})`,(0,e.createElement)(`br`),`${r(`runtimeDataDir`)}: ${i.dataDir}`),v=p===null?``:r(m(p.pack)),y=p===null?null:(0,e.createElement)(`p`,{className:j},h?r(`runtimeJobRunning`,{pack:v}):r(`runtimeJobEnded`,{status:p.status})),b=p===null||p.output===``?null:(0,e.createElement)(`pre`,{className:`dss-job`},p.output),x=a!==``||!d||i===null,S=f.map(e=>ge({pack:e,state:i?.packs[e]??null,t:r,disabled:x,running:h,activePack:p?.pack??null,onAct:s,onCancel:c})),C=i!==null&&!d?(0,e.createElement)(`div`,null,(0,e.createElement)(`p`,{className:j},r(`runtimeJobsMissing`)),l):null;return(0,e.createElement)(_,{title:r(`runtimeTitle`),hint:r(`runtimeHint`)},g,u,y,b,(0,e.createElement)(`div`,{className:`dss-packs`},...S),C)}async function P(e){let{form:t,draft:n,ops:r,state:i,t:a,setDraft:o,setFailure:s,setSaving:c}=e;c(!0),s(``);try{await t.mutate(r,n.baseRevision)?o(e=>{let t={...e.values};for(let e of r){let[n]=e.path;Reflect.deleteProperty(t,n)}return Object.keys(t).length===0?N:{...e,values:t}}):s(n.baseRevision!==void 0&&n.baseRevision!==i.revision?a(`stale`):a(`rejected`))}catch(e){s(a(`failed`,{reason:String(e)}))}finally{c(!1)}}function F(t){let{form:n,t:r}=t,[i,a]=(0,e.useState)(N),[s,c]=(0,e.useState)(``),[l,u]=(0,e.useState)(!1),[d,f]=(0,e.useState)([]),p=(0,e.useSyncExternalStore)(n===void 0?ee:n.subscribe,n===void 0?D:n.getSnapshot),m=he(t.runtime);if(t.view!==`page`||n===void 0)return(0,e.createElement)(g,null);let h=p.writable&&p.status===`ready`,_=ie(i.values),y=async()=>{i.invalid.length>0||_.length===0||await P({form:n,draft:i,ops:_,state:p,t:r,setDraft:a,setFailure:c,setSaving:u})},b=(e,t)=>{c(``);let n=k(e,t);a(r=>{let i={...r.values},a={...r.invalidText},o=r.invalid.filter(t=>t!==e.key),s=r.baseRevision??p.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})})},x=o.map(e=>fe({group:e,t:r,shown:e=>te(e,p.value,i.values,i.invalidText),disabled:!h||l,revealed:e=>d.includes(e.key),onReveal:e=>{f(t=>t.includes(e.key)?t.filter(t=>t!==e.key):[...t,e.key])},onChange:b})),S=me({t:r,saving:l,editable:h,changed:_.length,invalid:i.invalid.length,onSave:()=>{y()},onUndo:()=>{a(N),c(``)}}),C=(0,e.createElement)(v,{items:[pe(r,p,_.length,i.invalid.length)]}),w=s===``?null:(0,e.createElement)(`p`,{className:`dsu-error`,role:`alert`,"aria-live":`assertive`},s);return(0,e.createElement)(g,null,C,w,...x,_e({reader:t.runtime,t:r,snapshot:m.snapshot,busy:m.busy,failure:m.failure,onAct:m.act,onCancel:m.cancel}),S)}const I=`@jayyuen66/dsh-scrapling`;function L(e,t){return e[t]}const R=`scraplingRuntime`,z=`remote.${R}`;function B(e,n){let r=e.safeParse(n);if(!r.success)throw TypeError(t.z.prettifyError(r.error));return r.data}const V=`runtime request requires a known pack`,ve=t.z.object({pack:t.z.enum(f,{error:V})},{error:V}),H=`runtime cancel requires a jobId`,ye=t.z.object({jobId:t.z.string({error:H}).min(1,{error:H})},{error:H}),U={mode:`strict`,typeSymbol:`${I}#runtime-pack-request`,create:()=>({parse(e){return B(ve,e)}})},be={mode:`strict`,typeSymbol:`${I}#runtime-cancel-request`,create:()=>({parse(e){return B(ye,e)}})},xe=t.z.enum([`ready`,`missing`,`corrupt`,`installing`,`blocked`]),Se=t.z.enum([`running`,`stopping`,`completed`,`killed`,`failed`]),W=t.z.enum(f),Ce=t.z.object({id:t.z.string(),pack:W,status:Se,output:t.z.string()}),we=t.z.object({ok:t.z.literal(!0),packs:t.z.partialRecord(W,xe),python:t.z.object({path:t.z.string(),via:t.z.string(),version:t.z.string()}),dataDir:t.z.string(),jobsReady:t.z.boolean(),job:Ce.nullable()}),Te=t.z.literal([400,404,409,500,503]),G=t.z.discriminatedUnion(`ok`,[t.z.object({ok:t.z.literal(!0),jobId:t.z.string()}),t.z.object({ok:t.z.literal(!1),error:t.z.string(),status:Te})]),Ee=[{id:`${I}#${R}/status`,service:R,namespace:R,method:`status`,invocation:{kind:`direct`},parameters:[],result:{mode:`src-json`}},{id:`${I}#${R}/installPack`,service:R,namespace:R,method:`installPack`,invocation:{kind:`direct`},parameters:[{name:`request`,wire:`request`,source:`json`,codec:U}],result:{mode:`src-json`}},{id:`${I}#${R}/repairPack`,service:R,namespace:R,method:`repairPack`,invocation:{kind:`direct`},parameters:[{name:`request`,wire:`request`,source:`json`,codec:U}],result:{mode:`src-json`}},{id:`${I}#${R}/cancelJob`,service:R,namespace:R,method:`cancelJob`,invocation:{kind:`direct`},parameters:[{name:`request`,wire:`request`,source:`json`,codec:be}],result:{mode:`src-json`}}];function De(e){return a(e)&&typeof L(e,`$mount`)==`function`}function Oe(e){return a(e)?typeof L(e,`status`)==`function`&&typeof L(e,`installPack`)==`function`&&typeof L(e,`repairPack`)==`function`&&typeof L(e,`cancelJob`)==`function`:!1}async function K(e,t){let n=await e;if(n.ok)return B(t,n.value);throw Error(`${n.error.code}: ${n.error.message}`)}function ke(e){let t,n=async()=>{let n=e.get?.(`remote`);if(!De(n))throw Error(`运行环境读面不可用:宿主网关没有提供 remote 服务`);try{t??=n.$mount({package:I,descriptors:Ee}),await t}catch(e){throw t=void 0,e}let r=e.get?.(z,!1);if(!Oe(r))throw Error(`${z} 未提供:宿主网关没有挂上这枚命名空间`);return r};return{async status(){return K((await n()).status(),we)},async install(e){return K((await n()).installPack({pack:e}),G)},async repair(e){return K((await n()).repairPack({pack:e}),G)},async cancel(e){return K((await n()).cancelJob({jobId:e}),G)}}}function Ae(e){return typeof e.get==`function`?ke(e):void 0}const q=`row.session`,J=[`scrapling_fetch`,`scrapling_extract`,`scrapling_locate`,`scrapling_links`,`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`,`scrapling_session_read`,`scrapling_session_act`,`scrapling_download`,`scrapling_screenshot`];function Y(e){return typeof e==`string`?e:typeof e==`number`||typeof e==`boolean`?String(e):``}function X(...e){for(let t of e){let e=Y(t);if(e!==``)return e}return``}function je(e,t,n){let r=Y(t.selector);return{tool:e,title:r===``?e:`${e} ${r}`,fields:[{labelKey:`row.matched`,value:Y(n.count)}]}}function Me(e,t,n){let r=[],i=Y(t.baseUrl);return i!==``&&r.push({labelKey:`row.url`,value:i}),r.push({labelKey:`row.matched`,value:Y(n.count)}),{tool:e,title:e,fields:r}}function Z(e,t,n){let r=a(t)?t:{},i=a(n)?n:{},o=X(i.url,r.url);if(e===`scrapling_extract`||e===`scrapling_locate`)return je(e,r,i);if(e===`scrapling_links`)return Me(e,r,i);if(e===`scrapling_session_list`)return{tool:e,title:e,fields:[{labelKey:`row.sessionCount`,value:Y(i.count)}]};if(e===`scrapling_session_open`)return{tool:e,title:e,fields:[{labelKey:`row.type`,value:Y(r.sessionType)},{labelKey:q,value:Y(i.sessionId)}]};if(e===`scrapling_session_close`)return{tool:e,title:e,fields:[{labelKey:q,value:Y(r.sessionId)}]};if(e===`scrapling_session_network`||e===`scrapling_session_state_save`||e===`scrapling_session_state_load`){let t=[{labelKey:q,value:Y(r.sessionId)}],n=Y(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:Y(r.maxPages)},{labelKey:`row.job`,value:Y(i.jobId)}]};let s=[];o!==``&&s.push({labelKey:`row.url`,value:o});let c=i.statusCode;return typeof c==`number`&&s.push({labelKey:`row.http`,value:String(c)}),i.truncated===!0&&s.push({labelKey:`row.body`,value:``,valueKey:`row.truncated`}),{tool:e,title:e,fields:s}}const Ne=[`url`,`baseUrl`,`selector`,`sessionType`,`sessionId`,`name`,`maxPages`];function Q(e){if(e===void 0)return{};let t={};for(let n of Ne){let r=e.text(n)??e.value(n);r!==void 0&&(t[n]=r)}return t}function $(e){return e.phase===`result`?e.block.meta:void 0}function Pe(t){let{toolName:n,block:r,inspect:i,t:a}=t,o=$(t),s=Z(n,Q(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 Fe=[`slots`,`configForms`,`locale`];function Ie(t){let n=t.locale.bind(c),r=[];for(let i of J)r.push(t.slots.register({name:`tool.call.toolview`,key:i,locale:c},t=>(0,e.createElement)(Pe,{...t,t:n})));return()=>{for(let e of r)e()}}function Le(t){i(t,`__dshScraplingToolviewApplied`,`dsh-scrapling toolview`)&&(t.effect(()=>{let e=oe();if(e===void 0)return()=>void 0;let t=se(e),n=M(e,`dsh-scrapling-row-css`,`
|
|
45
120
|
.dsh-scrapling-row{display:flex;flex-direction:column;gap:2px;min-width:0}
|
|
46
121
|
.dsh-scrapling-rowTitle{color:var(--dsw-alias-label-primary);font-size:13px;line-height:20px;overflow:hidden;text-overflow:ellipsis;white-space:nowrap}
|
|
47
122
|
.dsh-scrapling-rowFields{display:flex;flex-wrap:wrap;gap:2px 12px;margin:0;padding:0;list-style:none}
|
|
@@ -51,7 +126,7 @@ Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});let e=require
|
|
|
51
126
|
.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}
|
|
52
127
|
.dsh-scrapling-rowButton:hover{color:var(--dsw-alias-label-primary)}
|
|
53
128
|
.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}
|
|
54
|
-
`);return()=>{t(),n()}},`dsh-scrapling: client styles`),t.effect(()=>{let e=
|
|
129
|
+
`);return()=>{t(),n()}},`dsh-scrapling: client styles`),t.effect(()=>{let e=d(),n=[t.locale.register(c,`zh`,e.zh),t.locale.register(c,`en`,e.en)],r;return t.slots.inject(`tool.call.toolview`,()=>{r=Ie(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(c),i={getSnapshot:()=>n.getSnapshot(),subscribe:e=>n.subscribe(e),mutate:(e,t)=>n.mutate(e,t)},a;return t.slots.inject(`plugins.bundle.config`,()=>{let n=Ae(t);a=t.slots.register({name:`plugins.bundle.config`,key:`@jayyuen66/dsh-scrapling`,locale:c},t=>(0,e.createElement)(F,{...t,t:r,form:i,runtime:n}))}),()=>{a?.()}},`dsh-scrapling: settings card`))}exports.ROW_TOOLS=J,exports.apply=Le,exports.buildRow=Z,exports.inject=Fe,exports.readArgs=Q,exports.resultMetaOf=$;
|
|
55
130
|
return module.exports;
|
|
56
131
|
},
|
|
57
132
|
});
|
package/docs/DETAIL.md
ADDED
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
# Scrapling web scraping
|
|
2
|
+
|
|
3
|
+
Fetches and extracts web pages — JavaScript rendering, CSS/XPath extraction with self-healing selectors, sessions with login state, a background crawler and page question-answering — all served by one resident Python process.
|
|
4
|
+
|
|
5
|
+
## What the card changes
|
|
6
|
+
|
|
7
|
+
Fifty card values grouped by purpose; most are read per call, so a change applies on the next tool call without restarting the host. `pythonBin`, `failFastOnMissingPython` and `dataDir` are applied when the plugin loads, so changing them needs a restart.
|
|
8
|
+
|
|
9
|
+
- **Runtime** — `pythonBin` (empty) chooses the interpreter: an explicit path wins, then the managed capability install, then this package's development venv, then `python3` on PATH. The plugin logs which one it picked every time. `failFastOnMissingPython` (on) refuses to load when the sidecar cannot start; an interpreter that starts but lacks Scrapling always degrades to "tools unavailable" and names the path. `dataDir` is where the sidecar's state lives.
|
|
10
|
+
- **Tool switches** — fifteen of them (fetch, extract, locate, links, render, capture XHR, network history, session, session state, crawl, answer, session read, session actions, download, screenshot). Turning one off removes that tool from the model's view, and the guidance text for it disappears too.
|
|
11
|
+
- **Extraction and output** — `extractionType` (markdown/html/text), `mainContentOnly`, and the per-tool output budgets (`fetchMaxOutputChars` and friends, default 200000) which are UTF-8 byte budgets enforced on both sides.
|
|
12
|
+
- **Browser** — `headless` (on), `networkIdle` (off), `blockAds` (on, about 3500 domains), `pierceShadow` (off), `waitSelectorState`.
|
|
13
|
+
- **Timeouts and recycling** — `fetchTimeoutMs` (120000), `sidecarHandshakeTimeoutMs` (30000), `sidecarGraceMs` (5000).
|
|
14
|
+
- **Network and safety** — `proxyUrl` (shown masked), `proxyBypass`, `allowedHosts`, `syntheticDnsRanges`, `nat64Prefixes`, plus the search backends (`searchBackend`, per-vendor API keys, `searxngEndpoint`, `searchPublicFallback` off by default).
|
|
15
|
+
- **Page question-answering** — `answerProvider`, `answerModel`, `answerMaxTokens` (2000).
|
|
16
|
+
|
|
17
|
+
## Some card switches need a second switch
|
|
18
|
+
|
|
19
|
+
`provideWebFetch` and `provideWebSearch` on the card are not enough by themselves: the deployment side must also select this plugin as the host's fetch and search provider. The same pairing applies to session actions, downloads and session state. A card switch alone will look like it does nothing.
|
|
20
|
+
|
|
21
|
+
## Thirty deployment values stay off the card
|
|
22
|
+
|
|
23
|
+
They change how the plugin is wired, not what a session decides, and each takes effect only on restart. The ones you are most likely to meet:
|
|
24
|
+
|
|
25
|
+
- `integrationMode` — `native` registers the tools with the host; `mcp` serves the same tool table over MCP instead; `official-mcp` does neither and only carries the upstream server's entry. The three are mutually exclusive and are read once at assembly, so switching means restarting.
|
|
26
|
+
- `mcpPort` (default 39217) must equal the URL in the profile's MCP-client entry; after changing it, re-run the plugin's `setup` — its `doctor` check compares the two.
|
|
27
|
+
- `officialMcpEnabled` (off) needs both this switch and the `setup` `--accept-risk` flag before any entry is generated, because the upstream server exposes actions this plugin's guard does not see.
|
|
28
|
+
- `allowWriteMethods` (off) — reading pages is this plugin's job; changing remote state is not, so that is a deployment statement.
|
|
29
|
+
- Also here: browser binary and CDP endpoint, real-Chrome and DNS-over-HTTPS options, Redis URL and adaptive storage, the crawler's runtime/robots/delay/concurrency/strategy/checkpoint settings, and the search endpoints.
|
|
30
|
+
|
|
31
|
+
Write them in the `config:` block of this plugin's row in `cordis.patch.yml`.
|
|
32
|
+
|
|
33
|
+
## What it needs from outside
|
|
34
|
+
|
|
35
|
+
Python and the Scrapling library are yours to provide: the plugin never installs them into your system interpreter. Chromium comes from `python -m patchright install chromium`. Capability packs are installed as host jobs in layers — `core`, `browser`, `search`, `media`, `adaptive-redis`, `mcp` — and the plugin is usable with only `core`, which is why the tool surface can be partial. If the interpreter you fall back to has no Scrapling, the tool list is empty and the guidance names the exact `pip install` command; that is a prerequisite statement, not a packaging defect. Search backends need their own API key or a SearXNG instance. `adaptiveStorage: redis` needs a reachable Redis.
|
|
36
|
+
|
|
37
|
+
Failures are named, not hidden: `SIDECAR_*`, `INSTALL_*`, `SEARCH_AUTH`, `JOBS_UNAVAILABLE`, `SESSION_STATE_DISABLED`, `MCP_PORT_IN_USE` / `MCP_PORT_MISMATCH` / `MCP_MODE_CONFLICT` / `MCP_CLIENT_MISSING`, `OFFICIAL_MCP_DISABLED`, `RISK_NOT_ACCEPTED`. An MCP token is read from `DSH_SCRAPLING_MCP_TOKEN` in the host's environment only — never from the profile file, which is plain text.
|
|
38
|
+
|
|
39
|
+
## Further detail
|
|
40
|
+
|
|
41
|
+
The sidecar protocol, capability-pack installer internals, offline assets and the security model are in the package README (`README.md` / `README.zh-CN.md`).
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
# Scrapling 网页抓取
|
|
2
|
+
|
|
3
|
+
抓取与结构化抽取网页——JS 渲染、CSS/XPath 抽取、选择器自愈、带登录态的会话、后台爬虫与页面问答,全部由一个常驻 Python 进程提供。
|
|
4
|
+
|
|
5
|
+
## 设置卡上改的是什么
|
|
6
|
+
|
|
7
|
+
卡上五十个取值按用途分组,多数每次调用现读,改完下一次调用就生效,不需要重启宿主。`pythonBin`、`failFastOnMissingPython` 与 `dataDir` 在插件装载时生效,改它们需要重启。
|
|
8
|
+
|
|
9
|
+
- **运行环境** — `pythonBin`(留空)决定用哪个解释器:显式路径优先,其次托管的能力包安装,再次本包的开发 venv,最后落回 PATH 上的 `python3`。每次都会播报选中的是哪一支。`failFastOnMissingPython`(默认开)让 sidecar 起不来时直接拒绝装载;而解释器起得来但没装 Scrapling 时,一律降级成「工具不可用」并在日志里点名路径。`dataDir` 是 sidecar 状态的落点。
|
|
10
|
+
- **工具开关** — 十五个(fetch、extract、locate、links、render、capture XHR、会话网络历史、session、登录态、crawl、answer、session read、页面动作、download、screenshot)。关掉一个就是模型看不见它,连对应的提示词段落一起撤掉。
|
|
11
|
+
- **抽取与输出** — `extractionType`(markdown/html/text)、`mainContentOnly`,以及各工具的输出预算(`fetchMaxOutputChars` 等,默认 200000)——那是 UTF-8 字节预算,两侧都会执行。
|
|
12
|
+
- **浏览器** — `headless`(默认开)、`networkIdle`(默认关)、`blockAds`(默认开,约 3500 个域名)、`pierceShadow`(默认关)、`waitSelectorState`。
|
|
13
|
+
- **超时与回收** — `fetchTimeoutMs`(120000)、`sidecarHandshakeTimeoutMs`(30000)、`sidecarGraceMs`(5000)。
|
|
14
|
+
- **网络与安全** — `proxyUrl`(显示时遮蔽)、`proxyBypass`、`allowedHosts`、`syntheticDnsRanges`、`nat64Prefixes`,以及搜索侧的 `searchBackend`、各家 API key、`searxngEndpoint`、`searchPublicFallback`(默认关)。
|
|
15
|
+
- **页面问答** — `answerProvider`、`answerModel`、`answerMaxTokens`(2000)。
|
|
16
|
+
|
|
17
|
+
## 有些卡上开关还要配一道部署侧的开关
|
|
18
|
+
|
|
19
|
+
卡上的 `provideWebFetch` 与 `provideWebSearch` 单独拨过去不够:部署侧还得把本插件选成宿主的 fetch / search 提供方,基座那一份仍会接管。页面动作、下载与登录态三档同理。只看卡上会以为开关坏了。
|
|
20
|
+
|
|
21
|
+
## 三十项部署值留在卡外
|
|
22
|
+
|
|
23
|
+
它们改的是本插件怎么接进宿主,不是某次会话该怎么走,而且都要重启才生效。最可能遇到的是这几项:
|
|
24
|
+
|
|
25
|
+
- `integrationMode` — `native` 把工具注册进宿主;`mcp` 改为把同一份工具表端给 MCP;`official-mcp` 两者都不做,只带上游 server 那条目。三档互斥,且只在装配时读一次,切换必须重启。
|
|
26
|
+
- `mcpPort`(默认 39217)要与 profile 里 MCP 客户端条目的 URL 同值;改完要重跑本包的 `setup`,它的 `doctor` 会比对两边。
|
|
27
|
+
- `officialMcpEnabled`(默认关)需要这一档加上 `setup` 的 `--accept-risk` 同一次表态才生成条目,因为上游 server 暴露的动作不归本插件的守卫看。
|
|
28
|
+
- `allowWriteMethods`(默认关)——读网页是这插件的本职,改对端状态不是,所以这一档属于部署表态。
|
|
29
|
+
- 同一档位的还有:浏览器二进制与 CDP 端点、真 Chrome 与 DNS-over-HTTPS 选项、Redis 地址与自适应存储、爬虫的运行时/robots/延时/并发/策略/checkpoint、各家搜索端点。
|
|
30
|
+
|
|
31
|
+
这些都写在本插件注册行的 `config:` 块里。
|
|
32
|
+
|
|
33
|
+
## 需要外部提供什么
|
|
34
|
+
|
|
35
|
+
Python 与 Scrapling 由你提供,本插件从不动你的系统解释器。Chromium 由 `python -m patchright install chromium` 装。能力包按层作为宿主作业安装——`core`、`browser`、`search`、`media`、`adaptive-redis`、`mcp`;只有 `core` 时插件照用,所以工具面本来就可以是不完整的。回退到的解释器没装 Scrapling 时工具表为空,指引会给出可照抄的 `pip install` 命令——那是「装之前要做的一件事」,不是产物缺陷。搜索后端要各自的 API key 或一套 SearXNG。`adaptiveStorage: redis` 要连得上的 Redis。
|
|
36
|
+
|
|
37
|
+
失败是被点名的,不是被藏起来的:`SIDECAR_*`、`INSTALL_*`、`SEARCH_AUTH`、`JOBS_UNAVAILABLE`、`SESSION_STATE_DISABLED`、`MCP_PORT_IN_USE` / `MCP_PORT_MISMATCH` / `MCP_MODE_CONFLICT` / `MCP_CLIENT_MISSING`、`OFFICIAL_MCP_DISABLED`、`RISK_NOT_ACCEPTED`。MCP 的 token 只从宿主环境变量 `DSH_SCRAPLING_MCP_TOKEN` 读,绝不写进 profile——那份文件是明文。
|
|
38
|
+
|
|
39
|
+
## 更完整的说明
|
|
40
|
+
|
|
41
|
+
sidecar 协议、能力包安装器内部、离线资产与安全模型都写在随包 README(`README.md` / `README.zh-CN.md`)。
|