@anmol-srv/sigil 0.13.0 → 0.15.3

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/server.js CHANGED
@@ -1,69 +1,73 @@
1
1
  #!/usr/bin/env node
2
2
  import { createRequire as __sigilCreateRequire } from 'node:module'; const require = __sigilCreateRequire(import.meta.url);
3
- var Po=Object.defineProperty;var te=(t,e)=>()=>(t&&(e=t(t=0)),e);var nr=(t,e)=>{for(var r in e)Po(t,r,{get:e[r],enumerable:!0})};import{fileURLToPath as bl}from"node:url";import{dirname as za,join as A}from"node:path";import{existsSync as Va}from"node:fs";import{homedir as Tl}from"node:os";function Il(){let t=za(bl(import.meta.url));for(let e=0;e<10;e++){if(Va(A(t,"package.json"))&&Va(A(t,"prompts")))return t;let r=za(t);if(r===t)break;t=r}return process.cwd()}var Be,Yx,qx,Za,L,qt,be,Jx,Xx,Qx,ev,tv,rv,nv,av,Ue,Jt,Xt,Ka,ov,sv,iv,uv,fv,Wa,cv,lv,lt=te(()=>{Be=Il(),Yx=A(Be,"prompts"),qx=A(Be,"src","db","migrations"),Za=Tl(),L=A(Za,".sigil"),qt=A(L,".env"),be=A(L,"config.json"),Jx=A(L,"db"),Xx=A(L,"CLAUDE.md"),Qx=A(L,"schemas"),ev=A(L,".hook-errors.log"),tv=A(L,".last-clean-doctor"),rv=A(L,".active-session.json"),nv=A(L,".stop-cursor.json"),av=A(L,".hook-dedup.json"),Ue=A(L,"sock"),Jt=A(L,"sigild.pid"),Xt=A(L,"sigild.log"),Ka=A(L,"heartbeat.json"),ov=A(L,"gui.token"),sv=A(Be,"dist","gui"),iv=A(Be,"src","gui","web"),uv=A(L,"iroh"),fv=A(L,"identity.key"),Wa=A(Za,".claude"),cv=A(Wa,"settings.json"),lv=A(Wa,"CLAUDE.md")});var _r=te(()=>{});import{existsSync as xr,readFileSync as Xa,writeFileSync as El,renameSync as Qa,mkdirSync as Sl,chmodSync as Ol,unlinkSync as hv}from"node:fs";import{dirname as wl}from"node:path";function Qt(){return{schemaVersion:vr,device:{id:null},database:{mode:null,url:null,host:"localhost",port:5432,name:"sigil",user:"sigil_app",password:null},llm:{provider:null,model:null,apiKey:null,host:null},embedding:{provider:null,model:null,apiKey:null,host:null},identity:{name:null},setup:{complete:!1,steps:{}}}}function dt(t){return t!==null&&typeof t=="object"&&!Array.isArray(t)}function br(t,e){if(!dt(e))return e;let r=Array.isArray(t)?[...t]:{...t};for(let[n,a]of Object.entries(e))r[n]=dt(a)&&dt(r[n])?br(r[n],a):a;return r}function Tr(){if(!xr(be))return{};try{return JSON.parse(Xa(be,"utf8"))||{}}catch{return{}}}function kl(t){let e=t,r=Number(e.schemaVersion)||1;for(;r<vr;){let n=r+1,a=Al[n];e=a?a(e):{...e,schemaVersion:n},r=n}return e}function er(t){let e=Qt(),r={};for(let n of Object.keys(e)){if(!(n in t))continue;if(!dt(e[n])){r[n]=t[n];continue}let a={};for(let o of Object.keys(e[n]))t[n]&&o in t[n]&&(a[o]=t[n][o]);n==="setup"&&dt(t.setup?.steps)&&(a.steps=t.setup.steps),r[n]=a}return r}function eo(t){Sl(wl(be),{recursive:!0});let e=`${be}.tmp`;El(e,`${JSON.stringify(t,null,2)}
4
- `,{mode:384}),Qa(e,be);try{Ol(be,384)}catch{}}function Rl(t,e){let r={};if(!dt(e))throw new Error(`config patch for "${t}" must be an object`);if(t==="database"&&("mode"in e&&e.mode!==null&&!Ya.includes(e.mode)&&(r.mode=`must be one of ${Ya.join(", ")}`),"port"in e&&e.port!=null&&!Number.isInteger(Number(e.port))&&(r.port="must be an integer"),"url"in e&&e.url!=null&&typeof e.url!="string"&&(r.url="must be a string")),Object.keys(r).length){let n=new Error(`invalid config for "${t}": ${JSON.stringify(r)}`);throw n.code="invalid_config",n.errors=r,n}}function Ll(t){if(!xr(t))return null;let e={};for(let r of Xa(t,"utf8").split(`
5
- `)){let n=r.match(/^\s*([A-Z_][A-Z0-9_]*)\s*=\s*(.*)$/i);if(!n)continue;let a=n[2].trim();(a.startsWith('"')&&a.endsWith('"')||a.startsWith("'")&&a.endsWith("'"))&&(a=a.slice(1,-1)),e[n[1]]=a}return e}function Cl(t){let e={},r={};if(t.SIGIL_DATABASE_URL||t.DATABASE_URL?(r.mode="url",r.url=t.SIGIL_DATABASE_URL||t.DATABASE_URL):(t.SIGIL_DB_HOST||t.SIGIL_DB_NAME||t.SIGIL_DB_PASSWORD)&&(r.mode="local",t.SIGIL_DB_HOST&&(r.host=t.SIGIL_DB_HOST),t.SIGIL_DB_PORT&&(r.port=Number(t.SIGIL_DB_PORT)||5432),t.SIGIL_DB_NAME&&(r.name=t.SIGIL_DB_NAME),t.SIGIL_DB_USER&&(r.user=t.SIGIL_DB_USER),t.SIGIL_DB_PASSWORD&&(r.password=t.SIGIL_DB_PASSWORD)),Object.keys(r).length&&(e.database=r),t.LLM_PROVIDER){let n={provider:t.LLM_PROVIDER},a={anthropic:t.ANTHROPIC_API_KEY,openai:t.OPENAI_API_KEY,openrouter:t.OPENROUTER_API_KEY}[t.LLM_PROVIDER];a&&(n.apiKey=a);let o={openai:t.LLM_OPENAI_MODEL,openrouter:t.LLM_OPENROUTER_MODEL,ollama:t.LLM_OLLAMA_MODEL,"claude-cli":t.LLM_CLI_MODEL}[t.LLM_PROVIDER];o&&(n.model=o),t.LLM_PROVIDER==="ollama"&&(t.LLM_OLLAMA_HOST||t.OLLAMA_HOST)&&(n.host=t.LLM_OLLAMA_HOST||t.OLLAMA_HOST),e.llm=n}if(t.EMBEDDING_PROVIDER){let n={provider:t.EMBEDDING_PROVIDER};t.EMBEDDING_MODEL&&(n.model=t.EMBEDDING_MODEL);let a={openai:t.OPENAI_API_KEY,voyage:t.VOYAGE_API_KEY,openrouter:t.OPENROUTER_API_KEY}[t.EMBEDDING_PROVIDER];a&&(n.apiKey=a),t.EMBEDDING_PROVIDER==="ollama"&&t.OLLAMA_HOST&&(n.host=t.OLLAMA_HOST),e.embedding=n}return t.SIGIL_SETUP_COMPLETE==="true"&&(e.setup={complete:!0}),e}function Nl(){if(!qa){qa=!0;try{let t=Ll(qt);if(!t)return;let e=Cl(t),r=er(Tr()),n={database:!!r.database?.mode,llm:!!r.llm?.provider,embedding:!!r.embedding?.provider,setup:!!r.setup?.complete};for(let[a,o]of Object.entries(e))if(!n[a])try{Ml(a,o)}catch{}try{Qa(qt,`${qt}.migrated`)}catch{}}catch{}}}function Pl(){Nl();let t=Tr(),e=kl(t);return xr(be)&&e.schemaVersion!==t.schemaVersion&&eo(er(e)),It=br(Qt(),er(e)),It}function to(){return It||Pl()}function Ml(t,e){if(!(t in Qt()))throw new Error(`unknown config section: ${t}`);Rl(t,e);let r=er(Tr());return r.schemaVersion=vr,r[t]={...r[t]||{},...e},eo(r),It=br(Qt(),r),It}var vr,Ya,Al,It,qa,ro=te(()=>{lt();_r();vr=1,Ya=["local","docker","url"];Al={},It=null;qa=!1});var ao={};nr(ao,{default:()=>$l});var C,N,Ir,tr,Er,no,Dl,$l,oo=te(()=>{ro();_r();C=(t,e)=>process.env[t]??e,N=()=>to(),Ir=t=>N().llm.provider===t&&N().llm.apiKey||"",tr=t=>N().llm.provider===t&&N().llm.model||"",Er=t=>N().embedding.provider===t&&N().embedding.apiKey||"",no=C("SIGIL_DB_TYPE","postgres");if(no!=="postgres")throw new Error(`SIGIL_DB_TYPE=${no} is no longer supported. Sigil 0.10.0+ is Postgres-only.
3
+ var zo=Object.defineProperty;var W=(t,e)=>()=>(t&&(e=t(t=0)),e);var Ze=(t,e)=>{for(var r in e)zo(t,r,{get:e[r],enumerable:!0})};import{fileURLToPath as Ll}from"node:url";import{dirname as Xa,join as A}from"node:path";import{existsSync as Qa}from"node:fs";import{homedir as Cl}from"node:os";function Nl(){let t=Xa(Ll(import.meta.url));for(let e=0;e<10;e++){if(Qa(A(t,"package.json"))&&Qa(A(t,"prompts")))return t;let r=Xa(t);if(r===t)break;t=r}return process.cwd()}var Ue,gv,yv,eo,C,ar,ee,_v,xv,vv,bv,Tv,Iv,Ev,Sv,Fe,or,sr,to,wv,Ov,Av,kv,Rv,ro,Lv,Cv,ht=W(()=>{Ue=Nl(),gv=A(Ue,"prompts"),yv=A(Ue,"src","db","migrations"),eo=Cl(),C=A(eo,".sigil"),ar=A(C,".env"),ee=A(C,"config.json"),_v=A(C,"db"),xv=A(C,"CLAUDE.md"),vv=A(C,"schemas"),bv=A(C,".hook-errors.log"),Tv=A(C,".last-clean-doctor"),Iv=A(C,".active-session.json"),Ev=A(C,".stop-cursor.json"),Sv=A(C,".hook-dedup.json"),Fe=A(C,"sock"),or=A(C,"sigild.pid"),sr=A(C,"sigild.log"),to=A(C,"heartbeat.json"),wv=A(C,"gui.token"),Ov=A(Ue,"dist","gui"),Av=A(Ue,"src","gui","web"),kv=A(C,"iroh"),Rv=A(C,"identity.key"),ro=A(eo,".claude"),Lv=A(ro,"settings.json"),Cv=A(ro,"CLAUDE.md")});var He,ir=W(()=>{He=1024});var co={};Ze(co,{CONFIG_SCHEMA_VERSION:()=>Rt,EMBEDDING_DIM:()=>He,ensureDeviceId:()=>Kl,getConfig:()=>_t,isSetupComplete:()=>Jl,loadConfig:()=>io,markSetupComplete:()=>ql,patchConfig:()=>Lt,resetConfig:()=>Xl,setStepStatus:()=>Yl});import{existsSync as cr,readFileSync as oo,writeFileSync as Pl,renameSync as so,mkdirSync as Ml,chmodSync as $l,unlinkSync as Dl}from"node:fs";import{dirname as jl}from"node:path";import{randomUUID as Gl}from"node:crypto";function kt(){return{schemaVersion:Rt,device:{id:null},database:{mode:null,url:null,host:"localhost",port:5432,name:"sigil",user:"sigil_app",password:null},llm:{provider:null,model:null,apiKey:null,host:null},embedding:{provider:null,model:null,apiKey:null,host:null},identity:{name:null},setup:{complete:!1,steps:{}}}}function gt(t){return t!==null&&typeof t=="object"&&!Array.isArray(t)}function ur(t,e){if(!gt(e))return e;let r=Array.isArray(t)?[...t]:{...t};for(let[n,a]of Object.entries(e))r[n]=gt(a)&&gt(r[n])?ur(r[n],a):a;return r}function yt(){if(!cr(ee))return{};try{return JSON.parse(oo(ee,"utf8"))||{}}catch{return{}}}function Fl(t){let e=t,r=Number(e.schemaVersion)||1;for(;r<Rt;){let n=r+1,a=Ul[n];e=a?a(e):{...e,schemaVersion:n},r=n}return e}function ze(t){let e=kt(),r={};for(let n of Object.keys(e)){if(!(n in t))continue;if(!gt(e[n])){r[n]=t[n];continue}let a={};for(let o of Object.keys(e[n]))t[n]&&o in t[n]&&(a[o]=t[n][o]);n==="setup"&&gt(t.setup?.steps)&&(a.steps=t.setup.steps),r[n]=a}return r}function Or(t){Ml(jl(ee),{recursive:!0});let e=`${ee}.tmp`;Pl(e,`${JSON.stringify(t,null,2)}
4
+ `,{mode:384}),so(e,ee);try{$l(ee,384)}catch{}}function Hl(t,e){let r={};if(!gt(e))throw new Error(`config patch for "${t}" must be an object`);if(t==="database"&&("mode"in e&&e.mode!==null&&!no.includes(e.mode)&&(r.mode=`must be one of ${no.join(", ")}`),"port"in e&&e.port!=null&&!Number.isInteger(Number(e.port))&&(r.port="must be an integer"),"url"in e&&e.url!=null&&typeof e.url!="string"&&(r.url="must be a string")),Object.keys(r).length){let n=new Error(`invalid config for "${t}": ${JSON.stringify(r)}`);throw n.code="invalid_config",n.errors=r,n}}function zl(t){if(!cr(t))return null;let e={};for(let r of oo(t,"utf8").split(`
5
+ `)){let n=r.match(/^\s*([A-Z_][A-Z0-9_]*)\s*=\s*(.*)$/i);if(!n)continue;let a=n[2].trim();(a.startsWith('"')&&a.endsWith('"')||a.startsWith("'")&&a.endsWith("'"))&&(a=a.slice(1,-1)),e[n[1]]=a}return e}function Vl(t){let e={},r={};if(t.SIGIL_DATABASE_URL||t.DATABASE_URL?(r.mode="url",r.url=t.SIGIL_DATABASE_URL||t.DATABASE_URL):(t.SIGIL_DB_HOST||t.SIGIL_DB_NAME||t.SIGIL_DB_PASSWORD)&&(r.mode="local",t.SIGIL_DB_HOST&&(r.host=t.SIGIL_DB_HOST),t.SIGIL_DB_PORT&&(r.port=Number(t.SIGIL_DB_PORT)||5432),t.SIGIL_DB_NAME&&(r.name=t.SIGIL_DB_NAME),t.SIGIL_DB_USER&&(r.user=t.SIGIL_DB_USER),t.SIGIL_DB_PASSWORD&&(r.password=t.SIGIL_DB_PASSWORD)),Object.keys(r).length&&(e.database=r),t.LLM_PROVIDER){let n={provider:t.LLM_PROVIDER},a={anthropic:t.ANTHROPIC_API_KEY,openai:t.OPENAI_API_KEY,openrouter:t.OPENROUTER_API_KEY}[t.LLM_PROVIDER];a&&(n.apiKey=a);let o={openai:t.LLM_OPENAI_MODEL,openrouter:t.LLM_OPENROUTER_MODEL,ollama:t.LLM_OLLAMA_MODEL,"claude-cli":t.LLM_CLI_MODEL}[t.LLM_PROVIDER];o&&(n.model=o),t.LLM_PROVIDER==="ollama"&&(t.LLM_OLLAMA_HOST||t.OLLAMA_HOST)&&(n.host=t.LLM_OLLAMA_HOST||t.OLLAMA_HOST),e.llm=n}if(t.EMBEDDING_PROVIDER){let n={provider:t.EMBEDDING_PROVIDER};t.EMBEDDING_MODEL&&(n.model=t.EMBEDDING_MODEL);let a={openai:t.OPENAI_API_KEY,voyage:t.VOYAGE_API_KEY,openrouter:t.OPENROUTER_API_KEY}[t.EMBEDDING_PROVIDER];a&&(n.apiKey=a),t.EMBEDDING_PROVIDER==="ollama"&&t.OLLAMA_HOST&&(n.host=t.OLLAMA_HOST),e.embedding=n}return t.SIGIL_SETUP_COMPLETE==="true"&&(e.setup={complete:!0}),e}function Zl(){if(!ao){ao=!0;try{let t=zl(ar);if(!t)return;let e=Vl(t),r=ze(yt()),n={database:!!r.database?.mode,llm:!!r.llm?.provider,embedding:!!r.embedding?.provider,setup:!!r.setup?.complete};for(let[a,o]of Object.entries(e))if(!n[a])try{Lt(a,o)}catch{}try{so(ar,`${ar}.migrated`)}catch{}}catch{}}}function io(){Zl();let t=yt(),e=Fl(t);return cr(ee)&&e.schemaVersion!==t.schemaVersion&&Or(ze(e)),Te=ur(kt(),ze(e)),Wl(),Te}function Wl(){let t=Te?.setup?.steps;if(!t)return;let e=Object.entries(t).filter(([,a])=>a==="active").map(([a])=>a);if(!e.length)return;let r=ze(yt()),n={...r.setup?.steps||{}};for(let a of e)n[a]="pending";Or({...r,schemaVersion:Rt,setup:{...r.setup||{},steps:n}}),Te=ur(kt(),ze(yt()))}function _t(){return Te||io()}function Lt(t,e){if(!(t in kt()))throw new Error(`unknown config section: ${t}`);Hl(t,e);let r=ze(yt());return r.schemaVersion=Rt,r[t]={...r[t]||{},...e},Or(r),Te=ur(kt(),r),Te}function Kl(){let t=_t();if(t.device?.id)return t.device.id;let e=Gl();return Lt("device",{id:e}),e}function Yl(t,e){if(!Bl.includes(e))throw new Error(`invalid step status: ${e}`);let r=ze(yt()),n={...r.setup?.steps||{},[t]:e};return Lt("setup",{...r.setup||{},steps:n})}function ql(t=!0){return Lt("setup",{complete:!!t})}function Jl(){return!!_t().setup?.complete}function Xl(){try{cr(ee)&&Dl(ee)}catch{}return Te=null,_t()}var Rt,no,Bl,Ul,Te,ao,Ar=W(()=>{ht();ir();Rt=1,no=["local","docker","url"],Bl=["pending","active","done","error"];Ul={},Te=null;ao=!1});var fo={};Ze(fo,{default:()=>ed});var N,P,kr,fr,Rr,uo,Ql,ed,lo=W(()=>{Ar();ir();N=(t,e)=>process.env[t]??e,P=()=>_t(),kr=t=>P().llm.provider===t&&P().llm.apiKey||"",fr=t=>P().llm.provider===t&&P().llm.model||"",Rr=t=>P().embedding.provider===t&&P().embedding.apiKey||"",uo=N("SIGIL_DB_TYPE","postgres");if(uo!=="postgres")throw new Error(`SIGIL_DB_TYPE=${uo} is no longer supported. Sigil 0.10.0+ is Postgres-only.
6
6
  PGlite was deprecated; existing PGlite data at ~/.sigil/db is preserved but unreachable from this version.
7
7
  Set SIGIL_DB_TYPE=postgres in ~/.sigil/.env and configure SIGIL_DB_HOST / PORT / NAME / USER / PASSWORD.
8
- Run \`sigil init\` for an interactive setup.`);Dl={db:{type:"postgres",get url(){return process.env.SIGIL_DATABASE_URL||process.env.DATABASE_URL||N().database.url||null},get host(){return process.env.SIGIL_DB_HOST||N().database.host||"localhost"},get port(){return Number(process.env.SIGIL_DB_PORT||N().database.port||5432)},get database(){return process.env.SIGIL_DB_NAME||N().database.name||"sigil"},get user(){return process.env.SIGIL_DB_USER||N().database.user||"sigil_app"},get password(){return process.env.SIGIL_DB_PASSWORD||N().database.password||""}},embedding:{get provider(){return process.env.EMBEDDING_PROVIDER||N().embedding.provider||""},get model(){return process.env.EMBEDDING_MODEL||N().embedding.model||"nomic-embed-text"},get dimensions(){return 1024},get ollamaHost(){return process.env.OLLAMA_HOST||(N().embedding.provider==="ollama"?N().embedding.host:"")||"http://localhost:11434"},get openaiApiKey(){return process.env.OPENAI_API_KEY||Er("openai")},get voyageApiKey(){return process.env.VOYAGE_API_KEY||Er("voyage")},get openrouterApiKey(){return process.env.OPENROUTER_API_KEY||Er("openrouter")},openrouterBaseUrl:process.env.EMBEDDING_OPENROUTER_BASE_URL||process.env.LLM_OPENROUTER_BASE_URL||"",openrouterReferer:process.env.EMBEDDING_OPENROUTER_REFERER||process.env.LLM_OPENROUTER_REFERER||"https://github.com/Anmol-Srv/sigil",openrouterTitle:process.env.EMBEDDING_OPENROUTER_TITLE||process.env.LLM_OPENROUTER_TITLE||"Sigil"},llm:{get provider(){return process.env.LLM_PROVIDER||N().llm.provider||""},get openaiApiKey(){return process.env.OPENAI_API_KEY||Ir("openai")},get openaiModel(){return process.env.LLM_OPENAI_MODEL||tr("openai")||"gpt-4o-mini"},get ollamaHost(){return process.env.LLM_OLLAMA_HOST||process.env.OLLAMA_HOST||(N().llm.provider==="ollama"?N().llm.host:"")||"http://localhost:11434"},get ollamaModel(){return process.env.LLM_OLLAMA_MODEL||tr("ollama")||"qwen2.5:7b"},get cliModel(){return process.env.LLM_CLI_MODEL||tr("claude-cli")||"haiku"},get cliPath(){return process.env.LLM_CLI_PATH||""},get apiKey(){return process.env.ANTHROPIC_API_KEY||Ir("anthropic")},get openrouterApiKey(){return process.env.OPENROUTER_API_KEY||Ir("openrouter")},get openrouterModel(){return process.env.LLM_OPENROUTER_MODEL||tr("openrouter")||"google/gemini-flash-latest"},get openrouterBaseUrl(){return process.env.LLM_OPENROUTER_BASE_URL||""},get openrouterReferer(){return process.env.LLM_OPENROUTER_REFERER||"https://github.com/Anmol-Srv/sigil"},get openrouterTitle(){return process.env.LLM_OPENROUTER_TITLE||"Sigil"},get extractionModel(){return process.env.LLM_EXTRACTION_MODEL||""},get decisionModel(){return process.env.LLM_DECISION_MODEL||""},get entityModel(){return process.env.LLM_ENTITY_MODEL||""},get maxRetries(){return Number(process.env.LLM_MAX_RETRIES)||3},get cliTimeout(){return Number(process.env.LLM_CLI_TIMEOUT)||12e4}},output:{storage:process.env.OUTPUT_STORAGE||"local",dir:process.env.OUTPUT_DIR||"./output",s3:{endpoint:process.env.S3_ENDPOINT||"",bucket:process.env.S3_BUCKET||"",region:process.env.S3_REGION||"us-east-1",accessKey:process.env.S3_ACCESS_KEY||"",secretKey:process.env.S3_SECRET_KEY||"",publicUrl:process.env.S3_PUBLIC_URL||""}},server:{port:Number(process.env.PORT)||4e3,host:process.env.HOST||"0.0.0.0",logLevel:process.env.LOG_LEVEL||"info"},http:{enabled:C("SIGIL_HTTP_ENABLED","true")!=="false",host:C("SIGIL_HTTP_HOST","127.0.0.1"),port:Number(C("SIGIL_HTTP_PORT",7777))},network:{mode:C("SIGIL_MODE","solo"),enabled:C("SIGIL_NETWORK_ENABLED",null)===null?C("SIGIL_MODE","solo")!=="solo":C("SIGIL_NETWORK_ENABLED","false")!=="false",masterNodeId:C("SIGIL_MASTER_NODE_ID","")||null},defaults:{namespace:process.env.DEFAULT_NAMESPACE||"default"},memory:{skipThreshold:Number(process.env.MEMORY_SKIP_THRESHOLD)||.88,ambiguousThreshold:Number(process.env.MEMORY_AMBIGUOUS_THRESHOLD)||.78,minFactSimilarity:Number(process.env.MEMORY_MIN_FACT_SIMILARITY)||.45,injectionFloor:Number(process.env.MEMORY_INJECTION_FLOOR)||.6},search:{synthesize:C("SIGIL_SYNTHESIZE","true")!=="false",synthesizeModel:C("SIGIL_SYNTH_MODEL","")},ingest:{eagerExtract:C("SIGIL_EAGER_EXTRACT","true")!=="false"},hebbian:{entity:{enabled:C("SIGIL_HEBBIAN_ENTITY_ENABLED",null,"true")!=="false",eta:Number(C("SIGIL_HEBBIAN_ENTITY_ETA",null,1)),cap:Number(C("SIGIL_HEBBIAN_ENTITY_CAP",null,50)),halfLifeDays:Number(C("SIGIL_HEBBIAN_ENTITY_HALF_LIFE_DAYS",null,30)),minEffective:Number(C("SIGIL_HEBBIAN_ENTITY_MIN_EFFECTIVE",null,.5)),rrfWeight:Number(C("SIGIL_HEBBIAN_ENTITY_RRF_WEIGHT",null,.3)),maxWriteEntities:Number(C("SIGIL_HEBBIAN_ENTITY_MAX_WRITE",null,12)),expandPerSeed:Number(C("SIGIL_HEBBIAN_ENTITY_EXPAND_PER_SEED",null,3))}}},$l=Dl});import{readFile as so,writeFile as Iv,unlink as io,mkdir as Ev}from"node:fs/promises";import{existsSync as uo}from"node:fs";function jl(t){if(!t||!Number.isFinite(t))return!1;try{return process.kill(t,0),!0}catch(e){return e.code==="EPERM"}}async function Gl(){if(!uo(Jt))return null;try{let t=(await so(Jt,"utf8")).trim(),e=Number(t);return Number.isFinite(e)?e:null}catch{return null}}async function Bl(){try{await io(Jt)}catch{}}async function Ul(){try{await io(Ue)}catch{}}async function Fl(){try{let t=JSON.parse(await so(Ka,"utf8"));return Number.isFinite(t?.pid)?t.pid:null}catch{return null}}async function Hl(){try{let{default:t}=await Promise.resolve().then(()=>(oo(),ao));if(!t.http.enabled)return!1;let{host:e,port:r}=t.http,n=new AbortController,a=setTimeout(()=>n.abort(),500);try{return(await fetch(`http://${e}:${r}/healthz`,{signal:n.signal})).ok}finally{clearTimeout(a)}}catch{return!1}}async function fo(){let t=await Gl();return t&&jl(t)?t:await Hl()?await Fl()??"unknown":(t&&await Bl(),uo(Ue)&&await Ul(),null)}var co=te(()=>{lt()});import{existsSync as zl}from"node:fs";import{dirname as Vl,join as Sr}from"node:path";import{fileURLToPath as Zl}from"node:url";function lo(){let t=[Sr(Be,"dist","daemon.js"),Sr(Be,"src","daemon","index.js"),Sr(Vl(Zl(import.meta.url)),"..","daemon","index.js")];for(let e of t)if(zl(e))return e;throw new Error("cannot locate daemon entry point (looked in dist/ and src/daemon/)")}var po=te(()=>{lt()});import{connect as Kl}from"node:net";import{randomUUID as Wl}from"node:crypto";function rr({path:t=Ue,timeoutMs:e=3e4}={}){return new Promise((r,n)=>{let a=Kl(t),o=new Map,s="",i=!1;a.setEncoding("utf8"),a.once("connect",()=>{a.off("error",u),r(f())});function u(l){n(l)}a.once("error",u),a.on("data",l=>{s+=l;let m;for(;(m=s.indexOf(`
9
- `))!==-1;){let g=s.slice(0,m);if(s=s.slice(m+1),!g.trim())continue;let x;try{x=JSON.parse(g)}catch{continue}let w=o.get(x.id);w&&(o.delete(x.id),clearTimeout(w.timer),x.ok?w.resolve(x):w.reject(new Or(x.error||{})))}}),a.on("close",()=>{i=!0;for(let[,l]of o)clearTimeout(l.timer),l.reject(new Error("daemon connection closed"));o.clear()}),a.on("error",()=>{});function f(){return{call(l,m){if(i)return Promise.reject(new Error("client is closed"));let g=Wl(),x=process.env.SIGIL_AGENT||null,w=JSON.stringify({id:g,method:l,params:m,agent:x})+`
10
- `;return new Promise((E,S)=>{let M=setTimeout(()=>{o.delete(g)&&S(new Error(`rpc timeout after ${e}ms: ${l}`))},e);o.set(g,{resolve:E,reject:S,timer:M}),a.write(w)})},close(){return new Promise(l=>{if(i)return l();a.end(()=>l())})}}}})}var Or,mo=te(()=>{lt();Or=class extends Error{constructor({code:e,message:r,stack:n}){super(r||e||"rpc error"),this.name="SigilRpcError",this.code=e||"handler_error",n&&(this.remoteStack=n)}}});import{spawn as Yl}from"node:child_process";import{existsSync as ql,openSync as ho,closeSync as go,mkdirSync as Jl}from"node:fs";import{setTimeout as Xl}from"node:timers/promises";async function _o({quiet:t=!1}={}){return await xo()?rr():(t||process.stderr.write(`[sigil] daemon not running, starting it...
11
- `),await td(),await rd(),rr())}async function xo(){if(!ql(Ue))return!1;try{let t=await rr({timeoutMs:1e3});return await t.call("ping",{}),await t.close(),!0}catch{return!1}}async function td(){Jl(L,{recursive:!0}),await fo();let t=lo(),e=ho(Xt,"a"),r=ho(Xt,"a");Yl(process.execPath,[t],{detached:!0,stdio:["ignore",e,r],env:{...process.env,SIGIL_DAEMON_AUTOSPAWN:"1"}}).unref();try{go(e)}catch{}try{go(r)}catch{}}async function rd(){let t=Date.now()+yo,e=Ql;for(;Date.now()<t;){if(await xo())return;await Xl(e),e=Math.min(e*2,ed)}throw new Error(`daemon did not become ready within ${yo}ms \u2014 check ${Xt}`)}var yo,Ql,ed,vo=te(()=>{lt();co();po();mo();yo=5e3,Ql=25,ed=400});var To={};nr(To,{closeDaemonConnection:()=>od,daemonCall:()=>P});async function bo(){return mt||(pt||(pt=_o({quiet:!0}).then(t=>(mt=t,t)).catch(t=>{throw pt=null,t})),pt)}function ad(t){return t?t.code&&nd.has(t.code)?!0:/^daemon connection closed/i.test(t.message||""):!1}async function P(t,e){let r=await bo();try{let{data:n}=await r.call(t,e??{});return n}catch(n){if(ad(n)){mt=null,pt=null;let a=await bo(),{data:o}=await a.call(t,e??{});return o}throw n}}async function od(){let t=mt;mt=null,pt=null,t&&await t.close()}var pt,mt,nd,Y=te(()=>{vo();pt=null,mt=null;nd=new Set(["ECONNREFUSED","ENOENT","EPIPE","ECONNRESET"])});import{config as cd}from"dotenv";import{resolve as wr,dirname as No}from"node:path";import{fileURLToPath as ld}from"node:url";import{existsSync as dd}from"node:fs";import"dotenv/config";import{McpServer as id}from"@modelcontextprotocol/sdk/server/mcp.js";import{StdioServerTransport as ud}from"@modelcontextprotocol/sdk/server/stdio.js";var y={};nr(y,{BRAND:()=>ss,DIRTY:()=>Te,EMPTY_PATH:()=>jo,INVALID:()=>_,NEVER:()=>zs,OK:()=>j,ParseStatus:()=>$,Schema:()=>T,ZodAny:()=>le,ZodArray:()=>oe,ZodBigInt:()=>Ee,ZodBoolean:()=>Se,ZodBranded:()=>yt,ZodCatch:()=>De,ZodDate:()=>Oe,ZodDefault:()=>Me,ZodDiscriminatedUnion:()=>At,ZodEffects:()=>V,ZodEnum:()=>Ne,ZodError:()=>B,ZodFirstPartyTypeKind:()=>v,ZodFunction:()=>Rt,ZodIntersection:()=>Re,ZodIssueCode:()=>c,ZodLazy:()=>Le,ZodLiteral:()=>Ce,ZodMap:()=>We,ZodNaN:()=>qe,ZodNativeEnum:()=>Pe,ZodNever:()=>Z,ZodNull:()=>Ae,ZodNullable:()=>X,ZodNumber:()=>Ie,ZodObject:()=>U,ZodOptional:()=>H,ZodParsedType:()=>p,ZodPipeline:()=>_t,ZodPromise:()=>de,ZodReadonly:()=>$e,ZodRecord:()=>kt,ZodSchema:()=>T,ZodSet:()=>Ye,ZodString:()=>ce,ZodSymbol:()=>Ze,ZodTransformer:()=>V,ZodTuple:()=>J,ZodType:()=>T,ZodUndefined:()=>we,ZodUnion:()=>ke,ZodUnknown:()=>ae,ZodVoid:()=>Ke,addIssueToContext:()=>d,any:()=>hs,array:()=>xs,bigint:()=>cs,boolean:()=>jr,coerce:()=>Hs,custom:()=>Mr,date:()=>ls,datetimeRegex:()=>Nr,defaultErrorMap:()=>re,discriminatedUnion:()=>Is,effect:()=>Ms,enum:()=>Cs,function:()=>ks,getErrorMap:()=>He,getParsedType:()=>q,instanceof:()=>us,intersection:()=>Es,isAborted:()=>Ot,isAsync:()=>ze,isDirty:()=>wt,isValid:()=>fe,late:()=>is,lazy:()=>Rs,literal:()=>Ls,makeIssue:()=>gt,map:()=>ws,nan:()=>fs,nativeEnum:()=>Ns,never:()=>ys,null:()=>ms,nullable:()=>$s,number:()=>$r,object:()=>vs,objectUtil:()=>ar,oboolean:()=>Fs,onumber:()=>Us,optional:()=>Ds,ostring:()=>Bs,pipeline:()=>Gs,preprocess:()=>js,promise:()=>Ps,quotelessJson:()=>Mo,record:()=>Os,set:()=>As,setErrorMap:()=>$o,strictObject:()=>bs,string:()=>Dr,symbol:()=>ds,transformer:()=>Ms,tuple:()=>Ss,undefined:()=>ps,union:()=>Ts,unknown:()=>gs,util:()=>I,void:()=>_s});var I;(function(t){t.assertEqual=a=>{};function e(a){}t.assertIs=e;function r(a){throw new Error}t.assertNever=r,t.arrayToEnum=a=>{let o={};for(let s of a)o[s]=s;return o},t.getValidEnumValues=a=>{let o=t.objectKeys(a).filter(i=>typeof a[a[i]]!="number"),s={};for(let i of o)s[i]=a[i];return t.objectValues(s)},t.objectValues=a=>t.objectKeys(a).map(function(o){return a[o]}),t.objectKeys=typeof Object.keys=="function"?a=>Object.keys(a):a=>{let o=[];for(let s in a)Object.prototype.hasOwnProperty.call(a,s)&&o.push(s);return o},t.find=(a,o)=>{for(let s of a)if(o(s))return s},t.isInteger=typeof Number.isInteger=="function"?a=>Number.isInteger(a):a=>typeof a=="number"&&Number.isFinite(a)&&Math.floor(a)===a;function n(a,o=" | "){return a.map(s=>typeof s=="string"?`'${s}'`:s).join(o)}t.joinValues=n,t.jsonStringifyReplacer=(a,o)=>typeof o=="bigint"?o.toString():o})(I||(I={}));var ar;(function(t){t.mergeShapes=(e,r)=>({...e,...r})})(ar||(ar={}));var p=I.arrayToEnum(["string","nan","number","integer","float","boolean","date","bigint","symbol","function","undefined","null","array","object","unknown","promise","void","never","map","set"]),q=t=>{switch(typeof t){case"undefined":return p.undefined;case"string":return p.string;case"number":return Number.isNaN(t)?p.nan:p.number;case"boolean":return p.boolean;case"function":return p.function;case"bigint":return p.bigint;case"symbol":return p.symbol;case"object":return Array.isArray(t)?p.array:t===null?p.null:t.then&&typeof t.then=="function"&&t.catch&&typeof t.catch=="function"?p.promise:typeof Map<"u"&&t instanceof Map?p.map:typeof Set<"u"&&t instanceof Set?p.set:typeof Date<"u"&&t instanceof Date?p.date:p.object;default:return p.unknown}};var c=I.arrayToEnum(["invalid_type","invalid_literal","custom","invalid_union","invalid_union_discriminator","invalid_enum_value","unrecognized_keys","invalid_arguments","invalid_return_type","invalid_date","invalid_string","too_small","too_big","invalid_intersection_types","not_multiple_of","not_finite"]),Mo=t=>JSON.stringify(t,null,2).replace(/"([^"]+)":/g,"$1:"),B=class t extends Error{get errors(){return this.issues}constructor(e){super(),this.issues=[],this.addIssue=n=>{this.issues=[...this.issues,n]},this.addIssues=(n=[])=>{this.issues=[...this.issues,...n]};let r=new.target.prototype;Object.setPrototypeOf?Object.setPrototypeOf(this,r):this.__proto__=r,this.name="ZodError",this.issues=e}format(e){let r=e||function(o){return o.message},n={_errors:[]},a=o=>{for(let s of o.issues)if(s.code==="invalid_union")s.unionErrors.map(a);else if(s.code==="invalid_return_type")a(s.returnTypeError);else if(s.code==="invalid_arguments")a(s.argumentsError);else if(s.path.length===0)n._errors.push(r(s));else{let i=n,u=0;for(;u<s.path.length;){let f=s.path[u];u===s.path.length-1?(i[f]=i[f]||{_errors:[]},i[f]._errors.push(r(s))):i[f]=i[f]||{_errors:[]},i=i[f],u++}}};return a(this),n}static assert(e){if(!(e instanceof t))throw new Error(`Not a ZodError: ${e}`)}toString(){return this.message}get message(){return JSON.stringify(this.issues,I.jsonStringifyReplacer,2)}get isEmpty(){return this.issues.length===0}flatten(e=r=>r.message){let r={},n=[];for(let a of this.issues)if(a.path.length>0){let o=a.path[0];r[o]=r[o]||[],r[o].push(e(a))}else n.push(e(a));return{formErrors:n,fieldErrors:r}}get formErrors(){return this.flatten()}};B.create=t=>new B(t);var Do=(t,e)=>{let r;switch(t.code){case c.invalid_type:t.received===p.undefined?r="Required":r=`Expected ${t.expected}, received ${t.received}`;break;case c.invalid_literal:r=`Invalid literal value, expected ${JSON.stringify(t.expected,I.jsonStringifyReplacer)}`;break;case c.unrecognized_keys:r=`Unrecognized key(s) in object: ${I.joinValues(t.keys,", ")}`;break;case c.invalid_union:r="Invalid input";break;case c.invalid_union_discriminator:r=`Invalid discriminator value. Expected ${I.joinValues(t.options)}`;break;case c.invalid_enum_value:r=`Invalid enum value. Expected ${I.joinValues(t.options)}, received '${t.received}'`;break;case c.invalid_arguments:r="Invalid function arguments";break;case c.invalid_return_type:r="Invalid function return type";break;case c.invalid_date:r="Invalid date";break;case c.invalid_string:typeof t.validation=="object"?"includes"in t.validation?(r=`Invalid input: must include "${t.validation.includes}"`,typeof t.validation.position=="number"&&(r=`${r} at one or more positions greater than or equal to ${t.validation.position}`)):"startsWith"in t.validation?r=`Invalid input: must start with "${t.validation.startsWith}"`:"endsWith"in t.validation?r=`Invalid input: must end with "${t.validation.endsWith}"`:I.assertNever(t.validation):t.validation!=="regex"?r=`Invalid ${t.validation}`:r="Invalid";break;case c.too_small:t.type==="array"?r=`Array must contain ${t.exact?"exactly":t.inclusive?"at least":"more than"} ${t.minimum} element(s)`:t.type==="string"?r=`String must contain ${t.exact?"exactly":t.inclusive?"at least":"over"} ${t.minimum} character(s)`:t.type==="number"?r=`Number must be ${t.exact?"exactly equal to ":t.inclusive?"greater than or equal to ":"greater than "}${t.minimum}`:t.type==="bigint"?r=`Number must be ${t.exact?"exactly equal to ":t.inclusive?"greater than or equal to ":"greater than "}${t.minimum}`:t.type==="date"?r=`Date must be ${t.exact?"exactly equal to ":t.inclusive?"greater than or equal to ":"greater than "}${new Date(Number(t.minimum))}`:r="Invalid input";break;case c.too_big:t.type==="array"?r=`Array must contain ${t.exact?"exactly":t.inclusive?"at most":"less than"} ${t.maximum} element(s)`:t.type==="string"?r=`String must contain ${t.exact?"exactly":t.inclusive?"at most":"under"} ${t.maximum} character(s)`:t.type==="number"?r=`Number must be ${t.exact?"exactly":t.inclusive?"less than or equal to":"less than"} ${t.maximum}`:t.type==="bigint"?r=`BigInt must be ${t.exact?"exactly":t.inclusive?"less than or equal to":"less than"} ${t.maximum}`:t.type==="date"?r=`Date must be ${t.exact?"exactly":t.inclusive?"smaller than or equal to":"smaller than"} ${new Date(Number(t.maximum))}`:r="Invalid input";break;case c.custom:r="Invalid input";break;case c.invalid_intersection_types:r="Intersection results could not be merged";break;case c.not_multiple_of:r=`Number must be a multiple of ${t.multipleOf}`;break;case c.not_finite:r="Number must be finite";break;default:r=e.defaultError,I.assertNever(t)}return{message:r}},re=Do;var Ar=re;function $o(t){Ar=t}function He(){return Ar}var gt=t=>{let{data:e,path:r,errorMaps:n,issueData:a}=t,o=[...r,...a.path||[]],s={...a,path:o};if(a.message!==void 0)return{...a,path:o,message:a.message};let i="",u=n.filter(f=>!!f).slice().reverse();for(let f of u)i=f(s,{data:e,defaultError:i}).message;return{...a,path:o,message:i}},jo=[];function d(t,e){let r=He(),n=gt({issueData:e,data:t.data,path:t.path,errorMaps:[t.common.contextualErrorMap,t.schemaErrorMap,r,r===re?void 0:re].filter(a=>!!a)});t.common.issues.push(n)}var $=class t{constructor(){this.value="valid"}dirty(){this.value==="valid"&&(this.value="dirty")}abort(){this.value!=="aborted"&&(this.value="aborted")}static mergeArray(e,r){let n=[];for(let a of r){if(a.status==="aborted")return _;a.status==="dirty"&&e.dirty(),n.push(a.value)}return{status:e.value,value:n}}static async mergeObjectAsync(e,r){let n=[];for(let a of r){let o=await a.key,s=await a.value;n.push({key:o,value:s})}return t.mergeObjectSync(e,n)}static mergeObjectSync(e,r){let n={};for(let a of r){let{key:o,value:s}=a;if(o.status==="aborted"||s.status==="aborted")return _;o.status==="dirty"&&e.dirty(),s.status==="dirty"&&e.dirty(),o.value!=="__proto__"&&(typeof s.value<"u"||a.alwaysSet)&&(n[o.value]=s.value)}return{status:e.value,value:n}}},_=Object.freeze({status:"aborted"}),Te=t=>({status:"dirty",value:t}),j=t=>({status:"valid",value:t}),Ot=t=>t.status==="aborted",wt=t=>t.status==="dirty",fe=t=>t.status==="valid",ze=t=>typeof Promise<"u"&&t instanceof Promise;var h;(function(t){t.errToObj=e=>typeof e=="string"?{message:e}:e||{},t.toString=e=>typeof e=="string"?e:e?.message})(h||(h={}));var z=class{constructor(e,r,n,a){this._cachedPath=[],this.parent=e,this.data=r,this._path=n,this._key=a}get path(){return this._cachedPath.length||(Array.isArray(this._key)?this._cachedPath.push(...this._path,...this._key):this._cachedPath.push(...this._path,this._key)),this._cachedPath}},kr=(t,e)=>{if(fe(e))return{success:!0,data:e.value};if(!t.common.issues.length)throw new Error("Validation failed but no issues detected.");return{success:!1,get error(){if(this._error)return this._error;let r=new B(t.common.issues);return this._error=r,this._error}}};function b(t){if(!t)return{};let{errorMap:e,invalid_type_error:r,required_error:n,description:a}=t;if(e&&(r||n))throw new Error(`Can't use "invalid_type_error" or "required_error" in conjunction with custom error map.`);return e?{errorMap:e,description:a}:{errorMap:(s,i)=>{let{message:u}=t;return s.code==="invalid_enum_value"?{message:u??i.defaultError}:typeof i.data>"u"?{message:u??n??i.defaultError}:s.code!=="invalid_type"?{message:i.defaultError}:{message:u??r??i.defaultError}},description:a}}var T=class{get description(){return this._def.description}_getType(e){return q(e.data)}_getOrReturnCtx(e,r){return r||{common:e.parent.common,data:e.data,parsedType:q(e.data),schemaErrorMap:this._def.errorMap,path:e.path,parent:e.parent}}_processInputParams(e){return{status:new $,ctx:{common:e.parent.common,data:e.data,parsedType:q(e.data),schemaErrorMap:this._def.errorMap,path:e.path,parent:e.parent}}}_parseSync(e){let r=this._parse(e);if(ze(r))throw new Error("Synchronous parse encountered promise.");return r}_parseAsync(e){let r=this._parse(e);return Promise.resolve(r)}parse(e,r){let n=this.safeParse(e,r);if(n.success)return n.data;throw n.error}safeParse(e,r){let n={common:{issues:[],async:r?.async??!1,contextualErrorMap:r?.errorMap},path:r?.path||[],schemaErrorMap:this._def.errorMap,parent:null,data:e,parsedType:q(e)},a=this._parseSync({data:e,path:n.path,parent:n});return kr(n,a)}"~validate"(e){let r={common:{issues:[],async:!!this["~standard"].async},path:[],schemaErrorMap:this._def.errorMap,parent:null,data:e,parsedType:q(e)};if(!this["~standard"].async)try{let n=this._parseSync({data:e,path:[],parent:r});return fe(n)?{value:n.value}:{issues:r.common.issues}}catch(n){n?.message?.toLowerCase()?.includes("encountered")&&(this["~standard"].async=!0),r.common={issues:[],async:!0}}return this._parseAsync({data:e,path:[],parent:r}).then(n=>fe(n)?{value:n.value}:{issues:r.common.issues})}async parseAsync(e,r){let n=await this.safeParseAsync(e,r);if(n.success)return n.data;throw n.error}async safeParseAsync(e,r){let n={common:{issues:[],contextualErrorMap:r?.errorMap,async:!0},path:r?.path||[],schemaErrorMap:this._def.errorMap,parent:null,data:e,parsedType:q(e)},a=this._parse({data:e,path:n.path,parent:n}),o=await(ze(a)?a:Promise.resolve(a));return kr(n,o)}refine(e,r){let n=a=>typeof r=="string"||typeof r>"u"?{message:r}:typeof r=="function"?r(a):r;return this._refinement((a,o)=>{let s=e(a),i=()=>o.addIssue({code:c.custom,...n(a)});return typeof Promise<"u"&&s instanceof Promise?s.then(u=>u?!0:(i(),!1)):s?!0:(i(),!1)})}refinement(e,r){return this._refinement((n,a)=>e(n)?!0:(a.addIssue(typeof r=="function"?r(n,a):r),!1))}_refinement(e){return new V({schema:this,typeName:v.ZodEffects,effect:{type:"refinement",refinement:e}})}superRefine(e){return this._refinement(e)}constructor(e){this.spa=this.safeParseAsync,this._def=e,this.parse=this.parse.bind(this),this.safeParse=this.safeParse.bind(this),this.parseAsync=this.parseAsync.bind(this),this.safeParseAsync=this.safeParseAsync.bind(this),this.spa=this.spa.bind(this),this.refine=this.refine.bind(this),this.refinement=this.refinement.bind(this),this.superRefine=this.superRefine.bind(this),this.optional=this.optional.bind(this),this.nullable=this.nullable.bind(this),this.nullish=this.nullish.bind(this),this.array=this.array.bind(this),this.promise=this.promise.bind(this),this.or=this.or.bind(this),this.and=this.and.bind(this),this.transform=this.transform.bind(this),this.brand=this.brand.bind(this),this.default=this.default.bind(this),this.catch=this.catch.bind(this),this.describe=this.describe.bind(this),this.pipe=this.pipe.bind(this),this.readonly=this.readonly.bind(this),this.isNullable=this.isNullable.bind(this),this.isOptional=this.isOptional.bind(this),this["~standard"]={version:1,vendor:"zod",validate:r=>this["~validate"](r)}}optional(){return H.create(this,this._def)}nullable(){return X.create(this,this._def)}nullish(){return this.nullable().optional()}array(){return oe.create(this)}promise(){return de.create(this,this._def)}or(e){return ke.create([this,e],this._def)}and(e){return Re.create(this,e,this._def)}transform(e){return new V({...b(this._def),schema:this,typeName:v.ZodEffects,effect:{type:"transform",transform:e}})}default(e){let r=typeof e=="function"?e:()=>e;return new Me({...b(this._def),innerType:this,defaultValue:r,typeName:v.ZodDefault})}brand(){return new yt({typeName:v.ZodBranded,type:this,...b(this._def)})}catch(e){let r=typeof e=="function"?e:()=>e;return new De({...b(this._def),innerType:this,catchValue:r,typeName:v.ZodCatch})}describe(e){let r=this.constructor;return new r({...this._def,description:e})}pipe(e){return _t.create(this,e)}readonly(){return $e.create(this)}isOptional(){return this.safeParse(void 0).success}isNullable(){return this.safeParse(null).success}},Go=/^c[^\s-]{8,}$/i,Bo=/^[0-9a-z]+$/,Uo=/^[0-9A-HJKMNP-TV-Z]{26}$/i,Fo=/^[0-9a-fA-F]{8}\b-[0-9a-fA-F]{4}\b-[0-9a-fA-F]{4}\b-[0-9a-fA-F]{4}\b-[0-9a-fA-F]{12}$/i,Ho=/^[a-z0-9_-]{21}$/i,zo=/^[A-Za-z0-9-_]+\.[A-Za-z0-9-_]+\.[A-Za-z0-9-_]*$/,Vo=/^[-+]?P(?!$)(?:(?:[-+]?\d+Y)|(?:[-+]?\d+[.,]\d+Y$))?(?:(?:[-+]?\d+M)|(?:[-+]?\d+[.,]\d+M$))?(?:(?:[-+]?\d+W)|(?:[-+]?\d+[.,]\d+W$))?(?:(?:[-+]?\d+D)|(?:[-+]?\d+[.,]\d+D$))?(?:T(?=[\d+-])(?:(?:[-+]?\d+H)|(?:[-+]?\d+[.,]\d+H$))?(?:(?:[-+]?\d+M)|(?:[-+]?\d+[.,]\d+M$))?(?:[-+]?\d+(?:[.,]\d+)?S)?)??$/,Zo=/^(?!\.)(?!.*\.\.)([A-Z0-9_'+\-\.]*)[A-Z0-9_+-]@([A-Z0-9][A-Z0-9\-]*\.)+[A-Z]{2,}$/i,Ko="^(\\p{Extended_Pictographic}|\\p{Emoji_Component})+$",or,Wo=/^(?:(?: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])$/,Yo=/^(?:(?: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])\/(3[0-2]|[12]?[0-9])$/,qo=/^(([0-9a-fA-F]{1,4}:){7,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}|:)|fe80:(:[0-9a-fA-F]{0,4}){0,4}%[0-9a-zA-Z]{1,}|::(ffff(:0{1,4}){0,1}:){0,1}((25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])\.){3,3}(25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])|([0-9a-fA-F]{1,4}:){1,4}:((25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])\.){3,3}(25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9]))$/,Jo=/^(([0-9a-fA-F]{1,4}:){7,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}|:)|fe80:(:[0-9a-fA-F]{0,4}){0,4}%[0-9a-zA-Z]{1,}|::(ffff(:0{1,4}){0,1}:){0,1}((25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])\.){3,3}(25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])|([0-9a-fA-F]{1,4}:){1,4}:((25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])\.){3,3}(25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9]))\/(12[0-8]|1[01][0-9]|[1-9]?[0-9])$/,Xo=/^([0-9a-zA-Z+/]{4})*(([0-9a-zA-Z+/]{2}==)|([0-9a-zA-Z+/]{3}=))?$/,Qo=/^([0-9a-zA-Z-_]{4})*(([0-9a-zA-Z-_]{2}(==)?)|([0-9a-zA-Z-_]{3}(=)?))?$/,Lr="((\\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])))",es=new RegExp(`^${Lr}$`);function Cr(t){let e="[0-5]\\d";t.precision?e=`${e}\\.\\d{${t.precision}}`:t.precision==null&&(e=`${e}(\\.\\d+)?`);let r=t.precision?"+":"?";return`([01]\\d|2[0-3]):[0-5]\\d(:${e})${r}`}function ts(t){return new RegExp(`^${Cr(t)}$`)}function Nr(t){let e=`${Lr}T${Cr(t)}`,r=[];return r.push(t.local?"Z?":"Z"),t.offset&&r.push("([+-]\\d{2}:?\\d{2})"),e=`${e}(${r.join("|")})`,new RegExp(`^${e}$`)}function rs(t,e){return!!((e==="v4"||!e)&&Wo.test(t)||(e==="v6"||!e)&&qo.test(t))}function ns(t,e){if(!zo.test(t))return!1;try{let[r]=t.split(".");if(!r)return!1;let n=r.replace(/-/g,"+").replace(/_/g,"/").padEnd(r.length+(4-r.length%4)%4,"="),a=JSON.parse(atob(n));return!(typeof a!="object"||a===null||"typ"in a&&a?.typ!=="JWT"||!a.alg||e&&a.alg!==e)}catch{return!1}}function as(t,e){return!!((e==="v4"||!e)&&Yo.test(t)||(e==="v6"||!e)&&Jo.test(t))}var ce=class t extends T{_parse(e){if(this._def.coerce&&(e.data=String(e.data)),this._getType(e)!==p.string){let o=this._getOrReturnCtx(e);return d(o,{code:c.invalid_type,expected:p.string,received:o.parsedType}),_}let n=new $,a;for(let o of this._def.checks)if(o.kind==="min")e.data.length<o.value&&(a=this._getOrReturnCtx(e,a),d(a,{code:c.too_small,minimum:o.value,type:"string",inclusive:!0,exact:!1,message:o.message}),n.dirty());else if(o.kind==="max")e.data.length>o.value&&(a=this._getOrReturnCtx(e,a),d(a,{code:c.too_big,maximum:o.value,type:"string",inclusive:!0,exact:!1,message:o.message}),n.dirty());else if(o.kind==="length"){let s=e.data.length>o.value,i=e.data.length<o.value;(s||i)&&(a=this._getOrReturnCtx(e,a),s?d(a,{code:c.too_big,maximum:o.value,type:"string",inclusive:!0,exact:!0,message:o.message}):i&&d(a,{code:c.too_small,minimum:o.value,type:"string",inclusive:!0,exact:!0,message:o.message}),n.dirty())}else if(o.kind==="email")Zo.test(e.data)||(a=this._getOrReturnCtx(e,a),d(a,{validation:"email",code:c.invalid_string,message:o.message}),n.dirty());else if(o.kind==="emoji")or||(or=new RegExp(Ko,"u")),or.test(e.data)||(a=this._getOrReturnCtx(e,a),d(a,{validation:"emoji",code:c.invalid_string,message:o.message}),n.dirty());else if(o.kind==="uuid")Fo.test(e.data)||(a=this._getOrReturnCtx(e,a),d(a,{validation:"uuid",code:c.invalid_string,message:o.message}),n.dirty());else if(o.kind==="nanoid")Ho.test(e.data)||(a=this._getOrReturnCtx(e,a),d(a,{validation:"nanoid",code:c.invalid_string,message:o.message}),n.dirty());else if(o.kind==="cuid")Go.test(e.data)||(a=this._getOrReturnCtx(e,a),d(a,{validation:"cuid",code:c.invalid_string,message:o.message}),n.dirty());else if(o.kind==="cuid2")Bo.test(e.data)||(a=this._getOrReturnCtx(e,a),d(a,{validation:"cuid2",code:c.invalid_string,message:o.message}),n.dirty());else if(o.kind==="ulid")Uo.test(e.data)||(a=this._getOrReturnCtx(e,a),d(a,{validation:"ulid",code:c.invalid_string,message:o.message}),n.dirty());else if(o.kind==="url")try{new URL(e.data)}catch{a=this._getOrReturnCtx(e,a),d(a,{validation:"url",code:c.invalid_string,message:o.message}),n.dirty()}else o.kind==="regex"?(o.regex.lastIndex=0,o.regex.test(e.data)||(a=this._getOrReturnCtx(e,a),d(a,{validation:"regex",code:c.invalid_string,message:o.message}),n.dirty())):o.kind==="trim"?e.data=e.data.trim():o.kind==="includes"?e.data.includes(o.value,o.position)||(a=this._getOrReturnCtx(e,a),d(a,{code:c.invalid_string,validation:{includes:o.value,position:o.position},message:o.message}),n.dirty()):o.kind==="toLowerCase"?e.data=e.data.toLowerCase():o.kind==="toUpperCase"?e.data=e.data.toUpperCase():o.kind==="startsWith"?e.data.startsWith(o.value)||(a=this._getOrReturnCtx(e,a),d(a,{code:c.invalid_string,validation:{startsWith:o.value},message:o.message}),n.dirty()):o.kind==="endsWith"?e.data.endsWith(o.value)||(a=this._getOrReturnCtx(e,a),d(a,{code:c.invalid_string,validation:{endsWith:o.value},message:o.message}),n.dirty()):o.kind==="datetime"?Nr(o).test(e.data)||(a=this._getOrReturnCtx(e,a),d(a,{code:c.invalid_string,validation:"datetime",message:o.message}),n.dirty()):o.kind==="date"?es.test(e.data)||(a=this._getOrReturnCtx(e,a),d(a,{code:c.invalid_string,validation:"date",message:o.message}),n.dirty()):o.kind==="time"?ts(o).test(e.data)||(a=this._getOrReturnCtx(e,a),d(a,{code:c.invalid_string,validation:"time",message:o.message}),n.dirty()):o.kind==="duration"?Vo.test(e.data)||(a=this._getOrReturnCtx(e,a),d(a,{validation:"duration",code:c.invalid_string,message:o.message}),n.dirty()):o.kind==="ip"?rs(e.data,o.version)||(a=this._getOrReturnCtx(e,a),d(a,{validation:"ip",code:c.invalid_string,message:o.message}),n.dirty()):o.kind==="jwt"?ns(e.data,o.alg)||(a=this._getOrReturnCtx(e,a),d(a,{validation:"jwt",code:c.invalid_string,message:o.message}),n.dirty()):o.kind==="cidr"?as(e.data,o.version)||(a=this._getOrReturnCtx(e,a),d(a,{validation:"cidr",code:c.invalid_string,message:o.message}),n.dirty()):o.kind==="base64"?Xo.test(e.data)||(a=this._getOrReturnCtx(e,a),d(a,{validation:"base64",code:c.invalid_string,message:o.message}),n.dirty()):o.kind==="base64url"?Qo.test(e.data)||(a=this._getOrReturnCtx(e,a),d(a,{validation:"base64url",code:c.invalid_string,message:o.message}),n.dirty()):I.assertNever(o);return{status:n.value,value:e.data}}_regex(e,r,n){return this.refinement(a=>e.test(a),{validation:r,code:c.invalid_string,...h.errToObj(n)})}_addCheck(e){return new t({...this._def,checks:[...this._def.checks,e]})}email(e){return this._addCheck({kind:"email",...h.errToObj(e)})}url(e){return this._addCheck({kind:"url",...h.errToObj(e)})}emoji(e){return this._addCheck({kind:"emoji",...h.errToObj(e)})}uuid(e){return this._addCheck({kind:"uuid",...h.errToObj(e)})}nanoid(e){return this._addCheck({kind:"nanoid",...h.errToObj(e)})}cuid(e){return this._addCheck({kind:"cuid",...h.errToObj(e)})}cuid2(e){return this._addCheck({kind:"cuid2",...h.errToObj(e)})}ulid(e){return this._addCheck({kind:"ulid",...h.errToObj(e)})}base64(e){return this._addCheck({kind:"base64",...h.errToObj(e)})}base64url(e){return this._addCheck({kind:"base64url",...h.errToObj(e)})}jwt(e){return this._addCheck({kind:"jwt",...h.errToObj(e)})}ip(e){return this._addCheck({kind:"ip",...h.errToObj(e)})}cidr(e){return this._addCheck({kind:"cidr",...h.errToObj(e)})}datetime(e){return typeof e=="string"?this._addCheck({kind:"datetime",precision:null,offset:!1,local:!1,message:e}):this._addCheck({kind:"datetime",precision:typeof e?.precision>"u"?null:e?.precision,offset:e?.offset??!1,local:e?.local??!1,...h.errToObj(e?.message)})}date(e){return this._addCheck({kind:"date",message:e})}time(e){return typeof e=="string"?this._addCheck({kind:"time",precision:null,message:e}):this._addCheck({kind:"time",precision:typeof e?.precision>"u"?null:e?.precision,...h.errToObj(e?.message)})}duration(e){return this._addCheck({kind:"duration",...h.errToObj(e)})}regex(e,r){return this._addCheck({kind:"regex",regex:e,...h.errToObj(r)})}includes(e,r){return this._addCheck({kind:"includes",value:e,position:r?.position,...h.errToObj(r?.message)})}startsWith(e,r){return this._addCheck({kind:"startsWith",value:e,...h.errToObj(r)})}endsWith(e,r){return this._addCheck({kind:"endsWith",value:e,...h.errToObj(r)})}min(e,r){return this._addCheck({kind:"min",value:e,...h.errToObj(r)})}max(e,r){return this._addCheck({kind:"max",value:e,...h.errToObj(r)})}length(e,r){return this._addCheck({kind:"length",value:e,...h.errToObj(r)})}nonempty(e){return this.min(1,h.errToObj(e))}trim(){return new t({...this._def,checks:[...this._def.checks,{kind:"trim"}]})}toLowerCase(){return new t({...this._def,checks:[...this._def.checks,{kind:"toLowerCase"}]})}toUpperCase(){return new t({...this._def,checks:[...this._def.checks,{kind:"toUpperCase"}]})}get isDatetime(){return!!this._def.checks.find(e=>e.kind==="datetime")}get isDate(){return!!this._def.checks.find(e=>e.kind==="date")}get isTime(){return!!this._def.checks.find(e=>e.kind==="time")}get isDuration(){return!!this._def.checks.find(e=>e.kind==="duration")}get isEmail(){return!!this._def.checks.find(e=>e.kind==="email")}get isURL(){return!!this._def.checks.find(e=>e.kind==="url")}get isEmoji(){return!!this._def.checks.find(e=>e.kind==="emoji")}get isUUID(){return!!this._def.checks.find(e=>e.kind==="uuid")}get isNANOID(){return!!this._def.checks.find(e=>e.kind==="nanoid")}get isCUID(){return!!this._def.checks.find(e=>e.kind==="cuid")}get isCUID2(){return!!this._def.checks.find(e=>e.kind==="cuid2")}get isULID(){return!!this._def.checks.find(e=>e.kind==="ulid")}get isIP(){return!!this._def.checks.find(e=>e.kind==="ip")}get isCIDR(){return!!this._def.checks.find(e=>e.kind==="cidr")}get isBase64(){return!!this._def.checks.find(e=>e.kind==="base64")}get isBase64url(){return!!this._def.checks.find(e=>e.kind==="base64url")}get minLength(){let e=null;for(let r of this._def.checks)r.kind==="min"&&(e===null||r.value>e)&&(e=r.value);return e}get maxLength(){let e=null;for(let r of this._def.checks)r.kind==="max"&&(e===null||r.value<e)&&(e=r.value);return e}};ce.create=t=>new ce({checks:[],typeName:v.ZodString,coerce:t?.coerce??!1,...b(t)});function os(t,e){let r=(t.toString().split(".")[1]||"").length,n=(e.toString().split(".")[1]||"").length,a=r>n?r:n,o=Number.parseInt(t.toFixed(a).replace(".","")),s=Number.parseInt(e.toFixed(a).replace(".",""));return o%s/10**a}var Ie=class t extends T{constructor(){super(...arguments),this.min=this.gte,this.max=this.lte,this.step=this.multipleOf}_parse(e){if(this._def.coerce&&(e.data=Number(e.data)),this._getType(e)!==p.number){let o=this._getOrReturnCtx(e);return d(o,{code:c.invalid_type,expected:p.number,received:o.parsedType}),_}let n,a=new $;for(let o of this._def.checks)o.kind==="int"?I.isInteger(e.data)||(n=this._getOrReturnCtx(e,n),d(n,{code:c.invalid_type,expected:"integer",received:"float",message:o.message}),a.dirty()):o.kind==="min"?(o.inclusive?e.data<o.value:e.data<=o.value)&&(n=this._getOrReturnCtx(e,n),d(n,{code:c.too_small,minimum:o.value,type:"number",inclusive:o.inclusive,exact:!1,message:o.message}),a.dirty()):o.kind==="max"?(o.inclusive?e.data>o.value:e.data>=o.value)&&(n=this._getOrReturnCtx(e,n),d(n,{code:c.too_big,maximum:o.value,type:"number",inclusive:o.inclusive,exact:!1,message:o.message}),a.dirty()):o.kind==="multipleOf"?os(e.data,o.value)!==0&&(n=this._getOrReturnCtx(e,n),d(n,{code:c.not_multiple_of,multipleOf:o.value,message:o.message}),a.dirty()):o.kind==="finite"?Number.isFinite(e.data)||(n=this._getOrReturnCtx(e,n),d(n,{code:c.not_finite,message:o.message}),a.dirty()):I.assertNever(o);return{status:a.value,value:e.data}}gte(e,r){return this.setLimit("min",e,!0,h.toString(r))}gt(e,r){return this.setLimit("min",e,!1,h.toString(r))}lte(e,r){return this.setLimit("max",e,!0,h.toString(r))}lt(e,r){return this.setLimit("max",e,!1,h.toString(r))}setLimit(e,r,n,a){return new t({...this._def,checks:[...this._def.checks,{kind:e,value:r,inclusive:n,message:h.toString(a)}]})}_addCheck(e){return new t({...this._def,checks:[...this._def.checks,e]})}int(e){return this._addCheck({kind:"int",message:h.toString(e)})}positive(e){return this._addCheck({kind:"min",value:0,inclusive:!1,message:h.toString(e)})}negative(e){return this._addCheck({kind:"max",value:0,inclusive:!1,message:h.toString(e)})}nonpositive(e){return this._addCheck({kind:"max",value:0,inclusive:!0,message:h.toString(e)})}nonnegative(e){return this._addCheck({kind:"min",value:0,inclusive:!0,message:h.toString(e)})}multipleOf(e,r){return this._addCheck({kind:"multipleOf",value:e,message:h.toString(r)})}finite(e){return this._addCheck({kind:"finite",message:h.toString(e)})}safe(e){return this._addCheck({kind:"min",inclusive:!0,value:Number.MIN_SAFE_INTEGER,message:h.toString(e)})._addCheck({kind:"max",inclusive:!0,value:Number.MAX_SAFE_INTEGER,message:h.toString(e)})}get minValue(){let e=null;for(let r of this._def.checks)r.kind==="min"&&(e===null||r.value>e)&&(e=r.value);return e}get maxValue(){let e=null;for(let r of this._def.checks)r.kind==="max"&&(e===null||r.value<e)&&(e=r.value);return e}get isInt(){return!!this._def.checks.find(e=>e.kind==="int"||e.kind==="multipleOf"&&I.isInteger(e.value))}get isFinite(){let e=null,r=null;for(let n of this._def.checks){if(n.kind==="finite"||n.kind==="int"||n.kind==="multipleOf")return!0;n.kind==="min"?(r===null||n.value>r)&&(r=n.value):n.kind==="max"&&(e===null||n.value<e)&&(e=n.value)}return Number.isFinite(r)&&Number.isFinite(e)}};Ie.create=t=>new Ie({checks:[],typeName:v.ZodNumber,coerce:t?.coerce||!1,...b(t)});var Ee=class t extends T{constructor(){super(...arguments),this.min=this.gte,this.max=this.lte}_parse(e){if(this._def.coerce)try{e.data=BigInt(e.data)}catch{return this._getInvalidInput(e)}if(this._getType(e)!==p.bigint)return this._getInvalidInput(e);let n,a=new $;for(let o of this._def.checks)o.kind==="min"?(o.inclusive?e.data<o.value:e.data<=o.value)&&(n=this._getOrReturnCtx(e,n),d(n,{code:c.too_small,type:"bigint",minimum:o.value,inclusive:o.inclusive,message:o.message}),a.dirty()):o.kind==="max"?(o.inclusive?e.data>o.value:e.data>=o.value)&&(n=this._getOrReturnCtx(e,n),d(n,{code:c.too_big,type:"bigint",maximum:o.value,inclusive:o.inclusive,message:o.message}),a.dirty()):o.kind==="multipleOf"?e.data%o.value!==BigInt(0)&&(n=this._getOrReturnCtx(e,n),d(n,{code:c.not_multiple_of,multipleOf:o.value,message:o.message}),a.dirty()):I.assertNever(o);return{status:a.value,value:e.data}}_getInvalidInput(e){let r=this._getOrReturnCtx(e);return d(r,{code:c.invalid_type,expected:p.bigint,received:r.parsedType}),_}gte(e,r){return this.setLimit("min",e,!0,h.toString(r))}gt(e,r){return this.setLimit("min",e,!1,h.toString(r))}lte(e,r){return this.setLimit("max",e,!0,h.toString(r))}lt(e,r){return this.setLimit("max",e,!1,h.toString(r))}setLimit(e,r,n,a){return new t({...this._def,checks:[...this._def.checks,{kind:e,value:r,inclusive:n,message:h.toString(a)}]})}_addCheck(e){return new t({...this._def,checks:[...this._def.checks,e]})}positive(e){return this._addCheck({kind:"min",value:BigInt(0),inclusive:!1,message:h.toString(e)})}negative(e){return this._addCheck({kind:"max",value:BigInt(0),inclusive:!1,message:h.toString(e)})}nonpositive(e){return this._addCheck({kind:"max",value:BigInt(0),inclusive:!0,message:h.toString(e)})}nonnegative(e){return this._addCheck({kind:"min",value:BigInt(0),inclusive:!0,message:h.toString(e)})}multipleOf(e,r){return this._addCheck({kind:"multipleOf",value:e,message:h.toString(r)})}get minValue(){let e=null;for(let r of this._def.checks)r.kind==="min"&&(e===null||r.value>e)&&(e=r.value);return e}get maxValue(){let e=null;for(let r of this._def.checks)r.kind==="max"&&(e===null||r.value<e)&&(e=r.value);return e}};Ee.create=t=>new Ee({checks:[],typeName:v.ZodBigInt,coerce:t?.coerce??!1,...b(t)});var Se=class extends T{_parse(e){if(this._def.coerce&&(e.data=!!e.data),this._getType(e)!==p.boolean){let n=this._getOrReturnCtx(e);return d(n,{code:c.invalid_type,expected:p.boolean,received:n.parsedType}),_}return j(e.data)}};Se.create=t=>new Se({typeName:v.ZodBoolean,coerce:t?.coerce||!1,...b(t)});var Oe=class t extends T{_parse(e){if(this._def.coerce&&(e.data=new Date(e.data)),this._getType(e)!==p.date){let o=this._getOrReturnCtx(e);return d(o,{code:c.invalid_type,expected:p.date,received:o.parsedType}),_}if(Number.isNaN(e.data.getTime())){let o=this._getOrReturnCtx(e);return d(o,{code:c.invalid_date}),_}let n=new $,a;for(let o of this._def.checks)o.kind==="min"?e.data.getTime()<o.value&&(a=this._getOrReturnCtx(e,a),d(a,{code:c.too_small,message:o.message,inclusive:!0,exact:!1,minimum:o.value,type:"date"}),n.dirty()):o.kind==="max"?e.data.getTime()>o.value&&(a=this._getOrReturnCtx(e,a),d(a,{code:c.too_big,message:o.message,inclusive:!0,exact:!1,maximum:o.value,type:"date"}),n.dirty()):I.assertNever(o);return{status:n.value,value:new Date(e.data.getTime())}}_addCheck(e){return new t({...this._def,checks:[...this._def.checks,e]})}min(e,r){return this._addCheck({kind:"min",value:e.getTime(),message:h.toString(r)})}max(e,r){return this._addCheck({kind:"max",value:e.getTime(),message:h.toString(r)})}get minDate(){let e=null;for(let r of this._def.checks)r.kind==="min"&&(e===null||r.value>e)&&(e=r.value);return e!=null?new Date(e):null}get maxDate(){let e=null;for(let r of this._def.checks)r.kind==="max"&&(e===null||r.value<e)&&(e=r.value);return e!=null?new Date(e):null}};Oe.create=t=>new Oe({checks:[],coerce:t?.coerce||!1,typeName:v.ZodDate,...b(t)});var Ze=class extends T{_parse(e){if(this._getType(e)!==p.symbol){let n=this._getOrReturnCtx(e);return d(n,{code:c.invalid_type,expected:p.symbol,received:n.parsedType}),_}return j(e.data)}};Ze.create=t=>new Ze({typeName:v.ZodSymbol,...b(t)});var we=class extends T{_parse(e){if(this._getType(e)!==p.undefined){let n=this._getOrReturnCtx(e);return d(n,{code:c.invalid_type,expected:p.undefined,received:n.parsedType}),_}return j(e.data)}};we.create=t=>new we({typeName:v.ZodUndefined,...b(t)});var Ae=class extends T{_parse(e){if(this._getType(e)!==p.null){let n=this._getOrReturnCtx(e);return d(n,{code:c.invalid_type,expected:p.null,received:n.parsedType}),_}return j(e.data)}};Ae.create=t=>new Ae({typeName:v.ZodNull,...b(t)});var le=class extends T{constructor(){super(...arguments),this._any=!0}_parse(e){return j(e.data)}};le.create=t=>new le({typeName:v.ZodAny,...b(t)});var ae=class extends T{constructor(){super(...arguments),this._unknown=!0}_parse(e){return j(e.data)}};ae.create=t=>new ae({typeName:v.ZodUnknown,...b(t)});var Z=class extends T{_parse(e){let r=this._getOrReturnCtx(e);return d(r,{code:c.invalid_type,expected:p.never,received:r.parsedType}),_}};Z.create=t=>new Z({typeName:v.ZodNever,...b(t)});var Ke=class extends T{_parse(e){if(this._getType(e)!==p.undefined){let n=this._getOrReturnCtx(e);return d(n,{code:c.invalid_type,expected:p.void,received:n.parsedType}),_}return j(e.data)}};Ke.create=t=>new Ke({typeName:v.ZodVoid,...b(t)});var oe=class t extends T{_parse(e){let{ctx:r,status:n}=this._processInputParams(e),a=this._def;if(r.parsedType!==p.array)return d(r,{code:c.invalid_type,expected:p.array,received:r.parsedType}),_;if(a.exactLength!==null){let s=r.data.length>a.exactLength.value,i=r.data.length<a.exactLength.value;(s||i)&&(d(r,{code:s?c.too_big:c.too_small,minimum:i?a.exactLength.value:void 0,maximum:s?a.exactLength.value:void 0,type:"array",inclusive:!0,exact:!0,message:a.exactLength.message}),n.dirty())}if(a.minLength!==null&&r.data.length<a.minLength.value&&(d(r,{code:c.too_small,minimum:a.minLength.value,type:"array",inclusive:!0,exact:!1,message:a.minLength.message}),n.dirty()),a.maxLength!==null&&r.data.length>a.maxLength.value&&(d(r,{code:c.too_big,maximum:a.maxLength.value,type:"array",inclusive:!0,exact:!1,message:a.maxLength.message}),n.dirty()),r.common.async)return Promise.all([...r.data].map((s,i)=>a.type._parseAsync(new z(r,s,r.path,i)))).then(s=>$.mergeArray(n,s));let o=[...r.data].map((s,i)=>a.type._parseSync(new z(r,s,r.path,i)));return $.mergeArray(n,o)}get element(){return this._def.type}min(e,r){return new t({...this._def,minLength:{value:e,message:h.toString(r)}})}max(e,r){return new t({...this._def,maxLength:{value:e,message:h.toString(r)}})}length(e,r){return new t({...this._def,exactLength:{value:e,message:h.toString(r)}})}nonempty(e){return this.min(1,e)}};oe.create=(t,e)=>new oe({type:t,minLength:null,maxLength:null,exactLength:null,typeName:v.ZodArray,...b(e)});function Ve(t){if(t instanceof U){let e={};for(let r in t.shape){let n=t.shape[r];e[r]=H.create(Ve(n))}return new U({...t._def,shape:()=>e})}else return t instanceof oe?new oe({...t._def,type:Ve(t.element)}):t instanceof H?H.create(Ve(t.unwrap())):t instanceof X?X.create(Ve(t.unwrap())):t instanceof J?J.create(t.items.map(e=>Ve(e))):t}var U=class t extends T{constructor(){super(...arguments),this._cached=null,this.nonstrict=this.passthrough,this.augment=this.extend}_getCached(){if(this._cached!==null)return this._cached;let e=this._def.shape(),r=I.objectKeys(e);return this._cached={shape:e,keys:r},this._cached}_parse(e){if(this._getType(e)!==p.object){let f=this._getOrReturnCtx(e);return d(f,{code:c.invalid_type,expected:p.object,received:f.parsedType}),_}let{status:n,ctx:a}=this._processInputParams(e),{shape:o,keys:s}=this._getCached(),i=[];if(!(this._def.catchall instanceof Z&&this._def.unknownKeys==="strip"))for(let f in a.data)s.includes(f)||i.push(f);let u=[];for(let f of s){let l=o[f],m=a.data[f];u.push({key:{status:"valid",value:f},value:l._parse(new z(a,m,a.path,f)),alwaysSet:f in a.data})}if(this._def.catchall instanceof Z){let f=this._def.unknownKeys;if(f==="passthrough")for(let l of i)u.push({key:{status:"valid",value:l},value:{status:"valid",value:a.data[l]}});else if(f==="strict")i.length>0&&(d(a,{code:c.unrecognized_keys,keys:i}),n.dirty());else if(f!=="strip")throw new Error("Internal ZodObject error: invalid unknownKeys value.")}else{let f=this._def.catchall;for(let l of i){let m=a.data[l];u.push({key:{status:"valid",value:l},value:f._parse(new z(a,m,a.path,l)),alwaysSet:l in a.data})}}return a.common.async?Promise.resolve().then(async()=>{let f=[];for(let l of u){let m=await l.key,g=await l.value;f.push({key:m,value:g,alwaysSet:l.alwaysSet})}return f}).then(f=>$.mergeObjectSync(n,f)):$.mergeObjectSync(n,u)}get shape(){return this._def.shape()}strict(e){return h.errToObj,new t({...this._def,unknownKeys:"strict",...e!==void 0?{errorMap:(r,n)=>{let a=this._def.errorMap?.(r,n).message??n.defaultError;return r.code==="unrecognized_keys"?{message:h.errToObj(e).message??a}:{message:a}}}:{}})}strip(){return new t({...this._def,unknownKeys:"strip"})}passthrough(){return new t({...this._def,unknownKeys:"passthrough"})}extend(e){return new t({...this._def,shape:()=>({...this._def.shape(),...e})})}merge(e){return new t({unknownKeys:e._def.unknownKeys,catchall:e._def.catchall,shape:()=>({...this._def.shape(),...e._def.shape()}),typeName:v.ZodObject})}setKey(e,r){return this.augment({[e]:r})}catchall(e){return new t({...this._def,catchall:e})}pick(e){let r={};for(let n of I.objectKeys(e))e[n]&&this.shape[n]&&(r[n]=this.shape[n]);return new t({...this._def,shape:()=>r})}omit(e){let r={};for(let n of I.objectKeys(this.shape))e[n]||(r[n]=this.shape[n]);return new t({...this._def,shape:()=>r})}deepPartial(){return Ve(this)}partial(e){let r={};for(let n of I.objectKeys(this.shape)){let a=this.shape[n];e&&!e[n]?r[n]=a:r[n]=a.optional()}return new t({...this._def,shape:()=>r})}required(e){let r={};for(let n of I.objectKeys(this.shape))if(e&&!e[n])r[n]=this.shape[n];else{let o=this.shape[n];for(;o instanceof H;)o=o._def.innerType;r[n]=o}return new t({...this._def,shape:()=>r})}keyof(){return Pr(I.objectKeys(this.shape))}};U.create=(t,e)=>new U({shape:()=>t,unknownKeys:"strip",catchall:Z.create(),typeName:v.ZodObject,...b(e)});U.strictCreate=(t,e)=>new U({shape:()=>t,unknownKeys:"strict",catchall:Z.create(),typeName:v.ZodObject,...b(e)});U.lazycreate=(t,e)=>new U({shape:t,unknownKeys:"strip",catchall:Z.create(),typeName:v.ZodObject,...b(e)});var ke=class extends T{_parse(e){let{ctx:r}=this._processInputParams(e),n=this._def.options;function a(o){for(let i of o)if(i.result.status==="valid")return i.result;for(let i of o)if(i.result.status==="dirty")return r.common.issues.push(...i.ctx.common.issues),i.result;let s=o.map(i=>new B(i.ctx.common.issues));return d(r,{code:c.invalid_union,unionErrors:s}),_}if(r.common.async)return Promise.all(n.map(async o=>{let s={...r,common:{...r.common,issues:[]},parent:null};return{result:await o._parseAsync({data:r.data,path:r.path,parent:s}),ctx:s}})).then(a);{let o,s=[];for(let u of n){let f={...r,common:{...r.common,issues:[]},parent:null},l=u._parseSync({data:r.data,path:r.path,parent:f});if(l.status==="valid")return l;l.status==="dirty"&&!o&&(o={result:l,ctx:f}),f.common.issues.length&&s.push(f.common.issues)}if(o)return r.common.issues.push(...o.ctx.common.issues),o.result;let i=s.map(u=>new B(u));return d(r,{code:c.invalid_union,unionErrors:i}),_}}get options(){return this._def.options}};ke.create=(t,e)=>new ke({options:t,typeName:v.ZodUnion,...b(e)});var ne=t=>t instanceof Le?ne(t.schema):t instanceof V?ne(t.innerType()):t instanceof Ce?[t.value]:t instanceof Ne?t.options:t instanceof Pe?I.objectValues(t.enum):t instanceof Me?ne(t._def.innerType):t instanceof we?[void 0]:t instanceof Ae?[null]:t instanceof H?[void 0,...ne(t.unwrap())]:t instanceof X?[null,...ne(t.unwrap())]:t instanceof yt||t instanceof $e?ne(t.unwrap()):t instanceof De?ne(t._def.innerType):[],At=class t extends T{_parse(e){let{ctx:r}=this._processInputParams(e);if(r.parsedType!==p.object)return d(r,{code:c.invalid_type,expected:p.object,received:r.parsedType}),_;let n=this.discriminator,a=r.data[n],o=this.optionsMap.get(a);return o?r.common.async?o._parseAsync({data:r.data,path:r.path,parent:r}):o._parseSync({data:r.data,path:r.path,parent:r}):(d(r,{code:c.invalid_union_discriminator,options:Array.from(this.optionsMap.keys()),path:[n]}),_)}get discriminator(){return this._def.discriminator}get options(){return this._def.options}get optionsMap(){return this._def.optionsMap}static create(e,r,n){let a=new Map;for(let o of r){let s=ne(o.shape[e]);if(!s.length)throw new Error(`A discriminator value for key \`${e}\` could not be extracted from all schema options`);for(let i of s){if(a.has(i))throw new Error(`Discriminator property ${String(e)} has duplicate value ${String(i)}`);a.set(i,o)}}return new t({typeName:v.ZodDiscriminatedUnion,discriminator:e,options:r,optionsMap:a,...b(n)})}};function sr(t,e){let r=q(t),n=q(e);if(t===e)return{valid:!0,data:t};if(r===p.object&&n===p.object){let a=I.objectKeys(e),o=I.objectKeys(t).filter(i=>a.indexOf(i)!==-1),s={...t,...e};for(let i of o){let u=sr(t[i],e[i]);if(!u.valid)return{valid:!1};s[i]=u.data}return{valid:!0,data:s}}else if(r===p.array&&n===p.array){if(t.length!==e.length)return{valid:!1};let a=[];for(let o=0;o<t.length;o++){let s=t[o],i=e[o],u=sr(s,i);if(!u.valid)return{valid:!1};a.push(u.data)}return{valid:!0,data:a}}else return r===p.date&&n===p.date&&+t==+e?{valid:!0,data:t}:{valid:!1}}var Re=class extends T{_parse(e){let{status:r,ctx:n}=this._processInputParams(e),a=(o,s)=>{if(Ot(o)||Ot(s))return _;let i=sr(o.value,s.value);return i.valid?((wt(o)||wt(s))&&r.dirty(),{status:r.value,value:i.data}):(d(n,{code:c.invalid_intersection_types}),_)};return n.common.async?Promise.all([this._def.left._parseAsync({data:n.data,path:n.path,parent:n}),this._def.right._parseAsync({data:n.data,path:n.path,parent:n})]).then(([o,s])=>a(o,s)):a(this._def.left._parseSync({data:n.data,path:n.path,parent:n}),this._def.right._parseSync({data:n.data,path:n.path,parent:n}))}};Re.create=(t,e,r)=>new Re({left:t,right:e,typeName:v.ZodIntersection,...b(r)});var J=class t extends T{_parse(e){let{status:r,ctx:n}=this._processInputParams(e);if(n.parsedType!==p.array)return d(n,{code:c.invalid_type,expected:p.array,received:n.parsedType}),_;if(n.data.length<this._def.items.length)return d(n,{code:c.too_small,minimum:this._def.items.length,inclusive:!0,exact:!1,type:"array"}),_;!this._def.rest&&n.data.length>this._def.items.length&&(d(n,{code:c.too_big,maximum:this._def.items.length,inclusive:!0,exact:!1,type:"array"}),r.dirty());let o=[...n.data].map((s,i)=>{let u=this._def.items[i]||this._def.rest;return u?u._parse(new z(n,s,n.path,i)):null}).filter(s=>!!s);return n.common.async?Promise.all(o).then(s=>$.mergeArray(r,s)):$.mergeArray(r,o)}get items(){return this._def.items}rest(e){return new t({...this._def,rest:e})}};J.create=(t,e)=>{if(!Array.isArray(t))throw new Error("You must pass an array of schemas to z.tuple([ ... ])");return new J({items:t,typeName:v.ZodTuple,rest:null,...b(e)})};var kt=class t extends T{get keySchema(){return this._def.keyType}get valueSchema(){return this._def.valueType}_parse(e){let{status:r,ctx:n}=this._processInputParams(e);if(n.parsedType!==p.object)return d(n,{code:c.invalid_type,expected:p.object,received:n.parsedType}),_;let a=[],o=this._def.keyType,s=this._def.valueType;for(let i in n.data)a.push({key:o._parse(new z(n,i,n.path,i)),value:s._parse(new z(n,n.data[i],n.path,i)),alwaysSet:i in n.data});return n.common.async?$.mergeObjectAsync(r,a):$.mergeObjectSync(r,a)}get element(){return this._def.valueType}static create(e,r,n){return r instanceof T?new t({keyType:e,valueType:r,typeName:v.ZodRecord,...b(n)}):new t({keyType:ce.create(),valueType:e,typeName:v.ZodRecord,...b(r)})}},We=class extends T{get keySchema(){return this._def.keyType}get valueSchema(){return this._def.valueType}_parse(e){let{status:r,ctx:n}=this._processInputParams(e);if(n.parsedType!==p.map)return d(n,{code:c.invalid_type,expected:p.map,received:n.parsedType}),_;let a=this._def.keyType,o=this._def.valueType,s=[...n.data.entries()].map(([i,u],f)=>({key:a._parse(new z(n,i,n.path,[f,"key"])),value:o._parse(new z(n,u,n.path,[f,"value"]))}));if(n.common.async){let i=new Map;return Promise.resolve().then(async()=>{for(let u of s){let f=await u.key,l=await u.value;if(f.status==="aborted"||l.status==="aborted")return _;(f.status==="dirty"||l.status==="dirty")&&r.dirty(),i.set(f.value,l.value)}return{status:r.value,value:i}})}else{let i=new Map;for(let u of s){let f=u.key,l=u.value;if(f.status==="aborted"||l.status==="aborted")return _;(f.status==="dirty"||l.status==="dirty")&&r.dirty(),i.set(f.value,l.value)}return{status:r.value,value:i}}}};We.create=(t,e,r)=>new We({valueType:e,keyType:t,typeName:v.ZodMap,...b(r)});var Ye=class t extends T{_parse(e){let{status:r,ctx:n}=this._processInputParams(e);if(n.parsedType!==p.set)return d(n,{code:c.invalid_type,expected:p.set,received:n.parsedType}),_;let a=this._def;a.minSize!==null&&n.data.size<a.minSize.value&&(d(n,{code:c.too_small,minimum:a.minSize.value,type:"set",inclusive:!0,exact:!1,message:a.minSize.message}),r.dirty()),a.maxSize!==null&&n.data.size>a.maxSize.value&&(d(n,{code:c.too_big,maximum:a.maxSize.value,type:"set",inclusive:!0,exact:!1,message:a.maxSize.message}),r.dirty());let o=this._def.valueType;function s(u){let f=new Set;for(let l of u){if(l.status==="aborted")return _;l.status==="dirty"&&r.dirty(),f.add(l.value)}return{status:r.value,value:f}}let i=[...n.data.values()].map((u,f)=>o._parse(new z(n,u,n.path,f)));return n.common.async?Promise.all(i).then(u=>s(u)):s(i)}min(e,r){return new t({...this._def,minSize:{value:e,message:h.toString(r)}})}max(e,r){return new t({...this._def,maxSize:{value:e,message:h.toString(r)}})}size(e,r){return this.min(e,r).max(e,r)}nonempty(e){return this.min(1,e)}};Ye.create=(t,e)=>new Ye({valueType:t,minSize:null,maxSize:null,typeName:v.ZodSet,...b(e)});var Rt=class t extends T{constructor(){super(...arguments),this.validate=this.implement}_parse(e){let{ctx:r}=this._processInputParams(e);if(r.parsedType!==p.function)return d(r,{code:c.invalid_type,expected:p.function,received:r.parsedType}),_;function n(i,u){return gt({data:i,path:r.path,errorMaps:[r.common.contextualErrorMap,r.schemaErrorMap,He(),re].filter(f=>!!f),issueData:{code:c.invalid_arguments,argumentsError:u}})}function a(i,u){return gt({data:i,path:r.path,errorMaps:[r.common.contextualErrorMap,r.schemaErrorMap,He(),re].filter(f=>!!f),issueData:{code:c.invalid_return_type,returnTypeError:u}})}let o={errorMap:r.common.contextualErrorMap},s=r.data;if(this._def.returns instanceof de){let i=this;return j(async function(...u){let f=new B([]),l=await i._def.args.parseAsync(u,o).catch(x=>{throw f.addIssue(n(u,x)),f}),m=await Reflect.apply(s,this,l);return await i._def.returns._def.type.parseAsync(m,o).catch(x=>{throw f.addIssue(a(m,x)),f})})}else{let i=this;return j(function(...u){let f=i._def.args.safeParse(u,o);if(!f.success)throw new B([n(u,f.error)]);let l=Reflect.apply(s,this,f.data),m=i._def.returns.safeParse(l,o);if(!m.success)throw new B([a(l,m.error)]);return m.data})}}parameters(){return this._def.args}returnType(){return this._def.returns}args(...e){return new t({...this._def,args:J.create(e).rest(ae.create())})}returns(e){return new t({...this._def,returns:e})}implement(e){return this.parse(e)}strictImplement(e){return this.parse(e)}static create(e,r,n){return new t({args:e||J.create([]).rest(ae.create()),returns:r||ae.create(),typeName:v.ZodFunction,...b(n)})}},Le=class extends T{get schema(){return this._def.getter()}_parse(e){let{ctx:r}=this._processInputParams(e);return this._def.getter()._parse({data:r.data,path:r.path,parent:r})}};Le.create=(t,e)=>new Le({getter:t,typeName:v.ZodLazy,...b(e)});var Ce=class extends T{_parse(e){if(e.data!==this._def.value){let r=this._getOrReturnCtx(e);return d(r,{received:r.data,code:c.invalid_literal,expected:this._def.value}),_}return{status:"valid",value:e.data}}get value(){return this._def.value}};Ce.create=(t,e)=>new Ce({value:t,typeName:v.ZodLiteral,...b(e)});function Pr(t,e){return new Ne({values:t,typeName:v.ZodEnum,...b(e)})}var Ne=class t extends T{_parse(e){if(typeof e.data!="string"){let r=this._getOrReturnCtx(e),n=this._def.values;return d(r,{expected:I.joinValues(n),received:r.parsedType,code:c.invalid_type}),_}if(this._cache||(this._cache=new Set(this._def.values)),!this._cache.has(e.data)){let r=this._getOrReturnCtx(e),n=this._def.values;return d(r,{received:r.data,code:c.invalid_enum_value,options:n}),_}return j(e.data)}get options(){return this._def.values}get enum(){let e={};for(let r of this._def.values)e[r]=r;return e}get Values(){let e={};for(let r of this._def.values)e[r]=r;return e}get Enum(){let e={};for(let r of this._def.values)e[r]=r;return e}extract(e,r=this._def){return t.create(e,{...this._def,...r})}exclude(e,r=this._def){return t.create(this.options.filter(n=>!e.includes(n)),{...this._def,...r})}};Ne.create=Pr;var Pe=class extends T{_parse(e){let r=I.getValidEnumValues(this._def.values),n=this._getOrReturnCtx(e);if(n.parsedType!==p.string&&n.parsedType!==p.number){let a=I.objectValues(r);return d(n,{expected:I.joinValues(a),received:n.parsedType,code:c.invalid_type}),_}if(this._cache||(this._cache=new Set(I.getValidEnumValues(this._def.values))),!this._cache.has(e.data)){let a=I.objectValues(r);return d(n,{received:n.data,code:c.invalid_enum_value,options:a}),_}return j(e.data)}get enum(){return this._def.values}};Pe.create=(t,e)=>new Pe({values:t,typeName:v.ZodNativeEnum,...b(e)});var de=class extends T{unwrap(){return this._def.type}_parse(e){let{ctx:r}=this._processInputParams(e);if(r.parsedType!==p.promise&&r.common.async===!1)return d(r,{code:c.invalid_type,expected:p.promise,received:r.parsedType}),_;let n=r.parsedType===p.promise?r.data:Promise.resolve(r.data);return j(n.then(a=>this._def.type.parseAsync(a,{path:r.path,errorMap:r.common.contextualErrorMap})))}};de.create=(t,e)=>new de({type:t,typeName:v.ZodPromise,...b(e)});var V=class extends T{innerType(){return this._def.schema}sourceType(){return this._def.schema._def.typeName===v.ZodEffects?this._def.schema.sourceType():this._def.schema}_parse(e){let{status:r,ctx:n}=this._processInputParams(e),a=this._def.effect||null,o={addIssue:s=>{d(n,s),s.fatal?r.abort():r.dirty()},get path(){return n.path}};if(o.addIssue=o.addIssue.bind(o),a.type==="preprocess"){let s=a.transform(n.data,o);if(n.common.async)return Promise.resolve(s).then(async i=>{if(r.value==="aborted")return _;let u=await this._def.schema._parseAsync({data:i,path:n.path,parent:n});return u.status==="aborted"?_:u.status==="dirty"?Te(u.value):r.value==="dirty"?Te(u.value):u});{if(r.value==="aborted")return _;let i=this._def.schema._parseSync({data:s,path:n.path,parent:n});return i.status==="aborted"?_:i.status==="dirty"?Te(i.value):r.value==="dirty"?Te(i.value):i}}if(a.type==="refinement"){let s=i=>{let u=a.refinement(i,o);if(n.common.async)return Promise.resolve(u);if(u instanceof Promise)throw new Error("Async refinement encountered during synchronous parse operation. Use .parseAsync instead.");return i};if(n.common.async===!1){let i=this._def.schema._parseSync({data:n.data,path:n.path,parent:n});return i.status==="aborted"?_:(i.status==="dirty"&&r.dirty(),s(i.value),{status:r.value,value:i.value})}else return this._def.schema._parseAsync({data:n.data,path:n.path,parent:n}).then(i=>i.status==="aborted"?_:(i.status==="dirty"&&r.dirty(),s(i.value).then(()=>({status:r.value,value:i.value}))))}if(a.type==="transform")if(n.common.async===!1){let s=this._def.schema._parseSync({data:n.data,path:n.path,parent:n});if(!fe(s))return _;let i=a.transform(s.value,o);if(i instanceof Promise)throw new Error("Asynchronous transform encountered during synchronous parse operation. Use .parseAsync instead.");return{status:r.value,value:i}}else return this._def.schema._parseAsync({data:n.data,path:n.path,parent:n}).then(s=>fe(s)?Promise.resolve(a.transform(s.value,o)).then(i=>({status:r.value,value:i})):_);I.assertNever(a)}};V.create=(t,e,r)=>new V({schema:t,typeName:v.ZodEffects,effect:e,...b(r)});V.createWithPreprocess=(t,e,r)=>new V({schema:e,effect:{type:"preprocess",transform:t},typeName:v.ZodEffects,...b(r)});var H=class extends T{_parse(e){return this._getType(e)===p.undefined?j(void 0):this._def.innerType._parse(e)}unwrap(){return this._def.innerType}};H.create=(t,e)=>new H({innerType:t,typeName:v.ZodOptional,...b(e)});var X=class extends T{_parse(e){return this._getType(e)===p.null?j(null):this._def.innerType._parse(e)}unwrap(){return this._def.innerType}};X.create=(t,e)=>new X({innerType:t,typeName:v.ZodNullable,...b(e)});var Me=class extends T{_parse(e){let{ctx:r}=this._processInputParams(e),n=r.data;return r.parsedType===p.undefined&&(n=this._def.defaultValue()),this._def.innerType._parse({data:n,path:r.path,parent:r})}removeDefault(){return this._def.innerType}};Me.create=(t,e)=>new Me({innerType:t,typeName:v.ZodDefault,defaultValue:typeof e.default=="function"?e.default:()=>e.default,...b(e)});var De=class extends T{_parse(e){let{ctx:r}=this._processInputParams(e),n={...r,common:{...r.common,issues:[]}},a=this._def.innerType._parse({data:n.data,path:n.path,parent:{...n}});return ze(a)?a.then(o=>({status:"valid",value:o.status==="valid"?o.value:this._def.catchValue({get error(){return new B(n.common.issues)},input:n.data})})):{status:"valid",value:a.status==="valid"?a.value:this._def.catchValue({get error(){return new B(n.common.issues)},input:n.data})}}removeCatch(){return this._def.innerType}};De.create=(t,e)=>new De({innerType:t,typeName:v.ZodCatch,catchValue:typeof e.catch=="function"?e.catch:()=>e.catch,...b(e)});var qe=class extends T{_parse(e){if(this._getType(e)!==p.nan){let n=this._getOrReturnCtx(e);return d(n,{code:c.invalid_type,expected:p.nan,received:n.parsedType}),_}return{status:"valid",value:e.data}}};qe.create=t=>new qe({typeName:v.ZodNaN,...b(t)});var ss=Symbol("zod_brand"),yt=class extends T{_parse(e){let{ctx:r}=this._processInputParams(e),n=r.data;return this._def.type._parse({data:n,path:r.path,parent:r})}unwrap(){return this._def.type}},_t=class t extends T{_parse(e){let{status:r,ctx:n}=this._processInputParams(e);if(n.common.async)return(async()=>{let o=await this._def.in._parseAsync({data:n.data,path:n.path,parent:n});return o.status==="aborted"?_:o.status==="dirty"?(r.dirty(),Te(o.value)):this._def.out._parseAsync({data:o.value,path:n.path,parent:n})})();{let a=this._def.in._parseSync({data:n.data,path:n.path,parent:n});return a.status==="aborted"?_:a.status==="dirty"?(r.dirty(),{status:"dirty",value:a.value}):this._def.out._parseSync({data:a.value,path:n.path,parent:n})}}static create(e,r){return new t({in:e,out:r,typeName:v.ZodPipeline})}},$e=class extends T{_parse(e){let r=this._def.innerType._parse(e),n=a=>(fe(a)&&(a.value=Object.freeze(a.value)),a);return ze(r)?r.then(a=>n(a)):n(r)}unwrap(){return this._def.innerType}};$e.create=(t,e)=>new $e({innerType:t,typeName:v.ZodReadonly,...b(e)});function Rr(t,e){let r=typeof t=="function"?t(e):typeof t=="string"?{message:t}:t;return typeof r=="string"?{message:r}:r}function Mr(t,e={},r){return t?le.create().superRefine((n,a)=>{let o=t(n);if(o instanceof Promise)return o.then(s=>{if(!s){let i=Rr(e,n),u=i.fatal??r??!0;a.addIssue({code:"custom",...i,fatal:u})}});if(!o){let s=Rr(e,n),i=s.fatal??r??!0;a.addIssue({code:"custom",...s,fatal:i})}}):le.create()}var is={object:U.lazycreate},v;(function(t){t.ZodString="ZodString",t.ZodNumber="ZodNumber",t.ZodNaN="ZodNaN",t.ZodBigInt="ZodBigInt",t.ZodBoolean="ZodBoolean",t.ZodDate="ZodDate",t.ZodSymbol="ZodSymbol",t.ZodUndefined="ZodUndefined",t.ZodNull="ZodNull",t.ZodAny="ZodAny",t.ZodUnknown="ZodUnknown",t.ZodNever="ZodNever",t.ZodVoid="ZodVoid",t.ZodArray="ZodArray",t.ZodObject="ZodObject",t.ZodUnion="ZodUnion",t.ZodDiscriminatedUnion="ZodDiscriminatedUnion",t.ZodIntersection="ZodIntersection",t.ZodTuple="ZodTuple",t.ZodRecord="ZodRecord",t.ZodMap="ZodMap",t.ZodSet="ZodSet",t.ZodFunction="ZodFunction",t.ZodLazy="ZodLazy",t.ZodLiteral="ZodLiteral",t.ZodEnum="ZodEnum",t.ZodEffects="ZodEffects",t.ZodNativeEnum="ZodNativeEnum",t.ZodOptional="ZodOptional",t.ZodNullable="ZodNullable",t.ZodDefault="ZodDefault",t.ZodCatch="ZodCatch",t.ZodPromise="ZodPromise",t.ZodBranded="ZodBranded",t.ZodPipeline="ZodPipeline",t.ZodReadonly="ZodReadonly"})(v||(v={}));var us=(t,e={message:`Input not instance of ${t.name}`})=>Mr(r=>r instanceof t,e),Dr=ce.create,$r=Ie.create,fs=qe.create,cs=Ee.create,jr=Se.create,ls=Oe.create,ds=Ze.create,ps=we.create,ms=Ae.create,hs=le.create,gs=ae.create,ys=Z.create,_s=Ke.create,xs=oe.create,vs=U.create,bs=U.strictCreate,Ts=ke.create,Is=At.create,Es=Re.create,Ss=J.create,Os=kt.create,ws=We.create,As=Ye.create,ks=Rt.create,Rs=Le.create,Ls=Ce.create,Cs=Ne.create,Ns=Pe.create,Ps=de.create,Ms=V.create,Ds=H.create,$s=X.create,js=V.createWithPreprocess,Gs=_t.create,Bs=()=>Dr().optional(),Us=()=>$r().optional(),Fs=()=>jr().optional(),Hs={string:(t=>ce.create({...t,coerce:!0})),number:(t=>Ie.create({...t,coerce:!0})),boolean:(t=>Se.create({...t,coerce:!0})),bigint:(t=>Ee.create({...t,coerce:!0})),date:(t=>Oe.create({...t,coerce:!0}))};var zs=_;var Vs=typeof global=="object"&&global&&global.Object===Object&&global,Lt=Vs;var Zs=typeof self=="object"&&self&&self.Object===Object&&self,Ks=Lt||Zs||Function("return this")(),D=Ks;var Ws=D.Symbol,G=Ws;var Gr=Object.prototype,Ys=Gr.hasOwnProperty,qs=Gr.toString,xt=G?G.toStringTag:void 0;function Js(t){var e=Ys.call(t,xt),r=t[xt];try{t[xt]=void 0;var n=!0}catch{}var a=qs.call(t);return n&&(e?t[xt]=r:delete t[xt]),a}var Br=Js;var Xs=Object.prototype,Qs=Xs.toString;function ei(t){return Qs.call(t)}var Ur=ei;var ti="[object Null]",ri="[object Undefined]",Fr=G?G.toStringTag:void 0;function ni(t){return t==null?t===void 0?ri:ti:Fr&&Fr in Object(t)?Br(t):Ur(t)}var K=ni;function ai(t){return t!=null&&typeof t=="object"}var W=ai;var oi="[object Symbol]";function si(t){return typeof t=="symbol"||W(t)&&K(t)==oi}var se=si;function ii(t,e){for(var r=-1,n=t==null?0:t.length,a=Array(n);++r<n;)a[r]=e(t[r],r,t);return a}var Je=ii;var ui=Array.isArray,R=ui;var fi=1/0,Hr=G?G.prototype:void 0,zr=Hr?Hr.toString:void 0;function Vr(t){if(typeof t=="string")return t;if(R(t))return Je(t,Vr)+"";if(se(t))return zr?zr.call(t):"";var e=t+"";return e=="0"&&1/t==-fi?"-0":e}var Zr=Vr;function ci(t){var e=typeof t;return t!=null&&(e=="object"||e=="function")}var pe=ci;function li(t){return t}var me=li;var di="[object AsyncFunction]",pi="[object Function]",mi="[object GeneratorFunction]",hi="[object Proxy]";function gi(t){if(!pe(t))return!1;var e=K(t);return e==pi||e==mi||e==di||e==hi}var Ct=gi;var yi=D["__core-js_shared__"],Nt=yi;var Kr=(function(){var t=/[^.]+$/.exec(Nt&&Nt.keys&&Nt.keys.IE_PROTO||"");return t?"Symbol(src)_1."+t:""})();function _i(t){return!!Kr&&Kr in t}var Wr=_i;var xi=Function.prototype,vi=xi.toString;function bi(t){if(t!=null){try{return vi.call(t)}catch{}try{return t+""}catch{}}return""}var ie=bi;var Ti=/[\\^$.*+?()[\]{}|]/g,Ii=/^\[object .+?Constructor\]$/,Ei=Function.prototype,Si=Object.prototype,Oi=Ei.toString,wi=Si.hasOwnProperty,Ai=RegExp("^"+Oi.call(wi).replace(Ti,"\\$&").replace(/hasOwnProperty|(function).*?(?=\\\()| for .+?(?=\\\])/g,"$1.*?")+"$");function ki(t){if(!pe(t)||Wr(t))return!1;var e=Ct(t)?Ai:Ii;return e.test(ie(t))}var Yr=ki;function Ri(t,e){return t?.[e]}var qr=Ri;function Li(t,e){var r=qr(t,e);return Yr(r)?r:void 0}var F=Li;var Ci=F(D,"WeakMap"),Pt=Ci;function Ni(t,e,r){switch(r.length){case 0:return t.call(e);case 1:return t.call(e,r[0]);case 2:return t.call(e,r[0],r[1]);case 3:return t.call(e,r[0],r[1],r[2])}return t.apply(e,r)}var Jr=Ni;var Pi=800,Mi=16,Di=Date.now;function $i(t){var e=0,r=0;return function(){var n=Di(),a=Mi-(n-r);if(r=n,a>0){if(++e>=Pi)return arguments[0]}else e=0;return t.apply(void 0,arguments)}}var Xr=$i;function ji(t){return function(){return t}}var Qr=ji;var Gi=(function(){try{var t=F(Object,"defineProperty");return t({},"",{}),t}catch{}})(),Xe=Gi;var Bi=Xe?function(t,e){return Xe(t,"toString",{configurable:!0,enumerable:!1,value:Qr(e),writable:!0})}:me,en=Bi;var Ui=Xr(en),tn=Ui;var Fi=9007199254740991,Hi=/^(?:0|[1-9]\d*)$/;function zi(t,e){var r=typeof t;return e=e??Fi,!!e&&(r=="number"||r!="symbol"&&Hi.test(t))&&t>-1&&t%1==0&&t<e}var Qe=zi;function Vi(t,e,r){e=="__proto__"&&Xe?Xe(t,e,{configurable:!0,enumerable:!0,value:r,writable:!0}):t[e]=r}var rn=Vi;function Zi(t,e){return t===e||t!==t&&e!==e}var et=Zi;var nn=Math.max;function Ki(t,e,r){return e=nn(e===void 0?t.length-1:e,0),function(){for(var n=arguments,a=-1,o=nn(n.length-e,0),s=Array(o);++a<o;)s[a]=n[e+a];a=-1;for(var i=Array(e+1);++a<e;)i[a]=n[a];return i[e]=r(s),Jr(t,this,i)}}var an=Ki;function Wi(t,e){return tn(an(t,e,me),t+"")}var on=Wi;var Yi=9007199254740991;function qi(t){return typeof t=="number"&&t>-1&&t%1==0&&t<=Yi}var tt=qi;function Ji(t){return t!=null&&tt(t.length)&&!Ct(t)}var he=Ji;function Xi(t,e,r){if(!pe(r))return!1;var n=typeof e;return(n=="number"?he(r)&&Qe(e,r.length):n=="string"&&e in r)?et(r[e],t):!1}var ir=Xi;var Qi=Object.prototype;function eu(t){var e=t&&t.constructor,r=typeof e=="function"&&e.prototype||Qi;return t===r}var sn=eu;function tu(t,e){for(var r=-1,n=Array(t);++r<t;)n[r]=e(r);return n}var un=tu;var ru="[object Arguments]";function nu(t){return W(t)&&K(t)==ru}var ur=nu;var fn=Object.prototype,au=fn.hasOwnProperty,ou=fn.propertyIsEnumerable,su=ur((function(){return arguments})())?ur:function(t){return W(t)&&au.call(t,"callee")&&!ou.call(t,"callee")},rt=su;function iu(){return!1}var cn=iu;var pn=typeof exports=="object"&&exports&&!exports.nodeType&&exports,ln=pn&&typeof module=="object"&&module&&!module.nodeType&&module,uu=ln&&ln.exports===pn,dn=uu?D.Buffer:void 0,fu=dn?dn.isBuffer:void 0,cu=fu||cn,vt=cu;var lu="[object Arguments]",du="[object Array]",pu="[object Boolean]",mu="[object Date]",hu="[object Error]",gu="[object Function]",yu="[object Map]",_u="[object Number]",xu="[object Object]",vu="[object RegExp]",bu="[object Set]",Tu="[object String]",Iu="[object WeakMap]",Eu="[object ArrayBuffer]",Su="[object DataView]",Ou="[object Float32Array]",wu="[object Float64Array]",Au="[object Int8Array]",ku="[object Int16Array]",Ru="[object Int32Array]",Lu="[object Uint8Array]",Cu="[object Uint8ClampedArray]",Nu="[object Uint16Array]",Pu="[object Uint32Array]",k={};k[Ou]=k[wu]=k[Au]=k[ku]=k[Ru]=k[Lu]=k[Cu]=k[Nu]=k[Pu]=!0;k[lu]=k[du]=k[Eu]=k[pu]=k[Su]=k[mu]=k[hu]=k[gu]=k[yu]=k[_u]=k[xu]=k[vu]=k[bu]=k[Tu]=k[Iu]=!1;function Mu(t){return W(t)&&tt(t.length)&&!!k[K(t)]}var mn=Mu;function Du(t){return function(e){return t(e)}}var Mt=Du;var hn=typeof exports=="object"&&exports&&!exports.nodeType&&exports,bt=hn&&typeof module=="object"&&module&&!module.nodeType&&module,$u=bt&&bt.exports===hn,fr=$u&&Lt.process,ju=(function(){try{var t=bt&&bt.require&&bt.require("util").types;return t||fr&&fr.binding&&fr.binding("util")}catch{}})(),cr=ju;var gn=cr&&cr.isTypedArray,Gu=gn?Mt(gn):mn,Dt=Gu;var Bu=Object.prototype,Uu=Bu.hasOwnProperty;function Fu(t,e){var r=R(t),n=!r&&rt(t),a=!r&&!n&&vt(t),o=!r&&!n&&!a&&Dt(t),s=r||n||a||o,i=s?un(t.length,String):[],u=i.length;for(var f in t)(e||Uu.call(t,f))&&!(s&&(f=="length"||a&&(f=="offset"||f=="parent")||o&&(f=="buffer"||f=="byteLength"||f=="byteOffset")||Qe(f,u)))&&i.push(f);return i}var yn=Fu;function Hu(t,e){return function(r){return t(e(r))}}var _n=Hu;var zu=_n(Object.keys,Object),xn=zu;var Vu=Object.prototype,Zu=Vu.hasOwnProperty;function Ku(t){if(!sn(t))return xn(t);var e=[];for(var r in Object(t))Zu.call(t,r)&&r!="constructor"&&e.push(r);return e}var vn=Ku;function Wu(t){return he(t)?yn(t):vn(t)}var nt=Wu;var Yu=/\.|\[(?:[^[\]]*|(["'])(?:(?!\1)[^\\]|\\.)*?\1)\]/,qu=/^\w*$/;function Ju(t,e){if(R(t))return!1;var r=typeof t;return r=="number"||r=="symbol"||r=="boolean"||t==null||se(t)?!0:qu.test(t)||!Yu.test(t)||e!=null&&t in Object(e)}var at=Ju;var Xu=F(Object,"create"),ue=Xu;function Qu(){this.__data__=ue?ue(null):{},this.size=0}var bn=Qu;function ef(t){var e=this.has(t)&&delete this.__data__[t];return this.size-=e?1:0,e}var Tn=ef;var tf="__lodash_hash_undefined__",rf=Object.prototype,nf=rf.hasOwnProperty;function af(t){var e=this.__data__;if(ue){var r=e[t];return r===tf?void 0:r}return nf.call(e,t)?e[t]:void 0}var In=af;var of=Object.prototype,sf=of.hasOwnProperty;function uf(t){var e=this.__data__;return ue?e[t]!==void 0:sf.call(e,t)}var En=uf;var ff="__lodash_hash_undefined__";function cf(t,e){var r=this.__data__;return this.size+=this.has(t)?0:1,r[t]=ue&&e===void 0?ff:e,this}var Sn=cf;function ot(t){var e=-1,r=t==null?0:t.length;for(this.clear();++e<r;){var n=t[e];this.set(n[0],n[1])}}ot.prototype.clear=bn;ot.prototype.delete=Tn;ot.prototype.get=In;ot.prototype.has=En;ot.prototype.set=Sn;var lr=ot;function lf(){this.__data__=[],this.size=0}var On=lf;function df(t,e){for(var r=t.length;r--;)if(et(t[r][0],e))return r;return-1}var ge=df;var pf=Array.prototype,mf=pf.splice;function hf(t){var e=this.__data__,r=ge(e,t);if(r<0)return!1;var n=e.length-1;return r==n?e.pop():mf.call(e,r,1),--this.size,!0}var wn=hf;function gf(t){var e=this.__data__,r=ge(e,t);return r<0?void 0:e[r][1]}var An=gf;function yf(t){return ge(this.__data__,t)>-1}var kn=yf;function _f(t,e){var r=this.__data__,n=ge(r,t);return n<0?(++this.size,r.push([t,e])):r[n][1]=e,this}var Rn=_f;function st(t){var e=-1,r=t==null?0:t.length;for(this.clear();++e<r;){var n=t[e];this.set(n[0],n[1])}}st.prototype.clear=On;st.prototype.delete=wn;st.prototype.get=An;st.prototype.has=kn;st.prototype.set=Rn;var ye=st;var xf=F(D,"Map"),_e=xf;function vf(){this.size=0,this.__data__={hash:new lr,map:new(_e||ye),string:new lr}}var Ln=vf;function bf(t){var e=typeof t;return e=="string"||e=="number"||e=="symbol"||e=="boolean"?t!=="__proto__":t===null}var Cn=bf;function Tf(t,e){var r=t.__data__;return Cn(e)?r[typeof e=="string"?"string":"hash"]:r.map}var xe=Tf;function If(t){var e=xe(this,t).delete(t);return this.size-=e?1:0,e}var Nn=If;function Ef(t){return xe(this,t).get(t)}var Pn=Ef;function Sf(t){return xe(this,t).has(t)}var Mn=Sf;function Of(t,e){var r=xe(this,t),n=r.size;return r.set(t,e),this.size+=r.size==n?0:1,this}var Dn=Of;function it(t){var e=-1,r=t==null?0:t.length;for(this.clear();++e<r;){var n=t[e];this.set(n[0],n[1])}}it.prototype.clear=Ln;it.prototype.delete=Nn;it.prototype.get=Pn;it.prototype.has=Mn;it.prototype.set=Dn;var je=it;var wf="Expected a function";function dr(t,e){if(typeof t!="function"||e!=null&&typeof e!="function")throw new TypeError(wf);var r=function(){var n=arguments,a=e?e.apply(this,n):n[0],o=r.cache;if(o.has(a))return o.get(a);var s=t.apply(this,n);return r.cache=o.set(a,s)||o,s};return r.cache=new(dr.Cache||je),r}dr.Cache=je;var $n=dr;var Af=500;function kf(t){var e=$n(t,function(n){return r.size===Af&&r.clear(),n}),r=e.cache;return e}var jn=kf;var Rf=/[^.[\]]+|\[(?:(-?\d+(?:\.\d+)?)|(["'])((?:(?!\2)[^\\]|\\.)*?)\2)\]|(?=(?:\.|\[\])(?:\.|\[\]|$))/g,Lf=/\\(\\)?/g,Cf=jn(function(t){var e=[];return t.charCodeAt(0)===46&&e.push(""),t.replace(Rf,function(r,n,a,o){e.push(a?o.replace(Lf,"$1"):n||r)}),e}),Gn=Cf;function Nf(t){return t==null?"":Zr(t)}var Bn=Nf;function Pf(t,e){return R(t)?t:at(t,e)?[t]:Gn(Bn(t))}var $t=Pf;var Mf=1/0;function Df(t){if(typeof t=="string"||se(t))return t;var e=t+"";return e=="0"&&1/t==-Mf?"-0":e}var ve=Df;function $f(t,e){e=$t(e,t);for(var r=0,n=e.length;t!=null&&r<n;)t=t[ve(e[r++])];return r&&r==n?t:void 0}var ut=$f;function jf(t,e,r){var n=t==null?void 0:ut(t,e);return n===void 0?r:n}var Un=jf;function Gf(t,e){for(var r=-1,n=e.length,a=t.length;++r<n;)t[a+r]=e[r];return t}var jt=Gf;var Fn=G?G.isConcatSpreadable:void 0;function Bf(t){return R(t)||rt(t)||!!(Fn&&t&&t[Fn])}var Hn=Bf;function zn(t,e,r,n,a){var o=-1,s=t.length;for(r||(r=Hn),a||(a=[]);++o<s;){var i=t[o];e>0&&r(i)?e>1?zn(i,e-1,r,n,a):jt(a,i):n||(a[a.length]=i)}return a}var Vn=zn;function Uf(){this.__data__=new ye,this.size=0}var Zn=Uf;function Ff(t){var e=this.__data__,r=e.delete(t);return this.size=e.size,r}var Kn=Ff;function Hf(t){return this.__data__.get(t)}var Wn=Hf;function zf(t){return this.__data__.has(t)}var Yn=zf;var Vf=200;function Zf(t,e){var r=this.__data__;if(r instanceof ye){var n=r.__data__;if(!_e||n.length<Vf-1)return n.push([t,e]),this.size=++r.size,this;r=this.__data__=new je(n)}return r.set(t,e),this.size=r.size,this}var qn=Zf;function ft(t){var e=this.__data__=new ye(t);this.size=e.size}ft.prototype.clear=Zn;ft.prototype.delete=Kn;ft.prototype.get=Wn;ft.prototype.has=Yn;ft.prototype.set=qn;var ct=ft;function Kf(t,e){for(var r=-1,n=t==null?0:t.length,a=0,o=[];++r<n;){var s=t[r];e(s,r,t)&&(o[a++]=s)}return o}var Jn=Kf;function Wf(){return[]}var Xn=Wf;var Yf=Object.prototype,qf=Yf.propertyIsEnumerable,Qn=Object.getOwnPropertySymbols,Jf=Qn?function(t){return t==null?[]:(t=Object(t),Jn(Qn(t),function(e){return qf.call(t,e)}))}:Xn,ea=Jf;function Xf(t,e,r){var n=e(t);return R(t)?n:jt(n,r(t))}var ta=Xf;function Qf(t){return ta(t,nt,ea)}var pr=Qf;var ec=F(D,"DataView"),Gt=ec;var tc=F(D,"Promise"),Bt=tc;var rc=F(D,"Set"),Ut=rc;var ra="[object Map]",nc="[object Object]",na="[object Promise]",aa="[object Set]",oa="[object WeakMap]",sa="[object DataView]",ac=ie(Gt),oc=ie(_e),sc=ie(Bt),ic=ie(Ut),uc=ie(Pt),Ge=K;(Gt&&Ge(new Gt(new ArrayBuffer(1)))!=sa||_e&&Ge(new _e)!=ra||Bt&&Ge(Bt.resolve())!=na||Ut&&Ge(new Ut)!=aa||Pt&&Ge(new Pt)!=oa)&&(Ge=function(t){var e=K(t),r=e==nc?t.constructor:void 0,n=r?ie(r):"";if(n)switch(n){case ac:return sa;case oc:return ra;case sc:return na;case ic:return aa;case uc:return oa}return e});var mr=Ge;var fc=D.Uint8Array,hr=fc;var cc="__lodash_hash_undefined__";function lc(t){return this.__data__.set(t,cc),this}var ia=lc;function dc(t){return this.__data__.has(t)}var ua=dc;function Ft(t){var e=-1,r=t==null?0:t.length;for(this.__data__=new je;++e<r;)this.add(t[e])}Ft.prototype.add=Ft.prototype.push=ia;Ft.prototype.has=ua;var fa=Ft;function pc(t,e){for(var r=-1,n=t==null?0:t.length;++r<n;)if(e(t[r],r,t))return!0;return!1}var ca=pc;function mc(t,e){return t.has(e)}var la=mc;var hc=1,gc=2;function yc(t,e,r,n,a,o){var s=r&hc,i=t.length,u=e.length;if(i!=u&&!(s&&u>i))return!1;var f=o.get(t),l=o.get(e);if(f&&l)return f==e&&l==t;var m=-1,g=!0,x=r&gc?new fa:void 0;for(o.set(t,e),o.set(e,t);++m<i;){var w=t[m],E=e[m];if(n)var S=s?n(E,w,m,e,t,o):n(w,E,m,t,e,o);if(S!==void 0){if(S)continue;g=!1;break}if(x){if(!ca(e,function(M,ee){if(!la(x,ee)&&(w===M||a(w,M,r,n,o)))return x.push(ee)})){g=!1;break}}else if(!(w===E||a(w,E,r,n,o))){g=!1;break}}return o.delete(t),o.delete(e),g}var Ht=yc;function _c(t){var e=-1,r=Array(t.size);return t.forEach(function(n,a){r[++e]=[a,n]}),r}var da=_c;function xc(t){var e=-1,r=Array(t.size);return t.forEach(function(n){r[++e]=n}),r}var pa=xc;var vc=1,bc=2,Tc="[object Boolean]",Ic="[object Date]",Ec="[object Error]",Sc="[object Map]",Oc="[object Number]",wc="[object RegExp]",Ac="[object Set]",kc="[object String]",Rc="[object Symbol]",Lc="[object ArrayBuffer]",Cc="[object DataView]",ma=G?G.prototype:void 0,gr=ma?ma.valueOf:void 0;function Nc(t,e,r,n,a,o,s){switch(r){case Cc:if(t.byteLength!=e.byteLength||t.byteOffset!=e.byteOffset)return!1;t=t.buffer,e=e.buffer;case Lc:return!(t.byteLength!=e.byteLength||!o(new hr(t),new hr(e)));case Tc:case Ic:case Oc:return et(+t,+e);case Ec:return t.name==e.name&&t.message==e.message;case wc:case kc:return t==e+"";case Sc:var i=da;case Ac:var u=n&vc;if(i||(i=pa),t.size!=e.size&&!u)return!1;var f=s.get(t);if(f)return f==e;n|=bc,s.set(t,e);var l=Ht(i(t),i(e),n,a,o,s);return s.delete(t),l;case Rc:if(gr)return gr.call(t)==gr.call(e)}return!1}var ha=Nc;var Pc=1,Mc=Object.prototype,Dc=Mc.hasOwnProperty;function $c(t,e,r,n,a,o){var s=r&Pc,i=pr(t),u=i.length,f=pr(e),l=f.length;if(u!=l&&!s)return!1;for(var m=u;m--;){var g=i[m];if(!(s?g in e:Dc.call(e,g)))return!1}var x=o.get(t),w=o.get(e);if(x&&w)return x==e&&w==t;var E=!0;o.set(t,e),o.set(e,t);for(var S=s;++m<u;){g=i[m];var M=t[g],ee=e[g];if(n)var Et=s?n(ee,M,g,e,t,o):n(M,ee,g,t,e,o);if(!(Et===void 0?M===ee||a(M,ee,r,n,o):Et)){E=!1;break}S||(S=g=="constructor")}if(E&&!S){var Fe=t.constructor,St=e.constructor;Fe!=St&&"constructor"in t&&"constructor"in e&&!(typeof Fe=="function"&&Fe instanceof Fe&&typeof St=="function"&&St instanceof St)&&(E=!1)}return o.delete(t),o.delete(e),E}var ga=$c;var jc=1,ya="[object Arguments]",_a="[object Array]",zt="[object Object]",Gc=Object.prototype,xa=Gc.hasOwnProperty;function Bc(t,e,r,n,a,o){var s=R(t),i=R(e),u=s?_a:mr(t),f=i?_a:mr(e);u=u==ya?zt:u,f=f==ya?zt:f;var l=u==zt,m=f==zt,g=u==f;if(g&&vt(t)){if(!vt(e))return!1;s=!0,l=!1}if(g&&!l)return o||(o=new ct),s||Dt(t)?Ht(t,e,r,n,a,o):ha(t,e,u,r,n,a,o);if(!(r&jc)){var x=l&&xa.call(t,"__wrapped__"),w=m&&xa.call(e,"__wrapped__");if(x||w){var E=x?t.value():t,S=w?e.value():e;return o||(o=new ct),a(E,S,r,n,o)}}return g?(o||(o=new ct),ga(t,e,r,n,a,o)):!1}var va=Bc;function ba(t,e,r,n,a){return t===e?!0:t==null||e==null||!W(t)&&!W(e)?t!==t&&e!==e:va(t,e,r,n,ba,a)}var Vt=ba;var Uc=1,Fc=2;function Hc(t,e,r,n){var a=r.length,o=a,s=!n;if(t==null)return!o;for(t=Object(t);a--;){var i=r[a];if(s&&i[2]?i[1]!==t[i[0]]:!(i[0]in t))return!1}for(;++a<o;){i=r[a];var u=i[0],f=t[u],l=i[1];if(s&&i[2]){if(f===void 0&&!(u in t))return!1}else{var m=new ct;if(n)var g=n(f,l,u,t,e,m);if(!(g===void 0?Vt(l,f,Uc|Fc,n,m):g))return!1}}return!0}var Ta=Hc;function zc(t){return t===t&&!pe(t)}var Zt=zc;function Vc(t){for(var e=nt(t),r=e.length;r--;){var n=e[r],a=t[n];e[r]=[n,a,Zt(a)]}return e}var Ia=Vc;function Zc(t,e){return function(r){return r==null?!1:r[t]===e&&(e!==void 0||t in Object(r))}}var Kt=Zc;function Kc(t){var e=Ia(t);return e.length==1&&e[0][2]?Kt(e[0][0],e[0][1]):function(r){return r===t||Ta(r,t,e)}}var Ea=Kc;function Wc(t,e){return t!=null&&e in Object(t)}var Sa=Wc;function Yc(t,e,r){e=$t(e,t);for(var n=-1,a=e.length,o=!1;++n<a;){var s=ve(e[n]);if(!(o=t!=null&&r(t,s)))break;t=t[s]}return o||++n!=a?o:(a=t==null?0:t.length,!!a&&tt(a)&&Qe(s,a)&&(R(t)||rt(t)))}var Oa=Yc;function qc(t,e){return t!=null&&Oa(t,e,Sa)}var wa=qc;var Jc=1,Xc=2;function Qc(t,e){return at(t)&&Zt(e)?Kt(ve(t),e):function(r){var n=Un(r,t);return n===void 0&&n===e?wa(r,t):Vt(e,n,Jc|Xc)}}var Aa=Qc;function el(t){return function(e){return e?.[t]}}var ka=el;function tl(t){return function(e){return ut(e,t)}}var Ra=tl;function rl(t){return at(t)?ka(ve(t)):Ra(t)}var La=rl;function nl(t){return typeof t=="function"?t:t==null?me:typeof t=="object"?R(t)?Aa(t[0],t[1]):Ea(t):La(t)}var Wt=nl;function al(t,e,r,n){for(var a=-1,o=t==null?0:t.length;++a<o;){var s=t[a];e(n,s,r(s),t)}return n}var Ca=al;function ol(t){return function(e,r,n){for(var a=-1,o=Object(e),s=n(e),i=s.length;i--;){var u=s[t?i:++a];if(r(o[u],u,o)===!1)break}return e}}var Na=ol;var sl=Na(),Pa=sl;function il(t,e){return t&&Pa(t,e,nt)}var Ma=il;function ul(t,e){return function(r,n){if(r==null)return r;if(!he(r))return t(r,n);for(var a=r.length,o=e?a:-1,s=Object(r);(e?o--:++o<a)&&n(s[o],o,s)!==!1;);return r}}var Da=ul;var fl=Da(Ma),Yt=fl;function cl(t,e,r,n){return Yt(t,function(a,o,s){e(n,a,r(a),s)}),n}var $a=cl;function ll(t,e){return function(r,n){var a=R(r)?Ca:$a,o=e?e():{};return a(r,t,Wt(n,2),o)}}var ja=ll;function dl(t,e){var r=-1,n=he(t)?Array(t.length):[];return Yt(t,function(a,o,s){n[++r]=e(a,o,s)}),n}var Ga=dl;var pl=Object.prototype,ml=pl.hasOwnProperty,hl=ja(function(t,e,r){ml.call(t,r)?t[r].push(e):rn(t,r,[e])}),Tt=hl;function gl(t,e){var r=t.length;for(t.sort(e);r--;)t[r]=t[r].value;return t}var Ba=gl;function yl(t,e){if(t!==e){var r=t!==void 0,n=t===null,a=t===t,o=se(t),s=e!==void 0,i=e===null,u=e===e,f=se(e);if(!i&&!f&&!o&&t>e||o&&s&&u&&!i&&!f||n&&s&&u||!r&&u||!a)return 1;if(!n&&!o&&!f&&t<e||f&&r&&a&&!n&&!o||i&&r&&a||!s&&a||!u)return-1}return 0}var Ua=yl;function _l(t,e,r){for(var n=-1,a=t.criteria,o=e.criteria,s=a.length,i=r.length;++n<s;){var u=Ua(a[n],o[n]);if(u){if(n>=i)return u;var f=r[n];return u*(f=="desc"?-1:1)}}return t.index-e.index}var Fa=_l;function xl(t,e,r){e.length?e=Je(e,function(o){return R(o)?function(s){return ut(s,o.length===1?o[0]:o)}:o}):e=[me];var n=-1;e=Je(e,Mt(Wt));var a=Ga(t,function(o,s,i){var u=Je(e,function(f){return f(o)});return{criteria:u,index:++n,value:o}});return Ba(a,function(o,s){return Fa(o,s,r)})}var Ha=xl;var vl=on(function(t,e){if(t==null)return[];var r=e.length;return r>1&&ir(t,e[0],e[1])?e=[]:r>2&&ir(e[0],e[1],e[2])&&(e=[e[0]]),Ha(t,Vn(e,1),[])}),yr=vl;Y();function O(t){return{content:[{type:"text",text:t}]}}function Q(t,e){return!t||t.length<=e?t:t.slice(0,e)+"..."}var ht=200;function Io(t){t.tool("search",`Search Sigil knowledge base for facts across all ingested documents.
8
+ Run \`sigil init\` for an interactive setup.`);Ql={db:{type:"postgres",get url(){return process.env.SIGIL_DATABASE_URL||process.env.DATABASE_URL||P().database.url||null},get host(){return process.env.SIGIL_DB_HOST||P().database.host||"localhost"},get port(){return Number(process.env.SIGIL_DB_PORT||P().database.port||5432)},get database(){return process.env.SIGIL_DB_NAME||P().database.name||"sigil"},get user(){return process.env.SIGIL_DB_USER||P().database.user||"sigil_app"},get password(){return process.env.SIGIL_DB_PASSWORD||P().database.password||""}},embedding:{get provider(){return process.env.EMBEDDING_PROVIDER||P().embedding.provider||""},get model(){return process.env.EMBEDDING_MODEL||P().embedding.model||"mxbai-embed-large"},get dimensions(){return 1024},get ollamaHost(){return process.env.OLLAMA_HOST||(P().embedding.provider==="ollama"?P().embedding.host:"")||"http://localhost:11434"},get openaiApiKey(){return process.env.OPENAI_API_KEY||Rr("openai")},get voyageApiKey(){return process.env.VOYAGE_API_KEY||Rr("voyage")},get openrouterApiKey(){return process.env.OPENROUTER_API_KEY||Rr("openrouter")},openrouterBaseUrl:process.env.EMBEDDING_OPENROUTER_BASE_URL||process.env.LLM_OPENROUTER_BASE_URL||"",openrouterReferer:process.env.EMBEDDING_OPENROUTER_REFERER||process.env.LLM_OPENROUTER_REFERER||"https://github.com/Anmol-Srv/sigil",openrouterTitle:process.env.EMBEDDING_OPENROUTER_TITLE||process.env.LLM_OPENROUTER_TITLE||"Sigil"},llm:{get provider(){return process.env.LLM_PROVIDER||P().llm.provider||""},get openaiApiKey(){return process.env.OPENAI_API_KEY||kr("openai")},get openaiModel(){return process.env.LLM_OPENAI_MODEL||fr("openai")||"gpt-4o-mini"},get ollamaHost(){return process.env.LLM_OLLAMA_HOST||process.env.OLLAMA_HOST||(P().llm.provider==="ollama"?P().llm.host:"")||"http://localhost:11434"},get ollamaModel(){return process.env.LLM_OLLAMA_MODEL||fr("ollama")||"qwen2.5:7b"},get cliModel(){return process.env.LLM_CLI_MODEL||fr("claude-cli")||"haiku"},get cliPath(){return process.env.LLM_CLI_PATH||""},get apiKey(){return process.env.ANTHROPIC_API_KEY||kr("anthropic")},get openrouterApiKey(){return process.env.OPENROUTER_API_KEY||kr("openrouter")},get openrouterModel(){return process.env.LLM_OPENROUTER_MODEL||fr("openrouter")||"google/gemini-flash-latest"},get openrouterBaseUrl(){return process.env.LLM_OPENROUTER_BASE_URL||""},get openrouterReferer(){return process.env.LLM_OPENROUTER_REFERER||"https://github.com/Anmol-Srv/sigil"},get openrouterTitle(){return process.env.LLM_OPENROUTER_TITLE||"Sigil"},get extractionModel(){return process.env.LLM_EXTRACTION_MODEL||""},get decisionModel(){return process.env.LLM_DECISION_MODEL||""},get entityModel(){return process.env.LLM_ENTITY_MODEL||""},get maxRetries(){return Number(process.env.LLM_MAX_RETRIES)||3},get cliTimeout(){return Number(process.env.LLM_CLI_TIMEOUT)||12e4},get requestTimeout(){return Number(process.env.LLM_REQUEST_TIMEOUT)||6e4}},output:{storage:process.env.OUTPUT_STORAGE||"local",dir:process.env.OUTPUT_DIR||"./output",s3:{endpoint:process.env.S3_ENDPOINT||"",bucket:process.env.S3_BUCKET||"",region:process.env.S3_REGION||"us-east-1",accessKey:process.env.S3_ACCESS_KEY||"",secretKey:process.env.S3_SECRET_KEY||"",publicUrl:process.env.S3_PUBLIC_URL||""}},server:{port:Number(process.env.PORT)||4e3,host:process.env.HOST||"0.0.0.0",logLevel:process.env.LOG_LEVEL||"info"},http:{enabled:N("SIGIL_HTTP_ENABLED","true")!=="false",host:N("SIGIL_HTTP_HOST","127.0.0.1"),port:Number(N("SIGIL_HTTP_PORT",7777))},network:{mode:N("SIGIL_MODE","solo"),enabled:N("SIGIL_NETWORK_ENABLED",null)===null?N("SIGIL_MODE","solo")!=="solo":N("SIGIL_NETWORK_ENABLED","false")!=="false",masterNodeId:N("SIGIL_MASTER_NODE_ID","")||null},defaults:{namespace:process.env.DEFAULT_NAMESPACE||"default"},memory:{skipThreshold:Number(process.env.MEMORY_SKIP_THRESHOLD)||.88,ambiguousThreshold:Number(process.env.MEMORY_AMBIGUOUS_THRESHOLD)||.78,minFactSimilarity:Number(process.env.MEMORY_MIN_FACT_SIMILARITY)||.45,injectionFloor:Number(process.env.MEMORY_INJECTION_FLOOR)||.6},search:{synthesize:N("SIGIL_SYNTHESIZE","true")!=="false",synthesizeModel:N("SIGIL_SYNTH_MODEL","")},ingest:{eagerExtract:N("SIGIL_EAGER_EXTRACT","true")!=="false"},hebbian:{entity:{enabled:N("SIGIL_HEBBIAN_ENTITY_ENABLED",null,"true")!=="false",eta:Number(N("SIGIL_HEBBIAN_ENTITY_ETA",null,1)),cap:Number(N("SIGIL_HEBBIAN_ENTITY_CAP",null,50)),halfLifeDays:Number(N("SIGIL_HEBBIAN_ENTITY_HALF_LIFE_DAYS",null,30)),minEffective:Number(N("SIGIL_HEBBIAN_ENTITY_MIN_EFFECTIVE",null,.5)),rrfWeight:Number(N("SIGIL_HEBBIAN_ENTITY_RRF_WEIGHT",null,.3)),maxWriteEntities:Number(N("SIGIL_HEBBIAN_ENTITY_MAX_WRITE",null,12)),expandPerSeed:Number(N("SIGIL_HEBBIAN_ENTITY_EXPAND_PER_SEED",null,3))}}},ed=Ql});import{readFile as po,writeFile as Hv,unlink as mo,mkdir as zv}from"node:fs/promises";import{existsSync as ho}from"node:fs";function td(t){if(!t||!Number.isFinite(t))return!1;try{return process.kill(t,0),!0}catch(e){return e.code==="EPERM"}}async function rd(){if(!ho(or))return null;try{let t=(await po(or,"utf8")).trim(),e=Number(t);return Number.isFinite(e)?e:null}catch{return null}}async function nd(){try{await mo(or)}catch{}}async function ad(){try{await mo(Fe)}catch{}}async function od(){try{let t=JSON.parse(await po(to,"utf8"));return Number.isFinite(t?.pid)?t.pid:null}catch{return null}}async function sd(){try{let{default:t}=await Promise.resolve().then(()=>(lo(),fo));if(!t.http.enabled)return!1;let{host:e,port:r}=t.http,n=new AbortController,a=setTimeout(()=>n.abort(),500);try{return(await fetch(`http://${e}:${r}/healthz`,{signal:n.signal})).ok}finally{clearTimeout(a)}}catch{return!1}}async function go(){let t=await rd();return t&&td(t)?t:await sd()?await od()??"unknown":(t&&await nd(),ho(Fe)&&await ad(),null)}var yo=W(()=>{ht()});import{existsSync as id}from"node:fs";import{dirname as cd,join as Lr}from"node:path";import{fileURLToPath as ud}from"node:url";function _o(){let t=[Lr(Ue,"dist","daemon.js"),Lr(Ue,"src","daemon","index.js"),Lr(cd(ud(import.meta.url)),"..","daemon","index.js")];for(let e of t)if(id(e))return e;throw new Error("cannot locate daemon entry point (looked in dist/ and src/daemon/)")}var xo=W(()=>{ht()});import{connect as fd}from"node:net";import{randomUUID as ld}from"node:crypto";function lr({path:t=Fe,timeoutMs:e=3e4}={}){return new Promise((r,n)=>{let a=fd(t),o=new Map,s="",i=!1;a.setEncoding("utf8"),a.once("connect",()=>{a.off("error",c),r(u())});function c(l){n(l)}a.once("error",c),a.on("data",l=>{s+=l;let m;for(;(m=s.indexOf(`
9
+ `))!==-1;){let g=s.slice(0,m);if(s=s.slice(m+1),!g.trim())continue;let x;try{x=JSON.parse(g)}catch{continue}let O=o.get(x.id);O&&(o.delete(x.id),clearTimeout(O.timer),x.ok?O.resolve(x):O.reject(new Cr(x.error||{})))}}),a.on("close",()=>{i=!0;for(let[,l]of o)clearTimeout(l.timer),l.reject(new Error("daemon connection closed"));o.clear()}),a.on("error",()=>{});function u(){return{call(l,m){if(i)return Promise.reject(new Error("client is closed"));let g=ld(),x=process.env.SIGIL_AGENT||null,O=JSON.stringify({id:g,method:l,params:m,agent:x})+`
10
+ `;return new Promise((S,w)=>{let M=setTimeout(()=>{o.delete(g)&&w(new Error(`rpc timeout after ${e}ms: ${l}`))},e);o.set(g,{resolve:S,reject:w,timer:M}),a.write(O)})},close(){return new Promise(l=>{if(i)return l();a.end(()=>l())})}}}})}var Cr,vo=W(()=>{ht();Cr=class extends Error{constructor({code:e,message:r,stack:n}){super(r||e||"rpc error"),this.name="SigilRpcError",this.code=e||"handler_error",n&&(this.remoteStack=n)}}});import{spawn as dd}from"node:child_process";import{existsSync as pd,openSync as bo,closeSync as To,mkdirSync as md}from"node:fs";import{setTimeout as hd}from"node:timers/promises";async function dr({quiet:t=!1}={}){return await Eo()?lr():(t||process.stderr.write(`[sigil] daemon not running, starting it...
11
+ `),await _d(),await xd(),lr())}async function Eo(){if(!pd(Fe))return!1;try{let t=await lr({timeoutMs:1e3});return await t.call("ping",{}),await t.close(),!0}catch{return!1}}async function _d(){md(C,{recursive:!0}),await go();let t=_o(),e=bo(sr,"a"),r=bo(sr,"a");dd(process.execPath,[t],{detached:!0,stdio:["ignore",e,r],env:{...process.env,SIGIL_DAEMON_AUTOSPAWN:"1"}}).unref();try{To(e)}catch{}try{To(r)}catch{}}async function xd(){let t=Date.now()+Io,e=gd;for(;Date.now()<t;){if(await Eo())return;await hd(e),e=Math.min(e*2,yd)}throw new Error(`daemon did not become ready within ${Io}ms \u2014 check ${sr}`)}var Io,gd,yd,Nr=W(()=>{ht();yo();xo();vo();Io=5e3,gd=25,yd=400});var wo={};Ze(wo,{closeDaemonConnection:()=>Td,daemonCall:()=>L});async function So(){return vt||(xt||(xt=dr({quiet:!0}).then(t=>(vt=t,t)).catch(t=>{throw xt=null,t})),xt)}function bd(t){return t?t.code&&vd.has(t.code)?!0:/^daemon connection closed/i.test(t.message||""):!1}async function L(t,e){let r=await So();try{let{data:n}=await r.call(t,e??{});return n}catch(n){if(bd(n)){vt=null,xt=null;let a=await So(),{data:o}=await a.call(t,e??{});return o}throw n}}async function Td(){let t=vt;vt=null,xt=null,t&&await t.close()}var xt,vt,vd,Z=W(()=>{Nr();xt=null,vt=null;vd=new Set(["ECONNREFUSED","ENOENT","EPIPE","ECONNRESET"])});var Do={};Ze(Do,{buildPreamble:()=>Ed});async function Ed({cwd:t=process.cwd(),limit:e=12,call:r}={}){let n={state:"ready",checks:{},config:{},totals:{facts:0,documents:0},facts:[],issues:[]};n.config=await Sd(),n.checks.llm=n.config.llmProvider?{ok:!0,detail:`${n.config.llmProvider}${n.config.llmModel?`/${n.config.llmModel}`:""}`}:{ok:!1,detail:"not configured"},n.checks.embedding=n.config.embProvider?{ok:!0,detail:`${n.config.embProvider}/${n.config.embModel} (dim=${n.config.dim})`}:{ok:!1,detail:"not configured"},n.config.llmProvider||n.issues.push("No LLM provider configured \u2014 fact extraction is off. Run `sigil init`."),n.config.embProvider||n.issues.push("No embedding provider configured \u2014 semantic search is off. Run `sigil init`.");let a=null,o=r;if(!o)try{a=await dr({quiet:!0}),o=async(s,i)=>(await a.call(s,i??{})).data}catch(s){return n.checks.daemon={ok:!1,detail:s.message},n.issues.push("Sigil daemon not reachable \u2014 run `npx sigil` (or `sigil daemon start`)."),$o(n)}n.checks.daemon={ok:!0};try{let s=null;try{s=await o("status",{}),n.totals={facts:s.facts??0,documents:s.documents??0},n.checks.db=s.db?.healthy?{ok:!0,detail:`${s.facts??0} facts`}:{ok:!1,detail:s.db?.error||"unreachable"},s.db?.healthy||n.issues.push(`Database unreachable: ${s.db?.error||"unknown"} \u2014 check Postgres, then \`sigil doctor\`.`)}catch(i){n.checks.db={ok:!1,detail:i.message},n.issues.push(`Could not query Sigil status: ${i.message}`)}try{let i=await o("setup.state",{});n.checks.setup=i.complete?{ok:!0}:{ok:!1,detail:`next: ${i.currentStep}`},i.complete||n.issues.push(`Setup incomplete \u2014 next step "${i.currentStep}". Run \`sigil init\` or open the GUI.`)}catch{}if(n.checks.db?.ok)try{let i=await o("refreshContext.explain",{cwd:t}),c=new Set;for(let u of i.sections||[]){for(let l of u.facts||[]){let m=(typeof l=="string"?l:l.content||"").trim();if(m&&!c.has(m)&&(c.add(m),n.facts.push({content:m,section:u.name}),n.facts.length>=e))break}if(n.facts.length>=e)break}}catch(i){n.checks.collection={ok:!1,detail:i.message}}}finally{if(a)try{await a.close()}catch{}}return $o(n)}function $o(t){let e=t.checks.daemon&&!t.checks.daemon.ok,r=t.checks.db&&!t.checks.db.ok,n=t.checks.setup&&!t.checks.setup.ok||!t.checks.llm.ok||!t.checks.embedding.ok;return e||r?t.state="degraded":n?t.state="setup":t.state="ready",t}async function Sd(){try{let{getConfig:t}=await Promise.resolve().then(()=>(Ar(),co)),e=t();return{llmProvider:e.llm?.provider||"",llmModel:e.llm?.model||"",embProvider:e.embedding?.provider||"",embModel:e.embedding?.model||"",dim:1024,name:e.identity?.name||""}}catch{return{llmProvider:"",llmModel:"",embProvider:"",embModel:"",dim:1024,name:""}}}var jo=W(()=>{Nr();ir()});var Go={};Ze(Go,{renderPreamble:()=>wd,statusLines:()=>Pr});function wd(t,{format:e="md",transport:r="cli"}={}){if(e==="json")return JSON.stringify(t,null,2);if(e==="lines")return Pr(t).join(`
12
+ `);let n=[...Pr(t),""];if(t.facts.length){n.push(`## Sigil memory (${t.facts.length} facts loaded at session start)`);for(let a of t.facts)n.push(`- ${a.content}`)}else t.state==="degraded"?(n.push("## Sigil memory"),n.push("- (unavailable \u2014 see the health warnings below)")):(n.push("## Sigil memory"),n.push("- (nothing stored yet \u2014 facts accrue as you and the user work)"));if(n.push("",Od(r)),t.issues.length){n.push("","## Sigil health");for(let a of t.issues)n.push(`- \u26A0 ${a}`)}return n.join(`
13
+ `)}function Pr(t){let e=[`SIGIL: ${t.state}`];return t.checks.daemon&&e.push(`DAEMON: ${t.checks.daemon.ok?"up":`down (${t.checks.daemon.detail||"unreachable"})`}`),t.checks.db&&e.push(`DB: ${t.checks.db.ok?`ok${t.checks.db.detail?` (${t.checks.db.detail})`:""}`:`down (${t.checks.db.detail||"unreachable"})`}`),e.push(`LLM: ${t.checks.llm?.ok?t.checks.llm.detail:"not configured"}`),e.push(`EMBED: ${t.checks.embedding?.ok?t.checks.embedding.detail:"not configured"}`),e.push(`FACTS: ${t.facts.length} loaded / ${t.totals?.facts??0} total`),e}function Od(t){return t==="mcp"?["## Using Sigil (no automatic memory in this client)","- Nothing is injected or saved automatically here. Call the `search` tool BEFORE answering anything that depends on the user, their preferences, or this project; call `ingest` to save durable facts the user will want next session.","- When you use a stored fact, name it in one short clause so the user sees their context being applied."].join(`
14
+ `):["## Using Sigil","- Memory is auto-injected per prompt and saved by hooks. Read the injected facts first; use `search` only to drill down when the injection missed something."].join(`
15
+ `)}var Bo=W(()=>{});import{config as Ld}from"dotenv";import{resolve as Mr,dirname as Ho}from"node:path";import{fileURLToPath as Cd}from"node:url";import{existsSync as Nd}from"node:fs";import"dotenv/config";import{McpServer as Ad}from"@modelcontextprotocol/sdk/server/mcp.js";import{StdioServerTransport as kd}from"@modelcontextprotocol/sdk/server/stdio.js";var y={};Ze(y,{BRAND:()=>gs,DIRTY:()=>Ie,EMPTY_PATH:()=>Ko,INVALID:()=>_,NEVER:()=>ei,OK:()=>j,ParseStatus:()=>D,Schema:()=>T,ZodAny:()=>de,ZodArray:()=>se,ZodBigInt:()=>Se,ZodBoolean:()=>we,ZodBranded:()=>It,ZodCatch:()=>De,ZodDate:()=>Oe,ZodDefault:()=>$e,ZodDiscriminatedUnion:()=>$t,ZodEffects:()=>V,ZodEnum:()=>Pe,ZodError:()=>B,ZodFirstPartyTypeKind:()=>v,ZodFunction:()=>jt,ZodIntersection:()=>Le,ZodIssueCode:()=>f,ZodLazy:()=>Ce,ZodLiteral:()=>Ne,ZodMap:()=>Xe,ZodNaN:()=>et,ZodNativeEnum:()=>Me,ZodNever:()=>K,ZodNull:()=>ke,ZodNullable:()=>Q,ZodNumber:()=>Ee,ZodObject:()=>U,ZodOptional:()=>H,ZodParsedType:()=>p,ZodPipeline:()=>Et,ZodPromise:()=>pe,ZodReadonly:()=>je,ZodRecord:()=>Dt,ZodSchema:()=>T,ZodSet:()=>Qe,ZodString:()=>le,ZodSymbol:()=>qe,ZodTransformer:()=>V,ZodTuple:()=>X,ZodType:()=>T,ZodUndefined:()=>Ae,ZodUnion:()=>Re,ZodUnknown:()=>oe,ZodVoid:()=>Je,addIssueToContext:()=>d,any:()=>Ss,array:()=>ks,bigint:()=>vs,boolean:()=>Zr,coerce:()=>Qs,custom:()=>Hr,date:()=>bs,datetimeRegex:()=>Ur,defaultErrorMap:()=>ne,discriminatedUnion:()=>Ns,effect:()=>Vs,enum:()=>Fs,function:()=>Gs,getErrorMap:()=>We,getParsedType:()=>J,instanceof:()=>_s,intersection:()=>Ps,isAborted:()=>Pt,isAsync:()=>Ke,isDirty:()=>Mt,isValid:()=>fe,late:()=>ys,lazy:()=>Bs,literal:()=>Us,makeIssue:()=>Tt,map:()=>Ds,nan:()=>xs,nativeEnum:()=>Hs,never:()=>Os,null:()=>Es,nullable:()=>Ws,number:()=>Vr,object:()=>Rs,objectUtil:()=>pr,oboolean:()=>Xs,onumber:()=>Js,optional:()=>Zs,ostring:()=>qs,pipeline:()=>Ys,preprocess:()=>Ks,promise:()=>zs,quotelessJson:()=>Vo,record:()=>$s,set:()=>js,setErrorMap:()=>Wo,strictObject:()=>Ls,string:()=>zr,symbol:()=>Ts,transformer:()=>Vs,tuple:()=>Ms,undefined:()=>Is,union:()=>Cs,unknown:()=>ws,util:()=>I,void:()=>As});var I;(function(t){t.assertEqual=a=>{};function e(a){}t.assertIs=e;function r(a){throw new Error}t.assertNever=r,t.arrayToEnum=a=>{let o={};for(let s of a)o[s]=s;return o},t.getValidEnumValues=a=>{let o=t.objectKeys(a).filter(i=>typeof a[a[i]]!="number"),s={};for(let i of o)s[i]=a[i];return t.objectValues(s)},t.objectValues=a=>t.objectKeys(a).map(function(o){return a[o]}),t.objectKeys=typeof Object.keys=="function"?a=>Object.keys(a):a=>{let o=[];for(let s in a)Object.prototype.hasOwnProperty.call(a,s)&&o.push(s);return o},t.find=(a,o)=>{for(let s of a)if(o(s))return s},t.isInteger=typeof Number.isInteger=="function"?a=>Number.isInteger(a):a=>typeof a=="number"&&Number.isFinite(a)&&Math.floor(a)===a;function n(a,o=" | "){return a.map(s=>typeof s=="string"?`'${s}'`:s).join(o)}t.joinValues=n,t.jsonStringifyReplacer=(a,o)=>typeof o=="bigint"?o.toString():o})(I||(I={}));var pr;(function(t){t.mergeShapes=(e,r)=>({...e,...r})})(pr||(pr={}));var p=I.arrayToEnum(["string","nan","number","integer","float","boolean","date","bigint","symbol","function","undefined","null","array","object","unknown","promise","void","never","map","set"]),J=t=>{switch(typeof t){case"undefined":return p.undefined;case"string":return p.string;case"number":return Number.isNaN(t)?p.nan:p.number;case"boolean":return p.boolean;case"function":return p.function;case"bigint":return p.bigint;case"symbol":return p.symbol;case"object":return Array.isArray(t)?p.array:t===null?p.null:t.then&&typeof t.then=="function"&&t.catch&&typeof t.catch=="function"?p.promise:typeof Map<"u"&&t instanceof Map?p.map:typeof Set<"u"&&t instanceof Set?p.set:typeof Date<"u"&&t instanceof Date?p.date:p.object;default:return p.unknown}};var f=I.arrayToEnum(["invalid_type","invalid_literal","custom","invalid_union","invalid_union_discriminator","invalid_enum_value","unrecognized_keys","invalid_arguments","invalid_return_type","invalid_date","invalid_string","too_small","too_big","invalid_intersection_types","not_multiple_of","not_finite"]),Vo=t=>JSON.stringify(t,null,2).replace(/"([^"]+)":/g,"$1:"),B=class t extends Error{get errors(){return this.issues}constructor(e){super(),this.issues=[],this.addIssue=n=>{this.issues=[...this.issues,n]},this.addIssues=(n=[])=>{this.issues=[...this.issues,...n]};let r=new.target.prototype;Object.setPrototypeOf?Object.setPrototypeOf(this,r):this.__proto__=r,this.name="ZodError",this.issues=e}format(e){let r=e||function(o){return o.message},n={_errors:[]},a=o=>{for(let s of o.issues)if(s.code==="invalid_union")s.unionErrors.map(a);else if(s.code==="invalid_return_type")a(s.returnTypeError);else if(s.code==="invalid_arguments")a(s.argumentsError);else if(s.path.length===0)n._errors.push(r(s));else{let i=n,c=0;for(;c<s.path.length;){let u=s.path[c];c===s.path.length-1?(i[u]=i[u]||{_errors:[]},i[u]._errors.push(r(s))):i[u]=i[u]||{_errors:[]},i=i[u],c++}}};return a(this),n}static assert(e){if(!(e instanceof t))throw new Error(`Not a ZodError: ${e}`)}toString(){return this.message}get message(){return JSON.stringify(this.issues,I.jsonStringifyReplacer,2)}get isEmpty(){return this.issues.length===0}flatten(e=r=>r.message){let r={},n=[];for(let a of this.issues)if(a.path.length>0){let o=a.path[0];r[o]=r[o]||[],r[o].push(e(a))}else n.push(e(a));return{formErrors:n,fieldErrors:r}}get formErrors(){return this.flatten()}};B.create=t=>new B(t);var Zo=(t,e)=>{let r;switch(t.code){case f.invalid_type:t.received===p.undefined?r="Required":r=`Expected ${t.expected}, received ${t.received}`;break;case f.invalid_literal:r=`Invalid literal value, expected ${JSON.stringify(t.expected,I.jsonStringifyReplacer)}`;break;case f.unrecognized_keys:r=`Unrecognized key(s) in object: ${I.joinValues(t.keys,", ")}`;break;case f.invalid_union:r="Invalid input";break;case f.invalid_union_discriminator:r=`Invalid discriminator value. Expected ${I.joinValues(t.options)}`;break;case f.invalid_enum_value:r=`Invalid enum value. Expected ${I.joinValues(t.options)}, received '${t.received}'`;break;case f.invalid_arguments:r="Invalid function arguments";break;case f.invalid_return_type:r="Invalid function return type";break;case f.invalid_date:r="Invalid date";break;case f.invalid_string:typeof t.validation=="object"?"includes"in t.validation?(r=`Invalid input: must include "${t.validation.includes}"`,typeof t.validation.position=="number"&&(r=`${r} at one or more positions greater than or equal to ${t.validation.position}`)):"startsWith"in t.validation?r=`Invalid input: must start with "${t.validation.startsWith}"`:"endsWith"in t.validation?r=`Invalid input: must end with "${t.validation.endsWith}"`:I.assertNever(t.validation):t.validation!=="regex"?r=`Invalid ${t.validation}`:r="Invalid";break;case f.too_small:t.type==="array"?r=`Array must contain ${t.exact?"exactly":t.inclusive?"at least":"more than"} ${t.minimum} element(s)`:t.type==="string"?r=`String must contain ${t.exact?"exactly":t.inclusive?"at least":"over"} ${t.minimum} character(s)`:t.type==="number"?r=`Number must be ${t.exact?"exactly equal to ":t.inclusive?"greater than or equal to ":"greater than "}${t.minimum}`:t.type==="bigint"?r=`Number must be ${t.exact?"exactly equal to ":t.inclusive?"greater than or equal to ":"greater than "}${t.minimum}`:t.type==="date"?r=`Date must be ${t.exact?"exactly equal to ":t.inclusive?"greater than or equal to ":"greater than "}${new Date(Number(t.minimum))}`:r="Invalid input";break;case f.too_big:t.type==="array"?r=`Array must contain ${t.exact?"exactly":t.inclusive?"at most":"less than"} ${t.maximum} element(s)`:t.type==="string"?r=`String must contain ${t.exact?"exactly":t.inclusive?"at most":"under"} ${t.maximum} character(s)`:t.type==="number"?r=`Number must be ${t.exact?"exactly":t.inclusive?"less than or equal to":"less than"} ${t.maximum}`:t.type==="bigint"?r=`BigInt must be ${t.exact?"exactly":t.inclusive?"less than or equal to":"less than"} ${t.maximum}`:t.type==="date"?r=`Date must be ${t.exact?"exactly":t.inclusive?"smaller than or equal to":"smaller than"} ${new Date(Number(t.maximum))}`:r="Invalid input";break;case f.custom:r="Invalid input";break;case f.invalid_intersection_types:r="Intersection results could not be merged";break;case f.not_multiple_of:r=`Number must be a multiple of ${t.multipleOf}`;break;case f.not_finite:r="Number must be finite";break;default:r=e.defaultError,I.assertNever(t)}return{message:r}},ne=Zo;var $r=ne;function Wo(t){$r=t}function We(){return $r}var Tt=t=>{let{data:e,path:r,errorMaps:n,issueData:a}=t,o=[...r,...a.path||[]],s={...a,path:o};if(a.message!==void 0)return{...a,path:o,message:a.message};let i="",c=n.filter(u=>!!u).slice().reverse();for(let u of c)i=u(s,{data:e,defaultError:i}).message;return{...a,path:o,message:i}},Ko=[];function d(t,e){let r=We(),n=Tt({issueData:e,data:t.data,path:t.path,errorMaps:[t.common.contextualErrorMap,t.schemaErrorMap,r,r===ne?void 0:ne].filter(a=>!!a)});t.common.issues.push(n)}var D=class t{constructor(){this.value="valid"}dirty(){this.value==="valid"&&(this.value="dirty")}abort(){this.value!=="aborted"&&(this.value="aborted")}static mergeArray(e,r){let n=[];for(let a of r){if(a.status==="aborted")return _;a.status==="dirty"&&e.dirty(),n.push(a.value)}return{status:e.value,value:n}}static async mergeObjectAsync(e,r){let n=[];for(let a of r){let o=await a.key,s=await a.value;n.push({key:o,value:s})}return t.mergeObjectSync(e,n)}static mergeObjectSync(e,r){let n={};for(let a of r){let{key:o,value:s}=a;if(o.status==="aborted"||s.status==="aborted")return _;o.status==="dirty"&&e.dirty(),s.status==="dirty"&&e.dirty(),o.value!=="__proto__"&&(typeof s.value<"u"||a.alwaysSet)&&(n[o.value]=s.value)}return{status:e.value,value:n}}},_=Object.freeze({status:"aborted"}),Ie=t=>({status:"dirty",value:t}),j=t=>({status:"valid",value:t}),Pt=t=>t.status==="aborted",Mt=t=>t.status==="dirty",fe=t=>t.status==="valid",Ke=t=>typeof Promise<"u"&&t instanceof Promise;var h;(function(t){t.errToObj=e=>typeof e=="string"?{message:e}:e||{},t.toString=e=>typeof e=="string"?e:e?.message})(h||(h={}));var z=class{constructor(e,r,n,a){this._cachedPath=[],this.parent=e,this.data=r,this._path=n,this._key=a}get path(){return this._cachedPath.length||(Array.isArray(this._key)?this._cachedPath.push(...this._path,...this._key):this._cachedPath.push(...this._path,this._key)),this._cachedPath}},Dr=(t,e)=>{if(fe(e))return{success:!0,data:e.value};if(!t.common.issues.length)throw new Error("Validation failed but no issues detected.");return{success:!1,get error(){if(this._error)return this._error;let r=new B(t.common.issues);return this._error=r,this._error}}};function b(t){if(!t)return{};let{errorMap:e,invalid_type_error:r,required_error:n,description:a}=t;if(e&&(r||n))throw new Error(`Can't use "invalid_type_error" or "required_error" in conjunction with custom error map.`);return e?{errorMap:e,description:a}:{errorMap:(s,i)=>{let{message:c}=t;return s.code==="invalid_enum_value"?{message:c??i.defaultError}:typeof i.data>"u"?{message:c??n??i.defaultError}:s.code!=="invalid_type"?{message:i.defaultError}:{message:c??r??i.defaultError}},description:a}}var T=class{get description(){return this._def.description}_getType(e){return J(e.data)}_getOrReturnCtx(e,r){return r||{common:e.parent.common,data:e.data,parsedType:J(e.data),schemaErrorMap:this._def.errorMap,path:e.path,parent:e.parent}}_processInputParams(e){return{status:new D,ctx:{common:e.parent.common,data:e.data,parsedType:J(e.data),schemaErrorMap:this._def.errorMap,path:e.path,parent:e.parent}}}_parseSync(e){let r=this._parse(e);if(Ke(r))throw new Error("Synchronous parse encountered promise.");return r}_parseAsync(e){let r=this._parse(e);return Promise.resolve(r)}parse(e,r){let n=this.safeParse(e,r);if(n.success)return n.data;throw n.error}safeParse(e,r){let n={common:{issues:[],async:r?.async??!1,contextualErrorMap:r?.errorMap},path:r?.path||[],schemaErrorMap:this._def.errorMap,parent:null,data:e,parsedType:J(e)},a=this._parseSync({data:e,path:n.path,parent:n});return Dr(n,a)}"~validate"(e){let r={common:{issues:[],async:!!this["~standard"].async},path:[],schemaErrorMap:this._def.errorMap,parent:null,data:e,parsedType:J(e)};if(!this["~standard"].async)try{let n=this._parseSync({data:e,path:[],parent:r});return fe(n)?{value:n.value}:{issues:r.common.issues}}catch(n){n?.message?.toLowerCase()?.includes("encountered")&&(this["~standard"].async=!0),r.common={issues:[],async:!0}}return this._parseAsync({data:e,path:[],parent:r}).then(n=>fe(n)?{value:n.value}:{issues:r.common.issues})}async parseAsync(e,r){let n=await this.safeParseAsync(e,r);if(n.success)return n.data;throw n.error}async safeParseAsync(e,r){let n={common:{issues:[],contextualErrorMap:r?.errorMap,async:!0},path:r?.path||[],schemaErrorMap:this._def.errorMap,parent:null,data:e,parsedType:J(e)},a=this._parse({data:e,path:n.path,parent:n}),o=await(Ke(a)?a:Promise.resolve(a));return Dr(n,o)}refine(e,r){let n=a=>typeof r=="string"||typeof r>"u"?{message:r}:typeof r=="function"?r(a):r;return this._refinement((a,o)=>{let s=e(a),i=()=>o.addIssue({code:f.custom,...n(a)});return typeof Promise<"u"&&s instanceof Promise?s.then(c=>c?!0:(i(),!1)):s?!0:(i(),!1)})}refinement(e,r){return this._refinement((n,a)=>e(n)?!0:(a.addIssue(typeof r=="function"?r(n,a):r),!1))}_refinement(e){return new V({schema:this,typeName:v.ZodEffects,effect:{type:"refinement",refinement:e}})}superRefine(e){return this._refinement(e)}constructor(e){this.spa=this.safeParseAsync,this._def=e,this.parse=this.parse.bind(this),this.safeParse=this.safeParse.bind(this),this.parseAsync=this.parseAsync.bind(this),this.safeParseAsync=this.safeParseAsync.bind(this),this.spa=this.spa.bind(this),this.refine=this.refine.bind(this),this.refinement=this.refinement.bind(this),this.superRefine=this.superRefine.bind(this),this.optional=this.optional.bind(this),this.nullable=this.nullable.bind(this),this.nullish=this.nullish.bind(this),this.array=this.array.bind(this),this.promise=this.promise.bind(this),this.or=this.or.bind(this),this.and=this.and.bind(this),this.transform=this.transform.bind(this),this.brand=this.brand.bind(this),this.default=this.default.bind(this),this.catch=this.catch.bind(this),this.describe=this.describe.bind(this),this.pipe=this.pipe.bind(this),this.readonly=this.readonly.bind(this),this.isNullable=this.isNullable.bind(this),this.isOptional=this.isOptional.bind(this),this["~standard"]={version:1,vendor:"zod",validate:r=>this["~validate"](r)}}optional(){return H.create(this,this._def)}nullable(){return Q.create(this,this._def)}nullish(){return this.nullable().optional()}array(){return se.create(this)}promise(){return pe.create(this,this._def)}or(e){return Re.create([this,e],this._def)}and(e){return Le.create(this,e,this._def)}transform(e){return new V({...b(this._def),schema:this,typeName:v.ZodEffects,effect:{type:"transform",transform:e}})}default(e){let r=typeof e=="function"?e:()=>e;return new $e({...b(this._def),innerType:this,defaultValue:r,typeName:v.ZodDefault})}brand(){return new It({typeName:v.ZodBranded,type:this,...b(this._def)})}catch(e){let r=typeof e=="function"?e:()=>e;return new De({...b(this._def),innerType:this,catchValue:r,typeName:v.ZodCatch})}describe(e){let r=this.constructor;return new r({...this._def,description:e})}pipe(e){return Et.create(this,e)}readonly(){return je.create(this)}isOptional(){return this.safeParse(void 0).success}isNullable(){return this.safeParse(null).success}},Yo=/^c[^\s-]{8,}$/i,qo=/^[0-9a-z]+$/,Jo=/^[0-9A-HJKMNP-TV-Z]{26}$/i,Xo=/^[0-9a-fA-F]{8}\b-[0-9a-fA-F]{4}\b-[0-9a-fA-F]{4}\b-[0-9a-fA-F]{4}\b-[0-9a-fA-F]{12}$/i,Qo=/^[a-z0-9_-]{21}$/i,es=/^[A-Za-z0-9-_]+\.[A-Za-z0-9-_]+\.[A-Za-z0-9-_]*$/,ts=/^[-+]?P(?!$)(?:(?:[-+]?\d+Y)|(?:[-+]?\d+[.,]\d+Y$))?(?:(?:[-+]?\d+M)|(?:[-+]?\d+[.,]\d+M$))?(?:(?:[-+]?\d+W)|(?:[-+]?\d+[.,]\d+W$))?(?:(?:[-+]?\d+D)|(?:[-+]?\d+[.,]\d+D$))?(?:T(?=[\d+-])(?:(?:[-+]?\d+H)|(?:[-+]?\d+[.,]\d+H$))?(?:(?:[-+]?\d+M)|(?:[-+]?\d+[.,]\d+M$))?(?:[-+]?\d+(?:[.,]\d+)?S)?)??$/,rs=/^(?!\.)(?!.*\.\.)([A-Z0-9_'+\-\.]*)[A-Z0-9_+-]@([A-Z0-9][A-Z0-9\-]*\.)+[A-Z]{2,}$/i,ns="^(\\p{Extended_Pictographic}|\\p{Emoji_Component})+$",mr,as=/^(?:(?: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])$/,os=/^(?:(?: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])\/(3[0-2]|[12]?[0-9])$/,ss=/^(([0-9a-fA-F]{1,4}:){7,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}|:)|fe80:(:[0-9a-fA-F]{0,4}){0,4}%[0-9a-zA-Z]{1,}|::(ffff(:0{1,4}){0,1}:){0,1}((25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])\.){3,3}(25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])|([0-9a-fA-F]{1,4}:){1,4}:((25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])\.){3,3}(25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9]))$/,is=/^(([0-9a-fA-F]{1,4}:){7,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}|:)|fe80:(:[0-9a-fA-F]{0,4}){0,4}%[0-9a-zA-Z]{1,}|::(ffff(:0{1,4}){0,1}:){0,1}((25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])\.){3,3}(25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])|([0-9a-fA-F]{1,4}:){1,4}:((25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])\.){3,3}(25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9]))\/(12[0-8]|1[01][0-9]|[1-9]?[0-9])$/,cs=/^([0-9a-zA-Z+/]{4})*(([0-9a-zA-Z+/]{2}==)|([0-9a-zA-Z+/]{3}=))?$/,us=/^([0-9a-zA-Z-_]{4})*(([0-9a-zA-Z-_]{2}(==)?)|([0-9a-zA-Z-_]{3}(=)?))?$/,Gr="((\\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])))",fs=new RegExp(`^${Gr}$`);function Br(t){let e="[0-5]\\d";t.precision?e=`${e}\\.\\d{${t.precision}}`:t.precision==null&&(e=`${e}(\\.\\d+)?`);let r=t.precision?"+":"?";return`([01]\\d|2[0-3]):[0-5]\\d(:${e})${r}`}function ls(t){return new RegExp(`^${Br(t)}$`)}function Ur(t){let e=`${Gr}T${Br(t)}`,r=[];return r.push(t.local?"Z?":"Z"),t.offset&&r.push("([+-]\\d{2}:?\\d{2})"),e=`${e}(${r.join("|")})`,new RegExp(`^${e}$`)}function ds(t,e){return!!((e==="v4"||!e)&&as.test(t)||(e==="v6"||!e)&&ss.test(t))}function ps(t,e){if(!es.test(t))return!1;try{let[r]=t.split(".");if(!r)return!1;let n=r.replace(/-/g,"+").replace(/_/g,"/").padEnd(r.length+(4-r.length%4)%4,"="),a=JSON.parse(atob(n));return!(typeof a!="object"||a===null||"typ"in a&&a?.typ!=="JWT"||!a.alg||e&&a.alg!==e)}catch{return!1}}function ms(t,e){return!!((e==="v4"||!e)&&os.test(t)||(e==="v6"||!e)&&is.test(t))}var le=class t extends T{_parse(e){if(this._def.coerce&&(e.data=String(e.data)),this._getType(e)!==p.string){let o=this._getOrReturnCtx(e);return d(o,{code:f.invalid_type,expected:p.string,received:o.parsedType}),_}let n=new D,a;for(let o of this._def.checks)if(o.kind==="min")e.data.length<o.value&&(a=this._getOrReturnCtx(e,a),d(a,{code:f.too_small,minimum:o.value,type:"string",inclusive:!0,exact:!1,message:o.message}),n.dirty());else if(o.kind==="max")e.data.length>o.value&&(a=this._getOrReturnCtx(e,a),d(a,{code:f.too_big,maximum:o.value,type:"string",inclusive:!0,exact:!1,message:o.message}),n.dirty());else if(o.kind==="length"){let s=e.data.length>o.value,i=e.data.length<o.value;(s||i)&&(a=this._getOrReturnCtx(e,a),s?d(a,{code:f.too_big,maximum:o.value,type:"string",inclusive:!0,exact:!0,message:o.message}):i&&d(a,{code:f.too_small,minimum:o.value,type:"string",inclusive:!0,exact:!0,message:o.message}),n.dirty())}else if(o.kind==="email")rs.test(e.data)||(a=this._getOrReturnCtx(e,a),d(a,{validation:"email",code:f.invalid_string,message:o.message}),n.dirty());else if(o.kind==="emoji")mr||(mr=new RegExp(ns,"u")),mr.test(e.data)||(a=this._getOrReturnCtx(e,a),d(a,{validation:"emoji",code:f.invalid_string,message:o.message}),n.dirty());else if(o.kind==="uuid")Xo.test(e.data)||(a=this._getOrReturnCtx(e,a),d(a,{validation:"uuid",code:f.invalid_string,message:o.message}),n.dirty());else if(o.kind==="nanoid")Qo.test(e.data)||(a=this._getOrReturnCtx(e,a),d(a,{validation:"nanoid",code:f.invalid_string,message:o.message}),n.dirty());else if(o.kind==="cuid")Yo.test(e.data)||(a=this._getOrReturnCtx(e,a),d(a,{validation:"cuid",code:f.invalid_string,message:o.message}),n.dirty());else if(o.kind==="cuid2")qo.test(e.data)||(a=this._getOrReturnCtx(e,a),d(a,{validation:"cuid2",code:f.invalid_string,message:o.message}),n.dirty());else if(o.kind==="ulid")Jo.test(e.data)||(a=this._getOrReturnCtx(e,a),d(a,{validation:"ulid",code:f.invalid_string,message:o.message}),n.dirty());else if(o.kind==="url")try{new URL(e.data)}catch{a=this._getOrReturnCtx(e,a),d(a,{validation:"url",code:f.invalid_string,message:o.message}),n.dirty()}else o.kind==="regex"?(o.regex.lastIndex=0,o.regex.test(e.data)||(a=this._getOrReturnCtx(e,a),d(a,{validation:"regex",code:f.invalid_string,message:o.message}),n.dirty())):o.kind==="trim"?e.data=e.data.trim():o.kind==="includes"?e.data.includes(o.value,o.position)||(a=this._getOrReturnCtx(e,a),d(a,{code:f.invalid_string,validation:{includes:o.value,position:o.position},message:o.message}),n.dirty()):o.kind==="toLowerCase"?e.data=e.data.toLowerCase():o.kind==="toUpperCase"?e.data=e.data.toUpperCase():o.kind==="startsWith"?e.data.startsWith(o.value)||(a=this._getOrReturnCtx(e,a),d(a,{code:f.invalid_string,validation:{startsWith:o.value},message:o.message}),n.dirty()):o.kind==="endsWith"?e.data.endsWith(o.value)||(a=this._getOrReturnCtx(e,a),d(a,{code:f.invalid_string,validation:{endsWith:o.value},message:o.message}),n.dirty()):o.kind==="datetime"?Ur(o).test(e.data)||(a=this._getOrReturnCtx(e,a),d(a,{code:f.invalid_string,validation:"datetime",message:o.message}),n.dirty()):o.kind==="date"?fs.test(e.data)||(a=this._getOrReturnCtx(e,a),d(a,{code:f.invalid_string,validation:"date",message:o.message}),n.dirty()):o.kind==="time"?ls(o).test(e.data)||(a=this._getOrReturnCtx(e,a),d(a,{code:f.invalid_string,validation:"time",message:o.message}),n.dirty()):o.kind==="duration"?ts.test(e.data)||(a=this._getOrReturnCtx(e,a),d(a,{validation:"duration",code:f.invalid_string,message:o.message}),n.dirty()):o.kind==="ip"?ds(e.data,o.version)||(a=this._getOrReturnCtx(e,a),d(a,{validation:"ip",code:f.invalid_string,message:o.message}),n.dirty()):o.kind==="jwt"?ps(e.data,o.alg)||(a=this._getOrReturnCtx(e,a),d(a,{validation:"jwt",code:f.invalid_string,message:o.message}),n.dirty()):o.kind==="cidr"?ms(e.data,o.version)||(a=this._getOrReturnCtx(e,a),d(a,{validation:"cidr",code:f.invalid_string,message:o.message}),n.dirty()):o.kind==="base64"?cs.test(e.data)||(a=this._getOrReturnCtx(e,a),d(a,{validation:"base64",code:f.invalid_string,message:o.message}),n.dirty()):o.kind==="base64url"?us.test(e.data)||(a=this._getOrReturnCtx(e,a),d(a,{validation:"base64url",code:f.invalid_string,message:o.message}),n.dirty()):I.assertNever(o);return{status:n.value,value:e.data}}_regex(e,r,n){return this.refinement(a=>e.test(a),{validation:r,code:f.invalid_string,...h.errToObj(n)})}_addCheck(e){return new t({...this._def,checks:[...this._def.checks,e]})}email(e){return this._addCheck({kind:"email",...h.errToObj(e)})}url(e){return this._addCheck({kind:"url",...h.errToObj(e)})}emoji(e){return this._addCheck({kind:"emoji",...h.errToObj(e)})}uuid(e){return this._addCheck({kind:"uuid",...h.errToObj(e)})}nanoid(e){return this._addCheck({kind:"nanoid",...h.errToObj(e)})}cuid(e){return this._addCheck({kind:"cuid",...h.errToObj(e)})}cuid2(e){return this._addCheck({kind:"cuid2",...h.errToObj(e)})}ulid(e){return this._addCheck({kind:"ulid",...h.errToObj(e)})}base64(e){return this._addCheck({kind:"base64",...h.errToObj(e)})}base64url(e){return this._addCheck({kind:"base64url",...h.errToObj(e)})}jwt(e){return this._addCheck({kind:"jwt",...h.errToObj(e)})}ip(e){return this._addCheck({kind:"ip",...h.errToObj(e)})}cidr(e){return this._addCheck({kind:"cidr",...h.errToObj(e)})}datetime(e){return typeof e=="string"?this._addCheck({kind:"datetime",precision:null,offset:!1,local:!1,message:e}):this._addCheck({kind:"datetime",precision:typeof e?.precision>"u"?null:e?.precision,offset:e?.offset??!1,local:e?.local??!1,...h.errToObj(e?.message)})}date(e){return this._addCheck({kind:"date",message:e})}time(e){return typeof e=="string"?this._addCheck({kind:"time",precision:null,message:e}):this._addCheck({kind:"time",precision:typeof e?.precision>"u"?null:e?.precision,...h.errToObj(e?.message)})}duration(e){return this._addCheck({kind:"duration",...h.errToObj(e)})}regex(e,r){return this._addCheck({kind:"regex",regex:e,...h.errToObj(r)})}includes(e,r){return this._addCheck({kind:"includes",value:e,position:r?.position,...h.errToObj(r?.message)})}startsWith(e,r){return this._addCheck({kind:"startsWith",value:e,...h.errToObj(r)})}endsWith(e,r){return this._addCheck({kind:"endsWith",value:e,...h.errToObj(r)})}min(e,r){return this._addCheck({kind:"min",value:e,...h.errToObj(r)})}max(e,r){return this._addCheck({kind:"max",value:e,...h.errToObj(r)})}length(e,r){return this._addCheck({kind:"length",value:e,...h.errToObj(r)})}nonempty(e){return this.min(1,h.errToObj(e))}trim(){return new t({...this._def,checks:[...this._def.checks,{kind:"trim"}]})}toLowerCase(){return new t({...this._def,checks:[...this._def.checks,{kind:"toLowerCase"}]})}toUpperCase(){return new t({...this._def,checks:[...this._def.checks,{kind:"toUpperCase"}]})}get isDatetime(){return!!this._def.checks.find(e=>e.kind==="datetime")}get isDate(){return!!this._def.checks.find(e=>e.kind==="date")}get isTime(){return!!this._def.checks.find(e=>e.kind==="time")}get isDuration(){return!!this._def.checks.find(e=>e.kind==="duration")}get isEmail(){return!!this._def.checks.find(e=>e.kind==="email")}get isURL(){return!!this._def.checks.find(e=>e.kind==="url")}get isEmoji(){return!!this._def.checks.find(e=>e.kind==="emoji")}get isUUID(){return!!this._def.checks.find(e=>e.kind==="uuid")}get isNANOID(){return!!this._def.checks.find(e=>e.kind==="nanoid")}get isCUID(){return!!this._def.checks.find(e=>e.kind==="cuid")}get isCUID2(){return!!this._def.checks.find(e=>e.kind==="cuid2")}get isULID(){return!!this._def.checks.find(e=>e.kind==="ulid")}get isIP(){return!!this._def.checks.find(e=>e.kind==="ip")}get isCIDR(){return!!this._def.checks.find(e=>e.kind==="cidr")}get isBase64(){return!!this._def.checks.find(e=>e.kind==="base64")}get isBase64url(){return!!this._def.checks.find(e=>e.kind==="base64url")}get minLength(){let e=null;for(let r of this._def.checks)r.kind==="min"&&(e===null||r.value>e)&&(e=r.value);return e}get maxLength(){let e=null;for(let r of this._def.checks)r.kind==="max"&&(e===null||r.value<e)&&(e=r.value);return e}};le.create=t=>new le({checks:[],typeName:v.ZodString,coerce:t?.coerce??!1,...b(t)});function hs(t,e){let r=(t.toString().split(".")[1]||"").length,n=(e.toString().split(".")[1]||"").length,a=r>n?r:n,o=Number.parseInt(t.toFixed(a).replace(".","")),s=Number.parseInt(e.toFixed(a).replace(".",""));return o%s/10**a}var Ee=class t extends T{constructor(){super(...arguments),this.min=this.gte,this.max=this.lte,this.step=this.multipleOf}_parse(e){if(this._def.coerce&&(e.data=Number(e.data)),this._getType(e)!==p.number){let o=this._getOrReturnCtx(e);return d(o,{code:f.invalid_type,expected:p.number,received:o.parsedType}),_}let n,a=new D;for(let o of this._def.checks)o.kind==="int"?I.isInteger(e.data)||(n=this._getOrReturnCtx(e,n),d(n,{code:f.invalid_type,expected:"integer",received:"float",message:o.message}),a.dirty()):o.kind==="min"?(o.inclusive?e.data<o.value:e.data<=o.value)&&(n=this._getOrReturnCtx(e,n),d(n,{code:f.too_small,minimum:o.value,type:"number",inclusive:o.inclusive,exact:!1,message:o.message}),a.dirty()):o.kind==="max"?(o.inclusive?e.data>o.value:e.data>=o.value)&&(n=this._getOrReturnCtx(e,n),d(n,{code:f.too_big,maximum:o.value,type:"number",inclusive:o.inclusive,exact:!1,message:o.message}),a.dirty()):o.kind==="multipleOf"?hs(e.data,o.value)!==0&&(n=this._getOrReturnCtx(e,n),d(n,{code:f.not_multiple_of,multipleOf:o.value,message:o.message}),a.dirty()):o.kind==="finite"?Number.isFinite(e.data)||(n=this._getOrReturnCtx(e,n),d(n,{code:f.not_finite,message:o.message}),a.dirty()):I.assertNever(o);return{status:a.value,value:e.data}}gte(e,r){return this.setLimit("min",e,!0,h.toString(r))}gt(e,r){return this.setLimit("min",e,!1,h.toString(r))}lte(e,r){return this.setLimit("max",e,!0,h.toString(r))}lt(e,r){return this.setLimit("max",e,!1,h.toString(r))}setLimit(e,r,n,a){return new t({...this._def,checks:[...this._def.checks,{kind:e,value:r,inclusive:n,message:h.toString(a)}]})}_addCheck(e){return new t({...this._def,checks:[...this._def.checks,e]})}int(e){return this._addCheck({kind:"int",message:h.toString(e)})}positive(e){return this._addCheck({kind:"min",value:0,inclusive:!1,message:h.toString(e)})}negative(e){return this._addCheck({kind:"max",value:0,inclusive:!1,message:h.toString(e)})}nonpositive(e){return this._addCheck({kind:"max",value:0,inclusive:!0,message:h.toString(e)})}nonnegative(e){return this._addCheck({kind:"min",value:0,inclusive:!0,message:h.toString(e)})}multipleOf(e,r){return this._addCheck({kind:"multipleOf",value:e,message:h.toString(r)})}finite(e){return this._addCheck({kind:"finite",message:h.toString(e)})}safe(e){return this._addCheck({kind:"min",inclusive:!0,value:Number.MIN_SAFE_INTEGER,message:h.toString(e)})._addCheck({kind:"max",inclusive:!0,value:Number.MAX_SAFE_INTEGER,message:h.toString(e)})}get minValue(){let e=null;for(let r of this._def.checks)r.kind==="min"&&(e===null||r.value>e)&&(e=r.value);return e}get maxValue(){let e=null;for(let r of this._def.checks)r.kind==="max"&&(e===null||r.value<e)&&(e=r.value);return e}get isInt(){return!!this._def.checks.find(e=>e.kind==="int"||e.kind==="multipleOf"&&I.isInteger(e.value))}get isFinite(){let e=null,r=null;for(let n of this._def.checks){if(n.kind==="finite"||n.kind==="int"||n.kind==="multipleOf")return!0;n.kind==="min"?(r===null||n.value>r)&&(r=n.value):n.kind==="max"&&(e===null||n.value<e)&&(e=n.value)}return Number.isFinite(r)&&Number.isFinite(e)}};Ee.create=t=>new Ee({checks:[],typeName:v.ZodNumber,coerce:t?.coerce||!1,...b(t)});var Se=class t extends T{constructor(){super(...arguments),this.min=this.gte,this.max=this.lte}_parse(e){if(this._def.coerce)try{e.data=BigInt(e.data)}catch{return this._getInvalidInput(e)}if(this._getType(e)!==p.bigint)return this._getInvalidInput(e);let n,a=new D;for(let o of this._def.checks)o.kind==="min"?(o.inclusive?e.data<o.value:e.data<=o.value)&&(n=this._getOrReturnCtx(e,n),d(n,{code:f.too_small,type:"bigint",minimum:o.value,inclusive:o.inclusive,message:o.message}),a.dirty()):o.kind==="max"?(o.inclusive?e.data>o.value:e.data>=o.value)&&(n=this._getOrReturnCtx(e,n),d(n,{code:f.too_big,type:"bigint",maximum:o.value,inclusive:o.inclusive,message:o.message}),a.dirty()):o.kind==="multipleOf"?e.data%o.value!==BigInt(0)&&(n=this._getOrReturnCtx(e,n),d(n,{code:f.not_multiple_of,multipleOf:o.value,message:o.message}),a.dirty()):I.assertNever(o);return{status:a.value,value:e.data}}_getInvalidInput(e){let r=this._getOrReturnCtx(e);return d(r,{code:f.invalid_type,expected:p.bigint,received:r.parsedType}),_}gte(e,r){return this.setLimit("min",e,!0,h.toString(r))}gt(e,r){return this.setLimit("min",e,!1,h.toString(r))}lte(e,r){return this.setLimit("max",e,!0,h.toString(r))}lt(e,r){return this.setLimit("max",e,!1,h.toString(r))}setLimit(e,r,n,a){return new t({...this._def,checks:[...this._def.checks,{kind:e,value:r,inclusive:n,message:h.toString(a)}]})}_addCheck(e){return new t({...this._def,checks:[...this._def.checks,e]})}positive(e){return this._addCheck({kind:"min",value:BigInt(0),inclusive:!1,message:h.toString(e)})}negative(e){return this._addCheck({kind:"max",value:BigInt(0),inclusive:!1,message:h.toString(e)})}nonpositive(e){return this._addCheck({kind:"max",value:BigInt(0),inclusive:!0,message:h.toString(e)})}nonnegative(e){return this._addCheck({kind:"min",value:BigInt(0),inclusive:!0,message:h.toString(e)})}multipleOf(e,r){return this._addCheck({kind:"multipleOf",value:e,message:h.toString(r)})}get minValue(){let e=null;for(let r of this._def.checks)r.kind==="min"&&(e===null||r.value>e)&&(e=r.value);return e}get maxValue(){let e=null;for(let r of this._def.checks)r.kind==="max"&&(e===null||r.value<e)&&(e=r.value);return e}};Se.create=t=>new Se({checks:[],typeName:v.ZodBigInt,coerce:t?.coerce??!1,...b(t)});var we=class extends T{_parse(e){if(this._def.coerce&&(e.data=!!e.data),this._getType(e)!==p.boolean){let n=this._getOrReturnCtx(e);return d(n,{code:f.invalid_type,expected:p.boolean,received:n.parsedType}),_}return j(e.data)}};we.create=t=>new we({typeName:v.ZodBoolean,coerce:t?.coerce||!1,...b(t)});var Oe=class t extends T{_parse(e){if(this._def.coerce&&(e.data=new Date(e.data)),this._getType(e)!==p.date){let o=this._getOrReturnCtx(e);return d(o,{code:f.invalid_type,expected:p.date,received:o.parsedType}),_}if(Number.isNaN(e.data.getTime())){let o=this._getOrReturnCtx(e);return d(o,{code:f.invalid_date}),_}let n=new D,a;for(let o of this._def.checks)o.kind==="min"?e.data.getTime()<o.value&&(a=this._getOrReturnCtx(e,a),d(a,{code:f.too_small,message:o.message,inclusive:!0,exact:!1,minimum:o.value,type:"date"}),n.dirty()):o.kind==="max"?e.data.getTime()>o.value&&(a=this._getOrReturnCtx(e,a),d(a,{code:f.too_big,message:o.message,inclusive:!0,exact:!1,maximum:o.value,type:"date"}),n.dirty()):I.assertNever(o);return{status:n.value,value:new Date(e.data.getTime())}}_addCheck(e){return new t({...this._def,checks:[...this._def.checks,e]})}min(e,r){return this._addCheck({kind:"min",value:e.getTime(),message:h.toString(r)})}max(e,r){return this._addCheck({kind:"max",value:e.getTime(),message:h.toString(r)})}get minDate(){let e=null;for(let r of this._def.checks)r.kind==="min"&&(e===null||r.value>e)&&(e=r.value);return e!=null?new Date(e):null}get maxDate(){let e=null;for(let r of this._def.checks)r.kind==="max"&&(e===null||r.value<e)&&(e=r.value);return e!=null?new Date(e):null}};Oe.create=t=>new Oe({checks:[],coerce:t?.coerce||!1,typeName:v.ZodDate,...b(t)});var qe=class extends T{_parse(e){if(this._getType(e)!==p.symbol){let n=this._getOrReturnCtx(e);return d(n,{code:f.invalid_type,expected:p.symbol,received:n.parsedType}),_}return j(e.data)}};qe.create=t=>new qe({typeName:v.ZodSymbol,...b(t)});var Ae=class extends T{_parse(e){if(this._getType(e)!==p.undefined){let n=this._getOrReturnCtx(e);return d(n,{code:f.invalid_type,expected:p.undefined,received:n.parsedType}),_}return j(e.data)}};Ae.create=t=>new Ae({typeName:v.ZodUndefined,...b(t)});var ke=class extends T{_parse(e){if(this._getType(e)!==p.null){let n=this._getOrReturnCtx(e);return d(n,{code:f.invalid_type,expected:p.null,received:n.parsedType}),_}return j(e.data)}};ke.create=t=>new ke({typeName:v.ZodNull,...b(t)});var de=class extends T{constructor(){super(...arguments),this._any=!0}_parse(e){return j(e.data)}};de.create=t=>new de({typeName:v.ZodAny,...b(t)});var oe=class extends T{constructor(){super(...arguments),this._unknown=!0}_parse(e){return j(e.data)}};oe.create=t=>new oe({typeName:v.ZodUnknown,...b(t)});var K=class extends T{_parse(e){let r=this._getOrReturnCtx(e);return d(r,{code:f.invalid_type,expected:p.never,received:r.parsedType}),_}};K.create=t=>new K({typeName:v.ZodNever,...b(t)});var Je=class extends T{_parse(e){if(this._getType(e)!==p.undefined){let n=this._getOrReturnCtx(e);return d(n,{code:f.invalid_type,expected:p.void,received:n.parsedType}),_}return j(e.data)}};Je.create=t=>new Je({typeName:v.ZodVoid,...b(t)});var se=class t extends T{_parse(e){let{ctx:r,status:n}=this._processInputParams(e),a=this._def;if(r.parsedType!==p.array)return d(r,{code:f.invalid_type,expected:p.array,received:r.parsedType}),_;if(a.exactLength!==null){let s=r.data.length>a.exactLength.value,i=r.data.length<a.exactLength.value;(s||i)&&(d(r,{code:s?f.too_big:f.too_small,minimum:i?a.exactLength.value:void 0,maximum:s?a.exactLength.value:void 0,type:"array",inclusive:!0,exact:!0,message:a.exactLength.message}),n.dirty())}if(a.minLength!==null&&r.data.length<a.minLength.value&&(d(r,{code:f.too_small,minimum:a.minLength.value,type:"array",inclusive:!0,exact:!1,message:a.minLength.message}),n.dirty()),a.maxLength!==null&&r.data.length>a.maxLength.value&&(d(r,{code:f.too_big,maximum:a.maxLength.value,type:"array",inclusive:!0,exact:!1,message:a.maxLength.message}),n.dirty()),r.common.async)return Promise.all([...r.data].map((s,i)=>a.type._parseAsync(new z(r,s,r.path,i)))).then(s=>D.mergeArray(n,s));let o=[...r.data].map((s,i)=>a.type._parseSync(new z(r,s,r.path,i)));return D.mergeArray(n,o)}get element(){return this._def.type}min(e,r){return new t({...this._def,minLength:{value:e,message:h.toString(r)}})}max(e,r){return new t({...this._def,maxLength:{value:e,message:h.toString(r)}})}length(e,r){return new t({...this._def,exactLength:{value:e,message:h.toString(r)}})}nonempty(e){return this.min(1,e)}};se.create=(t,e)=>new se({type:t,minLength:null,maxLength:null,exactLength:null,typeName:v.ZodArray,...b(e)});function Ye(t){if(t instanceof U){let e={};for(let r in t.shape){let n=t.shape[r];e[r]=H.create(Ye(n))}return new U({...t._def,shape:()=>e})}else return t instanceof se?new se({...t._def,type:Ye(t.element)}):t instanceof H?H.create(Ye(t.unwrap())):t instanceof Q?Q.create(Ye(t.unwrap())):t instanceof X?X.create(t.items.map(e=>Ye(e))):t}var U=class t extends T{constructor(){super(...arguments),this._cached=null,this.nonstrict=this.passthrough,this.augment=this.extend}_getCached(){if(this._cached!==null)return this._cached;let e=this._def.shape(),r=I.objectKeys(e);return this._cached={shape:e,keys:r},this._cached}_parse(e){if(this._getType(e)!==p.object){let u=this._getOrReturnCtx(e);return d(u,{code:f.invalid_type,expected:p.object,received:u.parsedType}),_}let{status:n,ctx:a}=this._processInputParams(e),{shape:o,keys:s}=this._getCached(),i=[];if(!(this._def.catchall instanceof K&&this._def.unknownKeys==="strip"))for(let u in a.data)s.includes(u)||i.push(u);let c=[];for(let u of s){let l=o[u],m=a.data[u];c.push({key:{status:"valid",value:u},value:l._parse(new z(a,m,a.path,u)),alwaysSet:u in a.data})}if(this._def.catchall instanceof K){let u=this._def.unknownKeys;if(u==="passthrough")for(let l of i)c.push({key:{status:"valid",value:l},value:{status:"valid",value:a.data[l]}});else if(u==="strict")i.length>0&&(d(a,{code:f.unrecognized_keys,keys:i}),n.dirty());else if(u!=="strip")throw new Error("Internal ZodObject error: invalid unknownKeys value.")}else{let u=this._def.catchall;for(let l of i){let m=a.data[l];c.push({key:{status:"valid",value:l},value:u._parse(new z(a,m,a.path,l)),alwaysSet:l in a.data})}}return a.common.async?Promise.resolve().then(async()=>{let u=[];for(let l of c){let m=await l.key,g=await l.value;u.push({key:m,value:g,alwaysSet:l.alwaysSet})}return u}).then(u=>D.mergeObjectSync(n,u)):D.mergeObjectSync(n,c)}get shape(){return this._def.shape()}strict(e){return h.errToObj,new t({...this._def,unknownKeys:"strict",...e!==void 0?{errorMap:(r,n)=>{let a=this._def.errorMap?.(r,n).message??n.defaultError;return r.code==="unrecognized_keys"?{message:h.errToObj(e).message??a}:{message:a}}}:{}})}strip(){return new t({...this._def,unknownKeys:"strip"})}passthrough(){return new t({...this._def,unknownKeys:"passthrough"})}extend(e){return new t({...this._def,shape:()=>({...this._def.shape(),...e})})}merge(e){return new t({unknownKeys:e._def.unknownKeys,catchall:e._def.catchall,shape:()=>({...this._def.shape(),...e._def.shape()}),typeName:v.ZodObject})}setKey(e,r){return this.augment({[e]:r})}catchall(e){return new t({...this._def,catchall:e})}pick(e){let r={};for(let n of I.objectKeys(e))e[n]&&this.shape[n]&&(r[n]=this.shape[n]);return new t({...this._def,shape:()=>r})}omit(e){let r={};for(let n of I.objectKeys(this.shape))e[n]||(r[n]=this.shape[n]);return new t({...this._def,shape:()=>r})}deepPartial(){return Ye(this)}partial(e){let r={};for(let n of I.objectKeys(this.shape)){let a=this.shape[n];e&&!e[n]?r[n]=a:r[n]=a.optional()}return new t({...this._def,shape:()=>r})}required(e){let r={};for(let n of I.objectKeys(this.shape))if(e&&!e[n])r[n]=this.shape[n];else{let o=this.shape[n];for(;o instanceof H;)o=o._def.innerType;r[n]=o}return new t({...this._def,shape:()=>r})}keyof(){return Fr(I.objectKeys(this.shape))}};U.create=(t,e)=>new U({shape:()=>t,unknownKeys:"strip",catchall:K.create(),typeName:v.ZodObject,...b(e)});U.strictCreate=(t,e)=>new U({shape:()=>t,unknownKeys:"strict",catchall:K.create(),typeName:v.ZodObject,...b(e)});U.lazycreate=(t,e)=>new U({shape:t,unknownKeys:"strip",catchall:K.create(),typeName:v.ZodObject,...b(e)});var Re=class extends T{_parse(e){let{ctx:r}=this._processInputParams(e),n=this._def.options;function a(o){for(let i of o)if(i.result.status==="valid")return i.result;for(let i of o)if(i.result.status==="dirty")return r.common.issues.push(...i.ctx.common.issues),i.result;let s=o.map(i=>new B(i.ctx.common.issues));return d(r,{code:f.invalid_union,unionErrors:s}),_}if(r.common.async)return Promise.all(n.map(async o=>{let s={...r,common:{...r.common,issues:[]},parent:null};return{result:await o._parseAsync({data:r.data,path:r.path,parent:s}),ctx:s}})).then(a);{let o,s=[];for(let c of n){let u={...r,common:{...r.common,issues:[]},parent:null},l=c._parseSync({data:r.data,path:r.path,parent:u});if(l.status==="valid")return l;l.status==="dirty"&&!o&&(o={result:l,ctx:u}),u.common.issues.length&&s.push(u.common.issues)}if(o)return r.common.issues.push(...o.ctx.common.issues),o.result;let i=s.map(c=>new B(c));return d(r,{code:f.invalid_union,unionErrors:i}),_}}get options(){return this._def.options}};Re.create=(t,e)=>new Re({options:t,typeName:v.ZodUnion,...b(e)});var ae=t=>t instanceof Ce?ae(t.schema):t instanceof V?ae(t.innerType()):t instanceof Ne?[t.value]:t instanceof Pe?t.options:t instanceof Me?I.objectValues(t.enum):t instanceof $e?ae(t._def.innerType):t instanceof Ae?[void 0]:t instanceof ke?[null]:t instanceof H?[void 0,...ae(t.unwrap())]:t instanceof Q?[null,...ae(t.unwrap())]:t instanceof It||t instanceof je?ae(t.unwrap()):t instanceof De?ae(t._def.innerType):[],$t=class t extends T{_parse(e){let{ctx:r}=this._processInputParams(e);if(r.parsedType!==p.object)return d(r,{code:f.invalid_type,expected:p.object,received:r.parsedType}),_;let n=this.discriminator,a=r.data[n],o=this.optionsMap.get(a);return o?r.common.async?o._parseAsync({data:r.data,path:r.path,parent:r}):o._parseSync({data:r.data,path:r.path,parent:r}):(d(r,{code:f.invalid_union_discriminator,options:Array.from(this.optionsMap.keys()),path:[n]}),_)}get discriminator(){return this._def.discriminator}get options(){return this._def.options}get optionsMap(){return this._def.optionsMap}static create(e,r,n){let a=new Map;for(let o of r){let s=ae(o.shape[e]);if(!s.length)throw new Error(`A discriminator value for key \`${e}\` could not be extracted from all schema options`);for(let i of s){if(a.has(i))throw new Error(`Discriminator property ${String(e)} has duplicate value ${String(i)}`);a.set(i,o)}}return new t({typeName:v.ZodDiscriminatedUnion,discriminator:e,options:r,optionsMap:a,...b(n)})}};function hr(t,e){let r=J(t),n=J(e);if(t===e)return{valid:!0,data:t};if(r===p.object&&n===p.object){let a=I.objectKeys(e),o=I.objectKeys(t).filter(i=>a.indexOf(i)!==-1),s={...t,...e};for(let i of o){let c=hr(t[i],e[i]);if(!c.valid)return{valid:!1};s[i]=c.data}return{valid:!0,data:s}}else if(r===p.array&&n===p.array){if(t.length!==e.length)return{valid:!1};let a=[];for(let o=0;o<t.length;o++){let s=t[o],i=e[o],c=hr(s,i);if(!c.valid)return{valid:!1};a.push(c.data)}return{valid:!0,data:a}}else return r===p.date&&n===p.date&&+t==+e?{valid:!0,data:t}:{valid:!1}}var Le=class extends T{_parse(e){let{status:r,ctx:n}=this._processInputParams(e),a=(o,s)=>{if(Pt(o)||Pt(s))return _;let i=hr(o.value,s.value);return i.valid?((Mt(o)||Mt(s))&&r.dirty(),{status:r.value,value:i.data}):(d(n,{code:f.invalid_intersection_types}),_)};return n.common.async?Promise.all([this._def.left._parseAsync({data:n.data,path:n.path,parent:n}),this._def.right._parseAsync({data:n.data,path:n.path,parent:n})]).then(([o,s])=>a(o,s)):a(this._def.left._parseSync({data:n.data,path:n.path,parent:n}),this._def.right._parseSync({data:n.data,path:n.path,parent:n}))}};Le.create=(t,e,r)=>new Le({left:t,right:e,typeName:v.ZodIntersection,...b(r)});var X=class t extends T{_parse(e){let{status:r,ctx:n}=this._processInputParams(e);if(n.parsedType!==p.array)return d(n,{code:f.invalid_type,expected:p.array,received:n.parsedType}),_;if(n.data.length<this._def.items.length)return d(n,{code:f.too_small,minimum:this._def.items.length,inclusive:!0,exact:!1,type:"array"}),_;!this._def.rest&&n.data.length>this._def.items.length&&(d(n,{code:f.too_big,maximum:this._def.items.length,inclusive:!0,exact:!1,type:"array"}),r.dirty());let o=[...n.data].map((s,i)=>{let c=this._def.items[i]||this._def.rest;return c?c._parse(new z(n,s,n.path,i)):null}).filter(s=>!!s);return n.common.async?Promise.all(o).then(s=>D.mergeArray(r,s)):D.mergeArray(r,o)}get items(){return this._def.items}rest(e){return new t({...this._def,rest:e})}};X.create=(t,e)=>{if(!Array.isArray(t))throw new Error("You must pass an array of schemas to z.tuple([ ... ])");return new X({items:t,typeName:v.ZodTuple,rest:null,...b(e)})};var Dt=class t extends T{get keySchema(){return this._def.keyType}get valueSchema(){return this._def.valueType}_parse(e){let{status:r,ctx:n}=this._processInputParams(e);if(n.parsedType!==p.object)return d(n,{code:f.invalid_type,expected:p.object,received:n.parsedType}),_;let a=[],o=this._def.keyType,s=this._def.valueType;for(let i in n.data)a.push({key:o._parse(new z(n,i,n.path,i)),value:s._parse(new z(n,n.data[i],n.path,i)),alwaysSet:i in n.data});return n.common.async?D.mergeObjectAsync(r,a):D.mergeObjectSync(r,a)}get element(){return this._def.valueType}static create(e,r,n){return r instanceof T?new t({keyType:e,valueType:r,typeName:v.ZodRecord,...b(n)}):new t({keyType:le.create(),valueType:e,typeName:v.ZodRecord,...b(r)})}},Xe=class extends T{get keySchema(){return this._def.keyType}get valueSchema(){return this._def.valueType}_parse(e){let{status:r,ctx:n}=this._processInputParams(e);if(n.parsedType!==p.map)return d(n,{code:f.invalid_type,expected:p.map,received:n.parsedType}),_;let a=this._def.keyType,o=this._def.valueType,s=[...n.data.entries()].map(([i,c],u)=>({key:a._parse(new z(n,i,n.path,[u,"key"])),value:o._parse(new z(n,c,n.path,[u,"value"]))}));if(n.common.async){let i=new Map;return Promise.resolve().then(async()=>{for(let c of s){let u=await c.key,l=await c.value;if(u.status==="aborted"||l.status==="aborted")return _;(u.status==="dirty"||l.status==="dirty")&&r.dirty(),i.set(u.value,l.value)}return{status:r.value,value:i}})}else{let i=new Map;for(let c of s){let u=c.key,l=c.value;if(u.status==="aborted"||l.status==="aborted")return _;(u.status==="dirty"||l.status==="dirty")&&r.dirty(),i.set(u.value,l.value)}return{status:r.value,value:i}}}};Xe.create=(t,e,r)=>new Xe({valueType:e,keyType:t,typeName:v.ZodMap,...b(r)});var Qe=class t extends T{_parse(e){let{status:r,ctx:n}=this._processInputParams(e);if(n.parsedType!==p.set)return d(n,{code:f.invalid_type,expected:p.set,received:n.parsedType}),_;let a=this._def;a.minSize!==null&&n.data.size<a.minSize.value&&(d(n,{code:f.too_small,minimum:a.minSize.value,type:"set",inclusive:!0,exact:!1,message:a.minSize.message}),r.dirty()),a.maxSize!==null&&n.data.size>a.maxSize.value&&(d(n,{code:f.too_big,maximum:a.maxSize.value,type:"set",inclusive:!0,exact:!1,message:a.maxSize.message}),r.dirty());let o=this._def.valueType;function s(c){let u=new Set;for(let l of c){if(l.status==="aborted")return _;l.status==="dirty"&&r.dirty(),u.add(l.value)}return{status:r.value,value:u}}let i=[...n.data.values()].map((c,u)=>o._parse(new z(n,c,n.path,u)));return n.common.async?Promise.all(i).then(c=>s(c)):s(i)}min(e,r){return new t({...this._def,minSize:{value:e,message:h.toString(r)}})}max(e,r){return new t({...this._def,maxSize:{value:e,message:h.toString(r)}})}size(e,r){return this.min(e,r).max(e,r)}nonempty(e){return this.min(1,e)}};Qe.create=(t,e)=>new Qe({valueType:t,minSize:null,maxSize:null,typeName:v.ZodSet,...b(e)});var jt=class t extends T{constructor(){super(...arguments),this.validate=this.implement}_parse(e){let{ctx:r}=this._processInputParams(e);if(r.parsedType!==p.function)return d(r,{code:f.invalid_type,expected:p.function,received:r.parsedType}),_;function n(i,c){return Tt({data:i,path:r.path,errorMaps:[r.common.contextualErrorMap,r.schemaErrorMap,We(),ne].filter(u=>!!u),issueData:{code:f.invalid_arguments,argumentsError:c}})}function a(i,c){return Tt({data:i,path:r.path,errorMaps:[r.common.contextualErrorMap,r.schemaErrorMap,We(),ne].filter(u=>!!u),issueData:{code:f.invalid_return_type,returnTypeError:c}})}let o={errorMap:r.common.contextualErrorMap},s=r.data;if(this._def.returns instanceof pe){let i=this;return j(async function(...c){let u=new B([]),l=await i._def.args.parseAsync(c,o).catch(x=>{throw u.addIssue(n(c,x)),u}),m=await Reflect.apply(s,this,l);return await i._def.returns._def.type.parseAsync(m,o).catch(x=>{throw u.addIssue(a(m,x)),u})})}else{let i=this;return j(function(...c){let u=i._def.args.safeParse(c,o);if(!u.success)throw new B([n(c,u.error)]);let l=Reflect.apply(s,this,u.data),m=i._def.returns.safeParse(l,o);if(!m.success)throw new B([a(l,m.error)]);return m.data})}}parameters(){return this._def.args}returnType(){return this._def.returns}args(...e){return new t({...this._def,args:X.create(e).rest(oe.create())})}returns(e){return new t({...this._def,returns:e})}implement(e){return this.parse(e)}strictImplement(e){return this.parse(e)}static create(e,r,n){return new t({args:e||X.create([]).rest(oe.create()),returns:r||oe.create(),typeName:v.ZodFunction,...b(n)})}},Ce=class extends T{get schema(){return this._def.getter()}_parse(e){let{ctx:r}=this._processInputParams(e);return this._def.getter()._parse({data:r.data,path:r.path,parent:r})}};Ce.create=(t,e)=>new Ce({getter:t,typeName:v.ZodLazy,...b(e)});var Ne=class extends T{_parse(e){if(e.data!==this._def.value){let r=this._getOrReturnCtx(e);return d(r,{received:r.data,code:f.invalid_literal,expected:this._def.value}),_}return{status:"valid",value:e.data}}get value(){return this._def.value}};Ne.create=(t,e)=>new Ne({value:t,typeName:v.ZodLiteral,...b(e)});function Fr(t,e){return new Pe({values:t,typeName:v.ZodEnum,...b(e)})}var Pe=class t extends T{_parse(e){if(typeof e.data!="string"){let r=this._getOrReturnCtx(e),n=this._def.values;return d(r,{expected:I.joinValues(n),received:r.parsedType,code:f.invalid_type}),_}if(this._cache||(this._cache=new Set(this._def.values)),!this._cache.has(e.data)){let r=this._getOrReturnCtx(e),n=this._def.values;return d(r,{received:r.data,code:f.invalid_enum_value,options:n}),_}return j(e.data)}get options(){return this._def.values}get enum(){let e={};for(let r of this._def.values)e[r]=r;return e}get Values(){let e={};for(let r of this._def.values)e[r]=r;return e}get Enum(){let e={};for(let r of this._def.values)e[r]=r;return e}extract(e,r=this._def){return t.create(e,{...this._def,...r})}exclude(e,r=this._def){return t.create(this.options.filter(n=>!e.includes(n)),{...this._def,...r})}};Pe.create=Fr;var Me=class extends T{_parse(e){let r=I.getValidEnumValues(this._def.values),n=this._getOrReturnCtx(e);if(n.parsedType!==p.string&&n.parsedType!==p.number){let a=I.objectValues(r);return d(n,{expected:I.joinValues(a),received:n.parsedType,code:f.invalid_type}),_}if(this._cache||(this._cache=new Set(I.getValidEnumValues(this._def.values))),!this._cache.has(e.data)){let a=I.objectValues(r);return d(n,{received:n.data,code:f.invalid_enum_value,options:a}),_}return j(e.data)}get enum(){return this._def.values}};Me.create=(t,e)=>new Me({values:t,typeName:v.ZodNativeEnum,...b(e)});var pe=class extends T{unwrap(){return this._def.type}_parse(e){let{ctx:r}=this._processInputParams(e);if(r.parsedType!==p.promise&&r.common.async===!1)return d(r,{code:f.invalid_type,expected:p.promise,received:r.parsedType}),_;let n=r.parsedType===p.promise?r.data:Promise.resolve(r.data);return j(n.then(a=>this._def.type.parseAsync(a,{path:r.path,errorMap:r.common.contextualErrorMap})))}};pe.create=(t,e)=>new pe({type:t,typeName:v.ZodPromise,...b(e)});var V=class extends T{innerType(){return this._def.schema}sourceType(){return this._def.schema._def.typeName===v.ZodEffects?this._def.schema.sourceType():this._def.schema}_parse(e){let{status:r,ctx:n}=this._processInputParams(e),a=this._def.effect||null,o={addIssue:s=>{d(n,s),s.fatal?r.abort():r.dirty()},get path(){return n.path}};if(o.addIssue=o.addIssue.bind(o),a.type==="preprocess"){let s=a.transform(n.data,o);if(n.common.async)return Promise.resolve(s).then(async i=>{if(r.value==="aborted")return _;let c=await this._def.schema._parseAsync({data:i,path:n.path,parent:n});return c.status==="aborted"?_:c.status==="dirty"?Ie(c.value):r.value==="dirty"?Ie(c.value):c});{if(r.value==="aborted")return _;let i=this._def.schema._parseSync({data:s,path:n.path,parent:n});return i.status==="aborted"?_:i.status==="dirty"?Ie(i.value):r.value==="dirty"?Ie(i.value):i}}if(a.type==="refinement"){let s=i=>{let c=a.refinement(i,o);if(n.common.async)return Promise.resolve(c);if(c instanceof Promise)throw new Error("Async refinement encountered during synchronous parse operation. Use .parseAsync instead.");return i};if(n.common.async===!1){let i=this._def.schema._parseSync({data:n.data,path:n.path,parent:n});return i.status==="aborted"?_:(i.status==="dirty"&&r.dirty(),s(i.value),{status:r.value,value:i.value})}else return this._def.schema._parseAsync({data:n.data,path:n.path,parent:n}).then(i=>i.status==="aborted"?_:(i.status==="dirty"&&r.dirty(),s(i.value).then(()=>({status:r.value,value:i.value}))))}if(a.type==="transform")if(n.common.async===!1){let s=this._def.schema._parseSync({data:n.data,path:n.path,parent:n});if(!fe(s))return _;let i=a.transform(s.value,o);if(i instanceof Promise)throw new Error("Asynchronous transform encountered during synchronous parse operation. Use .parseAsync instead.");return{status:r.value,value:i}}else return this._def.schema._parseAsync({data:n.data,path:n.path,parent:n}).then(s=>fe(s)?Promise.resolve(a.transform(s.value,o)).then(i=>({status:r.value,value:i})):_);I.assertNever(a)}};V.create=(t,e,r)=>new V({schema:t,typeName:v.ZodEffects,effect:e,...b(r)});V.createWithPreprocess=(t,e,r)=>new V({schema:e,effect:{type:"preprocess",transform:t},typeName:v.ZodEffects,...b(r)});var H=class extends T{_parse(e){return this._getType(e)===p.undefined?j(void 0):this._def.innerType._parse(e)}unwrap(){return this._def.innerType}};H.create=(t,e)=>new H({innerType:t,typeName:v.ZodOptional,...b(e)});var Q=class extends T{_parse(e){return this._getType(e)===p.null?j(null):this._def.innerType._parse(e)}unwrap(){return this._def.innerType}};Q.create=(t,e)=>new Q({innerType:t,typeName:v.ZodNullable,...b(e)});var $e=class extends T{_parse(e){let{ctx:r}=this._processInputParams(e),n=r.data;return r.parsedType===p.undefined&&(n=this._def.defaultValue()),this._def.innerType._parse({data:n,path:r.path,parent:r})}removeDefault(){return this._def.innerType}};$e.create=(t,e)=>new $e({innerType:t,typeName:v.ZodDefault,defaultValue:typeof e.default=="function"?e.default:()=>e.default,...b(e)});var De=class extends T{_parse(e){let{ctx:r}=this._processInputParams(e),n={...r,common:{...r.common,issues:[]}},a=this._def.innerType._parse({data:n.data,path:n.path,parent:{...n}});return Ke(a)?a.then(o=>({status:"valid",value:o.status==="valid"?o.value:this._def.catchValue({get error(){return new B(n.common.issues)},input:n.data})})):{status:"valid",value:a.status==="valid"?a.value:this._def.catchValue({get error(){return new B(n.common.issues)},input:n.data})}}removeCatch(){return this._def.innerType}};De.create=(t,e)=>new De({innerType:t,typeName:v.ZodCatch,catchValue:typeof e.catch=="function"?e.catch:()=>e.catch,...b(e)});var et=class extends T{_parse(e){if(this._getType(e)!==p.nan){let n=this._getOrReturnCtx(e);return d(n,{code:f.invalid_type,expected:p.nan,received:n.parsedType}),_}return{status:"valid",value:e.data}}};et.create=t=>new et({typeName:v.ZodNaN,...b(t)});var gs=Symbol("zod_brand"),It=class extends T{_parse(e){let{ctx:r}=this._processInputParams(e),n=r.data;return this._def.type._parse({data:n,path:r.path,parent:r})}unwrap(){return this._def.type}},Et=class t extends T{_parse(e){let{status:r,ctx:n}=this._processInputParams(e);if(n.common.async)return(async()=>{let o=await this._def.in._parseAsync({data:n.data,path:n.path,parent:n});return o.status==="aborted"?_:o.status==="dirty"?(r.dirty(),Ie(o.value)):this._def.out._parseAsync({data:o.value,path:n.path,parent:n})})();{let a=this._def.in._parseSync({data:n.data,path:n.path,parent:n});return a.status==="aborted"?_:a.status==="dirty"?(r.dirty(),{status:"dirty",value:a.value}):this._def.out._parseSync({data:a.value,path:n.path,parent:n})}}static create(e,r){return new t({in:e,out:r,typeName:v.ZodPipeline})}},je=class extends T{_parse(e){let r=this._def.innerType._parse(e),n=a=>(fe(a)&&(a.value=Object.freeze(a.value)),a);return Ke(r)?r.then(a=>n(a)):n(r)}unwrap(){return this._def.innerType}};je.create=(t,e)=>new je({innerType:t,typeName:v.ZodReadonly,...b(e)});function jr(t,e){let r=typeof t=="function"?t(e):typeof t=="string"?{message:t}:t;return typeof r=="string"?{message:r}:r}function Hr(t,e={},r){return t?de.create().superRefine((n,a)=>{let o=t(n);if(o instanceof Promise)return o.then(s=>{if(!s){let i=jr(e,n),c=i.fatal??r??!0;a.addIssue({code:"custom",...i,fatal:c})}});if(!o){let s=jr(e,n),i=s.fatal??r??!0;a.addIssue({code:"custom",...s,fatal:i})}}):de.create()}var ys={object:U.lazycreate},v;(function(t){t.ZodString="ZodString",t.ZodNumber="ZodNumber",t.ZodNaN="ZodNaN",t.ZodBigInt="ZodBigInt",t.ZodBoolean="ZodBoolean",t.ZodDate="ZodDate",t.ZodSymbol="ZodSymbol",t.ZodUndefined="ZodUndefined",t.ZodNull="ZodNull",t.ZodAny="ZodAny",t.ZodUnknown="ZodUnknown",t.ZodNever="ZodNever",t.ZodVoid="ZodVoid",t.ZodArray="ZodArray",t.ZodObject="ZodObject",t.ZodUnion="ZodUnion",t.ZodDiscriminatedUnion="ZodDiscriminatedUnion",t.ZodIntersection="ZodIntersection",t.ZodTuple="ZodTuple",t.ZodRecord="ZodRecord",t.ZodMap="ZodMap",t.ZodSet="ZodSet",t.ZodFunction="ZodFunction",t.ZodLazy="ZodLazy",t.ZodLiteral="ZodLiteral",t.ZodEnum="ZodEnum",t.ZodEffects="ZodEffects",t.ZodNativeEnum="ZodNativeEnum",t.ZodOptional="ZodOptional",t.ZodNullable="ZodNullable",t.ZodDefault="ZodDefault",t.ZodCatch="ZodCatch",t.ZodPromise="ZodPromise",t.ZodBranded="ZodBranded",t.ZodPipeline="ZodPipeline",t.ZodReadonly="ZodReadonly"})(v||(v={}));var _s=(t,e={message:`Input not instance of ${t.name}`})=>Hr(r=>r instanceof t,e),zr=le.create,Vr=Ee.create,xs=et.create,vs=Se.create,Zr=we.create,bs=Oe.create,Ts=qe.create,Is=Ae.create,Es=ke.create,Ss=de.create,ws=oe.create,Os=K.create,As=Je.create,ks=se.create,Rs=U.create,Ls=U.strictCreate,Cs=Re.create,Ns=$t.create,Ps=Le.create,Ms=X.create,$s=Dt.create,Ds=Xe.create,js=Qe.create,Gs=jt.create,Bs=Ce.create,Us=Ne.create,Fs=Pe.create,Hs=Me.create,zs=pe.create,Vs=V.create,Zs=H.create,Ws=Q.create,Ks=V.createWithPreprocess,Ys=Et.create,qs=()=>zr().optional(),Js=()=>Vr().optional(),Xs=()=>Zr().optional(),Qs={string:(t=>le.create({...t,coerce:!0})),number:(t=>Ee.create({...t,coerce:!0})),boolean:(t=>we.create({...t,coerce:!0})),bigint:(t=>Se.create({...t,coerce:!0})),date:(t=>Oe.create({...t,coerce:!0}))};var ei=_;var ti=typeof global=="object"&&global&&global.Object===Object&&global,Gt=ti;var ri=typeof self=="object"&&self&&self.Object===Object&&self,ni=Gt||ri||Function("return this")(),$=ni;var ai=$.Symbol,G=ai;var Wr=Object.prototype,oi=Wr.hasOwnProperty,si=Wr.toString,St=G?G.toStringTag:void 0;function ii(t){var e=oi.call(t,St),r=t[St];try{t[St]=void 0;var n=!0}catch{}var a=si.call(t);return n&&(e?t[St]=r:delete t[St]),a}var Kr=ii;var ci=Object.prototype,ui=ci.toString;function fi(t){return ui.call(t)}var Yr=fi;var li="[object Null]",di="[object Undefined]",qr=G?G.toStringTag:void 0;function pi(t){return t==null?t===void 0?di:li:qr&&qr in Object(t)?Kr(t):Yr(t)}var Y=pi;function mi(t){return t!=null&&typeof t=="object"}var q=mi;var hi="[object Symbol]";function gi(t){return typeof t=="symbol"||q(t)&&Y(t)==hi}var ie=gi;function yi(t,e){for(var r=-1,n=t==null?0:t.length,a=Array(n);++r<n;)a[r]=e(t[r],r,t);return a}var tt=yi;var _i=Array.isArray,R=_i;var xi=1/0,Jr=G?G.prototype:void 0,Xr=Jr?Jr.toString:void 0;function Qr(t){if(typeof t=="string")return t;if(R(t))return tt(t,Qr)+"";if(ie(t))return Xr?Xr.call(t):"";var e=t+"";return e=="0"&&1/t==-xi?"-0":e}var en=Qr;function vi(t){var e=typeof t;return t!=null&&(e=="object"||e=="function")}var me=vi;function bi(t){return t}var he=bi;var Ti="[object AsyncFunction]",Ii="[object Function]",Ei="[object GeneratorFunction]",Si="[object Proxy]";function wi(t){if(!me(t))return!1;var e=Y(t);return e==Ii||e==Ei||e==Ti||e==Si}var Bt=wi;var Oi=$["__core-js_shared__"],Ut=Oi;var tn=(function(){var t=/[^.]+$/.exec(Ut&&Ut.keys&&Ut.keys.IE_PROTO||"");return t?"Symbol(src)_1."+t:""})();function Ai(t){return!!tn&&tn in t}var rn=Ai;var ki=Function.prototype,Ri=ki.toString;function Li(t){if(t!=null){try{return Ri.call(t)}catch{}try{return t+""}catch{}}return""}var ce=Li;var Ci=/[\\^$.*+?()[\]{}|]/g,Ni=/^\[object .+?Constructor\]$/,Pi=Function.prototype,Mi=Object.prototype,$i=Pi.toString,Di=Mi.hasOwnProperty,ji=RegExp("^"+$i.call(Di).replace(Ci,"\\$&").replace(/hasOwnProperty|(function).*?(?=\\\()| for .+?(?=\\\])/g,"$1.*?")+"$");function Gi(t){if(!me(t)||rn(t))return!1;var e=Bt(t)?ji:Ni;return e.test(ce(t))}var nn=Gi;function Bi(t,e){return t?.[e]}var an=Bi;function Ui(t,e){var r=an(t,e);return nn(r)?r:void 0}var F=Ui;var Fi=F($,"WeakMap"),Ft=Fi;function Hi(t,e,r){switch(r.length){case 0:return t.call(e);case 1:return t.call(e,r[0]);case 2:return t.call(e,r[0],r[1]);case 3:return t.call(e,r[0],r[1],r[2])}return t.apply(e,r)}var on=Hi;var zi=800,Vi=16,Zi=Date.now;function Wi(t){var e=0,r=0;return function(){var n=Zi(),a=Vi-(n-r);if(r=n,a>0){if(++e>=zi)return arguments[0]}else e=0;return t.apply(void 0,arguments)}}var sn=Wi;function Ki(t){return function(){return t}}var cn=Ki;var Yi=(function(){try{var t=F(Object,"defineProperty");return t({},"",{}),t}catch{}})(),rt=Yi;var qi=rt?function(t,e){return rt(t,"toString",{configurable:!0,enumerable:!1,value:cn(e),writable:!0})}:he,un=qi;var Ji=sn(un),fn=Ji;var Xi=9007199254740991,Qi=/^(?:0|[1-9]\d*)$/;function ec(t,e){var r=typeof t;return e=e??Xi,!!e&&(r=="number"||r!="symbol"&&Qi.test(t))&&t>-1&&t%1==0&&t<e}var nt=ec;function tc(t,e,r){e=="__proto__"&&rt?rt(t,e,{configurable:!0,enumerable:!0,value:r,writable:!0}):t[e]=r}var ln=tc;function rc(t,e){return t===e||t!==t&&e!==e}var at=rc;var dn=Math.max;function nc(t,e,r){return e=dn(e===void 0?t.length-1:e,0),function(){for(var n=arguments,a=-1,o=dn(n.length-e,0),s=Array(o);++a<o;)s[a]=n[e+a];a=-1;for(var i=Array(e+1);++a<e;)i[a]=n[a];return i[e]=r(s),on(t,this,i)}}var pn=nc;function ac(t,e){return fn(pn(t,e,he),t+"")}var mn=ac;var oc=9007199254740991;function sc(t){return typeof t=="number"&&t>-1&&t%1==0&&t<=oc}var ot=sc;function ic(t){return t!=null&&ot(t.length)&&!Bt(t)}var ge=ic;function cc(t,e,r){if(!me(r))return!1;var n=typeof e;return(n=="number"?ge(r)&&nt(e,r.length):n=="string"&&e in r)?at(r[e],t):!1}var gr=cc;var uc=Object.prototype;function fc(t){var e=t&&t.constructor,r=typeof e=="function"&&e.prototype||uc;return t===r}var hn=fc;function lc(t,e){for(var r=-1,n=Array(t);++r<t;)n[r]=e(r);return n}var gn=lc;var dc="[object Arguments]";function pc(t){return q(t)&&Y(t)==dc}var yr=pc;var yn=Object.prototype,mc=yn.hasOwnProperty,hc=yn.propertyIsEnumerable,gc=yr((function(){return arguments})())?yr:function(t){return q(t)&&mc.call(t,"callee")&&!hc.call(t,"callee")},st=gc;function yc(){return!1}var _n=yc;var bn=typeof exports=="object"&&exports&&!exports.nodeType&&exports,xn=bn&&typeof module=="object"&&module&&!module.nodeType&&module,_c=xn&&xn.exports===bn,vn=_c?$.Buffer:void 0,xc=vn?vn.isBuffer:void 0,vc=xc||_n,wt=vc;var bc="[object Arguments]",Tc="[object Array]",Ic="[object Boolean]",Ec="[object Date]",Sc="[object Error]",wc="[object Function]",Oc="[object Map]",Ac="[object Number]",kc="[object Object]",Rc="[object RegExp]",Lc="[object Set]",Cc="[object String]",Nc="[object WeakMap]",Pc="[object ArrayBuffer]",Mc="[object DataView]",$c="[object Float32Array]",Dc="[object Float64Array]",jc="[object Int8Array]",Gc="[object Int16Array]",Bc="[object Int32Array]",Uc="[object Uint8Array]",Fc="[object Uint8ClampedArray]",Hc="[object Uint16Array]",zc="[object Uint32Array]",k={};k[$c]=k[Dc]=k[jc]=k[Gc]=k[Bc]=k[Uc]=k[Fc]=k[Hc]=k[zc]=!0;k[bc]=k[Tc]=k[Pc]=k[Ic]=k[Mc]=k[Ec]=k[Sc]=k[wc]=k[Oc]=k[Ac]=k[kc]=k[Rc]=k[Lc]=k[Cc]=k[Nc]=!1;function Vc(t){return q(t)&&ot(t.length)&&!!k[Y(t)]}var Tn=Vc;function Zc(t){return function(e){return t(e)}}var Ht=Zc;var In=typeof exports=="object"&&exports&&!exports.nodeType&&exports,Ot=In&&typeof module=="object"&&module&&!module.nodeType&&module,Wc=Ot&&Ot.exports===In,_r=Wc&&Gt.process,Kc=(function(){try{var t=Ot&&Ot.require&&Ot.require("util").types;return t||_r&&_r.binding&&_r.binding("util")}catch{}})(),xr=Kc;var En=xr&&xr.isTypedArray,Yc=En?Ht(En):Tn,zt=Yc;var qc=Object.prototype,Jc=qc.hasOwnProperty;function Xc(t,e){var r=R(t),n=!r&&st(t),a=!r&&!n&&wt(t),o=!r&&!n&&!a&&zt(t),s=r||n||a||o,i=s?gn(t.length,String):[],c=i.length;for(var u in t)(e||Jc.call(t,u))&&!(s&&(u=="length"||a&&(u=="offset"||u=="parent")||o&&(u=="buffer"||u=="byteLength"||u=="byteOffset")||nt(u,c)))&&i.push(u);return i}var Sn=Xc;function Qc(t,e){return function(r){return t(e(r))}}var wn=Qc;var eu=wn(Object.keys,Object),On=eu;var tu=Object.prototype,ru=tu.hasOwnProperty;function nu(t){if(!hn(t))return On(t);var e=[];for(var r in Object(t))ru.call(t,r)&&r!="constructor"&&e.push(r);return e}var An=nu;function au(t){return ge(t)?Sn(t):An(t)}var it=au;var ou=/\.|\[(?:[^[\]]*|(["'])(?:(?!\1)[^\\]|\\.)*?\1)\]/,su=/^\w*$/;function iu(t,e){if(R(t))return!1;var r=typeof t;return r=="number"||r=="symbol"||r=="boolean"||t==null||ie(t)?!0:su.test(t)||!ou.test(t)||e!=null&&t in Object(e)}var ct=iu;var cu=F(Object,"create"),ue=cu;function uu(){this.__data__=ue?ue(null):{},this.size=0}var kn=uu;function fu(t){var e=this.has(t)&&delete this.__data__[t];return this.size-=e?1:0,e}var Rn=fu;var lu="__lodash_hash_undefined__",du=Object.prototype,pu=du.hasOwnProperty;function mu(t){var e=this.__data__;if(ue){var r=e[t];return r===lu?void 0:r}return pu.call(e,t)?e[t]:void 0}var Ln=mu;var hu=Object.prototype,gu=hu.hasOwnProperty;function yu(t){var e=this.__data__;return ue?e[t]!==void 0:gu.call(e,t)}var Cn=yu;var _u="__lodash_hash_undefined__";function xu(t,e){var r=this.__data__;return this.size+=this.has(t)?0:1,r[t]=ue&&e===void 0?_u:e,this}var Nn=xu;function ut(t){var e=-1,r=t==null?0:t.length;for(this.clear();++e<r;){var n=t[e];this.set(n[0],n[1])}}ut.prototype.clear=kn;ut.prototype.delete=Rn;ut.prototype.get=Ln;ut.prototype.has=Cn;ut.prototype.set=Nn;var vr=ut;function vu(){this.__data__=[],this.size=0}var Pn=vu;function bu(t,e){for(var r=t.length;r--;)if(at(t[r][0],e))return r;return-1}var ye=bu;var Tu=Array.prototype,Iu=Tu.splice;function Eu(t){var e=this.__data__,r=ye(e,t);if(r<0)return!1;var n=e.length-1;return r==n?e.pop():Iu.call(e,r,1),--this.size,!0}var Mn=Eu;function Su(t){var e=this.__data__,r=ye(e,t);return r<0?void 0:e[r][1]}var $n=Su;function wu(t){return ye(this.__data__,t)>-1}var Dn=wu;function Ou(t,e){var r=this.__data__,n=ye(r,t);return n<0?(++this.size,r.push([t,e])):r[n][1]=e,this}var jn=Ou;function ft(t){var e=-1,r=t==null?0:t.length;for(this.clear();++e<r;){var n=t[e];this.set(n[0],n[1])}}ft.prototype.clear=Pn;ft.prototype.delete=Mn;ft.prototype.get=$n;ft.prototype.has=Dn;ft.prototype.set=jn;var _e=ft;var Au=F($,"Map"),xe=Au;function ku(){this.size=0,this.__data__={hash:new vr,map:new(xe||_e),string:new vr}}var Gn=ku;function Ru(t){var e=typeof t;return e=="string"||e=="number"||e=="symbol"||e=="boolean"?t!=="__proto__":t===null}var Bn=Ru;function Lu(t,e){var r=t.__data__;return Bn(e)?r[typeof e=="string"?"string":"hash"]:r.map}var ve=Lu;function Cu(t){var e=ve(this,t).delete(t);return this.size-=e?1:0,e}var Un=Cu;function Nu(t){return ve(this,t).get(t)}var Fn=Nu;function Pu(t){return ve(this,t).has(t)}var Hn=Pu;function Mu(t,e){var r=ve(this,t),n=r.size;return r.set(t,e),this.size+=r.size==n?0:1,this}var zn=Mu;function lt(t){var e=-1,r=t==null?0:t.length;for(this.clear();++e<r;){var n=t[e];this.set(n[0],n[1])}}lt.prototype.clear=Gn;lt.prototype.delete=Un;lt.prototype.get=Fn;lt.prototype.has=Hn;lt.prototype.set=zn;var Ge=lt;var $u="Expected a function";function br(t,e){if(typeof t!="function"||e!=null&&typeof e!="function")throw new TypeError($u);var r=function(){var n=arguments,a=e?e.apply(this,n):n[0],o=r.cache;if(o.has(a))return o.get(a);var s=t.apply(this,n);return r.cache=o.set(a,s)||o,s};return r.cache=new(br.Cache||Ge),r}br.Cache=Ge;var Vn=br;var Du=500;function ju(t){var e=Vn(t,function(n){return r.size===Du&&r.clear(),n}),r=e.cache;return e}var Zn=ju;var Gu=/[^.[\]]+|\[(?:(-?\d+(?:\.\d+)?)|(["'])((?:(?!\2)[^\\]|\\.)*?)\2)\]|(?=(?:\.|\[\])(?:\.|\[\]|$))/g,Bu=/\\(\\)?/g,Uu=Zn(function(t){var e=[];return t.charCodeAt(0)===46&&e.push(""),t.replace(Gu,function(r,n,a,o){e.push(a?o.replace(Bu,"$1"):n||r)}),e}),Wn=Uu;function Fu(t){return t==null?"":en(t)}var Kn=Fu;function Hu(t,e){return R(t)?t:ct(t,e)?[t]:Wn(Kn(t))}var Vt=Hu;var zu=1/0;function Vu(t){if(typeof t=="string"||ie(t))return t;var e=t+"";return e=="0"&&1/t==-zu?"-0":e}var be=Vu;function Zu(t,e){e=Vt(e,t);for(var r=0,n=e.length;t!=null&&r<n;)t=t[be(e[r++])];return r&&r==n?t:void 0}var dt=Zu;function Wu(t,e,r){var n=t==null?void 0:dt(t,e);return n===void 0?r:n}var Yn=Wu;function Ku(t,e){for(var r=-1,n=e.length,a=t.length;++r<n;)t[a+r]=e[r];return t}var Zt=Ku;var qn=G?G.isConcatSpreadable:void 0;function Yu(t){return R(t)||st(t)||!!(qn&&t&&t[qn])}var Jn=Yu;function Xn(t,e,r,n,a){var o=-1,s=t.length;for(r||(r=Jn),a||(a=[]);++o<s;){var i=t[o];e>0&&r(i)?e>1?Xn(i,e-1,r,n,a):Zt(a,i):n||(a[a.length]=i)}return a}var Qn=Xn;function qu(){this.__data__=new _e,this.size=0}var ea=qu;function Ju(t){var e=this.__data__,r=e.delete(t);return this.size=e.size,r}var ta=Ju;function Xu(t){return this.__data__.get(t)}var ra=Xu;function Qu(t){return this.__data__.has(t)}var na=Qu;var ef=200;function tf(t,e){var r=this.__data__;if(r instanceof _e){var n=r.__data__;if(!xe||n.length<ef-1)return n.push([t,e]),this.size=++r.size,this;r=this.__data__=new Ge(n)}return r.set(t,e),this.size=r.size,this}var aa=tf;function pt(t){var e=this.__data__=new _e(t);this.size=e.size}pt.prototype.clear=ea;pt.prototype.delete=ta;pt.prototype.get=ra;pt.prototype.has=na;pt.prototype.set=aa;var mt=pt;function rf(t,e){for(var r=-1,n=t==null?0:t.length,a=0,o=[];++r<n;){var s=t[r];e(s,r,t)&&(o[a++]=s)}return o}var oa=rf;function nf(){return[]}var sa=nf;var af=Object.prototype,of=af.propertyIsEnumerable,ia=Object.getOwnPropertySymbols,sf=ia?function(t){return t==null?[]:(t=Object(t),oa(ia(t),function(e){return of.call(t,e)}))}:sa,ca=sf;function cf(t,e,r){var n=e(t);return R(t)?n:Zt(n,r(t))}var ua=cf;function uf(t){return ua(t,it,ca)}var Tr=uf;var ff=F($,"DataView"),Wt=ff;var lf=F($,"Promise"),Kt=lf;var df=F($,"Set"),Yt=df;var fa="[object Map]",pf="[object Object]",la="[object Promise]",da="[object Set]",pa="[object WeakMap]",ma="[object DataView]",mf=ce(Wt),hf=ce(xe),gf=ce(Kt),yf=ce(Yt),_f=ce(Ft),Be=Y;(Wt&&Be(new Wt(new ArrayBuffer(1)))!=ma||xe&&Be(new xe)!=fa||Kt&&Be(Kt.resolve())!=la||Yt&&Be(new Yt)!=da||Ft&&Be(new Ft)!=pa)&&(Be=function(t){var e=Y(t),r=e==pf?t.constructor:void 0,n=r?ce(r):"";if(n)switch(n){case mf:return ma;case hf:return fa;case gf:return la;case yf:return da;case _f:return pa}return e});var Ir=Be;var xf=$.Uint8Array,Er=xf;var vf="__lodash_hash_undefined__";function bf(t){return this.__data__.set(t,vf),this}var ha=bf;function Tf(t){return this.__data__.has(t)}var ga=Tf;function qt(t){var e=-1,r=t==null?0:t.length;for(this.__data__=new Ge;++e<r;)this.add(t[e])}qt.prototype.add=qt.prototype.push=ha;qt.prototype.has=ga;var ya=qt;function If(t,e){for(var r=-1,n=t==null?0:t.length;++r<n;)if(e(t[r],r,t))return!0;return!1}var _a=If;function Ef(t,e){return t.has(e)}var xa=Ef;var Sf=1,wf=2;function Of(t,e,r,n,a,o){var s=r&Sf,i=t.length,c=e.length;if(i!=c&&!(s&&c>i))return!1;var u=o.get(t),l=o.get(e);if(u&&l)return u==e&&l==t;var m=-1,g=!0,x=r&wf?new ya:void 0;for(o.set(t,e),o.set(e,t);++m<i;){var O=t[m],S=e[m];if(n)var w=s?n(S,O,m,e,t,o):n(O,S,m,t,e,o);if(w!==void 0){if(w)continue;g=!1;break}if(x){if(!_a(e,function(M,re){if(!xa(x,re)&&(O===M||a(O,M,r,n,o)))return x.push(re)})){g=!1;break}}else if(!(O===S||a(O,S,r,n,o))){g=!1;break}}return o.delete(t),o.delete(e),g}var Jt=Of;function Af(t){var e=-1,r=Array(t.size);return t.forEach(function(n,a){r[++e]=[a,n]}),r}var va=Af;function kf(t){var e=-1,r=Array(t.size);return t.forEach(function(n){r[++e]=n}),r}var ba=kf;var Rf=1,Lf=2,Cf="[object Boolean]",Nf="[object Date]",Pf="[object Error]",Mf="[object Map]",$f="[object Number]",Df="[object RegExp]",jf="[object Set]",Gf="[object String]",Bf="[object Symbol]",Uf="[object ArrayBuffer]",Ff="[object DataView]",Ta=G?G.prototype:void 0,Sr=Ta?Ta.valueOf:void 0;function Hf(t,e,r,n,a,o,s){switch(r){case Ff:if(t.byteLength!=e.byteLength||t.byteOffset!=e.byteOffset)return!1;t=t.buffer,e=e.buffer;case Uf:return!(t.byteLength!=e.byteLength||!o(new Er(t),new Er(e)));case Cf:case Nf:case $f:return at(+t,+e);case Pf:return t.name==e.name&&t.message==e.message;case Df:case Gf:return t==e+"";case Mf:var i=va;case jf:var c=n&Rf;if(i||(i=ba),t.size!=e.size&&!c)return!1;var u=s.get(t);if(u)return u==e;n|=Lf,s.set(t,e);var l=Jt(i(t),i(e),n,a,o,s);return s.delete(t),l;case Bf:if(Sr)return Sr.call(t)==Sr.call(e)}return!1}var Ia=Hf;var zf=1,Vf=Object.prototype,Zf=Vf.hasOwnProperty;function Wf(t,e,r,n,a,o){var s=r&zf,i=Tr(t),c=i.length,u=Tr(e),l=u.length;if(c!=l&&!s)return!1;for(var m=c;m--;){var g=i[m];if(!(s?g in e:Zf.call(e,g)))return!1}var x=o.get(t),O=o.get(e);if(x&&O)return x==e&&O==t;var S=!0;o.set(t,e),o.set(e,t);for(var w=s;++m<c;){g=i[m];var M=t[g],re=e[g];if(n)var Ct=s?n(re,M,g,e,t,o):n(M,re,g,t,e,o);if(!(Ct===void 0?M===re||a(M,re,r,n,o):Ct)){S=!1;break}w||(w=g=="constructor")}if(S&&!w){var Ve=t.constructor,Nt=e.constructor;Ve!=Nt&&"constructor"in t&&"constructor"in e&&!(typeof Ve=="function"&&Ve instanceof Ve&&typeof Nt=="function"&&Nt instanceof Nt)&&(S=!1)}return o.delete(t),o.delete(e),S}var Ea=Wf;var Kf=1,Sa="[object Arguments]",wa="[object Array]",Xt="[object Object]",Yf=Object.prototype,Oa=Yf.hasOwnProperty;function qf(t,e,r,n,a,o){var s=R(t),i=R(e),c=s?wa:Ir(t),u=i?wa:Ir(e);c=c==Sa?Xt:c,u=u==Sa?Xt:u;var l=c==Xt,m=u==Xt,g=c==u;if(g&&wt(t)){if(!wt(e))return!1;s=!0,l=!1}if(g&&!l)return o||(o=new mt),s||zt(t)?Jt(t,e,r,n,a,o):Ia(t,e,c,r,n,a,o);if(!(r&Kf)){var x=l&&Oa.call(t,"__wrapped__"),O=m&&Oa.call(e,"__wrapped__");if(x||O){var S=x?t.value():t,w=O?e.value():e;return o||(o=new mt),a(S,w,r,n,o)}}return g?(o||(o=new mt),Ea(t,e,r,n,a,o)):!1}var Aa=qf;function ka(t,e,r,n,a){return t===e?!0:t==null||e==null||!q(t)&&!q(e)?t!==t&&e!==e:Aa(t,e,r,n,ka,a)}var Qt=ka;var Jf=1,Xf=2;function Qf(t,e,r,n){var a=r.length,o=a,s=!n;if(t==null)return!o;for(t=Object(t);a--;){var i=r[a];if(s&&i[2]?i[1]!==t[i[0]]:!(i[0]in t))return!1}for(;++a<o;){i=r[a];var c=i[0],u=t[c],l=i[1];if(s&&i[2]){if(u===void 0&&!(c in t))return!1}else{var m=new mt;if(n)var g=n(u,l,c,t,e,m);if(!(g===void 0?Qt(l,u,Jf|Xf,n,m):g))return!1}}return!0}var Ra=Qf;function el(t){return t===t&&!me(t)}var er=el;function tl(t){for(var e=it(t),r=e.length;r--;){var n=e[r],a=t[n];e[r]=[n,a,er(a)]}return e}var La=tl;function rl(t,e){return function(r){return r==null?!1:r[t]===e&&(e!==void 0||t in Object(r))}}var tr=rl;function nl(t){var e=La(t);return e.length==1&&e[0][2]?tr(e[0][0],e[0][1]):function(r){return r===t||Ra(r,t,e)}}var Ca=nl;function al(t,e){return t!=null&&e in Object(t)}var Na=al;function ol(t,e,r){e=Vt(e,t);for(var n=-1,a=e.length,o=!1;++n<a;){var s=be(e[n]);if(!(o=t!=null&&r(t,s)))break;t=t[s]}return o||++n!=a?o:(a=t==null?0:t.length,!!a&&ot(a)&&nt(s,a)&&(R(t)||st(t)))}var Pa=ol;function sl(t,e){return t!=null&&Pa(t,e,Na)}var Ma=sl;var il=1,cl=2;function ul(t,e){return ct(t)&&er(e)?tr(be(t),e):function(r){var n=Yn(r,t);return n===void 0&&n===e?Ma(r,t):Qt(e,n,il|cl)}}var $a=ul;function fl(t){return function(e){return e?.[t]}}var Da=fl;function ll(t){return function(e){return dt(e,t)}}var ja=ll;function dl(t){return ct(t)?Da(be(t)):ja(t)}var Ga=dl;function pl(t){return typeof t=="function"?t:t==null?he:typeof t=="object"?R(t)?$a(t[0],t[1]):Ca(t):Ga(t)}var rr=pl;function ml(t,e,r,n){for(var a=-1,o=t==null?0:t.length;++a<o;){var s=t[a];e(n,s,r(s),t)}return n}var Ba=ml;function hl(t){return function(e,r,n){for(var a=-1,o=Object(e),s=n(e),i=s.length;i--;){var c=s[t?i:++a];if(r(o[c],c,o)===!1)break}return e}}var Ua=hl;var gl=Ua(),Fa=gl;function yl(t,e){return t&&Fa(t,e,it)}var Ha=yl;function _l(t,e){return function(r,n){if(r==null)return r;if(!ge(r))return t(r,n);for(var a=r.length,o=e?a:-1,s=Object(r);(e?o--:++o<a)&&n(s[o],o,s)!==!1;);return r}}var za=_l;var xl=za(Ha),nr=xl;function vl(t,e,r,n){return nr(t,function(a,o,s){e(n,a,r(a),s)}),n}var Va=vl;function bl(t,e){return function(r,n){var a=R(r)?Ba:Va,o=e?e():{};return a(r,t,rr(n,2),o)}}var Za=bl;function Tl(t,e){var r=-1,n=ge(t)?Array(t.length):[];return nr(t,function(a,o,s){n[++r]=e(a,o,s)}),n}var Wa=Tl;var Il=Object.prototype,El=Il.hasOwnProperty,Sl=Za(function(t,e,r){El.call(t,r)?t[r].push(e):ln(t,r,[e])}),At=Sl;function wl(t,e){var r=t.length;for(t.sort(e);r--;)t[r]=t[r].value;return t}var Ka=wl;function Ol(t,e){if(t!==e){var r=t!==void 0,n=t===null,a=t===t,o=ie(t),s=e!==void 0,i=e===null,c=e===e,u=ie(e);if(!i&&!u&&!o&&t>e||o&&s&&c&&!i&&!u||n&&s&&c||!r&&c||!a)return 1;if(!n&&!o&&!u&&t<e||u&&r&&a&&!n&&!o||i&&r&&a||!s&&a||!c)return-1}return 0}var Ya=Ol;function Al(t,e,r){for(var n=-1,a=t.criteria,o=e.criteria,s=a.length,i=r.length;++n<s;){var c=Ya(a[n],o[n]);if(c){if(n>=i)return c;var u=r[n];return c*(u=="desc"?-1:1)}}return t.index-e.index}var qa=Al;function kl(t,e,r){e.length?e=tt(e,function(o){return R(o)?function(s){return dt(s,o.length===1?o[0]:o)}:o}):e=[he];var n=-1;e=tt(e,Ht(rr));var a=Wa(t,function(o,s,i){var c=tt(e,function(u){return u(o)});return{criteria:c,index:++n,value:o}});return Ka(a,function(o,s){return qa(o,s,r)})}var Ja=kl;var Rl=mn(function(t,e){if(t==null)return[];var r=e.length;return r>1&&gr(t,e[0],e[1])?e=[]:r>2&&gr(e[0],e[1],e[2])&&(e=[e[0]]),Ja(t,Qn(e,1),[])}),wr=Rl;Z();function E(t){return{content:[{type:"text",text:t}]}}function te(t,e){return!t||t.length<=e?t:t.slice(0,e)+"..."}var bt=200;function Oo(t){t.tool("search",`Search Sigil knowledge base for facts across all ingested documents.
12
16
  Automatically detects entity names and returns entity-centric results.
13
17
  Use for: "how does X work", "what is Y?", "what are the rules for Z", domain knowledge, decisions.
14
18
  Returns compact facts. Use get_fact_context(factId) for full detail on any fact.
15
19
  Set includeChunks=true only when raw document context is needed.
16
- Set format="compact" for token-efficient output (one line per category, no IDs/metadata).`,{query:y.string().describe("Natural language search query"),limit:y.number().optional().default(5).describe("Max facts to return (default 5)"),namespaces:y.array(y.string()).optional().describe("Filter by namespaces"),minConfidence:y.enum(["low","medium","high"]).optional().default("medium").describe("Minimum fact confidence"),includeChunks:y.boolean().optional().default(!1).describe("Include raw document chunks (verbose \u2014 only when needed)"),useGraph:y.boolean().optional().default(!1).describe("Traverse entity graph for additional related facts"),pointInTime:y.string().optional().describe("ISO timestamp \u2014 return only facts valid at this point in time"),format:y.enum(["full","compact"]).optional().default("full").describe('Output format: "full" (default) or "compact" (token-efficient, one line per category)'),podScope:y.union([y.literal("auto"),y.literal("global"),y.array(y.string())]).optional().describe('Pod scope: "auto" (active project/session pods \u2014 the default), "global" (whole brain, no scope), or list of pod uids/names.')},async({query:e,limit:r,namespaces:n,minConfidence:a,includeChunks:o,useGraph:s,pointInTime:i,format:u,podScope:f})=>{let l=await P("search",{query:e,namespaces:n,limit:r,minConfidence:a,includeChunks:o,useGraph:s,pointInTime:i,podScope:f??"auto",cwd:process.cwd(),route:!1,synthesize:!1}),{facts:m,chunks:g,matchedEntity:x,relatedEntities:w}=l;if(u==="compact")return O(sd(m,x));let E=[];if(x&&(E.push(`**Matched entity:** ${x.name} (${x.entityType||x.type}, id:${x.id}, ${x.mentions??x.mentionCount??0} mentions)`),x.description&&E.push(x.description),E.push("")),m.length){E.push(`**Facts (${m.length}):**`);for(let S of m){let M=Q(S.content,ht),ee=S.importance==="vital"?" **[VITAL]**":"",Et=S.agent?` \xB7 via ${S.agent}`:"",Fe=Array.isArray(S.sourceDocumentIds)&&S.sourceDocumentIds.length?` \xB7 doc#${S.sourceDocumentIds[0]}`:"";E.push(`- [${S.category}] ${M}${ee} _(${S.confidence}, id:${S.id}${Et}${Fe})_`)}}if(w.length){E.push(""),E.push(`**Related entities (${w.length}):**`);for(let S of w.slice(0,10))E.push(`- ${S.name} (${S.entityType||S.type}) [${S.relation}] id:${S.id}`)}if(o&&g.length){E.push(""),E.push(`**Chunks (${g.length}):**`);for(let S of g.slice(0,3)){let M=S.sectionHeading?`[${S.sectionHeading}] `:"";E.push(`---
17
- ${M}${Q(S.content,500)}`)}}return!m.length&&!g.length&&E.push("No results found. Try broader terms or use search_entity to find entity names."),x&&E.push(`
18
- _Drill down: get_entity_context(entityId=${x.id}) for full details about ${x.name}_`),O(E.join(`
19
- `))})}function sd(t,e){let r=[];if(e&&r.push(`> ${e.name} (${e.entityType||e.type})`),!t.length)return r.push("No results."),r.join(`
20
- `);let n=Tt(t,"category");for(let[a,o]of Object.entries(n)){let i=yr(o,u=>u.importance==="vital"?0:1).map(u=>u.content);r.push(`[${a}]: ${i.join(". ")}`)}return r.join(`
21
- `)}Y();function Eo(t){t.tool("search_entity",`Find entities in the knowledge graph by name or type.
20
+ Set format="compact" for token-efficient output (one line per category, no IDs/metadata).`,{query:y.string().describe("Natural language search query"),limit:y.number().optional().default(5).describe("Max facts to return (default 5)"),namespaces:y.array(y.string()).optional().describe("Filter by namespaces"),minConfidence:y.enum(["low","medium","high"]).optional().default("medium").describe("Minimum fact confidence"),includeChunks:y.boolean().optional().default(!1).describe("Include raw document chunks (verbose \u2014 only when needed)"),useGraph:y.boolean().optional().default(!1).describe("Traverse entity graph for additional related facts"),pointInTime:y.string().optional().describe("ISO timestamp \u2014 return only facts valid at this point in time"),format:y.enum(["full","compact"]).optional().default("full").describe('Output format: "full" (default) or "compact" (token-efficient, one line per category)'),podScope:y.union([y.literal("auto"),y.literal("global"),y.array(y.string())]).optional().describe('Pod scope: "auto" (active project/session pods \u2014 the default), "global" (whole brain, no scope), or list of pod uids/names.')},async({query:e,limit:r,namespaces:n,minConfidence:a,includeChunks:o,useGraph:s,pointInTime:i,format:c,podScope:u})=>{let l=await L("search",{query:e,namespaces:n,limit:r,minConfidence:a,includeChunks:o,useGraph:s,pointInTime:i,podScope:u??"auto",cwd:process.cwd(),route:!1,synthesize:!1}),{facts:m,chunks:g,matchedEntity:x,relatedEntities:O}=l;if(c==="compact")return E(Id(m,x));let S=[];if(x&&(S.push(`**Matched entity:** ${x.name} (${x.entityType||x.type}, id:${x.id}, ${x.mentions??x.mentionCount??0} mentions)`),x.description&&S.push(x.description),S.push("")),m.length){S.push(`**Facts (${m.length}):**`);for(let w of m){let M=te(w.content,bt),re=w.importance==="vital"?" **[VITAL]**":"",Ct=w.agent?` \xB7 via ${w.agent}`:"",Ve=Array.isArray(w.sourceDocumentIds)&&w.sourceDocumentIds.length?` \xB7 doc#${w.sourceDocumentIds[0]}`:"";S.push(`- [${w.category}] ${M}${re} _(${w.confidence}, id:${w.id}${Ct}${Ve})_`)}}if(O.length){S.push(""),S.push(`**Related entities (${O.length}):**`);for(let w of O.slice(0,10))S.push(`- ${w.name} (${w.entityType||w.type}) [${w.relation}] id:${w.id}`)}if(o&&g.length){S.push(""),S.push(`**Chunks (${g.length}):**`);for(let w of g.slice(0,3)){let M=w.sectionHeading?`[${w.sectionHeading}] `:"";S.push(`---
21
+ ${M}${te(w.content,500)}`)}}return!m.length&&!g.length&&S.push("No results found. Try broader terms or use search_entity to find entity names."),x&&S.push(`
22
+ _Drill down: get_entity_context(entityId=${x.id}) for full details about ${x.name}_`),E(S.join(`
23
+ `))})}function Id(t,e){let r=[];if(e&&r.push(`> ${e.name} (${e.entityType||e.type})`),!t.length)return r.push("No results."),r.join(`
24
+ `);let n=At(t,"category");for(let[a,o]of Object.entries(n)){let i=wr(o,c=>c.importance==="vital"?0:1).map(c=>c.content);r.push(`[${a}]: ${i.join(". ")}`)}return r.join(`
25
+ `)}Z();function Ao(t){t.tool("search_entity",`Find entities in the knowledge graph by name or type.
22
26
  Use for: "find Alice", "list all topics", "show all people", "find documents about normalization".
23
27
  Entity types: document, person, topic (extensible per domain).
24
- Returns compact entity list. Use get_entity_context(entityId) for full details.`,{query:y.string().optional().describe('Entity name to search (e.g. "Alice", "Cohort 6")'),entityType:y.string().optional().describe("Filter by type: session, course, person, topic"),limit:y.number().optional().default(10).describe("Max results"),namespace:y.string().optional().describe("Namespace. Omit for default.")},async({query:e,entityType:r,limit:n,namespace:a})=>{if(!e&&!r)return O("Error: Provide either a query (entity name) or entityType.");let{entities:o}=await P("searchEntity",{query:e,entityType:r,limit:n,namespace:a});if(!o.length){let u=e?`matching "${e}"`:`of type "${r}"`;return O(`No entities found ${u}.`)}let s=o.map(u=>{let f=u.description?` \u2014 ${u.description}`:"";return`- **${u.name}** (${u.entityType}, id:${u.id}, ${u.mentionCount} mentions)${f}`}),i=e?`Entities matching "${e}"`:`${r} entities`;return O(`${i} (${o.length}):
28
+ Returns compact entity list. Use get_entity_context(entityId) for full details.`,{query:y.string().optional().describe('Entity name to search (e.g. "Alice", "Cohort 6")'),entityType:y.string().optional().describe("Filter by type: session, course, person, topic"),limit:y.number().optional().default(10).describe("Max results"),namespace:y.string().optional().describe("Namespace. Omit for default.")},async({query:e,entityType:r,limit:n,namespace:a})=>{if(!e&&!r)return E("Error: Provide either a query (entity name) or entityType.");let{entities:o}=await L("searchEntity",{query:e,entityType:r,limit:n,namespace:a});if(!o.length){let c=e?`matching "${e}"`:`of type "${r}"`;return E(`No entities found ${c}.`)}let s=o.map(c=>{let u=c.description?` \u2014 ${c.description}`:"";return`- **${c.name}** (${c.entityType}, id:${c.id}, ${c.mentionCount} mentions)${u}`}),i=e?`Entities matching "${e}"`:`${r} entities`;return E(`${i} (${o.length}):
25
29
  ${s.join(`
26
30
  `)}
27
31
 
28
- _Use get_entity_context(entityId=<id>) for details or traverse_graph(startEntityId=<id>) for connections._`)})}Y();function So(t){t.tool("traverse_graph",`Navigate entity relationships in the knowledge graph.
32
+ _Use get_entity_context(entityId=<id>) for details or traverse_graph(startEntityId=<id>) for connections._`)})}Z();function ko(t){t.tool("traverse_graph",`Navigate entity relationships in the knowledge graph.
29
33
  Use for: "who did Alice mentor?", "what topics does course X cover?", "how is A related to B?",
30
34
  "what documents cover this topic?", "show mentorship chain".
31
- Relation types: PART_OF, LED_BY, MENTORED, COVERS, FOLLOWS.`,{startEntityId:y.number().describe("Starting entity ID (from search_entity results)"),action:y.enum(["neighbors","path","related"]).optional().default("neighbors").describe("neighbors = direct connections, path = shortest path to target, related = all reachable"),targetEntityId:y.number().optional().describe('Target entity ID (required for "path" action)'),relationType:y.string().optional().describe("Filter: PART_OF, LED_BY, MENTORED, COVERS, FOLLOWS"),maxDepth:y.number().optional().default(2).describe("Traversal depth 1-3"),limit:y.number().optional().default(20).describe("Max results")},async({startEntityId:e,action:r,targetEntityId:n,relationType:a,maxDepth:o,limit:s})=>{let i=await P("traverseGraph",{startEntityId:e,action:r,targetEntityId:n,relationType:a,maxDepth:o,limit:s});if(i.notFound)return O(`Error: Entity ID ${e} not found.`);let u=`${i.start.name} (${i.start.entityType}, id:${i.start.id})`;if(i.action==="path"){if(!i.path)return O(`No path found from ${i.start.name} to entity ${n}.`);let g=i.path.path.map((x,w)=>{let E=w<i.path.relationTypes.length?` --[${i.path.relationTypes[w]}]--> `:"";return`${x.name} (${x.entityType})${E}`});return O(`Path (${i.path.depth} hops):
32
- ${g.join("")}`)}if(i.action==="related"){let g=i.related||[];if(!g.length)return O(`${i.start.name} has no related entities within ${o} hops.`);let x=Tt(g,"depth"),w=[`Entities related to ${u} (${g.length}):`];for(let E of Object.keys(x).sort()){let S=E==="1"?"Direct":`${E} hops`;w.push(`
33
- ${S}:`);for(let M of x[E])w.push(`- [${M.relationType}] ${M.name} (${M.entityType}, id:${M.entityId})`)}return O(w.join(`
34
- `))}if(i.related){let g=i.related.map(x=>`- [${x.relationType}] ${x.name} (${x.entityType}, id:${x.entityId||x.id}) depth:${x.depth}`);return O(`${u}
35
+ Relation types: PART_OF, LED_BY, MENTORED, COVERS, FOLLOWS.`,{startEntityId:y.number().describe("Starting entity ID (from search_entity results)"),action:y.enum(["neighbors","path","related"]).optional().default("neighbors").describe("neighbors = direct connections, path = shortest path to target, related = all reachable"),targetEntityId:y.number().optional().describe('Target entity ID (required for "path" action)'),relationType:y.string().optional().describe("Filter: PART_OF, LED_BY, MENTORED, COVERS, FOLLOWS"),maxDepth:y.number().optional().default(2).describe("Traversal depth 1-3"),limit:y.number().optional().default(20).describe("Max results")},async({startEntityId:e,action:r,targetEntityId:n,relationType:a,maxDepth:o,limit:s})=>{let i=await L("traverseGraph",{startEntityId:e,action:r,targetEntityId:n,relationType:a,maxDepth:o,limit:s});if(i.notFound)return E(`Error: Entity ID ${e} not found.`);let c=`${i.start.name} (${i.start.entityType}, id:${i.start.id})`;if(i.action==="path"){if(!i.path)return E(`No path found from ${i.start.name} to entity ${n}.`);let g=i.path.path.map((x,O)=>{let S=O<i.path.relationTypes.length?` --[${i.path.relationTypes[O]}]--> `:"";return`${x.name} (${x.entityType})${S}`});return E(`Path (${i.path.depth} hops):
36
+ ${g.join("")}`)}if(i.action==="related"){let g=i.related||[];if(!g.length)return E(`${i.start.name} has no related entities within ${o} hops.`);let x=At(g,"depth"),O=[`Entities related to ${c} (${g.length}):`];for(let S of Object.keys(x).sort()){let w=S==="1"?"Direct":`${S} hops`;O.push(`
37
+ ${w}:`);for(let M of x[S])O.push(`- [${M.relationType}] ${M.name} (${M.entityType}, id:${M.entityId})`)}return E(O.join(`
38
+ `))}if(i.related){let g=i.related.map(x=>`- [${x.relationType}] ${x.name} (${x.entityType}, id:${x.entityId||x.id}) depth:${x.depth}`);return E(`${c}
35
39
  Connections (${i.related.length}):
36
40
  ${g.join(`
37
- `)}`)}if(!i.relations?.length)return O(`${u}
38
- No connections found.`);let f=i.relations.filter(g=>g.direction==="outgoing"),l=i.relations.filter(g=>g.direction==="incoming"),m=[u];if(f.length){m.push(`
39
- Outgoing (${f.length}):`);for(let g of f)m.push(`- [${g.relationType}] ${g.name} (${g.entityType}, id:${g.entityId})`)}if(l.length){m.push(`
40
- Incoming (${l.length}):`);for(let g of l)m.push(`- ${g.name} (${g.entityType}, id:${g.entityId}) [${g.relationType}]`)}return O(m.join(`
41
- `))})}Y();function Oo(t){t.tool("get_fact_context",`Get full context for a specific fact: complete content, entities mentioned, relations created, sources.
41
+ `)}`)}if(!i.relations?.length)return E(`${c}
42
+ No connections found.`);let u=i.relations.filter(g=>g.direction==="outgoing"),l=i.relations.filter(g=>g.direction==="incoming"),m=[c];if(u.length){m.push(`
43
+ Outgoing (${u.length}):`);for(let g of u)m.push(`- [${g.relationType}] ${g.name} (${g.entityType}, id:${g.entityId})`)}if(l.length){m.push(`
44
+ Incoming (${l.length}):`);for(let g of l)m.push(`- ${g.name} (${g.entityType}, id:${g.entityId}) [${g.relationType}]`)}return E(m.join(`
45
+ `))})}Z();function Ro(t){t.tool("get_fact_context",`Get full context for a specific fact: complete content, entities mentioned, relations created, sources.
42
46
  Use for: drilling down on a fact from search results, checking provenance, understanding connections.
43
- This is the detail view \u2014 search returns truncated facts, this returns everything.`,{factId:y.number().optional().describe("Fact ID (from search results)"),uid:y.string().optional().describe('Fact UID (e.g. "fact-a1b2c3d4")')},async({uid:e,factId:r})=>{if(!e&&!r)return O("Error: Provide either factId or uid.");let n=await P("getFactContext",{uid:e,factId:r});if(n.notFound)return O("Error: Fact not found.");let{fact:a,entities:o,relations:s,documents:i}=n,u=[`**Fact ${a.uid}** (${a.category}, ${a.confidence}, ${a.status})`,a.content];if(a.sourceSection&&u.push(`Source section: ${a.sourceSection}`),o.length&&u.push(`
44
- Entities mentioned: ${o.map(f=>`${f.name} (${f.entityType}, id:${f.id})`).join(", ")}`),s.length){u.push(`
45
- Relations from this fact:`);for(let f of s)u.push(`- ${f.sourceName} --[${f.relationType}]--> ${f.targetName}`)}return i.length&&u.push(`
46
- Sources: ${i.map(f=>`${f.title} (${f.sourceType})`).join(", ")}`),O(u.join(`
47
- `))})}Y();function wo(t){t.tool("get_entity_context",`Get full context for an entity: relations, connected facts, graph position.
47
+ This is the detail view \u2014 search returns truncated facts, this returns everything.`,{factId:y.number().optional().describe("Fact ID (from search results)"),uid:y.string().optional().describe('Fact UID (e.g. "fact-a1b2c3d4")')},async({uid:e,factId:r})=>{if(!e&&!r)return E("Error: Provide either factId or uid.");let n=await L("getFactContext",{uid:e,factId:r});if(n.notFound)return E("Error: Fact not found.");let{fact:a,entities:o,relations:s,documents:i}=n,c=[`**Fact ${a.uid}** (${a.category}, ${a.confidence}, ${a.status})`,a.content];if(a.sourceSection&&c.push(`Source section: ${a.sourceSection}`),o.length&&c.push(`
48
+ Entities mentioned: ${o.map(u=>`${u.name} (${u.entityType}, id:${u.id})`).join(", ")}`),s.length){c.push(`
49
+ Relations from this fact:`);for(let u of s)c.push(`- ${u.sourceName} --[${u.relationType}]--> ${u.targetName}`)}return i.length&&c.push(`
50
+ Sources: ${i.map(u=>`${u.title} (${u.sourceType})`).join(", ")}`),E(c.join(`
51
+ `))})}Z();function Lo(t){t.tool("get_entity_context",`Get full context for an entity: relations, connected facts, graph position.
48
52
  Use for: "tell me about Alice", "what documents cover this topic?", "show expertise areas".
49
- Returns entity details + relations + key facts (truncated \u2014 use get_fact_context for full text).`,{entityId:y.number().optional().describe("Entity ID (from search_entity or search results)"),name:y.string().optional().describe("Entity name (alternative to ID)"),namespace:y.string().optional().describe("Namespace. Omit for default.")},async({entityId:e,name:r,namespace:n})=>{if(!e&&!r)return O("Error: Provide either entityId or name.");let a=await P("getEntityContext",{entityId:e,name:r,namespace:n});if(a.notFound)return O("Error: Entity not found.");let{entity:o,relations:s,facts:i}=a,u=[`**${o.name}** (${o.entityType}, id:${o.id}, ${o.mentionCount} mentions)`];o.description&&u.push(o.description);let f=s.filter(m=>m.direction==="outgoing"),l=s.filter(m=>m.direction==="incoming");if(f.length){u.push(`
50
- Outgoing relations (${f.length}):`);for(let m of f.slice(0,15))u.push(`- [${m.relationType}] ${m.name} (${m.entityType}, id:${m.entityId})`);f.length>15&&u.push(` ...and ${f.length-15} more`)}if(l.length){u.push(`
51
- Incoming relations (${l.length}):`);for(let m of l.slice(0,15))u.push(`- ${m.name} (${m.entityType}, id:${m.entityId}) [${m.relationType}]`);l.length>15&&u.push(` ...and ${l.length-15} more`)}if(i.length){u.push(`
52
- Key facts (${i.length}):`);for(let m of i){let g=Q(m.content,ht);u.push(`- [${m.category}] ${g} _(${m.confidence}, id:${m.id})_`)}}return!f.length&&!l.length&&!i.length&&u.push(`
53
- No connections or facts found for this entity.`),u.push(`
54
- _Use traverse_graph(startEntityId=${o.id}) for deeper graph exploration._`),O(u.join(`
55
- `))})}Y();function Ao(t){t.tool("status",`Show Sigil knowledge base statistics \u2014 documents, chunks, facts, entities, relations.
56
- Use when: checking system health, verifying ingestion, reviewing knowledge graph size.`,{namespace:y.string().optional().describe("Filter by namespace. Omit for global stats.")},async({namespace:e})=>{let r=await P("status",{namespace:e,hotFactsLimit:5}),a=[`Sigil KB${r.namespace?` (${r.namespace})`:""}: ${r.documents} docs, ${r.chunks} chunks, ${r.facts} facts`,`Entities: ${r.entities.documents} documents, ${r.entities.people} people, ${r.entities.topics} topics`,`Relations: ${r.relations}`,`Hot facts (top ${r.hotFacts.length}): ${r.hotFacts.map(o=>`${Q(o.content,60)} (${o.accessCount}x)`).join(", ")||"none yet"}`].join(`
57
- `);return O(a)})}Y();function ko(t){t.tool("ingest",`Ingest a document into the Sigil knowledge base. Accepts raw content, a file path, or a URL.
53
+ Returns entity details + relations + key facts (truncated \u2014 use get_fact_context for full text).`,{entityId:y.number().optional().describe("Entity ID (from search_entity or search results)"),name:y.string().optional().describe("Entity name (alternative to ID)"),namespace:y.string().optional().describe("Namespace. Omit for default.")},async({entityId:e,name:r,namespace:n})=>{if(!e&&!r)return E("Error: Provide either entityId or name.");let a=await L("getEntityContext",{entityId:e,name:r,namespace:n});if(a.notFound)return E("Error: Entity not found.");let{entity:o,relations:s,facts:i}=a,c=[`**${o.name}** (${o.entityType}, id:${o.id}, ${o.mentionCount} mentions)`];o.description&&c.push(o.description);let u=s.filter(m=>m.direction==="outgoing"),l=s.filter(m=>m.direction==="incoming");if(u.length){c.push(`
54
+ Outgoing relations (${u.length}):`);for(let m of u.slice(0,15))c.push(`- [${m.relationType}] ${m.name} (${m.entityType}, id:${m.entityId})`);u.length>15&&c.push(` ...and ${u.length-15} more`)}if(l.length){c.push(`
55
+ Incoming relations (${l.length}):`);for(let m of l.slice(0,15))c.push(`- ${m.name} (${m.entityType}, id:${m.entityId}) [${m.relationType}]`);l.length>15&&c.push(` ...and ${l.length-15} more`)}if(i.length){c.push(`
56
+ Key facts (${i.length}):`);for(let m of i){let g=te(m.content,bt);c.push(`- [${m.category}] ${g} _(${m.confidence}, id:${m.id})_`)}}return!u.length&&!l.length&&!i.length&&c.push(`
57
+ No connections or facts found for this entity.`),c.push(`
58
+ _Use traverse_graph(startEntityId=${o.id}) for deeper graph exploration._`),E(c.join(`
59
+ `))})}Z();function Co(t){t.tool("status",`Show Sigil knowledge base statistics \u2014 documents, chunks, facts, entities, relations.
60
+ Use when: checking system health, verifying ingestion, reviewing knowledge graph size.`,{namespace:y.string().optional().describe("Filter by namespace. Omit for global stats.")},async({namespace:e})=>{let r=await L("status",{namespace:e,hotFactsLimit:5}),a=[`Sigil KB${r.namespace?` (${r.namespace})`:""}: ${r.documents} docs, ${r.chunks} chunks, ${r.facts} facts`,`Entities: ${r.entities.documents} documents, ${r.entities.people} people, ${r.entities.topics} topics`,`Relations: ${r.relations}`,`Hot facts (top ${r.hotFacts.length}): ${r.hotFacts.map(o=>`${te(o.content,60)} (${o.accessCount}x)`).join(", ")||"none yet"}`].join(`
61
+ `);return E(a)})}Z();function No(t){t.tool("ingest",`Ingest a document into the Sigil knowledge base. Accepts raw content, a file path, or a URL.
58
62
  Parses the content, chunks it, embeds it, extracts facts, links entities, and stores everything for search.
59
- Use when: adding documents to the knowledge base, ingesting files, URLs, or raw text.`,{content:y.string().optional().describe("Raw text content to ingest. Provide this OR filePath OR url."),filePath:y.string().optional().describe("Local file path to ingest. Provide this OR content OR url."),url:y.string().optional().describe("URL to fetch and ingest. Provide this OR content OR filePath."),title:y.string().optional().describe("Document title. Auto-detected if not provided."),namespace:y.string().optional().describe("Namespace for the document. Defaults to config default."),sourceType:y.string().optional().describe("Source type label (e.g., docs, code, notes). Auto-detected from format."),skipFacts:y.boolean().optional().default(!1).describe("Skip fact extraction (faster, chunks only)"),skipEntities:y.boolean().optional().default(!1).describe("Skip entity linking")},async({content:e,filePath:r,url:n,title:a,namespace:o,sourceType:s,skipFacts:i,skipEntities:u})=>{let f=await P("ingestDoc",{content:e,filePath:r,url:n,title:a,namespace:o,sourceType:s,skipFacts:i,skipEntities:u}),l=f.skipped?`Document "${f.title}" already up to date \u2014 skipped.`:[`Document "${f.title}" ingested.`,`- Document ID: ${f.documentId}`,`- Chunks: ${f.chunkCount}`,f.facts?`- Facts: ${f.facts.total} extracted (${f.facts.added} new, ${f.facts.skipped} skipped)`:"- Facts: skipped",f.entities?`- Entities: ${f.entities.entityCount}, Relations: ${f.entities.relationCount}`:"- Entities: skipped",f.output?`- Output: ${f.output}`:""].filter(Boolean).join(`
60
- `);return O(l)})}Y();function Ro(t){t.tool("list_pods",`List memory pods (typed containers segregating facts by source or subject).
63
+ Use when: adding documents to the knowledge base, ingesting files, URLs, or raw text.`,{content:y.string().optional().describe("Raw text content to ingest. Provide this OR filePath OR url."),filePath:y.string().optional().describe("Local file path to ingest. Provide this OR content OR url."),url:y.string().optional().describe("URL to fetch and ingest. Provide this OR content OR filePath."),title:y.string().optional().describe("Document title. Auto-detected if not provided."),namespace:y.string().optional().describe("Namespace for the document. Defaults to config default."),sourceType:y.string().optional().describe("Source type label (e.g., docs, code, notes). Auto-detected from format."),skipFacts:y.boolean().optional().default(!1).describe("Skip fact extraction (faster, chunks only)"),skipEntities:y.boolean().optional().default(!1).describe("Skip entity linking")},async({content:e,filePath:r,url:n,title:a,namespace:o,sourceType:s,skipFacts:i,skipEntities:c})=>{let u=await L("ingestDoc",{content:e,filePath:r,url:n,title:a,namespace:o,sourceType:s,skipFacts:i,skipEntities:c}),l=u.skipped?`Document "${u.title}" already up to date \u2014 skipped.`:[`Document "${u.title}" ingested.`,`- Document ID: ${u.documentId}`,`- Chunks: ${u.chunkCount}`,u.facts?`- Facts: ${u.facts.total} extracted (${u.facts.added} new, ${u.facts.skipped} skipped)`:"- Facts: skipped",u.entities?`- Entities: ${u.entities.entityCount}, Relations: ${u.entities.relationCount}`:"- Entities: skipped",u.output?`- Output: ${u.output}`:""].filter(Boolean).join(`
64
+ `);return E(l)})}Z();function Po(t){t.tool("list_pods",`List memory pods (typed containers segregating facts by source or subject).
61
65
  Use for: "what sessions do I have?", "list everyone I have a pod for", "which workspaces?".
62
66
  Pod types: session (Claude Code), person (people you have a relationship with),
63
- project, connector_workspace, custom.`,{type:y.enum(["session","person","project","connector_workspace","custom"]).optional().describe("Filter by pod type. Omit for all types."),namespace:y.string().optional().describe("Namespace. Omit for default."),status:y.enum(["active","archived"]).optional().default("active"),limit:y.number().int().positive().max(100).optional().default(20)},async({type:e,namespace:r,status:n,limit:a})=>{let{pods:o}=await P("listPods",{type:e,namespace:r,status:n,limit:a});if(!o.length){let i=e?` of type "${e}"`:"";return O(`No${i} pods found.`)}let s=[`Found ${o.length} pod${o.length===1?"":"s"}:`,""];for(let i of o){let u=i.memberFactCount??0,f=i.memberDocCount??0,l=i.updatedAt?new Date(i.updatedAt).toISOString().slice(0,16).replace("T"," "):"\u2014";s.push(`- **${i.name}** (${i.podType}, uid:${i.uid})`),s.push(` facts=${u} docs=${f} updated=${l}`)}return s.push(""),s.push("_Use get_pod(uid=...) for member facts and full metadata._"),O(s.join(`
64
- `))})}Y();function Lo(t){t.tool("get_pod",`Get a memory pod with its member facts, documents, and (for person pods)
67
+ project, connector_workspace, custom.`,{type:y.enum(["session","person","project","connector_workspace","custom"]).optional().describe("Filter by pod type. Omit for all types."),namespace:y.string().optional().describe("Namespace. Omit for default."),status:y.enum(["active","archived"]).optional().default("active"),limit:y.number().int().positive().max(100).optional().default(20)},async({type:e,namespace:r,status:n,limit:a})=>{let{pods:o}=await L("listPods",{type:e,namespace:r,status:n,limit:a});if(!o.length){let i=e?` of type "${e}"`:"";return E(`No${i} pods found.`)}let s=[`Found ${o.length} pod${o.length===1?"":"s"}:`,""];for(let i of o){let c=i.memberFactCount??0,u=i.memberDocCount??0,l=i.updatedAt?new Date(i.updatedAt).toISOString().slice(0,16).replace("T"," "):"\u2014";s.push(`- **${i.name}** (${i.podType}, uid:${i.uid})`),s.push(` facts=${c} docs=${u} updated=${l}`)}return s.push(""),s.push("_Use get_pod(uid=...) for member facts and full metadata._"),E(s.join(`
68
+ `))})}Z();function Mo(t){t.tool("get_pod",`Get a memory pod with its member facts, documents, and (for person pods)
65
69
  the canonical entity link.
66
70
  Use for: "what happened in this session?", "show me everything sigil knows
67
71
  about Dhaval", "what's in the Slack workspace pod?".
68
- Returns pod metadata + up to 20 latest facts + up to 10 latest documents.`,{uid:y.string().describe("Pod uid (from list_pods or sigil session current)")},async({uid:e})=>{let r=await P("getPod",{uid:e});if(r.notFound)return O(`Error: pod ${e} not found.`);let{pod:n,facts:a,documents:o}=r,s=[`**${n.name}** (${n.podType}, uid:${n.uid})`,"",`- namespace: ${n.namespace}`,`- status: ${n.status}`];n.startedAt&&s.push(`- started_at: ${n.startedAt}`),n.endedAt&&s.push(`- ended_at: ${n.endedAt}`),n.entityId&&s.push(`- entity_id: ${n.entityId}`),n.connectionId&&s.push(`- connection_id: ${n.connectionId}`),n.externalId&&s.push(`- external_id: ${n.externalId}`);let i=Object.entries(n.attrs||{}).filter(([,u])=>u!=null&&u!=="");if(i.length){s.push("","Attrs:");for(let[u,f]of i){let l=typeof f=="object"?JSON.stringify(f):f;s.push(`- ${u}: ${l}`)}}if(a.length){s.push("",`Member facts (${a.length}, up to 20):`);for(let u of a){let f=Q(u.content,ht),l=u.podRole==="mention"?" _[mention]_":"";s.push(`- ${f} (id:${u.id})${l}`)}}if(o.length){s.push("",`Member documents (${o.length}, up to 10):`);for(let u of o){let f=u.title||u.sourcePath||`doc-${u.id}`;s.push(`- ${Q(f,80)} (id:${u.id})`)}}return!a.length&&!o.length&&s.push("","_Pod has no member facts or documents yet._"),O(s.join(`
69
- `))})}process.env.SIGIL_AGENT||(process.env.SIGIL_AGENT="mcp");function fd(){let t=new id({name:"sigil",version:"0.2.0"});return Io(t),Eo(t),So(t),Oo(t),wo(t),Lo(t),Ro(t),Ao(t),ko(t),t}async function Co(){let t=fd(),e=new ud;await t.connect(e);let{closeDaemonConnection:r}=await Promise.resolve().then(()=>(Y(),To)),n=()=>{r().catch(()=>{})};return process.on("SIGTERM",n),process.on("SIGINT",n),process.on("beforeExit",n),t}var pd=No(No(ld(import.meta.url))),md=process.env.DOTENV_CONFIG_PATH||(dd(wr(process.cwd(),".env"))?wr(process.cwd(),".env"):null)||wr(pd,".env");cd({path:md,quiet:!0});await Co();
72
+ Returns pod metadata + up to 20 latest facts + up to 10 latest documents.`,{uid:y.string().describe("Pod uid (from list_pods or sigil session current)")},async({uid:e})=>{let r=await L("getPod",{uid:e});if(r.notFound)return E(`Error: pod ${e} not found.`);let{pod:n,facts:a,documents:o}=r,s=[`**${n.name}** (${n.podType}, uid:${n.uid})`,"",`- namespace: ${n.namespace}`,`- status: ${n.status}`];n.startedAt&&s.push(`- started_at: ${n.startedAt}`),n.endedAt&&s.push(`- ended_at: ${n.endedAt}`),n.entityId&&s.push(`- entity_id: ${n.entityId}`),n.connectionId&&s.push(`- connection_id: ${n.connectionId}`),n.externalId&&s.push(`- external_id: ${n.externalId}`);let i=Object.entries(n.attrs||{}).filter(([,c])=>c!=null&&c!=="");if(i.length){s.push("","Attrs:");for(let[c,u]of i){let l=typeof u=="object"?JSON.stringify(u):u;s.push(`- ${c}: ${l}`)}}if(a.length){s.push("",`Member facts (${a.length}, up to 20):`);for(let c of a){let u=te(c.content,bt),l=c.podRole==="mention"?" _[mention]_":"";s.push(`- ${u} (id:${c.id})${l}`)}}if(o.length){s.push("",`Member documents (${o.length}, up to 10):`);for(let c of o){let u=c.title||c.sourcePath||`doc-${c.id}`;s.push(`- ${te(u,80)} (id:${c.id})`)}}return!a.length&&!o.length&&s.push("","_Pod has no member facts or documents yet._"),E(s.join(`
73
+ `))})}Z();function Uo(t){t.tool("prime","Prime your memory for this session \u2014 CALL THIS FIRST, before answering anything.\nThis client has no automatic memory: nothing is recalled or saved for you.\nReturns: Sigil health (DB/providers) + fresh facts about the user and this project.\nIf you skip it, you start with zero knowledge of who the user is or what they're working on.\nAfter priming, still call `search` for specifics and `ingest` to save durable facts.",{limit:y.number().optional().default(12).describe("Max fresh facts to load (default 12)")},async({limit:e}={})=>{let{buildPreamble:r}=await Promise.resolve().then(()=>(jo(),Do)),{renderPreamble:n}=await Promise.resolve().then(()=>(Bo(),Go)),a=await r({cwd:process.cwd(),limit:Number.isFinite(e)?e:12,call:L});return E(n(a,{format:"md",transport:"mcp"}))})}process.env.SIGIL_AGENT||(process.env.SIGIL_AGENT="mcp");function Rd(){let t=new Ad({name:"sigil",version:"0.2.0"});return Uo(t),Oo(t),Ao(t),ko(t),Ro(t),Lo(t),Mo(t),Po(t),Co(t),No(t),t}async function Fo(){let t=Rd(),e=new kd;await t.connect(e);let{closeDaemonConnection:r}=await Promise.resolve().then(()=>(Z(),wo)),n=()=>{r().catch(()=>{})};return process.on("SIGTERM",n),process.on("SIGINT",n),process.on("beforeExit",n),t}var Pd=Ho(Ho(Cd(import.meta.url))),Md=process.env.DOTENV_CONFIG_PATH||(Nd(Mr(process.cwd(),".env"))?Mr(process.cwd(),".env"):null)||Mr(Pd,".env");Ld({path:Md,quiet:!0});await Fo();