@dmmulroy/overseer 0.7.0 → 0.8.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/bin/os +20 -134
- package/{dist → host/dist}/api/index.d.ts +1 -2
- package/{dist → host/dist}/api/index.js +1 -2
- package/{dist → host/dist}/api/learnings.d.ts +0 -1
- package/{dist → host/dist}/api/learnings.js +2 -2
- package/{dist → host/dist}/api/tasks.d.ts +0 -1
- package/{dist → host/dist}/api/tasks.js +0 -1
- package/host/dist/cli.d.ts +18 -0
- package/{dist → host/dist}/cli.js +22 -6
- package/{dist → host/dist}/decoder.d.ts +0 -1
- package/{dist → host/dist}/decoder.js +0 -1
- package/{dist → host/dist}/executor.d.ts +0 -1
- package/{dist → host/dist}/executor.js +0 -1
- package/host/dist/index.d.ts +2 -0
- package/host/dist/index.js +136 -0
- package/{dist/server.d.ts → host/dist/mcp.d.ts} +2 -3
- package/{dist/server.js → host/dist/mcp.js} +4 -5
- package/{dist → host/dist}/types.d.ts +0 -1
- package/{dist → host/dist}/types.js +0 -1
- package/host/dist/ui.d.ts +462 -0
- package/host/dist/ui.js +278 -0
- package/package.json +15 -12
- package/ui/dist/assets/index-71exl-6F.css +1 -0
- package/ui/dist/assets/index-CwXwWbGm.js +112 -0
- package/{dist/ui/static → ui/dist}/index.html +3 -3
- package/dist/api/index.d.ts.map +0 -1
- package/dist/api/index.js.map +0 -1
- package/dist/api/learnings.d.ts.map +0 -1
- package/dist/api/learnings.js.map +0 -1
- package/dist/api/tasks.d.ts.map +0 -1
- package/dist/api/tasks.js.map +0 -1
- package/dist/cli.d.ts +0 -5
- package/dist/cli.d.ts.map +0 -1
- package/dist/cli.js.map +0 -1
- package/dist/decoder.d.ts.map +0 -1
- package/dist/decoder.js.map +0 -1
- package/dist/executor.d.ts.map +0 -1
- package/dist/executor.js.map +0 -1
- package/dist/index.d.ts +0 -3
- package/dist/index.d.ts.map +0 -1
- package/dist/index.js +0 -10
- package/dist/index.js.map +0 -1
- package/dist/server.d.ts.map +0 -1
- package/dist/server.js.map +0 -1
- package/dist/tests/executor.test.d.ts +0 -2
- package/dist/tests/executor.test.d.ts.map +0 -1
- package/dist/tests/executor.test.js +0 -169
- package/dist/tests/executor.test.js.map +0 -1
- package/dist/tests/integration.test.d.ts +0 -2
- package/dist/tests/integration.test.d.ts.map +0 -1
- package/dist/tests/integration.test.js +0 -543
- package/dist/tests/integration.test.js.map +0 -1
- package/dist/tests/server.test.d.ts +0 -2
- package/dist/tests/server.test.d.ts.map +0 -1
- package/dist/tests/server.test.js +0 -53
- package/dist/tests/server.test.js.map +0 -1
- package/dist/types.d.ts.map +0 -1
- package/dist/types.js.map +0 -1
- package/dist/ui/server.js +0 -5
- package/dist/ui/server.js.map +0 -7
- package/dist/ui/static/assets/index-DnoPgzO1.js +0 -112
- package/dist/ui/static/assets/index-KqpkQhtL.css +0 -1
package/dist/ui/server.js
DELETED
|
@@ -1,5 +0,0 @@
|
|
|
1
|
-
// Overseer UI Server - Bundled with esbuild
|
|
2
|
-
import{createServer as $t}from"http";import{Http2ServerRequest as qt}from"http2";import{Http2ServerRequest as me}from"http2";import{Readable as He}from"stream";import Qt from"crypto";var _=class extends Error{constructor(e,t){super(e,t),this.name="RequestError"}},Mt=e=>e instanceof _?e:new _(e.message,{cause:e}),Nt=global.Request,V=class extends Nt{constructor(e,t){typeof e=="object"&&B in e&&(e=e[B]()),typeof t?.body?.getReader<"u"&&(t.duplex??="half"),super(e,t)}},Ut=e=>{let t=[],s=e.rawHeaders;for(let r=0;r<s.length;r+=2){let{[r]:n,[r+1]:a}=s;n.charCodeAt(0)!==58&&t.push([n,a])}return new Headers(t)},$e=Symbol("wrapBodyStream"),Bt=(e,t,s,r,n)=>{let a={method:e,headers:s,signal:n.signal};if(e==="TRACE"){a.method="GET";let o=new V(t,a);return Object.defineProperty(o,"method",{get(){return"TRACE"}}),o}if(!(e==="GET"||e==="HEAD"))if("rawBody"in r&&r.rawBody instanceof Buffer)a.body=new ReadableStream({start(o){o.enqueue(r.rawBody),o.close()}});else if(r[$e]){let o;a.body=new ReadableStream({async pull(i){try{o||=He.toWeb(r).getReader();let{done:c,value:u}=await o.read();c?i.close():i.enqueue(u)}catch(c){i.error(c)}}})}else a.body=He.toWeb(r);return new V(t,a)},B=Symbol("getRequestCache"),Ft=Symbol("requestCache"),re=Symbol("incomingKey"),se=Symbol("urlKey"),Wt=Symbol("headersKey"),U=Symbol("abortControllerKey"),zt=Symbol("getAbortController"),ne={get method(){return this[re].method||"GET"},get url(){return this[se]},get headers(){return this[Wt]||=Ut(this[re])},[zt](){return this[B](),this[U]},[B](){return this[U]||=new AbortController,this[Ft]||=Bt(this.method,this[se],this.headers,this[re],this[U])}};["body","bodyUsed","cache","credentials","destination","integrity","mode","redirect","referrer","referrerPolicy","signal","keepalive"].forEach(e=>{Object.defineProperty(ne,e,{get(){return this[B]()[e]}})});["arrayBuffer","blob","clone","formData","json","text"].forEach(e=>{Object.defineProperty(ne,e,{value:function(){return this[B]()[e]()}})});Object.setPrototypeOf(ne,V.prototype);var Gt=(e,t)=>{let s=Object.create(ne);s[re]=e;let r=e.url||"";if(r[0]!=="/"&&(r.startsWith("http://")||r.startsWith("https://"))){if(e instanceof me)throw new _("Absolute URL for :path is not allowed in HTTP/2");try{let i=new URL(r);s[se]=i.href}catch(i){throw new _("Invalid absolute URL",{cause:i})}return s}let n=(e instanceof me?e.authority:e.headers.host)||t;if(!n)throw new _("Missing host header");let a;if(e instanceof me){if(a=e.scheme,!(a==="http"||a==="https"))throw new _("Unsupported scheme")}else a=e.socket&&e.socket.encrypted?"https":"http";let o=new URL(`${a}://${n}${r}`);if(o.hostname.length!==n.length&&o.hostname!==n.replace(/:\d+$/,""))throw new _("Invalid host header");return s[se]=o.href,s},De=Symbol("responseCache"),N=Symbol("getResponseCache"),H=Symbol("cache"),ye=global.Response,J=class qe{#t;#e;[N](){return delete this[H],this[De]||=new ye(this.#t,this.#e)}constructor(t,s){let r;if(this.#t=t,s instanceof qe){let n=s[De];if(n){this.#e=n,this[N]();return}else this.#e=s.#e,r=new Headers(s.#e.headers)}else this.#e=s;(typeof t=="string"||typeof t?.getReader<"u"||t instanceof Blob||t instanceof Uint8Array)&&(r||=s?.headers||{"content-type":"text/plain; charset=UTF-8"},this[H]=[s?.status||200,t,r])}get headers(){let t=this[H];return t?(t[2]instanceof Headers||(t[2]=new Headers(t[2])),t[2]):this[N]().headers}get status(){return this[H]?.[0]??this[N]().status}get ok(){let t=this.status;return t>=200&&t<300}};["body","bodyUsed","redirected","statusText","trailers","type","url"].forEach(e=>{Object.defineProperty(J.prototype,e,{get(){return this[N]()[e]}})});["arrayBuffer","blob","clone","formData","json","text"].forEach(e=>{Object.defineProperty(J.prototype,e,{value:function(){return this[N]()[e]()}})});Object.setPrototypeOf(J,ye);Object.setPrototypeOf(J.prototype,ye.prototype);async function Kt(e){return Promise.race([e,Promise.resolve().then(()=>Promise.resolve(void 0))])}function Me(e,t,s){let r=i=>{e.cancel(i).catch(()=>{})};return t.on("close",r),t.on("error",r),(s??e.read()).then(o,n),e.closed.finally(()=>{t.off("close",r),t.off("error",r)});function n(i){i&&t.destroy(i)}function a(){e.read().then(o,n)}function o({done:i,value:c}){try{if(i)t.end();else if(!t.write(c))t.once("drain",a);else return e.read().then(o,n)}catch(u){n(u)}}}function Vt(e,t){if(e.locked)throw new TypeError("ReadableStream is locked.");return t.destroyed?void 0:Me(e.getReader(),t)}var Ne=e=>{let t={};e instanceof Headers||(e=new Headers(e??void 0));let s=[];for(let[r,n]of e)r==="set-cookie"?s.push(n):t[r]=n;return s.length>0&&(t["set-cookie"]=s),t["content-type"]??="text/plain; charset=UTF-8",t},Jt="x-hono-already-sent";typeof global.crypto>"u"&&(global.crypto=Qt);var we=Symbol("outgoingEnded"),Yt=()=>new Response(null,{status:400}),Ue=e=>new Response(null,{status:e instanceof Error&&(e.name==="TimeoutError"||e.constructor.name==="TimeoutError")?504:500}),ge=(e,t)=>{let s=e instanceof Error?e:new Error("unknown error",{cause:e});s.code==="ERR_STREAM_PREMATURE_CLOSE"?console.info("The user aborted a request."):(console.error(e),t.headersSent||t.writeHead(500,{"Content-Type":"text/plain"}),t.end(`Error: ${s.message}`),t.destroy(s))},Be=e=>{"flushHeaders"in e&&e.writable&&e.flushHeaders()},Fe=async(e,t)=>{let[s,r,n]=e[H];n instanceof Headers&&(n=Ne(n)),typeof r=="string"?n["Content-Length"]=Buffer.byteLength(r):r instanceof Uint8Array?n["Content-Length"]=r.byteLength:r instanceof Blob&&(n["Content-Length"]=r.size),t.writeHead(s,n),typeof r=="string"||r instanceof Uint8Array?t.end(r):r instanceof Blob?t.end(new Uint8Array(await r.arrayBuffer())):(Be(t),await Vt(r,t)?.catch(a=>ge(a,t))),t[we]?.()},Xt=e=>typeof e.then=="function",Zt=async(e,t,s={})=>{if(Xt(e))if(s.errorHandler)try{e=await e}catch(n){let a=await s.errorHandler(n);if(!a)return;e=a}else e=await e.catch(Ue);if(H in e)return Fe(e,t);let r=Ne(e.headers);if(e.body){let n=e.body.getReader(),a=[],o=!1,i;if(r["transfer-encoding"]!=="chunked"){let c=2;for(let u=0;u<c;u++){i||=n.read();let l=await Kt(i).catch(f=>{console.error(f),o=!0});if(!l){if(u===1){await new Promise(f=>setTimeout(f)),c=3;continue}break}if(i=void 0,l.value&&a.push(l.value),l.done){o=!0;break}}o&&!("content-length"in r)&&(r["content-length"]=a.reduce((u,l)=>u+l.length,0))}t.writeHead(e.status,r),a.forEach(c=>{t.write(c)}),o?t.end():(a.length===0&&Be(t),await Me(n,t,i))}else r[Jt]||(t.writeHead(e.status,r),t.end());t[we]?.()},er=(e,t={})=>{let s=t.autoCleanupIncoming??!0;return t.overrideGlobalObjects!==!1&&global.Request!==V&&(Object.defineProperty(global,"Request",{value:V}),Object.defineProperty(global,"Response",{value:J})),async(r,n)=>{let a,o;try{o=Gt(r,t.hostname);let i=!s||r.method==="GET"||r.method==="HEAD";if(i||(r[$e]=!0,r.on("end",()=>{i=!0}),r instanceof qt&&(n[we]=()=>{i||setTimeout(()=>{i||setTimeout(()=>{r.destroy(),n.destroy()})})})),n.on("close",()=>{o[U]&&(r.errored?o[U].abort(r.errored.toString()):n.writableFinished||o[U].abort("Client connection prematurely closed.")),i||setTimeout(()=>{i||setTimeout(()=>{r.destroy()})})}),a=e(o,{incoming:r,outgoing:n}),H in a)return Fe(a,n)}catch(i){if(a)return ge(i,n);if(t.errorHandler){if(a=await t.errorHandler(o?i:Mt(i)),!a)return}else o?a=Ue(i):a=Yt()}try{return await Zt(a,n,t)}catch(i){return ge(i,n)}}},tr=e=>{let t=e.fetch,s=er(t,{hostname:e.hostname,overrideGlobalObjects:e.overrideGlobalObjects,autoCleanupIncoming:e.autoCleanupIncoming});return(e.createServer||$t)(e.serverOptions||{},s)},We=(e,t)=>{let s=tr(e);return s.listen(e?.port??3e3,e.hostname,()=>{let r=s.address();t&&t(r)}),s};var be=(e,t,s)=>(r,n)=>{let a=-1;return o(0);async function o(i){if(i<=a)throw new Error("next() called multiple times");a=i;let c,u=!1,l;if(e[i]?(l=e[i][0][0],r.req.routeIndex=i):l=i===e.length&&n||void 0,l)try{c=await l(r,()=>o(i+1))}catch(f){if(f instanceof Error&&t)r.error=f,c=await t(f,r),u=!0;else throw f}else r.finalized===!1&&s&&(c=await s(r));return c&&(r.finalized===!1||u)&&(r.res=c),r}};var ze=Symbol();var Ge=async(e,t=Object.create(null))=>{let{all:s=!1,dot:r=!1}=t,a=(e instanceof ae?e.raw.headers:e.headers).get("Content-Type");return a?.startsWith("multipart/form-data")||a?.startsWith("application/x-www-form-urlencoded")?rr(e,{all:s,dot:r}):{}};async function rr(e,t){let s=await e.formData();return s?sr(s,t):{}}function sr(e,t){let s=Object.create(null);return e.forEach((r,n)=>{t.all||n.endsWith("[]")?nr(s,n,r):s[n]=r}),t.dot&&Object.entries(s).forEach(([r,n])=>{r.includes(".")&&(ar(s,r,n),delete s[r])}),s}var nr=(e,t,s)=>{e[t]!==void 0?Array.isArray(e[t])?e[t].push(s):e[t]=[e[t],s]:t.endsWith("[]")?e[t]=[s]:e[t]=s},ar=(e,t,s)=>{let r=e,n=t.split(".");n.forEach((a,o)=>{o===n.length-1?r[a]=s:((!r[a]||typeof r[a]!="object"||Array.isArray(r[a])||r[a]instanceof File)&&(r[a]=Object.create(null)),r=r[a])})};var ve=e=>{let t=e.split("/");return t[0]===""&&t.shift(),t},Ke=e=>{let{groups:t,path:s}=or(e),r=ve(s);return ir(r,t)},or=e=>{let t=[];return e=e.replace(/\{[^}]+\}/g,(s,r)=>{let n=`@${r}`;return t.push([n,s]),n}),{groups:t,path:e}},ir=(e,t)=>{for(let s=t.length-1;s>=0;s--){let[r]=t[s];for(let n=e.length-1;n>=0;n--)if(e[n].includes(r)){e[n]=e[n].replace(r,t[s][1]);break}}return e},oe={},Ve=(e,t)=>{if(e==="*")return"*";let s=e.match(/^\:([^\{\}]+)(?:\{(.+)\})?$/);if(s){let r=`${e}#${t}`;return oe[r]||(s[2]?oe[r]=t&&t[0]!==":"&&t[0]!=="*"?[r,s[1],new RegExp(`^${s[2]}(?=/${t})`)]:[e,s[1],new RegExp(`^${s[2]}$`)]:oe[r]=[e,s[1],!0]),oe[r]}return null},ie=(e,t)=>{try{return t(e)}catch{return e.replace(/(?:%[0-9A-Fa-f]{2})+/g,s=>{try{return t(s)}catch{return s}})}},cr=e=>ie(e,decodeURI),ke=e=>{let t=e.url,s=t.indexOf("/",t.indexOf(":")+4),r=s;for(;r<t.length;r++){let n=t.charCodeAt(r);if(n===37){let a=t.indexOf("?",r),o=t.slice(s,a===-1?void 0:a);return cr(o.includes("%25")?o.replace(/%25/g,"%2525"):o)}else if(n===63)break}return t.slice(s,r)};var Je=e=>{let t=ke(e);return t.length>1&&t.at(-1)==="/"?t.slice(0,-1):t},D=(e,t,...s)=>(s.length&&(t=D(t,...s)),`${e?.[0]==="/"?"":"/"}${e}${t==="/"?"":`${e?.at(-1)==="/"?"":"/"}${t?.[0]==="/"?t.slice(1):t}`}`),ce=e=>{if(e.charCodeAt(e.length-1)!==63||!e.includes(":"))return null;let t=e.split("/"),s=[],r="";return t.forEach(n=>{if(n!==""&&!/\:/.test(n))r+="/"+n;else if(/\:/.test(n))if(/\?/.test(n)){s.length===0&&r===""?s.push("/"):s.push(r);let a=n.replace("?","");r+="/"+a,s.push(r)}else r+="/"+n}),s.filter((n,a,o)=>o.indexOf(n)===a)},xe=e=>/[%+]/.test(e)?(e.indexOf("+")!==-1&&(e=e.replace(/\+/g," ")),e.indexOf("%")!==-1?ie(e,Ee):e):e,Qe=(e,t,s)=>{let r;if(!s&&t&&!/[%+]/.test(t)){let o=e.indexOf("?",8);if(o===-1)return;for(e.startsWith(t,o+1)||(o=e.indexOf(`&${t}`,o+1));o!==-1;){let i=e.charCodeAt(o+t.length+1);if(i===61){let c=o+t.length+2,u=e.indexOf("&",c);return xe(e.slice(c,u===-1?void 0:u))}else if(i==38||isNaN(i))return"";o=e.indexOf(`&${t}`,o+1)}if(r=/[%+]/.test(e),!r)return}let n={};r??=/[%+]/.test(e);let a=e.indexOf("?",8);for(;a!==-1;){let o=e.indexOf("&",a+1),i=e.indexOf("=",a);i>o&&o!==-1&&(i=-1);let c=e.slice(a+1,i===-1?o===-1?void 0:o:i);if(r&&(c=xe(c)),a=o,c==="")continue;let u;i===-1?u="":(u=e.slice(i+1,o===-1?void 0:o),r&&(u=xe(u))),s?(n[c]&&Array.isArray(n[c])||(n[c]=[]),n[c].push(u)):n[c]??=u}return t?n[t]:n},Ye=Qe,Xe=(e,t)=>Qe(e,t,!0),Ee=decodeURIComponent;var Ze=e=>ie(e,Ee),ae=class{raw;#t;#e;routeIndex=0;path;bodyCache={};constructor(e,t="/",s=[[]]){this.raw=e,this.path=t,this.#e=s,this.#t={}}param(e){return e?this.#r(e):this.#a()}#r(e){let t=this.#e[0][this.routeIndex][1][e],s=this.#n(t);return s&&/\%/.test(s)?Ze(s):s}#a(){let e={},t=Object.keys(this.#e[0][this.routeIndex][1]);for(let s of t){let r=this.#n(this.#e[0][this.routeIndex][1][s]);r!==void 0&&(e[s]=/\%/.test(r)?Ze(r):r)}return e}#n(e){return this.#e[1]?this.#e[1][e]:e}query(e){return Ye(this.url,e)}queries(e){return Xe(this.url,e)}header(e){if(e)return this.raw.headers.get(e)??void 0;let t={};return this.raw.headers.forEach((s,r)=>{t[r]=s}),t}async parseBody(e){return this.bodyCache.parsedBody??=await Ge(this,e)}#s=e=>{let{bodyCache:t,raw:s}=this,r=t[e];if(r)return r;let n=Object.keys(t)[0];return n?t[n].then(a=>(n==="json"&&(a=JSON.stringify(a)),new Response(a)[e]())):t[e]=s[e]()};json(){return this.#s("text").then(e=>JSON.parse(e))}text(){return this.#s("text")}arrayBuffer(){return this.#s("arrayBuffer")}blob(){return this.#s("blob")}formData(){return this.#s("formData")}addValidatedData(e,t){this.#t[e]=t}valid(e){return this.#t[e]}get url(){return this.raw.url}get method(){return this.raw.method}get[ze](){return this.#e}get matchedRoutes(){return this.#e[0].map(([[,e]])=>e)}get routePath(){return this.#e[0].map(([[,e]])=>e)[this.routeIndex].path}};var et={Stringify:1,BeforeStream:2,Stream:3},ur=(e,t)=>{let s=new String(e);return s.isEscaped=!0,s.callbacks=t,s};var Re=async(e,t,s,r,n)=>{typeof e=="object"&&!(e instanceof String)&&(e instanceof Promise||(e=e.toString()),e instanceof Promise&&(e=await e));let a=e.callbacks;if(!a?.length)return Promise.resolve(e);n?n[0]+=e:n=[e];let o=Promise.all(a.map(i=>i({phase:t,buffer:n,context:r}))).then(i=>Promise.all(i.filter(Boolean).map(c=>Re(c,t,!1,r,n))).then(()=>n[0]));return s?ur(await o,a):o};var lr="text/plain; charset=UTF-8",Te=(e,t)=>({"Content-Type":e,...t}),tt=class{#t;#e;env={};#r;finalized=!1;error;#a;#n;#s;#l;#c;#u;#i;#d;#h;constructor(e,t){this.#t=e,t&&(this.#n=t.executionCtx,this.env=t.env,this.#u=t.notFoundHandler,this.#h=t.path,this.#d=t.matchResult)}get req(){return this.#e??=new ae(this.#t,this.#h,this.#d),this.#e}get event(){if(this.#n&&"respondWith"in this.#n)return this.#n;throw Error("This context has no FetchEvent")}get executionCtx(){if(this.#n)return this.#n;throw Error("This context has no ExecutionContext")}get res(){return this.#s||=new Response(null,{headers:this.#i??=new Headers})}set res(e){if(this.#s&&e){e=new Response(e.body,e);for(let[t,s]of this.#s.headers.entries())if(t!=="content-type")if(t==="set-cookie"){let r=this.#s.headers.getSetCookie();e.headers.delete("set-cookie");for(let n of r)e.headers.append("set-cookie",n)}else e.headers.set(t,s)}this.#s=e,this.finalized=!0}render=(...e)=>(this.#c??=t=>this.html(t),this.#c(...e));setLayout=e=>this.#l=e;getLayout=()=>this.#l;setRenderer=e=>{this.#c=e};header=(e,t,s)=>{this.finalized&&(this.#s=new Response(this.#s.body,this.#s));let r=this.#s?this.#s.headers:this.#i??=new Headers;t===void 0?r.delete(e):s?.append?r.append(e,t):r.set(e,t)};status=e=>{this.#a=e};set=(e,t)=>{this.#r??=new Map,this.#r.set(e,t)};get=e=>this.#r?this.#r.get(e):void 0;get var(){return this.#r?Object.fromEntries(this.#r):{}}#o(e,t,s){let r=this.#s?new Headers(this.#s.headers):this.#i??new Headers;if(typeof t=="object"&&"headers"in t){let a=t.headers instanceof Headers?t.headers:new Headers(t.headers);for(let[o,i]of a)o.toLowerCase()==="set-cookie"?r.append(o,i):r.set(o,i)}if(s)for(let[a,o]of Object.entries(s))if(typeof o=="string")r.set(a,o);else{r.delete(a);for(let i of o)r.append(a,i)}let n=typeof t=="number"?t:t?.status??this.#a;return new Response(e,{status:n,headers:r})}newResponse=(...e)=>this.#o(...e);body=(e,t,s)=>this.#o(e,t,s);text=(e,t,s)=>!this.#i&&!this.#a&&!t&&!s&&!this.finalized?new Response(e):this.#o(e,t,Te(lr,s));json=(e,t,s)=>this.#o(JSON.stringify(e),t,Te("application/json",s));html=(e,t,s)=>{let r=n=>this.#o(n,t,Te("text/html; charset=UTF-8",s));return typeof e=="object"?Re(e,et.Stringify,!1,{}).then(r):r(e)};redirect=(e,t)=>{let s=String(e);return this.header("Location",/[^\x00-\xFF]/.test(s)?encodeURI(s):s),this.newResponse(null,t??302)};notFound=()=>(this.#u??=()=>new Response,this.#u(this))};var w="ALL",rt="all",st=["get","post","put","delete","options","patch"],ue="Can not add a route since the matcher is already built.",le=class extends Error{};var nt="__COMPOSED_HANDLER";var dr=e=>e.text("404 Not Found",404),at=(e,t)=>{if("getResponse"in e){let s=e.getResponse();return t.newResponse(s.body,s)}return console.error(e),t.text("Internal Server Error",500)},ot=class it{get;post;put;delete;options;patch;all;on;use;router;getPath;_basePath="/";#t="/";routes=[];constructor(t={}){[...st,rt].forEach(a=>{this[a]=(o,...i)=>(typeof o=="string"?this.#t=o:this.#a(a,this.#t,o),i.forEach(c=>{this.#a(a,this.#t,c)}),this)}),this.on=(a,o,...i)=>{for(let c of[o].flat()){this.#t=c;for(let u of[a].flat())i.map(l=>{this.#a(u.toUpperCase(),this.#t,l)})}return this},this.use=(a,...o)=>(typeof a=="string"?this.#t=a:(this.#t="*",o.unshift(a)),o.forEach(i=>{this.#a(w,this.#t,i)}),this);let{strict:r,...n}=t;Object.assign(this,n),this.getPath=r??!0?t.getPath??ke:Je}#e(){let t=new it({router:this.router,getPath:this.getPath});return t.errorHandler=this.errorHandler,t.#r=this.#r,t.routes=this.routes,t}#r=dr;errorHandler=at;route(t,s){let r=this.basePath(t);return s.routes.map(n=>{let a;s.errorHandler===at?a=n.handler:(a=async(o,i)=>(await be([],s.errorHandler)(o,()=>n.handler(o,i))).res,a[nt]=n.handler),r.#a(n.method,n.path,a)}),this}basePath(t){let s=this.#e();return s._basePath=D(this._basePath,t),s}onError=t=>(this.errorHandler=t,this);notFound=t=>(this.#r=t,this);mount(t,s,r){let n,a;r&&(typeof r=="function"?a=r:(a=r.optionHandler,r.replaceRequest===!1?n=c=>c:n=r.replaceRequest));let o=a?c=>{let u=a(c);return Array.isArray(u)?u:[u]}:c=>{let u;try{u=c.executionCtx}catch{}return[c.env,u]};n||=(()=>{let c=D(this._basePath,t),u=c==="/"?0:c.length;return l=>{let f=new URL(l.url);return f.pathname=f.pathname.slice(u)||"/",new Request(f,l)}})();let i=async(c,u)=>{let l=await s(n(c.req.raw),...o(c));if(l)return l;await u()};return this.#a(w,D(t,"*"),i),this}#a(t,s,r){t=t.toUpperCase(),s=D(this._basePath,s);let n={basePath:this._basePath,path:s,method:t,handler:r};this.router.add(t,s,[r,n]),this.routes.push(n)}#n(t,s){if(t instanceof Error)return this.errorHandler(t,s);throw t}#s(t,s,r,n){if(n==="HEAD")return(async()=>new Response(null,await this.#s(t,s,r,"GET")))();let a=this.getPath(t,{env:r}),o=this.router.match(n,a),i=new tt(t,{path:a,matchResult:o,env:r,executionCtx:s,notFoundHandler:this.#r});if(o[0].length===1){let u;try{u=o[0][0][0][0](i,async()=>{i.res=await this.#r(i)})}catch(l){return this.#n(l,i)}return u instanceof Promise?u.then(l=>l||(i.finalized?i.res:this.#r(i))).catch(l=>this.#n(l,i)):u??this.#r(i)}let c=be(o[0],this.errorHandler,this.#r);return(async()=>{try{let u=await c(i);if(!u.finalized)throw new Error("Context is not finalized. Did you forget to return a Response object or `await next()`?");return u.res}catch(u){return this.#n(u,i)}})()}fetch=(t,...s)=>this.#s(t,s[1],s[0],t.method);request=(t,s,r,n)=>t instanceof Request?this.fetch(s?new Request(t,s):t,r,n):(t=t.toString(),this.fetch(new Request(/^https?:\/\//.test(t)?t:`http://localhost${D("/",t)}`,s),r,n));fire=()=>{addEventListener("fetch",t=>{t.respondWith(this.#s(t.request,t,void 0,t.request.method))})}};var de=[];function Ie(e,t){let s=this.buildAllMatchers(),r=(n,a)=>{let o=s[n]||s[w],i=o[2][a];if(i)return i;let c=a.match(o[0]);if(!c)return[[],de];let u=c.indexOf("",1);return[o[1][u],c]};return this.match=r,r(e,t)}var he="[^/]+",Q=".*",Y="(?:|/.*)",$=Symbol(),hr=new Set(".\\+*[^]$()");function fr(e,t){return e.length===1?t.length===1?e<t?-1:1:-1:t.length===1||e===Q||e===Y?1:t===Q||t===Y?-1:e===he?1:t===he?-1:e.length===t.length?e<t?-1:1:t.length-e.length}var ct=class Se{#t;#e;#r=Object.create(null);insert(t,s,r,n,a){if(t.length===0){if(this.#t!==void 0)throw $;if(a)return;this.#t=s;return}let[o,...i]=t,c=o==="*"?i.length===0?["","",Q]:["","",he]:o==="/*"?["","",Y]:o.match(/^\:([^\{\}]+)(?:\{(.+)\})?$/),u;if(c){let l=c[1],f=c[2]||he;if(l&&c[2]&&(f===".*"||(f=f.replace(/^\((?!\?:)(?=[^)]+\)$)/,"(?:"),/\((?!\?:)/.test(f))))throw $;if(u=this.#r[f],!u){if(Object.keys(this.#r).some(m=>m!==Q&&m!==Y))throw $;if(a)return;u=this.#r[f]=new Se,l!==""&&(u.#e=n.varIndex++)}!a&&l!==""&&r.push([l,u.#e])}else if(u=this.#r[o],!u){if(Object.keys(this.#r).some(l=>l.length>1&&l!==Q&&l!==Y))throw $;if(a)return;u=this.#r[o]=new Se}u.insert(i,s,r,n,a)}buildRegExpStr(){let s=Object.keys(this.#r).sort(fr).map(r=>{let n=this.#r[r];return(typeof n.#e=="number"?`(${r})@${n.#e}`:hr.has(r)?`\\${r}`:r)+n.buildRegExpStr()});return typeof this.#t=="number"&&s.unshift(`#${this.#t}`),s.length===0?"":s.length===1?s[0]:"(?:"+s.join("|")+")"}};var ut=class{#t={varIndex:0};#e=new ct;insert(e,t,s){let r=[],n=[];for(let o=0;;){let i=!1;if(e=e.replace(/\{[^}]+\}/g,c=>{let u=`@\\${o}`;return n[o]=[u,c],o++,i=!0,u}),!i)break}let a=e.match(/(?::[^\/]+)|(?:\/\*$)|./g)||[];for(let o=n.length-1;o>=0;o--){let[i]=n[o];for(let c=a.length-1;c>=0;c--)if(a[c].indexOf(i)!==-1){a[c]=a[c].replace(i,n[o][1]);break}}return this.#e.insert(a,t,r,this.#t,s),r}buildRegExp(){let e=this.#e.buildRegExpStr();if(e==="")return[/^$/,[],[]];let t=0,s=[],r=[];return e=e.replace(/#(\d+)|@(\d+)|\.\*\$/g,(n,a,o)=>a!==void 0?(s[++t]=Number(a),"$()"):(o!==void 0&&(r[Number(o)]=++t),"")),[new RegExp(`^${e}`),s,r]}};var pr=[/^$/,[],Object.create(null)],lt=Object.create(null);function dt(e){return lt[e]??=new RegExp(e==="*"?"":`^${e.replace(/\/\*$|([.\\+*[^\]$()])/g,(t,s)=>s?`\\${s}`:"(?:|/.*)")}$`)}function mr(){lt=Object.create(null)}function gr(e){let t=new ut,s=[];if(e.length===0)return pr;let r=e.map(u=>[!/\*|\/:/.test(u[0]),...u]).sort(([u,l],[f,m])=>u?1:f?-1:l.length-m.length),n=Object.create(null);for(let u=0,l=-1,f=r.length;u<f;u++){let[m,p,b]=r[u];m?n[p]=[b.map(([x])=>[x,Object.create(null)]),de]:l++;let g;try{g=t.insert(p,l,m)}catch(x){throw x===$?new le(p):x}m||(s[l]=b.map(([x,E])=>{let S=Object.create(null);for(E-=1;E>=0;E--){let[O,v]=g[E];S[O]=v}return[x,S]}))}let[a,o,i]=t.buildRegExp();for(let u=0,l=s.length;u<l;u++)for(let f=0,m=s[u].length;f<m;f++){let p=s[u][f]?.[1];if(!p)continue;let b=Object.keys(p);for(let g=0,x=b.length;g<x;g++)p[b[g]]=i[p[b[g]]]}let c=[];for(let u in o)c[u]=s[o[u]];return[a,c,n]}function F(e,t){if(e){for(let s of Object.keys(e).sort((r,n)=>n.length-r.length))if(dt(s).test(t))return[...e[s]]}}var fe=class{name="RegExpRouter";#t;#e;constructor(){this.#t={[w]:Object.create(null)},this.#e={[w]:Object.create(null)}}add(e,t,s){let r=this.#t,n=this.#e;if(!r||!n)throw new Error(ue);r[e]||[r,n].forEach(i=>{i[e]=Object.create(null),Object.keys(i[w]).forEach(c=>{i[e][c]=[...i[w][c]]})}),t==="/*"&&(t="*");let a=(t.match(/\/:/g)||[]).length;if(/\*$/.test(t)){let i=dt(t);e===w?Object.keys(r).forEach(c=>{r[c][t]||=F(r[c],t)||F(r[w],t)||[]}):r[e][t]||=F(r[e],t)||F(r[w],t)||[],Object.keys(r).forEach(c=>{(e===w||e===c)&&Object.keys(r[c]).forEach(u=>{i.test(u)&&r[c][u].push([s,a])})}),Object.keys(n).forEach(c=>{(e===w||e===c)&&Object.keys(n[c]).forEach(u=>i.test(u)&&n[c][u].push([s,a]))});return}let o=ce(t)||[t];for(let i=0,c=o.length;i<c;i++){let u=o[i];Object.keys(n).forEach(l=>{(e===w||e===l)&&(n[l][u]||=[...F(r[l],u)||F(r[w],u)||[]],n[l][u].push([s,a-c+i+1]))})}}match=Ie;buildAllMatchers(){let e=Object.create(null);return Object.keys(this.#e).concat(Object.keys(this.#t)).forEach(t=>{e[t]||=this.#r(t)}),this.#t=this.#e=void 0,mr(),e}#r(e){let t=[],s=e===w;return[this.#t,this.#e].forEach(r=>{let n=r[e]?Object.keys(r[e]).map(a=>[a,r[e][a]]):[];n.length!==0?(s||=!0,t.push(...n)):e!==w&&t.push(...Object.keys(r[w]).map(a=>[a,r[w][a]]))}),s?gr(t):null}};var Oe=class{name="SmartRouter";#t=[];#e=[];constructor(e){this.#t=e.routers}add(e,t,s){if(!this.#e)throw new Error(ue);this.#e.push([e,t,s])}match(e,t){if(!this.#e)throw new Error("Fatal error");let s=this.#t,r=this.#e,n=s.length,a=0,o;for(;a<n;a++){let i=s[a];try{for(let c=0,u=r.length;c<u;c++)i.add(...r[c]);o=i.match(e,t)}catch(c){if(c instanceof le)continue;throw c}this.match=i.match.bind(i),this.#t=[i],this.#e=void 0;break}if(a===n)throw new Error("Fatal error");return this.name=`SmartRouter + ${this.activeRouter.name}`,o}get activeRouter(){if(this.#e||this.#t.length!==1)throw new Error("No active router has been determined yet.");return this.#t[0]}};var X=Object.create(null),ht=class ft{#t;#e;#r;#a=0;#n=X;constructor(t,s,r){if(this.#e=r||Object.create(null),this.#t=[],t&&s){let n=Object.create(null);n[t]={handler:s,possibleKeys:[],score:0},this.#t=[n]}this.#r=[]}insert(t,s,r){this.#a=++this.#a;let n=this,a=Ke(s),o=[];for(let i=0,c=a.length;i<c;i++){let u=a[i],l=a[i+1],f=Ve(u,l),m=Array.isArray(f)?f[0]:u;if(m in n.#e){n=n.#e[m],f&&o.push(f[1]);continue}n.#e[m]=new ft,f&&(n.#r.push(f),o.push(f[1])),n=n.#e[m]}return n.#t.push({[t]:{handler:r,possibleKeys:o.filter((i,c,u)=>u.indexOf(i)===c),score:this.#a}}),n}#s(t,s,r,n){let a=[];for(let o=0,i=t.#t.length;o<i;o++){let c=t.#t[o],u=c[s]||c[w],l={};if(u!==void 0&&(u.params=Object.create(null),a.push(u),r!==X||n&&n!==X))for(let f=0,m=u.possibleKeys.length;f<m;f++){let p=u.possibleKeys[f],b=l[u.score];u.params[p]=n?.[p]&&!b?n[p]:r[p]??n?.[p],l[u.score]=!0}}return a}search(t,s){let r=[];this.#n=X;let a=[this],o=ve(s),i=[];for(let c=0,u=o.length;c<u;c++){let l=o[c],f=c===u-1,m=[];for(let p=0,b=a.length;p<b;p++){let g=a[p],x=g.#e[l];x&&(x.#n=g.#n,f?(x.#e["*"]&&r.push(...this.#s(x.#e["*"],t,g.#n)),r.push(...this.#s(x,t,g.#n))):m.push(x));for(let E=0,S=g.#r.length;E<S;E++){let O=g.#r[E],v=g.#n===X?{}:{...g.#n};if(O==="*"){let P=g.#e["*"];P&&(r.push(...this.#s(P,t,g.#n)),P.#n=v,m.push(P));continue}let[R,_e,K]=O;if(!l&&!(K instanceof RegExp))continue;let A=g.#e[R],Ht=o.slice(c).join("/");if(K instanceof RegExp){let P=K.exec(Ht);if(P){if(v[_e]=P[0],r.push(...this.#s(A,t,g.#n,v)),Object.keys(A.#e).length){A.#n=v;let Dt=P[0].match(/\//)?.length??0;(i[Dt]||=[]).push(A)}continue}}(K===!0||K.test(l))&&(v[_e]=l,f?(r.push(...this.#s(A,t,v,g.#n)),A.#e["*"]&&r.push(...this.#s(A.#e["*"],t,v,g.#n))):(A.#n=v,m.push(A)))}}a=m.concat(i.shift()??[])}return r.length>1&&r.sort((c,u)=>c.score-u.score),[r.map(({handler:c,params:u})=>[c,u])]}};var Ae=class{name="TrieRouter";#t;constructor(){this.#t=new ht}add(e,t,s){let r=ce(t);if(r){for(let n=0,a=r.length;n<a;n++)this.#t.insert(e,r[n],s);return}this.#t.insert(e,t,s)}match(e,t){return this.#t.search(e,t)}};var W=class extends ot{constructor(e={}){super(e),this.router=e.router??new Oe({routers:[new fe,new Ae]})}};var pt=(e,t=wr)=>{let s=/\.([a-zA-Z0-9]+?)$/,r=e.match(s);if(!r)return;let n=t[r[1]];return n&&n.startsWith("text")&&(n+="; charset=utf-8"),n};var yr={aac:"audio/aac",avi:"video/x-msvideo",avif:"image/avif",av1:"video/av1",bin:"application/octet-stream",bmp:"image/bmp",css:"text/css",csv:"text/csv",eot:"application/vnd.ms-fontobject",epub:"application/epub+zip",gif:"image/gif",gz:"application/gzip",htm:"text/html",html:"text/html",ico:"image/x-icon",ics:"text/calendar",jpeg:"image/jpeg",jpg:"image/jpeg",js:"text/javascript",json:"application/json",jsonld:"application/ld+json",map:"application/json",mid:"audio/x-midi",midi:"audio/x-midi",mjs:"text/javascript",mp3:"audio/mpeg",mp4:"video/mp4",mpeg:"video/mpeg",oga:"audio/ogg",ogv:"video/ogg",ogx:"application/ogg",opus:"audio/opus",otf:"font/otf",pdf:"application/pdf",png:"image/png",rtf:"application/rtf",svg:"image/svg+xml",tif:"image/tiff",tiff:"image/tiff",ts:"video/mp2t",ttf:"font/ttf",txt:"text/plain",wasm:"application/wasm",webm:"video/webm",weba:"audio/webm",webmanifest:"application/manifest+json",webp:"image/webp",woff:"font/woff",woff2:"font/woff2",xhtml:"application/xhtml+xml",xml:"application/xml",zip:"application/zip","3gp":"video/3gpp","3g2":"video/3gpp2",gltf:"model/gltf+json",glb:"model/gltf-binary"},wr=yr;import{createReadStream as mt,statSync as br,existsSync as xr}from"fs";import{join as gt}from"path";import{versions as vr}from"process";import{Readable as kr}from"stream";var Er=/^\s*(?:text\/[^;\s]+|application\/(?:javascript|json|xml|xml-dtd|ecmascript|dart|postscript|rtf|tar|toml|vnd\.dart|vnd\.ms-fontobject|vnd\.ms-opentype|wasm|x-httpd-php|x-javascript|x-ns-proxy-autoconfig|x-sh|x-tar|x-virtualbox-hdd|x-virtualbox-ova|x-virtualbox-ovf|x-virtualbox-vbox|x-virtualbox-vdi|x-virtualbox-vhd|x-virtualbox-vmdk|x-www-form-urlencoded)|font\/(?:otf|ttf)|image\/(?:bmp|vnd\.adobe\.photoshop|vnd\.microsoft\.icon|vnd\.ms-dds|x-icon|x-ms-bmp)|message\/rfc822|model\/gltf-binary|x-shader\/x-fragment|x-shader\/x-vertex|[^;\s]+?\+(?:json|text|xml|yaml))(?:[;\s]|$)/i,Pe={br:".br",zstd:".zst",gzip:".gz"},Rr=Object.keys(Pe),Tr=()=>{let[e,t]=vr.node.split(".").map(s=>parseInt(s));return e>=23||e===22&&t>=7||e===20&&t>=18},Ir=Tr(),yt=e=>Ir?kr.toWeb(e):new ReadableStream({start(s){e.on("data",r=>{s.enqueue(r)}),e.on("error",r=>{s.error(r)}),e.on("end",()=>{s.close()})},cancel(){e.destroy()}}),Ce=e=>{let t;try{t=br(e)}catch{}return t},je=(e={root:""})=>{let t=e.root||"",s=e.path;return t!==""&&!xr(t)&&console.error(`serveStatic: root path '${t}' is not found, are you sure it's correct?`),async(r,n)=>{if(r.finalized)return n();let a;if(s)a=s;else try{if(a=decodeURIComponent(r.req.path),/(?:^|[\/\\])\.\.(?:$|[\/\\])/.test(a))throw new Error}catch{return await e.onNotFound?.(r.req.path,r),n()}let o=gt(t,!s&&e.rewriteRequestPath?e.rewriteRequestPath(a,r):a),i=Ce(o);if(i&&i.isDirectory()){let m=e.index??"index.html";o=gt(o,m),i=Ce(o)}if(!i)return await e.onNotFound?.(o,r),n();let c=pt(o);if(r.header("Content-Type",c||"application/octet-stream"),e.precompressed&&(!c||Er.test(c))){let m=new Set(r.req.header("Accept-Encoding")?.split(",").map(p=>p.trim()));for(let p of Rr){if(!m.has(p))continue;let b=Ce(o+Pe[p]);if(b){r.header("Content-Encoding",p),r.header("Vary","Accept-Encoding",{append:!0}),i=b,o=o+Pe[p];break}}}let u,l=i.size,f=r.req.header("range")||"";if(r.req.method=="HEAD"||r.req.method=="OPTIONS")r.header("Content-Length",l.toString()),r.status(200),u=r.body(null);else if(!f)r.header("Content-Length",l.toString()),u=r.body(yt(mt(o)),200);else{r.header("Accept-Ranges","bytes"),r.header("Date",i.birthtime.toUTCString());let m=f.replace(/bytes=/,"").split("-",2),p=parseInt(m[0],10)||0,b=parseInt(m[1],10)||l-1;l<b-p+1&&(b=l-1);let g=b-p+1,x=mt(o,{start:p,end:b});r.header("Content-Length",g.toString()),r.header("Content-Range",`bytes ${p}-${b}/${i.size}`),u=r.body(yt(x),206)}return await e.onFound?.(o,r),u}};import{spawn as Sr}from"node:child_process";function k(e){return e.startsWith("task_")&&e.length===31}function wt(e){return e.startsWith("lrn_")&&e.length===30}var j=class extends Error{constructor(s,r,n){super(s);this.exitCode=r;this.stderr=n;this.name="CliError"}},pe=class extends Error{constructor(t="CLI command timeout (30s)"){super(t),this.name="CliTimeoutError"}};var Or=3e4,Ar=process.env.OVERSEER_CLI_PATH??"os",Cr=process.env.OVERSEER_CLI_CWD??process.cwd();async function C(e){return new Promise((t,s)=>{let r=Sr(Ar,[...e,"--json"],{cwd:Cr,stdio:["ignore","pipe","pipe"]}),n=setTimeout(()=>{r.kill("SIGTERM"),s(new pe)},Or),a="",o="";r.stdout.on("data",i=>{a+=i.toString()}),r.stderr.on("data",i=>{o+=i.toString()}),r.on("error",i=>{clearTimeout(n),s(new j(`Failed to spawn os: ${i.message}`,-1,""))}),r.on("close",i=>{if(clearTimeout(n),i!==0){let c=o.trim()||`os exited with code ${i}`;s(new j(c,i??-1,o));return}try{let c=JSON.parse(a);t(c)}catch(c){s(new j(`Invalid JSON from os: ${c instanceof Error?c.message:String(c)}`,0,a))}})})}function I(e,t){return e===2?(...s)=>s.length>=2?t(s[0],s[1]):r=>t(r,s[0]):e===3?(...s)=>s.length>=3?t(s[0],s[1],s[2]):r=>t(r,s[0],s[1]):e===4?(...s)=>s.length>=4?t(s[0],s[1],s[2],s[3]):r=>t(r,s[0],s[1],s[2]):(...s)=>s.length>=e?t(...s):r=>t(r,...s)}var Pr=e=>e instanceof Error?{name:e.name,message:e.message,stack:e.stack}:e,jr=e=>e instanceof Error&&"_tag"in e&&typeof e._tag=="string",ee=Object.assign(e=>()=>{class t extends Error{_tag=e;static is(r){return r instanceof t}constructor(r){let n=r&&"message"in r&&typeof r.message=="string"?r.message:void 0,a=r&&"cause"in r?r.cause:void 0;if(super(n,a!==void 0?{cause:a}:void 0),r&&Object.assign(this,r),Object.setPrototypeOf(this,new.target.prototype),this.name=e,a instanceof Error&&a.stack){let o=a.stack.replace(/\n/g,`
|
|
3
|
-
`);this.stack=`${this.stack}
|
|
4
|
-
Caused by: ${o}`}}toJSON(){return{...this,_tag:this._tag,name:this.name,message:this.message,cause:Pr(this.cause),stack:this.stack}}}return t},{is:jr}),Jn=I(2,(e,t)=>{let s=t[e._tag];return s(e)}),Qn=I(3,(e,t,s)=>{let r=t[e._tag];return typeof r=="function"?r(e):s(e)});var vt=class extends ee("UnhandledException")(){constructor(e){let t=e.cause instanceof Error?`Unhandled exception: ${e.cause.message}`:`Unhandled exception: ${String(e.cause)}`;super({message:t,cause:e.cause})}},Lr=class extends ee("Panic")(){},_r=class extends ee("ResultDeserializationError")(){constructor(e){super({message:'Failed to deserialize value as Result: expected { status: "ok", value } or { status: "error", error }',value:e.value})}};var T=(e,t)=>{throw new Lr({message:e,cause:t})},q=(e,t)=>{try{return e()}catch(s){throw T(t,s)}},bt=async(e,t)=>{try{return await e()}catch(s){throw T(t,s)}},kt=class Et{status="ok";constructor(t){this.value=t}isOk(){return!0}isErr(){return!1}map(t){return q(()=>new Et(t(this.value)),"map callback threw")}mapError(t){return this}andThen(t){return q(()=>t(this.value),"andThen callback threw")}andThenAsync(t){return bt(()=>t(this.value),"andThenAsync callback threw")}match(t){return q(()=>t.ok(this.value),"match ok handler threw")}unwrap(t){return this.value}unwrapOr(t){return this.value}tap(t){return q(()=>(t(this.value),this),"tap callback threw")}tapAsync(t){return bt(async()=>(await t(this.value),this),"tapAsync callback threw")}*[Symbol.iterator](){return this.value}},Rt=class Tt{status="error";constructor(t){this.error=t}isOk(){return!1}isErr(){return!0}map(t){return this}mapError(t){return q(()=>new Tt(t(this.error)),"mapError callback threw")}andThen(t){return this}andThenAsync(t){return Promise.resolve(this)}match(t){return q(()=>t.err(this.error),"match err handler threw")}unwrap(t){return T(t??`Unwrap called on Err: ${String(this.error)}`,this.error)}unwrapOr(t){return t}tap(t){return this}tapAsync(t){return Promise.resolve(this)}*[Symbol.iterator](){return yield this,T("Unreachable: Err yielded in Result.gen but generator continued",this.error)}};function Z(e){return new kt(e)}var Hr=e=>e.status==="ok",z=e=>new Rt(e),Dr=e=>e.status==="error",$r=(e,t)=>{let s=()=>{if(typeof e=="function")try{return Z(e())}catch(a){return z(new vt({cause:a}))}try{return Z(e.try())}catch(a){try{return z(e.catch(a))}catch(o){throw T("Result.try catch handler threw",o)}}},r=t?.retry?.times??0,n=s();for(let a=0;a<r&&n.status==="error";a++)n=s();return n},qr=async(e,t)=>{let s=async()=>{if(typeof e=="function")try{return Z(await e())}catch(c){return z(new vt({cause:c}))}try{return Z(await e.try())}catch(c){try{return z(await e.catch(c))}catch(u){throw T("Result.tryPromise catch handler threw",u)}}},r=t?.retry;if(!r)return s();let n=c=>{switch(r.backoff){case"constant":return r.delayMs;case"linear":return r.delayMs*(c+1);case"exponential":return r.delayMs*2**c}},a=c=>new Promise(u=>setTimeout(u,c)),o=await s(),i=r.shouldRetry??(()=>!0);for(let c=0;c<r.times&&o.status==="error";c++){let u=o.error;if(!q(()=>i(u),"shouldRetry predicate threw"))break;await a(n(c)),o=await s()}return o},Mr=I(2,(e,t)=>e.map(t)),Nr=I(2,(e,t)=>e.mapError(t)),Ur=I(2,(e,t)=>e.andThen(t)),Br=I(2,(e,t)=>e.andThenAsync(t)),Fr=I(2,(e,t)=>e.match(t)),Wr=I(2,(e,t)=>e.tap(t)),zr=I(2,(e,t)=>e.tapAsync(t)),Gr=(e,t)=>e.unwrap(t);function xt(e){if(!(e!==null&&typeof e=="object"&&"status"in e&&(e.status==="ok"||e.status==="error")))return T("Result.gen body must return Result.ok() or Result.err(), got: "+(e===null?"null":typeof e=="object"?JSON.stringify(e):String(e)))}var Kr=I(2,(e,t)=>e.unwrapOr(t)),Vr=(e,t)=>{let s=e.call(t);if(Symbol.asyncIterator in s)return(async()=>{let a=s,o;try{o=await a.next()}catch(i){throw T("generator body threw",i)}if(xt(o.value),!o.done)try{await a.return?.(void 0)}catch(i){throw T("generator cleanup threw",i)}return o.value})();let r=s,n;try{n=r.next()}catch(a){throw T("generator body threw",a)}if(xt(n.value),!n.done)try{r.return?.(void 0)}catch(a){throw T("generator cleanup threw",a)}return n.value};async function*Jr(e){return yield*await e}function Qr(e){return e!==null&&typeof e=="object"&&"status"in e&&(e.status==="ok"&&"value"in e||e.status==="error"&&"error"in e)}var Yr=e=>e.status==="ok"?{status:"ok",value:e.value}:{status:"error",error:e.error},It=e=>Qr(e)?e.status==="ok"?new kt(e.value):new Rt(e.error):z(new _r({value:e})),Xr=e=>It(e),Zr=e=>{let t=[],s=[];for(let r of e)r.status==="ok"?t.push(r.value):s.push(r.error);return[t,s]},es=e=>e.status==="ok"?e.value:e,d={ok:Z,isOk:Hr,err:z,isError:Dr,try:$r,tryPromise:qr,map:Mr,mapError:Nr,andThen:Ur,andThenAsync:Br,match:Fr,tap:Wr,tapAsync:zr,unwrap:Gr,unwrapOr:Kr,gen:Vr,await:Jr,serialize:Yr,deserialize:It,hydrate:Xr,partition:Zr,flatten:es};var h=class extends ee("DecodeError")(){};function M(e){return typeof e=="object"&&e!==null&&!Array.isArray(e)}function y(e){return typeof e=="string"}function St(e){return typeof e=="boolean"}function ts(e){return typeof e=="number"}function Ot(e){return ts(e)&&e>=1&&e<=5&&Number.isInteger(e)}function rs(e){return e===0||e===1||e===2}function ss(e){if(!M(e))return d.err(new h({message:"Learning must be object"}));let{id:t,taskId:s,content:r,sourceTaskId:n,createdAt:a}=e;return!y(t)||!wt(t)?d.err(new h({message:`Invalid learning id: ${t}`})):!y(s)||!k(s)?d.err(new h({message:`Invalid learning taskId: ${s}`})):y(r)?n!==null&&(!y(n)||!k(n))?d.err(new h({message:`Invalid learning sourceTaskId: ${n}`})):y(a)?d.ok({id:t,taskId:s,content:r,sourceTaskId:n,createdAt:a}):d.err(new h({message:"Learning createdAt must be string"})):d.err(new h({message:"Learning content must be string"}))}function te(e){if(!Array.isArray(e))return d.err(new h({message:"Learnings must be array"}));let t=[];for(let s=0;s<e.length;s++){let r=ss(e[s]);if(r.isErr())return d.err(new h({message:r.error.message,path:`learnings[${s}]`}));t.push(r.value)}return d.ok(t)}function G(e){if(!M(e))return d.err(new h({message:"Task must be object"}));let{id:t,parentId:s,description:r,priority:n,completed:a,completedAt:o,startedAt:i,createdAt:c,updatedAt:u,result:l,commitSha:f,depth:m,blockedBy:p,blocks:b,bookmark:g,startCommit:x,effectivelyBlocked:E}=e;if(!y(t)||!k(t))return d.err(new h({message:`Invalid task id: ${t}`}));if(s!==null&&(!y(s)||!k(s)))return d.err(new h({message:`Invalid task parentId: ${s}`}));if(!y(r))return d.err(new h({message:"Task description must be string"}));if(!Ot(n))return d.err(new h({message:`Invalid task priority: ${n}`}));if(!St(a))return d.err(new h({message:"Task completed must be boolean"}));if(o!==null&&!y(o))return d.err(new h({message:"Task completedAt must be string or null"}));if(i!==null&&!y(i))return d.err(new h({message:"Task startedAt must be string or null"}));if(!y(c))return d.err(new h({message:"Task createdAt must be string"}));if(!y(u))return d.err(new h({message:"Task updatedAt must be string"}));if(l!==null&&!y(l))return d.err(new h({message:"Task result must be string or null"}));if(f!==null&&!y(f))return d.err(new h({message:"Task commitSha must be string or null"}));if(!rs(m))return d.err(new h({message:`Invalid task depth: ${m}`}));if(!St(E))return d.err(new h({message:"Task effectivelyBlocked must be boolean"}));let S;if(p!==void 0){if(!Array.isArray(p))return d.err(new h({message:"Task blockedBy must be array"}));S=[];for(let R of p){if(!y(R)||!k(R))return d.err(new h({message:`Invalid blocker id: ${R}`}));S.push(R)}}let O;if(b!==void 0){if(!Array.isArray(b))return d.err(new h({message:"Task blocks must be array"}));O=[];for(let R of b){if(!y(R)||!k(R))return d.err(new h({message:`Invalid blocks id: ${R}`}));O.push(R)}}if(g!==void 0&&!y(g))return d.err(new h({message:"Task bookmark must be string"}));if(x!==void 0&&!y(x))return d.err(new h({message:"Task startCommit must be string"}));let v={id:t,parentId:s,description:r,priority:n,completed:a,completedAt:o,startedAt:i,createdAt:c,updatedAt:u,result:l,commitSha:f,depth:m,effectivelyBlocked:E};return S&&(v.blockedBy=S),O&&(v.blocks=O),g!==void 0&&(v.bookmark=g),x!==void 0&&(v.startCommit=x),d.ok(v)}function At(e){if(!Array.isArray(e))return d.err(new h({message:"Tasks must be array"}));let t=[];for(let s=0;s<e.length;s++){let r=G(e[s]);if(r.isErr())return d.err(new h({message:r.error.message,path:`tasks[${s}]`}));t.push(r.value)}return d.ok(t)}function ns(e){if(!M(e))return d.err(new h({message:"TaskContext must be object"}));let{own:t,parent:s,milestone:r}=e;if(!y(t))return d.err(new h({message:"TaskContext.own must be string"}));if(s!==void 0&&!y(s))return d.err(new h({message:"TaskContext.parent must be string"}));if(r!==void 0&&!y(r))return d.err(new h({message:"TaskContext.milestone must be string"}));let n={own:t};return s!==void 0&&(n.parent=s),r!==void 0&&(n.milestone=r),d.ok(n)}function as(e){if(!M(e))return d.err(new h({message:"InheritedLearnings must be object"}));let{own:t,parent:s,milestone:r}=e,n=te(t??[]);if(n.isErr())return d.err(new h({message:n.error.message,path:"learnings.own"}));let a=te(s??[]);if(a.isErr())return d.err(new h({message:a.error.message,path:"learnings.parent"}));let o=te(r??[]);return o.isErr()?d.err(new h({message:o.error.message,path:"learnings.milestone"})):d.ok({own:n.value,parent:a.value,milestone:o.value})}function Le(e){if(!M(e))return d.err(new h({message:"TaskWithContext must be object"}));let t=G(e);if(t.isErr())return t;let{context:s,learnings:r}=e,n=ns(s);if(n.isErr())return d.err(new h({message:n.error.message,path:"context"}));let a=as(r);return a.isErr()?d.err(new h({message:a.error.message,path:"learnings"})):d.ok({...t.value,context:n.value,learnings:a.value})}function Ct(e){return e===null?d.ok(null):Le(e)}function Pt(e){if(!M(e))return d.err(new h({message:"UpdateTaskRequest must be object"}));let{description:t,context:s,priority:r}=e,n={};if(t!==void 0){if(!y(t))return d.err(new h({message:"description must be string"}));n.description=t}if(s!==void 0){if(!y(s))return d.err(new h({message:"context must be string"}));n.context=s}if(r!==void 0){if(!Ot(r))return d.err(new h({message:`Invalid priority: ${r}`}));n.priority=r}return d.ok(n)}function jt(e){if(!M(e))return d.err(new h({message:"CompleteTaskRequest must be object"}));let{result:t,learnings:s}=e,r={};if(t!==void 0){if(!y(t))return d.err(new h({message:"result must be string"}));r.result=t}if(s!==void 0){if(!Array.isArray(s))return d.err(new h({message:"learnings must be array"}));for(let n=0;n<s.length;n++)if(!y(s[n]))return d.err(new h({message:`learnings[${n}] must be string`}));r.learnings=s}return d.ok(r)}function L(e,t){if(t instanceof j){let r=t.message.toLowerCase();return r.includes("not found")||r.includes("no task")?e.json({error:t.message},404):r.includes("invalid")||r.includes("validation")||r.includes("cycle")?e.json({error:t.message},400):r.includes("not a repository")||r.includes("dirty working copy")?e.json({error:t.message,code:"VCS_ERROR"},400):e.json({error:t.message},500)}let s=t instanceof Error?t.message:String(t);return e.json({error:s},500)}var Lt=new W().get("/",async e=>{let t=e.req.query("parentId"),s=e.req.query("ready"),r=e.req.query("completed"),n=["task","list"];if(t){if(!k(t))return e.json({error:`Invalid parentId: ${t}`},400);n.push("--parent",t)}s==="true"&&n.push("--ready"),r==="true"&&n.push("--completed");try{let a=At(await C(n)).unwrap("GET /api/tasks");return e.json(a)}catch(a){return L(e,a)}}).get("/next-ready",async e=>{let t=e.req.query("milestoneId"),s=["task","next-ready"];if(t){if(!k(t))return e.json({error:`Invalid milestoneId: ${t}`},400);s.push("--milestone",t)}try{let r=Ct(await C(s)).unwrap("GET /api/tasks/next-ready");return r===null?e.json(null,200):e.json(r)}catch(r){return L(e,r)}}).get("/:id",async e=>{let t=e.req.param("id");if(!k(t))return e.json({error:`Invalid task ID: ${t}`},400);try{let s=Le(await C(["task","get",t])).unwrap("GET /api/tasks/:id");return e.json(s)}catch(s){return L(e,s)}}).put("/:id",async e=>{let t=e.req.param("id");if(!k(t))return e.json({error:`Invalid task ID: ${t}`},400);let s;try{s=Pt(await e.req.json()).unwrap("PUT /api/tasks/:id body")}catch{return e.json({error:"Invalid JSON body"},400)}let r=["task","update",t];if(s.description&&r.push("-d",s.description),s.context&&r.push("--context",s.context),s.priority&&r.push("--priority",String(s.priority)),r.length===3)return e.json({error:"No fields to update"},400);try{let n=G(await C(r)).unwrap("PUT /api/tasks/:id");return e.json(n)}catch(n){return L(e,n)}}).delete("/:id",async e=>{let t=e.req.param("id");if(!k(t))return e.json({error:`Invalid task ID: ${t}`},400);try{return await C(["task","delete",t]),e.json({deleted:!0})}catch(s){return L(e,s)}}).post("/:id/complete",async e=>{let t=e.req.param("id");if(!k(t))return e.json({error:`Invalid task ID: ${t}`},400);let s;try{let n=await e.req.text();n?s=jt(JSON.parse(n)).unwrap("POST /api/tasks/:id/complete body"):s={}}catch{return e.json({error:"Invalid JSON body"},400)}let r=["task","complete",t];if(s.result&&r.push("--result",s.result),s.learnings)for(let n of s.learnings)r.push("--learning",n);try{let n=G(await C(r)).unwrap("POST /api/tasks/:id/complete");return e.json(n)}catch(n){return L(e,n)}}).post("/:id/reopen",async e=>{let t=e.req.param("id");if(!k(t))return e.json({error:`Invalid task ID: ${t}`},400);try{let s=G(await C(["task","reopen",t])).unwrap("POST /api/tasks/:id/reopen");return e.json(s)}catch(s){return L(e,s)}}).get("/:taskId/learnings",async e=>{let t=e.req.param("taskId");if(!k(t))return e.json({error:`Invalid task ID: ${t}`},400);try{let s=te(await C(["learning","list",t])).unwrap("GET /api/tasks/:taskId/learnings");return e.json(s)}catch(s){return L(e,s)}});var os=new W().get("/health",e=>e.json({status:"ok"})).route("/api/tasks",Lt).all("/api/*",e=>e.json({error:"Not found"},404));function _t(e){let t=e??process.env.OVERSEER_UI_STATIC_ROOT??"./static";return new W().route("/",os).use("/*",je({root:t})).get("/*",je({root:t,path:"index.html"}))}var is=process.env.PORT===void 0?6969:Number.parseInt(process.env.PORT,10)||6969,cs=process.env.OVERSEER_UI_STATIC_ROOT??"./dist",us=_t(cs);We({fetch:us.fetch,port:is},e=>{console.log(`Overseer UI: http://localhost:${e.port}`)});
|
|
5
|
-
//# sourceMappingURL=server.js.map
|