@jayyuen66/dsh-scrapling 0.1.9 → 0.1.11
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 +30 -0
- package/README.md +35 -29
- package/README.zh-CN.md +35 -29
- package/bin/dsh-scrapling.mjs +5 -5
- package/client.js +14 -14
- package/docs/DETAIL.md +1 -1
- package/docs/DETAIL.zh.md +1 -1
- package/host.js +7 -7
- package/package.json +44 -43
- package/py/adapters.py +10 -0
- package/py/runtime-requirements.txt +1 -1
package/bin/dsh-scrapling.mjs
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
import{createRequire as e}from"node:module";import{accessSync as t,constants as n,existsSync as r,readFileSync as i,statSync as a}from"node:fs";import{access as o,chmod as s,cp as c,mkdir as l,open as u,readFile as d,readdir as f,rename as p,rm as m,rmdir as h,writeFile as ee}from"node:fs/promises";import te from"node:os";import g from"node:path";import{createHash as ne,randomUUID as re}from"node:crypto";import{spawn as ie}from"node:child_process";const ae=`scrapling`,oe=`streamable-http`,se=`stdio`,ce=`DSH_SCRAPLING_MCP_TOKEN`,_=`@deepseek-ai/dsh-mcp-client`,le=`0.2.2-rc.
|
|
3
|
-
`:return String.raw`\n`;case`\r`:return String.raw`\r`;case` `:return String.raw`\t`;default:return`\\u${e.charCodeAt(0).toString(16).padStart(4,`0`)}`}}const ye=/[\u0000-\u001F\u007F-\u009F"\\]/gu;function be(e){return`"${e.replaceAll(ye,e=>ve(e))}"`}const xe="official-mcp 直连官方 scrapling-mcp:它的全部工具不经本插件的 URL 守卫与会话闸门(钉住的 scrapling 版本里有 `browser_evaluate` 这类任意 JS 执行),用的是它自己的会话与状态,本插件既不复用也不拦截。";function Se(e){if(!e.enabled)throw new ge(`OFFICIAL_MCP_DISABLED`,`official-mcp 未启用:部署配置里把 officialMcpEnabled 设为 true 才会生成接入配置`);if(!e.acceptedRisk)throw new ge(`RISK_NOT_ACCEPTED`,`${xe} 确认接受请再跑一次 setup 并带 --accept-risk。`);let t=_e(e.dataDir);return{command:t,args:[],serverName:ae,risk:xe,installCommand:he(`0.2.2-rc.
|
|
2
|
+
import{createRequire as e}from"node:module";import{accessSync as t,constants as n,existsSync as r,readFileSync as i,statSync as a}from"node:fs";import{access as o,chmod as s,cp as c,mkdir as l,open as u,readFile as d,readdir as f,rename as p,rm as m,rmdir as h,writeFile as ee}from"node:fs/promises";import te from"node:os";import g from"node:path";import{createHash as ne,randomUUID as re}from"node:crypto";import{spawn as ie}from"node:child_process";const ae=`scrapling`,oe=`streamable-http`,se=`stdio`,ce=`DSH_SCRAPLING_MCP_TOKEN`,_=`@deepseek-ai/dsh-mcp-client`,le=`0.2.2-rc.2`,ue=[le,`0.2.2-rc.1`,`next`],de=[`native`,`mcp`,`official-mcp`],fe=new Set(de);function pe(e){return fe.has(e)}function me(e,t){if(!Number.isInteger(e)||e<1||e>65535)throw Error(`MCP port must be an integer in 1..65535, got ${String(e)}`);return`http://${t.includes(`:`)&&!t.startsWith(`[`)?`[${t}]`:t}:${String(e)}/mcp`}function he(e=le){if(!ue.includes(e))throw Error(`unsupported MCP client pin: ${JSON.stringify(e)}`);return`dsh plugin --profile <profile> add ${_}@${e}`}var ge=class extends Error{code;constructor(e,t){super(t),this.name=`OfficialMcpError`,this.code=e}};function _e(e){let t=g.join(e,`runtime`,`venv`);return process.platform===`win32`?g.join(t,`Scripts`,`scrapling-mcp.exe`):g.join(t,`bin`,`scrapling-mcp`)}function ve(e){switch(e){case`"`:return String.raw`\"`;case`\\`:return String.raw`\\`;case`
|
|
3
|
+
`:return String.raw`\n`;case`\r`:return String.raw`\r`;case` `:return String.raw`\t`;default:return`\\u${e.charCodeAt(0).toString(16).padStart(4,`0`)}`}}const ye=/[\u0000-\u001F\u007F-\u009F"\\]/gu;function be(e){return`"${e.replaceAll(ye,e=>ve(e))}"`}const xe="official-mcp 直连官方 scrapling-mcp:它的全部工具不经本插件的 URL 守卫与会话闸门(钉住的 scrapling 版本里有 `browser_evaluate` 这类任意 JS 执行),用的是它自己的会话与状态,本插件既不复用也不拦截。";function Se(e){if(!e.enabled)throw new ge(`OFFICIAL_MCP_DISABLED`,`official-mcp 未启用:部署配置里把 officialMcpEnabled 设为 true 才会生成接入配置`);if(!e.acceptedRisk)throw new ge(`RISK_NOT_ACCEPTED`,`${xe} 确认接受请再跑一次 setup 并带 --accept-risk。`);let t=_e(e.dataDir);return{command:t,args:[],serverName:ae,risk:xe,installCommand:he(`0.2.2-rc.2`),patch:[`- insert:`,` - id: scrapling-official-mcp`,` name: '${_}'`,` config:`,` serverName: ${ae}`,` transport: ${se}`,` command: ${be(t)}`,` args: []`,` failOnStartupError: true`,``].join(`
|
|
4
4
|
`)}}function Ce(e){return typeof e==`object`&&!!e&&!Array.isArray(e)}const we=/\r\n|\n|\r/u,Te=/:(?<port>\d+)/u,Ee=/[\t ]#.*$/u,De=/^(?:"(?<double>[^"]*)"|'(?<single>[^']*)')$/u,Oe=/^(?:-[\t ]*)?name:(?<value>.*)$/u,ke=/^(?<key>[\w-]+):[\t ]+(?<value>\S.*)$/u;function Ae(e){let t=e.replace(Ee,``).trim(),n=De.exec(t)?.groups,r=n?.double??n?.single;return r===void 0?t.length===0?void 0:t:r}function je(e){return e.split(we)}function Me(e){let t=[],n;for(let r of je(e)){let e=r.length-r.trimStart().length,i=r.slice(e),a=Ae(Oe.exec(i)?.groups?.value??``),o=ke.exec(i)?.groups;a===void 0?o?.key!==void 0&&o.value!==void 0&&n!==void 0&&e>n.indent&&(n.entry.config[o.key]=Ae(o.value)):(n={entry:{name:a,config:{}},indent:e},t.push(n.entry))}return t}function Ne(e){let{url:t}=e.config,n;if(t!==void 0)try{let{port:e,protocol:r}=new URL(t);e===``?r===`http:`?n=`80`:r===`https:`&&(n=`443`):n=e}catch{n=Te.exec(t)?.groups?.port}return n}function Pe(e){return e.config.transport===se}function Fe(e){let t=[];e.mode!==`native`&&e.clientVersion===void 0&&t.push({code:`MCP_CLIENT_MISSING`,detail:`profile 没有 ${_}:跑 ${he()} 装上它`});let n=e.clientVersion;return n!==void 0&&!ue.includes(n)&&t.push({code:`MCP_CLIENT_UNPINNED`,detail:`客户端钉的是 ${e.clientVersion},只接受 ${ue.join(` 或 `)} —— 宿主对不匹配的对端拒绝装载`}),t}function Ie(e,t){let n=[];t.length>1&&n.push({code:`DUPLICATE_SCRAPLING_ENTRY`,detail:`serverName 为 scrapling 的条目有 ${String(t.length)} 条,一个名字只能有一个 server`}),t.some(e=>Pe(e))&&t.some(e=>!Pe(e))&&n.push({code:`MCP_MODE_CONFLICT`,detail:`本插件的 ${oe} 条目与官方 ${se} 条目并存;同一时刻只能一种`});let r=e.mode===`official-mcp`,i=t.some(e=>r===Pe(e));return e.mode===`native`&&t.length>0?n.push({code:`MCP_MODE_ENTRY_MISMATCH`,detail:`integrationMode=native 却留着 scrapling 的 MCP 条目:模型会同时看到两套工具`}):e.mode!==`native`&&!i&&n.push({code:`MCP_MODE_ENTRY_MISMATCH`,detail:`integrationMode=${e.mode} 需要 ${r?se:oe} 条目,profile 里没有`}),r&&!e.officialMcpEnabled&&t.some(e=>Pe(e))&&n.push({code:`MCP_OFFICIAL_SWITCH_OFF`,detail:`留着官方 stdio 条目但 officialMcpEnabled=false:官方 server 的工具不经本插件守卫,开关要明说`}),n}function Le(e,t){let n=[...new Set(e.map(e=>Ne(e)).filter(e=>e!==void 0))];if(n.length===0)return[];let r=t===void 0?void 0:String(t);return n.length<2&&(r===void 0||n.includes(r))?[]:[{code:`MCP_PORT_MISMATCH`,detail:`条目里的端口是 ${n.join(`, `)}${r===void 0?``:`,--port 说的是 ${r}`};改过 mcpPort 就要重新应用 patch`}]}function Re(e){let t=Me(e.patchText).filter(e=>e.name===`@deepseek-ai/dsh-mcp-client`&&e.config.serverName===`scrapling`);return[...Fe(e),...Ie(e,t),...Le(t,e.expectedPort)]}const ze=/^[\t ]*officialMcpEnabled:(?<value>[^\r\n]*)$/gmu;function Be(e){let t;for(let n of e.matchAll(ze))t=n.groups?.value;let n=t?.replace(Ee,``).trim(),r=n===void 0?void 0:De.exec(n)?.groups;return r?.double??r?.single??n}function Ve(e){let t=Be(e);return t===`true`||t===`True`||t===`TRUE`}async function He(e){try{return await d(e,`utf8`)}catch(t){if(Ce(t)&&t.code===`ENOENT`)return``;throw Error(`读不出 ${e}:${String(t)}`,{cause:t})}}function Ue(e){try{let t=JSON.parse(e);return Ce(t)?t:{}}catch{return{}}}function We(e){let{dependencies:t}=Ue(e),n=Ce(t)?t[_]:void 0;return typeof n==`string`?n:void 0}async function Ge(e){let[t,n]=await Promise.all([He(g.join(e,`cordis.patch.yml`)),He(g.join(e,`package.json`))]);return{patchText:t,clientVersion:We(n),officialMcpEnabled:Ve(t)}}function Ke(e){return`${e}.patch.yml`}function qe(e){let t=[`- insert:`,` - id: scrapling-mcp`,` name: '${_}'`,` config:`,` serverName: ${ae}`,` transport: ${oe}`,` url: ${me(e.port,`127.0.0.1`)}`,` failOnStartupError: false`];return e.withAuth&&t.push(` headers:`,` Authorization: !!js '\`Bearer \${process.env.${ce}}\`'`),`${t.join(`
|
|
5
5
|
`)}\n`}function Je(){return[`# integrationMode=native:profile 里不留 scrapling 的 MCP 条目。`,`# 留着条目时模型会同时看到原生工具与 mcp__scrapling__* 两套同名不同层的工具。`,`# 这份文本本身不删任何东西:profile 里若已有 name: '${_}' 的条目,`,"# 要手工删掉它再重启宿主,否则 `doctor --mode native` 会按事实报 MCP_MODE_ENTRY_MISMATCH。",``].join(`
|
|
6
6
|
`)}const Ye=[`auto`,`tavily`,`bing`,`brave`,`serper`,`duckduckgo`,`searxng`];function Xe(e){return Ye.includes(e)}function Ze(e){let t=Object.values(e).filter(e=>typeof e==`number`);return Object.entries(e).filter(([e,n])=>t.indexOf(+e)===-1).map(([e,t])=>t)}function Qe(e,t=`|`){return e.map(e=>_t(e)).join(t)}function $e(e,t){return typeof t==`bigint`?t.toString():t}var et=class{constructor(e){this._getter=e,this._value=void 0}get value(){let e=this._getter;return e!==void 0&&(this._value=e(),this._getter=void 0),this._value}};function tt(e){return new et(e)}function nt(e){return e==null}function rt(e){let t=+!!e.startsWith(`^`),n=e.endsWith(`$`)?e.length-1:e.length;return e.slice(t,n)}function it(e,t){let n=e/t,r=Math.round(n),i=4*2**-52*Math.max(Math.abs(n),1);return Math.abs(n-r)<i?0:n-r}function v(e,t,n){Object.defineProperty(e,t,{value:n,writable:!0,enumerable:!0,configurable:!0})}function at(e){let t=Object.getOwnPropertyDescriptor(e,`shape`);return t?.get?t.get.raw:t?.value}function y(e){return at(e._zod.def)??e._zod.def.shape}function ot(e,t,n){Object.defineProperty(e,t,{get(){let e=n();return v(this,t,e),e},enumerable:!0,configurable:!0})}function st(e,t,n){t in e?v(e,t,n):e[t]=n}function b(e,t,n,r){let i=y(t);for(let a of n){let n=Object.getOwnPropertyDescriptor(i,a);n.enumerable&&(n.get?ot(e,a,()=>{let e=t._zod.def.shape[a];return r?r(e,a):e}):st(e,a,r?r(n.value,a):n.value))}}function ct(e,t){for(let n of Reflect.ownKeys(t)){let r=Object.getOwnPropertyDescriptor(t,n);r.enumerable&&(r.get?ot(e,n,()=>t[n]):st(e,n,r.value))}}function x(...e){let t={};for(let n of e){let e=Object.getOwnPropertyDescriptors(n);Object.assign(t,e)}return Object.defineProperties({},t)}function lt(e){return JSON.stringify(e)}function ut(e){return e.toLowerCase().trim().replace(/[^\w\s-]/g,``).replace(/[\s_-]+/g,`-`).replace(/^-+|-+$/g,``)}const dt=`captureStackTrace`in Error?Error.captureStackTrace:(...e)=>{};function ft(e){return typeof e==`object`&&!!e&&!Array.isArray(e)}const pt=/* @__PURE__*/ tt(()=>{if(N.jitless||typeof navigator<`u`&&navigator?.userAgent?.includes(`Cloudflare`))return!1;try{return Function(``),!0}catch{return!1}});function S(e){if(ft(e)===!1)return!1;let t=e.constructor;if(t===void 0||typeof t!=`function`)return!0;let n=t.prototype;return ft(n)!==!1&&Object.prototype.hasOwnProperty.call(n,`isPrototypeOf`)!==!1}function mt(e){return S(e)?{...e}:Array.isArray(e)?[...e]:e instanceof Map?new Map(e):e instanceof Set?new Set(e):e}const ht=/* @__PURE__*/ new Set([`string`,`number`,`symbol`]);function gt(e){return e.replace(/[.*+?^${}()|[\]\\]/g,`\\$&`)}function C(e,t,n){let r=new e._zod.constr(t??e._zod.def);return(!t||n?.parent)&&(r._zod.parent=e),r}function w(e){let t=e;if(!t)return{};if(typeof t==`string`)return{error:()=>t};if(t?.message!==void 0){if(t?.error!==void 0)throw Error("Cannot specify both `message` and `error` params");t.error=t.message}return delete t.message,typeof t.error==`string`?{...t,error:()=>t.error}:t}function _t(e){return typeof e==`bigint`?e.toString()+`n`:typeof e==`string`?`"${e}"`:`${e}`}function vt(e){return Object.keys(e).filter(t=>e[t]._zod.optin!==void 0&&e[t]._zod.optout===`optional`)}const yt={safeint:[-(2**53-1),2**53-1],int32:[-2147483648,2147483647],uint32:[0,4294967295],float32:[-34028234663852886e22,34028234663852886e22],float64:[-Number.MAX_VALUE,Number.MAX_VALUE]},bt={int64:[/* @__PURE__*/ BigInt(`-9223372036854775808`),/* @__PURE__*/ BigInt(`9223372036854775807`)],uint64:[/* @__PURE__*/ BigInt(0),/* @__PURE__*/ BigInt(`18446744073709551615`)]};function xt(e,t){let n=e._zod.def,r=n.checks;if(r&&r.length>0)throw Error(`.pick() cannot be used on object schemas containing refinements`);let i={};return b(i,e,St(e,t)),C(e,x(n,{shape:i,checks:[]}))}function St(e,t){let n=y(e),r=[];for(let e of Reflect.ownKeys(t)){if(!Object.getOwnPropertyDescriptor(n,e)?.enumerable)throw Error(`Unrecognized key: "${String(e)}"`);t[e]&&r.push(e)}return r}function Ct(e,t){let n=e._zod.def,r=n.checks;if(r&&r.length>0)throw Error(`.omit() cannot be used on object schemas containing refinements`);let i=new Set(St(e,t)),a={};return b(a,e,Reflect.ownKeys(y(e)).filter(e=>!i.has(e))),C(e,x(n,{shape:a,checks:[]}))}function wt(e,t){if(!S(t))throw Error(`Invalid input to extend: expected a plain object`);let n=e._zod.def.checks;if(n&&n.length>0){let n=y(e);for(let e of Reflect.ownKeys(t))if(Object.getOwnPropertyDescriptor(n,e)!==void 0)throw Error("Cannot overwrite keys on object schemas containing refinements. Use `.safeExtend()` instead.")}return C(e,x(e._zod.def,{shape:Tt(e,t)}))}function Tt(e,t){let n={};return b(n,e,Reflect.ownKeys(y(e))),ct(n,t),n}function Et(e,t){if(!S(t))throw Error(`Invalid input to safeExtend: expected a plain object`);return C(e,x(e._zod.def,{shape:Tt(e,t)}))}function Dt(e,t){if(!t?._zod?.def)throw Error("Invalid input to merge: expected an object schema. To merge a plain shape, use `.extend()`.");if(e._zod.def.checks?.length)throw Error(`.merge() cannot be used on object schemas containing refinements. Use .safeExtend() instead.`);let n={};return b(n,e,Reflect.ownKeys(y(e))),b(n,t,Reflect.ownKeys(y(t))),C(e,x(e._zod.def,{shape:n,get catchall(){return t._zod.def.catchall},checks:t._zod.def.checks??[]}))}function Ot(e,t,n,r=`partial`){let i=t._zod.def.checks;if(i&&i.length>0)throw Error(`.${r}() cannot be used on object schemas containing refinements`);let a=n?new Set(St(t,n)):void 0,o={};return b(o,t,Reflect.ownKeys(y(t)),e&&((t,n)=>a&&!a.has(n)?t:new e({type:`optional`,innerType:t}))),C(t,x(t._zod.def,{shape:o,checks:[]}))}function kt(e,t,n){let r=n?new Set(St(t,n)):void 0,i={};return b(i,t,Reflect.ownKeys(y(t)),(t,n)=>r&&!r.has(n)?t:new e({type:`nonoptional`,innerType:t})),C(t,x(t._zod.def,{shape:i}))}function T(e,t=0){if(e.aborted===!0)return!0;for(let n=t;n<e.issues.length;n++)if(e.issues[n]?.continue!==!0)return!0;return!1}function At(e,t=0){if(e.aborted===!0)return!0;for(let n=t;n<e.issues.length;n++)if(e.issues[n]?.continue===!1)return!0;return!1}function E(e,t){return t.map(t=>{var n;return(n=t).path??(n.path=[]),t.path.unshift(e),t})}function jt(e){return typeof e==`string`?e:e?.message}function Mt(e){let t=[];for(let n of e??[]){let e=n._zod.def;if(!/_(length|size)$|_equals$/.test(e.check))break;let r=e.maximum??e.length??e.size;r>=0&&t.push([r,n])}return t}function Nt(e,t,n){var r;for(let i=t;i<e.length;i++)(r=e[i]).schema??(r.schema=n)}function D(e,t,n){var r;let i=e.inst?._zod?.traits;i?.has(`$ZodType`)&&(i.has(`$ZodCheck`)?(r=e).schema??(r.schema=e.inst):e.schema=e.inst);let a=e.schema===e.inst?void 0:e.schema?._zod.def?.error,o=e.message?e.message:jt(e.inst?._zod.def?.error?.(e))??jt(a?.(e))??jt(t?.error?.(e))??jt(n.customError?.(e))??jt(n.localeError?.(e))??`Invalid input`,s={};for(let t of Object.keys(e))t!==`inst`&&t!==`schema`&&t!==`continue`&&t!==`input`&&t!==`__proto__`&&(s[t]=e[t]);return s.path??=[],s.message=o,t?.reportInput&&(s.input=e.input),s}const Pt=/[\uD800-\uDBFF]/;function Ft(e){let t=e.length;if(!Pt.test(e))return t;let n=t;for(let r=0;r<t-1;r++)(e.charCodeAt(r)&64512)==55296&&(e.charCodeAt(r+1)&64512)==56320&&(n--,r++);return n}function It(e){return Array.isArray(e)?`array`:typeof e==`string`?`string`:`unknown`}function Lt(e){let t=typeof e;switch(t){case`number`:return Number.isNaN(e)?`nan`:`number`;case`object`:{if(e===null)return`null`;if(Array.isArray(e))return`array`;let t=e;if(t&&Object.getPrototypeOf(t)!==Object.prototype&&`constructor`in t&&t.constructor)return t.constructor.name}}return t}function Rt(...e){let[t,n,r]=e;return typeof t==`string`?{message:t,code:`custom`,input:n,inst:r}:{...t}}function zt(e,t){for(let n in t){let r=Object.getOwnPropertyDescriptor(t,n);r.get?Object.defineProperty(e,n,{...r,enumerable:!1}):Ht(e,n,r.value)}}function O(e,t,n,r=!0){return Object.defineProperty(e,t,{configurable:!0,writable:!0,enumerable:r,value:n}),n}function Bt(e,t,n){return O(e,t,n,!1)}/* @__NO_SIDE_EFFECTS__ */
|
|
@@ -114,6 +114,6 @@ function _o(e,t,n){return new e({type:`custom`,check:`custom`,fn:t,...w(n)})}//
|
|
|
114
114
|
function vo(e,t){let n=/* @__PURE__ */ yo(t=>(t.addIssue=e=>{if(typeof e==`string`)t.issues.push(Rt(e,t.value,n._zod.def));else{let r=e;r.fatal&&(r.continue=!1),r.code??=`custom`,`input`in r||(r.input=t.value),r.inst??=n,r.continue??=!n._zod.def.abort,t.issues.push(Rt(r))}},e(t.value,t)),t);return n}// @__NO_SIDE_EFFECTS__
|
|
115
115
|
function yo(e,t){let n=new F({check:`custom`,...w(t)});return n._zod.check=e,n}function bo(e,...t){for(let n of t)for(let t of Reflect.ownKeys(n))Object.prototype.propertyIsEnumerable.call(n,t)&&v(e,t,n[t]);return e}function xo(e){let t=e?.target??`draft-2020-12`;return t===`draft-4`&&(t=`draft-04`),t===`draft-7`&&(t=`draft-07`),{processors:e.processors??{},metadataRegistry:e?.metadata??va,target:t,unrepresentable:e?.unrepresentable??`throw`,override:e?.override??(()=>{}),io:e?.io??`output`,counter:0,seen:/* @__PURE__ */ new Map,sharedDefsExtractedFor:void 0,sharedEmitDoneFor:void 0,cycles:e?.cycles??`ref`,reused:e?.reused??`inline`,intersections:[],deferred:[],external:e?.external??void 0}}function z(e,t,n,r,i){let a=typeof t.unrepresentable==`function`?t.unrepresentable({zodSchema:e,path:r.path,message:i}):t.unrepresentable;if(a===`any`)return!1;if(a===void 0||a===`throw`)throw Error(i);return Object.assign(n,a),!0}function B(e,t,n={path:[],schemaPath:[]}){var r;let i=e._zod.def,a=t.seen.get(e);if(a)return a.count++,n.schemaPath.includes(e)&&(a.cycle=n.path),a.schema;let o={schema:{},count:1,cycle:void 0,path:n.path};t.seen.set(e,o),t.sharedDefsExtractedFor=void 0,t.sharedEmitDoneFor=void 0;let s=e._zod.toJSONSchema?.();if(s)o.schema=s;else{let r={...n,schemaPath:[...n.schemaPath,e],path:n.path};if(e._zod.processJSONSchema)e._zod.processJSONSchema(t,o.schema,r);else{let n=o.schema,a=t.processors[i.type];if(!a)throw Error(`[toJSONSchema]: Non-representable type encountered: ${i.type}`);a(e,t,n,r)}let a=e._zod.parent;a&&(o.ref||=a,B(a,t,r),t.seen.get(a).isParent=!0)}let c=t.metadataRegistry.get(e);return c&&bo(o.schema,c),t.io===`input`&&V(e)&&(delete o.schema.examples,delete o.schema.default),t.io===`input`&&`_prefault`in o.schema&&((r=o.schema).default??(r.default=o.schema._prefault)),delete o.schema._prefault,t.seen.get(e).schema}function So(e){return e.replace(/~/g,`~0`).replace(/\//g,`~1`)}function Co(e,t){let n=e.seen.get(t);if(!n)throw Error(`Unprocessed schema. This is a bug in Zod.`);if(e.external&&e.sharedDefsExtractedFor===e.external)return;let r=/* @__PURE__ */ new Map;for(let t of e.seen.entries()){let n=e.metadataRegistry.get(t[0])?.id;if(n){let e=r.get(n);if(e&&e!==t[0])throw Error(`Duplicate schema id "${n}" detected during JSON Schema conversion. Two different schemas cannot share the same id when converted together.`);r.set(n,t[0])}}let i=t=>{let r=e.target===`draft-2020-12`?`$defs`:`definitions`;if(e.external){let n=e.external.registry.get(t[0])?.id,i=e.external.uri??(e=>e);if(n)return{ref:i(n)};let a=t[1].defId??t[1].schema.id??`schema${e.counter++}`;return t[1].defId=a,{defId:a,ref:`${i(`__shared`)}#/${r}/${So(a)}`}}let i=`#/${r}/`;if(t[1]===n&&!t[1].schema.id)return{ref:`#`};let a=t[1].schema.id??`__schema${e.counter++}`;return{defId:a,ref:i+So(a)}},a=e=>{if(e[1].schema.$ref)return;let t=e[1],{ref:n,defId:r}=i(e);t.def={...t.schema},r&&(t.defId=r);let a=t.schema;for(let e in a)delete a[e];a.$ref=n};if(e.cycles===`throw`)for(let t of e.seen.entries()){let e=t[1];if(e.cycle)throw Error(`Cycle detected: #/${e.cycle?.join(`/`)}/<root>
|
|
116
116
|
|
|
117
|
-
Set the \`cycles\` parameter to \`"ref"\` to resolve cyclical schemas with defs.`)}for(let n of e.seen.entries()){let r=n[1];if(t===n[0])a(n);else{if(e.external){let r=e.external.registry.get(n[0])?.id;if(t!==n[0]&&r){a(n);continue}}(e.metadataRegistry.get(n[0])?.id||r.cycle||r.count>1&&e.reused===`ref`)&&a(n)}}e.external&&(e.sharedDefsExtractedFor=e.external)}function wo(e){let t=e.anyOf;if(!Array.isArray(t)||t.length===0||e.type!==void 0)return;let n=[];for(let e of t){if(!e||typeof e!=`object`)return;wo(e);let t=Object.keys(e);if(t.length!==1||t[0]!==`type`)return;let r=e.type;for(let e of Array.isArray(r)?r:[r]){if(typeof e!=`string`)return;n.includes(e)||n.push(e)}}delete e.anyOf,e.type=n.length===1?n[0]:n}const To=/* @__PURE__ */ new Set([`type`,`properties`,`required`,`additionalProperties`]),Eo=[`oneOf`,`anyOf`];function Do(e){let t=e.additionalProperties;return t===void 0||t===!1||typeof t!=`object`||!t?null:Object.keys(t).length?t:null}function Oo(e){let t=[];for(let n of e){if(typeof n!=`object`||n.type!==`object`)return null;for(let e in n)if(!To.has(e))return null;t.push(n)}let n={},r=/* @__PURE__ */ new Set;for(let e of t){for(let r in e.properties){if(Object.prototype.hasOwnProperty.call(n,r))continue;let e=[];for(let n of t){let t=n.properties?.[r]??Do(n);t!=null&&(e.some(e=>JSON.stringify(e)===JSON.stringify(t))||e.push(t))}v(n,r,e.length===1?e[0]:Oo(e)??{allOf:e})}for(let t of e.required??[])r.add(t)}let i={type:`object`,properties:n};if(r.size&&(i.required=[...r]),t.every(e=>e.additionalProperties===!1))i.additionalProperties=!1;else{let e=[];for(let n of t){let t=Do(n);t&&!e.some(e=>JSON.stringify(e)===JSON.stringify(t))&&e.push(t)}e.length===1?i.additionalProperties=e[0]:e.length>1&&(i.additionalProperties={allOf:e})}return i}function ko(e){let t=e.allOf;if(!Array.isArray(t)||t.length<2)return;for(let t of To)if(t in e)return;let n=t.filter(e=>Eo.some(t=>Array.isArray(e[t]))),r=null;if(!n.length)r=Oo(t);else{let e=n[0],i=Eo.find(t=>Array.isArray(e[t]));if(Object.keys(e).length!==1)return;let a=t.filter(t=>t!==e),o=e[i].map(e=>Oo([...a,e]));if(o.some(e=>!e))return;r={[i]:o}}r&&(delete e.allOf,bo(e,r))}function Ao(e,t){let n=e.seen.get(t);if(!n)throw Error(`Unprocessed schema. This is a bug in Zod.`);let r=t=>{let n=e.seen.get(t);if(n.ref===null)return;let i=n.def??n.schema,a={...i},o=n.ref;if(n.ref=null,o){r(o);let n=e.seen.get(o),s=n.schema;if(s.$ref&&(e.target===`draft-07`||e.target===`draft-04`||e.target===`openapi-3.0`)?(i.allOf=i.allOf??[],i.allOf.push(s)):bo(i,s),bo(i,a),t._zod.parent===o)for(let e in i)e!==`$ref`&&e!==`allOf`&&(e in a||delete i[e]);if(s.$ref&&n.def)for(let e in i)e!==`$ref`&&e!==`allOf`&&e in n.def&&JSON.stringify(i[e])===JSON.stringify(n.def[e])&&delete i[e]}let s=t._zod.parent;if(s&&s!==o){r(s);let t=e.seen.get(s);if(t?.schema.$ref&&(i.$ref=t.schema.$ref,t.def))for(let e in i)e!==`$ref`&&e!==`allOf`&&e in t.def&&JSON.stringify(i[e])===JSON.stringify(t.def[e])&&delete i[e]}e.override({zodSchema:t,jsonSchema:i,path:n.path??[]})};if(!e.external||e.sharedEmitDoneFor!==e.external){for(let t of[...e.seen.entries()].reverse())r(t[0]);if(e.target!==`openapi-3.0`)for(let t of e.seen.entries())wo(t[1].def??t[1].schema);for(let t of e.deferred)t();if(e.intersections.length){let t=/* @__PURE__ */ new Map;for(let n of e.seen.values())for(let e of[n.schema,n.def]){let n=e?.allOf;if(!Array.isArray(n))continue;let r=t.get(n);r?r.push(e):t.set(n,[e])}for(let n of e.intersections)for(let e of t.get(n)??[])ko(e)}}let i={};if(e.target===`draft-2020-12`?i.$schema=`https://json-schema.org/draft/2020-12/schema`:e.target===`draft-07`?i.$schema=`http://json-schema.org/draft-07/schema#`:e.target===`draft-04`?i.$schema=`http://json-schema.org/draft-04/schema#`:e.target,e.external?.uri){let n=e.external.registry.get(t)?.id;if(!n)throw Error("Schema is missing an `id` property");i.$id=e.external.uri(n)}bo(i,n.defId?n.schema:n.def??n.schema);let a=e.metadataRegistry.get(t)?.id;a!==void 0&&i.id===a&&delete i.id;let o=e.external?.defs??{};if(!e.external||e.sharedEmitDoneFor!==e.external)for(let t of e.seen.entries()){let e=t[1];e.def&&e.defId&&(e.def.id===e.defId&&delete e.def.id,v(o,e.defId,e.def))}e.external&&(e.sharedEmitDoneFor=e.external),e.external||Object.keys(o).length>0&&(e.target===`draft-2020-12`?i.$defs=o:i.definitions=o);try{let n=JSON.parse(JSON.stringify(i));return Object.defineProperty(n,"~standard",{value:{...t[`~standard`],jsonSchema:{input:Mo(t,`input`,e.processors),output:Mo(t,`output`,e.processors)}},enumerable:!1,writable:!1}),n}catch{throw Error(`Error converting schema to JSON.`)}}function V(e,t){let n=t??{seen:/* @__PURE__ */ new Set};if(n.seen.has(e))return!1;n.seen.add(e);let r=e._zod.def;if(r.type===`transform`)return!0;if(r.type===`array`)return V(r.element,n);if(r.type===`set`)return V(r.valueType,n);if(r.type===`lazy`)return V(r.getter(),n);if(r.type===`promise`||r.type===`optional`||r.type===`nonoptional`||r.type===`nullable`||r.type===`readonly`||r.type==="default"||r.type===`prefault`||r.type===`catch`)return V(r.innerType,n);if(r.type===`intersection`)return V(r.left,n)||V(r.right,n);if(r.type===`record`||r.type===`map`)return V(r.keyType,n)||V(r.valueType,n);if(r.type===`pipe`)return e._zod.traits.has(`$ZodCodec`)?!0:V(r.in,n)||V(r.out,n);if(r.type===`object`){for(let e in r.shape)if(V(r.shape[e],n))return!0;return!1}if(r.type===`union`){for(let e of r.options)if(V(e,n))return!0;return!1}if(r.type===`tuple`){for(let e of r.items)if(V(e,n))return!0;return!!(r.rest&&V(r.rest,n))}return!1}const jo=(e,t={})=>n=>{let r=xo({...n,processors:t});return B(e,r),Co(r,e),Ao(r,e)},Mo=(e,t,n={})=>r=>{let{libraryOptions:i,target:a}=r??{},o=xo({...i??{},target:a,io:t,processors:n});return B(e,o),Co(o,e),Ao(o,e)},H=(e,t,n)=>{(e[t]===void 0||n>e[t])&&(e[t]=n)},U=(e,t,n)=>{(e[t]===void 0||n<e[t])&&(e[t]=n)},No=(e,t)=>{H(e,`minimum`,t),U(e,`maximum`,t)},Po=(e,t)=>{e.multipleOf??=[],e.multipleOf.includes(t)||e.multipleOf.push(t)},Fo=(e,t)=>{e.patterns??=/* @__PURE__ */ new Set,e.patterns.add(t)},Io=(e,t)=>{e.mime=e.mime?e.mime.filter(e=>t.includes(e)):[...t]},Lo=(e,t)=>{e.format=t,t.includes(`int`)&&(e.isInt=!0)},Ro=(e,t)=>H(e,`minimum`,t.minimum),zo=(e,t)=>U(e,`maximum`,t.maximum),Bo=e=>(t,n)=>{Lo(t,n.format);let[r,i]=e[n.format];H(t,`minimum`,r),U(t,`maximum`,i)},Vo={greater_than:(e,t)=>H(e,t.inclusive?`minimum`:`exclusiveMinimum`,t.value),less_than:(e,t)=>U(e,t.inclusive?`maximum`:`exclusiveMaximum`,t.value),multiple_of:(e,t)=>Po(e,t.value),number_format:Bo(yt),bigint_format:Bo(bt),min_length:Ro,max_length:zo,length_equals:(e,t)=>No(e,t.length),min_size:Ro,max_size:zo,size_equals:(e,t)=>No(e,t.size),string_format:(e,t)=>{Lo(e,t.format),t.pattern&&Fo(e,t.pattern),(t.format===`base64`||t.format===`base64url`)&&(e.contentEncoding=t.format),(t.local||t.precision===-1)&&(e.laxFormat=!0)},mime_type:(e,t)=>Io(e,t.mime)};function W(e){let t={},n=e._zod.def,r=e._zod.traits.has(`$ZodCheck`)?[e,...n.checks??[]]:n.checks??[];for(let e of r)Vo[e._zod.def.check]?.(t,e._zod.def);let i=e._zod.bag;i.minimum!==void 0&&H(t,`minimum`,i.minimum),i.exclusiveMinimum!==void 0&&H(t,`exclusiveMinimum`,i.exclusiveMinimum),i.maximum!==void 0&&U(t,`maximum`,i.maximum),i.exclusiveMaximum!==void 0&&U(t,`exclusiveMaximum`,i.exclusiveMaximum),i.multipleOf!==void 0&&Po(t,i.multipleOf),i.format!==void 0&&(t.format??=i.format,i.format.includes(`int`)&&(t.isInt=!0)),i.mime&&Io(t,i.mime);for(let e of i.patterns??[])Fo(t,e);return t}const Ho={guid:`uuid`,url:`uri`,datetime:`date-time`,json_string:`json-string`,regex:``},Uo=/* @__PURE__ */ new Map([[oi,Kn],[ci,qn]]),Wo=e=>Uo.get(e)??e,Go=(e,t,n,r)=>{let i=n;i.type=`string`;let{minimum:a,maximum:o,format:s,patterns:c,contentEncoding:l,laxFormat:u}=W(e);if(typeof a==`number`&&(i.minLength=a),typeof o==`number`&&(i.maxLength=o),s&&(i.format=Ho[s]??s,i.format===``&&delete i.format,(s===`time`||u)&&delete i.format),l&&(i.contentEncoding=l),c&&c.size>0){let e=[...c].map(Wo);e.length===1?i.pattern=e[0].source:e.length>1&&(i.allOf=[...e.map(e=>({...t.target===`draft-07`||t.target===`draft-04`||t.target===`openapi-3.0`?{type:`string`}:{},pattern:e.source}))])}},Ko=(e,t,n,r)=>{let i=n,{minimum:a,maximum:o,multipleOf:s,exclusiveMaximum:c,exclusiveMinimum:l,isInt:u}=W(e);i.type=u?`integer`:`number`;let d=typeof l==`number`&&l>=(a??-1/0),f=typeof c==`number`&&c<=(o??1/0),p=t.target===`draft-04`||t.target===`openapi-3.0`;if(d?p?(i.minimum=l,i.exclusiveMinimum=!0):i.exclusiveMinimum=l:typeof a==`number`&&(i.minimum=a),f?p?(i.maximum=c,i.exclusiveMaximum=!0):i.exclusiveMaximum=c:typeof o==`number`&&(i.maximum=o),s){let n=/* @__PURE__ */ new Set;for(let a of s)Number.isFinite(a)&&a!==0?n.add(Math.abs(a)):z(e,t,i,r,`A multipleOf divisor of ${a} cannot be represented in JSON Schema`);let[a,...o]=n;a!==void 0&&(i.multipleOf=a),o.length&&(i.allOf=[...i.allOf??[],...o.map(e=>({multipleOf:e}))])}},qo=(e,t,n,r)=>{n.not={}},Jo=(e,t,n,r)=>{let i=e._zod.def,a=Ze(i.entries);a.length===0?n.not={}:(a.every(e=>typeof e==`number`)&&(n.type=`number`),a.every(e=>typeof e==`string`)&&(n.type=`string`),n.enum=a)},Yo=(e,t,n,r)=>{z(e,t,n,r,`Custom types cannot be represented in JSON Schema`)},Xo=(e,t,n,r)=>{z(e,t,n,r,`Transforms cannot be represented in JSON Schema`)},Zo=(e,t,n,r)=>{let i=n,a=e._zod.def,{minimum:o,maximum:s}=W(e);typeof o==`number`&&(i.minItems=o),typeof s==`number`&&(i.maxItems=s),i.type=`array`,i.items=B(a.element,t,{...r,path:[...r.path,`items`]})};function Qo(e){let t=e._zod.def;return t.type===`pipe`&&t.in._zod.traits.has(`$ZodTransform`)?Qo(t.out):t.type===`catch`?Qo(t.innerType):e._zod.optin}const $o=(e,t,n,r)=>{let i=n,a=e._zod.def,o=a.shape;if(Object.getOwnPropertySymbols(o).length&&z(e,t,i,r,`Symbol keys cannot be represented in JSON Schema`))return;i.type=`object`,i.properties={};for(let e in o)v(i.properties,e,B(o[e],t,{...r,path:[...r.path,`properties`,e]}));let s=[];for(let e of Object.keys(o)){let n=a.shape[e];(t.io===`input`?Qo(n)===void 0:n._zod.optout===void 0)&&s.push(e)}s.length>0&&(i.required=s),a.catchall?._zod.def.type===`never`?i.additionalProperties=!1:a.catchall?a.catchall&&(i.additionalProperties=B(a.catchall,t,{...r,path:[...r.path,`additionalProperties`]})):t.io===`output`&&(i.additionalProperties=!1)},es=(e,t,n,r)=>{let i=e._zod.def,a=i.inclusive===!1,o=i.options.map((e,n)=>B(e,t,{...r,path:[...r.path,a?`oneOf`:`anyOf`,n]}));a?n.oneOf=o:n.anyOf=o},ts=(e,t,n,r)=>{let i=e._zod.def,a=B(i.left,t,{...r,path:[...r.path,`allOf`,0]}),o=B(i.right,t,{...r,path:[...r.path,`allOf`,1]}),s=e=>`allOf`in e&&Object.keys(e).length===1,c=[...s(a)?a.allOf:[a],...s(o)?o.allOf:[o]];n.allOf=c,t.intersections.push(c)};function ns(e,t,n){if(t.$ref){if(n.has(t))return t;n.add(t);let r=e.get(t)?.def;if(!r)return t;let i=ns(e,r,n);return i===r?t:i}for(let r of[`anyOf`,`oneOf`]){let i=t[r];if(!Array.isArray(i))continue;let a=i.map(t=>ns(e,t,n));a.some((e,t)=>e!==i[t])&&(t={...t,[r]:a})}let r=Array.isArray(t.type)?t.type:[t.type],i=!r.includes(`string`)&&r.some(e=>e===`number`||e===`integer`),a=t.enum??(t.const===void 0?void 0:[t.const]);if(!i&&!a?.some(e=>typeof e==`number`))return t;let{minimum:o,maximum:s,exclusiveMinimum:c,exclusiveMaximum:l,multipleOf:u,format:d,id:f,...p}=t;return p.enum?p.enum=p.enum.map(e=>typeof e==`number`?String(e):e):typeof p.const==`number`&&(p.const=String(p.const)),i&&(p.type=`string`,a||(p.pattern=(r.includes(`number`)?ir:rr).source)),p}const rs=/* @__PURE__ */ new WeakMap;function is(e){let t=/* @__PURE__ */ new Map;for(let n of e.seen.values())n.def&&!t.has(n.schema)&&t.set(n.schema,n);let n=/* @__PURE__ */ new Map;for(let r of rs.get(e)??[]){let i=e.seen.get(r),a=(i?.def??i?.schema)?.propertyNames;if(!a||a===!0||n.has(a))continue;let o=ns(t,a,/* @__PURE__ */ new Set);o!==a&&n.set(a,o)}if(n.size)for(let t of e.seen.values())for(let e of[t.schema,t.def]){let t=e&&n.get(e.propertyNames);t&&(e.propertyNames=t)}}const as=(e,t,n,r)=>{let i=n,a=e._zod.def;i.type=`object`;let o=a.keyType,s=W(o).patterns;if(a.mode===`loose`&&s&&s.size>0){let e=B(a.valueType,t,{...r,path:[...r.path,`patternProperties`,`*`]});i.patternProperties={};for(let t of s)v(i.patternProperties,Wo(t).source,e)}else{if(t.target===`draft-07`||t.target===`draft-2020-12`){i.propertyNames=B(a.keyType,t,{...r,path:[...r.path,`propertyNames`]});let n=rs.get(t);n||(n=[],rs.set(t,n),t.deferred.push(()=>is(t))),n.push(e)}i.additionalProperties=B(a.valueType,t,{...r,path:[...r.path,`additionalProperties`]})}let c=o._zod.values,l=t.io===`input`&&Qo(a.valueType)!==void 0;if(c&&!a.partial&&!l){let e=[...c].filter(e=>typeof e==`string`||typeof e==`number`);e.length>0&&(i.required=e.map(String))}},os=(e,t,n,r)=>{let i=e._zod.def,a=B(i.innerType,t,r),o=t.seen.get(e);t.target===`openapi-3.0`?(o.ref=i.innerType,n.nullable=!0):n.anyOf=[a,{type:`null`}]},ss=(e,t,n,r)=>{let i=e._zod.def;B(i.innerType,t,r);let a=t.seen.get(e);a.ref=i.innerType},cs=Symbol();function ls(e,t,n,r,i){let a=!1,o=JSON.stringify(e,(e,t)=>typeof t==`bigint`?(a=!0,null):t);return a?(z(t,n,r,i,`BigInt defaults cannot be represented in JSON Schema`),cs):JSON.parse(o)}const us=(e,t,n,r)=>{let i=e._zod.def;B(i.innerType,t,r);let a=t.seen.get(e);a.ref=i.innerType;let o=ls(i.defaultValue,e,t,n,r);o!==cs&&(n.default=o)},ds=(e,t,n,r)=>{let i=e._zod.def;B(i.innerType,t,r);let a=t.seen.get(e);if(a.ref=i.innerType,t.io!==`input`)return;let o=ls(i.defaultValue,e,t,n,r);o!==cs&&(n._prefault=o)},fs=(e,t,n,r)=>{let i=e._zod.def;B(i.innerType,t,r);let a=t.seen.get(e);a.ref=i.innerType;let o;try{o=i.catchValue(void 0)}catch{z(e,t,n,r,`Dynamic catch values are not supported in JSON Schema`);return}n.default=o},ps=(e,t,n,r)=>{let i=e._zod.def,a=i.in._zod.traits.has(`$ZodTransform`),o=t.io===`input`?a?i.out:i.in:i.out;B(o,t,r);let s=t.seen.get(e);s.ref=o},ms=(e,t,n,r)=>{let i=e._zod.def;B(i.innerType,t,r);let a=t.seen.get(e);a.ref=i.innerType,n.readOnly=!0},hs=(e,t,n,r)=>{let i=e._zod.def;B(i.innerType,t,r);let a=t.seen.get(e);a.ref=i.innerType},gs=/* @__PURE__ */ new WeakSet([Object.prototype,Error.prototype]);function _s(e,t,n){Object.defineProperty(e,t,{configurable:!0,enumerable:!1,get(){let e=n(this);return Object.defineProperty(this,t,{value:e,configurable:!0,writable:!0}),e},set(e){Object.defineProperty(this,t,{value:e,configurable:!0,writable:!0})}})}const G=/*@__PURE__*/ j(`ZodError`,(e,t)=>{an.init(e,t),e.name=`ZodError`;let n=Object.getPrototypeOf(e);gs.has(n)||(gs.add(n),_s(n,`format`,e=>t=>cn(e,t)),_s(n,`flatten`,e=>t=>sn(e,t)),_s(n,`addIssue`,e=>t=>{e.issues.push(t),e.message=JSON.stringify(e.issues,$e,2)}),_s(n,`addIssues`,e=>t=>{e.issues.push(...t),e.message=JSON.stringify(e.issues,$e,2)}),Object.defineProperty(n,"isEmpty",{configurable:!0,enumerable:!1,get(){return this.issues.length===0}}))},void 0,{Parent:Error}),vs=/* @__PURE__ */ fn(G),ys=/* @__PURE__ */ pn(G),bs=/* @__PURE__ */ mn(G),xs=/* @__PURE__ */ gn(G),Ss=/* @__PURE__ */ Sn(G),Cs=/* @__PURE__ */ Cn(G),ws=/* @__PURE__ */ wn(G),Ts=/* @__PURE__ */ Tn(G),Es=/* @__PURE__ */ En(G),Ds=/* @__PURE__ */ Dn(G),Os=/* @__PURE__ */ On(G),ks=/* @__PURE__ */ kn(G);function As(){N.localeError||P(ma())}function js(){N.memoizer||P({memoizer:da()})}const K=/*@__PURE__*/ j(`ZodType`,(e,t)=>(As(),I.init(e,t),e.def=t,e.type=t.type,e),{check(...e){let t=this.def;return this.clone(x(t,{checks:[...t.checks??[],...e.map(e=>typeof e==`function`?{_zod:{check:e,def:{check:`custom`},onattach:[]}}:e)]}),{parent:!0})},with(...e){return this.check(...e)},clone(e,t){return C(this,e,t)},brand(){return this},register(e,t){return e.add(this,t),this},refine(e,t){return this.check(Wc(e,t))},superRefine(e,t){return this.check(Gc(e,t))},overwrite(e){return this.check(/* @__PURE__ */ R(e))},optional(){return Ec(this)},exactOptional(){return Oc(this)},nullable(){return Ac(this)},nullish(){return Ec(Ac(this))},nonoptional(e){return Ic(this,e)},array(){return fc(this)},or(e){return gc([this,e])},and(e){return vc(this,e)},transform(e){return Bc(this,wc(e))},default(e){return Mc(this,e)},prefault(e){return Pc(this,e)},catch(e){return Rc(this,e)},pipe(e){return Bc(this,e)},readonly(){return Hc(this)},describe(e){let t=this.clone();return va.add(t,{description:e}),t},meta(...e){if(e.length===0)return va.get(this);let t=this.clone();return va.add(t,e[0]),t},isOptional(){return this.safeParse(void 0).success},isNullable(){return this.safeParse(null).success},apply(e,...t){return t.length===0?e(this):e(this,...t)},get"~standard"(){return Bt(this,`~standard`,{...Or(this),jsonSchema:{input:Mo(this,`input`),output:Mo(this,`output`)}})},set"~standard"(e){O(this,`~standard`,e)},parse:function e(t,n){return vs(this,t,n,{callee:e})},parseAsync:async function e(t,n){return await ys(this,t,n,{callee:e})},safeParse(e,t){return bs(this,e,t)},async safeParseAsync(e,t){return xs(this,e,t)},get spa(){return this?.safeParseAsync},set spa(e){O(this,`spa`,e)},validate(e,t){return yn(this,e,t)},validateAsync(e,t){return xn(this,e,t)},encode:function e(t,n){return Ss(this,t,n,{callee:e})},decode:function e(t,n){return Cs(this,t,n,{callee:e})},encodeAsync:async function e(t,n){return await ws(this,t,n,{callee:e})},decodeAsync:async function e(t,n){return await Ts(this,t,n,{callee:e})},safeEncode(e,t){return Es(this,e,t)},safeDecode(e,t){return Ds(this,e,t)},async safeEncodeAsync(e,t){return Os(this,e,t)},async safeDecodeAsync(e,t){return ks(this,e,t)},toJSONSchema(e){return jo(this,{})(e)},get description(){return va.get(this)?.description},get _def(){return this._zod.def}}),Ms=/*@__PURE__*/ j(`_ZodString`,(e,t)=>{kr.init(e,t),K.init(e,t),e._zod.processJSONSchema=(t,n,r)=>Go(e,t,n,r)},/*@__PURE__*/ Vt({format:e=>W(e).format??null,minLength:e=>W(e).minimum??null,maxLength:e=>W(e).maximum??null},{regex(...e){return this.check(/* @__PURE__ */ io(...e))},includes(...e){return this.check(/* @__PURE__ */ so(...e))},startsWith(...e){return this.check(/* @__PURE__ */ co(...e))},endsWith(...e){return this.check(/* @__PURE__ */ lo(...e))},min(...e){return this.check(/* @__PURE__ */ no(...e))},max(...e){return this.check(/* @__PURE__ */ to(...e))},length(...e){return this.check(/* @__PURE__ */ ro(...e))},nonempty(...e){return this.check(/* @__PURE__ */ no(1,...e))},lowercase(e){return this.check(/* @__PURE__ */ ao(e))},uppercase(e){return this.check(/* @__PURE__ */ oo(e))},trim(){return this.check(/* @__PURE__ */ fo())},normalize(...e){return this.check(/* @__PURE__ */ uo(...e))},toLowerCase(){return this.check(/* @__PURE__ */ po())},toUpperCase(){return this.check(/* @__PURE__ */ mo())},slugify(){return this.check(/* @__PURE__ */ ho())}})),Ns=/*@__PURE__*/ j(`ZodString`,(e,t)=>{kr.init(e,t),Ms.init(e,t)},{email(e){return this.check(/* @__PURE__ */ xa(Rs,e))},url(e){return this.check(/* @__PURE__ */ Da(Vs,e))},jwt(e){return this.check(/* @__PURE__ */ Ha(rc,e))},emoji(e){return this.check(/* @__PURE__ */ Oa(Us,e))},guid(e){return this.check(/* @__PURE__ */ Sa(zs,e))},uuid(e){return this.check(/* @__PURE__ */ Ca(Bs,e))},uuidv4(e){return this.check(/* @__PURE__ */ wa(Bs,e))},uuidv6(e){return this.check(/* @__PURE__ */ Ta(Bs,e))},uuidv7(e){return this.check(/* @__PURE__ */ Ea(Bs,e))},nanoid(e){return this.check(/* @__PURE__ */ ka(Ws,e))},cuid(e){return this.check(/* @__PURE__ */ Aa(Gs,e))},cuid2(e){return this.check(/* @__PURE__ */ ja(Ks,e))},ulid(e){return this.check(/* @__PURE__ */ Ma(qs,e))},base64(e){return this.check(/* @__PURE__ */ za(ec,e))},base64url(e){return this.check(/* @__PURE__ */ Ba(tc,e))},xid(e){return this.check(/* @__PURE__ */ Na(Js,e))},ksuid(e){return this.check(/* @__PURE__ */ Pa(Ys,e))},ipv4(e){return this.check(/* @__PURE__ */ Fa(Xs,e))},ipv6(e){return this.check(/* @__PURE__ */ Ia(Zs,e))},cidrv4(e){return this.check(/* @__PURE__ */ La(Qs,e))},cidrv6(e){return this.check(/* @__PURE__ */ Ra($s,e))},e164(e){return this.check(/* @__PURE__ */ Va(nc,e))},datetime(e){return this.check(/* @__PURE__ */ Ua(Ps,e))},date(e){return this.check(/* @__PURE__ */ Wa(Fs,e))},time(e){return this.check(/* @__PURE__ */ Ga(Is,e))},duration(e){return this.check(/* @__PURE__ */ Ka(Ls,e))}});function q(e){return/* @__PURE__ */ ba(Ns,e)}const J=/*@__PURE__*/ j(`ZodStringFormat`,(e,t)=>{L.init(e,t),Ms.init(e,t)}),Ps=/*@__PURE__*/ j(`ZodISODateTime`,(e,t)=>{Jr.init(e,t),J.init(e,t)}),Fs=/*@__PURE__*/ j(`ZodISODate`,(e,t)=>{Yr.init(e,t),J.init(e,t)}),Is=/*@__PURE__*/ j(`ZodISOTime`,(e,t)=>{Xr.init(e,t),J.init(e,t)}),Ls=/*@__PURE__*/ j(`ZodISODuration`,(e,t)=>{Zr.init(e,t),J.init(e,t)}),Rs=/*@__PURE__*/ j(`ZodEmail`,(e,t)=>{Mr.init(e,t),J.init(e,t)}),zs=/*@__PURE__*/ j(`ZodGUID`,(e,t)=>{Ar.init(e,t),J.init(e,t)}),Bs=/*@__PURE__*/ j(`ZodUUID`,(e,t)=>{jr.init(e,t),J.init(e,t)}),Vs=/*@__PURE__*/ j(`ZodURL`,(e,t)=>{Br.init(e,t),J.init(e,t)});function Hs(e){return/* @__PURE__ */ Da(Vs,e)}const Us=/*@__PURE__*/ j(`ZodEmoji`,(e,t)=>{Vr.init(e,t),J.init(e,t)}),Ws=/*@__PURE__*/ j(`ZodNanoID`,(e,t)=>{Hr.init(e,t),J.init(e,t)}),Gs=/*@__PURE__*/ j(`ZodCUID`,(e,t)=>{Ur.init(e,t),J.init(e,t)}),Ks=/*@__PURE__*/ j(`ZodCUID2`,(e,t)=>{Wr.init(e,t),J.init(e,t)}),qs=/*@__PURE__*/ j(`ZodULID`,(e,t)=>{Gr.init(e,t),J.init(e,t)}),Js=/*@__PURE__*/ j(`ZodXID`,(e,t)=>{Kr.init(e,t),J.init(e,t)}),Ys=/*@__PURE__*/ j(`ZodKSUID`,(e,t)=>{qr.init(e,t),J.init(e,t)}),Xs=/*@__PURE__*/ j(`ZodIPv4`,(e,t)=>{Qr.init(e,t),J.init(e,t)}),Zs=/*@__PURE__*/ j(`ZodIPv6`,(e,t)=>{ti.init(e,t),J.init(e,t)}),Qs=/*@__PURE__*/ j(`ZodCIDRv4`,(e,t)=>{ni.init(e,t),J.init(e,t)}),$s=/*@__PURE__*/ j(`ZodCIDRv6`,(e,t)=>{ii.init(e,t),J.init(e,t)}),ec=/*@__PURE__*/ j(`ZodBase64`,(e,t)=>{si.init(e,t),J.init(e,t)}),tc=/*@__PURE__*/ j(`ZodBase64URL`,(e,t)=>{ui.init(e,t),J.init(e,t)}),nc=/*@__PURE__*/ j(`ZodE164`,(e,t)=>{di.init(e,t),J.init(e,t)}),rc=/*@__PURE__*/ j(`ZodJWT`,(e,t)=>{pi.init(e,t),J.init(e,t)}),ic=/*@__PURE__*/ j(`ZodNumber`,(e,t)=>{mi.init(e,t),K.init(e,t),e._zod.processJSONSchema=(t,n,r)=>Ko(e,t,n,r),e.isFinite=!0},/*@__PURE__*/ Vt({minValue:e=>{let{minimum:t,exclusiveMinimum:n}=W(e);return Math.max(t??-1/0,n??-1/0)},maxValue:e=>{let{maximum:t,exclusiveMaximum:n}=W(e);return Math.min(t??1/0,n??1/0)},isInt:e=>{let{isInt:t,multipleOf:n}=W(e);return!!t||!!n?.some(Number.isSafeInteger)},format:e=>W(e).format??null},{gt(e,t){return this.check(/* @__PURE__ */ Qa(e,t))},gte(e,t){return this.check(/* @__PURE__ */ $a(e,t))},min(e,t){return this.check(/* @__PURE__ */ $a(e,t))},lt(e,t){return this.check(/* @__PURE__ */ Xa(e,t))},lte(e,t){return this.check(/* @__PURE__ */ Za(e,t))},max(e,t){return this.check(/* @__PURE__ */ Za(e,t))},int(e){return this.check(oc(e))},safe(e){return this.check(oc(e))},positive(e){return this.check(/* @__PURE__ */ Qa(0,e))},nonnegative(e){return this.check(/* @__PURE__ */ $a(0,e))},negative(e){return this.check(/* @__PURE__ */ Xa(0,e))},nonpositive(e){return this.check(/* @__PURE__ */ Za(0,e))},multipleOf(e,t){return this.check(/* @__PURE__ */ eo(e,t))},step(e,t){return this.check(/* @__PURE__ */ eo(e,t))},finite(){return this}})),ac=/*@__PURE__*/ j(`ZodNumberFormat`,(e,t)=>{hi.init(e,t),ic.init(e,t)});function oc(e){return/* @__PURE__ */ qa(ac,e)}const sc=/*@__PURE__*/ j(`ZodUnknown`,(e,t)=>{gi.init(e,t),K.init(e,t),e._zod.processJSONSchema=(e,t,n)=>void 0});function cc(){return/* @__PURE__ */ Ja(sc)}const lc=/*@__PURE__*/ j(`ZodNever`,(e,t)=>{_i.init(e,t),K.init(e,t),e._zod.processJSONSchema=(t,n,r)=>qo(e,t,n,r)});function uc(e){return/* @__PURE__ */ Ya(lc,e)}const dc=/*@__PURE__*/ j(`ZodArray`,(e,t)=>{js(),xi.init(e,t),K.init(e,t),e._zod.processJSONSchema=(t,n,r)=>Zo(e,t,n,r),e.element=t.element},{min(e,t){return this.check(/* @__PURE__ */ no(e,t))},nonempty(e){return this.check(/* @__PURE__ */ no(1,e))},max(e,t){return this.check(/* @__PURE__ */ to(e,t))},length(e,t){return this.check(/* @__PURE__ */ ro(e,t))},unwrap(){return this.element}});function fc(e,t){return/* @__PURE__ */ go(dc,e,t)}const pc=/*@__PURE__*/ j(`ZodObject`,(e,t)=>{js(),Di.init(e,t),K.init(e,t),e._zod.processJSONSchema=(t,n,r)=>$o(e,t,n,r),Kt(e,`shape`,e=>e._zod.def.shape,!1)},{keyof(){return Sc(Object.keys(this._zod.def.shape))},catchall(e){return this.clone(x(this._zod.def,{catchall:e}))},passthrough(){return this.clone(x(this._zod.def,{catchall:cc()}))},loose(){return this.clone(x(this._zod.def,{catchall:cc()}))},strict(){return this.clone(x(this._zod.def,{catchall:uc()}))},strip(){return this.clone(x(this._zod.def,{catchall:void 0}))},extend(e){return wt(this,e)},safeExtend(e){return Et(this,e)},merge(e){return Dt(this,e)},pick(e){return xt(this,e)},omit(e){return Ct(this,e)},partial(...e){return Ot(Tc,this,e[0])},exactPartial(...e){return Ot(Dc,this,e[0],`exactPartial`)},required(...e){return kt(Fc,this,e[0])}});function mc(e,t){let n={type:`object`,shape:e??{},...w(t)};return new pc(n)}const hc=/*@__PURE__*/ j(`ZodUnion`,(e,t)=>{ki.init(e,t),K.init(e,t),e._zod.processJSONSchema=(t,n,r)=>es(e,t,n,r),e.options=t.options});function gc(e,t){return new hc({type:`union`,options:e,...w(t)})}const _c=/*@__PURE__*/ j(`ZodIntersection`,(e,t)=>{Ai.init(e,t),K.init(e,t),e._zod.processJSONSchema=(t,n,r)=>ts(e,t,n,r)});function vc(e,t){return new _c({type:`intersection`,left:e,right:t})}const yc=/*@__PURE__*/ j(`ZodRecord`,(e,t)=>{js(),Ni.init(e,t),K.init(e,t),e._zod.processJSONSchema=(t,n,r)=>as(e,t,n,r),e.keyType=t.keyType,e.valueType=t.valueType});function bc(e,t,n){return!t||!t._zod?new yc({type:`record`,keyType:q(),valueType:e,...w(t)}):new yc({type:`record`,keyType:e,valueType:t,...w(n)})}const xc=/*@__PURE__*/ j(`ZodEnum`,(e,t)=>{Pi.init(e,t),K.init(e,t),e._zod.processJSONSchema=(t,n,r)=>Jo(e,t,n,r),e.enum=t.entries,e.options=[...e._zod.values];let n=new Set(Object.keys(t.entries));e.extract=(e,r)=>{let i={};for(let r of e)if(n.has(r))i[r]=t.entries[r];else throw Error(`Key ${r} not found in enum`);return new xc({...t,checks:[],...w(r),entries:i})},e.exclude=(e,r)=>{let i={...t.entries};for(let t of e)if(n.has(t))delete i[t];else throw Error(`Key ${t} not found in enum`);return new xc({...t,checks:[],...w(r),entries:i})}});function Sc(e,t){let n=Array.isArray(e)?Object.fromEntries(e.map(e=>[e,e])):e;return new xc({type:`enum`,entries:n,...w(t)})}const Cc=/*@__PURE__*/ j(`ZodTransform`,(e,t)=>{js(),Fi.init(e,t),K.init(e,t),e._zod.processJSONSchema=(t,n,r)=>Xo(e,t,n,r),e._zod.parse=(n,r)=>{if(r.direction===`backward`)throw new Qt(e.constructor.name);n.addIssue=r=>{if(typeof r==`string`)n.issues.push(Rt(r,n.value,t));else{let t=r;t.fatal&&(t.continue=!1),t.code??=`custom`,`input`in t||(t.input=n.value),t.inst??=e,n.issues.push(Rt(t))}};let i=t.transform(n.value,n);return i instanceof Promise?i.then(e=>(n.value=e,n)):(n.value=i,n)}});function wc(e){return new Cc({type:`transform`,transform:e})}const Tc=/*@__PURE__*/ j(`ZodOptional`,(e,t)=>{Li.init(e,t),K.init(e,t),e._zod.processJSONSchema=(t,n,r)=>hs(e,t,n,r),e.unwrap=()=>e._zod.def.innerType});function Ec(e){return new Tc({type:`optional`,innerType:e})}const Dc=/*@__PURE__*/ j(`ZodExactOptional`,(e,t)=>{Ri.init(e,t),K.init(e,t),e._zod.processJSONSchema=(t,n,r)=>hs(e,t,n,r),e.unwrap=()=>e._zod.def.innerType});function Oc(e){return new Dc({type:`optional`,innerType:e})}const kc=/*@__PURE__*/ j(`ZodNullable`,(e,t)=>{zi.init(e,t),K.init(e,t),e._zod.processJSONSchema=(t,n,r)=>os(e,t,n,r),e.unwrap=()=>e._zod.def.innerType});function Ac(e){return new kc({type:`nullable`,innerType:e})}const jc=/*@__PURE__*/ j(`ZodDefault`,(e,t)=>{Bi.init(e,t),K.init(e,t),e._zod.processJSONSchema=(t,n,r)=>us(e,t,n,r),e.unwrap=()=>e._zod.def.innerType,e.removeDefault=e.unwrap});function Mc(e,t){return new jc({type:`default`,innerType:e,get defaultValue(){return typeof t==`function`?t():mt(t)}})}const Nc=/*@__PURE__*/ j(`ZodPrefault`,(e,t)=>{Hi.init(e,t),K.init(e,t),e._zod.processJSONSchema=(t,n,r)=>ds(e,t,n,r),e.unwrap=()=>e._zod.def.innerType});function Pc(e,t){return new Nc({type:`prefault`,innerType:e,get defaultValue(){return typeof t==`function`?t():mt(t)}})}const Fc=/*@__PURE__*/ j(`ZodNonOptional`,(e,t)=>{Ui.init(e,t),K.init(e,t),e._zod.processJSONSchema=(t,n,r)=>ss(e,t,n,r),e.unwrap=()=>e._zod.def.innerType});function Ic(e,t){return new Fc({type:`nonoptional`,innerType:e,...w(t)})}const Lc=/*@__PURE__*/ j(`ZodCatch`,(e,t)=>{Ki.init(e,t),K.init(e,t),e._zod.processJSONSchema=(t,n,r)=>fs(e,t,n,r),e.unwrap=()=>e._zod.def.innerType,e.removeCatch=e.unwrap});function Rc(e,t){return new Lc({type:`catch`,innerType:e,catchValue:typeof t==`function`?t:qt(t)})}const zc=/*@__PURE__*/ j(`ZodPipe`,(e,t)=>{qi.init(e,t),K.init(e,t),e._zod.processJSONSchema=(t,n,r)=>ps(e,t,n,r),e.in=t.in,e.out=t.out});function Bc(e,t){return new zc({type:`pipe`,in:e,out:t})}const Vc=/*@__PURE__*/ j(`ZodReadonly`,(e,t)=>{Yi.init(e,t),K.init(e,t),e._zod.processJSONSchema=(t,n,r)=>ms(e,t,n,r),e.unwrap=()=>e._zod.def.innerType});function Hc(e){return new Vc({type:`readonly`,innerType:e})}const Uc=/*@__PURE__*/ j(`ZodCustom`,(e,t)=>{Zi.init(e,t),K.init(e,t),e._zod.processJSONSchema=(t,n,r)=>Yo(e,t,n,r)});function Wc(e,t={}){return/* @__PURE__ */ _o(Uc,e,t)}function Gc(e,t){return/* @__PURE__ */ vo(e,t)}const Kc=mc({darwinArm64:mc({platform:q(),arch:q(),pythonVersion:q().regex(/^\d+\.\d+\.\d+$/u,`pythonVersion 必须是三段数字的版本号`),release:q(),url:Hs(),sha256:q().regex(/^[0-9a-f]{64}$/u,`sha256 必须是 64 位小写十六进制`),sizeBytes:oc().positive()}),unsupported:bc(q(),q())}),qc=r(g.join(import.meta.dirname,`runtime-manifest.json`))?import.meta.dirname:g.resolve(import.meta.dirname,`..`);function Jc(e){let t;try{t=JSON.parse(e)}catch(e){throw Error(`runtime-manifest.json is invalid: ${String(e)}`,{cause:e})}let n=Kc.safeParse(t);if(!n.success)throw Error(`runtime-manifest.json is invalid: ${un(n.error)}`);return n.data}const Yc=Jc(i(g.join(qc,`runtime-manifest.json`),`utf8`));function Xc(e){return g.join(e,`runtime`,`python`,Yc.darwinArm64.pythonVersion,`bin`,`python3`)}function Zc(e){try{return a(e).isFile()?(t(e,n.X_OK),!0):!1}catch{return!1}}function Qc(e){return process.platform===`win32`?g.join(e,`_env`,`.venv`,`Scripts`,`python.exe`):g.join(e,`_env`,`.venv`,`bin`,`python`)}function $c(e){let t=e.pythonBin.trim();if(t.length>0)return{pythonPath:t,via:`configured`,version:`unknown`};if(process.platform===`darwin`&&process.arch===`arm64`&&e.dataDir.length>0){let t=Xc(e.dataDir);if(Zc(t))return{pythonPath:t,via:`managed`,version:Yc.darwinArm64.pythonVersion}}let n=Qc(e.repoRoot);return Zc(n)?{pythonPath:n,via:`repo`,version:`unknown`}:{pythonPath:process.platform===`win32`?`python`:`python3`,via:`path`,version:`unknown`}}function Y(e){return typeof e==`object`&&!!e&&!Array.isArray(e)}const el=`state.json`,tl=/No matching distribution|Could not find a version/iu,nl=/Network|Temporary failure|Connection|timed out/iu;function rl(){return process.platform===`darwin`&&process.arch===`arm64`}const il=/* @__PURE__ */ new Set([`Chromium`,`chrome`,`chrome.exe`,`Google Chrome for Testing`]);var X=class extends Error{code;constructor(e,t,n){super(t,n),this.name=`InstallError`,this.code=e}};function al(e){return Y(e)&&typeof e.code==`string`?e.code:void 0}async function ol(e,t={}){return new Promise(n=>{let r=ie(e[0]??``,e.slice(1),{env:{...process.env,...t.env},stdio:[`ignore`,`pipe`,`pipe`]}),i=``,a=``;r.stdout.on(`data`,e=>{i+=e.toString(`utf8`)}),r.stderr.on(`data`,e=>{a+=e.toString(`utf8`)}),r.on(`error`,e=>{n({code:null,stdout:i,stderr:`${a}${String(e)}`})}),r.on(`close`,e=>{n({code:e,stdout:i,stderr:a})})})}function sl(e){return async t=>{let n=g.join(te.tmpdir(),`dsh-scrapling-dl-${re()}`),r=await e([`curl`,`--fail`,`--location`,`--silent`,`--show-error`,`--output`,n,t]);if(r.code===0)try{return new Uint8Array(await d(n))}finally{await m(n,{force:!0})}if(await m(n,{force:!0}),r.code!==null)throw new X(`INSTALL_NETWORK`,`curl failed for ${t}: ${r.stderr.slice(0,400)}`);let i=await fetch(t);if(!i.ok)throw new X(`INSTALL_NETWORK`,`${t} answered HTTP ${i.status}`);return new Uint8Array(await i.arrayBuffer())}}const cl={download:sl(ol),extract:async(e,t)=>{let n=await ol([`tar`,`-xzf`,e,`-C`,t]);if(n.code!==0)throw new X(`INSTALL_FAILED`,`tar failed: ${n.stderr.slice(0,400)}`)},spawn:ol};async function Z(e){try{return await o(e,n.F_OK),!0}catch{return!1}}function ll(t=e(import.meta.url)){let n;try{n=t(`fs-native-extensions`)}catch{n=void 0}if(Y(n)){let e=n.tryLock,t=n.unlock;if(typeof e==`function`&&typeof t==`function`)return{tryLock:t=>!!e.call(n,t),unlock:e=>{t.call(n,e)}}}return null}const ul=ll();function dl(e,t=ul){if(t===null)throw new X(`INSTALL_LOCK_UNREADABLE`,`fs-native-extensions is not loadable`);try{return t.tryLock(e)}catch(e){throw new X(`INSTALL_LOCK_UNREADABLE`,`cannot lock install fd: ${String(e)}`)}}async function fl(e,t=ul){let n;try{n=await u(e,`a+`)}catch(t){throw new X(`INSTALL_LOCK_UNREADABLE`,`cannot open install lock ${e}: ${String(t)}`)}if(!dl(n.fd,t))throw await n.close(),new X(`INSTALL_BUSY`,`another install holds ${e}`);return{release:async()=>{try{t?.unlock(n.fd)}catch{}await n.close()}}}const pl=/* @__PURE__ */ new Map;function ml(e,t){t<=1?pl.delete(e):pl.set(e,t-1)}async function hl(e){let t=g.join(e,`runtime`);return await l(t,{recursive:!0}),process.platform!==`win32`&&await s(t,448),t}async function Q(e,t){let n=g.join(e,`runtime`),r=g.join(n,`install.lock`),i=g.resolve(r),a=pl.get(i)??0;if(a>0){pl.set(i,a+1);try{return await t()}finally{ml(i,a+1)}}await hl(e);let o=await fl(r);pl.set(i,1);try{return await t()}finally{ml(i,1),await o.release()}}async function gl(e,t){if(!URL.canParse(t))throw new X(`INSTALL_OFFLINE_ASSETS`,`manifest archive URL is not parseable: ${t}`);let n=g.basename(new URL(t).pathname),r;try{r=decodeURIComponent(n)}catch{throw new X(`INSTALL_OFFLINE_ASSETS`,`manifest archive name has invalid percent-encoding: ${n}`)}let i=n===r?[n]:[r,n],a=(await Promise.all(i.map(async t=>({name:t,bytes:await d(g.join(e,t)).catch(()=>null)})))).find(e=>e.bytes!==null)?.bytes;if(a==null)throw new X(`INSTALL_OFFLINE_ASSETS`,`offline python archive missing under ${e}: expected ${i.join(` or `)}`);return new Uint8Array(a)}async function _l(e,t,n,r){return Q(t,async()=>{let i=g.join(t,`runtime`,`.tmp`,re());await l(i,{recursive:!0});let a=g.join(i,`python.tar.gz`);try{let o=r===void 0?await n.download(e.url):await gl(r,e.url),s=ne(`sha256`).update(o).digest(`hex`);if(s!==e.sha256)throw new X(`INSTALL_HASH_MISMATCH`,`python archive hash ${s} does not match ${e.sha256}`);await ee(a,o);let u=g.join(i,`extract`);await l(u,{recursive:!0}),await n.extract(a,u);let d=g.join(u,`python`),f=await Z(g.join(d,`bin`,`python3`))?d:u,p=g.dirname(g.dirname(Xc(t)));await m(p,{recursive:!0,force:!0}),await l(g.dirname(p),{recursive:!0}),await c(f,p,{recursive:!0,dereference:!0});let h=Xc(t);if(!await Z(h))throw new X(`INSTALL_FAILED`,`python archive did not contain bin/python3`);return{pythonPath:h,version:e.pythonVersion}}finally{await m(i,{recursive:!0,force:!0}),await h(g.join(t,`runtime`,`.tmp`)).catch(()=>null)}})}async function vl(e){let t=g.join(e,`runtime`,el),n;try{n=await d(t,`utf8`)}catch(e){if(al(e)===`ENOENT`)return{packs:{}};throw new X(`INSTALL_STATE_CORRUPT`,`cannot read ${t}: ${String(e)}; delete it and install again`,{cause:e})}let r;try{r=JSON.parse(n)}catch(e){throw new X(`INSTALL_STATE_CORRUPT`,`${t} is not valid JSON; delete it and install again`,{cause:e})}if(!Y(r))throw new X(`INSTALL_STATE_CORRUPT`,`${t} does not hold a JSON object; delete it and install again`);return r}async function yl(e,t){let n=await hl(e),r=g.join(n,el),i=`${r}.${re()}.tmp`;try{await ee(i,JSON.stringify(t,null,2),`utf8`),await p(i,r)}finally{try{await m(i,{force:!0})}catch{}}}async function bl(e,t,n,r=e=>d(e,`utf8`)){let i=g.join(e,`bin`),a=`#!${t}/`,o=(await f(i,{withFileTypes:!0}).catch(()=>[])).filter(e=>e.isFile()).map(e=>g.join(i,e.name));await Promise.all(o.map(async e=>{let t=await r(e).catch(()=>``),i=t.indexOf(`
|
|
118
|
-
`),o=i===-1?t:t.slice(0,i);if(!o.startsWith(a))return;let s=i===-1?``:t.slice(i);await ee(e,`#!${n}/${o.slice(a.length)}${s}`,`utf8`)}))}async function xl(e,t){let n=!1;if(t){try{await m(e.venv,{recursive:!0,force:!0})}catch{}try{await p(e.previousVenv,e.venv)}catch{n=!0}}if(!n)try{await m(e.previousVenv,{recursive:!0,force:!0})}catch{}try{await m(e.staging,{recursive:!0,force:!0})}catch{}}async function Sl(e){let{io:t}=e;await Q(e.dataDir,async()=>{let n=await hl(e.dataDir),r=g.join(n,`venv`),i=g.join(n,`.tmp`,`venv-${re()}`),a=g.join(n,`.tmp`,`venv-previous-${re()}`),o=g.join(e.repoRoot,`py`,`runtime-requirements.txt`),s=!1,c=!1;try{let n=await t.spawn([e.pythonPath,`-m`,`venv`,i]);if(n.code!==0)throw new X(`INSTALL_FAILED`,`venv failed: ${n.stderr.slice(0,400)}`);let l=g.join(i,`bin`,`python3`),u=e.assets===void 0?[]:[`--no-index`,`--find-links`,g.join(e.assets,`wheels`)],d=await t.spawn([l,`-m`,`pip`,`install`,`--only-binary=:all:`,`--require-hashes`,`-r`,o,...u],{env:{PIP_DISABLE_PIP_VERSION_CHECK:`1`}});if(d.code!==0){let e=`${d.stdout}\n${d.stderr}`;throw tl.test(e)?new X(`INSTALL_NO_WHEEL`,`a dependency has no wheel for this platform`):nl.test(e)?new X(`INSTALL_NETWORK`,`pip could not reach the package index`):new X(`INSTALL_FAILED`,`pip failed: ${d.stderr.slice(0,400)}`)}await bl(i,i,r);try{await Z(r)&&(await p(r,a),s=!0),await p(i,r)}catch(e){throw new X(`INSTALL_FAILED`,`cannot replace ${r}: ${String(e)}`,{cause:e})}let f=await vl(e.dataDir),m={...Y(f.packs)?f.packs:{},core:`ready`};await yl(e.dataDir,{...f,packs:m,python:e.pythonPath}),c=!0}finally{await xl({venv:r,previousVenv:a,staging:i},s&&!c)}})}async function Cl(e){try{return(await f(e,{recursive:!0})).some(e=>il.has(g.basename(e)))}catch{return!1}}async function wl(e){return Cl(g.join(e,`runtime`,`browsers`))}async function Tl(e){let{io:t}=e;return Q(e.dataDir,async()=>{let n=g.join(e.dataDir,`runtime`,`browsers`);await l(n,{recursive:!0});let r=await t.spawn([e.pythonPath,`-m`,`patchright`,`install`,`chromium`],{env:{PLAYWRIGHT_BROWSERS_PATH:n}});if(r.code!==0)throw new X(`INSTALL_BROWSER_FAILED`,`chromium install failed: ${r.stderr.slice(0,400)}`);if(!await Cl(n))throw new X(`INSTALL_BROWSER_FAILED`,`no chromium executable found under ${n}`);let i=await vl(e.dataDir),a={...Y(i.packs)?i.packs:{},browser:`ready`};return await yl(e.dataDir,{...i,packs:a,browsersPath:n}),{browsersPath:n}})}function El(e,t){return e===`ready`?t?`ready`:`corrupt`:`missing`}async function Dl(e,t){if(!rl())return{core:`blocked`,browser:`blocked`,search:`blocked`,media:`blocked`,"adaptive-redis":`blocked`,mcp:`blocked`};let n=(await vl(e)).packs,r=Y(n)?n:{},i=El(r.core,await Z(g.join(e,`runtime`,`venv`,`bin`,`python3`))),a={core:i,browser:El(r.browser,await wl(e)),search:i,media:i,"adaptive-redis":i,mcp:i};return t!==void 0&&(a[t]=`installing`),a}function Ol(e){if(e?.aborted===!0)throw new X(`INSTALL_FAILED`,`install cancelled`)}async function kl(e,t,n,r,i){let a=Xc(e);return await Z(a)?a:(Ol(n),(await _l(r,e,t,i)).pythonPath)}async function Al(e,t){if(!rl())throw new X(`INSTALL_PACK_BLOCKED`,`runtime packs are verified on macOS arm64 only; this host is ${process.platform}/${process.arch}`);let{dataDir:n,repoRoot:r,io:i,signal:a,onProgress:o,assets:s}=t,c=t.asset??Yc.darwinArm64;if(s!==void 0&&!await Z(g.join(s,`wheels`)))throw new X(`INSTALL_OFFLINE_ASSETS`,`offline wheelhouse missing: ${g.join(s,`wheels`)}`);Ol(a),o?.(`installing ${e}`);let l=await kl(n,i,a,c,s);Ol(a),o?.(`installing core packages into ${l}`),await Sl({pythonPath:l,dataDir:n,repoRoot:r,io:i,...s===void 0?{}:{assets:s}}),Ol(a),e===`browser`&&(o?.(`installing full chromium`),await Tl({pythonPath:g.join(n,`runtime`,`venv`,`bin`,`python3`),dataDir:n,io:i}),Ol(a)),o?.(`${e} ready`)}const jl=Al;async function Ml(e,t){await Q(t.dataDir,async()=>{let n=g.join(t.dataDir,`runtime`),r=e===`browser`?`browsers`:`venv`;await m(g.join(n,r),{recursive:!0,force:!0}),t.purge&&(await Promise.all([``,`-wal`,`-shm`].map(e=>m(g.join(t.dataDir,`elements_storage.db${e}`),{force:!0}))),await m(g.join(t.dataDir,`downloads`),{recursive:!0,force:!0}));let i=await vl(t.dataDir);if(!Y(i.packs))return;let a={...i.packs};Reflect.deleteProperty(a,e),await yl(t.dataDir,{...i,packs:a})})}const Nl=/\r\n|\n|\r/u,Pl=/[\t ]#.*$/u,Fl=/* @__PURE__ */ new Set([`core`,`browser`,`search`,`media`,`adaptive-redis`,`mcp`]),Il=/* @__PURE__ */ new Set([`setup`,`doctor`]),Ll=/* @__PURE__ */ new Set([`status`,`apply`,`repair`,`purge`,`dry-run`,`with-auth`,`accept-risk`]),Rl=/* @__PURE__ */ new Set([`port`,`mode`,`profile`,`offline`,`uninstall`,`feature`]);function zl(){let e=process.env.DSH_SCRAPLING_DATA_DIR;return e===void 0||e===``?g.join(te.homedir(),`.dsh-scrapling`):g.resolve(e)}function Bl(e){return Fl.has(e)}function Vl(e,t){if(!e.startsWith(`--`))return{kind:`invalid`};let n=e.slice(2);return Ll.has(n)?{kind:`boolean`,name:n}:!Rl.has(n)||t===void 0||t.startsWith(`--`)?{kind:`invalid`}:{kind:`value`,name:n,value:t}}function Hl(e){let[t,...n]=e;if(t===void 0||!Il.has(t))return null;let r=/* @__PURE__ */ new Map,i=/* @__PURE__ */ new Set;for(let[e,t]of n.entries())if(!i.has(e)){let a=Vl(t,n[e+1]);if(a.kind===`invalid`)return null;r.set(a.name,a.kind!==`value`||a.value),a.kind===`value`&&i.add(e+1)}return{command:t,flags:r}}function Ul(e){return{io:cl,dataDir:zl(),repoRoot:g.resolve(import.meta.dirname,`..`),log:e=>{console.info(e)},installPackFn:Al,repairPackFn:jl,uninstallPackFn:Ml,...e}}function $(e,t){let n=e.get(t);return typeof n==`string`?n:void 0}function Wl(e){let t=$(e,`port`);if(t===void 0)return{invalid:!1};let n=Number(t);return Number.isInteger(n)&&n>0&&n<=65535?{port:n,invalid:!1}:{invalid:!0}}function Gl(e){let t=$(e,`mode`);return t===void 0||!pe(t)?null:t}function Kl(e){let t=$(e,`mode`),n=t===void 0?`(缺省)`:JSON.stringify(t);return`--mode 要写 ${de.join(` / `)} 之一;现在给的是 ${n}`}function ql(e){if(e.mode===`native`)return{text:Je(),note:`native 模式不留 dsh-mcp-client 条目:原生工具已经在宿主名册里,再端一份就是两套。`,install:``};if(e.mode===`mcp`){let t=e.withAuth?`Authorization 在宿主装载时从宿主进程环境的 ${ce} 求值:变量缺席会写成 "Bearer undefined",加鉴权前先确认宿主环境里已设置它。`:``;return{text:qe({port:e.port,withAuth:e.withAuth}),note:`mcp 模式起的是本插件的 server,URL 里的端口要与部署项 mcpPort 同值(当前按 ${String(e.port)} 生成)。${t}`,install:he()}}let t=Se({dataDir:e.dataDir,enabled:e.enabled,acceptedRisk:e.acceptRisk});return{text:t.patch,note:t.risk,install:t.installCommand}}async function Jl(e,t){await l(g.dirname(e),{recursive:!0}),await ee(e,t,`utf8`)}async function Yl(e,t){let n=Gl(e);if(n===null)return t.log(Kl(e)),2;let i=Wl(e);if(i.invalid)return t.log(`--port 要写 1 到 65535 之间的整数;现在给的是 ${String($(e,`port`))}`),2;let a=i.port??39217,o=$(e,`profile`),s=o===void 0?void 0:await Ge(o),c=ql({mode:n,port:a,withAuth:e.has(`with-auth`),acceptRisk:e.has(`accept-risk`),dataDir:t.dataDir,enabled:s?.officialMcpEnabled===!0});t.log(c.text),t.log(c.note),c.install!==``&&(t.log(`客户端没装就先跑:${c.install}`),t.log(`只接受 ${ue.join(` 或 `)}:npm 的 latest 比宿主线旧,宿主拒绝装载不匹配的对端。`));let l=g.join(t.dataDir,`mcp`,Ke(n));if(n===`official-mcp`){let e=_e(t.dataDir);r(e)||t.log(`${e} 现在还不存在:先跑 setup --feature mcp --apply 把官方 server 装进托管 venv;在那之前这条条目连不上(failOnStartupError: true 会让宿主把这条报成红)。`)}return!e.has(`apply`)||e.has(`dry-run`)?(t.log(`dry-run; add --apply to write ${l}`),0):(await Jl(l,c.text),t.log(`wrote ${l}`),t.log(`profile 不会被这条命令改写:把这段并进 <profile>/cordis.patch.yml,再重启宿主。`),0)}function Xl(e){let t=e.trim(),n=t.charAt(0);if(n===`"`||n===`'`){let e=t.indexOf(n,1);if(e>0)return t.slice(1,e)}return t.replace(Pl,``).trim()}function Zl(e,t){let n=RegExp(`^[\\t ]*(?:-[\\t ]+)?${t}:(?<value>[^\\r\\n]*)$`,`u`);return e.split(Nl).filter(e=>!e.trimStart().startsWith(`#`)).map(e=>Xl(n.exec(e)?.groups?.value??``)).find(e=>e!==``)}function Ql(e,t){return Zl(e,t)!==void 0}function $l(e,t){let n=Zl(e,t);return n===`true`||n===`True`||n===`TRUE`}async function eu(e){let t=$(e,`profile`);if(t===void 0)return{profile:{path:null,pythonBin:null,note:`未读 profile:runtime 只按 CLI 自身的解析链(pythonBin 配置 → 托管 runtime → 仓内 _env/.venv → PATH python3);要看部署配置解析出的解释器就加 --profile <目录>`},pythonBin:``};let n=Zl((await Ge(t)).patchText,`pythonBin`)??``;return{profile:n===``?{path:t,pythonBin:null,note:`profile 里没有 scrapling 的 pythonBin:runtime 回落到 CLI 自身的解析链(托管 runtime → 仓内 _env/.venv → PATH python3)`}:{path:t,pythonBin:n},pythonBin:n}}async function tu(e,t){let{profile:n,pythonBin:r}=await eu(e),i=$c({pythonBin:r,dataDir:t.dataDir,repoRoot:t.repoRoot}),a=await vl(t.dataDir),o=await Dl(t.dataDir);return t.log(JSON.stringify({dataDir:t.dataDir,profile:n,runtime:i,packs:o,state:a},null,2)),0}const nu={tavily:`tavilyApiKey`,brave:`braveApiKey`,serper:`serperApiKey`,searxng:`searxngEndpoint`};function ru(e){return e===void 0||Xe(e)?[]:[{code:`SEARCH_BACKEND_INVALID`,detail:`searchBackend=${e} 不是本包实现的后端:可写的取值是 ${Ye.join(` / `)},删掉这一行即回到 auto。`}]}function iu(e,t){let n=Zl(e,`searchProvider`),r=Zl(e,`searchBackend`),i=r??`auto`,a=$l(e,`searchPublicFallback`),o=Ql(e,`tavilyApiKey`),s=Ql(e,`searxngEndpoint`),c=i===`auto`&&!o&&!s&&!a,l=i===`auto`?void 0:nu[i],u=l!==void 0&&!Ql(e,l),d=n===`scrapling`,f=[],p=[];return n===void 0&&f.push(`SEARCH_PROVIDER_NOT_CONFIGURED 部署配置里还没写 searchProvider: scrapling:内置 web_search 仍走宿主自己选的 provider(base 层默认 deepseek-official),本插件的 search provider 只是备选。要接管它,给 <profile>/cordis.patch.yml 里 - id: web 的 config 加一行 searchProvider: scrapling,再重启宿主。`),c&&!d&&f.push(`SEARCH_BACKEND_MISSING 搜索后端未配置(预期行为):searchBackend=auto 但没配 tavilyApiKey、也没设 searxngEndpoint,且 searchPublicFallback=false,所以本插件的 search provider 不可用。修复:配 tavilyApiKey、设 searxngEndpoint,或显式把 searchPublicFallback 设为 true(会把查询词发给公共引擎)。`),u&&!d&&f.push(`SEARCH_AUTH searchBackend=${i} 但 ${l} 没配:查询会报 SEARCH_AUTH。修复:配 ${l},或换一个后端。`),p.push(...ru(r)),d&&!t&&p.push({code:`WEB_PROVIDER_CONFIGURED_UNAVAILABLE`,detail:`searchProvider 已指向 scrapling,但能力包没装好(core venv 不在 ready):web_search 会报 WEB_PROVIDER_CONFIGURED_UNAVAILABLE。修复:dsh-scrapling setup --feature core --apply。`}),d&&c&&p.push({code:`WEB_PROVIDER_CONFIGURED_UNAVAILABLE`,detail:`searchProvider 已指向 scrapling,但搜索后端不可用(没配 key/SearXNG,且 searchPublicFallback=false):web_search 会报 WEB_PROVIDER_CONFIGURED_UNAVAILABLE。修复:配 tavilyApiKey、设 searxngEndpoint,或显式打开 searchPublicFallback。`}),d&&u&&p.push({code:`SEARCH_AUTH`,detail:`searchBackend=${i} 但 ${l} 没配:provider 会注册成功,而每次查询都会报 SEARCH_AUTH。修复:配 ${l},或换一个后端。`}),{hints:f,findings:p}}async function au(e,t){let n=Gl(e);if(n===null)return t.log(Kl(e)),2;let r=$(e,`profile`);if(r===void 0)return t.log(`doctor 要 --profile <目录>:判据来自那份 profile 自己写下的 cordis.patch.yml。`),2;let i=Wl(e);if(i.invalid)return t.log(`--port 要写 1 到 65535 之间的整数;现在给的是 ${String($(e,`port`))}`),2;let a=await Ge(r),o=await Dl(t.dataDir),s=Re({mode:n,expectedPort:i.port,...a}),c=iu(a.patchText,o.core===`ready`);for(let e of c.hints)t.log(e);for(let e of s)t.log(`${e.code} ${e.detail}`);for(let e of c.findings)t.log(`${e.code} ${e.detail}`);let l=s.length+c.findings.length;return l===0?(t.log(`${r} 与 integrationMode=${n} 一致。`),0):(t.log(s.length>0?`${String(l)} 处不一致:改完重跑 setup --mode ${n} --apply,并把条目并进 profile 后重启宿主。`:`${String(l)} 处搜索配置不一致:按上面逐条的修复动作改 ${r} 里 web 条目的 config,重启宿主生效。`),1)}async function ou(e,t){let n=e.get(`uninstall`);if(typeof n!=`string`||!Bl(n))return 2;let r=e.has(`purge`);return t.log(`uninstall ${n}${r?` (and purge user data)`:``} from ${g.join(t.dataDir,`runtime`)}`),!e.has(`apply`)||e.has(`dry-run`)?(t.log(e.has(`dry-run`)?`dry-run:--dry-run 压过 --apply,只打印计划,不删任何 runtime 文件`:`dry-run; add --apply to uninstall`),0):(await Q(t.dataDir,async()=>{await t.uninstallPackFn(n,{dataDir:t.dataDir,purge:r})}),t.log(`uninstalled ${n}${r?` (purged data)`:``}`),0)}function su(e,t){let n=Yc.darwinArm64;return[`python ${n.pythonVersion} (${n.sizeBytes} bytes)`,e===`browser`?`full Chromium (~583M)`:`core wheels (~327M)`,`into ${g.join(t.dataDir,`runtime`)}`].join(`
|
|
119
|
-
`)}async function cu(e,t,n,r){await(n?t.repairPackFn:t.installPackFn)(e,{dataDir:t.dataDir,repoRoot:t.repoRoot,io:t.io,onProgress:t.log,...r===void 0?{}:{assets:r}})}async function lu(e,t){let n=e.get(`feature`);if(typeof n!=`string`||!
|
|
117
|
+
Set the \`cycles\` parameter to \`"ref"\` to resolve cyclical schemas with defs.`)}for(let n of e.seen.entries()){let r=n[1];if(t===n[0])a(n);else{if(e.external){let r=e.external.registry.get(n[0])?.id;if(t!==n[0]&&r){a(n);continue}}(e.metadataRegistry.get(n[0])?.id||r.cycle||r.count>1&&e.reused===`ref`)&&a(n)}}e.external&&(e.sharedDefsExtractedFor=e.external)}function wo(e){let t=e.anyOf;if(!Array.isArray(t)||t.length===0||e.type!==void 0)return;let n=[];for(let e of t){if(!e||typeof e!=`object`)return;wo(e);let t=Object.keys(e);if(t.length!==1||t[0]!==`type`)return;let r=e.type;for(let e of Array.isArray(r)?r:[r]){if(typeof e!=`string`)return;n.includes(e)||n.push(e)}}delete e.anyOf,e.type=n.length===1?n[0]:n}const To=/* @__PURE__ */ new Set([`type`,`properties`,`required`,`additionalProperties`]),Eo=[`oneOf`,`anyOf`];function Do(e){let t=e.additionalProperties;return t===void 0||t===!1||typeof t!=`object`||!t?null:Object.keys(t).length?t:null}function Oo(e){let t=[];for(let n of e){if(typeof n!=`object`||n.type!==`object`)return null;for(let e in n)if(!To.has(e))return null;t.push(n)}let n={},r=/* @__PURE__ */ new Set;for(let e of t){for(let r in e.properties){if(Object.prototype.hasOwnProperty.call(n,r))continue;let e=[];for(let n of t){let t=n.properties?.[r]??Do(n);t!=null&&(e.some(e=>JSON.stringify(e)===JSON.stringify(t))||e.push(t))}v(n,r,e.length===1?e[0]:Oo(e)??{allOf:e})}for(let t of e.required??[])r.add(t)}let i={type:`object`,properties:n};if(r.size&&(i.required=[...r]),t.every(e=>e.additionalProperties===!1))i.additionalProperties=!1;else{let e=[];for(let n of t){let t=Do(n);t&&!e.some(e=>JSON.stringify(e)===JSON.stringify(t))&&e.push(t)}e.length===1?i.additionalProperties=e[0]:e.length>1&&(i.additionalProperties={allOf:e})}return i}function ko(e){let t=e.allOf;if(!Array.isArray(t)||t.length<2)return;for(let t of To)if(t in e)return;let n=t.filter(e=>Eo.some(t=>Array.isArray(e[t]))),r=null;if(!n.length)r=Oo(t);else{let e=n[0],i=Eo.find(t=>Array.isArray(e[t]));if(Object.keys(e).length!==1)return;let a=t.filter(t=>t!==e),o=e[i].map(e=>Oo([...a,e]));if(o.some(e=>!e))return;r={[i]:o}}r&&(delete e.allOf,bo(e,r))}function Ao(e,t){let n=e.seen.get(t);if(!n)throw Error(`Unprocessed schema. This is a bug in Zod.`);let r=t=>{let n=e.seen.get(t);if(n.ref===null)return;let i=n.def??n.schema,a={...i},o=n.ref;if(n.ref=null,o){r(o);let n=e.seen.get(o),s=n.schema;if(s.$ref&&(e.target===`draft-07`||e.target===`draft-04`||e.target===`openapi-3.0`)?(i.allOf=i.allOf??[],i.allOf.push(s)):bo(i,s),bo(i,a),t._zod.parent===o)for(let e in i)e!==`$ref`&&e!==`allOf`&&(e in a||delete i[e]);if(s.$ref&&n.def)for(let e in i)e!==`$ref`&&e!==`allOf`&&e in n.def&&JSON.stringify(i[e])===JSON.stringify(n.def[e])&&delete i[e]}let s=t._zod.parent;if(s&&s!==o){r(s);let t=e.seen.get(s);if(t?.schema.$ref&&(i.$ref=t.schema.$ref,t.def))for(let e in i)e!==`$ref`&&e!==`allOf`&&e in t.def&&JSON.stringify(i[e])===JSON.stringify(t.def[e])&&delete i[e]}e.override({zodSchema:t,jsonSchema:i,path:n.path??[]})};if(!e.external||e.sharedEmitDoneFor!==e.external){for(let t of[...e.seen.entries()].reverse())r(t[0]);if(e.target!==`openapi-3.0`)for(let t of e.seen.entries())wo(t[1].def??t[1].schema);for(let t of e.deferred)t();if(e.intersections.length){let t=/* @__PURE__ */ new Map;for(let n of e.seen.values())for(let e of[n.schema,n.def]){let n=e?.allOf;if(!Array.isArray(n))continue;let r=t.get(n);r?r.push(e):t.set(n,[e])}for(let n of e.intersections)for(let e of t.get(n)??[])ko(e)}}let i={};if(e.target===`draft-2020-12`?i.$schema=`https://json-schema.org/draft/2020-12/schema`:e.target===`draft-07`?i.$schema=`http://json-schema.org/draft-07/schema#`:e.target===`draft-04`?i.$schema=`http://json-schema.org/draft-04/schema#`:e.target,e.external?.uri){let n=e.external.registry.get(t)?.id;if(!n)throw Error("Schema is missing an `id` property");i.$id=e.external.uri(n)}bo(i,n.defId?n.schema:n.def??n.schema);let a=e.metadataRegistry.get(t)?.id;a!==void 0&&i.id===a&&delete i.id;let o=e.external?.defs??{};if(!e.external||e.sharedEmitDoneFor!==e.external)for(let t of e.seen.entries()){let e=t[1];e.def&&e.defId&&(e.def.id===e.defId&&delete e.def.id,v(o,e.defId,e.def))}e.external&&(e.sharedEmitDoneFor=e.external),e.external||Object.keys(o).length>0&&(e.target===`draft-2020-12`?i.$defs=o:i.definitions=o);try{let n=JSON.parse(JSON.stringify(i));return Object.defineProperty(n,"~standard",{value:{...t[`~standard`],jsonSchema:{input:Mo(t,`input`,e.processors),output:Mo(t,`output`,e.processors)}},enumerable:!1,writable:!1}),n}catch{throw Error(`Error converting schema to JSON.`)}}function V(e,t){let n=t??{seen:/* @__PURE__ */ new Set};if(n.seen.has(e))return!1;n.seen.add(e);let r=e._zod.def;if(r.type===`transform`)return!0;if(r.type===`array`)return V(r.element,n);if(r.type===`set`)return V(r.valueType,n);if(r.type===`lazy`)return V(r.getter(),n);if(r.type===`promise`||r.type===`optional`||r.type===`nonoptional`||r.type===`nullable`||r.type===`readonly`||r.type==="default"||r.type===`prefault`||r.type===`catch`)return V(r.innerType,n);if(r.type===`intersection`)return V(r.left,n)||V(r.right,n);if(r.type===`record`||r.type===`map`)return V(r.keyType,n)||V(r.valueType,n);if(r.type===`pipe`)return e._zod.traits.has(`$ZodCodec`)?!0:V(r.in,n)||V(r.out,n);if(r.type===`object`){for(let e in r.shape)if(V(r.shape[e],n))return!0;return!1}if(r.type===`union`){for(let e of r.options)if(V(e,n))return!0;return!1}if(r.type===`tuple`){for(let e of r.items)if(V(e,n))return!0;return!!(r.rest&&V(r.rest,n))}return!1}const jo=(e,t={})=>n=>{let r=xo({...n,processors:t});return B(e,r),Co(r,e),Ao(r,e)},Mo=(e,t,n={})=>r=>{let{libraryOptions:i,target:a}=r??{},o=xo({...i??{},target:a,io:t,processors:n});return B(e,o),Co(o,e),Ao(o,e)},H=(e,t,n)=>{(e[t]===void 0||n>e[t])&&(e[t]=n)},U=(e,t,n)=>{(e[t]===void 0||n<e[t])&&(e[t]=n)},No=(e,t)=>{H(e,`minimum`,t),U(e,`maximum`,t)},Po=(e,t)=>{e.multipleOf??=[],e.multipleOf.includes(t)||e.multipleOf.push(t)},Fo=(e,t)=>{e.patterns??=/* @__PURE__ */ new Set,e.patterns.add(t)},Io=(e,t)=>{e.mime=e.mime?e.mime.filter(e=>t.includes(e)):[...t]},Lo=(e,t)=>{e.format=t,t.includes(`int`)&&(e.isInt=!0)},Ro=(e,t)=>H(e,`minimum`,t.minimum),zo=(e,t)=>U(e,`maximum`,t.maximum),Bo=e=>(t,n)=>{Lo(t,n.format);let[r,i]=e[n.format];H(t,`minimum`,r),U(t,`maximum`,i)},Vo={greater_than:(e,t)=>H(e,t.inclusive?`minimum`:`exclusiveMinimum`,t.value),less_than:(e,t)=>U(e,t.inclusive?`maximum`:`exclusiveMaximum`,t.value),multiple_of:(e,t)=>Po(e,t.value),number_format:Bo(yt),bigint_format:Bo(bt),min_length:Ro,max_length:zo,length_equals:(e,t)=>No(e,t.length),min_size:Ro,max_size:zo,size_equals:(e,t)=>No(e,t.size),string_format:(e,t)=>{Lo(e,t.format),t.pattern&&Fo(e,t.pattern),(t.format===`base64`||t.format===`base64url`)&&(e.contentEncoding=t.format),(t.local||t.precision===-1)&&(e.laxFormat=!0)},mime_type:(e,t)=>Io(e,t.mime)};function W(e){let t={},n=e._zod.def,r=e._zod.traits.has(`$ZodCheck`)?[e,...n.checks??[]]:n.checks??[];for(let e of r)Vo[e._zod.def.check]?.(t,e._zod.def);let i=e._zod.bag;i.minimum!==void 0&&H(t,`minimum`,i.minimum),i.exclusiveMinimum!==void 0&&H(t,`exclusiveMinimum`,i.exclusiveMinimum),i.maximum!==void 0&&U(t,`maximum`,i.maximum),i.exclusiveMaximum!==void 0&&U(t,`exclusiveMaximum`,i.exclusiveMaximum),i.multipleOf!==void 0&&Po(t,i.multipleOf),i.format!==void 0&&(t.format??=i.format,i.format.includes(`int`)&&(t.isInt=!0)),i.mime&&Io(t,i.mime);for(let e of i.patterns??[])Fo(t,e);return t}const Ho={guid:`uuid`,url:`uri`,datetime:`date-time`,json_string:`json-string`,regex:``},Uo=/* @__PURE__ */ new Map([[oi,Kn],[ci,qn]]),Wo=e=>Uo.get(e)??e,Go=(e,t,n,r)=>{let i=n;i.type=`string`;let{minimum:a,maximum:o,format:s,patterns:c,contentEncoding:l,laxFormat:u}=W(e);if(typeof a==`number`&&(i.minLength=a),typeof o==`number`&&(i.maxLength=o),s&&(i.format=Ho[s]??s,i.format===``&&delete i.format,(s===`time`||u)&&delete i.format),l&&(i.contentEncoding=l),c&&c.size>0){let e=[...c].map(Wo);e.length===1?i.pattern=e[0].source:e.length>1&&(i.allOf=[...e.map(e=>({...t.target===`draft-07`||t.target===`draft-04`||t.target===`openapi-3.0`?{type:`string`}:{},pattern:e.source}))])}},Ko=(e,t,n,r)=>{let i=n,{minimum:a,maximum:o,multipleOf:s,exclusiveMaximum:c,exclusiveMinimum:l,isInt:u}=W(e);i.type=u?`integer`:`number`;let d=typeof l==`number`&&l>=(a??-1/0),f=typeof c==`number`&&c<=(o??1/0),p=t.target===`draft-04`||t.target===`openapi-3.0`;if(d?p?(i.minimum=l,i.exclusiveMinimum=!0):i.exclusiveMinimum=l:typeof a==`number`&&(i.minimum=a),f?p?(i.maximum=c,i.exclusiveMaximum=!0):i.exclusiveMaximum=c:typeof o==`number`&&(i.maximum=o),s){let n=/* @__PURE__ */ new Set;for(let a of s)Number.isFinite(a)&&a!==0?n.add(Math.abs(a)):z(e,t,i,r,`A multipleOf divisor of ${a} cannot be represented in JSON Schema`);let[a,...o]=n;a!==void 0&&(i.multipleOf=a),o.length&&(i.allOf=[...i.allOf??[],...o.map(e=>({multipleOf:e}))])}},qo=(e,t,n,r)=>{n.not={}},Jo=(e,t,n,r)=>{let i=e._zod.def,a=Ze(i.entries);a.length===0?n.not={}:(a.every(e=>typeof e==`number`)&&(n.type=`number`),a.every(e=>typeof e==`string`)&&(n.type=`string`),n.enum=a)},Yo=(e,t,n,r)=>{z(e,t,n,r,`Custom types cannot be represented in JSON Schema`)},Xo=(e,t,n,r)=>{z(e,t,n,r,`Transforms cannot be represented in JSON Schema`)},Zo=(e,t,n,r)=>{let i=n,a=e._zod.def,{minimum:o,maximum:s}=W(e);typeof o==`number`&&(i.minItems=o),typeof s==`number`&&(i.maxItems=s),i.type=`array`,i.items=B(a.element,t,{...r,path:[...r.path,`items`]})};function Qo(e){let t=e._zod.def;return t.type===`pipe`&&t.in._zod.traits.has(`$ZodTransform`)?Qo(t.out):t.type===`catch`?Qo(t.innerType):e._zod.optin}const $o=(e,t,n,r)=>{let i=n,a=e._zod.def,o=a.shape;if(Object.getOwnPropertySymbols(o).length&&z(e,t,i,r,`Symbol keys cannot be represented in JSON Schema`))return;i.type=`object`,i.properties={};for(let e in o)v(i.properties,e,B(o[e],t,{...r,path:[...r.path,`properties`,e]}));let s=[];for(let e of Object.keys(o)){let n=a.shape[e];(t.io===`input`?Qo(n)===void 0:n._zod.optout===void 0)&&s.push(e)}s.length>0&&(i.required=s),a.catchall?._zod.def.type===`never`?i.additionalProperties=!1:a.catchall?a.catchall&&(i.additionalProperties=B(a.catchall,t,{...r,path:[...r.path,`additionalProperties`]})):t.io===`output`&&(i.additionalProperties=!1)},es=(e,t,n,r)=>{let i=e._zod.def,a=i.inclusive===!1,o=i.options.map((e,n)=>B(e,t,{...r,path:[...r.path,a?`oneOf`:`anyOf`,n]}));a?n.oneOf=o:n.anyOf=o},ts=(e,t,n,r)=>{let i=e._zod.def,a=B(i.left,t,{...r,path:[...r.path,`allOf`,0]}),o=B(i.right,t,{...r,path:[...r.path,`allOf`,1]}),s=e=>`allOf`in e&&Object.keys(e).length===1,c=[...s(a)?a.allOf:[a],...s(o)?o.allOf:[o]];n.allOf=c,t.intersections.push(c)};function ns(e,t,n){if(t.$ref){if(n.has(t))return t;n.add(t);let r=e.get(t)?.def;if(!r)return t;let i=ns(e,r,n);return i===r?t:i}for(let r of[`anyOf`,`oneOf`]){let i=t[r];if(!Array.isArray(i))continue;let a=i.map(t=>ns(e,t,n));a.some((e,t)=>e!==i[t])&&(t={...t,[r]:a})}let r=Array.isArray(t.type)?t.type:[t.type],i=!r.includes(`string`)&&r.some(e=>e===`number`||e===`integer`),a=t.enum??(t.const===void 0?void 0:[t.const]);if(!i&&!a?.some(e=>typeof e==`number`))return t;let{minimum:o,maximum:s,exclusiveMinimum:c,exclusiveMaximum:l,multipleOf:u,format:d,id:f,...p}=t;return p.enum?p.enum=p.enum.map(e=>typeof e==`number`?String(e):e):typeof p.const==`number`&&(p.const=String(p.const)),i&&(p.type=`string`,a||(p.pattern=(r.includes(`number`)?ir:rr).source)),p}const rs=/* @__PURE__ */ new WeakMap;function is(e){let t=/* @__PURE__ */ new Map;for(let n of e.seen.values())n.def&&!t.has(n.schema)&&t.set(n.schema,n);let n=/* @__PURE__ */ new Map;for(let r of rs.get(e)??[]){let i=e.seen.get(r),a=(i?.def??i?.schema)?.propertyNames;if(!a||a===!0||n.has(a))continue;let o=ns(t,a,/* @__PURE__ */ new Set);o!==a&&n.set(a,o)}if(n.size)for(let t of e.seen.values())for(let e of[t.schema,t.def]){let t=e&&n.get(e.propertyNames);t&&(e.propertyNames=t)}}const as=(e,t,n,r)=>{let i=n,a=e._zod.def;i.type=`object`;let o=a.keyType,s=W(o).patterns;if(a.mode===`loose`&&s&&s.size>0){let e=B(a.valueType,t,{...r,path:[...r.path,`patternProperties`,`*`]});i.patternProperties={};for(let t of s)v(i.patternProperties,Wo(t).source,e)}else{if(t.target===`draft-07`||t.target===`draft-2020-12`){i.propertyNames=B(a.keyType,t,{...r,path:[...r.path,`propertyNames`]});let n=rs.get(t);n||(n=[],rs.set(t,n),t.deferred.push(()=>is(t))),n.push(e)}i.additionalProperties=B(a.valueType,t,{...r,path:[...r.path,`additionalProperties`]})}let c=o._zod.values,l=t.io===`input`&&Qo(a.valueType)!==void 0;if(c&&!a.partial&&!l){let e=[...c].filter(e=>typeof e==`string`||typeof e==`number`);e.length>0&&(i.required=e.map(String))}},os=(e,t,n,r)=>{let i=e._zod.def,a=B(i.innerType,t,r),o=t.seen.get(e);t.target===`openapi-3.0`?(o.ref=i.innerType,n.nullable=!0):n.anyOf=[a,{type:`null`}]},ss=(e,t,n,r)=>{let i=e._zod.def;B(i.innerType,t,r);let a=t.seen.get(e);a.ref=i.innerType},cs=Symbol();function ls(e,t,n,r,i){let a=!1,o=JSON.stringify(e,(e,t)=>typeof t==`bigint`?(a=!0,null):t);return a?(z(t,n,r,i,`BigInt defaults cannot be represented in JSON Schema`),cs):JSON.parse(o)}const us=(e,t,n,r)=>{let i=e._zod.def;B(i.innerType,t,r);let a=t.seen.get(e);a.ref=i.innerType;let o=ls(i.defaultValue,e,t,n,r);o!==cs&&(n.default=o)},ds=(e,t,n,r)=>{let i=e._zod.def;B(i.innerType,t,r);let a=t.seen.get(e);if(a.ref=i.innerType,t.io!==`input`)return;let o=ls(i.defaultValue,e,t,n,r);o!==cs&&(n._prefault=o)},fs=(e,t,n,r)=>{let i=e._zod.def;B(i.innerType,t,r);let a=t.seen.get(e);a.ref=i.innerType;let o;try{o=i.catchValue(void 0)}catch{z(e,t,n,r,`Dynamic catch values are not supported in JSON Schema`);return}n.default=o},ps=(e,t,n,r)=>{let i=e._zod.def,a=i.in._zod.traits.has(`$ZodTransform`),o=t.io===`input`?a?i.out:i.in:i.out;B(o,t,r);let s=t.seen.get(e);s.ref=o},ms=(e,t,n,r)=>{let i=e._zod.def;B(i.innerType,t,r);let a=t.seen.get(e);a.ref=i.innerType,n.readOnly=!0},hs=(e,t,n,r)=>{let i=e._zod.def;B(i.innerType,t,r);let a=t.seen.get(e);a.ref=i.innerType},gs=/* @__PURE__ */ new WeakSet([Object.prototype,Error.prototype]);function _s(e,t,n){Object.defineProperty(e,t,{configurable:!0,enumerable:!1,get(){let e=n(this);return Object.defineProperty(this,t,{value:e,configurable:!0,writable:!0}),e},set(e){Object.defineProperty(this,t,{value:e,configurable:!0,writable:!0})}})}const G=/*@__PURE__*/ j(`ZodError`,(e,t)=>{an.init(e,t),e.name=`ZodError`;let n=Object.getPrototypeOf(e);gs.has(n)||(gs.add(n),_s(n,`format`,e=>t=>cn(e,t)),_s(n,`flatten`,e=>t=>sn(e,t)),_s(n,`addIssue`,e=>t=>{e.issues.push(t),e.message=JSON.stringify(e.issues,$e,2)}),_s(n,`addIssues`,e=>t=>{e.issues.push(...t),e.message=JSON.stringify(e.issues,$e,2)}),Object.defineProperty(n,"isEmpty",{configurable:!0,enumerable:!1,get(){return this.issues.length===0}}))},void 0,{Parent:Error}),vs=/* @__PURE__ */ fn(G),ys=/* @__PURE__ */ pn(G),bs=/* @__PURE__ */ mn(G),xs=/* @__PURE__ */ gn(G),Ss=/* @__PURE__ */ Sn(G),Cs=/* @__PURE__ */ Cn(G),ws=/* @__PURE__ */ wn(G),Ts=/* @__PURE__ */ Tn(G),Es=/* @__PURE__ */ En(G),Ds=/* @__PURE__ */ Dn(G),Os=/* @__PURE__ */ On(G),ks=/* @__PURE__ */ kn(G);function As(){N.localeError||P(ma())}function js(){N.memoizer||P({memoizer:da()})}const K=/*@__PURE__*/ j(`ZodType`,(e,t)=>(As(),I.init(e,t),e.def=t,e.type=t.type,e),{check(...e){let t=this.def;return this.clone(x(t,{checks:[...t.checks??[],...e.map(e=>typeof e==`function`?{_zod:{check:e,def:{check:`custom`},onattach:[]}}:e)]}),{parent:!0})},with(...e){return this.check(...e)},clone(e,t){return C(this,e,t)},brand(){return this},register(e,t){return e.add(this,t),this},refine(e,t){return this.check(Wc(e,t))},superRefine(e,t){return this.check(Gc(e,t))},overwrite(e){return this.check(/* @__PURE__ */ R(e))},optional(){return Ec(this)},exactOptional(){return Oc(this)},nullable(){return Ac(this)},nullish(){return Ec(Ac(this))},nonoptional(e){return Ic(this,e)},array(){return fc(this)},or(e){return gc([this,e])},and(e){return vc(this,e)},transform(e){return Bc(this,wc(e))},default(e){return Mc(this,e)},prefault(e){return Pc(this,e)},catch(e){return Rc(this,e)},pipe(e){return Bc(this,e)},readonly(){return Hc(this)},describe(e){let t=this.clone();return va.add(t,{description:e}),t},meta(...e){if(e.length===0)return va.get(this);let t=this.clone();return va.add(t,e[0]),t},isOptional(){return this.safeParse(void 0).success},isNullable(){return this.safeParse(null).success},apply(e,...t){return t.length===0?e(this):e(this,...t)},get"~standard"(){return Bt(this,`~standard`,{...Or(this),jsonSchema:{input:Mo(this,`input`),output:Mo(this,`output`)}})},set"~standard"(e){O(this,`~standard`,e)},parse:function e(t,n){return vs(this,t,n,{callee:e})},parseAsync:async function e(t,n){return await ys(this,t,n,{callee:e})},safeParse(e,t){return bs(this,e,t)},async safeParseAsync(e,t){return xs(this,e,t)},get spa(){return this?.safeParseAsync},set spa(e){O(this,`spa`,e)},validate(e,t){return yn(this,e,t)},validateAsync(e,t){return xn(this,e,t)},encode:function e(t,n){return Ss(this,t,n,{callee:e})},decode:function e(t,n){return Cs(this,t,n,{callee:e})},encodeAsync:async function e(t,n){return await ws(this,t,n,{callee:e})},decodeAsync:async function e(t,n){return await Ts(this,t,n,{callee:e})},safeEncode(e,t){return Es(this,e,t)},safeDecode(e,t){return Ds(this,e,t)},async safeEncodeAsync(e,t){return Os(this,e,t)},async safeDecodeAsync(e,t){return ks(this,e,t)},toJSONSchema(e){return jo(this,{})(e)},get description(){return va.get(this)?.description},get _def(){return this._zod.def}}),Ms=/*@__PURE__*/ j(`_ZodString`,(e,t)=>{kr.init(e,t),K.init(e,t),e._zod.processJSONSchema=(t,n,r)=>Go(e,t,n,r)},/*@__PURE__*/ Vt({format:e=>W(e).format??null,minLength:e=>W(e).minimum??null,maxLength:e=>W(e).maximum??null},{regex(...e){return this.check(/* @__PURE__ */ io(...e))},includes(...e){return this.check(/* @__PURE__ */ so(...e))},startsWith(...e){return this.check(/* @__PURE__ */ co(...e))},endsWith(...e){return this.check(/* @__PURE__ */ lo(...e))},min(...e){return this.check(/* @__PURE__ */ no(...e))},max(...e){return this.check(/* @__PURE__ */ to(...e))},length(...e){return this.check(/* @__PURE__ */ ro(...e))},nonempty(...e){return this.check(/* @__PURE__ */ no(1,...e))},lowercase(e){return this.check(/* @__PURE__ */ ao(e))},uppercase(e){return this.check(/* @__PURE__ */ oo(e))},trim(){return this.check(/* @__PURE__ */ fo())},normalize(...e){return this.check(/* @__PURE__ */ uo(...e))},toLowerCase(){return this.check(/* @__PURE__ */ po())},toUpperCase(){return this.check(/* @__PURE__ */ mo())},slugify(){return this.check(/* @__PURE__ */ ho())}})),Ns=/*@__PURE__*/ j(`ZodString`,(e,t)=>{kr.init(e,t),Ms.init(e,t)},{email(e){return this.check(/* @__PURE__ */ xa(Rs,e))},url(e){return this.check(/* @__PURE__ */ Da(Vs,e))},jwt(e){return this.check(/* @__PURE__ */ Ha(rc,e))},emoji(e){return this.check(/* @__PURE__ */ Oa(Us,e))},guid(e){return this.check(/* @__PURE__ */ Sa(zs,e))},uuid(e){return this.check(/* @__PURE__ */ Ca(Bs,e))},uuidv4(e){return this.check(/* @__PURE__ */ wa(Bs,e))},uuidv6(e){return this.check(/* @__PURE__ */ Ta(Bs,e))},uuidv7(e){return this.check(/* @__PURE__ */ Ea(Bs,e))},nanoid(e){return this.check(/* @__PURE__ */ ka(Ws,e))},cuid(e){return this.check(/* @__PURE__ */ Aa(Gs,e))},cuid2(e){return this.check(/* @__PURE__ */ ja(Ks,e))},ulid(e){return this.check(/* @__PURE__ */ Ma(qs,e))},base64(e){return this.check(/* @__PURE__ */ za(ec,e))},base64url(e){return this.check(/* @__PURE__ */ Ba(tc,e))},xid(e){return this.check(/* @__PURE__ */ Na(Js,e))},ksuid(e){return this.check(/* @__PURE__ */ Pa(Ys,e))},ipv4(e){return this.check(/* @__PURE__ */ Fa(Xs,e))},ipv6(e){return this.check(/* @__PURE__ */ Ia(Zs,e))},cidrv4(e){return this.check(/* @__PURE__ */ La(Qs,e))},cidrv6(e){return this.check(/* @__PURE__ */ Ra($s,e))},e164(e){return this.check(/* @__PURE__ */ Va(nc,e))},datetime(e){return this.check(/* @__PURE__ */ Ua(Ps,e))},date(e){return this.check(/* @__PURE__ */ Wa(Fs,e))},time(e){return this.check(/* @__PURE__ */ Ga(Is,e))},duration(e){return this.check(/* @__PURE__ */ Ka(Ls,e))}});function q(e){return/* @__PURE__ */ ba(Ns,e)}const J=/*@__PURE__*/ j(`ZodStringFormat`,(e,t)=>{L.init(e,t),Ms.init(e,t)}),Ps=/*@__PURE__*/ j(`ZodISODateTime`,(e,t)=>{Jr.init(e,t),J.init(e,t)}),Fs=/*@__PURE__*/ j(`ZodISODate`,(e,t)=>{Yr.init(e,t),J.init(e,t)}),Is=/*@__PURE__*/ j(`ZodISOTime`,(e,t)=>{Xr.init(e,t),J.init(e,t)}),Ls=/*@__PURE__*/ j(`ZodISODuration`,(e,t)=>{Zr.init(e,t),J.init(e,t)}),Rs=/*@__PURE__*/ j(`ZodEmail`,(e,t)=>{Mr.init(e,t),J.init(e,t)}),zs=/*@__PURE__*/ j(`ZodGUID`,(e,t)=>{Ar.init(e,t),J.init(e,t)}),Bs=/*@__PURE__*/ j(`ZodUUID`,(e,t)=>{jr.init(e,t),J.init(e,t)}),Vs=/*@__PURE__*/ j(`ZodURL`,(e,t)=>{Br.init(e,t),J.init(e,t)});function Hs(e){return/* @__PURE__ */ Da(Vs,e)}const Us=/*@__PURE__*/ j(`ZodEmoji`,(e,t)=>{Vr.init(e,t),J.init(e,t)}),Ws=/*@__PURE__*/ j(`ZodNanoID`,(e,t)=>{Hr.init(e,t),J.init(e,t)}),Gs=/*@__PURE__*/ j(`ZodCUID`,(e,t)=>{Ur.init(e,t),J.init(e,t)}),Ks=/*@__PURE__*/ j(`ZodCUID2`,(e,t)=>{Wr.init(e,t),J.init(e,t)}),qs=/*@__PURE__*/ j(`ZodULID`,(e,t)=>{Gr.init(e,t),J.init(e,t)}),Js=/*@__PURE__*/ j(`ZodXID`,(e,t)=>{Kr.init(e,t),J.init(e,t)}),Ys=/*@__PURE__*/ j(`ZodKSUID`,(e,t)=>{qr.init(e,t),J.init(e,t)}),Xs=/*@__PURE__*/ j(`ZodIPv4`,(e,t)=>{Qr.init(e,t),J.init(e,t)}),Zs=/*@__PURE__*/ j(`ZodIPv6`,(e,t)=>{ti.init(e,t),J.init(e,t)}),Qs=/*@__PURE__*/ j(`ZodCIDRv4`,(e,t)=>{ni.init(e,t),J.init(e,t)}),$s=/*@__PURE__*/ j(`ZodCIDRv6`,(e,t)=>{ii.init(e,t),J.init(e,t)}),ec=/*@__PURE__*/ j(`ZodBase64`,(e,t)=>{si.init(e,t),J.init(e,t)}),tc=/*@__PURE__*/ j(`ZodBase64URL`,(e,t)=>{ui.init(e,t),J.init(e,t)}),nc=/*@__PURE__*/ j(`ZodE164`,(e,t)=>{di.init(e,t),J.init(e,t)}),rc=/*@__PURE__*/ j(`ZodJWT`,(e,t)=>{pi.init(e,t),J.init(e,t)}),ic=/*@__PURE__*/ j(`ZodNumber`,(e,t)=>{mi.init(e,t),K.init(e,t),e._zod.processJSONSchema=(t,n,r)=>Ko(e,t,n,r),e.isFinite=!0},/*@__PURE__*/ Vt({minValue:e=>{let{minimum:t,exclusiveMinimum:n}=W(e);return Math.max(t??-1/0,n??-1/0)},maxValue:e=>{let{maximum:t,exclusiveMaximum:n}=W(e);return Math.min(t??1/0,n??1/0)},isInt:e=>{let{isInt:t,multipleOf:n}=W(e);return!!t||!!n?.some(Number.isSafeInteger)},format:e=>W(e).format??null},{gt(e,t){return this.check(/* @__PURE__ */ Qa(e,t))},gte(e,t){return this.check(/* @__PURE__ */ $a(e,t))},min(e,t){return this.check(/* @__PURE__ */ $a(e,t))},lt(e,t){return this.check(/* @__PURE__ */ Xa(e,t))},lte(e,t){return this.check(/* @__PURE__ */ Za(e,t))},max(e,t){return this.check(/* @__PURE__ */ Za(e,t))},int(e){return this.check(oc(e))},safe(e){return this.check(oc(e))},positive(e){return this.check(/* @__PURE__ */ Qa(0,e))},nonnegative(e){return this.check(/* @__PURE__ */ $a(0,e))},negative(e){return this.check(/* @__PURE__ */ Xa(0,e))},nonpositive(e){return this.check(/* @__PURE__ */ Za(0,e))},multipleOf(e,t){return this.check(/* @__PURE__ */ eo(e,t))},step(e,t){return this.check(/* @__PURE__ */ eo(e,t))},finite(){return this}})),ac=/*@__PURE__*/ j(`ZodNumberFormat`,(e,t)=>{hi.init(e,t),ic.init(e,t)});function oc(e){return/* @__PURE__ */ qa(ac,e)}const sc=/*@__PURE__*/ j(`ZodUnknown`,(e,t)=>{gi.init(e,t),K.init(e,t),e._zod.processJSONSchema=(e,t,n)=>void 0});function cc(){return/* @__PURE__ */ Ja(sc)}const lc=/*@__PURE__*/ j(`ZodNever`,(e,t)=>{_i.init(e,t),K.init(e,t),e._zod.processJSONSchema=(t,n,r)=>qo(e,t,n,r)});function uc(e){return/* @__PURE__ */ Ya(lc,e)}const dc=/*@__PURE__*/ j(`ZodArray`,(e,t)=>{js(),xi.init(e,t),K.init(e,t),e._zod.processJSONSchema=(t,n,r)=>Zo(e,t,n,r),e.element=t.element},{min(e,t){return this.check(/* @__PURE__ */ no(e,t))},nonempty(e){return this.check(/* @__PURE__ */ no(1,e))},max(e,t){return this.check(/* @__PURE__ */ to(e,t))},length(e,t){return this.check(/* @__PURE__ */ ro(e,t))},unwrap(){return this.element}});function fc(e,t){return/* @__PURE__ */ go(dc,e,t)}const pc=/*@__PURE__*/ j(`ZodObject`,(e,t)=>{js(),Di.init(e,t),K.init(e,t),e._zod.processJSONSchema=(t,n,r)=>$o(e,t,n,r),Kt(e,`shape`,e=>e._zod.def.shape,!1)},{keyof(){return Sc(Object.keys(this._zod.def.shape))},catchall(e){return this.clone(x(this._zod.def,{catchall:e}))},passthrough(){return this.clone(x(this._zod.def,{catchall:cc()}))},loose(){return this.clone(x(this._zod.def,{catchall:cc()}))},strict(){return this.clone(x(this._zod.def,{catchall:uc()}))},strip(){return this.clone(x(this._zod.def,{catchall:void 0}))},extend(e){return wt(this,e)},safeExtend(e){return Et(this,e)},merge(e){return Dt(this,e)},pick(e){return xt(this,e)},omit(e){return Ct(this,e)},partial(...e){return Ot(Tc,this,e[0])},exactPartial(...e){return Ot(Dc,this,e[0],`exactPartial`)},required(...e){return kt(Fc,this,e[0])}});function mc(e,t){let n={type:`object`,shape:e??{},...w(t)};return new pc(n)}const hc=/*@__PURE__*/ j(`ZodUnion`,(e,t)=>{ki.init(e,t),K.init(e,t),e._zod.processJSONSchema=(t,n,r)=>es(e,t,n,r),e.options=t.options});function gc(e,t){return new hc({type:`union`,options:e,...w(t)})}const _c=/*@__PURE__*/ j(`ZodIntersection`,(e,t)=>{Ai.init(e,t),K.init(e,t),e._zod.processJSONSchema=(t,n,r)=>ts(e,t,n,r)});function vc(e,t){return new _c({type:`intersection`,left:e,right:t})}const yc=/*@__PURE__*/ j(`ZodRecord`,(e,t)=>{js(),Ni.init(e,t),K.init(e,t),e._zod.processJSONSchema=(t,n,r)=>as(e,t,n,r),e.keyType=t.keyType,e.valueType=t.valueType});function bc(e,t,n){return!t||!t._zod?new yc({type:`record`,keyType:q(),valueType:e,...w(t)}):new yc({type:`record`,keyType:e,valueType:t,...w(n)})}const xc=/*@__PURE__*/ j(`ZodEnum`,(e,t)=>{Pi.init(e,t),K.init(e,t),e._zod.processJSONSchema=(t,n,r)=>Jo(e,t,n,r),e.enum=t.entries,e.options=[...e._zod.values];let n=new Set(Object.keys(t.entries));e.extract=(e,r)=>{let i={};for(let r of e)if(n.has(r))i[r]=t.entries[r];else throw Error(`Key ${r} not found in enum`);return new xc({...t,checks:[],...w(r),entries:i})},e.exclude=(e,r)=>{let i={...t.entries};for(let t of e)if(n.has(t))delete i[t];else throw Error(`Key ${t} not found in enum`);return new xc({...t,checks:[],...w(r),entries:i})}});function Sc(e,t){let n=Array.isArray(e)?Object.fromEntries(e.map(e=>[e,e])):e;return new xc({type:`enum`,entries:n,...w(t)})}const Cc=/*@__PURE__*/ j(`ZodTransform`,(e,t)=>{js(),Fi.init(e,t),K.init(e,t),e._zod.processJSONSchema=(t,n,r)=>Xo(e,t,n,r),e._zod.parse=(n,r)=>{if(r.direction===`backward`)throw new Qt(e.constructor.name);n.addIssue=r=>{if(typeof r==`string`)n.issues.push(Rt(r,n.value,t));else{let t=r;t.fatal&&(t.continue=!1),t.code??=`custom`,`input`in t||(t.input=n.value),t.inst??=e,n.issues.push(Rt(t))}};let i=t.transform(n.value,n);return i instanceof Promise?i.then(e=>(n.value=e,n)):(n.value=i,n)}});function wc(e){return new Cc({type:`transform`,transform:e})}const Tc=/*@__PURE__*/ j(`ZodOptional`,(e,t)=>{Li.init(e,t),K.init(e,t),e._zod.processJSONSchema=(t,n,r)=>hs(e,t,n,r),e.unwrap=()=>e._zod.def.innerType});function Ec(e){return new Tc({type:`optional`,innerType:e})}const Dc=/*@__PURE__*/ j(`ZodExactOptional`,(e,t)=>{Ri.init(e,t),K.init(e,t),e._zod.processJSONSchema=(t,n,r)=>hs(e,t,n,r),e.unwrap=()=>e._zod.def.innerType});function Oc(e){return new Dc({type:`optional`,innerType:e})}const kc=/*@__PURE__*/ j(`ZodNullable`,(e,t)=>{zi.init(e,t),K.init(e,t),e._zod.processJSONSchema=(t,n,r)=>os(e,t,n,r),e.unwrap=()=>e._zod.def.innerType});function Ac(e){return new kc({type:`nullable`,innerType:e})}const jc=/*@__PURE__*/ j(`ZodDefault`,(e,t)=>{Bi.init(e,t),K.init(e,t),e._zod.processJSONSchema=(t,n,r)=>us(e,t,n,r),e.unwrap=()=>e._zod.def.innerType,e.removeDefault=e.unwrap});function Mc(e,t){return new jc({type:`default`,innerType:e,get defaultValue(){return typeof t==`function`?t():mt(t)}})}const Nc=/*@__PURE__*/ j(`ZodPrefault`,(e,t)=>{Hi.init(e,t),K.init(e,t),e._zod.processJSONSchema=(t,n,r)=>ds(e,t,n,r),e.unwrap=()=>e._zod.def.innerType});function Pc(e,t){return new Nc({type:`prefault`,innerType:e,get defaultValue(){return typeof t==`function`?t():mt(t)}})}const Fc=/*@__PURE__*/ j(`ZodNonOptional`,(e,t)=>{Ui.init(e,t),K.init(e,t),e._zod.processJSONSchema=(t,n,r)=>ss(e,t,n,r),e.unwrap=()=>e._zod.def.innerType});function Ic(e,t){return new Fc({type:`nonoptional`,innerType:e,...w(t)})}const Lc=/*@__PURE__*/ j(`ZodCatch`,(e,t)=>{Ki.init(e,t),K.init(e,t),e._zod.processJSONSchema=(t,n,r)=>fs(e,t,n,r),e.unwrap=()=>e._zod.def.innerType,e.removeCatch=e.unwrap});function Rc(e,t){return new Lc({type:`catch`,innerType:e,catchValue:typeof t==`function`?t:qt(t)})}const zc=/*@__PURE__*/ j(`ZodPipe`,(e,t)=>{qi.init(e,t),K.init(e,t),e._zod.processJSONSchema=(t,n,r)=>ps(e,t,n,r),e.in=t.in,e.out=t.out});function Bc(e,t){return new zc({type:`pipe`,in:e,out:t})}const Vc=/*@__PURE__*/ j(`ZodReadonly`,(e,t)=>{Yi.init(e,t),K.init(e,t),e._zod.processJSONSchema=(t,n,r)=>ms(e,t,n,r),e.unwrap=()=>e._zod.def.innerType});function Hc(e){return new Vc({type:`readonly`,innerType:e})}const Uc=/*@__PURE__*/ j(`ZodCustom`,(e,t)=>{Zi.init(e,t),K.init(e,t),e._zod.processJSONSchema=(t,n,r)=>Yo(e,t,n,r)});function Wc(e,t={}){return/* @__PURE__ */ _o(Uc,e,t)}function Gc(e,t){return/* @__PURE__ */ vo(e,t)}const Kc=mc({darwinArm64:mc({platform:q(),arch:q(),pythonVersion:q().regex(/^\d+\.\d+\.\d+$/u,`pythonVersion 必须是三段数字的版本号`),release:q(),url:Hs(),sha256:q().regex(/^[0-9a-f]{64}$/u,`sha256 必须是 64 位小写十六进制`),sizeBytes:oc().positive()}),unsupported:bc(q(),q())}),qc=r(g.join(import.meta.dirname,`runtime-manifest.json`))?import.meta.dirname:g.resolve(import.meta.dirname,`..`);function Jc(e){let t;try{t=JSON.parse(e)}catch(e){throw Error(`runtime-manifest.json is invalid: ${String(e)}`,{cause:e})}let n=Kc.safeParse(t);if(!n.success)throw Error(`runtime-manifest.json is invalid: ${un(n.error)}`);return n.data}const Yc=Jc(i(g.join(qc,`runtime-manifest.json`),`utf8`));function Xc(e){return g.join(e,`runtime`,`python`,Yc.darwinArm64.pythonVersion,`bin`,`python3`)}function Zc(e){try{return a(e).isFile()?(t(e,n.X_OK),!0):!1}catch{return!1}}function Qc(e){return process.platform===`win32`?g.join(e,`_env`,`.venv`,`Scripts`,`python.exe`):g.join(e,`_env`,`.venv`,`bin`,`python`)}function $c(e){let t=e.pythonBin.trim();if(t.length>0)return{pythonPath:t,via:`configured`,version:`unknown`};if(process.platform===`darwin`&&process.arch===`arm64`&&e.dataDir.length>0){let t=Xc(e.dataDir);if(Zc(t))return{pythonPath:t,via:`managed`,version:Yc.darwinArm64.pythonVersion}}let n=Qc(e.repoRoot);return Zc(n)?{pythonPath:n,via:`repo`,version:`unknown`}:{pythonPath:process.platform===`win32`?`python`:`python3`,via:`path`,version:`unknown`}}function Y(e){return typeof e==`object`&&!!e&&!Array.isArray(e)}const el=`state.json`,tl=/No matching distribution|Could not find a version/iu,nl=/Network|Temporary failure|Connection|timed out/iu;function rl(){return process.platform===`darwin`&&process.arch===`arm64`}const il=/* @__PURE__ */ new Set([`Chromium`,`chrome`,`chrome.exe`,`Google Chrome for Testing`]);var X=class extends Error{code;constructor(e,t,n){super(t,n),this.name=`InstallError`,this.code=e}};function al(e){return Y(e)&&typeof e.code==`string`?e.code:void 0}async function ol(e,t={}){return new Promise(n=>{let r=ie(e[0]??``,e.slice(1),{env:{...process.env,...t.env},stdio:[`ignore`,`pipe`,`pipe`]}),i=``,a=``;r.stdout.on(`data`,e=>{i+=e.toString(`utf8`)}),r.stderr.on(`data`,e=>{a+=e.toString(`utf8`)}),r.on(`error`,e=>{n({code:null,stdout:i,stderr:`${a}${String(e)}`})}),r.on(`close`,e=>{n({code:e,stdout:i,stderr:a})})})}function sl(e){return async t=>{let n=g.join(te.tmpdir(),`dsh-scrapling-dl-${re()}`),r=await e([`curl`,`--fail`,`--location`,`--silent`,`--show-error`,`--output`,n,t]);if(r.code===0)try{return new Uint8Array(await d(n))}finally{await m(n,{force:!0})}if(await m(n,{force:!0}),r.code!==null)throw new X(`INSTALL_NETWORK`,`curl failed for ${t}: ${r.stderr.slice(0,400)}`);let i=await fetch(t);if(!i.ok)throw new X(`INSTALL_NETWORK`,`${t} answered HTTP ${i.status}`);return new Uint8Array(await i.arrayBuffer())}}const cl={download:sl(ol),extract:async(e,t)=>{let n=await ol([`tar`,`-xzf`,e,`-C`,t]);if(n.code!==0)throw new X(`INSTALL_FAILED`,`tar failed: ${n.stderr.slice(0,400)}`)},spawn:ol};async function Z(e){try{return await o(e,n.F_OK),!0}catch{return!1}}function ll(t=e(import.meta.url)){let n;try{n=t(`fs-native-extensions`)}catch{n=void 0}if(Y(n)){let e=n.tryLock,t=n.unlock;if(typeof e==`function`&&typeof t==`function`)return{tryLock:t=>!!e.call(n,t),unlock:e=>{t.call(n,e)}}}return null}const ul=ll();function dl(e,t=ul){if(t===null)throw new X(`INSTALL_LOCK_UNREADABLE`,`fs-native-extensions is not loadable`);try{return t.tryLock(e)}catch(e){throw new X(`INSTALL_LOCK_UNREADABLE`,`cannot lock install fd: ${String(e)}`)}}async function fl(e,t=ul){let n;try{n=await u(e,`a+`)}catch(t){throw new X(`INSTALL_LOCK_UNREADABLE`,`cannot open install lock ${e}: ${String(t)}`)}if(!dl(n.fd,t))throw await n.close(),new X(`INSTALL_BUSY`,`another install holds ${e}`);return{release:async()=>{try{t?.unlock(n.fd)}catch{}await n.close()}}}const pl=/* @__PURE__ */ new Map;function ml(e,t){t<=1?pl.delete(e):pl.set(e,t-1)}async function hl(e){let t=g.join(e,`runtime`);return await l(t,{recursive:!0}),process.platform!==`win32`&&await s(t,448),t}async function gl(e,t){let n=g.join(e,`runtime`),r=g.join(n,`install.lock`),i=g.resolve(r),a=pl.get(i)??0;if(a>0){pl.set(i,a+1);try{return await t()}finally{ml(i,a+1)}}await hl(e);let o=await fl(r);pl.set(i,1);try{return await t()}finally{ml(i,1),await o.release()}}async function _l(e,t){if(!URL.canParse(t))throw new X(`INSTALL_OFFLINE_ASSETS`,`manifest archive URL is not parseable: ${t}`);let n=g.basename(new URL(t).pathname),r;try{r=decodeURIComponent(n)}catch{throw new X(`INSTALL_OFFLINE_ASSETS`,`manifest archive name has invalid percent-encoding: ${n}`)}let i=n===r?[n]:[r,n],a=(await Promise.all(i.map(async t=>({name:t,bytes:await d(g.join(e,t)).catch(()=>null)})))).find(e=>e.bytes!==null)?.bytes;if(a==null)throw new X(`INSTALL_OFFLINE_ASSETS`,`offline python archive missing under ${e}: expected ${i.join(` or `)}`);return new Uint8Array(a)}async function vl(e,t,n,r){return gl(t,async()=>{let i=g.join(t,`runtime`,`.tmp`,re());await l(i,{recursive:!0});let a=g.join(i,`python.tar.gz`);try{let o=r===void 0?await n.download(e.url):await _l(r,e.url),s=ne(`sha256`).update(o).digest(`hex`);if(s!==e.sha256)throw new X(`INSTALL_HASH_MISMATCH`,`python archive hash ${s} does not match ${e.sha256}`);await ee(a,o);let u=g.join(i,`extract`);await l(u,{recursive:!0}),await n.extract(a,u);let d=g.join(u,`python`),f=await Z(g.join(d,`bin`,`python3`))?d:u,p=g.dirname(g.dirname(Xc(t)));await m(p,{recursive:!0,force:!0}),await l(g.dirname(p),{recursive:!0}),await c(f,p,{recursive:!0,dereference:!0});let h=Xc(t);if(!await Z(h))throw new X(`INSTALL_FAILED`,`python archive did not contain bin/python3`);return{pythonPath:h,version:e.pythonVersion}}finally{await m(i,{recursive:!0,force:!0}),await h(g.join(t,`runtime`,`.tmp`)).catch(()=>null)}})}async function yl(e){let t=g.join(e,`runtime`,el),n;try{n=await d(t,`utf8`)}catch(e){if(al(e)===`ENOENT`)return{packs:{}};throw new X(`INSTALL_STATE_CORRUPT`,`cannot read ${t}: ${String(e)}; delete it and install again`,{cause:e})}let r;try{r=JSON.parse(n)}catch(e){throw new X(`INSTALL_STATE_CORRUPT`,`${t} is not valid JSON; delete it and install again`,{cause:e})}if(!Y(r))throw new X(`INSTALL_STATE_CORRUPT`,`${t} does not hold a JSON object; delete it and install again`);return r}async function bl(e,t){let n=await hl(e),r=g.join(n,el),i=`${r}.${re()}.tmp`;try{await ee(i,JSON.stringify(t,null,2),`utf8`),await p(i,r)}finally{try{await m(i,{force:!0})}catch{}}}async function xl(e,t,n,r=e=>d(e,`utf8`)){let i=g.join(e,`bin`),a=`#!${t}/`,o=(await f(i,{withFileTypes:!0}).catch(()=>[])).filter(e=>e.isFile()).map(e=>g.join(i,e.name));await Promise.all(o.map(async e=>{let t=await r(e).catch(()=>``),i=t.indexOf(`
|
|
118
|
+
`),o=i===-1?t:t.slice(0,i);if(!o.startsWith(a))return;let s=i===-1?``:t.slice(i);await ee(e,`#!${n}/${o.slice(a.length)}${s}`,`utf8`)}))}async function Sl(e,t){let n=!1;if(t){try{await m(e.venv,{recursive:!0,force:!0})}catch{}try{await p(e.previousVenv,e.venv)}catch{n=!0}}if(!n)try{await m(e.previousVenv,{recursive:!0,force:!0})}catch{}try{await m(e.staging,{recursive:!0,force:!0})}catch{}}async function Cl(e){let{io:t}=e;await gl(e.dataDir,async()=>{let n=await hl(e.dataDir),r=g.join(n,`venv`),i=g.join(n,`.tmp`,`venv-${re()}`),a=g.join(n,`.tmp`,`venv-previous-${re()}`),o=g.join(e.repoRoot,`py`,`runtime-requirements.txt`),s=!1,c=!1;try{let n=await t.spawn([e.pythonPath,`-m`,`venv`,i]);if(n.code!==0)throw new X(`INSTALL_FAILED`,`venv failed: ${n.stderr.slice(0,400)}`);let l=g.join(i,`bin`,`python3`),u=e.assets===void 0?[]:[`--no-index`,`--find-links`,g.join(e.assets,`wheels`)],d=await t.spawn([l,`-m`,`pip`,`install`,`--only-binary=:all:`,`--require-hashes`,`-r`,o,...u],{env:{PIP_DISABLE_PIP_VERSION_CHECK:`1`}});if(d.code!==0){let e=`${d.stdout}\n${d.stderr}`;throw tl.test(e)?new X(`INSTALL_NO_WHEEL`,`a dependency has no wheel for this platform`):nl.test(e)?new X(`INSTALL_NETWORK`,`pip could not reach the package index`):new X(`INSTALL_FAILED`,`pip failed: ${d.stderr.slice(0,400)}`)}await xl(i,i,r);try{await Z(r)&&(await p(r,a),s=!0),await p(i,r)}catch(e){throw new X(`INSTALL_FAILED`,`cannot replace ${r}: ${String(e)}`,{cause:e})}let f=await yl(e.dataDir),m={...Y(f.packs)?f.packs:{},core:`ready`};await bl(e.dataDir,{...f,packs:m,python:e.pythonPath}),c=!0}finally{await Sl({venv:r,previousVenv:a,staging:i},s&&!c)}})}async function wl(e){try{return(await f(e,{recursive:!0})).some(e=>il.has(g.basename(e)))}catch{return!1}}async function Tl(e){return wl(g.join(e,`runtime`,`browsers`))}async function El(e){let{io:t}=e;return gl(e.dataDir,async()=>{let n=g.join(e.dataDir,`runtime`,`browsers`);await l(n,{recursive:!0});let r=await t.spawn([e.pythonPath,`-m`,`patchright`,`install`,`chromium`],{env:{PLAYWRIGHT_BROWSERS_PATH:n}});if(r.code!==0)throw new X(`INSTALL_BROWSER_FAILED`,`chromium install failed: ${r.stderr.slice(0,400)}`);if(!await wl(n))throw new X(`INSTALL_BROWSER_FAILED`,`no chromium executable found under ${n}`);let i=await yl(e.dataDir),a={...Y(i.packs)?i.packs:{},browser:`ready`};return await bl(e.dataDir,{...i,packs:a,browsersPath:n}),{browsersPath:n}})}function Dl(e,t){return e===`ready`?t?`ready`:`corrupt`:`missing`}async function Ol(e,t){if(!rl())return{core:`blocked`,browser:`blocked`,search:`blocked`,media:`blocked`,"adaptive-redis":`blocked`,mcp:`blocked`};let n=(await yl(e)).packs,r=Y(n)?n:{},i=Dl(r.core,await Z(g.join(e,`runtime`,`venv`,`bin`,`python3`))),a={core:i,browser:Dl(r.browser,await Tl(e)),search:i,media:i,"adaptive-redis":i,mcp:i};return t!==void 0&&(a[t]=`installing`),a}function kl(e){if(e?.aborted===!0)throw new X(`INSTALL_FAILED`,`install cancelled`)}async function Al(e,t,n,r,i){let a=Xc(e);return await Z(a)?a:(kl(n),(await vl(r,e,t,i)).pythonPath)}async function jl(e,t){if(!rl())throw new X(`INSTALL_PACK_BLOCKED`,`runtime packs are verified on macOS arm64 only; this host is ${process.platform}/${process.arch}`);let{dataDir:n,repoRoot:r,io:i,signal:a,onProgress:o,assets:s}=t,c=t.asset??Yc.darwinArm64;if(s!==void 0&&!await Z(g.join(s,`wheels`)))throw new X(`INSTALL_OFFLINE_ASSETS`,`offline wheelhouse missing: ${g.join(s,`wheels`)}`);kl(a),o?.(`installing ${e}`);let l=await Al(n,i,a,c,s);kl(a),o?.(`installing core packages into ${l}`),await Cl({pythonPath:l,dataDir:n,repoRoot:r,io:i,...s===void 0?{}:{assets:s}}),kl(a),e===`browser`&&(o?.(`installing full chromium`),await El({pythonPath:g.join(n,`runtime`,`venv`,`bin`,`python3`),dataDir:n,io:i}),kl(a)),o?.(`${e} ready`)}const Ml=jl;async function Nl(e,t){await gl(t.dataDir,async()=>{let n=g.join(t.dataDir,`runtime`),r=e===`browser`?`browsers`:`venv`;await m(g.join(n,r),{recursive:!0,force:!0}),t.purge&&(await Promise.all([``,`-wal`,`-shm`].map(e=>m(g.join(t.dataDir,`elements_storage.db${e}`),{force:!0}))),await m(g.join(t.dataDir,`downloads`),{recursive:!0,force:!0}));let i=await yl(t.dataDir);if(!Y(i.packs))return;let a={...i.packs};Reflect.deleteProperty(a,e),await bl(t.dataDir,{...i,packs:a})})}const Pl=/\r\n|\n|\r/u,Fl=/[\t ]#.*$/u,Il=/* @__PURE__ */ new Set([`core`,`browser`,`search`,`media`,`adaptive-redis`,`mcp`]),Ll=/* @__PURE__ */ new Set([`setup`,`doctor`]),Rl=/* @__PURE__ */ new Set([`status`,`apply`,`repair`,`purge`,`dry-run`,`with-auth`,`accept-risk`]),zl=/* @__PURE__ */ new Set([`port`,`mode`,`profile`,`offline`,`uninstall`,`feature`]);function Bl(){let e=process.env.DSH_SCRAPLING_DATA_DIR;return e===void 0||e===``?g.join(te.homedir(),`.dsh-scrapling`):g.resolve(e)}function Vl(e){return Il.has(e)}function Hl(e,t){if(!e.startsWith(`--`))return{kind:`invalid`};let n=e.slice(2);return Rl.has(n)?{kind:`boolean`,name:n}:!zl.has(n)||t===void 0||t.startsWith(`--`)?{kind:`invalid`}:{kind:`value`,name:n,value:t}}function Ul(e){let[t,...n]=e;if(t===void 0||!Ll.has(t))return null;let r=/* @__PURE__ */ new Map,i=/* @__PURE__ */ new Set;for(let[e,t]of n.entries())if(!i.has(e)){let a=Hl(t,n[e+1]);if(a.kind===`invalid`)return null;r.set(a.name,a.kind!==`value`||a.value),a.kind===`value`&&i.add(e+1)}return{command:t,flags:r}}function Wl(e){return{io:cl,dataDir:Bl(),repoRoot:g.resolve(import.meta.dirname,`..`),log:e=>{console.info(e)},installPackFn:jl,repairPackFn:Ml,uninstallPackFn:Nl,...e}}function Q(e,t){let n=e.get(t);return typeof n==`string`?n:void 0}function Gl(e){let t=Q(e,`port`);if(t===void 0)return{invalid:!1};let n=Number(t);return Number.isInteger(n)&&n>0&&n<=65535?{port:n,invalid:!1}:{invalid:!0}}function Kl(e){let t=Q(e,`mode`);return t===void 0||!pe(t)?null:t}function ql(e){let t=Q(e,`mode`),n=t===void 0?`(缺省)`:JSON.stringify(t);return`--mode 要写 ${de.join(` / `)} 之一;现在给的是 ${n}`}function Jl(e){if(e.mode===`native`)return{text:Je(),note:`native 模式不留 dsh-mcp-client 条目:原生工具已经在宿主名册里,再端一份就是两套。`,install:``};if(e.mode===`mcp`){let t=e.withAuth?`Authorization 在宿主装载时从宿主进程环境的 ${ce} 求值:变量缺席会写成 "Bearer undefined",加鉴权前先确认宿主环境里已设置它。`:``;return{text:qe({port:e.port,withAuth:e.withAuth}),note:`mcp 模式起的是本插件的 server,URL 里的端口要与部署项 mcpPort 同值(当前按 ${String(e.port)} 生成)。${t}`,install:he()}}let t=Se({dataDir:e.dataDir,enabled:e.enabled,acceptedRisk:e.acceptRisk});return{text:t.patch,note:t.risk,install:t.installCommand}}async function Yl(e,t){await l(g.dirname(e),{recursive:!0}),await ee(e,t,`utf8`)}async function Xl(e,t){let n=Kl(e);if(n===null)return t.log(ql(e)),2;let i=Gl(e);if(i.invalid)return t.log(`--port 要写 1 到 65535 之间的整数;现在给的是 ${String(Q(e,`port`))}`),2;let a=i.port??39217,o=Q(e,`profile`),s=o===void 0?void 0:await Ge(o),c=Jl({mode:n,port:a,withAuth:e.has(`with-auth`),acceptRisk:e.has(`accept-risk`),dataDir:t.dataDir,enabled:s?.officialMcpEnabled===!0});t.log(c.text),t.log(c.note),c.install!==``&&(t.log(`客户端没装就先跑:${c.install}`),t.log(`只接受 ${ue.join(` 或 `)}:npm 的 latest 比宿主线旧,宿主拒绝装载不匹配的对端。`));let l=g.join(t.dataDir,`mcp`,Ke(n));if(n===`official-mcp`){let e=_e(t.dataDir);r(e)||t.log(`${e} 现在还不存在:先跑 setup --feature mcp --apply 把官方 server 装进托管 venv;在那之前这条条目连不上(failOnStartupError: true 会让宿主把这条报成红)。`)}return!e.has(`apply`)||e.has(`dry-run`)?(t.log(`dry-run; add --apply to write ${l}`),0):(await Yl(l,c.text),t.log(`wrote ${l}`),t.log(`profile 不会被这条命令改写:把这段并进 <profile>/cordis.patch.yml,再重启宿主。`),0)}function Zl(e){let t=e.trim(),n=t.charAt(0);if(n===`"`||n===`'`){let e=t.indexOf(n,1);if(e>0)return t.slice(1,e)}return t.replace(Fl,``).trim()}function $(e,t){let n=RegExp(`^[\\t ]*(?:-[\\t ]+)?${t}:(?<value>[^\\r\\n]*)$`,`u`);return e.split(Pl).filter(e=>!e.trimStart().startsWith(`#`)).map(e=>Zl(n.exec(e)?.groups?.value??``)).find(e=>e!==``)}function Ql(e,t){return $(e,t)!==void 0}function $l(e,t){let n=$(e,t);return n===`true`||n===`True`||n===`TRUE`}async function eu(e){let t=Q(e,`profile`);if(t===void 0)return{profile:{path:null,pythonBin:null,dataDir:null,note:`未读 profile:runtime 只按 CLI 自身的解析链(pythonBin 配置 → 托管 runtime → 仓内 _env/.venv → PATH python3);要看部署配置解析出的解释器就加 --profile <目录>`},pythonBin:``};let n=await Ge(t),r=$(n.patchText,`pythonBin`)??``,i=$(n.patchText,`dataDir`)??``;return{profile:r===``?{path:t,pythonBin:null,dataDir:i===``?null:i,note:`profile 里没有 scrapling 的 pythonBin:runtime 回落到 CLI 自身的解析链(托管 runtime → 仓内 _env/.venv → PATH python3)`}:{path:t,pythonBin:r,dataDir:i===``?null:i},pythonBin:r,...i===``?{}:{dataDirOverride:i}}}async function tu(e,t){let{profile:n,pythonBin:r,dataDirOverride:i}=await eu(e),a=i??t.dataDir,o=$c({pythonBin:r,dataDir:a,repoRoot:t.repoRoot}),s=await yl(a),c=await Ol(a);return t.log(JSON.stringify({dataDir:a,profile:n,runtime:o,packs:c,state:s},null,2)),0}const nu={tavily:`tavilyApiKey`,brave:`braveApiKey`,serper:`serperApiKey`,searxng:`searxngEndpoint`};function ru(e){return e===void 0||Xe(e)?[]:[{code:`SEARCH_BACKEND_INVALID`,detail:`searchBackend=${e} 不是本包实现的后端:可写的取值是 ${Ye.join(` / `)},删掉这一行即回到 auto。`}]}function iu(e,t){let n=$(e,`searchProvider`),r=$(e,`searchBackend`),i=r??`auto`,a=$l(e,`searchPublicFallback`),o=Ql(e,`tavilyApiKey`),s=Ql(e,`searxngEndpoint`),c=i===`auto`&&!o&&!s&&!a,l=i===`auto`?void 0:nu[i],u=l!==void 0&&!Ql(e,l),d=n===`scrapling`,f=[],p=[];return n===void 0&&f.push(`SEARCH_PROVIDER_NOT_CONFIGURED 部署配置里还没写 searchProvider: scrapling:内置 web_search 仍走宿主自己选的 provider(base 层默认 deepseek-official),本插件的 search provider 只是备选。要接管它,给 <profile>/cordis.patch.yml 里 - id: web 的 config 加一行 searchProvider: scrapling,再重启宿主。`),c&&!d&&f.push(`SEARCH_BACKEND_MISSING 搜索后端未配置(预期行为):searchBackend=auto 但没配 tavilyApiKey、也没设 searxngEndpoint,且 searchPublicFallback=false,所以本插件的 search provider 不可用。修复:配 tavilyApiKey、设 searxngEndpoint,或显式把 searchPublicFallback 设为 true(会把查询词发给公共引擎)。`),u&&!d&&f.push(`SEARCH_AUTH searchBackend=${i} 但 ${l} 没配:查询会报 SEARCH_AUTH。修复:配 ${l},或换一个后端。`),p.push(...ru(r)),d&&!t&&p.push({code:`WEB_PROVIDER_CONFIGURED_UNAVAILABLE`,detail:`searchProvider 已指向 scrapling,但能力包没装好(core venv 不在 ready):web_search 会报 WEB_PROVIDER_CONFIGURED_UNAVAILABLE。修复:dsh-scrapling setup --feature core --apply。`}),d&&c&&p.push({code:`WEB_PROVIDER_CONFIGURED_UNAVAILABLE`,detail:`searchProvider 已指向 scrapling,但搜索后端不可用(没配 key/SearXNG,且 searchPublicFallback=false):web_search 会报 WEB_PROVIDER_CONFIGURED_UNAVAILABLE。修复:配 tavilyApiKey、设 searxngEndpoint,或显式打开 searchPublicFallback。`}),d&&u&&p.push({code:`SEARCH_AUTH`,detail:`searchBackend=${i} 但 ${l} 没配:provider 会注册成功,而每次查询都会报 SEARCH_AUTH。修复:配 ${l},或换一个后端。`}),{hints:f,findings:p}}async function au(e,t){let n=Kl(e);if(n===null)return t.log(ql(e)),2;let r=Q(e,`profile`);if(r===void 0)return t.log(`doctor 要 --profile <目录>:判据来自那份 profile 自己写下的 cordis.patch.yml。`),2;let i=Gl(e);if(i.invalid)return t.log(`--port 要写 1 到 65535 之间的整数;现在给的是 ${String(Q(e,`port`))}`),2;let a=await Ge(r),o=await Ol(t.dataDir),s=Re({mode:n,expectedPort:i.port,...a}),c=iu(a.patchText,o.core===`ready`);for(let e of c.hints)t.log(e);for(let e of s)t.log(`${e.code} ${e.detail}`);for(let e of c.findings)t.log(`${e.code} ${e.detail}`);let l=s.length+c.findings.length;return l===0?(t.log(`${r} 与 integrationMode=${n} 一致。`),0):(t.log(s.length>0?`${String(l)} 处不一致:改完重跑 setup --mode ${n} --apply,并把条目并进 profile 后重启宿主。`:`${String(l)} 处搜索配置不一致:按上面逐条的修复动作改 ${r} 里 web 条目的 config,重启宿主生效。`),1)}async function ou(e,t){let n=e.get(`uninstall`);if(typeof n!=`string`||!Vl(n))return 2;let r=e.has(`purge`);return t.log(`uninstall ${n}${r?` (and purge user data)`:``} from ${g.join(t.dataDir,`runtime`)}`),!e.has(`apply`)||e.has(`dry-run`)?(t.log(e.has(`dry-run`)?`dry-run:--dry-run 压过 --apply,只打印计划,不删任何 runtime 文件`:`dry-run; add --apply to uninstall`),0):(await gl(t.dataDir,async()=>{await t.uninstallPackFn(n,{dataDir:t.dataDir,purge:r})}),t.log(`uninstalled ${n}${r?` (purged data)`:``}`),0)}function su(e,t){let n=Yc.darwinArm64;return[`python ${n.pythonVersion} (${n.sizeBytes} bytes)`,e===`browser`?`full Chromium (~583M)`:`core wheels (~327M)`,`into ${g.join(t.dataDir,`runtime`)}`].join(`
|
|
119
|
+
`)}async function cu(e,t,n,r){await(n?t.repairPackFn:t.installPackFn)(e,{dataDir:t.dataDir,repoRoot:t.repoRoot,io:t.io,onProgress:t.log,...r===void 0?{}:{assets:r}})}async function lu(e,t){let n=e.get(`feature`);if(typeof n!=`string`||!Vl(n))return 2;let r=Q(e,`offline`);return r===``?(t.log(`--offline 要给一个资产目录`),2):(t.log(su(n,t)),r!==void 0&&t.log(`离线资产目录:${r}`),!e.has(`apply`)||e.has(`dry-run`)?(t.log(e.has(`dry-run`)?`dry-run:--dry-run 压过 --apply,只打印计划,不下载也不写 runtime`:`dry-run; add --apply to install`),0):(await cu(n,t,e.has(`repair`),r),t.log(`installed ${n}`),0))}function uu(e,t){return t.log(e instanceof X||e instanceof ge?`${e.code}: ${e.message}`:`command failed: ${String(e)}`),1}async function du(e,t={}){let n=Wl(t),r=Ul(e);if(r===null)return n.log(`用法:dsh-scrapling setup [--feature <core|browser|search|media|adaptive-redis|mcp>] [--mode <native|mcp|official-mcp>] [--profile <目录>] [--port <1-65535>] [--apply] [--repair] [--status] [--uninstall <包> [--purge]];dsh-scrapling doctor --mode <...> --profile <目录>`),2;let{flags:i}=r;try{return r.command===`doctor`?await au(i,n):i.has(`status`)?await tu(i,n):i.has(`mode`)?await Xl(i,n):i.has(`uninstall`)?await ou(i,n):await lu(i,n)}catch(e){return uu(e,n)}}process.exitCode=await du(process.argv.slice(2));export{};
|