@vietor/easy-agent 0.7.0 → 0.7.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/dist/main.js +2 -0
- package/dist/tools/local-script.js +70 -0
- package/package.json +2 -2
package/dist/main.js
CHANGED
|
@@ -8,6 +8,7 @@ import { tryReadFileText } from "@vietor/agent-core/util";
|
|
|
8
8
|
import { startApp } from "./tui/app.js";
|
|
9
9
|
import { getPackageInfo } from "./util/package.js";
|
|
10
10
|
import { FileSessionPersistence } from "./session-persistence.js";
|
|
11
|
+
import { localScriptTool } from "./tools/local-script.js";
|
|
11
12
|
function buildSystemPromptBase(cwd) {
|
|
12
13
|
return [
|
|
13
14
|
"You are Easy Agent, an autonomous assistant. You complete tasks by calling tools, inspecting their results, and iterating until the work is done.",
|
|
@@ -93,6 +94,7 @@ export async function main(argv = []) {
|
|
|
93
94
|
cwd: cwd,
|
|
94
95
|
sessionId,
|
|
95
96
|
clientInfo: { name: pkg.name, version: pkg.version },
|
|
97
|
+
tools: [localScriptTool],
|
|
96
98
|
});
|
|
97
99
|
if (resume) {
|
|
98
100
|
const state = await store.load(sessionId);
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
import { mkdtemp, rm, writeFile } from "node:fs/promises";
|
|
2
|
+
import { tmpdir } from "node:os";
|
|
3
|
+
import { join } from "node:path";
|
|
4
|
+
import { toolError } from "@vietor/agent-core";
|
|
5
|
+
import { runProcess, findCommands, CALL_TIMEOUT_MS, NO_OUTPUT } from "@vietor/agent-core/util";
|
|
6
|
+
const LANGUAGE_SPECS = {
|
|
7
|
+
javascript: {
|
|
8
|
+
commands: ["node", "bun"],
|
|
9
|
+
extension: "js",
|
|
10
|
+
args: (filepath) => [filepath],
|
|
11
|
+
},
|
|
12
|
+
python: {
|
|
13
|
+
commands: ["python", "python3"],
|
|
14
|
+
extension: "py",
|
|
15
|
+
args: (filepath) => ["-u", filepath],
|
|
16
|
+
},
|
|
17
|
+
};
|
|
18
|
+
const LANGUAGE_CONFIGS = {};
|
|
19
|
+
for (const [language, spec] of Object.entries(LANGUAGE_SPECS)) {
|
|
20
|
+
const command = findCommands(spec.commands)[0];
|
|
21
|
+
if (command)
|
|
22
|
+
LANGUAGE_CONFIGS[language] = { command, extension: spec.extension, args: spec.args };
|
|
23
|
+
}
|
|
24
|
+
const DESCRIPTION = `Execute ${Object.keys(LANGUAGE_CONFIGS)
|
|
25
|
+
.map((name) => name[0].toUpperCase() + name.slice(1))
|
|
26
|
+
.join(" or ")} script in a local environment.
|
|
27
|
+
|
|
28
|
+
Use this for throwaway code — quick computations, data transformation, or experiments — instead of writing files into the project or assembling a Shell one-liner. The script is saved to a temporary directory that is removed after execution, and runs with the working directory as cwd, so relative paths work. Print results to stdout; stdin is unavailable. Do not include a shebang line or interpreter flags in the script source.`;
|
|
29
|
+
export const localScriptTool = {
|
|
30
|
+
name: "LocalScript",
|
|
31
|
+
description: DESCRIPTION,
|
|
32
|
+
parameters: {
|
|
33
|
+
type: "object",
|
|
34
|
+
properties: {
|
|
35
|
+
language: {
|
|
36
|
+
type: "string",
|
|
37
|
+
enum: Object.keys(LANGUAGE_CONFIGS),
|
|
38
|
+
description: "Programming language of the script",
|
|
39
|
+
},
|
|
40
|
+
script: { type: "string", description: "The source code to execute. No shebang line or interpreter flags; print results to stdout." },
|
|
41
|
+
},
|
|
42
|
+
required: ["language", "script"],
|
|
43
|
+
},
|
|
44
|
+
async execute(args, ctx) {
|
|
45
|
+
const language = args.language;
|
|
46
|
+
const config = LANGUAGE_CONFIGS[language];
|
|
47
|
+
if (!config) {
|
|
48
|
+
return toolError(`unsupported language: ${language}`);
|
|
49
|
+
}
|
|
50
|
+
const script = args.script;
|
|
51
|
+
if (typeof script !== "string") {
|
|
52
|
+
return toolError("script argument must be a string");
|
|
53
|
+
}
|
|
54
|
+
const tempDir = await mkdtemp(join(tmpdir(), "local-script-"));
|
|
55
|
+
const filepath = join(tempDir, `script.${config.extension}`);
|
|
56
|
+
try {
|
|
57
|
+
await writeFile(filepath, script, "utf8");
|
|
58
|
+
const r = await runProcess(config.command, config.args(filepath), { cwd: ctx.cwd, timeout: CALL_TIMEOUT_MS }, ctx.signal);
|
|
59
|
+
if (r.status === 0 && !r.error) {
|
|
60
|
+
return { content: r.stdout || NO_OUTPUT };
|
|
61
|
+
}
|
|
62
|
+
const parts = [r.stdout, r.stderr, r.error?.message].filter(Boolean);
|
|
63
|
+
return toolError(parts.join("\n") || NO_OUTPUT);
|
|
64
|
+
}
|
|
65
|
+
finally {
|
|
66
|
+
await rm(tempDir, { recursive: true, force: true });
|
|
67
|
+
}
|
|
68
|
+
},
|
|
69
|
+
summaryKeys: ["language"],
|
|
70
|
+
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@vietor/easy-agent",
|
|
3
|
-
"version": "0.7.
|
|
3
|
+
"version": "0.7.2",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"bin": {
|
|
@@ -23,7 +23,7 @@
|
|
|
23
23
|
"react": "^19.2.8",
|
|
24
24
|
"string-width": "^8.2.2",
|
|
25
25
|
"zod": "^4.4.3",
|
|
26
|
-
"@vietor/agent-core": "0.7.
|
|
26
|
+
"@vietor/agent-core": "0.7.2"
|
|
27
27
|
},
|
|
28
28
|
"devDependencies": {
|
|
29
29
|
"@types/node": "^22.20.1",
|