broods 0.35.0 → 0.36.1
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 +1 -1
- package/dist/account.js +1 -1
- package/dist/chunk-3ryp98a2.js +15 -0
- package/dist/chunk-5jh5xqdy.js +1 -0
- package/dist/chunk-5tnnqapc.js +468 -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-s6j5t96c.js +1 -0
- package/dist/chunk-vfqvarac.js +1 -0
- package/dist/chunk-wg45zxe9.js +1 -0
- package/dist/chunk-z9eykngk.js +4 -0
- package/dist/cli/index.js +124 -100
- package/dist/index.d.ts +28 -9
- package/dist/index.js +1 -1
- package/package.json +2 -2
- package/dist/chunk-gg06g89t.js +0 -1
- package/dist/chunk-grj4bad5.js +0 -15
- package/dist/chunk-vf5trjn9.js +0 -1
- package/dist/chunk-wgwmcq6q.js +0 -5
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import"./chunk-s6j5t96c.js";import{Pe,e,r,t,s}from"./cli/index.js";import{readFileSync as d}from"node:fs";import{dirname as m,resolve as p}from"node:path";import{Client as g}from"@modelcontextprotocol/client";import{StdioClientTransport as h}from"@modelcontextprotocol/client/stdio";var f={name:"broods-machine",version:"1.0.0"},u=t({command:e().min(1),args:r(e()).default([]),env:s(e(),e()).optional(),cwd:e().optional()}),w=t({mcpServers:s(e(),u).refine((n)=>Object.keys(n).length>0,"lists no MCP servers")});class y{#t=new Map;#e;#r;constructor(n,i){this.#r=n,this.#e=i}async callTool(n,i,o){return await(await this.#n(n)).callTool({name:i,arguments:o})}async listTools(n){return(await(await this.#n(n)).listTools()).tools}names(){return[...this.#r.keys()]}async stop(){let n=[...this.#t.values()];this.#t.clear(),await Promise.all(n.map((i)=>i.then((o)=>o.close()).catch(()=>{})))}#n(n){let i=this.#r.get(n);if(!i)return Promise.reject(Error(`no MCP server named "${n}" in the --mcp file`));let o=this.#t.get(n);if(o)return o;let c=(async()=>{this.#e(`mcp ${n}: ${[i.command,...i.args].join(" ")}`);let a=new h({...i,env:{...v(),...i.env},stderr:"inherit"});a.onclose=()=>{if(this.#e(`mcp ${n}: exited`),this.#t.get(n)===c)this.#t.delete(n)};let l=new g(f);return await l.connect(a),l})();return c.catch(()=>{if(this.#t.get(n)===c)this.#t.delete(n)}),this.#t.set(n,c),c}}function R(n){let i=p(n),o=w.safeParse(S(i));if(!o.success)throw Error(`${i}: ${Pe(o.error)}`);return new Map(Object.entries(o.data.mcpServers).map(([c,a])=>[c,a.cwd?{...a,cwd:p(m(i),a.cwd)}:a]))}function v(){let n={};for(let[i,o]of Object.entries(process.env))if(typeof o==="string")n[i]=o;return n}function S(n){try{return JSON.parse(d(n,"utf8"))}catch(i){throw Error(`could not read ${n}: ${i instanceof Error?i.message:String(i)}`)}}export{y as McpHost,R as readMcpServersFile};
|
|
@@ -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",P=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.")}),H=P.extend({type:n("computer"),id:e()}),U=t({type:n("computer-result"),id:e(),text:e().optional(),image:t({data:e(),mediaType:e()}).optional(),app:e().optional(),error:e().optional()}),B=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",[H,B,W,G,X]),me=S("type",[U,K,J,q,Y]);function O(a){let c=new URL(N,a);return c.protocol=c.protocol==="https:"?"wss:":"ws:",c.toString()}function D(a){return Q(Z,a)}function Q(a,c){if(typeof c!=="string")return null;try{let d=a.safeParse(JSON.parse(c));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(a,c,d){return new Promise((y)=>{let m=L.now(),f=new C(a.outputLimitBytes),b=new C(a.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:a.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",a.code],{cwd:a.cwd??c,env:{...process.env,...a.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()},a.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(a){let c=le(),d=a.mcpFile?await ie(a.mcpFile,a.log):null,y=a.computer?await ne(a.log):null,m=z;try{while(!a.signal.aborted){let f=Date.now(),b=await ae(a,c,y,d);if(a.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;a.log(`disconnected (${b.reason||b.code}), reconnecting in ${Math.round(m/1000)}s`),await ce(m,a.signal),m=Math.min(m*2,T)}}finally{y?.stop(),await d?.stop()}}class C{#o=[];#e;#t=0;truncated=!1;constructor(a){this.#e=a}append(a){if(this.#t>=this.#e){this.truncated=!0;return}let c=this.#e-this.#t;if(a.byteLength>c){this.#o.push(a.subarray(0,c)),this.#t=this.#e,this.truncated=!0;return}this.#o.push(a),this.#t+=a.byteLength}text(){let a=Buffer.concat(this.#o).toString("utf8");return this.truncated?`${a}
|
|
3
|
+
[output truncated]`:a}}function re(a){let c=[a.action];if(a.coordinate)c.push(`at ${a.coordinate.join(",")}`);if(a.text!==void 0)c.push(JSON.stringify(A(a.text)));if(a.region)c.push(`region ${a.region.join(",")}`);return c.join(" ")}function A(a){let c=a.trim().split(`
|
|
4
|
+
`)[0]??"";return c.length>R?`${c.slice(0,R)}…`:c}async function ne(a){let{startDesktop:c}=await import("./chunk-5tnnqapc.js"),{display:d,driver:y,permissions:m}=await c(!1);if(a(`computer use on, ${d.width}x${d.height} screenshots`),!m.screenRecording||!m.accessibility)a(" screen recording or accessibility is missing, run `broods machine --doctor --request`");return y}async function ie(a,c){let{McpHost:d,readMcpServersFile:y}=await import("./chunk-wg45zxe9.js"),m=new d(y(a),c);return c(`mcp servers from ${a}: ${m.names().join(", ")}`),m}async function se(a,c,d){try{if(a.type==="mcp-list"){let m=await c.listTools(a.server);return d(` mcp ${a.server}: ${m.length} tools`),{type:"mcp-tools",id:a.id,tools:m}}d(` mcp ${a.server}.${a.tool}`);let y=await c.callTool(a.server,a.tool,a.args);return{type:"mcp-result",id:a.id,result:y}}catch(y){let m=y instanceof Error?y.message:String(y);return d(` mcp ${a.server}: ${m}`),{type:a.type==="mcp-call"?"mcp-result":"mcp-tools",id:a.id,error:m}}}function ae(a,c,d,y){return new Promise((m)=>{let f=new c(O(a.baseUrl),I(a.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)=>{a.signal.removeEventListener("abort",w),b.abort(),m({code:h,reason:g})};a.signal.addEventListener("abort",w,{once:!0}),f.onopen=()=>x({type:"hello",sandbox:a.sandbox,hostname:ee(),platform:process.platform,computer:d!==null,mcp:y?.names()}),f.onmessage=(h)=>{let g=D(h.data);if(g?.type==="ready"){a.log(`connected as ${a.sandbox} (${g.sandboxId})`);return}if(g?.type==="computer"&&d){a.log(` ${re(g)}`),d.run(g).then((M)=>{if(M.error)a.log(` error: ${M.error}`);x(M)});return}if((g?.type==="mcp-call"||g?.type==="mcp-list")&&y){se(g,y,a.log).then(x);return}if(g?.type!=="exec")return;a.log(`$ ${A(g.code)}`),oe(g,a.cwd,b.signal).then((M)=>{a.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};
|