@reason-machines/cli-linux-arm64-musl 0.2.381 → 0.2.383
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/README.md +3 -1
- package/bin/ara +2 -2
- package/bin/vm-hands/api-credentials-xppmbg0m.js +2 -0
- package/bin/vm-hands/api-xmpbsm6b.js +2 -0
- package/bin/vm-hands/{ask-relay-fc0jc3t5.js → ask-relay-h8f5dmfh.js} +3 -3
- package/bin/vm-hands/connect-cli-qvfxpk5t.js +2 -0
- package/bin/vm-hands/{custom-endpoint-device-zhpake9f.js → custom-endpoint-device-bm94e9r0.js} +1 -1
- package/bin/vm-hands/desktop-account-3tnm4z5w.js +2 -0
- package/bin/vm-hands/{device-workspace-vbcry9d6.js → device-workspace-0xsj5ykf.js} +1 -1
- package/bin/vm-hands/hands-worker-source-azdrrhsz.js +2 -0
- package/bin/vm-hands/{index-bbk6a9sk.js → index-7f2kwwen.js} +1 -1
- package/bin/vm-hands/{install-receipt-7x81ek76.js → install-receipt-3xyx3rdd.js} +1 -1
- package/bin/vm-hands/local-automation-pvy9revm.js +2 -0
- package/bin/vm-hands/local-capabilities-zfzyknay.js +2 -0
- package/bin/vm-hands/local-desktop-users-ajb81vjm.js +2 -0
- package/bin/vm-hands/local-display-mac-9h6btvvq.js +2 -0
- package/bin/vm-hands/local-display-session-xqncvp30.js +2 -0
- package/bin/vm-hands/local-pty-session-cjas515w.js +2 -0
- package/bin/vm-hands/managed-runtime-s414h5nm.js +2 -0
- package/bin/vm-hands/{network-contract-zqvt1v0t.js → network-contract-dsw79qkc.js} +1 -1
- package/bin/vm-hands/package-smk3nqjs.js +2 -0
- package/bin/vm-hands/permissions-3mkk9mfw.js +2 -0
- package/bin/vm-hands/{reason-hands-protocol-8fxjynte.js → reason-hands-protocol-7d7xj1h3.js} +1 -1
- package/bin/vm-hands/serve-service-txzqn5kj.js +2 -0
- package/bin/vm-hands/status-23eqx9t3.js +96 -0
- package/bin/vm-hands/version-3gj9bqhc.js +2 -0
- package/bin/vm-hands/{vm-hands-entry-lite-7shpbsw8.js → vm-hands-entry-lite-1gxktkpe.js} +2 -2
- package/bin/vm-hands/vm-hands-entry-lite-2e18tm6w.js +245 -0
- package/bin/vm-hands/{vm-hands-entry-lite-g036gtem.js → vm-hands-entry-lite-2t0vcvd8.js} +1 -1
- package/bin/vm-hands/vm-hands-entry-lite-3dc4v5bd.js +11 -0
- package/bin/vm-hands/{vm-hands-entry-lite-hgkf1svv.js → vm-hands-entry-lite-41nygv3p.js} +2 -2
- package/bin/vm-hands/{vm-hands-entry-lite-j2q1k9vb.js → vm-hands-entry-lite-51hmj6am.js} +1 -1
- package/bin/vm-hands/{vm-hands-entry-lite-zfwg7ehq.js → vm-hands-entry-lite-5n4vsm6b.js} +2 -2
- package/bin/vm-hands/{vm-hands-entry-lite-k7wwza46.js → vm-hands-entry-lite-7xbgw4m0.js} +2 -2
- package/bin/vm-hands/vm-hands-entry-lite-8fj07njx.js +3 -0
- package/bin/vm-hands/{vm-hands-entry-lite-3hbe4em3.js → vm-hands-entry-lite-9cmfthkq.js} +1 -1
- package/bin/vm-hands/{vm-hands-entry-lite-4q8tsaqv.js → vm-hands-entry-lite-9r5tz2dx.js} +2 -2
- package/bin/vm-hands/{vm-hands-entry-lite-45j8qwsf.js → vm-hands-entry-lite-9w5vs9zv.js} +1 -1
- package/bin/vm-hands/vm-hands-entry-lite-a0yfp7s2.js +251 -0
- package/bin/vm-hands/{vm-hands-entry-lite-za55dtte.js → vm-hands-entry-lite-ammr3xbc.js} +2 -2
- package/bin/vm-hands/vm-hands-entry-lite-dh5gwmyf.js +3 -0
- package/bin/vm-hands/{vm-hands-entry-lite-5pm6bhb8.js → vm-hands-entry-lite-e0gdt6r5.js} +1 -1
- package/bin/vm-hands/{vm-hands-entry-lite-5kgvss4p.js → vm-hands-entry-lite-e2mjbqmr.js} +2 -2
- package/bin/vm-hands/vm-hands-entry-lite-ejm5er3h.js +7 -0
- package/bin/vm-hands/vm-hands-entry-lite-eqhsewc0.js +105 -0
- package/bin/vm-hands/{vm-hands-entry-lite-mh0xecf3.js → vm-hands-entry-lite-f02906k8.js} +4 -4
- package/bin/vm-hands/vm-hands-entry-lite-f5230h6t.js +67 -0
- package/bin/vm-hands/{vm-hands-entry-lite-zh8p7ndn.js → vm-hands-entry-lite-fb5dzy9x.js} +2 -2
- package/bin/vm-hands/{vm-hands-entry-lite-yjn6sk08.js → vm-hands-entry-lite-fcrqyxz0.js} +1 -1
- package/bin/vm-hands/vm-hands-entry-lite-fyvgav60.js +3 -0
- package/bin/vm-hands/vm-hands-entry-lite-g5grabna.js +540 -0
- package/bin/vm-hands/vm-hands-entry-lite-g7h6wjqy.js +3 -0
- package/bin/vm-hands/{vm-hands-entry-lite-34e71nbe.js → vm-hands-entry-lite-g8pj1jxa.js} +174 -16
- package/bin/vm-hands/vm-hands-entry-lite-h1rxv02g.js +458 -0
- package/bin/vm-hands/vm-hands-entry-lite-h8dbw0c7.js +4 -0
- package/bin/vm-hands/{vm-hands-entry-lite-nhtb458c.js → vm-hands-entry-lite-hnsm5t36.js} +1 -1
- package/bin/vm-hands/{vm-hands-entry-lite-0asdf4pm.js → vm-hands-entry-lite-jzcc9h71.js} +3 -3
- package/bin/vm-hands/{vm-hands-entry-lite-r6pap1kh.js → vm-hands-entry-lite-ma001vzh.js} +1 -1
- package/bin/vm-hands/{vm-hands-entry-lite-anmv8hp7.js → vm-hands-entry-lite-mn64e4pt.js} +286 -104
- package/bin/vm-hands/{vm-hands-entry-lite-9cgm6g8t.js → vm-hands-entry-lite-pk3q774c.js} +1 -1
- package/bin/vm-hands/vm-hands-entry-lite-qef2ndkd.js +6 -0
- package/bin/vm-hands/vm-hands-entry-lite-qnnfvm5r.js +5 -0
- package/bin/vm-hands/vm-hands-entry-lite-r8qg3wp1.js +3 -0
- package/bin/vm-hands/vm-hands-entry-lite-rd0ak4ye.js +4 -0
- package/bin/vm-hands/{vm-hands-entry-lite-00qsbphw.js → vm-hands-entry-lite-rpn0frzb.js} +2 -2
- package/bin/vm-hands/{vm-hands-entry-lite-g9rvf5qk.js → vm-hands-entry-lite-rtt2w6c6.js} +1 -1
- package/bin/vm-hands/vm-hands-entry-lite-sex82vb1.js +3 -0
- package/bin/vm-hands/vm-hands-entry-lite-vcwgh8tr.js +346 -0
- package/bin/vm-hands/{vm-hands-entry-lite-dgxxsdwb.js → vm-hands-entry-lite-xrthfx3q.js} +2 -2
- package/bin/vm-hands/{vm-hands-entry-lite-kxdw4myj.js → vm-hands-entry-lite-y2s2w174.js} +1 -1
- package/bin/vm-hands/{vm-hands-entry-lite-hc3p6r9p.js → vm-hands-entry-lite-zjfr0zh8.js} +2 -2
- package/bin/vm-hands/vm-hands-entry-lite.js +1 -1
- package/bin/vm-hands/{vm-hands-executor-qssgfea1.js → vm-hands-executor-9p92j0mv.js} +1 -1
- package/bin/vm-hands/vm-hands-op-runner-ers4cefp.js +2 -0
- package/bin/vm-hands/{vm-hands-runtime-5me6cpmn.js → vm-hands-runtime-en4gj0t0.js} +3 -3
- package/bin/vm-hands/worker-sandbox-tgqbmy6b.js +2 -0
- package/package.json +1 -1
- package/bin/vm-hands/api-af9g18n7.js +0 -2
- package/bin/vm-hands/api-credentials-65mrr3tn.js +0 -2
- package/bin/vm-hands/connect-cli-j478km3s.js +0 -2
- package/bin/vm-hands/desktop-account-5zvgspyw.js +0 -2
- package/bin/vm-hands/hands-worker-source-h0b1j53p.js +0 -2
- package/bin/vm-hands/local-automation-c86tjeft.js +0 -2
- package/bin/vm-hands/local-capabilities-1h99gkt6.js +0 -2
- package/bin/vm-hands/local-desktop-users-0hadyvx1.js +0 -2
- package/bin/vm-hands/local-display-mac-v1pc7177.js +0 -2
- package/bin/vm-hands/local-display-session-tzq0hne8.js +0 -2
- package/bin/vm-hands/local-pty-session-hs7rq03x.js +0 -2
- package/bin/vm-hands/managed-runtime-5dqaaw1x.js +0 -2
- package/bin/vm-hands/package-3cd7cfyv.js +0 -2
- package/bin/vm-hands/permissions-vbyqjbyb.js +0 -2
- package/bin/vm-hands/serve-service-be739c9s.js +0 -2
- package/bin/vm-hands/status-s8ny6men.js +0 -96
- package/bin/vm-hands/version-8s4syrp2.js +0 -2
- package/bin/vm-hands/vm-hands-entry-lite-1085xsma.js +0 -5
- package/bin/vm-hands/vm-hands-entry-lite-4m40gwkf.js +0 -3
- package/bin/vm-hands/vm-hands-entry-lite-62wmnm7g.js +0 -540
- package/bin/vm-hands/vm-hands-entry-lite-98076n5g.js +0 -62
- package/bin/vm-hands/vm-hands-entry-lite-bvbfcp1k.js +0 -4
- package/bin/vm-hands/vm-hands-entry-lite-c01eyep6.js +0 -3
- package/bin/vm-hands/vm-hands-entry-lite-dcynw6t2.js +0 -3
- package/bin/vm-hands/vm-hands-entry-lite-hh24bq0d.js +0 -3
- package/bin/vm-hands/vm-hands-entry-lite-jb2sr2r7.js +0 -3
- package/bin/vm-hands/vm-hands-entry-lite-kt5aj2ax.js +0 -11
- package/bin/vm-hands/vm-hands-entry-lite-n9nnb482.js +0 -459
- package/bin/vm-hands/vm-hands-entry-lite-sb9a1jcn.js +0 -4
- package/bin/vm-hands/vm-hands-entry-lite-xg3d0a2y.js +0 -340
- package/bin/vm-hands/vm-hands-entry-lite-zamt8xp7.js +0 -181
- package/bin/vm-hands/vm-hands-entry-lite-ze9msfq1.js +0 -3
- package/bin/vm-hands/vm-hands-op-runner-b76rjaps.js +0 -2
- package/bin/vm-hands/worker-sandbox-wpzkvwer.js +0 -2
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
// @bun
|
|
2
|
+
import{spawn as N}from"child_process";import{statSync as O}from"fs";import{delimiter as Q,join as R}from"path";function X(q,z=process.env.PATH??"",D=process.env,G=process.platform){let A=G==="win32",H=q.includes("/")||A&&q.includes("\\");if(!q||H||q.includes("\x00"))return!1;let I=A?["",...(D.PATHEXT??".EXE;.CMD;.BAT;.COM").split(";")]:[""];return z.split(Q).some((C)=>{if(!C)return!1;return I.some((E)=>{if(E===void 0)return!1;try{let J=O(R(C,`${q}${E}`));if(!J.isFile())return!1;return A||(J.mode&73)!==0}catch{return!1}})})}async function K(q){if(!q)return"";let z=[];try{for await(let D of q)z.push(Buffer.from(D))}catch{}return Buffer.concat(z).toString("utf8")}async function Y(q,z){let[D,...G]=q;if(!D)throw Error("A child process probe requires a program.");if(z.signal?.aborted)return{exitCode:-1,stdout:"",stderr:""};let A=N(D,G,{stdio:["ignore","pipe","pipe"],...z.env?{env:z.env}:{}}),H=K(A.stdout),I=K(A.stderr),C=()=>{try{A.kill()}catch{}};if(z.signal?.aborted)C();else z.signal?.addEventListener("abort",C,{once:!0});let E;try{return{exitCode:await Promise.race([new Promise((F)=>{A.once("error",()=>F(-1)),A.once("close",(M)=>F(M??-1))}),new Promise((F)=>{E=setTimeout(()=>{C(),F(-1)},z.timeoutMs)})]),stdout:await H,stderr:await I}}finally{if(E)clearTimeout(E);z.signal?.removeEventListener("abort",C)}}function Z(q){if(!(q>0))return;Atomics.wait(new Int32Array(new SharedArrayBuffer(4)),0,0,q)}
|
|
3
|
+
export{X as dd,Y as ed,Z as fd};
|
|
@@ -1,14 +1,17 @@
|
|
|
1
1
|
// @bun
|
|
2
|
-
import{
|
|
2
|
+
import{Sd as ae,Ud as ne}from"./vm-hands-entry-lite-eqhsewc0.js";import{vf as be}from"./vm-hands-entry-lite-5n4vsm6b.js";import{$f as z,Tf as C,Uf as ie,Wf as M,Xf as Oe,_f as Y,ag as v,jg as O,kg as Be}from"./vm-hands-entry-lite-a0yfp7s2.js";import{Rg as Se}from"./vm-hands-entry-lite-fb5dzy9x.js";import{Gi as se}from"./vm-hands-entry-lite-jzcc9h71.js";import{fj as J}from"./vm-hands-entry-lite-9r5tz2dx.js";import{lj as x}from"./vm-hands-entry-lite-fyvgav60.js";import{ck as Ne,dk as oe}from"./vm-hands-entry-lite-1gxktkpe.js";import{jk as ye,pk as Ie}from"./vm-hands-entry-lite-rd0ak4ye.js";import{wk as xe}from"./vm-hands-entry-lite-r8qg3wp1.js";import{Ek as p}from"./vm-hands-entry-lite-51hmj6am.js";import{spawn as S,spawnSync as pt}from"child_process";import{createHash as ft,randomUUID as Te}from"crypto";import{closeSync as mt,copyFileSync as de,existsSync as q,fstatSync as _t,mkdirSync as pe,openSync as ht,readdirSync as D,readFileSync as j,readlinkSync as wt,renameSync as ve,rmSync as gt,statSync as bt,writeFileSync as xt}from"fs";import{connect as St}from"net";import{tmpdir as F,userInfo as Re}from"os";import{basename as fe,delimiter as yt,dirname as B,join as f}from"path";var Z=`import { spawn, execFileSync } from "node:child_process";
|
|
3
3
|
import { createHash, randomUUID } from "node:crypto";
|
|
4
4
|
import { readFileSync, readlinkSync, lstatSync, realpathSync, statSync, mkdtempSync, mkdirSync, chmodSync, writeFileSync, readdirSync, rmSync, openSync, readSync, closeSync, renameSync } from "node:fs";
|
|
5
5
|
import { tmpdir } from "node:os";
|
|
6
|
-
import { basename, join } from "node:path";
|
|
6
|
+
import { basename, isAbsolute, join } from "node:path";
|
|
7
|
+
|
|
8
|
+
// By its System32 path: a bare name is looked up in the current folder first.
|
|
9
|
+
const windowsPowerShell=()=>join(process.env.SystemRoot || "C:\\\\Windows", "System32", "WindowsPowerShell", "v1.0", "powershell.exe");
|
|
7
10
|
|
|
8
11
|
const fail = code => { throw new Error(code); };
|
|
9
12
|
const record = value => value && typeof value === "object" && !Array.isArray(value);
|
|
10
13
|
const text = result => Array.isArray(result?.content) ? result.content.filter(item => item.type === "text").map(item => item.text).join("\\n") : "";
|
|
11
|
-
export const CLICKABLE_ROLES = new Set(["button", "push button", "toggle button", "check box", "checkbox", "radio button", "radio", "link", "menu item", "check menu item", "tab", "text field", "entry", "combo box", "list item", "tree item"]);
|
|
14
|
+
export const CLICKABLE_ROLES = new Set(["button", "push button", "toggle button", "check box", "checkbox", "radio button", "radio", "link", "menu item", "check menu item", "tab", "text field", "entry", "combo box", "list item", "tree item", "tab item", "hyperlink"]);
|
|
12
15
|
const ACCESSIBLE_CLICK_ACTIONS = /^(?:click|press|activate|invoke|toggle|select)$/i;
|
|
13
16
|
function stableJson(value) {
|
|
14
17
|
if (Array.isArray(value)) return value.map(stableJson);
|
|
@@ -79,9 +82,10 @@ export function assertAccessibilityTreeMatches(expected, current) {
|
|
|
79
82
|
}
|
|
80
83
|
export function assertSafeComputerTarget(target, action) {
|
|
81
84
|
if (!target || !Number.isSafeInteger(target.pid) || target.pid <= 0 || !target.executable || !target.processStart) fail("cloud_computer_window_unavailable");
|
|
82
|
-
|
|
85
|
+
// A Windows executable's name without its .exe; Windows' shells, terminals, file manager and editors follow.
|
|
86
|
+
const name = basename(target.executable).toLowerCase().replace(/\\.exe$/, "");
|
|
83
87
|
if (/(?:chrome|chromium|firefox|msedge|brave|safari)/i.test(name + " " + target.app)) fail("cloud_computer_use_browser_use");
|
|
84
|
-
if (/^(?:xterm|uxterm|gnome-terminal(?:-server)?|konsole|xfce4-terminal|mate-terminal|qterminal|lxterminal|tilix|kitty|alacritty|terminal|iterm2?|bash|sh|zsh|fish|mc|pcmanfm|thunar|nautilus|dolphin|nemo|finder|openbox|tint2|dock|spotlight|systemuiserver|system settings|system preferences|code|code-oss|electron|gedit|kate|leafpad|mousepad|textedit|automator|script editor|shortcuts|emacs|gvim|vim|nvim|python[0-9.]*|node|ruby|perl|wish[0-9.]*|tclsh[0-9.]
|
|
88
|
+
if (/^(?:xterm|uxterm|gnome-terminal(?:-server)?|konsole|xfce4-terminal|mate-terminal|qterminal|lxterminal|tilix|kitty|alacritty|terminal|iterm2?|bash|sh|zsh|fish|mc|pcmanfm|thunar|nautilus|dolphin|nemo|finder|openbox|tint2|dock|spotlight|systemuiserver|system settings|system preferences|code|code-oss|electron|gedit|kate|leafpad|mousepad|textedit|automator|script editor|shortcuts|emacs|gvim|vim|nvim|python[0-9.]*|node|ruby|perl|wish[0-9.]*|tclsh[0-9.]*|cmd|powershell|powershell_ise|pwsh|windowsterminal|openconsole|conhost|wsl|explorer|regedit|mmc|taskmgr|notepad|wordpad)$/i.test(name)
|
|
85
89
|
|| /(?:devtools|developer tools|javascript console)/i.test(target.title)
|
|
86
90
|
|| /(?:com\\.apple\\.(?:Terminal|Finder|Automator|ScriptEditor2|Shortcuts|systempreferences|dock|Spotlight)|com\\.googlecode\\.iterm2)/i.test(target.app)) fail("cloud_computer_use_bash");
|
|
87
91
|
if (action?.kind === "key_press") {
|
|
@@ -179,6 +183,11 @@ function targetFor(result, expectedApp) {
|
|
|
179
183
|
let executable,processStart;
|
|
180
184
|
if (process.platform === "linux") {
|
|
181
185
|
executable=readlinkSync(\`/proc/\${pid}/exe\`); const stat=readFileSync(\`/proc/\${pid}/stat\`,"utf8"); processStart=stat.slice(stat.lastIndexOf(")")+2).split(/\\s+/)[19];
|
|
186
|
+
} else if (process.platform === "win32") {
|
|
187
|
+
// Path, then start time in UTC file-time ticks; a reused process id starts later.
|
|
188
|
+
// A cold PowerShell start on a busy Windows on Arm machine can take over 10 s.
|
|
189
|
+
[executable="",processStart=""]=execFileSync(windowsPowerShell(),["-NoLogo","-NoProfile","-NonInteractive","-Command",
|
|
190
|
+
\`$p=Get-Process -Id \${pid}; $p.Path; $p.StartTime.ToFileTimeUtc()\`],{encoding:"utf8",timeout:30000,windowsHide:true}).trim().split(/\\r?\\n/).map(line=>line.trim());
|
|
182
191
|
} else {
|
|
183
192
|
executable=execFileSync("/bin/ps",["-p",String(pid),"-o","comm="],{encoding:"utf8",timeout:3000}).trim();
|
|
184
193
|
processStart=execFileSync("/bin/ps",["-p",String(pid),"-o","lstart="],{encoding:"utf8",timeout:3000}).trim();
|
|
@@ -233,6 +242,154 @@ export function actionTool(action, app, target, elements = []) {
|
|
|
233
242
|
if (action.kind === "drag") { point(action.from_x,action.from_y);point(action.to_x,action.to_y);if(!Number.isSafeInteger(action.duration_ms)||action.duration_ms<100||action.duration_ms>2000||!Number.isSafeInteger(action.steps)||action.steps<1||action.steps>120)fail("cloud_computer_action_invalid");return ["drag",{app,from_x:action.from_x,from_y:action.from_y,to_x:action.to_x,to_y:action.to_y}]; }
|
|
234
243
|
fail("cloud_computer_action_unsupported");
|
|
235
244
|
}
|
|
245
|
+
// Windows OCU 0.3.5 posts clicks, keys and text as window messages to the app's
|
|
246
|
+
// top-level window, which its controls never receive. On Windows the runtime
|
|
247
|
+
// instead brings that window to the front and sends real input (SendInput) at
|
|
248
|
+
// the snapshot's pixels; OCU still captures, lists and clicks elements.
|
|
249
|
+
const WINDOWS_INPUT_ACTIONS = new Set(["click_pixel", "type_text", "key_press", "drag"]);
|
|
250
|
+
const WINDOWS_KEYS = { Return: 0x0d, Tab: 0x09, Escape: 0x1b, BackSpace: 0x08, Delete: 0x2e, space: 0x20, Left: 0x25, Up: 0x26,
|
|
251
|
+
Right: 0x27, Down: 0x28, Home: 0x24, End: 0x23, Page_Up: 0x21, Page_Down: 0x22, "*": 0x6a, "/": 0x6f, "=": 0xbb, ".": 0xbe, "-": 0xbd };
|
|
252
|
+
const WINDOWS_MODIFIERS = { ctrl: 0x11, alt: 0x12, shift: 0x10, super: 0x5b };
|
|
253
|
+
const WINDOWS_EXTENDED_KEYS = new Set([0x21, 0x22, 0x23, 0x24, 0x25, 0x26, 0x27, 0x28, 0x2e, 0x5b, 0x6f]);
|
|
254
|
+
/** Helper lines for an action actionTool accepted: \`m x y\` (snapshot pixels), \`b flags\`, \`k vk flags\`, \`u unit\`, \`s ms\`. */
|
|
255
|
+
export function windowsInputLines(action) {
|
|
256
|
+
const key = (vk, up) => \`k \${vk} \${(up ? 2 : 0) | (WINDOWS_EXTENDED_KEYS.has(vk) ? 1 : 0)}\`;
|
|
257
|
+
if (action.kind === "click_pixel") return [\`m \${action.x} \${action.y}\`, "b 2", "b 4"];
|
|
258
|
+
if (action.kind === "drag") {
|
|
259
|
+
const lines = [\`m \${action.from_x} \${action.from_y}\`, "b 2"];
|
|
260
|
+
for (let step = 1; step <= action.steps; step++) {
|
|
261
|
+
lines.push(\`s \${Math.round(action.duration_ms / action.steps)}\`, \`m \${Math.round(action.from_x + (action.to_x - action.from_x) * step / action.steps)} \${Math.round(action.from_y + (action.to_y - action.from_y) * step / action.steps)}\`);
|
|
262
|
+
}
|
|
263
|
+
return [...lines, "b 4"];
|
|
264
|
+
}
|
|
265
|
+
if (action.kind === "type_text") {
|
|
266
|
+
return [...action.text.replace(/\\r\\n?/g, "\\n")].flatMap(character => character === "\\n" ? [key(0x0d), key(0x0d, true)]
|
|
267
|
+
: character === "\\t" ? [key(0x09), key(0x09, true)]
|
|
268
|
+
: /[\\x00-\\x1f\\x7f]/.test(character) ? [] : Array.from({ length: character.length }, (_, index) => \`u \${character.charCodeAt(index)}\`));
|
|
269
|
+
}
|
|
270
|
+
const parts = action.key.split("+");
|
|
271
|
+
const modifiers = parts.slice(0, -1).map(name => WINDOWS_MODIFIERS[name]);
|
|
272
|
+
const main = parts.at(-1);
|
|
273
|
+
const vk = /^[a-zA-Z0-9]$/.test(main) ? main.toUpperCase().charCodeAt(0) : /^F\\d+$/.test(main) ? 0x6f + Number(main.slice(1)) : WINDOWS_KEYS[main];
|
|
274
|
+
return [...modifiers.map(code => key(code)), key(vk), key(vk, true), ...modifiers.reverse().map(code => key(code, true))];
|
|
275
|
+
}
|
|
276
|
+
const WINDOWS_INPUT_HELPER = String.raw\`
|
|
277
|
+
$ErrorActionPreference = "Stop"
|
|
278
|
+
Add-Type -TypeDefinition @"
|
|
279
|
+
using System;
|
|
280
|
+
using System.Runtime.InteropServices;
|
|
281
|
+
public static class ReasonWindowsInput {
|
|
282
|
+
[StructLayout(LayoutKind.Sequential)] public struct MOUSEINPUT { public int dx; public int dy; public int mouseData; public uint dwFlags; public uint time; public IntPtr dwExtraInfo; }
|
|
283
|
+
[StructLayout(LayoutKind.Sequential)] public struct KEYBDINPUT { public ushort wVk; public ushort wScan; public uint dwFlags; public uint time; public IntPtr dwExtraInfo; }
|
|
284
|
+
[StructLayout(LayoutKind.Explicit)] public struct UNION { [FieldOffset(0)] public MOUSEINPUT mi; [FieldOffset(0)] public KEYBDINPUT ki; }
|
|
285
|
+
[StructLayout(LayoutKind.Sequential)] public struct INPUT { public uint type; public UNION u; }
|
|
286
|
+
[StructLayout(LayoutKind.Sequential)] public struct RECT { public int Left; public int Top; public int Right; public int Bottom; }
|
|
287
|
+
[StructLayout(LayoutKind.Sequential)] public struct POINT { public int X; public int Y; }
|
|
288
|
+
[DllImport("user32.dll")] static extern uint SendInput(uint count, INPUT[] inputs, int size);
|
|
289
|
+
[DllImport("user32.dll")] static extern uint MapVirtualKey(uint code, uint type);
|
|
290
|
+
[DllImport("user32.dll")] public static extern bool SetProcessDPIAware();
|
|
291
|
+
[DllImport("user32.dll")] public static extern int GetSystemMetrics(int index);
|
|
292
|
+
[DllImport("user32.dll")] public static extern bool GetWindowRect(IntPtr hwnd, out RECT rect);
|
|
293
|
+
[DllImport("user32.dll")] public static extern bool IsIconic(IntPtr hwnd);
|
|
294
|
+
[DllImport("user32.dll")] public static extern bool ShowWindow(IntPtr hwnd, int command);
|
|
295
|
+
[DllImport("user32.dll")] public static extern IntPtr GetForegroundWindow();
|
|
296
|
+
[DllImport("user32.dll")] public static extern bool SetForegroundWindow(IntPtr hwnd);
|
|
297
|
+
[DllImport("user32.dll")] public static extern bool BringWindowToTop(IntPtr hwnd);
|
|
298
|
+
[DllImport("user32.dll")] public static extern uint GetWindowThreadProcessId(IntPtr hwnd, out uint pid);
|
|
299
|
+
[DllImport("user32.dll")] public static extern bool AttachThreadInput(uint from, uint to, bool attach);
|
|
300
|
+
[DllImport("kernel32.dll")] public static extern uint GetCurrentThreadId();
|
|
301
|
+
[DllImport("user32.dll")] public static extern IntPtr WindowFromPoint(POINT point);
|
|
302
|
+
[DllImport("user32.dll")] public static extern IntPtr GetAncestor(IntPtr hwnd, uint flags);
|
|
303
|
+
[DllImport("user32.dll")] public static extern bool GetCursorPos(out POINT point);
|
|
304
|
+
[DllImport("user32.dll")] public static extern bool SetCursorPos(int x, int y);
|
|
305
|
+
static void Send(INPUT input) { SendInput(1, new INPUT[] { input }, Marshal.SizeOf(typeof(INPUT))); }
|
|
306
|
+
public static void Mouse(uint flags, int x, int y) { INPUT input = new INPUT(); input.type = 0; input.u.mi.dx = x; input.u.mi.dy = y; input.u.mi.dwFlags = flags; Send(input); }
|
|
307
|
+
public static void Key(ushort vk, ushort unit, uint flags) {
|
|
308
|
+
INPUT input = new INPUT(); input.type = 1;
|
|
309
|
+
input.u.ki.wVk = vk; input.u.ki.wScan = vk != 0 ? (ushort)MapVirtualKey(vk, 0) : unit; input.u.ki.dwFlags = flags; Send(input);
|
|
310
|
+
}
|
|
311
|
+
public static uint Owner(IntPtr hwnd) { uint pid; GetWindowThreadProcessId(hwnd, out pid); return pid; }
|
|
312
|
+
}
|
|
313
|
+
"@
|
|
314
|
+
[void][ReasonWindowsInput]::SetProcessDPIAware()
|
|
315
|
+
$target = __PID__
|
|
316
|
+
$hwnd = [IntPtr](Get-Process -Id $target).MainWindowHandle
|
|
317
|
+
if ($hwnd -eq [IntPtr]::Zero) { exit 3 }
|
|
318
|
+
if ([ReasonWindowsInput]::IsIconic($hwnd)) { [void][ReasonWindowsInput]::ShowWindow($hwnd, 9) }
|
|
319
|
+
# The app's own window (its dialog, say) may already be in front; otherwise bring
|
|
320
|
+
# its main window there, sharing the foreground thread's input state to be allowed to.
|
|
321
|
+
if ([ReasonWindowsInput]::Owner([ReasonWindowsInput]::GetForegroundWindow()) -ne $target) {
|
|
322
|
+
$foreground = [ReasonWindowsInput]::GetForegroundWindow()
|
|
323
|
+
$owner = [uint32]0
|
|
324
|
+
$thread = [ReasonWindowsInput]::GetWindowThreadProcessId($foreground, [ref]$owner)
|
|
325
|
+
$self = [ReasonWindowsInput]::GetCurrentThreadId()
|
|
326
|
+
[void][ReasonWindowsInput]::AttachThreadInput($self, $thread, $true)
|
|
327
|
+
[void][ReasonWindowsInput]::BringWindowToTop($hwnd)
|
|
328
|
+
[void][ReasonWindowsInput]::SetForegroundWindow($hwnd)
|
|
329
|
+
[void][ReasonWindowsInput]::AttachThreadInput($self, $thread, $false)
|
|
330
|
+
}
|
|
331
|
+
for ($i = 0; [ReasonWindowsInput]::Owner([ReasonWindowsInput]::GetForegroundWindow()) -ne $target; $i++) {
|
|
332
|
+
if ($i -ge 40) { [Console]::Error.WriteLine("windows input: window not brought to the front"); exit 4 }
|
|
333
|
+
# Still not in front: a key press makes this process the last to receive
|
|
334
|
+
# input, which Windows requires of a process that sets the foreground.
|
|
335
|
+
if ($i -eq 20) { [ReasonWindowsInput]::Key(0x12, 0, 0); [ReasonWindowsInput]::Key(0x12, 0, 2); [void][ReasonWindowsInput]::SetForegroundWindow($hwnd) }
|
|
336
|
+
Start-Sleep -Milliseconds 50
|
|
337
|
+
}
|
|
338
|
+
$rect = New-Object ReasonWindowsInput+RECT
|
|
339
|
+
if (-not [ReasonWindowsInput]::GetWindowRect($hwnd, [ref]$rect)) { exit 3 }
|
|
340
|
+
$left = [ReasonWindowsInput]::GetSystemMetrics(76); $top = [ReasonWindowsInput]::GetSystemMetrics(77)
|
|
341
|
+
$width = [Math]::Max(2, [ReasonWindowsInput]::GetSystemMetrics(78)); $height = [Math]::Max(2, [ReasonWindowsInput]::GetSystemMetrics(79))
|
|
342
|
+
$pointer = New-Object ReasonWindowsInput+POINT
|
|
343
|
+
[void][ReasonWindowsInput]::GetCursorPos([ref]$pointer)
|
|
344
|
+
$moved = $false
|
|
345
|
+
$down = $false
|
|
346
|
+
$code = 0
|
|
347
|
+
# A drag stopped part way still lets go of the button and puts the pointer back.
|
|
348
|
+
try {
|
|
349
|
+
:lines foreach ($line in [Console]::In.ReadToEnd().Split([char]10)) {
|
|
350
|
+
$n = $line.Trim().Split(" ")
|
|
351
|
+
switch ($n[0]) {
|
|
352
|
+
"m" {
|
|
353
|
+
# Snapshot pixels map onto the window's rectangle, whatever scale OCU captured it at.
|
|
354
|
+
$point = New-Object ReasonWindowsInput+POINT
|
|
355
|
+
$point.X = $rect.Left + [int][Math]::Floor([int]$n[1] * ($rect.Right - $rect.Left) / __WIDTH__)
|
|
356
|
+
$point.Y = $rect.Top + [int][Math]::Floor([int]$n[2] * ($rect.Bottom - $rect.Top) / __HEIGHT__)
|
|
357
|
+
# Never click another app's window that covers this point.
|
|
358
|
+
# A window just brought to the front may take a moment to be on top there.
|
|
359
|
+
for ($i = 0; [ReasonWindowsInput]::Owner([ReasonWindowsInput]::GetAncestor([ReasonWindowsInput]::WindowFromPoint($point), 2)) -ne $target; $i++) {
|
|
360
|
+
if ($i -ge 10) { [Console]::Error.WriteLine("windows input: another window covers the point"); $code = 5; break lines }
|
|
361
|
+
Start-Sleep -Milliseconds 100
|
|
362
|
+
}
|
|
363
|
+
$moved = $true
|
|
364
|
+
[ReasonWindowsInput]::Mouse(0xC001, [int](($point.X - $left) * 65535.0 / ($width - 1)), [int](($point.Y - $top) * 65535.0 / ($height - 1)))
|
|
365
|
+
}
|
|
366
|
+
"b" { [ReasonWindowsInput]::Mouse([uint32]$n[1], 0, 0); $down = [uint32]$n[1] -eq 2 }
|
|
367
|
+
"k" { [ReasonWindowsInput]::Key([uint16]$n[1], 0, [uint32]$n[2]) }
|
|
368
|
+
"u" { [ReasonWindowsInput]::Key(0, [uint16]$n[1], 4); [ReasonWindowsInput]::Key(0, [uint16]$n[1], 6) }
|
|
369
|
+
"s" { Start-Sleep -Milliseconds ([int]$n[1]) }
|
|
370
|
+
}
|
|
371
|
+
}
|
|
372
|
+
} finally {
|
|
373
|
+
if ($down) { [ReasonWindowsInput]::Mouse(4, 0, 0) }
|
|
374
|
+
# Let the app paint before the after-action capture.
|
|
375
|
+
Start-Sleep -Milliseconds 200
|
|
376
|
+
# The person's pointer goes back where it was; left over the app, its hover
|
|
377
|
+
# tooltip's shadow would become the window OCU captures next.
|
|
378
|
+
if ($moved) { [void][ReasonWindowsInput]::SetCursorPos($pointer.X, $pointer.Y) }
|
|
379
|
+
}
|
|
380
|
+
if ($code) { exit $code }
|
|
381
|
+
\`;
|
|
382
|
+
export function windowsInput(target, action, execute = execFileSync) {
|
|
383
|
+
const script = WINDOWS_INPUT_HELPER.replace("__PID__", String(target.pid)).replace("__WIDTH__", String(target.width)).replace("__HEIGHT__", String(target.height));
|
|
384
|
+
try {
|
|
385
|
+
execute(windowsPowerShell(),
|
|
386
|
+
["-NoLogo", "-NoProfile", "-NonInteractive", "-ExecutionPolicy", "Bypass", "-EncodedCommand", Buffer.from(script, "utf16le").toString("base64")],
|
|
387
|
+
{ input: windowsInputLines(action).join("\\n"), stdio: ["pipe", "ignore", "inherit"], timeout: 30000 + (action.duration_ms ?? 0), windowsHide: true });
|
|
388
|
+
} catch (error) {
|
|
389
|
+
fail(error?.status === 3 ? "cloud_computer_window_unavailable" : error?.status === 4 || error?.status === 5 ? "cloud_computer_window_covered" : "cloud_computer_input_failed");
|
|
390
|
+
}
|
|
391
|
+
return { content: [{ type: "text", text: "Input sent." }] };
|
|
392
|
+
}
|
|
236
393
|
const explicitTabTools = new Set(["navigate", "wait_load", "page_info", "cdp", "move_mouse", "wait_file_chooser"]);
|
|
237
394
|
export function validateBrowserTab(request) {
|
|
238
395
|
if (explicitTabTools.has(request.tool) && (!record(request.arguments) || !Number.isSafeInteger(request.arguments.tab_id) || request.arguments.tab_id <= 0)) fail("cloud_automation_browser_tab_id_required");
|
|
@@ -589,7 +746,7 @@ export function computerArgs(args, env = process.env) {
|
|
|
589
746
|
}
|
|
590
747
|
export async function runCloudAutomation(request) {
|
|
591
748
|
if (!record(request) || request.version !== 1 || !["computer","browser"].includes(request.kind)) fail("cloud_automation_request_invalid");
|
|
592
|
-
const home = process.env.HOME; if (!home
|
|
749
|
+
const home = process.env.HOME; if (!home || !isAbsolute(home)) fail("cloud_automation_home_unavailable");
|
|
593
750
|
const computer = request.kind === "computer";
|
|
594
751
|
if (!computer && (typeof request.scope !== "string" || !/^reason-cloud-[a-f0-9]{64}$/.test(request.scope))) fail("cloud_automation_scope_invalid");
|
|
595
752
|
const command = automationCommand(computer ? "computer" : "browser");
|
|
@@ -625,7 +782,7 @@ export async function runCloudAutomation(request) {
|
|
|
625
782
|
}
|
|
626
783
|
if (request.operation === "launch_simulator") return await launchInstalledSimulator(call);
|
|
627
784
|
if (request.operation === "launch_calculator") {
|
|
628
|
-
if (process.platform === "linux") { const child=spawn("/usr/bin/galculator",[],{stdio:"ignore",detached:true,env:process.env}); await new Promise((resolve,reject)=>{child.once("spawn",resolve);child.once("error",reject);});child.unref(); }
|
|
785
|
+
if (process.platform === "linux" || process.platform === "win32") { const child=spawn(process.platform === "win32" ? join(process.env.SystemRoot || "C:\\\\Windows","System32","calc.exe") : "/usr/bin/galculator",[],{stdio:"ignore",detached:true,env:process.env}); await new Promise((resolve,reject)=>{child.once("spawn",resolve);child.once("error",reject);});child.unref(); }
|
|
629
786
|
else execFileSync("/usr/bin/open",["-b","com.apple.calculator"],{timeout:5000,stdio:"ignore"});
|
|
630
787
|
return {ok:true,launched:"Calculator"};
|
|
631
788
|
}
|
|
@@ -646,7 +803,8 @@ export async function runCloudAutomation(request) {
|
|
|
646
803
|
if(request.operation !== "act" || !sameComputerTarget(target,request.expected)) fail("cloud_computer_window_changed");
|
|
647
804
|
if (request.action?.kind === "click_element") assertAccessibilityTreeMatches(request.expected, target);
|
|
648
805
|
assertSafeComputerTarget(target,request.action);
|
|
649
|
-
const [tool,args]=actionTool(request.action,request.app,target,accessibility.elements);
|
|
806
|
+
const [tool,args]=actionTool(request.action,request.app,target,accessibility.elements);
|
|
807
|
+
const result=process.platform === "win32" && WINDOWS_INPUT_ACTIONS.has(request.action.kind) ? windowsInput(target,request.action) : await call(tool,args);
|
|
650
808
|
return process.platform === "darwin"
|
|
651
809
|
? {ok:true,...macComputerActionObservation(result,target)}
|
|
652
810
|
: {ok:true,target,result};
|
|
@@ -691,11 +849,11 @@ if(process.env.REASON_CLOUD_GATEWAY_EXEC === "1") {
|
|
|
691
849
|
process.stdout.write(JSON.stringify(cloudAutomationFailure(error))+"\\n");process.exitCode=1;
|
|
692
850
|
}
|
|
693
851
|
}
|
|
694
|
-
`;import{spawn as
|
|
695
|
-
`).at(-1)?.slice(-300)??"";if(!
|
|
696
|
-
`);if(
|
|
697
|
-
`}function
|
|
698
|
-
`),1;if(e.length===1&&e[0]==="doctor"){let
|
|
699
|
-
`),1;return(r.stdout??process.stdout).write(
|
|
700
|
-
`),2;let[a,...c]=i;return(r.run??Rt)(a,[...c,o.ocu,"mcp"],{...process.env,OPEN_COMPUTER_USE_DISABLE_APP_AGENT_PROXY:"1"})}function Nr(e=v){return e()?.userChrome??{code:"user_chrome_browser_use_missing"}}function Ne(e,r,t,i){return new Promise((o)=>{let a=O(e,r,{env:t,stdio:"ignore"}),c=setTimeout(()=>{a.kill("SIGKILL"),o(-1)},i);a.once("error",()=>{clearTimeout(c),o(-1)}),a.once("exit",(s)=>{clearTimeout(c),o(s??-1)})})}function Tt(e,r,t,i){return new Promise((o)=>{let a=O(e,r,{env:t,stdio:["ignore","pipe","ignore"]}),c="";a.stdout.setEncoding("utf8").on("data",(l)=>{c+=l});let s=setTimeout(()=>{a.kill("SIGKILL"),o(null)},i);a.once("error",()=>{clearTimeout(s),o(null)}),a.once("close",(l)=>{clearTimeout(s),o(l===0?c:null)})})}var Ct="/tmp/open-browser-use",It=/^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/,kt=33554432;function qt(e,r){let t;try{t=e===null?null:JSON.parse(e)}catch{return null}let i=E(t)&&E(t.result)?t.result.metadata:null;if(!E(i)||i.extensionId!==r)return null;return typeof i.extensionInstanceId==="string"&&It.test(i.extensionInstanceId)?i.extensionInstanceId:null}async function Re(e,r,t){let i=t.storages.map((s)=>{try{return F(s).filter((l)=>l.endsWith(".log")||l.endsWith(".ldb")).map((l)=>_(s,l))}catch{return[]}}),o;try{o=i.some((s)=>s.length>0)?F(t.socketDir).filter((s)=>s.endsWith(".sock")):[]}catch{return[]}let a=[];for(let s of o){let l=_(t.socketDir,s),u=qt(await Tt(e,["info","--socket",l,"--timeout","2s"],r,5000),t.extensionId);if(u)a.push({instance:u,socket:l})}let c=[];for(let[s,l]of(a.length>0?i:[]).entries())for(let u of l)try{if(pt(u).size>kt)continue;let n=Ae(u),d=a.find((m)=>n.includes(m.instance));if(d){c.push({storage:t.storages[s],...d});break}}catch{}return c}async function Et(e,r,t){return(await Re(e,r,t))[0]?.instance??null}function Te(e,r,t){return Et(e,r,{socketDir:Ct,extensionId:D,storages:[_(t,"browser-profile","Default","Local Extension Settings",D)]})}var fe=/^(Default|Profile ([0-9]+))$/;async function Bt(e,r,t=y(),i=W){let o=_(t,"Library","Application Support","Google","Chrome"),a=[];try{a=F(o)}catch(n){if(n.code==="EPERM")throw new f("browser_use_chrome_access_denied","macOS blocked Reason from reading Chrome's profiles. Allow Full Disk Access for Reason on this Mac and try again.")}let c=(n)=>Number(fe.exec(n)?.[2]??-1),s=a.filter((n)=>fe.test(n)&&G(_(o,n,"Extensions",q))).sort((n,d)=>c(n)-c(d)),l=(n)=>_(o,n,"Local Extension Settings",q);return(await Re(e,r,{socketDir:i,extensionId:q,storages:s.map(l)})).map(({storage:n,instance:d,socket:m})=>({profile:s.find((p)=>l(p)===n),instance:d,socket:m}))}async function Ft(e,r,t=y(),i=W){let o=(await Bt(e,r,t,i))[0]?.instance;if(!o)throw new f("automation_user_chrome_not_connected","No Chrome profile on this Mac is connected to Reason. Open Chrome with the Reason extension, then try again.");return o}function me(e){return new Promise((r)=>{let t=_t({path:e}),i=(o)=>{t.destroy(),r(o)};t.setTimeout(1000,()=>i(!1)),t.once("error",()=>i(!1)),t.once("connect",()=>i(!0))})}async function Ce(e,r){let t=Date.now()+r;while(Date.now()<t){if(await e())return!0;await new Promise((i)=>setTimeout(i,200))}return!1}var $=new Map;function L(e,r){let t=$.get(e);if(!t)t=r().finally(()=>$.delete(e)),$.set(e,t);return t}async function Pt(e,r){if(await me(e))return;if(mt(e,{force:!0}),await Ne("dbus-daemon",["--session",`--address=unix:path=${e}`,"--fork"],r,1e4)!==0||!await Ce(()=>me(e),5000))throw new f("automation_unavailable","Reason could not start the desktop session bus.")}async function pe(e,r,t){let i=e.platform==="darwin-arm64"?async()=>await Te(e.nativeHost,r,t)!==null:async()=>await Ne(e.nativeHost,["info"],r,5000)===0;if(await i())return;let o=["--profile-directory=Default",`--load-extension=${e.extensionDir}`,"--no-first-run","--no-default-browser-check","--window-size=1280,800","about:blank"],a,c=null,s=0;if(e.platform==="darwin-arm64"){let n=_(t,"browser-profile");T(n);let d=_(n,"NativeMessagingHosts");le(d,{recursive:!0,mode:448});let m=z(e.platform).nativeHostManifests[0];ce(m,_(d,ue(m)));let p=e.browser.slice(0,e.browser.indexOf(".app/")+4),b=o.filter((A)=>A!=="about:blank").concat("--no-startup-window","--use-mock-keychain");a=O("/usr/bin/open",["-g","-n","-a",p,"--args",`--user-data-dir=${n}`,...b],{env:r,stdio:"ignore"})}else{let n=_(r.HOME,".config","google-chrome"),d=_(n,"NativeMessagingHosts");le(d,{recursive:!0,mode:448});let m=z(e.platform).nativeHostManifests[0];ce(m,_(d,ue(m)));let p=process.geteuid?.()===0?["--no-sandbox"]:[];c=_(t,"browser.log");let b=ut(c,"a",384);s=lt(b).size,a=O(e.browser,[`--user-data-dir=${n}`,...o,...p,"--force-renderer-accessibility"],{detached:!0,stdio:["ignore",b,b],env:{...r,ACCESSIBILITY_ENABLED:"1"}}),ct(b)}let l=!1;a.once("error",()=>{l=!0}),a.once("exit",(n)=>{l||=n!==0}),a.unref();let u=!1;if(await Ce(async()=>l||(u=await i()),St),!u){if(c&&Ae(c).subarray(s).toString("utf8").includes("No usable sandbox"))throw new f("automation_browser_sandbox_unavailable","Chromium found no usable sandbox on this machine. Run the worker as a non-root user with unprivileged user namespaces enabled, or in a container with seccomp unconfined.");throw new f("automation_browser_unavailable","Reason could not connect the desktop browser.")}}async function Rr(e){await qe(e,!0)}function Tr(e){return Ie(e,ke(e))}function Ie(e,r){return e.platform==="darwin-arm64"?_(r,"browser-profile"):_(r,"home",".config","google-chrome")}function ke(e){let r=_(e.root,"automation");if(!G(r)||!$t(e.automation))return e.automation;if(!Lt(Ie(e,r)))try{ft(r,e.automation)}catch{}return G(r)?r:e.automation}function $t(e){try{return F(e).length===0}catch(r){return r.code==="ENOENT"}}function Lt(e){let r;try{r=dt(_(e,"SingletonLock"))}catch{return!1}let t=Number(r.slice(r.lastIndexOf("-")+1));if(!Number.isSafeInteger(t)||t<=0)return!0;try{return process.kill(t,0),!0}catch(i){return i.code==="EPERM"}}async function qe(e,r){be({root:e.root,automation:e.automation,extensionDir:e.extensionDir});let t=ke(e);T(t);let i=Oe().username,o={USER:i,LOGNAME:i,REASON_AUTOMATION_OCU:e.ocu,REASON_AUTOMATION_OBU:e.nativeHost};if(e.platform==="darwin-arm64"){let n={...o,HOME:y(),PATH:`${U(e.node)}:/usr/bin:/bin:/usr/sbin:/sbin`,REASON_AUTOMATION_OCU:process.execPath,REASON_AUTOMATION_OCU_SUBCOMMAND:vt};if(!r)return n;await L("browser",()=>pe(e,n,t));let d=await Te(e.nativeHost,n,t);if(!d)throw new f("automation_browser_unavailable","Reason could not connect the desktop browser.");return{...n,REASON_AUTOMATION_OBU_INSTANCE:d,REASON_AUTOMATION_BACKGROUND_TABS:"1"}}let a=await Fe(),c=_(t,"home"),s=_(t,"runtime");T(c),T(s);let l=_(t,"bus"),u={...o,HOME:c,PATH:`${U(e.node)}:/usr/bin:/bin`,DISPLAY:a.display,XAUTHORITY:a.xauthority,XDG_RUNTIME_DIR:s,DBUS_SESSION_BUS_ADDRESS:`unix:path=${l}`,...a.sound?{PULSE_SERVER:ye(a.sound)}:{}};if(await L("bus",()=>Pt(l,u)),r)await L("browser",()=>pe(e,u,t));return u}async function Dt(e,r,t){let i=Oe().username,o={USER:i,LOGNAME:i,HOME:y(),PATH:`${U(e.node)}:/usr/bin:/bin:/usr/sbin:/sbin`,REASON_AUTOMATION_OBU:r,REASON_AUTOMATION_BACKGROUND_TABS:"1"},a=await Ft(r,o);return t.throwIfAborted(),{...o,REASON_AUTOMATION_OBU_INSTANCE:a}}function Ee(e,r,t,i){if(typeof de!=="string")return Promise.reject(new f("automation_unavailable","This Reason build has no automation runtime."));let o=de;return new Promise((a,c)=>{let s=O(e,["--input-type=module","--eval",o],{env:{...r,REASON_CLOUD_GATEWAY_EXEC:"1",REASON_AUTOMATION_INLINE_RESULT:"1"},stdio:["pipe","pipe","pipe"],detached:!0}),l=[],u=0,n="",d=null,m=!1,p=(h)=>{d??=h;try{process.kill(-s.pid,"SIGKILL")}catch{s.kill("SIGKILL")}},b=(h)=>{if(m)return;m=!0,clearTimeout(A),i.removeEventListener("abort",x),h()},A=setTimeout(()=>p(new f("automation_timed_out","Reason automation did not finish in time.")),wt),x=()=>p(new f("cancelled","Reason cancelled the automation call."));if(i.addEventListener("abort",x,{once:!0}),s.stdout.on("data",(h)=>{if(u+=h.byteLength,u>ht)p(new f("automation_output_too_large","Reason automation output is too large."));else l.push(h)}),s.stderr.setEncoding("utf8").on("data",(h)=>{n=(n+h).slice(-gt)}),s.stdin.on("error",()=>{}),s.once("error",()=>b(()=>c(d??new f("automation_unavailable","Reason could not start the automation runtime.")))),s.once("close",(h)=>b(()=>{if(d)c(d);else a({code:h??1,stdout:Buffer.concat(l),stderr:n})})),i.aborted)x();s.stdin.end(t)})}var S=new Map;function Gt(e,r,t){for(let[o,a]of S)if(a.expiresAt<=t)S.delete(o);while(S.size>=yt)S.delete(S.keys().next().value);let i=Se();return S.set(i,{runId:e,bytes:r,expiresAt:t+xt}),i}async function Be(e,r,t,i={}){let o=await(i.environment??qe)(e,r.kind==="browser");return t.throwIfAborted(),await(i.runtime??Ee)(e.node,o,JSON.stringify(r),t)}async function Cr(e,r){let t=ve({call:e});if(!("call"in t))B();let i=v();if(!i?.features.computer||t.call.kind==="browser"&&!i.features.browser)throw new f("automation_unavailable","Run `reason desktop install` on this machine to enable computer and browser use.");return await Be(i,t.call,r)}function _e(e,r,t){let i=e.stdout.byteLength>M?Gt(r,e.stdout,t):void 0;return{code:e.code,stderr:e.stderr,instance_id:Ot,output_bytes:e.stdout.byteLength,chunk:e.stdout.subarray(0,M).toString("base64"),...i?{output_id:i}:{}}}async function Ir(e,r={}){let t=ve(e.payload),i=(r.now??Date.now)();if("output_id"in t){let p=S.get(t.output_id);if(!p||p.runId!==e.runId||p.expiresAt<=i||t.offset>p.bytes.byteLength)throw new f("automation_output_unavailable","Reason automation output expired.");return{chunk:p.bytes.subarray(t.offset,t.offset+M).toString("base64")}}let o=(r.components??v)(),a=(r.platform??process.platform)==="darwin",c=a?(r.macIdentity??J)():[],s=r.macSetup??k,l=!o?.features.computer||t.call.kind==="browser"&&!t.userChrome&&!o.features.browser;if(a&&(l||c.length===0||t.call.kind==="browser"&&t.userChrome&&!e.userChrome))return _e(await se({runId:e.runId,call:t.call,identity:c,desktopMissing:l,signal:e.signal},s),e.runId,i);if(!o?.features.computer)throw new f("automation_unavailable","Run `reason desktop install` on this machine to enable computer and browser use.");let u=t.userChrome?e.userChrome:void 0;if(t.userChrome&&!u)throw new f("automation_user_chrome_unavailable","Your own Chrome is not enabled on this computer: run `reason desktop install` on this Mac (and `reason connect --user-chrome on` if you turned it off).");if(t.call.kind==="browser"&&!u&&!o.features.browser)throw new f("automation_browser_not_installed",o.platform==="darwin-arm64"?"Browser use is unavailable on this machine: re-run `reason desktop install`.":"Browser use is unavailable on this machine: install a non-snap Chromium at /usr/bin/chromium, then re-run `reason desktop install`.");e.signal.throwIfAborted();let n=await we(e.runId,e.signal,r.now),d="account"in r?r.account??null:ge(),m;try{if(u){let p=await(r.userChromeEnvironment??Dt)(o,u,e.signal);e.signal.throwIfAborted(),m=await(r.runtime??Ee)(o.node,p,JSON.stringify(t.call),e.signal)}else if(d)m=await(r.delegate??X)(d,t.call,e.signal);else m=await Be(o,t.call,e.signal,r)}finally{n()}if(a)m=await ne({runId:e.runId,call:t.call,identity:c,output:m,signal:e.signal},s);return _e(m,e.runId,i)}
|
|
701
|
-
export{
|
|
852
|
+
`;import{spawn as Ge}from"child_process";import{basename as Me}from"path";var Ke="__desktop-call",ze="/usr/bin/setpriv",Je=27262976,je=8192,Ye=2000;function U(e){return Boolean(e)&&typeof e==="object"&&!Array.isArray(e)}function Xe(e){try{return JSON.parse(e)}catch{return null}}function Ve(){return[process.execPath,...Me(process.execPath).startsWith("bun")&&process.argv[1]?[process.argv[1]]:[],Ke]}function Ze(e,r,t,i={}){t.throwIfAborted();let o=i.command??Ve();return new Promise((s,c)=>{let a=(i.spawnProcess??Ge)(ze,[`--reuid=${e.uid}`,`--regid=${e.gid}`,"--clear-groups","--no-new-privs","--",...o],{cwd:e.home,detached:!0,stdio:["pipe","pipe","pipe"],env:{HOME:e.home,USER:e.username,LOGNAME:e.username,PATH:"/usr/local/bin:/usr/bin:/bin"}}),l=[],d=0,n="",u=null,m=!1,_,g=(w)=>{try{process.kill(-a.pid,w)}catch{a.kill(w)}},N=(w)=>{u??=w,g("SIGTERM"),_??=setTimeout(()=>g("SIGKILL"),Ye)},y=()=>N(new p("cancelled","Reason cancelled the desktop operation."));t.addEventListener("abort",y,{once:!0});let h=(w)=>{if(m)return;m=!0,clearTimeout(_),t.removeEventListener("abort",y),w()};if(a.stdout.on("data",(w)=>{if(d+=w.byteLength,d>Je)N(new p("desktop_delegate_failed","Reason's desktop reply is too large."));else l.push(w)}),a.stderr.setEncoding("utf8").on("data",(w)=>{n=(n+w).slice(-je)}),a.stdin.on("error",()=>{}),a.once("error",()=>h(()=>c(u??new p("desktop_delegate_unavailable","Reason could not start its desktop as the desktop account.")))),a.once("close",(w,Ue)=>h(()=>{if(u)return c(u);let b=Xe(Buffer.concat(l).toString("utf8"));if(U(b)&&b.ok===!0&&U(b.result))return s(b.result);let R=U(b)&&b.ok===!1&&typeof b.code==="string"&&typeof b.message==="string"?new p(b.code.slice(0,120),b.message.slice(0,2000)):null,X=`exited ${w??Ue}${R?"":" with no reply"}`,V=n.trim().split(`
|
|
853
|
+
`).at(-1)?.slice(-300)??"";if(!R||R.code==="desktop_delegate_failed")process.stderr.write(`Reason worker: desktop call ${X}${n?`: ${n.trim().slice(-500)}`:""}
|
|
854
|
+
`);if(R)return c(R);c(new p("desktop_delegate_failed",`Reason's desktop operation failed (${X}${V?`: ${V}`:""}).`))})),t.aborted)y();a.stdin.end(JSON.stringify(r))})}async function H(e,r,t,i={}){let o=await Ze(e,{op:"automation",call:r},t,i);if(!Number.isSafeInteger(o.code)||typeof o.stdout!=="string"||typeof o.stderr!=="string")throw new p("desktop_delegate_failed","Reason's desktop reply is malformed.");return{code:o.code,stdout:Buffer.from(o.stdout,"base64"),stderr:o.stderr}}import{execFile as He,spawn as Qe}from"child_process";import{closeSync as et,mkdirSync as tt,openSync as rt}from"fs";import{dirname as A,join as it}from"path";import{promisify as ot}from"util";var st=ot(He),Q="x-apple.systempreferences:com.apple.preference.security",at={accessibility:`${Q}?Privacy_Accessibility`,screen:`${Q}?Privacy_ScreenCapture`},nt=64,$=new Map;function k(e,r){let t=$.get(e);if(t?.has(r))return!1;if(!t){if($.size>=nt)$.delete($.keys().next().value);t=new Set,$.set(e,t)}return t.add(r),!0}function ct(){let e=x(),r=ne(ae(e),process.env),t=it(e,".local","share","reason","desktop-install.log");tt(A(t),{recursive:!0,mode:448});let i=rt(t,"a",384);try{let o=Qe(r,["desktop","install"],{detached:!0,stdio:["ignore",i,i],env:{...process.env,REASON_DESKTOP_BACKGROUND:"1"}});o.on("error",()=>{return}),o.unref()}finally{et(i)}}var P={open:async(e,r)=>{await st("/usr/bin/open",e,{signal:r,timeout:1e4,maxBuffer:8192})},request:(e,r)=>oe(e,r),tile:se,installDesktop:ct},ee=!1;async function te(e,r,t){try{await r.open(["-a","Google Chrome",e],t)}catch{t.throwIfAborted(),await r.open([e],t)}}async function ce(e,r,t,i){if(await t.open([at[r]],i).catch(()=>{}),e[0]&&!i.aborted)t.tile(A(A(A(e[0]))),r)}async function lt(e,r,t,i,o){for(let s of t){if(!k(e,`grant:${s}`))continue;o.throwIfAborted(),await i.request(r,s).catch(()=>null),await ce(r,s,i,o)}}var ut={name:"open_tab",description:"Open a web page in the user's own Chrome on this Mac. Reason cannot read, screenshot or click in that tab, and no tab_id is returned: browser control needs Reason's Chrome extension. An actual browser call opens its setup page.",inputSchema:{type:"object",properties:{url:{type:"string",description:"An http or https URL."}},required:["url"],additionalProperties:!1}};function re(e){return{code:0,stderr:"",stdout:Buffer.from(JSON.stringify({ok:!0,...e}))}}function dt(e){if(typeof e!=="string")return null;try{let r=new URL(e);return r.protocol==="https:"||r.protocol==="http:"?r.href:null}catch{return null}}async function le(e,r=P){let{call:t,runId:i,signal:o}=e;if(t.kind==="browser"){if(t.operation==="discover")return re({result:{tools:[ut]}});if(t.operation!=="call")throw new p("automation_browser_setup_required","Browser control is not set up on this Mac yet. Request a browser operation or connect Chrome from Reason to set it up.")}if(e.desktopMissing&&!ee){ee=!0;try{r.installDesktop()}catch{}}if(t.kind==="computer"){if(e.identity.length>0&&k(i,"grant:probe")){let a=await r.request(e.identity).catch(()=>null),l=a?[...a.accessibility?[]:["accessibility"],...a.screen?[]:["screen"]]:[];for(let d of l)k(i,`grant:${d}`);for(let d of l)await ce(e.identity,d,r,o)}throw new p("automation_computer_setup_required","Computer use is not set up on this Mac yet; Reason asked macOS for any missing permission.")}if(k(i,"page:chrome-extension"))await te(ie,r,o).catch(()=>{});let s=t.arguments,c=t.operation==="call"&&t.tool==="open_tab"&&s&&typeof s==="object"&&!Array.isArray(s)?dt(s.url):null;if(!c)throw new p("automation_browser_setup_required","Browser control is not set up on this Mac yet; Reason opened its Chrome Web Store page. open_tab still opens pages.");return await te(c,r,o),re({result:{content:[{type:"text",text:JSON.stringify({opened:c,browser:"the user's Chrome",controllable:!1,note:"Opened for the user to see. Reason cannot read or act in this tab until Reason's Chrome extension is added (its Chrome Web Store page is open)."})}]}})}async function ue(e,r=P){if(e.call.kind!=="computer"||e.call.operation!=="permission_status"||e.output.code!==0||e.identity.length===0)return e.output;let t;try{t=JSON.parse(e.output.stdout.toString("utf8"))}catch{return e.output}if(!t||typeof t!=="object"||Array.isArray(t))return e.output;let i=t.permissions;if(!i||typeof i!=="object")return e.output;let o=i,s=[...o.accessibility==="missing"?["accessibility"]:[],...o.screenRecording==="missing"?["screen"]:[]];if(s.length===0)return e.output;return await lt(e.runId,e.identity,s,r,e.signal),{...e.output,stdout:Buffer.from(JSON.stringify({...t,requested:s}))}}var K=172032,It=18874368,Nt=8192,Ot=65536,Tt=55000,vt=60000,Rt=4,$t=40000,At=/^[0-9a-f-]{36}$/,me=Z,kt=Te();function W(e){return Boolean(e)&&typeof e==="object"&&!Array.isArray(e)}function E(){throw new p("invalid_automation_request","Reason automation request is malformed.")}function $e(e){let r=Object.keys(e).sort().join(",");if(r==="call"||r==="browser,call"){let t=e.call,i=r==="browser,call";if(!W(t)||t.version!==1||t.kind!=="computer"&&t.kind!=="browser"||i&&(e.browser!==be||t.kind!=="browser")||JSON.stringify(t).length>Ot)E();return{call:t,userChrome:i}}if(r==="offset,output_id"){if(typeof e.output_id!=="string"||!At.test(e.output_id)||!Number.isSafeInteger(e.offset)||e.offset<0)E();return{output_id:e.output_id,offset:e.offset}}return E()}function Wr(e=process.platform,r=v){if(e==="darwin")return!0;return(e==="linux"||e==="win32")&&r()?.features.computer===!0}var Pt="__computer-use";function Ct(e){let r=(t)=>t?"granted":"missing";return`Permissions: accessibility=${r(e.accessibility)}, screenRecording=${r(e.screen)}
|
|
855
|
+
`}function Wt(e,r,t,i={stdin:process.stdin,stdout:process.stdout}){return new Promise((o)=>{let s=S(e,r,{env:t,stdio:["pipe","pipe","inherit"]}),c=(n)=>{s.kill(n)},a=["SIGTERM","SIGINT","SIGHUP"];for(let n of a)process.on(n,c);i.stdin.pipe(s.stdin),s.stdin.on("error",()=>{return}),s.stdout.pipe(i.stdout,{end:!1});let l=!1,d=(n)=>{if(l)return;l=!0;for(let u of a)process.off(u,c);i.stdin.unpipe(s.stdin),i.stdout.write("",()=>o(n))};s.once("error",()=>d(127)),s.once("close",(n)=>d(n??1))})}async function Er(e,r={}){let t=r.stderr??process.stderr,i=(r.identity??J)(),o=(r.components??v)();if(i.length===0||o?.platform!=="darwin-arm64")return t.write(`Reason computer use: Reason's background identity cannot run Open Computer Use here (computer_use_identity_unavailable)
|
|
856
|
+
`),1;if(e.length===1&&e[0]==="doctor"){let a=await(r.grants??Ne)(i);if(!a)return t.write(`Reason computer use: Reason's permissions could not be read (computer_use_permission_status_unavailable)
|
|
857
|
+
`),1;return(r.stdout??process.stdout).write(Ct(a)),0}if(e.length!==1||e[0]!=="mcp")return t.write(`Usage: reason __computer-use mcp|doctor
|
|
858
|
+
`),2;let[s,...c]=i;return(r.run??Wt)(s,[...c,o.ocu,"mcp"],{...process.env,OPEN_COMPUTER_USE_DISABLE_APP_AGENT_PROXY:"1"})}function qr(e=v){return e()?.userChrome??{code:"user_chrome_browser_use_missing"}}function Ae(e,r,t,i){return new Promise((o)=>{let s=S(e,r,{env:t,stdio:"ignore",windowsHide:!0}),c=setTimeout(()=>{s.kill("SIGKILL"),o(-1)},i);s.once("error",()=>{clearTimeout(c),o(-1)}),s.once("exit",(a)=>{clearTimeout(c),o(a??-1)})})}function Et(e,r,t,i){return new Promise((o)=>{let s=S(e,r,{env:t,stdio:["ignore","pipe","ignore"],windowsHide:!0}),c="";s.stdout.setEncoding("utf8").on("data",(l)=>{c+=l});let a=setTimeout(()=>{s.kill("SIGKILL"),o(null)},i);s.once("error",()=>{clearTimeout(a),o(null)}),s.once("close",(l)=>{clearTimeout(a),o(l===0?c:null)})})}function qt(e){return T(e)?f(F(),"open-browser-use"):"/tmp/open-browser-use"}function T(e){return e.platform==="win32-x64"||e.platform==="win32-arm64"}var Dt=/^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/,Ft=33554432;function Bt(e,r){let t;try{t=e===null?null:JSON.parse(e)}catch{return null}let i=W(t)&&W(t.result)?t.result.metadata:null;if(!W(i)||i.extensionId!==r)return null;return typeof i.extensionInstanceId==="string"&&Dt.test(i.extensionInstanceId)?i.extensionInstanceId:null}async function ke(e,r,t){let i=t.storages.map((a)=>{try{return D(a).filter((l)=>l.endsWith(".log")||l.endsWith(".ldb")).map((l)=>f(a,l))}catch{return[]}}),o;try{o=i.some((a)=>a.length>0)?D(t.socketDir).filter((a)=>a.endsWith(".sock")):[]}catch{return[]}let s=[];for(let a of o){let l=f(t.socketDir,a),d=Bt(await Et(e,["info","--socket",l,"--timeout","2s"],r,5000),t.extensionId);if(d)s.push({instance:d,socket:l})}let c=[];for(let[a,l]of(s.length>0?i:[]).entries())for(let d of l)try{if(bt(d).size>Ft)continue;let n=j(d),u=s.find((m)=>n.includes(m.instance));if(u){c.push({storage:t.storages[a],...u});break}}catch{}return c}async function Ut(e,r,t){return(await ke(e,r,t))[0]?.instance??null}function Pe(e,r,t){return Ut(e.nativeHost,r,{socketDir:qt(e),extensionId:M,storages:[f(t,"browser-profile","Default","Local Extension Settings",M)]})}var _e=/^(Default|Profile ([0-9]+))$/;async function Lt(e,r,t=x(),i=Y){let o=f(t,"Library","Application Support","Google","Chrome"),s=[];try{s=D(o)}catch(n){if(n.code==="EPERM")throw new p("browser_use_chrome_access_denied","macOS blocked Reason from reading Chrome's profiles. Allow Full Disk Access for Reason on this Mac and try again.")}let c=(n)=>Number(_e.exec(n)?.[2]??-1),a=s.filter((n)=>_e.test(n)&&q(f(o,n,"Extensions",C))).sort((n,u)=>c(n)-c(u)),l=(n)=>f(o,n,"Local Extension Settings",C);return(await ke(e,r,{socketDir:i,extensionId:C,storages:a.map(l)})).map(({storage:n,instance:u,socket:m})=>({profile:a.find((_)=>l(_)===n),instance:u,socket:m}))}async function Gt(e,r,t=x(),i=Y){let o=(await Lt(e,r,t,i))[0]?.instance;if(!o)throw new p("automation_user_chrome_not_connected","No Chrome profile on this Mac is connected to Reason. Open Chrome with the Reason extension, then try again.");return o}function he(e){return new Promise((r)=>{let t=St({path:e}),i=(o)=>{t.destroy(),r(o)};t.setTimeout(1000,()=>i(!1)),t.once("error",()=>i(!1)),t.once("connect",()=>i(!0))})}async function Ce(e,r){let t=Date.now()+r;while(Date.now()<t){if(await e())return!0;await new Promise((i)=>setTimeout(i,200))}return!1}var L=new Map;function G(e,r){let t=L.get(e);if(!t)t=r().finally(()=>L.delete(e)),L.set(e,t);return t}async function Mt(e,r){if(await he(e))return;if(gt(e,{force:!0}),await Ae("dbus-daemon",["--session",`--address=unix:path=${e}`,"--fork"],r,1e4)!==0||!await Ce(()=>he(e),5000))throw new p("automation_unavailable","Reason could not start the desktop session bus.")}async function we(e,r,t){let i=e.platform==="darwin-arm64"||T(e)?async()=>await Pe(e,r,t)!==null:async()=>await Ae(e.nativeHost,["info"],r,5000)===0;if(await i())return;let o=["--profile-directory=Default",`--load-extension=${e.extensionDir}`,"--no-first-run","--no-default-browser-check","--window-size=1280,800","about:blank"],s,c=null,a=0;if(e.platform==="darwin-arm64"){let n=f(t,"browser-profile");O(n);let u=f(n,"NativeMessagingHosts");pe(u,{recursive:!0,mode:448});let m=z(e.platform).nativeHostManifests[0];de(m,f(u,fe(m)));let _=e.browser.slice(0,e.browser.indexOf(".app/")+4),g=o.filter((N)=>N!=="about:blank").concat("--no-startup-window","--use-mock-keychain");s=S("/usr/bin/open",["-g","-n","-a",_,"--args",`--user-data-dir=${n}`,...g],{env:r,stdio:"ignore"})}else if(T(e)){let n=f(t,"browser-profile");O(n),pt(xe("icacls"),[B(e.browser),"/grant","*S-1-15-2-1:(OI)(CI)(RX)","*S-1-15-2-2:(OI)(CI)(RX)"],{stdio:"ignore",windowsHide:!0,timeout:60000});let u=o.filter((m)=>m!=="about:blank").concat("--no-startup-window","--keep-alive-for-test");s=S(e.browser,[`--user-data-dir=${n}`,...u],{detached:!0,stdio:"ignore",env:r})}else{let n=f(r.HOME,".config","google-chrome"),u=f(n,"NativeMessagingHosts");pe(u,{recursive:!0,mode:448});let m=z(e.platform).nativeHostManifests[0];de(m,f(u,fe(m)));let _=process.geteuid?.()===0?["--no-sandbox"]:[];c=f(t,"browser.log");let g=ht(c,"a",384);a=_t(g).size,s=S(e.browser,[`--user-data-dir=${n}`,...o,..._,"--force-renderer-accessibility"],{detached:!0,stdio:["ignore",g,g],env:{...r,ACCESSIBILITY_ENABLED:"1"}}),mt(g)}let l=!1;s.once("error",()=>{l=!0}),s.once("exit",(n)=>{l||=n!==0}),s.unref();let d=!1;if(await Ce(async()=>l||(d=await i()),$t),!d){if(c&&j(c).subarray(a).toString("utf8").includes("No usable sandbox"))throw new p("automation_browser_sandbox_unavailable","Chromium found no usable sandbox on this machine. Run the worker as a non-root user with unprivileged user namespaces enabled, or in a container with seccomp unconfined.");throw new p("automation_browser_unavailable","Reason could not connect the desktop browser.")}}async function Dr(e){await qe(e,!0)}function Fr(e){return We(e,Ee(e))}function We(e,r){return e.platform==="darwin-arm64"||T(e)?f(r,"browser-profile"):f(r,"home",".config","google-chrome")}function Ee(e){let r=f(e.root,"automation");if(!q(r)||!Kt(e.automation))return e.automation;if(!zt(We(e,r)))try{ve(r,e.automation)}catch{}return q(r)?r:e.automation}function Kt(e){try{return D(e).length===0}catch(r){return r.code==="ENOENT"}}function zt(e){let r;try{r=wt(f(e,"SingletonLock"))}catch{return!1}let t=Number(r.slice(r.lastIndexOf("-")+1));if(!Number.isSafeInteger(t)||t<=0)return!0;try{return process.kill(t,0),!0}catch(i){return i.code==="EPERM"}}async function qe(e,r){ye({root:e.root,automation:e.automation,extensionDir:e.extensionDir});let t=Ee(e);O(t);let i=Re().username,o={USER:i,LOGNAME:i,REASON_AUTOMATION_OCU:e.ocu,REASON_AUTOMATION_OBU:e.nativeHost};if(e.platform==="darwin-arm64"||T(e)){let n=T(e)?{...o,...Jt(),HOME:x()}:{...o,HOME:x(),PATH:`${B(e.node)}:/usr/bin:/bin:/usr/sbin:/sbin`,REASON_AUTOMATION_OCU:process.execPath,REASON_AUTOMATION_OCU_SUBCOMMAND:Pt};if(!r)return n;await G("browser",()=>we(e,n,t));let u=await Pe(e,n,t);if(!u)throw new p("automation_browser_unavailable","Reason could not connect the desktop browser.");return{...n,REASON_AUTOMATION_OBU_INSTANCE:u,REASON_AUTOMATION_BACKGROUND_TABS:"1"}}let s=await Be(),c=f(t,"home"),a=f(t,"runtime");O(c),O(a);let l=f(t,"bus"),d={...o,HOME:c,PATH:`${B(e.node)}:/usr/bin:/bin`,DISPLAY:s.display,XAUTHORITY:s.xauthority,XDG_RUNTIME_DIR:a,DBUS_SESSION_BUS_ADDRESS:`unix:path=${l}`,...s.sound?{PULSE_SERVER:Oe(s.sound)}:{}};if(await G("bus",()=>Mt(l,d)),r)await G("browser",()=>we(e,d,t));return d}function Jt(){let e=process.env.SystemRoot??"C:\\Windows",r=Object.fromEntries(["SystemDrive","USERPROFILE","LOCALAPPDATA","APPDATA","ProgramData","ProgramFiles","PATHEXT","ComSpec","USERNAME","USERDOMAIN","COMPUTERNAME","NUMBER_OF_PROCESSORS","PROCESSOR_ARCHITECTURE","PSModuleAnalysisCachePath"].flatMap((i)=>process.env[i]?[[i,process.env[i]]]:[])),t=f(e,"System32");return{...r,SystemRoot:e,windir:e,TEMP:F(),TMP:F(),PATH:[t,f(t,"WindowsPowerShell","v1.0"),e].join(yt)}}async function jt(e,r,t){let i=Re().username,o={USER:i,LOGNAME:i,HOME:x(),PATH:`${B(e.node)}:/usr/bin:/bin:/usr/sbin:/sbin`,REASON_AUTOMATION_OBU:r,REASON_AUTOMATION_BACKGROUND_TABS:"1"},s=await Gt(r,o);return t.throwIfAborted(),{...o,REASON_AUTOMATION_OBU_INSTANCE:s}}function Yt(e){if(process.platform!=="win32")return["--input-type=module","--eval",e];let r=f(F(),`reason-automation-${ft("sha256").update(e).digest("hex").slice(0,16)}.mjs`);if(!q(r)||j(r,"utf8")!==e){let t=`${r}.${process.pid}.tmp`;xt(t,e,{mode:384}),ve(t,r)}return[r]}function De(e,r,t,i){if(typeof me!=="string")return Promise.reject(new p("automation_unavailable","This Reason build has no automation runtime."));let o=me;return new Promise((s,c)=>{let a=S(e,Yt(o),{env:{...r,REASON_CLOUD_GATEWAY_EXEC:"1",REASON_AUTOMATION_INLINE_RESULT:"1"},stdio:["pipe","pipe","pipe"],detached:process.platform!=="win32",windowsHide:!0}),l=[],d=0,n="",u=null,m=!1,_=(h)=>{if(u??=h,process.platform==="win32"&&a.pid){S(f(process.env.SystemRoot??"C:\\Windows","System32","taskkill.exe"),["/pid",String(a.pid),"/t","/f"],{stdio:"ignore",windowsHide:!0}).once("error",()=>a.kill("SIGKILL"));return}try{process.kill(-a.pid,"SIGKILL")}catch{a.kill("SIGKILL")}},g=(h)=>{if(m)return;m=!0,clearTimeout(N),i.removeEventListener("abort",y),h()},N=setTimeout(()=>_(new p("automation_timed_out","Reason automation did not finish in time.")),Tt),y=()=>_(new p("cancelled","Reason cancelled the automation call."));if(i.addEventListener("abort",y,{once:!0}),a.stdout.on("data",(h)=>{if(d+=h.byteLength,d>It)_(new p("automation_output_too_large","Reason automation output is too large."));else l.push(h)}),a.stderr.setEncoding("utf8").on("data",(h)=>{n=(n+h).slice(-Nt)}),a.stdin.on("error",()=>{}),a.once("error",()=>g(()=>c(u??new p("automation_unavailable","Reason could not start the automation runtime.")))),a.once("close",(h)=>g(()=>{if(u)c(u);else s({code:h??1,stdout:Buffer.concat(l),stderr:n})})),i.aborted)y();a.stdin.end(t)})}var I=new Map;function Xt(e,r,t){for(let[o,s]of I)if(s.expiresAt<=t)I.delete(o);while(I.size>=Rt)I.delete(I.keys().next().value);let i=Te();return I.set(i,{runId:e,bytes:r,expiresAt:t+vt}),i}async function Fe(e,r,t,i={}){let o=await(i.environment??qe)(e,r.kind==="browser");return t.throwIfAborted(),await(i.runtime??De)(e.node,o,JSON.stringify(r),t)}async function Br(e,r){let t=$e({call:e});if(!("call"in t))E();let i=v();if(!i?.features.computer||t.call.kind==="browser"&&!i.features.browser)throw new p("automation_unavailable","Run `reason desktop install` on this machine to enable computer and browser use.");return await Fe(i,t.call,r)}function ge(e,r,t){let i=e.stdout.byteLength>K?Xt(r,e.stdout,t):void 0;return{code:e.code,stderr:e.stderr,instance_id:kt,output_bytes:e.stdout.byteLength,chunk:e.stdout.subarray(0,K).toString("base64"),...i?{output_id:i}:{}}}async function Ur(e,r={}){let t=$e(e.payload),i=(r.now??Date.now)();if("output_id"in t){let _=I.get(t.output_id);if(!_||_.runId!==e.runId||_.expiresAt<=i||t.offset>_.bytes.byteLength)throw new p("automation_output_unavailable","Reason automation output expired.");return{chunk:_.bytes.subarray(t.offset,t.offset+K).toString("base64")}}let o=(r.components??v)(),s=(r.platform??process.platform)==="darwin",c=s?(r.macIdentity??J)():[],a=r.macSetup??P,l=!o?.features.computer||t.call.kind==="browser"&&!t.userChrome&&!o.features.browser;if(s&&(l||c.length===0||t.call.kind==="browser"&&t.userChrome&&!e.userChrome))return ge(await le({runId:e.runId,call:t.call,identity:c,desktopMissing:l,signal:e.signal},a),e.runId,i);if(!o?.features.computer)throw new p("automation_unavailable","Run `reason desktop install` on this machine to enable computer and browser use.");let d=t.userChrome?e.userChrome:void 0;if(t.userChrome&&!d)throw new p("automation_user_chrome_unavailable","Your own Chrome is not enabled on this computer: run `reason desktop install` on this Mac (and `reason connect --user-chrome on` if you turned it off).");if(t.call.kind==="browser"&&!d&&!o.features.browser)throw new p("automation_browser_not_installed",!o.platform.startsWith("linux")?"Browser use is unavailable on this machine: re-run `reason desktop install`.":"Browser use is unavailable on this machine: install a non-snap Chromium at /usr/bin/chromium, then re-run `reason desktop install`.");e.signal.throwIfAborted();let n=await Ie(e.runId,e.signal,r.now),u="account"in r?r.account??null:Se(),m;try{if(d){let _=await(r.userChromeEnvironment??jt)(o,d,e.signal);e.signal.throwIfAborted(),m=await(r.runtime??De)(o.node,_,JSON.stringify(t.call),e.signal)}else if(u)m=await(r.delegate??H)(u,t.call,e.signal);else m=await Fe(o,t.call,e.signal,r)}finally{n()}if(s)m=await ue({runId:e.runId,call:t.call,identity:c,output:m,signal:e.signal},a);return ge(m,e.runId,i)}
|
|
859
|
+
export{Ze as Cd,K as Dd,$e as Ed,Wr as Fd,Wt as Gd,Er as Hd,qr as Id,Lt as Jd,Gt as Kd,Dr as Ld,Fr as Md,Br as Nd,Ur as Od};
|