@tpmjs/tools-sprites-exec 0.1.1 → 0.1.2

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/README.md ADDED
@@ -0,0 +1,71 @@
1
+ # @tpmjs/sprites-exec
2
+
3
+ Execute a command inside a sprite and return the output.
4
+
5
+ ## Installation
6
+
7
+ ```bash
8
+ npm install @tpmjs/sprites-exec
9
+ ```
10
+
11
+ ## Requirements
12
+
13
+ - `SPRITES_TOKEN` environment variable - Get your token from https://sprites.dev
14
+
15
+ ## Usage
16
+
17
+ ```typescript
18
+ import { spritesExecTool } from '@tpmjs/sprites-exec';
19
+
20
+ // Run a simple command
21
+ const result = await spritesExecTool.execute({
22
+ name: 'my-sandbox',
23
+ cmd: 'ls -la /home'
24
+ });
25
+
26
+ console.log(result);
27
+ // {
28
+ // exitCode: 0,
29
+ // stdout: 'total 4\ndrwxr-xr-x 2 root root 4096 Jan 15 10:30 .\n...',
30
+ // stderr: '',
31
+ // duration: 45
32
+ // }
33
+
34
+ // Run with stdin input
35
+ const pythonResult = await spritesExecTool.execute({
36
+ name: 'my-sandbox',
37
+ cmd: 'python3',
38
+ stdin: 'print("Hello from stdin!")'
39
+ });
40
+ ```
41
+
42
+ ## Input Parameters
43
+
44
+ | Parameter | Type | Required | Description |
45
+ |-----------|------|----------|-------------|
46
+ | `name` | `string` | Yes | Name of the sprite to execute command in |
47
+ | `cmd` | `string` | Yes | Command to execute (e.g., 'ls -la', 'python script.py') |
48
+ | `stdin` | `string` | No | Optional stdin input to pass to the command |
49
+ | `timeoutMs` | `number` | No | Execution timeout in milliseconds (default: 60000) |
50
+
51
+ ## Output
52
+
53
+ | Field | Type | Description |
54
+ |-------|------|-------------|
55
+ | `exitCode` | `number` | Command exit code (0 = success) |
56
+ | `stdout` | `string` | Standard output from the command |
57
+ | `stderr` | `string` | Standard error from the command |
58
+ | `duration` | `number` | Execution duration in milliseconds |
59
+
60
+ ## Error Handling
61
+
62
+ The tool throws errors in these cases:
63
+ - `SPRITES_TOKEN` environment variable is not set
64
+ - Sprite not found (HTTP 404)
65
+ - Command execution timeout
66
+ - Invalid or expired API token (HTTP 401)
67
+ - Network errors with descriptive messages
68
+
69
+ ## License
70
+
71
+ MIT
package/dist/index.js CHANGED
@@ -68,9 +68,7 @@ var spritesExecTool = tool({
68
68
  } catch (error) {
69
69
  if (error instanceof Error) {
70
70
  if (error.name === "AbortError") {
71
- throw new Error(
72
- `Command execution in sprite "${name}" timed out after ${timeout}ms`
73
- );
71
+ throw new Error(`Command execution in sprite "${name}" timed out after ${timeout}ms`);
74
72
  }
75
73
  throw new Error(`Failed to execute command in sprite "${name}": ${error.message}`);
76
74
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tpmjs/tools-sprites-exec",
3
- "version": "0.1.1",
3
+ "version": "0.1.2",
4
4
  "description": "Execute a command inside a sprite and return the output with exit code",
5
5
  "type": "module",
6
6
  "keywords": [