bunite-core 0.14.0 → 0.16.0
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/package.json +4 -4
- package/src/host/core/App.ts +2 -1
- package/src/host/core/BrowserView.ts +345 -24
- package/src/host/core/SurfaceBrowserIPC.ts +10 -1
- package/src/host/core/SurfaceManager.ts +357 -16
- package/src/host/events/webviewEvents.ts +18 -1
- package/src/host/log.ts +6 -1
- package/src/host/native.ts +140 -1
- package/src/host/preloadBundle.ts +7 -2
- package/src/native/linux/bunite_linux_ffi.cpp +205 -1
- package/src/native/linux/bunite_linux_internal.h +12 -0
- package/src/native/linux/bunite_linux_runtime.cpp +6 -1
- package/src/native/linux/bunite_linux_view.cpp +211 -5
- package/src/native/mac/bunite_mac_ffi.mm +278 -4
- package/src/native/mac/bunite_mac_internal.h +13 -0
- package/src/native/mac/bunite_mac_view.mm +227 -7
- package/src/native/shared/ffi_exports.h +93 -30
- package/src/native/win/native_host_cef.cpp +102 -10
- package/src/native/win/native_host_ffi.cpp +818 -2
- package/src/native/win/native_host_internal.h +22 -0
- package/src/native/win-webview2/bunite_webview2_ffi.cpp +788 -4
- package/src/native/win-webview2/webview2_internal.h +14 -0
- package/src/native/win-webview2/webview2_runtime.cpp +276 -23
- package/src/preload/runtime.built.js +1 -1
- package/src/rpc/framework.ts +174 -11
- package/src/rpc/index.ts +11 -0
- package/src/webview/native.ts +142 -32
- package/src/webview/polyfill.ts +91 -14
|
@@ -1 +1 @@
|
|
|
1
|
-
var fX=Symbol.for("bunite.rpc.CallDef"),gX=Symbol.for("bunite.rpc.StreamDef"),pX=Symbol.for("bunite.rpc.CapDef"),uX=Symbol.for("bunite.rpc.CapRefToken"),lX=Symbol.for("bunite.rpc.CapArrayToken"),dX=Symbol.for("bunite.rpc.CapRecordToken"),y$=Symbol.for("bunite.rpc.Schema");function t8(X){return{[uX]:!0,cap:X}}t8.array=(X)=>({[lX]:!0,cap:X});t8.record=(X)=>({[dX]:!0,cap:X});var c=t8;function P8(X){return typeof X==="object"&&X!==null&&X[uX]===!0}function C8(X){return typeof X==="object"&&X!==null&&X[lX]===!0}function E8(X){return typeof X==="object"&&X!==null&&X[dX]===!0}function j8(X){return typeof X==="object"&&X!==null&&X[fX]===!0}function x8(X){return typeof X==="object"&&X!==null&&X[gX]===!0}function A(X){return{[fX]:!0,idempotent:!!X?.idempotent,returns:X?.returns}}function Y8(X){return{[gX]:!0,hint:X?.hint}}function i(X,$,Q){return{[pX]:!0,name:X,version:Q?.version!=null?String(Q.version):void 0,methods:$,disposal:Q?.disposal??void 0}}function w8(X){return typeof X==="object"&&X!==null&&X[pX]===!0}function e8(X){return typeof X==="object"&&X!==null&&X[y$]===!0}var $X;try{$X=new TextDecoder}catch(X){}var O,n,J=0;var H$=[],QX=H$,ZX=0,b={},E,J8,s=0,e=0,g,H8,u=[],C,cX={useRecords:!1,mapsAsObjects:!0};class k8{}var qX=new k8;qX.name="MessagePack 0xC1";var K8=!1,sX=2,nX,oX,iX;class X8{constructor(X){if(X){if(X.useRecords===!1&&X.mapsAsObjects===void 0)X.mapsAsObjects=!0;if(X.sequential&&X.trusted!==!1){if(X.trusted=!0,!X.structures&&X.useRecords!=!1){if(X.structures=[],!X.maxSharedStructures)X.maxSharedStructures=0}}if(X.structures)X.structures.sharedLength=X.structures.length;else if(X.getStructures)(X.structures=[]).uninitialized=!0,X.structures.sharedLength=0;if(X.int64AsNumber)X.int64AsType="number"}Object.assign(this,X)}unpack(X,$){if(O)return Y$(()=>{return I8(),this?this.unpack(X,$):X8.prototype.unpack.call(cX,X,$)});if(!X.buffer&&X.constructor===ArrayBuffer)X=typeof Buffer<"u"?Buffer.from(X):new Uint8Array(X);if(typeof $==="object")n=$.end||X.length,J=$.start||0;else J=0,n=$>-1?$:X.length;ZX=0,e=0,J8=null,QX=H$,g=null,O=X;try{C=X.dataView||(X.dataView=new DataView(X.buffer,X.byteOffset,X.byteLength))}catch(Q){if(O=null,X instanceof Uint8Array)throw Q;throw Error("Source must be a Uint8Array or Buffer but was a "+(X&&typeof X=="object"?X.constructor.name:typeof X))}if(this instanceof X8){if(b=this,this.structures)return E=this.structures,b8($);else if(!E||E.length>0)E=[]}else if(b=cX,!E||E.length>0)E=[];return b8($)}unpackMultiple(X,$){let Q,Z=0;try{K8=!0;let H=X.length,q=this?this.unpack(X,H):S8.unpack(X,H);if($){if($(q,Z,J)===!1)return;while(J<H)if(Z=J,$(b8(),Z,J)===!1)return}else{Q=[q];while(J<H)Z=J,Q.push(b8());return Q}}catch(H){throw H.lastPosition=Z,H.values=Q,H}finally{K8=!1,I8()}}_mergeStructures(X,$){if(oX)X=oX.call(this,X);if(X=X||[],Object.isFrozen(X))X=X.map((Q)=>Q.slice(0));for(let Q=0,Z=X.length;Q<Z;Q++){let H=X[Q];if(H){if(H.isShared=!0,Q>=32)H.highByte=Q-32>>5}}X.sharedLength=X.length;for(let Q in $||[])if(Q>=0){let Z=X[Q],H=$[Q];if(H){if(Z)(X.restoreStructures||(X.restoreStructures=[]))[Q]=Z;X[Q]=H}}return this.structures=X}decode(X,$){return this.unpack(X,$)}}function b8(X){try{if(!b.trusted&&!K8){let Q=E.sharedLength||0;if(Q<E.length)E.length=Q}let $;if(b.randomAccessStructure&&O[J]<64&&O[J]>=32&&nX){if($=nX(O,J,n,b),O=null,!(X&&X.lazy)&&$)$=$.toJSON();J=n}else $=h();if(g)J=g.postBundlePosition,g=null;if(K8)E.restoreStructures=null;if(J==n){if(E&&E.restoreStructures)aX();if(E=null,O=null,H8)H8=null}else if(J>n)throw Error("Unexpected end of MessagePack data");else if(!K8){let Q;try{Q=JSON.stringify($,(Z,H)=>typeof H==="bigint"?`${H}n`:H).slice(0,100)}catch(Z){Q="(JSON view not available "+Z+")"}throw Error("Data read, but end of buffer not reached "+Q)}return $}catch($){if(E&&E.restoreStructures)aX();if(I8(),$ instanceof RangeError||$.message.startsWith("Unexpected end of buffer")||J>n)$.incomplete=!0;throw $}}function aX(){for(let X in E.restoreStructures)E[X]=E.restoreStructures[X];E.restoreStructures=null}function h(){let X=O[J++];if(X<160)if(X<128)if(X<64)return X;else{let $=E[X&63]||b.getStructures&&q$()[X&63];if($){if(!$.read)$.read=JX($,X&63);return $.read()}else return X}else if(X<144)if(X-=128,b.mapsAsObjects){let $={};for(let Q=0;Q<X;Q++){let Z=K$();if(Z==="__proto__")Z="__proto_";$[Z]=h()}return $}else{let $=new Map;for(let Q=0;Q<X;Q++)$.set(h(),h());return $}else{X-=144;let $=Array(X);for(let Q=0;Q<X;Q++)$[Q]=h();if(b.freezeData)return Object.freeze($);return $}else if(X<192){let $=X-160;if(e>=J)return J8.slice(J-s,(J+=$)-s);if(e==0&&n<140){let Q=$<16?KX($):J$($);if(Q!=null)return Q}return HX($)}else{let $;switch(X){case 192:return null;case 193:if(g)if($=h(),$>0)return g[1].slice(g.position1,g.position1+=$);else return g[0].slice(g.position0,g.position0-=$);return qX;case 194:return!1;case 195:return!0;case 196:if($=O[J++],$===void 0)throw Error("Unexpected end of buffer");return XX($);case 197:return $=C.getUint16(J),J+=2,XX($);case 198:return $=C.getUint32(J),J+=4,XX($);case 199:return N8(O[J++]);case 200:return $=C.getUint16(J),J+=2,N8($);case 201:return $=C.getUint32(J),J+=4,N8($);case 202:if($=C.getFloat32(J),b.useFloat32>2){let Q=y8[(O[J]&127)<<1|O[J+1]>>7];return J+=4,(Q*$+($>0?0.5:-0.5)>>0)/Q}return J+=4,$;case 203:return $=C.getFloat64(J),J+=8,$;case 204:return O[J++];case 205:return $=C.getUint16(J),J+=2,$;case 206:return $=C.getUint32(J),J+=4,$;case 207:if(b.int64AsType==="number")$=C.getUint32(J)*4294967296,$+=C.getUint32(J+4);else if(b.int64AsType==="string")$=C.getBigUint64(J).toString();else if(b.int64AsType==="auto"){if($=C.getBigUint64(J),$<=BigInt(2)<<BigInt(52))$=Number($)}else $=C.getBigUint64(J);return J+=8,$;case 208:return C.getInt8(J++);case 209:return $=C.getInt16(J),J+=2,$;case 210:return $=C.getInt32(J),J+=4,$;case 211:if(b.int64AsType==="number")$=C.getInt32(J)*4294967296,$+=C.getUint32(J+4);else if(b.int64AsType==="string")$=C.getBigInt64(J).toString();else if(b.int64AsType==="auto"){if($=C.getBigInt64(J),$>=BigInt(-2)<<BigInt(52)&&$<=BigInt(2)<<BigInt(52))$=Number($)}else $=C.getBigInt64(J);return J+=8,$;case 212:if($=O[J++],$==114)return Q$(O[J++]&63);else{let Q=u[$];if(Q)if(Q.read)return J++,Q.read(h());else if(Q.noBuffer)return J++,Q();else return Q(O.subarray(J,++J));else throw Error("Unknown extension "+$)}case 213:if($=O[J],$==114)return J++,Q$(O[J++]&63,O[J++]);else return N8(2);case 214:return N8(4);case 215:return N8(8);case 216:return N8(16);case 217:if($=O[J++],e>=J)return J8.slice(J-s,(J+=$)-s);return v$($);case 218:if($=C.getUint16(J),J+=2,e>=J)return J8.slice(J-s,(J+=$)-s);return h$($);case 219:if($=C.getUint32(J),J+=4,e>=J)return J8.slice(J-s,(J+=$)-s);return m$($);case 220:return $=C.getUint16(J),J+=2,tX($);case 221:return $=C.getUint32(J),J+=4,tX($);case 222:return $=C.getUint16(J),J+=2,eX($);case 223:return $=C.getUint32(J),J+=4,eX($);default:if(X>=224)return X-256;if(X===void 0){let Q=Error("Unexpected end of MessagePack data");throw Q.incomplete=!0,Q}throw Error("Unknown MessagePack token "+X)}}}var S$=/^[a-zA-Z_$][a-zA-Z\d_$]*$/;function JX(X,$){function Q(){if(Q.count++>sX){let H;try{H=X.read=Function("r","return function(){return "+(b.freezeData?"Object.freeze":"")+"({"+X.map((q)=>q==="__proto__"?"__proto_:r()":S$.test(q)?q+":r()":"["+JSON.stringify(q)+"]:r()").join(",")+"})}")(h)}catch(q){return sX=1/0,Q()}if(X.highByte===0)X.read=rX($,X.read);return H()}let Z={};for(let H=0,q=X.length;H<q;H++){let N=X[H];if(N==="__proto__")N="__proto_";Z[N]=h()}if(b.freezeData)return Object.freeze(Z);return Z}if(Q.count=0,X.highByte===0)return rX($,Q);return Q}var rX=(X,$)=>{return function(){let Q=O[J++];if(Q===0)return $();let Z=X<32?-(X+(Q<<5)):X+(Q<<5),H=E[Z]||q$()[Z];if(!H)throw Error("Record id is not defined for "+Z);if(!H.read)H.read=JX(H,X);return H.read()}};function q$(){let X=Y$(()=>{return O=null,b.getStructures()});return E=b._mergeStructures(X,E)}var HX=_8,v$=_8,h$=_8,m$=_8;function _8(X){let $;if(X<16){if($=KX(X))return $}if(X>64&&$X)return $X.decode(O.subarray(J,J+=X));let Q=J+X,Z=[];$="";while(J<Q){let H=O[J++];if((H&128)===0)Z.push(H);else if((H&224)===192){let q=O[J++]&63,N=(H&31)<<6|q;if(N<128)Z.push(65533);else Z.push(N)}else if((H&240)===224){let q=O[J++]&63,N=O[J++]&63,D=(H&31)<<12|q<<6|N;if(D<2048||D>=55296&&D<=57343)Z.push(65533);else Z.push(D)}else if((H&248)===240){let q=O[J++]&63,N=O[J++]&63,D=O[J++]&63,_=(H&7)<<18|q<<12|N<<6|D;if(_<65536||_>1114111)Z.push(65533);else if(_>65535)_-=65536,Z.push(_>>>10&1023|55296),_=56320|_&1023,Z.push(_);else Z.push(_)}else Z.push(65533);if(Z.length>=4096)$+=f.apply(String,Z),Z.length=0}if(Z.length>0)$+=f.apply(String,Z);return $}function tX(X){let $=Array(X);for(let Q=0;Q<X;Q++)$[Q]=h();if(b.freezeData)return Object.freeze($);return $}function eX(X){if(b.mapsAsObjects){let $={};for(let Q=0;Q<X;Q++){let Z=K$();if(Z==="__proto__")Z="__proto_";$[Z]=h()}return $}else{let $=new Map;for(let Q=0;Q<X;Q++)$.set(h(),h());return $}}var f=String.fromCharCode;function J$(X){let $=J,Q=Array(X);for(let Z=0;Z<X;Z++){let H=O[J++];if((H&128)>0){J=$;return}Q[Z]=H}return f.apply(String,Q)}function KX(X){if(X<4)if(X<2)if(X===0)return"";else{let $=O[J++];if(($&128)>1){J-=1;return}return f($)}else{let $=O[J++],Q=O[J++];if(($&128)>0||(Q&128)>0){J-=2;return}if(X<3)return f($,Q);let Z=O[J++];if((Z&128)>0){J-=3;return}return f($,Q,Z)}else{let $=O[J++],Q=O[J++],Z=O[J++],H=O[J++];if(($&128)>0||(Q&128)>0||(Z&128)>0||(H&128)>0){J-=4;return}if(X<6)if(X===4)return f($,Q,Z,H);else{let q=O[J++];if((q&128)>0){J-=5;return}return f($,Q,Z,H,q)}else if(X<8){let q=O[J++],N=O[J++];if((q&128)>0||(N&128)>0){J-=6;return}if(X<7)return f($,Q,Z,H,q,N);let D=O[J++];if((D&128)>0){J-=7;return}return f($,Q,Z,H,q,N,D)}else{let q=O[J++],N=O[J++],D=O[J++],_=O[J++];if((q&128)>0||(N&128)>0||(D&128)>0||(_&128)>0){J-=8;return}if(X<10)if(X===8)return f($,Q,Z,H,q,N,D,_);else{let M=O[J++];if((M&128)>0){J-=9;return}return f($,Q,Z,H,q,N,D,_,M)}else if(X<12){let M=O[J++],T=O[J++];if((M&128)>0||(T&128)>0){J-=10;return}if(X<11)return f($,Q,Z,H,q,N,D,_,M,T);let V=O[J++];if((V&128)>0){J-=11;return}return f($,Q,Z,H,q,N,D,_,M,T,V)}else{let M=O[J++],T=O[J++],V=O[J++],j=O[J++];if((M&128)>0||(T&128)>0||(V&128)>0||(j&128)>0){J-=12;return}if(X<14)if(X===12)return f($,Q,Z,H,q,N,D,_,M,T,V,j);else{let k=O[J++];if((k&128)>0){J-=13;return}return f($,Q,Z,H,q,N,D,_,M,T,V,j,k)}else{let k=O[J++],v=O[J++];if((k&128)>0||(v&128)>0){J-=14;return}if(X<15)return f($,Q,Z,H,q,N,D,_,M,T,V,j,k,v);let p=O[J++];if((p&128)>0){J-=15;return}return f($,Q,Z,H,q,N,D,_,M,T,V,j,k,v,p)}}}}}function X$(){let X=O[J++],$;if(X<192)$=X-160;else switch(X){case 217:$=O[J++];break;case 218:$=C.getUint16(J),J+=2;break;case 219:$=C.getUint32(J),J+=4;break;default:throw Error("Expected string")}return _8($)}function XX(X){return b.copyBuffers?Uint8Array.prototype.slice.call(O,J,J+=X):O.subarray(J,J+=X)}function N8(X){let $=O[J++];if(u[$]){let Q;return u[$](O.subarray(J,Q=J+=X),(Z)=>{J=Z;try{return h()}finally{J=Q}})}else throw Error("Unknown extension type "+$)}var $$=Array(4096);function K$(){let X=O[J++];if(X>=160&&X<192){if(X=X-160,e>=J)return J8.slice(J-s,(J+=X)-s);else if(!(e==0&&n<180))return HX(X)}else return J--,N$(h());let $=(X<<5^(X>1?C.getUint16(J):X>0?O[J]:0))&4095,Q=$$[$],Z=J,H=J+X-3,q,N=0;if(Q&&Q.bytes==X){while(Z<H){if(q=C.getUint32(Z),q!=Q[N++]){Z=1879048192;break}Z+=4}H+=3;while(Z<H)if(q=O[Z++],q!=Q[N++]){Z=1879048192;break}if(Z===H)return J=Z,Q.string;H-=3,Z=J}Q=[],$$[$]=Q,Q.bytes=X;while(Z<H)q=C.getUint32(Z),Q.push(q),Z+=4;H+=3;while(Z<H)q=O[Z++],Q.push(q);let D=X<16?KX(X):J$(X);if(D!=null)return Q.string=D;return Q.string=HX(X)}function N$(X){if(typeof X==="string")return X;if(typeof X==="number"||typeof X==="boolean"||typeof X==="bigint")return X.toString();if(X==null)return X+"";if(b.allowArraysInMapKeys&&Array.isArray(X)&&X.flat().every(($)=>["string","number","boolean","bigint"].includes(typeof $)))return X.flat().toString();throw Error(`Invalid property type for record: ${typeof X}`)}var Q$=(X,$)=>{let Q=h().map(N$),Z=X;if($!==void 0)X=X<32?-(($<<5)+X):($<<5)+X,Q.highByte=$;let H=E[X];if(H&&(H.isShared||K8))(E.restoreStructures||(E.restoreStructures=[]))[X]=H;return E[X]=Q,Q.read=JX(Q,Z),Q.read()};u[0]=()=>{};u[0].noBuffer=!0;u[66]=(X)=>{let $=X.byteLength%8||8,Q=BigInt(X[0]&128?X[0]-256:X[0]);for(let Z=1;Z<$;Z++)Q<<=BigInt(8),Q+=BigInt(X[Z]);if(X.byteLength!==$){let Z=new DataView(X.buffer,X.byteOffset,X.byteLength),H=(q,N)=>{let D=N-q;if(D<=40){let V=Z.getBigUint64(q);for(let j=q+8;j<N;j+=8)V<<=BigInt(64),V|=Z.getBigUint64(j);return V}let _=q+(D>>4<<3),M=H(q,_),T=H(_,N);return M<<BigInt((N-_)*8)|T};Q=Q<<BigInt((Z.byteLength-$)*8)|H($,Z.byteLength)}return Q};var Z$={Error,EvalError,RangeError,ReferenceError,SyntaxError,TypeError,URIError,AggregateError:typeof AggregateError==="function"?AggregateError:null};u[101]=()=>{let X=h();if(!Z$[X[0]]){let $=Error(X[1],{cause:X[2]});return $.name=X[0],$}return Z$[X[0]](X[1],{cause:X[2]})};u[105]=(X)=>{if(b.structuredClone===!1)throw Error("Structured clone extension is disabled");let $=C.getUint32(J-4);if(!H8)H8=new Map;let Q=O[J],Z;if(Q>=144&&Q<160||Q==220||Q==221)Z=[];else if(Q>=128&&Q<144||Q==222||Q==223)Z=new Map;else if((Q>=199&&Q<=201||Q>=212&&Q<=216)&&O[J+1]===115)Z=new Set;else Z={};let H={target:Z};H8.set($,H);let q=h();if(!H.used)return H.target=q;else Object.assign(Z,q);if(Z instanceof Map)for(let[N,D]of q.entries())Z.set(N,D);if(Z instanceof Set)for(let N of Array.from(q))Z.add(N);return Z};u[112]=(X)=>{if(b.structuredClone===!1)throw Error("Structured clone extension is disabled");let $=C.getUint32(J-4),Q=H8.get($);return Q.used=!0,Q.target};u[115]=()=>new Set(h());var NX=["Int8","Uint8","Uint8Clamped","Int16","Uint16","Int32","Uint32","Float32","Float64","BigInt64","BigUint64"].map((X)=>X+"Array"),f$=typeof globalThis==="object"?globalThis:window;u[116]=(X)=>{let $=X[0],Q=Uint8Array.prototype.slice.call(X,1).buffer,Z=NX[$];if(!Z){if($===16)return Q;if($===17)return new DataView(Q);throw Error("Could not find typed array for code "+$)}return new f$[Z](Q)};u[120]=()=>{let X=h();return new RegExp(X[0],X[1])};var g$=[];u[98]=(X)=>{let $=(X[0]<<24)+(X[1]<<16)+(X[2]<<8)+X[3],Q=J;return J+=$-X.length,g=g$,g=[X$(),X$()],g.position0=0,g.position1=0,g.postBundlePosition=J,J=Q,h()};u[255]=(X)=>{if(X.length==4)return new Date((X[0]*16777216+(X[1]<<16)+(X[2]<<8)+X[3])*1000);else if(X.length==8)return new Date(((X[0]<<22)+(X[1]<<14)+(X[2]<<6)+(X[3]>>2))/1e6+((X[3]&3)*4294967296+X[4]*16777216+(X[5]<<16)+(X[6]<<8)+X[7])*1000);else if(X.length==12)return new Date(((X[0]<<24)+(X[1]<<16)+(X[2]<<8)+X[3])/1e6+((X[4]&128?-281474976710656:0)+X[6]*1099511627776+X[7]*4294967296+X[8]*16777216+(X[9]<<16)+(X[10]<<8)+X[11])*1000);else return new Date("invalid")};function Y$(X){if(iX)iX();let $=n,Q=J,Z=ZX,H=s,q=e,N=J8,D=QX,_=H8,M=g,T=new Uint8Array(O.slice(0,n)),V=E,j=E.slice(0,E.length),k=b,v=K8,p=X();return n=$,J=Q,ZX=Z,s=H,e=q,J8=N,QX=D,H8=_,g=M,O=T,K8=v,E=V,E.splice(0,E.length,...j),b=k,C=new DataView(O.buffer,O.byteOffset,O.byteLength),p}function I8(){O=null,H8=null,E=null}function G$(X){if(X.unpack)u[X.type]=X.unpack;else u[X.type]=X}var y8=Array(147);for(let X=0;X<256;X++)y8[X]=+("1e"+Math.floor(45.15-X*0.30103));var S8=new X8({useRecords:!1}),p$=S8.unpack,u$=S8.unpackMultiple,l$=S8.unpack;var d$=new Float32Array(1),CQ=new Uint8Array(d$.buffer,0,4);var h8;try{h8=new TextEncoder}catch(X){}var m8,f8,D8=typeof Buffer<"u",v8=D8?function(X){return Buffer.allocUnsafeSlow(X)}:Uint8Array,O$=D8?Buffer:Uint8Array,D$=D8?4294967296:2144337920,Y,z8,I,K=0,l,S=null,c$,s$=21760,n$=/[\u0080-\uFFFF]/,G8=Symbol("record-id");class F8 extends X8{constructor(X){super(X);this.offset=0;let $,Q,Z,H,q,N=O$.prototype.utf8Write?function(G,z){return Y.utf8Write(G,z,Y.byteLength-z)}:h8&&h8.encodeInto?function(G,z){return h8.encodeInto(G,Y.subarray(z)).written}:!1,D=this;if(!X)X={};let _=X&&X.sequential,M=X.structures||X.saveStructures,T=X.maxSharedStructures;if(T==null)T=M?32:0;if(T>8160)throw Error("Maximum maxSharedStructure is 8160");if(X.structuredClone&&X.moreTypes==null)this.moreTypes=!0;let V=X.maxOwnStructures;if(V==null)V=M?32:64;if(!this.structures&&X.useRecords!=!1)this.structures=[];let j=T>32||V+T>64,k=T+64,v=T+V+64;if(v>8256)throw Error("Maximum maxSharedStructure + maxOwnStructure is 8192");let p=[],m=0,Q8=0;this.pack=this.encode=function(G,z){if(!Y)Y=new v8(8192),I=Y.dataView||(Y.dataView=new DataView(Y.buffer,0,8192)),K=0;if(l=Y.length-10,l-K<2048)Y=new v8(Y.length),I=Y.dataView||(Y.dataView=new DataView(Y.buffer,0,Y.length)),l=Y.length-10,K=0;else K=K+7&2147483640;if(Q=K,z&A$)K+=z&255;if(q=D.structuredClone?new Map:null,D.bundleStrings&&typeof G!=="string")S=[],S.size=1/0;else S=null;if(H=D.structures,H){if(H.uninitialized)H=D._mergeStructures(D.getStructures());let F=H.sharedLength||0;if(F>T)throw Error("Shared structures is larger than maximum shared structures, try increasing maxSharedStructures to "+H.sharedLength);if(!H.transitions){H.transitions=Object.create(null);for(let L=0;L<F;L++){let R=H[L];if(!R)continue;let B,W=H.transitions;for(let x=0,w=R.length;x<w;x++){let t=R[x];if(B=W[t],!B)B=W[t]=Object.create(null);W=B}W[G8]=L+64}this.lastNamedStructuresLength=F}if(!_)H.nextId=F+64}if(Z)Z=!1;let U;try{if(D.randomAccessStructure&&G&&typeof G==="object")if(G.constructor===Object)mX(G);else if(G.constructor!==Map&&!Array.isArray(G)&&!f8.some((L)=>G instanceof L))mX(G.toJSON?G.toJSON():G);else y(G);else y(G);let F=S;if(S)L$(Q,y,0);if(q&&q.idsToInsert){let L=q.idsToInsert.sort((x,w)=>x.offset>w.offset?1:-1),R=L.length,B=-1;while(F&&R>0){let x=L[--R].offset+Q;if(x<F.stringsPosition+Q&&B===-1)B=0;if(x>F.position+Q){if(B>=0)B+=6}else{if(B>=0)I.setUint32(F.position+Q,I.getUint32(F.position+Q)+B),B=-1;F=F.previous,R++}}if(B>=0&&F)I.setUint32(F.position+Q,I.getUint32(F.position+Q)+B);if(K+=L.length*6,K>l)Z8(K);D.offset=K;let W=o$(Y.subarray(Q,K),L);return q=null,W}if(D.offset=K,z&z$)return Y.start=Q,Y.end=K,Y;return Y.subarray(Q,K)}catch(F){throw U=F,F}finally{if(H){if(V8(),Z&&D.saveStructures){let F=H.sharedLength||0,L=Y.subarray(Q,K),R=i$(H,D);if(!U){if(D.saveStructures(R,R.isCompatible)===!1)return D.pack(G,z);if(D.lastNamedStructuresLength=F,Y.length>1073741824)Y=null;return L}}}if(Y.length>1073741824)Y=null;if(z&M$)K=Q}};let V8=()=>{if(Q8<10)Q8++;let G=H.sharedLength||0;if(H.length>G&&!_)H.length=G;if(m>1e4){if(H.transitions=null,Q8=0,m=0,p.length>0)p=[]}else if(p.length>0&&!_){for(let z=0,U=p.length;z<U;z++)p[z][G8]=0;p=[]}},a8=(G)=>{var z=G.length;if(z<16)Y[K++]=144|z;else if(z<65536)Y[K++]=220,Y[K++]=z>>8,Y[K++]=z&255;else Y[K++]=221,I.setUint32(K,z),K+=4;for(let U=0;U<z;U++)y(G[U])},y=(G)=>{if(K>l)Y=Z8(K);var z=typeof G,U;if(z==="string"){let F=G.length;if(S&&F>=4&&F<4096){if((S.size+=F)>s$){let W,x=(S[0]?S[0].length*3+S[1].length:0)+10;if(K+x>l)Y=Z8(K+x);let w;if(S.position)w=S,Y[K]=200,K+=3,Y[K++]=98,W=K-Q,K+=4,L$(Q,y,0),I.setUint16(W+Q-3,K-Q-W);else Y[K++]=214,Y[K++]=98,W=K-Q,K+=4;S=["",""],S.previous=w,S.size=0,S.position=W}let B=n$.test(G);S[B?0:1]+=G,Y[K++]=193,y(B?-F:F);return}let L;if(F<32)L=1;else if(F<256)L=2;else if(F<65536)L=3;else L=5;let R=F*3;if(K+R>l)Y=Z8(K+R);if(F<64||!N){let B,W,x,w=K+L;for(B=0;B<F;B++)if(W=G.charCodeAt(B),W<128)Y[w++]=W;else if(W<2048)Y[w++]=W>>6|192,Y[w++]=W&63|128;else if((W&64512)===55296&&((x=G.charCodeAt(B+1))&64512)===56320)W=65536+((W&1023)<<10)+(x&1023),B++,Y[w++]=W>>18|240,Y[w++]=W>>12&63|128,Y[w++]=W>>6&63|128,Y[w++]=W&63|128;else Y[w++]=W>>12|224,Y[w++]=W>>6&63|128,Y[w++]=W&63|128;U=w-K-L}else U=N(G,K+L);if(U<32)Y[K++]=160|U;else if(U<256){if(L<2)Y.copyWithin(K+2,K+1,K+1+U);Y[K++]=217,Y[K++]=U}else if(U<65536){if(L<3)Y.copyWithin(K+3,K+2,K+2+U);Y[K++]=218,Y[K++]=U>>8,Y[K++]=U&255}else{if(L<5)Y.copyWithin(K+5,K+3,K+3+U);Y[K++]=219,I.setUint32(K,U),K+=4}K+=U}else if(z==="number")if(G>>>0===G)if(G<32||G<128&&this.useRecords===!1||G<64&&!this.randomAccessStructure)Y[K++]=G;else if(G<256)Y[K++]=204,Y[K++]=G;else if(G<65536)Y[K++]=205,Y[K++]=G>>8,Y[K++]=G&255;else Y[K++]=206,I.setUint32(K,G),K+=4;else if(G>>0===G)if(G>=-32)Y[K++]=256+G;else if(G>=-128)Y[K++]=208,Y[K++]=G+256;else if(G>=-32768)Y[K++]=209,I.setInt16(K,G),K+=2;else Y[K++]=210,I.setInt32(K,G),K+=4;else{let F;if((F=this.useFloat32)>0&&G<4294967296&&G>=-2147483648){Y[K++]=202,I.setFloat32(K,G);let L;if(F<4||(L=G*y8[(Y[K]&127)<<1|Y[K+1]>>7])>>0===L){K+=4;return}else K--}Y[K++]=203,I.setFloat64(K,G),K+=8}else if(z==="object"||z==="function")if(!G)Y[K++]=192;else{if(q){let L=q.get(G);if(L){if(!L.id){let R=q.idsToInsert||(q.idsToInsert=[]);L.id=R.push(L)}Y[K++]=214,Y[K++]=112,I.setUint32(K,L.id),K+=4;return}else q.set(G,{offset:K-Q})}let F=G.constructor;if(F===Object)T8(G);else if(F===Array)a8(G);else if(F===Map)if(this.mapAsEmptyObject)Y[K++]=128;else{if(U=G.size,U<16)Y[K++]=128|U;else if(U<65536)Y[K++]=222,Y[K++]=U>>8,Y[K++]=U&255;else Y[K++]=223,I.setUint32(K,U),K+=4;for(let[L,R]of G)y(L),y(R)}else{for(let L=0,R=m8.length;L<R;L++){let B=f8[L];if(G instanceof B){let W=m8[L];if(W.write){if(W.type)Y[K++]=212,Y[K++]=W.type,Y[K++]=0;let O8=W.write.call(this,G);if(O8===G)if(Array.isArray(G))a8(G);else T8(G);else y(O8);return}let x=Y,w=I,t=K;Y=null;let q8;try{q8=W.pack.call(this,G,(O8)=>{if(Y=x,x=null,K+=O8,K>l)Z8(K);return{target:Y,targetView:I,position:K-O8}},y)}finally{if(x)Y=x,I=w,K=t,l=Y.length-10}if(q8){if(q8.length+K>l)Z8(q8.length+K);K=F$(q8,Y,K,W.type)}return}}if(Array.isArray(G))a8(G);else{if(G.toJSON){let L=G.toJSON();if(L!==G)return y(L)}if(z==="function")return y(this.writeFunction&&this.writeFunction(G));T8(G)}}}else if(z==="boolean")Y[K++]=G?195:194;else if(z==="bigint"){if(G<9223372036854776000&&G>=-9223372036854776000)Y[K++]=211,I.setBigInt64(K,G);else if(G<18446744073709552000&&G>0)Y[K++]=207,I.setBigUint64(K,G);else if(this.largeBigIntToFloat)Y[K++]=203,I.setFloat64(K,Number(G));else if(this.largeBigIntToString)return y(G.toString());else if(this.useBigIntExtension||this.moreTypes){let F=G<0?BigInt(-1):BigInt(0),L;if(G>>BigInt(65536)===F){let R=BigInt(18446744073709552000)-BigInt(1),B=[];while(!0){if(B.push(G&R),G>>BigInt(63)===F)break;G>>=BigInt(64)}L=new Uint8Array(new BigUint64Array(B).buffer),L.reverse()}else{let R=G<0,B=(R?~G:G).toString(16);if(B.length%2)B="0"+B;else if(parseInt(B.charAt(0),16)>=8)B="00"+B;if(D8)L=Buffer.from(B,"hex");else{L=new Uint8Array(B.length/2);for(let W=0;W<L.length;W++)L[W]=parseInt(B.slice(W*2,W*2+2),16)}if(R)for(let W=0;W<L.length;W++)L[W]=~L[W]}if(L.length+K>l)Z8(L.length+K);K=F$(L,Y,K,66);return}else throw RangeError(G+" was too large to fit in MessagePack 64-bit integer format, use useBigIntExtension, or set largeBigIntToFloat to convert to float-64, or set largeBigIntToString to convert to string");K+=8}else if(z==="undefined")if(this.encodeUndefinedAsNil)Y[K++]=192;else Y[K++]=212,Y[K++]=0,Y[K++]=0;else throw Error("Unknown type: "+z)},yX=this.variableMapSize||this.coercibleKeyAsNumber||this.skipValues?(G)=>{let z;if(this.skipValues){z=[];for(let L in G)if((typeof G.hasOwnProperty!=="function"||G.hasOwnProperty(L))&&!this.skipValues.includes(G[L]))z.push(L)}else z=Object.keys(G);let U=z.length;if(U<16)Y[K++]=128|U;else if(U<65536)Y[K++]=222,Y[K++]=U>>8,Y[K++]=U&255;else Y[K++]=223,I.setUint32(K,U),K+=4;let F;if(this.coercibleKeyAsNumber)for(let L=0;L<U;L++){F=z[L];let R=Number(F);y(isNaN(R)?F:R),y(G[F])}else for(let L=0;L<U;L++)y(F=z[L]),y(G[F])}:(G)=>{Y[K++]=222;let z=K-Q;K+=2;let U=0;for(let F in G)if(typeof G.hasOwnProperty!=="function"||G.hasOwnProperty(F))y(F),y(G[F]),U++;if(U>65535)throw Error('Object is too large to serialize with fast 16-bit map size, use the "variableMapSize" option to serialize this object');Y[z+++Q]=U>>8,Y[z+Q]=U&255},SX=this.useRecords===!1?yX:X.progressiveRecords&&!j?(G)=>{let z,U=H.transitions||(H.transitions=Object.create(null)),F=K++-Q,L;for(let R in G)if(typeof G.hasOwnProperty!=="function"||G.hasOwnProperty(R)){if(z=U[R],z)U=z;else{let B=Object.keys(G),W=U;U=H.transitions;let x=0;for(let w=0,t=B.length;w<t;w++){let q8=B[w];if(z=U[q8],!z)z=U[q8]=Object.create(null),x++;U=z}if(F+Q+1==K)K--,r8(U,B,x);else hX(U,B,F,x);L=!0,U=W[R]}y(G[R])}if(!L){let R=U[G8];if(R)Y[F+Q]=R;else hX(U,Object.keys(G),F,0)}}:(G)=>{let z,U=H.transitions||(H.transitions=Object.create(null)),F=0;for(let R in G)if(typeof G.hasOwnProperty!=="function"||G.hasOwnProperty(R)){if(z=U[R],!z)z=U[R]=Object.create(null),F++;U=z}let L=U[G8];if(L)if(L>=96&&j)Y[K++]=((L-=96)&31)+96,Y[K++]=L>>5;else Y[K++]=L;else r8(U,U.__keys__||Object.keys(G),F);for(let R in G)if(typeof G.hasOwnProperty!=="function"||G.hasOwnProperty(R))y(G[R])},vX=typeof this.useRecords=="function"&&this.useRecords,T8=vX?(G)=>{vX(G)?SX(G):yX(G)}:SX,Z8=(G)=>{let z;if(G>16777216){if(G-Q>D$)throw Error("Packed buffer would be larger than maximum buffer size");z=Math.min(D$,Math.round(Math.max((G-Q)*(G>67108864?1.25:2),4194304)/4096)*4096)}else z=(Math.max(G-Q<<2,Y.length-1)>>12)+1<<12;let U=new v8(z);if(I=U.dataView||(U.dataView=new DataView(U.buffer,0,z)),G=Math.min(G,Y.length),Y.copy)Y.copy(U,0,Q,G);else U.set(Y.slice(Q,G));return K-=Q,Q=0,l=U.length-10,Y=U},r8=(G,z,U)=>{let F=H.nextId;if(!F)F=64;if(F<k&&this.shouldShareStructure&&!this.shouldShareStructure(z)){if(F=H.nextOwnId,!(F<v))F=k;H.nextOwnId=F+1}else{if(F>=v)F=k;H.nextId=F+1}let L=z.highByte=F>=96&&j?F-96>>5:-1;if(G[G8]=F,G.__keys__=z,H[F-64]=z,F<k)if(z.isShared=!0,H.sharedLength=F-63,Z=!0,L>=0)Y[K++]=(F&31)+96,Y[K++]=L;else Y[K++]=F;else{if(L>=0)Y[K++]=213,Y[K++]=114,Y[K++]=(F&31)+96,Y[K++]=L;else Y[K++]=212,Y[K++]=114,Y[K++]=F;if(U)m+=Q8*U;if(p.length>=V)p.shift()[G8]=0;p.push(G),y(z)}},hX=(G,z,U,F)=>{let L=Y,R=K,B=l,W=Q;if(Y=z8,K=0,Q=0,!Y)z8=Y=new v8(8192);l=Y.length-10,r8(G,z,F),z8=Y;let x=K;if(Y=L,K=R,l=B,Q=W,x>1){let w=K+x-1;if(w>l)Z8(w);let t=U+Q;Y.copyWithin(t+x,t+1,K),Y.set(z8.slice(0,x),t),K=w}else Y[U+Q]=z8[0]},mX=(G)=>{let z=c$(G,Y,Q,K,H,Z8,(U,F,L)=>{if(L)return Z=!0;K=F;let R=Y;if(y(U),V8(),R!==Y)return{position:K,targetView:I,target:Y};return K},this);if(z===0)return T8(G);K=z}}useBuffer(X){Y=X,Y.dataView||(Y.dataView=new DataView(Y.buffer,Y.byteOffset,Y.byteLength)),I=Y.dataView,K=0}set position(X){K=X}get position(){return K}clearSharedData(){if(this.structures)this.structures=[];if(this.typedStructs)this.typedStructs=[]}}f8=[Date,Set,Error,RegExp,ArrayBuffer,Object.getPrototypeOf(Uint8Array.prototype).constructor,DataView,k8];m8=[{pack(X,$,Q){let Z=X.getTime()/1000;if((this.useTimestamp32||X.getMilliseconds()===0)&&Z>=0&&Z<4294967296){let{target:H,targetView:q,position:N}=$(6);H[N++]=214,H[N++]=255,q.setUint32(N,Z)}else if(Z>0&&Z<4294967296){let{target:H,targetView:q,position:N}=$(10);H[N++]=215,H[N++]=255,q.setUint32(N,X.getMilliseconds()*4000000+(Z/1000/4294967296>>0)),q.setUint32(N+4,Z)}else if(isNaN(Z)){if(this.onInvalidDate)return $(0),Q(this.onInvalidDate());let{target:H,targetView:q,position:N}=$(3);H[N++]=212,H[N++]=255,H[N++]=255}else{let{target:H,targetView:q,position:N}=$(15);H[N++]=199,H[N++]=12,H[N++]=255,q.setUint32(N,X.getMilliseconds()*1e6),q.setBigInt64(N+4,BigInt(Math.floor(Z)))}}},{pack(X,$,Q){if(this.setAsEmptyObject)return $(0),Q({});let Z=Array.from(X),{target:H,position:q}=$(this.moreTypes?3:0);if(this.moreTypes)H[q++]=212,H[q++]=115,H[q++]=0;Q(Z)}},{pack(X,$,Q){let{target:Z,position:H}=$(this.moreTypes?3:0);if(this.moreTypes)Z[H++]=212,Z[H++]=101,Z[H++]=0;Q([X.name,X.message,X.cause])}},{pack(X,$,Q){let{target:Z,position:H}=$(this.moreTypes?3:0);if(this.moreTypes)Z[H++]=212,Z[H++]=120,Z[H++]=0;Q([X.source,X.flags])}},{pack(X,$){if(this.moreTypes)YX(X,16,$);else GX(D8?Buffer.from(X):new Uint8Array(X),$)}},{pack(X,$){let Q=X.constructor;if(Q!==O$&&this.moreTypes)YX(X,NX.indexOf(Q.name),$);else GX(X,$)}},{pack(X,$){if(this.moreTypes)YX(X,17,$);else GX(D8?Buffer.from(X):new Uint8Array(X),$)}},{pack(X,$){let{target:Q,position:Z}=$(1);Q[Z]=193}}];function YX(X,$,Q,Z){let H=X.byteLength;if(H+1<256){var{target:q,position:N}=Q(4+H);q[N++]=199,q[N++]=H+1}else if(H+1<65536){var{target:q,position:N}=Q(5+H);q[N++]=200,q[N++]=H+1>>8,q[N++]=H+1&255}else{var{target:q,position:N,targetView:D}=Q(7+H);q[N++]=201,D.setUint32(N,H+1),N+=4}if(q[N++]=116,q[N++]=$,!X.buffer)X=new Uint8Array(X);q.set(new Uint8Array(X.buffer,X.byteOffset,X.byteLength),N)}function GX(X,$){let Q=X.byteLength;var Z,H;if(Q<256){var{target:Z,position:H}=$(Q+2);Z[H++]=196,Z[H++]=Q}else if(Q<65536){var{target:Z,position:H}=$(Q+3);Z[H++]=197,Z[H++]=Q>>8,Z[H++]=Q&255}else{var{target:Z,position:H,targetView:q}=$(Q+5);Z[H++]=198,q.setUint32(H,Q),H+=4}Z.set(X,H)}function F$(X,$,Q,Z){let H=X.length;switch(H){case 1:$[Q++]=212;break;case 2:$[Q++]=213;break;case 4:$[Q++]=214;break;case 8:$[Q++]=215;break;case 16:$[Q++]=216;break;default:if(H<256)$[Q++]=199,$[Q++]=H;else if(H<65536)$[Q++]=200,$[Q++]=H>>8,$[Q++]=H&255;else $[Q++]=201,$[Q++]=H>>24,$[Q++]=H>>16&255,$[Q++]=H>>8&255,$[Q++]=H&255}return $[Q++]=Z,$.set(X,Q),Q+=H,Q}function o$(X,$){let Q,Z=$.length*6,H=X.length-Z;while(Q=$.pop()){let{offset:q,id:N}=Q;X.copyWithin(q+Z,q,H),Z-=6;let D=q+Z;X[D++]=214,X[D++]=105,X[D++]=N>>24,X[D++]=N>>16&255,X[D++]=N>>8&255,X[D++]=N&255,H=q}return X}function L$(X,$,Q){if(S.length>0){I.setUint32(S.position+X,K+Q-S.position-X),S.stringsPosition=K-X;let Z=S;S=null,$(Z[0]),$(Z[1])}}function DX(X){if(X.Class){if(!X.pack&&!X.write)throw Error("Extension has no pack or write function");if(X.pack&&!X.type)throw Error("Extension has no type (numeric code to identify the extension)");f8.unshift(X.Class),m8.unshift(X)}G$(X)}function i$(X,$){return X.isCompatible=(Q)=>{let Z=!Q||($.lastNamedStructuresLength||0)===Q.length;if(!Z)$._mergeStructures(Q);return Z},X}var _$=new F8({useRecords:!1}),a$=_$.pack,r$=_$.pack;var z$=512,M$=1024,A$=2048;var R$=80;class a{capId;constructor(X){this.capId=X}}var t$=new Set(["hello","goaway","call","result","cancel","stream","drop","cap_revoked"]);function FX(X){if(typeof X!=="object"||X===null)return!1;let $=X,Q=$.op;if(typeof Q!=="string"||!t$.has(Q))return!1;switch(Q){case"hello":return $.v===1&&($.mode==="native"||$.mode==="web")&&Array.isArray($.features)&&typeof $.maxBytes==="number"&&typeof $.origin==="string";case"goaway":return $.reason===void 0||typeof $.reason==="string";case"call":return typeof $.id==="number"&&typeof $.method==="string"&&typeof $.target==="object"&&$.target!==null&&$.target.kind==="cap"&&typeof $.target.id==="number";case"result":return typeof $.id==="number"&&($.ok===!0||$.ok===!1);case"cancel":return typeof $.id==="number";case"stream":return typeof $.id==="number"&&typeof $.ev==="string"&&($.ev==="next"||$.ev==="credit"||$.ev==="end"||$.ev==="error");case"drop":return Array.isArray($.caps);case"cap_revoked":if(!Array.isArray($.capIds))return!1;for(let Z of $.capIds)if(typeof Z!=="number"||!Number.isInteger(Z)||Z<0||Z>4294967295)return!1;return!0}}var W$=!1;function e$(){if(W$)return;W$=!0,DX({Class:a,type:R$,pack:(X)=>XQ(X.capId),unpack:(X)=>new a(QQ(X))})}function LX(){return e$(),{packr:new F8({useRecords:!0,sequential:!0,moreTypes:!0}),unpackr:new X8({useRecords:!0,sequential:!0,moreTypes:!0})}}function XQ(X){let $=new Uint8Array(5),Q=X>>>0,Z=0;while(Q>=128)$[Z++]=Q&127|128,Q>>>=7;return $[Z++]=Q&127,$.subarray(0,Z)}var $Q=5;function QQ(X){let $=0,Q=0,Z=Math.min(X.length,$Q);for(let H=0;H<Z;H++){let q=X[H];if($|=(q&127)<<Q,(q&128)===0)return $>>>0;Q+=7}throw Error("Truncated or oversize varuint")}var UX=67108864,OX=1,g8="bunite.",p8="bootstrap";class P extends Error{code;details;retry;constructor(X){super(X.message??X.code);this.name="IpcError",this.code=X.code,this.details=X.details,this.retry=X.retry}toStatus(){return{code:this.code,message:this.message,details:this.details,retry:this.retry}}}var u8=i("bunite.BrowserWindow",{focus:A(),close:A(),setBounds:A(),setTitle:A(),id:A({idempotent:!0}),label:A({idempotent:!0})}),_X=i("bunite.Window",{create:A({returns:c(u8)}),list:A({returns:c.array(u8),idempotent:!0}),focus:A(),close:A()}),l8=i("bunite.FileRef",{text:A({idempotent:!0}),bytes:A({idempotent:!0}),path:A({idempotent:!0}),revoke:A()},{disposal:{method:"revoke"}}),zX=i("bunite.Dialogs",{openFile:A({returns:c.array(l8)}),saveFile:A({returns:c(l8)}),showMessage:A()}),MX=i("bunite.Clipboard",{readText:A({idempotent:!0}),writeText:A(),readBytes:A({idempotent:!0}),writeBytes:A()}),AX=i("bunite.Shell",{openExternal:A(),showItemInFolder:A()}),WX=i("bunite.PageReporting",{reportConsoleBatch:A()}),RX=i("bunite.Surface",{init:A(),resize:A(),remove:A(),setHidden:A(),setMasks:A(),setAllPassthrough:A(),bringAllVisiblesToFront:A(),navigate:A(),goBack:A(),reload:A(),evaluate:A(),capabilities:A(),click:A(),type:A(),press:A(),scroll:A(),mouse:A(),screenshot:A(),waitForSelector:A(),waitForFunction:A(),respondToDialog:A(),setDialogTimeout:A(),getConsoleBuffer:A({idempotent:!0}),surfaceEvents:Y8(),dialogs:Y8(),consoleEvents:Y8()}),M8=i("bunite.Runtime",{window:A({returns:c(_X),idempotent:!0}),dialogs:A({returns:c(zX),idempotent:!0}),clipboard:A({returns:c(MX),idempotent:!0}),shell:A({returns:c(AX),idempotent:!0}),appName:A({idempotent:!0}),appVersion:A({idempotent:!0}),theme:A({idempotent:!0}),themeWatch:Y8(),surface:A({returns:c(RX),idempotent:!0}),reporting:A({returns:c(WX),idempotent:!0})}),$8={Runtime:1,Window:2,Dialogs:3,FileRef:4,Clipboard:5,Shell:6,BrowserWindow:7,Surface:8,PageReporting:9},ZQ=new Map([[M8,$8.Runtime],[_X,$8.Window],[zX,$8.Dialogs],[l8,$8.FileRef],[MX,$8.Clipboard],[AX,$8.Shell],[u8,$8.BrowserWindow],[RX,$8.Surface],[WX,$8.PageReporting]]);function BX(X){return ZQ.get(X)}var c8=0,PX=1,V$=0,T$=1,L8=2,CX=128,s8=1024,P$=1024,HQ=s8*4,qQ=500,JQ=32,KQ=8,NQ=1024;function YQ(X){let $=X?.initialBudget;if(typeof $!=="number"||!Number.isFinite($)||!Number.isInteger($)||$<1)return JQ;return Math.min($,NQ)}var d8=null;class EX{entries=new Map;nextCapId=L8;capLimit;constructor(X=s8){this.capLimit=X}install(X,$){if(this.entries.has(X))throw Error(`cap-id ${X} already installed`);let Q={capId:X,...$};return this.entries.set(X,Q),Q}allocate(X){if(this.entries.size>=this.capLimit)throw new P({code:"resource_exhausted",message:`cap-table limit ${this.capLimit}`,details:{reason:"max_caps_per_connection"}});let $=this.nextCapId++;while(this.entries.has($))$=this.nextCapId++;return this.install($,X)}get(X){return this.entries.get(X)}release(X,$=1){let Q=this.entries.get(X);if(!Q)return!1;if(Q.refCount=Math.max(0,Q.refCount-$),Q.refCount===0&&X>=L8)return this.entries.delete(X),!0;return!1}delete(X){if(X<L8)return!1;return this.entries.delete(X)}clear(){this.entries.clear(),this.nextCapId=L8}size(){return this.entries.size}values(){return this.entries.values()}}var GQ={origin:"",topOrigin:"",partition:"default",isAppRes:!1,isMainFrame:!1,userGesture:!1,level:"untrusted"},C$=Symbol("bunite.rpc.ExportedCap"),B$=Symbol("bunite.rpc.CapProxyMeta");function DQ(X){return typeof X==="object"&&X!==null&&X[C$]===!0}var FQ=typeof FinalizationRegistry<"u"?new FinalizationRegistry((X)=>{if(X.dropped())return;let $=X.connRef.deref();if(!$||$.closed)return;$._dropFromFinalizer(X.capId)}):{register:()=>{}};class E${transport;capTable;pending=new Map;clientStreams=new Map;serverStreams=new Map;serverCallChildren=new Map;serverActiveCalls=new Map;registry=new Map;rootInstances=new Map;revokedCapIds=new Set;closeHandlers=new Set;observers={};nextCallId=1;remoteHello=null;remoteReady;resolveRemoteReady;rejectRemoteReady;closed_=!1;maxBytes;maxInFlightCalls;mode;origin;features;attestation;peerId;policy;constructor(X){this.transport=X.transport,this.mode=X.mode,this.origin=X.origin,this.features=X.features??[],this.maxBytes=X.maxBytes??UX,this.maxInFlightCalls=X.maxInFlightCalls??P$,this.attestation=X.attestation??GQ,this.peerId=X.peerId??"peer",this.policy=X.policy,this.capTable=new EX(X.capLimit??s8),this.capTable.install(c8,{typeId:V$,cap:null,impl:null,refCount:1}),this.capTable.install(PX,{typeId:T$,cap:M8,impl:X.runtime??null,refCount:1}),this.remoteReady=new Promise(($,Q)=>{this.resolveRemoteReady=$,this.rejectRemoteReady=Q}),this.remoteReady.catch(()=>{}),this.transport.setReceive(($)=>this.handleFrame($)),this.transport.send({op:"hello",v:OX,mode:this.mode,features:this.features,maxBytes:this.maxBytes,origin:this.origin})}get closed(){return this.closed_}onClose(X){return this.closeHandlers.add(X),()=>this.closeHandlers.delete(X)}on(X,$){let Q=this.observers[X];if(!Q)Q=new Set,this.observers[X]=Q;return Q.add($),()=>{Q.delete($)}}emitObs(X,$){let Q=this.observers[X];if(!Q||Q.size===0)return;for(let Z of Q)try{Z($)}catch{}}markRevoked(X){this.revokedCapIds.add(X);while(this.revokedCapIds.size>HQ){let $=this.revokedCapIds.values().next().value;if($===void 0)break;this.revokedCapIds.delete($)}}serve(X,$,Q){this.assertNotFrameworkName(X.name);let Z=Q?.ifExists??"throw";if(this.registry.get(X.name))switch(Z){case"throw":throw new P({code:"already_exists",message:`cap "${X.name}" already served`,details:{reason:"name_collision"}});case"skip":return this.makeHandle([]);case"replace":return this.replace(X,$),this.makeHandle([X.name])}return this.registry.set(X.name,{cap:X,impl:$,version:X.version}),this.makeHandle([X.name])}makeHandle(X){let $={names:X,[Symbol.dispose]:()=>this.unserve($)};return $}serveAll(X,$,Q){let Z=Q?.ifExists??"throw";for(let q of Object.keys(X.roots)){let N=X.roots[q];this.assertNotFrameworkName(N.name);let D=this.registry.get(N.name);if(D){if(Z==="throw")throw new P({code:"already_exists",message:`cap "${N.name}" already served`,details:{reason:"name_collision"}});if(Z==="replace"&&D.version!==N.version)throw new P({code:"failed_precondition",message:`version mismatch on replace for "${N.name}" (current "${D.version}", new "${N.version}")`,details:{reason:"version_mismatch"}})}}let H=[];for(let q of Object.keys(X.roots)){let N=X.roots[q],D=$[q];if(this.serve(N,D,{ifExists:Z}).names.length>0)H.push(N.name)}return this.makeHandle(H)}unserve(X){let $=w8(X)?[X.name]:Array.from(X.names),Q=[];for(let Z of $){if(!this.registry.delete(Z))continue;let H=this.rootInstances.get(Z);if(H!==void 0){let q=this.capTable.get(H);if(q)this.invokeServerDisposal(q);this.rootInstances.delete(Z),this.capTable.delete(H),Q.push(H)}}if(Q.length>0)this.transport.send({op:"cap_revoked",capIds:Q}),this.emitObs("revoke",{capIds:Q,reason:"unserve"})}replace(X,$){let Q=this.registry.get(X.name);if(!Q)throw new P({code:"not_found",message:`cap "${X.name}" not served`});if(Q.version!==X.version)throw new P({code:"failed_precondition",message:`version mismatch (current "${Q.version}", new "${X.version}")`,details:{reason:"version_mismatch"}});Q.impl=$,Q.cap=X;let Z=this.rootInstances.get(X.name);if(Z!==void 0){let H=this.capTable.get(Z);if(H)H.impl=$,H.cap=X}this.emitObs("revoke",{capIds:Z!==void 0?[Z]:[],reason:"replace"})}assertNotFrameworkName(X){if(X.startsWith(g8))throw new P({code:"already_exists",message:`cap name "${X}" uses reserved prefix "${g8}"`,details:{reason:"reserved_namespace"}})}runtimeProxy=null;runtime(){if(!this.runtimeProxy)this.runtimeProxy=this.makeCapProxy(M8,PX);return this.runtimeProxy}async bootstrap(X){if(w8(X))return this._bootstrapCap(X);if(e8(X))return this._bootstrapSchema(X);throw new P({code:"invalid_argument",message:"bootstrap target must be CapDef or Schema"})}async _bootstrapCap(X){await this.remoteReady;let $={name:X.name};if(X.version!=null)$.version=X.version;let Q=await this.sendCallTyped(c8,p8,$,void 0);if(!(Q instanceof a))throw new P({code:"invalid_argument",message:"bootstrap did not return a CapRef"});return this.makeCapProxy(X,Q.capId)}async _bootstrapSchema(X){let $=Object.keys(X.roots),Q=await Promise.allSettled($.map((q)=>this._bootstrapCap(X.roots[q]))),Z=Q.find((q)=>q.status==="rejected");if(Z){for(let q of Q)if(q.status==="fulfilled")try{this.releaseRef(q.value)}catch{}throw Z.reason}let H={};for(let q=0;q<$.length;q++)H[$[q]]=Q[q].value;return H}handleFrame(X){if(this.closed_)return;switch(X.op){case"hello":this.handleHello(X);return;case"call":this.handleCall(X);return;case"result":this.handleResult(X);return;case"cancel":this.handleCancel(X);return;case"stream":this.handleStreamFrame(X);return;case"drop":this.handleDrop(X);return;case"cap_revoked":this.handleCapRevoked(X);return;case"goaway":this.handleGoaway(X);return;default:this.handleUnknownFrame(X);return}}handleUnknownFrame(X){let $=X?.id;if(typeof $==="number"){this.transport.send({op:"result",id:$,ok:!1,error:{code:"invalid_argument",message:"unknown opcode"}});return}this.transport.send({op:"goaway",reason:"invalid_argument",error:{code:"invalid_argument",message:"unknown opcode"}}),this.shutdown("invalid_argument")}handleHello(X){this.remoteHello=X,this.resolveRemoteReady(X)}handleGoaway(X){this.rejectRemoteReady(new P(X.error??{code:"unavailable",message:X.reason??"peer goaway"})),this.shutdown(X.reason??"remote goaway")}handleCapRevoked(X){for(let $ of X.capIds){this.markRevoked($);let Q=new P({code:"failed_precondition",message:"cap revoked",details:{reason:"revoked"}});for(let[Z,H]of this.pending)if(H.capId===$){if(this.pending.delete(Z),H.timer)clearTimeout(H.timer);H.reject(Q)}for(let[Z,H]of this.clientStreams)if(H.capId===$)this.clientStreams.delete(Z),H.fail(Q)}}async handleCall(X){if(X.target.id===c8&&X.method===p8){await this.handleBootstrap(X);return}let $=this.capTable.get(X.target.id);if(!$)return this.emitObs("call",{capId:X.target.id,method:X.method,callId:X.id,result:"not_found"}),this.sendError(X.id,"not_found",`cap-id ${X.target.id} not found`);let Q=$.cap;if(!Q||!$.impl)return this.emitObs("call",{capId:X.target.id,method:X.method,callId:X.id,result:"not_found"}),this.sendError(X.id,"not_found","cap has no impl");let Z=Q.methods[X.method];if(!Z)return this.emitObs("call",{capId:X.target.id,capName:Q.name,method:X.method,callId:X.id,result:"not_found"}),this.sendError(X.id,"not_found",`method "${X.method}" on cap "${Q.name}"`);let H=$.impl[X.method];if(typeof H!=="function")return this.emitObs("call",{capId:X.target.id,capName:Q.name,method:X.method,callId:X.id,result:"not_found"}),this.sendError(X.id,"not_found",`method "${X.method}" has no handler`);if(this.serverActiveCalls.size+this.serverStreams.size>=this.maxInFlightCalls)return this.emitObs("call",{capId:X.target.id,capName:Q.name,method:X.method,callId:X.id,result:"resource_exhausted"}),this.sendError(X.id,"resource_exhausted",`in-flight calls limit ${this.maxInFlightCalls}`,{reason:"max_concurrent_calls"});await this.invokeServerMethod(X,Q,Z,H)}async handleBootstrap(X){let $=X.args??{},Q=$.name;if(typeof Q!=="string")return this.emitObs("bootstrap",{name:String(Q),attestation:this.attestation,result:"invalid_argument"}),this.sendError(X.id,"invalid_argument","bootstrap requires {name: string}");let Z=$.version!=null?String($.version):void 0,H=this.registry.get(Q);if(!H)return this.emitObs("bootstrap",{name:Q,version:Z,attestation:this.attestation,result:"not_found"}),this.sendError(X.id,"not_found",`cap "${Q}" not served`);let q=H.version;if(q!=null&&Z!=null&&q!==Z)return this.emitObs("bootstrap",{name:Q,version:Z,attestation:this.attestation,result:"version_mismatch"}),this.sendError(X.id,"failed_precondition",`version mismatch (server "${q}", client "${Z}")`,{reason:"version_mismatch"});if(this.policy){let D;try{D=await this.policy(Q,this.attestation)}catch(_){return this.emitObs("error",{phase:"policy",error:_ instanceof Error?_:Error(String(_))}),this.emitObs("bootstrap",{name:Q,version:Z,attestation:this.attestation,result:"internal"}),this.sendError(X.id,"internal","policy threw")}if(typeof D!=="boolean")return this.emitObs("error",{phase:"policy",error:Error(`policy must return boolean (got ${typeof D})`)}),this.emitObs("bootstrap",{name:Q,version:Z,attestation:this.attestation,result:"internal"}),this.sendError(X.id,"internal","policy returned non-boolean");if(!D)return this.emitObs("bootstrap",{name:Q,version:Z,attestation:this.attestation,result:"denied"}),this.sendError(X.id,"failed_precondition","policy denied",{reason:"unauthorized"})}let N=this.rootInstances.get(Q);if(N!==void 0){let D=this.capTable.get(N);if(D)D.refCount+=1;else this.rootInstances.delete(Q),N=void 0}if(N===void 0)try{N=this.capTable.allocate({typeId:BX(H.cap)??CX,cap:H.cap,impl:H.impl,refCount:1}).capId,this.rootInstances.set(Q,N)}catch(D){if(D instanceof P){let _=D.code==="resource_exhausted"?"resource_exhausted":"internal";return this.emitObs("bootstrap",{name:Q,version:Z,attestation:this.attestation,result:_}),this.sendError(X.id,D.code,D.message,D.details)}throw D}this.emitObs("bootstrap",{name:Q,version:Z,attestation:this.attestation,result:"ok",capId:N}),this.transport.send({op:"result",id:X.id,ok:!0,value:new a(N)})}async invokeServerMethod(X,$,Q,Z){let H=this.makeCallCtx(X);if(x8(Q)){let q=YQ(Q.hint);try{let N=()=>Z(X.args,H),D=d8,M=(D?()=>D.run({callId:X.id},N):N)();this.runServerStream(X.id,M,H,q,$,X.method,X.target.id)}catch(N){this.emitObs("stream",{capId:X.target.id,capName:$.name,method:X.method,callId:X.id,event:"error"}),this.transport.send({op:"stream",id:X.id,ev:"error",error:VX(N)})}return}if(j8(Q)){let q=performance.now(),N=Q.idempotent?void 0:this.armServerDeadline(X,H);this.serverActiveCalls.set(X.id,{ctrl:H._ctrl,capId:X.target.id,capName:$.name,method:X.method,startedAt:q});let D=LQ(Q.returns),_=()=>Promise.resolve(Z(X.args,H)),M=d8,T=M?()=>M.run({callId:X.id},_):_;try{let V=await T();if(N)clearTimeout(N);if(!this.serverActiveCalls.delete(X.id))return;let j=D(V);this.transport.send({op:"result",id:X.id,ok:!0,value:j}),this.emitObs("call",{capId:X.target.id,capName:$.name,method:X.method,callId:X.id,durationMs:performance.now()-q,result:"ok"})}catch(V){if(N)clearTimeout(N);if(!this.serverActiveCalls.delete(X.id))return;let j=VX(V);this.sendErrorFromStatus(X.id,j),this.emitObs("call",{capId:X.target.id,capName:$.name,method:X.method,callId:X.id,durationMs:performance.now()-q,result:j.code})}return}this.sendError(X.id,"not_found","unknown method kind")}armServerDeadline(X,$){let Q=X.meta?.deadlineMs;if(!Q)return;return setTimeout(()=>{$._ctrl.abort()},Q)}makeCallCtx(X){let $=new AbortController;return{callId:X.id,peerId:this.peerId,attestation:this.attestation,signal:$.signal,deadline:X.meta?.deadlineMs,_ctrl:$,exportCap:(Z,H)=>this.exportCap(Z,H)}}exportCap(X,$){let Q=BX(X)??CX,Z=this.capTable.allocate({typeId:Q,cap:X,impl:$,refCount:1});return{[C$]:!0,cap:X,capId:Z.capId,typeId:Z.typeId}}runServerStream(X,$,Q,Z,H,q,N){let D=$[Symbol.asyncIterator](),_=Q._ctrl,M={iter:D,abort:_,cancelled:!1,credit:Z,creditWaker:null,capId:N,capName:H.name,method:q,callId:X,count:0};this.serverStreams.set(X,M),this.emitObs("stream",{capId:N,capName:H.name,method:q,callId:X,event:"start"});let T=()=>{if(M.credit>0||M.cancelled)return Promise.resolve();return new Promise((j)=>{M.creditWaker=j})};(async()=>{let j=!1;try{while(!M.cancelled){if(M.credit===0)await T();if(M.cancelled)break;let{done:k,value:v}=await D.next();if(k)break;if(M.cancelled)break;M.credit-=1,M.count+=1,this.transport.send({op:"stream",id:X,ev:"next",value:v})}}catch(k){j=!0,this.transport.send({op:"stream",id:X,ev:"error",error:VX(k)}),this.emitObs("stream",{capId:N,capName:H.name,method:q,callId:X,event:"error",count:M.count})}finally{if(!j)this.transport.send({op:"stream",id:X,ev:"end"}),this.emitObs("stream",{capId:N,capName:H.name,method:q,callId:X,event:M.cancelled?"cancel":"end",count:M.count});this.serverStreams.delete(X)}})()}handleResult(X){let $=this.pending.get(X.id);if($){if(this.pending.delete(X.id),this.serverCallChildren.delete(X.id),$.timer)clearTimeout($.timer);if(X.ok){let Z=$.decodeReturn?$.decodeReturn(X.value):X.value;$.resolve(Z)}else $.reject(new P(X.error));return}let Q=this.clientStreams.get(X.id);if(Q){this.clientStreams.delete(X.id);let Z=X.ok?new P({code:"invalid_argument",message:"stream method returned result frame"}):new P(X.error);Q.fail(Z)}}handleCancel(X){let $=this.serverStreams.get(X.id);if($)$.cancelled=!0,$.abort.abort(),$.iter?.return?.(),this.serverStreams.delete(X.id);let Q=this.serverActiveCalls.get(X.id);if(Q)this.serverActiveCalls.delete(X.id),Q.ctrl.abort(),this.transport.send({op:"result",id:X.id,ok:!1,error:{code:"cancelled",message:X.reason}}),this.emitObs("call",{capId:Q.capId,capName:Q.capName,method:Q.method,callId:X.id,durationMs:performance.now()-Q.startedAt,result:"cancelled"});for(let[Z,H]of this.serverCallChildren){if(H.parentId!==X.id)continue;if(this.serverCallChildren.delete(Z),this.pending.has(Z))this.transport.send({op:"cancel",id:Z,reason:X.reason})}}releaseRef(X){if(typeof X!=="object"||X===null)return;let $=X[B$];if(!$||$.dropped)return;$.dropped=!0,this.sendDrop($.capId)}sendDrop(X){if(this.closed_)return;if(X<L8)return;this.transport.send({op:"drop",caps:[{id:X,delta:1}]})}handleStreamFrame(X){if(X.ev==="credit"){let Q=this.serverStreams.get(X.id);if(!Q)return;Q.credit+=X.credit?.messages??0;let Z=Q.creditWaker;Q.creditWaker=null,Z?.();return}let $=this.clientStreams.get(X.id);if(!$)return;switch(X.ev){case"next":$.push(X.value);return;case"end":$.end(),this.clientStreams.delete(X.id);return;case"error":$.fail(new P(X.error)),this.clientStreams.delete(X.id);return}}handleDrop(X){for(let{id:$,delta:Q}of X.caps)if(this.capTable.release($,Q)){for(let[H,q]of this.rootInstances)if(q===$){this.rootInstances.delete(H);break}}}sendError(X,$,Q,Z){let H={code:$,message:Q};if(Z!==void 0)H.details=Z;this.transport.send({op:"result",id:X,ok:!1,error:H})}sendErrorFromStatus(X,$){this.transport.send({op:"result",id:X,ok:!1,error:$})}nextId(){return this.nextCallId++}sendCallTyped(X,$,Q,Z,H,q){if(this.closed_)return Promise.reject(new P({code:"unavailable",message:"connection closed"}));if(this.revokedCapIds.has(X))return Promise.reject(new P({code:"failed_precondition",message:"cap revoked",details:{reason:"revoked"}}));if(this.pending.size>=this.maxInFlightCalls)return Promise.reject(new P({code:"resource_exhausted",message:`in-flight calls limit ${this.maxInFlightCalls}`,details:{reason:"max_concurrent_calls"}}));let N=this.nextId();return new Promise((D,_)=>{let M=new AbortController,T={resolve:D,reject:_,abort:M,decodeReturn:Z,startedAt:performance.now(),capId:X,method:$,capName:q,kind:"call"};if(H?.deadlineMs)T.timer=setTimeout(()=>{if(this.pending.delete(N))this.transport.send({op:"cancel",id:N,reason:"deadline_exceeded"}),_(new P({code:"deadline_exceeded"}))},H.deadlineMs+qQ);this.pending.set(N,T);let V=H;if(V?.parentCallId===void 0&&d8){let j=d8.getStore();if(j)V={...V??{},parentCallId:j.callId}}if(V?.parentCallId!==void 0)this.serverCallChildren.set(N,{parentId:V.parentCallId});this.transport.send({op:"call",id:N,target:{kind:"cap",id:X},method:$,args:Q,meta:V})})}openClientStream(X,$,Q,Z,H){if(this.closed_){let M=TX(X,0,()=>{},()=>{});return M.fail(new P({code:"unavailable",message:"connection closed"})),M.stream}if(this.revokedCapIds.has(X)){let M=TX(X,0,()=>{},()=>{});return M.fail(new P({code:"failed_precondition",message:"cap revoked",details:{reason:"revoked"}})),M.stream}let q=this.nextId(),_=TX(X,q,()=>{if(this.clientStreams.delete(q))this.transport.send({op:"cancel",id:q,reason:"client_cancel"})},(M)=>{if(this.closed_||!this.clientStreams.has(q))return;this.transport.send({op:"stream",id:q,ev:"credit",credit:{messages:M}})});return this.clientStreams.set(q,_),this.transport.send({op:"call",id:q,target:{kind:"cap",id:X},method:$,args:Q,meta:Z}),_.stream}makeCapProxy(X,$){let Q={},Z={capId:$,dropped:!1};Q[B$]=Z;let H=()=>{if(Z.dropped)return;Z.dropped=!0,this.sendDrop($)};for(let N of Object.keys(X.methods)){let D=X.methods[N];if(x8(D))Q[N]=(_)=>this.openClientStream($,N,_,void 0,X.name);else if(j8(D)){let _=UQ(D.returns,(M,T)=>this.makeCapProxy(M,T));Q[N]=(M)=>this.sendCallTyped($,N,M,_,void 0,X.name)}}let q=X.disposal;if(q){let N=this;Q[Symbol.dispose]=()=>{try{let D=Q[q.method]?.();if(D&&typeof D.then==="function")D.catch((_)=>N.emitObs("error",{phase:"dispose",error:_ instanceof Error?_:Error(String(_))}))}catch(D){N.emitObs("error",{phase:"dispose",error:D instanceof Error?D:Error(String(D))})}H()}}if(typeof FinalizationRegistry<"u")FQ.register(Q,{connRef:new WeakRef(this),capId:$,dropped:()=>Z.dropped});return Q}_dropFromFinalizer(X){try{this.sendDrop(X)}catch{}}shutdown(X="shutdown"){if(this.closed_)return;this.closed_=!0;for(let $ of this.pending.values()){if($.timer)clearTimeout($.timer);$.reject(new P({code:"unavailable",message:X}))}this.pending.clear();for(let $ of this.clientStreams.values())$.fail(new P({code:"unavailable",message:X}));this.clientStreams.clear();for(let $ of this.serverStreams.values())$.cancelled=!0,$.abort.abort(),$.iter?.return?.();this.serverStreams.clear();for(let $ of this.serverActiveCalls.values())$.ctrl.abort();this.serverActiveCalls.clear();for(let $ of this.capTable.values())this.invokeServerDisposal($);if(this.capTable.clear(),!this.remoteHello)this.rejectRemoteReady(new P({code:"unavailable",message:X}));for(let $ of this.closeHandlers)try{$()}catch{}this.closeHandlers.clear();try{this.transport.close()}catch{}}invokeServerDisposal(X){let $=X.cap;if(!$)return;let Q=$.disposal;if(!Q)return;let Z=X.impl,H=Z?.[Q.method];if(!H)return;try{H.call(Z,void 0,void 0)}catch{}}}function LQ(X){if(!X)return(Q)=>Q;let $=(Q,Z)=>{if(!DQ(Q))throw new P({code:"failed_precondition",message:"expected ctx.exportCap return for cap method",details:{reason:"unregistered_cap_return"}});if(Q.cap!==Z)throw new P({code:"failed_precondition",message:"exported cap type mismatch with method returns",details:{reason:"unregistered_cap_return"}});return new a(Q.capId)};if(P8(X))return(Q)=>$(Q,X.cap);if(C8(X))return(Q)=>{if(!Array.isArray(Q))throw new P({code:"invalid_argument",message:"expected ExportedCap[] for cap.array method"});return Q.map((Z)=>$(Z,X.cap))};if(E8(X))return(Q)=>{if(!Q||typeof Q!=="object")throw new P({code:"invalid_argument",message:"expected Record<string, ExportedCap> for cap.record method"});let Z={};for(let H of Object.keys(Q))Z[H]=$(Q[H],X.cap);return Z};return(Q)=>Q}function UQ(X,$){if(!X)return;if(P8(X)){let Q=X.cap;return(Z)=>{if(!(Z instanceof a))throw new P({code:"invalid_argument",message:"expected CapRef"});return $(Q,Z.capId)}}if(C8(X)){let Q=X.cap,Z=Q.disposal;return(H)=>{if(!Array.isArray(H))throw new P({code:"invalid_argument",message:"expected array"});let q=H.map((N)=>{if(!(N instanceof a))throw new P({code:"invalid_argument",message:"expected CapRef in array"});return $(Q,N.capId)});return OQ(q,Z),q}}if(E8(X)){let Q=X.cap;return(Z)=>{if(!Z||typeof Z!=="object")throw new P({code:"invalid_argument",message:"expected record"});let H={};for(let q of Object.keys(Z)){let N=Z[q];if(!(N instanceof a))throw new P({code:"invalid_argument",message:"expected CapRef in record"});H[q]=$(Q,N.capId)}return H}}return}function OQ(X,$){if(!$)return;X[Symbol.dispose]=()=>{for(let Q of X)Q[Symbol.dispose]?.call(Q)}}function VX(X){if(X instanceof P)return X.toStatus();if(X instanceof Error)return{code:"internal",message:X.message};return{code:"internal",message:String(X)}}function TX(X,$,Q,Z){let H=[],q=[],N=!1,D=null,_=!1,M=0;function T(){if(M+=1,M>=KQ)Z(M),M=0}function V(){if(H.length>0){let m=H.shift();return T(),{value:m,done:!1}}if(D)return null;if(N||_)return{value:void 0,done:!0};return null}function j(){let m=V();if(m)return Promise.resolve(m);if(D)return Promise.reject(D);return new Promise((Q8,V8)=>q.push({resolve:Q8,reject:V8}))}function k(){while(q.length>0){let m=q.shift(),Q8=V();if(Q8){m.resolve(Q8);continue}if(D){m.reject(D);continue}q.unshift(m);break}}function v(){if(_||N||D)return;_=!0,Q(),k()}let p={[Symbol.asyncIterator]:()=>({next:j,return:()=>{return v(),Promise.resolve({value:void 0,done:!0})},throw:(m)=>{return v(),Promise.reject(m)}}),[Symbol.dispose]:v,cancel:v};return{capId:X,stream:p,push(m){if(_||N||D)return;H.push(m),k()},end(){N=!0,k()},fail(m){D=m,k()}}}function jX(X){return new E$(X)}function xX(X,$={}){let Q=LX(),Z;return X.setReceive((H)=>{let q;try{q=Q.unpackr.unpack(H)}catch(N){$.onProtocolError?.(`unpack failed: ${N instanceof Error?N.message:String(N)}`),X.close();return}if(!FX(q)){$.onProtocolError?.("malformed frame"),X.close();return}Z?.(q)}),{send(H){let q=Q.packr.pack(H);X.send(q instanceof Uint8Array?q:new Uint8Array(q))},setReceive(H){Z=H},close(){X.close()}}}function wX(X){if("binaryType"in X)try{X.binaryType="arraybuffer"}catch{}let $,Q=(Z)=>{if(!$)return;let H=Z.data;if(H instanceof Uint8Array){$(H);return}if(H instanceof ArrayBuffer){$(new Uint8Array(H));return}if(typeof Blob<"u"&&H instanceof Blob){H.arrayBuffer().then((q)=>$?.(new Uint8Array(q)));return}};return X.addEventListener("message",Q),{send(Z){X.send(Z)},setReceive(Z){$=Z},close(){X.removeEventListener?.("message",Q),X.close?.()}}}function A8(X){let $=new ArrayBuffer(X.byteLength);return new Uint8Array($).set(X),$}async function _Q(X){return crypto.subtle.importKey("raw",A8(X),"AES-GCM",!1,["encrypt","decrypt"])}async function bX(X,$){let Q=await _Q($),Z,H=Promise.resolve(),q=Promise.resolve(),N=!1,D=()=>{if(!N)N=!0,X.close()};return X.setReceive((_)=>{if(N)return;if(_.length<13||_[0]!==1){D();return}let M=A8(_.subarray(1,13)),T=A8(_.subarray(13));q=q.then(async()=>{if(N)return;try{let V=await crypto.subtle.decrypt({name:"AES-GCM",iv:M},Q,T);Z?.(new Uint8Array(V))}catch{D()}})}),{send(_){if(N)return;let M=A8(_);H=H.then(async()=>{if(N)return;try{let T=crypto.getRandomValues(new Uint8Array(12)),V=A8(T),j=await crypto.subtle.encrypt({name:"AES-GCM",iv:V},Q,M),k=new Uint8Array(j),v=new Uint8Array(13+k.byteLength);v[0]=1,v.set(T,1),v.set(k,13),X.send(v)}catch{D()}})},setReceive(_){Z=_},close(){D()}}}class zQ{buffer=[];waiters=[];ctrl=new AbortController;cleanup;ended=!1;failure=null;constructor(X){let $=(Q)=>{if(this.ended||this.failure)return;let Z=this.waiters.shift();if(Z){Z.resolve({value:Q,done:!1});return}this.buffer.push(Q)};try{let Q=X($,this.ctrl.signal);if(typeof Q==="function")this.cleanup=Q}catch(Q){this.failure=Q}}[Symbol.asyncIterator](){return{next:async()=>{if(this.buffer.length>0)return{value:this.buffer.shift(),done:!1};if(this.failure)throw this.failure;if(this.ended)return{value:void 0,done:!0};return new Promise((X,$)=>this.waiters.push({resolve:X,reject:$}))},return:async()=>{return this.dispose(),{value:void 0,done:!0}}}}cancel(){this.dispose()}[Symbol.dispose](){this.dispose()}dispose(){if(this.ended)return;this.ended=!0,this.ctrl.abort();try{this.cleanup?.()}catch{}while(this.waiters.length>0)this.waiters.shift().resolve({value:void 0,done:!0})}}var IX=null;function n8(){if(!IX)IX=host.runtime().then((X)=>X.surface());return IX}function o(X){return n8().then(X).catch(($)=>{if(globalThis.__BUNITE_DEBUG__)console.warn("[bunite] surface call failed",$);return})}function d(X){return n8().then(X)}class j${element;onBoundsChange;observer=null;rafId=0;lastRect={x:0,y:0,width:0,height:0};dirty=!1;stopped=!1;constructor(X,$){this.element=X,this.onBoundsChange=$}start(){this.observer=new ResizeObserver(()=>this.markDirty()),this.observer.observe(this.element),this.scheduleFrame()}stop(){if(this.stopped=!0,this.observer?.disconnect(),this.observer=null,this.rafId)cancelAnimationFrame(this.rafId),this.rafId=0}markDirty(){this.dirty=!0}scheduleFrame(){if(this.stopped)return;this.rafId=requestAnimationFrame(()=>{this.flush(),this.scheduleFrame()})}flush(){let X=window.devicePixelRatio||1,$=this.element.getBoundingClientRect(),Q={x:Math.round($.x*X),y:Math.round($.y*X),width:Math.round($.width*X),height:Math.round($.height*X)};if(!this.dirty&&Q.x===this.lastRect.x&&Q.y===this.lastRect.y&&Q.width===this.lastRect.width&&Q.height===this.lastRect.height)return;this.dirty=!1,this.lastRect=Q,this.onBoundsChange(Q)}}class x$ extends HTMLElement{static observedAttributes=["src"];_surfaceId=null;_syncCtrl=null;_initPromise=null;_aborted=!1;_pendingSrc=null;_syncHidden=!1;_userHidden=!1;_layoutObserver=null;_unsubNavigate=null;_activeStreams=[];constructor(){super()}connectedCallback(){this._aborted=!1,this._syncHidden=!1,this._userHidden=!1;let X=new AbortController;this._unsubNavigate=()=>X.abort(),(async()=>{try{let $=await n8();if(X.signal.aborted)return;await this._waitForSurfaceId(X.signal);let Q=this._surfaceId;if(X.signal.aborted||Q==null)return;let Z=$.surfaceEvents({surfaceId:Q});this._activeStreams.push(Z);for await(let H of Z){if(X.signal.aborted)break;this.dispatchEvent(new CustomEvent("surface-event",{detail:H}))}}catch($){if(globalThis.__BUNITE_DEBUG__)console.warn("[bunite] surfaceEvents stream failed",$)}})(),this._waitForLayout()}async _waitForSurfaceId(X){while(this._surfaceId==null&&!X.aborted){let $=this._initPromise;if($)try{await $}catch{return}else await new Promise((Q)=>setTimeout(Q,16))}}_waitForLayout(){if(this._layoutObserver)return;let X=()=>{if(!this.isConnected||this._aborted)return!0;let $=this.getBoundingClientRect();if($.width>0&&$.height>0){if(this.getAttribute("src")||this._pendingSrc||"")this.initSurface();return!0}return!1};requestAnimationFrame(()=>{if(X())return;this._layoutObserver=new ResizeObserver(()=>{if(X())this._layoutObserver?.disconnect(),this._layoutObserver=null}),this._layoutObserver.observe(this)})}disconnectedCallback(){this._aborted=!0,this._unsubNavigate?.(),this._unsubNavigate=null;for(let X of this._activeStreams)try{X.cancel?.()}catch{}if(this._activeStreams=[],this._layoutObserver?.disconnect(),this._layoutObserver=null,this._syncCtrl?.stop(),this._syncCtrl=null,this._surfaceId!=null){let X=this._surfaceId;this._surfaceId=null,o(($)=>$.remove({surfaceId:X}))}else if(this._initPromise)this._initPromise.then((X)=>{o(($)=>$.remove({surfaceId:X.surfaceId}))}).catch(()=>{});this._initPromise=null}attributeChangedCallback(X,$,Q){if(X!=="src")return;if(this._surfaceId!=null){let Z=this._surfaceId;o((H)=>H.navigate({surfaceId:Z,url:Q||""}))}else if(this._initPromise)this._pendingSrc=Q||"";else if(this.isConnected&&!this._aborted&&Q)this._waitForLayout()}setHidden(X){this._userHidden=X,this._applySurfaceHidden()}goBack(){let X=this._surfaceId;if(X!=null)o(($)=>$.goBack({surfaceId:X}))}reload(){let X=this._surfaceId;if(X!=null)o(($)=>$.reload({surfaceId:X}))}navigate(X){this.setAttribute("src",X)}async evaluate(X){let $=this._surfaceId;if($==null)return{ok:!1,code:"not_supported",message:"surface not ready"};return d((Q)=>Q.evaluate({surfaceId:$,script:X}))}async capabilities(){let X=this._surfaceId;if(X==null)return{evaluate:!1,crossOriginEval:!1,surfaceEvents:!1,nativeInputTrusted:!1,click:!1,type:!1,press:!1,scroll:!1,mouse:!1,dialogs:!1,console:!1,screenshot:!1};return d(($)=>$.capabilities({surfaceId:X}))}async sendClick(X){let $=this._surfaceId;if($==null)return;await d((Q)=>Q.click({surfaceId:$,...X}))}async sendType(X){let $=this._surfaceId;if($==null)return;await d((Q)=>Q.type({surfaceId:$,text:X}))}async sendPress(X,$,Q){let Z=this._surfaceId;if(Z==null)return;await d((H)=>H.press({surfaceId:Z,key:X,modifiers:$,action:Q}))}async sendScroll(X){let $=this._surfaceId;if($==null)return;await d((Q)=>Q.scroll({surfaceId:$,...X}))}async sendMouse(X){let $=this._surfaceId;if($==null)return;await d((Q)=>Q.mouse({surfaceId:$,...X}))}async respondToDialog(X,$,Q){let Z=this._surfaceId;if(Z==null)return;await d((H)=>H.respondToDialog({surfaceId:Z,requestId:X,accept:$,text:Q}))}async setDialogTimeout(X){let $=this._surfaceId;if($==null)return;await d((Q)=>Q.setDialogTimeout({surfaceId:$,ms:X}))}async waitForSelector(X,$){let Q=this._surfaceId;if(Q==null)return{ok:!1,code:"runtime_error",message:"surface not ready"};return d((Z)=>Z.waitForSelector({surfaceId:Q,selector:X,timeoutMs:$}))}async waitForFunction(X,$){let Q=this._surfaceId;if(Q==null)return{ok:!1,code:"runtime_error",message:"surface not ready"};return d((Z)=>Z.waitForFunction({surfaceId:Q,expression:X,...$}))}async getConsoleBuffer(X){let $=this._surfaceId;if($==null)return[];return await d((Q)=>Q.getConsoleBuffer({surfaceId:$,clear:X?.clear}))??[]}async screenshot(X){let $=this._surfaceId;if($==null)return{ok:!1,code:"not_supported",message:"surface not ready"};return d((Q)=>Q.screenshot({surfaceId:$,...X}))}_applySurfaceHidden(){let X=this._surfaceId;if(X==null)return;let $=this._userHidden||this._syncHidden;o((Q)=>Q.setHidden({surfaceId:X,hidden:$}))}initSurface(){if(this._surfaceId!=null||this._initPromise!=null)return;let X=window.devicePixelRatio||1,$=this.getBoundingClientRect(),Q=this._pendingSrc||this.getAttribute("src")||"";this._pendingSrc=null;let Z=n8().then((H)=>H.init({src:Q,x:Math.round($.x*X),y:Math.round($.y*X),width:Math.round($.width*X),height:Math.round($.height*X),hidden:this._userHidden}));this._initPromise=Z,Z.then((H)=>{if(this._initPromise!==Z)return;if(this._aborted){o((q)=>q.remove({surfaceId:H.surfaceId}));return}if(this._surfaceId=H.surfaceId,this._userHidden)this._applySurfaceHidden();if(this._pendingSrc!=null){let q=this._pendingSrc;this._pendingSrc=null;let N=this._surfaceId;if(N!=null)o((D)=>D.navigate({surfaceId:N,url:q}))}this._syncCtrl=new j$(this,(q)=>{let N=this._surfaceId;if(N==null)return;if(q.width===0&&q.height===0){if(!this._syncHidden)this._syncHidden=!0,this._applySurfaceHidden();return}if(this._syncHidden)this._syncHidden=!1,this._applySurfaceHidden();o((_)=>_.resize({surfaceId:N,x:q.x,y:q.y,w:q.width,h:q.height}))}),this._syncCtrl.start()}).catch(()=>{}).finally(()=>{if(this._initPromise===Z)this._initPromise=null})}}if(typeof customElements<"u"){customElements.define("bunite-webview",x$);let X=()=>{o(($)=>$.bringAllVisiblesToFront())};document.addEventListener("pointerdown",X,!0),document.addEventListener("dragstart",()=>{o(($)=>$.setAllPassthrough({passthrough:!0}))},!0),document.addEventListener("dragend",()=>{o(($)=>$.setAllPassthrough({passthrough:!1})),X()},!0)}var kX=null,W8=null;function i8(){if(kX)return Promise.resolve(kX);if(W8)return W8;let X=(async()=>{let $=new WebSocket(`ws://localhost:${__buniteRpcSocketPort}/rpc?webviewId=${__buniteWebviewId}`);$.binaryType="arraybuffer",await new Promise((q,N)=>{$.addEventListener("open",()=>q(),{once:!0}),$.addEventListener("error",()=>N(Error("bunite preload ws connect failed")),{once:!0})});let Q=Uint8Array.from(atob(__buniteSecretKeyBase64),(q)=>q.charCodeAt(0)),Z=await bX(wX($),Q),H=jX({transport:xX(Z),mode:"native",origin:location.origin});return kX=H,H})();return W8=X,X.catch(()=>{if(W8===X)W8=null}),X}var r=window;r.__bunite??={};r.__buniteWebviewId=__buniteWebviewId;r.__buniteRpcSocketPort=__buniteRpcSocketPort;r.host??={};r.host.bootstrap=async(X)=>{return(await i8()).bootstrap(X)};r.host.runtime=async()=>(await i8()).runtime();r.host.releaseRef=async(X)=>{(await i8()).releaseRef(X)};r.host.getConnection=()=>i8();var k$=Symbol.for("bunite.console.buffer"),w$=200,MQ=16,AQ=50;r[k$]=[];var o8=r[k$];function WQ(X){if(typeof X==="string")return X;if(X instanceof Error)return X.stack??X.message;try{return JSON.stringify(X)}catch{return String(X)}}var U8=null,b$=0,RQ=1000;function BQ(){if(U8)return U8;if(Date.now()<b$)return Promise.reject(Error("reporting cap cooldown"));return U8=(async()=>{return(await r.host.runtime()).reporting()})(),U8.catch(()=>{U8=null,b$=Date.now()+RQ}),U8}var R8=[],B8=null;function I$(){if(B8)clearTimeout(B8),B8=null;if(R8.length===0)return;let X=R8;R8=[],BQ().then(($)=>$.reportConsoleBatch({entries:X})).catch(()=>{})}function VQ(){if(R8.length>=AQ){I$();return}if(B8)return;B8=setTimeout(I$,MQ)}function TQ(){for(let X of["log","warn","error","info","debug"]){let $=console[X].bind(console);console[X]=(...Q)=>{try{$(...Q)}catch{}try{let Z={level:X,args:Q.map(WQ),ts:Date.now()};if(o8.push(Z),o8.length>w$)o8.splice(0,o8.length-w$);R8.push(Z),VQ()}catch{}}}}TQ();
|
|
1
|
+
var gX=Symbol.for("bunite.rpc.CallDef"),fX=Symbol.for("bunite.rpc.StreamDef"),pX=Symbol.for("bunite.rpc.CapDef"),uX=Symbol.for("bunite.rpc.CapRefToken"),lX=Symbol.for("bunite.rpc.CapArrayToken"),dX=Symbol.for("bunite.rpc.CapRecordToken"),y0=Symbol.for("bunite.rpc.Schema");function t8(X){return{[uX]:!0,cap:X}}t8.array=(X)=>({[lX]:!0,cap:X});t8.record=(X)=>({[dX]:!0,cap:X});var n=t8;function C8(X){return typeof X==="object"&&X!==null&&X[uX]===!0}function E8(X){return typeof X==="object"&&X!==null&&X[lX]===!0}function j8(X){return typeof X==="object"&&X!==null&&X[dX]===!0}function x8(X){return typeof X==="object"&&X!==null&&X[gX]===!0}function w8(X){return typeof X==="object"&&X!==null&&X[fX]===!0}function z(X){return{[gX]:!0,idempotent:!!X?.idempotent,returns:X?.returns}}function G8(X){return{[fX]:!0,hint:X?.hint}}function i(X,$,Q){return{[pX]:!0,name:X,version:Q?.version!=null?String(Q.version):void 0,methods:$,disposal:Q?.disposal??void 0}}function b8(X){return typeof X==="object"&&X!==null&&X[pX]===!0}function e8(X){return typeof X==="object"&&X!==null&&X[y0]===!0}var $X;try{$X=new TextDecoder}catch(X){}var _,s,J=0;var H0=[],QX=H0,ZX=0,b={},E,J8,o=0,e=0,p,H8,l=[],C,cX={useRecords:!1,mapsAsObjects:!0};class y8{}var qX=new y8;qX.name="MessagePack 0xC1";var N8=!1,nX=2,oX,sX,iX;class X8{constructor(X){if(X){if(X.useRecords===!1&&X.mapsAsObjects===void 0)X.mapsAsObjects=!0;if(X.sequential&&X.trusted!==!1){if(X.trusted=!0,!X.structures&&X.useRecords!=!1){if(X.structures=[],!X.maxSharedStructures)X.maxSharedStructures=0}}if(X.structures)X.structures.sharedLength=X.structures.length;else if(X.getStructures)(X.structures=[]).uninitialized=!0,X.structures.sharedLength=0;if(X.int64AsNumber)X.int64AsType="number"}Object.assign(this,X)}unpack(X,$){if(_)return K0(()=>{return k8(),this?this.unpack(X,$):X8.prototype.unpack.call(cX,X,$)});if(!X.buffer&&X.constructor===ArrayBuffer)X=typeof Buffer<"u"?Buffer.from(X):new Uint8Array(X);if(typeof $==="object")s=$.end||X.length,J=$.start||0;else J=0,s=$>-1?$:X.length;ZX=0,e=0,J8=null,QX=H0,p=null,_=X;try{C=X.dataView||(X.dataView=new DataView(X.buffer,X.byteOffset,X.byteLength))}catch(Q){if(_=null,X instanceof Uint8Array)throw Q;throw Error("Source must be a Uint8Array or Buffer but was a "+(X&&typeof X=="object"?X.constructor.name:typeof X))}if(this instanceof X8){if(b=this,this.structures)return E=this.structures,I8($);else if(!E||E.length>0)E=[]}else if(b=cX,!E||E.length>0)E=[];return I8($)}unpackMultiple(X,$){let Q,Z=0;try{N8=!0;let H=X.length,q=this?this.unpack(X,H):v8.unpack(X,H);if($){if($(q,Z,J)===!1)return;while(J<H)if(Z=J,$(I8(),Z,J)===!1)return}else{Q=[q];while(J<H)Z=J,Q.push(I8());return Q}}catch(H){throw H.lastPosition=Z,H.values=Q,H}finally{N8=!1,k8()}}_mergeStructures(X,$){if(sX)X=sX.call(this,X);if(X=X||[],Object.isFrozen(X))X=X.map((Q)=>Q.slice(0));for(let Q=0,Z=X.length;Q<Z;Q++){let H=X[Q];if(H){if(H.isShared=!0,Q>=32)H.highByte=Q-32>>5}}X.sharedLength=X.length;for(let Q in $||[])if(Q>=0){let Z=X[Q],H=$[Q];if(H){if(Z)(X.restoreStructures||(X.restoreStructures=[]))[Q]=Z;X[Q]=H}}return this.structures=X}decode(X,$){return this.unpack(X,$)}}function I8(X){try{if(!b.trusted&&!N8){let Q=E.sharedLength||0;if(Q<E.length)E.length=Q}let $;if(b.randomAccessStructure&&_[J]<64&&_[J]>=32&&oX){if($=oX(_,J,s,b),_=null,!(X&&X.lazy)&&$)$=$.toJSON();J=s}else $=h();if(p)J=p.postBundlePosition,p=null;if(N8)E.restoreStructures=null;if(J==s){if(E&&E.restoreStructures)aX();if(E=null,_=null,H8)H8=null}else if(J>s)throw Error("Unexpected end of MessagePack data");else if(!N8){let Q;try{Q=JSON.stringify($,(Z,H)=>typeof H==="bigint"?`${H}n`:H).slice(0,100)}catch(Z){Q="(JSON view not available "+Z+")"}throw Error("Data read, but end of buffer not reached "+Q)}return $}catch($){if(E&&E.restoreStructures)aX();if(k8(),$ instanceof RangeError||$.message.startsWith("Unexpected end of buffer")||J>s)$.incomplete=!0;throw $}}function aX(){for(let X in E.restoreStructures)E[X]=E.restoreStructures[X];E.restoreStructures=null}function h(){let X=_[J++];if(X<160)if(X<128)if(X<64)return X;else{let $=E[X&63]||b.getStructures&&q0()[X&63];if($){if(!$.read)$.read=JX($,X&63);return $.read()}else return X}else if(X<144)if(X-=128,b.mapsAsObjects){let $={};for(let Q=0;Q<X;Q++){let Z=N0();if(Z==="__proto__")Z="__proto_";$[Z]=h()}return $}else{let $=new Map;for(let Q=0;Q<X;Q++)$.set(h(),h());return $}else{X-=144;let $=Array(X);for(let Q=0;Q<X;Q++)$[Q]=h();if(b.freezeData)return Object.freeze($);return $}else if(X<192){let $=X-160;if(e>=J)return J8.slice(J-o,(J+=$)-o);if(e==0&&s<140){let Q=$<16?NX($):J0($);if(Q!=null)return Q}return HX($)}else{let $;switch(X){case 192:return null;case 193:if(p)if($=h(),$>0)return p[1].slice(p.position1,p.position1+=$);else return p[0].slice(p.position0,p.position0-=$);return qX;case 194:return!1;case 195:return!0;case 196:if($=_[J++],$===void 0)throw Error("Unexpected end of buffer");return XX($);case 197:return $=C.getUint16(J),J+=2,XX($);case 198:return $=C.getUint32(J),J+=4,XX($);case 199:return K8(_[J++]);case 200:return $=C.getUint16(J),J+=2,K8($);case 201:return $=C.getUint32(J),J+=4,K8($);case 202:if($=C.getFloat32(J),b.useFloat32>2){let Q=S8[(_[J]&127)<<1|_[J+1]>>7];return J+=4,(Q*$+($>0?0.5:-0.5)>>0)/Q}return J+=4,$;case 203:return $=C.getFloat64(J),J+=8,$;case 204:return _[J++];case 205:return $=C.getUint16(J),J+=2,$;case 206:return $=C.getUint32(J),J+=4,$;case 207:if(b.int64AsType==="number")$=C.getUint32(J)*4294967296,$+=C.getUint32(J+4);else if(b.int64AsType==="string")$=C.getBigUint64(J).toString();else if(b.int64AsType==="auto"){if($=C.getBigUint64(J),$<=BigInt(2)<<BigInt(52))$=Number($)}else $=C.getBigUint64(J);return J+=8,$;case 208:return C.getInt8(J++);case 209:return $=C.getInt16(J),J+=2,$;case 210:return $=C.getInt32(J),J+=4,$;case 211:if(b.int64AsType==="number")$=C.getInt32(J)*4294967296,$+=C.getUint32(J+4);else if(b.int64AsType==="string")$=C.getBigInt64(J).toString();else if(b.int64AsType==="auto"){if($=C.getBigInt64(J),$>=BigInt(-2)<<BigInt(52)&&$<=BigInt(2)<<BigInt(52))$=Number($)}else $=C.getBigInt64(J);return J+=8,$;case 212:if($=_[J++],$==114)return Q0(_[J++]&63);else{let Q=l[$];if(Q)if(Q.read)return J++,Q.read(h());else if(Q.noBuffer)return J++,Q();else return Q(_.subarray(J,++J));else throw Error("Unknown extension "+$)}case 213:if($=_[J],$==114)return J++,Q0(_[J++]&63,_[J++]);else return K8(2);case 214:return K8(4);case 215:return K8(8);case 216:return K8(16);case 217:if($=_[J++],e>=J)return J8.slice(J-o,(J+=$)-o);return v0($);case 218:if($=C.getUint16(J),J+=2,e>=J)return J8.slice(J-o,(J+=$)-o);return h0($);case 219:if($=C.getUint32(J),J+=4,e>=J)return J8.slice(J-o,(J+=$)-o);return m0($);case 220:return $=C.getUint16(J),J+=2,tX($);case 221:return $=C.getUint32(J),J+=4,tX($);case 222:return $=C.getUint16(J),J+=2,eX($);case 223:return $=C.getUint32(J),J+=4,eX($);default:if(X>=224)return X-256;if(X===void 0){let Q=Error("Unexpected end of MessagePack data");throw Q.incomplete=!0,Q}throw Error("Unknown MessagePack token "+X)}}}var S0=/^[a-zA-Z_$][a-zA-Z\d_$]*$/;function JX(X,$){function Q(){if(Q.count++>nX){let H;try{H=X.read=Function("r","return function(){return "+(b.freezeData?"Object.freeze":"")+"({"+X.map((q)=>q==="__proto__"?"__proto_:r()":S0.test(q)?q+":r()":"["+JSON.stringify(q)+"]:r()").join(",")+"})}")(h)}catch(q){return nX=1/0,Q()}if(X.highByte===0)X.read=rX($,X.read);return H()}let Z={};for(let H=0,q=X.length;H<q;H++){let G=X[H];if(G==="__proto__")G="__proto_";Z[G]=h()}if(b.freezeData)return Object.freeze(Z);return Z}if(Q.count=0,X.highByte===0)return rX($,Q);return Q}var rX=(X,$)=>{return function(){let Q=_[J++];if(Q===0)return $();let Z=X<32?-(X+(Q<<5)):X+(Q<<5),H=E[Z]||q0()[Z];if(!H)throw Error("Record id is not defined for "+Z);if(!H.read)H.read=JX(H,X);return H.read()}};function q0(){let X=K0(()=>{return _=null,b.getStructures()});return E=b._mergeStructures(X,E)}var HX=_8,v0=_8,h0=_8,m0=_8;function _8(X){let $;if(X<16){if($=NX(X))return $}if(X>64&&$X)return $X.decode(_.subarray(J,J+=X));let Q=J+X,Z=[];$="";while(J<Q){let H=_[J++];if((H&128)===0)Z.push(H);else if((H&224)===192){let q=_[J++]&63,G=(H&31)<<6|q;if(G<128)Z.push(65533);else Z.push(G)}else if((H&240)===224){let q=_[J++]&63,G=_[J++]&63,D=(H&31)<<12|q<<6|G;if(D<2048||D>=55296&&D<=57343)Z.push(65533);else Z.push(D)}else if((H&248)===240){let q=_[J++]&63,G=_[J++]&63,D=_[J++]&63,O=(H&7)<<18|q<<12|G<<6|D;if(O<65536||O>1114111)Z.push(65533);else if(O>65535)O-=65536,Z.push(O>>>10&1023|55296),O=56320|O&1023,Z.push(O);else Z.push(O)}else Z.push(65533);if(Z.length>=4096)$+=f.apply(String,Z),Z.length=0}if(Z.length>0)$+=f.apply(String,Z);return $}function tX(X){let $=Array(X);for(let Q=0;Q<X;Q++)$[Q]=h();if(b.freezeData)return Object.freeze($);return $}function eX(X){if(b.mapsAsObjects){let $={};for(let Q=0;Q<X;Q++){let Z=N0();if(Z==="__proto__")Z="__proto_";$[Z]=h()}return $}else{let $=new Map;for(let Q=0;Q<X;Q++)$.set(h(),h());return $}}var f=String.fromCharCode;function J0(X){let $=J,Q=Array(X);for(let Z=0;Z<X;Z++){let H=_[J++];if((H&128)>0){J=$;return}Q[Z]=H}return f.apply(String,Q)}function NX(X){if(X<4)if(X<2)if(X===0)return"";else{let $=_[J++];if(($&128)>1){J-=1;return}return f($)}else{let $=_[J++],Q=_[J++];if(($&128)>0||(Q&128)>0){J-=2;return}if(X<3)return f($,Q);let Z=_[J++];if((Z&128)>0){J-=3;return}return f($,Q,Z)}else{let $=_[J++],Q=_[J++],Z=_[J++],H=_[J++];if(($&128)>0||(Q&128)>0||(Z&128)>0||(H&128)>0){J-=4;return}if(X<6)if(X===4)return f($,Q,Z,H);else{let q=_[J++];if((q&128)>0){J-=5;return}return f($,Q,Z,H,q)}else if(X<8){let q=_[J++],G=_[J++];if((q&128)>0||(G&128)>0){J-=6;return}if(X<7)return f($,Q,Z,H,q,G);let D=_[J++];if((D&128)>0){J-=7;return}return f($,Q,Z,H,q,G,D)}else{let q=_[J++],G=_[J++],D=_[J++],O=_[J++];if((q&128)>0||(G&128)>0||(D&128)>0||(O&128)>0){J-=8;return}if(X<10)if(X===8)return f($,Q,Z,H,q,G,D,O);else{let M=_[J++];if((M&128)>0){J-=9;return}return f($,Q,Z,H,q,G,D,O,M)}else if(X<12){let M=_[J++],T=_[J++];if((M&128)>0||(T&128)>0){J-=10;return}if(X<11)return f($,Q,Z,H,q,G,D,O,M,T);let V=_[J++];if((V&128)>0){J-=11;return}return f($,Q,Z,H,q,G,D,O,M,T,V)}else{let M=_[J++],T=_[J++],V=_[J++],j=_[J++];if((M&128)>0||(T&128)>0||(V&128)>0||(j&128)>0){J-=12;return}if(X<14)if(X===12)return f($,Q,Z,H,q,G,D,O,M,T,V,j);else{let k=_[J++];if((k&128)>0){J-=13;return}return f($,Q,Z,H,q,G,D,O,M,T,V,j,k)}else{let k=_[J++],v=_[J++];if((k&128)>0||(v&128)>0){J-=14;return}if(X<15)return f($,Q,Z,H,q,G,D,O,M,T,V,j,k,v);let u=_[J++];if((u&128)>0){J-=15;return}return f($,Q,Z,H,q,G,D,O,M,T,V,j,k,v,u)}}}}}function X0(){let X=_[J++],$;if(X<192)$=X-160;else switch(X){case 217:$=_[J++];break;case 218:$=C.getUint16(J),J+=2;break;case 219:$=C.getUint32(J),J+=4;break;default:throw Error("Expected string")}return _8($)}function XX(X){return b.copyBuffers?Uint8Array.prototype.slice.call(_,J,J+=X):_.subarray(J,J+=X)}function K8(X){let $=_[J++];if(l[$]){let Q;return l[$](_.subarray(J,Q=J+=X),(Z)=>{J=Z;try{return h()}finally{J=Q}})}else throw Error("Unknown extension type "+$)}var $0=Array(4096);function N0(){let X=_[J++];if(X>=160&&X<192){if(X=X-160,e>=J)return J8.slice(J-o,(J+=X)-o);else if(!(e==0&&s<180))return HX(X)}else return J--,G0(h());let $=(X<<5^(X>1?C.getUint16(J):X>0?_[J]:0))&4095,Q=$0[$],Z=J,H=J+X-3,q,G=0;if(Q&&Q.bytes==X){while(Z<H){if(q=C.getUint32(Z),q!=Q[G++]){Z=1879048192;break}Z+=4}H+=3;while(Z<H)if(q=_[Z++],q!=Q[G++]){Z=1879048192;break}if(Z===H)return J=Z,Q.string;H-=3,Z=J}Q=[],$0[$]=Q,Q.bytes=X;while(Z<H)q=C.getUint32(Z),Q.push(q),Z+=4;H+=3;while(Z<H)q=_[Z++],Q.push(q);let D=X<16?NX(X):J0(X);if(D!=null)return Q.string=D;return Q.string=HX(X)}function G0(X){if(typeof X==="string")return X;if(typeof X==="number"||typeof X==="boolean"||typeof X==="bigint")return X.toString();if(X==null)return X+"";if(b.allowArraysInMapKeys&&Array.isArray(X)&&X.flat().every(($)=>["string","number","boolean","bigint"].includes(typeof $)))return X.flat().toString();throw Error(`Invalid property type for record: ${typeof X}`)}var Q0=(X,$)=>{let Q=h().map(G0),Z=X;if($!==void 0)X=X<32?-(($<<5)+X):($<<5)+X,Q.highByte=$;let H=E[X];if(H&&(H.isShared||N8))(E.restoreStructures||(E.restoreStructures=[]))[X]=H;return E[X]=Q,Q.read=JX(Q,Z),Q.read()};l[0]=()=>{};l[0].noBuffer=!0;l[66]=(X)=>{let $=X.byteLength%8||8,Q=BigInt(X[0]&128?X[0]-256:X[0]);for(let Z=1;Z<$;Z++)Q<<=BigInt(8),Q+=BigInt(X[Z]);if(X.byteLength!==$){let Z=new DataView(X.buffer,X.byteOffset,X.byteLength),H=(q,G)=>{let D=G-q;if(D<=40){let V=Z.getBigUint64(q);for(let j=q+8;j<G;j+=8)V<<=BigInt(64),V|=Z.getBigUint64(j);return V}let O=q+(D>>4<<3),M=H(q,O),T=H(O,G);return M<<BigInt((G-O)*8)|T};Q=Q<<BigInt((Z.byteLength-$)*8)|H($,Z.byteLength)}return Q};var Z0={Error,EvalError,RangeError,ReferenceError,SyntaxError,TypeError,URIError,AggregateError:typeof AggregateError==="function"?AggregateError:null};l[101]=()=>{let X=h();if(!Z0[X[0]]){let $=Error(X[1],{cause:X[2]});return $.name=X[0],$}return Z0[X[0]](X[1],{cause:X[2]})};l[105]=(X)=>{if(b.structuredClone===!1)throw Error("Structured clone extension is disabled");let $=C.getUint32(J-4);if(!H8)H8=new Map;let Q=_[J],Z;if(Q>=144&&Q<160||Q==220||Q==221)Z=[];else if(Q>=128&&Q<144||Q==222||Q==223)Z=new Map;else if((Q>=199&&Q<=201||Q>=212&&Q<=216)&&_[J+1]===115)Z=new Set;else Z={};let H={target:Z};H8.set($,H);let q=h();if(!H.used)return H.target=q;else Object.assign(Z,q);if(Z instanceof Map)for(let[G,D]of q.entries())Z.set(G,D);if(Z instanceof Set)for(let G of Array.from(q))Z.add(G);return Z};l[112]=(X)=>{if(b.structuredClone===!1)throw Error("Structured clone extension is disabled");let $=C.getUint32(J-4),Q=H8.get($);return Q.used=!0,Q.target};l[115]=()=>new Set(h());var GX=["Int8","Uint8","Uint8Clamped","Int16","Uint16","Int32","Uint32","Float32","Float64","BigInt64","BigUint64"].map((X)=>X+"Array"),g0=typeof globalThis==="object"?globalThis:window;l[116]=(X)=>{let $=X[0],Q=Uint8Array.prototype.slice.call(X,1).buffer,Z=GX[$];if(!Z){if($===16)return Q;if($===17)return new DataView(Q);throw Error("Could not find typed array for code "+$)}return new g0[Z](Q)};l[120]=()=>{let X=h();return new RegExp(X[0],X[1])};var f0=[];l[98]=(X)=>{let $=(X[0]<<24)+(X[1]<<16)+(X[2]<<8)+X[3],Q=J;return J+=$-X.length,p=f0,p=[X0(),X0()],p.position0=0,p.position1=0,p.postBundlePosition=J,J=Q,h()};l[255]=(X)=>{if(X.length==4)return new Date((X[0]*16777216+(X[1]<<16)+(X[2]<<8)+X[3])*1000);else if(X.length==8)return new Date(((X[0]<<22)+(X[1]<<14)+(X[2]<<6)+(X[3]>>2))/1e6+((X[3]&3)*4294967296+X[4]*16777216+(X[5]<<16)+(X[6]<<8)+X[7])*1000);else if(X.length==12)return new Date(((X[0]<<24)+(X[1]<<16)+(X[2]<<8)+X[3])/1e6+((X[4]&128?-281474976710656:0)+X[6]*1099511627776+X[7]*4294967296+X[8]*16777216+(X[9]<<16)+(X[10]<<8)+X[11])*1000);else return new Date("invalid")};function K0(X){if(iX)iX();let $=s,Q=J,Z=ZX,H=o,q=e,G=J8,D=QX,O=H8,M=p,T=new Uint8Array(_.slice(0,s)),V=E,j=E.slice(0,E.length),k=b,v=N8,u=X();return s=$,J=Q,ZX=Z,o=H,e=q,J8=G,QX=D,H8=O,p=M,_=T,N8=v,E=V,E.splice(0,E.length,...j),b=k,C=new DataView(_.buffer,_.byteOffset,_.byteLength),u}function k8(){_=null,H8=null,E=null}function Y0(X){if(X.unpack)l[X.type]=X.unpack;else l[X.type]=X}var S8=Array(147);for(let X=0;X<256;X++)S8[X]=+("1e"+Math.floor(45.15-X*0.30103));var v8=new X8({useRecords:!1}),p0=v8.unpack,u0=v8.unpackMultiple,l0=v8.unpack;var d0=new Float32Array(1),C$=new Uint8Array(d0.buffer,0,4);var m8;try{m8=new TextEncoder}catch(X){}var g8,f8,D8=typeof Buffer<"u",h8=D8?function(X){return Buffer.allocUnsafeSlow(X)}:Uint8Array,O0=D8?Buffer:Uint8Array,D0=D8?4294967296:2144337920,K,A8,I,N=0,d,S=null,c0,n0=21760,o0=/[\u0080-\uFFFF]/,Y8=Symbol("record-id");class F8 extends X8{constructor(X){super(X);this.offset=0;let $,Q,Z,H,q,G=O0.prototype.utf8Write?function(Y,A){return K.utf8Write(Y,A,K.byteLength-A)}:m8&&m8.encodeInto?function(Y,A){return m8.encodeInto(Y,K.subarray(A)).written}:!1,D=this;if(!X)X={};let O=X&&X.sequential,M=X.structures||X.saveStructures,T=X.maxSharedStructures;if(T==null)T=M?32:0;if(T>8160)throw Error("Maximum maxSharedStructure is 8160");if(X.structuredClone&&X.moreTypes==null)this.moreTypes=!0;let V=X.maxOwnStructures;if(V==null)V=M?32:64;if(!this.structures&&X.useRecords!=!1)this.structures=[];let j=T>32||V+T>64,k=T+64,v=T+V+64;if(v>8256)throw Error("Maximum maxSharedStructure + maxOwnStructure is 8192");let u=[],g=0,Q8=0;this.pack=this.encode=function(Y,A){if(!K)K=new h8(8192),I=K.dataView||(K.dataView=new DataView(K.buffer,0,8192)),N=0;if(d=K.length-10,d-N<2048)K=new h8(K.length),I=K.dataView||(K.dataView=new DataView(K.buffer,0,K.length)),d=K.length-10,N=0;else N=N+7&2147483640;if(Q=N,A&M0)N+=A&255;if(q=D.structuredClone?new Map:null,D.bundleStrings&&typeof Y!=="string")S=[],S.size=1/0;else S=null;if(H=D.structures,H){if(H.uninitialized)H=D._mergeStructures(D.getStructures());let F=H.sharedLength||0;if(F>T)throw Error("Shared structures is larger than maximum shared structures, try increasing maxSharedStructures to "+H.sharedLength);if(!H.transitions){H.transitions=Object.create(null);for(let L=0;L<F;L++){let R=H[L];if(!R)continue;let B,W=H.transitions;for(let x=0,w=R.length;x<w;x++){let t=R[x];if(B=W[t],!B)B=W[t]=Object.create(null);W=B}W[Y8]=L+64}this.lastNamedStructuresLength=F}if(!O)H.nextId=F+64}if(Z)Z=!1;let U;try{if(D.randomAccessStructure&&Y&&typeof Y==="object")if(Y.constructor===Object)mX(Y);else if(Y.constructor!==Map&&!Array.isArray(Y)&&!f8.some((L)=>Y instanceof L))mX(Y.toJSON?Y.toJSON():Y);else y(Y);else y(Y);let F=S;if(S)L0(Q,y,0);if(q&&q.idsToInsert){let L=q.idsToInsert.sort((x,w)=>x.offset>w.offset?1:-1),R=L.length,B=-1;while(F&&R>0){let x=L[--R].offset+Q;if(x<F.stringsPosition+Q&&B===-1)B=0;if(x>F.position+Q){if(B>=0)B+=6}else{if(B>=0)I.setUint32(F.position+Q,I.getUint32(F.position+Q)+B),B=-1;F=F.previous,R++}}if(B>=0&&F)I.setUint32(F.position+Q,I.getUint32(F.position+Q)+B);if(N+=L.length*6,N>d)Z8(N);D.offset=N;let W=s0(K.subarray(Q,N),L);return q=null,W}if(D.offset=N,A&A0)return K.start=Q,K.end=N,K;return K.subarray(Q,N)}catch(F){throw U=F,F}finally{if(H){if(T8(),Z&&D.saveStructures){let F=H.sharedLength||0,L=K.subarray(Q,N),R=i0(H,D);if(!U){if(D.saveStructures(R,R.isCompatible)===!1)return D.pack(Y,A);if(D.lastNamedStructuresLength=F,K.length>1073741824)K=null;return L}}}if(K.length>1073741824)K=null;if(A&z0)N=Q}};let T8=()=>{if(Q8<10)Q8++;let Y=H.sharedLength||0;if(H.length>Y&&!O)H.length=Y;if(g>1e4){if(H.transitions=null,Q8=0,g=0,u.length>0)u=[]}else if(u.length>0&&!O){for(let A=0,U=u.length;A<U;A++)u[A][Y8]=0;u=[]}},a8=(Y)=>{var A=Y.length;if(A<16)K[N++]=144|A;else if(A<65536)K[N++]=220,K[N++]=A>>8,K[N++]=A&255;else K[N++]=221,I.setUint32(N,A),N+=4;for(let U=0;U<A;U++)y(Y[U])},y=(Y)=>{if(N>d)K=Z8(N);var A=typeof Y,U;if(A==="string"){let F=Y.length;if(S&&F>=4&&F<4096){if((S.size+=F)>n0){let W,x=(S[0]?S[0].length*3+S[1].length:0)+10;if(N+x>d)K=Z8(N+x);let w;if(S.position)w=S,K[N]=200,N+=3,K[N++]=98,W=N-Q,N+=4,L0(Q,y,0),I.setUint16(W+Q-3,N-Q-W);else K[N++]=214,K[N++]=98,W=N-Q,N+=4;S=["",""],S.previous=w,S.size=0,S.position=W}let B=o0.test(Y);S[B?0:1]+=Y,K[N++]=193,y(B?-F:F);return}let L;if(F<32)L=1;else if(F<256)L=2;else if(F<65536)L=3;else L=5;let R=F*3;if(N+R>d)K=Z8(N+R);if(F<64||!G){let B,W,x,w=N+L;for(B=0;B<F;B++)if(W=Y.charCodeAt(B),W<128)K[w++]=W;else if(W<2048)K[w++]=W>>6|192,K[w++]=W&63|128;else if((W&64512)===55296&&((x=Y.charCodeAt(B+1))&64512)===56320)W=65536+((W&1023)<<10)+(x&1023),B++,K[w++]=W>>18|240,K[w++]=W>>12&63|128,K[w++]=W>>6&63|128,K[w++]=W&63|128;else K[w++]=W>>12|224,K[w++]=W>>6&63|128,K[w++]=W&63|128;U=w-N-L}else U=G(Y,N+L);if(U<32)K[N++]=160|U;else if(U<256){if(L<2)K.copyWithin(N+2,N+1,N+1+U);K[N++]=217,K[N++]=U}else if(U<65536){if(L<3)K.copyWithin(N+3,N+2,N+2+U);K[N++]=218,K[N++]=U>>8,K[N++]=U&255}else{if(L<5)K.copyWithin(N+5,N+3,N+3+U);K[N++]=219,I.setUint32(N,U),N+=4}N+=U}else if(A==="number")if(Y>>>0===Y)if(Y<32||Y<128&&this.useRecords===!1||Y<64&&!this.randomAccessStructure)K[N++]=Y;else if(Y<256)K[N++]=204,K[N++]=Y;else if(Y<65536)K[N++]=205,K[N++]=Y>>8,K[N++]=Y&255;else K[N++]=206,I.setUint32(N,Y),N+=4;else if(Y>>0===Y)if(Y>=-32)K[N++]=256+Y;else if(Y>=-128)K[N++]=208,K[N++]=Y+256;else if(Y>=-32768)K[N++]=209,I.setInt16(N,Y),N+=2;else K[N++]=210,I.setInt32(N,Y),N+=4;else{let F;if((F=this.useFloat32)>0&&Y<4294967296&&Y>=-2147483648){K[N++]=202,I.setFloat32(N,Y);let L;if(F<4||(L=Y*S8[(K[N]&127)<<1|K[N+1]>>7])>>0===L){N+=4;return}else N--}K[N++]=203,I.setFloat64(N,Y),N+=8}else if(A==="object"||A==="function")if(!Y)K[N++]=192;else{if(q){let L=q.get(Y);if(L){if(!L.id){let R=q.idsToInsert||(q.idsToInsert=[]);L.id=R.push(L)}K[N++]=214,K[N++]=112,I.setUint32(N,L.id),N+=4;return}else q.set(Y,{offset:N-Q})}let F=Y.constructor;if(F===Object)P8(Y);else if(F===Array)a8(Y);else if(F===Map)if(this.mapAsEmptyObject)K[N++]=128;else{if(U=Y.size,U<16)K[N++]=128|U;else if(U<65536)K[N++]=222,K[N++]=U>>8,K[N++]=U&255;else K[N++]=223,I.setUint32(N,U),N+=4;for(let[L,R]of Y)y(L),y(R)}else{for(let L=0,R=g8.length;L<R;L++){let B=f8[L];if(Y instanceof B){let W=g8[L];if(W.write){if(W.type)K[N++]=212,K[N++]=W.type,K[N++]=0;let O8=W.write.call(this,Y);if(O8===Y)if(Array.isArray(Y))a8(Y);else P8(Y);else y(O8);return}let x=K,w=I,t=N;K=null;let q8;try{q8=W.pack.call(this,Y,(O8)=>{if(K=x,x=null,N+=O8,N>d)Z8(N);return{target:K,targetView:I,position:N-O8}},y)}finally{if(x)K=x,I=w,N=t,d=K.length-10}if(q8){if(q8.length+N>d)Z8(q8.length+N);N=F0(q8,K,N,W.type)}return}}if(Array.isArray(Y))a8(Y);else{if(Y.toJSON){let L=Y.toJSON();if(L!==Y)return y(L)}if(A==="function")return y(this.writeFunction&&this.writeFunction(Y));P8(Y)}}}else if(A==="boolean")K[N++]=Y?195:194;else if(A==="bigint"){if(Y<9223372036854776000&&Y>=-9223372036854776000)K[N++]=211,I.setBigInt64(N,Y);else if(Y<18446744073709552000&&Y>0)K[N++]=207,I.setBigUint64(N,Y);else if(this.largeBigIntToFloat)K[N++]=203,I.setFloat64(N,Number(Y));else if(this.largeBigIntToString)return y(Y.toString());else if(this.useBigIntExtension||this.moreTypes){let F=Y<0?BigInt(-1):BigInt(0),L;if(Y>>BigInt(65536)===F){let R=BigInt(18446744073709552000)-BigInt(1),B=[];while(!0){if(B.push(Y&R),Y>>BigInt(63)===F)break;Y>>=BigInt(64)}L=new Uint8Array(new BigUint64Array(B).buffer),L.reverse()}else{let R=Y<0,B=(R?~Y:Y).toString(16);if(B.length%2)B="0"+B;else if(parseInt(B.charAt(0),16)>=8)B="00"+B;if(D8)L=Buffer.from(B,"hex");else{L=new Uint8Array(B.length/2);for(let W=0;W<L.length;W++)L[W]=parseInt(B.slice(W*2,W*2+2),16)}if(R)for(let W=0;W<L.length;W++)L[W]=~L[W]}if(L.length+N>d)Z8(L.length+N);N=F0(L,K,N,66);return}else throw RangeError(Y+" was too large to fit in MessagePack 64-bit integer format, use useBigIntExtension, or set largeBigIntToFloat to convert to float-64, or set largeBigIntToString to convert to string");N+=8}else if(A==="undefined")if(this.encodeUndefinedAsNil)K[N++]=192;else K[N++]=212,K[N++]=0,K[N++]=0;else throw Error("Unknown type: "+A)},yX=this.variableMapSize||this.coercibleKeyAsNumber||this.skipValues?(Y)=>{let A;if(this.skipValues){A=[];for(let L in Y)if((typeof Y.hasOwnProperty!=="function"||Y.hasOwnProperty(L))&&!this.skipValues.includes(Y[L]))A.push(L)}else A=Object.keys(Y);let U=A.length;if(U<16)K[N++]=128|U;else if(U<65536)K[N++]=222,K[N++]=U>>8,K[N++]=U&255;else K[N++]=223,I.setUint32(N,U),N+=4;let F;if(this.coercibleKeyAsNumber)for(let L=0;L<U;L++){F=A[L];let R=Number(F);y(isNaN(R)?F:R),y(Y[F])}else for(let L=0;L<U;L++)y(F=A[L]),y(Y[F])}:(Y)=>{K[N++]=222;let A=N-Q;N+=2;let U=0;for(let F in Y)if(typeof Y.hasOwnProperty!=="function"||Y.hasOwnProperty(F))y(F),y(Y[F]),U++;if(U>65535)throw Error('Object is too large to serialize with fast 16-bit map size, use the "variableMapSize" option to serialize this object');K[A+++Q]=U>>8,K[A+Q]=U&255},SX=this.useRecords===!1?yX:X.progressiveRecords&&!j?(Y)=>{let A,U=H.transitions||(H.transitions=Object.create(null)),F=N++-Q,L;for(let R in Y)if(typeof Y.hasOwnProperty!=="function"||Y.hasOwnProperty(R)){if(A=U[R],A)U=A;else{let B=Object.keys(Y),W=U;U=H.transitions;let x=0;for(let w=0,t=B.length;w<t;w++){let q8=B[w];if(A=U[q8],!A)A=U[q8]=Object.create(null),x++;U=A}if(F+Q+1==N)N--,r8(U,B,x);else hX(U,B,F,x);L=!0,U=W[R]}y(Y[R])}if(!L){let R=U[Y8];if(R)K[F+Q]=R;else hX(U,Object.keys(Y),F,0)}}:(Y)=>{let A,U=H.transitions||(H.transitions=Object.create(null)),F=0;for(let R in Y)if(typeof Y.hasOwnProperty!=="function"||Y.hasOwnProperty(R)){if(A=U[R],!A)A=U[R]=Object.create(null),F++;U=A}let L=U[Y8];if(L)if(L>=96&&j)K[N++]=((L-=96)&31)+96,K[N++]=L>>5;else K[N++]=L;else r8(U,U.__keys__||Object.keys(Y),F);for(let R in Y)if(typeof Y.hasOwnProperty!=="function"||Y.hasOwnProperty(R))y(Y[R])},vX=typeof this.useRecords=="function"&&this.useRecords,P8=vX?(Y)=>{vX(Y)?SX(Y):yX(Y)}:SX,Z8=(Y)=>{let A;if(Y>16777216){if(Y-Q>D0)throw Error("Packed buffer would be larger than maximum buffer size");A=Math.min(D0,Math.round(Math.max((Y-Q)*(Y>67108864?1.25:2),4194304)/4096)*4096)}else A=(Math.max(Y-Q<<2,K.length-1)>>12)+1<<12;let U=new h8(A);if(I=U.dataView||(U.dataView=new DataView(U.buffer,0,A)),Y=Math.min(Y,K.length),K.copy)K.copy(U,0,Q,Y);else U.set(K.slice(Q,Y));return N-=Q,Q=0,d=U.length-10,K=U},r8=(Y,A,U)=>{let F=H.nextId;if(!F)F=64;if(F<k&&this.shouldShareStructure&&!this.shouldShareStructure(A)){if(F=H.nextOwnId,!(F<v))F=k;H.nextOwnId=F+1}else{if(F>=v)F=k;H.nextId=F+1}let L=A.highByte=F>=96&&j?F-96>>5:-1;if(Y[Y8]=F,Y.__keys__=A,H[F-64]=A,F<k)if(A.isShared=!0,H.sharedLength=F-63,Z=!0,L>=0)K[N++]=(F&31)+96,K[N++]=L;else K[N++]=F;else{if(L>=0)K[N++]=213,K[N++]=114,K[N++]=(F&31)+96,K[N++]=L;else K[N++]=212,K[N++]=114,K[N++]=F;if(U)g+=Q8*U;if(u.length>=V)u.shift()[Y8]=0;u.push(Y),y(A)}},hX=(Y,A,U,F)=>{let L=K,R=N,B=d,W=Q;if(K=A8,N=0,Q=0,!K)A8=K=new h8(8192);d=K.length-10,r8(Y,A,F),A8=K;let x=N;if(K=L,N=R,d=B,Q=W,x>1){let w=N+x-1;if(w>d)Z8(w);let t=U+Q;K.copyWithin(t+x,t+1,N),K.set(A8.slice(0,x),t),N=w}else K[U+Q]=A8[0]},mX=(Y)=>{let A=c0(Y,K,Q,N,H,Z8,(U,F,L)=>{if(L)return Z=!0;N=F;let R=K;if(y(U),T8(),R!==K)return{position:N,targetView:I,target:K};return N},this);if(A===0)return P8(Y);N=A}}useBuffer(X){K=X,K.dataView||(K.dataView=new DataView(K.buffer,K.byteOffset,K.byteLength)),I=K.dataView,N=0}set position(X){N=X}get position(){return N}clearSharedData(){if(this.structures)this.structures=[];if(this.typedStructs)this.typedStructs=[]}}f8=[Date,Set,Error,RegExp,ArrayBuffer,Object.getPrototypeOf(Uint8Array.prototype).constructor,DataView,y8];g8=[{pack(X,$,Q){let Z=X.getTime()/1000;if((this.useTimestamp32||X.getMilliseconds()===0)&&Z>=0&&Z<4294967296){let{target:H,targetView:q,position:G}=$(6);H[G++]=214,H[G++]=255,q.setUint32(G,Z)}else if(Z>0&&Z<4294967296){let{target:H,targetView:q,position:G}=$(10);H[G++]=215,H[G++]=255,q.setUint32(G,X.getMilliseconds()*4000000+(Z/1000/4294967296>>0)),q.setUint32(G+4,Z)}else if(isNaN(Z)){if(this.onInvalidDate)return $(0),Q(this.onInvalidDate());let{target:H,targetView:q,position:G}=$(3);H[G++]=212,H[G++]=255,H[G++]=255}else{let{target:H,targetView:q,position:G}=$(15);H[G++]=199,H[G++]=12,H[G++]=255,q.setUint32(G,X.getMilliseconds()*1e6),q.setBigInt64(G+4,BigInt(Math.floor(Z)))}}},{pack(X,$,Q){if(this.setAsEmptyObject)return $(0),Q({});let Z=Array.from(X),{target:H,position:q}=$(this.moreTypes?3:0);if(this.moreTypes)H[q++]=212,H[q++]=115,H[q++]=0;Q(Z)}},{pack(X,$,Q){let{target:Z,position:H}=$(this.moreTypes?3:0);if(this.moreTypes)Z[H++]=212,Z[H++]=101,Z[H++]=0;Q([X.name,X.message,X.cause])}},{pack(X,$,Q){let{target:Z,position:H}=$(this.moreTypes?3:0);if(this.moreTypes)Z[H++]=212,Z[H++]=120,Z[H++]=0;Q([X.source,X.flags])}},{pack(X,$){if(this.moreTypes)KX(X,16,$);else YX(D8?Buffer.from(X):new Uint8Array(X),$)}},{pack(X,$){let Q=X.constructor;if(Q!==O0&&this.moreTypes)KX(X,GX.indexOf(Q.name),$);else YX(X,$)}},{pack(X,$){if(this.moreTypes)KX(X,17,$);else YX(D8?Buffer.from(X):new Uint8Array(X),$)}},{pack(X,$){let{target:Q,position:Z}=$(1);Q[Z]=193}}];function KX(X,$,Q,Z){let H=X.byteLength;if(H+1<256){var{target:q,position:G}=Q(4+H);q[G++]=199,q[G++]=H+1}else if(H+1<65536){var{target:q,position:G}=Q(5+H);q[G++]=200,q[G++]=H+1>>8,q[G++]=H+1&255}else{var{target:q,position:G,targetView:D}=Q(7+H);q[G++]=201,D.setUint32(G,H+1),G+=4}if(q[G++]=116,q[G++]=$,!X.buffer)X=new Uint8Array(X);q.set(new Uint8Array(X.buffer,X.byteOffset,X.byteLength),G)}function YX(X,$){let Q=X.byteLength;var Z,H;if(Q<256){var{target:Z,position:H}=$(Q+2);Z[H++]=196,Z[H++]=Q}else if(Q<65536){var{target:Z,position:H}=$(Q+3);Z[H++]=197,Z[H++]=Q>>8,Z[H++]=Q&255}else{var{target:Z,position:H,targetView:q}=$(Q+5);Z[H++]=198,q.setUint32(H,Q),H+=4}Z.set(X,H)}function F0(X,$,Q,Z){let H=X.length;switch(H){case 1:$[Q++]=212;break;case 2:$[Q++]=213;break;case 4:$[Q++]=214;break;case 8:$[Q++]=215;break;case 16:$[Q++]=216;break;default:if(H<256)$[Q++]=199,$[Q++]=H;else if(H<65536)$[Q++]=200,$[Q++]=H>>8,$[Q++]=H&255;else $[Q++]=201,$[Q++]=H>>24,$[Q++]=H>>16&255,$[Q++]=H>>8&255,$[Q++]=H&255}return $[Q++]=Z,$.set(X,Q),Q+=H,Q}function s0(X,$){let Q,Z=$.length*6,H=X.length-Z;while(Q=$.pop()){let{offset:q,id:G}=Q;X.copyWithin(q+Z,q,H),Z-=6;let D=q+Z;X[D++]=214,X[D++]=105,X[D++]=G>>24,X[D++]=G>>16&255,X[D++]=G>>8&255,X[D++]=G&255,H=q}return X}function L0(X,$,Q){if(S.length>0){I.setUint32(S.position+X,N+Q-S.position-X),S.stringsPosition=N-X;let Z=S;S=null,$(Z[0]),$(Z[1])}}function DX(X){if(X.Class){if(!X.pack&&!X.write)throw Error("Extension has no pack or write function");if(X.pack&&!X.type)throw Error("Extension has no type (numeric code to identify the extension)");f8.unshift(X.Class),g8.unshift(X)}Y0(X)}function i0(X,$){return X.isCompatible=(Q)=>{let Z=!Q||($.lastNamedStructuresLength||0)===Q.length;if(!Z)$._mergeStructures(Q);return Z},X}var _0=new F8({useRecords:!1}),a0=_0.pack,r0=_0.pack;var A0=512,z0=1024,M0=2048;var R0=80;class a{capId;constructor(X){this.capId=X}}var t0=new Set(["hello","goaway","call","result","cancel","stream","drop","cap_revoked"]);function FX(X){if(typeof X!=="object"||X===null)return!1;let $=X,Q=$.op;if(typeof Q!=="string"||!t0.has(Q))return!1;switch(Q){case"hello":return $.v===1&&($.mode==="native"||$.mode==="web")&&Array.isArray($.features)&&typeof $.maxBytes==="number"&&typeof $.origin==="string";case"goaway":return $.reason===void 0||typeof $.reason==="string";case"call":return typeof $.id==="number"&&typeof $.method==="string"&&typeof $.target==="object"&&$.target!==null&&$.target.kind==="cap"&&typeof $.target.id==="number";case"result":return typeof $.id==="number"&&($.ok===!0||$.ok===!1);case"cancel":return typeof $.id==="number";case"stream":return typeof $.id==="number"&&typeof $.ev==="string"&&($.ev==="next"||$.ev==="credit"||$.ev==="end"||$.ev==="error");case"drop":return Array.isArray($.caps);case"cap_revoked":if(!Array.isArray($.capIds))return!1;for(let Z of $.capIds)if(typeof Z!=="number"||!Number.isInteger(Z)||Z<0||Z>4294967295)return!1;return!0}}var W0=!1;function e0(){if(W0)return;W0=!0,DX({Class:a,type:R0,pack:(X)=>X$(X.capId),unpack:(X)=>new a(Q$(X))})}function LX(){return e0(),{packr:new F8({useRecords:!0,sequential:!0,moreTypes:!0}),unpackr:new X8({useRecords:!0,sequential:!0,moreTypes:!0})}}function X$(X){let $=new Uint8Array(5),Q=X>>>0,Z=0;while(Q>=128)$[Z++]=Q&127|128,Q>>>=7;return $[Z++]=Q&127,$.subarray(0,Z)}var $$=5;function Q$(X){let $=0,Q=0,Z=Math.min(X.length,$$);for(let H=0;H<Z;H++){let q=X[H];if($|=(q&127)<<Q,(q&128)===0)return $>>>0;Q+=7}throw Error("Truncated or oversize varuint")}var UX=67108864,OX=1,p8="bunite.",u8="bootstrap";class P extends Error{code;details;retry;constructor(X){super(X.message??X.code);this.name="IpcError",this.code=X.code,this.details=X.details,this.retry=X.retry}toStatus(){return{code:this.code,message:this.message,details:this.details,retry:this.retry}}}var l8=i("bunite.BrowserWindow",{focus:z(),close:z(),setBounds:z(),setTitle:z(),id:z({idempotent:!0}),label:z({idempotent:!0})}),_X=i("bunite.Window",{create:z({returns:n(l8)}),list:z({returns:n.array(l8),idempotent:!0}),focus:z(),close:z()}),d8=i("bunite.FileRef",{text:z({idempotent:!0}),bytes:z({idempotent:!0}),path:z({idempotent:!0}),revoke:z()},{disposal:{method:"revoke"}}),AX=i("bunite.Dialogs",{openFile:z({returns:n.array(d8)}),saveFile:z({returns:n(d8)}),showMessage:z()}),zX=i("bunite.Clipboard",{readText:z({idempotent:!0}),writeText:z(),readBytes:z({idempotent:!0}),writeBytes:z()}),MX=i("bunite.Shell",{openExternal:z(),showItemInFolder:z()}),WX=i("bunite.PageReporting",{reportConsoleBatch:z()}),RX=i("bunite.Surface",{init:z(),resize:z(),remove:z(),setHidden:z(),setMasks:z(),setAllPassthrough:z(),bringAllVisiblesToFront:z(),navigate:z(),goBack:z(),reload:z(),evaluate:z(),capabilities:z(),click:z(),type:z(),press:z(),scroll:z(),mouse:z(),screenshot:z(),waitForSelector:z(),waitForFunction:z(),respondToDialog:z(),setDialogTimeout:z(),getConsoleBuffer:z({idempotent:!0}),surfaceEvents:G8(),dialogs:G8(),consoleEvents:G8(),getNavigationState:z({idempotent:!0}),accessibilitySnapshot:z(),getBoundingRect:z({idempotent:!0}),listFrames:z({idempotent:!0}),downloadEvents:G8(),waitForDownload:z(),setDownloadPolicy:z(),acceptPopup:z(),dismissPopup:z(),extendPopupTimeout:z(),resolveAndClick:z()}),z8=i("bunite.Runtime",{window:z({returns:n(_X),idempotent:!0}),dialogs:z({returns:n(AX),idempotent:!0}),clipboard:z({returns:n(zX),idempotent:!0}),shell:z({returns:n(MX),idempotent:!0}),appName:z({idempotent:!0}),appVersion:z({idempotent:!0}),theme:z({idempotent:!0}),themeWatch:G8(),surface:z({returns:n(RX),idempotent:!0}),reporting:z({returns:n(WX),idempotent:!0}),popupMetrics:z({idempotent:!0})}),$8={Runtime:1,Window:2,Dialogs:3,FileRef:4,Clipboard:5,Shell:6,BrowserWindow:7,Surface:8,PageReporting:9},Z$=new Map([[z8,$8.Runtime],[_X,$8.Window],[AX,$8.Dialogs],[d8,$8.FileRef],[zX,$8.Clipboard],[MX,$8.Shell],[l8,$8.BrowserWindow],[RX,$8.Surface],[WX,$8.PageReporting]]);function BX(X){return Z$.get(X)}var n8=0,PX=1,V0=0,T0=1,L8=2,CX=128,o8=1024,P0=1024,H$=o8*4,q$=500,J$=32,N$=8,G$=1024;function K$(X){let $=X?.initialBudget;if(typeof $!=="number"||!Number.isFinite($)||!Number.isInteger($)||$<1)return J$;return Math.min($,G$)}var c8=null;class EX{entries=new Map;nextCapId=L8;capLimit;constructor(X=o8){this.capLimit=X}install(X,$){if(this.entries.has(X))throw Error(`cap-id ${X} already installed`);let Q={capId:X,...$};return this.entries.set(X,Q),Q}allocate(X){if(this.entries.size>=this.capLimit)throw new P({code:"resource_exhausted",message:`cap-table limit ${this.capLimit}`,details:{reason:"max_caps_per_connection"}});let $=this.nextCapId++;while(this.entries.has($))$=this.nextCapId++;return this.install($,X)}get(X){return this.entries.get(X)}release(X,$=1){let Q=this.entries.get(X);if(!Q)return!1;if(Q.refCount=Math.max(0,Q.refCount-$),Q.refCount===0&&X>=L8)return this.entries.delete(X),!0;return!1}delete(X){if(X<L8)return!1;return this.entries.delete(X)}clear(){this.entries.clear(),this.nextCapId=L8}size(){return this.entries.size}values(){return this.entries.values()}}var Y$={origin:"",topOrigin:"",partition:"default",isAppRes:!1,isMainFrame:!1,userGesture:!1,level:"untrusted"},C0=Symbol("bunite.rpc.ExportedCap"),B0=Symbol("bunite.rpc.CapProxyMeta");function D$(X){return typeof X==="object"&&X!==null&&X[C0]===!0}var F$=typeof FinalizationRegistry<"u"?new FinalizationRegistry((X)=>{if(X.dropped())return;let $=X.connRef.deref();if(!$||$.closed)return;$._dropFromFinalizer(X.capId)}):{register:()=>{}};class E0{transport;capTable;pending=new Map;clientStreams=new Map;serverStreams=new Map;serverCallChildren=new Map;serverActiveCalls=new Map;registry=new Map;rootInstances=new Map;revokedCapIds=new Set;closeHandlers=new Set;observers={};nextCallId=1;remoteHello=null;remoteReady;resolveRemoteReady;rejectRemoteReady;closed_=!1;maxBytes;maxInFlightCalls;mode;origin;features;attestation;peerId;policy;constructor(X){this.transport=X.transport,this.mode=X.mode,this.origin=X.origin,this.features=X.features??[],this.maxBytes=X.maxBytes??UX,this.maxInFlightCalls=X.maxInFlightCalls??P0,this.attestation=X.attestation??Y$,this.peerId=X.peerId??"peer",this.policy=X.policy,this.capTable=new EX(X.capLimit??o8),this.capTable.install(n8,{typeId:V0,cap:null,impl:null,refCount:1}),this.capTable.install(PX,{typeId:T0,cap:z8,impl:X.runtime??null,refCount:1}),this.remoteReady=new Promise(($,Q)=>{this.resolveRemoteReady=$,this.rejectRemoteReady=Q}),this.remoteReady.catch(()=>{}),this.transport.setReceive(($)=>this.handleFrame($)),this.transport.send({op:"hello",v:OX,mode:this.mode,features:this.features,maxBytes:this.maxBytes,origin:this.origin})}get closed(){return this.closed_}onClose(X){return this.closeHandlers.add(X),()=>this.closeHandlers.delete(X)}on(X,$){let Q=this.observers[X];if(!Q)Q=new Set,this.observers[X]=Q;return Q.add($),()=>{Q.delete($)}}emitObs(X,$){let Q=this.observers[X];if(!Q||Q.size===0)return;for(let Z of Q)try{Z($)}catch{}}markRevoked(X){this.revokedCapIds.add(X);while(this.revokedCapIds.size>H$){let $=this.revokedCapIds.values().next().value;if($===void 0)break;this.revokedCapIds.delete($)}}serve(X,$,Q){this.assertNotFrameworkName(X.name);let Z=Q?.ifExists??"throw";if(this.registry.get(X.name))switch(Z){case"throw":throw new P({code:"already_exists",message:`cap "${X.name}" already served`,details:{reason:"name_collision"}});case"skip":return this.makeHandle([]);case"replace":return this.replace(X,$),this.makeHandle([X.name])}return this.registry.set(X.name,{cap:X,impl:$,version:X.version}),this.makeHandle([X.name])}makeHandle(X){let $={names:X,[Symbol.dispose]:()=>this.unserve($)};return $}serveAll(X,$,Q){let Z=Q?.ifExists??"throw";for(let q of Object.keys(X.roots)){let G=X.roots[q];this.assertNotFrameworkName(G.name);let D=this.registry.get(G.name);if(D){if(Z==="throw")throw new P({code:"already_exists",message:`cap "${G.name}" already served`,details:{reason:"name_collision"}});if(Z==="replace"&&D.version!==G.version)throw new P({code:"failed_precondition",message:`version mismatch on replace for "${G.name}" (current "${D.version}", new "${G.version}")`,details:{reason:"version_mismatch"}})}}let H=[];for(let q of Object.keys(X.roots)){let G=X.roots[q],D=$[q];if(this.serve(G,D,{ifExists:Z}).names.length>0)H.push(G.name)}return this.makeHandle(H)}unserve(X){let $=b8(X)?[X.name]:Array.from(X.names),Q=[];for(let Z of $){if(!this.registry.delete(Z))continue;let H=this.rootInstances.get(Z);if(H!==void 0){let q=this.capTable.get(H);if(q)this.invokeServerDisposal(q);this.rootInstances.delete(Z),this.capTable.delete(H),Q.push(H)}}if(Q.length>0)this.transport.send({op:"cap_revoked",capIds:Q}),this.emitObs("revoke",{capIds:Q,reason:"unserve"})}replace(X,$){let Q=this.registry.get(X.name);if(!Q)throw new P({code:"not_found",message:`cap "${X.name}" not served`});if(Q.version!==X.version)throw new P({code:"failed_precondition",message:`version mismatch (current "${Q.version}", new "${X.version}")`,details:{reason:"version_mismatch"}});Q.impl=$,Q.cap=X;let Z=this.rootInstances.get(X.name);if(Z!==void 0){let H=this.capTable.get(Z);if(H)H.impl=$,H.cap=X}this.emitObs("revoke",{capIds:Z!==void 0?[Z]:[],reason:"replace"})}assertNotFrameworkName(X){if(X.startsWith(p8))throw new P({code:"already_exists",message:`cap name "${X}" uses reserved prefix "${p8}"`,details:{reason:"reserved_namespace"}})}runtimeProxy=null;runtime(){if(!this.runtimeProxy)this.runtimeProxy=this.makeCapProxy(z8,PX);return this.runtimeProxy}async bootstrap(X){if(b8(X))return this._bootstrapCap(X);if(e8(X))return this._bootstrapSchema(X);throw new P({code:"invalid_argument",message:"bootstrap target must be CapDef or Schema"})}async _bootstrapCap(X){await this.remoteReady;let $={name:X.name};if(X.version!=null)$.version=X.version;let Q=await this.sendCallTyped(n8,u8,$,void 0);if(!(Q instanceof a))throw new P({code:"invalid_argument",message:"bootstrap did not return a CapRef"});return this.makeCapProxy(X,Q.capId)}async _bootstrapSchema(X){let $=Object.keys(X.roots),Q=await Promise.allSettled($.map((q)=>this._bootstrapCap(X.roots[q]))),Z=Q.find((q)=>q.status==="rejected");if(Z){for(let q of Q)if(q.status==="fulfilled")try{this.releaseRef(q.value)}catch{}throw Z.reason}let H={};for(let q=0;q<$.length;q++)H[$[q]]=Q[q].value;return H}handleFrame(X){if(this.closed_)return;switch(X.op){case"hello":this.handleHello(X);return;case"call":this.handleCall(X);return;case"result":this.handleResult(X);return;case"cancel":this.handleCancel(X);return;case"stream":this.handleStreamFrame(X);return;case"drop":this.handleDrop(X);return;case"cap_revoked":this.handleCapRevoked(X);return;case"goaway":this.handleGoaway(X);return;default:this.handleUnknownFrame(X);return}}handleUnknownFrame(X){let $=X?.id;if(typeof $==="number"){this.transport.send({op:"result",id:$,ok:!1,error:{code:"invalid_argument",message:"unknown opcode"}});return}this.transport.send({op:"goaway",reason:"invalid_argument",error:{code:"invalid_argument",message:"unknown opcode"}}),this.shutdown("invalid_argument")}handleHello(X){this.remoteHello=X,this.resolveRemoteReady(X)}handleGoaway(X){this.rejectRemoteReady(new P(X.error??{code:"unavailable",message:X.reason??"peer goaway"})),this.shutdown(X.reason??"remote goaway")}handleCapRevoked(X){for(let $ of X.capIds){this.markRevoked($);let Q=new P({code:"failed_precondition",message:"cap revoked",details:{reason:"revoked"}});for(let[Z,H]of this.pending)if(H.capId===$){if(this.pending.delete(Z),H.timer)clearTimeout(H.timer);H.reject(Q)}for(let[Z,H]of this.clientStreams)if(H.capId===$)this.clientStreams.delete(Z),H.fail(Q)}}async handleCall(X){if(X.target.id===n8&&X.method===u8){await this.handleBootstrap(X);return}let $=this.capTable.get(X.target.id);if(!$)return this.emitObs("call",{capId:X.target.id,method:X.method,callId:X.id,result:"not_found"}),this.sendError(X.id,"not_found",`cap-id ${X.target.id} not found`);let Q=$.cap;if(!Q||!$.impl)return this.emitObs("call",{capId:X.target.id,method:X.method,callId:X.id,result:"not_found"}),this.sendError(X.id,"not_found","cap has no impl");let Z=Q.methods[X.method];if(!Z)return this.emitObs("call",{capId:X.target.id,capName:Q.name,method:X.method,callId:X.id,result:"not_found"}),this.sendError(X.id,"not_found",`method "${X.method}" on cap "${Q.name}"`);let H=$.impl[X.method];if(typeof H!=="function")return this.emitObs("call",{capId:X.target.id,capName:Q.name,method:X.method,callId:X.id,result:"not_found"}),this.sendError(X.id,"not_found",`method "${X.method}" has no handler`);if(this.serverActiveCalls.size+this.serverStreams.size>=this.maxInFlightCalls)return this.emitObs("call",{capId:X.target.id,capName:Q.name,method:X.method,callId:X.id,result:"resource_exhausted"}),this.sendError(X.id,"resource_exhausted",`in-flight calls limit ${this.maxInFlightCalls}`,{reason:"max_concurrent_calls"});await this.invokeServerMethod(X,Q,Z,H)}async handleBootstrap(X){let $=X.args??{},Q=$.name;if(typeof Q!=="string")return this.emitObs("bootstrap",{name:String(Q),attestation:this.attestation,result:"invalid_argument"}),this.sendError(X.id,"invalid_argument","bootstrap requires {name: string}");let Z=$.version!=null?String($.version):void 0,H=this.registry.get(Q);if(!H)return this.emitObs("bootstrap",{name:Q,version:Z,attestation:this.attestation,result:"not_found"}),this.sendError(X.id,"not_found",`cap "${Q}" not served`);let q=H.version;if(q!=null&&Z!=null&&q!==Z)return this.emitObs("bootstrap",{name:Q,version:Z,attestation:this.attestation,result:"version_mismatch"}),this.sendError(X.id,"failed_precondition",`version mismatch (server "${q}", client "${Z}")`,{reason:"version_mismatch"});if(this.policy){let D;try{D=await this.policy(Q,this.attestation)}catch(O){return this.emitObs("error",{phase:"policy",error:O instanceof Error?O:Error(String(O))}),this.emitObs("bootstrap",{name:Q,version:Z,attestation:this.attestation,result:"internal"}),this.sendError(X.id,"internal","policy threw")}if(typeof D!=="boolean")return this.emitObs("error",{phase:"policy",error:Error(`policy must return boolean (got ${typeof D})`)}),this.emitObs("bootstrap",{name:Q,version:Z,attestation:this.attestation,result:"internal"}),this.sendError(X.id,"internal","policy returned non-boolean");if(!D)return this.emitObs("bootstrap",{name:Q,version:Z,attestation:this.attestation,result:"denied"}),this.sendError(X.id,"failed_precondition","policy denied",{reason:"unauthorized"})}let G=this.rootInstances.get(Q);if(G!==void 0){let D=this.capTable.get(G);if(D)D.refCount+=1;else this.rootInstances.delete(Q),G=void 0}if(G===void 0)try{G=this.capTable.allocate({typeId:BX(H.cap)??CX,cap:H.cap,impl:H.impl,refCount:1}).capId,this.rootInstances.set(Q,G)}catch(D){if(D instanceof P){let O=D.code==="resource_exhausted"?"resource_exhausted":"internal";return this.emitObs("bootstrap",{name:Q,version:Z,attestation:this.attestation,result:O}),this.sendError(X.id,D.code,D.message,D.details)}throw D}this.emitObs("bootstrap",{name:Q,version:Z,attestation:this.attestation,result:"ok",capId:G}),this.transport.send({op:"result",id:X.id,ok:!0,value:new a(G)})}async invokeServerMethod(X,$,Q,Z){let H=this.makeCallCtx(X);if(w8(Q)){let q=K$(Q.hint);try{let G=()=>Z(X.args,H),D=c8,M=(D?()=>D.run({callId:X.id},G):G)();this.runServerStream(X.id,M,H,q,$,X.method,X.target.id)}catch(G){this.emitObs("stream",{capId:X.target.id,capName:$.name,method:X.method,callId:X.id,event:"error"}),this.transport.send({op:"stream",id:X.id,ev:"error",error:VX(G)})}return}if(x8(Q)){let q=performance.now(),G=Q.idempotent?void 0:this.armServerDeadline(X,H);this.serverActiveCalls.set(X.id,{ctrl:H._ctrl,capId:X.target.id,capName:$.name,method:X.method,startedAt:q});let D=L$(Q.returns),O=()=>Promise.resolve(Z(X.args,H)),M=c8,T=M?()=>M.run({callId:X.id},O):O;try{let V=await T();if(G)clearTimeout(G);if(!this.serverActiveCalls.delete(X.id))return;let j=D(V);this.transport.send({op:"result",id:X.id,ok:!0,value:j}),this.emitObs("call",{capId:X.target.id,capName:$.name,method:X.method,callId:X.id,durationMs:performance.now()-q,result:"ok"})}catch(V){if(G)clearTimeout(G);if(!this.serverActiveCalls.delete(X.id))return;let j=VX(V);this.sendErrorFromStatus(X.id,j),this.emitObs("call",{capId:X.target.id,capName:$.name,method:X.method,callId:X.id,durationMs:performance.now()-q,result:j.code})}return}this.sendError(X.id,"not_found","unknown method kind")}armServerDeadline(X,$){let Q=X.meta?.deadlineMs;if(!Q)return;return setTimeout(()=>{$._ctrl.abort()},Q)}makeCallCtx(X){let $=new AbortController;return{callId:X.id,peerId:this.peerId,attestation:this.attestation,signal:$.signal,deadline:X.meta?.deadlineMs,_ctrl:$,exportCap:(Z,H)=>this.exportCap(Z,H)}}exportCap(X,$){let Q=BX(X)??CX,Z=this.capTable.allocate({typeId:Q,cap:X,impl:$,refCount:1});return{[C0]:!0,cap:X,capId:Z.capId,typeId:Z.typeId}}runServerStream(X,$,Q,Z,H,q,G){let D=$[Symbol.asyncIterator](),O=Q._ctrl,M={iter:D,abort:O,cancelled:!1,credit:Z,creditWaker:null,capId:G,capName:H.name,method:q,callId:X,count:0};this.serverStreams.set(X,M),this.emitObs("stream",{capId:G,capName:H.name,method:q,callId:X,event:"start"});let T=()=>{if(M.credit>0||M.cancelled)return Promise.resolve();return new Promise((j)=>{M.creditWaker=j})};(async()=>{let j=!1;try{while(!M.cancelled){if(M.credit===0)await T();if(M.cancelled)break;let{done:k,value:v}=await D.next();if(k)break;if(M.cancelled)break;M.credit-=1,M.count+=1,this.transport.send({op:"stream",id:X,ev:"next",value:v})}}catch(k){j=!0,this.transport.send({op:"stream",id:X,ev:"error",error:VX(k)}),this.emitObs("stream",{capId:G,capName:H.name,method:q,callId:X,event:"error",count:M.count})}finally{if(!j)this.transport.send({op:"stream",id:X,ev:"end"}),this.emitObs("stream",{capId:G,capName:H.name,method:q,callId:X,event:M.cancelled?"cancel":"end",count:M.count});this.serverStreams.delete(X)}})()}handleResult(X){let $=this.pending.get(X.id);if($){if(this.pending.delete(X.id),this.serverCallChildren.delete(X.id),$.timer)clearTimeout($.timer);if(X.ok){let Z=$.decodeReturn?$.decodeReturn(X.value):X.value;$.resolve(Z)}else $.reject(new P(X.error));return}let Q=this.clientStreams.get(X.id);if(Q){this.clientStreams.delete(X.id);let Z=X.ok?new P({code:"invalid_argument",message:"stream method returned result frame"}):new P(X.error);Q.fail(Z)}}handleCancel(X){let $=this.serverStreams.get(X.id);if($)$.cancelled=!0,$.abort.abort(),$.iter?.return?.(),this.serverStreams.delete(X.id);let Q=this.serverActiveCalls.get(X.id);if(Q)this.serverActiveCalls.delete(X.id),Q.ctrl.abort(),this.transport.send({op:"result",id:X.id,ok:!1,error:{code:"cancelled",message:X.reason}}),this.emitObs("call",{capId:Q.capId,capName:Q.capName,method:Q.method,callId:X.id,durationMs:performance.now()-Q.startedAt,result:"cancelled"});for(let[Z,H]of this.serverCallChildren){if(H.parentId!==X.id)continue;if(this.serverCallChildren.delete(Z),this.pending.has(Z))this.transport.send({op:"cancel",id:Z,reason:X.reason})}}releaseRef(X){if(typeof X!=="object"||X===null)return;let $=X[B0];if(!$||$.dropped)return;$.dropped=!0,this.sendDrop($.capId)}sendDrop(X){if(this.closed_)return;if(X<L8)return;this.transport.send({op:"drop",caps:[{id:X,delta:1}]})}handleStreamFrame(X){if(X.ev==="credit"){let Q=this.serverStreams.get(X.id);if(!Q)return;Q.credit+=X.credit?.messages??0;let Z=Q.creditWaker;Q.creditWaker=null,Z?.();return}let $=this.clientStreams.get(X.id);if(!$)return;switch(X.ev){case"next":$.push(X.value);return;case"end":$.end(),this.clientStreams.delete(X.id);return;case"error":$.fail(new P(X.error)),this.clientStreams.delete(X.id);return}}handleDrop(X){for(let{id:$,delta:Q}of X.caps)if(this.capTable.release($,Q)){for(let[H,q]of this.rootInstances)if(q===$){this.rootInstances.delete(H);break}}}sendError(X,$,Q,Z){let H={code:$,message:Q};if(Z!==void 0)H.details=Z;this.transport.send({op:"result",id:X,ok:!1,error:H})}sendErrorFromStatus(X,$){this.transport.send({op:"result",id:X,ok:!1,error:$})}nextId(){return this.nextCallId++}sendCallTyped(X,$,Q,Z,H,q){if(this.closed_)return Promise.reject(new P({code:"unavailable",message:"connection closed"}));if(this.revokedCapIds.has(X))return Promise.reject(new P({code:"failed_precondition",message:"cap revoked",details:{reason:"revoked"}}));if(this.pending.size>=this.maxInFlightCalls)return Promise.reject(new P({code:"resource_exhausted",message:`in-flight calls limit ${this.maxInFlightCalls}`,details:{reason:"max_concurrent_calls"}}));let G=this.nextId();return new Promise((D,O)=>{let M=new AbortController,T={resolve:D,reject:O,abort:M,decodeReturn:Z,startedAt:performance.now(),capId:X,method:$,capName:q,kind:"call"};if(H?.deadlineMs)T.timer=setTimeout(()=>{if(this.pending.delete(G))this.transport.send({op:"cancel",id:G,reason:"deadline_exceeded"}),O(new P({code:"deadline_exceeded"}))},H.deadlineMs+q$);this.pending.set(G,T);let V=H;if(V?.parentCallId===void 0&&c8){let j=c8.getStore();if(j)V={...V??{},parentCallId:j.callId}}if(V?.parentCallId!==void 0)this.serverCallChildren.set(G,{parentId:V.parentCallId});this.transport.send({op:"call",id:G,target:{kind:"cap",id:X},method:$,args:Q,meta:V})})}openClientStream(X,$,Q,Z,H){if(this.closed_){let M=TX(X,0,()=>{},()=>{});return M.fail(new P({code:"unavailable",message:"connection closed"})),M.stream}if(this.revokedCapIds.has(X)){let M=TX(X,0,()=>{},()=>{});return M.fail(new P({code:"failed_precondition",message:"cap revoked",details:{reason:"revoked"}})),M.stream}let q=this.nextId(),O=TX(X,q,()=>{if(this.clientStreams.delete(q))this.transport.send({op:"cancel",id:q,reason:"client_cancel"})},(M)=>{if(this.closed_||!this.clientStreams.has(q))return;this.transport.send({op:"stream",id:q,ev:"credit",credit:{messages:M}})});return this.clientStreams.set(q,O),this.transport.send({op:"call",id:q,target:{kind:"cap",id:X},method:$,args:Q,meta:Z}),O.stream}makeCapProxy(X,$){let Q={},Z={capId:$,dropped:!1};Q[B0]=Z;let H=()=>{if(Z.dropped)return;Z.dropped=!0,this.sendDrop($)};for(let G of Object.keys(X.methods)){let D=X.methods[G];if(w8(D))Q[G]=(O)=>this.openClientStream($,G,O,void 0,X.name);else if(x8(D)){let O=U$(D.returns,(M,T)=>this.makeCapProxy(M,T));Q[G]=(M)=>this.sendCallTyped($,G,M,O,void 0,X.name)}}let q=X.disposal;if(q){let G=this;Q[Symbol.dispose]=()=>{try{let D=Q[q.method]?.();if(D&&typeof D.then==="function")D.catch((O)=>G.emitObs("error",{phase:"dispose",error:O instanceof Error?O:Error(String(O))}))}catch(D){G.emitObs("error",{phase:"dispose",error:D instanceof Error?D:Error(String(D))})}H()}}if(typeof FinalizationRegistry<"u")F$.register(Q,{connRef:new WeakRef(this),capId:$,dropped:()=>Z.dropped});return Q}_dropFromFinalizer(X){try{this.sendDrop(X)}catch{}}shutdown(X="shutdown"){if(this.closed_)return;this.closed_=!0;for(let $ of this.pending.values()){if($.timer)clearTimeout($.timer);$.reject(new P({code:"unavailable",message:X}))}this.pending.clear();for(let $ of this.clientStreams.values())$.fail(new P({code:"unavailable",message:X}));this.clientStreams.clear();for(let $ of this.serverStreams.values())$.cancelled=!0,$.abort.abort(),$.iter?.return?.();this.serverStreams.clear();for(let $ of this.serverActiveCalls.values())$.ctrl.abort();this.serverActiveCalls.clear();for(let $ of this.capTable.values())this.invokeServerDisposal($);if(this.capTable.clear(),!this.remoteHello)this.rejectRemoteReady(new P({code:"unavailable",message:X}));for(let $ of this.closeHandlers)try{$()}catch{}this.closeHandlers.clear();try{this.transport.close()}catch{}}invokeServerDisposal(X){let $=X.cap;if(!$)return;let Q=$.disposal;if(!Q)return;let Z=X.impl,H=Z?.[Q.method];if(!H)return;try{H.call(Z,void 0,void 0)}catch{}}}function L$(X){if(!X)return(Q)=>Q;let $=(Q,Z)=>{if(!D$(Q))throw new P({code:"failed_precondition",message:"expected ctx.exportCap return for cap method",details:{reason:"unregistered_cap_return"}});if(Q.cap!==Z)throw new P({code:"failed_precondition",message:"exported cap type mismatch with method returns",details:{reason:"unregistered_cap_return"}});return new a(Q.capId)};if(C8(X))return(Q)=>$(Q,X.cap);if(E8(X))return(Q)=>{if(!Array.isArray(Q))throw new P({code:"invalid_argument",message:"expected ExportedCap[] for cap.array method"});return Q.map((Z)=>$(Z,X.cap))};if(j8(X))return(Q)=>{if(!Q||typeof Q!=="object")throw new P({code:"invalid_argument",message:"expected Record<string, ExportedCap> for cap.record method"});let Z={};for(let H of Object.keys(Q))Z[H]=$(Q[H],X.cap);return Z};return(Q)=>Q}function U$(X,$){if(!X)return;if(C8(X)){let Q=X.cap;return(Z)=>{if(!(Z instanceof a))throw new P({code:"invalid_argument",message:"expected CapRef"});return $(Q,Z.capId)}}if(E8(X)){let Q=X.cap,Z=Q.disposal;return(H)=>{if(!Array.isArray(H))throw new P({code:"invalid_argument",message:"expected array"});let q=H.map((G)=>{if(!(G instanceof a))throw new P({code:"invalid_argument",message:"expected CapRef in array"});return $(Q,G.capId)});return O$(q,Z),q}}if(j8(X)){let Q=X.cap;return(Z)=>{if(!Z||typeof Z!=="object")throw new P({code:"invalid_argument",message:"expected record"});let H={};for(let q of Object.keys(Z)){let G=Z[q];if(!(G instanceof a))throw new P({code:"invalid_argument",message:"expected CapRef in record"});H[q]=$(Q,G.capId)}return H}}return}function O$(X,$){if(!$)return;X[Symbol.dispose]=()=>{for(let Q of X)Q[Symbol.dispose]?.call(Q)}}function VX(X){if(X instanceof P)return X.toStatus();if(X instanceof Error)return{code:"internal",message:X.message};return{code:"internal",message:String(X)}}function TX(X,$,Q,Z){let H=[],q=[],G=!1,D=null,O=!1,M=0;function T(){if(M+=1,M>=N$)Z(M),M=0}function V(){if(H.length>0){let g=H.shift();return T(),{value:g,done:!1}}if(D)return null;if(G||O)return{value:void 0,done:!0};return null}function j(){let g=V();if(g)return Promise.resolve(g);if(D)return Promise.reject(D);return new Promise((Q8,T8)=>q.push({resolve:Q8,reject:T8}))}function k(){while(q.length>0){let g=q.shift(),Q8=V();if(Q8){g.resolve(Q8);continue}if(D){g.reject(D);continue}q.unshift(g);break}}function v(){if(O||G||D)return;O=!0,Q(),k()}let u={[Symbol.asyncIterator]:()=>({next:j,return:()=>{return v(),Promise.resolve({value:void 0,done:!0})},throw:(g)=>{return v(),Promise.reject(g)}}),[Symbol.dispose]:v,cancel:v};return{capId:X,stream:u,push(g){if(O||G||D)return;H.push(g),k()},end(){G=!0,k()},fail(g){D=g,k()}}}function jX(X){return new E0(X)}function xX(X,$={}){let Q=LX(),Z;return X.setReceive((H)=>{let q;try{q=Q.unpackr.unpack(H)}catch(G){$.onProtocolError?.(`unpack failed: ${G instanceof Error?G.message:String(G)}`),X.close();return}if(!FX(q)){$.onProtocolError?.("malformed frame"),X.close();return}Z?.(q)}),{send(H){let q=Q.packr.pack(H);X.send(q instanceof Uint8Array?q:new Uint8Array(q))},setReceive(H){Z=H},close(){X.close()}}}function wX(X){if("binaryType"in X)try{X.binaryType="arraybuffer"}catch{}let $,Q=(Z)=>{if(!$)return;let H=Z.data;if(H instanceof Uint8Array){$(H);return}if(H instanceof ArrayBuffer){$(new Uint8Array(H));return}if(typeof Blob<"u"&&H instanceof Blob){H.arrayBuffer().then((q)=>$?.(new Uint8Array(q)));return}};return X.addEventListener("message",Q),{send(Z){X.send(Z)},setReceive(Z){$=Z},close(){X.removeEventListener?.("message",Q),X.close?.()}}}function M8(X){let $=new ArrayBuffer(X.byteLength);return new Uint8Array($).set(X),$}async function _$(X){return crypto.subtle.importKey("raw",M8(X),"AES-GCM",!1,["encrypt","decrypt"])}async function bX(X,$){let Q=await _$($),Z,H=Promise.resolve(),q=Promise.resolve(),G=!1,D=()=>{if(!G)G=!0,X.close()};return X.setReceive((O)=>{if(G)return;if(O.length<13||O[0]!==1){D();return}let M=M8(O.subarray(1,13)),T=M8(O.subarray(13));q=q.then(async()=>{if(G)return;try{let V=await crypto.subtle.decrypt({name:"AES-GCM",iv:M},Q,T);Z?.(new Uint8Array(V))}catch{D()}})}),{send(O){if(G)return;let M=M8(O);H=H.then(async()=>{if(G)return;try{let T=crypto.getRandomValues(new Uint8Array(12)),V=M8(T),j=await crypto.subtle.encrypt({name:"AES-GCM",iv:V},Q,M),k=new Uint8Array(j),v=new Uint8Array(13+k.byteLength);v[0]=1,v.set(T,1),v.set(k,13),X.send(v)}catch{D()}})},setReceive(O){Z=O},close(){D()}}}class A${buffer=[];waiters=[];ctrl=new AbortController;cleanup;ended=!1;failure=null;constructor(X){let $=(Q)=>{if(this.ended||this.failure)return;let Z=this.waiters.shift();if(Z){Z.resolve({value:Q,done:!1});return}this.buffer.push(Q)};try{let Q=X($,this.ctrl.signal);if(typeof Q==="function")this.cleanup=Q}catch(Q){this.failure=Q}}[Symbol.asyncIterator](){return{next:async()=>{if(this.buffer.length>0)return{value:this.buffer.shift(),done:!1};if(this.failure)throw this.failure;if(this.ended)return{value:void 0,done:!0};return new Promise((X,$)=>this.waiters.push({resolve:X,reject:$}))},return:async()=>{return this.dispose(),{value:void 0,done:!0}}}}cancel(){this.dispose()}[Symbol.dispose](){this.dispose()}dispose(){if(this.ended)return;this.ended=!0,this.ctrl.abort();try{this.cleanup?.()}catch{}while(this.waiters.length>0)this.waiters.shift().resolve({value:void 0,done:!0})}}var IX=null;function W8(){if(!IX)IX=host.runtime().then((X)=>X.surface());return IX}function c(X){return W8().then(X).catch(($)=>{if(globalThis.__BUNITE_DEBUG__)console.warn("[bunite] surface call failed",$);return})}function m(X){return W8().then(X)}class j0{element;onBoundsChange;observer=null;rafId=0;lastRect={x:0,y:0,width:0,height:0};dirty=!1;stopped=!1;constructor(X,$){this.element=X,this.onBoundsChange=$}start(){this.observer=new ResizeObserver(()=>this.markDirty()),this.observer.observe(this.element),this.scheduleFrame()}stop(){if(this.stopped=!0,this.observer?.disconnect(),this.observer=null,this.rafId)cancelAnimationFrame(this.rafId),this.rafId=0}markDirty(){this.dirty=!0}scheduleFrame(){if(this.stopped)return;this.rafId=requestAnimationFrame(()=>{this.flush(),this.scheduleFrame()})}flush(){let X=window.devicePixelRatio||1,$=this.element.getBoundingClientRect(),Q={x:Math.round($.x*X),y:Math.round($.y*X),width:Math.round($.width*X),height:Math.round($.height*X)};if(!this.dirty&&Q.x===this.lastRect.x&&Q.y===this.lastRect.y&&Q.width===this.lastRect.width&&Q.height===this.lastRect.height)return;this.dirty=!1,this.lastRect=Q,this.onBoundsChange(Q)}}class x0 extends HTMLElement{static observedAttributes=["src"];_surfaceId=null;_syncCtrl=null;_initPromise=null;_aborted=!1;_pendingSrc=null;_syncHidden=!1;_userHidden=!1;_layoutObserver=null;_unsubNavigate=null;_activeStreams=[];constructor(){super()}connectedCallback(){this._aborted=!1,this._syncHidden=!1,this._userHidden=!1;let X=new AbortController;this._unsubNavigate=()=>X.abort(),(async()=>{try{let $=await W8();if(X.signal.aborted)return;await this._waitForSurfaceId(X.signal);let Q=this._surfaceId;if(X.signal.aborted||Q==null)return;let Z=$.surfaceEvents({surfaceId:Q});this._activeStreams.push(Z);let H=$.downloadEvents({surfaceId:Q});this._activeStreams.push(H),(async()=>{try{for await(let q of H){if(X.signal.aborted)break;this.dispatchEvent(new CustomEvent("download-event",{detail:q}))}}catch{}})();for await(let q of Z){if(X.signal.aborted)break;this.dispatchEvent(new CustomEvent("surface-event",{detail:q}))}}catch($){if(globalThis.__BUNITE_DEBUG__)console.warn("[bunite] surfaceEvents stream failed",$)}})(),this._waitForLayout()}async _waitForSurfaceId(X){while(this._surfaceId==null&&!X.aborted){let $=this._initPromise;if($)try{await $}catch{return}else await new Promise((Q)=>setTimeout(Q,16))}}_waitForLayout(){if(this._layoutObserver)return;let X=()=>{if(!this.isConnected||this._aborted)return!0;let $=this.getBoundingClientRect();if($.width>0&&$.height>0){if(this.getAttribute("src")||this._pendingSrc||"")this.initSurface();return!0}return!1};requestAnimationFrame(()=>{if(X())return;this._layoutObserver=new ResizeObserver(()=>{if(X())this._layoutObserver?.disconnect(),this._layoutObserver=null}),this._layoutObserver.observe(this)})}disconnectedCallback(){this._aborted=!0,this._unsubNavigate?.(),this._unsubNavigate=null;for(let X of this._activeStreams)try{X.cancel?.()}catch{}if(this._activeStreams=[],this._layoutObserver?.disconnect(),this._layoutObserver=null,this._syncCtrl?.stop(),this._syncCtrl=null,this._surfaceId!=null){let X=this._surfaceId;this._surfaceId=null,c(($)=>$.remove({surfaceId:X}))}else if(this._initPromise)this._initPromise.then((X)=>{c(($)=>$.remove({surfaceId:X.surfaceId}))}).catch(()=>{});this._initPromise=null}attributeChangedCallback(X,$,Q){if(X!=="src")return;if(this._surfaceId!=null){let Z=this._surfaceId;c((H)=>H.navigate({surfaceId:Z,url:Q||""}))}else if(this._initPromise)this._pendingSrc=Q||"";else if(this.isConnected&&!this._aborted&&Q)this._waitForLayout()}setHidden(X){this._userHidden=X,this._applySurfaceHidden()}goBack(){let X=this._surfaceId;if(X!=null)c(($)=>$.goBack({surfaceId:X}))}reload(){let X=this._surfaceId;if(X!=null)c(($)=>$.reload({surfaceId:X}))}navigate(X){this.setAttribute("src",X)}async evaluate(X,$){let Q=this._surfaceId;if(Q==null)return{ok:!1,code:"not_supported",message:"surface not ready"};return m((Z)=>Z.evaluate({surfaceId:Q,script:X,frameId:$?.frameId}))}async capabilities(){let X=this._surfaceId;if(X==null)return{evaluate:!1,crossOriginEval:!1,surfaceEvents:!1,nativeInputTrusted:!1,click:!1,type:!1,press:!1,scroll:!1,mouse:!1,dialogs:!1,console:!1,screenshot:!1,accessibilitySnapshot:!1,getBoundingRect:!1,frames:!1,downloads:!1,popups:!1,resolveAndClick:!1};return m(($)=>$.capabilities({surfaceId:X}))}async sendClick(X){let $=this._surfaceId;if($==null)return;await m((Q)=>Q.click({surfaceId:$,...X}))}async sendType(X){let $=this._surfaceId;if($==null)return;await m((Q)=>Q.type({surfaceId:$,text:X}))}async sendPress(X,$,Q){let Z=this._surfaceId;if(Z==null)return;await m((H)=>H.press({surfaceId:Z,key:X,modifiers:$,action:Q}))}async sendScroll(X){let $=this._surfaceId;if($==null)return;await m((Q)=>Q.scroll({surfaceId:$,...X}))}async sendMouse(X){let $=this._surfaceId;if($==null)return;await m((Q)=>Q.mouse({surfaceId:$,...X}))}async respondToDialog(X,$,Q){let Z=this._surfaceId;if(Z==null)return;await m((H)=>H.respondToDialog({surfaceId:Z,requestId:X,accept:$,text:Q}))}async setDialogTimeout(X){let $=this._surfaceId;if($==null)return;await m((Q)=>Q.setDialogTimeout({surfaceId:$,ms:X}))}async waitForSelector(X,$){let Q=this._surfaceId;if(Q==null)return{ok:!1,code:"runtime_error",message:"surface not ready"};return m((Z)=>Z.waitForSelector({surfaceId:Q,selector:X,timeoutMs:$}))}async waitForFunction(X,$){let Q=this._surfaceId;if(Q==null)return{ok:!1,code:"runtime_error",message:"surface not ready"};return m((Z)=>Z.waitForFunction({surfaceId:Q,expression:X,...$}))}async getConsoleBuffer(X){let $=this._surfaceId;if($==null)return[];return await m((Q)=>Q.getConsoleBuffer({surfaceId:$,clear:X?.clear}))??[]}async getNavigationState(){let X=this._surfaceId;if(X==null)return{lastLoadEpoch:0,isLoading:!1,currentUrl:""};return m(($)=>$.getNavigationState({surfaceId:X}))}async accessibilitySnapshot(X){let $=this._surfaceId;if($==null)return{ok:!1,code:"not_supported",message:"surface not ready"};return m((Q)=>Q.accessibilitySnapshot({surfaceId:$,interestingOnly:X?.interestingOnly}))}async getBoundingRect(X,$){let Q=this._surfaceId;if(Q==null)return{ok:!1,code:"runtime_error",message:"surface not ready"};return m((Z)=>Z.getBoundingRect({surfaceId:Q,selector:X,frameId:$?.frameId}))}async listFrames(){let X=this._surfaceId;if(X==null)return{ok:!1,code:"not_supported",message:"surface not ready"};return m(($)=>$.listFrames({surfaceId:X}))}async resolveAndClick(X,$){let Q=this._surfaceId;if(Q==null)return{ok:!1,code:"runtime_error",message:"surface not ready"};return m((Z)=>Z.resolveAndClick({surfaceId:Q,selector:X,...$}))}async setDownloadPolicy(X,$){let Q=this._surfaceId;if(Q==null)return;await c((Z)=>Z.setDownloadPolicy({surfaceId:Q,policy:X,downloadDir:$}))}async waitForDownload(X){let $=this._surfaceId;if($==null)return{ok:!1,code:"not_supported",message:"surface not ready"};return m((Q)=>Q.waitForDownload({surfaceId:$,timeoutMs:X?.timeoutMs}))}async dismissPopup(X){await c(($)=>$.dismissPopup({newSurfaceId:X}))}async extendAdoptionTimeout(X,$){return m((Q)=>Q.extendPopupTimeout({newSurfaceId:X,gracePeriodMs:$}))}async screenshot(X){let $=this._surfaceId;if($==null)return{ok:!1,code:"not_supported",message:"surface not ready"};return m((Q)=>Q.screenshot({surfaceId:$,...X}))}_applySurfaceHidden(){let X=this._surfaceId;if(X==null)return;let $=this._userHidden||this._syncHidden;c((Q)=>Q.setHidden({surfaceId:X,hidden:$}))}_setupSyncCtrl(){this._syncCtrl=new j0(this,(X)=>{let $=this._surfaceId;if($==null)return;if(X.width===0&&X.height===0){if(!this._syncHidden)this._syncHidden=!0,this._applySurfaceHidden();return}if(this._syncHidden)this._syncHidden=!1,this._applySurfaceHidden();c((Z)=>Z.resize({surfaceId:$,x:X.x,y:X.y,w:X.width,h:X.height}))}),this._syncCtrl.start()}initSurface(){if(this._surfaceId!=null||this._initPromise!=null)return;let X=window.devicePixelRatio||1,$=this.getBoundingClientRect(),Q=this.getAttribute("adopt-popup-id"),Z=Q?Number(Q):NaN;if(Number.isFinite(Z)){let G=W8().then(async(D)=>{let O=await D.acceptPopup({newSurfaceId:Z,hostViewId:__buniteWebviewId,bounds:{x:Math.round($.x*X),y:Math.round($.y*X),width:Math.round($.width*X),height:Math.round($.height*X)}});if(!O.ok)throw Error(`acceptPopup failed: ${O.code}: ${O.message}`);return{surfaceId:Z}});this._initPromise=G,G.then((D)=>{if(this._initPromise!==G)return;if(this._aborted){c((O)=>O.remove({surfaceId:D.surfaceId}));return}this._surfaceId=D.surfaceId,this._setupSyncCtrl()}).catch((D)=>{if(globalThis.__BUNITE_DEBUG__)console.warn("[bunite] adopt-popup-id init failed",D);this._initPromise=null});return}let H=this._pendingSrc||this.getAttribute("src")||"";this._pendingSrc=null;let q=W8().then((G)=>G.init({src:H,x:Math.round($.x*X),y:Math.round($.y*X),width:Math.round($.width*X),height:Math.round($.height*X),hidden:this._userHidden}));this._initPromise=q,q.then((G)=>{if(this._initPromise!==q)return;if(this._aborted){c((D)=>D.remove({surfaceId:G.surfaceId}));return}if(this._surfaceId=G.surfaceId,this._userHidden)this._applySurfaceHidden();if(this._pendingSrc!=null){let D=this._pendingSrc;this._pendingSrc=null;let O=this._surfaceId;if(O!=null)c((M)=>M.navigate({surfaceId:O,url:D}))}this._setupSyncCtrl()}).catch(()=>{}).finally(()=>{if(this._initPromise===q)this._initPromise=null})}}if(typeof customElements<"u"){customElements.define("bunite-webview",x0);let X=()=>{c(($)=>$.bringAllVisiblesToFront())};document.addEventListener("pointerdown",X,!0),document.addEventListener("dragstart",()=>{c(($)=>$.setAllPassthrough({passthrough:!0}))},!0),document.addEventListener("dragend",()=>{c(($)=>$.setAllPassthrough({passthrough:!1})),X()},!0)}var kX=null,R8=null;function i8(){if(kX)return Promise.resolve(kX);if(R8)return R8;let X=(async()=>{let $=new WebSocket(`ws://localhost:${__buniteRpcSocketPort}/rpc?webviewId=${__buniteWebviewId}`);$.binaryType="arraybuffer",await new Promise((q,G)=>{$.addEventListener("open",()=>q(),{once:!0}),$.addEventListener("error",()=>G(Error("bunite preload ws connect failed")),{once:!0})});let Q=Uint8Array.from(atob(__buniteSecretKeyBase64),(q)=>q.charCodeAt(0)),Z=await bX(wX($),Q),H=jX({transport:xX(Z),mode:"native",origin:location.origin});return kX=H,H})();return R8=X,X.catch(()=>{if(R8===X)R8=null}),X}var r=window;r.__bunite??={};r.__buniteWebviewId=__buniteWebviewId;r.__buniteRpcSocketPort=__buniteRpcSocketPort;r.host??={};r.host.bootstrap=async(X)=>{return(await i8()).bootstrap(X)};r.host.runtime=async()=>(await i8()).runtime();r.host.releaseRef=async(X)=>{(await i8()).releaseRef(X)};r.host.getConnection=()=>i8();var k0=Symbol.for("bunite.console.buffer"),w0=200,z$=16,M$=50;r[k0]=[];var s8=r[k0];function W$(X){if(typeof X==="string")return X;if(X instanceof Error)return X.stack??X.message;try{return JSON.stringify(X)}catch{return String(X)}}var U8=null,b0=0,R$=1000;function B$(){if(U8)return U8;if(Date.now()<b0)return Promise.reject(Error("reporting cap cooldown"));return U8=(async()=>{return(await r.host.runtime()).reporting()})(),U8.catch(()=>{U8=null,b0=Date.now()+R$}),U8}var B8=[],V8=null;function I0(){if(V8)clearTimeout(V8),V8=null;if(B8.length===0)return;let X=B8;B8=[],B$().then(($)=>$.reportConsoleBatch({entries:X})).catch(()=>{})}function V$(){if(B8.length>=M$){I0();return}if(V8)return;V8=setTimeout(I0,z$)}function T$(){for(let X of["log","warn","error","info","debug"]){let $=console[X].bind(console);console[X]=(...Q)=>{try{$(...Q)}catch{}try{let Z={level:X,args:Q.map(W$),ts:Date.now()};if(s8.push(Z),s8.length>w0)s8.splice(0,s8.length-w0);B8.push(Z),V$()}catch{}}}}T$();
|
package/src/rpc/framework.ts
CHANGED
|
@@ -82,9 +82,9 @@ export const PageReportingCap = defineCap("bunite.PageReporting", {
|
|
|
82
82
|
|
|
83
83
|
export type SurfaceMask = { x: number; y: number; w: number; h: number };
|
|
84
84
|
|
|
85
|
-
/** Automation feature flags reported per surface.
|
|
86
|
-
*
|
|
87
|
-
*
|
|
85
|
+
/** Automation feature flags reported per surface. Two categories: method
|
|
86
|
+
* gate (false → must not call) and property advertise (false → method runs,
|
|
87
|
+
* property degrades; per-field JSDoc below). See `.agents/architecture.md`. */
|
|
88
88
|
export interface SurfaceCapabilities {
|
|
89
89
|
evaluate: boolean;
|
|
90
90
|
crossOriginEval: boolean;
|
|
@@ -110,19 +110,142 @@ export interface SurfaceCapabilities {
|
|
|
110
110
|
screenshot: boolean;
|
|
111
111
|
/** Present only when `screenshot` is true. */
|
|
112
112
|
formats?: ("png" | "jpeg")[];
|
|
113
|
+
accessibilitySnapshot: boolean;
|
|
114
|
+
getBoundingRect: boolean;
|
|
115
|
+
/** `listFrames` works + `evaluate({frameId})` reaches the target frame's
|
|
116
|
+
* isolated world. Frame-targeted input dispatch is not yet implemented. */
|
|
117
|
+
frames: boolean;
|
|
118
|
+
/** Backend can intercept downloads and emit lifecycle events. When `false`,
|
|
119
|
+
* every download attempt emits `{kind: "blocked", reason: "not_supported"}`. */
|
|
120
|
+
downloads: boolean;
|
|
121
|
+
/** Backend can intercept popups (window.open / target=_blank / cmd-click) and
|
|
122
|
+
* mint a new surface with the opener relationship preserved. Host adopts via
|
|
123
|
+
* `acceptPopup({newSurfaceId, hostViewId, bounds})`. */
|
|
124
|
+
popups: boolean;
|
|
125
|
+
/** Atomic `resolveAndClick(selector)`. Click trust is per-call (see `ResolveAndClickResult`). */
|
|
126
|
+
resolveAndClick: boolean;
|
|
113
127
|
}
|
|
114
128
|
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
129
|
+
export interface AxNode {
|
|
130
|
+
nodeId: string;
|
|
131
|
+
role: string;
|
|
132
|
+
name: string;
|
|
133
|
+
value?: string;
|
|
134
|
+
description?: string;
|
|
135
|
+
level?: number;
|
|
136
|
+
checked?: boolean | "mixed";
|
|
137
|
+
pressed?: boolean | "mixed";
|
|
138
|
+
expanded?: boolean;
|
|
139
|
+
disabled?: boolean;
|
|
140
|
+
focused?: boolean;
|
|
141
|
+
invalid?: boolean;
|
|
142
|
+
required?: boolean;
|
|
143
|
+
selected?: boolean;
|
|
144
|
+
children?: AxNode[];
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
export interface AccessibilitySnapshotArgs {
|
|
148
|
+
surfaceId: number;
|
|
149
|
+
/** Drop nodes with `ignored:true` (and reparent their children). Default true. */
|
|
150
|
+
interestingOnly?: boolean;
|
|
151
|
+
}
|
|
152
|
+
export type AccessibilitySnapshotResult =
|
|
153
|
+
| { ok: true; tree: AxNode }
|
|
154
|
+
| { ok: false; code: "not_supported" | "runtime_error" | "timeout"; message: string };
|
|
155
|
+
|
|
156
|
+
export interface BoundingRectArgs {
|
|
157
|
+
surfaceId: number;
|
|
158
|
+
selector: string;
|
|
159
|
+
/** When set, `rect` is FRAME-LOCAL (the iframe's own viewport). Use frame-local
|
|
160
|
+
* coords for further `evaluate({frameId})` ops; do not pass to `click({x,y})`
|
|
161
|
+
* which expects page-viewport coords. */
|
|
162
|
+
frameId?: string;
|
|
163
|
+
}
|
|
164
|
+
export type BoundingRectResult =
|
|
165
|
+
/** `visible` = rect has size AND intersects the frame's viewport. opacity /
|
|
166
|
+
* visibility:hidden / occlusion are NOT checked — agent must `evaluate` for those. */
|
|
167
|
+
| { ok: true; rect: { x: number; y: number; width: number; height: number }; visible: boolean }
|
|
168
|
+
| { ok: false; code: "not_found" | "runtime_error" | "cross_origin" | "not_supported"; message: string };
|
|
169
|
+
|
|
170
|
+
export interface Frame {
|
|
171
|
+
frameId: string;
|
|
172
|
+
parentFrameId: string | null;
|
|
173
|
+
origin: string;
|
|
174
|
+
url: string;
|
|
175
|
+
name?: string;
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
export type ListFramesResult =
|
|
179
|
+
| { ok: true; frames: Frame[] }
|
|
180
|
+
| { ok: false; code: "not_supported" | "runtime_error"; message: string };
|
|
181
|
+
|
|
182
|
+
export type DownloadPolicy = "auto" | "ask" | "block";
|
|
183
|
+
|
|
184
|
+
export type DownloadEvent =
|
|
185
|
+
| { kind: "started"; id: string; url: string; suggestedFilename: string; mimeType?: string; sizeBytes?: number }
|
|
186
|
+
| { kind: "progress"; id: string; receivedBytes: number; totalBytes?: number }
|
|
187
|
+
| { kind: "completed"; id: string; localPath: string }
|
|
188
|
+
| { kind: "failed"; id: string; reason: string }
|
|
189
|
+
| { kind: "blocked"; id: string; url: string; reason: "host-policy" | "backend-block" | "mime-blocked" | "not_supported" | "ask-not-implemented" };
|
|
190
|
+
|
|
191
|
+
export type WaitForDownloadResult =
|
|
192
|
+
| { ok: true; id: string; suggestedFilename: string; url: string; mimeType?: string; sizeBytes?: number; localPath: string }
|
|
193
|
+
| { ok: false; code: "timeout" | "blocked" | "failed" | "not_supported"; message: string };
|
|
194
|
+
|
|
195
|
+
export interface SetDownloadPolicyArgs {
|
|
196
|
+
surfaceId: number;
|
|
197
|
+
policy: DownloadPolicy;
|
|
198
|
+
/** Absolute path. When omitted, backend keeps current dir (or temp). */
|
|
199
|
+
downloadDir?: string;
|
|
200
|
+
}
|
|
201
|
+
|
|
202
|
+
export interface AcceptPopupArgs {
|
|
203
|
+
newSurfaceId: number;
|
|
204
|
+
/** The host BrowserView that will own the new surface. */
|
|
205
|
+
hostViewId: number;
|
|
206
|
+
bounds: { x: number; y: number; width: number; height: number };
|
|
207
|
+
}
|
|
208
|
+
export type AcceptPopupResult =
|
|
209
|
+
| { ok: true }
|
|
210
|
+
| { ok: false; code: "not_found" | "host_view_invalid"; message: string };
|
|
211
|
+
|
|
212
|
+
export interface ExtendPopupTimeoutArgs {
|
|
213
|
+
newSurfaceId: number;
|
|
214
|
+
/** Reset semantic: new deadline = now + gracePeriodMs. Not cumulative.
|
|
215
|
+
* Capped at 60s since the popup arm was emitted. */
|
|
216
|
+
gracePeriodMs: number;
|
|
217
|
+
}
|
|
218
|
+
export type ExtendPopupTimeoutResult =
|
|
219
|
+
| { ok: true; deadlineMs: number } // epoch ms of the new deadline
|
|
220
|
+
| { ok: false; code: "not_found" | "already_adopted" | "already_dismissed" | "cap_exceeded"; message: string };
|
|
221
|
+
|
|
222
|
+
/** Surface lifecycle event arm before the surface pipeline stamps `epoch`. */
|
|
223
|
+
export type SurfaceEventBase =
|
|
121
224
|
| { type: "navigate"; url: string }
|
|
122
225
|
| { type: "load-start"; url: string }
|
|
123
226
|
| { type: "load-finish"; url: string }
|
|
124
227
|
| { type: "load-fail"; url: string; reason?: string }
|
|
125
|
-
| { type: "title-change"; title: string }
|
|
228
|
+
| { type: "title-change"; title: string }
|
|
229
|
+
| {
|
|
230
|
+
type: "popup";
|
|
231
|
+
url: string;
|
|
232
|
+
disposition: "tab" | "window" | "popup";
|
|
233
|
+
openerSurfaceId: number;
|
|
234
|
+
/** Native surface ID minted before the arm is emitted. Host must call
|
|
235
|
+
* `acceptPopup` (within `popupAdoptionTimeoutMs`, default 5s) to attach,
|
|
236
|
+
* or `dismissPopup` to close. Auto-dismiss fires on timeout. */
|
|
237
|
+
newSurfaceId: number;
|
|
238
|
+
};
|
|
239
|
+
|
|
240
|
+
/** Wire form of `SurfaceEventBase`. `epoch` bumps on every `navigate` (incl. SPA
|
|
241
|
+
* `pushState`); other arms carry the current epoch. See `docs/browser-automation.md`. */
|
|
242
|
+
export type SurfaceEvent = SurfaceEventBase & { epoch: number };
|
|
243
|
+
|
|
244
|
+
export interface NavigationState {
|
|
245
|
+
lastLoadEpoch: number;
|
|
246
|
+
isLoading: boolean;
|
|
247
|
+
currentUrl: string;
|
|
248
|
+
}
|
|
126
249
|
|
|
127
250
|
export type EvaluateResult =
|
|
128
251
|
| { ok: true; value: unknown }
|
|
@@ -206,6 +329,7 @@ export interface WaitForSelectorArgs {
|
|
|
206
329
|
selector: string;
|
|
207
330
|
/** Default 5000ms. Polled at 50ms intervals via `evaluate`. */
|
|
208
331
|
timeoutMs?: number;
|
|
332
|
+
frameId?: string;
|
|
209
333
|
}
|
|
210
334
|
export interface WaitForFunctionArgs {
|
|
211
335
|
surfaceId: number;
|
|
@@ -215,6 +339,7 @@ export interface WaitForFunctionArgs {
|
|
|
215
339
|
timeoutMs?: number;
|
|
216
340
|
/** Default 50ms. Increase for heavy expressions to reduce IPC load. */
|
|
217
341
|
pollIntervalMs?: number;
|
|
342
|
+
frameId?: string;
|
|
218
343
|
}
|
|
219
344
|
export type WaitResult =
|
|
220
345
|
| { ok: true }
|
|
@@ -248,6 +373,22 @@ export type ScreenshotResult =
|
|
|
248
373
|
| { ok: true; data: Uint8Array; mime: string; format: "png" | "jpeg" }
|
|
249
374
|
| { ok: false; code: "not_supported" | "runtime_error" | "timeout" | "black_frame"; message: string };
|
|
250
375
|
|
|
376
|
+
export interface ResolveAndClickArgs {
|
|
377
|
+
surfaceId: number;
|
|
378
|
+
selector: string;
|
|
379
|
+
/** Same-origin iframe (CEF/WV2). OOPIF → `cross_origin`. mac/linux → `not_supported`. */
|
|
380
|
+
frameId?: string;
|
|
381
|
+
button?: "left" | "middle" | "right";
|
|
382
|
+
clickCount?: number;
|
|
383
|
+
modifiers?: Modifier[];
|
|
384
|
+
}
|
|
385
|
+
/** rect is viewport-normalized. `isTrustedEvent` is empirical per backend —
|
|
386
|
+
* CEF/WV2 CDP `Input.dispatchMouseEvent` produces trusted events; mac NSEvent
|
|
387
|
+
* direct dispatch is also trusted. All shipped backends report `true`. */
|
|
388
|
+
export type ResolveAndClickResult =
|
|
389
|
+
| { ok: true; rect: { x: number; y: number; width: number; height: number }; isTrustedEvent: boolean }
|
|
390
|
+
| { ok: false; code: "not_found" | "not_visible" | "runtime_error" | "cross_origin" | "not_supported"; message: string };
|
|
391
|
+
|
|
251
392
|
export const SurfaceCap = defineCap("bunite.Surface", {
|
|
252
393
|
init: call<{
|
|
253
394
|
src: string;
|
|
@@ -266,7 +407,7 @@ export const SurfaceCap = defineCap("bunite.Surface", {
|
|
|
266
407
|
navigate: call<{ surfaceId: number; url: string }, void>(),
|
|
267
408
|
goBack: call<{ surfaceId: number }, void>(),
|
|
268
409
|
reload: call<{ surfaceId: number }, void>(),
|
|
269
|
-
evaluate: call<{ surfaceId: number; script: string }, EvaluateResult>(),
|
|
410
|
+
evaluate: call<{ surfaceId: number; script: string; frameId?: string }, EvaluateResult>(),
|
|
270
411
|
capabilities: call<{ surfaceId: number }, SurfaceCapabilities>(),
|
|
271
412
|
click: call<ClickArgs, void>(),
|
|
272
413
|
type: call<TypeArgs, void>(),
|
|
@@ -282,8 +423,29 @@ export const SurfaceCap = defineCap("bunite.Surface", {
|
|
|
282
423
|
surfaceEvents: stream<{ surfaceId: number }, SurfaceEvent>(),
|
|
283
424
|
dialogs: stream<{ surfaceId: number }, DialogEvent>(),
|
|
284
425
|
consoleEvents: stream<{ surfaceId: number }, ConsoleEntry>(),
|
|
426
|
+
getNavigationState: call<{ surfaceId: number }, NavigationState>({ idempotent: true }),
|
|
427
|
+
accessibilitySnapshot: call<AccessibilitySnapshotArgs, AccessibilitySnapshotResult>(),
|
|
428
|
+
getBoundingRect: call<BoundingRectArgs, BoundingRectResult>({ idempotent: true }),
|
|
429
|
+
listFrames: call<{ surfaceId: number }, ListFramesResult>({ idempotent: true }),
|
|
430
|
+
downloadEvents: stream<{ surfaceId: number }, DownloadEvent>(),
|
|
431
|
+
waitForDownload: call<{ surfaceId: number; timeoutMs?: number }, WaitForDownloadResult>(),
|
|
432
|
+
setDownloadPolicy: call<SetDownloadPolicyArgs, void>(),
|
|
433
|
+
acceptPopup: call<AcceptPopupArgs, AcceptPopupResult>(),
|
|
434
|
+
dismissPopup: call<{ newSurfaceId: number }, void>(),
|
|
435
|
+
extendPopupTimeout: call<ExtendPopupTimeoutArgs, ExtendPopupTimeoutResult>(),
|
|
436
|
+
resolveAndClick: call<ResolveAndClickArgs, ResolveAndClickResult>(),
|
|
285
437
|
});
|
|
286
438
|
|
|
439
|
+
/** Process-lifetime cumulative counts of popup lifecycle resolutions. Useful
|
|
440
|
+
* for tuning the default popup adoption timeout. */
|
|
441
|
+
export interface PopupMetrics {
|
|
442
|
+
armed: number;
|
|
443
|
+
adopted: number;
|
|
444
|
+
dismissed: number;
|
|
445
|
+
timeoutFired: number;
|
|
446
|
+
extended: number;
|
|
447
|
+
}
|
|
448
|
+
|
|
287
449
|
export const RuntimeCap = defineCap("bunite.Runtime", {
|
|
288
450
|
window: call<void, typeof WindowCap>({ returns: cap(WindowCap), idempotent: true }),
|
|
289
451
|
dialogs: call<void, typeof DialogsCap>({ returns: cap(DialogsCap), idempotent: true }),
|
|
@@ -295,6 +457,7 @@ export const RuntimeCap = defineCap("bunite.Runtime", {
|
|
|
295
457
|
themeWatch: stream<void, "light" | "dark">(),
|
|
296
458
|
surface: call<void, typeof SurfaceCap>({ returns: cap(SurfaceCap), idempotent: true }),
|
|
297
459
|
reporting: call<void, typeof PageReportingCap>({ returns: cap(PageReportingCap), idempotent: true }),
|
|
460
|
+
popupMetrics: call<void, PopupMetrics>({ idempotent: true }),
|
|
298
461
|
});
|
|
299
462
|
|
|
300
463
|
export const FRAMEWORK_TYPE_IDS = {
|
package/src/rpc/index.ts
CHANGED
|
@@ -112,6 +112,11 @@ export type {
|
|
|
112
112
|
DialogMessageOpts,
|
|
113
113
|
SurfaceCapabilities,
|
|
114
114
|
SurfaceEvent,
|
|
115
|
+
SurfaceEventBase,
|
|
116
|
+
NavigationState,
|
|
117
|
+
DownloadEvent,
|
|
118
|
+
DownloadPolicy,
|
|
119
|
+
WaitForDownloadResult,
|
|
115
120
|
SurfaceMask,
|
|
116
121
|
Modifier,
|
|
117
122
|
ClickArgs,
|
|
@@ -130,6 +135,12 @@ export type {
|
|
|
130
135
|
ScreenshotArgs,
|
|
131
136
|
ScreenshotResult,
|
|
132
137
|
EvaluateResult,
|
|
138
|
+
AcceptPopupArgs,
|
|
139
|
+
AcceptPopupResult,
|
|
140
|
+
ExtendPopupTimeoutArgs,
|
|
141
|
+
ExtendPopupTimeoutResult,
|
|
142
|
+
ResolveAndClickArgs,
|
|
143
|
+
ResolveAndClickResult,
|
|
133
144
|
} from "./framework";
|
|
134
145
|
|
|
135
146
|
export type {
|