-
-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathexecuteCommand.ts
More file actions
31 lines (27 loc) · 726 Bytes
/
executeCommand.ts
File metadata and controls
31 lines (27 loc) · 726 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
import { z } from "zod";
import { $ } from "zx";
import { Tool } from "../openai/tool.utils.js";
const argsSchema = z.object({
command: z.string(),
cwd: z
.string()
.optional()
.describe(
"relative path to the current directory to execute the command from",
),
});
type Args = z.input<typeof argsSchema>;
export default {
name: "executeCommand",
description: "Executes a command in a bash terminal",
argsSchema,
async call(args: Args) {
// Split space but keep quoted strings together
const argsArray = args.command.match(/"[^"]+"|\S+/g) || [];
const res = await $`${argsArray}`;
return {
success: true,
output: res.stdout,
};
},
} satisfies Tool<Args>;