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

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/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,isIntranetReachable as ne}from"@x-otto/shared";import{isShadowModeEnabled as re,normalizeEnv as x,resolveInternalRegistryUrl as ie,resolveNpmSniffRegistries as ae}from"@x-otto/env";import{parseSkillContent as oe}from"@x-otto/skill";import{HIGH_RISK_CAPABILITIES as se,PLUGIN_MANIFEST_FILENAME as ce,isPluginTrusted as le,parsePluginManifest as ue,trustPlugin as de,untrustPlugin as fe}from"@x-otto/plugin";import{compare as pe}from"semver";const me=[`.zip`,`.tar.gz`,`.tgz`,`.tar`],he=6e4;async function ge(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 _e(e,t){let n=async(e,t)=>{let{stderr:n,status:r,signal:i,timedOut:a}=await ge(e,t,{timeout:he});if(a)throw Error(`解压超时(${he/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 ve(e,t){let{stderr:n,status:r,signal:i,timedOut:a}=await ge(`tar`,[`czf`,t,`-C`,e,`.`],{timeout:he});if(a)throw Error(`打包超时(${he/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 ye(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 be(){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 xe(t){let n=be();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 Se(e){if(!n(e))throw Error(`文件不存在:${e}`);if(u(e).isDirectory())return xe(e);let t=h(e);if(!me.some(e=>t.endsWith(e)))throw Error(`不支持的归档格式:${t}。支持 .zip、.tar.gz、.tgz、.tar(或直接传目录路径)`);let r=be();try{await _e(e,r);let{totalBytes:n}=S(r);return ye(e,n),{tempDir:r,sourceUrl:w(t),sourceType:`file`}}catch(e){throw C(r),e}}const Ce=te(`@x-otto/coding:install:url-resolver`),we=x(process.env.OTTO_DOWNLOAD_TIMEOUT_MS,3e4),Te=x(process.env.OTTO_DOWNLOAD_MAX_REDIRECTS,3),Ee=100*1024*1024;async function De(e,t){let r=h(new URL(e).pathname)||`download`,i=r.toLowerCase();if(!me.some(e=>i.endsWith(e)))throw Error(`URL 文件类型不支持:${r}。请提供 .zip、.tar.gz、.tgz 或 .tar 归档。`);let a=g(m(),`otto-download-${Date.now()}-${r}`),o=be();try{await Oe(e,a,t)}catch(e){C(o);try{n(a)&&d(a)}catch{}throw e}try{await _e(a,o);let{totalBytes:e}=S(o);ye(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 Oe(e,n,r){let i=e;for(let a=0;a<=Te;a++){let o=await fetch(i,{signal:AbortSignal.timeout(we),redirect:`manual`});if(o.status>=300&&o.status<400&&o.headers.get(`location`)){i=o.headers.get(`location`),Ce.info(`Redirecting (%d/%d): %s → %s`,a+1,Te,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>Ee)throw Error(`文件过大:${Math.round(e/1024/1024)}MB,上限 ${Math.round(Ee/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>Ee)throw Error(`下载文件过大(超过 ${Math.round(Ee/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(`下载失败:重定向次数超过上限 (${Te})`)}const ke=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 Ae(e,t){let n=be();return t===void 0?je(e,n):Me(e,n,t)}async function je(e,t){let n=await T([`clone`,`--depth`,`1`,`--quiet`,`--`,e,t],{timeout:ke});if(n.timedOut)throw C(t),Error(`git clone 超时(${ke/1e3}s)`);if(n.status!==0)throw C(t),Error(`git clone 失败:${Pe(n.stderr)}`);let r=await Ne(t);return{tempDir:t,sourceUrl:w(e),sourceType:`git`,commit:r}}async function Me(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:ke});if(i.timedOut)throw C(t),Error(`git fetch 超时(${ke/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}' 失败:${Pe(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 Ne(t);return{tempDir:t,sourceUrl:w(e),sourceType:`git`,commit:o}}async function Ne(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 Pe(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 Fe(){return[...ae(),`https://registry.npmjs.org`]}async function Ie(e,t=5e3){for(let n of Fe()){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??Le(r);if(e)return{version:e,registry:n}}if(t?.version)return{version:t.version,registry:n}}}catch{}finally{clearTimeout(a)}}return null}function Le(e){let t;for(let n of Object.values(e))(!t||Re(n,t)>0)&&(t=n);return t}function Re(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 ze=x(process.env.OTTO_NPM_PACK_TIMEOUT_MS,6e4);function Be(e){let t=e.indexOf(`@`,e.startsWith(`@`)?1:0);return t>0?e.slice(0,t):e}function Ve(e){return e.indexOf(`@`,e.startsWith(`@`)?1:0)>0}async function He(e){let t=i(g(m(),`otto-npm-`)),r=i(g(m(),`otto-npm-extract-`)),a=await Ie(Be(e)).catch(()=>null),o=a?.registry,s=Ve(e)?e:a?`${e}@${a.version}`:e;try{let{stderr:i,status:a,timedOut:c}=await Ue(s,t,o);if(c)throw Error(`npm pack 超时(${ze/1e3}s)`);if(a!==0){let e=i.trim()||`exit code ${a}`,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 l=We(t);if(!l)throw Error(`npm pack 未生成 .tgz 文件:${e}`);await _e(l,r);let{totalBytes:u}=S(r);ye(l,u);try{Ge(t)}catch{}let d=g(r,`package`);return n(d)?{tempDir:d,sourceUrl:`npm:${e}`,sourceType:`npm`}:{tempDir:r,sourceUrl:`npm:${e}`,sourceType:`npm`}}catch(e){throw Ge(t),Ge(r),e}}async function Ue(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()},ze);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 We(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 Ge(e){try{n(e)&&l(e,{recursive:!0,force:!0})}catch{}}function Ke(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 qe(e){let t=Ke(e);return t.length>0?t[0]:null}function Je(e){let t=qe(e);if(!t)throw Error(`未找到 SKILL.md。skill 包必须包含一个 SKILL.md 文件(位于根目录或一层子目录下)。`);let n=a(t,`utf-8`),r=g(t,`..`);try{return oe(n,t,r)}catch(e){throw Error(`SKILL.md 解析失败:${e instanceof Error?e.message:String(e)}`)}}function Ye(e,t){let r=n(g(e,ce)),i=qe(e)!==null,a=n(g(e,`.mcp.json`));if(t)return Xe(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 Xe(e,o[0])}function Xe(e,t){switch(t){case`skill`:return Ze(e);case`plugin`:return Qe(e);case`mcp`:return $e(e)}}function Ze(e){let t=Ke(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(oe(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 Qe(e){let t=g(e,ce);if(!n(t))throw Error(`未找到 ${ce}。`);let r=ue(a(t,`utf-8`),t);if(!r)throw Error(`${ce} 格式无效(缺少 id 字段或 JSON 解析失败)。`);return{type:`plugin`,pluginManifest:r}}function $e(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 et=/^[a-z0-9][a-z0-9-]*[a-z0-9]$|^[a-z0-9]$/;function tt(t,a,o){let s;if(o)s=o;else try{s=Je(t)}catch(e){return{success:!1,error:e instanceof Error?e.message:String(e)}}let u=s.metadata.name;if(!et.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=nt(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 nt(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 rt(e){return(e.capabilities??[]).filter(e=>se.includes(e))}const it={provider:`provider —— 注册 LLM provider,将处理你的凭据与请求流量`,tools:`tools —— 注册可被 agent 调用的工具`,"tui.renderer":`tui.renderer —— 在 TUI 进程内运行自定义渲染代码`,network:`network —— 发起任意网络请求`};async function at(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=rt(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=>` • ${it[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{de(d),v=!0}catch{}let y=[..._],b;if(a.scripts?.postinstall&&o.postInstallExecutor)if(o.global||le(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=rt(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 ot(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 st=/^https?:\/\//,ct=/^(git@|git:\/\/|ssh:\/\/)|\.git$|(?<!https?:\/\/)\b(github\.com|gitlab\.com|bitbucket\.org)\b/;var lt=class{async install(e,t,n,r){let i,a;try{let o=t.type??ut(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 ht(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=Ye(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}),tt(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(tt(r,n,e[a]));let s=i.every(e=>e.success);return{success:s,name:`${e.length} skills`,error:s?void 0:pt(i),failureKind:s?void 0:mt(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 at(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}),ot(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 ut(e){return ct.test(e)?`git`:st.test(e)?`url`:dt(e)?`file`:`npm`}function dt(e){return/^@[^/]+\/[^/]+$/.test(e)?!1:!!(/\.(zip|tar\.gz|tgz|tar)$/i.test(e)||e.includes(`/`)||e.includes(`\\`))}function ft(e){return e.replace(/[。.]\s*$/,``)}function pt(e){let t=e.filter(e=>!e.success),n=t.map(e=>`${e.name??`?`} —— ${ft(e.error??`unknown error`)}`).join(`;`);return`${t.length}/${e.length} 个 skill 安装失败:${n}`}function mt(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 ht(e,t,n,r){switch(t){case`file`:return Se(e);case`url`:return De(e,r);case`git`:return Ae(e,n);case`npm`:return He(e)}}function gt(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 _t(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 vt(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{fe(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 yt(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=oe(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=ue(a(e,`utf-8`),e);n?.version&&r.push({name:n.id,type:t,installed:n.version,path:i})}catch{}}}}async function bt(e){let t=[];for(let n of e){let e=xt(n.path);if(e===`git`){let e=await Et(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&&!St(n.name)){let e=await Et(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 Ct(n.name);if(!e){t.push({name:n.name,type:n.type,installed:n.installed,error:`无法获取最新版本`});continue}let r=pe(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 xt(e){let t=g(e,`.otto-install.json`);if(n(t))try{return JSON.parse(a(t,`utf-8`)).sourceType}catch{return}}function St(e){return!e.includes(`://`)&&!e.endsWith(`.git`)&&!e.endsWith(`.zip`)}async function Ct(e){return(await Ie(e))?.version??null}function wt(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=Tt(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 Tt(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 Et(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=Tt(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.`)}},Dt=class extends Error{constructor(e){super(`Encountered unidirectional transform during encode: ${e}`),this.name=`ZodEncodeError`}};const Ot={};function j(e){return e&&Object.assign(Ot,e),Ot}function kt(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 At(e,t){return typeof t==`bigint`?t.toString():t}function jt(e){return{get value(){{let t=e();return Object.defineProperty(this,`value`,{value:t}),t}throw Error(`cached value already set`)}}}function Mt(e){return e==null}function Nt(e){let t=e.startsWith(`^`)?1:0,n=e.endsWith(`$`)?e.length-1:e.length;return e.slice(t,n)}const Pt=Symbol(`evaluating`);function M(e,t,n){let r;Object.defineProperty(e,t,{get(){if(r!==Pt)return r===void 0&&(r=Pt,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 Ft(e){return JSON.stringify(e)}function It(e){return e.toLowerCase().trim().replace(/[^\w\s-]/g,``).replace(/[\s_-]+/g,`-`).replace(/^-+|-+$/g,``)}const Lt=`captureStackTrace`in Error?Error.captureStackTrace:(...e)=>{};function Rt(e){return typeof e==`object`&&!!e&&!Array.isArray(e)}const zt=jt(()=>{if(typeof navigator<`u`&&navigator?.userAgent?.includes(`Cloudflare`))return!1;try{return Function(``),!0}catch{return!1}});function F(e){if(Rt(e)===!1)return!1;let t=e.constructor;if(t===void 0||typeof t!=`function`)return!0;let n=t.prototype;return!(Rt(n)===!1||Object.prototype.hasOwnProperty.call(n,`isPrototypeOf`)===!1)}function Bt(e){return F(e)?{...e}:Array.isArray(e)?[...e]:e}const Vt=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 Ht(e){return Object.keys(e).filter(t=>e[t]._zod.optin===`optional`&&e[t]._zod.optout===`optional`)}-Number.MAX_VALUE,Number.MAX_VALUE;function Ut(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 Wt(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 Gt(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 Kt(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 qt(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 Jt(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 Yt(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 Xt(e,t){return t.map(t=>{var n;return(n=t).path??(n.path=[]),t.path.unshift(e),t})}function Zt(e){return typeof e==`string`?e:e?.message}function B(e,t,n){let r={...e,path:e.path??[]};return e.message||(r.message=Zt(e.inst?._zod.def?.error?.(e))??Zt(t?.error?.(e))??Zt(n.customError?.(e))??Zt(n.localeError?.(e))??`Invalid input`),delete r.inst,delete r.continue,t?.reportInput||delete r.input,r}function Qt(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 $t=(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,At,2),Object.defineProperty(e,`toString`,{value:()=>e.message,enumerable:!1})},en=k(`$ZodError`,$t),tn=k(`$ZodError`,$t,{Parent:Error});function nn(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 rn(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 an=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 Lt(t,i?.callee),t}return o.value},on=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 Lt(t,i?.callee),t}return o.value},sn=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??en)(a.issues.map(e=>B(e,i,j())))}:{success:!0,data:a.value}},cn=sn(tn),ln=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}},un=ln(tn),dn=e=>(t,n,r)=>{let i=r?Object.assign(r,{direction:`backward`}):{direction:`backward`};return an(e)(t,n,i)},fn=e=>(t,n,r)=>an(e)(t,n,r),pn=e=>async(t,n,r)=>{let i=r?Object.assign(r,{direction:`backward`}):{direction:`backward`};return on(e)(t,n,i)},mn=e=>async(t,n,r)=>on(e)(t,n,r),hn=e=>(t,n,r)=>{let i=r?Object.assign(r,{direction:`backward`}):{direction:`backward`};return sn(e)(t,n,i)},gn=e=>(t,n,r)=>sn(e)(t,n,r),_n=e=>async(t,n,r)=>{let i=r?Object.assign(r,{direction:`backward`}):{direction:`backward`};return ln(e)(t,n,i)},vn=e=>async(t,n,r)=>ln(e)(t,n,r),yn=/^[cC][^\s-]{8,}$/,bn=/^[0-9a-z]+$/,xn=/^[0-9A-HJKMNP-TV-Za-hjkmnp-tv-z]{26}$/,Sn=/^[0-9a-vA-V]{20}$/,Cn=/^[A-Za-z0-9]{27}$/,wn=/^[a-zA-Z0-9_-]{21}$/,Tn=/^P(?:(\d+W)|(?!.*W)(?=\d|T\d)(\d+Y)?(\d+M)?(\d+D)?(T(?=\d)(\d+H)?(\d+M)?(\d+([.,]\d+)?S)?)?)$/,En=/^([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})$/,Dn=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)$/,On=/^(?!\.)(?!.*\.\.)([A-Za-z0-9_'+\-\.]*)[A-Za-z0-9_+-]@([A-Za-z0-9][A-Za-z0-9\-]*\.)+[A-Za-z]{2,}$/;function kn(){return RegExp(`^(\\p{Extended_Pictographic}|\\p{Emoji_Component})+$`,`u`)}const An=/^(?:(?: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])$/,jn=/^(([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}|:))$/,Mn=/^((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])$/,Nn=/^(([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])$/,Pn=/^$|^(?:[0-9a-zA-Z+/]{4})*(?:(?:[0-9a-zA-Z+/]{2}==)|(?:[0-9a-zA-Z+/]{3}=))?$/,Fn=/^[A-Za-z0-9_-]*$/,In=/^\+[1-9]\d{6,14}$/,Ln=`(?:(?:\\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])))`,Rn=RegExp(`^${Ln}$`);function zn(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 Bn(e){return RegExp(`^${zn(e)}$`)}function Vn(e){let t=zn({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(`^${Ln}T(?:${r})$`)}const Hn=e=>{let t=e?`[\\s\\S]{${e?.minimum??0},${e?.maximum??``}}`:`[\\s\\S]*`;return RegExp(`^${t}$`)},Un=/^(?:true|false)$/i,Wn=/^[^A-Z]*$/,Gn=/^[^a-z]*$/,H=k(`$ZodCheck`,(e,t)=>{var n;e._zod??={},e._zod.def=t,(n=e._zod).onattach??(n.onattach=[])}),Kn=k(`$ZodCheckMaxLength`,(e,t)=>{var n;H.init(e,t),(n=e._zod.def).when??(n.when=e=>{let t=e.value;return!Mt(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=Qt(r);n.issues.push({origin:i,code:`too_big`,maximum:t.maximum,inclusive:!0,input:r,inst:e,continue:!t.abort})}}),qn=k(`$ZodCheckMinLength`,(e,t)=>{var n;H.init(e,t),(n=e._zod.def).when??(n.when=e=>{let t=e.value;return!Mt(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=Qt(r);n.issues.push({origin:i,code:`too_small`,minimum:t.minimum,inclusive:!0,input:r,inst:e,continue:!t.abort})}}),Jn=k(`$ZodCheckLengthEquals`,(e,t)=>{var n;H.init(e,t),(n=e._zod.def).when??(n.when=e=>{let t=e.value;return!Mt(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=Qt(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})}}),Yn=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=()=>{})}),Xn=k(`$ZodCheckRegex`,(e,t)=>{Yn.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})}}),Zn=k(`$ZodCheckLowerCase`,(e,t)=>{t.pattern??=Wn,Yn.init(e,t)}),Qn=k(`$ZodCheckUpperCase`,(e,t)=>{t.pattern??=Gn,Yn.init(e,t)}),$n=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})}}),er=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})}}),tr=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})}}),nr=k(`$ZodCheckOverwrite`,(e,t)=>{H.init(e,t),e._zod.check=e=>{e.value=t.tx(e.value)}});var rr=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 ir={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=ir;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=cn(e,t);return n.success?{value:n.data}:{issues:n.error?.issues}}catch{return un(e,t).then(e=>e.success?{value:e.data}:{issues:e.error?.issues})}},vendor:`zod`,version:1}))}),ar=k(`$ZodString`,(e,t)=>{U.init(e,t),e._zod.pattern=[...e?._zod.bag?.patterns??[]].pop()??Hn(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)=>{Yn.init(e,t),ar.init(e,t)}),or=k(`$ZodGUID`,(e,t)=>{t.pattern??=En,W.init(e,t)}),sr=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??=Dn(e)}else t.pattern??=Dn();W.init(e,t)}),cr=k(`$ZodEmail`,(e,t)=>{t.pattern??=On,W.init(e,t)}),lr=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})}}}),ur=k(`$ZodEmoji`,(e,t)=>{t.pattern??=kn(),W.init(e,t)}),dr=k(`$ZodNanoID`,(e,t)=>{t.pattern??=wn,W.init(e,t)}),fr=k(`$ZodCUID`,(e,t)=>{t.pattern??=yn,W.init(e,t)}),pr=k(`$ZodCUID2`,(e,t)=>{t.pattern??=bn,W.init(e,t)}),mr=k(`$ZodULID`,(e,t)=>{t.pattern??=xn,W.init(e,t)}),hr=k(`$ZodXID`,(e,t)=>{t.pattern??=Sn,W.init(e,t)}),gr=k(`$ZodKSUID`,(e,t)=>{t.pattern??=Cn,W.init(e,t)}),_r=k(`$ZodISODateTime`,(e,t)=>{t.pattern??=Vn(t),W.init(e,t)}),vr=k(`$ZodISODate`,(e,t)=>{t.pattern??=Rn,W.init(e,t)}),yr=k(`$ZodISOTime`,(e,t)=>{t.pattern??=Bn(t),W.init(e,t)}),br=k(`$ZodISODuration`,(e,t)=>{t.pattern??=Tn,W.init(e,t)}),xr=k(`$ZodIPv4`,(e,t)=>{t.pattern??=An,W.init(e,t),e._zod.bag.format=`ipv4`}),Sr=k(`$ZodIPv6`,(e,t)=>{t.pattern??=jn,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})}}}),Cr=k(`$ZodCIDRv4`,(e,t)=>{t.pattern??=Mn,W.init(e,t)}),wr=k(`$ZodCIDRv6`,(e,t)=>{t.pattern??=Nn,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 Tr(e){if(e===``)return!0;if(e.length%4!=0)return!1;try{return atob(e),!0}catch{return!1}}const Er=k(`$ZodBase64`,(e,t)=>{t.pattern??=Pn,W.init(e,t),e._zod.bag.contentEncoding=`base64`,e._zod.check=n=>{Tr(n.value)||n.issues.push({code:`invalid_format`,format:`base64`,input:n.value,inst:e,continue:!t.abort})}});function Dr(e){if(!Fn.test(e))return!1;let t=e.replace(/[-_]/g,e=>e===`-`?`+`:`/`);return Tr(t.padEnd(Math.ceil(t.length/4)*4,`=`))}const Or=k(`$ZodBase64URL`,(e,t)=>{t.pattern??=Fn,W.init(e,t),e._zod.bag.contentEncoding=`base64url`,e._zod.check=n=>{Dr(n.value)||n.issues.push({code:`invalid_format`,format:`base64url`,input:n.value,inst:e,continue:!t.abort})}}),kr=k(`$ZodE164`,(e,t)=>{t.pattern??=In,W.init(e,t)});function Ar(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 jr=k(`$ZodJWT`,(e,t)=>{W.init(e,t),e._zod.check=n=>{Ar(n.value,t.alg)||n.issues.push({code:`invalid_format`,format:`jwt`,input:n.value,inst:e,continue:!t.abort})}}),Mr=k(`$ZodBoolean`,(e,t)=>{U.init(e,t),e._zod.pattern=Un,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}}),Nr=k(`$ZodUnknown`,(e,t)=>{U.init(e,t),e._zod.parse=e=>e}),Pr=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 Fr(e,t,n){e.issues.length&&t.issues.push(...Xt(n,e.issues)),t.value[n]=e.value}const Ir=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=>Fr(t,n,e))):Fr(s,n,e)}return a.length?Promise.all(a).then(()=>n):n}});function Lr(e,t,n,r,i){if(e.issues.length){if(i&&!(n in r))return;t.issues.push(...Xt(n,e.issues))}e.value===void 0?n in r&&(t.value[n]=void 0):t.value[n]=e.value}function Rr(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=Ht(e.shape);return{...e,keys:t,keySet:new Set(t),numKeys:t.length,optionalKeys:new Set(n)}}function zr(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=>Lr(e,n,i,t,u))):Lr(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 Br=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=jt(()=>Rr(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=Rt,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=>Lr(n,t,e,s,r))):Lr(i,t,e,s,r)}return i?zr(c,s,t,o,n.value,e):c.length?Promise.all(c).then(()=>t):t}}),Vr=k(`$ZodObjectJIT`,(e,t)=>{Br.init(e,t);let n=e._zod.parse,r=jt(()=>Rr(t)),i=e=>{let t=new rr([`shape`,`payload`,`ctx`]),n=r.value,i=e=>{let t=Ft(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=Ft(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=Rt,s=!Ot.jitless,c=s&&zt.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?zr([],p,d,f,u,e):d):n(d,f):(d.issues.push({expected:`object`,code:`invalid_type`,input:p,inst:e}),d)}});function Hr(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 Ur=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=>Nt(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=>Hr(t,i,e,a)):Hr(s,i,e,a)}}),Wr=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])=>Kr(e,t,n)):Kr(e,i,a)}});function Gr(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=Gr(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=Gr(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 Kr(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=Gr(t.value,n.value);if(!o.valid)throw Error(`Unmergable intersection. Error path: ${JSON.stringify(o.mergeErrorPath)}`);return e.value=o.data,e}const qr=k(`$ZodEnum`,(e,t)=>{U.init(e,t);let n=kt(t.entries),r=new Set(n);e._zod.values=r,e._zod.pattern=RegExp(`^(${n.filter(e=>Vt.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}}),Jr=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}}),Yr=k(`$ZodTransform`,(e,t)=>{U.init(e,t),e._zod.parse=(n,r)=>{if(r.direction===`backward`)throw new Dt(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 Xr(e,t){return e.issues.length&&t===void 0?{issues:[],value:void 0}:e}const Zr=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(`^(${Nt(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=>Xr(t,e.value)):Xr(r,e.value)}return e.value===void 0?e:t.innerType._zod.run(e,n)}}),Qr=k(`$ZodExactOptional`,(e,t)=>{Zr.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)}),$r=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(`^(${Nt(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)}),ei=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=>ti(e,t)):ti(r,t)}});function ti(e,t){return e.value===void 0&&(e.value=t.defaultValue),e}const ni=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))}),ri=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=>ii(t,e)):ii(i,e)}});function ii(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 ai=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)}}),oi=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=>si(e,t.in,n)):si(r,t.in,n)}let r=t.in._zod.run(e,n);return r instanceof Promise?r.then(e=>si(e,t.out,n)):si(r,t.out,n)}});function si(e,t,n){return e.issues.length?(e.aborted=!0,e):t._zod.run({value:e.value,issues:e.issues},n)}const ci=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(li):li(r)}});function li(e){return e.value=Object.freeze(e.value),e}const ui=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=>di(t,n,r,e));di(i,n,r,e)}});function di(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 fi,pi=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 mi(){return new pi}(fi=globalThis).__zod_globalRegistry??(fi.__zod_globalRegistry=mi());const G=globalThis.__zod_globalRegistry;function hi(e,t){return new e({type:`string`,...R(t)})}function gi(e,t){return new e({type:`string`,format:`email`,check:`string_format`,abort:!1,...R(t)})}function _i(e,t){return new e({type:`string`,format:`guid`,check:`string_format`,abort:!1,...R(t)})}function vi(e,t){return new e({type:`string`,format:`uuid`,check:`string_format`,abort:!1,...R(t)})}function yi(e,t){return new e({type:`string`,format:`uuid`,check:`string_format`,abort:!1,version:`v4`,...R(t)})}function bi(e,t){return new e({type:`string`,format:`uuid`,check:`string_format`,abort:!1,version:`v6`,...R(t)})}function xi(e,t){return new e({type:`string`,format:`uuid`,check:`string_format`,abort:!1,version:`v7`,...R(t)})}function Si(e,t){return new e({type:`string`,format:`url`,check:`string_format`,abort:!1,...R(t)})}function Ci(e,t){return new e({type:`string`,format:`emoji`,check:`string_format`,abort:!1,...R(t)})}function wi(e,t){return new e({type:`string`,format:`nanoid`,check:`string_format`,abort:!1,...R(t)})}function Ti(e,t){return new e({type:`string`,format:`cuid`,check:`string_format`,abort:!1,...R(t)})}function Ei(e,t){return new e({type:`string`,format:`cuid2`,check:`string_format`,abort:!1,...R(t)})}function Di(e,t){return new e({type:`string`,format:`ulid`,check:`string_format`,abort:!1,...R(t)})}function Oi(e,t){return new e({type:`string`,format:`xid`,check:`string_format`,abort:!1,...R(t)})}function ki(e,t){return new e({type:`string`,format:`ksuid`,check:`string_format`,abort:!1,...R(t)})}function Ai(e,t){return new e({type:`string`,format:`ipv4`,check:`string_format`,abort:!1,...R(t)})}function ji(e,t){return new e({type:`string`,format:`ipv6`,check:`string_format`,abort:!1,...R(t)})}function Mi(e,t){return new e({type:`string`,format:`cidrv4`,check:`string_format`,abort:!1,...R(t)})}function Ni(e,t){return new e({type:`string`,format:`cidrv6`,check:`string_format`,abort:!1,...R(t)})}function Pi(e,t){return new e({type:`string`,format:`base64`,check:`string_format`,abort:!1,...R(t)})}function Fi(e,t){return new e({type:`string`,format:`base64url`,check:`string_format`,abort:!1,...R(t)})}function Ii(e,t){return new e({type:`string`,format:`e164`,check:`string_format`,abort:!1,...R(t)})}function Li(e,t){return new e({type:`string`,format:`jwt`,check:`string_format`,abort:!1,...R(t)})}function Ri(e,t){return new e({type:`string`,format:`datetime`,check:`string_format`,offset:!1,local:!1,precision:null,...R(t)})}function zi(e,t){return new e({type:`string`,format:`date`,check:`string_format`,...R(t)})}function Bi(e,t){return new e({type:`string`,format:`time`,check:`string_format`,precision:null,...R(t)})}function Vi(e,t){return new e({type:`string`,format:`duration`,check:`string_format`,...R(t)})}function Hi(e,t){return new e({type:`boolean`,...R(t)})}function Ui(e){return new e({type:`unknown`})}function Wi(e,t){return new e({type:`never`,...R(t)})}function Gi(e,t){return new Kn({check:`max_length`,...R(t),maximum:e})}function Ki(e,t){return new qn({check:`min_length`,...R(t),minimum:e})}function qi(e,t){return new Jn({check:`length_equals`,...R(t),length:e})}function Ji(e,t){return new Xn({check:`string_format`,format:`regex`,...R(t),pattern:e})}function Yi(e){return new Zn({check:`string_format`,format:`lowercase`,...R(e)})}function Xi(e){return new Qn({check:`string_format`,format:`uppercase`,...R(e)})}function Zi(e,t){return new $n({check:`string_format`,format:`includes`,...R(t),includes:e})}function Qi(e,t){return new er({check:`string_format`,format:`starts_with`,...R(t),prefix:e})}function $i(e,t){return new tr({check:`string_format`,format:`ends_with`,...R(t),suffix:e})}function K(e){return new nr({check:`overwrite`,tx:e})}function ea(e){return K(t=>t.normalize(e))}function ta(){return K(e=>e.trim())}function na(){return K(e=>e.toLowerCase())}function ra(){return K(e=>e.toUpperCase())}function ia(){return K(e=>It(e))}function aa(e,t,n){return new e({type:`array`,element:t,...R(n)})}function oa(e,t,n){return new e({type:`custom`,check:`custom`,fn:t,...R(n)})}function sa(e){let t=ca(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 ca(e,t){let n=new H({check:`custom`,...R(t)});return n._zod.check=e,n}function la(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 ua(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 da(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:pa(t,`input`,e.processors),output:pa(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 fa=(e,t={})=>n=>{let r=la({...n,processors:t});return q(e,r),ua(r,e),da(r,e)},pa=(e,t,n={})=>r=>{let{libraryOptions:i,target:a}=r??{},o=la({...i??{},target:a,io:t,processors:n});return q(e,o),ua(o,e),da(o,e)},ma={guid:`uuid`,url:`uri`,datetime:`date-time`,json_string:`json-string`,regex:``},ha=(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=ma[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}))])}},ga=(e,t,n,r)=>{n.type=`boolean`},_a=(e,t,n,r)=>{n.not={}},va=(e,t,n,r)=>{let i=e._zod.def,a=kt(i.entries);a.every(e=>typeof e==`number`)&&(n.type=`number`),a.every(e=>typeof e==`string`)&&(n.type=`string`),n.enum=a},ya=(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},ba=(e,t,n,r)=>{if(t.unrepresentable===`throw`)throw Error(`Custom types cannot be represented in JSON Schema`)},xa=(e,t,n,r)=>{if(t.unrepresentable===`throw`)throw Error(`Transforms cannot be represented in JSON Schema`)},Sa=(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`]})},Ca=(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)},wa=(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},Ta=(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]]},Ea=(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`}]},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},Oa=(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))},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,t.io===`input`&&(n._prefault=JSON.parse(JSON.stringify(i.defaultValue)))},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;let o;try{o=i.catchValue(void 0)}catch{throw Error(`Dynamic catch values are not supported in JSON Schema`)}n.default=o},ja=(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},Ma=(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},Na=(e,t,n,r)=>{let i=e._zod.def;q(i.innerType,t,r);let a=t.seen.get(e);a.ref=i.innerType},Pa=k(`ZodISODateTime`,(e,t)=>{_r.init(e,t),Q.init(e,t)});function Fa(e){return Ri(Pa,e)}const Ia=k(`ZodISODate`,(e,t)=>{vr.init(e,t),Q.init(e,t)});function La(e){return zi(Ia,e)}const Ra=k(`ZodISOTime`,(e,t)=>{yr.init(e,t),Q.init(e,t)});function za(e){return Bi(Ra,e)}const Ba=k(`ZodISODuration`,(e,t)=>{br.init(e,t),Q.init(e,t)});function Va(e){return Vi(Ba,e)}const Ha=(e,t)=>{en.init(e,t),e.name=`ZodError`,Object.defineProperties(e,{format:{value:t=>rn(e,t)},flatten:{value:t=>nn(e,t)},addIssue:{value:t=>{e.issues.push(t),e.message=JSON.stringify(e.issues,At,2)}},addIssues:{value:t=>{e.issues.push(...t),e.message=JSON.stringify(e.issues,At,2)}},isEmpty:{get(){return e.issues.length===0}}})};k(`ZodError`,Ha);const Y=k(`ZodError`,Ha,{Parent:Error}),Ua=an(Y),Wa=on(Y),Ga=sn(Y),Ka=ln(Y),qa=dn(Y),Ja=fn(Y),Ya=pn(Y),Xa=mn(Y),Za=hn(Y),Qa=gn(Y),$a=_n(Y),eo=vn(Y),X=k(`ZodType`,(e,t)=>(U.init(e,t),Object.assign(e[`~standard`],{jsonSchema:{input:pa(e,`input`),output:pa(e,`output`)}}),e.toJSONSchema=fa(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)=>Ua(e,t,n,{callee:e.parse}),e.safeParse=(t,n)=>Ga(e,t,n),e.parseAsync=async(t,n)=>Wa(e,t,n,{callee:e.parseAsync}),e.safeParseAsync=async(t,n)=>Ka(e,t,n),e.spa=e.safeParseAsync,e.encode=(t,n)=>qa(e,t,n),e.decode=(t,n)=>Ja(e,t,n),e.encodeAsync=async(t,n)=>Ya(e,t,n),e.decodeAsync=async(t,n)=>Xa(e,t,n),e.safeEncode=(t,n)=>Za(e,t,n),e.safeDecode=(t,n)=>Qa(e,t,n),e.safeEncodeAsync=async(t,n)=>$a(e,t,n),e.safeDecodeAsync=async(t,n)=>eo(e,t,n),e.refine=(t,n)=>e.check(cs(t,n)),e.superRefine=t=>e.check(ls(t)),e.overwrite=t=>e.check(K(t)),e.optional=()=>Wo(e),e.exactOptional=()=>Ko(e),e.nullable=()=>Jo(e),e.nullish=()=>Wo(Jo(e)),e.nonoptional=t=>es(e,t),e.array=()=>Ao(e),e.or=t=>Po([e,t]),e.and=t=>Io(e,t),e.transform=t=>is(e,Ho(t)),e.default=t=>Xo(e,t),e.prefault=t=>Qo(e,t),e.catch=t=>ns(e,t),e.pipe=t=>is(e,t),e.readonly=()=>os(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)),to=k(`_ZodString`,(e,t)=>{ar.init(e,t),X.init(e,t),e._zod.processJSONSchema=(t,n,r)=>ha(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(Ji(...t)),e.includes=(...t)=>e.check(Zi(...t)),e.startsWith=(...t)=>e.check(Qi(...t)),e.endsWith=(...t)=>e.check($i(...t)),e.min=(...t)=>e.check(Ki(...t)),e.max=(...t)=>e.check(Gi(...t)),e.length=(...t)=>e.check(qi(...t)),e.nonempty=(...t)=>e.check(Ki(1,...t)),e.lowercase=t=>e.check(Yi(t)),e.uppercase=t=>e.check(Xi(t)),e.trim=()=>e.check(ta()),e.normalize=(...t)=>e.check(ea(...t)),e.toLowerCase=()=>e.check(na()),e.toUpperCase=()=>e.check(ra()),e.slugify=()=>e.check(ia())}),no=k(`ZodString`,(e,t)=>{ar.init(e,t),to.init(e,t),e.email=t=>e.check(gi(ro,t)),e.url=t=>e.check(Si(oo,t)),e.jwt=t=>e.check(Li(So,t)),e.emoji=t=>e.check(Ci(so,t)),e.guid=t=>e.check(_i(io,t)),e.uuid=t=>e.check(vi(ao,t)),e.uuidv4=t=>e.check(yi(ao,t)),e.uuidv6=t=>e.check(bi(ao,t)),e.uuidv7=t=>e.check(xi(ao,t)),e.nanoid=t=>e.check(wi(co,t)),e.guid=t=>e.check(_i(io,t)),e.cuid=t=>e.check(Ti(lo,t)),e.cuid2=t=>e.check(Ei(uo,t)),e.ulid=t=>e.check(Di(fo,t)),e.base64=t=>e.check(Pi(yo,t)),e.base64url=t=>e.check(Fi(bo,t)),e.xid=t=>e.check(Oi(po,t)),e.ksuid=t=>e.check(ki(mo,t)),e.ipv4=t=>e.check(Ai(ho,t)),e.ipv6=t=>e.check(ji(go,t)),e.cidrv4=t=>e.check(Mi(_o,t)),e.cidrv6=t=>e.check(Ni(vo,t)),e.e164=t=>e.check(Ii(xo,t)),e.datetime=t=>e.check(Fa(t)),e.date=t=>e.check(La(t)),e.time=t=>e.check(za(t)),e.duration=t=>e.check(Va(t))});function Z(e){return hi(no,e)}const Q=k(`ZodStringFormat`,(e,t)=>{W.init(e,t),to.init(e,t)}),ro=k(`ZodEmail`,(e,t)=>{cr.init(e,t),Q.init(e,t)}),io=k(`ZodGUID`,(e,t)=>{or.init(e,t),Q.init(e,t)}),ao=k(`ZodUUID`,(e,t)=>{sr.init(e,t),Q.init(e,t)}),oo=k(`ZodURL`,(e,t)=>{lr.init(e,t),Q.init(e,t)}),so=k(`ZodEmoji`,(e,t)=>{ur.init(e,t),Q.init(e,t)}),co=k(`ZodNanoID`,(e,t)=>{dr.init(e,t),Q.init(e,t)}),lo=k(`ZodCUID`,(e,t)=>{fr.init(e,t),Q.init(e,t)}),uo=k(`ZodCUID2`,(e,t)=>{pr.init(e,t),Q.init(e,t)}),fo=k(`ZodULID`,(e,t)=>{mr.init(e,t),Q.init(e,t)}),po=k(`ZodXID`,(e,t)=>{hr.init(e,t),Q.init(e,t)}),mo=k(`ZodKSUID`,(e,t)=>{gr.init(e,t),Q.init(e,t)}),ho=k(`ZodIPv4`,(e,t)=>{xr.init(e,t),Q.init(e,t)}),go=k(`ZodIPv6`,(e,t)=>{Sr.init(e,t),Q.init(e,t)}),_o=k(`ZodCIDRv4`,(e,t)=>{Cr.init(e,t),Q.init(e,t)}),vo=k(`ZodCIDRv6`,(e,t)=>{wr.init(e,t),Q.init(e,t)}),yo=k(`ZodBase64`,(e,t)=>{Er.init(e,t),Q.init(e,t)}),bo=k(`ZodBase64URL`,(e,t)=>{Or.init(e,t),Q.init(e,t)}),xo=k(`ZodE164`,(e,t)=>{kr.init(e,t),Q.init(e,t)}),So=k(`ZodJWT`,(e,t)=>{jr.init(e,t),Q.init(e,t)}),Co=k(`ZodBoolean`,(e,t)=>{Mr.init(e,t),X.init(e,t),e._zod.processJSONSchema=(t,n,r)=>ga(e,t,n,r)});function wo(e){return Hi(Co,e)}const To=k(`ZodUnknown`,(e,t)=>{Nr.init(e,t),X.init(e,t),e._zod.processJSONSchema=(e,t,n)=>void 0});function Eo(){return Ui(To)}const Do=k(`ZodNever`,(e,t)=>{Pr.init(e,t),X.init(e,t),e._zod.processJSONSchema=(t,n,r)=>_a(e,t,n,r)});function Oo(e){return Wi(Do,e)}const ko=k(`ZodArray`,(e,t)=>{Ir.init(e,t),X.init(e,t),e._zod.processJSONSchema=(t,n,r)=>Sa(e,t,n,r),e.element=t.element,e.min=(t,n)=>e.check(Ki(t,n)),e.nonempty=t=>e.check(Ki(1,t)),e.max=(t,n)=>e.check(Gi(t,n)),e.length=(t,n)=>e.check(qi(t,n)),e.unwrap=()=>e.element});function Ao(e,t){return aa(ko,e,t)}const jo=k(`ZodObject`,(e,t)=>{Vr.init(e,t),X.init(e,t),e._zod.processJSONSchema=(t,n,r)=>Ca(e,t,n,r),M(e,`shape`,()=>t.shape),e.keyof=()=>Ro(Object.keys(e._zod.def.shape)),e.catchall=t=>e.clone({...e._zod.def,catchall:t}),e.passthrough=()=>e.clone({...e._zod.def,catchall:Eo()}),e.loose=()=>e.clone({...e._zod.def,catchall:Eo()}),e.strict=()=>e.clone({...e._zod.def,catchall:Oo()}),e.strip=()=>e.clone({...e._zod.def,catchall:void 0}),e.extend=t=>Gt(e,t),e.safeExtend=t=>Kt(e,t),e.merge=t=>qt(e,t),e.pick=t=>Ut(e,t),e.omit=t=>Wt(e,t),e.partial=(...t)=>Jt(Uo,e,t[0]),e.required=(...t)=>Yt($o,e,t[0])});function Mo(e,t){return new jo({type:`object`,shape:e??{},...R(t)})}const No=k(`ZodUnion`,(e,t)=>{Ur.init(e,t),X.init(e,t),e._zod.processJSONSchema=(t,n,r)=>wa(e,t,n,r),e.options=t.options});function Po(e,t){return new No({type:`union`,options:e,...R(t)})}const Fo=k(`ZodIntersection`,(e,t)=>{Wr.init(e,t),X.init(e,t),e._zod.processJSONSchema=(t,n,r)=>Ta(e,t,n,r)});function Io(e,t){return new Fo({type:`intersection`,left:e,right:t})}const Lo=k(`ZodEnum`,(e,t)=>{qr.init(e,t),X.init(e,t),e._zod.processJSONSchema=(t,n,r)=>va(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 Lo({...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 Lo({...t,checks:[],...R(r),entries:i})}});function Ro(e,t){return new Lo({type:`enum`,entries:Array.isArray(e)?Object.fromEntries(e.map(e=>[e,e])):e,...R(t)})}const zo=k(`ZodLiteral`,(e,t)=>{Jr.init(e,t),X.init(e,t),e._zod.processJSONSchema=(t,n,r)=>ya(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 Bo(e,t){return new zo({type:`literal`,values:Array.isArray(e)?e:[e],...R(t)})}const Vo=k(`ZodTransform`,(e,t)=>{Yr.init(e,t),X.init(e,t),e._zod.processJSONSchema=(t,n,r)=>xa(e,t,n,r),e._zod.parse=(n,r)=>{if(r.direction===`backward`)throw new Dt(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 Ho(e){return new Vo({type:`transform`,transform:e})}const Uo=k(`ZodOptional`,(e,t)=>{Zr.init(e,t),X.init(e,t),e._zod.processJSONSchema=(t,n,r)=>Na(e,t,n,r),e.unwrap=()=>e._zod.def.innerType});function Wo(e){return new Uo({type:`optional`,innerType:e})}const Go=k(`ZodExactOptional`,(e,t)=>{Qr.init(e,t),X.init(e,t),e._zod.processJSONSchema=(t,n,r)=>Na(e,t,n,r),e.unwrap=()=>e._zod.def.innerType});function Ko(e){return new Go({type:`optional`,innerType:e})}const qo=k(`ZodNullable`,(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 Jo(e){return new qo({type:`nullable`,innerType:e})}const Yo=k(`ZodDefault`,(e,t)=>{ei.init(e,t),X.init(e,t),e._zod.processJSONSchema=(t,n,r)=>Oa(e,t,n,r),e.unwrap=()=>e._zod.def.innerType,e.removeDefault=e.unwrap});function Xo(e,t){return new Yo({type:`default`,innerType:e,get defaultValue(){return typeof t==`function`?t():Bt(t)}})}const Zo=k(`ZodPrefault`,(e,t)=>{ni.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 Qo(e,t){return new Zo({type:`prefault`,innerType:e,get defaultValue(){return typeof t==`function`?t():Bt(t)}})}const $o=k(`ZodNonOptional`,(e,t)=>{ri.init(e,t),X.init(e,t),e._zod.processJSONSchema=(t,n,r)=>Da(e,t,n,r),e.unwrap=()=>e._zod.def.innerType});function es(e,t){return new $o({type:`nonoptional`,innerType:e,...R(t)})}const ts=k(`ZodCatch`,(e,t)=>{ai.init(e,t),X.init(e,t),e._zod.processJSONSchema=(t,n,r)=>Aa(e,t,n,r),e.unwrap=()=>e._zod.def.innerType,e.removeCatch=e.unwrap});function ns(e,t){return new ts({type:`catch`,innerType:e,catchValue:typeof t==`function`?t:()=>t})}const rs=k(`ZodPipe`,(e,t)=>{oi.init(e,t),X.init(e,t),e._zod.processJSONSchema=(t,n,r)=>ja(e,t,n,r),e.in=t.in,e.out=t.out});function is(e,t){return new rs({type:`pipe`,in:e,out:t})}const as=k(`ZodReadonly`,(e,t)=>{ci.init(e,t),X.init(e,t),e._zod.processJSONSchema=(t,n,r)=>Ma(e,t,n,r),e.unwrap=()=>e._zod.def.innerType});function os(e){return new as({type:`readonly`,innerType:e})}const ss=k(`ZodCustom`,(e,t)=>{ui.init(e,t),X.init(e,t),e._zod.processJSONSchema=(t,n,r)=>ba(e,t,n,r)});function cs(e,t={}){return oa(ss,e,t)}function ls(e){return sa(e)}const us=Ro([`plugin`,`skill`,`mcp`]),ds=Ro([`latest-tag`,`latest-release`]),fs=Po([wo(),Mo({reason:Z().min(1),alternative:Z().optional()})]),ps=Mo({id:Z().min(1),type:us,description:Z().min(1),source:Z().min(1),subPath:Z().optional(),capabilities:Ao(Z()).optional(),keywords:Ao(Z()).optional(),author:Z().optional(),homepage:Z().optional(),versionPolicy:ds.optional(),deprecated:fs.optional()}),ms=Mo({version:Bo(1),name:Z().min(1),entries:Ao(Eo())});function $(e){let t=ms.parse(e),n=[],r=[];return t.entries.forEach((e,t)=>{let i=ps.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 hs=x(process.env.OTTO_REGISTRY_FETCH_TIMEOUT_MS,5e3),gs=x(process.env.OTTO_REGISTRY_CACHE_TTL_MS,36e5);function _s(e){return{name:`otto-official`,url:e,builtin:!0}}const vs=`otto-official-internal`;var ys=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)]}async listSourcesAsync(){let e=this.listSources(),t=ie();return t?this.readUserSources().find(e=>e.name===`otto-official-internal`)?.disabled?[e[0],{name:vs,url:t,builtin:!0,disabled:!0},...e.slice(1)]:await ne()?[e[0],{name:vs,url:t,builtin:!0},...e.slice(1)]:e:e}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 await this.listSourcesAsync())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<gs)return{...$(t.raw),sourceName:e.name,sourceUrl:e.url,stale:!1};try{let t=await(this.options.fetchImpl??fetch)(e.url,{signal:AbortSignal.timeout(hs)});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(re())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,`${bs(e)}.json`);return n(t)?JSON.parse(a(t,`utf-8`)):void 0}catch{return}}writeCache(e,t){if(!re())try{r(this.cacheDir,{recursive:!0});let n={fetchedAt:Date.now(),raw:t};f(g(this.cacheDir,`${bs(e)}.json`),JSON.stringify(n))}catch{}}};function bs(e){return e.replace(/[^\w.-]+/g,`_`)}export{lt as InstallManager,ys as RegistryClient,_s as builtinOfficialSource,ye as checkArchiveBomb,wt as checkGitUpgrades,bt as checkUpgrades,C as cleanTempDir,ve as createArchive,be as createTempDir,gt as detectUninstallTarget,_e as extractArchive,_t as listInstalledItems,$ as parseRegistry,ps as registryEntrySchema,us as registryEntryTypeSchema,ms as registrySchema,w as sanitizeSourceUrl,yt as scanInstalledVersions,vt as uninstall,S as validateExtractedPaths};
44
44
  //# sourceMappingURL=index.js.map