@aigne/cli 1.26.0 → 1.26.1-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/bunwrapper.js +0 -0
- package/dist/cli.js +2 -1
- package/dist/commands/aigne.d.ts +2 -2
- package/dist/commands/aigne.js +18 -11
- package/dist/commands/app.d.ts +2 -0
- package/dist/commands/app.js +98 -0
- package/dist/commands/connect.d.ts +6 -0
- package/dist/commands/connect.js +91 -0
- package/dist/commands/create.d.ts +6 -2
- package/dist/commands/create.js +62 -58
- package/dist/commands/observe.d.ts +7 -2
- package/dist/commands/observe.js +22 -13
- package/dist/commands/run.d.ts +6 -3
- package/dist/commands/run.js +96 -81
- package/dist/commands/serve-mcp.d.ts +10 -3
- package/dist/commands/serve-mcp.js +41 -23
- package/dist/commands/test.d.ts +7 -3
- package/dist/commands/test.js +20 -14
- package/dist/utils/download.d.ts +3 -1
- package/dist/utils/download.js +2 -2
- package/dist/utils/load-aigne.d.ts +10 -1
- package/dist/utils/load-aigne.js +57 -43
- package/dist/utils/run-with-aigne.d.ts +26 -2
- package/dist/utils/run-with-aigne.js +80 -57
- package/package.json +32 -29
- package/LICENSE.md +0 -93
|
@@ -4,67 +4,90 @@ import { dirname, isAbsolute, join } from "node:path";
|
|
|
4
4
|
import { isatty } from "node:tty";
|
|
5
5
|
import { promisify } from "node:util";
|
|
6
6
|
import { exists } from "@aigne/agent-library/utils/fs.js";
|
|
7
|
-
import { AIGNE, DEFAULT_OUTPUT_KEY, readAllString, UserAgent, } from "@aigne/core";
|
|
7
|
+
import { AIAgent, AIGNE, DEFAULT_OUTPUT_KEY, readAllString, UserAgent, } from "@aigne/core";
|
|
8
8
|
import { loadModel } from "@aigne/core/loader/index.js";
|
|
9
9
|
import { getLevelFromEnv, LogLevel, logger } from "@aigne/core/utils/logger.js";
|
|
10
|
-
import {
|
|
10
|
+
import { flat, isEmpty, tryOrThrow, } from "@aigne/core/utils/type-utils.js";
|
|
11
11
|
import chalk from "chalk";
|
|
12
|
-
import { Command } from "commander";
|
|
13
12
|
import { parse } from "yaml";
|
|
13
|
+
import yargs from "yargs";
|
|
14
14
|
import { ZodError, ZodObject, z } from "zod";
|
|
15
15
|
import { availableModels } from "../constants.js";
|
|
16
16
|
import { TerminalTracer } from "../tracer/terminal.js";
|
|
17
17
|
import { DEFAULT_CHAT_INPUT_KEY, runChatLoopInTerminal, } from "./run-chat-loop.js";
|
|
18
|
-
export const createRunAIGNECommand = (
|
|
19
|
-
.
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
.
|
|
25
|
-
.
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
.option("
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
.option("
|
|
18
|
+
export const createRunAIGNECommand = (yargs) => yargs
|
|
19
|
+
.option("chat", {
|
|
20
|
+
describe: "Run chat loop in terminal",
|
|
21
|
+
type: "boolean",
|
|
22
|
+
default: false,
|
|
23
|
+
})
|
|
24
|
+
.option("model", {
|
|
25
|
+
describe: `AI model to use in format 'provider[:model]' where model is optional. Examples: 'openai' or 'openai:gpt-4o-mini'. Available providers: ${availableModels()
|
|
26
|
+
.map((i) => i.name.toLowerCase().replace(/ChatModel$/i, ""))
|
|
27
|
+
.join(", ")} (default: openai)`,
|
|
28
|
+
type: "string",
|
|
29
|
+
})
|
|
30
|
+
.option("temperature", {
|
|
31
|
+
describe: "Temperature for the model (controls randomness, higher values produce more random outputs). Range: 0.0-2.0",
|
|
32
|
+
type: "number",
|
|
33
|
+
coerce: customZodError("--temperature", (s) => z.coerce.number().min(0).max(2).parse(s)),
|
|
34
|
+
})
|
|
35
|
+
.option("top-p", {
|
|
36
|
+
describe: "Top P (nucleus sampling) parameter for the model (controls diversity). Range: 0.0-1.0",
|
|
37
|
+
type: "number",
|
|
38
|
+
coerce: customZodError("--top-p", (s) => z.coerce.number().min(0).max(1).parse(s)),
|
|
39
|
+
})
|
|
40
|
+
.option("presence-penalty", {
|
|
41
|
+
describe: "Presence penalty for the model (penalizes repeating the same tokens). Range: -2.0 to 2.0",
|
|
42
|
+
type: "number",
|
|
43
|
+
coerce: customZodError("--presence-penalty", (s) => z.coerce.number().min(-2).max(2).parse(s)),
|
|
44
|
+
})
|
|
45
|
+
.option("frequency-penalty", {
|
|
46
|
+
describe: "Frequency penalty for the model (penalizes frequency of token usage). Range: -2.0 to 2.0",
|
|
47
|
+
type: "number",
|
|
48
|
+
coerce: customZodError("--frequency-penalty", (s) => z.coerce.number().min(-2).max(2).parse(s)),
|
|
49
|
+
})
|
|
50
|
+
.option("input", {
|
|
51
|
+
describe: "Input to the agent, use @<file> to read from a file",
|
|
52
|
+
type: "array",
|
|
53
|
+
alias: "i",
|
|
54
|
+
})
|
|
55
|
+
.option("format", {
|
|
56
|
+
describe: "Input format for the agent (available: text, json, yaml default: text)",
|
|
57
|
+
type: "string",
|
|
58
|
+
})
|
|
59
|
+
.option("output", {
|
|
60
|
+
describe: "Output file to save the result (default: stdout)",
|
|
61
|
+
type: "string",
|
|
62
|
+
alias: "o",
|
|
63
|
+
})
|
|
64
|
+
.option("output-key", {
|
|
65
|
+
describe: "Key in the result to save to the output file",
|
|
66
|
+
type: "string",
|
|
67
|
+
default: DEFAULT_OUTPUT_KEY,
|
|
68
|
+
})
|
|
69
|
+
.option("force", {
|
|
70
|
+
describe: "Truncate the output file if it exists, and create directory if the output path is not exists",
|
|
71
|
+
type: "boolean",
|
|
72
|
+
default: false,
|
|
73
|
+
})
|
|
74
|
+
.option("log-level", {
|
|
75
|
+
describe: `Log level for detailed debugging information. Values: ${Object.values(LogLevel).join(", ")}`,
|
|
76
|
+
type: "string",
|
|
77
|
+
default: getLevelFromEnv(logger.options.ns) || LogLevel.INFO,
|
|
78
|
+
coerce: customZodError("--log-level", (s) => z.nativeEnum(LogLevel).parse(s)),
|
|
79
|
+
});
|
|
36
80
|
export async function parseAgentInputByCommander(agent, options = {}) {
|
|
37
|
-
const
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
.
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
.action(async (agentInputOptions) => {
|
|
48
|
-
try {
|
|
49
|
-
const input = Object.fromEntries((await Promise.all(Object.entries(agentInputOptions).map(async ([key, value]) => {
|
|
50
|
-
let k = key.replace(/^input/, "");
|
|
51
|
-
k = k.charAt(0).toLowerCase() + k.slice(1);
|
|
52
|
-
if (!k)
|
|
53
|
-
return null;
|
|
54
|
-
if (typeof value === "string" && value.startsWith("@")) {
|
|
55
|
-
value = await readFile(value.slice(1), "utf8");
|
|
56
|
-
}
|
|
57
|
-
return [k, value];
|
|
58
|
-
}))).filter(isNonNullable));
|
|
59
|
-
resolve(input);
|
|
60
|
-
}
|
|
61
|
-
catch (error) {
|
|
62
|
-
reject(error);
|
|
63
|
-
}
|
|
64
|
-
})
|
|
65
|
-
.parseAsync(options.argv ?? process.argv)
|
|
66
|
-
.catch((error) => reject(error));
|
|
67
|
-
});
|
|
81
|
+
const inputSchemaShape = flat(agent instanceof AIAgent ? agent.inputKey : undefined, agent.inputSchema instanceof ZodObject ? Object.keys(agent.inputSchema.shape) : []);
|
|
82
|
+
const parsedInput = await yargs().parseAsync(options.argv ?? process.argv);
|
|
83
|
+
const input = Object.fromEntries(await Promise.all(inputSchemaShape.map(async (key) => {
|
|
84
|
+
const k = `input${key.charAt(0).toUpperCase()}${key.slice(1)}`;
|
|
85
|
+
let value = parsedInput[k];
|
|
86
|
+
if (typeof value === "string" && value.startsWith("@")) {
|
|
87
|
+
value = await readFile(value.slice(1), "utf8");
|
|
88
|
+
}
|
|
89
|
+
return [key, value];
|
|
90
|
+
})));
|
|
68
91
|
const rawInput = options.input ||
|
|
69
92
|
(isatty(process.stdin.fd) || !(await stdinHasData())
|
|
70
93
|
? null
|
|
@@ -96,14 +119,12 @@ export async function parseAgentInputByCommander(agent, options = {}) {
|
|
|
96
119
|
return input;
|
|
97
120
|
}
|
|
98
121
|
export const parseModelOption = (model) => {
|
|
99
|
-
const { provider, name } = (model || process.env.MODEL)?.match(/(?<provider>[^:]
|
|
122
|
+
const { provider, name } = (model || process.env.MODEL)?.match(/(?<provider>[^:]*)(:(?<name>(\S+)))?/)?.groups ?? {};
|
|
100
123
|
return { provider, name };
|
|
101
124
|
};
|
|
102
125
|
export async function runWithAIGNE(agentCreator, { argv = process.argv, chatLoopOptions, modelOptions, outputKey, } = {}) {
|
|
103
|
-
await
|
|
104
|
-
.
|
|
105
|
-
.showSuggestionAfterError(true)
|
|
106
|
-
.action(async (options) => {
|
|
126
|
+
await yargs()
|
|
127
|
+
.command("$0", "Run an agent with AIGNE", (yargs) => createRunAIGNECommand(yargs), async (options) => {
|
|
107
128
|
if (options.logLevel) {
|
|
108
129
|
logger.level = options.logLevel;
|
|
109
130
|
}
|
|
@@ -134,6 +155,8 @@ export async function runWithAIGNE(agentCreator, { argv = process.argv, chatLoop
|
|
|
134
155
|
await aigne.shutdown();
|
|
135
156
|
}
|
|
136
157
|
})
|
|
158
|
+
.alias("h", "help")
|
|
159
|
+
.alias("v", "version")
|
|
137
160
|
.parseAsync(argv)
|
|
138
161
|
.catch((error) => {
|
|
139
162
|
console.error(`${chalk.red("Error:")} ${error.message}`);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@aigne/cli",
|
|
3
|
-
"version": "1.26.0",
|
|
3
|
+
"version": "1.26.1-0",
|
|
4
4
|
"description": "cli for AIGNE framework",
|
|
5
5
|
"publishConfig": {
|
|
6
6
|
"access": "public"
|
|
@@ -41,9 +41,36 @@
|
|
|
41
41
|
]
|
|
42
42
|
}
|
|
43
43
|
},
|
|
44
|
+
"scripts": {
|
|
45
|
+
"lint": "tsc --noEmit",
|
|
46
|
+
"build": "tsc --build tsconfig.build.json",
|
|
47
|
+
"clean": "rimraf dist test/coverage templates/coverage",
|
|
48
|
+
"prepublishOnly": "run-s clean build",
|
|
49
|
+
"test": "run-s test:src test:templates",
|
|
50
|
+
"test:coverage": "run-s test:src:coverage test:templates:coverage",
|
|
51
|
+
"test:src": "bun --cwd test test",
|
|
52
|
+
"test:src:coverage": "bun --cwd test test --coverage --coverage-reporter=lcov --coverage-reporter=text",
|
|
53
|
+
"test:templates": "cd templates && node --test",
|
|
54
|
+
"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"
|
|
55
|
+
},
|
|
44
56
|
"dependencies": {
|
|
57
|
+
"@aigne/agent-library": "workspace:^",
|
|
58
|
+
"@aigne/agentic-memory": "workspace:^",
|
|
59
|
+
"@aigne/aigne-hub": "workspace:^",
|
|
60
|
+
"@aigne/anthropic": "workspace:^",
|
|
61
|
+
"@aigne/bedrock": "workspace:^",
|
|
62
|
+
"@aigne/core": "workspace:^",
|
|
63
|
+
"@aigne/deepseek": "workspace:^",
|
|
64
|
+
"@aigne/default-memory": "workspace:^",
|
|
65
|
+
"@aigne/gemini": "workspace:^",
|
|
45
66
|
"@aigne/listr2": "^1.0.10",
|
|
46
67
|
"@aigne/marked-terminal": "^7.3.2",
|
|
68
|
+
"@aigne/observability-api": "workspace:^",
|
|
69
|
+
"@aigne/ollama": "workspace:^",
|
|
70
|
+
"@aigne/open-router": "workspace:^",
|
|
71
|
+
"@aigne/openai": "workspace:^",
|
|
72
|
+
"@aigne/xai": "workspace:^",
|
|
73
|
+
"@blocklet/aigne-hub": "^0.2.17",
|
|
47
74
|
"@inquirer/prompts": "^7.6.0",
|
|
48
75
|
"@inquirer/type": "^3.0.8",
|
|
49
76
|
"@listr2/prompt-adapter-inquirer": "^3.0.1",
|
|
@@ -51,7 +78,6 @@
|
|
|
51
78
|
"@ocap/mcrypto": "^1.21.0",
|
|
52
79
|
"@smithy/node-http-handler": "^4.1.0",
|
|
53
80
|
"chalk": "^5.4.1",
|
|
54
|
-
"commander": "^14.0.0",
|
|
55
81
|
"crypto": "^1.0.1",
|
|
56
82
|
"detect-port": "^2.1.0",
|
|
57
83
|
"dotenv-flow": "^4.1.0",
|
|
@@ -69,21 +95,8 @@
|
|
|
69
95
|
"tar": "^7.4.3",
|
|
70
96
|
"wrap-ansi": "^9.0.0",
|
|
71
97
|
"yaml": "^2.8.0",
|
|
72
|
-
"
|
|
73
|
-
"
|
|
74
|
-
"@aigne/agent-library": "^1.21.6",
|
|
75
|
-
"@aigne/aigne-hub": "^0.2.2",
|
|
76
|
-
"@aigne/anthropic": "^0.10.2",
|
|
77
|
-
"@aigne/deepseek": "^0.7.6",
|
|
78
|
-
"@aigne/bedrock": "^0.8.6",
|
|
79
|
-
"@aigne/core": "^1.39.0",
|
|
80
|
-
"@aigne/default-memory": "^1.0.6",
|
|
81
|
-
"@aigne/gemini": "^0.8.6",
|
|
82
|
-
"@aigne/ollama": "^0.7.6",
|
|
83
|
-
"@aigne/observability-api": "^0.8.2",
|
|
84
|
-
"@aigne/open-router": "^0.7.6",
|
|
85
|
-
"@aigne/openai": "^0.10.6",
|
|
86
|
-
"@aigne/xai": "^0.7.6"
|
|
98
|
+
"yargs": "^18.0.0",
|
|
99
|
+
"zod": "^3.25.67"
|
|
87
100
|
},
|
|
88
101
|
"devDependencies": {
|
|
89
102
|
"@types/archiver": "^6.0.3",
|
|
@@ -92,22 +105,12 @@
|
|
|
92
105
|
"@types/glob": "^9.0.0",
|
|
93
106
|
"@types/gradient-string": "^1.1.6",
|
|
94
107
|
"@types/node": "^24.0.12",
|
|
108
|
+
"@types/yargs": "^17.0.33",
|
|
95
109
|
"archiver": "^7.0.1",
|
|
96
110
|
"hono": "4.8.4",
|
|
97
111
|
"npm-run-all": "^4.1.5",
|
|
98
112
|
"rimraf": "^6.0.1",
|
|
99
113
|
"typescript": "^5.8.3",
|
|
100
114
|
"ufo": "^1.6.1"
|
|
101
|
-
},
|
|
102
|
-
"scripts": {
|
|
103
|
-
"lint": "tsc --noEmit",
|
|
104
|
-
"build": "tsc --build tsconfig.build.json",
|
|
105
|
-
"clean": "rimraf dist test/coverage templates/coverage",
|
|
106
|
-
"test": "run-s test:src test:templates",
|
|
107
|
-
"test:coverage": "run-s test:src:coverage test:templates:coverage",
|
|
108
|
-
"test:src": "bun --cwd test test",
|
|
109
|
-
"test:src:coverage": "bun --cwd test test --coverage --coverage-reporter=lcov --coverage-reporter=text",
|
|
110
|
-
"test:templates": "cd templates && node --test",
|
|
111
|
-
"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"
|
|
112
115
|
}
|
|
113
|
-
}
|
|
116
|
+
}
|
package/LICENSE.md
DELETED
|
@@ -1,93 +0,0 @@
|
|
|
1
|
-
Elastic License 2.0
|
|
2
|
-
|
|
3
|
-
URL: https://www.elastic.co/licensing/elastic-license
|
|
4
|
-
|
|
5
|
-
## Acceptance
|
|
6
|
-
|
|
7
|
-
By using the software, you agree to all of the terms and conditions below.
|
|
8
|
-
|
|
9
|
-
## Copyright License
|
|
10
|
-
|
|
11
|
-
The licensor grants you a non-exclusive, royalty-free, worldwide,
|
|
12
|
-
non-sublicensable, non-transferable license to use, copy, distribute, make
|
|
13
|
-
available, and prepare derivative works of the software, in each case subject to
|
|
14
|
-
the limitations and conditions below.
|
|
15
|
-
|
|
16
|
-
## Limitations
|
|
17
|
-
|
|
18
|
-
You may not provide the software to third parties as a hosted or managed
|
|
19
|
-
service, where the service provides users with access to any substantial set of
|
|
20
|
-
the features or functionality of the software.
|
|
21
|
-
|
|
22
|
-
You may not move, change, disable, or circumvent the license key functionality
|
|
23
|
-
in the software, and you may not remove or obscure any functionality in the
|
|
24
|
-
software that is protected by the license key.
|
|
25
|
-
|
|
26
|
-
You may not alter, remove, or obscure any licensing, copyright, or other notices
|
|
27
|
-
of the licensor in the software. Any use of the licensor’s trademarks is subject
|
|
28
|
-
to applicable law.
|
|
29
|
-
|
|
30
|
-
## Patents
|
|
31
|
-
|
|
32
|
-
The licensor grants you a license, under any patent claims the licensor can
|
|
33
|
-
license, or becomes able to license, to make, have made, use, sell, offer for
|
|
34
|
-
sale, import and have imported the software, in each case subject to the
|
|
35
|
-
limitations and conditions in this license. This license does not cover any
|
|
36
|
-
patent claims that you cause to be infringed by modifications or additions to
|
|
37
|
-
the software. If you or your company make any written claim that the software
|
|
38
|
-
infringes or contributes to infringement of any patent, your patent license for
|
|
39
|
-
the software granted under these terms ends immediately. If your company makes
|
|
40
|
-
such a claim, your patent license ends immediately for work on behalf of your
|
|
41
|
-
company.
|
|
42
|
-
|
|
43
|
-
## Notices
|
|
44
|
-
|
|
45
|
-
You must ensure that anyone who gets a copy of any part of the software from you
|
|
46
|
-
also gets a copy of these terms.
|
|
47
|
-
|
|
48
|
-
If you modify the software, you must include in any modified copies of the
|
|
49
|
-
software prominent notices stating that you have modified the software.
|
|
50
|
-
|
|
51
|
-
## No Other Rights
|
|
52
|
-
|
|
53
|
-
These terms do not imply any licenses other than those expressly granted in
|
|
54
|
-
these terms.
|
|
55
|
-
|
|
56
|
-
## Termination
|
|
57
|
-
|
|
58
|
-
If you use the software in violation of these terms, such use is not licensed,
|
|
59
|
-
and your licenses will automatically terminate. If the licensor provides you
|
|
60
|
-
with a notice of your violation, and you cease all violation of this license no
|
|
61
|
-
later than 30 days after you receive that notice, your licenses will be
|
|
62
|
-
reinstated retroactively. However, if you violate these terms after such
|
|
63
|
-
reinstatement, any additional violation of these terms will cause your licenses
|
|
64
|
-
to terminate automatically and permanently.
|
|
65
|
-
|
|
66
|
-
## No Liability
|
|
67
|
-
|
|
68
|
-
*As far as the law allows, the software comes as is, without any warranty or
|
|
69
|
-
condition, and the licensor will not be liable to you for any damages arising
|
|
70
|
-
out of these terms or the use or nature of the software, under any kind of
|
|
71
|
-
legal claim.*
|
|
72
|
-
|
|
73
|
-
## Definitions
|
|
74
|
-
|
|
75
|
-
The **licensor** is the entity offering these terms, and the **software** is the
|
|
76
|
-
software the licensor makes available under these terms, including any portion
|
|
77
|
-
of it.
|
|
78
|
-
|
|
79
|
-
**you** refers to the individual or entity agreeing to these terms.
|
|
80
|
-
|
|
81
|
-
**your company** is any legal entity, sole proprietorship, or other kind of
|
|
82
|
-
organization that you work for, plus all organizations that have control over,
|
|
83
|
-
are under the control of, or are under common control with that
|
|
84
|
-
organization. **control** means ownership of substantially all the assets of an
|
|
85
|
-
entity, or the power to direct its management and policies by vote, contract, or
|
|
86
|
-
otherwise. Control can be direct or indirect.
|
|
87
|
-
|
|
88
|
-
**your licenses** are all the licenses granted to you for the software under
|
|
89
|
-
these terms.
|
|
90
|
-
|
|
91
|
-
**use** means anything you do with the software requiring one of your licenses.
|
|
92
|
-
|
|
93
|
-
**trademark** means trademarks, service marks, and similar rights.
|