@ycodium-ai/plugin-devices 0.2.5029 → 0.2.5100
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/assets/ui.js +3 -3
- package/dist/index.js +1 -1
- package/package.json +4 -4
package/assets/ui.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
var
|
|
1
|
+
var na=`/*! tailwindcss v4.3.0 | MIT License | https://tailwindcss.com */
|
|
2
2
|
@layer properties, theme, base, components, utilities;
|
|
3
3
|
@layer properties;
|
|
4
4
|
@layer utilities {
|
|
@@ -557,7 +557,7 @@ var da=`/*! tailwindcss v4.3.0 | MIT License | https://tailwindcss.com */
|
|
|
557
557
|
}
|
|
558
558
|
}
|
|
559
559
|
}
|
|
560
|
-
`;var
|
|
560
|
+
`;var So=window.__ycodiumPluginHost.react;var{Activity:Kr,Children:Xr,Component:$r,Fragment:jr,Profiler:Zr,PureComponent:Jr,StrictMode:Qr,Suspense:Yr,__CLIENT_INTERNALS_DO_NOT_USE_OR_WARN_USERS_THEY_CANNOT_UPGRADE:el,__COMPILER_RUNTIME:al,act:tl,cache:ol,cacheSignal:rl,captureOwnerStack:ll,cloneElement:sl,createContext:Fa,createElement:ne,createRef:dl,forwardRef:qe,isValidElement:nl,lazy:ul,memo:il,startTransition:fl,unstable_useCacheRefresh:cl,use:pl,useActionState:ml,useCallback:Y,useContext:Oa,useDebugValue:gl,useDeferredValue:Ll,useEffect:B,useEffectEvent:hl,useId:xl,useImperativeHandle:Il,useInsertionEffect:Cl,useLayoutEffect:Ea,useMemo:ue,useOptimistic:Sl,useReducer:vl,useRef:G,useState:g,useSyncExternalStore:Ua,useTransition:yl,version:wl}=So;var qa=Fa(null),He=qa.Provider;function E(){let e=Oa(qa);if(e===null)throw new Error("The devices panel has not been registered.");return e}var Ha=window.__ycodiumPluginHost.modules?.["@ycodium-ai/plugin-api/ui"];if(!Ha)throw new Error("This plugin needs a newer Ycodium app. Update the app.");var{HOST_TEAM_VIEW_PREFIX:Pl,PLUGIN_UI_BRIDGE_VERSION:Al,PLUGIN_UI_FLOATING_VIEW_PROP:Na,PLUGIN_UI_GLOBAL_KEY:Tl,PLUGIN_UI_HOST_CAPABILITIES:Bl,PLUGIN_UI_HOST_COMMAND_PALETTE_UNAVAILABLE_MESSAGE:Ml,PLUGIN_UI_HOST_UPGRADE_MESSAGE:Rl,TEAM_VIEW_KEY_PATTERN:Fl,communicationRecordStage:Ol,defineTeamView:El,isTeamViewKey:Ul,pluginUiHostHasCapability:ce}=Ha;var vo="deviceFloat",Ne="device",j=e=>`${e.hostId}\0${e.id}`;function Se(e){let a={hostId:e.hostId,deviceId:e.id,platform:e.platform};return{viewId:vo,key:j(e),title:e.name,props:{...a},sourceSize:e.platform==="ios"?{width:9,height:19.5}:{width:9,height:20},...e.platform==="android"?{cornerRatio:.14}:{}}}function Va(e){let a=e.orientation==="landscape_left"||e.orientation==="landscape_right",t=Math.max(e.width,e.height),o=Math.min(e.width,e.height);return a?{width:t,height:o}:{width:o,height:t}}var ua=new Map,ia=new Set,Ve=(e,a)=>`${e}\0${a}`;function Ga(e,a){return Ua(t=>(ia.add(t),()=>{ia.delete(t)}),()=>ua.get(Ve(e,a))??null)}function Ge(e,a,t){let o=Ve(e,a);if((ua.get(o)??null)!==t){ua.set(o,t);for(let l of ia)l()}}var fa=new Set;function ca(e,a,t,o=!0){let l=`${Ve(e,a)}\0${t}`;o?fa.add(l):fa.delete(l)}function za(e){let a=new Set,t=[];for(let o of e.sessions){if(o.threadId!==e.threadId)continue;let l=e.devices.find(n=>n.hostId===o.hostId&&n.id===o.deviceId);if(l===void 0)continue;let d=j(l);if(a.add(d),e.previous===null||e.previous.has(d))continue;let s=`${Ve(e.environmentId,e.threadId)}\0${d}`;fa.delete(s)||t.push(l)}return{seen:a,opened:t}}var ze="ycodium-devices-ui";function A(e){return(a=>ne(E().ui[e],{...a,className:`${ze} ${typeof a.className=="string"?a.className:""}`}))}var S=A("Button"),z=A("Spinner"),pe=A("Switch"),_a=A("Tooltip"),Wa=A("TooltipPopup"),Ka=A("TooltipTrigger"),_e=A("Menu"),We=A("MenuPopup"),ve=A("MenuItem"),Xa=A("MenuSeparator"),Ke=A("MenuTrigger"),$a=A("MenuRadioGroup"),ja=A("MenuRadioItem"),ae=A("Input"),Za=A("Textarea"),pa=A("Select"),ma=A("SelectTrigger"),ga=A("SelectValue"),La=A("SelectPopup"),ha=A("SelectItem"),Xe=A("Collapsible"),$e=A("CollapsibleTrigger"),je=A("CollapsiblePanel"),Ja=A("ToggleGroup"),Qa=A("Toggle"),Ya=A("Popover"),et=A("PopoverTrigger"),at=A("PopoverPopup");var{jsx:r,jsxs:f,Fragment:Z}=window.__ycodiumPluginHost.jsxRuntime;function ee(e){return f("div",{className:"flex size-full flex-col items-center justify-center gap-3 p-6 text-center",children:[e.stage==="error"?null:r(z,{size:"sm"}),f("div",{className:"space-y-1",children:[r("p",{className:"text-sm font-medium text-foreground",children:e.name}),e.description?r("p",{className:"text-xs text-muted-foreground",children:e.description}):null]}),r("p",{role:e.stage==="error"?"alert":"status",className:e.stage==="error"?"max-w-sm whitespace-pre-wrap break-words text-xs text-destructive-foreground":"max-w-sm text-xs text-muted-foreground",children:e.message}),e.children]})}var Ze=class{decoder=new TextDecoder;rawDecoder=new TextDecoder("utf-8",{ignoreBOM:!0});pending="";raw="";data=[];eventName="";lastId=null;push(a){let t=[];return this.scan(a,!1,(o,l)=>{l!==void 0&&t.push(l)}),t}pushBlocks(a){let t=[];return this.scan(a,!0,(o,l)=>t.push({raw:o,event:l})),t}scan(a,t,o){let l=this.decoder.decode(a,{stream:!0}),d=this.pending+l;if(this.rawDecoder!==void 0){let n=this.rawDecoder.decode(a,{stream:!0});t&&(this.raw+=n.slice(0,n.length-l.length)),d.length>0&&(this.rawDecoder=void 0,d.charCodeAt(0)===65279&&(t&&(this.raw+=d[0]),d=d.slice(1)))}let s=0;for(let n=0;n<d.length;n++){let u=d[n];if(u!==`
|
|
561
561
|
`&&u!=="\r")continue;if(u==="\r"&&n===d.length-1)break;let i=d.slice(s,n);u==="\r"&&d[n+1]===`
|
|
562
562
|
`&&n++,t&&(this.raw+=d.slice(s,n+1));let c=this.line(i);i===""&&(o(this.raw,c),this.raw=""),s=n+1}this.pending=d.slice(s)}flush(){let a=this.raw+this.pending+this.decoder.decode();return this.raw="",this.pending="",this.data=[],this.eventName="",a}line(a){if(a===""){let d=this.data.length>0?{event:this.eventName||"message",data:this.data.join(`
|
|
563
|
-
`),id:this.lastId}:void 0;return this.data=[],this.eventName="",d}if(a.startsWith(":"))return;let t=a.indexOf(":"),o=t===-1?a:a.slice(0,t),l=t===-1?"":a.slice(t+1);l.startsWith(" ")&&(l=l.slice(1)),o==="data"?this.data.push(l):o==="event"?this.eventName=l:o==="id"&&!l.includes("\0")&&(this.lastId=l)}};async function Je(e,a,t){let o=e.body;if(!o)throw new Error("The response has no body to stream.");let l=o.getReader(),d=()=>{l.cancel().catch(()=>{})};if(t?.aborted)return d();t?.addEventListener("abort",d,{once:!0});try{for(;;){let{done:s,value:n}=await l.read();if(s||t?.aborted)return;a(n)}}catch(s){if(t?.aborted)return;throw s}finally{t?.removeEventListener("abort",d)}}async function et(e,a,t){if(!e.ok)throw await e.body?.cancel().catch(()=>{}),new Error(`Event stream failed (${e.status}).`);let o=new Ze;await Je(e,l=>{for(let d of o.push(l))a(d)},t)}var me=e=>e==="ios"?"/vendor/serve-sim":"/vendor/serve-emu";var Io=1e3,Co=500,Qe=(e,a,t)=>`${me(e.platform)}${a}${t?`?${new URLSearchParams(t).toString()}`:""}`,at=async(e,a,t)=>{let o=await e.transport.fetch(a,t?{signal:t}:void 0);if(!o.ok)throw new Error(`${o.status} ${o.statusText}`);return await o.json()},J=e=>typeof e=="object"&&e!==null,X=(e,a)=>typeof e=="number"&&Number.isFinite(e)?e:a,So=e=>{let a=e[0],t=J(a)&&J(a.frame)?a.frame:null,o=Math.max(1,X(t?.width,1)),l=Math.max(1,X(t?.height,1)),d=[],s=(n,u)=>{if(d.length>=Co||!J(n)||!J(n.frame))return;let i=n.frame,c=X(i.width,0),L=X(i.height,0);!(Math.abs(c-o)<.5&&Math.abs(L-l)<.5)&&c>0&&L>0&&d.push({id:typeof n.AXUniqueId=="string"?n.AXUniqueId:u,label:typeof n.AXLabel=="string"?n.AXLabel:"",role:typeof n.type=="string"?n.type:"",x:X(i.x,0)/o,y:X(i.y,0)/l,width:c/o,height:L/l}),(Array.isArray(n.children)?n.children:[]).forEach((p,h)=>s(p,`${u}.${h}`))};return e.forEach((n,u)=>s(n,String(u))),d},tt=e=>J(e)&&typeof e.error=="string"?e.error:"Unexpected accessibility payload.";async function rt(e,a){if(e.platform==="ios"){let u=await at(e,Qe(e,`/helper/${encodeURIComponent(e.deviceId)}/ax`),a);return Array.isArray(u)?{elements:So(u),errors:[]}:{elements:[],errors:[tt(u)]}}let t=await at(e,Qe(e,"/api/accessibility",{device:e.deviceId}),a);if(!J(t)||!Array.isArray(t.nodes))return{elements:[],errors:[tt(t)]};let o=t.nodes.filter(u=>J(u)&&J(u.bounds)),l=o[0]?.bounds,d=Math.max(1,X(l?.right,1)),s=Math.max(1,X(l?.bottom,1));return{elements:o.slice(1).flatMap(u=>{let i=u.bounds,c=X(i.left,0),L=X(i.top,0),v=(X(i.right,c)-c)/d,C=(X(i.bottom,L)-L)/s,p=typeof u.text=="string"?u.text:"",h=typeof u.contentDescription=="string"?u.contentDescription:"",T=p||h;if(v>=.95&&C>=.9)return[];if(!T&&u.clickable!==!0)return[];let m=typeof u.className=="string"?u.className:"";return[{id:String(u.id??""),label:T,role:m.split(".").at(-1)??"",x:c/d,y:L/s,width:v,height:C}]}),errors:[]}}var lt=(e,a,t)=>{let o=new AbortController,l=null,d=()=>{e.transport.fetch(a,{signal:o.signal}).then(s=>et(s,n=>{try{t(JSON.parse(n.data))}catch{}},o.signal)).catch(()=>{}).finally(()=>{o.signal.aborted||(l=setTimeout(d,Io))})};return d(),()=>{o.abort(),l!==null&&clearTimeout(l)}};function st(e,a){return e.platform!=="ios"?()=>{}:lt(e,Qe(e,"/appstate",{device:e.deviceId}),t=>{if(J(t)){if(t.bundleId===null||t.bundleId===""){a(null);return}typeof t.bundleId=="string"&&a({id:t.bundleId,...typeof t.pid=="number"?{pid:t.pid}:{},...typeof t.isReactNative=="boolean"?{isReactNative:t.isReactNative}:{}})}})}var ot=e=>!J(e)||typeof e.id!="number"?null:{id:e.id,timestamp:typeof e.timestamp=="string"?e.timestamp:"",kind:typeof e.kind=="string"?e.kind:"",summary:typeof e.summary=="string"?e.summary:typeof e.msg=="string"?e.msg:""};function dt(e,a){return e.platform!=="ios"?()=>{}:lt(e,Qe(e,"/api/event-log/events",{device:e.deviceId,limit:"100"}),t=>{if(!J(t))return;if(Array.isArray(t.events)){a(t.events.flatMap(l=>ot(l)??[]),!0);return}let o=ot(t.event);o&&a([o],!1)})}function D(){return{t:O().i18n.usePluginTranslation()}}function ea(e){if(e.length<4)return"avc1.42E01E";let a=t=>t.toString(16).padStart(2,"0");return`avc1.${a(e[1])}${a(e[2])}${a(e[3])}`}function nt(e){let a=new Uint8Array(e);if(a.byteLength>16){let t=new DataView(e,0,16);if(t.getUint32(0,!1)===1397050709&&t.getUint8(4)===1){let o=t.getBigUint64(8,!1);return{data:a.subarray(16),isKey:(t.getUint8(5)&1)!==0,timestamp:o<=BigInt(Number.MAX_SAFE_INTEGER)?Number(o):null}}}return{data:a,isKey:null,timestamp:null}}var ut=e=>{try{return JSON.parse(e)?.type==="video-session"}catch{return!1}};function it(e){let a=!1,t=null,o=e.length,l=0;for(;l+2<o;){if(e[l]===0&&e[l+1]===0){let d=0;if(e[l+2]===1?d=3:l+3<o&&e[l+2]===0&&e[l+3]===1&&(d=4),d){let s=e[l+d]&31;s===7&&!t&&(t=e.subarray(l+d)),s===5&&(a=!0),l+=d+1;continue}}l++}return{isKey:a,sps:t}}var vo={1:"description",2:"keyframe",3:"delta",4:"seed"},Ye=class{buffer=new Uint8Array(64*1024);length=0;push(a){if(this.length+a.length>this.buffer.length){let l=this.buffer.length;for(;l<this.length+a.length;)l*=2;let d=new Uint8Array(l);d.set(this.buffer.subarray(0,this.length)),this.buffer=d}this.buffer.set(a,this.length),this.length+=a.length;let t=[],o=0;for(;this.length-o>=4;){let d=new DataView(this.buffer.buffer,this.buffer.byteOffset+o,4).getUint32(0,!1);if(this.length-o-4<d)break;if(d>=1){let s=vo[this.buffer[o+4]];s&&t.push({type:s,payload:this.buffer.slice(o+5,o+4+d)})}o+=4+d}return o>0&&(this.buffer.copyWithin(0,o,this.length),this.length-=o),t}reset(){this.length=0}};var yo={Enter:40,Escape:41,Backspace:42,Tab:43,Space:44,Minus:45,Equal:46,BracketLeft:47,BracketRight:48,Backslash:49,Semicolon:51,Quote:52,Backquote:53,Comma:54,Period:55,Slash:56,Delete:76,ArrowRight:79,ArrowLeft:80,ArrowDown:81,ArrowUp:82,ControlLeft:224,ShiftLeft:225,AltLeft:226,MetaLeft:227,ControlRight:228,ShiftRight:229,AltRight:230,MetaRight:231};function ft(e){return/^Key[A-Z]$/.test(e)?4+(e.charCodeAt(3)-65):/^Digit[1-9]$/.test(e)?30+(e.charCodeAt(5)-49):e==="Digit0"?39:yo[e]??null}var ct={ArrowUp:19,ArrowDown:20,ArrowLeft:21,ArrowRight:22,Tab:61,Enter:66,Backspace:67,Delete:112,Home:122,End:123,PageUp:92,PageDown:93};function ha(e){if(e.stopped)return;let a=d=>{e.configuring=!1,e.connecting(d),e.scheduleRetry("input",()=>ha(e))},t;try{t=e.transport.connect(`${e.vendor}/ws?device=${e.device}&frame-meta=1`)}catch(d){e.events.onInputConnected(!1,d.message),a(d.message);return}e.socket=t;let o=[],l=!1;t.onopen=()=>{e.stopped||e.socket!==t||(e.connecting(),e.events.onInputConnected(!0))},t.onmessage=d=>{if(e.stopped||e.socket!==t)return;if(typeof d.data=="string"){ut(d.data)&&(e.closeDecoder(),e.configuring=!1,o=[],l=!1,e.connecting());return}let s=nt(d.data),n=!e.videoDecoder||e.videoDecoder.state!=="configured",i=s.isKey===null||s.isKey&&n?it(s.data):null,c=s.isKey??i?.isKey??!1,L={isKey:c,data:s.data,timestamp:s.timestamp};if(e.configuring){o.push(L);return}if(i?.sps&&n){e.configuring=!0,o=[L];let v=e.decoderEpoch,C=()=>!e.stopped&&e.socket===t;e.configureDecoder({codec:ea(i.sps)},C).then(p=>{if(!C()||v!==e.decoderEpoch)return;e.configuring=!1,e.awaitingKeyframe=!0;let h=o;if(o=[],!!p){for(let T of h)e.decode(T.isKey,T.data,T.timestamp);e.awaitingKeyframe&&e.requestKeyframe()}});return}if(n){!c&&!l&&(l=!0,e.requestKeyframe());return}e.decode(c,s.data,s.timestamp)},t.onclose=d=>{e.socket===t&&(e.socket=null,e.closeDecoder(),!e.stopped&&(e.events.onInputConnected(!1,d.reason||`closed ${d.code}`),a(d.reason||void 0)))},t.onerror=()=>t.close()}function pt(e){return{sendTouch(a,t,o){let l=a==="begin"?"down":a==="move"?"move":"up";e.send(JSON.stringify({type:"touch",action:l,x:t,y:o}))},sendKey(a,t){if(t!=="down")return;if(a.key==="Escape")return e.send(JSON.stringify({type:"back"}));let o=ct[a.key];if(o!==void 0)return e.send(JSON.stringify({type:"key",keycode:o}));a.key.length===1&&!a.metaKey&&!a.ctrlKey&&e.send(JSON.stringify({type:"text",text:a.key}))},pressButton(a){let t=a==="appSwitcher"?"recents":a;(t==="home"||t==="back"||t==="recents"||t==="power")&&e.send(JSON.stringify({type:t}))},rotate(){},setOrientation(){}}}function mt(e){return{present(a,t,o){let l=e.getContext("2d");return l?((e.width!==t||e.height!==o)&&(e.width=t,e.height=o),l.drawImage(a,0,0,t,o),!0):!1}}}var gt=new TextEncoder,Lt=new TextDecoder;function xt(e){if(!e)return null;let a=/boundary=(?:"([^"]+)"|([^;\s]+))/i.exec(e),t=a?.[1]??a?.[2];return t?t.startsWith("--")?t:`--${t}`:null}function ht(e,a,t,o){let l=o-a.length;for(let d=t;d<=l;d++){if(e[d]!==a[0])continue;let s=1;for(;s<a.length&&e[d+s]===a[s];)s++;if(s===a.length)return d}return-1}var aa=class{delimiter;buffer=new Uint8Array(64*1024);length=0;pos=0;state="boundary";contentLength=null;scanFrom=0;constructor(a){this.delimiter=a?gt.encode(a):null}push(a){this.append(a);let t=[];for(;;){if(this.state==="done"){this.pos=this.length=0;break}if(this.state==="boundary"){if(!this.readBoundary())break}else if(this.state==="headers"){if(!this.readHeaders())break}else{let o=this.readBody();if(!o)break;o.length>0&&t.push(o)}}if(this.length-this.pos>16777216)throw new Error("MJPEG part is too large.");return this.pos>0&&(this.buffer.copyWithin(0,this.pos,this.length),this.length-=this.pos,this.scanFrom=Math.max(0,this.scanFrom-this.pos),this.pos=0),t}append(a){if(this.length+a.length>this.buffer.length){let t=this.buffer.length;for(;t<this.length+a.length;)t*=2;let o=new Uint8Array(t);o.set(this.buffer.subarray(0,this.length)),this.buffer=o}this.buffer.set(a,this.length),this.length+=a.length}lineEnd(a){return this.buffer.subarray(0,this.length).indexOf(10,a)}readBoundary(){let a=this.buffer;if(!this.delimiter)for(;;){let s=this.lineEnd(this.pos);if(s===-1)return!1;let n=Lt.decode(a.subarray(this.pos,s)).trim();if(this.pos=s+1,n.startsWith("--"))return this.delimiter=gt.encode(n),this.state="headers",!0}let t=this.delimiter,o=ht(a,t,this.pos,this.length);if(o===-1)return this.pos=Math.max(this.pos,this.length-t.length+1),!1;let l=o+t.length;if(l+2>this.length)return this.pos=o,!1;if(a[l]===45&&a[l+1]===45)return this.state="done",!0;let d=this.lineEnd(l);return d===-1?(this.pos=o,!1):(this.pos=d+1,this.state="headers",!0)}readHeaders(){let a=this.pos,t=null;for(;;){let o=this.lineEnd(a);if(o===-1)return!1;let l=Lt.decode(this.buffer.subarray(a,o)).replace(/\r$/,"");if(a=o+1,l==="")break;let d=l.indexOf(":");if(d>0&&l.slice(0,d).trim().toLowerCase()==="content-length"){let s=Number.parseInt(l.slice(d+1).trim(),10);Number.isFinite(s)&&s>=0&&(t=s)}}return this.pos=a,this.contentLength=t,this.scanFrom=a,this.state="body",!0}readBody(){if(this.contentLength!==null){if(this.length-this.pos<this.contentLength)return null;let o=this.buffer.slice(this.pos,this.pos+this.contentLength);return this.pos+=this.contentLength,this.state="boundary",o}let a=this.delimiter,t=Math.max(this.scanFrom,this.pos+1);for(;;){let o=ht(this.buffer,a,t,this.length);if(o===-1)return this.scanFrom=Math.max(this.pos,this.length-a.length),null;if(this.buffer[o-1]!==10){t=o+1;continue}let l=o-1;l>this.pos&&this.buffer[l-1]===13&&l--;let d=this.buffer.slice(this.pos,Math.max(l,this.pos));return this.pos=o,this.state="boundary",d}}};async function wo(e,a,t){let o=new aa(xt(e.headers.get("content-type")));await Je(e,l=>{for(let d of o.push(l))a(d)},t)}function ye(e){e.stopped||e.mjpeg||(e.mjpeg=!0,e.controller?.abort(),e.controller=null,e.closeDecoder(),e.connecting(),e.events.onMjpegFallback?.(),It(e))}var xa=e=>`${e.vendor}/helper/${e.device}/stream.mjpeg`;async function It(e){let a=e.generation,t=++e.videoGeneration,o=new AbortController;e.controller=o;let l=()=>!e.stopped&&e.generation===a&&e.videoGeneration===t&&e.controller===o,d=null,s=!1,n=async()=>{s=!0;try{for(;d;){let i=d;d=null;try{let c=await e.createBitmap(new Blob([i],{type:"image/jpeg"}));try{l()&&e.paint(c,c.width,c.height)}finally{c.close()}}catch{}}}finally{s=!1}},u;try{let i=await e.transport.fetch(xa(e),{signal:o.signal});if(!l()){await i.body?.cancel();return}if(!i.ok||!i.body)throw new Error(`stream ${i.status}`);if(await wo(i,c=>{l()&&(d=c,s||n())},o.signal),!l())return;u="Device stream ended."}catch(i){if(!l())return;u=i.message}l()&&(e.controller=null,o.abort(),e.connecting(u),e.scheduleRetry("video",()=>{It(e)}))}var bo=1e3,Ia=15e3,ko=16667,Do=8,Po=e=>typeof e=="object"&&e!==null&&"present"in e;function St(e){let{transport:a,platform:t,events:o}=e,l=Po(e.output)?e.output:mt(e.output),d=n=>e.globals?.[n]??globalThis[n],s={platform:t,transport:a,events:o,preferMjpeg:e.preferMjpeg===!0,vendor:me(t),device:encodeURIComponent(e.deviceId),stopped:!0,generation:0,videoGeneration:0,decoderEpoch:0,socket:null,controller:null,primeController:null,videoDecoder:null,timestamp:0,awaitingKeyframe:!0,screen:null,firstFrame:!1,configuring:!1,mjpeg:!1,frameTimer:null,videoReadTimer:null,retryTimers:new Map,webCodecs(){let n=d("VideoDecoder"),u=d("EncodedVideoChunk");return n&&u?{VideoDecoder:n,EncodedVideoChunk:u}:null},createBitmap(n){let u=d("createImageBitmap");return u?u(n):Promise.reject(new Error("createImageBitmap is unavailable."))},setStatus(n,u){s.stopped||o.onStatus(n,u)},fail(n){s.stopped||(s.stop(),o.onInputConnected(!1,n),o.onStatus("error",n))},connecting(n){s.firstFrame=!1,s.frameTimer===null&&(s.frameTimer=setTimeout(()=>s.fail("No video received from the device. Reconnect to try again."),Ia)),s.setStatus("connecting",n)},paint(n,u,i){if(!s.stopped){if(t==="android"&&(s.screen?.width!==u||s.screen.height!==i)&&(s.screen={width:u,height:i,orientation:u>i?"landscape_left":"portrait"},o.onScreen(s.screen)),!l.present(n,u,i)){s.fail("Could not display the device stream. Reconnect to try again.");return}s.firstFrame||(s.firstFrame=!0,s.frameTimer!==null&&clearTimeout(s.frameTimer),s.frameTimer=null,s.setStatus("streaming"))}},closeDecoder(){s.decoderEpoch++,s.configuring=!1;try{s.videoDecoder?.close()}catch{}s.videoDecoder=null,s.awaitingKeyframe=!0},recoverDecoder(){t==="ios"?ye(s):(s.closeDecoder(),s.connecting("Video decoder restarted."),s.requestKeyframe())},async configureDecoder(n,u=()=>!s.stopped){let i=s.webCodecs();if(!i)return!1;let c=s.decoderEpoch,L={...n,optimizeForLatency:!0},v=await i.VideoDecoder.isConfigSupported(L).catch(()=>({supported:!1}));if(!u()||c!==s.decoderEpoch)return!1;if(!v.supported)return t==="android"&&s.fail(`This browser cannot decode ${n.codec}.`),!1;try{return(!s.videoDecoder||s.videoDecoder.state==="closed")&&(s.videoDecoder=Ao(s,i)),s.videoDecoder.configure(L),!0}catch(C){return t==="android"&&s.fail(`Video decoder: ${C.message}`),!1}},decode(n,u,i){let c=s.videoDecoder,L=s.webCodecs();if(!(!c||c.state!=="configured"||!L)){if(s.awaitingKeyframe){if(!n)return;s.awaitingKeyframe=!1}if(c.decodeQueueSize>Do){s.recoverDecoder();return}try{c.decode(new L.EncodedVideoChunk({type:n?"key":"delta",timestamp:i??s.timestamp,data:u})),s.timestamp+=ko}catch{s.recoverDecoder()}}},requestKeyframe(){t==="android"&&s.socket?.readyState===1&&s.socket.send(JSON.stringify({type:"reset-video",ack:!1}))},scheduleRetry(n,u){s.stopped||s.retryTimers.has(n)||s.retryTimers.set(n,setTimeout(()=>{s.retryTimers.delete(n),u()},bo))},send(n){!s.stopped&&s.socket?.readyState===1&&s.socket.send(n)},stop(){if(s.stopped)return;s.stopped=!0,s.generation++,s.videoGeneration++,s.mjpeg=!1,s.frameTimer!==null&&clearTimeout(s.frameTimer),s.frameTimer=null,s.videoReadTimer!==null&&clearTimeout(s.videoReadTimer),s.videoReadTimer=null;for(let u of s.retryTimers.values())clearTimeout(u);s.retryTimers.clear(),s.primeController?.abort(),s.primeController=null,s.controller?.abort(),s.controller=null;let n=s.socket;s.socket=null,n?.close(),s.closeDecoder()}};return s}function Ao(e,a){let t=e.videoGeneration,o=()=>e.platform!=="ios"||t===e.videoGeneration,l=new a.VideoDecoder({output:d=>{try{e.videoDecoder===l&&o()&&e.paint(d,d.displayWidth,d.displayHeight)}finally{d.close()}},error:()=>{e.stopped||e.videoDecoder!==l||!o()||e.recoverDecoder()}});return l}var To=3,Bo=4,Mo=6,vt=7,Ro=13,Fo=130,Eo=2e3,Oo=new TextEncoder,Uo=new TextDecoder,ta=["portrait","landscape_left","portrait_upside_down","landscape_right"],qo=new Set(ta);function ge(e,a){let t=Oo.encode(JSON.stringify(a)),o=new Uint8Array(1+t.length);return o[0]=e,o.set(t,1),o}function Ho(e){if(typeof e!="object"||e===null)return null;let{width:a,height:t,orientation:o,screenId:l}=e;if(typeof a!="number"||!Number.isFinite(a)||a<=0||typeof t!="number"||!Number.isFinite(t)||t<=0||typeof o!="string"||!qo.has(o))return null;let d={width:a,height:t,orientation:o};return typeof l=="number"?{...d,screenId:l}:d}function yt(e,a){bt(e),a?wt(e):ye(e)}async function wt(e){let a=e.generation,t=++e.videoGeneration,o=new Ye,l=new AbortController;e.controller=l;let d=()=>!e.stopped&&e.generation===a&&e.videoGeneration===t&&e.controller===l,s;try{let n=await e.transport.fetch(`${e.vendor}/helper/${e.device}/stream.avcc`,{signal:l.signal});if(!d()){await n.body?.cancel();return}if(!n.ok||!n.body)throw new Error(`stream ${n.status}`);let u=n.body.getReader();for(;;){let i=setTimeout(()=>{d()&&e.fail("Device stream stopped receiving video. Reconnect to try again.")},Ia);e.videoReadTimer=i;let c;try{c=await u.read()}finally{clearTimeout(i),e.videoReadTimer===i&&(e.videoReadTimer=null)}let{done:L,value:v}=c;if(!d())return;if(L)break;for(let C of o.push(v))switch(C.type){case"seed":e.createBitmap(new Blob([C.payload],{type:"image/jpeg"})).then(p=>{try{d()&&e.paint(p,p.width,p.height)}finally{p.close()}}).catch(()=>{});break;case"description":{e.awaitingKeyframe=!0;let p=await e.configureDecoder({codec:ea(C.payload),description:C.payload},d);if(!d())return;if(!p){if(await u.cancel().catch(()=>{}),!d())return;ye(e);return}break}case"keyframe":case"delta":e.decode(C.type==="keyframe",C.payload);break}}}catch(n){if(!d())return;s=n.message}d()&&(e.controller=null,l.abort(),e.closeDecoder(),e.connecting(s),e.scheduleRetry("video",()=>{wt(e)}))}async function No(e,a){let t=new AbortController;e.primeController=t;let o=setTimeout(()=>t.abort(),Eo);try{let l=await e.transport.fetch(xa(e),{signal:t.signal});if(e.stopped||e.generation!==a)return;await l.body?.getReader().read()}catch{}finally{clearTimeout(o),t.abort(),e.primeController===t&&(e.primeController=null)}}async function bt(e){if(e.stopped)return;let a=e.generation;if(await No(e,a),e.stopped||e.generation!==a)return;let t=()=>e.scheduleRetry("input",()=>{bt(e)}),o;try{o=e.transport.connect(`${e.vendor}/helper/ws?device=${e.device}`)}catch(l){e.events.onInputConnected(!1,l.message),t();return}e.socket=o,o.onopen=()=>{e.stopped||e.socket!==o||(o.send(ge(Ro,{enabled:!1})),e.events.onInputConnected(!0))},o.onmessage=l=>{if(e.stopped||e.socket!==o||typeof l.data=="string")return;let d=new Uint8Array(l.data);if(!(d.length<1||d[0]!==Fo))try{let s=Ho(JSON.parse(Uo.decode(d.subarray(1))));s&&(e.screen=s,e.events.onScreen(s))}catch{}},o.onclose=l=>{e.socket===o&&(e.socket=null,!e.stopped&&(e.events.onInputConnected(!1,l.reason||(l.code===1006?"input socket refused":`closed ${l.code}`)),t()))},o.onerror=()=>o.close()}function Vo(e,a,t){let o=e.screen;if(!o||o.width>o.height)return{x:a,y:t};switch(o.orientation){case"landscape_left":return{x:t,y:1-a};case"landscape_right":return{x:1-t,y:a};case"portrait_upside_down":return{x:1-a,y:1-t};default:return{x:a,y:t}}}function kt(e){return{sendTouch(a,t,o){e.send(ge(To,{type:a,...Vo(e,t,o)}))},sendKey(a,t){let o=ft(a.code);o!==null&&e.send(ge(Mo,{type:t,usage:o}))},pressButton(a){let t=a==="home"?"home":a==="appSwitcher"?"app_switcher":a==="power"?"lock":null;t&&e.send(ge(Bo,{button:t}))},rotate(){let a=e.screen?.orientation??"portrait",t=ta[(ta.indexOf(a)+1)%ta.length];e.send(ge(vt,{orientation:t}))},setOrientation(a){e.send(ge(vt,{orientation:a}))}}}function Dt(e){let a=St(e),t=e.platform==="ios"?kt(a):pt(a);return{start:()=>{if(!a.stopped)return;a.stopped=!1,a.generation++,a.configuring=!1,a.connecting();let l=a.webCodecs()!==null&&!(e.platform==="ios"&&a.preferMjpeg);e.platform==="ios"?yt(a,l):l?ha(a):a.fail("This browser cannot decode the Android stream (WebCodecs unavailable).")},stop:a.stop,isMjpeg:()=>a.mjpeg,...t}}var Go=56,zo=2e3;function _o(e,a,t,o=0){let l=Math.max(0,a-o);if(l===0||t===0)return{width:0,height:0};let d={width:t*e,height:t};return d.width<=l?d:{width:l,height:l/e}}function Wo(e,a){if(!a)return e==="ios"?9/19.5:9/20;let t=a.orientation==="landscape_left"||a.orientation==="landscape_right",o=Math.max(a.width,a.height),l=Math.min(a.width,a.height);return t?o/l:l/o}function Ko(e,a){if(e!=="ios"||!a||a.width>a.height)return 0;switch(a.orientation){case"landscape_left":return 90;case"landscape_right":return-90;case"portrait_upside_down":return 180;default:return 0}}var Xo=()=>typeof navigator<"u"&&/iPhone|iPad|iPod/.test(navigator.userAgent);function oa(e){let{t:a}=D(),t=G(null),o=G(null),[l,d]=g("connecting"),[s,n]=g(),[u,i]=g(!1),[c,L]=g(null),[v,C]=g({connected:!1}),{onHandle:p,onStreaming:h,onScreen:T,transport:m,platform:y,deviceId:R}=e;B(()=>T?.(c),[T,c]),B(()=>{let I=t.current;if(!I)return;let k=Dt({transport:m,platform:y,deviceId:R,output:I,preferMjpeg:Xo(),events:{onStatus:(E,N)=>{d(E),n(N),E==="streaming"&&i(!0),h(E==="streaming")},onScreen:L,onInputConnected:(E,N)=>{C({connected:E,...N?{detail:N}:{}}),p({pressButton:k.pressButton,rotate:k.rotate,inputConnected:E})}}});return o.current=k,C({connected:!1}),k.start(),p({pressButton:k.pressButton,rotate:k.rotate,inputConnected:!1}),()=>{k.stop(),o.current=null,p(null),h(!1),i(!1),L(null)}},[R,p,h,y,m]);let F=G(null),[_,P]=g({width:0,height:0});B(()=>{let I=F.current;if(!I)return;let k=()=>{let N=I.getBoundingClientRect();P(de=>de.width===N.width&&de.height===N.height?de:{width:N.width,height:N.height})};k();let E=new ResizeObserver(k);return E.observe(I),()=>E.disconnect()},[]);let b=e.withControls?Go:0,U=ue(()=>_o(Wo(y,c),_.width,_.height,b),[_,b,y,c]),W=Ko(y,c),q=W===90||W===-90?{width:U.height,height:U.width,left:(U.width-U.height)/2,top:(U.height-U.width)/2,transform:`rotate(${W}deg)`}:{width:U.width,height:U.height,...W?{transform:`rotate(${W}deg)`}:{}},[K,$]=g([]);B(()=>{if(!e.axOverlay)return;let I=null,k=null,E=!1,N=async()=>{I=new AbortController;try{let de=await rt({transport:m,platform:y,deviceId:R},I.signal);E||$(de.elements)}catch{}E||(k=setTimeout(()=>{N()},zo))};return N(),()=>{E=!0,I?.abort(),k&&clearTimeout(k),$([])}},[R,y,e.axOverlay,m]);let V=G(!1),x=I=>{let k=I.currentTarget.getBoundingClientRect(),E=(I.clientX-k.left)/k.width,N=(I.clientY-k.top)/k.height;return{x:Math.min(1,Math.max(0,E)),y:Math.min(1,Math.max(0,N))}},H=I=>{if(!V.current)return;V.current=!1;let{x:k,y:E}=x(I);o.current?.sendTouch("end",k,E)};return f("div",{ref:F,className:"relative flex size-full min-h-0 min-w-0 items-center justify-center overflow-hidden",style:b?{paddingRight:b}:void 0,tabIndex:0,role:"application","aria-label":a(y==="ios"?"stream.iosScreen":"stream.androidScreen"),onKeyDown:I=>{I.target===I.currentTarget&&(I.metaKey&&!["r","R"].includes(I.key)||(I.preventDefault(),o.current?.sendKey(I.nativeEvent,"down")))},onKeyUp:I=>{I.target===I.currentTarget&&o.current?.sendKey(I.nativeEvent,"up")},children:[f("div",{className:"relative touch-none select-none",style:{width:U.width,height:U.height},onPointerDown:I=>{I.currentTarget.setPointerCapture(I.pointerId),I.currentTarget.parentElement?.focus(),V.current=!0;let{x:k,y:E}=x(I);o.current?.sendTouch("begin",k,E)},onPointerMove:I=>{if(!V.current)return;let{x:k,y:E}=x(I);o.current?.sendTouch("move",k,E)},onPointerUp:H,onPointerCancel:H,children:[r("canvas",{ref:t,className:"absolute top-0 left-0",style:q}),K.length>0?r("div",{className:"pointer-events-none absolute inset-0","aria-hidden":!0,children:K.map(I=>r("div",{className:"absolute border border-info/80 bg-info/10",style:{left:`${I.x*100}%`,top:`${I.y*100}%`,width:`${I.width*100}%`,height:`${I.height*100}%`},children:I.label?r("span",{className:"absolute -top-3.5 left-0 max-w-full truncate rounded-sm bg-info px-1 text-ui-2xs leading-3.5 text-white",children:I.label}):null},I.id))}):null]}),l==="streaming"&&!v.connected?r("div",{className:"pointer-events-none absolute inset-x-0 bottom-0 flex justify-center p-2",children:r("span",{className:"rounded-md bg-background/85 px-2 py-1 text-xs text-muted-foreground",children:v.detail?a("stream.inputLostDetail",{detail:v.detail}):a("stream.inputLost")})}):null,l==="connecting"&&u?r("div",{className:"pointer-events-none absolute inset-x-0 bottom-0 flex justify-center p-2",children:r("span",{className:"rounded-md bg-background/85 px-2 py-1 text-xs text-muted-foreground",children:a("stream.connecting")})}):null,l==="error"||l!=="streaming"&&!u?r("div",{className:"absolute inset-0 bg-background",children:r(ee,{name:e.deviceName,description:e.deviceDescription,stage:l==="error"?"error":"connecting",message:l==="error"?s??a("stream.failed"):a("stream.connecting"),children:l==="error"?r(S,{size:"sm",variant:"outline",onClick:()=>{o.current?.stop(),o.current?.start()},children:a("stream.reconnect")}):null})}):null]})}var $o={hosts:[],hostStatuses:{},devices:[],sessions:[],bootingDevices:[],revision:0};function Le(e){let t=O().commands.useSubscription("state",{},{environmentId:e});return{state:t.data??$o,loaded:t.data!==null,error:t.error,unavailable:t.isUnavailable}}function te(){let e=O();return Y((a,t,o={})=>e.commands.invoke(a,o,{environmentId:t}),[e])}var he="local",ra=class extends Error{code;constructor(a,t,o){super(t,o),this.name="DeviceError",this.code=a}};var Pt="hub";function la(e){let a=O(),[t,o]=g({status:"connecting"});return B(()=>{let l=a.network;if(!ce(a,"network")||l===void 0){o({status:"failed",message:null});return}let d=!1;return o({status:"connecting"}),l.client(e).then(s=>{d||o({status:"ready",transport:{fetch:(n,u)=>s.fetch(Pt,n,{...u,instance:he}),connect:n=>s.connect(Pt,n,{instance:he})}})},s=>{d||o({status:"failed",message:s instanceof Error?s.message:String(s)})}),()=>{d=!0}},[a,e]),t}var At=()=>{};function Tt(e){let{environmentId:a,threadId:t,hostId:o,deviceId:l,platform:d}=e,s=e[qa],n=O(),{t:u}=D(),{state:i,loaded:c}=Le(a),L=la(a),v=ue(()=>({environmentId:a,threadId:t}),[a,t]),C=i.devices.find(y=>y.hostId===o&&y.id===l),p=i.sessions.some(y=>y.threadId===t&&y.hostId===o&&y.deviceId===l);B(()=>{c&&!p&&n.floating?.close(v,s.key)},[n,s.key,c,p,v]),B(()=>(s.setOpenInPanel(()=>{Ge(a,t,s.key),n.floating?.openPanel(v,Ne),n.floating?.close(v,s.key)}),()=>s.setOpenInPanel(null)),[n,a,s,v,t]);let h=Y(y=>s.reportSourceSize(y===null?null:Ha(y)),[s]),T=C?.name??l,m=C?.version??d;return L.status!=="ready"?r(ee,{name:T,description:m,stage:L.status==="failed"?"error":"connecting",message:L.status==="failed"?L.message??u("workspace.needsNewerApp"):u("stream.connecting")}):r(oa,{transport:L.transport,platform:d,deviceId:l,deviceName:T,deviceDescription:m,axOverlay:!1,withControls:!1,onHandle:At,onStreaming:At,onScreen:h})}var sa=(...e)=>e.filter((a,t,o)=>!!a&&a.trim()!==""&&o.indexOf(a)===t).join(" ").trim();var Bt=e=>e.replace(/([a-z0-9])([A-Z])/g,"$1-$2").toLowerCase();var Mt=e=>e.replace(/^([A-Z])|[\s-_]+(\w)/g,(a,t,o)=>o?o.toUpperCase():t.toLowerCase());var Ca=e=>{let a=Mt(e);return a.charAt(0).toUpperCase()+a.slice(1)};var Rt={xmlns:"http://www.w3.org/2000/svg",width:24,height:24,viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:2,strokeLinecap:"round",strokeLinejoin:"round"};var Ft=e=>{for(let a in e)if(a.startsWith("aria-")||a==="role"||a==="title")return!0;return!1};var Et=qe(({color:e="currentColor",size:a=24,strokeWidth:t=2,absoluteStrokeWidth:o,className:l="",children:d,iconNode:s,...n},u)=>ne("svg",{ref:u,...Rt,width:a,height:a,stroke:e,strokeWidth:o?Number(t)*24/Number(a):t,className:sa("lucide",l),...!d&&!Ft(n)&&{"aria-hidden":"true"},...n},[...s.map(([i,c])=>ne(i,c)),...Array.isArray(d)?d:[d]]));var w=(e,a)=>{let t=qe(({className:o,...l},d)=>ne(Et,{ref:d,iconNode:a,className:sa(`lucide-${Bt(Ca(e))}`,`lucide-${e}`,o),...l}));return t.displayName=Ca(e),t};var jo=[["path",{d:"M13.997 4a2 2 0 0 1 1.76 1.05l.486.9A2 2 0 0 0 18.003 7H20a2 2 0 0 1 2 2v9a2 2 0 0 1-2 2H4a2 2 0 0 1-2-2V9a2 2 0 0 1 2-2h1.997a2 2 0 0 0 1.759-1.048l.489-.904A2 2 0 0 1 10.004 4z",key:"18u6gg"}],["circle",{cx:"12",cy:"13",r:"3",key:"1vg3eu"}]],we=w("camera",jo);var Zo=[["path",{d:"m6 9 6 6 6-6",key:"qrunsl"}]],be=w("chevron-down",Zo);var Jo=[["path",{d:"m15 18-6-6 6-6",key:"1wnfg3"}]],ke=w("chevron-left",Jo);var Qo=[["circle",{cx:"12",cy:"12",r:"1",key:"41hilf"}],["circle",{cx:"19",cy:"12",r:"1",key:"1wjl8i"}],["circle",{cx:"5",cy:"12",r:"1",key:"1pcz8c"}]],oe=w("ellipsis",Qo);var Yo=[["path",{d:"M15 21v-8a1 1 0 0 0-1-1h-4a1 1 0 0 0-1 1v8",key:"5wwlr5"}],["path",{d:"M3 10a2 2 0 0 1 .709-1.528l7-6a2 2 0 0 1 2.582 0l7 6A2 2 0 0 1 21 10v9a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2z",key:"r6nss1"}]],re=w("house",Yo);var er=[["circle",{cx:"12",cy:"12",r:"10",key:"1mglay"}],["path",{d:"M12 16v-4",key:"1dtifu"}],["path",{d:"M12 8h.01",key:"e9boi3"}]],De=w("info",er);var ar=[["path",{d:"M20.985 12.486a9 9 0 1 1-9.473-9.472c.405-.022.617.46.402.803a6 6 0 0 0 8.268 8.268c.344-.215.825-.004.803.401",key:"kfwtm"}]],Pe=w("moon",ar);var tr=[["path",{d:"M21 9V6a2 2 0 0 0-2-2H4a2 2 0 0 0-2 2v10c0 1.1.9 2 2 2h4",key:"daa4of"}],["rect",{width:"10",height:"7",x:"12",y:"13",rx:"2",key:"1nb8gs"}]],Ae=w("picture-in-picture-2",tr);var or=[["path",{d:"M12 2v10",key:"mnfbl"}],["path",{d:"M18.4 6.6a9 9 0 1 1-12.77.04",key:"obofu9"}]],Te=w("power",or);var rr=[["path",{d:"M3 12a9 9 0 1 0 9-9 9.75 9.75 0 0 0-6.74 2.74L3 8",key:"1357e3"}],["path",{d:"M3 3v5h5",key:"1xhq8a"}]],xe=w("rotate-ccw",rr);var lr=[["path",{d:"M21 12a9 9 0 1 1-9-9c2.52 0 4.93 1 6.74 2.74L21 8",key:"1p45f6"}],["path",{d:"M21 3v5h-5",key:"1q7to0"}]],Be=w("rotate-cw",lr);var sr=[["path",{d:"M10 5H3",key:"1qgfaw"}],["path",{d:"M12 19H3",key:"yhmn1j"}],["path",{d:"M14 3v4",key:"1sua03"}],["path",{d:"M16 17v4",key:"1q0r14"}],["path",{d:"M21 12h-9",key:"1o4lsq"}],["path",{d:"M21 19h-5",key:"1rlt1p"}],["path",{d:"M21 5h-7",key:"1oszz2"}],["path",{d:"M8 10v4",key:"tgpxqk"}],["path",{d:"M8 12H3",key:"a7s4jb"}]],Me=w("sliders-horizontal",sr);var dr=[["rect",{width:"14",height:"20",x:"5",y:"2",rx:"2",ry:"2",key:"1yt0o3"}],["path",{d:"M12 18h.01",key:"mhygvu"}]],Ie=w("smartphone",dr);var nr=[["rect",{width:"18",height:"18",x:"3",y:"3",rx:"2",key:"afitv7"}]],Re=w("square",nr);var ur=[["circle",{cx:"12",cy:"12",r:"4",key:"4exip2"}],["path",{d:"M12 2v2",key:"tus03m"}],["path",{d:"M12 20v2",key:"1lh1kg"}],["path",{d:"m4.93 4.93 1.41 1.41",key:"149t6j"}],["path",{d:"m17.66 17.66 1.41 1.41",key:"ptbguv"}],["path",{d:"M2 12h2",key:"1t8f8n"}],["path",{d:"M20 12h2",key:"1q8mjw"}],["path",{d:"m6.34 17.66-1.41 1.41",key:"1m8zz5"}],["path",{d:"m19.07 4.93-1.41 1.41",key:"1shlcs"}]],Fe=w("sun",ur);var ir=[["path",{d:"M12 4v16",key:"1654pz"}],["path",{d:"M4 7V5a1 1 0 0 1 1-1h14a1 1 0 0 1 1 1v2",key:"e0r10z"}],["path",{d:"M9 20h6",key:"s66wpe"}]],Ee=w("type",ir);var fr=[["path",{d:"M18 6 6 18",key:"1bl5f8"}],["path",{d:"m6 6 12 12",key:"d8bk6v"}]],Q=w("x",fr);function cr(e,a){let t=o=>a(o==="hub"?"versions.hubName":"versions.agentName");return e.status==="starting"?a("panel.startingHost"):e.status!=="installing"?e.message??"":e.tool&&e.toVersion?e.fromVersion?a("panel.updatingTool",{tool:t(e.tool),from:e.fromVersion,to:e.toVersion}):a("panel.installingTool",{tool:t(e.tool),to:e.toVersion}):a("panel.installing")}function Sa(){let{t:e}=D();return a=>cr(a,e)}function Ot(e){let{t:a}=D(),t=Sa(),[o,l]=g(!1),d=e.detail;return!d||d.status==="ready"||d.status==="idle"?null:d.status==="failed"?f("div",{role:"alert",className:"flex items-start gap-2 border-b bg-destructive/5 px-3 py-2 text-xs",children:[f("div",{className:"min-w-0 flex-1 space-y-0.5",children:[r("p",{className:"font-medium text-destructive-foreground",children:a("panel.hostFailed")}),d.message?r("p",{className:"whitespace-pre-wrap break-words text-muted-foreground",children:d.message}):null]}),f(S,{size:"xs",variant:"outline",disabled:o,onClick:()=>{l(!0),e.onRetry().finally(()=>l(!1))},children:[o?r(z,{size:"xs"}):r(Be,{}),a(o?"panel.retrying":"panel.retry")]})]}):f("div",{role:"status",className:"flex items-center gap-2 border-b px-3 py-2 text-xs text-muted-foreground",children:[r(z,{size:"xs"}),r("span",{className:"min-w-0 flex-1",children:t(d)})]})}var va=["hub","agent"],ya=e=>e!==void 0&&!e.installedVersions.includes(e.requiredVersion);function Ut(e){let{t:a}=D(),t=te(),o=O(),[l,d]=g(null),[s,n]=g(null),[u,i]=g(!1),c=e.host?.tools,L=e.busy||l!==null,v=p=>{d(p),n(null),i(!1),(p==="check"?t("inspect",e.environmentId):t("updateTool",e.environmentId,{tool:p})).then(()=>i(p==="check")).catch(()=>{n(a(p==="check"?"versions.checkFailed":"versions.updateFailed")),p!=="check"&&o.notify(a("versions.updateFailed"),"error")}).finally(()=>d(null))},C=p=>p??a("versions.none");return f(Ja,{children:[f(Qa,{render:r(S,{size:"xs",variant:"ghost","aria-label":a("versions.title")}),children:[r(De,{}),a("versions.title"),va.some(p=>ya(c?.[p]))?r("span",{className:"size-1.5 rounded-full bg-warning","aria-hidden":!0}):null]}),r(Ya,{side:"bottom",align:"start",className:"w-80",children:f("div",{className:"space-y-3 text-xs",children:[va.map(p=>{let h=c?.[p];return f("section",{className:"space-y-1",children:[r("h4",{className:"font-medium text-foreground",children:a(p==="hub"?"versions.hubName":"versions.agentName")}),f("dl",{className:"grid grid-cols-[auto_1fr] gap-x-3 gap-y-0.5 text-muted-foreground",children:[r("dt",{children:a("versions.required")}),r("dd",{className:"font-mono",children:C(h?.requiredVersion)}),r("dt",{children:a("versions.installed")}),r("dd",{className:"font-mono",children:h&&h.installedVersions.length>0?h.installedVersions.join(", "):a("versions.none")}),r("dt",{children:a("versions.running")}),r("dd",{className:"font-mono",children:C(h?.runningVersion)})]}),ya(h)?f(S,{size:"xs",variant:"outline",disabled:L,onClick:()=>v(p),children:[l===p?r(z,{size:"xs"}):null,a("versions.updateTo",{version:h?.requiredVersion??""})]}):null]},p)}),c===void 0?r("p",{className:"text-muted-foreground",children:a("versions.unknown")}):null,va.some(p=>ya(c?.[p]))?r("p",{className:"text-muted-foreground",children:a("versions.pendingPolicy")}):null,s?r("p",{role:"alert",className:"text-destructive-foreground",children:s}):null,f("div",{className:"flex items-center justify-between gap-2 border-t pt-2",children:[r("p",{role:"status",className:"text-muted-foreground",children:a(u?"versions.checked":"versions.checkHint")}),f(S,{size:"xs",variant:"ghost",disabled:L,onClick:()=>v("check"),children:[l==="check"?r(z,{size:"xs"}):null,a("versions.check")]})]})]})})]})}var wa=[{api:"35",name:"Android 15"},{api:"30",name:"Android 11"}],qt=wa[0].api;var Oe=e=>e>=1073741824?`${(e/1073741824).toFixed(2)} GB`:`${(e/1048576).toFixed(1)} MB`;function Ht(e){let{phase:a,receivedBytes:t,totalBytes:o,bytesPerSecond:l}=e,d=a==="download"&&t!==void 0&&o?{received:t,total:o}:null,s=d&&l?(d.total-d.received)/l:null;return{titleKey:`environment.stages.${a??"starting"}`,component:e.component??"",percent:d?Math.floor(d.received/d.total*100):null,transferred:d?{done:Oe(d.received),total:Oe(d.total)}:null,speed:d&&l?Oe(l):null,minutesLeft:s===null?null:Math.ceil(s/60),slow:s!==null&&s>1200}}var Nt=e=>e.source==="private"&&e.ready;function Vt(e){return e.supported?e.freeBytes!==null&&e.freeBytes<e.requiredFreeBytes?"environment.notEnoughSpace":null:e.reasonCode?`environment.reasons.${e.reasonCode}`:"environment.unsupported"}function Gt(e,a){return e.cacheBytes>0||a==="android"&&e.deviceDataBytes>0}function zt(e){let{t:a}=D(),t=Ht(e.progress),o=[t.transferred?a("environment.transferred",t.transferred):null,t.speed?a("environment.speed",{speed:t.speed}):null,t.minutesLeft===null?null:a("environment.timeLeft",{minutes:String(t.minutesLeft)})].filter(l=>l!==null);return f("div",{role:"status",className:"space-y-2",children:[f("p",{className:"flex items-center gap-2 font-medium text-foreground",children:[r(z,{size:"xs"}),a(t.titleKey,{component:t.component})]}),t.percent===null?null:r("div",{role:"progressbar","aria-valuemin":0,"aria-valuemax":100,"aria-valuenow":t.percent,className:"h-1.5 overflow-hidden rounded-full bg-muted",children:r("div",{className:"h-full rounded-full bg-primary",style:{width:`${t.percent}%`}})}),o.length>0?r("p",{children:o.join(" \xB7 ")}):null,t.slow?r("p",{className:"text-warning-foreground",children:a("environment.slowDownload")}):null,r("p",{children:a("environment.continues")}),r(S,{size:"sm",variant:"outline",disabled:e.cancelling,onClick:e.onCancel,children:a("environment.cancel")})]})}function _t(e){let{t:a}=D(),t=te(),o=O(),d=o.commands.useSubscription("environmentProgress",{},{environmentId:e.environmentId}).data,[s,n]=g(!1),[u,i]=g("android"),[c,L]=g(""),[v,C]=g(""),[p,h]=g(null),[T,m]=g(!1),[y,R]=g(!1),[F,_]=g(!1),[P,b]=g(null),[U,W]=g(!1),[fe,q]=g(!1),[K,$]=g(void 0),V=d?.status==="working",x=P!==null||V,H=d&&d.id!==K?d:null;B(()=>{(V||H?.status==="failed")&&n(!0),H?.status==="done"&&H.plan?.platform===u&&h(H.plan)},[H,u,V]);let I=()=>{h(null),m(!1),R(!1),_(!1),q(!1),$(d?.id)},k=async(M,mo={})=>{b(M),W(!1),q(!1),$(d?.id);try{let go=await t(M,e.environmentId,{platform:u,directory:c,version:v,...mo});M==="cleanupEnvironment"?h(await t("environmentPlan",e.environmentId,{platform:u,directory:c,version:v})):M!=="prepareEnvironment"&&h(go),q(M==="cleanupEnvironment")}catch{W(!0),o.notify(a("environment.failed"),"error")}finally{b(null)}},E=p?Vt(p):null,N=M=>M===null?a("environment.unknownSize"):Oe(M),de=p!==null&&Nt(p);return f(Xe,{open:s,onOpenChange:n,className:"w-full text-left",children:[r($e,{render:r(S,{variant:"outline",size:"sm",className:"w-full"}),children:a("environment.title")}),r(je,{children:f("div",{className:"space-y-3 rounded-md border p-3 text-xs",children:[V?r(zt,{progress:d,cancelling:P==="cancelEnvironment",onCancel:()=>{b("cancelEnvironment"),t("cancelEnvironment",e.environmentId,{}).catch(()=>{W(!0),o.notify(a("environment.failed"),"error")}).finally(()=>b(null))}}):f(Z,{children:[r("p",{children:a("environment.description")}),e.iosSupported?r("div",{className:"flex gap-2",children:["android","ios"].map(M=>r(S,{size:"sm",variant:u===M?"default":"outline",disabled:x,onClick:()=>{i(M),C(""),I()},children:a(M==="ios"?"panel.platformIos":"panel.platformAndroid")},M))}):null,f("label",{className:"block space-y-1",children:[r("span",{children:a("environment.directory")}),r(ae,{value:c,disabled:x,onChange:M=>{L(M.target.value),I()},placeholder:a("environment.defaultDirectory")})]}),r("p",{children:a("environment.directoryHint")}),u==="android"?f("div",{className:"space-y-1",children:[r("span",{children:a("environment.androidVersion")}),r("div",{className:"flex flex-wrap gap-2",children:wa.map(M=>r(S,{size:"sm",variant:(v||qt)===M.api?"default":"outline",disabled:x,onClick:()=>{C(M.api),I()},children:a("environment.androidVersionOption",{name:M.name,api:M.api})},M.api))})]}):f("label",{className:"block space-y-1",children:[r("span",{children:a("environment.iosVersion")}),r(ae,{value:v,disabled:x,onChange:M=>{C(M.target.value),I()},placeholder:a("environment.iosVersionPlaceholder")})]}),r(S,{size:"sm",variant:"outline",disabled:x,onClick:()=>{k("environmentPlan")},children:a("environment.inspect")}),p?f("div",{className:"space-y-2",children:[f("dl",{className:"grid grid-cols-[auto_1fr] gap-x-3 gap-y-1 break-all",children:[r("dt",{children:a("environment.source")}),r("dd",{children:a(`environment.sources.${p.source}`)}),r("dt",{children:a("environment.version")}),r("dd",{children:p.version||a("environment.versionRequired")}),r("dt",{children:a("environment.location")}),r("dd",{children:p.root}),p.existingSdkRoot?f(Z,{children:[r("dt",{children:a("environment.existingSdk")}),r("dd",{children:p.existingSdkRoot})]}):null,r("dt",{children:a("environment.download")}),r("dd",{children:p.downloadBytes===0?a("environment.nothingToDownload"):N(p.downloadBytes)}),r("dt",{children:a("environment.free")}),r("dd",{children:N(p.freeBytes)}),r("dt",{children:a("environment.required")}),r("dd",{children:N(p.requiredFreeBytes)})]}),p.source==="external"?r("p",{children:a("environment.external")}):null,p.reasonCode&&p.supported?r("p",{role:"status",children:a(`environment.reasons.${p.reasonCode}`)}):null,r("a",{className:"underline",href:p.guidanceUrl,target:"_blank",rel:"noreferrer",children:a("environment.guide")}),u==="ios"?r("p",{children:a("environment.appleOwnership")}):r("p",{children:a("environment.privateOwnership")}),de?r("p",{role:"status",className:"font-medium text-foreground",children:a("environment.ready")}):f(Z,{children:[r("ul",{children:p.licenses.map(M=>r("li",{children:r("a",{className:"underline",href:M.url,target:"_blank",rel:"noreferrer",children:a(u==="ios"?"environment.appleLicense":"environment.androidLicense")})},M.url))}),f("label",{className:"flex items-center gap-2",children:[r(pe,{checked:T,disabled:x,onCheckedChange:m}),r("span",{children:a("environment.acceptLicense")})]}),u==="ios"?f("label",{className:"flex items-center gap-2",children:[r(pe,{checked:y,disabled:x,onCheckedChange:R}),r("span",{children:a("environment.confirmApple")})]}):null,E?r("p",{role:"alert",className:"font-medium text-warning-foreground",children:a(E)}):null,r(S,{size:"sm",disabled:x||!p.supported||!T||u==="ios"&&(!y||!v)||p.freeBytes===null||p.freeBytes<p.requiredFreeBytes,onClick:()=>{k("prepareEnvironment",{acceptLicenses:T,confirmAppleInstall:y})},children:a("environment.prepare")})]}),Gt(p,u)?f("div",{className:"space-y-2 border-t pt-2",children:[r("p",{children:a("environment.retention")}),r(S,{size:"sm",variant:"outline",disabled:x||p.cacheBytes===0,onClick:()=>{k("cleanupEnvironment",{category:"cache",confirm:!0})},children:a("environment.cleanCache",{size:N(p.cacheBytes)})}),u==="android"?f(Z,{children:[r("p",{children:a("environment.deviceData",{size:N(p.deviceDataBytes)})}),f("label",{className:"flex items-center gap-2",children:[r(pe,{checked:F,disabled:x,onCheckedChange:_}),r("span",{children:a("environment.confirmData")})]}),r(S,{size:"sm",variant:"destructive",disabled:x||!F||p.deviceDataBytes===0,onClick:()=>{k("cleanupEnvironment",{category:"devices",confirm:F})},children:a("environment.cleanDevices")})]}):null]}):null]}):null]}),P!==null&&!V?f("p",{role:"status",className:"flex items-center gap-2",children:[r(z,{size:"xs"}),a("environment.working")]}):null,U?r("p",{role:"alert",className:"text-destructive-foreground",children:a("environment.failed")}):null,H?.status==="failed"?f("div",{role:"alert",className:"space-y-1 text-destructive-foreground",children:[r("p",{children:a("environment.prepareFailed")}),H.message?r("p",{className:"whitespace-pre-wrap break-words text-muted-foreground",children:H.message}):null]}):null,H?.status==="cancelled"?r("p",{role:"status",children:a("environment.cancelled")}):null,fe?r("p",{role:"status",children:a("environment.cleaned")}):null]})})]})}var Wt=["small","default","large","extra-large"],pr=e=>Wt.includes(e);function Kt(e){let{t:a}=D(),{handle:t,controls:o}=e,l=o.detail?.settings,d=!t?.inputConnected,s=l?.appearance==="dark"?"light":"dark",n=u=>a(u==="small"?"rail.textSmall":u==="default"?"rail.textDefault":u==="large"?"rail.textLarge":"rail.textExtraLarge");return r("aside",{"aria-label":a("rail.label"),className:"pointer-events-none absolute inset-y-0 right-0 z-10 flex w-14 flex-col items-center justify-center gap-2 overflow-y-auto py-3 pr-2",children:f("div",{className:"pointer-events-auto flex shrink-0 flex-col items-center gap-1 rounded-full border border-border/50 bg-background/80 p-2 shadow-sm",children:[r(le,{label:a("rail.home"),disabled:d,onClick:()=>t?.pressButton("home"),children:r(re,{})}),e.platform==="android"?f(Z,{children:[r(le,{label:a("rail.back"),disabled:d,onClick:()=>t?.pressButton("back"),children:r(ke,{})}),r(le,{label:a("rail.recents"),disabled:d,onClick:()=>t?.pressButton("recents"),children:r(Re,{})}),f(_e,{children:[r(Ke,{render:r(S,{size:"icon-sm",variant:"ghost","aria-label":a("rail.rotate"),disabled:o.disabled}),children:r(xe,{})}),f(We,{side:"left",children:[r(ve,{onClick:()=>{o.act({type:"setOrientation",value:"portrait"})},children:a("rail.portrait")}),r(ve,{onClick:()=>{o.act({type:"setOrientation",value:"landscape_left"})},children:a("rail.landscape")})]})]})]}):r(le,{label:a("rail.rotate"),disabled:d,onClick:()=>t?.rotate(),children:r(xe,{})}),r(mr,{}),r(le,{label:a(s==="dark"?"rail.toDark":"rail.toLight"),disabled:o.disabled||!l?.appearance,onClick:()=>{o.act({type:"setAppearance",value:s})},children:l?.appearance==="dark"?r(Fe,{}):r(Pe,{})}),f(_e,{children:[r(Ke,{render:r(S,{size:"icon-sm",variant:"ghost","aria-label":a("rail.textSize"),title:a("rail.textSize"),disabled:o.disabled||!l?.textSize}),children:r(Ee,{})}),r(We,{side:"left",children:r(Ka,{value:l?.textSize??"",onValueChange:u=>{pr(u)&&o.act({type:"setTextSize",value:u})},children:Wt.map(u=>r(Xa,{value:u,children:n(u)},u))})})]}),r(le,{label:a("rail.tools"),pressed:e.toolsOpen,onClick:e.onTools,children:r(Me,{})}),r(le,{label:e.screenshotPending?a("rail.capturing"):a("rail.screenshot"),disabled:!e.streaming||e.screenshotPending,onClick:e.onScreenshot,children:r(we,{})}),e.onFloat?r(le,{label:a("rail.float"),onClick:e.onFloat,children:r(Ae,{})}):null,f(_e,{children:[r(Ke,{render:r(S,{size:"icon-sm",variant:"ghost","aria-label":a("rail.more"),title:a("rail.more")}),children:r(oe,{})}),f(We,{side:"left",align:"end",children:[f(ve,{onClick:e.onClose,children:[r(Q,{}),a("rail.closePanel")]}),r(Wa,{}),f(ve,{variant:"destructive",onClick:e.onPowerOff,children:[r(Te,{}),a("rail.powerOff")]})]})]})]})})}function mr(){return r("div",{"aria-hidden":!0,className:"my-1 h-px w-5 shrink-0 bg-border/70"})}function le(e){return f(Ga,{children:[r(_a,{render:r(S,{size:"icon-sm",variant:e.pressed?"secondary":"ghost","aria-label":e.label,"aria-pressed":e.pressed,disabled:e.disabled,onClick:e.onClick}),children:e.children}),r(za,{side:"left",children:e.label})]})}var ba=(e,a)=>new ra("invalid-input",`Invalid ${e}: ${a}.`);var Xt=4096,$t=["light","dark"],jt=["small","default","large","extra-large"];var Zt=["clear","tinted"],Jt=["none","grayscale","red-green","green-red","blue-yellow"],Qt=["portrait","landscape_left","portrait_upside_down","landscape_right"],Yt=["camera","microphone","photos","contacts","calendar","reminders","location","notifications","motion","media-library","faceid"];var gr=e=>typeof e=="object"&&e!==null&&!Array.isArray(e);var eo=e=>{let a=typeof e=="string"?{aps:{alert:e}}:e;if(!gr(a))throw ba("push payload","expected a string or an object");let t;try{t=JSON.stringify(a)}catch{t=void 0}if(t===void 0)throw ba("push payload","could not be encoded as JSON");if(new TextEncoder().encode(t).length>Xt)throw ba("push payload",`larger than ${String(Xt)} bytes`);return t};var Lr=new Set(["setAppearance","setTextSize","setToggle","setLiquidGlass","setColorFilter","setLocation","clearLocation","setPermission","openUrl","launchApp","relaunchApp","terminateApp","sendPush"]),hr=new Set(["setAppearance","setTextSize","setToggle","setOrientation","setLocation","setPermission","openUrl","launchApp","relaunchApp","terminateApp"]),xr=new Set(["reduceMotion","increaseContrast","reduceTransparency","showBorders","voiceOver"]),Ir=new Set(["reduceMotion","networkEnabled"]),ka=(e,a)=>(e==="ios"?Lr:hr).has(a.type)?a.type==="setToggle"?(e==="ios"?xr:Ir).has(a.setting):!0:!1;function ie(e){return f("section",{className:"flex flex-col gap-2 border-b px-3 py-2.5",children:[r("h3",{className:"text-xs font-medium text-muted-foreground",children:e.title}),e.children]})}function se(e){return f("div",{className:"flex min-h-7 items-center justify-between gap-3",children:[r("span",{className:"shrink-0 text-xs text-muted-foreground",children:e.label}),r("div",{className:"flex min-w-0 items-center justify-end",children:e.children})]})}function Da(e){return r(se,{label:e.label,children:r(pe,{"aria-label":e.label,checked:e.checked??!1,disabled:e.disabled||e.checked===void 0,onCheckedChange:a=>{e.onChange(a)}})})}function Pa(e){return r(ja,{"aria-label":e.label,variant:"outline",value:e.value===void 0?[]:[e.value],disabled:e.disabled||e.value===void 0,onValueChange:a=>{let t=e.options.find(o=>o.value===a[0]);t&&e.onChange(t.value)},children:e.options.map(a=>r(Za,{size:"xs",value:a.value,children:a.label},a.value))})}function Ue(e){let a=e.options.find(t=>t.value===e.value);return f(ca,{value:e.value,disabled:e.disabled,onValueChange:t=>{let o=e.options.find(l=>l.value===t);o&&o.value!==e.value&&e.onChange(o.value)},children:[r(pa,{size:"xs",className:e.width??"w-40","aria-label":e.ariaLabel,children:r(ma,{children:a?a.label:r("span",{className:"text-muted-foreground",children:e.placeholder})})}),r(ga,{align:"end",alignItemWithTrigger:!1,children:e.options.map(t=>r(La,{value:t.value,children:t.label},t.value))})]})}function Aa(e){let[a,t]=g(""),o=a.trim()||e.fallback||"",l=()=>{o&&e.onSubmit(o).then(()=>t(""))};return f("form",{className:"flex gap-1.5",onSubmit:d=>{d.preventDefault(),l()},children:[r(ae,{size:"compact",className:"min-w-0 flex-1 font-mono",placeholder:e.placeholder,"aria-label":e.placeholder,value:a,disabled:e.disabled,onChange:d=>t(d.target.value)}),r(S,{type:"submit",size:"xs",variant:"outline",disabled:e.disabled||!o,children:e.action})]})}var ao=[{key:"tools.location.sanFrancisco",latitude:37.7749,longitude:-122.4194},{key:"tools.location.newYork",latitude:40.7128,longitude:-74.006},{key:"tools.location.london",latitude:51.5074,longitude:-.1278},{key:"tools.location.stockholm",latitude:59.3293,longitude:18.0686},{key:"tools.location.tokyo",latitude:35.6762,longitude:139.6503}];function oo(e){let{t:a}=D(),[t,o]=g(e.current?String(e.current.latitude):""),[l,d]=g(e.current?String(e.current.longitude):""),s={latitude:Number(t),longitude:Number(l)},n=t.trim()!==""&&l.trim()!==""&&Math.abs(s.latitude)<=90&&Math.abs(s.longitude)<=180,u=(i,c)=>e.act({type:"setLocation",latitude:i,longitude:c});return f(ie,{title:a("tools.location.title"),children:[f("div",{className:"flex gap-1.5",children:[r(ae,{size:"compact",className:"min-w-0 flex-1 font-mono",placeholder:a("tools.location.latitude"),"aria-label":a("tools.location.latitude"),inputMode:"decimal",value:t,disabled:e.disabled,onChange:i=>o(i.target.value)}),r(ae,{size:"compact",className:"min-w-0 flex-1 font-mono",placeholder:a("tools.location.longitude"),"aria-label":a("tools.location.longitude"),inputMode:"decimal",value:l,disabled:e.disabled,onChange:i=>d(i.target.value)})]}),f("div",{className:"flex flex-wrap items-center gap-1.5",children:[f(ca,{value:null,disabled:e.disabled,onValueChange:i=>{let c=ao.find(L=>L.key===i);c&&(o(String(c.latitude)),d(String(c.longitude)),u(c.latitude,c.longitude))},children:[r(pa,{size:"xs",className:"w-32","aria-label":a("tools.location.preset"),children:r(ma,{children:r("span",{className:"text-muted-foreground",children:a("tools.location.presetPlaceholder")})})}),r(ga,{align:"start",alignItemWithTrigger:!1,children:ao.map(i=>r(La,{value:i.key,children:a(i.key)},i.key))})]}),r(S,{size:"xs",variant:"outline",disabled:e.disabled||!n,onClick:()=>{u(s.latitude,s.longitude)},children:a("tools.location.set")}),e.canClear?r(S,{size:"xs",variant:"ghost",disabled:e.disabled,onClick:()=>{o(""),d(""),e.act({type:"clearLocation"})},children:a("tools.location.clear")}):null]}),e.current?r("p",{role:"status",className:"text-xs text-muted-foreground",children:a("tools.location.current",{latitude:e.current.latitude,longitude:e.current.longitude})}):null]})}var Cr={camera:"tools.permissions.camera",microphone:"tools.permissions.microphone",photos:"tools.permissions.photos",contacts:"tools.permissions.contacts",calendar:"tools.permissions.calendar",reminders:"tools.permissions.reminders",location:"tools.permissions.location",notifications:"tools.permissions.notifications",motion:"tools.permissions.motion","media-library":"tools.permissions.mediaLibrary",faceid:"tools.permissions.faceId"},Sr=new Set(["camera","microphone","photos","contacts","calendar","location","notifications","motion"]);function ro(e){let{t:a}=D(),t=e.platform==="ios",[o,l]=g(""),[d,s]=g("camera"),n=o.trim()||e.defaultAppId,u=Yt.filter(c=>t||Sr.has(c)).map(c=>({value:c,label:a(!t&&c==="motion"?"tools.permissions.activity":Cr[c])})),i=c=>{e.act({type:"setPermission",appId:n,permission:d,decision:c})};return f(ie,{title:a("tools.permissions.title"),children:[r(ae,{size:"compact",className:"font-mono",placeholder:e.defaultAppId||a("tools.permissions.appId"),"aria-label":a("tools.permissions.appId"),value:o,disabled:e.disabled,onChange:c=>l(c.target.value)}),f("div",{className:"flex flex-wrap items-center gap-1.5",children:[r(Ue,{ariaLabel:a("tools.permissions.permission"),value:d,options:u,placeholder:a("tools.unknown"),disabled:e.disabled,onChange:c=>(s(c),Promise.resolve())}),r(S,{size:"xs",variant:"outline",disabled:e.disabled||!n,onClick:()=>i("grant"),children:a("tools.permissions.grant")}),r(S,{size:"xs",variant:"outline",disabled:e.disabled||!n,onClick:()=>i("revoke"),children:a("tools.permissions.revoke")}),t?r(S,{size:"xs",variant:"ghost",disabled:e.disabled||!n,onClick:()=>i("reset"),children:a("tools.permissions.reset")}):null]})]})}var vr=e=>{let a=e;try{let t=JSON.parse(e);typeof t=="object"&&t!==null&&!Array.isArray(t)&&(a=t)}catch{}try{return eo(a),a}catch{return null}};function lo(e){let{t:a}=D(),[t,o]=g(""),l=t.trim(),d=l?vr(l):null,s=e.appId;return f(ie,{title:a("tools.push.title"),children:[r($a,{size:"sm",rows:4,className:"font-mono",placeholder:a("tools.push.placeholder"),"aria-label":a("tools.push.placeholder"),value:t,disabled:e.disabled||!s,onChange:n=>o(n.target.value)}),f("div",{className:"flex items-center gap-2",children:[r(S,{size:"xs",variant:"outline",disabled:e.disabled||!s||d===null,onClick:()=>{s&&d!==null&&e.act({type:"sendPush",appId:s,payload:d})},children:a("tools.push.send")}),s?l&&d===null?r("p",{className:"text-xs text-destructive-foreground",children:a("tools.push.invalid")}):null:r("p",{className:"text-xs text-muted-foreground",children:a("tools.push.needsApp")})]})]})}var to=100;function so(e){let{t:a}=D(),[t,o]=g(!1),[l,d]=g([]),{transport:s,platform:n,deviceId:u}=e;return B(()=>{if(!t)return;let i=dt({transport:s,platform:n,deviceId:u},(c,L)=>{d(v=>{let C=L?[...c]:[...v,...c];return C.length>to?C.slice(-to):C})});return()=>{i(),d([])}},[t,s,n,u]),f(Xe,{open:t,onOpenChange:o,children:[f($e,{className:"flex w-full items-center gap-1.5 border-b px-3 py-2.5 text-left text-xs font-medium text-muted-foreground",children:[a("tools.eventLog.title"),r(be,{className:`ml-auto size-3.5 transition-transform ${t?"rotate-180":""}`})]}),r(je,{children:r("ol",{className:"max-h-64 overflow-y-auto px-3 py-2 font-mono text-ui-2xs leading-relaxed",children:l.length===0?r("li",{className:"text-muted-foreground",children:a("tools.eventLog.empty")}):l.map(i=>f("li",{className:"flex gap-2",children:[r("span",{className:"shrink-0 text-muted-foreground",children:i.timestamp.slice(11,19)}),r("span",{className:"truncate",children:i.summary})]},i.id))})})]})}var yr=640,wr={light:"tools.settings.light",dark:"tools.settings.dark"},br={small:"tools.settings.textSmall",default:"tools.settings.textDefault",large:"tools.settings.textLarge","extra-large":"tools.settings.textExtraLarge"},kr={clear:"tools.settings.glassClear",tinted:"tools.settings.glassTinted"},Dr={none:"tools.settings.filterNone",grayscale:"tools.settings.filterGrayscale","red-green":"tools.settings.filterRedGreen","green-red":"tools.settings.filterGreenRed","blue-yellow":"tools.settings.filterBlueYellow"},Pr={portrait:"tools.settings.orientationPortrait",landscape_left:"tools.settings.orientationLandscapeLeft",portrait_upside_down:"tools.settings.orientationUpsideDown",landscape_right:"tools.settings.orientationLandscapeRight"},Ar=[{setting:"reduceMotion",labelKey:"tools.settings.reduceMotion"},{setting:"increaseContrast",labelKey:"tools.settings.increaseContrast"},{setting:"reduceTransparency",labelKey:"tools.settings.reduceTransparency"},{setting:"showBorders",labelKey:"tools.settings.showBorders"},{setting:"voiceOver",labelKey:"tools.settings.voiceOver"},{setting:"networkEnabled",labelKey:"tools.settings.network"}];function no(e){let{t:a}=D(),{device:t,controls:o}=e,{detail:l,pending:d,error:s,foregroundApp:n,disabled:u,act:i}=o,c=l?.settings,L=t.platform==="ios",v=G(null),[C,p]=g(!0);Fa(()=>{let m=v.current?.parentElement;if(!m)return;let y=()=>p(m.clientWidth<yr);y();let R=new ResizeObserver(y);return R.observe(m),()=>R.disconnect()},[]),B(()=>o.followDevice(),[o.followDevice]);let h=jt.map(m=>({value:m,label:a(br[m])})),T=Ar.filter(m=>ka(t.platform,{type:"setToggle",setting:m.setting,value:!0}));return f("aside",{ref:v,"aria-label":a("tools.title"),className:`flex min-h-0 flex-col border-l bg-background text-sm ${C?"absolute inset-y-0 right-0 z-10 w-full max-w-72 shadow-lg":"w-72 shrink-0"}`,children:[f("div",{className:"flex h-9 shrink-0 items-center gap-2 border-b px-3",children:[r("span",{className:"font-medium",children:a("tools.title")}),d?r(z,{size:"sm"}):null,r(S,{size:"icon-xs",variant:"ghost-muted","aria-label":a("tools.close"),className:"ml-auto",onClick:e.onClose,children:r(Q,{})})]}),f("div",{className:"min-h-0 flex-1 overflow-y-auto",children:[s?r("p",{role:"alert",className:"border-b bg-destructive/10 px-3 py-2 text-xs text-destructive-foreground",children:s}):null,l===null&&!s?f("div",{className:"flex items-center gap-2 px-3 py-3 text-xs text-muted-foreground",children:[r(z,{size:"sm"}),a("tools.reading")]}):null,f(ie,{title:a("tools.app.title"),children:[r(se,{label:a("tools.app.foreground"),children:r("span",{className:"truncate font-mono text-xs",children:n?.id??a("tools.app.none")})}),n?f("div",{className:"flex gap-1.5",children:[r(S,{size:"xs",variant:"outline",disabled:u,onClick:()=>{i({type:"terminateApp",appId:n.id})},children:a("tools.app.terminate")}),r(S,{size:"xs",variant:"outline",disabled:u,onClick:()=>{i({type:"relaunchApp",appId:n.id})},children:a("tools.app.relaunch")})]}):null,r(Aa,{placeholder:a("tools.app.urlPlaceholder"),action:a("tools.app.open"),disabled:u,onSubmit:m=>i({type:"openUrl",url:m})}),r(Aa,{placeholder:a(L?"tools.app.bundleIdPlaceholder":"tools.app.packagePlaceholder"),action:a("tools.app.launch"),disabled:u,fallback:n?.id,onSubmit:m=>i({type:"launchApp",appId:m})})]}),f(ie,{title:a(L?"tools.settings.titleIos":"tools.settings.titleAndroid"),children:[r(se,{label:a("tools.settings.appearance"),children:r(Pa,{label:a("tools.settings.appearance"),value:c?.appearance,options:$t.map(m=>({value:m,label:a(wr[m])})),disabled:u,onChange:m=>i({type:"setAppearance",value:m})})}),r(se,{label:a("tools.settings.textSize"),children:r(Ue,{ariaLabel:a("tools.settings.textSize"),value:c?.textSize??null,options:h,placeholder:a("tools.unknown"),disabled:u,onChange:m=>i({type:"setTextSize",value:m})})}),L?f(Z,{children:[r(se,{label:a("tools.settings.liquidGlass"),children:r(Pa,{label:a("tools.settings.liquidGlass"),value:c?.liquidGlass,options:Zt.map(m=>({value:m,label:a(kr[m])})),disabled:u,onChange:m=>i({type:"setLiquidGlass",value:m})})}),r(se,{label:a("tools.settings.colorFilter"),children:r(Ue,{ariaLabel:a("tools.settings.colorFilter"),value:c?.colorFilter??null,options:Jt.map(m=>({value:m,label:a(Dr[m])})),placeholder:a("tools.unknown"),disabled:u,onChange:m=>i({type:"setColorFilter",value:m})})})]}):r(se,{label:a("tools.settings.orientation"),children:r(Ue,{ariaLabel:a("tools.settings.orientation"),value:null,options:Qt.map(m=>({value:m,label:a(Pr[m])})),placeholder:a("tools.settings.rotateTo"),disabled:u,onChange:m=>i({type:"setOrientation",value:m})})}),T.map(m=>r(Da,{label:a(m.labelKey),checked:c?.[m.setting],disabled:u,onChange:y=>i({type:"setToggle",setting:m.setting,value:y})},m.setting))]}),r(ie,{title:a("tools.accessibility.title"),children:r(Da,{label:a("tools.accessibility.overlay"),checked:e.axOverlay,disabled:!1,onChange:m=>(e.onAxOverlayChange(m),Promise.resolve())})}),r(oo,{current:o.location,canClear:ka(t.platform,{type:"clearLocation"}),disabled:u,act:i}),r(ro,{platform:t.platform,defaultAppId:n?.id??"",disabled:u,act:i}),L?r(lo,{appId:n?.id,disabled:u,act:i}):null,L?r(so,{transport:e.transport,platform:t.platform,deviceId:t.id}):null]})]})}var Tr=2e4,Ta=class extends Error{status;constructor(a){super(`Screenshot capture failed (${a}). Try again.`),this.status=a}};async function uo(e,a,t,o){let l=AbortSignal.timeout(Tr),d=await e.fetch(`${me(a)}/api/screenshot?device=${encodeURIComponent(t)}`,{method:"POST",signal:o?AbortSignal.any([o,l]):l});if(!d.ok)throw new Ta(d.status);let s=await d.blob();if(!s.size)throw new Error("The device returned an empty screenshot. Try again.");return s.type?s:new Blob([s],{type:"image/png"})}var Br=3e3,Ba=e=>e instanceof Error?e.message:String(e);function io(e){let{environmentId:a,device:t}=e,o=te(),l=O(),{t:d}=D(),[s,n]=g(null),[u,i]=g(null),[c,L]=g(!1),[v,C]=g(null),p=G(!1),h=G(0),T=G(!1),m={hostId:t.hostId,deviceId:t.id},y=P=>o("detail",a,m).then(b=>{h.current===P&&(n(b),C(null))},b=>{h.current===P&&(n(null),C(Ba(b)))});B(()=>{let P=++h.current;return y(P),()=>{h.current++}},[a,t.hostId,t.id]);let R=async P=>{if(p.current||s===null)return!1;p.current=!0;let b=++h.current;L(!0),C(null);try{let U=await o("action",a,{...m,...P});return h.current===b?n(U):await y(++h.current),P.type==="setLocation"?i({latitude:P.latitude,longitude:P.longitude}):P.type==="clearLocation"&&i(null),!0}catch(U){return h.current===b&&C(Ba(U)),l.notify(d("rail.actionFailed"),"error",Ba(U)),!1}finally{p.current=!1,L(!1)}},F=G(()=>{});F.current=()=>{if(p.current||T.current)return;T.current=!0;let P=++h.current;o("detail",a,m).then(b=>{h.current===P&&n(b)},()=>{}).finally(()=>{T.current=!1})};let _=Y(()=>{F.current();let P=setInterval(()=>F.current(),Br);return()=>clearInterval(P)},[]);return{detail:s,location:u,pending:c,error:v,act:R,followDevice:_,disabled:c||s===null,foregroundApp:e.foreground===void 0?s?.foregroundApp??null:e.foreground}}var Mr=()=>typeof window<"u"&&"ReactNativeWebView"in window;function fo(e){let{t:a}=D(),t=O(),o=la(e.environmentId),[l,d]=g(null),[s,n]=g(!1),[u,i]=g(!1),[c,L]=g(!1),[v,C]=g(),[p,h]=g(!1),[T,m]=g(null),[y,R]=g(null),F=G(null),_=G(null),P=o.status==="ready"?o.transport:null,b=io({environmentId:e.environmentId,device:e.device,foreground:v}),U=Y(q=>d(q),[]),W=Y(q=>n(q),[]);B(()=>{if(!P)return;let q=st({transport:P,platform:e.device.platform,deviceId:e.device.id},C);return()=>{q(),C(void 0)}},[e.device.id,e.device.platform,P]),B(()=>()=>{F.current?.abort(),_.current&&URL.revokeObjectURL(_.current)},[]);let fe=()=>{if(!P||F.current)return;let q=new AbortController;F.current=q,h(!0),m(null),uo(P,e.device.platform,e.device.id,q.signal).then(K=>{if(q.signal.aborted)return;_.current&&URL.revokeObjectURL(_.current);let $=URL.createObjectURL(K);if(_.current=$,Mr()){R($);return}let V=document.createElement("a");V.href=$,V.download=`${e.device.name.replace(/[^a-z0-9-]/gi,"-")}-${Date.now()}.png`,document.body.append(V),V.click(),V.remove()}).catch(K=>{q.signal.aborted||(m(K instanceof Error?K.message:a("workspace.screenshotFailed")),t.notify(a("workspace.screenshotFailed"),"error",K instanceof Error?K.message:void 0))}).finally(()=>{F.current===q&&(F.current=null,h(!1))})};return o.status!=="ready"?r(ee,{name:e.device.name,description:e.device.version,stage:o.status==="failed"?"error":"connecting",message:o.status==="failed"?o.message??a("workspace.needsNewerApp"):a("stream.connecting"),children:r(S,{size:"sm",variant:"outline",onClick:e.onBack,children:a("workspace.allDevices")})}):f("div",{className:"relative flex min-h-0 min-w-0 flex-1",children:[f("div",{className:"relative flex min-h-0 min-w-0 flex-1 flex-col",children:[T||b.error&&!u?r("p",{role:"alert",className:"px-3 py-2 text-xs text-destructive-foreground",children:T??b.error}):null,f("div",{className:"relative min-h-0 flex-1",children:[r(oa,{transport:o.transport,platform:e.device.platform,deviceId:e.device.id,deviceName:e.device.name,deviceDescription:e.device.version,axOverlay:c,withControls:!0,onHandle:U,onStreaming:W}),r(Kt,{platform:e.device.platform,handle:l,streaming:s,controls:b,screenshotPending:p,onScreenshot:fe,toolsOpen:u,onTools:()=>i(!u),onClose:e.onClose,onPowerOff:e.onPowerOff,onFloat:e.onFloat})]})]}),u?r(no,{device:e.device,controls:b,transport:o.transport,axOverlay:c,onAxOverlayChange:L,onClose:()=>i(!1)}):null,y?f("div",{className:"absolute inset-0 z-20 flex flex-col items-center justify-center gap-3 bg-background/95 p-4",children:[r("img",{src:y,alt:a("workspace.screenshotAlt"),className:"max-h-[80%] max-w-full object-contain"}),r("p",{className:"text-xs text-muted-foreground",children:a("workspace.screenshotSaveHint")}),f(S,{size:"sm",variant:"outline",onClick:()=>R(null),children:[r(Q,{}),a("workspace.closeBrowser")]})]}):null]})}var Ce=e=>e instanceof Error?e.message:String(e);function co(e){let{environmentId:a,threadId:t}=e,{t:o}=D(),{state:l,loaded:d,error:s,unavailable:n}=Le(a),u=te(),[i,c]=g(null),[L,v]=g(null),C=Na(a,t),p=x=>Ge(a,t,x),h=O(),T=ce(h,"floating"),m=()=>{c(null),u("refresh",a).catch(x=>{c(Ce(x)),h.notify(o("panel.refreshFailed"),"error",Ce(x))})};B(()=>{!d||n||u("refresh",a).catch(()=>{})},[a,d,u,n]);let y=ue(()=>l.sessions.filter(x=>x.threadId===t),[l.sessions,t]),R=Fr(y,C),F=R?l.devices.find(x=>x.hostId===R.hostId&&x.id===R.deviceId):void 0,_=F&&R?Se(F):null;B(()=>{h.floating?.present({environmentId:a,threadId:t},_)}),B(()=>()=>h.floating?.present({environmentId:a,threadId:t},null),[h,a,t]);let P=ue(()=>Er(l),[l]),b=l.hostStatuses[he],U=b?.status==="ready",W=b?.status==="installing"||b?.status==="starting",fe=Sa(),q=l.bootingDevices.filter(x=>x.threadId===t),K=l.hosts.flatMap(x=>x.platforms.filter(H=>!H.available)),$=async x=>{c(null),v(x),fa(a,t,j(x));try{await u("open",a,{threadId:t,hostId:x.hostId,deviceId:x.id,platform:x.platform}),p(j(x))}catch(H){fa(a,t,j(x),!1),c(Ce(H)),h.notify(o("panel.openFailed"),"error",Ce(H))}finally{v(null)}},V=x=>{R&&(c(null),u("close",a,{threadId:t,hostId:R.hostId,deviceId:R.deviceId,shutdown:x}).then(()=>p(null)).catch(H=>{c(Ce(H)),h.notify(o("panel.closeFailed"),"error",Ce(H))}))};return n?r(ee,{name:o("panel.title"),stage:"error",message:o("panel.unavailable")}):f("div",{className:"flex size-full min-h-0 flex-col",children:[q.length>0?r("div",{role:"status",className:"border-b px-3 py-2 text-xs text-muted-foreground",children:o("panel.booting",{names:q.map(x=>x.name).join(", ")})}):null,W&&!F?null:r(Ot,{detail:b,onRetry:()=>u("refresh",a).catch(()=>{})}),i||s?f("div",{role:"alert",className:"flex items-start gap-2 border-b bg-destructive/5 px-3 py-2 text-xs text-destructive-foreground",children:[r("p",{className:"min-w-0 flex-1 whitespace-pre-wrap break-words",children:i??s}),i?r(S,{size:"icon-xs",variant:"ghost","aria-label":o("panel.dismissError"),onClick:()=>c(null),children:r(Q,{className:"size-3"})}):null]}):null,r("div",{className:"relative flex min-h-0 flex-1",children:F&&R?r(fo,{environmentId:a,device:F,onBack:()=>p(""),onFloat:T?()=>h.floating?.open({environmentId:a,threadId:t},{...Se(F),reason:"user"}):void 0,onPowerOff:()=>V(!0),onClose:()=>V(!1)},`${a}\0${j(F)}`):L||W||!d?r(ee,{name:L?.name??o("panel.title"),...L?{description:L.version}:{},stage:"opening",message:L?L.booted?o("panel.opening"):o("panel.starting"):W&&b?fe(b):o("panel.finding")}):r(Rr,{environmentId:a,host:l.hosts.find(x=>x.id===he),grouped:P,hostReady:U,hostFailed:b?.status==="failed",unavailableReasons:K,showNoAvdHint:U&&!l.devices.some(x=>x.platform==="android")&&!K.some(x=>x.platform==="android"),pendingKey:L?j(L):null,onOpen:x=>{$(x)},onRefresh:m})})]})}function Rr(e){let{t:a}=D(),t=e.grouped.length===0;return r("div",{className:"flex size-full flex-col overflow-y-auto px-4 py-6 text-sm text-muted-foreground",children:f("div",{className:`mx-auto flex w-full max-w-xl flex-col gap-5 ${t?"items-center text-center":""}`,children:[r(_t,{environmentId:e.environmentId,iosSupported:!e.unavailableReasons.some(o=>o.reasonCode==="ios-needs-macos")},e.environmentId),t?f(Z,{children:[r(Ie,{className:"size-6 opacity-60"}),r("p",{className:"max-w-sm",children:e.hostFailed?a("panel.hubFailed"):a("panel.empty")})]}):null,e.hostReady?e.grouped.map(o=>f("section",{className:"w-full space-y-2 text-left",children:[f("h3",{className:"flex items-center gap-2 font-medium",children:[r(Ie,{className:"size-4 shrink-0"}),o.platform==="ios"?a("panel.platformIos"):a("panel.platformAndroid")]}),r("ul",{className:"divide-y rounded-md border",children:o.devices.map(l=>r("li",{children:f(S,{variant:"ghost",className:"h-auto min-h-11 w-full justify-between gap-3 rounded-none px-3 py-2 text-left font-normal",disabled:e.pendingKey!==null,onClick:()=>e.onOpen(l),children:[f("span",{className:"min-w-0 flex-1",children:[r("span",{className:"block truncate text-foreground",children:l.name}),f("span",{className:"block text-xs",children:[l.version,","," ",l.booted?a("panel.running"):a("panel.stopped")]})]}),e.pendingKey===j(l)?r(z,{size:"xs"}):r("span",{className:"text-xs",children:l.booted?a("panel.open"):a("panel.start")})]})},j(l)))})]},o.platform)):null,e.unavailableReasons.map(o=>r("p",{className:"max-w-sm text-xs",children:o.reasonCode?a(`unavailable.${o.reasonCode}`,{root:o.sdkRoot??""}):o.reason},`${o.platform}:${o.reasonCode}`)),e.showNoAvdHint?r("p",{className:"max-w-sm text-xs",children:a("panel.noAvd")}):null,f("div",{className:`flex flex-wrap items-center gap-2 ${t?"self-center":"self-start"}`,children:[r(S,{variant:t?"outline":"ghost",size:"sm",onClick:e.onRefresh,children:a("panel.refresh")}),r(Ut,{environmentId:e.environmentId,host:e.host,busy:!1})]})]})})}function Fr(e,a){if(a!==""){if(a!==null){let t=e.find(o=>j({hostId:o.hostId,id:o.deviceId})===a);if(t)return t}return e.toSorted((t,o)=>o.openedAt.localeCompare(t.openedAt))[0]}}function Er(e){let a=[];for(let t of["ios","android"]){let o=e.devices.filter(l=>l.platform===t).toSorted((l,d)=>Number(d.booted)-Number(l.booted)||l.name.localeCompare(d.name));o.length>0&&a.push({platform:t,devices:o})}return a}function po({environmentId:e,threadId:a}){let t=O(),{state:o,loaded:l}=Le(e),d=G(null);return B(()=>{if(!l||!ce(t,"floating"))return;let s=`${e}\0${a}`,n=d.current?.key===s?d.current.seen:null,{seen:u,opened:i}=Va({environmentId:e,threadId:a,previous:n,sessions:o.sessions,devices:o.devices});d.current={key:s,seen:u};for(let c of i)t.floating?.open({environmentId:e,threadId:a},{...Se(c),reason:"agent",panelId:Ne})},[t,e,l,o.devices,o.sessions,a]),null}function Or(e){return{panels:{device:function(t){return f(He,{value:e,children:[r("style",{children:da}),r("div",{className:`${ze} flex h-full min-h-0 flex-1 flex-col`,children:r(co,{environmentId:t.environmentId,threadId:t.threadId})})]})}},views:{deviceFloat:function(t){return f(He,{value:e,children:[r("style",{children:da}),r("div",{className:`${ze} relative size-full`,children:r(Tt,{...t})})]})},deviceSessions:function(t){return r(He,{value:e,children:r(po,{environmentId:t.environmentId,threadId:t.threadId})})}}}}export{Or as default};
|
|
563
|
+
`),id:this.lastId}:void 0;return this.data=[],this.eventName="",d}if(a.startsWith(":"))return;let t=a.indexOf(":"),o=t===-1?a:a.slice(0,t),l=t===-1?"":a.slice(t+1);l.startsWith(" ")&&(l=l.slice(1)),o==="data"?this.data.push(l):o==="event"?this.eventName=l:o==="id"&&!l.includes("\0")&&(this.lastId=l)}};async function Je(e,a,t){let o=e.body;if(!o)throw new Error("The response has no body to stream.");let l=o.getReader(),d=()=>{l.cancel().catch(()=>{})};if(t?.aborted)return d();t?.addEventListener("abort",d,{once:!0});try{for(;;){let{done:s,value:n}=await l.read();if(s||t?.aborted)return;a(n)}}catch(s){if(t?.aborted)return;throw s}finally{t?.removeEventListener("abort",d)}}function Qe(e,a,t){let o=e;if(a+t.length>e.length){let l=e.length;for(;l<a+t.length;)l*=2;o=new Uint8Array(l),o.set(e.subarray(0,a))}return o.set(t,a),o}async function tt(e,a,t){if(!e.ok)throw await e.body?.cancel().catch(()=>{}),new Error(`Event stream failed (${e.status}).`);let o=new Ze;await Je(e,l=>{for(let d of o.push(l))a(d)},t)}var me=e=>e==="ios"?"/vendor/serve-sim":"/vendor/serve-emu";var yo=1e3,wo=500,Ye=(e,a,t)=>`${me(e.platform)}${a}${t?`?${new URLSearchParams(t).toString()}`:""}`,ot=async(e,a,t)=>{let o=await e.transport.fetch(a,t?{signal:t}:void 0);if(!o.ok)throw new Error(`${o.status} ${o.statusText}`);return await o.json()},J=e=>typeof e=="object"&&e!==null,X=(e,a)=>typeof e=="number"&&Number.isFinite(e)?e:a,bo=e=>{let a=e[0],t=J(a)&&J(a.frame)?a.frame:null,o=Math.max(1,X(t?.width,1)),l=Math.max(1,X(t?.height,1)),d=[],s=(n,u)=>{if(d.length>=wo||!J(n)||!J(n.frame))return;let i=n.frame,c=X(i.width,0),L=X(i.height,0);!(Math.abs(c-o)<.5&&Math.abs(L-l)<.5)&&c>0&&L>0&&d.push({id:typeof n.AXUniqueId=="string"?n.AXUniqueId:u,label:typeof n.AXLabel=="string"?n.AXLabel:"",role:typeof n.type=="string"?n.type:"",x:X(i.x,0)/o,y:X(i.y,0)/l,width:c/o,height:L/l}),(Array.isArray(n.children)?n.children:[]).forEach((p,h)=>s(p,`${u}.${h}`))};return e.forEach((n,u)=>s(n,String(u))),d},rt=e=>J(e)&&typeof e.error=="string"?e.error:"Unexpected accessibility payload.";async function st(e,a){if(e.platform==="ios"){let u=await ot(e,Ye(e,`/helper/${encodeURIComponent(e.deviceId)}/ax`),a);return Array.isArray(u)?{elements:bo(u),errors:[]}:{elements:[],errors:[rt(u)]}}let t=await ot(e,Ye(e,"/api/accessibility",{device:e.deviceId}),a);if(!J(t)||!Array.isArray(t.nodes))return{elements:[],errors:[rt(t)]};let o=t.nodes.filter(u=>J(u)&&J(u.bounds)),l=o[0]?.bounds,d=Math.max(1,X(l?.right,1)),s=Math.max(1,X(l?.bottom,1));return{elements:o.slice(1).flatMap(u=>{let i=u.bounds,c=X(i.left,0),L=X(i.top,0),v=(X(i.right,c)-c)/d,C=(X(i.bottom,L)-L)/s,p=typeof u.text=="string"?u.text:"",h=typeof u.contentDescription=="string"?u.contentDescription:"",T=p||h;if(v>=.95&&C>=.9)return[];if(!T&&u.clickable!==!0)return[];let m=typeof u.className=="string"?u.className:"";return[{id:String(u.id??""),label:T,role:m.split(".").at(-1)??"",x:c/d,y:L/s,width:v,height:C}]}),errors:[]}}var dt=(e,a,t)=>{let o=new AbortController,l=null,d=()=>{e.transport.fetch(a,{signal:o.signal}).then(s=>tt(s,n=>{try{t(JSON.parse(n.data))}catch{}},o.signal)).catch(()=>{}).finally(()=>{o.signal.aborted||(l=setTimeout(d,yo))})};return d(),()=>{o.abort(),l!==null&&clearTimeout(l)}};function nt(e,a){return e.platform!=="ios"?()=>{}:dt(e,Ye(e,"/appstate",{device:e.deviceId}),t=>{if(J(t)){if(t.bundleId===null||t.bundleId===""){a(null);return}typeof t.bundleId=="string"&&a({id:t.bundleId,...typeof t.pid=="number"?{pid:t.pid}:{},...typeof t.isReactNative=="boolean"?{isReactNative:t.isReactNative}:{}})}})}var lt=e=>!J(e)||typeof e.id!="number"?null:{id:e.id,timestamp:typeof e.timestamp=="string"?e.timestamp:"",kind:typeof e.kind=="string"?e.kind:"",summary:typeof e.summary=="string"?e.summary:typeof e.msg=="string"?e.msg:""};function ut(e,a){return e.platform!=="ios"?()=>{}:dt(e,Ye(e,"/api/event-log/events",{device:e.deviceId,limit:"100"}),t=>{if(!J(t))return;if(Array.isArray(t.events)){a(t.events.flatMap(l=>lt(l)??[]),!0);return}let o=lt(t.event);o&&a([o],!1)})}function D(){return{t:E().i18n.usePluginTranslation()}}var ko=1397050709,xa=16,Do=1;function aa(e){if(e.length<4)return"avc1.42E01E";let a=t=>t.toString(16).padStart(2,"0");return`avc1.${a(e[1])}${a(e[2])}${a(e[3])}`}function it(e){let a=new Uint8Array(e);if(a.byteLength>xa){let t=new DataView(e,0,xa);if(t.getUint32(0,!1)===ko&&t.getUint8(4)===1){let o=t.getBigUint64(8,!1);return{data:a.subarray(xa),isKey:(t.getUint8(5)&Do)!==0,timestamp:o<=BigInt(Number.MAX_SAFE_INTEGER)?Number(o):null}}}return{data:a,isKey:null,timestamp:null}}var ft=e=>{try{return JSON.parse(e)?.type==="video-session"}catch{return!1}};function ct(e){let a=!1,t=null,o=e.length,l=0;for(;l+2<o;){if(e[l]===0&&e[l+1]===0){let d=0;if(e[l+2]===1?d=3:l+3<o&&e[l+2]===0&&e[l+3]===1&&(d=4),d){let s=e[l+d]&31;s===7&&!t&&(t=e.subarray(l+d)),s===5&&(a=!0),l+=d+1;continue}}l++}return{isKey:a,sps:t}}var Po={1:"description",2:"keyframe",3:"delta",4:"seed"},ea=class{buffer=new Uint8Array(64*1024);length=0;push(a){this.buffer=Qe(this.buffer,this.length,a),this.length+=a.length;let t=[],o=0;for(;this.length-o>=4;){let d=new DataView(this.buffer.buffer,this.buffer.byteOffset+o,4).getUint32(0,!1);if(this.length-o-4<d)break;if(d>=1){let s=Po[this.buffer[o+4]];s&&t.push({type:s,payload:this.buffer.slice(o+5,o+4+d)})}o+=4+d}return o>0&&(this.buffer.copyWithin(0,o,this.length),this.length-=o),t}reset(){this.length=0}};var Ao={Enter:40,Escape:41,Backspace:42,Tab:43,Space:44,Minus:45,Equal:46,BracketLeft:47,BracketRight:48,Backslash:49,Semicolon:51,Quote:52,Backquote:53,Comma:54,Period:55,Slash:56,Delete:76,ArrowRight:79,ArrowLeft:80,ArrowDown:81,ArrowUp:82,ControlLeft:224,ShiftLeft:225,AltLeft:226,MetaLeft:227,ControlRight:228,ShiftRight:229,AltRight:230,MetaRight:231};function pt(e){return/^Key[A-Z]$/.test(e)?4+(e.charCodeAt(3)-65):/^Digit[1-9]$/.test(e)?30+(e.charCodeAt(5)-49):e==="Digit0"?39:Ao[e]??null}var mt={ArrowUp:19,ArrowDown:20,ArrowLeft:21,ArrowRight:22,Tab:61,Enter:66,Backspace:67,Delete:112,Home:122,End:123,PageUp:92,PageDown:93};function Ia(e){if(e.stopped)return;let a=d=>{e.configuring=!1,e.connecting(d),e.scheduleRetry("input",()=>Ia(e))},t;try{t=e.transport.connect(`${e.vendor}/ws?device=${e.device}&frame-meta=1`)}catch(d){e.events.onInputConnected(!1,d.message),a(d.message);return}e.socket=t;let o=[],l=!1;t.onopen=()=>{e.stopped||e.socket!==t||(e.connecting(),e.events.onInputConnected(!0))},t.onmessage=d=>{if(e.stopped||e.socket!==t)return;if(typeof d.data=="string"){ft(d.data)&&(e.closeDecoder(),e.configuring=!1,o=[],l=!1,e.connecting());return}let s=it(d.data),n=!e.videoDecoder||e.videoDecoder.state!=="configured",i=s.isKey===null||s.isKey&&n?ct(s.data):null,c=s.isKey??i?.isKey??!1,L={isKey:c,data:s.data,timestamp:s.timestamp};if(e.configuring){o.push(L);return}if(i?.sps&&n){e.configuring=!0,o=[L];let v=e.decoderEpoch,C=()=>!e.stopped&&e.socket===t;e.configureDecoder({codec:aa(i.sps)},C).then(p=>{if(!C()||v!==e.decoderEpoch)return;e.configuring=!1,e.awaitingKeyframe=!0;let h=o;if(o=[],!!p){for(let T of h)e.decode(T.isKey,T.data,T.timestamp);e.awaitingKeyframe&&e.requestKeyframe()}});return}if(n){!c&&!l&&(l=!0,e.requestKeyframe());return}e.decode(c,s.data,s.timestamp)},t.onclose=d=>{e.socket===t&&(e.socket=null,e.closeDecoder(),!e.stopped&&(e.events.onInputConnected(!1,d.reason||`closed ${d.code}`),a(d.reason||void 0)))},t.onerror=()=>t.close()}function gt(e){return{sendTouch(a,t,o){let l=a==="begin"?"down":a==="move"?"move":"up";e.send(JSON.stringify({type:"touch",action:l,x:t,y:o}))},sendKey(a,t){if(t!=="down")return;if(a.key==="Escape")return e.send(JSON.stringify({type:"back"}));let o=mt[a.key];if(o!==void 0)return e.send(JSON.stringify({type:"key",keycode:o}));a.key.length===1&&!a.metaKey&&!a.ctrlKey&&e.send(JSON.stringify({type:"text",text:a.key}))},pressButton(a){let t=a==="appSwitcher"?"recents":a;(t==="home"||t==="back"||t==="recents"||t==="power")&&e.send(JSON.stringify({type:t}))},rotate(){},setOrientation(){}}}function Lt(e){return{present(a,t,o){let l=e.getContext("2d");return l?((e.width!==t||e.height!==o)&&(e.width=t,e.height=o),l.drawImage(a,0,0,t,o),!0):!1}}}var To=13,ht=10,xt=45,Bo=16*1024*1024,It=new TextEncoder,Ct=new TextDecoder;function vt(e){if(!e)return null;let a=/boundary=(?:"([^"]+)"|([^;\s]+))/i.exec(e),t=a?.[1]??a?.[2];return t?t.startsWith("--")?t:`--${t}`:null}function St(e,a,t,o){let l=o-a.length;for(let d=t;d<=l;d++){if(e[d]!==a[0])continue;let s=1;for(;s<a.length&&e[d+s]===a[s];)s++;if(s===a.length)return d}return-1}var ta=class{delimiter;buffer=new Uint8Array(64*1024);length=0;pos=0;state="boundary";contentLength=null;scanFrom=0;constructor(a){this.delimiter=a?It.encode(a):null}push(a){this.append(a);let t=[];for(;;){if(this.state==="done"){this.pos=this.length=0;break}if(this.state==="boundary"){if(!this.readBoundary())break}else if(this.state==="headers"){if(!this.readHeaders())break}else{let o=this.readBody();if(!o)break;o.length>0&&t.push(o)}}if(this.length-this.pos>Bo)throw new Error("MJPEG part is too large.");return this.pos>0&&(this.buffer.copyWithin(0,this.pos,this.length),this.length-=this.pos,this.scanFrom=Math.max(0,this.scanFrom-this.pos),this.pos=0),t}append(a){this.buffer=Qe(this.buffer,this.length,a),this.length+=a.length}lineEnd(a){return this.buffer.subarray(0,this.length).indexOf(ht,a)}readBoundary(){let a=this.buffer;if(!this.delimiter)for(;;){let s=this.lineEnd(this.pos);if(s===-1)return!1;let n=Ct.decode(a.subarray(this.pos,s)).trim();if(this.pos=s+1,n.startsWith("--"))return this.delimiter=It.encode(n),this.state="headers",!0}let t=this.delimiter,o=St(a,t,this.pos,this.length);if(o===-1)return this.pos=Math.max(this.pos,this.length-t.length+1),!1;let l=o+t.length;if(l+2>this.length)return this.pos=o,!1;if(a[l]===xt&&a[l+1]===xt)return this.state="done",!0;let d=this.lineEnd(l);return d===-1?(this.pos=o,!1):(this.pos=d+1,this.state="headers",!0)}readHeaders(){let a=this.pos,t=null;for(;;){let o=this.lineEnd(a);if(o===-1)return!1;let l=Ct.decode(this.buffer.subarray(a,o)).replace(/\r$/,"");if(a=o+1,l==="")break;let d=l.indexOf(":");if(d>0&&l.slice(0,d).trim().toLowerCase()==="content-length"){let s=Number.parseInt(l.slice(d+1).trim(),10);Number.isFinite(s)&&s>=0&&(t=s)}}return this.pos=a,this.contentLength=t,this.scanFrom=a,this.state="body",!0}readBody(){if(this.contentLength!==null){if(this.length-this.pos<this.contentLength)return null;let o=this.buffer.slice(this.pos,this.pos+this.contentLength);return this.pos+=this.contentLength,this.state="boundary",o}let a=this.delimiter,t=Math.max(this.scanFrom,this.pos+1);for(;;){let o=St(this.buffer,a,t,this.length);if(o===-1)return this.scanFrom=Math.max(this.pos,this.length-a.length),null;if(this.buffer[o-1]!==ht){t=o+1;continue}let l=o-1;l>this.pos&&this.buffer[l-1]===To&&l--;let d=this.buffer.slice(this.pos,Math.max(l,this.pos));return this.pos=o,this.state="boundary",d}}};async function Mo(e,a,t){let o=new ta(vt(e.headers.get("content-type")));await Je(e,l=>{for(let d of o.push(l))a(d)},t)}function ye(e){e.stopped||e.mjpeg||(e.mjpeg=!0,e.controller?.abort(),e.controller=null,e.closeDecoder(),e.connecting(),e.events.onMjpegFallback?.(),yt(e))}var Ca=e=>`${e.vendor}/helper/${e.device}/stream.mjpeg`;async function yt(e){let a=e.generation,t=++e.videoGeneration,o=new AbortController;e.controller=o;let l=()=>!e.stopped&&e.generation===a&&e.videoGeneration===t&&e.controller===o,d=null,s=!1,n=async()=>{s=!0;try{for(;d;){let i=d;d=null;try{let c=await e.createBitmap(new Blob([i],{type:"image/jpeg"}));try{l()&&e.paint(c,c.width,c.height)}finally{c.close()}}catch{}}}finally{s=!1}},u;try{let i=await e.transport.fetch(Ca(e),{signal:o.signal});if(!l()){await i.body?.cancel();return}if(!i.ok||!i.body)throw new Error(`stream ${i.status}`);if(await Mo(i,c=>{l()&&(d=c,s||n())},o.signal),!l())return;u="Device stream ended."}catch(i){if(!l())return;u=i.message}l()&&(e.controller=null,o.abort(),e.connecting(u),e.scheduleRetry("video",()=>{yt(e)}))}var Ro=1e3,Sa=15e3,Fo=16667,Oo=8,Eo=e=>typeof e=="object"&&e!==null&&"present"in e;function bt(e){let{transport:a,platform:t,events:o}=e,l=Eo(e.output)?e.output:Lt(e.output),d=n=>e.globals?.[n]??globalThis[n],s={platform:t,transport:a,events:o,preferMjpeg:e.preferMjpeg===!0,vendor:me(t),device:encodeURIComponent(e.deviceId),stopped:!0,generation:0,videoGeneration:0,decoderEpoch:0,socket:null,controller:null,primeController:null,videoDecoder:null,timestamp:0,awaitingKeyframe:!0,screen:null,firstFrame:!1,configuring:!1,mjpeg:!1,frameTimer:null,videoReadTimer:null,retryTimers:new Map,webCodecs(){let n=d("VideoDecoder"),u=d("EncodedVideoChunk");return n&&u?{VideoDecoder:n,EncodedVideoChunk:u}:null},createBitmap(n){let u=d("createImageBitmap");return u?u(n):Promise.reject(new Error("createImageBitmap is unavailable."))},setStatus(n,u){s.stopped||o.onStatus(n,u)},fail(n){s.stopped||(s.stop(),o.onInputConnected(!1,n),o.onStatus("error",n))},connecting(n){s.firstFrame=!1,s.frameTimer===null&&(s.frameTimer=setTimeout(()=>s.fail("No video received from the device. Reconnect to try again."),Sa)),s.setStatus("connecting",n)},paint(n,u,i){if(!s.stopped){if(t==="android"&&(s.screen?.width!==u||s.screen.height!==i)&&(s.screen={width:u,height:i,orientation:u>i?"landscape_left":"portrait"},o.onScreen(s.screen)),!l.present(n,u,i)){s.fail("Could not display the device stream. Reconnect to try again.");return}s.firstFrame||(s.firstFrame=!0,s.frameTimer!==null&&clearTimeout(s.frameTimer),s.frameTimer=null,s.setStatus("streaming"))}},closeDecoder(){s.decoderEpoch++,s.configuring=!1;try{s.videoDecoder?.close()}catch{}s.videoDecoder=null,s.awaitingKeyframe=!0},recoverDecoder(){t==="ios"?ye(s):(s.closeDecoder(),s.connecting("Video decoder restarted."),s.requestKeyframe())},async configureDecoder(n,u=()=>!s.stopped){let i=s.webCodecs();if(!i)return!1;let c=s.decoderEpoch,L={...n,optimizeForLatency:!0},v=await i.VideoDecoder.isConfigSupported(L).catch(()=>({supported:!1}));if(!u()||c!==s.decoderEpoch)return!1;if(!v.supported)return t==="android"&&s.fail(`This browser cannot decode ${n.codec}.`),!1;try{return(!s.videoDecoder||s.videoDecoder.state==="closed")&&(s.videoDecoder=Uo(s,i)),s.videoDecoder.configure(L),!0}catch(C){return t==="android"&&s.fail(`Video decoder: ${C.message}`),!1}},decode(n,u,i){let c=s.videoDecoder,L=s.webCodecs();if(!(!c||c.state!=="configured"||!L)){if(s.awaitingKeyframe){if(!n)return;s.awaitingKeyframe=!1}if(c.decodeQueueSize>Oo){s.recoverDecoder();return}try{c.decode(new L.EncodedVideoChunk({type:n?"key":"delta",timestamp:i??s.timestamp,data:u})),s.timestamp+=Fo}catch{s.recoverDecoder()}}},requestKeyframe(){t==="android"&&s.socket?.readyState===1&&s.socket.send(JSON.stringify({type:"reset-video",ack:!1}))},scheduleRetry(n,u){s.stopped||s.retryTimers.has(n)||s.retryTimers.set(n,setTimeout(()=>{s.retryTimers.delete(n),u()},Ro))},send(n){!s.stopped&&s.socket?.readyState===1&&s.socket.send(n)},stop(){if(s.stopped)return;s.stopped=!0,s.generation++,s.videoGeneration++,s.mjpeg=!1,s.frameTimer!==null&&clearTimeout(s.frameTimer),s.frameTimer=null,s.videoReadTimer!==null&&clearTimeout(s.videoReadTimer),s.videoReadTimer=null;for(let u of s.retryTimers.values())clearTimeout(u);s.retryTimers.clear(),s.primeController?.abort(),s.primeController=null,s.controller?.abort(),s.controller=null;let n=s.socket;s.socket=null,n?.close(),s.closeDecoder()}};return s}function Uo(e,a){let t=e.videoGeneration,o=()=>e.platform!=="ios"||t===e.videoGeneration,l=new a.VideoDecoder({output:d=>{try{e.videoDecoder===l&&o()&&e.paint(d,d.displayWidth,d.displayHeight)}finally{d.close()}},error:()=>{e.stopped||e.videoDecoder!==l||!o()||e.recoverDecoder()}});return l}var qo=3,Ho=4,No=6,kt=7,Vo=13,Go=130,zo=2e3,_o=new TextEncoder,Wo=new TextDecoder,oa=["portrait","landscape_left","portrait_upside_down","landscape_right"],Ko=new Set(oa);function ge(e,a){let t=_o.encode(JSON.stringify(a)),o=new Uint8Array(1+t.length);return o[0]=e,o.set(t,1),o}function Xo(e){if(typeof e!="object"||e===null)return null;let{width:a,height:t,orientation:o,screenId:l}=e;if(typeof a!="number"||!Number.isFinite(a)||a<=0||typeof t!="number"||!Number.isFinite(t)||t<=0||typeof o!="string"||!Ko.has(o))return null;let d={width:a,height:t,orientation:o};return typeof l=="number"?{...d,screenId:l}:d}function Dt(e,a){At(e),a?Pt(e):ye(e)}async function Pt(e){let a=e.generation,t=++e.videoGeneration,o=new ea,l=new AbortController;e.controller=l;let d=()=>!e.stopped&&e.generation===a&&e.videoGeneration===t&&e.controller===l,s;try{let n=await e.transport.fetch(`${e.vendor}/helper/${e.device}/stream.avcc`,{signal:l.signal});if(!d()){await n.body?.cancel();return}if(!n.ok||!n.body)throw new Error(`stream ${n.status}`);let u=n.body.getReader();for(;;){let i=setTimeout(()=>{d()&&e.fail("Device stream stopped receiving video. Reconnect to try again.")},Sa);e.videoReadTimer=i;let c;try{c=await u.read()}finally{clearTimeout(i),e.videoReadTimer===i&&(e.videoReadTimer=null)}let{done:L,value:v}=c;if(!d())return;if(L)break;for(let C of o.push(v))switch(C.type){case"seed":e.createBitmap(new Blob([C.payload],{type:"image/jpeg"})).then(p=>{try{d()&&e.paint(p,p.width,p.height)}finally{p.close()}}).catch(()=>{});break;case"description":{e.awaitingKeyframe=!0;let p=await e.configureDecoder({codec:aa(C.payload),description:C.payload},d);if(!d())return;if(!p){if(await u.cancel().catch(()=>{}),!d())return;ye(e);return}break}case"keyframe":case"delta":e.decode(C.type==="keyframe",C.payload);break}}}catch(n){if(!d())return;s=n.message}d()&&(e.controller=null,l.abort(),e.closeDecoder(),e.connecting(s),e.scheduleRetry("video",()=>{Pt(e)}))}async function $o(e,a){let t=new AbortController;e.primeController=t;let o=setTimeout(()=>t.abort(),zo);try{let l=await e.transport.fetch(Ca(e),{signal:t.signal});if(e.stopped||e.generation!==a)return;await l.body?.getReader().read()}catch{}finally{clearTimeout(o),t.abort(),e.primeController===t&&(e.primeController=null)}}async function At(e){if(e.stopped)return;let a=e.generation;if(await $o(e,a),e.stopped||e.generation!==a)return;let t=()=>e.scheduleRetry("input",()=>{At(e)}),o;try{o=e.transport.connect(`${e.vendor}/helper/ws?device=${e.device}`)}catch(l){e.events.onInputConnected(!1,l.message),t();return}e.socket=o,o.onopen=()=>{e.stopped||e.socket!==o||(o.send(ge(Vo,{enabled:!1})),e.events.onInputConnected(!0))},o.onmessage=l=>{if(e.stopped||e.socket!==o||typeof l.data=="string")return;let d=new Uint8Array(l.data);if(!(d.length<1||d[0]!==Go))try{let s=Xo(JSON.parse(Wo.decode(d.subarray(1))));s&&(e.screen=s,e.events.onScreen(s))}catch{}},o.onclose=l=>{e.socket===o&&(e.socket=null,!e.stopped&&(e.events.onInputConnected(!1,l.reason||(l.code===1006?"input socket refused":`closed ${l.code}`)),t()))},o.onerror=()=>o.close()}function jo(e,a,t){let o=e.screen;if(!o||o.width>o.height)return{x:a,y:t};switch(o.orientation){case"landscape_left":return{x:t,y:1-a};case"landscape_right":return{x:1-t,y:a};case"portrait_upside_down":return{x:1-a,y:1-t};default:return{x:a,y:t}}}function Tt(e){return{sendTouch(a,t,o){e.send(ge(qo,{type:a,...jo(e,t,o)}))},sendKey(a,t){let o=pt(a.code);o!==null&&e.send(ge(No,{type:t,usage:o}))},pressButton(a){let t=a==="home"?"home":a==="appSwitcher"?"app_switcher":a==="power"?"lock":null;t&&e.send(ge(Ho,{button:t}))},rotate(){let a=e.screen?.orientation??"portrait",t=oa[(oa.indexOf(a)+1)%oa.length];e.send(ge(kt,{orientation:t}))},setOrientation(a){e.send(ge(kt,{orientation:a}))}}}function Bt(e){let a=bt(e),t=e.platform==="ios"?Tt(a):gt(a);return{start:()=>{if(!a.stopped)return;a.stopped=!1,a.generation++,a.configuring=!1,a.connecting();let l=a.webCodecs()!==null&&!(e.platform==="ios"&&a.preferMjpeg);e.platform==="ios"?Dt(a,l):l?Ia(a):a.fail("This browser cannot decode the Android stream (WebCodecs unavailable).")},stop:a.stop,isMjpeg:()=>a.mjpeg,...t}}var Zo=56,Jo=2e3;function Qo(e,a,t,o=0){let l=Math.max(0,a-o);if(l===0||t===0)return{width:0,height:0};let d={width:t*e,height:t};return d.width<=l?d:{width:l,height:l/e}}function Yo(e,a){if(!a)return e==="ios"?9/19.5:9/20;let t=a.orientation==="landscape_left"||a.orientation==="landscape_right",o=Math.max(a.width,a.height),l=Math.min(a.width,a.height);return t?o/l:l/o}function er(e,a){if(e!=="ios"||!a||a.width>a.height)return 0;switch(a.orientation){case"landscape_left":return 90;case"landscape_right":return-90;case"portrait_upside_down":return 180;default:return 0}}var ar=()=>typeof navigator<"u"&&/iPhone|iPad|iPod/.test(navigator.userAgent);function ra(e){let{t:a}=D(),t=G(null),o=G(null),[l,d]=g("connecting"),[s,n]=g(),[u,i]=g(!1),[c,L]=g(null),[v,C]=g({connected:!1}),{onHandle:p,onStreaming:h,onScreen:T,transport:m,platform:y,deviceId:R}=e;B(()=>T?.(c),[T,c]),B(()=>{let I=t.current;if(!I)return;let k=Bt({transport:m,platform:y,deviceId:R,output:I,preferMjpeg:ar(),events:{onStatus:(O,N)=>{d(O),n(N),O==="streaming"&&i(!0),h(O==="streaming")},onScreen:L,onInputConnected:(O,N)=>{C({connected:O,...N?{detail:N}:{}}),p({pressButton:k.pressButton,rotate:k.rotate,inputConnected:O})}}});return o.current=k,C({connected:!1}),k.start(),p({pressButton:k.pressButton,rotate:k.rotate,inputConnected:!1}),()=>{k.stop(),o.current=null,p(null),h(!1),i(!1),L(null)}},[R,p,h,y,m]);let F=G(null),[_,P]=g({width:0,height:0});B(()=>{let I=F.current;if(!I)return;let k=()=>{let N=I.getBoundingClientRect();P(de=>de.width===N.width&&de.height===N.height?de:{width:N.width,height:N.height})};k();let O=new ResizeObserver(k);return O.observe(I),()=>O.disconnect()},[]);let b=e.withControls?Zo:0,U=ue(()=>Qo(Yo(y,c),_.width,_.height,b),[_,b,y,c]),W=er(y,c),q=W===90||W===-90?{width:U.height,height:U.width,left:(U.width-U.height)/2,top:(U.height-U.width)/2,transform:`rotate(${W}deg)`}:{width:U.width,height:U.height,...W?{transform:`rotate(${W}deg)`}:{}},[K,$]=g([]);B(()=>{if(!e.axOverlay)return;let I=null,k=null,O=!1,N=async()=>{I=new AbortController;try{let de=await st({transport:m,platform:y,deviceId:R},I.signal);O||$(de.elements)}catch{}O||(k=setTimeout(()=>{N()},Jo))};return N(),()=>{O=!0,I?.abort(),k&&clearTimeout(k),$([])}},[R,y,e.axOverlay,m]);let V=G(!1),x=I=>{let k=I.currentTarget.getBoundingClientRect(),O=(I.clientX-k.left)/k.width,N=(I.clientY-k.top)/k.height;return{x:Math.min(1,Math.max(0,O)),y:Math.min(1,Math.max(0,N))}},H=I=>{if(!V.current)return;V.current=!1;let{x:k,y:O}=x(I);o.current?.sendTouch("end",k,O)};return f("div",{ref:F,className:"relative flex size-full min-h-0 min-w-0 items-center justify-center overflow-hidden",style:b?{paddingRight:b}:void 0,tabIndex:0,role:"application","aria-label":a(y==="ios"?"stream.iosScreen":"stream.androidScreen"),onKeyDown:I=>{I.target===I.currentTarget&&(I.metaKey&&!["r","R"].includes(I.key)||(I.preventDefault(),o.current?.sendKey(I.nativeEvent,"down")))},onKeyUp:I=>{I.target===I.currentTarget&&o.current?.sendKey(I.nativeEvent,"up")},children:[f("div",{className:"relative touch-none select-none",style:{width:U.width,height:U.height},onPointerDown:I=>{I.currentTarget.setPointerCapture(I.pointerId),I.currentTarget.parentElement?.focus(),V.current=!0;let{x:k,y:O}=x(I);o.current?.sendTouch("begin",k,O)},onPointerMove:I=>{if(!V.current)return;let{x:k,y:O}=x(I);o.current?.sendTouch("move",k,O)},onPointerUp:H,onPointerCancel:H,children:[r("canvas",{ref:t,className:"absolute top-0 left-0",style:q}),K.length>0?r("div",{className:"pointer-events-none absolute inset-0","aria-hidden":!0,children:K.map(I=>r("div",{className:"absolute border border-info/80 bg-info/10",style:{left:`${I.x*100}%`,top:`${I.y*100}%`,width:`${I.width*100}%`,height:`${I.height*100}%`},children:I.label?r("span",{className:"absolute -top-3.5 left-0 max-w-full truncate rounded-sm bg-info px-1 text-ui-2xs leading-3.5 text-white",children:I.label}):null},I.id))}):null]}),l==="streaming"&&!v.connected?r("div",{className:"pointer-events-none absolute inset-x-0 bottom-0 flex justify-center p-2",children:r("span",{className:"rounded-md bg-background/85 px-2 py-1 text-xs text-muted-foreground",children:v.detail?a("stream.inputLostDetail",{detail:v.detail}):a("stream.inputLost")})}):null,l==="connecting"&&u?r("div",{className:"pointer-events-none absolute inset-x-0 bottom-0 flex justify-center p-2",children:r("span",{className:"rounded-md bg-background/85 px-2 py-1 text-xs text-muted-foreground",children:a("stream.connecting")})}):null,l==="error"||l!=="streaming"&&!u?r("div",{className:"absolute inset-0 bg-background",children:r(ee,{name:e.deviceName,description:e.deviceDescription,stage:l==="error"?"error":"connecting",message:l==="error"?s??a("stream.failed"):a("stream.connecting"),children:l==="error"?r(S,{size:"sm",variant:"outline",onClick:()=>{o.current?.stop(),o.current?.start()},children:a("stream.reconnect")}):null})}):null]})}var tr={hosts:[],hostStatuses:{},devices:[],sessions:[],bootingDevices:[],revision:0};function Le(e){let t=E().commands.useSubscription("state",{},{environmentId:e});return{state:t.data??tr,loaded:t.data!==null,error:t.error,unavailable:t.isUnavailable}}function te(){let e=E();return Y((a,t,o={})=>e.commands.invoke(a,o,{environmentId:t}),[e])}var he="local",la=class extends Error{code;constructor(a,t,o){super(t,o),this.name="DeviceError",this.code=a}};var Mt="hub";function sa(e){let a=E(),[t,o]=g({status:"connecting"});return B(()=>{let l=a.network;if(!ce(a,"network")||l===void 0){o({status:"failed",message:null});return}let d=!1;return o({status:"connecting"}),l.client(e).then(s=>{d||o({status:"ready",transport:{fetch:(n,u)=>s.fetch(Mt,n,{...u,instance:he}),connect:n=>s.connect(Mt,n,{instance:he})}})},s=>{d||o({status:"failed",message:s instanceof Error?s.message:String(s)})}),()=>{d=!0}},[a,e]),t}var Rt=()=>{};function Ft(e){let{environmentId:a,threadId:t,hostId:o,deviceId:l,platform:d}=e,s=e[Na],n=E(),{t:u}=D(),{state:i,loaded:c}=Le(a),L=sa(a),v=ue(()=>({environmentId:a,threadId:t}),[a,t]),C=i.devices.find(y=>y.hostId===o&&y.id===l),p=i.sessions.some(y=>y.threadId===t&&y.hostId===o&&y.deviceId===l);B(()=>{c&&!p&&n.floating?.close(v,s.key)},[n,s.key,c,p,v]),B(()=>(s.setOpenInPanel(()=>{Ge(a,t,s.key),n.floating?.openPanel(v,Ne),n.floating?.close(v,s.key)}),()=>s.setOpenInPanel(null)),[n,a,s,v,t]);let h=Y(y=>s.reportSourceSize(y===null?null:Va(y)),[s]),T=C?.name??l,m=C?.version??d;return L.status!=="ready"?r(ee,{name:T,description:m,stage:L.status==="failed"?"error":"connecting",message:L.status==="failed"?L.message??u("workspace.needsNewerApp"):u("stream.connecting")}):r(ra,{transport:L.transport,platform:d,deviceId:l,deviceName:T,deviceDescription:m,axOverlay:!1,withControls:!1,onHandle:Rt,onStreaming:Rt,onScreen:h})}var da=(...e)=>e.filter((a,t,o)=>!!a&&a.trim()!==""&&o.indexOf(a)===t).join(" ").trim();var Ot=e=>e.replace(/([a-z0-9])([A-Z])/g,"$1-$2").toLowerCase();var Et=e=>e.replace(/^([A-Z])|[\s-_]+(\w)/g,(a,t,o)=>o?o.toUpperCase():t.toLowerCase());var va=e=>{let a=Et(e);return a.charAt(0).toUpperCase()+a.slice(1)};var Ut={xmlns:"http://www.w3.org/2000/svg",width:24,height:24,viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:2,strokeLinecap:"round",strokeLinejoin:"round"};var qt=e=>{for(let a in e)if(a.startsWith("aria-")||a==="role"||a==="title")return!0;return!1};var Ht=qe(({color:e="currentColor",size:a=24,strokeWidth:t=2,absoluteStrokeWidth:o,className:l="",children:d,iconNode:s,...n},u)=>ne("svg",{ref:u,...Ut,width:a,height:a,stroke:e,strokeWidth:o?Number(t)*24/Number(a):t,className:da("lucide",l),...!d&&!qt(n)&&{"aria-hidden":"true"},...n},[...s.map(([i,c])=>ne(i,c)),...Array.isArray(d)?d:[d]]));var w=(e,a)=>{let t=qe(({className:o,...l},d)=>ne(Ht,{ref:d,iconNode:a,className:da(`lucide-${Ot(va(e))}`,`lucide-${e}`,o),...l}));return t.displayName=va(e),t};var or=[["path",{d:"M13.997 4a2 2 0 0 1 1.76 1.05l.486.9A2 2 0 0 0 18.003 7H20a2 2 0 0 1 2 2v9a2 2 0 0 1-2 2H4a2 2 0 0 1-2-2V9a2 2 0 0 1 2-2h1.997a2 2 0 0 0 1.759-1.048l.489-.904A2 2 0 0 1 10.004 4z",key:"18u6gg"}],["circle",{cx:"12",cy:"13",r:"3",key:"1vg3eu"}]],we=w("camera",or);var rr=[["path",{d:"m6 9 6 6 6-6",key:"qrunsl"}]],be=w("chevron-down",rr);var lr=[["path",{d:"m15 18-6-6 6-6",key:"1wnfg3"}]],ke=w("chevron-left",lr);var sr=[["circle",{cx:"12",cy:"12",r:"1",key:"41hilf"}],["circle",{cx:"19",cy:"12",r:"1",key:"1wjl8i"}],["circle",{cx:"5",cy:"12",r:"1",key:"1pcz8c"}]],oe=w("ellipsis",sr);var dr=[["path",{d:"M15 21v-8a1 1 0 0 0-1-1h-4a1 1 0 0 0-1 1v8",key:"5wwlr5"}],["path",{d:"M3 10a2 2 0 0 1 .709-1.528l7-6a2 2 0 0 1 2.582 0l7 6A2 2 0 0 1 21 10v9a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2z",key:"r6nss1"}]],re=w("house",dr);var nr=[["circle",{cx:"12",cy:"12",r:"10",key:"1mglay"}],["path",{d:"M12 16v-4",key:"1dtifu"}],["path",{d:"M12 8h.01",key:"e9boi3"}]],De=w("info",nr);var ur=[["path",{d:"M20.985 12.486a9 9 0 1 1-9.473-9.472c.405-.022.617.46.402.803a6 6 0 0 0 8.268 8.268c.344-.215.825-.004.803.401",key:"kfwtm"}]],Pe=w("moon",ur);var ir=[["path",{d:"M21 9V6a2 2 0 0 0-2-2H4a2 2 0 0 0-2 2v10c0 1.1.9 2 2 2h4",key:"daa4of"}],["rect",{width:"10",height:"7",x:"12",y:"13",rx:"2",key:"1nb8gs"}]],Ae=w("picture-in-picture-2",ir);var fr=[["path",{d:"M12 2v10",key:"mnfbl"}],["path",{d:"M18.4 6.6a9 9 0 1 1-12.77.04",key:"obofu9"}]],Te=w("power",fr);var cr=[["path",{d:"M3 12a9 9 0 1 0 9-9 9.75 9.75 0 0 0-6.74 2.74L3 8",key:"1357e3"}],["path",{d:"M3 3v5h5",key:"1xhq8a"}]],xe=w("rotate-ccw",cr);var pr=[["path",{d:"M21 12a9 9 0 1 1-9-9c2.52 0 4.93 1 6.74 2.74L21 8",key:"1p45f6"}],["path",{d:"M21 3v5h-5",key:"1q7to0"}]],Be=w("rotate-cw",pr);var mr=[["path",{d:"M10 5H3",key:"1qgfaw"}],["path",{d:"M12 19H3",key:"yhmn1j"}],["path",{d:"M14 3v4",key:"1sua03"}],["path",{d:"M16 17v4",key:"1q0r14"}],["path",{d:"M21 12h-9",key:"1o4lsq"}],["path",{d:"M21 19h-5",key:"1rlt1p"}],["path",{d:"M21 5h-7",key:"1oszz2"}],["path",{d:"M8 10v4",key:"tgpxqk"}],["path",{d:"M8 12H3",key:"a7s4jb"}]],Me=w("sliders-horizontal",mr);var gr=[["rect",{width:"14",height:"20",x:"5",y:"2",rx:"2",ry:"2",key:"1yt0o3"}],["path",{d:"M12 18h.01",key:"mhygvu"}]],Ie=w("smartphone",gr);var Lr=[["rect",{width:"18",height:"18",x:"3",y:"3",rx:"2",key:"afitv7"}]],Re=w("square",Lr);var hr=[["circle",{cx:"12",cy:"12",r:"4",key:"4exip2"}],["path",{d:"M12 2v2",key:"tus03m"}],["path",{d:"M12 20v2",key:"1lh1kg"}],["path",{d:"m4.93 4.93 1.41 1.41",key:"149t6j"}],["path",{d:"m17.66 17.66 1.41 1.41",key:"ptbguv"}],["path",{d:"M2 12h2",key:"1t8f8n"}],["path",{d:"M20 12h2",key:"1q8mjw"}],["path",{d:"m6.34 17.66-1.41 1.41",key:"1m8zz5"}],["path",{d:"m19.07 4.93-1.41 1.41",key:"1shlcs"}]],Fe=w("sun",hr);var xr=[["path",{d:"M12 4v16",key:"1654pz"}],["path",{d:"M4 7V5a1 1 0 0 1 1-1h14a1 1 0 0 1 1 1v2",key:"e0r10z"}],["path",{d:"M9 20h6",key:"s66wpe"}]],Oe=w("type",xr);var Ir=[["path",{d:"M18 6 6 18",key:"1bl5f8"}],["path",{d:"m6 6 12 12",key:"d8bk6v"}]],Q=w("x",Ir);function Cr(e,a){let t=o=>a(o==="hub"?"versions.hubName":"versions.agentName");return e.status==="starting"?a("panel.startingHost"):e.status!=="installing"?e.message??"":e.tool&&e.toVersion?e.fromVersion?a("panel.updatingTool",{tool:t(e.tool),from:e.fromVersion,to:e.toVersion}):a("panel.installingTool",{tool:t(e.tool),to:e.toVersion}):a("panel.installing")}function ya(){let{t:e}=D();return a=>Cr(a,e)}function Nt(e){let{t:a}=D(),t=ya(),[o,l]=g(!1),d=e.detail;return!d||d.status==="ready"||d.status==="idle"?null:d.status==="failed"?f("div",{role:"alert",className:"flex items-start gap-2 border-b bg-destructive/5 px-3 py-2 text-xs",children:[f("div",{className:"min-w-0 flex-1 space-y-0.5",children:[r("p",{className:"font-medium text-destructive-foreground",children:a("panel.hostFailed")}),d.message?r("p",{className:"whitespace-pre-wrap break-words text-muted-foreground",children:d.message}):null]}),f(S,{size:"xs",variant:"outline",disabled:o,onClick:()=>{l(!0),e.onRetry().finally(()=>l(!1))},children:[o?r(z,{size:"xs"}):r(Be,{}),a(o?"panel.retrying":"panel.retry")]})]}):f("div",{role:"status",className:"flex items-center gap-2 border-b px-3 py-2 text-xs text-muted-foreground",children:[r(z,{size:"xs"}),r("span",{className:"min-w-0 flex-1",children:t(d)})]})}var wa=["hub","agent"],ba=e=>e!==void 0&&!e.installedVersions.includes(e.requiredVersion);function Vt(e){let{t:a}=D(),t=te(),o=E(),[l,d]=g(null),[s,n]=g(null),[u,i]=g(!1),c=e.host?.tools,L=e.busy||l!==null,v=p=>{d(p),n(null),i(!1),(p==="check"?t("inspect",e.environmentId):t("updateTool",e.environmentId,{tool:p})).then(()=>i(p==="check")).catch(()=>{n(a(p==="check"?"versions.checkFailed":"versions.updateFailed")),p!=="check"&&o.notify(a("versions.updateFailed"),"error")}).finally(()=>d(null))},C=p=>p??a("versions.none");return f(Ya,{children:[f(et,{render:r(S,{size:"xs",variant:"ghost","aria-label":a("versions.title")}),children:[r(De,{}),a("versions.title"),wa.some(p=>ba(c?.[p]))?r("span",{className:"size-1.5 rounded-full bg-warning","aria-hidden":!0}):null]}),r(at,{side:"bottom",align:"start",className:"w-80",children:f("div",{className:"space-y-3 text-xs",children:[wa.map(p=>{let h=c?.[p];return f("section",{className:"space-y-1",children:[r("h4",{className:"font-medium text-foreground",children:a(p==="hub"?"versions.hubName":"versions.agentName")}),f("dl",{className:"grid grid-cols-[auto_1fr] gap-x-3 gap-y-0.5 text-muted-foreground",children:[r("dt",{children:a("versions.required")}),r("dd",{className:"font-mono",children:C(h?.requiredVersion)}),r("dt",{children:a("versions.installed")}),r("dd",{className:"font-mono",children:h&&h.installedVersions.length>0?h.installedVersions.join(", "):a("versions.none")}),r("dt",{children:a("versions.running")}),r("dd",{className:"font-mono",children:C(h?.runningVersion)})]}),ba(h)?f(S,{size:"xs",variant:"outline",disabled:L,onClick:()=>v(p),children:[l===p?r(z,{size:"xs"}):null,a("versions.updateTo",{version:h?.requiredVersion??""})]}):null]},p)}),c===void 0?r("p",{className:"text-muted-foreground",children:a("versions.unknown")}):null,wa.some(p=>ba(c?.[p]))?r("p",{className:"text-muted-foreground",children:a("versions.pendingPolicy")}):null,s?r("p",{role:"alert",className:"text-destructive-foreground",children:s}):null,f("div",{className:"flex items-center justify-between gap-2 border-t pt-2",children:[r("p",{role:"status",className:"text-muted-foreground",children:a(u?"versions.checked":"versions.checkHint")}),f(S,{size:"xs",variant:"ghost",disabled:L,onClick:()=>v("check"),children:[l==="check"?r(z,{size:"xs"}):null,a("versions.check")]})]})]})})]})}var ka=[{api:"35",name:"Android 15"},{api:"30",name:"Android 11"}],Gt=ka[0].api;var Ee=e=>e>=1073741824?`${(e/1073741824).toFixed(2)} GB`:`${(e/1048576).toFixed(1)} MB`;function zt(e){let{phase:a,receivedBytes:t,totalBytes:o,bytesPerSecond:l}=e,d=a==="download"&&t!==void 0&&o?{received:t,total:o}:null,s=d&&l?(d.total-d.received)/l:null;return{titleKey:`environment.stages.${a??"starting"}`,component:e.component??"",percent:d?Math.floor(d.received/d.total*100):null,transferred:d?{done:Ee(d.received),total:Ee(d.total)}:null,speed:d&&l?Ee(l):null,minutesLeft:s===null?null:Math.ceil(s/60),slow:s!==null&&s>1200}}var _t=e=>e.source==="private"&&e.ready;function Wt(e){return e.supported?e.freeBytes!==null&&e.freeBytes<e.requiredFreeBytes?"environment.notEnoughSpace":null:e.reasonCode?`environment.reasons.${e.reasonCode}`:"environment.unsupported"}function Kt(e,a){return e.cacheBytes>0||a==="android"&&e.deviceDataBytes>0}function Xt(e){let{t:a}=D(),t=zt(e.progress),o=[t.transferred?a("environment.transferred",t.transferred):null,t.speed?a("environment.speed",{speed:t.speed}):null,t.minutesLeft===null?null:a("environment.timeLeft",{minutes:String(t.minutesLeft)})].filter(l=>l!==null);return f("div",{role:"status",className:"space-y-2",children:[f("p",{className:"flex items-center gap-2 font-medium text-foreground",children:[r(z,{size:"xs"}),a(t.titleKey,{component:t.component})]}),t.percent===null?null:r("div",{role:"progressbar","aria-valuemin":0,"aria-valuemax":100,"aria-valuenow":t.percent,className:"h-1.5 overflow-hidden rounded-full bg-muted",children:r("div",{className:"h-full rounded-full bg-primary",style:{width:`${t.percent}%`}})}),o.length>0?r("p",{children:o.join(" \xB7 ")}):null,t.slow?r("p",{className:"text-warning-foreground",children:a("environment.slowDownload")}):null,r("p",{children:a("environment.continues")}),r(S,{size:"sm",variant:"outline",disabled:e.cancelling,onClick:e.onCancel,children:a("environment.cancel")})]})}function $t(e){let{t:a}=D(),t=te(),o=E(),d=o.commands.useSubscription("environmentProgress",{},{environmentId:e.environmentId}).data,[s,n]=g(!1),[u,i]=g("android"),[c,L]=g(""),[v,C]=g(""),[p,h]=g(null),[T,m]=g(!1),[y,R]=g(!1),[F,_]=g(!1),[P,b]=g(null),[U,W]=g(!1),[fe,q]=g(!1),[K,$]=g(void 0),V=d?.status==="working",x=P!==null||V,H=d&&d.id!==K?d:null;B(()=>{(V||H?.status==="failed")&&n(!0),H?.status==="done"&&H.plan?.platform===u&&h(H.plan)},[H,u,V]);let I=()=>{h(null),m(!1),R(!1),_(!1),q(!1),$(d?.id)},k=async(M,xo={})=>{b(M),W(!1),q(!1),$(d?.id);try{let Io=await t(M,e.environmentId,{platform:u,directory:c,version:v,...xo});M==="cleanupEnvironment"?h(await t("environmentPlan",e.environmentId,{platform:u,directory:c,version:v})):M!=="prepareEnvironment"&&h(Io),q(M==="cleanupEnvironment")}catch{W(!0),o.notify(a("environment.failed"),"error")}finally{b(null)}},O=p?Wt(p):null,N=M=>M===null?a("environment.unknownSize"):Ee(M),de=p!==null&&_t(p);return f(Xe,{open:s,onOpenChange:n,className:"w-full text-left",children:[r($e,{render:r(S,{variant:"outline",size:"sm",className:"w-full"}),children:a("environment.title")}),r(je,{children:f("div",{className:"space-y-3 rounded-md border p-3 text-xs",children:[V?r(Xt,{progress:d,cancelling:P==="cancelEnvironment",onCancel:()=>{b("cancelEnvironment"),t("cancelEnvironment",e.environmentId,{}).catch(()=>{W(!0),o.notify(a("environment.failed"),"error")}).finally(()=>b(null))}}):f(Z,{children:[r("p",{children:a("environment.description")}),e.iosSupported?r("div",{className:"flex gap-2",children:["android","ios"].map(M=>r(S,{size:"sm",variant:u===M?"default":"outline",disabled:x,onClick:()=>{i(M),C(""),I()},children:a(M==="ios"?"panel.platformIos":"panel.platformAndroid")},M))}):null,f("label",{className:"block space-y-1",children:[r("span",{children:a("environment.directory")}),r(ae,{value:c,disabled:x,onChange:M=>{L(M.target.value),I()},placeholder:a("environment.defaultDirectory")})]}),r("p",{children:a("environment.directoryHint")}),u==="android"?f("div",{className:"space-y-1",children:[r("span",{children:a("environment.androidVersion")}),r("div",{className:"flex flex-wrap gap-2",children:ka.map(M=>r(S,{size:"sm",variant:(v||Gt)===M.api?"default":"outline",disabled:x,onClick:()=>{C(M.api),I()},children:a("environment.androidVersionOption",{name:M.name,api:M.api})},M.api))})]}):f("label",{className:"block space-y-1",children:[r("span",{children:a("environment.iosVersion")}),r(ae,{value:v,disabled:x,onChange:M=>{C(M.target.value),I()},placeholder:a("environment.iosVersionPlaceholder")})]}),r(S,{size:"sm",variant:"outline",disabled:x,onClick:()=>{k("environmentPlan")},children:a("environment.inspect")}),p?f("div",{className:"space-y-2",children:[f("dl",{className:"grid grid-cols-[auto_1fr] gap-x-3 gap-y-1 break-all",children:[r("dt",{children:a("environment.source")}),r("dd",{children:a(`environment.sources.${p.source}`)}),r("dt",{children:a("environment.version")}),r("dd",{children:p.version||a("environment.versionRequired")}),r("dt",{children:a("environment.location")}),r("dd",{children:p.root}),p.existingSdkRoot?f(Z,{children:[r("dt",{children:a("environment.existingSdk")}),r("dd",{children:p.existingSdkRoot})]}):null,r("dt",{children:a("environment.download")}),r("dd",{children:p.downloadBytes===0?a("environment.nothingToDownload"):N(p.downloadBytes)}),r("dt",{children:a("environment.free")}),r("dd",{children:N(p.freeBytes)}),r("dt",{children:a("environment.required")}),r("dd",{children:N(p.requiredFreeBytes)})]}),p.source==="external"?r("p",{children:a("environment.external")}):null,p.reasonCode&&p.supported?r("p",{role:"status",children:a(`environment.reasons.${p.reasonCode}`)}):null,r("a",{className:"underline",href:p.guidanceUrl,target:"_blank",rel:"noreferrer",children:a("environment.guide")}),u==="ios"?r("p",{children:a("environment.appleOwnership")}):r("p",{children:a("environment.privateOwnership")}),de?r("p",{role:"status",className:"font-medium text-foreground",children:a("environment.ready")}):f(Z,{children:[r("ul",{children:p.licenses.map(M=>r("li",{children:r("a",{className:"underline",href:M.url,target:"_blank",rel:"noreferrer",children:a(u==="ios"?"environment.appleLicense":"environment.androidLicense")})},M.url))}),f("label",{className:"flex items-center gap-2",children:[r(pe,{checked:T,disabled:x,onCheckedChange:m}),r("span",{children:a("environment.acceptLicense")})]}),u==="ios"?f("label",{className:"flex items-center gap-2",children:[r(pe,{checked:y,disabled:x,onCheckedChange:R}),r("span",{children:a("environment.confirmApple")})]}):null,O?r("p",{role:"alert",className:"font-medium text-warning-foreground",children:a(O)}):null,r(S,{size:"sm",disabled:x||!p.supported||!T||u==="ios"&&(!y||!v)||p.freeBytes===null||p.freeBytes<p.requiredFreeBytes,onClick:()=>{k("prepareEnvironment",{acceptLicenses:T,confirmAppleInstall:y})},children:a("environment.prepare")})]}),Kt(p,u)?f("div",{className:"space-y-2 border-t pt-2",children:[r("p",{children:a("environment.retention")}),r(S,{size:"sm",variant:"outline",disabled:x||p.cacheBytes===0,onClick:()=>{k("cleanupEnvironment",{category:"cache",confirm:!0})},children:a("environment.cleanCache",{size:N(p.cacheBytes)})}),u==="android"?f(Z,{children:[r("p",{children:a("environment.deviceData",{size:N(p.deviceDataBytes)})}),f("label",{className:"flex items-center gap-2",children:[r(pe,{checked:F,disabled:x,onCheckedChange:_}),r("span",{children:a("environment.confirmData")})]}),r(S,{size:"sm",variant:"destructive",disabled:x||!F||p.deviceDataBytes===0,onClick:()=>{k("cleanupEnvironment",{category:"devices",confirm:F})},children:a("environment.cleanDevices")})]}):null]}):null]}):null]}),P!==null&&!V?f("p",{role:"status",className:"flex items-center gap-2",children:[r(z,{size:"xs"}),a("environment.working")]}):null,U?r("p",{role:"alert",className:"text-destructive-foreground",children:a("environment.failed")}):null,H?.status==="failed"?f("div",{role:"alert",className:"space-y-1 text-destructive-foreground",children:[r("p",{children:a("environment.prepareFailed")}),H.message?r("p",{className:"whitespace-pre-wrap break-words text-muted-foreground",children:H.message}):null]}):null,H?.status==="cancelled"?r("p",{role:"status",children:a("environment.cancelled")}):null,fe?r("p",{role:"status",children:a("environment.cleaned")}):null]})})]})}var jt=["small","default","large","extra-large"],Sr=e=>jt.includes(e);function Zt(e){let{t:a}=D(),{handle:t,controls:o}=e,l=o.detail?.settings,d=!t?.inputConnected,s=l?.appearance==="dark"?"light":"dark",n=u=>a(u==="small"?"rail.textSmall":u==="default"?"rail.textDefault":u==="large"?"rail.textLarge":"rail.textExtraLarge");return r("aside",{"aria-label":a("rail.label"),className:"pointer-events-none absolute inset-y-0 right-0 z-10 flex w-14 flex-col items-center justify-center gap-2 overflow-y-auto py-3 pr-2",children:f("div",{className:"pointer-events-auto flex shrink-0 flex-col items-center gap-1 rounded-full border border-border/50 bg-background/80 p-2 shadow-sm",children:[r(le,{label:a("rail.home"),disabled:d,onClick:()=>t?.pressButton("home"),children:r(re,{})}),e.platform==="android"?f(Z,{children:[r(le,{label:a("rail.back"),disabled:d,onClick:()=>t?.pressButton("back"),children:r(ke,{})}),r(le,{label:a("rail.recents"),disabled:d,onClick:()=>t?.pressButton("recents"),children:r(Re,{})}),f(_e,{children:[r(Ke,{render:r(S,{size:"icon-sm",variant:"ghost","aria-label":a("rail.rotate"),disabled:o.disabled}),children:r(xe,{})}),f(We,{side:"left",children:[r(ve,{onClick:()=>{o.act({type:"setOrientation",value:"portrait"})},children:a("rail.portrait")}),r(ve,{onClick:()=>{o.act({type:"setOrientation",value:"landscape_left"})},children:a("rail.landscape")})]})]})]}):r(le,{label:a("rail.rotate"),disabled:d,onClick:()=>t?.rotate(),children:r(xe,{})}),r(vr,{}),r(le,{label:a(s==="dark"?"rail.toDark":"rail.toLight"),disabled:o.disabled||!l?.appearance,onClick:()=>{o.act({type:"setAppearance",value:s})},children:l?.appearance==="dark"?r(Fe,{}):r(Pe,{})}),f(_e,{children:[r(Ke,{render:r(S,{size:"icon-sm",variant:"ghost","aria-label":a("rail.textSize"),title:a("rail.textSize"),disabled:o.disabled||!l?.textSize}),children:r(Oe,{})}),r(We,{side:"left",children:r($a,{value:l?.textSize??"",onValueChange:u=>{Sr(u)&&o.act({type:"setTextSize",value:u})},children:jt.map(u=>r(ja,{value:u,children:n(u)},u))})})]}),r(le,{label:a("rail.tools"),pressed:e.toolsOpen,onClick:e.onTools,children:r(Me,{})}),r(le,{label:e.screenshotPending?a("rail.capturing"):a("rail.screenshot"),disabled:!e.streaming||e.screenshotPending,onClick:e.onScreenshot,children:r(we,{})}),e.onFloat?r(le,{label:a("rail.float"),onClick:e.onFloat,children:r(Ae,{})}):null,f(_e,{children:[r(Ke,{render:r(S,{size:"icon-sm",variant:"ghost","aria-label":a("rail.more"),title:a("rail.more")}),children:r(oe,{})}),f(We,{side:"left",align:"end",children:[f(ve,{onClick:e.onClose,children:[r(Q,{}),a("rail.closePanel")]}),r(Xa,{}),f(ve,{variant:"destructive",onClick:e.onPowerOff,children:[r(Te,{}),a("rail.powerOff")]})]})]})]})})}function vr(){return r("div",{"aria-hidden":!0,className:"my-1 h-px w-5 shrink-0 bg-border/70"})}function le(e){return f(_a,{children:[r(Ka,{render:r(S,{size:"icon-sm",variant:e.pressed?"secondary":"ghost","aria-label":e.label,"aria-pressed":e.pressed,disabled:e.disabled,onClick:e.onClick}),children:e.children}),r(Wa,{side:"left",children:e.label})]})}var Da=(e,a)=>new la("invalid-input",`Invalid ${e}: ${a}.`);var Jt=4096,Qt=["light","dark"],Yt=["small","default","large","extra-large"];var eo=["clear","tinted"],ao=["none","grayscale","red-green","green-red","blue-yellow"],to=["portrait","landscape_left","portrait_upside_down","landscape_right"],oo=["camera","microphone","photos","contacts","calendar","reminders","location","notifications","motion","media-library","faceid"];var yr=e=>typeof e=="object"&&e!==null&&!Array.isArray(e);var ro=e=>{let a=typeof e=="string"?{aps:{alert:e}}:e;if(!yr(a))throw Da("push payload","expected a string or an object");let t;try{t=JSON.stringify(a)}catch{t=void 0}if(t===void 0)throw Da("push payload","could not be encoded as JSON");if(new TextEncoder().encode(t).length>Jt)throw Da("push payload",`larger than ${String(Jt)} bytes`);return t};var wr=new Set(["setAppearance","setTextSize","setToggle","setLiquidGlass","setColorFilter","setLocation","clearLocation","setPermission","openUrl","launchApp","relaunchApp","terminateApp","sendPush"]),br=new Set(["setAppearance","setTextSize","setToggle","setOrientation","setLocation","setPermission","openUrl","launchApp","relaunchApp","terminateApp"]),kr=new Set(["reduceMotion","increaseContrast","reduceTransparency","showBorders","voiceOver"]),Dr=new Set(["reduceMotion","networkEnabled"]),Pa=(e,a)=>(e==="ios"?wr:br).has(a.type)?a.type==="setToggle"?(e==="ios"?kr:Dr).has(a.setting):!0:!1;function ie(e){return f("section",{className:"flex flex-col gap-2 border-b px-3 py-2.5",children:[r("h3",{className:"text-xs font-medium text-muted-foreground",children:e.title}),e.children]})}function se(e){return f("div",{className:"flex min-h-7 items-center justify-between gap-3",children:[r("span",{className:"shrink-0 text-xs text-muted-foreground",children:e.label}),r("div",{className:"flex min-w-0 items-center justify-end",children:e.children})]})}function Aa(e){return r(se,{label:e.label,children:r(pe,{"aria-label":e.label,checked:e.checked??!1,disabled:e.disabled||e.checked===void 0,onCheckedChange:a=>{e.onChange(a)}})})}function Ta(e){return r(Ja,{"aria-label":e.label,variant:"outline",value:e.value===void 0?[]:[e.value],disabled:e.disabled||e.value===void 0,onValueChange:a=>{let t=e.options.find(o=>o.value===a[0]);t&&e.onChange(t.value)},children:e.options.map(a=>r(Qa,{size:"xs",value:a.value,children:a.label},a.value))})}function Ue(e){let a=e.options.find(t=>t.value===e.value);return f(pa,{value:e.value,disabled:e.disabled,onValueChange:t=>{let o=e.options.find(l=>l.value===t);o&&o.value!==e.value&&e.onChange(o.value)},children:[r(ma,{size:"xs",className:e.width??"w-40","aria-label":e.ariaLabel,children:r(ga,{children:a?a.label:r("span",{className:"text-muted-foreground",children:e.placeholder})})}),r(La,{align:"end",alignItemWithTrigger:!1,children:e.options.map(t=>r(ha,{value:t.value,children:t.label},t.value))})]})}function Ba(e){let[a,t]=g(""),o=a.trim()||e.fallback||"",l=()=>{o&&e.onSubmit(o).then(()=>t(""))};return f("form",{className:"flex gap-1.5",onSubmit:d=>{d.preventDefault(),l()},children:[r(ae,{size:"compact",className:"min-w-0 flex-1 font-mono",placeholder:e.placeholder,"aria-label":e.placeholder,value:a,disabled:e.disabled,onChange:d=>t(d.target.value)}),r(S,{type:"submit",size:"xs",variant:"outline",disabled:e.disabled||!o,children:e.action})]})}var lo=[{key:"tools.location.sanFrancisco",latitude:37.7749,longitude:-122.4194},{key:"tools.location.newYork",latitude:40.7128,longitude:-74.006},{key:"tools.location.london",latitude:51.5074,longitude:-.1278},{key:"tools.location.stockholm",latitude:59.3293,longitude:18.0686},{key:"tools.location.tokyo",latitude:35.6762,longitude:139.6503}];function no(e){let{t:a}=D(),[t,o]=g(e.current?String(e.current.latitude):""),[l,d]=g(e.current?String(e.current.longitude):""),s={latitude:Number(t),longitude:Number(l)},n=t.trim()!==""&&l.trim()!==""&&Math.abs(s.latitude)<=90&&Math.abs(s.longitude)<=180,u=(i,c)=>e.act({type:"setLocation",latitude:i,longitude:c});return f(ie,{title:a("tools.location.title"),children:[f("div",{className:"flex gap-1.5",children:[r(ae,{size:"compact",className:"min-w-0 flex-1 font-mono",placeholder:a("tools.location.latitude"),"aria-label":a("tools.location.latitude"),inputMode:"decimal",value:t,disabled:e.disabled,onChange:i=>o(i.target.value)}),r(ae,{size:"compact",className:"min-w-0 flex-1 font-mono",placeholder:a("tools.location.longitude"),"aria-label":a("tools.location.longitude"),inputMode:"decimal",value:l,disabled:e.disabled,onChange:i=>d(i.target.value)})]}),f("div",{className:"flex flex-wrap items-center gap-1.5",children:[f(pa,{value:null,disabled:e.disabled,onValueChange:i=>{let c=lo.find(L=>L.key===i);c&&(o(String(c.latitude)),d(String(c.longitude)),u(c.latitude,c.longitude))},children:[r(ma,{size:"xs",className:"w-32","aria-label":a("tools.location.preset"),children:r(ga,{children:r("span",{className:"text-muted-foreground",children:a("tools.location.presetPlaceholder")})})}),r(La,{align:"start",alignItemWithTrigger:!1,children:lo.map(i=>r(ha,{value:i.key,children:a(i.key)},i.key))})]}),r(S,{size:"xs",variant:"outline",disabled:e.disabled||!n,onClick:()=>{u(s.latitude,s.longitude)},children:a("tools.location.set")}),e.canClear?r(S,{size:"xs",variant:"ghost",disabled:e.disabled,onClick:()=>{o(""),d(""),e.act({type:"clearLocation"})},children:a("tools.location.clear")}):null]}),e.current?r("p",{role:"status",className:"text-xs text-muted-foreground",children:a("tools.location.current",{latitude:e.current.latitude,longitude:e.current.longitude})}):null]})}var Pr={camera:"tools.permissions.camera",microphone:"tools.permissions.microphone",photos:"tools.permissions.photos",contacts:"tools.permissions.contacts",calendar:"tools.permissions.calendar",reminders:"tools.permissions.reminders",location:"tools.permissions.location",notifications:"tools.permissions.notifications",motion:"tools.permissions.motion","media-library":"tools.permissions.mediaLibrary",faceid:"tools.permissions.faceId"},Ar=new Set(["camera","microphone","photos","contacts","calendar","location","notifications","motion"]);function uo(e){let{t:a}=D(),t=e.platform==="ios",[o,l]=g(""),[d,s]=g("camera"),n=o.trim()||e.defaultAppId,u=oo.filter(c=>t||Ar.has(c)).map(c=>({value:c,label:a(!t&&c==="motion"?"tools.permissions.activity":Pr[c])})),i=c=>{e.act({type:"setPermission",appId:n,permission:d,decision:c})};return f(ie,{title:a("tools.permissions.title"),children:[r(ae,{size:"compact",className:"font-mono",placeholder:e.defaultAppId||a("tools.permissions.appId"),"aria-label":a("tools.permissions.appId"),value:o,disabled:e.disabled,onChange:c=>l(c.target.value)}),f("div",{className:"flex flex-wrap items-center gap-1.5",children:[r(Ue,{ariaLabel:a("tools.permissions.permission"),value:d,options:u,placeholder:a("tools.unknown"),disabled:e.disabled,onChange:c=>(s(c),Promise.resolve())}),r(S,{size:"xs",variant:"outline",disabled:e.disabled||!n,onClick:()=>i("grant"),children:a("tools.permissions.grant")}),r(S,{size:"xs",variant:"outline",disabled:e.disabled||!n,onClick:()=>i("revoke"),children:a("tools.permissions.revoke")}),t?r(S,{size:"xs",variant:"ghost",disabled:e.disabled||!n,onClick:()=>i("reset"),children:a("tools.permissions.reset")}):null]})]})}var Tr=e=>{let a=e;try{let t=JSON.parse(e);typeof t=="object"&&t!==null&&!Array.isArray(t)&&(a=t)}catch{}try{return ro(a),a}catch{return null}};function io(e){let{t:a}=D(),[t,o]=g(""),l=t.trim(),d=l?Tr(l):null,s=e.appId;return f(ie,{title:a("tools.push.title"),children:[r(Za,{size:"sm",rows:4,className:"font-mono",placeholder:a("tools.push.placeholder"),"aria-label":a("tools.push.placeholder"),value:t,disabled:e.disabled||!s,onChange:n=>o(n.target.value)}),f("div",{className:"flex items-center gap-2",children:[r(S,{size:"xs",variant:"outline",disabled:e.disabled||!s||d===null,onClick:()=>{s&&d!==null&&e.act({type:"sendPush",appId:s,payload:d})},children:a("tools.push.send")}),s?l&&d===null?r("p",{className:"text-xs text-destructive-foreground",children:a("tools.push.invalid")}):null:r("p",{className:"text-xs text-muted-foreground",children:a("tools.push.needsApp")})]})]})}var so=100;function fo(e){let{t:a}=D(),[t,o]=g(!1),[l,d]=g([]),{transport:s,platform:n,deviceId:u}=e;return B(()=>{if(!t)return;let i=ut({transport:s,platform:n,deviceId:u},(c,L)=>{d(v=>{let C=L?[...c]:[...v,...c];return C.length>so?C.slice(-so):C})});return()=>{i(),d([])}},[t,s,n,u]),f(Xe,{open:t,onOpenChange:o,children:[f($e,{className:"flex w-full items-center gap-1.5 border-b px-3 py-2.5 text-left text-xs font-medium text-muted-foreground",children:[a("tools.eventLog.title"),r(be,{className:`ml-auto size-3.5 transition-transform ${t?"rotate-180":""}`})]}),r(je,{children:r("ol",{className:"max-h-64 overflow-y-auto px-3 py-2 font-mono text-ui-2xs leading-relaxed",children:l.length===0?r("li",{className:"text-muted-foreground",children:a("tools.eventLog.empty")}):l.map(i=>f("li",{className:"flex gap-2",children:[r("span",{className:"shrink-0 text-muted-foreground",children:i.timestamp.slice(11,19)}),r("span",{className:"truncate",children:i.summary})]},i.id))})})]})}var Br=640,Mr={light:"tools.settings.light",dark:"tools.settings.dark"},Rr={small:"tools.settings.textSmall",default:"tools.settings.textDefault",large:"tools.settings.textLarge","extra-large":"tools.settings.textExtraLarge"},Fr={clear:"tools.settings.glassClear",tinted:"tools.settings.glassTinted"},Or={none:"tools.settings.filterNone",grayscale:"tools.settings.filterGrayscale","red-green":"tools.settings.filterRedGreen","green-red":"tools.settings.filterGreenRed","blue-yellow":"tools.settings.filterBlueYellow"},Er={portrait:"tools.settings.orientationPortrait",landscape_left:"tools.settings.orientationLandscapeLeft",portrait_upside_down:"tools.settings.orientationUpsideDown",landscape_right:"tools.settings.orientationLandscapeRight"},Ur=[{setting:"reduceMotion",labelKey:"tools.settings.reduceMotion"},{setting:"increaseContrast",labelKey:"tools.settings.increaseContrast"},{setting:"reduceTransparency",labelKey:"tools.settings.reduceTransparency"},{setting:"showBorders",labelKey:"tools.settings.showBorders"},{setting:"voiceOver",labelKey:"tools.settings.voiceOver"},{setting:"networkEnabled",labelKey:"tools.settings.network"}];function co(e){let{t:a}=D(),{device:t,controls:o}=e,{detail:l,pending:d,error:s,foregroundApp:n,disabled:u,act:i}=o,c=l?.settings,L=t.platform==="ios",v=G(null),[C,p]=g(!0);Ea(()=>{let m=v.current?.parentElement;if(!m)return;let y=()=>p(m.clientWidth<Br);y();let R=new ResizeObserver(y);return R.observe(m),()=>R.disconnect()},[]),B(()=>o.followDevice(),[o.followDevice]);let h=Yt.map(m=>({value:m,label:a(Rr[m])})),T=Ur.filter(m=>Pa(t.platform,{type:"setToggle",setting:m.setting,value:!0}));return f("aside",{ref:v,"aria-label":a("tools.title"),className:`flex min-h-0 flex-col border-l bg-background text-sm ${C?"absolute inset-y-0 right-0 z-10 w-full max-w-72 shadow-lg":"w-72 shrink-0"}`,children:[f("div",{className:"flex h-9 shrink-0 items-center gap-2 border-b px-3",children:[r("span",{className:"font-medium",children:a("tools.title")}),d?r(z,{size:"sm"}):null,r(S,{size:"icon-xs",variant:"ghost-muted","aria-label":a("tools.close"),className:"ml-auto",onClick:e.onClose,children:r(Q,{})})]}),f("div",{className:"min-h-0 flex-1 overflow-y-auto",children:[s?r("p",{role:"alert",className:"border-b bg-destructive/10 px-3 py-2 text-xs text-destructive-foreground",children:s}):null,l===null&&!s?f("div",{className:"flex items-center gap-2 px-3 py-3 text-xs text-muted-foreground",children:[r(z,{size:"sm"}),a("tools.reading")]}):null,f(ie,{title:a("tools.app.title"),children:[r(se,{label:a("tools.app.foreground"),children:r("span",{className:"truncate font-mono text-xs",children:n?.id??a("tools.app.none")})}),n?f("div",{className:"flex gap-1.5",children:[r(S,{size:"xs",variant:"outline",disabled:u,onClick:()=>{i({type:"terminateApp",appId:n.id})},children:a("tools.app.terminate")}),r(S,{size:"xs",variant:"outline",disabled:u,onClick:()=>{i({type:"relaunchApp",appId:n.id})},children:a("tools.app.relaunch")})]}):null,r(Ba,{placeholder:a("tools.app.urlPlaceholder"),action:a("tools.app.open"),disabled:u,onSubmit:m=>i({type:"openUrl",url:m})}),r(Ba,{placeholder:a(L?"tools.app.bundleIdPlaceholder":"tools.app.packagePlaceholder"),action:a("tools.app.launch"),disabled:u,fallback:n?.id,onSubmit:m=>i({type:"launchApp",appId:m})})]}),f(ie,{title:a(L?"tools.settings.titleIos":"tools.settings.titleAndroid"),children:[r(se,{label:a("tools.settings.appearance"),children:r(Ta,{label:a("tools.settings.appearance"),value:c?.appearance,options:Qt.map(m=>({value:m,label:a(Mr[m])})),disabled:u,onChange:m=>i({type:"setAppearance",value:m})})}),r(se,{label:a("tools.settings.textSize"),children:r(Ue,{ariaLabel:a("tools.settings.textSize"),value:c?.textSize??null,options:h,placeholder:a("tools.unknown"),disabled:u,onChange:m=>i({type:"setTextSize",value:m})})}),L?f(Z,{children:[r(se,{label:a("tools.settings.liquidGlass"),children:r(Ta,{label:a("tools.settings.liquidGlass"),value:c?.liquidGlass,options:eo.map(m=>({value:m,label:a(Fr[m])})),disabled:u,onChange:m=>i({type:"setLiquidGlass",value:m})})}),r(se,{label:a("tools.settings.colorFilter"),children:r(Ue,{ariaLabel:a("tools.settings.colorFilter"),value:c?.colorFilter??null,options:ao.map(m=>({value:m,label:a(Or[m])})),placeholder:a("tools.unknown"),disabled:u,onChange:m=>i({type:"setColorFilter",value:m})})})]}):r(se,{label:a("tools.settings.orientation"),children:r(Ue,{ariaLabel:a("tools.settings.orientation"),value:null,options:to.map(m=>({value:m,label:a(Er[m])})),placeholder:a("tools.settings.rotateTo"),disabled:u,onChange:m=>i({type:"setOrientation",value:m})})}),T.map(m=>r(Aa,{label:a(m.labelKey),checked:c?.[m.setting],disabled:u,onChange:y=>i({type:"setToggle",setting:m.setting,value:y})},m.setting))]}),r(ie,{title:a("tools.accessibility.title"),children:r(Aa,{label:a("tools.accessibility.overlay"),checked:e.axOverlay,disabled:!1,onChange:m=>(e.onAxOverlayChange(m),Promise.resolve())})}),r(no,{current:o.location,canClear:Pa(t.platform,{type:"clearLocation"}),disabled:u,act:i}),r(uo,{platform:t.platform,defaultAppId:n?.id??"",disabled:u,act:i}),L?r(io,{appId:n?.id,disabled:u,act:i}):null,L?r(fo,{transport:e.transport,platform:t.platform,deviceId:t.id}):null]})]})}var qr=2e4,Ma=class extends Error{status;constructor(a){super(`Screenshot capture failed (${a}). Try again.`),this.status=a}};async function po(e,a,t,o){let l=AbortSignal.timeout(qr),d=await e.fetch(`${me(a)}/api/screenshot?device=${encodeURIComponent(t)}`,{method:"POST",signal:o?AbortSignal.any([o,l]):l});if(!d.ok)throw new Ma(d.status);let s=await d.blob();if(!s.size)throw new Error("The device returned an empty screenshot. Try again.");return s.type?s:new Blob([s],{type:"image/png"})}var Hr=3e3,Ra=e=>e instanceof Error?e.message:String(e);function mo(e){let{environmentId:a,device:t}=e,o=te(),l=E(),{t:d}=D(),[s,n]=g(null),[u,i]=g(null),[c,L]=g(!1),[v,C]=g(null),p=G(!1),h=G(0),T=G(!1),m={hostId:t.hostId,deviceId:t.id},y=P=>o("detail",a,m).then(b=>{h.current===P&&(n(b),C(null))},b=>{h.current===P&&(n(null),C(Ra(b)))});B(()=>{let P=++h.current;return y(P),()=>{h.current++}},[a,t.hostId,t.id]);let R=async P=>{if(p.current||s===null)return!1;p.current=!0;let b=++h.current;L(!0),C(null);try{let U=await o("action",a,{...m,...P});return h.current===b?n(U):await y(++h.current),P.type==="setLocation"?i({latitude:P.latitude,longitude:P.longitude}):P.type==="clearLocation"&&i(null),!0}catch(U){return h.current===b&&C(Ra(U)),l.notify(d("rail.actionFailed"),"error",Ra(U)),!1}finally{p.current=!1,L(!1)}},F=G(()=>{});F.current=()=>{if(p.current||T.current)return;T.current=!0;let P=++h.current;o("detail",a,m).then(b=>{h.current===P&&n(b)},()=>{}).finally(()=>{T.current=!1})};let _=Y(()=>{F.current();let P=setInterval(()=>F.current(),Hr);return()=>clearInterval(P)},[]);return{detail:s,location:u,pending:c,error:v,act:R,followDevice:_,disabled:c||s===null,foregroundApp:e.foreground===void 0?s?.foregroundApp??null:e.foreground}}var Nr=()=>typeof window<"u"&&"ReactNativeWebView"in window;function go(e){let{t:a}=D(),t=E(),o=sa(e.environmentId),[l,d]=g(null),[s,n]=g(!1),[u,i]=g(!1),[c,L]=g(!1),[v,C]=g(),[p,h]=g(!1),[T,m]=g(null),[y,R]=g(null),F=G(null),_=G(null),P=o.status==="ready"?o.transport:null,b=mo({environmentId:e.environmentId,device:e.device,foreground:v}),U=Y(q=>d(q),[]),W=Y(q=>n(q),[]);B(()=>{if(!P)return;let q=nt({transport:P,platform:e.device.platform,deviceId:e.device.id},C);return()=>{q(),C(void 0)}},[e.device.id,e.device.platform,P]),B(()=>()=>{F.current?.abort(),_.current&&URL.revokeObjectURL(_.current)},[]);let fe=()=>{if(!P||F.current)return;let q=new AbortController;F.current=q,h(!0),m(null),po(P,e.device.platform,e.device.id,q.signal).then(K=>{if(q.signal.aborted)return;_.current&&URL.revokeObjectURL(_.current);let $=URL.createObjectURL(K);if(_.current=$,Nr()){R($);return}let V=document.createElement("a");V.href=$,V.download=`${e.device.name.replace(/[^a-z0-9-]/gi,"-")}-${Date.now()}.png`,document.body.append(V),V.click(),V.remove()}).catch(K=>{q.signal.aborted||(m(K instanceof Error?K.message:a("workspace.screenshotFailed")),t.notify(a("workspace.screenshotFailed"),"error",K instanceof Error?K.message:void 0))}).finally(()=>{F.current===q&&(F.current=null,h(!1))})};return o.status!=="ready"?r(ee,{name:e.device.name,description:e.device.version,stage:o.status==="failed"?"error":"connecting",message:o.status==="failed"?o.message??a("workspace.needsNewerApp"):a("stream.connecting"),children:r(S,{size:"sm",variant:"outline",onClick:e.onBack,children:a("workspace.allDevices")})}):f("div",{className:"relative flex min-h-0 min-w-0 flex-1",children:[f("div",{className:"relative flex min-h-0 min-w-0 flex-1 flex-col",children:[T||b.error&&!u?r("p",{role:"alert",className:"px-3 py-2 text-xs text-destructive-foreground",children:T??b.error}):null,f("div",{className:"relative min-h-0 flex-1",children:[r(ra,{transport:o.transport,platform:e.device.platform,deviceId:e.device.id,deviceName:e.device.name,deviceDescription:e.device.version,axOverlay:c,withControls:!0,onHandle:U,onStreaming:W}),r(Zt,{platform:e.device.platform,handle:l,streaming:s,controls:b,screenshotPending:p,onScreenshot:fe,toolsOpen:u,onTools:()=>i(!u),onClose:e.onClose,onPowerOff:e.onPowerOff,onFloat:e.onFloat})]})]}),u?r(co,{device:e.device,controls:b,transport:o.transport,axOverlay:c,onAxOverlayChange:L,onClose:()=>i(!1)}):null,y?f("div",{className:"absolute inset-0 z-20 flex flex-col items-center justify-center gap-3 bg-background/95 p-4",children:[r("img",{src:y,alt:a("workspace.screenshotAlt"),className:"max-h-[80%] max-w-full object-contain"}),r("p",{className:"text-xs text-muted-foreground",children:a("workspace.screenshotSaveHint")}),f(S,{size:"sm",variant:"outline",onClick:()=>R(null),children:[r(Q,{}),a("workspace.closeBrowser")]})]}):null]})}var Ce=e=>e instanceof Error?e.message:String(e);function Lo(e){let{environmentId:a,threadId:t}=e,{t:o}=D(),{state:l,loaded:d,error:s,unavailable:n}=Le(a),u=te(),[i,c]=g(null),[L,v]=g(null),C=Ga(a,t),p=x=>Ge(a,t,x),h=E(),T=ce(h,"floating"),m=()=>{c(null),u("refresh",a).catch(x=>{c(Ce(x)),h.notify(o("panel.refreshFailed"),"error",Ce(x))})};B(()=>{!d||n||u("refresh",a).catch(()=>{})},[a,d,u,n]);let y=ue(()=>l.sessions.filter(x=>x.threadId===t),[l.sessions,t]),R=Gr(y,C),F=R?l.devices.find(x=>x.hostId===R.hostId&&x.id===R.deviceId):void 0,_=F&&R?Se(F):null;B(()=>{h.floating?.present({environmentId:a,threadId:t},_)}),B(()=>()=>h.floating?.present({environmentId:a,threadId:t},null),[h,a,t]);let P=ue(()=>zr(l),[l]),b=l.hostStatuses[he],U=b?.status==="ready",W=b?.status==="installing"||b?.status==="starting",fe=ya(),q=l.bootingDevices.filter(x=>x.threadId===t),K=l.hosts.flatMap(x=>x.platforms.filter(H=>!H.available)),$=async x=>{c(null),v(x),ca(a,t,j(x));try{await u("open",a,{threadId:t,hostId:x.hostId,deviceId:x.id,platform:x.platform}),p(j(x))}catch(H){ca(a,t,j(x),!1),c(Ce(H)),h.notify(o("panel.openFailed"),"error",Ce(H))}finally{v(null)}},V=x=>{R&&(c(null),u("close",a,{threadId:t,hostId:R.hostId,deviceId:R.deviceId,shutdown:x}).then(()=>p(null)).catch(H=>{c(Ce(H)),h.notify(o("panel.closeFailed"),"error",Ce(H))}))};return n?r(ee,{name:o("panel.title"),stage:"error",message:o("panel.unavailable")}):f("div",{className:"flex size-full min-h-0 flex-col",children:[q.length>0?r("div",{role:"status",className:"border-b px-3 py-2 text-xs text-muted-foreground",children:o("panel.booting",{names:q.map(x=>x.name).join(", ")})}):null,W&&!F?null:r(Nt,{detail:b,onRetry:()=>u("refresh",a).catch(()=>{})}),i||s?f("div",{role:"alert",className:"flex items-start gap-2 border-b bg-destructive/5 px-3 py-2 text-xs text-destructive-foreground",children:[r("p",{className:"min-w-0 flex-1 whitespace-pre-wrap break-words",children:i??s}),i?r(S,{size:"icon-xs",variant:"ghost","aria-label":o("panel.dismissError"),onClick:()=>c(null),children:r(Q,{className:"size-3"})}):null]}):null,r("div",{className:"relative flex min-h-0 flex-1",children:F&&R?r(go,{environmentId:a,device:F,onBack:()=>p(""),onFloat:T?()=>h.floating?.open({environmentId:a,threadId:t},{...Se(F),reason:"user"}):void 0,onPowerOff:()=>V(!0),onClose:()=>V(!1)},`${a}\0${j(F)}`):L||W||!d?r(ee,{name:L?.name??o("panel.title"),...L?{description:L.version}:{},stage:"opening",message:L?L.booted?o("panel.opening"):o("panel.starting"):W&&b?fe(b):o("panel.finding")}):r(Vr,{environmentId:a,host:l.hosts.find(x=>x.id===he),grouped:P,hostReady:U,hostFailed:b?.status==="failed",unavailableReasons:K,showNoAvdHint:U&&!l.devices.some(x=>x.platform==="android")&&!K.some(x=>x.platform==="android"),pendingKey:L?j(L):null,onOpen:x=>{$(x)},onRefresh:m})})]})}function Vr(e){let{t:a}=D(),t=e.grouped.length===0;return r("div",{className:"flex size-full flex-col overflow-y-auto px-4 py-6 text-sm text-muted-foreground",children:f("div",{className:`mx-auto flex w-full max-w-xl flex-col gap-5 ${t?"items-center text-center":""}`,children:[r($t,{environmentId:e.environmentId,iosSupported:!e.unavailableReasons.some(o=>o.reasonCode==="ios-needs-macos")},e.environmentId),t?f(Z,{children:[r(Ie,{className:"size-6 opacity-60"}),r("p",{className:"max-w-sm",children:e.hostFailed?a("panel.hubFailed"):a("panel.empty")})]}):null,e.hostReady?e.grouped.map(o=>f("section",{className:"w-full space-y-2 text-left",children:[f("h3",{className:"flex items-center gap-2 font-medium",children:[r(Ie,{className:"size-4 shrink-0"}),o.platform==="ios"?a("panel.platformIos"):a("panel.platformAndroid")]}),r("ul",{className:"divide-y rounded-md border",children:o.devices.map(l=>r("li",{children:f(S,{variant:"ghost",className:"h-auto min-h-11 w-full justify-between gap-3 rounded-none px-3 py-2 text-left font-normal",disabled:e.pendingKey!==null,onClick:()=>e.onOpen(l),children:[f("span",{className:"min-w-0 flex-1",children:[r("span",{className:"block truncate text-foreground",children:l.name}),f("span",{className:"block text-xs",children:[l.version,","," ",l.booted?a("panel.running"):a("panel.stopped")]})]}),e.pendingKey===j(l)?r(z,{size:"xs"}):r("span",{className:"text-xs",children:l.booted?a("panel.open"):a("panel.start")})]})},j(l)))})]},o.platform)):null,e.unavailableReasons.map(o=>r("p",{className:"max-w-sm text-xs",children:o.reasonCode?a(`unavailable.${o.reasonCode}`,{root:o.sdkRoot??""}):o.reason},`${o.platform}:${o.reasonCode}`)),e.showNoAvdHint?r("p",{className:"max-w-sm text-xs",children:a("panel.noAvd")}):null,f("div",{className:`flex flex-wrap items-center gap-2 ${t?"self-center":"self-start"}`,children:[r(S,{variant:t?"outline":"ghost",size:"sm",onClick:e.onRefresh,children:a("panel.refresh")}),r(Vt,{environmentId:e.environmentId,host:e.host,busy:!1})]})]})})}function Gr(e,a){if(a!==""){if(a!==null){let t=e.find(o=>j({hostId:o.hostId,id:o.deviceId})===a);if(t)return t}return e.toSorted((t,o)=>o.openedAt.localeCompare(t.openedAt))[0]}}function zr(e){let a=[];for(let t of["ios","android"]){let o=e.devices.filter(l=>l.platform===t).toSorted((l,d)=>Number(d.booted)-Number(l.booted)||l.name.localeCompare(d.name));o.length>0&&a.push({platform:t,devices:o})}return a}function ho({environmentId:e,threadId:a}){let t=E(),{state:o,loaded:l}=Le(e),d=G(null);return B(()=>{if(!l||!ce(t,"floating"))return;let s=`${e}\0${a}`,n=d.current?.key===s?d.current.seen:null,{seen:u,opened:i}=za({environmentId:e,threadId:a,previous:n,sessions:o.sessions,devices:o.devices});d.current={key:s,seen:u};for(let c of i)t.floating?.open({environmentId:e,threadId:a},{...Se(c),reason:"agent",panelId:Ne})},[t,e,l,o.devices,o.sessions,a]),null}function _r(e){return{panels:{device:function(t){return f(He,{value:e,children:[r("style",{children:na}),r("div",{className:`${ze} flex h-full min-h-0 flex-1 flex-col`,children:r(Lo,{environmentId:t.environmentId,threadId:t.threadId})})]})}},views:{deviceFloat:function(t){return f(He,{value:e,children:[r("style",{children:na}),r("div",{className:`${ze} relative size-full`,children:r(Ft,{...t})})]})},deviceSessions:function(t){return r(He,{value:e,children:r(ho,{environmentId:t.environmentId,threadId:t.threadId})})}}}}export{_r as default};
|
package/dist/index.js
CHANGED
|
@@ -3,7 +3,7 @@ import * as NodePath9 from "node:path";
|
|
|
3
3
|
import { definePlugin, PLUGIN_PROXY_DIRECT } from "@ycodium-ai/plugin-api";
|
|
4
4
|
|
|
5
5
|
// ../../packages/plugin-api/src/version.ts
|
|
6
|
-
var PLUGIN_API_VERSION =
|
|
6
|
+
var PLUGIN_API_VERSION = 148;
|
|
7
7
|
|
|
8
8
|
// src/types.ts
|
|
9
9
|
var DEVICE_PLATFORMS = ["ios", "android"];
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ycodium-ai/plugin-devices",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.5100",
|
|
4
4
|
"description": "Lets agents drive iOS Simulators and Android Emulators on this machine.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"android",
|
|
@@ -34,9 +34,9 @@
|
|
|
34
34
|
"tailwindcss": "^4.0.0",
|
|
35
35
|
"typescript": "~6.0.3",
|
|
36
36
|
"vite-plus": "0.2.2",
|
|
37
|
-
"@ycodium-ai/plugin-api": "0.2.
|
|
38
|
-
"ycodium-
|
|
39
|
-
"ycodium-
|
|
37
|
+
"@ycodium-ai/plugin-api": "0.2.5100",
|
|
38
|
+
"ycodium-fetch-ports": "0.0.0",
|
|
39
|
+
"ycodium-sse-stream": "0.0.0"
|
|
40
40
|
},
|
|
41
41
|
"ycodium": {
|
|
42
42
|
"plugin": "./dist/index.js",
|