@ycodium-ai/plugin-devices 0.2.2800 → 0.2.2808

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