@aigne/cli 1.0.0-0
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/cli.js +5 -0
- package/dist/commands/aigne.js +19 -0
- package/dist/commands/create.js +75 -0
- package/dist/commands/run.js +40 -0
- package/dist/commands/test.js +17 -0
- package/package.json +45 -0
- package/templates/default/README.md +32 -0
- package/templates/default/aigne.yaml +5 -0
- package/templates/default/chat.yaml +7 -0
- package/templates/default/sandbox.js +26 -0
- package/templates/default/sandbox.test.js +7 -0
package/dist/cli.js
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.createAIGNECommand = createAIGNECommand;
|
|
4
|
+
const commander_1 = require("commander");
|
|
5
|
+
const package_json_1 = require("../../package.json");
|
|
6
|
+
const create_js_1 = require("./create.js");
|
|
7
|
+
const run_js_1 = require("./run.js");
|
|
8
|
+
const test_js_1 = require("./test.js");
|
|
9
|
+
function createAIGNECommand() {
|
|
10
|
+
return new commander_1.Command()
|
|
11
|
+
.name("aigne")
|
|
12
|
+
.description("CLI for AIGNE framework")
|
|
13
|
+
.version(package_json_1.version)
|
|
14
|
+
.addCommand((0, run_js_1.createRunCommand)())
|
|
15
|
+
.addCommand((0, test_js_1.createTestCommand)())
|
|
16
|
+
.addCommand((0, create_js_1.createCreateCommand)())
|
|
17
|
+
.showHelpAfterError(true)
|
|
18
|
+
.showSuggestionAfterError(true);
|
|
19
|
+
}
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.createCreateCommand = createCreateCommand;
|
|
7
|
+
const node_fs_1 = require("node:fs");
|
|
8
|
+
const promises_1 = require("node:fs/promises");
|
|
9
|
+
const node_path_1 = require("node:path");
|
|
10
|
+
const commander_1 = require("commander");
|
|
11
|
+
const inquirer_1 = __importDefault(require("inquirer"));
|
|
12
|
+
function createCreateCommand() {
|
|
13
|
+
return new commander_1.Command("create")
|
|
14
|
+
.description("Create a new aigne project with agent config files")
|
|
15
|
+
.argument("[path]", "Path to create the project directory", ".")
|
|
16
|
+
.action(async (path) => {
|
|
17
|
+
let projectPath = path;
|
|
18
|
+
if (projectPath === ".") {
|
|
19
|
+
const answers = await inquirer_1.default.prompt([
|
|
20
|
+
{
|
|
21
|
+
type: "input",
|
|
22
|
+
name: "projectName",
|
|
23
|
+
message: "Project name:",
|
|
24
|
+
default: path !== "." ? path : "my-aigne-project",
|
|
25
|
+
validate: (input) => {
|
|
26
|
+
if (input.trim() === "")
|
|
27
|
+
return "Project name cannot be empty.";
|
|
28
|
+
return true;
|
|
29
|
+
},
|
|
30
|
+
},
|
|
31
|
+
]);
|
|
32
|
+
projectPath = answers.projectName;
|
|
33
|
+
}
|
|
34
|
+
const absolutePath = (0, node_path_1.isAbsolute)(path) ? path : (0, node_path_1.resolve)(process.cwd(), path);
|
|
35
|
+
const isPathNotEmpty = (0, node_fs_1.existsSync)(absolutePath) && (0, node_fs_1.readdirSync)(absolutePath).length > 0;
|
|
36
|
+
if (isPathNotEmpty) {
|
|
37
|
+
const answers = await inquirer_1.default.prompt([
|
|
38
|
+
{
|
|
39
|
+
type: "confirm",
|
|
40
|
+
name: "overwrite",
|
|
41
|
+
message: `The directory "${absolutePath}" is not empty. Do you want to remove its contents?`,
|
|
42
|
+
default: false,
|
|
43
|
+
},
|
|
44
|
+
]);
|
|
45
|
+
if (!answers.overwrite) {
|
|
46
|
+
console.log("Operation cancelled.");
|
|
47
|
+
process.exit(0);
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
const templates = [{ name: "default" }];
|
|
51
|
+
const { template } = await inquirer_1.default.prompt([
|
|
52
|
+
{
|
|
53
|
+
type: "list",
|
|
54
|
+
name: "template",
|
|
55
|
+
message: "Select a template:",
|
|
56
|
+
choices: templates.map((t) => t.name),
|
|
57
|
+
default: "default",
|
|
58
|
+
},
|
|
59
|
+
]);
|
|
60
|
+
(0, node_fs_1.mkdirSync)(absolutePath, { recursive: true });
|
|
61
|
+
const templatePath = (0, node_path_1.join)(__dirname, "../../templates", template);
|
|
62
|
+
if (!(0, node_fs_1.existsSync)(templatePath))
|
|
63
|
+
throw new Error(`Template "${template}" not found.`);
|
|
64
|
+
const files = (0, node_fs_1.readdirSync)(templatePath);
|
|
65
|
+
for (const file of files) {
|
|
66
|
+
const source = (0, node_path_1.join)(templatePath, file);
|
|
67
|
+
const destination = (0, node_path_1.join)(absolutePath, file);
|
|
68
|
+
await (0, promises_1.cp)(source, destination, { recursive: true, force: true });
|
|
69
|
+
}
|
|
70
|
+
console.log("\n✅ Aigne project created successfully!");
|
|
71
|
+
console.log(`\nTo use your new agent, run:\n cd ${path} && npx -y aigne run`);
|
|
72
|
+
})
|
|
73
|
+
.showHelpAfterError(true)
|
|
74
|
+
.showSuggestionAfterError(true);
|
|
75
|
+
}
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.createRunCommand = createRunCommand;
|
|
4
|
+
const node_path_1 = require("node:path");
|
|
5
|
+
const core_1 = require("@aigne/core");
|
|
6
|
+
const run_chat_loop_js_1 = require("@aigne/core/utils/run-chat-loop.js");
|
|
7
|
+
const commander_1 = require("commander");
|
|
8
|
+
function createRunCommand() {
|
|
9
|
+
return new commander_1.Command("run")
|
|
10
|
+
.description("Run a chat loop with the specified agent")
|
|
11
|
+
.argument("[path]", "Path to the agents directory", ".")
|
|
12
|
+
.option("--agent <agent>", "Name of the agent to use (defaults to the first agent found)")
|
|
13
|
+
.action(async (path, options) => {
|
|
14
|
+
const absolutePath = (0, node_path_1.isAbsolute)(path) ? path : (0, node_path_1.resolve)(process.cwd(), path);
|
|
15
|
+
const engine = await core_1.ExecutionEngine.load({ path: absolutePath });
|
|
16
|
+
let agent;
|
|
17
|
+
if (options.agent) {
|
|
18
|
+
agent = engine.agents[options.agent];
|
|
19
|
+
if (!agent) {
|
|
20
|
+
console.error(`Agent "${options.agent}" not found.`);
|
|
21
|
+
console.log("Available agents:");
|
|
22
|
+
for (const agent of engine.agents) {
|
|
23
|
+
console.log(`- ${agent.name}`);
|
|
24
|
+
}
|
|
25
|
+
process.exit(1);
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
else {
|
|
29
|
+
agent = engine.agents[0];
|
|
30
|
+
if (!agent) {
|
|
31
|
+
console.error("No agents found in the specified path.");
|
|
32
|
+
process.exit(1);
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
const user = engine.call(agent);
|
|
36
|
+
await (0, run_chat_loop_js_1.runChatLoopInTerminal)(user, {});
|
|
37
|
+
})
|
|
38
|
+
.showHelpAfterError(true)
|
|
39
|
+
.showSuggestionAfterError(true);
|
|
40
|
+
}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.createTestCommand = createTestCommand;
|
|
4
|
+
const node_child_process_1 = require("node:child_process");
|
|
5
|
+
const node_path_1 = require("node:path");
|
|
6
|
+
const commander_1 = require("commander");
|
|
7
|
+
function createTestCommand() {
|
|
8
|
+
return new commander_1.Command("test")
|
|
9
|
+
.description("Run tests in the specified agents directory")
|
|
10
|
+
.argument("[path]", "Path to the agents directory", ".")
|
|
11
|
+
.action(async (path) => {
|
|
12
|
+
const absolutePath = (0, node_path_1.isAbsolute)(path) ? path : (0, node_path_1.resolve)(process.cwd(), path);
|
|
13
|
+
(0, node_child_process_1.spawnSync)("node", ["--test"], { cwd: absolutePath, stdio: "inherit" });
|
|
14
|
+
})
|
|
15
|
+
.showHelpAfterError(true)
|
|
16
|
+
.showSuggestionAfterError(true);
|
|
17
|
+
}
|
package/package.json
ADDED
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@aigne/cli",
|
|
3
|
+
"version": "1.0.0-0",
|
|
4
|
+
"description": "cli for AIGNE framework",
|
|
5
|
+
"publishConfig": {
|
|
6
|
+
"access": "public"
|
|
7
|
+
},
|
|
8
|
+
"author": "Arcblock <blocklet@arcblock.io> https://github.com/blocklet",
|
|
9
|
+
"homepage": "https://github.com/AIGNE-io/aigne-framework",
|
|
10
|
+
"license": "ISC",
|
|
11
|
+
"repository": {
|
|
12
|
+
"type": "git",
|
|
13
|
+
"url": "git+https://github.com/AIGNE-io/aigne-framework"
|
|
14
|
+
},
|
|
15
|
+
"files": [
|
|
16
|
+
"dist",
|
|
17
|
+
"LICENSE",
|
|
18
|
+
"README.md",
|
|
19
|
+
"CHANGELOG.md",
|
|
20
|
+
"templates"
|
|
21
|
+
],
|
|
22
|
+
"bin": {
|
|
23
|
+
"aigne": "dist/cli.js"
|
|
24
|
+
},
|
|
25
|
+
"dependencies": {
|
|
26
|
+
"commander": "^13.1.0",
|
|
27
|
+
"inquirer": "^12.5.0",
|
|
28
|
+
"openai": "^4.89.1",
|
|
29
|
+
"@aigne/core": "^1.5.0"
|
|
30
|
+
},
|
|
31
|
+
"devDependencies": {
|
|
32
|
+
"@types/bun": "^1.2.6",
|
|
33
|
+
"@types/node": "^22.13.14",
|
|
34
|
+
"npm-run-all": "^4.1.5",
|
|
35
|
+
"rimraf": "^6.0.1",
|
|
36
|
+
"typescript": "^5.8.2"
|
|
37
|
+
},
|
|
38
|
+
"scripts": {
|
|
39
|
+
"lint": "tsc --noEmit",
|
|
40
|
+
"build": "tsc --build tsconfig.build.json",
|
|
41
|
+
"clean": "rimraf dist coverage",
|
|
42
|
+
"test": "bun test",
|
|
43
|
+
"test:coverage": "bun test --coverage --coverage-reporter=lcov --coverage-reporter=text"
|
|
44
|
+
}
|
|
45
|
+
}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
# Aigne Default Template
|
|
2
|
+
|
|
3
|
+
This is the default project template for the Aigne framework, providing a basic chat agent and JavaScript code execution functionality.
|
|
4
|
+
|
|
5
|
+
## Template Structure
|
|
6
|
+
|
|
7
|
+
- `aigne.yaml` - Project configuration file that defines the chat model used and references to agents
|
|
8
|
+
- `chat.yaml` - Chat agent configuration, including agent instructions and tools used
|
|
9
|
+
- `sandbox.js` - JavaScript code execution tool for running JavaScript code within conversations
|
|
10
|
+
- `sandbox.test.js` - Test file to verify the functionality of the code execution tool
|
|
11
|
+
|
|
12
|
+
## Quick Start
|
|
13
|
+
|
|
14
|
+
### Install AIGNE CLI
|
|
15
|
+
|
|
16
|
+
```bash
|
|
17
|
+
npm install -g aigne
|
|
18
|
+
```
|
|
19
|
+
|
|
20
|
+
### Start the Project
|
|
21
|
+
|
|
22
|
+
```bash
|
|
23
|
+
aigne run
|
|
24
|
+
```
|
|
25
|
+
|
|
26
|
+
## Testing
|
|
27
|
+
|
|
28
|
+
Run the following command to execute test cases:
|
|
29
|
+
|
|
30
|
+
```bash
|
|
31
|
+
aigne test
|
|
32
|
+
```
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
name: chat
|
|
2
|
+
description: Chat agent
|
|
3
|
+
instructions: |
|
|
4
|
+
You are a helpful assistant that can answer questions and provide information on a wide range of topics.
|
|
5
|
+
Your goal is to assist users in finding the information they need and to engage in friendly conversation.
|
|
6
|
+
tools:
|
|
7
|
+
- sandbox.js
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import vm from "node:vm";
|
|
2
|
+
|
|
3
|
+
export default async function evaluateJs({ code }) {
|
|
4
|
+
const sandbox = {};
|
|
5
|
+
const context = vm.createContext(sandbox);
|
|
6
|
+
const result = vm.runInContext(code, context, { displayErrors: true });
|
|
7
|
+
return { result };
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
evaluateJs.description = "This agent evaluates JavaScript code.";
|
|
11
|
+
|
|
12
|
+
evaluateJs.input_schema = {
|
|
13
|
+
type: "object",
|
|
14
|
+
properties: {
|
|
15
|
+
code: { type: "string", description: "JavaScript code to evaluate" },
|
|
16
|
+
},
|
|
17
|
+
required: ["code"],
|
|
18
|
+
};
|
|
19
|
+
|
|
20
|
+
evaluateJs.output_schema = {
|
|
21
|
+
type: "object",
|
|
22
|
+
properties: {
|
|
23
|
+
result: { type: "any", description: "Result of the evaluated code" },
|
|
24
|
+
},
|
|
25
|
+
required: ["result"],
|
|
26
|
+
};
|