@x-otto/install 0.0.1-alpha.0 → 0.0.1-alpha.1

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/dist/index.js CHANGED
@@ -1,9 +1,9 @@
1
- import{cpSync as e,createWriteStream as t,existsSync as n,mkdirSync as r,mkdtempSync as i,readFileSync as a,readdirSync as o,realpathSync as s,renameSync as c,rmSync as l,statSync as u,unlinkSync as d,writeFileSync as f}from"node:fs";import{homedir as p,tmpdir as m}from"node:os";import{basename as h,dirname as ee,join as g,relative as _,resolve as v}from"node:path";import{spawn as y,spawnSync as b}from"node:child_process";import{createLogger as x}from"@x-otto/shared";import{isShadowModeEnabled as S,normalizeEnv as C,resolveNpmSniffRegistries as te}from"@x-otto/env";import{parseSkillContent as ne}from"@x-otto/skill";import{HIGH_RISK_CAPABILITIES as re,PLUGIN_MANIFEST_FILENAME as ie,isPluginTrusted as ae,parsePluginManifest as oe,trustPlugin as se,untrustPlugin as ce}from"@x-otto/plugin";import{compare as le}from"semver";const ue=[`.zip`,`.tar.gz`,`.tgz`,`.tar`],de=6e4;async function fe(e,t,n){return new Promise(r=>{let i=y(e,t,{stdio:`pipe`,...n}),a=``,o=``;i.stdout?.on(`data`,e=>{a+=e.toString(`utf-8`)}),i.stderr?.on(`data`,e=>{o+=e.toString(`utf-8`)});let s=!1,c=!1,l=n.timeout?setTimeout(()=>{c=!0,i.kill()},n.timeout):void 0;i.on(`close`,(e,t)=>{l&&clearTimeout(l),s||(s=!0,r({stdout:a,stderr:o,status:e,signal:t,timedOut:c}))}),i.on(`error`,()=>{l&&clearTimeout(l),s||(s=!0,r({stdout:a,stderr:o,status:null,signal:null,timedOut:!1}))})})}async function pe(e,t){let n=async(e,t)=>{let{stderr:n,status:r,signal:i,timedOut:a}=await fe(e,t,{timeout:de});if(a)throw Error(`解压超时(${de/1e3}s)`);if(r!==0){let e=n.trim()||`exit code ${r}${i?` (${i})`:``}`;throw Error(`解压失败:${e}`)}},r=e.toLowerCase();if(r.endsWith(`.tar.gz`)||r.endsWith(`.tgz`)){await n(`tar`,[`xzf`,e,`-C`,t]);return}if(r.endsWith(`.tar`)){await n(`tar`,[`xf`,e,`-C`,t]);return}if(r.endsWith(`.zip`)){await n(`unzip`,[`-o`,`-q`,e,`-d`,t]);return}throw Error(`不支持的归档格式:${e}`)}async function me(e,t){let{stderr:n,status:r,signal:i,timedOut:a}=await fe(`tar`,[`czf`,t,`-C`,e,`.`],{timeout:de});if(a)throw Error(`打包超时(${de/1e3}s)`);if(r!==0){let e=n.trim()||`exit code ${r}${i?` (${i})`:``}`;throw Error(`打包失败:${e}`)}}function he(e){let t=v(e),n;try{n=s(e)}catch{n=t}let r=0,i=0,a=c=>{let l;try{l=o(c,{withFileTypes:!0})}catch{return}for(let o of l){let l=g(c,o.name);if(o.isSymbolicLink()){let t;try{t=s(l)}catch{throw Error(`安全拒绝:归档包含断链 "${_(e,l)}"`)}if(!t.startsWith(n+`/`)&&t!==n)throw Error(`安全拒绝:归档包含越界链接 "${_(e,l)}" → "${t}"`);try{u(l).isDirectory()&&a(l)}catch{}continue}if(!v(l).startsWith(t+`/`)&&v(l)!==t)throw Error(`安全拒绝:归档包含越界路径 "${_(e,l)}"`);if(o.isDirectory()){a(l);continue}if(o.isFile()){if(r++,r>1e4)throw Error(`安全拒绝:归档包含超过 10000 个文件`);try{i+=u(l).size}catch{}if(i>104857600)throw Error(`安全拒绝:归档总大小超过 100MB`)}}};return a(e),{totalBytes:i}}function ge(e,t){let n;try{n=u(e).size}catch{return}if(n===0)throw Error(`安全拒绝:归档文件为空`);let r=t/n;if(r>100)throw Error(`安全拒绝:压缩比异常(${Math.round(r)}:1,上限 100:1)`)}function _e(){return i(g(m(),`otto-install-`))}function w(e){try{n(e)&&l(e,{recursive:!0,force:!0})}catch{}}function T(e){return e.replace(/\/\/[^@]+@/,`//`)}function ve(t){let n=_e();try{e(t,n,{recursive:!0,verbatimSymlinks:!0,filter:e=>!e.includes(`/node_modules/`)&&!e.endsWith(`/node_modules`)});let{totalBytes:r}=he(n);return{tempDir:n,sourceUrl:T(h(t)),sourceType:`file`}}catch(e){throw w(n),e}}async function ye(e){if(!n(e))throw Error(`文件不存在:${e}`);if(u(e).isDirectory())return ve(e);let t=h(e);if(!ue.some(e=>t.endsWith(e)))throw Error(`不支持的归档格式:${t}。支持 .zip、.tar.gz、.tgz、.tar(或直接传目录路径)`);let r=_e();try{await pe(e,r);let{totalBytes:n}=he(r);return ge(e,n),{tempDir:r,sourceUrl:T(t),sourceType:`file`}}catch(e){throw w(r),e}}const be=x(`@x-otto/coding:install:url-resolver`),xe=C(process.env.OTTO_DOWNLOAD_TIMEOUT_MS,3e4),Se=C(process.env.OTTO_DOWNLOAD_MAX_REDIRECTS,3),Ce=100*1024*1024;async function we(e,t){let r=h(new URL(e).pathname)||`download`,i=r.toLowerCase();if(!ue.some(e=>i.endsWith(e)))throw Error(`URL 文件类型不支持:${r}。请提供 .zip、.tar.gz、.tgz 或 .tar 归档。`);let a=g(m(),`otto-download-${Date.now()}-${r}`),o=_e();try{await Te(e,a,t)}catch(e){w(o);try{n(a)&&d(a)}catch{}throw e}try{await pe(a,o);let{totalBytes:e}=he(o);ge(a,e)}catch(e){throw w(o),e}finally{try{n(a)&&d(a)}catch{}}return{tempDir:o,sourceUrl:T(e),sourceType:`url`}}async function Te(e,n,r){let i=e;for(let a=0;a<=Se;a++){let o=await fetch(i,{signal:AbortSignal.timeout(xe),redirect:`manual`});if(o.status>=300&&o.status<400&&o.headers.get(`location`)){i=o.headers.get(`location`),be.info(`Redirecting (%d/%d): %s → %s`,a+1,Se,e,i);continue}if(!o.ok){let e=o.status===404?`(URL 指向的文件不存在——核对下载地址)`:o.status===403||o.status===401?`(无访问权限——该资源可能需要登录或已过期)`:``;throw Error(`下载失败:HTTP ${o.status} ${o.statusText}${e}`)}let s=o.headers.get(`content-length`);if(s){let e=Number(s);if(Number.isFinite(e)&&e>Ce)throw Error(`文件过大:${Math.round(e/1024/1024)}MB,上限 ${Math.round(Ce/1024/1024)}MB`)}if(!o.body)throw Error(`下载失败:响应体为空`);let c=t(n),l=o.body.getReader(),u=0,d=0,f=s&&Number.isFinite(Number(s))?Number(s):void 0,p=f===void 0?262144:Math.max(f*.03,65536);try{for(;;){let{done:e,value:t}=await l.read();if(e)break;if(u+=t.byteLength,u>Ce)throw Error(`下载文件过大(超过 ${Math.round(Ce/1024/1024)}MB)`);r&&u-d>=p&&(d=u,r(u,f)),c.write(t)||await new Promise(e=>c.once(`drain`,e))}r&&u!==d&&r(u,f)}finally{l.releaseLock(),c.end(),await new Promise((e,t)=>{c.on(`finish`,e),c.on(`error`,t)})}return}throw Error(`下载失败:重定向次数超过上限 (${Se})`)}const Ee=C(process.env.OTTO_GIT_CLONE_TIMEOUT_MS,3e4);async function E(e,t){return new Promise(n=>{let r=y(`git`,e,{stdio:`pipe`,...t}),i=``,a=``;r.stdout?.on(`data`,e=>{i+=e.toString(`utf-8`)}),r.stderr?.on(`data`,e=>{a+=e.toString(`utf-8`)});let o=!1,s=!1,c=t.timeout?setTimeout(()=>{s=!0,r.kill()},t.timeout):void 0;r.on(`close`,e=>{c&&clearTimeout(c),o||(o=!0,n({stdout:i,stderr:a,status:e,timedOut:s}))}),r.on(`error`,()=>{c&&clearTimeout(c),o||(o=!0,n({stdout:i,stderr:a,status:null,timedOut:!1}))})})}async function De(e,t){let n=_e();return t===void 0?Oe(e,n):ke(e,n,t)}async function Oe(e,t){let n=await E([`clone`,`--depth`,`1`,`--quiet`,`--`,e,t],{timeout:Ee});if(n.timedOut)throw w(t),Error(`git clone 超时(${Ee/1e3}s)`);if(n.status!==0)throw w(t),Error(`git clone 失败:${je(n.stderr)}`);let r=await Ae(t);return{tempDir:t,sourceUrl:T(e),sourceType:`git`,commit:r}}async function ke(e,t,n){let r=await E([`init`,`--quiet`,t],{timeout:5e3});if(r.status!==0)throw w(t),Error(`git init 失败:${r.stderr.trim()||`unknown error`}`);let i=await E([`fetch`,`--depth`,`1`,`--quiet`,`--`,e,n],{cwd:t,timeout:Ee});if(i.timedOut)throw w(t),Error(`git fetch 超时(${Ee/1e3}s)`);if(i.status!==0){w(t);let e=i.stderr.trim()||`unknown error`,r=/couldn't find remote ref|fatal: remote error|unable to negotiate|no such ref/i.test(e)?`(ref '${n}' 不存在,或不是合法的 tag/branch 名——commit hash 精确 pin 暂不支持,因主流 git 托管方默认拒绝按任意 commit fetch)`:``;throw Error(`git fetch ref '${n}' 失败:${je(e)}${r}`)}let a=await E([`checkout`,`--quiet`,`FETCH_HEAD`],{cwd:t,timeout:1e4});if(a.status!==0)throw w(t),Error(`git checkout FETCH_HEAD 失败:${a.stderr.trim()||`unknown error`}`);let o=await Ae(t);return{tempDir:t,sourceUrl:T(e),sourceType:`git`,commit:o}}async function Ae(e){try{let t=await E([`rev-parse`,`HEAD`],{cwd:e,timeout:5e3});return t.status===0?t.stdout.trim():void 0}catch{return}}function je(e){let t=e.trim()||`unknown error`;return`${t}${/not found|repository.*does not exist/i.test(t)?`(仓库地址可能有误或为私有仓库——核对 URL;私有仓库需先配置 git 凭据)`:/permission denied|authentication failed|could not read/i.test(t)?`(无访问权限——私有仓库需配置 SSH key 或 git 凭据)`:/could not resolve host|unable to access/i.test(t)?`(网络不可达——检查网络连接后重试)`:``}`}function Me(){return[...te(),`https://registry.npmjs.org`]}async function Ne(e,t=5e3){for(let n of Me()){let r=`${n}/${encodeURIComponent(e)}`,i=new AbortController,a=setTimeout(()=>i.abort(),t);try{let e=await fetch(r,{signal:i.signal});if(e.ok){let t=await e.json(),r=t[`dist-tags`];if(r){let e=r.latest??r.alpha??Pe(r);if(e)return{version:e,registry:n}}if(t?.version)return{version:t.version,registry:n}}}catch{}finally{clearTimeout(a)}}return null}function Pe(e){let t;for(let n of Object.values(e))(!t||Fe(n,t)>0)&&(t=n);return t}function Fe(e,t){let n=/(\d+)\.(\d+)\.(\d+)/.exec(e),r=/(\d+)\.(\d+)\.(\d+)/.exec(t);if(n&&r)for(let e=1;e<=3;e++){let t=Number(n[e])-Number(r[e]);if(t!==0)return t}return e<t?-1:e>t?1:0}const Ie=C(process.env.OTTO_NPM_PACK_TIMEOUT_MS,6e4);function Le(e){let t=e.indexOf(`@`,e.startsWith(`@`)?1:0);return t>0?e.slice(0,t):e}async function Re(e){let t=i(g(m(),`otto-npm-`)),r=i(g(m(),`otto-npm-extract-`)),a=(await Ne(Le(e)).catch(()=>null))?.registry;try{let{stderr:i,status:o,timedOut:s}=await ze(e,t,a);if(s)throw Error(`npm pack 超时(${Ie/1e3}s)`);if(o!==0){let e=i.trim()||`exit code ${o}`,t=/404|E404/.test(e)?`(包名可能拼写有误——用 /search <关键词> 在 registry 中查找,或核对 npmjs.com)`:/ENOTFOUND|ETIMEDOUT|ECONNREFUSED|network/i.test(e)?`(网络不可达——检查网络连接或 npm registry 配置后重试)`:``;throw Error(`npm pack 失败:${e}${t}`)}let c=Be(t);if(!c)throw Error(`npm pack 未生成 .tgz 文件:${e}`);await pe(c,r);let{totalBytes:l}=he(r);ge(c,l);try{Ve(t)}catch{}let u=g(r,`package`);return n(u)?{tempDir:u,sourceUrl:`npm:${e}`,sourceType:`npm`}:{tempDir:r,sourceUrl:`npm:${e}`,sourceType:`npm`}}catch(e){throw Ve(t),Ve(r),e}}async function ze(e,t,n){return new Promise(r=>{let i=[`pack`,e,`--pack-destination`,t,`--quiet`];n&&i.push(`--registry`,n);let a=y(`npm`,i,{stdio:`pipe`}),o=``,s=``;a.stdout?.on(`data`,e=>{o+=e.toString(`utf-8`)}),a.stderr?.on(`data`,e=>{s+=e.toString(`utf-8`)});let c=!1,l=!1,u=setTimeout(()=>{l=!0,a.kill()},Ie);a.on(`close`,e=>{clearTimeout(u),c||(c=!0,r({stdout:o,stderr:s,status:e,timedOut:l}))}),a.on(`error`,()=>{clearTimeout(u),c||(c=!0,r({stdout:o,stderr:s,status:null,timedOut:!1}))})})}function Be(e){try{let t=o(e);for(let n of t)if(n.endsWith(`.tgz`)||n.endsWith(`.tar.gz`))return g(e,n)}catch{}return null}function Ve(e){try{n(e)&&l(e,{recursive:!0,force:!0})}catch{}}function He(e){let t=g(e,`SKILL.md`);if(n(t))return[t];let r=[];try{let t=o(e);for(let i of t){let t=g(e,i);try{if(!u(t).isDirectory())continue}catch{continue}let a=g(t,`SKILL.md`);n(a)&&r.push(a)}}catch{}return r}function Ue(e){let t=He(e);return t.length>0?t[0]:null}function We(e){let t=Ue(e);if(!t)throw Error(`未找到 SKILL.md。skill 包必须包含一个 SKILL.md 文件(位于根目录或一层子目录下)。`);let n=a(t,`utf-8`),r=g(t,`..`);try{return ne(n,t,r)}catch(e){throw Error(`SKILL.md 解析失败:${e instanceof Error?e.message:String(e)}`)}}function Ge(e,t){let r=n(g(e,ie)),i=Ue(e)!==null,a=n(g(e,`.mcp.json`));if(t)return Ke(e,t);let o=[];if(r&&o.push(`plugin`),i&&o.push(`skill`),a&&o.push(`mcp`),o.length===0)throw Error(`未检测到可安装内容。需要 otto-plugin.json(plugin)、SKILL.md(skill)或 .mcp.json(mcp)。如确定类型,请使用 --as 指定。`);if(o.length>1)throw Error(`检测到多种内容类型:${o.join(` + `)}。无法自动判定,请使用 --as ${o.join(` 或 --as `)} 指定。`);return Ke(e,o[0])}function Ke(e,t){switch(t){case`skill`:return qe(e);case`plugin`:return Je(e);case`mcp`:return Ye(e)}}function qe(e){let t=He(e);if(t.length===0)throw Error(`未找到 SKILL.md。skill 包必须包含一个 SKILL.md 文件。`);let n=[];for(let e of t)try{let t=a(e,`utf-8`),r=g(e,`..`);n.push(ne(t,e,r))}catch(t){throw Error(`${e}: ${t instanceof Error?t.message:String(t)}`)}if(new Set(n.map(e=>e.metadata.name)).size!==n.length){let e=n.filter((e,t,n)=>n.findIndex(t=>t.metadata.name===e.metadata.name)!==t).map(e=>`"${e.metadata.name}" (${e.filePath})`).join(`, `);throw Error(`检测到同名 skill:${e}。请修改 SKILL.md 中的 name 字段使其唯一。`)}return{type:`skill`,skillDef:n.length===1?n[0]:void 0,skillDefs:n}}function Je(e){let t=g(e,ie);if(!n(t))throw Error(`未找到 ${ie}。`);let r=oe(a(t,`utf-8`),t);if(!r)throw Error(`${ie} 格式无效(缺少 id 字段或 JSON 解析失败)。`);return{type:`plugin`,pluginManifest:r}}function Ye(e){let t=g(e,`.mcp.json`),r;if(n(t)){let e=a(t,`utf-8`);try{r=JSON.parse(e)}catch{throw Error(`.mcp.json 格式无效(JSON 解析失败)。`)}}else r={};return{type:`mcp`,mcpConfig:r}}const Xe=/^[a-z0-9][a-z0-9-]*[a-z0-9]$|^[a-z0-9]$/;function Ze(t,a,o){let s;if(o)s=o;else try{s=We(t)}catch(e){return{success:!1,error:e instanceof Error?e.message:String(e)}}let u=s.metadata.name;if(!Xe.test(u))return{success:!1,error:`skill 名称 "${u}" 不符合命名规范。仅允许小写字母、数字和连字符(kebab-case),例如 "my-skill"。`};let d=a.global?g(p(),`.otto`,`skills`):a.workspaceDir?g(a.workspaceDir,`.otto`,`skills`):g(process.cwd(),`.otto`,`skills`),h=g(d,u),v=n(h);if(a.dryRun){let e=Qe(s.directory);return{success:!0,name:u,targetPath:h,definition:s,plan:[`来源:${s.directory}`,`目标:${h}`,`模式:${a.global?`全局`:`项目`}级`,v?`操作:覆盖(--force)`:`操作:新建`,`文件(${e.length}):`,...e.map(e=>` ${e}`)]}}if(v&&!a.force)return{success:!1,name:u,error:`skill "${u}" 已存在于 ${h}。`,failureKind:`conflict`};let y=i(g(m(),`otto-staging-`)),b=[];try{if(r(d,{recursive:!0}),e(s.directory,y,{recursive:!0}),a.sourceMetadata)try{let e={sourceType:a.sourceMetadata.sourceType,sourceUrl:a.sourceMetadata.sourceUrl,commit:a.sourceMetadata.commit,subPath:_(t,s.directory)||void 0,installedAt:new Date().toISOString(),installedBy:`user`,installerVersion:process.env.OTTO_VERSION??`unknown`};f(g(y,`.otto-install.json`),JSON.stringify(e,null,2)+`
2
- `)}catch(e){b.push(`无法写入安装元数据:${e instanceof Error?e.message:String(e)}`)}if(v){let e=g(ee(h),`.${u}.bak`);try{l(e,{recursive:!0,force:!0})}catch{}try{c(h,e)}catch(e){return l(y,{recursive:!0,force:!0}),{success:!1,name:u,error:`无法替换已有 skill 目录:${e instanceof Error?e.message:String(e)}`}}try{c(y,h)}catch(t){try{c(e,h)}catch{}return l(y,{recursive:!0,force:!0}),{success:!1,name:u,error:`安装失败:${t instanceof Error?t.message:String(t)}`}}try{l(e,{recursive:!0,force:!0})}catch{}}else try{c(y,h)}catch(e){return l(y,{recursive:!0,force:!0}),{success:!1,name:u,error:`安装失败:${e instanceof Error?e.message:String(e)}`}}}catch(e){try{l(y,{recursive:!0,force:!0})}catch{}return{success:!1,name:u,error:`安装失败:${e instanceof Error?e.message:String(e)}`}}return{success:!0,name:u,targetPath:h,definition:s,...b.length>0?{warnings:b}:{}}}function Qe(e){let t=[],n=[{dir:e,prefix:``}];for(;;){let e=n.pop();if(!e)break;let r=o(e.dir,{withFileTypes:!0});for(let i of r){let r=e.prefix?`${e.prefix}/${i.name}`:i.name;i.isDirectory()?n.push({dir:g(e.dir,i.name),prefix:r}):t.push(r)}}return t.sort()}function $e(e){return(e.capabilities??[]).filter(e=>re.includes(e))}const et={provider:`provider —— 注册 LLM provider,将处理你的凭据与请求流量`,tools:`tools —— 注册可被 agent 调用的工具`,"tui.renderer":`tui.renderer —— 在 TUI 进程内运行自定义渲染代码`,network:`network —— 发起任意网络请求`};async function tt(t,a,o){let s=a.id,u=o.global?g(p(),`.otto`,`plugins`):o.workspaceDir?g(o.workspaceDir,`.otto`,`plugins`):g(process.cwd(),`.otto`,`plugins`),d=g(u,s),h=n(d);if(o.dryRun){let e=$e(a);return{success:!0,name:s,targetPath:d,manifest:a,pendingCapabilities:e.length>0?e:void 0,plan:[`类型:plugin`,`名称:${a.name??s}`,`来源:${t}`,`目标:${d}`,`模式:${o.global?`全局`:`项目`}级`,h?`操作:覆盖(--force)`:`操作:新建`,`信任策略:${o.global?`自动信任(用户级)`:`安装后自动信任`}`,...a.scripts?.postinstall?[`⚠ postinstall(安装后立即执行 shell):${a.scripts.postinstall}`]:[],...a.scripts?.setup?[`⚠ setup(首次加载执行 shell):${a.scripts.setup}`]:[],...e.length>0?[`⚠ 高危能力(安装后需另行 /trust plugin ${s} 显式授予,默认不生效):`,...e.map(e=>` • ${et[e]??e}`)]:[]]}}if(h&&!o.force)return{success:!1,name:s,error:`plugin "${s}" 已存在于 ${d}。`,failureKind:`conflict`};let _=i(g(m(),`otto-staging-plugin-`)),v=[];try{if(r(u,{recursive:!0}),e(t,_,{recursive:!0}),o.sourceMetadata)try{let e={sourceType:o.sourceMetadata.sourceType,sourceUrl:o.sourceMetadata.sourceUrl,commit:o.sourceMetadata.commit,subPath:o.sourceMetadata.subPath,installedAt:new Date().toISOString(),installedBy:`user`,installerVersion:process.env.OTTO_VERSION??`unknown`};f(g(_,`.otto-install.json`),JSON.stringify(e,null,2)+`
3
- `)}catch(e){v.push(`无法写入安装元数据:${e instanceof Error?e.message:String(e)}`)}if(h){let e=g(ee(d),`.${s}.bak`);try{l(e,{recursive:!0,force:!0})}catch{}try{c(d,e)}catch(e){return l(_,{recursive:!0,force:!0}),{success:!1,name:s,error:`无法替换已有 plugin 目录:${e instanceof Error?e.message:String(e)}`}}try{c(_,d)}catch(t){try{c(e,d)}catch{}return l(_,{recursive:!0,force:!0}),{success:!1,name:s,error:`安装失败:${t instanceof Error?t.message:String(t)}(已恢复旧版本)`}}try{l(e,{recursive:!0,force:!0})}catch{}}else try{c(_,d)}catch(e){return l(_,{recursive:!0,force:!0}),{success:!1,name:s,error:`安装失败:${e instanceof Error?e.message:String(e)}`}}}catch(e){try{l(_,{recursive:!0,force:!0})}catch{}return{success:!1,name:s,error:`安装失败:${e instanceof Error?e.message:String(e)}`}}let y=!1;if(!o.global)try{se(d),y=!0}catch{}let b=[...v],x;if(a.scripts?.postinstall&&o.postInstallExecutor)if(o.global||ae(d)){if(x=await o.postInstallExecutor({pluginDir:d,pluginId:s,workspaceDir:o.workspaceDir},a.scripts.postinstall),!x.success){let e=x.timeout?`postinstall 超时 (30s): ${a.scripts.postinstall}`:x.error?`postinstall 错误: ${x.error}`:`postinstall 返回非零 (exit=${x.exitCode}): ${a.scripts.postinstall}`;b.push(e)}}else{let e=o.global?void 0:`postinstall 跳过:插件信任持久化失败,使用 isPluginTrusted 验证未通过`;e&&b.push(e)}else a.scripts?.postinstall&&!o.postInstallExecutor?b.push(`postinstall 跳过:当前环境中未配置钩子执行器`):!o.global&&!y&&b.push(`插件信任持久化失败,可执行面(.mcp.json/commands/scripts)下次加载时将被门控`);let S=$e(a);return S.length>0&&b.push(`插件声明高危能力(${S.join(`, `)})尚未授予——运行 /trust plugin ${s} 完成确认后方可生效`),{success:!0,name:s,targetPath:d,manifest:a,pendingCapabilities:S.length>0?S:void 0,...x?{postinstall:x}:{},...b.length>0?{warnings:b}:{}}}async function nt(e,t,n,r,i){let a=n.global?`全局`:`项目`;if(n.dryRun){let n=t.type??(t.command?`stdio`:`http`);return{success:!0,name:e,mcpConfig:t,plan:[`类型:mcp`,`名称:${e}`,`传输:${n}`,`${t.command?`命令:${t.command} ${(t.args??[]).join(` `)}`:``}`,`${t.url?`URL:${t.url}`:``}`,`模式:${a}级`,`操作:写入 settings.mcp_servers.${e}`].filter(e=>!!e)}}let o=r()??{};if(e in o&&!n.force)return{success:!1,name:e,error:`MCP server "${e}" 已存在。`,failureKind:`conflict`};let s={...o,[e]:t};try{await i(s)}catch(t){return{success:!1,name:e,error:`写入 MCP 配置失败:${t instanceof Error?t.message:String(t)}`}}return{success:!0,name:e,mcpConfig:t}}const rt=/^https?:\/\//,it=/^(git@|git:\/\/|ssh:\/\/)|\.git$|(?<!https?:\/\/)\b(github\.com|gitlab\.com|bitbucket\.org)\b/;var at=class{async install(e,t,n,r){let i,a;try{let o=t.type??ot(e);D(t,{phase:`resolving`,message:`Resolving ${o} source...`});let s=t.onProgress&&!t.dryRun?(e,n)=>{D(t,{phase:`resolving`,message:`Resolving ${o} source...`,bytesDownloaded:e,bytesTotal:n})}:void 0;a=await dt(e,o,t.ref,s),i=a.tempDir;let c=i;if(t.subPath){let{resolve:e,sep:n}=await import(`node:path`),r=e(i,t.subPath);if(r!==i&&!r.startsWith(i+n))throw Error(`subPath 越出来源根目录:${t.subPath}`);let{existsSync:a}=await import(`node:fs`);if(!a(r))throw Error(`subPath 不存在于来源中:${t.subPath}`);c=r}D(t,{phase:`detecting`,message:`Detecting installed content...`});let l=Ge(c,t.as),u=l.type;switch(u){case`skill`:{let e=l.skillDefs??(l.skillDef?[l.skillDef]:[]);if(e.length===0)throw Error(`skill 检测失败:无法解析 SKILL.md`);let n={...t,sourceMetadata:{sourceType:o,sourceUrl:a.sourceUrl,commit:a.commit}};if(e.length===1)return D(t,{phase:`installing`,message:`Installing ${e[0].metadata.name}`,current:1,total:1}),Ze(c,n,e[0]);let r=c,i=[];for(let a=0;a<e.length;a++)D(t,{phase:`installing`,message:`Installing ${e[a].metadata.name}`,current:a+1,total:e.length}),i.push(Ze(r,n,e[a]));let s=i.every(e=>e.success);return{success:s,name:`${e.length} skills`,error:s?void 0:lt(i),failureKind:s?void 0:ut(i),plan:t.dryRun?i.map((t,n)=>{let r=(e[n].supportingFiles?.length??0)+1;return`${t.name??`?`} → ${t.targetPath??`?`} (${r} 文件)`}):void 0,results:i,warnings:i.flatMap(e=>e.warnings??[]),targetPath:i[0]?.targetPath}}case`plugin`:{if(!l.pluginManifest)throw Error(`plugin 检测失败:无法解析 otto-plugin.json`);D(t,{phase:`installing`,message:`Installing ${l.pluginManifest.id}`,current:1,total:1});let e={...t,sourceMetadata:{sourceType:o,sourceUrl:a.sourceUrl,commit:a.commit}};return await tt(c,l.pluginManifest,e)}case`mcp`:{if(!n||!r)return{success:!1,error:`MCP 安装需要 settings 访问权限。请在 CLI 环境中执行。`};let e=l.mcpConfig?.url?new URL(l.mcpConfig.url).hostname.replace(/\./g,`-`):l.mcpConfig?.command?l.mcpConfig.command.replace(/[^a-z0-9-]/g,`-`).slice(0,40):`mcp-server`,i={...l.mcpConfig,...t.env?{env:{...l.mcpConfig?.env??{},...t.env}}:{}};return D(t,{phase:`installing`,message:`Installing MCP ${e}`,current:1,total:1}),nt(e,i,t,n,r)}default:return{success:!1,error:`不支持的内容类型:${u}`}}}catch(e){return{success:!1,error:e instanceof Error?e.message:String(e)}}finally{i&&w(i)}}async installSkill(e,t){return this.install(e,{...t,as:`skill`})}};function ot(e){return it.test(e)?`git`:rt.test(e)?`url`:st(e)?`file`:`npm`}function st(e){return/^@[^/]+\/[^/]+$/.test(e)?!1:!!(/\.(zip|tar\.gz|tgz|tar)$/i.test(e)||e.includes(`/`)||e.includes(`\\`))}function ct(e){return e.replace(/[。.]\s*$/,``)}function lt(e){let t=e.filter(e=>!e.success),n=t.map(e=>`${e.name??`?`} —— ${ct(e.error??`unknown error`)}`).join(`;`);return`${t.length}/${e.length} 个 skill 安装失败:${n}`}function ut(e){let t=e.filter(e=>!e.success);if(t.length!==0)return t.every(e=>e.failureKind===`conflict`)?`conflict`:void 0}function D(e,t){if(e.onProgress&&!(e.dryRun&&t.phase!==`resolving`&&t.phase!==`detecting`))try{e.onProgress(t)}catch{}}async function dt(e,t,n,r){switch(t){case`file`:return ye(e);case`url`:return we(e,r);case`git`:return De(e,n);case`npm`:return Re(e)}}function ft(e,t,r){let i=t.global?g(p(),`.otto`):t.workspaceRoot?g(t.workspaceRoot,`.otto`):t.workspaceDir?g(t.workspaceDir,`.otto`):g(process.cwd(),`.otto`);return n(g(i,`skills`,e))?`skill`:n(g(i,`plugins`,e))?`plugin`:r&&e in r?`mcp`:null}function O(e){try{return o(e,{withFileTypes:!0}).filter(e=>e.isDirectory()).map(e=>e.name)}catch{return[]}}function pt(e,t){let n=[],r=e.workspaceDir??process.cwd(),i=!e.scope||e.scope===`global`,a=!e.scope||e.scope===`project`,o=!e.scope||e.scope===`repository`;if(i){let e=g(p(),`.otto`);O(g(e,`skills`)).forEach(e=>n.push({name:e,type:`skill`,scope:`global`})),O(g(e,`plugins`)).forEach(e=>n.push({name:e,type:`plugin`,scope:`global`}))}if(a){let e=g(r,`.otto`);O(g(e,`skills`)).forEach(e=>n.push({name:e,type:`skill`,scope:`project`})),O(g(e,`plugins`)).forEach(e=>n.push({name:e,type:`plugin`,scope:`project`})),t&&Object.entries(t).forEach(([e,t])=>{let r=t.command??t.url;n.push({name:e,type:`mcp`,scope:`project`,detail:r})})}if(o&&e.workspaceRoot){let t=g(e.workspaceRoot,`.otto`);O(g(t,`skills`)).forEach(e=>n.push({name:e,type:`skill`,scope:`repository`})),O(g(t,`plugins`)).forEach(e=>n.push({name:e,type:`plugin`,scope:`repository`}))}let s=new Map;for(let e of n){let t=`${e.type}:${e.name}`;(!s.has(t)||e.scope===`global`)&&s.set(t,e)}return[...s.values()]}async function mt(e,t,r,i,a){if(e.includes(`/`)||e.includes(`\\`)||e.includes(`..`))return{success:!1,name:e,type:t,error:`非法名称(含路径分隔符或 ..):${e}`};let o=r.global?g(p(),`.otto`):r.workspaceRoot?g(r.workspaceRoot,`.otto`):r.workspaceDir?g(r.workspaceDir,`.otto`):g(process.cwd(),`.otto`),s=r.global?`全局`:r.workspaceRoot?`仓库`:`项目`;switch(t){case`skill`:{let i=g(o,`skills`,e);if(r.dryRun)return{success:!0,name:e,type:t,plan:[`类型:skill`,`名称:${e}`,`路径:${i}`,`模式:${s}级`,`操作:删除目录`]};if(!n(i))return{success:!1,name:e,type:t,error:`skill "${e}" 不存在于 ${i}`};try{l(i,{recursive:!0,force:!0})}catch(n){return{success:!1,name:e,type:t,error:`删除失败:${n instanceof Error?n.message:String(n)}`}}return{success:!0,name:e,type:t}}case`plugin`:{let i=g(o,`plugins`,e);if(r.dryRun)return{success:!0,name:e,type:t,plan:[`类型:plugin`,`名称:${e}`,`路径:${i}`,`模式:${s}级`,`操作:删除目录 + 撤销信任记录`]};if(!n(i))return{success:!1,name:e,type:t,error:`plugin "${e}" 不存在于 ${i}`};try{try{ce(i)}catch{}l(i,{recursive:!0,force:!0})}catch(n){return{success:!1,name:e,type:t,error:`删除失败:${n instanceof Error?n.message:String(n)}`}}return{success:!0,name:e,type:t}}case`mcp`:{if(!i||!a)return{success:!1,name:e,type:t,error:`MCP 卸载需要 settings 访问权限`};let n={...i()??{}};if(!(e in n))return{success:!1,name:e,type:t,error:`MCP server "${e}" 不存在`};if(r.dryRun){let r=n[e];return{success:!0,name:e,type:t,plan:[`类型:mcp server`,`名称:${e}`,`命令:${r?.command??`(URL)`}`,`模式:${s}级`,`操作:从 settings.mcp_servers 删除配置`]}}delete n[e];try{await a(n)}catch(n){return{success:!1,name:e,type:t,error:`删除 MCP 配置失败:${n instanceof Error?n.message:String(n)}`}}return{success:!0,name:e,type:t}}}}function ht(e){let t=[];if(e.scope===void 0||e.scope===`all`||e.scope===`project`){let n=e.workspaceDir?g(e.workspaceDir,`.otto`):g(process.cwd(),`.otto`);k(g(n,`skills`),`skill`,t),k(g(n,`plugins`),`plugin`,t)}if((e.scope===void 0||e.scope===`all`||e.scope===`repository`)&&e.workspaceRoot){let n=g(e.workspaceRoot,`.otto`);k(g(n,`skills`),`skill`,t),k(g(n,`plugins`),`plugin`,t)}if(e.scope===void 0||e.scope===`all`||e.scope===`global`){let e=g(p(),`.otto`);k(g(e,`skills`),`skill`,t),k(g(e,`plugins`),`plugin`,t)}return t}function k(e,t,r){if(!n(e))return;let i;try{i=o(e)}catch{return}for(let o of i){let i=g(e,o);try{if(!u(i).isDirectory())continue}catch{continue}if(t===`skill`){let e=g(i,`SKILL.md`);if(!n(e))continue;try{let n=ne(a(e,`utf-8`),e,i);n.metadata.version&&r.push({name:n.metadata.name,type:t,installed:n.metadata.version,path:i})}catch{}}else{let e=g(i,`otto-plugin.json`);if(!n(e))continue;try{let n=oe(a(e,`utf-8`),e);n?.version&&r.push({name:n.id,type:t,installed:n.version,path:i})}catch{}}}}async function gt(e){let t=[];for(let n of e){let e=_t(n.path);if(e===`git`){let e=await St(n.path,n.name,n.type);if(e){t.push(e);continue}t.push({name:n.name,type:n.type,installed:n.installed,error:`无法检查升级(.otto-install.json 声明 git 来源但缺 commit/sourceUrl)`});continue}if(e===`file`||e===`url`){t.push({name:n.name,type:n.type,installed:n.installed,error:`无法检查升级(${e} 来源不支持版本比对)`});continue}if(e===void 0&&!vt(n.name)){let e=await St(n.path,n.name,n.type);if(e){t.push(e);continue}t.push({name:n.name,type:n.type,installed:n.installed,error:`无法检查升级(非 npm 来源且无 .otto-install.json)`});continue}try{let e=await yt(n.name);if(!e){t.push({name:n.name,type:n.type,installed:n.installed,error:`无法获取最新版本`});continue}let r=le(e,n.installed)>0;t.push({name:n.name,type:n.type,installed:n.installed,latest:e,newer:r})}catch{t.push({name:n.name,type:n.type,installed:n.installed,error:`版本检查失败`})}}return t}function _t(e){let t=g(e,`.otto-install.json`);if(n(t))try{return JSON.parse(a(t,`utf-8`)).sourceType}catch{return}}function vt(e){return!e.includes(`://`)&&!e.endsWith(`.git`)&&!e.endsWith(`.zip`)}async function yt(e){return(await Ne(e))?.version??null}function bt(e,t){let r=[];if(!n(e))return r;let i;try{i=o(e)}catch{return r}for(let o of i){let i=g(e,o);try{if(!u(i).isDirectory())continue}catch{continue}let s=g(i,`.otto-install.json`);if(!n(s))continue;let c;try{c=JSON.parse(a(s,`utf-8`))}catch{continue}if(!(c.sourceType!==`git`||!c.commit||!c.sourceUrl))try{let e=xt(c.sourceUrl);if(!e){r.push({name:o,type:t,sourceUrl:c.sourceUrl,installedCommit:c.commit,error:`远程无默认分支`});continue}r.push({name:o,type:t,sourceUrl:c.sourceUrl,installedCommit:c.commit,remoteCommit:e,newer:e!==c.commit})}catch{r.push({name:o,type:t,sourceUrl:c.sourceUrl,installedCommit:c.commit,error:`git ls-remote 执行异常`})}}return r}function xt(e){let t=b(`git`,[`ls-remote`,`--symref`,e,`HEAD`],{stdio:`pipe`,timeout:1e4});if(t.status===0){let e=t.stdout.toString().trim().split(`
4
- `);for(let t=e.length-1;t>=0;t--){let n=e[t];if(!n.startsWith(`ref:`))return n.split(` `)[0]}}for(let t of[`refs/heads/main`,`refs/heads/master`]){let n=b(`git`,[`ls-remote`,e,t],{stdio:`pipe`,timeout:1e4});if(n.status===0){let e=n.stdout.toString().trim().split(` `)[0];if(e)return e}}}async function St(e,t,r){let i=g(e,`.otto-install.json`);if(!n(i))return null;let o;try{o=JSON.parse(a(i,`utf-8`))}catch{return null}if(o.sourceType!==`git`||!o.commit||!o.sourceUrl)return null;let s;try{s=xt(o.sourceUrl)}catch{return{name:t,type:r,installed:o.commit,error:`git ls-remote 执行异常`}}return s?{name:t,type:r,installed:o.commit,latest:s.slice(0,8),newer:s!==o.commit}:{name:t,type:r,installed:o.commit,error:`远程无默认分支`}}Object.freeze({status:`aborted`});function A(e,t,n){function r(n,r){if(n._zod||Object.defineProperty(n,`_zod`,{value:{def:r,constr:o,traits:new Set},enumerable:!1}),n._zod.traits.has(e))return;n._zod.traits.add(e),t(n,r);let i=o.prototype,a=Object.keys(i);for(let e=0;e<a.length;e++){let t=a[e];t in n||(n[t]=i[t].bind(n))}}let i=n?.Parent??Object;class a extends i{}Object.defineProperty(a,`name`,{value:e});function o(e){var t;let i=n?.Parent?new a:this;r(i,e),(t=i._zod).deferred??(t.deferred=[]);for(let e of i._zod.deferred)e();return i}return Object.defineProperty(o,`init`,{value:r}),Object.defineProperty(o,Symbol.hasInstance,{value:t=>n?.Parent&&t instanceof n.Parent?!0:t?._zod?.traits?.has(e)}),Object.defineProperty(o,`name`,{value:e}),o}var j=class extends Error{constructor(){super(`Encountered Promise during synchronous parse. Use .parseAsync() instead.`)}},Ct=class extends Error{constructor(e){super(`Encountered unidirectional transform during encode: ${e}`),this.name=`ZodEncodeError`}};const wt={};function M(e){return e&&Object.assign(wt,e),wt}function Tt(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 Et(e,t){return typeof t==`bigint`?t.toString():t}function Dt(e){return{get value(){{let t=e();return Object.defineProperty(this,`value`,{value:t}),t}throw Error(`cached value already set`)}}}function Ot(e){return e==null}function kt(e){let t=e.startsWith(`^`)?1:0,n=e.endsWith(`$`)?e.length-1:e.length;return e.slice(t,n)}const At=Symbol(`evaluating`);function N(e,t,n){let r;Object.defineProperty(e,t,{get(){if(r!==At)return r===void 0&&(r=At,r=n()),r},set(n){Object.defineProperty(e,t,{value:n})},configurable:!0})}function P(e,t,n){Object.defineProperty(e,t,{value:n,writable:!0,enumerable:!0,configurable:!0})}function F(...e){let t={};for(let n of e)Object.assign(t,Object.getOwnPropertyDescriptors(n));return Object.defineProperties({},t)}function jt(e){return JSON.stringify(e)}function Mt(e){return e.toLowerCase().trim().replace(/[^\w\s-]/g,``).replace(/[\s_-]+/g,`-`).replace(/^-+|-+$/g,``)}const Nt=`captureStackTrace`in Error?Error.captureStackTrace:(...e)=>{};function Pt(e){return typeof e==`object`&&!!e&&!Array.isArray(e)}const Ft=Dt(()=>{if(typeof navigator<`u`&&navigator?.userAgent?.includes(`Cloudflare`))return!1;try{return Function(``),!0}catch{return!1}});function I(e){if(Pt(e)===!1)return!1;let t=e.constructor;if(t===void 0||typeof t!=`function`)return!0;let n=t.prototype;return!(Pt(n)===!1||Object.prototype.hasOwnProperty.call(n,`isPrototypeOf`)===!1)}function It(e){return I(e)?{...e}:Array.isArray(e)?[...e]:e}const Lt=new Set([`string`,`number`,`symbol`]);function L(e){return e.replace(/[.*+?^${}()|[\]\\]/g,`\\$&`)}function R(e,t,n){let r=new e._zod.constr(t??e._zod.def);return(!t||n?.parent)&&(r._zod.parent=e),r}function z(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 Rt(e){return Object.keys(e).filter(t=>e[t]._zod.optin===`optional`&&e[t]._zod.optout===`optional`)}-Number.MAX_VALUE,Number.MAX_VALUE;function zt(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`);return R(e,F(e._zod.def,{get shape(){let e={};for(let r in t){if(!(r in n.shape))throw Error(`Unrecognized key: "${r}"`);t[r]&&(e[r]=n.shape[r])}return P(this,`shape`,e),e},checks:[]}))}function Bt(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`);return R(e,F(e._zod.def,{get shape(){let r={...e._zod.def.shape};for(let e in t){if(!(e in n.shape))throw Error(`Unrecognized key: "${e}"`);t[e]&&delete r[e]}return P(this,`shape`,r),r},checks:[]}))}function Vt(e,t){if(!I(t))throw Error(`Invalid input to extend: expected a plain object`);let n=e._zod.def.checks;if(n&&n.length>0){let n=e._zod.def.shape;for(let e in t)if(Object.getOwnPropertyDescriptor(n,e)!==void 0)throw Error("Cannot overwrite keys on object schemas containing refinements. Use `.safeExtend()` instead.")}return R(e,F(e._zod.def,{get shape(){let n={...e._zod.def.shape,...t};return P(this,`shape`,n),n}}))}function Ht(e,t){if(!I(t))throw Error(`Invalid input to safeExtend: expected a plain object`);return R(e,F(e._zod.def,{get shape(){let n={...e._zod.def.shape,...t};return P(this,`shape`,n),n}}))}function Ut(e,t){return R(e,F(e._zod.def,{get shape(){let n={...e._zod.def.shape,...t._zod.def.shape};return P(this,`shape`,n),n},get catchall(){return t._zod.def.catchall},checks:[]}))}function Wt(e,t,n){let r=t._zod.def.checks;if(r&&r.length>0)throw Error(`.partial() cannot be used on object schemas containing refinements`);return R(t,F(t._zod.def,{get shape(){let r=t._zod.def.shape,i={...r};if(n)for(let t in n){if(!(t in r))throw Error(`Unrecognized key: "${t}"`);n[t]&&(i[t]=e?new e({type:`optional`,innerType:r[t]}):r[t])}else for(let t in r)i[t]=e?new e({type:`optional`,innerType:r[t]}):r[t];return P(this,`shape`,i),i},checks:[]}))}function Gt(e,t,n){return R(t,F(t._zod.def,{get shape(){let r=t._zod.def.shape,i={...r};if(n)for(let t in n){if(!(t in i))throw Error(`Unrecognized key: "${t}"`);n[t]&&(i[t]=new e({type:`nonoptional`,innerType:r[t]}))}else for(let t in r)i[t]=new e({type:`nonoptional`,innerType:r[t]});return P(this,`shape`,i),i}}))}function B(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 Kt(e,t){return t.map(t=>{var n;return(n=t).path??(n.path=[]),t.path.unshift(e),t})}function qt(e){return typeof e==`string`?e:e?.message}function V(e,t,n){let r={...e,path:e.path??[]};return e.message||(r.message=qt(e.inst?._zod.def?.error?.(e))??qt(t?.error?.(e))??qt(n.customError?.(e))??qt(n.localeError?.(e))??`Invalid input`),delete r.inst,delete r.continue,t?.reportInput||delete r.input,r}function Jt(e){return Array.isArray(e)?`array`:typeof e==`string`?`string`:`unknown`}function H(...e){let[t,n,r]=e;return typeof t==`string`?{message:t,code:`custom`,input:n,inst:r}:{...t}}const Yt=(e,t)=>{e.name=`$ZodError`,Object.defineProperty(e,`_zod`,{value:e._zod,enumerable:!1}),Object.defineProperty(e,`issues`,{value:t,enumerable:!1}),e.message=JSON.stringify(t,Et,2),Object.defineProperty(e,`toString`,{value:()=>e.message,enumerable:!1})},Xt=A(`$ZodError`,Yt),Zt=A(`$ZodError`,Yt,{Parent:Error});function Qt(e,t=e=>e.message){let n={},r=[];for(let i of e.issues)i.path.length>0?(n[i.path[0]]=n[i.path[0]]||[],n[i.path[0]].push(t(i))):r.push(t(i));return{formErrors:r,fieldErrors:n}}function $t(e,t=e=>e.message){let n={_errors:[]},r=e=>{for(let i of e.issues)if(i.code===`invalid_union`&&i.errors.length)i.errors.map(e=>r({issues:e}));else if(i.code===`invalid_key`)r({issues:i.issues});else if(i.code===`invalid_element`)r({issues:i.issues});else if(i.path.length===0)n._errors.push(t(i));else{let e=n,r=0;for(;r<i.path.length;){let n=i.path[r];r===i.path.length-1?(e[n]=e[n]||{_errors:[]},e[n]._errors.push(t(i))):e[n]=e[n]||{_errors:[]},e=e[n],r++}}};return r(e),n}const en=e=>(t,n,r,i)=>{let a=r?Object.assign(r,{async:!1}):{async:!1},o=t._zod.run({value:n,issues:[]},a);if(o instanceof Promise)throw new j;if(o.issues.length){let t=new(i?.Err??e)(o.issues.map(e=>V(e,a,M())));throw Nt(t,i?.callee),t}return o.value},tn=e=>async(t,n,r,i)=>{let a=r?Object.assign(r,{async:!0}):{async:!0},o=t._zod.run({value:n,issues:[]},a);if(o instanceof Promise&&(o=await o),o.issues.length){let t=new(i?.Err??e)(o.issues.map(e=>V(e,a,M())));throw Nt(t,i?.callee),t}return o.value},nn=e=>(t,n,r)=>{let i=r?{...r,async:!1}:{async:!1},a=t._zod.run({value:n,issues:[]},i);if(a instanceof Promise)throw new j;return a.issues.length?{success:!1,error:new(e??Xt)(a.issues.map(e=>V(e,i,M())))}:{success:!0,data:a.value}},rn=nn(Zt),an=e=>async(t,n,r)=>{let i=r?Object.assign(r,{async:!0}):{async:!0},a=t._zod.run({value:n,issues:[]},i);return a instanceof Promise&&(a=await a),a.issues.length?{success:!1,error:new e(a.issues.map(e=>V(e,i,M())))}:{success:!0,data:a.value}},on=an(Zt),sn=e=>(t,n,r)=>{let i=r?Object.assign(r,{direction:`backward`}):{direction:`backward`};return en(e)(t,n,i)},cn=e=>(t,n,r)=>en(e)(t,n,r),ln=e=>async(t,n,r)=>{let i=r?Object.assign(r,{direction:`backward`}):{direction:`backward`};return tn(e)(t,n,i)},un=e=>async(t,n,r)=>tn(e)(t,n,r),dn=e=>(t,n,r)=>{let i=r?Object.assign(r,{direction:`backward`}):{direction:`backward`};return nn(e)(t,n,i)},fn=e=>(t,n,r)=>nn(e)(t,n,r),pn=e=>async(t,n,r)=>{let i=r?Object.assign(r,{direction:`backward`}):{direction:`backward`};return an(e)(t,n,i)},mn=e=>async(t,n,r)=>an(e)(t,n,r),hn=/^[cC][^\s-]{8,}$/,gn=/^[0-9a-z]+$/,_n=/^[0-9A-HJKMNP-TV-Za-hjkmnp-tv-z]{26}$/,vn=/^[0-9a-vA-V]{20}$/,yn=/^[A-Za-z0-9]{27}$/,bn=/^[a-zA-Z0-9_-]{21}$/,xn=/^P(?:(\d+W)|(?!.*W)(?=\d|T\d)(\d+Y)?(\d+M)?(\d+D)?(T(?=\d)(\d+H)?(\d+M)?(\d+([.,]\d+)?S)?)?)$/,Sn=/^([0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12})$/,Cn=e=>e?RegExp(`^([0-9a-fA-F]{8}-[0-9a-fA-F]{4}-${e}[0-9a-fA-F]{3}-[89abAB][0-9a-fA-F]{3}-[0-9a-fA-F]{12})$`):/^([0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[1-8][0-9a-fA-F]{3}-[89abAB][0-9a-fA-F]{3}-[0-9a-fA-F]{12}|00000000-0000-0000-0000-000000000000|ffffffff-ffff-ffff-ffff-ffffffffffff)$/,wn=/^(?!\.)(?!.*\.\.)([A-Za-z0-9_'+\-\.]*)[A-Za-z0-9_+-]@([A-Za-z0-9][A-Za-z0-9\-]*\.)+[A-Za-z]{2,}$/;function Tn(){return RegExp(`^(\\p{Extended_Pictographic}|\\p{Emoji_Component})+$`,`u`)}const En=/^(?:(?:25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])\.){3}(?:25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])$/,Dn=/^(([0-9a-fA-F]{1,4}:){7}[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,7}:|([0-9a-fA-F]{1,4}:){1,6}:[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,5}(:[0-9a-fA-F]{1,4}){1,2}|([0-9a-fA-F]{1,4}:){1,4}(:[0-9a-fA-F]{1,4}){1,3}|([0-9a-fA-F]{1,4}:){1,3}(:[0-9a-fA-F]{1,4}){1,4}|([0-9a-fA-F]{1,4}:){1,2}(:[0-9a-fA-F]{1,4}){1,5}|[0-9a-fA-F]{1,4}:((:[0-9a-fA-F]{1,4}){1,6})|:((:[0-9a-fA-F]{1,4}){1,7}|:))$/,On=/^((25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])\.){3}(25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])\/([0-9]|[1-2][0-9]|3[0-2])$/,kn=/^(([0-9a-fA-F]{1,4}:){7}[0-9a-fA-F]{1,4}|::|([0-9a-fA-F]{1,4})?::([0-9a-fA-F]{1,4}:?){0,6})\/(12[0-8]|1[01][0-9]|[1-9]?[0-9])$/,An=/^$|^(?:[0-9a-zA-Z+/]{4})*(?:(?:[0-9a-zA-Z+/]{2}==)|(?:[0-9a-zA-Z+/]{3}=))?$/,jn=/^[A-Za-z0-9_-]*$/,Mn=/^\+[1-9]\d{6,14}$/,Nn=`(?:(?:\\d\\d[2468][048]|\\d\\d[13579][26]|\\d\\d0[48]|[02468][048]00|[13579][26]00)-02-29|\\d{4}-(?:(?:0[13578]|1[02])-(?:0[1-9]|[12]\\d|3[01])|(?:0[469]|11)-(?:0[1-9]|[12]\\d|30)|(?:02)-(?:0[1-9]|1\\d|2[0-8])))`,Pn=RegExp(`^${Nn}$`);function Fn(e){let t=`(?:[01]\\d|2[0-3]):[0-5]\\d`;return typeof e.precision==`number`?e.precision===-1?`${t}`:e.precision===0?`${t}:[0-5]\\d`:`${t}:[0-5]\\d\\.\\d{${e.precision}}`:`${t}(?::[0-5]\\d(?:\\.\\d+)?)?`}function In(e){return RegExp(`^${Fn(e)}$`)}function Ln(e){let t=Fn({precision:e.precision}),n=[`Z`];e.local&&n.push(``),e.offset&&n.push(`([+-](?:[01]\\d|2[0-3]):[0-5]\\d)`);let r=`${t}(?:${n.join(`|`)})`;return RegExp(`^${Nn}T(?:${r})$`)}const Rn=e=>{let t=e?`[\\s\\S]{${e?.minimum??0},${e?.maximum??``}}`:`[\\s\\S]*`;return RegExp(`^${t}$`)},zn=/^(?:true|false)$/i,Bn=/^[^A-Z]*$/,Vn=/^[^a-z]*$/,U=A(`$ZodCheck`,(e,t)=>{var n;e._zod??={},e._zod.def=t,(n=e._zod).onattach??(n.onattach=[])}),Hn=A(`$ZodCheckMaxLength`,(e,t)=>{var n;U.init(e,t),(n=e._zod.def).when??(n.when=e=>{let t=e.value;return!Ot(t)&&t.length!==void 0}),e._zod.onattach.push(e=>{let n=e._zod.bag.maximum??1/0;t.maximum<n&&(e._zod.bag.maximum=t.maximum)}),e._zod.check=n=>{let r=n.value;if(r.length<=t.maximum)return;let i=Jt(r);n.issues.push({origin:i,code:`too_big`,maximum:t.maximum,inclusive:!0,input:r,inst:e,continue:!t.abort})}}),Un=A(`$ZodCheckMinLength`,(e,t)=>{var n;U.init(e,t),(n=e._zod.def).when??(n.when=e=>{let t=e.value;return!Ot(t)&&t.length!==void 0}),e._zod.onattach.push(e=>{let n=e._zod.bag.minimum??-1/0;t.minimum>n&&(e._zod.bag.minimum=t.minimum)}),e._zod.check=n=>{let r=n.value;if(r.length>=t.minimum)return;let i=Jt(r);n.issues.push({origin:i,code:`too_small`,minimum:t.minimum,inclusive:!0,input:r,inst:e,continue:!t.abort})}}),Wn=A(`$ZodCheckLengthEquals`,(e,t)=>{var n;U.init(e,t),(n=e._zod.def).when??(n.when=e=>{let t=e.value;return!Ot(t)&&t.length!==void 0}),e._zod.onattach.push(e=>{let n=e._zod.bag;n.minimum=t.length,n.maximum=t.length,n.length=t.length}),e._zod.check=n=>{let r=n.value,i=r.length;if(i===t.length)return;let a=Jt(r),o=i>t.length;n.issues.push({origin:a,...o?{code:`too_big`,maximum:t.length}:{code:`too_small`,minimum:t.length},inclusive:!0,exact:!0,input:n.value,inst:e,continue:!t.abort})}}),Gn=A(`$ZodCheckStringFormat`,(e,t)=>{var n,r;U.init(e,t),e._zod.onattach.push(e=>{let n=e._zod.bag;n.format=t.format,t.pattern&&(n.patterns??=new Set,n.patterns.add(t.pattern))}),t.pattern?(n=e._zod).check??(n.check=n=>{t.pattern.lastIndex=0,!t.pattern.test(n.value)&&n.issues.push({origin:`string`,code:`invalid_format`,format:t.format,input:n.value,...t.pattern?{pattern:t.pattern.toString()}:{},inst:e,continue:!t.abort})}):(r=e._zod).check??(r.check=()=>{})}),Kn=A(`$ZodCheckRegex`,(e,t)=>{Gn.init(e,t),e._zod.check=n=>{t.pattern.lastIndex=0,!t.pattern.test(n.value)&&n.issues.push({origin:`string`,code:`invalid_format`,format:`regex`,input:n.value,pattern:t.pattern.toString(),inst:e,continue:!t.abort})}}),qn=A(`$ZodCheckLowerCase`,(e,t)=>{t.pattern??=Bn,Gn.init(e,t)}),Jn=A(`$ZodCheckUpperCase`,(e,t)=>{t.pattern??=Vn,Gn.init(e,t)}),Yn=A(`$ZodCheckIncludes`,(e,t)=>{U.init(e,t);let n=L(t.includes),r=new RegExp(typeof t.position==`number`?`^.{${t.position}}${n}`:n);t.pattern=r,e._zod.onattach.push(e=>{let t=e._zod.bag;t.patterns??=new Set,t.patterns.add(r)}),e._zod.check=n=>{n.value.includes(t.includes,t.position)||n.issues.push({origin:`string`,code:`invalid_format`,format:`includes`,includes:t.includes,input:n.value,inst:e,continue:!t.abort})}}),Xn=A(`$ZodCheckStartsWith`,(e,t)=>{U.init(e,t);let n=RegExp(`^${L(t.prefix)}.*`);t.pattern??=n,e._zod.onattach.push(e=>{let t=e._zod.bag;t.patterns??=new Set,t.patterns.add(n)}),e._zod.check=n=>{n.value.startsWith(t.prefix)||n.issues.push({origin:`string`,code:`invalid_format`,format:`starts_with`,prefix:t.prefix,input:n.value,inst:e,continue:!t.abort})}}),Zn=A(`$ZodCheckEndsWith`,(e,t)=>{U.init(e,t);let n=RegExp(`.*${L(t.suffix)}$`);t.pattern??=n,e._zod.onattach.push(e=>{let t=e._zod.bag;t.patterns??=new Set,t.patterns.add(n)}),e._zod.check=n=>{n.value.endsWith(t.suffix)||n.issues.push({origin:`string`,code:`invalid_format`,format:`ends_with`,suffix:t.suffix,input:n.value,inst:e,continue:!t.abort})}}),Qn=A(`$ZodCheckOverwrite`,(e,t)=>{U.init(e,t),e._zod.check=e=>{e.value=t.tx(e.value)}});var $n=class{constructor(e=[]){this.content=[],this.indent=0,this&&(this.args=e)}indented(e){this.indent+=1,e(this),--this.indent}write(e){if(typeof e==`function`){e(this,{execution:`sync`}),e(this,{execution:`async`});return}let t=e.split(`
1
+ import{cpSync as e,createWriteStream as t,existsSync as n,mkdirSync as r,mkdtempSync as i,readFileSync as a,readdirSync as o,realpathSync as s,renameSync as c,rmSync as l,statSync as u,unlinkSync as d,writeFileSync as f}from"node:fs";import{homedir as p,tmpdir as m}from"node:os";import{basename as h,dirname as ee,join as g,relative as _,resolve as v}from"node:path";import{spawn as y,spawnSync as b}from"node:child_process";import{createLogger as te}from"@x-otto/shared";import{isShadowModeEnabled as ne,normalizeEnv as x,resolveNpmSniffRegistries as re}from"@x-otto/env";import{parseSkillContent as ie}from"@x-otto/skill";import{HIGH_RISK_CAPABILITIES as ae,PLUGIN_MANIFEST_FILENAME as oe,isPluginTrusted as se,parsePluginManifest as ce,trustPlugin as le,untrustPlugin as ue}from"@x-otto/plugin";import{compare as de}from"semver";const fe=[`.zip`,`.tar.gz`,`.tgz`,`.tar`],pe=6e4;async function me(e,t,n){return new Promise(r=>{let i=y(e,t,{stdio:`pipe`,...n}),a=``,o=``;i.stdout?.on(`data`,e=>{a+=e.toString(`utf-8`)}),i.stderr?.on(`data`,e=>{o+=e.toString(`utf-8`)});let s=!1,c=!1,l=n.timeout?setTimeout(()=>{c=!0,i.kill()},n.timeout):void 0;i.on(`close`,(e,t)=>{l&&clearTimeout(l),s||(s=!0,r({stdout:a,stderr:o,status:e,signal:t,timedOut:c}))}),i.on(`error`,()=>{l&&clearTimeout(l),s||(s=!0,r({stdout:a,stderr:o,status:null,signal:null,timedOut:!1}))})})}async function he(e,t){let n=async(e,t)=>{let{stderr:n,status:r,signal:i,timedOut:a}=await me(e,t,{timeout:pe});if(a)throw Error(`解压超时(${pe/1e3}s)`);if(r!==0){let e=n.trim()||`exit code ${r}${i?` (${i})`:``}`;throw Error(`解压失败:${e}`)}},r=e.toLowerCase();if(r.endsWith(`.tar.gz`)||r.endsWith(`.tgz`)){await n(`tar`,[`xzf`,e,`-C`,t]);return}if(r.endsWith(`.tar`)){await n(`tar`,[`xf`,e,`-C`,t]);return}if(r.endsWith(`.zip`)){await n(`unzip`,[`-o`,`-q`,e,`-d`,t]);return}throw Error(`不支持的归档格式:${e}`)}async function ge(e,t){let{stderr:n,status:r,signal:i,timedOut:a}=await me(`tar`,[`czf`,t,`-C`,e,`.`],{timeout:pe});if(a)throw Error(`打包超时(${pe/1e3}s)`);if(r!==0){let e=n.trim()||`exit code ${r}${i?` (${i})`:``}`;throw Error(`打包失败:${e}`)}}function S(e){let t=v(e),n;try{n=s(e)}catch{n=t}let r=0,i=0,a=c=>{let l;try{l=o(c,{withFileTypes:!0})}catch{return}for(let o of l){let l=g(c,o.name);if(o.isSymbolicLink()){let t;try{t=s(l)}catch{throw Error(`安全拒绝:归档包含断链 "${_(e,l)}"`)}if(!t.startsWith(n+`/`)&&t!==n)throw Error(`安全拒绝:归档包含越界链接 "${_(e,l)}" → "${t}"`);try{u(l).isDirectory()&&a(l)}catch{}continue}if(!v(l).startsWith(t+`/`)&&v(l)!==t)throw Error(`安全拒绝:归档包含越界路径 "${_(e,l)}"`);if(o.isDirectory()){a(l);continue}if(o.isFile()){if(r++,r>1e4)throw Error(`安全拒绝:归档包含超过 10000 个文件`);try{i+=u(l).size}catch{}if(i>104857600)throw Error(`安全拒绝:归档总大小超过 100MB`)}}};return a(e),{totalBytes:i}}function _e(e,t){let n;try{n=u(e).size}catch{return}if(n===0)throw Error(`安全拒绝:归档文件为空`);let r=t/n;if(r>100)throw Error(`安全拒绝:压缩比异常(${Math.round(r)}:1,上限 100:1)`)}function ve(){return i(g(m(),`otto-install-`))}function C(e){try{n(e)&&l(e,{recursive:!0,force:!0})}catch{}}function w(e){return e.replace(/\/\/[^@]+@/,`//`)}function ye(t){let n=ve();try{e(t,n,{recursive:!0,verbatimSymlinks:!0,filter:e=>!e.includes(`/node_modules/`)&&!e.endsWith(`/node_modules`)});let{totalBytes:r}=S(n);return{tempDir:n,sourceUrl:w(h(t)),sourceType:`file`}}catch(e){throw C(n),e}}async function be(e){if(!n(e))throw Error(`文件不存在:${e}`);if(u(e).isDirectory())return ye(e);let t=h(e);if(!fe.some(e=>t.endsWith(e)))throw Error(`不支持的归档格式:${t}。支持 .zip、.tar.gz、.tgz、.tar(或直接传目录路径)`);let r=ve();try{await he(e,r);let{totalBytes:n}=S(r);return _e(e,n),{tempDir:r,sourceUrl:w(t),sourceType:`file`}}catch(e){throw C(r),e}}const xe=te(`@x-otto/coding:install:url-resolver`),Se=x(process.env.OTTO_DOWNLOAD_TIMEOUT_MS,3e4),Ce=x(process.env.OTTO_DOWNLOAD_MAX_REDIRECTS,3),we=100*1024*1024;async function Te(e,t){let r=h(new URL(e).pathname)||`download`,i=r.toLowerCase();if(!fe.some(e=>i.endsWith(e)))throw Error(`URL 文件类型不支持:${r}。请提供 .zip、.tar.gz、.tgz 或 .tar 归档。`);let a=g(m(),`otto-download-${Date.now()}-${r}`),o=ve();try{await Ee(e,a,t)}catch(e){C(o);try{n(a)&&d(a)}catch{}throw e}try{await he(a,o);let{totalBytes:e}=S(o);_e(a,e)}catch(e){throw C(o),e}finally{try{n(a)&&d(a)}catch{}}return{tempDir:o,sourceUrl:w(e),sourceType:`url`}}async function Ee(e,n,r){let i=e;for(let a=0;a<=Ce;a++){let o=await fetch(i,{signal:AbortSignal.timeout(Se),redirect:`manual`});if(o.status>=300&&o.status<400&&o.headers.get(`location`)){i=o.headers.get(`location`),xe.info(`Redirecting (%d/%d): %s → %s`,a+1,Ce,e,i);continue}if(!o.ok){let e=o.status===404?`(URL 指向的文件不存在——核对下载地址)`:o.status===403||o.status===401?`(无访问权限——该资源可能需要登录或已过期)`:``;throw Error(`下载失败:HTTP ${o.status} ${o.statusText}${e}`)}let s=o.headers.get(`content-length`);if(s){let e=Number(s);if(Number.isFinite(e)&&e>we)throw Error(`文件过大:${Math.round(e/1024/1024)}MB,上限 ${Math.round(we/1024/1024)}MB`)}if(!o.body)throw Error(`下载失败:响应体为空`);let c=t(n),l=o.body.getReader(),u=0,d=0,f=s&&Number.isFinite(Number(s))?Number(s):void 0,p=f===void 0?262144:Math.max(f*.03,65536);try{for(;;){let{done:e,value:t}=await l.read();if(e)break;if(u+=t.byteLength,u>we)throw Error(`下载文件过大(超过 ${Math.round(we/1024/1024)}MB)`);r&&u-d>=p&&(d=u,r(u,f)),c.write(t)||await new Promise(e=>c.once(`drain`,e))}r&&u!==d&&r(u,f)}finally{l.releaseLock(),c.end(),await new Promise((e,t)=>{c.on(`finish`,e),c.on(`error`,t)})}return}throw Error(`下载失败:重定向次数超过上限 (${Ce})`)}const De=x(process.env.OTTO_GIT_CLONE_TIMEOUT_MS,3e4);async function T(e,t){return new Promise(n=>{let r=y(`git`,e,{stdio:`pipe`,...t}),i=``,a=``;r.stdout?.on(`data`,e=>{i+=e.toString(`utf-8`)}),r.stderr?.on(`data`,e=>{a+=e.toString(`utf-8`)});let o=!1,s=!1,c=t.timeout?setTimeout(()=>{s=!0,r.kill()},t.timeout):void 0;r.on(`close`,e=>{c&&clearTimeout(c),o||(o=!0,n({stdout:i,stderr:a,status:e,timedOut:s}))}),r.on(`error`,()=>{c&&clearTimeout(c),o||(o=!0,n({stdout:i,stderr:a,status:null,timedOut:!1}))})})}async function Oe(e,t){let n=ve();return t===void 0?ke(e,n):Ae(e,n,t)}async function ke(e,t){let n=await T([`clone`,`--depth`,`1`,`--quiet`,`--`,e,t],{timeout:De});if(n.timedOut)throw C(t),Error(`git clone 超时(${De/1e3}s)`);if(n.status!==0)throw C(t),Error(`git clone 失败:${Me(n.stderr)}`);let r=await je(t);return{tempDir:t,sourceUrl:w(e),sourceType:`git`,commit:r}}async function Ae(e,t,n){let r=await T([`init`,`--quiet`,t],{timeout:5e3});if(r.status!==0)throw C(t),Error(`git init 失败:${r.stderr.trim()||`unknown error`}`);let i=await T([`fetch`,`--depth`,`1`,`--quiet`,`--`,e,n],{cwd:t,timeout:De});if(i.timedOut)throw C(t),Error(`git fetch 超时(${De/1e3}s)`);if(i.status!==0){C(t);let e=i.stderr.trim()||`unknown error`,r=/couldn't find remote ref|fatal: remote error|unable to negotiate|no such ref/i.test(e)?`(ref '${n}' 不存在,或不是合法的 tag/branch 名——commit hash 精确 pin 暂不支持,因主流 git 托管方默认拒绝按任意 commit fetch)`:``;throw Error(`git fetch ref '${n}' 失败:${Me(e)}${r}`)}let a=await T([`checkout`,`--quiet`,`FETCH_HEAD`],{cwd:t,timeout:1e4});if(a.status!==0)throw C(t),Error(`git checkout FETCH_HEAD 失败:${a.stderr.trim()||`unknown error`}`);let o=await je(t);return{tempDir:t,sourceUrl:w(e),sourceType:`git`,commit:o}}async function je(e){try{let t=await T([`rev-parse`,`HEAD`],{cwd:e,timeout:5e3});return t.status===0?t.stdout.trim():void 0}catch{return}}function Me(e){let t=e.trim()||`unknown error`;return`${t}${/not found|repository.*does not exist/i.test(t)?`(仓库地址可能有误或为私有仓库——核对 URL;私有仓库需先配置 git 凭据)`:/permission denied|authentication failed|could not read/i.test(t)?`(无访问权限——私有仓库需配置 SSH key 或 git 凭据)`:/could not resolve host|unable to access/i.test(t)?`(网络不可达——检查网络连接后重试)`:``}`}function Ne(){return[...re(),`https://registry.npmjs.org`]}async function Pe(e,t=5e3){for(let n of Ne()){let r=`${n}/${encodeURIComponent(e)}`,i=new AbortController,a=setTimeout(()=>i.abort(),t);try{let e=await fetch(r,{signal:i.signal});if(e.ok){let t=await e.json(),r=t[`dist-tags`];if(r){let e=r.latest??r.alpha??Fe(r);if(e)return{version:e,registry:n}}if(t?.version)return{version:t.version,registry:n}}}catch{}finally{clearTimeout(a)}}return null}function Fe(e){let t;for(let n of Object.values(e))(!t||Ie(n,t)>0)&&(t=n);return t}function Ie(e,t){let n=/(\d+)\.(\d+)\.(\d+)/.exec(e),r=/(\d+)\.(\d+)\.(\d+)/.exec(t);if(n&&r)for(let e=1;e<=3;e++){let t=Number(n[e])-Number(r[e]);if(t!==0)return t}return e<t?-1:e>t?1:0}const Le=x(process.env.OTTO_NPM_PACK_TIMEOUT_MS,6e4);function Re(e){let t=e.indexOf(`@`,e.startsWith(`@`)?1:0);return t>0?e.slice(0,t):e}async function ze(e){let t=i(g(m(),`otto-npm-`)),r=i(g(m(),`otto-npm-extract-`)),a=(await Pe(Re(e)).catch(()=>null))?.registry;try{let{stderr:i,status:o,timedOut:s}=await Be(e,t,a);if(s)throw Error(`npm pack 超时(${Le/1e3}s)`);if(o!==0){let e=i.trim()||`exit code ${o}`,t=/404|E404/.test(e)?`(包名可能拼写有误——用 /search <关键词> 在 registry 中查找,或核对 npmjs.com)`:/ENOTFOUND|ETIMEDOUT|ECONNREFUSED|network/i.test(e)?`(网络不可达——检查网络连接或 npm registry 配置后重试)`:``;throw Error(`npm pack 失败:${e}${t}`)}let c=Ve(t);if(!c)throw Error(`npm pack 未生成 .tgz 文件:${e}`);await he(c,r);let{totalBytes:l}=S(r);_e(c,l);try{He(t)}catch{}let u=g(r,`package`);return n(u)?{tempDir:u,sourceUrl:`npm:${e}`,sourceType:`npm`}:{tempDir:r,sourceUrl:`npm:${e}`,sourceType:`npm`}}catch(e){throw He(t),He(r),e}}async function Be(e,t,n){return new Promise(r=>{let i=[`pack`,e,`--pack-destination`,t,`--quiet`];n&&i.push(`--registry`,n);let a=y(`npm`,i,{stdio:`pipe`}),o=``,s=``;a.stdout?.on(`data`,e=>{o+=e.toString(`utf-8`)}),a.stderr?.on(`data`,e=>{s+=e.toString(`utf-8`)});let c=!1,l=!1,u=setTimeout(()=>{l=!0,a.kill()},Le);a.on(`close`,e=>{clearTimeout(u),c||(c=!0,r({stdout:o,stderr:s,status:e,timedOut:l}))}),a.on(`error`,()=>{clearTimeout(u),c||(c=!0,r({stdout:o,stderr:s,status:null,timedOut:!1}))})})}function Ve(e){try{let t=o(e);for(let n of t)if(n.endsWith(`.tgz`)||n.endsWith(`.tar.gz`))return g(e,n)}catch{}return null}function He(e){try{n(e)&&l(e,{recursive:!0,force:!0})}catch{}}function Ue(e){let t=g(e,`SKILL.md`);if(n(t))return[t];let r=[];try{let t=o(e);for(let i of t){let t=g(e,i);try{if(!u(t).isDirectory())continue}catch{continue}let a=g(t,`SKILL.md`);n(a)&&r.push(a)}}catch{}return r}function We(e){let t=Ue(e);return t.length>0?t[0]:null}function Ge(e){let t=We(e);if(!t)throw Error(`未找到 SKILL.md。skill 包必须包含一个 SKILL.md 文件(位于根目录或一层子目录下)。`);let n=a(t,`utf-8`),r=g(t,`..`);try{return ie(n,t,r)}catch(e){throw Error(`SKILL.md 解析失败:${e instanceof Error?e.message:String(e)}`)}}function Ke(e,t){let r=n(g(e,oe)),i=We(e)!==null,a=n(g(e,`.mcp.json`));if(t)return qe(e,t);let o=[];if(r&&o.push(`plugin`),i&&o.push(`skill`),a&&o.push(`mcp`),o.length===0)throw Error(`未检测到可安装内容。需要 otto-plugin.json(plugin)、SKILL.md(skill)或 .mcp.json(mcp)。如确定类型,请使用 --as 指定。`);if(o.length>1)throw Error(`检测到多种内容类型:${o.join(` + `)}。无法自动判定,请使用 --as ${o.join(` 或 --as `)} 指定。`);return qe(e,o[0])}function qe(e,t){switch(t){case`skill`:return Je(e);case`plugin`:return Ye(e);case`mcp`:return Xe(e)}}function Je(e){let t=Ue(e);if(t.length===0)throw Error(`未找到 SKILL.md。skill 包必须包含一个 SKILL.md 文件。`);let n=[];for(let e of t)try{let t=a(e,`utf-8`),r=g(e,`..`);n.push(ie(t,e,r))}catch(t){throw Error(`${e}: ${t instanceof Error?t.message:String(t)}`)}if(new Set(n.map(e=>e.metadata.name)).size!==n.length){let e=n.filter((e,t,n)=>n.findIndex(t=>t.metadata.name===e.metadata.name)!==t).map(e=>`"${e.metadata.name}" (${e.filePath})`).join(`, `);throw Error(`检测到同名 skill:${e}。请修改 SKILL.md 中的 name 字段使其唯一。`)}return{type:`skill`,skillDef:n.length===1?n[0]:void 0,skillDefs:n}}function Ye(e){let t=g(e,oe);if(!n(t))throw Error(`未找到 ${oe}。`);let r=ce(a(t,`utf-8`),t);if(!r)throw Error(`${oe} 格式无效(缺少 id 字段或 JSON 解析失败)。`);return{type:`plugin`,pluginManifest:r}}function Xe(e){let t=g(e,`.mcp.json`),r;if(n(t)){let e=a(t,`utf-8`);try{r=JSON.parse(e)}catch{throw Error(`.mcp.json 格式无效(JSON 解析失败)。`)}}else r={};return{type:`mcp`,mcpConfig:r}}const Ze=/^[a-z0-9][a-z0-9-]*[a-z0-9]$|^[a-z0-9]$/;function Qe(t,a,o){let s;if(o)s=o;else try{s=Ge(t)}catch(e){return{success:!1,error:e instanceof Error?e.message:String(e)}}let u=s.metadata.name;if(!Ze.test(u))return{success:!1,error:`skill 名称 "${u}" 不符合命名规范。仅允许小写字母、数字和连字符(kebab-case),例如 "my-skill"。`};let d=a.global?g(p(),`.otto`,`skills`):a.workspaceDir?g(a.workspaceDir,`.otto`,`skills`):g(process.cwd(),`.otto`,`skills`),m=g(d,u),h=n(m);if(a.dryRun){let e=$e(s.directory);return{success:!0,name:u,targetPath:m,definition:s,plan:[`来源:${s.directory}`,`目标:${m}`,`模式:${a.global?`全局`:`项目`}级`,h?`操作:覆盖(--force)`:`操作:新建`,`文件(${e.length}):`,...e.map(e=>` ${e}`)]}}if(h&&!a.force)return{success:!1,name:u,error:`skill "${u}" 已存在于 ${m}。`,failureKind:`conflict`};r(d,{recursive:!0});let v=i(g(d,`.otto-staging-${u}-`)),y=[];try{if(e(s.directory,v,{recursive:!0}),a.sourceMetadata)try{let e={sourceType:a.sourceMetadata.sourceType,sourceUrl:a.sourceMetadata.sourceUrl,commit:a.sourceMetadata.commit,subPath:_(t,s.directory)||void 0,installedAt:new Date().toISOString(),installedBy:`user`,installerVersion:process.env.OTTO_VERSION??`unknown`};f(g(v,`.otto-install.json`),JSON.stringify(e,null,2)+`
2
+ `)}catch(e){y.push(`无法写入安装元数据:${e instanceof Error?e.message:String(e)}`)}if(h){let e=g(ee(m),`.${u}.bak`);try{l(e,{recursive:!0,force:!0})}catch{}try{c(m,e)}catch(e){return l(v,{recursive:!0,force:!0}),{success:!1,name:u,error:`无法替换已有 skill 目录:${e instanceof Error?e.message:String(e)}`}}try{c(v,m)}catch(t){try{c(e,m)}catch{}return l(v,{recursive:!0,force:!0}),{success:!1,name:u,error:`安装失败:${t instanceof Error?t.message:String(t)}`}}try{l(e,{recursive:!0,force:!0})}catch{}}else try{c(v,m)}catch(e){return l(v,{recursive:!0,force:!0}),{success:!1,name:u,error:`安装失败:${e instanceof Error?e.message:String(e)}`}}}catch(e){try{l(v,{recursive:!0,force:!0})}catch{}return{success:!1,name:u,error:`安装失败:${e instanceof Error?e.message:String(e)}`}}return{success:!0,name:u,targetPath:m,definition:s,...y.length>0?{warnings:y}:{}}}function $e(e){let t=[],n=[{dir:e,prefix:``}];for(;;){let e=n.pop();if(!e)break;let r=o(e.dir,{withFileTypes:!0});for(let i of r){let r=e.prefix?`${e.prefix}/${i.name}`:i.name;i.isDirectory()?n.push({dir:g(e.dir,i.name),prefix:r}):t.push(r)}}return t.sort()}function et(e){return(e.capabilities??[]).filter(e=>ae.includes(e))}const tt={provider:`provider —— 注册 LLM provider,将处理你的凭据与请求流量`,tools:`tools —— 注册可被 agent 调用的工具`,"tui.renderer":`tui.renderer —— 在 TUI 进程内运行自定义渲染代码`,network:`network —— 发起任意网络请求`};async function nt(t,a,o){let s=a.id,u=o.global?g(p(),`.otto`,`plugins`):o.workspaceDir?g(o.workspaceDir,`.otto`,`plugins`):g(process.cwd(),`.otto`,`plugins`),d=g(u,s),m=n(d);if(o.dryRun){let e=et(a);return{success:!0,name:s,targetPath:d,manifest:a,pendingCapabilities:e.length>0?e:void 0,plan:[`类型:plugin`,`名称:${a.name??s}`,`来源:${t}`,`目标:${d}`,`模式:${o.global?`全局`:`项目`}级`,m?`操作:覆盖(--force)`:`操作:新建`,`信任策略:${o.global?`自动信任(用户级)`:`安装后自动信任`}`,...a.scripts?.postinstall?[`⚠ postinstall(安装后立即执行 shell):${a.scripts.postinstall}`]:[],...a.scripts?.setup?[`⚠ setup(首次加载执行 shell):${a.scripts.setup}`]:[],...e.length>0?[`⚠ 高危能力(安装后需另行 /trust plugin ${s} 显式授予,默认不生效):`,...e.map(e=>` • ${tt[e]??e}`)]:[]]}}if(m&&!o.force)return{success:!1,name:s,error:`plugin "${s}" 已存在于 ${d}。`,failureKind:`conflict`};r(u,{recursive:!0});let h=i(g(u,`.otto-staging-plugin-${s}-`)),_=[];try{if(e(t,h,{recursive:!0}),o.sourceMetadata)try{let e={sourceType:o.sourceMetadata.sourceType,sourceUrl:o.sourceMetadata.sourceUrl,commit:o.sourceMetadata.commit,subPath:o.sourceMetadata.subPath,installedAt:new Date().toISOString(),installedBy:`user`,installerVersion:process.env.OTTO_VERSION??`unknown`};f(g(h,`.otto-install.json`),JSON.stringify(e,null,2)+`
3
+ `)}catch(e){_.push(`无法写入安装元数据:${e instanceof Error?e.message:String(e)}`)}if(m){let e=g(ee(d),`.${s}.bak`);try{l(e,{recursive:!0,force:!0})}catch{}try{c(d,e)}catch(e){return l(h,{recursive:!0,force:!0}),{success:!1,name:s,error:`无法替换已有 plugin 目录:${e instanceof Error?e.message:String(e)}`}}try{c(h,d)}catch(t){try{c(e,d)}catch{}return l(h,{recursive:!0,force:!0}),{success:!1,name:s,error:`安装失败:${t instanceof Error?t.message:String(t)}(已恢复旧版本)`}}try{l(e,{recursive:!0,force:!0})}catch{}}else try{c(h,d)}catch(e){return l(h,{recursive:!0,force:!0}),{success:!1,name:s,error:`安装失败:${e instanceof Error?e.message:String(e)}`}}}catch(e){try{l(h,{recursive:!0,force:!0})}catch{}return{success:!1,name:s,error:`安装失败:${e instanceof Error?e.message:String(e)}`}}let v=!1;if(!o.global)try{le(d),v=!0}catch{}let y=[..._],b;if(a.scripts?.postinstall&&o.postInstallExecutor)if(o.global||se(d)){if(b=await o.postInstallExecutor({pluginDir:d,pluginId:s,workspaceDir:o.workspaceDir},a.scripts.postinstall),!b.success){let e=b.timeout?`postinstall 超时 (30s): ${a.scripts.postinstall}`:b.error?`postinstall 错误: ${b.error}`:`postinstall 返回非零 (exit=${b.exitCode}): ${a.scripts.postinstall}`;y.push(e)}}else{let e=o.global?void 0:`postinstall 跳过:插件信任持久化失败,使用 isPluginTrusted 验证未通过`;e&&y.push(e)}else a.scripts?.postinstall&&!o.postInstallExecutor?y.push(`postinstall 跳过:当前环境中未配置钩子执行器`):!o.global&&!v&&y.push(`插件信任持久化失败,可执行面(.mcp.json/commands/scripts)下次加载时将被门控`);let te=et(a);return te.length>0&&y.push(`插件声明高危能力(${te.join(`, `)})尚未授予——运行 /trust plugin ${s} 完成确认后方可生效`),{success:!0,name:s,targetPath:d,manifest:a,pendingCapabilities:te.length>0?te:void 0,...b?{postinstall:b}:{},...y.length>0?{warnings:y}:{}}}async function rt(e,t,n,r,i){let a=n.global?`全局`:`项目`;if(n.dryRun){let n=t.type??(t.command?`stdio`:`http`);return{success:!0,name:e,mcpConfig:t,plan:[`类型:mcp`,`名称:${e}`,`传输:${n}`,`${t.command?`命令:${t.command} ${(t.args??[]).join(` `)}`:``}`,`${t.url?`URL:${t.url}`:``}`,`模式:${a}级`,`操作:写入 settings.mcp_servers.${e}`].filter(e=>!!e)}}let o=r()??{};if(e in o&&!n.force)return{success:!1,name:e,error:`MCP server "${e}" 已存在。`,failureKind:`conflict`};let s={...o,[e]:t};try{await i(s)}catch(t){return{success:!1,name:e,error:`写入 MCP 配置失败:${t instanceof Error?t.message:String(t)}`}}return{success:!0,name:e,mcpConfig:t}}const it=/^https?:\/\//,at=/^(git@|git:\/\/|ssh:\/\/)|\.git$|(?<!https?:\/\/)\b(github\.com|gitlab\.com|bitbucket\.org)\b/;var ot=class{async install(e,t,n,r){let i,a;try{let o=t.type??st(e);E(t,{phase:`resolving`,message:`Resolving ${o} source...`});let s=t.onProgress&&!t.dryRun?(e,n)=>{E(t,{phase:`resolving`,message:`Resolving ${o} source...`,bytesDownloaded:e,bytesTotal:n})}:void 0;a=await ft(e,o,t.ref,s),i=a.tempDir;let c=i;if(t.subPath){let{resolve:e,sep:n}=await import(`node:path`),r=e(i,t.subPath);if(r!==i&&!r.startsWith(i+n))throw Error(`subPath 越出来源根目录:${t.subPath}`);let{existsSync:a}=await import(`node:fs`);if(!a(r))throw Error(`subPath 不存在于来源中:${t.subPath}`);c=r}E(t,{phase:`detecting`,message:`Detecting installed content...`});let l=Ke(c,t.as),u=l.type;switch(u){case`skill`:{let e=l.skillDefs??(l.skillDef?[l.skillDef]:[]);if(e.length===0)throw Error(`skill 检测失败:无法解析 SKILL.md`);let n={...t,sourceMetadata:{sourceType:o,sourceUrl:a.sourceUrl,commit:a.commit}};if(e.length===1)return E(t,{phase:`installing`,message:`Installing ${e[0].metadata.name}`,current:1,total:1}),Qe(c,n,e[0]);let r=c,i=[];for(let a=0;a<e.length;a++)E(t,{phase:`installing`,message:`Installing ${e[a].metadata.name}`,current:a+1,total:e.length}),i.push(Qe(r,n,e[a]));let s=i.every(e=>e.success);return{success:s,name:`${e.length} skills`,error:s?void 0:ut(i),failureKind:s?void 0:dt(i),plan:t.dryRun?i.map((t,n)=>{let r=(e[n].supportingFiles?.length??0)+1;return`${t.name??`?`} → ${t.targetPath??`?`} (${r} 文件)`}):void 0,results:i,warnings:i.flatMap(e=>e.warnings??[]),targetPath:i[0]?.targetPath}}case`plugin`:{if(!l.pluginManifest)throw Error(`plugin 检测失败:无法解析 otto-plugin.json`);E(t,{phase:`installing`,message:`Installing ${l.pluginManifest.id}`,current:1,total:1});let e={...t,sourceMetadata:{sourceType:o,sourceUrl:a.sourceUrl,commit:a.commit}};return await nt(c,l.pluginManifest,e)}case`mcp`:{if(!n||!r)return{success:!1,error:`MCP 安装需要 settings 访问权限。请在 CLI 环境中执行。`};let e=l.mcpConfig?.url?new URL(l.mcpConfig.url).hostname.replace(/\./g,`-`):l.mcpConfig?.command?l.mcpConfig.command.replace(/[^a-z0-9-]/g,`-`).slice(0,40):`mcp-server`,i={...l.mcpConfig,...t.env?{env:{...l.mcpConfig?.env??{},...t.env}}:{}};return E(t,{phase:`installing`,message:`Installing MCP ${e}`,current:1,total:1}),rt(e,i,t,n,r)}default:return{success:!1,error:`不支持的内容类型:${u}`}}}catch(e){return{success:!1,error:e instanceof Error?e.message:String(e)}}finally{i&&C(i)}}async installSkill(e,t){return this.install(e,{...t,as:`skill`})}};function st(e){return at.test(e)?`git`:it.test(e)?`url`:ct(e)?`file`:`npm`}function ct(e){return/^@[^/]+\/[^/]+$/.test(e)?!1:!!(/\.(zip|tar\.gz|tgz|tar)$/i.test(e)||e.includes(`/`)||e.includes(`\\`))}function lt(e){return e.replace(/[。.]\s*$/,``)}function ut(e){let t=e.filter(e=>!e.success),n=t.map(e=>`${e.name??`?`} —— ${lt(e.error??`unknown error`)}`).join(`;`);return`${t.length}/${e.length} 个 skill 安装失败:${n}`}function dt(e){let t=e.filter(e=>!e.success);if(t.length!==0)return t.every(e=>e.failureKind===`conflict`)?`conflict`:void 0}function E(e,t){if(e.onProgress&&!(e.dryRun&&t.phase!==`resolving`&&t.phase!==`detecting`))try{e.onProgress(t)}catch{}}async function ft(e,t,n,r){switch(t){case`file`:return be(e);case`url`:return Te(e,r);case`git`:return Oe(e,n);case`npm`:return ze(e)}}function pt(e,t,r){let i=t.global?g(p(),`.otto`):t.workspaceRoot?g(t.workspaceRoot,`.otto`):t.workspaceDir?g(t.workspaceDir,`.otto`):g(process.cwd(),`.otto`);return n(g(i,`skills`,e))?`skill`:n(g(i,`plugins`,e))?`plugin`:r&&e in r?`mcp`:null}function D(e){try{return o(e,{withFileTypes:!0}).filter(e=>e.isDirectory()).map(e=>e.name)}catch{return[]}}function mt(e,t){let n=[],r=e.workspaceDir??process.cwd(),i=!e.scope||e.scope===`global`,a=!e.scope||e.scope===`project`,o=!e.scope||e.scope===`repository`;if(i){let e=g(p(),`.otto`);D(g(e,`skills`)).forEach(e=>n.push({name:e,type:`skill`,scope:`global`})),D(g(e,`plugins`)).forEach(e=>n.push({name:e,type:`plugin`,scope:`global`}))}if(a){let e=g(r,`.otto`);D(g(e,`skills`)).forEach(e=>n.push({name:e,type:`skill`,scope:`project`})),D(g(e,`plugins`)).forEach(e=>n.push({name:e,type:`plugin`,scope:`project`})),t&&Object.entries(t).forEach(([e,t])=>{let r=t.command??t.url;n.push({name:e,type:`mcp`,scope:`project`,detail:r})})}if(o&&e.workspaceRoot){let t=g(e.workspaceRoot,`.otto`);D(g(t,`skills`)).forEach(e=>n.push({name:e,type:`skill`,scope:`repository`})),D(g(t,`plugins`)).forEach(e=>n.push({name:e,type:`plugin`,scope:`repository`}))}let s=new Map;for(let e of n){let t=`${e.type}:${e.name}`;(!s.has(t)||e.scope===`global`)&&s.set(t,e)}return[...s.values()]}async function ht(e,t,r,i,a){if(e.includes(`/`)||e.includes(`\\`)||e.includes(`..`))return{success:!1,name:e,type:t,error:`非法名称(含路径分隔符或 ..):${e}`};let o=r.global?g(p(),`.otto`):r.workspaceRoot?g(r.workspaceRoot,`.otto`):r.workspaceDir?g(r.workspaceDir,`.otto`):g(process.cwd(),`.otto`),s=r.global?`全局`:r.workspaceRoot?`仓库`:`项目`;switch(t){case`skill`:{let i=g(o,`skills`,e);if(r.dryRun)return{success:!0,name:e,type:t,plan:[`类型:skill`,`名称:${e}`,`路径:${i}`,`模式:${s}级`,`操作:删除目录`]};if(!n(i))return{success:!1,name:e,type:t,error:`skill "${e}" 不存在于 ${i}`};try{l(i,{recursive:!0,force:!0})}catch(n){return{success:!1,name:e,type:t,error:`删除失败:${n instanceof Error?n.message:String(n)}`}}return{success:!0,name:e,type:t}}case`plugin`:{let i=g(o,`plugins`,e);if(r.dryRun)return{success:!0,name:e,type:t,plan:[`类型:plugin`,`名称:${e}`,`路径:${i}`,`模式:${s}级`,`操作:删除目录 + 撤销信任记录`]};if(!n(i))return{success:!1,name:e,type:t,error:`plugin "${e}" 不存在于 ${i}`};try{try{ue(i)}catch{}l(i,{recursive:!0,force:!0})}catch(n){return{success:!1,name:e,type:t,error:`删除失败:${n instanceof Error?n.message:String(n)}`}}return{success:!0,name:e,type:t}}case`mcp`:{if(!i||!a)return{success:!1,name:e,type:t,error:`MCP 卸载需要 settings 访问权限`};let n={...i()??{}};if(!(e in n))return{success:!1,name:e,type:t,error:`MCP server "${e}" 不存在`};if(r.dryRun){let r=n[e];return{success:!0,name:e,type:t,plan:[`类型:mcp server`,`名称:${e}`,`命令:${r?.command??`(URL)`}`,`模式:${s}级`,`操作:从 settings.mcp_servers 删除配置`]}}delete n[e];try{await a(n)}catch(n){return{success:!1,name:e,type:t,error:`删除 MCP 配置失败:${n instanceof Error?n.message:String(n)}`}}return{success:!0,name:e,type:t}}}}function gt(e){let t=[];if(e.scope===void 0||e.scope===`all`||e.scope===`project`){let n=e.workspaceDir?g(e.workspaceDir,`.otto`):g(process.cwd(),`.otto`);O(g(n,`skills`),`skill`,t),O(g(n,`plugins`),`plugin`,t)}if((e.scope===void 0||e.scope===`all`||e.scope===`repository`)&&e.workspaceRoot){let n=g(e.workspaceRoot,`.otto`);O(g(n,`skills`),`skill`,t),O(g(n,`plugins`),`plugin`,t)}if(e.scope===void 0||e.scope===`all`||e.scope===`global`){let e=g(p(),`.otto`);O(g(e,`skills`),`skill`,t),O(g(e,`plugins`),`plugin`,t)}return t}function O(e,t,r){if(!n(e))return;let i;try{i=o(e)}catch{return}for(let o of i){let i=g(e,o);try{if(!u(i).isDirectory())continue}catch{continue}if(t===`skill`){let e=g(i,`SKILL.md`);if(!n(e))continue;try{let n=ie(a(e,`utf-8`),e,i);n.metadata.version&&r.push({name:n.metadata.name,type:t,installed:n.metadata.version,path:i})}catch{}}else{let e=g(i,`otto-plugin.json`);if(!n(e))continue;try{let n=ce(a(e,`utf-8`),e);n?.version&&r.push({name:n.id,type:t,installed:n.version,path:i})}catch{}}}}async function _t(e){let t=[];for(let n of e){let e=vt(n.path);if(e===`git`){let e=await Ct(n.path,n.name,n.type);if(e){t.push(e);continue}t.push({name:n.name,type:n.type,installed:n.installed,error:`无法检查升级(.otto-install.json 声明 git 来源但缺 commit/sourceUrl)`});continue}if(e===`file`||e===`url`){t.push({name:n.name,type:n.type,installed:n.installed,error:`无法检查升级(${e} 来源不支持版本比对)`});continue}if(e===void 0&&!yt(n.name)){let e=await Ct(n.path,n.name,n.type);if(e){t.push(e);continue}t.push({name:n.name,type:n.type,installed:n.installed,error:`无法检查升级(非 npm 来源且无 .otto-install.json)`});continue}try{let e=await bt(n.name);if(!e){t.push({name:n.name,type:n.type,installed:n.installed,error:`无法获取最新版本`});continue}let r=de(e,n.installed)>0;t.push({name:n.name,type:n.type,installed:n.installed,latest:e,newer:r})}catch{t.push({name:n.name,type:n.type,installed:n.installed,error:`版本检查失败`})}}return t}function vt(e){let t=g(e,`.otto-install.json`);if(n(t))try{return JSON.parse(a(t,`utf-8`)).sourceType}catch{return}}function yt(e){return!e.includes(`://`)&&!e.endsWith(`.git`)&&!e.endsWith(`.zip`)}async function bt(e){return(await Pe(e))?.version??null}function xt(e,t){let r=[];if(!n(e))return r;let i;try{i=o(e)}catch{return r}for(let o of i){let i=g(e,o);try{if(!u(i).isDirectory())continue}catch{continue}let s=g(i,`.otto-install.json`);if(!n(s))continue;let c;try{c=JSON.parse(a(s,`utf-8`))}catch{continue}if(!(c.sourceType!==`git`||!c.commit||!c.sourceUrl))try{let e=St(c.sourceUrl);if(!e){r.push({name:o,type:t,sourceUrl:c.sourceUrl,installedCommit:c.commit,error:`远程无默认分支`});continue}r.push({name:o,type:t,sourceUrl:c.sourceUrl,installedCommit:c.commit,remoteCommit:e,newer:e!==c.commit})}catch{r.push({name:o,type:t,sourceUrl:c.sourceUrl,installedCommit:c.commit,error:`git ls-remote 执行异常`})}}return r}function St(e){let t=b(`git`,[`ls-remote`,`--symref`,e,`HEAD`],{stdio:`pipe`,timeout:1e4});if(t.status===0){let e=t.stdout.toString().trim().split(`
4
+ `);for(let t=e.length-1;t>=0;t--){let n=e[t];if(!n.startsWith(`ref:`))return n.split(` `)[0]}}for(let t of[`refs/heads/main`,`refs/heads/master`]){let n=b(`git`,[`ls-remote`,e,t],{stdio:`pipe`,timeout:1e4});if(n.status===0){let e=n.stdout.toString().trim().split(` `)[0];if(e)return e}}}async function Ct(e,t,r){let i=g(e,`.otto-install.json`);if(!n(i))return null;let o;try{o=JSON.parse(a(i,`utf-8`))}catch{return null}if(o.sourceType!==`git`||!o.commit||!o.sourceUrl)return null;let s;try{s=St(o.sourceUrl)}catch{return{name:t,type:r,installed:o.commit,error:`git ls-remote 执行异常`}}return s?{name:t,type:r,installed:o.commit,latest:s.slice(0,8),newer:s!==o.commit}:{name:t,type:r,installed:o.commit,error:`远程无默认分支`}}Object.freeze({status:`aborted`});function k(e,t,n){function r(n,r){if(n._zod||Object.defineProperty(n,`_zod`,{value:{def:r,constr:o,traits:new Set},enumerable:!1}),n._zod.traits.has(e))return;n._zod.traits.add(e),t(n,r);let i=o.prototype,a=Object.keys(i);for(let e=0;e<a.length;e++){let t=a[e];t in n||(n[t]=i[t].bind(n))}}let i=n?.Parent??Object;class a extends i{}Object.defineProperty(a,`name`,{value:e});function o(e){var t;let i=n?.Parent?new a:this;r(i,e),(t=i._zod).deferred??(t.deferred=[]);for(let e of i._zod.deferred)e();return i}return Object.defineProperty(o,`init`,{value:r}),Object.defineProperty(o,Symbol.hasInstance,{value:t=>n?.Parent&&t instanceof n.Parent?!0:t?._zod?.traits?.has(e)}),Object.defineProperty(o,`name`,{value:e}),o}var A=class extends Error{constructor(){super(`Encountered Promise during synchronous parse. Use .parseAsync() instead.`)}},wt=class extends Error{constructor(e){super(`Encountered unidirectional transform during encode: ${e}`),this.name=`ZodEncodeError`}};const Tt={};function j(e){return e&&Object.assign(Tt,e),Tt}function Et(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 Dt(e,t){return typeof t==`bigint`?t.toString():t}function Ot(e){return{get value(){{let t=e();return Object.defineProperty(this,`value`,{value:t}),t}throw Error(`cached value already set`)}}}function kt(e){return e==null}function At(e){let t=e.startsWith(`^`)?1:0,n=e.endsWith(`$`)?e.length-1:e.length;return e.slice(t,n)}const jt=Symbol(`evaluating`);function M(e,t,n){let r;Object.defineProperty(e,t,{get(){if(r!==jt)return r===void 0&&(r=jt,r=n()),r},set(n){Object.defineProperty(e,t,{value:n})},configurable:!0})}function N(e,t,n){Object.defineProperty(e,t,{value:n,writable:!0,enumerable:!0,configurable:!0})}function P(...e){let t={};for(let n of e)Object.assign(t,Object.getOwnPropertyDescriptors(n));return Object.defineProperties({},t)}function Mt(e){return JSON.stringify(e)}function Nt(e){return e.toLowerCase().trim().replace(/[^\w\s-]/g,``).replace(/[\s_-]+/g,`-`).replace(/^-+|-+$/g,``)}const Pt=`captureStackTrace`in Error?Error.captureStackTrace:(...e)=>{};function Ft(e){return typeof e==`object`&&!!e&&!Array.isArray(e)}const It=Ot(()=>{if(typeof navigator<`u`&&navigator?.userAgent?.includes(`Cloudflare`))return!1;try{return Function(``),!0}catch{return!1}});function F(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 Lt(e){return F(e)?{...e}:Array.isArray(e)?[...e]:e}const Rt=new Set([`string`,`number`,`symbol`]);function I(e){return e.replace(/[.*+?^${}()|[\]\\]/g,`\\$&`)}function L(e,t,n){let r=new e._zod.constr(t??e._zod.def);return(!t||n?.parent)&&(r._zod.parent=e),r}function R(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 zt(e){return Object.keys(e).filter(t=>e[t]._zod.optin===`optional`&&e[t]._zod.optout===`optional`)}-Number.MAX_VALUE,Number.MAX_VALUE;function Bt(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`);return L(e,P(e._zod.def,{get shape(){let e={};for(let r in t){if(!(r in n.shape))throw Error(`Unrecognized key: "${r}"`);t[r]&&(e[r]=n.shape[r])}return N(this,`shape`,e),e},checks:[]}))}function Vt(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`);return L(e,P(e._zod.def,{get shape(){let r={...e._zod.def.shape};for(let e in t){if(!(e in n.shape))throw Error(`Unrecognized key: "${e}"`);t[e]&&delete r[e]}return N(this,`shape`,r),r},checks:[]}))}function Ht(e,t){if(!F(t))throw Error(`Invalid input to extend: expected a plain object`);let n=e._zod.def.checks;if(n&&n.length>0){let n=e._zod.def.shape;for(let e in t)if(Object.getOwnPropertyDescriptor(n,e)!==void 0)throw Error("Cannot overwrite keys on object schemas containing refinements. Use `.safeExtend()` instead.")}return L(e,P(e._zod.def,{get shape(){let n={...e._zod.def.shape,...t};return N(this,`shape`,n),n}}))}function Ut(e,t){if(!F(t))throw Error(`Invalid input to safeExtend: expected a plain object`);return L(e,P(e._zod.def,{get shape(){let n={...e._zod.def.shape,...t};return N(this,`shape`,n),n}}))}function Wt(e,t){return L(e,P(e._zod.def,{get shape(){let n={...e._zod.def.shape,...t._zod.def.shape};return N(this,`shape`,n),n},get catchall(){return t._zod.def.catchall},checks:[]}))}function Gt(e,t,n){let r=t._zod.def.checks;if(r&&r.length>0)throw Error(`.partial() cannot be used on object schemas containing refinements`);return L(t,P(t._zod.def,{get shape(){let r=t._zod.def.shape,i={...r};if(n)for(let t in n){if(!(t in r))throw Error(`Unrecognized key: "${t}"`);n[t]&&(i[t]=e?new e({type:`optional`,innerType:r[t]}):r[t])}else for(let t in r)i[t]=e?new e({type:`optional`,innerType:r[t]}):r[t];return N(this,`shape`,i),i},checks:[]}))}function Kt(e,t,n){return L(t,P(t._zod.def,{get shape(){let r=t._zod.def.shape,i={...r};if(n)for(let t in n){if(!(t in i))throw Error(`Unrecognized key: "${t}"`);n[t]&&(i[t]=new e({type:`nonoptional`,innerType:r[t]}))}else for(let t in r)i[t]=new e({type:`nonoptional`,innerType:r[t]});return N(this,`shape`,i),i}}))}function z(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 qt(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 B(e,t,n){let r={...e,path:e.path??[]};return e.message||(r.message=Jt(e.inst?._zod.def?.error?.(e))??Jt(t?.error?.(e))??Jt(n.customError?.(e))??Jt(n.localeError?.(e))??`Invalid input`),delete r.inst,delete r.continue,t?.reportInput||delete r.input,r}function Yt(e){return Array.isArray(e)?`array`:typeof e==`string`?`string`:`unknown`}function V(...e){let[t,n,r]=e;return typeof t==`string`?{message:t,code:`custom`,input:n,inst:r}:{...t}}const Xt=(e,t)=>{e.name=`$ZodError`,Object.defineProperty(e,`_zod`,{value:e._zod,enumerable:!1}),Object.defineProperty(e,`issues`,{value:t,enumerable:!1}),e.message=JSON.stringify(t,Dt,2),Object.defineProperty(e,`toString`,{value:()=>e.message,enumerable:!1})},Zt=k(`$ZodError`,Xt),Qt=k(`$ZodError`,Xt,{Parent:Error});function $t(e,t=e=>e.message){let n={},r=[];for(let i of e.issues)i.path.length>0?(n[i.path[0]]=n[i.path[0]]||[],n[i.path[0]].push(t(i))):r.push(t(i));return{formErrors:r,fieldErrors:n}}function en(e,t=e=>e.message){let n={_errors:[]},r=e=>{for(let i of e.issues)if(i.code===`invalid_union`&&i.errors.length)i.errors.map(e=>r({issues:e}));else if(i.code===`invalid_key`)r({issues:i.issues});else if(i.code===`invalid_element`)r({issues:i.issues});else if(i.path.length===0)n._errors.push(t(i));else{let e=n,r=0;for(;r<i.path.length;){let n=i.path[r];r===i.path.length-1?(e[n]=e[n]||{_errors:[]},e[n]._errors.push(t(i))):e[n]=e[n]||{_errors:[]},e=e[n],r++}}};return r(e),n}const tn=e=>(t,n,r,i)=>{let a=r?Object.assign(r,{async:!1}):{async:!1},o=t._zod.run({value:n,issues:[]},a);if(o instanceof Promise)throw new A;if(o.issues.length){let t=new(i?.Err??e)(o.issues.map(e=>B(e,a,j())));throw Pt(t,i?.callee),t}return o.value},nn=e=>async(t,n,r,i)=>{let a=r?Object.assign(r,{async:!0}):{async:!0},o=t._zod.run({value:n,issues:[]},a);if(o instanceof Promise&&(o=await o),o.issues.length){let t=new(i?.Err??e)(o.issues.map(e=>B(e,a,j())));throw Pt(t,i?.callee),t}return o.value},rn=e=>(t,n,r)=>{let i=r?{...r,async:!1}:{async:!1},a=t._zod.run({value:n,issues:[]},i);if(a instanceof Promise)throw new A;return a.issues.length?{success:!1,error:new(e??Zt)(a.issues.map(e=>B(e,i,j())))}:{success:!0,data:a.value}},an=rn(Qt),on=e=>async(t,n,r)=>{let i=r?Object.assign(r,{async:!0}):{async:!0},a=t._zod.run({value:n,issues:[]},i);return a instanceof Promise&&(a=await a),a.issues.length?{success:!1,error:new e(a.issues.map(e=>B(e,i,j())))}:{success:!0,data:a.value}},sn=on(Qt),cn=e=>(t,n,r)=>{let i=r?Object.assign(r,{direction:`backward`}):{direction:`backward`};return tn(e)(t,n,i)},ln=e=>(t,n,r)=>tn(e)(t,n,r),un=e=>async(t,n,r)=>{let i=r?Object.assign(r,{direction:`backward`}):{direction:`backward`};return nn(e)(t,n,i)},dn=e=>async(t,n,r)=>nn(e)(t,n,r),fn=e=>(t,n,r)=>{let i=r?Object.assign(r,{direction:`backward`}):{direction:`backward`};return rn(e)(t,n,i)},pn=e=>(t,n,r)=>rn(e)(t,n,r),mn=e=>async(t,n,r)=>{let i=r?Object.assign(r,{direction:`backward`}):{direction:`backward`};return on(e)(t,n,i)},hn=e=>async(t,n,r)=>on(e)(t,n,r),gn=/^[cC][^\s-]{8,}$/,_n=/^[0-9a-z]+$/,vn=/^[0-9A-HJKMNP-TV-Za-hjkmnp-tv-z]{26}$/,yn=/^[0-9a-vA-V]{20}$/,bn=/^[A-Za-z0-9]{27}$/,xn=/^[a-zA-Z0-9_-]{21}$/,Sn=/^P(?:(\d+W)|(?!.*W)(?=\d|T\d)(\d+Y)?(\d+M)?(\d+D)?(T(?=\d)(\d+H)?(\d+M)?(\d+([.,]\d+)?S)?)?)$/,Cn=/^([0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12})$/,wn=e=>e?RegExp(`^([0-9a-fA-F]{8}-[0-9a-fA-F]{4}-${e}[0-9a-fA-F]{3}-[89abAB][0-9a-fA-F]{3}-[0-9a-fA-F]{12})$`):/^([0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[1-8][0-9a-fA-F]{3}-[89abAB][0-9a-fA-F]{3}-[0-9a-fA-F]{12}|00000000-0000-0000-0000-000000000000|ffffffff-ffff-ffff-ffff-ffffffffffff)$/,Tn=/^(?!\.)(?!.*\.\.)([A-Za-z0-9_'+\-\.]*)[A-Za-z0-9_+-]@([A-Za-z0-9][A-Za-z0-9\-]*\.)+[A-Za-z]{2,}$/;function En(){return RegExp(`^(\\p{Extended_Pictographic}|\\p{Emoji_Component})+$`,`u`)}const Dn=/^(?:(?:25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])\.){3}(?:25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])$/,On=/^(([0-9a-fA-F]{1,4}:){7}[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,7}:|([0-9a-fA-F]{1,4}:){1,6}:[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,5}(:[0-9a-fA-F]{1,4}){1,2}|([0-9a-fA-F]{1,4}:){1,4}(:[0-9a-fA-F]{1,4}){1,3}|([0-9a-fA-F]{1,4}:){1,3}(:[0-9a-fA-F]{1,4}){1,4}|([0-9a-fA-F]{1,4}:){1,2}(:[0-9a-fA-F]{1,4}){1,5}|[0-9a-fA-F]{1,4}:((:[0-9a-fA-F]{1,4}){1,6})|:((:[0-9a-fA-F]{1,4}){1,7}|:))$/,kn=/^((25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])\.){3}(25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])\/([0-9]|[1-2][0-9]|3[0-2])$/,An=/^(([0-9a-fA-F]{1,4}:){7}[0-9a-fA-F]{1,4}|::|([0-9a-fA-F]{1,4})?::([0-9a-fA-F]{1,4}:?){0,6})\/(12[0-8]|1[01][0-9]|[1-9]?[0-9])$/,jn=/^$|^(?:[0-9a-zA-Z+/]{4})*(?:(?:[0-9a-zA-Z+/]{2}==)|(?:[0-9a-zA-Z+/]{3}=))?$/,Mn=/^[A-Za-z0-9_-]*$/,Nn=/^\+[1-9]\d{6,14}$/,Pn=`(?:(?:\\d\\d[2468][048]|\\d\\d[13579][26]|\\d\\d0[48]|[02468][048]00|[13579][26]00)-02-29|\\d{4}-(?:(?:0[13578]|1[02])-(?:0[1-9]|[12]\\d|3[01])|(?:0[469]|11)-(?:0[1-9]|[12]\\d|30)|(?:02)-(?:0[1-9]|1\\d|2[0-8])))`,Fn=RegExp(`^${Pn}$`);function In(e){let t=`(?:[01]\\d|2[0-3]):[0-5]\\d`;return typeof e.precision==`number`?e.precision===-1?`${t}`:e.precision===0?`${t}:[0-5]\\d`:`${t}:[0-5]\\d\\.\\d{${e.precision}}`:`${t}(?::[0-5]\\d(?:\\.\\d+)?)?`}function Ln(e){return RegExp(`^${In(e)}$`)}function Rn(e){let t=In({precision:e.precision}),n=[`Z`];e.local&&n.push(``),e.offset&&n.push(`([+-](?:[01]\\d|2[0-3]):[0-5]\\d)`);let r=`${t}(?:${n.join(`|`)})`;return RegExp(`^${Pn}T(?:${r})$`)}const zn=e=>{let t=e?`[\\s\\S]{${e?.minimum??0},${e?.maximum??``}}`:`[\\s\\S]*`;return RegExp(`^${t}$`)},Bn=/^(?:true|false)$/i,Vn=/^[^A-Z]*$/,Hn=/^[^a-z]*$/,H=k(`$ZodCheck`,(e,t)=>{var n;e._zod??={},e._zod.def=t,(n=e._zod).onattach??(n.onattach=[])}),Un=k(`$ZodCheckMaxLength`,(e,t)=>{var n;H.init(e,t),(n=e._zod.def).when??(n.when=e=>{let t=e.value;return!kt(t)&&t.length!==void 0}),e._zod.onattach.push(e=>{let n=e._zod.bag.maximum??1/0;t.maximum<n&&(e._zod.bag.maximum=t.maximum)}),e._zod.check=n=>{let r=n.value;if(r.length<=t.maximum)return;let i=Yt(r);n.issues.push({origin:i,code:`too_big`,maximum:t.maximum,inclusive:!0,input:r,inst:e,continue:!t.abort})}}),Wn=k(`$ZodCheckMinLength`,(e,t)=>{var n;H.init(e,t),(n=e._zod.def).when??(n.when=e=>{let t=e.value;return!kt(t)&&t.length!==void 0}),e._zod.onattach.push(e=>{let n=e._zod.bag.minimum??-1/0;t.minimum>n&&(e._zod.bag.minimum=t.minimum)}),e._zod.check=n=>{let r=n.value;if(r.length>=t.minimum)return;let i=Yt(r);n.issues.push({origin:i,code:`too_small`,minimum:t.minimum,inclusive:!0,input:r,inst:e,continue:!t.abort})}}),Gn=k(`$ZodCheckLengthEquals`,(e,t)=>{var n;H.init(e,t),(n=e._zod.def).when??(n.when=e=>{let t=e.value;return!kt(t)&&t.length!==void 0}),e._zod.onattach.push(e=>{let n=e._zod.bag;n.minimum=t.length,n.maximum=t.length,n.length=t.length}),e._zod.check=n=>{let r=n.value,i=r.length;if(i===t.length)return;let a=Yt(r),o=i>t.length;n.issues.push({origin:a,...o?{code:`too_big`,maximum:t.length}:{code:`too_small`,minimum:t.length},inclusive:!0,exact:!0,input:n.value,inst:e,continue:!t.abort})}}),Kn=k(`$ZodCheckStringFormat`,(e,t)=>{var n,r;H.init(e,t),e._zod.onattach.push(e=>{let n=e._zod.bag;n.format=t.format,t.pattern&&(n.patterns??=new Set,n.patterns.add(t.pattern))}),t.pattern?(n=e._zod).check??(n.check=n=>{t.pattern.lastIndex=0,!t.pattern.test(n.value)&&n.issues.push({origin:`string`,code:`invalid_format`,format:t.format,input:n.value,...t.pattern?{pattern:t.pattern.toString()}:{},inst:e,continue:!t.abort})}):(r=e._zod).check??(r.check=()=>{})}),qn=k(`$ZodCheckRegex`,(e,t)=>{Kn.init(e,t),e._zod.check=n=>{t.pattern.lastIndex=0,!t.pattern.test(n.value)&&n.issues.push({origin:`string`,code:`invalid_format`,format:`regex`,input:n.value,pattern:t.pattern.toString(),inst:e,continue:!t.abort})}}),Jn=k(`$ZodCheckLowerCase`,(e,t)=>{t.pattern??=Vn,Kn.init(e,t)}),Yn=k(`$ZodCheckUpperCase`,(e,t)=>{t.pattern??=Hn,Kn.init(e,t)}),Xn=k(`$ZodCheckIncludes`,(e,t)=>{H.init(e,t);let n=I(t.includes),r=new RegExp(typeof t.position==`number`?`^.{${t.position}}${n}`:n);t.pattern=r,e._zod.onattach.push(e=>{let t=e._zod.bag;t.patterns??=new Set,t.patterns.add(r)}),e._zod.check=n=>{n.value.includes(t.includes,t.position)||n.issues.push({origin:`string`,code:`invalid_format`,format:`includes`,includes:t.includes,input:n.value,inst:e,continue:!t.abort})}}),Zn=k(`$ZodCheckStartsWith`,(e,t)=>{H.init(e,t);let n=RegExp(`^${I(t.prefix)}.*`);t.pattern??=n,e._zod.onattach.push(e=>{let t=e._zod.bag;t.patterns??=new Set,t.patterns.add(n)}),e._zod.check=n=>{n.value.startsWith(t.prefix)||n.issues.push({origin:`string`,code:`invalid_format`,format:`starts_with`,prefix:t.prefix,input:n.value,inst:e,continue:!t.abort})}}),Qn=k(`$ZodCheckEndsWith`,(e,t)=>{H.init(e,t);let n=RegExp(`.*${I(t.suffix)}$`);t.pattern??=n,e._zod.onattach.push(e=>{let t=e._zod.bag;t.patterns??=new Set,t.patterns.add(n)}),e._zod.check=n=>{n.value.endsWith(t.suffix)||n.issues.push({origin:`string`,code:`invalid_format`,format:`ends_with`,suffix:t.suffix,input:n.value,inst:e,continue:!t.abort})}}),$n=k(`$ZodCheckOverwrite`,(e,t)=>{H.init(e,t),e._zod.check=e=>{e.value=t.tx(e.value)}});var er=class{constructor(e=[]){this.content=[],this.indent=0,this&&(this.args=e)}indented(e){this.indent+=1,e(this),--this.indent}write(e){if(typeof e==`function`){e(this,{execution:`sync`}),e(this,{execution:`async`});return}let t=e.split(`
5
5
  `).filter(e=>e),n=Math.min(...t.map(e=>e.length-e.trimStart().length)),r=t.map(e=>e.slice(n)).map(e=>` `.repeat(this.indent*2)+e);for(let e of r)this.content.push(e)}compile(){let e=Function,t=this?.args,n=[...(this?.content??[``]).map(e=>` ${e}`)];return new e(...t,n.join(`
6
- `))}};const er={major:4,minor:3,patch:6},W=A(`$ZodType`,(e,t)=>{var n;e??={},e._zod.def=t,e._zod.bag=e._zod.bag||{},e._zod.version=er;let r=[...e._zod.def.checks??[]];e._zod.traits.has(`$ZodCheck`)&&r.unshift(e);for(let t of r)for(let n of t._zod.onattach)n(e);if(r.length===0)(n=e._zod).deferred??(n.deferred=[]),e._zod.deferred?.push(()=>{e._zod.run=e._zod.parse});else{let t=(e,t,n)=>{let r=B(e),i;for(let a of t){if(a._zod.def.when){if(!a._zod.def.when(e))continue}else if(r)continue;let t=e.issues.length,o=a._zod.check(e);if(o instanceof Promise&&n?.async===!1)throw new j;if(i||o instanceof Promise)i=(i??Promise.resolve()).then(async()=>{await o,e.issues.length!==t&&(r||=B(e,t))});else{if(e.issues.length===t)continue;r||=B(e,t)}}return i?i.then(()=>e):e},n=(n,i,a)=>{if(B(n))return n.aborted=!0,n;let o=t(i,r,a);if(o instanceof Promise){if(a.async===!1)throw new j;return o.then(t=>e._zod.parse(t,a))}return e._zod.parse(o,a)};e._zod.run=(i,a)=>{if(a.skipChecks)return e._zod.parse(i,a);if(a.direction===`backward`){let t=e._zod.parse({value:i.value,issues:[]},{...a,skipChecks:!0});return t instanceof Promise?t.then(e=>n(e,i,a)):n(t,i,a)}let o=e._zod.parse(i,a);if(o instanceof Promise){if(a.async===!1)throw new j;return o.then(e=>t(e,r,a))}return t(o,r,a)}}N(e,`~standard`,()=>({validate:t=>{try{let n=rn(e,t);return n.success?{value:n.data}:{issues:n.error?.issues}}catch{return on(e,t).then(e=>e.success?{value:e.data}:{issues:e.error?.issues})}},vendor:`zod`,version:1}))}),tr=A(`$ZodString`,(e,t)=>{W.init(e,t),e._zod.pattern=[...e?._zod.bag?.patterns??[]].pop()??Rn(e._zod.bag),e._zod.parse=(n,r)=>{if(t.coerce)try{n.value=String(n.value)}catch{}return typeof n.value==`string`||n.issues.push({expected:`string`,code:`invalid_type`,input:n.value,inst:e}),n}}),G=A(`$ZodStringFormat`,(e,t)=>{Gn.init(e,t),tr.init(e,t)}),nr=A(`$ZodGUID`,(e,t)=>{t.pattern??=Sn,G.init(e,t)}),rr=A(`$ZodUUID`,(e,t)=>{if(t.version){let e={v1:1,v2:2,v3:3,v4:4,v5:5,v6:6,v7:7,v8:8}[t.version];if(e===void 0)throw Error(`Invalid UUID version: "${t.version}"`);t.pattern??=Cn(e)}else t.pattern??=Cn();G.init(e,t)}),ir=A(`$ZodEmail`,(e,t)=>{t.pattern??=wn,G.init(e,t)}),ar=A(`$ZodURL`,(e,t)=>{G.init(e,t),e._zod.check=n=>{try{let r=n.value.trim(),i=new URL(r);t.hostname&&(t.hostname.lastIndex=0,t.hostname.test(i.hostname)||n.issues.push({code:`invalid_format`,format:`url`,note:`Invalid hostname`,pattern:t.hostname.source,input:n.value,inst:e,continue:!t.abort})),t.protocol&&(t.protocol.lastIndex=0,t.protocol.test(i.protocol.endsWith(`:`)?i.protocol.slice(0,-1):i.protocol)||n.issues.push({code:`invalid_format`,format:`url`,note:`Invalid protocol`,pattern:t.protocol.source,input:n.value,inst:e,continue:!t.abort})),t.normalize?n.value=i.href:n.value=r;return}catch{n.issues.push({code:`invalid_format`,format:`url`,input:n.value,inst:e,continue:!t.abort})}}}),or=A(`$ZodEmoji`,(e,t)=>{t.pattern??=Tn(),G.init(e,t)}),sr=A(`$ZodNanoID`,(e,t)=>{t.pattern??=bn,G.init(e,t)}),cr=A(`$ZodCUID`,(e,t)=>{t.pattern??=hn,G.init(e,t)}),lr=A(`$ZodCUID2`,(e,t)=>{t.pattern??=gn,G.init(e,t)}),ur=A(`$ZodULID`,(e,t)=>{t.pattern??=_n,G.init(e,t)}),dr=A(`$ZodXID`,(e,t)=>{t.pattern??=vn,G.init(e,t)}),fr=A(`$ZodKSUID`,(e,t)=>{t.pattern??=yn,G.init(e,t)}),pr=A(`$ZodISODateTime`,(e,t)=>{t.pattern??=Ln(t),G.init(e,t)}),mr=A(`$ZodISODate`,(e,t)=>{t.pattern??=Pn,G.init(e,t)}),hr=A(`$ZodISOTime`,(e,t)=>{t.pattern??=In(t),G.init(e,t)}),gr=A(`$ZodISODuration`,(e,t)=>{t.pattern??=xn,G.init(e,t)}),_r=A(`$ZodIPv4`,(e,t)=>{t.pattern??=En,G.init(e,t),e._zod.bag.format=`ipv4`}),vr=A(`$ZodIPv6`,(e,t)=>{t.pattern??=Dn,G.init(e,t),e._zod.bag.format=`ipv6`,e._zod.check=n=>{try{new URL(`http://[${n.value}]`)}catch{n.issues.push({code:`invalid_format`,format:`ipv6`,input:n.value,inst:e,continue:!t.abort})}}}),yr=A(`$ZodCIDRv4`,(e,t)=>{t.pattern??=On,G.init(e,t)}),br=A(`$ZodCIDRv6`,(e,t)=>{t.pattern??=kn,G.init(e,t),e._zod.check=n=>{let r=n.value.split(`/`);try{if(r.length!==2)throw Error();let[e,t]=r;if(!t)throw Error();let n=Number(t);if(`${n}`!==t||n<0||n>128)throw Error();new URL(`http://[${e}]`)}catch{n.issues.push({code:`invalid_format`,format:`cidrv6`,input:n.value,inst:e,continue:!t.abort})}}});function xr(e){if(e===``)return!0;if(e.length%4!=0)return!1;try{return atob(e),!0}catch{return!1}}const Sr=A(`$ZodBase64`,(e,t)=>{t.pattern??=An,G.init(e,t),e._zod.bag.contentEncoding=`base64`,e._zod.check=n=>{xr(n.value)||n.issues.push({code:`invalid_format`,format:`base64`,input:n.value,inst:e,continue:!t.abort})}});function Cr(e){if(!jn.test(e))return!1;let t=e.replace(/[-_]/g,e=>e===`-`?`+`:`/`);return xr(t.padEnd(Math.ceil(t.length/4)*4,`=`))}const wr=A(`$ZodBase64URL`,(e,t)=>{t.pattern??=jn,G.init(e,t),e._zod.bag.contentEncoding=`base64url`,e._zod.check=n=>{Cr(n.value)||n.issues.push({code:`invalid_format`,format:`base64url`,input:n.value,inst:e,continue:!t.abort})}}),Tr=A(`$ZodE164`,(e,t)=>{t.pattern??=Mn,G.init(e,t)});function Er(e,t=null){try{let n=e.split(`.`);if(n.length!==3)return!1;let[r]=n;if(!r)return!1;let i=JSON.parse(atob(r));return!(`typ`in i&&i?.typ!==`JWT`||!i.alg||t&&(!(`alg`in i)||i.alg!==t))}catch{return!1}}const Dr=A(`$ZodJWT`,(e,t)=>{G.init(e,t),e._zod.check=n=>{Er(n.value,t.alg)||n.issues.push({code:`invalid_format`,format:`jwt`,input:n.value,inst:e,continue:!t.abort})}}),Or=A(`$ZodBoolean`,(e,t)=>{W.init(e,t),e._zod.pattern=zn,e._zod.parse=(n,r)=>{if(t.coerce)try{n.value=!!n.value}catch{}let i=n.value;return typeof i==`boolean`||n.issues.push({expected:`boolean`,code:`invalid_type`,input:i,inst:e}),n}}),kr=A(`$ZodUnknown`,(e,t)=>{W.init(e,t),e._zod.parse=e=>e}),Ar=A(`$ZodNever`,(e,t)=>{W.init(e,t),e._zod.parse=(t,n)=>(t.issues.push({expected:`never`,code:`invalid_type`,input:t.value,inst:e}),t)});function jr(e,t,n){e.issues.length&&t.issues.push(...Kt(n,e.issues)),t.value[n]=e.value}const Mr=A(`$ZodArray`,(e,t)=>{W.init(e,t),e._zod.parse=(n,r)=>{let i=n.value;if(!Array.isArray(i))return n.issues.push({expected:`array`,code:`invalid_type`,input:i,inst:e}),n;n.value=Array(i.length);let a=[];for(let e=0;e<i.length;e++){let o=i[e],s=t.element._zod.run({value:o,issues:[]},r);s instanceof Promise?a.push(s.then(t=>jr(t,n,e))):jr(s,n,e)}return a.length?Promise.all(a).then(()=>n):n}});function Nr(e,t,n,r,i){if(e.issues.length){if(i&&!(n in r))return;t.issues.push(...Kt(n,e.issues))}e.value===void 0?n in r&&(t.value[n]=void 0):t.value[n]=e.value}function Pr(e){let t=Object.keys(e.shape);for(let n of t)if(!e.shape?.[n]?._zod?.traits?.has(`$ZodType`))throw Error(`Invalid element at key "${n}": expected a Zod schema`);let n=Rt(e.shape);return{...e,keys:t,keySet:new Set(t),numKeys:t.length,optionalKeys:new Set(n)}}function Fr(e,t,n,r,i,a){let o=[],s=i.keySet,c=i.catchall._zod,l=c.def.type,u=c.optout===`optional`;for(let i in t){if(s.has(i))continue;if(l===`never`){o.push(i);continue}let a=c.run({value:t[i],issues:[]},r);a instanceof Promise?e.push(a.then(e=>Nr(e,n,i,t,u))):Nr(a,n,i,t,u)}return o.length&&n.issues.push({code:`unrecognized_keys`,keys:o,input:t,inst:a}),e.length?Promise.all(e).then(()=>n):n}const Ir=A(`$ZodObject`,(e,t)=>{if(W.init(e,t),!Object.getOwnPropertyDescriptor(t,`shape`)?.get){let e=t.shape;Object.defineProperty(t,`shape`,{get:()=>{let n={...e};return Object.defineProperty(t,`shape`,{value:n}),n}})}let n=Dt(()=>Pr(t));N(e._zod,`propValues`,()=>{let e=t.shape,n={};for(let t in e){let r=e[t]._zod;if(r.values){n[t]??(n[t]=new Set);for(let e of r.values)n[t].add(e)}}return n});let r=Pt,i=t.catchall,a;e._zod.parse=(t,o)=>{a??=n.value;let s=t.value;if(!r(s))return t.issues.push({expected:`object`,code:`invalid_type`,input:s,inst:e}),t;t.value={};let c=[],l=a.shape;for(let e of a.keys){let n=l[e],r=n._zod.optout===`optional`,i=n._zod.run({value:s[e],issues:[]},o);i instanceof Promise?c.push(i.then(n=>Nr(n,t,e,s,r))):Nr(i,t,e,s,r)}return i?Fr(c,s,t,o,n.value,e):c.length?Promise.all(c).then(()=>t):t}}),Lr=A(`$ZodObjectJIT`,(e,t)=>{Ir.init(e,t);let n=e._zod.parse,r=Dt(()=>Pr(t)),i=e=>{let t=new $n([`shape`,`payload`,`ctx`]),n=r.value,i=e=>{let t=jt(e);return`shape[${t}]._zod.run({ value: input[${t}], issues: [] }, ctx)`};t.write(`const input = payload.value;`);let a=Object.create(null),o=0;for(let e of n.keys)a[e]=`key_${o++}`;t.write(`const newResult = {};`);for(let r of n.keys){let n=a[r],o=jt(r),s=e[r]?._zod?.optout===`optional`;t.write(`const ${n} = ${i(r)};`),s?t.write(`
6
+ `))}};const tr={major:4,minor:3,patch:6},U=k(`$ZodType`,(e,t)=>{var n;e??={},e._zod.def=t,e._zod.bag=e._zod.bag||{},e._zod.version=tr;let r=[...e._zod.def.checks??[]];e._zod.traits.has(`$ZodCheck`)&&r.unshift(e);for(let t of r)for(let n of t._zod.onattach)n(e);if(r.length===0)(n=e._zod).deferred??(n.deferred=[]),e._zod.deferred?.push(()=>{e._zod.run=e._zod.parse});else{let t=(e,t,n)=>{let r=z(e),i;for(let a of t){if(a._zod.def.when){if(!a._zod.def.when(e))continue}else if(r)continue;let t=e.issues.length,o=a._zod.check(e);if(o instanceof Promise&&n?.async===!1)throw new A;if(i||o instanceof Promise)i=(i??Promise.resolve()).then(async()=>{await o,e.issues.length!==t&&(r||=z(e,t))});else{if(e.issues.length===t)continue;r||=z(e,t)}}return i?i.then(()=>e):e},n=(n,i,a)=>{if(z(n))return n.aborted=!0,n;let o=t(i,r,a);if(o instanceof Promise){if(a.async===!1)throw new A;return o.then(t=>e._zod.parse(t,a))}return e._zod.parse(o,a)};e._zod.run=(i,a)=>{if(a.skipChecks)return e._zod.parse(i,a);if(a.direction===`backward`){let t=e._zod.parse({value:i.value,issues:[]},{...a,skipChecks:!0});return t instanceof Promise?t.then(e=>n(e,i,a)):n(t,i,a)}let o=e._zod.parse(i,a);if(o instanceof Promise){if(a.async===!1)throw new A;return o.then(e=>t(e,r,a))}return t(o,r,a)}}M(e,`~standard`,()=>({validate:t=>{try{let n=an(e,t);return n.success?{value:n.data}:{issues:n.error?.issues}}catch{return sn(e,t).then(e=>e.success?{value:e.data}:{issues:e.error?.issues})}},vendor:`zod`,version:1}))}),nr=k(`$ZodString`,(e,t)=>{U.init(e,t),e._zod.pattern=[...e?._zod.bag?.patterns??[]].pop()??zn(e._zod.bag),e._zod.parse=(n,r)=>{if(t.coerce)try{n.value=String(n.value)}catch{}return typeof n.value==`string`||n.issues.push({expected:`string`,code:`invalid_type`,input:n.value,inst:e}),n}}),W=k(`$ZodStringFormat`,(e,t)=>{Kn.init(e,t),nr.init(e,t)}),rr=k(`$ZodGUID`,(e,t)=>{t.pattern??=Cn,W.init(e,t)}),ir=k(`$ZodUUID`,(e,t)=>{if(t.version){let e={v1:1,v2:2,v3:3,v4:4,v5:5,v6:6,v7:7,v8:8}[t.version];if(e===void 0)throw Error(`Invalid UUID version: "${t.version}"`);t.pattern??=wn(e)}else t.pattern??=wn();W.init(e,t)}),ar=k(`$ZodEmail`,(e,t)=>{t.pattern??=Tn,W.init(e,t)}),or=k(`$ZodURL`,(e,t)=>{W.init(e,t),e._zod.check=n=>{try{let r=n.value.trim(),i=new URL(r);t.hostname&&(t.hostname.lastIndex=0,t.hostname.test(i.hostname)||n.issues.push({code:`invalid_format`,format:`url`,note:`Invalid hostname`,pattern:t.hostname.source,input:n.value,inst:e,continue:!t.abort})),t.protocol&&(t.protocol.lastIndex=0,t.protocol.test(i.protocol.endsWith(`:`)?i.protocol.slice(0,-1):i.protocol)||n.issues.push({code:`invalid_format`,format:`url`,note:`Invalid protocol`,pattern:t.protocol.source,input:n.value,inst:e,continue:!t.abort})),t.normalize?n.value=i.href:n.value=r;return}catch{n.issues.push({code:`invalid_format`,format:`url`,input:n.value,inst:e,continue:!t.abort})}}}),sr=k(`$ZodEmoji`,(e,t)=>{t.pattern??=En(),W.init(e,t)}),cr=k(`$ZodNanoID`,(e,t)=>{t.pattern??=xn,W.init(e,t)}),lr=k(`$ZodCUID`,(e,t)=>{t.pattern??=gn,W.init(e,t)}),ur=k(`$ZodCUID2`,(e,t)=>{t.pattern??=_n,W.init(e,t)}),dr=k(`$ZodULID`,(e,t)=>{t.pattern??=vn,W.init(e,t)}),fr=k(`$ZodXID`,(e,t)=>{t.pattern??=yn,W.init(e,t)}),pr=k(`$ZodKSUID`,(e,t)=>{t.pattern??=bn,W.init(e,t)}),mr=k(`$ZodISODateTime`,(e,t)=>{t.pattern??=Rn(t),W.init(e,t)}),hr=k(`$ZodISODate`,(e,t)=>{t.pattern??=Fn,W.init(e,t)}),gr=k(`$ZodISOTime`,(e,t)=>{t.pattern??=Ln(t),W.init(e,t)}),_r=k(`$ZodISODuration`,(e,t)=>{t.pattern??=Sn,W.init(e,t)}),vr=k(`$ZodIPv4`,(e,t)=>{t.pattern??=Dn,W.init(e,t),e._zod.bag.format=`ipv4`}),yr=k(`$ZodIPv6`,(e,t)=>{t.pattern??=On,W.init(e,t),e._zod.bag.format=`ipv6`,e._zod.check=n=>{try{new URL(`http://[${n.value}]`)}catch{n.issues.push({code:`invalid_format`,format:`ipv6`,input:n.value,inst:e,continue:!t.abort})}}}),br=k(`$ZodCIDRv4`,(e,t)=>{t.pattern??=kn,W.init(e,t)}),xr=k(`$ZodCIDRv6`,(e,t)=>{t.pattern??=An,W.init(e,t),e._zod.check=n=>{let r=n.value.split(`/`);try{if(r.length!==2)throw Error();let[e,t]=r;if(!t)throw Error();let n=Number(t);if(`${n}`!==t||n<0||n>128)throw Error();new URL(`http://[${e}]`)}catch{n.issues.push({code:`invalid_format`,format:`cidrv6`,input:n.value,inst:e,continue:!t.abort})}}});function Sr(e){if(e===``)return!0;if(e.length%4!=0)return!1;try{return atob(e),!0}catch{return!1}}const Cr=k(`$ZodBase64`,(e,t)=>{t.pattern??=jn,W.init(e,t),e._zod.bag.contentEncoding=`base64`,e._zod.check=n=>{Sr(n.value)||n.issues.push({code:`invalid_format`,format:`base64`,input:n.value,inst:e,continue:!t.abort})}});function wr(e){if(!Mn.test(e))return!1;let t=e.replace(/[-_]/g,e=>e===`-`?`+`:`/`);return Sr(t.padEnd(Math.ceil(t.length/4)*4,`=`))}const Tr=k(`$ZodBase64URL`,(e,t)=>{t.pattern??=Mn,W.init(e,t),e._zod.bag.contentEncoding=`base64url`,e._zod.check=n=>{wr(n.value)||n.issues.push({code:`invalid_format`,format:`base64url`,input:n.value,inst:e,continue:!t.abort})}}),Er=k(`$ZodE164`,(e,t)=>{t.pattern??=Nn,W.init(e,t)});function Dr(e,t=null){try{let n=e.split(`.`);if(n.length!==3)return!1;let[r]=n;if(!r)return!1;let i=JSON.parse(atob(r));return!(`typ`in i&&i?.typ!==`JWT`||!i.alg||t&&(!(`alg`in i)||i.alg!==t))}catch{return!1}}const Or=k(`$ZodJWT`,(e,t)=>{W.init(e,t),e._zod.check=n=>{Dr(n.value,t.alg)||n.issues.push({code:`invalid_format`,format:`jwt`,input:n.value,inst:e,continue:!t.abort})}}),kr=k(`$ZodBoolean`,(e,t)=>{U.init(e,t),e._zod.pattern=Bn,e._zod.parse=(n,r)=>{if(t.coerce)try{n.value=!!n.value}catch{}let i=n.value;return typeof i==`boolean`||n.issues.push({expected:`boolean`,code:`invalid_type`,input:i,inst:e}),n}}),Ar=k(`$ZodUnknown`,(e,t)=>{U.init(e,t),e._zod.parse=e=>e}),jr=k(`$ZodNever`,(e,t)=>{U.init(e,t),e._zod.parse=(t,n)=>(t.issues.push({expected:`never`,code:`invalid_type`,input:t.value,inst:e}),t)});function Mr(e,t,n){e.issues.length&&t.issues.push(...qt(n,e.issues)),t.value[n]=e.value}const Nr=k(`$ZodArray`,(e,t)=>{U.init(e,t),e._zod.parse=(n,r)=>{let i=n.value;if(!Array.isArray(i))return n.issues.push({expected:`array`,code:`invalid_type`,input:i,inst:e}),n;n.value=Array(i.length);let a=[];for(let e=0;e<i.length;e++){let o=i[e],s=t.element._zod.run({value:o,issues:[]},r);s instanceof Promise?a.push(s.then(t=>Mr(t,n,e))):Mr(s,n,e)}return a.length?Promise.all(a).then(()=>n):n}});function Pr(e,t,n,r,i){if(e.issues.length){if(i&&!(n in r))return;t.issues.push(...qt(n,e.issues))}e.value===void 0?n in r&&(t.value[n]=void 0):t.value[n]=e.value}function Fr(e){let t=Object.keys(e.shape);for(let n of t)if(!e.shape?.[n]?._zod?.traits?.has(`$ZodType`))throw Error(`Invalid element at key "${n}": expected a Zod schema`);let n=zt(e.shape);return{...e,keys:t,keySet:new Set(t),numKeys:t.length,optionalKeys:new Set(n)}}function Ir(e,t,n,r,i,a){let o=[],s=i.keySet,c=i.catchall._zod,l=c.def.type,u=c.optout===`optional`;for(let i in t){if(s.has(i))continue;if(l===`never`){o.push(i);continue}let a=c.run({value:t[i],issues:[]},r);a instanceof Promise?e.push(a.then(e=>Pr(e,n,i,t,u))):Pr(a,n,i,t,u)}return o.length&&n.issues.push({code:`unrecognized_keys`,keys:o,input:t,inst:a}),e.length?Promise.all(e).then(()=>n):n}const Lr=k(`$ZodObject`,(e,t)=>{if(U.init(e,t),!Object.getOwnPropertyDescriptor(t,`shape`)?.get){let e=t.shape;Object.defineProperty(t,`shape`,{get:()=>{let n={...e};return Object.defineProperty(t,`shape`,{value:n}),n}})}let n=Ot(()=>Fr(t));M(e._zod,`propValues`,()=>{let e=t.shape,n={};for(let t in e){let r=e[t]._zod;if(r.values){n[t]??(n[t]=new Set);for(let e of r.values)n[t].add(e)}}return n});let r=Ft,i=t.catchall,a;e._zod.parse=(t,o)=>{a??=n.value;let s=t.value;if(!r(s))return t.issues.push({expected:`object`,code:`invalid_type`,input:s,inst:e}),t;t.value={};let c=[],l=a.shape;for(let e of a.keys){let n=l[e],r=n._zod.optout===`optional`,i=n._zod.run({value:s[e],issues:[]},o);i instanceof Promise?c.push(i.then(n=>Pr(n,t,e,s,r))):Pr(i,t,e,s,r)}return i?Ir(c,s,t,o,n.value,e):c.length?Promise.all(c).then(()=>t):t}}),Rr=k(`$ZodObjectJIT`,(e,t)=>{Lr.init(e,t);let n=e._zod.parse,r=Ot(()=>Fr(t)),i=e=>{let t=new er([`shape`,`payload`,`ctx`]),n=r.value,i=e=>{let t=Mt(e);return`shape[${t}]._zod.run({ value: input[${t}], issues: [] }, ctx)`};t.write(`const input = payload.value;`);let a=Object.create(null),o=0;for(let e of n.keys)a[e]=`key_${o++}`;t.write(`const newResult = {};`);for(let r of n.keys){let n=a[r],o=Mt(r),s=e[r]?._zod?.optout===`optional`;t.write(`const ${n} = ${i(r)};`),s?t.write(`
7
7
  if (${n}.issues.length) {
8
8
  if (${o} in input) {
9
9
  payload.issues = payload.issues.concat(${n}.issues.map(iss => ({
@@ -37,8 +37,8 @@ import{cpSync as e,createWriteStream as t,existsSync as n,mkdirSync as r,mkdtemp
37
37
  newResult[${o}] = ${n}.value;
38
38
  }
39
39
 
40
- `)}t.write(`payload.value = newResult;`),t.write(`return payload;`);let s=t.compile();return(t,n)=>s(e,t,n)},a,o=Pt,s=!wt.jitless,c=s&&Ft.value,l=t.catchall,u;e._zod.parse=(d,f)=>{u??=r.value;let p=d.value;return o(p)?s&&c&&f?.async===!1&&f.jitless!==!0?(a||=i(t.shape),d=a(d,f),l?Fr([],p,d,f,u,e):d):n(d,f):(d.issues.push({expected:`object`,code:`invalid_type`,input:p,inst:e}),d)}});function Rr(e,t,n,r){for(let n of e)if(n.issues.length===0)return t.value=n.value,t;let i=e.filter(e=>!B(e));return i.length===1?(t.value=i[0].value,i[0]):(t.issues.push({code:`invalid_union`,input:t.value,inst:n,errors:e.map(e=>e.issues.map(e=>V(e,r,M())))}),t)}const zr=A(`$ZodUnion`,(e,t)=>{W.init(e,t),N(e._zod,`optin`,()=>t.options.some(e=>e._zod.optin===`optional`)?`optional`:void 0),N(e._zod,`optout`,()=>t.options.some(e=>e._zod.optout===`optional`)?`optional`:void 0),N(e._zod,`values`,()=>{if(t.options.every(e=>e._zod.values))return new Set(t.options.flatMap(e=>Array.from(e._zod.values)))}),N(e._zod,`pattern`,()=>{if(t.options.every(e=>e._zod.pattern)){let e=t.options.map(e=>e._zod.pattern);return RegExp(`^(${e.map(e=>kt(e.source)).join(`|`)})$`)}});let n=t.options.length===1,r=t.options[0]._zod.run;e._zod.parse=(i,a)=>{if(n)return r(i,a);let o=!1,s=[];for(let e of t.options){let t=e._zod.run({value:i.value,issues:[]},a);if(t instanceof Promise)s.push(t),o=!0;else{if(t.issues.length===0)return t;s.push(t)}}return o?Promise.all(s).then(t=>Rr(t,i,e,a)):Rr(s,i,e,a)}}),Br=A(`$ZodIntersection`,(e,t)=>{W.init(e,t),e._zod.parse=(e,n)=>{let r=e.value,i=t.left._zod.run({value:r,issues:[]},n),a=t.right._zod.run({value:r,issues:[]},n);return i instanceof Promise||a instanceof Promise?Promise.all([i,a]).then(([t,n])=>Hr(e,t,n)):Hr(e,i,a)}});function Vr(e,t){if(e===t||e instanceof Date&&t instanceof Date&&+e==+t)return{valid:!0,data:e};if(I(e)&&I(t)){let n=Object.keys(t),r=Object.keys(e).filter(e=>n.indexOf(e)!==-1),i={...e,...t};for(let n of r){let r=Vr(e[n],t[n]);if(!r.valid)return{valid:!1,mergeErrorPath:[n,...r.mergeErrorPath]};i[n]=r.data}return{valid:!0,data:i}}if(Array.isArray(e)&&Array.isArray(t)){if(e.length!==t.length)return{valid:!1,mergeErrorPath:[]};let n=[];for(let r=0;r<e.length;r++){let i=e[r],a=t[r],o=Vr(i,a);if(!o.valid)return{valid:!1,mergeErrorPath:[r,...o.mergeErrorPath]};n.push(o.data)}return{valid:!0,data:n}}return{valid:!1,mergeErrorPath:[]}}function Hr(e,t,n){let r=new Map,i;for(let n of t.issues)if(n.code===`unrecognized_keys`){i??=n;for(let e of n.keys)r.has(e)||r.set(e,{}),r.get(e).l=!0}else e.issues.push(n);for(let t of n.issues)if(t.code===`unrecognized_keys`)for(let e of t.keys)r.has(e)||r.set(e,{}),r.get(e).r=!0;else e.issues.push(t);let a=[...r].filter(([,e])=>e.l&&e.r).map(([e])=>e);if(a.length&&i&&e.issues.push({...i,keys:a}),B(e))return e;let o=Vr(t.value,n.value);if(!o.valid)throw Error(`Unmergable intersection. Error path: ${JSON.stringify(o.mergeErrorPath)}`);return e.value=o.data,e}const Ur=A(`$ZodEnum`,(e,t)=>{W.init(e,t);let n=Tt(t.entries),r=new Set(n);e._zod.values=r,e._zod.pattern=RegExp(`^(${n.filter(e=>Lt.has(typeof e)).map(e=>typeof e==`string`?L(e):e.toString()).join(`|`)})$`),e._zod.parse=(t,i)=>{let a=t.value;return r.has(a)||t.issues.push({code:`invalid_value`,values:n,input:a,inst:e}),t}}),Wr=A(`$ZodLiteral`,(e,t)=>{if(W.init(e,t),t.values.length===0)throw Error(`Cannot create literal schema with no valid values`);let n=new Set(t.values);e._zod.values=n,e._zod.pattern=RegExp(`^(${t.values.map(e=>typeof e==`string`?L(e):e?L(e.toString()):String(e)).join(`|`)})$`),e._zod.parse=(r,i)=>{let a=r.value;return n.has(a)||r.issues.push({code:`invalid_value`,values:t.values,input:a,inst:e}),r}}),Gr=A(`$ZodTransform`,(e,t)=>{W.init(e,t),e._zod.parse=(n,r)=>{if(r.direction===`backward`)throw new Ct(e.constructor.name);let i=t.transform(n.value,n);if(r.async)return(i instanceof Promise?i:Promise.resolve(i)).then(e=>(n.value=e,n));if(i instanceof Promise)throw new j;return n.value=i,n}});function Kr(e,t){return e.issues.length&&t===void 0?{issues:[],value:void 0}:e}const qr=A(`$ZodOptional`,(e,t)=>{W.init(e,t),e._zod.optin=`optional`,e._zod.optout=`optional`,N(e._zod,`values`,()=>t.innerType._zod.values?new Set([...t.innerType._zod.values,void 0]):void 0),N(e._zod,`pattern`,()=>{let e=t.innerType._zod.pattern;return e?RegExp(`^(${kt(e.source)})?$`):void 0}),e._zod.parse=(e,n)=>{if(t.innerType._zod.optin===`optional`){let r=t.innerType._zod.run(e,n);return r instanceof Promise?r.then(t=>Kr(t,e.value)):Kr(r,e.value)}return e.value===void 0?e:t.innerType._zod.run(e,n)}}),Jr=A(`$ZodExactOptional`,(e,t)=>{qr.init(e,t),N(e._zod,`values`,()=>t.innerType._zod.values),N(e._zod,`pattern`,()=>t.innerType._zod.pattern),e._zod.parse=(e,n)=>t.innerType._zod.run(e,n)}),Yr=A(`$ZodNullable`,(e,t)=>{W.init(e,t),N(e._zod,`optin`,()=>t.innerType._zod.optin),N(e._zod,`optout`,()=>t.innerType._zod.optout),N(e._zod,`pattern`,()=>{let e=t.innerType._zod.pattern;return e?RegExp(`^(${kt(e.source)}|null)$`):void 0}),N(e._zod,`values`,()=>t.innerType._zod.values?new Set([...t.innerType._zod.values,null]):void 0),e._zod.parse=(e,n)=>e.value===null?e:t.innerType._zod.run(e,n)}),Xr=A(`$ZodDefault`,(e,t)=>{W.init(e,t),e._zod.optin=`optional`,N(e._zod,`values`,()=>t.innerType._zod.values),e._zod.parse=(e,n)=>{if(n.direction===`backward`)return t.innerType._zod.run(e,n);if(e.value===void 0)return e.value=t.defaultValue,e;let r=t.innerType._zod.run(e,n);return r instanceof Promise?r.then(e=>Zr(e,t)):Zr(r,t)}});function Zr(e,t){return e.value===void 0&&(e.value=t.defaultValue),e}const Qr=A(`$ZodPrefault`,(e,t)=>{W.init(e,t),e._zod.optin=`optional`,N(e._zod,`values`,()=>t.innerType._zod.values),e._zod.parse=(e,n)=>(n.direction===`backward`||e.value===void 0&&(e.value=t.defaultValue),t.innerType._zod.run(e,n))}),$r=A(`$ZodNonOptional`,(e,t)=>{W.init(e,t),N(e._zod,`values`,()=>{let e=t.innerType._zod.values;return e?new Set([...e].filter(e=>e!==void 0)):void 0}),e._zod.parse=(n,r)=>{let i=t.innerType._zod.run(n,r);return i instanceof Promise?i.then(t=>ei(t,e)):ei(i,e)}});function ei(e,t){return!e.issues.length&&e.value===void 0&&e.issues.push({code:`invalid_type`,expected:`nonoptional`,input:e.value,inst:t}),e}const ti=A(`$ZodCatch`,(e,t)=>{W.init(e,t),N(e._zod,`optin`,()=>t.innerType._zod.optin),N(e._zod,`optout`,()=>t.innerType._zod.optout),N(e._zod,`values`,()=>t.innerType._zod.values),e._zod.parse=(e,n)=>{if(n.direction===`backward`)return t.innerType._zod.run(e,n);let r=t.innerType._zod.run(e,n);return r instanceof Promise?r.then(r=>(e.value=r.value,r.issues.length&&(e.value=t.catchValue({...e,error:{issues:r.issues.map(e=>V(e,n,M()))},input:e.value}),e.issues=[]),e)):(e.value=r.value,r.issues.length&&(e.value=t.catchValue({...e,error:{issues:r.issues.map(e=>V(e,n,M()))},input:e.value}),e.issues=[]),e)}}),ni=A(`$ZodPipe`,(e,t)=>{W.init(e,t),N(e._zod,`values`,()=>t.in._zod.values),N(e._zod,`optin`,()=>t.in._zod.optin),N(e._zod,`optout`,()=>t.out._zod.optout),N(e._zod,`propValues`,()=>t.in._zod.propValues),e._zod.parse=(e,n)=>{if(n.direction===`backward`){let r=t.out._zod.run(e,n);return r instanceof Promise?r.then(e=>ri(e,t.in,n)):ri(r,t.in,n)}let r=t.in._zod.run(e,n);return r instanceof Promise?r.then(e=>ri(e,t.out,n)):ri(r,t.out,n)}});function ri(e,t,n){return e.issues.length?(e.aborted=!0,e):t._zod.run({value:e.value,issues:e.issues},n)}const ii=A(`$ZodReadonly`,(e,t)=>{W.init(e,t),N(e._zod,`propValues`,()=>t.innerType._zod.propValues),N(e._zod,`values`,()=>t.innerType._zod.values),N(e._zod,`optin`,()=>t.innerType?._zod?.optin),N(e._zod,`optout`,()=>t.innerType?._zod?.optout),e._zod.parse=(e,n)=>{if(n.direction===`backward`)return t.innerType._zod.run(e,n);let r=t.innerType._zod.run(e,n);return r instanceof Promise?r.then(ai):ai(r)}});function ai(e){return e.value=Object.freeze(e.value),e}const oi=A(`$ZodCustom`,(e,t)=>{U.init(e,t),W.init(e,t),e._zod.parse=(e,t)=>e,e._zod.check=n=>{let r=n.value,i=t.fn(r);if(i instanceof Promise)return i.then(t=>si(t,n,r,e));si(i,n,r,e)}});function si(e,t,n,r){if(!e){let e={code:`custom`,input:n,inst:r,path:[...r._zod.def.path??[]],continue:!r._zod.def.abort};r._zod.def.params&&(e.params=r._zod.def.params),t.issues.push(H(e))}}var ci,li=class{constructor(){this._map=new WeakMap,this._idmap=new Map}add(e,...t){let n=t[0];return this._map.set(e,n),n&&typeof n==`object`&&`id`in n&&this._idmap.set(n.id,e),this}clear(){return this._map=new WeakMap,this._idmap=new Map,this}remove(e){let t=this._map.get(e);return t&&typeof t==`object`&&`id`in t&&this._idmap.delete(t.id),this._map.delete(e),this}get(e){let t=e._zod.parent;if(t){let n={...this.get(t)??{}};delete n.id;let r={...n,...this._map.get(e)};return Object.keys(r).length?r:void 0}return this._map.get(e)}has(e){return this._map.has(e)}};function ui(){return new li}(ci=globalThis).__zod_globalRegistry??(ci.__zod_globalRegistry=ui());const di=globalThis.__zod_globalRegistry;function fi(e,t){return new e({type:`string`,...z(t)})}function pi(e,t){return new e({type:`string`,format:`email`,check:`string_format`,abort:!1,...z(t)})}function mi(e,t){return new e({type:`string`,format:`guid`,check:`string_format`,abort:!1,...z(t)})}function hi(e,t){return new e({type:`string`,format:`uuid`,check:`string_format`,abort:!1,...z(t)})}function gi(e,t){return new e({type:`string`,format:`uuid`,check:`string_format`,abort:!1,version:`v4`,...z(t)})}function _i(e,t){return new e({type:`string`,format:`uuid`,check:`string_format`,abort:!1,version:`v6`,...z(t)})}function vi(e,t){return new e({type:`string`,format:`uuid`,check:`string_format`,abort:!1,version:`v7`,...z(t)})}function yi(e,t){return new e({type:`string`,format:`url`,check:`string_format`,abort:!1,...z(t)})}function bi(e,t){return new e({type:`string`,format:`emoji`,check:`string_format`,abort:!1,...z(t)})}function xi(e,t){return new e({type:`string`,format:`nanoid`,check:`string_format`,abort:!1,...z(t)})}function Si(e,t){return new e({type:`string`,format:`cuid`,check:`string_format`,abort:!1,...z(t)})}function Ci(e,t){return new e({type:`string`,format:`cuid2`,check:`string_format`,abort:!1,...z(t)})}function wi(e,t){return new e({type:`string`,format:`ulid`,check:`string_format`,abort:!1,...z(t)})}function Ti(e,t){return new e({type:`string`,format:`xid`,check:`string_format`,abort:!1,...z(t)})}function Ei(e,t){return new e({type:`string`,format:`ksuid`,check:`string_format`,abort:!1,...z(t)})}function Di(e,t){return new e({type:`string`,format:`ipv4`,check:`string_format`,abort:!1,...z(t)})}function Oi(e,t){return new e({type:`string`,format:`ipv6`,check:`string_format`,abort:!1,...z(t)})}function ki(e,t){return new e({type:`string`,format:`cidrv4`,check:`string_format`,abort:!1,...z(t)})}function Ai(e,t){return new e({type:`string`,format:`cidrv6`,check:`string_format`,abort:!1,...z(t)})}function ji(e,t){return new e({type:`string`,format:`base64`,check:`string_format`,abort:!1,...z(t)})}function Mi(e,t){return new e({type:`string`,format:`base64url`,check:`string_format`,abort:!1,...z(t)})}function Ni(e,t){return new e({type:`string`,format:`e164`,check:`string_format`,abort:!1,...z(t)})}function Pi(e,t){return new e({type:`string`,format:`jwt`,check:`string_format`,abort:!1,...z(t)})}function Fi(e,t){return new e({type:`string`,format:`datetime`,check:`string_format`,offset:!1,local:!1,precision:null,...z(t)})}function Ii(e,t){return new e({type:`string`,format:`date`,check:`string_format`,...z(t)})}function Li(e,t){return new e({type:`string`,format:`time`,check:`string_format`,precision:null,...z(t)})}function Ri(e,t){return new e({type:`string`,format:`duration`,check:`string_format`,...z(t)})}function zi(e,t){return new e({type:`boolean`,...z(t)})}function Bi(e){return new e({type:`unknown`})}function Vi(e,t){return new e({type:`never`,...z(t)})}function Hi(e,t){return new Hn({check:`max_length`,...z(t),maximum:e})}function Ui(e,t){return new Un({check:`min_length`,...z(t),minimum:e})}function Wi(e,t){return new Wn({check:`length_equals`,...z(t),length:e})}function Gi(e,t){return new Kn({check:`string_format`,format:`regex`,...z(t),pattern:e})}function Ki(e){return new qn({check:`string_format`,format:`lowercase`,...z(e)})}function qi(e){return new Jn({check:`string_format`,format:`uppercase`,...z(e)})}function Ji(e,t){return new Yn({check:`string_format`,format:`includes`,...z(t),includes:e})}function Yi(e,t){return new Xn({check:`string_format`,format:`starts_with`,...z(t),prefix:e})}function Xi(e,t){return new Zn({check:`string_format`,format:`ends_with`,...z(t),suffix:e})}function K(e){return new Qn({check:`overwrite`,tx:e})}function Zi(e){return K(t=>t.normalize(e))}function Qi(){return K(e=>e.trim())}function $i(){return K(e=>e.toLowerCase())}function ea(){return K(e=>e.toUpperCase())}function ta(){return K(e=>Mt(e))}function na(e,t,n){return new e({type:`array`,element:t,...z(n)})}function ra(e,t,n){return new e({type:`custom`,check:`custom`,fn:t,...z(n)})}function ia(e){let t=aa(n=>(n.addIssue=e=>{if(typeof e==`string`)n.issues.push(H(e,n.value,t._zod.def));else{let r=e;r.fatal&&(r.continue=!1),r.code??=`custom`,r.input??=n.value,r.inst??=t,r.continue??=!t._zod.def.abort,n.issues.push(H(r))}},e(n.value,n)));return t}function aa(e,t){let n=new U({check:`custom`,...z(t)});return n._zod.check=e,n}function oa(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??di,target:t,unrepresentable:e?.unrepresentable??`throw`,override:e?.override??(()=>{}),io:e?.io??`output`,counter:0,seen:new Map,cycles:e?.cycles??`ref`,reused:e?.reused??`inline`,external:e?.external??void 0}}function q(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);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,q(a,t,r),t.seen.get(a).isParent=!0)}let c=t.metadataRegistry.get(e);return c&&Object.assign(o.schema,c),t.io===`input`&&J(e)&&(delete o.schema.examples,delete o.schema.default),t.io===`input`&&o.schema._prefault&&((r=o.schema).default??(r.default=o.schema._prefault)),delete o.schema._prefault,t.seen.get(e).schema}function sa(e,t){let n=e.seen.get(t);if(!n)throw Error(`Unprocessed schema. This is a bug in Zod.`);let r=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}/${a}`}}if(t[1]===n)return{ref:`#`};let i=`#/${r}/`,a=t[1].schema.id??`__schema${e.counter++}`;return{defId:a,ref:i+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>
40
+ `)}t.write(`payload.value = newResult;`),t.write(`return payload;`);let s=t.compile();return(t,n)=>s(e,t,n)},a,o=Ft,s=!Tt.jitless,c=s&&It.value,l=t.catchall,u;e._zod.parse=(d,f)=>{u??=r.value;let p=d.value;return o(p)?s&&c&&f?.async===!1&&f.jitless!==!0?(a||=i(t.shape),d=a(d,f),l?Ir([],p,d,f,u,e):d):n(d,f):(d.issues.push({expected:`object`,code:`invalid_type`,input:p,inst:e}),d)}});function zr(e,t,n,r){for(let n of e)if(n.issues.length===0)return t.value=n.value,t;let i=e.filter(e=>!z(e));return i.length===1?(t.value=i[0].value,i[0]):(t.issues.push({code:`invalid_union`,input:t.value,inst:n,errors:e.map(e=>e.issues.map(e=>B(e,r,j())))}),t)}const Br=k(`$ZodUnion`,(e,t)=>{U.init(e,t),M(e._zod,`optin`,()=>t.options.some(e=>e._zod.optin===`optional`)?`optional`:void 0),M(e._zod,`optout`,()=>t.options.some(e=>e._zod.optout===`optional`)?`optional`:void 0),M(e._zod,`values`,()=>{if(t.options.every(e=>e._zod.values))return new Set(t.options.flatMap(e=>Array.from(e._zod.values)))}),M(e._zod,`pattern`,()=>{if(t.options.every(e=>e._zod.pattern)){let e=t.options.map(e=>e._zod.pattern);return RegExp(`^(${e.map(e=>At(e.source)).join(`|`)})$`)}});let n=t.options.length===1,r=t.options[0]._zod.run;e._zod.parse=(i,a)=>{if(n)return r(i,a);let o=!1,s=[];for(let e of t.options){let t=e._zod.run({value:i.value,issues:[]},a);if(t instanceof Promise)s.push(t),o=!0;else{if(t.issues.length===0)return t;s.push(t)}}return o?Promise.all(s).then(t=>zr(t,i,e,a)):zr(s,i,e,a)}}),Vr=k(`$ZodIntersection`,(e,t)=>{U.init(e,t),e._zod.parse=(e,n)=>{let r=e.value,i=t.left._zod.run({value:r,issues:[]},n),a=t.right._zod.run({value:r,issues:[]},n);return i instanceof Promise||a instanceof Promise?Promise.all([i,a]).then(([t,n])=>Ur(e,t,n)):Ur(e,i,a)}});function Hr(e,t){if(e===t||e instanceof Date&&t instanceof Date&&+e==+t)return{valid:!0,data:e};if(F(e)&&F(t)){let n=Object.keys(t),r=Object.keys(e).filter(e=>n.indexOf(e)!==-1),i={...e,...t};for(let n of r){let r=Hr(e[n],t[n]);if(!r.valid)return{valid:!1,mergeErrorPath:[n,...r.mergeErrorPath]};i[n]=r.data}return{valid:!0,data:i}}if(Array.isArray(e)&&Array.isArray(t)){if(e.length!==t.length)return{valid:!1,mergeErrorPath:[]};let n=[];for(let r=0;r<e.length;r++){let i=e[r],a=t[r],o=Hr(i,a);if(!o.valid)return{valid:!1,mergeErrorPath:[r,...o.mergeErrorPath]};n.push(o.data)}return{valid:!0,data:n}}return{valid:!1,mergeErrorPath:[]}}function Ur(e,t,n){let r=new Map,i;for(let n of t.issues)if(n.code===`unrecognized_keys`){i??=n;for(let e of n.keys)r.has(e)||r.set(e,{}),r.get(e).l=!0}else e.issues.push(n);for(let t of n.issues)if(t.code===`unrecognized_keys`)for(let e of t.keys)r.has(e)||r.set(e,{}),r.get(e).r=!0;else e.issues.push(t);let a=[...r].filter(([,e])=>e.l&&e.r).map(([e])=>e);if(a.length&&i&&e.issues.push({...i,keys:a}),z(e))return e;let o=Hr(t.value,n.value);if(!o.valid)throw Error(`Unmergable intersection. Error path: ${JSON.stringify(o.mergeErrorPath)}`);return e.value=o.data,e}const Wr=k(`$ZodEnum`,(e,t)=>{U.init(e,t);let n=Et(t.entries),r=new Set(n);e._zod.values=r,e._zod.pattern=RegExp(`^(${n.filter(e=>Rt.has(typeof e)).map(e=>typeof e==`string`?I(e):e.toString()).join(`|`)})$`),e._zod.parse=(t,i)=>{let a=t.value;return r.has(a)||t.issues.push({code:`invalid_value`,values:n,input:a,inst:e}),t}}),Gr=k(`$ZodLiteral`,(e,t)=>{if(U.init(e,t),t.values.length===0)throw Error(`Cannot create literal schema with no valid values`);let n=new Set(t.values);e._zod.values=n,e._zod.pattern=RegExp(`^(${t.values.map(e=>typeof e==`string`?I(e):e?I(e.toString()):String(e)).join(`|`)})$`),e._zod.parse=(r,i)=>{let a=r.value;return n.has(a)||r.issues.push({code:`invalid_value`,values:t.values,input:a,inst:e}),r}}),Kr=k(`$ZodTransform`,(e,t)=>{U.init(e,t),e._zod.parse=(n,r)=>{if(r.direction===`backward`)throw new wt(e.constructor.name);let i=t.transform(n.value,n);if(r.async)return(i instanceof Promise?i:Promise.resolve(i)).then(e=>(n.value=e,n));if(i instanceof Promise)throw new A;return n.value=i,n}});function qr(e,t){return e.issues.length&&t===void 0?{issues:[],value:void 0}:e}const Jr=k(`$ZodOptional`,(e,t)=>{U.init(e,t),e._zod.optin=`optional`,e._zod.optout=`optional`,M(e._zod,`values`,()=>t.innerType._zod.values?new Set([...t.innerType._zod.values,void 0]):void 0),M(e._zod,`pattern`,()=>{let e=t.innerType._zod.pattern;return e?RegExp(`^(${At(e.source)})?$`):void 0}),e._zod.parse=(e,n)=>{if(t.innerType._zod.optin===`optional`){let r=t.innerType._zod.run(e,n);return r instanceof Promise?r.then(t=>qr(t,e.value)):qr(r,e.value)}return e.value===void 0?e:t.innerType._zod.run(e,n)}}),Yr=k(`$ZodExactOptional`,(e,t)=>{Jr.init(e,t),M(e._zod,`values`,()=>t.innerType._zod.values),M(e._zod,`pattern`,()=>t.innerType._zod.pattern),e._zod.parse=(e,n)=>t.innerType._zod.run(e,n)}),Xr=k(`$ZodNullable`,(e,t)=>{U.init(e,t),M(e._zod,`optin`,()=>t.innerType._zod.optin),M(e._zod,`optout`,()=>t.innerType._zod.optout),M(e._zod,`pattern`,()=>{let e=t.innerType._zod.pattern;return e?RegExp(`^(${At(e.source)}|null)$`):void 0}),M(e._zod,`values`,()=>t.innerType._zod.values?new Set([...t.innerType._zod.values,null]):void 0),e._zod.parse=(e,n)=>e.value===null?e:t.innerType._zod.run(e,n)}),Zr=k(`$ZodDefault`,(e,t)=>{U.init(e,t),e._zod.optin=`optional`,M(e._zod,`values`,()=>t.innerType._zod.values),e._zod.parse=(e,n)=>{if(n.direction===`backward`)return t.innerType._zod.run(e,n);if(e.value===void 0)return e.value=t.defaultValue,e;let r=t.innerType._zod.run(e,n);return r instanceof Promise?r.then(e=>Qr(e,t)):Qr(r,t)}});function Qr(e,t){return e.value===void 0&&(e.value=t.defaultValue),e}const $r=k(`$ZodPrefault`,(e,t)=>{U.init(e,t),e._zod.optin=`optional`,M(e._zod,`values`,()=>t.innerType._zod.values),e._zod.parse=(e,n)=>(n.direction===`backward`||e.value===void 0&&(e.value=t.defaultValue),t.innerType._zod.run(e,n))}),ei=k(`$ZodNonOptional`,(e,t)=>{U.init(e,t),M(e._zod,`values`,()=>{let e=t.innerType._zod.values;return e?new Set([...e].filter(e=>e!==void 0)):void 0}),e._zod.parse=(n,r)=>{let i=t.innerType._zod.run(n,r);return i instanceof Promise?i.then(t=>ti(t,e)):ti(i,e)}});function ti(e,t){return!e.issues.length&&e.value===void 0&&e.issues.push({code:`invalid_type`,expected:`nonoptional`,input:e.value,inst:t}),e}const ni=k(`$ZodCatch`,(e,t)=>{U.init(e,t),M(e._zod,`optin`,()=>t.innerType._zod.optin),M(e._zod,`optout`,()=>t.innerType._zod.optout),M(e._zod,`values`,()=>t.innerType._zod.values),e._zod.parse=(e,n)=>{if(n.direction===`backward`)return t.innerType._zod.run(e,n);let r=t.innerType._zod.run(e,n);return r instanceof Promise?r.then(r=>(e.value=r.value,r.issues.length&&(e.value=t.catchValue({...e,error:{issues:r.issues.map(e=>B(e,n,j()))},input:e.value}),e.issues=[]),e)):(e.value=r.value,r.issues.length&&(e.value=t.catchValue({...e,error:{issues:r.issues.map(e=>B(e,n,j()))},input:e.value}),e.issues=[]),e)}}),ri=k(`$ZodPipe`,(e,t)=>{U.init(e,t),M(e._zod,`values`,()=>t.in._zod.values),M(e._zod,`optin`,()=>t.in._zod.optin),M(e._zod,`optout`,()=>t.out._zod.optout),M(e._zod,`propValues`,()=>t.in._zod.propValues),e._zod.parse=(e,n)=>{if(n.direction===`backward`){let r=t.out._zod.run(e,n);return r instanceof Promise?r.then(e=>ii(e,t.in,n)):ii(r,t.in,n)}let r=t.in._zod.run(e,n);return r instanceof Promise?r.then(e=>ii(e,t.out,n)):ii(r,t.out,n)}});function ii(e,t,n){return e.issues.length?(e.aborted=!0,e):t._zod.run({value:e.value,issues:e.issues},n)}const ai=k(`$ZodReadonly`,(e,t)=>{U.init(e,t),M(e._zod,`propValues`,()=>t.innerType._zod.propValues),M(e._zod,`values`,()=>t.innerType._zod.values),M(e._zod,`optin`,()=>t.innerType?._zod?.optin),M(e._zod,`optout`,()=>t.innerType?._zod?.optout),e._zod.parse=(e,n)=>{if(n.direction===`backward`)return t.innerType._zod.run(e,n);let r=t.innerType._zod.run(e,n);return r instanceof Promise?r.then(oi):oi(r)}});function oi(e){return e.value=Object.freeze(e.value),e}const si=k(`$ZodCustom`,(e,t)=>{H.init(e,t),U.init(e,t),e._zod.parse=(e,t)=>e,e._zod.check=n=>{let r=n.value,i=t.fn(r);if(i instanceof Promise)return i.then(t=>ci(t,n,r,e));ci(i,n,r,e)}});function ci(e,t,n,r){if(!e){let e={code:`custom`,input:n,inst:r,path:[...r._zod.def.path??[]],continue:!r._zod.def.abort};r._zod.def.params&&(e.params=r._zod.def.params),t.issues.push(V(e))}}var li,ui=class{constructor(){this._map=new WeakMap,this._idmap=new Map}add(e,...t){let n=t[0];return this._map.set(e,n),n&&typeof n==`object`&&`id`in n&&this._idmap.set(n.id,e),this}clear(){return this._map=new WeakMap,this._idmap=new Map,this}remove(e){let t=this._map.get(e);return t&&typeof t==`object`&&`id`in t&&this._idmap.delete(t.id),this._map.delete(e),this}get(e){let t=e._zod.parent;if(t){let n={...this.get(t)??{}};delete n.id;let r={...n,...this._map.get(e)};return Object.keys(r).length?r:void 0}return this._map.get(e)}has(e){return this._map.has(e)}};function di(){return new ui}(li=globalThis).__zod_globalRegistry??(li.__zod_globalRegistry=di());const G=globalThis.__zod_globalRegistry;function fi(e,t){return new e({type:`string`,...R(t)})}function pi(e,t){return new e({type:`string`,format:`email`,check:`string_format`,abort:!1,...R(t)})}function mi(e,t){return new e({type:`string`,format:`guid`,check:`string_format`,abort:!1,...R(t)})}function hi(e,t){return new e({type:`string`,format:`uuid`,check:`string_format`,abort:!1,...R(t)})}function gi(e,t){return new e({type:`string`,format:`uuid`,check:`string_format`,abort:!1,version:`v4`,...R(t)})}function _i(e,t){return new e({type:`string`,format:`uuid`,check:`string_format`,abort:!1,version:`v6`,...R(t)})}function vi(e,t){return new e({type:`string`,format:`uuid`,check:`string_format`,abort:!1,version:`v7`,...R(t)})}function yi(e,t){return new e({type:`string`,format:`url`,check:`string_format`,abort:!1,...R(t)})}function bi(e,t){return new e({type:`string`,format:`emoji`,check:`string_format`,abort:!1,...R(t)})}function xi(e,t){return new e({type:`string`,format:`nanoid`,check:`string_format`,abort:!1,...R(t)})}function Si(e,t){return new e({type:`string`,format:`cuid`,check:`string_format`,abort:!1,...R(t)})}function Ci(e,t){return new e({type:`string`,format:`cuid2`,check:`string_format`,abort:!1,...R(t)})}function wi(e,t){return new e({type:`string`,format:`ulid`,check:`string_format`,abort:!1,...R(t)})}function Ti(e,t){return new e({type:`string`,format:`xid`,check:`string_format`,abort:!1,...R(t)})}function Ei(e,t){return new e({type:`string`,format:`ksuid`,check:`string_format`,abort:!1,...R(t)})}function Di(e,t){return new e({type:`string`,format:`ipv4`,check:`string_format`,abort:!1,...R(t)})}function Oi(e,t){return new e({type:`string`,format:`ipv6`,check:`string_format`,abort:!1,...R(t)})}function ki(e,t){return new e({type:`string`,format:`cidrv4`,check:`string_format`,abort:!1,...R(t)})}function Ai(e,t){return new e({type:`string`,format:`cidrv6`,check:`string_format`,abort:!1,...R(t)})}function ji(e,t){return new e({type:`string`,format:`base64`,check:`string_format`,abort:!1,...R(t)})}function Mi(e,t){return new e({type:`string`,format:`base64url`,check:`string_format`,abort:!1,...R(t)})}function Ni(e,t){return new e({type:`string`,format:`e164`,check:`string_format`,abort:!1,...R(t)})}function Pi(e,t){return new e({type:`string`,format:`jwt`,check:`string_format`,abort:!1,...R(t)})}function Fi(e,t){return new e({type:`string`,format:`datetime`,check:`string_format`,offset:!1,local:!1,precision:null,...R(t)})}function Ii(e,t){return new e({type:`string`,format:`date`,check:`string_format`,...R(t)})}function Li(e,t){return new e({type:`string`,format:`time`,check:`string_format`,precision:null,...R(t)})}function Ri(e,t){return new e({type:`string`,format:`duration`,check:`string_format`,...R(t)})}function zi(e,t){return new e({type:`boolean`,...R(t)})}function Bi(e){return new e({type:`unknown`})}function Vi(e,t){return new e({type:`never`,...R(t)})}function Hi(e,t){return new Un({check:`max_length`,...R(t),maximum:e})}function Ui(e,t){return new Wn({check:`min_length`,...R(t),minimum:e})}function Wi(e,t){return new Gn({check:`length_equals`,...R(t),length:e})}function Gi(e,t){return new qn({check:`string_format`,format:`regex`,...R(t),pattern:e})}function Ki(e){return new Jn({check:`string_format`,format:`lowercase`,...R(e)})}function qi(e){return new Yn({check:`string_format`,format:`uppercase`,...R(e)})}function Ji(e,t){return new Xn({check:`string_format`,format:`includes`,...R(t),includes:e})}function Yi(e,t){return new Zn({check:`string_format`,format:`starts_with`,...R(t),prefix:e})}function Xi(e,t){return new Qn({check:`string_format`,format:`ends_with`,...R(t),suffix:e})}function K(e){return new $n({check:`overwrite`,tx:e})}function Zi(e){return K(t=>t.normalize(e))}function Qi(){return K(e=>e.trim())}function $i(){return K(e=>e.toLowerCase())}function ea(){return K(e=>e.toUpperCase())}function ta(){return K(e=>Nt(e))}function na(e,t,n){return new e({type:`array`,element:t,...R(n)})}function ra(e,t,n){return new e({type:`custom`,check:`custom`,fn:t,...R(n)})}function ia(e){let t=aa(n=>(n.addIssue=e=>{if(typeof e==`string`)n.issues.push(V(e,n.value,t._zod.def));else{let r=e;r.fatal&&(r.continue=!1),r.code??=`custom`,r.input??=n.value,r.inst??=t,r.continue??=!t._zod.def.abort,n.issues.push(V(r))}},e(n.value,n)));return t}function aa(e,t){let n=new H({check:`custom`,...R(t)});return n._zod.check=e,n}function oa(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??G,target:t,unrepresentable:e?.unrepresentable??`throw`,override:e?.override??(()=>{}),io:e?.io??`output`,counter:0,seen:new Map,cycles:e?.cycles??`ref`,reused:e?.reused??`inline`,external:e?.external??void 0}}function q(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);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,q(a,t,r),t.seen.get(a).isParent=!0)}let c=t.metadataRegistry.get(e);return c&&Object.assign(o.schema,c),t.io===`input`&&J(e)&&(delete o.schema.examples,delete o.schema.default),t.io===`input`&&o.schema._prefault&&((r=o.schema).default??(r.default=o.schema._prefault)),delete o.schema._prefault,t.seen.get(e).schema}function sa(e,t){let n=e.seen.get(t);if(!n)throw Error(`Unprocessed schema. This is a bug in Zod.`);let r=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}/${a}`}}if(t[1]===n)return{ref:`#`};let i=`#/${r}/`,a=t[1].schema.id??`__schema${e.counter++}`;return{defId:a,ref:i+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>
41
41
 
42
- 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);continue}if(e.external){let r=e.external.registry.get(n[0])?.id;if(t!==n[0]&&r){a(n);continue}}if(e.metadataRegistry.get(n[0])?.id){a(n);continue}if(r.cycle){a(n);continue}if(r.count>1&&e.reused===`ref`){a(n);continue}}}function ca(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)):Object.assign(i,s),Object.assign(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??[]})};for(let t of[...e.seen.entries()].reverse())r(t[0]);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)}Object.assign(i,n.def??n.schema);let a=e.external?.defs??{};for(let t of e.seen.entries()){let e=t[1];e.def&&e.defId&&(a[e.defId]=e.def)}e.external||Object.keys(a).length>0&&(e.target===`draft-2020-12`?i.$defs=a:i.definitions=a);try{let n=JSON.parse(JSON.stringify(i));return Object.defineProperty(n,`~standard`,{value:{...t[`~standard`],jsonSchema:{input:ua(t,`input`,e.processors),output:ua(t,`output`,e.processors)}},enumerable:!1,writable:!1}),n}catch{throw Error(`Error converting schema to JSON.`)}}function J(e,t){let n=t??{seen: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 J(r.element,n);if(r.type===`set`)return J(r.valueType,n);if(r.type===`lazy`)return J(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`)return J(r.innerType,n);if(r.type===`intersection`)return J(r.left,n)||J(r.right,n);if(r.type===`record`||r.type===`map`)return J(r.keyType,n)||J(r.valueType,n);if(r.type===`pipe`)return J(r.in,n)||J(r.out,n);if(r.type===`object`){for(let e in r.shape)if(J(r.shape[e],n))return!0;return!1}if(r.type===`union`){for(let e of r.options)if(J(e,n))return!0;return!1}if(r.type===`tuple`){for(let e of r.items)if(J(e,n))return!0;return!!(r.rest&&J(r.rest,n))}return!1}const la=(e,t={})=>n=>{let r=oa({...n,processors:t});return q(e,r),sa(r,e),ca(r,e)},ua=(e,t,n={})=>r=>{let{libraryOptions:i,target:a}=r??{},o=oa({...i??{},target:a,io:t,processors:n});return q(e,o),sa(o,e),ca(o,e)},da={guid:`uuid`,url:`uri`,datetime:`date-time`,json_string:`json-string`,regex:``},fa=(e,t,n,r)=>{let i=n;i.type=`string`;let{minimum:a,maximum:o,format:s,patterns:c,contentEncoding:l}=e._zod.bag;if(typeof a==`number`&&(i.minLength=a),typeof o==`number`&&(i.maxLength=o),s&&(i.format=da[s]??s,i.format===``&&delete i.format,s===`time`&&delete i.format),l&&(i.contentEncoding=l),c&&c.size>0){let e=[...c];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}))])}},pa=(e,t,n,r)=>{n.type=`boolean`},ma=(e,t,n,r)=>{n.not={}},ha=(e,t,n,r)=>{let i=e._zod.def,a=Tt(i.entries);a.every(e=>typeof e==`number`)&&(n.type=`number`),a.every(e=>typeof e==`string`)&&(n.type=`string`),n.enum=a},ga=(e,t,n,r)=>{let i=e._zod.def,a=[];for(let e of i.values)if(e===void 0){if(t.unrepresentable===`throw`)throw Error("Literal `undefined` cannot be represented in JSON Schema")}else if(typeof e==`bigint`){if(t.unrepresentable===`throw`)throw Error(`BigInt literals cannot be represented in JSON Schema`);a.push(Number(e))}else a.push(e);if(a.length!==0)if(a.length===1){let e=a[0];n.type=e===null?`null`:typeof e,t.target===`draft-04`||t.target===`openapi-3.0`?n.enum=[e]:n.const=e}else a.every(e=>typeof e==`number`)&&(n.type=`number`),a.every(e=>typeof e==`string`)&&(n.type=`string`),a.every(e=>typeof e==`boolean`)&&(n.type=`boolean`),a.every(e=>e===null)&&(n.type=`null`),n.enum=a},_a=(e,t,n,r)=>{if(t.unrepresentable===`throw`)throw Error(`Custom types cannot be represented in JSON Schema`)},va=(e,t,n,r)=>{if(t.unrepresentable===`throw`)throw Error(`Transforms cannot be represented in JSON Schema`)},ya=(e,t,n,r)=>{let i=n,a=e._zod.def,{minimum:o,maximum:s}=e._zod.bag;typeof o==`number`&&(i.minItems=o),typeof s==`number`&&(i.maxItems=s),i.type=`array`,i.items=q(a.element,t,{...r,path:[...r.path,`items`]})},ba=(e,t,n,r)=>{let i=n,a=e._zod.def;i.type=`object`,i.properties={};let o=a.shape;for(let e in o)i.properties[e]=q(o[e],t,{...r,path:[...r.path,`properties`,e]});let s=new Set(Object.keys(o)),c=new Set([...s].filter(e=>{let n=a.shape[e]._zod;return t.io===`input`?n.optin===void 0:n.optout===void 0}));c.size>0&&(i.required=Array.from(c)),a.catchall?._zod.def.type===`never`?i.additionalProperties=!1:a.catchall?a.catchall&&(i.additionalProperties=q(a.catchall,t,{...r,path:[...r.path,`additionalProperties`]})):t.io===`output`&&(i.additionalProperties=!1)},xa=(e,t,n,r)=>{let i=e._zod.def,a=i.inclusive===!1,o=i.options.map((e,n)=>q(e,t,{...r,path:[...r.path,a?`oneOf`:`anyOf`,n]}));a?n.oneOf=o:n.anyOf=o},Sa=(e,t,n,r)=>{let i=e._zod.def,a=q(i.left,t,{...r,path:[...r.path,`allOf`,0]}),o=q(i.right,t,{...r,path:[...r.path,`allOf`,1]}),s=e=>`allOf`in e&&Object.keys(e).length===1;n.allOf=[...s(a)?a.allOf:[a],...s(o)?o.allOf:[o]]},Ca=(e,t,n,r)=>{let i=e._zod.def,a=q(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`}]},wa=(e,t,n,r)=>{let i=e._zod.def;q(i.innerType,t,r);let a=t.seen.get(e);a.ref=i.innerType},Ta=(e,t,n,r)=>{let i=e._zod.def;q(i.innerType,t,r);let a=t.seen.get(e);a.ref=i.innerType,n.default=JSON.parse(JSON.stringify(i.defaultValue))},Ea=(e,t,n,r)=>{let i=e._zod.def;q(i.innerType,t,r);let a=t.seen.get(e);a.ref=i.innerType,t.io===`input`&&(n._prefault=JSON.parse(JSON.stringify(i.defaultValue)))},Da=(e,t,n,r)=>{let i=e._zod.def;q(i.innerType,t,r);let a=t.seen.get(e);a.ref=i.innerType;let o;try{o=i.catchValue(void 0)}catch{throw Error(`Dynamic catch values are not supported in JSON Schema`)}n.default=o},Oa=(e,t,n,r)=>{let i=e._zod.def,a=t.io===`input`?i.in._zod.def.type===`transform`?i.out:i.in:i.out;q(a,t,r);let o=t.seen.get(e);o.ref=a},ka=(e,t,n,r)=>{let i=e._zod.def;q(i.innerType,t,r);let a=t.seen.get(e);a.ref=i.innerType,n.readOnly=!0},Aa=(e,t,n,r)=>{let i=e._zod.def;q(i.innerType,t,r);let a=t.seen.get(e);a.ref=i.innerType},ja=A(`ZodISODateTime`,(e,t)=>{pr.init(e,t),Q.init(e,t)});function Ma(e){return Fi(ja,e)}const Na=A(`ZodISODate`,(e,t)=>{mr.init(e,t),Q.init(e,t)});function Pa(e){return Ii(Na,e)}const Fa=A(`ZodISOTime`,(e,t)=>{hr.init(e,t),Q.init(e,t)});function Ia(e){return Li(Fa,e)}const La=A(`ZodISODuration`,(e,t)=>{gr.init(e,t),Q.init(e,t)});function Ra(e){return Ri(La,e)}const za=(e,t)=>{Xt.init(e,t),e.name=`ZodError`,Object.defineProperties(e,{format:{value:t=>$t(e,t)},flatten:{value:t=>Qt(e,t)},addIssue:{value:t=>{e.issues.push(t),e.message=JSON.stringify(e.issues,Et,2)}},addIssues:{value:t=>{e.issues.push(...t),e.message=JSON.stringify(e.issues,Et,2)}},isEmpty:{get(){return e.issues.length===0}}})};A(`ZodError`,za);const Y=A(`ZodError`,za,{Parent:Error}),Ba=en(Y),Va=tn(Y),Ha=nn(Y),Ua=an(Y),Wa=sn(Y),Ga=cn(Y),Ka=ln(Y),qa=un(Y),Ja=dn(Y),Ya=fn(Y),Xa=pn(Y),Za=mn(Y),X=A(`ZodType`,(e,t)=>(W.init(e,t),Object.assign(e[`~standard`],{jsonSchema:{input:ua(e,`input`),output:ua(e,`output`)}}),e.toJSONSchema=la(e,{}),e.def=t,e.type=t.type,Object.defineProperty(e,`_def`,{value:t}),e.check=(...n)=>e.clone(F(t,{checks:[...t.checks??[],...n.map(e=>typeof e==`function`?{_zod:{check:e,def:{check:`custom`},onattach:[]}}:e)]}),{parent:!0}),e.with=e.check,e.clone=(t,n)=>R(e,t,n),e.brand=()=>e,e.register=((t,n)=>(t.add(e,n),e)),e.parse=(t,n)=>Ba(e,t,n,{callee:e.parse}),e.safeParse=(t,n)=>Ha(e,t,n),e.parseAsync=async(t,n)=>Va(e,t,n,{callee:e.parseAsync}),e.safeParseAsync=async(t,n)=>Ua(e,t,n),e.spa=e.safeParseAsync,e.encode=(t,n)=>Wa(e,t,n),e.decode=(t,n)=>Ga(e,t,n),e.encodeAsync=async(t,n)=>Ka(e,t,n),e.decodeAsync=async(t,n)=>qa(e,t,n),e.safeEncode=(t,n)=>Ja(e,t,n),e.safeDecode=(t,n)=>Ya(e,t,n),e.safeEncodeAsync=async(t,n)=>Xa(e,t,n),e.safeDecodeAsync=async(t,n)=>Za(e,t,n),e.refine=(t,n)=>e.check(as(t,n)),e.superRefine=t=>e.check(os(t)),e.overwrite=t=>e.check(K(t)),e.optional=()=>Vo(e),e.exactOptional=()=>Uo(e),e.nullable=()=>Go(e),e.nullish=()=>Vo(Go(e)),e.nonoptional=t=>Zo(e,t),e.array=()=>Do(e),e.or=t=>jo([e,t]),e.and=t=>No(e,t),e.transform=t=>ts(e,zo(t)),e.default=t=>qo(e,t),e.prefault=t=>Yo(e,t),e.catch=t=>$o(e,t),e.pipe=t=>ts(e,t),e.readonly=()=>rs(e),e.describe=t=>{let n=e.clone();return di.add(n,{description:t}),n},Object.defineProperty(e,`description`,{get(){return di.get(e)?.description},configurable:!0}),e.meta=(...t)=>{if(t.length===0)return di.get(e);let n=e.clone();return di.add(n,t[0]),n},e.isOptional=()=>e.safeParse(void 0).success,e.isNullable=()=>e.safeParse(null).success,e.apply=t=>t(e),e)),Qa=A(`_ZodString`,(e,t)=>{tr.init(e,t),X.init(e,t),e._zod.processJSONSchema=(t,n,r)=>fa(e,t,n,r);let n=e._zod.bag;e.format=n.format??null,e.minLength=n.minimum??null,e.maxLength=n.maximum??null,e.regex=(...t)=>e.check(Gi(...t)),e.includes=(...t)=>e.check(Ji(...t)),e.startsWith=(...t)=>e.check(Yi(...t)),e.endsWith=(...t)=>e.check(Xi(...t)),e.min=(...t)=>e.check(Ui(...t)),e.max=(...t)=>e.check(Hi(...t)),e.length=(...t)=>e.check(Wi(...t)),e.nonempty=(...t)=>e.check(Ui(1,...t)),e.lowercase=t=>e.check(Ki(t)),e.uppercase=t=>e.check(qi(t)),e.trim=()=>e.check(Qi()),e.normalize=(...t)=>e.check(Zi(...t)),e.toLowerCase=()=>e.check($i()),e.toUpperCase=()=>e.check(ea()),e.slugify=()=>e.check(ta())}),$a=A(`ZodString`,(e,t)=>{tr.init(e,t),Qa.init(e,t),e.email=t=>e.check(pi(eo,t)),e.url=t=>e.check(yi(ro,t)),e.jwt=t=>e.check(Pi(yo,t)),e.emoji=t=>e.check(bi(io,t)),e.guid=t=>e.check(mi(to,t)),e.uuid=t=>e.check(hi(no,t)),e.uuidv4=t=>e.check(gi(no,t)),e.uuidv6=t=>e.check(_i(no,t)),e.uuidv7=t=>e.check(vi(no,t)),e.nanoid=t=>e.check(xi(ao,t)),e.guid=t=>e.check(mi(to,t)),e.cuid=t=>e.check(Si(oo,t)),e.cuid2=t=>e.check(Ci(so,t)),e.ulid=t=>e.check(wi(co,t)),e.base64=t=>e.check(ji(go,t)),e.base64url=t=>e.check(Mi(_o,t)),e.xid=t=>e.check(Ti(lo,t)),e.ksuid=t=>e.check(Ei(uo,t)),e.ipv4=t=>e.check(Di(fo,t)),e.ipv6=t=>e.check(Oi(po,t)),e.cidrv4=t=>e.check(ki(mo,t)),e.cidrv6=t=>e.check(Ai(ho,t)),e.e164=t=>e.check(Ni(vo,t)),e.datetime=t=>e.check(Ma(t)),e.date=t=>e.check(Pa(t)),e.time=t=>e.check(Ia(t)),e.duration=t=>e.check(Ra(t))});function Z(e){return fi($a,e)}const Q=A(`ZodStringFormat`,(e,t)=>{G.init(e,t),Qa.init(e,t)}),eo=A(`ZodEmail`,(e,t)=>{ir.init(e,t),Q.init(e,t)}),to=A(`ZodGUID`,(e,t)=>{nr.init(e,t),Q.init(e,t)}),no=A(`ZodUUID`,(e,t)=>{rr.init(e,t),Q.init(e,t)}),ro=A(`ZodURL`,(e,t)=>{ar.init(e,t),Q.init(e,t)}),io=A(`ZodEmoji`,(e,t)=>{or.init(e,t),Q.init(e,t)}),ao=A(`ZodNanoID`,(e,t)=>{sr.init(e,t),Q.init(e,t)}),oo=A(`ZodCUID`,(e,t)=>{cr.init(e,t),Q.init(e,t)}),so=A(`ZodCUID2`,(e,t)=>{lr.init(e,t),Q.init(e,t)}),co=A(`ZodULID`,(e,t)=>{ur.init(e,t),Q.init(e,t)}),lo=A(`ZodXID`,(e,t)=>{dr.init(e,t),Q.init(e,t)}),uo=A(`ZodKSUID`,(e,t)=>{fr.init(e,t),Q.init(e,t)}),fo=A(`ZodIPv4`,(e,t)=>{_r.init(e,t),Q.init(e,t)}),po=A(`ZodIPv6`,(e,t)=>{vr.init(e,t),Q.init(e,t)}),mo=A(`ZodCIDRv4`,(e,t)=>{yr.init(e,t),Q.init(e,t)}),ho=A(`ZodCIDRv6`,(e,t)=>{br.init(e,t),Q.init(e,t)}),go=A(`ZodBase64`,(e,t)=>{Sr.init(e,t),Q.init(e,t)}),_o=A(`ZodBase64URL`,(e,t)=>{wr.init(e,t),Q.init(e,t)}),vo=A(`ZodE164`,(e,t)=>{Tr.init(e,t),Q.init(e,t)}),yo=A(`ZodJWT`,(e,t)=>{Dr.init(e,t),Q.init(e,t)}),bo=A(`ZodBoolean`,(e,t)=>{Or.init(e,t),X.init(e,t),e._zod.processJSONSchema=(t,n,r)=>pa(e,t,n,r)});function xo(e){return zi(bo,e)}const So=A(`ZodUnknown`,(e,t)=>{kr.init(e,t),X.init(e,t),e._zod.processJSONSchema=(e,t,n)=>void 0});function Co(){return Bi(So)}const wo=A(`ZodNever`,(e,t)=>{Ar.init(e,t),X.init(e,t),e._zod.processJSONSchema=(t,n,r)=>ma(e,t,n,r)});function To(e){return Vi(wo,e)}const Eo=A(`ZodArray`,(e,t)=>{Mr.init(e,t),X.init(e,t),e._zod.processJSONSchema=(t,n,r)=>ya(e,t,n,r),e.element=t.element,e.min=(t,n)=>e.check(Ui(t,n)),e.nonempty=t=>e.check(Ui(1,t)),e.max=(t,n)=>e.check(Hi(t,n)),e.length=(t,n)=>e.check(Wi(t,n)),e.unwrap=()=>e.element});function Do(e,t){return na(Eo,e,t)}const Oo=A(`ZodObject`,(e,t)=>{Lr.init(e,t),X.init(e,t),e._zod.processJSONSchema=(t,n,r)=>ba(e,t,n,r),N(e,`shape`,()=>t.shape),e.keyof=()=>Fo(Object.keys(e._zod.def.shape)),e.catchall=t=>e.clone({...e._zod.def,catchall:t}),e.passthrough=()=>e.clone({...e._zod.def,catchall:Co()}),e.loose=()=>e.clone({...e._zod.def,catchall:Co()}),e.strict=()=>e.clone({...e._zod.def,catchall:To()}),e.strip=()=>e.clone({...e._zod.def,catchall:void 0}),e.extend=t=>Vt(e,t),e.safeExtend=t=>Ht(e,t),e.merge=t=>Ut(e,t),e.pick=t=>zt(e,t),e.omit=t=>Bt(e,t),e.partial=(...t)=>Wt(Bo,e,t[0]),e.required=(...t)=>Gt(Xo,e,t[0])});function ko(e,t){return new Oo({type:`object`,shape:e??{},...z(t)})}const Ao=A(`ZodUnion`,(e,t)=>{zr.init(e,t),X.init(e,t),e._zod.processJSONSchema=(t,n,r)=>xa(e,t,n,r),e.options=t.options});function jo(e,t){return new Ao({type:`union`,options:e,...z(t)})}const Mo=A(`ZodIntersection`,(e,t)=>{Br.init(e,t),X.init(e,t),e._zod.processJSONSchema=(t,n,r)=>Sa(e,t,n,r)});function No(e,t){return new Mo({type:`intersection`,left:e,right:t})}const Po=A(`ZodEnum`,(e,t)=>{Ur.init(e,t),X.init(e,t),e._zod.processJSONSchema=(t,n,r)=>ha(e,t,n,r),e.enum=t.entries,e.options=Object.values(t.entries);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 Po({...t,checks:[],...z(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 Po({...t,checks:[],...z(r),entries:i})}});function Fo(e,t){return new Po({type:`enum`,entries:Array.isArray(e)?Object.fromEntries(e.map(e=>[e,e])):e,...z(t)})}const Io=A(`ZodLiteral`,(e,t)=>{Wr.init(e,t),X.init(e,t),e._zod.processJSONSchema=(t,n,r)=>ga(e,t,n,r),e.values=new Set(t.values),Object.defineProperty(e,`value`,{get(){if(t.values.length>1)throw Error("This schema contains multiple valid literal values. Use `.values` instead.");return t.values[0]}})});function Lo(e,t){return new Io({type:`literal`,values:Array.isArray(e)?e:[e],...z(t)})}const Ro=A(`ZodTransform`,(e,t)=>{Gr.init(e,t),X.init(e,t),e._zod.processJSONSchema=(t,n,r)=>va(e,t,n,r),e._zod.parse=(n,r)=>{if(r.direction===`backward`)throw new Ct(e.constructor.name);n.addIssue=r=>{if(typeof r==`string`)n.issues.push(H(r,n.value,t));else{let t=r;t.fatal&&(t.continue=!1),t.code??=`custom`,t.input??=n.value,t.inst??=e,n.issues.push(H(t))}};let i=t.transform(n.value,n);return i instanceof Promise?i.then(e=>(n.value=e,n)):(n.value=i,n)}});function zo(e){return new Ro({type:`transform`,transform:e})}const Bo=A(`ZodOptional`,(e,t)=>{qr.init(e,t),X.init(e,t),e._zod.processJSONSchema=(t,n,r)=>Aa(e,t,n,r),e.unwrap=()=>e._zod.def.innerType});function Vo(e){return new Bo({type:`optional`,innerType:e})}const Ho=A(`ZodExactOptional`,(e,t)=>{Jr.init(e,t),X.init(e,t),e._zod.processJSONSchema=(t,n,r)=>Aa(e,t,n,r),e.unwrap=()=>e._zod.def.innerType});function Uo(e){return new Ho({type:`optional`,innerType:e})}const Wo=A(`ZodNullable`,(e,t)=>{Yr.init(e,t),X.init(e,t),e._zod.processJSONSchema=(t,n,r)=>Ca(e,t,n,r),e.unwrap=()=>e._zod.def.innerType});function Go(e){return new Wo({type:`nullable`,innerType:e})}const Ko=A(`ZodDefault`,(e,t)=>{Xr.init(e,t),X.init(e,t),e._zod.processJSONSchema=(t,n,r)=>Ta(e,t,n,r),e.unwrap=()=>e._zod.def.innerType,e.removeDefault=e.unwrap});function qo(e,t){return new Ko({type:`default`,innerType:e,get defaultValue(){return typeof t==`function`?t():It(t)}})}const Jo=A(`ZodPrefault`,(e,t)=>{Qr.init(e,t),X.init(e,t),e._zod.processJSONSchema=(t,n,r)=>Ea(e,t,n,r),e.unwrap=()=>e._zod.def.innerType});function Yo(e,t){return new Jo({type:`prefault`,innerType:e,get defaultValue(){return typeof t==`function`?t():It(t)}})}const Xo=A(`ZodNonOptional`,(e,t)=>{$r.init(e,t),X.init(e,t),e._zod.processJSONSchema=(t,n,r)=>wa(e,t,n,r),e.unwrap=()=>e._zod.def.innerType});function Zo(e,t){return new Xo({type:`nonoptional`,innerType:e,...z(t)})}const Qo=A(`ZodCatch`,(e,t)=>{ti.init(e,t),X.init(e,t),e._zod.processJSONSchema=(t,n,r)=>Da(e,t,n,r),e.unwrap=()=>e._zod.def.innerType,e.removeCatch=e.unwrap});function $o(e,t){return new Qo({type:`catch`,innerType:e,catchValue:typeof t==`function`?t:()=>t})}const es=A(`ZodPipe`,(e,t)=>{ni.init(e,t),X.init(e,t),e._zod.processJSONSchema=(t,n,r)=>Oa(e,t,n,r),e.in=t.in,e.out=t.out});function ts(e,t){return new es({type:`pipe`,in:e,out:t})}const ns=A(`ZodReadonly`,(e,t)=>{ii.init(e,t),X.init(e,t),e._zod.processJSONSchema=(t,n,r)=>ka(e,t,n,r),e.unwrap=()=>e._zod.def.innerType});function rs(e){return new ns({type:`readonly`,innerType:e})}const is=A(`ZodCustom`,(e,t)=>{oi.init(e,t),X.init(e,t),e._zod.processJSONSchema=(t,n,r)=>_a(e,t,n,r)});function as(e,t={}){return ra(is,e,t)}function os(e){return ia(e)}const ss=Fo([`plugin`,`skill`,`mcp`]),cs=Fo([`latest-tag`,`latest-release`]),ls=jo([xo(),ko({reason:Z().min(1),alternative:Z().optional()})]),us=ko({id:Z().min(1),type:ss,description:Z().min(1),source:Z().min(1),subPath:Z().optional(),capabilities:Do(Z()).optional(),keywords:Do(Z()).optional(),author:Z().optional(),homepage:Z().optional(),versionPolicy:cs.optional(),deprecated:ls.optional()}),ds=ko({version:Lo(1),name:Z().min(1),entries:Do(Co())});function $(e){let t=ds.parse(e),n=[],r=[];return t.entries.forEach((e,t)=>{let i=us.safeParse(e);i.success?n.push(i.data):r.push({index:t,reason:i.error.issues.map(e=>`${e.path.join(`.`)}: ${e.message}`).join(`; `)})}),{name:t.name,version:t.version,entries:n,rejected:r}}const fs=C(process.env.OTTO_REGISTRY_FETCH_TIMEOUT_MS,5e3),ps=C(process.env.OTTO_REGISTRY_CACHE_TTL_MS,36e5);function ms(e){return{name:`otto-official`,url:e,builtin:!0}}var hs=class{constructor(e){this.options=e}get registriesPath(){return g(this.options.configDir,`registries.json`)}get cacheDir(){return g(this.options.ottoHome,`registry-cache`)}listSources(){let e=this.readUserSources(),t=e.find(e=>e.name===this.options.officialSource.name);return[{...this.options.officialSource,disabled:t?.disabled},...e.filter(e=>e.name!==this.options.officialSource.name)]}addSource(e,t){if(e===this.options.officialSource.name)throw Error(`'${e}' 是内置官方源名,不可占用`);let n=this.readUserSources().filter(e=>e.name!==this.options.officialSource.name);if(n.some(t=>t.name===e))throw Error(`registry '${e}' 已存在`);n.push({name:e,url:t}),this.writeUserSources(n)}removeSource(e){if(e===this.options.officialSource.name)throw Error(`官方源不可移除(可 disable:本版本未提供,直接忽略其结果即可)`);let t=this.readUserSources();if(!t.some(t=>t.name===e))throw Error(`registry '${e}' 不存在`);this.writeUserSources(t.filter(t=>t.name!==e))}setSourceEnabled(e,t){if(e===this.options.officialSource.name){let n=this.readUserSources(),r=n.find(t=>t.name===e);r?(r.disabled=!t,this.writeUserSources(n)):this.writeUserSources([...n,{name:e,url:this.options.officialSource.url,disabled:!t}]);return}let n=this.readUserSources(),r=n.find(t=>t.name===e);if(!r)throw Error(`registry '${e}' 不存在`);r.disabled=!t,this.writeUserSources(n)}async loadAll(){let e=[],t=[];for(let n of this.listSources())if(!n.disabled)try{e.push(await this.loadOne(n))}catch(e){t.push(`registry '${n.name}' 加载失败:${e instanceof Error?e.message:String(e)}`)}return{registries:e,warnings:t}}async loadOne(e){if(!/^https?:\/\//.test(e.url)){let t=e.url.replace(/^file:/,``);return{...$(JSON.parse(a(t,`utf-8`))),sourceName:e.name,sourceUrl:e.url,stale:!1}}let t=this.readCache(e.name);if(t&&Date.now()-t.fetchedAt<ps)return{...$(t.raw),sourceName:e.name,sourceUrl:e.url,stale:!1};try{let t=await(this.options.fetchImpl??fetch)(e.url,{signal:AbortSignal.timeout(fs)});if(!t.ok)throw Error(`HTTP ${t.status}`);let n=await t.json(),r=$(n);return this.writeCache(e.name,n),{...r,sourceName:e.name,sourceUrl:e.url,stale:!1}}catch(n){if(t)return{...$(t.raw),sourceName:e.name,sourceUrl:e.url,stale:!0};throw n}}readUserSources(){try{if(!n(this.registriesPath))return[];let e=JSON.parse(a(this.registriesPath,`utf-8`));return Array.isArray(e.sources)?e.sources:[]}catch{return[]}}writeUserSources(e){if(S())return;r(this.options.configDir,{recursive:!0});let t={version:1,sources:e};f(this.registriesPath,JSON.stringify(t,null,2)+`
43
- `)}readCache(e){try{let t=g(this.cacheDir,`${gs(e)}.json`);return n(t)?JSON.parse(a(t,`utf-8`)):void 0}catch{return}}writeCache(e,t){if(!S())try{r(this.cacheDir,{recursive:!0});let n={fetchedAt:Date.now(),raw:t};f(g(this.cacheDir,`${gs(e)}.json`),JSON.stringify(n))}catch{}}};function gs(e){return e.replace(/[^\w.-]+/g,`_`)}export{at as InstallManager,hs as RegistryClient,ms as builtinOfficialSource,ge as checkArchiveBomb,bt as checkGitUpgrades,gt as checkUpgrades,w as cleanTempDir,me as createArchive,_e as createTempDir,ft as detectUninstallTarget,pe as extractArchive,pt as listInstalledItems,$ as parseRegistry,us as registryEntrySchema,ss as registryEntryTypeSchema,ds as registrySchema,T as sanitizeSourceUrl,ht as scanInstalledVersions,mt as uninstall,he as validateExtractedPaths};
42
+ 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);continue}if(e.external){let r=e.external.registry.get(n[0])?.id;if(t!==n[0]&&r){a(n);continue}}if(e.metadataRegistry.get(n[0])?.id){a(n);continue}if(r.cycle){a(n);continue}if(r.count>1&&e.reused===`ref`){a(n);continue}}}function ca(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)):Object.assign(i,s),Object.assign(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??[]})};for(let t of[...e.seen.entries()].reverse())r(t[0]);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)}Object.assign(i,n.def??n.schema);let a=e.external?.defs??{};for(let t of e.seen.entries()){let e=t[1];e.def&&e.defId&&(a[e.defId]=e.def)}e.external||Object.keys(a).length>0&&(e.target===`draft-2020-12`?i.$defs=a:i.definitions=a);try{let n=JSON.parse(JSON.stringify(i));return Object.defineProperty(n,`~standard`,{value:{...t[`~standard`],jsonSchema:{input:ua(t,`input`,e.processors),output:ua(t,`output`,e.processors)}},enumerable:!1,writable:!1}),n}catch{throw Error(`Error converting schema to JSON.`)}}function J(e,t){let n=t??{seen: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 J(r.element,n);if(r.type===`set`)return J(r.valueType,n);if(r.type===`lazy`)return J(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`)return J(r.innerType,n);if(r.type===`intersection`)return J(r.left,n)||J(r.right,n);if(r.type===`record`||r.type===`map`)return J(r.keyType,n)||J(r.valueType,n);if(r.type===`pipe`)return J(r.in,n)||J(r.out,n);if(r.type===`object`){for(let e in r.shape)if(J(r.shape[e],n))return!0;return!1}if(r.type===`union`){for(let e of r.options)if(J(e,n))return!0;return!1}if(r.type===`tuple`){for(let e of r.items)if(J(e,n))return!0;return!!(r.rest&&J(r.rest,n))}return!1}const la=(e,t={})=>n=>{let r=oa({...n,processors:t});return q(e,r),sa(r,e),ca(r,e)},ua=(e,t,n={})=>r=>{let{libraryOptions:i,target:a}=r??{},o=oa({...i??{},target:a,io:t,processors:n});return q(e,o),sa(o,e),ca(o,e)},da={guid:`uuid`,url:`uri`,datetime:`date-time`,json_string:`json-string`,regex:``},fa=(e,t,n,r)=>{let i=n;i.type=`string`;let{minimum:a,maximum:o,format:s,patterns:c,contentEncoding:l}=e._zod.bag;if(typeof a==`number`&&(i.minLength=a),typeof o==`number`&&(i.maxLength=o),s&&(i.format=da[s]??s,i.format===``&&delete i.format,s===`time`&&delete i.format),l&&(i.contentEncoding=l),c&&c.size>0){let e=[...c];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}))])}},pa=(e,t,n,r)=>{n.type=`boolean`},ma=(e,t,n,r)=>{n.not={}},ha=(e,t,n,r)=>{let i=e._zod.def,a=Et(i.entries);a.every(e=>typeof e==`number`)&&(n.type=`number`),a.every(e=>typeof e==`string`)&&(n.type=`string`),n.enum=a},ga=(e,t,n,r)=>{let i=e._zod.def,a=[];for(let e of i.values)if(e===void 0){if(t.unrepresentable===`throw`)throw Error("Literal `undefined` cannot be represented in JSON Schema")}else if(typeof e==`bigint`){if(t.unrepresentable===`throw`)throw Error(`BigInt literals cannot be represented in JSON Schema`);a.push(Number(e))}else a.push(e);if(a.length!==0)if(a.length===1){let e=a[0];n.type=e===null?`null`:typeof e,t.target===`draft-04`||t.target===`openapi-3.0`?n.enum=[e]:n.const=e}else a.every(e=>typeof e==`number`)&&(n.type=`number`),a.every(e=>typeof e==`string`)&&(n.type=`string`),a.every(e=>typeof e==`boolean`)&&(n.type=`boolean`),a.every(e=>e===null)&&(n.type=`null`),n.enum=a},_a=(e,t,n,r)=>{if(t.unrepresentable===`throw`)throw Error(`Custom types cannot be represented in JSON Schema`)},va=(e,t,n,r)=>{if(t.unrepresentable===`throw`)throw Error(`Transforms cannot be represented in JSON Schema`)},ya=(e,t,n,r)=>{let i=n,a=e._zod.def,{minimum:o,maximum:s}=e._zod.bag;typeof o==`number`&&(i.minItems=o),typeof s==`number`&&(i.maxItems=s),i.type=`array`,i.items=q(a.element,t,{...r,path:[...r.path,`items`]})},ba=(e,t,n,r)=>{let i=n,a=e._zod.def;i.type=`object`,i.properties={};let o=a.shape;for(let e in o)i.properties[e]=q(o[e],t,{...r,path:[...r.path,`properties`,e]});let s=new Set(Object.keys(o)),c=new Set([...s].filter(e=>{let n=a.shape[e]._zod;return t.io===`input`?n.optin===void 0:n.optout===void 0}));c.size>0&&(i.required=Array.from(c)),a.catchall?._zod.def.type===`never`?i.additionalProperties=!1:a.catchall?a.catchall&&(i.additionalProperties=q(a.catchall,t,{...r,path:[...r.path,`additionalProperties`]})):t.io===`output`&&(i.additionalProperties=!1)},xa=(e,t,n,r)=>{let i=e._zod.def,a=i.inclusive===!1,o=i.options.map((e,n)=>q(e,t,{...r,path:[...r.path,a?`oneOf`:`anyOf`,n]}));a?n.oneOf=o:n.anyOf=o},Sa=(e,t,n,r)=>{let i=e._zod.def,a=q(i.left,t,{...r,path:[...r.path,`allOf`,0]}),o=q(i.right,t,{...r,path:[...r.path,`allOf`,1]}),s=e=>`allOf`in e&&Object.keys(e).length===1;n.allOf=[...s(a)?a.allOf:[a],...s(o)?o.allOf:[o]]},Ca=(e,t,n,r)=>{let i=e._zod.def,a=q(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`}]},wa=(e,t,n,r)=>{let i=e._zod.def;q(i.innerType,t,r);let a=t.seen.get(e);a.ref=i.innerType},Ta=(e,t,n,r)=>{let i=e._zod.def;q(i.innerType,t,r);let a=t.seen.get(e);a.ref=i.innerType,n.default=JSON.parse(JSON.stringify(i.defaultValue))},Ea=(e,t,n,r)=>{let i=e._zod.def;q(i.innerType,t,r);let a=t.seen.get(e);a.ref=i.innerType,t.io===`input`&&(n._prefault=JSON.parse(JSON.stringify(i.defaultValue)))},Da=(e,t,n,r)=>{let i=e._zod.def;q(i.innerType,t,r);let a=t.seen.get(e);a.ref=i.innerType;let o;try{o=i.catchValue(void 0)}catch{throw Error(`Dynamic catch values are not supported in JSON Schema`)}n.default=o},Oa=(e,t,n,r)=>{let i=e._zod.def,a=t.io===`input`?i.in._zod.def.type===`transform`?i.out:i.in:i.out;q(a,t,r);let o=t.seen.get(e);o.ref=a},ka=(e,t,n,r)=>{let i=e._zod.def;q(i.innerType,t,r);let a=t.seen.get(e);a.ref=i.innerType,n.readOnly=!0},Aa=(e,t,n,r)=>{let i=e._zod.def;q(i.innerType,t,r);let a=t.seen.get(e);a.ref=i.innerType},ja=k(`ZodISODateTime`,(e,t)=>{mr.init(e,t),Q.init(e,t)});function Ma(e){return Fi(ja,e)}const Na=k(`ZodISODate`,(e,t)=>{hr.init(e,t),Q.init(e,t)});function Pa(e){return Ii(Na,e)}const Fa=k(`ZodISOTime`,(e,t)=>{gr.init(e,t),Q.init(e,t)});function Ia(e){return Li(Fa,e)}const La=k(`ZodISODuration`,(e,t)=>{_r.init(e,t),Q.init(e,t)});function Ra(e){return Ri(La,e)}const za=(e,t)=>{Zt.init(e,t),e.name=`ZodError`,Object.defineProperties(e,{format:{value:t=>en(e,t)},flatten:{value:t=>$t(e,t)},addIssue:{value:t=>{e.issues.push(t),e.message=JSON.stringify(e.issues,Dt,2)}},addIssues:{value:t=>{e.issues.push(...t),e.message=JSON.stringify(e.issues,Dt,2)}},isEmpty:{get(){return e.issues.length===0}}})};k(`ZodError`,za);const Y=k(`ZodError`,za,{Parent:Error}),Ba=tn(Y),Va=nn(Y),Ha=rn(Y),Ua=on(Y),Wa=cn(Y),Ga=ln(Y),Ka=un(Y),qa=dn(Y),Ja=fn(Y),Ya=pn(Y),Xa=mn(Y),Za=hn(Y),X=k(`ZodType`,(e,t)=>(U.init(e,t),Object.assign(e[`~standard`],{jsonSchema:{input:ua(e,`input`),output:ua(e,`output`)}}),e.toJSONSchema=la(e,{}),e.def=t,e.type=t.type,Object.defineProperty(e,`_def`,{value:t}),e.check=(...n)=>e.clone(P(t,{checks:[...t.checks??[],...n.map(e=>typeof e==`function`?{_zod:{check:e,def:{check:`custom`},onattach:[]}}:e)]}),{parent:!0}),e.with=e.check,e.clone=(t,n)=>L(e,t,n),e.brand=()=>e,e.register=((t,n)=>(t.add(e,n),e)),e.parse=(t,n)=>Ba(e,t,n,{callee:e.parse}),e.safeParse=(t,n)=>Ha(e,t,n),e.parseAsync=async(t,n)=>Va(e,t,n,{callee:e.parseAsync}),e.safeParseAsync=async(t,n)=>Ua(e,t,n),e.spa=e.safeParseAsync,e.encode=(t,n)=>Wa(e,t,n),e.decode=(t,n)=>Ga(e,t,n),e.encodeAsync=async(t,n)=>Ka(e,t,n),e.decodeAsync=async(t,n)=>qa(e,t,n),e.safeEncode=(t,n)=>Ja(e,t,n),e.safeDecode=(t,n)=>Ya(e,t,n),e.safeEncodeAsync=async(t,n)=>Xa(e,t,n),e.safeDecodeAsync=async(t,n)=>Za(e,t,n),e.refine=(t,n)=>e.check(as(t,n)),e.superRefine=t=>e.check(os(t)),e.overwrite=t=>e.check(K(t)),e.optional=()=>Vo(e),e.exactOptional=()=>Uo(e),e.nullable=()=>Go(e),e.nullish=()=>Vo(Go(e)),e.nonoptional=t=>Zo(e,t),e.array=()=>Do(e),e.or=t=>jo([e,t]),e.and=t=>No(e,t),e.transform=t=>ts(e,zo(t)),e.default=t=>qo(e,t),e.prefault=t=>Yo(e,t),e.catch=t=>$o(e,t),e.pipe=t=>ts(e,t),e.readonly=()=>rs(e),e.describe=t=>{let n=e.clone();return G.add(n,{description:t}),n},Object.defineProperty(e,`description`,{get(){return G.get(e)?.description},configurable:!0}),e.meta=(...t)=>{if(t.length===0)return G.get(e);let n=e.clone();return G.add(n,t[0]),n},e.isOptional=()=>e.safeParse(void 0).success,e.isNullable=()=>e.safeParse(null).success,e.apply=t=>t(e),e)),Qa=k(`_ZodString`,(e,t)=>{nr.init(e,t),X.init(e,t),e._zod.processJSONSchema=(t,n,r)=>fa(e,t,n,r);let n=e._zod.bag;e.format=n.format??null,e.minLength=n.minimum??null,e.maxLength=n.maximum??null,e.regex=(...t)=>e.check(Gi(...t)),e.includes=(...t)=>e.check(Ji(...t)),e.startsWith=(...t)=>e.check(Yi(...t)),e.endsWith=(...t)=>e.check(Xi(...t)),e.min=(...t)=>e.check(Ui(...t)),e.max=(...t)=>e.check(Hi(...t)),e.length=(...t)=>e.check(Wi(...t)),e.nonempty=(...t)=>e.check(Ui(1,...t)),e.lowercase=t=>e.check(Ki(t)),e.uppercase=t=>e.check(qi(t)),e.trim=()=>e.check(Qi()),e.normalize=(...t)=>e.check(Zi(...t)),e.toLowerCase=()=>e.check($i()),e.toUpperCase=()=>e.check(ea()),e.slugify=()=>e.check(ta())}),$a=k(`ZodString`,(e,t)=>{nr.init(e,t),Qa.init(e,t),e.email=t=>e.check(pi(eo,t)),e.url=t=>e.check(yi(ro,t)),e.jwt=t=>e.check(Pi(yo,t)),e.emoji=t=>e.check(bi(io,t)),e.guid=t=>e.check(mi(to,t)),e.uuid=t=>e.check(hi(no,t)),e.uuidv4=t=>e.check(gi(no,t)),e.uuidv6=t=>e.check(_i(no,t)),e.uuidv7=t=>e.check(vi(no,t)),e.nanoid=t=>e.check(xi(ao,t)),e.guid=t=>e.check(mi(to,t)),e.cuid=t=>e.check(Si(oo,t)),e.cuid2=t=>e.check(Ci(so,t)),e.ulid=t=>e.check(wi(co,t)),e.base64=t=>e.check(ji(go,t)),e.base64url=t=>e.check(Mi(_o,t)),e.xid=t=>e.check(Ti(lo,t)),e.ksuid=t=>e.check(Ei(uo,t)),e.ipv4=t=>e.check(Di(fo,t)),e.ipv6=t=>e.check(Oi(po,t)),e.cidrv4=t=>e.check(ki(mo,t)),e.cidrv6=t=>e.check(Ai(ho,t)),e.e164=t=>e.check(Ni(vo,t)),e.datetime=t=>e.check(Ma(t)),e.date=t=>e.check(Pa(t)),e.time=t=>e.check(Ia(t)),e.duration=t=>e.check(Ra(t))});function Z(e){return fi($a,e)}const Q=k(`ZodStringFormat`,(e,t)=>{W.init(e,t),Qa.init(e,t)}),eo=k(`ZodEmail`,(e,t)=>{ar.init(e,t),Q.init(e,t)}),to=k(`ZodGUID`,(e,t)=>{rr.init(e,t),Q.init(e,t)}),no=k(`ZodUUID`,(e,t)=>{ir.init(e,t),Q.init(e,t)}),ro=k(`ZodURL`,(e,t)=>{or.init(e,t),Q.init(e,t)}),io=k(`ZodEmoji`,(e,t)=>{sr.init(e,t),Q.init(e,t)}),ao=k(`ZodNanoID`,(e,t)=>{cr.init(e,t),Q.init(e,t)}),oo=k(`ZodCUID`,(e,t)=>{lr.init(e,t),Q.init(e,t)}),so=k(`ZodCUID2`,(e,t)=>{ur.init(e,t),Q.init(e,t)}),co=k(`ZodULID`,(e,t)=>{dr.init(e,t),Q.init(e,t)}),lo=k(`ZodXID`,(e,t)=>{fr.init(e,t),Q.init(e,t)}),uo=k(`ZodKSUID`,(e,t)=>{pr.init(e,t),Q.init(e,t)}),fo=k(`ZodIPv4`,(e,t)=>{vr.init(e,t),Q.init(e,t)}),po=k(`ZodIPv6`,(e,t)=>{yr.init(e,t),Q.init(e,t)}),mo=k(`ZodCIDRv4`,(e,t)=>{br.init(e,t),Q.init(e,t)}),ho=k(`ZodCIDRv6`,(e,t)=>{xr.init(e,t),Q.init(e,t)}),go=k(`ZodBase64`,(e,t)=>{Cr.init(e,t),Q.init(e,t)}),_o=k(`ZodBase64URL`,(e,t)=>{Tr.init(e,t),Q.init(e,t)}),vo=k(`ZodE164`,(e,t)=>{Er.init(e,t),Q.init(e,t)}),yo=k(`ZodJWT`,(e,t)=>{Or.init(e,t),Q.init(e,t)}),bo=k(`ZodBoolean`,(e,t)=>{kr.init(e,t),X.init(e,t),e._zod.processJSONSchema=(t,n,r)=>pa(e,t,n,r)});function xo(e){return zi(bo,e)}const So=k(`ZodUnknown`,(e,t)=>{Ar.init(e,t),X.init(e,t),e._zod.processJSONSchema=(e,t,n)=>void 0});function Co(){return Bi(So)}const wo=k(`ZodNever`,(e,t)=>{jr.init(e,t),X.init(e,t),e._zod.processJSONSchema=(t,n,r)=>ma(e,t,n,r)});function To(e){return Vi(wo,e)}const Eo=k(`ZodArray`,(e,t)=>{Nr.init(e,t),X.init(e,t),e._zod.processJSONSchema=(t,n,r)=>ya(e,t,n,r),e.element=t.element,e.min=(t,n)=>e.check(Ui(t,n)),e.nonempty=t=>e.check(Ui(1,t)),e.max=(t,n)=>e.check(Hi(t,n)),e.length=(t,n)=>e.check(Wi(t,n)),e.unwrap=()=>e.element});function Do(e,t){return na(Eo,e,t)}const Oo=k(`ZodObject`,(e,t)=>{Rr.init(e,t),X.init(e,t),e._zod.processJSONSchema=(t,n,r)=>ba(e,t,n,r),M(e,`shape`,()=>t.shape),e.keyof=()=>Fo(Object.keys(e._zod.def.shape)),e.catchall=t=>e.clone({...e._zod.def,catchall:t}),e.passthrough=()=>e.clone({...e._zod.def,catchall:Co()}),e.loose=()=>e.clone({...e._zod.def,catchall:Co()}),e.strict=()=>e.clone({...e._zod.def,catchall:To()}),e.strip=()=>e.clone({...e._zod.def,catchall:void 0}),e.extend=t=>Ht(e,t),e.safeExtend=t=>Ut(e,t),e.merge=t=>Wt(e,t),e.pick=t=>Bt(e,t),e.omit=t=>Vt(e,t),e.partial=(...t)=>Gt(Bo,e,t[0]),e.required=(...t)=>Kt(Xo,e,t[0])});function ko(e,t){return new Oo({type:`object`,shape:e??{},...R(t)})}const Ao=k(`ZodUnion`,(e,t)=>{Br.init(e,t),X.init(e,t),e._zod.processJSONSchema=(t,n,r)=>xa(e,t,n,r),e.options=t.options});function jo(e,t){return new Ao({type:`union`,options:e,...R(t)})}const Mo=k(`ZodIntersection`,(e,t)=>{Vr.init(e,t),X.init(e,t),e._zod.processJSONSchema=(t,n,r)=>Sa(e,t,n,r)});function No(e,t){return new Mo({type:`intersection`,left:e,right:t})}const Po=k(`ZodEnum`,(e,t)=>{Wr.init(e,t),X.init(e,t),e._zod.processJSONSchema=(t,n,r)=>ha(e,t,n,r),e.enum=t.entries,e.options=Object.values(t.entries);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 Po({...t,checks:[],...R(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 Po({...t,checks:[],...R(r),entries:i})}});function Fo(e,t){return new Po({type:`enum`,entries:Array.isArray(e)?Object.fromEntries(e.map(e=>[e,e])):e,...R(t)})}const Io=k(`ZodLiteral`,(e,t)=>{Gr.init(e,t),X.init(e,t),e._zod.processJSONSchema=(t,n,r)=>ga(e,t,n,r),e.values=new Set(t.values),Object.defineProperty(e,`value`,{get(){if(t.values.length>1)throw Error("This schema contains multiple valid literal values. Use `.values` instead.");return t.values[0]}})});function Lo(e,t){return new Io({type:`literal`,values:Array.isArray(e)?e:[e],...R(t)})}const Ro=k(`ZodTransform`,(e,t)=>{Kr.init(e,t),X.init(e,t),e._zod.processJSONSchema=(t,n,r)=>va(e,t,n,r),e._zod.parse=(n,r)=>{if(r.direction===`backward`)throw new wt(e.constructor.name);n.addIssue=r=>{if(typeof r==`string`)n.issues.push(V(r,n.value,t));else{let t=r;t.fatal&&(t.continue=!1),t.code??=`custom`,t.input??=n.value,t.inst??=e,n.issues.push(V(t))}};let i=t.transform(n.value,n);return i instanceof Promise?i.then(e=>(n.value=e,n)):(n.value=i,n)}});function zo(e){return new Ro({type:`transform`,transform:e})}const Bo=k(`ZodOptional`,(e,t)=>{Jr.init(e,t),X.init(e,t),e._zod.processJSONSchema=(t,n,r)=>Aa(e,t,n,r),e.unwrap=()=>e._zod.def.innerType});function Vo(e){return new Bo({type:`optional`,innerType:e})}const Ho=k(`ZodExactOptional`,(e,t)=>{Yr.init(e,t),X.init(e,t),e._zod.processJSONSchema=(t,n,r)=>Aa(e,t,n,r),e.unwrap=()=>e._zod.def.innerType});function Uo(e){return new Ho({type:`optional`,innerType:e})}const Wo=k(`ZodNullable`,(e,t)=>{Xr.init(e,t),X.init(e,t),e._zod.processJSONSchema=(t,n,r)=>Ca(e,t,n,r),e.unwrap=()=>e._zod.def.innerType});function Go(e){return new Wo({type:`nullable`,innerType:e})}const Ko=k(`ZodDefault`,(e,t)=>{Zr.init(e,t),X.init(e,t),e._zod.processJSONSchema=(t,n,r)=>Ta(e,t,n,r),e.unwrap=()=>e._zod.def.innerType,e.removeDefault=e.unwrap});function qo(e,t){return new Ko({type:`default`,innerType:e,get defaultValue(){return typeof t==`function`?t():Lt(t)}})}const Jo=k(`ZodPrefault`,(e,t)=>{$r.init(e,t),X.init(e,t),e._zod.processJSONSchema=(t,n,r)=>Ea(e,t,n,r),e.unwrap=()=>e._zod.def.innerType});function Yo(e,t){return new Jo({type:`prefault`,innerType:e,get defaultValue(){return typeof t==`function`?t():Lt(t)}})}const Xo=k(`ZodNonOptional`,(e,t)=>{ei.init(e,t),X.init(e,t),e._zod.processJSONSchema=(t,n,r)=>wa(e,t,n,r),e.unwrap=()=>e._zod.def.innerType});function Zo(e,t){return new Xo({type:`nonoptional`,innerType:e,...R(t)})}const Qo=k(`ZodCatch`,(e,t)=>{ni.init(e,t),X.init(e,t),e._zod.processJSONSchema=(t,n,r)=>Da(e,t,n,r),e.unwrap=()=>e._zod.def.innerType,e.removeCatch=e.unwrap});function $o(e,t){return new Qo({type:`catch`,innerType:e,catchValue:typeof t==`function`?t:()=>t})}const es=k(`ZodPipe`,(e,t)=>{ri.init(e,t),X.init(e,t),e._zod.processJSONSchema=(t,n,r)=>Oa(e,t,n,r),e.in=t.in,e.out=t.out});function ts(e,t){return new es({type:`pipe`,in:e,out:t})}const ns=k(`ZodReadonly`,(e,t)=>{ai.init(e,t),X.init(e,t),e._zod.processJSONSchema=(t,n,r)=>ka(e,t,n,r),e.unwrap=()=>e._zod.def.innerType});function rs(e){return new ns({type:`readonly`,innerType:e})}const is=k(`ZodCustom`,(e,t)=>{si.init(e,t),X.init(e,t),e._zod.processJSONSchema=(t,n,r)=>_a(e,t,n,r)});function as(e,t={}){return ra(is,e,t)}function os(e){return ia(e)}const ss=Fo([`plugin`,`skill`,`mcp`]),cs=Fo([`latest-tag`,`latest-release`]),ls=jo([xo(),ko({reason:Z().min(1),alternative:Z().optional()})]),us=ko({id:Z().min(1),type:ss,description:Z().min(1),source:Z().min(1),subPath:Z().optional(),capabilities:Do(Z()).optional(),keywords:Do(Z()).optional(),author:Z().optional(),homepage:Z().optional(),versionPolicy:cs.optional(),deprecated:ls.optional()}),ds=ko({version:Lo(1),name:Z().min(1),entries:Do(Co())});function $(e){let t=ds.parse(e),n=[],r=[];return t.entries.forEach((e,t)=>{let i=us.safeParse(e);i.success?n.push(i.data):r.push({index:t,reason:i.error.issues.map(e=>`${e.path.join(`.`)}: ${e.message}`).join(`; `)})}),{name:t.name,version:t.version,entries:n,rejected:r}}const fs=x(process.env.OTTO_REGISTRY_FETCH_TIMEOUT_MS,5e3),ps=x(process.env.OTTO_REGISTRY_CACHE_TTL_MS,36e5);function ms(e){return{name:`otto-official`,url:e,builtin:!0}}var hs=class{constructor(e){this.options=e}get registriesPath(){return g(this.options.configDir,`registries.json`)}get cacheDir(){return g(this.options.ottoHome,`registry-cache`)}listSources(){let e=this.readUserSources(),t=e.find(e=>e.name===this.options.officialSource.name);return[{...this.options.officialSource,disabled:t?.disabled},...e.filter(e=>e.name!==this.options.officialSource.name)]}addSource(e,t){if(e===this.options.officialSource.name)throw Error(`'${e}' 是内置官方源名,不可占用`);let n=this.readUserSources().filter(e=>e.name!==this.options.officialSource.name);if(n.some(t=>t.name===e))throw Error(`registry '${e}' 已存在`);n.push({name:e,url:t}),this.writeUserSources(n)}removeSource(e){if(e===this.options.officialSource.name)throw Error(`官方源不可移除(可 disable:本版本未提供,直接忽略其结果即可)`);let t=this.readUserSources();if(!t.some(t=>t.name===e))throw Error(`registry '${e}' 不存在`);this.writeUserSources(t.filter(t=>t.name!==e))}setSourceEnabled(e,t){if(e===this.options.officialSource.name){let n=this.readUserSources(),r=n.find(t=>t.name===e);r?(r.disabled=!t,this.writeUserSources(n)):this.writeUserSources([...n,{name:e,url:this.options.officialSource.url,disabled:!t}]);return}let n=this.readUserSources(),r=n.find(t=>t.name===e);if(!r)throw Error(`registry '${e}' 不存在`);r.disabled=!t,this.writeUserSources(n)}async loadAll(){let e=[],t=[];for(let n of this.listSources())if(!n.disabled)try{e.push(await this.loadOne(n))}catch(e){t.push(`registry '${n.name}' 加载失败:${e instanceof Error?e.message:String(e)}`)}return{registries:e,warnings:t}}async loadOne(e){if(!/^https?:\/\//.test(e.url)){let t=e.url.replace(/^file:/,``);return{...$(JSON.parse(a(t,`utf-8`))),sourceName:e.name,sourceUrl:e.url,stale:!1}}let t=this.readCache(e.name);if(t&&Date.now()-t.fetchedAt<ps)return{...$(t.raw),sourceName:e.name,sourceUrl:e.url,stale:!1};try{let t=await(this.options.fetchImpl??fetch)(e.url,{signal:AbortSignal.timeout(fs)});if(!t.ok)throw Error(`HTTP ${t.status}`);let n=await t.json(),r=$(n);return this.writeCache(e.name,n),{...r,sourceName:e.name,sourceUrl:e.url,stale:!1}}catch(n){if(t)return{...$(t.raw),sourceName:e.name,sourceUrl:e.url,stale:!0};throw n}}readUserSources(){try{if(!n(this.registriesPath))return[];let e=JSON.parse(a(this.registriesPath,`utf-8`));return Array.isArray(e.sources)?e.sources:[]}catch{return[]}}writeUserSources(e){if(ne())return;r(this.options.configDir,{recursive:!0});let t={version:1,sources:e};f(this.registriesPath,JSON.stringify(t,null,2)+`
43
+ `)}readCache(e){try{let t=g(this.cacheDir,`${gs(e)}.json`);return n(t)?JSON.parse(a(t,`utf-8`)):void 0}catch{return}}writeCache(e,t){if(!ne())try{r(this.cacheDir,{recursive:!0});let n={fetchedAt:Date.now(),raw:t};f(g(this.cacheDir,`${gs(e)}.json`),JSON.stringify(n))}catch{}}};function gs(e){return e.replace(/[^\w.-]+/g,`_`)}export{ot as InstallManager,hs as RegistryClient,ms as builtinOfficialSource,_e as checkArchiveBomb,xt as checkGitUpgrades,_t as checkUpgrades,C as cleanTempDir,ge as createArchive,ve as createTempDir,pt as detectUninstallTarget,he as extractArchive,mt as listInstalledItems,$ as parseRegistry,us as registryEntrySchema,ss as registryEntryTypeSchema,ds as registrySchema,w as sanitizeSourceUrl,gt as scanInstalledVersions,ht as uninstall,S as validateExtractedPaths};
44
44
  //# sourceMappingURL=index.js.map