@agentconnect.md/computer 2.8.0-rc.22 → 2.8.0-rc.25

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.
@@ -87124,7 +87124,7 @@ var serviceEntry = () => managedEntry() ?? resolve2(process.argv[1]);
87124
87124
 
87125
87125
  // src/version.ts
87126
87126
  init_define_AGENTCONNECT_COMPUTER_WINDOWS_SOURCES();
87127
- var COMPUTER_DAEMON_VERSION = true ? "2.8.0-rc.22" : JSON.parse(readFileSync(new URL("../package.json", import.meta.url), "utf8")).version;
87127
+ var COMPUTER_DAEMON_VERSION = true ? "2.8.0-rc.25" : JSON.parse(readFileSync(new URL("../package.json", import.meta.url), "utf8")).version;
87128
87128
 
87129
87129
  // src/http-server.ts
87130
87130
  var CONTROL_HEADER = "x-agentconnect-computer";
@@ -87266,7 +87266,7 @@ import { mkdirSync as mkdirSync4, writeFileSync as writeFileSync4 } from "node:f
87266
87266
  import { join as join6 } from "node:path";
87267
87267
  var waylandSession = () => process.platform === "linux" && Boolean(process.env.WAYLAND_DISPLAY);
87268
87268
  var HELPER = String.raw`#!/usr/bin/env python3
87269
- # Usage: screencast.py TOKEN_FILE FPS [FRAMES]. Asks the ScreenCast portal for the monitor (persisting a restore
87269
+ # Usage: screencast.py TOKEN_FILE FPS CURSOR(1|0) [FRAMES]. Asks the ScreenCast portal for the monitor (persisting a restore
87270
87270
  # token so consent is asked once), then streams it as Y4M on stdout until killed.
87271
87271
  import os, signal, subprocess, sys
87272
87272
  import gi
@@ -87274,7 +87274,8 @@ gi.require_version('Gio', '2.0')
87274
87274
  from gi.repository import Gio, GLib
87275
87275
 
87276
87276
  token_path, fps = sys.argv[1], int(sys.argv[2])
87277
- frames = int(sys.argv[3]) if len(sys.argv) > 3 else 0
87277
+ show_cursor = sys.argv[3] == '1'
87278
+ frames = int(sys.argv[4]) if len(sys.argv) > 4 else 0
87278
87279
  NAME, PATH = 'org.freedesktop.portal.Desktop', '/org/freedesktop/portal/desktop'
87279
87280
  IFACE = 'org.freedesktop.portal.ScreenCast'
87280
87281
  bus = Gio.bus_get_sync(Gio.BusType.SESSION, None)
@@ -87306,7 +87307,8 @@ def request(method, build):
87306
87307
  modes = bus.call_sync(NAME, PATH, 'org.freedesktop.DBus.Properties', 'Get',
87307
87308
  GLib.Variant('(ss)', (IFACE, 'AvailableCursorModes')), None, Gio.DBusCallFlags.NONE, -1,
87308
87309
  None).unpack()[0]
87309
- cursor = 2 if modes & 2 else 1
87310
+ # 2 embeds the pointer in the frames, 1 hides it.
87311
+ cursor = 2 if show_cursor and modes & 2 else 1
87310
87312
  session = request('CreateSession', lambda t: GLib.Variant('(a{sv})', (
87311
87313
  {'handle_token': t, 'session_handle_token': GLib.Variant('s', 'acd%d' % os.getpid())},)))['session_handle']
87312
87314
  options = {'types': GLib.Variant('u', 1), 'multiple': GLib.Variant('b', False),
@@ -87440,19 +87442,20 @@ async function downloadFfmpeg(dataDir2, target, log40) {
87440
87442
  log40(`Installed ffmpeg ${build3.version} at ${target}`);
87441
87443
  return target;
87442
87444
  }
87443
- function captureInputs(fps, dataDir2, frames = 0) {
87445
+ function captureInputs(fps, dataDir2, frames = 0, cursor = true) {
87446
+ const mouse = cursor ? "1" : "0";
87444
87447
  const override = process.env.AGENTCONNECT_COMPUTER_CAPTURE;
87445
87448
  if (override) return [{ name: "override", args: override.split(" ").filter(Boolean), filters: [] }];
87446
87449
  if (process.platform === "win32") {
87447
87450
  return [
87448
87451
  {
87449
87452
  name: "ddagrab",
87450
- args: ["-f", "lavfi", "-i", `ddagrab=output_idx=0:framerate=${fps}:draw_mouse=1`],
87453
+ args: ["-f", "lavfi", "-i", `ddagrab=output_idx=0:framerate=${fps}:draw_mouse=${mouse}`],
87451
87454
  filters: ["hwdownload", "format=bgra"]
87452
87455
  },
87453
87456
  {
87454
87457
  name: "gdigrab",
87455
- args: ["-f", "gdigrab", "-framerate", String(fps), "-draw_mouse", "1", "-i", "desktop"],
87458
+ args: ["-f", "gdigrab", "-framerate", String(fps), "-draw_mouse", mouse, "-i", "desktop"],
87456
87459
  filters: []
87457
87460
  }
87458
87461
  ];
@@ -87461,7 +87464,16 @@ function captureInputs(fps, dataDir2, frames = 0) {
87461
87464
  return [
87462
87465
  {
87463
87466
  name: "avfoundation",
87464
- args: ["-f", "avfoundation", "-capture_cursor", "1", "-framerate", String(fps), "-i", "Capture screen 0:none"],
87467
+ args: [
87468
+ "-f",
87469
+ "avfoundation",
87470
+ "-capture_cursor",
87471
+ mouse,
87472
+ "-framerate",
87473
+ String(fps),
87474
+ "-i",
87475
+ "Capture screen 0:none"
87476
+ ],
87465
87477
  filters: []
87466
87478
  }
87467
87479
  ];
@@ -87473,7 +87485,7 @@ function captureInputs(fps, dataDir2, frames = 0) {
87473
87485
  name: "pipewire",
87474
87486
  producer: {
87475
87487
  command: "python3",
87476
- args: [helper, screencastTokenPath(dataDir2), String(fps), ...frames ? [String(frames)] : []]
87488
+ args: [helper, screencastTokenPath(dataDir2), String(fps), mouse, ...frames ? [String(frames)] : []]
87477
87489
  },
87478
87490
  args: ["-f", "yuv4mpegpipe", "-i", "pipe:0"],
87479
87491
  filters: []
@@ -87483,7 +87495,7 @@ function captureInputs(fps, dataDir2, frames = 0) {
87483
87495
  return [
87484
87496
  {
87485
87497
  name: "x11grab",
87486
- args: ["-f", "x11grab", "-framerate", String(fps), "-i", process.env.DISPLAY ?? ":0"],
87498
+ args: ["-f", "x11grab", "-draw_mouse", mouse, "-framerate", String(fps), "-i", process.env.DISPLAY ?? ":0"],
87487
87499
  filters: []
87488
87500
  }
87489
87501
  ];
@@ -98262,7 +98274,7 @@ function canPairTcpCandidates(local, remote) {
98262
98274
  return localType === "active" && remoteType === "passive" || localType === "passive" && remoteType === "active" || localType === "so" && remoteType === "so";
98263
98275
  }
98264
98276
  function candidateLocalPreference({
98265
- candidateType,
98277
+ candidateType: candidateType2,
98266
98278
  transport = "udp",
98267
98279
  tcptype,
98268
98280
  otherPreference = 8191
@@ -98271,27 +98283,27 @@ function candidateLocalPreference({
98271
98283
  return otherPreference;
98272
98284
  }
98273
98285
  const tcpType = normalizeTcpType(tcptype) ?? "active";
98274
- const directionPreference = candidateType === "srflx" || candidateType === "prflx" ? REFLEXIVE_DIRECTION_PREFERENCE[tcpType] : ACTIVE_PASSIVE_DIRECTION_PREFERENCE[tcpType];
98286
+ const directionPreference = candidateType2 === "srflx" || candidateType2 === "prflx" ? REFLEXIVE_DIRECTION_PREFERENCE[tcpType] : ACTIVE_PASSIVE_DIRECTION_PREFERENCE[tcpType];
98275
98287
  return (1 << 13) * directionPreference + otherPreference;
98276
98288
  }
98277
- function candidateTypePreference(candidateType, transport = "udp") {
98289
+ function candidateTypePreference(candidateType2, transport = "udp") {
98278
98290
  const table = normalizeTransport(transport) === "tcp" ? TCP_TYPE_PREFERENCE : UDP_TYPE_PREFERENCE;
98279
- return table[candidateType] ?? 0;
98291
+ return table[candidateType2] ?? 0;
98280
98292
  }
98281
- function candidateFoundation(candidateType, candidateTransport, baseAddress) {
98282
- const key = `${candidateType}|${candidateTransport}|${baseAddress}`;
98293
+ function candidateFoundation(candidateType2, candidateTransport, baseAddress) {
98294
+ const key = `${candidateType2}|${candidateTransport}|${baseAddress}`;
98283
98295
  return createHash32("md5").update(key, "ascii").digest("hex").slice(7);
98284
98296
  }
98285
- function candidatePriority(candidateType, options = 65535) {
98297
+ function candidatePriority(candidateType2, options = 65535) {
98286
98298
  const candidateComponent = 1;
98287
98299
  const transport = typeof options === "number" ? "udp" : normalizeTransport(options.transport);
98288
98300
  const localPref = typeof options === "number" ? options : options.localPreference ?? candidateLocalPreference({
98289
- candidateType,
98301
+ candidateType: candidateType2,
98290
98302
  transport,
98291
98303
  tcptype: options.tcptype,
98292
98304
  otherPreference: options.otherPreference
98293
98305
  });
98294
- const typePref = candidateTypePreference(candidateType, transport);
98306
+ const typePref = candidateTypePreference(candidateType2, transport);
98295
98307
  return (1 << 24) * typePref + (1 << 8) * localPref + (256 - candidateComponent);
98296
98308
  }
98297
98309
  function remoteTcpTypeForIncoming(localTcpType) {
@@ -109869,6 +109881,7 @@ var GATHER_TIMEOUT_MS = 3e3;
109869
109881
  var TURN_GATHER_TIMEOUT_MS = 8e3;
109870
109882
  var STUN_GATHER_TIMEOUT_MS = 2e3;
109871
109883
  var MAX_REMOTE_CANDIDATES = 64;
109884
+ var RELEASE_DELAY_MS = 100;
109872
109885
  var ANSWER_TIMEOUT_MS2 = 3e4;
109873
109886
  var SILENCE_TIMEOUT_MS = 1e4;
109874
109887
  var h264 = () => new RTCRtpCodecParameters({
@@ -109943,12 +109956,17 @@ var RtcSessions = class {
109943
109956
  pc,
109944
109957
  lastSeen: Date.now(),
109945
109958
  candidates: [],
109946
- gathered: false
109959
+ gathered: false,
109960
+ ...transport === "stun" ? { held: [] } : {}
109947
109961
  };
109948
109962
  pc.onIceCandidate.subscribe((candidate) => {
109949
109963
  if (!candidate) return void (session.gathered = true);
109950
109964
  const { candidate: line, sdpMid, sdpMLineIndex } = candidate.toJSON();
109951
- session.candidates.push({ candidate: line, sdpMid, sdpMLineIndex });
109965
+ (session.held && candidateType(line) === "srflx" ? session.held : session.candidates).push({
109966
+ candidate: line,
109967
+ sdpMid,
109968
+ sdpMLineIndex
109969
+ });
109952
109970
  });
109953
109971
  pc.iceGatheringStateChange.subscribe((state) => {
109954
109972
  if (state === "complete") session.gathered = true;
@@ -109983,7 +110001,7 @@ var RtcSessions = class {
109983
110001
  session.connected = true;
109984
110002
  session.lastSeen = Date.now();
109985
110003
  this.options.log(`viewer ${client()}: WebRTC connected (${transport}${selectedPairType(pc)})`);
109986
- session.unsubscribe ??= this.options.stream.subscribe((packet) => track.writeRtp(packet));
110004
+ session.unsubscribe ??= this.options.stream.subscribe(continuous(track));
109987
110005
  }
109988
110006
  if (state === "failed" || state === "closed" || state === "disconnected") this.close(session.id);
109989
110007
  });
@@ -110013,7 +110031,7 @@ var RtcSessions = class {
110013
110031
  const candidates = session.candidates.length;
110014
110032
  return {
110015
110033
  id: session.id,
110016
- sdp: transport === "direct" && advertise ? onlyCandidatesFor(sdp, advertise) : sdp,
110034
+ sdp: transport === "direct" && advertise ? onlyCandidatesFor(sdp, advertise) : transport === "stun" ? withoutReflexive(sdp) : sdp,
110017
110035
  candidates
110018
110036
  };
110019
110037
  }
@@ -110024,19 +110042,26 @@ var RtcSessions = class {
110024
110042
  addCandidate(client, id, candidate) {
110025
110043
  const session = this.owned(client, id);
110026
110044
  if (session.transport === "direct") throw new Error("an ICE-lite session takes no trickled candidates");
110027
- if (!candidate || candidate.candidate === "") return;
110045
+ if (!candidate || candidate.candidate === "") return this.release(session);
110028
110046
  const remote = session.remoteCandidates = (session.remoteCandidates ?? 0) + 1;
110029
110047
  if (remote > MAX_REMOTE_CANDIDATES) throw new Error("too many candidates");
110030
110048
  void session.pc.addIceCandidate({
110031
110049
  candidate: candidate.candidate,
110032
110050
  sdpMid: candidate.sdpMid ?? void 0,
110033
110051
  sdpMLineIndex: candidate.sdpMLineIndex ?? void 0
110052
+ }).then(() => {
110053
+ if (isPublicIpv4(candidate.candidate)) setTimeout(() => this.release(session), RELEASE_DELAY_MS).unref();
110034
110054
  }).catch((error63) => this.options.log(`viewer ${client}: candidate refused: ${error63.message}`));
110035
110055
  }
110056
+ release(session) {
110057
+ if (!session.held) return;
110058
+ session.candidates.push(...session.held);
110059
+ session.held = void 0;
110060
+ }
110036
110061
  /** The desktop's own candidates after the first `after`, and whether gathering is done, for the browser to trickle in. */
110037
110062
  candidates(client, id, after) {
110038
110063
  const session = this.owned(client, id);
110039
- return { candidates: session.candidates.slice(after), done: session.gathered };
110064
+ return { candidates: session.candidates.slice(after), done: session.gathered && !session.held };
110040
110065
  }
110041
110066
  owned(client, id) {
110042
110067
  const session = this.sessions.get(id);
@@ -110083,6 +110108,15 @@ function selectedPairType(pc) {
110083
110108
  }
110084
110109
  var PAIR_STATES = ["frozen", "waiting", "in-progress", "succeeded", "failed"];
110085
110110
  var endpoint = (c) => `${c.type} ${c.host}:${c.port}`;
110111
+ function continuous(track) {
110112
+ let source;
110113
+ return (packet) => {
110114
+ const ssrc = packet.readUInt32BE(8);
110115
+ if (source !== void 0 && ssrc !== source) track.notifySourceChanged(RtpPacket.deSerialize(packet).header);
110116
+ source = ssrc;
110117
+ track.writeRtp(packet);
110118
+ };
110119
+ }
110086
110120
  function iceReport(pc, trickled) {
110087
110121
  const connection = pc.iceTransports[0]?.connection;
110088
110122
  if (!connection) return "no ICE transport";
@@ -110093,6 +110127,11 @@ function iceReport(pc, trickled) {
110093
110127
  ).join(", ") || "none";
110094
110128
  return `ICE ${connection.state}; local ${local}; remote ${remote} (${trickled} trickled); pairs sent/answered/received ${pairs}`;
110095
110129
  }
110130
+ var candidateType = (line) => / typ (\w+)/.exec(line)?.[1];
110131
+ var isPublicIpv4 = (line) => ["srflx", "prflx", "relay"].includes(candidateType(line) ?? "") && /^\d+\.\d+\.\d+\.\d+$/.test(line.split(" ")[4] ?? "");
110132
+ var withoutReflexive = (sdp) => sdp.split("\r\n").filter(
110133
+ (line) => line !== "a=end-of-candidates" && !(line.startsWith("a=candidate:") && candidateType(line) === "srflx")
110134
+ ).join("\r\n");
110096
110135
  var onlyCandidatesFor = (sdp, address) => sdp.split("\r\n").filter((line) => !line.startsWith("a=candidate:") || line.split(" ")[4] === address).join("\r\n");
110097
110136
 
110098
110137
  // src/stream/screen-stream.ts
@@ -110117,6 +110156,9 @@ var ScreenStream = class {
110117
110156
  socket;
110118
110157
  process;
110119
110158
  restart;
110159
+ // The running capture's pointer setting, and the process being replaced because that setting changed.
110160
+ cursor = true;
110161
+ swapping;
110120
110162
  inputIndex = 0;
110121
110163
  running = false;
110122
110164
  runs = 0;
@@ -110152,7 +110194,8 @@ var ScreenStream = class {
110152
110194
  }
110153
110195
  spawn() {
110154
110196
  if (!this.running || !this.socket) return;
110155
- const inputs = captureInputs(this.options.fps, this.options.dataDir);
110197
+ this.cursor = this.options.cursor?.() ?? true;
110198
+ const inputs = captureInputs(this.options.fps, this.options.dataDir, 0, this.cursor);
110156
110199
  const input2 = inputs[Math.min(this.inputIndex, inputs.length - 1)];
110157
110200
  const args = [
110158
110201
  "-hide_banner",
@@ -110185,7 +110228,9 @@ var ScreenStream = class {
110185
110228
  `)));
110186
110229
  feeder.once("exit", () => this.children.delete(feeder));
110187
110230
  }
110188
- this.options.log(`screen stream: ffmpeg started (${input2.name}, ${this.options.fps} fps)`);
110231
+ this.options.log(
110232
+ `screen stream: ffmpeg started (${input2.name}, ${this.options.fps} fps${this.cursor ? "" : ", no pointer"})`
110233
+ );
110189
110234
  child2.once("error", (error63) => {
110190
110235
  this.lastError = `ffmpeg could not start: ${error63.message}`;
110191
110236
  this.options.log(`screen stream: ${this.lastError}`);
@@ -110195,6 +110240,10 @@ var ScreenStream = class {
110195
110240
  producer?.kill();
110196
110241
  if (this.process === child2) this.process = void 0;
110197
110242
  if (!this.running) return;
110243
+ if (this.swapping === child2) {
110244
+ this.swapping = void 0;
110245
+ return this.spawn();
110246
+ }
110198
110247
  const detail = stderr.trim().split("\n").slice(-3).join(" | ");
110199
110248
  this.lastError = `ffmpeg (${input2.name}) exited with ${code}: ${detail}`;
110200
110249
  this.options.log(`screen stream: ${this.lastError}`);
@@ -110202,6 +110251,13 @@ var ScreenStream = class {
110202
110251
  this.restart = setTimeout(() => this.spawn(), RESTART_DELAY_MS);
110203
110252
  });
110204
110253
  }
110254
+ // Restarts the capture when the pointer setting changed; the next keyframe carries the new frames.
110255
+ refresh() {
110256
+ const child2 = this.process;
110257
+ if (!child2 || this.swapping || (this.options.cursor?.() ?? true) === this.cursor) return;
110258
+ this.swapping = child2;
110259
+ terminate(child2);
110260
+ }
110205
110261
  get bytesPerMs() {
110206
110262
  return this.options.bitrateKbps * PACE_FACTOR / 8;
110207
110263
  }
@@ -110234,16 +110290,19 @@ var ScreenStream = class {
110234
110290
  this.queue.length = 0;
110235
110291
  this.queuedBytes = 0;
110236
110292
  clearTimeout(this.restart);
110293
+ this.swapping = void 0;
110237
110294
  const child2 = this.process;
110238
110295
  this.process = void 0;
110239
- child2?.kill();
110240
- if (child2)
110241
- setTimeout(() => child2.exitCode === null && child2.signalCode === null && child2.kill("SIGKILL"), 2e3).unref();
110296
+ if (child2) terminate(child2);
110242
110297
  this.socket?.close();
110243
110298
  this.socket = void 0;
110244
110299
  this.options.log("screen stream: stopped (no viewers)");
110245
110300
  }
110246
110301
  };
110302
+ function terminate(child2) {
110303
+ child2.kill();
110304
+ setTimeout(() => child2.exitCode === null && child2.signalCode === null && child2.kill("SIGKILL"), 2e3).unref();
110305
+ }
110247
110306
 
110248
110307
  // src/tools.ts
110249
110308
  init_define_AGENTCONNECT_COMPUTER_WINDOWS_SOURCES();
@@ -110602,7 +110661,7 @@ var VIEWER_PAGE = `<!doctype html>
110602
110661
  #screen.ctl { outline: 2px solid #4ade80; }
110603
110662
  video, img { max-width: 100vw; max-height: calc(100vh - 48px); display: block; }
110604
110663
  #surface { position: absolute; inset: 0; outline: none; }
110605
- #screen.ctl #surface { cursor: crosshair; }
110664
+ #screen.ctl #surface { cursor: default; }
110606
110665
  #login { display: none; gap: 8px; }
110607
110666
  #error { color: #f87171; }
110608
110667
  </style>
@@ -114510,6 +114569,8 @@ function buildViewer(dir, config2, computer, refusal, consoleViewer, advertiseAd
114510
114569
  fps: config2.streamFps,
114511
114570
  maxWidth: config2.streamMaxWidth,
114512
114571
  bitrateKbps: config2.streamBitrateKbps,
114572
+ // A person driving sees their browser's pointer at once, so the delayed one in the frames would be a second cursor.
114573
+ cursor: () => computer.liveStatus() !== "human_in_control",
114513
114574
  log: log39
114514
114575
  });
114515
114576
  const rtc = config2.webrtc ? new RtcSessions({
@@ -114532,7 +114593,7 @@ function buildViewer(dir, config2, computer, refusal, consoleViewer, advertiseAd
114532
114593
  streamError: () => stream.lastError,
114533
114594
  ...refusal ? { refusal } : {}
114534
114595
  });
114535
- return viewer;
114596
+ return { ...viewer, statusChanged: () => stream.refresh() };
114536
114597
  }
114537
114598
  async function loadDriverTools(driver, config2) {
114538
114599
  if (!config2.exposeDriverTools) return [];
@@ -114638,6 +114699,7 @@ async function run3(dir, initial, clientName) {
114638
114699
  setTitle(status);
114639
114700
  live2.channel?.client.beat();
114640
114701
  live2.local?.update();
114702
+ live2.viewer?.statusChanged();
114641
114703
  void live2.computer?.adminPromptChanged();
114642
114704
  },
114643
114705
  () => authority.refusal(),
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@agentconnect.md/computer",
3
- "version": "2.8.0-rc.22",
3
+ "version": "2.8.0-rc.25",
4
4
  "description": "AgentConnect computer daemon: drives a desktop through Cua Driver and serves the computer_* tools over MCP; installed and upgraded by agentconnect computer",
5
5
  "license": "Apache-2.0",
6
6
  "repository": {