@graphai/shell_utilty_agent 0.0.5 → 0.1.1

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.
@@ -1,5 +1,5 @@
1
1
  import { AgentFunction, AgentFunctionInfo } from "graphai";
2
- export declare const runShellCommand: (command: string, path?: string) => Promise<{
2
+ export declare const runShellCommand: (commands: string[], path?: string) => Promise<{
3
3
  text?: string | unknown;
4
4
  error?: unknown;
5
5
  stderr?: unknown;
@@ -9,7 +9,7 @@ export declare const runShellAgent: AgentFunction<null, {
9
9
  error?: unknown;
10
10
  stderr?: unknown;
11
11
  }, {
12
- command: string;
12
+ commands: string[];
13
13
  baseDir?: string;
14
14
  dirs?: string[];
15
15
  }>;
@@ -36,21 +36,32 @@ Object.defineProperty(exports, "__esModule", { value: true });
36
36
  exports.runShellAgent = exports.runShellCommand = void 0;
37
37
  const child_process_1 = require("child_process");
38
38
  const path = __importStar(require("node:path"));
39
- const runShellCommand = (command, path) => {
39
+ const runShellCommand = (commands, path) => {
40
+ if (!Array.isArray(commands)) {
41
+ throw new Error("runShellAgent error: command must be string[]");
42
+ }
40
43
  return new Promise((resolve, reject) => {
41
- (0, child_process_1.exec)(command, { cwd: path ?? process.cwd() }, function (error, stdout, stderr) {
42
- if (error) {
43
- reject({ error, stderr, stdout });
44
- }
45
- else if (stdout) {
46
- resolve({ text: stdout, stderr });
47
- }
44
+ const [command, args] = [commands[0], commands.slice(1)];
45
+ const results = [];
46
+ const stderrs = [];
47
+ const child = (0, child_process_1.spawn)(command, args, { cwd: path ?? process.cwd() });
48
+ child.stdout.on('data', (data) => {
49
+ results.push(data);
50
+ });
51
+ child.stderr.on('data', (data) => {
52
+ stderrs.push(data);
53
+ });
54
+ child.stderr.on('data', (data) => {
55
+ reject({ error: data, stdout: results.join(""), stderr: stderrs.join("") });
56
+ });
57
+ child.on('close', () => {
58
+ resolve({ text: results.join(""), stderr: stderrs.join("") });
48
59
  });
49
60
  });
50
61
  };
51
62
  exports.runShellCommand = runShellCommand;
52
- const runShellAgent = async ({ namedInputs, }) => {
53
- const { baseDir, dirs, command } = namedInputs;
63
+ const runShellAgent = async ({ namedInputs }) => {
64
+ const { baseDir, dirs, commands } = namedInputs;
54
65
  const dir = (() => {
55
66
  if (dirs) {
56
67
  return path.resolve(...dirs);
@@ -60,7 +71,7 @@ const runShellAgent = async ({ namedInputs, }) => {
60
71
  }
61
72
  })();
62
73
  try {
63
- const result = await (0, exports.runShellCommand)(command, dir);
74
+ const result = await (0, exports.runShellCommand)(commands, dir);
64
75
  return result;
65
76
  }
66
77
  catch (err) {
@@ -81,7 +92,7 @@ const runShellAgentInfo = {
81
92
  samples: [
82
93
  {
83
94
  params: {},
84
- inputs: { command: "echo 1", baseDir: "./" },
95
+ inputs: { commands: ["echo", "1"], baseDir: "./" },
85
96
  result: {
86
97
  text: "1\n",
87
98
  stderr: "",
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@graphai/shell_utilty_agent",
3
- "version": "0.0.5",
3
+ "version": "0.1.1",
4
4
  "description": "shell utilty agent",
5
5
  "main": "lib/index.js",
6
6
  "files": [
@@ -17,18 +17,10 @@
17
17
  },
18
18
  "author": "isamu arimoto",
19
19
  "license": "MIT",
20
- "devDependencies": {
21
- "@graphai/vanilla": "^0.2.5",
22
- "@receptron/agentdoc": "^0.0.6",
23
- "@receptron/test_utils": "^0.2.2",
24
- "@types/node": "^22.10.1",
25
- "eslint": "^9.16.0",
26
- "graphai": "^0.6.4",
27
- "prettier": "^3.4.2",
28
- "ts-node": "^10.9.2",
29
- "tsconfig-paths": "^4.2.0",
30
- "typescript": "^5.7.2",
31
- "typescript-eslint": "^8.17.0"
32
- },
33
- "dependencies": {}
20
+ "devDependencies": {},
21
+ "dependencies": {},
22
+ "types": "./lib/index.d.ts",
23
+ "directories": {
24
+ "lib": "lib"
25
+ }
34
26
  }