alchemylab-opencode 2.0.3 → 2.0.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/{anthropic-ND6UHXWL.js → anthropic-FVULF7C3.js} +1 -1
- package/dist/{app-runtime-ZWWQ4JTM.js → app-runtime-LDQWNGWP.js} +1 -1
- package/dist/{chunk-IQSFXWDQ.js → chunk-2JE3QYG6.js} +1 -1
- package/dist/{chunk-6MAPFAXY.js → chunk-4GJE6OMN.js} +1 -1
- package/dist/{chunk-AUB2TEYJ.js → chunk-5BLZCAU6.js} +1 -1
- package/dist/{chunk-XSKT4AXR.js → chunk-B74WSFN4.js} +3 -3
- package/dist/{chunk-2XWBNI3L.js → chunk-DADVNQTM.js} +80 -80
- package/dist/{chunk-RIA6SDOY.js → chunk-DWEYXIQI.js} +3 -3
- package/dist/{chunk-L3CE2Y3L.js → chunk-FOHYZ7MJ.js} +1 -1
- package/dist/{chunk-WL33KE3H.js → chunk-G7PFO5HG.js} +3 -3
- package/dist/{chunk-DGJQZN2Q.js → chunk-NGT6LCW6.js} +1 -1
- package/dist/{chunk-DZ6G4VSD.js → chunk-OT2YNR56.js} +1 -1
- package/dist/{chunk-WZ4237YY.js → chunk-OUVSKG2H.js} +1 -1
- package/dist/{chunk-F5PY52BY.js → chunk-UPEPL4I2.js} +1 -1
- package/dist/{code-mode-H3HRSD24.js → code-mode-YYOGD36U.js} +1 -1
- package/dist/{dist-KGNO5AP7.js → dist-KM5HCPZX.js} +1 -1
- package/dist/{dist-WZJ3LNRG.js → dist-YUH4RKR5.js} +1 -1
- package/dist/{dist-es-RZ25XEH6.js → dist-es-6PLFRCS4.js} +1 -1
- package/dist/{dist-es-EVVG3KDV.js → dist-es-G5UIJOU7.js} +2 -2
- package/dist/{dist-es-DHCTZZ2E.js → dist-es-HYIIGUNX.js} +1 -1
- package/dist/{dist-es-CH2YKBKX.js → dist-es-LSR2QCFZ.js} +1 -1
- package/dist/{dist-es-HRCONNGK.js → dist-es-W5GYOX6F.js} +1 -1
- package/dist/run.js +1 -1
- package/dist/serve.js +1 -1
- package/dist/{server-XRUYBM7W.js → server-LVIHYOCY.js} +3 -3
- package/dist/{session-4BXV4JJH.js → session-6OPJNJMK.js} +1 -1
- package/dist/{src-QJHT5SCV.js → src-3NCXEROI.js} +1 -1
- package/dist/{worktree-B2LROS2B.js → worktree-32M5MTFE.js} +1 -1
- package/package.json +1 -1
- /package/dist/{dist-LOXU6IEM.js → dist-CYBRID2F.js} +0 -0
- /package/dist/{lib-7VH6D2QJ.js → lib-ZP7Q6A3E.js} +0 -0
- /package/dist/{mime-types-GSWEOYZ5.js → mime-types-46EO4HOZ.js} +0 -0
- /package/dist/{signin-DKBWDEYP.js → signin-OCIW23YM.js} +0 -0
- /package/dist/{src-JODD73WX.js → src-LXWGIUZH.js} +0 -0
- /package/dist/{src-SMM4U63G.js → src-YAAFIGTW.js} +0 -0
- /package/dist/{sso-oidc-S3P64MCY.js → sso-oidc-OMMKINFE.js} +0 -0
- /package/dist/{sts-RG44NMOQ.js → sts-MWK22JIX.js} +0 -0
- /package/dist/{token-2V62AM3G.js → token-QPO3OAGS.js} +0 -0
- /package/dist/{token-util-VXONHEUD.js → token-util-YGPCEEPO.js} +0 -0
|
@@ -15,7 +15,7 @@ import { dirname as __alchemyDirname } from 'node:path';
|
|
|
15
15
|
const __alchemy_filename = __alchemyFileURLToPath(import.meta.url);
|
|
16
16
|
const __alchemy_dirname = __alchemyDirname(__alchemy_filename);
|
|
17
17
|
|
|
18
|
-
import{C as Zn,Da as q,La as dn,Ma as Yn,_a as ln,aa as Qn,db as er,h as an,ib as un,k as At,kb as pn,l as Gn,lb as mn,m as Hn,mb as gn,n as vt,o as cn,p as Me,q as fn,r as Y,u as Ft,v as U,w as me,x as le}from"./chunk-RIA6SDOY.js";import{b as Xn,i as Kn}from"./chunk-WKZYINC7.js";import{La as tn,Ma as nn,Oa as Bn,Pa as K,Ra as Se,Sa as yt,Sc as Jn,Va as rn,Wa as It,Ya as Rt,Za as wt,_a as jt,_c as st,ab as Xe,b as Kt,bc as Vn,bd as sn,c as Yt,fd as zn,ha as De,ia as On,ib as Un,ma as Fe,mb as it,nb as Wn,pa as G,pc as ot,qa as en,qb as pe,ta as Ln,ub as $n,uc as on,vb as qn}from"./chunk-7XX6TY62.js";import{t as Ie,x as rt}from"./chunk-VWLJXTZ5.js";import{Bc as gt,Bf as d,Ig as Fn,Tc as ve,aa as je,bb as Ae,bh as Xt,dc as ce,jd as ht,lc as ye,nb as Qt,pd as Ct,pj as S,zd as An}from"./chunk-ELPXQ32J.js";import{a as m,e as Re}from"./chunk-2MRHL4B2.js";var Cn={};Re(Cn,{ArchivedTimestamp:()=>_n,BusyError:()=>Tn,ChildrenInput:()=>Lo,CreateInput:()=>Ao,Event:()=>zo,ForkInput:()=>Fo,GetInput:()=>Oo,GlobalInfo:()=>jo,Info:()=>Ur,MessagesInput:()=>Jo,Metadata:()=>Zt,ProjectInfo:()=>Wr,RemoveInput:()=>Bo,Service:()=>tt,Session:()=>Cn,SetArchivedInput:()=>Wo,SetMetadataInput:()=>$o,SetPermissionInput:()=>qo,SetRevertInput:()=>Vo,SetTitleInput:()=>Uo,fromRow:()=>Mt,getUsage:()=>Ho,isDefaultTitle:()=>No,node:()=>Yo,plan:()=>Go,toRow:()=>Mo,use:()=>Zo});import Nt from"path";var at={};Re(at,{BackgroundJob:()=>at,Service:()=>Oe,node:()=>Zr});var Le={};Re(Le,{BackgroundJob:()=>Le,Service:()=>Oe,make:()=>rr,node:()=>Gr});var Dt={};Re(Dt,{Identifier:()=>Dt,ascending:()=>$r,create:()=>nr,descending:()=>qr,timestamp:()=>Vr});var hn={job:"job",event:"evt",session:"ses",message:"msg",permission:"per",question:"que",part:"prt",pty:"pty",tool:"tool",workspace:"wrk"};function $r(e,t){return tr(e,"ascending",t)}m($r,"ascending");function qr(e,t){return tr(e,"descending",t)}m(qr,"descending");function tr(e,t,n){if(!n)return nr(hn[e],t);if(!n.startsWith(hn[e]))throw new Error(`ID ${n} does not start with ${hn[e]}`);return n}m(tr,"generateID");function nr(e,t,n){return e+"_"+Ln(t==="descending",n)}m(nr,"create");function Vr(e){let t=e.split("_")[0],n=e.slice(t.length+1,t.length+13),r=BigInt("0x"+n);return Number(r/BigInt(4096))}m(Vr,"timestamp");var Oe=class extends Ae.Service()("@opencode/BackgroundJob"){static{m(this,"Service")}};function fe(e){return{...e.info,...e.info.metadata?{metadata:{...e.info.metadata}}:{}}}m(fe,"snapshot");function Jr(e){return e instanceof Error?e.message:String(e)}m(Jr,"errorText");var rr=d.gen(function*(){let e={jobs:yield*Ie.make(new Map),scope:yield*gt.Scope},t=d.fn("BackgroundJob.settle")(function*(l,u,g,y){let w=yield*Ct.currentTimeMillis,D=yield*Ie.modify(e.jobs,x=>{let I=x.get(l);if(!I)return[{},x];if(I.token!==u)return[{},x];if(I.info.status!=="running")return[{info:fe(I)},x];let k=I.pending-1,T=ye.isSuccess(y)&&(!I.output||g>I.output.sequence)?{sequence:g,text:y.value}:I.output;if(ye.isSuccess(y)&&k>0)return[{},new Map(x).set(l,{...I,pending:k,output:T})];let O=ye.isSuccess(y)?"completed":ht.hasInterruptsOnly(y.cause)?"cancelled":"error",W={...I,onPromote:void 0,pending:0,output:T,info:{...I.info,status:O,completed_at:w,...T?{output:T.text}:{},...ye.isFailure(y)?{error:Jr(ht.squash(y.cause))}:{}}};return[{info:fe(W),done:I.done,scope:I.scope},new Map(x).set(l,W)]});return D.info&&D.done&&(yield*ce.succeed(D.done,D.info).pipe(d.ignore)),D.scope&&(yield*gt.close(D.scope,ye.void).pipe(d.forkIn(e.scope,{startImmediately:!0}))),D.info}),n=d.fn("BackgroundJob.fork")(function*(l,u,g,y,w){return yield*w.pipe(d.matchCauseEffect({onSuccess:m(D=>t(u,g,y,ye.succeed(D)),"onSuccess"),onFailure:m(D=>t(u,g,y,ye.failCause(D)),"onFailure")}),d.asVoid,d.forkIn(l,{startImmediately:!0}))}),r=d.fn("BackgroundJob.list")(function*(){return Array.from((yield*Ie.get(e.jobs)).values()).map(fe).toSorted((l,u)=>l.started_at-u.started_at)}),i=d.fn("BackgroundJob.get")(function*(l){let u=(yield*Ie.get(e.jobs)).get(l);if(u)return fe(u)}),o=d.fn("BackgroundJob.start")(function*(l){return yield*d.uninterruptibleMask(u=>d.gen(function*(){let g=l.id??Dt.ascending("job"),y=yield*Ct.currentTimeMillis,w=yield*ce.make(),D=yield*ce.make(),x=yield*ce.make(),I=yield*Ie.modifyEffect(e.jobs,d.fnUntraced(function*(k){let T=k.get(g);if(T?.info.status==="running")return[{info:fe(T)},k];let O=yield*gt.fork(e.scope,"parallel"),W={},H={info:{id:g,type:l.type,title:l.title,status:"running",started_at:y,metadata:l.metadata},done:w,scope:O,token:W,pending:1,next:1,tail:x,promoted:D,onPromote:l.onPromote};return[{info:fe(H),scope:O,token:W},new Map(k).set(g,H)]}));return"scope"in I&&(yield*n(I.scope,g,I.token,0,u(l.run).pipe(d.ensuring(ce.succeed(x,void 0))))),I.info}))}),s=d.fn("BackgroundJob.extend")(function*(l){return yield*d.uninterruptibleMask(u=>d.gen(function*(){let g=yield*ce.make(),y=yield*Ie.modify(e.jobs,w=>{let D=w.get(l.id);return!D||D.info.status!=="running"?[{extended:!1},w]:[{extended:!0,previous:D.tail,scope:D.scope,tail:g,token:D.token,sequence:D.next},new Map(w).set(l.id,{...D,pending:D.pending+1,next:D.next+1,tail:g})]});return y.extended?(yield*n(y.scope,l.id,y.token,y.sequence,ce.await(y.previous).pipe(d.andThen(u(l.run)),d.ensuring(ce.succeed(y.tail,void 0)))),!0):!1}))}),a=d.fn("BackgroundJob.wait")(function*(l){let u=(yield*Ie.get(e.jobs)).get(l.id);if(!u)return{timedOut:!1};if(u.info.status!=="running")return{info:fe(u),timedOut:!1};if(l.timeout===void 0)return{info:yield*ce.await(u.done),timedOut:!1};if(l.timeout<=0)return{info:fe(u),timedOut:!0};let g=yield*ce.await(u.done).pipe(d.timeoutOption(l.timeout));return g._tag==="Some"?{info:g.value,timedOut:!1}:{info:fe(u),timedOut:!0}}),f=d.fn("BackgroundJob.waitForPromotion")(function*(l){let u=(yield*Ie.get(e.jobs)).get(l);return!u||u.info.status!=="running"?yield*d.never:u.info.metadata?.background===!0?fe(u):yield*ce.await(u.promoted)}),c=d.fn("BackgroundJob.promote")(function*(l){let u=yield*Ie.modifyEffect(e.jobs,d.fnUntraced(function*(g){let y=g.get(l);if(!y||y.info.status!=="running")return[{},g];if(y.info.metadata?.background===!0)return[{info:fe(y)},g];let w={...y,onPromote:void 0,info:{...y.info,metadata:{...y.info.metadata,background:!0}}};return[{info:fe(w),onPromote:y.onPromote,promoted:y.promoted},new Map(g).set(l,w)]}));return u.info&&u.promoted&&(yield*ce.succeed(u.promoted,u.info).pipe(d.ignore)),u.onPromote&&(yield*u.onPromote.pipe(d.ignore)),u.info}),p=d.fn("BackgroundJob.cancel")(function*(l){let u=yield*Ct.currentTimeMillis,g=yield*Ie.modify(e.jobs,y=>{let w=y.get(l);if(!w)return[{},y];if(w.info.status!=="running")return[{info:fe(w)},y];let D={...w,onPromote:void 0,pending:0,info:{...w.info,status:"cancelled",completed_at:u}};return[{info:fe(D),done:w.done,scope:w.scope},new Map(y).set(l,D)]});return g.info&&g.done&&(yield*ce.succeed(g.done,g.info).pipe(d.ignore)),g.scope&&(yield*gt.close(g.scope,ye.void)),g.info});return Oe.of({list:r,get:i,start:o,extend:s,wait:a,waitForPromotion:f,promote:c,cancel:p})}),zr=ve.effect(Oe,rr),Gr=On({service:Oe,layer:zr,deps:[]});var Hr=ve.effect(Le.Service,d.gen(function*(){let e=yield*q.make(()=>Le.make);return Le.Service.of({list:m(()=>q.useEffect(e,t=>t.list()),"list"),get:m(t=>q.useEffect(e,n=>n.get(t)),"get"),start:m(t=>q.useEffect(e,n=>n.start(t)),"start"),extend:m(t=>q.useEffect(e,n=>n.extend(t)),"extend"),wait:m(t=>q.useEffect(e,n=>n.wait(t)),"wait"),waitForPromotion:m(t=>q.useEffect(e,n=>n.waitForPromotion(t)),"waitForPromotion"),promote:m(t=>q.useEffect(e,n=>n.promote(t)),"promote"),cancel:m(t=>q.useEffect(e,n=>n.cancel(t)),"cancel")})})),Zr=De.make({service:Le.Service,layer:Hr,deps:[]});var ct=9e15,$e=1e9,yn="0123456789abcdef",Bt="2.3025850929940456840179914546843642076011014886287729760333279009675726096773524802359972050895982983419677840422862486334095254650828067566662873690987816894829072083255546808437998948262331985283935053089653777326288461633662222876982198867465436674744042432743651550489343149393914796194044002221051017141748003688084012647080685567743216228355220114804663715659121373450747856947683463616792101806445070648000277502684916746550586856935673420670581136429224554405758925724208241314695689016758940256776311356919292033376587141660230105703089634572075440370847469940168269282808481184289314848524948644871927809676271275775397027668605952496716674183485704422507197965004714951050492214776567636938662976979522110718264549734772662425709429322582798502585509785265383207606726317164309505995087807523710333101197857547331541421808427543863591778117054309827482385045648019095610299291824318237525357709750539565187697510374970888692180205189339507238539205144634197265287286965110862571492198849978748873771345686209167058",Ut="3.1415926535897932384626433832795028841971693993751058209749445923078164062862089986280348253421170679821480865132823066470938446095505822317253594081284811174502841027019385211055596446229489549303819644288109756659334461284756482337867831652712019091456485669234603486104543266482133936072602491412737245870066063155881748815209209628292540917153643678925903600113305305488204665213841469519415116094330572703657595919530921861173819326117931051185480744623799627495673518857527248912279381830119491298336733624406566430860213949463952247371907021798609437027705392171762931767523846748184676694051320005681271452635608277857713427577896091736371787214684409012249534301465495853710507922796892589235420199561121290219608640344181598136297747713099605187072113499999983729780499510597317328160963185950244594553469083026425223082533446850352619311881710100031378387528865875332083814206171776691473035982534904287554687311595628638823537875937519577818577805321712268066130019278766111959092164201989380952572010654858632789",In={precision:20,rounding:4,modulo:1,toExpNeg:-7,toExpPos:21,minE:-ct,maxE:ct,crypto:!1},ar,Te,j=!0,$t="[DecimalError] ",We=$t+"Invalid argument: ",cr=$t+"Precision limit exceeded",fr=$t+"crypto unavailable",dr="[object Decimal]",ie=Math.floor,ee=Math.pow,Qr=/^0b([01]+(\.[01]*)?|\.[01]+)(p[+-]?\d+)?$/i,Xr=/^0x([0-9a-f]+(\.[0-9a-f]*)?|\.[0-9a-f]+)(p[+-]?\d+)?$/i,Kr=/^0o([0-7]+(\.[0-7]*)?|\.[0-7]+)(p[+-]?\d+)?$/i,lr=/^(\d+(\.\d*)?|\.\d+)(e[+-]?\d+)?$/i,we=1e7,_=7,Yr=9007199254740991,ei=Bt.length-1,wn=Ut.length-1,v={toStringTag:dr};v.absoluteValue=v.abs=function(){var e=new this.constructor(this);return e.s<0&&(e.s=1),N(e)};v.ceil=function(){return N(new this.constructor(this),this.e+1,2)};v.clampedTo=v.clamp=function(e,t){var n,r=this,i=r.constructor;if(e=new i(e),t=new i(t),!e.s||!t.s)return new i(NaN);if(e.gt(t))throw Error(We+t);return n=r.cmp(e),n<0?e:r.cmp(t)>0?t:new i(r)};v.comparedTo=v.cmp=function(e){var t,n,r,i,o=this,s=o.d,a=(e=new o.constructor(e)).d,f=o.s,c=e.s;if(!s||!a)return!f||!c?NaN:f!==c?f:s===a?0:!s^f<0?1:-1;if(!s[0]||!a[0])return s[0]?f:a[0]?-c:0;if(f!==c)return f;if(o.e!==e.e)return o.e>e.e^f<0?1:-1;for(r=s.length,i=a.length,t=0,n=r<i?r:i;t<n;++t)if(s[t]!==a[t])return s[t]>a[t]^f<0?1:-1;return r===i?0:r>i^f<0?1:-1};v.cosine=v.cos=function(){var e,t,n=this,r=n.constructor;return n.d?n.d[0]?(e=r.precision,t=r.rounding,r.precision=e+Math.max(n.e,n.sd())+_,r.rounding=1,n=ti(r,hr(r,n)),r.precision=e,r.rounding=t,N(Te==2||Te==3?n.neg():n,e,t,!0)):new r(1):new r(NaN)};v.cubeRoot=v.cbrt=function(){var e,t,n,r,i,o,s,a,f,c,p=this,l=p.constructor;if(!p.isFinite()||p.isZero())return new l(p);for(j=!1,o=p.s*ee(p.s*p,1/3),!o||Math.abs(o)==1/0?(n=ne(p.d),e=p.e,(o=(e-n.length+1)%3)&&(n+=o==1||o==-2?"0":"00"),o=ee(n,1/3),e=ie((e+1)/3)-(e%3==(e<0?-1:2)),o==1/0?n="5e"+e:(n=o.toExponential(),n=n.slice(0,n.indexOf("e")+1)+e),r=new l(n),r.s=p.s):r=new l(o.toString()),s=(e=l.precision)+3;;)if(a=r,f=a.times(a).times(a),c=f.plus(p),r=V(c.plus(p).times(a),c.plus(f),s+2,1),ne(a.d).slice(0,s)===(n=ne(r.d)).slice(0,s))if(n=n.slice(s-3,s+1),n=="9999"||!i&&n=="4999"){if(!i&&(N(a,e+1,0),a.times(a).times(a).eq(p))){r=a;break}s+=4,i=1}else{(!+n||!+n.slice(1)&&n.charAt(0)=="5")&&(N(r,e+1,1),t=!r.times(r).times(r).eq(p));break}return j=!0,N(r,e,l.rounding,t)};v.decimalPlaces=v.dp=function(){var e,t=this.d,n=NaN;if(t){if(e=t.length-1,n=(e-ie(this.e/_))*_,e=t[e],e)for(;e%10==0;e/=10)n--;n<0&&(n=0)}return n};v.dividedBy=v.div=function(e){return V(this,new this.constructor(e))};v.dividedToIntegerBy=v.divToInt=function(e){var t=this,n=t.constructor;return N(V(t,new n(e),0,1,1),n.precision,n.rounding)};v.equals=v.eq=function(e){return this.cmp(e)===0};v.floor=function(){return N(new this.constructor(this),this.e+1,3)};v.greaterThan=v.gt=function(e){return this.cmp(e)>0};v.greaterThanOrEqualTo=v.gte=function(e){var t=this.cmp(e);return t==1||t===0};v.hyperbolicCosine=v.cosh=function(){var e,t,n,r,i,o=this,s=o.constructor,a=new s(1);if(!o.isFinite())return new s(o.s?1/0:NaN);if(o.isZero())return a;n=s.precision,r=s.rounding,s.precision=n+Math.max(o.e,o.sd())+4,s.rounding=1,i=o.d.length,i<32?(e=Math.ceil(i/3),t=(1/Vt(4,e)).toString()):(e=16,t="2.3283064365386962890625e-10"),o=ft(s,1,o.times(t),new s(1),!0);for(var f,c=e,p=new s(8);c--;)f=o.times(o),o=a.minus(f.times(p.minus(f.times(p))));return N(o,s.precision=n,s.rounding=r,!0)};v.hyperbolicSine=v.sinh=function(){var e,t,n,r,i=this,o=i.constructor;if(!i.isFinite()||i.isZero())return new o(i);if(t=o.precision,n=o.rounding,o.precision=t+Math.max(i.e,i.sd())+4,o.rounding=1,r=i.d.length,r<3)i=ft(o,2,i,i,!0);else{e=1.4*Math.sqrt(r),e=e>16?16:e|0,i=i.times(1/Vt(5,e)),i=ft(o,2,i,i,!0);for(var s,a=new o(5),f=new o(16),c=new o(20);e--;)s=i.times(i),i=i.times(a.plus(s.times(f.times(s).plus(c))))}return o.precision=t,o.rounding=n,N(i,t,n,!0)};v.hyperbolicTangent=v.tanh=function(){var e,t,n=this,r=n.constructor;return n.isFinite()?n.isZero()?new r(n):(e=r.precision,t=r.rounding,r.precision=e+7,r.rounding=1,V(n.sinh(),n.cosh(),r.precision=e,r.rounding=t)):new r(n.s)};v.inverseCosine=v.acos=function(){var e=this,t=e.constructor,n=e.abs().cmp(1),r=t.precision,i=t.rounding;return n!==-1?n===0?e.isNeg()?Ee(t,r,i):new t(0):new t(NaN):e.isZero()?Ee(t,r+4,i).times(.5):(t.precision=r+6,t.rounding=1,e=new t(1).minus(e).div(e.plus(1)).sqrt().atan(),t.precision=r,t.rounding=i,e.times(2))};v.inverseHyperbolicCosine=v.acosh=function(){var e,t,n=this,r=n.constructor;return n.lte(1)?new r(n.eq(1)?0:NaN):n.isFinite()?(e=r.precision,t=r.rounding,r.precision=e+Math.max(Math.abs(n.e),n.sd())+4,r.rounding=1,j=!1,n=n.times(n).minus(1).sqrt().plus(n),j=!0,r.precision=e,r.rounding=t,n.ln()):new r(n)};v.inverseHyperbolicSine=v.asinh=function(){var e,t,n=this,r=n.constructor;return!n.isFinite()||n.isZero()?new r(n):(e=r.precision,t=r.rounding,r.precision=e+2*Math.max(Math.abs(n.e),n.sd())+6,r.rounding=1,j=!1,n=n.times(n).plus(1).sqrt().plus(n),j=!0,r.precision=e,r.rounding=t,n.ln())};v.inverseHyperbolicTangent=v.atanh=function(){var e,t,n,r,i=this,o=i.constructor;return i.isFinite()?i.e>=0?new o(i.abs().eq(1)?i.s/0:i.isZero()?i:NaN):(e=o.precision,t=o.rounding,r=i.sd(),Math.max(r,e)<2*-i.e-1?N(new o(i),e,t,!0):(o.precision=n=r-i.e,i=V(i.plus(1),new o(1).minus(i),n+e,1),o.precision=e+4,o.rounding=1,i=i.ln(),o.precision=e,o.rounding=t,i.times(.5))):new o(NaN)};v.inverseSine=v.asin=function(){var e,t,n,r,i=this,o=i.constructor;return i.isZero()?new o(i):(t=i.abs().cmp(1),n=o.precision,r=o.rounding,t!==-1?t===0?(e=Ee(o,n+4,r).times(.5),e.s=i.s,e):new o(NaN):(o.precision=n+6,o.rounding=1,i=i.div(new o(1).minus(i.times(i)).sqrt().plus(1)).atan(),o.precision=n,o.rounding=r,i.times(2)))};v.inverseTangent=v.atan=function(){var e,t,n,r,i,o,s,a,f,c=this,p=c.constructor,l=p.precision,u=p.rounding;if(c.isFinite()){if(c.isZero())return new p(c);if(c.abs().eq(1)&&l+4<=wn)return s=Ee(p,l+4,u).times(.25),s.s=c.s,s}else{if(!c.s)return new p(NaN);if(l+4<=wn)return s=Ee(p,l+4,u).times(.5),s.s=c.s,s}for(p.precision=a=l+10,p.rounding=1,n=Math.min(28,a/_+2|0),e=n;e;--e)c=c.div(c.times(c).plus(1).sqrt().plus(1));for(j=!1,t=Math.ceil(a/_),r=1,f=c.times(c),s=new p(c),i=c;e!==-1;)if(i=i.times(f),o=s.minus(i.div(r+=2)),i=i.times(f),s=o.plus(i.div(r+=2)),s.d[t]!==void 0)for(e=t;s.d[e]===o.d[e]&&e--;);return n&&(s=s.times(2<<n-1)),j=!0,N(s,p.precision=l,p.rounding=u,!0)};v.isFinite=function(){return!!this.d};v.isInteger=v.isInt=function(){return!!this.d&&ie(this.e/_)>this.d.length-2};v.isNaN=function(){return!this.s};v.isNegative=v.isNeg=function(){return this.s<0};v.isPositive=v.isPos=function(){return this.s>0};v.isZero=function(){return!!this.d&&this.d[0]===0};v.lessThan=v.lt=function(e){return this.cmp(e)<0};v.lessThanOrEqualTo=v.lte=function(e){return this.cmp(e)<1};v.logarithm=v.log=function(e){var t,n,r,i,o,s,a,f,c=this,p=c.constructor,l=p.precision,u=p.rounding,g=5;if(e==null)e=new p(10),t=!0;else{if(e=new p(e),n=e.d,e.s<0||!n||!n[0]||e.eq(1))return new p(NaN);t=e.eq(10)}if(n=c.d,c.s<0||!n||!n[0]||c.eq(1))return new p(n&&!n[0]?-1/0:c.s!=1?NaN:n?0:1/0);if(t)if(n.length>1)o=!0;else{for(i=n[0];i%10===0;)i/=10;o=i!==1}if(j=!1,a=l+g,s=Ue(c,a),r=t?Wt(p,a+10):Ue(e,a),f=V(s,r,a,1),St(f.d,i=l,u))do if(a+=10,s=Ue(c,a),r=t?Wt(p,a+10):Ue(e,a),f=V(s,r,a,1),!o){+ne(f.d).slice(i+1,i+15)+1==1e14&&(f=N(f,l+1,0));break}while(St(f.d,i+=10,u));return j=!0,N(f,l,u)};v.minus=v.sub=function(e){var t,n,r,i,o,s,a,f,c,p,l,u,g=this,y=g.constructor;if(e=new y(e),!g.d||!e.d)return!g.s||!e.s?e=new y(NaN):g.d?e.s=-e.s:e=new y(e.d||g.s!==e.s?g:NaN),e;if(g.s!=e.s)return e.s=-e.s,g.plus(e);if(c=g.d,u=e.d,a=y.precision,f=y.rounding,!c[0]||!u[0]){if(u[0])e.s=-e.s;else if(c[0])e=new y(g);else return new y(f===3?-0:0);return j?N(e,a,f):e}if(n=ie(e.e/_),p=ie(g.e/_),c=c.slice(),o=p-n,o){for(l=o<0,l?(t=c,o=-o,s=u.length):(t=u,n=p,s=c.length),r=Math.max(Math.ceil(a/_),s)+2,o>r&&(o=r,t.length=1),t.reverse(),r=o;r--;)t.push(0);t.reverse()}else{for(r=c.length,s=u.length,l=r<s,l&&(s=r),r=0;r<s;r++)if(c[r]!=u[r]){l=c[r]<u[r];break}o=0}for(l&&(t=c,c=u,u=t,e.s=-e.s),s=c.length,r=u.length-s;r>0;--r)c[s++]=0;for(r=u.length;r>o;){if(c[--r]<u[r]){for(i=r;i&&c[--i]===0;)c[i]=we-1;--c[i],c[r]+=we}c[r]-=u[r]}for(;c[--s]===0;)c.pop();for(;c[0]===0;c.shift())--n;return c[0]?(e.d=c,e.e=qt(c,n),j?N(e,a,f):e):new y(f===3?-0:0)};v.modulo=v.mod=function(e){var t,n=this,r=n.constructor;return e=new r(e),!n.d||!e.s||e.d&&!e.d[0]?new r(NaN):!e.d||n.d&&!n.d[0]?N(new r(n),r.precision,r.rounding):(j=!1,r.modulo==9?(t=V(n,e.abs(),0,3,1),t.s*=e.s):t=V(n,e,0,r.modulo,1),t=t.times(e),j=!0,n.minus(t))};v.naturalExponential=v.exp=function(){return vn(this)};v.naturalLogarithm=v.ln=function(){return Ue(this)};v.negated=v.neg=function(){var e=new this.constructor(this);return e.s=-e.s,N(e)};v.plus=v.add=function(e){var t,n,r,i,o,s,a,f,c,p,l=this,u=l.constructor;if(e=new u(e),!l.d||!e.d)return!l.s||!e.s?e=new u(NaN):l.d||(e=new u(e.d||l.s===e.s?l:NaN)),e;if(l.s!=e.s)return e.s=-e.s,l.minus(e);if(c=l.d,p=e.d,a=u.precision,f=u.rounding,!c[0]||!p[0])return p[0]||(e=new u(l)),j?N(e,a,f):e;if(o=ie(l.e/_),r=ie(e.e/_),c=c.slice(),i=o-r,i){for(i<0?(n=c,i=-i,s=p.length):(n=p,r=o,s=c.length),o=Math.ceil(a/_),s=o>s?o+1:s+1,i>s&&(i=s,n.length=1),n.reverse();i--;)n.push(0);n.reverse()}for(s=c.length,i=p.length,s-i<0&&(i=s,n=p,p=c,c=n),t=0;i;)t=(c[--i]=c[i]+p[i]+t)/we|0,c[i]%=we;for(t&&(c.unshift(t),++r),s=c.length;c[--s]==0;)c.pop();return e.d=c,e.e=qt(c,r),j?N(e,a,f):e};v.precision=v.sd=function(e){var t,n=this;if(e!==void 0&&e!==!!e&&e!==1&&e!==0)throw Error(We+e);return n.d?(t=ur(n.d),e&&n.e+1>t&&(t=n.e+1)):t=NaN,t};v.round=function(){var e=this,t=e.constructor;return N(new t(e),e.e+1,t.rounding)};v.sine=v.sin=function(){var e,t,n=this,r=n.constructor;return n.isFinite()?n.isZero()?new r(n):(e=r.precision,t=r.rounding,r.precision=e+Math.max(n.e,n.sd())+_,r.rounding=1,n=ri(r,hr(r,n)),r.precision=e,r.rounding=t,N(Te>2?n.neg():n,e,t,!0)):new r(NaN)};v.squareRoot=v.sqrt=function(){var e,t,n,r,i,o,s=this,a=s.d,f=s.e,c=s.s,p=s.constructor;if(c!==1||!a||!a[0])return new p(!c||c<0&&(!a||a[0])?NaN:a?s:1/0);for(j=!1,c=Math.sqrt(+s),c==0||c==1/0?(t=ne(a),(t.length+f)%2==0&&(t+="0"),c=Math.sqrt(t),f=ie((f+1)/2)-(f<0||f%2),c==1/0?t="5e"+f:(t=c.toExponential(),t=t.slice(0,t.indexOf("e")+1)+f),r=new p(t)):r=new p(c.toString()),n=(f=p.precision)+3;;)if(o=r,r=o.plus(V(s,o,n+2,1)).times(.5),ne(o.d).slice(0,n)===(t=ne(r.d)).slice(0,n))if(t=t.slice(n-3,n+1),t=="9999"||!i&&t=="4999"){if(!i&&(N(o,f+1,0),o.times(o).eq(s))){r=o;break}n+=4,i=1}else{(!+t||!+t.slice(1)&&t.charAt(0)=="5")&&(N(r,f+1,1),e=!r.times(r).eq(s));break}return j=!0,N(r,f,p.rounding,e)};v.tangent=v.tan=function(){var e,t,n=this,r=n.constructor;return n.isFinite()?n.isZero()?new r(n):(e=r.precision,t=r.rounding,r.precision=e+10,r.rounding=1,n=n.sin(),n.s=1,n=V(n,new r(1).minus(n.times(n)).sqrt(),e+10,0),r.precision=e,r.rounding=t,N(Te==2||Te==4?n.neg():n,e,t,!0)):new r(NaN)};v.times=v.mul=function(e){var t,n,r,i,o,s,a,f,c,p=this,l=p.constructor,u=p.d,g=(e=new l(e)).d;if(e.s*=p.s,!u||!u[0]||!g||!g[0])return new l(!e.s||u&&!u[0]&&!g||g&&!g[0]&&!u?NaN:!u||!g?e.s/0:e.s*0);for(n=ie(p.e/_)+ie(e.e/_),f=u.length,c=g.length,f<c&&(o=u,u=g,g=o,s=f,f=c,c=s),o=[],s=f+c,r=s;r--;)o.push(0);for(r=c;--r>=0;){for(t=0,i=f+r;i>r;)a=o[i]+g[r]*u[i-r-1]+t,o[i--]=a%we|0,t=a/we|0;o[i]=(o[i]+t)%we|0}for(;!o[--s];)o.pop();return t?++n:o.shift(),e.d=o,e.e=qt(o,n),j?N(e,l.precision,l.rounding):e};v.toBinary=function(e,t){return Dn(this,2,e,t)};v.toDecimalPlaces=v.toDP=function(e,t){var n=this,r=n.constructor;return n=new r(n),e===void 0?n:(de(e,0,$e),t===void 0?t=r.rounding:de(t,0,8),N(n,e+n.e+1,t))};v.toExponential=function(e,t){var n,r=this,i=r.constructor;return e===void 0?n=ke(r,!0):(de(e,0,$e),t===void 0?t=i.rounding:de(t,0,8),r=N(new i(r),e+1,t),n=ke(r,!0,e+1)),r.isNeg()&&!r.isZero()?"-"+n:n};v.toFixed=function(e,t){var n,r,i=this,o=i.constructor;return e===void 0?n=ke(i):(de(e,0,$e),t===void 0?t=o.rounding:de(t,0,8),r=N(new o(i),e+i.e+1,t),n=ke(r,!1,e+r.e+1)),i.isNeg()&&!i.isZero()?"-"+n:n};v.toFraction=function(e){var t,n,r,i,o,s,a,f,c,p,l,u,g=this,y=g.d,w=g.constructor;if(!y)return new w(g);if(c=n=new w(1),r=f=new w(0),t=new w(r),o=t.e=ur(y)-g.e-1,s=o%_,t.d[0]=ee(10,s<0?_+s:s),e==null)e=o>0?t:c;else{if(a=new w(e),!a.isInt()||a.lt(c))throw Error(We+a);e=a.gt(t)?o>0?t:c:a}for(j=!1,a=new w(ne(y)),p=w.precision,w.precision=o=y.length*_*2;l=V(a,t,0,1,1),i=n.plus(l.times(r)),i.cmp(e)!=1;)n=r,r=i,i=c,c=f.plus(l.times(i)),f=i,i=t,t=a.minus(l.times(i)),a=i;return i=V(e.minus(n),r,0,1,1),f=f.plus(i.times(c)),n=n.plus(i.times(r)),f.s=c.s=g.s,u=V(c,r,o,1).minus(g).abs().cmp(V(f,n,o,1).minus(g).abs())<1?[c,r]:[f,n],w.precision=p,j=!0,u};v.toHexadecimal=v.toHex=function(e,t){return Dn(this,16,e,t)};v.toNearest=function(e,t){var n=this,r=n.constructor;if(n=new r(n),e==null){if(!n.d)return n;e=new r(1),t=r.rounding}else{if(e=new r(e),t===void 0?t=r.rounding:de(t,0,8),!n.d)return e.s?n:e;if(!e.d)return e.s&&(e.s=n.s),e}return e.d[0]?(j=!1,n=V(n,e,0,t,1).times(e),j=!0,N(n)):(e.s=n.s,n=e),n};v.toNumber=function(){return+this};v.toOctal=function(e,t){return Dn(this,8,e,t)};v.toPower=v.pow=function(e){var t,n,r,i,o,s,a=this,f=a.constructor,c=+(e=new f(e));if(!a.d||!e.d||!a.d[0]||!e.d[0])return new f(ee(+a,c));if(a=new f(a),a.eq(1))return a;if(r=f.precision,o=f.rounding,e.eq(1))return N(a,r,o);if(t=ie(e.e/_),t>=e.d.length-1&&(n=c<0?-c:c)<=Yr)return i=pr(f,a,n,r),e.s<0?new f(1).div(i):N(i,r,o);if(s=a.s,s<0){if(t<e.d.length-1)return new f(NaN);if((e.d[t]&1)==0&&(s=1),a.e==0&&a.d[0]==1&&a.d.length==1)return a.s=s,a}return n=ee(+a,c),t=n==0||!isFinite(n)?ie(c*(Math.log("0."+ne(a.d))/Math.LN10+a.e+1)):new f(n+"").e,t>f.maxE+1||t<f.minE-1?new f(t>0?s/0:0):(j=!1,f.rounding=a.s=1,n=Math.min(12,(t+"").length),i=vn(e.times(Ue(a,r+n)),r),i.d&&(i=N(i,r+5,1),St(i.d,r,o)&&(t=r+10,i=N(vn(e.times(Ue(a,t+n)),t),t+5,1),+ne(i.d).slice(r+1,r+15)+1==1e14&&(i=N(i,r+1,0)))),i.s=s,j=!0,f.rounding=o,N(i,r,o))};v.toPrecision=function(e,t){var n,r=this,i=r.constructor;return e===void 0?n=ke(r,r.e<=i.toExpNeg||r.e>=i.toExpPos):(de(e,1,$e),t===void 0?t=i.rounding:de(t,0,8),r=N(new i(r),e,t),n=ke(r,e<=r.e||r.e<=i.toExpNeg,e)),r.isNeg()&&!r.isZero()?"-"+n:n};v.toSignificantDigits=v.toSD=function(e,t){var n=this,r=n.constructor;return e===void 0?(e=r.precision,t=r.rounding):(de(e,1,$e),t===void 0?t=r.rounding:de(t,0,8)),N(new r(n),e,t)};v.toString=function(){var e=this,t=e.constructor,n=ke(e,e.e<=t.toExpNeg||e.e>=t.toExpPos);return e.isNeg()&&!e.isZero()?"-"+n:n};v.truncated=v.trunc=function(){return N(new this.constructor(this),this.e+1,1)};v.valueOf=v.toJSON=function(){var e=this,t=e.constructor,n=ke(e,e.e<=t.toExpNeg||e.e>=t.toExpPos);return e.isNeg()?"-"+n:n};function ne(e){var t,n,r,i=e.length-1,o="",s=e[0];if(i>0){for(o+=s,t=1;t<i;t++)r=e[t]+"",n=_-r.length,n&&(o+=Be(n)),o+=r;s=e[t],r=s+"",n=_-r.length,n&&(o+=Be(n))}else if(s===0)return"0";for(;s%10===0;)s/=10;return o+s}m(ne,"digitsToString");function de(e,t,n){if(e!==~~e||e<t||e>n)throw Error(We+e)}m(de,"checkInt32");function St(e,t,n,r){var i,o,s,a;for(o=e[0];o>=10;o/=10)--t;return--t<0?(t+=_,i=0):(i=Math.ceil((t+1)/_),t%=_),o=ee(10,_-t),a=e[i]%o|0,r==null?t<3?(t==0?a=a/100|0:t==1&&(a=a/10|0),s=n<4&&a==99999||n>3&&a==49999||a==5e4||a==0):s=(n<4&&a+1==o||n>3&&a+1==o/2)&&(e[i+1]/o/100|0)==ee(10,t-2)-1||(a==o/2||a==0)&&(e[i+1]/o/100|0)==0:t<4?(t==0?a=a/1e3|0:t==1?a=a/100|0:t==2&&(a=a/10|0),s=(r||n<4)&&a==9999||!r&&n>3&&a==4999):s=((r||n<4)&&a+1==o||!r&&n>3&&a+1==o/2)&&(e[i+1]/o/1e3|0)==ee(10,t-3)-1,s}m(St,"checkRoundingDigits");function Ot(e,t,n){for(var r,i=[0],o,s=0,a=e.length;s<a;){for(o=i.length;o--;)i[o]*=t;for(i[0]+=yn.indexOf(e.charAt(s++)),r=0;r<i.length;r++)i[r]>n-1&&(i[r+1]===void 0&&(i[r+1]=0),i[r+1]+=i[r]/n|0,i[r]%=n)}return i.reverse()}m(Ot,"convertBase");function ti(e,t){var n,r,i;if(t.isZero())return t;r=t.d.length,r<32?(n=Math.ceil(r/3),i=(1/Vt(4,n)).toString()):(n=16,i="2.3283064365386962890625e-10"),e.precision+=n,t=ft(e,1,t.times(i),new e(1));for(var o=n;o--;){var s=t.times(t);t=s.times(s).minus(s).times(8).plus(1)}return e.precision-=n,t}m(ti,"cosine");var V=(function(){function e(r,i,o){var s,a=0,f=r.length;for(r=r.slice();f--;)s=r[f]*i+a,r[f]=s%o|0,a=s/o|0;return a&&r.unshift(a),r}m(e,"multiplyInteger");function t(r,i,o,s){var a,f;if(o!=s)f=o>s?1:-1;else for(a=f=0;a<o;a++)if(r[a]!=i[a]){f=r[a]>i[a]?1:-1;break}return f}m(t,"compare");function n(r,i,o,s){for(var a=0;o--;)r[o]-=a,a=r[o]<i[o]?1:0,r[o]=a*s+r[o]-i[o];for(;!r[0]&&r.length>1;)r.shift()}return m(n,"subtract"),function(r,i,o,s,a,f){var c,p,l,u,g,y,w,D,x,I,k,T,O,W,H,ae,te,Ge,re,_e,xe=r.constructor,He=r.s==i.s?1:-1,Z=r.d,E=i.d;if(!Z||!Z[0]||!E||!E[0])return new xe(!r.s||!i.s||(Z?E&&Z[0]==E[0]:!E)?NaN:Z&&Z[0]==0||!E?He*0:He/0);for(f?(g=1,p=r.e-i.e):(f=we,g=_,p=ie(r.e/g)-ie(i.e/g)),re=E.length,te=Z.length,x=new xe(He),I=x.d=[],l=0;E[l]==(Z[l]||0);l++);if(E[l]>(Z[l]||0)&&p--,o==null?(W=o=xe.precision,s=xe.rounding):a?W=o+(r.e-i.e)+1:W=o,W<0)I.push(1),y=!0;else{if(W=W/g+2|0,l=0,re==1){for(u=0,E=E[0],W++;(l<te||u)&&W--;l++)H=u*f+(Z[l]||0),I[l]=H/E|0,u=H%E|0;y=u||l<te}else{for(u=f/(E[0]+1)|0,u>1&&(E=e(E,u,f),Z=e(Z,u,f),re=E.length,te=Z.length),ae=re,k=Z.slice(0,re),T=k.length;T<re;)k[T++]=0;_e=E.slice(),_e.unshift(0),Ge=E[0],E[1]>=f/2&&++Ge;do u=0,c=t(E,k,re,T),c<0?(O=k[0],re!=T&&(O=O*f+(k[1]||0)),u=O/Ge|0,u>1?(u>=f&&(u=f-1),w=e(E,u,f),D=w.length,T=k.length,c=t(w,k,D,T),c==1&&(u--,n(w,re<D?_e:E,D,f))):(u==0&&(c=u=1),w=E.slice()),D=w.length,D<T&&w.unshift(0),n(k,w,T,f),c==-1&&(T=k.length,c=t(E,k,re,T),c<1&&(u++,n(k,re<T?_e:E,T,f))),T=k.length):c===0&&(u++,k=[0]),I[l++]=u,c&&k[0]?k[T++]=Z[ae]||0:(k=[Z[ae]],T=1);while((ae++<te||k[0]!==void 0)&&W--);y=k[0]!==void 0}I[0]||I.shift()}if(g==1)x.e=p,ar=y;else{for(l=1,u=I[0];u>=10;u/=10)l++;x.e=l+p*g-1,N(x,a?o+x.e+1:o,s,y)}return x}})();function N(e,t,n,r){var i,o,s,a,f,c,p,l,u,g=e.constructor;e:if(t!=null){if(l=e.d,!l)return e;for(i=1,a=l[0];a>=10;a/=10)i++;if(o=t-i,o<0)o+=_,s=t,p=l[u=0],f=p/ee(10,i-s-1)%10|0;else if(u=Math.ceil((o+1)/_),a=l.length,u>=a)if(r){for(;a++<=u;)l.push(0);p=f=0,i=1,o%=_,s=o-_+1}else break e;else{for(p=a=l[u],i=1;a>=10;a/=10)i++;o%=_,s=o-_+i,f=s<0?0:p/ee(10,i-s-1)%10|0}if(r=r||t<0||l[u+1]!==void 0||(s<0?p:p%ee(10,i-s-1)),c=n<4?(f||r)&&(n==0||n==(e.s<0?3:2)):f>5||f==5&&(n==4||r||n==6&&(o>0?s>0?p/ee(10,i-s):0:l[u-1])%10&1||n==(e.s<0?8:7)),t<1||!l[0])return l.length=0,c?(t-=e.e+1,l[0]=ee(10,(_-t%_)%_),e.e=-t||0):l[0]=e.e=0,e;if(o==0?(l.length=u,a=1,u--):(l.length=u+1,a=ee(10,_-o),l[u]=s>0?(p/ee(10,i-s)%ee(10,s)|0)*a:0),c)for(;;)if(u==0){for(o=1,s=l[0];s>=10;s/=10)o++;for(s=l[0]+=a,a=1;s>=10;s/=10)a++;o!=a&&(e.e++,l[0]==we&&(l[0]=1));break}else{if(l[u]+=a,l[u]!=we)break;l[u--]=0,a=1}for(o=l.length;l[--o]===0;)l.pop()}return j&&(e.e>g.maxE?(e.d=null,e.e=NaN):e.e<g.minE&&(e.e=0,e.d=[0])),e}m(N,"finalise");function ke(e,t,n){if(!e.isFinite())return gr(e);var r,i=e.e,o=ne(e.d),s=o.length;return t?(n&&(r=n-s)>0?o=o.charAt(0)+"."+o.slice(1)+Be(r):s>1&&(o=o.charAt(0)+"."+o.slice(1)),o=o+(e.e<0?"e":"e+")+e.e):i<0?(o="0."+Be(-i-1)+o,n&&(r=n-s)>0&&(o+=Be(r))):i>=s?(o+=Be(i+1-s),n&&(r=n-i-1)>0&&(o=o+"."+Be(r))):((r=i+1)<s&&(o=o.slice(0,r)+"."+o.slice(r)),n&&(r=n-s)>0&&(i+1===s&&(o+="."),o+=Be(r))),o}m(ke,"finiteToString");function qt(e,t){var n=e[0];for(t*=_;n>=10;n/=10)t++;return t}m(qt,"getBase10Exponent");function Wt(e,t,n){if(t>ei)throw j=!0,n&&(e.precision=n),Error(cr);return N(new e(Bt),t,1,!0)}m(Wt,"getLn10");function Ee(e,t,n){if(t>wn)throw Error(cr);return N(new e(Ut),t,n,!0)}m(Ee,"getPi");function ur(e){var t=e.length-1,n=t*_+1;if(t=e[t],t){for(;t%10==0;t/=10)n--;for(t=e[0];t>=10;t/=10)n++}return n}m(ur,"getPrecision");function Be(e){for(var t="";e--;)t+="0";return t}m(Be,"getZeroString");function pr(e,t,n,r){var i,o=new e(1),s=Math.ceil(r/_+4);for(j=!1;;){if(n%2&&(o=o.times(t),or(o.d,s)&&(i=!0)),n=ie(n/2),n===0){n=o.d.length-1,i&&o.d[n]===0&&++o.d[n];break}t=t.times(t),or(t.d,s)}return j=!0,o}m(pr,"intPow");function ir(e){return e.d[e.d.length-1]&1}m(ir,"isOdd");function mr(e,t,n){for(var r,i,o=new e(t[0]),s=0;++s<t.length;){if(i=new e(t[s]),!i.s){o=i;break}r=o.cmp(i),(r===n||r===0&&o.s===n)&&(o=i)}return o}m(mr,"maxOrMin");function vn(e,t){var n,r,i,o,s,a,f,c=0,p=0,l=0,u=e.constructor,g=u.rounding,y=u.precision;if(!e.d||!e.d[0]||e.e>17)return new u(e.d?e.d[0]?e.s<0?0:1/0:1:e.s?e.s<0?0:e:NaN);for(t==null?(j=!1,f=y):f=t,a=new u(.03125);e.e>-2;)e=e.times(a),l+=5;for(r=Math.log(ee(2,l))/Math.LN10*2+5|0,f+=r,n=o=s=new u(1),u.precision=f;;){if(o=N(o.times(e),f,1),n=n.times(++p),a=s.plus(V(o,n,f,1)),ne(a.d).slice(0,f)===ne(s.d).slice(0,f)){for(i=l;i--;)s=N(s.times(s),f,1);if(t==null)if(c<3&&St(s.d,f-r,g,c))u.precision=f+=10,n=o=a=new u(1),p=0,c++;else return N(s,u.precision=y,g,j=!0);else return u.precision=y,s}s=a}}m(vn,"naturalExponential");function Ue(e,t){var n,r,i,o,s,a,f,c,p,l,u,g=1,y=10,w=e,D=w.d,x=w.constructor,I=x.rounding,k=x.precision;if(w.s<0||!D||!D[0]||!w.e&&D[0]==1&&D.length==1)return new x(D&&!D[0]?-1/0:w.s!=1?NaN:D?0:w);if(t==null?(j=!1,p=k):p=t,x.precision=p+=y,n=ne(D),r=n.charAt(0),Math.abs(o=w.e)<15e14){for(;r<7&&r!=1||r==1&&n.charAt(1)>3;)w=w.times(e),n=ne(w.d),r=n.charAt(0),g++;o=w.e,r>1?(w=new x("0."+n),o++):w=new x(r+"."+n.slice(1))}else return c=Wt(x,p+2,k).times(o+""),w=Ue(new x(r+"."+n.slice(1)),p-y).plus(c),x.precision=k,t==null?N(w,k,I,j=!0):w;for(l=w,f=s=w=V(w.minus(1),w.plus(1),p,1),u=N(w.times(w),p,1),i=3;;){if(s=N(s.times(u),p,1),c=f.plus(V(s,new x(i),p,1)),ne(c.d).slice(0,p)===ne(f.d).slice(0,p))if(f=f.times(2),o!==0&&(f=f.plus(Wt(x,p+2,k).times(o+""))),f=V(f,new x(g),p,1),t==null)if(St(f.d,p-y,I,a))x.precision=p+=y,c=s=w=V(l.minus(1),l.plus(1),p,1),u=N(w.times(w),p,1),i=a=1;else return N(f,x.precision=k,I,j=!0);else return x.precision=k,f;f=c,i+=2}}m(Ue,"naturalLogarithm");function gr(e){return String(e.s*e.s/0)}m(gr,"nonFiniteToString");function Lt(e,t){var n,r,i;for((n=t.indexOf("."))>-1&&(t=t.replace(".","")),(r=t.search(/e/i))>0?(n<0&&(n=r),n+=+t.slice(r+1),t=t.substring(0,r)):n<0&&(n=t.length),r=0;t.charCodeAt(r)===48;r++);for(i=t.length;t.charCodeAt(i-1)===48;--i);if(t=t.slice(r,i),t){if(i-=r,e.e=n=n-r-1,e.d=[],r=(n+1)%_,n<0&&(r+=_),r<i){for(r&&e.d.push(+t.slice(0,r)),i-=_;r<i;)e.d.push(+t.slice(r,r+=_));t=t.slice(r),r=_-t.length}else r-=i;for(;r--;)t+="0";e.d.push(+t),j&&(e.e>e.constructor.maxE?(e.d=null,e.e=NaN):e.e<e.constructor.minE&&(e.e=0,e.d=[0]))}else e.e=0,e.d=[0];return e}m(Lt,"parseDecimal");function ni(e,t){var n,r,i,o,s,a,f,c,p;if(t.indexOf("_")>-1){if(t=t.replace(/(\d)_(?=\d)/g,"$1"),lr.test(t))return Lt(e,t)}else if(t==="Infinity"||t==="NaN")return+t||(e.s=NaN),e.e=NaN,e.d=null,e;if(Xr.test(t))n=16,t=t.toLowerCase();else if(Qr.test(t))n=2;else if(Kr.test(t))n=8;else throw Error(We+t);for(o=t.search(/p/i),o>0?(f=+t.slice(o+1),t=t.substring(2,o)):t=t.slice(2),o=t.indexOf("."),s=o>=0,r=e.constructor,s&&(t=t.replace(".",""),a=t.length,o=a-o,i=pr(r,new r(n),o,o*2)),c=Ot(t,n,we),p=c.length-1,o=p;c[o]===0;--o)c.pop();return o<0?new r(e.s*0):(e.e=qt(c,p),e.d=c,j=!1,s&&(e=V(e,i,a*4)),f&&(e=e.times(Math.abs(f)<54?ee(2,f):ge.pow(2,f))),j=!0,e)}m(ni,"parseOther");function ri(e,t){var n,r=t.d.length;if(r<3)return t.isZero()?t:ft(e,2,t,t);n=1.4*Math.sqrt(r),n=n>16?16:n|0,t=t.times(1/Vt(5,n)),t=ft(e,2,t,t);for(var i,o=new e(5),s=new e(16),a=new e(20);n--;)i=t.times(t),t=t.times(o.plus(i.times(s.times(i).minus(a))));return t}m(ri,"sine");function ft(e,t,n,r,i){var o,s,a,f,c=1,p=e.precision,l=Math.ceil(p/_);for(j=!1,f=n.times(n),a=new e(r);;){if(s=V(a.times(f),new e(t++*t++),p,1),a=i?r.plus(s):r.minus(s),r=V(s.times(f),new e(t++*t++),p,1),s=a.plus(r),s.d[l]!==void 0){for(o=l;s.d[o]===a.d[o]&&o--;);if(o==-1)break}o=a,a=r,r=s,s=o,c++}return j=!0,s.d.length=l+1,s}m(ft,"taylorSeries");function Vt(e,t){for(var n=e;--t;)n*=e;return n}m(Vt,"tinyPow");function hr(e,t){var n,r=t.s<0,i=Ee(e,e.precision,1),o=i.times(.5);if(t=t.abs(),t.lte(o))return Te=r?4:1,t;if(n=t.divToInt(i),n.isZero())Te=r?3:2;else{if(t=t.minus(n.times(i)),t.lte(o))return Te=ir(n)?r?2:3:r?4:1,t;Te=ir(n)?r?1:4:r?3:2}return t.minus(i).abs()}m(hr,"toLessThanHalfPi");function Dn(e,t,n,r){var i,o,s,a,f,c,p,l,u,g=e.constructor,y=n!==void 0;if(y?(de(n,1,$e),r===void 0?r=g.rounding:de(r,0,8)):(n=g.precision,r=g.rounding),!e.isFinite())p=gr(e);else{for(p=ke(e),s=p.indexOf("."),y?(i=2,t==16?n=n*4-3:t==8&&(n=n*3-2)):i=t,s>=0&&(p=p.replace(".",""),u=new g(1),u.e=p.length-s,u.d=Ot(ke(u),10,i),u.e=u.d.length),l=Ot(p,10,i),o=f=l.length;l[--f]==0;)l.pop();if(!l[0])p=y?"0p+0":"0";else{if(s<0?o--:(e=new g(e),e.d=l,e.e=o,e=V(e,u,n,r,0,i),l=e.d,o=e.e,c=ar),s=l[n],a=i/2,c=c||l[n+1]!==void 0,c=r<4?(s!==void 0||c)&&(r===0||r===(e.s<0?3:2)):s>a||s===a&&(r===4||c||r===6&&l[n-1]&1||r===(e.s<0?8:7)),l.length=n,c)for(;++l[--n]>i-1;)l[n]=0,n||(++o,l.unshift(1));for(f=l.length;!l[f-1];--f);for(s=0,p="";s<f;s++)p+=yn.charAt(l[s]);if(y){if(f>1)if(t==16||t==8){for(s=t==16?4:3,--f;f%s;f++)p+="0";for(l=Ot(p,i,t),f=l.length;!l[f-1];--f);for(s=1,p="1.";s<f;s++)p+=yn.charAt(l[s])}else p=p.charAt(0)+"."+p.slice(1);p=p+(o<0?"p":"p+")+o}else if(o<0){for(;++o;)p="0"+p;p="0."+p}else if(++o>f)for(o-=f;o--;)p+="0";else o<f&&(p=p.slice(0,o)+"."+p.slice(o))}p=(t==16?"0x":t==2?"0b":t==8?"0o":"")+p}return e.s<0?"-"+p:p}m(Dn,"toStringBinary");function or(e,t){if(e.length>t)return e.length=t,!0}m(or,"truncate");function ii(e){return new this(e).abs()}m(ii,"abs");function oi(e){return new this(e).acos()}m(oi,"acos");function si(e){return new this(e).acosh()}m(si,"acosh");function ai(e,t){return new this(e).plus(t)}m(ai,"add");function ci(e){return new this(e).asin()}m(ci,"asin");function fi(e){return new this(e).asinh()}m(fi,"asinh");function di(e){return new this(e).atan()}m(di,"atan");function li(e){return new this(e).atanh()}m(li,"atanh");function ui(e,t){e=new this(e),t=new this(t);var n,r=this.precision,i=this.rounding,o=r+4;return!e.s||!t.s?n=new this(NaN):!e.d&&!t.d?(n=Ee(this,o,1).times(t.s>0?.25:.75),n.s=e.s):!t.d||e.isZero()?(n=t.s<0?Ee(this,r,i):new this(0),n.s=e.s):!e.d||t.isZero()?(n=Ee(this,o,1).times(.5),n.s=e.s):t.s<0?(this.precision=o,this.rounding=1,n=this.atan(V(e,t,o,1)),t=Ee(this,o,1),this.precision=r,this.rounding=i,n=e.s<0?n.minus(t):n.plus(t)):n=this.atan(V(e,t,o,1)),n}m(ui,"atan2");function pi(e){return new this(e).cbrt()}m(pi,"cbrt");function mi(e){return N(e=new this(e),e.e+1,2)}m(mi,"ceil");function gi(e,t,n){return new this(e).clamp(t,n)}m(gi,"clamp");function hi(e){if(!e||typeof e!="object")throw Error($t+"Object expected");var t,n,r,i=e.defaults===!0,o=["precision",1,$e,"rounding",0,8,"toExpNeg",-ct,0,"toExpPos",0,ct,"maxE",0,ct,"minE",-ct,0,"modulo",0,9];for(t=0;t<o.length;t+=3)if(n=o[t],i&&(this[n]=In[n]),(r=e[n])!==void 0)if(ie(r)===r&&r>=o[t+1]&&r<=o[t+2])this[n]=r;else throw Error(We+n+": "+r);if(n="crypto",i&&(this[n]=In[n]),(r=e[n])!==void 0)if(r===!0||r===!1||r===0||r===1)if(r)if(typeof crypto<"u"&&crypto&&(crypto.getRandomValues||crypto.randomBytes))this[n]=!0;else throw Error(fr);else this[n]=!1;else throw Error(We+n+": "+r);return this}m(hi,"config");function yi(e){return new this(e).cos()}m(yi,"cos");function Ii(e){return new this(e).cosh()}m(Ii,"cosh");function yr(e){var t,n,r;function i(o){var s,a,f,c=this;if(!(c instanceof i))return new i(o);if(c.constructor=i,sr(o)){c.s=o.s,j?!o.d||o.e>i.maxE?(c.e=NaN,c.d=null):o.e<i.minE?(c.e=0,c.d=[0]):(c.e=o.e,c.d=o.d.slice()):(c.e=o.e,c.d=o.d?o.d.slice():o.d);return}if(f=typeof o,f==="number"){if(o===0){c.s=1/o<0?-1:1,c.e=0,c.d=[0];return}if(o<0?(o=-o,c.s=-1):c.s=1,o===~~o&&o<1e7){for(s=0,a=o;a>=10;a/=10)s++;j?s>i.maxE?(c.e=NaN,c.d=null):s<i.minE?(c.e=0,c.d=[0]):(c.e=s,c.d=[o]):(c.e=s,c.d=[o]);return}if(o*0!==0){o||(c.s=NaN),c.e=NaN,c.d=null;return}return Lt(c,o.toString())}if(f==="string")return(a=o.charCodeAt(0))===45?(o=o.slice(1),c.s=-1):(a===43&&(o=o.slice(1)),c.s=1),lr.test(o)?Lt(c,o):ni(c,o);if(f==="bigint")return o<0?(o=-o,c.s=-1):c.s=1,Lt(c,o.toString());throw Error(We+o)}if(m(i,"Decimal"),i.prototype=v,i.ROUND_UP=0,i.ROUND_DOWN=1,i.ROUND_CEIL=2,i.ROUND_FLOOR=3,i.ROUND_HALF_UP=4,i.ROUND_HALF_DOWN=5,i.ROUND_HALF_EVEN=6,i.ROUND_HALF_CEIL=7,i.ROUND_HALF_FLOOR=8,i.EUCLID=9,i.config=i.set=hi,i.clone=yr,i.isDecimal=sr,i.abs=ii,i.acos=oi,i.acosh=si,i.add=ai,i.asin=ci,i.asinh=fi,i.atan=di,i.atanh=li,i.atan2=ui,i.cbrt=pi,i.ceil=mi,i.clamp=gi,i.cos=yi,i.cosh=Ii,i.div=wi,i.exp=vi,i.floor=Di,i.hypot=Si,i.ln=Ei,i.log=ki,i.log10=xi,i.log2=bi,i.max=Pi,i.min=Ni,i.mod=Mi,i.mul=Ti,i.pow=_i,i.random=Ci,i.round=Ri,i.sign=ji,i.sin=Ai,i.sinh=Fi,i.sqrt=Oi,i.sub=Li,i.sum=Bi,i.tan=Ui,i.tanh=Wi,i.trunc=$i,e===void 0&&(e={}),e&&e.defaults!==!0)for(r=["precision","rounding","toExpNeg","toExpPos","maxE","minE","modulo","crypto"],t=0;t<r.length;)e.hasOwnProperty(n=r[t++])||(e[n]=this[n]);return i.config(e),i}m(yr,"clone");function wi(e,t){return new this(e).div(t)}m(wi,"div");function vi(e){return new this(e).exp()}m(vi,"exp");function Di(e){return N(e=new this(e),e.e+1,3)}m(Di,"floor");function Si(){var e,t,n=new this(0);for(j=!1,e=0;e<arguments.length;)if(t=new this(arguments[e++]),t.d)n.d&&(n=n.plus(t.times(t)));else{if(t.s)return j=!0,new this(1/0);n=t}return j=!0,n.sqrt()}m(Si,"hypot");function sr(e){return e instanceof ge||e&&e.toStringTag===dr||!1}m(sr,"isDecimalInstance");function Ei(e){return new this(e).ln()}m(Ei,"ln");function ki(e,t){return new this(e).log(t)}m(ki,"log");function bi(e){return new this(e).log(2)}m(bi,"log2");function xi(e){return new this(e).log(10)}m(xi,"log10");function Pi(){return mr(this,arguments,-1)}m(Pi,"max");function Ni(){return mr(this,arguments,1)}m(Ni,"min");function Mi(e,t){return new this(e).mod(t)}m(Mi,"mod");function Ti(e,t){return new this(e).mul(t)}m(Ti,"mul");function _i(e,t){return new this(e).pow(t)}m(_i,"pow");function Ci(e){var t,n,r,i,o=0,s=new this(1),a=[];if(e===void 0?e=this.precision:de(e,1,$e),r=Math.ceil(e/_),this.crypto)if(crypto.getRandomValues)for(t=crypto.getRandomValues(new Uint32Array(r));o<r;)i=t[o],i>=429e7?t[o]=crypto.getRandomValues(new Uint32Array(1))[0]:a[o++]=i%1e7;else if(crypto.randomBytes){for(t=crypto.randomBytes(r*=4);o<r;)i=t[o]+(t[o+1]<<8)+(t[o+2]<<16)+((t[o+3]&127)<<24),i>=214e7?crypto.randomBytes(4).copy(t,o):(a.push(i%1e7),o+=4);o=r/4}else throw Error(fr);else for(;o<r;)a[o++]=Math.random()*1e7|0;for(r=a[--o],e%=_,r&&e&&(i=ee(10,_-e),a[o]=(r/i|0)*i);a[o]===0;o--)a.pop();if(o<0)n=0,a=[0];else{for(n=-1;a[0]===0;n-=_)a.shift();for(r=1,i=a[0];i>=10;i/=10)r++;r<_&&(n-=_-r)}return s.e=n,s.d=a,s}m(Ci,"random");function Ri(e){return N(e=new this(e),e.e+1,this.rounding)}m(Ri,"round");function ji(e){return e=new this(e),e.d?e.d[0]?e.s:0*e.s:e.s||NaN}m(ji,"sign");function Ai(e){return new this(e).sin()}m(Ai,"sin");function Fi(e){return new this(e).sinh()}m(Fi,"sinh");function Oi(e){return new this(e).sqrt()}m(Oi,"sqrt");function Li(e,t){return new this(e).sub(t)}m(Li,"sub");function Bi(){var e=0,t=arguments,n=new this(t[e]);for(j=!1;n.s&&++e<t.length;)n=n.plus(t[e]);return j=!0,N(n,this.precision,this.rounding)}m(Bi,"sum");function Ui(e){return new this(e).tan()}m(Ui,"tan");function Wi(e){return new this(e).tanh()}m(Wi,"tanh");function $i(e){return N(e=new this(e),e.e+1,1)}m($i,"trunc");v[Symbol.for("nodejs.util.inspect.custom")]=v.toString;v[Symbol.toStringTag]="Decimal";var ge=v.constructor=yr(In);Bt=new ge(Bt);Ut=new ge(Ut);var En={};Re(En,{NotFoundError:()=>be,Service:()=>dt,Storage:()=>En,node:()=>to});import oe from"path";var be=class e extends S.TaggedErrorClass()("NotFoundError",{message:S.String}){static{m(this,"NotFoundError")}static isInstance(t){return t instanceof e}},qi=S.Struct({path:S.optional(S.Struct({root:S.optional(S.String)}))}),Vi=S.Struct({id:S.String}),Ji=S.Struct({id:S.String}),zi=S.Struct({additions:Fe,deletions:Fe}),Gi=S.Struct({id:S.String,projectID:S.String,summary:S.Struct({diffs:S.Array(zi)})}),Hi=S.decodeUnknownOption(qi),Zi=S.decodeUnknownOption(Vi),Qi=S.decodeUnknownOption(Ji),Xi=S.decodeUnknownOption(Gi),dt=class extends Ae.Service()("@opencode/Storage"){static{m(this,"Service")}};function Ki(e,t){return oe.join(e,...t)+".json"}m(Ki,"file");function Sn(e){return!e||typeof e!="object"?!1:"code"in e&&e.code==="ENOENT"?!0:"reason"in e&&e.reason&&typeof e.reason=="object"&&"_tag"in e.reason?e.reason._tag==="NotFound":!1}m(Sn,"missing");function Yi(e){let t=Number.parseInt(e,10);return Number.isNaN(t)?0:t}m(Yi,"parseMigration");var Ir=[d.fn("Storage.migration.1")(function*(e,t,n){let r=oe.resolve(e,"../project");if(!(yield*t.isDir(r)))return;let i=yield*t.glob("*",{cwd:r,include:"all"});for(let o of i){let s=oe.join(r,o);if(!(yield*t.isDir(s)))continue;yield*d.logInfo(`migrating project ${o}`);let a=o,f="/";if(a!=="global"){for(let l of yield*t.glob("storage/session/message/*/*.json",{cwd:s,absolute:!0})){let u=Hi(yield*t.readJson(l),{onExcessProperty:"preserve"}),g=je.isSome(u)?u.value.path?.root:void 0;if(g){f=g;break}}if(!f||!(yield*t.isDir(f)))continue;let c=yield*n.run(["rev-list","--max-parents=0","--all"],{cwd:f}),[p]=c.text().split(`
|
|
18
|
+
import{C as Zn,Da as q,La as dn,Ma as Yn,_a as ln,aa as Qn,db as er,h as an,ib as un,k as At,kb as pn,l as Gn,lb as mn,m as Hn,mb as gn,n as vt,o as cn,p as Me,q as fn,r as Y,u as Ft,v as U,w as me,x as le}from"./chunk-DWEYXIQI.js";import{b as Xn,i as Kn}from"./chunk-WKZYINC7.js";import{La as tn,Ma as nn,Oa as Bn,Pa as K,Ra as Se,Sa as yt,Sc as Jn,Va as rn,Wa as It,Ya as Rt,Za as wt,_a as jt,_c as st,ab as Xe,b as Kt,bc as Vn,bd as sn,c as Yt,fd as zn,ha as De,ia as On,ib as Un,ma as Fe,mb as it,nb as Wn,pa as G,pc as ot,qa as en,qb as pe,ta as Ln,ub as $n,uc as on,vb as qn}from"./chunk-7XX6TY62.js";import{t as Ie,x as rt}from"./chunk-VWLJXTZ5.js";import{Bc as gt,Bf as d,Ig as Fn,Tc as ve,aa as je,bb as Ae,bh as Xt,dc as ce,jd as ht,lc as ye,nb as Qt,pd as Ct,pj as S,zd as An}from"./chunk-ELPXQ32J.js";import{a as m,e as Re}from"./chunk-2MRHL4B2.js";var Cn={};Re(Cn,{ArchivedTimestamp:()=>_n,BusyError:()=>Tn,ChildrenInput:()=>Lo,CreateInput:()=>Ao,Event:()=>zo,ForkInput:()=>Fo,GetInput:()=>Oo,GlobalInfo:()=>jo,Info:()=>Ur,MessagesInput:()=>Jo,Metadata:()=>Zt,ProjectInfo:()=>Wr,RemoveInput:()=>Bo,Service:()=>tt,Session:()=>Cn,SetArchivedInput:()=>Wo,SetMetadataInput:()=>$o,SetPermissionInput:()=>qo,SetRevertInput:()=>Vo,SetTitleInput:()=>Uo,fromRow:()=>Mt,getUsage:()=>Ho,isDefaultTitle:()=>No,node:()=>Yo,plan:()=>Go,toRow:()=>Mo,use:()=>Zo});import Nt from"path";var at={};Re(at,{BackgroundJob:()=>at,Service:()=>Oe,node:()=>Zr});var Le={};Re(Le,{BackgroundJob:()=>Le,Service:()=>Oe,make:()=>rr,node:()=>Gr});var Dt={};Re(Dt,{Identifier:()=>Dt,ascending:()=>$r,create:()=>nr,descending:()=>qr,timestamp:()=>Vr});var hn={job:"job",event:"evt",session:"ses",message:"msg",permission:"per",question:"que",part:"prt",pty:"pty",tool:"tool",workspace:"wrk"};function $r(e,t){return tr(e,"ascending",t)}m($r,"ascending");function qr(e,t){return tr(e,"descending",t)}m(qr,"descending");function tr(e,t,n){if(!n)return nr(hn[e],t);if(!n.startsWith(hn[e]))throw new Error(`ID ${n} does not start with ${hn[e]}`);return n}m(tr,"generateID");function nr(e,t,n){return e+"_"+Ln(t==="descending",n)}m(nr,"create");function Vr(e){let t=e.split("_")[0],n=e.slice(t.length+1,t.length+13),r=BigInt("0x"+n);return Number(r/BigInt(4096))}m(Vr,"timestamp");var Oe=class extends Ae.Service()("@opencode/BackgroundJob"){static{m(this,"Service")}};function fe(e){return{...e.info,...e.info.metadata?{metadata:{...e.info.metadata}}:{}}}m(fe,"snapshot");function Jr(e){return e instanceof Error?e.message:String(e)}m(Jr,"errorText");var rr=d.gen(function*(){let e={jobs:yield*Ie.make(new Map),scope:yield*gt.Scope},t=d.fn("BackgroundJob.settle")(function*(l,u,g,y){let w=yield*Ct.currentTimeMillis,D=yield*Ie.modify(e.jobs,x=>{let I=x.get(l);if(!I)return[{},x];if(I.token!==u)return[{},x];if(I.info.status!=="running")return[{info:fe(I)},x];let k=I.pending-1,T=ye.isSuccess(y)&&(!I.output||g>I.output.sequence)?{sequence:g,text:y.value}:I.output;if(ye.isSuccess(y)&&k>0)return[{},new Map(x).set(l,{...I,pending:k,output:T})];let O=ye.isSuccess(y)?"completed":ht.hasInterruptsOnly(y.cause)?"cancelled":"error",W={...I,onPromote:void 0,pending:0,output:T,info:{...I.info,status:O,completed_at:w,...T?{output:T.text}:{},...ye.isFailure(y)?{error:Jr(ht.squash(y.cause))}:{}}};return[{info:fe(W),done:I.done,scope:I.scope},new Map(x).set(l,W)]});return D.info&&D.done&&(yield*ce.succeed(D.done,D.info).pipe(d.ignore)),D.scope&&(yield*gt.close(D.scope,ye.void).pipe(d.forkIn(e.scope,{startImmediately:!0}))),D.info}),n=d.fn("BackgroundJob.fork")(function*(l,u,g,y,w){return yield*w.pipe(d.matchCauseEffect({onSuccess:m(D=>t(u,g,y,ye.succeed(D)),"onSuccess"),onFailure:m(D=>t(u,g,y,ye.failCause(D)),"onFailure")}),d.asVoid,d.forkIn(l,{startImmediately:!0}))}),r=d.fn("BackgroundJob.list")(function*(){return Array.from((yield*Ie.get(e.jobs)).values()).map(fe).toSorted((l,u)=>l.started_at-u.started_at)}),i=d.fn("BackgroundJob.get")(function*(l){let u=(yield*Ie.get(e.jobs)).get(l);if(u)return fe(u)}),o=d.fn("BackgroundJob.start")(function*(l){return yield*d.uninterruptibleMask(u=>d.gen(function*(){let g=l.id??Dt.ascending("job"),y=yield*Ct.currentTimeMillis,w=yield*ce.make(),D=yield*ce.make(),x=yield*ce.make(),I=yield*Ie.modifyEffect(e.jobs,d.fnUntraced(function*(k){let T=k.get(g);if(T?.info.status==="running")return[{info:fe(T)},k];let O=yield*gt.fork(e.scope,"parallel"),W={},H={info:{id:g,type:l.type,title:l.title,status:"running",started_at:y,metadata:l.metadata},done:w,scope:O,token:W,pending:1,next:1,tail:x,promoted:D,onPromote:l.onPromote};return[{info:fe(H),scope:O,token:W},new Map(k).set(g,H)]}));return"scope"in I&&(yield*n(I.scope,g,I.token,0,u(l.run).pipe(d.ensuring(ce.succeed(x,void 0))))),I.info}))}),s=d.fn("BackgroundJob.extend")(function*(l){return yield*d.uninterruptibleMask(u=>d.gen(function*(){let g=yield*ce.make(),y=yield*Ie.modify(e.jobs,w=>{let D=w.get(l.id);return!D||D.info.status!=="running"?[{extended:!1},w]:[{extended:!0,previous:D.tail,scope:D.scope,tail:g,token:D.token,sequence:D.next},new Map(w).set(l.id,{...D,pending:D.pending+1,next:D.next+1,tail:g})]});return y.extended?(yield*n(y.scope,l.id,y.token,y.sequence,ce.await(y.previous).pipe(d.andThen(u(l.run)),d.ensuring(ce.succeed(y.tail,void 0)))),!0):!1}))}),a=d.fn("BackgroundJob.wait")(function*(l){let u=(yield*Ie.get(e.jobs)).get(l.id);if(!u)return{timedOut:!1};if(u.info.status!=="running")return{info:fe(u),timedOut:!1};if(l.timeout===void 0)return{info:yield*ce.await(u.done),timedOut:!1};if(l.timeout<=0)return{info:fe(u),timedOut:!0};let g=yield*ce.await(u.done).pipe(d.timeoutOption(l.timeout));return g._tag==="Some"?{info:g.value,timedOut:!1}:{info:fe(u),timedOut:!0}}),f=d.fn("BackgroundJob.waitForPromotion")(function*(l){let u=(yield*Ie.get(e.jobs)).get(l);return!u||u.info.status!=="running"?yield*d.never:u.info.metadata?.background===!0?fe(u):yield*ce.await(u.promoted)}),c=d.fn("BackgroundJob.promote")(function*(l){let u=yield*Ie.modifyEffect(e.jobs,d.fnUntraced(function*(g){let y=g.get(l);if(!y||y.info.status!=="running")return[{},g];if(y.info.metadata?.background===!0)return[{info:fe(y)},g];let w={...y,onPromote:void 0,info:{...y.info,metadata:{...y.info.metadata,background:!0}}};return[{info:fe(w),onPromote:y.onPromote,promoted:y.promoted},new Map(g).set(l,w)]}));return u.info&&u.promoted&&(yield*ce.succeed(u.promoted,u.info).pipe(d.ignore)),u.onPromote&&(yield*u.onPromote.pipe(d.ignore)),u.info}),p=d.fn("BackgroundJob.cancel")(function*(l){let u=yield*Ct.currentTimeMillis,g=yield*Ie.modify(e.jobs,y=>{let w=y.get(l);if(!w)return[{},y];if(w.info.status!=="running")return[{info:fe(w)},y];let D={...w,onPromote:void 0,pending:0,info:{...w.info,status:"cancelled",completed_at:u}};return[{info:fe(D),done:w.done,scope:w.scope},new Map(y).set(l,D)]});return g.info&&g.done&&(yield*ce.succeed(g.done,g.info).pipe(d.ignore)),g.scope&&(yield*gt.close(g.scope,ye.void)),g.info});return Oe.of({list:r,get:i,start:o,extend:s,wait:a,waitForPromotion:f,promote:c,cancel:p})}),zr=ve.effect(Oe,rr),Gr=On({service:Oe,layer:zr,deps:[]});var Hr=ve.effect(Le.Service,d.gen(function*(){let e=yield*q.make(()=>Le.make);return Le.Service.of({list:m(()=>q.useEffect(e,t=>t.list()),"list"),get:m(t=>q.useEffect(e,n=>n.get(t)),"get"),start:m(t=>q.useEffect(e,n=>n.start(t)),"start"),extend:m(t=>q.useEffect(e,n=>n.extend(t)),"extend"),wait:m(t=>q.useEffect(e,n=>n.wait(t)),"wait"),waitForPromotion:m(t=>q.useEffect(e,n=>n.waitForPromotion(t)),"waitForPromotion"),promote:m(t=>q.useEffect(e,n=>n.promote(t)),"promote"),cancel:m(t=>q.useEffect(e,n=>n.cancel(t)),"cancel")})})),Zr=De.make({service:Le.Service,layer:Hr,deps:[]});var ct=9e15,$e=1e9,yn="0123456789abcdef",Bt="2.3025850929940456840179914546843642076011014886287729760333279009675726096773524802359972050895982983419677840422862486334095254650828067566662873690987816894829072083255546808437998948262331985283935053089653777326288461633662222876982198867465436674744042432743651550489343149393914796194044002221051017141748003688084012647080685567743216228355220114804663715659121373450747856947683463616792101806445070648000277502684916746550586856935673420670581136429224554405758925724208241314695689016758940256776311356919292033376587141660230105703089634572075440370847469940168269282808481184289314848524948644871927809676271275775397027668605952496716674183485704422507197965004714951050492214776567636938662976979522110718264549734772662425709429322582798502585509785265383207606726317164309505995087807523710333101197857547331541421808427543863591778117054309827482385045648019095610299291824318237525357709750539565187697510374970888692180205189339507238539205144634197265287286965110862571492198849978748873771345686209167058",Ut="3.1415926535897932384626433832795028841971693993751058209749445923078164062862089986280348253421170679821480865132823066470938446095505822317253594081284811174502841027019385211055596446229489549303819644288109756659334461284756482337867831652712019091456485669234603486104543266482133936072602491412737245870066063155881748815209209628292540917153643678925903600113305305488204665213841469519415116094330572703657595919530921861173819326117931051185480744623799627495673518857527248912279381830119491298336733624406566430860213949463952247371907021798609437027705392171762931767523846748184676694051320005681271452635608277857713427577896091736371787214684409012249534301465495853710507922796892589235420199561121290219608640344181598136297747713099605187072113499999983729780499510597317328160963185950244594553469083026425223082533446850352619311881710100031378387528865875332083814206171776691473035982534904287554687311595628638823537875937519577818577805321712268066130019278766111959092164201989380952572010654858632789",In={precision:20,rounding:4,modulo:1,toExpNeg:-7,toExpPos:21,minE:-ct,maxE:ct,crypto:!1},ar,Te,j=!0,$t="[DecimalError] ",We=$t+"Invalid argument: ",cr=$t+"Precision limit exceeded",fr=$t+"crypto unavailable",dr="[object Decimal]",ie=Math.floor,ee=Math.pow,Qr=/^0b([01]+(\.[01]*)?|\.[01]+)(p[+-]?\d+)?$/i,Xr=/^0x([0-9a-f]+(\.[0-9a-f]*)?|\.[0-9a-f]+)(p[+-]?\d+)?$/i,Kr=/^0o([0-7]+(\.[0-7]*)?|\.[0-7]+)(p[+-]?\d+)?$/i,lr=/^(\d+(\.\d*)?|\.\d+)(e[+-]?\d+)?$/i,we=1e7,_=7,Yr=9007199254740991,ei=Bt.length-1,wn=Ut.length-1,v={toStringTag:dr};v.absoluteValue=v.abs=function(){var e=new this.constructor(this);return e.s<0&&(e.s=1),N(e)};v.ceil=function(){return N(new this.constructor(this),this.e+1,2)};v.clampedTo=v.clamp=function(e,t){var n,r=this,i=r.constructor;if(e=new i(e),t=new i(t),!e.s||!t.s)return new i(NaN);if(e.gt(t))throw Error(We+t);return n=r.cmp(e),n<0?e:r.cmp(t)>0?t:new i(r)};v.comparedTo=v.cmp=function(e){var t,n,r,i,o=this,s=o.d,a=(e=new o.constructor(e)).d,f=o.s,c=e.s;if(!s||!a)return!f||!c?NaN:f!==c?f:s===a?0:!s^f<0?1:-1;if(!s[0]||!a[0])return s[0]?f:a[0]?-c:0;if(f!==c)return f;if(o.e!==e.e)return o.e>e.e^f<0?1:-1;for(r=s.length,i=a.length,t=0,n=r<i?r:i;t<n;++t)if(s[t]!==a[t])return s[t]>a[t]^f<0?1:-1;return r===i?0:r>i^f<0?1:-1};v.cosine=v.cos=function(){var e,t,n=this,r=n.constructor;return n.d?n.d[0]?(e=r.precision,t=r.rounding,r.precision=e+Math.max(n.e,n.sd())+_,r.rounding=1,n=ti(r,hr(r,n)),r.precision=e,r.rounding=t,N(Te==2||Te==3?n.neg():n,e,t,!0)):new r(1):new r(NaN)};v.cubeRoot=v.cbrt=function(){var e,t,n,r,i,o,s,a,f,c,p=this,l=p.constructor;if(!p.isFinite()||p.isZero())return new l(p);for(j=!1,o=p.s*ee(p.s*p,1/3),!o||Math.abs(o)==1/0?(n=ne(p.d),e=p.e,(o=(e-n.length+1)%3)&&(n+=o==1||o==-2?"0":"00"),o=ee(n,1/3),e=ie((e+1)/3)-(e%3==(e<0?-1:2)),o==1/0?n="5e"+e:(n=o.toExponential(),n=n.slice(0,n.indexOf("e")+1)+e),r=new l(n),r.s=p.s):r=new l(o.toString()),s=(e=l.precision)+3;;)if(a=r,f=a.times(a).times(a),c=f.plus(p),r=V(c.plus(p).times(a),c.plus(f),s+2,1),ne(a.d).slice(0,s)===(n=ne(r.d)).slice(0,s))if(n=n.slice(s-3,s+1),n=="9999"||!i&&n=="4999"){if(!i&&(N(a,e+1,0),a.times(a).times(a).eq(p))){r=a;break}s+=4,i=1}else{(!+n||!+n.slice(1)&&n.charAt(0)=="5")&&(N(r,e+1,1),t=!r.times(r).times(r).eq(p));break}return j=!0,N(r,e,l.rounding,t)};v.decimalPlaces=v.dp=function(){var e,t=this.d,n=NaN;if(t){if(e=t.length-1,n=(e-ie(this.e/_))*_,e=t[e],e)for(;e%10==0;e/=10)n--;n<0&&(n=0)}return n};v.dividedBy=v.div=function(e){return V(this,new this.constructor(e))};v.dividedToIntegerBy=v.divToInt=function(e){var t=this,n=t.constructor;return N(V(t,new n(e),0,1,1),n.precision,n.rounding)};v.equals=v.eq=function(e){return this.cmp(e)===0};v.floor=function(){return N(new this.constructor(this),this.e+1,3)};v.greaterThan=v.gt=function(e){return this.cmp(e)>0};v.greaterThanOrEqualTo=v.gte=function(e){var t=this.cmp(e);return t==1||t===0};v.hyperbolicCosine=v.cosh=function(){var e,t,n,r,i,o=this,s=o.constructor,a=new s(1);if(!o.isFinite())return new s(o.s?1/0:NaN);if(o.isZero())return a;n=s.precision,r=s.rounding,s.precision=n+Math.max(o.e,o.sd())+4,s.rounding=1,i=o.d.length,i<32?(e=Math.ceil(i/3),t=(1/Vt(4,e)).toString()):(e=16,t="2.3283064365386962890625e-10"),o=ft(s,1,o.times(t),new s(1),!0);for(var f,c=e,p=new s(8);c--;)f=o.times(o),o=a.minus(f.times(p.minus(f.times(p))));return N(o,s.precision=n,s.rounding=r,!0)};v.hyperbolicSine=v.sinh=function(){var e,t,n,r,i=this,o=i.constructor;if(!i.isFinite()||i.isZero())return new o(i);if(t=o.precision,n=o.rounding,o.precision=t+Math.max(i.e,i.sd())+4,o.rounding=1,r=i.d.length,r<3)i=ft(o,2,i,i,!0);else{e=1.4*Math.sqrt(r),e=e>16?16:e|0,i=i.times(1/Vt(5,e)),i=ft(o,2,i,i,!0);for(var s,a=new o(5),f=new o(16),c=new o(20);e--;)s=i.times(i),i=i.times(a.plus(s.times(f.times(s).plus(c))))}return o.precision=t,o.rounding=n,N(i,t,n,!0)};v.hyperbolicTangent=v.tanh=function(){var e,t,n=this,r=n.constructor;return n.isFinite()?n.isZero()?new r(n):(e=r.precision,t=r.rounding,r.precision=e+7,r.rounding=1,V(n.sinh(),n.cosh(),r.precision=e,r.rounding=t)):new r(n.s)};v.inverseCosine=v.acos=function(){var e=this,t=e.constructor,n=e.abs().cmp(1),r=t.precision,i=t.rounding;return n!==-1?n===0?e.isNeg()?Ee(t,r,i):new t(0):new t(NaN):e.isZero()?Ee(t,r+4,i).times(.5):(t.precision=r+6,t.rounding=1,e=new t(1).minus(e).div(e.plus(1)).sqrt().atan(),t.precision=r,t.rounding=i,e.times(2))};v.inverseHyperbolicCosine=v.acosh=function(){var e,t,n=this,r=n.constructor;return n.lte(1)?new r(n.eq(1)?0:NaN):n.isFinite()?(e=r.precision,t=r.rounding,r.precision=e+Math.max(Math.abs(n.e),n.sd())+4,r.rounding=1,j=!1,n=n.times(n).minus(1).sqrt().plus(n),j=!0,r.precision=e,r.rounding=t,n.ln()):new r(n)};v.inverseHyperbolicSine=v.asinh=function(){var e,t,n=this,r=n.constructor;return!n.isFinite()||n.isZero()?new r(n):(e=r.precision,t=r.rounding,r.precision=e+2*Math.max(Math.abs(n.e),n.sd())+6,r.rounding=1,j=!1,n=n.times(n).plus(1).sqrt().plus(n),j=!0,r.precision=e,r.rounding=t,n.ln())};v.inverseHyperbolicTangent=v.atanh=function(){var e,t,n,r,i=this,o=i.constructor;return i.isFinite()?i.e>=0?new o(i.abs().eq(1)?i.s/0:i.isZero()?i:NaN):(e=o.precision,t=o.rounding,r=i.sd(),Math.max(r,e)<2*-i.e-1?N(new o(i),e,t,!0):(o.precision=n=r-i.e,i=V(i.plus(1),new o(1).minus(i),n+e,1),o.precision=e+4,o.rounding=1,i=i.ln(),o.precision=e,o.rounding=t,i.times(.5))):new o(NaN)};v.inverseSine=v.asin=function(){var e,t,n,r,i=this,o=i.constructor;return i.isZero()?new o(i):(t=i.abs().cmp(1),n=o.precision,r=o.rounding,t!==-1?t===0?(e=Ee(o,n+4,r).times(.5),e.s=i.s,e):new o(NaN):(o.precision=n+6,o.rounding=1,i=i.div(new o(1).minus(i.times(i)).sqrt().plus(1)).atan(),o.precision=n,o.rounding=r,i.times(2)))};v.inverseTangent=v.atan=function(){var e,t,n,r,i,o,s,a,f,c=this,p=c.constructor,l=p.precision,u=p.rounding;if(c.isFinite()){if(c.isZero())return new p(c);if(c.abs().eq(1)&&l+4<=wn)return s=Ee(p,l+4,u).times(.25),s.s=c.s,s}else{if(!c.s)return new p(NaN);if(l+4<=wn)return s=Ee(p,l+4,u).times(.5),s.s=c.s,s}for(p.precision=a=l+10,p.rounding=1,n=Math.min(28,a/_+2|0),e=n;e;--e)c=c.div(c.times(c).plus(1).sqrt().plus(1));for(j=!1,t=Math.ceil(a/_),r=1,f=c.times(c),s=new p(c),i=c;e!==-1;)if(i=i.times(f),o=s.minus(i.div(r+=2)),i=i.times(f),s=o.plus(i.div(r+=2)),s.d[t]!==void 0)for(e=t;s.d[e]===o.d[e]&&e--;);return n&&(s=s.times(2<<n-1)),j=!0,N(s,p.precision=l,p.rounding=u,!0)};v.isFinite=function(){return!!this.d};v.isInteger=v.isInt=function(){return!!this.d&&ie(this.e/_)>this.d.length-2};v.isNaN=function(){return!this.s};v.isNegative=v.isNeg=function(){return this.s<0};v.isPositive=v.isPos=function(){return this.s>0};v.isZero=function(){return!!this.d&&this.d[0]===0};v.lessThan=v.lt=function(e){return this.cmp(e)<0};v.lessThanOrEqualTo=v.lte=function(e){return this.cmp(e)<1};v.logarithm=v.log=function(e){var t,n,r,i,o,s,a,f,c=this,p=c.constructor,l=p.precision,u=p.rounding,g=5;if(e==null)e=new p(10),t=!0;else{if(e=new p(e),n=e.d,e.s<0||!n||!n[0]||e.eq(1))return new p(NaN);t=e.eq(10)}if(n=c.d,c.s<0||!n||!n[0]||c.eq(1))return new p(n&&!n[0]?-1/0:c.s!=1?NaN:n?0:1/0);if(t)if(n.length>1)o=!0;else{for(i=n[0];i%10===0;)i/=10;o=i!==1}if(j=!1,a=l+g,s=Ue(c,a),r=t?Wt(p,a+10):Ue(e,a),f=V(s,r,a,1),St(f.d,i=l,u))do if(a+=10,s=Ue(c,a),r=t?Wt(p,a+10):Ue(e,a),f=V(s,r,a,1),!o){+ne(f.d).slice(i+1,i+15)+1==1e14&&(f=N(f,l+1,0));break}while(St(f.d,i+=10,u));return j=!0,N(f,l,u)};v.minus=v.sub=function(e){var t,n,r,i,o,s,a,f,c,p,l,u,g=this,y=g.constructor;if(e=new y(e),!g.d||!e.d)return!g.s||!e.s?e=new y(NaN):g.d?e.s=-e.s:e=new y(e.d||g.s!==e.s?g:NaN),e;if(g.s!=e.s)return e.s=-e.s,g.plus(e);if(c=g.d,u=e.d,a=y.precision,f=y.rounding,!c[0]||!u[0]){if(u[0])e.s=-e.s;else if(c[0])e=new y(g);else return new y(f===3?-0:0);return j?N(e,a,f):e}if(n=ie(e.e/_),p=ie(g.e/_),c=c.slice(),o=p-n,o){for(l=o<0,l?(t=c,o=-o,s=u.length):(t=u,n=p,s=c.length),r=Math.max(Math.ceil(a/_),s)+2,o>r&&(o=r,t.length=1),t.reverse(),r=o;r--;)t.push(0);t.reverse()}else{for(r=c.length,s=u.length,l=r<s,l&&(s=r),r=0;r<s;r++)if(c[r]!=u[r]){l=c[r]<u[r];break}o=0}for(l&&(t=c,c=u,u=t,e.s=-e.s),s=c.length,r=u.length-s;r>0;--r)c[s++]=0;for(r=u.length;r>o;){if(c[--r]<u[r]){for(i=r;i&&c[--i]===0;)c[i]=we-1;--c[i],c[r]+=we}c[r]-=u[r]}for(;c[--s]===0;)c.pop();for(;c[0]===0;c.shift())--n;return c[0]?(e.d=c,e.e=qt(c,n),j?N(e,a,f):e):new y(f===3?-0:0)};v.modulo=v.mod=function(e){var t,n=this,r=n.constructor;return e=new r(e),!n.d||!e.s||e.d&&!e.d[0]?new r(NaN):!e.d||n.d&&!n.d[0]?N(new r(n),r.precision,r.rounding):(j=!1,r.modulo==9?(t=V(n,e.abs(),0,3,1),t.s*=e.s):t=V(n,e,0,r.modulo,1),t=t.times(e),j=!0,n.minus(t))};v.naturalExponential=v.exp=function(){return vn(this)};v.naturalLogarithm=v.ln=function(){return Ue(this)};v.negated=v.neg=function(){var e=new this.constructor(this);return e.s=-e.s,N(e)};v.plus=v.add=function(e){var t,n,r,i,o,s,a,f,c,p,l=this,u=l.constructor;if(e=new u(e),!l.d||!e.d)return!l.s||!e.s?e=new u(NaN):l.d||(e=new u(e.d||l.s===e.s?l:NaN)),e;if(l.s!=e.s)return e.s=-e.s,l.minus(e);if(c=l.d,p=e.d,a=u.precision,f=u.rounding,!c[0]||!p[0])return p[0]||(e=new u(l)),j?N(e,a,f):e;if(o=ie(l.e/_),r=ie(e.e/_),c=c.slice(),i=o-r,i){for(i<0?(n=c,i=-i,s=p.length):(n=p,r=o,s=c.length),o=Math.ceil(a/_),s=o>s?o+1:s+1,i>s&&(i=s,n.length=1),n.reverse();i--;)n.push(0);n.reverse()}for(s=c.length,i=p.length,s-i<0&&(i=s,n=p,p=c,c=n),t=0;i;)t=(c[--i]=c[i]+p[i]+t)/we|0,c[i]%=we;for(t&&(c.unshift(t),++r),s=c.length;c[--s]==0;)c.pop();return e.d=c,e.e=qt(c,r),j?N(e,a,f):e};v.precision=v.sd=function(e){var t,n=this;if(e!==void 0&&e!==!!e&&e!==1&&e!==0)throw Error(We+e);return n.d?(t=ur(n.d),e&&n.e+1>t&&(t=n.e+1)):t=NaN,t};v.round=function(){var e=this,t=e.constructor;return N(new t(e),e.e+1,t.rounding)};v.sine=v.sin=function(){var e,t,n=this,r=n.constructor;return n.isFinite()?n.isZero()?new r(n):(e=r.precision,t=r.rounding,r.precision=e+Math.max(n.e,n.sd())+_,r.rounding=1,n=ri(r,hr(r,n)),r.precision=e,r.rounding=t,N(Te>2?n.neg():n,e,t,!0)):new r(NaN)};v.squareRoot=v.sqrt=function(){var e,t,n,r,i,o,s=this,a=s.d,f=s.e,c=s.s,p=s.constructor;if(c!==1||!a||!a[0])return new p(!c||c<0&&(!a||a[0])?NaN:a?s:1/0);for(j=!1,c=Math.sqrt(+s),c==0||c==1/0?(t=ne(a),(t.length+f)%2==0&&(t+="0"),c=Math.sqrt(t),f=ie((f+1)/2)-(f<0||f%2),c==1/0?t="5e"+f:(t=c.toExponential(),t=t.slice(0,t.indexOf("e")+1)+f),r=new p(t)):r=new p(c.toString()),n=(f=p.precision)+3;;)if(o=r,r=o.plus(V(s,o,n+2,1)).times(.5),ne(o.d).slice(0,n)===(t=ne(r.d)).slice(0,n))if(t=t.slice(n-3,n+1),t=="9999"||!i&&t=="4999"){if(!i&&(N(o,f+1,0),o.times(o).eq(s))){r=o;break}n+=4,i=1}else{(!+t||!+t.slice(1)&&t.charAt(0)=="5")&&(N(r,f+1,1),e=!r.times(r).eq(s));break}return j=!0,N(r,f,p.rounding,e)};v.tangent=v.tan=function(){var e,t,n=this,r=n.constructor;return n.isFinite()?n.isZero()?new r(n):(e=r.precision,t=r.rounding,r.precision=e+10,r.rounding=1,n=n.sin(),n.s=1,n=V(n,new r(1).minus(n.times(n)).sqrt(),e+10,0),r.precision=e,r.rounding=t,N(Te==2||Te==4?n.neg():n,e,t,!0)):new r(NaN)};v.times=v.mul=function(e){var t,n,r,i,o,s,a,f,c,p=this,l=p.constructor,u=p.d,g=(e=new l(e)).d;if(e.s*=p.s,!u||!u[0]||!g||!g[0])return new l(!e.s||u&&!u[0]&&!g||g&&!g[0]&&!u?NaN:!u||!g?e.s/0:e.s*0);for(n=ie(p.e/_)+ie(e.e/_),f=u.length,c=g.length,f<c&&(o=u,u=g,g=o,s=f,f=c,c=s),o=[],s=f+c,r=s;r--;)o.push(0);for(r=c;--r>=0;){for(t=0,i=f+r;i>r;)a=o[i]+g[r]*u[i-r-1]+t,o[i--]=a%we|0,t=a/we|0;o[i]=(o[i]+t)%we|0}for(;!o[--s];)o.pop();return t?++n:o.shift(),e.d=o,e.e=qt(o,n),j?N(e,l.precision,l.rounding):e};v.toBinary=function(e,t){return Dn(this,2,e,t)};v.toDecimalPlaces=v.toDP=function(e,t){var n=this,r=n.constructor;return n=new r(n),e===void 0?n:(de(e,0,$e),t===void 0?t=r.rounding:de(t,0,8),N(n,e+n.e+1,t))};v.toExponential=function(e,t){var n,r=this,i=r.constructor;return e===void 0?n=ke(r,!0):(de(e,0,$e),t===void 0?t=i.rounding:de(t,0,8),r=N(new i(r),e+1,t),n=ke(r,!0,e+1)),r.isNeg()&&!r.isZero()?"-"+n:n};v.toFixed=function(e,t){var n,r,i=this,o=i.constructor;return e===void 0?n=ke(i):(de(e,0,$e),t===void 0?t=o.rounding:de(t,0,8),r=N(new o(i),e+i.e+1,t),n=ke(r,!1,e+r.e+1)),i.isNeg()&&!i.isZero()?"-"+n:n};v.toFraction=function(e){var t,n,r,i,o,s,a,f,c,p,l,u,g=this,y=g.d,w=g.constructor;if(!y)return new w(g);if(c=n=new w(1),r=f=new w(0),t=new w(r),o=t.e=ur(y)-g.e-1,s=o%_,t.d[0]=ee(10,s<0?_+s:s),e==null)e=o>0?t:c;else{if(a=new w(e),!a.isInt()||a.lt(c))throw Error(We+a);e=a.gt(t)?o>0?t:c:a}for(j=!1,a=new w(ne(y)),p=w.precision,w.precision=o=y.length*_*2;l=V(a,t,0,1,1),i=n.plus(l.times(r)),i.cmp(e)!=1;)n=r,r=i,i=c,c=f.plus(l.times(i)),f=i,i=t,t=a.minus(l.times(i)),a=i;return i=V(e.minus(n),r,0,1,1),f=f.plus(i.times(c)),n=n.plus(i.times(r)),f.s=c.s=g.s,u=V(c,r,o,1).minus(g).abs().cmp(V(f,n,o,1).minus(g).abs())<1?[c,r]:[f,n],w.precision=p,j=!0,u};v.toHexadecimal=v.toHex=function(e,t){return Dn(this,16,e,t)};v.toNearest=function(e,t){var n=this,r=n.constructor;if(n=new r(n),e==null){if(!n.d)return n;e=new r(1),t=r.rounding}else{if(e=new r(e),t===void 0?t=r.rounding:de(t,0,8),!n.d)return e.s?n:e;if(!e.d)return e.s&&(e.s=n.s),e}return e.d[0]?(j=!1,n=V(n,e,0,t,1).times(e),j=!0,N(n)):(e.s=n.s,n=e),n};v.toNumber=function(){return+this};v.toOctal=function(e,t){return Dn(this,8,e,t)};v.toPower=v.pow=function(e){var t,n,r,i,o,s,a=this,f=a.constructor,c=+(e=new f(e));if(!a.d||!e.d||!a.d[0]||!e.d[0])return new f(ee(+a,c));if(a=new f(a),a.eq(1))return a;if(r=f.precision,o=f.rounding,e.eq(1))return N(a,r,o);if(t=ie(e.e/_),t>=e.d.length-1&&(n=c<0?-c:c)<=Yr)return i=pr(f,a,n,r),e.s<0?new f(1).div(i):N(i,r,o);if(s=a.s,s<0){if(t<e.d.length-1)return new f(NaN);if((e.d[t]&1)==0&&(s=1),a.e==0&&a.d[0]==1&&a.d.length==1)return a.s=s,a}return n=ee(+a,c),t=n==0||!isFinite(n)?ie(c*(Math.log("0."+ne(a.d))/Math.LN10+a.e+1)):new f(n+"").e,t>f.maxE+1||t<f.minE-1?new f(t>0?s/0:0):(j=!1,f.rounding=a.s=1,n=Math.min(12,(t+"").length),i=vn(e.times(Ue(a,r+n)),r),i.d&&(i=N(i,r+5,1),St(i.d,r,o)&&(t=r+10,i=N(vn(e.times(Ue(a,t+n)),t),t+5,1),+ne(i.d).slice(r+1,r+15)+1==1e14&&(i=N(i,r+1,0)))),i.s=s,j=!0,f.rounding=o,N(i,r,o))};v.toPrecision=function(e,t){var n,r=this,i=r.constructor;return e===void 0?n=ke(r,r.e<=i.toExpNeg||r.e>=i.toExpPos):(de(e,1,$e),t===void 0?t=i.rounding:de(t,0,8),r=N(new i(r),e,t),n=ke(r,e<=r.e||r.e<=i.toExpNeg,e)),r.isNeg()&&!r.isZero()?"-"+n:n};v.toSignificantDigits=v.toSD=function(e,t){var n=this,r=n.constructor;return e===void 0?(e=r.precision,t=r.rounding):(de(e,1,$e),t===void 0?t=r.rounding:de(t,0,8)),N(new r(n),e,t)};v.toString=function(){var e=this,t=e.constructor,n=ke(e,e.e<=t.toExpNeg||e.e>=t.toExpPos);return e.isNeg()&&!e.isZero()?"-"+n:n};v.truncated=v.trunc=function(){return N(new this.constructor(this),this.e+1,1)};v.valueOf=v.toJSON=function(){var e=this,t=e.constructor,n=ke(e,e.e<=t.toExpNeg||e.e>=t.toExpPos);return e.isNeg()?"-"+n:n};function ne(e){var t,n,r,i=e.length-1,o="",s=e[0];if(i>0){for(o+=s,t=1;t<i;t++)r=e[t]+"",n=_-r.length,n&&(o+=Be(n)),o+=r;s=e[t],r=s+"",n=_-r.length,n&&(o+=Be(n))}else if(s===0)return"0";for(;s%10===0;)s/=10;return o+s}m(ne,"digitsToString");function de(e,t,n){if(e!==~~e||e<t||e>n)throw Error(We+e)}m(de,"checkInt32");function St(e,t,n,r){var i,o,s,a;for(o=e[0];o>=10;o/=10)--t;return--t<0?(t+=_,i=0):(i=Math.ceil((t+1)/_),t%=_),o=ee(10,_-t),a=e[i]%o|0,r==null?t<3?(t==0?a=a/100|0:t==1&&(a=a/10|0),s=n<4&&a==99999||n>3&&a==49999||a==5e4||a==0):s=(n<4&&a+1==o||n>3&&a+1==o/2)&&(e[i+1]/o/100|0)==ee(10,t-2)-1||(a==o/2||a==0)&&(e[i+1]/o/100|0)==0:t<4?(t==0?a=a/1e3|0:t==1?a=a/100|0:t==2&&(a=a/10|0),s=(r||n<4)&&a==9999||!r&&n>3&&a==4999):s=((r||n<4)&&a+1==o||!r&&n>3&&a+1==o/2)&&(e[i+1]/o/1e3|0)==ee(10,t-3)-1,s}m(St,"checkRoundingDigits");function Ot(e,t,n){for(var r,i=[0],o,s=0,a=e.length;s<a;){for(o=i.length;o--;)i[o]*=t;for(i[0]+=yn.indexOf(e.charAt(s++)),r=0;r<i.length;r++)i[r]>n-1&&(i[r+1]===void 0&&(i[r+1]=0),i[r+1]+=i[r]/n|0,i[r]%=n)}return i.reverse()}m(Ot,"convertBase");function ti(e,t){var n,r,i;if(t.isZero())return t;r=t.d.length,r<32?(n=Math.ceil(r/3),i=(1/Vt(4,n)).toString()):(n=16,i="2.3283064365386962890625e-10"),e.precision+=n,t=ft(e,1,t.times(i),new e(1));for(var o=n;o--;){var s=t.times(t);t=s.times(s).minus(s).times(8).plus(1)}return e.precision-=n,t}m(ti,"cosine");var V=(function(){function e(r,i,o){var s,a=0,f=r.length;for(r=r.slice();f--;)s=r[f]*i+a,r[f]=s%o|0,a=s/o|0;return a&&r.unshift(a),r}m(e,"multiplyInteger");function t(r,i,o,s){var a,f;if(o!=s)f=o>s?1:-1;else for(a=f=0;a<o;a++)if(r[a]!=i[a]){f=r[a]>i[a]?1:-1;break}return f}m(t,"compare");function n(r,i,o,s){for(var a=0;o--;)r[o]-=a,a=r[o]<i[o]?1:0,r[o]=a*s+r[o]-i[o];for(;!r[0]&&r.length>1;)r.shift()}return m(n,"subtract"),function(r,i,o,s,a,f){var c,p,l,u,g,y,w,D,x,I,k,T,O,W,H,ae,te,Ge,re,_e,xe=r.constructor,He=r.s==i.s?1:-1,Z=r.d,E=i.d;if(!Z||!Z[0]||!E||!E[0])return new xe(!r.s||!i.s||(Z?E&&Z[0]==E[0]:!E)?NaN:Z&&Z[0]==0||!E?He*0:He/0);for(f?(g=1,p=r.e-i.e):(f=we,g=_,p=ie(r.e/g)-ie(i.e/g)),re=E.length,te=Z.length,x=new xe(He),I=x.d=[],l=0;E[l]==(Z[l]||0);l++);if(E[l]>(Z[l]||0)&&p--,o==null?(W=o=xe.precision,s=xe.rounding):a?W=o+(r.e-i.e)+1:W=o,W<0)I.push(1),y=!0;else{if(W=W/g+2|0,l=0,re==1){for(u=0,E=E[0],W++;(l<te||u)&&W--;l++)H=u*f+(Z[l]||0),I[l]=H/E|0,u=H%E|0;y=u||l<te}else{for(u=f/(E[0]+1)|0,u>1&&(E=e(E,u,f),Z=e(Z,u,f),re=E.length,te=Z.length),ae=re,k=Z.slice(0,re),T=k.length;T<re;)k[T++]=0;_e=E.slice(),_e.unshift(0),Ge=E[0],E[1]>=f/2&&++Ge;do u=0,c=t(E,k,re,T),c<0?(O=k[0],re!=T&&(O=O*f+(k[1]||0)),u=O/Ge|0,u>1?(u>=f&&(u=f-1),w=e(E,u,f),D=w.length,T=k.length,c=t(w,k,D,T),c==1&&(u--,n(w,re<D?_e:E,D,f))):(u==0&&(c=u=1),w=E.slice()),D=w.length,D<T&&w.unshift(0),n(k,w,T,f),c==-1&&(T=k.length,c=t(E,k,re,T),c<1&&(u++,n(k,re<T?_e:E,T,f))),T=k.length):c===0&&(u++,k=[0]),I[l++]=u,c&&k[0]?k[T++]=Z[ae]||0:(k=[Z[ae]],T=1);while((ae++<te||k[0]!==void 0)&&W--);y=k[0]!==void 0}I[0]||I.shift()}if(g==1)x.e=p,ar=y;else{for(l=1,u=I[0];u>=10;u/=10)l++;x.e=l+p*g-1,N(x,a?o+x.e+1:o,s,y)}return x}})();function N(e,t,n,r){var i,o,s,a,f,c,p,l,u,g=e.constructor;e:if(t!=null){if(l=e.d,!l)return e;for(i=1,a=l[0];a>=10;a/=10)i++;if(o=t-i,o<0)o+=_,s=t,p=l[u=0],f=p/ee(10,i-s-1)%10|0;else if(u=Math.ceil((o+1)/_),a=l.length,u>=a)if(r){for(;a++<=u;)l.push(0);p=f=0,i=1,o%=_,s=o-_+1}else break e;else{for(p=a=l[u],i=1;a>=10;a/=10)i++;o%=_,s=o-_+i,f=s<0?0:p/ee(10,i-s-1)%10|0}if(r=r||t<0||l[u+1]!==void 0||(s<0?p:p%ee(10,i-s-1)),c=n<4?(f||r)&&(n==0||n==(e.s<0?3:2)):f>5||f==5&&(n==4||r||n==6&&(o>0?s>0?p/ee(10,i-s):0:l[u-1])%10&1||n==(e.s<0?8:7)),t<1||!l[0])return l.length=0,c?(t-=e.e+1,l[0]=ee(10,(_-t%_)%_),e.e=-t||0):l[0]=e.e=0,e;if(o==0?(l.length=u,a=1,u--):(l.length=u+1,a=ee(10,_-o),l[u]=s>0?(p/ee(10,i-s)%ee(10,s)|0)*a:0),c)for(;;)if(u==0){for(o=1,s=l[0];s>=10;s/=10)o++;for(s=l[0]+=a,a=1;s>=10;s/=10)a++;o!=a&&(e.e++,l[0]==we&&(l[0]=1));break}else{if(l[u]+=a,l[u]!=we)break;l[u--]=0,a=1}for(o=l.length;l[--o]===0;)l.pop()}return j&&(e.e>g.maxE?(e.d=null,e.e=NaN):e.e<g.minE&&(e.e=0,e.d=[0])),e}m(N,"finalise");function ke(e,t,n){if(!e.isFinite())return gr(e);var r,i=e.e,o=ne(e.d),s=o.length;return t?(n&&(r=n-s)>0?o=o.charAt(0)+"."+o.slice(1)+Be(r):s>1&&(o=o.charAt(0)+"."+o.slice(1)),o=o+(e.e<0?"e":"e+")+e.e):i<0?(o="0."+Be(-i-1)+o,n&&(r=n-s)>0&&(o+=Be(r))):i>=s?(o+=Be(i+1-s),n&&(r=n-i-1)>0&&(o=o+"."+Be(r))):((r=i+1)<s&&(o=o.slice(0,r)+"."+o.slice(r)),n&&(r=n-s)>0&&(i+1===s&&(o+="."),o+=Be(r))),o}m(ke,"finiteToString");function qt(e,t){var n=e[0];for(t*=_;n>=10;n/=10)t++;return t}m(qt,"getBase10Exponent");function Wt(e,t,n){if(t>ei)throw j=!0,n&&(e.precision=n),Error(cr);return N(new e(Bt),t,1,!0)}m(Wt,"getLn10");function Ee(e,t,n){if(t>wn)throw Error(cr);return N(new e(Ut),t,n,!0)}m(Ee,"getPi");function ur(e){var t=e.length-1,n=t*_+1;if(t=e[t],t){for(;t%10==0;t/=10)n--;for(t=e[0];t>=10;t/=10)n++}return n}m(ur,"getPrecision");function Be(e){for(var t="";e--;)t+="0";return t}m(Be,"getZeroString");function pr(e,t,n,r){var i,o=new e(1),s=Math.ceil(r/_+4);for(j=!1;;){if(n%2&&(o=o.times(t),or(o.d,s)&&(i=!0)),n=ie(n/2),n===0){n=o.d.length-1,i&&o.d[n]===0&&++o.d[n];break}t=t.times(t),or(t.d,s)}return j=!0,o}m(pr,"intPow");function ir(e){return e.d[e.d.length-1]&1}m(ir,"isOdd");function mr(e,t,n){for(var r,i,o=new e(t[0]),s=0;++s<t.length;){if(i=new e(t[s]),!i.s){o=i;break}r=o.cmp(i),(r===n||r===0&&o.s===n)&&(o=i)}return o}m(mr,"maxOrMin");function vn(e,t){var n,r,i,o,s,a,f,c=0,p=0,l=0,u=e.constructor,g=u.rounding,y=u.precision;if(!e.d||!e.d[0]||e.e>17)return new u(e.d?e.d[0]?e.s<0?0:1/0:1:e.s?e.s<0?0:e:NaN);for(t==null?(j=!1,f=y):f=t,a=new u(.03125);e.e>-2;)e=e.times(a),l+=5;for(r=Math.log(ee(2,l))/Math.LN10*2+5|0,f+=r,n=o=s=new u(1),u.precision=f;;){if(o=N(o.times(e),f,1),n=n.times(++p),a=s.plus(V(o,n,f,1)),ne(a.d).slice(0,f)===ne(s.d).slice(0,f)){for(i=l;i--;)s=N(s.times(s),f,1);if(t==null)if(c<3&&St(s.d,f-r,g,c))u.precision=f+=10,n=o=a=new u(1),p=0,c++;else return N(s,u.precision=y,g,j=!0);else return u.precision=y,s}s=a}}m(vn,"naturalExponential");function Ue(e,t){var n,r,i,o,s,a,f,c,p,l,u,g=1,y=10,w=e,D=w.d,x=w.constructor,I=x.rounding,k=x.precision;if(w.s<0||!D||!D[0]||!w.e&&D[0]==1&&D.length==1)return new x(D&&!D[0]?-1/0:w.s!=1?NaN:D?0:w);if(t==null?(j=!1,p=k):p=t,x.precision=p+=y,n=ne(D),r=n.charAt(0),Math.abs(o=w.e)<15e14){for(;r<7&&r!=1||r==1&&n.charAt(1)>3;)w=w.times(e),n=ne(w.d),r=n.charAt(0),g++;o=w.e,r>1?(w=new x("0."+n),o++):w=new x(r+"."+n.slice(1))}else return c=Wt(x,p+2,k).times(o+""),w=Ue(new x(r+"."+n.slice(1)),p-y).plus(c),x.precision=k,t==null?N(w,k,I,j=!0):w;for(l=w,f=s=w=V(w.minus(1),w.plus(1),p,1),u=N(w.times(w),p,1),i=3;;){if(s=N(s.times(u),p,1),c=f.plus(V(s,new x(i),p,1)),ne(c.d).slice(0,p)===ne(f.d).slice(0,p))if(f=f.times(2),o!==0&&(f=f.plus(Wt(x,p+2,k).times(o+""))),f=V(f,new x(g),p,1),t==null)if(St(f.d,p-y,I,a))x.precision=p+=y,c=s=w=V(l.minus(1),l.plus(1),p,1),u=N(w.times(w),p,1),i=a=1;else return N(f,x.precision=k,I,j=!0);else return x.precision=k,f;f=c,i+=2}}m(Ue,"naturalLogarithm");function gr(e){return String(e.s*e.s/0)}m(gr,"nonFiniteToString");function Lt(e,t){var n,r,i;for((n=t.indexOf("."))>-1&&(t=t.replace(".","")),(r=t.search(/e/i))>0?(n<0&&(n=r),n+=+t.slice(r+1),t=t.substring(0,r)):n<0&&(n=t.length),r=0;t.charCodeAt(r)===48;r++);for(i=t.length;t.charCodeAt(i-1)===48;--i);if(t=t.slice(r,i),t){if(i-=r,e.e=n=n-r-1,e.d=[],r=(n+1)%_,n<0&&(r+=_),r<i){for(r&&e.d.push(+t.slice(0,r)),i-=_;r<i;)e.d.push(+t.slice(r,r+=_));t=t.slice(r),r=_-t.length}else r-=i;for(;r--;)t+="0";e.d.push(+t),j&&(e.e>e.constructor.maxE?(e.d=null,e.e=NaN):e.e<e.constructor.minE&&(e.e=0,e.d=[0]))}else e.e=0,e.d=[0];return e}m(Lt,"parseDecimal");function ni(e,t){var n,r,i,o,s,a,f,c,p;if(t.indexOf("_")>-1){if(t=t.replace(/(\d)_(?=\d)/g,"$1"),lr.test(t))return Lt(e,t)}else if(t==="Infinity"||t==="NaN")return+t||(e.s=NaN),e.e=NaN,e.d=null,e;if(Xr.test(t))n=16,t=t.toLowerCase();else if(Qr.test(t))n=2;else if(Kr.test(t))n=8;else throw Error(We+t);for(o=t.search(/p/i),o>0?(f=+t.slice(o+1),t=t.substring(2,o)):t=t.slice(2),o=t.indexOf("."),s=o>=0,r=e.constructor,s&&(t=t.replace(".",""),a=t.length,o=a-o,i=pr(r,new r(n),o,o*2)),c=Ot(t,n,we),p=c.length-1,o=p;c[o]===0;--o)c.pop();return o<0?new r(e.s*0):(e.e=qt(c,p),e.d=c,j=!1,s&&(e=V(e,i,a*4)),f&&(e=e.times(Math.abs(f)<54?ee(2,f):ge.pow(2,f))),j=!0,e)}m(ni,"parseOther");function ri(e,t){var n,r=t.d.length;if(r<3)return t.isZero()?t:ft(e,2,t,t);n=1.4*Math.sqrt(r),n=n>16?16:n|0,t=t.times(1/Vt(5,n)),t=ft(e,2,t,t);for(var i,o=new e(5),s=new e(16),a=new e(20);n--;)i=t.times(t),t=t.times(o.plus(i.times(s.times(i).minus(a))));return t}m(ri,"sine");function ft(e,t,n,r,i){var o,s,a,f,c=1,p=e.precision,l=Math.ceil(p/_);for(j=!1,f=n.times(n),a=new e(r);;){if(s=V(a.times(f),new e(t++*t++),p,1),a=i?r.plus(s):r.minus(s),r=V(s.times(f),new e(t++*t++),p,1),s=a.plus(r),s.d[l]!==void 0){for(o=l;s.d[o]===a.d[o]&&o--;);if(o==-1)break}o=a,a=r,r=s,s=o,c++}return j=!0,s.d.length=l+1,s}m(ft,"taylorSeries");function Vt(e,t){for(var n=e;--t;)n*=e;return n}m(Vt,"tinyPow");function hr(e,t){var n,r=t.s<0,i=Ee(e,e.precision,1),o=i.times(.5);if(t=t.abs(),t.lte(o))return Te=r?4:1,t;if(n=t.divToInt(i),n.isZero())Te=r?3:2;else{if(t=t.minus(n.times(i)),t.lte(o))return Te=ir(n)?r?2:3:r?4:1,t;Te=ir(n)?r?1:4:r?3:2}return t.minus(i).abs()}m(hr,"toLessThanHalfPi");function Dn(e,t,n,r){var i,o,s,a,f,c,p,l,u,g=e.constructor,y=n!==void 0;if(y?(de(n,1,$e),r===void 0?r=g.rounding:de(r,0,8)):(n=g.precision,r=g.rounding),!e.isFinite())p=gr(e);else{for(p=ke(e),s=p.indexOf("."),y?(i=2,t==16?n=n*4-3:t==8&&(n=n*3-2)):i=t,s>=0&&(p=p.replace(".",""),u=new g(1),u.e=p.length-s,u.d=Ot(ke(u),10,i),u.e=u.d.length),l=Ot(p,10,i),o=f=l.length;l[--f]==0;)l.pop();if(!l[0])p=y?"0p+0":"0";else{if(s<0?o--:(e=new g(e),e.d=l,e.e=o,e=V(e,u,n,r,0,i),l=e.d,o=e.e,c=ar),s=l[n],a=i/2,c=c||l[n+1]!==void 0,c=r<4?(s!==void 0||c)&&(r===0||r===(e.s<0?3:2)):s>a||s===a&&(r===4||c||r===6&&l[n-1]&1||r===(e.s<0?8:7)),l.length=n,c)for(;++l[--n]>i-1;)l[n]=0,n||(++o,l.unshift(1));for(f=l.length;!l[f-1];--f);for(s=0,p="";s<f;s++)p+=yn.charAt(l[s]);if(y){if(f>1)if(t==16||t==8){for(s=t==16?4:3,--f;f%s;f++)p+="0";for(l=Ot(p,i,t),f=l.length;!l[f-1];--f);for(s=1,p="1.";s<f;s++)p+=yn.charAt(l[s])}else p=p.charAt(0)+"."+p.slice(1);p=p+(o<0?"p":"p+")+o}else if(o<0){for(;++o;)p="0"+p;p="0."+p}else if(++o>f)for(o-=f;o--;)p+="0";else o<f&&(p=p.slice(0,o)+"."+p.slice(o))}p=(t==16?"0x":t==2?"0b":t==8?"0o":"")+p}return e.s<0?"-"+p:p}m(Dn,"toStringBinary");function or(e,t){if(e.length>t)return e.length=t,!0}m(or,"truncate");function ii(e){return new this(e).abs()}m(ii,"abs");function oi(e){return new this(e).acos()}m(oi,"acos");function si(e){return new this(e).acosh()}m(si,"acosh");function ai(e,t){return new this(e).plus(t)}m(ai,"add");function ci(e){return new this(e).asin()}m(ci,"asin");function fi(e){return new this(e).asinh()}m(fi,"asinh");function di(e){return new this(e).atan()}m(di,"atan");function li(e){return new this(e).atanh()}m(li,"atanh");function ui(e,t){e=new this(e),t=new this(t);var n,r=this.precision,i=this.rounding,o=r+4;return!e.s||!t.s?n=new this(NaN):!e.d&&!t.d?(n=Ee(this,o,1).times(t.s>0?.25:.75),n.s=e.s):!t.d||e.isZero()?(n=t.s<0?Ee(this,r,i):new this(0),n.s=e.s):!e.d||t.isZero()?(n=Ee(this,o,1).times(.5),n.s=e.s):t.s<0?(this.precision=o,this.rounding=1,n=this.atan(V(e,t,o,1)),t=Ee(this,o,1),this.precision=r,this.rounding=i,n=e.s<0?n.minus(t):n.plus(t)):n=this.atan(V(e,t,o,1)),n}m(ui,"atan2");function pi(e){return new this(e).cbrt()}m(pi,"cbrt");function mi(e){return N(e=new this(e),e.e+1,2)}m(mi,"ceil");function gi(e,t,n){return new this(e).clamp(t,n)}m(gi,"clamp");function hi(e){if(!e||typeof e!="object")throw Error($t+"Object expected");var t,n,r,i=e.defaults===!0,o=["precision",1,$e,"rounding",0,8,"toExpNeg",-ct,0,"toExpPos",0,ct,"maxE",0,ct,"minE",-ct,0,"modulo",0,9];for(t=0;t<o.length;t+=3)if(n=o[t],i&&(this[n]=In[n]),(r=e[n])!==void 0)if(ie(r)===r&&r>=o[t+1]&&r<=o[t+2])this[n]=r;else throw Error(We+n+": "+r);if(n="crypto",i&&(this[n]=In[n]),(r=e[n])!==void 0)if(r===!0||r===!1||r===0||r===1)if(r)if(typeof crypto<"u"&&crypto&&(crypto.getRandomValues||crypto.randomBytes))this[n]=!0;else throw Error(fr);else this[n]=!1;else throw Error(We+n+": "+r);return this}m(hi,"config");function yi(e){return new this(e).cos()}m(yi,"cos");function Ii(e){return new this(e).cosh()}m(Ii,"cosh");function yr(e){var t,n,r;function i(o){var s,a,f,c=this;if(!(c instanceof i))return new i(o);if(c.constructor=i,sr(o)){c.s=o.s,j?!o.d||o.e>i.maxE?(c.e=NaN,c.d=null):o.e<i.minE?(c.e=0,c.d=[0]):(c.e=o.e,c.d=o.d.slice()):(c.e=o.e,c.d=o.d?o.d.slice():o.d);return}if(f=typeof o,f==="number"){if(o===0){c.s=1/o<0?-1:1,c.e=0,c.d=[0];return}if(o<0?(o=-o,c.s=-1):c.s=1,o===~~o&&o<1e7){for(s=0,a=o;a>=10;a/=10)s++;j?s>i.maxE?(c.e=NaN,c.d=null):s<i.minE?(c.e=0,c.d=[0]):(c.e=s,c.d=[o]):(c.e=s,c.d=[o]);return}if(o*0!==0){o||(c.s=NaN),c.e=NaN,c.d=null;return}return Lt(c,o.toString())}if(f==="string")return(a=o.charCodeAt(0))===45?(o=o.slice(1),c.s=-1):(a===43&&(o=o.slice(1)),c.s=1),lr.test(o)?Lt(c,o):ni(c,o);if(f==="bigint")return o<0?(o=-o,c.s=-1):c.s=1,Lt(c,o.toString());throw Error(We+o)}if(m(i,"Decimal"),i.prototype=v,i.ROUND_UP=0,i.ROUND_DOWN=1,i.ROUND_CEIL=2,i.ROUND_FLOOR=3,i.ROUND_HALF_UP=4,i.ROUND_HALF_DOWN=5,i.ROUND_HALF_EVEN=6,i.ROUND_HALF_CEIL=7,i.ROUND_HALF_FLOOR=8,i.EUCLID=9,i.config=i.set=hi,i.clone=yr,i.isDecimal=sr,i.abs=ii,i.acos=oi,i.acosh=si,i.add=ai,i.asin=ci,i.asinh=fi,i.atan=di,i.atanh=li,i.atan2=ui,i.cbrt=pi,i.ceil=mi,i.clamp=gi,i.cos=yi,i.cosh=Ii,i.div=wi,i.exp=vi,i.floor=Di,i.hypot=Si,i.ln=Ei,i.log=ki,i.log10=xi,i.log2=bi,i.max=Pi,i.min=Ni,i.mod=Mi,i.mul=Ti,i.pow=_i,i.random=Ci,i.round=Ri,i.sign=ji,i.sin=Ai,i.sinh=Fi,i.sqrt=Oi,i.sub=Li,i.sum=Bi,i.tan=Ui,i.tanh=Wi,i.trunc=$i,e===void 0&&(e={}),e&&e.defaults!==!0)for(r=["precision","rounding","toExpNeg","toExpPos","maxE","minE","modulo","crypto"],t=0;t<r.length;)e.hasOwnProperty(n=r[t++])||(e[n]=this[n]);return i.config(e),i}m(yr,"clone");function wi(e,t){return new this(e).div(t)}m(wi,"div");function vi(e){return new this(e).exp()}m(vi,"exp");function Di(e){return N(e=new this(e),e.e+1,3)}m(Di,"floor");function Si(){var e,t,n=new this(0);for(j=!1,e=0;e<arguments.length;)if(t=new this(arguments[e++]),t.d)n.d&&(n=n.plus(t.times(t)));else{if(t.s)return j=!0,new this(1/0);n=t}return j=!0,n.sqrt()}m(Si,"hypot");function sr(e){return e instanceof ge||e&&e.toStringTag===dr||!1}m(sr,"isDecimalInstance");function Ei(e){return new this(e).ln()}m(Ei,"ln");function ki(e,t){return new this(e).log(t)}m(ki,"log");function bi(e){return new this(e).log(2)}m(bi,"log2");function xi(e){return new this(e).log(10)}m(xi,"log10");function Pi(){return mr(this,arguments,-1)}m(Pi,"max");function Ni(){return mr(this,arguments,1)}m(Ni,"min");function Mi(e,t){return new this(e).mod(t)}m(Mi,"mod");function Ti(e,t){return new this(e).mul(t)}m(Ti,"mul");function _i(e,t){return new this(e).pow(t)}m(_i,"pow");function Ci(e){var t,n,r,i,o=0,s=new this(1),a=[];if(e===void 0?e=this.precision:de(e,1,$e),r=Math.ceil(e/_),this.crypto)if(crypto.getRandomValues)for(t=crypto.getRandomValues(new Uint32Array(r));o<r;)i=t[o],i>=429e7?t[o]=crypto.getRandomValues(new Uint32Array(1))[0]:a[o++]=i%1e7;else if(crypto.randomBytes){for(t=crypto.randomBytes(r*=4);o<r;)i=t[o]+(t[o+1]<<8)+(t[o+2]<<16)+((t[o+3]&127)<<24),i>=214e7?crypto.randomBytes(4).copy(t,o):(a.push(i%1e7),o+=4);o=r/4}else throw Error(fr);else for(;o<r;)a[o++]=Math.random()*1e7|0;for(r=a[--o],e%=_,r&&e&&(i=ee(10,_-e),a[o]=(r/i|0)*i);a[o]===0;o--)a.pop();if(o<0)n=0,a=[0];else{for(n=-1;a[0]===0;n-=_)a.shift();for(r=1,i=a[0];i>=10;i/=10)r++;r<_&&(n-=_-r)}return s.e=n,s.d=a,s}m(Ci,"random");function Ri(e){return N(e=new this(e),e.e+1,this.rounding)}m(Ri,"round");function ji(e){return e=new this(e),e.d?e.d[0]?e.s:0*e.s:e.s||NaN}m(ji,"sign");function Ai(e){return new this(e).sin()}m(Ai,"sin");function Fi(e){return new this(e).sinh()}m(Fi,"sinh");function Oi(e){return new this(e).sqrt()}m(Oi,"sqrt");function Li(e,t){return new this(e).sub(t)}m(Li,"sub");function Bi(){var e=0,t=arguments,n=new this(t[e]);for(j=!1;n.s&&++e<t.length;)n=n.plus(t[e]);return j=!0,N(n,this.precision,this.rounding)}m(Bi,"sum");function Ui(e){return new this(e).tan()}m(Ui,"tan");function Wi(e){return new this(e).tanh()}m(Wi,"tanh");function $i(e){return N(e=new this(e),e.e+1,1)}m($i,"trunc");v[Symbol.for("nodejs.util.inspect.custom")]=v.toString;v[Symbol.toStringTag]="Decimal";var ge=v.constructor=yr(In);Bt=new ge(Bt);Ut=new ge(Ut);var En={};Re(En,{NotFoundError:()=>be,Service:()=>dt,Storage:()=>En,node:()=>to});import oe from"path";var be=class e extends S.TaggedErrorClass()("NotFoundError",{message:S.String}){static{m(this,"NotFoundError")}static isInstance(t){return t instanceof e}},qi=S.Struct({path:S.optional(S.Struct({root:S.optional(S.String)}))}),Vi=S.Struct({id:S.String}),Ji=S.Struct({id:S.String}),zi=S.Struct({additions:Fe,deletions:Fe}),Gi=S.Struct({id:S.String,projectID:S.String,summary:S.Struct({diffs:S.Array(zi)})}),Hi=S.decodeUnknownOption(qi),Zi=S.decodeUnknownOption(Vi),Qi=S.decodeUnknownOption(Ji),Xi=S.decodeUnknownOption(Gi),dt=class extends Ae.Service()("@opencode/Storage"){static{m(this,"Service")}};function Ki(e,t){return oe.join(e,...t)+".json"}m(Ki,"file");function Sn(e){return!e||typeof e!="object"?!1:"code"in e&&e.code==="ENOENT"?!0:"reason"in e&&e.reason&&typeof e.reason=="object"&&"_tag"in e.reason?e.reason._tag==="NotFound":!1}m(Sn,"missing");function Yi(e){let t=Number.parseInt(e,10);return Number.isNaN(t)?0:t}m(Yi,"parseMigration");var Ir=[d.fn("Storage.migration.1")(function*(e,t,n){let r=oe.resolve(e,"../project");if(!(yield*t.isDir(r)))return;let i=yield*t.glob("*",{cwd:r,include:"all"});for(let o of i){let s=oe.join(r,o);if(!(yield*t.isDir(s)))continue;yield*d.logInfo(`migrating project ${o}`);let a=o,f="/";if(a!=="global"){for(let l of yield*t.glob("storage/session/message/*/*.json",{cwd:s,absolute:!0})){let u=Hi(yield*t.readJson(l),{onExcessProperty:"preserve"}),g=je.isSome(u)?u.value.path?.root:void 0;if(g){f=g;break}}if(!f||!(yield*t.isDir(f)))continue;let c=yield*n.run(["rev-list","--max-parents=0","--all"],{cwd:f}),[p]=c.text().split(`
|
|
19
19
|
`).filter(Boolean).map(l=>l.trim()).toSorted();if(!p)continue;a=p,yield*t.writeWithDirs(oe.join(e,"project",a+".json"),JSON.stringify({id:p,vcs:"git",worktree:f,time:{created:Date.now(),initialized:Date.now()}},null,2)),yield*d.logInfo(`migrating sessions for project ${a}`);for(let l of yield*t.glob("storage/session/info/*.json",{cwd:s,absolute:!0})){let u=oe.join(e,"session",a,oe.basename(l));yield*d.logInfo("copying",{sessionFile:l,dest:u});let g=yield*t.readJson(l),y=Zi(g,{onExcessProperty:"preserve"});if(yield*t.writeWithDirs(u,JSON.stringify(g,null,2)),!je.isNone(y)){yield*d.logInfo(`migrating messages for session ${y.value.id}`);for(let w of yield*t.glob(`storage/session/message/${y.value.id}/*.json`,{cwd:s,absolute:!0})){let D=oe.join(e,"message",y.value.id,oe.basename(w));yield*d.logInfo("copying",{msgFile:w,dest:D});let x=yield*t.readJson(w),I=Qi(x,{onExcessProperty:"preserve"});if(yield*t.writeWithDirs(D,JSON.stringify(x,null,2)),!je.isNone(I)){yield*d.logInfo(`migrating parts for message ${I.value.id}`);for(let k of yield*t.glob(`storage/session/part/${y.value.id}/${I.value.id}/*.json`,{cwd:s,absolute:!0})){let T=oe.join(e,"part",I.value.id,oe.basename(k)),O=yield*t.readJson(k);yield*d.logInfo("copying",{partFile:k,dest:T}),yield*t.writeWithDirs(T,JSON.stringify(O,null,2))}}}}}}}}),d.fn("Storage.migration.2")(function*(e,t){for(let n of yield*t.glob("session/*/*.json",{cwd:e,absolute:!0})){let r=yield*t.readJson(n),i=Xi(r,{onExcessProperty:"preserve"});if(je.isNone(i))continue;let o=i.value.summary.diffs;yield*t.writeWithDirs(oe.join(e,"session_diff",i.value.id+".json"),JSON.stringify(o,null,2)),yield*t.writeWithDirs(oe.join(e,"session",i.value.projectID,i.value.id+".json"),JSON.stringify({...r,summary:{additions:o.reduce((s,a)=>s+a.additions,0),deletions:o.reduce((s,a)=>s+a.deletions,0)}},null,2))}})],eo=ve.effect(dt,d.gen(function*(){let e=yield*ot.Service,t=yield*mn.Service,n=yield*Xt.make({lookup:m(()=>rt.make(),"lookup"),idleTimeToLive:0}),r=yield*d.cached(d.gen(function*(){let g=oe.join(it.Path.data,"storage"),y=oe.join(g,"migration"),w=yield*e.readFileString(y).pipe(d.map(Yi),d.catchIf(Sn,()=>d.succeed(0)),d.orElseSucceed(()=>0));for(let D=w;D<Ir.length;D++){yield*d.logInfo("running migration",{index:D});let x=Ir[D],I=yield*d.exit(x(g,e,t));if(ye.isFailure(I)){yield*d.logError("failed to run migration",{index:D,cause:I.cause});break}yield*e.writeWithDirs(y,String(D+1))}return{dir:g}})),i=m(g=>d.fail(new be({message:`Resource not found: ${g}`})),"fail"),o=m((g,y)=>y.pipe(d.catchIf(Sn,()=>i(g))),"wrap"),s=d.fnUntraced(function*(g,y){yield*e.writeWithDirs(g,JSON.stringify(y,null,2))}),a=m((g,y)=>d.scoped(d.gen(function*(){let w=Ki((yield*r).dir,g);return yield*y(w,yield*Xt.get(n,w))})),"withResolved"),f=d.fn("Storage.remove")(function*(g){yield*a(g,(y,w)=>rt.withWriteLock(w,e.remove(y).pipe(d.catchIf(Sn,()=>d.void))))}),c=m(g=>d.gen(function*(){return yield*a(g,(w,D)=>rt.withReadLock(D,o(w,e.readJson(w))))}),"read"),p=m((g,y)=>d.gen(function*(){return yield*a(g,(D,x)=>rt.withWriteLock(x,d.gen(function*(){let I=yield*o(D,e.readJson(D));return y(I),yield*s(D,I),I})))}),"update"),l=m((g,y)=>d.gen(function*(){yield*a(g,(w,D)=>rt.withWriteLock(D,s(w,y)))}),"write"),u=d.fn("Storage.list")(function*(g){let y=(yield*r).dir,w=oe.join(y,...g);return(yield*e.glob("**/*",{cwd:w,include:"file"}).pipe(d.catch(()=>d.succeed([])))).map(x=>[...g,...x.slice(0,-5).split(oe.sep)]).toSorted((x,I)=>x.join("/").localeCompare(I.join("/")))});return dt.of({remove:f,read:c,update:p,write:l,list:u})})),to=De.make({service:dt,layer:eo,deps:[ot.node,mn.node]});var Je={};Re(Je,{Event:()=>co,MessageV2:()=>Je,SYNTHETIC_ATTACHMENT_PROMPT:()=>kr,cursor:()=>Nn,filterCompacted:()=>_r,filterCompactedEffect:()=>ho,fromError:()=>Io,get:()=>go,isMedia:()=>kt,latest:()=>yo,node:()=>wo,page:()=>Nr,parts:()=>Tr,stream:()=>Mr,toModelMessages:()=>mo,toModelMessagesEffect:()=>Pr});var se=Qn.ID,qe=S.String.check(S.isStartsWith("msg")).pipe(S.brand("MessageID"),en(e=>({ascending:m(t=>e.make(un.ascending("message",t)),"ascending")}))),Jt=S.String.check(S.isStartsWith("prt")).pipe(S.brand("PartID"),en(e=>({ascending:m(t=>e.make(un.ascending("part",t)),"ascending")})));var Ve={};Re(Ve,{HeaderTimeoutError:()=>kn,ProviderError:()=>Ve,RESPONSE_FAILED_CODE:()=>Sr,RESPONSE_INCOMPLETE_CODE:()=>Dr,ResponseStreamError:()=>bn,parseAPICallError:()=>oo,parseStreamError:()=>io,quotaExhaustion:()=>Pn,statedRetryDelayMs:()=>xn});import{STATUS_CODES as wr}from"http";function lt(e){return e()}m(lt,"iife");var kn=class extends Error{constructor(n){super(`Provider response headers timed out after ${n}ms`);this.ms=n}ms;static{m(this,"HeaderTimeoutError")}name="ProviderHeaderTimeoutError"},bn=class extends Error{static{m(this,"ResponseStreamError")}name="ProviderResponseStreamError";constructor(t,n){super(t,n)}},Dr="response_incomplete",Sr="response_failed";function no(e){let t=e.statusCode;return t&&t===404||e.isRetryable}m(no,"isOpenAiErrorRetryable");function ro(e,t){return lt(()=>{let n=t.message;if(n===""){if(t.responseBody)return t.responseBody;if(t.statusCode){let r=wr[t.statusCode];if(r)return r}return"Unknown error"}if(!t.responseBody||t.statusCode&&n!==wr[t.statusCode])return n;try{let r=JSON.parse(t.responseBody),i=r.message||r.error||r.error?.message;if(i&&typeof i=="string")return`${n}: ${i}`}catch{}return/^\s*<!doctype|^\s*<html/i.test(t.responseBody)?t.statusCode===401?"Unauthorized: request was blocked by a gateway or proxy. Your authentication token may be missing or expired \u2014 try running `opencode auth login <your provider URL>` to re-authenticate.":t.statusCode===403?"Forbidden: request was blocked by a gateway or proxy. You may not have permission to access this resource \u2014 check your account and provider settings.":n:`${n}: ${t.responseBody}`}).trim()}m(ro,"message");function Et(e){if(typeof e=="string")try{let t=JSON.parse(e);return t&&typeof t=="object"?t:void 0}catch{return}if(typeof e=="object"&&e!==null)return e}m(Et,"json");var vr=new Set(["usage_limit_reached","insufficient_quota","billing_hard_limit_reached","quota_exceeded"]);function xn(e){let t=Et(e),n=t&&typeof t.error=="object"?t.error:void 0,r=Array.isArray(n?.details)?n.details:[];for(let i of r){if(!i||typeof i!="object")continue;let o=i;if(typeof o["@type"]!="string"||!o["@type"].endsWith("google.rpc.RetryInfo"))continue;let s=typeof o.retryDelay=="string"?/^(\d+(?:\.\d+)?)s$/.exec(o.retryDelay):null;if(s)return Math.ceil(Number.parseFloat(s[1])*1e3)}}m(xn,"statedRetryDelayMs");function Pn(e){let t=xn(e.body);if(t!==void 0&&t<=6e5)return;let n=Et(e.body),r=lt(()=>{if(!n)return;let y=n.error;return y&&typeof y=="object"?y:n}),i=typeof r?.type=="string"?r.type:"",o=typeof r?.code=="string"?r.code:"",s=typeof r?.message=="string"?r.message:e.message??"",a=typeof r?.resets_at=="number"?r.resets_at:void 0,f=typeof r?.resets_in_seconds=="number"?r.resets_in_seconds:void 0,c=typeof r?.plan_type=="string"?r.plan_type:void 0,p=vr.has(i)||vr.has(o),l=e.statusCode===429||e.statusCode===402,u=/usage limit|quota/i.test(s),g=(f??0)>600||a!==void 0&&a*1e3-Date.now()>6e5;if(p||l&&(u||g))return{message:s||"Provider usage limit reached",planType:c,resetsAt:a??(f!==void 0?Math.round(Date.now()/1e3)+f:void 0)??(t!==void 0?Math.round((Date.now()+t)/1e3):void 0)}}m(Pn,"quotaExhaustion");function io(e){let t=Et(e),n=typeof t?.message=="string"?Et(t.message)??t:t;if(!n)return;let r=JSON.stringify(n);if(n.type!=="error")return;switch(n?.error?.code){case"context_length_exceeded":return{type:"context_overflow",message:"Input exceeds context window of this model",responseBody:r};case"insufficient_quota":return{type:"quota",message:"Quota exceeded. Check your plan and billing details.",responseBody:r};case"usage_not_included":return{type:"api_error",message:"To use Codex with your ChatGPT plan, upgrade to Plus: https://chatgpt.com/explore/plus.",isRetryable:!1,responseBody:r};case"invalid_prompt":return{type:"api_error",message:typeof n?.error?.message=="string"?n?.error?.message:"Invalid prompt.",isRetryable:!1,responseBody:r};case"server_is_overloaded":case"server_error":return{type:"api_error",message:typeof n?.error?.message=="string"?n?.error?.message:"Server error.",isRetryable:!0,responseBody:r};case Dr:return{type:"unknown",message:typeof n?.error?.message=="string"?n?.error?.message:"The response failed.",responseBody:r}}let i=Pn({body:n});if(i)return{type:"quota",message:i.message,planType:i.planType,resetsAt:i.resetsAt,responseBody:r};if(n?.error?.type===Sr){let o=typeof n.error.code=="string"?n.error.code:"";return{type:"api_error",message:typeof n.error.message=="string"&&n.error.message?n.error.message:"The response failed.",isRetryable:!/invalid|policy/i.test(o),responseBody:r}}return{type:"api_error",message:typeof n?.error?.message=="string"?n.error.message:"Server error.",isRetryable:!0,responseBody:r}}m(io,"parseStreamError");function oo(e){let t=ro(e.providerID,e.error),n=Et(e.error.responseBody);if(Vn(t)||e.error.statusCode===413||n?.error?.code==="context_length_exceeded")return{type:"context_overflow",message:t,responseBody:e.error.responseBody};let r=Pn({statusCode:e.error.statusCode,body:n,message:t});if(r)return{type:"quota",message:r.message,statusCode:e.error.statusCode,planType:r.planType,resetsAt:r.resetsAt,responseBody:e.error.responseBody};let i=e.error.url?{url:e.error.url}:void 0;return{type:"api_error",message:t,statusCode:e.error.statusCode,isRetryable:e.providerID.startsWith("openai")?no(e.error):e.error.isRetryable,responseHeaders:lt(()=>{let o=xn(e.error.responseBody),s=e.error.responseHeaders;return o===void 0||s?.["retry-after"]||s?.["retry-after-ms"]?s:{...s??{},"retry-after-ms":String(o)}}),responseBody:e.error.responseBody,metadata:i}}m(oo,"parseAPICallError");var Ke=m((e,t)=>t.every((n,r)=>e[r]===n),"startsWith");function so(e){return e==="application/pdf"}m(so,"isPdfAttachment");function kt(e){return e.startsWith("image/")||so(e)}m(kt,"isMedia");function js(e){return e.startsWith("image/")&&e!=="image/svg+xml"&&e!=="image/vnd.fastbidsheet"}m(js,"isImageAttachment");function As(e,t){return Ke(e,[137,80,78,71,13,10,26,10])?"image/png":Ke(e,[255,216,255])?"image/jpeg":Ke(e,[71,73,70,56])?"image/gif":Ke(e,[66,77])?"image/bmp":Ke(e,[37,80,68,70,45])?"application/pdf":Ke(e,[82,73,70,70])&&Ke(e.subarray(8),[87,69,66,80])?"image/webp":t}m(As,"sniffAttachmentMime");var kr="Attached media from tool result:";function ao(e,t){if(!t||e.length<=t)return e;let n=e.length-t;return`${e.slice(0,t)}
|
|
20
20
|
[Tool output truncated for compaction: omitted ${n} chars]`}m(ao,"truncateToolOutput");var co={Updated:Y.Event.MessageUpdated,Removed:Y.Event.MessageRemoved,PartUpdated:Y.Event.PartUpdated,PartDelta:Y.Event.PartDelta,PartRemoved:Y.Event.PartRemoved},fo=S.Struct({id:qe,time:S.Finite.check(S.isGreaterThanOrEqualTo(0))}),lo=S.decodeUnknownSync(fo),Nn={encode(e){return Buffer.from(JSON.stringify(e)).toString("base64url")},decode(e){return lo(JSON.parse(Buffer.from(e,"base64url").toString("utf8")))}},br=m(e=>({...e.data,id:e.id,sessionID:e.session_id}),"info"),xr=m(e=>({...e.data,id:e.id,sessionID:e.session_id,messageID:e.message_id}),"part"),uo=m(e=>yt(It(me.time_created,e.time),Se(K(me.time_created,e.time),It(me.id,e.id))),"older");function po(e,t){let n=t.map(i=>i.id),r=new Map;return d.gen(function*(){if(n.length>0){let i=yield*e.select().from(le).where(Rt(le.message_id,n)).orderBy(le.message_id,le.id).all().pipe(d.orDie);for(let o of i){let s=xr(o),a=r.get(o.message_id);a?a.push(s):r.set(o.message_id,[s])}}return t.map(i=>({info:br(i),parts:r.get(i.id)??[]}))})}m(po,"hydrate");function zt(e){if(!e)return;let{providerExecuted:t,...n}=e;return Object.keys(n).length>0?n:void 0}m(zt,"providerMeta");var Pr=d.fnUntraced(function*(e,t,n){let r=[],i=new Set,o=dn.view(e,t),s,a=m(u=>{for(let[g,y]of(u?o?.after.get(u):void 0)?.entries()??[])r.push({id:`${u}-system-${g}`,role:"system",parts:[{type:"text",text:y}]})},"systemAfter"),f=m(u=>{if(t.api.npm==="@ai-sdk/anthropic"||t.api.npm==="@ai-sdk/openai"||t.api.npm==="@ai-sdk/amazon-bedrock/mantle")return!0;if(t.api.npm==="@ai-sdk/amazon-bedrock"){if(!u.mime.startsWith("image/"))return!1;let g=t.api.id.toLowerCase();return g.includes("anthropic.")||g.includes("nova")||g.includes("llama4")||g.includes("llama-4")}if(t.api.npm==="@ai-sdk/xai")return u.mime.startsWith("image/");if(t.api.npm==="@ai-sdk/google-vertex/anthropic")return!0;if(t.api.npm==="@ai-sdk/google"){let g=t.api.id.toLowerCase();return g.includes("gemini-3")&&!g.includes("gemini-2")}return!1},"supportsMediaInToolResult"),c=m(u=>t.api.npm==="@ai-sdk/xai"&&u.mime.startsWith("image/")&&!["image/png","image/jpeg","image/webp"].includes(u.mime),"rejectedByProvider"),p=m(u=>{let g=u.output;if(typeof g=="string")return{type:"text",value:g};if(typeof g=="object"){let y=g,w=(y.attachments??[]).filter(D=>D.url.startsWith("data:")&&D.url.includes(","));return{type:"content",value:[...y.text?[{type:"text",text:y.text}]:[],...w.map(D=>({type:"media",mediaType:D.mime,data:lt(()=>{let x=D.url.indexOf(",");return x===-1?D.url:D.url.slice(x+1)})}))]}}return{type:"json",value:g}},"toModelOutput");for(let u of e)if(o&&(a(s),s=u.info.id),u.parts.length!==0&&!o?.drop.has(u.info.id)){if(u.info.role==="user"){let g={id:u.info.id,role:"user",parts:[]};for(let y of u.parts)y.type==="text"&&!y.ignored&&y.text!==""&&g.parts.push({type:"text",text:y.text}),y.type==="file"&&y.mime!=="text/plain"&&y.mime!=="application/x-directory"&&(n?.stripMedia&&kt(y.mime)?g.parts.push({type:"text",text:`[Attached ${y.mime}: ${y.filename??"file"}]`}):g.parts.push({type:"file",url:y.url,mediaType:y.mime,filename:y.filename})),y.type==="compaction"&&!o?.skip.has(u.info.id)&&g.parts.push({type:"text",text:"What did we do so far?"}),y.type==="subtask"&&g.parts.push({type:"text",text:"The following tool was executed by the user"});g.parts.length>0&&r.push(g)}if(u.info.role==="assistant"){let g=`${t.providerID}/${t.id}`!=`${u.info.providerID}/${u.info.modelID}`,y=o?.blocks.get(u.info.id);if(y){dn.remember(y),r.push({id:u.info.id,role:"assistant",parts:[{type:"text",text:y.content,providerMetadata:{anthropic:{type:"compaction"}}}]});continue}let w=[];if(u.info.error&&!(vt.isInstance(u.info.error)&&u.parts.some(I=>I.type!=="step-start"&&I.type!=="reasoning")))continue;if(u.info.aside){let I=u.parts.filter(k=>k.type==="text"&&!k.ignored).map(k=>k.text.trim()).filter(Boolean).join(`
|
|
21
21
|
`);I&&r.push({id:u.info.id,role:"user",parts:[{type:"text",text:`[While a tool was running you already answered the user's message above: "${I}". Do not answer it again; carry on with your work.]`}]});continue}let D={id:u.info.id,role:"assistant",parts:[]},x=u.parts.some(I=>I.type!=="reasoning"?!1:I.metadata?.anthropic?.signature!=null);for(let I of u.parts){if(I.type==="text"){let k=I.text===""&&x?" ":I.text;D.parts.push({type:"text",text:k,...g?{}:{providerMetadata:I.metadata}})}if(I.type==="step-start"&&D.parts.push({type:"step-start"}),I.type==="tool"){if(i.add(I.tool),I.state.status==="completed"){let k=I.state.time.compacted?"[Old tool result content cleared]":ao(I.state.output,n?.toolOutputMaxChars),T=I.state.time.compacted||n?.stripMedia?[]:(I.state.attachments??[]).filter(te=>!c(te)),W=T.filter(te=>kt(te.mime)).filter(te=>!f(te));W.length>0&&w.push(...W);let H=T.filter(te=>!kt(te.mime)||f(te)),ae=H.length>0?{text:k,attachments:H}:k;D.parts.push({type:"tool-"+I.tool,state:"output-available",toolCallId:I.callID,input:I.state.input,output:ae,...I.metadata?.providerExecuted?{providerExecuted:!0}:{},...g?{}:{callProviderMetadata:zt(I.metadata)}})}if(I.state.status==="error"){let k=I.state.metadata?.interrupted===!0?I.state.metadata.output:void 0;typeof k=="string"?D.parts.push({type:"tool-"+I.tool,state:"output-available",toolCallId:I.callID,input:I.state.input,output:k,...I.metadata?.providerExecuted?{providerExecuted:!0}:{},...g?{}:{callProviderMetadata:zt(I.metadata)}}):D.parts.push({type:"tool-"+I.tool,state:"output-error",toolCallId:I.callID,input:I.state.input,errorText:I.state.error,...I.metadata?.providerExecuted?{providerExecuted:!0}:{},...g?{}:{callProviderMetadata:zt(I.metadata)}})}(I.state.status==="pending"||I.state.status==="running")&&D.parts.push({type:"tool-"+I.tool,state:"output-error",toolCallId:I.callID,input:I.state.input,errorText:n?.runningToolNote??"[Tool execution was interrupted]",...I.metadata?.providerExecuted?{providerExecuted:!0}:{},...g?{}:{callProviderMetadata:zt(I.metadata)}})}if(I.type==="reasoning"){if(g){I.text.trim().length>0&&D.parts.push({type:"text",text:I.text});continue}D.parts.push({type:"reasoning",text:I.text,providerMetadata:I.metadata})}}D.parts.length>0&&(r.push(D),w.length>0&&r.push({id:qe.ascending(),role:"user",parts:[{type:"text",text:kr},...w.map(I=>({type:"file",url:I.url,mediaType:I.mime,filename:I.filename}))]}))}}o&&a(s);let l=Object.fromEntries(Array.from(i).map(u=>[u,{toModelOutput:p}]));return yield*d.promise(()=>er(r.filter(u=>u.parts.some(g=>g.type!=="step-start")),{tools:l}))});function mo(e,t,n){return d.runPromise(Pr(e,t,n))}m(mo,"toModelMessages");var Nr=d.fn("MessageV2.page")(function*(e){let{db:t}=yield*pe.Service,n=e.before?Nn.decode(e.before):void 0,r=n?Se(K(me.session_id,e.sessionID),uo(n)):K(me.session_id,e.sessionID),i=yield*t.select().from(me).where(r).orderBy(Xe(me.time_created),Xe(me.id)).limit(e.limit+1).all().pipe(d.orDie);if(i.length===0)return(yield*t.select({id:U.id}).from(U).where(K(U.id,e.sessionID)).get().pipe(d.orDie))?{items:[],more:!1}:yield*new be({message:`Session not found: ${e.sessionID}`});let o=i.length>e.limit,s=o?i.slice(0,e.limit):i,a=yield*po(t,s);a.reverse();let f=s.at(-1);return{items:a,more:o,cursor:o&&f?Nn.encode({id:f.id,time:f.time_created}):void 0}});function Mr(e){return d.gen(function*(){let n=[],r;for(;;){let i=yield*Nr({sessionID:e,limit:50,before:r}).pipe(d.catchIf(be.isInstance,()=>d.succeed({items:[],more:!1,cursor:void 0})));if(i.items.length===0)break;for(let o=i.items.length-1;o>=0;o--){let s=i.items[o];s&&n.push(s)}if(!i.more||!i.cursor)break;r=i.cursor}return n})}m(Mr,"stream");function Tr(e){return d.gen(function*(){let{db:t}=yield*pe.Service;return(yield*t.select().from(le).where(K(le.message_id,e)).orderBy(le.id).all().pipe(d.orDie)).map(xr)})}m(Tr,"parts");var go=d.fn("MessageV2.get")(function*(e){let{db:t}=yield*pe.Service,n=yield*t.select().from(me).where(Se(K(me.id,e.messageID),K(me.session_id,e.sessionID))).get().pipe(d.orDie);return n?{info:br(n),parts:yield*Tr(e.messageID)}:yield*new be({message:`Message not found: ${e.messageID}`})});function _r(e){let t=[],n=new Set,r;for(let c of e){if(t.push(c),r){if(c.info.id===r)break;continue}if(c.info.role==="user"&&n.has(c.info.id)){let p=c.parts.find(l=>l.type==="compaction");if(!p)continue;if(!p.tail_start_id||(r=p.tail_start_id,c.info.id===r))break;continue}if(c.info.role==="user"&&n.has(c.info.id)&&c.parts.some(p=>p.type==="compaction"))break;c.info.role==="assistant"&&c.info.summary&&c.info.finish&&!c.info.error&&n.add(c.info.parentID)}t.reverse();let i=t.findLastIndex(c=>c.info.role==="user"&&c.parts.some(p=>p.type==="compaction"&&p.tail_start_id!==void 0)),o=t[i],s=o?.parts.find(c=>c.type==="compaction"&&c.tail_start_id!==void 0),a=o?t.findIndex((c,p)=>p>i&&c.info.role==="assistant"&&c.info.summary&&c.info.parentID===o.info.id):-1,f=s?.tail_start_id?t.findIndex(c=>c.info.id===s.tail_start_id):-1;return f>=0&&f<i&&a>i?[...t.slice(i,a+1),...t.slice(f,i),...t.slice(a+1)]:t}m(_r,"filterCompacted");var ho=d.fnUntraced(function*(e){return _r(yield*Mr(e))});function yo(e){let t,n,r;for(let o of e){let s=o.info;s.role==="user"&&Gt(s,t)&&(t=s),s.role==="assistant"&&Gt(s,n)&&(n=s),s.role==="assistant"&&s.finish&&Gt(s,r)&&(r=s)}let i=e.flatMap(o=>r&&!Gt(o.info,r)?[]:o.parts.filter(s=>s.type==="compaction"||s.type==="subtask"));return{user:t,assistant:n,finished:r,tasks:i}}m(yo,"latest");function Gt(e,t){return t?e.time.created!==t.time.created?e.time.created>t.time.created:e.id>t.id:!0}m(Gt,"isAfter");function Io(e,t){switch(!0){case(e instanceof DOMException&&e.name==="AbortError"):return new vt({message:e.message},{cause:e}).toObject();case Gn.isInstance(e):return e;case Me.isInstance(e):return e.toObject();case Kn.isInstance(e):return new Hn({providerID:t.providerID,message:e.message},{cause:e}).toObject();case Er(e)!==void 0:{let r=Er(e);return new Me({message:"Connection reset by server",isRetryable:!0,metadata:{code:r.code??"",syscall:r.syscall??"",message:r.message??""}},{cause:e}).toObject()}case(e instanceof TypeError&&e.message==="terminated"):{if(t.aborted)return new vt({message:e.message},{cause:e}).toObject();let r=e.cause;return new Me({message:"Connection closed by server",isRetryable:!0,metadata:{code:typeof r?.code=="string"?r.code:"",message:typeof r?.message=="string"?r.message:""}},{cause:e}).toObject()}case(e instanceof Error&&e.code==="ZlibError"):return t.aborted?new vt({message:e.message},{cause:e}).toObject():new Me({message:"Response decompression failed",isRetryable:!0,metadata:{code:e.code,message:e.message}},{cause:e}).toObject();case e instanceof Ve.HeaderTimeoutError:return new Me({message:e.message,isRetryable:!0,metadata:{code:e.name,timeoutMs:String(e.ms)}},{cause:e}).toObject();case e instanceof Ve.ResponseStreamError:return new Me({message:e.message,isRetryable:!0,metadata:{code:e.name}},{cause:e}).toObject();case Xn.isInstance(e):let n=Ve.parseAPICallError({providerID:t.providerID,error:e});return n.type==="context_overflow"?new fn({message:n.message,responseBody:n.responseBody},{cause:e}).toObject():n.type==="quota"?new cn({providerID:t.providerID,message:n.message,planType:n.planType,resetsAt:n.resetsAt,statusCode:n.statusCode,responseBody:n.responseBody},{cause:e}).toObject():new Me({message:n.message,statusCode:n.statusCode,isRetryable:n.isRetryable,responseHeaders:n.responseHeaders,responseBody:n.responseBody,metadata:n.metadata},{cause:e}).toObject();case e instanceof Error:return new At.Unknown({message:Yn(e)},{cause:e}).toObject();default:try{let r=Ve.parseStreamError(e);if(r)return r.type==="context_overflow"?new fn({message:r.message,responseBody:r.responseBody},{cause:e}).toObject():r.type==="quota"?new cn({providerID:t.providerID,message:r.message,planType:r.planType,resetsAt:r.resetsAt,responseBody:r.responseBody},{cause:e}).toObject():r.type==="unknown"?new At.Unknown({message:r.message},{cause:e}).toObject():new Me({message:r.message,isRetryable:r.isRetryable,responseBody:r.responseBody},{cause:e}).toObject()}catch{}return new At.Unknown({message:JSON.stringify(e)},{cause:e}).toObject()}}m(Io,"fromError");function Er(e){let t=e;for(let n=0;n<4&&t;n++){if(t?.code==="ECONNRESET")return t;t=t?.cause}}m(Er,"connectionResetError");var wo=De.group([pe.node]);var Pt={};Re(Pt,{FileDiff:()=>ko,Patch:()=>Eo,Service:()=>pt,Snapshot:()=>Pt,node:()=>Po});var bt=class{static{m(this,"Diff")}diff(t,n,r={}){let i;typeof r=="function"?(i=r,r={}):"callback"in r&&(i=r.callback);let o=this.castInput(t,r),s=this.castInput(n,r),a=this.removeEmpty(this.tokenize(o,r)),f=this.removeEmpty(this.tokenize(s,r));return this.diffWithOptionsObj(a,f,r,i)}diffWithOptionsObj(t,n,r,i){var o;let s=m(I=>{if(I=this.postProcess(I,r),i){setTimeout(function(){i(I)},0);return}else return I},"done"),a=n.length,f=t.length,c=1,p=a+f;r.maxEditLength!=null&&(p=Math.min(p,r.maxEditLength));let l=(o=r.timeout)!==null&&o!==void 0?o:1/0,u=Date.now()+l,g=[{oldPos:-1,lastComponent:void 0}],y=this.extractCommon(g[0],n,t,0,r);if(g[0].oldPos+1>=f&&y+1>=a)return s(this.buildValues(g[0].lastComponent,n,t));let w=-1/0,D=1/0,x=m(()=>{for(let I=Math.max(w,-c);I<=Math.min(D,c);I+=2){let k,T=g[I-1],O=g[I+1];T&&(g[I-1]=void 0);let W=!1;if(O){let ae=O.oldPos-I;W=O&&0<=ae&&ae<a}let H=T&&T.oldPos+1<f;if(!W&&!H){g[I]=void 0;continue}if(!H||W&&T.oldPos<O.oldPos?k=this.addToPath(O,!0,!1,0,r):k=this.addToPath(T,!1,!0,1,r),y=this.extractCommon(k,n,t,I,r),k.oldPos+1>=f&&y+1>=a)return s(this.buildValues(k.lastComponent,n,t))||!0;g[I]=k,k.oldPos+1>=f&&(D=Math.min(D,I-1)),y+1>=a&&(w=Math.max(w,I+1))}c++},"execEditLength");if(i)m(function I(){setTimeout(function(){if(c>p||Date.now()>u)return i(void 0);x()||I()},0)},"exec")();else for(;c<=p&&Date.now()<=u;){let I=x();if(I)return I}}addToPath(t,n,r,i,o){let s=t.lastComponent;return s&&!o.oneChangePerToken&&s.added===n&&s.removed===r?{oldPos:t.oldPos+i,lastComponent:{count:s.count+1,added:n,removed:r,previousComponent:s.previousComponent}}:{oldPos:t.oldPos+i,lastComponent:{count:1,added:n,removed:r,previousComponent:s}}}extractCommon(t,n,r,i,o){let s=n.length,a=r.length,f=t.oldPos,c=f-i,p=0;for(;c+1<s&&f+1<a&&this.equals(r[f+1],n[c+1],o);)c++,f++,p++,o.oneChangePerToken&&(t.lastComponent={count:1,previousComponent:t.lastComponent,added:!1,removed:!1});return p&&!o.oneChangePerToken&&(t.lastComponent={count:p,previousComponent:t.lastComponent,added:!1,removed:!1}),t.oldPos=f,c}equals(t,n,r){return r.comparator?r.comparator(t,n):t===n||!!r.ignoreCase&&t.toLowerCase()===n.toLowerCase()}removeEmpty(t){let n=[];for(let r=0;r<t.length;r++)t[r]&&n.push(t[r]);return n}castInput(t,n){return t}tokenize(t,n){return Array.from(t)}join(t){return t.join("")}postProcess(t,n){return t}get useLongestToken(){return!1}buildValues(t,n,r){let i=[],o;for(;t;)i.push(t),o=t.previousComponent,delete t.previousComponent,t=o;i.reverse();let s=i.length,a=0,f=0,c=0;for(;a<s;a++){let p=i[a];if(p.removed)p.value=this.join(r.slice(c,c+p.count)),c+=p.count;else{if(!p.added&&this.useLongestToken){let l=n.slice(f,f+p.count);l=l.map(function(u,g){let y=r[c+g];return y.length>u.length?y:u}),p.value=this.join(l)}else p.value=this.join(n.slice(f,f+p.count));f+=p.count,p.added||(c+=p.count)}}return i}};var Mn=class extends bt{static{m(this,"LineDiff")}constructor(){super(...arguments),this.tokenize=vo}equals(t,n,r){return r.ignoreWhitespace?((!r.newlineIsToken||!t.includes(`
|