@moxxy/cli 0.12.0 → 0.12.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/bin.js CHANGED
@@ -138594,54 +138594,48 @@ function buildBrowserSessionTool(deps) {
138594
138594
  function browserSidecarCall(method, params = {}, deps) {
138595
138595
  return getSidecar(deps).call(method, params);
138596
138596
  }
138597
- function browserSidecarOnEvent(fn, deps) {
138598
- return getSidecar(deps).onEvent(fn);
138599
- }
138600
138597
  async function closeBrowserSidecar() {
138601
138598
  if (SIDECAR_INSTANCE) {
138602
138599
  await SIDECAR_INSTANCE.close();
138603
138600
  SIDECAR_INSTANCE = null;
138604
138601
  }
138605
138602
  }
138603
+ var FRAME_INTERVAL_MS = 450;
138604
+ var FAIL_GRACE = 4;
138606
138605
  function buildBrowserSurface(deps) {
138607
138606
  return defineSurface({
138608
138607
  kind: "browser",
138609
138608
  description: "A live view of the agent's browser; click, type, and navigate.",
138610
138609
  open: () => {
138611
138610
  const dataSubs = /* @__PURE__ */ new Set();
138612
- let lastBase64 = null;
138613
- let lastUrl = "";
138614
- let vw = 1280;
138615
- let vh = 800;
138611
+ let last = null;
138612
+ let timer = null;
138613
+ let inFlight = false;
138614
+ let fails = 0;
138616
138615
  const emit2 = (payload) => {
138617
138616
  for (const cb of dataSubs)
138618
138617
  cb(payload);
138619
138618
  };
138620
- const offEvent = browserSidecarOnEvent((event) => {
138621
- if (event.event !== "screencastFrame")
138622
- return;
138623
- const data = typeof event.data === "string" ? event.data : null;
138624
- if (!data)
138619
+ const tick = async () => {
138620
+ if (inFlight)
138625
138621
  return;
138626
- lastBase64 = data;
138627
- if (typeof event.url === "string")
138628
- lastUrl = event.url;
138629
- emit2({ type: "frame", base64: data, mime: "image/jpeg", url: lastUrl });
138630
- }, deps);
138631
- const refreshViewport = async () => {
138622
+ inFlight = true;
138632
138623
  try {
138633
- const f3 = await browserSidecarCall("frame", {}, deps);
138634
- if (f3.width)
138635
- vw = f3.width;
138636
- if (f3.height)
138637
- vh = f3.height;
138638
- if (typeof f3.url === "string")
138639
- lastUrl = f3.url;
138640
- } catch {
138624
+ const frame = await browserSidecarCall("frame", {}, deps);
138625
+ last = frame;
138626
+ fails = 0;
138627
+ emit2({ type: "frame", base64: frame.base64, mime: frame.mediaType, url: frame.url });
138628
+ } catch (err) {
138629
+ if (++fails === FAIL_GRACE && !last) {
138630
+ const message = err instanceof Error ? err.message : String(err);
138631
+ emit2({ type: "status", text: `Browser unavailable: ${message}` });
138632
+ }
138633
+ } finally {
138634
+ inFlight = false;
138641
138635
  }
138642
138636
  };
138643
- void browserSidecarCall("startScreencast", {}, deps).catch(() => void 0);
138644
- void refreshViewport();
138637
+ void tick();
138638
+ timer = setInterval(() => void tick(), FRAME_INTERVAL_MS);
138645
138639
  return {
138646
138640
  id: "browser",
138647
138641
  kind: "browser",
@@ -138649,23 +138643,29 @@ function buildBrowserSurface(deps) {
138649
138643
  dataSubs.add(cb);
138650
138644
  return () => dataSubs.delete(cb);
138651
138645
  },
138652
- snapshot: () => lastBase64 ? { type: "frame", base64: lastBase64, mime: "image/jpeg", url: lastUrl } : { type: "frame", url: lastUrl },
138646
+ snapshot: () => last ? { type: "frame", base64: last.base64, mime: last.mediaType, url: last.url } : { type: "status", text: "Starting browser\u2026" },
138653
138647
  input: async (msg) => {
138648
+ const vw = last?.width ?? 1280;
138649
+ const vh = last?.height ?? 720;
138654
138650
  if (msg.type === "navigate" && typeof msg.url === "string") {
138655
138651
  await browserSidecarCall("goto", { url: msg.url }, deps).catch(() => void 0);
138656
- void refreshViewport();
138652
+ void tick();
138657
138653
  } else if (msg.type === "click" && typeof msg.fx === "number" && typeof msg.fy === "number") {
138658
138654
  await browserSidecarCall("mouse", { x: msg.fx * vw, y: msg.fy * vh }, deps).catch(() => void 0);
138655
+ void tick();
138659
138656
  } else if (msg.type === "key" && typeof msg.key === "string") {
138660
138657
  await browserSidecarCall("key", { key: msg.key }, deps).catch(() => void 0);
138658
+ void tick();
138661
138659
  } else if (msg.type === "scroll" && typeof msg.dy === "number") {
138662
138660
  await browserSidecarCall("scroll", { dy: msg.dy }, deps).catch(() => void 0);
138661
+ void tick();
138663
138662
  }
138664
138663
  },
138665
138664
  close: () => {
138666
- offEvent();
138665
+ if (timer)
138666
+ clearInterval(timer);
138667
+ timer = null;
138667
138668
  dataSubs.clear();
138668
- void browserSidecarCall("stopScreencast", {}, deps).catch(() => void 0);
138669
138669
  }
138670
138670
  };
138671
138671
  }