@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,46 @@
|
|
|
1
|
+
import chalk from "chalk";
|
|
2
|
+
import { tryOrThrow } from "@aigne/core/utils/type-utils";
|
|
3
|
+
import { startObservabilityCLIServer } from "@aigne/observability-api/cli";
|
|
4
|
+
import getObservabilityDbPath from "@aigne/observability-api/db-path";
|
|
5
|
+
import detectPort from "detect-port";
|
|
6
|
+
|
|
7
|
+
//#region src/commands/observe.ts
|
|
8
|
+
const DEFAULT_PORT = () => tryOrThrow(() => {
|
|
9
|
+
const { PORT } = process.env;
|
|
10
|
+
if (!PORT) return 7890;
|
|
11
|
+
const port = Number.parseInt(PORT, 10);
|
|
12
|
+
if (!port || !Number.isInteger(port)) throw new Error(`Invalid PORT: ${PORT}`);
|
|
13
|
+
return port;
|
|
14
|
+
}, (error) => /* @__PURE__ */ new Error(`parse PORT error ${error.message}`));
|
|
15
|
+
function createObservabilityCommand() {
|
|
16
|
+
return {
|
|
17
|
+
command: "observe",
|
|
18
|
+
describe: "Start the observability server",
|
|
19
|
+
builder: (yargs) => {
|
|
20
|
+
return yargs.option("host", {
|
|
21
|
+
type: "string",
|
|
22
|
+
describe: "Host to run the observability server on, use 0.0.0.0 to publicly expose the server",
|
|
23
|
+
default: "localhost"
|
|
24
|
+
}).option("port", {
|
|
25
|
+
type: "number",
|
|
26
|
+
describe: "Port to run the observability server on"
|
|
27
|
+
});
|
|
28
|
+
},
|
|
29
|
+
handler: async (options) => {
|
|
30
|
+
const port = await detectPort(options.port || DEFAULT_PORT());
|
|
31
|
+
const dbUrl = getObservabilityDbPath();
|
|
32
|
+
process.once("SIGINT", async () => {
|
|
33
|
+
process.exit(0);
|
|
34
|
+
});
|
|
35
|
+
console.log("Observability database path:", chalk.greenBright(dbUrl));
|
|
36
|
+
await startObservabilityCLIServer({
|
|
37
|
+
port,
|
|
38
|
+
dbUrl
|
|
39
|
+
});
|
|
40
|
+
}
|
|
41
|
+
};
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
//#endregion
|
|
45
|
+
export { createObservabilityCommand };
|
|
46
|
+
//# sourceMappingURL=observe.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"observe.mjs","names":[],"sources":["../../src/commands/observe.ts"],"sourcesContent":["import { tryOrThrow } from \"@aigne/core/utils/type-utils\";\nimport { startObservabilityCLIServer } from \"@aigne/observability-api/cli\";\nimport getObservabilityDbPath from \"@aigne/observability-api/db-path\";\nimport chalk from \"chalk\";\nimport detectPort from \"detect-port\";\nimport type { CommandModule } from \"yargs\";\n\ninterface ServeMCPOptions {\n host: string;\n port?: number;\n}\n\nconst DEFAULT_PORT = () =>\n tryOrThrow(\n () => {\n const { PORT } = process.env;\n if (!PORT) return 7890;\n const port = Number.parseInt(PORT, 10);\n if (!port || !Number.isInteger(port)) throw new Error(`Invalid PORT: ${PORT}`);\n return port;\n },\n (error) => new Error(`parse PORT error ${error.message}`),\n );\n\nexport function createObservabilityCommand(): CommandModule<unknown, ServeMCPOptions> {\n return {\n command: \"observe\",\n describe: \"Start the observability server\",\n builder: (yargs) => {\n return yargs\n .option(\"host\", {\n type: \"string\",\n describe:\n \"Host to run the observability server on, use 0.0.0.0 to publicly expose the server\",\n default: \"localhost\",\n })\n .option(\"port\", {\n type: \"number\",\n describe: \"Port to run the observability server on\",\n });\n },\n handler: async (options) => {\n const port = await detectPort(options.port || DEFAULT_PORT());\n const dbUrl = getObservabilityDbPath();\n\n process.once(\"SIGINT\", async () => {\n process.exit(0);\n });\n\n console.log(\"Observability database path:\", chalk.greenBright(dbUrl));\n await startObservabilityCLIServer({ port, dbUrl });\n },\n };\n}\n"],"mappings":";;;;;;;AAYA,MAAM,qBACJ,iBACQ;CACJ,MAAM,EAAE,SAAS,QAAQ;AACzB,KAAI,CAAC,KAAM,QAAO;CAClB,MAAM,OAAO,OAAO,SAAS,MAAM,GAAG;AACtC,KAAI,CAAC,QAAQ,CAAC,OAAO,UAAU,KAAK,CAAE,OAAM,IAAI,MAAM,iBAAiB,OAAO;AAC9E,QAAO;IAER,0BAAU,IAAI,MAAM,oBAAoB,MAAM,UAAU,CAC1D;AAEH,SAAgB,6BAAsE;AACpF,QAAO;EACL,SAAS;EACT,UAAU;EACV,UAAU,UAAU;AAClB,UAAO,MACJ,OAAO,QAAQ;IACd,MAAM;IACN,UACE;IACF,SAAS;IACV,CAAC,CACD,OAAO,QAAQ;IACd,MAAM;IACN,UAAU;IACX,CAAC;;EAEN,SAAS,OAAO,YAAY;GAC1B,MAAM,OAAO,MAAM,WAAW,QAAQ,QAAQ,cAAc,CAAC;GAC7D,MAAM,QAAQ,wBAAwB;AAEtC,WAAQ,KAAK,UAAU,YAAY;AACjC,YAAQ,KAAK,EAAE;KACf;AAEF,WAAQ,IAAI,gCAAgC,MAAM,YAAY,MAAM,CAAC;AACrE,SAAM,4BAA4B;IAAE;IAAM;IAAO,CAAC;;EAErD"}
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
const require_rolldown_runtime = require('../_virtual/rolldown_runtime.cjs');
|
|
2
|
+
const require_utils_aigne_hub_model = require('../utils/aigne-hub/model.cjs');
|
|
3
|
+
const require_utils_yargs = require('../utils/yargs.cjs');
|
|
4
|
+
const require_agent = require('./app/agent.cjs');
|
|
5
|
+
let node_path = require("node:path");
|
|
6
|
+
let _aigne_core = require("@aigne/core");
|
|
7
|
+
let zod = require("zod");
|
|
8
|
+
let _aigne_afs_history = require("@aigne/afs-history");
|
|
9
|
+
let _aigne_afs_local_fs = require("@aigne/afs-local-fs");
|
|
10
|
+
let _aigne_agent_library_agent_skill_manager = require("@aigne/agent-library/agent-skill-manager");
|
|
11
|
+
_aigne_agent_library_agent_skill_manager = require_rolldown_runtime.__toESM(_aigne_agent_library_agent_skill_manager);
|
|
12
|
+
let _aigne_agent_library_ask_user_question = require("@aigne/agent-library/ask-user-question");
|
|
13
|
+
_aigne_agent_library_ask_user_question = require_rolldown_runtime.__toESM(_aigne_agent_library_ask_user_question);
|
|
14
|
+
let _aigne_agent_library_bash = require("@aigne/agent-library/bash");
|
|
15
|
+
_aigne_agent_library_bash = require_rolldown_runtime.__toESM(_aigne_agent_library_bash);
|
|
16
|
+
|
|
17
|
+
//#region src/commands/run-skill.ts
|
|
18
|
+
function createRunSkillCommand() {
|
|
19
|
+
return {
|
|
20
|
+
command: ["run-skill"],
|
|
21
|
+
describe: "Run Agent Skill for the specified path",
|
|
22
|
+
builder: async (yargs) => {
|
|
23
|
+
return require_utils_yargs.withAgentInputSchema(yargs.option("skill", {
|
|
24
|
+
array: true,
|
|
25
|
+
type: "string",
|
|
26
|
+
describe: "Path to the Agent Skill directory"
|
|
27
|
+
}).option("interactive", {
|
|
28
|
+
describe: "Run in interactive chat mode",
|
|
29
|
+
type: "boolean",
|
|
30
|
+
default: false,
|
|
31
|
+
alias: ["chat"]
|
|
32
|
+
}).demandOption("skill"), {
|
|
33
|
+
inputSchema: zod.z.object({ message: zod.z.string() }),
|
|
34
|
+
optionalInputs: ["message"]
|
|
35
|
+
});
|
|
36
|
+
},
|
|
37
|
+
handler: async (options) => {
|
|
38
|
+
if (!Array.isArray(options.skill) || options.skill.length === 0) throw new Error("At least one skill path must be provided.");
|
|
39
|
+
const aigne = new _aigne_core.AIGNE({ model: await require_utils_aigne_hub_model.loadChatModel({ model: options.model || "aignehub/anthropic/claude-sonnet-4-5" }) });
|
|
40
|
+
const approvedCmds = /* @__PURE__ */ new Set();
|
|
41
|
+
await require_agent.invokeAgent({
|
|
42
|
+
aigne,
|
|
43
|
+
agent: new _aigne_agent_library_agent_skill_manager.default({
|
|
44
|
+
inputKey: "message",
|
|
45
|
+
taskRenderMode: "collapse",
|
|
46
|
+
skills: [new _aigne_agent_library_bash.default({
|
|
47
|
+
sandbox: false,
|
|
48
|
+
permissions: {
|
|
49
|
+
defaultMode: "ask",
|
|
50
|
+
guard: _aigne_core.FunctionAgent.from(async (input, options$1) => {
|
|
51
|
+
if (approvedCmds.has(input.script || "")) return { approved: true };
|
|
52
|
+
const confirm = options$1.prompts?.confirm;
|
|
53
|
+
if (!confirm) throw new Error("No confirm prompt available for permission guard.");
|
|
54
|
+
const approved = await confirm({ message: `Run command ${input.script}?` });
|
|
55
|
+
if (approved && input.script) approvedCmds.add(input.script);
|
|
56
|
+
return { approved };
|
|
57
|
+
})
|
|
58
|
+
}
|
|
59
|
+
}), new _aigne_agent_library_ask_user_question.default()],
|
|
60
|
+
afs: { modules: [
|
|
61
|
+
new _aigne_afs_history.AFSHistory({}),
|
|
62
|
+
new _aigne_afs_local_fs.LocalFS({
|
|
63
|
+
name: "workspace",
|
|
64
|
+
localPath: process.cwd(),
|
|
65
|
+
description: `\
|
|
66
|
+
Current working directory. All temporary files should be written here using absolute AFS paths (e.g., /modules/workspace/temp.py).
|
|
67
|
+
Note: Bash is already running in this directory, so do NOT use 'cd /modules/workspace' in scripts. Use relative paths directly (e.g., python temp.py).`
|
|
68
|
+
}),
|
|
69
|
+
...options.skill.map((path) => new _aigne_afs_local_fs.LocalFS({
|
|
70
|
+
name: (0, node_path.basename)((0, node_path.resolve)(path)),
|
|
71
|
+
localPath: path,
|
|
72
|
+
description: "Contains Agent Skills. Use 'Skill' tool to invoke skills from this module.",
|
|
73
|
+
agentSkills: true
|
|
74
|
+
}))
|
|
75
|
+
] }
|
|
76
|
+
}),
|
|
77
|
+
input: { ...options }
|
|
78
|
+
});
|
|
79
|
+
}
|
|
80
|
+
};
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
//#endregion
|
|
84
|
+
exports.createRunSkillCommand = createRunSkillCommand;
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
import { loadChatModel } from "../utils/aigne-hub/model.mjs";
|
|
2
|
+
import { withAgentInputSchema } from "../utils/yargs.mjs";
|
|
3
|
+
import { invokeAgent } from "./app/agent.mjs";
|
|
4
|
+
import { basename, resolve } from "node:path";
|
|
5
|
+
import { AIGNE, FunctionAgent } from "@aigne/core";
|
|
6
|
+
import { z as z$1 } from "zod";
|
|
7
|
+
import { AFSHistory } from "@aigne/afs-history";
|
|
8
|
+
import { LocalFS } from "@aigne/afs-local-fs";
|
|
9
|
+
import AgentSkillManager from "@aigne/agent-library/agent-skill-manager";
|
|
10
|
+
import AskUserQuestion from "@aigne/agent-library/ask-user-question";
|
|
11
|
+
import BashAgent from "@aigne/agent-library/bash";
|
|
12
|
+
|
|
13
|
+
//#region src/commands/run-skill.ts
|
|
14
|
+
function createRunSkillCommand() {
|
|
15
|
+
return {
|
|
16
|
+
command: ["run-skill"],
|
|
17
|
+
describe: "Run Agent Skill for the specified path",
|
|
18
|
+
builder: async (yargs) => {
|
|
19
|
+
return withAgentInputSchema(yargs.option("skill", {
|
|
20
|
+
array: true,
|
|
21
|
+
type: "string",
|
|
22
|
+
describe: "Path to the Agent Skill directory"
|
|
23
|
+
}).option("interactive", {
|
|
24
|
+
describe: "Run in interactive chat mode",
|
|
25
|
+
type: "boolean",
|
|
26
|
+
default: false,
|
|
27
|
+
alias: ["chat"]
|
|
28
|
+
}).demandOption("skill"), {
|
|
29
|
+
inputSchema: z$1.object({ message: z$1.string() }),
|
|
30
|
+
optionalInputs: ["message"]
|
|
31
|
+
});
|
|
32
|
+
},
|
|
33
|
+
handler: async (options) => {
|
|
34
|
+
if (!Array.isArray(options.skill) || options.skill.length === 0) throw new Error("At least one skill path must be provided.");
|
|
35
|
+
const aigne = new AIGNE({ model: await loadChatModel({ model: options.model || "aignehub/anthropic/claude-sonnet-4-5" }) });
|
|
36
|
+
const approvedCmds = /* @__PURE__ */ new Set();
|
|
37
|
+
await invokeAgent({
|
|
38
|
+
aigne,
|
|
39
|
+
agent: new AgentSkillManager({
|
|
40
|
+
inputKey: "message",
|
|
41
|
+
taskRenderMode: "collapse",
|
|
42
|
+
skills: [new BashAgent({
|
|
43
|
+
sandbox: false,
|
|
44
|
+
permissions: {
|
|
45
|
+
defaultMode: "ask",
|
|
46
|
+
guard: FunctionAgent.from(async (input, options$1) => {
|
|
47
|
+
if (approvedCmds.has(input.script || "")) return { approved: true };
|
|
48
|
+
const confirm = options$1.prompts?.confirm;
|
|
49
|
+
if (!confirm) throw new Error("No confirm prompt available for permission guard.");
|
|
50
|
+
const approved = await confirm({ message: `Run command ${input.script}?` });
|
|
51
|
+
if (approved && input.script) approvedCmds.add(input.script);
|
|
52
|
+
return { approved };
|
|
53
|
+
})
|
|
54
|
+
}
|
|
55
|
+
}), new AskUserQuestion()],
|
|
56
|
+
afs: { modules: [
|
|
57
|
+
new AFSHistory({}),
|
|
58
|
+
new LocalFS({
|
|
59
|
+
name: "workspace",
|
|
60
|
+
localPath: process.cwd(),
|
|
61
|
+
description: `\
|
|
62
|
+
Current working directory. All temporary files should be written here using absolute AFS paths (e.g., /modules/workspace/temp.py).
|
|
63
|
+
Note: Bash is already running in this directory, so do NOT use 'cd /modules/workspace' in scripts. Use relative paths directly (e.g., python temp.py).`
|
|
64
|
+
}),
|
|
65
|
+
...options.skill.map((path$1) => new LocalFS({
|
|
66
|
+
name: basename(resolve(path$1)),
|
|
67
|
+
localPath: path$1,
|
|
68
|
+
description: "Contains Agent Skills. Use 'Skill' tool to invoke skills from this module.",
|
|
69
|
+
agentSkills: true
|
|
70
|
+
}))
|
|
71
|
+
] }
|
|
72
|
+
}),
|
|
73
|
+
input: { ...options }
|
|
74
|
+
});
|
|
75
|
+
}
|
|
76
|
+
};
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
//#endregion
|
|
80
|
+
export { createRunSkillCommand };
|
|
81
|
+
//# sourceMappingURL=run-skill.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"run-skill.mjs","names":["z","options","path"],"sources":["../../src/commands/run-skill.ts"],"sourcesContent":["import { basename, resolve } from \"node:path\";\nimport { AFSHistory } from \"@aigne/afs-history\";\nimport { LocalFS } from \"@aigne/afs-local-fs\";\nimport AgentSkillManager from \"@aigne/agent-library/agent-skill-manager\";\nimport AskUserQuestion from \"@aigne/agent-library/ask-user-question\";\nimport BashAgent from \"@aigne/agent-library/bash\";\nimport { AIGNE, FunctionAgent } from \"@aigne/core\";\nimport type { CommandModule } from \"yargs\";\nimport { z } from \"zod\";\nimport { loadChatModel } from \"../utils/aigne-hub/model.js\";\nimport { type AgentRunCommonOptions, withAgentInputSchema } from \"../utils/yargs.js\";\nimport { invokeAgent } from \"./app/agent.js\";\n\nexport function createRunSkillCommand(): CommandModule<\n unknown,\n { skill?: string[]; interactive?: boolean } & AgentRunCommonOptions\n> {\n return {\n command: [\"run-skill\"],\n describe: \"Run Agent Skill for the specified path\",\n builder: async (yargs) => {\n return withAgentInputSchema(\n yargs\n .option(\"skill\", {\n array: true,\n type: \"string\",\n describe: \"Path to the Agent Skill directory\",\n })\n .option(\"interactive\", {\n describe: \"Run in interactive chat mode\",\n type: \"boolean\",\n default: false,\n alias: [\"chat\"],\n })\n .demandOption(\"skill\"),\n {\n inputSchema: z.object({\n message: z.string(),\n }),\n optionalInputs: [\"message\"],\n },\n );\n },\n handler: async (options) => {\n if (!Array.isArray(options.skill) || options.skill.length === 0) {\n throw new Error(\"At least one skill path must be provided.\");\n }\n\n const model = await loadChatModel({\n model: options.model || \"aignehub/anthropic/claude-sonnet-4-5\",\n });\n\n const aigne = new AIGNE({ model });\n\n const approvedCmds = new Set<string>();\n\n const agent = new AgentSkillManager({\n inputKey: \"message\",\n taskRenderMode: \"collapse\",\n skills: [\n new BashAgent({\n sandbox: false,\n permissions: {\n defaultMode: \"ask\",\n guard: FunctionAgent.from(async (input, options) => {\n if (approvedCmds.has(input.script || \"\")) {\n return {\n approved: true,\n };\n }\n\n const confirm = options.prompts?.confirm;\n if (!confirm) throw new Error(\"No confirm prompt available for permission guard.\");\n\n const approved = await confirm({ message: `Run command ${input.script}?` });\n\n if (approved && input.script) {\n approvedCmds.add(input.script);\n }\n\n return {\n approved,\n };\n }),\n },\n }),\n new AskUserQuestion(),\n ],\n afs: {\n modules: [\n new AFSHistory({}),\n new LocalFS({\n name: \"workspace\",\n localPath: process.cwd(),\n description: `\\\nCurrent working directory. All temporary files should be written here using absolute AFS paths (e.g., /modules/workspace/temp.py).\nNote: Bash is already running in this directory, so do NOT use 'cd /modules/workspace' in scripts. Use relative paths directly (e.g., python temp.py).`,\n }),\n ...options.skill.map(\n (path) =>\n new LocalFS({\n name: basename(resolve(path)),\n localPath: path,\n description:\n \"Contains Agent Skills. Use 'Skill' tool to invoke skills from this module.\",\n agentSkills: true,\n }),\n ),\n ],\n },\n });\n\n await invokeAgent({\n aigne,\n agent,\n input: {\n ...options,\n },\n });\n },\n };\n}\n"],"mappings":";;;;;;;;;;;;;AAaA,SAAgB,wBAGd;AACA,QAAO;EACL,SAAS,CAAC,YAAY;EACtB,UAAU;EACV,SAAS,OAAO,UAAU;AACxB,UAAO,qBACL,MACG,OAAO,SAAS;IACf,OAAO;IACP,MAAM;IACN,UAAU;IACX,CAAC,CACD,OAAO,eAAe;IACrB,UAAU;IACV,MAAM;IACN,SAAS;IACT,OAAO,CAAC,OAAO;IAChB,CAAC,CACD,aAAa,QAAQ,EACxB;IACE,aAAaA,IAAE,OAAO,EACpB,SAASA,IAAE,QAAQ,EACpB,CAAC;IACF,gBAAgB,CAAC,UAAU;IAC5B,CACF;;EAEH,SAAS,OAAO,YAAY;AAC1B,OAAI,CAAC,MAAM,QAAQ,QAAQ,MAAM,IAAI,QAAQ,MAAM,WAAW,EAC5D,OAAM,IAAI,MAAM,4CAA4C;GAO9D,MAAM,QAAQ,IAAI,MAAM,EAAE,OAJZ,MAAM,cAAc,EAChC,OAAO,QAAQ,SAAS,wCACzB,CAAC,EAE+B,CAAC;GAElC,MAAM,+BAAe,IAAI,KAAa;AA0DtC,SAAM,YAAY;IAChB;IACA,OA1DY,IAAI,kBAAkB;KAClC,UAAU;KACV,gBAAgB;KAChB,QAAQ,CACN,IAAI,UAAU;MACZ,SAAS;MACT,aAAa;OACX,aAAa;OACb,OAAO,cAAc,KAAK,OAAO,OAAO,cAAY;AAClD,YAAI,aAAa,IAAI,MAAM,UAAU,GAAG,CACtC,QAAO,EACL,UAAU,MACX;QAGH,MAAM,UAAUC,UAAQ,SAAS;AACjC,YAAI,CAAC,QAAS,OAAM,IAAI,MAAM,oDAAoD;QAElF,MAAM,WAAW,MAAM,QAAQ,EAAE,SAAS,eAAe,MAAM,OAAO,IAAI,CAAC;AAE3E,YAAI,YAAY,MAAM,OACpB,cAAa,IAAI,MAAM,OAAO;AAGhC,eAAO,EACL,UACD;SACD;OACH;MACF,CAAC,EACF,IAAI,iBAAiB,CACtB;KACD,KAAK,EACH,SAAS;MACP,IAAI,WAAW,EAAE,CAAC;MAClB,IAAI,QAAQ;OACV,MAAM;OACN,WAAW,QAAQ,KAAK;OACxB,aAAa;;;OAGd,CAAC;MACF,GAAG,QAAQ,MAAM,KACd,WACC,IAAI,QAAQ;OACV,MAAM,SAAS,QAAQC,OAAK,CAAC;OAC7B,WAAWA;OACX,aACE;OACF,aAAa;OACd,CAAC,CACL;MACF,EACF;KACF,CAAC;IAKA,OAAO,EACL,GAAG,SACJ;IACF,CAAC;;EAEL"}
|
|
@@ -0,0 +1,172 @@
|
|
|
1
|
+
const require_rolldown_runtime = require('../_virtual/rolldown_runtime.cjs');
|
|
2
|
+
const require_constants = require('../constants.cjs');
|
|
3
|
+
const require_utils_download = require('../utils/download.cjs');
|
|
4
|
+
const require_utils_load_aigne = require('../utils/load-aigne.cjs');
|
|
5
|
+
const require_utils_agent_v1 = require('../utils/agent-v1.cjs');
|
|
6
|
+
const require_utils_url = require('../utils/url.cjs');
|
|
7
|
+
const require_utils_yargs = require('../utils/yargs.cjs');
|
|
8
|
+
const require_agent = require('./app/agent.cjs');
|
|
9
|
+
let _aigne_core_utils_logger = require("@aigne/core/utils/logger");
|
|
10
|
+
let dotenv_flow = require("dotenv-flow");
|
|
11
|
+
let yargs = require("yargs");
|
|
12
|
+
yargs = require_rolldown_runtime.__toESM(yargs);
|
|
13
|
+
let node_path = require("node:path");
|
|
14
|
+
let node_fs_promises = require("node:fs/promises");
|
|
15
|
+
let _aigne_listr2 = require("@aigne/listr2");
|
|
16
|
+
let _aigne_core_utils_type_utils = require("@aigne/core/utils/type-utils");
|
|
17
|
+
let node_os = require("node:os");
|
|
18
|
+
let _aigne_agent_library_utils_fs = require("@aigne/agent-library/utils/fs");
|
|
19
|
+
let _aigne_core_loader = require("@aigne/core/loader");
|
|
20
|
+
|
|
21
|
+
//#region src/commands/run.ts
|
|
22
|
+
let yargsInstance = null;
|
|
23
|
+
function createRunCommand({ aigneFilePath } = {}) {
|
|
24
|
+
return {
|
|
25
|
+
command: ["run [path] [entry-agent]", "$0"],
|
|
26
|
+
describe: "Run AIGNE for the specified path",
|
|
27
|
+
builder: async (yargs$2) => {
|
|
28
|
+
yargsInstance = yargs$2;
|
|
29
|
+
return yargs$2.positional("path", {
|
|
30
|
+
type: "string",
|
|
31
|
+
describe: "Path to the agents directory or URL to an aigne project",
|
|
32
|
+
default: "."
|
|
33
|
+
}).positional("entry-agent", {
|
|
34
|
+
type: "string",
|
|
35
|
+
describe: "Name of the agent to run (defaults to the entry agent if not specified)"
|
|
36
|
+
}).option("version", {
|
|
37
|
+
type: "boolean",
|
|
38
|
+
alias: "v",
|
|
39
|
+
describe: "Show version number"
|
|
40
|
+
}).option("interactive", {
|
|
41
|
+
describe: "Run in interactive chat mode",
|
|
42
|
+
type: "boolean",
|
|
43
|
+
default: false,
|
|
44
|
+
alias: ["chat"]
|
|
45
|
+
}).help(false).version(false).strict(false);
|
|
46
|
+
},
|
|
47
|
+
handler: async (options) => {
|
|
48
|
+
if (options.version) {
|
|
49
|
+
console.log(require_constants.AIGNE_CLI_VERSION);
|
|
50
|
+
process.exit(0);
|
|
51
|
+
return;
|
|
52
|
+
}
|
|
53
|
+
if (!options.entryAgent && options.path) {
|
|
54
|
+
if (!await (0, _aigne_agent_library_utils_fs.exists)(options.path) && !require_utils_url.isUrl(options.path)) {
|
|
55
|
+
options.entryAgent = options.path;
|
|
56
|
+
options.path = void 0;
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
const path = aigneFilePath || options.path || ".";
|
|
60
|
+
if (!require_utils_url.isUrl(path) && !await (0, _aigne_core_loader.findAIGNEFile)(path).catch((error) => {
|
|
61
|
+
if (options._[0] !== "run") yargsInstance?.showHelp();
|
|
62
|
+
else throw error;
|
|
63
|
+
return false;
|
|
64
|
+
})) return;
|
|
65
|
+
const opts = require_utils_yargs.withRunAgentCommonOptions((0, yargs.default)(process.argv).help(false).version(false).strict(false)).parseSync();
|
|
66
|
+
_aigne_core_utils_logger.logger.level = opts.logLevel;
|
|
67
|
+
const { aigne } = await loadApplication(path, {
|
|
68
|
+
modelOptions: (0, _aigne_core_utils_type_utils.pick)(opts, require_constants.CHAT_MODEL_OPTIONS),
|
|
69
|
+
imageModelOptions: { model: opts.imageModel }
|
|
70
|
+
});
|
|
71
|
+
const subYargs = (0, yargs.default)().scriptName("").usage("aigne run <path> <agent> [...options]");
|
|
72
|
+
if (aigne.cli.chat) subYargs.command({
|
|
73
|
+
...require_agent.agentCommandModule({
|
|
74
|
+
aigne,
|
|
75
|
+
agent: aigne.cli.chat,
|
|
76
|
+
interactive: true
|
|
77
|
+
}),
|
|
78
|
+
command: "$0"
|
|
79
|
+
});
|
|
80
|
+
const allAgents = (0, _aigne_core_utils_type_utils.flat)(aigne.agents, aigne.skills, aigne.cli.chat, aigne.mcpServer.agents);
|
|
81
|
+
for (const agent of allAgents) subYargs.command(require_agent.agentCommandModule({
|
|
82
|
+
aigne,
|
|
83
|
+
agent,
|
|
84
|
+
interactive: options.interactive
|
|
85
|
+
}));
|
|
86
|
+
for (const cliAgent of aigne.cli.agents ?? []) subYargs.command(require_agent.cliAgentCommandModule({
|
|
87
|
+
aigne,
|
|
88
|
+
cliAgent
|
|
89
|
+
}));
|
|
90
|
+
const argv = process.argv.slice(aigneFilePath ? 3 : 2);
|
|
91
|
+
if (argv[0] === "run") argv.shift();
|
|
92
|
+
if (argv[0] === "--path" || argv[0] === "--url") argv.shift();
|
|
93
|
+
if (argv[0] === options.path) argv.shift();
|
|
94
|
+
if (argv[0] === "--entry-agent") argv.shift();
|
|
95
|
+
const firstAgent = aigne.agents[0]?.name;
|
|
96
|
+
if (!options.entryAgent && firstAgent && !argv.some((i) => ["-h", "--help"].includes(i))) argv.unshift(firstAgent);
|
|
97
|
+
await subYargs.strict().demandCommand().alias("h", "help").alias("v", "version").fail((message, error, yargs$2) => {
|
|
98
|
+
if (!error) {
|
|
99
|
+
yargs$2.showHelp();
|
|
100
|
+
console.error(`\n${message}`);
|
|
101
|
+
process.exit(1);
|
|
102
|
+
}
|
|
103
|
+
}).parseAsync(argv);
|
|
104
|
+
}
|
|
105
|
+
};
|
|
106
|
+
}
|
|
107
|
+
async function loadApplication(path, options = {}) {
|
|
108
|
+
const { cacheDir, dir } = prepareDirs(path);
|
|
109
|
+
if (cacheDir) await new _aigne_listr2.Listr([{
|
|
110
|
+
title: "Download package",
|
|
111
|
+
task: () => downloadPackage(path, cacheDir)
|
|
112
|
+
}, {
|
|
113
|
+
title: "Extract package",
|
|
114
|
+
task: () => extractPackage(cacheDir, dir)
|
|
115
|
+
}], { rendererOptions: {
|
|
116
|
+
collapseSubtasks: false,
|
|
117
|
+
showErrorMessage: false,
|
|
118
|
+
timer: _aigne_listr2.PRESET_TIMER
|
|
119
|
+
} }).run();
|
|
120
|
+
(0, dotenv_flow.config)({
|
|
121
|
+
path: dir,
|
|
122
|
+
silent: true
|
|
123
|
+
});
|
|
124
|
+
return {
|
|
125
|
+
aigne: await require_utils_load_aigne.loadAIGNE({
|
|
126
|
+
...options,
|
|
127
|
+
path: dir
|
|
128
|
+
}),
|
|
129
|
+
path: dir
|
|
130
|
+
};
|
|
131
|
+
}
|
|
132
|
+
async function downloadPackage(url, cacheDir) {
|
|
133
|
+
await (0, node_fs_promises.rm)(cacheDir, {
|
|
134
|
+
recursive: true,
|
|
135
|
+
force: true
|
|
136
|
+
});
|
|
137
|
+
await (0, node_fs_promises.mkdir)(cacheDir, { recursive: true });
|
|
138
|
+
await require_utils_download.downloadAndExtract(url, cacheDir);
|
|
139
|
+
}
|
|
140
|
+
async function extractPackage(cacheDir, dir) {
|
|
141
|
+
await (0, node_fs_promises.mkdir)(dir, { recursive: true });
|
|
142
|
+
if (await require_utils_agent_v1.isV1Package(cacheDir)) await require_utils_agent_v1.toAIGNEPackage(cacheDir, dir);
|
|
143
|
+
else await (0, node_fs_promises.cp)(cacheDir, dir, {
|
|
144
|
+
recursive: true,
|
|
145
|
+
force: true
|
|
146
|
+
});
|
|
147
|
+
}
|
|
148
|
+
function prepareDirs(path) {
|
|
149
|
+
let dir;
|
|
150
|
+
let cacheDir;
|
|
151
|
+
if (!path.startsWith("http")) dir = (0, node_path.isAbsolute)(path) ? path : (0, node_path.resolve)(process.cwd(), path);
|
|
152
|
+
else {
|
|
153
|
+
dir = getLocalPackagePathFromUrl(path);
|
|
154
|
+
cacheDir = getLocalPackagePathFromUrl(path, { subdir: ".download" });
|
|
155
|
+
}
|
|
156
|
+
return {
|
|
157
|
+
cacheDir,
|
|
158
|
+
dir
|
|
159
|
+
};
|
|
160
|
+
}
|
|
161
|
+
function getLocalPackagePathFromUrl(url, { subdir } = {}) {
|
|
162
|
+
const root = [
|
|
163
|
+
(0, node_os.homedir)(),
|
|
164
|
+
".aigne",
|
|
165
|
+
subdir
|
|
166
|
+
].filter(_aigne_core_utils_type_utils.isNonNullable);
|
|
167
|
+
const u = new URL(url);
|
|
168
|
+
return (0, node_path.join)(...root, u.hostname, u.pathname);
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
//#endregion
|
|
172
|
+
exports.createRunCommand = createRunCommand;
|
|
@@ -0,0 +1,171 @@
|
|
|
1
|
+
import { AIGNE_CLI_VERSION, CHAT_MODEL_OPTIONS } from "../constants.mjs";
|
|
2
|
+
import { downloadAndExtract } from "../utils/download.mjs";
|
|
3
|
+
import { loadAIGNE } from "../utils/load-aigne.mjs";
|
|
4
|
+
import { isV1Package, toAIGNEPackage } from "../utils/agent-v1.mjs";
|
|
5
|
+
import { isUrl } from "../utils/url.mjs";
|
|
6
|
+
import { withRunAgentCommonOptions } from "../utils/yargs.mjs";
|
|
7
|
+
import { agentCommandModule, cliAgentCommandModule } from "./app/agent.mjs";
|
|
8
|
+
import { logger } from "@aigne/core/utils/logger";
|
|
9
|
+
import { config } from "dotenv-flow";
|
|
10
|
+
import yargs from "yargs";
|
|
11
|
+
import { isAbsolute, join, resolve } from "node:path";
|
|
12
|
+
import { cp, mkdir, rm } from "node:fs/promises";
|
|
13
|
+
import { Listr, PRESET_TIMER } from "@aigne/listr2";
|
|
14
|
+
import { flat, isNonNullable, pick } from "@aigne/core/utils/type-utils";
|
|
15
|
+
import { homedir } from "node:os";
|
|
16
|
+
import { exists } from "@aigne/agent-library/utils/fs";
|
|
17
|
+
import { findAIGNEFile } from "@aigne/core/loader";
|
|
18
|
+
|
|
19
|
+
//#region src/commands/run.ts
|
|
20
|
+
let yargsInstance = null;
|
|
21
|
+
function createRunCommand({ aigneFilePath } = {}) {
|
|
22
|
+
return {
|
|
23
|
+
command: ["run [path] [entry-agent]", "$0"],
|
|
24
|
+
describe: "Run AIGNE for the specified path",
|
|
25
|
+
builder: async (yargs$1) => {
|
|
26
|
+
yargsInstance = yargs$1;
|
|
27
|
+
return yargs$1.positional("path", {
|
|
28
|
+
type: "string",
|
|
29
|
+
describe: "Path to the agents directory or URL to an aigne project",
|
|
30
|
+
default: "."
|
|
31
|
+
}).positional("entry-agent", {
|
|
32
|
+
type: "string",
|
|
33
|
+
describe: "Name of the agent to run (defaults to the entry agent if not specified)"
|
|
34
|
+
}).option("version", {
|
|
35
|
+
type: "boolean",
|
|
36
|
+
alias: "v",
|
|
37
|
+
describe: "Show version number"
|
|
38
|
+
}).option("interactive", {
|
|
39
|
+
describe: "Run in interactive chat mode",
|
|
40
|
+
type: "boolean",
|
|
41
|
+
default: false,
|
|
42
|
+
alias: ["chat"]
|
|
43
|
+
}).help(false).version(false).strict(false);
|
|
44
|
+
},
|
|
45
|
+
handler: async (options) => {
|
|
46
|
+
if (options.version) {
|
|
47
|
+
console.log(AIGNE_CLI_VERSION);
|
|
48
|
+
process.exit(0);
|
|
49
|
+
return;
|
|
50
|
+
}
|
|
51
|
+
if (!options.entryAgent && options.path) {
|
|
52
|
+
if (!await exists(options.path) && !isUrl(options.path)) {
|
|
53
|
+
options.entryAgent = options.path;
|
|
54
|
+
options.path = void 0;
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
const path$1 = aigneFilePath || options.path || ".";
|
|
58
|
+
if (!isUrl(path$1) && !await findAIGNEFile(path$1).catch((error) => {
|
|
59
|
+
if (options._[0] !== "run") yargsInstance?.showHelp();
|
|
60
|
+
else throw error;
|
|
61
|
+
return false;
|
|
62
|
+
})) return;
|
|
63
|
+
const opts = withRunAgentCommonOptions(yargs(process.argv).help(false).version(false).strict(false)).parseSync();
|
|
64
|
+
logger.level = opts.logLevel;
|
|
65
|
+
const { aigne } = await loadApplication(path$1, {
|
|
66
|
+
modelOptions: pick(opts, CHAT_MODEL_OPTIONS),
|
|
67
|
+
imageModelOptions: { model: opts.imageModel }
|
|
68
|
+
});
|
|
69
|
+
const subYargs = yargs().scriptName("").usage("aigne run <path> <agent> [...options]");
|
|
70
|
+
if (aigne.cli.chat) subYargs.command({
|
|
71
|
+
...agentCommandModule({
|
|
72
|
+
aigne,
|
|
73
|
+
agent: aigne.cli.chat,
|
|
74
|
+
interactive: true
|
|
75
|
+
}),
|
|
76
|
+
command: "$0"
|
|
77
|
+
});
|
|
78
|
+
const allAgents = flat(aigne.agents, aigne.skills, aigne.cli.chat, aigne.mcpServer.agents);
|
|
79
|
+
for (const agent of allAgents) subYargs.command(agentCommandModule({
|
|
80
|
+
aigne,
|
|
81
|
+
agent,
|
|
82
|
+
interactive: options.interactive
|
|
83
|
+
}));
|
|
84
|
+
for (const cliAgent of aigne.cli.agents ?? []) subYargs.command(cliAgentCommandModule({
|
|
85
|
+
aigne,
|
|
86
|
+
cliAgent
|
|
87
|
+
}));
|
|
88
|
+
const argv = process.argv.slice(aigneFilePath ? 3 : 2);
|
|
89
|
+
if (argv[0] === "run") argv.shift();
|
|
90
|
+
if (argv[0] === "--path" || argv[0] === "--url") argv.shift();
|
|
91
|
+
if (argv[0] === options.path) argv.shift();
|
|
92
|
+
if (argv[0] === "--entry-agent") argv.shift();
|
|
93
|
+
const firstAgent = aigne.agents[0]?.name;
|
|
94
|
+
if (!options.entryAgent && firstAgent && !argv.some((i) => ["-h", "--help"].includes(i))) argv.unshift(firstAgent);
|
|
95
|
+
await subYargs.strict().demandCommand().alias("h", "help").alias("v", "version").fail((message, error, yargs$1) => {
|
|
96
|
+
if (!error) {
|
|
97
|
+
yargs$1.showHelp();
|
|
98
|
+
console.error(`\n${message}`);
|
|
99
|
+
process.exit(1);
|
|
100
|
+
}
|
|
101
|
+
}).parseAsync(argv);
|
|
102
|
+
}
|
|
103
|
+
};
|
|
104
|
+
}
|
|
105
|
+
async function loadApplication(path$1, options = {}) {
|
|
106
|
+
const { cacheDir, dir } = prepareDirs(path$1);
|
|
107
|
+
if (cacheDir) await new Listr([{
|
|
108
|
+
title: "Download package",
|
|
109
|
+
task: () => downloadPackage(path$1, cacheDir)
|
|
110
|
+
}, {
|
|
111
|
+
title: "Extract package",
|
|
112
|
+
task: () => extractPackage(cacheDir, dir)
|
|
113
|
+
}], { rendererOptions: {
|
|
114
|
+
collapseSubtasks: false,
|
|
115
|
+
showErrorMessage: false,
|
|
116
|
+
timer: PRESET_TIMER
|
|
117
|
+
} }).run();
|
|
118
|
+
config({
|
|
119
|
+
path: dir,
|
|
120
|
+
silent: true
|
|
121
|
+
});
|
|
122
|
+
return {
|
|
123
|
+
aigne: await loadAIGNE({
|
|
124
|
+
...options,
|
|
125
|
+
path: dir
|
|
126
|
+
}),
|
|
127
|
+
path: dir
|
|
128
|
+
};
|
|
129
|
+
}
|
|
130
|
+
async function downloadPackage(url, cacheDir) {
|
|
131
|
+
await rm(cacheDir, {
|
|
132
|
+
recursive: true,
|
|
133
|
+
force: true
|
|
134
|
+
});
|
|
135
|
+
await mkdir(cacheDir, { recursive: true });
|
|
136
|
+
await downloadAndExtract(url, cacheDir);
|
|
137
|
+
}
|
|
138
|
+
async function extractPackage(cacheDir, dir) {
|
|
139
|
+
await mkdir(dir, { recursive: true });
|
|
140
|
+
if (await isV1Package(cacheDir)) await toAIGNEPackage(cacheDir, dir);
|
|
141
|
+
else await cp(cacheDir, dir, {
|
|
142
|
+
recursive: true,
|
|
143
|
+
force: true
|
|
144
|
+
});
|
|
145
|
+
}
|
|
146
|
+
function prepareDirs(path$1) {
|
|
147
|
+
let dir;
|
|
148
|
+
let cacheDir;
|
|
149
|
+
if (!path$1.startsWith("http")) dir = isAbsolute(path$1) ? path$1 : resolve(process.cwd(), path$1);
|
|
150
|
+
else {
|
|
151
|
+
dir = getLocalPackagePathFromUrl(path$1);
|
|
152
|
+
cacheDir = getLocalPackagePathFromUrl(path$1, { subdir: ".download" });
|
|
153
|
+
}
|
|
154
|
+
return {
|
|
155
|
+
cacheDir,
|
|
156
|
+
dir
|
|
157
|
+
};
|
|
158
|
+
}
|
|
159
|
+
function getLocalPackagePathFromUrl(url, { subdir } = {}) {
|
|
160
|
+
const root = [
|
|
161
|
+
homedir(),
|
|
162
|
+
".aigne",
|
|
163
|
+
subdir
|
|
164
|
+
].filter(isNonNullable);
|
|
165
|
+
const u = new URL(url);
|
|
166
|
+
return join(...root, u.hostname, u.pathname);
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
//#endregion
|
|
170
|
+
export { createRunCommand };
|
|
171
|
+
//# sourceMappingURL=run.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"run.mjs","names":["yargs","path"],"sources":["../../src/commands/run.ts"],"sourcesContent":["import { cp, mkdir, rm } from \"node:fs/promises\";\nimport { homedir } from \"node:os\";\nimport { isAbsolute, join, resolve } from \"node:path\";\nimport { exists } from \"@aigne/agent-library/utils/fs\";\nimport { findAIGNEFile } from \"@aigne/core/loader\";\nimport { logger } from \"@aigne/core/utils/logger\";\nimport { flat, isNonNullable, pick } from \"@aigne/core/utils/type-utils\";\nimport { Listr, PRESET_TIMER } from \"@aigne/listr2\";\nimport { config } from \"dotenv-flow\";\nimport type { Argv, CommandModule } from \"yargs\";\nimport yargs from \"yargs\";\nimport { AIGNE_CLI_VERSION, CHAT_MODEL_OPTIONS } from \"../constants.js\";\nimport { isV1Package, toAIGNEPackage } from \"../utils/agent-v1.js\";\nimport { downloadAndExtract } from \"../utils/download.js\";\nimport { loadAIGNE } from \"../utils/load-aigne.js\";\nimport { isUrl } from \"../utils/url.js\";\nimport { withRunAgentCommonOptions } from \"../utils/yargs.js\";\nimport { agentCommandModule, cliAgentCommandModule } from \"./app/agent.js\";\n\nlet yargsInstance: Argv | null = null;\n\nexport function createRunCommand({\n aigneFilePath,\n}: {\n aigneFilePath?: string;\n} = {}): CommandModule<\n unknown,\n { version?: boolean; path?: string; entryAgent?: string; interactive?: boolean }\n> {\n return {\n // $0 must place after 'run' to make positional args work correctly\n command: [\"run [path] [entry-agent]\", \"$0\"],\n describe: \"Run AIGNE for the specified path\",\n builder: async (yargs) => {\n yargsInstance = yargs;\n\n return yargs\n .positional(\"path\", {\n type: \"string\",\n describe: \"Path to the agents directory or URL to an aigne project\",\n default: \".\",\n })\n .positional(\"entry-agent\", {\n type: \"string\",\n describe: \"Name of the agent to run (defaults to the entry agent if not specified)\",\n })\n .option(\"version\", {\n type: \"boolean\",\n alias: \"v\",\n describe: \"Show version number\",\n })\n .option(\"interactive\", {\n describe: \"Run in interactive chat mode\",\n type: \"boolean\",\n default: false,\n alias: [\"chat\"],\n })\n .help(false)\n .version(false)\n .strict(false);\n },\n handler: async (options) => {\n if (options.version) {\n console.log(AIGNE_CLI_VERSION);\n process.exit(0);\n return;\n }\n\n if (!options.entryAgent && options.path) {\n if (!(await exists(options.path)) && !isUrl(options.path)) {\n options.entryAgent = options.path;\n options.path = undefined;\n }\n }\n\n const path = aigneFilePath || options.path || \".\";\n if (\n !isUrl(path) &&\n !(await findAIGNEFile(path).catch((error) => {\n if (options._[0] !== \"run\") {\n yargsInstance?.showHelp();\n } else {\n throw error;\n }\n return false;\n }))\n ) {\n return;\n }\n\n // Parse model options for loading application\n const opts = withRunAgentCommonOptions(\n yargs(process.argv).help(false).version(false).strict(false),\n ).parseSync();\n logger.level = opts.logLevel;\n\n const { aigne } = await loadApplication(path, {\n modelOptions: pick(opts, CHAT_MODEL_OPTIONS),\n imageModelOptions: { model: opts.imageModel },\n });\n\n const subYargs = yargs().scriptName(\"\").usage(\"aigne run <path> <agent> [...options]\");\n\n if (aigne.cli.chat) {\n subYargs.command({\n ...agentCommandModule({ aigne, agent: aigne.cli.chat, interactive: true }),\n command: \"$0\",\n });\n }\n\n // Allow user to run all of agents in the AIGNE instances\n const allAgents = flat(aigne.agents, aigne.skills, aigne.cli.chat, aigne.mcpServer.agents);\n for (const agent of allAgents) {\n subYargs.command(agentCommandModule({ aigne, agent, interactive: options.interactive }));\n }\n\n for (const cliAgent of aigne.cli.agents ?? []) {\n subYargs.command(\n cliAgentCommandModule({\n aigne,\n cliAgent,\n }),\n );\n }\n\n const argv = process.argv.slice(aigneFilePath ? 3 : 2);\n if (argv[0] === \"run\") argv.shift(); // remove 'run' command\n\n // For compatibility with old `run` command like: `aigne run --path /xx/xx --entry-agent xx --xx`\n if (argv[0] === \"--path\" || argv[0] === \"--url\") argv.shift(); // remove --path flag\n if (argv[0] === options.path) argv.shift(); // remove path/url args\n if (argv[0] === \"--entry-agent\") argv.shift();\n\n const firstAgent = aigne.agents[0]?.name;\n if (!options.entryAgent && firstAgent && !argv.some((i) => [\"-h\", \"--help\"].includes(i))) {\n argv.unshift(firstAgent);\n }\n\n await subYargs\n .strict()\n .demandCommand()\n .alias(\"h\", \"help\")\n .alias(\"v\", \"version\")\n .fail((message, error, yargs) => {\n // We catch all errors below, here just print the help message non-error case like demandCommand\n if (!error) {\n yargs.showHelp();\n\n console.error(`\\n${message}`);\n process.exit(1);\n }\n })\n .parseAsync(argv);\n },\n };\n}\n\nasync function loadApplication(path: string, options: Parameters<typeof loadAIGNE>[0] = {}) {\n const { cacheDir, dir } = prepareDirs(path);\n\n if (cacheDir) {\n await new Listr(\n [\n {\n title: \"Download package\",\n task: () => downloadPackage(path, cacheDir),\n },\n {\n title: \"Extract package\",\n task: () => extractPackage(cacheDir, dir),\n },\n ],\n {\n rendererOptions: {\n collapseSubtasks: false,\n showErrorMessage: false,\n timer: PRESET_TIMER,\n },\n },\n ).run();\n }\n\n // Load env files in the aigne directory\n config({ path: dir, silent: true });\n\n const aigne = await loadAIGNE({ ...options, path: dir });\n\n return { aigne, path: dir };\n}\n\nasync function downloadPackage(url: string, cacheDir: string) {\n await rm(cacheDir, { recursive: true, force: true });\n\n await mkdir(cacheDir, { recursive: true });\n\n await downloadAndExtract(url, cacheDir);\n}\n\nasync function extractPackage(cacheDir: string, dir: string) {\n await mkdir(dir, { recursive: true });\n\n if (await isV1Package(cacheDir)) {\n await toAIGNEPackage(cacheDir, dir);\n } else {\n await cp(cacheDir, dir, { recursive: true, force: true });\n }\n}\n\nfunction prepareDirs(path: string) {\n let dir: string;\n let cacheDir: string | undefined;\n\n if (!path.startsWith(\"http\")) {\n dir = isAbsolute(path) ? path : resolve(process.cwd(), path);\n } else {\n dir = getLocalPackagePathFromUrl(path);\n cacheDir = getLocalPackagePathFromUrl(path, { subdir: \".download\" });\n }\n\n return { cacheDir, dir };\n}\n\nfunction getLocalPackagePathFromUrl(url: string, { subdir }: { subdir?: string } = {}) {\n const root = [homedir(), \".aigne\", subdir].filter(isNonNullable);\n const u = new URL(url);\n return join(...root, u.hostname, u.pathname);\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;AAmBA,IAAI,gBAA6B;AAEjC,SAAgB,iBAAiB,EAC/B,kBAGE,EAAE,EAGJ;AACA,QAAO;EAEL,SAAS,CAAC,4BAA4B,KAAK;EAC3C,UAAU;EACV,SAAS,OAAO,YAAU;AACxB,mBAAgBA;AAEhB,UAAOA,QACJ,WAAW,QAAQ;IAClB,MAAM;IACN,UAAU;IACV,SAAS;IACV,CAAC,CACD,WAAW,eAAe;IACzB,MAAM;IACN,UAAU;IACX,CAAC,CACD,OAAO,WAAW;IACjB,MAAM;IACN,OAAO;IACP,UAAU;IACX,CAAC,CACD,OAAO,eAAe;IACrB,UAAU;IACV,MAAM;IACN,SAAS;IACT,OAAO,CAAC,OAAO;IAChB,CAAC,CACD,KAAK,MAAM,CACX,QAAQ,MAAM,CACd,OAAO,MAAM;;EAElB,SAAS,OAAO,YAAY;AAC1B,OAAI,QAAQ,SAAS;AACnB,YAAQ,IAAI,kBAAkB;AAC9B,YAAQ,KAAK,EAAE;AACf;;AAGF,OAAI,CAAC,QAAQ,cAAc,QAAQ,MACjC;QAAI,CAAE,MAAM,OAAO,QAAQ,KAAK,IAAK,CAAC,MAAM,QAAQ,KAAK,EAAE;AACzD,aAAQ,aAAa,QAAQ;AAC7B,aAAQ,OAAO;;;GAInB,MAAMC,SAAO,iBAAiB,QAAQ,QAAQ;AAC9C,OACE,CAAC,MAAMA,OAAK,IACZ,CAAE,MAAM,cAAcA,OAAK,CAAC,OAAO,UAAU;AAC3C,QAAI,QAAQ,EAAE,OAAO,MACnB,gBAAe,UAAU;QAEzB,OAAM;AAER,WAAO;KACP,CAEF;GAIF,MAAM,OAAO,0BACX,MAAM,QAAQ,KAAK,CAAC,KAAK,MAAM,CAAC,QAAQ,MAAM,CAAC,OAAO,MAAM,CAC7D,CAAC,WAAW;AACb,UAAO,QAAQ,KAAK;GAEpB,MAAM,EAAE,UAAU,MAAM,gBAAgBA,QAAM;IAC5C,cAAc,KAAK,MAAM,mBAAmB;IAC5C,mBAAmB,EAAE,OAAO,KAAK,YAAY;IAC9C,CAAC;GAEF,MAAM,WAAW,OAAO,CAAC,WAAW,GAAG,CAAC,MAAM,wCAAwC;AAEtF,OAAI,MAAM,IAAI,KACZ,UAAS,QAAQ;IACf,GAAG,mBAAmB;KAAE;KAAO,OAAO,MAAM,IAAI;KAAM,aAAa;KAAM,CAAC;IAC1E,SAAS;IACV,CAAC;GAIJ,MAAM,YAAY,KAAK,MAAM,QAAQ,MAAM,QAAQ,MAAM,IAAI,MAAM,MAAM,UAAU,OAAO;AAC1F,QAAK,MAAM,SAAS,UAClB,UAAS,QAAQ,mBAAmB;IAAE;IAAO;IAAO,aAAa,QAAQ;IAAa,CAAC,CAAC;AAG1F,QAAK,MAAM,YAAY,MAAM,IAAI,UAAU,EAAE,CAC3C,UAAS,QACP,sBAAsB;IACpB;IACA;IACD,CAAC,CACH;GAGH,MAAM,OAAO,QAAQ,KAAK,MAAM,gBAAgB,IAAI,EAAE;AACtD,OAAI,KAAK,OAAO,MAAO,MAAK,OAAO;AAGnC,OAAI,KAAK,OAAO,YAAY,KAAK,OAAO,QAAS,MAAK,OAAO;AAC7D,OAAI,KAAK,OAAO,QAAQ,KAAM,MAAK,OAAO;AAC1C,OAAI,KAAK,OAAO,gBAAiB,MAAK,OAAO;GAE7C,MAAM,aAAa,MAAM,OAAO,IAAI;AACpC,OAAI,CAAC,QAAQ,cAAc,cAAc,CAAC,KAAK,MAAM,MAAM,CAAC,MAAM,SAAS,CAAC,SAAS,EAAE,CAAC,CACtF,MAAK,QAAQ,WAAW;AAG1B,SAAM,SACH,QAAQ,CACR,eAAe,CACf,MAAM,KAAK,OAAO,CAClB,MAAM,KAAK,UAAU,CACrB,MAAM,SAAS,OAAO,YAAU;AAE/B,QAAI,CAAC,OAAO;AACV,aAAM,UAAU;AAEhB,aAAQ,MAAM,KAAK,UAAU;AAC7B,aAAQ,KAAK,EAAE;;KAEjB,CACD,WAAW,KAAK;;EAEtB;;AAGH,eAAe,gBAAgB,QAAc,UAA2C,EAAE,EAAE;CAC1F,MAAM,EAAE,UAAU,QAAQ,YAAYA,OAAK;AAE3C,KAAI,SACF,OAAM,IAAI,MACR,CACE;EACE,OAAO;EACP,YAAY,gBAAgBA,QAAM,SAAS;EAC5C,EACD;EACE,OAAO;EACP,YAAY,eAAe,UAAU,IAAI;EAC1C,CACF,EACD,EACE,iBAAiB;EACf,kBAAkB;EAClB,kBAAkB;EAClB,OAAO;EACR,EACF,CACF,CAAC,KAAK;AAIT,QAAO;EAAE,MAAM;EAAK,QAAQ;EAAM,CAAC;AAInC,QAAO;EAAE,OAFK,MAAM,UAAU;GAAE,GAAG;GAAS,MAAM;GAAK,CAAC;EAExC,MAAM;EAAK;;AAG7B,eAAe,gBAAgB,KAAa,UAAkB;AAC5D,OAAM,GAAG,UAAU;EAAE,WAAW;EAAM,OAAO;EAAM,CAAC;AAEpD,OAAM,MAAM,UAAU,EAAE,WAAW,MAAM,CAAC;AAE1C,OAAM,mBAAmB,KAAK,SAAS;;AAGzC,eAAe,eAAe,UAAkB,KAAa;AAC3D,OAAM,MAAM,KAAK,EAAE,WAAW,MAAM,CAAC;AAErC,KAAI,MAAM,YAAY,SAAS,CAC7B,OAAM,eAAe,UAAU,IAAI;KAEnC,OAAM,GAAG,UAAU,KAAK;EAAE,WAAW;EAAM,OAAO;EAAM,CAAC;;AAI7D,SAAS,YAAY,QAAc;CACjC,IAAI;CACJ,IAAI;AAEJ,KAAI,CAACA,OAAK,WAAW,OAAO,CAC1B,OAAM,WAAWA,OAAK,GAAGA,SAAO,QAAQ,QAAQ,KAAK,EAAEA,OAAK;MACvD;AACL,QAAM,2BAA2BA,OAAK;AACtC,aAAW,2BAA2BA,QAAM,EAAE,QAAQ,aAAa,CAAC;;AAGtE,QAAO;EAAE;EAAU;EAAK;;AAG1B,SAAS,2BAA2B,KAAa,EAAE,WAAgC,EAAE,EAAE;CACrF,MAAM,OAAO;EAAC,SAAS;EAAE;EAAU;EAAO,CAAC,OAAO,cAAc;CAChE,MAAM,IAAI,IAAI,IAAI,IAAI;AACtB,QAAO,KAAK,GAAG,MAAM,EAAE,UAAU,EAAE,SAAS"}
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
const require_rolldown_runtime = require('../_virtual/rolldown_runtime.cjs');
|
|
2
|
+
const require_utils_load_aigne = require('../utils/load-aigne.cjs');
|
|
3
|
+
const require_utils_serve_mcp = require('../utils/serve-mcp.cjs');
|
|
4
|
+
let node_path = require("node:path");
|
|
5
|
+
let _aigne_core_utils_type_utils = require("@aigne/core/utils/type-utils");
|
|
6
|
+
|
|
7
|
+
//#region src/commands/serve-mcp.ts
|
|
8
|
+
const DEFAULT_PORT = () => (0, _aigne_core_utils_type_utils.tryOrThrow)(() => {
|
|
9
|
+
const { PORT } = process.env;
|
|
10
|
+
if (!PORT) return 3e3;
|
|
11
|
+
const port = Number.parseInt(PORT, 10);
|
|
12
|
+
if (!port || !Number.isInteger(port)) throw new Error(`Invalid PORT: ${PORT}`);
|
|
13
|
+
return port;
|
|
14
|
+
}, (error) => /* @__PURE__ */ new Error(`parse PORT error ${error.message}`));
|
|
15
|
+
function createServeMCPCommand({ aigneFilePath } = {}) {
|
|
16
|
+
return {
|
|
17
|
+
command: "serve-mcp",
|
|
18
|
+
describe: "Serve the agents in the specified directory as a MCP server (streamable http)",
|
|
19
|
+
builder: (yargs) => {
|
|
20
|
+
return yargs.option("path", {
|
|
21
|
+
describe: "Path to the agents directory or URL to aigne project",
|
|
22
|
+
type: "string",
|
|
23
|
+
default: ".",
|
|
24
|
+
alias: ["url"]
|
|
25
|
+
}).option("host", {
|
|
26
|
+
describe: "Host to run the MCP server on, use 0.0.0.0 to publicly expose the server",
|
|
27
|
+
type: "string",
|
|
28
|
+
default: "localhost"
|
|
29
|
+
}).option("port", {
|
|
30
|
+
describe: "Port to run the MCP server on",
|
|
31
|
+
type: "number"
|
|
32
|
+
}).option("pathname", {
|
|
33
|
+
describe: "Pathname to the service",
|
|
34
|
+
type: "string",
|
|
35
|
+
default: "/mcp"
|
|
36
|
+
}).option("aigne-hub-url", {
|
|
37
|
+
describe: "Custom AIGNE Hub service URL. Used to fetch remote agent definitions or models. ",
|
|
38
|
+
type: "string"
|
|
39
|
+
});
|
|
40
|
+
},
|
|
41
|
+
handler: async (options) => {
|
|
42
|
+
const path = aigneFilePath || options.path;
|
|
43
|
+
const aigne = await require_utils_load_aigne.loadAIGNE({
|
|
44
|
+
path: (0, node_path.isAbsolute)(path) ? path : (0, node_path.resolve)(process.cwd(), path),
|
|
45
|
+
modelOptions: { aigneHubUrl: options.aigneHubUrl }
|
|
46
|
+
});
|
|
47
|
+
await serveMCPServerFromDir({
|
|
48
|
+
...options,
|
|
49
|
+
aigne
|
|
50
|
+
});
|
|
51
|
+
}
|
|
52
|
+
};
|
|
53
|
+
}
|
|
54
|
+
async function serveMCPServerFromDir(options) {
|
|
55
|
+
const port = options.port || DEFAULT_PORT();
|
|
56
|
+
await require_utils_serve_mcp.serveMCPServer({
|
|
57
|
+
aigne: options.aigne,
|
|
58
|
+
host: options.host,
|
|
59
|
+
port,
|
|
60
|
+
pathname: options.pathname
|
|
61
|
+
});
|
|
62
|
+
console.log(`MCP server is running on http://${options.host}:${port}${options.pathname}`);
|
|
63
|
+
if (!process.env.CI && process.env.NODE_ENV !== "test") await new Promise(() => {});
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
//#endregion
|
|
67
|
+
exports.createServeMCPCommand = createServeMCPCommand;
|
|
68
|
+
exports.serveMCPServerFromDir = serveMCPServerFromDir;
|