computesdk 1.10.2 → 1.10.3

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.mjs CHANGED
@@ -675,7 +675,7 @@ var TerminalCommand = class {
675
675
  */
676
676
  async run(command, options) {
677
677
  const response = await this.runHandler(command, options?.background);
678
- const cmd2 = new Command({
678
+ const cmd = new Command({
679
679
  cmdId: response.data.cmd_id || "",
680
680
  terminalId: this.terminalId,
681
681
  command: response.data.command,
@@ -686,9 +686,9 @@ var TerminalCommand = class {
686
686
  durationMs: response.data.duration_ms,
687
687
  startedAt: (/* @__PURE__ */ new Date()).toISOString()
688
688
  });
689
- cmd2.setWaitHandler((timeout) => this.waitHandler(cmd2.id, timeout));
690
- cmd2.setRetrieveHandler(() => this.retrieveHandler(cmd2.id));
691
- return cmd2;
689
+ cmd.setWaitHandler((timeout) => this.waitHandler(cmd.id, timeout));
690
+ cmd.setRetrieveHandler(() => this.retrieveHandler(cmd.id));
691
+ return cmd;
692
692
  }
693
693
  /**
694
694
  * List all commands executed in this terminal
@@ -697,7 +697,7 @@ var TerminalCommand = class {
697
697
  async list() {
698
698
  const response = await this.listHandler();
699
699
  return response.data.commands.map((item) => {
700
- const cmd2 = new Command({
700
+ const cmd = new Command({
701
701
  cmdId: item.cmd_id,
702
702
  terminalId: this.terminalId,
703
703
  command: item.command,
@@ -711,9 +711,9 @@ var TerminalCommand = class {
711
711
  startedAt: item.started_at,
712
712
  finishedAt: item.finished_at
713
713
  });
714
- cmd2.setWaitHandler((timeout) => this.waitHandler(cmd2.id, timeout));
715
- cmd2.setRetrieveHandler(() => this.retrieveHandler(cmd2.id));
716
- return cmd2;
714
+ cmd.setWaitHandler((timeout) => this.waitHandler(cmd.id, timeout));
715
+ cmd.setRetrieveHandler(() => this.retrieveHandler(cmd.id));
716
+ return cmd;
717
717
  });
718
718
  }
719
719
  /**
@@ -723,7 +723,7 @@ var TerminalCommand = class {
723
723
  */
724
724
  async retrieve(cmdId) {
725
725
  const response = await this.retrieveHandler(cmdId);
726
- const cmd2 = new Command({
726
+ const cmd = new Command({
727
727
  cmdId: response.data.cmd_id,
728
728
  terminalId: this.terminalId,
729
729
  command: response.data.command,
@@ -735,9 +735,9 @@ var TerminalCommand = class {
735
735
  startedAt: response.data.started_at,
736
736
  finishedAt: response.data.finished_at
737
737
  });
738
- cmd2.setWaitHandler((timeout) => this.waitHandler(cmd2.id, timeout));
739
- cmd2.setRetrieveHandler(() => this.retrieveHandler(cmd2.id));
740
- return cmd2;
738
+ cmd.setWaitHandler((timeout) => this.waitHandler(cmd.id, timeout));
739
+ cmd.setRetrieveHandler(() => this.retrieveHandler(cmd.id));
740
+ return cmd;
741
741
  }
742
742
  };
743
743
 
@@ -1268,7 +1268,7 @@ var SignalService = class {
1268
1268
  };
1269
1269
 
1270
1270
  // src/client/index.ts
1271
- import { cmd, escapeArgs, mkdir, test } from "@computesdk/cmd";
1271
+ import { escapeArgs, mkdir, test } from "@computesdk/cmd";
1272
1272
 
1273
1273
  // src/client/resources/terminal.ts
1274
1274
  var Terminal = class {
@@ -1757,6 +1757,8 @@ var Run = class {
1757
1757
  * @param options - Execution options
1758
1758
  * @param options.shell - Shell to use (optional)
1759
1759
  * @param options.background - Run in background (optional)
1760
+ * @param options.cwd - Working directory for the command (optional)
1761
+ * @param options.env - Environment variables (optional)
1760
1762
  * @returns Command execution result with stdout, stderr, exit code, and duration
1761
1763
  */
1762
1764
  async command(command, options) {
@@ -1882,7 +1884,7 @@ var Sandbox = class {
1882
1884
  await this.writeFile(path, content);
1883
1885
  },
1884
1886
  mkdir: async (path) => {
1885
- await this.runCommand(mkdir(path));
1887
+ await this.runCommand(escapeArgs(mkdir(path)));
1886
1888
  },
1887
1889
  readdir: async (path) => {
1888
1890
  const response = await this.listFiles(path);
@@ -1894,7 +1896,7 @@ var Sandbox = class {
1894
1896
  }));
1895
1897
  },
1896
1898
  exists: async (path) => {
1897
- const result = await this.runCommand(test.exists(path));
1899
+ const result = await this.runCommand(escapeArgs(test.exists(path)));
1898
1900
  return result.exitCode === 0;
1899
1901
  },
1900
1902
  remove: async (path) => {
@@ -1919,7 +1921,13 @@ var Sandbox = class {
1919
1921
  };
1920
1922
  },
1921
1923
  command: async (command, options) => {
1922
- const result = await this.runCommandRequest({ command, shell: options?.shell, background: options?.background });
1924
+ const result = await this.runCommandRequest({
1925
+ command,
1926
+ shell: options?.shell,
1927
+ background: options?.background,
1928
+ cwd: options?.cwd,
1929
+ env: options?.env
1930
+ });
1923
1931
  return {
1924
1932
  stdout: result.data.stdout,
1925
1933
  stderr: result.data.stderr,
@@ -2233,12 +2241,14 @@ API request failed (${response.status}): ${error}`
2233
2241
  });
2234
2242
  }
2235
2243
  /**
2236
- * Execute a shell command (POST /run/command)
2244
+ * Execute a command and get the result
2245
+ * Lower-level method that returns the raw API response
2237
2246
  *
2238
- * @param options - Command options
2239
- * @param options.command - The command to execute
2247
+ * @param options.command - Command to execute
2240
2248
  * @param options.shell - Shell to use (optional)
2241
2249
  * @param options.background - Run in background (optional)
2250
+ * @param options.cwd - Working directory for the command (optional)
2251
+ * @param options.env - Environment variables (optional)
2242
2252
  * @returns Command execution result
2243
2253
  *
2244
2254
  * @example
@@ -2835,29 +2845,35 @@ API request failed (${response.status}): ${error}`
2835
2845
  return this.run.code(code, language ? { language } : void 0);
2836
2846
  }
2837
2847
  /**
2838
- * Execute shell command in the sandbox (convenience method)
2848
+ * Execute shell command in the sandbox
2839
2849
  *
2840
- * Delegates to sandbox.run.command() - prefer using that directly for new code.
2850
+ * Sends clean command string to server - no preprocessing or shell wrapping.
2851
+ * The server handles shell invocation, working directory, and backgrounding.
2841
2852
  *
2842
- * @param command - The command to execute (string or array form)
2843
- * @param argsOrOptions - Arguments array or options object
2844
- * @param maybeOptions - Options when using (command, args, options) form
2853
+ * @param command - The command to execute (raw string, e.g., "npm install")
2854
+ * @param options - Execution options
2855
+ * @param options.background - Run in background (server uses goroutines)
2856
+ * @param options.cwd - Working directory (server uses cmd.Dir)
2857
+ * @param options.env - Environment variables (server uses cmd.Env)
2845
2858
  * @returns Command execution result
2859
+ *
2860
+ * @example
2861
+ * ```typescript
2862
+ * // Simple command
2863
+ * await sandbox.runCommand('ls -la')
2864
+ *
2865
+ * // With working directory
2866
+ * await sandbox.runCommand('npm install', { cwd: '/app' })
2867
+ *
2868
+ * // Background with env vars
2869
+ * await sandbox.runCommand('node server.js', {
2870
+ * background: true,
2871
+ * env: { PORT: '3000' }
2872
+ * })
2873
+ * ```
2846
2874
  */
2847
- async runCommand(commandOrArray, argsOrOptions, maybeOptions) {
2848
- let commandParts;
2849
- let options;
2850
- if (Array.isArray(commandOrArray)) {
2851
- commandParts = commandOrArray;
2852
- options = argsOrOptions;
2853
- } else {
2854
- const args = Array.isArray(argsOrOptions) ? argsOrOptions : [];
2855
- commandParts = [commandOrArray, ...args];
2856
- options = Array.isArray(argsOrOptions) ? maybeOptions : argsOrOptions;
2857
- }
2858
- const finalCommand = cmd(commandParts, options);
2859
- const fullCommand = escapeArgs(finalCommand);
2860
- return this.run.command(fullCommand, { background: options?.background });
2875
+ async runCommand(command, options) {
2876
+ return this.run.command(command, options);
2861
2877
  }
2862
2878
  /**
2863
2879
  * Get server information