@linkshell/gateway 0.6.10 → 0.6.11
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/gateway/tsconfig.tsbuildinfo +1 -1
- package/dist/wire/src/questions.js +1 -1
- package/dist/wire/src/questions.js.map +1 -1
- package/package.json +2 -2
- package/web-client/assets/{Prototype-B_Ol8PFk.js → Prototype-jUvLvS7-.js} +1 -1
- package/web-client/assets/{index-0FecUgtS.js → index-E4E6ovrQ.js} +5 -5
- package/web-client/assets/{qr-scanner.min-3SiDiDF1.js → qr-scanner.min-CUJBiTnI.js} +1 -1
- package/web-client/index.html +1 -1
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/qr-scanner.min-
|
|
1
|
+
const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/qr-scanner.min-CUJBiTnI.js","assets/markdown-SZOrMO_3.js","assets/account-R7yD1rZE.js","assets/terminal-DWFexEE4.js","assets/terminal-DOrYoP_4.css","assets/Prototype-jUvLvS7-.js"])))=>i.map(i=>d[i]);
|
|
2
2
|
import{r as P1,g as kj,a as x,R as Qs,j as f,b as ml,M as Nj,c as Oj,d as Rj}from"./markdown-SZOrMO_3.js";import{_ as Hs,a as F1,b as Dj,c as Mj}from"./account-R7yD1rZE.js";import{D as zj,o as Ij}from"./terminal-DWFexEE4.js";(function(){const e=document.createElement("link").relList;if(e&&e.supports&&e.supports("modulepreload"))return;for(const o of document.querySelectorAll('link[rel="modulepreload"]'))r(o);new MutationObserver(o=>{for(const l of o)if(l.type==="childList")for(const u of l.addedNodes)u.tagName==="LINK"&&u.rel==="modulepreload"&&r(u)}).observe(document,{childList:!0,subtree:!0});function s(o){const l={};return o.integrity&&(l.integrity=o.integrity),o.referrerPolicy&&(l.referrerPolicy=o.referrerPolicy),o.crossOrigin==="use-credentials"?l.credentials="include":o.crossOrigin==="anonymous"?l.credentials="omit":l.credentials="same-origin",l}function r(o){if(o.ep)return;o.ep=!0;const l=s(o);fetch(o.href,l)}})();function G1(n){var e,s,r="";if(typeof n=="string"||typeof n=="number")r+=n;else if(typeof n=="object")if(Array.isArray(n)){var o=n.length;for(e=0;e<o;e++)n[e]&&(s=G1(n[e]))&&(r&&(r+=" "),r+=s)}else for(s in n)n[s]&&(r&&(r+=" "),r+=s);return r}function Z1(){for(var n,e,s=0,r="",o=arguments.length;s<o;s++)(n=arguments[s])&&(e=G1(n))&&(r&&(r+=" "),r+=e);return r}const Lj=(n,e)=>{const s=new Array(n.length+e.length);for(let r=0;r<n.length;r++)s[r]=n[r];for(let r=0;r<e.length;r++)s[n.length+r]=e[r];return s},Uj=(n,e)=>({classGroupId:n,validator:e}),Y1=(n=new Map,e=null,s)=>({nextPart:n,validators:e,classGroupId:s}),zu="-",Lb=[],Bj="arbitrary..",Hj=n=>{const e=Vj(n),{conflictingClassGroups:s,conflictingClassGroupModifiers:r}=n;return{getClassGroupId:u=>{if(u.startsWith("[")&&u.endsWith("]"))return $j(u);const d=u.split(zu),m=d[0]===""&&d.length>1?1:0;return K1(d,m,e)},getConflictingClassGroupIds:(u,d)=>{if(d){const m=r[u],p=s[u];return m?p?Lj(p,m):m:p||Lb}return s[u]||Lb}}},K1=(n,e,s)=>{if(n.length-e===0)return s.classGroupId;const o=n[e],l=s.nextPart.get(o);if(l){const p=K1(n,e+1,l);if(p)return p}const u=s.validators;if(u===null)return;const d=e===0?n.join(zu):n.slice(e).join(zu),m=u.length;for(let p=0;p<m;p++){const y=u[p];if(y.validator(d))return y.classGroupId}},$j=n=>n.slice(1,-1).indexOf(":")===-1?void 0:(()=>{const e=n.slice(1,-1),s=e.indexOf(":"),r=e.slice(0,s);return r?Bj+r:void 0})(),Vj=n=>{const{theme:e,classGroups:s}=n;return qj(s,e)},qj=(n,e)=>{const s=Y1();for(const r in n){const o=n[r];Up(o,s,r,e)}return s},Up=(n,e,s,r)=>{const o=n.length;for(let l=0;l<o;l++){const u=n[l];Pj(u,e,s,r)}},Pj=(n,e,s,r)=>{if(typeof n=="string"){Fj(n,e,s);return}if(typeof n=="function"){Gj(n,e,s,r);return}Zj(n,e,s,r)},Fj=(n,e,s)=>{const r=n===""?e:X1(e,n);r.classGroupId=s},Gj=(n,e,s,r)=>{if(Yj(n)){Up(n(r),e,s,r);return}e.validators===null&&(e.validators=[]),e.validators.push(Uj(s,n))},Zj=(n,e,s,r)=>{const o=Object.entries(n),l=o.length;for(let u=0;u<l;u++){const[d,m]=o[u];Up(m,X1(e,d),s,r)}},X1=(n,e)=>{let s=n;const r=e.split(zu),o=r.length;for(let l=0;l<o;l++){const u=r[l];let d=s.nextPart.get(u);d||(d=Y1(),s.nextPart.set(u,d)),s=d}return s},Yj=n=>"isThemeGetter"in n&&n.isThemeGetter===!0,Kj=n=>{if(n<1)return{get:()=>{},set:()=>{}};let e=0,s=Object.create(null),r=Object.create(null);const o=(l,u)=>{s[l]=u,e++,e>n&&(e=0,r=s,s=Object.create(null))};return{get(l){let u=s[l];if(u!==void 0)return u;if((u=r[l])!==void 0)return o(l,u),u},set(l,u){l in s?s[l]=u:o(l,u)}}},qm="!",Ub=":",Xj=[],Bb=(n,e,s,r,o)=>({modifiers:n,hasImportantModifier:e,baseClassName:s,maybePostfixModifierPosition:r,isExternal:o}),Qj=n=>{const{prefix:e,experimentalParseClassName:s}=n;let r=o=>{const l=[];let u=0,d=0,m=0,p;const y=o.length;for(let S=0;S<y;S++){const E=o[S];if(u===0&&d===0){if(E===Ub){l.push(o.slice(m,S)),m=S+1;continue}if(E==="/"){p=S;continue}}E==="["?u++:E==="]"?u--:E==="("?d++:E===")"&&d--}const v=l.length===0?o:o.slice(m);let b=v,C=!1;v.endsWith(qm)?(b=v.slice(0,-1),C=!0):v.startsWith(qm)&&(b=v.slice(1),C=!0);const T=p&&p>m?p-m:void 0;return Bb(l,C,b,T)};if(e){const o=e+Ub,l=r;r=u=>u.startsWith(o)?l(u.slice(o.length)):Bb(Xj,!1,u,void 0,!0)}if(s){const o=r;r=l=>s({className:l,parseClassName:o})}return r},Wj=n=>{const e=new Map;return n.orderSensitiveModifiers.forEach((s,r)=>{e.set(s,1e6+r)}),s=>{const r=[];let o=[];for(let l=0;l<s.length;l++){const u=s[l],d=u[0]==="[",m=e.has(u);d||m?(o.length>0&&(o.sort(),r.push(...o),o=[]),r.push(u)):o.push(u)}return o.length>0&&(o.sort(),r.push(...o)),r}},Jj=n=>({cache:Kj(n.cacheSize),parseClassName:Qj(n),sortModifiers:Wj(n),postfixLookupClassGroupIds:eA(n),...Hj(n)}),eA=n=>{const e=Object.create(null),s=n.postfixLookupClassGroups;if(s)for(let r=0;r<s.length;r++)e[s[r]]=!0;return e},tA=/\s+/,nA=(n,e)=>{const{parseClassName:s,getClassGroupId:r,getConflictingClassGroupIds:o,sortModifiers:l,postfixLookupClassGroupIds:u}=e,d=[],m=n.trim().split(tA);let p="";for(let y=m.length-1;y>=0;y-=1){const v=m[y],{isExternal:b,modifiers:C,hasImportantModifier:T,baseClassName:S,maybePostfixModifierPosition:E}=s(v);if(b){p=v+(p.length>0?" "+p:p);continue}let _=!!E,j;if(_){const M=S.substring(0,E);j=r(M);const R=j&&u[j]?r(S):void 0;R&&R!==j&&(j=R,_=!1)}else j=r(S);if(!j){if(!_){p=v+(p.length>0?" "+p:p);continue}if(j=r(S),!j){p=v+(p.length>0?" "+p:p);continue}_=!1}const N=C.length===0?"":C.length===1?C[0]:l(C).join(":"),z=T?N+qm:N,k=z+j;if(d.indexOf(k)>-1)continue;d.push(k);const O=o(j,_);for(let M=0;M<O.length;++M){const R=O[M];d.push(z+R)}p=v+(p.length>0?" "+p:p)}return p},aA=(...n)=>{let e=0,s,r,o="";for(;e<n.length;)(s=n[e++])&&(r=Q1(s))&&(o&&(o+=" "),o+=r);return o},Q1=n=>{if(typeof n=="string")return n;let e,s="";for(let r=0;r<n.length;r++)n[r]&&(e=Q1(n[r]))&&(s&&(s+=" "),s+=e);return s},sA=(n,...e)=>{let s,r,o,l;const u=m=>{const p=e.reduce((y,v)=>v(y),n());return s=Jj(p),r=s.cache.get,o=s.cache.set,l=d,d(m)},d=m=>{const p=r(m);if(p)return p;const y=nA(m,s);return o(m,y),y};return l=u,(...m)=>l(aA(...m))},rA=[],Ut=n=>{const e=s=>s[n]||rA;return e.isThemeGetter=!0,e.themeKey=n,e},W1=/^\[(?:(\w[\w-]*):)?(.+)\]$/i,J1=/^\((?:(\w[\w-]*):)?(.+)\)$/i,iA=/^\d+(?:\.\d+)?\/\d+(?:\.\d+)?$/,oA=/^(\d+(\.\d+)?)?(xs|sm|md|lg|xl)$/,lA=/\d+(%|px|r?em|[sdl]?v([hwib]|min|max)|pt|pc|in|cm|mm|cap|ch|ex|r?lh|cq(w|h|i|b|min|max))|\b(calc|min|max|clamp)\(.+\)|^0$/,cA=/^(rgba?|hsla?|hwb|(ok)?(lab|lch)|color-mix|color|light-dark)\(.+\)$/,uA=/^(inset_)?-?((\d+)?\.?(\d+)[a-z]+|0)_-?((\d+)?\.?(\d+)[a-z]+|0)/,dA=/^(url|image|image-set|cross-fade|element|(repeating-)?(linear|radial|conic)-gradient)\(.+\)$/,Os=n=>iA.test(n),qe=n=>!!n&&!Number.isNaN(Number(n)),la=n=>!!n&&Number.isInteger(Number(n)),sm=n=>n.endsWith("%")&&qe(n.slice(0,-1)),Va=n=>oA.test(n),ew=()=>!0,fA=n=>lA.test(n)&&!cA.test(n),Bp=()=>!1,hA=n=>uA.test(n),mA=n=>dA.test(n),pA=n=>!be(n)&&!we(n),gA=n=>n.startsWith("@container")&&(n[10]==="/"&&n[11]!==void 0||n[11]==="s"&&n[16]!==void 0&&n.startsWith("-size/",10)||n[11]==="n"&&n[18]!==void 0&&n.startsWith("-normal/",10)),vA=n=>Ws(n,aw,Bp),be=n=>W1.test(n),Sr=n=>Ws(n,sw,fA),Hb=n=>Ws(n,_A,qe),yA=n=>Ws(n,iw,ew),bA=n=>Ws(n,rw,Bp),$b=n=>Ws(n,tw,Bp),xA=n=>Ws(n,nw,mA),iu=n=>Ws(n,ow,hA),we=n=>J1.test(n),ll=n=>Fr(n,sw),wA=n=>Fr(n,rw),Vb=n=>Fr(n,tw),SA=n=>Fr(n,aw),EA=n=>Fr(n,nw),ou=n=>Fr(n,ow,!0),CA=n=>Fr(n,iw,!0),Ws=(n,e,s)=>{const r=W1.exec(n);return r?r[1]?e(r[1]):s(r[2]):!1},Fr=(n,e,s=!1)=>{const r=J1.exec(n);return r?r[1]?e(r[1]):s:!1},tw=n=>n==="position"||n==="percentage",nw=n=>n==="image"||n==="url",aw=n=>n==="length"||n==="size"||n==="bg-size",sw=n=>n==="length",_A=n=>n==="number",rw=n=>n==="family-name",iw=n=>n==="number"||n==="weight",ow=n=>n==="shadow",jA=()=>{const n=Ut("color"),e=Ut("font"),s=Ut("text"),r=Ut("font-weight"),o=Ut("tracking"),l=Ut("leading"),u=Ut("breakpoint"),d=Ut("container"),m=Ut("spacing"),p=Ut("radius"),y=Ut("shadow"),v=Ut("inset-shadow"),b=Ut("text-shadow"),C=Ut("drop-shadow"),T=Ut("blur"),S=Ut("perspective"),E=Ut("aspect"),_=Ut("ease"),j=Ut("animate"),N=()=>["auto","avoid","all","avoid-page","page","left","right","column"],z=()=>["center","top","bottom","left","right","top-left","left-top","top-right","right-top","bottom-right","right-bottom","bottom-left","left-bottom"],k=()=>[...z(),we,be],O=()=>["auto","hidden","clip","visible","scroll"],M=()=>["auto","contain","none"],R=()=>[we,be,m],L=()=>[Os,"full","auto",...R()],H=()=>[la,"none","subgrid",we,be],V=()=>["auto",{span:["full",la,we,be]},la,we,be],q=()=>[la,"auto",we,be],P=()=>["auto","min","max","fr",we,be],J=()=>["start","end","center","between","around","evenly","stretch","baseline","center-safe","end-safe"],ie=()=>["start","end","center","stretch","center-safe","end-safe"],U=()=>["auto",...R()],G=()=>[Os,"auto","full","dvw","dvh","lvw","lvh","svw","svh","min","max","fit",...R()],W=()=>[d,Os,"screen","full","dvw","lvw","svw","min","max","fit",...R()],te=()=>[Os,"screen","full","lh","dvh","lvh","svh","min","max","fit",...R()],X=()=>[n,we,be],ge=()=>[...z(),Vb,$b,{position:[we,be]}],Z=()=>["no-repeat",{repeat:["","x","y","space","round"]}],ee=()=>["auto","cover","contain",SA,vA,{size:[we,be]}],fe=()=>[sm,ll,Sr],ue=()=>["","none","full",p,we,be],oe=()=>["",qe,ll,Sr],Ce=()=>["solid","dashed","dotted","double"],me=()=>["normal","multiply","screen","overlay","darken","lighten","color-dodge","color-burn","hard-light","soft-light","difference","exclusion","hue","saturation","color","luminosity"],he=()=>[qe,sm,Vb,$b],He=()=>["","none",T,we,be],ke=()=>["none",qe,we,be],De=()=>["none",qe,we,be],$e=()=>[qe,we,be],ze=()=>[Os,"full",...R()];return{cacheSize:500,theme:{animate:["spin","ping","pulse","bounce"],aspect:["video"],blur:[Va],breakpoint:[Va],color:[ew],container:[Va],"drop-shadow":[Va],ease:["in","out","in-out"],font:[pA],"font-weight":["thin","extralight","light","normal","medium","semibold","bold","extrabold","black"],"inset-shadow":[Va],leading:["none","tight","snug","normal","relaxed","loose"],perspective:["dramatic","near","normal","midrange","distant","none"],radius:[Va],shadow:[Va],spacing:["px",qe],text:[Va],"text-shadow":[Va],tracking:["tighter","tight","normal","wide","wider","widest"]},classGroups:{aspect:[{aspect:["auto","square",Os,be,we,E]}],container:["container"],"container-type":[{"@container":["","normal","size",we,be]}],"container-named":[gA],columns:[{columns:[qe,"auto",be,we,d]}],"break-after":[{"break-after":N()}],"break-before":[{"break-before":N()}],"break-inside":[{"break-inside":["auto","avoid","avoid-page","avoid-column"]}],"box-decoration":[{"box-decoration":["slice","clone"]}],box:[{box:["border","content"]}],display:["block","inline-block","inline","flex","inline-flex","table","inline-table","table-caption","table-cell","table-column","table-column-group","table-footer-group","table-header-group","table-row-group","table-row","flow-root","grid","inline-grid","contents","list-item","hidden"],sr:["sr-only","not-sr-only"],float:[{float:["right","left","none","start","end"]}],clear:[{clear:["left","right","both","none","start","end"]}],isolation:["isolate","isolation-auto"],"object-fit":[{object:["contain","cover","fill","none","scale-down"]}],"object-position":[{object:k()}],overflow:[{overflow:O()}],"overflow-x":[{"overflow-x":O()}],"overflow-y":[{"overflow-y":O()}],overscroll:[{overscroll:M()}],"overscroll-x":[{"overscroll-x":M()}],"overscroll-y":[{"overscroll-y":M()}],position:["static","fixed","absolute","relative","sticky"],inset:[{inset:L()}],"inset-x":[{"inset-x":L()}],"inset-y":[{"inset-y":L()}],start:[{"inset-s":L(),start:L()}],end:[{"inset-e":L(),end:L()}],"inset-bs":[{"inset-bs":L()}],"inset-be":[{"inset-be":L()}],top:[{top:L()}],right:[{right:L()}],bottom:[{bottom:L()}],left:[{left:L()}],visibility:["visible","invisible","collapse"],z:[{z:[la,"auto",we,be]}],basis:[{basis:[Os,"full","auto",d,...R()]}],"flex-direction":[{flex:["row","row-reverse","col","col-reverse"]}],"flex-wrap":[{flex:["nowrap","wrap","wrap-reverse"]}],flex:[{flex:[qe,Os,"auto","initial","none",be]}],grow:[{grow:["",qe,we,be]}],shrink:[{shrink:["",qe,we,be]}],order:[{order:[la,"first","last","none",we,be]}],"grid-cols":[{"grid-cols":H()}],"col-start-end":[{col:V()}],"col-start":[{"col-start":q()}],"col-end":[{"col-end":q()}],"grid-rows":[{"grid-rows":H()}],"row-start-end":[{row:V()}],"row-start":[{"row-start":q()}],"row-end":[{"row-end":q()}],"grid-flow":[{"grid-flow":["row","col","dense","row-dense","col-dense"]}],"auto-cols":[{"auto-cols":P()}],"auto-rows":[{"auto-rows":P()}],gap:[{gap:R()}],"gap-x":[{"gap-x":R()}],"gap-y":[{"gap-y":R()}],"justify-content":[{justify:[...J(),"normal"]}],"justify-items":[{"justify-items":[...ie(),"normal"]}],"justify-self":[{"justify-self":["auto",...ie()]}],"align-content":[{content:["normal",...J()]}],"align-items":[{items:[...ie(),{baseline:["","last"]}]}],"align-self":[{self:["auto",...ie(),{baseline:["","last"]}]}],"place-content":[{"place-content":J()}],"place-items":[{"place-items":[...ie(),"baseline"]}],"place-self":[{"place-self":["auto",...ie()]}],p:[{p:R()}],px:[{px:R()}],py:[{py:R()}],ps:[{ps:R()}],pe:[{pe:R()}],pbs:[{pbs:R()}],pbe:[{pbe:R()}],pt:[{pt:R()}],pr:[{pr:R()}],pb:[{pb:R()}],pl:[{pl:R()}],m:[{m:U()}],mx:[{mx:U()}],my:[{my:U()}],ms:[{ms:U()}],me:[{me:U()}],mbs:[{mbs:U()}],mbe:[{mbe:U()}],mt:[{mt:U()}],mr:[{mr:U()}],mb:[{mb:U()}],ml:[{ml:U()}],"space-x":[{"space-x":R()}],"space-x-reverse":["space-x-reverse"],"space-y":[{"space-y":R()}],"space-y-reverse":["space-y-reverse"],size:[{size:G()}],"inline-size":[{inline:["auto",...W()]}],"min-inline-size":[{"min-inline":["auto",...W()]}],"max-inline-size":[{"max-inline":["none",...W()]}],"block-size":[{block:["auto",...te()]}],"min-block-size":[{"min-block":["auto",...te()]}],"max-block-size":[{"max-block":["none",...te()]}],w:[{w:[d,"screen",...G()]}],"min-w":[{"min-w":[d,"screen","none",...G()]}],"max-w":[{"max-w":[d,"screen","none","prose",{screen:[u]},...G()]}],h:[{h:["screen","lh",...G()]}],"min-h":[{"min-h":["screen","lh","none",...G()]}],"max-h":[{"max-h":["screen","lh","none",...G()]}],"font-size":[{text:["base",s,ll,Sr]}],"font-smoothing":["antialiased","subpixel-antialiased"],"font-style":["italic","not-italic"],"font-weight":[{font:[r,CA,yA]}],"font-stretch":[{"font-stretch":["ultra-condensed","extra-condensed","condensed","semi-condensed","normal","semi-expanded","expanded","extra-expanded","ultra-expanded",sm,be]}],"font-family":[{font:[wA,bA,e]}],"font-features":[{"font-features":[be]}],"fvn-normal":["normal-nums"],"fvn-ordinal":["ordinal"],"fvn-slashed-zero":["slashed-zero"],"fvn-figure":["lining-nums","oldstyle-nums"],"fvn-spacing":["proportional-nums","tabular-nums"],"fvn-fraction":["diagonal-fractions","stacked-fractions"],tracking:[{tracking:[o,we,be]}],"line-clamp":[{"line-clamp":[qe,"none",we,Hb]}],leading:[{leading:["none",l,...R()]}],"list-image":[{"list-image":["none",we,be]}],"list-style-position":[{list:["inside","outside"]}],"list-style-type":[{list:["disc","decimal","none",we,be]}],"text-alignment":[{text:["left","center","right","justify","start","end"]}],"placeholder-color":[{placeholder:X()}],"text-color":[{text:X()}],"text-decoration":["underline","overline","line-through","no-underline"],"text-decoration-style":[{decoration:[...Ce(),"wavy"]}],"text-decoration-thickness":[{decoration:[qe,"from-font","auto",we,Sr]}],"text-decoration-color":[{decoration:X()}],"underline-offset":[{"underline-offset":[qe,"auto",we,be]}],"text-transform":["uppercase","lowercase","capitalize","normal-case"],"text-overflow":["truncate","text-ellipsis","text-clip"],"text-wrap":[{text:["wrap","nowrap","balance","pretty"]}],indent:[{indent:R()}],"tab-size":[{tab:[la,we,be]}],"vertical-align":[{align:["baseline","top","middle","bottom","text-top","text-bottom","sub","super",we,be]}],whitespace:[{whitespace:["normal","nowrap","pre","pre-line","pre-wrap","break-spaces"]}],break:[{break:["normal","words","all","keep"]}],wrap:[{wrap:["break-word","anywhere","normal"]}],hyphens:[{hyphens:["none","manual","auto"]}],content:[{content:["none",we,be]}],"bg-attachment":[{bg:["fixed","local","scroll"]}],"bg-clip":[{"bg-clip":["border","padding","content","text"]}],"bg-origin":[{"bg-origin":["border","padding","content"]}],"bg-position":[{bg:ge()}],"bg-repeat":[{bg:Z()}],"bg-size":[{bg:ee()}],"bg-image":[{bg:["none",{linear:[{to:["t","tr","r","br","b","bl","l","tl"]},la,we,be],radial:["",we,be],conic:["",la,we,be]},EA,xA]}],"bg-color":[{bg:X()}],"gradient-from-pos":[{from:fe()}],"gradient-via-pos":[{via:fe()}],"gradient-to-pos":[{to:fe()}],"gradient-from":[{from:X()}],"gradient-via":[{via:X()}],"gradient-to":[{to:X()}],rounded:[{rounded:ue()}],"rounded-s":[{"rounded-s":ue()}],"rounded-e":[{"rounded-e":ue()}],"rounded-t":[{"rounded-t":ue()}],"rounded-r":[{"rounded-r":ue()}],"rounded-b":[{"rounded-b":ue()}],"rounded-l":[{"rounded-l":ue()}],"rounded-ss":[{"rounded-ss":ue()}],"rounded-se":[{"rounded-se":ue()}],"rounded-ee":[{"rounded-ee":ue()}],"rounded-es":[{"rounded-es":ue()}],"rounded-tl":[{"rounded-tl":ue()}],"rounded-tr":[{"rounded-tr":ue()}],"rounded-br":[{"rounded-br":ue()}],"rounded-bl":[{"rounded-bl":ue()}],"border-w":[{border:oe()}],"border-w-x":[{"border-x":oe()}],"border-w-y":[{"border-y":oe()}],"border-w-s":[{"border-s":oe()}],"border-w-e":[{"border-e":oe()}],"border-w-bs":[{"border-bs":oe()}],"border-w-be":[{"border-be":oe()}],"border-w-t":[{"border-t":oe()}],"border-w-r":[{"border-r":oe()}],"border-w-b":[{"border-b":oe()}],"border-w-l":[{"border-l":oe()}],"divide-x":[{"divide-x":oe()}],"divide-x-reverse":["divide-x-reverse"],"divide-y":[{"divide-y":oe()}],"divide-y-reverse":["divide-y-reverse"],"border-style":[{border:[...Ce(),"hidden","none"]}],"divide-style":[{divide:[...Ce(),"hidden","none"]}],"border-color":[{border:X()}],"border-color-x":[{"border-x":X()}],"border-color-y":[{"border-y":X()}],"border-color-s":[{"border-s":X()}],"border-color-e":[{"border-e":X()}],"border-color-bs":[{"border-bs":X()}],"border-color-be":[{"border-be":X()}],"border-color-t":[{"border-t":X()}],"border-color-r":[{"border-r":X()}],"border-color-b":[{"border-b":X()}],"border-color-l":[{"border-l":X()}],"divide-color":[{divide:X()}],"outline-style":[{outline:[...Ce(),"none","hidden"]}],"outline-offset":[{"outline-offset":[qe,we,be]}],"outline-w":[{outline:["",qe,ll,Sr]}],"outline-color":[{outline:X()}],shadow:[{shadow:["","inner","none",y,ou,iu]}],"shadow-color":[{shadow:X()}],"inset-shadow":[{"inset-shadow":["none",v,ou,iu]}],"inset-shadow-color":[{"inset-shadow":X()}],"ring-w":[{ring:oe()}],"ring-w-inset":["ring-inset"],"ring-color":[{ring:X()}],"ring-offset-w":[{"ring-offset":[qe,Sr]}],"ring-offset-color":[{"ring-offset":X()}],"inset-ring-w":[{"inset-ring":oe()}],"inset-ring-color":[{"inset-ring":X()}],"text-shadow":[{"text-shadow":["none",b,ou,iu]}],"text-shadow-color":[{"text-shadow":X()}],opacity:[{opacity:[qe,we,be]}],"mix-blend":[{"mix-blend":[...me(),"plus-darker","plus-lighter"]}],"bg-blend":[{"bg-blend":me()}],"mask-clip":[{"mask-clip":["border","padding","content","fill","stroke","view"]},"mask-no-clip"],"mask-composite":[{mask:["add","subtract","intersect","exclude"]}],"mask-image-linear-pos":[{"mask-linear":[qe]}],"mask-image-linear-from-pos":[{"mask-linear-from":he()}],"mask-image-linear-to-pos":[{"mask-linear-to":he()}],"mask-image-linear-from-color":[{"mask-linear-from":X()}],"mask-image-linear-to-color":[{"mask-linear-to":X()}],"mask-image-t-from-pos":[{"mask-t-from":he()}],"mask-image-t-to-pos":[{"mask-t-to":he()}],"mask-image-t-from-color":[{"mask-t-from":X()}],"mask-image-t-to-color":[{"mask-t-to":X()}],"mask-image-r-from-pos":[{"mask-r-from":he()}],"mask-image-r-to-pos":[{"mask-r-to":he()}],"mask-image-r-from-color":[{"mask-r-from":X()}],"mask-image-r-to-color":[{"mask-r-to":X()}],"mask-image-b-from-pos":[{"mask-b-from":he()}],"mask-image-b-to-pos":[{"mask-b-to":he()}],"mask-image-b-from-color":[{"mask-b-from":X()}],"mask-image-b-to-color":[{"mask-b-to":X()}],"mask-image-l-from-pos":[{"mask-l-from":he()}],"mask-image-l-to-pos":[{"mask-l-to":he()}],"mask-image-l-from-color":[{"mask-l-from":X()}],"mask-image-l-to-color":[{"mask-l-to":X()}],"mask-image-x-from-pos":[{"mask-x-from":he()}],"mask-image-x-to-pos":[{"mask-x-to":he()}],"mask-image-x-from-color":[{"mask-x-from":X()}],"mask-image-x-to-color":[{"mask-x-to":X()}],"mask-image-y-from-pos":[{"mask-y-from":he()}],"mask-image-y-to-pos":[{"mask-y-to":he()}],"mask-image-y-from-color":[{"mask-y-from":X()}],"mask-image-y-to-color":[{"mask-y-to":X()}],"mask-image-radial":[{"mask-radial":[we,be]}],"mask-image-radial-from-pos":[{"mask-radial-from":he()}],"mask-image-radial-to-pos":[{"mask-radial-to":he()}],"mask-image-radial-from-color":[{"mask-radial-from":X()}],"mask-image-radial-to-color":[{"mask-radial-to":X()}],"mask-image-radial-shape":[{"mask-radial":["circle","ellipse"]}],"mask-image-radial-size":[{"mask-radial":[{closest:["side","corner"],farthest:["side","corner"]}]}],"mask-image-radial-pos":[{"mask-radial-at":z()}],"mask-image-conic-pos":[{"mask-conic":[qe]}],"mask-image-conic-from-pos":[{"mask-conic-from":he()}],"mask-image-conic-to-pos":[{"mask-conic-to":he()}],"mask-image-conic-from-color":[{"mask-conic-from":X()}],"mask-image-conic-to-color":[{"mask-conic-to":X()}],"mask-mode":[{mask:["alpha","luminance","match"]}],"mask-origin":[{"mask-origin":["border","padding","content","fill","stroke","view"]}],"mask-position":[{mask:ge()}],"mask-repeat":[{mask:Z()}],"mask-size":[{mask:ee()}],"mask-type":[{"mask-type":["alpha","luminance"]}],"mask-image":[{mask:["none",we,be]}],filter:[{filter:["","none",we,be]}],blur:[{blur:He()}],brightness:[{brightness:[qe,we,be]}],contrast:[{contrast:[qe,we,be]}],"drop-shadow":[{"drop-shadow":["","none",C,ou,iu]}],"drop-shadow-color":[{"drop-shadow":X()}],grayscale:[{grayscale:["",qe,we,be]}],"hue-rotate":[{"hue-rotate":[qe,we,be]}],invert:[{invert:["",qe,we,be]}],saturate:[{saturate:[qe,we,be]}],sepia:[{sepia:["",qe,we,be]}],"backdrop-filter":[{"backdrop-filter":["","none",we,be]}],"backdrop-blur":[{"backdrop-blur":He()}],"backdrop-brightness":[{"backdrop-brightness":[qe,we,be]}],"backdrop-contrast":[{"backdrop-contrast":[qe,we,be]}],"backdrop-grayscale":[{"backdrop-grayscale":["",qe,we,be]}],"backdrop-hue-rotate":[{"backdrop-hue-rotate":[qe,we,be]}],"backdrop-invert":[{"backdrop-invert":["",qe,we,be]}],"backdrop-opacity":[{"backdrop-opacity":[qe,we,be]}],"backdrop-saturate":[{"backdrop-saturate":[qe,we,be]}],"backdrop-sepia":[{"backdrop-sepia":["",qe,we,be]}],"border-collapse":[{border:["collapse","separate"]}],"border-spacing":[{"border-spacing":R()}],"border-spacing-x":[{"border-spacing-x":R()}],"border-spacing-y":[{"border-spacing-y":R()}],"table-layout":[{table:["auto","fixed"]}],caption:[{caption:["top","bottom"]}],transition:[{transition:["","all","colors","opacity","shadow","transform","none",we,be]}],"transition-behavior":[{transition:["normal","discrete"]}],duration:[{duration:[qe,"initial",we,be]}],ease:[{ease:["linear","initial",_,we,be]}],delay:[{delay:[qe,we,be]}],animate:[{animate:["none",j,we,be]}],backface:[{backface:["hidden","visible"]}],perspective:[{perspective:[S,we,be]}],"perspective-origin":[{"perspective-origin":k()}],rotate:[{rotate:ke()}],"rotate-x":[{"rotate-x":ke()}],"rotate-y":[{"rotate-y":ke()}],"rotate-z":[{"rotate-z":ke()}],scale:[{scale:De()}],"scale-x":[{"scale-x":De()}],"scale-y":[{"scale-y":De()}],"scale-z":[{"scale-z":De()}],"scale-3d":["scale-3d"],skew:[{skew:$e()}],"skew-x":[{"skew-x":$e()}],"skew-y":[{"skew-y":$e()}],transform:[{transform:[we,be,"","none","gpu","cpu"]}],"transform-origin":[{origin:k()}],"transform-style":[{transform:["3d","flat"]}],translate:[{translate:ze()}],"translate-x":[{"translate-x":ze()}],"translate-y":[{"translate-y":ze()}],"translate-z":[{"translate-z":ze()}],"translate-none":["translate-none"],zoom:[{zoom:[la,we,be]}],accent:[{accent:X()}],appearance:[{appearance:["none","auto"]}],"caret-color":[{caret:X()}],"color-scheme":[{scheme:["normal","dark","light","light-dark","only-dark","only-light"]}],cursor:[{cursor:["auto","default","pointer","wait","text","move","help","not-allowed","none","context-menu","progress","cell","crosshair","vertical-text","alias","copy","no-drop","grab","grabbing","all-scroll","col-resize","row-resize","n-resize","e-resize","s-resize","w-resize","ne-resize","nw-resize","se-resize","sw-resize","ew-resize","ns-resize","nesw-resize","nwse-resize","zoom-in","zoom-out",we,be]}],"field-sizing":[{"field-sizing":["fixed","content"]}],"pointer-events":[{"pointer-events":["auto","none"]}],resize:[{resize:["none","","y","x"]}],"scroll-behavior":[{scroll:["auto","smooth"]}],"scrollbar-thumb-color":[{"scrollbar-thumb":X()}],"scrollbar-track-color":[{"scrollbar-track":X()}],"scrollbar-gutter":[{"scrollbar-gutter":["auto","stable","both"]}],"scrollbar-w":[{scrollbar:["auto","thin","none"]}],"scroll-m":[{"scroll-m":R()}],"scroll-mx":[{"scroll-mx":R()}],"scroll-my":[{"scroll-my":R()}],"scroll-ms":[{"scroll-ms":R()}],"scroll-me":[{"scroll-me":R()}],"scroll-mbs":[{"scroll-mbs":R()}],"scroll-mbe":[{"scroll-mbe":R()}],"scroll-mt":[{"scroll-mt":R()}],"scroll-mr":[{"scroll-mr":R()}],"scroll-mb":[{"scroll-mb":R()}],"scroll-ml":[{"scroll-ml":R()}],"scroll-p":[{"scroll-p":R()}],"scroll-px":[{"scroll-px":R()}],"scroll-py":[{"scroll-py":R()}],"scroll-ps":[{"scroll-ps":R()}],"scroll-pe":[{"scroll-pe":R()}],"scroll-pbs":[{"scroll-pbs":R()}],"scroll-pbe":[{"scroll-pbe":R()}],"scroll-pt":[{"scroll-pt":R()}],"scroll-pr":[{"scroll-pr":R()}],"scroll-pb":[{"scroll-pb":R()}],"scroll-pl":[{"scroll-pl":R()}],"snap-align":[{snap:["start","end","center","align-none"]}],"snap-stop":[{snap:["normal","always"]}],"snap-type":[{snap:["none","x","y","both"]}],"snap-strictness":[{snap:["mandatory","proximity"]}],touch:[{touch:["auto","none","manipulation"]}],"touch-x":[{"touch-pan":["x","left","right"]}],"touch-y":[{"touch-pan":["y","up","down"]}],"touch-pz":["touch-pinch-zoom"],select:[{select:["none","text","all","auto"]}],"will-change":[{"will-change":["auto","scroll","contents","transform",we,be]}],fill:[{fill:["none",...X()]}],"stroke-w":[{stroke:[qe,ll,Sr,Hb]}],stroke:[{stroke:["none",...X()]}],"forced-color-adjust":[{"forced-color-adjust":["auto","none"]}]},conflictingClassGroups:{"container-named":["container-type"],overflow:["overflow-x","overflow-y"],overscroll:["overscroll-x","overscroll-y"],inset:["inset-x","inset-y","inset-bs","inset-be","start","end","top","right","bottom","left"],"inset-x":["start","end","right","left"],"inset-y":["inset-bs","inset-be","top","bottom"],flex:["basis","grow","shrink"],gap:["gap-x","gap-y"],p:["px","py","ps","pe","pbs","pbe","pt","pr","pb","pl"],px:["ps","pe","pr","pl"],py:["pbs","pbe","pt","pb"],m:["mx","my","ms","me","mbs","mbe","mt","mr","mb","ml"],mx:["ms","me","mr","ml"],my:["mbs","mbe","mt","mb"],size:["w","h"],"font-size":["leading"],"fvn-normal":["fvn-ordinal","fvn-slashed-zero","fvn-figure","fvn-spacing","fvn-fraction"],"fvn-ordinal":["fvn-normal"],"fvn-slashed-zero":["fvn-normal"],"fvn-figure":["fvn-normal"],"fvn-spacing":["fvn-normal"],"fvn-fraction":["fvn-normal"],"line-clamp":["display","overflow"],rounded:["rounded-s","rounded-e","rounded-t","rounded-r","rounded-b","rounded-l","rounded-ss","rounded-se","rounded-ee","rounded-es","rounded-tl","rounded-tr","rounded-br","rounded-bl"],"rounded-s":["rounded-ss","rounded-es"],"rounded-e":["rounded-se","rounded-ee"],"rounded-t":["rounded-tl","rounded-tr"],"rounded-r":["rounded-tr","rounded-br"],"rounded-b":["rounded-br","rounded-bl"],"rounded-l":["rounded-tl","rounded-bl"],"border-spacing":["border-spacing-x","border-spacing-y"],"border-w":["border-w-x","border-w-y","border-w-s","border-w-e","border-w-bs","border-w-be","border-w-t","border-w-r","border-w-b","border-w-l"],"border-w-x":["border-w-s","border-w-e","border-w-r","border-w-l"],"border-w-y":["border-w-bs","border-w-be","border-w-t","border-w-b"],"border-color":["border-color-x","border-color-y","border-color-s","border-color-e","border-color-bs","border-color-be","border-color-t","border-color-r","border-color-b","border-color-l"],"border-color-x":["border-color-s","border-color-e","border-color-r","border-color-l"],"border-color-y":["border-color-bs","border-color-be","border-color-t","border-color-b"],translate:["translate-x","translate-y","translate-none"],"translate-none":["translate","translate-x","translate-y","translate-z"],"scroll-m":["scroll-mx","scroll-my","scroll-ms","scroll-me","scroll-mbs","scroll-mbe","scroll-mt","scroll-mr","scroll-mb","scroll-ml"],"scroll-mx":["scroll-ms","scroll-me","scroll-mr","scroll-ml"],"scroll-my":["scroll-mbs","scroll-mbe","scroll-mt","scroll-mb"],"scroll-p":["scroll-px","scroll-py","scroll-ps","scroll-pe","scroll-pbs","scroll-pbe","scroll-pt","scroll-pr","scroll-pb","scroll-pl"],"scroll-px":["scroll-ps","scroll-pe","scroll-pr","scroll-pl"],"scroll-py":["scroll-pbs","scroll-pbe","scroll-pt","scroll-pb"],touch:["touch-x","touch-y","touch-pz"],"touch-x":["touch"],"touch-y":["touch"],"touch-pz":["touch"]},conflictingClassGroupModifiers:{"font-size":["leading"]},postfixLookupClassGroups:["container-type"],orderSensitiveModifiers:["*","**","after","backdrop","before","details-content","file","first-letter","first-line","marker","placeholder","selection"]}},AA=sA(jA);function Pe(...n){return AA(Z1(n))}var rm={exports:{}},Jt={};/**
|
|
3
3
|
* @license React
|
|
4
4
|
* react-dom.production.js
|
|
@@ -151,14 +151,14 @@ ${JSON.stringify(e)}
|
|
|
151
151
|
</send_user_message_question_reply>
|
|
152
152
|
`}function _2(n){const e=/^<send_user_message_question_reply>\s*([\s\S]+?)\s*<\/send_user_message_question_reply>$/.exec(n.replace(/\r\n/g,`
|
|
153
153
|
`).trim());if(!e)return;let s;try{s=JSON.parse(e[1])}catch{return}const r=Array.isArray(s)?s:[s];if(r.length===0)return;const o=[];for(const l of r){if(!l||typeof l!="object")return;const{questionItemId:u,question:d,answer:m}=l;if(typeof d!="string"||typeof m!="string")return;o.push({...typeof u=="string"?{id:u}:{},question:d.trim(),answer:m.trim()})}return o}function oO(n){return(_2(n)??[]).flatMap(e=>e.id?[[e.id,e.answer]]:[])}const lO=Me(["running","paused","completed","failed","stopped"]),xg=Me(["pending","running","paused","completed","failed","stopped","unknown"]),cO=I({id:A(),toolCallId:A().optional(),title:A(),state:xg,phaseId:A().optional(),model:A().optional(),tokens:se().nonnegative().optional(),toolCalls:se().int().nonnegative().optional(),durationMs:se().nonnegative().optional(),startedAt:se().optional(),endedAt:se().optional(),result:A().optional()}),uO=I({id:A(),title:A(),order:se()}),j2=I({runId:A().optional(),name:A().optional(),state:lO.optional(),started:se().int().nonnegative().optional(),completed:se().int().nonnegative().optional(),tokens:se().nonnegative().optional(),durationMs:se().nonnegative().optional(),startedAt:se().optional(),endedAt:se().optional(),phases:xe(uO).optional(),agents:xe(cO).optional()}),Bn=A().nullish().transform(n=>n??void 0),A2=Ji(jn()).nullish().transform(n=>n??void 0),ul={annotations:I({audience:xe(Me(["user","assistant"])).nullish().transform(n=>n??void 0),priority:se().nullish().transform(n=>n??void 0),lastModified:Bn}).passthrough().nullish().transform(n=>n??void 0),_meta:A2},dO=wa("type",[I({type:pe("text"),text:A(),...ul}),I({type:pe("image"),mimeType:A(),data:Bn,uri:Bn,...ul}),I({type:pe("audio"),mimeType:A(),data:Bn,uri:Bn,...ul}),I({type:pe("resource"),resource:I({uri:A(),mimeType:Bn,text:Bn,blob:Bn,assetUri:Bn,_meta:A2}),...ul}),I({type:pe("resource_link"),uri:A(),name:A(),title:Bn,description:Bn,mimeType:Bn,size:se().nullish().transform(n=>n??void 0),...ul,kind:Me(["file","skill","agent"]).optional()})]),kr=dO,$x=Me(["pending","in_progress","completed","failed"]),Nu=wa("type",[I({type:pe("content"),content:kr}),I({type:pe("diff"),path:A(),oldText:A().nullable().optional(),newText:A()}),I({type:pe("patch"),path:A(),change:Me(["add","delete","update"]),movePath:A().optional(),diff:A()}),I({type:pe("terminal"),terminalId:A()})]),fO=Me(["multi_client","handoff","remote","terminal"]),hO=I({interrupt:ye(),steer:ye(),permissions:ye(),images:ye(),audio:ye().optional(),embeddedContext:ye().optional(),acp:ye().optional(),fork:ye(),models:ye(),modes:ye()}),mO=I({state:Me(["ok","missing","unknown"]),method:A().optional(),hint:A().optional()}),T2=I({id:A().min(1),label:A().min(1),tier:fO,installed:ye(),version:A().optional(),problem:A().optional(),auth:mO.optional(),capabilities:hO}),Ju=Me(["desktop","remote","none"]),k2=Me(["idle","running","waiting","error","offline","unknown"]),xl=Me(["read","edit","delete","move","search","execute","think","fetch","switch_mode","other"]),N2=I({optionId:A().min(1),name:A().min(1),kind:Me(["allow_once","allow_always","reject_once","reject_always"])}),pO=I({kind:Me(["thinking","responding","tool"]),title:A().optional(),toolKind:xl.optional()}),O2=I({id:A(),constraints:I({type:Me(["string","number","integer","boolean","array"]),minimum:se().optional(),maximum:se().optional(),minLength:se().int().nonnegative().optional(),maxLength:se().int().nonnegative().optional(),minItems:se().int().nonnegative().optional(),maxItems:se().int().nonnegative().optional(),pattern:A().optional(),format:A().optional()}).optional(),defaults:xe(A()).optional(),header:A().optional(),text:A(),kind:Me(["choice","choices","text"]),options:xe(I({value:A(),label:A(),description:A().optional()})).optional(),other:ye().optional(),secret:ye().optional(),required:ye().optional()}),wg=I({id:A(),values:xe(A().max(2e4)).max(50),other:A().max(2e4).optional()}),ed=I({requestId:A(),childSessionId:A().optional(),toolCallId:A().optional(),title:A(),detail:A().optional(),tool:I({title:A().optional(),kind:xl.optional(),rawInput:jn().optional(),content:xe(Nu).optional(),locations:xe(I({path:A(),line:se().int().optional()})).optional()}).optional(),url:I({url:A(),elicitationId:A()}).optional(),options:xe(N2).min(1),questions:xe(O2).optional()}),gO=I({clientMessageId:A(),text:A(),images:se().int().nonnegative()}),vO=I({nativeSessionId:A().optional(),canCancel:ye().optional(),toolCallId:A(),parentToolCallId:A().optional(),task:A(),agentType:A().optional(),name:A().optional(),running:ye(),failed:ye().optional(),startedAt:se(),endedAt:se().optional(),state:xg.optional(),workflow:j2.optional(),lastSeq:se().int().nonnegative().optional()}),yO=Me(["running","completed","failed","stopped","unknown"]),R2=I({id:A(),kind:Me(["shell","monitor"]),toolCallId:A().optional(),title:A(),command:A().optional(),state:yO,startedAt:se(),endedAt:se().optional(),summary:A().optional(),exitCode:se().int().optional(),output:ye().optional(),canStop:ye().optional(),lastSeq:se().int().nonnegative().optional()}),_r=I({id:A().min(1),agent:A().min(1),nativeId:A().min(1),title:A().optional(),preview:A().optional(),cwd:A(),state:k2,driver:Ju.optional(),pendingPermissions:se().int().nonnegative(),model:A().optional(),createdAt:se(),updatedAt:se(),lastSeq:se().int().nonnegative(),archived:ye(),activity:pO.optional(),permission:ed.optional(),asyncQuestions:xe(xp).optional(),queue:xe(gO).optional(),worktree:I({branch:A(),source:A()}).optional(),subagents:I({total:se().int(),running:se().int()}).optional(),tasks:I({total:se().int(),running:se().int()}).optional()}),bO=I({root:A(),branch:A().optional(),head:A().optional(),dirty:ye()}),xO=I({path:A(),branch:A(),source:A(),createdAt:se(),sessions:xe(A()),dirty:ye(),ahead:se().int().nonnegative()}),wO=I({cwd:A(),name:A(),lastActiveAt:se(),sessionCount:se().int().nonnegative(),branch:A().optional()});I({machineId:A().min(1),hostname:A(),platform:A(),hostVersion:A(),home:A().optional(),agents:xe(T2),direct:I({iceServers:xe(A())}).optional()});const SO=I({port:se().int().min(1).max(65535),process:A(),pid:se().int().optional(),cwd:A().optional(),title:A().optional(),http:ye()}),Ou=I({id:A(),title:A(),cwd:A(),cols:se().int(),rows:se().int(),createdAt:se(),activeAt:se(),command:A().optional(),exitCode:se().int().nullable().optional(),interrupted:ye().optional()});I({url:A().optional(),status:Me(["off","connecting","online","offline"]),error:I({code:A(),message:A()}).optional(),machine:I({id:A(),name:A()}).optional(),account:I({userId:A(),email:A().optional()}).optional(),devices:xe(I({id:A(),name:A(),pairedAt:se(),online:ye()}))});const D2=I({objective:A(),status:Me(["active","paused","blocked","usageLimited","budgetLimited","complete"]),tokenBudget:se().nonnegative().nullable().optional(),tokensUsed:se().nonnegative().optional(),timeUsedSeconds:se().nonnegative().optional(),iterations:se().int().nonnegative().optional(),lastReason:A().nullable().optional()}),EO=wa("action",[I({action:pe("get")}),I({action:pe("set"),objective:A().trim().min(1).max(4e3),tokenBudget:se().int().positive().max(Number.MAX_SAFE_INTEGER).optional()}),I({action:pe("pause")}),I({action:pe("resume")}),I({action:pe("clear")})]),Cm=I({path:A(),line:se().int().optional()}),Vx=wa("type",[I({type:pe("mcp"),server:A(),tool:A()}),I({type:pe("subagent"),action:Me(["spawn","message","wait","stop","resume","list"]).default("spawn"),task:A().optional(),agentType:A().optional(),name:A().optional(),nativeSessionId:A().optional(),canCancel:ye().optional(),model:A().optional(),state:xg.optional(),workflow:j2.optional()}),I({type:pe("skill"),name:A(),description:A().optional()}),I({type:pe("web_search"),query:A().optional()}),I({type:pe("image_generation"),prompt:A().optional()}),I({type:pe("compaction")}),I({type:pe("review"),phase:Me(["started","finished"])}),I({type:pe("question"),text:A(),more:se().int().optional()})]),CO=I({content:A(),priority:Me(["high","medium","low"]).default("medium"),status:Me(["pending","in_progress","completed"])}),_O=Me(["end_turn","cancelled","error","max_tokens","max_turn_requests","refusal","unknown"]),jO=I({id:A(),name:A(),description:A().optional(),type:Me(["select","boolean"]).optional(),category:Me(["model","model_config","mode","effort","other"]).default("other"),current:A(),values:xe(I({value:A(),name:A(),description:A().optional(),group:A().optional()}))}),AO=wa("sessionUpdate",[I({sessionUpdate:pe("ls_message"),messageId:A(),role:Me(["user","agent","thought","session"]),parentToolCallId:A().optional(),content:xe(kr).optional(),append:ye().optional(),senderSessionId:A().optional(),recipientSessionId:A().optional()}),I({sessionUpdate:pe("user_message_chunk"),messageId:A().optional(),content:kr}),I({sessionUpdate:pe("agent_message_chunk"),parentToolCallId:A().optional(),messageId:A(),content:kr}),I({sessionUpdate:pe("agent_thought_chunk"),parentToolCallId:A().optional(),messageId:A(),content:kr}),I({sessionUpdate:pe("tool_call"),toolCallId:A(),parentToolCallId:A().optional(),title:A(),name:A().optional(),kind:xl,status:$x,rawInput:jn().optional(),rawOutput:jn().optional(),content:xe(Nu).optional(),locations:xe(Cm).optional(),detail:Vx.optional()}),I({sessionUpdate:pe("tool_call_update"),toolCallId:A(),parentToolCallId:A().optional(),status:$x.optional(),title:A().optional(),name:A().optional(),kind:xl.optional(),rawInput:jn().optional(),locations:xe(Cm).optional(),detail:Vx.optional(),content:xe(Nu).optional(),appendOutput:A().optional(),replaceOutput:A().optional(),replaceContent:ye().optional(),rawOutput:jn().optional()}),I({sessionUpdate:pe("plan"),entries:xe(CO),planId:A().optional(),title:A().optional(),markdown:A().nullable().optional(),path:A().nullable().optional(),removed:ye().optional()}),I({sessionUpdate:pe("ls_goal"),goal:D2.nullable()}),I({sessionUpdate:pe("available_commands_update"),availableCommands:xe(I({name:A(),description:A(),hint:A().optional()}))}),I({sessionUpdate:pe("current_mode_update"),currentModeId:A()}),I({sessionUpdate:pe("session_info_update"),title:A().nullable().optional(),updatedAt:A().nullable().optional(),model:A().optional()}),I({sessionUpdate:pe("usage_update"),usedTokens:se().optional(),contextWindow:se().optional(),cost:I({amount:se(),currency:A()}).nullable().optional(),tokens:I({totalTokens:se(),inputTokens:se(),outputTokens:se(),thoughtTokens:se().nullish(),cachedReadTokens:se().nullish(),cachedWriteTokens:se().nullish()}).optional()}),I({sessionUpdate:pe("ls_async_questions"),questions:xe(xp)}),I({sessionUpdate:pe("ls_message_done"),parentToolCallId:A().optional(),messageId:A(),role:Me(["agent","thought","user"]),questions:xe(xp).optional()}),I({sessionUpdate:pe("ls_config"),options:xe(jO)}),I({sessionUpdate:pe("ls_notice"),level:Me(["info","warning"]),title:A(),detail:A().optional()}),I({sessionUpdate:pe("ls_turn"),parentToolCallId:A().optional(),state:Me(["started","ended"]),turnId:A().optional(),stopReason:_O.optional()}),I({sessionUpdate:pe("ls_permission"),requestId:A(),childSessionId:A().optional(),toolCallId:A().optional(),title:A(),detail:A().optional(),tool:I({title:A().optional(),kind:xl.optional(),rawInput:jn().optional(),content:xe(Nu).optional(),locations:xe(Cm).optional()}).optional(),url:I({url:A(),elicitationId:A()}).optional(),options:xe(N2).min(1),questions:xe(O2).optional()}),I({sessionUpdate:pe("ls_permission_resolved"),requestId:A(),optionId:A().optional(),answers:xe(wg).optional()}),I({sessionUpdate:pe("ls_driver"),driver:Ju,deviceId:A().optional()}),I({sessionUpdate:pe("ls_status"),state:k2,turnActive:ye().optional()}),I({sessionUpdate:pe("ls_task"),task:R2}),I({sessionUpdate:pe("ls_error"),code:A(),message:A(),hint:A().optional()})]),TO=I({severity:A(),title:A(),description:A().optional()}),qx=I({sessionId:A(),seq:se().int().positive(),ts:se(),update:AO}),gl=Ji(A()),kO=wa("type",[I({type:pe("stdio"),name:A().min(1),command:A().min(1),args:xe(A()).default([]),env:gl.default({})}),I({type:pe("http"),name:A().min(1),url:A().url(),headers:gl.default({})}),I({type:pe("sse"),name:A().min(1),url:A().url(),headers:gl.default({})}),I({type:pe("acp"),name:A().min(1),command:A().min(1),args:xe(A()).default([]),env:gl.default({})})]),kl=I({protocolVersion:bg([pe(1),pe(2)]).default(1),experimental:ye().default(!0),mcpServers:xe(kO).max(32).default([]),additionalDirectories:xe(A().min(1)).max(32).default([])}),wp=I({id:A().regex(/^[a-z][a-z0-9_-]{0,63}$/),label:A().min(1).max(80),transport:Me(["stdio","http","websocket"]),command:A().optional(),args:xe(A()).default([]),url:A().url().optional(),headerEnv:gl.default({}),settings:kl.default({})}),NO=I({id:A(),name:A(),description:A().optional(),type:Me(["agent","terminal"])}),OO=I({protocolVersion:se(),authMethods:xe(NO),logout:ye(),providers:ye(),nes:ye(),additionalDirectories:ye(),mcpHttp:ye(),mcpSse:ye()}),RO=I({providerId:A(),supported:xe(A()),required:ye(),current:I({apiType:A(),baseUrl:A()}).nullish()});Me(["nes/start","nes/suggest","nes/close","nes/accept","nes/reject","document/didOpen","document/didChange","document/didClose","document/didSave","document/didFocus"]);const qs=I({line:se().int().nonnegative(),character:se().int().nonnegative()}),DO=I({start:qs,end:qs}),gu={id:A(),uri:A()},MO=wa("kind",[I({kind:pe("edit"),...gu,edits:xe(I({range:DO,newText:A()})),cursorPosition:qs.nullish()}),I({kind:pe("jump"),...gu,position:qs}),I({kind:pe("rename"),...gu,position:qs,newName:A()}),I({kind:pe("searchAndReplace"),...gu,search:A(),replace:A(),isRegex:ye().nullish()})]);I({agent:A(),operation:Me(["open","suggest","preview","apply","save","reject","close"]),editorId:A().optional(),cwd:A().optional(),path:A().optional(),text:A().max(262144).optional(),position:qs.optional(),suggestionId:A().optional(),previewId:A().optional()});I({editorId:A().optional(),path:A().optional(),text:A().optional(),version:se().optional(),suggestions:xe(MO).optional(),preview:I({id:A(),path:A(),before:A(),after:A(),kind:Me(["edit","jump","searchAndReplace"]),position:qs.optional()}).optional(),position:qs.optional()});const zO=bg([A(),se()]),IO=I({code:se().int(),message:A(),data:jn().optional()});I({jsonrpc:pe("2.0"),id:zO.optional(),method:A().optional(),params:jn().optional(),result:jn().optional(),error:IO.optional()});Me(["invalid_params","not_found","agent_unavailable","not_supported","not_ready","busy","offline","internal"]);const LO=-32601,vl=-32e3;I({}).passthrough();const Px=I({name:A(),path:A(),project:ye().optional(),file:ye().optional(),size:se().int().optional()});I({agent:A().min(1),sessionId:A().optional()}),I({features:OO,settings:kl,interactions:xe(ed)}),I({interactions:xe(I({agent:A(),request:ed}))}),I({agent:A().min(1),settings:kl,sessionId:A().optional()}),I({agent:A().min(1),methodId:A().optional(),logout:ye().optional()}),I({terminalId:A().optional()}),I({agent:A().min(1),requestId:A().min(1),optionId:A().optional(),answers:xe(wg).optional()}),I({agent:A().min(1),operation:Me(["list","set","disable"]),config:I({providerId:A(),apiType:A().optional(),baseUrl:A().url().optional(),headers:Ji(A()).optional()}).optional()}),I({providers:xe(RO)}),I({save:wp.optional(),remove:A().optional()}),I({agents:xe(wp)});I({limit:se().int().positive().max(200).optional()}),I({projects:xe(wO)}),I({limit:se().int().positive().max(200).optional(),before:se().optional(),includeArchived:ye().optional()}),I({sessions:xe(_r),nextBefore:se().optional()}),I({agent:A().min(1),cwd:A().min(1),prompt:xe(kr).optional(),clientMessageId:A().optional(),model:A().optional(),worktree:ye().optional()}),I({session:_r}),I({sessionId:A().min(1),itemId:A().min(1).optional(),worktree:ye().optional()}),I({session:_r}),I({sessionId:A().min(1),fromSeq:se().int().nonnegative(),lazyImages:ye().optional()}),I({session:_r,startSeq:se().int().nonnegative().optional()}),I({sessionId:A().min(1),beforeSeq:se().int().positive(),lazyImages:ye().optional()}),I({events:xe(qx),startSeq:se().int().nonnegative()}),I({sessionId:A().min(1)}),I({subagents:xe(vO)}),I({sessionId:A().min(1),nativeSessionId:A().min(1)}),I({sessionId:A().min(1),toolCallId:A().min(1),lazyImages:ye().optional()}),I({events:xe(qx)}),I({sessionId:A().min(1)}),I({tasks:xe(R2)}),I({sessionId:A().min(1),taskId:A().min(1),before:se().int().nonnegative().optional(),limit:se().int().positive().max(256*1024).optional()}),I({text:A(),start:se().int().nonnegative(),size:se().int().nonnegative()}),I({sessionId:A().min(1),taskId:A().min(1)}),I({sessionId:A().min(1),direct:ye().optional()}),I({port:se().int().positive(),token:A()}),I({sessionId:A().min(1)}),I({sessionId:A().min(1),uri:A().min(1)}),I({mimeType:A(),data:A()}),I({sessionId:A().min(1)}),I({sessionId:A().min(1),clientMessageId:A().min(1),content:xe(kr).min(1),whenBusy:Me(["queue"]).optional()}),I({delivery:Me(["started","steered","queued","duplicate"])}),I({sessionId:A().min(1)}),I({sessionId:A().min(1),requestId:A().min(1),optionId:A().min(1)}),I({sessionId:A().min(1),requestId:A().min(1),answers:xe(wg).max(50)}),I({sessionId:A(),change:EO}),I({goal:D2.nullable()}),I({sessionId:A().min(1),optionId:A().min(1),value:A().min(1)}),I({sessionId:A().min(1),clientMessageId:A().min(1).optional()}),I({sessionId:A().min(1),clientMessageIds:xe(A().min(1))}),I({sessionId:A().min(1),clientMessageId:A().min(1)}),I({removed:ye()}),I({sessionId:A().min(1),archived:ye()}),I({session:_r}),I({sessionId:A().min(1),title:A().max(200)}),I({session:_r}),I({sessionId:A().min(1),worktree:Me(["keep","remove"]).optional()}),I({sessionId:A().min(1)}),I({driver:Ju.optional()}),I({sessionId:A().min(1)}),I({driver:Ju.optional()}),I({agent:A().min(1),sessionId:A().optional(),args:xe(A()).default([]),cwd:A().optional(),env:Ji(A()).optional()}),I({command:A(),args:xe(A()),env:Ji(A()).optional(),sessionId:A().optional()}),I({sessionId:A().min(1)}),I({sessionId:A().min(1)}),I({command:A(),args:xe(A()),env:Ji(A()).optional()}),I({link:A(),code:A(),expiresAt:se(),gateway:A()}),I({deviceId:A().min(1)}),I({path:A().min(1)}),I({git:bO.optional()}),I({worktrees:xe(xO)}),I({path:A().min(1),force:ye().optional()}),I({path:A().optional(),hidden:ye().default(!1),files:ye().default(!1)}),I({path:A(),parent:A().optional(),home:A(),entries:xe(Px),truncated:ye().optional()}),I({path:A().min(1),offset:se().int().nonnegative().default(0),maxBytes:se().int().min(1).max(2e6).default(512e3)}),I({path:A(),size:se().int(),modifiedAt:se(),kind:Me(["text","image","binary"]),text:A().optional(),data:A().optional(),mimeType:A().optional(),truncated:ye(),nextOffset:se().int().optional()}),I({dir:A().min(1),name:A().min(1).max(255),data:A().max(4e7)}),I({path:A(),size:se().int()}),I({parent:A().min(1),name:A().min(1).max(255)}),I({path:A()}),I({query:A().min(1).max(200),limit:se().int().min(1).max(200).default(60)}),I({entries:xe(Px),truncated:ye()}),I({terminals:xe(Ou)}),I({cwd:A().optional(),command:A().max(4e3).optional(),cols:se().int().min(10).max(1e3).default(80),rows:se().int().min(4).max(500).default(24)}),I({terminal:Ou}),I({terminalId:A().min(1),fromSeq:se().int().min(0).optional(),replayFormat:pe("frames-v1").optional(),fromFrame:se().int().min(0).optional(),snapshot:ye().optional()}),I({terminal:Ou,replay:A(),reset:ye(),seq:se().int(),recording:I({afterFrame:se().int(),throughFrame:se().int()}).optional(),state:I({snapshotId:A(),length:se().int().min(0),frame:se().int().min(0),cols:se().int().min(1),rows:se().int().min(1)}).optional()}),I({terminalId:A().min(1),snapshotId:A().min(1),offset:se().int().min(0)}),I({data:A(),nextOffset:se().int().min(0),done:ye()}),I({terminalId:A().min(1),afterFrame:se().int().min(0),throughFrame:se().int().min(0)}),I({frames:xe(I({frame:se().int(),cols:se().int(),rows:se().int(),data:A()})),nextFrame:se().int(),done:ye()}),I({terminalId:A().min(1)}),I({terminalId:A().min(1),data:A().max(1e6)}),I({terminalId:A().min(1),cols:se().int().min(10).max(1e3),rows:se().int().min(4).max(500)}),I({terminalId:A().min(1)}),I({ports:xe(SO)}),I({port:se().int().min(1).max(65535),direct:ye().optional()}),I({streamId:A(),channel:se().int().nonnegative().optional()}),I({sdp:A().min(1).max(2e5)}),I({sdp:A()}),I({port:se().int(),token:A(),displays:xe(I({index:se().int(),name:A()}))}),I({ask:ye().optional()}),I({supported:ye(),ffmpeg:ye(),recording:ye().nullable(),control:ye().nullable(),app:A().optional(),problem:A().optional()}),I({streamId:A().min(1),data:A().max(2e6)}),I({streamId:A().min(1)});I({agent:T2}),I({agent:A(),request:bg([ed,I({requestId:A(),resolved:pe(!0)})])}),I({sessionId:A(),notice:TO}),I({sessionId:A(),startSeq:se().int().nonnegative()}),I({session:_r}),I({sessionId:A()}),I({sessionId:A()}),I({sessionId:A()}),I({sessionId:A(),line:A()}),I({device:I({id:A(),name:A()})}),I({terminalId:A(),seq:se().int(),data:A(),frame:se().int().optional(),cols:se().int().optional(),rows:se().int().optional()}),I({terminal:Ou,closed:ye().optional()}),I({streamId:A(),data:A()}),I({streamId:A(),error:A().optional()});class da extends Error{constructor(e,s,r){super(s),this.code=e,this.data=r,this.name="RpcError"}static app(e,s,r){return new da(vl,s,{code:e,...r})}get appCode(){const e=this.data;return typeof e?.code=="string"?e.code:void 0}toObject(){return this.data===void 0?{code:this.code,message:this.message}:{code:this.code,message:this.message,data:this.data}}}const UO=Symbol("rpc.abandon");class BO{constructor(e){this.options=e}nextId=1;pending=new Map;closed=!1;request(e,s,r){if(this.closed)return Promise.reject(new da(vl,`connection closed (${e})`));const o=this.nextId++;return new Promise((l,u)=>{const d={resolve:l,reject:u,method:e},m=r??this.options.requestTimeoutMs??3e4;m>0&&(d.timer=setTimeout(()=>{this.pending.delete(o),u(new da(vl,`${e} timed out after ${m}ms`,{code:"timeout"}))},m)),this.pending.set(o,d),this.write({jsonrpc:"2.0",id:o,method:e,params:s??{}})})}notify(e,s){this.closed||this.write({jsonrpc:"2.0",method:e,params:s??{}})}receive(e){for(const s of e.split(`
|
|
154
|
-
`)){if(!s.trim())continue;let r;try{r=JSON.parse(s)}catch{continue}if(Array.isArray(r)){if(!r.length||r.length>128){this.write({jsonrpc:"2.0",id:null,error:{code:-32600,message:"invalid JSON-RPC batch"}});continue}const o=[];Promise.all(r.map(l=>Promise.resolve(this.dispatch(l,u=>{o.push(u)})))).then(()=>{o.length&&this.write(o)})}else this.dispatch(r)}}close(e="connection closed"){if(!this.closed){this.closed=!0;for(const[s,r]of this.pending)r.timer&&clearTimeout(r.timer),r.reject(new da(vl,`${e} (${r.method})`,{code:"closed"})),this.pending.delete(s)}}get isClosed(){return this.closed}hasPendingRequest(e){return this.pending.has(e)}dispatch(e,s=r=>this.write(r)){if(!e||typeof e!="object"||Array.isArray(e)){s({jsonrpc:"2.0",id:null,error:{code:-32600,message:"invalid JSON-RPC request"}});return}const r=e.id,o=typeof e.method=="string"?e.method:void 0;if(o===void 0){if(r===void 0)return;const u=this.pending.get(r);if(!u)return;this.pending.delete(r),u.timer&&clearTimeout(u.timer);const d=e.error;d?u.reject(new da(d.code,d.message,d.data)):u.resolve(e.result);return}if(r===void 0){this.options.onNotification?.(o,e.params);return}const l=this.options.onRequest;if(!l){s({jsonrpc:"2.0",id:r,error:{code:LO,message:`no handler for ${o}`}});return}return Promise.resolve().then(()=>l(o,e.params,r)).then(u=>{u!==UO&&s({jsonrpc:"2.0",id:r,result:u??{}})},u=>{const d=u instanceof da?u:new da(vl,u instanceof Error?u.message:String(u),{code:"internal"});s({jsonrpc:"2.0",id:r,error:d.toObject()})})}write(e){if(!this.closed)try{this.options.send(JSON.stringify(e))}catch{this.close("send failed")}}}/*! noble-ciphers - MIT License (c) 2023 Paul Miller (paulmillr.com) */function Sp(n){return n instanceof Uint8Array||ArrayBuffer.isView(n)&&n.constructor.name==="Uint8Array"&&"BYTES_PER_ELEMENT"in n&&n.BYTES_PER_ELEMENT===1}const td=n=>n?`"${n}" `:"";function Ep(n,e=""){if(typeof n!="boolean")throw new TypeError(td(e)+"expected boolean, got type="+typeof n);return n}function eo(n,e=""){if(typeof n!="number")throw new TypeError(td(e)+"expected number, got "+typeof n);if(!Number.isSafeInteger(n)||n<0)throw new RangeError(td(e)+"expected integer >= 0, got "+n);return n}function Pt(n,e,s=""){if(Sp(n)&&(e===void 0||n.length===e))return n;e!==void 0&&eo(e,"length");const r=Sp(n),o=e!==void 0?` of length ${e}`:"",l=r?`length=${n.length}`:`type=${typeof n}`,u=td(s)+"expected Uint8Array"+o+", got "+l;throw r?new RangeError(u):new TypeError(u)}const Fx=(n,e)=>{if(n===null||typeof n!="object"||Array.isArray(n))throw new TypeError(e==="object"?"expected valid options object":`"${e}" expected object, got type=${typeof n}`)};function Gx(n,e=!0){if(n.destroyed)throw new Error("hash was destroyed");if(e&&n.finished)throw new Error("digest() was already called")}function HO(n,e){Pt(n,void 0,"output");const s=e.outputLen;if(!(n.length>=s))throw new RangeError('"output" expected length >= '+s)}function Ya(n){return new Uint32Array(n.buffer,n.byteOffset,Math.floor(n.byteLength/4))}function va(...n){for(let e=0;e<n.length;e++)n[e].fill(0)}function $O(n){return new DataView(n.buffer,n.byteOffset,n.byteLength)}const ma=new Uint8Array(new Uint32Array([287454020]).buffer)[0]===68;function VO(n){return n<<24&4278190080|n<<8&16711680|n>>>8&65280|n>>>24&255}function qO(n){for(let e=0;e<n.length;e++)n[e]=VO(n[e]);return n}const Xn=ma?n=>n:qO;function PO(n,e){return!n.byteLength||!e.byteLength?!1:n.buffer===e.buffer&&n.byteOffset<e.byteOffset+e.byteLength&&e.byteOffset<n.byteOffset+n.byteLength}function FO(n,e){if(PO(n,e)&&n.byteOffset<e.byteOffset)throw new Error("complex overlap of input and output is not supported")}function GO(n,e){return Fx(n,"defaults"),Fx(e,"opts"),Object.assign(n,e)}function ZO(n,e){if(n=Pt(n),e=Pt(e),n.length!==e.length)return!1;let s=0;for(let r=0;r<n.length;r++)s|=n[r]^e[r];return s===0}function YO(n,e,s){const r=e,o=(()=>[]),l=(d,m)=>r(m,...o(d)).update(d).digest(),u=r(new Uint8Array(n),...o(new Uint8Array(0)));return l.outputLen=u.outputLen,l.blockLen=u.blockLen,l.create=(d,...m)=>r(d,...m),l}const KO=(n,e)=>{function s(r,...o){if(Pt(r,void 0,"key"),n.nonceLength!==void 0){const v=o[0];Pt(v,n.varSizeNonce?void 0:n.nonceLength,"nonce")}const l=n.tagLength,u=n.nonceLength!==void 0?1:0;if(!n.withAAD){for(let v=u;v<o.length;v++)if(Sp(o[v]))throw new Error("AAD not supported")}n.withAAD&&o[u]!==void 0&&Pt(o[u],void 0,"AAD");const d=e(r,...o),m=(v,b)=>{if(b!==void 0){if(v!==2)throw new Error("cipher output not supported");Pt(b,void 0,"output")}};let p=!1;return{encrypt(v,b){if(p)throw new Error("cannot encrypt() twice with same key + nonce");return p=!0,Pt(v,void 0,"data"),m(d.encrypt.length,b),d.encrypt(v,b)},decrypt(v,b){if(Pt(v,void 0,"data"),l&&v.length<l)throw new Error('"ciphertext" expected length >= tagLength='+l);return m(d.decrypt.length,b),d.decrypt(v,b)}}}return Object.assign(s,n),s};function Cp(n,e,s=!0){if(e===void 0)return new Uint8Array(n);if(Pt(e,n,"output"),s&&!nd(e))throw new Error("invalid output, must be aligned");return e}function XO(n,e,s){eo(n),eo(e),Ep(s);const r=new Uint8Array(16),o=$O(r);return o.setBigUint64(0,BigInt(e),s),o.setBigUint64(8,BigInt(n),s),r}function nd(n){return n.byteOffset%4===0}function ad(n){return Uint8Array.from(Pt(n))}const M2=n=>Uint8Array.from(n.split(""),e=>e.charCodeAt(0)),QO=Xn(Ya(M2("expand 16-byte k"))),WO=Xn(Ya(M2("expand 32-byte k")));function st(n,e){return n<<e|n>>>32-e}const dl=64,JO=16,_p=2**32-1,Zx=Uint32Array.of();function e5(n,e,s,r,o,l,u,d){const m=o.length,p=new Uint8Array(dl),y=Ya(p),v=ma&&nd(o)&&nd(l),b=v?Ya(o):Zx,C=v?Ya(l):Zx;if(!ma){for(let T=0;T<m;u++){if(n(e,s,r,y,u,d),Xn(y),u>=_p)throw new Error("arx: counter overflow");const S=Math.min(dl,m-T);for(let E=0,_;E<S;E++)_=T+E,l[_]=o[_]^p[E];T+=S}return}for(let T=0;T<m;u++){if(n(e,s,r,y,u,d),u>=_p)throw new Error("arx: counter overflow");const S=Math.min(dl,m-T);if(v&&S===dl){const E=T/4;if(T%4!==0)throw new Error("arx: invalid block position");for(let _=0,j;_<JO;_++)j=E+_,C[j]=b[j]^y[_];T+=dl;continue}for(let E=0,_;E<S;E++)_=T+E,l[_]=o[_]^p[E];T+=S}}function t5(n,e){const{allowShortKeys:s,extendNonceFn:r,counterLength:o,counterRight:l,rounds:u}=GO({allowShortKeys:!1,counterLength:8,counterRight:!1,rounds:20},e);if(typeof n!="function")throw new Error("core must be a function");return eo(o),eo(u),Ep(l),Ep(s),(d,m,p,y,v=0)=>{Pt(d,void 0,"key"),Pt(m,void 0,"nonce"),Pt(p,void 0,"data");const b=p.length,C=y!==void 0;if(y=Cp(b,y,!1),C&&FO(p,y),eo(v),v<0||v>=_p)throw new Error("arx: counter overflow");const T=[];let S=d.length,E,_;if(S===32)T.push(E=ad(d)),_=WO;else if(S===16&&s)E=new Uint8Array(32),E.set(d),E.set(d,16),_=QO,T.push(E);else throw Pt(d,32,"arx key"),new Error("invalid key size");(!ma||!nd(m))&&T.push(m=ad(m));let j=Ya(E);if(r){if(m.length!==24)throw new Error("arx: extended nonce must be 24 bytes");const k=m.subarray(0,16);if(ma)r(_,j,Ya(k),j);else{const O=Xn(Uint32Array.from(_));r(O,j,Ya(k),j),va(O),Xn(j)}m=m.subarray(16)}else ma||Xn(j);const N=16-o;if(N!==m.length)throw new Error(`arx: nonce must be ${N} or 16 bytes`);if(N!==12){const k=new Uint8Array(12);k.set(m,l?0:12-m.length),m=k,T.push(m)}const z=Xn(Ya(m));try{return e5(n,_,j,z,p,y,v,u),y}finally{va(...T)}}}function Xt(n,e){return n[e++]&255|(n[e++]&255)<<8}class n5{blockLen=16;outputLen=16;buffer=new Uint8Array(16);r=new Uint16Array(10);h=new Uint16Array(10);pad=new Uint16Array(8);pos=0;finished=!1;destroyed=!1;constructor(e){e=ad(Pt(e,32,"key"));const s=Xt(e,0),r=Xt(e,2),o=Xt(e,4),l=Xt(e,6),u=Xt(e,8),d=Xt(e,10),m=Xt(e,12),p=Xt(e,14);this.r[0]=s&8191,this.r[1]=(s>>>13|r<<3)&8191,this.r[2]=(r>>>10|o<<6)&7939,this.r[3]=(o>>>7|l<<9)&8191,this.r[4]=(l>>>4|u<<12)&255,this.r[5]=u>>>1&8190,this.r[6]=(u>>>14|d<<2)&8191,this.r[7]=(d>>>11|m<<5)&8065,this.r[8]=(m>>>8|p<<8)&8191,this.r[9]=p>>>5&127;for(let y=0;y<8;y++)this.pad[y]=Xt(e,16+2*y)}process(e,s,r=!1){const o=r?0:2048,{h:l,r:u}=this,d=u[0],m=u[1],p=u[2],y=u[3],v=u[4],b=u[5],C=u[6],T=u[7],S=u[8],E=u[9],_=Xt(e,s+0),j=Xt(e,s+2),N=Xt(e,s+4),z=Xt(e,s+6),k=Xt(e,s+8),O=Xt(e,s+10),M=Xt(e,s+12),R=Xt(e,s+14);let L=l[0]+(_&8191),H=l[1]+((_>>>13|j<<3)&8191),V=l[2]+((j>>>10|N<<6)&8191),q=l[3]+((N>>>7|z<<9)&8191),P=l[4]+((z>>>4|k<<12)&8191),J=l[5]+(k>>>1&8191),ie=l[6]+((k>>>14|O<<2)&8191),U=l[7]+((O>>>11|M<<5)&8191),G=l[8]+((M>>>8|R<<8)&8191),W=l[9]+(R>>>5|o),te=0,X=te+L*d+H*(5*E)+V*(5*S)+q*(5*T)+P*(5*C);te=X>>>13,X&=8191,X+=J*(5*b)+ie*(5*v)+U*(5*y)+G*(5*p)+W*(5*m),te+=X>>>13,X&=8191;let ge=te+L*m+H*d+V*(5*E)+q*(5*S)+P*(5*T);te=ge>>>13,ge&=8191,ge+=J*(5*C)+ie*(5*b)+U*(5*v)+G*(5*y)+W*(5*p),te+=ge>>>13,ge&=8191;let Z=te+L*p+H*m+V*d+q*(5*E)+P*(5*S);te=Z>>>13,Z&=8191,Z+=J*(5*T)+ie*(5*C)+U*(5*b)+G*(5*v)+W*(5*y),te+=Z>>>13,Z&=8191;let ee=te+L*y+H*p+V*m+q*d+P*(5*E);te=ee>>>13,ee&=8191,ee+=J*(5*S)+ie*(5*T)+U*(5*C)+G*(5*b)+W*(5*v),te+=ee>>>13,ee&=8191;let fe=te+L*v+H*y+V*p+q*m+P*d;te=fe>>>13,fe&=8191,fe+=J*(5*E)+ie*(5*S)+U*(5*T)+G*(5*C)+W*(5*b),te+=fe>>>13,fe&=8191;let ue=te+L*b+H*v+V*y+q*p+P*m;te=ue>>>13,ue&=8191,ue+=J*d+ie*(5*E)+U*(5*S)+G*(5*T)+W*(5*C),te+=ue>>>13,ue&=8191;let oe=te+L*C+H*b+V*v+q*y+P*p;te=oe>>>13,oe&=8191,oe+=J*m+ie*d+U*(5*E)+G*(5*S)+W*(5*T),te+=oe>>>13,oe&=8191;let Ce=te+L*T+H*C+V*b+q*v+P*y;te=Ce>>>13,Ce&=8191,Ce+=J*p+ie*m+U*d+G*(5*E)+W*(5*S),te+=Ce>>>13,Ce&=8191;let me=te+L*S+H*T+V*C+q*b+P*v;te=me>>>13,me&=8191,me+=J*y+ie*p+U*m+G*d+W*(5*E),te+=me>>>13,me&=8191;let he=te+L*E+H*S+V*T+q*C+P*b;te=he>>>13,he&=8191,he+=J*v+ie*y+U*p+G*m+W*d,te+=he>>>13,he&=8191,te=(te<<2)+te|0,te=te+X|0,X=te&8191,te=te>>>13,ge+=te,l[0]=X,l[1]=ge,l[2]=Z,l[3]=ee,l[4]=fe,l[5]=ue,l[6]=oe,l[7]=Ce,l[8]=me,l[9]=he}finalize(){const{h:e,pad:s}=this,r=new Uint16Array(10);let o=e[1]>>>13;e[1]&=8191;for(let d=2;d<10;d++)e[d]+=o,o=e[d]>>>13,e[d]&=8191;e[0]+=o*5,o=e[0]>>>13,e[0]&=8191,e[1]+=o,o=e[1]>>>13,e[1]&=8191,e[2]+=o,r[0]=e[0]+5,o=r[0]>>>13,r[0]&=8191;for(let d=1;d<10;d++)r[d]=e[d]+o,o=r[d]>>>13,r[d]&=8191;r[9]-=8192;let l=(o^1)-1;for(let d=0;d<10;d++)r[d]&=l;l=~l;for(let d=0;d<10;d++)e[d]=e[d]&l|r[d];e[0]=(e[0]|e[1]<<13)&65535,e[1]=(e[1]>>>3|e[2]<<10)&65535,e[2]=(e[2]>>>6|e[3]<<7)&65535,e[3]=(e[3]>>>9|e[4]<<4)&65535,e[4]=(e[4]>>>12|e[5]<<1|e[6]<<14)&65535,e[5]=(e[6]>>>2|e[7]<<11)&65535,e[6]=(e[7]>>>5|e[8]<<8)&65535,e[7]=(e[8]>>>8|e[9]<<5)&65535;let u=e[0]+s[0];e[0]=u&65535;for(let d=1;d<8;d++)u=(e[d]+s[d]|0)+(u>>>16)|0,e[d]=u&65535;va(r)}update(e){Gx(this),Pt(e),e=ad(e);const{buffer:s,blockLen:r}=this,o=e.length;for(let l=0;l<o;){const u=Math.min(r-this.pos,o-l);if(u===r){for(;r<=o-l;l+=r)this.process(e,l);continue}s.set(e.subarray(l,l+u),this.pos),this.pos+=u,l+=u,this.pos===r&&(this.process(s,0,!1),this.pos=0)}return this}destroy(){this.destroyed=!0,va(this.h,this.r,this.buffer,this.pad)}digestInto(e){Gx(this),HO(e,this),this.finished=!0;const{buffer:s,h:r}=this;let{pos:o}=this;if(o){for(s[o++]=1;o<16;o++)s[o]=0;this.process(s,0,!0)}this.finalize();let l=0;for(let u=0;u<8;u++)e[l++]=r[u]>>>0,e[l++]=r[u]>>>8}digest(){const{buffer:e,outputLen:s}=this;this.digestInto(e);const r=e.slice(0,s);return this.destroy(),r}}const a5=YO(32,n=>new n5(n));function z2(n,e,s,r,o,l=20){let u=n[0],d=n[1],m=n[2],p=n[3],y=e[0],v=e[1],b=e[2],C=e[3],T=e[4],S=e[5],E=e[6],_=e[7],j=o,N=s[0],z=s[1],k=s[2],O=u,M=d,R=m,L=p,H=y,V=v,q=b,P=C,J=T,ie=S,U=E,G=_,W=j,te=N,X=z,ge=k;for(let ee=0;ee<l;ee+=2)O=O+H|0,W=st(W^O,16),J=J+W|0,H=st(H^J,12),O=O+H|0,W=st(W^O,8),J=J+W|0,H=st(H^J,7),M=M+V|0,te=st(te^M,16),ie=ie+te|0,V=st(V^ie,12),M=M+V|0,te=st(te^M,8),ie=ie+te|0,V=st(V^ie,7),R=R+q|0,X=st(X^R,16),U=U+X|0,q=st(q^U,12),R=R+q|0,X=st(X^R,8),U=U+X|0,q=st(q^U,7),L=L+P|0,ge=st(ge^L,16),G=G+ge|0,P=st(P^G,12),L=L+P|0,ge=st(ge^L,8),G=G+ge|0,P=st(P^G,7),O=O+V|0,ge=st(ge^O,16),U=U+ge|0,V=st(V^U,12),O=O+V|0,ge=st(ge^O,8),U=U+ge|0,V=st(V^U,7),M=M+q|0,W=st(W^M,16),G=G+W|0,q=st(q^G,12),M=M+q|0,W=st(W^M,8),G=G+W|0,q=st(q^G,7),R=R+P|0,te=st(te^R,16),J=J+te|0,P=st(P^J,12),R=R+P|0,te=st(te^R,8),J=J+te|0,P=st(P^J,7),L=L+H|0,X=st(X^L,16),ie=ie+X|0,H=st(H^ie,12),L=L+H|0,X=st(X^L,8),ie=ie+X|0,H=st(H^ie,7);let Z=0;r[Z++]=u+O|0,r[Z++]=d+M|0,r[Z++]=m+R|0,r[Z++]=p+L|0,r[Z++]=y+H|0,r[Z++]=v+V|0,r[Z++]=b+q|0,r[Z++]=C+P|0,r[Z++]=T+J|0,r[Z++]=S+ie|0,r[Z++]=E+U|0,r[Z++]=_+G|0,r[Z++]=j+W|0,r[Z++]=N+te|0,r[Z++]=z+X|0,r[Z++]=k+ge|0}function s5(n,e,s,r){const o=ma?n:Xn(n.slice(0,4)),l=ma?e:Xn(e.slice(0,8)),u=ma?s:Xn(s.slice(0,4)),d=new Uint32Array(16);z2(o,l,u.subarray(1),d,u[0]);let m=0;r[m++]=d[0]-o[0]|0,r[m++]=d[1]-o[1]|0,r[m++]=d[2]-o[2]|0,r[m++]=d[3]-o[3]|0,r[m++]=d[12]-u[0]|0,r[m++]=d[13]-u[1]|0,r[m++]=d[14]-u[2]|0,r[m++]=d[15]-u[3]|0,Xn(r),ma||va(o,l,u),va(d)}const r5=t5(z2,{counterRight:!1,counterLength:8,extendNonceFn:s5,allowShortKeys:!1}),i5=new Uint8Array(16),Yx=(n,e)=>{n.update(e);const s=e.length%16;s&&n.update(i5.subarray(s))},o5=new Uint8Array(32);function Kx(n,e,s,r,o){o!==void 0&&Pt(o,void 0,"AAD");const l=n(e,s,o5),u=XO(r.length,o?o.length:0,!0),d=a5.create(l);o&&Yx(d,o),Yx(d,r),d.update(u);const m=d.digest();return va(l,u),m}const l5=n=>(e,s,r)=>({encrypt(l,u){const d=l.length;u=Cp(d+16,u,!1),u.set(l);const m=u.subarray(0,-16);n(e,s,m,m,1);const p=Kx(n,e,s,m,r);return u.set(p,d),va(p),u},decrypt(l,u){u=Cp(l.length-16,u,!1);const d=l.subarray(0,-16),m=l.subarray(-16),p=Kx(n,e,s,d,r);if(!ZO(m,p))throw va(p),new Error("invalid tag");return u.set(l.subarray(0,-16)),n(e,s,u,u,1),va(p),u}}),Xx=KO({blockSize:64,nonceLength:24,tagLength:16,withAAD:!0},l5(r5)),qi=typeof globalThis=="object"&&"crypto"in globalThis?globalThis.crypto:void 0;/*! noble-hashes - MIT License (c) 2022 Paul Miller (paulmillr.com) */function zd(n){return n instanceof Uint8Array||ArrayBuffer.isView(n)&&n.constructor.name==="Uint8Array"}function sd(n){if(!Number.isSafeInteger(n)||n<0)throw new Error("positive integer expected, got "+n)}function nr(n,...e){if(!zd(n))throw new Error("Uint8Array expected");if(e.length>0&&!e.includes(n.length))throw new Error("Uint8Array expected of length "+e+", got length="+n.length)}function Sg(n){if(typeof n!="function"||typeof n.create!="function")throw new Error("Hash should be wrapped by utils.createHasher");sd(n.outputLen),sd(n.blockLen)}function rd(n,e=!0){if(n.destroyed)throw new Error("Hash instance has been destroyed");if(e&&n.finished)throw new Error("Hash#digest() has already been called")}function c5(n,e){nr(n);const s=e.outputLen;if(n.length<s)throw new Error("digestInto() expects output buffer of length at least "+s)}function Br(...n){for(let e=0;e<n.length;e++)n[e].fill(0)}function _m(n){return new DataView(n.buffer,n.byteOffset,n.byteLength)}function ca(n,e){return n<<32-e|n>>>e}const I2=typeof Uint8Array.from([]).toHex=="function"&&typeof Uint8Array.fromHex=="function",u5=Array.from({length:256},(n,e)=>e.toString(16).padStart(2,"0"));function Eg(n){if(nr(n),I2)return n.toHex();let e="";for(let s=0;s<n.length;s++)e+=u5[n[s]];return e}const qa={_0:48,_9:57,A:65,F:70,a:97,f:102};function Qx(n){if(n>=qa._0&&n<=qa._9)return n-qa._0;if(n>=qa.A&&n<=qa.F)return n-(qa.A-10);if(n>=qa.a&&n<=qa.f)return n-(qa.a-10)}function L2(n){if(typeof n!="string")throw new Error("hex string expected, got "+typeof n);if(I2)return Uint8Array.fromHex(n);const e=n.length,s=e/2;if(e%2)throw new Error("hex string expected, got unpadded hex of length "+e);const r=new Uint8Array(s);for(let o=0,l=0;o<s;o++,l+=2){const u=Qx(n.charCodeAt(l)),d=Qx(n.charCodeAt(l+1));if(u===void 0||d===void 0){const m=n[l]+n[l+1];throw new Error('hex string expected, got non-hex character "'+m+'" at index '+l)}r[o]=u*16+d}return r}function d5(n){if(typeof n!="string")throw new Error("string expected");return new Uint8Array(new TextEncoder().encode(n))}function Nl(n){return typeof n=="string"&&(n=d5(n)),nr(n),n}function Wx(...n){let e=0;for(let r=0;r<n.length;r++){const o=n[r];nr(o),e+=o.length}const s=new Uint8Array(e);for(let r=0,o=0;r<n.length;r++){const l=n[r];s.set(l,o),o+=l.length}return s}class U2{}function B2(n){const e=r=>n().update(Nl(r)).digest(),s=n();return e.outputLen=s.outputLen,e.blockLen=s.blockLen,e.create=()=>n(),e}function H2(n=32){if(qi&&typeof qi.getRandomValues=="function")return qi.getRandomValues(new Uint8Array(n));if(qi&&typeof qi.randomBytes=="function")return Uint8Array.from(qi.randomBytes(n));throw new Error("crypto.getRandomValues must be defined")}function f5(n,e,s,r){if(typeof n.setBigUint64=="function")return n.setBigUint64(e,s,r);const o=BigInt(32),l=BigInt(4294967295),u=Number(s>>o&l),d=Number(s&l),m=r?4:0,p=r?0:4;n.setUint32(e+m,u,r),n.setUint32(e+p,d,r)}function h5(n,e,s){return n&e^~n&s}function m5(n,e,s){return n&e^n&s^e&s}class $2 extends U2{constructor(e,s,r,o){super(),this.finished=!1,this.length=0,this.pos=0,this.destroyed=!1,this.blockLen=e,this.outputLen=s,this.padOffset=r,this.isLE=o,this.buffer=new Uint8Array(e),this.view=_m(this.buffer)}update(e){rd(this),e=Nl(e),nr(e);const{view:s,buffer:r,blockLen:o}=this,l=e.length;for(let u=0;u<l;){const d=Math.min(o-this.pos,l-u);if(d===o){const m=_m(e);for(;o<=l-u;u+=o)this.process(m,u);continue}r.set(e.subarray(u,u+d),this.pos),this.pos+=d,u+=d,this.pos===o&&(this.process(s,0),this.pos=0)}return this.length+=e.length,this.roundClean(),this}digestInto(e){rd(this),c5(e,this),this.finished=!0;const{buffer:s,view:r,blockLen:o,isLE:l}=this;let{pos:u}=this;s[u++]=128,Br(this.buffer.subarray(u)),this.padOffset>o-u&&(this.process(r,0),u=0);for(let v=u;v<o;v++)s[v]=0;f5(r,o-8,BigInt(this.length*8),l),this.process(r,0);const d=_m(e),m=this.outputLen;if(m%4)throw new Error("_sha2: outputLen should be aligned to 32bit");const p=m/4,y=this.get();if(p>y.length)throw new Error("_sha2: outputLen bigger than state");for(let v=0;v<p;v++)d.setUint32(4*v,y[v],l)}digest(){const{buffer:e,outputLen:s}=this;this.digestInto(e);const r=e.slice(0,s);return this.destroy(),r}_cloneInto(e){e||(e=new this.constructor),e.set(...this.get());const{blockLen:s,buffer:r,length:o,finished:l,destroyed:u,pos:d}=this;return e.destroyed=u,e.finished=l,e.length=o,e.pos=d,o%s&&e.buffer.set(r),e}clone(){return this._cloneInto()}}const Rs=Uint32Array.from([1779033703,3144134277,1013904242,2773480762,1359893119,2600822924,528734635,1541459225]),en=Uint32Array.from([1779033703,4089235720,3144134277,2227873595,1013904242,4271175723,2773480762,1595750129,1359893119,2917565137,2600822924,725511199,528734635,4215389547,1541459225,327033209]),vu=BigInt(2**32-1),Jx=BigInt(32);function p5(n,e=!1){return e?{h:Number(n&vu),l:Number(n>>Jx&vu)}:{h:Number(n>>Jx&vu)|0,l:Number(n&vu)|0}}function g5(n,e=!1){const s=n.length;let r=new Uint32Array(s),o=new Uint32Array(s);for(let l=0;l<s;l++){const{h:u,l:d}=p5(n[l],e);[r[l],o[l]]=[u,d]}return[r,o]}const e1=(n,e,s)=>n>>>s,t1=(n,e,s)=>n<<32-s|e>>>s,Pi=(n,e,s)=>n>>>s|e<<32-s,Fi=(n,e,s)=>n<<32-s|e>>>s,yu=(n,e,s)=>n<<64-s|e>>>s-32,bu=(n,e,s)=>n>>>s-32|e<<64-s;function Pa(n,e,s,r){const o=(e>>>0)+(r>>>0);return{h:n+s+(o/2**32|0)|0,l:o|0}}const v5=(n,e,s)=>(n>>>0)+(e>>>0)+(s>>>0),y5=(n,e,s,r)=>e+s+r+(n/2**32|0)|0,b5=(n,e,s,r)=>(n>>>0)+(e>>>0)+(s>>>0)+(r>>>0),x5=(n,e,s,r,o)=>e+s+r+o+(n/2**32|0)|0,w5=(n,e,s,r,o)=>(n>>>0)+(e>>>0)+(s>>>0)+(r>>>0)+(o>>>0),S5=(n,e,s,r,o,l)=>e+s+r+o+l+(n/2**32|0)|0,E5=Uint32Array.from([1116352408,1899447441,3049323471,3921009573,961987163,1508970993,2453635748,2870763221,3624381080,310598401,607225278,1426881987,1925078388,2162078206,2614888103,3248222580,3835390401,4022224774,264347078,604807628,770255983,1249150122,1555081692,1996064986,2554220882,2821834349,2952996808,3210313671,3336571891,3584528711,113926993,338241895,666307205,773529912,1294757372,1396182291,1695183700,1986661051,2177026350,2456956037,2730485921,2820302411,3259730800,3345764771,3516065817,3600352804,4094571909,275423344,430227734,506948616,659060556,883997877,958139571,1322822218,1537002063,1747873779,1955562222,2024104815,2227730452,2361852424,2428436474,2756734187,3204031479,3329325298]),Ds=new Uint32Array(64);class C5 extends $2{constructor(e=32){super(64,e,8,!1),this.A=Rs[0]|0,this.B=Rs[1]|0,this.C=Rs[2]|0,this.D=Rs[3]|0,this.E=Rs[4]|0,this.F=Rs[5]|0,this.G=Rs[6]|0,this.H=Rs[7]|0}get(){const{A:e,B:s,C:r,D:o,E:l,F:u,G:d,H:m}=this;return[e,s,r,o,l,u,d,m]}set(e,s,r,o,l,u,d,m){this.A=e|0,this.B=s|0,this.C=r|0,this.D=o|0,this.E=l|0,this.F=u|0,this.G=d|0,this.H=m|0}process(e,s){for(let v=0;v<16;v++,s+=4)Ds[v]=e.getUint32(s,!1);for(let v=16;v<64;v++){const b=Ds[v-15],C=Ds[v-2],T=ca(b,7)^ca(b,18)^b>>>3,S=ca(C,17)^ca(C,19)^C>>>10;Ds[v]=S+Ds[v-7]+T+Ds[v-16]|0}let{A:r,B:o,C:l,D:u,E:d,F:m,G:p,H:y}=this;for(let v=0;v<64;v++){const b=ca(d,6)^ca(d,11)^ca(d,25),C=y+b+h5(d,m,p)+E5[v]+Ds[v]|0,S=(ca(r,2)^ca(r,13)^ca(r,22))+m5(r,o,l)|0;y=p,p=m,m=d,d=u+C|0,u=l,l=o,o=r,r=C+S|0}r=r+this.A|0,o=o+this.B|0,l=l+this.C|0,u=u+this.D|0,d=d+this.E|0,m=m+this.F|0,p=p+this.G|0,y=y+this.H|0,this.set(r,o,l,u,d,m,p,y)}roundClean(){Br(Ds)}destroy(){this.set(0,0,0,0,0,0,0,0),Br(this.buffer)}}const V2=g5(["0x428a2f98d728ae22","0x7137449123ef65cd","0xb5c0fbcfec4d3b2f","0xe9b5dba58189dbbc","0x3956c25bf348b538","0x59f111f1b605d019","0x923f82a4af194f9b","0xab1c5ed5da6d8118","0xd807aa98a3030242","0x12835b0145706fbe","0x243185be4ee4b28c","0x550c7dc3d5ffb4e2","0x72be5d74f27b896f","0x80deb1fe3b1696b1","0x9bdc06a725c71235","0xc19bf174cf692694","0xe49b69c19ef14ad2","0xefbe4786384f25e3","0x0fc19dc68b8cd5b5","0x240ca1cc77ac9c65","0x2de92c6f592b0275","0x4a7484aa6ea6e483","0x5cb0a9dcbd41fbd4","0x76f988da831153b5","0x983e5152ee66dfab","0xa831c66d2db43210","0xb00327c898fb213f","0xbf597fc7beef0ee4","0xc6e00bf33da88fc2","0xd5a79147930aa725","0x06ca6351e003826f","0x142929670a0e6e70","0x27b70a8546d22ffc","0x2e1b21385c26c926","0x4d2c6dfc5ac42aed","0x53380d139d95b3df","0x650a73548baf63de","0x766a0abb3c77b2a8","0x81c2c92e47edaee6","0x92722c851482353b","0xa2bfe8a14cf10364","0xa81a664bbc423001","0xc24b8b70d0f89791","0xc76c51a30654be30","0xd192e819d6ef5218","0xd69906245565a910","0xf40e35855771202a","0x106aa07032bbd1b8","0x19a4c116b8d2d0c8","0x1e376c085141ab53","0x2748774cdf8eeb99","0x34b0bcb5e19b48a8","0x391c0cb3c5c95a63","0x4ed8aa4ae3418acb","0x5b9cca4f7763e373","0x682e6ff3d6b2b8a3","0x748f82ee5defb2fc","0x78a5636f43172f60","0x84c87814a1f0ab72","0x8cc702081a6439ec","0x90befffa23631e28","0xa4506cebde82bde9","0xbef9a3f7b2c67915","0xc67178f2e372532b","0xca273eceea26619c","0xd186b8c721c0c207","0xeada7dd6cde0eb1e","0xf57d4f7fee6ed178","0x06f067aa72176fba","0x0a637dc5a2c898a6","0x113f9804bef90dae","0x1b710b35131c471b","0x28db77f523047d84","0x32caab7b40c72493","0x3c9ebe0a15c9bebc","0x431d67c49c100d4c","0x4cc5d4becb3e42b6","0x597f299cfc657e2a","0x5fcb6fab3ad6faec","0x6c44198c4a475817"].map(n=>BigInt(n))),_5=V2[0],j5=V2[1],Ms=new Uint32Array(80),zs=new Uint32Array(80);class A5 extends $2{constructor(e=64){super(128,e,16,!1),this.Ah=en[0]|0,this.Al=en[1]|0,this.Bh=en[2]|0,this.Bl=en[3]|0,this.Ch=en[4]|0,this.Cl=en[5]|0,this.Dh=en[6]|0,this.Dl=en[7]|0,this.Eh=en[8]|0,this.El=en[9]|0,this.Fh=en[10]|0,this.Fl=en[11]|0,this.Gh=en[12]|0,this.Gl=en[13]|0,this.Hh=en[14]|0,this.Hl=en[15]|0}get(){const{Ah:e,Al:s,Bh:r,Bl:o,Ch:l,Cl:u,Dh:d,Dl:m,Eh:p,El:y,Fh:v,Fl:b,Gh:C,Gl:T,Hh:S,Hl:E}=this;return[e,s,r,o,l,u,d,m,p,y,v,b,C,T,S,E]}set(e,s,r,o,l,u,d,m,p,y,v,b,C,T,S,E){this.Ah=e|0,this.Al=s|0,this.Bh=r|0,this.Bl=o|0,this.Ch=l|0,this.Cl=u|0,this.Dh=d|0,this.Dl=m|0,this.Eh=p|0,this.El=y|0,this.Fh=v|0,this.Fl=b|0,this.Gh=C|0,this.Gl=T|0,this.Hh=S|0,this.Hl=E|0}process(e,s){for(let N=0;N<16;N++,s+=4)Ms[N]=e.getUint32(s),zs[N]=e.getUint32(s+=4);for(let N=16;N<80;N++){const z=Ms[N-15]|0,k=zs[N-15]|0,O=Pi(z,k,1)^Pi(z,k,8)^e1(z,k,7),M=Fi(z,k,1)^Fi(z,k,8)^t1(z,k,7),R=Ms[N-2]|0,L=zs[N-2]|0,H=Pi(R,L,19)^yu(R,L,61)^e1(R,L,6),V=Fi(R,L,19)^bu(R,L,61)^t1(R,L,6),q=b5(M,V,zs[N-7],zs[N-16]),P=x5(q,O,H,Ms[N-7],Ms[N-16]);Ms[N]=P|0,zs[N]=q|0}let{Ah:r,Al:o,Bh:l,Bl:u,Ch:d,Cl:m,Dh:p,Dl:y,Eh:v,El:b,Fh:C,Fl:T,Gh:S,Gl:E,Hh:_,Hl:j}=this;for(let N=0;N<80;N++){const z=Pi(v,b,14)^Pi(v,b,18)^yu(v,b,41),k=Fi(v,b,14)^Fi(v,b,18)^bu(v,b,41),O=v&C^~v&S,M=b&T^~b&E,R=w5(j,k,M,j5[N],zs[N]),L=S5(R,_,z,O,_5[N],Ms[N]),H=R|0,V=Pi(r,o,28)^yu(r,o,34)^yu(r,o,39),q=Fi(r,o,28)^bu(r,o,34)^bu(r,o,39),P=r&l^r&d^l&d,J=o&u^o&m^u&m;_=S|0,j=E|0,S=C|0,E=T|0,C=v|0,T=b|0,{h:v,l:b}=Pa(p|0,y|0,L|0,H|0),p=d|0,y=m|0,d=l|0,m=u|0,l=r|0,u=o|0;const ie=v5(H,q,J);r=y5(ie,L,V,P),o=ie|0}({h:r,l:o}=Pa(this.Ah|0,this.Al|0,r|0,o|0)),{h:l,l:u}=Pa(this.Bh|0,this.Bl|0,l|0,u|0),{h:d,l:m}=Pa(this.Ch|0,this.Cl|0,d|0,m|0),{h:p,l:y}=Pa(this.Dh|0,this.Dl|0,p|0,y|0),{h:v,l:b}=Pa(this.Eh|0,this.El|0,v|0,b|0),{h:C,l:T}=Pa(this.Fh|0,this.Fl|0,C|0,T|0),{h:S,l:E}=Pa(this.Gh|0,this.Gl|0,S|0,E|0),{h:_,l:j}=Pa(this.Hh|0,this.Hl|0,_|0,j|0),this.set(r,o,l,u,d,m,p,y,v,b,C,T,S,E,_,j)}roundClean(){Br(Ms,zs)}destroy(){Br(this.buffer),this.set(0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0)}}const Ol=B2(()=>new C5),T5=B2(()=>new A5);/*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) */const Cg=BigInt(0),jp=BigInt(1);function Ap(n,e=""){if(typeof n!="boolean"){const s=e&&`"${e}"`;throw new Error(s+"expected boolean, got type="+typeof n)}return n}function Ru(n,e,s=""){const r=zd(n),o=n?.length,l=e!==void 0;if(!r||l&&o!==e){const u=s&&`"${s}" `,d=l?` of length ${e}`:"",m=r?`length=${o}`:`type=${typeof n}`;throw new Error(u+"expected Uint8Array"+d+", got "+m)}return n}function q2(n){if(typeof n!="string")throw new Error("hex string expected, got "+typeof n);return n===""?Cg:BigInt("0x"+n)}function k5(n){return q2(Eg(n))}function ro(n){return nr(n),q2(Eg(Uint8Array.from(n).reverse()))}function P2(n,e){return L2(n.toString(16).padStart(e*2,"0"))}function F2(n,e){return P2(n,e).reverse()}function ua(n,e,s){let r;if(typeof e=="string")try{r=L2(e)}catch(l){throw new Error(n+" must be hex string or Uint8Array, cause: "+l)}else if(zd(e))r=Uint8Array.from(e);else throw new Error(n+" must be hex string or Uint8Array");const o=r.length;if(typeof s=="number"&&o!==s)throw new Error(n+" of length "+s+" expected, got "+o);return r}function n1(n){return Uint8Array.from(n)}const jm=n=>typeof n=="bigint"&&Cg<=n;function N5(n,e,s){return jm(n)&&jm(e)&&jm(s)&&e<=n&&n<s}function id(n,e,s,r){if(!N5(e,s,r))throw new Error("expected valid "+n+": "+s+" <= n < "+r+", got "+e)}function O5(n){let e;for(e=0;n>Cg;n>>=jp,e+=1);return e}const _g=n=>(jp<<BigInt(n))-jp;function Id(n,e,s={}){if(!n||typeof n!="object")throw new Error("expected valid options object");function r(o,l,u){const d=n[o];if(u&&d===void 0)return;const m=typeof d;if(m!==l||d===null)throw new Error(`param "${o}" is invalid: expected ${l}, got ${m}`)}Object.entries(e).forEach(([o,l])=>r(o,l,!1)),Object.entries(s).forEach(([o,l])=>r(o,l,!0))}function a1(n){const e=new WeakMap;return(s,...r)=>{const o=e.get(s);if(o!==void 0)return o;const l=n(s,...r);return e.set(s,l),l}}/*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) */const fn=BigInt(0),nn=BigInt(1),Nr=BigInt(2),G2=BigInt(3),Z2=BigInt(4),Y2=BigInt(5),R5=BigInt(7),K2=BigInt(8),D5=BigInt(9),X2=BigInt(16);function At(n,e){const s=n%e;return s>=fn?s:e+s}function Yn(n,e,s){let r=n;for(;e-- >fn;)r*=r,r%=s;return r}function s1(n,e){if(n===fn)throw new Error("invert: expected non-zero number");if(e<=fn)throw new Error("invert: expected positive modulus, got "+e);let s=At(n,e),r=e,o=fn,l=nn;for(;s!==fn;){const d=r/s,m=r%s,p=o-l*d;r=s,s=m,o=l,l=p}if(r!==nn)throw new Error("invert: does not exist");return At(o,e)}function jg(n,e,s){if(!n.eql(n.sqr(e),s))throw new Error("Cannot find square root")}function Q2(n,e){const s=(n.ORDER+nn)/Z2,r=n.pow(e,s);return jg(n,r,e),r}function M5(n,e){const s=(n.ORDER-Y2)/K2,r=n.mul(e,Nr),o=n.pow(r,s),l=n.mul(e,o),u=n.mul(n.mul(l,Nr),o),d=n.mul(l,n.sub(u,n.ONE));return jg(n,d,e),d}function z5(n){const e=Hl(n),s=W2(n),r=s(e,e.neg(e.ONE)),o=s(e,r),l=s(e,e.neg(r)),u=(n+R5)/X2;return(d,m)=>{let p=d.pow(m,u),y=d.mul(p,r);const v=d.mul(p,o),b=d.mul(p,l),C=d.eql(d.sqr(y),m),T=d.eql(d.sqr(v),m);p=d.cmov(p,y,C),y=d.cmov(b,v,T);const S=d.eql(d.sqr(y),m),E=d.cmov(p,y,S);return jg(d,E,m),E}}function W2(n){if(n<G2)throw new Error("sqrt is not defined for small field");let e=n-nn,s=0;for(;e%Nr===fn;)e/=Nr,s++;let r=Nr;const o=Hl(n);for(;r1(o,r)===1;)if(r++>1e3)throw new Error("Cannot find square root: probably non-prime P");if(s===1)return Q2;let l=o.pow(r,e);const u=(e+nn)/Nr;return function(m,p){if(m.is0(p))return p;if(r1(m,p)!==1)throw new Error("Cannot find square root");let y=s,v=m.mul(m.ONE,l),b=m.pow(p,e),C=m.pow(p,u);for(;!m.eql(b,m.ONE);){if(m.is0(b))return m.ZERO;let T=1,S=m.sqr(b);for(;!m.eql(S,m.ONE);)if(T++,S=m.sqr(S),T===y)throw new Error("Cannot find square root");const E=nn<<BigInt(y-T-1),_=m.pow(v,E);y=T,v=m.sqr(_),b=m.mul(b,v),C=m.mul(C,_)}return C}}function I5(n){return n%Z2===G2?Q2:n%K2===Y2?M5:n%X2===D5?z5(n):W2(n)}const L5=(n,e)=>(At(n,e)&nn)===nn,U5=["create","isValid","is0","neg","inv","sqrt","sqr","eql","add","sub","mul","pow","div","addN","subN","mulN","sqrN"];function B5(n){const e={ORDER:"bigint",MASK:"bigint",BYTES:"number",BITS:"number"},s=U5.reduce((r,o)=>(r[o]="function",r),e);return Id(n,s),n}function H5(n,e,s){if(s<fn)throw new Error("invalid exponent, negatives unsupported");if(s===fn)return n.ONE;if(s===nn)return e;let r=n.ONE,o=e;for(;s>fn;)s&nn&&(r=n.mul(r,o)),o=n.sqr(o),s>>=nn;return r}function J2(n,e,s=!1){const r=new Array(e.length).fill(s?n.ZERO:void 0),o=e.reduce((u,d,m)=>n.is0(d)?u:(r[m]=u,n.mul(u,d)),n.ONE),l=n.inv(o);return e.reduceRight((u,d,m)=>n.is0(d)?u:(r[m]=n.mul(u,r[m]),n.mul(u,d)),l),r}function r1(n,e){const s=(n.ORDER-nn)/Nr,r=n.pow(e,s),o=n.eql(r,n.ONE),l=n.eql(r,n.ZERO),u=n.eql(r,n.neg(n.ONE));if(!o&&!l&&!u)throw new Error("invalid Legendre symbol result");return o?1:l?0:-1}function $5(n,e){e!==void 0&&sd(e);const s=e!==void 0?e:n.toString(2).length,r=Math.ceil(s/8);return{nBitLength:s,nByteLength:r}}function Hl(n,e,s=!1,r={}){if(n<=fn)throw new Error("invalid field: expected ORDER > 0, got "+n);let o,l,u=!1,d;if(typeof e=="object"&&e!=null){if(r.sqrt||s)throw new Error("cannot specify opts in two arguments");const b=e;b.BITS&&(o=b.BITS),b.sqrt&&(l=b.sqrt),typeof b.isLE=="boolean"&&(s=b.isLE),typeof b.modFromBytes=="boolean"&&(u=b.modFromBytes),d=b.allowedLengths}else typeof e=="number"&&(o=e),r.sqrt&&(l=r.sqrt);const{nBitLength:m,nByteLength:p}=$5(n,o);if(p>2048)throw new Error("invalid field: expected ORDER of <= 2048 bytes");let y;const v=Object.freeze({ORDER:n,isLE:s,BITS:m,BYTES:p,MASK:_g(m),ZERO:fn,ONE:nn,allowedLengths:d,create:b=>At(b,n),isValid:b=>{if(typeof b!="bigint")throw new Error("invalid field element: expected bigint, got "+typeof b);return fn<=b&&b<n},is0:b=>b===fn,isValidNot0:b=>!v.is0(b)&&v.isValid(b),isOdd:b=>(b&nn)===nn,neg:b=>At(-b,n),eql:(b,C)=>b===C,sqr:b=>At(b*b,n),add:(b,C)=>At(b+C,n),sub:(b,C)=>At(b-C,n),mul:(b,C)=>At(b*C,n),pow:(b,C)=>H5(v,b,C),div:(b,C)=>At(b*s1(C,n),n),sqrN:b=>b*b,addN:(b,C)=>b+C,subN:(b,C)=>b-C,mulN:(b,C)=>b*C,inv:b=>s1(b,n),sqrt:l||(b=>(y||(y=I5(n)),y(v,b))),toBytes:b=>s?F2(b,p):P2(b,p),fromBytes:(b,C=!0)=>{if(d){if(!d.includes(b.length)||b.length>p)throw new Error("Field.fromBytes: expected "+d+" bytes, got "+b.length);const S=new Uint8Array(p);S.set(b,s?0:S.length-b.length),b=S}if(b.length!==p)throw new Error("Field.fromBytes: expected "+p+" bytes, got "+b.length);let T=s?ro(b):k5(b);if(u&&(T=At(T,n)),!C&&!v.isValid(T))throw new Error("invalid field element: outside of range 0..ORDER");return T},invertBatch:b=>J2(v,b),cmov:(b,C,T)=>T?C:b});return Object.freeze(v)}/*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) */const od=BigInt(0),Tp=BigInt(1);function i1(n,e){const s=e.negate();return n?s:e}function xu(n,e){const s=J2(n.Fp,e.map(r=>r.Z));return e.map((r,o)=>n.fromAffine(r.toAffine(s[o])))}function eE(n,e){if(!Number.isSafeInteger(n)||n<=0||n>e)throw new Error("invalid window size, expected [1.."+e+"], got W="+n)}function Am(n,e){eE(n,e);const s=Math.ceil(e/n)+1,r=2**(n-1),o=2**n,l=_g(n),u=BigInt(n);return{windows:s,windowSize:r,mask:l,maxNumber:o,shiftBy:u}}function o1(n,e,s){const{windowSize:r,mask:o,maxNumber:l,shiftBy:u}=s;let d=Number(n&o),m=n>>u;d>r&&(d-=l,m+=Tp);const p=e*r,y=p+Math.abs(d)-1,v=d===0,b=d<0,C=e%2!==0;return{nextN:m,offset:y,isZero:v,isNeg:b,isNegF:C,offsetF:p}}function V5(n,e){if(!Array.isArray(n))throw new Error("array expected");n.forEach((s,r)=>{if(!(s instanceof e))throw new Error("invalid point at index "+r)})}function q5(n,e){if(!Array.isArray(n))throw new Error("array of scalars expected");n.forEach((s,r)=>{if(!e.isValid(s))throw new Error("invalid scalar at index "+r)})}const Tm=new WeakMap,tE=new WeakMap;function km(n){return tE.get(n)||1}function l1(n){if(n!==od)throw new Error("invalid wNAF")}class P5{constructor(e,s){this.BASE=e.BASE,this.ZERO=e.ZERO,this.Fn=e.Fn,this.bits=s}_unsafeLadder(e,s,r=this.ZERO){let o=e;for(;s>od;)s&Tp&&(r=r.add(o)),o=o.double(),s>>=Tp;return r}precomputeWindow(e,s){const{windows:r,windowSize:o}=Am(s,this.bits),l=[];let u=e,d=u;for(let m=0;m<r;m++){d=u,l.push(d);for(let p=1;p<o;p++)d=d.add(u),l.push(d);u=d.double()}return l}wNAF(e,s,r){if(!this.Fn.isValid(r))throw new Error("invalid scalar");let o=this.ZERO,l=this.BASE;const u=Am(e,this.bits);for(let d=0;d<u.windows;d++){const{nextN:m,offset:p,isZero:y,isNeg:v,isNegF:b,offsetF:C}=o1(r,d,u);r=m,y?l=l.add(i1(b,s[C])):o=o.add(i1(v,s[p]))}return l1(r),{p:o,f:l}}wNAFUnsafe(e,s,r,o=this.ZERO){const l=Am(e,this.bits);for(let u=0;u<l.windows&&r!==od;u++){const{nextN:d,offset:m,isZero:p,isNeg:y}=o1(r,u,l);if(r=d,!p){const v=s[m];o=o.add(y?v.negate():v)}}return l1(r),o}getPrecomputes(e,s,r){let o=Tm.get(s);return o||(o=this.precomputeWindow(s,e),e!==1&&(typeof r=="function"&&(o=r(o)),Tm.set(s,o))),o}cached(e,s,r){const o=km(e);return this.wNAF(o,this.getPrecomputes(o,e,r),s)}unsafe(e,s,r,o){const l=km(e);return l===1?this._unsafeLadder(e,s,o):this.wNAFUnsafe(l,this.getPrecomputes(l,e,r),s,o)}createCache(e,s){eE(s,this.bits),tE.set(e,s),Tm.delete(e)}hasCache(e){return km(e)!==1}}function F5(n,e,s,r){V5(s,n),q5(r,e);const o=s.length,l=r.length;if(o!==l)throw new Error("arrays of points and scalars must have equal length");const u=n.ZERO,d=O5(BigInt(o));let m=1;d>12?m=d-3:d>4?m=d-2:d>0&&(m=2);const p=_g(m),y=new Array(Number(p)+1).fill(u),v=Math.floor((e.BITS-1)/m)*m;let b=u;for(let C=v;C>=0;C-=m){y.fill(u);for(let S=0;S<l;S++){const E=r[S],_=Number(E>>BigInt(C)&p);y[_]=y[_].add(s[S])}let T=u;for(let S=y.length-1,E=u;S>0;S--)E=E.add(y[S]),T=T.add(E);if(b=b.add(T),C!==0)for(let S=0;S<m;S++)b=b.double()}return b}function c1(n,e,s){if(e){if(e.ORDER!==n)throw new Error("Field.ORDER must match order: Fp == p, Fn == n");return B5(e),e}else return Hl(n,{isLE:s})}function G5(n,e,s={},r){if(r===void 0&&(r=n==="edwards"),!e||typeof e!="object")throw new Error(`expected valid ${n} CURVE object`);for(const m of["p","n","h"]){const p=e[m];if(!(typeof p=="bigint"&&p>od))throw new Error(`CURVE.${m} must be positive bigint`)}const o=c1(e.p,s.Fp,r),l=c1(e.n,s.Fn,r),d=["Gx","Gy","a","d"];for(const m of d)if(!o.isValid(e[m]))throw new Error(`CURVE.${m} must be valid field element of CURVE.Fp`);return e=Object.freeze(Object.assign({},e)),{CURVE:e,Fp:o,Fn:l}}/*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) */const Is=BigInt(0),$t=BigInt(1),Nm=BigInt(2),Z5=BigInt(8);function Y5(n,e,s,r){const o=n.sqr(s),l=n.sqr(r),u=n.add(n.mul(e.a,o),l),d=n.add(n.ONE,n.mul(e.d,n.mul(o,l)));return n.eql(u,d)}function K5(n,e={}){const s=G5("edwards",n,e,e.FpFnLE),{Fp:r,Fn:o}=s;let l=s.CURVE;const{h:u}=l;Id(e,{},{uvRatio:"function"});const d=Nm<<BigInt(o.BYTES*8)-$t,m=E=>r.create(E),p=e.uvRatio||((E,_)=>{try{return{isValid:!0,value:r.sqrt(r.div(E,_))}}catch{return{isValid:!1,value:Is}}});if(!Y5(r,l,l.Gx,l.Gy))throw new Error("bad curve params: generator point");function y(E,_,j=!1){const N=j?$t:Is;return id("coordinate "+E,_,N,d),_}function v(E){if(!(E instanceof T))throw new Error("ExtendedPoint expected")}const b=a1((E,_)=>{const{X:j,Y:N,Z:z}=E,k=E.is0();_==null&&(_=k?Z5:r.inv(z));const O=m(j*_),M=m(N*_),R=r.mul(z,_);if(k)return{x:Is,y:$t};if(R!==$t)throw new Error("invZ was invalid");return{x:O,y:M}}),C=a1(E=>{const{a:_,d:j}=l;if(E.is0())throw new Error("bad point: ZERO");const{X:N,Y:z,Z:k,T:O}=E,M=m(N*N),R=m(z*z),L=m(k*k),H=m(L*L),V=m(M*_),q=m(L*m(V+R)),P=m(H+m(j*m(M*R)));if(q!==P)throw new Error("bad point: equation left != right (1)");const J=m(N*z),ie=m(k*O);if(J!==ie)throw new Error("bad point: equation left != right (2)");return!0});class T{constructor(_,j,N,z){this.X=y("x",_),this.Y=y("y",j),this.Z=y("z",N,!0),this.T=y("t",z),Object.freeze(this)}static CURVE(){return l}static fromAffine(_){if(_ instanceof T)throw new Error("extended point not allowed");const{x:j,y:N}=_||{};return y("x",j),y("y",N),new T(j,N,$t,m(j*N))}static fromBytes(_,j=!1){const N=r.BYTES,{a:z,d:k}=l;_=n1(Ru(_,N,"point")),Ap(j,"zip215");const O=n1(_),M=_[N-1];O[N-1]=M&-129;const R=ro(O),L=j?d:r.ORDER;id("point.y",R,Is,L);const H=m(R*R),V=m(H-$t),q=m(k*H-z);let{isValid:P,value:J}=p(V,q);if(!P)throw new Error("bad point: invalid y coordinate");const ie=(J&$t)===$t,U=(M&128)!==0;if(!j&&J===Is&&U)throw new Error("bad point: x=0 and x_0=1");return U!==ie&&(J=m(-J)),T.fromAffine({x:J,y:R})}static fromHex(_,j=!1){return T.fromBytes(ua("point",_),j)}get x(){return this.toAffine().x}get y(){return this.toAffine().y}precompute(_=8,j=!0){return S.createCache(this,_),j||this.multiply(Nm),this}assertValidity(){C(this)}equals(_){v(_);const{X:j,Y:N,Z:z}=this,{X:k,Y:O,Z:M}=_,R=m(j*M),L=m(k*z),H=m(N*M),V=m(O*z);return R===L&&H===V}is0(){return this.equals(T.ZERO)}negate(){return new T(m(-this.X),this.Y,this.Z,m(-this.T))}double(){const{a:_}=l,{X:j,Y:N,Z:z}=this,k=m(j*j),O=m(N*N),M=m(Nm*m(z*z)),R=m(_*k),L=j+N,H=m(m(L*L)-k-O),V=R+O,q=V-M,P=R-O,J=m(H*q),ie=m(V*P),U=m(H*P),G=m(q*V);return new T(J,ie,G,U)}add(_){v(_);const{a:j,d:N}=l,{X:z,Y:k,Z:O,T:M}=this,{X:R,Y:L,Z:H,T:V}=_,q=m(z*R),P=m(k*L),J=m(M*N*V),ie=m(O*H),U=m((z+k)*(R+L)-q-P),G=ie-J,W=ie+J,te=m(P-j*q),X=m(U*G),ge=m(W*te),Z=m(U*te),ee=m(G*W);return new T(X,ge,ee,Z)}subtract(_){return this.add(_.negate())}multiply(_){if(!o.isValidNot0(_))throw new Error("invalid scalar: expected 1 <= sc < curve.n");const{p:j,f:N}=S.cached(this,_,z=>xu(T,z));return xu(T,[j,N])[0]}multiplyUnsafe(_,j=T.ZERO){if(!o.isValid(_))throw new Error("invalid scalar: expected 0 <= sc < curve.n");return _===Is?T.ZERO:this.is0()||_===$t?this:S.unsafe(this,_,N=>xu(T,N),j)}isSmallOrder(){return this.multiplyUnsafe(u).is0()}isTorsionFree(){return S.unsafe(this,l.n).is0()}toAffine(_){return b(this,_)}clearCofactor(){return u===$t?this:this.multiplyUnsafe(u)}toBytes(){const{x:_,y:j}=this.toAffine(),N=r.toBytes(j);return N[N.length-1]|=_&$t?128:0,N}toHex(){return Eg(this.toBytes())}toString(){return`<Point ${this.is0()?"ZERO":this.toHex()}>`}get ex(){return this.X}get ey(){return this.Y}get ez(){return this.Z}get et(){return this.T}static normalizeZ(_){return xu(T,_)}static msm(_,j){return F5(T,o,_,j)}_setWindowSize(_){this.precompute(_)}toRawBytes(){return this.toBytes()}}T.BASE=new T(l.Gx,l.Gy,$t,m(l.Gx*l.Gy)),T.ZERO=new T(Is,$t,$t,Is),T.Fp=r,T.Fn=o;const S=new P5(T,o.BITS);return T.BASE.precompute(8),T}function X5(n,e,s={}){if(typeof e!="function")throw new Error('"hash" function param is required');Id(s,{},{adjustScalarBytes:"function",randomBytes:"function",domain:"function",prehash:"function",mapToCurve:"function"});const{prehash:r}=s,{BASE:o,Fp:l,Fn:u}=n,d=s.randomBytes||H2,m=s.adjustScalarBytes||(L=>L),p=s.domain||((L,H,V)=>{if(Ap(V,"phflag"),H.length||V)throw new Error("Contexts/pre-hash are not supported");return L});function y(L){return u.create(ro(L))}function v(L){const H=N.secretKey;L=ua("private key",L,H);const V=ua("hashed private key",e(L),2*H),q=m(V.slice(0,H)),P=V.slice(H,2*H),J=y(q);return{head:q,prefix:P,scalar:J}}function b(L){const{head:H,prefix:V,scalar:q}=v(L),P=o.multiply(q),J=P.toBytes();return{head:H,prefix:V,scalar:q,point:P,pointBytes:J}}function C(L){return b(L).pointBytes}function T(L=Uint8Array.of(),...H){const V=Wx(...H);return y(e(p(V,ua("context",L),!!r)))}function S(L,H,V={}){L=ua("message",L),r&&(L=r(L));const{prefix:q,scalar:P,pointBytes:J}=b(H),ie=T(V.context,q,L),U=o.multiply(ie).toBytes(),G=T(V.context,U,J,L),W=u.create(ie+G*P);if(!u.isValid(W))throw new Error("sign failed: invalid s");const te=Wx(U,u.toBytes(W));return Ru(te,N.signature,"result")}const E={zip215:!0};function _(L,H,V,q=E){const{context:P,zip215:J}=q,ie=N.signature;L=ua("signature",L,ie),H=ua("message",H),V=ua("publicKey",V,N.publicKey),J!==void 0&&Ap(J,"zip215"),r&&(H=r(H));const U=ie/2,G=L.subarray(0,U),W=ro(L.subarray(U,ie));let te,X,ge;try{te=n.fromBytes(V,J),X=n.fromBytes(G,J),ge=o.multiplyUnsafe(W)}catch{return!1}if(!J&&te.isSmallOrder())return!1;const Z=T(P,X.toBytes(),te.toBytes(),H);return X.add(te.multiplyUnsafe(Z)).subtract(ge).clearCofactor().is0()}const j=l.BYTES,N={secretKey:j,publicKey:j,signature:2*j,seed:j};function z(L=d(N.seed)){return Ru(L,N.seed,"seed")}function k(L){const H=R.randomSecretKey(L);return{secretKey:H,publicKey:C(H)}}function O(L){return zd(L)&&L.length===u.BYTES}function M(L,H){try{return!!n.fromBytes(L,H)}catch{return!1}}const R={getExtendedPublicKey:b,randomSecretKey:z,isValidSecretKey:O,isValidPublicKey:M,toMontgomery(L){const{y:H}=n.fromBytes(L),V=N.publicKey,q=V===32;if(!q&&V!==57)throw new Error("only defined for 25519 and 448");const P=q?l.div($t+H,$t-H):l.div(H-$t,H+$t);return l.toBytes(P)},toMontgomerySecret(L){const H=N.secretKey;Ru(L,H);const V=e(L.subarray(0,H));return m(V).subarray(0,H)},randomPrivateKey:z,precompute(L=8,H=n.BASE){return H.precompute(L,!1)}};return Object.freeze({keygen:k,getPublicKey:C,sign:S,verify:_,utils:R,Point:n,lengths:N})}function Q5(n){const e={a:n.a,d:n.d,p:n.Fp.ORDER,n:n.n,h:n.h,Gx:n.Gx,Gy:n.Gy},s=n.Fp,r=Hl(e.n,n.nBitLength,!0),o={Fp:s,Fn:r,uvRatio:n.uvRatio},l={randomBytes:n.randomBytes,adjustScalarBytes:n.adjustScalarBytes,domain:n.domain,prehash:n.prehash,mapToCurve:n.mapToCurve};return{CURVE:e,curveOpts:o,hash:n.hash,eddsaOpts:l}}function W5(n,e){const s=e.Point;return Object.assign({},e,{ExtendedPoint:s,CURVE:n,nBitLength:s.Fn.BITS,nByteLength:s.Fn.BYTES})}function J5(n){const{CURVE:e,curveOpts:s,hash:r,eddsaOpts:o}=Q5(n),l=K5(e,s),u=X5(l,r,o);return W5(n,u)}/*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) */const fl=BigInt(0),Gi=BigInt(1),wu=BigInt(2);function eR(n){return Id(n,{adjustScalarBytes:"function",powPminus2:"function"}),Object.freeze({...n})}function tR(n){const e=eR(n),{P:s,type:r,adjustScalarBytes:o,powPminus2:l,randomBytes:u}=e,d=r==="x25519";if(!d&&r!=="x448")throw new Error("invalid type");const m=u||H2,p=d?255:448,y=d?32:56,v=BigInt(d?9:5),b=BigInt(d?121665:39081),C=d?wu**BigInt(254):wu**BigInt(447),T=d?BigInt(8)*wu**BigInt(251)-Gi:BigInt(4)*wu**BigInt(445)-Gi,S=C+T+Gi,E=P=>At(P,s),_=j(v);function j(P){return F2(E(P),y)}function N(P){const J=ua("u coordinate",P,y);return d&&(J[31]&=127),E(ro(J))}function z(P){return ro(o(ua("scalar",P,y)))}function k(P,J){const ie=R(N(J),z(P));if(ie===fl)throw new Error("invalid private or public key received");return j(ie)}function O(P){return k(P,_)}function M(P,J,ie){const U=E(P*(J-ie));return J=E(J-U),ie=E(ie+U),{x_2:J,x_3:ie}}function R(P,J){id("u",P,fl,s),id("scalar",J,C,S);const ie=J,U=P;let G=Gi,W=fl,te=P,X=Gi,ge=fl;for(let ee=BigInt(p-1);ee>=fl;ee--){const fe=ie>>ee&Gi;ge^=fe,{x_2:G,x_3:te}=M(ge,G,te),{x_2:W,x_3:X}=M(ge,W,X),ge=fe;const ue=G+W,oe=E(ue*ue),Ce=G-W,me=E(Ce*Ce),he=oe-me,He=te+X,ke=te-X,De=E(ke*ue),$e=E(He*Ce),ze=De+$e,pt=De-$e;te=E(ze*ze),X=E(U*E(pt*pt)),G=E(oe*me),W=E(he*(oe+E(b*he)))}({x_2:G,x_3:te}=M(ge,G,te)),{x_2:W,x_3:X}=M(ge,W,X);const Z=l(W);return E(G*Z)}const L={secretKey:y,publicKey:y,seed:y},H=(P=m(y))=>(nr(P,L.seed),P);function V(P){const J=H(P);return{secretKey:J,publicKey:O(J)}}return{keygen:V,getSharedSecret:(P,J)=>k(P,J),getPublicKey:P=>O(P),scalarMult:k,scalarMultBase:O,utils:{randomSecretKey:H,randomPrivateKey:H},GuBytes:_.slice(),lengths:L}}/*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) */const nR=BigInt(1),u1=BigInt(2),aR=BigInt(3),sR=BigInt(5),rR=BigInt(8),Ag=BigInt("0x7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffed"),nE={p:Ag,n:BigInt("0x1000000000000000000000000000000014def9dea2f79cd65812631a5cf5d3ed"),h:rR,a:BigInt("0x7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffec"),d:BigInt("0x52036cee2b6ffe738cc740797779e89800700a4d4141d8ab75eb4dca135978a3"),Gx:BigInt("0x216936d3cd6e53fec0a4e231fdd6dc5c692cc7609525a7b2c9562d608f25d51a"),Gy:BigInt("0x6666666666666666666666666666666666666666666666666666666666666658")};function aE(n){const e=BigInt(10),s=BigInt(20),r=BigInt(40),o=BigInt(80),l=Ag,d=n*n%l*n%l,m=Yn(d,u1,l)*d%l,p=Yn(m,nR,l)*n%l,y=Yn(p,sR,l)*p%l,v=Yn(y,e,l)*y%l,b=Yn(v,s,l)*v%l,C=Yn(b,r,l)*b%l,T=Yn(C,o,l)*C%l,S=Yn(T,o,l)*C%l,E=Yn(S,e,l)*y%l;return{pow_p_5_8:Yn(E,u1,l)*n%l,b2:d}}function sE(n){return n[0]&=248,n[31]&=127,n[31]|=64,n}const d1=BigInt("19681161376707505956807079304988542015446066515923890162744021073123829784752");function iR(n,e){const s=Ag,r=At(e*e*e,s),o=At(r*r*e,s),l=aE(n*o).pow_p_5_8;let u=At(n*r*l,s);const d=At(e*u*u,s),m=u,p=At(u*d1,s),y=d===n,v=d===At(-n,s),b=d===At(-n*d1,s);return y&&(u=m),(v||b)&&(u=p),L5(u,s)&&(u=At(-u,s)),{isValid:y||v,value:u}}const rE=Hl(nE.p,{isLE:!0}),oR={...nE,Fp:rE,hash:T5,adjustScalarBytes:sE,uvRatio:iR},Tg=J5(oR),Ar=(()=>{const n=rE.ORDER;return tR({P:n,type:"x25519",powPminus2:e=>{const{pow_p_5_8:s,b2:r}=aE(e);return At(Yn(s,aR,n)*r,n)},adjustScalarBytes:sE})})();class iE extends U2{constructor(e,s){super(),this.finished=!1,this.destroyed=!1,Sg(e);const r=Nl(s);if(this.iHash=e.create(),typeof this.iHash.update!="function")throw new Error("Expected instance of class which extends utils.Hash");this.blockLen=this.iHash.blockLen,this.outputLen=this.iHash.outputLen;const o=this.blockLen,l=new Uint8Array(o);l.set(r.length>o?e.create().update(r).digest():r);for(let u=0;u<l.length;u++)l[u]^=54;this.iHash.update(l),this.oHash=e.create();for(let u=0;u<l.length;u++)l[u]^=106;this.oHash.update(l),Br(l)}update(e){return rd(this),this.iHash.update(e),this}digestInto(e){rd(this),nr(e,this.outputLen),this.finished=!0,this.iHash.digestInto(e),this.oHash.update(e),this.oHash.digestInto(e),this.destroy()}digest(){const e=new Uint8Array(this.oHash.outputLen);return this.digestInto(e),e}_cloneInto(e){e||(e=Object.create(Object.getPrototypeOf(this),{}));const{oHash:s,iHash:r,finished:o,destroyed:l,blockLen:u,outputLen:d}=this;return e=e,e.finished=o,e.destroyed=l,e.blockLen=u,e.outputLen=d,e.oHash=s._cloneInto(e.oHash),e.iHash=r._cloneInto(e.iHash),e}clone(){return this._cloneInto()}destroy(){this.destroyed=!0,this.oHash.destroy(),this.iHash.destroy()}}const Ld=(n,e,s)=>new iE(n,e).update(s).digest();Ld.create=(n,e)=>new iE(n,e);function lR(n,e,s){return Sg(n),s===void 0&&(s=new Uint8Array(n.outputLen)),Ld(n,Nl(s),Nl(e))}const Om=Uint8Array.from([0]),f1=Uint8Array.of();function cR(n,e,s,r=32){Sg(n),sd(r);const o=n.outputLen;if(r>255*o)throw new Error("Length should be <= 255*HashLen");const l=Math.ceil(r/o);s===void 0&&(s=f1);const u=new Uint8Array(l*o),d=Ld.create(n,e),m=d._cloneInto(),p=new Uint8Array(d.outputLen);for(let y=0;y<l;y++)Om[0]=y+1,m.update(y===0?f1:p).update(s).update(Om).digestInto(p),u.set(p,o*y),d._cloneInto(m);return d.destroy(),m.destroy(),Br(p,Om),u.slice(0,r)}const uR=(n,e,s,r,o)=>cR(n,lR(n,e,s),r,o);function dR(n){const e=[];for(let s=0;s<n.length;s++){let r=n.charCodeAt(s);if(r>=55296&&r<=56319&&s+1<n.length){const o=n.charCodeAt(s+1);o>=56320&&o<=57343&&(r=65536+(r-55296<<10)+(o-56320),s++)}r<128?e.push(r):r<2048?e.push(192|r>>6,128|r&63):r<65536?e.push(224|r>>12,128|r>>6&63,128|r&63):e.push(240|r>>18,128|r>>12&63,128|r>>6&63,128|r&63)}return Uint8Array.from(e)}function fR(n){let e="",s=[];const r=()=>{e+=String.fromCharCode(...s),s=[]};for(let o=0;o<n.length;){const l=n[o];let u;l<128?(u=l,o+=1):l>=240?(u=(l&7)<<18|(n[o+1]&63)<<12|(n[o+2]&63)<<6|n[o+3]&63,o+=4):l>=224?(u=(l&15)<<12|(n[o+1]&63)<<6|n[o+2]&63,o+=3):(u=(l&31)<<6|n[o+1]&63,o+=2),u>65535?(u-=65536,s.push(55296+(u>>10),56320+(u&1023))):s.push(u),s.length>8e3&&r()}return r(),e}const Hr={encode:dR},yl="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_",hR=new Map([...yl].map((n,e)=>[n,e]));function Qn(n){let e="";for(let s=0;s<n.length;s+=3){const r=n[s]<<16|(n[s+1]??0)<<8|(n[s+2]??0);e+=yl[r>>18&63]+yl[r>>12&63],s+1<n.length&&(e+=yl[r>>6&63]),s+2<n.length&&(e+=yl[r&63])}return e}function pa(n){const e=n.replace(/=+$/,"").replace(/\+/g,"-").replace(/\//g,"_"),s=new Uint8Array(Math.floor(e.length*3/4));let r=0,o=0,l=0;for(const u of e){const d=hR.get(u);if(d===void 0)throw new Error("invalid base64");o=o<<6|d,r+=6,r>=8&&(r-=8,s[l++]=o>>r&255)}return s.subarray(0,l)}function h1(...n){const e=new Uint8Array(n.reduce((r,o)=>r+o.length,0));let s=0;for(const r of n)e.set(r,s),s+=r.length;return e}function ld(n){const e=new Uint8Array(n);return globalThis.crypto.getRandomValues(e),e}function oE(n){return Qn(Ol(pa(n)).subarray(0,16))}function mR(){const n=ld(32),e=ld(32),s=Qn(Tg.getPublicKey(n));return{id:oE(s),signKey:s,boxKey:Qn(Ar.getPublicKey(e)),signSecret:Qn(n),boxSecret:Qn(e)}}function cd(n){return{id:n.id,signKey:n.signKey,boxKey:n.boxKey}}function lE(n,e){return Qn(Tg.sign(Hr.encode(e),pa(n.signSecret)))}function pR(n,e,s){try{return Tg.verify(pa(s),Hr.encode(e),pa(n))}catch{return!1}}function gR(n){return`linkshell-gateway-v2:${n}`}function cE(n,e){return Qn(Ld(Ol,pa(n),Hr.encode(`${e.id}.${e.boxKey}`)))}function vR(n){return Qn(Ol(Hr.encode(`linkshell-pair-code:${n}`)))}function yR(){const n=ld(32);return{secret:n,public:Qn(Ar.getPublicKey(n))}}function bR(n){const e=pa(n.local.boxSecret),s=pa(n.remoteBoxKey),r=pa(n.remoteEphemeral),o=Ar.getSharedSecret(n.localEphemeral,r),l=Ar.getSharedSecret(e,s),u=Ar.getSharedSecret(n.localEphemeral,s),d=Ar.getSharedSecret(e,r),m=u,p=d,y=Ar.getPublicKey(n.localEphemeral),[v,b]=[y,r],[C,T]=[pa(n.local.boxKey),s],S=h1(Hr.encode("linkshell/v2/channel"),v,b,C,T),E=uR(Ol,h1(o,m,p,l),Ol(S),Hr.encode("linkshell/v2/keys"),64),_=E.subarray(0,32),j=E.subarray(32,64);return n.initiator?{send:_,receive:j}:{send:j,receive:_}}function m1(n){const e=new Uint8Array(24),s=new DataView(e.buffer);return s.setUint32(16,Math.floor(n/2**32)),s.setUint32(20,n>>>0),e}class xR{constructor(e){this.keys=e}sent=0;received=0;seal(e){const s=++this.sent,r=Xx(this.keys.send,m1(s)).encrypt(Hr.encode(e));return`${s}.${Qn(r)}`}open(e){const s=e.indexOf("."),r=Number(e.slice(0,s));if(!Number.isSafeInteger(r)||r<=this.received)throw new Error("replayed or out-of-order frame");const o=Xx(this.keys.receive,m1(r)).decrypt(pa(e.slice(s+1)));return this.received=r,fR(o)}}const wR="/v2/connect",Ud=I({id:A(),signKey:A(),boxKey:A()}),SR=Me(["machine","device"]);Ud.extend({name:A(),platform:A().optional(),online:ye(),via:Me(["paired","account"])});Ud.extend({name:A(),online:ye(),pairedAt:se().optional()});wa("t",[I({t:pe("auth"),role:SR,identity:Ud,signature:A(),name:A().max(120),platform:A().max(40).optional(),token:A().optional()}),I({t:pe("req"),id:se().int(),method:A(),params:jn().optional()}),I({t:pe("to"),to:A(),d:A().max(40*1024*1024)}),I({t:pe("ping")})]);const ER=wa("t",[I({t:pe("challenge"),nonce:A()}),I({t:pe("ready"),userId:A().optional(),email:A().optional()}),I({t:pe("res"),id:se().int(),result:jn().optional(),error:I({code:A(),message:A()}).optional()}),I({t:pe("event"),name:A(),data:jn()}),I({t:pe("from"),from:Ud,via:Me(["paired","account"]),d:A()}),I({t:pe("undeliverable"),to:A(),reason:A()}),I({t:pe("pong")}),I({t:pe("error"),code:A(),message:A()})]),p1="linkshell://pair?";function uE(n){const e=n.trim();if(!e.startsWith(p1))return;const s=new URLSearchParams(e.slice(p1.length)),r=s.get("g"),o=s.get("k"),l=s.get("s"),u=s.get("c");if(!(!r||!o||!l||!u||!/^(wss?|https?):\/\//.test(r)))return{gateway:r,signKey:o,secret:l,code:u}}const CR=wa("k",[I({k:pe("hello"),ch:A(),eph:A(),sig:A()}),I({k:pe("welcome"),ch:A(),eph:A(),sig:A()}),I({k:pe("data"),ch:A(),box:A()}),I({k:pe("close"),ch:A(),reason:A().optional()}),I({k:pe("refuse"),ch:A(),code:A(),message:A()})]);function g1(n,e,s,r,o){return`linkshell-tunnel-v2:${n}:${e}:${s}:${r}:${o}`}function _R(n,e,s){const r=yR();return{hello:{k:"hello",ch:s,eph:r.public,sig:lE(n,g1("hello",s,n.id,e.id,r.public))},accept(l){if(!pR(e.signKey,g1("welcome",s,e.id,n.id,l.eph),l.sig))throw new Error("the computer's key doesn't match: refusing to connect");return new xR(bR({initiator:!0,local:n,localEphemeral:r.secret,remoteBoxKey:e.boxKey,remoteEphemeral:l.eph}))}}}class Su extends Error{constructor(e,s){super(s),this.code=e}}const jR=1;class AR{constructor(e){this.options=e}socket;statusValue="offline";attempt=0;timer;nextId=1;pending=new Map;statusListeners=new Set;frameListeners=new Set;undeliverableListeners=new Set;eventListeners=new Map;waiters=new Set;account;lastError;get status(){return this.statusValue}get identity(){return cd(this.options.identity)}onStatus(e){return this.statusListeners.add(e),()=>this.statusListeners.delete(e)}onFrame(e){return this.frameListeners.add(e),()=>this.frameListeners.delete(e)}onUndeliverable(e){return this.undeliverableListeners.add(e),()=>this.undeliverableListeners.delete(e)}on(e,s){let r=this.eventListeners.get(e);r||this.eventListeners.set(e,r=new Set);const o=s;return r.add(o),()=>r.delete(o)}start(){this.statusValue==="connecting"||this.statusValue==="online"||this.open()}stop(){this.setStatus("stopped"),clearTimeout(this.timer),this.socket?.close(1e3,"stopped"),this.socket=void 0,this.failPending("stopped");for(const e of this.waiters)e()}reconnectNow(){this.statusValue==="stopped"||this.statusValue==="online"||this.statusValue==="connecting"||(clearTimeout(this.timer),this.attempt=0,this.open())}reauthenticate(){if(this.statusValue==="stopped")return;clearTimeout(this.timer),this.attempt=0;const e=this.socket;this.socket=void 0,e?.close(1e3,"signing in again"),this.failPending("connection closed"),this.open()}waitOnline(e){return this.statusValue==="online"?Promise.resolve(!0):this.statusValue==="stopped"?Promise.resolve(!1):new Promise(s=>{const r=()=>{clearTimeout(o),this.waiters.delete(r),s(this.statusValue==="online")},o=setTimeout(r,e);this.waiters.add(r)})}async request(e,s,r){const o=r??this.options.requestTimeoutMs??2e4;if(!await this.waitOnline(o))throw new Su("offline","not connected to the gateway");const l=this.nextId++;return new Promise((u,d)=>{const m=setTimeout(()=>{this.pending.delete(l),d(new Su("timeout",`${e} timed out`))},o);this.pending.set(l,{resolve:u,reject:d,timer:m}),this.sendFrame({t:"req",id:l,method:e,params:s})})}send(e,s){return this.statusValue!=="online"?!1:this.sendFrame({t:"to",to:e,d:JSON.stringify(s)})}sendFrame(e){return!this.socket||this.socket.readyState!==jR?!1:(this.socket.send(JSON.stringify(e)),!0)}setStatus(e,s){if(s&&(this.lastError=s),e==="online"&&(this.lastError=void 0),!(this.statusValue===e&&!s)){this.statusValue=e;for(const r of this.statusListeners)r(e,s);if(e==="online"||e==="stopped")for(const r of this.waiters)r()}}failPending(e){for(const[s,r]of this.pending)clearTimeout(r.timer),r.reject(new Su("offline",e)),this.pending.delete(s)}open(){this.setStatus("connecting");let e;try{e=this.options.createSocket(this.options.url)}catch(r){this.scheduleReconnect({code:"connect_failed",message:r instanceof Error?r.message:String(r)});return}this.socket=e;let s;e.onmessage=r=>{let o;try{const l=ER.safeParse(JSON.parse(String(r.data)));if(!l.success)return;o=l.data}catch{return}switch(o.t){case"challenge":this.authenticate(o.nonce);return;case"ready":this.attempt=0,this.account=o.userId?{userId:o.userId,email:o.email}:void 0,this.setStatus("online");return;case"res":{const l=this.pending.get(o.id);if(!l)return;clearTimeout(l.timer),this.pending.delete(o.id),o.error?l.reject(new Su(o.error.code,o.error.message)):l.resolve(o.result);return}case"event":for(const l of this.eventListeners.get(o.name)??[])l(o.data);return;case"from":{let l;try{const u=CR.safeParse(JSON.parse(o.d));if(!u.success)return;l=u.data}catch{return}for(const u of this.frameListeners)u(o.from,o.via,l);return}case"undeliverable":for(const l of this.undeliverableListeners)l(o.to,o.reason);return;case"error":s={code:o.code,message:o.message};return;case"pong":return}},e.onerror=()=>{},e.onclose=r=>{if(this.socket===e&&(this.socket=void 0,this.failPending("connection closed"),this.statusValue!=="stopped")){if(r.code===4e3){this.setStatus("offline",{code:"replaced",message:"connected elsewhere with this identity"});return}this.scheduleReconnect(s??{code:"disconnected",message:r.reason||"connection lost"})}}}async authenticate(e){let s;try{s=await this.options.token?.()??void 0}catch{s=void 0}this.sendFrame({t:"auth",role:this.options.role,identity:cd(this.options.identity),signature:lE(this.options.identity,gR(e)),name:this.options.name.slice(0,120),platform:this.options.platform,token:s})}scheduleReconnect(e){this.setStatus("offline",e);const s=this.options.minBackoffMs??500,r=this.options.maxBackoffMs??3e4,o=Math.min(r,s*2**this.attempt)*(.75+Math.random()*.5);this.attempt+=1,this.timer=setTimeout(()=>this.open(),o)}}const TR="linkshell-bulk",v1=16*1024,dE=1,fE=2;function y1(n){const e=n.type==="data"?n.data:new TextEncoder().encode(n.error??""),s=new Uint8Array(5+e.length);return s[0]=n.type==="data"?dE:fE,new DataView(s.buffer).setUint32(1,n.stream),s.set(e,5),s}function kR(n){if(n.length<5)return;const e=new DataView(n.buffer,n.byteOffset,n.byteLength).getUint32(1),s=n.subarray(5);if(n[0]===dE)return{type:"data",stream:e,data:s};if(n[0]===fE)return{type:"close",stream:e,error:s.length?new TextDecoder().decode(s):void 0}}const b1=48*1024,NR=I({id:A().regex(/^[a-f0-9]{64}$/),target:A().max(1024),capturedAt:se().finite().nonnegative(),width:se().int().positive().max(2048),height:se().int().positive().max(2048),mimeType:pe("image/webp")});class OR{held=new Uint8Array(0);push(e){if(this.held.length+e.length>b1+4104)throw new Error("preview buffer too large");const s=new Uint8Array(this.held.length+e.length);s.set(this.held),s.set(e,this.held.length),this.held=s;const r=[];for(;this.held.length>=8;){const o=new DataView(this.held.buffer,this.held.byteOffset),l=o.getUint32(0),u=o.getUint32(4);if(l>4096||u>b1||!l||!u)throw new Error("invalid preview frame");const d=8+l+u;if(this.held.length<d)break;const m=NR.parse(JSON.parse(new TextDecoder().decode(this.held.subarray(8,8+l))));r.push({...m,bytes:this.held.slice(8+l,d)}),this.held=this.held.slice(d)}return r}}function Rm(n,e){const s=n.header??n.text,r=e?.values??[],o=n.constraints;if(r.length>1&&n.kind!=="choices")return`${s}只能填写一个答案`;if(n.options&&r.some(d=>!n.options.some(m=>m.value===d)))return`${s}包含无效选项`;if(!(o?.type==="array"?e!==void 0:o?.type==="string"?r[0]!==void 0||!!e?.other?.trim():r.some(d=>d!=="")||!!e?.other?.trim()))return n.required?`还没回答:${s}`:void 0;if(!o)return;const u=r[0]??"";if(o.type==="number"||o.type==="integer"){const d=Number(u);if(!u.trim()||!Number.isFinite(d)||o.type==="integer"&&!Number.isInteger(d))return`${s}需要填写${o.type==="integer"?"整数":"数字"}`;if(o.minimum!==void 0&&d<o.minimum)return`${s}不能小于 ${o.minimum}`;if(o.maximum!==void 0&&d>o.maximum)return`${s}不能大于 ${o.maximum}`}if(o.type==="array"){if(new Set(r).size!==r.length)return`${s}不能重复选择`;if(o.minItems!==void 0&&r.length<o.minItems)return`${s}至少选择 ${o.minItems} 项`;if(o.maxItems!==void 0&&r.length>o.maxItems)return`${s}最多选择 ${o.maxItems} 项`}if(o.type==="string"){const d=[...u].length;if(o.minLength!==void 0&&d<o.minLength)return`${s}至少需要 ${o.minLength} 个字符`;if(o.maxLength!==void 0&&d>o.maxLength)return`${s}最多允许 ${o.maxLength} 个字符`;if(o.pattern)try{if(!new RegExp(o.pattern,"u").test(u))return`${s}格式不符合要求`}catch{return`${s}的格式规则无效`}if(o.format==="email"&&!/^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(u))return`${s}需要有效的邮箱地址`;if(o.format==="uri")try{new URL(u)}catch{return`${s}需要完整的网址`}if(o.format==="date"&&(!/^\d{4}-\d{2}-\d{2}$/.test(u)||!Number.isFinite(Date.parse(u))||new Date(u).toISOString().slice(0,10)!==u))return`${s}需要有效日期(YYYY-MM-DD)`;if(o.format==="date-time"&&(!/^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}(?:\.\d+)?(?:Z|[+-]\d{2}:\d{2})$/i.test(u)||!Number.isFinite(Date.parse(u))))return`${s}需要包含时区的有效日期时间`}}function to(n){return{sessionId:n,lastSeq:0,startSeq:0,items:[],index:{},permissions:[],config:[],commands:[],state:"idle",turnActive:!1}}function jt(n,e){const s=n.index[e.id];if(s===void 0)return{...n,items:[...n.items,e],index:{...n.index,[e.id]:n.items.length}};const r=n.items.slice();return r[s]=e,{...n,items:r}}function _n(n,e,s){const r=n.index[e],o=r===void 0?void 0:n.items[r];return o&&o.kind===s?o:void 0}function x1(n,e){return e.type==="text"?n+e.text:n}function Du(n,e){let s;return n.items.forEach((r,o)=>{(r.kind==="agent"||r.kind==="thought")&&r.streaming&&(s??=n.items.slice(),s[o]=r.kind==="thought"?{...r,streaming:!1,endedTs:r.endedTs??e}:{...r,streaming:!1})}),s?{...n,items:s}:n}function ud(n,e){const s=Du(n,e);let r;return s.items.forEach((o,l)=>{if(o.kind!=="tool"||!o.sub)return;const u=ud(o.sub,e);u!==o.sub&&(r??=s.items.slice(),r[l]={...o,sub:u})}),r?{...s,items:r}:s}function RR(n){switch(n.sessionUpdate){case"ls_message":return n.parentToolCallId;case"agent_message_chunk":case"agent_thought_chunk":case"tool_call":case"tool_call_update":case"ls_message_done":case"ls_turn":return n.parentToolCallId;default:return}}function DR(n,e){return n.flatMap(s=>{const r=e.find(u=>u.id===s.id);if(!r)return[];const o=r.values.filter(Boolean).map(u=>s.options?.find(d=>d.value===u)?.label??u),l=[...s.secret&&o.length>0?["••••••"]:o,...r.other?[r.other]:[]];return l.length>0?[{question:s.header??s.text,answer:l.join(",")}]:[]})}function hE(n,e,s,r,o){if(!_n(n,e,"tool")){for(const m of n.items)if(!(m.kind!=="tool"||!m.sub||!kg(m.sub,e)))return jt(n,{...m,sub:hE(m.sub,e,s,r,o)})}const l=_n(n,e,"tool")??{kind:"tool",id:e,title:"Sub-agent",toolKind:"other",status:"in_progress",detail:{type:"subagent",action:"spawn"},content:[],output:"",ts:r},u={...s,parentToolCallId:void 0},d=Ng(l.sub??to(n.sessionId),u,r,o);return d===l.sub?n:jt(n,{...l,sub:d})}function kg(n,e){const s=_n(n,e,"tool");if(s)return s;for(const r of n.items){if(r.kind!=="tool"||!r.sub)continue;const o=kg(r.sub,e);if(o)return o}}function Ng(n,e,s,r){const o=RR(e);if(o)return hE(n,o,e,s,r);switch(e.sessionUpdate){case"ls_message":{const l=e.role==="thought"?`thought:${e.messageId}`:e.messageId,u=e.role==="session"?"agent":e.role,d=_n(n,l,u);if(e.content===void 0&&d)return u==="agent"?jt(n,{...d,senderSessionId:e.senderSessionId??(d.kind==="agent"?d.senderSessionId:void 0),recipientSessionId:e.recipientSessionId??(d.kind==="agent"?d.recipientSessionId:void 0)}):n;const m=e.content??[],p=m.filter(v=>v.type==="text").map(v=>v.text).join(""),y=d?.ts??s;if(u==="user"){const v=e.append&&d?.kind==="user"?[...d.blocks,...m]:m;return jt(n,{kind:"user",id:l,blocks:kp(v),agentMessages:dp(v),ts:y})}return u==="thought"?jt(n,{kind:"thought",id:l,text:(e.append&&d?.kind==="thought"?d.text:"")+p,streaming:n.turnActive,ts:y}):jt(n,{kind:"agent",id:l,text:(e.append&&d?.kind==="agent"?d.text:"")+p,attachments:[...e.append&&d?.kind==="agent"?d.attachments??[]:[],...m.filter(v=>v.type!=="text")],senderSessionId:e.senderSessionId??(d?.kind==="agent"?d.senderSessionId:void 0),recipientSessionId:e.recipientSessionId??(d?.kind==="agent"?d.recipientSessionId:void 0),streaming:n.turnActive,ts:y})}case"user_message_chunk":{const l=e.messageId??`user-${r}`,u=_n(n,l,"user"),d=u&&!u.pending?[...u.blocks,e.content]:[e.content];return jt(n,{kind:"user",id:l,blocks:kp(d),agentMessages:dp(d),ts:u?.ts??s})}case"agent_message_chunk":{const l=_n(n,e.messageId,"agent"),u=e.content.type==="text"?l?.attachments:[...l?.attachments??[],e.content];return jt(n,{kind:"agent",id:e.messageId,text:x1(l?.text??"",e.content),attachments:u,streaming:!0,ts:l?.ts??s})}case"agent_thought_chunk":{const l=`thought:${e.messageId}`,u=_n(n,l,"thought");return jt(n,{kind:"thought",id:l,text:x1(u?.text??"",e.content),streaming:!0,ts:u?.ts??s})}case"ls_message_done":{const l=e.role==="thought"?`thought:${e.messageId}`:e.messageId,u=_n(n,l,"agent");if(u)return jt(n,{...u,streaming:!1,...e.questions?.length?{questions:e.questions}:{}});const d=_n(n,l,"thought");return d?jt(n,{...d,streaming:!1,endedTs:d.endedTs??s}):n}case"tool_call":{const l=_n(n,e.toolCallId,"tool"),u=e.status==="completed"||e.status==="failed";return jt(Du(n,s),{kind:"tool",id:e.toolCallId,title:e.title,name:e.name??l?.name,toolKind:e.kind,status:e.status,rawInput:e.rawInput??l?.rawInput,rawOutput:e.rawOutput??l?.rawOutput,locations:e.locations??l?.locations,detail:e.detail??l?.detail,sub:l?.sub,content:e.content??l?.content??[],output:l?.output??"",ts:l?.ts??s,endedTs:u?s:l?.endedTs})}case"tool_call_update":{const u=_n(n,e.toolCallId,"tool")??{kind:"tool",id:e.toolCallId,title:e.title??"Tool",toolKind:"other",status:"in_progress",content:[],output:"",ts:s},d=e.status??u.status,m=d==="completed"||d==="failed";return jt(n,{...u,title:e.title??u.title,name:e.name??u.name,toolKind:e.kind??u.toolKind,rawInput:e.rawInput===void 0?u.rawInput:e.rawInput,locations:e.locations??u.locations,detail:e.detail??u.detail,status:d,content:e.content?e.replaceContent?e.content:pE(u.content,e.content):u.content,output:e.replaceOutput??(e.appendOutput?u.output+e.appendOutput:u.output),rawOutput:e.rawOutput===void 0?u.rawOutput:e.rawOutput,endedTs:m?u.endedTs??s:e.status?void 0:u.endedTs,sub:m&&u.sub?ud(u.sub,s):u.sub})}case"plan":{const l=e.planId?`plan:${e.planId}`:n.planId??`plan-${r}`;return e.removed?Np(n,l):{...jt(n,{kind:"plan",id:l,entries:e.entries,title:e.title,markdown:e.markdown,path:e.path,ts:_n(n,l,"plan")?.ts??s}),planId:l}}case"available_commands_update":return{...n,commands:e.availableCommands};case"ls_goal":return{...n,goal:e.goal};case"current_mode_update":return{...n,modeId:e.currentModeId,config:n.config.map(l=>l.category==="mode"?{...l,current:e.currentModeId}:l)};case"ls_config":return{...n,config:e.options,modeId:e.options.find(l=>l.category==="mode")?.current??n.modeId};case"session_info_update":return{...n,title:e.title===null?void 0:e.title??n.title};case"usage_update":return{...n,usage:{...n.usage,usedTokens:e.usedTokens??n.usage?.usedTokens,contextWindow:e.contextWindow??n.usage?.contextWindow,cost:e.cost===void 0?n.usage?.cost:e.cost,tokens:e.tokens??n.usage?.tokens}};case"ls_turn":if(e.state==="started")return{...n,turnActive:!0,state:"running",planId:void 0};{const l=ud(n,s),u={...l,turnActive:!1,state:l.permissions.some(d=>d.childSessionId)?"waiting":e.stopReason==="error"?"error":"idle",permissions:l.permissions.filter(d=>d.childSessionId)};return e.stopReason&&e.stopReason!=="end_turn"?jt(u,{kind:"turn-end",id:`turn-end-${r}`,stopReason:e.stopReason,ts:s}):u}case"ls_status":return{...n,state:e.state,turnActive:e.turnActive??n.turnActive};case"ls_permission":return n.permissions.some(l=>l.requestId===e.requestId)?n:{...Du(n,s),state:"waiting",permissions:[...n.permissions,{requestId:e.requestId,childSessionId:e.childSessionId,toolCallId:e.toolCallId,title:e.title,detail:e.detail,tool:e.tool,url:e.url,options:e.options,questions:e.questions,ts:s}]};case"ls_permission_resolved":{const l=n.permissions.find(p=>p.requestId===e.requestId);if(!l)return n;const u=l.options.find(p=>p.optionId===e.optionId),d=n.permissions.filter(p=>p.requestId!==e.requestId),m={...n,permissions:d,state:d.length>0?"waiting":n.turnActive?"running":n.state==="waiting"?"idle":n.state};return jt(m,{kind:"permission-result",id:`perm-${e.requestId}`,title:l.title,detail:l.detail,optionName:u?.name,allowed:u?u.kind.startsWith("allow"):void 0,asked:l.questions?!0:void 0,answers:l.questions&&e.answers?DR(l.questions,e.answers):void 0,ts:s})}case"ls_driver":{if(n.driver===e.driver)return n;const l={...n,driver:e.driver};return n.driver===void 0?l:jt(l,{kind:"driver",id:`driver-${r}`,driver:e.driver,ts:s})}case"ls_error":return jt(Du(n,s),{kind:"error",id:`error-${r}`,code:e.code,message:e.message,hint:e.hint,ts:s});case"ls_notice":return jt(n,{kind:"notice",id:`notice-${r}`,level:e.level,title:e.title,detail:e.detail,ts:s});default:return n}}function kp(n){const e=[];for(const s of n){const r=e[e.length-1];s.type==="text"&&r?.type==="text"?e[e.length-1]={type:"text",text:r.text+s.text}:e.push(s)}return e}function MR(n,e){if(e.seq<=n.lastSeq)return n;const s=Ng(n,e.update,e.ts,String(e.seq));return s===n?{...n,lastSeq:e.seq}:{...s,lastSeq:e.seq}}function Dm(n,e){return e.reduce(MR,n)}function zR(n,e){if(n.lastSeq===0)return{...n,startSeq:e};if(n.lastSeq===e)return n;const s=n.items.filter(o=>o.kind==="user"&&(o.pending||o.failed)),r={};return s.forEach((o,l)=>{r[o.id]=l}),{...to(n.sessionId),startSeq:e,items:s,index:r}}const IR=new Set(["Tool","Sub-agent"]);function LR(n,e){if(n.kind==="agent"&&e.kind==="agent"){const s=[...n.attachments??[],...e.attachments??[]];return{...e,text:n.text+e.text,attachments:s.length?s:void 0,ts:n.ts}}if(n.kind==="thought"&&e.kind==="thought")return{...e,text:n.text+e.text,ts:n.ts};if(n.kind==="user"&&e.kind==="user"){const s=kp([...n.blocks,...e.blocks]);return{...e,blocks:s,agentMessages:dp(s),ts:n.ts}}return n.kind==="tool"&&e.kind==="tool"?{...e,title:IR.has(e.title)?n.title:e.title,toolKind:n.toolKind,rawInput:e.rawInput??n.rawInput,rawOutput:e.rawOutput??n.rawOutput,locations:e.locations??n.locations,detail:e.detail??n.detail,content:e.content.length?pE(n.content,e.content):n.content,output:n.output+e.output,sub:n.sub&&e.sub?mE(n.sub,e.sub):e.sub??n.sub,ts:n.ts,endedTs:e.endedTs??n.endedTs}:e}function mE(n,e){const s=[],r=new Set;for(const l of n.items){const u=e.index[l.id];u===void 0?s.push(l):(s.push(LR(l,e.items[u])),r.add(l.id))}for(const l of e.items)r.has(l.id)||s.push(l);const o={};return s.forEach((l,u)=>{o[l.id]=u}),{...e,items:s,index:o}}function UR(n,e,s){let r=to(n.sessionId);for(const o of e)r=Ng(r,o.update,o.ts,String(o.seq));return r=ud(r,e[e.length-1]?.ts??0),{...mE(r,n),startSeq:s}}function Eu(n,e,s,r=Date.now(),o=!1){return jt(n,{kind:"user",id:`local-${e}`,blocks:s,ts:r,pending:!0,...o?{accepted:!0}:{}})}function w1(n,e){const s=_n(n,`local-${e}`,"user");return s&&s.pending?jt(n,{...s,pending:!1,failed:!0}):n}function Np(n,e){const s=n.index[e];if(s===void 0)return n;const r=n.items.filter((l,u)=>u!==s),o={};return r.forEach((l,u)=>{o[l.id]=u}),{...n,items:r,index:o}}function pE(n,e){if(e.some(r=>r.type==="diff"))return e;const s=n.filter(r=>r.type==="diff");return s.length?[...s,...e]:e}const BR=1;function HR(n){const e=globalThis.WebSocket;if(!e)throw new Error("No WebSocket implementation available");return new e(n)}class $R{constructor(e){this.options=e}socket;peer;statusValue="idle";attempt=0;reconnectTimer;heartbeatTimer;subscriptions=new Map;waiters=new Set;statusListeners=new Set;eventListeners=new Set;summaryListeners=new Set;onlineListeners=new Set;restoredListeners=new Set;notificationListeners=new Map;lastError;get status(){return this.statusValue}onStatus(e){return this.statusListeners.add(e),()=>this.statusListeners.delete(e)}onEvent(e){return this.eventListeners.add(e),()=>this.eventListeners.delete(e)}onSummary(e){return this.summaryListeners.add(e),()=>this.summaryListeners.delete(e)}on(e,s){let r=this.notificationListeners.get(e);r||this.notificationListeners.set(e,r=new Set);const o=s;return r.add(o),()=>r.delete(o)}onOnline(e){return this.onlineListeners.add(e),()=>this.onlineListeners.delete(e)}start(){this.statusValue==="connecting"||this.statusValue==="online"||this.open()}stop(){this.setStatus("stopped"),this.reconnectTimer&&clearTimeout(this.reconnectTimer),this.heartbeatTimer&&clearInterval(this.heartbeatTimer),this.peer?.close("stopped"),this.socket?.close(),this.socket=void 0;for(const e of this.waiters)e()}reconnectNow(){this.statusValue!=="stopped"&&this.statusValue!=="online"&&(this.reconnectTimer&&clearTimeout(this.reconnectTimer),this.reconnectTimer=void 0,this.attempt=0,this.open())}async call(e,s,r){const o=r??this.options.requestTimeoutMs??3e4,l=Date.now()+o;if(await this.waitOnline(o>0?o:this.options.requestTimeoutMs||3e4),!this.peer||this.statusValue!=="online")throw da.app("offline","Not connected to the computer",{code:"offline"});return this.peer.request(e,s,o===0?0:Math.max(1e3,l-Date.now()))}onRestored(e){return this.restoredListeners.add(e),()=>this.restoredListeners.delete(e)}subscribe(e,s){return this.subscriptions.set(e,{cursor:s}),this.statusValue!=="online"?Promise.resolve(void 0):this.sendSubscribe(e).then(r=>r?.session)}unsubscribe(e){this.subscriptions.delete(e)&&this.statusValue==="online"&&this.peer?.request("sessions.unsubscribe",{sessionId:e}).catch(()=>{})}setStatus(e,s){if(s!==void 0&&(this.lastError=s),this.statusValue!==e){this.statusValue=e;for(const r of this.statusListeners)r(e,s)}}waitOnline(e){return this.statusValue==="online"||this.statusValue==="stopped"?Promise.resolve():new Promise(s=>{const r=()=>{clearTimeout(o),this.waiters.delete(r),s()},o=setTimeout(r,e);this.waiters.add(r)})}open(){this.setStatus(this.attempt===0?"connecting":"reconnecting");let e;try{e=(this.options.createSocket??HR)(this.options.url)}catch(o){this.scheduleReconnect(o instanceof Error?o.message:String(o));return}this.socket=e;const s=new BO({send:o=>{e.readyState===BR&&e.send(o)},onNotification:(o,l)=>this.onNotification(o,l),requestTimeoutMs:this.options.requestTimeoutMs??3e4});this.peer=s,e.onmessage=o=>{const l=o.data;s.receive(typeof l=="string"?l:String(l))};let r;e.onopen=()=>void this.onOpen(e),e.onerror=o=>{const l=o?.message;typeof l=="string"&&l&&(r=l)},e.onclose=()=>{this.socket===e&&(s.close("connection closed"),this.socket=void 0,this.heartbeatTimer&&clearInterval(this.heartbeatTimer),this.statusValue!=="stopped"&&this.scheduleReconnect(r??"连接已断开"))}}async onOpen(e){if(this.socket!==e)return;this.attempt=0,this.setStatus("online",""),await Promise.all([...this.subscriptions.keys()].map(r=>this.sendSubscribe(r).then(o=>{if(o?.session)for(const l of this.restoredListeners)l(o.session)})));for(const r of[...this.waiters])r();for(const r of this.onlineListeners)r();const s=this.options.heartbeatMs??25e3;s>0&&(this.heartbeatTimer&&clearInterval(this.heartbeatTimer),this.heartbeatTimer=setInterval(()=>{this.socket!==e||this.statusValue!=="online"||this.peer?.request("machine.info",{},1e4).catch(()=>{this.socket===e&&e.close()})},s))}sendSubscribe(e){const s=this.subscriptions.get(e);return!s||!this.peer?Promise.resolve(void 0):this.peer.request("sessions.subscribe",{sessionId:e,fromSeq:s.cursor(),lazyImages:this.options.lazyImages}).catch(()=>{})}scheduleReconnect(e){if(this.statusValue==="stopped")return;this.setStatus("reconnecting",e);const s=this.options.minBackoffMs??500,r=this.options.maxBackoffMs??15e3,o=Math.min(r,s*2**this.attempt)*(.8+Math.random()*.4);this.attempt+=1,this.reconnectTimer&&clearTimeout(this.reconnectTimer),this.reconnectTimer=setTimeout(()=>{this.reconnectTimer=void 0,this.open()},o)}onNotification(e,s){if(e==="session.event")for(const r of this.eventListeners)r(s);else if(e==="session.summary"){const r=s.session;if(r)for(const o of this.summaryListeners)o(r)}for(const r of this.notificationListeners.get(e)??[])r(s)}}function gE(n,e){return e.reduce((s,r)=>{const o=s[r.id];return o&&(o.lastSeq??0)>=(r.lastSeq??0)?s:{...s,[r.id]:r}},n)}function VR(n,e){return e.update.sessionUpdate==="ls_task"?gE(n,[{...e.update.task,lastSeq:e.seq}]):n}function Op(n,e){const s=n[e.toolCallId];return s&&s.lastSeq>=e.lastSeq?n:{...n,[e.toolCallId]:{...e,startedAt:e.workflow.startedAt??s?.startedAt??e.startedAt,workflow:{...s?.workflow,...e.workflow}}}}function qR(n,e){const s=e.update;if(s.sessionUpdate!=="tool_call"&&s.sessionUpdate!=="tool_call_update")return n;const r=n[s.toolCallId],o=s.detail?.type==="subagent"?s.detail:void 0;return o?.workflow?Op(n,{toolCallId:s.toolCallId,task:o.task??r?.task??s.title??"工作流",startedAt:r?.startedAt??e.ts,lastSeq:e.seq,workflow:o.workflow}):r&&!r.workflow.state&&s.status==="failed"?Op(n,{...r,lastSeq:e.seq,workflow:{...r.workflow,state:"failed",endedAt:e.ts}}):n}function PR(n,e){return e.reduce((s,r)=>r.workflow?Op(s,{toolCallId:r.toolCallId,task:r.task,startedAt:r.startedAt,lastSeq:r.lastSeq??0,workflow:r.workflow}):s,n)}function FR(n,e){const s=n??[];if(!e?.length)return s;const r=new Set(s.map(o=>o.clientMessageId));return[...s,...e.filter(o=>!r.has(o.clientMessageId))]}function Rp(n,e){return`${n}
|
|
154
|
+
`)){if(!s.trim())continue;let r;try{r=JSON.parse(s)}catch{continue}if(Array.isArray(r)){if(!r.length||r.length>128){this.write({jsonrpc:"2.0",id:null,error:{code:-32600,message:"invalid JSON-RPC batch"}});continue}const o=[];Promise.all(r.map(l=>Promise.resolve(this.dispatch(l,u=>{o.push(u)})))).then(()=>{o.length&&this.write(o)})}else this.dispatch(r)}}close(e="connection closed"){if(!this.closed){this.closed=!0;for(const[s,r]of this.pending)r.timer&&clearTimeout(r.timer),r.reject(new da(vl,`${e} (${r.method})`,{code:"closed"})),this.pending.delete(s)}}get isClosed(){return this.closed}hasPendingRequest(e){return this.pending.has(e)}dispatch(e,s=r=>this.write(r)){if(!e||typeof e!="object"||Array.isArray(e)){s({jsonrpc:"2.0",id:null,error:{code:-32600,message:"invalid JSON-RPC request"}});return}const r=e.id,o=typeof e.method=="string"?e.method:void 0;if(o===void 0){if(r===void 0)return;const u=this.pending.get(r);if(!u)return;this.pending.delete(r),u.timer&&clearTimeout(u.timer);const d=e.error;d?u.reject(new da(d.code,d.message,d.data)):u.resolve(e.result);return}if(r===void 0){this.options.onNotification?.(o,e.params);return}const l=this.options.onRequest;if(!l){s({jsonrpc:"2.0",id:r,error:{code:LO,message:`no handler for ${o}`}});return}return Promise.resolve().then(()=>l(o,e.params,r)).then(u=>{u!==UO&&s({jsonrpc:"2.0",id:r,result:u??{}})},u=>{const d=u instanceof da?u:new da(vl,u instanceof Error?u.message:String(u),{code:"internal"});s({jsonrpc:"2.0",id:r,error:d.toObject()})})}write(e){if(!this.closed)try{this.options.send(JSON.stringify(e))}catch{this.close("send failed")}}}/*! noble-ciphers - MIT License (c) 2023 Paul Miller (paulmillr.com) */function Sp(n){return n instanceof Uint8Array||ArrayBuffer.isView(n)&&n.constructor.name==="Uint8Array"&&"BYTES_PER_ELEMENT"in n&&n.BYTES_PER_ELEMENT===1}const td=n=>n?`"${n}" `:"";function Ep(n,e=""){if(typeof n!="boolean")throw new TypeError(td(e)+"expected boolean, got type="+typeof n);return n}function eo(n,e=""){if(typeof n!="number")throw new TypeError(td(e)+"expected number, got "+typeof n);if(!Number.isSafeInteger(n)||n<0)throw new RangeError(td(e)+"expected integer >= 0, got "+n);return n}function Pt(n,e,s=""){if(Sp(n)&&(e===void 0||n.length===e))return n;e!==void 0&&eo(e,"length");const r=Sp(n),o=e!==void 0?` of length ${e}`:"",l=r?`length=${n.length}`:`type=${typeof n}`,u=td(s)+"expected Uint8Array"+o+", got "+l;throw r?new RangeError(u):new TypeError(u)}const Fx=(n,e)=>{if(n===null||typeof n!="object"||Array.isArray(n))throw new TypeError(e==="object"?"expected valid options object":`"${e}" expected object, got type=${typeof n}`)};function Gx(n,e=!0){if(n.destroyed)throw new Error("hash was destroyed");if(e&&n.finished)throw new Error("digest() was already called")}function HO(n,e){Pt(n,void 0,"output");const s=e.outputLen;if(!(n.length>=s))throw new RangeError('"output" expected length >= '+s)}function Ya(n){return new Uint32Array(n.buffer,n.byteOffset,Math.floor(n.byteLength/4))}function va(...n){for(let e=0;e<n.length;e++)n[e].fill(0)}function $O(n){return new DataView(n.buffer,n.byteOffset,n.byteLength)}const ma=new Uint8Array(new Uint32Array([287454020]).buffer)[0]===68;function VO(n){return n<<24&4278190080|n<<8&16711680|n>>>8&65280|n>>>24&255}function qO(n){for(let e=0;e<n.length;e++)n[e]=VO(n[e]);return n}const Xn=ma?n=>n:qO;function PO(n,e){return!n.byteLength||!e.byteLength?!1:n.buffer===e.buffer&&n.byteOffset<e.byteOffset+e.byteLength&&e.byteOffset<n.byteOffset+n.byteLength}function FO(n,e){if(PO(n,e)&&n.byteOffset<e.byteOffset)throw new Error("complex overlap of input and output is not supported")}function GO(n,e){return Fx(n,"defaults"),Fx(e,"opts"),Object.assign(n,e)}function ZO(n,e){if(n=Pt(n),e=Pt(e),n.length!==e.length)return!1;let s=0;for(let r=0;r<n.length;r++)s|=n[r]^e[r];return s===0}function YO(n,e,s){const r=e,o=(()=>[]),l=(d,m)=>r(m,...o(d)).update(d).digest(),u=r(new Uint8Array(n),...o(new Uint8Array(0)));return l.outputLen=u.outputLen,l.blockLen=u.blockLen,l.create=(d,...m)=>r(d,...m),l}const KO=(n,e)=>{function s(r,...o){if(Pt(r,void 0,"key"),n.nonceLength!==void 0){const v=o[0];Pt(v,n.varSizeNonce?void 0:n.nonceLength,"nonce")}const l=n.tagLength,u=n.nonceLength!==void 0?1:0;if(!n.withAAD){for(let v=u;v<o.length;v++)if(Sp(o[v]))throw new Error("AAD not supported")}n.withAAD&&o[u]!==void 0&&Pt(o[u],void 0,"AAD");const d=e(r,...o),m=(v,b)=>{if(b!==void 0){if(v!==2)throw new Error("cipher output not supported");Pt(b,void 0,"output")}};let p=!1;return{encrypt(v,b){if(p)throw new Error("cannot encrypt() twice with same key + nonce");return p=!0,Pt(v,void 0,"data"),m(d.encrypt.length,b),d.encrypt(v,b)},decrypt(v,b){if(Pt(v,void 0,"data"),l&&v.length<l)throw new Error('"ciphertext" expected length >= tagLength='+l);return m(d.decrypt.length,b),d.decrypt(v,b)}}}return Object.assign(s,n),s};function Cp(n,e,s=!0){if(e===void 0)return new Uint8Array(n);if(Pt(e,n,"output"),s&&!nd(e))throw new Error("invalid output, must be aligned");return e}function XO(n,e,s){eo(n),eo(e),Ep(s);const r=new Uint8Array(16),o=$O(r);return o.setBigUint64(0,BigInt(e),s),o.setBigUint64(8,BigInt(n),s),r}function nd(n){return n.byteOffset%4===0}function ad(n){return Uint8Array.from(Pt(n))}const M2=n=>Uint8Array.from(n.split(""),e=>e.charCodeAt(0)),QO=Xn(Ya(M2("expand 16-byte k"))),WO=Xn(Ya(M2("expand 32-byte k")));function st(n,e){return n<<e|n>>>32-e}const dl=64,JO=16,_p=2**32-1,Zx=Uint32Array.of();function e5(n,e,s,r,o,l,u,d){const m=o.length,p=new Uint8Array(dl),y=Ya(p),v=ma&&nd(o)&&nd(l),b=v?Ya(o):Zx,C=v?Ya(l):Zx;if(!ma){for(let T=0;T<m;u++){if(n(e,s,r,y,u,d),Xn(y),u>=_p)throw new Error("arx: counter overflow");const S=Math.min(dl,m-T);for(let E=0,_;E<S;E++)_=T+E,l[_]=o[_]^p[E];T+=S}return}for(let T=0;T<m;u++){if(n(e,s,r,y,u,d),u>=_p)throw new Error("arx: counter overflow");const S=Math.min(dl,m-T);if(v&&S===dl){const E=T/4;if(T%4!==0)throw new Error("arx: invalid block position");for(let _=0,j;_<JO;_++)j=E+_,C[j]=b[j]^y[_];T+=dl;continue}for(let E=0,_;E<S;E++)_=T+E,l[_]=o[_]^p[E];T+=S}}function t5(n,e){const{allowShortKeys:s,extendNonceFn:r,counterLength:o,counterRight:l,rounds:u}=GO({allowShortKeys:!1,counterLength:8,counterRight:!1,rounds:20},e);if(typeof n!="function")throw new Error("core must be a function");return eo(o),eo(u),Ep(l),Ep(s),(d,m,p,y,v=0)=>{Pt(d,void 0,"key"),Pt(m,void 0,"nonce"),Pt(p,void 0,"data");const b=p.length,C=y!==void 0;if(y=Cp(b,y,!1),C&&FO(p,y),eo(v),v<0||v>=_p)throw new Error("arx: counter overflow");const T=[];let S=d.length,E,_;if(S===32)T.push(E=ad(d)),_=WO;else if(S===16&&s)E=new Uint8Array(32),E.set(d),E.set(d,16),_=QO,T.push(E);else throw Pt(d,32,"arx key"),new Error("invalid key size");(!ma||!nd(m))&&T.push(m=ad(m));let j=Ya(E);if(r){if(m.length!==24)throw new Error("arx: extended nonce must be 24 bytes");const k=m.subarray(0,16);if(ma)r(_,j,Ya(k),j);else{const O=Xn(Uint32Array.from(_));r(O,j,Ya(k),j),va(O),Xn(j)}m=m.subarray(16)}else ma||Xn(j);const N=16-o;if(N!==m.length)throw new Error(`arx: nonce must be ${N} or 16 bytes`);if(N!==12){const k=new Uint8Array(12);k.set(m,l?0:12-m.length),m=k,T.push(m)}const z=Xn(Ya(m));try{return e5(n,_,j,z,p,y,v,u),y}finally{va(...T)}}}function Xt(n,e){return n[e++]&255|(n[e++]&255)<<8}class n5{blockLen=16;outputLen=16;buffer=new Uint8Array(16);r=new Uint16Array(10);h=new Uint16Array(10);pad=new Uint16Array(8);pos=0;finished=!1;destroyed=!1;constructor(e){e=ad(Pt(e,32,"key"));const s=Xt(e,0),r=Xt(e,2),o=Xt(e,4),l=Xt(e,6),u=Xt(e,8),d=Xt(e,10),m=Xt(e,12),p=Xt(e,14);this.r[0]=s&8191,this.r[1]=(s>>>13|r<<3)&8191,this.r[2]=(r>>>10|o<<6)&7939,this.r[3]=(o>>>7|l<<9)&8191,this.r[4]=(l>>>4|u<<12)&255,this.r[5]=u>>>1&8190,this.r[6]=(u>>>14|d<<2)&8191,this.r[7]=(d>>>11|m<<5)&8065,this.r[8]=(m>>>8|p<<8)&8191,this.r[9]=p>>>5&127;for(let y=0;y<8;y++)this.pad[y]=Xt(e,16+2*y)}process(e,s,r=!1){const o=r?0:2048,{h:l,r:u}=this,d=u[0],m=u[1],p=u[2],y=u[3],v=u[4],b=u[5],C=u[6],T=u[7],S=u[8],E=u[9],_=Xt(e,s+0),j=Xt(e,s+2),N=Xt(e,s+4),z=Xt(e,s+6),k=Xt(e,s+8),O=Xt(e,s+10),M=Xt(e,s+12),R=Xt(e,s+14);let L=l[0]+(_&8191),H=l[1]+((_>>>13|j<<3)&8191),V=l[2]+((j>>>10|N<<6)&8191),q=l[3]+((N>>>7|z<<9)&8191),P=l[4]+((z>>>4|k<<12)&8191),J=l[5]+(k>>>1&8191),ie=l[6]+((k>>>14|O<<2)&8191),U=l[7]+((O>>>11|M<<5)&8191),G=l[8]+((M>>>8|R<<8)&8191),W=l[9]+(R>>>5|o),te=0,X=te+L*d+H*(5*E)+V*(5*S)+q*(5*T)+P*(5*C);te=X>>>13,X&=8191,X+=J*(5*b)+ie*(5*v)+U*(5*y)+G*(5*p)+W*(5*m),te+=X>>>13,X&=8191;let ge=te+L*m+H*d+V*(5*E)+q*(5*S)+P*(5*T);te=ge>>>13,ge&=8191,ge+=J*(5*C)+ie*(5*b)+U*(5*v)+G*(5*y)+W*(5*p),te+=ge>>>13,ge&=8191;let Z=te+L*p+H*m+V*d+q*(5*E)+P*(5*S);te=Z>>>13,Z&=8191,Z+=J*(5*T)+ie*(5*C)+U*(5*b)+G*(5*v)+W*(5*y),te+=Z>>>13,Z&=8191;let ee=te+L*y+H*p+V*m+q*d+P*(5*E);te=ee>>>13,ee&=8191,ee+=J*(5*S)+ie*(5*T)+U*(5*C)+G*(5*b)+W*(5*v),te+=ee>>>13,ee&=8191;let fe=te+L*v+H*y+V*p+q*m+P*d;te=fe>>>13,fe&=8191,fe+=J*(5*E)+ie*(5*S)+U*(5*T)+G*(5*C)+W*(5*b),te+=fe>>>13,fe&=8191;let ue=te+L*b+H*v+V*y+q*p+P*m;te=ue>>>13,ue&=8191,ue+=J*d+ie*(5*E)+U*(5*S)+G*(5*T)+W*(5*C),te+=ue>>>13,ue&=8191;let oe=te+L*C+H*b+V*v+q*y+P*p;te=oe>>>13,oe&=8191,oe+=J*m+ie*d+U*(5*E)+G*(5*S)+W*(5*T),te+=oe>>>13,oe&=8191;let Ce=te+L*T+H*C+V*b+q*v+P*y;te=Ce>>>13,Ce&=8191,Ce+=J*p+ie*m+U*d+G*(5*E)+W*(5*S),te+=Ce>>>13,Ce&=8191;let me=te+L*S+H*T+V*C+q*b+P*v;te=me>>>13,me&=8191,me+=J*y+ie*p+U*m+G*d+W*(5*E),te+=me>>>13,me&=8191;let he=te+L*E+H*S+V*T+q*C+P*b;te=he>>>13,he&=8191,he+=J*v+ie*y+U*p+G*m+W*d,te+=he>>>13,he&=8191,te=(te<<2)+te|0,te=te+X|0,X=te&8191,te=te>>>13,ge+=te,l[0]=X,l[1]=ge,l[2]=Z,l[3]=ee,l[4]=fe,l[5]=ue,l[6]=oe,l[7]=Ce,l[8]=me,l[9]=he}finalize(){const{h:e,pad:s}=this,r=new Uint16Array(10);let o=e[1]>>>13;e[1]&=8191;for(let d=2;d<10;d++)e[d]+=o,o=e[d]>>>13,e[d]&=8191;e[0]+=o*5,o=e[0]>>>13,e[0]&=8191,e[1]+=o,o=e[1]>>>13,e[1]&=8191,e[2]+=o,r[0]=e[0]+5,o=r[0]>>>13,r[0]&=8191;for(let d=1;d<10;d++)r[d]=e[d]+o,o=r[d]>>>13,r[d]&=8191;r[9]-=8192;let l=(o^1)-1;for(let d=0;d<10;d++)r[d]&=l;l=~l;for(let d=0;d<10;d++)e[d]=e[d]&l|r[d];e[0]=(e[0]|e[1]<<13)&65535,e[1]=(e[1]>>>3|e[2]<<10)&65535,e[2]=(e[2]>>>6|e[3]<<7)&65535,e[3]=(e[3]>>>9|e[4]<<4)&65535,e[4]=(e[4]>>>12|e[5]<<1|e[6]<<14)&65535,e[5]=(e[6]>>>2|e[7]<<11)&65535,e[6]=(e[7]>>>5|e[8]<<8)&65535,e[7]=(e[8]>>>8|e[9]<<5)&65535;let u=e[0]+s[0];e[0]=u&65535;for(let d=1;d<8;d++)u=(e[d]+s[d]|0)+(u>>>16)|0,e[d]=u&65535;va(r)}update(e){Gx(this),Pt(e),e=ad(e);const{buffer:s,blockLen:r}=this,o=e.length;for(let l=0;l<o;){const u=Math.min(r-this.pos,o-l);if(u===r){for(;r<=o-l;l+=r)this.process(e,l);continue}s.set(e.subarray(l,l+u),this.pos),this.pos+=u,l+=u,this.pos===r&&(this.process(s,0,!1),this.pos=0)}return this}destroy(){this.destroyed=!0,va(this.h,this.r,this.buffer,this.pad)}digestInto(e){Gx(this),HO(e,this),this.finished=!0;const{buffer:s,h:r}=this;let{pos:o}=this;if(o){for(s[o++]=1;o<16;o++)s[o]=0;this.process(s,0,!0)}this.finalize();let l=0;for(let u=0;u<8;u++)e[l++]=r[u]>>>0,e[l++]=r[u]>>>8}digest(){const{buffer:e,outputLen:s}=this;this.digestInto(e);const r=e.slice(0,s);return this.destroy(),r}}const a5=YO(32,n=>new n5(n));function z2(n,e,s,r,o,l=20){let u=n[0],d=n[1],m=n[2],p=n[3],y=e[0],v=e[1],b=e[2],C=e[3],T=e[4],S=e[5],E=e[6],_=e[7],j=o,N=s[0],z=s[1],k=s[2],O=u,M=d,R=m,L=p,H=y,V=v,q=b,P=C,J=T,ie=S,U=E,G=_,W=j,te=N,X=z,ge=k;for(let ee=0;ee<l;ee+=2)O=O+H|0,W=st(W^O,16),J=J+W|0,H=st(H^J,12),O=O+H|0,W=st(W^O,8),J=J+W|0,H=st(H^J,7),M=M+V|0,te=st(te^M,16),ie=ie+te|0,V=st(V^ie,12),M=M+V|0,te=st(te^M,8),ie=ie+te|0,V=st(V^ie,7),R=R+q|0,X=st(X^R,16),U=U+X|0,q=st(q^U,12),R=R+q|0,X=st(X^R,8),U=U+X|0,q=st(q^U,7),L=L+P|0,ge=st(ge^L,16),G=G+ge|0,P=st(P^G,12),L=L+P|0,ge=st(ge^L,8),G=G+ge|0,P=st(P^G,7),O=O+V|0,ge=st(ge^O,16),U=U+ge|0,V=st(V^U,12),O=O+V|0,ge=st(ge^O,8),U=U+ge|0,V=st(V^U,7),M=M+q|0,W=st(W^M,16),G=G+W|0,q=st(q^G,12),M=M+q|0,W=st(W^M,8),G=G+W|0,q=st(q^G,7),R=R+P|0,te=st(te^R,16),J=J+te|0,P=st(P^J,12),R=R+P|0,te=st(te^R,8),J=J+te|0,P=st(P^J,7),L=L+H|0,X=st(X^L,16),ie=ie+X|0,H=st(H^ie,12),L=L+H|0,X=st(X^L,8),ie=ie+X|0,H=st(H^ie,7);let Z=0;r[Z++]=u+O|0,r[Z++]=d+M|0,r[Z++]=m+R|0,r[Z++]=p+L|0,r[Z++]=y+H|0,r[Z++]=v+V|0,r[Z++]=b+q|0,r[Z++]=C+P|0,r[Z++]=T+J|0,r[Z++]=S+ie|0,r[Z++]=E+U|0,r[Z++]=_+G|0,r[Z++]=j+W|0,r[Z++]=N+te|0,r[Z++]=z+X|0,r[Z++]=k+ge|0}function s5(n,e,s,r){const o=ma?n:Xn(n.slice(0,4)),l=ma?e:Xn(e.slice(0,8)),u=ma?s:Xn(s.slice(0,4)),d=new Uint32Array(16);z2(o,l,u.subarray(1),d,u[0]);let m=0;r[m++]=d[0]-o[0]|0,r[m++]=d[1]-o[1]|0,r[m++]=d[2]-o[2]|0,r[m++]=d[3]-o[3]|0,r[m++]=d[12]-u[0]|0,r[m++]=d[13]-u[1]|0,r[m++]=d[14]-u[2]|0,r[m++]=d[15]-u[3]|0,Xn(r),ma||va(o,l,u),va(d)}const r5=t5(z2,{counterRight:!1,counterLength:8,extendNonceFn:s5,allowShortKeys:!1}),i5=new Uint8Array(16),Yx=(n,e)=>{n.update(e);const s=e.length%16;s&&n.update(i5.subarray(s))},o5=new Uint8Array(32);function Kx(n,e,s,r,o){o!==void 0&&Pt(o,void 0,"AAD");const l=n(e,s,o5),u=XO(r.length,o?o.length:0,!0),d=a5.create(l);o&&Yx(d,o),Yx(d,r),d.update(u);const m=d.digest();return va(l,u),m}const l5=n=>(e,s,r)=>({encrypt(l,u){const d=l.length;u=Cp(d+16,u,!1),u.set(l);const m=u.subarray(0,-16);n(e,s,m,m,1);const p=Kx(n,e,s,m,r);return u.set(p,d),va(p),u},decrypt(l,u){u=Cp(l.length-16,u,!1);const d=l.subarray(0,-16),m=l.subarray(-16),p=Kx(n,e,s,d,r);if(!ZO(m,p))throw va(p),new Error("invalid tag");return u.set(l.subarray(0,-16)),n(e,s,u,u,1),va(p),u}}),Xx=KO({blockSize:64,nonceLength:24,tagLength:16,withAAD:!0},l5(r5)),qi=typeof globalThis=="object"&&"crypto"in globalThis?globalThis.crypto:void 0;/*! noble-hashes - MIT License (c) 2022 Paul Miller (paulmillr.com) */function zd(n){return n instanceof Uint8Array||ArrayBuffer.isView(n)&&n.constructor.name==="Uint8Array"}function sd(n){if(!Number.isSafeInteger(n)||n<0)throw new Error("positive integer expected, got "+n)}function nr(n,...e){if(!zd(n))throw new Error("Uint8Array expected");if(e.length>0&&!e.includes(n.length))throw new Error("Uint8Array expected of length "+e+", got length="+n.length)}function Sg(n){if(typeof n!="function"||typeof n.create!="function")throw new Error("Hash should be wrapped by utils.createHasher");sd(n.outputLen),sd(n.blockLen)}function rd(n,e=!0){if(n.destroyed)throw new Error("Hash instance has been destroyed");if(e&&n.finished)throw new Error("Hash#digest() has already been called")}function c5(n,e){nr(n);const s=e.outputLen;if(n.length<s)throw new Error("digestInto() expects output buffer of length at least "+s)}function Br(...n){for(let e=0;e<n.length;e++)n[e].fill(0)}function _m(n){return new DataView(n.buffer,n.byteOffset,n.byteLength)}function ca(n,e){return n<<32-e|n>>>e}const I2=typeof Uint8Array.from([]).toHex=="function"&&typeof Uint8Array.fromHex=="function",u5=Array.from({length:256},(n,e)=>e.toString(16).padStart(2,"0"));function Eg(n){if(nr(n),I2)return n.toHex();let e="";for(let s=0;s<n.length;s++)e+=u5[n[s]];return e}const qa={_0:48,_9:57,A:65,F:70,a:97,f:102};function Qx(n){if(n>=qa._0&&n<=qa._9)return n-qa._0;if(n>=qa.A&&n<=qa.F)return n-(qa.A-10);if(n>=qa.a&&n<=qa.f)return n-(qa.a-10)}function L2(n){if(typeof n!="string")throw new Error("hex string expected, got "+typeof n);if(I2)return Uint8Array.fromHex(n);const e=n.length,s=e/2;if(e%2)throw new Error("hex string expected, got unpadded hex of length "+e);const r=new Uint8Array(s);for(let o=0,l=0;o<s;o++,l+=2){const u=Qx(n.charCodeAt(l)),d=Qx(n.charCodeAt(l+1));if(u===void 0||d===void 0){const m=n[l]+n[l+1];throw new Error('hex string expected, got non-hex character "'+m+'" at index '+l)}r[o]=u*16+d}return r}function d5(n){if(typeof n!="string")throw new Error("string expected");return new Uint8Array(new TextEncoder().encode(n))}function Nl(n){return typeof n=="string"&&(n=d5(n)),nr(n),n}function Wx(...n){let e=0;for(let r=0;r<n.length;r++){const o=n[r];nr(o),e+=o.length}const s=new Uint8Array(e);for(let r=0,o=0;r<n.length;r++){const l=n[r];s.set(l,o),o+=l.length}return s}class U2{}function B2(n){const e=r=>n().update(Nl(r)).digest(),s=n();return e.outputLen=s.outputLen,e.blockLen=s.blockLen,e.create=()=>n(),e}function H2(n=32){if(qi&&typeof qi.getRandomValues=="function")return qi.getRandomValues(new Uint8Array(n));if(qi&&typeof qi.randomBytes=="function")return Uint8Array.from(qi.randomBytes(n));throw new Error("crypto.getRandomValues must be defined")}function f5(n,e,s,r){if(typeof n.setBigUint64=="function")return n.setBigUint64(e,s,r);const o=BigInt(32),l=BigInt(4294967295),u=Number(s>>o&l),d=Number(s&l),m=r?4:0,p=r?0:4;n.setUint32(e+m,u,r),n.setUint32(e+p,d,r)}function h5(n,e,s){return n&e^~n&s}function m5(n,e,s){return n&e^n&s^e&s}class $2 extends U2{constructor(e,s,r,o){super(),this.finished=!1,this.length=0,this.pos=0,this.destroyed=!1,this.blockLen=e,this.outputLen=s,this.padOffset=r,this.isLE=o,this.buffer=new Uint8Array(e),this.view=_m(this.buffer)}update(e){rd(this),e=Nl(e),nr(e);const{view:s,buffer:r,blockLen:o}=this,l=e.length;for(let u=0;u<l;){const d=Math.min(o-this.pos,l-u);if(d===o){const m=_m(e);for(;o<=l-u;u+=o)this.process(m,u);continue}r.set(e.subarray(u,u+d),this.pos),this.pos+=d,u+=d,this.pos===o&&(this.process(s,0),this.pos=0)}return this.length+=e.length,this.roundClean(),this}digestInto(e){rd(this),c5(e,this),this.finished=!0;const{buffer:s,view:r,blockLen:o,isLE:l}=this;let{pos:u}=this;s[u++]=128,Br(this.buffer.subarray(u)),this.padOffset>o-u&&(this.process(r,0),u=0);for(let v=u;v<o;v++)s[v]=0;f5(r,o-8,BigInt(this.length*8),l),this.process(r,0);const d=_m(e),m=this.outputLen;if(m%4)throw new Error("_sha2: outputLen should be aligned to 32bit");const p=m/4,y=this.get();if(p>y.length)throw new Error("_sha2: outputLen bigger than state");for(let v=0;v<p;v++)d.setUint32(4*v,y[v],l)}digest(){const{buffer:e,outputLen:s}=this;this.digestInto(e);const r=e.slice(0,s);return this.destroy(),r}_cloneInto(e){e||(e=new this.constructor),e.set(...this.get());const{blockLen:s,buffer:r,length:o,finished:l,destroyed:u,pos:d}=this;return e.destroyed=u,e.finished=l,e.length=o,e.pos=d,o%s&&e.buffer.set(r),e}clone(){return this._cloneInto()}}const Rs=Uint32Array.from([1779033703,3144134277,1013904242,2773480762,1359893119,2600822924,528734635,1541459225]),en=Uint32Array.from([1779033703,4089235720,3144134277,2227873595,1013904242,4271175723,2773480762,1595750129,1359893119,2917565137,2600822924,725511199,528734635,4215389547,1541459225,327033209]),vu=BigInt(2**32-1),Jx=BigInt(32);function p5(n,e=!1){return e?{h:Number(n&vu),l:Number(n>>Jx&vu)}:{h:Number(n>>Jx&vu)|0,l:Number(n&vu)|0}}function g5(n,e=!1){const s=n.length;let r=new Uint32Array(s),o=new Uint32Array(s);for(let l=0;l<s;l++){const{h:u,l:d}=p5(n[l],e);[r[l],o[l]]=[u,d]}return[r,o]}const e1=(n,e,s)=>n>>>s,t1=(n,e,s)=>n<<32-s|e>>>s,Pi=(n,e,s)=>n>>>s|e<<32-s,Fi=(n,e,s)=>n<<32-s|e>>>s,yu=(n,e,s)=>n<<64-s|e>>>s-32,bu=(n,e,s)=>n>>>s-32|e<<64-s;function Pa(n,e,s,r){const o=(e>>>0)+(r>>>0);return{h:n+s+(o/2**32|0)|0,l:o|0}}const v5=(n,e,s)=>(n>>>0)+(e>>>0)+(s>>>0),y5=(n,e,s,r)=>e+s+r+(n/2**32|0)|0,b5=(n,e,s,r)=>(n>>>0)+(e>>>0)+(s>>>0)+(r>>>0),x5=(n,e,s,r,o)=>e+s+r+o+(n/2**32|0)|0,w5=(n,e,s,r,o)=>(n>>>0)+(e>>>0)+(s>>>0)+(r>>>0)+(o>>>0),S5=(n,e,s,r,o,l)=>e+s+r+o+l+(n/2**32|0)|0,E5=Uint32Array.from([1116352408,1899447441,3049323471,3921009573,961987163,1508970993,2453635748,2870763221,3624381080,310598401,607225278,1426881987,1925078388,2162078206,2614888103,3248222580,3835390401,4022224774,264347078,604807628,770255983,1249150122,1555081692,1996064986,2554220882,2821834349,2952996808,3210313671,3336571891,3584528711,113926993,338241895,666307205,773529912,1294757372,1396182291,1695183700,1986661051,2177026350,2456956037,2730485921,2820302411,3259730800,3345764771,3516065817,3600352804,4094571909,275423344,430227734,506948616,659060556,883997877,958139571,1322822218,1537002063,1747873779,1955562222,2024104815,2227730452,2361852424,2428436474,2756734187,3204031479,3329325298]),Ds=new Uint32Array(64);class C5 extends $2{constructor(e=32){super(64,e,8,!1),this.A=Rs[0]|0,this.B=Rs[1]|0,this.C=Rs[2]|0,this.D=Rs[3]|0,this.E=Rs[4]|0,this.F=Rs[5]|0,this.G=Rs[6]|0,this.H=Rs[7]|0}get(){const{A:e,B:s,C:r,D:o,E:l,F:u,G:d,H:m}=this;return[e,s,r,o,l,u,d,m]}set(e,s,r,o,l,u,d,m){this.A=e|0,this.B=s|0,this.C=r|0,this.D=o|0,this.E=l|0,this.F=u|0,this.G=d|0,this.H=m|0}process(e,s){for(let v=0;v<16;v++,s+=4)Ds[v]=e.getUint32(s,!1);for(let v=16;v<64;v++){const b=Ds[v-15],C=Ds[v-2],T=ca(b,7)^ca(b,18)^b>>>3,S=ca(C,17)^ca(C,19)^C>>>10;Ds[v]=S+Ds[v-7]+T+Ds[v-16]|0}let{A:r,B:o,C:l,D:u,E:d,F:m,G:p,H:y}=this;for(let v=0;v<64;v++){const b=ca(d,6)^ca(d,11)^ca(d,25),C=y+b+h5(d,m,p)+E5[v]+Ds[v]|0,S=(ca(r,2)^ca(r,13)^ca(r,22))+m5(r,o,l)|0;y=p,p=m,m=d,d=u+C|0,u=l,l=o,o=r,r=C+S|0}r=r+this.A|0,o=o+this.B|0,l=l+this.C|0,u=u+this.D|0,d=d+this.E|0,m=m+this.F|0,p=p+this.G|0,y=y+this.H|0,this.set(r,o,l,u,d,m,p,y)}roundClean(){Br(Ds)}destroy(){this.set(0,0,0,0,0,0,0,0),Br(this.buffer)}}const V2=g5(["0x428a2f98d728ae22","0x7137449123ef65cd","0xb5c0fbcfec4d3b2f","0xe9b5dba58189dbbc","0x3956c25bf348b538","0x59f111f1b605d019","0x923f82a4af194f9b","0xab1c5ed5da6d8118","0xd807aa98a3030242","0x12835b0145706fbe","0x243185be4ee4b28c","0x550c7dc3d5ffb4e2","0x72be5d74f27b896f","0x80deb1fe3b1696b1","0x9bdc06a725c71235","0xc19bf174cf692694","0xe49b69c19ef14ad2","0xefbe4786384f25e3","0x0fc19dc68b8cd5b5","0x240ca1cc77ac9c65","0x2de92c6f592b0275","0x4a7484aa6ea6e483","0x5cb0a9dcbd41fbd4","0x76f988da831153b5","0x983e5152ee66dfab","0xa831c66d2db43210","0xb00327c898fb213f","0xbf597fc7beef0ee4","0xc6e00bf33da88fc2","0xd5a79147930aa725","0x06ca6351e003826f","0x142929670a0e6e70","0x27b70a8546d22ffc","0x2e1b21385c26c926","0x4d2c6dfc5ac42aed","0x53380d139d95b3df","0x650a73548baf63de","0x766a0abb3c77b2a8","0x81c2c92e47edaee6","0x92722c851482353b","0xa2bfe8a14cf10364","0xa81a664bbc423001","0xc24b8b70d0f89791","0xc76c51a30654be30","0xd192e819d6ef5218","0xd69906245565a910","0xf40e35855771202a","0x106aa07032bbd1b8","0x19a4c116b8d2d0c8","0x1e376c085141ab53","0x2748774cdf8eeb99","0x34b0bcb5e19b48a8","0x391c0cb3c5c95a63","0x4ed8aa4ae3418acb","0x5b9cca4f7763e373","0x682e6ff3d6b2b8a3","0x748f82ee5defb2fc","0x78a5636f43172f60","0x84c87814a1f0ab72","0x8cc702081a6439ec","0x90befffa23631e28","0xa4506cebde82bde9","0xbef9a3f7b2c67915","0xc67178f2e372532b","0xca273eceea26619c","0xd186b8c721c0c207","0xeada7dd6cde0eb1e","0xf57d4f7fee6ed178","0x06f067aa72176fba","0x0a637dc5a2c898a6","0x113f9804bef90dae","0x1b710b35131c471b","0x28db77f523047d84","0x32caab7b40c72493","0x3c9ebe0a15c9bebc","0x431d67c49c100d4c","0x4cc5d4becb3e42b6","0x597f299cfc657e2a","0x5fcb6fab3ad6faec","0x6c44198c4a475817"].map(n=>BigInt(n))),_5=V2[0],j5=V2[1],Ms=new Uint32Array(80),zs=new Uint32Array(80);class A5 extends $2{constructor(e=64){super(128,e,16,!1),this.Ah=en[0]|0,this.Al=en[1]|0,this.Bh=en[2]|0,this.Bl=en[3]|0,this.Ch=en[4]|0,this.Cl=en[5]|0,this.Dh=en[6]|0,this.Dl=en[7]|0,this.Eh=en[8]|0,this.El=en[9]|0,this.Fh=en[10]|0,this.Fl=en[11]|0,this.Gh=en[12]|0,this.Gl=en[13]|0,this.Hh=en[14]|0,this.Hl=en[15]|0}get(){const{Ah:e,Al:s,Bh:r,Bl:o,Ch:l,Cl:u,Dh:d,Dl:m,Eh:p,El:y,Fh:v,Fl:b,Gh:C,Gl:T,Hh:S,Hl:E}=this;return[e,s,r,o,l,u,d,m,p,y,v,b,C,T,S,E]}set(e,s,r,o,l,u,d,m,p,y,v,b,C,T,S,E){this.Ah=e|0,this.Al=s|0,this.Bh=r|0,this.Bl=o|0,this.Ch=l|0,this.Cl=u|0,this.Dh=d|0,this.Dl=m|0,this.Eh=p|0,this.El=y|0,this.Fh=v|0,this.Fl=b|0,this.Gh=C|0,this.Gl=T|0,this.Hh=S|0,this.Hl=E|0}process(e,s){for(let N=0;N<16;N++,s+=4)Ms[N]=e.getUint32(s),zs[N]=e.getUint32(s+=4);for(let N=16;N<80;N++){const z=Ms[N-15]|0,k=zs[N-15]|0,O=Pi(z,k,1)^Pi(z,k,8)^e1(z,k,7),M=Fi(z,k,1)^Fi(z,k,8)^t1(z,k,7),R=Ms[N-2]|0,L=zs[N-2]|0,H=Pi(R,L,19)^yu(R,L,61)^e1(R,L,6),V=Fi(R,L,19)^bu(R,L,61)^t1(R,L,6),q=b5(M,V,zs[N-7],zs[N-16]),P=x5(q,O,H,Ms[N-7],Ms[N-16]);Ms[N]=P|0,zs[N]=q|0}let{Ah:r,Al:o,Bh:l,Bl:u,Ch:d,Cl:m,Dh:p,Dl:y,Eh:v,El:b,Fh:C,Fl:T,Gh:S,Gl:E,Hh:_,Hl:j}=this;for(let N=0;N<80;N++){const z=Pi(v,b,14)^Pi(v,b,18)^yu(v,b,41),k=Fi(v,b,14)^Fi(v,b,18)^bu(v,b,41),O=v&C^~v&S,M=b&T^~b&E,R=w5(j,k,M,j5[N],zs[N]),L=S5(R,_,z,O,_5[N],Ms[N]),H=R|0,V=Pi(r,o,28)^yu(r,o,34)^yu(r,o,39),q=Fi(r,o,28)^bu(r,o,34)^bu(r,o,39),P=r&l^r&d^l&d,J=o&u^o&m^u&m;_=S|0,j=E|0,S=C|0,E=T|0,C=v|0,T=b|0,{h:v,l:b}=Pa(p|0,y|0,L|0,H|0),p=d|0,y=m|0,d=l|0,m=u|0,l=r|0,u=o|0;const ie=v5(H,q,J);r=y5(ie,L,V,P),o=ie|0}({h:r,l:o}=Pa(this.Ah|0,this.Al|0,r|0,o|0)),{h:l,l:u}=Pa(this.Bh|0,this.Bl|0,l|0,u|0),{h:d,l:m}=Pa(this.Ch|0,this.Cl|0,d|0,m|0),{h:p,l:y}=Pa(this.Dh|0,this.Dl|0,p|0,y|0),{h:v,l:b}=Pa(this.Eh|0,this.El|0,v|0,b|0),{h:C,l:T}=Pa(this.Fh|0,this.Fl|0,C|0,T|0),{h:S,l:E}=Pa(this.Gh|0,this.Gl|0,S|0,E|0),{h:_,l:j}=Pa(this.Hh|0,this.Hl|0,_|0,j|0),this.set(r,o,l,u,d,m,p,y,v,b,C,T,S,E,_,j)}roundClean(){Br(Ms,zs)}destroy(){Br(this.buffer),this.set(0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0)}}const Ol=B2(()=>new C5),T5=B2(()=>new A5);/*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) */const Cg=BigInt(0),jp=BigInt(1);function Ap(n,e=""){if(typeof n!="boolean"){const s=e&&`"${e}"`;throw new Error(s+"expected boolean, got type="+typeof n)}return n}function Ru(n,e,s=""){const r=zd(n),o=n?.length,l=e!==void 0;if(!r||l&&o!==e){const u=s&&`"${s}" `,d=l?` of length ${e}`:"",m=r?`length=${o}`:`type=${typeof n}`;throw new Error(u+"expected Uint8Array"+d+", got "+m)}return n}function q2(n){if(typeof n!="string")throw new Error("hex string expected, got "+typeof n);return n===""?Cg:BigInt("0x"+n)}function k5(n){return q2(Eg(n))}function ro(n){return nr(n),q2(Eg(Uint8Array.from(n).reverse()))}function P2(n,e){return L2(n.toString(16).padStart(e*2,"0"))}function F2(n,e){return P2(n,e).reverse()}function ua(n,e,s){let r;if(typeof e=="string")try{r=L2(e)}catch(l){throw new Error(n+" must be hex string or Uint8Array, cause: "+l)}else if(zd(e))r=Uint8Array.from(e);else throw new Error(n+" must be hex string or Uint8Array");const o=r.length;if(typeof s=="number"&&o!==s)throw new Error(n+" of length "+s+" expected, got "+o);return r}function n1(n){return Uint8Array.from(n)}const jm=n=>typeof n=="bigint"&&Cg<=n;function N5(n,e,s){return jm(n)&&jm(e)&&jm(s)&&e<=n&&n<s}function id(n,e,s,r){if(!N5(e,s,r))throw new Error("expected valid "+n+": "+s+" <= n < "+r+", got "+e)}function O5(n){let e;for(e=0;n>Cg;n>>=jp,e+=1);return e}const _g=n=>(jp<<BigInt(n))-jp;function Id(n,e,s={}){if(!n||typeof n!="object")throw new Error("expected valid options object");function r(o,l,u){const d=n[o];if(u&&d===void 0)return;const m=typeof d;if(m!==l||d===null)throw new Error(`param "${o}" is invalid: expected ${l}, got ${m}`)}Object.entries(e).forEach(([o,l])=>r(o,l,!1)),Object.entries(s).forEach(([o,l])=>r(o,l,!0))}function a1(n){const e=new WeakMap;return(s,...r)=>{const o=e.get(s);if(o!==void 0)return o;const l=n(s,...r);return e.set(s,l),l}}/*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) */const fn=BigInt(0),nn=BigInt(1),Nr=BigInt(2),G2=BigInt(3),Z2=BigInt(4),Y2=BigInt(5),R5=BigInt(7),K2=BigInt(8),D5=BigInt(9),X2=BigInt(16);function At(n,e){const s=n%e;return s>=fn?s:e+s}function Yn(n,e,s){let r=n;for(;e-- >fn;)r*=r,r%=s;return r}function s1(n,e){if(n===fn)throw new Error("invert: expected non-zero number");if(e<=fn)throw new Error("invert: expected positive modulus, got "+e);let s=At(n,e),r=e,o=fn,l=nn;for(;s!==fn;){const d=r/s,m=r%s,p=o-l*d;r=s,s=m,o=l,l=p}if(r!==nn)throw new Error("invert: does not exist");return At(o,e)}function jg(n,e,s){if(!n.eql(n.sqr(e),s))throw new Error("Cannot find square root")}function Q2(n,e){const s=(n.ORDER+nn)/Z2,r=n.pow(e,s);return jg(n,r,e),r}function M5(n,e){const s=(n.ORDER-Y2)/K2,r=n.mul(e,Nr),o=n.pow(r,s),l=n.mul(e,o),u=n.mul(n.mul(l,Nr),o),d=n.mul(l,n.sub(u,n.ONE));return jg(n,d,e),d}function z5(n){const e=Hl(n),s=W2(n),r=s(e,e.neg(e.ONE)),o=s(e,r),l=s(e,e.neg(r)),u=(n+R5)/X2;return(d,m)=>{let p=d.pow(m,u),y=d.mul(p,r);const v=d.mul(p,o),b=d.mul(p,l),C=d.eql(d.sqr(y),m),T=d.eql(d.sqr(v),m);p=d.cmov(p,y,C),y=d.cmov(b,v,T);const S=d.eql(d.sqr(y),m),E=d.cmov(p,y,S);return jg(d,E,m),E}}function W2(n){if(n<G2)throw new Error("sqrt is not defined for small field");let e=n-nn,s=0;for(;e%Nr===fn;)e/=Nr,s++;let r=Nr;const o=Hl(n);for(;r1(o,r)===1;)if(r++>1e3)throw new Error("Cannot find square root: probably non-prime P");if(s===1)return Q2;let l=o.pow(r,e);const u=(e+nn)/Nr;return function(m,p){if(m.is0(p))return p;if(r1(m,p)!==1)throw new Error("Cannot find square root");let y=s,v=m.mul(m.ONE,l),b=m.pow(p,e),C=m.pow(p,u);for(;!m.eql(b,m.ONE);){if(m.is0(b))return m.ZERO;let T=1,S=m.sqr(b);for(;!m.eql(S,m.ONE);)if(T++,S=m.sqr(S),T===y)throw new Error("Cannot find square root");const E=nn<<BigInt(y-T-1),_=m.pow(v,E);y=T,v=m.sqr(_),b=m.mul(b,v),C=m.mul(C,_)}return C}}function I5(n){return n%Z2===G2?Q2:n%K2===Y2?M5:n%X2===D5?z5(n):W2(n)}const L5=(n,e)=>(At(n,e)&nn)===nn,U5=["create","isValid","is0","neg","inv","sqrt","sqr","eql","add","sub","mul","pow","div","addN","subN","mulN","sqrN"];function B5(n){const e={ORDER:"bigint",MASK:"bigint",BYTES:"number",BITS:"number"},s=U5.reduce((r,o)=>(r[o]="function",r),e);return Id(n,s),n}function H5(n,e,s){if(s<fn)throw new Error("invalid exponent, negatives unsupported");if(s===fn)return n.ONE;if(s===nn)return e;let r=n.ONE,o=e;for(;s>fn;)s&nn&&(r=n.mul(r,o)),o=n.sqr(o),s>>=nn;return r}function J2(n,e,s=!1){const r=new Array(e.length).fill(s?n.ZERO:void 0),o=e.reduce((u,d,m)=>n.is0(d)?u:(r[m]=u,n.mul(u,d)),n.ONE),l=n.inv(o);return e.reduceRight((u,d,m)=>n.is0(d)?u:(r[m]=n.mul(u,r[m]),n.mul(u,d)),l),r}function r1(n,e){const s=(n.ORDER-nn)/Nr,r=n.pow(e,s),o=n.eql(r,n.ONE),l=n.eql(r,n.ZERO),u=n.eql(r,n.neg(n.ONE));if(!o&&!l&&!u)throw new Error("invalid Legendre symbol result");return o?1:l?0:-1}function $5(n,e){e!==void 0&&sd(e);const s=e!==void 0?e:n.toString(2).length,r=Math.ceil(s/8);return{nBitLength:s,nByteLength:r}}function Hl(n,e,s=!1,r={}){if(n<=fn)throw new Error("invalid field: expected ORDER > 0, got "+n);let o,l,u=!1,d;if(typeof e=="object"&&e!=null){if(r.sqrt||s)throw new Error("cannot specify opts in two arguments");const b=e;b.BITS&&(o=b.BITS),b.sqrt&&(l=b.sqrt),typeof b.isLE=="boolean"&&(s=b.isLE),typeof b.modFromBytes=="boolean"&&(u=b.modFromBytes),d=b.allowedLengths}else typeof e=="number"&&(o=e),r.sqrt&&(l=r.sqrt);const{nBitLength:m,nByteLength:p}=$5(n,o);if(p>2048)throw new Error("invalid field: expected ORDER of <= 2048 bytes");let y;const v=Object.freeze({ORDER:n,isLE:s,BITS:m,BYTES:p,MASK:_g(m),ZERO:fn,ONE:nn,allowedLengths:d,create:b=>At(b,n),isValid:b=>{if(typeof b!="bigint")throw new Error("invalid field element: expected bigint, got "+typeof b);return fn<=b&&b<n},is0:b=>b===fn,isValidNot0:b=>!v.is0(b)&&v.isValid(b),isOdd:b=>(b&nn)===nn,neg:b=>At(-b,n),eql:(b,C)=>b===C,sqr:b=>At(b*b,n),add:(b,C)=>At(b+C,n),sub:(b,C)=>At(b-C,n),mul:(b,C)=>At(b*C,n),pow:(b,C)=>H5(v,b,C),div:(b,C)=>At(b*s1(C,n),n),sqrN:b=>b*b,addN:(b,C)=>b+C,subN:(b,C)=>b-C,mulN:(b,C)=>b*C,inv:b=>s1(b,n),sqrt:l||(b=>(y||(y=I5(n)),y(v,b))),toBytes:b=>s?F2(b,p):P2(b,p),fromBytes:(b,C=!0)=>{if(d){if(!d.includes(b.length)||b.length>p)throw new Error("Field.fromBytes: expected "+d+" bytes, got "+b.length);const S=new Uint8Array(p);S.set(b,s?0:S.length-b.length),b=S}if(b.length!==p)throw new Error("Field.fromBytes: expected "+p+" bytes, got "+b.length);let T=s?ro(b):k5(b);if(u&&(T=At(T,n)),!C&&!v.isValid(T))throw new Error("invalid field element: outside of range 0..ORDER");return T},invertBatch:b=>J2(v,b),cmov:(b,C,T)=>T?C:b});return Object.freeze(v)}/*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) */const od=BigInt(0),Tp=BigInt(1);function i1(n,e){const s=e.negate();return n?s:e}function xu(n,e){const s=J2(n.Fp,e.map(r=>r.Z));return e.map((r,o)=>n.fromAffine(r.toAffine(s[o])))}function eE(n,e){if(!Number.isSafeInteger(n)||n<=0||n>e)throw new Error("invalid window size, expected [1.."+e+"], got W="+n)}function Am(n,e){eE(n,e);const s=Math.ceil(e/n)+1,r=2**(n-1),o=2**n,l=_g(n),u=BigInt(n);return{windows:s,windowSize:r,mask:l,maxNumber:o,shiftBy:u}}function o1(n,e,s){const{windowSize:r,mask:o,maxNumber:l,shiftBy:u}=s;let d=Number(n&o),m=n>>u;d>r&&(d-=l,m+=Tp);const p=e*r,y=p+Math.abs(d)-1,v=d===0,b=d<0,C=e%2!==0;return{nextN:m,offset:y,isZero:v,isNeg:b,isNegF:C,offsetF:p}}function V5(n,e){if(!Array.isArray(n))throw new Error("array expected");n.forEach((s,r)=>{if(!(s instanceof e))throw new Error("invalid point at index "+r)})}function q5(n,e){if(!Array.isArray(n))throw new Error("array of scalars expected");n.forEach((s,r)=>{if(!e.isValid(s))throw new Error("invalid scalar at index "+r)})}const Tm=new WeakMap,tE=new WeakMap;function km(n){return tE.get(n)||1}function l1(n){if(n!==od)throw new Error("invalid wNAF")}class P5{constructor(e,s){this.BASE=e.BASE,this.ZERO=e.ZERO,this.Fn=e.Fn,this.bits=s}_unsafeLadder(e,s,r=this.ZERO){let o=e;for(;s>od;)s&Tp&&(r=r.add(o)),o=o.double(),s>>=Tp;return r}precomputeWindow(e,s){const{windows:r,windowSize:o}=Am(s,this.bits),l=[];let u=e,d=u;for(let m=0;m<r;m++){d=u,l.push(d);for(let p=1;p<o;p++)d=d.add(u),l.push(d);u=d.double()}return l}wNAF(e,s,r){if(!this.Fn.isValid(r))throw new Error("invalid scalar");let o=this.ZERO,l=this.BASE;const u=Am(e,this.bits);for(let d=0;d<u.windows;d++){const{nextN:m,offset:p,isZero:y,isNeg:v,isNegF:b,offsetF:C}=o1(r,d,u);r=m,y?l=l.add(i1(b,s[C])):o=o.add(i1(v,s[p]))}return l1(r),{p:o,f:l}}wNAFUnsafe(e,s,r,o=this.ZERO){const l=Am(e,this.bits);for(let u=0;u<l.windows&&r!==od;u++){const{nextN:d,offset:m,isZero:p,isNeg:y}=o1(r,u,l);if(r=d,!p){const v=s[m];o=o.add(y?v.negate():v)}}return l1(r),o}getPrecomputes(e,s,r){let o=Tm.get(s);return o||(o=this.precomputeWindow(s,e),e!==1&&(typeof r=="function"&&(o=r(o)),Tm.set(s,o))),o}cached(e,s,r){const o=km(e);return this.wNAF(o,this.getPrecomputes(o,e,r),s)}unsafe(e,s,r,o){const l=km(e);return l===1?this._unsafeLadder(e,s,o):this.wNAFUnsafe(l,this.getPrecomputes(l,e,r),s,o)}createCache(e,s){eE(s,this.bits),tE.set(e,s),Tm.delete(e)}hasCache(e){return km(e)!==1}}function F5(n,e,s,r){V5(s,n),q5(r,e);const o=s.length,l=r.length;if(o!==l)throw new Error("arrays of points and scalars must have equal length");const u=n.ZERO,d=O5(BigInt(o));let m=1;d>12?m=d-3:d>4?m=d-2:d>0&&(m=2);const p=_g(m),y=new Array(Number(p)+1).fill(u),v=Math.floor((e.BITS-1)/m)*m;let b=u;for(let C=v;C>=0;C-=m){y.fill(u);for(let S=0;S<l;S++){const E=r[S],_=Number(E>>BigInt(C)&p);y[_]=y[_].add(s[S])}let T=u;for(let S=y.length-1,E=u;S>0;S--)E=E.add(y[S]),T=T.add(E);if(b=b.add(T),C!==0)for(let S=0;S<m;S++)b=b.double()}return b}function c1(n,e,s){if(e){if(e.ORDER!==n)throw new Error("Field.ORDER must match order: Fp == p, Fn == n");return B5(e),e}else return Hl(n,{isLE:s})}function G5(n,e,s={},r){if(r===void 0&&(r=n==="edwards"),!e||typeof e!="object")throw new Error(`expected valid ${n} CURVE object`);for(const m of["p","n","h"]){const p=e[m];if(!(typeof p=="bigint"&&p>od))throw new Error(`CURVE.${m} must be positive bigint`)}const o=c1(e.p,s.Fp,r),l=c1(e.n,s.Fn,r),d=["Gx","Gy","a","d"];for(const m of d)if(!o.isValid(e[m]))throw new Error(`CURVE.${m} must be valid field element of CURVE.Fp`);return e=Object.freeze(Object.assign({},e)),{CURVE:e,Fp:o,Fn:l}}/*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) */const Is=BigInt(0),$t=BigInt(1),Nm=BigInt(2),Z5=BigInt(8);function Y5(n,e,s,r){const o=n.sqr(s),l=n.sqr(r),u=n.add(n.mul(e.a,o),l),d=n.add(n.ONE,n.mul(e.d,n.mul(o,l)));return n.eql(u,d)}function K5(n,e={}){const s=G5("edwards",n,e,e.FpFnLE),{Fp:r,Fn:o}=s;let l=s.CURVE;const{h:u}=l;Id(e,{},{uvRatio:"function"});const d=Nm<<BigInt(o.BYTES*8)-$t,m=E=>r.create(E),p=e.uvRatio||((E,_)=>{try{return{isValid:!0,value:r.sqrt(r.div(E,_))}}catch{return{isValid:!1,value:Is}}});if(!Y5(r,l,l.Gx,l.Gy))throw new Error("bad curve params: generator point");function y(E,_,j=!1){const N=j?$t:Is;return id("coordinate "+E,_,N,d),_}function v(E){if(!(E instanceof T))throw new Error("ExtendedPoint expected")}const b=a1((E,_)=>{const{X:j,Y:N,Z:z}=E,k=E.is0();_==null&&(_=k?Z5:r.inv(z));const O=m(j*_),M=m(N*_),R=r.mul(z,_);if(k)return{x:Is,y:$t};if(R!==$t)throw new Error("invZ was invalid");return{x:O,y:M}}),C=a1(E=>{const{a:_,d:j}=l;if(E.is0())throw new Error("bad point: ZERO");const{X:N,Y:z,Z:k,T:O}=E,M=m(N*N),R=m(z*z),L=m(k*k),H=m(L*L),V=m(M*_),q=m(L*m(V+R)),P=m(H+m(j*m(M*R)));if(q!==P)throw new Error("bad point: equation left != right (1)");const J=m(N*z),ie=m(k*O);if(J!==ie)throw new Error("bad point: equation left != right (2)");return!0});class T{constructor(_,j,N,z){this.X=y("x",_),this.Y=y("y",j),this.Z=y("z",N,!0),this.T=y("t",z),Object.freeze(this)}static CURVE(){return l}static fromAffine(_){if(_ instanceof T)throw new Error("extended point not allowed");const{x:j,y:N}=_||{};return y("x",j),y("y",N),new T(j,N,$t,m(j*N))}static fromBytes(_,j=!1){const N=r.BYTES,{a:z,d:k}=l;_=n1(Ru(_,N,"point")),Ap(j,"zip215");const O=n1(_),M=_[N-1];O[N-1]=M&-129;const R=ro(O),L=j?d:r.ORDER;id("point.y",R,Is,L);const H=m(R*R),V=m(H-$t),q=m(k*H-z);let{isValid:P,value:J}=p(V,q);if(!P)throw new Error("bad point: invalid y coordinate");const ie=(J&$t)===$t,U=(M&128)!==0;if(!j&&J===Is&&U)throw new Error("bad point: x=0 and x_0=1");return U!==ie&&(J=m(-J)),T.fromAffine({x:J,y:R})}static fromHex(_,j=!1){return T.fromBytes(ua("point",_),j)}get x(){return this.toAffine().x}get y(){return this.toAffine().y}precompute(_=8,j=!0){return S.createCache(this,_),j||this.multiply(Nm),this}assertValidity(){C(this)}equals(_){v(_);const{X:j,Y:N,Z:z}=this,{X:k,Y:O,Z:M}=_,R=m(j*M),L=m(k*z),H=m(N*M),V=m(O*z);return R===L&&H===V}is0(){return this.equals(T.ZERO)}negate(){return new T(m(-this.X),this.Y,this.Z,m(-this.T))}double(){const{a:_}=l,{X:j,Y:N,Z:z}=this,k=m(j*j),O=m(N*N),M=m(Nm*m(z*z)),R=m(_*k),L=j+N,H=m(m(L*L)-k-O),V=R+O,q=V-M,P=R-O,J=m(H*q),ie=m(V*P),U=m(H*P),G=m(q*V);return new T(J,ie,G,U)}add(_){v(_);const{a:j,d:N}=l,{X:z,Y:k,Z:O,T:M}=this,{X:R,Y:L,Z:H,T:V}=_,q=m(z*R),P=m(k*L),J=m(M*N*V),ie=m(O*H),U=m((z+k)*(R+L)-q-P),G=ie-J,W=ie+J,te=m(P-j*q),X=m(U*G),ge=m(W*te),Z=m(U*te),ee=m(G*W);return new T(X,ge,ee,Z)}subtract(_){return this.add(_.negate())}multiply(_){if(!o.isValidNot0(_))throw new Error("invalid scalar: expected 1 <= sc < curve.n");const{p:j,f:N}=S.cached(this,_,z=>xu(T,z));return xu(T,[j,N])[0]}multiplyUnsafe(_,j=T.ZERO){if(!o.isValid(_))throw new Error("invalid scalar: expected 0 <= sc < curve.n");return _===Is?T.ZERO:this.is0()||_===$t?this:S.unsafe(this,_,N=>xu(T,N),j)}isSmallOrder(){return this.multiplyUnsafe(u).is0()}isTorsionFree(){return S.unsafe(this,l.n).is0()}toAffine(_){return b(this,_)}clearCofactor(){return u===$t?this:this.multiplyUnsafe(u)}toBytes(){const{x:_,y:j}=this.toAffine(),N=r.toBytes(j);return N[N.length-1]|=_&$t?128:0,N}toHex(){return Eg(this.toBytes())}toString(){return`<Point ${this.is0()?"ZERO":this.toHex()}>`}get ex(){return this.X}get ey(){return this.Y}get ez(){return this.Z}get et(){return this.T}static normalizeZ(_){return xu(T,_)}static msm(_,j){return F5(T,o,_,j)}_setWindowSize(_){this.precompute(_)}toRawBytes(){return this.toBytes()}}T.BASE=new T(l.Gx,l.Gy,$t,m(l.Gx*l.Gy)),T.ZERO=new T(Is,$t,$t,Is),T.Fp=r,T.Fn=o;const S=new P5(T,o.BITS);return T.BASE.precompute(8),T}function X5(n,e,s={}){if(typeof e!="function")throw new Error('"hash" function param is required');Id(s,{},{adjustScalarBytes:"function",randomBytes:"function",domain:"function",prehash:"function",mapToCurve:"function"});const{prehash:r}=s,{BASE:o,Fp:l,Fn:u}=n,d=s.randomBytes||H2,m=s.adjustScalarBytes||(L=>L),p=s.domain||((L,H,V)=>{if(Ap(V,"phflag"),H.length||V)throw new Error("Contexts/pre-hash are not supported");return L});function y(L){return u.create(ro(L))}function v(L){const H=N.secretKey;L=ua("private key",L,H);const V=ua("hashed private key",e(L),2*H),q=m(V.slice(0,H)),P=V.slice(H,2*H),J=y(q);return{head:q,prefix:P,scalar:J}}function b(L){const{head:H,prefix:V,scalar:q}=v(L),P=o.multiply(q),J=P.toBytes();return{head:H,prefix:V,scalar:q,point:P,pointBytes:J}}function C(L){return b(L).pointBytes}function T(L=Uint8Array.of(),...H){const V=Wx(...H);return y(e(p(V,ua("context",L),!!r)))}function S(L,H,V={}){L=ua("message",L),r&&(L=r(L));const{prefix:q,scalar:P,pointBytes:J}=b(H),ie=T(V.context,q,L),U=o.multiply(ie).toBytes(),G=T(V.context,U,J,L),W=u.create(ie+G*P);if(!u.isValid(W))throw new Error("sign failed: invalid s");const te=Wx(U,u.toBytes(W));return Ru(te,N.signature,"result")}const E={zip215:!0};function _(L,H,V,q=E){const{context:P,zip215:J}=q,ie=N.signature;L=ua("signature",L,ie),H=ua("message",H),V=ua("publicKey",V,N.publicKey),J!==void 0&&Ap(J,"zip215"),r&&(H=r(H));const U=ie/2,G=L.subarray(0,U),W=ro(L.subarray(U,ie));let te,X,ge;try{te=n.fromBytes(V,J),X=n.fromBytes(G,J),ge=o.multiplyUnsafe(W)}catch{return!1}if(!J&&te.isSmallOrder())return!1;const Z=T(P,X.toBytes(),te.toBytes(),H);return X.add(te.multiplyUnsafe(Z)).subtract(ge).clearCofactor().is0()}const j=l.BYTES,N={secretKey:j,publicKey:j,signature:2*j,seed:j};function z(L=d(N.seed)){return Ru(L,N.seed,"seed")}function k(L){const H=R.randomSecretKey(L);return{secretKey:H,publicKey:C(H)}}function O(L){return zd(L)&&L.length===u.BYTES}function M(L,H){try{return!!n.fromBytes(L,H)}catch{return!1}}const R={getExtendedPublicKey:b,randomSecretKey:z,isValidSecretKey:O,isValidPublicKey:M,toMontgomery(L){const{y:H}=n.fromBytes(L),V=N.publicKey,q=V===32;if(!q&&V!==57)throw new Error("only defined for 25519 and 448");const P=q?l.div($t+H,$t-H):l.div(H-$t,H+$t);return l.toBytes(P)},toMontgomerySecret(L){const H=N.secretKey;Ru(L,H);const V=e(L.subarray(0,H));return m(V).subarray(0,H)},randomPrivateKey:z,precompute(L=8,H=n.BASE){return H.precompute(L,!1)}};return Object.freeze({keygen:k,getPublicKey:C,sign:S,verify:_,utils:R,Point:n,lengths:N})}function Q5(n){const e={a:n.a,d:n.d,p:n.Fp.ORDER,n:n.n,h:n.h,Gx:n.Gx,Gy:n.Gy},s=n.Fp,r=Hl(e.n,n.nBitLength,!0),o={Fp:s,Fn:r,uvRatio:n.uvRatio},l={randomBytes:n.randomBytes,adjustScalarBytes:n.adjustScalarBytes,domain:n.domain,prehash:n.prehash,mapToCurve:n.mapToCurve};return{CURVE:e,curveOpts:o,hash:n.hash,eddsaOpts:l}}function W5(n,e){const s=e.Point;return Object.assign({},e,{ExtendedPoint:s,CURVE:n,nBitLength:s.Fn.BITS,nByteLength:s.Fn.BYTES})}function J5(n){const{CURVE:e,curveOpts:s,hash:r,eddsaOpts:o}=Q5(n),l=K5(e,s),u=X5(l,r,o);return W5(n,u)}/*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) */const fl=BigInt(0),Gi=BigInt(1),wu=BigInt(2);function eR(n){return Id(n,{adjustScalarBytes:"function",powPminus2:"function"}),Object.freeze({...n})}function tR(n){const e=eR(n),{P:s,type:r,adjustScalarBytes:o,powPminus2:l,randomBytes:u}=e,d=r==="x25519";if(!d&&r!=="x448")throw new Error("invalid type");const m=u||H2,p=d?255:448,y=d?32:56,v=BigInt(d?9:5),b=BigInt(d?121665:39081),C=d?wu**BigInt(254):wu**BigInt(447),T=d?BigInt(8)*wu**BigInt(251)-Gi:BigInt(4)*wu**BigInt(445)-Gi,S=C+T+Gi,E=P=>At(P,s),_=j(v);function j(P){return F2(E(P),y)}function N(P){const J=ua("u coordinate",P,y);return d&&(J[31]&=127),E(ro(J))}function z(P){return ro(o(ua("scalar",P,y)))}function k(P,J){const ie=R(N(J),z(P));if(ie===fl)throw new Error("invalid private or public key received");return j(ie)}function O(P){return k(P,_)}function M(P,J,ie){const U=E(P*(J-ie));return J=E(J-U),ie=E(ie+U),{x_2:J,x_3:ie}}function R(P,J){id("u",P,fl,s),id("scalar",J,C,S);const ie=J,U=P;let G=Gi,W=fl,te=P,X=Gi,ge=fl;for(let ee=BigInt(p-1);ee>=fl;ee--){const fe=ie>>ee&Gi;ge^=fe,{x_2:G,x_3:te}=M(ge,G,te),{x_2:W,x_3:X}=M(ge,W,X),ge=fe;const ue=G+W,oe=E(ue*ue),Ce=G-W,me=E(Ce*Ce),he=oe-me,He=te+X,ke=te-X,De=E(ke*ue),$e=E(He*Ce),ze=De+$e,pt=De-$e;te=E(ze*ze),X=E(U*E(pt*pt)),G=E(oe*me),W=E(he*(oe+E(b*he)))}({x_2:G,x_3:te}=M(ge,G,te)),{x_2:W,x_3:X}=M(ge,W,X);const Z=l(W);return E(G*Z)}const L={secretKey:y,publicKey:y,seed:y},H=(P=m(y))=>(nr(P,L.seed),P);function V(P){const J=H(P);return{secretKey:J,publicKey:O(J)}}return{keygen:V,getSharedSecret:(P,J)=>k(P,J),getPublicKey:P=>O(P),scalarMult:k,scalarMultBase:O,utils:{randomSecretKey:H,randomPrivateKey:H},GuBytes:_.slice(),lengths:L}}/*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) */const nR=BigInt(1),u1=BigInt(2),aR=BigInt(3),sR=BigInt(5),rR=BigInt(8),Ag=BigInt("0x7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffed"),nE={p:Ag,n:BigInt("0x1000000000000000000000000000000014def9dea2f79cd65812631a5cf5d3ed"),h:rR,a:BigInt("0x7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffec"),d:BigInt("0x52036cee2b6ffe738cc740797779e89800700a4d4141d8ab75eb4dca135978a3"),Gx:BigInt("0x216936d3cd6e53fec0a4e231fdd6dc5c692cc7609525a7b2c9562d608f25d51a"),Gy:BigInt("0x6666666666666666666666666666666666666666666666666666666666666658")};function aE(n){const e=BigInt(10),s=BigInt(20),r=BigInt(40),o=BigInt(80),l=Ag,d=n*n%l*n%l,m=Yn(d,u1,l)*d%l,p=Yn(m,nR,l)*n%l,y=Yn(p,sR,l)*p%l,v=Yn(y,e,l)*y%l,b=Yn(v,s,l)*v%l,C=Yn(b,r,l)*b%l,T=Yn(C,o,l)*C%l,S=Yn(T,o,l)*C%l,E=Yn(S,e,l)*y%l;return{pow_p_5_8:Yn(E,u1,l)*n%l,b2:d}}function sE(n){return n[0]&=248,n[31]&=127,n[31]|=64,n}const d1=BigInt("19681161376707505956807079304988542015446066515923890162744021073123829784752");function iR(n,e){const s=Ag,r=At(e*e*e,s),o=At(r*r*e,s),l=aE(n*o).pow_p_5_8;let u=At(n*r*l,s);const d=At(e*u*u,s),m=u,p=At(u*d1,s),y=d===n,v=d===At(-n,s),b=d===At(-n*d1,s);return y&&(u=m),(v||b)&&(u=p),L5(u,s)&&(u=At(-u,s)),{isValid:y||v,value:u}}const rE=Hl(nE.p,{isLE:!0}),oR={...nE,Fp:rE,hash:T5,adjustScalarBytes:sE,uvRatio:iR},Tg=J5(oR),Ar=(()=>{const n=rE.ORDER;return tR({P:n,type:"x25519",powPminus2:e=>{const{pow_p_5_8:s,b2:r}=aE(e);return At(Yn(s,aR,n)*r,n)},adjustScalarBytes:sE})})();class iE extends U2{constructor(e,s){super(),this.finished=!1,this.destroyed=!1,Sg(e);const r=Nl(s);if(this.iHash=e.create(),typeof this.iHash.update!="function")throw new Error("Expected instance of class which extends utils.Hash");this.blockLen=this.iHash.blockLen,this.outputLen=this.iHash.outputLen;const o=this.blockLen,l=new Uint8Array(o);l.set(r.length>o?e.create().update(r).digest():r);for(let u=0;u<l.length;u++)l[u]^=54;this.iHash.update(l),this.oHash=e.create();for(let u=0;u<l.length;u++)l[u]^=106;this.oHash.update(l),Br(l)}update(e){return rd(this),this.iHash.update(e),this}digestInto(e){rd(this),nr(e,this.outputLen),this.finished=!0,this.iHash.digestInto(e),this.oHash.update(e),this.oHash.digestInto(e),this.destroy()}digest(){const e=new Uint8Array(this.oHash.outputLen);return this.digestInto(e),e}_cloneInto(e){e||(e=Object.create(Object.getPrototypeOf(this),{}));const{oHash:s,iHash:r,finished:o,destroyed:l,blockLen:u,outputLen:d}=this;return e=e,e.finished=o,e.destroyed=l,e.blockLen=u,e.outputLen=d,e.oHash=s._cloneInto(e.oHash),e.iHash=r._cloneInto(e.iHash),e}clone(){return this._cloneInto()}destroy(){this.destroyed=!0,this.oHash.destroy(),this.iHash.destroy()}}const Ld=(n,e,s)=>new iE(n,e).update(s).digest();Ld.create=(n,e)=>new iE(n,e);function lR(n,e,s){return Sg(n),s===void 0&&(s=new Uint8Array(n.outputLen)),Ld(n,Nl(s),Nl(e))}const Om=Uint8Array.from([0]),f1=Uint8Array.of();function cR(n,e,s,r=32){Sg(n),sd(r);const o=n.outputLen;if(r>255*o)throw new Error("Length should be <= 255*HashLen");const l=Math.ceil(r/o);s===void 0&&(s=f1);const u=new Uint8Array(l*o),d=Ld.create(n,e),m=d._cloneInto(),p=new Uint8Array(d.outputLen);for(let y=0;y<l;y++)Om[0]=y+1,m.update(y===0?f1:p).update(s).update(Om).digestInto(p),u.set(p,o*y),d._cloneInto(m);return d.destroy(),m.destroy(),Br(p,Om),u.slice(0,r)}const uR=(n,e,s,r,o)=>cR(n,lR(n,e,s),r,o);function dR(n){const e=[];for(let s=0;s<n.length;s++){let r=n.charCodeAt(s);if(r>=55296&&r<=56319&&s+1<n.length){const o=n.charCodeAt(s+1);o>=56320&&o<=57343&&(r=65536+(r-55296<<10)+(o-56320),s++)}r<128?e.push(r):r<2048?e.push(192|r>>6,128|r&63):r<65536?e.push(224|r>>12,128|r>>6&63,128|r&63):e.push(240|r>>18,128|r>>12&63,128|r>>6&63,128|r&63)}return Uint8Array.from(e)}function fR(n){let e="",s=[];const r=()=>{e+=String.fromCharCode(...s),s=[]};for(let o=0;o<n.length;){const l=n[o];let u;l<128?(u=l,o+=1):l>=240?(u=(l&7)<<18|(n[o+1]&63)<<12|(n[o+2]&63)<<6|n[o+3]&63,o+=4):l>=224?(u=(l&15)<<12|(n[o+1]&63)<<6|n[o+2]&63,o+=3):(u=(l&31)<<6|n[o+1]&63,o+=2),u>65535?(u-=65536,s.push(55296+(u>>10),56320+(u&1023))):s.push(u),s.length>8e3&&r()}return r(),e}const Hr={encode:dR},yl="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_",hR=new Map([...yl].map((n,e)=>[n,e]));function Qn(n){let e="";for(let s=0;s<n.length;s+=3){const r=n[s]<<16|(n[s+1]??0)<<8|(n[s+2]??0);e+=yl[r>>18&63]+yl[r>>12&63],s+1<n.length&&(e+=yl[r>>6&63]),s+2<n.length&&(e+=yl[r&63])}return e}function pa(n){const e=n.replace(/=+$/,"").replace(/\+/g,"-").replace(/\//g,"_"),s=new Uint8Array(Math.floor(e.length*3/4));let r=0,o=0,l=0;for(const u of e){const d=hR.get(u);if(d===void 0)throw new Error("invalid base64");o=o<<6|d,r+=6,r>=8&&(r-=8,s[l++]=o>>r&255)}return s.subarray(0,l)}function h1(...n){const e=new Uint8Array(n.reduce((r,o)=>r+o.length,0));let s=0;for(const r of n)e.set(r,s),s+=r.length;return e}function ld(n){const e=new Uint8Array(n);return globalThis.crypto.getRandomValues(e),e}function oE(n){return Qn(Ol(pa(n)).subarray(0,16))}function mR(){const n=ld(32),e=ld(32),s=Qn(Tg.getPublicKey(n));return{id:oE(s),signKey:s,boxKey:Qn(Ar.getPublicKey(e)),signSecret:Qn(n),boxSecret:Qn(e)}}function cd(n){return{id:n.id,signKey:n.signKey,boxKey:n.boxKey}}function lE(n,e){return Qn(Tg.sign(Hr.encode(e),pa(n.signSecret)))}function pR(n,e,s){try{return Tg.verify(pa(s),Hr.encode(e),pa(n))}catch{return!1}}function gR(n){return`linkshell-gateway-v2:${n}`}function cE(n,e){return Qn(Ld(Ol,pa(n),Hr.encode(`${e.id}.${e.boxKey}`)))}function vR(n){return Qn(Ol(Hr.encode(`linkshell-pair-code:${n}`)))}function yR(){const n=ld(32);return{secret:n,public:Qn(Ar.getPublicKey(n))}}function bR(n){const e=pa(n.local.boxSecret),s=pa(n.remoteBoxKey),r=pa(n.remoteEphemeral),o=Ar.getSharedSecret(n.localEphemeral,r),l=Ar.getSharedSecret(e,s),u=Ar.getSharedSecret(n.localEphemeral,s),d=Ar.getSharedSecret(e,r),m=u,p=d,y=Ar.getPublicKey(n.localEphemeral),[v,b]=[y,r],[C,T]=[pa(n.local.boxKey),s],S=h1(Hr.encode("linkshell/v2/channel"),v,b,C,T),E=uR(Ol,h1(o,m,p,l),Ol(S),Hr.encode("linkshell/v2/keys"),64),_=E.subarray(0,32),j=E.subarray(32,64);return n.initiator?{send:_,receive:j}:{send:j,receive:_}}function m1(n){const e=new Uint8Array(24),s=new DataView(e.buffer);return s.setUint32(16,Math.floor(n/2**32)),s.setUint32(20,n>>>0),e}class xR{constructor(e){this.keys=e}sent=0;received=0;seal(e){const s=++this.sent,r=Xx(this.keys.send,m1(s)).encrypt(Hr.encode(e));return`${s}.${Qn(r)}`}open(e){const s=e.indexOf("."),r=Number(e.slice(0,s));if(!Number.isSafeInteger(r)||r<=this.received)throw new Error("replayed or out-of-order frame");const o=Xx(this.keys.receive,m1(r)).decrypt(pa(e.slice(s+1)));return this.received=r,fR(o)}}const wR="/v2/connect",Ud=I({id:A(),signKey:A(),boxKey:A()}),SR=Me(["machine","device"]);Ud.extend({name:A(),platform:A().optional(),online:ye(),via:Me(["paired","account"])});Ud.extend({name:A(),online:ye(),pairedAt:se().optional()});wa("t",[I({t:pe("auth"),role:SR,identity:Ud,signature:A(),name:A().max(120),platform:A().max(40).optional(),token:A().optional()}),I({t:pe("req"),id:se().int(),method:A(),params:jn().optional()}),I({t:pe("to"),to:A(),d:A().max(40*1024*1024)}),I({t:pe("ping")})]);const ER=wa("t",[I({t:pe("challenge"),nonce:A()}),I({t:pe("ready"),userId:A().optional(),email:A().optional()}),I({t:pe("res"),id:se().int(),result:jn().optional(),error:I({code:A(),message:A()}).optional()}),I({t:pe("event"),name:A(),data:jn()}),I({t:pe("from"),from:Ud,via:Me(["paired","account"]),d:A()}),I({t:pe("undeliverable"),to:A(),reason:A()}),I({t:pe("pong")}),I({t:pe("error"),code:A(),message:A()})]),p1="linkshell://pair?";function uE(n){const e=n.trim();if(!e.startsWith(p1))return;const s=new URLSearchParams(e.slice(p1.length)),r=s.get("g"),o=s.get("k"),l=s.get("s"),u=s.get("c");if(!(!r||!o||!l||!u||!/^(wss?|https?):\/\//.test(r)))return{gateway:r,signKey:o,secret:l,code:u}}const CR=wa("k",[I({k:pe("hello"),ch:A(),eph:A(),sig:A()}),I({k:pe("welcome"),ch:A(),eph:A(),sig:A()}),I({k:pe("data"),ch:A(),box:A()}),I({k:pe("close"),ch:A(),reason:A().optional()}),I({k:pe("refuse"),ch:A(),code:A(),message:A()})]);function g1(n,e,s,r,o){return`linkshell-tunnel-v2:${n}:${e}:${s}:${r}:${o}`}function _R(n,e,s){const r=yR();return{hello:{k:"hello",ch:s,eph:r.public,sig:lE(n,g1("hello",s,n.id,e.id,r.public))},accept(l){if(!pR(e.signKey,g1("welcome",s,e.id,n.id,l.eph),l.sig))throw new Error("the computer's key doesn't match: refusing to connect");return new xR(bR({initiator:!0,local:n,localEphemeral:r.secret,remoteBoxKey:e.boxKey,remoteEphemeral:l.eph}))}}}class Su extends Error{constructor(e,s){super(s),this.code=e}}const jR=1;class AR{constructor(e){this.options=e}socket;statusValue="offline";attempt=0;timer;nextId=1;pending=new Map;statusListeners=new Set;frameListeners=new Set;undeliverableListeners=new Set;eventListeners=new Map;waiters=new Set;account;lastError;get status(){return this.statusValue}get identity(){return cd(this.options.identity)}onStatus(e){return this.statusListeners.add(e),()=>this.statusListeners.delete(e)}onFrame(e){return this.frameListeners.add(e),()=>this.frameListeners.delete(e)}onUndeliverable(e){return this.undeliverableListeners.add(e),()=>this.undeliverableListeners.delete(e)}on(e,s){let r=this.eventListeners.get(e);r||this.eventListeners.set(e,r=new Set);const o=s;return r.add(o),()=>r.delete(o)}start(){this.statusValue==="connecting"||this.statusValue==="online"||this.open()}stop(){this.setStatus("stopped"),clearTimeout(this.timer),this.socket?.close(1e3,"stopped"),this.socket=void 0,this.failPending("stopped");for(const e of this.waiters)e()}reconnectNow(){this.statusValue==="stopped"||this.statusValue==="online"||this.statusValue==="connecting"||(clearTimeout(this.timer),this.attempt=0,this.open())}reauthenticate(){if(this.statusValue==="stopped")return;clearTimeout(this.timer),this.attempt=0;const e=this.socket;this.socket=void 0,e?.close(1e3,"signing in again"),this.failPending("connection closed"),this.open()}waitOnline(e){return this.statusValue==="online"?Promise.resolve(!0):this.statusValue==="stopped"?Promise.resolve(!1):new Promise(s=>{const r=()=>{clearTimeout(o),this.waiters.delete(r),s(this.statusValue==="online")},o=setTimeout(r,e);this.waiters.add(r)})}async request(e,s,r){const o=r??this.options.requestTimeoutMs??2e4;if(!await this.waitOnline(o))throw new Su("offline","not connected to the gateway");const l=this.nextId++;return new Promise((u,d)=>{const m=setTimeout(()=>{this.pending.delete(l),d(new Su("timeout",`${e} timed out`))},o);this.pending.set(l,{resolve:u,reject:d,timer:m}),this.sendFrame({t:"req",id:l,method:e,params:s})})}send(e,s){return this.statusValue!=="online"?!1:this.sendFrame({t:"to",to:e,d:JSON.stringify(s)})}sendFrame(e){return!this.socket||this.socket.readyState!==jR?!1:(this.socket.send(JSON.stringify(e)),!0)}setStatus(e,s){if(s&&(this.lastError=s),e==="online"&&(this.lastError=void 0),!(this.statusValue===e&&!s)){this.statusValue=e;for(const r of this.statusListeners)r(e,s);if(e==="online"||e==="stopped")for(const r of this.waiters)r()}}failPending(e){for(const[s,r]of this.pending)clearTimeout(r.timer),r.reject(new Su("offline",e)),this.pending.delete(s)}open(){this.setStatus("connecting");let e;try{e=this.options.createSocket(this.options.url)}catch(r){this.scheduleReconnect({code:"connect_failed",message:r instanceof Error?r.message:String(r)});return}this.socket=e;let s;e.onmessage=r=>{let o;try{const l=ER.safeParse(JSON.parse(String(r.data)));if(!l.success)return;o=l.data}catch{return}switch(o.t){case"challenge":this.authenticate(o.nonce);return;case"ready":this.attempt=0,this.account=o.userId?{userId:o.userId,email:o.email}:void 0,this.setStatus("online");return;case"res":{const l=this.pending.get(o.id);if(!l)return;clearTimeout(l.timer),this.pending.delete(o.id),o.error?l.reject(new Su(o.error.code,o.error.message)):l.resolve(o.result);return}case"event":for(const l of this.eventListeners.get(o.name)??[])l(o.data);return;case"from":{let l;try{const u=CR.safeParse(JSON.parse(o.d));if(!u.success)return;l=u.data}catch{return}for(const u of this.frameListeners)u(o.from,o.via,l);return}case"undeliverable":for(const l of this.undeliverableListeners)l(o.to,o.reason);return;case"error":s={code:o.code,message:o.message};return;case"pong":return}},e.onerror=()=>{},e.onclose=r=>{if(this.socket===e&&(this.socket=void 0,this.failPending("connection closed"),this.statusValue!=="stopped")){if(r.code===4e3){this.setStatus("offline",{code:"replaced",message:"connected elsewhere with this identity"});return}this.scheduleReconnect(s??{code:"disconnected",message:r.reason||"connection lost"})}}}async authenticate(e){let s;try{s=await this.options.token?.()??void 0}catch{s=void 0}this.sendFrame({t:"auth",role:this.options.role,identity:cd(this.options.identity),signature:lE(this.options.identity,gR(e)),name:this.options.name.slice(0,120),platform:this.options.platform,token:s})}scheduleReconnect(e){this.setStatus("offline",e);const s=this.options.minBackoffMs??500,r=this.options.maxBackoffMs??3e4,o=Math.min(r,s*2**this.attempt)*(.75+Math.random()*.5);this.attempt+=1,this.timer=setTimeout(()=>this.open(),o)}}const TR="linkshell-bulk",v1=16*1024,dE=1,fE=2;function y1(n){const e=n.type==="data"?n.data:new TextEncoder().encode(n.error??""),s=new Uint8Array(5+e.length);return s[0]=n.type==="data"?dE:fE,new DataView(s.buffer).setUint32(1,n.stream),s.set(e,5),s}function kR(n){if(n.length<5)return;const e=new DataView(n.buffer,n.byteOffset,n.byteLength).getUint32(1),s=n.subarray(5);if(n[0]===dE)return{type:"data",stream:e,data:s};if(n[0]===fE)return{type:"close",stream:e,error:s.length?new TextDecoder().decode(s):void 0}}const b1=48*1024,NR=I({id:A().regex(/^[a-f0-9]{64}$/),target:A().max(1024),capturedAt:se().finite().nonnegative(),width:se().int().positive().max(2048),height:se().int().positive().max(2048),mimeType:pe("image/webp")});class OR{held=new Uint8Array(0);push(e){if(this.held.length+e.length>b1+4104)throw new Error("preview buffer too large");const s=new Uint8Array(this.held.length+e.length);s.set(this.held),s.set(e,this.held.length),this.held=s;const r=[];for(;this.held.length>=8;){const o=new DataView(this.held.buffer,this.held.byteOffset),l=o.getUint32(0),u=o.getUint32(4);if(l>4096||u>b1||!l||!u)throw new Error("invalid preview frame");const d=8+l+u;if(this.held.length<d)break;const m=NR.parse(JSON.parse(new TextDecoder().decode(this.held.subarray(8,8+l))));r.push({...m,bytes:this.held.slice(8+l,d)}),this.held=this.held.slice(d)}return r}}function Rm(n,e){const s=n.header??n.text,r=e?.values??[],o=n.constraints;if(r.length>1&&n.kind!=="choices")return`${s}只能填写一个答案`;if(n.kind!=="text"&&n.options&&r.some(d=>!n.options.some(m=>m.value===d)))return`${s}包含无效选项`;if(!(o?.type==="array"?e!==void 0:o?.type==="string"?r[0]!==void 0||!!e?.other?.trim():r.some(d=>d!=="")||!!e?.other?.trim()))return n.required?`还没回答:${s}`:void 0;if(!o)return;const u=r[0]??"";if(o.type==="number"||o.type==="integer"){const d=Number(u);if(!u.trim()||!Number.isFinite(d)||o.type==="integer"&&!Number.isInteger(d))return`${s}需要填写${o.type==="integer"?"整数":"数字"}`;if(o.minimum!==void 0&&d<o.minimum)return`${s}不能小于 ${o.minimum}`;if(o.maximum!==void 0&&d>o.maximum)return`${s}不能大于 ${o.maximum}`}if(o.type==="array"){if(new Set(r).size!==r.length)return`${s}不能重复选择`;if(o.minItems!==void 0&&r.length<o.minItems)return`${s}至少选择 ${o.minItems} 项`;if(o.maxItems!==void 0&&r.length>o.maxItems)return`${s}最多选择 ${o.maxItems} 项`}if(o.type==="string"){const d=[...u].length;if(o.minLength!==void 0&&d<o.minLength)return`${s}至少需要 ${o.minLength} 个字符`;if(o.maxLength!==void 0&&d>o.maxLength)return`${s}最多允许 ${o.maxLength} 个字符`;if(o.pattern)try{if(!new RegExp(o.pattern,"u").test(u))return`${s}格式不符合要求`}catch{return`${s}的格式规则无效`}if(o.format==="email"&&!/^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(u))return`${s}需要有效的邮箱地址`;if(o.format==="uri")try{new URL(u)}catch{return`${s}需要完整的网址`}if(o.format==="date"&&(!/^\d{4}-\d{2}-\d{2}$/.test(u)||!Number.isFinite(Date.parse(u))||new Date(u).toISOString().slice(0,10)!==u))return`${s}需要有效日期(YYYY-MM-DD)`;if(o.format==="date-time"&&(!/^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}(?:\.\d+)?(?:Z|[+-]\d{2}:\d{2})$/i.test(u)||!Number.isFinite(Date.parse(u))))return`${s}需要包含时区的有效日期时间`}}function to(n){return{sessionId:n,lastSeq:0,startSeq:0,items:[],index:{},permissions:[],config:[],commands:[],state:"idle",turnActive:!1}}function jt(n,e){const s=n.index[e.id];if(s===void 0)return{...n,items:[...n.items,e],index:{...n.index,[e.id]:n.items.length}};const r=n.items.slice();return r[s]=e,{...n,items:r}}function _n(n,e,s){const r=n.index[e],o=r===void 0?void 0:n.items[r];return o&&o.kind===s?o:void 0}function x1(n,e){return e.type==="text"?n+e.text:n}function Du(n,e){let s;return n.items.forEach((r,o)=>{(r.kind==="agent"||r.kind==="thought")&&r.streaming&&(s??=n.items.slice(),s[o]=r.kind==="thought"?{...r,streaming:!1,endedTs:r.endedTs??e}:{...r,streaming:!1})}),s?{...n,items:s}:n}function ud(n,e){const s=Du(n,e);let r;return s.items.forEach((o,l)=>{if(o.kind!=="tool"||!o.sub)return;const u=ud(o.sub,e);u!==o.sub&&(r??=s.items.slice(),r[l]={...o,sub:u})}),r?{...s,items:r}:s}function RR(n){switch(n.sessionUpdate){case"ls_message":return n.parentToolCallId;case"agent_message_chunk":case"agent_thought_chunk":case"tool_call":case"tool_call_update":case"ls_message_done":case"ls_turn":return n.parentToolCallId;default:return}}function DR(n,e){return n.flatMap(s=>{const r=e.find(u=>u.id===s.id);if(!r)return[];const o=r.values.filter(Boolean).map(u=>s.options?.find(d=>d.value===u)?.label??u),l=[...s.secret&&o.length>0?["••••••"]:o,...r.other?[r.other]:[]];return l.length>0?[{question:s.header??s.text,answer:l.join(",")}]:[]})}function hE(n,e,s,r,o){if(!_n(n,e,"tool")){for(const m of n.items)if(!(m.kind!=="tool"||!m.sub||!kg(m.sub,e)))return jt(n,{...m,sub:hE(m.sub,e,s,r,o)})}const l=_n(n,e,"tool")??{kind:"tool",id:e,title:"Sub-agent",toolKind:"other",status:"in_progress",detail:{type:"subagent",action:"spawn"},content:[],output:"",ts:r},u={...s,parentToolCallId:void 0},d=Ng(l.sub??to(n.sessionId),u,r,o);return d===l.sub?n:jt(n,{...l,sub:d})}function kg(n,e){const s=_n(n,e,"tool");if(s)return s;for(const r of n.items){if(r.kind!=="tool"||!r.sub)continue;const o=kg(r.sub,e);if(o)return o}}function Ng(n,e,s,r){const o=RR(e);if(o)return hE(n,o,e,s,r);switch(e.sessionUpdate){case"ls_message":{const l=e.role==="thought"?`thought:${e.messageId}`:e.messageId,u=e.role==="session"?"agent":e.role,d=_n(n,l,u);if(e.content===void 0&&d)return u==="agent"?jt(n,{...d,senderSessionId:e.senderSessionId??(d.kind==="agent"?d.senderSessionId:void 0),recipientSessionId:e.recipientSessionId??(d.kind==="agent"?d.recipientSessionId:void 0)}):n;const m=e.content??[],p=m.filter(v=>v.type==="text").map(v=>v.text).join(""),y=d?.ts??s;if(u==="user"){const v=e.append&&d?.kind==="user"?[...d.blocks,...m]:m;return jt(n,{kind:"user",id:l,blocks:kp(v),agentMessages:dp(v),ts:y})}return u==="thought"?jt(n,{kind:"thought",id:l,text:(e.append&&d?.kind==="thought"?d.text:"")+p,streaming:n.turnActive,ts:y}):jt(n,{kind:"agent",id:l,text:(e.append&&d?.kind==="agent"?d.text:"")+p,attachments:[...e.append&&d?.kind==="agent"?d.attachments??[]:[],...m.filter(v=>v.type!=="text")],senderSessionId:e.senderSessionId??(d?.kind==="agent"?d.senderSessionId:void 0),recipientSessionId:e.recipientSessionId??(d?.kind==="agent"?d.recipientSessionId:void 0),streaming:n.turnActive,ts:y})}case"user_message_chunk":{const l=e.messageId??`user-${r}`,u=_n(n,l,"user"),d=u&&!u.pending?[...u.blocks,e.content]:[e.content];return jt(n,{kind:"user",id:l,blocks:kp(d),agentMessages:dp(d),ts:u?.ts??s})}case"agent_message_chunk":{const l=_n(n,e.messageId,"agent"),u=e.content.type==="text"?l?.attachments:[...l?.attachments??[],e.content];return jt(n,{kind:"agent",id:e.messageId,text:x1(l?.text??"",e.content),attachments:u,streaming:!0,ts:l?.ts??s})}case"agent_thought_chunk":{const l=`thought:${e.messageId}`,u=_n(n,l,"thought");return jt(n,{kind:"thought",id:l,text:x1(u?.text??"",e.content),streaming:!0,ts:u?.ts??s})}case"ls_message_done":{const l=e.role==="thought"?`thought:${e.messageId}`:e.messageId,u=_n(n,l,"agent");if(u)return jt(n,{...u,streaming:!1,...e.questions?.length?{questions:e.questions}:{}});const d=_n(n,l,"thought");return d?jt(n,{...d,streaming:!1,endedTs:d.endedTs??s}):n}case"tool_call":{const l=_n(n,e.toolCallId,"tool"),u=e.status==="completed"||e.status==="failed";return jt(Du(n,s),{kind:"tool",id:e.toolCallId,title:e.title,name:e.name??l?.name,toolKind:e.kind,status:e.status,rawInput:e.rawInput??l?.rawInput,rawOutput:e.rawOutput??l?.rawOutput,locations:e.locations??l?.locations,detail:e.detail??l?.detail,sub:l?.sub,content:e.content??l?.content??[],output:l?.output??"",ts:l?.ts??s,endedTs:u?s:l?.endedTs})}case"tool_call_update":{const u=_n(n,e.toolCallId,"tool")??{kind:"tool",id:e.toolCallId,title:e.title??"Tool",toolKind:"other",status:"in_progress",content:[],output:"",ts:s},d=e.status??u.status,m=d==="completed"||d==="failed";return jt(n,{...u,title:e.title??u.title,name:e.name??u.name,toolKind:e.kind??u.toolKind,rawInput:e.rawInput===void 0?u.rawInput:e.rawInput,locations:e.locations??u.locations,detail:e.detail??u.detail,status:d,content:e.content?e.replaceContent?e.content:pE(u.content,e.content):u.content,output:e.replaceOutput??(e.appendOutput?u.output+e.appendOutput:u.output),rawOutput:e.rawOutput===void 0?u.rawOutput:e.rawOutput,endedTs:m?u.endedTs??s:e.status?void 0:u.endedTs,sub:m&&u.sub?ud(u.sub,s):u.sub})}case"plan":{const l=e.planId?`plan:${e.planId}`:n.planId??`plan-${r}`;return e.removed?Np(n,l):{...jt(n,{kind:"plan",id:l,entries:e.entries,title:e.title,markdown:e.markdown,path:e.path,ts:_n(n,l,"plan")?.ts??s}),planId:l}}case"available_commands_update":return{...n,commands:e.availableCommands};case"ls_goal":return{...n,goal:e.goal};case"current_mode_update":return{...n,modeId:e.currentModeId,config:n.config.map(l=>l.category==="mode"?{...l,current:e.currentModeId}:l)};case"ls_config":return{...n,config:e.options,modeId:e.options.find(l=>l.category==="mode")?.current??n.modeId};case"session_info_update":return{...n,title:e.title===null?void 0:e.title??n.title};case"usage_update":return{...n,usage:{...n.usage,usedTokens:e.usedTokens??n.usage?.usedTokens,contextWindow:e.contextWindow??n.usage?.contextWindow,cost:e.cost===void 0?n.usage?.cost:e.cost,tokens:e.tokens??n.usage?.tokens}};case"ls_turn":if(e.state==="started")return{...n,turnActive:!0,state:"running",planId:void 0};{const l=ud(n,s),u={...l,turnActive:!1,state:l.permissions.some(d=>d.childSessionId)?"waiting":e.stopReason==="error"?"error":"idle",permissions:l.permissions.filter(d=>d.childSessionId)};return e.stopReason&&e.stopReason!=="end_turn"?jt(u,{kind:"turn-end",id:`turn-end-${r}`,stopReason:e.stopReason,ts:s}):u}case"ls_status":return{...n,state:e.state,turnActive:e.turnActive??n.turnActive};case"ls_permission":return n.permissions.some(l=>l.requestId===e.requestId)?n:{...Du(n,s),state:"waiting",permissions:[...n.permissions,{requestId:e.requestId,childSessionId:e.childSessionId,toolCallId:e.toolCallId,title:e.title,detail:e.detail,tool:e.tool,url:e.url,options:e.options,questions:e.questions,ts:s}]};case"ls_permission_resolved":{const l=n.permissions.find(p=>p.requestId===e.requestId);if(!l)return n;const u=l.options.find(p=>p.optionId===e.optionId),d=n.permissions.filter(p=>p.requestId!==e.requestId),m={...n,permissions:d,state:d.length>0?"waiting":n.turnActive?"running":n.state==="waiting"?"idle":n.state};return jt(m,{kind:"permission-result",id:`perm-${e.requestId}`,title:l.title,detail:l.detail,optionName:u?.name,allowed:u?u.kind.startsWith("allow"):void 0,asked:l.questions?!0:void 0,answers:l.questions&&e.answers?DR(l.questions,e.answers):void 0,ts:s})}case"ls_driver":{if(n.driver===e.driver)return n;const l={...n,driver:e.driver};return n.driver===void 0?l:jt(l,{kind:"driver",id:`driver-${r}`,driver:e.driver,ts:s})}case"ls_error":return jt(Du(n,s),{kind:"error",id:`error-${r}`,code:e.code,message:e.message,hint:e.hint,ts:s});case"ls_notice":return jt(n,{kind:"notice",id:`notice-${r}`,level:e.level,title:e.title,detail:e.detail,ts:s});default:return n}}function kp(n){const e=[];for(const s of n){const r=e[e.length-1];s.type==="text"&&r?.type==="text"?e[e.length-1]={type:"text",text:r.text+s.text}:e.push(s)}return e}function MR(n,e){if(e.seq<=n.lastSeq)return n;const s=Ng(n,e.update,e.ts,String(e.seq));return s===n?{...n,lastSeq:e.seq}:{...s,lastSeq:e.seq}}function Dm(n,e){return e.reduce(MR,n)}function zR(n,e){if(n.lastSeq===0)return{...n,startSeq:e};if(n.lastSeq===e)return n;const s=n.items.filter(o=>o.kind==="user"&&(o.pending||o.failed)),r={};return s.forEach((o,l)=>{r[o.id]=l}),{...to(n.sessionId),startSeq:e,items:s,index:r}}const IR=new Set(["Tool","Sub-agent"]);function LR(n,e){if(n.kind==="agent"&&e.kind==="agent"){const s=[...n.attachments??[],...e.attachments??[]];return{...e,text:n.text+e.text,attachments:s.length?s:void 0,ts:n.ts}}if(n.kind==="thought"&&e.kind==="thought")return{...e,text:n.text+e.text,ts:n.ts};if(n.kind==="user"&&e.kind==="user"){const s=kp([...n.blocks,...e.blocks]);return{...e,blocks:s,agentMessages:dp(s),ts:n.ts}}return n.kind==="tool"&&e.kind==="tool"?{...e,title:IR.has(e.title)?n.title:e.title,toolKind:n.toolKind,rawInput:e.rawInput??n.rawInput,rawOutput:e.rawOutput??n.rawOutput,locations:e.locations??n.locations,detail:e.detail??n.detail,content:e.content.length?pE(n.content,e.content):n.content,output:n.output+e.output,sub:n.sub&&e.sub?mE(n.sub,e.sub):e.sub??n.sub,ts:n.ts,endedTs:e.endedTs??n.endedTs}:e}function mE(n,e){const s=[],r=new Set;for(const l of n.items){const u=e.index[l.id];u===void 0?s.push(l):(s.push(LR(l,e.items[u])),r.add(l.id))}for(const l of e.items)r.has(l.id)||s.push(l);const o={};return s.forEach((l,u)=>{o[l.id]=u}),{...e,items:s,index:o}}function UR(n,e,s){let r=to(n.sessionId);for(const o of e)r=Ng(r,o.update,o.ts,String(o.seq));return r=ud(r,e[e.length-1]?.ts??0),{...mE(r,n),startSeq:s}}function Eu(n,e,s,r=Date.now(),o=!1){return jt(n,{kind:"user",id:`local-${e}`,blocks:s,ts:r,pending:!0,...o?{accepted:!0}:{}})}function w1(n,e){const s=_n(n,`local-${e}`,"user");return s&&s.pending?jt(n,{...s,pending:!1,failed:!0}):n}function Np(n,e){const s=n.index[e];if(s===void 0)return n;const r=n.items.filter((l,u)=>u!==s),o={};return r.forEach((l,u)=>{o[l.id]=u}),{...n,items:r,index:o}}function pE(n,e){if(e.some(r=>r.type==="diff"))return e;const s=n.filter(r=>r.type==="diff");return s.length?[...s,...e]:e}const BR=1;function HR(n){const e=globalThis.WebSocket;if(!e)throw new Error("No WebSocket implementation available");return new e(n)}class $R{constructor(e){this.options=e}socket;peer;statusValue="idle";attempt=0;reconnectTimer;heartbeatTimer;subscriptions=new Map;waiters=new Set;statusListeners=new Set;eventListeners=new Set;summaryListeners=new Set;onlineListeners=new Set;restoredListeners=new Set;notificationListeners=new Map;lastError;get status(){return this.statusValue}onStatus(e){return this.statusListeners.add(e),()=>this.statusListeners.delete(e)}onEvent(e){return this.eventListeners.add(e),()=>this.eventListeners.delete(e)}onSummary(e){return this.summaryListeners.add(e),()=>this.summaryListeners.delete(e)}on(e,s){let r=this.notificationListeners.get(e);r||this.notificationListeners.set(e,r=new Set);const o=s;return r.add(o),()=>r.delete(o)}onOnline(e){return this.onlineListeners.add(e),()=>this.onlineListeners.delete(e)}start(){this.statusValue==="connecting"||this.statusValue==="online"||this.open()}stop(){this.setStatus("stopped"),this.reconnectTimer&&clearTimeout(this.reconnectTimer),this.heartbeatTimer&&clearInterval(this.heartbeatTimer),this.peer?.close("stopped"),this.socket?.close(),this.socket=void 0;for(const e of this.waiters)e()}reconnectNow(){this.statusValue!=="stopped"&&this.statusValue!=="online"&&(this.reconnectTimer&&clearTimeout(this.reconnectTimer),this.reconnectTimer=void 0,this.attempt=0,this.open())}async call(e,s,r){const o=r??this.options.requestTimeoutMs??3e4,l=Date.now()+o;if(await this.waitOnline(o>0?o:this.options.requestTimeoutMs||3e4),!this.peer||this.statusValue!=="online")throw da.app("offline","Not connected to the computer",{code:"offline"});return this.peer.request(e,s,o===0?0:Math.max(1e3,l-Date.now()))}onRestored(e){return this.restoredListeners.add(e),()=>this.restoredListeners.delete(e)}subscribe(e,s){return this.subscriptions.set(e,{cursor:s}),this.statusValue!=="online"?Promise.resolve(void 0):this.sendSubscribe(e).then(r=>r?.session)}unsubscribe(e){this.subscriptions.delete(e)&&this.statusValue==="online"&&this.peer?.request("sessions.unsubscribe",{sessionId:e}).catch(()=>{})}setStatus(e,s){if(s!==void 0&&(this.lastError=s),this.statusValue!==e){this.statusValue=e;for(const r of this.statusListeners)r(e,s)}}waitOnline(e){return this.statusValue==="online"||this.statusValue==="stopped"?Promise.resolve():new Promise(s=>{const r=()=>{clearTimeout(o),this.waiters.delete(r),s()},o=setTimeout(r,e);this.waiters.add(r)})}open(){this.setStatus(this.attempt===0?"connecting":"reconnecting");let e;try{e=(this.options.createSocket??HR)(this.options.url)}catch(o){this.scheduleReconnect(o instanceof Error?o.message:String(o));return}this.socket=e;const s=new BO({send:o=>{e.readyState===BR&&e.send(o)},onNotification:(o,l)=>this.onNotification(o,l),requestTimeoutMs:this.options.requestTimeoutMs??3e4});this.peer=s,e.onmessage=o=>{const l=o.data;s.receive(typeof l=="string"?l:String(l))};let r;e.onopen=()=>void this.onOpen(e),e.onerror=o=>{const l=o?.message;typeof l=="string"&&l&&(r=l)},e.onclose=()=>{this.socket===e&&(s.close("connection closed"),this.socket=void 0,this.heartbeatTimer&&clearInterval(this.heartbeatTimer),this.statusValue!=="stopped"&&this.scheduleReconnect(r??"连接已断开"))}}async onOpen(e){if(this.socket!==e)return;this.attempt=0,this.setStatus("online",""),await Promise.all([...this.subscriptions.keys()].map(r=>this.sendSubscribe(r).then(o=>{if(o?.session)for(const l of this.restoredListeners)l(o.session)})));for(const r of[...this.waiters])r();for(const r of this.onlineListeners)r();const s=this.options.heartbeatMs??25e3;s>0&&(this.heartbeatTimer&&clearInterval(this.heartbeatTimer),this.heartbeatTimer=setInterval(()=>{this.socket!==e||this.statusValue!=="online"||this.peer?.request("machine.info",{},1e4).catch(()=>{this.socket===e&&e.close()})},s))}sendSubscribe(e){const s=this.subscriptions.get(e);return!s||!this.peer?Promise.resolve(void 0):this.peer.request("sessions.subscribe",{sessionId:e,fromSeq:s.cursor(),lazyImages:this.options.lazyImages}).catch(()=>{})}scheduleReconnect(e){if(this.statusValue==="stopped")return;this.setStatus("reconnecting",e);const s=this.options.minBackoffMs??500,r=this.options.maxBackoffMs??15e3,o=Math.min(r,s*2**this.attempt)*(.8+Math.random()*.4);this.attempt+=1,this.reconnectTimer&&clearTimeout(this.reconnectTimer),this.reconnectTimer=setTimeout(()=>{this.reconnectTimer=void 0,this.open()},o)}onNotification(e,s){if(e==="session.event")for(const r of this.eventListeners)r(s);else if(e==="session.summary"){const r=s.session;if(r)for(const o of this.summaryListeners)o(r)}for(const r of this.notificationListeners.get(e)??[])r(s)}}function gE(n,e){return e.reduce((s,r)=>{const o=s[r.id];return o&&(o.lastSeq??0)>=(r.lastSeq??0)?s:{...s,[r.id]:r}},n)}function VR(n,e){return e.update.sessionUpdate==="ls_task"?gE(n,[{...e.update.task,lastSeq:e.seq}]):n}function Op(n,e){const s=n[e.toolCallId];return s&&s.lastSeq>=e.lastSeq?n:{...n,[e.toolCallId]:{...e,startedAt:e.workflow.startedAt??s?.startedAt??e.startedAt,workflow:{...s?.workflow,...e.workflow}}}}function qR(n,e){const s=e.update;if(s.sessionUpdate!=="tool_call"&&s.sessionUpdate!=="tool_call_update")return n;const r=n[s.toolCallId],o=s.detail?.type==="subagent"?s.detail:void 0;return o?.workflow?Op(n,{toolCallId:s.toolCallId,task:o.task??r?.task??s.title??"工作流",startedAt:r?.startedAt??e.ts,lastSeq:e.seq,workflow:o.workflow}):r&&!r.workflow.state&&s.status==="failed"?Op(n,{...r,lastSeq:e.seq,workflow:{...r.workflow,state:"failed",endedAt:e.ts}}):n}function PR(n,e){return e.reduce((s,r)=>r.workflow?Op(s,{toolCallId:r.toolCallId,task:r.task,startedAt:r.startedAt,lastSeq:r.lastSeq??0,workflow:r.workflow}):s,n)}function FR(n,e){const s=n??[];if(!e?.length)return s;const r=new Set(s.map(o=>o.clientMessageId));return[...s,...e.filter(o=>!r.has(o.clientMessageId))]}function Rp(n,e){return`${n}
|
|
155
155
|
${e}`}function S1(n,e,s){const r=s.update;if(r.toolCallId===e)return{...s,update:{...s.update,parentToolCallId:void 0}};if(r.parentToolCallId&&(r.parentToolCallId===e||kg(n,r.parentToolCallId)))return s}function GR(){const n=globalThis.crypto;return n?.randomUUID?n.randomUUID():`${Date.now().toString(36)}-${Math.random().toString(36).slice(2,10)}`}function ZR(n){return n instanceof da||n instanceof Error?n.message:String(n)}function YR(n,e={}){const s=e.newId??GR;let r=[],o;const l=()=>{if(o&&clearTimeout(o),o=void 0,r.length===0)return;const _=r;r=[],E.setState(j=>{let N=j.views,z=j.subagentViews,k=j.workflows,O=j.tasks;const M=new Map;for(const R of _){const L=O[R.sessionId]??{},H=VR(L,R);H!==L&&(O={...O,[R.sessionId]:H});const V=k[R.sessionId]??{},q=qR(V,R);q!==V&&(k={...k,[R.sessionId]:q});const P=M.get(R.sessionId)??[];P.push(R),M.set(R.sessionId,P);const J=`${R.sessionId}
|
|
156
156
|
`;for(const[ie,U]of d)ie.startsWith(J)&&U.push(R);for(const[ie,U]of Object.entries(z)){if(!ie.startsWith(J))continue;const G=S1(U,ie.slice(J.length),R);if(!G)continue;const W=Dm(U,[G]);W!==U&&(z={...z,[ie]:W})}}for(const[R,L]of M){const H=N[R];if(!H)continue;const V=Dm(H,L);V!==H&&(N={...N,[R]:V})}return N===j.views&&z===j.subagentViews&&k===j.workflows&&O===j.tasks?j:{views:N,subagentViews:z,workflows:k,tasks:O}})},u=_=>{const j=_.id;E.getState().open[j]&&(l(),E.setState(N=>({sessions:{...N.sessions,[j]:_},ready:{...N.ready,[j]:!0}})),E.getState().loadTasks(j).catch(()=>{}))},d=new Map,m=new Map,p=(_,j)=>{m.set(_,j),m.size>50&&m.delete(m.keys().next().value)},y=new Map,v=new Map;let b=0;const C=_=>{y.delete(_),b-=v.get(_)??0,v.delete(_)};function T(_){E.setState(j=>{const N=z=>{if(!(_ in z))return z;const k={...z};return delete k[_],k};return{sessions:N(j.sessions),notices:N(j.notices),views:N(j.views),open:N(j.open),ready:N(j.ready),loadingEarlier:N(j.loadingEarlier),queueing:N(j.queueing),subagents:N(j.subagents),workflows:N(j.workflows),tasks:N(j.tasks),subagentViews:Object.fromEntries(Object.entries(j.subagentViews).filter(([z])=>!z.startsWith(`${_}
|
|
157
157
|
`)))}})}const S=new Set,E=b2()((_,j)=>{const N=(k,O)=>_(M=>{const R=M.views[k]??to(k),L=O(R);return L===R?M:{views:{...M.views,[k]:L}}}),z=async(k,O=!1)=>{const M=j().outbox[k];if(!M)return"failed";try{const R=await n.call("sessions.prompt",{sessionId:M.sessionId,clientMessageId:k,content:M.content,whenBusy:O?void 0:"queue"});return R.delivery==="queued"&&p(k,M.content),_(L=>{const H={...L.outbox};return delete H[k],{outbox:H}}),R.delivery}catch{return N(M.sessionId,R=>w1(R,k)),"failed"}};return{status:n.status,sessions:{},notices:{},interactions:{},sessionsLoaded:!1,projects:[],views:{},open:{},ready:{},loadingEarlier:{},subagents:{},workflows:{},tasks:{},subagentViews:{},outbox:{},queueing:{},connect(){n.start()},disconnect(){n.stop()},dismissNotice(k,O){_(M=>({notices:{...M.notices,[k]:(M.notices[k]??[]).filter(R=>R.id!==O)}}))},async refresh(){n.call("agents.pending",{}).then(({interactions:k})=>{_(O=>{const M={...O.interactions};for(const{agent:R,request:L}of k)S.has(`${R}
|
|
158
158
|
${L.requestId}`)||M[R]?.some(H=>H.requestId===L.requestId)||(M[R]=[...M[R]??[],L]);return{interactions:M}})}).catch(()=>{});try{const[k,O,M]=await Promise.all([n.call("machine.info",{}),n.call("sessions.list",{limit:200}),n.call("projects.list",{limit:100})]);_(R=>{const L={...R.sessions};if(O.sessions.length<200){const H=new Set(O.sessions.map(V=>V.id));for(const[V,q]of Object.entries(L))!q.archived&&!H.has(V)&&delete L[V]}for(const H of O.sessions)L[H.id]=H;return{machine:k,sessions:L,projects:M.projects,sessionsLoaded:!0,sessionsError:void 0}})}catch(k){_({sessionsError:ZR(k)})}},openSession(k){j().open[k]||(_(O=>({open:{...O.open,[k]:!0},views:O.views[k]?O.views:{...O.views,[k]:to(k)}})),n.subscribe(k,()=>j().views[k]?.lastSeq??0).then(O=>{O&&u(O)}))},closeSession(k){j().open[k]&&(n.unsubscribe(k),_(O=>{const M={...O.open};delete M[k];const R={...O.ready};return delete R[k],{open:M,ready:R}}))},async send(k,O,M){const R=s(),L=j().sessions[k],H=!M?.now&&(L?.state==="running"||L?.state==="waiting"||(L?.queue?.length??0)>0);if(_(q=>({outbox:{...q.outbox,[R]:{sessionId:k,content:O}}})),H){const q={clientMessageId:R,text:O.map(P=>P.type==="text"?P.text:"").join("").trim(),images:O.filter(P=>P.type==="image").length,pending:!0};_(P=>({queueing:{...P.queueing,[k]:[...P.queueing[k]??[],q]}}))}else N(k,q=>Eu(q,R,O));const V=await z(R,M?.now);return H?(_(q=>{const P=(q.queueing[k]??[]).filter(ie=>ie.clientMessageId!==R),J={...q.queueing};return P.length>0?J[k]=P:delete J[k],{queueing:J}}),(V==="started"||V==="steered"||V==="failed")&&(N(k,q=>q.index[`local-${R}`]===void 0?Eu(q,R,O):q),V==="failed"&&N(k,q=>w1(q,R))),V):(V==="queued"&&N(k,q=>Np(q,`local-${R}`)),V)},async retry(k){const O=j().outbox[k];O&&(N(O.sessionId,M=>Eu(M,k,O.content)),await z(k))},discard(k){const O=j().outbox[k];O&&(N(O.sessionId,M=>Np(M,`local-${k}`)),_(M=>{const R={...M.outbox};return delete R[k],{outbox:R}}))},async respond(k,O,M){await n.call("sessions.permission",{sessionId:k,requestId:O,optionId:M})},async answer(k,O,M){await n.call("sessions.answer",{sessionId:k,requestId:O,answers:M})},async answerAsync(k,O,M){const R=s();if((await n.call("sessions.prompt",{sessionId:k,clientMessageId:R,content:[{type:"text",text:C2([{question:O,answer:M}])}]},3e4)).delivery==="queued")try{await n.call("sessions.sendQueued",{sessionId:k,clientMessageId:R},3e4)}catch(H){throw await n.call("sessions.unqueue",{sessionId:k,clientMessageId:R}).catch(()=>{}),H}},async cancel(k){await n.call("sessions.cancel",{sessionId:k})},async takeover(k){await n.call("sessions.takeover",{sessionId:k},6e4)},async release(k){await n.call("sessions.release",{sessionId:k})},async setConfig(k,O,M){await n.call("sessions.setConfig",{sessionId:k,optionId:O,value:M})},async unqueue(k,O){const{removed:M}=await n.call("sessions.unqueue",{sessionId:k,clientMessageId:O});return M&&m.delete(O),M},async takeQueued(k,O){const M=j().sessions[k]?.queue?.find(H=>H.clientMessageId===O),{removed:R}=await n.call("sessions.unqueue",{sessionId:k,clientMessageId:O});if(!R)return;const L=m.get(O)??(M?.text?[{type:"text",text:M.text}]:[]);return m.delete(O),L},async sendQueuedNow(k,O){const M=j().sessions[k]?.queue??[],R=O?M.find(H=>H.clientMessageId===O):M[0],L=R&&(m.get(R.clientMessageId)??(R.text?[{type:"text",text:R.text}]:[]));if(await n.call("sessions.sendQueued",{sessionId:k,clientMessageId:O},3e4),R&&L?.length){const H=R.clientMessageId;j().sessions[k]?.queue?.some(q=>q.clientMessageId===H)||N(k,q=>q.index[`local-${H}`]===void 0?Eu(q,H,L,Date.now(),!0):q)}},async reorderQueue(k,O){await n.call("sessions.reorderQueue",{sessionId:k,clientMessageIds:O})},async archive(k,O){const{session:M}=await n.call("sessions.archive",{sessionId:k,archived:O});_(R=>({sessions:{...R.sessions,[M.id]:M}}))},async rename(k,O){const{session:M}=await n.call("sessions.rename",{sessionId:k,title:O});_(R=>({sessions:{...R.sessions,[M.id]:M}}))},async deleteSession(k,O){await n.call("sessions.delete",{sessionId:k,worktree:O},6e4),T(k)},async forkSession(k,O){const{session:M}=await n.call("sessions.fork",{sessionId:k,itemId:O?.itemId,worktree:O?.worktree},9e4);return _(R=>({sessions:{...R.sessions,[M.id]:M}})),j().openSession(M.id),M},async gitInfo(k){return(await n.call("git.info",{path:k})).git},async listWorktrees(){return(await n.call("worktrees.list",{})).worktrees},async removeWorktree(k,O){await n.call("worktrees.remove",{path:k,force:O},6e4)},async loadArchived(){const k=await n.call("sessions.list",{limit:200,includeArchived:!0});_(O=>{const M={...O.sessions};for(const R of k.sessions)M[R.id]=R;return{sessions:M}})},async loadEarlier(k){const O=j().views[k]?.startSeq??0;if(O===0||j().loadingEarlier[k])return!1;_(M=>({loadingEarlier:{...M.loadingEarlier,[k]:!0}}));try{const M=await n.call("sessions.history",{sessionId:k,beforeSeq:O+1,lazyImages:e.lazyImages});return l(),j().views[k]?.startSeq!==O?!1:(N(k,R=>UR(R,M.events,M.startSeq)),!0)}catch{return!1}finally{_(M=>{const R={...M.loadingEarlier};return delete R[k],{loadingEarlier:R}})}},async loadTasks(k){const{tasks:O}=await n.call("sessions.tasks",{sessionId:k});return l(),_(M=>({tasks:{...M.tasks,[k]:gE(M.tasks[k]??{},O)}})),O},loadTaskOutput:(k,O,M)=>n.call("sessions.taskOutput",{sessionId:k,taskId:O,before:M}),async stopTask(k,O){await n.call("sessions.stopTask",{sessionId:k,taskId:O}),await j().loadTasks(k)},async loadSubagents(k){const{subagents:O}=await n.call("sessions.subagents",{sessionId:k});return l(),_(M=>({subagents:{...M.subagents,[k]:O},workflows:{...M.workflows,[k]:PR(M.workflows[k]??{},O)}})),O},async openSubagent(k,O){const M=Rp(k,O);if(d.has(M))return!1;const R=[];d.set(M,R);try{const{events:L}=await n.call("sessions.subagent",{sessionId:k,toolCallId:O,lazyImages:e.lazyImages},3e4);l();let H=to(k);for(const V of[...L,...R]){const q=S1(H,O,V);q&&(H=Dm(H,[q]))}return _(V=>({subagentViews:{...V.subagentViews,[M]:H}})),!0}catch{return!1}finally{d.delete(M)}},closeSubagent(k,O){const M=Rp(k,O);M in j().subagentViews&&_(R=>{const L={...R.subagentViews};return delete L[M],{subagentViews:L}})},loadImage(k,O){const M=`${k} ${O}`,R=y.get(M);if(R)return y.delete(M),y.set(M,R),R;const L=n.call("sessions.image",{sessionId:k,uri:O}).then(H=>{const V=`data:${H.mimeType};base64,${H.data}`;v.set(M,V.length),b+=V.length;const q=e.imageCacheChars??24*1024*1024;for(const P of y.keys()){if(b<=q||P===M)break;C(P)}return V},H=>{throw C(M),H});return y.set(M,L),L},async createSession(k){const{session:O}=await n.call("sessions.create",{agent:k.agent,cwd:k.cwd,worktree:k.worktree},6e4);return _(M=>({sessions:{...M.sessions,[O.id]:O}})),j().openSession(O.id),k.prompt&&k.prompt.length>0&&await j().send(O.id,k.prompt),O}}});return n.onStatus((_,j)=>{_!=="online"&&S.clear(),E.setState({status:_,statusDetail:j||void 0,..._!=="online"?{notices:{},interactions:{}}:{}})}),n.on("agent.interaction",({agent:_,request:j})=>{const N=`${_}
|
|
159
159
|
${j.requestId}`;"resolved"in j?S.add(N):S.delete(N),E.setState(z=>({interactions:{...z.interactions,[_]:"resolved"in j?(z.interactions[_]??[]).filter(k=>k.requestId!==j.requestId):[...(z.interactions[_]??[]).filter(k=>k.requestId!==j.requestId),j]}}))}),n.on("agent.changed",({agent:_})=>E.setState(j=>j.machine?{machine:{...j.machine,agents:j.machine.agents.map(N=>N.id===_.id?_:N)}}:{})),n.on("session.notice",({sessionId:_,notice:j})=>{E.setState(N=>({notices:{...N.notices,[_]:[...(N.notices[_]??[]).slice(-4),{...j,id:s()}]}}))}),n.on("session.removed",({sessionId:_})=>T(_)),n.on("session.window",({sessionId:_,startSeq:j})=>{l(),E.setState(N=>{const z=N.views[_];if(!z)return N;const k=zR(z,j);return k===z?N:{views:{...N.views,[_]:k}}})}),n.onSummary(_=>E.setState(j=>({sessions:{...j.sessions,[_.id]:_}}))),n.onEvent(_=>{r.push(_),o??=setTimeout(l,16)}),n.onRestored(_=>u(_)),n.onOnline(()=>{E.getState().refresh()}),E}const E1=0,Mm=1,Cu=3,C1=15e3;class KR{constructor(e,s,r){this.relay=e,this.machine=r;const o=_R(s,r,this.ch);this.cleanup.push(e.onFrame((l,u,d)=>{if(!(l.id!==r.id||d.ch!==this.ch))switch(d.k){case"welcome":try{this.channel=o.accept(d)}catch(m){this.fail(m instanceof Error?m.message:String(m));return}clearTimeout(this.timer),this.readyState=Mm,this.onopen?.({});return;case"data":{if(!this.channel)return;let m;try{m=this.channel.open(d.box)}catch{this.fail("the connection was tampered with");return}this.onmessage?.({data:m});return}case"refuse":this.fail(d.code==="not_paired"?"这台电脑不再信任这台设备,请重新配对":d.message,d.code);return;case"close":this.finish(1e3,d.reason??"closed");return;default:return}}),e.onUndeliverable((l,u)=>{l===r.id&&this.fail(u==="offline"?"电脑不在线":u==="not_allowed"?"没有权限连接这台电脑":u,u)}),e.onStatus(l=>{(l==="offline"||l==="stopped")&&this.fail("与网关的连接断开了")})),e.waitOnline(C1).then(l=>{if(this.readyState===E1){if(!l){this.fail(e.lastError?.message??"连不上网关");return}e.send(r.id,o.hello),this.timer=setTimeout(()=>this.fail("电脑没有响应"),C1)}})}readyState=E1;onopen=null;onclose=null;onerror=null;onmessage=null;ch=Qn(ld(12));channel;cleanup=[];timer;send(e){this.readyState!==Mm||!this.channel||this.relay.send(this.machine.id,{k:"data",ch:this.ch,box:this.channel.seal(e)})}close(){this.readyState!==Cu&&(this.readyState===Mm&&this.relay.send(this.machine.id,{k:"close",ch:this.ch}),this.finish(1e3,"closed"))}fail(e,s){this.readyState!==Cu&&(this.onerror?.({message:e,code:s}),this.finish(4e3,e))}finish(e,s){if(this.readyState!==Cu){this.readyState=Cu,clearTimeout(this.timer);for(const r of this.cleanup.splice(0))r();this.onclose?.({code:e,reason:s})}}}async function XR(n,e,s){const{machine:r}=await n.request("pair.claim",{machineId:oE(s.signKey),proof:cE(s.secret,cd(e))},4e4);if(r.signKey!==s.signKey)throw new Error("网关返回的电脑和二维码不一致,已拒绝");return r}async function QR(n,e,s){const r=s.replace(/\D/g,""),{machine:o}=await n.request("pair.claim",{code:r,proof:cE(vR(r),cd(e))},4e4);return o}const _1={encode(n){let e="";for(let s=0;s<n.length;s+=32768)e+=String.fromCharCode(...n.subarray(s,s+32768));return btoa(e)},decode(n){const e=atob(n),s=new Uint8Array(e.length);for(let r=0;r<e.length;r++)s[r]=e.charCodeAt(r);return s}};class WR{constructor(e,s){this.link=e,this.options=s,e.on("proxy.data",({streamId:r,data:o})=>this.relayed.get(r)?.data(_1.decode(o))),e.on("proxy.closed",({streamId:r,error:o})=>{const l=this.relayed.get(r);this.relayed.delete(r),l?.closed(o)}),e.onStatus(r=>{if(r==="online")return;this.dropRelayed("连接已断开");const o=this.connection;this.dropDirect(),o?.close()}),e.onOnline(()=>this.connect()),e.status==="online"&&this.connect()}pathValue="relay";connection;attempt=0;retryTimer;stopped=!1;pathListeners=new Set;relayed=new Map;directed=new Map;early=new Map;get path(){return this.pathValue}onPath(e){return this.pathListeners.add(e),()=>this.pathListeners.delete(e)}connect(){if(this.stopped||!this.options.connector||this.connection||this.link.status!=="online")return;const e=this.options.iceServers();if(!e)return;this.retryTimer&&clearTimeout(this.retryTimer),this.retryTimer=void 0;const s=this.options.connector(e);this.connection=s,this.setPath("connecting");let r=!1;const o=setTimeout(()=>!r&&this.lose(s),this.options.connectTimeoutMs??12e3);s.onMessage(l=>{const u=kR(l);u&&this.receive(u)}),s.onState(l=>{this.connection===s&&(l==="open"?(r=!0,clearTimeout(o),this.attempt=0,this.setPath("direct")):(clearTimeout(o),this.lose(s)))}),s.offer().then(l=>this.link.call("direct.offer",{sdp:l},2e4)).then(l=>s.accept(l.sdp)).catch(()=>{clearTimeout(o),this.lose(s)})}async open(e,s,r={}){const o=r.direct!==!1&&this.pathValue==="direct"?this.connection:void 0,l=await this.link.call("proxy.open",{port:e,direct:o?!0:void 0}),{streamId:u}=l;if(l.channel!==void 0&&o&&this.connection===o){const m=l.channel;this.directed.set(m,s);for(const y of this.early.get(m)??[])this.receive(y);this.early.delete(m);let p=!1;return{direct:!0,write:y=>{if(!(p||this.connection!==o))for(let v=0;v<y.length;v+=v1)o.send(y1({type:"data",stream:m,data:y.subarray(v,v+v1)}))},close:()=>{p||(p=!0,this.directed.delete(m)&&this.connection===o&&o.send(y1({type:"close",stream:m})))}}}if(l.channel!==void 0)throw new Error("直连中断了");this.relayed.set(u,s);let d=!1;return{direct:!1,write:m=>{d||this.link.call("proxy.write",{streamId:u,data:_1.encode(m)}).catch(()=>{this.relayed.delete(u)&&s.closed("发送失败")})},close:()=>{d||(d=!0,this.relayed.delete(u)&&this.link.call("proxy.close",{streamId:u}).catch(()=>{}))}}}start(){this.stopped=!1,this.connect()}stop(){this.stopped=!0,this.retryTimer&&clearTimeout(this.retryTimer),this.retryTimer=void 0,this.dropRelayed();const e=this.connection;this.dropDirect(),e?.close()}receive(e){const s=this.directed.get(e.stream);if(!s){const r=this.early.get(e.stream)??[];r.length<64&&this.early.size<32&&this.early.set(e.stream,[...r,e]);return}e.type==="data"?s.data(e.data):(this.directed.delete(e.stream),s.closed(e.error))}setPath(e){if(this.pathValue!==e){this.pathValue=e;for(const s of this.pathListeners)s(e)}}lose(e){if(this.connection!==e||(this.dropDirect(),e.close(),this.stopped||this.link.status!=="online"))return;const s=this.options.retryMs??[5e3,2e4,6e4],r=s[Math.min(this.attempt,s.length-1)];this.attempt+=1,this.retryTimer=setTimeout(()=>{this.retryTimer=void 0,this.connect()},r)}dropDirect(){this.connection=void 0;const e=[...this.directed.values()];this.directed.clear(),this.early.clear(),this.setPath("relay");for(const s of e)s.closed("直连中断了")}dropRelayed(e){const s=[...this.relayed.values()];this.relayed.clear();for(const r of s)r.closed(e)}}class JR{constructor(e,s,r,o,l){this.link=e,this.streams=s,this.sessionId=r,this.onFrame=o,this.last=l,this.remove=[e.onStatus(u=>{u==="online"?this.open():this.drop()}),s.onPath(u=>{u==="direct"&&!this.stream?.direct&&this.open()})],e.status==="online"&&this.open()}stream;generation=0;stopped=!1;retry;remove;last;drop(){this.generation++,this.retry&&clearTimeout(this.retry),this.retry=void 0;const e=this.stream;this.stream=void 0,e?.close()}open(){if(this.stopped||this.link.status!=="online")return;this.drop();const e=this.generation,s=new OR,r=()=>{this.stopped||e!==this.generation||(this.drop(),this.retry=setTimeout(()=>this.open(),3e3))};this.link.call("sessions.preview",{sessionId:this.sessionId,direct:this.streams.path==="direct"}).then(async o=>{if(this.stopped||e!==this.generation)return;const l=await this.streams.open(o.port,{data:u=>{if(!(this.stopped||e!==this.generation))try{for(const d of s.push(u))this.last=d.id,this.onFrame(d),this.stream?.write(new TextEncoder().encode(`ack
|
|
160
160
|
`))}catch{r()}},closed:r});if(this.stopped||e!==this.generation){l.close();return}this.stream=l,l.write(new TextEncoder().encode(JSON.stringify({token:o.token,after:this.last,direct:l.direct})+`
|
|
161
|
-
`))}).catch(o=>{o?.code!==-32601&&r()})}close(){this.stopped=!0,this.drop();for(const e of this.remove)e()}}const eD="https://mkbeusztkzffnzjdwmqk.supabase.co",tD="eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJzdXBhYmFzZSIsInJlZiI6Im1rYmV1c3p0a3pmZm56amR3bXFrIiwicm9sZSI6ImFub24iLCJpYXQiOjE3NjU5Nzc0NzgsImV4cCI6MjA4MTU1MzQ3OH0.2wlT6q6687Z5rpEYsdp01IQpNNl_XWv0IAfBgwPyDP0";let nD;function wl(){return nD??=Mj(window.__LINKSHELL_CONFIG__?.account?.url??eD,window.__LINKSHELL_CONFIG__?.account?.anonKey??tD,{auth:{persistSession:!0,autoRefreshToken:!0,detectSessionInUrl:!0,flowType:"pkce",storageKey:"linkshell.web.account.v2"}})}async function aD(){const n=wl().auth,{data:e,error:s}=await n.getSession();if(s)throw s;if(!e.session)return;if((e.session.expires_at??0)*1e3>Date.now()+12e4)return e.session.access_token;const r=await n.refreshSession();if(r.error)throw r.error;if(!r.data.session)throw new Error("登录已失效,请重新登录");return r.data.session.access_token}function Ks(n,e){try{return JSON.parse(localStorage.getItem(`linkshell.web.${n}`)??"null")??e}catch{return e}}function fa(n,e){localStorage.setItem(`linkshell.web.${n}`,JSON.stringify(e))}let sD;function rD(){return sD??=new Promise((n,e)=>{const s=indexedDB.open("linkshell.web.identity",1);s.onupgradeneeded=()=>s.result.createObjectStore("keys"),s.onerror=()=>e(new Error("无法保存浏览器设备身份,请允许此网站使用本地存储")),s.onsuccess=()=>{const r=s.result,o=r.transaction("keys","readwrite"),l=o.objectStore("keys"),u=l.get("device");let d;u.onsuccess=()=>{d=u.result??mR(),u.result||l.put(d,"device")},o.oncomplete=()=>{r.close(),n(d)},o.onerror=()=>{r.close(),e(new Error("设备身份保存失败"))}}})}const iD=n=>{const e=new RTCPeerConnection({iceServers:n.map(r=>({urls:r}))}),s=e.createDataChannel(TR,{ordered:!0});return s.binaryType="arraybuffer",{async offer(){if(await e.setLocalDescription(await e.createOffer()),e.iceGatheringState!=="complete"&&await new Promise(r=>{const o=()=>{clearTimeout(u),e.removeEventListener("icegatheringstatechange",l),r()},l=()=>{e.iceGatheringState==="complete"&&o()},u=setTimeout(o,2e3);e.addEventListener("icegatheringstatechange",l)}),!e.localDescription?.sdp)throw new Error("无法建立直连通道");return e.localDescription.sdp},accept:r=>e.setRemoteDescription({type:"answer",sdp:r}),send(r){s.send(r)},onState(r){s.addEventListener("open",()=>r("open")),s.addEventListener("close",()=>r("closed")),e.addEventListener("connectionstatechange",()=>{["failed","closed"].includes(e.connectionState)&&r("closed")})},onMessage(r){s.addEventListener("message",o=>{o.data instanceof ArrayBuffer&&r(new Uint8Array(o.data))})},close(){e.close()}}},oD=Ks("source",Zs),vE=Zs==="self-hosted"?"self-hosted":oD,lD=vE==="official"?jr:Ks("gateway",C6);class cD{state=b2(()=>({source:vE,gateway:lD,computers:[],relayStatus:{},locked:!1,ready:!1}));identity;relays=new Map;paired=Ks("paired",[]);selected=Ks("selected","");releaseLock;starting;authUser;authSubscribed=!1;generation=0;channel=typeof BroadcastChannel<"u"?new BroadcastChannel("linkshell.web.owner"):void 0;constructor(){this.channel?.addEventListener("message",e=>{e.data==="yield"&&(this.stop(),this.state.setState({locked:!0}))}),window.addEventListener("pagehide",()=>this.stop()),window.addEventListener("pageshow",()=>{this.start()}),window.addEventListener("online",()=>this.reconnect()),document.addEventListener("visibilitychange",()=>{document.hidden||this.reconnect()})}report(e){this.state.setState({error:e instanceof Error?e.message:String(e)})}async start(){return this.releaseLock||this.starting?this.starting:(this.starting=this.acquire(!1).finally(()=>{this.starting=void 0}),this.starting)}async claim(){this.channel?.postMessage("yield"),await this.acquire(!0)}async acquire(e){if(!navigator.locks){this.report(new Error("此浏览器不支持设备连接锁,请使用最新版 Chrome、Edge、Safari 或 Firefox"));return}await new Promise((s,r)=>{navigator.locks.request("linkshell.web.connection",{ifAvailable:!e},async o=>{if(!o){this.state.setState({locked:!0,ready:!0}),s();return}await new Promise(l=>{this.releaseLock=l,this.state.setState({locked:!1}),this.boot().then(s,r)})}).catch(r)}).catch(s=>this.report(s))}async boot(){const e=++this.generation;if(this.identity=await rD(),e===this.generation){this.state.setState({computers:this.paired.map(s=>({...s,machine:{...s.machine,online:!1}})),ready:!0});for(const s of this.paired)this.relay(s.gateway);this.state.getState().source==="official"?await this.connectAccount():this.state.getState().gateway&&this.relay(Sm(this.state.getState().gateway))}}async connectAccount(){if(Zs==="self-hosted")throw new Error("私有部署使用设备配对");const e=wl().auth,{data:s,error:r}=await e.getSession();if(r)throw r;this.authUser=s.session?.user.id,this.state.setState({account:s.session?.user.email,source:"official",gateway:jr}),this.authSubscribed||(this.authSubscribed=!0,e.onAuthStateChange((o,l)=>{const u=this.authUser!==l?.user.id;this.authUser=l?.user.id,this.state.setState({account:l?.user.email}),u&&this.releaseLock&&setTimeout(()=>{this.relays.get(jr)?.reauthenticate(),l&&this.relay(jr)},0)})),fa("source","official"),s.session&&this.relay(jr).reauthenticate()}relay(e){if(!this.identity||!this.releaseLock)throw new Error("请先在本标签页启用连接");const s=Sm(e),r=this.relays.get(s);if(r)return r;const o=s===jr&&Zs!=="self-hosted",l=new AR({url:s+wR,identity:this.identity,role:"device",name:"LinkShell Web",platform:"web",token:o?async()=>{try{return await aD()}catch(u){throw this.report(u),u}}:void 0,createSocket:u=>{const d=new WebSocket(u),m=d.send.bind(d);return d.send=p=>{if(typeof p=="string"&&o&&this.authUser){const y=JSON.parse(p);if(y.t==="auth"&&!y.token){d.close(4001,"账号续期失败,正在重试");return}}m(p)},d}});return this.relays.set(s,l),l.onStatus((u,d)=>{this.state.setState(m=>({relayStatus:{...m.relayStatus,[s]:u},...d?{error:d.message}:{}})),u==="online"&&this.refresh(s).catch(m=>this.report(m))}),l.on("machines.changed",()=>{this.refresh(s).catch(u=>this.report(u))}),l.on("presence",({id:u,online:d})=>this.state.setState(m=>({computers:m.computers.map(p=>p.gateway===s&&p.machine.id===u?{...p,machine:{...p.machine,online:d}}:p)}))),l.start(),l}async refresh(e){const s=this.relays.get(e);if(!s)return;const{machines:r}=await s.request("machines.list",{}),o=r.map(u=>({gateway:e,machine:u,key:`${e}#${u.id}`}));this.state.setState(u=>({computers:[...u.computers.filter(d=>d.gateway!==e),...o]}));const l=this.state.getState();if(!l.connection){const u=l.computers.find(d=>d.key===this.selected)??l.computers.find(d=>d.machine.online);u&&this.select(u)}}select(e){if(!this.identity)throw new Error("设备身份尚未就绪");this.disconnect();const s=this.identity,r=this.relay(e.gateway),o=new $R({url:e.key,createSocket:()=>new KR(r,s,e.machine),lazyImages:!0}),l=YR(o,{lazyImages:!0}),u=new WR(o,{connector:iD,iceServers:()=>l.getState().machine?.direct?.iceServers});l.subscribe((d,m)=>{d.machine!==m.machine&&u.connect()}),this.state.setState({connection:{computer:e,link:o,store:l,streams:u},error:void 0}),this.selected=e.key,fa("selected",e.key),l.getState().connect(),u.start()}async pair(e,s){const r=s.trim().startsWith("linkshell:")?uE(s.trim()):void 0;if(s.trim().startsWith("linkshell:")&&!r)throw new Error("配对链接格式不正确");if(!r&&!/^\d{6}$/.test(s.trim()))throw new Error("请输入 6 位配对码");const o=Sm((r?.gateway??e).replace(/^http/,"ws")),l=this.relay(o),u=r?await XR(l,this.identity,r):await QR(l,this.identity,s.trim()),d={key:`${o}#${u.id}`,gateway:o,machine:u};this.paired=[...this.paired.filter(m=>m.key!==d.key),d],fa("paired",this.paired),fa("source","self-hosted"),fa("gateway",o),this.state.setState({source:"self-hosted",gateway:o}),await this.refresh(o),this.select(d)}async forget(e){await this.relay(e.gateway).request("machines.forget",{machineId:e.machine.id}),this.paired=this.paired.filter(s=>s.key!==e.key),fa("paired",this.paired),this.state.getState().connection?.computer.key===e.key&&this.disconnect(),this.state.setState(s=>({computers:s.computers.filter(r=>r.key!==e.key)}))}reconnect(){if(this.releaseLock){for(const e of this.relays.values())e.reconnectNow();this.state.getState().connection?.link.reconnectNow()}}disconnect(){const e=this.state.getState().connection;e?.streams.stop(),e?.store.getState().disconnect(),this.state.setState({connection:void 0})}stop(){this.generation++,this.disconnect();for(const e of this.relays.values())e.stop();this.relays.clear(),this.releaseLock?.(),this.releaseLock=void 0}}const Qt=new cD,uD={codex:{svg:'<svg viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg"><path d="M19.503 0H4.496A4.496 4.496 0 000 4.496v15.007A4.496 4.496 0 004.496 24h15.007A4.496 4.496 0 0024 19.503V4.496A4.496 4.496 0 0019.503 0z" fill="#fff"></path><path d="M9.064 3.344a4.578 4.578 0 012.285-.312c1 .115 1.891.54 2.673 1.275.01.01.024.017.037.021a.09.09 0 00.043 0 4.55 4.55 0 013.046.275l.047.022.116.057a4.581 4.581 0 012.188 2.399c.209.51.313 1.041.315 1.595a4.24 4.24 0 01-.134 1.223.123.123 0 00.03.115c.594.607.988 1.33 1.183 2.17.289 1.425-.007 2.71-.887 3.854l-.136.166a4.548 4.548 0 01-2.201 1.388.123.123 0 00-.081.076c-.191.551-.383 1.023-.74 1.494-.9 1.187-2.222 1.846-3.711 1.838-1.187-.006-2.239-.44-3.157-1.302a.107.107 0 00-.105-.024c-.388.125-.78.143-1.204.138a4.441 4.441 0 01-1.945-.466 4.544 4.544 0 01-1.61-1.335c-.152-.202-.303-.392-.414-.617a5.81 5.81 0 01-.37-.961 4.582 4.582 0 01-.014-2.298.124.124 0 00.006-.056.085.085 0 00-.027-.048 4.467 4.467 0 01-1.034-1.651 3.896 3.896 0 01-.251-1.192 5.189 5.189 0 01.141-1.6c.337-1.112.982-1.985 1.933-2.618.212-.141.413-.251.601-.33.215-.089.43-.164.646-.227a.098.098 0 00.065-.066 4.51 4.51 0 01.829-1.615 4.535 4.535 0 011.837-1.388zm3.482 10.565a.637.637 0 000 1.272h3.636a.637.637 0 100-1.272h-3.636zM8.462 9.23a.637.637 0 00-1.106.631l1.272 2.224-1.266 2.136a.636.636 0 101.095.649l1.454-2.455a.636.636 0 00.005-.64L8.462 9.23z" fill="url(#lobe-icons-codex-_R_0_)"></path><defs><linearGradient gradientUnits="userSpaceOnUse" id="lobe-icons-codex-_R_0_" x1="12" x2="12" y1="3" y2="21"><stop stop-color="#B1A7FF"></stop><stop offset=".5" stop-color="#7A9DFF"></stop><stop offset="1" stop-color="#3941FF"></stop></linearGradient></defs></svg>',full:!0},gemini:{svg:'<svg viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg"><path d="M0 4.391A4.391 4.391 0 014.391 0h15.217A4.391 4.391 0 0124 4.391v15.217A4.391 4.391 0 0119.608 24H4.391A4.391 4.391 0 010 19.608V4.391z" fill="url(#lobe-icons-gemini-cli-_R_0_)"></path><path clip-rule="evenodd" d="M19.74 1.444a2.816 2.816 0 012.816 2.816v15.48a2.816 2.816 0 01-2.816 2.816H4.26a2.816 2.816 0 01-2.816-2.816V4.26A2.816 2.816 0 014.26 1.444h15.48zM7.236 8.564l7.752 3.728-7.752 3.727v2.802l9.557-4.596v-3.866L7.236 5.763v2.801z" fill="#1E1E2E" fill-rule="evenodd"></path><defs><linearGradient gradientUnits="userSpaceOnUse" id="lobe-icons-gemini-cli-_R_0_" x1="24" x2="0" y1="6.587" y2="16.494"><stop stop-color="#EE4D5D"></stop><stop offset=".328" stop-color="#B381DD"></stop><stop offset=".476" stop-color="#207CFE"></stop></linearGradient></defs></svg>',full:!0},claude:{svg:'<svg viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg"><path clip-rule="evenodd" d="M20.998 10.949H24v3.102h-3v3.028h-1.487V20H18v-2.921h-1.487V20H15v-2.921H9V20H7.488v-2.921H6V20H4.487v-2.921H3V14.05H0V10.95h3V5h17.998v5.949zM6 10.949h1.488V8.102H6v2.847zm10.51 0H18V8.102h-1.49v2.847z" fill="#D97757" fill-rule="evenodd"></path></svg>',full:!1,bg:{light:"#F4F1EA",dark:"#2A2926"}},copilot:{svg:'<svg fill="currentColor" fill-rule="evenodd" viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg"><path d="M19.245 5.364c1.322 1.36 1.877 3.216 2.11 5.817.622 0 1.2.135 1.592.654l.73.964c.21.278.323.61.323.955v2.62c0 .339-.173.669-.453.868C20.239 19.602 16.157 21.5 12 21.5c-4.6 0-9.205-2.583-11.547-4.258-.28-.2-.452-.53-.453-.868v-2.62c0-.345.113-.679.321-.956l.73-.963c.392-.517.974-.654 1.593-.654l.029-.297c.25-2.446.81-4.213 2.082-5.52 2.461-2.54 5.71-2.851 7.146-2.864h.198c1.436.013 4.685.323 7.146 2.864zm-7.244 4.328c-.284 0-.613.016-.962.05-.123.447-.305.85-.57 1.108-1.05 1.023-2.316 1.18-2.994 1.18-.638 0-1.306-.13-1.851-.464-.516.165-1.012.403-1.044.996a65.882 65.882 0 00-.063 2.884l-.002.48c-.002.563-.005 1.126-.013 1.69.002.326.204.63.51.765 2.482 1.102 4.83 1.657 6.99 1.657 2.156 0 4.504-.555 6.985-1.657a.854.854 0 00.51-.766c.03-1.682.006-3.372-.076-5.053-.031-.596-.528-.83-1.046-.996-.546.333-1.212.464-1.85.464-.677 0-1.942-.157-2.993-1.18-.266-.258-.447-.661-.57-1.108-.32-.032-.64-.049-.96-.05zm-2.525 4.013c.539 0 .976.426.976.95v1.753c0 .525-.437.95-.976.95a.964.964 0 01-.976-.95v-1.752c0-.525.437-.951.976-.951zm5 0c.539 0 .976.426.976.95v1.753c0 .525-.437.95-.976.95a.964.964 0 01-.976-.95v-1.752c0-.525.437-.951.976-.951zM7.635 5.087c-1.05.102-1.935.438-2.385.906-.975 1.037-.765 3.668-.21 4.224.405.394 1.17.657 1.995.657h.09c.649-.013 1.785-.176 2.73-1.11.435-.41.705-1.433.675-2.47-.03-.834-.27-1.52-.63-1.813-.39-.336-1.275-.482-2.265-.394zm6.465.394c-.36.292-.6.98-.63 1.813-.03 1.037.24 2.06.675 2.47.968.957 2.136 1.104 2.776 1.11h.044c.825 0 1.59-.263 1.995-.657.555-.556.765-3.187-.21-4.224-.45-.468-1.335-.804-2.385-.906-.99-.088-1.875.058-2.265.394zM12 7.615c-.24 0-.525.015-.84.044.03.16.045.336.06.526l-.001.159a2.94 2.94 0 01-.014.25c.225-.022.425-.027.612-.028h.366c.187 0 .387.006.612.028-.015-.146-.015-.277-.015-.409.015-.19.03-.365.06-.526a9.29 9.29 0 00-.84-.044z"></path></svg>',full:!1,bg:{light:"#0D1117",dark:"#F0F3F6"},fg:{light:"#FFFFFF",dark:"#0D1117"}},grok:{svg:'<svg fill="currentColor" fill-rule="evenodd" viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg"><path d="M9.27 15.29l7.978-5.897c.391-.29.95-.177 1.137.272.98 2.369.542 5.215-1.41 7.169-1.951 1.954-4.667 2.382-7.149 1.406l-2.711 1.257c3.889 2.661 8.611 2.003 11.562-.953 2.341-2.344 3.066-5.539 2.388-8.42l.006.007c-.983-4.232.242-5.924 2.75-9.383.06-.082.12-.164.179-.248l-3.301 3.305v-.01L9.267 15.292M7.623 16.723c-2.792-2.67-2.31-6.801.071-9.184 1.761-1.763 4.647-2.483 7.166-1.425l2.705-1.25a7.808 7.808 0 00-1.829-1A8.975 8.975 0 005.984 5.83c-2.533 2.536-3.33 6.436-1.962 9.764 1.022 2.487-.653 4.246-2.34 6.022-.599.63-1.199 1.259-1.682 1.925l7.62-6.815"></path></svg>',full:!1,bg:{light:"#000000",dark:"#FFFFFF"},fg:{light:"#FFFFFF",dark:"#000000"}},opencode:{svg:'<svg fill="currentColor" fill-rule="evenodd" viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg"><path d="M16 6H8v12h8V6zm4 16H4V2h16v20z"></path></svg>',full:!1,bg:{light:"#131010",dark:"#F1ECEC"},fg:{light:"#F1ECEC",dark:"#131010"}},cursor:{svg:'<svg fill="currentColor" fill-rule="evenodd" viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg"><path d="M22.106 5.68L12.5.135a.998.998 0 00-.998 0L1.893 5.68a.84.84 0 00-.419.726v11.186c0 .3.16.577.42.727l9.607 5.547a.999.999 0 00.998 0l9.608-5.547a.84.84 0 00.42-.727V6.407a.84.84 0 00-.42-.726zm-.603 1.176L12.228 22.92c-.063.108-.228.064-.228-.061V12.34a.59.59 0 00-.295-.51l-9.11-5.26c-.107-.062-.063-.228.062-.228h18.55c.264 0 .428.286.296.514z"></path></svg>',full:!1,bg:{light:"#14120B",dark:"#EDECEC"},fg:{light:"#EDECEC",dark:"#14120B"}}},yE=x.createContext(null);function yt(){const n=x.useContext(yE);if(!n)throw new Error("尚未连接电脑");return n}function lt(n){return Md(yt().store,n)}function pn(){return yt().store.getState()}const bE=n=>n instanceof Error?n.message:String(n),dd=n=>n.replace(/\/$/,"").split("/").pop()??n,Tr=n=>n.title||dd(n.cwd)||"未命名会话",dD=n=>({idle:"已完成",waiting:"需要你",running:"进行中",error:"出错",offline:"离线",completed:"已完成",failed:"失败",stopped:"已停止",pending:"等待中",active:"进行中",paused:"已暂停",complete:"已完成",blocked:"待处理",usageLimited:"用量受限",budgetLimited:"预算已用完",unknown:"未知"})[n]??n;function Bd({agent:n}){const e=uD[n.toLowerCase()];return f.jsx("span",{className:`agent-mark ${n.toLowerCase()} ${e?.full?"full-mark":""}`,children:e?f.jsx("img",{src:`data:image/svg+xml,${encodeURIComponent(e.svg.replaceAll("currentColor",e.fg?.light??"#333"))}`,alt:n}):n.slice(0,1).toUpperCase()})}function $r({state:n}){return f.jsxs("span",{className:`badge ${n==="idle"||n==="completed"?"done":n}`,children:[f.jsx("span",{className:"status-dot"}),dD(n)]})}function xt({error:n}){return n?f.jsx("p",{role:"alert",className:"form-error",children:n}):null}function Rl({title:n,children:e,close:s,wide:r=!1,returnFocus:o}){return f.jsx(f2,{open:!0,onOpenChange:l=>{l||s()},children:f.jsxs(h2,{onCloseAutoFocus:o?l=>{l.preventDefault(),o()}:void 0,className:Pe("max-h-[85dvh] overflow-y-auto p-6 sm:max-w-xl",r&&"sm:max-w-5xl"),children:[f.jsxs(m2,{children:[f.jsx(p2,{children:n}),f.jsxs(g2,{className:"sr-only",children:[n,"设置与操作"]})]}),e]})})}function Nt(){const[n,e]=x.useState(),[s,r]=x.useState(!1),o=x.useRef(!1);async function l(u){if(!o.current){o.current=!0,r(!0),e(void 0);try{return await u()}catch(d){e(bE(d))}finally{o.current=!1,r(!1)}}}return{error:n,busy:s,run:l,clear:()=>e(void 0)}}function ta(n,e,s=0){const[r,o]=x.useState({loading:!0}),[l,u]=x.useState(0),d=x.useRef(n);return d.current=n,x.useEffect(()=>{let m=!0,p=!1;const y=async()=>{if(!p){p=!0;try{const b=await d.current();m&&o({value:b,loading:!1})}catch(b){m&&o(C=>({...C,error:bE(b),loading:!1}))}finally{p=!1}}};o({loading:!0}),y();const v=s?setInterval(()=>void y(),s):void 0;return()=>{m=!1,clearInterval(v)}},[...e,l,s]),{...r,reload:()=>u(m=>m+1)}}function Sa({loading:n,error:e}){return f.jsxs(f.Fragment,{children:[n&&f.jsx("p",{className:"muted loading-copy",role:"status",children:"正在加载…"}),f.jsx(xt,{error:e})]})}function fD({found:n}){const e=x.useRef(null),[s,r]=x.useState(!1),[o,l]=x.useState(),u=x.useRef(n);u.current=n;function d(p){if(!uE(p)){l("这不是有效的 LinkShell 配对二维码");return}u.current(p),r(!1),l(void 0)}const m=x.useRef(d);return m.current=d,x.useEffect(()=>{if(!s||!e.current)return;let p=!1,y;return up(()=>import("./qr-scanner.min-3SiDiDF1.js"),__vite__mapDeps([0,1,2,3,4])).then(async({default:v})=>{p||!e.current||(y=new v(e.current,b=>m.current(b.data),{preferredCamera:"environment",returnDetailedScanResult:!0,highlightScanRegion:!0}),await y.start())}).catch(v=>{p||(l(v instanceof Error?v.message:"无法打开摄像头,请使用图片或配对码"),r(!1))}),()=>{p=!0,y?.destroy()}},[s]),f.jsxs("div",{className:"qr-scan",children:[f.jsxs("div",{className:"permission-buttons",children:[f.jsx("button",{className:"button secondary",type:"button",onClick:()=>r(!s),children:s?"关闭摄像头":"扫描二维码"}),f.jsxs("label",{className:"button secondary",children:["从图片识别",f.jsx("input",{type:"file",accept:"image/*",hidden:!0,onChange:p=>{const y=p.target.files?.[0];p.target.value="",y&&up(()=>import("./qr-scanner.min-3SiDiDF1.js"),__vite__mapDeps([0,1,2,3,4])).then(v=>v.default.scanImage(y,{returnDetailedScanResult:!0})).then(v=>d(v.data),()=>l("没有识别到二维码,请换一张图片或输入配对码"))}})]})]}),s&&f.jsx("video",{ref:e,className:"qr-video",muted:!0,playsInline:!0}),f.jsx(xt,{error:o})]})}function hD({close:n}){const e=Md(Qt.state),[s,r]=x.useState(e.source),[o,l]=x.useState(""),[u,d]=x.useState(""),[m,p]=x.useState(s==="self-hosted"?e.gateway:""),[y,v]=x.useState(""),b=Nt();return f.jsxs(Rl,{title:"连接你的电脑",close:n,children:[f.jsx("p",{className:"muted modal-subtitle",children:"电脑保持运行,网页即可继续你的会话。"}),Zs==="official"&&f.jsxs("div",{className:"source-options",children:[f.jsxs("button",{className:`source-option ${s==="official"?"selected":""}`,"aria-pressed":s==="official",onClick:()=>r("official"),children:[f.jsx(Tt,{name:"globe"}),f.jsx("strong",{children:"官方账号"}),f.jsx("span",{children:"同一 iTool 账号发现电脑"})]}),f.jsxs("button",{className:`source-option ${s==="self-hosted"?"selected":""}`,"aria-pressed":s==="self-hosted",onClick:()=>r("self-hosted"),children:[f.jsx(Tt,{name:"server"}),f.jsx("strong",{children:"配对电脑"}),f.jsx("span",{children:"官方或自托管网关的配对码"})]})]}),s==="official"?f.jsxs("form",{className:"new-form",onSubmit:C=>{C.preventDefault(),b.run(async()=>{const T=await wl().auth.signInWithPassword({email:o.trim(),password:u});if(T.error)throw T.error;await Qt.connectAccount(),n()})},children:[e.account?f.jsx("div",{className:"private-note",children:f.jsxs("div",{children:[f.jsx("strong",{children:e.account}),f.jsx("p",{children:"电脑端运行 linkshell login,使用同一账号。电脑接入官方网关需要 Pro 订阅。"}),f.jsx("button",{type:"button",className:"text-button",onClick:()=>void b.run(async()=>{await Qt.connectAccount(),n()}),children:"刷新账号电脑"})]})}):f.jsxs(f.Fragment,{children:[f.jsx("label",{htmlFor:"email",children:"邮箱"}),f.jsx("input",{id:"email",type:"email",autoComplete:"username",value:o,onChange:C=>l(C.target.value),required:!0}),f.jsx("label",{htmlFor:"password",children:"密码"}),f.jsx("input",{id:"password",type:"password",autoComplete:"current-password",value:u,onChange:C=>d(C.target.value),required:!0}),f.jsx("button",{className:"button primary full",disabled:b.busy,children:"登录"}),f.jsx("div",{className:"form-columns",children:["github","google"].map(C=>f.jsx("button",{type:"button",className:"button secondary",disabled:b.busy,onClick:()=>void b.run(async()=>{const T=await wl().auth.signInWithOAuth({provider:C,options:{redirectTo:location.origin+location.pathname}});if(T.error)throw T.error}),children:C==="github"?"GitHub 登录":"Google 登录"},C))}),f.jsxs("p",{className:"field-hint",children:["登录状态自动续期。",f.jsx("a",{href:"https://itool.tech/zh/register",target:"_blank",rel:"noreferrer",children:"注册 iTool 账号 ↗"})]})]}),e.account&&f.jsx("button",{type:"button",className:"button secondary full",disabled:b.busy,onClick:()=>void b.run(async()=>{const C=await wl().auth.signOut({scope:"local"});if(C.error)throw C.error;Qt.disconnect()}),children:"退出本浏览器账号"})]}):f.jsxs("form",{className:"pairing-form",onSubmit:C=>{C.preventDefault(),b.run(async()=>{await Qt.pair(m,y),n()})},children:[f.jsx(fD,{found:v}),f.jsx("label",{htmlFor:"gateway",children:"网关地址"}),f.jsx("input",{id:"gateway",placeholder:"wss://gateway.example.com",value:m,onChange:C=>p(C.target.value),required:!y.startsWith("linkshell:")}),f.jsx("p",{className:"field-hint",children:"电脑需先连接同一个网关。"}),f.jsx("label",{htmlFor:"pairing",children:"配对码或配对链接"}),f.jsx("input",{id:"pairing",value:y,onChange:C=>v(C.target.value),placeholder:"6 位配对码,或粘贴 linkshell://pair 链接",required:!0}),f.jsxs("p",{className:"field-hint",children:["在电脑运行 ",f.jsx("code",{children:"linkshell pair"}),"。有效期 10 分钟,成功后此浏览器会记住设备。"]}),f.jsx("button",{className:"button primary full",disabled:b.busy||e.locked,children:"配对并连接"}),f.jsx("p",{className:"field-hint",children:"自托管不使用 iTool 登录凭证。清除网站数据后需要重新配对。"})]}),f.jsx(xt,{error:b.error}),b.busy&&f.jsx("p",{className:"muted",role:"status",children:"正在连接…"})]})}function mD({...n}){return f.jsx(Z3,{"data-slot":"popover",...n})}function pD({className:n,align:e="center",sideOffset:s=4,...r}){return f.jsx(W3,{children:f.jsx(J3,{"data-slot":"popover-content",align:e,sideOffset:s,className:Pe("z-50 flex w-72 origin-(--radix-popover-content-transform-origin) flex-col gap-2.5 rounded-lg bg-popover p-2.5 text-sm text-popover-foreground shadow-md ring-1 ring-foreground/10 outline-hidden duration-100 data-[side=bottom]:slide-in-from-top-2 data-[side=left]:slide-in-from-right-2 data-[side=right]:slide-in-from-left-2 data-[side=top]:slide-in-from-bottom-2 data-[state=open]:animate-in data-[state=open]:fade-in-0 data-[state=open]:zoom-in-95 data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=closed]:zoom-out-95",n),...r})})}function gD({...n}){return f.jsx(K3,{"data-slot":"popover-anchor",...n})}var j1=1,vD=.9,yD=.8,bD=.17,zm=.1,Im=.999,xD=.9999,wD=.99,SD=/[\\\/_+.#"@\[\(\{&]/,ED=/[\\\/_+.#"@\[\(\{&]/g,CD=/[\s-]/,xE=/[\s-]/g;function Dp(n,e,s,r,o,l,u){if(l===e.length)return o===n.length?j1:wD;var d=`${o},${l}`;if(u[d]!==void 0)return u[d];for(var m=r.charAt(l),p=s.indexOf(m,o),y=0,v,b,C,T;p>=0;)v=Dp(n,e,s,r,p+1,l+1,u),v>y&&(p===o?v*=j1:SD.test(n.charAt(p-1))?(v*=yD,C=n.slice(o,p-1).match(ED),C&&o>0&&(v*=Math.pow(Im,C.length))):CD.test(n.charAt(p-1))?(v*=vD,T=n.slice(o,p-1).match(xE),T&&o>0&&(v*=Math.pow(Im,T.length))):(v*=bD,o>0&&(v*=Math.pow(Im,p-o))),n.charAt(p)!==e.charAt(l)&&(v*=xD)),(v<zm&&s.charAt(p-1)===r.charAt(l+1)||r.charAt(l+1)===r.charAt(l)&&s.charAt(p-1)!==r.charAt(l))&&(b=Dp(n,e,s,r,p+1,l+2,u),b*zm>v&&(v=b*zm)),v>y&&(y=v),p=s.indexOf(m,p+1);return u[d]=y,y}function A1(n){return n.toLowerCase().replace(xE," ")}function _D(n,e,s){return n=s&&s.length>0?`${n+" "+s.join(" ")}`:n,Dp(n,e,A1(n),A1(e),0,0,{})}function Ps(n,e,{checkForDefaultPrevented:s=!0}={}){return function(o){if(n?.(o),s===!1||!o.defaultPrevented)return e?.(o)}}function T1(n,e){if(typeof n=="function")return n(e);n!=null&&(n.current=e)}function Vr(...n){return e=>{let s=!1;const r=n.map(o=>{const l=T1(o,e);return!s&&typeof l=="function"&&(s=!0),l});if(s)return()=>{for(let o=0;o<r.length;o++){const l=r[o];typeof l=="function"?l():T1(n[o],null)}}}}function ei(...n){return x.useCallback(Vr(...n),n)}function jD(n,e){const s=x.createContext(e),r=l=>{const{children:u,...d}=l,m=x.useMemo(()=>d,Object.values(d));return f.jsx(s.Provider,{value:m,children:u})};r.displayName=n+"Provider";function o(l){const u=x.useContext(s);if(u)return u;if(e!==void 0)return e;throw new Error(`\`${l}\` must be used within \`${n}\``)}return[r,o]}function AD(n,e=[]){let s=[];function r(l,u){const d=x.createContext(u),m=s.length;s=[...s,u];const p=v=>{const{scope:b,children:C,...T}=v,S=b?.[n]?.[m]||d,E=x.useMemo(()=>T,Object.values(T));return f.jsx(S.Provider,{value:E,children:C})};p.displayName=l+"Provider";function y(v,b){const C=b?.[n]?.[m]||d,T=x.useContext(C);if(T)return T;if(u!==void 0)return u;throw new Error(`\`${v}\` must be used within \`${l}\``)}return[p,y]}const o=()=>{const l=s.map(u=>x.createContext(u));return function(d){const m=d?.[n]||l;return x.useMemo(()=>({[`__scope${n}`]:{...d,[n]:m}}),[d,m])}};return o.scopeName=n,[r,TD(o,...e)]}function TD(...n){const e=n[0];if(n.length===1)return e;const s=()=>{const r=n.map(o=>({useScope:o(),scopeName:o.scopeName}));return function(l){const u=r.reduce((d,{useScope:m,scopeName:p})=>{const v=m(l)[`__scope${p}`];return{...d,...v}},{});return x.useMemo(()=>({[`__scope${e.scopeName}`]:u}),[u])}};return s.scopeName=e.scopeName,s}var Dl=globalThis?.document?x.useLayoutEffect:()=>{},kD=Qs[" useId ".trim().toString()]||(()=>{}),ND=0;function Wa(n){const[e,s]=x.useState(kD());return Dl(()=>{s(r=>r??String(ND++))},[n]),e?`radix-${e}`:""}var OD=Qs[" useInsertionEffect ".trim().toString()]||Dl;function RD({prop:n,defaultProp:e,onChange:s=()=>{},caller:r}){const[o,l,u]=DD({defaultProp:e,onChange:s}),d=n!==void 0,m=d?n:o;{const y=x.useRef(n!==void 0);x.useEffect(()=>{const v=y.current;v!==d&&console.warn(`${r} is changing from ${v?"controlled":"uncontrolled"} to ${d?"controlled":"uncontrolled"}. Components should not switch from controlled to uncontrolled (or vice versa). Decide between using a controlled or uncontrolled value for the lifetime of the component.`),y.current=d},[d,r])}const p=x.useCallback(y=>{if(d){const v=MD(y)?y(n):y;v!==n&&u.current?.(v)}else l(y)},[d,n,l,u]);return[m,p]}function DD({defaultProp:n,onChange:e}){const[s,r]=x.useState(n),o=x.useRef(s),l=x.useRef(e);return OD(()=>{l.current=e},[e]),x.useEffect(()=>{o.current!==s&&(l.current?.(s),o.current=s)},[s,o]),[s,r,l]}function MD(n){return typeof n=="function"}function wE(n){const e=zD(n),s=x.forwardRef((r,o)=>{const{children:l,...u}=r,d=x.Children.toArray(l),m=d.find(LD);if(m){const p=m.props.children,y=d.map(v=>v===m?x.Children.count(p)>1?x.Children.only(null):x.isValidElement(p)?p.props.children:null:v);return f.jsx(e,{...u,ref:o,children:x.isValidElement(p)?x.cloneElement(p,void 0,y):null})}return f.jsx(e,{...u,ref:o,children:l})});return s.displayName=`${n}.Slot`,s}function zD(n){const e=x.forwardRef((s,r)=>{const{children:o,...l}=s;if(x.isValidElement(o)){const u=BD(o),d=UD(l,o.props);return o.type!==x.Fragment&&(d.ref=r?Vr(r,u):u),x.cloneElement(o,d)}return x.Children.count(o)>1?x.Children.only(null):null});return e.displayName=`${n}.SlotClone`,e}var ID=Symbol("radix.slottable");function LD(n){return x.isValidElement(n)&&typeof n.type=="function"&&"__radixId"in n.type&&n.type.__radixId===ID}function UD(n,e){const s={...e};for(const r in e){const o=n[r],l=e[r];/^on[A-Z]/.test(r)?o&&l?s[r]=(...d)=>{const m=l(...d);return o(...d),m}:o&&(s[r]=o):r==="style"?s[r]={...o,...l}:r==="className"&&(s[r]=[o,l].filter(Boolean).join(" "))}return{...n,...s}}function BD(n){let e=Object.getOwnPropertyDescriptor(n.props,"ref")?.get,s=e&&"isReactWarning"in e&&e.isReactWarning;return s?n.ref:(e=Object.getOwnPropertyDescriptor(n,"ref")?.get,s=e&&"isReactWarning"in e&&e.isReactWarning,s?n.props.ref:n.props.ref||n.ref)}var HD=["a","button","div","form","h2","h3","img","input","label","li","nav","ol","p","select","span","svg","ul"],Wt=HD.reduce((n,e)=>{const s=wE(`Primitive.${e}`),r=x.forwardRef((o,l)=>{const{asChild:u,...d}=o,m=u?s:e;return typeof window<"u"&&(window[Symbol.for("radix-ui")]=!0),f.jsx(m,{...d,ref:l})});return r.displayName=`Primitive.${e}`,{...n,[e]:r}},{});function $D(n,e){n&&Gr.flushSync(()=>n.dispatchEvent(e))}function Ml(n){const e=x.useRef(n);return x.useEffect(()=>{e.current=n}),x.useMemo(()=>(...s)=>e.current?.(...s),[])}function VD(n,e=globalThis?.document){const s=Ml(n);x.useEffect(()=>{const r=o=>{o.key==="Escape"&&s(o)};return e.addEventListener("keydown",r,{capture:!0}),()=>e.removeEventListener("keydown",r,{capture:!0})},[s,e])}var qD="DismissableLayer",Mp="dismissableLayer.update",PD="dismissableLayer.pointerDownOutside",FD="dismissableLayer.focusOutside",k1,SE=x.createContext({layers:new Set,layersWithOutsidePointerEventsDisabled:new Set,branches:new Set}),EE=x.forwardRef((n,e)=>{const{disableOutsidePointerEvents:s=!1,onEscapeKeyDown:r,onPointerDownOutside:o,onFocusOutside:l,onInteractOutside:u,onDismiss:d,...m}=n,p=x.useContext(SE),[y,v]=x.useState(null),b=y?.ownerDocument??globalThis?.document,[,C]=x.useState({}),T=ei(e,M=>v(M)),S=Array.from(p.layers),[E]=[...p.layersWithOutsidePointerEventsDisabled].slice(-1),_=S.indexOf(E),j=y?S.indexOf(y):-1,N=p.layersWithOutsidePointerEventsDisabled.size>0,z=j>=_,k=YD(M=>{const R=M.target,L=[...p.branches].some(H=>H.contains(R));!z||L||(o?.(M),u?.(M),M.defaultPrevented||d?.())},b),O=KD(M=>{const R=M.target;[...p.branches].some(H=>H.contains(R))||(l?.(M),u?.(M),M.defaultPrevented||d?.())},b);return VD(M=>{j===p.layers.size-1&&(r?.(M),!M.defaultPrevented&&d&&(M.preventDefault(),d()))},b),x.useEffect(()=>{if(y)return s&&(p.layersWithOutsidePointerEventsDisabled.size===0&&(k1=b.body.style.pointerEvents,b.body.style.pointerEvents="none"),p.layersWithOutsidePointerEventsDisabled.add(y)),p.layers.add(y),N1(),()=>{s&&p.layersWithOutsidePointerEventsDisabled.size===1&&(b.body.style.pointerEvents=k1)}},[y,b,s,p]),x.useEffect(()=>()=>{y&&(p.layers.delete(y),p.layersWithOutsidePointerEventsDisabled.delete(y),N1())},[y,p]),x.useEffect(()=>{const M=()=>C({});return document.addEventListener(Mp,M),()=>document.removeEventListener(Mp,M)},[]),f.jsx(Wt.div,{...m,ref:T,style:{pointerEvents:N?z?"auto":"none":void 0,...n.style},onFocusCapture:Ps(n.onFocusCapture,O.onFocusCapture),onBlurCapture:Ps(n.onBlurCapture,O.onBlurCapture),onPointerDownCapture:Ps(n.onPointerDownCapture,k.onPointerDownCapture)})});EE.displayName=qD;var GD="DismissableLayerBranch",ZD=x.forwardRef((n,e)=>{const s=x.useContext(SE),r=x.useRef(null),o=ei(e,r);return x.useEffect(()=>{const l=r.current;if(l)return s.branches.add(l),()=>{s.branches.delete(l)}},[s.branches]),f.jsx(Wt.div,{...n,ref:o})});ZD.displayName=GD;function YD(n,e=globalThis?.document){const s=Ml(n),r=x.useRef(!1),o=x.useRef(()=>{});return x.useEffect(()=>{const l=d=>{if(d.target&&!r.current){let m=function(){CE(PD,s,p,{discrete:!0})};const p={originalEvent:d};d.pointerType==="touch"?(e.removeEventListener("click",o.current),o.current=m,e.addEventListener("click",o.current,{once:!0})):m()}else e.removeEventListener("click",o.current);r.current=!1},u=window.setTimeout(()=>{e.addEventListener("pointerdown",l)},0);return()=>{window.clearTimeout(u),e.removeEventListener("pointerdown",l),e.removeEventListener("click",o.current)}},[e,s]),{onPointerDownCapture:()=>r.current=!0}}function KD(n,e=globalThis?.document){const s=Ml(n),r=x.useRef(!1);return x.useEffect(()=>{const o=l=>{l.target&&!r.current&&CE(FD,s,{originalEvent:l},{discrete:!1})};return e.addEventListener("focusin",o),()=>e.removeEventListener("focusin",o)},[e,s]),{onFocusCapture:()=>r.current=!0,onBlurCapture:()=>r.current=!1}}function N1(){const n=new CustomEvent(Mp);document.dispatchEvent(n)}function CE(n,e,s,{discrete:r}){const o=s.originalEvent.target,l=new CustomEvent(n,{bubbles:!1,cancelable:!0,detail:s});e&&o.addEventListener(n,e,{once:!0}),r?$D(o,l):o.dispatchEvent(l)}var Lm="focusScope.autoFocusOnMount",Um="focusScope.autoFocusOnUnmount",O1={bubbles:!1,cancelable:!0},XD="FocusScope",_E=x.forwardRef((n,e)=>{const{loop:s=!1,trapped:r=!1,onMountAutoFocus:o,onUnmountAutoFocus:l,...u}=n,[d,m]=x.useState(null),p=Ml(o),y=Ml(l),v=x.useRef(null),b=ei(e,S=>m(S)),C=x.useRef({paused:!1,pause(){this.paused=!0},resume(){this.paused=!1}}).current;x.useEffect(()=>{if(r){let S=function(N){if(C.paused||!d)return;const z=N.target;d.contains(z)?v.current=z:Us(v.current,{select:!0})},E=function(N){if(C.paused||!d)return;const z=N.relatedTarget;z!==null&&(d.contains(z)||Us(v.current,{select:!0}))},_=function(N){if(document.activeElement===document.body)for(const k of N)k.removedNodes.length>0&&Us(d)};document.addEventListener("focusin",S),document.addEventListener("focusout",E);const j=new MutationObserver(_);return d&&j.observe(d,{childList:!0,subtree:!0}),()=>{document.removeEventListener("focusin",S),document.removeEventListener("focusout",E),j.disconnect()}}},[r,d,C.paused]),x.useEffect(()=>{if(d){D1.add(C);const S=document.activeElement;if(!d.contains(S)){const _=new CustomEvent(Lm,O1);d.addEventListener(Lm,p),d.dispatchEvent(_),_.defaultPrevented||(QD(nM(jE(d)),{select:!0}),document.activeElement===S&&Us(d))}return()=>{d.removeEventListener(Lm,p),setTimeout(()=>{const _=new CustomEvent(Um,O1);d.addEventListener(Um,y),d.dispatchEvent(_),_.defaultPrevented||Us(S??document.body,{select:!0}),d.removeEventListener(Um,y),D1.remove(C)},0)}}},[d,p,y,C]);const T=x.useCallback(S=>{if(!s&&!r||C.paused)return;const E=S.key==="Tab"&&!S.altKey&&!S.ctrlKey&&!S.metaKey,_=document.activeElement;if(E&&_){const j=S.currentTarget,[N,z]=WD(j);N&&z?!S.shiftKey&&_===z?(S.preventDefault(),s&&Us(N,{select:!0})):S.shiftKey&&_===N&&(S.preventDefault(),s&&Us(z,{select:!0})):_===j&&S.preventDefault()}},[s,r,C.paused]);return f.jsx(Wt.div,{tabIndex:-1,...u,ref:b,onKeyDown:T})});_E.displayName=XD;function QD(n,{select:e=!1}={}){const s=document.activeElement;for(const r of n)if(Us(r,{select:e}),document.activeElement!==s)return}function WD(n){const e=jE(n),s=R1(e,n),r=R1(e.reverse(),n);return[s,r]}function jE(n){const e=[],s=document.createTreeWalker(n,NodeFilter.SHOW_ELEMENT,{acceptNode:r=>{const o=r.tagName==="INPUT"&&r.type==="hidden";return r.disabled||r.hidden||o?NodeFilter.FILTER_SKIP:r.tabIndex>=0?NodeFilter.FILTER_ACCEPT:NodeFilter.FILTER_SKIP}});for(;s.nextNode();)e.push(s.currentNode);return e}function R1(n,e){for(const s of n)if(!JD(s,{upTo:e}))return s}function JD(n,{upTo:e}){if(getComputedStyle(n).visibility==="hidden")return!0;for(;n;){if(e!==void 0&&n===e)return!1;if(getComputedStyle(n).display==="none")return!0;n=n.parentElement}return!1}function eM(n){return n instanceof HTMLInputElement&&"select"in n}function Us(n,{select:e=!1}={}){if(n&&n.focus){const s=document.activeElement;n.focus({preventScroll:!0}),n!==s&&eM(n)&&e&&n.select()}}var D1=tM();function tM(){let n=[];return{add(e){const s=n[0];e!==s&&s?.pause(),n=M1(n,e),n.unshift(e)},remove(e){n=M1(n,e),n[0]?.resume()}}}function M1(n,e){const s=[...n],r=s.indexOf(e);return r!==-1&&s.splice(r,1),s}function nM(n){return n.filter(e=>e.tagName!=="A")}var aM="Portal",AE=x.forwardRef((n,e)=>{const{container:s,...r}=n,[o,l]=x.useState(!1);Dl(()=>l(!0),[]);const u=s||o&&globalThis?.document?.body;return u?kA.createPortal(f.jsx(Wt.div,{...r,ref:e}),u):null});AE.displayName=aM;function sM(n,e){return x.useReducer((s,r)=>e[s][r]??s,n)}var Hd=n=>{const{present:e,children:s}=n,r=rM(e),o=typeof s=="function"?s({present:r.isPresent}):x.Children.only(s),l=ei(r.ref,iM(o));return typeof s=="function"||r.isPresent?x.cloneElement(o,{ref:l}):null};Hd.displayName="Presence";function rM(n){const[e,s]=x.useState(),r=x.useRef(null),o=x.useRef(n),l=x.useRef("none"),u=n?"mounted":"unmounted",[d,m]=sM(u,{mounted:{UNMOUNT:"unmounted",ANIMATION_OUT:"unmountSuspended"},unmountSuspended:{MOUNT:"mounted",ANIMATION_END:"unmounted"},unmounted:{MOUNT:"mounted"}});return x.useEffect(()=>{const p=_u(r.current);l.current=d==="mounted"?p:"none"},[d]),Dl(()=>{const p=r.current,y=o.current;if(y!==n){const b=l.current,C=_u(p);n?m("MOUNT"):C==="none"||p?.display==="none"?m("UNMOUNT"):m(y&&b!==C?"ANIMATION_OUT":"UNMOUNT"),o.current=n}},[n,m]),Dl(()=>{if(e){let p;const y=e.ownerDocument.defaultView??window,v=C=>{const S=_u(r.current).includes(CSS.escape(C.animationName));if(C.target===e&&S&&(m("ANIMATION_END"),!o.current)){const E=e.style.animationFillMode;e.style.animationFillMode="forwards",p=y.setTimeout(()=>{e.style.animationFillMode==="forwards"&&(e.style.animationFillMode=E)})}},b=C=>{C.target===e&&(l.current=_u(r.current))};return e.addEventListener("animationstart",b),e.addEventListener("animationcancel",v),e.addEventListener("animationend",v),()=>{y.clearTimeout(p),e.removeEventListener("animationstart",b),e.removeEventListener("animationcancel",v),e.removeEventListener("animationend",v)}}else m("ANIMATION_END")},[e,m]),{isPresent:["mounted","unmountSuspended"].includes(d),ref:x.useCallback(p=>{r.current=p?getComputedStyle(p):null,s(p)},[])}}function _u(n){return n?.animationName||"none"}function iM(n){let e=Object.getOwnPropertyDescriptor(n.props,"ref")?.get,s=e&&"isReactWarning"in e&&e.isReactWarning;return s?n.ref:(e=Object.getOwnPropertyDescriptor(n,"ref")?.get,s=e&&"isReactWarning"in e&&e.isReactWarning,s?n.props.ref:n.props.ref||n.ref)}var Bm=0;function oM(){x.useEffect(()=>{const n=document.querySelectorAll("[data-radix-focus-guard]");return document.body.insertAdjacentElement("afterbegin",n[0]??z1()),document.body.insertAdjacentElement("beforeend",n[1]??z1()),Bm++,()=>{Bm===1&&document.querySelectorAll("[data-radix-focus-guard]").forEach(e=>e.remove()),Bm--}},[])}function z1(){const n=document.createElement("span");return n.setAttribute("data-radix-focus-guard",""),n.tabIndex=0,n.style.outline="none",n.style.opacity="0",n.style.position="fixed",n.style.pointerEvents="none",n}var $d="Dialog",[TE]=AD($d),[lM,na]=TE($d),kE=n=>{const{__scopeDialog:e,children:s,open:r,defaultOpen:o,onOpenChange:l,modal:u=!0}=n,d=x.useRef(null),m=x.useRef(null),[p,y]=RD({prop:r,defaultProp:o??!1,onChange:l,caller:$d});return f.jsx(lM,{scope:e,triggerRef:d,contentRef:m,contentId:Wa(),titleId:Wa(),descriptionId:Wa(),open:p,onOpenChange:y,onOpenToggle:x.useCallback(()=>y(v=>!v),[y]),modal:u,children:s})};kE.displayName=$d;var NE="DialogTrigger",cM=x.forwardRef((n,e)=>{const{__scopeDialog:s,...r}=n,o=na(NE,s),l=ei(e,o.triggerRef);return f.jsx(Wt.button,{type:"button","aria-haspopup":"dialog","aria-expanded":o.open,"aria-controls":o.contentId,"data-state":Dg(o.open),...r,ref:l,onClick:Ps(n.onClick,o.onOpenToggle)})});cM.displayName=NE;var Og="DialogPortal",[uM,OE]=TE(Og,{forceMount:void 0}),RE=n=>{const{__scopeDialog:e,forceMount:s,children:r,container:o}=n,l=na(Og,e);return f.jsx(uM,{scope:e,forceMount:s,children:x.Children.map(r,u=>f.jsx(Hd,{present:s||l.open,children:f.jsx(AE,{asChild:!0,container:o,children:u})}))})};RE.displayName=Og;var fd="DialogOverlay",DE=x.forwardRef((n,e)=>{const s=OE(fd,n.__scopeDialog),{forceMount:r=s.forceMount,...o}=n,l=na(fd,n.__scopeDialog);return l.modal?f.jsx(Hd,{present:r||l.open,children:f.jsx(fM,{...o,ref:e})}):null});DE.displayName=fd;var dM=wE("DialogOverlay.RemoveScroll"),fM=x.forwardRef((n,e)=>{const{__scopeDialog:s,...r}=n,o=na(fd,s);return f.jsx(co,{as:dM,allowPinchZoom:!0,shards:[o.contentRef],children:f.jsx(Wt.div,{"data-state":Dg(o.open),...r,ref:e,style:{pointerEvents:"auto",...r.style}})})}),qr="DialogContent",ME=x.forwardRef((n,e)=>{const s=OE(qr,n.__scopeDialog),{forceMount:r=s.forceMount,...o}=n,l=na(qr,n.__scopeDialog);return f.jsx(Hd,{present:r||l.open,children:l.modal?f.jsx(hM,{...o,ref:e}):f.jsx(mM,{...o,ref:e})})});ME.displayName=qr;var hM=x.forwardRef((n,e)=>{const s=na(qr,n.__scopeDialog),r=x.useRef(null),o=ei(e,s.contentRef,r);return x.useEffect(()=>{const l=r.current;if(l)return Il(l)},[]),f.jsx(zE,{...n,ref:o,trapFocus:s.open,disableOutsidePointerEvents:!0,onCloseAutoFocus:Ps(n.onCloseAutoFocus,l=>{l.preventDefault(),s.triggerRef.current?.focus()}),onPointerDownOutside:Ps(n.onPointerDownOutside,l=>{const u=l.detail.originalEvent,d=u.button===0&&u.ctrlKey===!0;(u.button===2||d)&&l.preventDefault()}),onFocusOutside:Ps(n.onFocusOutside,l=>l.preventDefault())})}),mM=x.forwardRef((n,e)=>{const s=na(qr,n.__scopeDialog),r=x.useRef(!1),o=x.useRef(!1);return f.jsx(zE,{...n,ref:e,trapFocus:!1,disableOutsidePointerEvents:!1,onCloseAutoFocus:l=>{n.onCloseAutoFocus?.(l),l.defaultPrevented||(r.current||s.triggerRef.current?.focus(),l.preventDefault()),r.current=!1,o.current=!1},onInteractOutside:l=>{n.onInteractOutside?.(l),l.defaultPrevented||(r.current=!0,l.detail.originalEvent.type==="pointerdown"&&(o.current=!0));const u=l.target;s.triggerRef.current?.contains(u)&&l.preventDefault(),l.detail.originalEvent.type==="focusin"&&o.current&&l.preventDefault()}})}),zE=x.forwardRef((n,e)=>{const{__scopeDialog:s,trapFocus:r,onOpenAutoFocus:o,onCloseAutoFocus:l,...u}=n,d=na(qr,s),m=x.useRef(null),p=ei(e,m);return oM(),f.jsxs(f.Fragment,{children:[f.jsx(_E,{asChild:!0,loop:!0,trapped:r,onMountAutoFocus:o,onUnmountAutoFocus:l,children:f.jsx(EE,{role:"dialog",id:d.contentId,"aria-describedby":d.descriptionId,"aria-labelledby":d.titleId,"data-state":Dg(d.open),...u,ref:p,onDismiss:()=>d.onOpenChange(!1)})}),f.jsxs(f.Fragment,{children:[f.jsx(yM,{titleId:d.titleId}),f.jsx(xM,{contentRef:m,descriptionId:d.descriptionId})]})]})}),Rg="DialogTitle",pM=x.forwardRef((n,e)=>{const{__scopeDialog:s,...r}=n,o=na(Rg,s);return f.jsx(Wt.h2,{id:o.titleId,...r,ref:e})});pM.displayName=Rg;var IE="DialogDescription",gM=x.forwardRef((n,e)=>{const{__scopeDialog:s,...r}=n,o=na(IE,s);return f.jsx(Wt.p,{id:o.descriptionId,...r,ref:e})});gM.displayName=IE;var LE="DialogClose",vM=x.forwardRef((n,e)=>{const{__scopeDialog:s,...r}=n,o=na(LE,s);return f.jsx(Wt.button,{type:"button",...r,ref:e,onClick:Ps(n.onClick,()=>o.onOpenChange(!1))})});vM.displayName=LE;function Dg(n){return n?"open":"closed"}var UE="DialogTitleWarning",[_9,BE]=jD(UE,{contentName:qr,titleName:Rg,docsSlug:"dialog"}),yM=({titleId:n})=>{const e=BE(UE),s=`\`${e.contentName}\` requires a \`${e.titleName}\` for the component to be accessible for screen reader users.
|
|
161
|
+
`))}).catch(o=>{o?.code!==-32601&&r()})}close(){this.stopped=!0,this.drop();for(const e of this.remove)e()}}const eD="https://mkbeusztkzffnzjdwmqk.supabase.co",tD="eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJzdXBhYmFzZSIsInJlZiI6Im1rYmV1c3p0a3pmZm56amR3bXFrIiwicm9sZSI6ImFub24iLCJpYXQiOjE3NjU5Nzc0NzgsImV4cCI6MjA4MTU1MzQ3OH0.2wlT6q6687Z5rpEYsdp01IQpNNl_XWv0IAfBgwPyDP0";let nD;function wl(){return nD??=Mj(window.__LINKSHELL_CONFIG__?.account?.url??eD,window.__LINKSHELL_CONFIG__?.account?.anonKey??tD,{auth:{persistSession:!0,autoRefreshToken:!0,detectSessionInUrl:!0,flowType:"pkce",storageKey:"linkshell.web.account.v2"}})}async function aD(){const n=wl().auth,{data:e,error:s}=await n.getSession();if(s)throw s;if(!e.session)return;if((e.session.expires_at??0)*1e3>Date.now()+12e4)return e.session.access_token;const r=await n.refreshSession();if(r.error)throw r.error;if(!r.data.session)throw new Error("登录已失效,请重新登录");return r.data.session.access_token}function Ks(n,e){try{return JSON.parse(localStorage.getItem(`linkshell.web.${n}`)??"null")??e}catch{return e}}function fa(n,e){localStorage.setItem(`linkshell.web.${n}`,JSON.stringify(e))}let sD;function rD(){return sD??=new Promise((n,e)=>{const s=indexedDB.open("linkshell.web.identity",1);s.onupgradeneeded=()=>s.result.createObjectStore("keys"),s.onerror=()=>e(new Error("无法保存浏览器设备身份,请允许此网站使用本地存储")),s.onsuccess=()=>{const r=s.result,o=r.transaction("keys","readwrite"),l=o.objectStore("keys"),u=l.get("device");let d;u.onsuccess=()=>{d=u.result??mR(),u.result||l.put(d,"device")},o.oncomplete=()=>{r.close(),n(d)},o.onerror=()=>{r.close(),e(new Error("设备身份保存失败"))}}})}const iD=n=>{const e=new RTCPeerConnection({iceServers:n.map(r=>({urls:r}))}),s=e.createDataChannel(TR,{ordered:!0});return s.binaryType="arraybuffer",{async offer(){if(await e.setLocalDescription(await e.createOffer()),e.iceGatheringState!=="complete"&&await new Promise(r=>{const o=()=>{clearTimeout(u),e.removeEventListener("icegatheringstatechange",l),r()},l=()=>{e.iceGatheringState==="complete"&&o()},u=setTimeout(o,2e3);e.addEventListener("icegatheringstatechange",l)}),!e.localDescription?.sdp)throw new Error("无法建立直连通道");return e.localDescription.sdp},accept:r=>e.setRemoteDescription({type:"answer",sdp:r}),send(r){s.send(r)},onState(r){s.addEventListener("open",()=>r("open")),s.addEventListener("close",()=>r("closed")),e.addEventListener("connectionstatechange",()=>{["failed","closed"].includes(e.connectionState)&&r("closed")})},onMessage(r){s.addEventListener("message",o=>{o.data instanceof ArrayBuffer&&r(new Uint8Array(o.data))})},close(){e.close()}}},oD=Ks("source",Zs),vE=Zs==="self-hosted"?"self-hosted":oD,lD=vE==="official"?jr:Ks("gateway",C6);class cD{state=b2(()=>({source:vE,gateway:lD,computers:[],relayStatus:{},locked:!1,ready:!1}));identity;relays=new Map;paired=Ks("paired",[]);selected=Ks("selected","");releaseLock;starting;authUser;authSubscribed=!1;generation=0;channel=typeof BroadcastChannel<"u"?new BroadcastChannel("linkshell.web.owner"):void 0;constructor(){this.channel?.addEventListener("message",e=>{e.data==="yield"&&(this.stop(),this.state.setState({locked:!0}))}),window.addEventListener("pagehide",()=>this.stop()),window.addEventListener("pageshow",()=>{this.start()}),window.addEventListener("online",()=>this.reconnect()),document.addEventListener("visibilitychange",()=>{document.hidden||this.reconnect()})}report(e){this.state.setState({error:e instanceof Error?e.message:String(e)})}async start(){return this.releaseLock||this.starting?this.starting:(this.starting=this.acquire(!1).finally(()=>{this.starting=void 0}),this.starting)}async claim(){this.channel?.postMessage("yield"),await this.acquire(!0)}async acquire(e){if(!navigator.locks){this.report(new Error("此浏览器不支持设备连接锁,请使用最新版 Chrome、Edge、Safari 或 Firefox"));return}await new Promise((s,r)=>{navigator.locks.request("linkshell.web.connection",{ifAvailable:!e},async o=>{if(!o){this.state.setState({locked:!0,ready:!0}),s();return}await new Promise(l=>{this.releaseLock=l,this.state.setState({locked:!1}),this.boot().then(s,r)})}).catch(r)}).catch(s=>this.report(s))}async boot(){const e=++this.generation;if(this.identity=await rD(),e===this.generation){this.state.setState({computers:this.paired.map(s=>({...s,machine:{...s.machine,online:!1}})),ready:!0});for(const s of this.paired)this.relay(s.gateway);this.state.getState().source==="official"?await this.connectAccount():this.state.getState().gateway&&this.relay(Sm(this.state.getState().gateway))}}async connectAccount(){if(Zs==="self-hosted")throw new Error("私有部署使用设备配对");const e=wl().auth,{data:s,error:r}=await e.getSession();if(r)throw r;this.authUser=s.session?.user.id,this.state.setState({account:s.session?.user.email,source:"official",gateway:jr}),this.authSubscribed||(this.authSubscribed=!0,e.onAuthStateChange((o,l)=>{const u=this.authUser!==l?.user.id;this.authUser=l?.user.id,this.state.setState({account:l?.user.email}),u&&this.releaseLock&&setTimeout(()=>{this.relays.get(jr)?.reauthenticate(),l&&this.relay(jr)},0)})),fa("source","official"),s.session&&this.relay(jr).reauthenticate()}relay(e){if(!this.identity||!this.releaseLock)throw new Error("请先在本标签页启用连接");const s=Sm(e),r=this.relays.get(s);if(r)return r;const o=s===jr&&Zs!=="self-hosted",l=new AR({url:s+wR,identity:this.identity,role:"device",name:"LinkShell Web",platform:"web",token:o?async()=>{try{return await aD()}catch(u){throw this.report(u),u}}:void 0,createSocket:u=>{const d=new WebSocket(u),m=d.send.bind(d);return d.send=p=>{if(typeof p=="string"&&o&&this.authUser){const y=JSON.parse(p);if(y.t==="auth"&&!y.token){d.close(4001,"账号续期失败,正在重试");return}}m(p)},d}});return this.relays.set(s,l),l.onStatus((u,d)=>{this.state.setState(m=>({relayStatus:{...m.relayStatus,[s]:u},...d?{error:d.message}:{}})),u==="online"&&this.refresh(s).catch(m=>this.report(m))}),l.on("machines.changed",()=>{this.refresh(s).catch(u=>this.report(u))}),l.on("presence",({id:u,online:d})=>this.state.setState(m=>({computers:m.computers.map(p=>p.gateway===s&&p.machine.id===u?{...p,machine:{...p.machine,online:d}}:p)}))),l.start(),l}async refresh(e){const s=this.relays.get(e);if(!s)return;const{machines:r}=await s.request("machines.list",{}),o=r.map(u=>({gateway:e,machine:u,key:`${e}#${u.id}`}));this.state.setState(u=>({computers:[...u.computers.filter(d=>d.gateway!==e),...o]}));const l=this.state.getState();if(!l.connection){const u=l.computers.find(d=>d.key===this.selected)??l.computers.find(d=>d.machine.online);u&&this.select(u)}}select(e){if(!this.identity)throw new Error("设备身份尚未就绪");this.disconnect();const s=this.identity,r=this.relay(e.gateway),o=new $R({url:e.key,createSocket:()=>new KR(r,s,e.machine),lazyImages:!0}),l=YR(o,{lazyImages:!0}),u=new WR(o,{connector:iD,iceServers:()=>l.getState().machine?.direct?.iceServers});l.subscribe((d,m)=>{d.machine!==m.machine&&u.connect()}),this.state.setState({connection:{computer:e,link:o,store:l,streams:u},error:void 0}),this.selected=e.key,fa("selected",e.key),l.getState().connect(),u.start()}async pair(e,s){const r=s.trim().startsWith("linkshell:")?uE(s.trim()):void 0;if(s.trim().startsWith("linkshell:")&&!r)throw new Error("配对链接格式不正确");if(!r&&!/^\d{6}$/.test(s.trim()))throw new Error("请输入 6 位配对码");const o=Sm((r?.gateway??e).replace(/^http/,"ws")),l=this.relay(o),u=r?await XR(l,this.identity,r):await QR(l,this.identity,s.trim()),d={key:`${o}#${u.id}`,gateway:o,machine:u};this.paired=[...this.paired.filter(m=>m.key!==d.key),d],fa("paired",this.paired),fa("source","self-hosted"),fa("gateway",o),this.state.setState({source:"self-hosted",gateway:o}),await this.refresh(o),this.select(d)}async forget(e){await this.relay(e.gateway).request("machines.forget",{machineId:e.machine.id}),this.paired=this.paired.filter(s=>s.key!==e.key),fa("paired",this.paired),this.state.getState().connection?.computer.key===e.key&&this.disconnect(),this.state.setState(s=>({computers:s.computers.filter(r=>r.key!==e.key)}))}reconnect(){if(this.releaseLock){for(const e of this.relays.values())e.reconnectNow();this.state.getState().connection?.link.reconnectNow()}}disconnect(){const e=this.state.getState().connection;e?.streams.stop(),e?.store.getState().disconnect(),this.state.setState({connection:void 0})}stop(){this.generation++,this.disconnect();for(const e of this.relays.values())e.stop();this.relays.clear(),this.releaseLock?.(),this.releaseLock=void 0}}const Qt=new cD,uD={codex:{svg:'<svg viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg"><path d="M19.503 0H4.496A4.496 4.496 0 000 4.496v15.007A4.496 4.496 0 004.496 24h15.007A4.496 4.496 0 0024 19.503V4.496A4.496 4.496 0 0019.503 0z" fill="#fff"></path><path d="M9.064 3.344a4.578 4.578 0 012.285-.312c1 .115 1.891.54 2.673 1.275.01.01.024.017.037.021a.09.09 0 00.043 0 4.55 4.55 0 013.046.275l.047.022.116.057a4.581 4.581 0 012.188 2.399c.209.51.313 1.041.315 1.595a4.24 4.24 0 01-.134 1.223.123.123 0 00.03.115c.594.607.988 1.33 1.183 2.17.289 1.425-.007 2.71-.887 3.854l-.136.166a4.548 4.548 0 01-2.201 1.388.123.123 0 00-.081.076c-.191.551-.383 1.023-.74 1.494-.9 1.187-2.222 1.846-3.711 1.838-1.187-.006-2.239-.44-3.157-1.302a.107.107 0 00-.105-.024c-.388.125-.78.143-1.204.138a4.441 4.441 0 01-1.945-.466 4.544 4.544 0 01-1.61-1.335c-.152-.202-.303-.392-.414-.617a5.81 5.81 0 01-.37-.961 4.582 4.582 0 01-.014-2.298.124.124 0 00.006-.056.085.085 0 00-.027-.048 4.467 4.467 0 01-1.034-1.651 3.896 3.896 0 01-.251-1.192 5.189 5.189 0 01.141-1.6c.337-1.112.982-1.985 1.933-2.618.212-.141.413-.251.601-.33.215-.089.43-.164.646-.227a.098.098 0 00.065-.066 4.51 4.51 0 01.829-1.615 4.535 4.535 0 011.837-1.388zm3.482 10.565a.637.637 0 000 1.272h3.636a.637.637 0 100-1.272h-3.636zM8.462 9.23a.637.637 0 00-1.106.631l1.272 2.224-1.266 2.136a.636.636 0 101.095.649l1.454-2.455a.636.636 0 00.005-.64L8.462 9.23z" fill="url(#lobe-icons-codex-_R_0_)"></path><defs><linearGradient gradientUnits="userSpaceOnUse" id="lobe-icons-codex-_R_0_" x1="12" x2="12" y1="3" y2="21"><stop stop-color="#B1A7FF"></stop><stop offset=".5" stop-color="#7A9DFF"></stop><stop offset="1" stop-color="#3941FF"></stop></linearGradient></defs></svg>',full:!0},gemini:{svg:'<svg viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg"><path d="M0 4.391A4.391 4.391 0 014.391 0h15.217A4.391 4.391 0 0124 4.391v15.217A4.391 4.391 0 0119.608 24H4.391A4.391 4.391 0 010 19.608V4.391z" fill="url(#lobe-icons-gemini-cli-_R_0_)"></path><path clip-rule="evenodd" d="M19.74 1.444a2.816 2.816 0 012.816 2.816v15.48a2.816 2.816 0 01-2.816 2.816H4.26a2.816 2.816 0 01-2.816-2.816V4.26A2.816 2.816 0 014.26 1.444h15.48zM7.236 8.564l7.752 3.728-7.752 3.727v2.802l9.557-4.596v-3.866L7.236 5.763v2.801z" fill="#1E1E2E" fill-rule="evenodd"></path><defs><linearGradient gradientUnits="userSpaceOnUse" id="lobe-icons-gemini-cli-_R_0_" x1="24" x2="0" y1="6.587" y2="16.494"><stop stop-color="#EE4D5D"></stop><stop offset=".328" stop-color="#B381DD"></stop><stop offset=".476" stop-color="#207CFE"></stop></linearGradient></defs></svg>',full:!0},claude:{svg:'<svg viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg"><path clip-rule="evenodd" d="M20.998 10.949H24v3.102h-3v3.028h-1.487V20H18v-2.921h-1.487V20H15v-2.921H9V20H7.488v-2.921H6V20H4.487v-2.921H3V14.05H0V10.95h3V5h17.998v5.949zM6 10.949h1.488V8.102H6v2.847zm10.51 0H18V8.102h-1.49v2.847z" fill="#D97757" fill-rule="evenodd"></path></svg>',full:!1,bg:{light:"#F4F1EA",dark:"#2A2926"}},copilot:{svg:'<svg fill="currentColor" fill-rule="evenodd" viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg"><path d="M19.245 5.364c1.322 1.36 1.877 3.216 2.11 5.817.622 0 1.2.135 1.592.654l.73.964c.21.278.323.61.323.955v2.62c0 .339-.173.669-.453.868C20.239 19.602 16.157 21.5 12 21.5c-4.6 0-9.205-2.583-11.547-4.258-.28-.2-.452-.53-.453-.868v-2.62c0-.345.113-.679.321-.956l.73-.963c.392-.517.974-.654 1.593-.654l.029-.297c.25-2.446.81-4.213 2.082-5.52 2.461-2.54 5.71-2.851 7.146-2.864h.198c1.436.013 4.685.323 7.146 2.864zm-7.244 4.328c-.284 0-.613.016-.962.05-.123.447-.305.85-.57 1.108-1.05 1.023-2.316 1.18-2.994 1.18-.638 0-1.306-.13-1.851-.464-.516.165-1.012.403-1.044.996a65.882 65.882 0 00-.063 2.884l-.002.48c-.002.563-.005 1.126-.013 1.69.002.326.204.63.51.765 2.482 1.102 4.83 1.657 6.99 1.657 2.156 0 4.504-.555 6.985-1.657a.854.854 0 00.51-.766c.03-1.682.006-3.372-.076-5.053-.031-.596-.528-.83-1.046-.996-.546.333-1.212.464-1.85.464-.677 0-1.942-.157-2.993-1.18-.266-.258-.447-.661-.57-1.108-.32-.032-.64-.049-.96-.05zm-2.525 4.013c.539 0 .976.426.976.95v1.753c0 .525-.437.95-.976.95a.964.964 0 01-.976-.95v-1.752c0-.525.437-.951.976-.951zm5 0c.539 0 .976.426.976.95v1.753c0 .525-.437.95-.976.95a.964.964 0 01-.976-.95v-1.752c0-.525.437-.951.976-.951zM7.635 5.087c-1.05.102-1.935.438-2.385.906-.975 1.037-.765 3.668-.21 4.224.405.394 1.17.657 1.995.657h.09c.649-.013 1.785-.176 2.73-1.11.435-.41.705-1.433.675-2.47-.03-.834-.27-1.52-.63-1.813-.39-.336-1.275-.482-2.265-.394zm6.465.394c-.36.292-.6.98-.63 1.813-.03 1.037.24 2.06.675 2.47.968.957 2.136 1.104 2.776 1.11h.044c.825 0 1.59-.263 1.995-.657.555-.556.765-3.187-.21-4.224-.45-.468-1.335-.804-2.385-.906-.99-.088-1.875.058-2.265.394zM12 7.615c-.24 0-.525.015-.84.044.03.16.045.336.06.526l-.001.159a2.94 2.94 0 01-.014.25c.225-.022.425-.027.612-.028h.366c.187 0 .387.006.612.028-.015-.146-.015-.277-.015-.409.015-.19.03-.365.06-.526a9.29 9.29 0 00-.84-.044z"></path></svg>',full:!1,bg:{light:"#0D1117",dark:"#F0F3F6"},fg:{light:"#FFFFFF",dark:"#0D1117"}},grok:{svg:'<svg fill="currentColor" fill-rule="evenodd" viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg"><path d="M9.27 15.29l7.978-5.897c.391-.29.95-.177 1.137.272.98 2.369.542 5.215-1.41 7.169-1.951 1.954-4.667 2.382-7.149 1.406l-2.711 1.257c3.889 2.661 8.611 2.003 11.562-.953 2.341-2.344 3.066-5.539 2.388-8.42l.006.007c-.983-4.232.242-5.924 2.75-9.383.06-.082.12-.164.179-.248l-3.301 3.305v-.01L9.267 15.292M7.623 16.723c-2.792-2.67-2.31-6.801.071-9.184 1.761-1.763 4.647-2.483 7.166-1.425l2.705-1.25a7.808 7.808 0 00-1.829-1A8.975 8.975 0 005.984 5.83c-2.533 2.536-3.33 6.436-1.962 9.764 1.022 2.487-.653 4.246-2.34 6.022-.599.63-1.199 1.259-1.682 1.925l7.62-6.815"></path></svg>',full:!1,bg:{light:"#000000",dark:"#FFFFFF"},fg:{light:"#FFFFFF",dark:"#000000"}},opencode:{svg:'<svg fill="currentColor" fill-rule="evenodd" viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg"><path d="M16 6H8v12h8V6zm4 16H4V2h16v20z"></path></svg>',full:!1,bg:{light:"#131010",dark:"#F1ECEC"},fg:{light:"#F1ECEC",dark:"#131010"}},cursor:{svg:'<svg fill="currentColor" fill-rule="evenodd" viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg"><path d="M22.106 5.68L12.5.135a.998.998 0 00-.998 0L1.893 5.68a.84.84 0 00-.419.726v11.186c0 .3.16.577.42.727l9.607 5.547a.999.999 0 00.998 0l9.608-5.547a.84.84 0 00.42-.727V6.407a.84.84 0 00-.42-.726zm-.603 1.176L12.228 22.92c-.063.108-.228.064-.228-.061V12.34a.59.59 0 00-.295-.51l-9.11-5.26c-.107-.062-.063-.228.062-.228h18.55c.264 0 .428.286.296.514z"></path></svg>',full:!1,bg:{light:"#14120B",dark:"#EDECEC"},fg:{light:"#EDECEC",dark:"#14120B"}}},yE=x.createContext(null);function yt(){const n=x.useContext(yE);if(!n)throw new Error("尚未连接电脑");return n}function lt(n){return Md(yt().store,n)}function pn(){return yt().store.getState()}const bE=n=>n instanceof Error?n.message:String(n),dd=n=>n.replace(/\/$/,"").split("/").pop()??n,Tr=n=>n.title||dd(n.cwd)||"未命名会话",dD=n=>({idle:"已完成",waiting:"需要你",running:"进行中",error:"出错",offline:"离线",completed:"已完成",failed:"失败",stopped:"已停止",pending:"等待中",active:"进行中",paused:"已暂停",complete:"已完成",blocked:"待处理",usageLimited:"用量受限",budgetLimited:"预算已用完",unknown:"未知"})[n]??n;function Bd({agent:n}){const e=uD[n.toLowerCase()];return f.jsx("span",{className:`agent-mark ${n.toLowerCase()} ${e?.full?"full-mark":""}`,children:e?f.jsx("img",{src:`data:image/svg+xml,${encodeURIComponent(e.svg.replaceAll("currentColor",e.fg?.light??"#333"))}`,alt:n}):n.slice(0,1).toUpperCase()})}function $r({state:n}){return f.jsxs("span",{className:`badge ${n==="idle"||n==="completed"?"done":n}`,children:[f.jsx("span",{className:"status-dot"}),dD(n)]})}function xt({error:n}){return n?f.jsx("p",{role:"alert",className:"form-error",children:n}):null}function Rl({title:n,children:e,close:s,wide:r=!1,returnFocus:o}){return f.jsx(f2,{open:!0,onOpenChange:l=>{l||s()},children:f.jsxs(h2,{onCloseAutoFocus:o?l=>{l.preventDefault(),o()}:void 0,className:Pe("max-h-[85dvh] overflow-y-auto p-6 sm:max-w-xl",r&&"sm:max-w-5xl"),children:[f.jsxs(m2,{children:[f.jsx(p2,{children:n}),f.jsxs(g2,{className:"sr-only",children:[n,"设置与操作"]})]}),e]})})}function Nt(){const[n,e]=x.useState(),[s,r]=x.useState(!1),o=x.useRef(!1);async function l(u){if(!o.current){o.current=!0,r(!0),e(void 0);try{return await u()}catch(d){e(bE(d))}finally{o.current=!1,r(!1)}}}return{error:n,busy:s,run:l,clear:()=>e(void 0)}}function ta(n,e,s=0){const[r,o]=x.useState({loading:!0}),[l,u]=x.useState(0),d=x.useRef(n);return d.current=n,x.useEffect(()=>{let m=!0,p=!1;const y=async()=>{if(!p){p=!0;try{const b=await d.current();m&&o({value:b,loading:!1})}catch(b){m&&o(C=>({...C,error:bE(b),loading:!1}))}finally{p=!1}}};o({loading:!0}),y();const v=s?setInterval(()=>void y(),s):void 0;return()=>{m=!1,clearInterval(v)}},[...e,l,s]),{...r,reload:()=>u(m=>m+1)}}function Sa({loading:n,error:e}){return f.jsxs(f.Fragment,{children:[n&&f.jsx("p",{className:"muted loading-copy",role:"status",children:"正在加载…"}),f.jsx(xt,{error:e})]})}function fD({found:n}){const e=x.useRef(null),[s,r]=x.useState(!1),[o,l]=x.useState(),u=x.useRef(n);u.current=n;function d(p){if(!uE(p)){l("这不是有效的 LinkShell 配对二维码");return}u.current(p),r(!1),l(void 0)}const m=x.useRef(d);return m.current=d,x.useEffect(()=>{if(!s||!e.current)return;let p=!1,y;return up(()=>import("./qr-scanner.min-CUJBiTnI.js"),__vite__mapDeps([0,1,2,3,4])).then(async({default:v})=>{p||!e.current||(y=new v(e.current,b=>m.current(b.data),{preferredCamera:"environment",returnDetailedScanResult:!0,highlightScanRegion:!0}),await y.start())}).catch(v=>{p||(l(v instanceof Error?v.message:"无法打开摄像头,请使用图片或配对码"),r(!1))}),()=>{p=!0,y?.destroy()}},[s]),f.jsxs("div",{className:"qr-scan",children:[f.jsxs("div",{className:"permission-buttons",children:[f.jsx("button",{className:"button secondary",type:"button",onClick:()=>r(!s),children:s?"关闭摄像头":"扫描二维码"}),f.jsxs("label",{className:"button secondary",children:["从图片识别",f.jsx("input",{type:"file",accept:"image/*",hidden:!0,onChange:p=>{const y=p.target.files?.[0];p.target.value="",y&&up(()=>import("./qr-scanner.min-CUJBiTnI.js"),__vite__mapDeps([0,1,2,3,4])).then(v=>v.default.scanImage(y,{returnDetailedScanResult:!0})).then(v=>d(v.data),()=>l("没有识别到二维码,请换一张图片或输入配对码"))}})]})]}),s&&f.jsx("video",{ref:e,className:"qr-video",muted:!0,playsInline:!0}),f.jsx(xt,{error:o})]})}function hD({close:n}){const e=Md(Qt.state),[s,r]=x.useState(e.source),[o,l]=x.useState(""),[u,d]=x.useState(""),[m,p]=x.useState(s==="self-hosted"?e.gateway:""),[y,v]=x.useState(""),b=Nt();return f.jsxs(Rl,{title:"连接你的电脑",close:n,children:[f.jsx("p",{className:"muted modal-subtitle",children:"电脑保持运行,网页即可继续你的会话。"}),Zs==="official"&&f.jsxs("div",{className:"source-options",children:[f.jsxs("button",{className:`source-option ${s==="official"?"selected":""}`,"aria-pressed":s==="official",onClick:()=>r("official"),children:[f.jsx(Tt,{name:"globe"}),f.jsx("strong",{children:"官方账号"}),f.jsx("span",{children:"同一 iTool 账号发现电脑"})]}),f.jsxs("button",{className:`source-option ${s==="self-hosted"?"selected":""}`,"aria-pressed":s==="self-hosted",onClick:()=>r("self-hosted"),children:[f.jsx(Tt,{name:"server"}),f.jsx("strong",{children:"配对电脑"}),f.jsx("span",{children:"官方或自托管网关的配对码"})]})]}),s==="official"?f.jsxs("form",{className:"new-form",onSubmit:C=>{C.preventDefault(),b.run(async()=>{const T=await wl().auth.signInWithPassword({email:o.trim(),password:u});if(T.error)throw T.error;await Qt.connectAccount(),n()})},children:[e.account?f.jsx("div",{className:"private-note",children:f.jsxs("div",{children:[f.jsx("strong",{children:e.account}),f.jsx("p",{children:"电脑端运行 linkshell login,使用同一账号。电脑接入官方网关需要 Pro 订阅。"}),f.jsx("button",{type:"button",className:"text-button",onClick:()=>void b.run(async()=>{await Qt.connectAccount(),n()}),children:"刷新账号电脑"})]})}):f.jsxs(f.Fragment,{children:[f.jsx("label",{htmlFor:"email",children:"邮箱"}),f.jsx("input",{id:"email",type:"email",autoComplete:"username",value:o,onChange:C=>l(C.target.value),required:!0}),f.jsx("label",{htmlFor:"password",children:"密码"}),f.jsx("input",{id:"password",type:"password",autoComplete:"current-password",value:u,onChange:C=>d(C.target.value),required:!0}),f.jsx("button",{className:"button primary full",disabled:b.busy,children:"登录"}),f.jsx("div",{className:"form-columns",children:["github","google"].map(C=>f.jsx("button",{type:"button",className:"button secondary",disabled:b.busy,onClick:()=>void b.run(async()=>{const T=await wl().auth.signInWithOAuth({provider:C,options:{redirectTo:location.origin+location.pathname}});if(T.error)throw T.error}),children:C==="github"?"GitHub 登录":"Google 登录"},C))}),f.jsxs("p",{className:"field-hint",children:["登录状态自动续期。",f.jsx("a",{href:"https://itool.tech/zh/register",target:"_blank",rel:"noreferrer",children:"注册 iTool 账号 ↗"})]})]}),e.account&&f.jsx("button",{type:"button",className:"button secondary full",disabled:b.busy,onClick:()=>void b.run(async()=>{const C=await wl().auth.signOut({scope:"local"});if(C.error)throw C.error;Qt.disconnect()}),children:"退出本浏览器账号"})]}):f.jsxs("form",{className:"pairing-form",onSubmit:C=>{C.preventDefault(),b.run(async()=>{await Qt.pair(m,y),n()})},children:[f.jsx(fD,{found:v}),f.jsx("label",{htmlFor:"gateway",children:"网关地址"}),f.jsx("input",{id:"gateway",placeholder:"wss://gateway.example.com",value:m,onChange:C=>p(C.target.value),required:!y.startsWith("linkshell:")}),f.jsx("p",{className:"field-hint",children:"电脑需先连接同一个网关。"}),f.jsx("label",{htmlFor:"pairing",children:"配对码或配对链接"}),f.jsx("input",{id:"pairing",value:y,onChange:C=>v(C.target.value),placeholder:"6 位配对码,或粘贴 linkshell://pair 链接",required:!0}),f.jsxs("p",{className:"field-hint",children:["在电脑运行 ",f.jsx("code",{children:"linkshell pair"}),"。有效期 10 分钟,成功后此浏览器会记住设备。"]}),f.jsx("button",{className:"button primary full",disabled:b.busy||e.locked,children:"配对并连接"}),f.jsx("p",{className:"field-hint",children:"自托管不使用 iTool 登录凭证。清除网站数据后需要重新配对。"})]}),f.jsx(xt,{error:b.error}),b.busy&&f.jsx("p",{className:"muted",role:"status",children:"正在连接…"})]})}function mD({...n}){return f.jsx(Z3,{"data-slot":"popover",...n})}function pD({className:n,align:e="center",sideOffset:s=4,...r}){return f.jsx(W3,{children:f.jsx(J3,{"data-slot":"popover-content",align:e,sideOffset:s,className:Pe("z-50 flex w-72 origin-(--radix-popover-content-transform-origin) flex-col gap-2.5 rounded-lg bg-popover p-2.5 text-sm text-popover-foreground shadow-md ring-1 ring-foreground/10 outline-hidden duration-100 data-[side=bottom]:slide-in-from-top-2 data-[side=left]:slide-in-from-right-2 data-[side=right]:slide-in-from-left-2 data-[side=top]:slide-in-from-bottom-2 data-[state=open]:animate-in data-[state=open]:fade-in-0 data-[state=open]:zoom-in-95 data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=closed]:zoom-out-95",n),...r})})}function gD({...n}){return f.jsx(K3,{"data-slot":"popover-anchor",...n})}var j1=1,vD=.9,yD=.8,bD=.17,zm=.1,Im=.999,xD=.9999,wD=.99,SD=/[\\\/_+.#"@\[\(\{&]/,ED=/[\\\/_+.#"@\[\(\{&]/g,CD=/[\s-]/,xE=/[\s-]/g;function Dp(n,e,s,r,o,l,u){if(l===e.length)return o===n.length?j1:wD;var d=`${o},${l}`;if(u[d]!==void 0)return u[d];for(var m=r.charAt(l),p=s.indexOf(m,o),y=0,v,b,C,T;p>=0;)v=Dp(n,e,s,r,p+1,l+1,u),v>y&&(p===o?v*=j1:SD.test(n.charAt(p-1))?(v*=yD,C=n.slice(o,p-1).match(ED),C&&o>0&&(v*=Math.pow(Im,C.length))):CD.test(n.charAt(p-1))?(v*=vD,T=n.slice(o,p-1).match(xE),T&&o>0&&(v*=Math.pow(Im,T.length))):(v*=bD,o>0&&(v*=Math.pow(Im,p-o))),n.charAt(p)!==e.charAt(l)&&(v*=xD)),(v<zm&&s.charAt(p-1)===r.charAt(l+1)||r.charAt(l+1)===r.charAt(l)&&s.charAt(p-1)!==r.charAt(l))&&(b=Dp(n,e,s,r,p+1,l+2,u),b*zm>v&&(v=b*zm)),v>y&&(y=v),p=s.indexOf(m,p+1);return u[d]=y,y}function A1(n){return n.toLowerCase().replace(xE," ")}function _D(n,e,s){return n=s&&s.length>0?`${n+" "+s.join(" ")}`:n,Dp(n,e,A1(n),A1(e),0,0,{})}function Ps(n,e,{checkForDefaultPrevented:s=!0}={}){return function(o){if(n?.(o),s===!1||!o.defaultPrevented)return e?.(o)}}function T1(n,e){if(typeof n=="function")return n(e);n!=null&&(n.current=e)}function Vr(...n){return e=>{let s=!1;const r=n.map(o=>{const l=T1(o,e);return!s&&typeof l=="function"&&(s=!0),l});if(s)return()=>{for(let o=0;o<r.length;o++){const l=r[o];typeof l=="function"?l():T1(n[o],null)}}}}function ei(...n){return x.useCallback(Vr(...n),n)}function jD(n,e){const s=x.createContext(e),r=l=>{const{children:u,...d}=l,m=x.useMemo(()=>d,Object.values(d));return f.jsx(s.Provider,{value:m,children:u})};r.displayName=n+"Provider";function o(l){const u=x.useContext(s);if(u)return u;if(e!==void 0)return e;throw new Error(`\`${l}\` must be used within \`${n}\``)}return[r,o]}function AD(n,e=[]){let s=[];function r(l,u){const d=x.createContext(u),m=s.length;s=[...s,u];const p=v=>{const{scope:b,children:C,...T}=v,S=b?.[n]?.[m]||d,E=x.useMemo(()=>T,Object.values(T));return f.jsx(S.Provider,{value:E,children:C})};p.displayName=l+"Provider";function y(v,b){const C=b?.[n]?.[m]||d,T=x.useContext(C);if(T)return T;if(u!==void 0)return u;throw new Error(`\`${v}\` must be used within \`${l}\``)}return[p,y]}const o=()=>{const l=s.map(u=>x.createContext(u));return function(d){const m=d?.[n]||l;return x.useMemo(()=>({[`__scope${n}`]:{...d,[n]:m}}),[d,m])}};return o.scopeName=n,[r,TD(o,...e)]}function TD(...n){const e=n[0];if(n.length===1)return e;const s=()=>{const r=n.map(o=>({useScope:o(),scopeName:o.scopeName}));return function(l){const u=r.reduce((d,{useScope:m,scopeName:p})=>{const v=m(l)[`__scope${p}`];return{...d,...v}},{});return x.useMemo(()=>({[`__scope${e.scopeName}`]:u}),[u])}};return s.scopeName=e.scopeName,s}var Dl=globalThis?.document?x.useLayoutEffect:()=>{},kD=Qs[" useId ".trim().toString()]||(()=>{}),ND=0;function Wa(n){const[e,s]=x.useState(kD());return Dl(()=>{s(r=>r??String(ND++))},[n]),e?`radix-${e}`:""}var OD=Qs[" useInsertionEffect ".trim().toString()]||Dl;function RD({prop:n,defaultProp:e,onChange:s=()=>{},caller:r}){const[o,l,u]=DD({defaultProp:e,onChange:s}),d=n!==void 0,m=d?n:o;{const y=x.useRef(n!==void 0);x.useEffect(()=>{const v=y.current;v!==d&&console.warn(`${r} is changing from ${v?"controlled":"uncontrolled"} to ${d?"controlled":"uncontrolled"}. Components should not switch from controlled to uncontrolled (or vice versa). Decide between using a controlled or uncontrolled value for the lifetime of the component.`),y.current=d},[d,r])}const p=x.useCallback(y=>{if(d){const v=MD(y)?y(n):y;v!==n&&u.current?.(v)}else l(y)},[d,n,l,u]);return[m,p]}function DD({defaultProp:n,onChange:e}){const[s,r]=x.useState(n),o=x.useRef(s),l=x.useRef(e);return OD(()=>{l.current=e},[e]),x.useEffect(()=>{o.current!==s&&(l.current?.(s),o.current=s)},[s,o]),[s,r,l]}function MD(n){return typeof n=="function"}function wE(n){const e=zD(n),s=x.forwardRef((r,o)=>{const{children:l,...u}=r,d=x.Children.toArray(l),m=d.find(LD);if(m){const p=m.props.children,y=d.map(v=>v===m?x.Children.count(p)>1?x.Children.only(null):x.isValidElement(p)?p.props.children:null:v);return f.jsx(e,{...u,ref:o,children:x.isValidElement(p)?x.cloneElement(p,void 0,y):null})}return f.jsx(e,{...u,ref:o,children:l})});return s.displayName=`${n}.Slot`,s}function zD(n){const e=x.forwardRef((s,r)=>{const{children:o,...l}=s;if(x.isValidElement(o)){const u=BD(o),d=UD(l,o.props);return o.type!==x.Fragment&&(d.ref=r?Vr(r,u):u),x.cloneElement(o,d)}return x.Children.count(o)>1?x.Children.only(null):null});return e.displayName=`${n}.SlotClone`,e}var ID=Symbol("radix.slottable");function LD(n){return x.isValidElement(n)&&typeof n.type=="function"&&"__radixId"in n.type&&n.type.__radixId===ID}function UD(n,e){const s={...e};for(const r in e){const o=n[r],l=e[r];/^on[A-Z]/.test(r)?o&&l?s[r]=(...d)=>{const m=l(...d);return o(...d),m}:o&&(s[r]=o):r==="style"?s[r]={...o,...l}:r==="className"&&(s[r]=[o,l].filter(Boolean).join(" "))}return{...n,...s}}function BD(n){let e=Object.getOwnPropertyDescriptor(n.props,"ref")?.get,s=e&&"isReactWarning"in e&&e.isReactWarning;return s?n.ref:(e=Object.getOwnPropertyDescriptor(n,"ref")?.get,s=e&&"isReactWarning"in e&&e.isReactWarning,s?n.props.ref:n.props.ref||n.ref)}var HD=["a","button","div","form","h2","h3","img","input","label","li","nav","ol","p","select","span","svg","ul"],Wt=HD.reduce((n,e)=>{const s=wE(`Primitive.${e}`),r=x.forwardRef((o,l)=>{const{asChild:u,...d}=o,m=u?s:e;return typeof window<"u"&&(window[Symbol.for("radix-ui")]=!0),f.jsx(m,{...d,ref:l})});return r.displayName=`Primitive.${e}`,{...n,[e]:r}},{});function $D(n,e){n&&Gr.flushSync(()=>n.dispatchEvent(e))}function Ml(n){const e=x.useRef(n);return x.useEffect(()=>{e.current=n}),x.useMemo(()=>(...s)=>e.current?.(...s),[])}function VD(n,e=globalThis?.document){const s=Ml(n);x.useEffect(()=>{const r=o=>{o.key==="Escape"&&s(o)};return e.addEventListener("keydown",r,{capture:!0}),()=>e.removeEventListener("keydown",r,{capture:!0})},[s,e])}var qD="DismissableLayer",Mp="dismissableLayer.update",PD="dismissableLayer.pointerDownOutside",FD="dismissableLayer.focusOutside",k1,SE=x.createContext({layers:new Set,layersWithOutsidePointerEventsDisabled:new Set,branches:new Set}),EE=x.forwardRef((n,e)=>{const{disableOutsidePointerEvents:s=!1,onEscapeKeyDown:r,onPointerDownOutside:o,onFocusOutside:l,onInteractOutside:u,onDismiss:d,...m}=n,p=x.useContext(SE),[y,v]=x.useState(null),b=y?.ownerDocument??globalThis?.document,[,C]=x.useState({}),T=ei(e,M=>v(M)),S=Array.from(p.layers),[E]=[...p.layersWithOutsidePointerEventsDisabled].slice(-1),_=S.indexOf(E),j=y?S.indexOf(y):-1,N=p.layersWithOutsidePointerEventsDisabled.size>0,z=j>=_,k=YD(M=>{const R=M.target,L=[...p.branches].some(H=>H.contains(R));!z||L||(o?.(M),u?.(M),M.defaultPrevented||d?.())},b),O=KD(M=>{const R=M.target;[...p.branches].some(H=>H.contains(R))||(l?.(M),u?.(M),M.defaultPrevented||d?.())},b);return VD(M=>{j===p.layers.size-1&&(r?.(M),!M.defaultPrevented&&d&&(M.preventDefault(),d()))},b),x.useEffect(()=>{if(y)return s&&(p.layersWithOutsidePointerEventsDisabled.size===0&&(k1=b.body.style.pointerEvents,b.body.style.pointerEvents="none"),p.layersWithOutsidePointerEventsDisabled.add(y)),p.layers.add(y),N1(),()=>{s&&p.layersWithOutsidePointerEventsDisabled.size===1&&(b.body.style.pointerEvents=k1)}},[y,b,s,p]),x.useEffect(()=>()=>{y&&(p.layers.delete(y),p.layersWithOutsidePointerEventsDisabled.delete(y),N1())},[y,p]),x.useEffect(()=>{const M=()=>C({});return document.addEventListener(Mp,M),()=>document.removeEventListener(Mp,M)},[]),f.jsx(Wt.div,{...m,ref:T,style:{pointerEvents:N?z?"auto":"none":void 0,...n.style},onFocusCapture:Ps(n.onFocusCapture,O.onFocusCapture),onBlurCapture:Ps(n.onBlurCapture,O.onBlurCapture),onPointerDownCapture:Ps(n.onPointerDownCapture,k.onPointerDownCapture)})});EE.displayName=qD;var GD="DismissableLayerBranch",ZD=x.forwardRef((n,e)=>{const s=x.useContext(SE),r=x.useRef(null),o=ei(e,r);return x.useEffect(()=>{const l=r.current;if(l)return s.branches.add(l),()=>{s.branches.delete(l)}},[s.branches]),f.jsx(Wt.div,{...n,ref:o})});ZD.displayName=GD;function YD(n,e=globalThis?.document){const s=Ml(n),r=x.useRef(!1),o=x.useRef(()=>{});return x.useEffect(()=>{const l=d=>{if(d.target&&!r.current){let m=function(){CE(PD,s,p,{discrete:!0})};const p={originalEvent:d};d.pointerType==="touch"?(e.removeEventListener("click",o.current),o.current=m,e.addEventListener("click",o.current,{once:!0})):m()}else e.removeEventListener("click",o.current);r.current=!1},u=window.setTimeout(()=>{e.addEventListener("pointerdown",l)},0);return()=>{window.clearTimeout(u),e.removeEventListener("pointerdown",l),e.removeEventListener("click",o.current)}},[e,s]),{onPointerDownCapture:()=>r.current=!0}}function KD(n,e=globalThis?.document){const s=Ml(n),r=x.useRef(!1);return x.useEffect(()=>{const o=l=>{l.target&&!r.current&&CE(FD,s,{originalEvent:l},{discrete:!1})};return e.addEventListener("focusin",o),()=>e.removeEventListener("focusin",o)},[e,s]),{onFocusCapture:()=>r.current=!0,onBlurCapture:()=>r.current=!1}}function N1(){const n=new CustomEvent(Mp);document.dispatchEvent(n)}function CE(n,e,s,{discrete:r}){const o=s.originalEvent.target,l=new CustomEvent(n,{bubbles:!1,cancelable:!0,detail:s});e&&o.addEventListener(n,e,{once:!0}),r?$D(o,l):o.dispatchEvent(l)}var Lm="focusScope.autoFocusOnMount",Um="focusScope.autoFocusOnUnmount",O1={bubbles:!1,cancelable:!0},XD="FocusScope",_E=x.forwardRef((n,e)=>{const{loop:s=!1,trapped:r=!1,onMountAutoFocus:o,onUnmountAutoFocus:l,...u}=n,[d,m]=x.useState(null),p=Ml(o),y=Ml(l),v=x.useRef(null),b=ei(e,S=>m(S)),C=x.useRef({paused:!1,pause(){this.paused=!0},resume(){this.paused=!1}}).current;x.useEffect(()=>{if(r){let S=function(N){if(C.paused||!d)return;const z=N.target;d.contains(z)?v.current=z:Us(v.current,{select:!0})},E=function(N){if(C.paused||!d)return;const z=N.relatedTarget;z!==null&&(d.contains(z)||Us(v.current,{select:!0}))},_=function(N){if(document.activeElement===document.body)for(const k of N)k.removedNodes.length>0&&Us(d)};document.addEventListener("focusin",S),document.addEventListener("focusout",E);const j=new MutationObserver(_);return d&&j.observe(d,{childList:!0,subtree:!0}),()=>{document.removeEventListener("focusin",S),document.removeEventListener("focusout",E),j.disconnect()}}},[r,d,C.paused]),x.useEffect(()=>{if(d){D1.add(C);const S=document.activeElement;if(!d.contains(S)){const _=new CustomEvent(Lm,O1);d.addEventListener(Lm,p),d.dispatchEvent(_),_.defaultPrevented||(QD(nM(jE(d)),{select:!0}),document.activeElement===S&&Us(d))}return()=>{d.removeEventListener(Lm,p),setTimeout(()=>{const _=new CustomEvent(Um,O1);d.addEventListener(Um,y),d.dispatchEvent(_),_.defaultPrevented||Us(S??document.body,{select:!0}),d.removeEventListener(Um,y),D1.remove(C)},0)}}},[d,p,y,C]);const T=x.useCallback(S=>{if(!s&&!r||C.paused)return;const E=S.key==="Tab"&&!S.altKey&&!S.ctrlKey&&!S.metaKey,_=document.activeElement;if(E&&_){const j=S.currentTarget,[N,z]=WD(j);N&&z?!S.shiftKey&&_===z?(S.preventDefault(),s&&Us(N,{select:!0})):S.shiftKey&&_===N&&(S.preventDefault(),s&&Us(z,{select:!0})):_===j&&S.preventDefault()}},[s,r,C.paused]);return f.jsx(Wt.div,{tabIndex:-1,...u,ref:b,onKeyDown:T})});_E.displayName=XD;function QD(n,{select:e=!1}={}){const s=document.activeElement;for(const r of n)if(Us(r,{select:e}),document.activeElement!==s)return}function WD(n){const e=jE(n),s=R1(e,n),r=R1(e.reverse(),n);return[s,r]}function jE(n){const e=[],s=document.createTreeWalker(n,NodeFilter.SHOW_ELEMENT,{acceptNode:r=>{const o=r.tagName==="INPUT"&&r.type==="hidden";return r.disabled||r.hidden||o?NodeFilter.FILTER_SKIP:r.tabIndex>=0?NodeFilter.FILTER_ACCEPT:NodeFilter.FILTER_SKIP}});for(;s.nextNode();)e.push(s.currentNode);return e}function R1(n,e){for(const s of n)if(!JD(s,{upTo:e}))return s}function JD(n,{upTo:e}){if(getComputedStyle(n).visibility==="hidden")return!0;for(;n;){if(e!==void 0&&n===e)return!1;if(getComputedStyle(n).display==="none")return!0;n=n.parentElement}return!1}function eM(n){return n instanceof HTMLInputElement&&"select"in n}function Us(n,{select:e=!1}={}){if(n&&n.focus){const s=document.activeElement;n.focus({preventScroll:!0}),n!==s&&eM(n)&&e&&n.select()}}var D1=tM();function tM(){let n=[];return{add(e){const s=n[0];e!==s&&s?.pause(),n=M1(n,e),n.unshift(e)},remove(e){n=M1(n,e),n[0]?.resume()}}}function M1(n,e){const s=[...n],r=s.indexOf(e);return r!==-1&&s.splice(r,1),s}function nM(n){return n.filter(e=>e.tagName!=="A")}var aM="Portal",AE=x.forwardRef((n,e)=>{const{container:s,...r}=n,[o,l]=x.useState(!1);Dl(()=>l(!0),[]);const u=s||o&&globalThis?.document?.body;return u?kA.createPortal(f.jsx(Wt.div,{...r,ref:e}),u):null});AE.displayName=aM;function sM(n,e){return x.useReducer((s,r)=>e[s][r]??s,n)}var Hd=n=>{const{present:e,children:s}=n,r=rM(e),o=typeof s=="function"?s({present:r.isPresent}):x.Children.only(s),l=ei(r.ref,iM(o));return typeof s=="function"||r.isPresent?x.cloneElement(o,{ref:l}):null};Hd.displayName="Presence";function rM(n){const[e,s]=x.useState(),r=x.useRef(null),o=x.useRef(n),l=x.useRef("none"),u=n?"mounted":"unmounted",[d,m]=sM(u,{mounted:{UNMOUNT:"unmounted",ANIMATION_OUT:"unmountSuspended"},unmountSuspended:{MOUNT:"mounted",ANIMATION_END:"unmounted"},unmounted:{MOUNT:"mounted"}});return x.useEffect(()=>{const p=_u(r.current);l.current=d==="mounted"?p:"none"},[d]),Dl(()=>{const p=r.current,y=o.current;if(y!==n){const b=l.current,C=_u(p);n?m("MOUNT"):C==="none"||p?.display==="none"?m("UNMOUNT"):m(y&&b!==C?"ANIMATION_OUT":"UNMOUNT"),o.current=n}},[n,m]),Dl(()=>{if(e){let p;const y=e.ownerDocument.defaultView??window,v=C=>{const S=_u(r.current).includes(CSS.escape(C.animationName));if(C.target===e&&S&&(m("ANIMATION_END"),!o.current)){const E=e.style.animationFillMode;e.style.animationFillMode="forwards",p=y.setTimeout(()=>{e.style.animationFillMode==="forwards"&&(e.style.animationFillMode=E)})}},b=C=>{C.target===e&&(l.current=_u(r.current))};return e.addEventListener("animationstart",b),e.addEventListener("animationcancel",v),e.addEventListener("animationend",v),()=>{y.clearTimeout(p),e.removeEventListener("animationstart",b),e.removeEventListener("animationcancel",v),e.removeEventListener("animationend",v)}}else m("ANIMATION_END")},[e,m]),{isPresent:["mounted","unmountSuspended"].includes(d),ref:x.useCallback(p=>{r.current=p?getComputedStyle(p):null,s(p)},[])}}function _u(n){return n?.animationName||"none"}function iM(n){let e=Object.getOwnPropertyDescriptor(n.props,"ref")?.get,s=e&&"isReactWarning"in e&&e.isReactWarning;return s?n.ref:(e=Object.getOwnPropertyDescriptor(n,"ref")?.get,s=e&&"isReactWarning"in e&&e.isReactWarning,s?n.props.ref:n.props.ref||n.ref)}var Bm=0;function oM(){x.useEffect(()=>{const n=document.querySelectorAll("[data-radix-focus-guard]");return document.body.insertAdjacentElement("afterbegin",n[0]??z1()),document.body.insertAdjacentElement("beforeend",n[1]??z1()),Bm++,()=>{Bm===1&&document.querySelectorAll("[data-radix-focus-guard]").forEach(e=>e.remove()),Bm--}},[])}function z1(){const n=document.createElement("span");return n.setAttribute("data-radix-focus-guard",""),n.tabIndex=0,n.style.outline="none",n.style.opacity="0",n.style.position="fixed",n.style.pointerEvents="none",n}var $d="Dialog",[TE]=AD($d),[lM,na]=TE($d),kE=n=>{const{__scopeDialog:e,children:s,open:r,defaultOpen:o,onOpenChange:l,modal:u=!0}=n,d=x.useRef(null),m=x.useRef(null),[p,y]=RD({prop:r,defaultProp:o??!1,onChange:l,caller:$d});return f.jsx(lM,{scope:e,triggerRef:d,contentRef:m,contentId:Wa(),titleId:Wa(),descriptionId:Wa(),open:p,onOpenChange:y,onOpenToggle:x.useCallback(()=>y(v=>!v),[y]),modal:u,children:s})};kE.displayName=$d;var NE="DialogTrigger",cM=x.forwardRef((n,e)=>{const{__scopeDialog:s,...r}=n,o=na(NE,s),l=ei(e,o.triggerRef);return f.jsx(Wt.button,{type:"button","aria-haspopup":"dialog","aria-expanded":o.open,"aria-controls":o.contentId,"data-state":Dg(o.open),...r,ref:l,onClick:Ps(n.onClick,o.onOpenToggle)})});cM.displayName=NE;var Og="DialogPortal",[uM,OE]=TE(Og,{forceMount:void 0}),RE=n=>{const{__scopeDialog:e,forceMount:s,children:r,container:o}=n,l=na(Og,e);return f.jsx(uM,{scope:e,forceMount:s,children:x.Children.map(r,u=>f.jsx(Hd,{present:s||l.open,children:f.jsx(AE,{asChild:!0,container:o,children:u})}))})};RE.displayName=Og;var fd="DialogOverlay",DE=x.forwardRef((n,e)=>{const s=OE(fd,n.__scopeDialog),{forceMount:r=s.forceMount,...o}=n,l=na(fd,n.__scopeDialog);return l.modal?f.jsx(Hd,{present:r||l.open,children:f.jsx(fM,{...o,ref:e})}):null});DE.displayName=fd;var dM=wE("DialogOverlay.RemoveScroll"),fM=x.forwardRef((n,e)=>{const{__scopeDialog:s,...r}=n,o=na(fd,s);return f.jsx(co,{as:dM,allowPinchZoom:!0,shards:[o.contentRef],children:f.jsx(Wt.div,{"data-state":Dg(o.open),...r,ref:e,style:{pointerEvents:"auto",...r.style}})})}),qr="DialogContent",ME=x.forwardRef((n,e)=>{const s=OE(qr,n.__scopeDialog),{forceMount:r=s.forceMount,...o}=n,l=na(qr,n.__scopeDialog);return f.jsx(Hd,{present:r||l.open,children:l.modal?f.jsx(hM,{...o,ref:e}):f.jsx(mM,{...o,ref:e})})});ME.displayName=qr;var hM=x.forwardRef((n,e)=>{const s=na(qr,n.__scopeDialog),r=x.useRef(null),o=ei(e,s.contentRef,r);return x.useEffect(()=>{const l=r.current;if(l)return Il(l)},[]),f.jsx(zE,{...n,ref:o,trapFocus:s.open,disableOutsidePointerEvents:!0,onCloseAutoFocus:Ps(n.onCloseAutoFocus,l=>{l.preventDefault(),s.triggerRef.current?.focus()}),onPointerDownOutside:Ps(n.onPointerDownOutside,l=>{const u=l.detail.originalEvent,d=u.button===0&&u.ctrlKey===!0;(u.button===2||d)&&l.preventDefault()}),onFocusOutside:Ps(n.onFocusOutside,l=>l.preventDefault())})}),mM=x.forwardRef((n,e)=>{const s=na(qr,n.__scopeDialog),r=x.useRef(!1),o=x.useRef(!1);return f.jsx(zE,{...n,ref:e,trapFocus:!1,disableOutsidePointerEvents:!1,onCloseAutoFocus:l=>{n.onCloseAutoFocus?.(l),l.defaultPrevented||(r.current||s.triggerRef.current?.focus(),l.preventDefault()),r.current=!1,o.current=!1},onInteractOutside:l=>{n.onInteractOutside?.(l),l.defaultPrevented||(r.current=!0,l.detail.originalEvent.type==="pointerdown"&&(o.current=!0));const u=l.target;s.triggerRef.current?.contains(u)&&l.preventDefault(),l.detail.originalEvent.type==="focusin"&&o.current&&l.preventDefault()}})}),zE=x.forwardRef((n,e)=>{const{__scopeDialog:s,trapFocus:r,onOpenAutoFocus:o,onCloseAutoFocus:l,...u}=n,d=na(qr,s),m=x.useRef(null),p=ei(e,m);return oM(),f.jsxs(f.Fragment,{children:[f.jsx(_E,{asChild:!0,loop:!0,trapped:r,onMountAutoFocus:o,onUnmountAutoFocus:l,children:f.jsx(EE,{role:"dialog",id:d.contentId,"aria-describedby":d.descriptionId,"aria-labelledby":d.titleId,"data-state":Dg(d.open),...u,ref:p,onDismiss:()=>d.onOpenChange(!1)})}),f.jsxs(f.Fragment,{children:[f.jsx(yM,{titleId:d.titleId}),f.jsx(xM,{contentRef:m,descriptionId:d.descriptionId})]})]})}),Rg="DialogTitle",pM=x.forwardRef((n,e)=>{const{__scopeDialog:s,...r}=n,o=na(Rg,s);return f.jsx(Wt.h2,{id:o.titleId,...r,ref:e})});pM.displayName=Rg;var IE="DialogDescription",gM=x.forwardRef((n,e)=>{const{__scopeDialog:s,...r}=n,o=na(IE,s);return f.jsx(Wt.p,{id:o.descriptionId,...r,ref:e})});gM.displayName=IE;var LE="DialogClose",vM=x.forwardRef((n,e)=>{const{__scopeDialog:s,...r}=n,o=na(LE,s);return f.jsx(Wt.button,{type:"button",...r,ref:e,onClick:Ps(n.onClick,()=>o.onOpenChange(!1))})});vM.displayName=LE;function Dg(n){return n?"open":"closed"}var UE="DialogTitleWarning",[_9,BE]=jD(UE,{contentName:qr,titleName:Rg,docsSlug:"dialog"}),yM=({titleId:n})=>{const e=BE(UE),s=`\`${e.contentName}\` requires a \`${e.titleName}\` for the component to be accessible for screen reader users.
|
|
162
162
|
|
|
163
163
|
If you want to hide the \`${e.titleName}\`, you can wrap it with our VisuallyHidden component.
|
|
164
164
|
|
|
@@ -201,8 +201,8 @@ Accept-Encoding: identity\r
|
|
|
201
201
|
Content-Length: ${l.length}\r
|
|
202
202
|
${N.map(([z,k])=>`${z}: ${k}\r
|
|
203
203
|
`).join("")}\r
|
|
204
|
-
`)),l.length&&j.write(l)},j=>S(new Error(String(j))))})}function S8(){const n=window.__LINKSHELL_CONFIG__?.previewOrigin,e=void 0;if(!n&&!e)return;const s=new URL(n??e);if(!(s.origin===location.origin||!["http:","https:"].includes(s.protocol)||s.username||s.password)&&!(location.protocol==="https:"&&s.protocol!=="https:"))return s.origin}function E8({port:n}){const{streams:e}=yt(),s=x.useRef(null),[r,o]=x.useState(),[l]=x.useState(()=>crypto.randomUUID()),u=S8();return x.useEffect(()=>{if(!u)return;let d=!0;const m=new Map,p=new Set;let y=0;const v=new Map,b=new Map,C=S=>{d&&s.current?.contentWindow?.postMessage({...S,channel:l},u)},T=S=>{if(S.source!==s.current?.contentWindow||S.origin!==u||S.data?.channel!==l)return;const E=S.data;if(E.type==="preview-ready"&&C({type:"preview-init",bootstrap:Lp.toString()}),E.type==="http-cancel"&&b.get(E.id)?.abort(),E.type==="http-request"){if(++y>128){y--,C({type:"http-error",id:E.id,error:"同时请求过多"});return}const _=(E.headers??[]).filter(([N])=>!/^(cookie|proxy-authorization)$/i.test(N));v.size&&_.push(["cookie",[...v].map(([N,z])=>`${N}=${z}`).join("; ")]);const j=new AbortController;b.set(E.id,j),w8(e,n,E.path??"/",E.method??"GET",_,E.body?new Uint8Array(E.body):new Uint8Array,j.signal).then(async N=>{for(const[M,R]of N.headers)if(M==="set-cookie"){const L=R.split(";")[0],H=L.indexOf("=");if(H>0){const V=L.slice(0,H);/max-age=0/i.test(R)?v.delete(V):v.set(V,L.slice(H+1))}}let z=N.body;const k=N.headers.find(([M])=>M==="content-encoding")?.[1];if(E.method!=="HEAD"&&![204,205,304].includes(N.status)&&(k==="gzip"||k==="deflate"))z=z.pipeThrough(new DecompressionStream(k));else if(k&&!["identity","gzip","deflate"].includes(k))throw new Error(`预览暂不支持 ${k} 压缩`);C({type:"http-head",id:E.id,status:N.status,headers:N.headers});const O=z.getReader();try{for(;d;){const M=await O.read();if(M.done)break;C({type:"http-chunk",id:E.id,body:M.value})}}finally{O.releaseLock(),d||j.abort()}C({type:"http-end",id:E.id})}).catch(N=>{j.abort(),C({type:"http-error",id:E.id,error:String(N)})}).finally(()=>{b.delete(E.id),y--})}if(E.type==="ws-open"){if(m.has(E.id)||p.has(E.id)||m.size+p.size>=24)return;try{const _=new URL(E.url,u);if(![new URL(u).hostname,"localhost","127.0.0.1"].includes(_.hostname)||!["ws:","wss:"].includes(_.protocol))throw new Error("仅代理当前预览端口的 WebSocket");const N=_.pathname.replace(new RegExp(`^/preview/view/${l}/`),"/")+_.search;p.add(E.id),lC(e,n,N,{open:()=>C({type:"ws-open",id:E.id}),data:z=>C({type:"ws-data",id:E.id,data:z}),close:z=>{p.delete(E.id),m.delete(E.id),C({type:"ws-close",id:E.id,reason:z})}},E.protocols).then(z=>{!d||!p.has(E.id)?z.close():(p.delete(E.id),m.set(E.id,z))},z=>{p.delete(E.id),C({type:"ws-close",id:E.id,reason:String(z)})})}catch(_){C({type:"ws-close",id:E.id,reason:String(_)})}}E.type==="ws-send"&&(typeof E.data=="string"||E.data instanceof ArrayBuffer)&&m.get(E.id)?.send(E.data),E.type==="ws-close"&&(p.delete(E.id),m.get(E.id)?.close(),m.delete(E.id))};return window.addEventListener("message",T),()=>{d=!1,window.removeEventListener("message",T);for(const S of m.values())S.close();p.clear();for(const S of b.values())S.abort();b.clear()}},[e,n,l,u]),u?f.jsxs(f.Fragment,{children:[f.jsx(xt,{error:r}),f.jsx("iframe",{className:"port-frame",ref:s,title:`端口 ${n} 预览`,src:`${u}/preview/bridge.html#${l}`,sandbox:"allow-scripts allow-same-origin allow-forms allow-downloads allow-modals allow-pointer-lock",allow:"autoplay; fullscreen",onLoad:()=>s.current?.contentWindow?.postMessage({channel:l,type:"preview-init",bootstrap:Lp.toString()},u),onError:()=>o("隔离预览页面加载失败,请检查预览域名配置")})]}):f.jsxs("p",{className:"notice-card",children:["此部署尚未配置独立的预览域名。管理员需要设置 ",f.jsx("code",{children:"previewOrigin"})," ","并在该域名部署网页制品中的 preview 目录。开发网页与账号页面隔离,避免项目脚本读取登录凭证。"]})}function C8(){const{link:n}=yt(),e=ta(()=>n.call("ports.list",{}),[n],1e4),[s,r]=x.useState(),[o,l]=x.useState("");return f.jsxs("section",{className:"ports-page",children:[f.jsxs("div",{className:"browser-toolbar",children:[f.jsx("h2",{children:"端口预览"}),f.jsxs("form",{className:"inline-form",onSubmit:u=>{u.preventDefault(),r(Number(o))},children:[f.jsx("input",{"aria-label":"预览端口",type:"number",min:"1",max:"65535",value:o,onChange:u=>l(u.target.value),required:!0,placeholder:"端口号"}),f.jsx("button",{className:"button secondary",children:"打开"})]})]}),f.jsx(Sa,{...e}),f.jsx("div",{className:"terminal-tabs",children:e.value?.ports.map(u=>f.jsxs("button",{className:s===u.port?"selected":"",onClick:()=>r(u.port),children:[u.port," · ",u.title??u.process,!u.http&&"(未识别为 HTTP)"]},u.port))}),s?f.jsx(E8,{port:s},s):f.jsx("p",{className:"muted",children:"选择电脑上的 HTTP 服务。请求通过加密通道传输。"})]})}const _8=x.lazy(()=>up(()=>import("./Prototype-
|
|
205
|
-
`,"linkshell host --daemon"]}),f.jsx("button",{className:"button primary",disabled:!n.ready,onClick:()=>s(!0),children:n.ready?Zs==="self-hosted"?"配对电脑":"登录或配对电脑":"正在准备设备身份…"}),f.jsx("p",{className:"muted",children:Zs==="self-hosted"?"运行 linkshell pair,输入此网关的配对码即可连接。":"官方服务使用 iTool 账号,自托管使用自己的网关与配对码。"}),n.computers.map(y=>f.jsxs("button",{className:"button secondary",onClick:()=>Qt.select(y),children:[y.machine.name," ·"," ",y.machine.online?"在线":"离线"]},y.key)),f.jsx("a",{className:"text-button",href:"?demo=1",children:"查看独立 UI 演示"})]})]}),e&&f.jsx(hD,{close:()=>s(!1)})]})}function T8({view:n,navigate:e,connect:s}){const r=lt(y=>y),[o,l]=x.useState(),[u,d]=x.useState(),{store:m}=yt(),p=r.sessions[n];return x.useEffect(()=>{n==="archive"&&m.getState().loadArchived()},[m,n]),f.jsxs(f.Fragment,{children:[r.status!=="online"&&f.jsxs("div",{className:"connection-banner",role:"status",children:[f.jsx("span",{children:r.statusDetail??"正在连接电脑…"}),f.jsx("button",{onClick:()=>Qt.reconnect(),children:"重新连接"})]}),p?f.jsx(b8,{session:p,navigate:e},p.id):f.jsxs("div",{className:"overview live-overview",children:[["home","archive"].includes(n)&&f.jsx(k8,{archived:n==="archive",navigate:e,create:()=>l(null)}),n==="projects"&&f.jsxs("section",{children:[f.jsxs("div",{className:"page-heading",children:[f.jsx("h1",{children:"项目"}),f.jsx("button",{className:"button primary",onClick:()=>l(null),children:"新建会话"})]}),r.projects.map(y=>f.jsxs("article",{className:"notice-card",children:[f.jsxs("div",{className:"browser-toolbar",children:[f.jsx("strong",{children:y.name}),f.jsx("span",{className:"muted",children:y.branch}),f.jsx("button",{className:"text-button",onClick:()=>l(y.cwd),children:"在此新建"})]}),f.jsx("p",{className:"muted",children:y.cwd}),f.jsx("div",{className:"task-list",children:Object.values(r.sessions).filter(v=>v.cwd===y.cwd||v.worktree?.source===y.cwd).map(v=>f.jsx(cC,{session:v,open:()=>e(v.id)},v.id))})]},y.cwd))]}),n==="computers"&&f.jsx(O8,{connect:s}),n==="files"&&f.jsxs(f.Fragment,{children:[f.jsx("h1",{children:"文件"}),f.jsx(Ug,{})]}),n==="terminals"&&f.jsx(iC,{selected:u,onSelect:d}),n==="worktrees"&&f.jsx(f8,{}),n==="ports"&&f.jsx(C8,{}),n==="screen"&&f.jsx(y8,{}),!["home","archive","projects","computers","files","terminals","worktrees","ports","screen"].includes(n)&&f.jsxs("div",{className:"empty-state",children:[f.jsx("h2",{children:"会话尚未加载或已被移除"}),f.jsx("button",{className:"text-button",onClick:()=>e("home"),children:"返回首页"})]})]}),o!==void 0&&f.jsx(N8,{initialDirectory:o??void 0,close:()=>l(void 0),created:y=>{l(void 0),e(y.id)}})]})}function cC({session:n,open:e}){return f.jsxs("button",{className:"task-row",onClick:e,children:[f.jsxs("span",{className:"row-avatar",children:[f.jsx(Bd,{agent:n.agent}),f.jsx("span",{className:`tiny-status ${n.state}`})]}),f.jsxs("span",{className:"task-info",children:[f.jsx("strong",{children:Tr(n)}),f.jsxs("span",{children:[f.jsx("span",{className:"project-label",children:dd(n.worktree?.source??n.cwd)}),f.jsx("span",{className:"separator",children:"·"}),f.jsx("span",{className:n.state==="running"?"running-copy":"",children:n.activity?.title??n.preview??n.agent})]})]}),f.jsxs("span",{className:"task-meta",children:[f.jsx("small",{children:new Date(n.updatedAt).toLocaleTimeString([],{hour:"2-digit",minute:"2-digit"})}),f.jsx($r,{state:n.state})]}),f.jsx(Tt,{name:"chevron",size:14})]})}function k8({archived:n,navigate:e,create:s}){const r=lt(v=>v),o=pn(),[l,u]=x.useState(""),[d,m]=x.useState("all"),p=Nt(),y=Object.values(r.sessions).filter(v=>v.archived===n&&`${Tr(v)} ${v.cwd} ${v.agent} ${v.preview??""}`.toLowerCase().includes(l.toLowerCase())&&(d==="all"||v.state===d)).sort((v,b)=>b.updatedAt-v.updatedAt);return f.jsxs(f.Fragment,{children:[f.jsxs("div",{className:"page-heading",children:[f.jsxs("div",{children:[f.jsx("h1",{children:n?"已归档":"首页"}),f.jsxs("p",{className:"host-summary",children:[f.jsx("span",{className:r.status==="online"?"online-dot":"offline-dot"}),r.machine?.hostname??"正在连接",f.jsxs("span",{className:"waiting-copy",children:[y.filter(v=>v.state==="waiting").length," ","项需要你"]})]})]}),f.jsxs("button",{className:"button primary",disabled:r.status!=="online",onClick:s,children:[f.jsx(Tt,{name:"plus"}),"新建任务"]})]}),f.jsxs("div",{className:"home-controls",children:[f.jsxs("label",{className:"search-box",children:[f.jsx(Tt,{name:"search"}),f.jsx("input",{"aria-label":"搜索会话",placeholder:"搜索会话、项目或 Agent",value:l,onChange:v=>u(v.target.value)})]}),f.jsx("div",{className:"filters",children:[{id:"all",name:"全部"},{id:"running",name:"进行中"},{id:"waiting",name:"需要你"},{id:"idle",name:"已完成"}].map(v=>f.jsx("button",{className:d===v.id?"selected":"",onClick:()=>m(v.id),children:v.name},v.id))})]}),f.jsx(xt,{error:r.sessionsError??p.error}),!r.sessionsLoaded&&!r.sessionsError&&f.jsx("p",{className:"muted",children:"正在加载会话…"}),["waiting","running","recent"].map(v=>{const b=y.filter(C=>v==="recent"?!["waiting","running"].includes(C.state):C.state===v);return b.length?f.jsxs("section",{className:"session-group",children:[f.jsx("div",{className:`section-heading ${v==="waiting"?"waiting-heading":""}`,children:f.jsxs("h2",{children:[v==="waiting"?"需要你":v==="running"?"进行中":"最近",f.jsx("span",{children:b.length})]})}),f.jsx("div",{className:"task-list",children:b.map(C=>f.jsxs("div",{children:[f.jsx(cC,{session:C,open:()=>e(C.id)}),C.permission&&v==="waiting"&&f.jsx(Ig,{permission:C.permission,sessionId:C.id})]},C.id))})]},v):null}),r.sessionsLoaded&&!y.length&&f.jsxs("div",{className:"empty-state",children:[f.jsx("h3",{children:l?"没有找到会话":n?"暂无已归档会话":"开始第一个任务"}),f.jsx("p",{children:"会话保存在当前电脑,手机与网页共享同一份记录。"})]}),f.jsx("button",{className:"text-button",disabled:p.busy,onClick:()=>void p.run(()=>o.refresh()),children:"刷新列表"})]})}function N8({initialDirectory:n,close:e,created:s}){const r=lt(R=>R.machine),o=lt(R=>R.projects),l=pn(),{store:u}=yt(),d=lt(R=>R.status==="online"),m=Nt(),[p,y]=x.useState(r?.agents.find(R=>R.installed&&!R.problem&&R.auth?.state!=="missing"&&R.tier!=="terminal")?.id??""),[v,b]=x.useState(n??o[0]?.cwd??r?.home??""),[C,T]=x.useState(""),[S,E]=x.useState(!1),[_,j]=x.useState(!1),[N,z]=x.useState(v);x.useEffect(()=>{E(!1);const R=setTimeout(()=>z(v),250);return()=>clearTimeout(R)},[v]);const k=ta(()=>N.trim()?l.gitInfo(N):Promise.resolve(void 0),[u,N]),O=r?.agents.find(R=>R.id===p),M=!!O&&O.installed&&!O.problem&&O.auth?.state!=="missing"&&O.tier!=="terminal";return f.jsxs(Rl,{title:"新建任务",close:e,wide:_,children:[f.jsx(Pd,{agent:p}),_?f.jsx(Ug,{start:v,directoriesOnly:!0,onPick:R=>{b(R),j(!1)}}):f.jsxs("form",{className:"new-form",onSubmit:R=>{R.preventDefault(),!(!d||!M||!v.trim())&&m.run(async()=>s(await l.createSession({agent:p,cwd:v,worktree:S&&!!k.value&&N===v,prompt:C.trim()?[{type:"text",text:C.trim()}]:void 0})))},children:[f.jsxs("label",{children:["任务描述",f.jsx("textarea",{value:C,onChange:R=>T(R.target.value),rows:4,placeholder:"想让 Agent 完成什么?"})]}),f.jsxs("label",{children:["Agent",f.jsx(Dd,{label:"Agent",value:p,onValueChange:y,options:(r?.agents??[]).map(R=>({value:R.id,label:R.label+(R.installed?R.auth?.state==="missing"?" · 未登录":R.tier==="terminal"?" · 请从终端打开":R.problem?` · ${R.problem}`:"":" · 未安装"),disabled:!R.installed||!!R.problem||R.auth?.state==="missing"||R.tier==="terminal"}))})]}),f.jsxs("label",{children:["工作目录",f.jsx("input",{value:v,onChange:R=>b(R.target.value),required:!0})]}),f.jsx("button",{type:"button",className:"text-button",onClick:()=>j(!0),children:"浏览电脑目录"}),k.value&&N===v&&f.jsxs("label",{className:"choice-option",children:[f.jsx("input",{type:"checkbox",checked:S,onChange:R=>E(R.target.checked)}),"在新 worktree 中工作"]}),f.jsx(xt,{error:m.error}),f.jsx("button",{className:"button primary full",disabled:m.busy||!d||!M||!v.trim(),children:"创建任务"})]})]})}function O8({connect:n}){const e=Jr(),s=Md(Qt.state),r=lt(d=>d.machine),{link:o}=yt(),l=Nt(),u=ta(()=>o.call("gateway.status",{}),[o],1e4);return f.jsxs("section",{children:[f.jsxs("div",{className:"page-heading",children:[f.jsx("h1",{children:"电脑"}),f.jsx("button",{className:"button primary",onClick:n,children:"添加电脑"})]}),f.jsx(xt,{error:l.error}),s.computers.map(d=>f.jsxs("article",{className:"notice-card",children:[f.jsxs("div",{className:"browser-toolbar",children:[f.jsx(Tt,{name:"computer"}),f.jsx("strong",{children:d.machine.name}),f.jsx("span",{className:"muted",children:d.machine.online?"在线":"离线"}),f.jsx("button",{className:"text-button",onClick:()=>Qt.select(d),children:"切换到此电脑"}),f.jsx("button",{className:"text-button danger-text",onClick:async()=>{await e.confirm(`移除「${d.machine.name}」的连接关系?需要时可重新登录或配对。`)&&l.run(()=>Qt.forget(d))},children:"移除"})]}),f.jsx("p",{className:"muted",children:d.gateway})]},d.key)),f.jsx("h2",{children:"当前电脑"}),f.jsxs("p",{className:"muted",children:[r?.hostname," · ",r?.platform," · Host ",r?.hostVersion]}),f.jsx("h3",{children:"Agent"}),f.jsx("div",{className:"agent-list",children:r?.agents.map(d=>f.jsxs("article",{children:[f.jsx(Bd,{agent:d.id}),f.jsxs("div",{children:[f.jsx("strong",{children:d.label}),f.jsxs("p",{children:[d.installed?d.version??"已安装":"未安装"," ·"," ",d.auth?.state==="ok"?"已登录":d.auth?.state==="missing"?"需要登录":"登录状态未知"]}),(d.problem||d.auth?.hint)&&f.jsx("p",{className:"muted",children:d.problem??d.auth?.hint})]})]},d.id))}),f.jsx(a8,{}),f.jsx("h3",{children:"配对设备"}),f.jsx(Sa,{...u}),u.value?.devices.map(d=>f.jsx("article",{className:"notice-card",children:f.jsxs("div",{className:"browser-toolbar",children:[f.jsx("strong",{children:d.name}),f.jsx("span",{className:"muted",children:d.online?"在线":"离线"}),f.jsx("button",{className:"text-button danger-text",onClick:async()=>{await e.confirm(`撤销「${d.name}」的配对?该设备将需要重新配对。`)&&l.run(async()=>{await o.call("devices.revoke",{deviceId:d.id}),u.reload()})},children:"撤销配对"})]})},d.id))]})}const R8=["#4a6cf7","#7d95ff"],D8=["rgba(74,108,247,0.11)","rgba(125,149,255,0.18)"],M8=["#4a6cf7","#7d95ff"],z8=["rgba(232,131,12,0.12)","rgba(255,166,61,0.16)"],I8=["rgba(15,149,96,0.12)","rgba(61,214,140,0.15)"],L8=["rgba(220,61,61,0.10)","rgba(255,107,107,0.15)"],U8=["#F0F0F4","#26262B"],B8=["#f1f1f6","#1c1c22"],H8=["#2a2b35","#e4e4ec"],$8=["rgba(15,149,96,0.12)","rgba(61,214,140,0.14)"],V8=["rgba(220,61,61,0.10)","rgba(255,107,107,0.14)"],q8=["#0b7a4f","#7fddb4"],P8=["#b42f2f","#ff9a9a"],F8=["#000000","#FFFFFF"],G8=["rgba(60,60,67,0.6)","rgba(235,235,245,0.6)"],Z8=["rgba(60,60,67,0.3)","rgba(235,235,245,0.3)"],Y8=["rgba(60,60,67,0.3)","rgba(235,235,245,0.3)"],K8=["rgba(60,60,67,0.18)","rgba(84,84,88,0.6)"],X8=["#F2F2F7","#000000"],Q8=["#FFFFFF","#1C1C1E"],W8=["#FFFFFF","#2C2C2E"],J8=["#F2F2F7","#1C1C1E"],e9=["#FFFFFF","#000000"],t9=["rgba(118,118,128,0.12)","rgba(118,118,128,0.24)"],n9=["rgba(120,120,128,0.16)","rgba(120,120,128,0.32)"],a9=["#E8830C","#FF9F0A"],s9=["#0F9560","#30D158"],r9=["#DC3D3D","#FF453A"],i9=["#F2F2F7","#1C1C1E"],o9=["#FFFFFF","#2C2C2E"],l9={accent:R8,accentSoft:D8,running:M8,waitingSoft:z8,okSoft:I8,dangerSoft:L8,userBubble:U8,code:B8,codeText:H8,diffAdd:$8,diffDel:V8,diffAddText:q8,diffDelText:P8,label:F8,secondaryLabel:G8,tertiaryLabel:Z8,placeholder:Y8,separator:K8,background:X8,card:Q8,cardRaised:W8,inset:J8,plain:e9,fill:t9,fillStrong:n9,waiting:a9,ok:s9,danger:r9,sheet:i9,sheetCard:o9},Vm=n=>Object.entries(l9).map(([e,s])=>`--${e}: ${s[n]};`).join(`
|
|
204
|
+
`)),l.length&&j.write(l)},j=>S(new Error(String(j))))})}function S8(){const n=window.__LINKSHELL_CONFIG__?.previewOrigin,e=void 0;if(!n&&!e)return;const s=new URL(n??e);if(!(s.origin===location.origin||!["http:","https:"].includes(s.protocol)||s.username||s.password)&&!(location.protocol==="https:"&&s.protocol!=="https:"))return s.origin}function E8({port:n}){const{streams:e}=yt(),s=x.useRef(null),[r,o]=x.useState(),[l]=x.useState(()=>crypto.randomUUID()),u=S8();return x.useEffect(()=>{if(!u)return;let d=!0;const m=new Map,p=new Set;let y=0;const v=new Map,b=new Map,C=S=>{d&&s.current?.contentWindow?.postMessage({...S,channel:l},u)},T=S=>{if(S.source!==s.current?.contentWindow||S.origin!==u||S.data?.channel!==l)return;const E=S.data;if(E.type==="preview-ready"&&C({type:"preview-init",bootstrap:Lp.toString()}),E.type==="http-cancel"&&b.get(E.id)?.abort(),E.type==="http-request"){if(++y>128){y--,C({type:"http-error",id:E.id,error:"同时请求过多"});return}const _=(E.headers??[]).filter(([N])=>!/^(cookie|proxy-authorization)$/i.test(N));v.size&&_.push(["cookie",[...v].map(([N,z])=>`${N}=${z}`).join("; ")]);const j=new AbortController;b.set(E.id,j),w8(e,n,E.path??"/",E.method??"GET",_,E.body?new Uint8Array(E.body):new Uint8Array,j.signal).then(async N=>{for(const[M,R]of N.headers)if(M==="set-cookie"){const L=R.split(";")[0],H=L.indexOf("=");if(H>0){const V=L.slice(0,H);/max-age=0/i.test(R)?v.delete(V):v.set(V,L.slice(H+1))}}let z=N.body;const k=N.headers.find(([M])=>M==="content-encoding")?.[1];if(E.method!=="HEAD"&&![204,205,304].includes(N.status)&&(k==="gzip"||k==="deflate"))z=z.pipeThrough(new DecompressionStream(k));else if(k&&!["identity","gzip","deflate"].includes(k))throw new Error(`预览暂不支持 ${k} 压缩`);C({type:"http-head",id:E.id,status:N.status,headers:N.headers});const O=z.getReader();try{for(;d;){const M=await O.read();if(M.done)break;C({type:"http-chunk",id:E.id,body:M.value})}}finally{O.releaseLock(),d||j.abort()}C({type:"http-end",id:E.id})}).catch(N=>{j.abort(),C({type:"http-error",id:E.id,error:String(N)})}).finally(()=>{b.delete(E.id),y--})}if(E.type==="ws-open"){if(m.has(E.id)||p.has(E.id)||m.size+p.size>=24)return;try{const _=new URL(E.url,u);if(![new URL(u).hostname,"localhost","127.0.0.1"].includes(_.hostname)||!["ws:","wss:"].includes(_.protocol))throw new Error("仅代理当前预览端口的 WebSocket");const N=_.pathname.replace(new RegExp(`^/preview/view/${l}/`),"/")+_.search;p.add(E.id),lC(e,n,N,{open:()=>C({type:"ws-open",id:E.id}),data:z=>C({type:"ws-data",id:E.id,data:z}),close:z=>{p.delete(E.id),m.delete(E.id),C({type:"ws-close",id:E.id,reason:z})}},E.protocols).then(z=>{!d||!p.has(E.id)?z.close():(p.delete(E.id),m.set(E.id,z))},z=>{p.delete(E.id),C({type:"ws-close",id:E.id,reason:String(z)})})}catch(_){C({type:"ws-close",id:E.id,reason:String(_)})}}E.type==="ws-send"&&(typeof E.data=="string"||E.data instanceof ArrayBuffer)&&m.get(E.id)?.send(E.data),E.type==="ws-close"&&(p.delete(E.id),m.get(E.id)?.close(),m.delete(E.id))};return window.addEventListener("message",T),()=>{d=!1,window.removeEventListener("message",T);for(const S of m.values())S.close();p.clear();for(const S of b.values())S.abort();b.clear()}},[e,n,l,u]),u?f.jsxs(f.Fragment,{children:[f.jsx(xt,{error:r}),f.jsx("iframe",{className:"port-frame",ref:s,title:`端口 ${n} 预览`,src:`${u}/preview/bridge.html#${l}`,sandbox:"allow-scripts allow-same-origin allow-forms allow-downloads allow-modals allow-pointer-lock",allow:"autoplay; fullscreen",onLoad:()=>s.current?.contentWindow?.postMessage({channel:l,type:"preview-init",bootstrap:Lp.toString()},u),onError:()=>o("隔离预览页面加载失败,请检查预览域名配置")})]}):f.jsxs("p",{className:"notice-card",children:["此部署尚未配置独立的预览域名。管理员需要设置 ",f.jsx("code",{children:"previewOrigin"})," ","并在该域名部署网页制品中的 preview 目录。开发网页与账号页面隔离,避免项目脚本读取登录凭证。"]})}function C8(){const{link:n}=yt(),e=ta(()=>n.call("ports.list",{}),[n],1e4),[s,r]=x.useState(),[o,l]=x.useState("");return f.jsxs("section",{className:"ports-page",children:[f.jsxs("div",{className:"browser-toolbar",children:[f.jsx("h2",{children:"端口预览"}),f.jsxs("form",{className:"inline-form",onSubmit:u=>{u.preventDefault(),r(Number(o))},children:[f.jsx("input",{"aria-label":"预览端口",type:"number",min:"1",max:"65535",value:o,onChange:u=>l(u.target.value),required:!0,placeholder:"端口号"}),f.jsx("button",{className:"button secondary",children:"打开"})]})]}),f.jsx(Sa,{...e}),f.jsx("div",{className:"terminal-tabs",children:e.value?.ports.map(u=>f.jsxs("button",{className:s===u.port?"selected":"",onClick:()=>r(u.port),children:[u.port," · ",u.title??u.process,!u.http&&"(未识别为 HTTP)"]},u.port))}),s?f.jsx(E8,{port:s},s):f.jsx("p",{className:"muted",children:"选择电脑上的 HTTP 服务。请求通过加密通道传输。"})]})}const _8=x.lazy(()=>up(()=>import("./Prototype-jUvLvS7-.js"),__vite__mapDeps([5,1,2,3,4])).then(n=>({default:n.Prototype})));function j8(){return new URLSearchParams(location.search).get("demo")==="1"?f.jsx(x.Suspense,{fallback:f.jsx("p",{children:"加载原型…"}),children:f.jsx(_8,{})}):f.jsx(A8,{})}function A8(){const n=Md(Qt.state),[e,s]=x.useState(!1),[r,o]=x.useState(()=>new URLSearchParams(location.hash.slice(1)).get("view")??Ks("lastView","home")),[l,u]=x.useState(!1),[d,m]=x.useState(()=>Ks("theme",matchMedia("(prefers-color-scheme: dark)").matches?"dark":"light"));x.useEffect(()=>{Qt.start()},[]),x.useEffect(()=>{document.documentElement.dataset.theme=d,fa("theme",d)},[d]),x.useEffect(()=>{const y=()=>o(new URLSearchParams(location.hash.slice(1)).get("view")??"home");return window.addEventListener("hashchange",y),()=>window.removeEventListener("hashchange",y)},[]);function p(y){fa("lastView",y),location.hash=new URLSearchParams({view:y}).toString(),o(y),u(!1)}return f.jsxs("div",{className:`app-shell ${l?"nav-open":""}`,children:[l&&f.jsx("button",{className:"nav-backdrop","aria-label":"关闭导航",onClick:()=>u(!1)}),f.jsxs("aside",{className:"sidebar",children:[f.jsxs("a",{className:"brand",href:"#home",onClick:y=>{y.preventDefault(),p("home")},children:[f.jsx("img",{src:Nx,className:"brand-symbol",alt:""}),"LinkShell",f.jsx("span",{className:"brand-web",children:"web"})]}),f.jsxs("button",{className:"connection-switch",onClick:()=>s(!0),children:[f.jsx("span",{className:"source-icon",children:f.jsx(Tt,{name:n.source==="official"?"globe":"server"})}),f.jsxs("span",{children:[f.jsx("strong",{children:n.source==="official"?"官方工作空间":"配对工作空间"}),f.jsx("small",{children:n.source==="official"?n.account??"登录或连接电脑":n.gateway?n.gateway.replace(/^wss?:\/\//,""):"设置你的网关"})]}),f.jsx(Tt,{name:"down",size:14})]}),f.jsx("nav",{"aria-label":"主导航",children:[{id:"home",title:"首页",icon:"grid"},{id:"projects",title:"项目",icon:"folder"},{id:"computers",title:"电脑",icon:"computer"},{id:"files",title:"文件",icon:"file"},{id:"terminals",title:"终端",icon:"terminal"},{id:"ports",title:"端口预览",icon:"globe"},{id:"screen",title:"电脑屏幕",icon:"computer"},{id:"worktrees",title:"Worktree",icon:"branch"},{id:"archive",title:"已归档",icon:"clock"}].map(y=>f.jsxs("button",{className:`nav-item ${r===y.id?"active":""}`,onClick:()=>p(y.id),children:[f.jsx(Tt,{name:y.icon}),y.title]},y.id))}),f.jsxs("div",{className:"sidebar-bottom",children:[f.jsxs("label",{className:"computer-select-label",children:["当前电脑",f.jsx(Dd,{label:"切换电脑",value:n.connection?.computer.key??"",placeholder:"选择电脑",onValueChange:y=>{const v=n.computers.find(b=>b.key===y);v&&(Qt.select(v),p("home"))},options:n.computers.map(y=>({value:y.key,label:`${y.machine.name} · ${y.machine.online?"在线":"离线"}`}))})]}),f.jsxs("button",{className:"profile-button",onClick:()=>s(!0),children:[f.jsx("span",{className:"avatar",children:f.jsx(Tt,{name:n.account?"globe":"server"})}),f.jsxs("span",{children:[f.jsx("strong",{children:n.account??"浏览器设备"}),f.jsx("small",{children:n.source==="official"?"账号连接":"配对连接"})]}),f.jsx(Tt,{name:"settings"})]})]})]}),f.jsxs("main",{className:"main",children:[f.jsxs("header",{className:"topbar",children:[f.jsxs("div",{className:"breadcrumbs",children:[f.jsx("button",{className:"icon-button mobile-menu","aria-label":"打开导航",onClick:()=>u(!0),children:f.jsx(Tt,{name:"menu"})}),f.jsx("strong",{children:n.connection?.computer.machine.name??"LinkShell"}),f.jsx("span",{className:"breadcrumb-slash",children:"/"}),f.jsx("span",{children:"网页工作台"})]}),f.jsxs("div",{className:"topbar-right",children:[f.jsx("button",{className:"icon-button","aria-label":"切换外观",onClick:()=>m(d==="light"?"dark":"light"),children:f.jsx(Tt,{name:"moon"})}),f.jsx("button",{className:"button secondary",onClick:()=>s(!0),children:"连接设置"})]})]}),n.error&&f.jsxs("div",{className:"connection-banner",role:"alert",children:[f.jsx("span",{children:n.error}),f.jsx("button",{onClick:()=>{Qt.state.setState({error:void 0}),Qt.reconnect()},children:"重试"}),f.jsx("button",{onClick:()=>Qt.state.setState({error:void 0}),children:"关闭"})]}),n.locked?f.jsxs("div",{className:"welcome-live",children:[f.jsx("h1",{children:"工作台已在另一个标签页打开"}),f.jsx("p",{className:"muted",children:"同一个浏览器设备只保持一条连接,避免标签页相互挤掉。"}),f.jsx("button",{className:"button primary",onClick:()=>void Qt.claim(),children:"在此标签页继续"})]}):n.connection?f.jsx(yE,{value:n.connection,children:f.jsx(T8,{view:r,navigate:p,connect:()=>s(!0)},n.connection.computer.key)}):f.jsxs("div",{className:"welcome-live",children:[f.jsx("img",{src:Nx,alt:"LinkShell"}),f.jsx("h1",{children:"连接你的电脑"}),f.jsx("p",{className:"muted",children:"会话在电脑上运行,网页让你继续对话、审批和操作。"}),f.jsxs("pre",{children:["npm i -g linkshell-cli",`
|
|
205
|
+
`,"linkshell host --daemon"]}),f.jsx("button",{className:"button primary",disabled:!n.ready,onClick:()=>s(!0),children:n.ready?Zs==="self-hosted"?"配对电脑":"登录或配对电脑":"正在准备设备身份…"}),f.jsx("p",{className:"muted",children:Zs==="self-hosted"?"运行 linkshell pair,输入此网关的配对码即可连接。":"官方服务使用 iTool 账号,自托管使用自己的网关与配对码。"}),n.computers.map(y=>f.jsxs("button",{className:"button secondary",onClick:()=>Qt.select(y),children:[y.machine.name," ·"," ",y.machine.online?"在线":"离线"]},y.key)),f.jsx("a",{className:"text-button",href:"?demo=1",children:"查看独立 UI 演示"})]})]}),e&&f.jsx(hD,{close:()=>s(!1)})]})}function T8({view:n,navigate:e,connect:s}){const r=lt(y=>y),[o,l]=x.useState(),[u,d]=x.useState(),{store:m}=yt(),p=r.sessions[n];return x.useEffect(()=>{n==="archive"&&m.getState().loadArchived()},[m,n]),f.jsxs(f.Fragment,{children:[r.status!=="online"&&f.jsxs("div",{className:"connection-banner",role:"status",children:[f.jsx("span",{children:r.statusDetail??"正在连接电脑…"}),f.jsx("button",{onClick:()=>Qt.reconnect(),children:"重新连接"})]}),p?f.jsx(b8,{session:p,navigate:e},p.id):f.jsxs("div",{className:"overview live-overview",children:[["home","archive"].includes(n)&&f.jsx(k8,{archived:n==="archive",navigate:e,create:()=>l(null)}),n==="projects"&&f.jsxs("section",{children:[f.jsxs("div",{className:"page-heading",children:[f.jsx("h1",{children:"项目"}),f.jsx("button",{className:"button primary",onClick:()=>l(null),children:"新建会话"})]}),r.projects.map(y=>f.jsxs("article",{className:"notice-card",children:[f.jsxs("div",{className:"browser-toolbar",children:[f.jsx("strong",{children:y.name}),f.jsx("span",{className:"muted",children:y.branch}),f.jsx("button",{className:"text-button",onClick:()=>l(y.cwd),children:"在此新建"})]}),f.jsx("p",{className:"muted",children:y.cwd}),f.jsx("div",{className:"task-list",children:Object.values(r.sessions).filter(v=>v.cwd===y.cwd||v.worktree?.source===y.cwd).map(v=>f.jsx(cC,{session:v,open:()=>e(v.id)},v.id))})]},y.cwd))]}),n==="computers"&&f.jsx(O8,{connect:s}),n==="files"&&f.jsxs(f.Fragment,{children:[f.jsx("h1",{children:"文件"}),f.jsx(Ug,{})]}),n==="terminals"&&f.jsx(iC,{selected:u,onSelect:d}),n==="worktrees"&&f.jsx(f8,{}),n==="ports"&&f.jsx(C8,{}),n==="screen"&&f.jsx(y8,{}),!["home","archive","projects","computers","files","terminals","worktrees","ports","screen"].includes(n)&&f.jsxs("div",{className:"empty-state",children:[f.jsx("h2",{children:"会话尚未加载或已被移除"}),f.jsx("button",{className:"text-button",onClick:()=>e("home"),children:"返回首页"})]})]}),o!==void 0&&f.jsx(N8,{initialDirectory:o??void 0,close:()=>l(void 0),created:y=>{l(void 0),e(y.id)}})]})}function cC({session:n,open:e}){return f.jsxs("button",{className:"task-row",onClick:e,children:[f.jsxs("span",{className:"row-avatar",children:[f.jsx(Bd,{agent:n.agent}),f.jsx("span",{className:`tiny-status ${n.state}`})]}),f.jsxs("span",{className:"task-info",children:[f.jsx("strong",{children:Tr(n)}),f.jsxs("span",{children:[f.jsx("span",{className:"project-label",children:dd(n.worktree?.source??n.cwd)}),f.jsx("span",{className:"separator",children:"·"}),f.jsx("span",{className:n.state==="running"?"running-copy":"",children:n.activity?.title??n.preview??n.agent})]})]}),f.jsxs("span",{className:"task-meta",children:[f.jsx("small",{children:new Date(n.updatedAt).toLocaleTimeString([],{hour:"2-digit",minute:"2-digit"})}),f.jsx($r,{state:n.state})]}),f.jsx(Tt,{name:"chevron",size:14})]})}function k8({archived:n,navigate:e,create:s}){const r=lt(v=>v),o=pn(),[l,u]=x.useState(""),[d,m]=x.useState("all"),p=Nt(),y=Object.values(r.sessions).filter(v=>v.archived===n&&`${Tr(v)} ${v.cwd} ${v.agent} ${v.preview??""}`.toLowerCase().includes(l.toLowerCase())&&(d==="all"||v.state===d)).sort((v,b)=>b.updatedAt-v.updatedAt);return f.jsxs(f.Fragment,{children:[f.jsxs("div",{className:"page-heading",children:[f.jsxs("div",{children:[f.jsx("h1",{children:n?"已归档":"首页"}),f.jsxs("p",{className:"host-summary",children:[f.jsx("span",{className:r.status==="online"?"online-dot":"offline-dot"}),r.machine?.hostname??"正在连接",f.jsxs("span",{className:"waiting-copy",children:[y.filter(v=>v.state==="waiting").length," ","项需要你"]})]})]}),f.jsxs("button",{className:"button primary",disabled:r.status!=="online",onClick:s,children:[f.jsx(Tt,{name:"plus"}),"新建任务"]})]}),f.jsxs("div",{className:"home-controls",children:[f.jsxs("label",{className:"search-box",children:[f.jsx(Tt,{name:"search"}),f.jsx("input",{"aria-label":"搜索会话",placeholder:"搜索会话、项目或 Agent",value:l,onChange:v=>u(v.target.value)})]}),f.jsx("div",{className:"filters",children:[{id:"all",name:"全部"},{id:"running",name:"进行中"},{id:"waiting",name:"需要你"},{id:"idle",name:"已完成"}].map(v=>f.jsx("button",{className:d===v.id?"selected":"",onClick:()=>m(v.id),children:v.name},v.id))})]}),f.jsx(xt,{error:r.sessionsError??p.error}),!r.sessionsLoaded&&!r.sessionsError&&f.jsx("p",{className:"muted",children:"正在加载会话…"}),["waiting","running","recent"].map(v=>{const b=y.filter(C=>v==="recent"?!["waiting","running"].includes(C.state):C.state===v);return b.length?f.jsxs("section",{className:"session-group",children:[f.jsx("div",{className:`section-heading ${v==="waiting"?"waiting-heading":""}`,children:f.jsxs("h2",{children:[v==="waiting"?"需要你":v==="running"?"进行中":"最近",f.jsx("span",{children:b.length})]})}),f.jsx("div",{className:"task-list",children:b.map(C=>f.jsxs("div",{children:[f.jsx(cC,{session:C,open:()=>e(C.id)}),C.permission&&v==="waiting"&&f.jsx(Ig,{permission:C.permission,sessionId:C.id})]},C.id))})]},v):null}),r.sessionsLoaded&&!y.length&&f.jsxs("div",{className:"empty-state",children:[f.jsx("h3",{children:l?"没有找到会话":n?"暂无已归档会话":"开始第一个任务"}),f.jsx("p",{children:"会话保存在当前电脑,手机与网页共享同一份记录。"})]}),f.jsx("button",{className:"text-button",disabled:p.busy,onClick:()=>void p.run(()=>o.refresh()),children:"刷新列表"})]})}function N8({initialDirectory:n,close:e,created:s}){const r=lt(R=>R.machine),o=lt(R=>R.projects),l=pn(),{store:u}=yt(),d=lt(R=>R.status==="online"),m=Nt(),[p,y]=x.useState(r?.agents.find(R=>R.installed&&!R.problem&&R.auth?.state!=="missing"&&R.tier!=="terminal")?.id??""),[v,b]=x.useState(n??o[0]?.cwd??r?.home??""),[C,T]=x.useState(""),[S,E]=x.useState(!1),[_,j]=x.useState(!1),[N,z]=x.useState(v);x.useEffect(()=>{E(!1);const R=setTimeout(()=>z(v),250);return()=>clearTimeout(R)},[v]);const k=ta(()=>N.trim()?l.gitInfo(N):Promise.resolve(void 0),[u,N]),O=r?.agents.find(R=>R.id===p),M=!!O&&O.installed&&!O.problem&&O.auth?.state!=="missing"&&O.tier!=="terminal";return f.jsxs(Rl,{title:"新建任务",close:e,wide:_,children:[f.jsx(Pd,{agent:p}),_?f.jsx(Ug,{start:v,directoriesOnly:!0,onPick:R=>{b(R),j(!1)}}):f.jsxs("form",{className:"new-form",onSubmit:R=>{R.preventDefault(),!(!d||!M||!v.trim())&&m.run(async()=>s(await l.createSession({agent:p,cwd:v,worktree:S&&!!k.value&&N===v,prompt:C.trim()?[{type:"text",text:C.trim()}]:void 0})))},children:[f.jsxs("label",{children:["任务描述",f.jsx("textarea",{value:C,onChange:R=>T(R.target.value),rows:4,placeholder:"想让 Agent 完成什么?"})]}),f.jsxs("label",{children:["Agent",f.jsx(Dd,{label:"Agent",value:p,onValueChange:y,options:(r?.agents??[]).map(R=>({value:R.id,label:R.label+(R.installed?R.auth?.state==="missing"?" · 未登录":R.tier==="terminal"?" · 请从终端打开":R.problem?` · ${R.problem}`:"":" · 未安装"),disabled:!R.installed||!!R.problem||R.auth?.state==="missing"||R.tier==="terminal"}))})]}),f.jsxs("label",{children:["工作目录",f.jsx("input",{value:v,onChange:R=>b(R.target.value),required:!0})]}),f.jsx("button",{type:"button",className:"text-button",onClick:()=>j(!0),children:"浏览电脑目录"}),k.value&&N===v&&f.jsxs("label",{className:"choice-option",children:[f.jsx("input",{type:"checkbox",checked:S,onChange:R=>E(R.target.checked)}),"在新 worktree 中工作"]}),f.jsx(xt,{error:m.error}),f.jsx("button",{className:"button primary full",disabled:m.busy||!d||!M||!v.trim(),children:"创建任务"})]})]})}function O8({connect:n}){const e=Jr(),s=Md(Qt.state),r=lt(d=>d.machine),{link:o}=yt(),l=Nt(),u=ta(()=>o.call("gateway.status",{}),[o],1e4);return f.jsxs("section",{children:[f.jsxs("div",{className:"page-heading",children:[f.jsx("h1",{children:"电脑"}),f.jsx("button",{className:"button primary",onClick:n,children:"添加电脑"})]}),f.jsx(xt,{error:l.error}),s.computers.map(d=>f.jsxs("article",{className:"notice-card",children:[f.jsxs("div",{className:"browser-toolbar",children:[f.jsx(Tt,{name:"computer"}),f.jsx("strong",{children:d.machine.name}),f.jsx("span",{className:"muted",children:d.machine.online?"在线":"离线"}),f.jsx("button",{className:"text-button",onClick:()=>Qt.select(d),children:"切换到此电脑"}),f.jsx("button",{className:"text-button danger-text",onClick:async()=>{await e.confirm(`移除「${d.machine.name}」的连接关系?需要时可重新登录或配对。`)&&l.run(()=>Qt.forget(d))},children:"移除"})]}),f.jsx("p",{className:"muted",children:d.gateway})]},d.key)),f.jsx("h2",{children:"当前电脑"}),f.jsxs("p",{className:"muted",children:[r?.hostname," · ",r?.platform," · Host ",r?.hostVersion]}),f.jsx("h3",{children:"Agent"}),f.jsx("div",{className:"agent-list",children:r?.agents.map(d=>f.jsxs("article",{children:[f.jsx(Bd,{agent:d.id}),f.jsxs("div",{children:[f.jsx("strong",{children:d.label}),f.jsxs("p",{children:[d.installed?d.version??"已安装":"未安装"," ·"," ",d.auth?.state==="ok"?d.id==="codex"?"使用电脑认证配置":"已登录":d.auth?.state==="missing"?"需要登录":d.id==="codex"?"使用电脑认证配置":"登录状态未知"]}),(d.problem||d.auth?.hint)&&f.jsx("p",{className:"muted",children:d.problem??d.auth?.hint})]})]},d.id))}),f.jsx(a8,{}),f.jsx("h3",{children:"配对设备"}),f.jsx(Sa,{...u}),u.value?.devices.map(d=>f.jsx("article",{className:"notice-card",children:f.jsxs("div",{className:"browser-toolbar",children:[f.jsx("strong",{children:d.name}),f.jsx("span",{className:"muted",children:d.online?"在线":"离线"}),f.jsx("button",{className:"text-button danger-text",onClick:async()=>{await e.confirm(`撤销「${d.name}」的配对?该设备将需要重新配对。`)&&l.run(async()=>{await o.call("devices.revoke",{deviceId:d.id}),u.reload()})},children:"撤销配对"})]})},d.id))]})}const R8=["#4a6cf7","#7d95ff"],D8=["rgba(74,108,247,0.11)","rgba(125,149,255,0.18)"],M8=["#4a6cf7","#7d95ff"],z8=["rgba(232,131,12,0.12)","rgba(255,166,61,0.16)"],I8=["rgba(15,149,96,0.12)","rgba(61,214,140,0.15)"],L8=["rgba(220,61,61,0.10)","rgba(255,107,107,0.15)"],U8=["#F0F0F4","#26262B"],B8=["#f1f1f6","#1c1c22"],H8=["#2a2b35","#e4e4ec"],$8=["rgba(15,149,96,0.12)","rgba(61,214,140,0.14)"],V8=["rgba(220,61,61,0.10)","rgba(255,107,107,0.14)"],q8=["#0b7a4f","#7fddb4"],P8=["#b42f2f","#ff9a9a"],F8=["#000000","#FFFFFF"],G8=["rgba(60,60,67,0.6)","rgba(235,235,245,0.6)"],Z8=["rgba(60,60,67,0.3)","rgba(235,235,245,0.3)"],Y8=["rgba(60,60,67,0.3)","rgba(235,235,245,0.3)"],K8=["rgba(60,60,67,0.18)","rgba(84,84,88,0.6)"],X8=["#F2F2F7","#000000"],Q8=["#FFFFFF","#1C1C1E"],W8=["#FFFFFF","#2C2C2E"],J8=["#F2F2F7","#1C1C1E"],e9=["#FFFFFF","#000000"],t9=["rgba(118,118,128,0.12)","rgba(118,118,128,0.24)"],n9=["rgba(120,120,128,0.16)","rgba(120,120,128,0.32)"],a9=["#E8830C","#FF9F0A"],s9=["#0F9560","#30D158"],r9=["#DC3D3D","#FF453A"],i9=["#F2F2F7","#1C1C1E"],o9=["#FFFFFF","#2C2C2E"],l9={accent:R8,accentSoft:D8,running:M8,waitingSoft:z8,okSoft:I8,dangerSoft:L8,userBubble:U8,code:B8,codeText:H8,diffAdd:$8,diffDel:V8,diffAddText:q8,diffDelText:P8,label:F8,secondaryLabel:G8,tertiaryLabel:Z8,placeholder:Y8,separator:K8,background:X8,card:Q8,cardRaised:W8,inset:J8,plain:e9,fill:t9,fillStrong:n9,waiting:a9,ok:s9,danger:r9,sheet:i9,sheetCard:o9},Vm=n=>Object.entries(l9).map(([e,s])=>`--${e}: ${s[n]};`).join(`
|
|
206
206
|
`),c9=`
|
|
207
207
|
:root { ${Vm(0)} color-scheme: light; }
|
|
208
208
|
@media (prefers-color-scheme: dark) { :root:not([data-theme="light"]) { ${Vm(1)} color-scheme: dark; } }
|