@aigne/cli 1.60.0-beta → 1.74.0-beta
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/README.md +12 -12
- package/dist/_virtual/rolldown_runtime.cjs +29 -0
- package/dist/bunwrapper.cjs +22 -0
- package/dist/bunwrapper.d.cts +1 -0
- package/dist/bunwrapper.d.mts +1 -0
- package/dist/bunwrapper.mjs +23 -0
- package/dist/bunwrapper.mjs.map +1 -0
- package/dist/cli.cjs +42 -0
- package/dist/cli.d.cts +9 -0
- package/dist/cli.d.cts.map +1 -0
- package/dist/cli.d.mts +10 -0
- package/dist/cli.d.mts.map +1 -0
- package/dist/cli.mjs +41 -0
- package/dist/cli.mjs.map +1 -0
- package/dist/commands/aigne.cjs +23 -0
- package/dist/commands/aigne.mjs +22 -0
- package/dist/commands/aigne.mjs.map +1 -0
- package/dist/commands/app/agent.cjs +117 -0
- package/dist/commands/app/agent.mjs +113 -0
- package/dist/commands/app/agent.mjs.map +1 -0
- package/dist/commands/app/app.cjs +92 -0
- package/dist/commands/app/app.mjs +90 -0
- package/dist/commands/app/app.mjs.map +1 -0
- package/dist/commands/app/cli.cjs +6 -0
- package/dist/commands/app/cli.d.cts +1 -0
- package/dist/commands/app/cli.d.mts +1 -0
- package/dist/commands/app/cli.mjs +8 -0
- package/dist/commands/app/cli.mjs.map +1 -0
- package/dist/commands/app/upgrade.cjs +243 -0
- package/dist/commands/app/upgrade.mjs +240 -0
- package/dist/commands/app/upgrade.mjs.map +1 -0
- package/dist/commands/app.cjs +53 -0
- package/dist/commands/app.mjs +53 -0
- package/dist/commands/app.mjs.map +1 -0
- package/dist/commands/create.cjs +66 -0
- package/dist/commands/create.mjs +65 -0
- package/dist/commands/create.mjs.map +1 -0
- package/dist/commands/deploy.cjs +237 -0
- package/dist/commands/deploy.mjs +237 -0
- package/dist/commands/deploy.mjs.map +1 -0
- package/dist/commands/eval.cjs +88 -0
- package/dist/commands/eval.mjs +88 -0
- package/dist/commands/eval.mjs.map +1 -0
- package/dist/commands/hub.cjs +297 -0
- package/dist/commands/hub.mjs +294 -0
- package/dist/commands/hub.mjs.map +1 -0
- package/dist/commands/observe.cjs +49 -0
- package/dist/commands/observe.mjs +46 -0
- package/dist/commands/observe.mjs.map +1 -0
- package/dist/commands/run-skill.cjs +84 -0
- package/dist/commands/run-skill.mjs +81 -0
- package/dist/commands/run-skill.mjs.map +1 -0
- package/dist/commands/run.cjs +172 -0
- package/dist/commands/run.mjs +171 -0
- package/dist/commands/run.mjs.map +1 -0
- package/dist/commands/serve-mcp.cjs +68 -0
- package/dist/commands/serve-mcp.mjs +67 -0
- package/dist/commands/serve-mcp.mjs.map +1 -0
- package/dist/commands/test.cjs +40 -0
- package/dist/commands/test.mjs +39 -0
- package/dist/commands/test.mjs.map +1 -0
- package/dist/constants.cjs +28 -0
- package/dist/constants.d.cts +9 -0
- package/dist/constants.d.cts.map +1 -0
- package/dist/constants.d.mts +9 -0
- package/dist/constants.d.mts.map +1 -0
- package/dist/constants.mjs +24 -0
- package/dist/constants.mjs.map +1 -0
- package/dist/global.d.cjs +0 -0
- package/dist/global.d.cts +6 -0
- package/dist/global.d.cts.map +1 -0
- package/dist/global.d.mts +6 -0
- package/dist/global.d.mts.map +1 -0
- package/dist/index.cjs +0 -0
- package/dist/index.d.cts +2 -0
- package/dist/index.d.mts +2 -0
- package/dist/index.mjs +1 -0
- package/dist/tracer/terminal.cjs +336 -0
- package/dist/tracer/terminal.mjs +332 -0
- package/dist/tracer/terminal.mjs.map +1 -0
- package/dist/type.cjs +0 -0
- package/dist/type.d.cts +10 -0
- package/dist/type.d.cts.map +1 -0
- package/dist/type.d.mts +10 -0
- package/dist/type.d.mts.map +1 -0
- package/dist/type.mjs +1 -0
- package/dist/ui/utils/terminal-input.cjs +145 -0
- package/dist/ui/utils/terminal-input.mjs +144 -0
- package/dist/ui/utils/terminal-input.mjs.map +1 -0
- package/dist/ui/utils/text-buffer.cjs +865 -0
- package/dist/ui/utils/text-buffer.mjs +865 -0
- package/dist/ui/utils/text-buffer.mjs.map +1 -0
- package/dist/ui/utils/text-utils.cjs +85 -0
- package/dist/ui/utils/text-utils.mjs +78 -0
- package/dist/ui/utils/text-utils.mjs.map +1 -0
- package/dist/utils/agent-v1.cjs +180 -0
- package/dist/utils/agent-v1.d.cts +138 -0
- package/dist/utils/agent-v1.d.cts.map +1 -0
- package/dist/utils/agent-v1.d.mts +138 -0
- package/dist/utils/agent-v1.d.mts.map +1 -0
- package/dist/utils/agent-v1.mjs +179 -0
- package/dist/utils/agent-v1.mjs.map +1 -0
- package/dist/utils/aigne-hub/constants.cjs +22 -0
- package/dist/utils/aigne-hub/constants.mjs +18 -0
- package/dist/utils/aigne-hub/constants.mjs.map +1 -0
- package/dist/utils/aigne-hub/credential.cjs +179 -0
- package/dist/utils/aigne-hub/credential.mjs +175 -0
- package/dist/utils/aigne-hub/credential.mjs.map +1 -0
- package/dist/utils/aigne-hub/crypto.cjs +41 -0
- package/dist/utils/aigne-hub/crypto.mjs +33 -0
- package/dist/utils/aigne-hub/crypto.mjs.map +1 -0
- package/dist/utils/aigne-hub/model.cjs +112 -0
- package/dist/utils/aigne-hub/model.d.cts +19 -0
- package/dist/utils/aigne-hub/model.d.cts.map +1 -0
- package/dist/utils/aigne-hub/model.d.mts +19 -0
- package/dist/utils/aigne-hub/model.d.mts.map +1 -0
- package/dist/utils/aigne-hub/model.mjs +106 -0
- package/dist/utils/aigne-hub/model.mjs.map +1 -0
- package/dist/utils/aigne-hub/store/file.cjs +64 -0
- package/dist/utils/aigne-hub/store/file.mjs +64 -0
- package/dist/utils/aigne-hub/store/file.mjs.map +1 -0
- package/dist/utils/aigne-hub/store/index.cjs +37 -0
- package/dist/utils/aigne-hub/store/index.mjs +37 -0
- package/dist/utils/aigne-hub/store/index.mjs.map +1 -0
- package/dist/utils/aigne-hub/store/keytar.cjs +61 -0
- package/dist/utils/aigne-hub/store/keytar.mjs +61 -0
- package/dist/utils/aigne-hub/store/keytar.mjs.map +1 -0
- package/dist/utils/aigne-hub/store/migrate.cjs +46 -0
- package/dist/utils/aigne-hub/store/migrate.mjs +45 -0
- package/dist/utils/aigne-hub/store/migrate.mjs.map +1 -0
- package/dist/utils/aigne-hub/type.d.cts +18 -0
- package/dist/utils/aigne-hub/type.d.cts.map +1 -0
- package/dist/utils/aigne-hub/type.d.mts +18 -0
- package/dist/utils/aigne-hub/type.d.mts.map +1 -0
- package/dist/utils/aigne-hub-user.cjs +11 -0
- package/dist/utils/aigne-hub-user.d.cts +23 -0
- package/dist/utils/aigne-hub-user.d.cts.map +1 -0
- package/dist/utils/aigne-hub-user.d.mts +23 -0
- package/dist/utils/aigne-hub-user.d.mts.map +1 -0
- package/dist/utils/aigne-hub-user.mjs +11 -0
- package/dist/utils/aigne-hub-user.mjs.map +1 -0
- package/dist/utils/ascii-logo.cjs +30 -0
- package/dist/utils/ascii-logo.d.cts +5 -0
- package/dist/utils/ascii-logo.d.cts.map +1 -0
- package/dist/utils/ascii-logo.d.mts +5 -0
- package/dist/utils/ascii-logo.d.mts.map +1 -0
- package/dist/utils/{ascii-logo.js → ascii-logo.mjs} +13 -3
- package/dist/utils/ascii-logo.mjs.map +1 -0
- package/dist/utils/download.cjs +25 -0
- package/dist/utils/download.d.cts +7 -0
- package/dist/utils/download.d.cts.map +1 -0
- package/dist/utils/download.d.mts +7 -0
- package/dist/utils/download.d.mts.map +1 -0
- package/dist/utils/download.mjs +25 -0
- package/dist/utils/download.mjs.map +1 -0
- package/dist/utils/evaluation/core.cjs +84 -0
- package/dist/utils/evaluation/core.mjs +84 -0
- package/dist/utils/evaluation/core.mjs.map +1 -0
- package/dist/utils/evaluation/dataset.cjs +47 -0
- package/dist/utils/evaluation/dataset.mjs +46 -0
- package/dist/utils/evaluation/dataset.mjs.map +1 -0
- package/dist/utils/evaluation/evaluator.cjs +109 -0
- package/dist/utils/evaluation/{evaluator.js → evaluator.mjs} +48 -45
- package/dist/utils/evaluation/evaluator.mjs.map +1 -0
- package/dist/utils/evaluation/reporter.cjs +225 -0
- package/dist/utils/evaluation/reporter.mjs +220 -0
- package/dist/utils/evaluation/reporter.mjs.map +1 -0
- package/dist/utils/evaluation/runner.cjs +85 -0
- package/dist/utils/evaluation/runner.mjs +85 -0
- package/dist/utils/evaluation/runner.mjs.map +1 -0
- package/dist/utils/get-url-origin.cjs +12 -0
- package/dist/utils/get-url-origin.d.cts +5 -0
- package/dist/utils/get-url-origin.d.cts.map +1 -0
- package/dist/utils/get-url-origin.d.mts +5 -0
- package/dist/utils/get-url-origin.d.mts.map +1 -0
- package/dist/utils/get-url-origin.mjs +12 -0
- package/dist/utils/get-url-origin.mjs.map +1 -0
- package/dist/utils/inquirer/checkbox.cjs +265 -0
- package/dist/utils/inquirer/checkbox.mjs +262 -0
- package/dist/utils/inquirer/checkbox.mjs.map +1 -0
- package/dist/utils/listr.cjs +226 -0
- package/dist/utils/listr.d.cts +71 -0
- package/dist/utils/listr.d.cts.map +1 -0
- package/dist/utils/listr.d.mts +71 -0
- package/dist/utils/listr.d.mts.map +1 -0
- package/dist/utils/listr.mjs +222 -0
- package/dist/utils/listr.mjs.map +1 -0
- package/dist/utils/load-aigne.cjs +77 -0
- package/dist/utils/load-aigne.d.cts +29 -0
- package/dist/utils/load-aigne.d.cts.map +1 -0
- package/dist/utils/load-aigne.d.mts +29 -0
- package/dist/utils/load-aigne.d.mts.map +1 -0
- package/dist/utils/load-aigne.mjs +74 -0
- package/dist/utils/load-aigne.mjs.map +1 -0
- package/dist/utils/run-chat-loop.cjs +90 -0
- package/dist/utils/run-chat-loop.d.cts +20 -0
- package/dist/utils/run-chat-loop.d.cts.map +1 -0
- package/dist/utils/run-chat-loop.d.mts +20 -0
- package/dist/utils/run-chat-loop.d.mts.map +1 -0
- package/dist/utils/run-chat-loop.mjs +89 -0
- package/dist/utils/run-chat-loop.mjs.map +1 -0
- package/dist/utils/run-with-aigne.cjs +131 -0
- package/dist/utils/run-with-aigne.d.cts +46 -0
- package/dist/utils/run-with-aigne.d.cts.map +1 -0
- package/dist/utils/run-with-aigne.d.mts +46 -0
- package/dist/utils/run-with-aigne.d.mts.map +1 -0
- package/dist/utils/run-with-aigne.mjs +126 -0
- package/dist/utils/run-with-aigne.mjs.map +1 -0
- package/dist/utils/serve-mcp.cjs +91 -0
- package/dist/utils/serve-mcp.d.cts +20 -0
- package/dist/utils/serve-mcp.d.cts.map +1 -0
- package/dist/utils/serve-mcp.d.mts +20 -0
- package/dist/utils/serve-mcp.d.mts.map +1 -0
- package/dist/utils/serve-mcp.mjs +89 -0
- package/dist/utils/serve-mcp.mjs.map +1 -0
- package/dist/utils/spinner.cjs +19 -0
- package/dist/utils/spinner.d.cts +5 -0
- package/dist/utils/spinner.d.cts.map +1 -0
- package/dist/utils/spinner.d.mts +5 -0
- package/dist/utils/spinner.d.mts.map +1 -0
- package/dist/utils/spinner.mjs +19 -0
- package/dist/utils/spinner.mjs.map +1 -0
- package/dist/utils/string-utils.cjs +11 -0
- package/dist/utils/string-utils.d.cts +5 -0
- package/dist/utils/string-utils.d.cts.map +1 -0
- package/dist/utils/string-utils.d.mts +5 -0
- package/dist/utils/string-utils.d.mts.map +1 -0
- package/dist/utils/string-utils.mjs +10 -0
- package/dist/utils/string-utils.mjs.map +1 -0
- package/dist/utils/time.cjs +14 -0
- package/dist/utils/time.d.cts +5 -0
- package/dist/utils/time.d.cts.map +1 -0
- package/dist/utils/time.d.mts +5 -0
- package/dist/utils/time.d.mts.map +1 -0
- package/dist/utils/time.mjs +14 -0
- package/dist/utils/time.mjs.map +1 -0
- package/dist/utils/url.cjs +8 -0
- package/dist/utils/url.d.cts +5 -0
- package/dist/utils/url.d.cts.map +1 -0
- package/dist/utils/url.d.mts +5 -0
- package/dist/utils/url.d.mts.map +1 -0
- package/dist/utils/url.mjs +8 -0
- package/dist/utils/url.mjs.map +1 -0
- package/dist/utils/yargs.cjs +191 -0
- package/dist/utils/yargs.d.cts +96 -0
- package/dist/utils/yargs.d.cts.map +1 -0
- package/dist/utils/yargs.d.mts +96 -0
- package/dist/utils/yargs.d.mts.map +1 -0
- package/dist/utils/yargs.mjs +186 -0
- package/dist/utils/yargs.mjs.map +1 -0
- package/package.json +122 -45
- package/CHANGELOG.md +0 -5019
- package/dist/bunwrapper.d.ts +0 -2
- package/dist/bunwrapper.js +0 -18
- package/dist/cli.d.ts +0 -7
- package/dist/cli.js +0 -42
- package/dist/commands/aigne.d.ts +0 -4
- package/dist/commands/aigne.js +0 -35
- package/dist/commands/app/agent.d.ts +0 -26
- package/dist/commands/app/agent.js +0 -122
- package/dist/commands/app/app.d.ts +0 -7
- package/dist/commands/app/app.js +0 -92
- package/dist/commands/app/cli.d.ts +0 -1
- package/dist/commands/app/cli.js +0 -2
- package/dist/commands/app/upgrade.d.ts +0 -54
- package/dist/commands/app/upgrade.js +0 -236
- package/dist/commands/app.d.ts +0 -4
- package/dist/commands/app.js +0 -54
- package/dist/commands/create.d.ts +0 -6
- package/dist/commands/create.js +0 -74
- package/dist/commands/deploy.d.ts +0 -11
- package/dist/commands/deploy.js +0 -255
- package/dist/commands/eval.d.ts +0 -11
- package/dist/commands/eval.js +0 -110
- package/dist/commands/hub.d.ts +0 -3
- package/dist/commands/hub.js +0 -323
- package/dist/commands/observe.d.ts +0 -7
- package/dist/commands/observe.js +0 -41
- package/dist/commands/run-skill.d.ts +0 -6
- package/dist/commands/run-skill.js +0 -102
- package/dist/commands/run.d.ts +0 -9
- package/dist/commands/run.js +0 -187
- package/dist/commands/serve-mcp.d.ts +0 -20
- package/dist/commands/serve-mcp.js +0 -67
- package/dist/commands/test.d.ts +0 -9
- package/dist/commands/test.js +0 -33
- package/dist/constants.d.ts +0 -7
- package/dist/constants.js +0 -21
- package/dist/index.d.ts +0 -1
- package/dist/index.js +0 -1
- package/dist/tracer/terminal.d.ts +0 -62
- package/dist/tracer/terminal.js +0 -404
- package/dist/type.d.ts +0 -5
- package/dist/type.js +0 -1
- package/dist/ui/utils/terminal-input.d.ts +0 -19
- package/dist/ui/utils/terminal-input.js +0 -123
- package/dist/ui/utils/text-buffer.d.ts +0 -87
- package/dist/ui/utils/text-buffer.js +0 -1059
- package/dist/ui/utils/text-utils.d.ts +0 -37
- package/dist/ui/utils/text-utils.js +0 -185
- package/dist/utils/agent-v1.d.ts +0 -134
- package/dist/utils/agent-v1.js +0 -213
- package/dist/utils/aigne-hub/constants.d.ts +0 -6
- package/dist/utils/aigne-hub/constants.js +0 -12
- package/dist/utils/aigne-hub/credential.d.ts +0 -20
- package/dist/utils/aigne-hub/credential.js +0 -182
- package/dist/utils/aigne-hub/crypto.d.ts +0 -4
- package/dist/utils/aigne-hub/crypto.js +0 -30
- package/dist/utils/aigne-hub/model.d.ts +0 -13
- package/dist/utils/aigne-hub/model.js +0 -122
- package/dist/utils/aigne-hub/store/file.d.ts +0 -15
- package/dist/utils/aigne-hub/store/file.js +0 -69
- package/dist/utils/aigne-hub/store/index.d.ts +0 -5
- package/dist/utils/aigne-hub/store/index.js +0 -43
- package/dist/utils/aigne-hub/store/keytar.d.ts +0 -15
- package/dist/utils/aigne-hub/store/keytar.js +0 -67
- package/dist/utils/aigne-hub/store/migrate.d.ts +0 -2
- package/dist/utils/aigne-hub/store/migrate.js +0 -57
- package/dist/utils/aigne-hub/type.d.ts +0 -38
- package/dist/utils/aigne-hub/type.js +0 -1
- package/dist/utils/aigne-hub-user.d.ts +0 -16
- package/dist/utils/aigne-hub-user.js +0 -10
- package/dist/utils/ascii-logo.d.ts +0 -1
- package/dist/utils/download.d.ts +0 -3
- package/dist/utils/download.js +0 -19
- package/dist/utils/evaluation/core.d.ts +0 -8
- package/dist/utils/evaluation/core.js +0 -83
- package/dist/utils/evaluation/dataset.d.ts +0 -15
- package/dist/utils/evaluation/dataset.js +0 -61
- package/dist/utils/evaluation/evaluator.d.ts +0 -9
- package/dist/utils/evaluation/reporter.d.ts +0 -28
- package/dist/utils/evaluation/reporter.js +0 -221
- package/dist/utils/evaluation/runner.d.ts +0 -16
- package/dist/utils/evaluation/runner.js +0 -129
- package/dist/utils/evaluation/type.d.ts +0 -69
- package/dist/utils/evaluation/type.js +0 -1
- package/dist/utils/get-url-origin.d.ts +0 -1
- package/dist/utils/get-url-origin.js +0 -8
- package/dist/utils/inquirer/checkbox.d.ts +0 -55
- package/dist/utils/inquirer/checkbox.js +0 -319
- package/dist/utils/listr.d.ts +0 -64
- package/dist/utils/listr.js +0 -265
- package/dist/utils/load-aigne.d.ts +0 -18
- package/dist/utils/load-aigne.js +0 -80
- package/dist/utils/run-chat-loop.d.ts +0 -15
- package/dist/utils/run-chat-loop.js +0 -87
- package/dist/utils/run-with-aigne.d.ts +0 -27
- package/dist/utils/run-with-aigne.js +0 -157
- package/dist/utils/serve-mcp.d.ts +0 -9
- package/dist/utils/serve-mcp.js +0 -93
- package/dist/utils/spinner.d.ts +0 -1
- package/dist/utils/spinner.js +0 -14
- package/dist/utils/string-utils.d.ts +0 -1
- package/dist/utils/string-utils.js +0 -4
- package/dist/utils/time.d.ts +0 -1
- package/dist/utils/time.js +0 -12
- package/dist/utils/url.d.ts +0 -1
- package/dist/utils/url.js +0 -3
- package/dist/utils/yargs.d.ts +0 -94
- package/dist/utils/yargs.js +0 -210
package/dist/utils/listr.js
DELETED
|
@@ -1,265 +0,0 @@
|
|
|
1
|
-
import { EOL } from "node:os";
|
|
2
|
-
import { format } from "node:util";
|
|
3
|
-
import { isAgentResponseProgress } from "@aigne/core";
|
|
4
|
-
import { LogLevel, logger } from "@aigne/core/utils/logger.js";
|
|
5
|
-
import { mergeAgentResponseChunk } from "@aigne/core/utils/stream-utils.js";
|
|
6
|
-
import { color, DefaultRenderer, figures, Listr, ListrDefaultRendererLogLevels, ListrLogger, SimpleRenderer, Spinner, } from "@aigne/listr2";
|
|
7
|
-
import { markedTerminal } from "@aigne/marked-terminal";
|
|
8
|
-
import chalk from "chalk";
|
|
9
|
-
import { Marked } from "marked";
|
|
10
|
-
import wrap from "wrap-ansi";
|
|
11
|
-
export class AIGNEListr extends Listr {
|
|
12
|
-
myOptions;
|
|
13
|
-
result = {};
|
|
14
|
-
error;
|
|
15
|
-
logs = [];
|
|
16
|
-
spinner;
|
|
17
|
-
constructor(myOptions, ...[task, options, parentTask]) {
|
|
18
|
-
const aigneOptions = {
|
|
19
|
-
getStdoutLogs: () => {
|
|
20
|
-
return this.logs.splice(0);
|
|
21
|
-
},
|
|
22
|
-
getBottomBarLogs: (_options) => {
|
|
23
|
-
// if (!options?.running) return [];
|
|
24
|
-
// const r = this.myOptions.formatResult(this.result);
|
|
25
|
-
// if (typeof r !== "string") throw new Error("Must return a string result for running task");
|
|
26
|
-
// return [r];
|
|
27
|
-
return [];
|
|
28
|
-
},
|
|
29
|
-
};
|
|
30
|
-
super(task, {
|
|
31
|
-
...options,
|
|
32
|
-
renderer: AIGNEListrRenderer,
|
|
33
|
-
rendererOptions: {
|
|
34
|
-
collapseSubtasks: false,
|
|
35
|
-
icon: {
|
|
36
|
-
[ListrDefaultRendererLogLevels.PENDING]: () => this.spinner.fetch(),
|
|
37
|
-
[ListrDefaultRendererLogLevels.COMPLETED_WITH_FAILED_SUBTASKS]: figures.cross,
|
|
38
|
-
},
|
|
39
|
-
color: {
|
|
40
|
-
[ListrDefaultRendererLogLevels.COMPLETED_WITH_FAILED_SUBTASKS]: (m) => m ? color.red(m) : "",
|
|
41
|
-
},
|
|
42
|
-
aigne: aigneOptions,
|
|
43
|
-
},
|
|
44
|
-
fallbackRenderer: AIGNEListrFallbackRenderer,
|
|
45
|
-
fallbackRendererOptions: {
|
|
46
|
-
aigne: aigneOptions,
|
|
47
|
-
logger: new (class extends ListrLogger {
|
|
48
|
-
log(...[level, ...args]) {
|
|
49
|
-
// ignore stdout logs if level `INFO` is not enabled
|
|
50
|
-
if (!this.options?.toStderr?.includes(level) && !logger.enabled(LogLevel.INFO)) {
|
|
51
|
-
return;
|
|
52
|
-
}
|
|
53
|
-
super.log(level, ...args);
|
|
54
|
-
}
|
|
55
|
-
})(),
|
|
56
|
-
},
|
|
57
|
-
}, parentTask);
|
|
58
|
-
this.myOptions = myOptions;
|
|
59
|
-
this.spinner = new Spinner();
|
|
60
|
-
}
|
|
61
|
-
needLogResult = true;
|
|
62
|
-
async run(stream) {
|
|
63
|
-
const originalLog = logger.logMessage;
|
|
64
|
-
const originalConsole = { ...console };
|
|
65
|
-
try {
|
|
66
|
-
this.ctx = {};
|
|
67
|
-
this.spinner.start();
|
|
68
|
-
if (logger.enabled(LogLevel.INFO)) {
|
|
69
|
-
const request = this.myOptions.formatRequest();
|
|
70
|
-
if (request)
|
|
71
|
-
console.log(request);
|
|
72
|
-
}
|
|
73
|
-
logger.logMessage = (...args) => this.logs.push(format(...args));
|
|
74
|
-
for (const method of ["debug", "log", "info", "warn", "error"]) {
|
|
75
|
-
console[method] = (...args) => {
|
|
76
|
-
const renderer = this["renderer"] instanceof AIGNEListrRenderer ? this["renderer"] : undefined;
|
|
77
|
-
const msg = format(...args);
|
|
78
|
-
renderer ? renderer.log(msg) : this.logs.push(msg);
|
|
79
|
-
};
|
|
80
|
-
}
|
|
81
|
-
const _stream = await stream();
|
|
82
|
-
this.add({ task: () => this.extractStream(_stream) });
|
|
83
|
-
const result = await super.run().then(() => {
|
|
84
|
-
if (this.error)
|
|
85
|
-
throw this.error;
|
|
86
|
-
return { ...this.result };
|
|
87
|
-
});
|
|
88
|
-
if (this.needLogResult) {
|
|
89
|
-
console.log(await this.myOptions.formatResult(this.result, { running: false, renderImage: true }));
|
|
90
|
-
}
|
|
91
|
-
return result;
|
|
92
|
-
}
|
|
93
|
-
finally {
|
|
94
|
-
logger.logMessage = originalLog;
|
|
95
|
-
Object.assign(console, originalConsole);
|
|
96
|
-
this.spinner.stop();
|
|
97
|
-
}
|
|
98
|
-
}
|
|
99
|
-
marked = new Marked().use({
|
|
100
|
-
// marked-terminal does not support code block meta, so we need to strip it
|
|
101
|
-
walkTokens: (token) => {
|
|
102
|
-
if (token.type === "code") {
|
|
103
|
-
if (typeof token.lang === "string") {
|
|
104
|
-
token.lang = token.lang.trim().split(/\s+/)[0];
|
|
105
|
-
}
|
|
106
|
-
}
|
|
107
|
-
},
|
|
108
|
-
}, markedTerminal({ forceHyperLink: false }, {
|
|
109
|
-
theme: {
|
|
110
|
-
string: chalk.green,
|
|
111
|
-
},
|
|
112
|
-
}));
|
|
113
|
-
async extractStream(stream) {
|
|
114
|
-
try {
|
|
115
|
-
this.result = {};
|
|
116
|
-
for await (const value of stream) {
|
|
117
|
-
mergeAgentResponseChunk(this.result, value);
|
|
118
|
-
if (isAgentResponseProgress(value) && value.progress.event === "message") {
|
|
119
|
-
const { message } = value.progress;
|
|
120
|
-
const rendered = [];
|
|
121
|
-
if (message.role === "user" || message.role === "agent") {
|
|
122
|
-
if (message.role === "agent" && message.toolCalls) {
|
|
123
|
-
for (const call of message.toolCalls) {
|
|
124
|
-
rendered.push(`${chalk.bold.gray(`[${call.function.name}]`)} ${chalk.gray(`${JSON.stringify(call.function.arguments).slice(0, 200)}...`)}`);
|
|
125
|
-
}
|
|
126
|
-
}
|
|
127
|
-
else if (typeof message.content === "string") {
|
|
128
|
-
rendered.push(this.marked.parse(message.content, { async: false }).trim());
|
|
129
|
-
}
|
|
130
|
-
else if (Array.isArray(message.content)) {
|
|
131
|
-
for (const msg of message.content) {
|
|
132
|
-
if (msg.type === "text") {
|
|
133
|
-
if (msg.isThinking) {
|
|
134
|
-
rendered.push(chalk.dim(chalk.grey(chalk.italic(`[Thinking] ${msg.text}`))));
|
|
135
|
-
}
|
|
136
|
-
else {
|
|
137
|
-
rendered.push(this.marked.parse(msg.text, { async: false }).trim());
|
|
138
|
-
}
|
|
139
|
-
}
|
|
140
|
-
}
|
|
141
|
-
}
|
|
142
|
-
}
|
|
143
|
-
if (rendered.length) {
|
|
144
|
-
const prefix = message.role === "user" ? chalk.blue.bold(">") : chalk.green.bold("•");
|
|
145
|
-
console.log(`${prefix} ${rendered.join("\n")}\n`);
|
|
146
|
-
this.needLogResult = false;
|
|
147
|
-
}
|
|
148
|
-
}
|
|
149
|
-
}
|
|
150
|
-
return this.result;
|
|
151
|
-
}
|
|
152
|
-
catch (error) {
|
|
153
|
-
this.error = error;
|
|
154
|
-
throw error;
|
|
155
|
-
}
|
|
156
|
-
}
|
|
157
|
-
}
|
|
158
|
-
export class AIGNEListrRenderer extends DefaultRenderer {
|
|
159
|
-
static rendererOptions = {
|
|
160
|
-
...DefaultRenderer.rendererOptions,
|
|
161
|
-
};
|
|
162
|
-
get _updater() {
|
|
163
|
-
return this["updater"];
|
|
164
|
-
}
|
|
165
|
-
get _logger() {
|
|
166
|
-
return this["logger"];
|
|
167
|
-
}
|
|
168
|
-
get _options() {
|
|
169
|
-
return this["options"];
|
|
170
|
-
}
|
|
171
|
-
get _spinner() {
|
|
172
|
-
return this["spinner"];
|
|
173
|
-
}
|
|
174
|
-
update() {
|
|
175
|
-
if (this.paused || this.ended) {
|
|
176
|
-
return;
|
|
177
|
-
}
|
|
178
|
-
this._updater(this.create({ running: true }));
|
|
179
|
-
}
|
|
180
|
-
paused = false;
|
|
181
|
-
ended = false;
|
|
182
|
-
end() {
|
|
183
|
-
this.ended = true;
|
|
184
|
-
super.end();
|
|
185
|
-
}
|
|
186
|
-
async pause() {
|
|
187
|
-
this.paused = true;
|
|
188
|
-
this._updater?.clear();
|
|
189
|
-
this._updater?.done();
|
|
190
|
-
await new Promise((resolve) => setTimeout(resolve, 100));
|
|
191
|
-
this._logger.process.release();
|
|
192
|
-
}
|
|
193
|
-
async resume() {
|
|
194
|
-
this._logger.process.hijack();
|
|
195
|
-
this.paused = false;
|
|
196
|
-
}
|
|
197
|
-
log(message) {
|
|
198
|
-
this._updater?.clear();
|
|
199
|
-
this._logger.toStdout(message);
|
|
200
|
-
}
|
|
201
|
-
isPreviousPrompt = false;
|
|
202
|
-
create({ running = false, ...options }) {
|
|
203
|
-
const logs = this._options.aigne?.getStdoutLogs?.();
|
|
204
|
-
if (logs?.length) {
|
|
205
|
-
this._updater.clear();
|
|
206
|
-
this._logger.toStdout(logs.join(EOL));
|
|
207
|
-
}
|
|
208
|
-
let buffer = "";
|
|
209
|
-
const prompt = super["renderPrompt"]();
|
|
210
|
-
if (prompt.length) {
|
|
211
|
-
buffer += prompt.join(EOL);
|
|
212
|
-
this.isPreviousPrompt = true;
|
|
213
|
-
}
|
|
214
|
-
// Skip a frame if previous render was a prompt, and reset the flag
|
|
215
|
-
else if (this.isPreviousPrompt) {
|
|
216
|
-
this.isPreviousPrompt = false;
|
|
217
|
-
}
|
|
218
|
-
else {
|
|
219
|
-
buffer += super.create({ ...options, prompt: false });
|
|
220
|
-
const bottomBar = this._options.aigne?.getBottomBarLogs?.({ running });
|
|
221
|
-
if (bottomBar?.length) {
|
|
222
|
-
buffer += EOL.repeat(2);
|
|
223
|
-
const output = [...bottomBar, running ? this._spinner.fetch() : ""]
|
|
224
|
-
.map((i) => this._wrap(i))
|
|
225
|
-
.join(EOL);
|
|
226
|
-
// If the task is not running, we show all lines
|
|
227
|
-
if (!running) {
|
|
228
|
-
buffer += output;
|
|
229
|
-
}
|
|
230
|
-
// For running tasks, we only show the last few lines
|
|
231
|
-
else {
|
|
232
|
-
const { rows } = process.stdout;
|
|
233
|
-
const lines = rows - buffer.split(EOL).length - 2;
|
|
234
|
-
buffer += output.split(EOL).slice(-Math.max(4, lines)).join(EOL);
|
|
235
|
-
}
|
|
236
|
-
}
|
|
237
|
-
}
|
|
238
|
-
return buffer;
|
|
239
|
-
}
|
|
240
|
-
_wrap(str) {
|
|
241
|
-
return wrap(str, process.stdout.columns ?? 80, {
|
|
242
|
-
hard: true,
|
|
243
|
-
trim: false,
|
|
244
|
-
});
|
|
245
|
-
}
|
|
246
|
-
}
|
|
247
|
-
export class AIGNEListrFallbackRenderer extends SimpleRenderer {
|
|
248
|
-
static rendererOptions = {
|
|
249
|
-
...SimpleRenderer.rendererOptions,
|
|
250
|
-
};
|
|
251
|
-
get _logger() {
|
|
252
|
-
return this["logger"];
|
|
253
|
-
}
|
|
254
|
-
get _options() {
|
|
255
|
-
return this["options"];
|
|
256
|
-
}
|
|
257
|
-
end() {
|
|
258
|
-
const logs = [this._options.aigne?.getStdoutLogs?.(), this._options.aigne?.getBottomBarLogs?.()]
|
|
259
|
-
.filter(Boolean)
|
|
260
|
-
.flat()
|
|
261
|
-
.join(EOL);
|
|
262
|
-
if (logs)
|
|
263
|
-
this._logger.toStdout(logs);
|
|
264
|
-
}
|
|
265
|
-
}
|
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
import { AIGNE, type ChatModel, type ChatModelInputOptions, type ImageModelInputOptions } from "@aigne/core";
|
|
2
|
-
import type { AIGNEMetadata } from "@aigne/core/aigne/type.js";
|
|
3
|
-
import type { LoadCredentialOptions } from "./aigne-hub/type.js";
|
|
4
|
-
import type { AgentRunCommonOptions } from "./yargs.js";
|
|
5
|
-
export interface RunOptions extends AgentRunCommonOptions {
|
|
6
|
-
path: string;
|
|
7
|
-
entryAgent?: string;
|
|
8
|
-
cacheDir?: string;
|
|
9
|
-
aigneHubUrl?: string;
|
|
10
|
-
}
|
|
11
|
-
export declare function printChatModelInfoBox(model: ChatModel, otherLines?: string[]): Promise<void>;
|
|
12
|
-
export declare function loadAIGNE({ path, modelOptions, imageModelOptions, skipModelLoading, metadata, }: {
|
|
13
|
-
path?: string;
|
|
14
|
-
modelOptions?: ChatModelInputOptions & LoadCredentialOptions;
|
|
15
|
-
imageModelOptions?: ImageModelInputOptions & LoadCredentialOptions;
|
|
16
|
-
skipModelLoading?: boolean;
|
|
17
|
-
metadata?: AIGNEMetadata;
|
|
18
|
-
}): Promise<AIGNE<import("@aigne/core").UserContext>>;
|
package/dist/utils/load-aigne.js
DELETED
|
@@ -1,80 +0,0 @@
|
|
|
1
|
-
import { createRequire } from "node:module";
|
|
2
|
-
import { AIGNE, } from "@aigne/core";
|
|
3
|
-
import { isNil, omitBy } from "@aigne/core/utils/type-utils.js";
|
|
4
|
-
import boxen from "boxen";
|
|
5
|
-
import chalk from "chalk";
|
|
6
|
-
import { AIGNE_CLI_VERSION, availableMemories } from "../constants.js";
|
|
7
|
-
import { loadChatModel, loadImageModel, maskApiKey } from "./aigne-hub/model.js";
|
|
8
|
-
import { getUrlOrigin } from "./get-url-origin.js";
|
|
9
|
-
export async function printChatModelInfoBox(model, otherLines) {
|
|
10
|
-
console.log(`${chalk.grey("TIPS:")} run ${chalk.cyan("aigne observe")} to start the observability server.\n`);
|
|
11
|
-
const credential = await model.credential;
|
|
12
|
-
const lines = [`${chalk.cyan("Provider")}: ${chalk.green(model.name.replace("ChatModel", ""))}`];
|
|
13
|
-
if (credential?.model) {
|
|
14
|
-
lines.push(`${chalk.cyan("Model")}: ${chalk.green(credential?.model)}`);
|
|
15
|
-
}
|
|
16
|
-
if (credential?.url) {
|
|
17
|
-
lines.push(`${chalk.cyan("API URL")}: ${chalk.green(getUrlOrigin(credential?.url) || "N/A")}`);
|
|
18
|
-
}
|
|
19
|
-
if (credential?.apiKey) {
|
|
20
|
-
lines.push(`${chalk.cyan("API Key")}: ${chalk.green(maskApiKey(credential?.apiKey))}`);
|
|
21
|
-
}
|
|
22
|
-
if (otherLines?.length)
|
|
23
|
-
lines.push(...otherLines);
|
|
24
|
-
console.log(boxen(lines.join("\n"), { padding: 1, borderStyle: "classic", borderColor: "cyan" }));
|
|
25
|
-
console.log("");
|
|
26
|
-
}
|
|
27
|
-
export async function loadAIGNE({ path, modelOptions, imageModelOptions, skipModelLoading = false, metadata, }) {
|
|
28
|
-
let aigne;
|
|
29
|
-
if (path) {
|
|
30
|
-
aigne = await AIGNE.load(path, {
|
|
31
|
-
require: async (modulePath, options) => {
|
|
32
|
-
if (!options.parent || modulePath.startsWith("@aigne/"))
|
|
33
|
-
return import(modulePath);
|
|
34
|
-
const require = createRequire(options.parent);
|
|
35
|
-
return require(modulePath);
|
|
36
|
-
},
|
|
37
|
-
memories: availableMemories,
|
|
38
|
-
model: (options) => {
|
|
39
|
-
if (skipModelLoading)
|
|
40
|
-
return undefined;
|
|
41
|
-
return loadChatModel({
|
|
42
|
-
...options,
|
|
43
|
-
...omitBy(modelOptions ?? {}, (v) => isNil(v)),
|
|
44
|
-
model: modelOptions?.model || process.env.MODEL || options?.model,
|
|
45
|
-
});
|
|
46
|
-
},
|
|
47
|
-
imageModel: (options) => {
|
|
48
|
-
if (skipModelLoading)
|
|
49
|
-
return undefined;
|
|
50
|
-
return loadImageModel({
|
|
51
|
-
...options,
|
|
52
|
-
...omitBy(imageModelOptions ?? {}, (v) => isNil(v)),
|
|
53
|
-
model: imageModelOptions?.model || process.env.IMAGE_MODEL || options?.model,
|
|
54
|
-
});
|
|
55
|
-
},
|
|
56
|
-
afs: {
|
|
57
|
-
availableModules: [
|
|
58
|
-
{
|
|
59
|
-
module: "history",
|
|
60
|
-
load: (options) => import("@aigne/afs-history").then((m) => m.AFSHistory.load(options)),
|
|
61
|
-
},
|
|
62
|
-
{
|
|
63
|
-
module: "local-fs",
|
|
64
|
-
alias: ["system-fs"],
|
|
65
|
-
load: (options) => import("@aigne/afs-local-fs").then((m) => m.LocalFS.load(options)),
|
|
66
|
-
},
|
|
67
|
-
],
|
|
68
|
-
},
|
|
69
|
-
metadata: { ...metadata, cliVersion: AIGNE_CLI_VERSION },
|
|
70
|
-
});
|
|
71
|
-
}
|
|
72
|
-
else {
|
|
73
|
-
const chatModel = await loadChatModel({ ...modelOptions });
|
|
74
|
-
aigne = new AIGNE({
|
|
75
|
-
model: chatModel,
|
|
76
|
-
metadata: { ...metadata, cliVersion: AIGNE_CLI_VERSION },
|
|
77
|
-
});
|
|
78
|
-
}
|
|
79
|
-
return aigne;
|
|
80
|
-
}
|
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
import { type Message, type UserAgent } from "@aigne/core";
|
|
2
|
-
export declare const DEFAULT_CHAT_INPUT_KEY = "message";
|
|
3
|
-
export interface ChatLoopOptions {
|
|
4
|
-
userId?: string;
|
|
5
|
-
sessionId?: string;
|
|
6
|
-
initialCall?: Message | string;
|
|
7
|
-
welcome?: string;
|
|
8
|
-
defaultQuestion?: string;
|
|
9
|
-
inputKey?: string;
|
|
10
|
-
inputFileKey?: string;
|
|
11
|
-
outputKey?: string;
|
|
12
|
-
dataOutputKey?: string;
|
|
13
|
-
input?: Message;
|
|
14
|
-
}
|
|
15
|
-
export declare function runChatLoopInTerminal(userAgent: UserAgent<any, any>, options?: ChatLoopOptions): Promise<void>;
|
|
@@ -1,87 +0,0 @@
|
|
|
1
|
-
import { readFile } from "node:fs/promises";
|
|
2
|
-
import { basename } from "node:path";
|
|
3
|
-
import { ChatModel } from "@aigne/core";
|
|
4
|
-
import { isNonNullable, omit } from "@aigne/core/utils/type-utils.js";
|
|
5
|
-
import { TerminalTracer } from "../tracer/terminal.js";
|
|
6
|
-
import { terminalInput } from "../ui/utils/terminal-input.js";
|
|
7
|
-
export const DEFAULT_CHAT_INPUT_KEY = "message";
|
|
8
|
-
export async function runChatLoopInTerminal(userAgent, options = {}) {
|
|
9
|
-
const { initialCall } = options;
|
|
10
|
-
if (initialCall) {
|
|
11
|
-
await callAgent(userAgent, initialCall, options);
|
|
12
|
-
if (options.input && options.inputFileKey) {
|
|
13
|
-
options.input = omit(options.input, options.inputFileKey);
|
|
14
|
-
}
|
|
15
|
-
}
|
|
16
|
-
for (let i = 0;; i++) {
|
|
17
|
-
const question = await terminalInput({
|
|
18
|
-
message: "💬",
|
|
19
|
-
default: i === 0 ? options?.defaultQuestion : undefined,
|
|
20
|
-
clear: true,
|
|
21
|
-
});
|
|
22
|
-
if (!question?.trim())
|
|
23
|
-
continue;
|
|
24
|
-
const cmd = COMMANDS[question.trim()];
|
|
25
|
-
if (cmd) {
|
|
26
|
-
const result = cmd();
|
|
27
|
-
if (result.message)
|
|
28
|
-
console.log(result.message);
|
|
29
|
-
if (result?.exit)
|
|
30
|
-
break;
|
|
31
|
-
continue;
|
|
32
|
-
}
|
|
33
|
-
const input = {};
|
|
34
|
-
if (options.inputFileKey) {
|
|
35
|
-
const { message, files } = await extractFilesFromQuestion(question);
|
|
36
|
-
input[options.inputKey || DEFAULT_CHAT_INPUT_KEY] = message;
|
|
37
|
-
input[options.inputFileKey] = files;
|
|
38
|
-
}
|
|
39
|
-
else {
|
|
40
|
-
input[options.inputKey || DEFAULT_CHAT_INPUT_KEY] = question;
|
|
41
|
-
}
|
|
42
|
-
await callAgent(userAgent, input, options);
|
|
43
|
-
if (options.input && options.inputFileKey) {
|
|
44
|
-
options.input = omit(options.input, options.inputFileKey);
|
|
45
|
-
}
|
|
46
|
-
}
|
|
47
|
-
}
|
|
48
|
-
async function extractFilesFromQuestion(question) {
|
|
49
|
-
const fileRegex = /@\S+/g;
|
|
50
|
-
const paths = question.match(fileRegex) || [];
|
|
51
|
-
const files = (await Promise.all(paths.map(async (path) => {
|
|
52
|
-
const p = path.slice(1);
|
|
53
|
-
const filename = basename(p);
|
|
54
|
-
const data = await readFile(p, "base64").catch((error) => {
|
|
55
|
-
if (error.code === "ENOENT")
|
|
56
|
-
return null;
|
|
57
|
-
throw error;
|
|
58
|
-
});
|
|
59
|
-
if (!data)
|
|
60
|
-
return;
|
|
61
|
-
return {
|
|
62
|
-
path,
|
|
63
|
-
file: { type: "file", data, filename, mimeType: await ChatModel.getMimeType(filename) },
|
|
64
|
-
};
|
|
65
|
-
}))).filter(isNonNullable);
|
|
66
|
-
// Remove file paths from question
|
|
67
|
-
for (const { path } of files) {
|
|
68
|
-
question = question.replaceAll(path, "");
|
|
69
|
-
}
|
|
70
|
-
return { message: question, files: files.map((i) => i.file) };
|
|
71
|
-
}
|
|
72
|
-
async function callAgent(userAgent, input, options) {
|
|
73
|
-
const tracer = new TerminalTracer(userAgent.context, options);
|
|
74
|
-
await tracer.run(userAgent, typeof input === "string"
|
|
75
|
-
? { ...options.input, [options.inputKey || DEFAULT_CHAT_INPUT_KEY]: input }
|
|
76
|
-
: { ...options.input, ...input }, { userContext: { sessionId: options.sessionId, userId: options.userId } });
|
|
77
|
-
}
|
|
78
|
-
const COMMANDS = {
|
|
79
|
-
"/exit": () => ({ exit: true }),
|
|
80
|
-
"/help": () => ({
|
|
81
|
-
message: `\
|
|
82
|
-
Commands:
|
|
83
|
-
/exit - exit the chat loop
|
|
84
|
-
/help - show this help message
|
|
85
|
-
`,
|
|
86
|
-
}),
|
|
87
|
-
};
|
|
@@ -1,27 +0,0 @@
|
|
|
1
|
-
import { type Agent, type AIGNE, type ChatModelInputOptions, type Message } from "@aigne/core";
|
|
2
|
-
import { type PromiseOrValue } from "@aigne/core/utils/type-utils.js";
|
|
3
|
-
import { type ChatLoopOptions } from "./run-chat-loop.js";
|
|
4
|
-
import { type AgentRunCommonOptions } from "./yargs.js";
|
|
5
|
-
export declare function parseAgentInputByCommander(agent: Agent, options?: AgentRunCommonOptions & {
|
|
6
|
-
inputKey?: string;
|
|
7
|
-
argv?: string[];
|
|
8
|
-
defaultInput?: string | Message;
|
|
9
|
-
}): Promise<Message>;
|
|
10
|
-
export declare function loadAIGNEWithCmdOptions(): Promise<AIGNE<import("@aigne/core").UserContext>>;
|
|
11
|
-
export declare function runWithAIGNE(agentCreator: ((aigne: AIGNE) => PromiseOrValue<Agent>) | Agent, { aigne, argv, chatLoopOptions, modelOptions, outputKey, }?: {
|
|
12
|
-
aigne?: AIGNE;
|
|
13
|
-
argv?: typeof process.argv;
|
|
14
|
-
chatLoopOptions?: ChatLoopOptions;
|
|
15
|
-
modelOptions?: ChatModelInputOptions;
|
|
16
|
-
outputKey?: string;
|
|
17
|
-
}): Promise<void>;
|
|
18
|
-
export declare function runAgentWithAIGNE(aigne: AIGNE, agent: Agent, { userId, sessionId, outputKey, outputFileKey, chatLoopOptions, ...options }?: {
|
|
19
|
-
userId?: string;
|
|
20
|
-
sessionId?: string;
|
|
21
|
-
outputKey?: string;
|
|
22
|
-
outputFileKey?: string;
|
|
23
|
-
chatLoopOptions?: ChatLoopOptions;
|
|
24
|
-
input?: Message;
|
|
25
|
-
} & Omit<AgentRunCommonOptions, "input">): Promise<{
|
|
26
|
-
result: Message;
|
|
27
|
-
} | undefined>;
|
|
@@ -1,157 +0,0 @@
|
|
|
1
|
-
import { mkdir, stat, writeFile } from "node:fs/promises";
|
|
2
|
-
import { dirname, isAbsolute, join } from "node:path";
|
|
3
|
-
import { isatty } from "node:tty";
|
|
4
|
-
import { fileURLToPath } from "node:url";
|
|
5
|
-
import { startExplorer } from "@aigne/afs-explorer";
|
|
6
|
-
import { exists } from "@aigne/agent-library/utils/fs.js";
|
|
7
|
-
import { AIAgent, DEFAULT_OUTPUT_KEY, UserAgent, } from "@aigne/core";
|
|
8
|
-
import { logger } from "@aigne/core/utils/logger.js";
|
|
9
|
-
import { isEmpty, isNil, omitBy, pick } from "@aigne/core/utils/type-utils.js";
|
|
10
|
-
import { v7 } from "@aigne/uuid";
|
|
11
|
-
import chalk from "chalk";
|
|
12
|
-
import { detect } from "detect-port";
|
|
13
|
-
import yargs from "yargs";
|
|
14
|
-
import { hideBin } from "yargs/helpers";
|
|
15
|
-
import { DEFAULT_AFS_EXPLORER_PORT, DEFAULT_USER_ID } from "../constants.js";
|
|
16
|
-
import { TerminalTracer } from "../tracer/terminal.js";
|
|
17
|
-
import { loadAIGNE, printChatModelInfoBox } from "./load-aigne.js";
|
|
18
|
-
import { DEFAULT_CHAT_INPUT_KEY, runChatLoopInTerminal, } from "./run-chat-loop.js";
|
|
19
|
-
import { parseAgentInput, withAgentInputSchema, withRunAgentCommonOptions, } from "./yargs.js";
|
|
20
|
-
export async function parseAgentInputByCommander(agent, options = {}) {
|
|
21
|
-
const args = await withAgentInputSchema(yargs(), agent)
|
|
22
|
-
.showHelpOnFail(false)
|
|
23
|
-
.fail(() => { })
|
|
24
|
-
.parseAsync(options.argv ?? process.argv);
|
|
25
|
-
const input = await parseAgentInput({ ...args, input: options.input || args.input }, agent);
|
|
26
|
-
if (isEmpty(input)) {
|
|
27
|
-
const defaultInput = options.defaultInput || process.env.INITIAL_CALL;
|
|
28
|
-
Object.assign(input, typeof defaultInput === "string"
|
|
29
|
-
? {
|
|
30
|
-
[options?.inputKey ||
|
|
31
|
-
(agent instanceof AIAgent ? agent.inputKey : undefined) ||
|
|
32
|
-
DEFAULT_CHAT_INPUT_KEY]: defaultInput,
|
|
33
|
-
}
|
|
34
|
-
: defaultInput);
|
|
35
|
-
}
|
|
36
|
-
return input;
|
|
37
|
-
}
|
|
38
|
-
export async function loadAIGNEWithCmdOptions() {
|
|
39
|
-
const options = await withRunAgentCommonOptions(yargs())
|
|
40
|
-
.strict(false)
|
|
41
|
-
.parseAsync(hideBin(process.argv));
|
|
42
|
-
return await loadAIGNE({
|
|
43
|
-
modelOptions: {
|
|
44
|
-
...omitBy(pick(options, "model", "temperature", "topP", "presencePenalty", "frequencyPenalty"), (v) => isNil(v)),
|
|
45
|
-
},
|
|
46
|
-
});
|
|
47
|
-
}
|
|
48
|
-
export async function runWithAIGNE(agentCreator, { aigne, argv = process.argv, chatLoopOptions, modelOptions, outputKey, } = {}) {
|
|
49
|
-
await yargs()
|
|
50
|
-
.command("$0", "Execute an AI agent using the AIGNE framework with specified configuration", (yargs) => withRunAgentCommonOptions(yargs), async (options) => {
|
|
51
|
-
if (options.logLevel) {
|
|
52
|
-
logger.level = options.logLevel;
|
|
53
|
-
}
|
|
54
|
-
aigne ??= await loadAIGNE({
|
|
55
|
-
modelOptions: {
|
|
56
|
-
...modelOptions,
|
|
57
|
-
...omitBy(pick(options, "model", "temperature", "topP", "presencePenalty", "frequencyPenalty"), (v) => isNil(v)),
|
|
58
|
-
},
|
|
59
|
-
});
|
|
60
|
-
let explorerServer;
|
|
61
|
-
let explorerServerURL;
|
|
62
|
-
try {
|
|
63
|
-
const agent = typeof agentCreator === "function" ? await agentCreator(aigne) : agentCreator;
|
|
64
|
-
const input = await parseAgentInputByCommander(agent, {
|
|
65
|
-
...options,
|
|
66
|
-
inputKey: chatLoopOptions?.inputKey,
|
|
67
|
-
defaultInput: chatLoopOptions?.initialCall || chatLoopOptions?.defaultQuestion,
|
|
68
|
-
});
|
|
69
|
-
if (agent.afs) {
|
|
70
|
-
const port = await detect(DEFAULT_AFS_EXPLORER_PORT);
|
|
71
|
-
explorerServer = await startExplorer(agent.afs, {
|
|
72
|
-
port,
|
|
73
|
-
distPath: dirname(fileURLToPath(import.meta.resolve("@aigne/afs-explorer/index.html"))),
|
|
74
|
-
});
|
|
75
|
-
explorerServerURL = `http://localhost:${port}`;
|
|
76
|
-
}
|
|
77
|
-
if (aigne.model) {
|
|
78
|
-
const lines = [];
|
|
79
|
-
if (explorerServerURL) {
|
|
80
|
-
lines.push(`${chalk.cyan("AFS Explorer")}: ${chalk.green(explorerServerURL)}`);
|
|
81
|
-
}
|
|
82
|
-
await printChatModelInfoBox(aigne.model, lines);
|
|
83
|
-
}
|
|
84
|
-
if (chatLoopOptions?.welcome)
|
|
85
|
-
console.log(chatLoopOptions.welcome);
|
|
86
|
-
await runAgentWithAIGNE(aigne, agent, {
|
|
87
|
-
...options,
|
|
88
|
-
outputKey: outputKey || options.outputKey,
|
|
89
|
-
chatLoopOptions,
|
|
90
|
-
input,
|
|
91
|
-
sessionId: chatLoopOptions?.sessionId || v7(),
|
|
92
|
-
userId: DEFAULT_USER_ID,
|
|
93
|
-
});
|
|
94
|
-
}
|
|
95
|
-
finally {
|
|
96
|
-
await explorerServer?.stop();
|
|
97
|
-
await aigne.shutdown();
|
|
98
|
-
}
|
|
99
|
-
})
|
|
100
|
-
.alias("h", "help")
|
|
101
|
-
.alias("v", "version")
|
|
102
|
-
.fail((message, error, yargs) => {
|
|
103
|
-
if (!error)
|
|
104
|
-
yargs.showHelp();
|
|
105
|
-
console.error(`\n${message || error?.message}`);
|
|
106
|
-
process.exit(1);
|
|
107
|
-
})
|
|
108
|
-
.parseAsync(hideBin(argv))
|
|
109
|
-
.catch((error) => {
|
|
110
|
-
console.error(`${chalk.red("Error:")} ${error.message}`);
|
|
111
|
-
process.exit(1);
|
|
112
|
-
});
|
|
113
|
-
}
|
|
114
|
-
export async function runAgentWithAIGNE(aigne, agent, { userId, sessionId, outputKey, outputFileKey, chatLoopOptions, ...options } = {}) {
|
|
115
|
-
if (options.output) {
|
|
116
|
-
const outputPath = isAbsolute(options.output)
|
|
117
|
-
? options.output
|
|
118
|
-
: join(process.cwd(), options.output);
|
|
119
|
-
if (await exists(outputPath)) {
|
|
120
|
-
const s = await stat(outputPath);
|
|
121
|
-
if (!s.isFile())
|
|
122
|
-
throw new Error(`Output path ${outputPath} is not a file`);
|
|
123
|
-
if (s.size > 0 && !options.force) {
|
|
124
|
-
throw new Error(`Output file ${outputPath} already exists. Use --force to overwrite.`);
|
|
125
|
-
}
|
|
126
|
-
}
|
|
127
|
-
else {
|
|
128
|
-
await mkdir(dirname(outputPath), { recursive: true });
|
|
129
|
-
}
|
|
130
|
-
await writeFile(outputPath, "", "utf8");
|
|
131
|
-
}
|
|
132
|
-
if (options.interactive) {
|
|
133
|
-
if (!isatty(process.stdout.fd)) {
|
|
134
|
-
throw new Error("--interactive mode requires a TTY terminal");
|
|
135
|
-
}
|
|
136
|
-
const userAgent = agent instanceof UserAgent ? agent : aigne.invoke(agent);
|
|
137
|
-
await runChatLoopInTerminal(userAgent, {
|
|
138
|
-
...chatLoopOptions,
|
|
139
|
-
outputKey,
|
|
140
|
-
inputFileKey: agent instanceof AIAgent ? agent.inputFileKey : undefined,
|
|
141
|
-
input: options.input,
|
|
142
|
-
sessionId,
|
|
143
|
-
userId,
|
|
144
|
-
});
|
|
145
|
-
return;
|
|
146
|
-
}
|
|
147
|
-
const tracer = new TerminalTracer(aigne.newContext(), { outputKey, outputFileKey });
|
|
148
|
-
const { result } = await tracer.run(agent, options.input ?? {});
|
|
149
|
-
if (options.output) {
|
|
150
|
-
const message = result[outputKey || DEFAULT_OUTPUT_KEY];
|
|
151
|
-
const content = typeof message === "string" ? message : JSON.stringify(result, null, 2);
|
|
152
|
-
const path = isAbsolute(options.output) ? options.output : join(process.cwd(), options.output);
|
|
153
|
-
await mkdir(dirname(path), { recursive: true });
|
|
154
|
-
await writeFile(path, content, "utf8");
|
|
155
|
-
}
|
|
156
|
-
return { result };
|
|
157
|
-
}
|
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
import { type AIGNE } from "@aigne/core";
|
|
2
|
-
import { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
|
|
3
|
-
export declare function serveMCPServer({ pathname, aigne, host, port, }: {
|
|
4
|
-
pathname?: string;
|
|
5
|
-
aigne: AIGNE;
|
|
6
|
-
host?: string;
|
|
7
|
-
port: number;
|
|
8
|
-
}): Promise<import("http").Server<typeof import("http").IncomingMessage, typeof import("http").ServerResponse>>;
|
|
9
|
-
export declare function createMcpServer(aigne: AIGNE): McpServer;
|