@reason-machines/cli-linux-x64 0.2.566 → 0.2.568

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 (124) hide show
  1. package/bin/reason +1 -1
  2. package/bin/vm-hands/agent-network-dw7yrrwt.js +2 -0
  3. package/bin/vm-hands/api-credentials-ntpwt7rg.js +2 -0
  4. package/bin/vm-hands/api-xvjq0bka.js +2 -0
  5. package/bin/vm-hands/{ask-relay-gk4ks8mg.js → ask-relay-hfa5kzxn.js} +2 -2
  6. package/bin/vm-hands/connect-cli-2ja7aj4w.js +2 -0
  7. package/bin/vm-hands/credentials-nfx99zxr.js +2 -0
  8. package/bin/vm-hands/custom-endpoint-device-5047vdn3.js +2 -0
  9. package/bin/vm-hands/desktop-account-d1g1m6yb.js +2 -0
  10. package/bin/vm-hands/desktop-components-577haqrs.js +2 -0
  11. package/bin/vm-hands/desktop-delegate-4hb0163k.js +2 -0
  12. package/bin/vm-hands/device-workspace-8941tdsy.js +2 -0
  13. package/bin/vm-hands/{fsevents-ezcg3e40.js → fsevents-e57jgcfe.js} +1 -1
  14. package/bin/vm-hands/hands-worker-source-8a4kh44t.js +2 -0
  15. package/bin/vm-hands/{index-w92ys6ra.js → index-y21r07rf.js} +8 -8
  16. package/bin/vm-hands/install-receipt-rckwjqmt.js +2 -0
  17. package/bin/vm-hands/local-automation-fxdb4ynz.js +2 -0
  18. package/bin/vm-hands/local-capabilities-8fgrfpj4.js +2 -0
  19. package/bin/vm-hands/local-desktop-users-hkdfxqtj.js +2 -0
  20. package/bin/vm-hands/local-display-mac-gsh74khc.js +2 -0
  21. package/bin/vm-hands/local-display-session-8b2hx1k6.js +2 -0
  22. package/bin/vm-hands/local-display-video-511qjgmq.js +2 -0
  23. package/bin/vm-hands/local-managed-process-h0fypn67.js +2 -0
  24. package/bin/vm-hands/local-pty-session-w0yhjdvz.js +2 -0
  25. package/bin/vm-hands/managed-runtime-e4cj6r2s.js +2 -0
  26. package/bin/vm-hands/{network-auto-update-qwds22kt.js → network-auto-update-8f2745gk.js} +2 -2
  27. package/bin/vm-hands/network-contract-ht0psj5j.js +2 -0
  28. package/bin/vm-hands/{network-sign-in-kqdg70kc.js → network-sign-in-s00679q9.js} +2 -2
  29. package/bin/vm-hands/package-3rv6jngd.js +2 -0
  30. package/bin/vm-hands/permissions-74rj58e1.js +2 -0
  31. package/bin/vm-hands/reason-hands-protocol-9r62swp0.js +2 -0
  32. package/bin/vm-hands/serve-service-19s965ze.js +2 -0
  33. package/bin/vm-hands/{status-q55nprve.js → status-099b2ec1.js} +5 -5
  34. package/bin/vm-hands/version-avq09c5d.js +2 -0
  35. package/bin/vm-hands/{vm-hands-entry-lite-pg7nnyc6.js → vm-hands-entry-lite-04nx5y4f.js} +2 -2
  36. package/bin/vm-hands/{vm-hands-entry-lite-33at6g06.js → vm-hands-entry-lite-0xfme8gg.js} +2 -2
  37. package/bin/vm-hands/{vm-hands-entry-lite-xfak34av.js → vm-hands-entry-lite-1as6h9ed.js} +4 -4
  38. package/bin/vm-hands/{vm-hands-entry-lite-gxf2r5en.js → vm-hands-entry-lite-1cdtev4n.js} +1 -1
  39. package/bin/vm-hands/{vm-hands-entry-lite-fn2805g8.js → vm-hands-entry-lite-1sy80ca9.js} +2 -2
  40. package/bin/vm-hands/{vm-hands-entry-lite-yg4dk99m.js → vm-hands-entry-lite-2927z566.js} +1 -1
  41. package/bin/vm-hands/{vm-hands-entry-lite-bkhc5mt4.js → vm-hands-entry-lite-2qh3rat2.js} +6 -6
  42. package/bin/vm-hands/{vm-hands-entry-lite-3q2ng4e9.js → vm-hands-entry-lite-3594pdj0.js} +2 -2
  43. package/bin/vm-hands/{vm-hands-entry-lite-2qfmabqn.js → vm-hands-entry-lite-4kb5rq3d.js} +3 -3
  44. package/bin/vm-hands/{vm-hands-entry-lite-s93f3pbv.js → vm-hands-entry-lite-732hnx41.js} +3 -3
  45. package/bin/vm-hands/vm-hands-entry-lite-7aeqbfc8.js +3 -0
  46. package/bin/vm-hands/{vm-hands-entry-lite-5qrft0nw.js → vm-hands-entry-lite-7jmt3q38.js} +3 -3
  47. package/bin/vm-hands/{vm-hands-entry-lite-a8z57vry.js → vm-hands-entry-lite-8s5n4wps.js} +1 -1
  48. package/bin/vm-hands/{vm-hands-entry-lite-y0jtj8zz.js → vm-hands-entry-lite-8twdd0ff.js} +1 -1
  49. package/bin/vm-hands/{vm-hands-entry-lite-50kqbrb7.js → vm-hands-entry-lite-9meg54bs.js} +4 -4
  50. package/bin/vm-hands/{vm-hands-entry-lite-qjrgvdbj.js → vm-hands-entry-lite-bbjsnjct.js} +21 -21
  51. package/bin/vm-hands/{vm-hands-entry-lite-zp7chzcc.js → vm-hands-entry-lite-bc9zq8gx.js} +1 -1
  52. package/bin/vm-hands/{vm-hands-entry-lite-b2w5071h.js → vm-hands-entry-lite-bcz4qpp6.js} +3 -3
  53. package/bin/vm-hands/{vm-hands-entry-lite-ngry8nkq.js → vm-hands-entry-lite-bqs4pkyb.js} +4 -4
  54. package/bin/vm-hands/{vm-hands-entry-lite-zpvr7wc6.js → vm-hands-entry-lite-bt6skt4h.js} +2 -2
  55. package/bin/vm-hands/{vm-hands-entry-lite-q62g6sx0.js → vm-hands-entry-lite-chve4vmh.js} +2 -2
  56. package/bin/vm-hands/{vm-hands-entry-lite-a3gq377t.js → vm-hands-entry-lite-dh87ysh2.js} +2 -2
  57. package/bin/vm-hands/{vm-hands-entry-lite-rz1ep81m.js → vm-hands-entry-lite-dhn0fs5e.js} +2 -2
  58. package/bin/vm-hands/{vm-hands-entry-lite-ttfqxjms.js → vm-hands-entry-lite-ezkb7f6j.js} +9 -9
  59. package/bin/vm-hands/{vm-hands-entry-lite-994kah8n.js → vm-hands-entry-lite-fp3gaa2c.js} +2 -2
  60. package/bin/vm-hands/{vm-hands-entry-lite-chq0qx9f.js → vm-hands-entry-lite-g0bpdyfz.js} +2 -2
  61. package/bin/vm-hands/{vm-hands-entry-lite-9wp7ahwa.js → vm-hands-entry-lite-h5x725z8.js} +4 -4
  62. package/bin/vm-hands/{vm-hands-entry-lite-rxydyqke.js → vm-hands-entry-lite-h7f5a5mb.js} +2 -2
  63. package/bin/vm-hands/{vm-hands-entry-lite-13nx02p7.js → vm-hands-entry-lite-hh0kba1y.js} +4 -4
  64. package/bin/vm-hands/{vm-hands-entry-lite-fccn6s4j.js → vm-hands-entry-lite-hpe54h0b.js} +2 -2
  65. package/bin/vm-hands/{vm-hands-entry-lite-kbnxk71q.js → vm-hands-entry-lite-hpw27zfb.js} +2 -2
  66. package/bin/vm-hands/{vm-hands-entry-lite-x6ybft9v.js → vm-hands-entry-lite-jm9jpj77.js} +5 -5
  67. package/bin/vm-hands/{vm-hands-entry-lite-284z7ct8.js → vm-hands-entry-lite-kankyeep.js} +2 -2
  68. package/bin/vm-hands/{vm-hands-entry-lite-2gxv7v1h.js → vm-hands-entry-lite-ksfd234v.js} +4 -4
  69. package/bin/vm-hands/{vm-hands-entry-lite-ezhfkjqr.js → vm-hands-entry-lite-kzygj0q8.js} +3 -3
  70. package/bin/vm-hands/{vm-hands-entry-lite-fs6jbfp3.js → vm-hands-entry-lite-mktndd2r.js} +19 -19
  71. package/bin/vm-hands/{vm-hands-entry-lite-6adz91f3.js → vm-hands-entry-lite-mzw2vcah.js} +70 -70
  72. package/bin/vm-hands/{vm-hands-entry-lite-72h3t64b.js → vm-hands-entry-lite-n9277v11.js} +2 -2
  73. package/bin/vm-hands/{vm-hands-entry-lite-88dxn9b5.js → vm-hands-entry-lite-peyr9y6z.js} +2 -2
  74. package/bin/vm-hands/{vm-hands-entry-lite-cmmb9k3g.js → vm-hands-entry-lite-r131db1f.js} +2 -2
  75. package/bin/vm-hands/{vm-hands-entry-lite-p02vay5n.js → vm-hands-entry-lite-rd7bm9we.js} +5 -5
  76. package/bin/vm-hands/{vm-hands-entry-lite-72084j3g.js → vm-hands-entry-lite-rpf4t8r4.js} +24 -24
  77. package/bin/vm-hands/{vm-hands-entry-lite-1b21avcs.js → vm-hands-entry-lite-sb1xtqxr.js} +2 -2
  78. package/bin/vm-hands/{vm-hands-entry-lite-b1vanmtv.js → vm-hands-entry-lite-sxnvhzy5.js} +4 -4
  79. package/bin/vm-hands/{vm-hands-entry-lite-cc8hwgxc.js → vm-hands-entry-lite-t2rhwchw.js} +3 -3
  80. package/bin/vm-hands/{vm-hands-entry-lite-sh4mqy93.js → vm-hands-entry-lite-t3k90kdn.js} +3 -3
  81. package/bin/vm-hands/{vm-hands-entry-lite-12ck5swp.js → vm-hands-entry-lite-tzv8s0e7.js} +1 -1
  82. package/bin/vm-hands/{vm-hands-entry-lite-jj7873n8.js → vm-hands-entry-lite-vha0pf8k.js} +2 -2
  83. package/bin/vm-hands/{vm-hands-entry-lite-fxptf351.js → vm-hands-entry-lite-vvhfaxpd.js} +5 -5
  84. package/bin/vm-hands/{vm-hands-entry-lite-3gc2bn5a.js → vm-hands-entry-lite-wtjqjvea.js} +2 -2
  85. package/bin/vm-hands/{vm-hands-entry-lite-30z7wsqr.js → vm-hands-entry-lite-y2vqwds4.js} +3 -3
  86. package/bin/vm-hands/{vm-hands-entry-lite-z65xva21.js → vm-hands-entry-lite-ys4jhf7n.js} +2 -2
  87. package/bin/vm-hands/vm-hands-entry-lite.js +2 -2
  88. package/bin/vm-hands/{vm-hands-executor-r6v6tzqj.js → vm-hands-executor-xd8v5v0e.js} +4 -4
  89. package/bin/vm-hands/{vm-hands-op-runner-wcbc42nw.js → vm-hands-op-runner-nr4ncs4p.js} +1 -1
  90. package/bin/vm-hands/vm-hands-runtime-qvy5s122.js +4 -0
  91. package/bin/vm-hands/worker-preview-readiness-w4zy5g2p.js +2 -0
  92. package/bin/vm-hands/worker-sandbox-2trfs79b.js +2 -0
  93. package/package.json +1 -1
  94. package/bin/vm-hands/agent-network-pak3wvrv.js +0 -2
  95. package/bin/vm-hands/api-credentials-a433ykxs.js +0 -2
  96. package/bin/vm-hands/api-kex52g1d.js +0 -2
  97. package/bin/vm-hands/connect-cli-afdc1h11.js +0 -2
  98. package/bin/vm-hands/credentials-sk4sag42.js +0 -2
  99. package/bin/vm-hands/custom-endpoint-device-3jscber1.js +0 -2
  100. package/bin/vm-hands/desktop-account-xma0330a.js +0 -2
  101. package/bin/vm-hands/desktop-components-y89gpa6e.js +0 -2
  102. package/bin/vm-hands/desktop-delegate-tch2qzx0.js +0 -2
  103. package/bin/vm-hands/device-workspace-4bj43nxq.js +0 -2
  104. package/bin/vm-hands/hands-worker-source-8pe7yv0m.js +0 -2
  105. package/bin/vm-hands/install-receipt-68xxg7hn.js +0 -2
  106. package/bin/vm-hands/local-automation-1s7035zm.js +0 -2
  107. package/bin/vm-hands/local-capabilities-h1hxzrhn.js +0 -2
  108. package/bin/vm-hands/local-desktop-users-jpf0resr.js +0 -2
  109. package/bin/vm-hands/local-display-mac-h5yz0ydd.js +0 -2
  110. package/bin/vm-hands/local-display-session-0vw1x2k6.js +0 -2
  111. package/bin/vm-hands/local-display-video-k4bgptc7.js +0 -2
  112. package/bin/vm-hands/local-managed-process-b79p5wwv.js +0 -2
  113. package/bin/vm-hands/local-pty-session-tqn2xmph.js +0 -2
  114. package/bin/vm-hands/managed-runtime-9jfx2885.js +0 -2
  115. package/bin/vm-hands/network-contract-nkwcf4r9.js +0 -2
  116. package/bin/vm-hands/package-9w0mmxb5.js +0 -2
  117. package/bin/vm-hands/permissions-q9nfdxrh.js +0 -2
  118. package/bin/vm-hands/reason-hands-protocol-pck5har9.js +0 -2
  119. package/bin/vm-hands/serve-service-hcc0zvg8.js +0 -2
  120. package/bin/vm-hands/version-7q2ft41r.js +0 -2
  121. package/bin/vm-hands/vm-hands-entry-lite-997y1m1r.js +0 -3
  122. package/bin/vm-hands/vm-hands-runtime-2t08ywa4.js +0 -4
  123. package/bin/vm-hands/worker-preview-readiness-h96yr4wf.js +0 -2
  124. package/bin/vm-hands/worker-sandbox-6kkhvryn.js +0 -2
@@ -1,5 +1,5 @@
1
1
  // @bun
2
- import{D,Dn,ds,Pr,ps,hs}from"./vm-hands-entry-lite-13nx02p7.js";import{wc,bc,A,Zo}from"./vm-hands-entry-lite-50kqbrb7.js";import{Ue}from"./vm-hands-entry-lite-chq0qx9f.js";import{r}from"./vm-hands-entry-lite-qy9xg6em.js";import{execFile as xt,spawn as _e}from"child_process";import{existsSync as vt}from"fs";import{connect as Et}from"net";function dt(){let e=new Set,t=null,s=(n)=>({holder:t?.viewer??null,you:t===n,same_user:Boolean(t?.viewer&&n.viewer&&t.viewer.user_id===n.viewer.user_id)}),i=()=>{for(let n of e)n.notify(s(n))};return{join(n){return e.add(n),n.notify(s(n)),()=>{if(!e.delete(n))return;if(t!==n)return;t=null,i()}},claim(n){if(t===n||!e.has(n))return;t=n,i()}}}var Ce=dt();import{spawn as pt}from"child_process";import{existsSync as ft}from"fs";import{connect as mt}from"net";import{join as j}from"path";var ze="reason_desktop",N={sampleRate:48000,channels:2,codec:"opus"},ht=5000,yt=107,gt=262144,Vo=(e)=>j(e,"native"),Kt=(e)=>`unix:${e}`;function he(e,t=1000){if(!ft(e))return Promise.resolve(!1);return new Promise((s)=>{let i=mt({path:e}),n=(l)=>{i.destroy(),s(l)};i.setTimeout(t,()=>n(!1)),i.once("error",()=>n(!1)),i.once("close",()=>n(!1)),i.once("connect",()=>n(!0))})}async function _c(e,t){if(!t)return null;let s=Vo(e);if(Buffer.byteLength(s)>yt||/["'\\\s]/.test(s))return null;try{if(await he(s))return s;let i=pt(t,["--daemonize=no","--system=no","--use-pid-file=no","--exit-idle-time=-1","--disallow-exit=yes","--realtime=no","--high-priority=no","--disallow-module-loading=yes","--log-level=warning",`--log-target=file:${j(e,"pulseaudio.log")}`,"-n",`--load=module-native-protocol-unix socket="${s}" auth-anonymous=1 auth-cookie-enabled=0`,`--load=module-null-sink sink_name=${ze} rate=${N.sampleRate} channels=${N.channels} sink_properties=device.description=Reason_desktop`],{detached:!0,stdio:"ignore",env:{HOME:e,PATH:"/usr/bin:/bin",XDG_RUNTIME_DIR:e,PULSE_RUNTIME_PATH:j(e,"runtime"),PULSE_STATE_PATH:j(e,"state")}});Ue(i.pid);let n=!1;i.once("error",()=>{n=!0}),i.once("exit",()=>{n=!0}),i.unref();let l=Date.now()+ht;while(Date.now()<l){if(await he(s))return s;if(n)return await he(s)?s:null;await new Promise((c)=>setTimeout(c,50))}if(!n)i.kill("SIGKILL");return null}catch{return null}}function Oe(){let{sampleRate:e,channels:t}=N;return["-hide_banner","-loglevel","error","-nostdin","-fflags","nobuffer","-f","pulse","-sample_rate",String(e),"-channels",String(t),"-fragment_size",String(e*t*2/50),"-i",`${ze}.monitor`,"-vn","-ac",String(t),"-ar",String(e),"-c:a","libopus","-b:a","64k","-application","lowdelay","-frame_duration","20","-flush_packets","1","-page_duration","20000","-f","ogg","pipe:1"]}var bt=[79,103,103,83],wt=Buffer.from("OpusHead"),_t=Buffer.from("OpusTags"),Be=(e,t)=>e.byteLength>=t.byteLength&&t.every((s,i)=>e[i]===s);class ye extends Error{constructor(e){super(e);this.name="OggProtocolError"}}class ge{buffer=new Uint8Array(0);partial=[];partialBytes=0;push(e){let t=new Uint8Array(this.buffer.byteLength+e.byteLength);t.set(this.buffer),t.set(e,this.buffer.byteLength);let s=[],i=0;while(t.byteLength-i>=27){if(bt.some((b,f)=>t[i+f]!==b)||t[i+4]!==0)throw new ye("invalid_page");let n=(t[i+5]&1)!==0,l=t[i+26];if(t.byteLength-i<27+l)break;let c=t.subarray(i+27,i+27+l),h=c.reduce((b,f)=>b+f,0),g=27+l+h;if(t.byteLength-i<g)break;if(!n&&this.partialBytes>0)this.resetPartial();let m=n&&this.partialBytes===0,p=i+27+l,w=p;for(let b of c){if(p+=b,b===255)continue;if(this.appendPartial(t.subarray(w,p),m),w=p,!m){let f=this.takePartial();if(f.byteLength>0&&!Be(f,wt)&&!Be(f,_t))s.push(f)}m=!1,this.resetPartial()}if(w<p)this.appendPartial(t.subarray(w,p),m);i+=g}return this.buffer=t.slice(i),s}appendPartial(e,t){if(t||e.byteLength===0)return;if(this.partialBytes+=e.byteLength,this.partialBytes>gt)throw new ye("packet_too_large");this.partial.push(e.slice())}takePartial(){if(this.partial.length===1)return this.partial[0];let e=new Uint8Array(this.partialBytes),t=0;for(let s of this.partial)e.set(s,t),t+=s.byteLength;return e}resetPartial(){this.partial=[],this.partialBytes=0}}import{spawn as kt}from"child_process";var Ve=1048576,St=String.raw`
2
+ import{D,On,ps,Pr,hs,fs}from"./vm-hands-entry-lite-hh0kba1y.js";import{wc,bc,A,Qo}from"./vm-hands-entry-lite-9meg54bs.js";import{Ue}from"./vm-hands-entry-lite-g0bpdyfz.js";import{r}from"./vm-hands-entry-lite-qy9xg6em.js";import{execFile as xt,spawn as _e}from"child_process";import{existsSync as vt}from"fs";import{connect as Et}from"net";function dt(){let e=new Set,t=null,s=(n)=>({holder:t?.viewer??null,you:t===n,same_user:Boolean(t?.viewer&&n.viewer&&t.viewer.user_id===n.viewer.user_id)}),i=()=>{for(let n of e)n.notify(s(n))};return{join(n){return e.add(n),n.notify(s(n)),()=>{if(!e.delete(n))return;if(t!==n)return;t=null,i()}},claim(n){if(t===n||!e.has(n))return;t=n,i()}}}var Ce=dt();import{spawn as pt}from"child_process";import{existsSync as ft}from"fs";import{connect as mt}from"net";import{join as j}from"path";var ze="reason_desktop",N={sampleRate:48000,channels:2,codec:"opus"},ht=5000,yt=107,gt=262144,Go=(e)=>j(e,"native"),Kt=(e)=>`unix:${e}`;function he(e,t=1000){if(!ft(e))return Promise.resolve(!1);return new Promise((s)=>{let i=mt({path:e}),n=(l)=>{i.destroy(),s(l)};i.setTimeout(t,()=>n(!1)),i.once("error",()=>n(!1)),i.once("close",()=>n(!1)),i.once("connect",()=>n(!0))})}async function _c(e,t){if(!t)return null;let s=Go(e);if(Buffer.byteLength(s)>yt||/["'\\\s]/.test(s))return null;try{if(await he(s))return s;let i=pt(t,["--daemonize=no","--system=no","--use-pid-file=no","--exit-idle-time=-1","--disallow-exit=yes","--realtime=no","--high-priority=no","--disallow-module-loading=yes","--log-level=warning",`--log-target=file:${j(e,"pulseaudio.log")}`,"-n",`--load=module-native-protocol-unix socket="${s}" auth-anonymous=1 auth-cookie-enabled=0`,`--load=module-null-sink sink_name=${ze} rate=${N.sampleRate} channels=${N.channels} sink_properties=device.description=Reason_desktop`],{detached:!0,stdio:"ignore",env:{HOME:e,PATH:"/usr/bin:/bin",XDG_RUNTIME_DIR:e,PULSE_RUNTIME_PATH:j(e,"runtime"),PULSE_STATE_PATH:j(e,"state")}});Ue(i.pid);let n=!1;i.once("error",()=>{n=!0}),i.once("exit",()=>{n=!0}),i.unref();let l=Date.now()+ht;while(Date.now()<l){if(await he(s))return s;if(n)return await he(s)?s:null;await new Promise((c)=>setTimeout(c,50))}if(!n)i.kill("SIGKILL");return null}catch{return null}}function Oe(){let{sampleRate:e,channels:t}=N;return["-hide_banner","-loglevel","error","-nostdin","-fflags","nobuffer","-f","pulse","-sample_rate",String(e),"-channels",String(t),"-fragment_size",String(e*t*2/50),"-i",`${ze}.monitor`,"-vn","-ac",String(t),"-ar",String(e),"-c:a","libopus","-b:a","64k","-application","lowdelay","-frame_duration","20","-flush_packets","1","-page_duration","20000","-f","ogg","pipe:1"]}var bt=[79,103,103,83],wt=Buffer.from("OpusHead"),_t=Buffer.from("OpusTags"),Be=(e,t)=>e.byteLength>=t.byteLength&&t.every((s,i)=>e[i]===s);class ye extends Error{constructor(e){super(e);this.name="OggProtocolError"}}class ge{buffer=new Uint8Array(0);partial=[];partialBytes=0;push(e){let t=new Uint8Array(this.buffer.byteLength+e.byteLength);t.set(this.buffer),t.set(e,this.buffer.byteLength);let s=[],i=0;while(t.byteLength-i>=27){if(bt.some((b,f)=>t[i+f]!==b)||t[i+4]!==0)throw new ye("invalid_page");let n=(t[i+5]&1)!==0,l=t[i+26];if(t.byteLength-i<27+l)break;let c=t.subarray(i+27,i+27+l),h=c.reduce((b,f)=>b+f,0),g=27+l+h;if(t.byteLength-i<g)break;if(!n&&this.partialBytes>0)this.resetPartial();let m=n&&this.partialBytes===0,p=i+27+l,w=p;for(let b of c){if(p+=b,b===255)continue;if(this.appendPartial(t.subarray(w,p),m),w=p,!m){let f=this.takePartial();if(f.byteLength>0&&!Be(f,wt)&&!Be(f,_t))s.push(f)}m=!1,this.resetPartial()}if(w<p)this.appendPartial(t.subarray(w,p),m);i+=g}return this.buffer=t.slice(i),s}appendPartial(e,t){if(t||e.byteLength===0)return;if(this.partialBytes+=e.byteLength,this.partialBytes>gt)throw new ye("packet_too_large");this.partial.push(e.slice())}takePartial(){if(this.partial.length===1)return this.partial[0];let e=new Uint8Array(this.partialBytes),t=0;for(let s of this.partial)e.set(s,t),t+=s.byteLength;return e}resetPartial(){this.partial=[],this.partialBytes=0}}import{spawn as kt}from"child_process";var Ve=1048576,St=String.raw`
3
3
  import gi, json, os, sys
4
4
  gi.require_version("Gtk", "3.0")
5
5
  from gi.repository import Gtk, Gdk, GLib
@@ -43,6 +43,6 @@ Gtk.main()
43
43
  `;function Ne(e,t){let s=kt("/usr/bin/python3",["-I","-u","-c",St],{env:{DISPLAY:e.display,XAUTHORITY:e.xauthority},stdio:["pipe","pipe","ignore"]}),i=!1,n=!0,l="",c=0,h=[],g=setTimeout(()=>p(),5000),m=()=>{i=!0,clearTimeout(g),h.length=0,s.kill("SIGKILL")},p=()=>{if(i)return;m(),t.end({error:new r("display_unavailable","Reason could not start this Linux desktop's UTF-8 clipboard.")})},w=(b,f=32)=>{if(i)return;if(!n){b();return}if(c+=f,c>Ve)m(),t.end({reason:"input_backpressure"});else h.push({apply:b,bytes:f})};return s.stdout.on("data",(b)=>{if(i)return;l+=b.toString("ascii");for(let f=l.indexOf(`
44
44
  `);f>=0;f=l.indexOf(`
45
45
  `)){let T=l.slice(0,f);l=l.slice(f+1);let x;try{x=JSON.parse(T)}catch{p();return}if(x==="ready"||x==="ack"){clearTimeout(g),n=!1;while(!n&&!i&&h.length){let d=h.shift();c-=d.bytes,d.apply()}}else if(x&&typeof x==="object"&&"text"in x&&typeof x.text==="string"&&Buffer.byteLength(x.text)<=D)t.clipboard(x.text);else{p();return}if(i)return}if(l.length>D*6+32)p()}),s.stdin.on("error",p),s.once("error",p),s.once("exit",p),{apply:w,write(b){if(Buffer.byteLength(b)>D||b.includes("\x00")){p();return}let f=`${JSON.stringify(b)}
46
- `;w(()=>{if(n=!0,g=setTimeout(()=>p(),5000),s.stdin.write(f),s.stdin.writableLength>Ve)m(),t.end({reason:"input_backpressure"})},Buffer.byteLength(f))},close:m}}var z={smooth:{fps:60,crf:23,kbps:8000,x264Preset:"ultrafast",threads:2,scale:1},sharp:{fps:30,crf:19,kbps:1e4,x264Preset:"superfast",scale:1},data_saver:{fps:20,crf:28,kbps:2000,x264Preset:"ultrafast",scale:0.75},balanced:{fps:30,crf:23,kbps:4000,x264Preset:"ultrafast",threads:2,scale:1}},Dt="avc1.4D002A",Ge={width:1920,height:1080},Mt=262144,Pt=0.2,It=250,Lt=1e4,At=1024,be=1e4,Rt=500,Tt=60,Ct=1e4,Bt=1000,Fe=1048576,Ut=-223,zt=-308,Go={kind:"mac_screen",sound:null},Ko={kind:"windows_screen",sound:null},Ot,He=()=>Ot??=A()?.ffmpeg??null,Z=(e,t,s)=>_e(e,t,{env:s,stdio:["ignore","pipe","ignore"],windowsHide:!0}),Vt,ke=()=>Vt??=Zo(A()),$e=(e,t,s)=>{let[i,...n]=[...ke(),e];return Z(i,[...n,...t],s)},Ke=()=>nt?.videotoolbox?"h264_videotoolbox":"libx264",Nt=()=>Math.round(performance.now()*1000),we=new Set,qe=!1;function Je(e){if(we.add(e),e.once("exit",()=>we.delete(e)),qe)return;qe=!0,process.once("exit",()=>{for(let t of we)try{t.kill("SIGKILL")}catch{}})}function Ze(e){try{e.stdout?.destroy()}catch{}if(e.exitCode!==null||e.signalCode!==null)return;try{e.kill("SIGTERM")}catch{return}let t=setTimeout(()=>{if(e.exitCode===null&&e.signalCode===null)try{e.kill("SIGKILL")}catch{}},Rt);e.once("exit",()=>clearTimeout(t))}function Gt(e,t,s){return{args:["-f","x11grab","-draw_mouse","1","-framerate",String(e),"-video_size",`${t.width}x${t.height}`,"-i",s],size:t}}function Ft(e){return{args:["-f","avfoundation","-capture_cursor","1","-pixel_format","nv12","-framerate",String(e),"-i","Capture screen 0:none"],size:null}}function Ht(e,t){return{args:["-f","gdigrab","-draw_mouse","1","-framerate",String(e),"-offset_x","0","-offset_y","0","-video_size",`${t.width}x${t.height}`,"-i","desktop"],size:t}}function $t(e){return{args:["-probesize","32","-analyzeduration","0","-f","image2pipe","-c:v","mjpeg","-framerate",String(e),"-i","pipe:0"],size:null}}var Qe=1700000;function et(e){return Math.min(1,Math.round(Math.sqrt(Qe/(e.width*e.height))*100)/100)}function qt(e,t,s){let i=_e(s.axe,["stream-video","--udid",s.udid,"--format","ffmpeg","--fps","30","--quality","85","--scale",String(Math.min(0.99,et(s.size)))],{stdio:["ignore","pipe","ignore"]}),n=_e(e,t,{env:{},stdio:["pipe","pipe","ignore"]});i.stdout.pipe(n.stdin),n.stdin.on("error",()=>{});let l=()=>{if(i.exitCode===null&&i.signalCode===null)i.kill("SIGTERM")};return n.once("exit",l),n.once("error",l),i.once("exit",()=>{if(n.exitCode===null&&n.signalCode===null)n.kill("SIGTERM")}),i.once("error",()=>{if(n.exitCode===null&&n.signalCode===null)n.kill("SIGTERM")}),n}function We(e){let t=Math.min(1,Ge.width/e.width,Ge.height/e.height);return{width:Math.round(e.width*t),height:Math.round(e.height*t)}}function J(e,t,s,i="libx264"){let n=z[e],l=(w)=>Math.max(2,Math.floor(w/2)*2),c={width:l(s.width*n.scale),height:l(s.height*n.scale)},h=c.width!==t.size?.width||c.height!==t.size.height,g=Math.max(1,Math.round(n.kbps*2/n.fps)),m=["-g",String(n.fps*Tt)],p=i==="h264_videotoolbox"?["-c:v","h264_videotoolbox","-realtime","1","-prio_speed","1","-allow_sw","1","-profile:v","main","-level","4.2","-bf","0","-pix_fmt","nv12",...m,"-b:v",`${n.kbps}k`,"-maxrate",`${n.kbps}k`,"-bufsize",`${g}k`,"-bsf:v","h264_metadata=aud=insert"]:["-c:v","libx264","-preset",n.x264Preset,"-tune","zerolatency","-profile:v","main","-level","4.2","-bf","0","-pix_fmt","yuv420p",...n.threads?["-threads",String(n.threads)]:[],"-x264-params","aud=1:repeat-headers=1",...m,"-crf",String(n.crf),"-maxrate",`${n.kbps}k`,"-bufsize",`${g}k`];return["-hide_banner","-loglevel","error","-nostdin","-fflags","nobuffer",...t.args,"-an",...h?["-vf",`scale=${c.width}:${c.height}:flags=fast_bilinear`]:[],...p,"-flush_packets","1","-f","h264","pipe:1"]}class tt{buffer=new Uint8Array(0);scanned=0;key=!1;micros=0;push(e,t){if(this.buffer.byteLength===0)this.micros=t;let s=new Uint8Array(this.buffer.byteLength+e.byteLength);s.set(this.buffer),s.set(e,this.buffer.byteLength),this.buffer=s;let i=[],n=this.scanned;while(n+3<this.buffer.byteLength){if(this.buffer[n]!==0||this.buffer[n+1]!==0||this.buffer[n+2]!==1){n++;continue}let l=this.buffer[n+3]&31,c=n>0&&this.buffer[n-1]===0?n-1:n;if(l===9&&c>0)i.push({data:this.buffer.slice(0,c),key:this.key,micros:this.micros}),this.buffer=this.buffer.subarray(c),this.key=!1,this.micros=t,n-=c;if(l===5)this.key=!0;n+=3}return this.scanned=n,i}}function Wt(e,t){let s=Et({path:e}),i=Buffer.alloc(0),n="version",l=0,c=!1,h=[],g=0,m=!1,p=(d)=>{if(m)return;m=!0,s.destroy(),t.end(d)},w=()=>p({reason:"display_protocol"}),b=(d)=>{if(m)return;if(!c){if(g+=d.byteLength,g>Fe)p({reason:"input_backpressure"});else h.push(d);return}if(s.write(d),s.writableLength>Fe)p({reason:"input_backpressure"})},f=(d)=>{i=i.subarray(d)},T=()=>{switch(n){case"version":{if(i.byteLength<12)return!1;let d=/^RFB (\d{3})\.(\d{3})\n$/.exec(i.subarray(0,12).toString("latin1"));if(!d||Number(d[1])*1000+Number(d[2])<3007)return w(),!1;return f(12),s.write(`RFB 003.007
47
- `),n="security",!0}case"security":{if(i.byteLength<1)return!1;let d=i[0];if(d===0)return w(),!1;if(i.byteLength<1+d)return!1;if(!i.subarray(1,1+d).includes(1))return w(),!1;return f(1+d),s.write(Buffer.from([1,1])),n="init",!0}case"init":{if(i.byteLength<24)return!1;let d=i.readUInt32BE(20);if(d>65536)return w(),!1;if(i.byteLength<24+d)return!1;let S={width:i.readUInt16BE(0),height:i.readUInt16BE(2)};if(f(24+d),S.width===0||S.height===0)return w(),!1;n="messages";let _=Buffer.alloc(12);_.writeUInt8(2,0),_.writeUInt16BE(2,2),_.writeInt32BE(zt,4),_.writeInt32BE(Ut,8),s.write(_),c=!0;for(let v of h)s.write(v);return h=[],g=0,t.ready(S),!m}case"skip":{let d=Math.min(l,i.byteLength);if(f(d),l-=d,l>0)return!1;return n="messages",!0}case"messages":{if(i.byteLength<1)return!1;switch(i[0]){case 1:{if(i.byteLength<6)return!1;let d=6+i.readUInt16BE(4)*6;if(i.byteLength<d)return!1;return f(d),!0}case 2:return f(1),!0;case 3:{if(i.byteLength<8)return!1;let d=i.readUInt32BE(4);if(d>D/2)return f(8),n="skip",l=d,!0;if(i.byteLength<8+d)return!1;let S=i.subarray(8,8+d).toString("latin1");return f(8+d),t.clipboard(S),!m}default:return w(),!1}}}},x=!1;return s.once("connect",()=>{x=!0}),s.on("data",(d)=>{if(m)return;i=i.byteLength?Buffer.concat([i,d]):d;while(!m&&T());}),s.once("error",()=>{if(!x)p({error:new r("display_unavailable","Reason could not reach this machine's desktop server.")})}),s.once("close",()=>p({reason:"display_closed"})),{pointer(d,S,_){let v=Buffer.alloc(6);v.writeUInt8(5,0),v.writeUInt8(_&255,1),v.writeUInt16BE(d,2),v.writeUInt16BE(S,4),b(v)},key(d,S){let _=Buffer.alloc(8);_.writeUInt8(4,0),_.writeUInt8(d?1:0,1),_.writeUInt32BE(S>>>0,4),b(_)},clipboard(d){if(Array.from(d).some((v)=>v.codePointAt(0)>255)){p({reason:"clipboard_unicode_unsupported"});return}let S=Buffer.from(d,"latin1"),_=Buffer.alloc(8);_.writeUInt8(6,0),_.writeUInt32BE(S.byteLength,4),b(Buffer.concat([_,S]))},close(){m=!0,s.destroy()}}}class Se{run=null;viewers=new Set;get running(){return this.run!==null}start(e,t,s,i){this.viewers.add(e),this.stop();let n;try{n=s()}catch{this.fail();return}Je(n);let l={child:n,splitter:new tt};this.run=l;for(let h of[...this.viewers])h.started(t);n.stdout?.on("data",(h)=>{if(this.run!==l)return;for(let g of l.splitter.push(h,i()))for(let m of[...this.viewers])m.unit(g)});let c=()=>{if(this.run!==l)return;this.run=null,this.fail()};n.once("exit",c),n.once("error",c)}leave(e){if(!this.viewers.delete(e))return;if(this.viewers.size===0)this.stop()}stop(){if(!this.run)return;Ze(this.run.child),this.run=null}fail(){for(let e of[...this.viewers])e.failed()}}var Xe=new WeakMap;function Xt(e){let t=Xe.get(e);if(!t)Xe.set(e,t=new Se);return t}var G=new Map;function Jo(e,t,s={}){let i=s.micros??Nt,n=new ds,l=t.request.preset,c=null,h=null,g=null,m=!1,p=null,w=!1,b=!1,f=null,T=0,x=0,d=!1,S=null,_=null,v=0,Q=null,I=[],F=0,L=[],xe=new Uint32Array(be+1),ee=0,te=null,ne=0,O=0,re=0,ve=0,Ee=0,H=null,ie=0,C={frames:0,bytes:0,since:i()},B=[],V=0,se,oe=!1,it=i(),M={},U=()=>Math.round((i()-it)/1000),De=s.control??Ce,ae=null,le=null,Me=0,ue=!1,Pe={pause(){if(!p?.running)return;p.stop(),ue=!0},adopt(o){let a=o!==null&&(o.width!==h?.width||o.height!==h?.height);if(a)h=o;if(!a&&!ue)return;if(ue=!1,p)Y();else pe()}},st=(o)=>{if(!s.resizeDesktop||!c||"kind"in c||e.done)return;let a=c.display,u=()=>[...G.get(a)??[]];Me++,s.resizeDesktop(c,o,()=>{for(let y of u())y.pause()}).then((y)=>{for(let k of u())k.adopt(y)})},P=(o)=>{let a=Dn(o);return e.send(a),ve+=a.byteLength,a.byteLength},K=(o)=>{if(e.done)return;if(e.open)P({type:"error",code:o});e.end({reason:o})},q=()=>Math.max(Mt,z[l].kbps*1000/8*Pt),W=()=>i()/1000,ot=()=>{while(L.length>1&&L[0].atMs<W()-Lt)L.shift();return L[0]?.rttMs??null},Ie=(o)=>{let a=ot();if(a===null||I.length===0)return!1;let u=(a+It)*o;return W()-I[0].sentMs>u||F>u/1000*z[l].kbps*1000/8},at=(o)=>{if(v===0)return;let a=Math.min(o,v-1);if(Q!==null&&a<=Q)return;Q=a;let u=W();while(I.length&&I[0].seq<=a){let y=I.shift();if(F-=y.bytes,y.seq!==a)continue;let k=Math.max(0,u-y.sentMs);while(L.length&&L.at(-1).rttMs>=k)L.pop();L.push({atMs:u,rttMs:k}),xe[Math.min(be,Math.round(k))]++,ee++,te=Math.min(te??k,k)}},lt=()=>{let o=0;for(let a=0;a<=be;a++)if(o+=xe[a],o*2>=ee)return a;return 0},ut=()=>e.bufferedAmount<=q()/2&&!Ie(0.5),Le=()=>{oe=!0,B=[],V=0,p?.leave(ce),p=null},Ae=(o)=>{if(e.done)return;if(o.key)M.first_key_ms??=U();if(!m){if(!p||B.length===0&&!o.key)return;if(B.push(o),V+=o.data.byteLength,V>q())Le();return}if(d){O++;return}if(e.bufferedAmount>q()||Ie(1)){d=!0,O++,S=setInterval(()=>{if(e.done||!ut())return;if(S)clearInterval(S);S=null,d=!1,Y()},s.drainPollMs??25);return}if(!w){if(!o.key){O++;return}if(P({type:"hello",width:h.width,height:h.height,fps:z[l].fps,preset:l,codec:Dt}),w=!0,M.first_frame_ms??=U(),!b&&c?.sound)P({type:"audioHello",...N}),b=!0}let a=P({type:"frame",key:o.key,seq:v,captureMicros:o.micros,data:o.data});if(I.push({seq:v,sentMs:W(),bytes:a}),F+=a,I.length>At)F-=I.shift().bytes;v++,ne++,H??=o.micros,ie=o.micros,C.frames++,C.bytes+=a},ce={started(o){l=o,w=!1,B=[],V=0},unit:Ae,failed:()=>K("encoder_failed")},de=()=>{let o=(s.ffmpeg??He)();if(!c||!h){K("encoder_failed");return}let[a,u]=[c,h],y="kind"in a&&a.kind==="simulator"?a.stream:null;if(!o&&!y){K("encoder_failed");return}if(p??="kind"in a&&a.kind==="mac_screen"?Xt(s.spawn??$e):new Se,M.encoder_ms===void 0)M.encoder_ms=U(),M.encoder_shared=p.running;p.start(ce,l,()=>{let k=z[l].fps;if(y)return y(k,z[l].kbps,Qe);if("kind"in a&&a.kind==="simulator"){let E=Math.min(0.99,et(a.size)),R={width:a.size.width*E,height:a.size.height*E};return qt(o,J(l,$t(Math.min(k,30)),R,(s.macEncoder??Ke)()),a)}if("kind"in a&&a.kind==="windows_screen")return(s.spawn??Z)(o,J(l,Ht(k,u),We(u)),{SystemRoot:process.env.SystemRoot??"C:\\Windows"});return"kind"in a?(s.spawn??$e)(o,J(l,Ft(k),We(u),(s.macEncoder??Ke)()),{}):(s.spawn??Z)(o,J(l,Gt(k,u,a.display),u),{DISPLAY:a.display,XAUTHORITY:a.xauthority})},i)},X=()=>{if(!f)return;Ze(f.child),f=null},ct=()=>{let o=(s.ffmpeg??He)();if(f||e.done||!b||!c?.sound||!o)return;let a;try{a=(s.spawn??Z)(o,Oe(),{PULSE_SERVER:Kt(c.sound)})}catch{return}Je(a);let u={child:a,reader:new ge};f=u,a.stdout?.on("data",(k)=>{if(f!==u||e.done)return;let E;try{E=u.reader.push(k)}catch{X();return}let R=i();for(let me of E){if(e.bufferedAmount>q()){x++;continue}P({type:"audio",captureMicros:R,data:me}),T++}});let y=()=>{if(f===u)X()};a.once("exit",y),a.once("error",y)},Y=()=>{if(!p||e.done)return;re++,de()},pe=()=>{if(e.done||!h)return;if(!m){if(p||oe)return;de(),se=setTimeout(()=>{if(!m)Le()},Ct);return}if(clearTimeout(se),M.encoder_early===void 0){if(M.encoder_early=p!==null,oe)M.hold_lapsed=!0}if(!p)de();let o=B;B=[],V=0;for(let a of o)Ae(a);_??=setInterval(()=>{let a=i(),u=Math.max(0.001,(a-C.since)/1e6);P({type:"stats",stats:{fps:Math.round(C.frames/u*10)/10,kbps:Math.round(C.bytes*8/1000/u),dropped:O,restarts:re,queued_bytes:e.bufferedAmount}}),C={frames:0,bytes:0,since:a}},Bt)};t.desktop.then((o)=>{if(e.done)return;c=o;let a={ready(u){h=u,M.desktop_ms??=U(),pe()},clipboard(u){if(e.open&&Buffer.byteLength(u)<=D)P({type:"serverClipboard",text:u})},end(u){if("reason"in u&&e.open)P({type:"error",code:u.reason});e.end(u)}};if("kind"in o&&o.kind==="simulator")g=o.input,a.ready(o.points);else if("kind"in o&&o.kind==="windows_screen")g=(s.windowsInput??bc)(a);else if("kind"in o)g=(s.macInput??((u)=>hs(u,ke())))(a);else{let u=G.get(o.display);if(!u)G.set(o.display,u=new Set);u.add(Pe);let y=(s.linuxClipboard??Ne)(o,a),k=Wt(o.rfbSocket,{...a,clipboard:(E)=>{if(!y)a.clipboard(E)}});g=y?{pointer:(E,R,me)=>y.apply(()=>k.pointer(E,R,me)),key:(E,R)=>y.apply(()=>k.key(E,R)),clipboard:(E)=>y.write(E),close(){y.close(),k.close()}}:k}Re()},(o)=>e.end({error:o}));function Re(){if(le||!t.viewerSameNetwork||!m||e.done||!c||!("kind"in c)||c.kind!=="mac_screen")return;le=(s.macWindows??ps)((o)=>{if(e.open)P({type:"windows",bounds:o})})}let Te={viewer:t.viewer??null,notify(o){if(e.open)P({type:"control",control:o})}},fe=(o)=>{if(!g)return;if(!c||!("kind"in c)||c.kind!=="simulator")De.claim(Te);o(g)};return{opened(){M.relay_ms??=U()},received(o){Ee+=o.byteLength;let a;try{a=n.push(o)}catch{K("viewer_protocol");return}for(let u of a){if(e.done)return;switch(u.type){case"ping":P({type:"pong",token:u.token});break;case"pointer":fe((y)=>y.pointer(u.x,u.y,u.buttons));break;case"key":fe((y)=>y.key(u.down,u.keysym));break;case"clientClipboard":fe((y)=>y.clipboard(u.text));break;case"config":if(u.preset!==l)l=u.preset,Y();break;case"keyframeRequest":if(w&&!d)Y();break;case"ack":at(u.seq);break;case"audioEnable":if(u.on)ct();else X();break;case"resize":st({width:u.width,height:u.height});break;default:break}}if(!m&&!e.done){if(m=!0,M.viewer_ms=U(),t.viewer)ae=De.join(Te);pe(),Re()}},close(){if(c&&!("kind"in c)){let o=G.get(c.display);if(o?.delete(Pe),o?.size===0)G.delete(c.display)}if(ae?.(),ae=null,le?.close(),S)clearInterval(S);if(_)clearInterval(_);clearTimeout(se),p?.leave(ce),X(),g?.close()},summary:()=>({output_bytes:ve,input_bytes:Ee,video:{preset:l,frames:ne,dropped:O,restarts:re,avg_fps:H!==null&&ie>H?Math.round((ne-1)/((ie-H)/1e6)*10)/10:0,min_rtt_ms:Math.round(te??0),p50_rtt_ms:ee?lt():0,audio_packets:T,audio_dropped:x,resizes:Me,connect:M}})}}var Ye=null,nt=null,Yt=null,jt=null;function Zt(){let e=A();return e?.features.display?e.ffmpeg:null}function rt(e){return Ye??=new Promise((t)=>{xt(e,["-hide_banner","-encoders"],{env:{},timeout:5000,killSignal:"SIGKILL",maxBuffer:1048576,encoding:"utf8"},(s,i)=>{let n=(l)=>!s&&new RegExp(`^\\s*V\\S*\\s+${l}\\s`,"m").test(i);t(nt={x264:n("libx264"),videotoolbox:n("h264_videotoolbox")})})}),Ye}var je=null;function Xo(){return je??=(async()=>{let e=[A()?.ffmpeg,"/opt/homebrew/bin/ffmpeg","/usr/local/bin/ffmpeg"].find((s)=>Boolean(s&&vt(s)));if(!e)return null;let t=await rt(e);return t.videotoolbox||t.x264?e:null})(),je}function Jt(e=process.platform,t={}){if(e!=="linux"&&e!=="darwin"&&e!=="win32")return Promise.resolve(!1);let s=(t.ffmpeg??Zt)();if(!s)return Promise.resolve(!1);let i=(t.encoders??rt)(s);if(e==="linux")return i.then((l)=>l.x264);if(e==="win32"){let l=t.windowsScreen?t.windowsScreen():jt??=wc();return Promise.all([i,l]).then(([c,h])=>c.x264&&(h?.session??0)>0)}let n=t.macScreen?t.macScreen():Yt??=Pr(ke());return Promise.all([i,n]).then(([l,c])=>(l.x264||l.videotoolbox)&&c?.screen===!0&&c.accessibility)}
48
- export{Vo,Kt,_c,Go,Ko,Jo,Xo,Jt};
46
+ `;w(()=>{if(n=!0,g=setTimeout(()=>p(),5000),s.stdin.write(f),s.stdin.writableLength>Ve)m(),t.end({reason:"input_backpressure"})},Buffer.byteLength(f))},close:m}}var z={smooth:{fps:60,crf:23,kbps:8000,x264Preset:"ultrafast",threads:2,scale:1},sharp:{fps:30,crf:19,kbps:1e4,x264Preset:"superfast",scale:1},data_saver:{fps:20,crf:28,kbps:2000,x264Preset:"ultrafast",scale:0.75},balanced:{fps:30,crf:23,kbps:4000,x264Preset:"ultrafast",threads:2,scale:1}},Dt="avc1.4D002A",Ge={width:1920,height:1080},Mt=262144,Pt=0.2,It=250,Lt=1e4,At=1024,be=1e4,Rt=500,Tt=60,Ct=1e4,Bt=1000,Fe=1048576,Ut=-223,zt=-308,Ko={kind:"mac_screen",sound:null},Jo={kind:"windows_screen",sound:null},Ot,He=()=>Ot??=A()?.ffmpeg??null,Z=(e,t,s)=>_e(e,t,{env:s,stdio:["ignore","pipe","ignore"],windowsHide:!0}),Vt,ke=()=>Vt??=Qo(A()),$e=(e,t,s)=>{let[i,...n]=[...ke(),e];return Z(i,[...n,...t],s)},Ke=()=>nt?.videotoolbox?"h264_videotoolbox":"libx264",Nt=()=>Math.round(performance.now()*1000),we=new Set,qe=!1;function Je(e){if(we.add(e),e.once("exit",()=>we.delete(e)),qe)return;qe=!0,process.once("exit",()=>{for(let t of we)try{t.kill("SIGKILL")}catch{}})}function Ze(e){try{e.stdout?.destroy()}catch{}if(e.exitCode!==null||e.signalCode!==null)return;try{e.kill("SIGTERM")}catch{return}let t=setTimeout(()=>{if(e.exitCode===null&&e.signalCode===null)try{e.kill("SIGKILL")}catch{}},Rt);e.once("exit",()=>clearTimeout(t))}function Gt(e,t,s){return{args:["-f","x11grab","-draw_mouse","1","-framerate",String(e),"-video_size",`${t.width}x${t.height}`,"-i",s],size:t}}function Ft(e){return{args:["-f","avfoundation","-capture_cursor","1","-pixel_format","nv12","-framerate",String(e),"-i","Capture screen 0:none"],size:null}}function Ht(e,t){return{args:["-f","gdigrab","-draw_mouse","1","-framerate",String(e),"-offset_x","0","-offset_y","0","-video_size",`${t.width}x${t.height}`,"-i","desktop"],size:t}}function $t(e){return{args:["-probesize","32","-analyzeduration","0","-f","image2pipe","-c:v","mjpeg","-framerate",String(e),"-i","pipe:0"],size:null}}var Qe=1700000;function et(e){return Math.min(1,Math.round(Math.sqrt(Qe/(e.width*e.height))*100)/100)}function qt(e,t,s){let i=_e(s.axe,["stream-video","--udid",s.udid,"--format","ffmpeg","--fps","30","--quality","85","--scale",String(Math.min(0.99,et(s.size)))],{stdio:["ignore","pipe","ignore"]}),n=_e(e,t,{env:{},stdio:["pipe","pipe","ignore"]});i.stdout.pipe(n.stdin),n.stdin.on("error",()=>{});let l=()=>{if(i.exitCode===null&&i.signalCode===null)i.kill("SIGTERM")};return n.once("exit",l),n.once("error",l),i.once("exit",()=>{if(n.exitCode===null&&n.signalCode===null)n.kill("SIGTERM")}),i.once("error",()=>{if(n.exitCode===null&&n.signalCode===null)n.kill("SIGTERM")}),n}function We(e){let t=Math.min(1,Ge.width/e.width,Ge.height/e.height);return{width:Math.round(e.width*t),height:Math.round(e.height*t)}}function J(e,t,s,i="libx264"){let n=z[e],l=(w)=>Math.max(2,Math.floor(w/2)*2),c={width:l(s.width*n.scale),height:l(s.height*n.scale)},h=c.width!==t.size?.width||c.height!==t.size.height,g=Math.max(1,Math.round(n.kbps*2/n.fps)),m=["-g",String(n.fps*Tt)],p=i==="h264_videotoolbox"?["-c:v","h264_videotoolbox","-realtime","1","-prio_speed","1","-allow_sw","1","-profile:v","main","-level","4.2","-bf","0","-pix_fmt","nv12",...m,"-b:v",`${n.kbps}k`,"-maxrate",`${n.kbps}k`,"-bufsize",`${g}k`,"-bsf:v","h264_metadata=aud=insert"]:["-c:v","libx264","-preset",n.x264Preset,"-tune","zerolatency","-profile:v","main","-level","4.2","-bf","0","-pix_fmt","yuv420p",...n.threads?["-threads",String(n.threads)]:[],"-x264-params","aud=1:repeat-headers=1",...m,"-crf",String(n.crf),"-maxrate",`${n.kbps}k`,"-bufsize",`${g}k`];return["-hide_banner","-loglevel","error","-nostdin","-fflags","nobuffer",...t.args,"-an",...h?["-vf",`scale=${c.width}:${c.height}:flags=fast_bilinear`]:[],...p,"-flush_packets","1","-f","h264","pipe:1"]}class tt{buffer=new Uint8Array(0);scanned=0;key=!1;micros=0;push(e,t){if(this.buffer.byteLength===0)this.micros=t;let s=new Uint8Array(this.buffer.byteLength+e.byteLength);s.set(this.buffer),s.set(e,this.buffer.byteLength),this.buffer=s;let i=[],n=this.scanned;while(n+3<this.buffer.byteLength){if(this.buffer[n]!==0||this.buffer[n+1]!==0||this.buffer[n+2]!==1){n++;continue}let l=this.buffer[n+3]&31,c=n>0&&this.buffer[n-1]===0?n-1:n;if(l===9&&c>0)i.push({data:this.buffer.slice(0,c),key:this.key,micros:this.micros}),this.buffer=this.buffer.subarray(c),this.key=!1,this.micros=t,n-=c;if(l===5)this.key=!0;n+=3}return this.scanned=n,i}}function Wt(e,t){let s=Et({path:e}),i=Buffer.alloc(0),n="version",l=0,c=!1,h=[],g=0,m=!1,p=(d)=>{if(m)return;m=!0,s.destroy(),t.end(d)},w=()=>p({reason:"display_protocol"}),b=(d)=>{if(m)return;if(!c){if(g+=d.byteLength,g>Fe)p({reason:"input_backpressure"});else h.push(d);return}if(s.write(d),s.writableLength>Fe)p({reason:"input_backpressure"})},f=(d)=>{i=i.subarray(d)},T=()=>{switch(n){case"version":{if(i.byteLength<12)return!1;let d=/^RFB (\d{3})\.(\d{3})\n$/.exec(i.subarray(0,12).toString("latin1"));if(!d||Number(d[1])*1000+Number(d[2])<3007)return w(),!1;return f(12),s.write(`RFB 003.007
47
+ `),n="security",!0}case"security":{if(i.byteLength<1)return!1;let d=i[0];if(d===0)return w(),!1;if(i.byteLength<1+d)return!1;if(!i.subarray(1,1+d).includes(1))return w(),!1;return f(1+d),s.write(Buffer.from([1,1])),n="init",!0}case"init":{if(i.byteLength<24)return!1;let d=i.readUInt32BE(20);if(d>65536)return w(),!1;if(i.byteLength<24+d)return!1;let S={width:i.readUInt16BE(0),height:i.readUInt16BE(2)};if(f(24+d),S.width===0||S.height===0)return w(),!1;n="messages";let _=Buffer.alloc(12);_.writeUInt8(2,0),_.writeUInt16BE(2,2),_.writeInt32BE(zt,4),_.writeInt32BE(Ut,8),s.write(_),c=!0;for(let v of h)s.write(v);return h=[],g=0,t.ready(S),!m}case"skip":{let d=Math.min(l,i.byteLength);if(f(d),l-=d,l>0)return!1;return n="messages",!0}case"messages":{if(i.byteLength<1)return!1;switch(i[0]){case 1:{if(i.byteLength<6)return!1;let d=6+i.readUInt16BE(4)*6;if(i.byteLength<d)return!1;return f(d),!0}case 2:return f(1),!0;case 3:{if(i.byteLength<8)return!1;let d=i.readUInt32BE(4);if(d>D/2)return f(8),n="skip",l=d,!0;if(i.byteLength<8+d)return!1;let S=i.subarray(8,8+d).toString("latin1");return f(8+d),t.clipboard(S),!m}default:return w(),!1}}}},x=!1;return s.once("connect",()=>{x=!0}),s.on("data",(d)=>{if(m)return;i=i.byteLength?Buffer.concat([i,d]):d;while(!m&&T());}),s.once("error",()=>{if(!x)p({error:new r("display_unavailable","Reason could not reach this machine's desktop server.")})}),s.once("close",()=>p({reason:"display_closed"})),{pointer(d,S,_){let v=Buffer.alloc(6);v.writeUInt8(5,0),v.writeUInt8(_&255,1),v.writeUInt16BE(d,2),v.writeUInt16BE(S,4),b(v)},key(d,S){let _=Buffer.alloc(8);_.writeUInt8(4,0),_.writeUInt8(d?1:0,1),_.writeUInt32BE(S>>>0,4),b(_)},clipboard(d){if(Array.from(d).some((v)=>v.codePointAt(0)>255)){p({reason:"clipboard_unicode_unsupported"});return}let S=Buffer.from(d,"latin1"),_=Buffer.alloc(8);_.writeUInt8(6,0),_.writeUInt32BE(S.byteLength,4),b(Buffer.concat([_,S]))},close(){m=!0,s.destroy()}}}class Se{run=null;viewers=new Set;get running(){return this.run!==null}start(e,t,s,i){this.viewers.add(e),this.stop();let n;try{n=s()}catch{this.fail();return}Je(n);let l={child:n,splitter:new tt};this.run=l;for(let h of[...this.viewers])h.started(t);n.stdout?.on("data",(h)=>{if(this.run!==l)return;for(let g of l.splitter.push(h,i()))for(let m of[...this.viewers])m.unit(g)});let c=()=>{if(this.run!==l)return;this.run=null,this.fail()};n.once("exit",c),n.once("error",c)}leave(e){if(!this.viewers.delete(e))return;if(this.viewers.size===0)this.stop()}stop(){if(!this.run)return;Ze(this.run.child),this.run=null}fail(){for(let e of[...this.viewers])e.failed()}}var Xe=new WeakMap;function Xt(e){let t=Xe.get(e);if(!t)Xe.set(e,t=new Se);return t}var G=new Map;function Xo(e,t,s={}){let i=s.micros??Nt,n=new ps,l=t.request.preset,c=null,h=null,g=null,m=!1,p=null,w=!1,b=!1,f=null,T=0,x=0,d=!1,S=null,_=null,v=0,Q=null,I=[],F=0,L=[],xe=new Uint32Array(be+1),ee=0,te=null,ne=0,O=0,re=0,ve=0,Ee=0,H=null,ie=0,C={frames:0,bytes:0,since:i()},B=[],V=0,se,oe=!1,it=i(),M={},U=()=>Math.round((i()-it)/1000),De=s.control??Ce,ae=null,le=null,Me=0,ue=!1,Pe={pause(){if(!p?.running)return;p.stop(),ue=!0},adopt(o){let a=o!==null&&(o.width!==h?.width||o.height!==h?.height);if(a)h=o;if(!a&&!ue)return;if(ue=!1,p)Y();else pe()}},st=(o)=>{if(!s.resizeDesktop||!c||"kind"in c||e.done)return;let a=c.display,u=()=>[...G.get(a)??[]];Me++,s.resizeDesktop(c,o,()=>{for(let y of u())y.pause()}).then((y)=>{for(let k of u())k.adopt(y)})},P=(o)=>{let a=On(o);return e.send(a),ve+=a.byteLength,a.byteLength},K=(o)=>{if(e.done)return;if(e.open)P({type:"error",code:o});e.end({reason:o})},q=()=>Math.max(Mt,z[l].kbps*1000/8*Pt),W=()=>i()/1000,ot=()=>{while(L.length>1&&L[0].atMs<W()-Lt)L.shift();return L[0]?.rttMs??null},Ie=(o)=>{let a=ot();if(a===null||I.length===0)return!1;let u=(a+It)*o;return W()-I[0].sentMs>u||F>u/1000*z[l].kbps*1000/8},at=(o)=>{if(v===0)return;let a=Math.min(o,v-1);if(Q!==null&&a<=Q)return;Q=a;let u=W();while(I.length&&I[0].seq<=a){let y=I.shift();if(F-=y.bytes,y.seq!==a)continue;let k=Math.max(0,u-y.sentMs);while(L.length&&L.at(-1).rttMs>=k)L.pop();L.push({atMs:u,rttMs:k}),xe[Math.min(be,Math.round(k))]++,ee++,te=Math.min(te??k,k)}},lt=()=>{let o=0;for(let a=0;a<=be;a++)if(o+=xe[a],o*2>=ee)return a;return 0},ut=()=>e.bufferedAmount<=q()/2&&!Ie(0.5),Le=()=>{oe=!0,B=[],V=0,p?.leave(ce),p=null},Ae=(o)=>{if(e.done)return;if(o.key)M.first_key_ms??=U();if(!m){if(!p||B.length===0&&!o.key)return;if(B.push(o),V+=o.data.byteLength,V>q())Le();return}if(d){O++;return}if(e.bufferedAmount>q()||Ie(1)){d=!0,O++,S=setInterval(()=>{if(e.done||!ut())return;if(S)clearInterval(S);S=null,d=!1,Y()},s.drainPollMs??25);return}if(!w){if(!o.key){O++;return}if(P({type:"hello",width:h.width,height:h.height,fps:z[l].fps,preset:l,codec:Dt}),w=!0,M.first_frame_ms??=U(),!b&&c?.sound)P({type:"audioHello",...N}),b=!0}let a=P({type:"frame",key:o.key,seq:v,captureMicros:o.micros,data:o.data});if(I.push({seq:v,sentMs:W(),bytes:a}),F+=a,I.length>At)F-=I.shift().bytes;v++,ne++,H??=o.micros,ie=o.micros,C.frames++,C.bytes+=a},ce={started(o){l=o,w=!1,B=[],V=0},unit:Ae,failed:()=>K("encoder_failed")},de=()=>{let o=(s.ffmpeg??He)();if(!c||!h){K("encoder_failed");return}let[a,u]=[c,h],y="kind"in a&&a.kind==="simulator"?a.stream:null;if(!o&&!y){K("encoder_failed");return}if(p??="kind"in a&&a.kind==="mac_screen"?Xt(s.spawn??$e):new Se,M.encoder_ms===void 0)M.encoder_ms=U(),M.encoder_shared=p.running;p.start(ce,l,()=>{let k=z[l].fps;if(y)return y(k,z[l].kbps,Qe);if("kind"in a&&a.kind==="simulator"){let E=Math.min(0.99,et(a.size)),R={width:a.size.width*E,height:a.size.height*E};return qt(o,J(l,$t(Math.min(k,30)),R,(s.macEncoder??Ke)()),a)}if("kind"in a&&a.kind==="windows_screen")return(s.spawn??Z)(o,J(l,Ht(k,u),We(u)),{SystemRoot:process.env.SystemRoot??"C:\\Windows"});return"kind"in a?(s.spawn??$e)(o,J(l,Ft(k),We(u),(s.macEncoder??Ke)()),{}):(s.spawn??Z)(o,J(l,Gt(k,u,a.display),u),{DISPLAY:a.display,XAUTHORITY:a.xauthority})},i)},X=()=>{if(!f)return;Ze(f.child),f=null},ct=()=>{let o=(s.ffmpeg??He)();if(f||e.done||!b||!c?.sound||!o)return;let a;try{a=(s.spawn??Z)(o,Oe(),{PULSE_SERVER:Kt(c.sound)})}catch{return}Je(a);let u={child:a,reader:new ge};f=u,a.stdout?.on("data",(k)=>{if(f!==u||e.done)return;let E;try{E=u.reader.push(k)}catch{X();return}let R=i();for(let me of E){if(e.bufferedAmount>q()){x++;continue}P({type:"audio",captureMicros:R,data:me}),T++}});let y=()=>{if(f===u)X()};a.once("exit",y),a.once("error",y)},Y=()=>{if(!p||e.done)return;re++,de()},pe=()=>{if(e.done||!h)return;if(!m){if(p||oe)return;de(),se=setTimeout(()=>{if(!m)Le()},Ct);return}if(clearTimeout(se),M.encoder_early===void 0){if(M.encoder_early=p!==null,oe)M.hold_lapsed=!0}if(!p)de();let o=B;B=[],V=0;for(let a of o)Ae(a);_??=setInterval(()=>{let a=i(),u=Math.max(0.001,(a-C.since)/1e6);P({type:"stats",stats:{fps:Math.round(C.frames/u*10)/10,kbps:Math.round(C.bytes*8/1000/u),dropped:O,restarts:re,queued_bytes:e.bufferedAmount}}),C={frames:0,bytes:0,since:a}},Bt)};t.desktop.then((o)=>{if(e.done)return;c=o;let a={ready(u){h=u,M.desktop_ms??=U(),pe()},clipboard(u){if(e.open&&Buffer.byteLength(u)<=D)P({type:"serverClipboard",text:u})},end(u){if("reason"in u&&e.open)P({type:"error",code:u.reason});e.end(u)}};if("kind"in o&&o.kind==="simulator")g=o.input,a.ready(o.points);else if("kind"in o&&o.kind==="windows_screen")g=(s.windowsInput??bc)(a);else if("kind"in o)g=(s.macInput??((u)=>fs(u,ke())))(a);else{let u=G.get(o.display);if(!u)G.set(o.display,u=new Set);u.add(Pe);let y=(s.linuxClipboard??Ne)(o,a),k=Wt(o.rfbSocket,{...a,clipboard:(E)=>{if(!y)a.clipboard(E)}});g=y?{pointer:(E,R,me)=>y.apply(()=>k.pointer(E,R,me)),key:(E,R)=>y.apply(()=>k.key(E,R)),clipboard:(E)=>y.write(E),close(){y.close(),k.close()}}:k}Re()},(o)=>e.end({error:o}));function Re(){if(le||!t.viewerSameNetwork||!m||e.done||!c||!("kind"in c)||c.kind!=="mac_screen")return;le=(s.macWindows??hs)((o)=>{if(e.open)P({type:"windows",bounds:o})})}let Te={viewer:t.viewer??null,notify(o){if(e.open)P({type:"control",control:o})}},fe=(o)=>{if(!g)return;if(!c||!("kind"in c)||c.kind!=="simulator")De.claim(Te);o(g)};return{opened(){M.relay_ms??=U()},received(o){Ee+=o.byteLength;let a;try{a=n.push(o)}catch{K("viewer_protocol");return}for(let u of a){if(e.done)return;switch(u.type){case"ping":P({type:"pong",token:u.token});break;case"pointer":fe((y)=>y.pointer(u.x,u.y,u.buttons));break;case"key":fe((y)=>y.key(u.down,u.keysym));break;case"clientClipboard":fe((y)=>y.clipboard(u.text));break;case"config":if(u.preset!==l)l=u.preset,Y();break;case"keyframeRequest":if(w&&!d)Y();break;case"ack":at(u.seq);break;case"audioEnable":if(u.on)ct();else X();break;case"resize":st({width:u.width,height:u.height});break;default:break}}if(!m&&!e.done){if(m=!0,M.viewer_ms=U(),t.viewer)ae=De.join(Te);pe(),Re()}},close(){if(c&&!("kind"in c)){let o=G.get(c.display);if(o?.delete(Pe),o?.size===0)G.delete(c.display)}if(ae?.(),ae=null,le?.close(),S)clearInterval(S);if(_)clearInterval(_);clearTimeout(se),p?.leave(ce),X(),g?.close()},summary:()=>({output_bytes:ve,input_bytes:Ee,video:{preset:l,frames:ne,dropped:O,restarts:re,avg_fps:H!==null&&ie>H?Math.round((ne-1)/((ie-H)/1e6)*10)/10:0,min_rtt_ms:Math.round(te??0),p50_rtt_ms:ee?lt():0,audio_packets:T,audio_dropped:x,resizes:Me,connect:M}})}}var Ye=null,nt=null,Yt=null,jt=null;function Zt(){let e=A();return e?.features.display?e.ffmpeg:null}function rt(e){return Ye??=new Promise((t)=>{xt(e,["-hide_banner","-encoders"],{env:{},timeout:5000,killSignal:"SIGKILL",maxBuffer:1048576,encoding:"utf8"},(s,i)=>{let n=(l)=>!s&&new RegExp(`^\\s*V\\S*\\s+${l}\\s`,"m").test(i);t(nt={x264:n("libx264"),videotoolbox:n("h264_videotoolbox")})})}),Ye}var je=null;function Yo(){return je??=(async()=>{let e=[A()?.ffmpeg,"/opt/homebrew/bin/ffmpeg","/usr/local/bin/ffmpeg"].find((s)=>Boolean(s&&vt(s)));if(!e)return null;let t=await rt(e);return t.videotoolbox||t.x264?e:null})(),je}function Jt(e=process.platform,t={}){if(e!=="linux"&&e!=="darwin"&&e!=="win32")return Promise.resolve(!1);let s=(t.ffmpeg??Zt)();if(!s)return Promise.resolve(!1);let i=(t.encoders??rt)(s);if(e==="linux")return i.then((l)=>l.x264);if(e==="win32"){let l=t.windowsScreen?t.windowsScreen():jt??=wc();return Promise.all([i,l]).then(([c,h])=>c.x264&&(h?.session??0)>0)}let n=t.macScreen?t.macScreen():Yt??=Pr(ke());return Promise.all([i,n]).then(([l,c])=>(l.x264||l.videotoolbox)&&c?.screen===!0&&c.accessibility)}
48
+ export{Go,Kt,_c,Ko,Jo,Xo,Yo,Jt};
@@ -1,5 +1,5 @@
1
1
  // @bun
2
- import{Xt,yc,le,Sr,Er,A}from"./vm-hands-entry-lite-50kqbrb7.js";import{ue}from"./vm-hands-entry-lite-cc8hwgxc.js";import{Rr}from"./vm-hands-entry-lite-13nx02p7.js";import{Tr}from"./vm-hands-entry-lite-bkhc5mt4.js";import{Bi}from"./vm-hands-entry-lite-b2w5071h.js";import{Ue,wr,br,Yo}from"./vm-hands-entry-lite-chq0qx9f.js";import{Kt}from"./vm-hands-entry-lite-2gxv7v1h.js";import{qr,ba}from"./vm-hands-entry-lite-sh4mqy93.js";import{Te,jt}from"./vm-hands-entry-lite-x6ybft9v.js";import{de,ze}from"./vm-hands-entry-lite-ttfqxjms.js";import{$r}from"./vm-hands-entry-lite-fxptf351.js";import{s}from"./vm-hands-entry-lite-12ck5swp.js";import{B}from"./vm-hands-entry-lite-pg7nnyc6.js";import{r}from"./vm-hands-entry-lite-qy9xg6em.js";import{spawn as S,spawnSync as De}from"child_process";import{createHash as Le,randomUUID as re}from"crypto";import{closeSync as $e,copyFileSync as J,existsSync as C,fstatSync as Be,mkdirSync as z,openSync as We,readdirSync as N,readFileSync as W,readlinkSync as qe,renameSync as ne,rmSync as Fe,statSync as He,writeFileSync as Ge}from"fs";import{connect as je}from"net";import{tmpdir as P,userInfo as ie}from"os";import{basename as V,delimiter as Xe,dirname as M,join as m}from"path";var q=`import { spawn, execFileSync } from "node:child_process";
2
+ import{Xt,yc,le,Sr,Er,A}from"./vm-hands-entry-lite-9meg54bs.js";import{ue}from"./vm-hands-entry-lite-t2rhwchw.js";import{Rr}from"./vm-hands-entry-lite-hh0kba1y.js";import{Tr}from"./vm-hands-entry-lite-2qh3rat2.js";import{Fi}from"./vm-hands-entry-lite-bcz4qpp6.js";import{Ue,wr,br,Zo}from"./vm-hands-entry-lite-g0bpdyfz.js";import{Kt}from"./vm-hands-entry-lite-ksfd234v.js";import{qr,va}from"./vm-hands-entry-lite-t3k90kdn.js";import{Te,jt}from"./vm-hands-entry-lite-jm9jpj77.js";import{de,ze}from"./vm-hands-entry-lite-ezkb7f6j.js";import{$r}from"./vm-hands-entry-lite-vvhfaxpd.js";import{s}from"./vm-hands-entry-lite-tzv8s0e7.js";import{B}from"./vm-hands-entry-lite-04nx5y4f.js";import{r}from"./vm-hands-entry-lite-qy9xg6em.js";import{spawn as S,spawnSync as De}from"child_process";import{createHash as Le,randomUUID as re}from"crypto";import{closeSync as $e,copyFileSync as J,existsSync as C,fstatSync as Be,mkdirSync as z,openSync as We,readdirSync as N,readFileSync as W,readlinkSync as qe,renameSync as ne,rmSync as Fe,statSync as He,writeFileSync as Ge}from"fs";import{connect as je}from"net";import{tmpdir as P,userInfo as ie}from"os";import{basename as V,delimiter as Xe,dirname as M,join as m}from"path";var q=`import { spawn, execFileSync } from "node:child_process";
3
3
  import { createHash, randomUUID } from "node:crypto";
4
4
  import { readFileSync, readlinkSync, lstatSync, realpathSync, statSync, mkdtempSync, mkdirSync, chmodSync, writeFileSync, readdirSync, rmSync, openSync, readSync, closeSync, renameSync } from "node:fs";
5
5
  import { tmpdir } from "node:os";
@@ -950,5 +950,5 @@ if(process.env.REASON_CLOUD_GATEWAY_EXEC === "1") {
950
950
  process.stdout.write(JSON.stringify(cloudAutomationFailure(error))+"\\n");process.exitCode=1;
951
951
  }
952
952
  }
953
- `;import{execFile as be,spawn as Se}from"child_process";import{closeSync as xe,mkdirSync as ve,openSync as Ie}from"fs";import{dirname as R,join as Re}from"path";import{promisify as ke}from"util";var Oe=ke(be),F="x-apple.systempreferences:com.apple.preference.security",Ae={accessibility:`${F}?Privacy_Accessibility`,screen:`${F}?Privacy_ScreenCapture`},Ee=64,I=new Map;function k(e,o){let t=I.get(e);if(t?.has(o))return!1;if(!t){if(I.size>=Ee)I.delete(I.keys().next().value);t=new Set,I.set(e,t)}return t.add(o),!0}function Ce(){let e=s(),o=ze(de(e),process.env),t=Re(e,".local","share","reason","desktop-install.log");ve(R(t),{recursive:!0,mode:448});let n=Ie(t,"a",384);try{let i=Se(o,["desktop","install"],{detached:!0,stdio:["ignore",n,n],env:{...process.env,REASON_DESKTOP_BACKGROUND:"1"}});i.on("error",()=>{return}),i.unref()}finally{xe(n)}}var O={open:async(e,o)=>{await Oe("/usr/bin/open",e,{signal:o,timeout:1e4,maxBuffer:8192})},request:(e,o)=>Rr(e,o),tile:Bi,installDesktop:Ce},H=!1;async function G(e,o,t){try{await o.open(["-a","Google Chrome",e],t)}catch{t.throwIfAborted(),await o.open([e],t)}}async function X(e,o,t,n){if(await t.open([Ae[o]],n).catch(()=>{}),e[0]&&!n.aborted)t.tile(R(R(R(e[0]))),o)}async function Ne(e,o,t,n,i){for(let a of t){if(!k(e,`grant:${a}`))continue;i.throwIfAborted(),await n.request(o,a).catch(()=>null),await X(o,a,n,i)}}var Pe={name:"open_tab",description:"Open a web page in the user's own Chrome on this Mac. Reason cannot read, screenshot or click in that tab, and no tab_id is returned: browser control needs Reason's Chrome extension. An actual browser call opens its setup page.",inputSchema:{type:"object",properties:{url:{type:"string",description:"An http or https URL."}},required:["url"],additionalProperties:!1}};function j(e){return{code:0,stderr:"",stdout:Buffer.from(JSON.stringify({ok:!0,...e}))}}function Me(e){if(typeof e!=="string")return null;try{let o=new URL(e);return o.protocol==="https:"||o.protocol==="http:"?o.href:null}catch{return null}}async function K(e,o=O){let{call:t,runId:n,signal:i}=e;if(t.kind==="browser"){if(t.operation==="discover")return j({result:{tools:[Pe]}});if(t.operation!=="call")throw new r("automation_browser_setup_required","Browser control is not set up on this Mac yet. Request a browser operation or connect Chrome from Reason to set it up.")}if(e.desktopMissing&&!H){H=!0;try{o.installDesktop()}catch{}}if(t.kind==="computer"){if(e.identity.length>0&&k(n,"grant:probe")){let c=await o.request(e.identity).catch(()=>null),l=c?[...c.accessibility?[]:["accessibility"],...c.screen?[]:["screen"]]:[];for(let f of l)k(n,`grant:${f}`);for(let f of l)await X(e.identity,f,o,i)}throw new r("automation_computer_setup_required","Computer use is not set up on this Mac yet; Reason asked macOS for any missing permission.")}if(k(n,"page:chrome-extension"))await G(yc,o,i).catch(()=>{});let a=t.arguments,u=t.operation==="call"&&t.tool==="open_tab"&&a&&typeof a==="object"&&!Array.isArray(a)?Me(a.url):null;if(!u)throw new r("automation_browser_setup_required","Browser control is not set up on this Mac yet; Reason opened its Chrome Web Store page. open_tab still opens pages.");return await G(u,o,i),j({result:{content:[{type:"text",text:JSON.stringify({opened:u,browser:"the user's Chrome",controllable:!1,note:"Opened for the user to see. Reason cannot read or act in this tab until Reason's Chrome extension is added (its Chrome Web Store page is open)."})}]}})}async function Y(e,o=O){if(e.call.kind!=="computer"||e.call.operation!=="permission_status"||e.output.code!==0||e.identity.length===0)return e.output;let t;try{t=JSON.parse(e.output.stdout.toString("utf8"))}catch{return e.output}if(!t||typeof t!=="object"||Array.isArray(t))return e.output;let n=t.permissions;if(!n||typeof n!=="object")return e.output;let i=n,a=[...i.accessibility==="missing"?["accessibility"]:[],...i.screenRecording==="missing"?["screen"]:[]];if(a.length===0)return e.output;return await Ne(e.runId,e.identity,a,o,e.signal),{...e.output,stdout:Buffer.from(JSON.stringify({...t,requested:a}))}}var L=172032,Ke=18874368,Ye=8192,Je=65536,Ve=55000,Ze=60000,Qe=4,et=40000,tt=/^[0-9a-f-]{36}$/,Z=q,ot=re();function E(e){return Boolean(e)&&typeof e==="object"&&!Array.isArray(e)}function T(){throw new r("invalid_automation_request","Reason automation request is malformed.")}function se(e){let o=Object.keys(e).sort().join(",");if(o==="call"||o==="browser,call"){let t=e.call,n=o==="browser,call";if(!E(t)||t.version!==1||t.kind!=="computer"&&t.kind!=="browser"||n&&(e.browser!==$r||t.kind!=="browser")||JSON.stringify(t).length>Je)T();return{call:t,userChrome:n}}if(o==="offset,output_id"){if(typeof e.output_id!=="string"||!tt.test(e.output_id)||!Number.isSafeInteger(e.offset)||e.offset<0)T();return{output_id:e.output_id,offset:e.offset}}return T()}function hr(e=process.platform,o=A){if(e==="darwin")return!0;return(e==="linux"||e==="win32")&&o()?.features.computer===!0}var rt="__computer-use";function Oo(e=A){return e()?.userChrome??{code:"user_chrome_browser_use_missing"}}function ae(e,o,t,n){return new Promise((i)=>{let a=S(e,o,{env:t,stdio:"ignore",windowsHide:!0}),u=setTimeout(()=>{a.kill("SIGKILL"),i(-1)},n);a.once("error",()=>{clearTimeout(u),i(-1)}),a.once("exit",(c)=>{clearTimeout(u),i(c??-1)})})}function nt(e,o,t,n){return new Promise((i)=>{let a=S(e,o,{env:t,stdio:["ignore","pipe","ignore"],windowsHide:!0}),u="";a.stdout.setEncoding("utf8").on("data",(l)=>{u+=l});let c=setTimeout(()=>{a.kill("SIGKILL"),i(null)},n);a.once("error",()=>{clearTimeout(c),i(null)}),a.once("close",(l)=>{clearTimeout(c),i(l===0?u:null)})})}function it(e){return x(e)?m(P(),"open-browser-use"):"/tmp/open-browser-use"}function x(e){return e.platform==="win32-x64"||e.platform==="win32-arm64"}var st=/^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/,at=33554432;function ct(e,o){let t;try{t=e===null?null:JSON.parse(e)}catch{return null}let n=E(t)&&E(t.result)?t.result.metadata:null;if(!E(n)||n.extensionId!==o)return null;return typeof n.extensionInstanceId==="string"&&st.test(n.extensionInstanceId)?n.extensionInstanceId:null}async function ce(e,o,t){let n=t.storages.map((c)=>{try{return N(c).filter((l)=>l.endsWith(".log")||l.endsWith(".ldb")).map((l)=>m(c,l))}catch{return[]}}),i;try{i=n.some((c)=>c.length>0)?N(t.socketDir).filter((c)=>c.endsWith(".sock")):[]}catch{return[]}let a=[];for(let c of i){let l=m(t.socketDir,c),f=ct(await nt(e,["info","--socket",l,"--timeout","2s"],o,5000),t.extensionId);if(f)a.push({instance:f,socket:l})}let u=[];for(let[c,l]of(a.length>0?n:[]).entries())for(let f of l)try{if(He(f).size>at)continue;let p=W(f),d=a.find((g)=>p.includes(g.instance));if(d){u.push({storage:t.storages[c],...d});break}}catch{}return u}async function lt(e,o,t){return(await ce(e,o,t))[0]?.instance??null}function pe(e,o,t){return lt(e.nativeHost,o,{socketDir:it(e),extensionId:le,storages:[m(t,"browser-profile","Default","Local Extension Settings",le)]})}var Q=/^(Default|Profile ([0-9]+))$/;async function ut(e,o,t=s(),n=Sr){let i=m(t,"Library","Application Support","Google","Chrome"),a=[];try{a=N(i)}catch(p){if(p.code==="EPERM")throw new r("browser_use_chrome_access_denied","macOS blocked Reason from reading Chrome's profiles. Allow Full Disk Access for Reason on this Mac and try again.")}let u=(p)=>Number(Q.exec(p)?.[2]??-1),c=a.filter((p)=>Q.test(p)&&C(m(i,p,"Extensions",Xt))).sort((p,d)=>u(p)-u(d)),l=(p)=>m(i,p,"Local Extension Settings",Xt);return(await ce(e,o,{socketDir:n,extensionId:Xt,storages:c.map(l)})).map(({storage:p,instance:d,socket:g})=>({profile:c.find((h)=>l(h)===p),instance:d,socket:g}))}async function dt(e,o,t=s(),n=Sr){let i=(await ut(e,o,t,n))[0]?.instance;if(!i)throw new r("automation_user_chrome_not_connected","No Chrome profile on this Mac is connected to Reason. Open Chrome with the Reason extension, then try again.");return i}function ee(e){return new Promise((o)=>{let t=je({path:e}),n=(i)=>{t.destroy(),o(i)};t.setTimeout(1000,()=>n(!1)),t.once("error",()=>n(!1)),t.once("connect",()=>n(!0))})}async function me(e,o){let t=Date.now()+o;while(Date.now()<t){if(await e())return!0;await new Promise((n)=>setTimeout(n,200))}return!1}var D=new Map;function U(e,o){let t=D.get(e);if(!t)t=o().finally(()=>D.delete(e)),D.set(e,t);return t}async function pt(e,o){if(await ee(e))return;if(Fe(e,{force:!0}),await ae("dbus-daemon",["--session",`--address=unix:path=${e}`,"--fork"],o,1e4)!==0||!await me(()=>ee(e),5000))throw new r("automation_unavailable","Reason could not start the desktop session bus.");br("dbus-daemon",`--address=unix:path=${e}`)}async function te(e,o,t){let n=e.platform==="darwin-arm64"||x(e)?async()=>await pe(e,o,t)!==null:async()=>await ae(e.nativeHost,["info"],o,5000)===0;if(await n())return;let i=["--profile-directory=Default",`--load-extension=${e.extensionDir}`,"--no-first-run","--no-default-browser-check","--window-size=1280,800","about:blank"],a,u=null,c=0;if(e.platform==="darwin-arm64"){let d=m(t,"browser-profile");Te(d);let g=m(d,"NativeMessagingHosts");z(g,{recursive:!0,mode:448});let h=Er(e.platform).nativeHostManifests[0];J(h,m(g,V(h)));let _=e.browser.slice(0,e.browser.indexOf(".app/")+4),y=i.filter((v)=>v!=="about:blank").concat("--no-startup-window","--use-mock-keychain");a=S("/usr/bin/open",["-g","-n","-a",_,"--args",`--user-data-dir=${d}`,...y],{env:o,stdio:"ignore"})}else if(x(e)){let d=m(t,"browser-profile");Te(d),De(B("icacls"),[M(e.browser),"/grant","*S-1-15-2-1:(OI)(CI)(RX)","*S-1-15-2-2:(OI)(CI)(RX)"],{stdio:"ignore",windowsHide:!0,timeout:60000});let g=i.filter((h)=>h!=="about:blank").concat("--no-startup-window","--keep-alive-for-test");a=S(e.browser,[`--user-data-dir=${d}`,...g],{detached:!0,stdio:"ignore",env:o})}else{let d=m(o.HOME,".config","google-chrome"),g=m(d,"NativeMessagingHosts");z(g,{recursive:!0,mode:448});let h=Er(e.platform).nativeHostManifests[0];J(h,m(g,V(h)));let _=process.geteuid?.()===0?["--no-sandbox"]:[];u=m(t,"browser.log");let y=We(u,"a",384);c=Be(y).size,a=S(e.browser,[`--user-data-dir=${d}`,...i,..._,"--force-renderer-accessibility"],{detached:!0,stdio:["ignore",y,y],env:{...o,ACCESSIBILITY_ENABLED:"1"}}),$e(y),Ue(a.pid)}let l=!1,f=!1;a.once("error",()=>{l=!0}),a.once("exit",(d)=>{l||=d!==0,f=d===0}),a.unref();let p=!1;if(await me(async()=>l||(p=await n()),et),!p){if(u&&W(u).subarray(c).toString("utf8").includes("No usable sandbox"))throw new r("automation_browser_sandbox_unavailable","Chromium found no usable sandbox on this machine. Run the worker as a non-root user with unprivileged user namespaces enabled, or in a container with seccomp unconfined.");if(f)wr("browser");throw new r("automation_browser_unavailable","Reason could not connect the desktop browser.")}}async function No(e){await ge(e,!0)}function Lo(e){return fe(e,he(e))}function fe(e,o){return e.platform==="darwin-arm64"||x(e)?m(o,"browser-profile"):m(o,"home",".config","google-chrome")}function he(e){let o=m(e.root,"automation");if(!C(o)||!mt(e.automation))return e.automation;if(!ft(fe(e,o)))try{ne(o,e.automation)}catch{}return C(o)?o:e.automation}function mt(e){try{return N(e).length===0}catch(o){return o.code==="ENOENT"}}function ft(e){let o;try{o=qe(m(e,"SingletonLock"))}catch{return!1}let t=Number(o.slice(o.lastIndexOf("-")+1));if(!Number.isSafeInteger(t)||t<=0)return!0;try{return process.kill(t,0),!0}catch(n){return n.code==="EPERM"}}async function ge(e,o){qr({root:e.root,automation:e.automation,extensionDir:e.extensionDir});let t=he(e);Te(t);let n=ie().username,i={USER:n,LOGNAME:n,REASON_AUTOMATION_OCU:e.ocu,REASON_AUTOMATION_OBU:e.nativeHost};if(e.platform==="darwin-arm64"||x(e)){let p=x(e)?{...i,...ht(),HOME:s()}:{...i,HOME:s(),PATH:`${M(e.node)}:/usr/bin:/bin:/usr/sbin:/sbin`,REASON_AUTOMATION_OCU:process.execPath,REASON_AUTOMATION_OCU_SUBCOMMAND:rt};if(!o)return p;await U("browser",()=>te(e,p,t));let d=await pe(e,p,t);if(!d)throw new r("automation_browser_unavailable","Reason could not connect the desktop browser.");return{...p,REASON_AUTOMATION_OBU_INSTANCE:d,REASON_AUTOMATION_BACKGROUND_TABS:"1"}}let a=await jt(),u=m(t,"home"),c=m(t,"runtime");Te(u),Te(c);let l=m(t,"bus"),f={...i,HOME:u,PATH:`${M(e.node)}:/usr/bin:/bin`,DISPLAY:a.display,XAUTHORITY:a.xauthority,XDG_RUNTIME_DIR:c,DBUS_SESSION_BUS_ADDRESS:`unix:path=${l}`,...a.sound?{PULSE_SERVER:Kt(a.sound)}:{}};if(await U("bus",()=>pt(l,f)),o)await U("browser",()=>te(e,f,t));return f}function ht(){let e=process.env.SystemRoot??"C:\\Windows",o=Object.fromEntries(["SystemDrive","USERPROFILE","LOCALAPPDATA","APPDATA","ProgramData","ProgramFiles","PATHEXT","ComSpec","USERNAME","USERDOMAIN","COMPUTERNAME","NUMBER_OF_PROCESSORS","PROCESSOR_ARCHITECTURE","PSModuleAnalysisCachePath"].flatMap((n)=>process.env[n]?[[n,process.env[n]]]:[])),t=m(e,"System32");return{...o,SystemRoot:e,windir:e,TEMP:P(),TMP:P(),PATH:[t,m(t,"WindowsPowerShell","v1.0"),e].join(Xe)}}async function gt(e,o,t){let n=ie().username,i={USER:n,LOGNAME:n,HOME:s(),PATH:`${M(e.node)}:/usr/bin:/bin:/usr/sbin:/sbin`,REASON_AUTOMATION_OBU:o,REASON_AUTOMATION_BACKGROUND_TABS:"1"},a=await dt(o,i);return t.throwIfAborted(),{...i,REASON_AUTOMATION_OBU_INSTANCE:a}}function _t(e){if(process.platform!=="win32")return["--input-type=module","--eval",e];let o=m(P(),`reason-automation-${Le("sha256").update(e).digest("hex").slice(0,16)}.mjs`);if(!C(o)||W(o,"utf8")!==e){let t=`${o}.${process.pid}.tmp`;Ge(t,e,{mode:384}),ne(t,o)}return[o]}function _e(e,o,t,n){if(typeof Z!=="string")return Promise.reject(new r("automation_unavailable","This Reason build has no automation runtime."));let i=Z;return new Promise((a,u)=>{let c=S(e,_t(i),{env:{...o,REASON_CLOUD_GATEWAY_EXEC:"1",REASON_AUTOMATION_INLINE_RESULT:"1"},stdio:["pipe","pipe","pipe"],detached:process.platform!=="win32",windowsHide:!0}),l=[],f=0,p="",d=null,g=!1,h=(w)=>{if(d??=w,process.platform==="win32"&&c.pid){S(m(process.env.SystemRoot??"C:\\Windows","System32","taskkill.exe"),["/pid",String(c.pid),"/t","/f"],{stdio:"ignore",windowsHide:!0}).once("error",()=>c.kill("SIGKILL"));return}try{process.kill(-c.pid,"SIGKILL")}catch{c.kill("SIGKILL")}},_=(w)=>{if(g)return;g=!0,clearTimeout(y),n.removeEventListener("abort",v),w()},y=setTimeout(()=>h(new r("automation_timed_out","Reason automation did not finish in time.")),Ve),v=()=>h(new r("cancelled","Reason cancelled the automation call."));if(n.addEventListener("abort",v,{once:!0}),c.stdout.on("data",(w)=>{if(f+=w.byteLength,f>Ke)h(new r("automation_output_too_large","Reason automation output is too large."));else l.push(w)}),c.stderr.setEncoding("utf8").on("data",(w)=>{p=(p+w).slice(-Ye)}),c.stdin.on("error",()=>{}),c.once("error",()=>_(()=>u(d??new r("automation_unavailable","Reason could not start the automation runtime.")))),c.once("close",(w)=>_(()=>{if(d)u(d);else a({code:w??1,stdout:Buffer.concat(l),stderr:p})})),n.aborted)v();c.stdin.end(t)})}var b=new Map;function wt(e,o,t){for(let[i,a]of b)if(a.expiresAt<=t)b.delete(i);while(b.size>=Qe)b.delete(b.keys().next().value);let n=re();return b.set(n,{runId:e,bytes:o,expiresAt:t+Ze}),n}async function we(e,o,t,n={}){let i=await(n.environment??ge)(e,o.kind==="browser");return t.throwIfAborted(),await(n.runtime??_e)(e.node,i,JSON.stringify(o),t)}async function Cl(e,o){let t=se({call:e});if(!("call"in t))T();let n=A();if(!n?.features.computer||t.call.kind==="browser"&&!n.features.browser)throw new r("automation_unavailable","Run `reason desktop install` on this machine to enable computer and browser use.");return await we(n,t.call,o)}function oe(e,o,t){let n=e.stdout.byteLength>L?wt(o,e.stdout,t):void 0;return{code:e.code,stderr:e.stderr,instance_id:ot,output_bytes:e.stdout.byteLength,chunk:e.stdout.subarray(0,L).toString("base64"),...n?{output_id:n}:{}}}async function $o(e,o={}){let t=se(e.payload),n=(o.now??Date.now)();if("output_id"in t){let _=b.get(t.output_id);if(!_||_.runId!==e.runId||_.expiresAt<=n||t.offset>_.bytes.byteLength)throw new r("automation_output_unavailable","Reason automation output expired.");return{chunk:_.bytes.subarray(t.offset,t.offset+L).toString("base64")}}let i=(o.components??A)(),a=(o.platform??process.platform)==="darwin",u=a?(o.macIdentity??Tr)():[],c=o.macSetup??O,l=!i?.features.computer||t.call.kind==="browser"&&!t.userChrome&&!i.features.browser;if(a&&(l||u.length===0||t.call.kind==="browser"&&t.userChrome&&!e.userChrome))return oe(await K({runId:e.runId,call:t.call,identity:u,desktopMissing:l,signal:e.signal},c),e.runId,n);if(!i?.features.computer)throw new r("automation_unavailable","Run `reason desktop install` on this machine to enable computer and browser use.");let f=t.userChrome?e.userChrome:void 0;if(t.userChrome&&!f)throw new r("automation_user_chrome_unavailable","Your own Chrome is not enabled on this computer: run `reason desktop install` on this Mac (and `reason connect --user-chrome on` if you turned it off).");if(t.call.kind==="browser"&&!f&&!i.features.browser)throw new r("automation_browser_not_installed",!i.platform.startsWith("linux")?"Browser use is unavailable on this machine: re-run `reason desktop install`.":"Browser use is unavailable on this machine: install a non-snap Chromium at /usr/bin/chromium, then re-run `reason desktop install`.");e.signal.throwIfAborted();let p=t.call.kind==="browser"&&t.call.operation!=="record_start"&&t.call.operation!=="record_stop",d=await ba(e.runId,e.signal,o.now,p?"call":"run"),g="account"in o?o.account??null:ue(),h;try{if(f){let _=await(o.userChromeEnvironment??gt)(i,f,e.signal);e.signal.throwIfAborted(),h=await(o.runtime??_e)(i.node,_,JSON.stringify(t.call),e.signal)}else if(g)h=await(o.delegate??Yo)(g,t.call,e.signal);else h=await we(i,t.call,e.signal,o)}finally{d()}if(a)h=await Y({runId:e.runId,call:t.call,identity:u,output:h,signal:e.signal},c);return oe(h,e.runId,n)}
954
- export{hr,Oo,No,Lo,Cl,$o};
953
+ `;import{execFile as be,spawn as Se}from"child_process";import{closeSync as xe,mkdirSync as ve,openSync as Ie}from"fs";import{dirname as R,join as Re}from"path";import{promisify as ke}from"util";var Oe=ke(be),F="x-apple.systempreferences:com.apple.preference.security",Ae={accessibility:`${F}?Privacy_Accessibility`,screen:`${F}?Privacy_ScreenCapture`},Ee=64,I=new Map;function k(e,o){let t=I.get(e);if(t?.has(o))return!1;if(!t){if(I.size>=Ee)I.delete(I.keys().next().value);t=new Set,I.set(e,t)}return t.add(o),!0}function Ce(){let e=s(),o=ze(de(e),process.env),t=Re(e,".local","share","reason","desktop-install.log");ve(R(t),{recursive:!0,mode:448});let n=Ie(t,"a",384);try{let i=Se(o,["desktop","install"],{detached:!0,stdio:["ignore",n,n],env:{...process.env,REASON_DESKTOP_BACKGROUND:"1"}});i.on("error",()=>{return}),i.unref()}finally{xe(n)}}var O={open:async(e,o)=>{await Oe("/usr/bin/open",e,{signal:o,timeout:1e4,maxBuffer:8192})},request:(e,o)=>Rr(e,o),tile:Fi,installDesktop:Ce},H=!1;async function G(e,o,t){try{await o.open(["-a","Google Chrome",e],t)}catch{t.throwIfAborted(),await o.open([e],t)}}async function X(e,o,t,n){if(await t.open([Ae[o]],n).catch(()=>{}),e[0]&&!n.aborted)t.tile(R(R(R(e[0]))),o)}async function Ne(e,o,t,n,i){for(let a of t){if(!k(e,`grant:${a}`))continue;i.throwIfAborted(),await n.request(o,a).catch(()=>null),await X(o,a,n,i)}}var Pe={name:"open_tab",description:"Open a web page in the user's own Chrome on this Mac. Reason cannot read, screenshot or click in that tab, and no tab_id is returned: browser control needs Reason's Chrome extension. An actual browser call opens its setup page.",inputSchema:{type:"object",properties:{url:{type:"string",description:"An http or https URL."}},required:["url"],additionalProperties:!1}};function j(e){return{code:0,stderr:"",stdout:Buffer.from(JSON.stringify({ok:!0,...e}))}}function Me(e){if(typeof e!=="string")return null;try{let o=new URL(e);return o.protocol==="https:"||o.protocol==="http:"?o.href:null}catch{return null}}async function K(e,o=O){let{call:t,runId:n,signal:i}=e;if(t.kind==="browser"){if(t.operation==="discover")return j({result:{tools:[Pe]}});if(t.operation!=="call")throw new r("automation_browser_setup_required","Browser control is not set up on this Mac yet. Request a browser operation or connect Chrome from Reason to set it up.")}if(e.desktopMissing&&!H){H=!0;try{o.installDesktop()}catch{}}if(t.kind==="computer"){if(e.identity.length>0&&k(n,"grant:probe")){let c=await o.request(e.identity).catch(()=>null),l=c?[...c.accessibility?[]:["accessibility"],...c.screen?[]:["screen"]]:[];for(let f of l)k(n,`grant:${f}`);for(let f of l)await X(e.identity,f,o,i)}throw new r("automation_computer_setup_required","Computer use is not set up on this Mac yet; Reason asked macOS for any missing permission.")}if(k(n,"page:chrome-extension"))await G(yc,o,i).catch(()=>{});let a=t.arguments,u=t.operation==="call"&&t.tool==="open_tab"&&a&&typeof a==="object"&&!Array.isArray(a)?Me(a.url):null;if(!u)throw new r("automation_browser_setup_required","Browser control is not set up on this Mac yet; Reason opened its Chrome Web Store page. open_tab still opens pages.");return await G(u,o,i),j({result:{content:[{type:"text",text:JSON.stringify({opened:u,browser:"the user's Chrome",controllable:!1,note:"Opened for the user to see. Reason cannot read or act in this tab until Reason's Chrome extension is added (its Chrome Web Store page is open)."})}]}})}async function Y(e,o=O){if(e.call.kind!=="computer"||e.call.operation!=="permission_status"||e.output.code!==0||e.identity.length===0)return e.output;let t;try{t=JSON.parse(e.output.stdout.toString("utf8"))}catch{return e.output}if(!t||typeof t!=="object"||Array.isArray(t))return e.output;let n=t.permissions;if(!n||typeof n!=="object")return e.output;let i=n,a=[...i.accessibility==="missing"?["accessibility"]:[],...i.screenRecording==="missing"?["screen"]:[]];if(a.length===0)return e.output;return await Ne(e.runId,e.identity,a,o,e.signal),{...e.output,stdout:Buffer.from(JSON.stringify({...t,requested:a}))}}var L=172032,Ke=18874368,Ye=8192,Je=65536,Ve=55000,Ze=60000,Qe=4,et=40000,tt=/^[0-9a-f-]{36}$/,Z=q,ot=re();function E(e){return Boolean(e)&&typeof e==="object"&&!Array.isArray(e)}function T(){throw new r("invalid_automation_request","Reason automation request is malformed.")}function se(e){let o=Object.keys(e).sort().join(",");if(o==="call"||o==="browser,call"){let t=e.call,n=o==="browser,call";if(!E(t)||t.version!==1||t.kind!=="computer"&&t.kind!=="browser"||n&&(e.browser!==$r||t.kind!=="browser")||JSON.stringify(t).length>Je)T();return{call:t,userChrome:n}}if(o==="offset,output_id"){if(typeof e.output_id!=="string"||!tt.test(e.output_id)||!Number.isSafeInteger(e.offset)||e.offset<0)T();return{output_id:e.output_id,offset:e.offset}}return T()}function hr(e=process.platform,o=A){if(e==="darwin")return!0;return(e==="linux"||e==="win32")&&o()?.features.computer===!0}var rt="__computer-use";function No(e=A){return e()?.userChrome??{code:"user_chrome_browser_use_missing"}}function ae(e,o,t,n){return new Promise((i)=>{let a=S(e,o,{env:t,stdio:"ignore",windowsHide:!0}),u=setTimeout(()=>{a.kill("SIGKILL"),i(-1)},n);a.once("error",()=>{clearTimeout(u),i(-1)}),a.once("exit",(c)=>{clearTimeout(u),i(c??-1)})})}function nt(e,o,t,n){return new Promise((i)=>{let a=S(e,o,{env:t,stdio:["ignore","pipe","ignore"],windowsHide:!0}),u="";a.stdout.setEncoding("utf8").on("data",(l)=>{u+=l});let c=setTimeout(()=>{a.kill("SIGKILL"),i(null)},n);a.once("error",()=>{clearTimeout(c),i(null)}),a.once("close",(l)=>{clearTimeout(c),i(l===0?u:null)})})}function it(e){return x(e)?m(P(),"open-browser-use"):"/tmp/open-browser-use"}function x(e){return e.platform==="win32-x64"||e.platform==="win32-arm64"}var st=/^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/,at=33554432;function ct(e,o){let t;try{t=e===null?null:JSON.parse(e)}catch{return null}let n=E(t)&&E(t.result)?t.result.metadata:null;if(!E(n)||n.extensionId!==o)return null;return typeof n.extensionInstanceId==="string"&&st.test(n.extensionInstanceId)?n.extensionInstanceId:null}async function ce(e,o,t){let n=t.storages.map((c)=>{try{return N(c).filter((l)=>l.endsWith(".log")||l.endsWith(".ldb")).map((l)=>m(c,l))}catch{return[]}}),i;try{i=n.some((c)=>c.length>0)?N(t.socketDir).filter((c)=>c.endsWith(".sock")):[]}catch{return[]}let a=[];for(let c of i){let l=m(t.socketDir,c),f=ct(await nt(e,["info","--socket",l,"--timeout","2s"],o,5000),t.extensionId);if(f)a.push({instance:f,socket:l})}let u=[];for(let[c,l]of(a.length>0?n:[]).entries())for(let f of l)try{if(He(f).size>at)continue;let p=W(f),d=a.find((g)=>p.includes(g.instance));if(d){u.push({storage:t.storages[c],...d});break}}catch{}return u}async function lt(e,o,t){return(await ce(e,o,t))[0]?.instance??null}function pe(e,o,t){return lt(e.nativeHost,o,{socketDir:it(e),extensionId:le,storages:[m(t,"browser-profile","Default","Local Extension Settings",le)]})}var Q=/^(Default|Profile ([0-9]+))$/;async function ut(e,o,t=s(),n=Sr){let i=m(t,"Library","Application Support","Google","Chrome"),a=[];try{a=N(i)}catch(p){if(p.code==="EPERM")throw new r("browser_use_chrome_access_denied","macOS blocked Reason from reading Chrome's profiles. Allow Full Disk Access for Reason on this Mac and try again.")}let u=(p)=>Number(Q.exec(p)?.[2]??-1),c=a.filter((p)=>Q.test(p)&&C(m(i,p,"Extensions",Xt))).sort((p,d)=>u(p)-u(d)),l=(p)=>m(i,p,"Local Extension Settings",Xt);return(await ce(e,o,{socketDir:n,extensionId:Xt,storages:c.map(l)})).map(({storage:p,instance:d,socket:g})=>({profile:c.find((h)=>l(h)===p),instance:d,socket:g}))}async function dt(e,o,t=s(),n=Sr){let i=(await ut(e,o,t,n))[0]?.instance;if(!i)throw new r("automation_user_chrome_not_connected","No Chrome profile on this Mac is connected to Reason. Open Chrome with the Reason extension, then try again.");return i}function ee(e){return new Promise((o)=>{let t=je({path:e}),n=(i)=>{t.destroy(),o(i)};t.setTimeout(1000,()=>n(!1)),t.once("error",()=>n(!1)),t.once("connect",()=>n(!0))})}async function me(e,o){let t=Date.now()+o;while(Date.now()<t){if(await e())return!0;await new Promise((n)=>setTimeout(n,200))}return!1}var D=new Map;function U(e,o){let t=D.get(e);if(!t)t=o().finally(()=>D.delete(e)),D.set(e,t);return t}async function pt(e,o){if(await ee(e))return;if(Fe(e,{force:!0}),await ae("dbus-daemon",["--session",`--address=unix:path=${e}`,"--fork"],o,1e4)!==0||!await me(()=>ee(e),5000))throw new r("automation_unavailable","Reason could not start the desktop session bus.");br("dbus-daemon",`--address=unix:path=${e}`)}async function te(e,o,t){let n=e.platform==="darwin-arm64"||x(e)?async()=>await pe(e,o,t)!==null:async()=>await ae(e.nativeHost,["info"],o,5000)===0;if(await n())return;let i=["--profile-directory=Default",`--load-extension=${e.extensionDir}`,"--no-first-run","--no-default-browser-check","--window-size=1280,800","about:blank"],a,u=null,c=0;if(e.platform==="darwin-arm64"){let d=m(t,"browser-profile");Te(d);let g=m(d,"NativeMessagingHosts");z(g,{recursive:!0,mode:448});let h=Er(e.platform).nativeHostManifests[0];J(h,m(g,V(h)));let _=e.browser.slice(0,e.browser.indexOf(".app/")+4),y=i.filter((v)=>v!=="about:blank").concat("--no-startup-window","--use-mock-keychain");a=S("/usr/bin/open",["-g","-n","-a",_,"--args",`--user-data-dir=${d}`,...y],{env:o,stdio:"ignore"})}else if(x(e)){let d=m(t,"browser-profile");Te(d),De(B("icacls"),[M(e.browser),"/grant","*S-1-15-2-1:(OI)(CI)(RX)","*S-1-15-2-2:(OI)(CI)(RX)"],{stdio:"ignore",windowsHide:!0,timeout:60000});let g=i.filter((h)=>h!=="about:blank").concat("--no-startup-window","--keep-alive-for-test");a=S(e.browser,[`--user-data-dir=${d}`,...g],{detached:!0,stdio:"ignore",env:o})}else{let d=m(o.HOME,".config","google-chrome"),g=m(d,"NativeMessagingHosts");z(g,{recursive:!0,mode:448});let h=Er(e.platform).nativeHostManifests[0];J(h,m(g,V(h)));let _=process.geteuid?.()===0?["--no-sandbox"]:[];u=m(t,"browser.log");let y=We(u,"a",384);c=Be(y).size,a=S(e.browser,[`--user-data-dir=${d}`,...i,..._,"--force-renderer-accessibility"],{detached:!0,stdio:["ignore",y,y],env:{...o,ACCESSIBILITY_ENABLED:"1"}}),$e(y),Ue(a.pid)}let l=!1,f=!1;a.once("error",()=>{l=!0}),a.once("exit",(d)=>{l||=d!==0,f=d===0}),a.unref();let p=!1;if(await me(async()=>l||(p=await n()),et),!p){if(u&&W(u).subarray(c).toString("utf8").includes("No usable sandbox"))throw new r("automation_browser_sandbox_unavailable","Chromium found no usable sandbox on this machine. Run the worker as a non-root user with unprivileged user namespaces enabled, or in a container with seccomp unconfined.");if(f)wr("browser");throw new r("automation_browser_unavailable","Reason could not connect the desktop browser.")}}async function Lo(e){await ge(e,!0)}function $o(e){return fe(e,he(e))}function fe(e,o){return e.platform==="darwin-arm64"||x(e)?m(o,"browser-profile"):m(o,"home",".config","google-chrome")}function he(e){let o=m(e.root,"automation");if(!C(o)||!mt(e.automation))return e.automation;if(!ft(fe(e,o)))try{ne(o,e.automation)}catch{}return C(o)?o:e.automation}function mt(e){try{return N(e).length===0}catch(o){return o.code==="ENOENT"}}function ft(e){let o;try{o=qe(m(e,"SingletonLock"))}catch{return!1}let t=Number(o.slice(o.lastIndexOf("-")+1));if(!Number.isSafeInteger(t)||t<=0)return!0;try{return process.kill(t,0),!0}catch(n){return n.code==="EPERM"}}async function ge(e,o){qr({root:e.root,automation:e.automation,extensionDir:e.extensionDir});let t=he(e);Te(t);let n=ie().username,i={USER:n,LOGNAME:n,REASON_AUTOMATION_OCU:e.ocu,REASON_AUTOMATION_OBU:e.nativeHost};if(e.platform==="darwin-arm64"||x(e)){let p=x(e)?{...i,...ht(),HOME:s()}:{...i,HOME:s(),PATH:`${M(e.node)}:/usr/bin:/bin:/usr/sbin:/sbin`,REASON_AUTOMATION_OCU:process.execPath,REASON_AUTOMATION_OCU_SUBCOMMAND:rt};if(!o)return p;await U("browser",()=>te(e,p,t));let d=await pe(e,p,t);if(!d)throw new r("automation_browser_unavailable","Reason could not connect the desktop browser.");return{...p,REASON_AUTOMATION_OBU_INSTANCE:d,REASON_AUTOMATION_BACKGROUND_TABS:"1"}}let a=await jt(),u=m(t,"home"),c=m(t,"runtime");Te(u),Te(c);let l=m(t,"bus"),f={...i,HOME:u,PATH:`${M(e.node)}:/usr/bin:/bin`,DISPLAY:a.display,XAUTHORITY:a.xauthority,XDG_RUNTIME_DIR:c,DBUS_SESSION_BUS_ADDRESS:`unix:path=${l}`,...a.sound?{PULSE_SERVER:Kt(a.sound)}:{}};if(await U("bus",()=>pt(l,f)),o)await U("browser",()=>te(e,f,t));return f}function ht(){let e=process.env.SystemRoot??"C:\\Windows",o=Object.fromEntries(["SystemDrive","USERPROFILE","LOCALAPPDATA","APPDATA","ProgramData","ProgramFiles","PATHEXT","ComSpec","USERNAME","USERDOMAIN","COMPUTERNAME","NUMBER_OF_PROCESSORS","PROCESSOR_ARCHITECTURE","PSModuleAnalysisCachePath"].flatMap((n)=>process.env[n]?[[n,process.env[n]]]:[])),t=m(e,"System32");return{...o,SystemRoot:e,windir:e,TEMP:P(),TMP:P(),PATH:[t,m(t,"WindowsPowerShell","v1.0"),e].join(Xe)}}async function gt(e,o,t){let n=ie().username,i={USER:n,LOGNAME:n,HOME:s(),PATH:`${M(e.node)}:/usr/bin:/bin:/usr/sbin:/sbin`,REASON_AUTOMATION_OBU:o,REASON_AUTOMATION_BACKGROUND_TABS:"1"},a=await dt(o,i);return t.throwIfAborted(),{...i,REASON_AUTOMATION_OBU_INSTANCE:a}}function _t(e){if(process.platform!=="win32")return["--input-type=module","--eval",e];let o=m(P(),`reason-automation-${Le("sha256").update(e).digest("hex").slice(0,16)}.mjs`);if(!C(o)||W(o,"utf8")!==e){let t=`${o}.${process.pid}.tmp`;Ge(t,e,{mode:384}),ne(t,o)}return[o]}function _e(e,o,t,n){if(typeof Z!=="string")return Promise.reject(new r("automation_unavailable","This Reason build has no automation runtime."));let i=Z;return new Promise((a,u)=>{let c=S(e,_t(i),{env:{...o,REASON_CLOUD_GATEWAY_EXEC:"1",REASON_AUTOMATION_INLINE_RESULT:"1"},stdio:["pipe","pipe","pipe"],detached:process.platform!=="win32",windowsHide:!0}),l=[],f=0,p="",d=null,g=!1,h=(w)=>{if(d??=w,process.platform==="win32"&&c.pid){S(m(process.env.SystemRoot??"C:\\Windows","System32","taskkill.exe"),["/pid",String(c.pid),"/t","/f"],{stdio:"ignore",windowsHide:!0}).once("error",()=>c.kill("SIGKILL"));return}try{process.kill(-c.pid,"SIGKILL")}catch{c.kill("SIGKILL")}},_=(w)=>{if(g)return;g=!0,clearTimeout(y),n.removeEventListener("abort",v),w()},y=setTimeout(()=>h(new r("automation_timed_out","Reason automation did not finish in time.")),Ve),v=()=>h(new r("cancelled","Reason cancelled the automation call."));if(n.addEventListener("abort",v,{once:!0}),c.stdout.on("data",(w)=>{if(f+=w.byteLength,f>Ke)h(new r("automation_output_too_large","Reason automation output is too large."));else l.push(w)}),c.stderr.setEncoding("utf8").on("data",(w)=>{p=(p+w).slice(-Ye)}),c.stdin.on("error",()=>{}),c.once("error",()=>_(()=>u(d??new r("automation_unavailable","Reason could not start the automation runtime.")))),c.once("close",(w)=>_(()=>{if(d)u(d);else a({code:w??1,stdout:Buffer.concat(l),stderr:p})})),n.aborted)v();c.stdin.end(t)})}var b=new Map;function wt(e,o,t){for(let[i,a]of b)if(a.expiresAt<=t)b.delete(i);while(b.size>=Qe)b.delete(b.keys().next().value);let n=re();return b.set(n,{runId:e,bytes:o,expiresAt:t+Ze}),n}async function we(e,o,t,n={}){let i=await(n.environment??ge)(e,o.kind==="browser");return t.throwIfAborted(),await(n.runtime??_e)(e.node,i,JSON.stringify(o),t)}async function Cl(e,o){let t=se({call:e});if(!("call"in t))T();let n=A();if(!n?.features.computer||t.call.kind==="browser"&&!n.features.browser)throw new r("automation_unavailable","Run `reason desktop install` on this machine to enable computer and browser use.");return await we(n,t.call,o)}function oe(e,o,t){let n=e.stdout.byteLength>L?wt(o,e.stdout,t):void 0;return{code:e.code,stderr:e.stderr,instance_id:ot,output_bytes:e.stdout.byteLength,chunk:e.stdout.subarray(0,L).toString("base64"),...n?{output_id:n}:{}}}async function Mo(e,o={}){let t=se(e.payload),n=(o.now??Date.now)();if("output_id"in t){let _=b.get(t.output_id);if(!_||_.runId!==e.runId||_.expiresAt<=n||t.offset>_.bytes.byteLength)throw new r("automation_output_unavailable","Reason automation output expired.");return{chunk:_.bytes.subarray(t.offset,t.offset+L).toString("base64")}}let i=(o.components??A)(),a=(o.platform??process.platform)==="darwin",u=a?(o.macIdentity??Tr)():[],c=o.macSetup??O,l=!i?.features.computer||t.call.kind==="browser"&&!t.userChrome&&!i.features.browser;if(a&&(l||u.length===0||t.call.kind==="browser"&&t.userChrome&&!e.userChrome))return oe(await K({runId:e.runId,call:t.call,identity:u,desktopMissing:l,signal:e.signal},c),e.runId,n);if(!i?.features.computer)throw new r("automation_unavailable","Run `reason desktop install` on this machine to enable computer and browser use.");let f=t.userChrome?e.userChrome:void 0;if(t.userChrome&&!f)throw new r("automation_user_chrome_unavailable","Your own Chrome is not enabled on this computer: run `reason desktop install` on this Mac (and `reason connect --user-chrome on` if you turned it off).");if(t.call.kind==="browser"&&!f&&!i.features.browser)throw new r("automation_browser_not_installed",!i.platform.startsWith("linux")?"Browser use is unavailable on this machine: re-run `reason desktop install`.":"Browser use is unavailable on this machine: install a non-snap Chromium at /usr/bin/chromium, then re-run `reason desktop install`.");e.signal.throwIfAborted();let p=t.call.kind==="browser"&&t.call.operation!=="record_start"&&t.call.operation!=="record_stop",d=await va(e.runId,e.signal,o.now,p?"call":"run"),g="account"in o?o.account??null:ue(),h;try{if(f){let _=await(o.userChromeEnvironment??gt)(i,f,e.signal);e.signal.throwIfAborted(),h=await(o.runtime??_e)(i.node,_,JSON.stringify(t.call),e.signal)}else if(g)h=await(o.delegate??Zo)(g,t.call,e.signal);else h=await we(i,t.call,e.signal,o)}finally{d()}if(a)h=await Y({runId:e.runId,call:t.call,identity:u,output:h,signal:e.signal},c);return oe(h,e.runId,n)}
954
+ export{hr,No,Lo,$o,Cl,Mo};