broods 0.34.1 → 0.36.0
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/dist/account.d.ts +2 -1
- package/dist/account.js +1 -1
- package/dist/chunk-09w5n6hc.js +1 -0
- package/dist/chunk-54pn8m91.js +15 -0
- package/dist/chunk-5tnnqapc.js +468 -0
- package/dist/chunk-6s753azk.js +1 -0
- package/dist/chunk-gvrqg36n.js +1 -0
- package/dist/{chunk-yd3vh7k7.js → chunk-mqsvqhkj.js} +2 -2
- package/dist/chunk-ny9c9z9g.js +0 -0
- package/dist/chunk-q2n2mxeg.js +5 -0
- package/dist/chunk-r4wpy43p.js +4 -0
- package/dist/chunk-s3cv33em.js +1 -0
- package/dist/cli/index.js +124 -100
- package/dist/index.d.ts +34 -9
- package/dist/index.js +1 -1
- package/package.json +2 -2
- package/dist/chunk-1vs3cf0w.js +0 -1
- package/dist/chunk-aewcp4db.js +0 -1
- package/dist/chunk-wgwmcq6q.js +0 -5
- package/dist/chunk-xg98kc3q.js +0 -15
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import{I}from"./chunk-q2n2mxeg.js";import{ce,le,e,o,i,l,r,t,u,S,s,p,n}from"./cli/index.js";import{spawn as V}from"node:child_process";import{hostname as ee}from"node:os";import{performance as L}from"node:perf_hooks";var j=["cursor_position","double_click","hold_key","key","left_click","left_click_drag","left_mouse_down","left_mouse_up","middle_click","mouse_move","right_click","screenshot","scroll","triple_click","type","wait","zoom"];var _={badFrame:{code:4400,reason:"Malformed frame"},replaced:{code:4409,reason:"Replaced by a newer connection"},unauthorized:{code:4401,reason:"Unauthorized; check BROODS_API_KEY"},unknownSandbox:{code:4404,reason:"No machine sandbox with that name in this account"}},N="/v1/machines/ws",H=t({action:p(j),coordinate:r(o().int()).length(2).optional().describe("[x, y] in screenshot pixels for mouse actions."),start_coordinate:r(o().int()).length(2).optional().describe("[x, y] where a left_click_drag starts."),text:e().optional().describe("Text for type, the key chord for key and hold_key, or modifiers to hold during a click, drag or scroll."),scroll_direction:p(["down","left","right","up"]).optional(),scroll_amount:o().int().min(1).optional().describe("Scroll clicks, default 3."),duration:o().min(0).max(300).optional().describe("Seconds for wait and hold_key."),region:r(o().int()).length(4).optional().describe("[x0, y0, x1, y1] of the screenshot to zoom into."),repeat:o().int().min(1).max(100).optional().describe("How many times to press the key.")}),P=H.extend({type:n("computer"),id:e()}),B=t({type:n("computer-result"),id:e(),text:e().optional(),image:t({data:e(),mediaType:e()}).optional(),app:e().optional(),error:e().optional()}),U=t({type:n("exec"),id:e(),code:e(),cwd:e().optional(),env:s(e(),e()).optional(),timeoutSeconds:o().positive(),outputLimitBytes:o().positive()}),K=t({type:n("hello"),sandbox:e().min(1),hostname:e().optional(),platform:e().optional(),computer:i().optional(),mcp:r(e()).optional()}),W=t({type:n("mcp-call"),id:e(),server:e(),tool:e(),args:s(e(),l())}),G=t({type:n("mcp-list"),id:e(),server:e()}),J=t({type:n("mcp-result"),id:e(),result:u({content:r(l())}).optional(),error:e().optional()}),q=t({type:n("mcp-tools"),id:e(),tools:r(u({name:e(),inputSchema:s(e(),l())})).optional(),error:e().optional()}),X=t({type:n("ready"),sandboxId:e()}),Y=t({type:n("result"),id:e(),exitCode:o().nullable(),stdout:e(),stderr:e(),durationMs:o(),timedOut:i(),truncated:i()}),Z=S("type",[P,U,W,G,X]),me=S("type",[B,K,J,q,Y]);function O(c){let a=new URL(N,c);return a.protocol=a.protocol==="https:"?"wss:":"ws:",a.toString()}function D(c){return Q(Z,c)}function Q(c,a){if(typeof a!=="string")return null;try{let d=c.safeParse(JSON.parse(a));return d.success?d.data:null}catch{return null}}var te=new Set([_.replaced.code,_.unauthorized.code,_.unknownSandbox.code]),R=72,T=30000,z=1000;function oe(c,a,d){return new Promise((y)=>{let m=L.now(),f=new C(c.outputLimitBytes),b=new C(c.outputLimitBytes),w=!1,x=!1,v=(F,E)=>{if(x)return;if(x=!0,clearTimeout(M),d?.removeEventListener("abort",k),E)b.append(Buffer.from(`${E}
|
|
2
|
+
`));y({type:"result",id:c.id,exitCode:F,stdout:f.text(),stderr:b.text(),durationMs:Math.round(L.now()-m),timedOut:w,truncated:f.truncated||b.truncated})},h=V("bash",["-lc",c.code],{cwd:c.cwd??a,env:{...process.env,...c.env},detached:!0,stdio:["ignore","pipe","pipe"]}),g=()=>{if(!h.pid)return;try{process.kill(-h.pid,"SIGKILL")}catch{h.kill("SIGKILL")}},M=setTimeout(()=>{w=!0,g()},c.timeoutSeconds*1000),k=()=>{g(),v(null,"stopped: the daemon closed its socket")};if(d?.addEventListener("abort",k,{once:!0}),h.stdout.on("data",(F)=>f.append(F)),h.stderr.on("data",(F)=>b.append(F)),h.on("error",(F)=>v(null,F.message)),h.on("close",(F)=>v(F)),d?.aborted)k()})}async function Fe(c){let a=le(),d=c.mcpFile?await ie(c.mcpFile,c.log):null,y=c.computer?await ne(c.log):null,m=z;try{while(!c.signal.aborted){let f=Date.now(),b=await ae(c,a,y,d);if(c.signal.aborted)return;if(te.has(b.code))throw Error(b.reason||`core closed the socket (${b.code})`);if(Date.now()-f>T)m=z;c.log(`disconnected (${b.reason||b.code}), reconnecting in ${Math.round(m/1000)}s`),await ce(m,c.signal),m=Math.min(m*2,T)}}finally{y?.stop(),await d?.stop()}}class C{#o=[];#e;#t=0;truncated=!1;constructor(c){this.#e=c}append(c){if(this.#t>=this.#e){this.truncated=!0;return}let a=this.#e-this.#t;if(c.byteLength>a){this.#o.push(c.subarray(0,a)),this.#t=this.#e,this.truncated=!0;return}this.#o.push(c),this.#t+=c.byteLength}text(){let c=Buffer.concat(this.#o).toString("utf8");return this.truncated?`${c}
|
|
3
|
+
[output truncated]`:c}}function re(c){let a=[c.action];if(c.coordinate)a.push(`at ${c.coordinate.join(",")}`);if(c.text!==void 0)a.push(JSON.stringify(A(c.text)));if(c.region)a.push(`region ${c.region.join(",")}`);return a.join(" ")}function A(c){let a=c.trim().split(`
|
|
4
|
+
`)[0]??"";return a.length>R?`${a.slice(0,R)}…`:a}async function ne(c){let{startDesktop:a}=await import("./chunk-5tnnqapc.js"),{display:d,driver:y,permissions:m}=await a(!1);if(c(`computer use on, ${d.width}x${d.height} screenshots`),!m.screenRecording||!m.accessibility)c(" screen recording or accessibility is missing, run `broods machine --doctor --request`");return y}async function ie(c,a){let{McpHost:d,readMcpServersFile:y}=await import("./chunk-09w5n6hc.js"),m=new d(y(c),a);return a(`mcp servers from ${c}: ${m.names().join(", ")}`),m}async function se(c,a,d){try{if(c.type==="mcp-list"){let m=await a.listTools(c.server);return d(` mcp ${c.server}: ${m.length} tools`),{type:"mcp-tools",id:c.id,tools:m}}d(` mcp ${c.server}.${c.tool}`);let y=await a.callTool(c.server,c.tool,c.args);return{type:"mcp-result",id:c.id,result:y}}catch(y){let m=y instanceof Error?y.message:String(y);return d(` mcp ${c.server}: ${m}`),{type:c.type==="mcp-call"?"mcp-result":"mcp-tools",id:c.id,error:m}}}function ae(c,a,d,y){return new Promise((m)=>{let f=new a(O(c.baseUrl),I(c.apiKey)),b=new AbortController,w=()=>f.close(1000,"daemon stopped"),x=(h)=>{if(f.readyState===f.OPEN)f.send(JSON.stringify(h))},v=(h,g)=>{c.signal.removeEventListener("abort",w),b.abort(),m({code:h,reason:g})};c.signal.addEventListener("abort",w,{once:!0}),f.onopen=()=>x({type:"hello",sandbox:c.sandbox,hostname:ee(),platform:process.platform,computer:d!==null,mcp:y?.names()}),f.onmessage=(h)=>{let g=D(h.data);if(g?.type==="ready"){c.log(`connected as ${c.sandbox} (${g.sandboxId})`);return}if(g?.type==="computer"&&d){c.log(` ${re(g)}`),d.run(g).then((M)=>{if(M.error)c.log(` error: ${M.error}`);x(M)});return}if((g?.type==="mcp-call"||g?.type==="mcp-list")&&y){se(g,y,c.log).then(x);return}if(g?.type!=="exec")return;c.log(`$ ${A(g.code)}`),oe(g,c.cwd,b.signal).then((M)=>{c.log(` exit ${M.exitCode??"none"} in ${M.durationMs}ms${M.timedOut?" (timed out)":""}`),x(M)})},f.onerror=()=>v(1006,"connection failed"),f.onclose=(h)=>v(h.code,h.reason)})}export{Fe as runMachineDaemon};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{y,ue,de,Re}from"./cli/index.js";var c=()=>{let a={string:{unit:"characters",verb:"to have"},file:{unit:"bytes",verb:"to have"},array:{unit:"items",verb:"to have"},set:{unit:"items",verb:"to have"},map:{unit:"entries",verb:"to have"}};function n(t){return a[t]??null}let d={regex:"input",email:"email address",url:"URL",emoji:"emoji",uuid:"UUID",uuidv4:"UUIDv4",uuidv6:"UUIDv6",nanoid:"nanoid",guid:"GUID",cuid:"cuid",cuid2:"cuid2",ulid:"ULID",xid:"XID",ksuid:"KSUID",datetime:"ISO datetime",date:"ISO date",time:"ISO time",duration:"ISO duration",ipv4:"IPv4 address",ipv6:"IPv6 address",mac:"MAC address",cidrv4:"IPv4 range",cidrv6:"IPv6 range",base64:"base64-encoded string",base64url:"base64url-encoded string",json_string:"JSON string",e164:"E.164 number",jwt:"JWT",template_literal:"input"},o={nan:"NaN"};return(t)=>{switch(t.code){case"invalid_type":{let e=o[t.expected]??t.expected,r=Re(t.input),l=o[r]??r;return`Invalid input: expected ${e}, received ${l}`}case"invalid_value":if(t.values.length===1)return`Invalid input: expected ${de(t.values[0])}`;return`Invalid option: expected one of ${ue(t.values,"|")}`;case"too_big":{let e=t.inclusive?"<=":"<",r=n(t.origin);if(r)return`Too big: expected ${t.origin??"value"} to have ${e}${t.maximum.toString()} ${r.unit??"elements"}`;return`Too big: expected ${t.origin??"value"} to be ${e}${t.maximum.toString()}`}case"too_small":{let e=t.inclusive?">=":">",r=n(t.origin);if(r)return`Too small: expected ${t.origin} to have ${e}${t.minimum.toString()} ${r.unit}`;return`Too small: expected ${t.origin} to be ${e}${t.minimum.toString()}`}case"invalid_format":{let e=t;if(e.format==="starts_with")return`Invalid string: must start with "${e.prefix}"`;if(e.format==="ends_with")return`Invalid string: must end with "${e.suffix}"`;if(e.format==="includes")return`Invalid string: must include "${e.includes}"`;if(e.format==="regex")return`Invalid string: must match pattern ${e.pattern}`;return`Invalid ${d[e.format]??t.format}`}case"not_multiple_of":return`Invalid number: must be a multiple of ${t.divisor}`;case"unrecognized_keys":return`Unrecognized key${t.keys.length>1?"s":""}: ${ue(t.keys,", ")}`;case"invalid_key":return`Invalid key in ${t.origin}`;case"invalid_union":if(t.options&&Array.isArray(t.options)&&t.options.length>0)return`Invalid discriminator value. Expected ${t.options.map((r)=>`'${r}'`).join(" | ")}`;return"Invalid input";case"invalid_element":return`Invalid value in ${t.origin}`;default:return"Invalid input"}}};function i(){return{localeError:c()}}y(i());
|