diff --git a/docs/index.html b/docs/index.html index d4233b4..41884c5 100644 --- a/docs/index.html +++ b/docs/index.html @@ -54,7 +54,8 @@
diff --git a/docs/telegram-bot-playground/assets/index-D5yhjlgw.js b/docs/telegram-bot-playground/assets/index-D5yhjlgw.js new file mode 100644 index 0000000..c71cf6c --- /dev/null +++ b/docs/telegram-bot-playground/assets/index-D5yhjlgw.js @@ -0,0 +1,26 @@ +var Ro=Object.defineProperty;var $r=e=>{throw TypeError(e)};var Po=(e,t,n)=>t in e?Ro(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n;var d=(e,t,n)=>Po(e,typeof t!="symbol"?t+"":t,n),Nr=(e,t,n)=>t.has(e)||$r("Cannot "+n);var Rr=(e,t,n)=>(Nr(e,t,"read from private field"),n?n.call(e):t.get(e)),Pr=(e,t,n)=>t.has(e)?$r("Cannot add the same private member more than once"):t instanceof WeakSet?t.add(e):t.set(e,n),jr=(e,t,n,r)=>(Nr(e,t,"write to private field"),r?r.call(e,n):t.set(e,n),n);(function(){const t=document.createElement("link").relList;if(t&&t.supports&&t.supports("modulepreload"))return;for(const i of document.querySelectorAll('link[rel="modulepreload"]'))r(i);new MutationObserver(i=>{for(const s of i)if(s.type==="childList")for(const o of s.addedNodes)o.tagName==="LINK"&&o.rel==="modulepreload"&&r(o)}).observe(document,{childList:!0,subtree:!0});function n(i){const s={};return i.integrity&&(s.integrity=i.integrity),i.referrerPolicy&&(s.referrerPolicy=i.referrerPolicy),i.crossOrigin==="use-credentials"?s.credentials="include":i.crossOrigin==="anonymous"?s.credentials="omit":s.credentials="same-origin",s}function r(i){if(i.ep)return;i.ep=!0;const s=n(i);fetch(i.href,s)}})();const jo="modulepreload",Lo=function(e,t){return new URL(e,t).href},Lr={},Fo=function(t,n,r){let i=Promise.resolve();if(n&&n.length>0){const o=document.getElementsByTagName("link"),a=document.querySelector("meta[property=csp-nonce]"),c=(a==null?void 0:a.nonce)||(a==null?void 0:a.getAttribute("nonce"));i=Promise.allSettled(n.map(u=>{if(u=Lo(u,r),u in Lr)return;Lr[u]=!0;const l=u.endsWith(".css"),f=l?'[rel="stylesheet"]':"";if(!!r)for(let k=o.length-1;k>=0;k--){const R=o[k];if(R.href===u&&(!l||R.rel==="stylesheet"))return}else if(document.querySelector(`link[href="${u}"]${f}`))return;const _=document.createElement("link");if(_.rel=l?"stylesheet":jo,l||(_.as="script"),_.crossOrigin="",_.href=u,c&&_.setAttribute("nonce",c),document.head.appendChild(_),l)return new Promise((k,R)=>{_.addEventListener("load",k),_.addEventListener("error",()=>R(new Error(`Unable to preload CSS for ${u}`)))})}))}function s(o){const a=new Event("vite:preloadError",{cancelable:!0});if(a.payload=o,window.dispatchEvent(a),!a.defaultPrevented)throw o}return i.then(o=>{for(const a of o||[])a.status==="rejected"&&s(a.reason);return t().catch(s)})},Bo=e=>typeof e=="function",g=function(e,t){if(typeof e=="function")return function(){return e(arguments)?t.apply(this,arguments):n=>t(n,...arguments)};switch(e){case 0:case 1:throw new RangeError(`Invalid arity ${e}`);case 2:return function(n,r){return arguments.length>=2?t(n,r):function(i){return t(i,n)}};case 3:return function(n,r,i){return arguments.length>=3?t(n,r,i):function(s){return t(s,n,r)}};case 4:return function(n,r,i,s){return arguments.length>=4?t(n,r,i,s):function(o){return t(o,n,r,i)}};case 5:return function(n,r,i,s,o){return arguments.length>=5?t(n,r,i,s,o):function(a){return t(a,n,r,i,s)}};default:return function(){if(arguments.length>=e)return t.apply(this,arguments);const n=arguments;return function(r){return t(r,...n)}}}},fe=e=>e,Un=e=>()=>e,Fr=Un(!0),Br=Un(!1),wi=Un(void 0),Do=wi;function C(e,t,n,r,i,s,o,a,c){switch(arguments.length){case 1:return e;case 2:return t(e);case 3:return n(t(e));case 4:return r(n(t(e)));case 5:return i(r(n(t(e))));case 6:return s(i(r(n(t(e)))));case 7:return o(s(i(r(n(t(e))))));case 8:return a(o(s(i(r(n(t(e)))))));case 9:return c(a(o(s(i(r(n(t(e))))))));default:{let u=arguments[0];for(let l=1;l(t,n)=>t===n||e(t,n);let Ho="3.12.6";const Si=()=>Ho,ht=`effect/GlobalValue/globalStoreId/${Si()}`;let De;const Ne=(e,t)=>(De||(globalThis[ht]??(globalThis[ht]=new Map),De=globalThis[ht]),De.has(e)||De.set(e,t()),De.get(e)),zn=Bo,Uo=e=>typeof e=="object"&&e!==null,xi=e=>Uo(e)||zn(e),N=g(2,(e,t)=>xi(e)&&t in e),zo=g(2,(e,t)=>N(e,"_tag")&&e._tag===t),Kn=e=>`BUG: ${e} - please report an issue at https://github.com/Effect-TS/effect/issues`;let Ei=class ki{constructor(t){d(this,"self");d(this,"called",!1);this.self=t}next(t){return this.called?{value:t,done:!0}:(this.called=!0,{value:this.self,done:!1})}return(t){return{value:t,done:!0}}throw(t){throw t}[Symbol.iterator](){return new ki(this.self)}};const fn=Symbol.for("effect/Utils/YieldWrap");var ot;class Ft{constructor(t){Pr(this,ot);jr(this,ot,t)}[fn](){return Rr(this,ot)}}ot=new WeakMap;function Ko(e){if(typeof e=="object"&&e!==null&&fn in e)return e[fn]();throw new Error(Kn("yieldWrapGet"))}const L=Ne("effect/Utils/isStructuralRegion",()=>({enabled:!1,tester:void 0})),tn=Ne(Symbol.for("effect/Hash/randomHashCache"),()=>new WeakMap),E=Symbol.for("effect/Hash"),w=e=>{if(L.enabled===!0)return 0;switch(typeof e){case"number":return Wn(e);case"bigint":return X(e.toString(10));case"boolean":return X(String(e));case"symbol":return X(String(e));case"string":return X(e);case"undefined":return X("undefined");case"function":case"object":return e===null?X("null"):e instanceof Date?w(e.toISOString()):qo(e)?e[E]():qn(e);default:throw new Error(`BUG: unhandled typeof ${typeof e} - please report an issue at https://github.com/Effect-TS/effect/issues`)}},qn=e=>(tn.has(e)||tn.set(e,Wn(Math.floor(Math.random()*Number.MAX_SAFE_INTEGER))),tn.get(e)),G=e=>t=>t*53^e,Bt=e=>e&3221225471|e>>>1&1073741824,qo=e=>N(e,E),Wn=e=>{if(e!==e||e===1/0)return 0;let t=e|0;for(t!==e&&(t^=e*4294967295);e>4294967295;)t^=e/=4294967295;return Bt(t)},X=e=>{let t=5381,n=e.length;for(;n;)t=t*33^e.charCodeAt(--n);return Bt(t)},Wo=(e,t)=>{let n=12289;for(let r=0;rWo(e,Object.keys(e)),Go=e=>{let t=6151;for(let n=0;nEt(e,arguments[0]):Et(arguments[0],arguments[1])}function Et(e,t){if(e===t)return!0;const n=typeof e;if(n!==typeof t)return!1;if(n==="object"||n==="function"){if(e!==null&&t!==null){if(Dr(e)&&Dr(t))return w(e)===w(t)&&e[I](t)?!0:L.enabled&&L.tester?L.tester(e,t):!1;if(e instanceof Date&&t instanceof Date)return e.toISOString()===t.toISOString()}if(L.enabled){if(Array.isArray(e)&&Array.isArray(t))return e.length===t.length&&e.every((r,i)=>Et(r,t[i]));if(Object.getPrototypeOf(e)===Object.prototype&&Object.getPrototypeOf(e)===Object.prototype){const r=Object.keys(e),i=Object.keys(t);if(r.length===i.length){for(const s of r)if(!(s in t&&Et(e[s],t[s])))return L.tester?L.tester(e,t):!1;return!0}}return L.tester?L.tester(e,t):!1}}return L.enabled&&L.tester?L.tester(e,t):!1}const Dr=e=>N(e,I),P=Symbol.for("nodejs.util.inspect.custom"),M=e=>{try{if(N(e,"toJSON")&&zn(e.toJSON)&&e.toJSON.length===0)return e.toJSON();if(Array.isArray(e))return e.map(M)}catch{return{}}return Xo(e)},J=e=>JSON.stringify(e,null,2),Yo=(e,t=2)=>{if(typeof e=="string")return e;try{return typeof e=="object"?Ci(e,t):String(e)}catch{return String(e)}},Ci=(e,t)=>{let n=[];const r=JSON.stringify(e,(i,s)=>typeof s=="object"&&s!==null?n.includes(s)?void 0:n.push(s)&&(kt.fiberRefs!==void 0&&Oi(s)?s[Vn](kt.fiberRefs):s):s,t);return n=void 0,r},Vn=Symbol.for("effect/Inspectable/Redactable"),Oi=e=>typeof e=="object"&&e!==null&&Vn in e,kt=Ne("effect/Inspectable/redactableState",()=>({fiberRefs:void 0})),Xo=e=>Oi(e)&&kt.fiberRefs!==void 0?e[Vn](kt.fiberRefs):e,Y=(e,t)=>{switch(t.length){case 0:return e;case 1:return t[0](e);case 2:return t[1](t[0](e));case 3:return t[2](t[1](t[0](e)));case 4:return t[3](t[2](t[1](t[0](e))));case 5:return t[4](t[3](t[2](t[1](t[0](e)))));case 6:return t[5](t[4](t[3](t[2](t[1](t[0](e))))));case 7:return t[6](t[5](t[4](t[3](t[2](t[1](t[0](e)))))));case 8:return t[7](t[6](t[5](t[4](t[3](t[2](t[1](t[0](e))))))));case 9:return t[8](t[7](t[6](t[5](t[4](t[3](t[2](t[1](t[0](e)))))))));default:{let n=e;for(let r=0,i=t.length;re,_E:e=>e,_A:e=>e,_V:Si()},sa={_A:e=>e,_In:e=>e,_L:e=>e,_E:e=>e,_R:e=>e},oa={_Env:e=>e,_InErr:e=>e,_InElem:e=>e,_InDone:e=>e,_OutErr:e=>e,_OutElem:e=>e,_OutDone:e=>e},at={[ta]:Ge,[na]:Ge,[ra]:sa,[ia]:oa,[I](e){return this===e},[E](){return U(this,qn(this))},[Symbol.iterator](){return new Ei(new Ft(this))},pipe(){return Y(this,arguments)}},aa={[E](){return U(this,Vo(this))},[I](e){const t=Object.keys(this),n=Object.keys(e);if(t.length!==n.length)return!1;for(const r of t)if(!(r in e&&$(this[r],e[r])))return!1;return!0}},ca={...at,_op:Zo},ua={...ca,...aa},Ai=Symbol.for("effect/Option"),Ii={...at,[Ai]:{_A:e=>e},[P](){return this.toJSON()},toString(){return J(this.toJSON())}},la=Object.assign(Object.create(Ii),{_tag:"Some",_op:"Some",[I](e){return Mi(e)&&$i(e)&&$(this.value,e.value)},[E](){return U(this,G(w(this._tag))(w(this.value)))},toJSON(){return{_id:"Option",_tag:this._tag,value:M(this.value)}}}),fa=w("None"),da=Object.assign(Object.create(Ii),{_tag:"None",_op:"None",[I](e){return Mi(e)&&Ti(e)},[E](){return fa},toJSON(){return{_id:"Option",_tag:this._tag}}}),Mi=e=>N(e,Ai),Ti=e=>e._tag==="None",$i=e=>e._tag==="Some",ha=Object.create(da),pa=e=>{const t=Object.create(la);return t.value=e,t},Ni=Symbol.for("effect/Either"),Ri={...at,[Ni]:{_R:e=>e},[P](){return this.toJSON()},toString(){return J(this.toJSON())}},_a=Object.assign(Object.create(Ri),{_tag:"Right",_op:"Right",[I](e){return Pi(e)&&ma(e)&&$(this.right,e.right)},[E](){return G(w(this._tag))(w(this.right))},toJSON(){return{_id:"Either",_tag:this._tag,right:M(this.right)}}}),ga=Object.assign(Object.create(Ri),{_tag:"Left",_op:"Left",[I](e){return Pi(e)&&ya(e)&&$(this.left,e.left)},[E](){return G(w(this._tag))(w(this.left))},toJSON(){return{_id:"Either",_tag:this._tag,left:M(this.left)}}}),Pi=e=>N(e,Ni),ya=e=>e._tag==="Left",ma=e=>e._tag==="Right",ba=e=>{const t=Object.create(ga);return t.left=e,t},va=e=>{const t=Object.create(_a);return t.right=e,t},pt=va,Jr=ba,D=()=>ha,Ye=pa,V=Ti,Xe=$i,wa=g(2,(e,t)=>V(e)?t():e.value),Sa=wa(wi),xa=e=>Array.isArray(e)?e:Array.from(e),Hr=e=>Array.from(e).reverse(),Ea=g(3,(e,t,n)=>xa(e).reduce((r,i,s)=>n(r,i,s),t)),ka=Symbol.for("effect/Context/Tag"),dn=Symbol.for("effect/Context/Reference"),Ca="effect/STM",Oa=Symbol.for(Ca),ji={...at,_op:"Tag",[Oa]:Ge,[ka]:{_Service:e=>e,_Identifier:e=>e},toString(){return J(this.toJSON())},toJSON(){return{_id:"Tag",key:this.key,stack:this.stack}},[P](){return this.toJSON()},of(e){return e},context(e){return Ra(this,e)}},Aa={...ji,[dn]:dn},Ia=e=>()=>{const t=Error.stackTraceLimit;Error.stackTraceLimit=2;const n=new Error;Error.stackTraceLimit=t;function r(){}return Object.setPrototypeOf(r,ji),r.key=e,Object.defineProperty(r,"stack",{get(){return n.stack}}),r},Ma=()=>(e,t)=>{const n=Error.stackTraceLimit;Error.stackTraceLimit=2;const r=new Error;Error.stackTraceLimit=n;function i(){}return Object.setPrototypeOf(i,Aa),i.key=e,i.defaultValue=t.defaultValue,Object.defineProperty(i,"stack",{get(){return r.stack}}),i},Li=Symbol.for("effect/Context"),Ta={[Li]:{_Services:e=>e},[I](e){if(Na(e)&&this.unsafeMap.size===e.unsafeMap.size){for(const t of this.unsafeMap.keys())if(!e.unsafeMap.has(t)||!$(this.unsafeMap.get(t),e.unsafeMap.get(t)))return!1;return!0}return!1},[E](){return U(this,Wn(this.unsafeMap.size))},pipe(){return Y(this,arguments)},toString(){return J(this.toJSON())},toJSON(){return{_id:"Context",services:Array.from(this.unsafeMap).map(M)}},[P](){return this.toJSON()}},Fi=e=>{const t=Object.create(Ta);return t.unsafeMap=e,t},$a=e=>{const t=new Error(`Service not found${e.key?`: ${String(e.key)}`:""}`);if(e.stack){const n=e.stack.split(` +`);if(n.length>2){const r=n[2].match(/at (.*)/);r&&(t.message=t.message+` (defined at ${r[1]})`)}}if(t.stack){const n=t.stack.split(` +`);n.splice(1,3),t.stack=n.join(` +`)}return t},Na=e=>N(e,Li),Ra=(e,t)=>Fi(new Map([[e.key,t]])),Pa=g(3,(e,t,n)=>{const r=new Map(e.unsafeMap);return r.set(t.key,n),Fi(r)}),nn=Ne("effect/Context/defaultValueCache",()=>new Map),Bi=e=>{if(nn.has(e.key))return nn.get(e.key);const t=e.defaultValue();return nn.set(e.key,t),t},ja=(e,t)=>e.unsafeMap.has(t.key)?e.unsafeMap.get(t.key):Bi(t),La=g(2,(e,t)=>{if(!e.unsafeMap.has(t.key)){if(dn in t)return Bi(t);throw $a(t)}return e.unsafeMap.get(t.key)}),Fa=Pa,Ba=La,ct=Ia,Di=Ma,Da=at,Ji=Symbol.for("effect/Micro"),Ct=Symbol.for("effect/Micro/MicroExit"),Ze=e=>typeof e=="object"&&e!==null&&Ji in e,Ur=Symbol.for("effect/Micro/MicroCause"),Ja={_E:fe};var yi;class Gn extends globalThis.Error{constructor(n,r,i){const s=`MicroCause.${n}`;let o,a,c;if(r instanceof globalThis.Error){o=`(${s}) ${r.name}`,a=r.message;const u=a.split(` +`).length;c=r.stack?`(${s}) ${r.stack.split(` +`).slice(0,u+3).join(` +`)}`:`${o}: ${a}`}else o=s,a=Yo(r,0),c=`${o}: ${a}`;i.length>0&&(c+=` + ${i.join(` + `)}`);super(a);d(this,"_tag");d(this,"traces");d(this,yi);this._tag=n,this.traces=i,this[Ur]=Ja,this.name=o,this.stack=c}pipe(){return Y(this,arguments)}toString(){return this.stack}[(yi=Ur,P)](){return this.stack}}class Ha extends Gn{constructor(n,r=[]){super("Fail",n,r);d(this,"error");this.error=n}}const Ua=(e,t=[])=>new Ha(e,t);class za extends Gn{constructor(n,r=[]){super("Die",n,r);d(this,"defect");this.defect=n}}const Ka=(e,t=[])=>new za(e,t);class qa extends Gn{constructor(t=[]){super("Interrupt","interrupted",t)}}const Wa=(e=[])=>new qa(e),Hi=e=>e._tag==="Interrupt",zr=Symbol.for("effect/Micro/MicroFiber"),Va={_A:fe,_E:fe};var mi;mi=zr;class Ui{constructor(t,n=!0){d(this,"context");d(this,"interruptible");d(this,mi);d(this,"_stack",[]);d(this,"_observers",[]);d(this,"_exit");d(this,"_children");d(this,"currentOpCount",0);d(this,"_interrupted",!1);d(this,"_yielded");this.context=t,this.interruptible=n,this[zr]=Va}getRef(t){return ja(this.context,t)}addObserver(t){return this._exit?(t(this._exit),Do):(this._observers.push(t),()=>{const n=this._observers.indexOf(t);n>=0&&this._observers.splice(n,1)})}unsafeInterrupt(){this._exit||(this._interrupted=!0,this.interruptible&&this.evaluate(Xn))}unsafePoll(){return this._exit}evaluate(t){if(this._exit)return;if(this._yielded!==void 0){const i=this._yielded;this._yielded=void 0,i()}const n=this.runLoop(t);if(n===Se)return;const r=Kr.interruptChildren&&Kr.interruptChildren(this);if(r!==void 0)return this.evaluate(B(r,()=>n));this._exit=n;for(let i=0;ii)}if(r=r[hn](this),r===Se){const i=this._yielded;return Ct in i?(this._yielded=void 0,i):Se}}}catch(i){return N(r,hn)?It(i):It(`MicroFiber.runLoop: Not a valid effect: ${String(r)}`)}}getCont(t){for(;;){const n=this._stack.pop();if(!n)return;const r=n[Ot]&&n[Ot](this);if(r)return{[t]:r};if(n[t])return n}}yieldWith(t){return this._yielded=t,Se}children(){return this._children??(this._children=new Set)}}const Kr=Ne("effect/Micro/fiberMiddleware",()=>({interruptChildren:void 0})),Ga=e=>Gi(t=>At(e.addObserver(n=>t(z(n))))),Ya=e=>Yn(()=>(e.unsafeInterrupt(),sc(Ga(e)))),zi=Symbol.for("effect/Micro/identifier"),b=Symbol.for("effect/Micro/args"),hn=Symbol.for("effect/Micro/evaluate"),Q=Symbol.for("effect/Micro/successCont"),ke=Symbol.for("effect/Micro/failureCont"),Ot=Symbol.for("effect/Micro/ensureCont"),Se=Symbol.for("effect/Micro/Yield"),Xa={_A:fe,_E:fe,_R:fe},Za={...Da,_op:"Micro",[Ji]:Xa,pipe(){return Y(this,arguments)},[Symbol.iterator](){return new Ei(new Ft(this))},toJSON(){return{_id:"Micro",op:this[zi],...b in this?{args:this[b]}:void 0}},toString(){return J(this)},[P](){return J(this)}};function Qa(e){return It("Micro.evaluate: Not implemented")}const Dt=e=>({...Za,[zi]:e.op,[hn]:e.eval??Qa,[Q]:e.contA,[ke]:e.contE,[Ot]:e.ensure}),oe=e=>{const t=Dt(e);return function(){const n=Object.create(t);return n[b]=e.single===!1?arguments:arguments[0],n}},Ki=e=>{const t={...Dt(e),[Ct]:Ct,_tag:e.op,get[e.prop](){return this[b]},toJSON(){return{_id:"MicroExit",_tag:e.op,[e.prop]:this[b]}},[I](n){return uc(n)&&n._tag===e.op&&$(this[b],n[b])},[E](){return U(this,G(X(e.op))(w(this[b])))}};return function(n){const r=Object.create(t);return r[b]=n,r[Q]=void 0,r[ke]=void 0,r[Ot]=void 0,r}},z=Ki({op:"Success",prop:"value",eval(e){const t=e.getCont(Q);return t?t[Q](this[b],e):e.yieldWith(this)}}),Qe=Ki({op:"Failure",prop:"cause",eval(e){let t=e.getCont(ke);for(;Hi(this[b])&&t&&e.interruptible;)t=e.getCont(ke);return t?t[ke](this[b],e):e.yieldWith(this)}}),et=e=>Qe(Ua(e)),At=oe({op:"Sync",eval(e){const t=this[b](),n=e.getCont(Q);return n?n[Q](t,e):e.yieldWith(Jt(t))}}),Yn=oe({op:"Suspend",eval(e){return this[b]()}}),ec=oe({op:"Yield",eval(e){let t=!1;return e.getRef(zt).scheduleTask(()=>{t||e.evaluate(Zn)},this[b]??0),e.yieldWith(()=>{t=!0})}}),qi=ec(0),Wi=z(void 0),pn=e=>Vi(function(t,n){try{e.try(n).then(r=>t(z(r)),r=>t(et(e.catch(r))))}catch(r){t(et(e.catch(r)))}},e.try.length!==0),ut=oe({op:"WithMicroFiber",eval(e){return this[b](e)}}),Vi=oe({op:"Async",single:!1,eval(e){const t=this[b][0];let n=!1,r=!1;const i=this[b][1]?new AbortController:void 0,s=t(o=>{n||(n=!0,r?e.evaluate(o):r=o)},i==null?void 0:i.signal);return r!==!1?r:(r=!0,e._yielded=()=>{n=!0},i===void 0&&s===void 0||e._stack.push(tc(()=>(n=!0,i==null||i.abort(),s??Zn))),Se)}}),tc=oe({op:"AsyncFinalizer",ensure(e){e.interruptible&&(e.interruptible=!1,e._stack.push(er(!0)))},contE(e,t){return Hi(e)?B(this[b](),()=>Qe(e)):Qe(e)}}),Gi=e=>Vi(e,e.length>=2),ye=(...e)=>Yn(()=>nc(e.length===1?e[0]():e[1].call(e[0]))),nc=oe({op:"Iterator",contA(e,t){const n=this[b].next(e);return n.done?z(n.value):(t._stack.push(this),Ko(n.value))},eval(e){return this[Q](void 0,e)}}),rc=g(2,(e,t)=>cc(e,n=>t)),Yi=g(2,(e,t)=>B(e,n=>{const r=Ze(t)?t:typeof t=="function"?t(n):t;return Ze(r)?r:z(r)})),ic=g(2,(e,t)=>B(e,n=>{const r=Ze(t)?t:typeof t=="function"?t(n):t;return Ze(r)?rc(r,n):z(n)})),sc=e=>B(e,t=>Zn),oc=e=>yc(e,{onFailure:Ht,onSuccess:Jt}),B=g(2,(e,t)=>{const n=Object.create(ac);return n[b]=e,n[Q]=t,n}),ac=Dt({op:"OnSuccess",eval(e){return e._stack.push(this),this[b]}}),cc=g(2,(e,t)=>B(e,n=>z(t(n)))),uc=e=>N(e,Ct),Jt=z,Ht=Qe,Xn=Ht(Wa()),It=e=>Ht(Ka(e)),Zn=Jt(void 0),lc="setImmediate"in globalThis?globalThis.setImmediate:e=>setTimeout(e,0);class Qn{constructor(){d(this,"tasks",[]);d(this,"running",!1);d(this,"afterScheduled",()=>{this.running=!1,this.runTasks()})}scheduleTask(t,n){this.tasks.push(t),this.running||(this.running=!0,lc(this.afterScheduled))}runTasks(){const t=this.tasks;this.tasks=[];for(let n=0,r=t.length;n=t.getRef(hc)}flush(){for(;this.tasks.length>0;)this.runTasks()}}const Ut=e=>ut(t=>z(Ba(t.context,e))),fc=g(2,(e,t)=>ut(n=>{const r=n.context;return n.context=t(r),bc(e,()=>(n.context=r,Wi))})),wt=g(3,(e,t,n)=>fc(e,Fa(t,n))),dc=g(3,(e,t,n)=>B(n,r=>wt(e,t,r)));class hc extends Di()("effect/Micro/currentMaxOpsBeforeYield",{defaultValue:()=>2048}){}class zt extends Di()("effect/Micro/currentScheduler",{defaultValue:()=>new Qn}){}const pc=g(2,(e,t)=>Yn(()=>{const n=t.schedule?Date.now():0;let r=0;const i=B(oc(e),s=>{if(t.while!==void 0&&!t.while(s))return s;if(t.times!==void 0&&r>=t.times)return s;r++;let o=qi;if(t.schedule!==void 0){const a=Date.now()-n,c=t.schedule(r,a);if(V(c))return s;o=Zi(c.value)}return B(o,()=>i)});return i})),_c=g(e=>Ze(e[0]),(e,t)=>pc(e,{...t,while:n=>n._tag==="Success"&&((t==null?void 0:t.while)===void 0||t.while(n.value))})),Xi=g(2,(e,t)=>{const n=Object.create(gc);return n[b]=e,n[Q]=t.onSuccess,n[ke]=t.onFailure,n}),gc=Dt({op:"OnSuccessAndFailure",eval(e){return e._stack.push(this),this[b]}}),yc=g(2,(e,t)=>Xi(e,{onFailure:n=>At(()=>t.onFailure(n)),onSuccess:n=>At(()=>t.onSuccess(n))})),Zi=e=>Gi(t=>{const n=setTimeout(()=>{t(Wi)},e);return At(()=>{clearTimeout(n)})}),mc=g(2,(e,t)=>Yi(Zi(t),e)),bc=g(2,(e,t)=>wc(n=>Xi(n(e),{onFailure:r=>B(t(Ht(r)),()=>Qe(r)),onSuccess:r=>B(t(Jt(r)),()=>z(r))}))),er=oe({op:"SetInterruptible",ensure(e){if(e.interruptible=this[b],e._interrupted&&e.interruptible)return()=>Xn}}),vc=e=>ut(t=>t.interruptible?e:(t.interruptible=!0,t._stack.push(er(!1)),t._interrupted?Xn:e)),wc=e=>ut(t=>t.interruptible?(t.interruptible=!1,t._stack.push(er(!0)),e(vc)):e(fe)),Sc=(e,t,n=!1,r=!1)=>{const i=new Ui(e.context,e.interruptible);return r||(e.children().add(i),i.addObserver(()=>e.children().delete(i))),n?i.evaluate(t):e.getRef(zt).scheduleTask(()=>i.evaluate(t),0),i},xc=e=>ut(t=>z(Sc(t,e,!1,!0))),Qi=(e,t)=>{const n=new Ui(zt.context((t==null?void 0:t.scheduler)??new Qn));if(n.evaluate(e),t!=null&&t.signal)if(t.signal.aborted)n.unsafeInterrupt();else{const r=()=>n.unsafeInterrupt();t.signal.addEventListener("abort",r,{once:!0}),n.addObserver(()=>t.signal.removeEventListener("abort",r))}return n},Ec=(e,t)=>new Promise((n,r)=>{Qi(e,t).addObserver(n)}),qr=(e,t)=>Ec(e,t).then(n=>{if(n._tag==="Failure")throw n.cause;return n.value}),kc=e=>{const t=new Qn,n=Qi(e,{scheduler:t});return t.flush(),n._exit??It(n)},Cc=e=>{const t=kc(e);if(t._tag==="Failure")throw t.cause;return t.value},Oc=e=>{let t=e[0];for(let n=1;nJo((t,n)=>t.length===n.length&&Ke(t).every((r,i)=>e(r,Ce(n,i)))),Mc=Ic($),Tc={[es]:{_A:e=>e},toString(){return J(this.toJSON())},toJSON(){return{_id:"Chunk",values:Ke(this).map(M)}},[P](){return this.toJSON()},[I](e){return $c(e)&&Mc(this,e)},[E](){return U(this,Go(Ke(this)))},[Symbol.iterator](){switch(this.backing._tag){case"IArray":return this.backing.array[Symbol.iterator]();case"IEmpty":return ts[Symbol.iterator]();default:return Ke(this)[Symbol.iterator]()}},pipe(){return Y(this,arguments)}},A=e=>{const t=Object.create(Tc);switch(t.backing=e,e._tag){case"IEmpty":{t.length=0,t.depth=0,t.left=t,t.right=t;break}case"IConcat":{t.length=e.left.length+e.right.length,t.depth=1+Math.max(e.left.depth,e.right.depth),t.left=e.left,t.right=e.right;break}case"IArray":{t.length=e.array.length,t.depth=0,t.left=Z,t.right=Z;break}case"ISingleton":{t.length=1,t.depth=0,t.left=Z,t.right=Z;break}case"ISlice":{t.length=e.length,t.depth=e.chunk.depth+1,t.left=Z,t.right=Z;break}}return t},$c=e=>N(e,es),Z=A({_tag:"IEmpty"}),tt=()=>Z,rn=(...e)=>e.length===1?nt(e[0]):Pc(e),nt=e=>A({_tag:"ISingleton",a:e}),_n=(e,t,n)=>{switch(e.backing._tag){case"IArray":{Ac(e.backing.array,0,t,n,e.length);break}case"IConcat":{_n(e.left,t,n),_n(e.right,t,n+e.left.length);break}case"ISingleton":{t[n]=e.backing.a;break}case"ISlice":{let r=0,i=n;for(;r{switch(e.backing._tag){case"IEmpty":return ts;case"IArray":return e.backing.array;default:{const t=new Array(e.length);return _n(e,t,0),e.backing={_tag:"IArray",array:t},e.left=Z,e.right=Z,e.depth=0,t}}},Ke=Nc,Rc=e=>{switch(e.backing._tag){case"IEmpty":case"ISingleton":return e;case"IArray":return A({_tag:"IArray",array:Hr(e.backing.array)});case"IConcat":return A({_tag:"IConcat",left:gn(e.backing.right),right:gn(e.backing.left)});case"ISlice":return ns(Hr(Ke(e)))}},gn=Rc,ns=e=>A({_tag:"IArray",array:e}),Pc=e=>ns(e),Ce=g(2,(e,t)=>{switch(e.backing._tag){case"IEmpty":throw new Error("Index out of bounds");case"ISingleton":{if(t!==0)throw new Error("Index out of bounds");return e.backing.a}case"IArray":{if(t>=e.length||t<0)throw new Error("Index out of bounds");return e.backing.array[t]}case"IConcat":return tne(nt(t),e)),ne=g(2,(e,t)=>{if(e.backing._tag==="IEmpty")return t;if(t.backing._tag==="IEmpty")return e;const n=t.depth-e.depth;if(Math.abs(n)<=1)return A({_tag:"IConcat",left:e,right:t});if(n<-1)if(e.left.depth>=e.right.depth){const r=ne(e.right,t);return A({_tag:"IConcat",left:e.left,right:r})}else{const r=ne(e.right.right,t);if(r.depth===e.depth-3){const i=A({_tag:"IConcat",left:e.right.left,right:r});return A({_tag:"IConcat",left:e.left,right:i})}else{const i=A({_tag:"IConcat",left:e.left,right:e.right.left});return A({_tag:"IConcat",left:i,right:r})}}else if(t.right.depth>=t.left.depth){const r=ne(e,t.left);return A({_tag:"IConcat",left:r,right:t.right})}else{const r=ne(e,t.left.left);if(r.depth===t.depth-3){const i=A({_tag:"IConcat",left:r,right:t.left.right});return A({_tag:"IConcat",left:i,right:t.right})}else{const i=A({_tag:"IConcat",left:t.left.right,right:t.right});return A({_tag:"IConcat",left:r,right:i})}}}),jc=e=>e.length===0,Wr=e=>e.length>0,Lc=e=>Ce(e,0),Vr=Lc,me=5,tr=Math.pow(2,me),Fc=tr-1,Bc=tr/2,Dc=tr/4;function Jc(e){return e-=e>>1&1431655765,e=(e&858993459)+(e>>2&858993459),e=e+(e>>4)&252645135,e+=e>>8,e+=e>>16,e&127}function Ie(e,t){return t>>>e&Fc}function xe(e){return 1<({value:e,previous:t});function Oe(e,t,n,r){let i=r;if(!e){const s=r.length;i=new Array(s);for(let o=0;o=t;)r[c--]=r[c];return r[t]=n,r}let s=0,o=0;const a=new Array(i+1);for(;s1?new nr(t,this.hash,u):u[0]}const a=r(D());return V(a)?this:(++o.value,os(t,n,this.hash,this,i,new de(t,i,s,a)))}updateCollisionList(t,n,r,i,s,o,a){const c=i.length;for(let l=0;l=Bc?qc(t,u,m,a,c):new Me(t,a|l,Uc(_,f,m,c)):this}const k=c[f],R=k.modify(t,n+me,r,i,s,o);if(k===R)return this;let h=a,y;if(W(R)){if(h&=~l,!h)return new re;if(c.length<=2&&zc(c[f^1]))return c[f^1];y=ss(_,f,c)}else y=Oe(_,f,R,c);return _?(this.mask=h,this.children=y,this):new Me(t,h,y)}}class rr{constructor(t,n,r){d(this,"edit");d(this,"size");d(this,"children");d(this,"_tag","ArrayNode");this.edit=t,this.size=n,this.children=r}modify(t,n,r,i,s,o){let a=this.size;const c=this.children,u=Ie(n,i),l=c[u],f=(l||new re).modify(t,n+me,r,i,s,o);if(l===f)return this;const p=Kt(this,t);let _;if(W(l)&&!W(f))++a,_=Oe(p,u,f,c);else if(!W(l)&&W(f)){if(--a,a<=Dc)return Kc(t,a,u,c);_=Oe(p,u,new re,c)}else _=Oe(p,u,f,c);return p?(this.size=a,this.children=_,this):new rr(t,a,_)}}function Kc(e,t,n,r){const i=new Array(t-1);let s=0,o=0;for(let a=0,c=r.length;a>>=1;return s[t]=n,new rr(e,a+1,s)}function Wc(e,t,n,r,i,s){if(n===i)return new nr(e,n,[s,r]);const o=Ie(t,n),a=Ie(t,i);if(o===a)return c=>new Me(e,xe(o)|xe(a),[c]);{const c=o[e,t])},[E](){let e=w(as);for(const t of this)e^=C(w(t[0]),G(w(t[1])));return U(this,e)},[I](e){if(Xc(e)){if(e._size!==this._size)return!1;for(const t of this){const n=C(e,Zc(t[0],w(t[0])));if(V(n))return!1;if(!$(t[1],n.value))return!1}return!0}return!1},toString(){return J(this.toJSON())},toJSON(){return{_id:"HashMap",values:Array.from(this).map(M)}},[P](){return this.toJSON()},pipe(){return Y(this,arguments)}},ir=(e,t,n,r)=>{const i=Object.create(Vc);return i._editable=e,i._edit=t,i._root=n,i._size=r,i};class qt{constructor(t,n){d(this,"map");d(this,"f");d(this,"v");this.map=t,this.f=n,this.v=cs(this.map._root,this.f,void 0)}next(){if(V(this.v))return{done:!0,value:void 0};const t=this.v.value;return this.v=Mt(t.cont),{done:!1,value:t.value}}[Symbol.iterator](){return new qt(this.map,this.f)}}const Mt=e=>e?us(e[0],e[1],e[2],e[3],e[4]):D(),cs=(e,t,n=void 0)=>{switch(e._tag){case"LeafNode":return Xe(e.value)?Ye({value:t(e.key,e.value.value),cont:n}):Mt(n);case"CollisionNode":case"ArrayNode":case"IndexedNode":{const r=e.children;return us(r.length,r,0,t,n)}default:return Mt(n)}},us=(e,t,n,r,i)=>{for(;nGc,Xc=e=>N(e,yn),Zc=g(3,(e,t,n)=>{let r=e._root,i=0;for(;;)switch(r._tag){case"LeafNode":return $(t,r.key)?r.value:D();case"CollisionNode":{if(n===r.hash){const s=r.children;for(let o=0,a=s.length;onu(e,t,()=>Ye(n))),Qc=g(3,(e,t,n)=>e._editable?(e._root=t,e._size=n,e):t===e._root?e:ir(e._editable,e._edit,t,n)),eu=e=>new qt(e,t=>t),mn=e=>e._size,tu=e=>ir(!0,e._edit+1,e._root,e._size),nu=g(3,(e,t,n)=>ru(e,t,w(t),n)),ru=g(4,(e,t,n,r)=>{const i={value:e._size},s=e._root.modify(e._editable?e._edit:NaN,0,r,n,t,i);return C(e,Qc(s,i.value))}),iu=g(2,(e,t)=>su(e,void 0,(n,r,i)=>t(r,i))),su=g(3,(e,t,n)=>{const r=e._root;if(r._tag==="LeafNode")return Xe(r.value)?n(t,r.value.value,r.key):t;if(r._tag==="EmptyNode")return t;const i=[r.children];let s;for(;s=i.pop();)for(let o=0,a=s.length;o{const t=Object.create(ou);return t._keyMap=e,t},au=e=>N(e,bn),cu=sr(Yc()),fs=()=>cu,uu=e=>mn(e._keyMap),lu=e=>sr(tu(e._keyMap)),fu=e=>(e._keyMap._editable=!1,e),du=g(2,(e,t)=>{const n=lu(e);return t(n),fu(n)}),vn=g(2,(e,t)=>e._keyMap._editable?(Gr(t,!0)(e._keyMap),e):sr(Gr(t,!0)(e._keyMap))),hu=g(2,(e,t)=>du(fs(),n=>{pu(e,r=>vn(n,r));for(const r of t)vn(n,r)})),pu=g(2,(e,t)=>iu(e._keyMap,(n,r)=>t(r))),Tt=fs,_u=uu,sn=vn,wn=hu,ds="Die",Sn="Empty",or="Fail",hs="Interrupt",rt="Parallel",it="Sequential",ps="effect/Cause",_s=Symbol.for(ps),gu={_E:e=>e},ar={[_s]:gu,[E](){return C(w(ps),G(w(wu(this))),U(this))},[I](e){return mu(e)&&vu(this,e)},pipe(){return Y(this,arguments)},toJSON(){switch(this._tag){case"Empty":return{_id:"Cause",_tag:this._tag};case"Die":return{_id:"Cause",_tag:this._tag,defect:M(this.defect)};case"Interrupt":return{_id:"Cause",_tag:this._tag,fiberId:this.fiberId.toJSON()};case"Fail":return{_id:"Cause",_tag:this._tag,failure:M(this.error)};case"Sequential":case"Parallel":return{_id:"Cause",_tag:this._tag,left:M(this.left),right:M(this.right)}}},toString(){return ys(this)},[P](){return this.toJSON()}},xn=e=>{const t=Object.create(ar);return t._tag=or,t.error=e,t},yu=(e,t)=>{const n=Object.create(ar);return n._tag=rt,n.left=e,n.right=t,n},_t=(e,t)=>{const n=Object.create(ar);return n._tag=it,n.left=e,n.right=t,n},mu=e=>N(e,_s),bu=e=>gs(void 0,xu)(e),vu=(e,t)=>{let n=nt(e),r=nt(t);for(;Wr(n)&&Wr(r);){const[i,s]=C(Vr(n),Zr([Tt(),tt()],([c,u],l)=>{const[f,p]=En(l);return Ye([C(c,wn(f)),C(u,ne(p))])})),[o,a]=C(Vr(r),Zr([Tt(),tt()],([c,u],l)=>{const[f,p]=En(l);return Ye([C(c,wn(f)),C(u,ne(p))])}));if(!$(i,o))return!1;n=s,r=a}return!0},wu=e=>Su(nt(e),tt()),Su=(e,t)=>{for(;;){const[n,r]=C(e,Ea([Tt(),tt()],([s,o],a)=>{const[c,u]=En(a);return[C(s,wn(c)),C(o,ne(u))]})),i=_u(n)>0?C(t,rs(n)):t;if(jc(r))return gn(i);e=r,t=i}throw new Error(Kn("Cause.flattenCauseLoop"))},En=e=>{let t=e;const n=[];let r=Tt(),i=tt();for(;t!==void 0;)switch(t._tag){case Sn:{if(n.length===0)return[r,i];t=n.pop();break}case or:{if(r=sn(r,rn(t._tag,t.error)),n.length===0)return[r,i];t=n.pop();break}case ds:{if(r=sn(r,rn(t._tag,t.defect)),n.length===0)return[r,i];t=n.pop();break}case hs:{if(r=sn(r,rn(t._tag,t.fiberId)),n.length===0)return[r,i];t=n.pop();break}case it:{switch(t.left._tag){case Sn:{t=t.right;break}case it:{t=_t(t.left.left,_t(t.left.right,t.right));break}case rt:{t=yu(_t(t.left.left,t.right),_t(t.left.right,t.right));break}default:{i=rs(i,t.right),t=t.left;break}}break}case rt:{n.push(t.right),t=t.left;break}}throw new Error(Kn("Cause.evaluateCauseLoop"))},xu={emptyCase:Fr,failCase:Br,dieCase:Br,interruptCase:Fr,sequentialCase:(e,t,n)=>t&&n,parallelCase:(e,t,n)=>t&&n},Yr="SequentialCase",Xr="ParallelCase",Zr=g(3,(e,t,n)=>{let r=t,i=e;const s=[];for(;i!==void 0;){const o=n(r,i);switch(r=Xe(o)?o.value:r,i._tag){case it:{s.push(i.right),i=i.left;break}case rt:{s.push(i.right),i=i.left;break}default:{i=void 0;break}}i===void 0&&s.length>0&&(i=s.pop())}return r}),gs=g(3,(e,t,n)=>{const r=[e],i=[];for(;r.length>0;){const o=r.pop();switch(o._tag){case Sn:{i.push(pt(n.emptyCase(t)));break}case or:{i.push(pt(n.failCase(t,o.error)));break}case ds:{i.push(pt(n.dieCase(t,o.defect)));break}case hs:{i.push(pt(n.interruptCase(t,o.fiberId)));break}case it:{r.push(o.right),r.push(o.left),i.push(Jr({_tag:Yr}));break}case rt:{r.push(o.right),r.push(o.left),i.push(Jr({_tag:Xr}));break}}}const s=[];for(;i.length>0;){const o=i.pop();switch(o._tag){case"Left":{switch(o.left._tag){case Yr:{const a=s.pop(),c=s.pop(),u=n.sequentialCase(t,a,c);s.push(u);break}case Xr:{const a=s.pop(),c=s.pop(),u=n.parallelCase(t,a,c);s.push(u);break}}break}case"Right":{s.push(o.right);break}}}if(s.length===0)throw new Error("BUG: Cause.reduceWithContext - please report an issue at https://github.com/Effect-TS/effect/issues");return s.pop()}),ys=(e,t)=>bu(e)?"All fibers interrupted without errors.":Au(e).map(function(n){return(t==null?void 0:t.renderErrorCause)!==!0||n.cause===void 0?n.stack:`${n.stack} { +${ms(n.cause," ")} +}`}).join(` +`),ms=(e,t)=>{const n=e.stack.split(` +`);let r=`${t}[cause]: ${n[0]}`;for(let i=1,s=n.length;i{s in this||(this[s]=n[s])})),this.stack=Ou(`${this.name}: ${this.message}`,n instanceof Error&&n.stack?n.stack:"",this.span)}}const Eu=e=>{if(typeof e=="string")return e;if(typeof e=="object"&&e!==null&&e instanceof Error)return e.message;try{if(N(e,"toString")&&zn(e.toString)&&e.toString!==Object.prototype.toString&&e.toString!==globalThis.Array.prototype.toString)return e.toString()}catch{}return Ci(e)},ku=/\((.*)\)/g,Cu=Ne("effect/Tracer/spanToTrace",()=>new WeakMap),Ou=(e,t,n)=>{const r=[e],i=t.startsWith(e)?t.slice(e.length).split(` +`):t.split(` +`);for(let s=1;s"))}if(n){let s=n,o=0;for(;s&&s._tag==="Span"&&o<10;){const a=Cu.get(s);if(typeof a=="function"){const c=a();if(typeof c=="string"){const u=c.matchAll(ku);let l=!1;for(const[,f]of u)l=!0,r.push(` at ${s.name} (${f})`);l||r.push(` at ${s.name} (${c.replace(/^at /,"")})`)}else r.push(` at ${s.name}`)}else r.push(` at ${s.name}`);s=Sa(s.parent),o++}}return r.join(` +`)},Qr=Symbol.for("effect/SpanAnnotation"),Au=e=>gs(e,void 0,{emptyCase:()=>[],dieCase:(t,n)=>[new $t(n)],failCase:(t,n)=>[new $t(n)],interruptCase:()=>[],parallelCase:(t,n,r)=>[...n,...r],sequentialCase:(t,n,r)=>[...n,...r]});class Wt{constructor(t){d(this,"self");d(this,"called",!1);this.self=t}next(t){return this.called?{value:t,done:!0}:(this.called=!0,{value:this.self,done:!1})}return(t){return{value:t,done:!0}}throw(t){throw t}[Symbol.iterator](){return new Wt(this.self)}}const cr=Symbol.for("effect/Effect");var bi;class Iu{constructor(t){d(this,"_op");d(this,"effect_instruction_i0");d(this,"effect_instruction_i1");d(this,"effect_instruction_i2");d(this,"trace");d(this,bi,Ge);this._op=t}[(bi=cr,I)](t){return this===t}[E](){return U(this,qn(this))}pipe(){return Y(this,arguments)}toJSON(){return{_id:"Effect",_op:this._op,effect_instruction_i0:M(this.effect_instruction_i0),effect_instruction_i1:M(this.effect_instruction_i1),effect_instruction_i2:M(this.effect_instruction_i2)}}toString(){return J(this.toJSON())}[P](){return this.toJSON()}[Symbol.iterator](){return new Wt(new Ft(this))}}var vi;class Mu{constructor(t){d(this,"_op");d(this,"effect_instruction_i0");d(this,"effect_instruction_i1");d(this,"effect_instruction_i2");d(this,"trace");d(this,vi,Ge);this._op=t,this._tag=t}[(vi=cr,I)](t){return ju(t)&&t._op==="Failure"&&$(this.effect_instruction_i0,t.effect_instruction_i0)}[E](){return C(X(this._tag),G(w(this.effect_instruction_i0)),U(this))}get cause(){return this.effect_instruction_i0}pipe(){return Y(this,arguments)}toJSON(){return{_id:"Exit",_tag:this._op,cause:this.cause.toJSON()}}toString(){return J(this.toJSON())}[P](){return this.toJSON()}[Symbol.iterator](){return new Wt(new Ft(this))}}const Tu=e=>N(e,cr),$u=e=>{const t=new Iu(ea);return t.effect_instruction_i0=e,t},kn=Symbol.for("effect/SpanAnnotation"),ei=Symbol.for("effect/OriginalAnnotation"),Nu=(e,t)=>Xe(t)?new Proxy(e,{has(n,r){return r===kn||r===ei||r in n},get(n,r){return r===kn?t.value:r===ei?e:n[r]}}):e,Ru=e=>xi(e)&&!(kn in e)?$u(t=>ti(xn(Nu(e,Lu(t))))):ti(xn(e)),ti=e=>{const t=new Mu(Qo);return t.effect_instruction_i0=e,t},Pu=function(){class e extends globalThis.Error{commit(){return Ru(this)}toJSON(){const n={...this};return this.message&&(n.message=this.message),this.cause&&(n.cause=this.cause),n}[P](){return this.toString!==globalThis.Error.prototype.toString?this.stack?`${this.toString()} +${this.stack.split(` +`).slice(1).join(` +`)}`:this.toString():"Bun"in globalThis?ys(xn(this),{renderErrorCause:!0}):this}}return Object.assign(e.prototype,ua),e}(),ju=e=>Tu(e)&&"_tag"in e&&(e._tag==="Success"||e._tag==="Failure"),Lu=e=>{const t=e.currentSpan;return t!==void 0&&t._tag==="Span"?Ye(t):D()},Fu=function(){const e=Symbol.for("effect/Data/Error/plainArgs");return class extends Pu{constructor(n){super(n==null?void 0:n.message,n!=null&&n.cause?{cause:n.cause}:void 0),n&&(Object.assign(this,n),Object.defineProperty(this,e,{value:n,enumerable:!1}))}toJSON(){return{...this[e],...this}}}}(),Bu=e=>{class t extends Fu{constructor(){super(...arguments);d(this,"_tag",e)}}return t.prototype.name=e,t};var Du=class extends ct("BotMessageHandler")(){},Ju=e=>{let t=e.batch_size??10,n=e.timeout??10,r=e.max_empty_responses,i=e.update_types,s=e.log_level;return(t<10||t>100)&&(console.warn("Wrong limit, must be in [10..100], using 10 instead"),t=10),(n<2||n>10)&&(console.warn("Wrong timeout, must be in [2..10], using 2 instead"),t=10),r&&r<2&&(console.warn("Wrong max_empty_responses, must be in [2..infinity], using infinity"),r=void 0),r&&r<2&&(console.warn("Wrong max_empty_responses, must be in [2..infinity], using infinity"),r=void 0),i||(console.info("Handling only messages, ignoring others"),i=["message"]),s||(s="info"),{limit:t,timeout:n,max_empty_responses:r,update_types:i,log_level:s}},Hu=e=>{for(const[t,n]of Object.entries(e))if(t!="update_id")return{type:t,...n}},le,Ee=(le=class extends Bu("TgBotClientError"){},d(le,"missingSuccess",new le({reason:{type:"ClientInternalError",cause:"Expected 'success' to be defined"}})),le),Uu="https://api.telegram.org",zu=e=>Ae.of({...e,base_url:e.base_url??Uu}),Ae=class extends ct("TgBotClientConfig")(){},Ku=e=>typeof e=="object"&&e!=null&&"file_content"in e&&e.file_content instanceof Uint8Array&&"file_name"in e&&typeof e.file_name=="string",qu=e=>typeof e=="object"&&e!=null&&"ok"in e&&typeof e.ok=="boolean",Wu=e=>{const t=Object.entries(e);if(t.length==0)return;const n=new FormData;for(const[r,i]of t)i&&(typeof i!="object"?n.append(r,`${i}`):Ku(i)?n.append(r,new Blob([i.file_content]),i.file_name):n.append(r,JSON.stringify(i)));return n},qe=(e,t)=>ye(function*(){const n=yield*Ut(Ae),r=yield*pn({try:()=>fetch(`${n.base_url}/bot${n.bot_token}/${Oc(e)}`,{body:Wu(t)??null,method:"POST"}),catch:s=>new Ee({reason:{type:"ClientInternalError",cause:s}})}),i=yield*pn({try:()=>r.json(),catch:()=>new Ee({reason:{type:"UnexpectedResponse",response:r}})});return qu(i)?r.ok?i.result:yield*et(new Ee({reason:{type:"NotOkResponse",...i.error_code?{errorCode:i.error_code}:void 0,...i.description?{details:i.description}:void 0}})):yield*et(new Ee({reason:{type:"UnexpectedResponse",response:i}}))}),Vu=({state:e,settings:t,handlers:n})=>ye(function*(){const r=e.lastUpdateId;t.log_level=="debug"&&console.debug("getting updates",e);const i=yield*qe("get_updates",{...t,...r?{offset:r}:void 0}).pipe(Yi(a=>a.sort(c=>c.update_id)));let s,o=!1;for(const a of i){const c=Hu(a);if(!c){console.warn("Unknown update",c),o=!0;break}const u=n[`on_${c.type}`];if(!u)if(t.update_types.includes(c.type)){console.error("Handler for update not defined",c),o=!0;break}else{t.log_level=="debug"&&console.debug("Ignored update",c),s=a.update_id;continue}c.type=="message"&&"text"in c&&console.info("Got new message",{chatId:c.chat.id,chatType:c.chat.type,message:`${c.text.slice(0,5)}...`});const l=u(c);if("chat"in c&&l){const f=yield*qe(`send_${l.type}`,{...l,chat_id:c.chat.id});t.log_level=="debug"&&console.debug("bot response",f)}!l&&t.log_level=="debug"&&console.debug("handler returned no response for update",{update:c}),s=a.update_id}return o&&s&&(yield*qe("get_updates",{offset:s,limit:0}),t.log_level=="debug"&&console.debug("committed offset",s)),{updates:i,lastSuccessId:s,hasError:o}}),Gu=e=>{const t={lastUpdateId:void 0,emptyResponses:0},n=Ju(e.settings);return mc(1e3)(Vu({state:t,settings:n,handlers:e.settings})).pipe(_c({while:({updates:r,lastSuccessId:i,hasError:s})=>{if(s)return console.info("error in handler, quitting"),!1;if(r.length==0){if(t.emptyResponses+=1,n.max_empty_responses&&t.emptyResponses>n.max_empty_responses)return console.info("too many empty responses, quitting"),!1}else t.emptyResponses=0;return i&&(t.lastUpdateId=i+1),!0}}))};(class extends ct("BotUpdatePollerService")(){});ye(function*(){console.log("Initiating BotUpdatesPollerServiceDefault");const e={fiber:void 0};return{runBot:ye(function*(){console.log("run bot");const n=yield*Ut(Du),r=Gu({settings:n}).pipe(xc,ic(i=>i.addObserver(s=>{console.log("bot's fiber has been closed",s)})));e.fiber&&(console.log("killing previous bot's fiber"),yield*Ya(e.fiber)),e.fiber=yield*r,console.log("Fetching bot updates via long polling...")}),getFiber:()=>e.fiber}});(class extends ct("BotFactoryService")(){});var Yu=e=>ye(function*(){const t=yield*qe("get_file",{file_id:e}),n=yield*Ut(Ae),r=t.file_path;if(!r||r.length==0)return yield*et(new Ee({reason:{type:"UnableToGetFile",cause:"File path not defined"}}));const i=r.replaceAll("/","-"),s=`${n.base_url}/file/bot${n.bot_token}/${r}`,o=yield*pn({try:()=>fetch(s).then(c=>c.arrayBuffer()),catch:c=>new Ee({reason:{type:"UnableToGetFile",cause:c}})});return new File([new Uint8Array(o)],i)}),ni=class extends ct("ClientFileService")(){},Xu=ye(function*(){return{getFile:e=>Yu(e.file_id)}}),Zu=e=>{const t=zu(e);return ye(function*(){const r=yield*Ut(ni);return{execute:(i,s)=>qe(i,s).pipe(wt(Ae,t),qr),getFile:i=>r.getFile(i).pipe(wt(Ae,t),qr)}}).pipe(dc(ni,Xu),wt(Ae,t),Cc)};const Qu=(e,t)=>n=>e.getJsCode().then(r=>{if(!(!n.bot.token||n.bot.token.length<10)){if(!r.serialized){console.warn("Serizalized js code not defined");return}t.postMessage({command:"run-bot",token:n.bot.token,code:r.serialized}),n.bot.status="active"}}).catch(r=>{console.warn("cannot run bot",r)}),el=async(e,t)=>{const n=e.bot.token;if(!n){e.bot.isReachable=!1;return}const r=Zu({bot_token:n});await r.execute("get_me",{}).then(s=>(e.bot.name=s.first_name,e.bot.isReachable=!0,console.log("Running bot"),t(e))).catch(s=>{e.botUpdates.push(s),e.bot.name="nameless",e.bot.isReachable=!1}),(await r.execute("get_webhook_info",{})).url&&(e.botUpdates.push("Cannot work with webhooks, delete it first"),e.bot.isReachable=!1)},tl=async e=>{const t=new Worker(new URL(""+new URL("web-worker-DkORvJaQ.js",import.meta.url).href,import.meta.url),{type:"module"});if(!t)return;const n=Qu(e,t);return{worker:t,runBot:r=>n(r),checkTokenAndRun:r=>el(r,n)}},ur=e=>fetch(e).then(t=>t.text()),nl=()=>{if(!("monaco_loader"in window)||typeof window.monaco_loader!="object"||window.monaco_loader==null){console.warn("monaco loader is not available");return}return window.monaco_loader},rl=async e=>{const t=await ur("https://cdn.jsdelivr.net/npm/@effect-ak/tg-bot-client@0.3.3/dist/index.d.ts");e.languages.typescript.typescriptDefaults.setExtraLibs([{content:t,filePath:"node_modules/@effect-ak/tg-bot-client/index.d.ts"}]),e.languages.typescript.typescriptDefaults.setCompilerOptions({...e.languages.typescript.typescriptDefaults.getCompilerOptions(),moduleResolution:e.languages.typescript.ModuleResolutionKind.NodeJs,typeRoots:["node_modules"],strict:!0})},il=async e=>{const t=await ur("./example/empty.ts"),n=e.editor.createModel(t,"typescript");let r=null;const i=async()=>(r||(r=await e.languages.typescript.getTypeScriptWorker().then(s=>s(n.uri))),r.getEmitOutput(n.uri.toString()));return{tsModel:n,getJsCode:async()=>{const o=(await i()).outputFiles[0].text,a=await sl(o);return{defaultExport:a,serialized:ol(a==null?void 0:a.default)}}}};async function sl(e){try{const t=encodeURIComponent(e);return{default:(await Fo(()=>import(`data:text/javascript,${t}`),[],import.meta.url)).default}}catch(t){console.warn("get default error",t);return}}const ol=e=>{if(typeof e!="object"||!e)return;const t=[];for(const[n,r]of Object.entries(e))typeof r=="function"&&t.push([n,r.toString()]);return JSON.stringify(Object.fromEntries(t))},al=async e=>{const t=document.getElementById("container");if(!t){console.warn("container not found");return}e.config({paths:{vs:"https://cdn.jsdelivr.net/npm/monaco-editor@latest/min/vs"}});const n=await e.init(),r=await il(n),i=n.editor.create(t,{model:r.tsModel,contextmenu:!1,minimap:{enabled:!1}});return{tsTextModel:r,editor:i,monaco:n}},cl=async()=>{const e=nl();if(!e)return;const t=await al(e);if(t)return await rl(t.monaco),{tsTextModel:t.tsTextModel,onCodeChange:n=>{let r;t.tsTextModel.tsModel.onDidChangeContent(()=>{r!==void 0&&clearTimeout(r),r=window.setTimeout(()=>{t.monaco.editor.getModelMarkers({resource:t.tsTextModel.tsModel.uri}).find(a=>a.severity.valueOf()==8)!=null?console.debug("Code contains errors"):n()},1e3)})}}};var Cn=!1,On=!1,he=[],An=-1;function ul(e){ll(e)}function ll(e){he.includes(e)||he.push(e),dl()}function fl(e){let t=he.indexOf(e);t!==-1&&t>An&&he.splice(t,1)}function dl(){!On&&!Cn&&(Cn=!0,queueMicrotask(hl))}function hl(){Cn=!1,On=!0;for(let e=0;ee.effect(t,{scheduler:n=>{In?ul(n):n()}}),bs=e.raw}function ri(e){ve=e}function gl(e){let t=()=>{};return[r=>{let i=ve(r);return e._x_effects||(e._x_effects=new Set,e._x_runEffects=()=>{e._x_effects.forEach(s=>s())}),e._x_effects.add(i),t=()=>{i!==void 0&&(e._x_effects.delete(i),Pe(i))},i},()=>{t()}]}function vs(e,t){let n=!0,r,i=ve(()=>{let s=e();JSON.stringify(s),n?r=s:queueMicrotask(()=>{t(s,r),r=s}),n=!1});return()=>Pe(i)}var ws=[],Ss=[],xs=[];function yl(e){xs.push(e)}function lr(e,t){typeof t=="function"?(e._x_cleanups||(e._x_cleanups=[]),e._x_cleanups.push(t)):(t=e,Ss.push(t))}function Es(e){ws.push(e)}function ks(e,t,n){e._x_attributeCleanups||(e._x_attributeCleanups={}),e._x_attributeCleanups[t]||(e._x_attributeCleanups[t]=[]),e._x_attributeCleanups[t].push(n)}function Cs(e,t){e._x_attributeCleanups&&Object.entries(e._x_attributeCleanups).forEach(([n,r])=>{(t===void 0||t.includes(n))&&(r.forEach(i=>i()),delete e._x_attributeCleanups[n])})}function ml(e){var t,n;for((t=e._x_effects)==null||t.forEach(fl);(n=e._x_cleanups)!=null&&n.length;)e._x_cleanups.pop()()}var fr=new MutationObserver(_r),dr=!1;function hr(){fr.observe(document,{subtree:!0,childList:!0,attributes:!0,attributeOldValue:!0}),dr=!0}function Os(){bl(),fr.disconnect(),dr=!1}var Je=[];function bl(){let e=fr.takeRecords();Je.push(()=>e.length>0&&_r(e));let t=Je.length;queueMicrotask(()=>{if(Je.length===t)for(;Je.length>0;)Je.shift()()})}function S(e){if(!dr)return e();Os();let t=e();return hr(),t}var pr=!1,Nt=[];function vl(){pr=!0}function wl(){pr=!1,_r(Nt),Nt=[]}function _r(e){if(pr){Nt=Nt.concat(e);return}let t=[],n=new Set,r=new Map,i=new Map;for(let s=0;s{o.nodeType===1&&o._x_marker&&n.add(o)}),e[s].addedNodes.forEach(o=>{if(o.nodeType===1){if(n.has(o)){n.delete(o);return}o._x_marker||t.push(o)}})),e[s].type==="attributes")){let o=e[s].target,a=e[s].attributeName,c=e[s].oldValue,u=()=>{r.has(o)||r.set(o,[]),r.get(o).push({name:a,value:o.getAttribute(a)})},l=()=>{i.has(o)||i.set(o,[]),i.get(o).push(a)};o.hasAttribute(a)&&c===null?u():o.hasAttribute(a)?(l(),u()):l()}i.forEach((s,o)=>{Cs(o,s)}),r.forEach((s,o)=>{ws.forEach(a=>a(o,s))});for(let s of n)t.some(o=>o.contains(s))||Ss.forEach(o=>o(s));for(let s of t)s.isConnected&&xs.forEach(o=>o(s));t=null,n=null,r=null,i=null}function As(e){return ft(Te(e))}function lt(e,t,n){return e._x_dataStack=[t,...Te(n||e)],()=>{e._x_dataStack=e._x_dataStack.filter(r=>r!==t)}}function Te(e){return e._x_dataStack?e._x_dataStack:typeof ShadowRoot=="function"&&e instanceof ShadowRoot?Te(e.host):e.parentNode?Te(e.parentNode):[]}function ft(e){return new Proxy({objects:e},Sl)}var Sl={ownKeys({objects:e}){return Array.from(new Set(e.flatMap(t=>Object.keys(t))))},has({objects:e},t){return t==Symbol.unscopables?!1:e.some(n=>Object.prototype.hasOwnProperty.call(n,t)||Reflect.has(n,t))},get({objects:e},t,n){return t=="toJSON"?xl:Reflect.get(e.find(r=>Reflect.has(r,t))||{},t,n)},set({objects:e},t,n,r){const i=e.find(o=>Object.prototype.hasOwnProperty.call(o,t))||e[e.length-1],s=Object.getOwnPropertyDescriptor(i,t);return s!=null&&s.set&&(s!=null&&s.get)?s.set.call(r,n)||!0:Reflect.set(i,t,n)}};function xl(){return Reflect.ownKeys(this).reduce((t,n)=>(t[n]=Reflect.get(this,n),t),{})}function Is(e){let t=r=>typeof r=="object"&&!Array.isArray(r)&&r!==null,n=(r,i="")=>{Object.entries(Object.getOwnPropertyDescriptors(r)).forEach(([s,{value:o,enumerable:a}])=>{if(a===!1||o===void 0||typeof o=="object"&&o!==null&&o.__v_skip)return;let c=i===""?s:`${i}.${s}`;typeof o=="object"&&o!==null&&o._x_interceptor?r[s]=o.initialize(e,c,s):t(o)&&o!==r&&!(o instanceof Element)&&n(o,c)})};return n(e)}function Ms(e,t=()=>{}){let n={initialValue:void 0,_x_interceptor:!0,initialize(r,i,s){return e(this.initialValue,()=>El(r,i),o=>Mn(r,i,o),i,s)}};return t(n),r=>{if(typeof r=="object"&&r!==null&&r._x_interceptor){let i=n.initialize.bind(n);n.initialize=(s,o,a)=>{let c=r.initialize(s,o,a);return n.initialValue=c,i(s,o,a)}}else n.initialValue=r;return n}}function El(e,t){return t.split(".").reduce((n,r)=>n[r],e)}function Mn(e,t,n){if(typeof t=="string"&&(t=t.split(".")),t.length===1)e[t[0]]=n;else{if(t.length===0)throw error;return e[t[0]]||(e[t[0]]={}),Mn(e[t[0]],t.slice(1),n)}}var Ts={};function K(e,t){Ts[e]=t}function Tn(e,t){let n=kl(t);return Object.entries(Ts).forEach(([r,i])=>{Object.defineProperty(e,`$${r}`,{get(){return i(t,n)},enumerable:!1})}),e}function kl(e){let[t,n]=Ls(e),r={interceptor:Ms,...t};return lr(e,n),r}function Cl(e,t,n,...r){try{return n(...r)}catch(i){st(i,e,t)}}function st(e,t,n=void 0){e=Object.assign(e??{message:"No error message given."},{el:t,expression:n}),console.warn(`Alpine Expression Error: ${e.message} + +${n?'Expression: "'+n+`" + +`:""}`,t),setTimeout(()=>{throw e},0)}var St=!0;function $s(e){let t=St;St=!1;let n=e();return St=t,n}function pe(e,t,n={}){let r;return T(e,t)(i=>r=i,n),r}function T(...e){return Ns(...e)}var Ns=Rs;function Ol(e){Ns=e}function Rs(e,t){let n={};Tn(n,e);let r=[n,...Te(e)],i=typeof t=="function"?Al(r,t):Ml(r,t,e);return Cl.bind(null,e,t,i)}function Al(e,t){return(n=()=>{},{scope:r={},params:i=[]}={})=>{let s=t.apply(ft([r,...e]),i);Rt(n,s)}}var on={};function Il(e,t){if(on[e])return on[e];let n=Object.getPrototypeOf(async function(){}).constructor,r=/^[\n\s]*if.*\(.*\)/.test(e.trim())||/^(let|const)\s/.test(e.trim())?`(async()=>{ ${e} })()`:e,s=(()=>{try{let o=new n(["__self","scope"],`with (scope) { __self.result = ${r} }; __self.finished = true; return __self.result;`);return Object.defineProperty(o,"name",{value:`[Alpine] ${e}`}),o}catch(o){return st(o,t,e),Promise.resolve()}})();return on[e]=s,s}function Ml(e,t,n){let r=Il(t,n);return(i=()=>{},{scope:s={},params:o=[]}={})=>{r.result=void 0,r.finished=!1;let a=ft([s,...e]);if(typeof r=="function"){let c=r(r,a).catch(u=>st(u,n,t));r.finished?(Rt(i,r.result,a,o,n),r.result=void 0):c.then(u=>{Rt(i,u,a,o,n)}).catch(u=>st(u,n,t)).finally(()=>r.result=void 0)}}}function Rt(e,t,n,r,i){if(St&&typeof t=="function"){let s=t.apply(n,r);s instanceof Promise?s.then(o=>Rt(e,o,n,r)).catch(o=>st(o,i,t)):e(s)}else typeof t=="object"&&t instanceof Promise?t.then(s=>e(s)):e(t)}var gr="x-";function je(e=""){return gr+e}function Tl(e){gr=e}var Pt={};function x(e,t){return Pt[e]=t,{before(n){if(!Pt[n]){console.warn(String.raw`Cannot find directive \`${n}\`. \`${e}\` will use the default order of execution`);return}const r=ue.indexOf(n);ue.splice(r>=0?r:ue.indexOf("DEFAULT"),0,e)}}}function $l(e){return Object.keys(Pt).includes(e)}function yr(e,t,n){if(t=Array.from(t),e._x_virtualDirectives){let s=Object.entries(e._x_virtualDirectives).map(([a,c])=>({name:a,value:c})),o=Ps(s);s=s.map(a=>o.find(c=>c.name===a.name)?{name:`x-bind:${a.name}`,value:`"${a.value}"`}:a),t=t.concat(s)}let r={};return t.map(Ds((s,o)=>r[s]=o)).filter(Hs).map(Pl(r,n)).sort(jl).map(s=>Rl(e,s))}function Ps(e){return Array.from(e).map(Ds()).filter(t=>!Hs(t))}var $n=!1,ze=new Map,js=Symbol();function Nl(e){$n=!0;let t=Symbol();js=t,ze.set(t,[]);let n=()=>{for(;ze.get(t).length;)ze.get(t).shift()();ze.delete(t)},r=()=>{$n=!1,n()};e(n),r()}function Ls(e){let t=[],n=a=>t.push(a),[r,i]=gl(e);return t.push(i),[{Alpine:dt,effect:r,cleanup:n,evaluateLater:T.bind(T,e),evaluate:pe.bind(pe,e)},()=>t.forEach(a=>a())]}function Rl(e,t){let n=()=>{},r=Pt[t.type]||n,[i,s]=Ls(e);ks(e,t.original,s);let o=()=>{e._x_ignore||e._x_ignoreSelf||(r.inline&&r.inline(e,t,i),r=r.bind(r,e,t,i),$n?ze.get(js).push(r):r())};return o.runCleanups=s,o}var Fs=(e,t)=>({name:n,value:r})=>(n.startsWith(e)&&(n=n.replace(e,t)),{name:n,value:r}),Bs=e=>e;function Ds(e=()=>{}){return({name:t,value:n})=>{let{name:r,value:i}=Js.reduce((s,o)=>o(s),{name:t,value:n});return r!==t&&e(r,t),{name:r,value:i}}}var Js=[];function mr(e){Js.push(e)}function Hs({name:e}){return Us().test(e)}var Us=()=>new RegExp(`^${gr}([^:^.]+)\\b`);function Pl(e,t){return({name:n,value:r})=>{let i=n.match(Us()),s=n.match(/:([a-zA-Z0-9\-_:]+)/),o=n.match(/\.[^.\]]+(?=[^\]]*$)/g)||[],a=t||e[n]||n;return{type:i?i[1]:null,value:s?s[1]:null,modifiers:o.map(c=>c.replace(".","")),expression:r,original:a}}}var Nn="DEFAULT",ue=["ignore","ref","data","id","anchor","bind","init","for","model","modelable","transition","show","if",Nn,"teleport"];function jl(e,t){let n=ue.indexOf(e.type)===-1?Nn:e.type,r=ue.indexOf(t.type)===-1?Nn:t.type;return ue.indexOf(n)-ue.indexOf(r)}function We(e,t,n={}){e.dispatchEvent(new CustomEvent(t,{detail:n,bubbles:!0,composed:!0,cancelable:!0}))}function be(e,t){if(typeof ShadowRoot=="function"&&e instanceof ShadowRoot){Array.from(e.children).forEach(i=>be(i,t));return}let n=!1;if(t(e,()=>n=!0),n)return;let r=e.firstElementChild;for(;r;)be(r,t),r=r.nextElementSibling}function F(e,...t){console.warn(`Alpine Warning: ${e}`,...t)}var ii=!1;function Ll(){ii&&F("Alpine has already been initialized on this page. Calling Alpine.start() more than once can cause problems."),ii=!0,document.body||F("Unable to initialize. Trying to load Alpine before `` is available. Did you forget to add `defer` in Alpine's ` + @@ -53,7 +53,7 @@

Telegram Bot Playground 🤖

x-model="$store.state.selectedExample" @change="$dispatch('change-example')" > - + diff --git a/src/common/editor/setup.ts b/src/common/editor/setup.ts index aa587b3..b1da332 100644 --- a/src/common/editor/setup.ts +++ b/src/common/editor/setup.ts @@ -5,7 +5,7 @@ export const setupDts = async ( monaco: Monaco ) => { - const dts = await fetchText("https://cdn.jsdelivr.net/npm/@effect-ak/tg-bot-client@0.2.2/dist/index.d.ts"); + const dts = await fetchText("https://cdn.jsdelivr.net/npm/@effect-ak/tg-bot-client@0.3.3/dist/index.d.ts"); monaco.languages.typescript.typescriptDefaults.setExtraLibs([ { diff --git a/src/tg-bot-playground/bot-launcher/run.ts b/src/tg-bot-playground/bot-launcher/run.ts index 6486a07..a0f5a10 100644 --- a/src/tg-bot-playground/bot-launcher/run.ts +++ b/src/tg-bot-playground/bot-launcher/run.ts @@ -1,3 +1,4 @@ +import { makeTgBotClient } from "@effect-ak/tg-bot-client"; import type { GlobalState } from "#/tg-bot-playground/main"; import type { TsTextModel } from "#/common/editor/ts-text-model"; @@ -14,8 +15,6 @@ export const makeRunnableBot = return; } - console.log("code", code.serialized) - worker.postMessage({ command: 'run-bot', token: state.bot.token, @@ -28,7 +27,7 @@ export const makeRunnableBot = }) export const checkTokenAndRun = - (state: GlobalState, runnableBot: RunnableBot) => { + async (state: GlobalState, runnableBot: RunnableBot) => { const token = state.bot.token; @@ -37,21 +36,29 @@ export const checkTokenAndRun = return }; - fetch(`https://api.telegram.org/bot${token}/getMe`) - .then(_ => _.json()) + const client = + makeTgBotClient({ + bot_token: token + }); + + await client.execute("get_me", {}) .then(info => { - if (info.ok) { - state.bot.name = info.result.first_name; - state.bot.isReachable = true; - console.log("Running bot") - runnableBot(state); - } else { - state.bot.name = "nameless"; - state.bot.isReachable = false; - } + state.bot.name = info.first_name; + state.bot.isReachable = true; + console.log("Running bot") + return runnableBot(state); }).catch(error => { - console.warn("check token error", error); + state.botUpdates.push(error); + state.bot.name = "nameless"; state.bot.isReachable = false; }); + const webhook = + await client.execute("get_webhook_info", {}); + + if (webhook.url) { + state.botUpdates.push("Cannot work with webhooks, delete it first"); + state.bot.isReachable = false; + } + } diff --git a/src/tg-bot-playground/index.html b/src/tg-bot-playground/index.html index de13487..d35e58e 100644 --- a/src/tg-bot-playground/index.html +++ b/src/tg-bot-playground/index.html @@ -53,7 +53,7 @@

Telegram Bot Playground 🤖

x-model="$store.state.selectedExample" @change="$dispatch('change-example')" > - + diff --git a/src/tg-bot-playground/main.ts b/src/tg-bot-playground/main.ts index 7425767..7921dab 100644 --- a/src/tg-bot-playground/main.ts +++ b/src/tg-bot-playground/main.ts @@ -73,7 +73,7 @@ async function setup() { botLauncher.worker.onmessage = (event: MessageEvent) => { const data = event.data - console.log('got message from worker', data); + // console.log('got message from worker', data); if (!data) return; if (data.botState) { Object.assign(state.bot, data.botState) diff --git a/src/tg-bot-playground/static/example/command.ts b/src/tg-bot-playground/static/example/command.ts index e524438..73b330d 100644 --- a/src/tg-bot-playground/static/example/command.ts +++ b/src/tg-bot-playground/static/example/command.ts @@ -23,12 +23,13 @@ export default { } } - console.log("got a message", msg.text) - - return { - type: "message", - text: "hey :)" + if (msg.text) { // reply with "hey" on any text message + return { + type: "message", + text: "hey 😇" + } } + }, } satisfies BotMessageHandlers diff --git a/src/tg-bot-playground/static/example/empty.ts b/src/tg-bot-playground/static/example/empty.ts index ebe4b2e..87d777e 100644 --- a/src/tg-bot-playground/static/example/empty.ts +++ b/src/tg-bot-playground/static/example/empty.ts @@ -3,9 +3,12 @@ import type { BotMessageHandlers } from "@effect-ak/tg-bot-client" export default { on_message: (msg) => { - return { - type: "message", - text: "hey :)" + if (msg.text) { + return { + type: "message", + text: "hey 😀" + } } + }, } satisfies BotMessageHandlers diff --git a/src/tg-bot-playground/static/example/file.ts b/src/tg-bot-playground/static/example/file.ts index f505eae..38f4961 100644 --- a/src/tg-bot-playground/static/example/file.ts +++ b/src/tg-bot-playground/static/example/file.ts @@ -18,9 +18,12 @@ export default { } } - return { - type: "message", - text: "hey, send me a message in the format '3+3+3' and I will return you the sum of it in a text file" + if (msg.text) { //reply on any text message + return { + type: "message", + text: "hey 🙃, send me a message in the format '3+3+3' and I will return you the sum of it in a text file" + } } + }, } satisfies BotMessageHandlers