@reason-machines/cli-linux-x64 0.2.504 → 0.2.505
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/THIRD_PARTY_NOTICES.txt +7 -8
- package/bin/reason +2 -2
- package/bin/runtime/srt/sandbox-runtime.mjs +52 -52
- package/bin/vm-hands/api-credentials-23k36ayh.js +2 -0
- package/bin/vm-hands/api-jd29p2kc.js +2 -0
- package/bin/vm-hands/ask-relay-zpp0rkhg.js +4 -0
- package/bin/vm-hands/connect-cli-xyxgcg6z.js +2 -0
- package/bin/vm-hands/credentials-byna24dv.js +2 -0
- package/bin/vm-hands/custom-endpoint-device-p2agcsk0.js +2 -0
- package/bin/vm-hands/desktop-account-z16mmkxg.js +2 -0
- package/bin/vm-hands/device-workspace-y0tk3ne8.js +2 -0
- package/bin/vm-hands/hands-worker-source-0qa16xzj.js +2 -0
- package/bin/vm-hands/index-h6xkz48h.js +12818 -0
- package/bin/vm-hands/install-receipt-nnragt7p.js +2 -0
- package/bin/vm-hands/local-automation-xbpca0f3.js +2 -0
- package/bin/vm-hands/local-capabilities-30m8pzpv.js +2 -0
- package/bin/vm-hands/local-desktop-users-gxfywsan.js +2 -0
- package/bin/vm-hands/local-display-mac-n236gkpe.js +2 -0
- package/bin/vm-hands/local-display-session-ddafdm8k.js +2 -0
- package/bin/vm-hands/local-display-video-gha54xwa.js +2 -0
- package/bin/vm-hands/local-managed-process-0zwxyqxd.js +2 -0
- package/bin/vm-hands/local-pty-session-w1yrmjm0.js +2 -0
- package/bin/vm-hands/managed-runtime-8y90twae.js +2 -0
- package/bin/vm-hands/network-contract-v0fkg94d.js +2 -0
- package/bin/vm-hands/network-sign-in-3dkdkh3a.js +34 -0
- package/bin/vm-hands/package-z2dk6xva.js +2 -0
- package/bin/vm-hands/permissions-ga1ax8wd.js +2 -0
- package/bin/vm-hands/reason-hands-protocol-vzgxd159.js +2 -0
- package/bin/vm-hands/serve-service-42nqanvr.js +2 -0
- package/bin/vm-hands/status-m0g7k47a.js +96 -0
- package/bin/vm-hands/version-ye6800p2.js +2 -0
- package/bin/vm-hands/vm-hands-entry-lite-00y3kn86.js +7 -0
- package/bin/vm-hands/vm-hands-entry-lite-0572m6cr.js +344 -0
- package/bin/vm-hands/vm-hands-entry-lite-07q2xvk1.js +5 -0
- package/bin/vm-hands/vm-hands-entry-lite-0a4cy8gw.js +5 -0
- package/bin/vm-hands/vm-hands-entry-lite-1nj03gbj.js +4 -0
- package/bin/vm-hands/vm-hands-entry-lite-26xb026c.js +3 -0
- package/bin/vm-hands/vm-hands-entry-lite-33h8294z.js +3 -0
- package/bin/vm-hands/vm-hands-entry-lite-3882raa5.js +3 -0
- package/bin/vm-hands/vm-hands-entry-lite-3rg3znp8.js +3 -0
- package/bin/vm-hands/vm-hands-entry-lite-4swa18qz.js +10 -0
- package/bin/vm-hands/vm-hands-entry-lite-56v9haps.js +3 -0
- package/bin/vm-hands/vm-hands-entry-lite-6x5pj2y0.js +4 -0
- package/bin/vm-hands/{vm-hands-entry-lite-fcvf8md1.js → vm-hands-entry-lite-8p8hz0j1.js} +2 -2
- package/bin/vm-hands/vm-hands-entry-lite-8twscwtw.js +112 -0
- package/bin/vm-hands/vm-hands-entry-lite-8xe0wzp9.js +3 -0
- package/bin/vm-hands/vm-hands-entry-lite-ah2ep922.js +4 -0
- package/bin/vm-hands/vm-hands-entry-lite-b0p8f295.js +52 -0
- package/bin/vm-hands/{vm-hands-entry-lite-77j164ps.js → vm-hands-entry-lite-b7wy89y0.js} +54 -54
- package/bin/vm-hands/vm-hands-entry-lite-c5gt0086.js +3 -0
- package/bin/vm-hands/{vm-hands-entry-lite-wrvz9jxy.js → vm-hands-entry-lite-c8bf82tx.js} +2 -2
- package/bin/vm-hands/vm-hands-entry-lite-dgmap6z4.js +5 -0
- package/bin/vm-hands/vm-hands-entry-lite-dhqmbqsh.js +9 -0
- package/bin/vm-hands/vm-hands-entry-lite-e1xjfj57.js +3 -0
- package/bin/vm-hands/vm-hands-entry-lite-e4hwb89r.js +66 -0
- package/bin/vm-hands/vm-hands-entry-lite-g6r5xrk0.js +105 -0
- package/bin/vm-hands/vm-hands-entry-lite-ghhpgt3v.js +3 -0
- package/bin/vm-hands/vm-hands-entry-lite-h5smacqn.js +3 -0
- package/bin/vm-hands/vm-hands-entry-lite-jd31as70.js +3 -0
- package/bin/vm-hands/vm-hands-entry-lite-k9n1pk42.js +4 -0
- package/bin/vm-hands/vm-hands-entry-lite-kqbats5n.js +3 -0
- package/bin/vm-hands/vm-hands-entry-lite-p9fwt68c.js +42 -0
- package/bin/vm-hands/vm-hands-entry-lite-pkk555dx.js +3 -0
- package/bin/vm-hands/vm-hands-entry-lite-pmw3ycgc.js +5 -0
- package/bin/vm-hands/vm-hands-entry-lite-q9g11dbj.js +3 -0
- package/bin/vm-hands/vm-hands-entry-lite-r374pchj.js +9 -0
- package/bin/vm-hands/vm-hands-entry-lite-r665z809.js +4 -0
- package/bin/vm-hands/vm-hands-entry-lite-rck5h8fr.js +3 -0
- package/bin/vm-hands/vm-hands-entry-lite-rj8yq6gp.js +3 -0
- package/bin/vm-hands/{vm-hands-entry-lite-c11fg8gx.js → vm-hands-entry-lite-s8ty42st.js} +9 -5
- package/bin/vm-hands/vm-hands-entry-lite-s8zfzv0k.js +6 -0
- package/bin/vm-hands/vm-hands-entry-lite-tafgty5k.js +4 -0
- package/bin/vm-hands/vm-hands-entry-lite-tbdcmq09.js +3 -0
- package/bin/vm-hands/vm-hands-entry-lite-td309c1y.js +5 -0
- package/bin/vm-hands/vm-hands-entry-lite-v0bp1v66.js +128 -0
- package/bin/vm-hands/vm-hands-entry-lite-v0k8b768.js +452 -0
- package/bin/vm-hands/vm-hands-entry-lite-v4r1fggm.js +3 -0
- package/bin/vm-hands/vm-hands-entry-lite-vqr3zrqr.js +539 -0
- package/bin/vm-hands/vm-hands-entry-lite-wbfmc0xn.js +3 -0
- package/bin/vm-hands/vm-hands-entry-lite-x3pbyg92.js +3 -0
- package/bin/vm-hands/{vm-hands-entry-lite-rfz60hb3.js → vm-hands-entry-lite-xd2dn3n8.js} +2 -2
- package/bin/vm-hands/vm-hands-entry-lite-yqn8h1p0.js +3 -0
- package/bin/vm-hands/vm-hands-entry-lite-zj3hb5jk.js +127 -0
- package/bin/vm-hands/vm-hands-entry-lite-zz8tr0bm.js +12 -0
- package/bin/vm-hands/vm-hands-entry-lite.js +1 -3
- package/bin/vm-hands/vm-hands-executor-6tncheya.js +12 -0
- package/bin/vm-hands/vm-hands-op-runner-s1ghsym7.js +2 -0
- package/bin/vm-hands/vm-hands-runtime-k6egwk2t.js +4 -0
- package/bin/vm-hands/worker-preview-readiness-wh0yg1dz.js +2 -0
- package/bin/vm-hands/worker-sandbox-s054x4zw.js +2 -0
- package/package.json +1 -1
- package/bin/vm-hands/api-credentials-gnefpvc1.js +0 -2
- package/bin/vm-hands/api-mjzanhf1.js +0 -2
- package/bin/vm-hands/connect-cli-dy7mdehx.js +0 -2
- package/bin/vm-hands/credentials-drj5ktpt.js +0 -2
- package/bin/vm-hands/custom-endpoint-device-j1x988g0.js +0 -2
- package/bin/vm-hands/desktop-account-4525j7h3.js +0 -2
- package/bin/vm-hands/device-workspace-pt07525s.js +0 -2
- package/bin/vm-hands/fsevents-8zxmv89w.js +0 -2
- package/bin/vm-hands/hands-worker-source-atg5dc7b.js +0 -2
- package/bin/vm-hands/index-ttmxy9nd.js +0 -12818
- package/bin/vm-hands/install-receipt-6v65enmf.js +0 -2
- package/bin/vm-hands/local-automation-wfa3dpbs.js +0 -2
- package/bin/vm-hands/local-capabilities-3v7x217d.js +0 -2
- package/bin/vm-hands/local-desktop-users-ar6xpadb.js +0 -2
- package/bin/vm-hands/local-display-mac-fnp3317m.js +0 -2
- package/bin/vm-hands/local-display-session-2064d8k8.js +0 -2
- package/bin/vm-hands/local-display-video-1hxqy3xj.js +0 -2
- package/bin/vm-hands/local-managed-process-trmeeyh2.js +0 -2
- package/bin/vm-hands/local-pty-session-5yh2a63r.js +0 -2
- package/bin/vm-hands/managed-runtime-hhk63f61.js +0 -2
- package/bin/vm-hands/network-contract-rzw769gw.js +0 -2
- package/bin/vm-hands/package-r7sgmw4t.js +0 -2
- package/bin/vm-hands/permissions-xwyhbnjc.js +0 -2
- package/bin/vm-hands/reason-hands-protocol-8fgk2s53.js +0 -2
- package/bin/vm-hands/serve-service-aye42qtb.js +0 -2
- package/bin/vm-hands/status-qtm9gb55.js +0 -10
- package/bin/vm-hands/version-gnb213c3.js +0 -2
- package/bin/vm-hands/vm-hands-entry-lite-0y9n06b6.js +0 -14
- package/bin/vm-hands/vm-hands-entry-lite-38g65s5x.js +0 -3
- package/bin/vm-hands/vm-hands-entry-lite-3sjkzhf6.js +0 -3
- package/bin/vm-hands/vm-hands-entry-lite-545m8hm0.js +0 -3
- package/bin/vm-hands/vm-hands-entry-lite-57v7y0km.js +0 -105
- package/bin/vm-hands/vm-hands-entry-lite-5gevvgec.js +0 -2
- package/bin/vm-hands/vm-hands-entry-lite-5tbntcyq.js +0 -42
- package/bin/vm-hands/vm-hands-entry-lite-61y11rrd.js +0 -3
- package/bin/vm-hands/vm-hands-entry-lite-6x1an7es.js +0 -7
- package/bin/vm-hands/vm-hands-entry-lite-7777m86y.js +0 -3
- package/bin/vm-hands/vm-hands-entry-lite-87vmbt38.js +0 -3
- package/bin/vm-hands/vm-hands-entry-lite-8e5djf5y.js +0 -5
- package/bin/vm-hands/vm-hands-entry-lite-8wcyveeh.js +0 -2
- package/bin/vm-hands/vm-hands-entry-lite-e1z3y9rs.js +0 -4
- package/bin/vm-hands/vm-hands-entry-lite-eabever7.js +0 -112
- package/bin/vm-hands/vm-hands-entry-lite-ewr54tpc.js +0 -3
- package/bin/vm-hands/vm-hands-entry-lite-ex69qn9q.js +0 -2
- package/bin/vm-hands/vm-hands-entry-lite-f62fvme8.js +0 -5
- package/bin/vm-hands/vm-hands-entry-lite-f69t48dj.js +0 -4
- package/bin/vm-hands/vm-hands-entry-lite-gvjffc5t.js +0 -65
- package/bin/vm-hands/vm-hands-entry-lite-hmaazqdr.js +0 -2
- package/bin/vm-hands/vm-hands-entry-lite-kq7hrjch.js +0 -128
- package/bin/vm-hands/vm-hands-entry-lite-mcjca0ez.js +0 -3
- package/bin/vm-hands/vm-hands-entry-lite-mk5ayds8.js +0 -3
- package/bin/vm-hands/vm-hands-entry-lite-mqzr55mw.js +0 -126
- package/bin/vm-hands/vm-hands-entry-lite-ncbzy69k.js +0 -4
- package/bin/vm-hands/vm-hands-entry-lite-np07qyeq.js +0 -3
- package/bin/vm-hands/vm-hands-entry-lite-nqdstx24.js +0 -3
- package/bin/vm-hands/vm-hands-entry-lite-psywfz8m.js +0 -9
- package/bin/vm-hands/vm-hands-entry-lite-pydgnx8a.js +0 -539
- package/bin/vm-hands/vm-hands-entry-lite-qpdpzg8g.js +0 -3
- package/bin/vm-hands/vm-hands-entry-lite-qt71vz32.js +0 -52
- package/bin/vm-hands/vm-hands-entry-lite-qxsqx6hz.js +0 -2
- package/bin/vm-hands/vm-hands-entry-lite-qy9xg6em.js +0 -3
- package/bin/vm-hands/vm-hands-entry-lite-rmabryke.js +0 -452
- package/bin/vm-hands/vm-hands-entry-lite-rzr2ncf5.js +0 -5
- package/bin/vm-hands/vm-hands-entry-lite-sss0m3yn.js +0 -3
- package/bin/vm-hands/vm-hands-entry-lite-swrymqj9.js +0 -3
- package/bin/vm-hands/vm-hands-entry-lite-tebh7dcm.js +0 -6
- package/bin/vm-hands/vm-hands-entry-lite-txd50spx.js +0 -3
- package/bin/vm-hands/vm-hands-entry-lite-wg0cykk2.js +0 -9
- package/bin/vm-hands/vm-hands-entry-lite-x39tmj7j.js +0 -5
- package/bin/vm-hands/vm-hands-entry-lite-xdjrdkh2.js +0 -4
- package/bin/vm-hands/vm-hands-entry-lite-yretc2th.js +0 -3
- package/bin/vm-hands/vm-hands-executor-8c542krk.js +0 -12
- package/bin/vm-hands/vm-hands-op-runner-88e10ptt.js +0 -2
- package/bin/vm-hands/vm-hands-runtime-njh3th64.js +0 -4
- package/bin/vm-hands/worker-preview-readiness-7xtgxsar.js +0 -2
- package/bin/vm-hands/worker-sandbox-s9pyac8p.js +0 -2
|
@@ -1,128 +0,0 @@
|
|
|
1
|
-
// @bun
|
|
2
|
-
import{$n,Eo,zt}from"./vm-hands-entry-lite-eabever7.js";import{On,Ve,po,In,Dn,Nn,Pr,x}from"./vm-hands-entry-lite-mqzr55mw.js";import{xt}from"./vm-hands-entry-lite-xdjrdkh2.js";import{Dr}from"./vm-hands-entry-lite-qpdpzg8g.js";import{j}from"./vm-hands-entry-lite-rzr2ncf5.js";import{a}from"./vm-hands-entry-lite-swrymqj9.js";import{r}from"./vm-hands-entry-lite-qy9xg6em.js";import{execFile as z,spawn as H}from"child_process";import{randomBytes as Qe}from"crypto";import{chmodSync as De,existsSync as I,lstatSync as _e,mkdirSync as we,readFileSync as Re,rmSync as ee,writeFileSync as g}from"fs";import{connect as de}from"net";import{join as y}from"path";var S=32,w=76;var B="./desktop-wallpaper-0pjhgyfk.jpg";var O="./dock-browser-afp005mt.png";var F="./dock-files-rywdm96b.png";var k="./dock-terminal-s41cj1jp.png";var K=`# Sets the X root window background and _XROOTPMAP_ID, as feh --bg-fill does.
|
|
3
|
-
# The native Blaxel image ships no feh, hsetroot or compositor, but it does ship
|
|
4
|
-
# python3-gi and libX11. tint2 reads _XROOTPMAP_ID to draw its transparent panel.
|
|
5
|
-
# Usage: DISPLAY=:99 python3 set-root-wallpaper.py IMAGE
|
|
6
|
-
import ctypes, sys
|
|
7
|
-
import gi
|
|
8
|
-
gi.require_version("GdkPixbuf", "2.0")
|
|
9
|
-
from gi.repository import GdkPixbuf
|
|
10
|
-
x = ctypes.cdll.LoadLibrary("libX11.so.6")
|
|
11
|
-
x.XOpenDisplay.restype = ctypes.c_void_p
|
|
12
|
-
x.XOpenDisplay.argtypes = [ctypes.c_char_p]
|
|
13
|
-
d = x.XOpenDisplay(None)
|
|
14
|
-
if not d: sys.exit("no display")
|
|
15
|
-
for name, res, args in [
|
|
16
|
-
("XDefaultScreen", ctypes.c_int, [ctypes.c_void_p]),
|
|
17
|
-
("XRootWindow", ctypes.c_ulong, [ctypes.c_void_p, ctypes.c_int]),
|
|
18
|
-
("XDisplayWidth", ctypes.c_int, [ctypes.c_void_p, ctypes.c_int]),
|
|
19
|
-
("XDisplayHeight", ctypes.c_int, [ctypes.c_void_p, ctypes.c_int]),
|
|
20
|
-
("XDefaultDepth", ctypes.c_int, [ctypes.c_void_p, ctypes.c_int]),
|
|
21
|
-
("XDefaultVisual", ctypes.c_void_p, [ctypes.c_void_p, ctypes.c_int]),
|
|
22
|
-
("XDefaultGC", ctypes.c_void_p, [ctypes.c_void_p, ctypes.c_int]),
|
|
23
|
-
("XCreatePixmap", ctypes.c_ulong, [ctypes.c_void_p, ctypes.c_ulong, ctypes.c_uint, ctypes.c_uint, ctypes.c_uint]),
|
|
24
|
-
("XCreateImage", ctypes.c_void_p, [ctypes.c_void_p, ctypes.c_void_p, ctypes.c_uint, ctypes.c_int, ctypes.c_int, ctypes.c_char_p, ctypes.c_uint, ctypes.c_uint, ctypes.c_int, ctypes.c_int]),
|
|
25
|
-
("XPutImage", ctypes.c_int, [ctypes.c_void_p, ctypes.c_ulong, ctypes.c_void_p, ctypes.c_void_p, ctypes.c_int, ctypes.c_int, ctypes.c_int, ctypes.c_int, ctypes.c_uint, ctypes.c_uint]),
|
|
26
|
-
("XInternAtom", ctypes.c_ulong, [ctypes.c_void_p, ctypes.c_char_p, ctypes.c_int]),
|
|
27
|
-
("XChangeProperty", ctypes.c_int, [ctypes.c_void_p, ctypes.c_ulong, ctypes.c_ulong, ctypes.c_ulong, ctypes.c_int, ctypes.c_int, ctypes.c_void_p, ctypes.c_int]),
|
|
28
|
-
("XSetWindowBackgroundPixmap", ctypes.c_int, [ctypes.c_void_p, ctypes.c_ulong, ctypes.c_ulong]),
|
|
29
|
-
("XClearWindow", ctypes.c_int, [ctypes.c_void_p, ctypes.c_ulong]),
|
|
30
|
-
("XSetCloseDownMode", ctypes.c_int, [ctypes.c_void_p, ctypes.c_int]),
|
|
31
|
-
("XCloseDisplay", ctypes.c_int, [ctypes.c_void_p]),
|
|
32
|
-
]:
|
|
33
|
-
f = getattr(x, name); f.restype = res; f.argtypes = args
|
|
34
|
-
s = x.XDefaultScreen(d); root = x.XRootWindow(d, s)
|
|
35
|
-
w, h = x.XDisplayWidth(d, s), x.XDisplayHeight(d, s)
|
|
36
|
-
if x.XDefaultDepth(d, s) != 24: sys.exit("unsupported depth")
|
|
37
|
-
# Scale to cover the screen, then crop the centre.
|
|
38
|
-
src = GdkPixbuf.Pixbuf.new_from_file(sys.argv[1])
|
|
39
|
-
k = max(w / src.get_width(), h / src.get_height())
|
|
40
|
-
sw, sh = max(w, round(src.get_width() * k)), max(h, round(src.get_height() * k))
|
|
41
|
-
pb = src.scale_simple(sw, sh, GdkPixbuf.InterpType.BILINEAR).new_subpixbuf((sw - w) // 2, (sh - h) // 2, w, h).copy()
|
|
42
|
-
if pb.get_has_alpha(): pb = pb.composite_color_simple(w, h, GdkPixbuf.InterpType.NEAREST, 255, 1, 0, 0)
|
|
43
|
-
rgb, stride = pb.get_pixels(), pb.get_rowstride()
|
|
44
|
-
bgrx = bytearray(w * h * 4)
|
|
45
|
-
for y in range(h):
|
|
46
|
-
row = rgb[y * stride:y * stride + w * 3]; o = y * w * 4
|
|
47
|
-
bgrx[o:o + w * 4:4] = row[2::3]; bgrx[o + 1:o + w * 4:4] = row[1::3]; bgrx[o + 2:o + w * 4:4] = row[0::3]
|
|
48
|
-
buf = ctypes.create_string_buffer(bytes(bgrx), len(bgrx))
|
|
49
|
-
pix = x.XCreatePixmap(d, root, w, h, 24)
|
|
50
|
-
img = x.XCreateImage(d, x.XDefaultVisual(d, s), 24, 2, 0, buf, w, h, 32, 0) # ZPixmap
|
|
51
|
-
x.XPutImage(d, pix, x.XDefaultGC(d, s), img, 0, 0, 0, 0, w, h)
|
|
52
|
-
ref = ctypes.c_ulong(pix)
|
|
53
|
-
for atom in (b"_XROOTPMAP_ID", b"ESETROOT_PMAP_ID"):
|
|
54
|
-
x.XChangeProperty(d, root, x.XInternAtom(d, atom, 0), 20, 32, 0, ctypes.byref(ref), 1) # XA_PIXMAP, PropModeReplace
|
|
55
|
-
x.XSetWindowBackgroundPixmap(d, root, pix)
|
|
56
|
-
x.XClearWindow(d, root)
|
|
57
|
-
x.XSetCloseDownMode(d, 1) # RetainPermanent: the pixmap outlives this process
|
|
58
|
-
x.XCloseDisplay(d)
|
|
59
|
-
`;function ye(e){return`<?xml version="1.0" encoding="UTF-8"?>
|
|
60
|
-
<openbox_config xmlns="http://openbox.org/3.4/rc">
|
|
61
|
-
<theme><keepBorder>no</keepBorder></theme>
|
|
62
|
-
<applications>
|
|
63
|
-
<!-- Debian Chromium is "Chromium"; Chrome for Testing is "Chromium-browser". -->
|
|
64
|
-
<application class="Chromium*">
|
|
65
|
-
<decor>no</decor>
|
|
66
|
-
<position force="yes"><x>${S}</x><y>${S}</y></position>
|
|
67
|
-
<size><width>${e.width-S*2}</width><height>${e.height-S-w}</height></size>
|
|
68
|
-
</application>
|
|
69
|
-
</applications>
|
|
70
|
-
</openbox_config>`}var le=`# Remote sandbox dock \u2014 launcher icons only, centred, no panel fill
|
|
71
|
-
panel_items = L
|
|
72
|
-
panel_size = 100% 46
|
|
73
|
-
panel_margin = 0 10
|
|
74
|
-
panel_padding = 0 0 10
|
|
75
|
-
panel_position = bottom center horizontal
|
|
76
|
-
panel_shrink = 1
|
|
77
|
-
panel_background_id = 0
|
|
78
|
-
panel_layer = top
|
|
79
|
-
mouse_effects = 1
|
|
80
|
-
mouse_hover_icon_asb = 100 0 12
|
|
81
|
-
mouse_pressed_icon_asb = 100 0 -12
|
|
82
|
-
|
|
83
|
-
launcher_icon_size = 46
|
|
84
|
-
launcher_padding = 0 0 10
|
|
85
|
-
launcher_background_id = 0
|
|
86
|
-
launcher_tooltip = 1
|
|
87
|
-
|
|
88
|
-
launcher_item_app = /tmp/ara-chromium.desktop
|
|
89
|
-
launcher_item_app = /tmp/ara-terminal.desktop
|
|
90
|
-
launcher_item_app = /tmp/ara-files.desktop
|
|
91
|
-
`,ue=`corner-radius = 12;
|
|
92
|
-
rounded-corners-exclude = [
|
|
93
|
-
"class_g = 'tint2'",
|
|
94
|
-
"window_type = 'dock'",
|
|
95
|
-
"window_type = 'desktop'"
|
|
96
|
-
];
|
|
97
|
-
backend = "xrender";
|
|
98
|
-
shadow = false;
|
|
99
|
-
fading = false;
|
|
100
|
-
vsync = false;
|
|
101
|
-
inactive-opacity = 1.0;
|
|
102
|
-
active-opacity = 1.0;
|
|
103
|
-
`,Pe="/tmp/ara-dock-browser.png",Se=`[Desktop Entry]
|
|
104
|
-
Name=Chrome
|
|
105
|
-
Exec=chromium --no-sandbox %U
|
|
106
|
-
Icon=${Pe}
|
|
107
|
-
Type=Application
|
|
108
|
-
Categories=Network;WebBrowser;
|
|
109
|
-
`,Xe=`[Desktop Entry]
|
|
110
|
-
Name=Terminal
|
|
111
|
-
Exec=bash -c "DISPLAY=:99 xterm -fa DejaVuSansMono -fs 11 -bg black -fg white"
|
|
112
|
-
Icon=/tmp/ara-dock-terminal.png
|
|
113
|
-
Type=Application
|
|
114
|
-
Categories=System;TerminalEmulator;
|
|
115
|
-
`,fe=`[Desktop Entry]
|
|
116
|
-
Name=Files
|
|
117
|
-
Exec=bash -c "DISPLAY=:99 pcmanfm --no-desktop"
|
|
118
|
-
Icon=/tmp/ara-dock-files.png
|
|
119
|
-
Type=Application
|
|
120
|
-
Categories=System;FileManager;
|
|
121
|
-
`;var V={"wallpaper.jpg":B,"dock-browser.png":O,"dock-terminal.png":k,"dock-files.png":F},Te=K,he='set_wallpaper() { if command -v feh >/dev/null 2>&1; then feh --bg-fill "$1"; else python3 "$2" "$1"; fi; }';function v(e){let s=(i)=>i.replaceAll("DISPLAY=:99",`DISPLAY=${e.display}`).replaceAll("/tmp/ara-",`${e.root}/ara-`),p=new Set(e.absent??[]),n=le.split(`
|
|
122
|
-
`).filter((i)=>!(p.has("terminal")&&i.endsWith("/ara-terminal.desktop"))&&!(p.has("files")&&i.endsWith("/ara-files.desktop"))).join(`
|
|
123
|
-
`),t={"openbox/rc.xml":ye(e.screen),"tint2/tint2rc":s(n),"picom/picom.conf":ue,...p.has("terminal")?{}:{"ara-terminal.desktop":s(Xe)},...p.has("files")?{}:{"ara-files.desktop":s(fe)},"ara-chromium.desktop":s(Se).replace("chromium --no-sandbox %U",e.browserExec),"ara-set-root-wallpaper.py":Te},o=[...R.slice(0,3),he,'[ ! -f "$ROOT/ara-wallpaper.jpg" ] || set_wallpaper "$ROOT/ara-wallpaper.jpg" "$ROOT/ara-set-root-wallpaper.py" || true',...R.slice(3)];return{files:t,start:o}}var R=['ticks() { line=$(cat "/proc/$1/stat" 2>/dev/null) || return 1; rest=${line##*) }; case $rest in Z*|X*) return 1;; esac; printf "%s" "$rest" | cut -d " " -f20; }','alive() { [ -f "$ROOT/$1.pid" ] || return 1; read -r pid start <"$ROOT/$1.pid"; current=$(ticks "$pid") || return 1; [ "$current" = "$start" ] && kill -0 "$pid" 2>/dev/null; }','launch() { name=$1; shift; "$@" 9>&- >"$ROOT/$name.log" 2>&1 & pid=$!; start=$(ticks "$pid"); printf "%s %s\\n" "$pid" "$start" >"$ROOT/$name.pid"; }','if [ -f "$ROOT/tint2/tint2rc" ] && ! alive tint2 && command -v tint2 >/dev/null 2>&1; then launch tint2 tint2 -c "$ROOT/tint2/tint2rc"; fi','if [ -f "$ROOT/picom/picom.conf" ] && ! alive picom && command -v picom >/dev/null 2>&1; then launch picom picom --config "$ROOT/picom/picom.conf"; fi'];var Ae=43200000,D=":99",Ee=60000,_=15000,C={width:1280,height:800},Ne=/^[A-Za-z0-9._:-]{1,160}$/;function Le(e){return Boolean(e)&&typeof e==="object"&&!Array.isArray(e)}var Je=["video","viewer","viewer_same_network","viewer_network"];function Ce(e,s=Date.now()){let p=["relay_url","session_id","expires_at"];if(!Le(e)||p.some((c)=>!(c in e))||Object.keys(e).some((c)=>!p.includes(c)&&!Je.includes(c)))throw new r("invalid_display_request","Reason desktop request is malformed.");let n="video"in e?Eo(e.video):void 0,t="viewer"in e?$n(e.viewer):null;if(n===null)throw new r("invalid_display_request","Reason desktop video request is invalid.");let o=null;try{o=typeof e.relay_url==="string"?new URL(e.relay_url):null}catch{}if(!o||o.protocol!=="wss:"&&o.protocol!=="ws:"||o.username||o.password)throw new r("invalid_display_request","Reason desktop relay URL is invalid.");if(typeof e.session_id!=="string"||!Ne.test(e.session_id))throw new r("invalid_display_request","Reason desktop session identity is invalid.");let i=typeof e.expires_at==="string"?Date.parse(e.expires_at):Number.NaN;if(!Number.isFinite(i)||i<=s)throw new r("invalid_display_request","Reason desktop session has already expired.");return{relay_url:e.relay_url,session_id:e.session_id,expires_at:new Date(Math.min(i,s+Ae)).toISOString(),...n?{video:n}:{},...t?{viewer:t}:{},...n&&e.viewer_same_network===!0?{viewer_same_network:!0}:{}}}function $t(e=process.platform){return(e==="linux"||e==="darwin"||e==="win32")&&x()?.features.display===!0}async function Bs(){if(process.platform==="win32")return $t()&&await Pr();if(process.platform!=="darwin")return $t();return await Pr()}function G(e){we(e,{recursive:!0,mode:448});let s=_e(e);if(!s.isDirectory()||s.isSymbolicLink()||process.getuid&&s.uid!==process.getuid())throw new r("display_unavailable","Reason desktop state directory is not private.");De(e,448)}function Ue(e,s){let p=(t)=>{let o=Buffer.alloc(2);return o.writeUInt16BE(t.length),Buffer.concat([o,t])},n=Buffer.from([255,255]);return Buffer.concat([n,p(Buffer.alloc(0)),p(Buffer.from(e)),p(Buffer.from("MIT-MAGIC-COOKIE-1")),p(s)])}function T(e,s,p=2000){return new Promise((n)=>{let t=de(e),o="",i=(c)=>{t.destroy(),n(c)};t.setTimeout(p,()=>i(!1)),t.once("error",()=>i(!1)),t.once("close",()=>i(!1)),t.once("connect",()=>{if(!s)i(!0)}),t.on("data",(c)=>{if(o+=c.toString("latin1"),o.length>=4)i(o.startsWith("RFB "))})})}async function m(e,s){let p=Date.now()+s;while(Date.now()<p){if(await e())return!0;await new Promise((n)=>setTimeout(n,100))}return!1}function d(e,s,p){return new Promise((n)=>{let t=H(e,s,{detached:!0,stdio:"ignore",env:p});t.once("error",()=>n(-1)),t.once("exit",(o)=>n(o)),t.unref(),setTimeout(()=>n(null),_).unref()})}var U=null;function qe(e=a()){return U??=ge(e).finally(()=>{U=null}),U}async function ge(e){let s=x({home:e});if(!s?.xvfb||!s.x11vnc||!s.openbox)throw new r("display_unavailable","Run `reason desktop install` on this machine to enable its desktop.");xt({root:s.root,automation:s.automation,extensionDir:s.extensionDir});let p=y(s.root,"display");G(p);let n=await Me(e,p,s.x11vnc);if(n)return n;let t={display:D,xauthority:y(p,"Xauthority"),rfbSocket:y(p,"rfb.sock")},o=y(p,"pulse"),i=(async()=>{try{G(o)}catch{return null}return await po(o,s.pulseaudio)})();G(y(p,"home"));let c=re(p,t,s.pulseaudio),h=async()=>({...t,sound:await i});if(await T({path:t.rfbSocket},!0))return pe(y(p,"theme"),R,c),await h();if(!I(t.xauthority))g(t.xauthority,Ue(D.slice(1),Qe(16)),{mode:384,flag:"wx"});let l=te(y(p,"theme"),t.display,C),q={path:`/tmp/.X11-unix/X${D.slice(1)}`};if(!await T(q,!1)){let u=`${C.width}x${C.height}`;if(s.xvnc)ee(t.rfbSocket,{force:!0}),d(s.xvnc,[t.display,"-geometry",u,"-depth","24","-nolisten","tcp","-auth",t.xauthority,"-rfbport","-1","-rfbunixpath",t.rfbSocket,"-SecurityTypes","None","-UseBlacklist=0","-AlwaysShared","-desktop","Reason"],c);else d(s.xvfb,[t.display,"-screen","0",`${u}x24`,"-nolisten","tcp","-auth",t.xauthority],c);if(!await m(()=>T(q,!1),_)||s.xvnc&&!await m(()=>T({path:t.rfbSocket},!0),_))throw new r("display_unavailable","Reason could not start the virtual display.");d(s.openbox,["--config-file",l.openboxConfig],c)}if(await ne(l,c),!await se(s.x11vnc,t,p,"x11vnc.log",c))throw new r("display_unavailable","Reason could not start the desktop server.");return await h()}function re(e,s,p){let n={HOME:y(e,"home"),PATH:"/usr/local/bin:/usr/bin:/bin",DISPLAY:s.display,XAUTHORITY:s.xauthority};if(p)n.PULSE_SERVER=Ve(On(y(e,"pulse")));return n}async function se(e,s,p,n,t){if(await T({path:s.rfbSocket},!0))return!0;ee(s.rfbSocket,{force:!0});let o=await d(e,["-display",s.display,"-auth",s.xauthority,"-rfbport","0","-rfbportv6","-1","-unixsock",s.rfbSocket,"-nopw","-forever","-shared","-noxdamage","-sb","0","-rfbversion","3.7","-quiet","-bg","-o",y(p,n)],t);if(o!==null&&o!==0)return!1;return await m(()=>T({path:s.rfbSocket},!0),_)}async function me(){let e=["DISPLAY","XAUTHORITY","WAYLAND_DISPLAY","XDG_SESSION_TYPE"],s=(p)=>Object.fromEntries(e.flatMap((n)=>p[n]?[[n,p[n]]]:[]));if(process.env.DISPLAY)return s(process.env);try{let p=await new Promise((n,t)=>z("systemctl",["--user","show-environment"],{encoding:"utf8",timeout:2000},(o,i)=>o?t(o):n(i)));return s(Object.fromEntries(p.split(`
|
|
124
|
-
`).flatMap((n)=>{let t=n.indexOf("=");return t>0?[[n.slice(0,t),n.slice(t+1)]]:[]})))}catch{return{}}}var Z=new Set;async function Me(e,s,p){let n=await me(),t=/^:(\d+)(?:\.\d+)?$/.exec(n.DISPLAY??"")?.[1];if(!t||`:${t}`===D||n.WAYLAND_DISPLAY||n.XDG_SESSION_TYPE==="wayland")return null;let o={display:`:${t}`,xauthority:n.XAUTHORITY??y(e,".Xauthority"),rfbSocket:y(s,`rfb-${t}.sock`)},i=`${o.display} ${o.xauthority}`;if(Z.has(i)||!await T({path:`/tmp/.X11-unix/X${t}`},!1))return null;let c={HOME:e,PATH:"/usr/local/bin:/usr/bin:/bin",DISPLAY:o.display,XAUTHORITY:o.xauthority};if(await se(p,o,s,`x11vnc-${t}.log`,c))return{...o,sound:null};return Z.add(i),process.stderr.write(`Reason worker: your screen ${o.display} could not be served; using the virtual desktop
|
|
125
|
-
`),null}function te(e,s,p){let n=`chromium --no-first-run --no-default-browser-check${process.geteuid?.()===0?" --no-sandbox":""} %U`,t=[["terminal","xterm"],["files","pcmanfm"]].filter(([,i])=>!I(`/usr/bin/${i}`)).map(([i])=>i),o=v({root:e,display:s,screen:p,browserExec:n,absent:t});for(let i of["","openbox","tint2","picom"])G(y(e,i));for(let[i,c]of Object.entries(o.files))g(y(e,i),c,{mode:384});for(let[i,c]of Object.entries(V))g(y(e,`ara-${i}`),Re(c),{mode:384});return{root:e,openboxConfig:y(e,"openbox","rc.xml"),start:o.start}}function ne(e,s){return pe(e.root,[...e.start,"openbox --reconfigure >/dev/null 2>&1 || true"],s)}function pe(e,s,p){let n=[`ROOT=${JSON.stringify(e)}`,...s].join(`
|
|
126
|
-
`);return new Promise((t)=>{let o=H("/bin/sh",["-c",n],{stdio:"ignore",env:{...p,PATH:"/usr/bin:/bin"}}),i=setTimeout(()=>{o.kill(),t()},_);o.once("error",()=>{clearTimeout(i),t()}),o.once("exit",()=>{clearTimeout(i),t()})})}var We=2073600,je=320;function Be(e,s){let p=Math.min(1,Math.sqrt(We/(e.width*e.height))),n=(t,o)=>Math.min(Math.floor(o/8)*8,Math.max(je,Math.round(t*p/8)*8));return{width:n(e.width,s.width),height:n(e.height,s.height)}}function oe(e,s,p){return new Promise((n)=>z(e,s,{env:p,encoding:"utf8",timeout:5000},(t,o)=>n(t?null:o)))}function Oe(e){let s=/current (\d+) x (\d+), maximum (\d+) x (\d+)/.exec(e),p=e.split(`
|
|
127
|
-
`),n=p.findIndex((o)=>/^\S+ connected/.test(o));if(!s||n<0)return null;let t=[];for(let o of p.slice(n+1)){let i=/^\s+(\d+x\d+)\s/.exec(o);if(!i)break;t.push(i[1])}return{current:{width:Number(s[1]),height:Number(s[2])},maximum:{width:Number(s[3]),height:Number(s[4])},output:p[n].split(" ")[0],modes:t}}async function Fe(e,s,p){if(e.display!==D)return null;let n={PATH:"/usr/bin:/bin",DISPLAY:e.display,XAUTHORITY:e.xauthority},t=(h)=>oe("xrandr",h,n),o=Oe(await t(["--query"])??"");if(!o||o.maximum.width<=o.current.width&&o.maximum.height<=o.current.height)return null;let i=Be(s,o.maximum);if(i.width===o.current.width&&i.height===o.current.height)return{size:i,changed:!1};let c=`${i.width}x${i.height}`;if(!o.modes.includes(c)){if(await t(["--newmode",c,"60",...[i.width,i.width,i.width,i.width,i.height,i.height,i.height,i.height].map(String)]),await t(["--addmode",o.output,c])===null)return null}return p(),await t(["--output",o.output,"--mode",c])===null?null:{size:i,changed:!0}}async function ke(e,s){let p=x({home:a()});if(!p)return;let n=y(p.root,"display"),t=re(n,e,p.pulseaudio);await ne(te(y(n,"theme"),e.display,s),t);let o=s.width-S*2,i=s.height-S-w;await oe("xdotool",["search","--onlyvisible","--class","Chromium","windowsize","%@",String(o),String(i),"windowmove","%@",String(S),String(S)],{...t,PATH:"/usr/bin:/bin"})}var Y=Promise.resolve();function Ge(e,s,p=()=>{}){let n=Y.then(()=>Fe(e,s,p));return Y=n.then((t)=>t?.changed?ke(e,t.size):void 0).catch(()=>{}),n.then((t)=>t?.size??null,()=>null)}async function Bt(e,s={}){let p=s.now??Date.now,n=Ce(e.payload,p());if(e.signal.throwIfAborted(),!n.video)throw new r("display_video_required","Reason desktops stream as video now; this request came without it.");let t=s.platform??process.platform;if(t!=="linux"&&t!=="darwin"&&t!=="win32")throw new r("display_video_unsupported","This machine does not serve desktop video.");let o=n.video,i=(s.video?.desktop??(t==="darwin"?async()=>In:t==="win32"?async()=>Dn:qe))();return await Ke(e.signal,n,s,p,(c)=>Nn(c,{request:o,desktop:i,...n.viewer?{viewer:n.viewer}:{},viewerSameNetwork:n.viewer_same_network===!0},{resizeDesktop:Ge,...s.video}),(c)=>zt({type:"error",code:c}))}function Ke(e,s,p,n,t,o){let i=n();return new Promise((c,h)=>{let l=null,q=!1,u=!1,M,A,Q,E=!1,P=null,X=(b)=>{if(u)return;if(P)b=P.outcome;u=!0,clearTimeout(M),clearTimeout(A),e.removeEventListener("abort",L),Q?.close();try{l?.close(1000,"display_session_over")}catch{}if("error"in b){h(b.error);return}c({reason:b.reason,...Q?.summary(),duration_ms:Math.max(0,n()-i)})},N=()=>X({error:new r("display_relay_unavailable","Reason could not reach the desktop relay.")}),L=()=>{let b=e.reason;X({error:b instanceof r?b:new r("cancelled","Reason closed the desktop session.")})},W=()=>{if(!P||!l)return;let{outcome:b}=P,f=!("error"in b)?b.reason:b.error instanceof r?b.error.code:"display_unavailable";if(!P.told)try{l.send(o(f))}catch{}X(b)};if(Q=t({get done(){return u||P!==null},get open(){return q&&!u&&P===null},get bufferedAmount(){return l?.bufferedAmount??0},send(b){if(u||P||!q||!l)return;try{l.send(b)}catch{X({reason:"relay_closed"})}},end:(b)=>{if(u||P)return;if(!("error"in b)&&E&&q){X(b);return}if(P={outcome:b,told:!("error"in b)&&q},E&&q)W()}}),u){Q.close();return}if(e.aborted){L();return}e.addEventListener("abort",L,{once:!0}),M=setTimeout(()=>X({reason:"session_expired"}),Math.max(1,Date.parse(s.expires_at)-n())),A=setTimeout(()=>X({reason:"viewer_absent"}),p.viewerWaitMs??Ee);try{l=(p.connect??Dr)(s.relay_url,(p.loadProxy??j)()?.url)}catch{N();return}l.binaryType="arraybuffer",l.onopen=()=>{if(u||!l)return;q=!0,Q?.opened()},l.onmessage=(b)=>{if(u)return;let f=b.data,J=f instanceof ArrayBuffer?new Uint8Array(f):ArrayBuffer.isView(f)?new Uint8Array(f.buffer,f.byteOffset,f.byteLength):null;if(!J||J.byteLength===0)return;if(clearTimeout(A),E=!0,P){W();return}Q?.received(J)},l.onclose=()=>{if(u)return;if(!q){N();return}X({reason:"relay_closed"})},l.onerror=()=>{if(u||q)return;N()}})}
|
|
128
|
-
export{$t,Bs,G,qe,Bt};
|
|
@@ -1,3 +0,0 @@
|
|
|
1
|
-
// @bun
|
|
2
|
-
var l=Object.create;var{getPrototypeOf:m,defineProperty:h,getOwnPropertyNames:n}=Object;var k=Object.prototype.hasOwnProperty;function o(a){return this[a]}var p,q,Li=(a,b,c)=>{var d=a!=null&&typeof a==="object";if(d){var i=b?p??=new WeakMap:q??=new WeakMap,j=i.get(a);if(j)return j}c=a!=null?l(m(a)):{};let f=b||!a||!a.__esModule||!k.call(a,"default")?h(c,"default",{value:a,enumerable:!0}):c;if(a&&typeof a==="object"||typeof a==="function"){for(let g of n(a))if(!k.call(f,g))h(f,g,{get:o.bind(a,g),enumerable:!0})}if(d)i.set(a,f);return f};var he=(a,b)=>()=>(b||a((b={exports:{}}).exports,b),b.exports);var r=(a)=>a;function s(a,b){this[a]=r.bind(null,b)}var us=(a,b)=>{for(var c in b)h(a,c,{get:b[c],enumerable:!0,configurable:!0,set:s.bind(b,c)})};var ds=(a,b,c)=>()=>{if(a)try{b=a(a=0)}catch(d){c=[d]}if(c)throw c[0];return b};var e=import.meta.require;
|
|
3
|
-
export{Li,he,us,ds,e};
|
|
@@ -1,126 +0,0 @@
|
|
|
1
|
-
// @bun
|
|
2
|
-
import{S,zt,Bn,Ge,Fn,jn}from"./vm-hands-entry-lite-eabever7.js";import{Yn}from"./vm-hands-entry-lite-wg0cykk2.js";import{Mn}from"./vm-hands-entry-lite-ncbzy69k.js";import{r}from"./vm-hands-entry-lite-qy9xg6em.js";import{execFile as ys,spawn as qe}from"child_process";import{existsSync as ws}from"fs";import{connect as xs}from"net";function pn(){let e=new Set,t=null,n=(s)=>({holder:t?.viewer??null,you:t===s,same_user:Boolean(t?.viewer&&s.viewer&&t.viewer.user_id===s.viewer.user_id)}),o=()=>{for(let s of e)s.notify(n(s))};return{join(s){return e.add(s),s.notify(n(s)),()=>{if(!e.delete(s))return;if(t!==s)return;t=null,o()}},claim(s){if(t===s||!e.has(s))return;t=s,o()}}}var ut=pn();import{createHash as St}from"crypto";import{once as Sn}from"events";import{createWriteStream as vn,existsSync as mr,mkdirSync as gr,mkdtempSync as hr,readFileSync as le,readdirSync as br,renameSync as yr,realpathSync as En,rmSync as Pn,statSync as Ne,writeFileSync as wr}from"fs";import{delimiter as _r,dirname as vt,join as b}from"path";import{finished as Cn}from"stream/promises";var We="omljlfpmafedpplnpkkahegadhkimdje",uo="https://chromewebstore.google.com/detail/reason/omljlfpmafedpplnpkkahegadhkimdje";var O={ocu:{repository:"https://github.com/iFurySt/open-codex-computer-use.git",revision:"386a260d1ab8b690adbbb27f7471595cf0c2b752",version:"0.3.5"},obu:{repository:"https://github.com/iFurySt/open-browser-use.git",revision:"ac015846df75928fbcf0f3a0f3ba3a210ce1a507",version:"0.1.42"}},H={version:"155.0.8059.84",macArm64Sha256:"13b9e98ce56f5ce18e100a009f455c9285f399e7c9dc8a76fdf2f3a9755bb5f2",linux64Sha256:"cf0f049892dea22e6a6db26d47ed0d7776b7158edcbec4634086633df8bafcbc",win64Sha256:"507f2a031441d10c62b5e3d4e863f09ac1198a571c1419976cbd8387f639afde"};var J={ocu:{url:`https://registry.npmjs.org/open-computer-use/-/open-computer-use-${O.ocu.version}.tgz`,sha256:"7c16a87c8cd357787b02c0ebd040dd5f93880c1fb51c1901caa2e0c05d063130",size_bytes:5844280},obu:{url:`https://registry.npmjs.org/open-browser-use/-/open-browser-use-${O.obu.version}.tgz`,sha256:"9386d8ce0a147b3f55e1807b68edf736836378807541c457c9b5f6ca2cabaa4e",size_bytes:21372018},extension:{url:`https://github.com/iFurySt/open-browser-use/releases/download/v${O.obu.version}/open-browser-use-chrome-extension-${O.obu.version}.zip`,sha256:"c9c07bec1175e12ea6985b0e7784a5ef01fd03f014b958224a1e17dcd838a241",size_bytes:31070}},F="pnbmoicbkopffjjgfgfglopechaiemkp";import{spawn as Me}from"child_process";import{createRequire as fn}from"module";import{join as mn}from"path";var gn=30000,hn=1048576;function Te(){return process.env.SystemRoot??"C:\\Windows"}function bn(){return mn(Te(),"System32","WindowsPowerShell","v1.0","powershell.exe")}var yn=String.raw`
|
|
3
|
-
$ErrorActionPreference = "Stop"
|
|
4
|
-
Add-Type -TypeDefinition @"
|
|
5
|
-
using System;
|
|
6
|
-
using System.Runtime.InteropServices;
|
|
7
|
-
public static class ReasonInput {
|
|
8
|
-
[StructLayout(LayoutKind.Sequential)] public struct MOUSEINPUT { public int dx; public int dy; public int mouseData; public uint dwFlags; public uint time; public IntPtr dwExtraInfo; }
|
|
9
|
-
[StructLayout(LayoutKind.Sequential)] public struct KEYBDINPUT { public ushort wVk; public ushort wScan; public uint dwFlags; public uint time; public IntPtr dwExtraInfo; }
|
|
10
|
-
[StructLayout(LayoutKind.Explicit)] public struct UNION { [FieldOffset(0)] public MOUSEINPUT mi; [FieldOffset(0)] public KEYBDINPUT ki; }
|
|
11
|
-
[StructLayout(LayoutKind.Sequential)] public struct INPUT { public uint type; public UNION u; }
|
|
12
|
-
[DllImport("user32.dll")] static extern uint SendInput(uint count, INPUT[] inputs, int size);
|
|
13
|
-
[DllImport("user32.dll")] public static extern bool SetProcessDPIAware();
|
|
14
|
-
[DllImport("user32.dll")] public static extern int GetSystemMetrics(int index);
|
|
15
|
-
[DllImport("user32.dll")] static extern uint MapVirtualKey(uint code, uint type);
|
|
16
|
-
[DllImport("user32.dll")] public static extern uint GetClipboardSequenceNumber();
|
|
17
|
-
static void Send(INPUT input) { SendInput(1, new INPUT[] { input }, Marshal.SizeOf(typeof(INPUT))); }
|
|
18
|
-
public static void Mouse(uint flags, int x, int y, int data) {
|
|
19
|
-
INPUT input = new INPUT(); input.type = 0;
|
|
20
|
-
input.u.mi.dx = x; input.u.mi.dy = y; input.u.mi.mouseData = data; input.u.mi.dwFlags = flags; Send(input);
|
|
21
|
-
}
|
|
22
|
-
public static void Key(ushort vk, ushort unit, uint flags) {
|
|
23
|
-
INPUT input = new INPUT(); input.type = 1;
|
|
24
|
-
input.u.ki.wVk = vk; input.u.ki.wScan = vk != 0 ? (ushort)MapVirtualKey(vk, 0) : unit; input.u.ki.dwFlags = flags; Send(input);
|
|
25
|
-
}
|
|
26
|
-
}
|
|
27
|
-
"@
|
|
28
|
-
[void][ReasonInput]::SetProcessDPIAware()
|
|
29
|
-
$width = [ReasonInput]::GetSystemMetrics(0)
|
|
30
|
-
$height = [ReasonInput]::GetSystemMetrics(1)
|
|
31
|
-
$session = [Diagnostics.Process]::GetCurrentProcess().SessionId
|
|
32
|
-
[Console]::Out.WriteLine('{"session":' + $session + ',"width":' + $width + ',"height":' + $height + '}')
|
|
33
|
-
[Console]::Out.Flush()
|
|
34
|
-
$mode = "__MODE__"
|
|
35
|
-
if ($mode -eq "probe") { exit 0 }
|
|
36
|
-
if ($mode -eq "clipboard") {
|
|
37
|
-
# Only changes made during this pairing: never export the initial clipboard.
|
|
38
|
-
$parent = Get-Process -Id __PARENT__
|
|
39
|
-
$last = [ReasonInput]::GetClipboardSequenceNumber()
|
|
40
|
-
while (-not $parent.HasExited) {
|
|
41
|
-
Start-Sleep -Milliseconds 100
|
|
42
|
-
$count = [ReasonInput]::GetClipboardSequenceNumber()
|
|
43
|
-
if ($count -eq $last) { continue }
|
|
44
|
-
$last = $count
|
|
45
|
-
try { $text = Get-Clipboard -Raw } catch { continue }
|
|
46
|
-
if (-not $text) { continue }
|
|
47
|
-
$bytes = [Text.Encoding]::UTF8.GetBytes($text)
|
|
48
|
-
if ($bytes.Length -gt __MAX_TEXT_BYTES__) { continue }
|
|
49
|
-
[Console]::Out.WriteLine("c " + [Convert]::ToBase64String($bytes))
|
|
50
|
-
[Console]::Out.Flush()
|
|
51
|
-
}
|
|
52
|
-
exit 0
|
|
53
|
-
}
|
|
54
|
-
$scaleX = 65535.0 / [Math]::Max(1, $width - 1)
|
|
55
|
-
$scaleY = 65535.0 / [Math]::Max(1, $height - 1)
|
|
56
|
-
while ($null -ne ($line = [Console]::In.ReadLine())) {
|
|
57
|
-
$n = $line.Split(" ")
|
|
58
|
-
try {
|
|
59
|
-
switch ($n[0]) {
|
|
60
|
-
"p" { [ReasonInput]::Mouse(0x8001, [int]([int]$n[1] * $scaleX), [int]([int]$n[2] * $scaleY), 0) }
|
|
61
|
-
"b" { [ReasonInput]::Mouse([uint32]$n[1], 0, 0, [int]$n[2]) }
|
|
62
|
-
"k" { [ReasonInput]::Key([uint16]$n[1], [uint16]$n[2], [uint32]$n[3]) }
|
|
63
|
-
"c" { Set-Clipboard -Value ([Text.Encoding]::UTF8.GetString([Convert]::FromBase64String($n[1]))) }
|
|
64
|
-
}
|
|
65
|
-
} catch { [Console]::Error.WriteLine("input: $_") }
|
|
66
|
-
}
|
|
67
|
-
`;function Oe(e){let t=yn.replace("__MODE__",e).replace("__PARENT__",String(process.pid)).replace("__MAX_TEXT_BYTES__",String(S));return[bn(),["-NoLogo","-NoProfile","-NonInteractive","-ExecutionPolicy","Bypass","-EncodedCommand",Buffer.from(t,"utf16le").toString("base64")]]}var wn=["USERPROFILE","LOCALAPPDATA","APPDATA","TEMP","TMP","PSModuleAnalysisCachePath"];function Ae(){let e=wn.flatMap((t)=>process.env[t]?[[t,process.env[t]]]:[]);return{...Object.fromEntries(e),SystemRoot:Te(),windir:Te()}}function ht(e){let t;try{t=JSON.parse(e)}catch{return null}if(!t||typeof t!=="object")return null;let n=t,o=(s,i)=>typeof s==="number"&&Number.isSafeInteger(s)&&s>=i;return o(n.session,0)&&o(n.width,1)&&o(n.height,1)?{session:n.session,width:n.width,height:n.height}:null}function bt(){return new Promise((e)=>{let t=Me(...Oe("probe"),{env:Ae(),stdio:["ignore","pipe","ignore"],windowsHide:!0}),n="",o=setTimeout(()=>{t.kill("SIGKILL"),e(null)},gn);t.stdout.setEncoding("utf8").on("data",(s)=>{n+=s}),t.once("error",()=>{clearTimeout(o),e(null)}),t.once("close",()=>{clearTimeout(o),e(ht(n.split(/\r?\n/)[0]??""))})})}var Z;function yt(){if(Z!==void 0)return Z;if(process.platform!=="win32")return Z=!1;try{let e=fn(import.meta.url)("bun:ffi"),{symbols:t}=e.dlopen("kernel32.dll",{GetCurrentProcessId:{args:[],returns:e.FFIType.u32},ProcessIdToSessionId:{args:[e.FFIType.u32,e.FFIType.ptr],returns:e.FFIType.i32}}),n=new Uint32Array(1);return Z=t.ProcessIdToSessionId(t.GetCurrentProcessId(),n)!==0&&n[0]>0}catch{return Z=!1}}var lt=[{bit:1,down:2,up:4},{bit:2,down:32,up:64},{bit:4,down:8,up:16}],dt=2048,pt=4096,xn=[[8,dt,120],[16,dt,-120],[32,pt,-120],[64,pt,120]],ft=1,Re=2,_n=4,kn=new Set([65505,65506]),mt=new Set([65507,65508,65511,65512,65513,65514,65027,65515,65516]),gt=new Map([[65505,[160,!1]],[65506,[161,!1]],[65507,[162,!1]],[65508,[163,!0]],[65511,[164,!1]],[65512,[165,!0]],[65513,[164,!1]],[65514,[165,!0]],[65027,[165,!0]],[65515,[91,!0]],[65516,[92,!0]],[65288,[8,!1]],[65289,[9,!1]],[65056,[9,!1]],[65293,[13,!1]],[65307,[27,!1]],[65535,[46,!0]],[65379,[45,!0]],[65360,[36,!0]],[65367,[35,!0]],[65365,[33,!0]],[65366,[34,!0]],[65361,[37,!0]],[65362,[38,!0]],[65363,[39,!0]],[65364,[40,!0]],[65383,[93,!0]],[65509,[20,!1]],[65299,[19,!1]],[65300,[145,!1]],[65377,[44,!0]],[65407,[144,!0]],[32,[32,!1]],[65421,[13,!0]],[65408,[32,!1]],[65450,[106,!1]],[65451,[107,!1]],[65452,[108,!1]],[65453,[109,!1]],[65454,[110,!1]],[65455,[111,!0]],[65429,[36,!1]],[65430,[37,!1]],[65431,[38,!1]],[65432,[39,!1]],[65433,[40,!1]],[65434,[33,!1]],[65435,[34,!1]],[65436,[35,!1]],[65438,[45,!1]],[65439,[46,!1]],...Array.from({length:10},(e,t)=>[65456+t,[96+t,!1]]),...Array.from({length:24},(e,t)=>[65470+t,[112+t,!1]])]);class wt{x=-1;y=-1;mask=0;held=new Set;pressed=new Set;pointer(e,t,n){let o=[];if(e!==this.x||t!==this.y)this.x=e,this.y=t,o.push(`p ${e} ${t}`);for(let s of lt){let i=(this.mask&s.bit)!==0,a=(n&s.bit)!==0;if(i!==a)o.push(`b ${a?s.down:s.up} 0`)}for(let[s,i,a]of xn)if(!(this.mask&s)&&n&s)o.push(`b ${i} ${a}`);return this.mask=n,o}key(e,t){let n=e?0:Re;if(kn.has(t)||mt.has(t))if(e)this.held.add(t);else this.held.delete(t);let o=gt.get(t);if(o)return[`k ${o[0]} 0 ${n|(o[1]?ft:0)}`];let s=t<256?t:(t&4278190080)===16777216?t&16777215:0,i=String.fromCharCode(s),a=[...this.held].some((y)=>mt.has(y)),d=/^[A-Za-z0-9]$/.test(i)?i.toUpperCase().charCodeAt(0):0;if(d&&(e?a:this.pressed.has(d))){if(e)this.pressed.add(d);else this.pressed.delete(d);return[`k ${d} 0 ${n}`]}if(s<33||s>=127&&s<160||s>65535||s>=55296&&s<57344)return[];return[`k 0 ${s} ${n|_n}`]}release(){let e=lt.filter((t)=>this.mask&t.bit).map((t)=>`b ${t.up} 0`);for(let t of this.pressed)e.push(`k ${t} 0 ${Re}`);for(let t of this.held){let[n,o]=gt.get(t);e.push(`k ${n} 0 ${Re|(o?ft:0)}`)}return this.mask=0,this.pressed.clear(),this.held.clear(),e}}function xt(e){let t=Me(...Oe("input"),{env:Ae(),stdio:["pipe","pipe","ignore"],windowsHide:!0}),n=new wt,o="",s=!1,i=null,a=()=>{if(i?.kill("SIGKILL"),t.exitCode!==null||t.signalCode!==null)return;t.stdin.end(n.release().map((p)=>`${p}
|
|
68
|
-
`).join("")),setTimeout(()=>t.kill("SIGKILL"),2000).unref()},d=(p)=>{if(s)return;s=!0,a(),e.end(p)},y=(p)=>d({error:new r("display_unavailable",p)}),h=(p)=>{if(s||p.length===0)return;if(t.stdin.write(p.map((w)=>`${w}
|
|
69
|
-
`).join("")),t.stdin.writableLength>hn)d({reason:"input_backpressure"})},g=()=>{i=Me(...Oe("clipboard"),{env:Ae(),stdio:["ignore","pipe","ignore"],windowsHide:!0});let p="";i.stdout?.on("data",(w)=>{if(s)return;p+=w.toString("ascii");for(let f=p.indexOf(`
|
|
70
|
-
`);f>=0;f=p.indexOf(`
|
|
71
|
-
`)){let M=p.slice(0,f).replace(/\r$/,"");if(p=p.slice(f+1),!M.startsWith("c "))continue;let E=M.slice(2);if(E.length>Math.ceil(S/3)*4||!/^(?:[A-Za-z0-9+/]{4})*(?:[A-Za-z0-9+/]{2}==|[A-Za-z0-9+/]{3}=)?$/.test(E)){d({reason:"display_protocol"});return}let c=Buffer.from(E,"base64");if(c.byteLength<=S)e.clipboard(c.toString("utf8"));if(s)return}if(p.length>Math.ceil(S/3)*4+4)d({reason:"display_protocol"})}),i.once("error",()=>y("Reason could not watch this computer's desktop clipboard.")),i.once("exit",()=>{if(!s)y("Reason could not watch this computer's desktop clipboard.")})};return t.stdout.on("data",(p)=>{if(s||o===null)return;o+=p.toString("utf8");let w=o.indexOf(`
|
|
72
|
-
`);if(w<0){if(o.length>4096)d({reason:"display_protocol"});return}let f=ht(o.slice(0,w).trim());if(o=null,!f)d({reason:"display_protocol"});else if(f.session===0)y("This Windows worker runs as a service, which has no desktop: run it in the signed-in desktop session.");else g(),e.ready({width:f.width,height:f.height})}),t.stdin.on("error",()=>{return}),t.once("error",()=>y("Reason could not start this computer's desktop input.")),t.once("exit",()=>{if(o!==null)y("Reason could not start this computer's desktop input.");else d({reason:"display_closed"})}),{pointer:(p,w,f)=>h(n.pointer(p,w,f)),key:(p,w)=>h(n.key(p,w)),clipboard:(p)=>h([`c ${Buffer.from(p,"utf8").toString("base64")}`]),close(){s=!0,a()}}}var Rn=["none","standard","all"],ue="22.23.3",Tn={"linux-x64":"1084aa36196bba4c3a5e69a1ee388a6e4ff729dad09445fbcd434b28fe3c24af","linux-arm64":"5ced2d48d1d7198739b7f86804de0171aefb6823b684b12341d3321afc3cb0b2","darwin-arm64":"23b25245dcfb9af7262f8ff142e9e2e0af025368117329e7a7458a51e5922f53","win32-x64":"2b0ff57b049cda1bbcea2240eec20467018713c1efe1f7360c2681859b90ed71","win32-arm64":"33dad22e4cef5ee8f9fbb1b0d037fdacd0e56d12a4580f0d63f68b894deab535"},$e={"linux-x64":{ocu:"dist/linux/amd64/open-computer-use",obu:"native/linux-amd64/open-browser-use"},"linux-arm64":{ocu:"dist/linux/arm64/open-computer-use",obu:"native/linux-arm64/open-browser-use"},"darwin-arm64":{ocu:"dist/Open Computer Use.app/Contents/MacOS/OpenComputerUse",obu:"native/darwin-arm64/open-browser-use"},"win32-x64":{ocu:"dist/windows/amd64/open-computer-use.exe",obu:"native/windows-amd64/open-browser-use.exe"},"win32-arm64":{ocu:"dist/windows/arm64/open-computer-use.exe",obu:"native/windows-arm64/open-browser-use.exe"}},Et="chrome-mac-arm64/Google Chrome for Testing.app/Contents/MacOS/Google Chrome for Testing",Dt="chrome-win64/chrome.exe",W={version:"9.0.2",url:"https://ffmpeg.martin-riedl.de/download/macos/arm64/1789931890_9.0.2/ffmpeg.zip",sha256:"c8ed4c4e6978a03c485edbfe4e0a5dc2380f8a30bba5150531b31b094492d924"},An={version:W.version,url:"https://ffmpeg.martin-riedl.de/download/macos/arm64/1789931890_9.0.2/ffprobe.zip",sha256:"fcbe839537485eaee7a7a8bc5cbc0f90d53617e80943e8a5b2e31cb851197ea6"},Le={version:W.version,url:`https://github.com/GyanD/codexffmpeg/releases/download/${W.version}/ffmpeg-${W.version}-essentials_build.zip`,sha256:"60f467265b1e312373dbcd92200c2618a74850f98d3d078e94296bb3fa2047ba"},_t=`ffmpeg-${Le.version}-essentials_build/bin`,z="com.ifuryst.open_browser_use.extension",It="com.reasonmachines.browser_use.extension",Ft="/tmp/reason-browser-use",Ue=["tint2","picom","xterm","pcmanfm"],Pt=["fonts-droid-fallback"],Ct=["pulseaudio"],Rt=["tigervnc-standalone-server"],$n=["xvfb","openbox","x11vnc","x11-utils","x11-xserver-utils","xdotool","dbus-x11","at-spi2-core","python3","python3-gi","gir1.2-atspi-2.0","gir1.2-gtk-3.0","fonts-dejavu-core",...Pt,"galculator","chromium","ffmpeg","tmux",...Ct,...Rt,...Ue],Un=new Set([...Ue,...Pt,...Ct,...Rt]),kt=$n.filter((e)=>e!=="chromium"&&!Un.has(e)),Hn=["Xvfb","openbox","x11vnc","xdotool","dbus-launch","python3","ffmpeg","tmux"],ce="/usr/bin/chromium",zn=["/usr/local/bin","/usr/bin","/bin","/opt/homebrew/bin"];function Gn(e=process.platform,t=process.arch){let n=`${e}-${t}`;return n==="linux-x64"||n==="linux-arm64"||n==="darwin-arm64"||n==="win32-x64"||n==="win32-arm64"?n:null}function K(e){return e==="win32-x64"||e==="win32-arm64"}function Be(e){return K(e)?`node-v${ue}-${e.replace("win32","win")}`:`node-v${ue}-${e}`}function de(e){return{node:{version:ue,url:`https://nodejs.org/dist/v${ue}/${Be(e)}${K(e)?".zip":".tar.gz"}`,sha256:Tn[e]},open_computer_use:{version:O.ocu.version,url:J.ocu.url,sha256:J.ocu.sha256},open_browser_use:{version:O.obu.version,url:J.obu.url,sha256:J.obu.sha256},...e==="darwin-arm64"?{chrome_for_testing:{version:H.version,url:`https://storage.googleapis.com/chrome-for-testing-public/${H.version}/mac-arm64/chrome-mac-arm64.zip`,sha256:H.macArm64Sha256}}:K(e)?{chrome_for_testing:{version:H.version,url:`https://storage.googleapis.com/chrome-for-testing-public/${H.version}/win64/chrome-win64.zip`,sha256:H.win64Sha256}}:{}}}function Vn(e){let t={extension:F};for(let[n,o]of Object.entries(de(e)))t[n]=`${o.version}@${o.sha256}`;return t}function Mt(e){return b(e,".local","share","reason","desktop")}function Tr(e,t=Mn()){let n=Mt(t),o=(p)=>b(n,p,de(e)[p]?.version??""),s=o("open_computer_use"),i=o("open_browser_use"),a=e==="darwin-arm64",d=K(e),y=b(t,"Library","Application Support"),h=b(process.platform==="win32"&&process.env.LOCALAPPDATA?process.env.LOCALAPPDATA:b(t,"AppData","Local"),"OpenBrowserUse"),g=a?b(y,"Google","Chrome","NativeMessagingHosts",`${z}.json`):d?b(h,"NativeMessagingHosts",`${z}.json`):b(t,".config","google-chrome","NativeMessagingHosts",`${z}.json`);return{root:n,automation:b(vt(n),"automation"),receipt:b(n,"receipt.json"),minimal:is(t),node:d?b(o("node"),Be(e),"node.exe"):b(o("node"),"bin","node"),ocuDir:s,ocu:b(s,$e[e].ocu),ocuApp:a?b(s,"dist","Open Computer Use.app"):null,obuDir:i,obu:b(i,"cli","open-browser-use.js"),nativeHost:b(i,$e[e].obu),extensionDir:a?b(y,"OpenBrowserUse","chrome-extension","release"):d?b(h,"chrome-extension","release"):b(t,".local","share","open-browser-use","chrome-extension","release"),setupNativeHostManifest:g,nativeHostManifests:a?[g,b(y,"Google","ChromeForTesting","NativeMessagingHosts",`${z}.json`)]:d?[g]:[b(t,".config","chromium","NativeMessagingHosts",`${z}.json`),b(t,".config","google-chrome-for-testing","NativeMessagingHosts",`${z}.json`)],browser:a?b(o("chrome_for_testing"),Et):d?b(o("chrome_for_testing"),Dt):ce,userChromeHost:a?b(n,"user-chrome","reason-browser-use"):null,userChromeRegistration:a?b(y,"Google","Chrome","NativeMessagingHosts",`${It}.json`):null,ffmpegDir:b(n,"ffmpeg"),ffmpeg:a?b(n,"ffmpeg",W.version,"ffmpeg"):d?b(n,"ffmpeg",Le.version,_t,"ffmpeg.exe"):null,ffprobe:a?b(n,"ffprobe",An.version,"ffprobe"):d?b(n,"ffmpeg",Le.version,_t,"ffprobe.exe"):null}}function Wn(e){try{let t=JSON.parse(le(e,"utf8"));if(typeof t!=="object"||t===null)return null;let n=t,o=n.pins;if(n.schema_version!==1||typeof n.platform!=="string"||typeof o!=="object"||o===null||!Object.values(o).every((s)=>typeof s==="string")||!Rn.includes(n.permissions)||!Array.isArray(n.missing_system_packages)||!n.missing_system_packages.every((s)=>typeof s==="string")||typeof n.updated_at!=="string")return null;return{schema_version:1,platform:n.platform,pins:o,permissions:n.permissions,missing_system_packages:n.missing_system_packages,updated_at:n.updated_at}}catch{return null}}function A(e){try{return Ne(e).isFile()}catch{return!1}}function Tt(e){try{let t=Ne(e);return t.isFile()&&(t.mode&73)!==0}catch{return!1}}function Kn(e){try{return le(e,"utf8")}catch{return null}}function U(e){for(let t of zn){let n=b(t,e);try{let o=Ne(n);if(o.isFile()&&(o.mode&73)!==0)return n}catch{}}return null}function Xn(e){try{let t=JSON.parse(le(b(e,"package.json"),"utf8"));return typeof t==="object"&&t!==null&&typeof t.version==="string"?t.version:null}catch{return null}}function qn(e,t,n){let o=de(n)[e];if(!o)return!1;let s=K(n);if(e==="node")return A(s?b(t,Be(n),"node.exe"):b(t,"bin","node"));if(e==="chrome_for_testing")return A(b(t,s?Dt:Et));let i=$e[n][e==="open_computer_use"?"ocu":"obu"];return Xn(t)===o.version&&A(b(t,i))&&(e==="open_computer_use"||A(b(t,"cli","open-browser-use.js")))}function Jn(e){return St("sha256").update(Buffer.from(e,"base64")).digest("hex").slice(0,32).replace(/./g,(t)=>String.fromCharCode(97+Number.parseInt(t,16)))}function He(e){try{let t=JSON.parse(le(e,"utf8"));return typeof t==="object"&&t!==null&&!Array.isArray(t)?t:null}catch{return null}}function Zn(e){let t=He(b(e.extensionDir,"manifest.json"));return t!==null&&t.version===O.obu.version&&typeof t.key==="string"&&Jn(t.key)===F}function Qn(e,t){let n=e?.allowed_origins;return e!==null&&e.name===z&&Array.isArray(n)&&n.length===1&&n[0]===`chrome-extension://${F}/`&&(t===void 0||e.path===t)}function es(e){return Zn(e)&&A(e.nativeHost)&&e.nativeHostManifests.every((t)=>Qn(He(t),e.nativeHost))}function ts(e){return`#!/bin/sh
|
|
73
|
-
# Reason's Chrome extension host (reason desktop install): Open Browser Use on Reason's socket directory.
|
|
74
|
-
obu=${`'${e.replaceAll("'","'\\''")}'`}
|
|
75
|
-
case "$1" in
|
|
76
|
-
chrome-extension://*) exec "$obu" host --socket-dir ${Ft} ;;
|
|
77
|
-
mcp) shift; exec "$obu" mcp --socket-dir ${Ft} "$@" ;;
|
|
78
|
-
esac
|
|
79
|
-
exec "$obu" "$@"
|
|
80
|
-
`}function ns(e){let t=He(e),n=t?.allowed_origins;return t!==null&&t.name===It&&t.type==="stdio"&&Array.isArray(n)&&n.includes(`chrome-extension://${We}/`)&&typeof t.path==="string"&&Tt(t.path)}function ss(e,t){if(!e.userChromeHost||!e.userChromeRegistration)return null;if(!t||Kn(e.userChromeHost)!==ts(e.nativeHost)||!Tt(e.userChromeHost))return{code:"user_chrome_browser_use_missing"};return ns(e.userChromeRegistration)?{host:e.userChromeHost}:{code:"user_chrome_native_host_unregistered"}}var rs={display:["display","desktop_session","desktop_video"],computer:["display","desktop_session","system_packages","node","open_computer_use"],browser:["display","desktop_session","system_packages","node","open_computer_use","open_browser_use","browser_extension","browser","chrome_for_testing"]};function x(e={}){let t=e.platform===void 0?Gn():e.platform;if(!t)return null;let n=Tr(t,e.home),o=Wn(n.receipt),s=Vn(t),i=o!==null&&o.platform===t&&JSON.stringify(Object.entries(o.pins).sort())===JSON.stringify(Object.entries(s).sort()),a=[],d=de(t);for(let c of["node","open_computer_use","open_browser_use","chrome_for_testing"]){let _=d[c];if(!_)continue;let v=qn(c,b(n.root,c,_.version),t),D=o?.pins[c],L=v&&D===s[c]?"ready":D!==void 0&&D!==s[c]?"outdated":"missing";a.push({name:c,state:L,detail:_.version})}let y=o?.pins.extension===F&&es(n);a.push({name:"browser_extension",state:y?"ready":"missing",detail:F});let h=U("Xvfb"),g=U("x11vnc"),p=U("openbox");if(K(t))a.push(yt()?{name:"desktop_session",state:"ready",detail:"signed-in desktop session"}:{name:"desktop_session",state:"missing",detail:"run the worker in the signed-in desktop session, not as a service"}),a.push(n.ffmpeg&&A(n.ffmpeg)?{name:"desktop_video",state:"ready",detail:n.ffmpeg}:{name:"desktop_video",state:"missing",detail:"run `reason desktop install` for desktop video"});else if(t!=="darwin-arm64"){a.push(A(ce)?{name:"browser",state:"ready",detail:ce}:{name:"browser",state:"missing",detail:`non-snap Chromium at ${ce}`});let c=h!==null&&g!==null&&p!==null;a.push({name:"display",state:c?"ready":"missing",detail:"Xvfb + openbox + x11vnc"});let _=Hn.filter((P)=>U(P)===null),v=(o?.missing_system_packages??kt).filter((P)=>kt.includes(P)),D=_.length===0&&v.length===0;a.push(D?{name:"system_packages",state:"ready"}:{name:"system_packages",state:"missing",detail:[...new Set([...v,..._])].join(" ")});let L=Ue.filter((P)=>U(P)===null);a.push(L.length===0?{name:"desktop_look",state:"ready"}:{name:"desktop_look",state:"missing",detail:L.join(" ")})}let w=n.ffmpeg&&A(n.ffmpeg)?n.ffmpeg:U("ffmpeg"),f=!w?null:w===n.ffmpeg?n.ffprobe:b(vt(En(w)),"ffprobe"),M=i&&a.every((c)=>c.state==="ready"),E=(c)=>i&&a.every((_)=>!rs[c].includes(_.name)||_.state==="ready");return{platform:t,root:n.root,automation:n.automation,ready:M,features:{display:E("display"),computer:E("computer"),browser:E("browser")},node:n.node,ocu:n.ocu,obu:n.obu,nativeHost:n.nativeHost,extensionDir:n.extensionDir,browser:n.browser,ffmpeg:w,ffprobe:f&&A(f)?f:null,userChrome:ss(n,i&&["node","open_browser_use"].every((c)=>a.find((_)=>_.name===c)?.state==="ready")),pulseaudio:U("pulseaudio"),xvnc:U("Xvnc"),xvfb:h,x11vnc:g,openbox:p,components:a}}function Ot(e){return os(e)?Yn():[]}function os(e){return e?.platform==="darwin-arm64"&&e.ffmpeg===b(e.root,"ffmpeg",W.version,"ffmpeg")}async function ho(e,t,n,o=fetch){try{let s=await o(e,{redirect:"follow"});if(!s.ok||!s.body)throw Error(`download failed (HTTP ${s.status}): ${e}`);let i=St("sha256"),a=vn(n,{mode:384});try{let y=s.body.getReader();for(let h=await y.read();!h.done;h=await y.read())if(i.update(h.value),!a.write(h.value))await Sn(a,"drain")}finally{a.end(),await Cn(a)}let d=i.digest("hex");if(d!==t)throw Error(`digest mismatch for ${e}: expected ${t}, got ${d}`)}catch(s){throw Pn(n,{force:!0}),s}}function is(e){return b(Mt(e),"minimal.json")}import{spawn as as}from"child_process";import{existsSync as cs}from"fs";import{connect as us}from"net";import{join as pe}from"path";var $t="reason_desktop",Q={sampleRate:48000,channels:2,codec:"opus"},ls=5000,ds=107,ps=262144,On=(e)=>pe(e,"native"),Ve=(e)=>`unix:${e}`;function Fe(e,t=1000){if(!cs(e))return Promise.resolve(!1);return new Promise((n)=>{let o=us({path:e}),s=(i)=>{o.destroy(),n(i)};o.setTimeout(t,()=>s(!1)),o.once("error",()=>s(!1)),o.once("close",()=>s(!1)),o.once("connect",()=>s(!0))})}async function po(e,t){if(!t)return null;let n=On(e);if(Buffer.byteLength(n)>ds||/["'\\\s]/.test(n))return null;try{if(await Fe(n))return n;let o=as(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:${pe(e,"pulseaudio.log")}`,"-n",`--load=module-native-protocol-unix socket="${n}" auth-anonymous=1 auth-cookie-enabled=0`,`--load=module-null-sink sink_name=${$t} rate=${Q.sampleRate} channels=${Q.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:pe(e,"runtime"),PULSE_STATE_PATH:pe(e,"state")}}),s=!1;o.once("error",()=>{s=!0}),o.once("exit",()=>{s=!0}),o.unref();let i=Date.now()+ls;while(Date.now()<i){if(await Fe(n))return n;if(s)return await Fe(n)?n:null;await new Promise((a)=>setTimeout(a,50))}if(!s)o.kill("SIGKILL");return null}catch{return null}}function Lt(){let{sampleRate:e,channels:t}=Q;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",`${$t}.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 fs=[79,103,103,83],ms=Buffer.from("OpusHead"),gs=Buffer.from("OpusTags"),At=(e,t)=>e.byteLength>=t.byteLength&&t.every((n,o)=>e[o]===n);class ze extends Error{constructor(e){super(e);this.name="OggProtocolError"}}class je{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 n=[],o=0;while(t.byteLength-o>=27){if(fs.some((w,f)=>t[o+f]!==w)||t[o+4]!==0)throw new ze("invalid_page");let s=(t[o+5]&1)!==0,i=t[o+26];if(t.byteLength-o<27+i)break;let a=t.subarray(o+27,o+27+i),d=a.reduce((w,f)=>w+f,0),y=27+i+d;if(t.byteLength-o<y)break;if(!s&&this.partialBytes>0)this.resetPartial();let h=s&&this.partialBytes===0,g=o+27+i,p=g;for(let w of a){if(g+=w,w===255)continue;if(this.appendPartial(t.subarray(p,g),h),p=g,!h){let f=this.takePartial();if(f.byteLength>0&&!At(f,ms)&&!At(f,gs))n.push(f)}h=!1,this.resetPartial()}if(p<g)this.appendPartial(t.subarray(p,g),h);o+=y}return this.buffer=t.slice(o),n}appendPartial(e,t){if(t||e.byteLength===0)return;if(this.partialBytes+=e.byteLength,this.partialBytes>ps)throw new ze("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 n of this.partial)e.set(n,t),t+=n.byteLength;return e}resetPartial(){this.partial=[],this.partialBytes=0}}import{spawn as hs}from"child_process";var Nt=1048576,bs=String.raw`
|
|
81
|
-
import gi, json, os, sys
|
|
82
|
-
gi.require_version("Gtk", "3.0")
|
|
83
|
-
from gi.repository import Gtk, Gdk, GLib
|
|
84
|
-
if not Gtk.init_check()[0]:
|
|
85
|
-
sys.exit(1)
|
|
86
|
-
clipboard = Gtk.Clipboard.get(Gdk.SELECTION_CLIPBOARD)
|
|
87
|
-
pending = b""
|
|
88
|
-
generation = 0
|
|
89
|
-
def send(value):
|
|
90
|
-
print(json.dumps(value, ensure_ascii=True), flush=True)
|
|
91
|
-
def changed(clipboard, event):
|
|
92
|
-
global generation
|
|
93
|
-
generation += 1
|
|
94
|
-
current = generation
|
|
95
|
-
def received(clipboard, text, unused):
|
|
96
|
-
if current == generation and text is not None and len(text.encode("utf-8")) <= ${S}:
|
|
97
|
-
send({"text": text})
|
|
98
|
-
clipboard.request_text(received, None)
|
|
99
|
-
# No request_text on startup: never share the pre-existing clipboard.
|
|
100
|
-
clipboard.connect("owner-change", changed)
|
|
101
|
-
def input_ready(fd, condition):
|
|
102
|
-
global pending
|
|
103
|
-
chunk = os.read(fd, 65536)
|
|
104
|
-
if not chunk:
|
|
105
|
-
Gtk.main_quit()
|
|
106
|
-
return False
|
|
107
|
-
pending += chunk
|
|
108
|
-
while b"\n" in pending:
|
|
109
|
-
line, pending = pending.split(b"\n", 1)
|
|
110
|
-
text = json.loads(line)
|
|
111
|
-
if not isinstance(text, str) or len(text.encode("utf-8")) > ${S} or "\x00" in text:
|
|
112
|
-
sys.exit(1)
|
|
113
|
-
clipboard.set_text(text, -1)
|
|
114
|
-
send("ack")
|
|
115
|
-
if len(pending) > ${S*6+2}:
|
|
116
|
-
sys.exit(1)
|
|
117
|
-
return True
|
|
118
|
-
GLib.io_add_watch(0, GLib.IO_IN | GLib.IO_HUP, input_ready)
|
|
119
|
-
send("ready")
|
|
120
|
-
Gtk.main()
|
|
121
|
-
`;function Ut(e,t){let n=hs("/usr/bin/python3",["-I","-u","-c",bs],{env:{DISPLAY:e.display,XAUTHORITY:e.xauthority},stdio:["pipe","pipe","ignore"]}),o=!1,s=!0,i="",a=0,d=[],y=setTimeout(()=>g(),5000),h=()=>{o=!0,clearTimeout(y),d.length=0,n.kill("SIGKILL")},g=()=>{if(o)return;h(),t.end({error:new r("display_unavailable","Reason could not start this Linux desktop's UTF-8 clipboard.")})},p=(w,f=32)=>{if(o)return;if(!s){w();return}if(a+=f,a>Nt)h(),t.end({reason:"input_backpressure"});else d.push({apply:w,bytes:f})};return n.stdout.on("data",(w)=>{if(o)return;i+=w.toString("ascii");for(let f=i.indexOf(`
|
|
122
|
-
`);f>=0;f=i.indexOf(`
|
|
123
|
-
`)){let M=i.slice(0,f);i=i.slice(f+1);let E;try{E=JSON.parse(M)}catch{g();return}if(E==="ready"||E==="ack"){clearTimeout(y),s=!1;while(!s&&!o&&d.length){let c=d.shift();a-=c.bytes,c.apply()}}else if(E&&typeof E==="object"&&"text"in E&&typeof E.text==="string"&&Buffer.byteLength(E.text)<=S)t.clipboard(E.text);else{g();return}if(o)return}if(i.length>S*6+32)g()}),n.stdin.on("error",g),n.once("error",g),n.once("exit",g),{apply:p,write(w){if(Buffer.byteLength(w)>S||w.includes("\x00")){g();return}let f=`${JSON.stringify(w)}
|
|
124
|
-
`;p(()=>{if(s=!0,y=setTimeout(()=>g(),5000),n.stdin.write(f),n.stdin.writableLength>Nt)h(),t.end({reason:"input_backpressure"})},Buffer.byteLength(f))},close:h}}var X={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}},_s="avc1.4D002A",Bt={width:1920,height:1080},ks=262144,Ss=0.2,vs=250,Es=1e4,Ds=1024,Ke=1e4,Is=500,Ps=60,Cs=1e4,Rs=1000,Ht=1048576,Ms=-223,Ts=-308,In={kind:"mac_screen",sound:null},Dn={kind:"windows_screen",sound:null},Os,jt=()=>Os??=x()?.ffmpeg??null,me=(e,t,n)=>qe(e,t,{env:n,stdio:["ignore","pipe","ignore"],windowsHide:!0}),As,Ye=()=>As??=Ot(x()),Gt=(e,t,n)=>{let[o,...s]=[...Ye(),e];return me(o,[...s,...t],n)},Vt=()=>nn?.videotoolbox?"h264_videotoolbox":"libx264",$s=()=>Math.round(performance.now()*1000),Xe=new Set,Wt=!1;function Jt(e){if(Xe.add(e),e.once("exit",()=>Xe.delete(e)),Wt)return;Wt=!0,process.once("exit",()=>{for(let t of Xe)try{t.kill("SIGKILL")}catch{}})}function Zt(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{}},Is);e.once("exit",()=>clearTimeout(t))}function Ls(e,t,n){return{args:["-f","x11grab","-draw_mouse","1","-framerate",String(e),"-video_size",`${t.width}x${t.height}`,"-i",n],size:t}}function Ns(e){return{args:["-f","avfoundation","-capture_cursor","1","-pixel_format","nv12","-framerate",String(e),"-i","Capture screen 0:none"],size:null}}function Us(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 Bs(e){return{args:["-probesize","32","-analyzeduration","0","-f","image2pipe","-c:v","mjpeg","-framerate",String(e),"-i","pipe:0"],size:null}}var Qt=1700000;function en(e){return Math.min(1,Math.round(Math.sqrt(Qt/(e.width*e.height))*100)/100)}function Hs(e,t,n){let o=qe(n.axe,["stream-video","--udid",n.udid,"--format","ffmpeg","--fps","30","--quality","85","--scale",String(Math.min(0.99,en(n.size)))],{stdio:["ignore","pipe","ignore"]}),s=qe(e,t,{env:{},stdio:["pipe","pipe","ignore"]});o.stdout.pipe(s.stdin),s.stdin.on("error",()=>{});let i=()=>{if(o.exitCode===null&&o.signalCode===null)o.kill("SIGTERM")};return s.once("exit",i),s.once("error",i),o.once("exit",()=>{if(s.exitCode===null&&s.signalCode===null)s.kill("SIGTERM")}),o.once("error",()=>{if(s.exitCode===null&&s.signalCode===null)s.kill("SIGTERM")}),s}function Kt(e){let t=Math.min(1,Bt.width/e.width,Bt.height/e.height);return{width:Math.round(e.width*t),height:Math.round(e.height*t)}}function fe(e,t,n,o="libx264"){let s=X[e],i=(p)=>Math.max(2,Math.floor(p/2)*2),a={width:i(n.width*s.scale),height:i(n.height*s.scale)},d=a.width!==t.size?.width||a.height!==t.size.height,y=Math.max(1,Math.round(s.kbps*2/s.fps)),h=["-g",String(s.fps*Ps)],g=o==="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",...h,"-b:v",`${s.kbps}k`,"-maxrate",`${s.kbps}k`,"-bufsize",`${y}k`,"-bsf:v","h264_metadata=aud=insert"]:["-c:v","libx264","-preset",s.x264Preset,"-tune","zerolatency","-profile:v","main","-level","4.2","-bf","0","-pix_fmt","yuv420p",...s.threads?["-threads",String(s.threads)]:[],"-x264-params","aud=1:repeat-headers=1",...h,"-crf",String(s.crf),"-maxrate",`${s.kbps}k`,"-bufsize",`${y}k`];return["-hide_banner","-loglevel","error","-nostdin","-fflags","nobuffer",...t.args,"-an",...d?["-vf",`scale=${a.width}:${a.height}:flags=fast_bilinear`]:[],...g,"-flush_packets","1","-f","h264","pipe:1"]}class tn{buffer=new Uint8Array(0);scanned=0;key=!1;micros=0;push(e,t){if(this.buffer.byteLength===0)this.micros=t;let n=new Uint8Array(this.buffer.byteLength+e.byteLength);n.set(this.buffer),n.set(e,this.buffer.byteLength),this.buffer=n;let o=[],s=this.scanned;while(s+3<this.buffer.byteLength){if(this.buffer[s]!==0||this.buffer[s+1]!==0||this.buffer[s+2]!==1){s++;continue}let i=this.buffer[s+3]&31,a=s>0&&this.buffer[s-1]===0?s-1:s;if(i===9&&a>0)o.push({data:this.buffer.slice(0,a),key:this.key,micros:this.micros}),this.buffer=this.buffer.subarray(a),this.key=!1,this.micros=t,s-=a;if(i===5)this.key=!0;s+=3}return this.scanned=s,o}}function Fs(e,t){let n=xs({path:e}),o=Buffer.alloc(0),s="version",i=0,a=!1,d=[],y=0,h=!1,g=(c)=>{if(h)return;h=!0,n.destroy(),t.end(c)},p=()=>g({reason:"display_protocol"}),w=(c)=>{if(h)return;if(!a){if(y+=c.byteLength,y>Ht)g({reason:"input_backpressure"});else d.push(c);return}if(n.write(c),n.writableLength>Ht)g({reason:"input_backpressure"})},f=(c)=>{o=o.subarray(c)},M=()=>{switch(s){case"version":{if(o.byteLength<12)return!1;let c=/^RFB (\d{3})\.(\d{3})\n$/.exec(o.subarray(0,12).toString("latin1"));if(!c||Number(c[1])*1000+Number(c[2])<3007)return p(),!1;return f(12),n.write(`RFB 003.007
|
|
125
|
-
`),s="security",!0}case"security":{if(o.byteLength<1)return!1;let c=o[0];if(c===0)return p(),!1;if(o.byteLength<1+c)return!1;if(!o.subarray(1,1+c).includes(1))return p(),!1;return f(1+c),n.write(Buffer.from([1,1])),s="init",!0}case"init":{if(o.byteLength<24)return!1;let c=o.readUInt32BE(20);if(c>65536)return p(),!1;if(o.byteLength<24+c)return!1;let _={width:o.readUInt16BE(0),height:o.readUInt16BE(2)};if(f(24+c),_.width===0||_.height===0)return p(),!1;s="messages";let v=Buffer.alloc(12);v.writeUInt8(2,0),v.writeUInt16BE(2,2),v.writeInt32BE(Ts,4),v.writeInt32BE(Ms,8),n.write(v),a=!0;for(let D of d)n.write(D);return d=[],y=0,t.ready(_),!h}case"skip":{let c=Math.min(i,o.byteLength);if(f(c),i-=c,i>0)return!1;return s="messages",!0}case"messages":{if(o.byteLength<1)return!1;switch(o[0]){case 1:{if(o.byteLength<6)return!1;let c=6+o.readUInt16BE(4)*6;if(o.byteLength<c)return!1;return f(c),!0}case 2:return f(1),!0;case 3:{if(o.byteLength<8)return!1;let c=o.readUInt32BE(4);if(c>S/2)return f(8),s="skip",i=c,!0;if(o.byteLength<8+c)return!1;let _=o.subarray(8,8+c).toString("latin1");return f(8+c),t.clipboard(_),!h}default:return p(),!1}}}},E=!1;return n.once("connect",()=>{E=!0}),n.on("data",(c)=>{if(h)return;o=o.byteLength?Buffer.concat([o,c]):c;while(!h&&M());}),n.once("error",()=>{if(!E)g({error:new r("display_unavailable","Reason could not reach this machine's desktop server.")})}),n.once("close",()=>g({reason:"display_closed"})),{pointer(c,_,v){let D=Buffer.alloc(6);D.writeUInt8(5,0),D.writeUInt8(v&255,1),D.writeUInt16BE(c,2),D.writeUInt16BE(_,4),w(D)},key(c,_){let v=Buffer.alloc(8);v.writeUInt8(4,0),v.writeUInt8(c?1:0,1),v.writeUInt32BE(_>>>0,4),w(v)},clipboard(c){if(Array.from(c).some((D)=>D.codePointAt(0)>255)){g({reason:"clipboard_unicode_unsupported"});return}let _=Buffer.from(c,"latin1"),v=Buffer.alloc(8);v.writeUInt8(6,0),v.writeUInt32BE(_.byteLength,4),w(Buffer.concat([v,_]))},close(){h=!0,n.destroy()}}}class Je{run=null;viewers=new Set;get running(){return this.run!==null}start(e,t,n,o){this.viewers.add(e),this.stop();let s;try{s=n()}catch{this.fail();return}Jt(s);let i={child:s,splitter:new tn};this.run=i;for(let d of[...this.viewers])d.started(t);s.stdout?.on("data",(d)=>{if(this.run!==i)return;for(let y of i.splitter.push(d,o()))for(let h of[...this.viewers])h.unit(y)});let a=()=>{if(this.run!==i)return;this.run=null,this.fail()};s.once("exit",a),s.once("error",a)}leave(e){if(!this.viewers.delete(e))return;if(this.viewers.size===0)this.stop()}stop(){if(!this.run)return;Zt(this.run.child),this.run=null}fail(){for(let e of[...this.viewers])e.failed()}}var Xt=new WeakMap;function zs(e){let t=Xt.get(e);if(!t)Xt.set(e,t=new Je);return t}var ee=new Map;function Nn(e,t,n={}){let o=n.micros??$s,s=new Bn,i=t.request.preset,a=null,d=null,y=null,h=!1,g=null,p=!1,w=!1,f=null,M=0,E=0,c=!1,_=null,v=null,D=0,L=null,P=[],te=0,N=[],Ze=new Uint32Array(Ke+1),ge=0,he=null,be=0,q=0,ye=0,Qe=0,et=0,ne=null,we=0,j={frames:0,bytes:0,since:o()},G=[],Y=0,xe,_e=!1,rn=o(),R={},V=()=>Math.round((o()-rn)/1000),tt=n.control??ut,ke=null,Se=null,nt=0,ve=!1,st={pause(){if(!g?.running)return;g.stop(),ve=!0},adopt(u){let l=u!==null&&(u.width!==d?.width||u.height!==d?.height);if(l)d=u;if(!l&&!ve)return;if(ve=!1,g)ae();else Ie()}},on=(u)=>{if(!n.resizeDesktop||!a||"kind"in a||e.done)return;let l=a.display,m=()=>[...ee.get(l)??[]];nt++,n.resizeDesktop(a,u,()=>{for(let k of m())k.pause()}).then((k)=>{for(let I of m())I.adopt(k)})},T=(u)=>{let l=zt(u);return e.send(l),Qe+=l.byteLength,l.byteLength},se=(u)=>{if(e.done)return;if(e.open)T({type:"error",code:u});e.end({reason:u})},re=()=>Math.max(ks,X[i].kbps*1000/8*Ss),oe=()=>o()/1000,an=()=>{while(N.length>1&&N[0].atMs<oe()-Es)N.shift();return N[0]?.rttMs??null},rt=(u)=>{let l=an();if(l===null||P.length===0)return!1;let m=(l+vs)*u;return oe()-P[0].sentMs>m||te>m/1000*X[i].kbps*1000/8},cn=(u)=>{if(D===0)return;let l=Math.min(u,D-1);if(L!==null&&l<=L)return;L=l;let m=oe();while(P.length&&P[0].seq<=l){let k=P.shift();if(te-=k.bytes,k.seq!==l)continue;let I=Math.max(0,m-k.sentMs);while(N.length&&N.at(-1).rttMs>=I)N.pop();N.push({atMs:m,rttMs:I}),Ze[Math.min(Ke,Math.round(I))]++,ge++,he=Math.min(he??I,I)}},un=()=>{let u=0;for(let l=0;l<=Ke;l++)if(u+=Ze[l],u*2>=ge)return l;return 0},ln=()=>e.bufferedAmount<=re()/2&&!rt(0.5),ot=()=>{_e=!0,G=[],Y=0,g?.leave(Ee),g=null},it=(u)=>{if(e.done)return;if(u.key)R.first_key_ms??=V();if(!h){if(!g||G.length===0&&!u.key)return;if(G.push(u),Y+=u.data.byteLength,Y>re())ot();return}if(c){q++;return}if(e.bufferedAmount>re()||rt(1)){c=!0,q++,_=setInterval(()=>{if(e.done||!ln())return;if(_)clearInterval(_);_=null,c=!1,ae()},n.drainPollMs??25);return}if(!p){if(!u.key){q++;return}if(T({type:"hello",width:d.width,height:d.height,fps:X[i].fps,preset:i,codec:_s}),p=!0,R.first_frame_ms??=V(),!w&&a?.sound)T({type:"audioHello",...Q}),w=!0}let l=T({type:"frame",key:u.key,seq:D,captureMicros:u.micros,data:u.data});if(P.push({seq:D,sentMs:oe(),bytes:l}),te+=l,P.length>Ds)te-=P.shift().bytes;D++,be++,ne??=u.micros,we=u.micros,j.frames++,j.bytes+=l},Ee={started(u){i=u,p=!1,G=[],Y=0},unit:it,failed:()=>se("encoder_failed")},De=()=>{let u=(n.ffmpeg??jt)();if(!a||!d){se("encoder_failed");return}let[l,m]=[a,d],k="kind"in l&&l.kind==="simulator"?l.stream:null;if(!u&&!k){se("encoder_failed");return}if(g??="kind"in l&&l.kind==="mac_screen"?zs(n.spawn??Gt):new Je,R.encoder_ms===void 0)R.encoder_ms=V(),R.encoder_shared=g.running;g.start(Ee,i,()=>{let I=X[i].fps;if(k)return k(I,X[i].kbps,Qt);if("kind"in l&&l.kind==="simulator"){let C=Math.min(0.99,en(l.size)),B={width:l.size.width*C,height:l.size.height*C};return Hs(u,fe(i,Bs(Math.min(I,30)),B,(n.macEncoder??Vt)()),l)}if("kind"in l&&l.kind==="windows_screen")return(n.spawn??me)(u,fe(i,Us(I,m),Kt(m)),{SystemRoot:process.env.SystemRoot??"C:\\Windows"});return"kind"in l?(n.spawn??Gt)(u,fe(i,Ns(I),Kt(m),(n.macEncoder??Vt)()),{}):(n.spawn??me)(u,fe(i,Ls(I,m,l.display),m),{DISPLAY:l.display,XAUTHORITY:l.xauthority})},o)},ie=()=>{if(!f)return;Zt(f.child),f=null},dn=()=>{let u=(n.ffmpeg??jt)();if(f||e.done||!w||!a?.sound||!u)return;let l;try{l=(n.spawn??me)(u,Lt(),{PULSE_SERVER:Ve(a.sound)})}catch{return}Jt(l);let m={child:l,reader:new je};f=m,l.stdout?.on("data",(I)=>{if(f!==m||e.done)return;let C;try{C=m.reader.push(I)}catch{ie();return}let B=o();for(let Ce of C){if(e.bufferedAmount>re()){E++;continue}T({type:"audio",captureMicros:B,data:Ce}),M++}});let k=()=>{if(f===m)ie()};l.once("exit",k),l.once("error",k)},ae=()=>{if(!g||e.done)return;ye++,De()},Ie=()=>{if(e.done||!d)return;if(!h){if(g||_e)return;De(),xe=setTimeout(()=>{if(!h)ot()},Cs);return}if(clearTimeout(xe),R.encoder_early===void 0){if(R.encoder_early=g!==null,_e)R.hold_lapsed=!0}if(!g)De();let u=G;G=[],Y=0;for(let l of u)it(l);v??=setInterval(()=>{let l=o(),m=Math.max(0.001,(l-j.since)/1e6);T({type:"stats",stats:{fps:Math.round(j.frames/m*10)/10,kbps:Math.round(j.bytes*8/1000/m),dropped:q,restarts:ye,queued_bytes:e.bufferedAmount}}),j={frames:0,bytes:0,since:l}},Rs)};t.desktop.then((u)=>{if(e.done)return;a=u;let l={ready(m){d=m,R.desktop_ms??=V(),Ie()},clipboard(m){if(e.open&&Buffer.byteLength(m)<=S)T({type:"serverClipboard",text:m})},end(m){if("reason"in m&&e.open)T({type:"error",code:m.reason});e.end(m)}};if("kind"in u&&u.kind==="simulator")y=u.input,l.ready(u.points);else if("kind"in u&&u.kind==="windows_screen")y=(n.windowsInput??xt)(l);else if("kind"in u)y=(n.macInput??((m)=>jn(m,Ye())))(l);else{let m=ee.get(u.display);if(!m)ee.set(u.display,m=new Set);m.add(st);let k=(n.linuxClipboard??Ut)(u,l),I=Fs(u.rfbSocket,{...l,clipboard:(C)=>{if(!k)l.clipboard(C)}});y=k?{pointer:(C,B,Ce)=>k.apply(()=>I.pointer(C,B,Ce)),key:(C,B)=>k.apply(()=>I.key(C,B)),clipboard:(C)=>k.write(C),close(){k.close(),I.close()}}:I}at()},(u)=>e.end({error:u}));function at(){if(Se||!t.viewerSameNetwork||!h||e.done||!a||!("kind"in a)||a.kind!=="mac_screen")return;Se=(n.macWindows??Fn)((u)=>{if(e.open)T({type:"windows",bounds:u})})}let ct={viewer:t.viewer??null,notify(u){if(e.open)T({type:"control",control:u})}},Pe=(u)=>{if(!y)return;if(!a||!("kind"in a)||a.kind!=="simulator")tt.claim(ct);u(y)};return{opened(){R.relay_ms??=V()},received(u){et+=u.byteLength;let l;try{l=s.push(u)}catch{se("viewer_protocol");return}for(let m of l){if(e.done)return;switch(m.type){case"ping":T({type:"pong",token:m.token});break;case"pointer":Pe((k)=>k.pointer(m.x,m.y,m.buttons));break;case"key":Pe((k)=>k.key(m.down,m.keysym));break;case"clientClipboard":Pe((k)=>k.clipboard(m.text));break;case"config":if(m.preset!==i)i=m.preset,ae();break;case"keyframeRequest":if(p&&!c)ae();break;case"ack":cn(m.seq);break;case"audioEnable":if(m.on)dn();else ie();break;case"resize":on({width:m.width,height:m.height});break;default:break}}if(!h&&!e.done){if(h=!0,R.viewer_ms=V(),t.viewer)ke=tt.join(ct);Ie(),at()}},close(){if(a&&!("kind"in a)){let u=ee.get(a.display);if(u?.delete(st),u?.size===0)ee.delete(a.display)}if(ke?.(),ke=null,Se?.close(),_)clearInterval(_);if(v)clearInterval(v);clearTimeout(xe),g?.leave(Ee),ie(),y?.close()},summary:()=>({output_bytes:Qe,input_bytes:et,video:{preset:i,frames:be,dropped:q,restarts:ye,avg_fps:ne!==null&&we>ne?Math.round((be-1)/((we-ne)/1e6)*10)/10:0,min_rtt_ms:Math.round(he??0),p50_rtt_ms:ge?un():0,audio_packets:M,audio_dropped:E,resizes:nt,connect:R}})}}var qt=null,nn=null,js=null,Gs=null;function Vs(){let e=x();return e?.features.display?e.ffmpeg:null}function sn(e){return qt??=new Promise((t)=>{ys(e,["-hide_banner","-encoders"],{env:{},timeout:5000,killSignal:"SIGKILL",maxBuffer:1048576,encoding:"utf8"},(n,o)=>{let s=(i)=>!n&&new RegExp(`^\\s*V\\S*\\s+${i}\\s`,"m").test(o);t(nn={x264:s("libx264"),videotoolbox:s("h264_videotoolbox")})})}),qt}var Yt=null;function Ln(){return Yt??=(async()=>{let e=[x()?.ffmpeg,"/opt/homebrew/bin/ffmpeg","/usr/local/bin/ffmpeg"].find((n)=>Boolean(n&&ws(n)));if(!e)return null;let t=await sn(e);return t.videotoolbox||t.x264?e:null})(),Yt}function Pr(e=process.platform,t={}){if(e!=="linux"&&e!=="darwin"&&e!=="win32")return Promise.resolve(!1);let n=(t.ffmpeg??Vs)();if(!n)return Promise.resolve(!1);let o=(t.encoders??sn)(n);if(e==="linux")return o.then((i)=>i.x264);if(e==="win32"){let i=t.windowsScreen?t.windowsScreen():Gs??=bt();return Promise.all([o,i]).then(([a,d])=>a.x264&&(d?.session??0)>0)}let s=t.macScreen?t.macScreen():js??=Ge(Ye());return Promise.all([o,s]).then(([i,a])=>(i.x264||i.videotoolbox)&&a?.screen===!0&&a.accessibility)}
|
|
126
|
-
export{We,uo,F,On,Ve,po,In,Dn,Nn,Ln,Pr,Ft,Tr,x,ho};
|
|
@@ -1,4 +0,0 @@
|
|
|
1
|
-
// @bun
|
|
2
|
-
import{a}from"./vm-hands-entry-lite-swrymqj9.js";import{readFileSync as c}from"fs";import{isAbsolute as l,normalize as i}from"path";var m="REASON_WORKER_DESKTOP_USER",u=null;function p(t,o){for(let s of o.split(`
|
|
3
|
-
`)){let e=s.split(":");if(e.length<7||Number(e[2])!==t||!/^\d+$/.test(e[2])||!/^\d+$/.test(e[3]))continue;let n=e[5];if(!/^[a-z_][a-z0-9_-]*$/i.test(e[0])||!l(n)||i(n)!==n||n==="/")return null;return{username:e[0],uid:t,gid:Number(e[3]),home:n}}return null}function Fs(t={}){let o="value"in t?t.value:process.env[m];if(u=null,o===void 0||o==="")return null;let s=t.platform??process.platform,e="euid"in t?t.euid:process.geteuid?.(),n=/^[1-9]\d{0,9}$/.test(o)?Number(o):NaN,r=s==="linux"&&e===0&&Number.isSafeInteger(n)?p(n,(t.passwd??(()=>c("/etc/passwd","utf8")))()):null;if(!r||r.gid===0)throw Error("worker_desktop_user_invalid");return u=r,r}function K(){return u}function Mn(){return u?.home??a()}
|
|
4
|
-
export{Fs,K,Mn};
|
|
@@ -1,3 +0,0 @@
|
|
|
1
|
-
// @bun
|
|
2
|
-
import{statSync as f}from"fs";import{delimiter as l,join as d}from"path";function Nt(e,o=process.env.PATH??"",i=process.env,u=process.platform){let r=u==="win32",a=e.includes("/")||r&&e.includes("\\");if(!e||a||e.includes("\x00"))return!1;let c=r?["",...(i.PATHEXT??".EXE;.CMD;.BAT;.COM").split(";")]:[""];return o.split(l).some((t)=>{if(!t)return!1;return c.some((n)=>{if(n===void 0)return!1;try{let s=f(d(t,`${e}${n}`));if(!s.isFile())return!1;return r||(s.mode&73)!==0}catch{return!1}})})}
|
|
3
|
-
export{Nt};
|
|
@@ -1,3 +0,0 @@
|
|
|
1
|
-
// @bun
|
|
2
|
-
import{T}from"./vm-hands-entry-lite-fcvf8md1.js";import{basename as ln}from"path";var gt=["production","staging"],un="https://api.reasonmachines.com",fn="https://staging-api.reasonmachines.com";var A={production:{api:"https://api.reasonmachines.ai",app:"https://reasonmachines.ai"},staging:{api:"https://staging-api.reasonmachines.ai",app:"https://staging.reasonmachines.ai"}},gn=new Set(["ara-staging","ara-staging.exe","reason-staging","reason-staging.exe"]);function _(n={}){let e=T(n.env??process.env,"REASON_CLI_CHANNEL")?.trim().toLowerCase();if(e){if(gt.includes(e))return e;throw Error(`Unknown Reason CLI channel: ${e}`)}let r=ln(n.executablePath??process.execPath).toLowerCase();return gn.has(r)?"staging":"production"}function er(n){return n==="staging"?fn:un}var U={production:["https://api.ara.so",A.production.api],staging:["https://api-staging.ara.so",A.staging.api]};function Zr(n){let e;try{e=new URL(n).origin}catch{return n}let r=gt.find((t)=>U[t].includes(e));return r?er(r):e}function Do(n,e){return n===e||Zr(n)===Zr(e)}function No(n,e){return gt.some((r)=>U[r].includes(n)&&e===er(r))}function Lo(n,e){try{let r=new URL(e);return!r.username&&!r.password&&(r.origin===er(n)||r.origin===A[n].api)}catch{return!1}}function ri(n){try{let e=new URL(n).hostname.replace(/^\[|\]$/g,"").toLowerCase();return e==="localhost"||e==="127.0.0.1"||e==="::1"}catch{return!1}}import{randomBytes as J}from"crypto";import{chmodSync as q,closeSync as B,constants as bn,linkSync as V,lstatSync as w,mkdirSync as z,openSync as En,readdirSync as L,readFileSync as Wn,readlinkSync as v,renameSync as S,rmdirSync as Q,symlinkSync as N,unlinkSync as d}from"fs";import{createRequire as Nn}from"module";import{constants as Sn}from"os";import{basename as R,join as l,sep as kn}from"path";import{existsSync as O,lstatSync as j,readdirSync as pn,readFileSync as mn,readlinkSync as dn,realpathSync as yn}from"fs";import{join as m,sep as hn}from"path";function G(n,...e){let r=m(n,"ara"),t=m(n,"reason");if(!Xr(r))return m(t,...e);if(!O(t))return m(r,...e);return O(m(r,...e))&&!O(m(t,...e))?m(r,...e):m(t,...e)}function Xr(n){try{let e=j(n);if(!e.isSymbolicLink())return e.isDirectory();return dn(n)!=="reason"&&O(n)}catch{return!1}}function X(n,e=[]){if(!Xr(n))return!1;let r;try{r=[n,...pn(n,{withFileTypes:!0}).filter((t)=>t.isDirectory()).map((t)=>m(n,t.name))]}catch{return!1}return r.some((t)=>["connect","connect-once"].filter((i)=>!e.includes(m(t,i))).some((i)=>{let s=m(t,i,"worker.json");try{j(s)}catch{return!1}try{let a=JSON.parse(mn(s,"utf8"))?.stateDirectory;if(typeof a!=="string")return!0;let c=(o,u)=>o===u||o.startsWith(u+hn);return c(a,n)||c(M(a),M(n))}catch{return!0}}))}function M(n){try{return yn(n)}catch{return n}}var P=new Set(["credentials.json","local-device.json","local-device.revoked.json","local-device.auth-migration.json","local-device.json.registration-pending.json","local-daemon.json","local-daemon.json.workspaces.json","local-root-fingerprint-key.json","instances","workspaces"]),Z=new Set(["local-device.proxy.json"]),Cn=new Set(["local-device.key","local-device.binding"]),W=new Map;function _t(n,e,r){let t=l(n,"ara");if(process.platform==="win32"||/[/\\]\.reason-ssh[/\\][^/\\]+[/\\]installer-home[/\\]\.config$/.test(n))return{state:p(t)?.isDirectory()?"kept":"absent"};return vn(t,l(n,"reason"),{linkAlways:!0,kept:(i)=>X(i,r??[]),native:e===void 0?An:()=>e},r!==void 0)}function ke(n,...e){return _t(n),G(n,...e)}var nn="config_rename_unavailable:busy";function vn(n,e,r,t=!1){let i=t?void 0:W.get(n);if(i)return i;let s;try{s=_n(n,e,r)}catch(a){let c=`config_rename_unavailable:${b(a)??"failed"}`;try{return{state:p(n)?.isDirectory()?"kept":"absent",problem:c}}catch{return{state:"kept",problem:c}}}if(!(s.state==="absent"&&r.linkAlways)&&s.problem!==nn&&!(s.state==="kept"&&!s.problem))W.set(n,s);return s}function _n(n,e,r){wn(e,r.native);let t=!1;for(let i=0;i<8;i+=1){let s=p(n);if(s?.isSymbolicLink())return v(n)===R(e)?{state:t?"renamed":"linked"}:{state:"kept"};if(!s){if(D(e))f(()=>d(e),"ENOENT");if(!(t||r.linkAlways)||!x(e))return{state:"absent"};let o=C(e,"link");N(R(e),o);try{f(()=>S(o,n),"EISDIR","ENOTEMPTY","EEXIST","ENOTDIR")}finally{f(()=>d(o),"ENOENT")}continue}if(!s.isDirectory())return{state:"absent"};if(r.kept(n))return K(e),{state:"kept"};let a=r.native();if(!a)return K(e),{state:"kept",problem:"config_rename_unavailable:no_native"};let c=In(a,n);if(!c)return{state:"kept",problem:nn};try{if(w(n).isSymbolicLink())continue;let o=Rn(a,n,e);if(o)return{state:"kept",problem:o};t=!0}finally{c()}}throw Object.assign(Error("legacy directory rename did not settle"),{code:"unsettled"})}function Rn(n,e,r){let t=p(r);if(!t||D(r)){if(!t)N(R(r),r);try{n.exchange(e,r)}catch(o){if(D(r))f(()=>d(r),"ENOENT");return`config_rename_unavailable:${b(o)??"exchange_failed"}`}return null}if(!t.isDirectory())return"config_rename_unavailable:ENOTDIR";if(t.dev!==w(e).dev)return"config_rename_unavailable:EXDEV";let i=[C(r,"probe"),C(r,"probe")];try{N("a",i[0]),N("b",i[1]),n.exchange(i[0],i[1])}catch(o){return`config_rename_unavailable:${b(o)??"exchange_failed"}`}finally{for(let o of i)f(()=>d(o),"ENOENT")}let s=cn(r);for(let o of Cn){let u=p(l(r,o)),g=p(l(e,o));if(u&&g&&u.ino!==g.ino)z(`${s}-replaced`,{mode:448,recursive:!0}),S(l(r,o),l(`${s}-replaced`,o))}let a={linked:new Map,unitsKept:new Set};rn(e,r,"",a);let c=C(r,"rename");N(R(r),c);try{n.exchange(e,c)}catch(o){return f(()=>d(c),"ENOENT"),`config_rename_unavailable:${b(o)??"exchange_failed"}`}return tn(c,r,a,s),null}function en(n){return n===""||!n.includes(kn)}function rn(n,e,r,t){let i=en(r)&&sn(l(e,r),l(n,r));if(i)t.unitsKept.add(r);for(let s of L(l(n,r))){if(i&&(P.has(s)||Z.has(s)))continue;let a=l(r,s),c=l(n,a),o=l(e,a),u=p(c);if(!u)continue;let g=p(o);if(u.isDirectory()){if(!g)f(()=>z(o,{mode:u.mode&4095}),"EEXIST"),q(o,u.mode&4095);if(x(o))rn(n,e,a,t)}else if(!g){if(u.isSymbolicLink())f(()=>N(v(c),o),"EEXIST");else if(f(()=>V(c,o),"EEXIST","ENOENT"))t.linked.set(a,u.ino)}}}function wn(n,e){let r;try{if(!x(n))return;r=L(n)}catch{return}for(let t of r){let i=/^\.(rename|link|probe|claim)-(\d+)-[0-9a-f]+$/.exec(t);if(!i)continue;let s=l(n,t),a=p(s);if(!a)continue;if(!a.isDirectory()){if(!Y(Number(i[2])))f(()=>d(s),"ENOENT");continue}let c=e(),o=null;if(c){try{o=c.lock(s)}catch{continue}if(!o)continue}else if(Y(Number(i[2])))continue;try{let u=C(n,"claim");if(f(()=>S(s,u),"ENOENT"))tn(u,n,null,cn(n))}finally{o?.()}}}function tn(n,e,r,t){for(let[i,s]of r?.linked??[])if(!p(l(n,i))&&p(l(e,i))?.ino===s)f(()=>d(l(e,i)),"ENOENT");if(on(n,e,"",r),f(()=>Q(n),"ENOTEMPTY","EEXIST"))return;S(n,t),q(t,448)}function on(n,e,r,t){let i=en(r)&&(t?t.unitsKept.has(r):sn(l(e,r),l(n,r)));for(let s of L(l(n,r))){let a=l(r,s),c=l(n,a),o=l(e,a),u=w(c),g=p(o);if(g&&u.ino===g.ino&&u.dev===g.dev){d(c);continue}if(u.isFile()&&g?.isFile()&&t?.linked.get(a)===g.ino){S(c,o);continue}if(i&&(P.has(s)||Z.has(s)))continue;if(!g){if(u.isFile()){if(f(()=>V(c,o),"EEXIST"))d(c)}else f(()=>S(c,o),"EEXIST","ENOTEMPTY");continue}if(u.isDirectory()&&g.isDirectory())on(n,e,a,t),f(()=>Q(c),"ENOTEMPTY","EEXIST")}}function sn(n,e){for(let r of P)if(an(l(n,r),l(e,r)))return!0;return!1}function an(n,e){let r=p(n);if(!r)return!1;let t=p(e);if(!t)return!0;if(r.isDirectory()){if(!t.isDirectory())return!0;return L(n).some((i)=>an(l(n,i),l(e,i)))}if(r.isSymbolicLink())return!t.isSymbolicLink()||v(n)!==v(e);return r.ino!==t.ino||r.dev!==t.dev}function K(n){if(D(n))f(()=>d(n),"ENOENT")}function cn(n){return l(n,`.pre-rename-${new Date().toISOString().replace(/[:.]/g,"-")}-${J(3).toString("hex")}`)}function D(n){try{return w(n).isSymbolicLink()&&v(n)===R(n)}catch{return!1}}function x(n){let e=p(n);return e!==null&&e.isDirectory()}function In(n,e){for(let r=0;r<40;r+=1){let t=n.lock(e);if(t)return t;Atomics.wait(new Int32Array(new SharedArrayBuffer(4)),0,0,50)}return null}function C(n,e){return l(n,`.${e}-${process.pid}-${J(6).toString("hex")}`)}function Y(n){if(n===process.pid)return!1;try{return process.kill(n,0),!0}catch(e){return b(e)==="EPERM"}}function p(n){try{return w(n)}catch(e){if(b(e)==="ENOENT"||b(e)==="ENOTDIR")return null;throw e}}function f(n,...e){try{return n(),!0}catch(r){if(e.includes(b(r)??""))return!1;throw r}}function b(n){return n instanceof Error&&"code"in n&&typeof n.code==="string"?n.code:void 0}var k,On=2,Dn=4,Ln=2,Tn=2,H=-100;function An(){if(k!==void 0)return k;if(k=null,process.platform!=="linux"&&process.platform!=="darwin")return null;let n;try{n=Nn(import.meta.url)("bun:ffi")}catch{return null}let e=process.platform==="darwin",r=e?"__error":"__errno_location",t=e?["/usr/lib/libSystem.B.dylib"]:["libc.so.6",`libc.musl-${process.arch==="arm64"?"aarch64":"x86_64"}.so.1`],{FFIType:i}=n;for(let s of t)try{let a=e?"renamex_np":"renameat2",o=n.dlopen(s,{flock:{args:[i.i32,i.i32],returns:i.i32},[r]:{args:[],returns:i.ptr},[a]:e?{args:[i.ptr,i.ptr,i.u32],returns:i.i32}:{args:[i.i32,i.ptr,i.i32,i.ptr,i.u32],returns:i.i32}}).symbols,u=o[r]();if(u===null)continue;let g=(E)=>{let h=n.read.i32(u),y=Object.entries(Sn.errno).find(([,I])=>I===h)?.[0]??`errno_${h}`;return Object.assign(Error(`${E} failed: ${y}`),{code:y})},F=(E)=>Buffer.from(`${E}\x00`,"utf8");return k={exchange(E,h){let y=F(E),I=F(h);if((e?o[a](n.ptr(y),n.ptr(I),Ln):o[a](H,n.ptr(y),H,n.ptr(I),Tn))!==0)throw g("exchange")},lock(E){let h=En(E,bn.O_RDONLY);if(o.flock(h,On|Dn)===0)return()=>B(h);let y=g("lock");if(B(h),y.code==="EWOULDBLOCK"||y.code==="EAGAIN")return null;throw y}},k}catch{}return null}
|
|
3
|
-
export{gt,_,er,Zr,Do,No,Lo,ri,Xr,_t,ke};
|
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
// @bun
|
|
2
|
-
import{r}from"./vm-hands-entry-lite-qy9xg6em.js";import{Ie,De}from"./vm-hands-entry-lite-87vmbt38.js";import{request as Ce}from"http";import{pipeline as Ne}from"stream";import{constants as te,createBrotliCompress as $e,createGzip as Me}from"zlib";import{WebSocket as U}from"ws";import{randomBytes as Re,timingSafeEqual as Be}from"crypto";import{createServer as Le}from"net";var p={chunk:32768,upload:1048576,total:536870912,streams:16,queued:512,buffered:262144,relayBuffered:8388608,requestMs:30000,lifetimeMs:600000,authorizationMs:2000,window:8};function Z(e){return e!==null&&typeof e==="object"&&!Array.isArray(e)}function L(e,t,n=Number.MAX_SAFE_INTEGER){return typeof e==="number"&&Number.isSafeInteger(e)&&e>=t&&e<=n}function pe(e){return typeof e==="string"&&/^[a-zA-Z0-9_-]{1,160}$/.test(e)}function fe(e,t){let n=Buffer.from(e,"latin1");return Buffer.concat([Buffer.from([n.length]),n,t])}function C(e){if(!Z(e)||Object.keys(e).length!==12||![e.organizationId,e.userId,e.runId,e.deviceId,e.rootId,e.jobId,e.fenceId].every(pe)||!L(e.attachmentRevision,0)||!L(e.grantRevision,1)||!L(e.generation,1)||!L(e.port,1024,65535)||!L(e.expiresAtMs,1))throw Error("preview_binding_invalid");return Object.freeze({...e})}function ze(e,t){return Object.keys(e).every((n)=>e[n]===t[n])}function H(e){if(e.length>4096||!e.startsWith("/")||e.startsWith("//")||/[\\\x00-\x20\x7f#]/.test(e))throw Error("preview_path_invalid");let t=decodeURIComponent(e);if(t.startsWith("//")||/[\\\x00-\x1f\x7f]/.test(t))throw Error("preview_path_invalid");return e}function ue(e){return Array.isArray(e)&&e.length<=64&&e.every((t)=>Array.isArray(t)&&t.length===2&&typeof t[0]==="string"&&/^[a-zA-Z0-9-]{1,80}$/.test(t[0])&&typeof t[1]==="string"&&t[1].length<=4096&&!/[\x00-\x1f\x7f]/.test(t[1]))}function z(e,t=p.chunk){if(e.length>Math.ceil(t/3)*4||!/^(?:[A-Za-z0-9+/]{4})*(?:[A-Za-z0-9+/]{2}==|[A-Za-z0-9+/]{3}=)?$/.test(e))throw Error("preview_data_invalid");let n=Buffer.from(e,"base64");if(n.length>t)throw Error("preview_data_too_large");return n}function me(e){if(Array.isArray(e))return Buffer.concat(e);if(typeof e==="string")return Buffer.from(e,"utf8");if(e instanceof ArrayBuffer)return Buffer.from(e);return e}function ge(e){if(Buffer.byteLength(e)>p.upload*1.4+300000)throw Error("preview_frame_too_large");let t=JSON.parse(e);if(!Z(t))throw Error("preview_frame_invalid");if(t.type==="hello")return{type:"hello",binding:C(t.binding),...L(t.messages,p.chunk,p.upload)?{messages:t.messages}:{},...L(t.window,1,p.window)?{window:t.window}:{},...t.bytes===!0?{bytes:!0}:{}};if(t.type==="refused"&&typeof t.reason==="string"&&/^[a-z_]{1,32}$/.test(t.reason))return{type:"refused",binding:C(t.binding),reason:t.reason};if(!pe(t.id))throw Error("preview_frame_invalid");if(t.type==="end"||t.type==="cancel"||t.type==="credit")return{type:t.type,id:t.id};if(t.type==="ws"&&typeof t.protocol==="string"&&/^[a-zA-Z0-9._-]{0,100}$/.test(t.protocol))return{type:"ws",id:t.id,protocol:t.protocol};if(t.type==="data"&&typeof t.data==="string"&&typeof t.binary==="boolean")return z(t.data,p.upload),{type:"data",id:t.id,data:t.data,binary:t.binary};if(t.type==="head"&&L(t.status,200,599)&&ue(t.headers))return{type:"head",id:t.id,status:t.status,headers:t.headers};if(t.type==="request"&&typeof t.method==="string"&&/^(GET|HEAD|POST|PUT|PATCH|DELETE|OPTIONS)$/.test(t.method)&&typeof t.path==="string"&&ue(t.headers)&&typeof t.body==="string"&&typeof t.upgrade==="boolean")return z(t.body,p.upload),{type:"request",id:t.id,method:t.method,path:H(t.path),headers:t.headers,body:t.body,upgrade:t.upgrade};throw Error("preview_frame_invalid")}function ee(e){let t=[...e],n=new Set(t.filter(([s])=>s.toLowerCase()==="connection").flatMap(([,s])=>s.toLowerCase().split(",").map((i)=>i.trim()))),o=new Set(["authorization","proxy-authorization","cookie","set-cookie","host","origin","referer","connection","upgrade","keep-alive","transfer-encoding","te","trailer","content-length","forwarded","alt-svc","service-worker-allowed","clear-site-data","refresh"]);return t.filter(([s])=>!o.has(s.toLowerCase())&&!n.has(s.toLowerCase())&&!/^(x-forwarded-|x-ara-|sec-websocket-|access-control-)/i.test(s))}async function re(e){let t;try{return await Promise.race([Promise.resolve().then(e).then((n)=>n===!0||(n===!1?!1:void 0),()=>{return}),new Promise((n)=>{t=setTimeout(()=>n(void 0),p.authorizationMs)})])}finally{clearTimeout(t)}}async function Dt(e){return await re(e)===!0}function J(e,t){let n=new URL(e);if(n.username||n.password||n.search||n.hash||!(n.protocol==="wss:"||n.protocol==="ws:"&&["127.0.0.1","[::1]"].includes(n.hostname))||!new RegExp(`^/${t}/[a-zA-Z0-9_-]+/[a-zA-Z0-9_-]{32,}$`).test(n.pathname))throw Error("preview_relay_invalid");return n.href}function ct(e){if(!Z(e)||Object.keys(e).length!==2||typeof e.deviceRelayUrl!=="string")throw Error("preview_open_invalid");return{binding:C(e.binding),deviceRelayUrl:J(e.deviceRelayUrl,"device")}}function so(e){if(!Z(e)||Object.keys(e).length!==1||!("binding"in e))throw Error("preview_close_invalid");return{binding:C(e.binding)}}var be="x-preview-connection";async function he(e,t){if(t.aborted)throw Error("preview_closed");let n=Re(32).toString("base64url"),o=new Set,s=!1,i=Le((c)=>{if(s||t.aborted||o.size>=p.streams*2)return c.destroy();o.add(c);let d=new AbortController;c.once("close",()=>{o.delete(c),d.abort()}),c.on("error",()=>c.destroy()),c.setTimeout(2000,()=>c.destroy());let b=Buffer.alloc(0),m=(g)=>{b=Buffer.concat([b,g]);let w=b.indexOf(`\r
|
|
3
|
-
\r
|
|
4
|
-
`);if(w<0){if(b.length>16384)c.destroy();return}if(c.pause(),c.off("data",m),w>16384||b.length>p.upload+16384)return c.destroy();l(b,w).catch(()=>c.destroy())};c.on("data",m);async function l(g,w){let y=g.subarray(0,w).toString("latin1").split(`\r
|
|
5
|
-
`),_=/^(GET|HEAD|POST|PUT|PATCH|DELETE|OPTIONS) (\S+) HTTP\/1\.1$/.exec(y.shift()??"");if(!_)throw Error("preview_request_invalid");H(_[2]);let k=!1,O=0,T=[];for(let B of y){let S=/^([a-zA-Z0-9-]+):[ \t]*([^\x00-\x08\x0a-\x1f\x7f]*)$/.exec(B);if(!S)throw Error("preview_header_invalid");if(S[1].toLowerCase()===be){O++;let N=Buffer.from(S[2].trim());k=N.length===n.length&&Be(N,Buffer.from(n))}else if(S[1].toLowerCase()!=="host")T.push(B)}if(!k||O!==1||s||d.signal.aborted)throw Error("preview_connection_denied");let v=await e.connect(d.signal);if(s||d.signal.aborted)throw v.destroy(),Error("preview_closed");o.add(v),v.on("error",()=>c.destroy()),v.once("close",()=>{o.delete(v),c.destroy()}),c.once("close",()=>v.destroy()),c.setTimeout(0);let P=[`${_[1]} ${_[2]} HTTP/1.1`,`Host: 127.0.0.1:${v.remotePort}`,...T,"",""].join(`\r
|
|
6
|
-
`);v.write(Buffer.concat([Buffer.from(P,"latin1"),g.subarray(w+4)])),v.pipe(c),c.pipe(v),c.resume()}});await new Promise((c,d)=>{i.once("error",d),i.listen(0,"127.0.0.1",c)});let a=i.address();if(!a||typeof a==="string")throw i.close(),Error("preview_bind_failed");function u(){if(s)return;s=!0,t.removeEventListener("abort",u);for(let c of o)c.destroy();o.clear(),i.close()}if(t.addEventListener("abort",u,{once:!0}),t.aborted)u();return{port:a.port,headers:{[be]:n},close:u}}var Oe=60000,Fe=1e4,He=5000,Ue=/^(?:text\/(?!event-stream)|application\/(?:(?:x-)?javascript|json|[a-z.+-]*\+json|xml|[a-z.+-]*\+xml|wasm)|image\/svg\+xml)/i;function je(e,t,n,o){let s=(c)=>t.find(([d])=>d.toLowerCase()===c)?.[1],i=(c)=>o.find(([d])=>d.toLowerCase()===c)?.[1],a=Number(i("content-length")??Number.NaN);if(e!=="GET"||n!==200||s("range")!==void 0||i("content-encoding")!==void 0||!Ue.test(i("content-type")??"")||/\bno-transform\b/i.test(i("cache-control")??"")||a<1024)return null;let u=(c)=>new RegExp(`(?:^|,)\\s*${c}\\s*(?:,|$|;\\s*q=(?:1|0?\\.0*[1-9]))`,"i").test(s("accept-encoding")??"");return u("br")?"br":u("gzip")?"gzip":null}function qe(e,t){let n=e.filter(([o])=>o.toLowerCase()==="vary").map(([,o])=>o).join(", ");return[...e.filter(([o])=>!["vary","etag","content-md5"].includes(o.toLowerCase())),...e.filter(([o])=>o.toLowerCase()==="etag").map(([o,s])=>[o,s.startsWith("W/")?s:`W/${s}`]),["Content-Encoding",t],["Vary",n.split(",").some((o)=>/^\s*(?:accept-encoding|\*)\s*$/i.test(o))?n:n?`${n}, Accept-Encoding`:"Accept-Encoding"]]}async function xn(e){process.stderr.write(`${JSON.stringify({event:"worker_preview.open_refused",job_id:e.jobId,port:e.port,reason_code:e.reason})}
|
|
7
|
-
`);let t=e.binding,n;try{n=J(e.deviceRelayUrl,"device")}catch{return}if(!t)return;await new Promise((o)=>{let s=new U(n,{followRedirects:!1,perMessageDeflate:!1,maxPayload:4096}),i=setTimeout(()=>{s.terminate(),o()},p.authorizationMs*2);s.addEventListener("open",()=>{s.send(JSON.stringify({type:"refused",binding:t,reason:e.reason})),s.close(1000,`worker_refused_${e.reason}`)}),s.addEventListener("error",()=>{clearTimeout(i),o()}),s.addEventListener("close",()=>{clearTimeout(i),o()})})}async function Ke(e,t){let n=Date.now()+Fe,o;for(;;){if(!t())return"closed";let s=o??=e.refusal().finally(()=>{o=void 0}),i,a=await Promise.race([s.catch(()=>"port_unproved"),new Promise((u)=>{i=setTimeout(()=>u("port_check_timeout"),p.authorizationMs)})]).finally(()=>clearTimeout(i));if(a===null)return null;if(!["listener_unproved","port_check_timeout"].includes(a)||Date.now()+500>=n)return a;await new Promise((u)=>setTimeout(u,500))}}async function _e(e){let t=C(e.binding),n=()=>!e.signal.aborted&&Date.now()<t.expiresAtMs,o=t.expiresAtMs>Date.now()+p.lifetimeMs+He?"binding_mismatch":await Ke(e.port,n);if(o)throw await xn({deviceRelayUrl:e.deviceRelayUrl,binding:t,jobId:t.jobId,port:t.port,reason:o}),Error("preview_not_authorized",{cause:o});let s=J(e.deviceRelayUrl,"device"),i=await he(e.port,e.signal),a;try{a=new U(s,{followRedirects:!1,perMessageDeflate:!1,maxPayload:p.upload*1.4+300000})}catch(f){throw i.close(),f}let u=new Map,c=!1,d=!1,b=0,m=!1,l,g,w,y=new Promise((f)=>{w=f}),_,k,O=new Promise((f,h)=>{_=f,k=h}),T=!1,v=(f)=>{let h=Buffer.isBuffer(f)?f:JSON.stringify(f);if(b+=Buffer.byteLength(h),!n()||d||a.readyState!==U.OPEN)return P(n()?"relay_closed":"expired");if(a.bufferedAmount>p.relayBuffered)return P("relay_backlog");if(b>p.total)return P("quota");a.send(h)};function P(f="closed"){if(d)return;d=!0,clearInterval(N),clearTimeout(S),e.signal.removeEventListener("abort",B);for(let h of u.values())h.stop();u.clear(),i.close(),a.close(1000,`worker_${f}`),k(Error("preview_closed")),w()}let B=()=>P("aborted"),S=setTimeout(()=>P("pair_timeout"),p.requestMs),N=setInterval(async()=>{if(!n())return P(e.signal.aborted?"aborted":"expired");if(m)return;m=!0;try{let f=l??=Promise.resolve().then(()=>e.port.check()).finally(()=>{l=void 0}),h=await re(()=>f);if(h===!1)return P("port_refused");if(h){g=void 0;return}if(Date.now()-(g??=Date.now())>Oe)return P("port_unknown");for(let E of u.values())E.stop()}finally{m=!1}},1000);if(e.signal.addEventListener("abort",B,{once:!0}),!n())P(e.signal.aborted?"aborted":"expired");a.addEventListener("open",()=>v({type:"hello",binding:t,messages:p.upload,window:p.window})),a.addEventListener("close",()=>P("relay_closed")),a.addEventListener("error",()=>P("relay_error")),a.addEventListener("message",(f)=>{try{if(!n()||d)return P(e.signal.aborted?"aborted":"expired");if(typeof f.data!=="string")throw Error("preview_frame_invalid");if(b+=Buffer.byteLength(f.data),b>p.total)return P("quota");let h=ge(f.data);if(!c){if(h.type!=="hello"||!ze(t,h.binding))return P("binding_mismatch");c=!0,T=h.bytes===!0,clearTimeout(S),_();return}if(h.type==="hello"||h.type==="refused")return P("invalid_frame");if(h.type==="request"){D(h).catch(()=>P("invalid_request"));return}let E=u.get(h.id);if(!E)return;if(h.type==="cancel"||h.type==="end")E.stop();else if(h.type==="credit"&&E.credit)E.credit();else if(h.type==="data"&&E.ws){if(E.ws.readyState!==U.OPEN||E.ws.bufferedAmount>p.buffered)return E.stop();let I=z(h.data,p.upload);E.ws.send(h.binary?I:I.toString("utf8"))}else P("invalid_frame")}catch{P("invalid_frame")}});async function D(f){if(u.has(f.id)||u.size>=p.streams)return P("stream_limit");if(!n())return P(e.signal.aborted?"aborted":"expired");let h=new AbortController,E,I,q,Y=0,R=(W=!1)=>{if(!u.delete(f.id))return;clearTimeout(E),h.abort(),I?.close(1000,"preview_closed"),q?.(),v({type:W?"end":"cancel",id:f.id})},ie={stop:()=>R(),credit:()=>{Y++,q?.()}};if(u.set(f.id,ie),E=setTimeout(R,p.requestMs),!await Dt(()=>e.port.check())||!n()||h.signal.aborted)return R();let ae=H(f.path);if(f.upgrade){if(f.method!=="GET"||f.body)return R();let W=f.headers.find(([A])=>A.toLowerCase()==="sec-websocket-protocol")?.[1].split(",").map((A)=>A.trim());if(W?.some((A)=>!/^[a-zA-Z0-9._-]{1,100}$/.test(A))||(W?.length??0)>8)return R();I=new U(`ws://127.0.0.1:${i.port}${ae}`,W,{headers:i.headers,followRedirects:!1,perMessageDeflate:!1,maxPayload:p.upload}),ie.ws=I,I.binaryType="arraybuffer",I.addEventListener("open",()=>{clearTimeout(E),v({type:"ws",id:f.id,protocol:I.protocol})}),I.addEventListener("message",(A)=>{let K=typeof A.data!=="string",M=me(A.data);if(M.length>p.upload)return R();v({type:"data",id:f.id,data:M.toString("base64"),binary:K})}),I.addEventListener("error",()=>R()),I.addEventListener("close",(A)=>R(A.wasClean));return}let Te=z(f.body,p.upload),de=Ce({hostname:"127.0.0.1",port:i.port,path:ae,method:f.method,headers:{...Object.fromEntries(ee(f.headers)),...i.headers,connection:"close"},signal:h.signal,agent:!1,maxHeaderSize:16384},async(W)=>{try{let A=[];for(let F=0;F<W.rawHeaders.length;F+=2)A.push([W.rawHeaders[F],W.rawHeaders[F+1]]);let K=W.statusCode??502,M=je(f.method,f.headers,K,A),Q=M==="br"?$e({flush:te.BROTLI_OPERATION_FLUSH,params:{[te.BROTLI_PARAM_QUALITY]:5}}):M==="gzip"?Me({level:6,flush:te.Z_SYNC_FLUSH}):void 0;if(v({type:"head",id:f.id,status:K,headers:ee(M?qe(A,M):A)}),clearTimeout(E),Q)Ne(W,Q,()=>{});for await(let F of Q??W){let ce=Buffer.from(F);for(let G=0;G<ce.length;G+=p.chunk){if(Y===0&&!h.signal.aborted)await new Promise((We)=>{q=We});if(q=void 0,h.signal.aborted)return;Y--;let le=ce.subarray(G,G+p.chunk);v(T?fe(f.id,le):{type:"data",id:f.id,data:le.toString("base64"),binary:!0})}}R(!0)}catch{R()}});de.on("error",()=>R()),de.end(Te)}return await O,{close:P,closed:y}}import{execFile as Ge}from"child_process";import{createRequire as Ze}from"module";import{win32 as V}from"path";var Je=250,Ve=50,Xe=250,Ye=4194304;function Pe(e){let t=/^(?:\[([^\]]+)\]|([^:]+)):([0-9]{1,5})$/.exec(e??""),n=Number(t?.[3]);return t&&n<=65535?{address:t[1]??t[2],port:n}:null}function Qe(e){let t=[];for(let n of e.split(/\r?\n/)){let o=n.trim().split(/\s+/);if(o[0]!=="TCP"||o.length<5)continue;let s=Pe(o[1]),i=Pe(o[2]),a=Number(o.at(-1));if(!s||!i||!Number.isSafeInteger(a)||a<0)continue;t.push({pid:a,localAddress:s.address,localPort:s.port,remoteAddress:i.address,remotePort:i.port,listening:i.port===0})}return t}function er(e){if(e.localAddress==="0.0.0.0"||e.localAddress==="::")return`*:${e.localPort}`;return e.localAddress.includes(":")?`[${e.localAddress}]:${e.localPort}`:`${e.localAddress}:${e.localPort}`}var ke=(e)=>new Promise((t,n)=>Ge(V.join(Ie("win32").split(";")[0],"NETSTAT.EXE"),["-ano"],{timeout:e,maxBuffer:Ye,encoding:"utf8",windowsHide:!0,env:De()},(o,s)=>o?n(o):t(s)));function ne(e){let t=V.normalize(e.startsWith("\\\\?\\")?e.slice(4):e);return t.length>3&&t.endsWith("\\")?t.slice(0,-1):t}function rr(e,t){let n=e.toLowerCase(),o=t.toLowerCase();return o===n||o.startsWith(n.endsWith("\\")?n:`${n}\\`)}function xe(e,t,n){let o=e.cwd(n),s=o?ne(o):null;return s&&V.isAbsolute(s)&&rr(t,s)?s:null}var j;function ye(){if(j!==void 0)return j;if(j=null,process.platform!=="win32"||!["x64","arm64"].includes(process.arch))return null;let e;try{e=Ze(import.meta.url)("bun:ffi")}catch{return null}let{FFIType:t,ptr:n}=e,o,s;try{o=e.dlopen("kernel32.dll",{CreateToolhelp32Snapshot:{args:[t.u32,t.u32],returns:t.u64},Process32FirstW:{args:[t.u64,t.ptr],returns:t.i32},Process32NextW:{args:[t.u64,t.ptr],returns:t.i32},OpenProcess:{args:[t.u32,t.i32,t.u32],returns:t.u64},ReadProcessMemory:{args:[t.u64,t.u64,t.ptr,t.u64,t.ptr],returns:t.i32},CloseHandle:{args:[t.u64],returns:t.i32}}).symbols,s=e.dlopen("ntdll.dll",{NtQueryInformationProcess:{args:[t.u64,t.i32,t.ptr,t.u32,t.ptr],returns:t.i32}}).symbols}catch{return null}let i=0xFFFFFFFFFFFFFFFFn,a=2,u=1040,c=568,d=(b,m,l)=>{let g=Buffer.alloc(l);return o.ReadProcessMemory(b,m,n(g),l,null)?g:null};return j={processes(){let b=BigInt(o.CreateToolhelp32Snapshot(a,0));if(b===i)throw new r("process_inspection_failed","Reading this computer's processes did not complete.");try{let m=Buffer.alloc(c);m.writeUInt32LE(c,0);let l=n(m),g=[];for(let w=o.Process32FirstW(b,l);w;w=o.Process32NextW(b,l)){let y=m.toString("utf16le",44,c),_=y.slice(0,y.includes("\x00")?y.indexOf("\x00"):void 0),k=m.readUInt32LE(8);if(k>0)g.push({pid:k,parentPid:m.readUInt32LE(32),command:_.replace(/\.exe$/i,"")||null})}return g}finally{o.CloseHandle(b)}},cwd(b){let m=BigInt(o.OpenProcess(u,0,b));if(m===0n)return null;try{let l=Buffer.alloc(48);if(s.NtQueryInformationProcess(m,0,n(l),l.length,null)!==0)return null;let g=d(m,l.readBigUInt64LE(8)+0x20n,8)?.readBigUInt64LE(0),w=g?d(m,g+0x38n,16):null,y=w?.readUInt16LE(0)??0;if(!w||y===0||y%2!==0)return null;return d(m,w.readBigUInt64LE(8),y)?.toString("utf16le")??null}finally{o.CloseHandle(m)}}},j}function oe(e){if(!e)throw new r("process_inspection_failed","Reading this computer's processes is unavailable.");return e}async function Se(e,t){let n;try{n=await e(t)}catch{throw new r("process_inspection_failed","Reading this computer's ports did not complete.")}return Qe(n)}async function ao(e,t=ye()){let n=oe(t),o=ne(e),s=[];for(let i of n.processes()){if(s.length>=Je)break;let a=xe(n,o,i.pid);if(a)s.push({pid:i.pid,command:i.command,cwd:V.relative(o,a)||"."})}return{processes:s}}async function co(e,t=ye(),n=ke){let o=oe(t),s=ne(e),i=(await Se(n,5000)).filter((d)=>d.listening&&d.pid>0).map((d)=>({pid:d.pid,port:d.localPort,address:er(d)})).sort((d,b)=>d.pid-b.pid||d.port-b.port||(d.address<b.address?-1:d.address>b.address?1:0)),a=[...new Set(i.map((d)=>d.pid))].slice(0,Ve),u=new Set(a.filter((d)=>xe(o,s,d)!==null));if(u.size===0)return{ports:[]};let c=new Map(o.processes().map((d)=>[d.pid,d.command]));return{ports:i.filter((d)=>u.has(d.pid)).slice(0,Xe).map((d)=>({pid:d.pid,command:c.get(d.pid)??null,address:d.address}))}}function ve(e,t){let n=new Set([t]);for(let o=!0;o;){o=!1;for(let s of e)if(!n.has(s.pid)&&n.has(s.parentPid)&&s.pid!==s.parentPid)n.add(s.pid),o=!0}return n}function tr(e,t,n,o){let s=(i)=>i==="127.0.0.1"||i==="::ffff:127.0.0.1"||i==="::1";return e.flatMap((i)=>{if(!t.has(i.pid)||i.localPort!==o)return[];let a=i.listening&&(s(i.localAddress)||["0.0.0.0","::"].includes(i.localAddress)),u=!i.listening&&s(i.localAddress)&&s(i.remoteAddress);if(!a&&!u)return[];let c=`${i.localAddress}:${i.localPort}>${i.remoteAddress}:${i.remotePort}`;return[{pid:i.pid,processGroupId:n,descriptor:String(i.pid),kernelId:c,state:a?"listen":"established",port:o,peerPort:a?null:i.remotePort,host:i.localAddress==="::1"?"::1":"127.0.0.1"}]})}async function Ee(e,t,n=ye(),o=ke){let s=oe(n),i=ve(s.processes(),e),a=await Se(o,1000),u=ve(s.processes(),e);return tr(a,new Set([...i].filter((c)=>u.has(c))),e,t)}import{execFile as nr}from"child_process";import{readFile as or,readdir as sr,readlink as ir}from"fs/promises";import{connect as ar}from"net";import{setTimeout as dr}from"timers/promises";var cr={directory:sr,text:(e)=>or(e,"utf8"),link:ir};class se extends Error{code;constructor(e="port_unproved"){super("preview_port_ownership_unproved");this.code=e}}var x=(e)=>new se(e),X="preview_listener_unproved",Ae="00000000000000000000000001000000";async function lr(e,t,n=cr){let o=new Map;for(let a of["tcp","tcp6"]){let u=await n.text(`/proc/net/${a}`);if(u.length>4194304)throw x();for(let c of u.split(`
|
|
8
|
-
`).slice(1)){let d=c.trim().split(/\s+/);if(d.length<10||!["0A","01"].includes(d[3]))continue;let[b,m]=d[1].split(":"),[l,g]=d[2].split(":");if(Number.parseInt(m,16)!==t)continue;let w=(k)=>k==="0100007F"||k==="0000000000000000FFFF00000100007F"||k===Ae,y=d[3]==="0A";if(!(w(b)||y&&/^0+$/.test(b??"")))continue;if(!y&&!w(l))continue;let _=d[9];if(!/^[1-9][0-9]*$/.test(_))continue;o.set(_,{kernelId:_,port:t,peerPort:y?null:Number.parseInt(g,16),state:y?"listen":"established",host:b===Ae?"::1":"127.0.0.1"})}}let s=await n.directory("/proc");if(s.length>8192)throw x();let i=[];for(let a of s){if(!/^[1-9][0-9]*$/.test(a))continue;try{let u=await n.text(`/proc/${a}/stat`),c=u.slice(u.lastIndexOf(")")+2).trim().split(/\s+/);if(Number(c[2])!==e)continue;let d=await n.directory(`/proc/${a}/fd`);if(d.length>1024)throw x();let b=[];for(let g of d){if(!/^[0-9]+$/.test(g))continue;let w=await n.link(`/proc/${a}/fd/${g}`).catch(()=>""),y=/^socket:\[([0-9]+)\]$/.exec(w)?.[1],_=y?o.get(y):void 0;if(_)b.push({..._,pid:Number(a),processGroupId:e,descriptor:g})}let m=await n.text(`/proc/${a}/stat`),l=m.slice(m.lastIndexOf(")")+2).trim().split(/\s+/);if(c[19]===l[19]&&c[2]===l[2])i.push(...b)}catch(u){if(u instanceof Error&&u.message==="preview_port_ownership_unproved")throw u}}return i}function ur(e,t,n){if(e.length>2097152)throw x();let o=0,s=0,i="",a="",u="",c="",d=[],b=()=>{if(o<1||s!==t||!/^\d+$/.test(i)||!/^0x[0-9a-f]+$/i.test(a))return;let m=c==="LISTEN"&&["*","127.0.0.1","[::ffff:127.0.0.1]","[::1]"].some((g)=>u===`${g}:${n}`),l=new RegExp(`^(?:127\\.0\\.0\\.1|\\[::ffff:127\\.0\\.0\\.1\\]|\\[::1\\]):${n}->(?:127\\.0\\.0\\.1|\\[::ffff:127\\.0\\.0\\.1\\]|\\[::1\\]):([0-9]+)$`).exec(u);if(m||c==="ESTABLISHED"&&l)d.push({pid:o,processGroupId:s,descriptor:i,kernelId:a,state:m?"listen":"established",port:n,peerPort:m?null:Number(l[1]),host:u.startsWith("[::1]:")?"::1":"127.0.0.1"})};for(let m of e.split(/[\0\n]/)){let l=m.slice(1);if(m[0]==="p")b(),o=Number(l),s=0,i=a=u=c="";else if(m[0]==="g")s=Number(l);else if(m[0]==="f")b(),i=l,a=u=c="";else if(m[0]==="d")a=l;else if(m[0]==="n")u=l;else if(m.startsWith("TST="))c=m.slice(4)}return b(),d}async function pr(e,t){if(process.platform==="linux")return lr(e,t);if(process.platform==="win32")return Ee(e,t);if(process.platform!=="darwin")throw x();let n=await new Promise((o,s)=>nr("/usr/sbin/lsof",["-nP","-a","-g",String(e),`-iTCP:${t}`,"-F0pgfdnT"],{timeout:1000,maxBuffer:2097152,encoding:"utf8",env:{PATH:"/usr/bin:/bin",LC_ALL:"C"}},(i,a)=>i?s(x()):o(a)));return ur(n,e,t)}function we(e,t={}){let n=C(e.binding),o=t.inspectSockets??pr,s=t.monotonicNow??(()=>performance.now());async function i(){let l=()=>{if(Date.now()>=n.expiresAtMs)throw x("binding_expired");if(e.deniedPorts.has(n.port))throw x("port_denied")};l();let g=await e.readCurrentJob(),w=g?.job,y=w?.process;if(l(),!g)throw x("server_stopped");if(!ze(n,g.binding)||w?.jobId!==n.jobId)throw x("binding_changed");if(w.state!=="running"||w.finishedAtMs!==null||w.leaseExpiresAtMs<n.expiresAtMs)throw x("job_not_running");if(!y||y.pid<1||y.pid!==y.processGroupId||y.executorLaunchId!==g.executorLaunchId)throw x("process_unproved");return{pid:y.pid,launch:y.executorLaunchId,started:w.startedAtMs}}let a,u;async function c(){let l=await i(),g=await o(l.pid,n.port).catch(()=>{throw Error(X)}),w=await i();if(l.pid!==w.pid||l.launch!==w.launch||l.started!==w.started)throw x("job_restarted");return g}async function d(l){for(;;){if(u&&u.startedAt>=l)return u.sockets;if(a&&a.startedAt>=l)return await a.sockets;if(a){await a.sockets.catch(()=>{});continue}let g={startedAt:s(),sockets:c()};a=g;try{let w=await g.sockets;if(!u||u.startedAt<=g.startedAt)u={startedAt:g.startedAt,sockets:w};return w}finally{if(a===g)a=void 0}}}async function b(l=()=>{},g=s()){l();let w=await d(g);if(l(),Date.now()>=n.expiresAtMs)throw x("binding_expired");if(!w.some((y)=>y.state==="listen"))throw Error(X);return w}async function m(){try{return await b(()=>{},s()-1000),null}catch(l){if(l instanceof Error&&l.message===X)return"listener_unproved";return l instanceof se?l.code:"port_unproved"}}return{refusal:m,async check(){let l=await m();if(l==="listener_unproved")throw Error(X);return l===null},async connect(l){if(l.aborted)throw x();let g=s()+2000,w=new AbortController,y=new Promise((P)=>w.signal.addEventListener("abort",()=>P(null),{once:!0})),_,k=()=>{w.abort(),_?.destroy()},O=setTimeout(k,2000);l.addEventListener("abort",k,{once:!0});let T=()=>{if(w.signal.aborted||l.aborted||s()>=g||_?.destroyed)throw k(),x()};async function v(P){T();let B=await Promise.race([P().then((S)=>({value:S})),y]);if(T(),!B)throw x();return B.value}try{let P=await v(()=>b(T,s()-1000));T();let B=P.some((f)=>f.state==="listen"&&f.host==="127.0.0.1")?"127.0.0.1":"::1",S=ar({host:B,port:n.port,signal:l});_=S,S.once("close",k),await v(()=>new Promise((f,h)=>{S.once("connect",f),S.once("error",h)}));let N=S.localPort;if(!N)throw x();let D=s();while(!(await v(()=>b(T,D))).some((f)=>f.state==="established"&&f.peerPort===N))await v(()=>dr(Math.min(20,Math.max(1,g-s())),void 0,{signal:w.signal})),D=s();return T(),S}catch(P){throw k(),P}finally{clearTimeout(O),l.removeEventListener("abort",k),_?.off("close",k),w.abort()}}}}
|
|
9
|
-
export{p,ze,Dt,ct,so,xn,_e,ye,ao,co,we};
|