@lizard-build/sdk 0.1.48 → 0.1.49

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/index.d.mts CHANGED
@@ -710,7 +710,8 @@ declare class Desktop {
710
710
  private readonly sandboxId;
711
711
  private readonly config;
712
712
  private readonly process;
713
- constructor(sandboxId: string, config: ConnectionConfig, process: Process);
713
+ private readonly fs;
714
+ constructor(sandboxId: string, config: ConnectionConfig, process: Process, fs: Fs);
714
715
  private get client();
715
716
  private get path();
716
717
  /**
package/dist/index.d.ts CHANGED
@@ -710,7 +710,8 @@ declare class Desktop {
710
710
  private readonly sandboxId;
711
711
  private readonly config;
712
712
  private readonly process;
713
- constructor(sandboxId: string, config: ConnectionConfig, process: Process);
713
+ private readonly fs;
714
+ constructor(sandboxId: string, config: ConnectionConfig, process: Process, fs: Fs);
714
715
  private get client();
715
716
  private get path();
716
717
  /**
package/dist/index.js CHANGED
@@ -849,12 +849,14 @@ var Watcher = class {
849
849
  // src/sandbox/desktop.ts
850
850
  var BUTTONS = { left: "1", middle: "2", right: "3" };
851
851
  var SCROLL_BUTTONS = { up: "4", down: "5", left: "6", right: "7" };
852
+ var SCREENSHOT_PATH = /^\/tmp\/lizard-screenshot-[A-Za-z0-9_-]+\.png$/;
852
853
  var TYPE_DELAY_MS = 12;
853
854
  var Desktop = class {
854
- constructor(sandboxId, config, process2) {
855
+ constructor(sandboxId, config, process2, fs) {
855
856
  this.sandboxId = sandboxId;
856
857
  this.config = config;
857
858
  this.process = process2;
859
+ this.fs = fs;
858
860
  }
859
861
  get client() {
860
862
  return new PlatformClient(this.config);
@@ -891,11 +893,17 @@ var Desktop = class {
891
893
  * ```
892
894
  */
893
895
  async screenshot() {
894
- const r = await this.run(["lizard-desktop", "screenshot"]);
895
- if (r.truncated) {
896
- throw new LizardError("Screenshot is larger than the exec output limit; start the desktop at a smaller size");
896
+ const r = await this.run(["lizard-desktop", "screenshot", "--path"]);
897
+ const path = r.stdout.split("\n").map((l) => l.trim()).filter(Boolean).pop() ?? "";
898
+ if (!SCREENSHOT_PATH.test(path)) {
899
+ throw new LizardError(`Screenshot returned an unexpected path: ${path.slice(0, 200)}`);
900
+ }
901
+ try {
902
+ return await this.fs.readBytes(path);
903
+ } finally {
904
+ await this.fs.remove(path).catch(() => {
905
+ });
897
906
  }
898
- return decodeBase64(r.stdout.trim());
899
907
  }
900
908
  /** Click at (x, y). */
901
909
  async click(x, y, opts = {}) {
@@ -990,12 +998,6 @@ function coord(n) {
990
998
  if (!Number.isFinite(n) || n < 0) throw new LizardError(`Invalid screen coordinate: ${n}`);
991
999
  return String(Math.round(n));
992
1000
  }
993
- function decodeBase64(b64) {
994
- if (!b64 || !/^[A-Za-z0-9+/]+={0,2}$/.test(b64)) {
995
- throw new LizardError("Screenshot returned no image");
996
- }
997
- return new Uint8Array(Buffer.from(b64, "base64"));
998
- }
999
1001
 
1000
1002
  // src/sandbox/client.ts
1001
1003
  var SandboxClient = class {
@@ -1098,7 +1100,7 @@ var Sandbox = class extends SandboxClient {
1098
1100
  this.connectionConfig = new ConnectionConfig(opts);
1099
1101
  this.fs = new Fs(this.sandboxId, this.connectionConfig);
1100
1102
  this.process = new Process(this.sandboxId, this.connectionConfig);
1101
- this.desktop = new Desktop(this.sandboxId, this.connectionConfig, this.process);
1103
+ this.desktop = new Desktop(this.sandboxId, this.connectionConfig, this.process, this.fs);
1102
1104
  }
1103
1105
  static async create(templateOrOpts, opts) {
1104
1106
  const template = typeof templateOrOpts === "string" ? templateOrOpts : templateOrOpts?.template ?? this.defaultTemplate;
package/dist/index.mjs CHANGED
@@ -797,12 +797,14 @@ var Watcher = class {
797
797
  // src/sandbox/desktop.ts
798
798
  var BUTTONS = { left: "1", middle: "2", right: "3" };
799
799
  var SCROLL_BUTTONS = { up: "4", down: "5", left: "6", right: "7" };
800
+ var SCREENSHOT_PATH = /^\/tmp\/lizard-screenshot-[A-Za-z0-9_-]+\.png$/;
800
801
  var TYPE_DELAY_MS = 12;
801
802
  var Desktop = class {
802
- constructor(sandboxId, config, process2) {
803
+ constructor(sandboxId, config, process2, fs) {
803
804
  this.sandboxId = sandboxId;
804
805
  this.config = config;
805
806
  this.process = process2;
807
+ this.fs = fs;
806
808
  }
807
809
  get client() {
808
810
  return new PlatformClient(this.config);
@@ -839,11 +841,17 @@ var Desktop = class {
839
841
  * ```
840
842
  */
841
843
  async screenshot() {
842
- const r = await this.run(["lizard-desktop", "screenshot"]);
843
- if (r.truncated) {
844
- throw new LizardError("Screenshot is larger than the exec output limit; start the desktop at a smaller size");
844
+ const r = await this.run(["lizard-desktop", "screenshot", "--path"]);
845
+ const path = r.stdout.split("\n").map((l) => l.trim()).filter(Boolean).pop() ?? "";
846
+ if (!SCREENSHOT_PATH.test(path)) {
847
+ throw new LizardError(`Screenshot returned an unexpected path: ${path.slice(0, 200)}`);
848
+ }
849
+ try {
850
+ return await this.fs.readBytes(path);
851
+ } finally {
852
+ await this.fs.remove(path).catch(() => {
853
+ });
845
854
  }
846
- return decodeBase64(r.stdout.trim());
847
855
  }
848
856
  /** Click at (x, y). */
849
857
  async click(x, y, opts = {}) {
@@ -938,12 +946,6 @@ function coord(n) {
938
946
  if (!Number.isFinite(n) || n < 0) throw new LizardError(`Invalid screen coordinate: ${n}`);
939
947
  return String(Math.round(n));
940
948
  }
941
- function decodeBase64(b64) {
942
- if (!b64 || !/^[A-Za-z0-9+/]+={0,2}$/.test(b64)) {
943
- throw new LizardError("Screenshot returned no image");
944
- }
945
- return new Uint8Array(Buffer.from(b64, "base64"));
946
- }
947
949
 
948
950
  // src/sandbox/client.ts
949
951
  var SandboxClient = class {
@@ -1046,7 +1048,7 @@ var Sandbox = class extends SandboxClient {
1046
1048
  this.connectionConfig = new ConnectionConfig(opts);
1047
1049
  this.fs = new Fs(this.sandboxId, this.connectionConfig);
1048
1050
  this.process = new Process(this.sandboxId, this.connectionConfig);
1049
- this.desktop = new Desktop(this.sandboxId, this.connectionConfig, this.process);
1051
+ this.desktop = new Desktop(this.sandboxId, this.connectionConfig, this.process, this.fs);
1050
1052
  }
1051
1053
  static async create(templateOrOpts, opts) {
1052
1054
  const template = typeof templateOrOpts === "string" ? templateOrOpts : templateOrOpts?.template ?? this.defaultTemplate;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lizard-build/sdk",
3
- "version": "0.1.48",
3
+ "version": "0.1.49",
4
4
  "description": "TypeScript SDK for Lizard: Kubernetes sandboxes, code execution and cloud apps.",
5
5
  "main": "./dist/index.js",
6
6
  "module": "./dist/index.mjs",