@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
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
const require_rolldown_runtime = require('../_virtual/rolldown_runtime.cjs');
|
|
2
|
+
const require_constants = require('../constants.cjs');
|
|
3
|
+
const require_utils_aigne_hub_model = require('./aigne-hub/model.cjs');
|
|
4
|
+
const require_utils_get_url_origin = require('./get-url-origin.cjs');
|
|
5
|
+
let chalk = require("chalk");
|
|
6
|
+
chalk = require_rolldown_runtime.__toESM(chalk);
|
|
7
|
+
let node_module = require("node:module");
|
|
8
|
+
let _aigne_core = require("@aigne/core");
|
|
9
|
+
let _aigne_core_utils_type_utils = require("@aigne/core/utils/type-utils");
|
|
10
|
+
let boxen = require("boxen");
|
|
11
|
+
boxen = require_rolldown_runtime.__toESM(boxen);
|
|
12
|
+
|
|
13
|
+
//#region src/utils/load-aigne.ts
|
|
14
|
+
async function printChatModelInfoBox(model, otherLines) {
|
|
15
|
+
console.log(`${chalk.default.grey("TIPS:")} run ${chalk.default.cyan("aigne observe")} to start the observability server.\n`);
|
|
16
|
+
const credential = await model.credential;
|
|
17
|
+
const lines = [`${chalk.default.cyan("Provider")}: ${chalk.default.green(model.name.replace("ChatModel", ""))}`];
|
|
18
|
+
if (credential?.model) lines.push(`${chalk.default.cyan("Model")}: ${chalk.default.green(credential?.model)}`);
|
|
19
|
+
if (credential?.url) lines.push(`${chalk.default.cyan("API URL")}: ${chalk.default.green(require_utils_get_url_origin.getUrlOrigin(credential?.url) || "N/A")}`);
|
|
20
|
+
if (credential?.apiKey) lines.push(`${chalk.default.cyan("API Key")}: ${chalk.default.green(require_utils_aigne_hub_model.maskApiKey(credential?.apiKey))}`);
|
|
21
|
+
if (otherLines?.length) lines.push(...otherLines);
|
|
22
|
+
console.log((0, boxen.default)(lines.join("\n"), {
|
|
23
|
+
padding: 1,
|
|
24
|
+
borderStyle: "classic",
|
|
25
|
+
borderColor: "cyan"
|
|
26
|
+
}));
|
|
27
|
+
console.log("");
|
|
28
|
+
}
|
|
29
|
+
async function loadAIGNE({ path, modelOptions, imageModelOptions, skipModelLoading = false, metadata }) {
|
|
30
|
+
let aigne;
|
|
31
|
+
if (path) aigne = await _aigne_core.AIGNE.load(path, {
|
|
32
|
+
require: async (modulePath, options) => {
|
|
33
|
+
if (!options.parent || modulePath.startsWith("@aigne/")) return import(modulePath);
|
|
34
|
+
return (0, node_module.createRequire)(options.parent)(modulePath);
|
|
35
|
+
},
|
|
36
|
+
model: (options) => {
|
|
37
|
+
if (skipModelLoading) return void 0;
|
|
38
|
+
return require_utils_aigne_hub_model.loadChatModel({
|
|
39
|
+
...options,
|
|
40
|
+
...(0, _aigne_core_utils_type_utils.omitBy)(modelOptions ?? {}, (v) => (0, _aigne_core_utils_type_utils.isNil)(v)),
|
|
41
|
+
model: modelOptions?.model || process.env.MODEL || options?.model
|
|
42
|
+
});
|
|
43
|
+
},
|
|
44
|
+
imageModel: (options) => {
|
|
45
|
+
if (skipModelLoading) return void 0;
|
|
46
|
+
return require_utils_aigne_hub_model.loadImageModel({
|
|
47
|
+
...options,
|
|
48
|
+
...(0, _aigne_core_utils_type_utils.omitBy)(imageModelOptions ?? {}, (v) => (0, _aigne_core_utils_type_utils.isNil)(v)),
|
|
49
|
+
model: imageModelOptions?.model || process.env.IMAGE_MODEL || options?.model
|
|
50
|
+
});
|
|
51
|
+
},
|
|
52
|
+
afs: { availableModules: [{
|
|
53
|
+
module: "history",
|
|
54
|
+
load: (options) => import("@aigne/afs-history").then((m) => m.AFSHistory.load(options))
|
|
55
|
+
}, {
|
|
56
|
+
module: "local-fs",
|
|
57
|
+
alias: ["system-fs"],
|
|
58
|
+
load: (options) => import("@aigne/afs-local-fs").then((m) => m.LocalFS.load(options))
|
|
59
|
+
}] },
|
|
60
|
+
metadata: {
|
|
61
|
+
...metadata,
|
|
62
|
+
cliVersion: require_constants.AIGNE_CLI_VERSION
|
|
63
|
+
}
|
|
64
|
+
});
|
|
65
|
+
else aigne = new _aigne_core.AIGNE({
|
|
66
|
+
model: await require_utils_aigne_hub_model.loadChatModel({ ...modelOptions }),
|
|
67
|
+
metadata: {
|
|
68
|
+
...metadata,
|
|
69
|
+
cliVersion: require_constants.AIGNE_CLI_VERSION
|
|
70
|
+
}
|
|
71
|
+
});
|
|
72
|
+
return aigne;
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
//#endregion
|
|
76
|
+
exports.loadAIGNE = loadAIGNE;
|
|
77
|
+
exports.printChatModelInfoBox = printChatModelInfoBox;
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { LoadCredentialOptions } from "./aigne-hub/type.cjs";
|
|
2
|
+
import { AgentRunCommonOptions } from "./yargs.cjs";
|
|
3
|
+
import * as _aigne_core0 from "@aigne/core";
|
|
4
|
+
import { AIGNE, AIGNEMetadata, ChatModel, ChatModelInputOptions, ImageModelInputOptions } from "@aigne/core";
|
|
5
|
+
|
|
6
|
+
//#region src/utils/load-aigne.d.ts
|
|
7
|
+
interface RunOptions extends AgentRunCommonOptions {
|
|
8
|
+
path: string;
|
|
9
|
+
entryAgent?: string;
|
|
10
|
+
cacheDir?: string;
|
|
11
|
+
aigneHubUrl?: string;
|
|
12
|
+
}
|
|
13
|
+
declare function printChatModelInfoBox(model: ChatModel, otherLines?: string[]): Promise<void>;
|
|
14
|
+
declare function loadAIGNE({
|
|
15
|
+
path,
|
|
16
|
+
modelOptions,
|
|
17
|
+
imageModelOptions,
|
|
18
|
+
skipModelLoading,
|
|
19
|
+
metadata
|
|
20
|
+
}: {
|
|
21
|
+
path?: string;
|
|
22
|
+
modelOptions?: ChatModelInputOptions & LoadCredentialOptions;
|
|
23
|
+
imageModelOptions?: ImageModelInputOptions & LoadCredentialOptions;
|
|
24
|
+
skipModelLoading?: boolean;
|
|
25
|
+
metadata?: AIGNEMetadata;
|
|
26
|
+
}): Promise<AIGNE<_aigne_core0.UserContext>>;
|
|
27
|
+
//#endregion
|
|
28
|
+
export { RunOptions, loadAIGNE, printChatModelInfoBox };
|
|
29
|
+
//# sourceMappingURL=load-aigne.d.cts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"load-aigne.d.cts","names":[],"sources":["../../src/utils/load-aigne.ts"],"mappings":";;;;;;UAiBiB,UAAA,SAAmB,qBAAA;EAAA,IAAA;EAAA,UAAA;EAAA,QAAA;EAAA,WAAA;AAAA;AAAA,iBAOd,qBAAA,CAAA,KAAA,EAA6B,SAAA,EAAA,UAAA,cAAgC,OAAA;AAAA,iBA2B7D,SAAA,CAAA;EAAA,IAAA;EAAA,YAAA;EAAA,iBAAA;EAAA,gBAAA;EAAA;AAAA;EAAA,IAAA;EAAA,YAAA,GAQL,qBAAA,GAAwB,qBAAA;EAAA,iBAAA,GACnB,sBAAA,GAAyB,qBAAA;EAAA,gBAAA;EAAA,QAAA,GAElC,aAAA;AAAA,IACZ,OAAA,CAAA,KAAA,CADyB,YAAA,CACzB,WAAA"}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { LoadCredentialOptions } from "./aigne-hub/type.mjs";
|
|
2
|
+
import { AgentRunCommonOptions } from "./yargs.mjs";
|
|
3
|
+
import * as _aigne_core0 from "@aigne/core";
|
|
4
|
+
import { AIGNE, AIGNEMetadata, ChatModel, ChatModelInputOptions, ImageModelInputOptions } from "@aigne/core";
|
|
5
|
+
|
|
6
|
+
//#region src/utils/load-aigne.d.ts
|
|
7
|
+
interface RunOptions extends AgentRunCommonOptions {
|
|
8
|
+
path: string;
|
|
9
|
+
entryAgent?: string;
|
|
10
|
+
cacheDir?: string;
|
|
11
|
+
aigneHubUrl?: string;
|
|
12
|
+
}
|
|
13
|
+
declare function printChatModelInfoBox(model: ChatModel, otherLines?: string[]): Promise<void>;
|
|
14
|
+
declare function loadAIGNE({
|
|
15
|
+
path,
|
|
16
|
+
modelOptions,
|
|
17
|
+
imageModelOptions,
|
|
18
|
+
skipModelLoading,
|
|
19
|
+
metadata
|
|
20
|
+
}: {
|
|
21
|
+
path?: string;
|
|
22
|
+
modelOptions?: ChatModelInputOptions & LoadCredentialOptions;
|
|
23
|
+
imageModelOptions?: ImageModelInputOptions & LoadCredentialOptions;
|
|
24
|
+
skipModelLoading?: boolean;
|
|
25
|
+
metadata?: AIGNEMetadata;
|
|
26
|
+
}): Promise<AIGNE<_aigne_core0.UserContext>>;
|
|
27
|
+
//#endregion
|
|
28
|
+
export { RunOptions, loadAIGNE, printChatModelInfoBox };
|
|
29
|
+
//# sourceMappingURL=load-aigne.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"load-aigne.d.mts","names":[],"sources":["../../src/utils/load-aigne.ts"],"mappings":";;;;;;UAiBiB,UAAA,SAAmB,qBAAA;EAAA,IAAA;EAAA,UAAA;EAAA,QAAA;EAAA,WAAA;AAAA;AAAA,iBAOd,qBAAA,CAAA,KAAA,EAA6B,SAAA,EAAA,UAAA,cAAgC,OAAA;AAAA,iBA2B7D,SAAA,CAAA;EAAA,IAAA;EAAA,YAAA;EAAA,iBAAA;EAAA,gBAAA;EAAA;AAAA;EAAA,IAAA;EAAA,YAAA,GAQL,qBAAA,GAAwB,qBAAA;EAAA,iBAAA,GACnB,sBAAA,GAAyB,qBAAA;EAAA,gBAAA;EAAA,QAAA,GAElC,aAAA;AAAA,IACZ,OAAA,CAAA,KAAA,CADyB,YAAA,CACzB,WAAA"}
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
import { AIGNE_CLI_VERSION } from "../constants.mjs";
|
|
2
|
+
import { loadChatModel, loadImageModel, maskApiKey } from "./aigne-hub/model.mjs";
|
|
3
|
+
import { getUrlOrigin } from "./get-url-origin.mjs";
|
|
4
|
+
import { createRequire } from "node:module";
|
|
5
|
+
import chalk from "chalk";
|
|
6
|
+
import { AIGNE } from "@aigne/core";
|
|
7
|
+
import { isNil, omitBy } from "@aigne/core/utils/type-utils";
|
|
8
|
+
import boxen from "boxen";
|
|
9
|
+
|
|
10
|
+
//#region src/utils/load-aigne.ts
|
|
11
|
+
async function printChatModelInfoBox(model, otherLines) {
|
|
12
|
+
console.log(`${chalk.grey("TIPS:")} run ${chalk.cyan("aigne observe")} to start the observability server.\n`);
|
|
13
|
+
const credential = await model.credential;
|
|
14
|
+
const lines = [`${chalk.cyan("Provider")}: ${chalk.green(model.name.replace("ChatModel", ""))}`];
|
|
15
|
+
if (credential?.model) lines.push(`${chalk.cyan("Model")}: ${chalk.green(credential?.model)}`);
|
|
16
|
+
if (credential?.url) lines.push(`${chalk.cyan("API URL")}: ${chalk.green(getUrlOrigin(credential?.url) || "N/A")}`);
|
|
17
|
+
if (credential?.apiKey) lines.push(`${chalk.cyan("API Key")}: ${chalk.green(maskApiKey(credential?.apiKey))}`);
|
|
18
|
+
if (otherLines?.length) lines.push(...otherLines);
|
|
19
|
+
console.log(boxen(lines.join("\n"), {
|
|
20
|
+
padding: 1,
|
|
21
|
+
borderStyle: "classic",
|
|
22
|
+
borderColor: "cyan"
|
|
23
|
+
}));
|
|
24
|
+
console.log("");
|
|
25
|
+
}
|
|
26
|
+
async function loadAIGNE({ path, modelOptions, imageModelOptions, skipModelLoading = false, metadata }) {
|
|
27
|
+
let aigne;
|
|
28
|
+
if (path) aigne = await AIGNE.load(path, {
|
|
29
|
+
require: async (modulePath, options) => {
|
|
30
|
+
if (!options.parent || modulePath.startsWith("@aigne/")) return import(modulePath);
|
|
31
|
+
return createRequire(options.parent)(modulePath);
|
|
32
|
+
},
|
|
33
|
+
model: (options) => {
|
|
34
|
+
if (skipModelLoading) return void 0;
|
|
35
|
+
return loadChatModel({
|
|
36
|
+
...options,
|
|
37
|
+
...omitBy(modelOptions ?? {}, (v) => isNil(v)),
|
|
38
|
+
model: modelOptions?.model || process.env.MODEL || options?.model
|
|
39
|
+
});
|
|
40
|
+
},
|
|
41
|
+
imageModel: (options) => {
|
|
42
|
+
if (skipModelLoading) return void 0;
|
|
43
|
+
return loadImageModel({
|
|
44
|
+
...options,
|
|
45
|
+
...omitBy(imageModelOptions ?? {}, (v) => isNil(v)),
|
|
46
|
+
model: imageModelOptions?.model || process.env.IMAGE_MODEL || options?.model
|
|
47
|
+
});
|
|
48
|
+
},
|
|
49
|
+
afs: { availableModules: [{
|
|
50
|
+
module: "history",
|
|
51
|
+
load: (options) => import("@aigne/afs-history").then((m) => m.AFSHistory.load(options))
|
|
52
|
+
}, {
|
|
53
|
+
module: "local-fs",
|
|
54
|
+
alias: ["system-fs"],
|
|
55
|
+
load: (options) => import("@aigne/afs-local-fs").then((m) => m.LocalFS.load(options))
|
|
56
|
+
}] },
|
|
57
|
+
metadata: {
|
|
58
|
+
...metadata,
|
|
59
|
+
cliVersion: AIGNE_CLI_VERSION
|
|
60
|
+
}
|
|
61
|
+
});
|
|
62
|
+
else aigne = new AIGNE({
|
|
63
|
+
model: await loadChatModel({ ...modelOptions }),
|
|
64
|
+
metadata: {
|
|
65
|
+
...metadata,
|
|
66
|
+
cliVersion: AIGNE_CLI_VERSION
|
|
67
|
+
}
|
|
68
|
+
});
|
|
69
|
+
return aigne;
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
//#endregion
|
|
73
|
+
export { loadAIGNE, printChatModelInfoBox };
|
|
74
|
+
//# sourceMappingURL=load-aigne.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"load-aigne.mjs","names":[],"sources":["../../src/utils/load-aigne.ts"],"sourcesContent":["import { createRequire } from \"node:module\";\nimport {\n AIGNE,\n type AIGNEMetadata,\n type ChatModel,\n type ChatModelInputOptions,\n type ImageModelInputOptions,\n} from \"@aigne/core\";\nimport { isNil, omitBy } from \"@aigne/core/utils/type-utils\";\nimport boxen from \"boxen\";\nimport chalk from \"chalk\";\nimport { AIGNE_CLI_VERSION } from \"../constants.js\";\nimport { loadChatModel, loadImageModel, maskApiKey } from \"./aigne-hub/model.js\";\nimport type { LoadCredentialOptions } from \"./aigne-hub/type.js\";\nimport { getUrlOrigin } from \"./get-url-origin.js\";\nimport type { AgentRunCommonOptions } from \"./yargs.js\";\n\nexport interface RunOptions extends AgentRunCommonOptions {\n path: string;\n entryAgent?: string;\n cacheDir?: string;\n aigneHubUrl?: string;\n}\n\nexport async function printChatModelInfoBox(model: ChatModel, otherLines?: string[]) {\n console.log(\n `${chalk.grey(\"TIPS:\")} run ${chalk.cyan(\"aigne observe\")} to start the observability server.\\n`,\n );\n\n const credential = await model.credential;\n\n const lines = [`${chalk.cyan(\"Provider\")}: ${chalk.green(model.name.replace(\"ChatModel\", \"\"))}`];\n\n if (credential?.model) {\n lines.push(`${chalk.cyan(\"Model\")}: ${chalk.green(credential?.model)}`);\n }\n\n if (credential?.url) {\n lines.push(`${chalk.cyan(\"API URL\")}: ${chalk.green(getUrlOrigin(credential?.url) || \"N/A\")}`);\n }\n\n if (credential?.apiKey) {\n lines.push(`${chalk.cyan(\"API Key\")}: ${chalk.green(maskApiKey(credential?.apiKey))}`);\n }\n\n if (otherLines?.length) lines.push(...otherLines);\n\n console.log(boxen(lines.join(\"\\n\"), { padding: 1, borderStyle: \"classic\", borderColor: \"cyan\" }));\n console.log(\"\");\n}\n\nexport async function loadAIGNE({\n path,\n modelOptions,\n imageModelOptions,\n skipModelLoading = false,\n metadata,\n}: {\n path?: string;\n modelOptions?: ChatModelInputOptions & LoadCredentialOptions;\n imageModelOptions?: ImageModelInputOptions & LoadCredentialOptions;\n skipModelLoading?: boolean;\n metadata?: AIGNEMetadata;\n}) {\n let aigne: AIGNE;\n\n if (path) {\n aigne = await AIGNE.load(path, {\n require: async (modulePath: string, options: { parent?: string }) => {\n if (!options.parent || modulePath.startsWith(\"@aigne/\")) return import(modulePath);\n\n const require = createRequire(options.parent);\n return require(modulePath);\n },\n model: (options) => {\n if (skipModelLoading) return undefined;\n return loadChatModel({\n ...options,\n ...omitBy(modelOptions ?? {}, (v) => isNil(v)),\n model: modelOptions?.model || process.env.MODEL || options?.model,\n });\n },\n imageModel: (options) => {\n if (skipModelLoading) return undefined;\n return loadImageModel({\n ...options,\n ...omitBy(imageModelOptions ?? {}, (v) => isNil(v)),\n model: imageModelOptions?.model || process.env.IMAGE_MODEL || options?.model,\n });\n },\n afs: {\n availableModules: [\n {\n module: \"history\",\n load: (options) => import(\"@aigne/afs-history\").then((m) => m.AFSHistory.load(options)),\n },\n {\n module: \"local-fs\",\n alias: [\"system-fs\"],\n load: (options) => import(\"@aigne/afs-local-fs\").then((m) => m.LocalFS.load(options)),\n },\n ],\n },\n metadata: { ...metadata, cliVersion: AIGNE_CLI_VERSION },\n });\n } else {\n const chatModel = await loadChatModel({ ...modelOptions });\n aigne = new AIGNE({\n model: chatModel,\n metadata: { ...metadata, cliVersion: AIGNE_CLI_VERSION },\n });\n }\n\n return aigne;\n}\n"],"mappings":";;;;;;;;;;AAwBA,eAAsB,sBAAsB,OAAkB,YAAuB;AACnF,SAAQ,IACN,GAAG,MAAM,KAAK,QAAQ,CAAC,OAAO,MAAM,KAAK,gBAAgB,CAAC,uCAC3D;CAED,MAAM,aAAa,MAAM,MAAM;CAE/B,MAAM,QAAQ,CAAC,GAAG,MAAM,KAAK,WAAW,CAAC,IAAI,MAAM,MAAM,MAAM,KAAK,QAAQ,aAAa,GAAG,CAAC,GAAG;AAEhG,KAAI,YAAY,MACd,OAAM,KAAK,GAAG,MAAM,KAAK,QAAQ,CAAC,IAAI,MAAM,MAAM,YAAY,MAAM,GAAG;AAGzE,KAAI,YAAY,IACd,OAAM,KAAK,GAAG,MAAM,KAAK,UAAU,CAAC,IAAI,MAAM,MAAM,aAAa,YAAY,IAAI,IAAI,MAAM,GAAG;AAGhG,KAAI,YAAY,OACd,OAAM,KAAK,GAAG,MAAM,KAAK,UAAU,CAAC,IAAI,MAAM,MAAM,WAAW,YAAY,OAAO,CAAC,GAAG;AAGxF,KAAI,YAAY,OAAQ,OAAM,KAAK,GAAG,WAAW;AAEjD,SAAQ,IAAI,MAAM,MAAM,KAAK,KAAK,EAAE;EAAE,SAAS;EAAG,aAAa;EAAW,aAAa;EAAQ,CAAC,CAAC;AACjG,SAAQ,IAAI,GAAG;;AAGjB,eAAsB,UAAU,EAC9B,MACA,cACA,mBACA,mBAAmB,OACnB,YAOC;CACD,IAAI;AAEJ,KAAI,KACF,SAAQ,MAAM,MAAM,KAAK,MAAM;EAC7B,SAAS,OAAO,YAAoB,YAAiC;AACnE,OAAI,CAAC,QAAQ,UAAU,WAAW,WAAW,UAAU,CAAE,QAAO,OAAO;AAGvE,UADgB,cAAc,QAAQ,OAAO,CAC9B,WAAW;;EAE5B,QAAQ,YAAY;AAClB,OAAI,iBAAkB,QAAO;AAC7B,UAAO,cAAc;IACnB,GAAG;IACH,GAAG,OAAO,gBAAgB,EAAE,GAAG,MAAM,MAAM,EAAE,CAAC;IAC9C,OAAO,cAAc,SAAS,QAAQ,IAAI,SAAS,SAAS;IAC7D,CAAC;;EAEJ,aAAa,YAAY;AACvB,OAAI,iBAAkB,QAAO;AAC7B,UAAO,eAAe;IACpB,GAAG;IACH,GAAG,OAAO,qBAAqB,EAAE,GAAG,MAAM,MAAM,EAAE,CAAC;IACnD,OAAO,mBAAmB,SAAS,QAAQ,IAAI,eAAe,SAAS;IACxE,CAAC;;EAEJ,KAAK,EACH,kBAAkB,CAChB;GACE,QAAQ;GACR,OAAO,YAAY,OAAO,sBAAsB,MAAM,MAAM,EAAE,WAAW,KAAK,QAAQ,CAAC;GACxF,EACD;GACE,QAAQ;GACR,OAAO,CAAC,YAAY;GACpB,OAAO,YAAY,OAAO,uBAAuB,MAAM,MAAM,EAAE,QAAQ,KAAK,QAAQ,CAAC;GACtF,CACF,EACF;EACD,UAAU;GAAE,GAAG;GAAU,YAAY;GAAmB;EACzD,CAAC;KAGF,SAAQ,IAAI,MAAM;EAChB,OAFgB,MAAM,cAAc,EAAE,GAAG,cAAc,CAAC;EAGxD,UAAU;GAAE,GAAG;GAAU,YAAY;GAAmB;EACzD,CAAC;AAGJ,QAAO"}
|
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
const require_rolldown_runtime = require('../_virtual/rolldown_runtime.cjs');
|
|
2
|
+
const require_terminal_input = require('../ui/utils/terminal-input.cjs');
|
|
3
|
+
const require_terminal = require('../tracer/terminal.cjs');
|
|
4
|
+
let node_path = require("node:path");
|
|
5
|
+
let node_fs_promises = require("node:fs/promises");
|
|
6
|
+
let _aigne_core = require("@aigne/core");
|
|
7
|
+
let _aigne_core_utils_type_utils = require("@aigne/core/utils/type-utils");
|
|
8
|
+
|
|
9
|
+
//#region src/utils/run-chat-loop.ts
|
|
10
|
+
const DEFAULT_CHAT_INPUT_KEY = "message";
|
|
11
|
+
async function runChatLoopInTerminal(userAgent, options = {}) {
|
|
12
|
+
const { initialCall } = options;
|
|
13
|
+
if (initialCall) {
|
|
14
|
+
await callAgent(userAgent, initialCall, options);
|
|
15
|
+
if (options.input && options.inputFileKey) options.input = (0, _aigne_core_utils_type_utils.omit)(options.input, options.inputFileKey);
|
|
16
|
+
}
|
|
17
|
+
for (let i = 0;; i++) {
|
|
18
|
+
const question = await require_terminal_input.terminalInput({
|
|
19
|
+
message: "💬",
|
|
20
|
+
default: i === 0 ? options?.defaultQuestion : void 0,
|
|
21
|
+
clear: true
|
|
22
|
+
});
|
|
23
|
+
if (!question?.trim()) continue;
|
|
24
|
+
const cmd = COMMANDS[question.trim()];
|
|
25
|
+
if (cmd) {
|
|
26
|
+
const result = cmd();
|
|
27
|
+
if (result.message) console.log(result.message);
|
|
28
|
+
if (result?.exit) break;
|
|
29
|
+
continue;
|
|
30
|
+
}
|
|
31
|
+
const input = {};
|
|
32
|
+
if (options.inputFileKey) {
|
|
33
|
+
const { message, files } = await extractFilesFromQuestion(question);
|
|
34
|
+
input[options.inputKey || DEFAULT_CHAT_INPUT_KEY] = message;
|
|
35
|
+
input[options.inputFileKey] = files;
|
|
36
|
+
} else input[options.inputKey || DEFAULT_CHAT_INPUT_KEY] = question;
|
|
37
|
+
await callAgent(userAgent, input, options);
|
|
38
|
+
if (options.input && options.inputFileKey) options.input = (0, _aigne_core_utils_type_utils.omit)(options.input, options.inputFileKey);
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
async function extractFilesFromQuestion(question) {
|
|
42
|
+
const paths = question.match(/@\S+/g) || [];
|
|
43
|
+
const files = (await Promise.all(paths.map(async (path) => {
|
|
44
|
+
const p = path.slice(1);
|
|
45
|
+
const filename = (0, node_path.basename)(p);
|
|
46
|
+
const data = await (0, node_fs_promises.readFile)(p, "base64").catch((error) => {
|
|
47
|
+
if (error.code === "ENOENT") return null;
|
|
48
|
+
throw error;
|
|
49
|
+
});
|
|
50
|
+
if (!data) return;
|
|
51
|
+
return {
|
|
52
|
+
path,
|
|
53
|
+
file: {
|
|
54
|
+
type: "file",
|
|
55
|
+
data,
|
|
56
|
+
filename,
|
|
57
|
+
mimeType: await _aigne_core.ChatModel.getMimeType(filename)
|
|
58
|
+
}
|
|
59
|
+
};
|
|
60
|
+
}))).filter(_aigne_core_utils_type_utils.isNonNullable);
|
|
61
|
+
for (const { path } of files) question = question.replaceAll(path, "");
|
|
62
|
+
return {
|
|
63
|
+
message: question,
|
|
64
|
+
files: files.map((i) => i.file)
|
|
65
|
+
};
|
|
66
|
+
}
|
|
67
|
+
async function callAgent(userAgent, input, options) {
|
|
68
|
+
await new require_terminal.TerminalTracer(userAgent.context, options).run(userAgent, typeof input === "string" ? {
|
|
69
|
+
...options.input,
|
|
70
|
+
[options.inputKey || DEFAULT_CHAT_INPUT_KEY]: input
|
|
71
|
+
} : {
|
|
72
|
+
...options.input,
|
|
73
|
+
...input
|
|
74
|
+
}, { userContext: {
|
|
75
|
+
sessionId: options.sessionId,
|
|
76
|
+
userId: options.userId
|
|
77
|
+
} });
|
|
78
|
+
}
|
|
79
|
+
const COMMANDS = {
|
|
80
|
+
"/exit": () => ({ exit: true }),
|
|
81
|
+
"/help": () => ({ message: `\
|
|
82
|
+
Commands:
|
|
83
|
+
/exit - exit the chat loop
|
|
84
|
+
/help - show this help message
|
|
85
|
+
` })
|
|
86
|
+
};
|
|
87
|
+
|
|
88
|
+
//#endregion
|
|
89
|
+
exports.DEFAULT_CHAT_INPUT_KEY = DEFAULT_CHAT_INPUT_KEY;
|
|
90
|
+
exports.runChatLoopInTerminal = runChatLoopInTerminal;
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { Message, UserAgent } from "@aigne/core";
|
|
2
|
+
|
|
3
|
+
//#region src/utils/run-chat-loop.d.ts
|
|
4
|
+
declare const DEFAULT_CHAT_INPUT_KEY = "message";
|
|
5
|
+
interface ChatLoopOptions {
|
|
6
|
+
userId?: string;
|
|
7
|
+
sessionId?: string;
|
|
8
|
+
initialCall?: Message | string;
|
|
9
|
+
welcome?: string;
|
|
10
|
+
defaultQuestion?: string;
|
|
11
|
+
inputKey?: string;
|
|
12
|
+
inputFileKey?: string;
|
|
13
|
+
outputKey?: string;
|
|
14
|
+
dataOutputKey?: string;
|
|
15
|
+
input?: Message;
|
|
16
|
+
}
|
|
17
|
+
declare function runChatLoopInTerminal(userAgent: UserAgent<any, any>, options?: ChatLoopOptions): Promise<void>;
|
|
18
|
+
//#endregion
|
|
19
|
+
export { ChatLoopOptions, DEFAULT_CHAT_INPUT_KEY, runChatLoopInTerminal };
|
|
20
|
+
//# sourceMappingURL=run-chat-loop.d.cts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"run-chat-loop.d.cts","names":[],"sources":["../../src/utils/run-chat-loop.ts"],"mappings":";;;cAOa,sBAAA;AAAA,UAEI,eAAA;EAAA,MAAA;EAAA,SAAA;EAAA,WAAA,GAGD,OAAA;EAAA,OAAA;EAAA,eAAA;EAAA,QAAA;EAAA,YAAA;EAAA,SAAA;EAAA,aAAA;EAAA,KAAA,GAON,OAAA;AAAA;AAAA,iBAGY,qBAAA,CAAA,SAAA,EACT,SAAA,YAAA,OAAA,GACF,eAAA,GAAoB,OAAA"}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { Message, UserAgent } from "@aigne/core";
|
|
2
|
+
|
|
3
|
+
//#region src/utils/run-chat-loop.d.ts
|
|
4
|
+
declare const DEFAULT_CHAT_INPUT_KEY = "message";
|
|
5
|
+
interface ChatLoopOptions {
|
|
6
|
+
userId?: string;
|
|
7
|
+
sessionId?: string;
|
|
8
|
+
initialCall?: Message | string;
|
|
9
|
+
welcome?: string;
|
|
10
|
+
defaultQuestion?: string;
|
|
11
|
+
inputKey?: string;
|
|
12
|
+
inputFileKey?: string;
|
|
13
|
+
outputKey?: string;
|
|
14
|
+
dataOutputKey?: string;
|
|
15
|
+
input?: Message;
|
|
16
|
+
}
|
|
17
|
+
declare function runChatLoopInTerminal(userAgent: UserAgent<any, any>, options?: ChatLoopOptions): Promise<void>;
|
|
18
|
+
//#endregion
|
|
19
|
+
export { ChatLoopOptions, DEFAULT_CHAT_INPUT_KEY, runChatLoopInTerminal };
|
|
20
|
+
//# sourceMappingURL=run-chat-loop.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"run-chat-loop.d.mts","names":[],"sources":["../../src/utils/run-chat-loop.ts"],"mappings":";;;cAOa,sBAAA;AAAA,UAEI,eAAA;EAAA,MAAA;EAAA,SAAA;EAAA,WAAA,GAGD,OAAA;EAAA,OAAA;EAAA,eAAA;EAAA,QAAA;EAAA,YAAA;EAAA,SAAA;EAAA,aAAA;EAAA,KAAA,GAON,OAAA;AAAA;AAAA,iBAGY,qBAAA,CAAA,SAAA,EACT,SAAA,YAAA,OAAA,GACF,eAAA,GAAoB,OAAA"}
|
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
import { terminalInput } from "../ui/utils/terminal-input.mjs";
|
|
2
|
+
import { TerminalTracer } from "../tracer/terminal.mjs";
|
|
3
|
+
import { basename } from "node:path";
|
|
4
|
+
import { readFile } from "node:fs/promises";
|
|
5
|
+
import { ChatModel } from "@aigne/core";
|
|
6
|
+
import { isNonNullable, omit } from "@aigne/core/utils/type-utils";
|
|
7
|
+
|
|
8
|
+
//#region src/utils/run-chat-loop.ts
|
|
9
|
+
const DEFAULT_CHAT_INPUT_KEY = "message";
|
|
10
|
+
async function runChatLoopInTerminal(userAgent, options = {}) {
|
|
11
|
+
const { initialCall } = options;
|
|
12
|
+
if (initialCall) {
|
|
13
|
+
await callAgent(userAgent, initialCall, options);
|
|
14
|
+
if (options.input && options.inputFileKey) options.input = omit(options.input, options.inputFileKey);
|
|
15
|
+
}
|
|
16
|
+
for (let i = 0;; i++) {
|
|
17
|
+
const question = await terminalInput({
|
|
18
|
+
message: "💬",
|
|
19
|
+
default: i === 0 ? options?.defaultQuestion : void 0,
|
|
20
|
+
clear: true
|
|
21
|
+
});
|
|
22
|
+
if (!question?.trim()) continue;
|
|
23
|
+
const cmd = COMMANDS[question.trim()];
|
|
24
|
+
if (cmd) {
|
|
25
|
+
const result = cmd();
|
|
26
|
+
if (result.message) console.log(result.message);
|
|
27
|
+
if (result?.exit) break;
|
|
28
|
+
continue;
|
|
29
|
+
}
|
|
30
|
+
const input = {};
|
|
31
|
+
if (options.inputFileKey) {
|
|
32
|
+
const { message, files } = await extractFilesFromQuestion(question);
|
|
33
|
+
input[options.inputKey || DEFAULT_CHAT_INPUT_KEY] = message;
|
|
34
|
+
input[options.inputFileKey] = files;
|
|
35
|
+
} else input[options.inputKey || DEFAULT_CHAT_INPUT_KEY] = question;
|
|
36
|
+
await callAgent(userAgent, input, options);
|
|
37
|
+
if (options.input && options.inputFileKey) options.input = omit(options.input, options.inputFileKey);
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
async function extractFilesFromQuestion(question) {
|
|
41
|
+
const paths = question.match(/@\S+/g) || [];
|
|
42
|
+
const files = (await Promise.all(paths.map(async (path$1) => {
|
|
43
|
+
const p = path$1.slice(1);
|
|
44
|
+
const filename = basename(p);
|
|
45
|
+
const data = await readFile(p, "base64").catch((error) => {
|
|
46
|
+
if (error.code === "ENOENT") return null;
|
|
47
|
+
throw error;
|
|
48
|
+
});
|
|
49
|
+
if (!data) return;
|
|
50
|
+
return {
|
|
51
|
+
path: path$1,
|
|
52
|
+
file: {
|
|
53
|
+
type: "file",
|
|
54
|
+
data,
|
|
55
|
+
filename,
|
|
56
|
+
mimeType: await ChatModel.getMimeType(filename)
|
|
57
|
+
}
|
|
58
|
+
};
|
|
59
|
+
}))).filter(isNonNullable);
|
|
60
|
+
for (const { path: path$1 } of files) question = question.replaceAll(path$1, "");
|
|
61
|
+
return {
|
|
62
|
+
message: question,
|
|
63
|
+
files: files.map((i) => i.file)
|
|
64
|
+
};
|
|
65
|
+
}
|
|
66
|
+
async function callAgent(userAgent, input, options) {
|
|
67
|
+
await new TerminalTracer(userAgent.context, options).run(userAgent, typeof input === "string" ? {
|
|
68
|
+
...options.input,
|
|
69
|
+
[options.inputKey || DEFAULT_CHAT_INPUT_KEY]: input
|
|
70
|
+
} : {
|
|
71
|
+
...options.input,
|
|
72
|
+
...input
|
|
73
|
+
}, { userContext: {
|
|
74
|
+
sessionId: options.sessionId,
|
|
75
|
+
userId: options.userId
|
|
76
|
+
} });
|
|
77
|
+
}
|
|
78
|
+
const COMMANDS = {
|
|
79
|
+
"/exit": () => ({ exit: true }),
|
|
80
|
+
"/help": () => ({ message: `\
|
|
81
|
+
Commands:
|
|
82
|
+
/exit - exit the chat loop
|
|
83
|
+
/help - show this help message
|
|
84
|
+
` })
|
|
85
|
+
};
|
|
86
|
+
|
|
87
|
+
//#endregion
|
|
88
|
+
export { DEFAULT_CHAT_INPUT_KEY, runChatLoopInTerminal };
|
|
89
|
+
//# sourceMappingURL=run-chat-loop.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"run-chat-loop.mjs","names":["path"],"sources":["../../src/utils/run-chat-loop.ts"],"sourcesContent":["import { readFile } from \"node:fs/promises\";\nimport { basename } from \"node:path\";\nimport { ChatModel, type FileUnionContent, type Message, type UserAgent } from \"@aigne/core\";\nimport { isNonNullable, omit } from \"@aigne/core/utils/type-utils\";\nimport { TerminalTracer } from \"../tracer/terminal.js\";\nimport { terminalInput } from \"../ui/utils/terminal-input.js\";\n\nexport const DEFAULT_CHAT_INPUT_KEY = \"message\";\n\nexport interface ChatLoopOptions {\n userId?: string;\n sessionId?: string;\n initialCall?: Message | string;\n welcome?: string;\n defaultQuestion?: string;\n inputKey?: string;\n inputFileKey?: string;\n outputKey?: string;\n dataOutputKey?: string;\n input?: Message;\n}\n\nexport async function runChatLoopInTerminal(\n userAgent: UserAgent<any, any>,\n options: ChatLoopOptions = {},\n) {\n const { initialCall } = options;\n\n if (initialCall) {\n await callAgent(userAgent, initialCall, options);\n if (options.input && options.inputFileKey) {\n options.input = omit(options.input, options.inputFileKey);\n }\n }\n\n for (let i = 0; ; i++) {\n const question = await terminalInput({\n message: \"💬\",\n default: i === 0 ? options?.defaultQuestion : undefined,\n clear: true,\n });\n\n if (!question?.trim()) continue;\n\n const cmd = COMMANDS[question.trim()];\n if (cmd) {\n const result = cmd();\n if (result.message) console.log(result.message);\n if (result?.exit) break;\n continue;\n }\n\n const input: Message = {};\n\n if (options.inputFileKey) {\n const { message, files } = await extractFilesFromQuestion(question);\n input[options.inputKey || DEFAULT_CHAT_INPUT_KEY] = message;\n input[options.inputFileKey] = files;\n } else {\n input[options.inputKey || DEFAULT_CHAT_INPUT_KEY] = question;\n }\n\n await callAgent(userAgent, input, options);\n\n if (options.input && options.inputFileKey) {\n options.input = omit(options.input, options.inputFileKey);\n }\n }\n}\n\nasync function extractFilesFromQuestion(\n question: string,\n): Promise<{ message: string; files: FileUnionContent[] }> {\n const fileRegex = /@\\S+/g;\n const paths = question.match(fileRegex) || [];\n\n const files = (\n await Promise.all(\n paths.map<Promise<{ path: string; file: FileUnionContent } | undefined>>(async (path) => {\n const p = path.slice(1);\n const filename = basename(p);\n\n const data = await readFile(p, \"base64\").catch((error) => {\n if (error.code === \"ENOENT\") return null;\n throw error;\n });\n if (!data) return;\n\n return {\n path,\n file: { type: \"file\", data, filename, mimeType: await ChatModel.getMimeType(filename) },\n };\n }),\n )\n ).filter(isNonNullable);\n\n // Remove file paths from question\n for (const { path } of files) {\n question = question.replaceAll(path, \"\");\n }\n\n return { message: question, files: files.map((i) => i.file) };\n}\n\nasync function callAgent(userAgent: UserAgent, input: Message | string, options: ChatLoopOptions) {\n const tracer = new TerminalTracer(userAgent.context, options);\n\n await tracer.run(\n userAgent,\n typeof input === \"string\"\n ? { ...options.input, [options.inputKey || DEFAULT_CHAT_INPUT_KEY]: input }\n : { ...options.input, ...input },\n { userContext: { sessionId: options.sessionId, userId: options.userId } },\n );\n}\n\nconst COMMANDS: { [key: string]: () => { exit?: boolean; message?: string } } = {\n \"/exit\": () => ({ exit: true }),\n \"/help\": () => ({\n message: `\\\nCommands:\n /exit - exit the chat loop\n /help - show this help message\n`,\n }),\n};\n"],"mappings":";;;;;;;;AAOA,MAAa,yBAAyB;AAetC,eAAsB,sBACpB,WACA,UAA2B,EAAE,EAC7B;CACA,MAAM,EAAE,gBAAgB;AAExB,KAAI,aAAa;AACf,QAAM,UAAU,WAAW,aAAa,QAAQ;AAChD,MAAI,QAAQ,SAAS,QAAQ,aAC3B,SAAQ,QAAQ,KAAK,QAAQ,OAAO,QAAQ,aAAa;;AAI7D,MAAK,IAAI,IAAI,IAAK,KAAK;EACrB,MAAM,WAAW,MAAM,cAAc;GACnC,SAAS;GACT,SAAS,MAAM,IAAI,SAAS,kBAAkB;GAC9C,OAAO;GACR,CAAC;AAEF,MAAI,CAAC,UAAU,MAAM,CAAE;EAEvB,MAAM,MAAM,SAAS,SAAS,MAAM;AACpC,MAAI,KAAK;GACP,MAAM,SAAS,KAAK;AACpB,OAAI,OAAO,QAAS,SAAQ,IAAI,OAAO,QAAQ;AAC/C,OAAI,QAAQ,KAAM;AAClB;;EAGF,MAAM,QAAiB,EAAE;AAEzB,MAAI,QAAQ,cAAc;GACxB,MAAM,EAAE,SAAS,UAAU,MAAM,yBAAyB,SAAS;AACnE,SAAM,QAAQ,YAAY,0BAA0B;AACpD,SAAM,QAAQ,gBAAgB;QAE9B,OAAM,QAAQ,YAAY,0BAA0B;AAGtD,QAAM,UAAU,WAAW,OAAO,QAAQ;AAE1C,MAAI,QAAQ,SAAS,QAAQ,aAC3B,SAAQ,QAAQ,KAAK,QAAQ,OAAO,QAAQ,aAAa;;;AAK/D,eAAe,yBACb,UACyD;CAEzD,MAAM,QAAQ,SAAS,MADL,QACqB,IAAI,EAAE;CAE7C,MAAM,SACJ,MAAM,QAAQ,IACZ,MAAM,IAAmE,OAAO,WAAS;EACvF,MAAM,IAAIA,OAAK,MAAM,EAAE;EACvB,MAAM,WAAW,SAAS,EAAE;EAE5B,MAAM,OAAO,MAAM,SAAS,GAAG,SAAS,CAAC,OAAO,UAAU;AACxD,OAAI,MAAM,SAAS,SAAU,QAAO;AACpC,SAAM;IACN;AACF,MAAI,CAAC,KAAM;AAEX,SAAO;GACL;GACA,MAAM;IAAE,MAAM;IAAQ;IAAM;IAAU,UAAU,MAAM,UAAU,YAAY,SAAS;IAAE;GACxF;GACD,CACH,EACD,OAAO,cAAc;AAGvB,MAAK,MAAM,EAAE,kBAAU,MACrB,YAAW,SAAS,WAAWA,QAAM,GAAG;AAG1C,QAAO;EAAE,SAAS;EAAU,OAAO,MAAM,KAAK,MAAM,EAAE,KAAK;EAAE;;AAG/D,eAAe,UAAU,WAAsB,OAAyB,SAA0B;AAGhG,OAFe,IAAI,eAAe,UAAU,SAAS,QAAQ,CAEhD,IACX,WACA,OAAO,UAAU,WACb;EAAE,GAAG,QAAQ;GAAQ,QAAQ,YAAY,yBAAyB;EAAO,GACzE;EAAE,GAAG,QAAQ;EAAO,GAAG;EAAO,EAClC,EAAE,aAAa;EAAE,WAAW,QAAQ;EAAW,QAAQ,QAAQ;EAAQ,EAAE,CAC1E;;AAGH,MAAM,WAA0E;CAC9E,gBAAgB,EAAE,MAAM,MAAM;CAC9B,gBAAgB,EACd,SAAS;;;;GAKV;CACF"}
|
|
@@ -0,0 +1,131 @@
|
|
|
1
|
+
const require_rolldown_runtime = require('../_virtual/rolldown_runtime.cjs');
|
|
2
|
+
const require_constants = require('../constants.cjs');
|
|
3
|
+
const require_utils_load_aigne = require('./load-aigne.cjs');
|
|
4
|
+
const require_utils_yargs = require('./yargs.cjs');
|
|
5
|
+
const require_terminal = require('../tracer/terminal.cjs');
|
|
6
|
+
const require_utils_run_chat_loop = require('./run-chat-loop.cjs');
|
|
7
|
+
let _aigne_core_utils_logger = require("@aigne/core/utils/logger");
|
|
8
|
+
let chalk = require("chalk");
|
|
9
|
+
chalk = require_rolldown_runtime.__toESM(chalk);
|
|
10
|
+
let yargs = require("yargs");
|
|
11
|
+
yargs = require_rolldown_runtime.__toESM(yargs);
|
|
12
|
+
let node_path = require("node:path");
|
|
13
|
+
let node_url = require("node:url");
|
|
14
|
+
let node_fs_promises = require("node:fs/promises");
|
|
15
|
+
let _aigne_core = require("@aigne/core");
|
|
16
|
+
let _aigne_core_utils_type_utils = require("@aigne/core/utils/type-utils");
|
|
17
|
+
let _aigne_agent_library_utils_fs = require("@aigne/agent-library/utils/fs");
|
|
18
|
+
let detect_port = require("detect-port");
|
|
19
|
+
let node_tty = require("node:tty");
|
|
20
|
+
let _aigne_uuid = require("@aigne/uuid");
|
|
21
|
+
let _aigne_afs_explorer = require("@aigne/afs-explorer");
|
|
22
|
+
let yargs_helpers = require("yargs/helpers");
|
|
23
|
+
|
|
24
|
+
//#region src/utils/run-with-aigne.ts
|
|
25
|
+
async function parseAgentInputByCommander(agent, options = {}) {
|
|
26
|
+
const args = await require_utils_yargs.withAgentInputSchema((0, yargs.default)(), agent).showHelpOnFail(false).fail(() => {}).parseAsync(options.argv ?? process.argv);
|
|
27
|
+
const input = await require_utils_yargs.parseAgentInput({
|
|
28
|
+
...args,
|
|
29
|
+
input: options.input || args.input
|
|
30
|
+
}, agent);
|
|
31
|
+
if ((0, _aigne_core_utils_type_utils.isEmpty)(input)) {
|
|
32
|
+
const defaultInput = options.defaultInput || process.env.INITIAL_CALL;
|
|
33
|
+
Object.assign(input, typeof defaultInput === "string" ? { [options?.inputKey || (agent instanceof _aigne_core.AIAgent ? agent.inputKey : void 0) || require_utils_run_chat_loop.DEFAULT_CHAT_INPUT_KEY]: defaultInput } : defaultInput);
|
|
34
|
+
}
|
|
35
|
+
return input;
|
|
36
|
+
}
|
|
37
|
+
async function loadAIGNEWithCmdOptions() {
|
|
38
|
+
return await require_utils_load_aigne.loadAIGNE({ modelOptions: { ...(0, _aigne_core_utils_type_utils.omitBy)((0, _aigne_core_utils_type_utils.pick)(await require_utils_yargs.withRunAgentCommonOptions((0, yargs.default)()).strict(false).parseAsync((0, yargs_helpers.hideBin)(process.argv)), "model", "temperature", "topP", "presencePenalty", "frequencyPenalty"), (v) => (0, _aigne_core_utils_type_utils.isNil)(v)) } });
|
|
39
|
+
}
|
|
40
|
+
async function runWithAIGNE(agentCreator, { aigne, argv = process.argv, chatLoopOptions, modelOptions, outputKey } = {}) {
|
|
41
|
+
await (0, yargs.default)().command("$0", "Execute an AI agent using the AIGNE framework with specified configuration", (yargs$2) => require_utils_yargs.withRunAgentCommonOptions(yargs$2), async (options) => {
|
|
42
|
+
if (options.logLevel) _aigne_core_utils_logger.logger.level = options.logLevel;
|
|
43
|
+
aigne ??= await require_utils_load_aigne.loadAIGNE({ modelOptions: {
|
|
44
|
+
...modelOptions,
|
|
45
|
+
...(0, _aigne_core_utils_type_utils.omitBy)((0, _aigne_core_utils_type_utils.pick)(options, "model", "temperature", "topP", "presencePenalty", "frequencyPenalty"), (v) => (0, _aigne_core_utils_type_utils.isNil)(v))
|
|
46
|
+
} });
|
|
47
|
+
let explorerServer;
|
|
48
|
+
let explorerServerURL;
|
|
49
|
+
try {
|
|
50
|
+
const agent = typeof agentCreator === "function" ? await agentCreator(aigne) : agentCreator;
|
|
51
|
+
const input = await parseAgentInputByCommander(agent, {
|
|
52
|
+
...options,
|
|
53
|
+
inputKey: chatLoopOptions?.inputKey,
|
|
54
|
+
defaultInput: chatLoopOptions?.initialCall || chatLoopOptions?.defaultQuestion
|
|
55
|
+
});
|
|
56
|
+
if (agent.afs) {
|
|
57
|
+
const port = await (0, detect_port.detect)(require_constants.DEFAULT_AFS_EXPLORER_PORT);
|
|
58
|
+
explorerServer = await (0, _aigne_afs_explorer.startExplorer)(agent.afs, {
|
|
59
|
+
port,
|
|
60
|
+
distPath: (0, node_path.dirname)((0, node_url.fileURLToPath)({}.resolve("@aigne/afs-explorer/index.html")))
|
|
61
|
+
});
|
|
62
|
+
explorerServerURL = `http://localhost:${port}`;
|
|
63
|
+
}
|
|
64
|
+
if (aigne.model) {
|
|
65
|
+
const lines = [];
|
|
66
|
+
if (explorerServerURL) lines.push(`${chalk.default.cyan("AFS Explorer")}: ${chalk.default.green(explorerServerURL)}`);
|
|
67
|
+
await require_utils_load_aigne.printChatModelInfoBox(aigne.model, lines);
|
|
68
|
+
}
|
|
69
|
+
if (chatLoopOptions?.welcome) console.log(chatLoopOptions.welcome);
|
|
70
|
+
await runAgentWithAIGNE(aigne, agent, {
|
|
71
|
+
...options,
|
|
72
|
+
outputKey: outputKey || options.outputKey,
|
|
73
|
+
chatLoopOptions,
|
|
74
|
+
input,
|
|
75
|
+
sessionId: chatLoopOptions?.sessionId || (0, _aigne_uuid.v7)(),
|
|
76
|
+
userId: require_constants.DEFAULT_USER_ID
|
|
77
|
+
});
|
|
78
|
+
} finally {
|
|
79
|
+
await explorerServer?.stop();
|
|
80
|
+
await aigne.shutdown();
|
|
81
|
+
}
|
|
82
|
+
}).alias("h", "help").alias("v", "version").fail((message, error, yargs$2) => {
|
|
83
|
+
if (!error) yargs$2.showHelp();
|
|
84
|
+
console.error(`\n${message || error?.message}`);
|
|
85
|
+
process.exit(1);
|
|
86
|
+
}).parseAsync((0, yargs_helpers.hideBin)(argv)).catch((error) => {
|
|
87
|
+
console.error(`${chalk.default.red("Error:")} ${error.message}`);
|
|
88
|
+
process.exit(1);
|
|
89
|
+
});
|
|
90
|
+
}
|
|
91
|
+
async function runAgentWithAIGNE(aigne, agent, { userId, sessionId, outputKey, outputFileKey, chatLoopOptions, ...options } = {}) {
|
|
92
|
+
if (options.output) {
|
|
93
|
+
const outputPath = (0, node_path.isAbsolute)(options.output) ? options.output : (0, node_path.join)(process.cwd(), options.output);
|
|
94
|
+
if (await (0, _aigne_agent_library_utils_fs.exists)(outputPath)) {
|
|
95
|
+
const s = await (0, node_fs_promises.stat)(outputPath);
|
|
96
|
+
if (!s.isFile()) throw new Error(`Output path ${outputPath} is not a file`);
|
|
97
|
+
if (s.size > 0 && !options.force) throw new Error(`Output file ${outputPath} already exists. Use --force to overwrite.`);
|
|
98
|
+
} else await (0, node_fs_promises.mkdir)((0, node_path.dirname)(outputPath), { recursive: true });
|
|
99
|
+
await (0, node_fs_promises.writeFile)(outputPath, "", "utf8");
|
|
100
|
+
}
|
|
101
|
+
if (options.interactive) {
|
|
102
|
+
if (!(0, node_tty.isatty)(process.stdout.fd)) throw new Error("--interactive mode requires a TTY terminal");
|
|
103
|
+
await require_utils_run_chat_loop.runChatLoopInTerminal(agent instanceof _aigne_core.UserAgent ? agent : aigne.invoke(agent), {
|
|
104
|
+
...chatLoopOptions,
|
|
105
|
+
outputKey,
|
|
106
|
+
inputFileKey: agent instanceof _aigne_core.AIAgent ? agent.inputFileKey : void 0,
|
|
107
|
+
input: options.input,
|
|
108
|
+
sessionId,
|
|
109
|
+
userId
|
|
110
|
+
});
|
|
111
|
+
return;
|
|
112
|
+
}
|
|
113
|
+
const { result } = await new require_terminal.TerminalTracer(aigne.newContext(), {
|
|
114
|
+
outputKey,
|
|
115
|
+
outputFileKey
|
|
116
|
+
}).run(agent, options.input ?? {});
|
|
117
|
+
if (options.output) {
|
|
118
|
+
const message = result[outputKey || _aigne_core.DEFAULT_OUTPUT_KEY];
|
|
119
|
+
const content = typeof message === "string" ? message : JSON.stringify(result, null, 2);
|
|
120
|
+
const path = (0, node_path.isAbsolute)(options.output) ? options.output : (0, node_path.join)(process.cwd(), options.output);
|
|
121
|
+
await (0, node_fs_promises.mkdir)((0, node_path.dirname)(path), { recursive: true });
|
|
122
|
+
await (0, node_fs_promises.writeFile)(path, content, "utf8");
|
|
123
|
+
}
|
|
124
|
+
return { result };
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
//#endregion
|
|
128
|
+
exports.loadAIGNEWithCmdOptions = loadAIGNEWithCmdOptions;
|
|
129
|
+
exports.parseAgentInputByCommander = parseAgentInputByCommander;
|
|
130
|
+
exports.runAgentWithAIGNE = runAgentWithAIGNE;
|
|
131
|
+
exports.runWithAIGNE = runWithAIGNE;
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import { AgentRunCommonOptions } from "./yargs.cjs";
|
|
2
|
+
import { ChatLoopOptions } from "./run-chat-loop.cjs";
|
|
3
|
+
import * as _aigne_core0 from "@aigne/core";
|
|
4
|
+
import { AIGNE, Agent, ChatModelInputOptions, Message } from "@aigne/core";
|
|
5
|
+
import { PromiseOrValue } from "@aigne/core/utils/type-utils";
|
|
6
|
+
|
|
7
|
+
//#region src/utils/run-with-aigne.d.ts
|
|
8
|
+
declare function parseAgentInputByCommander(agent: Agent, options?: AgentRunCommonOptions & {
|
|
9
|
+
inputKey?: string;
|
|
10
|
+
argv?: string[];
|
|
11
|
+
defaultInput?: string | Message;
|
|
12
|
+
}): Promise<Message>;
|
|
13
|
+
declare function loadAIGNEWithCmdOptions(): Promise<AIGNE<_aigne_core0.UserContext>>;
|
|
14
|
+
declare function runWithAIGNE(agentCreator: ((aigne: AIGNE) => PromiseOrValue<Agent>) | Agent, {
|
|
15
|
+
aigne,
|
|
16
|
+
argv,
|
|
17
|
+
chatLoopOptions,
|
|
18
|
+
modelOptions,
|
|
19
|
+
outputKey
|
|
20
|
+
}?: {
|
|
21
|
+
aigne?: AIGNE;
|
|
22
|
+
argv?: typeof process.argv;
|
|
23
|
+
chatLoopOptions?: ChatLoopOptions;
|
|
24
|
+
modelOptions?: ChatModelInputOptions;
|
|
25
|
+
outputKey?: string;
|
|
26
|
+
}): Promise<void>;
|
|
27
|
+
declare function runAgentWithAIGNE(aigne: AIGNE, agent: Agent, {
|
|
28
|
+
userId,
|
|
29
|
+
sessionId,
|
|
30
|
+
outputKey,
|
|
31
|
+
outputFileKey,
|
|
32
|
+
chatLoopOptions,
|
|
33
|
+
...options
|
|
34
|
+
}?: {
|
|
35
|
+
userId?: string;
|
|
36
|
+
sessionId?: string;
|
|
37
|
+
outputKey?: string;
|
|
38
|
+
outputFileKey?: string;
|
|
39
|
+
chatLoopOptions?: ChatLoopOptions;
|
|
40
|
+
input?: Message;
|
|
41
|
+
} & Omit<AgentRunCommonOptions, "input">): Promise<{
|
|
42
|
+
result: Message;
|
|
43
|
+
} | undefined>;
|
|
44
|
+
//#endregion
|
|
45
|
+
export { loadAIGNEWithCmdOptions, parseAgentInputByCommander, runAgentWithAIGNE, runWithAIGNE };
|
|
46
|
+
//# sourceMappingURL=run-with-aigne.d.cts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"run-with-aigne.d.cts","names":[],"sources":["../../src/utils/run-with-aigne.ts"],"mappings":";;;;;;;iBAqCsB,0BAAA,CAAA,KAAA,EACb,KAAA,EAAA,OAAA,GACE,qBAAA;EAAA,QAAA;EAAA,IAAA;EAAA,YAAA,YAGiB,OAAA;AAAA,IAEzB,OAAA,CAAQ,OAAA;AAAA,iBAyBW,uBAAA,CAAA,GAAuB,OAAA,CAAA,KAAA,CAAA,YAAA,CAAA,WAAA;AAAA,iBAcvB,YAAA,CAAA,YAAA,IAAA,KAAA,EACG,KAAA,KAAU,cAAA,CAAe,KAAA,KAAU,KAAA;EAAA,KAAA;EAAA,IAAA;EAAA,eAAA;EAAA,YAAA;EAAA;AAAA;EAAA,KAAA,GAQhD,KAAA;EAAA,IAAA,UACM,OAAA,CAAQ,IAAA;EAAA,eAAA,GACJ,eAAA;EAAA,YAAA,GACH,qBAAA;EAAA,SAAA;AAAA,IAEX,OAAA;AAAA,iBAuFc,iBAAA,CAAA,KAAA,EACb,KAAA,EAAA,KAAA,EACA,KAAA;EAAA,MAAA;EAAA,SAAA;EAAA,SAAA;EAAA,aAAA;EAAA,eAAA;EAAA,GAAA;AAAA;EAAA,MAAA;EAAA,SAAA;EAAA,SAAA;EAAA,aAAA;EAAA,eAAA,GAaa,eAAA;EAAA,KAAA,GACV,OAAA;AAAA,IACN,IAAA,CAAK,qBAAA,aAAoC,OAAA;EAAA,MAAA"}
|