@tpmjs/tools-sprites-exec 0.1.0 → 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/LICENSE +21 -0
- package/README.md +71 -0
- package/dist/index.js +1 -3
- package/package.json +64 -28
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2024-2025 TPMJS
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
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,28 +1,32 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tpmjs/tools-sprites-exec",
|
|
3
|
-
"version": "0.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
|
-
"keywords": [
|
|
6
|
+
"keywords": [
|
|
7
|
+
"tpmjs",
|
|
8
|
+
"sprites",
|
|
9
|
+
"sandbox",
|
|
10
|
+
"code-execution",
|
|
11
|
+
"ai"
|
|
12
|
+
],
|
|
7
13
|
"exports": {
|
|
8
14
|
".": {
|
|
9
15
|
"types": "./dist/index.d.ts",
|
|
10
16
|
"default": "./dist/index.js"
|
|
11
17
|
}
|
|
12
18
|
},
|
|
13
|
-
"files": [
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
"dev": "tsup --watch",
|
|
17
|
-
"type-check": "tsc --noEmit",
|
|
18
|
-
"clean": "rm -rf dist .turbo"
|
|
19
|
-
},
|
|
19
|
+
"files": [
|
|
20
|
+
"dist"
|
|
21
|
+
],
|
|
20
22
|
"devDependencies": {
|
|
21
|
-
"@tpmjs/tsconfig": "workspace:*",
|
|
22
23
|
"tsup": "^8.5.1",
|
|
23
|
-
"typescript": "^5.9.3"
|
|
24
|
+
"typescript": "^5.9.3",
|
|
25
|
+
"@tpmjs/tsconfig": "0.0.0"
|
|
26
|
+
},
|
|
27
|
+
"publishConfig": {
|
|
28
|
+
"access": "public"
|
|
24
29
|
},
|
|
25
|
-
"publishConfig": { "access": "public" },
|
|
26
30
|
"repository": {
|
|
27
31
|
"type": "git",
|
|
28
32
|
"url": "https://github.com/anthropics/tpmjs.git",
|
|
@@ -32,21 +36,53 @@
|
|
|
32
36
|
"license": "MIT",
|
|
33
37
|
"tpmjs": {
|
|
34
38
|
"category": "sandbox",
|
|
35
|
-
"frameworks": [
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
39
|
+
"frameworks": [
|
|
40
|
+
"vercel-ai"
|
|
41
|
+
],
|
|
42
|
+
"tools": [
|
|
43
|
+
{
|
|
44
|
+
"name": "spritesExecTool",
|
|
45
|
+
"description": "Execute a command inside a sprite and return the output with exit code",
|
|
46
|
+
"parameters": [
|
|
47
|
+
{
|
|
48
|
+
"name": "name",
|
|
49
|
+
"type": "string",
|
|
50
|
+
"description": "Name of the sprite to execute command in",
|
|
51
|
+
"required": true
|
|
52
|
+
},
|
|
53
|
+
{
|
|
54
|
+
"name": "cmd",
|
|
55
|
+
"type": "string",
|
|
56
|
+
"description": "Command to execute",
|
|
57
|
+
"required": true
|
|
58
|
+
},
|
|
59
|
+
{
|
|
60
|
+
"name": "stdin",
|
|
61
|
+
"type": "string",
|
|
62
|
+
"description": "Optional stdin input",
|
|
63
|
+
"required": false
|
|
64
|
+
},
|
|
65
|
+
{
|
|
66
|
+
"name": "timeoutMs",
|
|
67
|
+
"type": "number",
|
|
68
|
+
"description": "Execution timeout in milliseconds",
|
|
69
|
+
"required": false
|
|
70
|
+
}
|
|
71
|
+
],
|
|
72
|
+
"returns": {
|
|
73
|
+
"type": "ExecResult",
|
|
74
|
+
"description": "Command output with exitCode, stdout, stderr, and duration"
|
|
75
|
+
}
|
|
48
76
|
}
|
|
49
|
-
|
|
77
|
+
]
|
|
50
78
|
},
|
|
51
|
-
"dependencies": {
|
|
52
|
-
|
|
79
|
+
"dependencies": {
|
|
80
|
+
"ai": "6.0.23"
|
|
81
|
+
},
|
|
82
|
+
"scripts": {
|
|
83
|
+
"build": "tsup",
|
|
84
|
+
"dev": "tsup --watch",
|
|
85
|
+
"type-check": "tsc --noEmit",
|
|
86
|
+
"clean": "rm -rf dist .turbo"
|
|
87
|
+
}
|
|
88
|
+
}
|