@tpmjs/tools-sprites-exec 0.1.4 → 0.1.6
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/dist/index.js +29 -4
- package/package.json +10 -10
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/dist/index.js
CHANGED
|
@@ -15,7 +15,34 @@ function getSpritesToken() {
|
|
|
15
15
|
}
|
|
16
16
|
return token;
|
|
17
17
|
}
|
|
18
|
+
var SHELL_OPERATORS = ["&&", "||", "|", ";", ">", ">>", "<", "<<", "2>", "2>>", "&>", "$(", "`"];
|
|
19
|
+
function needsShellWrapper(cmdString) {
|
|
20
|
+
let inSingleQuote = false;
|
|
21
|
+
let inDoubleQuote = false;
|
|
22
|
+
for (let i = 0; i < cmdString.length; i++) {
|
|
23
|
+
const char = cmdString[i];
|
|
24
|
+
if (char === "'" && !inDoubleQuote) {
|
|
25
|
+
inSingleQuote = !inSingleQuote;
|
|
26
|
+
continue;
|
|
27
|
+
}
|
|
28
|
+
if (char === '"' && !inSingleQuote) {
|
|
29
|
+
inDoubleQuote = !inDoubleQuote;
|
|
30
|
+
continue;
|
|
31
|
+
}
|
|
32
|
+
if (!inSingleQuote && !inDoubleQuote) {
|
|
33
|
+
for (const op of SHELL_OPERATORS) {
|
|
34
|
+
if (cmdString.slice(i, i + op.length) === op) {
|
|
35
|
+
return true;
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
return false;
|
|
41
|
+
}
|
|
18
42
|
function parseCommand(cmdString) {
|
|
43
|
+
if (needsShellWrapper(cmdString)) {
|
|
44
|
+
return ["sh", "-c", cmdString];
|
|
45
|
+
}
|
|
19
46
|
const args = [];
|
|
20
47
|
let current = "";
|
|
21
48
|
let inSingleQuote = false;
|
|
@@ -94,7 +121,7 @@ function parseBinaryResponse(buffer) {
|
|
|
94
121
|
return { stdout, stderr, exitCode };
|
|
95
122
|
}
|
|
96
123
|
var spritesExecTool = tool({
|
|
97
|
-
description: "Execute a command inside a sprite and return the output. Supports stdin input for interactive commands. Returns exit code, stdout, stderr, and execution duration.",
|
|
124
|
+
description: "Execute a command inside a sprite and return the output. Supports stdin input for interactive commands. Returns exit code, stdout, stderr, and execution duration. IMPORTANT: If starting a web server, it must listen on port 8080 - this is the Sprites convention for public URLs (use sprites-url-set to make it publicly accessible).",
|
|
98
125
|
inputSchema: jsonSchema({
|
|
99
126
|
type: "object",
|
|
100
127
|
properties: {
|
|
@@ -184,9 +211,7 @@ var spritesExecTool = tool({
|
|
|
184
211
|
try {
|
|
185
212
|
const errorResponse = JSON.parse(jsonText);
|
|
186
213
|
if (errorResponse.error) {
|
|
187
|
-
throw new Error(
|
|
188
|
-
`Failed to execute command in sprite "${name}": ${errorResponse.error}`
|
|
189
|
-
);
|
|
214
|
+
throw new Error(`Failed to execute command in sprite "${name}": ${errorResponse.error}`);
|
|
190
215
|
}
|
|
191
216
|
} catch (parseError) {
|
|
192
217
|
if (parseError instanceof SyntaxError) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tpmjs/tools-sprites-exec",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.6",
|
|
4
4
|
"description": "Execute a command inside a sprite and return the output with exit code",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"keywords": [
|
|
@@ -19,16 +19,10 @@
|
|
|
19
19
|
"files": [
|
|
20
20
|
"dist"
|
|
21
21
|
],
|
|
22
|
-
"scripts": {
|
|
23
|
-
"build": "tsup",
|
|
24
|
-
"dev": "tsup --watch",
|
|
25
|
-
"type-check": "tsc --noEmit",
|
|
26
|
-
"clean": "rm -rf dist .turbo"
|
|
27
|
-
},
|
|
28
22
|
"devDependencies": {
|
|
29
|
-
"@tpmjs/tsconfig": "workspace:*",
|
|
30
23
|
"tsup": "^8.5.1",
|
|
31
|
-
"typescript": "^5.9.3"
|
|
24
|
+
"typescript": "^5.9.3",
|
|
25
|
+
"@tpmjs/tsconfig": "0.0.0"
|
|
32
26
|
},
|
|
33
27
|
"publishConfig": {
|
|
34
28
|
"access": "public"
|
|
@@ -84,5 +78,11 @@
|
|
|
84
78
|
},
|
|
85
79
|
"dependencies": {
|
|
86
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
87
|
}
|
|
88
|
-
}
|
|
88
|
+
}
|