@ycodium-ai/plugin-devices 0.2.2892 → 0.2.2898

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.
Files changed (2) hide show
  1. package/assets/ui.js +4 -4
  2. package/package.json +3 -3
package/assets/ui.js CHANGED
@@ -453,8 +453,8 @@ var Je=`/*! tailwindcss v4.3.0 | MIT License | https://tailwindcss.com */
453
453
  .whitespace-pre-wrap:where(:scope, *) {
454
454
  white-space: pre-wrap;
455
455
  }
456
- .text-destructive:where(:scope, *) {
457
- color: var(--destructive);
456
+ .text-destructive-foreground:where(:scope, *) {
457
+ color: var(--destructive-foreground);
458
458
  }
459
459
  .text-foreground:where(:scope, *) {
460
460
  color: var(--contrast-foreground);
@@ -539,7 +539,7 @@ var Je=`/*! tailwindcss v4.3.0 | MIT License | https://tailwindcss.com */
539
539
  }
540
540
  }
541
541
  }
542
- `;var to=window.__ycodiumPluginHost.react;var{Activity:vr,Children:wr,Component:br,Fragment:kr,Profiler:Dr,PureComponent:Pr,StrictMode:Ar,Suspense:Tr,__CLIENT_INTERNALS_DO_NOT_USE_OR_WARN_USERS_THEY_CANNOT_UPGRADE:Mr,__COMPILER_RUNTIME:Br,act:Rr,cache:Fr,cacheSignal:Ur,captureOwnerStack:Or,cloneElement:qr,createContext:Sa,createElement:Y,createRef:Hr,forwardRef:Be,isValidElement:Er,lazy:Nr,memo:Gr,startTransition:Vr,unstable_useCacheRefresh:zr,use:_r,useActionState:Wr,useCallback:ee,useContext:ya,useDebugValue:Kr,useDeferredValue:Xr,useEffect:k,useEffectEvent:$r,useId:jr,useImperativeHandle:Zr,useInsertionEffect:Jr,useLayoutEffect:va,useMemo:ae,useOptimistic:Qr,useReducer:Yr,useRef:U,useState:h,useSyncExternalStore:wa,useTransition:el,version:al}=to;var ba=Sa(null),Re=ba.Provider;function O(){let e=ya(ba);if(e===null)throw new Error("The devices panel has not been registered.");return e}var ka=window.__ycodiumPluginHost.modules?.["@ycodium-ai/plugin-api/ui"];if(!ka)throw new Error("This plugin needs a newer Ycodium app. Update the app.");var{PLUGIN_UI_BRIDGE_VERSION:ll,PLUGIN_UI_FLOATING_VIEW_PROP:Da,PLUGIN_UI_GLOBAL_KEY:sl,PLUGIN_UI_HOST_CAPABILITIES:dl,PLUGIN_UI_HOST_COMMAND_PALETTE_UNAVAILABLE_MESSAGE:ul,PLUGIN_UI_HOST_UPGRADE_MESSAGE:nl,pluginUiHostHasCapability:oe}=ka;var oo="deviceFloat",Fe="device",z=e=>`${e.hostId}\0${e.id}`;function ge(e){let a={hostId:e.hostId,deviceId:e.id,platform:e.platform};return{viewId:oo,key:z(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 Pa(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 Qe=new Map,Ye=new Set,Ue=(e,a)=>`${e}\0${a}`;function Aa(e,a){return wa(t=>(Ye.add(t),()=>{Ye.delete(t)}),()=>Qe.get(Ue(e,a))??null)}function Oe(e,a,t){let o=Ue(e,a);if((Qe.get(o)??null)!==t){Qe.set(o,t);for(let r of Ye)r()}}var ea=new Set;function aa(e,a,t,o=!0){let r=`${Ue(e,a)}\0${t}`;o?ea.add(r):ea.delete(r)}function Ta(e){let a=new Set,t=[];for(let o of e.sessions){if(o.threadId!==e.threadId)continue;let r=e.devices.find(u=>u.hostId===o.hostId&&u.id===o.deviceId);if(r===void 0)continue;let d=z(r);if(a.add(d),e.previous===null||e.previous.has(d))continue;let s=`${Ue(e.environmentId,e.threadId)}\0${d}`;ea.delete(s)||t.push(r)}return{seen:a,opened:t}}var qe="ycodium-devices-ui";function w(e){return(a=>Y(O().ui[e],{...a,className:`${qe} ${typeof a.className=="string"?a.className:""}`}))}var C=w("Button"),H=w("Spinner"),Ma=w("Switch"),Ba=w("Tooltip"),Ra=w("TooltipPopup"),Fa=w("TooltipTrigger"),He=w("Menu"),Ee=w("MenuPopup"),Le=w("MenuItem"),Ua=w("MenuSeparator"),Ne=w("MenuTrigger"),Oa=w("MenuRadioGroup"),qa=w("MenuRadioItem"),he=w("Input"),Ha=w("Textarea"),ta=w("Select"),oa=w("SelectTrigger"),ra=w("SelectValue"),la=w("SelectPopup"),sa=w("SelectItem"),Ea=w("Collapsible"),Na=w("CollapsibleTrigger"),Ga=w("CollapsiblePanel"),Va=w("ToggleGroup"),za=w("Toggle"),_a=w("Popover"),Wa=w("PopoverTrigger"),Ka=w("PopoverPopup");var{jsx:l,jsxs:p,Fragment:re}=window.__ycodiumPluginHost.jsxRuntime;function X(e){return p("div",{className:"flex size-full flex-col items-center justify-center gap-3 p-6 text-center",children:[e.stage==="error"?null:l(H,{size:"sm"}),p("div",{className:"space-y-1",children:[l("p",{className:"text-sm font-medium text-foreground",children:e.name}),e.description?l("p",{className:"text-xs text-muted-foreground",children:e.description}):null]}),l("p",{role:e.stage==="error"?"alert":"status",className:e.stage==="error"?"max-w-sm whitespace-pre-wrap break-words text-xs text-destructive":"max-w-sm text-xs text-muted-foreground",children:e.message}),e.children]})}async function Ge(e,a,t){let o=e.body;if(!o)throw new Error("The response has no body to stream.");let r=o.getReader(),d=()=>{r.cancel().catch(()=>{})};if(t?.aborted)return d();t?.addEventListener("abort",d,{once:!0});try{for(;;){let{done:s,value:u}=await r.read();if(s||t?.aborted)return;a(u)}}catch(s){if(t?.aborted)return;throw s}finally{t?.removeEventListener("abort",d)}}var da=class{decoder=new TextDecoder;pending="";first=!0;data=[];eventName="";lastId=null;push(a){let t=this.pending+this.decoder.decode(a,{stream:!0});this.first&&t.length>0&&(this.first=!1,t.charCodeAt(0)===65279&&(t=t.slice(1)));let o=[],r=0;for(let d=0;d<t.length;d++){let s=t[d];if(!(s!==`
542
+ `;var to=window.__ycodiumPluginHost.react;var{Activity:vr,Children:wr,Component:br,Fragment:kr,Profiler:Dr,PureComponent:Pr,StrictMode:Ar,Suspense:Tr,__CLIENT_INTERNALS_DO_NOT_USE_OR_WARN_USERS_THEY_CANNOT_UPGRADE:Mr,__COMPILER_RUNTIME:Br,act:Rr,cache:Fr,cacheSignal:Ur,captureOwnerStack:Or,cloneElement:qr,createContext:Sa,createElement:Y,createRef:Hr,forwardRef:Be,isValidElement:Er,lazy:Nr,memo:Gr,startTransition:Vr,unstable_useCacheRefresh:zr,use:_r,useActionState:Wr,useCallback:ee,useContext:ya,useDebugValue:Kr,useDeferredValue:Xr,useEffect:k,useEffectEvent:$r,useId:jr,useImperativeHandle:Zr,useInsertionEffect:Jr,useLayoutEffect:va,useMemo:ae,useOptimistic:Qr,useReducer:Yr,useRef:U,useState:h,useSyncExternalStore:wa,useTransition:el,version:al}=to;var ba=Sa(null),Re=ba.Provider;function O(){let e=ya(ba);if(e===null)throw new Error("The devices panel has not been registered.");return e}var ka=window.__ycodiumPluginHost.modules?.["@ycodium-ai/plugin-api/ui"];if(!ka)throw new Error("This plugin needs a newer Ycodium app. Update the app.");var{PLUGIN_UI_BRIDGE_VERSION:ll,PLUGIN_UI_FLOATING_VIEW_PROP:Da,PLUGIN_UI_GLOBAL_KEY:sl,PLUGIN_UI_HOST_CAPABILITIES:dl,PLUGIN_UI_HOST_COMMAND_PALETTE_UNAVAILABLE_MESSAGE:ul,PLUGIN_UI_HOST_UPGRADE_MESSAGE:nl,pluginUiHostHasCapability:oe}=ka;var oo="deviceFloat",Fe="device",z=e=>`${e.hostId}\0${e.id}`;function ge(e){let a={hostId:e.hostId,deviceId:e.id,platform:e.platform};return{viewId:oo,key:z(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 Pa(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 Qe=new Map,Ye=new Set,Ue=(e,a)=>`${e}\0${a}`;function Aa(e,a){return wa(t=>(Ye.add(t),()=>{Ye.delete(t)}),()=>Qe.get(Ue(e,a))??null)}function Oe(e,a,t){let o=Ue(e,a);if((Qe.get(o)??null)!==t){Qe.set(o,t);for(let r of Ye)r()}}var ea=new Set;function aa(e,a,t,o=!0){let r=`${Ue(e,a)}\0${t}`;o?ea.add(r):ea.delete(r)}function Ta(e){let a=new Set,t=[];for(let o of e.sessions){if(o.threadId!==e.threadId)continue;let r=e.devices.find(u=>u.hostId===o.hostId&&u.id===o.deviceId);if(r===void 0)continue;let d=z(r);if(a.add(d),e.previous===null||e.previous.has(d))continue;let s=`${Ue(e.environmentId,e.threadId)}\0${d}`;ea.delete(s)||t.push(r)}return{seen:a,opened:t}}var qe="ycodium-devices-ui";function w(e){return(a=>Y(O().ui[e],{...a,className:`${qe} ${typeof a.className=="string"?a.className:""}`}))}var C=w("Button"),H=w("Spinner"),Ma=w("Switch"),Ba=w("Tooltip"),Ra=w("TooltipPopup"),Fa=w("TooltipTrigger"),He=w("Menu"),Ee=w("MenuPopup"),Le=w("MenuItem"),Ua=w("MenuSeparator"),Ne=w("MenuTrigger"),Oa=w("MenuRadioGroup"),qa=w("MenuRadioItem"),he=w("Input"),Ha=w("Textarea"),ta=w("Select"),oa=w("SelectTrigger"),ra=w("SelectValue"),la=w("SelectPopup"),sa=w("SelectItem"),Ea=w("Collapsible"),Na=w("CollapsibleTrigger"),Ga=w("CollapsiblePanel"),Va=w("ToggleGroup"),za=w("Toggle"),_a=w("Popover"),Wa=w("PopoverTrigger"),Ka=w("PopoverPopup");var{jsx:l,jsxs:p,Fragment:re}=window.__ycodiumPluginHost.jsxRuntime;function X(e){return p("div",{className:"flex size-full flex-col items-center justify-center gap-3 p-6 text-center",children:[e.stage==="error"?null:l(H,{size:"sm"}),p("div",{className:"space-y-1",children:[l("p",{className:"text-sm font-medium text-foreground",children:e.name}),e.description?l("p",{className:"text-xs text-muted-foreground",children:e.description}):null]}),l("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]})}async function Ge(e,a,t){let o=e.body;if(!o)throw new Error("The response has no body to stream.");let r=o.getReader(),d=()=>{r.cancel().catch(()=>{})};if(t?.aborted)return d();t?.addEventListener("abort",d,{once:!0});try{for(;;){let{done:s,value:u}=await r.read();if(s||t?.aborted)return;a(u)}}catch(s){if(t?.aborted)return;throw s}finally{t?.removeEventListener("abort",d)}}var da=class{decoder=new TextDecoder;pending="";first=!0;data=[];eventName="";lastId=null;push(a){let t=this.pending+this.decoder.decode(a,{stream:!0});this.first&&t.length>0&&(this.first=!1,t.charCodeAt(0)===65279&&(t=t.slice(1)));let o=[],r=0;for(let d=0;d<t.length;d++){let s=t[d];if(!(s!==`
543
543
  `&&s!=="\r")){if(s==="\r"&&d===t.length-1)break;this.line(t.slice(r,d),o),s==="\r"&&t[d+1]===`
544
544
  `&&d++,r=d+1}}return this.pending=t.slice(r),o}line(a,t){if(a===""){this.data.length>0&&t.push({event:this.eventName||"message",data:this.data.join(`
545
- `),id:this.lastId}),this.data=[],this.eventName="";return}if(a.startsWith(":"))return;let o=a.indexOf(":"),r=o===-1?a:a.slice(0,o),d=o===-1?"":a.slice(o+1);d.startsWith(" ")&&(d=d.slice(1)),r==="data"?this.data.push(d):r==="event"?this.eventName=d:r==="id"&&!d.includes("\0")&&(this.lastId=d)}};async function Xa(e,a,t){if(!e.ok)throw await e.body?.cancel().catch(()=>{}),new Error(`Event stream failed (${e.status}).`);let o=new da;await Ge(e,r=>{for(let d of o.push(r))a(d)},t)}var le=e=>e==="ios"?"/vendor/serve-sim":"/vendor/serve-emu";var ro=1e3,lo=500,Ve=(e,a,t)=>`${le(e.platform)}${a}${t?`?${new URLSearchParams(t).toString()}`:""}`,$a=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()},_=e=>typeof e=="object"&&e!==null,N=(e,a)=>typeof e=="number"&&Number.isFinite(e)?e:a,so=e=>{let a=e[0],t=_(a)&&_(a.frame)?a.frame:null,o=Math.max(1,N(t?.width,1)),r=Math.max(1,N(t?.height,1)),d=[],s=(u,n)=>{if(d.length>=lo||!_(u)||!_(u.frame))return;let i=u.frame,f=N(i.width,0),m=N(i.height,0);!(Math.abs(f-o)<.5&&Math.abs(m-r)<.5)&&f>0&&m>0&&d.push({id:typeof u.AXUniqueId=="string"?u.AXUniqueId:n,label:typeof u.AXLabel=="string"?u.AXLabel:"",role:typeof u.type=="string"?u.type:"",x:N(i.x,0)/o,y:N(i.y,0)/r,width:f/o,height:m/r}),(Array.isArray(u.children)?u.children:[]).forEach((b,y)=>s(b,`${n}.${y}`))};return e.forEach((u,n)=>s(u,String(n))),d},ja=e=>_(e)&&typeof e.error=="string"?e.error:"Unexpected accessibility payload.";async function Ja(e,a){if(e.platform==="ios"){let n=await $a(e,Ve(e,`/helper/${encodeURIComponent(e.deviceId)}/ax`),a);return Array.isArray(n)?{elements:so(n),errors:[]}:{elements:[],errors:[ja(n)]}}let t=await $a(e,Ve(e,"/api/accessibility",{device:e.deviceId}),a);if(!_(t)||!Array.isArray(t.nodes))return{elements:[],errors:[ja(t)]};let o=t.nodes.filter(n=>_(n)&&_(n.bounds)),r=o[0]?.bounds,d=Math.max(1,N(r?.right,1)),s=Math.max(1,N(r?.bottom,1));return{elements:o.slice(1).flatMap(n=>{let i=n.bounds,f=N(i.left,0),m=N(i.top,0),L=(N(i.right,f)-f)/d,I=(N(i.bottom,m)-m)/s,b=typeof n.text=="string"?n.text:"",y=typeof n.contentDescription=="string"?n.contentDescription:"",v=b||y;if(L>=.95&&I>=.9)return[];if(!v&&n.clickable!==!0)return[];let g=typeof n.className=="string"?n.className:"";return[{id:String(n.id??""),label:v,role:g.split(".").at(-1)??"",x:f/d,y:m/s,width:L,height:I}]}),errors:[]}}var Qa=(e,a,t)=>{let o=new AbortController,r=null,d=()=>{e.transport.fetch(a,{signal:o.signal}).then(s=>Xa(s,u=>{try{t(JSON.parse(u.data))}catch{}},o.signal)).catch(()=>{}).finally(()=>{o.signal.aborted||(r=setTimeout(d,ro))})};return d(),()=>{o.abort(),r!==null&&clearTimeout(r)}};function Ya(e,a){return e.platform!=="ios"?()=>{}:Qa(e,Ve(e,"/appstate",{device:e.deviceId}),t=>{if(_(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 Za=e=>!_(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 et(e,a){return e.platform!=="ios"?()=>{}:Qa(e,Ve(e,"/api/event-log/events",{device:e.deviceId,limit:"100"}),t=>{if(!_(t))return;if(Array.isArray(t.events)){a(t.events.flatMap(r=>Za(r)??[]),!0);return}let o=Za(t.event);o&&a([o],!1)})}function D(){return{t:O().i18n.usePluginTranslation()}}function _e(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 at(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 tt=e=>{try{return JSON.parse(e)?.type==="video-session"}catch{return!1}};function ot(e){let a=!1,t=null,o=e.length,r=0;for(;r+2<o;){if(e[r]===0&&e[r+1]===0){let d=0;if(e[r+2]===1?d=3:r+3<o&&e[r+2]===0&&e[r+3]===1&&(d=4),d){let s=e[r+d]&31;s===7&&!t&&(t=e.subarray(r+d)),s===5&&(a=!0),r+=d+1;continue}}r++}return{isKey:a,sps:t}}var uo={1:"description",2:"keyframe",3:"delta",4:"seed"},ze=class{buffer=new Uint8Array(64*1024);length=0;push(a){if(this.length+a.length>this.buffer.length){let r=this.buffer.length;for(;r<this.length+a.length;)r*=2;let d=new Uint8Array(r);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=uo[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 no={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 rt(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:no[e]??null}var lt={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 ua(e){if(e.stopped)return;let a=o=>{e.configuring=!1,e.connecting(o),e.scheduleRetry("input",()=>ua(e))},t;try{t=e.transport.connect(`${e.vendor}/ws?device=${e.device}&frame-meta=1`)}catch(o){e.events.onInputConnected(!1,o.message),a(o.message);return}e.socket=t,t.onopen=()=>{e.stopped||e.socket!==t||(e.connecting(),e.events.onInputConnected(!0))},t.onmessage=o=>{if(e.stopped||e.socket!==t)return;if(typeof o.data=="string"){tt(o.data)&&(e.closeDecoder(),e.configuring=!1,e.connecting(),e.requestKeyframe());return}let r=at(o.data),d=!e.videoDecoder||e.videoDecoder.state!=="configured",u=r.isKey===null||r.isKey&&d?ot(r.data):null,n=r.isKey??u?.isKey??!1;if(u?.sps&&d){if(e.configuring)return;e.configuring=!0;let i=e.decoderEpoch,f=()=>!e.stopped&&e.socket===t;e.configureDecoder({codec:_e(u.sps)},f).then(m=>{!f()||i!==e.decoderEpoch||(e.configuring=!1,e.awaitingKeyframe=!0,m&&e.requestKeyframe())});return}if(d){n||e.requestKeyframe();return}e.decode(n,r.data,r.timestamp)},t.onclose=o=>{e.socket===t&&(e.socket=null,e.closeDecoder(),!e.stopped&&(e.events.onInputConnected(!1,o.reason||`closed ${o.code}`),a(o.reason||void 0)))},t.onerror=()=>t.close()}function st(e){return{sendTouch(a,t,o){let r=a==="begin"?"down":a==="move"?"move":"up";e.send(JSON.stringify({type:"touch",action:r,x:t,y:o}))},sendKey(a,t){if(t!=="down")return;if(a.key==="Escape")return e.send(JSON.stringify({type:"back"}));let o=lt[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 dt(e){return{present(a,t,o){let r=e.getContext("2d");return r?((e.width!==t||e.height!==o)&&(e.width=t,e.height=o),r.drawImage(a,0,0,t,o),!0):!1}}}var ut=new TextEncoder,nt=new TextDecoder;function ft(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 it(e,a,t,o){let r=o-a.length;for(let d=t;d<=r;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 We=class{delimiter;buffer=new Uint8Array(64*1024);length=0;pos=0;state="boundary";contentLength=null;scanFrom=0;constructor(a){this.delimiter=a?ut.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 u=nt.decode(a.subarray(this.pos,s)).trim();if(this.pos=s+1,u.startsWith("--"))return this.delimiter=ut.encode(u),this.state="headers",!0}let t=this.delimiter,o=it(a,t,this.pos,this.length);if(o===-1)return this.pos=Math.max(this.pos,this.length-t.length+1),!1;let r=o+t.length;if(r+2>this.length)return this.pos=o,!1;if(a[r]===45&&a[r+1]===45)return this.state="done",!0;let d=this.lineEnd(r);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 r=nt.decode(this.buffer.subarray(a,o)).replace(/\r$/,"");if(a=o+1,r==="")break;let d=r.indexOf(":");if(d>0&&r.slice(0,d).trim().toLowerCase()==="content-length"){let s=Number.parseInt(r.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=it(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 r=o-1;r>this.pos&&this.buffer[r-1]===13&&r--;let d=this.buffer.slice(this.pos,Math.max(r,this.pos));return this.pos=o,this.state="boundary",d}}};async function io(e,a,t){let o=new We(ft(e.headers.get("content-type")));await Ge(e,r=>{for(let d of o.push(r))a(d)},t)}function xe(e){e.stopped||e.mjpeg||(e.mjpeg=!0,e.controller?.abort(),e.controller=null,e.closeDecoder(),e.connecting(),e.events.onMjpegFallback?.(),ct(e))}var na=e=>`${e.vendor}/helper/${e.device}/stream.mjpeg`;async function ct(e){let a=e.generation,t=++e.videoGeneration,o=new AbortController;e.controller=o;let r=()=>!e.stopped&&e.generation===a&&e.videoGeneration===t&&e.controller===o,d=null,s=!1,u=async()=>{s=!0;try{for(;d;){let i=d;d=null;try{let f=await e.createBitmap(new Blob([i],{type:"image/jpeg"}));try{r()&&e.paint(f,f.width,f.height)}finally{f.close()}}catch{}}}finally{s=!1}},n;try{let i=await e.transport.fetch(na(e),{signal:o.signal});if(!r()){await i.body?.cancel();return}if(!i.ok||!i.body)throw new Error(`stream ${i.status}`);if(await io(i,f=>{r()&&(d=f,s||u())},o.signal),!r())return;n="Device stream ended."}catch(i){if(!r())return;n=i.message}r()&&(e.controller=null,o.abort(),e.connecting(n),e.scheduleRetry("video",()=>{ct(e)}))}var fo=1e3,ia=15e3,co=16667,po=8,mo=e=>typeof e=="object"&&e!==null&&"present"in e;function mt(e){let{transport:a,platform:t,events:o}=e,r=mo(e.output)?e.output:dt(e.output),d=u=>e.globals?.[u]??globalThis[u],s={platform:t,transport:a,events:o,preferMjpeg:e.preferMjpeg===!0,vendor:le(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 u=d("VideoDecoder"),n=d("EncodedVideoChunk");return u&&n?{VideoDecoder:u,EncodedVideoChunk:n}:null},createBitmap(u){let n=d("createImageBitmap");return n?n(u):Promise.reject(new Error("createImageBitmap is unavailable."))},setStatus(u,n){s.stopped||o.onStatus(u,n)},fail(u){s.stopped||(s.stop(),o.onInputConnected(!1,u),o.onStatus("error",u))},connecting(u){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",u)},paint(u,n,i){if(!s.stopped){if(t==="android"&&(s.screen?.width!==n||s.screen.height!==i)&&(s.screen={width:n,height:i,orientation:n>i?"landscape_left":"portrait"},o.onScreen(s.screen)),!r.present(u,n,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"?xe(s):(s.closeDecoder(),s.connecting("Video decoder restarted."),s.requestKeyframe())},async configureDecoder(u,n=()=>!s.stopped){let i=s.webCodecs();if(!i)return!1;let f=s.decoderEpoch,m={...u,optimizeForLatency:!0},L=await i.VideoDecoder.isConfigSupported(m).catch(()=>({supported:!1}));if(!n()||f!==s.decoderEpoch)return!1;if(!L.supported)return t==="android"&&s.fail(`This browser cannot decode ${u.codec}.`),!1;try{return(!s.videoDecoder||s.videoDecoder.state==="closed")&&(s.videoDecoder=go(s,i)),s.videoDecoder.configure(m),!0}catch(I){return t==="android"&&s.fail(`Video decoder: ${I.message}`),!1}},decode(u,n,i){let f=s.videoDecoder,m=s.webCodecs();if(!(!f||f.state!=="configured"||!m)){if(s.awaitingKeyframe){if(!u)return;s.awaitingKeyframe=!1}if(f.decodeQueueSize>po){s.recoverDecoder();return}try{f.decode(new m.EncodedVideoChunk({type:u?"key":"delta",timestamp:i??s.timestamp,data:n})),s.timestamp+=co}catch{s.recoverDecoder()}}},requestKeyframe(){t==="android"&&s.socket?.readyState===1&&s.socket.send(JSON.stringify({type:"reset-video",ack:!1}))},scheduleRetry(u,n){s.stopped||s.retryTimers.has(u)||s.retryTimers.set(u,setTimeout(()=>{s.retryTimers.delete(u),n()},fo))},send(u){!s.stopped&&s.socket?.readyState===1&&s.socket.send(u)},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 n of s.retryTimers.values())clearTimeout(n);s.retryTimers.clear(),s.primeController?.abort(),s.primeController=null,s.controller?.abort(),s.controller=null;let u=s.socket;s.socket=null,u?.close(),s.closeDecoder()}};return s}function go(e,a){let t=e.videoGeneration,o=()=>e.platform!=="ios"||t===e.videoGeneration,r=new a.VideoDecoder({output:d=>{try{e.videoDecoder===r&&o()&&e.paint(d,d.displayWidth,d.displayHeight)}finally{d.close()}},error:()=>{e.stopped||e.videoDecoder!==r||!o()||e.recoverDecoder()}});return r}var Lo=3,ho=4,xo=6,gt=7,Io=13,Co=130,So=2e3,yo=new TextEncoder,vo=new TextDecoder,Ke=["portrait","landscape_left","portrait_upside_down","landscape_right"],wo=new Set(Ke);function se(e,a){let t=yo.encode(JSON.stringify(a)),o=new Uint8Array(1+t.length);return o[0]=e,o.set(t,1),o}function bo(e){if(typeof e!="object"||e===null)return null;let{width:a,height:t,orientation:o,screenId:r}=e;if(typeof a!="number"||!Number.isFinite(a)||a<=0||typeof t!="number"||!Number.isFinite(t)||t<=0||typeof o!="string"||!wo.has(o))return null;let d={width:a,height:t,orientation:o};return typeof r=="number"?{...d,screenId:r}:d}function Lt(e,a){xt(e),a?ht(e):xe(e)}async function ht(e){let a=e.generation,t=++e.videoGeneration,o=new ze,r=new AbortController;e.controller=r;let d=()=>!e.stopped&&e.generation===a&&e.videoGeneration===t&&e.controller===r,s;try{let u=await e.transport.fetch(`${e.vendor}/helper/${e.device}/stream.avcc`,{signal:r.signal});if(!d()){await u.body?.cancel();return}if(!u.ok||!u.body)throw new Error(`stream ${u.status}`);let n=u.body.getReader();for(;;){let i=setTimeout(()=>{d()&&e.fail("Device stream stopped receiving video. Reconnect to try again.")},ia);e.videoReadTimer=i;let f;try{f=await n.read()}finally{clearTimeout(i),e.videoReadTimer===i&&(e.videoReadTimer=null)}let{done:m,value:L}=f;if(!d())return;if(m)break;for(let I of o.push(L))switch(I.type){case"seed":e.createBitmap(new Blob([I.payload],{type:"image/jpeg"})).then(b=>{try{d()&&e.paint(b,b.width,b.height)}finally{b.close()}}).catch(()=>{});break;case"description":{e.awaitingKeyframe=!0;let b=await e.configureDecoder({codec:_e(I.payload),description:I.payload},d);if(!d())return;if(!b){if(await n.cancel().catch(()=>{}),!d())return;xe(e);return}break}case"keyframe":case"delta":e.decode(I.type==="keyframe",I.payload);break}}}catch(u){if(!d())return;s=u.message}d()&&(e.controller=null,r.abort(),e.closeDecoder(),e.connecting(s),e.scheduleRetry("video",()=>{ht(e)}))}async function ko(e,a){let t=new AbortController;e.primeController=t;let o=setTimeout(()=>t.abort(),So);try{let r=await e.transport.fetch(na(e),{signal:t.signal});if(e.stopped||e.generation!==a)return;await r.body?.getReader().read()}catch{}finally{clearTimeout(o),t.abort(),e.primeController===t&&(e.primeController=null)}}async function xt(e){if(e.stopped)return;let a=e.generation;if(await ko(e,a),e.stopped||e.generation!==a)return;let t=()=>e.scheduleRetry("input",()=>{xt(e)}),o;try{o=e.transport.connect(`${e.vendor}/helper/ws?device=${e.device}`)}catch(r){e.events.onInputConnected(!1,r.message),t();return}e.socket=o,o.onopen=()=>{e.stopped||e.socket!==o||(o.send(se(Io,{enabled:!1})),e.events.onInputConnected(!0))},o.onmessage=r=>{if(e.stopped||e.socket!==o||typeof r.data=="string")return;let d=new Uint8Array(r.data);if(!(d.length<1||d[0]!==Co))try{let s=bo(JSON.parse(vo.decode(d.subarray(1))));s&&(e.screen=s,e.events.onScreen(s))}catch{}},o.onclose=r=>{e.socket===o&&(e.socket=null,!e.stopped&&(e.events.onInputConnected(!1,r.reason||(r.code===1006?"input socket refused":`closed ${r.code}`)),t()))},o.onerror=()=>o.close()}function Do(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 It(e){return{sendTouch(a,t,o){e.send(se(Lo,{type:a,...Do(e,t,o)}))},sendKey(a,t){let o=rt(a.code);o!==null&&e.send(se(xo,{type:t,usage:o}))},pressButton(a){let t=a==="home"?"home":a==="appSwitcher"?"app_switcher":a==="power"?"lock":null;t&&e.send(se(ho,{button:t}))},rotate(){let a=e.screen?.orientation??"portrait",t=Ke[(Ke.indexOf(a)+1)%Ke.length];e.send(se(gt,{orientation:t}))},setOrientation(a){e.send(se(gt,{orientation:a}))}}}function Ct(e){let a=mt(e),t=e.platform==="ios"?It(a):st(a);return{start:()=>{if(!a.stopped)return;a.stopped=!1,a.generation++,a.configuring=!1,a.connecting();let r=a.webCodecs()!==null&&!(e.platform==="ios"&&a.preferMjpeg);e.platform==="ios"?Lt(a,r):r?ua(a):a.fail("This browser cannot decode the Android stream (WebCodecs unavailable).")},stop:a.stop,isMjpeg:()=>a.mjpeg,...t}}var Po=56,Ao=2e3;function To(e,a,t,o=0){let r=Math.max(0,a-o);if(r===0||t===0)return{width:0,height:0};let d={width:t*e,height:t};return d.width<=r?d:{width:r,height:r/e}}function Mo(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),r=Math.min(a.width,a.height);return t?o/r:r/o}function Bo(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 Ro=()=>typeof navigator<"u"&&/iPhone|iPad|iPod/.test(navigator.userAgent);function Xe(e){let{t:a}=D(),t=U(null),o=U(null),[r,d]=h("connecting"),[s,u]=h(),[n,i]=h(null),[f,m]=h({connected:!1}),{onHandle:L,onStreaming:I,onScreen:b,transport:y,platform:v,deviceId:g}=e;k(()=>b?.(n),[b,n]),k(()=>{let c=t.current;if(!c)return;let S=Ct({transport:y,platform:v,deviceId:g,output:c,preferMjpeg:Ro(),events:{onStatus:(T,q)=>{d(T),u(q),I(T==="streaming")},onScreen:i,onInputConnected:(T,q)=>{m({connected:T,...q?{detail:q}:{}}),L({pressButton:S.pressButton,rotate:S.rotate,inputConnected:T})}}});return o.current=S,m({connected:!1}),S.start(),L({pressButton:S.pressButton,rotate:S.rotate,inputConnected:!1}),()=>{S.stop(),o.current=null,L(null),I(!1),i(null)}},[g,L,I,v,y]);let P=U(null),[A,R]=h({width:0,height:0});k(()=>{let c=P.current;if(!c)return;let S=()=>{let q=c.getBoundingClientRect();R(me=>me.width===q.width&&me.height===q.height?me:{width:q.width,height:q.height})};S();let T=new ResizeObserver(S);return T.observe(c),()=>T.disconnect()},[]);let E=e.withControls?Po:0,M=ae(()=>To(Mo(v,n),A.width,A.height,E),[A,E,v,n]),F=Bo(v,n),Q=F===90||F===-90?{width:M.height,height:M.width,left:(M.width-M.height)/2,top:(M.height-M.width)/2,transform:`rotate(${F}deg)`}:{width:M.width,height:M.height,...F?{transform:`rotate(${F}deg)`}:{}},[B,K]=h([]);k(()=>{if(!e.axOverlay)return;let c=null,S=null,T=!1,q=async()=>{c=new AbortController;try{let me=await Ja({transport:y,platform:v,deviceId:g},c.signal);T||K(me.elements)}catch{}T||(S=setTimeout(()=>{q()},Ao))};return q(),()=>{T=!0,c?.abort(),S&&clearTimeout(S),K([])}},[g,v,e.axOverlay,y]);let G=U(!1),V=c=>{let S=c.currentTarget.getBoundingClientRect(),T=(c.clientX-S.left)/S.width,q=(c.clientY-S.top)/S.height;return{x:Math.min(1,Math.max(0,T)),y:Math.min(1,Math.max(0,q))}},pe=c=>{if(!G.current)return;G.current=!1;let{x:S,y:T}=V(c);o.current?.sendTouch("end",S,T)};return p("div",{ref:P,className:"relative flex size-full min-h-0 min-w-0 items-center justify-center overflow-hidden",style:E?{paddingRight:E}:void 0,tabIndex:0,role:"application","aria-label":a(v==="ios"?"stream.iosScreen":"stream.androidScreen"),onKeyDown:c=>{c.target===c.currentTarget&&(c.metaKey&&!["r","R"].includes(c.key)||(c.preventDefault(),o.current?.sendKey(c.nativeEvent,"down")))},onKeyUp:c=>{c.target===c.currentTarget&&o.current?.sendKey(c.nativeEvent,"up")},children:[p("div",{className:"relative touch-none select-none",style:{width:M.width,height:M.height},onPointerDown:c=>{c.currentTarget.setPointerCapture(c.pointerId),c.currentTarget.parentElement?.focus(),G.current=!0;let{x:S,y:T}=V(c);o.current?.sendTouch("begin",S,T)},onPointerMove:c=>{if(!G.current)return;let{x:S,y:T}=V(c);o.current?.sendTouch("move",S,T)},onPointerUp:pe,onPointerCancel:pe,children:[l("canvas",{ref:t,className:"absolute top-0 left-0",style:Q}),B.length>0?l("div",{className:"pointer-events-none absolute inset-0","aria-hidden":!0,children:B.map(c=>l("div",{className:"absolute border border-info/80 bg-info/10",style:{left:`${c.x*100}%`,top:`${c.y*100}%`,width:`${c.width*100}%`,height:`${c.height*100}%`},children:c.label?l("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:c.label}):null},c.id))}):null]}),r==="streaming"&&!f.connected?l("div",{className:"pointer-events-none absolute inset-x-0 bottom-0 flex justify-center p-2",children:l("span",{className:"rounded-md bg-background/85 px-2 py-1 text-xs text-muted-foreground",children:f.detail?a("stream.inputLostDetail",{detail:f.detail}):a("stream.inputLost")})}):null,r!=="streaming"?l("div",{className:"absolute inset-0 bg-background",children:l(X,{name:e.deviceName,description:e.deviceDescription,stage:r==="error"?"error":"connecting",message:r==="error"?s??a("stream.failed"):a("stream.connecting"),children:r==="error"?l(C,{size:"sm",variant:"outline",onClick:()=>{o.current?.stop(),o.current?.start()},children:a("stream.reconnect")}):null})}):null]})}var Fo={hosts:[],hostStatuses:{},devices:[],sessions:[],bootingDevices:[],revision:0};function de(e){let t=O().commands.useSubscription("state",{},{environmentId:e});return{state:t.data??Fo,loaded:t.data!==null,error:t.error,unavailable:t.isUnavailable}}function ue(){let e=O();return ee((a,t,o={})=>e.commands.invoke(a,o,{environmentId:t}),[e])}var ne="local",$e=class extends Error{code;constructor(a,t,o){super(t,o),this.name="DeviceError",this.code=a}};var St="hub";function je(e){let a=O(),[t,o]=h({status:"connecting"});return k(()=>{let r=a.network;if(!oe(a,"network")||r===void 0){o({status:"failed",message:null});return}let d=!1;return o({status:"connecting"}),r.client(e).then(s=>{d||o({status:"ready",transport:{fetch:(u,n)=>s.fetch(St,u,{...n,instance:ne}),connect:u=>s.connect(St,u,{instance:ne})}})},s=>{d||o({status:"failed",message:s instanceof Error?s.message:String(s)})}),()=>{d=!0}},[a,e]),t}var yt=()=>{};function vt(e){let{environmentId:a,threadId:t,hostId:o,deviceId:r,platform:d}=e,s=e[Da],u=O(),{t:n}=D(),{state:i,loaded:f}=de(a),m=je(a),L=ae(()=>({environmentId:a,threadId:t}),[a,t]),I=i.devices.find(P=>P.hostId===o&&P.id===r),b=i.sessions.some(P=>P.threadId===t&&P.hostId===o&&P.deviceId===r);k(()=>{f&&!b&&u.floating?.close(L,s.key)},[u,s.key,f,b,L]),k(()=>(s.setOpenInPanel(()=>{Oe(a,t,s.key),u.floating?.openPanel(L,Fe),u.floating?.close(L,s.key)}),()=>s.setOpenInPanel(null)),[u,a,s,L,t]);let y=ee(P=>s.reportSourceSize(P===null?null:Pa(P)),[s]),v=I?.name??r,g=I?.version??d;return m.status!=="ready"?l(X,{name:v,description:g,stage:m.status==="failed"?"error":"connecting",message:m.status==="failed"?m.message??n("workspace.needsNewerApp"):n("stream.connecting")}):l(Xe,{transport:m.transport,platform:d,deviceId:r,deviceName:v,deviceDescription:g,axOverlay:!1,withControls:!1,onHandle:yt,onStreaming:yt,onScreen:y})}var Ze=(...e)=>e.filter((a,t,o)=>!!a&&a.trim()!==""&&o.indexOf(a)===t).join(" ").trim();var wt=e=>e.replace(/([a-z0-9])([A-Z])/g,"$1-$2").toLowerCase();var bt=e=>e.replace(/^([A-Z])|[\s-_]+(\w)/g,(a,t,o)=>o?o.toUpperCase():t.toLowerCase());var fa=e=>{let a=bt(e);return a.charAt(0).toUpperCase()+a.slice(1)};var kt={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 Dt=e=>{for(let a in e)if(a.startsWith("aria-")||a==="role"||a==="title")return!0;return!1};var Pt=Be(({color:e="currentColor",size:a=24,strokeWidth:t=2,absoluteStrokeWidth:o,className:r="",children:d,iconNode:s,...u},n)=>Y("svg",{ref:n,...kt,width:a,height:a,stroke:e,strokeWidth:o?Number(t)*24/Number(a):t,className:Ze("lucide",r),...!d&&!Dt(u)&&{"aria-hidden":"true"},...u},[...s.map(([i,f])=>Y(i,f)),...Array.isArray(d)?d:[d]]));var x=(e,a)=>{let t=Be(({className:o,...r},d)=>Y(Pt,{ref:d,iconNode:a,className:Ze(`lucide-${wt(fa(e))}`,`lucide-${e}`,o),...r}));return t.displayName=fa(e),t};var Uo=[["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"}]],Ie=x("camera",Uo);var Oo=[["path",{d:"m6 9 6 6 6-6",key:"qrunsl"}]],Ce=x("chevron-down",Oo);var qo=[["path",{d:"m15 18-6-6 6-6",key:"1wnfg3"}]],Se=x("chevron-left",qo);var Ho=[["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"}]],$=x("ellipsis",Ho);var Eo=[["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"}]],j=x("house",Eo);var No=[["circle",{cx:"12",cy:"12",r:"10",key:"1mglay"}],["path",{d:"M12 16v-4",key:"1dtifu"}],["path",{d:"M12 8h.01",key:"e9boi3"}]],ye=x("info",No);var Go=[["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"}]],ve=x("moon",Go);var Vo=[["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"}]],we=x("picture-in-picture-2",Vo);var zo=[["path",{d:"M12 2v10",key:"mnfbl"}],["path",{d:"M18.4 6.6a9 9 0 1 1-12.77.04",key:"obofu9"}]],be=x("power",zo);var _o=[["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"}]],ie=x("rotate-ccw",_o);var Wo=[["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"}]],ke=x("rotate-cw",Wo);var Ko=[["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"}]],De=x("sliders-horizontal",Ko);var Xo=[["rect",{width:"14",height:"20",x:"5",y:"2",rx:"2",ry:"2",key:"1yt0o3"}],["path",{d:"M12 18h.01",key:"mhygvu"}]],fe=x("smartphone",Xo);var $o=[["rect",{width:"18",height:"18",x:"3",y:"3",rx:"2",key:"afitv7"}]],Pe=x("square",$o);var jo=[["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"}]],Ae=x("sun",jo);var Zo=[["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"}]],Te=x("type",Zo);var Jo=[["path",{d:"M18 6 6 18",key:"1bl5f8"}],["path",{d:"m6 6 12 12",key:"d8bk6v"}]],W=x("x",Jo);function Qo(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 ca(){let{t:e}=D();return a=>Qo(a,e)}function At(e){let{t:a}=D(),t=ca(),[o,r]=h(!1),d=e.detail;return!d||d.status==="ready"||d.status==="idle"?null:d.status==="failed"?p("div",{role:"alert",className:"flex items-start gap-2 border-b bg-destructive/5 px-3 py-2 text-xs",children:[p("div",{className:"min-w-0 flex-1 space-y-0.5",children:[l("p",{className:"font-medium text-destructive",children:a("panel.hostFailed")}),d.message?l("p",{className:"whitespace-pre-wrap break-words text-muted-foreground",children:d.message}):null]}),p(C,{size:"xs",variant:"outline",disabled:o,onClick:()=>{r(!0),e.onRetry().finally(()=>r(!1))},children:[o?l(H,{size:"xs"}):l(ke,{}),a(o?"panel.retrying":"panel.retry")]})]}):p("div",{role:"status",className:"flex items-center gap-2 border-b px-3 py-2 text-xs text-muted-foreground",children:[l(H,{size:"xs"}),l("span",{className:"min-w-0 flex-1",children:t(d)})]})}var pa=["hub","agent"],ma=e=>e!==void 0&&!e.installedVersions.includes(e.requiredVersion);function Tt(e){let{t:a}=D(),t=ue(),[o,r]=h(null),[d,s]=h(null),u=e.host?.tools,n=e.busy||o!==null,i=m=>{r(m),s(null),(m==="check"?t("inspect",e.environmentId):t("updateTool",e.environmentId,{tool:m})).catch(()=>s(a(m==="check"?"versions.checkFailed":"versions.updateFailed"))).finally(()=>r(null))},f=m=>m??a("versions.none");return p(_a,{children:[p(Wa,{render:l(C,{size:"xs",variant:"ghost","aria-label":a("versions.title")}),children:[l(ye,{}),a("versions.title"),pa.some(m=>ma(u?.[m]))?l("span",{className:"size-1.5 rounded-full bg-warning","aria-hidden":!0}):null]}),l(Ka,{side:"bottom",align:"start",className:"w-80",children:p("div",{className:"space-y-3 text-xs",children:[pa.map(m=>{let L=u?.[m];return p("section",{className:"space-y-1",children:[l("h4",{className:"font-medium text-foreground",children:a(m==="hub"?"versions.hubName":"versions.agentName")}),p("dl",{className:"grid grid-cols-[auto_1fr] gap-x-3 gap-y-0.5 text-muted-foreground",children:[l("dt",{children:a("versions.required")}),l("dd",{className:"font-mono",children:f(L?.requiredVersion)}),l("dt",{children:a("versions.installed")}),l("dd",{className:"font-mono",children:L&&L.installedVersions.length>0?L.installedVersions.join(", "):a("versions.none")}),l("dt",{children:a("versions.running")}),l("dd",{className:"font-mono",children:f(L?.runningVersion)})]}),ma(L)?p(C,{size:"xs",variant:"outline",disabled:n,onClick:()=>i(m),children:[o===m?l(H,{size:"xs"}):null,a("versions.updateTo",{version:L?.requiredVersion??""})]}):null]},m)}),u===void 0?l("p",{className:"text-muted-foreground",children:a("versions.unknown")}):null,pa.some(m=>ma(u?.[m]))?l("p",{className:"text-muted-foreground",children:a("versions.pendingPolicy")}):null,d?l("p",{role:"alert",className:"text-destructive",children:d}):null,p("div",{className:"flex items-center justify-between gap-2 border-t pt-2",children:[l("p",{className:"text-muted-foreground",children:a("versions.checkHint")}),p(C,{size:"xs",variant:"ghost",disabled:n,onClick:()=>i("check"),children:[o==="check"?l(H,{size:"xs"}):null,a("versions.check")]})]})]})})]})}var Mt=["small","default","large","extra-large"],Yo=e=>Mt.includes(e);function Bt(e){let{t:a}=D(),{handle:t,controls:o}=e,r=o.detail?.settings,d=!t?.inputConnected,s=r?.appearance==="dark"?"light":"dark",u=n=>a(n==="small"?"rail.textSmall":n==="default"?"rail.textDefault":n==="large"?"rail.textLarge":"rail.textExtraLarge");return l("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:p("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:[l(Z,{label:a("rail.home"),disabled:d,onClick:()=>t?.pressButton("home"),children:l(j,{})}),e.platform==="android"?p(re,{children:[l(Z,{label:a("rail.back"),disabled:d,onClick:()=>t?.pressButton("back"),children:l(Se,{})}),l(Z,{label:a("rail.recents"),disabled:d,onClick:()=>t?.pressButton("recents"),children:l(Pe,{})}),p(He,{children:[l(Ne,{render:l(C,{size:"icon-sm",variant:"ghost","aria-label":a("rail.rotate"),disabled:o.disabled}),children:l(ie,{})}),p(Ee,{side:"left",children:[l(Le,{onClick:()=>{o.act({type:"setOrientation",value:"portrait"})},children:a("rail.portrait")}),l(Le,{onClick:()=>{o.act({type:"setOrientation",value:"landscape_left"})},children:a("rail.landscape")})]})]})]}):l(Z,{label:a("rail.rotate"),disabled:d,onClick:()=>t?.rotate(),children:l(ie,{})}),l(er,{}),l(Z,{label:a(s==="dark"?"rail.toDark":"rail.toLight"),disabled:o.disabled||!r?.appearance,onClick:()=>{o.act({type:"setAppearance",value:s})},children:r?.appearance==="dark"?l(Ae,{}):l(ve,{})}),p(He,{children:[l(Ne,{render:l(C,{size:"icon-sm",variant:"ghost","aria-label":a("rail.textSize"),title:a("rail.textSize"),disabled:o.disabled||!r?.textSize}),children:l(Te,{})}),l(Ee,{side:"left",className:"min-w-40",children:l(Oa,{value:r?.textSize??"",onValueChange:n=>{Yo(n)&&o.act({type:"setTextSize",value:n})},children:Mt.map(n=>l(qa,{value:n,children:u(n)},n))})})]}),l(Z,{label:a("rail.tools"),pressed:e.toolsOpen,onClick:e.onTools,children:l(De,{})}),l(Z,{label:e.screenshotPending?a("rail.capturing"):a("rail.screenshot"),disabled:!e.streaming||e.screenshotPending,onClick:e.onScreenshot,children:l(Ie,{})}),e.onFloat?l(Z,{label:a("rail.float"),onClick:e.onFloat,children:l(we,{})}):null,p(He,{children:[l(Ne,{render:l(C,{size:"icon-sm",variant:"ghost","aria-label":a("rail.more"),title:a("rail.more")}),children:l($,{})}),p(Ee,{side:"left",align:"end",children:[p(Le,{onClick:e.onClose,children:[l(W,{}),a("rail.closePanel")]}),l(Ua,{}),p(Le,{variant:"destructive",onClick:e.onPowerOff,children:[l(be,{}),a("rail.powerOff")]})]})]})]})})}function er(){return l("div",{"aria-hidden":!0,className:"my-1 h-px w-5 shrink-0 bg-border/70"})}function Z(e){return p(Ba,{children:[l(Fa,{render:l(C,{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}),l(Ra,{side:"left",children:e.label})]})}var ga=(e,a)=>new $e("invalid-input",`Invalid ${e}: ${a}.`);var Rt=4096,Ft=["light","dark"],Ut=["small","default","large","extra-large"];var Ot=["clear","tinted"],qt=["none","grayscale","red-green","green-red","blue-yellow"],Ht=["portrait","landscape_left","portrait_upside_down","landscape_right"],Et=["camera","microphone","photos","contacts","calendar","reminders","location","notifications","motion","media-library","faceid"];var ar=e=>typeof e=="object"&&e!==null&&!Array.isArray(e);var Nt=e=>{let a=typeof e=="string"?{aps:{alert:e}}:e;if(!ar(a))throw ga("push payload","expected a string or an object");let t;try{t=JSON.stringify(a)}catch{t=void 0}if(t===void 0)throw ga("push payload","could not be encoded as JSON");if(new TextEncoder().encode(t).length>Rt)throw ga("push payload",`larger than ${String(Rt)} bytes`);return t};var tr=new Set(["setAppearance","setTextSize","setToggle","setLiquidGlass","setColorFilter","setLocation","clearLocation","setPermission","openUrl","launchApp","terminateApp","sendPush"]),or=new Set(["setAppearance","setTextSize","setToggle","setOrientation","setLocation","clearLocation","setPermission","openUrl","launchApp","terminateApp"]),rr=new Set(["reduceMotion","increaseContrast","reduceTransparency","showBorders","voiceOver"]),lr=new Set(["reduceMotion","networkEnabled"]),Gt=(e,a)=>(e==="ios"?tr:or).has(a.type)?a.type==="setToggle"?(e==="ios"?rr:lr).has(a.setting):!0:!1;function te(e){return p("section",{className:"flex flex-col gap-2 border-b px-3 py-2.5",children:[l("h3",{className:"text-xs font-medium text-muted-foreground",children:e.title}),e.children]})}function J(e){return p("div",{className:"flex min-h-7 items-center justify-between gap-3",children:[l("span",{className:"shrink-0 text-xs text-muted-foreground",children:e.label}),l("div",{className:"flex min-w-0 items-center justify-end",children:e.children})]})}function La(e){return l(J,{label:e.label,children:l(Ma,{"aria-label":e.label,checked:e.checked??!1,disabled:e.disabled||e.checked===void 0,onCheckedChange:a=>{e.onChange(a)}})})}function ha(e){return l(Va,{"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=>l(za,{size:"xs",value:a.value,children:a.label},a.value))})}function Me(e){let a=e.options.find(t=>t.value===e.value);return p(ta,{value:e.value,disabled:e.disabled,onValueChange:t=>{let o=e.options.find(r=>r.value===t);o&&o.value!==e.value&&e.onChange(o.value)},children:[l(oa,{size:"xs",className:e.width??"w-40","aria-label":e.ariaLabel,children:l(ra,{children:a?a.label:l("span",{className:"text-muted-foreground",children:e.placeholder})})}),l(la,{align:"end",alignItemWithTrigger:!1,children:e.options.map(t=>l(sa,{value:t.value,children:t.label},t.value))})]})}function xa(e){let[a,t]=h(""),o=a.trim()||e.fallback||"",r=()=>{o&&e.onSubmit(o).then(()=>t(""))};return p("form",{className:"flex gap-1.5",onSubmit:d=>{d.preventDefault(),r()},children:[l(he,{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)}),l(C,{type:"submit",size:"xs",variant:"outline",disabled:e.disabled||!o,children:e.action})]})}var Vt=[{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 _t(e){let{t:a}=D(),[t,o]=h(""),[r,d]=h(""),s={latitude:Number(t),longitude:Number(r)},u=t.trim()!==""&&r.trim()!==""&&Math.abs(s.latitude)<=90&&Math.abs(s.longitude)<=180,n=(i,f)=>e.act({type:"setLocation",latitude:i,longitude:f});return p(te,{title:a("tools.location.title"),children:[p("div",{className:"flex gap-1.5",children:[l(he,{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)}),l(he,{size:"compact",className:"min-w-0 flex-1 font-mono",placeholder:a("tools.location.longitude"),"aria-label":a("tools.location.longitude"),inputMode:"decimal",value:r,disabled:e.disabled,onChange:i=>d(i.target.value)})]}),p("div",{className:"flex flex-wrap items-center gap-1.5",children:[p(ta,{value:null,disabled:e.disabled,onValueChange:i=>{let f=Vt.find(m=>m.key===i);f&&(o(String(f.latitude)),d(String(f.longitude)),n(f.latitude,f.longitude))},children:[l(oa,{size:"xs",className:"w-32","aria-label":a("tools.location.preset"),children:l(ra,{children:l("span",{className:"text-muted-foreground",children:a("tools.location.presetPlaceholder")})})}),l(la,{align:"start",alignItemWithTrigger:!1,children:Vt.map(i=>l(sa,{value:i.key,children:a(i.key)},i.key))})]}),l(C,{size:"xs",variant:"outline",disabled:e.disabled||!u,onClick:()=>{n(s.latitude,s.longitude)},children:a("tools.location.set")}),l(C,{size:"xs",variant:"ghost",disabled:e.disabled,onClick:()=>{o(""),d(""),e.act({type:"clearLocation"})},children:a("tools.location.clear")})]})]})}var sr={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"},dr=new Set(["camera","microphone","photos","contacts","calendar","location","notifications","motion"]);function Wt(e){let{t:a}=D(),t=e.platform==="ios",[o,r]=h(""),[d,s]=h("camera"),u=o.trim()||e.defaultAppId,n=Et.filter(f=>t||dr.has(f)).map(f=>({value:f,label:a(!t&&f==="motion"?"tools.permissions.activity":sr[f])})),i=f=>{e.act({type:"setPermission",appId:u,permission:d,decision:f})};return p(te,{title:a("tools.permissions.title"),children:[l(he,{size:"compact",className:"font-mono",placeholder:e.defaultAppId||a("tools.permissions.appId"),"aria-label":a("tools.permissions.appId"),value:o,disabled:e.disabled,onChange:f=>r(f.target.value)}),p("div",{className:"flex flex-wrap items-center gap-1.5",children:[l(Me,{ariaLabel:a("tools.permissions.permission"),value:d,options:n,placeholder:a("tools.unknown"),disabled:e.disabled,onChange:f=>(s(f),Promise.resolve())}),l(C,{size:"xs",variant:"outline",disabled:e.disabled||!u,onClick:()=>i("grant"),children:a("tools.permissions.grant")}),l(C,{size:"xs",variant:"outline",disabled:e.disabled||!u,onClick:()=>i("revoke"),children:a("tools.permissions.revoke")}),t?l(C,{size:"xs",variant:"ghost",disabled:e.disabled||!u,onClick:()=>i("reset"),children:a("tools.permissions.reset")}):null]})]})}var ur=e=>{let a=e;try{let t=JSON.parse(e);typeof t=="object"&&t!==null&&!Array.isArray(t)&&(a=t)}catch{}try{return Nt(a),a}catch{return null}};function Kt(e){let{t:a}=D(),[t,o]=h(""),r=t.trim(),d=r?ur(r):null,s=e.appId;return p(te,{title:a("tools.push.title"),children:[l(Ha,{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:u=>o(u.target.value)}),p("div",{className:"flex items-center gap-2",children:[l(C,{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?r&&d===null?l("p",{className:"text-xs text-destructive",children:a("tools.push.invalid")}):null:l("p",{className:"text-xs text-muted-foreground",children:a("tools.push.needsApp")})]})]})}var zt=100;function Xt(e){let{t:a}=D(),[t,o]=h(!1),[r,d]=h([]),{transport:s,platform:u,deviceId:n}=e;return k(()=>{if(!t)return;let i=et({transport:s,platform:u,deviceId:n},(f,m)=>{d(L=>{let I=m?[...f]:[...L,...f];return I.length>zt?I.slice(-zt):I})});return()=>{i(),d([])}},[t,s,u,n]),p(Ea,{open:t,onOpenChange:o,children:[p(Na,{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"),l(Ce,{className:`ml-auto size-3.5 transition-transform ${t?"rotate-180":""}`})]}),l(Ga,{children:l("ol",{className:"max-h-64 overflow-y-auto px-3 py-2 font-mono text-ui-2xs leading-relaxed",children:r.length===0?l("li",{className:"text-muted-foreground",children:a("tools.eventLog.empty")}):r.map(i=>p("li",{className:"flex gap-2",children:[l("span",{className:"shrink-0 text-muted-foreground",children:i.timestamp.slice(11,19)}),l("span",{className:"truncate",children:i.summary})]},i.id))})})]})}var nr=640,ir={light:"tools.settings.light",dark:"tools.settings.dark"},fr={small:"tools.settings.textSmall",default:"tools.settings.textDefault",large:"tools.settings.textLarge","extra-large":"tools.settings.textExtraLarge"},cr={clear:"tools.settings.glassClear",tinted:"tools.settings.glassTinted"},pr={none:"tools.settings.filterNone",grayscale:"tools.settings.filterGrayscale","red-green":"tools.settings.filterRedGreen","green-red":"tools.settings.filterGreenRed","blue-yellow":"tools.settings.filterBlueYellow"},mr={portrait:"tools.settings.orientationPortrait",landscape_left:"tools.settings.orientationLandscapeLeft",portrait_upside_down:"tools.settings.orientationUpsideDown",landscape_right:"tools.settings.orientationLandscapeRight"},gr=[{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 $t(e){let{t:a}=D(),{device:t,controls:o}=e,{detail:r,pending:d,error:s,foregroundApp:u,disabled:n,act:i}=o,f=r?.settings,m=t.platform==="ios",L=U(null),[I,b]=h(!0);va(()=>{let g=L.current?.parentElement;if(!g)return;let P=()=>b(g.clientWidth<nr);P();let A=new ResizeObserver(P);return A.observe(g),()=>A.disconnect()},[]);let y=Ut.map(g=>({value:g,label:a(fr[g])})),v=gr.filter(g=>Gt(t.platform,{type:"setToggle",setting:g.setting,value:!0}));return p("aside",{ref:L,"aria-label":a("tools.title"),className:`flex min-h-0 flex-col border-l bg-background text-sm ${I?"absolute inset-y-0 right-0 z-10 w-full max-w-72 shadow-lg":"w-72 shrink-0"}`,children:[p("div",{className:"flex h-9 shrink-0 items-center gap-2 border-b px-3",children:[l("span",{className:"font-medium",children:a("tools.title")}),d?l(H,{size:"sm"}):null,l(C,{size:"icon-xs",variant:"ghost-muted","aria-label":a("tools.close"),className:"ml-auto",onClick:e.onClose,children:l(W,{})})]}),p("div",{className:"min-h-0 flex-1 overflow-y-auto",children:[s?l("p",{role:"alert",className:"border-b bg-destructive/10 px-3 py-2 text-xs text-destructive",children:s}):null,r===null&&!s?p("div",{className:"flex items-center gap-2 px-3 py-3 text-xs text-muted-foreground",children:[l(H,{size:"sm"}),a("tools.reading")]}):null,p(te,{title:a("tools.app.title"),children:[l(J,{label:a("tools.app.foreground"),children:l("span",{className:"truncate font-mono text-xs",children:u?.id??a("tools.app.none")})}),u?p("div",{className:"flex gap-1.5",children:[l(C,{size:"xs",variant:"outline",disabled:n,onClick:()=>{i({type:"terminateApp",appId:u.id})},children:a("tools.app.terminate")}),l(C,{size:"xs",variant:"outline",disabled:n,onClick:()=>{i({type:"launchApp",appId:u.id})},children:a("tools.app.relaunch")})]}):null,l(xa,{placeholder:a("tools.app.urlPlaceholder"),action:a("tools.app.open"),disabled:n,onSubmit:g=>i({type:"openUrl",url:g})}),l(xa,{placeholder:a(m?"tools.app.bundleIdPlaceholder":"tools.app.packagePlaceholder"),action:a("tools.app.launch"),disabled:n,fallback:u?.id,onSubmit:g=>i({type:"launchApp",appId:g})})]}),p(te,{title:a(m?"tools.settings.titleIos":"tools.settings.titleAndroid"),children:[l(J,{label:a("tools.settings.appearance"),children:l(ha,{label:a("tools.settings.appearance"),value:f?.appearance,options:Ft.map(g=>({value:g,label:a(ir[g])})),disabled:n,onChange:g=>i({type:"setAppearance",value:g})})}),l(J,{label:a("tools.settings.textSize"),children:l(Me,{ariaLabel:a("tools.settings.textSize"),value:f?.textSize??null,options:y,placeholder:a("tools.unknown"),disabled:n,onChange:g=>i({type:"setTextSize",value:g})})}),m?p(re,{children:[l(J,{label:a("tools.settings.liquidGlass"),children:l(ha,{label:a("tools.settings.liquidGlass"),value:f?.liquidGlass,options:Ot.map(g=>({value:g,label:a(cr[g])})),disabled:n,onChange:g=>i({type:"setLiquidGlass",value:g})})}),l(J,{label:a("tools.settings.colorFilter"),children:l(Me,{ariaLabel:a("tools.settings.colorFilter"),value:f?.colorFilter??null,options:qt.map(g=>({value:g,label:a(pr[g])})),placeholder:a("tools.unknown"),disabled:n,onChange:g=>i({type:"setColorFilter",value:g})})})]}):l(J,{label:a("tools.settings.orientation"),children:l(Me,{ariaLabel:a("tools.settings.orientation"),value:null,options:Ht.map(g=>({value:g,label:a(mr[g])})),placeholder:a("tools.settings.rotateTo"),disabled:n,onChange:g=>i({type:"setOrientation",value:g})})}),v.map(g=>l(La,{label:a(g.labelKey),checked:f?.[g.setting],disabled:n,onChange:P=>i({type:"setToggle",setting:g.setting,value:P})},g.setting))]}),l(te,{title:a("tools.accessibility.title"),children:l(La,{label:a("tools.accessibility.overlay"),checked:e.axOverlay,disabled:!1,onChange:g=>(e.onAxOverlayChange(g),Promise.resolve())})}),l(_t,{disabled:n,act:i}),l(Wt,{platform:t.platform,defaultAppId:u?.id??"",disabled:n,act:i}),m?l(Kt,{appId:u?.id,disabled:n,act:i}):null,m?l(Xt,{transport:e.transport,platform:t.platform,deviceId:t.id}):null]})]})}var Lr=2e4,Ia=class extends Error{status;constructor(a){super(`Screenshot capture failed (${a}). Try again.`),this.status=a}};async function jt(e,a,t,o){let r=AbortSignal.timeout(Lr),d=await e.fetch(`${le(a)}/api/screenshot?device=${encodeURIComponent(t)}`,{method:"POST",signal:o?AbortSignal.any([o,r]):r});if(!d.ok)throw new Ia(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 Zt=e=>e instanceof Error?e.message:String(e);function Jt(e){let{environmentId:a,device:t}=e,o=ue(),[r,d]=h(null),[s,u]=h(!1),[n,i]=h(null),f=U(!1),m=U(0),L={hostId:t.hostId,deviceId:t.id},I=y=>o("detail",a,L).then(v=>{m.current===y&&(d(v),i(null))},v=>{m.current===y&&(d(null),i(Zt(v)))});return k(()=>{let y=++m.current;return I(y),()=>{m.current++}},[a,t.hostId,t.id]),{detail:r,pending:s,error:n,act:async y=>{if(f.current||r===null)return;f.current=!0;let v=++m.current;u(!0),i(null);try{let g=await o("action",a,{...L,...y});m.current===v?d(g):await I(++m.current)}catch(g){m.current===v&&i(Zt(g))}finally{f.current=!1,u(!1)}},disabled:s||r===null,foregroundApp:e.foreground===void 0?r?.foregroundApp??null:e.foreground}}var hr=()=>typeof window<"u"&&"ReactNativeWebView"in window;function Qt(e){let{t:a}=D(),t=je(e.environmentId),[o,r]=h(null),[d,s]=h(!1),[u,n]=h(!1),[i,f]=h(!1),[m,L]=h(),[I,b]=h(!1),[y,v]=h(null),[g,P]=h(null),A=U(null),R=U(null),E=t.status==="ready"?t.transport:null,M=Jt({environmentId:e.environmentId,device:e.device,foreground:m}),F=ee(B=>r(B),[]),ce=ee(B=>s(B),[]);k(()=>{if(!E)return;let B=Ya({transport:E,platform:e.device.platform,deviceId:e.device.id},L);return()=>{B(),L(void 0)}},[e.device.id,e.device.platform,E]),k(()=>()=>{A.current?.abort(),R.current&&URL.revokeObjectURL(R.current)},[]);let Q=()=>{if(!E||A.current)return;let B=new AbortController;A.current=B,b(!0),v(null),jt(E,e.device.platform,e.device.id,B.signal).then(K=>{if(B.signal.aborted)return;R.current&&URL.revokeObjectURL(R.current);let G=URL.createObjectURL(K);if(R.current=G,hr()){P(G);return}let V=document.createElement("a");V.href=G,V.download=`${e.device.name.replace(/[^a-z0-9-]/gi,"-")}-${Date.now()}.png`,document.body.append(V),V.click(),V.remove()}).catch(K=>{B.signal.aborted||v(K instanceof Error?K.message:a("workspace.screenshotFailed"))}).finally(()=>{A.current===B&&(A.current=null,b(!1))})};return t.status!=="ready"?l(X,{name:e.device.name,description:e.device.version,stage:t.status==="failed"?"error":"connecting",message:t.status==="failed"?t.message??a("workspace.needsNewerApp"):a("stream.connecting"),children:l(C,{size:"sm",variant:"outline",onClick:e.onBack,children:a("workspace.allDevices")})}):p("div",{className:"relative flex min-h-0 min-w-0 flex-1",children:[p("div",{className:"relative flex min-h-0 min-w-0 flex-1 flex-col",children:[y||M.error&&!u?l("p",{role:"alert",className:"px-3 py-2 text-xs text-destructive",children:y??M.error}):null,p("div",{className:"relative min-h-0 flex-1",children:[l(Xe,{transport:t.transport,platform:e.device.platform,deviceId:e.device.id,deviceName:e.device.name,deviceDescription:e.device.version,axOverlay:i,withControls:!0,onHandle:F,onStreaming:ce}),l(Bt,{platform:e.device.platform,handle:o,streaming:d,controls:M,screenshotPending:I,onScreenshot:Q,toolsOpen:u,onTools:()=>n(!u),onClose:e.onClose,onPowerOff:e.onPowerOff,onFloat:e.onFloat})]})]}),u?l($t,{device:e.device,controls:M,transport:t.transport,axOverlay:i,onAxOverlayChange:f,onClose:()=>n(!1)}):null,g?p("div",{className:"absolute inset-0 z-20 flex flex-col items-center justify-center gap-3 bg-background/95 p-4",children:[l("img",{src:g,alt:a("workspace.screenshotAlt"),className:"max-h-[80%] max-w-full object-contain"}),l("p",{className:"text-xs text-muted-foreground",children:a("workspace.screenshotSaveHint")}),p(C,{size:"sm",variant:"outline",onClick:()=>P(null),children:[l(W,{}),a("workspace.closePreview")]})]}):null]})}var Ca=e=>e instanceof Error?e.message:String(e);function Yt(e){let{environmentId:a,threadId:t}=e,{t:o}=D(),{state:r,loaded:d,error:s,unavailable:u}=de(a),n=ue(),[i,f]=h(null),[m,L]=h(null),I=Aa(a,t),b=c=>Oe(a,t,c),y=O(),v=oe(y,"floating"),g=()=>{f(null),n("refresh",a).catch(c=>f(Ca(c)))};k(()=>{!d||u||n("refresh",a).catch(()=>{})},[a,d,n,u]);let P=ae(()=>r.sessions.filter(c=>c.threadId===t),[r.sessions,t]),A=Ir(P,I),R=A?r.devices.find(c=>c.hostId===A.hostId&&c.id===A.deviceId):void 0,E=R&&A?ge(R):null;k(()=>{y.floating?.present({environmentId:a,threadId:t},E)}),k(()=>()=>y.floating?.present({environmentId:a,threadId:t},null),[y,a,t]);let M=ae(()=>Cr(r),[r]),F=r.hostStatuses[ne],ce=F?.status==="ready",Q=F?.status==="installing"||F?.status==="starting",B=ca(),K=r.bootingDevices.filter(c=>c.threadId===t),G=r.hosts.flatMap(c=>c.platforms.filter(S=>!S.available)),V=async c=>{f(null),L(c),aa(a,t,z(c));try{await n("open",a,{threadId:t,hostId:c.hostId,deviceId:c.id,platform:c.platform}),b(z(c))}catch(S){aa(a,t,z(c),!1),f(Ca(S))}finally{L(null)}},pe=c=>{A&&(f(null),n("close",a,{threadId:t,hostId:A.hostId,deviceId:A.deviceId,shutdown:c}).then(()=>b(null)).catch(S=>f(Ca(S))))};return u?l(X,{name:o("panel.title"),stage:"error",message:o("panel.unavailable")}):p("div",{className:"flex size-full min-h-0 flex-col",children:[K.length>0?l("div",{role:"status",className:"border-b px-3 py-2 text-xs text-muted-foreground",children:o("panel.booting",{names:K.map(c=>c.name).join(", ")})}):null,Q&&!R?null:l(At,{detail:F,onRetry:()=>n("refresh",a).catch(()=>{})}),i||s?p("div",{role:"alert",className:"flex items-start gap-2 border-b bg-destructive/5 px-3 py-2 text-xs text-destructive",children:[l("p",{className:"min-w-0 flex-1 whitespace-pre-wrap break-words",children:i??s}),i?l(C,{size:"icon-xs",variant:"ghost","aria-label":o("panel.dismissError"),onClick:()=>f(null),children:l(W,{className:"size-3"})}):null]}):null,l("div",{className:"relative flex min-h-0 flex-1",children:R&&A?l(Qt,{environmentId:a,device:R,onBack:()=>b(""),onFloat:v?()=>y.floating?.open({environmentId:a,threadId:t},{...ge(R),reason:"user"}):void 0,onPowerOff:()=>pe(!0),onClose:()=>pe(!1)},`${a}\0${z(R)}`):m||Q||!d?l(X,{name:m?.name??o("panel.title"),...m?{description:m.version}:{},stage:"opening",message:m?m.booted?o("panel.opening"):o("panel.starting"):Q&&F?B(F):o("panel.finding")}):l(xr,{environmentId:a,host:r.hosts.find(c=>c.id===ne),grouped:M,hostReady:ce,hostFailed:F?.status==="failed",unavailableReasons:G.map(c=>c.reason??""),showNoAvdHint:ce&&!r.devices.some(c=>c.platform==="android")&&!G.some(c=>c.platform==="android"),pendingKey:m?z(m):null,onOpen:c=>{V(c)},onRefresh:g})})]})}function xr(e){let{t:a}=D(),t=e.grouped.length===0;return l("div",{className:"flex size-full flex-col overflow-y-auto px-4 py-6 text-sm text-muted-foreground",children:p("div",{className:`mx-auto flex w-full max-w-xl flex-col gap-5 ${t?"my-auto items-center text-center":""}`,children:[t?p(re,{children:[l(fe,{className:"size-6 opacity-60"}),l("p",{className:"max-w-sm",children:e.hostFailed?a("panel.hubFailed"):a("panel.empty")})]}):null,e.hostReady?e.grouped.map(o=>p("section",{className:"w-full space-y-2 text-left",children:[p("h3",{className:"flex items-center gap-2 font-medium",children:[l(fe,{className:"size-4 shrink-0"}),o.platform==="ios"?a("panel.platformIos"):a("panel.platformAndroid")]}),l("ul",{className:"divide-y rounded-md border",children:o.devices.map(r=>l("li",{children:p(C,{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(r),children:[p("span",{className:"min-w-0 flex-1",children:[l("span",{className:"block truncate text-foreground",children:r.name}),p("span",{className:"block text-xs",children:[r.version," \xB7"," ",r.booted?a("panel.running"):a("panel.stopped")]})]}),e.pendingKey===z(r)?l(H,{size:"xs"}):l("span",{className:"text-xs",children:r.booted?a("panel.open"):a("panel.start")})]})},z(r)))})]},o.platform)):null,e.unavailableReasons.filter(o=>o.length>0).map(o=>l("p",{className:"max-w-sm text-xs",children:o},o)),e.showNoAvdHint?l("p",{className:"max-w-sm text-xs",children:a("panel.noAvd")}):null,p("div",{className:`flex flex-wrap items-center gap-2 ${t?"self-center":"self-start"}`,children:[l(C,{variant:t?"outline":"ghost",size:"sm",onClick:e.onRefresh,children:a("panel.refresh")}),l(Tt,{environmentId:e.environmentId,host:e.host,busy:!1})]})]})})}function Ir(e,a){if(a!==""){if(a!==null){let t=e.find(o=>z({hostId:o.hostId,id:o.deviceId})===a);if(t)return t}return e.toSorted((t,o)=>o.openedAt.localeCompare(t.openedAt))[0]}}function Cr(e){let a=[];for(let t of["ios","android"]){let o=e.devices.filter(r=>r.platform===t).toSorted((r,d)=>Number(d.booted)-Number(r.booted)||r.name.localeCompare(d.name));o.length>0&&a.push({platform:t,devices:o})}return a}function eo({environmentId:e,threadId:a}){let t=O(),{state:o,loaded:r}=de(e),d=U(null);return k(()=>{if(!r||!oe(t,"floating"))return;let s=`${e}\0${a}`,u=d.current?.key===s?d.current.seen:null,{seen:n,opened:i}=Ta({environmentId:e,threadId:a,previous:u,sessions:o.sessions,devices:o.devices});d.current={key:s,seen:n};for(let f of i)t.floating?.open({environmentId:e,threadId:a},{...ge(f),reason:"agent",panelId:Fe})},[t,e,r,o.devices,o.sessions,a]),null}function Sr(e){return{panels:{device:function(t){return p(Re,{value:e,children:[l("style",{children:Je}),l("div",{className:`${qe} flex h-full min-h-0 flex-1 flex-col`,children:l(Yt,{environmentId:t.environmentId,threadId:t.threadId})})]})}},views:{deviceFloat:function(t){return p(Re,{value:e,children:[l("style",{children:Je}),l("div",{className:`${qe} relative size-full`,children:l(vt,{...t})})]})},deviceSessions:function(t){return l(Re,{value:e,children:l(eo,{environmentId:t.environmentId,threadId:t.threadId})})}}}}export{Sr as default};
545
+ `),id:this.lastId}),this.data=[],this.eventName="";return}if(a.startsWith(":"))return;let o=a.indexOf(":"),r=o===-1?a:a.slice(0,o),d=o===-1?"":a.slice(o+1);d.startsWith(" ")&&(d=d.slice(1)),r==="data"?this.data.push(d):r==="event"?this.eventName=d:r==="id"&&!d.includes("\0")&&(this.lastId=d)}};async function Xa(e,a,t){if(!e.ok)throw await e.body?.cancel().catch(()=>{}),new Error(`Event stream failed (${e.status}).`);let o=new da;await Ge(e,r=>{for(let d of o.push(r))a(d)},t)}var le=e=>e==="ios"?"/vendor/serve-sim":"/vendor/serve-emu";var ro=1e3,lo=500,Ve=(e,a,t)=>`${le(e.platform)}${a}${t?`?${new URLSearchParams(t).toString()}`:""}`,$a=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()},_=e=>typeof e=="object"&&e!==null,N=(e,a)=>typeof e=="number"&&Number.isFinite(e)?e:a,so=e=>{let a=e[0],t=_(a)&&_(a.frame)?a.frame:null,o=Math.max(1,N(t?.width,1)),r=Math.max(1,N(t?.height,1)),d=[],s=(u,n)=>{if(d.length>=lo||!_(u)||!_(u.frame))return;let i=u.frame,f=N(i.width,0),m=N(i.height,0);!(Math.abs(f-o)<.5&&Math.abs(m-r)<.5)&&f>0&&m>0&&d.push({id:typeof u.AXUniqueId=="string"?u.AXUniqueId:n,label:typeof u.AXLabel=="string"?u.AXLabel:"",role:typeof u.type=="string"?u.type:"",x:N(i.x,0)/o,y:N(i.y,0)/r,width:f/o,height:m/r}),(Array.isArray(u.children)?u.children:[]).forEach((b,y)=>s(b,`${n}.${y}`))};return e.forEach((u,n)=>s(u,String(n))),d},ja=e=>_(e)&&typeof e.error=="string"?e.error:"Unexpected accessibility payload.";async function Ja(e,a){if(e.platform==="ios"){let n=await $a(e,Ve(e,`/helper/${encodeURIComponent(e.deviceId)}/ax`),a);return Array.isArray(n)?{elements:so(n),errors:[]}:{elements:[],errors:[ja(n)]}}let t=await $a(e,Ve(e,"/api/accessibility",{device:e.deviceId}),a);if(!_(t)||!Array.isArray(t.nodes))return{elements:[],errors:[ja(t)]};let o=t.nodes.filter(n=>_(n)&&_(n.bounds)),r=o[0]?.bounds,d=Math.max(1,N(r?.right,1)),s=Math.max(1,N(r?.bottom,1));return{elements:o.slice(1).flatMap(n=>{let i=n.bounds,f=N(i.left,0),m=N(i.top,0),L=(N(i.right,f)-f)/d,I=(N(i.bottom,m)-m)/s,b=typeof n.text=="string"?n.text:"",y=typeof n.contentDescription=="string"?n.contentDescription:"",v=b||y;if(L>=.95&&I>=.9)return[];if(!v&&n.clickable!==!0)return[];let g=typeof n.className=="string"?n.className:"";return[{id:String(n.id??""),label:v,role:g.split(".").at(-1)??"",x:f/d,y:m/s,width:L,height:I}]}),errors:[]}}var Qa=(e,a,t)=>{let o=new AbortController,r=null,d=()=>{e.transport.fetch(a,{signal:o.signal}).then(s=>Xa(s,u=>{try{t(JSON.parse(u.data))}catch{}},o.signal)).catch(()=>{}).finally(()=>{o.signal.aborted||(r=setTimeout(d,ro))})};return d(),()=>{o.abort(),r!==null&&clearTimeout(r)}};function Ya(e,a){return e.platform!=="ios"?()=>{}:Qa(e,Ve(e,"/appstate",{device:e.deviceId}),t=>{if(_(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 Za=e=>!_(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 et(e,a){return e.platform!=="ios"?()=>{}:Qa(e,Ve(e,"/api/event-log/events",{device:e.deviceId,limit:"100"}),t=>{if(!_(t))return;if(Array.isArray(t.events)){a(t.events.flatMap(r=>Za(r)??[]),!0);return}let o=Za(t.event);o&&a([o],!1)})}function D(){return{t:O().i18n.usePluginTranslation()}}function _e(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 at(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 tt=e=>{try{return JSON.parse(e)?.type==="video-session"}catch{return!1}};function ot(e){let a=!1,t=null,o=e.length,r=0;for(;r+2<o;){if(e[r]===0&&e[r+1]===0){let d=0;if(e[r+2]===1?d=3:r+3<o&&e[r+2]===0&&e[r+3]===1&&(d=4),d){let s=e[r+d]&31;s===7&&!t&&(t=e.subarray(r+d)),s===5&&(a=!0),r+=d+1;continue}}r++}return{isKey:a,sps:t}}var uo={1:"description",2:"keyframe",3:"delta",4:"seed"},ze=class{buffer=new Uint8Array(64*1024);length=0;push(a){if(this.length+a.length>this.buffer.length){let r=this.buffer.length;for(;r<this.length+a.length;)r*=2;let d=new Uint8Array(r);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=uo[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 no={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 rt(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:no[e]??null}var lt={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 ua(e){if(e.stopped)return;let a=o=>{e.configuring=!1,e.connecting(o),e.scheduleRetry("input",()=>ua(e))},t;try{t=e.transport.connect(`${e.vendor}/ws?device=${e.device}&frame-meta=1`)}catch(o){e.events.onInputConnected(!1,o.message),a(o.message);return}e.socket=t,t.onopen=()=>{e.stopped||e.socket!==t||(e.connecting(),e.events.onInputConnected(!0))},t.onmessage=o=>{if(e.stopped||e.socket!==t)return;if(typeof o.data=="string"){tt(o.data)&&(e.closeDecoder(),e.configuring=!1,e.connecting(),e.requestKeyframe());return}let r=at(o.data),d=!e.videoDecoder||e.videoDecoder.state!=="configured",u=r.isKey===null||r.isKey&&d?ot(r.data):null,n=r.isKey??u?.isKey??!1;if(u?.sps&&d){if(e.configuring)return;e.configuring=!0;let i=e.decoderEpoch,f=()=>!e.stopped&&e.socket===t;e.configureDecoder({codec:_e(u.sps)},f).then(m=>{!f()||i!==e.decoderEpoch||(e.configuring=!1,e.awaitingKeyframe=!0,m&&e.requestKeyframe())});return}if(d){n||e.requestKeyframe();return}e.decode(n,r.data,r.timestamp)},t.onclose=o=>{e.socket===t&&(e.socket=null,e.closeDecoder(),!e.stopped&&(e.events.onInputConnected(!1,o.reason||`closed ${o.code}`),a(o.reason||void 0)))},t.onerror=()=>t.close()}function st(e){return{sendTouch(a,t,o){let r=a==="begin"?"down":a==="move"?"move":"up";e.send(JSON.stringify({type:"touch",action:r,x:t,y:o}))},sendKey(a,t){if(t!=="down")return;if(a.key==="Escape")return e.send(JSON.stringify({type:"back"}));let o=lt[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 dt(e){return{present(a,t,o){let r=e.getContext("2d");return r?((e.width!==t||e.height!==o)&&(e.width=t,e.height=o),r.drawImage(a,0,0,t,o),!0):!1}}}var ut=new TextEncoder,nt=new TextDecoder;function ft(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 it(e,a,t,o){let r=o-a.length;for(let d=t;d<=r;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 We=class{delimiter;buffer=new Uint8Array(64*1024);length=0;pos=0;state="boundary";contentLength=null;scanFrom=0;constructor(a){this.delimiter=a?ut.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 u=nt.decode(a.subarray(this.pos,s)).trim();if(this.pos=s+1,u.startsWith("--"))return this.delimiter=ut.encode(u),this.state="headers",!0}let t=this.delimiter,o=it(a,t,this.pos,this.length);if(o===-1)return this.pos=Math.max(this.pos,this.length-t.length+1),!1;let r=o+t.length;if(r+2>this.length)return this.pos=o,!1;if(a[r]===45&&a[r+1]===45)return this.state="done",!0;let d=this.lineEnd(r);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 r=nt.decode(this.buffer.subarray(a,o)).replace(/\r$/,"");if(a=o+1,r==="")break;let d=r.indexOf(":");if(d>0&&r.slice(0,d).trim().toLowerCase()==="content-length"){let s=Number.parseInt(r.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=it(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 r=o-1;r>this.pos&&this.buffer[r-1]===13&&r--;let d=this.buffer.slice(this.pos,Math.max(r,this.pos));return this.pos=o,this.state="boundary",d}}};async function io(e,a,t){let o=new We(ft(e.headers.get("content-type")));await Ge(e,r=>{for(let d of o.push(r))a(d)},t)}function xe(e){e.stopped||e.mjpeg||(e.mjpeg=!0,e.controller?.abort(),e.controller=null,e.closeDecoder(),e.connecting(),e.events.onMjpegFallback?.(),ct(e))}var na=e=>`${e.vendor}/helper/${e.device}/stream.mjpeg`;async function ct(e){let a=e.generation,t=++e.videoGeneration,o=new AbortController;e.controller=o;let r=()=>!e.stopped&&e.generation===a&&e.videoGeneration===t&&e.controller===o,d=null,s=!1,u=async()=>{s=!0;try{for(;d;){let i=d;d=null;try{let f=await e.createBitmap(new Blob([i],{type:"image/jpeg"}));try{r()&&e.paint(f,f.width,f.height)}finally{f.close()}}catch{}}}finally{s=!1}},n;try{let i=await e.transport.fetch(na(e),{signal:o.signal});if(!r()){await i.body?.cancel();return}if(!i.ok||!i.body)throw new Error(`stream ${i.status}`);if(await io(i,f=>{r()&&(d=f,s||u())},o.signal),!r())return;n="Device stream ended."}catch(i){if(!r())return;n=i.message}r()&&(e.controller=null,o.abort(),e.connecting(n),e.scheduleRetry("video",()=>{ct(e)}))}var fo=1e3,ia=15e3,co=16667,po=8,mo=e=>typeof e=="object"&&e!==null&&"present"in e;function mt(e){let{transport:a,platform:t,events:o}=e,r=mo(e.output)?e.output:dt(e.output),d=u=>e.globals?.[u]??globalThis[u],s={platform:t,transport:a,events:o,preferMjpeg:e.preferMjpeg===!0,vendor:le(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 u=d("VideoDecoder"),n=d("EncodedVideoChunk");return u&&n?{VideoDecoder:u,EncodedVideoChunk:n}:null},createBitmap(u){let n=d("createImageBitmap");return n?n(u):Promise.reject(new Error("createImageBitmap is unavailable."))},setStatus(u,n){s.stopped||o.onStatus(u,n)},fail(u){s.stopped||(s.stop(),o.onInputConnected(!1,u),o.onStatus("error",u))},connecting(u){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",u)},paint(u,n,i){if(!s.stopped){if(t==="android"&&(s.screen?.width!==n||s.screen.height!==i)&&(s.screen={width:n,height:i,orientation:n>i?"landscape_left":"portrait"},o.onScreen(s.screen)),!r.present(u,n,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"?xe(s):(s.closeDecoder(),s.connecting("Video decoder restarted."),s.requestKeyframe())},async configureDecoder(u,n=()=>!s.stopped){let i=s.webCodecs();if(!i)return!1;let f=s.decoderEpoch,m={...u,optimizeForLatency:!0},L=await i.VideoDecoder.isConfigSupported(m).catch(()=>({supported:!1}));if(!n()||f!==s.decoderEpoch)return!1;if(!L.supported)return t==="android"&&s.fail(`This browser cannot decode ${u.codec}.`),!1;try{return(!s.videoDecoder||s.videoDecoder.state==="closed")&&(s.videoDecoder=go(s,i)),s.videoDecoder.configure(m),!0}catch(I){return t==="android"&&s.fail(`Video decoder: ${I.message}`),!1}},decode(u,n,i){let f=s.videoDecoder,m=s.webCodecs();if(!(!f||f.state!=="configured"||!m)){if(s.awaitingKeyframe){if(!u)return;s.awaitingKeyframe=!1}if(f.decodeQueueSize>po){s.recoverDecoder();return}try{f.decode(new m.EncodedVideoChunk({type:u?"key":"delta",timestamp:i??s.timestamp,data:n})),s.timestamp+=co}catch{s.recoverDecoder()}}},requestKeyframe(){t==="android"&&s.socket?.readyState===1&&s.socket.send(JSON.stringify({type:"reset-video",ack:!1}))},scheduleRetry(u,n){s.stopped||s.retryTimers.has(u)||s.retryTimers.set(u,setTimeout(()=>{s.retryTimers.delete(u),n()},fo))},send(u){!s.stopped&&s.socket?.readyState===1&&s.socket.send(u)},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 n of s.retryTimers.values())clearTimeout(n);s.retryTimers.clear(),s.primeController?.abort(),s.primeController=null,s.controller?.abort(),s.controller=null;let u=s.socket;s.socket=null,u?.close(),s.closeDecoder()}};return s}function go(e,a){let t=e.videoGeneration,o=()=>e.platform!=="ios"||t===e.videoGeneration,r=new a.VideoDecoder({output:d=>{try{e.videoDecoder===r&&o()&&e.paint(d,d.displayWidth,d.displayHeight)}finally{d.close()}},error:()=>{e.stopped||e.videoDecoder!==r||!o()||e.recoverDecoder()}});return r}var Lo=3,ho=4,xo=6,gt=7,Io=13,Co=130,So=2e3,yo=new TextEncoder,vo=new TextDecoder,Ke=["portrait","landscape_left","portrait_upside_down","landscape_right"],wo=new Set(Ke);function se(e,a){let t=yo.encode(JSON.stringify(a)),o=new Uint8Array(1+t.length);return o[0]=e,o.set(t,1),o}function bo(e){if(typeof e!="object"||e===null)return null;let{width:a,height:t,orientation:o,screenId:r}=e;if(typeof a!="number"||!Number.isFinite(a)||a<=0||typeof t!="number"||!Number.isFinite(t)||t<=0||typeof o!="string"||!wo.has(o))return null;let d={width:a,height:t,orientation:o};return typeof r=="number"?{...d,screenId:r}:d}function Lt(e,a){xt(e),a?ht(e):xe(e)}async function ht(e){let a=e.generation,t=++e.videoGeneration,o=new ze,r=new AbortController;e.controller=r;let d=()=>!e.stopped&&e.generation===a&&e.videoGeneration===t&&e.controller===r,s;try{let u=await e.transport.fetch(`${e.vendor}/helper/${e.device}/stream.avcc`,{signal:r.signal});if(!d()){await u.body?.cancel();return}if(!u.ok||!u.body)throw new Error(`stream ${u.status}`);let n=u.body.getReader();for(;;){let i=setTimeout(()=>{d()&&e.fail("Device stream stopped receiving video. Reconnect to try again.")},ia);e.videoReadTimer=i;let f;try{f=await n.read()}finally{clearTimeout(i),e.videoReadTimer===i&&(e.videoReadTimer=null)}let{done:m,value:L}=f;if(!d())return;if(m)break;for(let I of o.push(L))switch(I.type){case"seed":e.createBitmap(new Blob([I.payload],{type:"image/jpeg"})).then(b=>{try{d()&&e.paint(b,b.width,b.height)}finally{b.close()}}).catch(()=>{});break;case"description":{e.awaitingKeyframe=!0;let b=await e.configureDecoder({codec:_e(I.payload),description:I.payload},d);if(!d())return;if(!b){if(await n.cancel().catch(()=>{}),!d())return;xe(e);return}break}case"keyframe":case"delta":e.decode(I.type==="keyframe",I.payload);break}}}catch(u){if(!d())return;s=u.message}d()&&(e.controller=null,r.abort(),e.closeDecoder(),e.connecting(s),e.scheduleRetry("video",()=>{ht(e)}))}async function ko(e,a){let t=new AbortController;e.primeController=t;let o=setTimeout(()=>t.abort(),So);try{let r=await e.transport.fetch(na(e),{signal:t.signal});if(e.stopped||e.generation!==a)return;await r.body?.getReader().read()}catch{}finally{clearTimeout(o),t.abort(),e.primeController===t&&(e.primeController=null)}}async function xt(e){if(e.stopped)return;let a=e.generation;if(await ko(e,a),e.stopped||e.generation!==a)return;let t=()=>e.scheduleRetry("input",()=>{xt(e)}),o;try{o=e.transport.connect(`${e.vendor}/helper/ws?device=${e.device}`)}catch(r){e.events.onInputConnected(!1,r.message),t();return}e.socket=o,o.onopen=()=>{e.stopped||e.socket!==o||(o.send(se(Io,{enabled:!1})),e.events.onInputConnected(!0))},o.onmessage=r=>{if(e.stopped||e.socket!==o||typeof r.data=="string")return;let d=new Uint8Array(r.data);if(!(d.length<1||d[0]!==Co))try{let s=bo(JSON.parse(vo.decode(d.subarray(1))));s&&(e.screen=s,e.events.onScreen(s))}catch{}},o.onclose=r=>{e.socket===o&&(e.socket=null,!e.stopped&&(e.events.onInputConnected(!1,r.reason||(r.code===1006?"input socket refused":`closed ${r.code}`)),t()))},o.onerror=()=>o.close()}function Do(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 It(e){return{sendTouch(a,t,o){e.send(se(Lo,{type:a,...Do(e,t,o)}))},sendKey(a,t){let o=rt(a.code);o!==null&&e.send(se(xo,{type:t,usage:o}))},pressButton(a){let t=a==="home"?"home":a==="appSwitcher"?"app_switcher":a==="power"?"lock":null;t&&e.send(se(ho,{button:t}))},rotate(){let a=e.screen?.orientation??"portrait",t=Ke[(Ke.indexOf(a)+1)%Ke.length];e.send(se(gt,{orientation:t}))},setOrientation(a){e.send(se(gt,{orientation:a}))}}}function Ct(e){let a=mt(e),t=e.platform==="ios"?It(a):st(a);return{start:()=>{if(!a.stopped)return;a.stopped=!1,a.generation++,a.configuring=!1,a.connecting();let r=a.webCodecs()!==null&&!(e.platform==="ios"&&a.preferMjpeg);e.platform==="ios"?Lt(a,r):r?ua(a):a.fail("This browser cannot decode the Android stream (WebCodecs unavailable).")},stop:a.stop,isMjpeg:()=>a.mjpeg,...t}}var Po=56,Ao=2e3;function To(e,a,t,o=0){let r=Math.max(0,a-o);if(r===0||t===0)return{width:0,height:0};let d={width:t*e,height:t};return d.width<=r?d:{width:r,height:r/e}}function Mo(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),r=Math.min(a.width,a.height);return t?o/r:r/o}function Bo(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 Ro=()=>typeof navigator<"u"&&/iPhone|iPad|iPod/.test(navigator.userAgent);function Xe(e){let{t:a}=D(),t=U(null),o=U(null),[r,d]=h("connecting"),[s,u]=h(),[n,i]=h(null),[f,m]=h({connected:!1}),{onHandle:L,onStreaming:I,onScreen:b,transport:y,platform:v,deviceId:g}=e;k(()=>b?.(n),[b,n]),k(()=>{let c=t.current;if(!c)return;let S=Ct({transport:y,platform:v,deviceId:g,output:c,preferMjpeg:Ro(),events:{onStatus:(T,q)=>{d(T),u(q),I(T==="streaming")},onScreen:i,onInputConnected:(T,q)=>{m({connected:T,...q?{detail:q}:{}}),L({pressButton:S.pressButton,rotate:S.rotate,inputConnected:T})}}});return o.current=S,m({connected:!1}),S.start(),L({pressButton:S.pressButton,rotate:S.rotate,inputConnected:!1}),()=>{S.stop(),o.current=null,L(null),I(!1),i(null)}},[g,L,I,v,y]);let P=U(null),[A,R]=h({width:0,height:0});k(()=>{let c=P.current;if(!c)return;let S=()=>{let q=c.getBoundingClientRect();R(me=>me.width===q.width&&me.height===q.height?me:{width:q.width,height:q.height})};S();let T=new ResizeObserver(S);return T.observe(c),()=>T.disconnect()},[]);let E=e.withControls?Po:0,M=ae(()=>To(Mo(v,n),A.width,A.height,E),[A,E,v,n]),F=Bo(v,n),Q=F===90||F===-90?{width:M.height,height:M.width,left:(M.width-M.height)/2,top:(M.height-M.width)/2,transform:`rotate(${F}deg)`}:{width:M.width,height:M.height,...F?{transform:`rotate(${F}deg)`}:{}},[B,K]=h([]);k(()=>{if(!e.axOverlay)return;let c=null,S=null,T=!1,q=async()=>{c=new AbortController;try{let me=await Ja({transport:y,platform:v,deviceId:g},c.signal);T||K(me.elements)}catch{}T||(S=setTimeout(()=>{q()},Ao))};return q(),()=>{T=!0,c?.abort(),S&&clearTimeout(S),K([])}},[g,v,e.axOverlay,y]);let G=U(!1),V=c=>{let S=c.currentTarget.getBoundingClientRect(),T=(c.clientX-S.left)/S.width,q=(c.clientY-S.top)/S.height;return{x:Math.min(1,Math.max(0,T)),y:Math.min(1,Math.max(0,q))}},pe=c=>{if(!G.current)return;G.current=!1;let{x:S,y:T}=V(c);o.current?.sendTouch("end",S,T)};return p("div",{ref:P,className:"relative flex size-full min-h-0 min-w-0 items-center justify-center overflow-hidden",style:E?{paddingRight:E}:void 0,tabIndex:0,role:"application","aria-label":a(v==="ios"?"stream.iosScreen":"stream.androidScreen"),onKeyDown:c=>{c.target===c.currentTarget&&(c.metaKey&&!["r","R"].includes(c.key)||(c.preventDefault(),o.current?.sendKey(c.nativeEvent,"down")))},onKeyUp:c=>{c.target===c.currentTarget&&o.current?.sendKey(c.nativeEvent,"up")},children:[p("div",{className:"relative touch-none select-none",style:{width:M.width,height:M.height},onPointerDown:c=>{c.currentTarget.setPointerCapture(c.pointerId),c.currentTarget.parentElement?.focus(),G.current=!0;let{x:S,y:T}=V(c);o.current?.sendTouch("begin",S,T)},onPointerMove:c=>{if(!G.current)return;let{x:S,y:T}=V(c);o.current?.sendTouch("move",S,T)},onPointerUp:pe,onPointerCancel:pe,children:[l("canvas",{ref:t,className:"absolute top-0 left-0",style:Q}),B.length>0?l("div",{className:"pointer-events-none absolute inset-0","aria-hidden":!0,children:B.map(c=>l("div",{className:"absolute border border-info/80 bg-info/10",style:{left:`${c.x*100}%`,top:`${c.y*100}%`,width:`${c.width*100}%`,height:`${c.height*100}%`},children:c.label?l("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:c.label}):null},c.id))}):null]}),r==="streaming"&&!f.connected?l("div",{className:"pointer-events-none absolute inset-x-0 bottom-0 flex justify-center p-2",children:l("span",{className:"rounded-md bg-background/85 px-2 py-1 text-xs text-muted-foreground",children:f.detail?a("stream.inputLostDetail",{detail:f.detail}):a("stream.inputLost")})}):null,r!=="streaming"?l("div",{className:"absolute inset-0 bg-background",children:l(X,{name:e.deviceName,description:e.deviceDescription,stage:r==="error"?"error":"connecting",message:r==="error"?s??a("stream.failed"):a("stream.connecting"),children:r==="error"?l(C,{size:"sm",variant:"outline",onClick:()=>{o.current?.stop(),o.current?.start()},children:a("stream.reconnect")}):null})}):null]})}var Fo={hosts:[],hostStatuses:{},devices:[],sessions:[],bootingDevices:[],revision:0};function de(e){let t=O().commands.useSubscription("state",{},{environmentId:e});return{state:t.data??Fo,loaded:t.data!==null,error:t.error,unavailable:t.isUnavailable}}function ue(){let e=O();return ee((a,t,o={})=>e.commands.invoke(a,o,{environmentId:t}),[e])}var ne="local",$e=class extends Error{code;constructor(a,t,o){super(t,o),this.name="DeviceError",this.code=a}};var St="hub";function je(e){let a=O(),[t,o]=h({status:"connecting"});return k(()=>{let r=a.network;if(!oe(a,"network")||r===void 0){o({status:"failed",message:null});return}let d=!1;return o({status:"connecting"}),r.client(e).then(s=>{d||o({status:"ready",transport:{fetch:(u,n)=>s.fetch(St,u,{...n,instance:ne}),connect:u=>s.connect(St,u,{instance:ne})}})},s=>{d||o({status:"failed",message:s instanceof Error?s.message:String(s)})}),()=>{d=!0}},[a,e]),t}var yt=()=>{};function vt(e){let{environmentId:a,threadId:t,hostId:o,deviceId:r,platform:d}=e,s=e[Da],u=O(),{t:n}=D(),{state:i,loaded:f}=de(a),m=je(a),L=ae(()=>({environmentId:a,threadId:t}),[a,t]),I=i.devices.find(P=>P.hostId===o&&P.id===r),b=i.sessions.some(P=>P.threadId===t&&P.hostId===o&&P.deviceId===r);k(()=>{f&&!b&&u.floating?.close(L,s.key)},[u,s.key,f,b,L]),k(()=>(s.setOpenInPanel(()=>{Oe(a,t,s.key),u.floating?.openPanel(L,Fe),u.floating?.close(L,s.key)}),()=>s.setOpenInPanel(null)),[u,a,s,L,t]);let y=ee(P=>s.reportSourceSize(P===null?null:Pa(P)),[s]),v=I?.name??r,g=I?.version??d;return m.status!=="ready"?l(X,{name:v,description:g,stage:m.status==="failed"?"error":"connecting",message:m.status==="failed"?m.message??n("workspace.needsNewerApp"):n("stream.connecting")}):l(Xe,{transport:m.transport,platform:d,deviceId:r,deviceName:v,deviceDescription:g,axOverlay:!1,withControls:!1,onHandle:yt,onStreaming:yt,onScreen:y})}var Ze=(...e)=>e.filter((a,t,o)=>!!a&&a.trim()!==""&&o.indexOf(a)===t).join(" ").trim();var wt=e=>e.replace(/([a-z0-9])([A-Z])/g,"$1-$2").toLowerCase();var bt=e=>e.replace(/^([A-Z])|[\s-_]+(\w)/g,(a,t,o)=>o?o.toUpperCase():t.toLowerCase());var fa=e=>{let a=bt(e);return a.charAt(0).toUpperCase()+a.slice(1)};var kt={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 Dt=e=>{for(let a in e)if(a.startsWith("aria-")||a==="role"||a==="title")return!0;return!1};var Pt=Be(({color:e="currentColor",size:a=24,strokeWidth:t=2,absoluteStrokeWidth:o,className:r="",children:d,iconNode:s,...u},n)=>Y("svg",{ref:n,...kt,width:a,height:a,stroke:e,strokeWidth:o?Number(t)*24/Number(a):t,className:Ze("lucide",r),...!d&&!Dt(u)&&{"aria-hidden":"true"},...u},[...s.map(([i,f])=>Y(i,f)),...Array.isArray(d)?d:[d]]));var x=(e,a)=>{let t=Be(({className:o,...r},d)=>Y(Pt,{ref:d,iconNode:a,className:Ze(`lucide-${wt(fa(e))}`,`lucide-${e}`,o),...r}));return t.displayName=fa(e),t};var Uo=[["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"}]],Ie=x("camera",Uo);var Oo=[["path",{d:"m6 9 6 6 6-6",key:"qrunsl"}]],Ce=x("chevron-down",Oo);var qo=[["path",{d:"m15 18-6-6 6-6",key:"1wnfg3"}]],Se=x("chevron-left",qo);var Ho=[["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"}]],$=x("ellipsis",Ho);var Eo=[["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"}]],j=x("house",Eo);var No=[["circle",{cx:"12",cy:"12",r:"10",key:"1mglay"}],["path",{d:"M12 16v-4",key:"1dtifu"}],["path",{d:"M12 8h.01",key:"e9boi3"}]],ye=x("info",No);var Go=[["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"}]],ve=x("moon",Go);var Vo=[["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"}]],we=x("picture-in-picture-2",Vo);var zo=[["path",{d:"M12 2v10",key:"mnfbl"}],["path",{d:"M18.4 6.6a9 9 0 1 1-12.77.04",key:"obofu9"}]],be=x("power",zo);var _o=[["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"}]],ie=x("rotate-ccw",_o);var Wo=[["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"}]],ke=x("rotate-cw",Wo);var Ko=[["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"}]],De=x("sliders-horizontal",Ko);var Xo=[["rect",{width:"14",height:"20",x:"5",y:"2",rx:"2",ry:"2",key:"1yt0o3"}],["path",{d:"M12 18h.01",key:"mhygvu"}]],fe=x("smartphone",Xo);var $o=[["rect",{width:"18",height:"18",x:"3",y:"3",rx:"2",key:"afitv7"}]],Pe=x("square",$o);var jo=[["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"}]],Ae=x("sun",jo);var Zo=[["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"}]],Te=x("type",Zo);var Jo=[["path",{d:"M18 6 6 18",key:"1bl5f8"}],["path",{d:"m6 6 12 12",key:"d8bk6v"}]],W=x("x",Jo);function Qo(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 ca(){let{t:e}=D();return a=>Qo(a,e)}function At(e){let{t:a}=D(),t=ca(),[o,r]=h(!1),d=e.detail;return!d||d.status==="ready"||d.status==="idle"?null:d.status==="failed"?p("div",{role:"alert",className:"flex items-start gap-2 border-b bg-destructive/5 px-3 py-2 text-xs",children:[p("div",{className:"min-w-0 flex-1 space-y-0.5",children:[l("p",{className:"font-medium text-destructive-foreground",children:a("panel.hostFailed")}),d.message?l("p",{className:"whitespace-pre-wrap break-words text-muted-foreground",children:d.message}):null]}),p(C,{size:"xs",variant:"outline",disabled:o,onClick:()=>{r(!0),e.onRetry().finally(()=>r(!1))},children:[o?l(H,{size:"xs"}):l(ke,{}),a(o?"panel.retrying":"panel.retry")]})]}):p("div",{role:"status",className:"flex items-center gap-2 border-b px-3 py-2 text-xs text-muted-foreground",children:[l(H,{size:"xs"}),l("span",{className:"min-w-0 flex-1",children:t(d)})]})}var pa=["hub","agent"],ma=e=>e!==void 0&&!e.installedVersions.includes(e.requiredVersion);function Tt(e){let{t:a}=D(),t=ue(),[o,r]=h(null),[d,s]=h(null),u=e.host?.tools,n=e.busy||o!==null,i=m=>{r(m),s(null),(m==="check"?t("inspect",e.environmentId):t("updateTool",e.environmentId,{tool:m})).catch(()=>s(a(m==="check"?"versions.checkFailed":"versions.updateFailed"))).finally(()=>r(null))},f=m=>m??a("versions.none");return p(_a,{children:[p(Wa,{render:l(C,{size:"xs",variant:"ghost","aria-label":a("versions.title")}),children:[l(ye,{}),a("versions.title"),pa.some(m=>ma(u?.[m]))?l("span",{className:"size-1.5 rounded-full bg-warning","aria-hidden":!0}):null]}),l(Ka,{side:"bottom",align:"start",className:"w-80",children:p("div",{className:"space-y-3 text-xs",children:[pa.map(m=>{let L=u?.[m];return p("section",{className:"space-y-1",children:[l("h4",{className:"font-medium text-foreground",children:a(m==="hub"?"versions.hubName":"versions.agentName")}),p("dl",{className:"grid grid-cols-[auto_1fr] gap-x-3 gap-y-0.5 text-muted-foreground",children:[l("dt",{children:a("versions.required")}),l("dd",{className:"font-mono",children:f(L?.requiredVersion)}),l("dt",{children:a("versions.installed")}),l("dd",{className:"font-mono",children:L&&L.installedVersions.length>0?L.installedVersions.join(", "):a("versions.none")}),l("dt",{children:a("versions.running")}),l("dd",{className:"font-mono",children:f(L?.runningVersion)})]}),ma(L)?p(C,{size:"xs",variant:"outline",disabled:n,onClick:()=>i(m),children:[o===m?l(H,{size:"xs"}):null,a("versions.updateTo",{version:L?.requiredVersion??""})]}):null]},m)}),u===void 0?l("p",{className:"text-muted-foreground",children:a("versions.unknown")}):null,pa.some(m=>ma(u?.[m]))?l("p",{className:"text-muted-foreground",children:a("versions.pendingPolicy")}):null,d?l("p",{role:"alert",className:"text-destructive-foreground",children:d}):null,p("div",{className:"flex items-center justify-between gap-2 border-t pt-2",children:[l("p",{className:"text-muted-foreground",children:a("versions.checkHint")}),p(C,{size:"xs",variant:"ghost",disabled:n,onClick:()=>i("check"),children:[o==="check"?l(H,{size:"xs"}):null,a("versions.check")]})]})]})})]})}var Mt=["small","default","large","extra-large"],Yo=e=>Mt.includes(e);function Bt(e){let{t:a}=D(),{handle:t,controls:o}=e,r=o.detail?.settings,d=!t?.inputConnected,s=r?.appearance==="dark"?"light":"dark",u=n=>a(n==="small"?"rail.textSmall":n==="default"?"rail.textDefault":n==="large"?"rail.textLarge":"rail.textExtraLarge");return l("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:p("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:[l(Z,{label:a("rail.home"),disabled:d,onClick:()=>t?.pressButton("home"),children:l(j,{})}),e.platform==="android"?p(re,{children:[l(Z,{label:a("rail.back"),disabled:d,onClick:()=>t?.pressButton("back"),children:l(Se,{})}),l(Z,{label:a("rail.recents"),disabled:d,onClick:()=>t?.pressButton("recents"),children:l(Pe,{})}),p(He,{children:[l(Ne,{render:l(C,{size:"icon-sm",variant:"ghost","aria-label":a("rail.rotate"),disabled:o.disabled}),children:l(ie,{})}),p(Ee,{side:"left",children:[l(Le,{onClick:()=>{o.act({type:"setOrientation",value:"portrait"})},children:a("rail.portrait")}),l(Le,{onClick:()=>{o.act({type:"setOrientation",value:"landscape_left"})},children:a("rail.landscape")})]})]})]}):l(Z,{label:a("rail.rotate"),disabled:d,onClick:()=>t?.rotate(),children:l(ie,{})}),l(er,{}),l(Z,{label:a(s==="dark"?"rail.toDark":"rail.toLight"),disabled:o.disabled||!r?.appearance,onClick:()=>{o.act({type:"setAppearance",value:s})},children:r?.appearance==="dark"?l(Ae,{}):l(ve,{})}),p(He,{children:[l(Ne,{render:l(C,{size:"icon-sm",variant:"ghost","aria-label":a("rail.textSize"),title:a("rail.textSize"),disabled:o.disabled||!r?.textSize}),children:l(Te,{})}),l(Ee,{side:"left",className:"min-w-40",children:l(Oa,{value:r?.textSize??"",onValueChange:n=>{Yo(n)&&o.act({type:"setTextSize",value:n})},children:Mt.map(n=>l(qa,{value:n,children:u(n)},n))})})]}),l(Z,{label:a("rail.tools"),pressed:e.toolsOpen,onClick:e.onTools,children:l(De,{})}),l(Z,{label:e.screenshotPending?a("rail.capturing"):a("rail.screenshot"),disabled:!e.streaming||e.screenshotPending,onClick:e.onScreenshot,children:l(Ie,{})}),e.onFloat?l(Z,{label:a("rail.float"),onClick:e.onFloat,children:l(we,{})}):null,p(He,{children:[l(Ne,{render:l(C,{size:"icon-sm",variant:"ghost","aria-label":a("rail.more"),title:a("rail.more")}),children:l($,{})}),p(Ee,{side:"left",align:"end",children:[p(Le,{onClick:e.onClose,children:[l(W,{}),a("rail.closePanel")]}),l(Ua,{}),p(Le,{variant:"destructive",onClick:e.onPowerOff,children:[l(be,{}),a("rail.powerOff")]})]})]})]})})}function er(){return l("div",{"aria-hidden":!0,className:"my-1 h-px w-5 shrink-0 bg-border/70"})}function Z(e){return p(Ba,{children:[l(Fa,{render:l(C,{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}),l(Ra,{side:"left",children:e.label})]})}var ga=(e,a)=>new $e("invalid-input",`Invalid ${e}: ${a}.`);var Rt=4096,Ft=["light","dark"],Ut=["small","default","large","extra-large"];var Ot=["clear","tinted"],qt=["none","grayscale","red-green","green-red","blue-yellow"],Ht=["portrait","landscape_left","portrait_upside_down","landscape_right"],Et=["camera","microphone","photos","contacts","calendar","reminders","location","notifications","motion","media-library","faceid"];var ar=e=>typeof e=="object"&&e!==null&&!Array.isArray(e);var Nt=e=>{let a=typeof e=="string"?{aps:{alert:e}}:e;if(!ar(a))throw ga("push payload","expected a string or an object");let t;try{t=JSON.stringify(a)}catch{t=void 0}if(t===void 0)throw ga("push payload","could not be encoded as JSON");if(new TextEncoder().encode(t).length>Rt)throw ga("push payload",`larger than ${String(Rt)} bytes`);return t};var tr=new Set(["setAppearance","setTextSize","setToggle","setLiquidGlass","setColorFilter","setLocation","clearLocation","setPermission","openUrl","launchApp","terminateApp","sendPush"]),or=new Set(["setAppearance","setTextSize","setToggle","setOrientation","setLocation","clearLocation","setPermission","openUrl","launchApp","terminateApp"]),rr=new Set(["reduceMotion","increaseContrast","reduceTransparency","showBorders","voiceOver"]),lr=new Set(["reduceMotion","networkEnabled"]),Gt=(e,a)=>(e==="ios"?tr:or).has(a.type)?a.type==="setToggle"?(e==="ios"?rr:lr).has(a.setting):!0:!1;function te(e){return p("section",{className:"flex flex-col gap-2 border-b px-3 py-2.5",children:[l("h3",{className:"text-xs font-medium text-muted-foreground",children:e.title}),e.children]})}function J(e){return p("div",{className:"flex min-h-7 items-center justify-between gap-3",children:[l("span",{className:"shrink-0 text-xs text-muted-foreground",children:e.label}),l("div",{className:"flex min-w-0 items-center justify-end",children:e.children})]})}function La(e){return l(J,{label:e.label,children:l(Ma,{"aria-label":e.label,checked:e.checked??!1,disabled:e.disabled||e.checked===void 0,onCheckedChange:a=>{e.onChange(a)}})})}function ha(e){return l(Va,{"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=>l(za,{size:"xs",value:a.value,children:a.label},a.value))})}function Me(e){let a=e.options.find(t=>t.value===e.value);return p(ta,{value:e.value,disabled:e.disabled,onValueChange:t=>{let o=e.options.find(r=>r.value===t);o&&o.value!==e.value&&e.onChange(o.value)},children:[l(oa,{size:"xs",className:e.width??"w-40","aria-label":e.ariaLabel,children:l(ra,{children:a?a.label:l("span",{className:"text-muted-foreground",children:e.placeholder})})}),l(la,{align:"end",alignItemWithTrigger:!1,children:e.options.map(t=>l(sa,{value:t.value,children:t.label},t.value))})]})}function xa(e){let[a,t]=h(""),o=a.trim()||e.fallback||"",r=()=>{o&&e.onSubmit(o).then(()=>t(""))};return p("form",{className:"flex gap-1.5",onSubmit:d=>{d.preventDefault(),r()},children:[l(he,{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)}),l(C,{type:"submit",size:"xs",variant:"outline",disabled:e.disabled||!o,children:e.action})]})}var Vt=[{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 _t(e){let{t:a}=D(),[t,o]=h(""),[r,d]=h(""),s={latitude:Number(t),longitude:Number(r)},u=t.trim()!==""&&r.trim()!==""&&Math.abs(s.latitude)<=90&&Math.abs(s.longitude)<=180,n=(i,f)=>e.act({type:"setLocation",latitude:i,longitude:f});return p(te,{title:a("tools.location.title"),children:[p("div",{className:"flex gap-1.5",children:[l(he,{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)}),l(he,{size:"compact",className:"min-w-0 flex-1 font-mono",placeholder:a("tools.location.longitude"),"aria-label":a("tools.location.longitude"),inputMode:"decimal",value:r,disabled:e.disabled,onChange:i=>d(i.target.value)})]}),p("div",{className:"flex flex-wrap items-center gap-1.5",children:[p(ta,{value:null,disabled:e.disabled,onValueChange:i=>{let f=Vt.find(m=>m.key===i);f&&(o(String(f.latitude)),d(String(f.longitude)),n(f.latitude,f.longitude))},children:[l(oa,{size:"xs",className:"w-32","aria-label":a("tools.location.preset"),children:l(ra,{children:l("span",{className:"text-muted-foreground",children:a("tools.location.presetPlaceholder")})})}),l(la,{align:"start",alignItemWithTrigger:!1,children:Vt.map(i=>l(sa,{value:i.key,children:a(i.key)},i.key))})]}),l(C,{size:"xs",variant:"outline",disabled:e.disabled||!u,onClick:()=>{n(s.latitude,s.longitude)},children:a("tools.location.set")}),l(C,{size:"xs",variant:"ghost",disabled:e.disabled,onClick:()=>{o(""),d(""),e.act({type:"clearLocation"})},children:a("tools.location.clear")})]})]})}var sr={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"},dr=new Set(["camera","microphone","photos","contacts","calendar","location","notifications","motion"]);function Wt(e){let{t:a}=D(),t=e.platform==="ios",[o,r]=h(""),[d,s]=h("camera"),u=o.trim()||e.defaultAppId,n=Et.filter(f=>t||dr.has(f)).map(f=>({value:f,label:a(!t&&f==="motion"?"tools.permissions.activity":sr[f])})),i=f=>{e.act({type:"setPermission",appId:u,permission:d,decision:f})};return p(te,{title:a("tools.permissions.title"),children:[l(he,{size:"compact",className:"font-mono",placeholder:e.defaultAppId||a("tools.permissions.appId"),"aria-label":a("tools.permissions.appId"),value:o,disabled:e.disabled,onChange:f=>r(f.target.value)}),p("div",{className:"flex flex-wrap items-center gap-1.5",children:[l(Me,{ariaLabel:a("tools.permissions.permission"),value:d,options:n,placeholder:a("tools.unknown"),disabled:e.disabled,onChange:f=>(s(f),Promise.resolve())}),l(C,{size:"xs",variant:"outline",disabled:e.disabled||!u,onClick:()=>i("grant"),children:a("tools.permissions.grant")}),l(C,{size:"xs",variant:"outline",disabled:e.disabled||!u,onClick:()=>i("revoke"),children:a("tools.permissions.revoke")}),t?l(C,{size:"xs",variant:"ghost",disabled:e.disabled||!u,onClick:()=>i("reset"),children:a("tools.permissions.reset")}):null]})]})}var ur=e=>{let a=e;try{let t=JSON.parse(e);typeof t=="object"&&t!==null&&!Array.isArray(t)&&(a=t)}catch{}try{return Nt(a),a}catch{return null}};function Kt(e){let{t:a}=D(),[t,o]=h(""),r=t.trim(),d=r?ur(r):null,s=e.appId;return p(te,{title:a("tools.push.title"),children:[l(Ha,{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:u=>o(u.target.value)}),p("div",{className:"flex items-center gap-2",children:[l(C,{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?r&&d===null?l("p",{className:"text-xs text-destructive-foreground",children:a("tools.push.invalid")}):null:l("p",{className:"text-xs text-muted-foreground",children:a("tools.push.needsApp")})]})]})}var zt=100;function Xt(e){let{t:a}=D(),[t,o]=h(!1),[r,d]=h([]),{transport:s,platform:u,deviceId:n}=e;return k(()=>{if(!t)return;let i=et({transport:s,platform:u,deviceId:n},(f,m)=>{d(L=>{let I=m?[...f]:[...L,...f];return I.length>zt?I.slice(-zt):I})});return()=>{i(),d([])}},[t,s,u,n]),p(Ea,{open:t,onOpenChange:o,children:[p(Na,{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"),l(Ce,{className:`ml-auto size-3.5 transition-transform ${t?"rotate-180":""}`})]}),l(Ga,{children:l("ol",{className:"max-h-64 overflow-y-auto px-3 py-2 font-mono text-ui-2xs leading-relaxed",children:r.length===0?l("li",{className:"text-muted-foreground",children:a("tools.eventLog.empty")}):r.map(i=>p("li",{className:"flex gap-2",children:[l("span",{className:"shrink-0 text-muted-foreground",children:i.timestamp.slice(11,19)}),l("span",{className:"truncate",children:i.summary})]},i.id))})})]})}var nr=640,ir={light:"tools.settings.light",dark:"tools.settings.dark"},fr={small:"tools.settings.textSmall",default:"tools.settings.textDefault",large:"tools.settings.textLarge","extra-large":"tools.settings.textExtraLarge"},cr={clear:"tools.settings.glassClear",tinted:"tools.settings.glassTinted"},pr={none:"tools.settings.filterNone",grayscale:"tools.settings.filterGrayscale","red-green":"tools.settings.filterRedGreen","green-red":"tools.settings.filterGreenRed","blue-yellow":"tools.settings.filterBlueYellow"},mr={portrait:"tools.settings.orientationPortrait",landscape_left:"tools.settings.orientationLandscapeLeft",portrait_upside_down:"tools.settings.orientationUpsideDown",landscape_right:"tools.settings.orientationLandscapeRight"},gr=[{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 $t(e){let{t:a}=D(),{device:t,controls:o}=e,{detail:r,pending:d,error:s,foregroundApp:u,disabled:n,act:i}=o,f=r?.settings,m=t.platform==="ios",L=U(null),[I,b]=h(!0);va(()=>{let g=L.current?.parentElement;if(!g)return;let P=()=>b(g.clientWidth<nr);P();let A=new ResizeObserver(P);return A.observe(g),()=>A.disconnect()},[]);let y=Ut.map(g=>({value:g,label:a(fr[g])})),v=gr.filter(g=>Gt(t.platform,{type:"setToggle",setting:g.setting,value:!0}));return p("aside",{ref:L,"aria-label":a("tools.title"),className:`flex min-h-0 flex-col border-l bg-background text-sm ${I?"absolute inset-y-0 right-0 z-10 w-full max-w-72 shadow-lg":"w-72 shrink-0"}`,children:[p("div",{className:"flex h-9 shrink-0 items-center gap-2 border-b px-3",children:[l("span",{className:"font-medium",children:a("tools.title")}),d?l(H,{size:"sm"}):null,l(C,{size:"icon-xs",variant:"ghost-muted","aria-label":a("tools.close"),className:"ml-auto",onClick:e.onClose,children:l(W,{})})]}),p("div",{className:"min-h-0 flex-1 overflow-y-auto",children:[s?l("p",{role:"alert",className:"border-b bg-destructive/10 px-3 py-2 text-xs text-destructive-foreground",children:s}):null,r===null&&!s?p("div",{className:"flex items-center gap-2 px-3 py-3 text-xs text-muted-foreground",children:[l(H,{size:"sm"}),a("tools.reading")]}):null,p(te,{title:a("tools.app.title"),children:[l(J,{label:a("tools.app.foreground"),children:l("span",{className:"truncate font-mono text-xs",children:u?.id??a("tools.app.none")})}),u?p("div",{className:"flex gap-1.5",children:[l(C,{size:"xs",variant:"outline",disabled:n,onClick:()=>{i({type:"terminateApp",appId:u.id})},children:a("tools.app.terminate")}),l(C,{size:"xs",variant:"outline",disabled:n,onClick:()=>{i({type:"launchApp",appId:u.id})},children:a("tools.app.relaunch")})]}):null,l(xa,{placeholder:a("tools.app.urlPlaceholder"),action:a("tools.app.open"),disabled:n,onSubmit:g=>i({type:"openUrl",url:g})}),l(xa,{placeholder:a(m?"tools.app.bundleIdPlaceholder":"tools.app.packagePlaceholder"),action:a("tools.app.launch"),disabled:n,fallback:u?.id,onSubmit:g=>i({type:"launchApp",appId:g})})]}),p(te,{title:a(m?"tools.settings.titleIos":"tools.settings.titleAndroid"),children:[l(J,{label:a("tools.settings.appearance"),children:l(ha,{label:a("tools.settings.appearance"),value:f?.appearance,options:Ft.map(g=>({value:g,label:a(ir[g])})),disabled:n,onChange:g=>i({type:"setAppearance",value:g})})}),l(J,{label:a("tools.settings.textSize"),children:l(Me,{ariaLabel:a("tools.settings.textSize"),value:f?.textSize??null,options:y,placeholder:a("tools.unknown"),disabled:n,onChange:g=>i({type:"setTextSize",value:g})})}),m?p(re,{children:[l(J,{label:a("tools.settings.liquidGlass"),children:l(ha,{label:a("tools.settings.liquidGlass"),value:f?.liquidGlass,options:Ot.map(g=>({value:g,label:a(cr[g])})),disabled:n,onChange:g=>i({type:"setLiquidGlass",value:g})})}),l(J,{label:a("tools.settings.colorFilter"),children:l(Me,{ariaLabel:a("tools.settings.colorFilter"),value:f?.colorFilter??null,options:qt.map(g=>({value:g,label:a(pr[g])})),placeholder:a("tools.unknown"),disabled:n,onChange:g=>i({type:"setColorFilter",value:g})})})]}):l(J,{label:a("tools.settings.orientation"),children:l(Me,{ariaLabel:a("tools.settings.orientation"),value:null,options:Ht.map(g=>({value:g,label:a(mr[g])})),placeholder:a("tools.settings.rotateTo"),disabled:n,onChange:g=>i({type:"setOrientation",value:g})})}),v.map(g=>l(La,{label:a(g.labelKey),checked:f?.[g.setting],disabled:n,onChange:P=>i({type:"setToggle",setting:g.setting,value:P})},g.setting))]}),l(te,{title:a("tools.accessibility.title"),children:l(La,{label:a("tools.accessibility.overlay"),checked:e.axOverlay,disabled:!1,onChange:g=>(e.onAxOverlayChange(g),Promise.resolve())})}),l(_t,{disabled:n,act:i}),l(Wt,{platform:t.platform,defaultAppId:u?.id??"",disabled:n,act:i}),m?l(Kt,{appId:u?.id,disabled:n,act:i}):null,m?l(Xt,{transport:e.transport,platform:t.platform,deviceId:t.id}):null]})]})}var Lr=2e4,Ia=class extends Error{status;constructor(a){super(`Screenshot capture failed (${a}). Try again.`),this.status=a}};async function jt(e,a,t,o){let r=AbortSignal.timeout(Lr),d=await e.fetch(`${le(a)}/api/screenshot?device=${encodeURIComponent(t)}`,{method:"POST",signal:o?AbortSignal.any([o,r]):r});if(!d.ok)throw new Ia(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 Zt=e=>e instanceof Error?e.message:String(e);function Jt(e){let{environmentId:a,device:t}=e,o=ue(),[r,d]=h(null),[s,u]=h(!1),[n,i]=h(null),f=U(!1),m=U(0),L={hostId:t.hostId,deviceId:t.id},I=y=>o("detail",a,L).then(v=>{m.current===y&&(d(v),i(null))},v=>{m.current===y&&(d(null),i(Zt(v)))});return k(()=>{let y=++m.current;return I(y),()=>{m.current++}},[a,t.hostId,t.id]),{detail:r,pending:s,error:n,act:async y=>{if(f.current||r===null)return;f.current=!0;let v=++m.current;u(!0),i(null);try{let g=await o("action",a,{...L,...y});m.current===v?d(g):await I(++m.current)}catch(g){m.current===v&&i(Zt(g))}finally{f.current=!1,u(!1)}},disabled:s||r===null,foregroundApp:e.foreground===void 0?r?.foregroundApp??null:e.foreground}}var hr=()=>typeof window<"u"&&"ReactNativeWebView"in window;function Qt(e){let{t:a}=D(),t=je(e.environmentId),[o,r]=h(null),[d,s]=h(!1),[u,n]=h(!1),[i,f]=h(!1),[m,L]=h(),[I,b]=h(!1),[y,v]=h(null),[g,P]=h(null),A=U(null),R=U(null),E=t.status==="ready"?t.transport:null,M=Jt({environmentId:e.environmentId,device:e.device,foreground:m}),F=ee(B=>r(B),[]),ce=ee(B=>s(B),[]);k(()=>{if(!E)return;let B=Ya({transport:E,platform:e.device.platform,deviceId:e.device.id},L);return()=>{B(),L(void 0)}},[e.device.id,e.device.platform,E]),k(()=>()=>{A.current?.abort(),R.current&&URL.revokeObjectURL(R.current)},[]);let Q=()=>{if(!E||A.current)return;let B=new AbortController;A.current=B,b(!0),v(null),jt(E,e.device.platform,e.device.id,B.signal).then(K=>{if(B.signal.aborted)return;R.current&&URL.revokeObjectURL(R.current);let G=URL.createObjectURL(K);if(R.current=G,hr()){P(G);return}let V=document.createElement("a");V.href=G,V.download=`${e.device.name.replace(/[^a-z0-9-]/gi,"-")}-${Date.now()}.png`,document.body.append(V),V.click(),V.remove()}).catch(K=>{B.signal.aborted||v(K instanceof Error?K.message:a("workspace.screenshotFailed"))}).finally(()=>{A.current===B&&(A.current=null,b(!1))})};return t.status!=="ready"?l(X,{name:e.device.name,description:e.device.version,stage:t.status==="failed"?"error":"connecting",message:t.status==="failed"?t.message??a("workspace.needsNewerApp"):a("stream.connecting"),children:l(C,{size:"sm",variant:"outline",onClick:e.onBack,children:a("workspace.allDevices")})}):p("div",{className:"relative flex min-h-0 min-w-0 flex-1",children:[p("div",{className:"relative flex min-h-0 min-w-0 flex-1 flex-col",children:[y||M.error&&!u?l("p",{role:"alert",className:"px-3 py-2 text-xs text-destructive-foreground",children:y??M.error}):null,p("div",{className:"relative min-h-0 flex-1",children:[l(Xe,{transport:t.transport,platform:e.device.platform,deviceId:e.device.id,deviceName:e.device.name,deviceDescription:e.device.version,axOverlay:i,withControls:!0,onHandle:F,onStreaming:ce}),l(Bt,{platform:e.device.platform,handle:o,streaming:d,controls:M,screenshotPending:I,onScreenshot:Q,toolsOpen:u,onTools:()=>n(!u),onClose:e.onClose,onPowerOff:e.onPowerOff,onFloat:e.onFloat})]})]}),u?l($t,{device:e.device,controls:M,transport:t.transport,axOverlay:i,onAxOverlayChange:f,onClose:()=>n(!1)}):null,g?p("div",{className:"absolute inset-0 z-20 flex flex-col items-center justify-center gap-3 bg-background/95 p-4",children:[l("img",{src:g,alt:a("workspace.screenshotAlt"),className:"max-h-[80%] max-w-full object-contain"}),l("p",{className:"text-xs text-muted-foreground",children:a("workspace.screenshotSaveHint")}),p(C,{size:"sm",variant:"outline",onClick:()=>P(null),children:[l(W,{}),a("workspace.closePreview")]})]}):null]})}var Ca=e=>e instanceof Error?e.message:String(e);function Yt(e){let{environmentId:a,threadId:t}=e,{t:o}=D(),{state:r,loaded:d,error:s,unavailable:u}=de(a),n=ue(),[i,f]=h(null),[m,L]=h(null),I=Aa(a,t),b=c=>Oe(a,t,c),y=O(),v=oe(y,"floating"),g=()=>{f(null),n("refresh",a).catch(c=>f(Ca(c)))};k(()=>{!d||u||n("refresh",a).catch(()=>{})},[a,d,n,u]);let P=ae(()=>r.sessions.filter(c=>c.threadId===t),[r.sessions,t]),A=Ir(P,I),R=A?r.devices.find(c=>c.hostId===A.hostId&&c.id===A.deviceId):void 0,E=R&&A?ge(R):null;k(()=>{y.floating?.present({environmentId:a,threadId:t},E)}),k(()=>()=>y.floating?.present({environmentId:a,threadId:t},null),[y,a,t]);let M=ae(()=>Cr(r),[r]),F=r.hostStatuses[ne],ce=F?.status==="ready",Q=F?.status==="installing"||F?.status==="starting",B=ca(),K=r.bootingDevices.filter(c=>c.threadId===t),G=r.hosts.flatMap(c=>c.platforms.filter(S=>!S.available)),V=async c=>{f(null),L(c),aa(a,t,z(c));try{await n("open",a,{threadId:t,hostId:c.hostId,deviceId:c.id,platform:c.platform}),b(z(c))}catch(S){aa(a,t,z(c),!1),f(Ca(S))}finally{L(null)}},pe=c=>{A&&(f(null),n("close",a,{threadId:t,hostId:A.hostId,deviceId:A.deviceId,shutdown:c}).then(()=>b(null)).catch(S=>f(Ca(S))))};return u?l(X,{name:o("panel.title"),stage:"error",message:o("panel.unavailable")}):p("div",{className:"flex size-full min-h-0 flex-col",children:[K.length>0?l("div",{role:"status",className:"border-b px-3 py-2 text-xs text-muted-foreground",children:o("panel.booting",{names:K.map(c=>c.name).join(", ")})}):null,Q&&!R?null:l(At,{detail:F,onRetry:()=>n("refresh",a).catch(()=>{})}),i||s?p("div",{role:"alert",className:"flex items-start gap-2 border-b bg-destructive/5 px-3 py-2 text-xs text-destructive-foreground",children:[l("p",{className:"min-w-0 flex-1 whitespace-pre-wrap break-words",children:i??s}),i?l(C,{size:"icon-xs",variant:"ghost","aria-label":o("panel.dismissError"),onClick:()=>f(null),children:l(W,{className:"size-3"})}):null]}):null,l("div",{className:"relative flex min-h-0 flex-1",children:R&&A?l(Qt,{environmentId:a,device:R,onBack:()=>b(""),onFloat:v?()=>y.floating?.open({environmentId:a,threadId:t},{...ge(R),reason:"user"}):void 0,onPowerOff:()=>pe(!0),onClose:()=>pe(!1)},`${a}\0${z(R)}`):m||Q||!d?l(X,{name:m?.name??o("panel.title"),...m?{description:m.version}:{},stage:"opening",message:m?m.booted?o("panel.opening"):o("panel.starting"):Q&&F?B(F):o("panel.finding")}):l(xr,{environmentId:a,host:r.hosts.find(c=>c.id===ne),grouped:M,hostReady:ce,hostFailed:F?.status==="failed",unavailableReasons:G.map(c=>c.reason??""),showNoAvdHint:ce&&!r.devices.some(c=>c.platform==="android")&&!G.some(c=>c.platform==="android"),pendingKey:m?z(m):null,onOpen:c=>{V(c)},onRefresh:g})})]})}function xr(e){let{t:a}=D(),t=e.grouped.length===0;return l("div",{className:"flex size-full flex-col overflow-y-auto px-4 py-6 text-sm text-muted-foreground",children:p("div",{className:`mx-auto flex w-full max-w-xl flex-col gap-5 ${t?"my-auto items-center text-center":""}`,children:[t?p(re,{children:[l(fe,{className:"size-6 opacity-60"}),l("p",{className:"max-w-sm",children:e.hostFailed?a("panel.hubFailed"):a("panel.empty")})]}):null,e.hostReady?e.grouped.map(o=>p("section",{className:"w-full space-y-2 text-left",children:[p("h3",{className:"flex items-center gap-2 font-medium",children:[l(fe,{className:"size-4 shrink-0"}),o.platform==="ios"?a("panel.platformIos"):a("panel.platformAndroid")]}),l("ul",{className:"divide-y rounded-md border",children:o.devices.map(r=>l("li",{children:p(C,{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(r),children:[p("span",{className:"min-w-0 flex-1",children:[l("span",{className:"block truncate text-foreground",children:r.name}),p("span",{className:"block text-xs",children:[r.version," \xB7"," ",r.booted?a("panel.running"):a("panel.stopped")]})]}),e.pendingKey===z(r)?l(H,{size:"xs"}):l("span",{className:"text-xs",children:r.booted?a("panel.open"):a("panel.start")})]})},z(r)))})]},o.platform)):null,e.unavailableReasons.filter(o=>o.length>0).map(o=>l("p",{className:"max-w-sm text-xs",children:o},o)),e.showNoAvdHint?l("p",{className:"max-w-sm text-xs",children:a("panel.noAvd")}):null,p("div",{className:`flex flex-wrap items-center gap-2 ${t?"self-center":"self-start"}`,children:[l(C,{variant:t?"outline":"ghost",size:"sm",onClick:e.onRefresh,children:a("panel.refresh")}),l(Tt,{environmentId:e.environmentId,host:e.host,busy:!1})]})]})})}function Ir(e,a){if(a!==""){if(a!==null){let t=e.find(o=>z({hostId:o.hostId,id:o.deviceId})===a);if(t)return t}return e.toSorted((t,o)=>o.openedAt.localeCompare(t.openedAt))[0]}}function Cr(e){let a=[];for(let t of["ios","android"]){let o=e.devices.filter(r=>r.platform===t).toSorted((r,d)=>Number(d.booted)-Number(r.booted)||r.name.localeCompare(d.name));o.length>0&&a.push({platform:t,devices:o})}return a}function eo({environmentId:e,threadId:a}){let t=O(),{state:o,loaded:r}=de(e),d=U(null);return k(()=>{if(!r||!oe(t,"floating"))return;let s=`${e}\0${a}`,u=d.current?.key===s?d.current.seen:null,{seen:n,opened:i}=Ta({environmentId:e,threadId:a,previous:u,sessions:o.sessions,devices:o.devices});d.current={key:s,seen:n};for(let f of i)t.floating?.open({environmentId:e,threadId:a},{...ge(f),reason:"agent",panelId:Fe})},[t,e,r,o.devices,o.sessions,a]),null}function Sr(e){return{panels:{device:function(t){return p(Re,{value:e,children:[l("style",{children:Je}),l("div",{className:`${qe} flex h-full min-h-0 flex-1 flex-col`,children:l(Yt,{environmentId:t.environmentId,threadId:t.threadId})})]})}},views:{deviceFloat:function(t){return p(Re,{value:e,children:[l("style",{children:Je}),l("div",{className:`${qe} relative size-full`,children:l(vt,{...t})})]})},deviceSessions:function(t){return l(Re,{value:e,children:l(eo,{environmentId:t.environmentId,threadId:t.threadId})})}}}}export{Sr as default};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ycodium-ai/plugin-devices",
3
- "version": "0.2.2892",
3
+ "version": "0.2.2898",
4
4
  "description": "Lets agents drive iOS Simulators and Android Emulators on this machine.",
5
5
  "keywords": [
6
6
  "android",
@@ -33,8 +33,8 @@
33
33
  "tailwindcss": "^4.0.0",
34
34
  "typescript": "~6.0.3",
35
35
  "vite-plus": "0.2.2",
36
- "ycodium-fetch-ports": "0.0.0",
37
- "@ycodium-ai/plugin-api": "0.2.2892"
36
+ "@ycodium-ai/plugin-api": "0.2.2898",
37
+ "ycodium-fetch-ports": "0.0.0"
38
38
  },
39
39
  "ycodium": {
40
40
  "plugin": "./dist/index.js",