@muxcodecli/cli 1.15.17 → 1.15.18
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/bip-bop-01-ga21wr3r.mp3 +0 -0
- package/dist/bip-bop-03-kgfd4rq4.mp3 +0 -0
- package/dist/chunk-0hqmdrjr.js +3 -0
- package/dist/chunk-0npjzye0.js +2 -0
- package/dist/chunk-0pe6y883.js +2 -0
- package/dist/chunk-0qqpjj2h.js +3 -0
- package/dist/chunk-0r3h8jgj.js +2 -0
- package/dist/chunk-11285jfy.js +3 -0
- package/dist/chunk-11ant2kk.js +3 -0
- package/dist/chunk-124qmktt.js +18 -0
- package/dist/chunk-138ntz3h.js +2 -0
- package/dist/chunk-1e73ypg5.js +3 -0
- package/dist/chunk-1evcc54z.js +3 -0
- package/dist/chunk-1mqsg5s7.js +75 -0
- package/dist/chunk-1pv2317e.js +7 -0
- package/dist/chunk-1y3ssxx6.js +2 -0
- package/dist/chunk-20x8vsdn.js +7 -0
- package/dist/chunk-21x3anp4.js +9 -0
- package/dist/chunk-22qpzg37.js +212 -0
- package/dist/chunk-2bt5mtgm.js +3 -0
- package/dist/chunk-2d95ene8.js +2 -0
- package/dist/chunk-2h2zq5cp.js +2 -0
- package/dist/chunk-2pc63est.js +2 -0
- package/dist/chunk-33gs9z8d.js +2 -0
- package/dist/chunk-33vwwxjk.js +2 -0
- package/dist/chunk-3dq7hfxc.js +9 -0
- package/dist/chunk-3jvft1k1.js +2 -0
- package/dist/chunk-4jqh4mpm.js +2 -0
- package/dist/chunk-4mgyaytc.js +672 -0
- package/dist/chunk-4va8fzq1.js +2 -0
- package/dist/chunk-4wkq9y2z.js +7 -0
- package/dist/chunk-526nbm9e.js +2 -0
- package/dist/chunk-5a6895cv.js +37 -0
- package/dist/chunk-5e9dq2av.js +2 -0
- package/dist/chunk-5jn2z3nf.js +3 -0
- package/dist/chunk-5npr1qyq.js +574 -0
- package/dist/chunk-5sfky0gz.js +8 -0
- package/dist/chunk-5t7xqdvk.js +3 -0
- package/dist/chunk-5tpqj6ag.js +10 -0
- package/dist/chunk-5v5015am.js +12 -0
- package/dist/chunk-5wawdxv2.js +7 -0
- package/dist/chunk-6btrg3ff.js +2 -0
- package/dist/chunk-6skbzman.js +6 -0
- package/dist/chunk-6sz698ew.js +11 -0
- package/dist/chunk-6xzrzmsr.js +2 -0
- package/dist/chunk-7848rf5q.js +63 -0
- package/dist/chunk-7ep2edcv.js +12 -0
- package/dist/chunk-7svw66kw.js +13 -0
- package/dist/chunk-7xgr8vx6.js +2 -0
- package/dist/chunk-7zjn6m1m.js +2 -0
- package/dist/chunk-8atqb297.js +12 -0
- package/dist/chunk-8ebkxjar.js +7 -0
- package/dist/chunk-8j3aw4qg.js +3 -0
- package/dist/chunk-8jy0dvcn.js +3 -0
- package/dist/chunk-8refh038.js +2 -0
- package/dist/chunk-93cszp8k.js +3 -0
- package/dist/chunk-93ze3gcb.js +2 -0
- package/dist/chunk-98yxzxtd.js +2 -0
- package/dist/chunk-9g64kggy.js +3 -0
- package/dist/chunk-9h1pwxb2.js +8 -0
- package/dist/chunk-9j4j9nrm.js +2 -0
- package/dist/chunk-9kzczwh0.js +3 -0
- package/dist/chunk-9n629gtn.js +3 -0
- package/dist/chunk-9y59sxde.js +2 -0
- package/dist/chunk-a2m5jyd8.js +2 -0
- package/dist/chunk-a595cp8s.js +2 -0
- package/dist/chunk-ak0k3m4q.js +3 -0
- package/dist/chunk-apksmrz9.js +3 -0
- package/dist/chunk-b05r09sj.js +10 -0
- package/dist/chunk-b47e563q.js +2 -0
- package/dist/chunk-b57avnse.js +2 -0
- package/dist/chunk-bfjq7w7k.js +2 -0
- package/dist/chunk-bhc70qet.js +3 -0
- package/dist/chunk-bvtscj68.js +2 -0
- package/dist/chunk-bw2cy5v0.js +8 -0
- package/dist/chunk-c7dvyh2x.js +2 -0
- package/dist/chunk-cbz8b7g5.js +3 -0
- package/dist/chunk-cw4vbnet.js +3 -0
- package/dist/chunk-czcj3j9y.js +2 -0
- package/dist/chunk-dg466kdp.js +2 -0
- package/dist/chunk-dmscgnhq.js +2 -0
- package/dist/chunk-dtk4m8rm.js +3 -0
- package/dist/chunk-dy7akyj3.js +2 -0
- package/dist/chunk-e2wv2sp4.js +2 -0
- package/dist/chunk-e8j03wnd.js +3 -0
- package/dist/chunk-egkp6tct.js +2 -0
- package/dist/chunk-emfc800a.js +2 -0
- package/dist/chunk-envnht72.js +4 -0
- package/dist/chunk-eskw1cj2.js +3 -0
- package/dist/chunk-ezz15tyg.js +2 -0
- package/dist/chunk-fkmzj0qt.js +16 -0
- package/dist/chunk-fqt3c3g5.js +4 -0
- package/dist/chunk-frbht418.js +19 -0
- package/dist/chunk-ftz8cqfq.js +2 -0
- package/dist/chunk-g4jxdrr6.js +2 -0
- package/dist/chunk-g52xzmrr.js +2 -0
- package/dist/chunk-gbtvkje9.js +4 -0
- package/dist/chunk-gm9msqq5.js +8 -0
- package/dist/chunk-gxat3dpd.js +3 -0
- package/dist/chunk-hfppq1w5.js +4 -0
- package/dist/chunk-jdg870gy.js +1683 -0
- package/dist/chunk-jfz77m78.js +3 -0
- package/dist/chunk-jg9r58pf.js +16 -0
- package/dist/chunk-jgzt4945.js +2 -0
- package/dist/chunk-jh2epywq.js +2 -0
- package/dist/chunk-jpj6a56k.js +2 -0
- package/dist/chunk-jw4sgq23.js +2 -0
- package/dist/chunk-jws11ngd.js +2 -0
- package/dist/chunk-jxhz82qt.js +2 -0
- package/dist/chunk-k19y2psf.js +4 -0
- package/dist/chunk-k6cj14zk.js +2 -0
- package/dist/chunk-kktm0pdc.js +3 -0
- package/dist/chunk-kmr27ake.js +160 -0
- package/dist/chunk-kyhwvbvq.js +2 -0
- package/dist/chunk-mgn5pejx.js +2 -0
- package/dist/chunk-mskyzxb3.js +3 -0
- package/dist/chunk-my9cfmvt.js +5 -0
- package/dist/chunk-n4vx7kvs.js +389 -0
- package/dist/chunk-nc44rvs7.js +23 -0
- package/dist/chunk-ng3vbpmy.js +3 -0
- package/dist/chunk-nmnp5g5p.js +228 -0
- package/dist/chunk-nn0t3xmn.js +2 -0
- package/dist/chunk-npr41z9a.js +19 -0
- package/dist/chunk-ntvr3177.js +25 -0
- package/dist/chunk-pkc5hkha.js +2 -0
- package/dist/chunk-ppg6zhae.js +3 -0
- package/dist/chunk-pqwm9zk1.js +6 -0
- package/dist/chunk-ptvjmfqx.js +2 -0
- package/dist/chunk-q1r48y0y.js +34 -0
- package/dist/chunk-q9yddd1r.js +3 -0
- package/dist/chunk-qavtgsrh.js +2 -0
- package/dist/chunk-qvh8ghjw.js +7 -0
- package/dist/chunk-qx6r187q.js +2 -0
- package/dist/chunk-r093mfa8.js +32 -0
- package/dist/chunk-rbaj9ktq.js +2 -0
- package/dist/chunk-rkf9ynkx.js +3 -0
- package/dist/chunk-rpp44jtx.js +3 -0
- package/dist/chunk-rrvwp351.js +2 -0
- package/dist/chunk-rs8fsgqt.js +81 -0
- package/dist/chunk-s4gy87ft.js +8 -0
- package/dist/chunk-s5qq2ch2.js +12 -0
- package/dist/chunk-s92578qx.js +71 -0
- package/dist/chunk-snsb760m.js +2 -0
- package/dist/chunk-sp1cvejp.js +2 -0
- package/dist/chunk-spb3tm25.js +4 -0
- package/dist/chunk-srnmswkj.js +2 -0
- package/dist/chunk-sxgbzwrs.js +2 -0
- package/dist/chunk-t2s6m9t2.js +35 -0
- package/dist/chunk-t98sdxty.js +2 -0
- package/dist/chunk-tbnxx5na.js +2 -0
- package/dist/chunk-tfxm3qz4.js +2 -0
- package/dist/chunk-treb38pz.js +3 -0
- package/dist/chunk-tvw8tfpr.js +6 -0
- package/dist/chunk-v107htgw.js +101 -0
- package/dist/chunk-v8at4gnt.js +2 -0
- package/dist/chunk-vmr3get8.js +2 -0
- package/dist/chunk-vqrnejgj.js +71 -0
- package/dist/chunk-vvwy955j.js +3 -0
- package/dist/chunk-w5jxffnq.js +2 -0
- package/dist/chunk-wcbh5jqy.js +3 -0
- package/dist/chunk-wfmrnep1.js +2 -0
- package/dist/chunk-wk11yy8h.js +3 -0
- package/dist/chunk-wn5f1tfj.js +2 -0
- package/dist/chunk-wpm2p1gq.js +3 -0
- package/dist/chunk-wxkyv5gj.js +2 -0
- package/dist/chunk-wyed730e.js +2 -0
- package/dist/chunk-x65zs89t.js +3 -0
- package/dist/chunk-x6zjq78z.js +2 -0
- package/dist/chunk-xedav0qx.js +3 -0
- package/dist/chunk-xmftb9ad.js +38 -0
- package/dist/chunk-xvtkw7hj.js +3 -0
- package/dist/chunk-xy0txg0n.js +2 -0
- package/dist/chunk-y7s5cpwr.js +34 -0
- package/dist/chunk-yg48tfvv.js +16 -0
- package/dist/chunk-ygpen625.js +3 -0
- package/dist/chunk-ymb45bt6.js +2 -0
- package/dist/chunk-yp2zfcvh.js +8 -0
- package/dist/chunk-z3mx7n44.js +3 -0
- package/dist/chunk-zaj612bw.js +3 -0
- package/dist/chunk-zb3179f9.js +3 -0
- package/dist/chunk-zhd8f4pc.js +759 -0
- package/dist/chunk-zjpnyah2.js +3 -0
- package/dist/cli/cmd/tui/worker.js +2 -0
- package/dist/highlights-eq9cgrbb.scm +604 -0
- package/dist/highlights-ghv9g403.scm +205 -0
- package/dist/highlights-hk7bwhj4.scm +284 -0
- package/dist/highlights-r812a2qc.scm +150 -0
- package/dist/highlights-x6tmsnaa.scm +115 -0
- package/dist/index.js +146 -5742
- package/dist/injections-73j83es3.scm +27 -0
- package/dist/muxcode-linux-x64 +0 -0
- package/dist/nope-03-2z8weyjw.mp3 +0 -0
- package/dist/photon_rs_bg-bq08arze.wasm +0 -0
- package/dist/staplebops-06-rz29m246.mp3 +0 -0
- package/dist/tree-sitter-3jzf13jk.wasm +0 -0
- package/dist/tree-sitter-bash-hq5s6fxb.wasm +0 -0
- package/dist/tree-sitter-javascript-nd0q4pe9.wasm +0 -0
- package/dist/tree-sitter-markdown-411r6y9b.wasm +0 -0
- package/dist/tree-sitter-markdown_inline-j5349f42.wasm +0 -0
- package/dist/tree-sitter-powershell-ryb2ffqs.wasm +0 -0
- package/dist/tree-sitter-typescript-zxjzwt75.wasm +0 -0
- package/dist/tree-sitter-zig-e78zbjpm.wasm +0 -0
- package/dist/yup-01-30ecpeh9.mp3 +0 -0
- package/package.json +2 -2
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
// @bun
|
|
2
|
+
import{bh as u,ch as S,dh as v}from"./chunk-7svw66kw.js";import{Ah as $,Bh as D,Fh as N,Gh as A,Kh as E,Mh as H,Oh as O,lh as q,qh as U,uh as k,xh as y}from"./chunk-yp2zfcvh.js";import"./chunk-21x3anp4.js";import{Du as j}from"./chunk-ntvr3177.js";import"./chunk-8j3aw4qg.js";var C=$(()=>D(j.object({error:j.object({message:j.string()})}))),f=$(()=>D(j.object({id:j.string().nullish(),model:j.string().nullish(),results:j.array(j.object({index:j.number(),relevance_score:j.number()})),usage:j.object({prompt_tokens:j.number(),completion_tokens:j.number(),total_tokens:j.number()})}))),M=$(()=>D(j.object({rankFields:j.array(j.string()).optional()}))),h=class{constructor(F,G){this.specificationVersion="v3",this.modelId=F,this.config=G}get provider(){return this.config.provider}async doRerank({documents:F,headers:G,query:K,topN:V,abortSignal:W,providerOptions:Y}){var J,P;let Z=await N({provider:"togetherai",providerOptions:Y,schema:M}),{responseHeaders:X,value:B,rawValue:x}=await A({url:`${this.config.baseURL}/rerank`,headers:q(this.config.headers(),G),body:{model:this.modelId,documents:F.values,query:K,top_n:V,rank_fields:Z==null?void 0:Z.rankFields,return_documents:!1},failedResponseHandler:E({errorSchema:C,errorToMessage:(Q)=>Q.error.message}),successfulResponseHandler:H(f),abortSignal:W,fetch:this.config.fetch});return{ranking:B.results.map((Q)=>({index:Q.index,relevanceScore:Q.relevance_score})),response:{id:(J=B.id)!=null?J:void 0,modelId:(P=B.model)!=null?P:void 0,headers:X,body:x}}}},I=class{constructor(F,G){this.modelId=F,this.config=G,this.specificationVersion="v3",this.maxImagesPerCall=1}get provider(){return this.config.provider}async doGenerate({prompt:F,n:G,size:K,seed:V,providerOptions:W,headers:Y,abortSignal:J,files:P,mask:Z}){var X,B,x;let Q=[];if(Z!=null)throw Error("Together AI does not support mask-based image editing. Use FLUX Kontext models (e.g., black-forest-labs/FLUX.1-kontext-pro) with a reference image and descriptive prompt instead.");if(K!=null)Q.push({type:"unsupported",feature:"aspectRatio",details:"This model does not support the `aspectRatio` option. Use `size` instead."});let _=(x=(B=(X=this.config._internal)==null?void 0:X.currentDate)==null?void 0:B.call(X))!=null?x:new Date,R=await N({provider:"togetherai",providerOptions:W,schema:m}),w;if(P!=null&&P.length>0){if(w=U(P[0]),P.length>1)Q.push({type:"other",message:"Together AI only supports a single input image. Additional images are ignored."})}let T=K==null?void 0:K.split("x"),{value:b,responseHeaders:z}=await A({url:`${this.config.baseURL}/images/generations`,headers:q(this.config.headers(),Y),body:{model:this.modelId,prompt:F,seed:V,...G>1?{n:G}:{},...T&&{width:parseInt(T[0]),height:parseInt(T[1])},...w!=null?{image_url:w}:{},response_format:"base64",...R!=null?R:{}},failedResponseHandler:E({errorSchema:g,errorToMessage:(L)=>L.error.message}),successfulResponseHandler:H(c),abortSignal:J,fetch:this.config.fetch});return{images:b.data.map((L)=>L.b64_json),warnings:Q,response:{timestamp:_,modelId:this.modelId,headers:z}}}},c=j.object({data:j.array(j.object({b64_json:j.string()}))}),g=j.object({error:j.object({message:j.string()})}),m=$(()=>D(j.object({steps:j.number().nullish(),guidance:j.number().nullish(),negative_prompt:j.string().nullish(),disable_safety_checker:j.boolean().nullish()}).passthrough())),p="2.0.41";function l(){if(typeof process>"u")return;if(typeof process.env.TOGETHER_API_KEY==="string")return;let F=process.env.TOGETHER_AI_API_KEY;if(typeof F==="string")console.warn("TOGETHER_AI_API_KEY is deprecated and will be removed in a future release. Please use TOGETHER_API_KEY instead.");return F}function n(F={}){var G;let K=O((G=F.baseURL)!=null?G:"https://api.together.xyz/v1/"),V=()=>{var x;return k({Authorization:`Bearer ${y({apiKey:(x=F.apiKey)!=null?x:l(),environmentVariableName:"TOGETHER_API_KEY",description:"TogetherAI"})}`,...F.headers},`ai-sdk/togetherai/${p}`)},W=(x)=>({provider:`togetherai.${x}`,url:({path:Q})=>`${K}${Q}`,headers:V,fetch:F.fetch}),Y=(x)=>{return new u(x,W("chat"))},J=(x)=>new S(x,W("completion")),P=(x)=>new v(x,W("embedding")),Z=(x)=>new I(x,{...W("image"),baseURL:K!=null?K:"https://api.together.xyz/v1/"}),X=(x)=>new h(x,{...W("reranking"),baseURL:K!=null?K:"https://api.together.xyz/v1/"}),B=(x)=>Y(x);return B.specificationVersion="v3",B.completionModel=J,B.languageModel=Y,B.chatModel=Y,B.embeddingModel=P,B.textEmbeddingModel=P,B.image=Z,B.imageModel=Z,B.reranking=X,B.rerankingModel=X,B}var xj=n();export{xj as togetherai,n as createTogetherAI,p as VERSION};
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
// @bun
|
|
2
|
+
import{$o as KJ,Ar as G$,Cp as a,Cr as u8,Dp as E0,Dr as n5,Ep as eJ,Fr as Y7,Hp as r5,Ip as t0,Jp as mJ,Jr as h7,Kp as T6,Kr as j$,Lr as V0,Mr as i0,Nr as d0,Op as s,Pp as e0,Qq as kY,Sr as F0,Tr as l0,Up as G0,Ur as YJ,Vp as WJ,Vq as eY,Vr as O5,Wp as u$,Wr as k5,Zp as t8,Zq as C$,_p as g$,_q as yY,_r as m$,aq as C5,bp as tY,bq as c$,cq as f5,cr as SY,dp as g7,eq as xJ,go as P8,gq as RJ,hq as $J,iq as i5,jq as yJ,kq as o5,oq as q0,qp as wY,sp as g8,tp as h8,wp as Q5,xp as sJ,yp as a5}from"./chunk-zhd8f4pc.js";import{gs as P$}from"./chunk-my9cfmvt.js";import{rs as qJ,ss as aJ,ts as oY,xs as rJ}from"./chunk-8jy0dvcn.js";import{Ot as J7,Vt as $7}from"./chunk-21x3anp4.js";import{AF as Q,Dw as TJ,Fx as n0,Gy as R$,Hz as F6,Rx as S8,TC as h5,Yz as j0,eC as B,fz as O$,gA as nY,hD as iY,hz as g5,tD as m5,tz as E6}from"./chunk-1mqsg5s7.js";import{QF as aV,RF as f0,SF as QJ,UF as T$}from"./chunk-8j3aw4qg.js";var $$=f0((f6)=>{Object.defineProperty(f6,"__esModule",{value:!0});f6.stringArray=f6.array=f6.func=f6.error=f6.number=f6.string=f6.boolean=void 0;function UZ(J){return J===!0||J===!1}f6.boolean=UZ;function C6(J){return typeof J==="string"||J instanceof String}f6.string=C6;function KZ(J){return typeof J==="number"||J instanceof Number}f6.number=KZ;function GZ(J){return J instanceof Error}f6.error=GZ;function WZ(J){return typeof J==="function"}f6.func=WZ;function b6(J){return Array.isArray(J)}f6.array=b6;function zZ(J){return b6(J)&&J.every(($)=>C6($))}f6.stringArray=zZ});var $8=f0((V9)=>{Object.defineProperty(V9,"__esModule",{value:!0});V9.Message=V9.NotificationType9=V9.NotificationType8=V9.NotificationType7=V9.NotificationType6=V9.NotificationType5=V9.NotificationType4=V9.NotificationType3=V9.NotificationType2=V9.NotificationType1=V9.NotificationType0=V9.NotificationType=V9.RequestType9=V9.RequestType8=V9.RequestType7=V9.RequestType6=V9.RequestType5=V9.RequestType4=V9.RequestType3=V9.RequestType2=V9.RequestType1=V9.RequestType=V9.RequestType0=V9.AbstractMessageSignature=V9.ParameterStructures=V9.ResponseError=V9.ErrorCodes=void 0;var SJ=$$(),e5;(function(J){J.ParseError=-32700,J.InvalidRequest=-32600,J.MethodNotFound=-32601,J.InvalidParams=-32602,J.InternalError=-32603,J.jsonrpcReservedErrorRangeStart=-32099,J.serverErrorStart=-32099,J.MessageWriteError=-32099,J.MessageReadError=-32098,J.PendingResponseRejected=-32097,J.ConnectionInactive=-32096,J.ServerNotInitialized=-32002,J.UnknownErrorCode=-32001,J.jsonrpcReservedErrorRangeEnd=-32000,J.serverErrorEnd=-32000})(e5||(V9.ErrorCodes=e5={}));class J8 extends Error{constructor(J,$,Y){super($);this.code=SJ.number(J)?J:e5.UnknownErrorCode,this.data=Y,Object.setPrototypeOf(this,J8.prototype)}toJson(){let J={code:this.code,message:this.message};if(this.data!==void 0)J.data=this.data;return J}}V9.ResponseError=J8;class k0{constructor(J){this.kind=J}static is(J){return J===k0.auto||J===k0.byName||J===k0.byPosition}toString(){return this.kind}}V9.ParameterStructures=k0;k0.auto=new k0("auto");k0.byPosition=new k0("byPosition");k0.byName=new k0("byName");class N0{constructor(J,$){this.method=J,this.numberOfParams=$}get parameterStructures(){return k0.auto}}V9.AbstractMessageSignature=N0;class S6 extends N0{constructor(J){super(J,0)}}V9.RequestType0=S6;class g6 extends N0{constructor(J,$=k0.auto){super(J,1);this._parameterStructures=$}get parameterStructures(){return this._parameterStructures}}V9.RequestType=g6;class h6 extends N0{constructor(J,$=k0.auto){super(J,1);this._parameterStructures=$}get parameterStructures(){return this._parameterStructures}}V9.RequestType1=h6;class u6 extends N0{constructor(J){super(J,2)}}V9.RequestType2=u6;class l6 extends N0{constructor(J){super(J,3)}}V9.RequestType3=l6;class x6 extends N0{constructor(J){super(J,4)}}V9.RequestType4=x6;class c6 extends N0{constructor(J){super(J,5)}}V9.RequestType5=c6;class p6 extends N0{constructor(J){super(J,6)}}V9.RequestType6=p6;class d6 extends N0{constructor(J){super(J,7)}}V9.RequestType7=d6;class m6 extends N0{constructor(J){super(J,8)}}V9.RequestType8=m6;class n6 extends N0{constructor(J){super(J,9)}}V9.RequestType9=n6;class i6 extends N0{constructor(J,$=k0.auto){super(J,1);this._parameterStructures=$}get parameterStructures(){return this._parameterStructures}}V9.NotificationType=i6;class o6 extends N0{constructor(J){super(J,0)}}V9.NotificationType0=o6;class a6 extends N0{constructor(J,$=k0.auto){super(J,1);this._parameterStructures=$}get parameterStructures(){return this._parameterStructures}}V9.NotificationType1=a6;class r6 extends N0{constructor(J){super(J,2)}}V9.NotificationType2=r6;class s6 extends N0{constructor(J){super(J,3)}}V9.NotificationType3=s6;class t6 extends N0{constructor(J){super(J,4)}}V9.NotificationType4=t6;class e6 extends N0{constructor(J){super(J,5)}}V9.NotificationType5=e6;class J9 extends N0{constructor(J){super(J,6)}}V9.NotificationType6=J9;class $9 extends N0{constructor(J){super(J,7)}}V9.NotificationType7=$9;class Y9 extends N0{constructor(J){super(J,8)}}V9.NotificationType8=Y9;class Z9 extends N0{constructor(J){super(J,9)}}V9.NotificationType9=Z9;var y6;(function(J){function $(V){let X=V;return X&&SJ.string(X.method)&&(SJ.string(X.id)||SJ.number(X.id))}J.isRequest=$;function Y(V){let X=V;return X&&SJ.string(X.method)&&V.id===void 0}J.isNotification=Y;function Z(V){let X=V;return X&&(X.result!==void 0||!!X.error)&&(SJ.string(X.id)||SJ.number(X.id)||X.id===null)}J.isResponse=Z})(y6||(V9.Message=y6={}))});var Z8=f0((U9)=>{var Q9;Object.defineProperty(U9,"__esModule",{value:!0});U9.LRUCache=U9.LinkedMap=U9.Touch=void 0;var y0;(function(J){J.None=0,J.First=1,J.AsOld=J.First,J.Last=2,J.AsNew=J.Last})(y0||(U9.Touch=y0={}));class Y8{constructor(){this[Q9]="LinkedMap",this._map=new Map,this._head=void 0,this._tail=void 0,this._size=0,this._state=0}clear(){this._map.clear(),this._head=void 0,this._tail=void 0,this._size=0,this._state++}isEmpty(){return!this._head&&!this._tail}get size(){return this._size}get first(){return this._head?.value}get last(){return this._tail?.value}has(J){return this._map.has(J)}get(J,$=y0.None){let Y=this._map.get(J);if(!Y)return;if($!==y0.None)this.touch(Y,$);return Y.value}set(J,$,Y=y0.None){let Z=this._map.get(J);if(Z){if(Z.value=$,Y!==y0.None)this.touch(Z,Y)}else{switch(Z={key:J,value:$,next:void 0,previous:void 0},Y){case y0.None:this.addItemLast(Z);break;case y0.First:this.addItemFirst(Z);break;case y0.Last:this.addItemLast(Z);break;default:this.addItemLast(Z);break}this._map.set(J,Z),this._size++}return this}delete(J){return!!this.remove(J)}remove(J){let $=this._map.get(J);if(!$)return;return this._map.delete(J),this.removeItem($),this._size--,$.value}shift(){if(!this._head&&!this._tail)return;if(!this._head||!this._tail)throw Error("Invalid list");let J=this._head;return this._map.delete(J.key),this.removeItem(J),this._size--,J.value}forEach(J,$){let Y=this._state,Z=this._head;while(Z){if($)J.bind($)(Z.value,Z.key,this);else J(Z.value,Z.key,this);if(this._state!==Y)throw Error("LinkedMap got modified during iteration.");Z=Z.next}}keys(){let J=this._state,$=this._head,Y={[Symbol.iterator]:()=>{return Y},next:()=>{if(this._state!==J)throw Error("LinkedMap got modified during iteration.");if($){let Z={value:$.key,done:!1};return $=$.next,Z}else return{value:void 0,done:!0}}};return Y}values(){let J=this._state,$=this._head,Y={[Symbol.iterator]:()=>{return Y},next:()=>{if(this._state!==J)throw Error("LinkedMap got modified during iteration.");if($){let Z={value:$.value,done:!1};return $=$.next,Z}else return{value:void 0,done:!0}}};return Y}entries(){let J=this._state,$=this._head,Y={[Symbol.iterator]:()=>{return Y},next:()=>{if(this._state!==J)throw Error("LinkedMap got modified during iteration.");if($){let Z={value:[$.key,$.value],done:!1};return $=$.next,Z}else return{value:void 0,done:!0}}};return Y}[(Q9=Symbol.toStringTag,Symbol.iterator)](){return this.entries()}trimOld(J){if(J>=this.size)return;if(J===0){this.clear();return}let $=this._head,Y=this.size;while($&&Y>J)this._map.delete($.key),$=$.next,Y--;if(this._head=$,this._size=Y,$)$.previous=void 0;this._state++}addItemFirst(J){if(!this._head&&!this._tail)this._tail=J;else if(!this._head)throw Error("Invalid list");else J.next=this._head,this._head.previous=J;this._head=J,this._state++}addItemLast(J){if(!this._head&&!this._tail)this._head=J;else if(!this._tail)throw Error("Invalid list");else J.previous=this._tail,this._tail.next=J;this._tail=J,this._state++}removeItem(J){if(J===this._head&&J===this._tail)this._head=void 0,this._tail=void 0;else if(J===this._head){if(!J.next)throw Error("Invalid list");J.next.previous=void 0,this._head=J.next}else if(J===this._tail){if(!J.previous)throw Error("Invalid list");J.previous.next=void 0,this._tail=J.previous}else{let{next:$,previous:Y}=J;if(!$||!Y)throw Error("Invalid list");$.previous=Y,Y.next=$}J.next=void 0,J.previous=void 0,this._state++}touch(J,$){if(!this._head||!this._tail)throw Error("Invalid list");if($!==y0.First&&$!==y0.Last)return;if($===y0.First){if(J===this._head)return;let{next:Y,previous:Z}=J;if(J===this._tail)Z.next=void 0,this._tail=Z;else Y.previous=Z,Z.next=Y;J.previous=void 0,J.next=this._head,this._head.previous=J,this._head=J,this._state++}else if($===y0.Last){if(J===this._tail)return;let{next:Y,previous:Z}=J;if(J===this._head)Y.previous=void 0,this._head=Y;else Y.previous=Z,Z.next=Y;J.next=void 0,J.previous=this._tail,this._tail.next=J,this._tail=J,this._state++}}toJSON(){let J=[];return this.forEach(($,Y)=>{J.push([Y,$])}),J}fromJSON(J){this.clear();for(let[$,Y]of J)this.set($,Y)}}U9.LinkedMap=Y8;class F9 extends Y8{constructor(J,$=1){super();this._limit=J,this._ratio=Math.min(Math.max(0,$),1)}get limit(){return this._limit}set limit(J){this._limit=J,this.checkTrim()}get ratio(){return this._ratio}set ratio(J){this._ratio=Math.min(Math.max(0,J),1),this.checkTrim()}get(J,$=y0.AsNew){return super.get(J,$)}peek(J){return super.get(J,y0.None)}set(J,$){return super.set(J,$,y0.Last),this.checkTrim(),this}checkTrim(){if(this.size>this._limit)this.trimOld(Math.round(this._limit*this._ratio))}}U9.LRUCache=F9});var H9=f0((W9)=>{Object.defineProperty(W9,"__esModule",{value:!0});W9.Disposable=void 0;var G9;(function(J){function $(Y){return{dispose:Y}}J.create=$})(G9||(W9.Disposable=G9={}))});var vJ=f0((j9)=>{Object.defineProperty(j9,"__esModule",{value:!0});var V8;function X8(){if(V8===void 0)throw Error("No runtime abstraction layer installed");return V8}(function(J){function $(Y){if(Y===void 0)throw Error("No runtime abstraction layer provided");V8=Y}J.install=$})(X8||(X8={}));j9.default=X8});var Y$=f0((A9)=>{Object.defineProperty(A9,"__esModule",{value:!0});A9.Emitter=A9.Event=void 0;var oZ=vJ(),B9;(function(J){let $={dispose(){}};J.None=function(){return $}})(B9||(A9.Event=B9={}));class N9{add(J,$=null,Y){if(!this._callbacks)this._callbacks=[],this._contexts=[];if(this._callbacks.push(J),this._contexts.push($),Array.isArray(Y))Y.push({dispose:()=>this.remove(J,$)})}remove(J,$=null){if(!this._callbacks)return;let Y=!1;for(let Z=0,V=this._callbacks.length;Z<V;Z++)if(this._callbacks[Z]===J)if(this._contexts[Z]===$){this._callbacks.splice(Z,1),this._contexts.splice(Z,1);return}else Y=!0;if(Y)throw Error("When adding a listener with a context, you should remove it with the same context")}invoke(...J){if(!this._callbacks)return[];let $=[],Y=this._callbacks.slice(0),Z=this._contexts.slice(0);for(let V=0,X=Y.length;V<X;V++)try{$.push(Y[V].apply(Z[V],J))}catch(U){(0,oZ.default)().console.error(U)}return $}isEmpty(){return!this._callbacks||this._callbacks.length===0}dispose(){this._callbacks=void 0,this._contexts=void 0}}class F5{constructor(J){this._options=J}get event(){if(!this._event)this._event=(J,$,Y)=>{if(!this._callbacks)this._callbacks=new N9;if(this._options&&this._options.onFirstListenerAdd&&this._callbacks.isEmpty())this._options.onFirstListenerAdd(this);this._callbacks.add(J,$);let Z={dispose:()=>{if(!this._callbacks)return;if(this._callbacks.remove(J,$),Z.dispose=F5._noop,this._options&&this._options.onLastListenerRemove&&this._callbacks.isEmpty())this._options.onLastListenerRemove(this)}};if(Array.isArray(Y))Y.push(Z);return Z};return this._event}fire(J){if(this._callbacks)this._callbacks.invoke.call(this._callbacks,J)}dispose(){if(this._callbacks)this._callbacks.dispose(),this._callbacks=void 0}}A9.Emitter=F5;F5._noop=function(){}});var K5=f0((I9)=>{Object.defineProperty(I9,"__esModule",{value:!0});I9.CancellationTokenSource=I9.CancellationToken=void 0;var rZ=vJ(),sZ=$$(),Q8=Y$(),U5;(function(J){J.None=Object.freeze({isCancellationRequested:!1,onCancellationRequested:Q8.Event.None}),J.Cancelled=Object.freeze({isCancellationRequested:!0,onCancellationRequested:Q8.Event.None});function $(Y){let Z=Y;return Z&&(Z===J.None||Z===J.Cancelled||sZ.boolean(Z.isCancellationRequested)&&!!Z.onCancellationRequested)}J.is=$})(U5||(I9.CancellationToken=U5={}));var tZ=Object.freeze(function(J,$){let Y=(0,rZ.default)().timer.setTimeout(J.bind($),0);return{dispose(){Y.dispose()}}});class F8{constructor(){this._isCancelled=!1}cancel(){if(!this._isCancelled){if(this._isCancelled=!0,this._emitter)this._emitter.fire(void 0),this.dispose()}}get isCancellationRequested(){return this._isCancelled}get onCancellationRequested(){if(this._isCancelled)return tZ;if(!this._emitter)this._emitter=new Q8.Emitter;return this._emitter.event}dispose(){if(this._emitter)this._emitter.dispose(),this._emitter=void 0}}class O9{get token(){if(!this._token)this._token=new F8;return this._token}cancel(){if(!this._token)this._token=U5.Cancelled;else this._token.cancel()}dispose(){if(!this._token)this._token=U5.None;else if(this._token instanceof F8)this._token.dispose()}}I9.CancellationTokenSource=O9});var T9=f0((M9)=>{Object.defineProperty(M9,"__esModule",{value:!0});M9.SharedArrayReceiverStrategy=M9.SharedArraySenderStrategy=void 0;var JV=K5(),_$;(function(J){J.Continue=0,J.Cancelled=1})(_$||(_$={}));class _9{constructor(){this.buffers=new Map}enableCancellation(J){if(J.id===null)return;let $=new SharedArrayBuffer(4),Y=new Int32Array($,0,1);Y[0]=_$.Continue,this.buffers.set(J.id,$),J.$cancellationData=$}async sendCancellation(J,$){let Y=this.buffers.get($);if(Y===void 0)return;let Z=new Int32Array(Y,0,1);Atomics.store(Z,0,_$.Cancelled)}cleanup(J){this.buffers.delete(J)}dispose(){this.buffers.clear()}}M9.SharedArraySenderStrategy=_9;class q9{constructor(J){this.data=new Int32Array(J,0,1)}get isCancellationRequested(){return Atomics.load(this.data,0)===_$.Cancelled}get onCancellationRequested(){throw Error("Cancellation over SharedArrayBuffer doesn't support cancellation events")}}class E9{constructor(J){this.token=new q9(J)}cancel(){}dispose(){}}class L9{constructor(){this.kind="request"}createCancellationTokenSource(J){let $=J.$cancellationData;if($===void 0)return new JV.CancellationTokenSource;return new E9($)}}M9.SharedArrayReceiverStrategy=L9});var U8=f0((P9)=>{Object.defineProperty(P9,"__esModule",{value:!0});P9.Semaphore=void 0;var YV=vJ();class v9{constructor(J=1){if(J<=0)throw Error("Capacity must be greater than 0");this._capacity=J,this._active=0,this._waiting=[]}lock(J){return new Promise(($,Y)=>{this._waiting.push({thunk:J,resolve:$,reject:Y}),this.runNext()})}get active(){return this._active}runNext(){if(this._waiting.length===0||this._active===this._capacity)return;(0,YV.default)().timer.setImmediate(()=>this.doRunNext())}doRunNext(){if(this._waiting.length===0||this._active===this._capacity)return;let J=this._waiting.shift();if(this._active++,this._active>this._capacity)throw Error("To many thunks active");try{let $=J.thunk();if($ instanceof Promise)$.then((Y)=>{this._active--,J.resolve(Y),this.runNext()},(Y)=>{this._active--,J.reject(Y),this.runNext()});else this._active--,J.resolve($),this.runNext()}catch($){this._active--,J.reject($),this.runNext()}}}P9.Semaphore=v9});var S9=f0((k9)=>{Object.defineProperty(k9,"__esModule",{value:!0});k9.ReadableStreamMessageReader=k9.AbstractMessageReader=k9.MessageReader=void 0;var G8=vJ(),Z$=$$(),K8=Y$(),ZV=U8(),b9;(function(J){function $(Y){let Z=Y;return Z&&Z$.func(Z.listen)&&Z$.func(Z.dispose)&&Z$.func(Z.onError)&&Z$.func(Z.onClose)&&Z$.func(Z.onPartialMessage)}J.is=$})(b9||(k9.MessageReader=b9={}));class z8{constructor(){this.errorEmitter=new K8.Emitter,this.closeEmitter=new K8.Emitter,this.partialMessageEmitter=new K8.Emitter}dispose(){this.errorEmitter.dispose(),this.closeEmitter.dispose()}get onError(){return this.errorEmitter.event}fireError(J){this.errorEmitter.fire(this.asError(J))}get onClose(){return this.closeEmitter.event}fireClose(){this.closeEmitter.fire(void 0)}get onPartialMessage(){return this.partialMessageEmitter.event}firePartialMessage(J){this.partialMessageEmitter.fire(J)}asError(J){if(J instanceof Error)return J;else return Error(`Reader received error. Reason: ${Z$.string(J.message)?J.message:"unknown"}`)}}k9.AbstractMessageReader=z8;var W8;(function(J){function $(Y){let Z,V,X,U=new Map,F,K=new Map;if(Y===void 0||typeof Y==="string")Z=Y??"utf-8";else{if(Z=Y.charset??"utf-8",Y.contentDecoder!==void 0)X=Y.contentDecoder,U.set(X.name,X);if(Y.contentDecoders!==void 0)for(let G of Y.contentDecoders)U.set(G.name,G);if(Y.contentTypeDecoder!==void 0)F=Y.contentTypeDecoder,K.set(F.name,F);if(Y.contentTypeDecoders!==void 0)for(let G of Y.contentTypeDecoders)K.set(G.name,G)}if(F===void 0)F=(0,G8.default)().applicationJson.decoder,K.set(F.name,F);return{charset:Z,contentDecoder:X,contentDecoders:U,contentTypeDecoder:F,contentTypeDecoders:K}}J.fromOptions=$})(W8||(W8={}));class f9 extends z8{constructor(J,$){super();this.readable=J,this.options=W8.fromOptions($),this.buffer=(0,G8.default)().messageBuffer.create(this.options.charset),this._partialMessageTimeout=1e4,this.nextMessageLength=-1,this.messageToken=0,this.readSemaphore=new ZV.Semaphore(1)}set partialMessageTimeout(J){this._partialMessageTimeout=J}get partialMessageTimeout(){return this._partialMessageTimeout}listen(J){this.nextMessageLength=-1,this.messageToken=0,this.partialMessageTimer=void 0,this.callback=J;let $=this.readable.onData((Y)=>{this.onData(Y)});return this.readable.onError((Y)=>this.fireError(Y)),this.readable.onClose(()=>this.fireClose()),$}onData(J){try{this.buffer.append(J);while(!0){if(this.nextMessageLength===-1){let Y=this.buffer.tryReadHeaders(!0);if(!Y)return;let Z=Y.get("content-length");if(!Z){this.fireError(Error(`Header must provide a Content-Length property.
|
|
3
|
+
${JSON.stringify(Object.fromEntries(Y))}`));return}let V=parseInt(Z);if(isNaN(V)){this.fireError(Error(`Content-Length value must be a number. Got ${Z}`));return}this.nextMessageLength=V}let $=this.buffer.tryReadBody(this.nextMessageLength);if($===void 0){this.setPartialMessageTimer();return}this.clearPartialMessageTimer(),this.nextMessageLength=-1,this.readSemaphore.lock(async()=>{let Y=this.options.contentDecoder!==void 0?await this.options.contentDecoder.decode($):$,Z=await this.options.contentTypeDecoder.decode(Y,this.options);this.callback(Z)}).catch((Y)=>{this.fireError(Y)})}}catch($){this.fireError($)}}clearPartialMessageTimer(){if(this.partialMessageTimer)this.partialMessageTimer.dispose(),this.partialMessageTimer=void 0}setPartialMessageTimer(){if(this.clearPartialMessageTimer(),this._partialMessageTimeout<=0)return;this.partialMessageTimer=(0,G8.default)().timer.setTimeout((J,$)=>{if(this.partialMessageTimer=void 0,J===this.messageToken)this.firePartialMessage({messageToken:J,waitingTime:$}),this.setPartialMessageTimer()},this._partialMessageTimeout,this.messageToken,this._partialMessageTimeout)}}k9.ReadableStreamMessageReader=f9});var d9=f0((c9)=>{Object.defineProperty(c9,"__esModule",{value:!0});c9.WriteableStreamMessageWriter=c9.AbstractMessageWriter=c9.MessageWriter=void 0;var g9=vJ(),q$=$$(),QV=U8(),h9=Y$(),FV="Content-Length: ",u9=`\r
|
|
4
|
+
`,l9;(function(J){function $(Y){let Z=Y;return Z&&q$.func(Z.dispose)&&q$.func(Z.onClose)&&q$.func(Z.onError)&&q$.func(Z.write)}J.is=$})(l9||(c9.MessageWriter=l9={}));class j8{constructor(){this.errorEmitter=new h9.Emitter,this.closeEmitter=new h9.Emitter}dispose(){this.errorEmitter.dispose(),this.closeEmitter.dispose()}get onError(){return this.errorEmitter.event}fireError(J,$,Y){this.errorEmitter.fire([this.asError(J),$,Y])}get onClose(){return this.closeEmitter.event}fireClose(){this.closeEmitter.fire(void 0)}asError(J){if(J instanceof Error)return J;else return Error(`Writer received error. Reason: ${q$.string(J.message)?J.message:"unknown"}`)}}c9.AbstractMessageWriter=j8;var H8;(function(J){function $(Y){if(Y===void 0||typeof Y==="string")return{charset:Y??"utf-8",contentTypeEncoder:(0,g9.default)().applicationJson.encoder};else return{charset:Y.charset??"utf-8",contentEncoder:Y.contentEncoder,contentTypeEncoder:Y.contentTypeEncoder??(0,g9.default)().applicationJson.encoder}}J.fromOptions=$})(H8||(H8={}));class x9 extends j8{constructor(J,$){super();this.writable=J,this.options=H8.fromOptions($),this.errorCount=0,this.writeSemaphore=new QV.Semaphore(1),this.writable.onError((Y)=>this.fireError(Y)),this.writable.onClose(()=>this.fireClose())}async write(J){return this.writeSemaphore.lock(async()=>{return this.options.contentTypeEncoder.encode(J,this.options).then((Y)=>{if(this.options.contentEncoder!==void 0)return this.options.contentEncoder.encode(Y);else return Y}).then((Y)=>{let Z=[];return Z.push(FV,Y.byteLength.toString(),u9),Z.push(u9),this.doWrite(J,Z,Y)},(Y)=>{throw this.fireError(Y),Y})})}async doWrite(J,$,Y){try{return await this.writable.write($.join(""),"ascii"),this.writable.write(Y)}catch(Z){return this.handleError(Z,J),Promise.reject(Z)}}handleError(J,$){this.errorCount++,this.fireError(J,$,this.errorCount)}end(){this.writable.end()}}c9.WriteableStreamMessageWriter=x9});var o9=f0((n9)=>{Object.defineProperty(n9,"__esModule",{value:!0});n9.AbstractMessageBuffer=void 0;var GV=13,WV=10,zV=`\r
|
|
5
|
+
`;class m9{constructor(J="utf-8"){this._encoding=J,this._chunks=[],this._totalLength=0}get encoding(){return this._encoding}append(J){let $=typeof J==="string"?this.fromString(J,this._encoding):J;this._chunks.push($),this._totalLength+=$.byteLength}tryReadHeaders(J=!1){if(this._chunks.length===0)return;let $=0,Y=0,Z=0,V=0;J:while(Y<this._chunks.length){let K=this._chunks[Y];Z=0;$:while(Z<K.length){switch(K[Z]){case GV:switch($){case 0:$=1;break;case 2:$=3;break;default:$=0}break;case WV:switch($){case 1:$=2;break;case 3:$=4,Z++;break J;default:$=0}break;default:$=0}Z++}V+=K.byteLength,Y++}if($!==4)return;let X=this._read(V+Z),U=new Map,F=this.toString(X,"ascii").split(zV);if(F.length<2)return U;for(let K=0;K<F.length-2;K++){let G=F[K],W=G.indexOf(":");if(W===-1)throw Error(`Message header must separate key and value using ':'
|
|
6
|
+
${G}`);let z=G.substr(0,W),A=G.substr(W+1).trim();U.set(J?z.toLowerCase():z,A)}return U}tryReadBody(J){if(this._totalLength<J)return;return this._read(J)}get numberOfBytes(){return this._totalLength}_read(J){if(J===0)return this.emptyBuffer();if(J>this._totalLength)throw Error("Cannot read so many bytes!");if(this._chunks[0].byteLength===J){let V=this._chunks[0];return this._chunks.shift(),this._totalLength-=J,this.asNative(V)}if(this._chunks[0].byteLength>J){let V=this._chunks[0],X=this.asNative(V,J);return this._chunks[0]=V.slice(J),this._totalLength-=J,X}let $=this.allocNative(J),Y=0,Z=0;while(J>0){let V=this._chunks[Z];if(V.byteLength>J){let X=V.slice(0,J);$.set(X,Y),Y+=J,this._chunks[Z]=V.slice(J),this._totalLength-=J,J-=J}else $.set(V,Y),Y+=V.byteLength,this._chunks.shift(),this._totalLength-=V.byteLength,J-=V.byteLength}return $}}n9.AbstractMessageBuffer=m9});var XY=f0((JY)=>{Object.defineProperty(JY,"__esModule",{value:!0});JY.createMessageConnection=JY.ConnectionOptions=JY.MessageStrategy=JY.CancellationStrategy=JY.CancellationSenderStrategy=JY.CancellationReceiverStrategy=JY.RequestCancellationReceiverStrategy=JY.IdCancellationReceiverStrategy=JY.ConnectionStrategy=JY.ConnectionError=JY.ConnectionErrors=JY.LogTraceNotification=JY.SetTraceNotification=JY.TraceFormat=JY.TraceValues=JY.Trace=JY.NullLogger=JY.ProgressType=JY.ProgressToken=void 0;var a9=vJ(),O0=$$(),m=$8(),r9=Z8(),E$=Y$(),B8=K5(),w$;(function(J){J.type=new m.NotificationType("$/cancelRequest")})(w$||(w$={}));var N8;(function(J){function $(Y){return typeof Y==="string"||typeof Y==="number"}J.is=$})(N8||(JY.ProgressToken=N8={}));var L$;(function(J){J.type=new m.NotificationType("$/progress")})(L$||(L$={}));class e9{constructor(){}}JY.ProgressType=e9;var A8;(function(J){function $(Y){return O0.func(Y)}J.is=$})(A8||(A8={}));JY.NullLogger=Object.freeze({error:()=>{},warn:()=>{},info:()=>{},log:()=>{}});var Z0;(function(J){J[J.Off=0]="Off",J[J.Messages=1]="Messages",J[J.Compact=2]="Compact",J[J.Verbose=3]="Verbose"})(Z0||(JY.Trace=Z0={}));var s9;(function(J){J.Off="off",J.Messages="messages",J.Compact="compact",J.Verbose="verbose"})(s9||(JY.TraceValues=s9={}));(function(J){function $(Z){if(!O0.string(Z))return J.Off;switch(Z=Z.toLowerCase(),Z){case"off":return J.Off;case"messages":return J.Messages;case"compact":return J.Compact;case"verbose":return J.Verbose;default:return J.Off}}J.fromString=$;function Y(Z){switch(Z){case J.Off:return"off";case J.Messages:return"messages";case J.Compact:return"compact";case J.Verbose:return"verbose";default:return"off"}}J.toString=Y})(Z0||(JY.Trace=Z0={}));var c0;(function(J){J.Text="text",J.JSON="json"})(c0||(JY.TraceFormat=c0={}));(function(J){function $(Y){if(!O0.string(Y))return J.Text;if(Y=Y.toLowerCase(),Y==="json")return J.JSON;else return J.Text}J.fromString=$})(c0||(JY.TraceFormat=c0={}));var R8;(function(J){J.type=new m.NotificationType("$/setTrace")})(R8||(JY.SetTraceNotification=R8={}));var G5;(function(J){J.type=new m.NotificationType("$/logTrace")})(G5||(JY.LogTraceNotification=G5={}));var M$;(function(J){J[J.Closed=1]="Closed",J[J.Disposed=2]="Disposed",J[J.AlreadyListening=3]="AlreadyListening"})(M$||(JY.ConnectionErrors=M$={}));class V$ extends Error{constructor(J,$){super($);this.code=J,Object.setPrototypeOf(this,V$.prototype)}}JY.ConnectionError=V$;var O8;(function(J){function $(Y){let Z=Y;return Z&&O0.func(Z.cancelUndispatched)}J.is=$})(O8||(JY.ConnectionStrategy=O8={}));var W5;(function(J){function $(Y){let Z=Y;return Z&&(Z.kind===void 0||Z.kind==="id")&&O0.func(Z.createCancellationTokenSource)&&(Z.dispose===void 0||O0.func(Z.dispose))}J.is=$})(W5||(JY.IdCancellationReceiverStrategy=W5={}));var I8;(function(J){function $(Y){let Z=Y;return Z&&Z.kind==="request"&&O0.func(Z.createCancellationTokenSource)&&(Z.dispose===void 0||O0.func(Z.dispose))}J.is=$})(I8||(JY.RequestCancellationReceiverStrategy=I8={}));var z5;(function(J){J.Message=Object.freeze({createCancellationTokenSource(Y){return new B8.CancellationTokenSource}});function $(Y){return W5.is(Y)||I8.is(Y)}J.is=$})(z5||(JY.CancellationReceiverStrategy=z5={}));var H5;(function(J){J.Message=Object.freeze({sendCancellation(Y,Z){return Y.sendNotification(w$.type,{id:Z})},cleanup(Y){}});function $(Y){let Z=Y;return Z&&O0.func(Z.sendCancellation)&&O0.func(Z.cleanup)}J.is=$})(H5||(JY.CancellationSenderStrategy=H5={}));var j5;(function(J){J.Message=Object.freeze({receiver:z5.Message,sender:H5.Message});function $(Y){let Z=Y;return Z&&z5.is(Z.receiver)&&H5.is(Z.sender)}J.is=$})(j5||(JY.CancellationStrategy=j5={}));var B5;(function(J){function $(Y){let Z=Y;return Z&&O0.func(Z.handleMessage)}J.is=$})(B5||(JY.MessageStrategy=B5={}));var t9;(function(J){function $(Y){let Z=Y;return Z&&(j5.is(Z.cancellationStrategy)||O8.is(Z.connectionStrategy)||B5.is(Z.messageStrategy))}J.is=$})(t9||(JY.ConnectionOptions=t9={}));var JJ;(function(J){J[J.New=1]="New",J[J.Listening=2]="Listening",J[J.Closed=3]="Closed",J[J.Disposed=4]="Disposed"})(JJ||(JJ={}));function HV(J,$,Y,Z){let V=Y!==void 0?Y:JY.NullLogger,X=0,U=0,F=0,K="2.0",G=void 0,W=new Map,z=void 0,A=new Map,j=new Map,D,O=new r9.LinkedMap,P=new Map,M=new Set,C=new Map,q=Z0.Off,f=c0.Text,_,y=JJ.New,k=new E$.Emitter,n=new E$.Emitter,d=new E$.Emitter,X0=new E$.Emitter,o=new E$.Emitter,t=Z&&Z.cancellationStrategy?Z.cancellationStrategy:j5.Message;function R(H){if(H===null)throw Error("Can't send requests with id null since the response can't be correlated.");return"req-"+H.toString()}function T(H){if(H===null)return"res-unknown-"+(++F).toString();else return"res-"+H.toString()}function N(){return"not-"+(++U).toString()}function I(H,E){if(m.Message.isRequest(E))H.set(R(E.id),E);else if(m.Message.isResponse(E))H.set(T(E.id),E);else H.set(N(),E)}function w(H){return}function v(){return y===JJ.Listening}function S(){return y===JJ.Closed}function g(){return y===JJ.Disposed}function c(){if(y===JJ.New||y===JJ.Listening)y=JJ.Closed,n.fire(void 0)}function r(H){k.fire([H,void 0,void 0])}function e(H){k.fire(H)}J.onClose(c),J.onError(r),$.onClose(c),$.onError(e);function z0(){if(D||O.size===0)return;D=(0,a9.default)().timer.setImmediate(()=>{D=void 0,J0()})}function l(H){if(m.Message.isRequest(H))B0(H);else if(m.Message.isNotification(H))a0(H);else if(m.Message.isResponse(H))x0(H);else zJ(H)}function J0(){if(O.size===0)return;let H=O.shift();try{let E=Z?.messageStrategy;if(B5.is(E))E.handleMessage(H,l);else l(H)}finally{z0()}}let P0=(H)=>{try{if(m.Message.isNotification(H)&&H.method===w$.type.method){let E=H.params.id,b=R(E),u=O.get(b);if(m.Message.isRequest(u)){let U0=Z?.connectionStrategy,I0=U0&&U0.cancelUndispatched?U0.cancelUndispatched(u,w):w(u);if(I0&&(I0.error!==void 0||I0.result!==void 0)){O.delete(b),C.delete(E),I0.id=u.id,HJ(I0,H.method,Date.now()),$.write(I0).catch(()=>V.error("Sending response for canceled message failed."));return}}let H0=C.get(E);if(H0!==void 0){H0.cancel(),pJ(H);return}else M.add(E)}I(O,H)}finally{z0()}};function B0(H){if(g())return;function E(Y0,R0,Q0){let L0={jsonrpc:K,id:H.id};if(Y0 instanceof m.ResponseError)L0.error=Y0.toJson();else L0.result=Y0===void 0?null:Y0;HJ(L0,R0,Q0),$.write(L0).catch(()=>V.error("Sending response failed."))}function b(Y0,R0,Q0){let L0={jsonrpc:K,id:H.id,error:Y0.toJson()};HJ(L0,R0,Q0),$.write(L0).catch(()=>V.error("Sending response failed."))}function u(Y0,R0,Q0){if(Y0===void 0)Y0=null;let L0={jsonrpc:K,id:H.id,result:Y0};HJ(L0,R0,Q0),$.write(L0).catch(()=>V.error("Sending response failed."))}cJ(H);let H0=W.get(H.method),U0,I0;if(H0)U0=H0.type,I0=H0.handler;let _0=Date.now();if(I0||G){let Y0=H.id??String(Date.now()),R0=W5.is(t.receiver)?t.receiver.createCancellationTokenSource(Y0):t.receiver.createCancellationTokenSource(H);if(H.id!==null&&M.has(H.id))R0.cancel();if(H.id!==null)C.set(Y0,R0);try{let Q0;if(I0)if(H.params===void 0){if(U0!==void 0&&U0.numberOfParams!==0){b(new m.ResponseError(m.ErrorCodes.InvalidParams,`Request ${H.method} defines ${U0.numberOfParams} params but received none.`),H.method,_0);return}Q0=I0(R0.token)}else if(Array.isArray(H.params)){if(U0!==void 0&&U0.parameterStructures===m.ParameterStructures.byName){b(new m.ResponseError(m.ErrorCodes.InvalidParams,`Request ${H.method} defines parameters by name but received parameters by position`),H.method,_0);return}Q0=I0(...H.params,R0.token)}else{if(U0!==void 0&&U0.parameterStructures===m.ParameterStructures.byPosition){b(new m.ResponseError(m.ErrorCodes.InvalidParams,`Request ${H.method} defines parameters by position but received parameters by name`),H.method,_0);return}Q0=I0(H.params,R0.token)}else if(G)Q0=G(H.method,H.params,R0.token);let L0=Q0;if(!Q0)C.delete(Y0),u(Q0,H.method,_0);else if(L0.then)L0.then((S0)=>{C.delete(Y0),E(S0,H.method,_0)},(S0)=>{if(C.delete(Y0),S0 instanceof m.ResponseError)b(S0,H.method,_0);else if(S0&&O0.string(S0.message))b(new m.ResponseError(m.ErrorCodes.InternalError,`Request ${H.method} failed with message: ${S0.message}`),H.method,_0);else b(new m.ResponseError(m.ErrorCodes.InternalError,`Request ${H.method} failed unexpectedly without providing any details.`),H.method,_0)});else C.delete(Y0),E(Q0,H.method,_0)}catch(Q0){if(C.delete(Y0),Q0 instanceof m.ResponseError)E(Q0,H.method,_0);else if(Q0&&O0.string(Q0.message))b(new m.ResponseError(m.ErrorCodes.InternalError,`Request ${H.method} failed with message: ${Q0.message}`),H.method,_0);else b(new m.ResponseError(m.ErrorCodes.InternalError,`Request ${H.method} failed unexpectedly without providing any details.`),H.method,_0)}}else b(new m.ResponseError(m.ErrorCodes.MethodNotFound,`Unhandled method ${H.method}`),H.method,_0)}function x0(H){if(g())return;if(H.id===null)if(H.error)V.error(`Received response message without id: Error is:
|
|
7
|
+
${JSON.stringify(H.error,void 0,4)}`);else V.error("Received response message without id. No further error information provided.");else{let E=H.id,b=P.get(E);if(_J(H,b),b!==void 0){P.delete(E);try{if(H.error){let u=H.error;b.reject(new m.ResponseError(u.code,u.message,u.data))}else if(H.result!==void 0)b.resolve(H.result);else throw Error("Should never happen.")}catch(u){if(u.message)V.error(`Response handler '${b.method}' failed with message: ${u.message}`);else V.error(`Response handler '${b.method}' failed unexpectedly.`)}}}}function a0(H){if(g())return;let E=void 0,b;if(H.method===w$.type.method){let u=H.params.id;M.delete(u),pJ(H);return}else{let u=A.get(H.method);if(u)b=u.handler,E=u.type}if(b||z)try{if(pJ(H),b)if(H.params===void 0){if(E!==void 0){if(E.numberOfParams!==0&&E.parameterStructures!==m.ParameterStructures.byName)V.error(`Notification ${H.method} defines ${E.numberOfParams} params but received none.`)}b()}else if(Array.isArray(H.params)){let u=H.params;if(H.method===L$.type.method&&u.length===2&&N8.is(u[0]))b({token:u[0],value:u[1]});else{if(E!==void 0){if(E.parameterStructures===m.ParameterStructures.byName)V.error(`Notification ${H.method} defines parameters by name but received parameters by position`);if(E.numberOfParams!==H.params.length)V.error(`Notification ${H.method} defines ${E.numberOfParams} params but received ${u.length} arguments`)}b(...u)}}else{if(E!==void 0&&E.parameterStructures===m.ParameterStructures.byPosition)V.error(`Notification ${H.method} defines parameters by position but received parameters by name`);b(H.params)}else if(z)z(H.method,H.params)}catch(u){if(u.message)V.error(`Notification handler '${H.method}' failed with message: ${u.message}`);else V.error(`Notification handler '${H.method}' failed unexpectedly.`)}else d.fire(H)}function zJ(H){if(!H){V.error("Received empty message.");return}V.error(`Received message which is neither a response nor a notification message:
|
|
8
|
+
${JSON.stringify(H,null,4)}`);let E=H;if(O0.string(E.id)||O0.number(E.id)){let b=E.id,u=P.get(b);if(u)u.reject(Error("The received response has neither a result nor an error property."))}}function w0(H){if(H===void 0||H===null)return;switch(q){case Z0.Verbose:return JSON.stringify(H,null,4);case Z0.Compact:return JSON.stringify(H);default:return}}function A0(H){if(q===Z0.Off||!_)return;if(f===c0.Text){let E=void 0;if((q===Z0.Verbose||q===Z0.Compact)&&H.params)E=`Params: ${w0(H.params)}
|
|
9
|
+
|
|
10
|
+
`;_.log(`Sending request '${H.method} - (${H.id})'.`,E)}else jJ("send-request",H)}function ZJ(H){if(q===Z0.Off||!_)return;if(f===c0.Text){let E=void 0;if(q===Z0.Verbose||q===Z0.Compact)if(H.params)E=`Params: ${w0(H.params)}
|
|
11
|
+
|
|
12
|
+
`;else E=`No parameters provided.
|
|
13
|
+
|
|
14
|
+
`;_.log(`Sending notification '${H.method}'.`,E)}else jJ("send-notification",H)}function HJ(H,E,b){if(q===Z0.Off||!_)return;if(f===c0.Text){let u=void 0;if(q===Z0.Verbose||q===Z0.Compact){if(H.error&&H.error.data)u=`Error data: ${w0(H.error.data)}
|
|
15
|
+
|
|
16
|
+
`;else if(H.result)u=`Result: ${w0(H.result)}
|
|
17
|
+
|
|
18
|
+
`;else if(H.error===void 0)u=`No result returned.
|
|
19
|
+
|
|
20
|
+
`}_.log(`Sending response '${E} - (${H.id})'. Processing request took ${Date.now()-b}ms`,u)}else jJ("send-response",H)}function cJ(H){if(q===Z0.Off||!_)return;if(f===c0.Text){let E=void 0;if((q===Z0.Verbose||q===Z0.Compact)&&H.params)E=`Params: ${w0(H.params)}
|
|
21
|
+
|
|
22
|
+
`;_.log(`Received request '${H.method} - (${H.id})'.`,E)}else jJ("receive-request",H)}function pJ(H){if(q===Z0.Off||!_||H.method===G5.type.method)return;if(f===c0.Text){let E=void 0;if(q===Z0.Verbose||q===Z0.Compact)if(H.params)E=`Params: ${w0(H.params)}
|
|
23
|
+
|
|
24
|
+
`;else E=`No parameters provided.
|
|
25
|
+
|
|
26
|
+
`;_.log(`Received notification '${H.method}'.`,E)}else jJ("receive-notification",H)}function _J(H,E){if(q===Z0.Off||!_)return;if(f===c0.Text){let b=void 0;if(q===Z0.Verbose||q===Z0.Compact){if(H.error&&H.error.data)b=`Error data: ${w0(H.error.data)}
|
|
27
|
+
|
|
28
|
+
`;else if(H.result)b=`Result: ${w0(H.result)}
|
|
29
|
+
|
|
30
|
+
`;else if(H.error===void 0)b=`No result returned.
|
|
31
|
+
|
|
32
|
+
`}if(E){let u=H.error?` Request failed: ${H.error.message} (${H.error.code}).`:"";_.log(`Received response '${E.method} - (${H.id})' in ${Date.now()-E.timerStart}ms.${u}`,b)}else _.log(`Received response ${H.id} without active response promise.`,b)}else jJ("receive-response",H)}function jJ(H,E){if(!_||q===Z0.Off)return;let b={isLSPMessage:!0,type:H,message:E,timestamp:Date.now()};_.log(b)}function N$(){if(S())throw new V$(M$.Closed,"Connection is closed.");if(g())throw new V$(M$.Disposed,"Connection is disposed.")}function m7(){if(v())throw new V$(M$.AlreadyListening,"Connection is already listening")}function n7(){if(!v())throw Error("Call listen() first.")}function A$(H){if(H===void 0)return null;else return H}function V6(H){if(H===null)return;else return H}function X6(H){return H!==void 0&&H!==null&&!Array.isArray(H)&&typeof H==="object"}function S5(H,E){switch(H){case m.ParameterStructures.auto:if(X6(E))return V6(E);else return[A$(E)];case m.ParameterStructures.byName:if(!X6(E))throw Error("Received parameters by name but param is not an object literal.");return V6(E);case m.ParameterStructures.byPosition:return[A$(E)];default:throw Error(`Unknown parameter structure ${H.toString()}`)}}function Q6(H,E){let b,u=H.numberOfParams;switch(u){case 0:b=void 0;break;case 1:b=S5(H.parameterStructures,E[0]);break;default:b=[];for(let H0=0;H0<E.length&&H0<u;H0++)b.push(A$(E[H0]));if(E.length<u)for(let H0=E.length;H0<u;H0++)b.push(null);break}return b}let dJ={sendNotification:(H,...E)=>{N$();let b,u;if(O0.string(H)){b=H;let U0=E[0],I0=0,_0=m.ParameterStructures.auto;if(m.ParameterStructures.is(U0))I0=1,_0=U0;let Y0=E.length,R0=Y0-I0;switch(R0){case 0:u=void 0;break;case 1:u=S5(_0,E[I0]);break;default:if(_0===m.ParameterStructures.byName)throw Error(`Received ${R0} parameters for 'by Name' notification parameter structure.`);u=E.slice(I0,Y0).map((Q0)=>A$(Q0));break}}else{let U0=E;b=H.method,u=Q6(H,U0)}let H0={jsonrpc:K,method:b,params:u};return ZJ(H0),$.write(H0).catch((U0)=>{throw V.error("Sending notification failed."),U0})},onNotification:(H,E)=>{N$();let b;if(O0.func(H))z=H;else if(E)if(O0.string(H))b=H,A.set(H,{type:void 0,handler:E});else b=H.method,A.set(H.method,{type:H,handler:E});return{dispose:()=>{if(b!==void 0)A.delete(b);else z=void 0}}},onProgress:(H,E,b)=>{if(j.has(E))throw Error(`Progress handler for token ${E} already registered`);return j.set(E,b),{dispose:()=>{j.delete(E)}}},sendProgress:(H,E,b)=>{return dJ.sendNotification(L$.type,{token:E,value:b})},onUnhandledProgress:X0.event,sendRequest:(H,...E)=>{N$(),n7();let b,u,H0=void 0;if(O0.string(H)){b=H;let Y0=E[0],R0=E[E.length-1],Q0=0,L0=m.ParameterStructures.auto;if(m.ParameterStructures.is(Y0))Q0=1,L0=Y0;let S0=E.length;if(B8.CancellationToken.is(R0))S0=S0-1,H0=R0;let VJ=S0-Q0;switch(VJ){case 0:u=void 0;break;case 1:u=S5(L0,E[Q0]);break;default:if(L0===m.ParameterStructures.byName)throw Error(`Received ${VJ} parameters for 'by Name' request parameter structure.`);u=E.slice(Q0,S0).map((i7)=>A$(i7));break}}else{let Y0=E;b=H.method,u=Q6(H,Y0);let R0=H.numberOfParams;H0=B8.CancellationToken.is(Y0[R0])?Y0[R0]:void 0}let U0=X++,I0;if(H0)I0=H0.onCancellationRequested(()=>{let Y0=t.sender.sendCancellation(dJ,U0);if(Y0===void 0)return V.log(`Received no promise from cancellation strategy when cancelling id ${U0}`),Promise.resolve();else return Y0.catch(()=>{V.log(`Sending cancellation messages for id ${U0} failed`)})});let _0={jsonrpc:K,id:U0,method:b,params:u};if(A0(_0),typeof t.sender.enableCancellation==="function")t.sender.enableCancellation(_0);return new Promise(async(Y0,R0)=>{let Q0=(VJ)=>{Y0(VJ),t.sender.cleanup(U0),I0?.dispose()},L0=(VJ)=>{R0(VJ),t.sender.cleanup(U0),I0?.dispose()},S0={method:b,timerStart:Date.now(),resolve:Q0,reject:L0};try{P.set(U0,S0),await $.write(_0)}catch(VJ){throw P.delete(U0),S0.reject(new m.ResponseError(m.ErrorCodes.MessageWriteError,VJ.message?VJ.message:"Unknown reason")),V.error("Sending request failed."),VJ}})},onRequest:(H,E)=>{N$();let b=null;if(A8.is(H))b=void 0,G=H;else if(O0.string(H)){if(b=null,E!==void 0)b=H,W.set(H,{handler:E,type:void 0})}else if(E!==void 0)b=H.method,W.set(H.method,{type:H,handler:E});return{dispose:()=>{if(b===null)return;if(b!==void 0)W.delete(b);else G=void 0}}},hasPendingResponse:()=>{return P.size>0},trace:async(H,E,b)=>{let u=!1,H0=c0.Text;if(b!==void 0)if(O0.boolean(b))u=b;else u=b.sendNotification||!1,H0=b.traceFormat||c0.Text;if(q=H,f=H0,q===Z0.Off)_=void 0;else _=E;if(u&&!S()&&!g())await dJ.sendNotification(R8.type,{value:Z0.toString(H)})},onError:k.event,onClose:n.event,onUnhandledNotification:d.event,onDispose:o.event,end:()=>{$.end()},dispose:()=>{if(g())return;y=JJ.Disposed,o.fire(void 0);let H=new m.ResponseError(m.ErrorCodes.PendingResponseRejected,"Pending response rejected since connection got disposed");for(let E of P.values())E.reject(H);if(P=new Map,C=new Map,M=new Set,O=new r9.LinkedMap,O0.func($.dispose))$.dispose();if(O0.func(J.dispose))J.dispose()},listen:()=>{N$(),m7(),y=JJ.Listening,J.listen(P0)},inspect:()=>{(0,a9.default)().console.log("inspect")}};return dJ.onNotification(G5.type,(H)=>{if(q===Z0.Off||!_)return;let E=q===Z0.Verbose||q===Z0.Compact;_.log(H.message,E?H.verbose:void 0)}),dJ.onNotification(L$.type,(H)=>{let E=j.get(H.token);if(E)E(H.value);else X0.fire(H)}),dJ}JY.createMessageConnection=HV});var N5=f0((h)=>{Object.defineProperty(h,"__esModule",{value:!0});h.ProgressType=h.ProgressToken=h.createMessageConnection=h.NullLogger=h.ConnectionOptions=h.ConnectionStrategy=h.AbstractMessageBuffer=h.WriteableStreamMessageWriter=h.AbstractMessageWriter=h.MessageWriter=h.ReadableStreamMessageReader=h.AbstractMessageReader=h.MessageReader=h.SharedArrayReceiverStrategy=h.SharedArraySenderStrategy=h.CancellationToken=h.CancellationTokenSource=h.Emitter=h.Event=h.Disposable=h.LRUCache=h.Touch=h.LinkedMap=h.ParameterStructures=h.NotificationType9=h.NotificationType8=h.NotificationType7=h.NotificationType6=h.NotificationType5=h.NotificationType4=h.NotificationType3=h.NotificationType2=h.NotificationType1=h.NotificationType0=h.NotificationType=h.ErrorCodes=h.ResponseError=h.RequestType9=h.RequestType8=h.RequestType7=h.RequestType6=h.RequestType5=h.RequestType4=h.RequestType3=h.RequestType2=h.RequestType1=h.RequestType0=h.RequestType=h.Message=h.RAL=void 0;h.MessageStrategy=h.CancellationStrategy=h.CancellationSenderStrategy=h.CancellationReceiverStrategy=h.ConnectionError=h.ConnectionErrors=h.LogTraceNotification=h.SetTraceNotification=h.TraceFormat=h.TraceValues=h.Trace=void 0;var W0=$8();Object.defineProperty(h,"Message",{enumerable:!0,get:function(){return W0.Message}});Object.defineProperty(h,"RequestType",{enumerable:!0,get:function(){return W0.RequestType}});Object.defineProperty(h,"RequestType0",{enumerable:!0,get:function(){return W0.RequestType0}});Object.defineProperty(h,"RequestType1",{enumerable:!0,get:function(){return W0.RequestType1}});Object.defineProperty(h,"RequestType2",{enumerable:!0,get:function(){return W0.RequestType2}});Object.defineProperty(h,"RequestType3",{enumerable:!0,get:function(){return W0.RequestType3}});Object.defineProperty(h,"RequestType4",{enumerable:!0,get:function(){return W0.RequestType4}});Object.defineProperty(h,"RequestType5",{enumerable:!0,get:function(){return W0.RequestType5}});Object.defineProperty(h,"RequestType6",{enumerable:!0,get:function(){return W0.RequestType6}});Object.defineProperty(h,"RequestType7",{enumerable:!0,get:function(){return W0.RequestType7}});Object.defineProperty(h,"RequestType8",{enumerable:!0,get:function(){return W0.RequestType8}});Object.defineProperty(h,"RequestType9",{enumerable:!0,get:function(){return W0.RequestType9}});Object.defineProperty(h,"ResponseError",{enumerable:!0,get:function(){return W0.ResponseError}});Object.defineProperty(h,"ErrorCodes",{enumerable:!0,get:function(){return W0.ErrorCodes}});Object.defineProperty(h,"NotificationType",{enumerable:!0,get:function(){return W0.NotificationType}});Object.defineProperty(h,"NotificationType0",{enumerable:!0,get:function(){return W0.NotificationType0}});Object.defineProperty(h,"NotificationType1",{enumerable:!0,get:function(){return W0.NotificationType1}});Object.defineProperty(h,"NotificationType2",{enumerable:!0,get:function(){return W0.NotificationType2}});Object.defineProperty(h,"NotificationType3",{enumerable:!0,get:function(){return W0.NotificationType3}});Object.defineProperty(h,"NotificationType4",{enumerable:!0,get:function(){return W0.NotificationType4}});Object.defineProperty(h,"NotificationType5",{enumerable:!0,get:function(){return W0.NotificationType5}});Object.defineProperty(h,"NotificationType6",{enumerable:!0,get:function(){return W0.NotificationType6}});Object.defineProperty(h,"NotificationType7",{enumerable:!0,get:function(){return W0.NotificationType7}});Object.defineProperty(h,"NotificationType8",{enumerable:!0,get:function(){return W0.NotificationType8}});Object.defineProperty(h,"NotificationType9",{enumerable:!0,get:function(){return W0.NotificationType9}});Object.defineProperty(h,"ParameterStructures",{enumerable:!0,get:function(){return W0.ParameterStructures}});var D8=Z8();Object.defineProperty(h,"LinkedMap",{enumerable:!0,get:function(){return D8.LinkedMap}});Object.defineProperty(h,"LRUCache",{enumerable:!0,get:function(){return D8.LRUCache}});Object.defineProperty(h,"Touch",{enumerable:!0,get:function(){return D8.Touch}});var vV=H9();Object.defineProperty(h,"Disposable",{enumerable:!0,get:function(){return vV.Disposable}});var QY=Y$();Object.defineProperty(h,"Event",{enumerable:!0,get:function(){return QY.Event}});Object.defineProperty(h,"Emitter",{enumerable:!0,get:function(){return QY.Emitter}});var FY=K5();Object.defineProperty(h,"CancellationTokenSource",{enumerable:!0,get:function(){return FY.CancellationTokenSource}});Object.defineProperty(h,"CancellationToken",{enumerable:!0,get:function(){return FY.CancellationToken}});var UY=T9();Object.defineProperty(h,"SharedArraySenderStrategy",{enumerable:!0,get:function(){return UY.SharedArraySenderStrategy}});Object.defineProperty(h,"SharedArrayReceiverStrategy",{enumerable:!0,get:function(){return UY.SharedArrayReceiverStrategy}});var _8=S9();Object.defineProperty(h,"MessageReader",{enumerable:!0,get:function(){return _8.MessageReader}});Object.defineProperty(h,"AbstractMessageReader",{enumerable:!0,get:function(){return _8.AbstractMessageReader}});Object.defineProperty(h,"ReadableStreamMessageReader",{enumerable:!0,get:function(){return _8.ReadableStreamMessageReader}});var q8=d9();Object.defineProperty(h,"MessageWriter",{enumerable:!0,get:function(){return q8.MessageWriter}});Object.defineProperty(h,"AbstractMessageWriter",{enumerable:!0,get:function(){return q8.AbstractMessageWriter}});Object.defineProperty(h,"WriteableStreamMessageWriter",{enumerable:!0,get:function(){return q8.WriteableStreamMessageWriter}});var PV=o9();Object.defineProperty(h,"AbstractMessageBuffer",{enumerable:!0,get:function(){return PV.AbstractMessageBuffer}});var v0=XY();Object.defineProperty(h,"ConnectionStrategy",{enumerable:!0,get:function(){return v0.ConnectionStrategy}});Object.defineProperty(h,"ConnectionOptions",{enumerable:!0,get:function(){return v0.ConnectionOptions}});Object.defineProperty(h,"NullLogger",{enumerable:!0,get:function(){return v0.NullLogger}});Object.defineProperty(h,"createMessageConnection",{enumerable:!0,get:function(){return v0.createMessageConnection}});Object.defineProperty(h,"ProgressToken",{enumerable:!0,get:function(){return v0.ProgressToken}});Object.defineProperty(h,"ProgressType",{enumerable:!0,get:function(){return v0.ProgressType}});Object.defineProperty(h,"Trace",{enumerable:!0,get:function(){return v0.Trace}});Object.defineProperty(h,"TraceValues",{enumerable:!0,get:function(){return v0.TraceValues}});Object.defineProperty(h,"TraceFormat",{enumerable:!0,get:function(){return v0.TraceFormat}});Object.defineProperty(h,"SetTraceNotification",{enumerable:!0,get:function(){return v0.SetTraceNotification}});Object.defineProperty(h,"LogTraceNotification",{enumerable:!0,get:function(){return v0.LogTraceNotification}});Object.defineProperty(h,"ConnectionErrors",{enumerable:!0,get:function(){return v0.ConnectionErrors}});Object.defineProperty(h,"ConnectionError",{enumerable:!0,get:function(){return v0.ConnectionError}});Object.defineProperty(h,"CancellationReceiverStrategy",{enumerable:!0,get:function(){return v0.CancellationReceiverStrategy}});Object.defineProperty(h,"CancellationSenderStrategy",{enumerable:!0,get:function(){return v0.CancellationSenderStrategy}});Object.defineProperty(h,"CancellationStrategy",{enumerable:!0,get:function(){return v0.CancellationStrategy}});Object.defineProperty(h,"MessageStrategy",{enumerable:!0,get:function(){return v0.MessageStrategy}});var CV=vJ();h.RAL=CV.default});var jY=f0((HY)=>{Object.defineProperty(HY,"__esModule",{value:!0});var KY=T$("util"),OJ=N5();class A5 extends OJ.AbstractMessageBuffer{constructor(J="utf-8"){super(J)}emptyBuffer(){return A5.emptyBuffer}fromString(J,$){return Buffer.from(J,$)}toString(J,$){if(J instanceof Buffer)return J.toString($);else return new KY.TextDecoder($).decode(J)}asNative(J,$){if($===void 0)return J instanceof Buffer?J:Buffer.from(J);else return J instanceof Buffer?J.slice(0,$):Buffer.from(J,0,$)}allocNative(J){return Buffer.allocUnsafe(J)}}A5.emptyBuffer=Buffer.allocUnsafe(0);class GY{constructor(J){this.stream=J}onClose(J){return this.stream.on("close",J),OJ.Disposable.create(()=>this.stream.off("close",J))}onError(J){return this.stream.on("error",J),OJ.Disposable.create(()=>this.stream.off("error",J))}onEnd(J){return this.stream.on("end",J),OJ.Disposable.create(()=>this.stream.off("end",J))}onData(J){return this.stream.on("data",J),OJ.Disposable.create(()=>this.stream.off("data",J))}}class WY{constructor(J){this.stream=J}onClose(J){return this.stream.on("close",J),OJ.Disposable.create(()=>this.stream.off("close",J))}onError(J){return this.stream.on("error",J),OJ.Disposable.create(()=>this.stream.off("error",J))}onEnd(J){return this.stream.on("end",J),OJ.Disposable.create(()=>this.stream.off("end",J))}write(J,$){return new Promise((Y,Z)=>{let V=(X)=>{if(X===void 0||X===null)Y();else Z(X)};if(typeof J==="string")this.stream.write(J,$,V);else this.stream.write(J,V)})}end(){this.stream.end()}}var zY=Object.freeze({messageBuffer:Object.freeze({create:(J)=>new A5(J)}),applicationJson:Object.freeze({encoder:Object.freeze({name:"application/json",encode:(J,$)=>{try{return Promise.resolve(Buffer.from(JSON.stringify(J,void 0,0),$.charset))}catch(Y){return Promise.reject(Y)}}}),decoder:Object.freeze({name:"application/json",decode:(J,$)=>{try{if(J instanceof Buffer)return Promise.resolve(JSON.parse(J.toString($.charset)));else return Promise.resolve(JSON.parse(new KY.TextDecoder($.charset).decode(J)))}catch(Y){return Promise.reject(Y)}}})}),stream:Object.freeze({asReadableStream:(J)=>new GY(J),asWritableStream:(J)=>new WY(J)}),console,timer:Object.freeze({setTimeout(J,$,...Y){let Z=setTimeout(J,$,...Y);return{dispose:()=>clearTimeout(Z)}},setImmediate(J,...$){let Y=setImmediate(J,...$);return{dispose:()=>clearImmediate(Y)}},setInterval(J,$,...Y){let Z=setInterval(J,$,...Y);return{dispose:()=>clearInterval(Z)}}})});function E8(){return zY}(function(J){function $(){OJ.RAL.install(zY)}J.install=$})(E8||(E8={}));HY.default=E8});var DY=f0(($0)=>{var SV=$0&&$0.__createBinding||(Object.create?function(J,$,Y,Z){if(Z===void 0)Z=Y;var V=Object.getOwnPropertyDescriptor($,Y);if(!V||("get"in V?!$.__esModule:V.writable||V.configurable))V={enumerable:!0,get:function(){return $[Y]}};Object.defineProperty(J,Z,V)}:function(J,$,Y,Z){if(Z===void 0)Z=Y;J[Z]=$[Y]}),gV=$0&&$0.__exportStar||function(J,$){for(var Y in J)if(Y!=="default"&&!Object.prototype.hasOwnProperty.call($,Y))SV($,J,Y)};Object.defineProperty($0,"__esModule",{value:!0});$0.createMessageConnection=$0.createServerSocketTransport=$0.createClientSocketTransport=$0.createServerPipeTransport=$0.createClientPipeTransport=$0.generateRandomPipeName=$0.StreamMessageWriter=$0.StreamMessageReader=$0.SocketMessageWriter=$0.SocketMessageReader=$0.PortMessageWriter=$0.PortMessageReader=$0.IPCMessageWriter=$0.IPCMessageReader=void 0;var X$=jY();X$.default.install();var BY=T$("path"),hV=T$("os"),uV=T$("crypto"),R5=T$("net"),p0=N5();gV(N5(),$0);class AY extends p0.AbstractMessageReader{constructor(J){super();this.process=J;let $=this.process;$.on("error",(Y)=>this.fireError(Y)),$.on("close",()=>this.fireClose())}listen(J){return this.process.on("message",J),p0.Disposable.create(()=>this.process.off("message",J))}}$0.IPCMessageReader=AY;class RY extends p0.AbstractMessageWriter{constructor(J){super();this.process=J,this.errorCount=0;let $=this.process;$.on("error",(Y)=>this.fireError(Y)),$.on("close",()=>this.fireClose)}write(J){try{if(typeof this.process.send==="function")this.process.send(J,void 0,void 0,($)=>{if($)this.errorCount++,this.handleError($,J);else this.errorCount=0});return Promise.resolve()}catch($){return this.handleError($,J),Promise.reject($)}}handleError(J,$){this.errorCount++,this.fireError(J,$,this.errorCount)}end(){}}$0.IPCMessageWriter=RY;class OY extends p0.AbstractMessageReader{constructor(J){super();this.onData=new p0.Emitter,J.on("close",()=>this.fireClose),J.on("error",($)=>this.fireError($)),J.on("message",($)=>{this.onData.fire($)})}listen(J){return this.onData.event(J)}}$0.PortMessageReader=OY;class IY extends p0.AbstractMessageWriter{constructor(J){super();this.port=J,this.errorCount=0,J.on("close",()=>this.fireClose()),J.on("error",($)=>this.fireError($))}write(J){try{return this.port.postMessage(J),Promise.resolve()}catch($){return this.handleError($,J),Promise.reject($)}}handleError(J,$){this.errorCount++,this.fireError(J,$,this.errorCount)}end(){}}$0.PortMessageWriter=IY;class Q$ extends p0.ReadableStreamMessageReader{constructor(J,$="utf-8"){super((0,X$.default)().stream.asReadableStream(J),$)}}$0.SocketMessageReader=Q$;class F$ extends p0.WriteableStreamMessageWriter{constructor(J,$){super((0,X$.default)().stream.asWritableStream(J),$);this.socket=J}dispose(){super.dispose(),this.socket.destroy()}}$0.SocketMessageWriter=F$;class L8 extends p0.ReadableStreamMessageReader{constructor(J,$){super((0,X$.default)().stream.asReadableStream(J),$)}}$0.StreamMessageReader=L8;class M8 extends p0.WriteableStreamMessageWriter{constructor(J,$){super((0,X$.default)().stream.asWritableStream(J),$)}}$0.StreamMessageWriter=M8;var NY=process.env.XDG_RUNTIME_DIR,lV=new Map([["linux",107],["darwin",103]]);function xV(){let J=(0,uV.randomBytes)(21).toString("hex");if(process.platform==="win32")return`\\\\.\\pipe\\vscode-jsonrpc-${J}-sock`;let $;if(NY)$=BY.join(NY,`vscode-ipc-${J}.sock`);else $=BY.join(hV.tmpdir(),`vscode-${J}.sock`);let Y=lV.get(process.platform);if(Y!==void 0&&$.length>Y)(0,X$.default)().console.warn(`WARNING: IPC handle "${$}" is longer than ${Y} characters.`);return $}$0.generateRandomPipeName=xV;function cV(J,$="utf-8"){let Y,Z=new Promise((V,X)=>{Y=V});return new Promise((V,X)=>{let U=(0,R5.createServer)((F)=>{U.close(),Y([new Q$(F,$),new F$(F,$)])});U.on("error",X),U.listen(J,()=>{U.removeListener("error",X),V({onConnected:()=>{return Z}})})})}$0.createClientPipeTransport=cV;function pV(J,$="utf-8"){let Y=(0,R5.createConnection)(J);return[new Q$(Y,$),new F$(Y,$)]}$0.createServerPipeTransport=pV;function dV(J,$="utf-8"){let Y,Z=new Promise((V,X)=>{Y=V});return new Promise((V,X)=>{let U=(0,R5.createServer)((F)=>{U.close(),Y([new Q$(F,$),new F$(F,$)])});U.on("error",X),U.listen(J,"127.0.0.1",()=>{U.removeListener("error",X),V({onConnected:()=>{return Z}})})})}$0.createClientSocketTransport=dV;function mV(J,$="utf-8"){let Y=(0,R5.createConnection)(J,"127.0.0.1");return[new Q$(Y,$),new F$(Y,$)]}$0.createServerSocketTransport=mV;function nV(J){let $=J;return $.read!==void 0&&$.addListener!==void 0}function iV(J){let $=J;return $.write!==void 0&&$.addListener!==void 0}function oV(J,$,Y,Z){if(!Y)Y=p0.NullLogger;let V=nV(J)?new L8(J):J,X=iV($)?new M8($):$;if(p0.ConnectionStrategy.is(Z))Z={connectionStrategy:Z};return(0,p0.createMessageConnection)(V,X,Y,Z)}$0.createMessageConnection=oV});var Z6={};QJ(Z6,{use:()=>EQ,toRow:()=>ZQ,plan:()=>_Q,listGlobal:()=>TQ,layer:()=>d7,isDefaultTitle:()=>YQ,getUsage:()=>qQ,fromRow:()=>p$,defaultLayer:()=>LQ,SetTitleInput:()=>HQ,SetRevertInput:()=>NQ,SetPermissionInput:()=>BQ,SetArchivedInput:()=>jQ,Session:()=>Z6,Service:()=>d$,RemoveInput:()=>zQ,ProjectInfo:()=>c7,MessagesInput:()=>AQ,Info:()=>Y6,GlobalInfo:()=>FQ,GetInput:()=>GQ,ForkInput:()=>KQ,Event:()=>l$,CreateInput:()=>UQ,ChildrenInput:()=>WQ,BusyError:()=>p7,ArchivedTimestamp:()=>y5});import x$ from"path";var nJ={};QJ(nJ,{layer:()=>U6,defaultLayer:()=>a7,Service:()=>n$,BackgroundJob:()=>nJ});class n$ extends n0.Service()("@muxcode/BackgroundJob"){}function XJ(J){return{...J.info,...J.info.metadata?{metadata:{...J.info.metadata}}:{}}}function o7(J){if(J instanceof Error)return J.message;return String(J)}var U6=j0.effect(n$,B.gen(function*(){let J=yield*s.make(B.fn("BackgroundJob.state")(function*(){return{jobs:yield*qJ.make(new Map),scope:yield*F6.Scope}})),$=B.fn("BackgroundJob.finish")(function*(F,K,G){let W=yield*g5.currentTimeMillis,z=yield*qJ.modify((yield*s.get(J)).jobs,(A)=>{let j=A.get(F);if(!j)return[{},A];if(j.info.status!=="running")return[{info:XJ(j)},A];let D={...j,fiber:void 0,info:{...j.info,status:K,completed_at:W,...G?.output!==void 0?{output:G.output}:{},...G?.error!==void 0?{error:G.error}:{}}};return[{info:XJ(D),done:j.done},new Map(A).set(F,D)]});if(z.info&&z.done)yield*R$.succeed(z.done,z.info).pipe(B.ignore);return z.info}),Y=B.fn("BackgroundJob.list")(function*(){return Array.from((yield*qJ.get((yield*s.get(J)).jobs)).values()).map(XJ).toSorted((F,K)=>F.started_at-K.started_at)}),Z=B.fn("BackgroundJob.get")(function*(F){let K=(yield*qJ.get((yield*s.get(J)).jobs)).get(F);if(!K)return;return XJ(K)}),V=B.fn("BackgroundJob.start")(function*(F){return yield*B.uninterruptibleMask((K)=>B.gen(function*(){let G=yield*s.get(J),W=F.id??mJ.ascending("job"),z=yield*g5.currentTimeMillis,A=yield*R$.make();return yield*qJ.modifyEffect(G.jobs,B.fnUntraced(function*(j){let D=j.get(W);if(D?.info.status==="running")return[XJ(D),j];let O=yield*K(F.run).pipe(B.matchCauseEffect({onSuccess:(M)=>$(W,"completed",{output:M}),onFailure:(M)=>$(W,O$.hasInterruptsOnly(M)?"cancelled":"error",{error:o7(O$.squash(M))})}),B.asVoid,B.forkIn(G.scope,{startImmediately:!0})),P={info:{id:W,type:F.type,title:F.title,status:"running",started_at:z,metadata:F.metadata},done:A,fiber:O};return[XJ(P),new Map(j).set(W,P)]}))}))}),X=B.fn("BackgroundJob.wait")(function*(F){let K=(yield*qJ.get((yield*s.get(J)).jobs)).get(F.id);if(!K)return{timedOut:!1};if(K.info.status!=="running")return{info:XJ(K),timedOut:!1};if(F.timeout===void 0)return{info:yield*R$.await(K.done),timedOut:!1};if(F.timeout<=0)return{info:XJ(K),timedOut:!0};let G=yield*R$.await(K.done).pipe(B.timeoutOption(F.timeout));if(G._tag==="Some")return{info:G.value,timedOut:!1};return{info:XJ(K),timedOut:!0}}),U=B.fn("BackgroundJob.cancel")(function*(F){let K=(yield*qJ.get((yield*s.get(J)).jobs)).get(F);if(!K)return;if(K.info.status!=="running")return XJ(K);if(K.fiber)yield*h5.interrupt(K.fiber).pipe(B.ignore),yield*h5.await(K.fiber).pipe(B.ignore);return yield*$(F,"cancelled")});return n$.of({list:Y,get:Z,start:V,wait:X,cancel:U})})),a7=U6;/*!
|
|
33
|
+
* decimal.js v10.5.0
|
|
34
|
+
* An arbitrary-precision Decimal type for JavaScript.
|
|
35
|
+
* https://github.com/MikeMcl/decimal.js
|
|
36
|
+
* Copyright (c) 2025 Michael Mclaughlin <M8ch88l@gmail.com>
|
|
37
|
+
* MIT Licence
|
|
38
|
+
*/var iJ=9000000000000000,wJ=1e9,u5="0123456789abcdef",a$="2.3025850929940456840179914546843642076011014886287729760333279009675726096773524802359972050895982983419677840422862486334095254650828067566662873690987816894829072083255546808437998948262331985283935053089653777326288461633662222876982198867465436674744042432743651550489343149393914796194044002221051017141748003688084012647080685567743216228355220114804663715659121373450747856947683463616792101806445070648000277502684916746550586856935673420670581136429224554405758925724208241314695689016758940256776311356919292033376587141660230105703089634572075440370847469940168269282808481184289314848524948644871927809676271275775397027668605952496716674183485704422507197965004714951050492214776567636938662976979522110718264549734772662425709429322582798502585509785265383207606726317164309505995087807523710333101197857547331541421808427543863591778117054309827482385045648019095610299291824318237525357709750539565187697510374970888692180205189339507238539205144634197265287286965110862571492198849978748873771345686209167058",r$="3.1415926535897932384626433832795028841971693993751058209749445923078164062862089986280348253421170679821480865132823066470938446095505822317253594081284811174502841027019385211055596446229489549303819644288109756659334461284756482337867831652712019091456485669234603486104543266482133936072602491412737245870066063155881748815209209628292540917153643678925903600113305305488204665213841469519415116094330572703657595919530921861173819326117931051185480744623799627495673518857527248912279381830119491298336733624406566430860213949463952247371907021798609437027705392171762931767523846748184676694051320005681271452635608277857713427577896091736371787214684409012249534301465495853710507922796892589235420199561121290219608640344181598136297747713099605187072113499999983729780499510597317328160963185950244594553469083026425223082533446850352619311881710100031378387528865875332083814206171776691473035982534904287554687311595628638823537875937519577818577805321712268066130019278766111959092164201989380952572010654858632789",l5={precision:20,rounding:4,modulo:1,toExpNeg:-7,toExpPos:21,minE:-iJ,maxE:iJ,crypto:!1},z6,BJ,i=!0,t$="[DecimalError] ",MJ=t$+"Invalid argument: ",H6=t$+"Precision limit exceeded",j6=t$+"crypto unavailable",B6="[object Decimal]",C0=Math.floor,M0=Math.pow,r7=/^0b([01]+(\.[01]*)?|\.[01]+)(p[+-]?\d+)?$/i,s7=/^0x([0-9a-f]+(\.[0-9a-f]*)?|\.[0-9a-f]+)(p[+-]?\d+)?$/i,t7=/^0o([0-7]+(\.[0-7]*)?|\.[0-7]+)(p[+-]?\d+)?$/i,N6=/^(\d+(\.\d*)?|\.\d+)(e[+-]?\d+)?$/i,r0=1e7,p=7,e7=9007199254740991,J4=a$.length-1,x5=r$.length-1,L={toStringTag:B6};L.absoluteValue=L.abs=function(){var J=new this.constructor(this);if(J.s<0)J.s=1;return x(J)};L.ceil=function(){return x(new this.constructor(this),this.e+1,2)};L.clampedTo=L.clamp=function(J,$){var Y,Z=this,V=Z.constructor;if(J=new V(J),$=new V($),!J.s||!$.s)return new V(NaN);if(J.gt($))throw Error(MJ+$);return Y=Z.cmp(J),Y<0?J:Z.cmp($)>0?$:new V(Z)};L.comparedTo=L.cmp=function(J){var $,Y,Z,V,X=this,U=X.d,F=(J=new X.constructor(J)).d,K=X.s,G=J.s;if(!U||!F)return!K||!G?NaN:K!==G?K:U===F?0:!U^K<0?1:-1;if(!U[0]||!F[0])return U[0]?K:F[0]?-G:0;if(K!==G)return K;if(X.e!==J.e)return X.e>J.e^K<0?1:-1;Z=U.length,V=F.length;for($=0,Y=Z<V?Z:V;$<Y;++$)if(U[$]!==F[$])return U[$]>F[$]^K<0?1:-1;return Z===V?0:Z>V^K<0?1:-1};L.cosine=L.cos=function(){var J,$,Y=this,Z=Y.constructor;if(!Y.d)return new Z(NaN);if(!Y.d[0])return new Z(1);return J=Z.precision,$=Z.rounding,Z.precision=J+Math.max(Y.e,Y.sd())+p,Z.rounding=1,Y=$4(Z,D6(Z,Y)),Z.precision=J,Z.rounding=$,x(BJ==2||BJ==3?Y.neg():Y,J,$,!0)};L.cubeRoot=L.cbrt=function(){var J,$,Y,Z,V,X,U,F,K,G,W=this,z=W.constructor;if(!W.isFinite()||W.isZero())return new z(W);if(i=!1,X=W.s*M0(W.s*W,0.3333333333333333),!X||Math.abs(X)==1/0){if(Y=T0(W.d),J=W.e,X=(J-Y.length+1)%3)Y+=X==1||X==-2?"0":"00";if(X=M0(Y,0.3333333333333333),J=C0((J+1)/3)-(J%3==(J<0?-1:2)),X==1/0)Y="5e"+J;else Y=X.toExponential(),Y=Y.slice(0,Y.indexOf("e")+1)+J;Z=new z(Y),Z.s=W.s}else Z=new z(X.toString());U=(J=z.precision)+3;for(;;)if(F=Z,K=F.times(F).times(F),G=K.plus(W),Z=K0(G.plus(W).times(F),G.plus(K),U+2,1),T0(F.d).slice(0,U)===(Y=T0(Z.d)).slice(0,U))if(Y=Y.slice(U-3,U+1),Y=="9999"||!V&&Y=="4999"){if(!V){if(x(F,J+1,0),F.times(F).times(F).eq(W)){Z=F;break}}U+=4,V=1}else{if(!+Y||!+Y.slice(1)&&Y.charAt(0)=="5")x(Z,J+1,1),$=!Z.times(Z).times(Z).eq(W);break}return i=!0,x(Z,J,z.rounding,$)};L.decimalPlaces=L.dp=function(){var J,$=this.d,Y=NaN;if($){if(J=$.length-1,Y=(J-C0(this.e/p))*p,J=$[J],J)for(;J%10==0;J/=10)Y--;if(Y<0)Y=0}return Y};L.dividedBy=L.div=function(J){return K0(this,new this.constructor(J))};L.dividedToIntegerBy=L.divToInt=function(J){var $=this,Y=$.constructor;return x(K0($,new Y(J),0,1,1),Y.precision,Y.rounding)};L.equals=L.eq=function(J){return this.cmp(J)===0};L.floor=function(){return x(new this.constructor(this),this.e+1,3)};L.greaterThan=L.gt=function(J){return this.cmp(J)>0};L.greaterThanOrEqualTo=L.gte=function(J){var $=this.cmp(J);return $==1||$===0};L.hyperbolicCosine=L.cosh=function(){var J,$,Y,Z,V,X=this,U=X.constructor,F=new U(1);if(!X.isFinite())return new U(X.s?1/0:NaN);if(X.isZero())return F;if(Y=U.precision,Z=U.rounding,U.precision=Y+Math.max(X.e,X.sd())+4,U.rounding=1,V=X.d.length,V<32)J=Math.ceil(V/3),$=(1/J5(4,J)).toString();else J=16,$="2.3283064365386962890625e-10";X=oJ(U,1,X.times($),new U(1),!0);var K,G=J,W=new U(8);for(;G--;)K=X.times(X),X=F.minus(K.times(W.minus(K.times(W))));return x(X,U.precision=Y,U.rounding=Z,!0)};L.hyperbolicSine=L.sinh=function(){var J,$,Y,Z,V=this,X=V.constructor;if(!V.isFinite()||V.isZero())return new X(V);if($=X.precision,Y=X.rounding,X.precision=$+Math.max(V.e,V.sd())+4,X.rounding=1,Z=V.d.length,Z<3)V=oJ(X,2,V,V,!0);else{J=1.4*Math.sqrt(Z),J=J>16?16:J|0,V=V.times(1/J5(5,J)),V=oJ(X,2,V,V,!0);var U,F=new X(5),K=new X(16),G=new X(20);for(;J--;)U=V.times(V),V=V.times(F.plus(U.times(K.times(U).plus(G))))}return X.precision=$,X.rounding=Y,x(V,$,Y,!0)};L.hyperbolicTangent=L.tanh=function(){var J,$,Y=this,Z=Y.constructor;if(!Y.isFinite())return new Z(Y.s);if(Y.isZero())return new Z(Y);return J=Z.precision,$=Z.rounding,Z.precision=J+7,Z.rounding=1,K0(Y.sinh(),Y.cosh(),Z.precision=J,Z.rounding=$)};L.inverseCosine=L.acos=function(){var J=this,$=J.constructor,Y=J.abs().cmp(1),Z=$.precision,V=$.rounding;if(Y!==-1)return Y===0?J.isNeg()?FJ($,Z,V):new $(0):new $(NaN);if(J.isZero())return FJ($,Z+4,V).times(0.5);return $.precision=Z+6,$.rounding=1,J=new $(1).minus(J).div(J.plus(1)).sqrt().atan(),$.precision=Z,$.rounding=V,J.times(2)};L.inverseHyperbolicCosine=L.acosh=function(){var J,$,Y=this,Z=Y.constructor;if(Y.lte(1))return new Z(Y.eq(1)?0:NaN);if(!Y.isFinite())return new Z(Y);return J=Z.precision,$=Z.rounding,Z.precision=J+Math.max(Math.abs(Y.e),Y.sd())+4,Z.rounding=1,i=!1,Y=Y.times(Y).minus(1).sqrt().plus(Y),i=!0,Z.precision=J,Z.rounding=$,Y.ln()};L.inverseHyperbolicSine=L.asinh=function(){var J,$,Y=this,Z=Y.constructor;if(!Y.isFinite()||Y.isZero())return new Z(Y);return J=Z.precision,$=Z.rounding,Z.precision=J+2*Math.max(Math.abs(Y.e),Y.sd())+6,Z.rounding=1,i=!1,Y=Y.times(Y).plus(1).sqrt().plus(Y),i=!0,Z.precision=J,Z.rounding=$,Y.ln()};L.inverseHyperbolicTangent=L.atanh=function(){var J,$,Y,Z,V=this,X=V.constructor;if(!V.isFinite())return new X(NaN);if(V.e>=0)return new X(V.abs().eq(1)?V.s/0:V.isZero()?V:NaN);if(J=X.precision,$=X.rounding,Z=V.sd(),Math.max(Z,J)<2*-V.e-1)return x(new X(V),J,$,!0);return X.precision=Y=Z-V.e,V=K0(V.plus(1),new X(1).minus(V),Y+J,1),X.precision=J+4,X.rounding=1,V=V.ln(),X.precision=J,X.rounding=$,V.times(0.5)};L.inverseSine=L.asin=function(){var J,$,Y,Z,V=this,X=V.constructor;if(V.isZero())return new X(V);if($=V.abs().cmp(1),Y=X.precision,Z=X.rounding,$!==-1){if($===0)return J=FJ(X,Y+4,Z).times(0.5),J.s=V.s,J;return new X(NaN)}return X.precision=Y+6,X.rounding=1,V=V.div(new X(1).minus(V.times(V)).sqrt().plus(1)).atan(),X.precision=Y,X.rounding=Z,V.times(2)};L.inverseTangent=L.atan=function(){var J,$,Y,Z,V,X,U,F,K,G=this,W=G.constructor,z=W.precision,A=W.rounding;if(!G.isFinite()){if(!G.s)return new W(NaN);if(z+4<=x5)return U=FJ(W,z+4,A).times(0.5),U.s=G.s,U}else if(G.isZero())return new W(G);else if(G.abs().eq(1)&&z+4<=x5)return U=FJ(W,z+4,A).times(0.25),U.s=G.s,U;W.precision=F=z+10,W.rounding=1,Y=Math.min(28,F/p+2|0);for(J=Y;J;--J)G=G.div(G.times(G).plus(1).sqrt().plus(1));i=!1,$=Math.ceil(F/p),Z=1,K=G.times(G),U=new W(G),V=G;for(;J!==-1;)if(V=V.times(K),X=U.minus(V.div(Z+=2)),V=V.times(K),U=X.plus(V.div(Z+=2)),U.d[$]!==void 0)for(J=$;U.d[J]===X.d[J]&&J--;);if(Y)U=U.times(2<<Y-1);return i=!0,x(U,W.precision=z,W.rounding=A,!0)};L.isFinite=function(){return!!this.d};L.isInteger=L.isInt=function(){return!!this.d&&C0(this.e/p)>this.d.length-2};L.isNaN=function(){return!this.s};L.isNegative=L.isNeg=function(){return this.s<0};L.isPositive=L.isPos=function(){return this.s>0};L.isZero=function(){return!!this.d&&this.d[0]===0};L.lessThan=L.lt=function(J){return this.cmp(J)<0};L.lessThanOrEqualTo=L.lte=function(J){return this.cmp(J)<1};L.logarithm=L.log=function(J){var $,Y,Z,V,X,U,F,K,G=this,W=G.constructor,z=W.precision,A=W.rounding,j=5;if(J==null)J=new W(10),$=!0;else{if(J=new W(J),Y=J.d,J.s<0||!Y||!Y[0]||J.eq(1))return new W(NaN);$=J.eq(10)}if(Y=G.d,G.s<0||!Y||!Y[0]||G.eq(1))return new W(Y&&!Y[0]?-1/0:G.s!=1?NaN:Y?0:1/0);if($)if(Y.length>1)X=!0;else{for(V=Y[0];V%10===0;)V/=10;X=V!==1}if(i=!1,F=z+j,U=LJ(G,F),Z=$?s$(W,F+10):LJ(J,F),K=K0(U,Z,F,1),I$(K.d,V=z,A))do if(F+=10,U=LJ(G,F),Z=$?s$(W,F+10):LJ(J,F),K=K0(U,Z,F,1),!X){if(+T0(K.d).slice(V+1,V+15)+1==100000000000000)K=x(K,z+1,0);break}while(I$(K.d,V+=10,A));return i=!0,x(K,z,A)};L.minus=L.sub=function(J){var $,Y,Z,V,X,U,F,K,G,W,z,A,j=this,D=j.constructor;if(J=new D(J),!j.d||!J.d){if(!j.s||!J.s)J=new D(NaN);else if(j.d)J.s=-J.s;else J=new D(J.d||j.s!==J.s?j:NaN);return J}if(j.s!=J.s)return J.s=-J.s,j.plus(J);if(G=j.d,A=J.d,F=D.precision,K=D.rounding,!G[0]||!A[0]){if(A[0])J.s=-J.s;else if(G[0])J=new D(j);else return new D(K===3?-0:0);return i?x(J,F,K):J}if(Y=C0(J.e/p),W=C0(j.e/p),G=G.slice(),X=W-Y,X){if(z=X<0,z)$=G,X=-X,U=A.length;else $=A,Y=W,U=G.length;if(Z=Math.max(Math.ceil(F/p),U)+2,X>Z)X=Z,$.length=1;$.reverse();for(Z=X;Z--;)$.push(0);$.reverse()}else{if(Z=G.length,U=A.length,z=Z<U,z)U=Z;for(Z=0;Z<U;Z++)if(G[Z]!=A[Z]){z=G[Z]<A[Z];break}X=0}if(z)$=G,G=A,A=$,J.s=-J.s;U=G.length;for(Z=A.length-U;Z>0;--Z)G[U++]=0;for(Z=A.length;Z>X;){if(G[--Z]<A[Z]){for(V=Z;V&&G[--V]===0;)G[V]=r0-1;--G[V],G[Z]+=r0}G[Z]-=A[Z]}for(;G[--U]===0;)G.pop();for(;G[0]===0;G.shift())--Y;if(!G[0])return new D(K===3?-0:0);return J.d=G,J.e=e$(G,Y),i?x(J,F,K):J};L.modulo=L.mod=function(J){var $,Y=this,Z=Y.constructor;if(J=new Z(J),!Y.d||!J.s||J.d&&!J.d[0])return new Z(NaN);if(!J.d||Y.d&&!Y.d[0])return x(new Z(Y),Z.precision,Z.rounding);if(i=!1,Z.modulo==9)$=K0(Y,J.abs(),0,3,1),$.s*=J.s;else $=K0(Y,J,0,Z.modulo,1);return $=$.times(J),i=!0,Y.minus($)};L.naturalExponential=L.exp=function(){return c5(this)};L.naturalLogarithm=L.ln=function(){return LJ(this)};L.negated=L.neg=function(){var J=new this.constructor(this);return J.s=-J.s,x(J)};L.plus=L.add=function(J){var $,Y,Z,V,X,U,F,K,G,W,z=this,A=z.constructor;if(J=new A(J),!z.d||!J.d){if(!z.s||!J.s)J=new A(NaN);else if(!z.d)J=new A(J.d||z.s===J.s?z:NaN);return J}if(z.s!=J.s)return J.s=-J.s,z.minus(J);if(G=z.d,W=J.d,F=A.precision,K=A.rounding,!G[0]||!W[0]){if(!W[0])J=new A(z);return i?x(J,F,K):J}if(X=C0(z.e/p),Z=C0(J.e/p),G=G.slice(),V=X-Z,V){if(V<0)Y=G,V=-V,U=W.length;else Y=W,Z=X,U=G.length;if(X=Math.ceil(F/p),U=X>U?X+1:U+1,V>U)V=U,Y.length=1;Y.reverse();for(;V--;)Y.push(0);Y.reverse()}if(U=G.length,V=W.length,U-V<0)V=U,Y=W,W=G,G=Y;for($=0;V;)$=(G[--V]=G[V]+W[V]+$)/r0|0,G[V]%=r0;if($)G.unshift($),++Z;for(U=G.length;G[--U]==0;)G.pop();return J.d=G,J.e=e$(G,Z),i?x(J,F,K):J};L.precision=L.sd=function(J){var $,Y=this;if(J!==void 0&&J!==!!J&&J!==1&&J!==0)throw Error(MJ+J);if(Y.d){if($=A6(Y.d),J&&Y.e+1>$)$=Y.e+1}else $=NaN;return $};L.round=function(){var J=this,$=J.constructor;return x(new $(J),J.e+1,$.rounding)};L.sine=L.sin=function(){var J,$,Y=this,Z=Y.constructor;if(!Y.isFinite())return new Z(NaN);if(Y.isZero())return new Z(Y);return J=Z.precision,$=Z.rounding,Z.precision=J+Math.max(Y.e,Y.sd())+p,Z.rounding=1,Y=Z4(Z,D6(Z,Y)),Z.precision=J,Z.rounding=$,x(BJ>2?Y.neg():Y,J,$,!0)};L.squareRoot=L.sqrt=function(){var J,$,Y,Z,V,X,U=this,F=U.d,K=U.e,G=U.s,W=U.constructor;if(G!==1||!F||!F[0])return new W(!G||G<0&&(!F||F[0])?NaN:F?U:1/0);if(i=!1,G=Math.sqrt(+U),G==0||G==1/0){if($=T0(F),($.length+K)%2==0)$+="0";if(G=Math.sqrt($),K=C0((K+1)/2)-(K<0||K%2),G==1/0)$="5e"+K;else $=G.toExponential(),$=$.slice(0,$.indexOf("e")+1)+K;Z=new W($)}else Z=new W(G.toString());Y=(K=W.precision)+3;for(;;)if(X=Z,Z=X.plus(K0(U,X,Y+2,1)).times(0.5),T0(X.d).slice(0,Y)===($=T0(Z.d)).slice(0,Y))if($=$.slice(Y-3,Y+1),$=="9999"||!V&&$=="4999"){if(!V){if(x(X,K+1,0),X.times(X).eq(U)){Z=X;break}}Y+=4,V=1}else{if(!+$||!+$.slice(1)&&$.charAt(0)=="5")x(Z,K+1,1),J=!Z.times(Z).eq(U);break}return i=!0,x(Z,K,W.rounding,J)};L.tangent=L.tan=function(){var J,$,Y=this,Z=Y.constructor;if(!Y.isFinite())return new Z(NaN);if(Y.isZero())return new Z(Y);return J=Z.precision,$=Z.rounding,Z.precision=J+10,Z.rounding=1,Y=Y.sin(),Y.s=1,Y=K0(Y,new Z(1).minus(Y.times(Y)).sqrt(),J+10,0),Z.precision=J,Z.rounding=$,x(BJ==2||BJ==4?Y.neg():Y,J,$,!0)};L.times=L.mul=function(J){var $,Y,Z,V,X,U,F,K,G,W=this,z=W.constructor,A=W.d,j=(J=new z(J)).d;if(J.s*=W.s,!A||!A[0]||!j||!j[0])return new z(!J.s||A&&!A[0]&&!j||j&&!j[0]&&!A?NaN:!A||!j?J.s/0:J.s*0);if(Y=C0(W.e/p)+C0(J.e/p),K=A.length,G=j.length,K<G)X=A,A=j,j=X,U=K,K=G,G=U;X=[],U=K+G;for(Z=U;Z--;)X.push(0);for(Z=G;--Z>=0;){$=0;for(V=K+Z;V>Z;)F=X[V]+j[Z]*A[V-Z-1]+$,X[V--]=F%r0|0,$=F/r0|0;X[V]=(X[V]+$)%r0|0}for(;!X[--U];)X.pop();if($)++Y;else X.shift();return J.d=X,J.e=e$(X,Y),i?x(J,z.precision,z.rounding):J};L.toBinary=function(J,$){return p5(this,2,J,$)};L.toDecimalPlaces=L.toDP=function(J,$){var Y=this,Z=Y.constructor;if(Y=new Z(Y),J===void 0)return Y;if(h0(J,0,wJ),$===void 0)$=Z.rounding;else h0($,0,8);return x(Y,J+Y.e+1,$)};L.toExponential=function(J,$){var Y,Z=this,V=Z.constructor;if(J===void 0)Y=UJ(Z,!0);else{if(h0(J,0,wJ),$===void 0)$=V.rounding;else h0($,0,8);Z=x(new V(Z),J+1,$),Y=UJ(Z,!0,J+1)}return Z.isNeg()&&!Z.isZero()?"-"+Y:Y};L.toFixed=function(J,$){var Y,Z,V=this,X=V.constructor;if(J===void 0)Y=UJ(V);else{if(h0(J,0,wJ),$===void 0)$=X.rounding;else h0($,0,8);Z=x(new X(V),J+V.e+1,$),Y=UJ(Z,!1,J+Z.e+1)}return V.isNeg()&&!V.isZero()?"-"+Y:Y};L.toFraction=function(J){var $,Y,Z,V,X,U,F,K,G,W,z,A,j=this,D=j.d,O=j.constructor;if(!D)return new O(j);if(G=Y=new O(1),Z=K=new O(0),$=new O(Z),X=$.e=A6(D)-j.e-1,U=X%p,$.d[0]=M0(10,U<0?p+U:U),J==null)J=X>0?$:G;else{if(F=new O(J),!F.isInt()||F.lt(G))throw Error(MJ+F);J=F.gt($)?X>0?$:G:F}i=!1,F=new O(T0(D)),W=O.precision,O.precision=X=D.length*p*2;for(;;){if(z=K0(F,$,0,1,1),V=Y.plus(z.times(Z)),V.cmp(J)==1)break;Y=Z,Z=V,V=G,G=K.plus(z.times(V)),K=V,V=$,$=F.minus(z.times(V)),F=V}return V=K0(J.minus(Y),Z,0,1,1),K=K.plus(V.times(G)),Y=Y.plus(V.times(Z)),K.s=G.s=j.s,A=K0(G,Z,X,1).minus(j).abs().cmp(K0(K,Y,X,1).minus(j).abs())<1?[G,Z]:[K,Y],O.precision=W,i=!0,A};L.toHexadecimal=L.toHex=function(J,$){return p5(this,16,J,$)};L.toNearest=function(J,$){var Y=this,Z=Y.constructor;if(Y=new Z(Y),J==null){if(!Y.d)return Y;J=new Z(1),$=Z.rounding}else{if(J=new Z(J),$===void 0)$=Z.rounding;else h0($,0,8);if(!Y.d)return J.s?Y:J;if(!J.d){if(J.s)J.s=Y.s;return J}}if(J.d[0])i=!1,Y=K0(Y,J,0,$,1).times(J),i=!0,x(Y);else J.s=Y.s,Y=J;return Y};L.toNumber=function(){return+this};L.toOctal=function(J,$){return p5(this,8,J,$)};L.toPower=L.pow=function(J){var $,Y,Z,V,X,U,F=this,K=F.constructor,G=+(J=new K(J));if(!F.d||!J.d||!F.d[0]||!J.d[0])return new K(M0(+F,G));if(F=new K(F),F.eq(1))return F;if(Z=K.precision,X=K.rounding,J.eq(1))return x(F,Z,X);if($=C0(J.e/p),$>=J.d.length-1&&(Y=G<0?-G:G)<=e7)return V=R6(K,F,Y,Z),J.s<0?new K(1).div(V):x(V,Z,X);if(U=F.s,U<0){if($<J.d.length-1)return new K(NaN);if((J.d[$]&1)==0)U=1;if(F.e==0&&F.d[0]==1&&F.d.length==1)return F.s=U,F}if(Y=M0(+F,G),$=Y==0||!isFinite(Y)?C0(G*(Math.log("0."+T0(F.d))/Math.LN10+F.e+1)):new K(Y+"").e,$>K.maxE+1||$<K.minE-1)return new K($>0?U/0:0);if(i=!1,K.rounding=F.s=1,Y=Math.min(12,($+"").length),V=c5(J.times(LJ(F,Z+Y)),Z),V.d){if(V=x(V,Z+5,1),I$(V.d,Z,X)){if($=Z+10,V=x(c5(J.times(LJ(F,$+Y)),$),$+5,1),+T0(V.d).slice(Z+1,Z+15)+1==100000000000000)V=x(V,Z+1,0)}}return V.s=U,i=!0,K.rounding=X,x(V,Z,X)};L.toPrecision=function(J,$){var Y,Z=this,V=Z.constructor;if(J===void 0)Y=UJ(Z,Z.e<=V.toExpNeg||Z.e>=V.toExpPos);else{if(h0(J,1,wJ),$===void 0)$=V.rounding;else h0($,0,8);Z=x(new V(Z),J,$),Y=UJ(Z,J<=Z.e||Z.e<=V.toExpNeg,J)}return Z.isNeg()&&!Z.isZero()?"-"+Y:Y};L.toSignificantDigits=L.toSD=function(J,$){var Y=this,Z=Y.constructor;if(J===void 0)J=Z.precision,$=Z.rounding;else if(h0(J,1,wJ),$===void 0)$=Z.rounding;else h0($,0,8);return x(new Z(Y),J,$)};L.toString=function(){var J=this,$=J.constructor,Y=UJ(J,J.e<=$.toExpNeg||J.e>=$.toExpPos);return J.isNeg()&&!J.isZero()?"-"+Y:Y};L.truncated=L.trunc=function(){return x(new this.constructor(this),this.e+1,1)};L.valueOf=L.toJSON=function(){var J=this,$=J.constructor,Y=UJ(J,J.e<=$.toExpNeg||J.e>=$.toExpPos);return J.isNeg()?"-"+Y:Y};function T0(J){var $,Y,Z,V=J.length-1,X="",U=J[0];if(V>0){X+=U;for($=1;$<V;$++){if(Z=J[$]+"",Y=p-Z.length,Y)X+=EJ(Y);X+=Z}if(U=J[$],Z=U+"",Y=p-Z.length,Y)X+=EJ(Y)}else if(U===0)return"0";for(;U%10===0;)U/=10;return X+U}function h0(J,$,Y){if(J!==~~J||J<$||J>Y)throw Error(MJ+J)}function I$(J,$,Y,Z){var V,X,U,F;for(X=J[0];X>=10;X/=10)--$;if(--$<0)$+=p,V=0;else V=Math.ceil(($+1)/p),$%=p;if(X=M0(10,p-$),F=J[V]%X|0,Z==null)if($<3){if($==0)F=F/100|0;else if($==1)F=F/10|0;U=Y<4&&F==99999||Y>3&&F==49999||F==50000||F==0}else U=(Y<4&&F+1==X||Y>3&&F+1==X/2)&&(J[V+1]/X/100|0)==M0(10,$-2)-1||(F==X/2||F==0)&&(J[V+1]/X/100|0)==0;else if($<4){if($==0)F=F/1000|0;else if($==1)F=F/100|0;else if($==2)F=F/10|0;U=(Z||Y<4)&&F==9999||!Z&&Y>3&&F==4999}else U=((Z||Y<4)&&F+1==X||!Z&&Y>3&&F+1==X/2)&&(J[V+1]/X/1000|0)==M0(10,$-3)-1;return U}function i$(J,$,Y){var Z,V=[0],X,U=0,F=J.length;for(;U<F;){for(X=V.length;X--;)V[X]*=$;V[0]+=u5.indexOf(J.charAt(U++));for(Z=0;Z<V.length;Z++)if(V[Z]>Y-1){if(V[Z+1]===void 0)V[Z+1]=0;V[Z+1]+=V[Z]/Y|0,V[Z]%=Y}}return V.reverse()}function $4(J,$){var Y,Z,V;if($.isZero())return $;if(Z=$.d.length,Z<32)Y=Math.ceil(Z/3),V=(1/J5(4,Y)).toString();else Y=16,V="2.3283064365386962890625e-10";J.precision+=Y,$=oJ(J,1,$.times(V),new J(1));for(var X=Y;X--;){var U=$.times($);$=U.times(U).minus(U).times(8).plus(1)}return J.precision-=Y,$}var K0=function(){function J(Z,V,X){var U,F=0,K=Z.length;for(Z=Z.slice();K--;)U=Z[K]*V+F,Z[K]=U%X|0,F=U/X|0;if(F)Z.unshift(F);return Z}function $(Z,V,X,U){var F,K;if(X!=U)K=X>U?1:-1;else for(F=K=0;F<X;F++)if(Z[F]!=V[F]){K=Z[F]>V[F]?1:-1;break}return K}function Y(Z,V,X,U){var F=0;for(;X--;)Z[X]-=F,F=Z[X]<V[X]?1:0,Z[X]=F*U+Z[X]-V[X];for(;!Z[0]&&Z.length>1;)Z.shift()}return function(Z,V,X,U,F,K){var G,W,z,A,j,D,O,P,M,C,q,f,_,y,k,n,d,X0,o,t,R=Z.constructor,T=Z.s==V.s?1:-1,N=Z.d,I=V.d;if(!N||!N[0]||!I||!I[0])return new R(!Z.s||!V.s||(N?I&&N[0]==I[0]:!I)?NaN:N&&N[0]==0||!I?T*0:T/0);if(K)j=1,W=Z.e-V.e;else K=r0,j=p,W=C0(Z.e/j)-C0(V.e/j);o=I.length,d=N.length,M=new R(T),C=M.d=[];for(z=0;I[z]==(N[z]||0);z++);if(I[z]>(N[z]||0))W--;if(X==null)y=X=R.precision,U=R.rounding;else if(F)y=X+(Z.e-V.e)+1;else y=X;if(y<0)C.push(1),D=!0;else{if(y=y/j+2|0,z=0,o==1){A=0,I=I[0],y++;for(;(z<d||A)&&y--;z++)k=A*K+(N[z]||0),C[z]=k/I|0,A=k%I|0;D=A||z<d}else{if(A=K/(I[0]+1)|0,A>1)I=J(I,A,K),N=J(N,A,K),o=I.length,d=N.length;n=o,q=N.slice(0,o),f=q.length;for(;f<o;)q[f++]=0;if(t=I.slice(),t.unshift(0),X0=I[0],I[1]>=K/2)++X0;do{if(A=0,G=$(I,q,o,f),G<0){if(_=q[0],o!=f)_=_*K+(q[1]||0);if(A=_/X0|0,A>1){if(A>=K)A=K-1;if(O=J(I,A,K),P=O.length,f=q.length,G=$(O,q,P,f),G==1)A--,Y(O,o<P?t:I,P,K)}else{if(A==0)G=A=1;O=I.slice()}if(P=O.length,P<f)O.unshift(0);if(Y(q,O,f,K),G==-1){if(f=q.length,G=$(I,q,o,f),G<1)A++,Y(q,o<f?t:I,f,K)}f=q.length}else if(G===0)A++,q=[0];if(C[z++]=A,G&&q[0])q[f++]=N[n]||0;else q=[N[n]],f=1}while((n++<d||q[0]!==void 0)&&y--);D=q[0]!==void 0}if(!C[0])C.shift()}if(j==1)M.e=W,z6=D;else{for(z=1,A=C[0];A>=10;A/=10)z++;M.e=z+W*j-1,x(M,F?X+M.e+1:X,U,D)}return M}}();function x(J,$,Y,Z){var V,X,U,F,K,G,W,z,A,j=J.constructor;J:if($!=null){if(z=J.d,!z)return J;for(V=1,F=z[0];F>=10;F/=10)V++;if(X=$-V,X<0)X+=p,U=$,W=z[A=0],K=W/M0(10,V-U-1)%10|0;else if(A=Math.ceil((X+1)/p),F=z.length,A>=F)if(Z){for(;F++<=A;)z.push(0);W=K=0,V=1,X%=p,U=X-p+1}else break J;else{W=F=z[A];for(V=1;F>=10;F/=10)V++;X%=p,U=X-p+V,K=U<0?0:W/M0(10,V-U-1)%10|0}if(Z=Z||$<0||z[A+1]!==void 0||(U<0?W:W%M0(10,V-U-1)),G=Y<4?(K||Z)&&(Y==0||Y==(J.s<0?3:2)):K>5||K==5&&(Y==4||Z||Y==6&&(X>0?U>0?W/M0(10,V-U):0:z[A-1])%10&1||Y==(J.s<0?8:7)),$<1||!z[0]){if(z.length=0,G)$-=J.e+1,z[0]=M0(10,(p-$%p)%p),J.e=-$||0;else z[0]=J.e=0;return J}if(X==0)z.length=A,F=1,A--;else z.length=A+1,F=M0(10,p-X),z[A]=U>0?(W/M0(10,V-U)%M0(10,U)|0)*F:0;if(G)for(;;)if(A==0){for(X=1,U=z[0];U>=10;U/=10)X++;U=z[0]+=F;for(F=1;U>=10;U/=10)F++;if(X!=F){if(J.e++,z[0]==r0)z[0]=1}break}else{if(z[A]+=F,z[A]!=r0)break;z[A--]=0,F=1}for(X=z.length;z[--X]===0;)z.pop()}if(i){if(J.e>j.maxE)J.d=null,J.e=NaN;else if(J.e<j.minE)J.e=0,J.d=[0]}return J}function UJ(J,$,Y){if(!J.isFinite())return I6(J);var Z,V=J.e,X=T0(J.d),U=X.length;if($){if(Y&&(Z=Y-U)>0)X=X.charAt(0)+"."+X.slice(1)+EJ(Z);else if(U>1)X=X.charAt(0)+"."+X.slice(1);X=X+(J.e<0?"e":"e+")+J.e}else if(V<0){if(X="0."+EJ(-V-1)+X,Y&&(Z=Y-U)>0)X+=EJ(Z)}else if(V>=U){if(X+=EJ(V+1-U),Y&&(Z=Y-V-1)>0)X=X+"."+EJ(Z)}else{if((Z=V+1)<U)X=X.slice(0,Z)+"."+X.slice(Z);if(Y&&(Z=Y-U)>0){if(V+1===U)X+=".";X+=EJ(Z)}}return X}function e$(J,$){var Y=J[0];for($*=p;Y>=10;Y/=10)$++;return $}function s$(J,$,Y){if($>J4){if(i=!0,Y)J.precision=Y;throw Error(H6)}return x(new J(a$),$,1,!0)}function FJ(J,$,Y){if($>x5)throw Error(H6);return x(new J(r$),$,Y,!0)}function A6(J){var $=J.length-1,Y=$*p+1;if($=J[$],$){for(;$%10==0;$/=10)Y--;for($=J[0];$>=10;$/=10)Y++}return Y}function EJ(J){var $="";for(;J--;)$+="0";return $}function R6(J,$,Y,Z){var V,X=new J(1),U=Math.ceil(Z/p+4);i=!1;for(;;){if(Y%2){if(X=X.times($),G6(X.d,U))V=!0}if(Y=C0(Y/2),Y===0){if(Y=X.d.length-1,V&&X.d[Y]===0)++X.d[Y];break}$=$.times($),G6($.d,U)}return i=!0,X}function K6(J){return J.d[J.d.length-1]&1}function O6(J,$,Y){var Z,V,X=new J($[0]),U=0;for(;++U<$.length;){if(V=new J($[U]),!V.s){X=V;break}if(Z=X.cmp(V),Z===Y||Z===0&&X.s===Y)X=V}return X}function c5(J,$){var Y,Z,V,X,U,F,K,G=0,W=0,z=0,A=J.constructor,j=A.rounding,D=A.precision;if(!J.d||!J.d[0]||J.e>17)return new A(J.d?!J.d[0]?1:J.s<0?0:1/0:J.s?J.s<0?0:J:NaN);if($==null)i=!1,K=D;else K=$;F=new A(0.03125);while(J.e>-2)J=J.times(F),z+=5;Z=Math.log(M0(2,z))/Math.LN10*2+5|0,K+=Z,Y=X=U=new A(1),A.precision=K;for(;;){if(X=x(X.times(J),K,1),Y=Y.times(++W),F=U.plus(K0(X,Y,K,1)),T0(F.d).slice(0,K)===T0(U.d).slice(0,K)){V=z;while(V--)U=x(U.times(U),K,1);if($==null)if(G<3&&I$(U.d,K-Z,j,G))A.precision=K+=10,Y=X=F=new A(1),W=0,G++;else return x(U,A.precision=D,j,i=!0);else return A.precision=D,U}U=F}}function LJ(J,$){var Y,Z,V,X,U,F,K,G,W,z,A,j=1,D=10,O=J,P=O.d,M=O.constructor,C=M.rounding,q=M.precision;if(O.s<0||!P||!P[0]||!O.e&&P[0]==1&&P.length==1)return new M(P&&!P[0]?-1/0:O.s!=1?NaN:P?0:O);if($==null)i=!1,W=q;else W=$;if(M.precision=W+=D,Y=T0(P),Z=Y.charAt(0),Math.abs(X=O.e)<1500000000000000){while(Z<7&&Z!=1||Z==1&&Y.charAt(1)>3)O=O.times(J),Y=T0(O.d),Z=Y.charAt(0),j++;if(X=O.e,Z>1)O=new M("0."+Y),X++;else O=new M(Z+"."+Y.slice(1))}else return G=s$(M,W+2,q).times(X+""),O=LJ(new M(Z+"."+Y.slice(1)),W-D).plus(G),M.precision=q,$==null?x(O,q,C,i=!0):O;z=O,K=U=O=K0(O.minus(1),O.plus(1),W,1),A=x(O.times(O),W,1),V=3;for(;;){if(U=x(U.times(A),W,1),G=K.plus(K0(U,new M(V),W,1)),T0(G.d).slice(0,W)===T0(K.d).slice(0,W)){if(K=K.times(2),X!==0)K=K.plus(s$(M,W+2,q).times(X+""));if(K=K0(K,new M(j),W,1),$==null)if(I$(K.d,W-D,C,F))M.precision=W+=D,G=U=O=K0(z.minus(1),z.plus(1),W,1),A=x(O.times(O),W,1),V=F=1;else return x(K,M.precision=q,C,i=!0);else return M.precision=q,K}K=G,V+=2}}function I6(J){return String(J.s*J.s/0)}function o$(J,$){var Y,Z,V;if((Y=$.indexOf("."))>-1)$=$.replace(".","");if((Z=$.search(/e/i))>0){if(Y<0)Y=Z;Y+=+$.slice(Z+1),$=$.substring(0,Z)}else if(Y<0)Y=$.length;for(Z=0;$.charCodeAt(Z)===48;Z++);for(V=$.length;$.charCodeAt(V-1)===48;--V);if($=$.slice(Z,V),$){if(V-=Z,J.e=Y=Y-Z-1,J.d=[],Z=(Y+1)%p,Y<0)Z+=p;if(Z<V){if(Z)J.d.push(+$.slice(0,Z));for(V-=p;Z<V;)J.d.push(+$.slice(Z,Z+=p));$=$.slice(Z),Z=p-$.length}else Z-=V;for(;Z--;)$+="0";if(J.d.push(+$),i){if(J.e>J.constructor.maxE)J.d=null,J.e=NaN;else if(J.e<J.constructor.minE)J.e=0,J.d=[0]}}else J.e=0,J.d=[0];return J}function Y4(J,$){var Y,Z,V,X,U,F,K,G,W;if($.indexOf("_")>-1){if($=$.replace(/(\d)_(?=\d)/g,"$1"),N6.test($))return o$(J,$)}else if($==="Infinity"||$==="NaN"){if(!+$)J.s=NaN;return J.e=NaN,J.d=null,J}if(s7.test($))Y=16,$=$.toLowerCase();else if(r7.test($))Y=2;else if(t7.test($))Y=8;else throw Error(MJ+$);if(X=$.search(/p/i),X>0)K=+$.slice(X+1),$=$.substring(2,X);else $=$.slice(2);if(X=$.indexOf("."),U=X>=0,Z=J.constructor,U)$=$.replace(".",""),F=$.length,X=F-X,V=R6(Z,new Z(Y),X,X*2);G=i$($,Y,r0),W=G.length-1;for(X=W;G[X]===0;--X)G.pop();if(X<0)return new Z(J.s*0);if(J.e=e$(G,W),J.d=G,i=!1,U)J=K0(J,V,F*4);if(K)J=J.times(Math.abs(K)<54?M0(2,K):s0.pow(2,K));return i=!0,J}function Z4(J,$){var Y,Z=$.d.length;if(Z<3)return $.isZero()?$:oJ(J,2,$,$);Y=1.4*Math.sqrt(Z),Y=Y>16?16:Y|0,$=$.times(1/J5(5,Y)),$=oJ(J,2,$,$);var V,X=new J(5),U=new J(16),F=new J(20);for(;Y--;)V=$.times($),$=$.times(X.plus(V.times(U.times(V).minus(F))));return $}function oJ(J,$,Y,Z,V){var X,U,F,K,G=1,W=J.precision,z=Math.ceil(W/p);i=!1,K=Y.times(Y),F=new J(Z);for(;;){if(U=K0(F.times(K),new J($++*$++),W,1),F=V?Z.plus(U):Z.minus(U),Z=K0(U.times(K),new J($++*$++),W,1),U=F.plus(Z),U.d[z]!==void 0){for(X=z;U.d[X]===F.d[X]&&X--;);if(X==-1)break}X=F,F=Z,Z=U,U=X,G++}return i=!0,U.d.length=z+1,U}function J5(J,$){var Y=J;while(--$)Y*=J;return Y}function D6(J,$){var Y,Z=$.s<0,V=FJ(J,J.precision,1),X=V.times(0.5);if($=$.abs(),$.lte(X))return BJ=Z?4:1,$;if(Y=$.divToInt(V),Y.isZero())BJ=Z?3:2;else{if($=$.minus(Y.times(V)),$.lte(X))return BJ=K6(Y)?Z?2:3:Z?4:1,$;BJ=K6(Y)?Z?1:4:Z?3:2}return $.minus(V).abs()}function p5(J,$,Y,Z){var V,X,U,F,K,G,W,z,A,j=J.constructor,D=Y!==void 0;if(D)if(h0(Y,1,wJ),Z===void 0)Z=j.rounding;else h0(Z,0,8);else Y=j.precision,Z=j.rounding;if(!J.isFinite())W=I6(J);else{if(W=UJ(J),U=W.indexOf("."),D){if(V=2,$==16)Y=Y*4-3;else if($==8)Y=Y*3-2}else V=$;if(U>=0)W=W.replace(".",""),A=new j(1),A.e=W.length-U,A.d=i$(UJ(A),10,V),A.e=A.d.length;z=i$(W,10,V),X=K=z.length;for(;z[--K]==0;)z.pop();if(!z[0])W=D?"0p+0":"0";else{if(U<0)X--;else J=new j(J),J.d=z,J.e=X,J=K0(J,A,Y,Z,0,V),z=J.d,X=J.e,G=z6;if(U=z[Y],F=V/2,G=G||z[Y+1]!==void 0,G=Z<4?(U!==void 0||G)&&(Z===0||Z===(J.s<0?3:2)):U>F||U===F&&(Z===4||G||Z===6&&z[Y-1]&1||Z===(J.s<0?8:7)),z.length=Y,G){for(;++z[--Y]>V-1;)if(z[Y]=0,!Y)++X,z.unshift(1)}for(K=z.length;!z[K-1];--K);for(U=0,W="";U<K;U++)W+=u5.charAt(z[U]);if(D){if(K>1)if($==16||$==8){U=$==16?4:3;for(--K;K%U;K++)W+="0";z=i$(W,V,$);for(K=z.length;!z[K-1];--K);for(U=1,W="1.";U<K;U++)W+=u5.charAt(z[U])}else W=W.charAt(0)+"."+W.slice(1);W=W+(X<0?"p":"p+")+X}else if(X<0){for(;++X;)W="0"+W;W="0."+W}else if(++X>K)for(X-=K;X--;)W+="0";else if(X<K)W=W.slice(0,X)+"."+W.slice(X)}W=($==16?"0x":$==2?"0b":$==8?"0o":"")+W}return J.s<0?"-"+W:W}function G6(J,$){if(J.length>$)return J.length=$,!0}function V4(J){return new this(J).abs()}function X4(J){return new this(J).acos()}function Q4(J){return new this(J).acosh()}function F4(J,$){return new this(J).plus($)}function U4(J){return new this(J).asin()}function K4(J){return new this(J).asinh()}function G4(J){return new this(J).atan()}function W4(J){return new this(J).atanh()}function z4(J,$){J=new this(J),$=new this($);var Y,Z=this.precision,V=this.rounding,X=Z+4;if(!J.s||!$.s)Y=new this(NaN);else if(!J.d&&!$.d)Y=FJ(this,X,1).times($.s>0?0.25:0.75),Y.s=J.s;else if(!$.d||J.isZero())Y=$.s<0?FJ(this,Z,V):new this(0),Y.s=J.s;else if(!J.d||$.isZero())Y=FJ(this,X,1).times(0.5),Y.s=J.s;else if($.s<0)this.precision=X,this.rounding=1,Y=this.atan(K0(J,$,X,1)),$=FJ(this,X,1),this.precision=Z,this.rounding=V,Y=J.s<0?Y.minus($):Y.plus($);else Y=this.atan(K0(J,$,X,1));return Y}function H4(J){return new this(J).cbrt()}function j4(J){return x(J=new this(J),J.e+1,2)}function B4(J,$,Y){return new this(J).clamp($,Y)}function N4(J){if(!J||typeof J!=="object")throw Error(t$+"Object expected");var $,Y,Z,V=J.defaults===!0,X=["precision",1,wJ,"rounding",0,8,"toExpNeg",-iJ,0,"toExpPos",0,iJ,"maxE",0,iJ,"minE",-iJ,0,"modulo",0,9];for($=0;$<X.length;$+=3){if(Y=X[$],V)this[Y]=l5[Y];if((Z=J[Y])!==void 0)if(C0(Z)===Z&&Z>=X[$+1]&&Z<=X[$+2])this[Y]=Z;else throw Error(MJ+Y+": "+Z)}if(Y="crypto",V)this[Y]=l5[Y];if((Z=J[Y])!==void 0)if(Z===!0||Z===!1||Z===0||Z===1)if(Z)if(typeof crypto<"u"&&crypto&&(crypto.getRandomValues||crypto.randomBytes))this[Y]=!0;else throw Error(j6);else this[Y]=!1;else throw Error(MJ+Y+": "+Z);return this}function A4(J){return new this(J).cos()}function R4(J){return new this(J).cosh()}function _6(J){var $,Y,Z;function V(X){var U,F,K,G=this;if(!(G instanceof V))return new V(X);if(G.constructor=V,W6(X)){if(G.s=X.s,i)if(!X.d||X.e>V.maxE)G.e=NaN,G.d=null;else if(X.e<V.minE)G.e=0,G.d=[0];else G.e=X.e,G.d=X.d.slice();else G.e=X.e,G.d=X.d?X.d.slice():X.d;return}if(K=typeof X,K==="number"){if(X===0){G.s=1/X<0?-1:1,G.e=0,G.d=[0];return}if(X<0)X=-X,G.s=-1;else G.s=1;if(X===~~X&&X<1e7){for(U=0,F=X;F>=10;F/=10)U++;if(i)if(U>V.maxE)G.e=NaN,G.d=null;else if(U<V.minE)G.e=0,G.d=[0];else G.e=U,G.d=[X];else G.e=U,G.d=[X];return}if(X*0!==0){if(!X)G.s=NaN;G.e=NaN,G.d=null;return}return o$(G,X.toString())}if(K==="string"){if((F=X.charCodeAt(0))===45)X=X.slice(1),G.s=-1;else{if(F===43)X=X.slice(1);G.s=1}return N6.test(X)?o$(G,X):Y4(G,X)}if(K==="bigint"){if(X<0)X=-X,G.s=-1;else G.s=1;return o$(G,X.toString())}throw Error(MJ+X)}if(V.prototype=L,V.ROUND_UP=0,V.ROUND_DOWN=1,V.ROUND_CEIL=2,V.ROUND_FLOOR=3,V.ROUND_HALF_UP=4,V.ROUND_HALF_DOWN=5,V.ROUND_HALF_EVEN=6,V.ROUND_HALF_CEIL=7,V.ROUND_HALF_FLOOR=8,V.EUCLID=9,V.config=V.set=N4,V.clone=_6,V.isDecimal=W6,V.abs=V4,V.acos=X4,V.acosh=Q4,V.add=F4,V.asin=U4,V.asinh=K4,V.atan=G4,V.atanh=W4,V.atan2=z4,V.cbrt=H4,V.ceil=j4,V.clamp=B4,V.cos=A4,V.cosh=R4,V.div=O4,V.exp=I4,V.floor=D4,V.hypot=_4,V.ln=q4,V.log=E4,V.log10=M4,V.log2=L4,V.max=w4,V.min=T4,V.mod=v4,V.mul=P4,V.pow=C4,V.random=b4,V.round=f4,V.sign=k4,V.sin=y4,V.sinh=S4,V.sqrt=g4,V.sub=h4,V.sum=u4,V.tan=l4,V.tanh=x4,V.trunc=c4,J===void 0)J={};if(J){if(J.defaults!==!0){Z=["precision","rounding","toExpNeg","toExpPos","maxE","minE","modulo","crypto"];for($=0;$<Z.length;)if(!J.hasOwnProperty(Y=Z[$++]))J[Y]=this[Y]}}return V.config(J),V}function O4(J,$){return new this(J).div($)}function I4(J){return new this(J).exp()}function D4(J){return x(J=new this(J),J.e+1,3)}function _4(){var J,$,Y=new this(0);i=!1;for(J=0;J<arguments.length;)if($=new this(arguments[J++]),!$.d){if($.s)return i=!0,new this(1/0);Y=$}else if(Y.d)Y=Y.plus($.times($));return i=!0,Y.sqrt()}function W6(J){return J instanceof s0||J&&J.toStringTag===B6||!1}function q4(J){return new this(J).ln()}function E4(J,$){return new this(J).log($)}function L4(J){return new this(J).log(2)}function M4(J){return new this(J).log(10)}function w4(){return O6(this,arguments,-1)}function T4(){return O6(this,arguments,1)}function v4(J,$){return new this(J).mod($)}function P4(J,$){return new this(J).mul($)}function C4(J,$){return new this(J).pow($)}function b4(J){var $,Y,Z,V,X=0,U=new this(1),F=[];if(J===void 0)J=this.precision;else h0(J,1,wJ);if(Z=Math.ceil(J/p),!this.crypto)for(;X<Z;)F[X++]=Math.random()*1e7|0;else if(crypto.getRandomValues){$=crypto.getRandomValues(new Uint32Array(Z));for(;X<Z;)if(V=$[X],V>=4290000000)$[X]=crypto.getRandomValues(new Uint32Array(1))[0];else F[X++]=V%1e7}else if(crypto.randomBytes){$=crypto.randomBytes(Z*=4);for(;X<Z;)if(V=$[X]+($[X+1]<<8)+($[X+2]<<16)+(($[X+3]&127)<<24),V>=2140000000)crypto.randomBytes(4).copy($,X);else F.push(V%1e7),X+=4;X=Z/4}else throw Error(j6);if(Z=F[--X],J%=p,Z&&J)V=M0(10,p-J),F[X]=(Z/V|0)*V;for(;F[X]===0;X--)F.pop();if(X<0)Y=0,F=[0];else{Y=-1;for(;F[0]===0;Y-=p)F.shift();for(Z=1,V=F[0];V>=10;V/=10)Z++;if(Z<p)Y-=p-Z}return U.e=Y,U.d=F,U}function f4(J){return x(J=new this(J),J.e+1,this.rounding)}function k4(J){return J=new this(J),J.d?J.d[0]?J.s:0*J.s:J.s||NaN}function y4(J){return new this(J).sin()}function S4(J){return new this(J).sinh()}function g4(J){return new this(J).sqrt()}function h4(J,$){return new this(J).sub($)}function u4(){var J=0,$=arguments,Y=new this($[J]);i=!1;for(;Y.s&&++J<$.length;)Y=Y.plus($[J]);return i=!0,x(Y,this.precision,this.rounding)}function l4(J){return new this(J).tan()}function x4(J){return new this(J).tanh()}function c4(J){return x(J=new this(J),J.e+1,1)}L[Symbol.for("nodejs.util.inspect.custom")]=L.toString;L[Symbol.toStringTag]="Decimal";var s0=L.constructor=_6(l5);a$=new s0(a$);r$=new s0(r$);var tJ={};QJ(tJ,{layer:()=>L6,defaultLayer:()=>JZ,Storage:()=>tJ,Service:()=>$5,NotFoundError:()=>GJ});import b0 from"path";var NJ=KJ({service:"storage"});class GJ extends Q.TaggedErrorClass()("NotFoundError",{message:Q.String}){static isInstance(J){return J instanceof GJ}}var p4=Q.Struct({path:Q.optional(Q.Struct({root:Q.optional(Q.String)}))}),d4=Q.Struct({id:Q.String}),m4=Q.Struct({id:Q.String}),n4=Q.Struct({additions:a,deletions:a}),i4=Q.Struct({id:Q.String,projectID:Q.String,summary:Q.Struct({diffs:Q.Array(n4)})}),o4=Q.decodeUnknownOption(p4),a4=Q.decodeUnknownOption(d4),r4=Q.decodeUnknownOption(m4),s4=Q.decodeUnknownOption(i4);class $5 extends n0.Service()("@muxcode/Storage"){}function t4(J,$){return b0.join(J,...$)+".json"}function d5(J){if(!J||typeof J!=="object")return!1;if("code"in J&&J.code==="ENOENT")return!0;if("reason"in J&&J.reason&&typeof J.reason==="object"&&"_tag"in J.reason)return J.reason._tag==="NotFound";return!1}function e4(J){let $=Number.parseInt(J,10);return Number.isNaN($)?0:$}var q6=[B.fn("Storage.migration.1")(function*(J,$,Y){let Z=b0.resolve(J,"../project");if(!(yield*$.isDir(Z)))return;let V=yield*$.glob("*",{cwd:Z,include:"all"});for(let X of V){let U=b0.join(Z,X);if(!(yield*$.isDir(U)))continue;NJ.info(`migrating project ${X}`);let F=X,K="/";if(F!=="global"){for(let z of yield*$.glob("storage/session/message/*/*.json",{cwd:U,absolute:!0})){let A=o4(yield*$.readJson(z),{onExcessProperty:"preserve"}),j=TJ.isSome(A)?A.value.path?.root:void 0;if(!j)continue;K=j;break}if(!K)continue;if(!(yield*$.isDir(K)))continue;let G=yield*Y.run(["rev-list","--max-parents=0","--all"],{cwd:K}),[W]=G.text().split(`
|
|
39
|
+
`).filter(Boolean).map((z)=>z.trim()).toSorted();if(!W)continue;F=W,yield*$.writeWithDirs(b0.join(J,"project",F+".json"),JSON.stringify({id:W,vcs:"git",worktree:K,time:{created:Date.now(),initialized:Date.now()}},null,2)),NJ.info(`migrating sessions for project ${F}`);for(let z of yield*$.glob("storage/session/info/*.json",{cwd:U,absolute:!0})){let A=b0.join(J,"session",F,b0.basename(z));NJ.info("copying",{sessionFile:z,dest:A});let j=yield*$.readJson(z),D=a4(j,{onExcessProperty:"preserve"});if(yield*$.writeWithDirs(A,JSON.stringify(j,null,2)),TJ.isNone(D))continue;NJ.info(`migrating messages for session ${D.value.id}`);for(let O of yield*$.glob(`storage/session/message/${D.value.id}/*.json`,{cwd:U,absolute:!0})){let P=b0.join(J,"message",D.value.id,b0.basename(O));NJ.info("copying",{msgFile:O,dest:P});let M=yield*$.readJson(O),C=r4(M,{onExcessProperty:"preserve"});if(yield*$.writeWithDirs(P,JSON.stringify(M,null,2)),TJ.isNone(C))continue;NJ.info(`migrating parts for message ${C.value.id}`);for(let q of yield*$.glob(`storage/session/part/${D.value.id}/${C.value.id}/*.json`,{cwd:U,absolute:!0})){let f=b0.join(J,"part",C.value.id,b0.basename(q)),_=yield*$.readJson(q);NJ.info("copying",{partFile:q,dest:f}),yield*$.writeWithDirs(f,JSON.stringify(_,null,2))}}}}}}),B.fn("Storage.migration.2")(function*(J,$){for(let Y of yield*$.glob("session/*/*.json",{cwd:J,absolute:!0})){let Z=yield*$.readJson(Y),V=s4(Z,{onExcessProperty:"preserve"});if(TJ.isNone(V))continue;let X=V.value.summary.diffs;yield*$.writeWithDirs(b0.join(J,"session_diff",V.value.id+".json"),JSON.stringify(X,null,2)),yield*$.writeWithDirs(b0.join(J,"session",V.value.projectID,V.value.id+".json"),JSON.stringify({...Z,summary:{additions:X.reduce((U,F)=>U+F.additions,0),deletions:X.reduce((U,F)=>U+F.deletions,0)}},null,2))}})],L6=j0.effect($5,B.gen(function*(){let J=yield*sJ.Service,$=yield*n5.Service,Y=yield*m5.make({lookup:()=>aJ.make(),idleTimeToLive:0}),Z=yield*B.cached(B.gen(function*(){let j=b0.join(rJ.Path.data,"storage"),D=b0.join(j,"migration"),O=yield*J.readFileString(D).pipe(B.map(e4),B.catchIf(d5,()=>B.succeed(0)),B.orElseSucceed(()=>0));for(let P=O;P<q6.length;P++){NJ.info("running migration",{index:P});let M=q6[P],C=yield*B.exit(M(j,J,$));if(E6.isFailure(C)){NJ.error("failed to run migration",{index:P,cause:C.cause});break}yield*J.writeWithDirs(D,String(P+1))}return{dir:j}})),V=(j)=>B.fail(new GJ({message:`Resource not found: ${j}`})),X=(j,D)=>D.pipe(B.catchIf(d5,()=>V(j))),U=B.fnUntraced(function*(j,D){yield*J.writeWithDirs(j,JSON.stringify(D,null,2))}),F=(j,D)=>B.scoped(B.gen(function*(){let O=t4((yield*Z).dir,j);return yield*D(O,yield*m5.get(Y,O))})),K=B.fn("Storage.remove")(function*(j){yield*F(j,(D,O)=>aJ.withWriteLock(O,J.remove(D).pipe(B.catchIf(d5,()=>B.void))))}),G=(j)=>B.gen(function*(){return yield*F(j,(O,P)=>aJ.withReadLock(P,X(O,J.readJson(O))))}),W=(j,D)=>B.gen(function*(){return yield*F(j,(P,M)=>aJ.withWriteLock(M,B.gen(function*(){let C=yield*X(P,J.readJson(P));return D(C),yield*U(P,C),C})))}),z=(j,D)=>B.gen(function*(){yield*F(j,(O,P)=>aJ.withWriteLock(P,U(O,D)))}),A=B.fn("Storage.list")(function*(j){let D=(yield*Z).dir,O=b0.join(D,...j);return(yield*J.glob("**/*",{cwd:O,include:"file"}).pipe(B.catch(()=>B.succeed([])))).map((M)=>[...j,...M.slice(0,-5).split(b0.sep)]).toSorted((M,C)=>M.join("/").localeCompare(C.join("/")))});return $5.of({remove:K,read:G,update:W,write:z,list:A})})),JZ=L6.pipe(j0.provide(sJ.defaultLayer),j0.provide(n5.defaultLayer));var u0={};QJ(u0,{versionedType:()=>AJ,use:()=>YZ,reset:()=>ZZ,registry:()=>J$,project:()=>QZ,layer:()=>v6,init:()=>VZ,effectPayloads:()=>FZ,define:()=>XZ,defaultLayer:()=>$Z,SyncEvent:()=>u0,Service:()=>D$});var g0=o5("event_sequence",{aggregate_id:yJ().notNull().primaryKey(),seq:i5().notNull(),owner_id:yJ()}),Z5=o5("event",{id:yJ().primaryKey(),aggregate_id:yJ().notNull().references(()=>g0.aggregate_id,{onDelete:"cascade"}),seq:i5().notNull(),type:yJ().notNull(),data:yJ({mode:"json"}).$type().notNull()});var M6=Q.String.check(Q.isStartsWith("evt")).pipe(Q.brand("EventID"),eJ((J)=>({ascending:($)=>J.make(mJ.ascending("event",$))})));class D$ extends n0.Service()("@muxcode/SyncEvent"){}var v6=j0.effect(D$)(B.gen(function*(){let J=yield*RJ.Service,$=yield*e0.Service,Y=B.fn("SyncEvent.replay")(function*(F,K){let G=J$.get(F.type);if(!G)throw Error(`Unknown event type: ${F.type}`);let W=q0.use((O)=>O.select({seq:g0.seq,ownerID:g0.owner_id}).from(g0).where(G0(g0.aggregate_id,F.aggregateID)).get()),z=W?.seq??-1;if(F.seq<=z)return;if(W?.ownerID&&W.ownerID!==K?.ownerID)return;let A=z+1;if(F.seq!==A)throw Error(`Sequence mismatch for aggregate "${F.aggregateID}": expected ${A}, got ${F.seq}`);let j=!!K?.publish,D=yield*a5.make();w6(G,F,{bus:$,bridge:D,publish:j,ownerID:K?.ownerID,experimentalWorkspaces:J.experimentalWorkspaces})}),Z=B.fn("SyncEvent.replayAll")(function*(F,K){let G=F[0]?.aggregateID;if(!G)return;if(F.some((z)=>z.aggregateID!==G))throw Error("Replay events must belong to the same session");let W=F[0].seq;for(let[z,A]of F.entries()){let j=W+z;if(A.seq!==j)throw Error(`Replay sequence mismatch at index ${z}: expected ${j}, got ${A.seq}`)}for(let z of F)yield*Y(z,K);return G}),V=B.fn("SyncEvent.run")(function*(F,K,G){let W=K[F.aggregate];if(W==null)throw Error(`SyncEvent.run: "${F.aggregate}" required but not found: ${JSON.stringify(K)}`);if(F.version!==X5.get(F.type))throw Error(`SyncEvent.run: running old versions of events is not allowed: ${F.type}`);let{publish:z=!0}=G||{},A=yield*a5.make();q0.transaction((j)=>{let D=M6.ascending(),O=j.select({seq:g0.seq}).from(g0).where(G0(g0.aggregate_id,W)).get(),P=O?.seq!=null?O.seq+1:0;w6(F,{id:D,seq:P,aggregateID:W,data:K},{bus:$,bridge:A,publish:z,experimentalWorkspaces:J.experimentalWorkspaces})},{behavior:"immediate"})}),X=B.fn("SyncEvent.remove")(function*(F){q0.transaction((K)=>{K.delete(g0).where(G0(g0.aggregate_id,F)).run(),K.delete(Z5).where(G0(Z5.aggregate_id,F)).run()})}),U=B.fn("SyncEvent.claim")((F,K)=>B.sync(()=>q0.use((G)=>G.update(g0).set({owner_id:K}).where(G0(g0.aggregate_id,F)).run())));return D$.of({run:V,replay:Y,replayAll:Z,remove:X,claim:U})})),$Z=v6.pipe(j0.provide([e0.defaultLayer,RJ.defaultLayer])),YZ=Q5(D$),J$=new Map,V5,X5=new Map,s5=!1,t5;function ZZ(){s5=!1,V5=void 0,t5=(J,$)=>$}function VZ(J){V5=new Map(J.projectors.map(([$,Y])=>[AJ($.type,$.version),Y]));for(let $ of r5.registry.values()){if(!$.version||!$.aggregate)continue;P6({type:$.type,version:$.version,aggregate:$.aggregate,properties:$.data,schema:$.data})}for(let[$,Y]of X5.entries()){let Z=J$.get(AJ($,Y));t0.define(Z.type,Z.properties)}s5=!0,t5=J.convertEvent??(($,Y)=>Y)}function AJ(J,$){return $?`${J}.${$}`:J}function XZ(J){if(s5)throw Error("Error defining sync event: sync system has been frozen");let $={type:J.type,version:J.version,aggregate:J.aggregate,schema:J.schema,properties:J.busSchema??J.schema};return P6($),$}function QZ(J,$){return[J,$]}function P6(J){X5.set(J.type,Math.max(J.version,X5.get(J.type)||0)),J$.set(AJ(J.type,J.version),J)}function w6(J,$,Y){if(V5==null)throw Error("No projectors available. Call `SyncEvent.init` to install projectors");let Z=V5.get(AJ(J.type,J.version));if(!Z){if(!J.type.includes("next"))throw Error(`Projector not found for event: ${J.type}`);return}q0.transaction((V)=>{if(Z(V,$.data,$),Y.experimentalWorkspaces)V.insert(g0).values({aggregate_id:$.aggregateID,seq:$.seq,owner_id:Y?.ownerID}).onConflictDoUpdate({target:g0.aggregate_id,set:{seq:$.seq}}).run(),V.insert(Z5).values({id:$.id,seq:$.seq,aggregate_id:$.aggregateID,type:AJ(J.type,J.version),data:$.data}).run();q0.effect(()=>{if(!Y.publish)return;let X=t5(J.type,$.data),U=(F)=>Y.bridge.fork(B.gen(function*(){yield*Y.bus.publish(J,F,{id:$.id});let K=yield*s.context,G=yield*s.workspaceID;T6.emit("event",{directory:K.directory,project:K.project.id,workspace:G,payload:{type:"sync",syncEvent:{type:AJ(J.type,J.version),...$}}})}));if(X instanceof Promise)X.then(U);else U(X)})})}function FZ(){return[...J$.entries().map(([J,$])=>Q.Struct({type:Q.Literal("sync"),name:Q.Literal(J),id:Q.String,seq:Q.Finite,aggregateID:Q.Literal($.aggregate),data:$.schema}).annotate({identifier:`SyncEvent.${J}`})).toArray(),...r5.registry.values().filter((J)=>J.version!==void 0&&!J$.has(AJ(J.type,J.version))).map((J)=>Q.Struct({type:Q.Literal("sync"),name:Q.Literal(AJ(J.type,J.version)),id:Q.String,seq:Q.Finite,aggregateID:Q.Literal(J.aggregate),data:J.data}).annotate({identifier:`SyncEvent.${J.type}`})).toArray()]}var m0={};QJ(m0,{toModelMessagesEffect:()=>v7,toModelMessages:()=>aX,stream:()=>C7,parts:()=>b7,page:()=>P7,latest:()=>tX,isMedia:()=>y$,get:()=>rX,fromError:()=>eX,filterCompactedEffect:()=>sX,filterCompacted:()=>f7,cursor:()=>p8,WithParts:()=>pX,User:()=>M7,ToolStateRunning:()=>I7,ToolStatePending:()=>O7,ToolStateError:()=>_7,ToolStateCompleted:()=>D7,ToolState:()=>q7,ToolPart:()=>E7,TextPartInput:()=>kX,TextPart:()=>U7,SymbolSource:()=>W7,SubtaskPartInput:()=>gX,SubtaskPart:()=>B7,StructuredOutputError:()=>V7,StepStartPart:()=>A7,StepFinishPart:()=>R7,SnapshotPart:()=>Q7,SYNTHETIC_ATTACHMENT_PROMPT:()=>Z7,RetryPart:()=>N7,ResourceSource:()=>z7,ReasoningPart:()=>K7,PatchPart:()=>F7,Part:()=>a8,OutputLengthError:()=>z$,OutputFormatText:()=>d8,OutputFormatJsonSchema:()=>m8,MessageV2:()=>m0,Info:()=>r8,Format:()=>X7,FileSource:()=>G7,FilePartSource:()=>i8,FilePartInput:()=>yX,FilePart:()=>o8,Event:()=>cX,ContextOverflowError:()=>P5,CompactionPart:()=>j7,AuthError:()=>H$,Assistant:()=>w7,AgentPartInput:()=>SX,AgentPart:()=>H7,AbortedError:()=>h$,APIError:()=>DJ});var f$={};QJ(f$,{layer:()=>hY,defaultLayer:()=>jX,Symbol:()=>KX,Status:()=>WX,Service:()=>D5,Range:()=>I5,LSP:()=>f$,Event:()=>gY,DocumentSymbol:()=>GX,Diagnostic:()=>b$});var U$=aV(DY(),1);import v$ from"path";import{pathToFileURL as PJ,fileURLToPath as rV}from"url";var _Y={".abap":"abap",".bat":"bat",".bib":"bibtex",".bibtex":"bibtex",".clj":"clojure",".cljs":"clojure",".cljc":"clojure",".edn":"clojure",".coffee":"coffeescript",".c":"c",".cpp":"cpp",".cxx":"cpp",".cc":"cpp",".c++":"cpp",".cs":"csharp",".csx":"csharp",".css":"css",".d":"d",".pas":"pascal",".pascal":"pascal",".diff":"diff",".patch":"diff",".dart":"dart",".dockerfile":"dockerfile",".ex":"elixir",".exs":"elixir",".erl":"erlang",".ets":"typescript",".hrl":"erlang",".fs":"fsharp",".fsi":"fsharp",".fsx":"fsharp",".fsscript":"fsharp",".gitcommit":"git-commit",".gitrebase":"git-rebase",".go":"go",".groovy":"groovy",".gleam":"gleam",".hbs":"handlebars",".handlebars":"handlebars",".hs":"haskell",".lhs":"haskell",".html":"html",".htm":"html",".ini":"ini",".java":"java",".jl":"julia",".js":"javascript",".kt":"kotlin",".kts":"kotlin",".jsx":"javascriptreact",".json":"json",".tex":"latex",".latex":"latex",".less":"less",".lua":"lua",".makefile":"makefile",makefile:"makefile",".md":"markdown",".markdown":"markdown",".m":"objective-c",".mm":"objective-cpp",".pl":"perl",".pm":"perl",".pm6":"perl6",".php":"php",".ps1":"powershell",".psm1":"powershell",".pug":"jade",".jade":"jade",".py":"python",".r":"r",".cshtml":"razor",".razor":"razor",".rb":"ruby",".rake":"ruby",".gemspec":"ruby",".ru":"ruby",".erb":"erb",".html.erb":"erb",".js.erb":"erb",".css.erb":"erb",".json.erb":"erb",".rs":"rust",".scss":"scss",".sass":"sass",".scala":"scala",".shader":"shaderlab",".sh":"shellscript",".bash":"shellscript",".zsh":"shellscript",".ksh":"shellscript",".sql":"sql",".svelte":"svelte",".swift":"swift",".ts":"typescript",".tsx":"typescriptreact",".mts":"typescript",".cts":"typescript",".mtsx":"typescriptreact",".ctsx":"typescriptreact",".xml":"xml",".xsl":"xsl",".yaml":"yaml",".yml":"yaml",".mjs":"javascript",".cjs":"javascript",".vue":"vue",".zig":"zig",".zon":"zig",".astro":"astro",".ml":"ocaml",".mli":"ocaml",".tf":"terraform",".tfvars":"terraform-vars",".hcl":"hcl",".nix":"nix",".typ":"typst",".typc":"typst"};var sV=150,w8=5000,T8=1e4,qY=3000,tV=45000,eV=1,JX=2,$X=2,YX=KJ({service:"lsp.client"}),EY=wY(e0.Service,e0.layer);class TY extends Q.TaggedErrorClass()("LSPInitializeError",{serverID:Q.String,cause:Q.optional(Q.Defect)}){}var LY={Diagnostics:t0.define("lsp.client.diagnostics",Q.Struct({serverID:Q.String,path:Q.String}))};function v8(J){if(!J.startsWith("file://"))return;return P$.normalizePath(rV(J))}function ZX(J){if(!J)return;let $=J.textDocumentSync;if(typeof $==="number")return $;return $?.change}function VX(J){let $=J.split(/\r\n|\r|\n/);return{line:$.length-1,character:$.at(-1)?.length??0}}function MY(J){let $=new Set;return J.filter((Y)=>{let Z=JSON.stringify({code:Y.code,severity:Y.severity,message:Y.message,source:Y.source,range:Y.range});if($.has(Z))return!1;return $.add(Z),!0})}function XX(J,$){if(!$)return J??null;return $.split(".").reduce((Z,V)=>{if(!Z||typeof Z!=="object"||!(V in Z))return;return Z[V]},J)??null}function QX(J){return J==="typescript"}async function vY(J){let $=YX.clone().tag("serverID",J.serverID);$.info("starting client");let Y=J.instance,Z=U$.createMessageConnection(new U$.StreamMessageReader(J.server.process.stdout),new U$.StreamMessageWriter(J.server.process.stdin));J.server.process.stderr?.on("data",(N)=>{let I=N.toString().trim();if(I)$.debug("server stderr",{text:I.slice(0,1000)})});let V=new Map,X=new Map,U=new Map,F=new Map,K=new Set,G=(N)=>MY([...V.get(N)??[],...X.get(N)??[]]),W=(N,I)=>{V.set(N,I),EY.runPromise((w)=>w.publish(LY.Diagnostics,{path:N,serverID:J.serverID}).pipe(B.provideService(P8,Y)))},z=(N,I)=>{X.set(N,I)},A=()=>{for(let N of[...K])N()};Z.onNotification("textDocument/publishDiagnostics",(N)=>{let I=v8(N.uri);if(!I)return;if($.info("textDocument/publishDiagnostics",{path:I,count:N.diagnostics.length,version:N.version}),U.set(I,{at:Date.now(),version:typeof N.version==="number"?N.version:void 0}),QX(J.serverID)&&!V.has(I)){V.set(I,N.diagnostics);return}W(I,N.diagnostics)}),Z.onRequest("window/workDoneProgress/create",(N)=>{return $.info("window/workDoneProgress/create",N),null}),Z.onRequest("workspace/configuration",async(N)=>{return(N.items??[]).map((w)=>XX(J.server.initialization,w.section))}),Z.onRequest("client/registerCapability",async(N)=>{let I=N.registrations??[],w=!1;for(let v of I){if(v.method!=="textDocument/diagnostic")continue;F.set(v.id,v),w=!0}if(w)A()}),Z.onRequest("client/unregisterCapability",async(N)=>{let I=N.unregisterations??[],w=!1;for(let v of I){if(v.method!=="textDocument/diagnostic")continue;F.delete(v.id),w=!0}if(w)A()}),Z.onRequest("workspace/workspaceFolders",async()=>[{name:"workspace",uri:PJ(J.root).href}]),Z.onRequest("workspace/diagnostic/refresh",async()=>null),Z.listen(),$.info("sending initialize");let j=await O5(Z.sendRequest("initialize",{rootUri:PJ(J.root).href,processId:J.server.process.pid,workspaceFolders:[{name:"workspace",uri:PJ(J.root).href}],initializationOptions:{...J.server.initialization},capabilities:{window:{workDoneProgress:!0},workspace:{configuration:!0,didChangeWatchedFiles:{dynamicRegistration:!0},diagnostics:{refreshSupport:!1}},textDocument:{synchronization:{didOpen:!0,didChange:!0},diagnostic:{dynamicRegistration:!0,relatedDocumentSupport:!0},publishDiagnostics:{versionSupport:!1}}}}),tV).catch((N)=>{throw $.error("initialize error",{error:N}),new TY({serverID:J.serverID,cause:N})}),D=ZX(j.capabilities),O=Boolean(j.capabilities?.diagnosticProvider);if(await Z.sendNotification("initialized",{}),J.server.initialization)await Z.sendNotification("workspace/didChangeConfiguration",{settings:J.server.initialization});let P={},M=(N,I)=>{let w=I.some((g)=>g.handled),v=I.some((g)=>g.matched);if(!w)return{handled:!1,matched:!1};let S=new Map;for(let g of I)for(let[c,r]of g.byFile.entries()){let e=S.get(c)??[];S.set(c,e.concat(r))}if(v&&!S.has(N))S.set(N,[]);for(let[g,c]of S.entries())z(g,MY(c));return{handled:w,matched:v}};async function C(N,I){let w=await O5(Z.sendRequest("textDocument/diagnostic",{...I?{identifier:I}:{},textDocument:{uri:PJ(N).href}}),qY).catch(()=>null);if(!w)return{handled:!1,matched:!1,byFile:new Map};let v=new Map,S=(r,e)=>{let z0=v.get(r)??[];v.set(r,z0.concat(e))},g=!1,c=!1;if(Array.isArray(w.items))S(N,w.items),g=!0,c=!0;for(let[r,e]of Object.entries(w.relatedDocuments??{})){let z0=v8(r);if(!z0||!Array.isArray(e.items))continue;S(z0,e.items),g=!0,c=c||z0===N}return{handled:g,matched:c,byFile:v}}async function q(N,I){let w=await O5(Z.sendRequest("workspace/diagnostic",{...I?{identifier:I}:{},previousResultIds:[]}),qY).catch(()=>null);if(!w)return{handled:!1,matched:!1,byFile:new Map};let v=new Map,S=!1;for(let g of w.items??[]){let c=g.uri?v8(g.uri):void 0;if(!c||!Array.isArray(g.items))continue;let r=v.get(c)??[];v.set(c,r.concat(g.items)),S=S||c===N}return{handled:!0,matched:S,byFile:v}}function f(){let N=[...F.values()].filter((I)=>I.registerOptions?.workspaceDiagnostics!==!0);return{documentIdentifiers:[...new Set(N.flatMap((I)=>I.registerOptions?.identifier??[]))],supported:O||N.length>0}}function _(){let N=[...F.values()].filter((I)=>I.registerOptions?.workspaceDiagnostics===!0);return{workspaceIdentifiers:[...new Set(N.flatMap((I)=>I.registerOptions?.identifier??[]))],supported:N.length>0}}let y=(N,I)=>I.some((w)=>(w.byFile.get(N)?.length??0)>0);async function k(N,I,w){if(!I.length)return{handled:!1,matched:!1};let v=[];return new Promise((S)=>{let g=I.length,c=!1,r=(e,z0=!1)=>{if(c)return;if(!z0&&!w(v))return;c=!0,S(e)};for(let e of I)e.then((z0)=>{v.push(z0),g-=1;let l=M(N,v);if(r(l),g===0)r(l,!0)})})}async function n(N){let I=f();if(!I.supported)return{handled:!1,matched:!1};return k(N,[C(N),...I.documentIdentifiers.map((w)=>C(N,w))],(w)=>y(N,w))}async function d(N){let I=f(),w=_();if(!I.supported&&!w.supported)return{handled:!1,matched:!1};return M(N,await Promise.all([...I.supported?[C(N)]:[],...I.documentIdentifiers.map((v)=>C(N,v)),...w.supported?[q(N)]:[],...w.workspaceIdentifiers.map((v)=>q(N,v))]))}function X0(N){if(N<=0)return Promise.resolve(!1);return new Promise((I)=>{let w=!1,v,S=(c)=>{if(w)return;if(w=!0,v)clearTimeout(v);K.delete(g),I(c)},g=()=>S(!0);K.add(g),v=setTimeout(()=>S(!1),N)})}function o(N){if(N.timeout<=0)return Promise.resolve(!1);return new Promise((I)=>{let w=!1,v,S,g,c=(e)=>{if(w)return;if(w=!0,v)clearTimeout(v);if(S)clearTimeout(S);g?.(),I(e)},r=()=>{let e=U.get(N.path);if(!e)return;if(typeof e.version==="number"&&e.version!==N.version)return;if(e.at<N.after&&e.version!==N.version)return;if(v)clearTimeout(v);v=setTimeout(()=>c(!0),Math.max(0,sV-(Date.now()-e.at)))};S=setTimeout(()=>c(!1),N.timeout),g=EY.runSync((e)=>e.subscribeCallback(LY.Diagnostics,(z0)=>{if(z0.properties.path!==N.path||z0.properties.serverID!==J.serverID)return;r()}).pipe(B.provideService(P8,Y))),r()})}async function t(N){let I=N.after??Date.now(),w=o({path:N.path,version:N.version,after:I,timeout:w8});while(Date.now()-I<w8){if((await n(N.path)).matched)return;let S=w8-(Date.now()-I);if(S<=0)return;if(await Promise.race([w.then((c)=>c?"push":"timeout"),X0(S).then((c)=>c?"registration":"timeout")])!=="registration")return}}async function R(N){let I=N.after??Date.now(),w=o({path:N.path,version:N.version,after:I,timeout:T8});while(Date.now()-I<T8){let v=await d(N.path);if(v.handled||v.matched)return;let S=T8-(Date.now()-I);if(S<=0)return;if(await Promise.race([w.then((c)=>c?"push":"timeout"),X0(S).then((c)=>c?"registration":"timeout")])!=="registration")return}}let T={root:J.root,get serverID(){return J.serverID},get connection(){return Z},notify:{async open(N){N.path=P$.normalizePath(v$.isAbsolute(N.path)?N.path:v$.resolve(J.directory,N.path));let I=await P$.readText(N.path),w=v$.extname(N.path),v=_Y[w]??"plaintext",S=P[N.path];if(S!==void 0){$.info("workspace/didChangeWatchedFiles",N),await Z.sendNotification("workspace/didChangeWatchedFiles",{changes:[{uri:PJ(N.path).href,type:JX}]});let g=S.version+1;return P[N.path]={version:g,text:I},$.info("textDocument/didChange",{path:N.path,version:g}),await Z.sendNotification("textDocument/didChange",{textDocument:{uri:PJ(N.path).href,version:g},contentChanges:D===$X?[{range:{start:{line:0,character:0},end:VX(S.text)},text:I}]:[{text:I}]}),g}return $.info("workspace/didChangeWatchedFiles",N),await Z.sendNotification("workspace/didChangeWatchedFiles",{changes:[{uri:PJ(N.path).href,type:eV}]}),$.info("textDocument/didOpen",N),V.delete(N.path),X.delete(N.path),await Z.sendNotification("textDocument/didOpen",{textDocument:{uri:PJ(N.path).href,languageId:v,version:0,text:I}}),P[N.path]={version:0,text:I},0}},get diagnostics(){let N=new Map;for(let I of new Set([...V.keys(),...X.keys()]))N.set(I,G(I));return N},async waitForDiagnostics(N){let I=P$.normalizePath(v$.isAbsolute(N.path)?N.path:v$.resolve(J.directory,N.path));if($.info("waiting for diagnostics",{path:I,mode:N.mode??"full",version:N.version}),N.mode==="document"){await t({path:I,version:N.version,after:N.after});return}await R({path:I,version:N.version,after:N.after})},async shutdown(){$.info("shutting down"),Z.end(),Z.dispose(),await C$.stop(J.server.process),$.info("shutdown")}};return $.info("initialized"),T}import C8 from"path";import{pathToFileURL as K$,fileURLToPath as UX}from"url";var b$={};QJ(b$,{report:()=>FX,pretty:()=>bY,Diagnostic:()=>b$});var CY=20;function bY(J){let Y={1:"ERROR",2:"WARN",3:"INFO",4:"HINT"}[J.severity||1],Z=J.range.start.line+1,V=J.range.start.character+1;return`${Y} [${Z}:${V}] ${J.message}`}function FX(J,$){let Y=$.filter((U)=>U.severity===1);if(Y.length===0)return"";let Z=Y.slice(0,CY),V=Y.length-CY,X=V>0?`
|
|
40
|
+
... and ${V} more`:"";return`<diagnostics file="${J}">
|
|
41
|
+
${Z.map(bY).join(`
|
|
42
|
+
`)}${X}
|
|
43
|
+
</diagnostics>`}var IJ=KJ({service:"lsp"}),gY={Updated:t0.define("lsp.updated",Q.Struct({}))},fY=Q.Struct({line:a,character:a}),I5=Q.Struct({start:fY,end:fY}).annotate({identifier:"Range"}),KX=Q.Struct({name:Q.String,kind:a,location:Q.Struct({uri:Q.String,range:I5})}).annotate({identifier:"Symbol"}),GX=Q.Struct({name:Q.String,detail:Q.optional(Q.String),kind:a,range:I5,selectionRange:I5}).annotate({identifier:"DocumentSymbol"}),WX=Q.Struct({id:Q.String,name:Q.String,root:Q.String,status:Q.Literals(["connected","error"])}).annotate({identifier:"LSPStatus"});var zX=[5,12,6,11,13,14,23,10],HX=(J,$)=>{if($.experimentalLspTy){if(J.pyright)IJ.info("LSP server pyright is disabled because MUXCODE_EXPERIMENTAL_LSP_TY is enabled"),delete J.pyright}else if(J.ty)delete J.ty};class D5 extends n0.Service()("@muxcode/LSP"){}var hY=j0.effect(D5,B.gen(function*(){let J=yield*G$.Service,$=yield*RJ.Service,Y=yield*s.make(B.fn("LSP.state")(function*(_){let y=yield*J.get(),k={};if(!y.lsp)IJ.info("all LSPs are disabled");else{for(let d of Object.values(SY))k[d.id]=d;if(HX(k,$),y.lsp!==!0)for(let[d,X0]of Object.entries(y.lsp)){let o=k[d];if(X0.disabled){IJ.info(`LSP server ${d} is disabled`),delete k[d];continue}k[d]={...o,id:d,root:o?.root??(async(t,R)=>R.directory),extensions:X0.extensions??o?.extensions??[],spawn:async(t)=>({process:yY(X0.command[0],X0.command.slice(1),{cwd:t,env:{...process.env,...X0.env}}),initialization:X0.initialization})}}IJ.info("enabled LSP servers",{serverIds:Object.values(k).map((d)=>d.id).join(", ")})}let n={clients:[],servers:k,broken:new Set,spawning:new Map};return yield*B.addFinalizer(()=>B.promise(async()=>{await Promise.all(n.clients.map((d)=>d.shutdown()))})),n})),Z=B.fnUntraced(function*(_){let y=yield*s.context;if(!kY(_,y))return[];let k=yield*s.get(Y);return yield*B.promise(async()=>{let n=C8.parse(_).ext||_,d=[];async function X0(o,t,R){let T=await o.spawn(t,y,$).then((w)=>{if(!w)k.broken.add(R);return w}).catch((w)=>{k.broken.add(R),IJ.error(`Failed to spawn LSP server ${o.id}`,{error:w});return});if(!T)return;IJ.info("spawned lsp server",{serverID:o.id,root:t});let N=await vY({serverID:o.id,server:T,root:t,directory:y.directory,instance:y}).catch(async(w)=>{k.broken.add(R),await C$.stop(T.process),IJ.error(`Failed to initialize LSP client ${o.id}`,{error:w});return});if(!N)return;let I=k.clients.find((w)=>w.root===t&&w.serverID===o.id);if(I)return await C$.stop(T.process),I;return k.clients.push(N),N}for(let o of Object.values(k.servers)){if(o.extensions.length&&!o.extensions.includes(n))continue;let t=await o.root(_,y);if(!t)continue;if(k.broken.has(t+o.id))continue;let R=k.clients.find((w)=>w.root===t&&w.serverID===o.id);if(R){d.push(R);continue}let T=k.spawning.get(t+o.id);if(T){let w=await T;if(!w)continue;d.push(w);continue}let N=X0(o,t,t+o.id);k.spawning.set(t+o.id,N),N.finally(()=>{if(k.spawning.get(t+o.id)===N)k.spawning.delete(t+o.id)});let I=await N;if(!I)continue;d.push(I),await e0.publish(y,gY.Updated,{})}return d})}),V=B.fnUntraced(function*(_,y){let k=yield*Z(_);return yield*B.promise(()=>Promise.all(k.map((n)=>y(n))))}),X=B.fnUntraced(function*(_){let y=yield*s.get(Y);return yield*B.promise(()=>Promise.all(y.clients.map((k)=>_(k))))}),U=B.fn("LSP.init")(function*(){yield*s.get(Y)}),F=B.fn("LSP.status")(function*(){let _=yield*s.context,y=yield*s.get(Y),k=[];for(let n of y.clients)k.push({id:n.serverID,name:y.servers[n.serverID].id,root:C8.relative(_.directory,n.root),status:"connected"});return k}),K=B.fn("LSP.hasClients")(function*(_){let y=yield*s.context,k=yield*s.get(Y);return yield*B.promise(async()=>{let n=C8.parse(_).ext||_;for(let d of Object.values(k.servers)){if(d.extensions.length&&!d.extensions.includes(n))continue;let X0=await d.root(_,y);if(!X0)continue;if(k.broken.has(X0+d.id))continue;return!0}return!1})}),G=B.fn("LSP.touchFile")(function*(_,y){IJ.info("touching file",{file:_});let k=yield*Z(_);yield*B.promise(()=>Promise.all(k.map(async(n)=>{let d=Date.now(),X0=await n.notify.open({path:_});if(!y)return;return n.waitForDiagnostics({path:_,version:X0,mode:y,after:d})})).catch((n)=>{IJ.error("failed to touch file",{err:n,file:_})}))}),W=B.fn("LSP.diagnostics")(function*(){let _={},y=yield*X(async(k)=>k.diagnostics);for(let k of y)for(let[n,d]of k.entries()){let X0=_[n]||[];X0.push(...d),_[n]=X0}return _}),z=B.fn("LSP.hover")(function*(_){return yield*V(_.file,(y)=>y.connection.sendRequest("textDocument/hover",{textDocument:{uri:K$(_.file).href},position:{line:_.line,character:_.character}}).catch(()=>null))}),A=B.fn("LSP.definition")(function*(_){return(yield*V(_.file,(k)=>k.connection.sendRequest("textDocument/definition",{textDocument:{uri:K$(_.file).href},position:{line:_.line,character:_.character}}).catch(()=>null))).flat().filter(Boolean)}),j=B.fn("LSP.references")(function*(_){return(yield*V(_.file,(k)=>k.connection.sendRequest("textDocument/references",{textDocument:{uri:K$(_.file).href},position:{line:_.line,character:_.character},context:{includeDeclaration:!0}}).catch(()=>[]))).flat().filter(Boolean)}),D=B.fn("LSP.implementation")(function*(_){return(yield*V(_.file,(k)=>k.connection.sendRequest("textDocument/implementation",{textDocument:{uri:K$(_.file).href},position:{line:_.line,character:_.character}}).catch(()=>null))).flat().filter(Boolean)}),O=B.fn("LSP.documentSymbol")(function*(_){let y=UX(_);return(yield*V(y,(n)=>n.connection.sendRequest("textDocument/documentSymbol",{textDocument:{uri:_}}).catch(()=>[]))).flat().filter(Boolean)}),P=B.fn("LSP.workspaceSymbol")(function*(_){return(yield*X((k)=>k.connection.sendRequest("workspace/symbol",{query:_}).then((n)=>n.filter((d)=>zX.includes(d.kind)).slice(0,10)).catch(()=>[]))).flat()}),M=B.fn("LSP.prepareCallHierarchy")(function*(_){return(yield*V(_.file,(k)=>k.connection.sendRequest("textDocument/prepareCallHierarchy",{textDocument:{uri:K$(_.file).href},position:{line:_.line,character:_.character}}).catch(()=>[]))).flat().filter(Boolean)}),C=B.fnUntraced(function*(_,y){return(yield*V(_.file,async(n)=>{let d=await n.connection.sendRequest("textDocument/prepareCallHierarchy",{textDocument:{uri:K$(_.file).href},position:{line:_.line,character:_.character}}).catch(()=>[]);if(!d?.length)return[];return n.connection.sendRequest(y,{item:d[0]}).catch(()=>[])})).flat().filter(Boolean)}),q=B.fn("LSP.incomingCalls")(function*(_){return yield*C(_,"callHierarchy/incomingCalls")}),f=B.fn("LSP.outgoingCalls")(function*(_){return yield*C(_,"callHierarchy/outgoingCalls")});return D5.of({init:U,status:F,hasClients:K,touchFile:G,diagnostics:W,hover:z,definition:A,references:j,implementation:D,documentSymbol:O,workspaceSymbol:P,prepareCallHierarchy:M,incomingCalls:q,outgoingCalls:f})})),jX=hY.pipe(j0.provide(G$.defaultLayer),j0.provide(RJ.defaultLayer));var bJ={};QJ(bJ,{layer:()=>aY,defaultLayer:()=>qX,Snapshot:()=>bJ,Service:()=>E5,Patch:()=>IX,FileDiff:()=>DX});class _5{diff(J,$,Y={}){let Z;if(typeof Y==="function")Z=Y,Y={};else if("callback"in Y)Z=Y.callback;let V=this.castInput(J,Y),X=this.castInput($,Y),U=this.removeEmpty(this.tokenize(V,Y)),F=this.removeEmpty(this.tokenize(X,Y));return this.diffWithOptionsObj(U,F,Y,Z)}diffWithOptionsObj(J,$,Y,Z){var V;let X=(M)=>{if(M=this.postProcess(M,Y),Z){setTimeout(function(){Z(M)},0);return}else return M},U=$.length,F=J.length,K=1,G=U+F;if(Y.maxEditLength!=null)G=Math.min(G,Y.maxEditLength);let W=(V=Y.timeout)!==null&&V!==void 0?V:1/0,z=Date.now()+W,A=[{oldPos:-1,lastComponent:void 0}],j=this.extractCommon(A[0],$,J,0,Y);if(A[0].oldPos+1>=F&&j+1>=U)return X(this.buildValues(A[0].lastComponent,$,J));let D=-1/0,O=1/0,P=()=>{for(let M=Math.max(D,-K);M<=Math.min(O,K);M+=2){let C,q=A[M-1],f=A[M+1];if(q)A[M-1]=void 0;let _=!1;if(f){let k=f.oldPos-M;_=f&&0<=k&&k<U}let y=q&&q.oldPos+1<F;if(!_&&!y){A[M]=void 0;continue}if(!y||_&&q.oldPos<f.oldPos)C=this.addToPath(f,!0,!1,0,Y);else C=this.addToPath(q,!1,!0,1,Y);if(j=this.extractCommon(C,$,J,M,Y),C.oldPos+1>=F&&j+1>=U)return X(this.buildValues(C.lastComponent,$,J))||!0;else{if(A[M]=C,C.oldPos+1>=F)O=Math.min(O,M-1);if(j+1>=U)D=Math.max(D,M+1)}}K++};if(Z)(function M(){setTimeout(function(){if(K>G||Date.now()>z)return Z(void 0);if(!P())M()},0)})();else while(K<=G&&Date.now()<=z){let M=P();if(M)return M}}addToPath(J,$,Y,Z,V){let X=J.lastComponent;if(X&&!V.oneChangePerToken&&X.added===$&&X.removed===Y)return{oldPos:J.oldPos+Z,lastComponent:{count:X.count+1,added:$,removed:Y,previousComponent:X.previousComponent}};else return{oldPos:J.oldPos+Z,lastComponent:{count:1,added:$,removed:Y,previousComponent:X}}}extractCommon(J,$,Y,Z,V){let X=$.length,U=Y.length,F=J.oldPos,K=F-Z,G=0;while(K+1<X&&F+1<U&&this.equals(Y[F+1],$[K+1],V))if(K++,F++,G++,V.oneChangePerToken)J.lastComponent={count:1,previousComponent:J.lastComponent,added:!1,removed:!1};if(G&&!V.oneChangePerToken)J.lastComponent={count:G,previousComponent:J.lastComponent,added:!1,removed:!1};return J.oldPos=F,K}equals(J,$,Y){if(Y.comparator)return Y.comparator(J,$);else return J===$||!!Y.ignoreCase&&J.toLowerCase()===$.toLowerCase()}removeEmpty(J){let $=[];for(let Y=0;Y<J.length;Y++)if(J[Y])$.push(J[Y]);return $}castInput(J,$){return J}tokenize(J,$){return Array.from(J)}join(J){return J.join("")}postProcess(J,$){return J}get useLongestToken(){return!1}buildValues(J,$,Y){let Z=[],V;while(J)Z.push(J),V=J.previousComponent,delete J.previousComponent,J=V;Z.reverse();let X=Z.length,U=0,F=0,K=0;for(;U<X;U++){let G=Z[U];if(!G.removed){if(!G.added&&this.useLongestToken){let W=$.slice(F,F+G.count);W=W.map(function(z,A){let j=Y[K+A];return j.length>z.length?j:z}),G.value=this.join(W)}else G.value=this.join($.slice(F,F+G.count));if(F+=G.count,!G.added)K+=G.count}else G.value=this.join(Y.slice(K,K+G.count)),K+=G.count}return Z}}class uY extends _5{constructor(){super(...arguments);this.tokenize=BX}equals(J,$,Y){if(Y.ignoreWhitespace){if(!Y.newlineIsToken||!J.includes(`
|
|
44
|
+
`))J=J.trim();if(!Y.newlineIsToken||!$.includes(`
|
|
45
|
+
`))$=$.trim()}else if(Y.ignoreNewlineAtEof&&!Y.newlineIsToken){if(J.endsWith(`
|
|
46
|
+
`))J=J.slice(0,-1);if($.endsWith(`
|
|
47
|
+
`))$=$.slice(0,-1)}return super.equals(J,$,Y)}}var lY=new uY;function q5(J,$,Y){return lY.diff(J,$,Y)}function BX(J,$){if($.stripTrailingCr)J=J.replace(/\r\n/g,`
|
|
48
|
+
`);let Y=[],Z=J.split(/(\n|\r\n)/);if(!Z[Z.length-1])Z.pop();for(let V=0;V<Z.length;V++){let X=Z[V];if(V%2&&!$.newlineIsToken)Y[Y.length-1]+=X;else Y.push(X)}return Y}function xY(J){return J.includes(`\r
|
|
49
|
+
`)&&!J.startsWith(`
|
|
50
|
+
`)&&!J.match(/[^\r]\n/)}function cY(J){return!J.includes(`\r
|
|
51
|
+
`)&&J.includes(`
|
|
52
|
+
`)}function b8(J){if(Array.isArray(J))return J.map(($)=>b8($));return Object.assign(Object.assign({},J),{hunks:J.hunks.map(($)=>Object.assign(Object.assign({},$),{lines:$.lines.map((Y,Z)=>{var V;return Y.startsWith("\\")||Y.endsWith("\r")||((V=$.lines[Z+1])===null||V===void 0?void 0:V.startsWith("\\"))?Y:Y+"\r"})}))})}function f8(J){if(Array.isArray(J))return J.map(($)=>f8($));return Object.assign(Object.assign({},J),{hunks:J.hunks.map(($)=>Object.assign(Object.assign({},$),{lines:$.lines.map((Y)=>Y.endsWith("\r")?Y.substring(0,Y.length-1):Y)}))})}function pY(J){if(!Array.isArray(J))J=[J];return!J.some(($)=>$.hunks.some((Y)=>Y.lines.some((Z)=>!Z.startsWith("\\")&&Z.endsWith("\r"))))}function dY(J){if(!Array.isArray(J))J=[J];return J.some(($)=>$.hunks.some((Y)=>Y.lines.some((Z)=>Z.endsWith("\r"))))&&J.every(($)=>$.hunks.every((Y)=>Y.lines.every((Z,V)=>{var X;return Z.startsWith("\\")||Z.endsWith("\r")||((X=Y.lines[V+1])===null||X===void 0?void 0:X.startsWith("\\"))})))}function k8(J){let $=J.split(/\n/),Y=[],Z=0;function V(){let F={};Y.push(F);while(Z<$.length){let K=$[Z];if(/^(---|\+\+\+|@@)\s/.test(K))break;let G=/^(?:Index:|diff(?: -r \w+)+)\s+(.+?)\s*$/.exec(K);if(G)F.index=G[1];Z++}X(F),X(F),F.hunks=[];while(Z<$.length){let K=$[Z];if(/^(Index:\s|diff\s|---\s|\+\+\+\s|===================================================================)/.test(K))break;else if(/^@@/.test(K))F.hunks.push(U());else if(K)throw Error("Unknown line "+(Z+1)+" "+JSON.stringify(K));else Z++}}function X(F){let K=/^(---|\+\+\+)\s+(.*)\r?$/.exec($[Z]);if(K){let G=K[2].split("\t",2),W=(G[1]||"").trim(),z=G[0].replace(/\\\\/g,"\\");if(/^".*"$/.test(z))z=z.substr(1,z.length-2);if(K[1]==="---")F.oldFileName=z,F.oldHeader=W;else F.newFileName=z,F.newHeader=W;Z++}}function U(){var F;let K=Z,G=$[Z++],W=G.split(/@@ -(\d+)(?:,(\d+))? \+(\d+)(?:,(\d+))? @@/),z={oldStart:+W[1],oldLines:typeof W[2]>"u"?1:+W[2],newStart:+W[3],newLines:typeof W[4]>"u"?1:+W[4],lines:[]};if(z.oldLines===0)z.oldStart+=1;if(z.newLines===0)z.newStart+=1;let A=0,j=0;for(;Z<$.length&&(j<z.oldLines||A<z.newLines||((F=$[Z])===null||F===void 0?void 0:F.startsWith("\\")));Z++){let D=$[Z].length==0&&Z!=$.length-1?" ":$[Z][0];if(D==="+"||D==="-"||D===" "||D==="\\"){if(z.lines.push($[Z]),D==="+")A++;else if(D==="-")j++;else if(D===" ")A++,j++}else throw Error(`Hunk at line ${K+1} contained invalid line ${$[Z]}`)}if(!A&&z.newLines===1)z.newLines=0;if(!j&&z.oldLines===1)z.oldLines=0;if(A!==z.newLines)throw Error("Added line count did not match for hunk at line "+(K+1));if(j!==z.oldLines)throw Error("Removed line count did not match for hunk at line "+(K+1));return z}while(Z<$.length)V();return Y}function y8(J,$,Y){let Z=!0,V=!1,X=!1,U=1;return function F(){if(Z&&!X){if(V)U++;else Z=!1;if(J+U<=Y)return J+U;X=!0}if(!V){if(!X)Z=!0;if($<=J-U)return J-U++;return V=!0,F()}return}}function NX(J,$,Y={}){let Z;if(typeof $==="string")Z=k8($);else if(Array.isArray($))Z=$;else Z=[$];if(Z.length>1)throw Error("applyPatch only works with a single input.");return AX(J,Z[0],Y)}function AX(J,$,Y={}){if(Y.autoConvertLineEndings||Y.autoConvertLineEndings==null){if(xY(J)&&pY($))$=b8($);else if(cY(J)&&dY($))$=f8($)}let Z=J.split(`
|
|
53
|
+
`),V=$.hunks,X=Y.compareLine||((D,O,P,M)=>O===M),U=Y.fuzzFactor||0,F=0;if(U<0||!Number.isInteger(U))throw Error("fuzzFactor must be a non-negative integer");if(!V.length)return J;let K="",G=!1,W=!1;for(let D=0;D<V[V.length-1].lines.length;D++){let O=V[V.length-1].lines[D];if(O[0]=="\\"){if(K[0]=="+")G=!0;else if(K[0]=="-")W=!0}K=O}if(G){if(W){if(!U&&Z[Z.length-1]=="")return!1}else if(Z[Z.length-1]=="")Z.pop();else if(!U)return!1}else if(W){if(Z[Z.length-1]!="")Z.push("");else if(!U)return!1}function z(D,O,P,M=0,C=!0,q=[],f=0){let _=0,y=!1;for(;M<D.length;M++){let k=D[M],n=k.length>0?k[0]:" ",d=k.length>0?k.substr(1):k;if(n==="-")if(X(O+1,Z[O],n,d))O++,_=0;else{if(!P||Z[O]==null)return null;return q[f]=Z[O],z(D,O+1,P-1,M,!1,q,f+1)}if(n==="+"){if(!C)return null;q[f]=d,f++,_=0,y=!0}if(n===" ")if(_++,q[f]=Z[O],X(O+1,Z[O],n,d))f++,C=!0,y=!1,O++;else{if(y||!P)return null;return Z[O]&&(z(D,O+1,P-1,M+1,!1,q,f+1)||z(D,O+1,P-1,M,!1,q,f+1))||z(D,O,P-1,M+1,!1,q,f)}}return f-=_,O-=_,q.length=f,{patchedLines:q,oldLineLastI:O-1}}let A=[],j=0;for(let D=0;D<V.length;D++){let O=V[D],P,M=Z.length-O.oldLines+U,C;for(let q=0;q<=U;q++){C=O.oldStart+j-1;let f=y8(C,F,M);for(;C!==void 0;C=f())if(P=z(O.lines,C,q),P)break;if(P)break}if(!P)return!1;for(let q=F;q<C;q++)A.push(Z[q]);for(let q=0;q<P.patchedLines.length;q++){let f=P.patchedLines[q];A.push(f)}F=P.oldLineLastI+1,j=C+1-O.oldStart}for(let D=F;D<Z.length;D++)A.push(Z[D]);return A.join(`
|
|
54
|
+
`)}function k$(J,$,Y,Z,V,X,U){let F;if(!U)F={};else if(typeof U==="function")F={callback:U};else F=U;if(typeof F.context>"u")F.context=4;let K=F.context;if(F.newlineIsToken)throw Error("newlineIsToken may not be used with patch-generation functions, only with diffing functions");if(!F.callback)return G(q5(Y,Z,F));else{let{callback:W}=F;q5(Y,Z,Object.assign(Object.assign({},F),{callback:(z)=>{let A=G(z);W(A)}}))}function G(W){if(!W)return;W.push({value:"",lines:[]});function z(C){return C.map(function(q){return" "+q})}let A=[],j=0,D=0,O=[],P=1,M=1;for(let C=0;C<W.length;C++){let q=W[C],f=q.lines||OX(q.value);if(q.lines=f,q.added||q.removed){if(!j){let _=W[C-1];if(j=P,D=M,_)O=K>0?z(_.lines.slice(-K)):[],j-=O.length,D-=O.length}for(let _ of f)O.push((q.added?"+":"-")+_);if(q.added)M+=f.length;else P+=f.length}else{if(j)if(f.length<=K*2&&C<W.length-2)for(let _ of z(f))O.push(_);else{let _=Math.min(f.length,K);for(let k of z(f.slice(0,_)))O.push(k);let y={oldStart:j,oldLines:P-j+_,newStart:D,newLines:M-D+_,lines:O};A.push(y),j=0,D=0,O=[]}P+=f.length,M+=f.length}}for(let C of A)for(let q=0;q<C.lines.length;q++)if(C.lines[q].endsWith(`
|
|
55
|
+
`))C.lines[q]=C.lines[q].slice(0,-1);else C.lines.splice(q+1,0,"\"),q++;return{oldFileName:J,newFileName:$,oldHeader:V,newHeader:X,hunks:A}}}function W$(J){if(Array.isArray(J))return J.map(W$).join(`
|
|
56
|
+
`);let $=[];if(J.oldFileName==J.newFileName)$.push("Index: "+J.oldFileName);$.push("==================================================================="),$.push("--- "+J.oldFileName+(typeof J.oldHeader>"u"?"":"\t"+J.oldHeader)),$.push("+++ "+J.newFileName+(typeof J.newHeader>"u"?"":"\t"+J.newHeader));for(let Y=0;Y<J.hunks.length;Y++){let Z=J.hunks[Y];if(Z.oldLines===0)Z.oldStart-=1;if(Z.newLines===0)Z.newStart-=1;$.push("@@ -"+Z.oldStart+","+Z.oldLines+" +"+Z.newStart+","+Z.newLines+" @@");for(let V of Z.lines)$.push(V)}return $.join(`
|
|
57
|
+
`)+`
|
|
58
|
+
`}function RX(J,$,Y,Z,V,X,U){if(typeof U==="function")U={callback:U};if(!(U===null||U===void 0?void 0:U.callback)){let F=k$(J,$,Y,Z,V,X,U);if(!F)return;return W$(F)}else{let{callback:F}=U;k$(J,$,Y,Z,V,X,Object.assign(Object.assign({},U),{callback:(K)=>{if(!K)F(void 0);else F(W$(K))}}))}}function OX(J){let $=J.endsWith(`
|
|
59
|
+
`),Y=J.split(`
|
|
60
|
+
`).map((Z)=>Z+`
|
|
61
|
+
`);if($)Y.pop();else Y.push(Y.pop().slice(0,-1));return Y}import gJ from"path";var IX=Q.Struct({hash:Q.String,files:Q.mutable(Q.Array(Q.String))}),DX=Q.Struct({file:Q.optional(Q.String),patch:Q.optional(Q.String),additions:Q.Finite,deletions:Q.Finite,status:Q.optional(Q.Literals(["added","deleted","modified"]))}).annotate({identifier:"SnapshotFileDiff"}),D0=KJ({service:"snapshot"}),mY="7.days",_X=2097152,uJ=["-c","core.longpaths=true","-c","core.symlinks=true"],CJ=["-c","core.autocrlf=false",...uJ],hJ=[...CJ,"-c","core.quotepath=false"];class E5 extends n0.Service()("@muxcode/Snapshot"){}var aY=j0.effect(E5,B.gen(function*(){let J=yield*sJ.Service,$=yield*u8.Service,Y=yield*G$.Service,Z=new Map,V=(U)=>{let F=Z.get(U);if(F)return F;let K=iY.makeUnsafe(1);return Z.set(U,K),K},X=yield*s.make(B.fn("Snapshot.state")(function*(U){let F={directory:U.directory,worktree:U.worktree,gitdir:gJ.join(rJ.Path.data,"snapshot",U.project.id,oY.fast(U.worktree)),vcs:U.project.vcs},K=(R)=>["--git-dir",F.gitdir,"--work-tree",F.worktree,...R],G=(R)=>R.join("\x00")+"\x00",W=B.fnUntraced(function*(R,T){let N=yield*$.run(h8.make("git",R,{cwd:T?.cwd,env:T?.env,extendEnv:!0}),{stdin:T?.stdin});return{code:g8.ExitCode(N.exitCode),text:N.stdout.toString("utf8"),stderr:N.stderr.toString("utf8")}},B.catch((R)=>B.succeed({code:g8.ExitCode(1),text:"",stderr:R instanceof Error?R.message:String(R)}))),z=B.fnUntraced(function*(R){if(!R.length)return new Set;let T=yield*W([...hJ,"--git-dir",gJ.join(F.worktree,".git"),"--work-tree",F.worktree,"check-ignore","--no-index","--stdin","-z"],{cwd:F.directory,stdin:G(R)});if(T.code!==0&&T.code!==1)return new Set;return new Set(T.text.split("\x00").filter(Boolean))}),A=B.fnUntraced(function*(R){if(!R.length)return;yield*W([...CJ,...K(["rm","--cached","-f","--ignore-unmatch","--pathspec-from-file=-","--pathspec-file-nul"])],{cwd:F.directory,stdin:G(R)})}),j=B.fnUntraced(function*(R){if(!R.length)return;let T=yield*W([...CJ,...K(["add","--all","--sparse","--pathspec-from-file=-","--pathspec-file-nul"])],{cwd:F.directory,stdin:G(R)});if(T.code===0)return;D0.warn("failed to add snapshot files",{exitCode:T.code,stderr:T.stderr})}),D=(R)=>J.exists(R).pipe(B.orDie),O=(R)=>J.readFileString(R).pipe(B.catch(()=>B.succeed(""))),P=(R)=>J.remove(R).pipe(B.catch(()=>B.void)),M=(R)=>V(F.gitdir).withPermits(1)(R),C=B.fnUntraced(function*(){if(F.vcs!=="git")return!1;return(yield*Y.get()).snapshot!==!1}),q=B.fnUntraced(function*(){let T=(yield*W(["rev-parse","--path-format=absolute","--git-path","info/exclude"],{cwd:F.worktree})).text.trim();if(!T)return;if(!(yield*D(T)))return;return T}),f=B.fnUntraced(function*(R=[]){let T=yield*q(),N=gJ.join(F.gitdir,"info","exclude"),I=[T?(yield*O(T)).trimEnd():"",...R.map((w)=>`/${w.replaceAll("\\","/")}`)].filter(Boolean).join(`
|
|
62
|
+
`);yield*J.ensureDir(gJ.join(F.gitdir,"info")).pipe(B.orDie),yield*J.writeFileString(N,I?`${I}
|
|
63
|
+
`:"").pipe(B.orDie)}),_=B.fnUntraced(function*(){yield*f();let[R,T]=yield*B.all([W([...hJ,...K(["diff-files","--name-only","-z","--","."])],{cwd:F.directory}),W([...hJ,...K(["ls-files","--others","--exclude-standard","-z","--","."])],{cwd:F.directory})],{concurrency:2});if(R.code!==0||T.code!==0){D0.warn("failed to list snapshot files",{diffCode:R.code,diffStderr:R.stderr,otherCode:T.code,otherStderr:T.stderr});return}let N=R.text.split("\x00").filter(Boolean),I=T.text.split("\x00").filter(Boolean),w=Array.from(new Set([...N,...I]));if(!w.length)return;let v=yield*z(w);if(v.size>0){let r=Array.from(v);D0.info("removing gitignored files from snapshot",{count:r.length}),yield*A(r)}let S=w.filter((r)=>!v.has(r));if(!S.length)return;let g=new Set((yield*B.all(S.map((r)=>J.stat(gJ.join(F.directory,r)).pipe(B.catch(()=>B.void)).pipe(B.map((e)=>{if(!e||e.type!=="File")return;return(typeof e.size==="bigint"?Number(e.size):e.size)>_X?r:void 0}))),{concurrency:8})).filter((r)=>Boolean(r))),c=new Set(I.filter((r)=>g.has(r)));yield*f(Array.from(c)),yield*j(S.filter((r)=>!c.has(r)))}),y=B.fnUntraced(function*(){return yield*M(B.gen(function*(){if(!(yield*C()))return;if(!(yield*D(F.gitdir)))return;let R=yield*W(K(["gc",`--prune=${mY}`]),{cwd:F.directory});if(R.code!==0){D0.warn("cleanup failed",{exitCode:R.code,stderr:R.stderr});return}D0.info("cleanup",{prune:mY})}))}),k=B.fnUntraced(function*(){return yield*M(B.gen(function*(){if(!(yield*C()))return;let R=yield*D(F.gitdir);if(yield*J.ensureDir(F.gitdir).pipe(B.orDie),!R)yield*W(["init"],{env:{GIT_DIR:F.gitdir,GIT_WORK_TREE:F.worktree}}),yield*W(["--git-dir",F.gitdir,"config","core.autocrlf","false"]),yield*W(["--git-dir",F.gitdir,"config","core.longpaths","true"]),yield*W(["--git-dir",F.gitdir,"config","core.symlinks","true"]),yield*W(["--git-dir",F.gitdir,"config","core.fsmonitor","false"]),D0.info("initialized");yield*_();let N=(yield*W(K(["write-tree"]),{cwd:F.directory})).text.trim();return D0.info("tracking",{hash:N,cwd:F.directory,git:F.gitdir}),N}))}),n=B.fnUntraced(function*(R){return yield*M(B.gen(function*(){yield*_();let T=yield*W([...hJ,...K(["diff","--cached","--no-ext-diff","--name-only",R,"--","."])],{cwd:F.directory});if(T.code!==0)return D0.warn("failed to get diff",{hash:R,exitCode:T.code}),{hash:R,files:[]};let N=T.text.trim().split(`
|
|
64
|
+
`).map((w)=>w.trim()).filter(Boolean),I=yield*z(N);return{hash:R,files:N.filter((w)=>!I.has(w)).map((w)=>gJ.join(F.worktree,w).replaceAll("\\","/"))}}))}),d=B.fnUntraced(function*(R){return yield*M(B.gen(function*(){D0.info("restore",{commit:R});let T=yield*W([...uJ,...K(["read-tree",R])],{cwd:F.worktree});if(T.code===0){let N=yield*W([...uJ,...K(["checkout-index","-a","-f"])],{cwd:F.worktree});if(N.code===0)return;D0.error("failed to restore snapshot",{snapshot:R,exitCode:N.code,stderr:N.stderr});return}D0.error("failed to restore snapshot",{snapshot:R,exitCode:T.code,stderr:T.stderr})}))}),X0=B.fnUntraced(function*(R){return yield*M(B.gen(function*(){let T=[],N=new Set;for(let v of R)for(let S of v.files){if(N.has(S))continue;N.add(S),T.push({hash:v.hash,file:S,rel:gJ.relative(F.worktree,S).replaceAll("\\","/")})}let I=B.fnUntraced(function*(v){if(D0.info("reverting",{file:v.file,hash:v.hash}),(yield*W([...uJ,...K(["checkout",v.hash,"--",v.file])],{cwd:F.worktree})).code===0)return;let g=yield*W([...uJ,...K(["ls-tree",v.hash,"--",v.rel])],{cwd:F.worktree});if(g.code===0&&g.text.trim()){D0.info("file existed in snapshot but checkout failed, keeping",{file:v.file,hash:v.hash});return}D0.info("file did not exist in snapshot, deleting",{file:v.file,hash:v.hash}),yield*P(v.file)}),w=(v,S)=>v===S||v.startsWith(`${S}/`)||S.startsWith(`${v}/`);for(let v=0;v<T.length;){let S=T[v],g=[S],c=v+1;while(c<T.length&&g.length<100){let l=T[c];if(l.hash!==S.hash)break;if(g.some((J0)=>w(J0.rel,l.rel)))break;g.push(l),c+=1}if(g.length===1){yield*I(S),v=c;continue}let r=yield*W([...uJ,...K(["ls-tree","--name-only",S.hash,"--",...g.map((l)=>l.rel)])],{cwd:F.worktree});if(r.code!==0){D0.info("batched ls-tree failed, falling back to single-file revert",{hash:S.hash,files:g.length});for(let l of g)yield*I(l);v=c;continue}let e=new Set(r.text.trim().split(`
|
|
65
|
+
`).map((l)=>l.trim()).filter(Boolean)),z0=g.filter((l)=>e.has(l.rel));if(z0.length){if(D0.info("reverting",{hash:S.hash,files:z0.length}),(yield*W([...uJ,...K(["checkout",S.hash,"--",...z0.map((J0)=>J0.file)])],{cwd:F.worktree})).code!==0){D0.info("batched checkout failed, falling back to single-file revert",{hash:S.hash,files:z0.length});for(let J0 of g)yield*I(J0);v=c;continue}}for(let l of g){if(e.has(l.rel))continue;D0.info("file did not exist in snapshot, deleting",{file:l.file,hash:l.hash}),yield*P(l.file)}v=c}}))}),o=B.fnUntraced(function*(R){return yield*M(B.gen(function*(){yield*_();let T=yield*W([...hJ,...K(["diff","--cached","--no-ext-diff",R,"--","."])],{cwd:F.worktree});if(T.code!==0)return D0.warn("failed to get diff",{hash:R,exitCode:T.code,stderr:T.stderr}),"";return T.text.trim()}))}),t=B.fnUntraced(function*(R,T){return yield*M(B.gen(function*(){let N=B.fnUntraced(function*(l){if(l.binary)return["",""];if(l.status==="added")return["",yield*W([...CJ,...K(["show",`${T}:${l.file}`])]).pipe(B.map((J0)=>J0.text))];if(l.status==="deleted")return[yield*W([...CJ,...K(["show",`${R}:${l.file}`])]).pipe(B.map((J0)=>J0.text)),""];return yield*B.all([W([...CJ,...K(["show",`${R}:${l.file}`])]).pipe(B.map((J0)=>J0.text)),W([...CJ,...K(["show",`${T}:${l.file}`])]).pipe(B.map((J0)=>J0.text))],{concurrency:2})}),I=B.fnUntraced(function*(l){let J0=l.flatMap((A0)=>{if(A0.binary)return[];if(A0.status==="added")return[{file:A0.file,side:"after",ref:`${T}:${A0.file}`}];if(A0.status==="deleted")return[{file:A0.file,side:"before",ref:`${R}:${A0.file}`}];return[{file:A0.file,side:"before",ref:`${R}:${A0.file}`},{file:A0.file,side:"after",ref:`${T}:${A0.file}`}]});if(!J0.length)return new Map;let P0=yield*$.run(h8.make("git",[...CJ,...K(["cat-file","--batch"])],{cwd:F.directory,extendEnv:!0}),{stdin:J0.map((A0)=>A0.ref).join(`
|
|
66
|
+
`)+`
|
|
67
|
+
`});if(P0.exitCode!==0){D0.info("git cat-file --batch failed during snapshot diff, falling back to per-file git show",{stderr:P0.stderr.toString("utf8"),refs:J0.length});return}let B0=P0.stdout,x0=(A0,ZJ)=>{D0.info(A0,{...ZJ,refs:J0.length});return},a0=new Map,zJ=new TextDecoder,w0=0;for(let A0 of J0){let ZJ=w0;while(ZJ<B0.length&&B0[ZJ]!==10)ZJ+=1;if(ZJ>=B0.length)return x0("git cat-file --batch returned a truncated header during snapshot diff, falling back to per-file git show");let HJ=zJ.decode(B0.slice(w0,ZJ));w0=ZJ+1;let cJ=a0.get(A0.file)??{before:"",after:""};if(HJ.endsWith(" missing")){a0.set(A0.file,cJ);continue}let pJ=HJ.match(/^[0-9a-f]+ blob (\d+)$/);if(!pJ)return x0("git cat-file --batch returned an unexpected header during snapshot diff, falling back to per-file git show",{head:HJ});let _J=Number(pJ[1]);if(!Number.isInteger(_J)||_J<0||w0+_J>=B0.length||B0[w0+_J]!==10)return x0("git cat-file --batch returned truncated content during snapshot diff, falling back to per-file git show",{head:HJ});let jJ=zJ.decode(B0.slice(w0,w0+_J));if(A0.side==="before")cJ.before=jJ;if(A0.side==="after")cJ.after=jJ;a0.set(A0.file,cJ),w0+=_J+1}if(w0!==B0.length)return x0("git cat-file --batch returned trailing data during snapshot diff, falling back to per-file git show");return a0},B.scoped,B.catch(()=>B.succeed(void 0))),w=[],v=new Map,S=yield*W([...hJ,...K(["diff","--no-ext-diff","--name-status","--no-renames",R,T,"--","."])],{cwd:F.directory});for(let l of S.text.trim().split(`
|
|
68
|
+
`)){if(!l)continue;let[J0,P0]=l.split("\t");if(!J0||!P0)continue;v.set(P0,J0.startsWith("A")?"added":J0.startsWith("D")?"deleted":"modified")}let c=(yield*W([...hJ,...K(["diff","--no-ext-diff","--no-renames","--numstat",R,T,"--","."])],{cwd:F.directory})).text.trim().split(`
|
|
69
|
+
`).filter(Boolean).flatMap((l)=>{let[J0,P0,B0]=l.split("\t");if(!B0)return[];let x0=J0==="-"&&P0==="-",a0=x0?0:parseInt(J0),zJ=x0?0:parseInt(P0);return[{file:B0,status:v.get(B0)??"modified",binary:x0,additions:Number.isFinite(a0)?a0:0,deletions:Number.isFinite(zJ)?zJ:0}]}),r=yield*z(c.map((l)=>l.file));if(r.size>0){let l=c.filter((J0)=>!r.has(J0.file));c.length=0,c.push(...l)}let e=100,z0=(l,J0,P0)=>W$(k$(l,l,J0,P0,"","",{context:Number.MAX_SAFE_INTEGER}));for(let l=0;l<c.length;l+=e){let J0=c.slice(l,l+e),P0=yield*I(J0);for(let B0 of J0){let x0=P0?.get(B0.file)??{before:"",after:""},[a0,zJ]=B0.binary?["",""]:P0?[x0.before,x0.after]:yield*N(B0);w.push({file:B0.file,patch:B0.binary?"":z0(B0.file,a0,zJ),additions:B0.additions,deletions:B0.deletions,status:B0.status})}}return w}))});return yield*y().pipe(B.catchCause((R)=>{return D0.error("cleanup loop failed",{cause:O$.pretty(R)}),B.void}),B.repeat(nY.spaced(S8.hours(1))),B.delay(S8.minutes(1)),B.forkScoped),{cleanup:y,track:k,patch:n,restore:d,revert:X0,diff:o,diffFull:t}}));return E5.of({init:B.fn("Snapshot.init")(function*(){yield*s.get(X)}),cleanup:B.fn("Snapshot.cleanup")(function*(){return yield*s.useEffect(X,(U)=>U.cleanup())}),track:B.fn("Snapshot.track")(function*(){return yield*s.useEffect(X,(U)=>U.track())}),patch:B.fn("Snapshot.patch")(function*(U){return yield*s.useEffect(X,(F)=>F.patch(U))}),restore:B.fn("Snapshot.restore")(function*(U){return yield*s.useEffect(X,(F)=>F.restore(U))}),revert:B.fn("Snapshot.revert")(function*(U){return yield*s.useEffect(X,(F)=>F.revert(U))}),diff:B.fn("Snapshot.diff")(function*(U){return yield*s.useEffect(X,(F)=>F.diff(U))}),diffFull:B.fn("Snapshot.diffFull")(function*(U,F){return yield*s.useEffect(X,(K)=>K.diffFull(U,F))})})})),qX=aY.pipe(j0.provide(u8.defaultLayer),j0.provide(sJ.defaultLayer),j0.provide(G$.defaultLayer));var T5={};QJ(T5,{parseStreamError:()=>x8,parseAPICallError:()=>c8,ResponseStreamError:()=>w5,ProviderError:()=>T5,HeaderTimeoutError:()=>M5});import{STATUS_CODES as rY}from"http";function L5(J){return J()}class M5 extends Error{ms;name="ProviderHeaderTimeoutError";constructor(J){super(`Provider response headers timed out after ${J}ms`);this.ms=J}}class w5 extends Error{name="ProviderResponseStreamError";constructor(J,$){super(J,$)}}var EX=[/prompt is too long/i,/input is too long for requested model/i,/exceeds the context window/i,/input token count.*exceeds the maximum/i,/maximum prompt length is \d+/i,/reduce the length of the messages/i,/maximum context length is \d+ tokens/i,/exceeds the limit of \d+/i,/exceeds the available context size/i,/greater than the context length/i,/context window exceeds limit/i,/exceeded model token limit/i,/context[_ ]length[_ ]exceeded/i,/request entity too large/i,/context length is only \d+ tokens/i,/input length.*exceeds.*context length/i,/prompt too long; exceeded (?:max )?context length/i,/too large for model with \d+ maximum context length/i,/model_context_window_exceeded/i];function LX(J){let $=J.statusCode;if(!$)return J.isRetryable;return $===404||J.isRetryable}function MX(J){if(EX.some(($)=>$.test(J)))return!0;return/^4(00|13)\s*(status code)?\s*\(no body\)/i.test(J)}function wX(J,$){return L5(()=>{let Y=$.message;if(Y===""){if($.responseBody)return $.responseBody;if($.statusCode){let Z=rY[$.statusCode];if(Z)return Z}return"Unknown error"}if(!$.responseBody||$.statusCode&&Y!==rY[$.statusCode])return Y;try{let Z=JSON.parse($.responseBody),V=Z.message||Z.error||Z.error?.message;if(V&&typeof V==="string")return`${Y}: ${V}`}catch{}if(/^\s*<!doctype|^\s*<html/i.test($.responseBody)){if($.statusCode===401)return"Unauthorized: request was blocked by a gateway or proxy. Your authentication token may be missing or expired \u2014 try running `muxcode auth login <your provider URL>` to re-authenticate.";if($.statusCode===403)return"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.";return Y}return`${Y}: ${$.responseBody}`}).trim()}function l8(J){if(typeof J==="string")try{let $=JSON.parse(J);if($&&typeof $==="object")return $;return}catch{return}if(typeof J==="object"&&J!==null)return J;return}function x8(J){let $=l8(J),Y=typeof $?.message==="string"?l8($.message)??$:$;if(!Y)return;let Z=JSON.stringify(Y);if(Y.type!=="error")return;switch(Y?.error?.code){case"context_length_exceeded":return{type:"context_overflow",message:"Input exceeds context window of this model",responseBody:Z};case"insufficient_quota":return{type:"api_error",message:"Quota exceeded. Check your plan and billing details.",isRetryable:!1,responseBody:Z};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:Z};case"invalid_prompt":return{type:"api_error",message:typeof Y?.error?.message==="string"?Y?.error?.message:"Invalid prompt.",isRetryable:!1,responseBody:Z};case"server_is_overloaded":case"server_error":return{type:"api_error",message:typeof Y?.error?.message==="string"?Y?.error?.message:"Server error.",isRetryable:!0,responseBody:Z}}}function c8(J){let $=wX(J.providerID,J.error),Y=l8(J.error.responseBody);if(MX($)||J.error.statusCode===413||Y?.error?.code==="context_length_exceeded")return{type:"context_overflow",message:$,responseBody:J.error.responseBody};let Z=J.error.url?{url:J.error.url}:void 0;return{type:"api_error",message:$,statusCode:J.error.statusCode,isRetryable:J.providerID.startsWith("openai")?LX(J.error):J.error.isRetryable,responseHeaders:J.error.responseHeaders,responseBody:J.error.responseBody,metadata:Z}}var lJ=(J,$)=>$.every((Y,Z)=>J[Z]===Y);function TX(J){return J==="application/pdf"}function y$(J){return J.startsWith("image/")||TX(J)}function FK(J){return J.startsWith("image/")&&J!=="image/svg+xml"&&J!=="image/vnd.fastbidsheet"}function UK(J,$){if(lJ(J,[137,80,78,71,13,10,26,10]))return"image/png";if(lJ(J,[255,216,255]))return"image/jpeg";if(lJ(J,[71,73,70,56]))return"image/gif";if(lJ(J,[66,77]))return"image/bmp";if(lJ(J,[37,80,68,70,45]))return"application/pdf";if(lJ(J,[82,73,70,70])&&lJ(J.subarray(8),[87,69,66,80]))return"image/webp";return $}var vX=Q.String.pipe(Q.brand("ProviderID")),fJ=vX.pipe(eJ((J)=>({muxcode:J.make("muxcode"),anthropic:J.make("anthropic"),openai:J.make("openai"),google:J.make("google"),googleVertex:J.make("google-vertex"),githubCopilot:J.make("github-copilot"),amazonBedrock:J.make("amazon-bedrock"),azure:J.make("azure"),openrouter:J.make("openrouter"),mistral:J.make("mistral"),gitlab:J.make("gitlab")}))),PX=Q.String.pipe(Q.brand("ModelID")),kJ=PX;var S$={};QJ(S$,{SharedSchema:()=>CX,Shared:()=>sY,OutputLengthError:()=>z$,MessageError:()=>S$,AuthError:()=>H$});var z$=$J.create("MessageOutputLengthError",{}),H$=$J.create("ProviderAuthError",{providerID:Q.String,message:Q.String}),sY=[H$.EffectSchema,$J.Unknown.EffectSchema,z$.EffectSchema],CX=Q.Union(sY);var Z7="Attached media from tool result:";var h$=$J.create("MessageAbortedError",{message:Q.String}),V7=$J.create("StructuredOutputError",{message:Q.String,retries:a}),DJ=$J.create("APIError",{message:Q.String,statusCode:Q.optional(a),isRetryable:Q.Boolean,responseHeaders:Q.optional(Q.Record(Q.String,Q.String)),responseBody:Q.optional(Q.String),metadata:Q.optional(Q.Record(Q.String,Q.String))}),P5=$J.create("ContextOverflowError",{message:Q.String,responseBody:Q.optional(Q.String)});class d8 extends Q.Class("OutputFormatText")({type:Q.Literal("text")}){}class m8 extends Q.Class("OutputFormatJsonSchema")({type:Q.Literal("json_schema"),schema:Q.Record(Q.String,Q.Any).annotate({identifier:"JSONSchema"}),retryCount:a.pipe(Q.optional,Q.withDecodingDefault(B.succeed(2)))}){}var X7=Q.Union([d8,m8]).annotate({discriminator:"type",identifier:"OutputFormat"}),o0={id:YJ,sessionID:F0,messageID:l0},Q7=Q.Struct({...o0,type:Q.Literal("snapshot"),snapshot:Q.String}).annotate({identifier:"SnapshotPart"}),F7=Q.Struct({...o0,type:Q.Literal("patch"),hash:Q.String,files:Q.Array(Q.String)}).annotate({identifier:"PatchPart"}),U7=Q.Struct({...o0,type:Q.Literal("text"),text:Q.String,synthetic:Q.optional(Q.Boolean),ignored:Q.optional(Q.Boolean),time:Q.optional(Q.Struct({start:a,end:Q.optional(a)})),metadata:Q.optional(Q.Record(Q.String,Q.Any))}).annotate({identifier:"TextPart"}),K7=Q.Struct({...o0,type:Q.Literal("reasoning"),text:Q.String,metadata:Q.optional(Q.Record(Q.String,Q.Any)),time:Q.Struct({start:a,end:Q.optional(a)})}).annotate({identifier:"ReasoningPart"}),n8={text:Q.Struct({value:Q.String,start:Q.Finite,end:Q.Finite}).annotate({identifier:"FilePartSourceText"})},G7=Q.Struct({...n8,type:Q.Literal("file"),path:Q.String}).annotate({identifier:"FileSource"}),W7=Q.Struct({...n8,type:Q.Literal("symbol"),path:Q.String,range:f$.Range,name:Q.String,kind:a}).annotate({identifier:"SymbolSource"}),z7=Q.Struct({...n8,type:Q.Literal("resource"),clientName:Q.String,uri:Q.String}).annotate({identifier:"ResourceSource"}),i8=Q.Union([G7,W7,z7]).annotate({discriminator:"type",identifier:"FilePartSource"}),o8=Q.Struct({...o0,type:Q.Literal("file"),mime:Q.String,filename:Q.optional(Q.String),url:Q.String,source:Q.optional(i8)}).annotate({identifier:"FilePart"}),H7=Q.Struct({...o0,type:Q.Literal("agent"),name:Q.String,source:Q.optional(Q.Struct({value:Q.String,start:a,end:a}))}).annotate({identifier:"AgentPart"}),j7=Q.Struct({...o0,type:Q.Literal("compaction"),auto:Q.Boolean,overflow:Q.optional(Q.Boolean),tail_start_id:Q.optional(l0)}).annotate({identifier:"CompactionPart"}),B7=Q.Struct({...o0,type:Q.Literal("subtask"),prompt:Q.String,description:Q.String,agent:Q.String,model:Q.optional(Q.Struct({providerID:fJ,modelID:kJ})),command:Q.optional(Q.String)}).annotate({identifier:"SubtaskPart"}),N7=Q.Struct({...o0,type:Q.Literal("retry"),attempt:a,error:DJ.EffectSchema,time:Q.Struct({created:a})}).annotate({identifier:"RetryPart"}),A7=Q.Struct({...o0,type:Q.Literal("step-start"),snapshot:Q.optional(Q.String)}).annotate({identifier:"StepStartPart"}),R7=Q.Struct({...o0,type:Q.Literal("step-finish"),reason:Q.String,snapshot:Q.optional(Q.String),cost:Q.Finite,tokens:Q.Struct({total:Q.optional(Q.Finite),input:Q.Finite,output:Q.Finite,reasoning:Q.Finite,cache:Q.Struct({read:Q.Finite,write:Q.Finite})})}).annotate({identifier:"StepFinishPart"}),O7=Q.Struct({status:Q.Literal("pending"),input:Q.Record(Q.String,Q.Any),raw:Q.String}).annotate({identifier:"ToolStatePending"}),I7=Q.Struct({status:Q.Literal("running"),input:Q.Record(Q.String,Q.Any),title:Q.optional(Q.String),metadata:Q.optional(Q.Record(Q.String,Q.Any)),time:Q.Struct({start:a})}).annotate({identifier:"ToolStateRunning"}),D7=Q.Struct({status:Q.Literal("completed"),input:Q.Record(Q.String,Q.Any),output:Q.String,title:Q.String,metadata:Q.Record(Q.String,Q.Any),time:Q.Struct({start:a,end:a,compacted:Q.optional(a)}),attachments:Q.optional(Q.Array(o8))}).annotate({identifier:"ToolStateCompleted"});function bX(J,$){if(!$||J.length<=$)return J;let Y=J.length-$;return`${J.slice(0,$)}
|
|
70
|
+
[Tool output truncated for compaction: omitted ${Y} chars]`}var _7=Q.Struct({status:Q.Literal("error"),input:Q.Record(Q.String,Q.Any),error:Q.String,metadata:Q.optional(Q.Record(Q.String,Q.Any)),time:Q.Struct({start:a,end:a})}).annotate({identifier:"ToolStateError"}),q7=Q.Union([O7,I7,D7,_7]).annotate({discriminator:"status",identifier:"ToolState"}),E7=Q.Struct({...o0,type:Q.Literal("tool"),callID:Q.String,tool:Q.String,state:q7,metadata:Q.optional(Q.Record(Q.String,Q.Any))}).annotate({identifier:"ToolPart"}),L7={id:l0,sessionID:F0},M7=Q.Struct({...L7,role:Q.Literal("user"),time:Q.Struct({created:a}),format:Q.optional(X7),summary:Q.optional(Q.Struct({title:Q.optional(Q.String),body:Q.optional(Q.String),diffs:Q.Array(bJ.FileDiff)})),agent:Q.String,model:Q.Struct({providerID:fJ,modelID:kJ,variant:Q.optional(Q.String)}),system:Q.optional(Q.String),tools:Q.optional(Q.Record(Q.String,Q.Boolean))}).annotate({identifier:"UserMessage"}),a8=Q.Union([U7,B7,K7,o8,E7,A7,R7,Q7,F7,H7,N7,j7]).annotate({discriminator:"type",identifier:"Part"}),fX=Q.Union([...S$.Shared,h$.EffectSchema,V7.EffectSchema,P5.EffectSchema,DJ.EffectSchema]).annotate({discriminator:"name"}),kX=Q.Struct({id:Q.optional(YJ),type:Q.Literal("text"),text:Q.String,synthetic:Q.optional(Q.Boolean),ignored:Q.optional(Q.Boolean),time:Q.optional(Q.Struct({start:a,end:Q.optional(a)})),metadata:Q.optional(Q.Record(Q.String,Q.Any))}).annotate({identifier:"TextPartInput"}),yX=Q.Struct({id:Q.optional(YJ),type:Q.Literal("file"),mime:Q.String,filename:Q.optional(Q.String),url:Q.String,source:Q.optional(i8)}).annotate({identifier:"FilePartInput"}),SX=Q.Struct({id:Q.optional(YJ),type:Q.Literal("agent"),name:Q.String,source:Q.optional(Q.Struct({value:Q.String,start:a,end:a}))}).annotate({identifier:"AgentPartInput"}),gX=Q.Struct({id:Q.optional(YJ),type:Q.Literal("subtask"),prompt:Q.String,description:Q.String,agent:Q.String,model:Q.optional(Q.Struct({providerID:fJ,modelID:kJ})),command:Q.optional(Q.String)}).annotate({identifier:"SubtaskPartInput"}),w7=Q.Struct({...L7,role:Q.Literal("assistant"),time:Q.Struct({created:a,completed:Q.optional(a)}),error:Q.optional(fX),parentID:l0,modelID:kJ,providerID:fJ,mode:Q.String,agent:Q.String,path:Q.Struct({cwd:Q.String,root:Q.String}),summary:Q.optional(Q.Boolean),cost:Q.Finite,tokens:Q.Struct({total:Q.optional(Q.Finite),input:Q.Finite,output:Q.Finite,reasoning:Q.Finite,cache:Q.Struct({read:Q.Finite,write:Q.Finite})}),structured:Q.optional(Q.Any),variant:Q.optional(Q.String),finish:Q.optional(Q.String)}).annotate({identifier:"AssistantMessage"}),r8=Q.Union([M7,w7]).annotate({discriminator:"role",identifier:"Message"}),hX=Q.Struct({sessionID:F0,info:r8}),uX=Q.Struct({sessionID:F0,messageID:l0}),lX=Q.Struct({sessionID:F0,part:a8,time:a}),xX=Q.Struct({sessionID:F0,messageID:l0,partID:YJ}),cX={Updated:u0.define({type:"message.updated",version:1,aggregate:"sessionID",schema:hX}),Removed:u0.define({type:"message.removed",version:1,aggregate:"sessionID",schema:uX}),PartUpdated:u0.define({type:"message.part.updated",version:1,aggregate:"sessionID",schema:lX}),PartDelta:t0.define("message.part.delta",Q.Struct({sessionID:F0,messageID:l0,partID:YJ,field:Q.String,delta:Q.String})),PartRemoved:u0.define({type:"message.part.removed",version:1,aggregate:"sessionID",schema:xX})},pX=Q.Struct({info:r8,parts:Q.Array(a8)}),dX=Q.Struct({id:l0,time:Q.Finite.check(Q.isGreaterThanOrEqualTo(0))}),mX=Q.decodeUnknownSync(dX),p8={encode(J){return Buffer.from(JSON.stringify(J)).toString("base64url")},decode(J){return mX(JSON.parse(Buffer.from(J,"base64url").toString("utf8")))}},T7=(J)=>({...J.data,id:J.id,sessionID:J.session_id}),nX=(J)=>({...J.data,id:J.id,sessionID:J.session_id,messageID:J.message_id}),iX=(J)=>u$(g$(i0.time_created,J.time),WJ(G0(i0.time_created,J.time),g$(i0.id,J.id)));function oX(J){let $=J.map((Z)=>Z.id),Y=new Map;if($.length>0){let Z=q0.use((V)=>V.select().from(d0).where(C5(d0.message_id,$)).orderBy(d0.message_id,d0.id).all());for(let V of Z){let X=nX(V),U=Y.get(V.message_id);if(U)U.push(X);else Y.set(V.message_id,[X])}}return J.map((Z)=>({info:T7(Z),parts:Y.get(Z.id)??[]}))}function v5(J){if(!J)return;let{providerExecuted:$,...Y}=J;return Object.keys(Y).length>0?Y:void 0}var v7=B.fnUntraced(function*(J,$,Y){let Z=[],V=new Set,X=(K)=>{if($.api.npm==="@ai-sdk/anthropic")return!0;if($.api.npm==="@ai-sdk/openai")return!0;if($.api.npm==="@ai-sdk/amazon-bedrock")return K.mime.startsWith("image/");if($.api.npm==="@ai-sdk/xai")return K.mime.startsWith("image/");if($.api.npm==="@ai-sdk/google-vertex/anthropic")return!0;if($.api.npm==="@ai-sdk/google"){let G=$.api.id.toLowerCase();return G.includes("gemini-3")&&!G.includes("gemini-2")}return!1},U=(K)=>{let G=K.output;if(typeof G==="string")return{type:"text",value:G};if(typeof G==="object"){let W=G,z=(W.attachments??[]).filter((A)=>{return A.url.startsWith("data:")&&A.url.includes(",")});return{type:"content",value:[...W.text?[{type:"text",text:W.text}]:[],...z.map((A)=>({type:"media",mediaType:A.mime,data:L5(()=>{let j=A.url.indexOf(",");return j===-1?A.url:A.url.slice(j+1)})}))]}}return{type:"json",value:G}};for(let K of J){if(K.parts.length===0)continue;if(K.info.role==="user"){let G={id:K.info.id,role:"user",parts:[]};for(let W of K.parts){if(W.type==="text"&&!W.ignored&&W.text!=="")G.parts.push({type:"text",text:W.text});if(W.type==="file"&&W.mime!=="text/plain"&&W.mime!=="application/x-directory")if(Y?.stripMedia&&y$(W.mime))G.parts.push({type:"text",text:`[Attached ${W.mime}: ${W.filename??"file"}]`});else G.parts.push({type:"file",url:W.url,mediaType:W.mime,filename:W.filename});if(W.type==="compaction")G.parts.push({type:"text",text:"What did we do so far?"});if(W.type==="subtask")G.parts.push({type:"text",text:"The following tool was executed by the user"})}if(G.parts.length>0)Z.push(G)}if(K.info.role==="assistant"){let G=`${$.providerID}/${$.id}`!==`${K.info.providerID}/${K.info.modelID}`,W=[];if(K.info.error&&!(h$.isInstance(K.info.error)&&K.parts.some((j)=>j.type!=="step-start"&&j.type!=="reasoning")))continue;let z={id:K.info.id,role:"assistant",parts:[]},A=K.parts.some((j)=>{if(j.type!=="reasoning")return!1;return j.metadata?.anthropic?.signature!=null});for(let j of K.parts){if(j.type==="text"){let D=j.text===""&&A?" ":j.text;z.parts.push({type:"text",text:D,...G?{}:{providerMetadata:j.metadata}})}if(j.type==="step-start")z.parts.push({type:"step-start"});if(j.type==="tool"){if(V.add(j.tool),j.state.status==="completed"){let D=j.state.time.compacted?"[Old tool result content cleared]":bX(j.state.output,Y?.toolOutputMaxChars),O=j.state.time.compacted||Y?.stripMedia?[]:j.state.attachments??[],M=O.filter((f)=>y$(f.mime)).filter((f)=>!X(f));if(M.length>0)W.push(...M);let C=O.filter((f)=>!y$(f.mime)||X(f)),q=C.length>0?{text:D,attachments:C}:D;z.parts.push({type:"tool-"+j.tool,state:"output-available",toolCallId:j.callID,input:j.state.input,output:q,...j.metadata?.providerExecuted?{providerExecuted:!0}:{},...G?{}:{callProviderMetadata:v5(j.metadata)}})}if(j.state.status==="error"){let D=j.state.metadata?.interrupted===!0?j.state.metadata.output:void 0;if(typeof D==="string")z.parts.push({type:"tool-"+j.tool,state:"output-available",toolCallId:j.callID,input:j.state.input,output:D,...j.metadata?.providerExecuted?{providerExecuted:!0}:{},...G?{}:{callProviderMetadata:v5(j.metadata)}});else z.parts.push({type:"tool-"+j.tool,state:"output-error",toolCallId:j.callID,input:j.state.input,errorText:j.state.error,...j.metadata?.providerExecuted?{providerExecuted:!0}:{},...G?{}:{callProviderMetadata:v5(j.metadata)}})}if(j.state.status==="pending"||j.state.status==="running")z.parts.push({type:"tool-"+j.tool,state:"output-error",toolCallId:j.callID,input:j.state.input,errorText:"[Tool execution was interrupted]",...j.metadata?.providerExecuted?{providerExecuted:!0}:{},...G?{}:{callProviderMetadata:v5(j.metadata)}})}if(j.type==="reasoning"){if(G){if(j.text.trim().length>0)z.parts.push({type:"text",text:j.text});continue}z.parts.push({type:"reasoning",text:j.text,providerMetadata:j.metadata})}}if(z.parts.length>0){if(Z.push(z),W.length>0)Z.push({id:l0.ascending(),role:"user",parts:[{type:"text",text:Z7},...W.map((j)=>({type:"file",url:j.url,mediaType:j.mime,filename:j.filename}))]})}}}let F=Object.fromEntries(Array.from(V).map((K)=>[K,{toModelOutput:U}]));return yield*B.promise(()=>Y7(Z.filter((K)=>K.parts.some((G)=>G.type!=="step-start")),{tools:F}))});function aX(J,$,Y){return B.runPromise(v7(J,$,Y).pipe(B.provide(tY)))}var P7=B.fn("MessageV2.page")(function*(J){let $=J.before?p8.decode(J.before):void 0,Y=$?WJ(G0(i0.session_id,J.sessionID),iX($)):G0(i0.session_id,J.sessionID),Z=q0.use((K)=>K.select().from(i0).where(Y).orderBy(xJ(i0.time_created),xJ(i0.id)).limit(J.limit+1).all());if(Z.length===0){if(!q0.use((G)=>G.select({id:V0.id}).from(V0).where(G0(V0.id,J.sessionID)).get()))return yield*new GJ({message:`Session not found: ${J.sessionID}`});return{items:[],more:!1}}let V=Z.length>J.limit,X=V?Z.slice(0,J.limit):Z,U=oX(X);U.reverse();let F=X.at(-1);return{items:U,more:V,cursor:V&&F?p8.encode({id:F.id,time:F.time_created}):void 0}});function*C7(J){let Y;while(!0){let Z=B.runSync(P7({sessionID:J,limit:50,before:Y}).pipe(B.catchIf(GJ.isInstance,()=>B.succeed({items:[],more:!1,cursor:void 0}))));if(Z.items.length===0)break;for(let V=Z.items.length-1;V>=0;V--)yield Z.items[V];if(!Z.more||!Z.cursor)break;Y=Z.cursor}}function b7(J){return q0.use((Y)=>Y.select().from(d0).where(G0(d0.message_id,J)).orderBy(d0.id).all()).map((Y)=>({...Y.data,id:Y.id,sessionID:Y.session_id,messageID:Y.message_id}))}var rX=B.fn("MessageV2.get")(function*(J){let $=q0.use((Y)=>Y.select().from(i0).where(WJ(G0(i0.id,J.messageID),G0(i0.session_id,J.sessionID))).get());if(!$)return yield*new GJ({message:`Message not found: ${J.messageID}`});return{info:T7($),parts:b7(J.messageID)}});function f7(J){let $=[],Y=new Set,Z;for(let G of J){if($.push(G),Z){if(G.info.id===Z)break;continue}if(G.info.role==="user"&&Y.has(G.info.id)){let W=G.parts.find((z)=>z.type==="compaction");if(!W)continue;if(!W.tail_start_id)break;if(Z=W.tail_start_id,G.info.id===Z)break;continue}if(G.info.role==="user"&&Y.has(G.info.id)&&G.parts.some((W)=>W.type==="compaction"))break;if(G.info.role==="assistant"&&G.info.summary&&G.info.finish&&!G.info.error)Y.add(G.info.parentID)}$.reverse();let V=$.findLastIndex((G)=>G.info.role==="user"&&G.parts.some((W)=>W.type==="compaction"&&W.tail_start_id!==void 0)),X=$[V],U=X?.parts.find((G)=>G.type==="compaction"&&G.tail_start_id!==void 0),F=X?$.findIndex((G,W)=>W>V&&G.info.role==="assistant"&&G.info.summary&&G.info.parentID===X.info.id):-1,K=U?.tail_start_id?$.findIndex((G)=>G.info.id===U.tail_start_id):-1;if(K>=0&&K<V&&F>V)return[...$.slice(V,F+1),...$.slice(K,V),...$.slice(F+1)];return $}var sX=B.fnUntraced(function*(J){return f7(C7(J))});function tX(J){let $,Y,Z;for(let X of J){let U=X.info;if(U.role==="user"&&(!$||U.id>$.id))$=U;if(U.role==="assistant"&&(!Y||U.id>Y.id))Y=U;if(U.role==="assistant"&&U.finish&&(!Z||U.id>Z.id))Z=U}let V=J.flatMap((X)=>Z&&X.info.id<=Z.id?[]:X.parts.filter((U)=>U.type==="compaction"||U.type==="subtask"));return{user:$,assistant:Y,finished:Z,tasks:V}}function eX(J,$){switch(!0){case(J instanceof DOMException&&J.name==="AbortError"):return new h$({message:J.message},{cause:J}).toObject();case z$.isInstance(J):return J;case $7.isInstance(J):return new H$({providerID:$.providerID,message:J.message},{cause:J}).toObject();case J?.code==="ECONNRESET":return new DJ({message:"Connection reset by server",isRetryable:!0,metadata:{code:J.code??"",syscall:J.syscall??"",message:J.message??""}},{cause:J}).toObject();case(J instanceof Error&&J.code==="ZlibError"):if($.aborted)return new h$({message:J.message},{cause:J}).toObject();return new DJ({message:"Response decompression failed",isRetryable:!0,metadata:{code:J.code,message:J.message}},{cause:J}).toObject();case J instanceof M5:return new DJ({message:J.message,isRetryable:!0,metadata:{code:J.name,timeoutMs:String(J.ms)}},{cause:J}).toObject();case J instanceof w5:return new DJ({message:J.message,isRetryable:!0,metadata:{code:J.name}},{cause:J}).toObject();case J7.isInstance(J):let Y=c8({providerID:$.providerID,error:J});if(Y.type==="context_overflow")return new P5({message:Y.message,responseBody:Y.responseBody},{cause:J}).toObject();return new DJ({message:Y.message,statusCode:Y.statusCode,isRetryable:Y.isRetryable,responseHeaders:Y.responseHeaders,responseBody:Y.responseBody,metadata:Y.metadata},{cause:J}).toObject();case J instanceof Error:return new $J.Unknown({message:eY(J)},{cause:J}).toObject();default:try{let Z=x8(J);if(Z){if(Z.type==="context_overflow")return new P5({message:Z.message,responseBody:Z.responseBody},{cause:J}).toObject();return new DJ({message:Z.message,isRetryable:Z.isRetryable,responseBody:Z.responseBody},{cause:J}).toObject()}}catch{}return new $J.Unknown({message:JSON.stringify(J)},{cause:J}).toObject()}}var JQ=Q.String.check(Q.isStartsWith("wrk")).pipe(Q.brand("WorkspaceID")),b5=JQ.pipe(eJ((J)=>({ascending:($)=>J.make(mJ.ascending("workspace",$))})));var k7=KJ({service:"session"}),u7="New session - ",l7="Child session - ";function $Q(J=!1){return(J?l7:u7)+new Date().toISOString()}function YQ(J){return new RegExp(`^(${u7}|${l7})\\d{4}-\\d{2}-\\d{2}T\\d{2}:\\d{2}:\\d{2}\\.\\d{3}Z$`).test(J)}function p$(J){let $=J.summary_additions!==null||J.summary_deletions!==null||J.summary_files!==null?{additions:J.summary_additions??0,deletions:J.summary_deletions??0,files:J.summary_files??0,diffs:J.summary_diffs??void 0}:void 0,Y=J.share_url?{url:J.share_url}:void 0,Z=J.revert??void 0;return{id:J.id,slug:J.slug,projectID:J.project_id,workspaceID:J.workspace_id??void 0,directory:J.directory,path:J.path??void 0,parentID:J.parent_id??void 0,title:J.title,agent:J.agent??void 0,model:J.model?{id:kJ.make(J.model.id),providerID:fJ.make(J.model.providerID),variant:J.model.variant}:void 0,version:J.version,summary:$,cost:J.cost,tokens:{input:J.tokens_input,output:J.tokens_output,reasoning:J.tokens_reasoning,cache:{read:J.tokens_cache_read,write:J.tokens_cache_write}},share:Y,revert:Z,permission:J.permission?[...J.permission]:void 0,time:{created:J.time_created,updated:J.time_updated,compacting:J.time_compacting??void 0,archived:J.time_archived??void 0}}}function ZQ(J){return{id:J.id,project_id:J.projectID,workspace_id:J.workspaceID,parent_id:J.parentID,slug:J.slug,directory:J.directory,path:J.path,title:J.title,agent:J.agent,model:J.model,version:J.version,share_url:J.share?.url,summary_additions:J.summary?.additions,summary_deletions:J.summary?.deletions,summary_files:J.summary?.files,summary_diffs:J.summary?.diffs,cost:J.cost??0,tokens_input:(J.tokens??B$).input,tokens_output:(J.tokens??B$).output,tokens_reasoning:(J.tokens??B$).reasoning,tokens_cache_read:(J.tokens??B$).cache.read,tokens_cache_write:(J.tokens??B$).cache.write,revert:J.revert??null,permission:J.permission,time_created:J.time.created,time_updated:J.time.updated,time_compacting:J.time.compacting,time_archived:J.time.archived}}function VQ(J){let $=J.match(/^(.+) \(fork #(\d+)\)$/);if($){let Y=$[1],Z=parseInt($[2],10);return`${Y} (fork #${Z+1})`}return`${J} (fork #1)`}function y7(J,$){return x$.relative(x$.resolve(J),$).replaceAll("\\","/")}var e8=Q.Struct({additions:Q.Finite,deletions:Q.Finite,files:Q.Finite,diffs:E0(Q.Array(bJ.FileDiff))}),x7=Q.Struct({input:Q.Finite,output:Q.Finite,reasoning:Q.Finite,cache:Q.Struct({read:Q.Finite,write:Q.Finite})}),B$={input:0,output:0,reasoning:0,cache:{read:0,write:0}},XQ=Q.Struct({url:Q.String}),y5=Q.Finite,QQ=Q.Struct({created:a,updated:a,compacting:E0(a),archived:E0(y5)}),J6=Q.Struct({messageID:l0,partID:E0(YJ),snapshot:E0(Q.String),diff:E0(Q.String)}),$6=Q.Struct({id:kJ,providerID:fJ,variant:E0(Q.String)}),Y6=Q.Struct({id:F0,slug:Q.String,projectID:k5,workspaceID:E0(b5),directory:Q.String,path:E0(Q.String),parentID:E0(F0),summary:E0(e8),cost:E0(Q.Finite),tokens:E0(x7),share:E0(XQ),title:Q.String,agent:E0(Q.String),model:E0($6),version:Q.String,time:QQ,permission:E0(m$.Ruleset),revert:E0(J6)}).annotate({identifier:"Session"}),c7=Q.Struct({id:k5,name:E0(Q.String),worktree:Q.String}).annotate({identifier:"ProjectSummary"}),FQ=Q.Struct({...Y6.fields,project:Q.NullOr(c7)}).annotate({identifier:"GlobalSession"}),UQ=Q.optional(Q.Struct({parentID:Q.optional(F0),title:Q.optional(Q.String),agent:Q.optional(Q.String),model:Q.optional($6),permission:Q.optional(m$.Ruleset),workspaceID:Q.optional(b5)})),KQ=Q.Struct({sessionID:F0,messageID:Q.optional(l0)}),GQ=F0,WQ=F0,zQ=F0,HQ=Q.Struct({sessionID:F0,title:Q.String}),jQ=Q.Struct({sessionID:F0,time:Q.optional(y5)}),BQ=Q.Struct({sessionID:F0,permission:m$.Ruleset}),NQ=Q.Struct({sessionID:F0,revert:Q.optional(J6),summary:Q.optional(e8)}),AQ=Q.Struct({sessionID:F0,limit:Q.optional(a)}),s8=Q.Struct({sessionID:F0,info:Y6}),RQ=Q.Struct({url:Q.optional(Q.NullOr(Q.String))}),OQ=Q.Struct({created:Q.optional(Q.NullOr(a)),updated:Q.optional(Q.NullOr(a)),compacting:Q.optional(Q.NullOr(a)),archived:Q.optional(Q.NullOr(y5))}),IQ=Q.Struct({id:Q.optional(Q.NullOr(F0)),slug:Q.optional(Q.NullOr(Q.String)),projectID:Q.optional(Q.NullOr(k5)),workspaceID:Q.optional(Q.NullOr(b5)),directory:Q.optional(Q.NullOr(Q.String)),path:Q.optional(Q.NullOr(Q.String)),parentID:Q.optional(Q.NullOr(F0)),summary:Q.optional(Q.NullOr(e8)),cost:Q.optional(Q.Finite),tokens:Q.optional(x7),share:Q.optional(RQ),title:Q.optional(Q.NullOr(Q.String)),agent:Q.optional(Q.NullOr(Q.String)),model:Q.optional(Q.NullOr($6)),version:Q.optional(Q.NullOr(Q.String)),time:Q.optional(OQ),permission:Q.optional(Q.NullOr(m$.Ruleset)),revert:Q.optional(Q.NullOr(J6))}),DQ=Q.Struct({sessionID:F0,info:IQ}),l$={Created:u0.define({type:"session.created",version:1,aggregate:"sessionID",schema:s8}),Updated:u0.define({type:"session.updated",version:1,aggregate:"sessionID",schema:DQ,busSchema:s8}),Deleted:u0.define({type:"session.deleted",version:1,aggregate:"sessionID",schema:s8}),Diff:t0.define("session.diff",Q.Struct({sessionID:F0,diff:Q.Array(bJ.FileDiff)})),Error:t0.define("session.error",Q.Struct({sessionID:Q.optional(F0),error:m0.Assistant.fields.error}))};function _Q(J,$){let Y=$.project.vcs?x$.join($.worktree,".muxcode","plans"):x$.join(rJ.Path.data,"plans");return x$.join(Y,[J.time.created,J.slug].join("-")+".md")}var qQ=(J)=>{let $=(A)=>{if(!Number.isFinite(A))return 0;return Math.max(0,A)},Y=$(J.usage.inputTokens??0),Z=$(J.usage.outputTokens??0),V=$(J.usage.reasoningTokens??0),X=$(J.usage.cacheReadInputTokens??0),U=$(Number(J.usage.cacheWriteInputTokens??J.metadata?.anthropic?.cacheCreationInputTokens??J.metadata?.vertex?.cacheCreationInputTokens??J.metadata?.bedrock?.usage?.cacheWriteInputTokens??J.metadata?.venice?.usage?.cacheCreationInputTokens??0)),F=$(Y-X-U),G={total:J.usage.totalTokens,input:F,output:$(Z-V),reasoning:V,cache:{write:U,read:X}},W=Y,z=J.model.cost?.tiers?.filter((A)=>A.tier.type==="context"&&W>A.tier.size).sort((A,j)=>j.tier.size-A.tier.size)[0]??(J.model.cost?.experimentalOver200K&&W>200000?J.model.cost.experimentalOver200K:J.model.cost);return{cost:$(new s0(0).add(new s0(G.input).mul(z?.input??0).div(1e6)).add(new s0(G.output).mul(z?.output??0).div(1e6)).add(new s0(G.cache.read).mul(z?.cache?.read??0).div(1e6)).add(new s0(G.cache.write).mul(z?.cache?.write??0).div(1e6)).add(new s0(G.reasoning).mul(z?.output??0).div(1e6)).toNumber()),tokens:G}};class p7 extends Q.TaggedErrorClass()("SessionBusyError",{sessionID:F0}){}class d$ extends n0.Service()("@muxcode/Session"){}var EQ=Q5(d$),S7=(J)=>B.sync(()=>q0.use(J)),d7=j0.effect(d$,B.gen(function*(){let J=yield*nJ.Service,$=yield*e0.Service,Y=yield*tJ.Service,Z=yield*u0.Service,V=yield*RJ.Service,X=B.fn("Session.createNext")(function*(R){let T=yield*s.context,N={id:F0.descending(R.id),slug:h7.create(),version:g7,projectID:T.project.id,directory:R.directory,path:R.path,workspaceID:R.workspaceID,parentID:R.parentID,title:R.title??$Q(!!R.parentID),agent:R.agent,model:R.model,permission:R.permission?[...R.permission]:void 0,cost:0,tokens:B$,time:{created:Date.now(),updated:Date.now()}};if(k7.info("created",N),yield*Z.run(l$.Created,{sessionID:N.id,info:N}),!V.experimentalWorkspaces)yield*$.publish(l$.Updated,{sessionID:N.id,info:N});return N}),U=B.fn("Session.get")(function*(R){let T=yield*S7((N)=>N.select().from(V0).where(G0(V0.id,R)).get());if(!T)return yield*B.fail(new GJ({message:`Session not found: ${R}`}));return p$(T)}),F=B.fn("Session.list")(function*(R){let T=yield*s.context;return Array.from(wQ({projectID:T.project.id,experimentalWorkspaces:V.experimentalWorkspaces,...R}))}),K=B.fn("Session.children")(function*(R){return(yield*S7((N)=>N.select().from(V0).where(WJ(G0(V0.parent_id,R))).all())).map(p$)}),G=B.fnUntraced(function*(R){let T=yield*U(R);try{let N=yield*s.directory.pipe(B.as(!0),B.catchCause(()=>B.succeed(!1)));if(N)yield*MQ(J,R);let I=yield*K(R);for(let w of I)yield*G(w.id);yield*Z.run(l$.Deleted,{sessionID:R,info:T},{publish:N}),yield*Z.remove(R)}catch(N){k7.error(N)}}),W=(R)=>B.gen(function*(){return yield*Z.run(m0.Event.Updated,{sessionID:R.sessionID,info:R}),R}).pipe(B.withSpan("Session.updateMessage")),z=(R)=>B.gen(function*(){return yield*Z.run(m0.Event.PartUpdated,{sessionID:R.sessionID,part:structuredClone(R),time:Date.now()}),R}).pipe(B.withSpan("Session.updatePart")),A=B.fn("Session.getPart")(function*(R){let T=q0.use((N)=>N.select().from(d0).where(WJ(G0(d0.session_id,R.sessionID),G0(d0.message_id,R.messageID),G0(d0.id,R.partID))).get());if(!T)return;return{...T.data,id:T.id,sessionID:T.session_id,messageID:T.message_id}}),j=B.fn("Session.create")(function*(R){let T=yield*s.context,N=yield*s.workspaceID;return yield*X({parentID:R?.parentID,directory:T.directory,path:y7(T.worktree,T.directory),title:R?.title,agent:R?.agent,model:R?.model,permission:R?.permission,workspaceID:R?.workspaceID??N})}),D=B.fn("Session.fork")(function*(R){let T=yield*s.context,N=yield*U(R.sessionID),I=VQ(N.title),w=yield*X({directory:T.directory,path:y7(T.worktree,T.directory),workspaceID:N.workspaceID,title:I}),v=yield*n({sessionID:R.sessionID}),S=new Map;for(let g of v){if(R.messageID&&g.info.id>=R.messageID)break;let c=l0.ascending();S.set(g.info.id,c);let r=g.info.role==="assistant"&&g.info.parentID?S.get(g.info.parentID):void 0,e=yield*W({...g.info,sessionID:w.id,id:c,...r&&{parentID:r}});for(let z0 of g.parts){let l={...z0,id:YJ.ascending(),messageID:e.id,sessionID:w.id};if(l.type==="compaction"&&l.tail_start_id)l.tail_start_id=S.get(l.tail_start_id);yield*z(l)}}return w}),O=(R,T)=>Z.run(l$.Updated,{sessionID:R,info:T}),P=B.fn("Session.touch")(function*(R){yield*O(R,{time:{updated:Date.now()}})}),M=B.fn("Session.setTitle")(function*(R){yield*O(R.sessionID,{title:R.title})}),C=B.fn("Session.setArchived")(function*(R){yield*O(R.sessionID,{time:{archived:R.time}})}),q=B.fn("Session.setPermission")(function*(R){yield*O(R.sessionID,{permission:[...R.permission],time:{updated:Date.now()}})}),f=B.fn("Session.setRevert")(function*(R){yield*O(R.sessionID,{summary:R.summary,time:{updated:Date.now()},revert:R.revert})}),_=B.fn("Session.clearRevert")(function*(R){yield*O(R,{time:{updated:Date.now()},revert:null})}),y=B.fn("Session.setSummary")(function*(R){yield*O(R.sessionID,{time:{updated:Date.now()},summary:R.summary})}),k=B.fn("Session.diff")(function*(R){return yield*Y.read(["session_diff",R]).pipe(B.orElseSucceed(()=>[]))}),n=B.fn("Session.messages")(function*(R){if(R.limit)return(yield*m0.page({sessionID:R.sessionID,limit:R.limit})).items;let T=50,N=[],I;while(!0){let w=yield*m0.page({sessionID:R.sessionID,limit:T,before:I});if(w.items.length===0)break;for(let v=w.items.length-1;v>=0;v--){let S=w.items[v];if(S)N.push(S)}if(!w.more||!w.cursor)break;I=w.cursor}return N.reverse()}),d=B.fn("Session.removeMessage")(function*(R){return yield*Z.run(m0.Event.Removed,{sessionID:R.sessionID,messageID:R.messageID}),R.messageID}),X0=B.fn("Session.removePart")(function*(R){return yield*Z.run(m0.Event.PartRemoved,{sessionID:R.sessionID,messageID:R.messageID,partID:R.partID}),R.partID}),o=B.fnUntraced(function*(R){yield*$.publish(m0.Event.PartDelta,R)}),t=B.fn("Session.findMessage")(function*(R,T){let I;while(!0){let w=yield*m0.page({sessionID:R,limit:50,before:I});if(w.items.length===0)break;for(let v=w.items.length-1;v>=0;v--){let S=w.items[v];if(S&&T(S))return TJ.some(S)}if(!w.more||!w.cursor)break;I=w.cursor}return TJ.none()});return d$.of({list:F,create:j,fork:D,touch:P,get:U,setTitle:M,setArchived:C,setPermission:q,setRevert:f,clearRevert:_,setSummary:y,diff:k,messages:n,children:K,remove:G,updateMessage:W,removeMessage:d,removePart:X0,updatePart:z,getPart:A,updatePartDelta:o,findMessage:t})})),LQ=d7.pipe(j0.provide(nJ.defaultLayer),j0.provide(e0.layer),j0.provide(tJ.defaultLayer),j0.provide(u0.defaultLayer),j0.provide(RJ.defaultLayer)),MQ=B.fn("Session.cancelBackgroundJobs")(function*(J,$){let Y=yield*J.list();yield*B.forEach(Y.filter((Z)=>{if(Z.status!=="running")return!1;if(Z.id===$)return!0;if(Z.metadata?.sessionId===$)return!0;return Z.metadata?.parentSessionId===$}),(Z)=>J.cancel(Z.id),{concurrency:"unbounded",discard:!0})});function*wQ(J){let $=[G0(V0.project_id,J.projectID)];if(J.workspaceID)$.push(G0(V0.workspace_id,J.workspaceID));if(J.path!==void 0){if(J.path){let V=[G0(V0.path,J.path),f5(V0.path,`${J.path}/%`)];$.push(J.directory?u$(...V,WJ(c$(V0.path),G0(V0.directory,J.directory))):u$(...V))}}else if(J.scope!=="project"&&!J.experimentalWorkspaces){if(J.directory)$.push(G0(V0.directory,J.directory))}if(J.roots)$.push(c$(V0.parent_id));if(J.start)$.push(t8(V0.time_updated,J.start));if(J.search)$.push(f5(V0.title,`%${J.search}%`));let Y=J.limit??100,Z=q0.use((V)=>V.select().from(V0).where(WJ(...$)).orderBy(xJ(V0.time_updated)).limit(Y).all());for(let V of Z)yield p$(V)}function*TQ(J){let $=[];if(J?.directory)$.push(G0(V0.directory,J.directory));if(J?.roots)$.push(c$(V0.parent_id));if(J?.start)$.push(t8(V0.time_updated,J.start));if(J?.cursor)$.push(g$(V0.time_updated,J.cursor));if(J?.search)$.push(f5(V0.title,`%${J.search}%`));if(!J?.archived)$.push(c$(V0.time_archived));let Y=J?.limit??100,Z=q0.use((U)=>{return($.length>0?U.select().from(V0).where(WJ(...$)):U.select().from(V0)).orderBy(xJ(V0.time_updated),xJ(V0.id)).limit(Y).all()}),V=[...new Set(Z.map((U)=>U.project_id))],X=new Map;if(V.length>0){let U=q0.use((F)=>F.select({id:j$.id,name:j$.name,worktree:j$.worktree}).from(j$).where(C5(j$.id,V)).all());for(let F of U)X.set(F.id,{id:F.id,name:F.name??void 0,worktree:F.worktree})}for(let U of Z){let F=X.get(U.project_id)??null;yield{...p$(U),project:F}}}
|
|
71
|
+
export{q5 as jn,k8 as kn,NX as ln,k$ as mn,W$ as nn,RX as on,GJ as pn,tJ as qn,bJ as rn,L5 as sn,T5 as tn,nJ as un,g0 as vn,Z5 as wn,u0 as xn,_Y as yn,f$ as zn,TX as An,FK as Bn,UK as Cn,fJ as Dn,kJ as En,m0 as Fn,b5 as Gn,YQ as Hn,p$ as In,ZQ as Jn,y5 as Kn,Y6 as Ln,c7 as Mn,FQ as Nn,UQ as On,KQ as Pn,GQ as Qn,WQ as Rn,zQ as Sn,HQ as Tn,jQ as Un,BQ as Vn,NQ as Wn,AQ as Xn,l$ as Yn,_Q as Zn,qQ as _n,p7 as $n,d$ as ao,EQ as bo,d7 as co,LQ as do,TQ as eo,Z6 as fo};
|