ompchamber 3.3.0 → 3.3.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/client/index.html
CHANGED
|
@@ -33,7 +33,7 @@
|
|
|
33
33
|
href="https://fonts.googleapis.com/css2?family=Inter:ital,opsz,wght@0,14..32,100..900;1,14..32,100..900&display=swap"
|
|
34
34
|
/>
|
|
35
35
|
<!--app-head-->
|
|
36
|
-
<link rel="stylesheet" crossorigin href="./static/js/index-bsxxt89j.css"><script type="module" crossorigin src="./static/js/index-
|
|
36
|
+
<link rel="stylesheet" crossorigin href="./static/js/index-bsxxt89j.css"><script type="module" crossorigin src="./static/js/index-4qx6m2p7.js"></script></head>
|
|
37
37
|
<body>
|
|
38
38
|
<div id="app"></div>
|
|
39
39
|
<!--app-bootstrap-->
|
package/dist/client/index.js
CHANGED
|
@@ -663,7 +663,7 @@ return u.substring(s,qi)
|
|
|
663
663
|
`:`c.headers={}
|
|
664
664
|
for(const [k,v] of c.request.headers.entries())c.headers[k]=v
|
|
665
665
|
`},listen(e){return(t,r)=>{if(typeof Bun>"u")throw Error(".listen() is designed to run on Bun only. If you are running Elysia in other environment please use a dedicated plugin or export the handler via Elysia.fetch");if(e.compile(),typeof t=="string"){if(!pp(t))throw Error("Port must be a numeric value");t=parseInt(t)}let n=(s,{withAsync:a=!1}={})=>{let c={},l=[];if(e.event.request?.length||e.event.trace?.length||e.extender.higherOrderFunctions.length)return a?Promise.resolve(c):c;for(let[u,d]of Object.entries(s))if(u=encodeURI(u),mp){if(!d)continue;for(let[f,p]of Object.entries(d))if(!(!p||!(f in eE))){if(p instanceof Promise){a&&(c[u]||(c[u]={}),l.push(p.then((g)=>{g instanceof Response&&(c[u][f]=g),Yl(g)&&(c[u][f]=g)})));continue}!(p instanceof Response)&&!Yl(p)||(c[u]||(c[u]={}),c[u][f]=p)}}else{if(!d)continue;if(d instanceof Promise){a&&(c[u]||(c[u]={}),l.push(d.then((f)=>{f instanceof Response&&(c[u]=f)})));continue}if(!(d instanceof Response))continue;c[u]=d}return a?Promise.all(l).then(()=>c):c},o=ZA(Zp(Zp(n(e.router.response),XA(e)),e.config.serve?.routes)),i=typeof t=="object"?{development:!jo,reusePort:!0,idleTimeout:30,...e.config.serve||{},...t||{},routes:o,websocket:{...e.config.websocket||{},...vy||{},...t.websocket||{}},fetch:e.fetch}:{development:!jo,reusePort:!0,idleTimeout:30,...e.config.serve||{},routes:o,websocket:{...e.config.websocket||{},...vy||{}},port:t,fetch:e.fetch};if(e.server=Bun.serve(i),e.event.start)for(let s=0;s<e.event.start.length;s++)e.event.start[s].fn(e);r&&r(e.server),process.on("beforeExit",async()=>{if(e.server&&(await e.server.stop?.(),e.server=null,e.event.stop))for(let s=0;s<e.event.stop.length;s++)e.event.stop[s].fn(e)}),e.promisedModules.then(async()=>{e.config.aot,e.compile();let s=ZA(Zp(Zp(await n(e.router.response,{withAsync:!0}),XA(e)),e.config.serve?.routes));e.server?.reload({...i,fetch:e.fetch,routes:s}),Bun?.gc(!1)})}},async stop(e,t){if(e.server){if(await e.server.stop(t),e.server=null,e.event.stop?.length)for(let r=0;r<e.event.stop.length;r++)e.event.stop[r].fn(e)}else console.log("Elysia isn't running. Call `app.listen` to start the server.",Error().stack)},ws(e,t,r){let{parse:n,body:o,response:i,...s}=r,a=ut(o,{modules:e.definitions.typebox,models:e.definitions.type,normalize:e.config.normalize}),c=a?a.provider==="standard"?(u)=>a.schema["~standard"].validate(u).issues:(u)=>a.Check(u)===!1:void 0,l=ut(i,{modules:e.definitions.typebox,models:e.definitions.type,normalize:e.config.normalize});e.route("WS",t,async(u)=>{let d=u.server??e.server,{set:f,path:p,qi:g,headers:m,query:y,params:b}=u;if(u.validator=l,r.upgrade)if(typeof r.upgrade=="function"){let v=r.upgrade(u);v instanceof Promise&&await v}else r.upgrade&&Object.assign(f.headers,r.upgrade);if(f.cookie&&Se(f.cookie)){let v=jl(f.cookie);v&&(f.headers["set-cookie"]=v)}f.headers["set-cookie"]&&Array.isArray(f.headers["set-cookie"])&&(f.headers=ly(new Headers(f.headers),f.headers["set-cookie"]));let w=QA(l),E=$A(n),A;if(typeof r.beforeHandle=="function"){let v=r.beforeHandle(u);v instanceof Promise&&await v}let S=[...r.error?Array.isArray(r.error)?r.error:[r.error]:[],...(e.event.error??[]).map((v)=>typeof v=="function"?v:v.fn)].filter((v)=>v),k=S.length>0,U=k?async(v,L)=>{for(let F of S){let C=F(Object.assign(u,{error:L}));if(C instanceof Promise&&(C=await C),await w(v,C),C)break}}:()=>{};if(!d?.upgrade(u.request,{headers:Se(f.headers)?f.headers:void 0,data:{...u,get id(){return A||(A=Do())},validator:l,ping(v,L){r.ping?.(v,L)},pong(v,L){r.pong?.(v,L)},open:async(v)=>{try{await w(v,r.open?.(new cc(v,u)))}catch(L){U(v,L)}},message:async(v,L)=>{let F=await E(v,L);if(c&&c(F)){let C=new ne("message",a,F);return k?U(v,C):void v.send(C.message)}try{await w(v,r.message?.(new cc(v,u,F),F))}catch(C){U(v,C)}},drain:async(v)=>{try{await w(v,r.drain?.(new cc(v,u)))}catch(L){U(v,L)}},close:async(v,L,F)=>{try{await w(v,r.close?.(new cc(v,u),L,F))}catch(C){U(v,C)}}}}))return io(400,"Expected a websocket connection")},{...s,websocket:r})}};var _p=Yr?Bun.env:typeof process<"u"&&process?.env?process.env:{};var iE=/^(.+)\[(\d+)\]$/,rE=new Set(["__proto__","constructor","prototype"]),nE=(e)=>{if(rE.has(e))return!0;let t=e.match(iE);return t?rE.has(t[1]):!1},oE=(e)=>{let t=e.match(iE);return t?{name:t[1],index:parseInt(t[2],10)}:null},I9=(e)=>{if(!(typeof e!="string"||e.charCodeAt(0)!==123))try{let t=JSON.parse(e);if(t&&typeof t=="object"&&!Array.isArray(t))return t}catch{return}},ky=(e,t,r)=>{let n=t.split("."),o=n.pop();if(nE(o)||n.some(nE))return;let i=e;for(let a of n){let c=oE(a);if(c){Array.isArray(i[c.name])||(i[c.name]=[]);let l=i[c.name][c.index],u=typeof File<"u"&&l instanceof File;(!l||typeof l!="object"||Array.isArray(l)||u)&&(i[c.name][c.index]=I9(l)??{}),i=i[c.name][c.index]}else(!i[a]||typeof i[a]!="object")&&(i[a]={}),i=i[a]}let s=oE(o);s?(Array.isArray(i[s.name])||(i[s.name]=[]),i[s.name][s.index]=r):i[o]=r},Ty=(e)=>{if(e.length===1){let o=e[0];if(typeof o=="string"&&(o.charCodeAt(0)===123||o.charCodeAt(0)===91))try{let i=JSON.parse(o);if(i&&typeof i=="object")return i}catch{}return e[0]}let t=e.find((o)=>typeof o=="string");if(!t||typeof File>"u")return e;let r=e.filter((o)=>o instanceof File);if(!r.length||t.charCodeAt(0)!==123)return e;let n;try{n=JSON.parse(t)}catch{return e}return typeof n!="object"||n===null?e:(!("file"in n)&&r.length===1?n.file=r[0]:!("files"in n)&&r.length>1&&(n.files=r),n)},Ay=(e,t)=>{let r=e.schema;if(!r)return;r.$defs?.[r.$ref]&&(r=r.$defs[r.$ref]);let n=lo(r);if(n)for(let[o,i]of Object.entries(n))t[o]??=i.default};async function js(e,t,r){let n=await t.Validate(r);if(n.issues)throw new ne(e,t,r,!1,n.issues);return n.value}var Ey=(e)=>{let{mapResponse:t,mapEarlyResponse:r}=e["~adapter"].handler,n=e.setHeaders;return async(o)=>{let i=o.url,s=i.indexOf("/",11),a=i.indexOf("?",s+1),c=a===-1?i.substring(s):i.substring(s,a),l={cookie:{},status:200,headers:n?{...n}:{}},u=Object.assign({},e.singleton.decorator,{set:l,store:e.singleton.store,request:o,path:c,qi:a,error:io,status:io,redirect:ws}),d;try{if(e.event.request)for(let L=0;L<e.event.request.length;L++){let F=e.event.request[L].fn,C=F(u);if(C instanceof Promise&&(C=await C),C=r(C,l),C)return u.response=C}let f=o.method==="GET"&&o.headers.get("upgrade")?.toLowerCase()==="websocket"?"WS":o.method,p=e.router.dynamic.find(o.method,c)??e.router.dynamic.find(f,c)??e.router.dynamic.find("ALL",c);if(!p)throw u.query=a===-1?{}:Ti(i.substring(a+1)),new Ja;let{handle:g,validator:m,content:y,route:b}=p.store;if(d=p.store.hooks,d.config?.mount)return await d.config.mount(o);let w;if(o.method!=="GET"&&o.method!=="HEAD")if(y)switch(y){case"application/json":w=await o.json();break;case"text/plain":w=await o.text();break;case"application/x-www-form-urlencoded":w=Ti(await o.text());break;case"application/octet-stream":w=await o.arrayBuffer();break;case"multipart/form-data":{w={};let L=await o.formData(),F=new Map;L.forEach((C,D)=>{let N=F.get(D);N?N.push(C):F.set(D,[C])});for(let[C,D]of F){if(w[C])continue;let N=Ty(D);C.includes(".")||C.includes("[")?ky(w,C,N):w[C]=N}break}}else{let L;if(o.body&&(L=o.headers.get("content-type")),L){let F=L.indexOf(";");if(F!==-1&&(L=L.slice(0,F)),u.contentType=L,d.parse)for(let C=0;C<d.parse.length;C++){let D=d.parse[C].fn;if(typeof D=="string")switch(D){case"json":case"application/json":w=await o.json();break;case"text":case"text/plain":w=await o.text();break;case"urlencoded":case"application/x-www-form-urlencoded":w=Ti(await o.text());break;case"arrayBuffer":case"application/octet-stream":w=await o.arrayBuffer();break;case"formdata":case"multipart/form-data":{w={};let N=await o.formData(),z=new Map;N.forEach((X,re)=>{let Z=z.get(re);Z?Z.push(X):z.set(re,[X])});for(let[X,re]of z){if(w[X])continue;let Z=Ty(re);X.includes(".")||X.includes("[")?ky(w,X,Z):w[X]=Z}break}default:{let N=e["~parser"][D];if(N){let z=N(u,L);if(z instanceof Promise&&(z=await z),z){w=z;break}}break}}else{let N=D(u,L);if(N instanceof Promise&&(N=await N),N){w=N;break}}}if(delete u.contentType,w===void 0)switch(L){case"application/json":w=await o.json();break;case"text/plain":w=await o.text();break;case"application/x-www-form-urlencoded":w=Ti(await o.text());break;case"application/octet-stream":w=await o.arrayBuffer();break;case"multipart/form-data":{w={};let C=await o.formData(),D=new Map;C.forEach((N,z)=>{let X=D.get(z);X?X.push(N):D.set(z,[N])});for(let[N,z]of D){if(w[N])continue;let X=Ty(z);N.includes(".")||N.includes("[")?ky(w,N,X):w[N]=X}break}}}}u.route=b,u.body=w,u.params=p?.params||void 0,u.query=a===-1?{}:Ti(i.substring(a+1)),u.headers={};for(let[L,F]of o.headers.entries())u.headers[L]=F;let E={domain:e.config.cookie?.domain??m?.cookie?.config.domain,expires:e.config.cookie?.expires??m?.cookie?.config.expires,httpOnly:e.config.cookie?.httpOnly??m?.cookie?.config.httpOnly,maxAge:e.config.cookie?.maxAge??m?.cookie?.config.maxAge,path:e.config.cookie?.path??m?.cookie?.config.path,priority:e.config.cookie?.priority??m?.cookie?.config.priority,partitioned:e.config.cookie?.partitioned??m?.cookie?.config.partitioned,sameSite:e.config.cookie?.sameSite??m?.cookie?.config.sameSite,secure:e.config.cookie?.secure??m?.cookie?.config.secure,secrets:e.config.cookie?.secrets??m?.cookie?.config.secrets,sign:e.config.cookie?.sign??m?.cookie?.config.sign},A=o.headers.get("cookie");u.cookie=await Up(u.set,A,E);let S=m?.createHeaders?.();S&&Ay(S,u.headers);let k=m?.createParams?.();k&&Ay(k,u.params);let U=m?.createQuery?.();if(U&&Ay(U,u.query),d.transform)for(let L=0;L<d.transform.length;L++){let F=d.transform[L],C=F.fn(u);if(C instanceof Promise&&(C=await C),C instanceof ct){let D=r(C,u.set);if(D)return u.response=D}F.subType==="derive"&&Object.assign(u,C)}if(m){if(S){let F=structuredClone(u.headers);for(let[C,D]of o.headers)F[C]=D;if(S.provider==="standard")u.headers=await js("header",S,F);else if(m.headers.Check(F)===!1)throw new ne("header",m.headers,F)}else m.headers?.Decode&&(u.headers=m.headers.Decode(u.headers));if(k?.provider==="standard")u.params=await js("params",k,u.params);else{if(k?.Check(u.params)===!1)throw new ne("params",m.params,u.params);m.params?.Decode&&(u.params=m.params.Decode(u.params))}if(m.query?.schema){let F=m.query.schema;F.$defs?.[F.$ref]&&(F=F.$defs[F.$ref]);let C=lo(F);if(C)for(let D of Object.keys(C)){let N=C[D];(N.type==="array"||N.items?.type==="string")&&typeof u.query[D]=="string"&&u.query[D]&&(u.query[D]=u.query[D].split(","))}}if(U?.provider==="standard")u.query=await js("query",U,u.query);else{if(U?.Check(u.query)===!1)throw new ne("query",m.query,u.query);m.query?.Decode&&(u.query=m.query.Decode(u.query))}if(m.createCookie?.()){let F={};for(let[C,D]of Object.entries(u.cookie))F[C]=D.value;if(m.cookie.provider==="standard"){F=await js("cookie",m.cookie,F);for(let C of Object.keys(F))u.cookie[C].value=F[C]}else{if(m.cookie.Check(F)===!1)throw new ne("cookie",m.cookie,F);m.cookie?.Decode&&(F=m.cookie.Decode(F))}}let L=m.createBody?.();if(L?.provider==="standard")u.body=await js("body",L,w);else{if(L?.Check(w)===!1)throw new ne("body",m.body,w);if(m.body?.Decode){let F=m.body.Decode(w);F instanceof Promise&&(F=await F),u.body=F?.value??F}}}if(d.beforeHandle)for(let L=0;L<d.beforeHandle.length;L++){let F=d.beforeHandle[L],C=F.fn(u);if(C instanceof Promise&&(C=await C),C instanceof ct){let D=r(C,u.set);if(D)return u.response=D}if(F.subType==="resolve"){Object.assign(u,C);continue}if(C!==void 0){if(u.response=C,d.afterHandle)for(let N=0;N<d.afterHandle.length;N++){let z=d.afterHandle[N].fn(u);z instanceof Promise&&(z=await z),z&&(C=z)}let D=r(C,u.set);if(D)return u.response=D}}let v=typeof g=="function"?g(u):g;if(v instanceof Promise&&(v=await v),d.afterHandle?.length){u.response=v;for(let L=0;L<d.afterHandle.length;L++){let F=d.afterHandle[L].fn(u);F instanceof Promise&&(F=await F);let C=F instanceof ct,D=C?F.code:l.status?typeof l.status=="string"?oo[l.status]:l.status:200;C&&(l.status=D,F=F.response);let N=m?.createResponse?.()?.[D];if(N?.provider==="standard")F=await js("response",N,F);else if(N?.Check(F)===!1)if(N?.Clean)try{let X=N.Clean(F);if(N?.Check(X)===!1)throw new ne("response",N,F);F=X}catch(X){throw X instanceof ne?X:new ne("response",N,F)}else throw new ne("response",N,F);if(N?.Encode&&(u.response=F=N.Encode(F)),N?.Clean)try{u.response=F=N.Clean(F)}catch{}let z=r(F,u.set);if(z!==void 0)return u.response=z}}else{let L=v instanceof ct,F=L?v.code:l.status?typeof l.status=="string"?oo[l.status]:l.status:200;L&&(l.status=F,v=v.response);let C=m?.createResponse?.()?.[F];if(C?.provider==="standard")v=await js("response",C,v);else if(C?.Check(v)===!1)if(C?.Clean)try{let D=C.Clean(v);if(C?.Check(D)===!1)throw new ne("response",C,v);v=D}catch(D){throw D instanceof ne?D:new ne("response",C,v)}else throw new ne("response",C,v);if(C?.Encode&&(v=C.Encode(v)),C?.Clean)try{v=C.Clean(v)}catch{}}if(u.set.cookie&&E?.sign){let L=E.secrets?typeof E.secrets=="string"?E.secrets:E.secrets[0]:void 0;if(E.sign===!0){if(L)for(let[F,C]of Object.entries(u.set.cookie))u.set.cookie[F].value=await za(C.value,L)}else{let F=lo(m?.cookie?.schema);if(L)for(let C of E.sign)!F||!(C in F)||u.set.cookie[C]?.value&&(u.set.cookie[C].value=await za(u.set.cookie[C].value,L))}}return t(u.response=v,u.set)}catch(f){let p=f instanceof hs&&f.error?f.error:f;return e.handleError(u,p)}finally{let f=d?d.afterResponse:e.event.afterResponse;f&&(up?setImmediate(async()=>{for(let p of f)await p.fn(u)}):Promise.resolve().then(async()=>{for(let p of f)await p.fn(u)}))}}},sE=(e)=>{let{mapResponse:t}=e["~adapter"].handler;return async(r,n)=>{let o=Object.assign(r,{error:n,code:n.code});if(o.set=r.set,typeof n?.toResponse=="function"&&!(n instanceof ne)&&!(n instanceof hs))try{let i=n.toResponse();typeof i?.then=="function"&&(i=await i),i instanceof Response&&(r.set.status=i.status),r.response=i}catch{}if(!r.response&&e.event.error)for(let i=0;i<e.event.error.length;i++){let s=e.event.error[i].fn(o);if(s instanceof Promise&&(s=await s),s!=null)return r.response=t(s,r.set)}if(r.response){if(e.event.mapResponse)for(let i=0;i<e.event.mapResponse.length;i++){let s=e.event.mapResponse[i].fn(o);s instanceof Promise&&(s=await s),s!=null&&(r.response=s)}return t(r.response,r.set)}return r.set.status=n.status??500,t(typeof n.cause=="string"?n.cause:n.message,r.set)}};var aE;aE=Symbol.dispose;var R9=class e{constructor(t={}){this.server=null,this.dependencies={},this["~Prefix"]="",this["~Singleton"]=null,this["~Definitions"]=null,this["~Metadata"]=null,this["~Ephemeral"]=null,this["~Volatile"]=null,this["~Routes"]=null,this.singleton={decorator:{},store:{},derive:{},resolve:{}},this.definitions={typebox:V.Module({}),type:{},error:{}},this.extender={macro:{},higherOrderFunctions:[]},this.validator={global:null,scoped:null,local:null,getCandidate(){return!this.global&&!this.scoped&&!this.local?{body:void 0,headers:void 0,params:void 0,query:void 0,cookie:void 0,response:void 0}:Ka(Ka(this.global,this.scoped),this.local)}},this.standaloneValidator={global:null,scoped:null,local:null},this.event={},this.router={"~http":void 0,get http(){return this["~http"]||(this["~http"]=new Zi({lazy:!0,onParam:Iy.default})),this["~http"]},"~dynamic":void 0,get dynamic(){return this["~dynamic"]||(this["~dynamic"]=new Zi({onParam:Iy.default})),this["~dynamic"]},static:{},response:{},history:[]},this.routeTree={},this.inference={body:!1,cookie:!1,headers:!1,query:!1,set:!1,server:!1,path:!1,route:!1,url:!1},this["~parser"]={},this.handle=async(r)=>this.fetch(r),this.handleError=async(r,n)=>(this.handleError=this.config.aot?Sy(this):sE(this))(r,n),this.listen=(r,n)=>(this["~adapter"].listen(this)(r,n),this),this.stop=async(r)=>(await this["~adapter"].stop?.(this,r),this),this[aE]=()=>{this.server&&this.stop()},t.tags&&(t.detail?t.detail.tags=t.tags:t.detail={tags:t.tags}),this.config={aot:_p.ELYSIA_AOT!=="false",nativeStaticResponse:!0,encodeSchema:!0,normalize:!0,...t,prefix:t.prefix?t.prefix.charCodeAt(0)===47?t.prefix:`/${t.prefix}`:void 0,cookie:{path:"/",...t?.cookie},experimental:t?.experimental??{},seed:t?.seed===void 0?"":t?.seed},this["~adapter"]=t.adapter??(typeof Bun<"u"?tE:Wl),t?.analytic&&(t?.name||t?.seed!==void 0)&&(this.telemetry={stack:Error().stack})}get store(){return this.singleton.store}get decorator(){return this.singleton.decorator}get routes(){return this.router.history}getGlobalRoutes(){return this.router.history}getGlobalDefinitions(){return this.definitions}getServer(){return this.server}getParent(){return null}get promisedModules(){return this._promisedModules||(this._promisedModules=new Oh(console.error,()=>{})),this._promisedModules}env(t,r=_p){if(ut(t,{modules:this.definitions.typebox,dynamic:!0,additionalProperties:!0,coerce:!0,sanitize:()=>this.config.sanitize}).Check(r)===!1){let n=new ne("env",t,r);throw Error(n.all.map((o)=>o.summary).join(`
|
|
666
|
-
`))}return this}wrap(t){return this.extender.higherOrderFunctions.push({checksum:No(JSON.stringify({name:this.config.name,seed:this.config.seed,content:t.toString()})),fn:t}),this}get models(){let t={};for(let r of Object.keys(this.definitions.type))t[r]=ut(this.definitions.typebox.Import(r),{models:this.definitions.type});return t.modules=this.definitions.typebox,t}add(t,r,n,o,i){let s=i?.skipPrefix??!1,a=i?.allowMeta??!1;o??={},this.applyMacro(o);let c=[];if(o.standaloneValidator&&(c=c.concat(o.standaloneValidator)),this.standaloneValidator.local&&(c=c.concat(this.standaloneValidator.local)),this.standaloneValidator.scoped&&(c=c.concat(this.standaloneValidator.scoped)),this.standaloneValidator.global&&(c=c.concat(this.standaloneValidator.global)),r!==""&&r.charCodeAt(0)!==47&&(r="/"+r),this.config.prefix&&!s&&(r=this.config.prefix+r),o?.type)switch(o.type){case"text":o.type="text/plain";break;case"json":o.type="application/json";break;case"formdata":o.type="multipart/form-data";break;case"urlencoded":o.type="application/x-www-form-urlencoded";break;case"arrayBuffer":o.type="application/octet-stream";break;default:break}let l=this.validator.getCandidate(),u={body:o?.body??l?.body,headers:o?.headers??l?.headers,params:o?.params??l?.params,query:o?.query??l?.query,cookie:o?.cookie??l?.cookie,response:o?.response??l?.response},d=this.config.precompile===!0||typeof this.config.precompile=="object"&&this.config.precompile.compose===!0,f=()=>{let C=this.definitions.type,D=!this.config.aot,N=this.config.normalize,z=this.definitions.typebox,X=()=>this.config.sanitize,re=()=>{if(u.cookie||c.find((Z)=>Z.cookie))return KA({modules:z,validator:u.cookie,defaultConfig:this.config.cookie,normalize:N,config:u.cookie?.config??{},dynamic:D,models:C,validators:c.map((Z)=>Z.cookie),sanitize:X})};return d?{body:ut(u.body,{modules:z,dynamic:D,models:C,normalize:N,additionalCoerce:(()=>{let Z=by(u.body,C,z);return Z&&P in Z&&(Ht("File",Z)||Ht("Files",Z))?hy():Kl()})(),validators:c.map((Z)=>Z.body),sanitize:X}),headers:ut(u.headers,{modules:z,dynamic:D,models:C,additionalProperties:!0,coerce:!0,additionalCoerce:Ds(),validators:c.map((Z)=>Z.headers),sanitize:X}),params:ut(u.params,{modules:z,dynamic:D,models:C,coerce:!0,additionalCoerce:Ds(),validators:c.map((Z)=>Z.params),sanitize:X}),query:ut(u.query,{modules:z,dynamic:D,models:C,normalize:N,coerce:!0,additionalCoerce:gy(),validators:c.map((Z)=>Z.query),sanitize:X}),cookie:re(),response:Jp(u.response,{modules:z,dynamic:D,models:C,normalize:N,validators:c.map((Z)=>Z.response),sanitize:X})}:{createBody(){return this.body?this.body:this.body=ut(u.body,{modules:z,dynamic:D,models:C,normalize:N,additionalCoerce:(()=>{let Z=by(u.body,C,z);return Z&&P in Z&&(Ht("File",Z)||Ht("Files",Z))?hy():Kl()})(),validators:c.map((Z)=>Z.body),sanitize:X})},createHeaders(){return this.headers?this.headers:this.headers=ut(u.headers,{modules:z,dynamic:D,models:C,normalize:N,additionalProperties:!N,coerce:!0,additionalCoerce:Ds(),validators:c.map((Z)=>Z.headers),sanitize:X})},createParams(){return this.params?this.params:this.params=ut(u.params,{modules:z,dynamic:D,models:C,normalize:N,coerce:!0,additionalCoerce:Ds(),validators:c.map((Z)=>Z.params),sanitize:X})},createQuery(){return this.query?this.query:this.query=ut(u.query,{modules:z,dynamic:D,models:C,normalize:N,coerce:!0,additionalCoerce:gy(),validators:c.map((Z)=>Z.query),sanitize:X})},createCookie(){return this.cookie?this.cookie:this.cookie=re()},createResponse(){return this.response?this.response:this.response=Jp(u.response,{modules:z,dynamic:D,models:C,normalize:N,validators:c.map((Z)=>Z.response),sanitize:X})}}};(l.body||l.cookie||l.headers||l.params||l.query||l.response)&&(o=no(o,l)),o.tags&&(o.detail?o.detail.tags=o.tags:o.detail={tags:o.tags}),Se(this.config.detail)&&(o.detail=Ct(Object.assign({},this.config.detail),o.detail));let p=Se(this.event)?no(this.event,Mh(o)):{...Vk(Mh(o))};if(c.length&&Object.assign(p,{standaloneValidator:c}),this.config.aot===!1){let C=f();this.router.dynamic.add(t,r,{validator:C,hooks:p,content:o?.type,handle:n,route:r});let D=Ss(r,{dynamic:!0});if(r!==D&&this.router.dynamic.add(t,D,{validator:C,hooks:p,content:o?.type,handle:n,route:r}),!this.config.strictPath){let N=xs(r);this.router.dynamic.add(t,N,{validator:C,hooks:p,content:o?.type,handle:n,route:r});let z=Ss(N);N!==z&&this.router.dynamic.add(t,N,{validator:C,hooks:p,content:o?.type,handle:n,route:r})}this.router.history.push({method:t,path:r,composed:null,handler:n,compile:void 0,hooks:p});return}let g=this["~adapter"].handler,m=typeof n!="function"?()=>{let C=g.createNativeStaticHandler?.(n,p,{headers:Object.assign({},this.setHeaders)});return C instanceof Promise?C.then((D)=>{if(D)return D}):C?.()}:void 0,y=this.config.nativeStaticResponse===!0,b=(C)=>{!y||!m||(mp?this.router.response[C]?this.router.response[C][t]=m():this.router.response[C]={[t]:m()}:this.router.response[C]=m())};b(r);let w,E=()=>{if(w)return w;let C=GA({app:this,path:r,method:t,hooks:p,validator:f(),handler:typeof n!="function"&&typeof g.createStaticHandler!="function"?()=>n:n,allowMeta:a,inference:this.inference});return this.router.history[S]&&(w=this.router.history[S].composed=C),C},A;if(`${t}_${r}`in this.routeTree)for(let C=0;C<this.router.history.length;C++){let D=this.router.history[C];if(D.path===r&&D.method===t){A=C;break}}else this.routeTree[`${t}_${r}`]=this.router.history.length;let S=A??this.router.history.length,k=this.router.history,U=d?E():(C)=>w?w(C):(k[S].composed=E())(C);A!==void 0?this.router.history[A]=Object.assign({method:t,path:r,composed:U,compile:E,handler:n,hooks:p},c.length?{standaloneValidators:c}:void 0,o.webSocket?{websocket:o.websocket}:void 0):this.router.history.push(Object.assign({method:t,path:r,composed:U,compile:E,handler:n,hooks:p},o.webSocket?{websocket:o.websocket}:void 0));let v={handler:d?k[S].composed:void 0,compile(){return this.handler=E()}},L=this.router.static,F=r.indexOf(":")===-1&&r.indexOf("*")===-1;if(t==="WS"){if(F){r in L?L[r][t]=S:L[r]={[t]:S};return}this.router.http.add("WS",r,v),this.config.strictPath||this.router.http.add("WS",xs(r),v);let C=Ss(r,{dynamic:!0});r!==C&&this.router.http.add("WS",C,v);return}if(F)r in L?L[r][t]=S:L[r]={[t]:S},this.config.strictPath||b(xs(r));else{if(this.router.http.add(t,r,v),!this.config.strictPath){let D=xs(r);b(D),this.router.http.add(t,D,v)}let C=Ss(r,{dynamic:!0});r!==C&&(this.router.http.add(t,C,v),b(C))}}headers(t){return t?(this.setHeaders||(this.setHeaders={}),this.setHeaders=Ct(this.setHeaders,t),this):this}onStart(t){return this.on("start",t),this}onRequest(t){return this.on("request",t),this}onParse(t,r){return r?this.on(t,"parse",r):typeof t=="string"?this.on("parse",this["~parser"][t]):this.on("parse",t)}parser(t,r){return this["~parser"][t]=r,this}onTransform(t,r){return r?this.on(t,"transform",r):this.on("transform",t)}resolve(t,r){r||(r=t,t={as:"local"});let n={subType:"resolve",fn:r};return this.onBeforeHandle(t,n)}mapResolve(t,r){r||(r=t,t={as:"local"});let n={subType:"mapResolve",fn:r};return this.onBeforeHandle(t,n)}onBeforeHandle(t,r){return r?this.on(t,"beforeHandle",r):this.on("beforeHandle",t)}onAfterHandle(t,r){return r?this.on(t,"afterHandle",r):this.on("afterHandle",t)}mapResponse(t,r){return r?this.on(t,"mapResponse",r):this.on("mapResponse",t)}onAfterResponse(t,r){return r?this.on(t,"afterResponse",r):this.on("afterResponse",t)}trace(t,r){r||(r=t,t={as:"local"}),Array.isArray(r)||(r=[r]);for(let n of r)this.on(t,"trace",BA(n));return this}error(t,r){switch(typeof t){case"string":return r.prototype[vs]=t,this.definitions.error[t]=r,this;case"function":return this.definitions.error=t(this.definitions.error),this}for(let[n,o]of Object.entries(t))o.prototype[vs]=n,this.definitions.error[n]=o;return this}onError(t,r){return r?this.on(t,"error",r):this.on("error",t)}onStop(t){return this.on("stop",t),this}on(t,r,n){let o;switch(typeof t){case"string":o=t,n=r;break;case"object":o=r,!Array.isArray(r)&&typeof r=="object"&&(n=r);break}Array.isArray(n)?n=Rt(n):typeof n=="function"?n=[{fn:n}]:n=[n];let i=n;for(let s of i)s.scope=typeof t=="string"?"local":t?.as??"local",(o==="resolve"||o==="derive")&&(s.subType=o);o!=="trace"&&(this.inference=Ms({[o]:i.map((s)=>s.fn)},this.inference,this.config.sucrose));for(let s of i){let a=Kk(s,"global",{skipIfHasType:!0});switch((this.config.name||this.config.seed)&&(a.checksum=No(this.config.name+JSON.stringify(this.config.seed))),o){case"start":this.event.start??=[],this.event.start.push(a);break;case"request":this.event.request??=[],this.event.request.push(a);break;case"parse":this.event.parse??=[],this.event.parse.push(a);break;case"transform":this.event.transform??=[],this.event.transform.push(a);break;case"derive":this.event.transform??=[],this.event.transform.push(Rt(a,"derive"));break;case"beforeHandle":this.event.beforeHandle??=[],this.event.beforeHandle.push(a);break;case"resolve":this.event.beforeHandle??=[],this.event.beforeHandle.push(Rt(a,"resolve"));break;case"afterHandle":this.event.afterHandle??=[],this.event.afterHandle.push(a);break;case"mapResponse":this.event.mapResponse??=[],this.event.mapResponse.push(a);break;case"afterResponse":this.event.afterResponse??=[],this.event.afterResponse.push(a);break;case"trace":this.event.trace??=[],this.event.trace.push(a);break;case"error":this.event.error??=[],this.event.error.push(a);break;case"stop":this.event.stop??=[],this.event.stop.push(a);break}}return this}as(t){return Bo(this.event.parse,t),Bo(this.event.transform,t),Bo(this.event.beforeHandle,t),Bo(this.event.afterHandle,t),Bo(this.event.mapResponse,t),Bo(this.event.afterResponse,t),Bo(this.event.trace,t),Bo(this.event.error,t),t==="scoped"?(this.validator.scoped=Ka(this.validator.scoped,this.validator.local),this.validator.local=null,this.standaloneValidator.local!==null&&(this.standaloneValidator.scoped||=[],this.standaloneValidator.scoped.push(...this.standaloneValidator.local),this.standaloneValidator.local=null)):t==="global"&&(this.validator.global=Ka(this.validator.global,Ka(this.validator.scoped,this.validator.local)),this.validator.scoped=null,this.validator.local=null,this.standaloneValidator.local!==null&&(this.standaloneValidator.scoped||=[],this.standaloneValidator.scoped.push(...this.standaloneValidator.local),this.standaloneValidator.local=null),this.standaloneValidator.scoped!==null&&(this.standaloneValidator.global||=[],this.standaloneValidator.global.push(...this.standaloneValidator.scoped),this.standaloneValidator.scoped=null)),this}group(t,r,n){let o=new e({...this.config,prefix:""});o.singleton={...this.singleton},o.definitions={...this.definitions},o.getServer=()=>this.getServer(),o.inference=fp(this.inference),o.extender={...this.extender},o["~parser"]=this["~parser"],o.standaloneValidator={local:[...this.standaloneValidator.local??[]],scoped:[...this.standaloneValidator.scoped??[]],global:[...this.standaloneValidator.global??[]]};let i=typeof r=="object",s=(i?n:r)(o);return this.singleton=Ct(this.singleton,o.singleton),this.definitions=Ct(this.definitions,o.definitions),s.event.request?.length&&(this.event.request=[...this.event.request||[],...s.event.request||[]]),s.event.mapResponse?.length&&(this.event.mapResponse=[...this.event.mapResponse||[],...s.event.mapResponse||[]]),this.model(s.definitions.type),Object.values(o.router.history).forEach(({method:a,path:c,handler:l,hooks:u})=>{if(c=(i?"":this.config.prefix??"")+t+c,i){let{body:d,headers:f,query:p,params:g,cookie:m,response:y,...b}=r,w=u;this.applyMacro(b);let E=d||f||p||g||m||y;this.add(a,c,l,no(b,{...w||{},error:w.error?Array.isArray(w.error)?[...w.error??[],...s.event.error??[]]:[w.error,...s.event.error??[]]:s.event.error,standaloneValidator:b.standaloneValidator||w.standaloneValidator||E?[...b.standaloneValidator??[],...w.standaloneValidator??[],...E?[{body:d,headers:f,query:p,params:g,cookie:m,response:y}]:[]]:void 0}),void 0)}else this.add(a,c,l,no(u,{error:s.event.error}),{skipPrefix:!0})}),this}guard(t,r){if(!r){if(typeof t=="object"){this.applyMacro(t),t.detail&&(this.config.detail?this.config.detail=Ct(Object.assign({},this.config.detail),t.detail):this.config.detail=t.detail),t.tags&&(this.config.detail?this.config.detail.tags=t.tags:this.config.detail={tags:t.tags});let i=t.as??"local";if(t.schema==="standalone"){this.standaloneValidator[i]||(this.standaloneValidator[i]=[]);let s=t?.response?typeof t.response=="string"||P in t.response||"~standard"in t.response?{200:t.response}:t?.response:void 0;this.standaloneValidator[i].push({body:t.body,headers:t.headers,params:t.params,query:t.query,response:s,cookie:t.cookie})}else this.validator[i]={body:t.body??this.validator[i]?.body,headers:t.headers??this.validator[i]?.headers,params:t.params??this.validator[i]?.params,query:t.query??this.validator[i]?.query,response:t.response??this.validator[i]?.response,cookie:t.cookie??this.validator[i]?.cookie};return t.parse&&this.on({as:i},"parse",t.parse),t.transform&&this.on({as:i},"transform",t.transform),t.derive&&this.on({as:i},"derive",t.derive),t.beforeHandle&&this.on({as:i},"beforeHandle",t.beforeHandle),t.resolve&&this.on({as:i},"resolve",t.resolve),t.afterHandle&&this.on({as:i},"afterHandle",t.afterHandle),t.mapResponse&&this.on({as:i},"mapResponse",t.mapResponse),t.afterResponse&&this.on({as:i},"afterResponse",t.afterResponse),t.error&&this.on({as:i},"error",t.error),this}return this.guard({},t)}let n=new e({...this.config,prefix:""});n.singleton={...this.singleton},n.definitions={...this.definitions},n.inference=fp(this.inference),n.extender={...this.extender},n.getServer=()=>this.getServer();let o=r(n);if(this.singleton=Ct(this.singleton,n.singleton),this.definitions=Ct(this.definitions,n.definitions),o.getServer=()=>this.server,o.event.request?.length&&(this.event.request=[...this.event.request||[],...o.event.request||[]]),o.event.mapResponse?.length&&(this.event.mapResponse=[...this.event.mapResponse||[],...o.event.mapResponse||[]]),this.model(o.definitions.type),Object.values(n.router.history).forEach(({method:i,path:s,handler:a,hooks:c})=>{let{body:l,headers:u,query:d,params:f,cookie:p,response:g,...m}=t,y=l||u||d||f||p||g;this.add(i,s,a,no(m,{...c||{},error:c.error?Array.isArray(c.error)?[...c.error??[],...o.event.error??[]]:[c.error,...o.event.error??[]]:o.event.error,standaloneValidator:y?[...c.standaloneValidator??[],{body:l,headers:u,query:d,params:f,cookie:p,response:g}]:c.standaloneValidator}))}),n.promisedModules.size>0){let i=n.router.history.length;for(let s of n.promisedModules.promises)this.promisedModules.add(s.then(()=>{let{body:a,headers:c,query:l,params:u,cookie:d,response:f,...p}=t,g=a||c||l||u||d||f,m=i;i=n.router.history.length;for(let y=m;y<n.router.history.length;y++){let{method:b,path:w,handler:E,hooks:A}=n.router.history[y];this.add(b,w,E,no(p,{...A||{},error:A.error?Array.isArray(A.error)?[...A.error??[],...o.event.error??[]]:[A.error,...o.event.error??[]]:o.event.error,standaloneValidator:g?[...A.standaloneValidator??[],{body:a,headers:c,query:l,params:u,cookie:d,response:f}]:A.standaloneValidator}))}}))}return this}use(t){if(!t)return this;if(Array.isArray(t)){let r=this;for(let n of t)r=r.use(n);return r}return t instanceof Promise?(this.promisedModules.add(t.then((r)=>{if(typeof r=="function")return r(this);if(r instanceof e)return this._use(r).compile();if(r.constructor?.name==="Elysia")return this._use(r).compile();if(typeof r.default=="function")return r.default(this);if(r.default instanceof e)return this._use(r.default);if(r.constructor?.name==="Elysia")return this._use(r.default);if(r.constructor?.name==="_Elysia")return this._use(r.default);try{return this._use(r.default)}catch(n){throw console.error('Invalid plugin type. Expected Elysia instance, function, or module with "default" as Elysia instance or function that returns Elysia instance.'),n}}).then((r)=>(r&&typeof r.compile=="function"&&r.compile(),r))),this):this._use(t)}propagatePromiseModules(t){if(t.promisedModules.size<=0)return this;for(let r of t.promisedModules.promises)this.promisedModules.add(r.then((n)=>{if(!n)return;let o=this._use(n);return o instanceof Promise?o.then((i)=>{i?i.compile():n.compile()}):n.compile()}));return this}_use(t){if(typeof t=="function"){let o=t(this);return o instanceof Promise?(this.promisedModules.add(o.then((i)=>{if(i instanceof e){i.getServer=()=>this.getServer(),i.getGlobalRoutes=()=>this.getGlobalRoutes(),i.getGlobalDefinitions=()=>this.getGlobalDefinitions(),i.model(this.definitions.type),i.error(this.definitions.error);for(let{method:s,path:a,handler:c,hooks:l}of Object.values(i.router.history))this.add(s,a,c,l,void 0);return i===this?void 0:(this.propagatePromiseModules(i),i)}return typeof i=="function"?i(this):typeof i.default=="function"?i.default(this):this._use(i)}).then((i)=>(i&&typeof i.compile=="function"&&i.compile(),i))),this):o}this.propagatePromiseModules(t);let r=t.config.name,n=t.config.seed;if(t.getParent=()=>this,t.getServer=()=>this.getServer(),t.getGlobalRoutes=()=>this.getGlobalRoutes(),t.getGlobalDefinitions=()=>this.getGlobalDefinitions(),t.standaloneValidator?.scoped&&(this.standaloneValidator.local?this.standaloneValidator.local=this.standaloneValidator.local.concat(t.standaloneValidator.scoped):this.standaloneValidator.local=t.standaloneValidator.scoped),t.standaloneValidator?.global&&(this.standaloneValidator.global?this.standaloneValidator.global=this.standaloneValidator.global.concat(t.standaloneValidator.global):this.standaloneValidator.global=t.standaloneValidator.global),Se(t["~parser"])&&(this["~parser"]={...t["~parser"],...this["~parser"]}),t.setHeaders&&this.headers(t.setHeaders),r){r in this.dependencies||(this.dependencies[r]=[]);let o=n!==void 0?No(r+JSON.stringify(n)):0;this.dependencies[r].some(({checksum:i})=>o===i)||(this.extender.macro={...this.extender.macro,...t.extender.macro},this.extender.higherOrderFunctions=this.extender.higherOrderFunctions.concat(t.extender.higherOrderFunctions))}else Se(t.extender.macro)&&(this.extender.macro={...this.extender.macro,...t.extender.macro}),t.extender.higherOrderFunctions.length&&(this.extender.higherOrderFunctions=this.extender.higherOrderFunctions.concat(t.extender.higherOrderFunctions));if(t.extender.higherOrderFunctions.length){Lh(this.extender.higherOrderFunctions);let o=[];for(let i=0;i<this.extender.higherOrderFunctions.length;i++){let s=this.extender.higherOrderFunctions[i];s.checksum&&(o.includes(s.checksum)&&(this.extender.higherOrderFunctions.splice(i,1),i--),o.push(s.checksum))}o.length=0}this.inference=Dp(this.inference,t.inference),Se(t.singleton.decorator)&&this.decorate(t.singleton.decorator),Se(t.singleton.store)&&this.state(t.singleton.store),Se(t.definitions.type)&&this.model(t.definitions.type),Se(t.definitions.error)&&this.error(t.definitions.error),Se(t.extender.macro)&&(this.extender.macro={...this.extender.macro,...t.extender.macro});for(let{method:o,path:i,handler:s,hooks:a}of Object.values(t.router.history))this.add(o,i,s,a);if(r){r in this.dependencies||(this.dependencies[r]=[]);let o=n!==void 0?No(r+JSON.stringify(n)):0;if(this.dependencies[r].some(({checksum:i})=>o===i))return this;this.dependencies[r].push(this.config?.analytic?{name:t.config.name,seed:t.config.seed,checksum:o,dependencies:t.dependencies,stack:t.telemetry?.stack,routes:t.router.history,decorators:t.singleton,store:t.singleton.store,error:t.definitions.error,derive:t.event.transform?.filter((i)=>i?.subType==="derive").map((i)=>({fn:i.toString(),stack:Error().stack??""})),resolve:t.event.transform?.filter((i)=>i?.subType==="resolve").map((i)=>({fn:i.toString(),stack:Error().stack??""}))}:{name:t.config.name,seed:t.config.seed,checksum:o,dependencies:t.dependencies}),Se(t.event)&&(this.event=Rh(this.event,Ch(t.event),o))}else Se(t.event)&&(this.event=Rh(this.event,Ch(t.event)));return t.validator.global&&(this.validator.global=no(this.validator.global,{...t.validator.global})),t.validator.scoped&&(this.validator.local=no(this.validator.local,{...t.validator.scoped})),this}macro(t,r){if(typeof t=="string"&&!r)throw Error("Macro function is required");return typeof t=="string"?this.extender.macro[t]=r:this.extender.macro={...this.extender.macro,...t},this}applyMacro(t,r=t,{iteration:n=0,applied:o={}}={}){if(n>=16)return;let i=this.extender.macro;for(let[s,a]of Object.entries(r)){if(!(s in i))continue;let c=typeof i[s]=="function"?i[s](a):i[s];if(!c||typeof i[s]=="object"&&a===!1)return;let l=No(s+JSON.stringify(c.seed??a));if(!(l in o)){o[l]=!0;for(let[u,d]of Object.entries(c))if(u!=="seed"){if(u in Jk){zk(t,u,d),delete t[s];continue}if(u==="introspect"){d?.(t),delete t[s];continue}if(u==="detail"){t.detail||(t.detail={}),t.detail=Ct(t.detail,d,{mergeArray:!0}),delete t[s];continue}if(u in i){this.applyMacro(t,{[u]:d},{applied:o,iteration:n+1}),delete t[s];continue}switch((u==="derive"||u==="resolve")&&typeof d=="function"&&(d={fn:d,subType:u}),typeof t[u]){case"function":t[u]=[t[u],d];break;case"object":Array.isArray(t[u])?t[u].push(d):t[u]=[t[u],d];break;case"undefined":t[u]=d;break}delete t[s]}}}}mount(t,r,n){if(t instanceof e||typeof t=="function"||t.length===0||t==="/"){let a=typeof t=="function"?t:t instanceof e?t.compile().fetch:r instanceof e?r.compile().fetch:typeof r=="function"?r:(()=>{throw Error("Invalid handler")})(),c=({request:l,path:u})=>a(new Request(lp(l.url,u),l));return this.route("ALL","/*",c,{parse:"none",...n,detail:{...n?.detail,hide:!0},config:{mount:a}}),this}let o=r instanceof e?r.compile().fetch:typeof r=="function"?r:(()=>{throw Error("Invalid handler")})(),i=(typeof t=="string"&&this.config.prefix?this.config.prefix+t:t).length-(t.endsWith("*")?1:0),s=({request:a,path:c})=>o(new Request(lp(a.url,c.slice(i)||"/"),a));return this.route("ALL",t,s,{parse:"none",...n,detail:{...n?.detail,hide:!0},config:{mount:o}}),this.route("ALL",t+(t.endsWith("/")?"*":"/*"),s,{parse:"none",...n,detail:{...n?.detail,hide:!0},config:{mount:o}}),this}get(t,r,n){return this.add("GET",t,r,n),this}post(t,r,n){return this.add("POST",t,r,n),this}put(t,r,n){return this.add("PUT",t,r,n),this}patch(t,r,n){return this.add("PATCH",t,r,n),this}delete(t,r,n){return this.add("DELETE",t,r,n),this}options(t,r,n){return this.add("OPTIONS",t,r,n),this}all(t,r,n){return this.add("ALL",t,r,n),this}head(t,r,n){return this.add("HEAD",t,r,n),this}connect(t,r,n){return this.add("CONNECT",t,r,n),this}route(t,r,n,o){return this.add(t.toUpperCase(),r,n,o,o?.config),this}ws(t,r){return this["~adapter"].ws?this["~adapter"].ws(this,t,r):console.warn("Current adapter doesn't support WebSocket"),this}state(t,r,n){r===void 0?(n=t,t={as:"append"},r=""):n===void 0&&(typeof t=="string"?(n=r,r=t,t={as:"append"}):typeof t=="object"&&(n=r,r=""));let{as:o}=t;if(typeof r!="string")return this;switch(typeof n){case"object":return!n||!Se(n)?this:r?((r in this.singleton.store)?this.singleton.store[r]=Ct(this.singleton.store[r],n,{override:o==="override"}):this.singleton.store[r]=n,this):n===null?this:(this.singleton.store=Ct(this.singleton.store,n,{override:o==="override"}),this);case"function":return r?(o==="override"||!(r in this.singleton.store))&&(this.singleton.store[r]=n):this.singleton.store=n(this.singleton.store),this;default:return(o==="override"||!(r in this.singleton.store))&&(this.singleton.store[r]=n),this}}decorate(t,r,n){r===void 0?(n=t,t={as:"append"},r=""):n===void 0&&(typeof t=="string"?(n=r,r=t,t={as:"append"}):typeof t=="object"&&(n=r,r=""));let{as:o}=t;if(typeof r!="string")return this;switch(typeof n){case"object":return r?((r in this.singleton.decorator)?this.singleton.decorator[r]=Ct(this.singleton.decorator[r],n,{override:o==="override"}):this.singleton.decorator[r]=n,this):n===null?this:(this.singleton.decorator=Ct(this.singleton.decorator,n,{override:o==="override"}),this);case"function":return r?(o==="override"||!(r in this.singleton.decorator))&&(this.singleton.decorator[r]=n):this.singleton.decorator=n(this.singleton.decorator),this;default:return(o==="override"||!(r in this.singleton.decorator))&&(this.singleton.decorator[r]=n),this}}derive(t,r){r||(r=t,t={as:"local"});let n={subType:"derive",fn:r};return this.onTransform(t,n)}model(t,r){let n=(o)=>{let i={};for(let s in o)"~standard"in o[s]||(i[s]=o[s]);return i};switch(typeof t){case"object":let o={},i=Object.entries(t);if(!i.length)return this;for(let[c,l]of i)c in this.definitions.type||("~standard"in l?this.definitions.type[c]=l:(o[c]=this.definitions.type[c]=l,o[c].$id??=`#/components/schemas/${c}`));return this.definitions.typebox=V.Module({...this.definitions.typebox.$defs,...o}),this;case"function":let s=t(this.definitions.type);return this.definitions.type=s,this.definitions.typebox=V.Module(n(s)),this;case"string":if(!r)break;if(this.definitions.type[t]=r,"~standard"in r)return this;let a={...r,id:r.$id??`#/components/schemas/${t}`};return this.definitions.typebox=V.Module({...this.definitions.typebox.$defs,...a}),this}return r?(this.definitions.type[t]=r,("~standard"in r)?this:(this.definitions.typebox=V.Module({...this.definitions.typebox.$defs,[t]:r}),this)):this}Ref(t){return V.Ref(t)}mapDerive(t,r){r||(r=t,t={as:"local"});let n={subType:"mapDerive",fn:r};return this.onTransform(t,n)}affix(t,r,n){if(n==="")return this;let o=["_","-"," "],i=(l)=>l[0].toUpperCase()+l.slice(1),s=t==="prefix"?(l,u)=>o.includes(l.at(-1)??"")?l+u:l+i(u):o.includes(n.at(-1)??"")?(l,u)=>u+l:(l,u)=>u+i(l),a=(l)=>{let u={};switch(l){case"decorator":for(let d in this.singleton.decorator)u[s(n,d)]=this.singleton.decorator[d];this.singleton.decorator=u;break;case"state":for(let d in this.singleton.store)u[s(n,d)]=this.singleton.store[d];this.singleton.store=u;break;case"model":for(let d in this.definitions.type)u[s(n,d)]=this.definitions.type[d];this.definitions.type=u;break;case"error":for(let d in this.definitions.error)u[s(n,d)]=this.definitions.error[d];this.definitions.error=u;break}},c=Array.isArray(r)?r:[r];for(let l of c.some((u)=>u==="all")?["decorator","state","model","error"]:c)a(l);return this}prefix(t,r){return this.affix("prefix",t,r)}suffix(t,r){return this.affix("suffix",t,r)}compile(){return this["~adapter"].beforeCompile?.(this),this["~adapter"].isWebStandard?(this._handle=this.config.aot?Qp(this):Ey(this),Object.defineProperty(this,"fetch",{value:this._handle,configurable:!0,writable:!0}),typeof this.server?.reload=="function"&&this.server.reload({...this.server||{},fetch:this.fetch}),this):(typeof this.server?.reload=="function"&&this.server.reload(this.server||{}),this._handle=Qp(this),this)}get fetch(){let t=this.config.aot?Qp(this):Ey(this);return Object.defineProperty(this,"fetch",{value:t,configurable:!0,writable:!0}),t}get modules(){return this.promisedModules}},un=R9;var ef={name:"ompchamber",version:"3.3.0",description:"Developer web console and diagnostic chamber for AI Oh-My-Pi \u2014 Elysia + Preact on Bun.",license:"UNLICENSED",author:"Wijanarko Putra Rajeb <wijanarko.rajeb@gmail.com>",type:"module",engines:{bun:">=1.4.0"},bin:{ompchamber:"./src/cli/ompchamber.js"},repository:{type:"git",url:"git+https://github.com/rajebdev/ompchamber.git"},homepage:"https://github.com/rajebdev/ompchamber#readme",bugs:{url:"https://github.com/rajebdev/ompchamber/issues"},keywords:["omp","oh-my-pi","agent","console","elysia","preact","bun"],files:["src","index.html","bunfig.toml","public","tsconfig.json","dist/client"],scripts:{dev:"bun run --hot src/server/index.ts --ompchamber-server","dev:lan":"HOST=0.0.0.0 bun run --hot src/server/index.ts --ompchamber-server",build:"bun run scripts/build-client.ts",start:"NODE_ENV=production bun run src/server/index.ts --ompchamber-server",typecheck:"tsc",clean:"rm -rf dist",lint:"tsc --noEmit",test:"bun test"},dependencies:{"@fontsource/fira-code":"^5.3.0","@shikijs/langs":"^4.4.3","@shikijs/themes":"^4.4.3","@tailwindcss/postcss":"^4.1.14","@xterm/addon-fit":"^0.11.0","@xterm/addon-webgl":"^0.19.0","@xterm/xterm":"^6.0.0",dompurify:"^3.4.15",elysia:"^1.4.30",katex:"^0.18.7","lucide-preact":"^1.47.0",marked:"^18.0.11","marked-linkify-it":"^4.0.2",mermaid:"^12.0.0",postcss:"^8.5.16",preact:"^10.29.8",remend:"^1.3.1",ripgrep:"^0.3.1",shiki:"^4.4.3",tailwindcss:"^4.1.14",yaml:"^2.9.1"},devDependencies:{"@semantic-release/changelog":"^7.0.0","@semantic-release/commit-analyzer":"^13.0.1","@semantic-release/git":"^11.0.1","@semantic-release/github":"^12.0.10","@semantic-release/npm":"^13.2.0","@semantic-release/release-notes-generator":"^14.1.1","@types/bun":"^1.4.2","@types/node":"^22.14.0","conventional-changelog-conventionalcommits":"^9.3.1","happy-dom":"^20.14.5","semantic-release":"^25.0.9",typescript:"~5.8.2"}};var cE=ES("{\"index\":\"./dist/client/index.html\",\"files\":[{\"input\":\"../../index.html\",\"path\":\"./dist/client/static/js/index-qkt4z7x0.js\",\"loader\":\"js\",\"isEntry\":true,\"headers\":{\"etag\":\"95N6BB-nfWA\",\"content-type\":\"text/javascript;charset=utf-8\"}},{\"input\":\"../../index.html\",\"path\":\"./dist/client/index.html\",\"loader\":\"html\",\"isEntry\":true,\"headers\":{\"etag\":\"LPfrYeN1cx8\",\"content-type\":\"text/html;charset=utf-8\"}},{\"input\":\"../../index.html\",\"path\":\"./dist/client/static/js/index-bsxxt89j.css\",\"loader\":\"css\",\"isEntry\":true,\"headers\":{\"etag\":\"S5m9nZrIyXI\",\"content-type\":\"text/css;charset=utf-8\"}},{\"input\":\"../../public/manifest.webmanifest\",\"path\":\"./dist/client/static/manifest-bnyy75kt.webmanifest\",\"loader\":\"file\",\"isEntry\":false,\"headers\":{\"etag\":\"CxU-Pqfls5o\",\"content-type\":\"application/manifest+json\"}},{\"input\":\"../../public/icon.svg\",\"path\":\"./dist/client/static/icon-d07z9dtz.svg\",\"loader\":\"file\",\"isEntry\":false,\"headers\":{\"etag\":\"baDnH-kt2p8\",\"content-type\":\"image/svg+xml\"}},{\"input\":\"../../public/icon-192x192.png\",\"path\":\"./dist/client/static/icon-192x192-6gn5cr2f.png\",\"loader\":\"file\",\"isEntry\":false,\"headers\":{\"etag\":\"JtAVBew4Ag8\",\"content-type\":\"image/png\"}},{\"input\":\"../../public/apple-touch-icon.png\",\"path\":\"./dist/client/static/apple-touch-icon-dskx5sr3.png\",\"loader\":\"file\",\"isEntry\":false,\"headers\":{\"etag\":\"TTkT3WVZWKM\",\"content-type\":\"image/png\"}}]}");function h(e,t={}){let r=new Headers(t.headers);if(!r.has("content-type"))r.set("content-type","application/json; charset=utf-8");return new Response(JSON.stringify(e),{status:t.status??200,headers:r})}var dn={"cache-control":"no-store"};import{brotliCompressSync as O9,constants as M9}from"zlib";var F9=1024,N9=/^(text\/|application\/(json|javascript|xml|wasm|svg))/,L9=["zstd","br","gzip"];function D9(e){for(let t of L9)if(e.includes(t))return t;return null}function B9(e,t){if(t==="zstd")return Bun.zstdCompressSync(e,{level:3});if(t==="br")return O9(e,{params:{[M9.BROTLI_PARAM_QUALITY]:4}});return Bun.gzipSync(e,{level:6})}async function tf(e,t){if(!t)return e;let r=e.headers.get("content-type")??"";if(r.includes("text/event-stream"))return e;if(!N9.test(r))return e;if(e.status===204||e.status===304)return e;let n=D9(t);if(!n)return e;let o=new Uint8Array(await e.arrayBuffer());if(o.byteLength<F9)return j9(e,o);let i=B9(o,n),s=new Headers(e.headers);return s.set("content-encoding",n),s.set("content-length",String(i.byteLength)),s.append("vary","accept-encoding"),new Response(i,{status:e.status,headers:s})}function j9(e,t){return new Response(t,{status:e.status,headers:e.headers})}function Q(e,t,r={}){let n=[];if(e.loader)n.push({method:"GET",path:t,handler:e.loader});else if(e.action)n.push({method:"GET",path:t,handler:ee});if(e.action)for(let o of r.mutating??["POST","PUT","PATCH","DELETE"])n.push({method:o,path:t,handler:e.action});return n}var ee=()=>new Response(JSON.stringify({error:"Method not allowed"}),{status:405,headers:{"content-type":"application/json; charset=utf-8"}});function Us(e,t){let r=e[t];return r?r:null}function qs(e,t=500){return h({error:e instanceof Error?e.message:String(e)},{status:t})}async function U9(e){if(e instanceof Response)return e;if(e instanceof ReadableStream)return new Response(e,{headers:{"content-type":"text/event-stream","cache-control":"no-cache"}});return new Response(JSON.stringify(e??null),{status:200,headers:{"content-type":"application/json; charset=utf-8"}})}function q9(e){return async({request:t,params:r})=>{try{let n=await U9(await e({request:t,params:r}));return await tf(n,t.headers.get("accept-encoding"))}catch(n){let o=n instanceof Error?n.message:String(n);return new Response(JSON.stringify({error:o}),{status:500,headers:{"content-type":"application/json; charset=utf-8"}})}}}function lE(e,t){let r=e;for(let{method:n,path:o,handler:i}of t){let s=q9(i);if(n==="GET")r=r.get(o,s);else if(n==="POST")r=r.post(o,s);else if(n==="PUT")r=r.put(o,s);else if(n==="PATCH")r=r.patch(o,s);else r=r.delete(o,s)}return r}function Yt(e,t,r){return[{method:"GET",path:t,handler:r??ee},...["POST","PUT","PATCH","DELETE"].map((n)=>({method:n,path:t,handler:e}))]}import{existsSync as W9,realpathSync as H9}from"fs";import{homedir as V9,tmpdir as Gke}from"os";import*as pn from"path";var K9="omp",z9=".omp";function G9(){return Bun.env.PI_CONFIG_DIR||z9}function lc(){return pn.join(V9(),G9())}function Oe(){let e=Bun.env.PI_CODING_AGENT_DIR;if(e)return pn.resolve(e);return pn.join(lc(),"agent")}function J9(){let e=Bun.env.PI_CODING_AGENT_DIR;if(e)return pn.resolve(e)===pn.join(lc(),"agent");return!0}function Y9(){if(process.platform!=="linux"&&process.platform!=="darwin")return;if(!J9())return;let e=Bun.env.XDG_DATA_HOME;if(!e)return;try{let t=pn.join(e,K9);return W9(t)?t:void 0}catch{return}}function $9(e){let t=Y9();return pn.join(t??Oe(),e)}function uo(){return $9("sessions")}function uE(){return pn.join(Oe(),"projects.json")}function rf(e){try{return H9.native(e)}catch{return e}}async function Be(e){try{return await Bun.file(e).stat(),!0}catch{return!1}}function Ii(e){let t=rf(e);return t.replace(/\/+$/,"")||t}import Cy from"fs";import*as nf from"path";function I(e){return typeof e==="object"&&e!==null&&!Array.isArray(e)}function $t(e){let t=[];for(let r of e.split(`
|
|
666
|
+
`))}return this}wrap(t){return this.extender.higherOrderFunctions.push({checksum:No(JSON.stringify({name:this.config.name,seed:this.config.seed,content:t.toString()})),fn:t}),this}get models(){let t={};for(let r of Object.keys(this.definitions.type))t[r]=ut(this.definitions.typebox.Import(r),{models:this.definitions.type});return t.modules=this.definitions.typebox,t}add(t,r,n,o,i){let s=i?.skipPrefix??!1,a=i?.allowMeta??!1;o??={},this.applyMacro(o);let c=[];if(o.standaloneValidator&&(c=c.concat(o.standaloneValidator)),this.standaloneValidator.local&&(c=c.concat(this.standaloneValidator.local)),this.standaloneValidator.scoped&&(c=c.concat(this.standaloneValidator.scoped)),this.standaloneValidator.global&&(c=c.concat(this.standaloneValidator.global)),r!==""&&r.charCodeAt(0)!==47&&(r="/"+r),this.config.prefix&&!s&&(r=this.config.prefix+r),o?.type)switch(o.type){case"text":o.type="text/plain";break;case"json":o.type="application/json";break;case"formdata":o.type="multipart/form-data";break;case"urlencoded":o.type="application/x-www-form-urlencoded";break;case"arrayBuffer":o.type="application/octet-stream";break;default:break}let l=this.validator.getCandidate(),u={body:o?.body??l?.body,headers:o?.headers??l?.headers,params:o?.params??l?.params,query:o?.query??l?.query,cookie:o?.cookie??l?.cookie,response:o?.response??l?.response},d=this.config.precompile===!0||typeof this.config.precompile=="object"&&this.config.precompile.compose===!0,f=()=>{let C=this.definitions.type,D=!this.config.aot,N=this.config.normalize,z=this.definitions.typebox,X=()=>this.config.sanitize,re=()=>{if(u.cookie||c.find((Z)=>Z.cookie))return KA({modules:z,validator:u.cookie,defaultConfig:this.config.cookie,normalize:N,config:u.cookie?.config??{},dynamic:D,models:C,validators:c.map((Z)=>Z.cookie),sanitize:X})};return d?{body:ut(u.body,{modules:z,dynamic:D,models:C,normalize:N,additionalCoerce:(()=>{let Z=by(u.body,C,z);return Z&&P in Z&&(Ht("File",Z)||Ht("Files",Z))?hy():Kl()})(),validators:c.map((Z)=>Z.body),sanitize:X}),headers:ut(u.headers,{modules:z,dynamic:D,models:C,additionalProperties:!0,coerce:!0,additionalCoerce:Ds(),validators:c.map((Z)=>Z.headers),sanitize:X}),params:ut(u.params,{modules:z,dynamic:D,models:C,coerce:!0,additionalCoerce:Ds(),validators:c.map((Z)=>Z.params),sanitize:X}),query:ut(u.query,{modules:z,dynamic:D,models:C,normalize:N,coerce:!0,additionalCoerce:gy(),validators:c.map((Z)=>Z.query),sanitize:X}),cookie:re(),response:Jp(u.response,{modules:z,dynamic:D,models:C,normalize:N,validators:c.map((Z)=>Z.response),sanitize:X})}:{createBody(){return this.body?this.body:this.body=ut(u.body,{modules:z,dynamic:D,models:C,normalize:N,additionalCoerce:(()=>{let Z=by(u.body,C,z);return Z&&P in Z&&(Ht("File",Z)||Ht("Files",Z))?hy():Kl()})(),validators:c.map((Z)=>Z.body),sanitize:X})},createHeaders(){return this.headers?this.headers:this.headers=ut(u.headers,{modules:z,dynamic:D,models:C,normalize:N,additionalProperties:!N,coerce:!0,additionalCoerce:Ds(),validators:c.map((Z)=>Z.headers),sanitize:X})},createParams(){return this.params?this.params:this.params=ut(u.params,{modules:z,dynamic:D,models:C,normalize:N,coerce:!0,additionalCoerce:Ds(),validators:c.map((Z)=>Z.params),sanitize:X})},createQuery(){return this.query?this.query:this.query=ut(u.query,{modules:z,dynamic:D,models:C,normalize:N,coerce:!0,additionalCoerce:gy(),validators:c.map((Z)=>Z.query),sanitize:X})},createCookie(){return this.cookie?this.cookie:this.cookie=re()},createResponse(){return this.response?this.response:this.response=Jp(u.response,{modules:z,dynamic:D,models:C,normalize:N,validators:c.map((Z)=>Z.response),sanitize:X})}}};(l.body||l.cookie||l.headers||l.params||l.query||l.response)&&(o=no(o,l)),o.tags&&(o.detail?o.detail.tags=o.tags:o.detail={tags:o.tags}),Se(this.config.detail)&&(o.detail=Ct(Object.assign({},this.config.detail),o.detail));let p=Se(this.event)?no(this.event,Mh(o)):{...Vk(Mh(o))};if(c.length&&Object.assign(p,{standaloneValidator:c}),this.config.aot===!1){let C=f();this.router.dynamic.add(t,r,{validator:C,hooks:p,content:o?.type,handle:n,route:r});let D=Ss(r,{dynamic:!0});if(r!==D&&this.router.dynamic.add(t,D,{validator:C,hooks:p,content:o?.type,handle:n,route:r}),!this.config.strictPath){let N=xs(r);this.router.dynamic.add(t,N,{validator:C,hooks:p,content:o?.type,handle:n,route:r});let z=Ss(N);N!==z&&this.router.dynamic.add(t,N,{validator:C,hooks:p,content:o?.type,handle:n,route:r})}this.router.history.push({method:t,path:r,composed:null,handler:n,compile:void 0,hooks:p});return}let g=this["~adapter"].handler,m=typeof n!="function"?()=>{let C=g.createNativeStaticHandler?.(n,p,{headers:Object.assign({},this.setHeaders)});return C instanceof Promise?C.then((D)=>{if(D)return D}):C?.()}:void 0,y=this.config.nativeStaticResponse===!0,b=(C)=>{!y||!m||(mp?this.router.response[C]?this.router.response[C][t]=m():this.router.response[C]={[t]:m()}:this.router.response[C]=m())};b(r);let w,E=()=>{if(w)return w;let C=GA({app:this,path:r,method:t,hooks:p,validator:f(),handler:typeof n!="function"&&typeof g.createStaticHandler!="function"?()=>n:n,allowMeta:a,inference:this.inference});return this.router.history[S]&&(w=this.router.history[S].composed=C),C},A;if(`${t}_${r}`in this.routeTree)for(let C=0;C<this.router.history.length;C++){let D=this.router.history[C];if(D.path===r&&D.method===t){A=C;break}}else this.routeTree[`${t}_${r}`]=this.router.history.length;let S=A??this.router.history.length,k=this.router.history,U=d?E():(C)=>w?w(C):(k[S].composed=E())(C);A!==void 0?this.router.history[A]=Object.assign({method:t,path:r,composed:U,compile:E,handler:n,hooks:p},c.length?{standaloneValidators:c}:void 0,o.webSocket?{websocket:o.websocket}:void 0):this.router.history.push(Object.assign({method:t,path:r,composed:U,compile:E,handler:n,hooks:p},o.webSocket?{websocket:o.websocket}:void 0));let v={handler:d?k[S].composed:void 0,compile(){return this.handler=E()}},L=this.router.static,F=r.indexOf(":")===-1&&r.indexOf("*")===-1;if(t==="WS"){if(F){r in L?L[r][t]=S:L[r]={[t]:S};return}this.router.http.add("WS",r,v),this.config.strictPath||this.router.http.add("WS",xs(r),v);let C=Ss(r,{dynamic:!0});r!==C&&this.router.http.add("WS",C,v);return}if(F)r in L?L[r][t]=S:L[r]={[t]:S},this.config.strictPath||b(xs(r));else{if(this.router.http.add(t,r,v),!this.config.strictPath){let D=xs(r);b(D),this.router.http.add(t,D,v)}let C=Ss(r,{dynamic:!0});r!==C&&(this.router.http.add(t,C,v),b(C))}}headers(t){return t?(this.setHeaders||(this.setHeaders={}),this.setHeaders=Ct(this.setHeaders,t),this):this}onStart(t){return this.on("start",t),this}onRequest(t){return this.on("request",t),this}onParse(t,r){return r?this.on(t,"parse",r):typeof t=="string"?this.on("parse",this["~parser"][t]):this.on("parse",t)}parser(t,r){return this["~parser"][t]=r,this}onTransform(t,r){return r?this.on(t,"transform",r):this.on("transform",t)}resolve(t,r){r||(r=t,t={as:"local"});let n={subType:"resolve",fn:r};return this.onBeforeHandle(t,n)}mapResolve(t,r){r||(r=t,t={as:"local"});let n={subType:"mapResolve",fn:r};return this.onBeforeHandle(t,n)}onBeforeHandle(t,r){return r?this.on(t,"beforeHandle",r):this.on("beforeHandle",t)}onAfterHandle(t,r){return r?this.on(t,"afterHandle",r):this.on("afterHandle",t)}mapResponse(t,r){return r?this.on(t,"mapResponse",r):this.on("mapResponse",t)}onAfterResponse(t,r){return r?this.on(t,"afterResponse",r):this.on("afterResponse",t)}trace(t,r){r||(r=t,t={as:"local"}),Array.isArray(r)||(r=[r]);for(let n of r)this.on(t,"trace",BA(n));return this}error(t,r){switch(typeof t){case"string":return r.prototype[vs]=t,this.definitions.error[t]=r,this;case"function":return this.definitions.error=t(this.definitions.error),this}for(let[n,o]of Object.entries(t))o.prototype[vs]=n,this.definitions.error[n]=o;return this}onError(t,r){return r?this.on(t,"error",r):this.on("error",t)}onStop(t){return this.on("stop",t),this}on(t,r,n){let o;switch(typeof t){case"string":o=t,n=r;break;case"object":o=r,!Array.isArray(r)&&typeof r=="object"&&(n=r);break}Array.isArray(n)?n=Rt(n):typeof n=="function"?n=[{fn:n}]:n=[n];let i=n;for(let s of i)s.scope=typeof t=="string"?"local":t?.as??"local",(o==="resolve"||o==="derive")&&(s.subType=o);o!=="trace"&&(this.inference=Ms({[o]:i.map((s)=>s.fn)},this.inference,this.config.sucrose));for(let s of i){let a=Kk(s,"global",{skipIfHasType:!0});switch((this.config.name||this.config.seed)&&(a.checksum=No(this.config.name+JSON.stringify(this.config.seed))),o){case"start":this.event.start??=[],this.event.start.push(a);break;case"request":this.event.request??=[],this.event.request.push(a);break;case"parse":this.event.parse??=[],this.event.parse.push(a);break;case"transform":this.event.transform??=[],this.event.transform.push(a);break;case"derive":this.event.transform??=[],this.event.transform.push(Rt(a,"derive"));break;case"beforeHandle":this.event.beforeHandle??=[],this.event.beforeHandle.push(a);break;case"resolve":this.event.beforeHandle??=[],this.event.beforeHandle.push(Rt(a,"resolve"));break;case"afterHandle":this.event.afterHandle??=[],this.event.afterHandle.push(a);break;case"mapResponse":this.event.mapResponse??=[],this.event.mapResponse.push(a);break;case"afterResponse":this.event.afterResponse??=[],this.event.afterResponse.push(a);break;case"trace":this.event.trace??=[],this.event.trace.push(a);break;case"error":this.event.error??=[],this.event.error.push(a);break;case"stop":this.event.stop??=[],this.event.stop.push(a);break}}return this}as(t){return Bo(this.event.parse,t),Bo(this.event.transform,t),Bo(this.event.beforeHandle,t),Bo(this.event.afterHandle,t),Bo(this.event.mapResponse,t),Bo(this.event.afterResponse,t),Bo(this.event.trace,t),Bo(this.event.error,t),t==="scoped"?(this.validator.scoped=Ka(this.validator.scoped,this.validator.local),this.validator.local=null,this.standaloneValidator.local!==null&&(this.standaloneValidator.scoped||=[],this.standaloneValidator.scoped.push(...this.standaloneValidator.local),this.standaloneValidator.local=null)):t==="global"&&(this.validator.global=Ka(this.validator.global,Ka(this.validator.scoped,this.validator.local)),this.validator.scoped=null,this.validator.local=null,this.standaloneValidator.local!==null&&(this.standaloneValidator.scoped||=[],this.standaloneValidator.scoped.push(...this.standaloneValidator.local),this.standaloneValidator.local=null),this.standaloneValidator.scoped!==null&&(this.standaloneValidator.global||=[],this.standaloneValidator.global.push(...this.standaloneValidator.scoped),this.standaloneValidator.scoped=null)),this}group(t,r,n){let o=new e({...this.config,prefix:""});o.singleton={...this.singleton},o.definitions={...this.definitions},o.getServer=()=>this.getServer(),o.inference=fp(this.inference),o.extender={...this.extender},o["~parser"]=this["~parser"],o.standaloneValidator={local:[...this.standaloneValidator.local??[]],scoped:[...this.standaloneValidator.scoped??[]],global:[...this.standaloneValidator.global??[]]};let i=typeof r=="object",s=(i?n:r)(o);return this.singleton=Ct(this.singleton,o.singleton),this.definitions=Ct(this.definitions,o.definitions),s.event.request?.length&&(this.event.request=[...this.event.request||[],...s.event.request||[]]),s.event.mapResponse?.length&&(this.event.mapResponse=[...this.event.mapResponse||[],...s.event.mapResponse||[]]),this.model(s.definitions.type),Object.values(o.router.history).forEach(({method:a,path:c,handler:l,hooks:u})=>{if(c=(i?"":this.config.prefix??"")+t+c,i){let{body:d,headers:f,query:p,params:g,cookie:m,response:y,...b}=r,w=u;this.applyMacro(b);let E=d||f||p||g||m||y;this.add(a,c,l,no(b,{...w||{},error:w.error?Array.isArray(w.error)?[...w.error??[],...s.event.error??[]]:[w.error,...s.event.error??[]]:s.event.error,standaloneValidator:b.standaloneValidator||w.standaloneValidator||E?[...b.standaloneValidator??[],...w.standaloneValidator??[],...E?[{body:d,headers:f,query:p,params:g,cookie:m,response:y}]:[]]:void 0}),void 0)}else this.add(a,c,l,no(u,{error:s.event.error}),{skipPrefix:!0})}),this}guard(t,r){if(!r){if(typeof t=="object"){this.applyMacro(t),t.detail&&(this.config.detail?this.config.detail=Ct(Object.assign({},this.config.detail),t.detail):this.config.detail=t.detail),t.tags&&(this.config.detail?this.config.detail.tags=t.tags:this.config.detail={tags:t.tags});let i=t.as??"local";if(t.schema==="standalone"){this.standaloneValidator[i]||(this.standaloneValidator[i]=[]);let s=t?.response?typeof t.response=="string"||P in t.response||"~standard"in t.response?{200:t.response}:t?.response:void 0;this.standaloneValidator[i].push({body:t.body,headers:t.headers,params:t.params,query:t.query,response:s,cookie:t.cookie})}else this.validator[i]={body:t.body??this.validator[i]?.body,headers:t.headers??this.validator[i]?.headers,params:t.params??this.validator[i]?.params,query:t.query??this.validator[i]?.query,response:t.response??this.validator[i]?.response,cookie:t.cookie??this.validator[i]?.cookie};return t.parse&&this.on({as:i},"parse",t.parse),t.transform&&this.on({as:i},"transform",t.transform),t.derive&&this.on({as:i},"derive",t.derive),t.beforeHandle&&this.on({as:i},"beforeHandle",t.beforeHandle),t.resolve&&this.on({as:i},"resolve",t.resolve),t.afterHandle&&this.on({as:i},"afterHandle",t.afterHandle),t.mapResponse&&this.on({as:i},"mapResponse",t.mapResponse),t.afterResponse&&this.on({as:i},"afterResponse",t.afterResponse),t.error&&this.on({as:i},"error",t.error),this}return this.guard({},t)}let n=new e({...this.config,prefix:""});n.singleton={...this.singleton},n.definitions={...this.definitions},n.inference=fp(this.inference),n.extender={...this.extender},n.getServer=()=>this.getServer();let o=r(n);if(this.singleton=Ct(this.singleton,n.singleton),this.definitions=Ct(this.definitions,n.definitions),o.getServer=()=>this.server,o.event.request?.length&&(this.event.request=[...this.event.request||[],...o.event.request||[]]),o.event.mapResponse?.length&&(this.event.mapResponse=[...this.event.mapResponse||[],...o.event.mapResponse||[]]),this.model(o.definitions.type),Object.values(n.router.history).forEach(({method:i,path:s,handler:a,hooks:c})=>{let{body:l,headers:u,query:d,params:f,cookie:p,response:g,...m}=t,y=l||u||d||f||p||g;this.add(i,s,a,no(m,{...c||{},error:c.error?Array.isArray(c.error)?[...c.error??[],...o.event.error??[]]:[c.error,...o.event.error??[]]:o.event.error,standaloneValidator:y?[...c.standaloneValidator??[],{body:l,headers:u,query:d,params:f,cookie:p,response:g}]:c.standaloneValidator}))}),n.promisedModules.size>0){let i=n.router.history.length;for(let s of n.promisedModules.promises)this.promisedModules.add(s.then(()=>{let{body:a,headers:c,query:l,params:u,cookie:d,response:f,...p}=t,g=a||c||l||u||d||f,m=i;i=n.router.history.length;for(let y=m;y<n.router.history.length;y++){let{method:b,path:w,handler:E,hooks:A}=n.router.history[y];this.add(b,w,E,no(p,{...A||{},error:A.error?Array.isArray(A.error)?[...A.error??[],...o.event.error??[]]:[A.error,...o.event.error??[]]:o.event.error,standaloneValidator:g?[...A.standaloneValidator??[],{body:a,headers:c,query:l,params:u,cookie:d,response:f}]:A.standaloneValidator}))}}))}return this}use(t){if(!t)return this;if(Array.isArray(t)){let r=this;for(let n of t)r=r.use(n);return r}return t instanceof Promise?(this.promisedModules.add(t.then((r)=>{if(typeof r=="function")return r(this);if(r instanceof e)return this._use(r).compile();if(r.constructor?.name==="Elysia")return this._use(r).compile();if(typeof r.default=="function")return r.default(this);if(r.default instanceof e)return this._use(r.default);if(r.constructor?.name==="Elysia")return this._use(r.default);if(r.constructor?.name==="_Elysia")return this._use(r.default);try{return this._use(r.default)}catch(n){throw console.error('Invalid plugin type. Expected Elysia instance, function, or module with "default" as Elysia instance or function that returns Elysia instance.'),n}}).then((r)=>(r&&typeof r.compile=="function"&&r.compile(),r))),this):this._use(t)}propagatePromiseModules(t){if(t.promisedModules.size<=0)return this;for(let r of t.promisedModules.promises)this.promisedModules.add(r.then((n)=>{if(!n)return;let o=this._use(n);return o instanceof Promise?o.then((i)=>{i?i.compile():n.compile()}):n.compile()}));return this}_use(t){if(typeof t=="function"){let o=t(this);return o instanceof Promise?(this.promisedModules.add(o.then((i)=>{if(i instanceof e){i.getServer=()=>this.getServer(),i.getGlobalRoutes=()=>this.getGlobalRoutes(),i.getGlobalDefinitions=()=>this.getGlobalDefinitions(),i.model(this.definitions.type),i.error(this.definitions.error);for(let{method:s,path:a,handler:c,hooks:l}of Object.values(i.router.history))this.add(s,a,c,l,void 0);return i===this?void 0:(this.propagatePromiseModules(i),i)}return typeof i=="function"?i(this):typeof i.default=="function"?i.default(this):this._use(i)}).then((i)=>(i&&typeof i.compile=="function"&&i.compile(),i))),this):o}this.propagatePromiseModules(t);let r=t.config.name,n=t.config.seed;if(t.getParent=()=>this,t.getServer=()=>this.getServer(),t.getGlobalRoutes=()=>this.getGlobalRoutes(),t.getGlobalDefinitions=()=>this.getGlobalDefinitions(),t.standaloneValidator?.scoped&&(this.standaloneValidator.local?this.standaloneValidator.local=this.standaloneValidator.local.concat(t.standaloneValidator.scoped):this.standaloneValidator.local=t.standaloneValidator.scoped),t.standaloneValidator?.global&&(this.standaloneValidator.global?this.standaloneValidator.global=this.standaloneValidator.global.concat(t.standaloneValidator.global):this.standaloneValidator.global=t.standaloneValidator.global),Se(t["~parser"])&&(this["~parser"]={...t["~parser"],...this["~parser"]}),t.setHeaders&&this.headers(t.setHeaders),r){r in this.dependencies||(this.dependencies[r]=[]);let o=n!==void 0?No(r+JSON.stringify(n)):0;this.dependencies[r].some(({checksum:i})=>o===i)||(this.extender.macro={...this.extender.macro,...t.extender.macro},this.extender.higherOrderFunctions=this.extender.higherOrderFunctions.concat(t.extender.higherOrderFunctions))}else Se(t.extender.macro)&&(this.extender.macro={...this.extender.macro,...t.extender.macro}),t.extender.higherOrderFunctions.length&&(this.extender.higherOrderFunctions=this.extender.higherOrderFunctions.concat(t.extender.higherOrderFunctions));if(t.extender.higherOrderFunctions.length){Lh(this.extender.higherOrderFunctions);let o=[];for(let i=0;i<this.extender.higherOrderFunctions.length;i++){let s=this.extender.higherOrderFunctions[i];s.checksum&&(o.includes(s.checksum)&&(this.extender.higherOrderFunctions.splice(i,1),i--),o.push(s.checksum))}o.length=0}this.inference=Dp(this.inference,t.inference),Se(t.singleton.decorator)&&this.decorate(t.singleton.decorator),Se(t.singleton.store)&&this.state(t.singleton.store),Se(t.definitions.type)&&this.model(t.definitions.type),Se(t.definitions.error)&&this.error(t.definitions.error),Se(t.extender.macro)&&(this.extender.macro={...this.extender.macro,...t.extender.macro});for(let{method:o,path:i,handler:s,hooks:a}of Object.values(t.router.history))this.add(o,i,s,a);if(r){r in this.dependencies||(this.dependencies[r]=[]);let o=n!==void 0?No(r+JSON.stringify(n)):0;if(this.dependencies[r].some(({checksum:i})=>o===i))return this;this.dependencies[r].push(this.config?.analytic?{name:t.config.name,seed:t.config.seed,checksum:o,dependencies:t.dependencies,stack:t.telemetry?.stack,routes:t.router.history,decorators:t.singleton,store:t.singleton.store,error:t.definitions.error,derive:t.event.transform?.filter((i)=>i?.subType==="derive").map((i)=>({fn:i.toString(),stack:Error().stack??""})),resolve:t.event.transform?.filter((i)=>i?.subType==="resolve").map((i)=>({fn:i.toString(),stack:Error().stack??""}))}:{name:t.config.name,seed:t.config.seed,checksum:o,dependencies:t.dependencies}),Se(t.event)&&(this.event=Rh(this.event,Ch(t.event),o))}else Se(t.event)&&(this.event=Rh(this.event,Ch(t.event)));return t.validator.global&&(this.validator.global=no(this.validator.global,{...t.validator.global})),t.validator.scoped&&(this.validator.local=no(this.validator.local,{...t.validator.scoped})),this}macro(t,r){if(typeof t=="string"&&!r)throw Error("Macro function is required");return typeof t=="string"?this.extender.macro[t]=r:this.extender.macro={...this.extender.macro,...t},this}applyMacro(t,r=t,{iteration:n=0,applied:o={}}={}){if(n>=16)return;let i=this.extender.macro;for(let[s,a]of Object.entries(r)){if(!(s in i))continue;let c=typeof i[s]=="function"?i[s](a):i[s];if(!c||typeof i[s]=="object"&&a===!1)return;let l=No(s+JSON.stringify(c.seed??a));if(!(l in o)){o[l]=!0;for(let[u,d]of Object.entries(c))if(u!=="seed"){if(u in Jk){zk(t,u,d),delete t[s];continue}if(u==="introspect"){d?.(t),delete t[s];continue}if(u==="detail"){t.detail||(t.detail={}),t.detail=Ct(t.detail,d,{mergeArray:!0}),delete t[s];continue}if(u in i){this.applyMacro(t,{[u]:d},{applied:o,iteration:n+1}),delete t[s];continue}switch((u==="derive"||u==="resolve")&&typeof d=="function"&&(d={fn:d,subType:u}),typeof t[u]){case"function":t[u]=[t[u],d];break;case"object":Array.isArray(t[u])?t[u].push(d):t[u]=[t[u],d];break;case"undefined":t[u]=d;break}delete t[s]}}}}mount(t,r,n){if(t instanceof e||typeof t=="function"||t.length===0||t==="/"){let a=typeof t=="function"?t:t instanceof e?t.compile().fetch:r instanceof e?r.compile().fetch:typeof r=="function"?r:(()=>{throw Error("Invalid handler")})(),c=({request:l,path:u})=>a(new Request(lp(l.url,u),l));return this.route("ALL","/*",c,{parse:"none",...n,detail:{...n?.detail,hide:!0},config:{mount:a}}),this}let o=r instanceof e?r.compile().fetch:typeof r=="function"?r:(()=>{throw Error("Invalid handler")})(),i=(typeof t=="string"&&this.config.prefix?this.config.prefix+t:t).length-(t.endsWith("*")?1:0),s=({request:a,path:c})=>o(new Request(lp(a.url,c.slice(i)||"/"),a));return this.route("ALL",t,s,{parse:"none",...n,detail:{...n?.detail,hide:!0},config:{mount:o}}),this.route("ALL",t+(t.endsWith("/")?"*":"/*"),s,{parse:"none",...n,detail:{...n?.detail,hide:!0},config:{mount:o}}),this}get(t,r,n){return this.add("GET",t,r,n),this}post(t,r,n){return this.add("POST",t,r,n),this}put(t,r,n){return this.add("PUT",t,r,n),this}patch(t,r,n){return this.add("PATCH",t,r,n),this}delete(t,r,n){return this.add("DELETE",t,r,n),this}options(t,r,n){return this.add("OPTIONS",t,r,n),this}all(t,r,n){return this.add("ALL",t,r,n),this}head(t,r,n){return this.add("HEAD",t,r,n),this}connect(t,r,n){return this.add("CONNECT",t,r,n),this}route(t,r,n,o){return this.add(t.toUpperCase(),r,n,o,o?.config),this}ws(t,r){return this["~adapter"].ws?this["~adapter"].ws(this,t,r):console.warn("Current adapter doesn't support WebSocket"),this}state(t,r,n){r===void 0?(n=t,t={as:"append"},r=""):n===void 0&&(typeof t=="string"?(n=r,r=t,t={as:"append"}):typeof t=="object"&&(n=r,r=""));let{as:o}=t;if(typeof r!="string")return this;switch(typeof n){case"object":return!n||!Se(n)?this:r?((r in this.singleton.store)?this.singleton.store[r]=Ct(this.singleton.store[r],n,{override:o==="override"}):this.singleton.store[r]=n,this):n===null?this:(this.singleton.store=Ct(this.singleton.store,n,{override:o==="override"}),this);case"function":return r?(o==="override"||!(r in this.singleton.store))&&(this.singleton.store[r]=n):this.singleton.store=n(this.singleton.store),this;default:return(o==="override"||!(r in this.singleton.store))&&(this.singleton.store[r]=n),this}}decorate(t,r,n){r===void 0?(n=t,t={as:"append"},r=""):n===void 0&&(typeof t=="string"?(n=r,r=t,t={as:"append"}):typeof t=="object"&&(n=r,r=""));let{as:o}=t;if(typeof r!="string")return this;switch(typeof n){case"object":return r?((r in this.singleton.decorator)?this.singleton.decorator[r]=Ct(this.singleton.decorator[r],n,{override:o==="override"}):this.singleton.decorator[r]=n,this):n===null?this:(this.singleton.decorator=Ct(this.singleton.decorator,n,{override:o==="override"}),this);case"function":return r?(o==="override"||!(r in this.singleton.decorator))&&(this.singleton.decorator[r]=n):this.singleton.decorator=n(this.singleton.decorator),this;default:return(o==="override"||!(r in this.singleton.decorator))&&(this.singleton.decorator[r]=n),this}}derive(t,r){r||(r=t,t={as:"local"});let n={subType:"derive",fn:r};return this.onTransform(t,n)}model(t,r){let n=(o)=>{let i={};for(let s in o)"~standard"in o[s]||(i[s]=o[s]);return i};switch(typeof t){case"object":let o={},i=Object.entries(t);if(!i.length)return this;for(let[c,l]of i)c in this.definitions.type||("~standard"in l?this.definitions.type[c]=l:(o[c]=this.definitions.type[c]=l,o[c].$id??=`#/components/schemas/${c}`));return this.definitions.typebox=V.Module({...this.definitions.typebox.$defs,...o}),this;case"function":let s=t(this.definitions.type);return this.definitions.type=s,this.definitions.typebox=V.Module(n(s)),this;case"string":if(!r)break;if(this.definitions.type[t]=r,"~standard"in r)return this;let a={...r,id:r.$id??`#/components/schemas/${t}`};return this.definitions.typebox=V.Module({...this.definitions.typebox.$defs,...a}),this}return r?(this.definitions.type[t]=r,("~standard"in r)?this:(this.definitions.typebox=V.Module({...this.definitions.typebox.$defs,[t]:r}),this)):this}Ref(t){return V.Ref(t)}mapDerive(t,r){r||(r=t,t={as:"local"});let n={subType:"mapDerive",fn:r};return this.onTransform(t,n)}affix(t,r,n){if(n==="")return this;let o=["_","-"," "],i=(l)=>l[0].toUpperCase()+l.slice(1),s=t==="prefix"?(l,u)=>o.includes(l.at(-1)??"")?l+u:l+i(u):o.includes(n.at(-1)??"")?(l,u)=>u+l:(l,u)=>u+i(l),a=(l)=>{let u={};switch(l){case"decorator":for(let d in this.singleton.decorator)u[s(n,d)]=this.singleton.decorator[d];this.singleton.decorator=u;break;case"state":for(let d in this.singleton.store)u[s(n,d)]=this.singleton.store[d];this.singleton.store=u;break;case"model":for(let d in this.definitions.type)u[s(n,d)]=this.definitions.type[d];this.definitions.type=u;break;case"error":for(let d in this.definitions.error)u[s(n,d)]=this.definitions.error[d];this.definitions.error=u;break}},c=Array.isArray(r)?r:[r];for(let l of c.some((u)=>u==="all")?["decorator","state","model","error"]:c)a(l);return this}prefix(t,r){return this.affix("prefix",t,r)}suffix(t,r){return this.affix("suffix",t,r)}compile(){return this["~adapter"].beforeCompile?.(this),this["~adapter"].isWebStandard?(this._handle=this.config.aot?Qp(this):Ey(this),Object.defineProperty(this,"fetch",{value:this._handle,configurable:!0,writable:!0}),typeof this.server?.reload=="function"&&this.server.reload({...this.server||{},fetch:this.fetch}),this):(typeof this.server?.reload=="function"&&this.server.reload(this.server||{}),this._handle=Qp(this),this)}get fetch(){let t=this.config.aot?Qp(this):Ey(this);return Object.defineProperty(this,"fetch",{value:t,configurable:!0,writable:!0}),t}get modules(){return this.promisedModules}},un=R9;var ef={name:"ompchamber",version:"3.3.1",description:"Developer web console and diagnostic chamber for AI Oh-My-Pi \u2014 Elysia + Preact on Bun.",license:"UNLICENSED",author:"Wijanarko Putra Rajeb <wijanarko.rajeb@gmail.com>",type:"module",engines:{bun:">=1.4.0"},bin:{ompchamber:"./src/cli/ompchamber.js"},repository:{type:"git",url:"git+https://github.com/rajebdev/ompchamber.git"},homepage:"https://github.com/rajebdev/ompchamber#readme",bugs:{url:"https://github.com/rajebdev/ompchamber/issues"},keywords:["omp","oh-my-pi","agent","console","elysia","preact","bun"],files:["src","index.html","bunfig.toml","public","tsconfig.json","dist/client"],scripts:{dev:"bun run --hot src/server/index.ts --ompchamber-server","dev:lan":"HOST=0.0.0.0 bun run --hot src/server/index.ts --ompchamber-server",build:"bun run scripts/build-client.ts",start:"NODE_ENV=production bun run src/server/index.ts --ompchamber-server",typecheck:"tsc",clean:"rm -rf dist",lint:"tsc --noEmit",test:"bun test"},dependencies:{"@fontsource/fira-code":"^5.3.0","@shikijs/langs":"^4.4.3","@shikijs/themes":"^4.4.3","@tailwindcss/postcss":"^4.1.14","@xterm/addon-fit":"^0.11.0","@xterm/addon-webgl":"^0.19.0","@xterm/xterm":"^6.0.0",dompurify:"^3.4.15",elysia:"^1.4.30",katex:"^0.18.7","lucide-preact":"^1.47.0",marked:"^18.0.11","marked-linkify-it":"^4.0.2",mermaid:"^12.0.0",postcss:"^8.5.16",preact:"^10.29.8",remend:"^1.3.1",ripgrep:"^0.3.1",shiki:"^4.4.3",tailwindcss:"^4.1.14",yaml:"^2.9.1"},devDependencies:{"@semantic-release/changelog":"^7.0.0","@semantic-release/commit-analyzer":"^13.0.1","@semantic-release/git":"^11.0.1","@semantic-release/github":"^12.0.10","@semantic-release/npm":"^13.2.0","@semantic-release/release-notes-generator":"^14.1.1","@types/bun":"^1.4.2","@types/node":"^22.14.0","conventional-changelog-conventionalcommits":"^9.3.1","happy-dom":"^20.14.5","semantic-release":"^25.0.9",typescript:"~5.8.2"}};var cE=ES("{\"index\":\"./dist/client/index.html\",\"files\":[{\"input\":\"../../index.html\",\"path\":\"./dist/client/static/js/index-4qx6m2p7.js\",\"loader\":\"js\",\"isEntry\":true,\"headers\":{\"etag\":\"RPcdJpRCtuc\",\"content-type\":\"text/javascript;charset=utf-8\"}},{\"input\":\"../../index.html\",\"path\":\"./dist/client/index.html\",\"loader\":\"html\",\"isEntry\":true,\"headers\":{\"etag\":\"z2S5dNAxSlA\",\"content-type\":\"text/html;charset=utf-8\"}},{\"input\":\"../../index.html\",\"path\":\"./dist/client/static/js/index-bsxxt89j.css\",\"loader\":\"css\",\"isEntry\":true,\"headers\":{\"etag\":\"S5m9nZrIyXI\",\"content-type\":\"text/css;charset=utf-8\"}},{\"input\":\"../../public/manifest.webmanifest\",\"path\":\"./dist/client/static/manifest-bnyy75kt.webmanifest\",\"loader\":\"file\",\"isEntry\":false,\"headers\":{\"etag\":\"CxU-Pqfls5o\",\"content-type\":\"application/manifest+json\"}},{\"input\":\"../../public/icon.svg\",\"path\":\"./dist/client/static/icon-d07z9dtz.svg\",\"loader\":\"file\",\"isEntry\":false,\"headers\":{\"etag\":\"baDnH-kt2p8\",\"content-type\":\"image/svg+xml\"}},{\"input\":\"../../public/icon-192x192.png\",\"path\":\"./dist/client/static/icon-192x192-6gn5cr2f.png\",\"loader\":\"file\",\"isEntry\":false,\"headers\":{\"etag\":\"JtAVBew4Ag8\",\"content-type\":\"image/png\"}},{\"input\":\"../../public/apple-touch-icon.png\",\"path\":\"./dist/client/static/apple-touch-icon-dskx5sr3.png\",\"loader\":\"file\",\"isEntry\":false,\"headers\":{\"etag\":\"TTkT3WVZWKM\",\"content-type\":\"image/png\"}}]}");function h(e,t={}){let r=new Headers(t.headers);if(!r.has("content-type"))r.set("content-type","application/json; charset=utf-8");return new Response(JSON.stringify(e),{status:t.status??200,headers:r})}var dn={"cache-control":"no-store"};import{brotliCompressSync as O9,constants as M9}from"zlib";var F9=1024,N9=/^(text\/|application\/(json|javascript|xml|wasm|svg))/,L9=["zstd","br","gzip"];function D9(e){for(let t of L9)if(e.includes(t))return t;return null}function B9(e,t){if(t==="zstd")return Bun.zstdCompressSync(e,{level:3});if(t==="br")return O9(e,{params:{[M9.BROTLI_PARAM_QUALITY]:4}});return Bun.gzipSync(e,{level:6})}async function tf(e,t){if(!t)return e;let r=e.headers.get("content-type")??"";if(r.includes("text/event-stream"))return e;if(!N9.test(r))return e;if(e.status===204||e.status===304)return e;let n=D9(t);if(!n)return e;let o=new Uint8Array(await e.arrayBuffer());if(o.byteLength<F9)return j9(e,o);let i=B9(o,n),s=new Headers(e.headers);return s.set("content-encoding",n),s.set("content-length",String(i.byteLength)),s.append("vary","accept-encoding"),new Response(i,{status:e.status,headers:s})}function j9(e,t){return new Response(t,{status:e.status,headers:e.headers})}function Q(e,t,r={}){let n=[];if(e.loader)n.push({method:"GET",path:t,handler:e.loader});else if(e.action)n.push({method:"GET",path:t,handler:ee});if(e.action)for(let o of r.mutating??["POST","PUT","PATCH","DELETE"])n.push({method:o,path:t,handler:e.action});return n}var ee=()=>new Response(JSON.stringify({error:"Method not allowed"}),{status:405,headers:{"content-type":"application/json; charset=utf-8"}});function Us(e,t){let r=e[t];return r?r:null}function qs(e,t=500){return h({error:e instanceof Error?e.message:String(e)},{status:t})}async function U9(e){if(e instanceof Response)return e;if(e instanceof ReadableStream)return new Response(e,{headers:{"content-type":"text/event-stream","cache-control":"no-cache"}});return new Response(JSON.stringify(e??null),{status:200,headers:{"content-type":"application/json; charset=utf-8"}})}function q9(e){return async({request:t,params:r})=>{try{let n=await U9(await e({request:t,params:r}));return await tf(n,t.headers.get("accept-encoding"))}catch(n){let o=n instanceof Error?n.message:String(n);return new Response(JSON.stringify({error:o}),{status:500,headers:{"content-type":"application/json; charset=utf-8"}})}}}function lE(e,t){let r=e;for(let{method:n,path:o,handler:i}of t){let s=q9(i);if(n==="GET")r=r.get(o,s);else if(n==="POST")r=r.post(o,s);else if(n==="PUT")r=r.put(o,s);else if(n==="PATCH")r=r.patch(o,s);else r=r.delete(o,s)}return r}function Yt(e,t,r){return[{method:"GET",path:t,handler:r??ee},...["POST","PUT","PATCH","DELETE"].map((n)=>({method:n,path:t,handler:e}))]}import{existsSync as W9,realpathSync as H9}from"fs";import{homedir as V9,tmpdir as Gke}from"os";import*as pn from"path";var K9="omp",z9=".omp";function G9(){return Bun.env.PI_CONFIG_DIR||z9}function lc(){return pn.join(V9(),G9())}function Oe(){let e=Bun.env.PI_CODING_AGENT_DIR;if(e)return pn.resolve(e);return pn.join(lc(),"agent")}function J9(){let e=Bun.env.PI_CODING_AGENT_DIR;if(e)return pn.resolve(e)===pn.join(lc(),"agent");return!0}function Y9(){if(process.platform!=="linux"&&process.platform!=="darwin")return;if(!J9())return;let e=Bun.env.XDG_DATA_HOME;if(!e)return;try{let t=pn.join(e,K9);return W9(t)?t:void 0}catch{return}}function $9(e){let t=Y9();return pn.join(t??Oe(),e)}function uo(){return $9("sessions")}function uE(){return pn.join(Oe(),"projects.json")}function rf(e){try{return H9.native(e)}catch{return e}}async function Be(e){try{return await Bun.file(e).stat(),!0}catch{return!1}}function Ii(e){let t=rf(e);return t.replace(/\/+$/,"")||t}import Cy from"fs";import*as nf from"path";function I(e){return typeof e==="object"&&e!==null&&!Array.isArray(e)}function $t(e){let t=[];for(let r of e.split(`
|
|
667
667
|
`)){let n=r.trim();if(!n)continue;try{t.push(JSON.parse(n))}catch{}}return t}function fE(e){if(typeof e==="string")return e;if(!Array.isArray(e))return"";let t=[];for(let r of e)if(I(r)&&r.type==="text"&&typeof r.text==="string")t.push(r.text);return t.join(" ")}function dE(e){let t=e.endsWith("\\")?e.slice(0,-1):e;try{return JSON.parse(`"${t}"`)}catch{return t.replace(/\\n/g,`
|
|
668
668
|
`).replace(/\\r/g,"\r").replace(/\\t/g,"\t").replace(/\\"/g,'"').replace(/\\\\/g,"\\")}}function or(e,t,r=0){let n=e.indexOf(`"${t}"`,r);if(n===-1)return;let o=e.indexOf(":",n+t.length+2);if(o===-1)return;let i=o+1;while(i<e.length){let c=e.charCodeAt(i);if(c!==32&&c!==9&&c!==10&&c!==13)break;i++}if(e.charCodeAt(i)!==34)return;let s=i+1,a=!1;for(let c=s;c<e.length;c++){let l=e.charCodeAt(c);if(a){a=!1;continue}if(l===92){a=!0;continue}if(l===34)return dE(e.slice(s,c))}return dE(e.slice(s))}function mE(e){let t=0,r=0;while(r<e.length){let n=e.indexOf('"type"',r);if(n===-1)break;let o=e.indexOf(":",n+6);if(o===-1)break;if(or(e,"type",n)==="message")t++;r=o+1}return t}function gE(e){let t,r=e.indexOf('"role"');while(r!==-1){let n=or(e,"role",r),o=or(e,"content",r)??or(e,"text",r);if(o){if(n==="user")return o;if(!t&&(n==="developer"||n==="assistant"))t=o}r=e.indexOf('"role"',r+6)}return t}function pE(e){if(e===void 0)return;return e.trim()?e:null}function Q9(e,t){if(e?.type!=="session"||typeof e.id!=="string")return;return{id:e.id,cwd:typeof e.cwd==="string"?e.cwd:void 0,title:t===null?void 0:t??(typeof e.title==="string"?e.title:void 0),parentSession:typeof e.parentSession==="string"?e.parentSession:void 0,timestamp:typeof e.timestamp==="string"?e.timestamp:void 0}}function X9(e,t){if(or(e,"type")!=="session")return;let r=or(e,"id");if(!r)return;return{id:r,cwd:or(e,"cwd"),title:t===null?void 0:t??or(e,"title"),parentSession:or(e,"parentSession"),timestamp:or(e,"timestamp")}}function hE(e,t){let r=t[0],n=pE(r?.type==="title"&&typeof r.title==="string"?r.title:void 0),o=Q9(t[r?.type==="title"?1:0],n);if(o)return o;let i,s=!0;for(let a of e.split(/\r?\n/)){let c=a.trim();if(!c)continue;if(s&&or(c,"type")==="title"){i=pE(or(c,"title")),s=!1;continue}return X9(c,i)}return}var Ry=4096,Z9=16384,yE=1048576;async function bE(e,t){let r=Bun.file(e),n=await r.stat(),o=Math.min(t,n.size);return{text:o>0?await r.slice(0,o).text():"",size:n.size,mtime:new Date(n.mtimeMs),mtimeMs:n.mtimeMs}}var _9={session_exit:!0};function eH(e){let t,r,n,o=!1;try{let a=JSON.parse(e);if(I(a))o=!0,t=a.type,r=a.customType,n=a.timestamp}catch{}if(!o)n=or(e,"timestamp"),t=or(e,"type"),r=or(e,"customType");let i;if(typeof n==="number"&&Number.isFinite(n))i=new Date(n);else if(typeof n==="string"){let a=new Date(n);if(!Number.isNaN(a.getTime()))i=a}if(!i)return;let s=t==="custom"&&typeof r==="string"&&_9[r]===!0;return{at:i,lifecycle:s}}async function wE(e,t,r){if(t<=0)return;let n=Z9;for(;;){let o=Math.max(0,t-n),i;if(t<=Ry)i=r;else if(o===0)try{i=await Bun.file(e).text()}catch{return}else try{i=await Bun.file(e).slice(o-1).text()}catch{return}let s=i.split(`
|
|
669
669
|
`);if(o>0)s.shift();for(let a=s.length-1;a>=0;a--){let c=s[a].trim();if(!c.includes('"timestamp"'))continue;let l=eH(c);if(l&&!l.lifecycle)return l.at}if(o===0||n>=yE)return;n=Math.min(n*4,yE)}}var Ws=256;async function xE(e){try{let{text:t,size:r,mtime:n,mtimeMs:o}=await bE(e,Ry),i=await wE(e,r,t),s=$t(t),a=hE(t,s);if(!a)return;let c=0,l="",u;for(let d=1;d<s.length;d++){let f=s[d];if(f.type==="compaction"&&typeof f.shortSummary==="string")u=f.shortSummary;if(f.type==="message"&&f.message){if(c++,f.message.role==="user"&&!l)l=fE(f.message.content)}}return l||=gE(t)??"",{path:e,id:a.id,cwd:a.cwd??"",title:a.title??u,parentSessionPath:a.parentSession,created:new Date(a.timestamp??""),modified:i??n,fileMtime:n,fileMtimeMs:o,messageCount:Math.max(c,mE(t)),size:r,firstMessage:l||"(no messages)"}}catch{return}}var SE=3,tH=2048;async function rH(e=uo()){try{await Bun.file(e).stat()}catch{return[]}if(!globalThis.__ompChamberSessionFileListCache)globalThis.__ompChamberSessionFileListCache=new Map;let t=globalThis.__ompChamberSessionFileListCache,r=t.get(e);if(r){let s=!0;for(let a of await Cy.promises.readdir(e,{withFileTypes:!0})){if(!a.isDirectory())continue;try{let c=await Bun.file(nf.join(e,a.name)).stat();if(r.dirMtimes.get(a.name)!==c.mtimeMs){s=!1;break}}catch{s=!1;break}}if(s&&r.dirMtimes.size>0)return r.files}let n=[],o=new Map,i=[];try{i=await Cy.promises.readdir(e,{withFileTypes:!0})}catch{}for(let s of i){if(!s.isDirectory())continue;let a=nf.join(e,s.name);try{o.set(s.name,(await Bun.file(a).stat()).mtimeMs)}catch{continue}let c=[];try{c=await Cy.promises.readdir(a,{withFileTypes:!0})}catch{continue}for(let l of c){if(!l.isFile()||!l.name.endsWith(".jsonl"))continue;n.push(nf.join(a,l.name))}}return t.set(e,{dirMtimes:o,files:n}),globalThis.__ompChamberSessionIdIndex?.delete(e),n}function nH(){let e=globalThis.__ompChamberSessionScanCache;if(e&&e.version===SE)return e.entries;let t={version:SE,entries:new Map};return globalThis.__ompChamberSessionScanCache=t,t.entries}async function oH(e){let t;try{t=await Bun.file(e).stat()}catch{return}let r=nH(),n=r.get(e);if(n){let i=n;if(i.size===t.size&&i.fileMtimeMs===t.mtimeMs)return r.delete(e),r.set(e,i),i;r.delete(e)}let o=await xE(e);if(o){r.set(e,o);while(r.size>tH){let i=r.keys().next().value;if(i===void 0)break;r.delete(i)}}return o}async function iH(e,t,r){let n=Array(e.length),o=0,i=Array(Math.min(t,e.length)).fill(null).map(async()=>{for(;;){let s=o++;if(s>=e.length)return;n[s]=await r(e[s])}});return await Promise.all(i),n}var sH=32;async function Py(e=uo()){let t=await rH(e),r=await iH(t,sH,(o)=>oH(o)),n=[];for(let o of r)if(o)n.push(o);return n.sort((o,i)=>i.modified.getTime()-o.modified.getTime()),n}async function Oy(e=uo()){let t=globalThis.__ompChamberSessionIdIndex??=new Map,r=t.get(e);if(r)return r.entries;let n=new Map;for(let o of await Py(e))if(!n.has(o.id))n.set(o.id,o.path);return t.set(e,{entries:n}),n}function Dt(){globalThis.__ompChamberSessionFileListCache?.clear(),globalThis.__ompChamberSessionScanCache?.entries.clear(),globalThis.__ompChamberSessionIdIndex?.clear()}async function uc(e){try{let r=(await Bun.file(e).slice(0,Ws+4096).text()).split(`
|