@aigne/cli 1.0.0-2 → 1.0.0-20

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 CHANGED
@@ -1,5 +1,3 @@
1
1
  #!/usr/bin/env node
2
- "use strict";
3
- Object.defineProperty(exports, "__esModule", { value: true });
4
- const aigne_js_1 = require("./commands/aigne.js");
5
- (0, aigne_js_1.createAIGNECommand)().parse();
2
+ import { createAIGNECommand } from "./commands/aigne.js";
3
+ createAIGNECommand().parse();
@@ -1,19 +1,18 @@
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()
1
+ import { Command } from "commander";
2
+ import pkg from "../../package.json" with { type: "json" };
3
+ import { asciiLogo } from "../utils/ascii-logo.js";
4
+ import { createCreateCommand } from "./create.js";
5
+ import { createRunCommand } from "./run.js";
6
+ import { createTestCommand } from "./test.js";
7
+ export function createAIGNECommand() {
8
+ console.log(asciiLogo);
9
+ return new Command()
11
10
  .name("aigne")
12
11
  .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)())
12
+ .version(pkg.version)
13
+ .addCommand(createRunCommand())
14
+ .addCommand(createTestCommand())
15
+ .addCommand(createCreateCommand())
17
16
  .showHelpAfterError(true)
18
17
  .showSuggestionAfterError(true);
19
18
  }
@@ -1,27 +1,21 @@
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")
1
+ import { existsSync, mkdirSync, readdirSync } from "node:fs";
2
+ import { cp } from "node:fs/promises";
3
+ import { isAbsolute, join, relative, resolve } from "node:path";
4
+ import { Command } from "commander";
5
+ import inquirer from "inquirer";
6
+ export function createCreateCommand() {
7
+ return new Command("create")
14
8
  .description("Create a new aigne project with agent config files")
15
9
  .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([
10
+ .action(async (_path) => {
11
+ let path = _path;
12
+ if (path === ".") {
13
+ const answers = await inquirer.prompt([
20
14
  {
21
15
  type: "input",
22
16
  name: "projectName",
23
17
  message: "Project name:",
24
- default: path !== "." ? path : "my-aigne-project",
18
+ default: _path !== "." ? _path : "my-aigne-project",
25
19
  validate: (input) => {
26
20
  if (input.trim() === "")
27
21
  return "Project name cannot be empty.";
@@ -29,16 +23,16 @@ function createCreateCommand() {
29
23
  },
30
24
  },
31
25
  ]);
32
- projectPath = answers.projectName;
26
+ path = answers.projectName;
33
27
  }
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;
28
+ path = isAbsolute(path) ? path : resolve(process.cwd(), path);
29
+ const isPathNotEmpty = existsSync(path) && readdirSync(path).length > 0;
36
30
  if (isPathNotEmpty) {
37
- const answers = await inquirer_1.default.prompt([
31
+ const answers = await inquirer.prompt([
38
32
  {
39
33
  type: "confirm",
40
34
  name: "overwrite",
41
- message: `The directory "${absolutePath}" is not empty. Do you want to remove its contents?`,
35
+ message: `The directory "${path}" is not empty. Do you want to remove its contents?`,
42
36
  default: false,
43
37
  },
44
38
  ]);
@@ -48,7 +42,7 @@ function createCreateCommand() {
48
42
  }
49
43
  }
50
44
  const templates = [{ name: "default" }];
51
- const { template } = await inquirer_1.default.prompt([
45
+ const { template } = await inquirer.prompt([
52
46
  {
53
47
  type: "list",
54
48
  name: "template",
@@ -57,18 +51,18 @@ function createCreateCommand() {
57
51
  default: "default",
58
52
  },
59
53
  ]);
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))
54
+ mkdirSync(path, { recursive: true });
55
+ const templatePath = join(import.meta.dirname, "../../templates", template);
56
+ if (!existsSync(templatePath))
63
57
  throw new Error(`Template "${template}" not found.`);
64
- const files = (0, node_fs_1.readdirSync)(templatePath);
58
+ const files = readdirSync(templatePath);
65
59
  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 });
60
+ const source = join(templatePath, file);
61
+ const destination = join(path, file);
62
+ await cp(source, destination, { recursive: true, force: true });
69
63
  }
70
64
  console.log("\n✅ Aigne project created successfully!");
71
- console.log(`\nTo use your new agent, run:\n cd ${path} && npx -y aigne run`);
65
+ console.log(`\nTo use your new agent, run:\n cd ${relative(process.cwd(), path)} && aigne run`);
72
66
  })
73
67
  .showHelpAfterError(true)
74
68
  .showSuggestionAfterError(true);
@@ -1,18 +1,15 @@
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")
1
+ import { isAbsolute, resolve } from "node:path";
2
+ import { ExecutionEngine } from "@aigne/core";
3
+ import { runChatLoopInTerminal } from "@aigne/core/utils/run-chat-loop.js";
4
+ import { Command } from "commander";
5
+ export function createRunCommand() {
6
+ return new Command("run")
10
7
  .description("Run a chat loop with the specified agent")
11
8
  .argument("[path]", "Path to the agents directory", ".")
12
9
  .option("--agent <agent>", "Name of the agent to use (defaults to the first agent found)")
13
10
  .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 });
11
+ const absolutePath = isAbsolute(path) ? path : resolve(process.cwd(), path);
12
+ const engine = await ExecutionEngine.load({ path: absolutePath });
16
13
  let agent;
17
14
  if (options.agent) {
18
15
  agent = engine.agents[options.agent];
@@ -22,18 +19,16 @@ function createRunCommand() {
22
19
  for (const agent of engine.agents) {
23
20
  console.log(`- ${agent.name}`);
24
21
  }
25
- process.exit(1);
22
+ throw new Error(`Agent "${options.agent}" not found`);
26
23
  }
27
24
  }
28
25
  else {
29
26
  agent = engine.agents[0];
30
- if (!agent) {
31
- console.error("No agents found in the specified path.");
32
- process.exit(1);
33
- }
27
+ if (!agent)
28
+ throw new Error("No agents found in the specified path");
34
29
  }
35
30
  const user = engine.call(agent);
36
- await (0, run_chat_loop_js_1.runChatLoopInTerminal)(user, {});
31
+ await runChatLoopInTerminal(user, {});
37
32
  })
38
33
  .showHelpAfterError(true)
39
34
  .showSuggestionAfterError(true);
@@ -1,16 +1,13 @@
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")
1
+ import { spawnSync } from "node:child_process";
2
+ import { isAbsolute, resolve } from "node:path";
3
+ import { Command } from "commander";
4
+ export function createTestCommand() {
5
+ return new Command("test")
9
6
  .description("Run tests in the specified agents directory")
10
7
  .argument("[path]", "Path to the agents directory", ".")
11
8
  .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" });
9
+ const absolutePath = isAbsolute(path) ? path : resolve(process.cwd(), path);
10
+ spawnSync("node", ["--test"], { cwd: absolutePath, stdio: "inherit" });
14
11
  })
15
12
  .showHelpAfterError(true)
16
13
  .showSuggestionAfterError(true);
@@ -0,0 +1,17 @@
1
+ import chalk from "chalk";
2
+ import gradient from "gradient-string";
3
+ import pkg from "../../package.json" with { type: "json" };
4
+ const modernGradient = gradient([
5
+ "#4facfe", // 天蓝色
6
+ "#7367f0", // 紫色
7
+ "#f86aad", // 粉红色
8
+ ]);
9
+ const logo = `
10
+ _ ___ ____ _ _ _____
11
+ / \\ |_ _/ ___| \\ | | ____|
12
+ / _ \\ | | | _| \\| | _|
13
+ / ___ \\ | | |_| | |\\ | |___
14
+ /_/ \\_\\___\\____|_| \\_|_____|
15
+ `;
16
+ const frameworkInfo = `v${pkg.version}`;
17
+ export const asciiLogo = `${modernGradient(logo)}\n\t${chalk.cyan(frameworkInfo)}\n\n`;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@aigne/cli",
3
- "version": "1.0.0-2",
3
+ "version": "1.0.0-20",
4
4
  "description": "cli for AIGNE framework",
5
5
  "publishConfig": {
6
6
  "access": "public"
@@ -19,34 +19,35 @@
19
19
  "CHANGELOG.md",
20
20
  "templates"
21
21
  ],
22
+ "type": "module",
22
23
  "bin": {
23
24
  "aigne": "dist/cli.js"
24
25
  },
25
26
  "dependencies": {
27
+ "chalk": "^5.4.1",
26
28
  "commander": "^13.1.0",
29
+ "gradient-string": "^3.0.0",
27
30
  "inquirer": "^12.5.0",
28
- "openai": "^4.89.1",
29
- "pkce-challenge": "^5.0.0",
30
- "@aigne/core": "^1.5.0"
31
+ "openai": "^4.91.1",
32
+ "@aigne/core": "^1.5.1-2"
31
33
  },
32
34
  "devDependencies": {
33
- "@types/bun": "^1.2.6",
34
- "@types/node": "^22.13.14",
35
+ "@types/bun": "^1.2.8",
36
+ "@types/gradient-string": "^1.1.6",
37
+ "@types/node": "^22.13.17",
35
38
  "npm-run-all": "^4.1.5",
36
39
  "rimraf": "^6.0.1",
37
40
  "typescript": "^5.8.2"
38
41
  },
39
- "resolutions": {
40
- "pkce-challenge": "^5.0.0"
41
- },
42
- "overrides": {
43
- "pkce-challenge": "^5.0.0"
44
- },
45
42
  "scripts": {
46
43
  "lint": "tsc --noEmit",
47
44
  "build": "tsc --build tsconfig.build.json",
48
- "clean": "rimraf dist coverage",
49
- "test": "bun test",
50
- "test:coverage": "bun test --coverage --coverage-reporter=lcov --coverage-reporter=text"
45
+ "clean": "rimraf dist test/coverage templates/coverage",
46
+ "test": "run-s test:src test:templates",
47
+ "test:coverage": "run-s test:src:coverage test:templates:coverage",
48
+ "test:src": "cd test && bun test/",
49
+ "test:src:coverage": "cd test && bun test --coverage --coverage-reporter=lcov --coverage-reporter=text",
50
+ "test:templates": "cd templates && node --test",
51
+ "test:templates:coverage": "cd templates && mkdir -p coverage && node --test --experimental-test-coverage --test-reporter=lcov --test-reporter-destination=coverage/lcov.info --test-reporter=spec --test-reporter-destination=stdout"
51
52
  }
52
53
  }
@@ -3,3 +3,5 @@ chat_model:
3
3
  temperature: 0.8
4
4
  agents:
5
5
  - chat.yaml
6
+ tools:
7
+ - sandbox.js