@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 @@
|
|
|
1
|
+
{"version":3,"file":"url.d.mts","names":[],"sources":["../../src/utils/url.ts"],"mappings":";iBAAgB,KAAA,CAAA,CAAA"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"url.mjs","names":[],"sources":["../../src/utils/url.ts"],"sourcesContent":["export function isUrl(s: string): boolean {\n return /^https?:\\/\\/\\S+/.test(s);\n}\n"],"mappings":";AAAA,SAAgB,MAAM,GAAoB;AACxC,QAAO,kBAAkB,KAAK,EAAE"}
|
|
@@ -0,0 +1,191 @@
|
|
|
1
|
+
const require_rolldown_runtime = require('../_virtual/rolldown_runtime.cjs');
|
|
2
|
+
let node_fs = require("node:fs");
|
|
3
|
+
let _aigne_core_utils_logger = require("@aigne/core/utils/logger");
|
|
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
|
+
let _aigne_aigne_hub = require("@aigne/aigne-hub");
|
|
9
|
+
let yaml = require("yaml");
|
|
10
|
+
let zod = require("zod");
|
|
11
|
+
zod = require_rolldown_runtime.__toESM(zod);
|
|
12
|
+
let node_tty = require("node:tty");
|
|
13
|
+
let node_util = require("node:util");
|
|
14
|
+
|
|
15
|
+
//#region src/utils/yargs.ts
|
|
16
|
+
const MODEL_OPTIONS_GROUP_NAME = "Model Options";
|
|
17
|
+
const withRunAgentCommonOptions = (yargs) => yargs.option("interactive", {
|
|
18
|
+
describe: "Run in interactive chat mode",
|
|
19
|
+
type: "boolean",
|
|
20
|
+
default: false,
|
|
21
|
+
alias: ["chat"]
|
|
22
|
+
}).option("session-id", {
|
|
23
|
+
describe: "Session ID for chat-based agents to maintain context across interactions",
|
|
24
|
+
type: "string"
|
|
25
|
+
}).option("model", {
|
|
26
|
+
group: MODEL_OPTIONS_GROUP_NAME,
|
|
27
|
+
describe: `AI model to use in format 'provider[/model]' where model is optional. Examples: 'openai' or 'openai/gpt-4o-mini'. Available providers: ${formatModelsName((0, _aigne_aigne_hub.availableModels)())} (default: openai)`,
|
|
28
|
+
type: "string"
|
|
29
|
+
}).option("image-model", {
|
|
30
|
+
group: MODEL_OPTIONS_GROUP_NAME,
|
|
31
|
+
describe: `Image model to use in format 'provider[/model]' where model is optional. Examples: 'openai' or 'openai/gpt-image-1'. Available providers: ${formatModelsName((0, _aigne_aigne_hub.availableImageModels)())} (default: openai)`,
|
|
32
|
+
type: "string"
|
|
33
|
+
}).option("temperature", {
|
|
34
|
+
group: MODEL_OPTIONS_GROUP_NAME,
|
|
35
|
+
describe: "Temperature for the model (controls randomness, higher values produce more random outputs). Range: 0.0-2.0",
|
|
36
|
+
type: "number",
|
|
37
|
+
coerce: customZodError("--temperature", (s) => zod.default.coerce.number().min(0).max(2).parse(s))
|
|
38
|
+
}).option("top-p", {
|
|
39
|
+
group: MODEL_OPTIONS_GROUP_NAME,
|
|
40
|
+
describe: "Top P (nucleus sampling) parameter for the model (controls diversity). Range: 0.0-1.0",
|
|
41
|
+
type: "number",
|
|
42
|
+
coerce: customZodError("--top-p", (s) => zod.default.coerce.number().min(0).max(1).parse(s))
|
|
43
|
+
}).option("presence-penalty", {
|
|
44
|
+
group: MODEL_OPTIONS_GROUP_NAME,
|
|
45
|
+
describe: "Presence penalty for the model (penalizes repeating the same tokens). Range: -2.0 to 2.0",
|
|
46
|
+
type: "number",
|
|
47
|
+
coerce: customZodError("--presence-penalty", (s) => zod.default.coerce.number().min(-2).max(2).parse(s))
|
|
48
|
+
}).option("frequency-penalty", {
|
|
49
|
+
group: MODEL_OPTIONS_GROUP_NAME,
|
|
50
|
+
describe: "Frequency penalty for the model (penalizes frequency of token usage). Range: -2.0 to 2.0",
|
|
51
|
+
type: "number",
|
|
52
|
+
coerce: customZodError("--frequency-penalty", (s) => zod.default.coerce.number().min(-2).max(2).parse(s))
|
|
53
|
+
}).option("input", {
|
|
54
|
+
describe: "Input to the agent, use @<file> to read from a file",
|
|
55
|
+
type: "string",
|
|
56
|
+
array: true,
|
|
57
|
+
alias: "i"
|
|
58
|
+
}).option("input-file", {
|
|
59
|
+
describe: "Input files to the agent",
|
|
60
|
+
type: "string",
|
|
61
|
+
array: true
|
|
62
|
+
}).option("format", {
|
|
63
|
+
describe: "Input format for the agent (available: text, json, yaml default: text)",
|
|
64
|
+
type: "string",
|
|
65
|
+
choices: [
|
|
66
|
+
"text",
|
|
67
|
+
"json",
|
|
68
|
+
"yaml"
|
|
69
|
+
]
|
|
70
|
+
}).option("output", {
|
|
71
|
+
describe: "Output file to save the result (default: stdout)",
|
|
72
|
+
type: "string",
|
|
73
|
+
alias: "o"
|
|
74
|
+
}).option("output-key", {
|
|
75
|
+
describe: "Key in the result to save to the output file",
|
|
76
|
+
type: "string",
|
|
77
|
+
default: _aigne_core.DEFAULT_OUTPUT_KEY
|
|
78
|
+
}).option("force", {
|
|
79
|
+
describe: "Truncate the output file if it exists, and create directory if the output path does not exists",
|
|
80
|
+
type: "boolean",
|
|
81
|
+
default: false
|
|
82
|
+
}).option("log-level", {
|
|
83
|
+
describe: `Log level for detailed debugging information. Values: ${Object.values(_aigne_core_utils_logger.LogLevel).join(", ")}`,
|
|
84
|
+
type: "string",
|
|
85
|
+
default: (0, _aigne_core_utils_logger.getLevelFromEnv)(_aigne_core_utils_logger.logger.options.ns) || _aigne_core_utils_logger.LogLevel.SILENT,
|
|
86
|
+
coerce: customZodError("--log-level", (s) => zod.default.nativeEnum(_aigne_core_utils_logger.LogLevel).parse(s))
|
|
87
|
+
}).option("aigne-hub-url", {
|
|
88
|
+
group: MODEL_OPTIONS_GROUP_NAME,
|
|
89
|
+
describe: "Custom AIGNE Hub service URL. Used to fetch remote agent definitions or models.",
|
|
90
|
+
type: "string"
|
|
91
|
+
});
|
|
92
|
+
function formatModelsName(models) {
|
|
93
|
+
return models.map((i) => {
|
|
94
|
+
if (typeof i.name === "string") return i.name.toLowerCase().replace(/ChatModel$/i, "");
|
|
95
|
+
return i.name.map((n) => n.toLowerCase().replace(/ChatModel$/i, ""));
|
|
96
|
+
}).join(", ");
|
|
97
|
+
}
|
|
98
|
+
function inferZodType(type, opts = {}) {
|
|
99
|
+
if (type instanceof zod.ZodUnknown || type instanceof zod.ZodAny) return {
|
|
100
|
+
type: "string",
|
|
101
|
+
optional: true
|
|
102
|
+
};
|
|
103
|
+
opts.optional ??= type.isNullable() || type.isOptional();
|
|
104
|
+
if ("innerType" in type._def && type._def.innerType instanceof zod.ZodType) return inferZodType(type._def.innerType, opts);
|
|
105
|
+
if (type instanceof zod.ZodArray) return inferZodType(type.element, {
|
|
106
|
+
...opts,
|
|
107
|
+
array: true
|
|
108
|
+
});
|
|
109
|
+
return {
|
|
110
|
+
...opts,
|
|
111
|
+
array: opts.array || void 0,
|
|
112
|
+
optional: opts.optional || void 0,
|
|
113
|
+
type: type instanceof zod.ZodBoolean ? "boolean" : type instanceof zod.ZodNumber ? "number" : "string"
|
|
114
|
+
};
|
|
115
|
+
}
|
|
116
|
+
function withAgentInputSchema(yargs, options) {
|
|
117
|
+
const inputSchema = options.inputSchema instanceof zod.ZodObject ? options.inputSchema.shape : {};
|
|
118
|
+
for (const [option, config] of Object.entries(inputSchema)) {
|
|
119
|
+
const type = inferZodType(config);
|
|
120
|
+
yargs.option(option, {
|
|
121
|
+
group: "Agent Parameters",
|
|
122
|
+
type: type.type,
|
|
123
|
+
description: config.description,
|
|
124
|
+
array: type.array
|
|
125
|
+
});
|
|
126
|
+
if (!type.optional && !options.optionalInputs?.includes(option)) yargs.demandOption(option);
|
|
127
|
+
}
|
|
128
|
+
return withRunAgentCommonOptions(yargs);
|
|
129
|
+
}
|
|
130
|
+
async function parseAgentInput(i, agent) {
|
|
131
|
+
const inputSchema = agent.inputSchema instanceof zod.ZodObject ? agent.inputSchema.shape : {};
|
|
132
|
+
const input = Object.fromEntries(await Promise.all(Object.entries((0, _aigne_core_utils_type_utils.pick)(i, Object.keys(inputSchema))).map(async ([key, val]) => {
|
|
133
|
+
if (typeof val === "string" && val.startsWith("@")) {
|
|
134
|
+
const schema = inputSchema[key];
|
|
135
|
+
val = await readFileAsInput(val, { format: schema instanceof zod.ZodString ? "raw" : void 0 });
|
|
136
|
+
}
|
|
137
|
+
return [key, val];
|
|
138
|
+
})));
|
|
139
|
+
if (agent instanceof _aigne_core.AIAgent && agent.inputFileKey) {
|
|
140
|
+
const files = [];
|
|
141
|
+
for (const file of (0, _aigne_core_utils_type_utils.flat)(i.inputFile, i[agent.inputFileKey]) ?? []) {
|
|
142
|
+
const raw = await (0, node_fs_promises.readFile)(file.replace(/^@/, ""), "base64");
|
|
143
|
+
const filename = (0, node_path.basename)(file);
|
|
144
|
+
const mimeType = await _aigne_core.ChatModel.getMimeType(filename) || "application/octet-stream";
|
|
145
|
+
files.push({
|
|
146
|
+
type: "file",
|
|
147
|
+
data: raw,
|
|
148
|
+
filename,
|
|
149
|
+
mimeType
|
|
150
|
+
});
|
|
151
|
+
}
|
|
152
|
+
Object.assign(input, { [agent.inputFileKey]: files });
|
|
153
|
+
}
|
|
154
|
+
const rawInput = i.input || ((0, node_tty.isatty)(process.stdin.fd) || !await stdinHasData() ? null : [await (0, _aigne_core.readAllString)(process.stdin)].filter(Boolean));
|
|
155
|
+
if (rawInput) for (const raw of rawInput) {
|
|
156
|
+
const parsed = raw.startsWith("@") ? await readFileAsInput(raw, { format: i.format }) : raw;
|
|
157
|
+
if (typeof parsed !== "string") Object.assign(input, parsed);
|
|
158
|
+
else {
|
|
159
|
+
const inputKey = agent instanceof _aigne_core.AIAgent ? agent.inputKey : void 0;
|
|
160
|
+
if (inputKey) Object.assign(input, { [inputKey]: parsed });
|
|
161
|
+
}
|
|
162
|
+
}
|
|
163
|
+
return input;
|
|
164
|
+
}
|
|
165
|
+
async function readFileAsInput(value, { format } = {}) {
|
|
166
|
+
if (value.startsWith("@")) {
|
|
167
|
+
const ext = (0, node_path.extname)(value);
|
|
168
|
+
value = await (0, node_fs_promises.readFile)(value.slice(1), "utf8");
|
|
169
|
+
if (!format) {
|
|
170
|
+
if (ext === ".json") format = "json";
|
|
171
|
+
else if (ext === ".yaml" || ext === ".yml") format = "yaml";
|
|
172
|
+
}
|
|
173
|
+
}
|
|
174
|
+
if (format === "json") return JSON.parse(value);
|
|
175
|
+
else if (format === "yaml") return (0, yaml.parse)(value);
|
|
176
|
+
return value;
|
|
177
|
+
}
|
|
178
|
+
async function stdinHasData() {
|
|
179
|
+
const stats = await (0, node_util.promisify)(node_fs.fstat)(0);
|
|
180
|
+
return stats.isFIFO() || stats.isFile();
|
|
181
|
+
}
|
|
182
|
+
function customZodError(label, fn) {
|
|
183
|
+
return ((...args) => (0, _aigne_core_utils_type_utils.tryOrThrow)(() => fn(...args), (e) => /* @__PURE__ */ new Error(`${label} ${e instanceof zod.ZodError ? e.issues[0]?.message : e.message}`)));
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
//#endregion
|
|
187
|
+
exports.inferZodType = inferZodType;
|
|
188
|
+
exports.parseAgentInput = parseAgentInput;
|
|
189
|
+
exports.stdinHasData = stdinHasData;
|
|
190
|
+
exports.withAgentInputSchema = withAgentInputSchema;
|
|
191
|
+
exports.withRunAgentCommonOptions = withRunAgentCommonOptions;
|
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
import { Agent, Message } from "@aigne/core";
|
|
2
|
+
import { LogLevel } from "@aigne/core/utils/logger";
|
|
3
|
+
import { Argv } from "yargs";
|
|
4
|
+
import { ZodType } from "zod";
|
|
5
|
+
|
|
6
|
+
//#region src/utils/yargs.d.ts
|
|
7
|
+
type InferArgv<T> = T extends Argv<infer U> ? U : never;
|
|
8
|
+
declare const withRunAgentCommonOptions: (yargs: Argv) => Argv<{
|
|
9
|
+
interactive: boolean;
|
|
10
|
+
} & {
|
|
11
|
+
"session-id": string | undefined;
|
|
12
|
+
} & {
|
|
13
|
+
model: string | undefined;
|
|
14
|
+
} & {
|
|
15
|
+
"image-model": string | undefined;
|
|
16
|
+
} & {
|
|
17
|
+
temperature: number | undefined;
|
|
18
|
+
} & {
|
|
19
|
+
"top-p": number | undefined;
|
|
20
|
+
} & {
|
|
21
|
+
"presence-penalty": number | undefined;
|
|
22
|
+
} & {
|
|
23
|
+
"frequency-penalty": number | undefined;
|
|
24
|
+
} & {
|
|
25
|
+
input: string[] | undefined;
|
|
26
|
+
} & {
|
|
27
|
+
"input-file": string[] | undefined;
|
|
28
|
+
} & {
|
|
29
|
+
format: string | undefined;
|
|
30
|
+
} & {
|
|
31
|
+
output: string | undefined;
|
|
32
|
+
} & {
|
|
33
|
+
"output-key": string;
|
|
34
|
+
} & {
|
|
35
|
+
force: boolean;
|
|
36
|
+
} & {
|
|
37
|
+
"log-level": LogLevel;
|
|
38
|
+
} & {
|
|
39
|
+
"aigne-hub-url": string | undefined;
|
|
40
|
+
}>;
|
|
41
|
+
type _AgentRunCommonOptions = Partial<InferArgv<ReturnType<typeof withAgentInputSchema>>>;
|
|
42
|
+
/** Convert literal string types like 'foo-bar' to 'FooBar' */
|
|
43
|
+
type PascalCase<S extends string> = string extends S ? string : S extends `${infer T}-${infer U}` ? `${Capitalize<T>}${PascalCase<U>}` : Capitalize<S>;
|
|
44
|
+
/** Convert literal string types like 'foo-bar' to 'fooBar' */
|
|
45
|
+
type CamelCase<S extends string> = string extends S ? string : S extends `${infer T}-${infer U}` ? `${T}${PascalCase<U>}` : S;
|
|
46
|
+
/** Convert literal string types like 'foo-bar' to 'fooBar', allowing all `PropertyKey` types */
|
|
47
|
+
type CamelCaseKey<K extends PropertyKey> = K extends string ? Exclude<CamelCase<K>, ""> : K;
|
|
48
|
+
type AgentRunCommonOptions = { [key in keyof _AgentRunCommonOptions as CamelCaseKey<key>]: _AgentRunCommonOptions[key] };
|
|
49
|
+
declare function inferZodType(type: ZodType, opts?: {
|
|
50
|
+
array?: boolean;
|
|
51
|
+
optional?: boolean;
|
|
52
|
+
}): {
|
|
53
|
+
type: "string" | "number" | "boolean";
|
|
54
|
+
array?: boolean;
|
|
55
|
+
optional?: boolean;
|
|
56
|
+
};
|
|
57
|
+
declare function withAgentInputSchema(yargs: Argv, options: Pick<Agent, "inputSchema"> & {
|
|
58
|
+
optionalInputs?: string[];
|
|
59
|
+
}): Argv<{
|
|
60
|
+
interactive: boolean;
|
|
61
|
+
} & {
|
|
62
|
+
"session-id": string | undefined;
|
|
63
|
+
} & {
|
|
64
|
+
model: string | undefined;
|
|
65
|
+
} & {
|
|
66
|
+
"image-model": string | undefined;
|
|
67
|
+
} & {
|
|
68
|
+
temperature: number | undefined;
|
|
69
|
+
} & {
|
|
70
|
+
"top-p": number | undefined;
|
|
71
|
+
} & {
|
|
72
|
+
"presence-penalty": number | undefined;
|
|
73
|
+
} & {
|
|
74
|
+
"frequency-penalty": number | undefined;
|
|
75
|
+
} & {
|
|
76
|
+
input: string[] | undefined;
|
|
77
|
+
} & {
|
|
78
|
+
"input-file": string[] | undefined;
|
|
79
|
+
} & {
|
|
80
|
+
format: string | undefined;
|
|
81
|
+
} & {
|
|
82
|
+
output: string | undefined;
|
|
83
|
+
} & {
|
|
84
|
+
"output-key": string;
|
|
85
|
+
} & {
|
|
86
|
+
force: boolean;
|
|
87
|
+
} & {
|
|
88
|
+
"log-level": LogLevel;
|
|
89
|
+
} & {
|
|
90
|
+
"aigne-hub-url": string | undefined;
|
|
91
|
+
}>;
|
|
92
|
+
declare function parseAgentInput(i: Message & AgentRunCommonOptions, agent: Agent): Promise<any>;
|
|
93
|
+
declare function stdinHasData(): Promise<boolean>;
|
|
94
|
+
//#endregion
|
|
95
|
+
export { AgentRunCommonOptions, InferArgv, inferZodType, parseAgentInput, stdinHasData, withAgentInputSchema, withRunAgentCommonOptions };
|
|
96
|
+
//# sourceMappingURL=yargs.d.cts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"yargs.d.cts","names":[],"sources":["../../src/utils/yargs.ts"],"mappings":";;;;;;KAoCY,SAAA,MAAe,CAAA,SAAU,IAAA,YAAA,CAAA;AAAA,cAIxB,yBAAA,GAAA,KAAA,EAAoC,IAAA,KAAI,IAAA;EAAA,WAAA;AAAA;EAAA;AAAA;EAAA,KAAA;AAAA;EAAA;AAAA;EAAA,WAAA;AAAA;EAAA;AAAA;EAAA;AAAA;EAAA;AAAA;EAAA,KAAA;AAAA;EAAA;AAAA;EAAA,MAAA;AAAA;EAAA,MAAA;AAAA;EAAA;AAAA;EAAA,KAAA;AAAA;EAAA;;;;KAiHhD,sBAAA,GAAyB,OAAA,CAAQ,SAAA,CAAU,UAAA,QAAkB,oBAAA;AAAA;AAAA,KAG7D,UAAA,oCAA8C,CAAA,YAE/C,CAAA,sCACK,UAAA,CAAW,CAAA,IAAK,UAAA,CAAW,CAAA,MAC9B,UAAA,CAAW,CAAA;AAAA;AAAA,KAGZ,SAAA,oCAA6C,CAAA,YAE9C,CAAA,sCACK,CAAA,GAAI,UAAA,CAAW,CAAA,MAClB,CAAA;AAAA;AAAA,KAGD,YAAA,WAAuB,WAAA,IAAe,CAAA,kBAAmB,OAAA,CAAQ,SAAA,CAAU,CAAA,SAAU,CAAA;AAAA,KAE9E,qBAAA,mBACI,sBAAA,IAA0B,YAAA,CAAa,GAAA,IAAO,sBAAA,CAAuB,GAAA;AAAA,iBAGrE,YAAA,CAAA,IAAA,EACR,OAAA,EAAA,IAAA;EAAA,KAAA;EAAA,QAAA;AAAA;EAAA,IAAA;EAAA,KAAA;EAAA,QAAA;AAAA;AAAA,iBA6BQ,oBAAA,CAAA,KAAA,EACP,IAAA,EAAA,OAAA,EACE,IAAA,CAAK,KAAA;EAAA,cAAA;AAAA,IAAqD,IAAA;EAAA,WAAA;AAAA;EAAA;AAAA;EAAA,KAAA;AAAA;EAAA;AAAA;EAAA,WAAA;AAAA;EAAA;AAAA;EAAA;AAAA;EAAA;AAAA;EAAA,KAAA;AAAA;EAAA;AAAA;EAAA,MAAA;AAAA;EAAA,MAAA;AAAA;EAAA;AAAA;EAAA,KAAA;AAAA;EAAA;;;;iBAuB/C,eAAA,CAAA,CAAA,EAAmB,OAAA,GAAU,qBAAA,EAAA,KAAA,EAA8B,KAAA,GAAK,OAAA;AAAA,iBAgFhE,YAAA,CAAA,GAAgB,OAAA"}
|
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
import { LogLevel } from "@aigne/core/utils/logger";
|
|
2
|
+
import { Argv } from "yargs";
|
|
3
|
+
import { Agent, Message } from "@aigne/core";
|
|
4
|
+
import { ZodType } from "zod";
|
|
5
|
+
|
|
6
|
+
//#region src/utils/yargs.d.ts
|
|
7
|
+
type InferArgv<T> = T extends Argv<infer U> ? U : never;
|
|
8
|
+
declare const withRunAgentCommonOptions: (yargs: Argv) => Argv<{
|
|
9
|
+
interactive: boolean;
|
|
10
|
+
} & {
|
|
11
|
+
"session-id": string | undefined;
|
|
12
|
+
} & {
|
|
13
|
+
model: string | undefined;
|
|
14
|
+
} & {
|
|
15
|
+
"image-model": string | undefined;
|
|
16
|
+
} & {
|
|
17
|
+
temperature: number | undefined;
|
|
18
|
+
} & {
|
|
19
|
+
"top-p": number | undefined;
|
|
20
|
+
} & {
|
|
21
|
+
"presence-penalty": number | undefined;
|
|
22
|
+
} & {
|
|
23
|
+
"frequency-penalty": number | undefined;
|
|
24
|
+
} & {
|
|
25
|
+
input: string[] | undefined;
|
|
26
|
+
} & {
|
|
27
|
+
"input-file": string[] | undefined;
|
|
28
|
+
} & {
|
|
29
|
+
format: string | undefined;
|
|
30
|
+
} & {
|
|
31
|
+
output: string | undefined;
|
|
32
|
+
} & {
|
|
33
|
+
"output-key": string;
|
|
34
|
+
} & {
|
|
35
|
+
force: boolean;
|
|
36
|
+
} & {
|
|
37
|
+
"log-level": LogLevel;
|
|
38
|
+
} & {
|
|
39
|
+
"aigne-hub-url": string | undefined;
|
|
40
|
+
}>;
|
|
41
|
+
type _AgentRunCommonOptions = Partial<InferArgv<ReturnType<typeof withAgentInputSchema>>>;
|
|
42
|
+
/** Convert literal string types like 'foo-bar' to 'FooBar' */
|
|
43
|
+
type PascalCase<S extends string> = string extends S ? string : S extends `${infer T}-${infer U}` ? `${Capitalize<T>}${PascalCase<U>}` : Capitalize<S>;
|
|
44
|
+
/** Convert literal string types like 'foo-bar' to 'fooBar' */
|
|
45
|
+
type CamelCase<S extends string> = string extends S ? string : S extends `${infer T}-${infer U}` ? `${T}${PascalCase<U>}` : S;
|
|
46
|
+
/** Convert literal string types like 'foo-bar' to 'fooBar', allowing all `PropertyKey` types */
|
|
47
|
+
type CamelCaseKey<K extends PropertyKey> = K extends string ? Exclude<CamelCase<K>, ""> : K;
|
|
48
|
+
type AgentRunCommonOptions = { [key in keyof _AgentRunCommonOptions as CamelCaseKey<key>]: _AgentRunCommonOptions[key] };
|
|
49
|
+
declare function inferZodType(type: ZodType, opts?: {
|
|
50
|
+
array?: boolean;
|
|
51
|
+
optional?: boolean;
|
|
52
|
+
}): {
|
|
53
|
+
type: "string" | "number" | "boolean";
|
|
54
|
+
array?: boolean;
|
|
55
|
+
optional?: boolean;
|
|
56
|
+
};
|
|
57
|
+
declare function withAgentInputSchema(yargs: Argv, options: Pick<Agent, "inputSchema"> & {
|
|
58
|
+
optionalInputs?: string[];
|
|
59
|
+
}): Argv<{
|
|
60
|
+
interactive: boolean;
|
|
61
|
+
} & {
|
|
62
|
+
"session-id": string | undefined;
|
|
63
|
+
} & {
|
|
64
|
+
model: string | undefined;
|
|
65
|
+
} & {
|
|
66
|
+
"image-model": string | undefined;
|
|
67
|
+
} & {
|
|
68
|
+
temperature: number | undefined;
|
|
69
|
+
} & {
|
|
70
|
+
"top-p": number | undefined;
|
|
71
|
+
} & {
|
|
72
|
+
"presence-penalty": number | undefined;
|
|
73
|
+
} & {
|
|
74
|
+
"frequency-penalty": number | undefined;
|
|
75
|
+
} & {
|
|
76
|
+
input: string[] | undefined;
|
|
77
|
+
} & {
|
|
78
|
+
"input-file": string[] | undefined;
|
|
79
|
+
} & {
|
|
80
|
+
format: string | undefined;
|
|
81
|
+
} & {
|
|
82
|
+
output: string | undefined;
|
|
83
|
+
} & {
|
|
84
|
+
"output-key": string;
|
|
85
|
+
} & {
|
|
86
|
+
force: boolean;
|
|
87
|
+
} & {
|
|
88
|
+
"log-level": LogLevel;
|
|
89
|
+
} & {
|
|
90
|
+
"aigne-hub-url": string | undefined;
|
|
91
|
+
}>;
|
|
92
|
+
declare function parseAgentInput(i: Message & AgentRunCommonOptions, agent: Agent): Promise<any>;
|
|
93
|
+
declare function stdinHasData(): Promise<boolean>;
|
|
94
|
+
//#endregion
|
|
95
|
+
export { AgentRunCommonOptions, InferArgv, inferZodType, parseAgentInput, stdinHasData, withAgentInputSchema, withRunAgentCommonOptions };
|
|
96
|
+
//# sourceMappingURL=yargs.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"yargs.d.mts","names":[],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AAA,MAAA;AAAA;EAAA,MAAA;AAAA;EAAA;AAAA;EAAA,KAAA;AAAA;EAAA;;;;iBAuB/C,eAAA,CAAA,CAAA,EAAmB,OAAA,GAAU,qBAAA,EAAA,KAAA,EAA8B,KAAA,GAAK,OAAA;AAAA,iBAgFhE,YAAA,CAAA,GAAgB,OAAA"}
|
|
@@ -0,0 +1,186 @@
|
|
|
1
|
+
import { fstat } from "node:fs";
|
|
2
|
+
import { LogLevel, getLevelFromEnv, logger } from "@aigne/core/utils/logger";
|
|
3
|
+
import { basename, extname } from "node:path";
|
|
4
|
+
import { readFile } from "node:fs/promises";
|
|
5
|
+
import { AIAgent, ChatModel, DEFAULT_OUTPUT_KEY, readAllString } from "@aigne/core";
|
|
6
|
+
import { flat, pick, tryOrThrow } from "@aigne/core/utils/type-utils";
|
|
7
|
+
import { availableImageModels, availableModels } from "@aigne/aigne-hub";
|
|
8
|
+
import { parse } from "yaml";
|
|
9
|
+
import z, { ZodAny, ZodArray, ZodBoolean, ZodError, ZodNumber, ZodObject, ZodString, ZodType, ZodUnknown } from "zod";
|
|
10
|
+
import { isatty } from "node:tty";
|
|
11
|
+
import { promisify } from "node:util";
|
|
12
|
+
|
|
13
|
+
//#region src/utils/yargs.ts
|
|
14
|
+
const MODEL_OPTIONS_GROUP_NAME = "Model Options";
|
|
15
|
+
const withRunAgentCommonOptions = (yargs) => yargs.option("interactive", {
|
|
16
|
+
describe: "Run in interactive chat mode",
|
|
17
|
+
type: "boolean",
|
|
18
|
+
default: false,
|
|
19
|
+
alias: ["chat"]
|
|
20
|
+
}).option("session-id", {
|
|
21
|
+
describe: "Session ID for chat-based agents to maintain context across interactions",
|
|
22
|
+
type: "string"
|
|
23
|
+
}).option("model", {
|
|
24
|
+
group: MODEL_OPTIONS_GROUP_NAME,
|
|
25
|
+
describe: `AI model to use in format 'provider[/model]' where model is optional. Examples: 'openai' or 'openai/gpt-4o-mini'. Available providers: ${formatModelsName(availableModels())} (default: openai)`,
|
|
26
|
+
type: "string"
|
|
27
|
+
}).option("image-model", {
|
|
28
|
+
group: MODEL_OPTIONS_GROUP_NAME,
|
|
29
|
+
describe: `Image model to use in format 'provider[/model]' where model is optional. Examples: 'openai' or 'openai/gpt-image-1'. Available providers: ${formatModelsName(availableImageModels())} (default: openai)`,
|
|
30
|
+
type: "string"
|
|
31
|
+
}).option("temperature", {
|
|
32
|
+
group: MODEL_OPTIONS_GROUP_NAME,
|
|
33
|
+
describe: "Temperature for the model (controls randomness, higher values produce more random outputs). Range: 0.0-2.0",
|
|
34
|
+
type: "number",
|
|
35
|
+
coerce: customZodError("--temperature", (s) => z.coerce.number().min(0).max(2).parse(s))
|
|
36
|
+
}).option("top-p", {
|
|
37
|
+
group: MODEL_OPTIONS_GROUP_NAME,
|
|
38
|
+
describe: "Top P (nucleus sampling) parameter for the model (controls diversity). Range: 0.0-1.0",
|
|
39
|
+
type: "number",
|
|
40
|
+
coerce: customZodError("--top-p", (s) => z.coerce.number().min(0).max(1).parse(s))
|
|
41
|
+
}).option("presence-penalty", {
|
|
42
|
+
group: MODEL_OPTIONS_GROUP_NAME,
|
|
43
|
+
describe: "Presence penalty for the model (penalizes repeating the same tokens). Range: -2.0 to 2.0",
|
|
44
|
+
type: "number",
|
|
45
|
+
coerce: customZodError("--presence-penalty", (s) => z.coerce.number().min(-2).max(2).parse(s))
|
|
46
|
+
}).option("frequency-penalty", {
|
|
47
|
+
group: MODEL_OPTIONS_GROUP_NAME,
|
|
48
|
+
describe: "Frequency penalty for the model (penalizes frequency of token usage). Range: -2.0 to 2.0",
|
|
49
|
+
type: "number",
|
|
50
|
+
coerce: customZodError("--frequency-penalty", (s) => z.coerce.number().min(-2).max(2).parse(s))
|
|
51
|
+
}).option("input", {
|
|
52
|
+
describe: "Input to the agent, use @<file> to read from a file",
|
|
53
|
+
type: "string",
|
|
54
|
+
array: true,
|
|
55
|
+
alias: "i"
|
|
56
|
+
}).option("input-file", {
|
|
57
|
+
describe: "Input files to the agent",
|
|
58
|
+
type: "string",
|
|
59
|
+
array: true
|
|
60
|
+
}).option("format", {
|
|
61
|
+
describe: "Input format for the agent (available: text, json, yaml default: text)",
|
|
62
|
+
type: "string",
|
|
63
|
+
choices: [
|
|
64
|
+
"text",
|
|
65
|
+
"json",
|
|
66
|
+
"yaml"
|
|
67
|
+
]
|
|
68
|
+
}).option("output", {
|
|
69
|
+
describe: "Output file to save the result (default: stdout)",
|
|
70
|
+
type: "string",
|
|
71
|
+
alias: "o"
|
|
72
|
+
}).option("output-key", {
|
|
73
|
+
describe: "Key in the result to save to the output file",
|
|
74
|
+
type: "string",
|
|
75
|
+
default: DEFAULT_OUTPUT_KEY
|
|
76
|
+
}).option("force", {
|
|
77
|
+
describe: "Truncate the output file if it exists, and create directory if the output path does not exists",
|
|
78
|
+
type: "boolean",
|
|
79
|
+
default: false
|
|
80
|
+
}).option("log-level", {
|
|
81
|
+
describe: `Log level for detailed debugging information. Values: ${Object.values(LogLevel).join(", ")}`,
|
|
82
|
+
type: "string",
|
|
83
|
+
default: getLevelFromEnv(logger.options.ns) || LogLevel.SILENT,
|
|
84
|
+
coerce: customZodError("--log-level", (s) => z.nativeEnum(LogLevel).parse(s))
|
|
85
|
+
}).option("aigne-hub-url", {
|
|
86
|
+
group: MODEL_OPTIONS_GROUP_NAME,
|
|
87
|
+
describe: "Custom AIGNE Hub service URL. Used to fetch remote agent definitions or models.",
|
|
88
|
+
type: "string"
|
|
89
|
+
});
|
|
90
|
+
function formatModelsName(models) {
|
|
91
|
+
return models.map((i) => {
|
|
92
|
+
if (typeof i.name === "string") return i.name.toLowerCase().replace(/ChatModel$/i, "");
|
|
93
|
+
return i.name.map((n) => n.toLowerCase().replace(/ChatModel$/i, ""));
|
|
94
|
+
}).join(", ");
|
|
95
|
+
}
|
|
96
|
+
function inferZodType(type, opts = {}) {
|
|
97
|
+
if (type instanceof ZodUnknown || type instanceof ZodAny) return {
|
|
98
|
+
type: "string",
|
|
99
|
+
optional: true
|
|
100
|
+
};
|
|
101
|
+
opts.optional ??= type.isNullable() || type.isOptional();
|
|
102
|
+
if ("innerType" in type._def && type._def.innerType instanceof ZodType) return inferZodType(type._def.innerType, opts);
|
|
103
|
+
if (type instanceof ZodArray) return inferZodType(type.element, {
|
|
104
|
+
...opts,
|
|
105
|
+
array: true
|
|
106
|
+
});
|
|
107
|
+
return {
|
|
108
|
+
...opts,
|
|
109
|
+
array: opts.array || void 0,
|
|
110
|
+
optional: opts.optional || void 0,
|
|
111
|
+
type: type instanceof ZodBoolean ? "boolean" : type instanceof ZodNumber ? "number" : "string"
|
|
112
|
+
};
|
|
113
|
+
}
|
|
114
|
+
function withAgentInputSchema(yargs, options) {
|
|
115
|
+
const inputSchema = options.inputSchema instanceof ZodObject ? options.inputSchema.shape : {};
|
|
116
|
+
for (const [option, config] of Object.entries(inputSchema)) {
|
|
117
|
+
const type = inferZodType(config);
|
|
118
|
+
yargs.option(option, {
|
|
119
|
+
group: "Agent Parameters",
|
|
120
|
+
type: type.type,
|
|
121
|
+
description: config.description,
|
|
122
|
+
array: type.array
|
|
123
|
+
});
|
|
124
|
+
if (!type.optional && !options.optionalInputs?.includes(option)) yargs.demandOption(option);
|
|
125
|
+
}
|
|
126
|
+
return withRunAgentCommonOptions(yargs);
|
|
127
|
+
}
|
|
128
|
+
async function parseAgentInput(i, agent) {
|
|
129
|
+
const inputSchema = agent.inputSchema instanceof ZodObject ? agent.inputSchema.shape : {};
|
|
130
|
+
const input = Object.fromEntries(await Promise.all(Object.entries(pick(i, Object.keys(inputSchema))).map(async ([key, val]) => {
|
|
131
|
+
if (typeof val === "string" && val.startsWith("@")) {
|
|
132
|
+
const schema = inputSchema[key];
|
|
133
|
+
val = await readFileAsInput(val, { format: schema instanceof ZodString ? "raw" : void 0 });
|
|
134
|
+
}
|
|
135
|
+
return [key, val];
|
|
136
|
+
})));
|
|
137
|
+
if (agent instanceof AIAgent && agent.inputFileKey) {
|
|
138
|
+
const files = [];
|
|
139
|
+
for (const file of flat(i.inputFile, i[agent.inputFileKey]) ?? []) {
|
|
140
|
+
const raw = await readFile(file.replace(/^@/, ""), "base64");
|
|
141
|
+
const filename = basename(file);
|
|
142
|
+
const mimeType = await ChatModel.getMimeType(filename) || "application/octet-stream";
|
|
143
|
+
files.push({
|
|
144
|
+
type: "file",
|
|
145
|
+
data: raw,
|
|
146
|
+
filename,
|
|
147
|
+
mimeType
|
|
148
|
+
});
|
|
149
|
+
}
|
|
150
|
+
Object.assign(input, { [agent.inputFileKey]: files });
|
|
151
|
+
}
|
|
152
|
+
const rawInput = i.input || (isatty(process.stdin.fd) || !await stdinHasData() ? null : [await readAllString(process.stdin)].filter(Boolean));
|
|
153
|
+
if (rawInput) for (const raw of rawInput) {
|
|
154
|
+
const parsed = raw.startsWith("@") ? await readFileAsInput(raw, { format: i.format }) : raw;
|
|
155
|
+
if (typeof parsed !== "string") Object.assign(input, parsed);
|
|
156
|
+
else {
|
|
157
|
+
const inputKey = agent instanceof AIAgent ? agent.inputKey : void 0;
|
|
158
|
+
if (inputKey) Object.assign(input, { [inputKey]: parsed });
|
|
159
|
+
}
|
|
160
|
+
}
|
|
161
|
+
return input;
|
|
162
|
+
}
|
|
163
|
+
async function readFileAsInput(value, { format: format$1 } = {}) {
|
|
164
|
+
if (value.startsWith("@")) {
|
|
165
|
+
const ext = extname(value);
|
|
166
|
+
value = await readFile(value.slice(1), "utf8");
|
|
167
|
+
if (!format$1) {
|
|
168
|
+
if (ext === ".json") format$1 = "json";
|
|
169
|
+
else if (ext === ".yaml" || ext === ".yml") format$1 = "yaml";
|
|
170
|
+
}
|
|
171
|
+
}
|
|
172
|
+
if (format$1 === "json") return JSON.parse(value);
|
|
173
|
+
else if (format$1 === "yaml") return parse(value);
|
|
174
|
+
return value;
|
|
175
|
+
}
|
|
176
|
+
async function stdinHasData() {
|
|
177
|
+
const stats = await promisify(fstat)(0);
|
|
178
|
+
return stats.isFIFO() || stats.isFile();
|
|
179
|
+
}
|
|
180
|
+
function customZodError(label, fn) {
|
|
181
|
+
return ((...args) => tryOrThrow(() => fn(...args), (e) => /* @__PURE__ */ new Error(`${label} ${e instanceof ZodError ? e.issues[0]?.message : e.message}`)));
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
//#endregion
|
|
185
|
+
export { inferZodType, parseAgentInput, stdinHasData, withAgentInputSchema, withRunAgentCommonOptions };
|
|
186
|
+
//# sourceMappingURL=yargs.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"yargs.mjs","names":["format"],"sources":["../../src/utils/yargs.ts"],"sourcesContent":["import { fstat } from \"node:fs\";\nimport { readFile } from \"node:fs/promises\";\nimport { basename, extname } from \"node:path\";\nimport { isatty } from \"node:tty\";\nimport { promisify } from \"node:util\";\nimport {\n availableImageModels,\n availableModels,\n type LoadableImageModel,\n type LoadableModel,\n} from \"@aigne/aigne-hub\";\nimport {\n type Agent,\n AIAgent,\n ChatModel,\n DEFAULT_OUTPUT_KEY,\n type FileUnionContent,\n type Message,\n readAllString,\n} from \"@aigne/core\";\nimport { getLevelFromEnv, LogLevel, logger } from \"@aigne/core/utils/logger\";\nimport { flat, pick, tryOrThrow } from \"@aigne/core/utils/type-utils\";\nimport { parse } from \"yaml\";\nimport type { Argv } from \"yargs\";\nimport z, {\n ZodAny,\n ZodArray,\n ZodBoolean,\n ZodError,\n ZodNumber,\n ZodObject,\n ZodString,\n ZodType,\n ZodUnknown,\n} from \"zod\";\n\nexport type InferArgv<T> = T extends Argv<infer U> ? U : never;\n\nconst MODEL_OPTIONS_GROUP_NAME = \"Model Options\";\n\nexport const withRunAgentCommonOptions = (yargs: Argv) =>\n yargs\n .option(\"interactive\", {\n describe: \"Run in interactive chat mode\",\n type: \"boolean\",\n default: false,\n alias: [\"chat\"],\n })\n .option(\"session-id\", {\n describe: \"Session ID for chat-based agents to maintain context across interactions\",\n type: \"string\",\n })\n .option(\"model\", {\n group: MODEL_OPTIONS_GROUP_NAME,\n describe: `AI model to use in format 'provider[/model]' where model is optional. Examples: 'openai' or 'openai/gpt-4o-mini'. Available providers: ${formatModelsName(\n availableModels(),\n )} (default: openai)`,\n type: \"string\",\n })\n .option(\"image-model\", {\n group: MODEL_OPTIONS_GROUP_NAME,\n describe: `Image model to use in format 'provider[/model]' where model is optional. Examples: 'openai' or 'openai/gpt-image-1'. Available providers: ${formatModelsName(\n availableImageModels(),\n )} (default: openai)`,\n type: \"string\",\n })\n .option(\"temperature\", {\n group: MODEL_OPTIONS_GROUP_NAME,\n describe:\n \"Temperature for the model (controls randomness, higher values produce more random outputs). Range: 0.0-2.0\",\n type: \"number\",\n coerce: customZodError(\"--temperature\", (s) => z.coerce.number().min(0).max(2).parse(s)),\n })\n .option(\"top-p\", {\n group: MODEL_OPTIONS_GROUP_NAME,\n describe:\n \"Top P (nucleus sampling) parameter for the model (controls diversity). Range: 0.0-1.0\",\n type: \"number\",\n coerce: customZodError(\"--top-p\", (s) => z.coerce.number().min(0).max(1).parse(s)),\n })\n .option(\"presence-penalty\", {\n group: MODEL_OPTIONS_GROUP_NAME,\n describe:\n \"Presence penalty for the model (penalizes repeating the same tokens). Range: -2.0 to 2.0\",\n type: \"number\",\n coerce: customZodError(\"--presence-penalty\", (s) =>\n z.coerce.number().min(-2).max(2).parse(s),\n ),\n })\n .option(\"frequency-penalty\", {\n group: MODEL_OPTIONS_GROUP_NAME,\n describe:\n \"Frequency penalty for the model (penalizes frequency of token usage). Range: -2.0 to 2.0\",\n type: \"number\",\n coerce: customZodError(\"--frequency-penalty\", (s) =>\n z.coerce.number().min(-2).max(2).parse(s),\n ),\n })\n .option(\"input\", {\n describe: \"Input to the agent, use @<file> to read from a file\",\n type: \"string\",\n array: true,\n alias: \"i\",\n })\n .option(\"input-file\", {\n describe: \"Input files to the agent\",\n type: \"string\",\n array: true,\n })\n .option(\"format\", {\n describe: \"Input format for the agent (available: text, json, yaml default: text)\",\n type: \"string\",\n choices: [\"text\", \"json\", \"yaml\"],\n })\n .option(\"output\", {\n describe: \"Output file to save the result (default: stdout)\",\n type: \"string\",\n alias: \"o\",\n })\n .option(\"output-key\", {\n describe: \"Key in the result to save to the output file\",\n type: \"string\",\n default: DEFAULT_OUTPUT_KEY,\n })\n .option(\"force\", {\n describe:\n \"Truncate the output file if it exists, and create directory if the output path does not exists\",\n type: \"boolean\",\n default: false,\n })\n .option(\"log-level\", {\n describe: `Log level for detailed debugging information. Values: ${Object.values(LogLevel).join(\", \")}`,\n type: \"string\",\n default: getLevelFromEnv(logger.options.ns) || LogLevel.SILENT,\n coerce: customZodError(\"--log-level\", (s) => z.nativeEnum(LogLevel).parse(s)),\n })\n .option(\"aigne-hub-url\", {\n group: MODEL_OPTIONS_GROUP_NAME,\n describe: \"Custom AIGNE Hub service URL. Used to fetch remote agent definitions or models.\",\n type: \"string\",\n });\n\nfunction formatModelsName(models: (LoadableModel | LoadableImageModel)[]): string {\n return models\n .map((i) => {\n if (typeof i.name === \"string\") {\n return i.name.toLowerCase().replace(/ChatModel$/i, \"\");\n }\n return i.name.map((n) => n.toLowerCase().replace(/ChatModel$/i, \"\"));\n })\n .join(\", \");\n}\n\ntype _AgentRunCommonOptions = Partial<InferArgv<ReturnType<typeof withAgentInputSchema>>>;\n\n/** Convert literal string types like 'foo-bar' to 'FooBar' */\ntype PascalCase<S extends string> = string extends S\n ? string\n : S extends `${infer T}-${infer U}`\n ? `${Capitalize<T>}${PascalCase<U>}`\n : Capitalize<S>;\n\n/** Convert literal string types like 'foo-bar' to 'fooBar' */\ntype CamelCase<S extends string> = string extends S\n ? string\n : S extends `${infer T}-${infer U}`\n ? `${T}${PascalCase<U>}`\n : S;\n\n/** Convert literal string types like 'foo-bar' to 'fooBar', allowing all `PropertyKey` types */\ntype CamelCaseKey<K extends PropertyKey> = K extends string ? Exclude<CamelCase<K>, \"\"> : K;\n\nexport type AgentRunCommonOptions = {\n [key in keyof _AgentRunCommonOptions as CamelCaseKey<key>]: _AgentRunCommonOptions[key];\n};\n\nexport function inferZodType(\n type: ZodType,\n opts: { array?: boolean; optional?: boolean } = {},\n): {\n type: \"string\" | \"number\" | \"boolean\";\n array?: boolean;\n optional?: boolean;\n} {\n if (type instanceof ZodUnknown || type instanceof ZodAny) {\n return { type: \"string\", optional: true };\n }\n\n opts.optional ??= type.isNullable() || type.isOptional();\n\n if (\"innerType\" in type._def && type._def.innerType instanceof ZodType) {\n return inferZodType(type._def.innerType, opts);\n }\n\n if (type instanceof ZodArray) {\n return inferZodType(type.element, { ...opts, array: true });\n }\n\n return {\n ...opts,\n array: opts.array || undefined,\n optional: opts.optional || undefined,\n type: type instanceof ZodBoolean ? \"boolean\" : type instanceof ZodNumber ? \"number\" : \"string\",\n };\n}\n\nexport function withAgentInputSchema(\n yargs: Argv,\n options: Pick<Agent, \"inputSchema\"> & { optionalInputs?: string[] },\n) {\n const inputSchema: { [key: string]: ZodType } =\n options.inputSchema instanceof ZodObject ? options.inputSchema.shape : {};\n\n for (const [option, config] of Object.entries(inputSchema)) {\n const type = inferZodType(config);\n\n yargs.option(option, {\n group: \"Agent Parameters\",\n type: type.type,\n description: config.description,\n array: type.array,\n });\n\n if (!type.optional && !options.optionalInputs?.includes(option)) {\n yargs.demandOption(option);\n }\n }\n\n return withRunAgentCommonOptions(yargs);\n}\n\nexport async function parseAgentInput(i: Message & AgentRunCommonOptions, agent: Agent) {\n const inputSchema: { [key: string]: ZodType } =\n agent.inputSchema instanceof ZodObject ? agent.inputSchema.shape : {};\n\n const input = Object.fromEntries(\n await Promise.all(\n Object.entries(pick(i, Object.keys(inputSchema))).map(async ([key, val]) => {\n if (typeof val === \"string\" && val.startsWith(\"@\")) {\n const schema = inputSchema[key];\n\n val = await readFileAsInput(val, {\n format: schema instanceof ZodString ? \"raw\" : undefined,\n });\n }\n\n return [key, val];\n }),\n ),\n );\n\n if (agent instanceof AIAgent && agent.inputFileKey) {\n const files: FileUnionContent[] = [];\n for (const file of flat(i.inputFile, i[agent.inputFileKey] as string[]) ?? []) {\n const raw = await readFile(file.replace(/^@/, \"\"), \"base64\");\n const filename = basename(file);\n const mimeType = (await ChatModel.getMimeType(filename)) || \"application/octet-stream\";\n files.push({ type: \"file\", data: raw, filename, mimeType });\n }\n\n Object.assign(input, { [agent.inputFileKey]: files });\n }\n\n const rawInput =\n i.input ||\n (isatty(process.stdin.fd) || !(await stdinHasData())\n ? null\n : [await readAllString(process.stdin)].filter(Boolean));\n\n if (rawInput) {\n for (const raw of rawInput) {\n const parsed = raw.startsWith(\"@\") ? await readFileAsInput(raw, { format: i.format }) : raw;\n\n if (typeof parsed !== \"string\") {\n Object.assign(input, parsed);\n } else {\n const inputKey = agent instanceof AIAgent ? agent.inputKey : undefined;\n if (inputKey) {\n Object.assign(input, { [inputKey]: parsed });\n }\n }\n }\n }\n\n return input;\n}\n\nasync function readFileAsInput(\n value: string,\n { format }: { format?: \"raw\" | \"json\" | \"yaml\" | string } = {},\n): Promise<unknown> {\n if (value.startsWith(\"@\")) {\n const ext = extname(value);\n\n value = await readFile(value.slice(1), \"utf8\");\n\n if (!format) {\n if (ext === \".json\") format = \"json\";\n else if (ext === \".yaml\" || ext === \".yml\") format = \"yaml\";\n }\n }\n\n if (format === \"json\") {\n return JSON.parse(value);\n } else if (format === \"yaml\") {\n return parse(value);\n }\n\n return value;\n}\n\nexport async function stdinHasData(): Promise<boolean> {\n const stats = await promisify(fstat)(0);\n return stats.isFIFO() || stats.isFile();\n}\n\nfunction customZodError<T extends (...args: unknown[]) => unknown>(label: string, fn: T): T {\n return ((...args: Parameters<T>) =>\n tryOrThrow(\n () => fn(...args),\n (e) => new Error(`${label} ${e instanceof ZodError ? e.issues[0]?.message : e.message}`),\n )) as T;\n}\n"],"mappings":";;;;;;;;;;;;;AAsCA,MAAM,2BAA2B;AAEjC,MAAa,6BAA6B,UACxC,MACG,OAAO,eAAe;CACrB,UAAU;CACV,MAAM;CACN,SAAS;CACT,OAAO,CAAC,OAAO;CAChB,CAAC,CACD,OAAO,cAAc;CACpB,UAAU;CACV,MAAM;CACP,CAAC,CACD,OAAO,SAAS;CACf,OAAO;CACP,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