@octavus/agent 0.3.0 → 0.4.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.
@@ -1,4 +1,4 @@
1
1
  import{createRequire}from'module';const require=createRequire(import.meta.url);
2
- import{spawn as g}from"node:child_process";import{LocalVideoTrack as S,Room as T,RoomEvent as p,TrackPublishOptions as R,TrackSource as v,VideoBufferType as y,VideoFrame as I,VideoSource as _,dispose as b}from"@livekit/rtc-node";var P=10,V=6e4;function d(r){let i=process.env[r];if(!i)throw new Error(`Missing required env ${r}`);return i}async function k(){let r=d("LIVEKIT_URL"),i=d("LIVEKIT_TOKEN"),w=d("DISPLAY"),s=Number(process.env.SCREEN_WIDTH??"1920"),c=Number(process.env.SCREEN_HEIGHT??"1080"),u=s*c*4,e=new T;await e.connect(r,i,{autoSubscribe:!1,dynacast:!0});let l=new _(s,c),E=S.createVideoTrack("screen",l);await e.localParticipant?.publishTrack(E,new R({source:v.SOURCE_SCREENSHARE}));let f=!1,m=e.remoteParticipants.size>0,a=g("ffmpeg",["-loglevel","error","-f","x11grab","-draw_mouse","1","-framerate",String(P),"-video_size",`${s}x${c}`,"-i",w,"-pix_fmt","rgba","-f","rawvideo","-"],{stdio:["ignore","pipe","inherit"]}),t=(n=0)=>{if(!f){f=!0;try{a.kill("SIGKILL")}catch{}(async()=>{try{await e.disconnect()}catch{}try{await b()}catch{}process.exit(n)})()}};a.on("error",n=>{process.stderr.write(`screen-publisher: ffmpeg failed to start (is it installed?): ${String(n)}
3
- `),t(1)}),a.on("exit",()=>t(0));let o=Buffer.alloc(0);a.stdout?.on("data",n=>{for(o=o.length===0?n:Buffer.concat([o,n]);o.length>=u;){let h=new Uint8Array(o.subarray(0,u));if(o=o.subarray(u),f)return;try{l.captureFrame(new I(h,s,c,y.RGBA))}catch{}}}),e.on(p.ParticipantConnected,()=>{m=!0}),e.on(p.ParticipantDisconnected,()=>{e.remoteParticipants.size===0&&t(0)}),e.on(p.Disconnected,()=>t(0)),setTimeout(()=>{!m&&e.remoteParticipants.size===0&&t(0)},V),process.on("SIGTERM",()=>t(0)),process.on("SIGINT",()=>t(0))}k().catch(r=>{process.stderr.write(`screen-publisher: ${r instanceof Error?r.message:String(r)}
2
+ import{spawn as g}from"node:child_process";import{LocalVideoTrack as R,Room as S,RoomEvent as p,TrackPublishOptions as T,TrackSource as _,VideoBufferType as v,VideoFrame as b,VideoSource as y,dispose as I}from"@livekit/rtc-node";var N=Number(process.env.SCREEN_FRAME_RATE??"10"),A=6e4;function d(r){let s=process.env[r];if(!s)throw new Error(`Missing required env ${r}`);return s}async function P(){let r=d("LIVEKIT_URL"),s=d("LIVEKIT_TOKEN"),E=d("DISPLAY"),i=Number(process.env.SCREEN_WIDTH??"1920"),c=Number(process.env.SCREEN_HEIGHT??"1080"),u=i*c*4,e=new S;await e.connect(r,s,{autoSubscribe:!1,dynacast:!0});let l=new y(i,c),w=R.createVideoTrack("screen",l);await e.localParticipant?.publishTrack(w,new T({source:_.SOURCE_SCREENSHARE}));let f=!1,m=e.remoteParticipants.size>0,a=g("ffmpeg",["-loglevel","error","-f","x11grab","-draw_mouse","1","-framerate",String(N),"-video_size",`${i}x${c}`,"-i",E,"-pix_fmt","rgba","-f","rawvideo","-"],{stdio:["ignore","pipe","inherit"]}),t=(n=0)=>{if(!f){f=!0;try{a.kill("SIGKILL")}catch{}(async()=>{try{await e.disconnect()}catch{}try{await I()}catch{}process.exit(n)})()}};a.on("error",n=>{process.stderr.write(`screen-publisher: ffmpeg failed to start (is it installed?): ${String(n)}
3
+ `),t(1)}),a.on("exit",()=>t(0));let o=Buffer.alloc(0);a.stdout?.on("data",n=>{for(o=o.length===0?n:Buffer.concat([o,n]);o.length>=u;){let h=new Uint8Array(o.subarray(0,u));if(o=o.subarray(u),f)return;try{l.captureFrame(new b(h,i,c,v.RGBA))}catch{}}}),e.on(p.ParticipantConnected,()=>{m=!0}),e.on(p.ParticipantDisconnected,()=>{e.remoteParticipants.size===0&&t(0)}),e.on(p.Disconnected,()=>t(0)),setTimeout(()=>{!m&&e.remoteParticipants.size===0&&t(0)},A),process.on("SIGTERM",()=>t(0)),process.on("SIGINT",()=>t(0))}P().catch(r=>{process.stderr.write(`screen-publisher: ${r instanceof Error?r.message:String(r)}
4
4
  `),process.exit(1)});
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@octavus/agent",
3
- "version": "0.3.0",
3
+ "version": "0.4.0",
4
4
  "description": "Octavus Agent CLI - run one of your cloud Octavus Agents on a machine you control, using that machine as the agent's computer. The agent lives in the cloud (fully configured and observable); the local machine only supplies the computer and the trigger.",
5
5
  "keywords": [
6
6
  "octavus",