@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,67 @@
|
|
|
1
|
+
import { loadAIGNE } from "../utils/load-aigne.mjs";
|
|
2
|
+
import { serveMCPServer } from "../utils/serve-mcp.mjs";
|
|
3
|
+
import { isAbsolute, resolve } from "node:path";
|
|
4
|
+
import { tryOrThrow } from "@aigne/core/utils/type-utils";
|
|
5
|
+
|
|
6
|
+
//#region src/commands/serve-mcp.ts
|
|
7
|
+
const DEFAULT_PORT = () => tryOrThrow(() => {
|
|
8
|
+
const { PORT } = process.env;
|
|
9
|
+
if (!PORT) return 3e3;
|
|
10
|
+
const port = Number.parseInt(PORT, 10);
|
|
11
|
+
if (!port || !Number.isInteger(port)) throw new Error(`Invalid PORT: ${PORT}`);
|
|
12
|
+
return port;
|
|
13
|
+
}, (error) => /* @__PURE__ */ new Error(`parse PORT error ${error.message}`));
|
|
14
|
+
function createServeMCPCommand({ aigneFilePath } = {}) {
|
|
15
|
+
return {
|
|
16
|
+
command: "serve-mcp",
|
|
17
|
+
describe: "Serve the agents in the specified directory as a MCP server (streamable http)",
|
|
18
|
+
builder: (yargs) => {
|
|
19
|
+
return yargs.option("path", {
|
|
20
|
+
describe: "Path to the agents directory or URL to aigne project",
|
|
21
|
+
type: "string",
|
|
22
|
+
default: ".",
|
|
23
|
+
alias: ["url"]
|
|
24
|
+
}).option("host", {
|
|
25
|
+
describe: "Host to run the MCP server on, use 0.0.0.0 to publicly expose the server",
|
|
26
|
+
type: "string",
|
|
27
|
+
default: "localhost"
|
|
28
|
+
}).option("port", {
|
|
29
|
+
describe: "Port to run the MCP server on",
|
|
30
|
+
type: "number"
|
|
31
|
+
}).option("pathname", {
|
|
32
|
+
describe: "Pathname to the service",
|
|
33
|
+
type: "string",
|
|
34
|
+
default: "/mcp"
|
|
35
|
+
}).option("aigne-hub-url", {
|
|
36
|
+
describe: "Custom AIGNE Hub service URL. Used to fetch remote agent definitions or models. ",
|
|
37
|
+
type: "string"
|
|
38
|
+
});
|
|
39
|
+
},
|
|
40
|
+
handler: async (options) => {
|
|
41
|
+
const path$1 = aigneFilePath || options.path;
|
|
42
|
+
const aigne = await loadAIGNE({
|
|
43
|
+
path: isAbsolute(path$1) ? path$1 : resolve(process.cwd(), path$1),
|
|
44
|
+
modelOptions: { aigneHubUrl: options.aigneHubUrl }
|
|
45
|
+
});
|
|
46
|
+
await serveMCPServerFromDir({
|
|
47
|
+
...options,
|
|
48
|
+
aigne
|
|
49
|
+
});
|
|
50
|
+
}
|
|
51
|
+
};
|
|
52
|
+
}
|
|
53
|
+
async function serveMCPServerFromDir(options) {
|
|
54
|
+
const port = options.port || DEFAULT_PORT();
|
|
55
|
+
await serveMCPServer({
|
|
56
|
+
aigne: options.aigne,
|
|
57
|
+
host: options.host,
|
|
58
|
+
port,
|
|
59
|
+
pathname: options.pathname
|
|
60
|
+
});
|
|
61
|
+
console.log(`MCP server is running on http://${options.host}:${port}${options.pathname}`);
|
|
62
|
+
if (!process.env.CI && process.env.NODE_ENV !== "test") await new Promise(() => {});
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
//#endregion
|
|
66
|
+
export { createServeMCPCommand, serveMCPServerFromDir };
|
|
67
|
+
//# sourceMappingURL=serve-mcp.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"serve-mcp.mjs","names":["path"],"sources":["../../src/commands/serve-mcp.ts"],"sourcesContent":["import { isAbsolute, resolve } from \"node:path\";\nimport type { AIGNE } from \"@aigne/core\";\nimport { tryOrThrow } from \"@aigne/core/utils/type-utils\";\nimport type { CommandModule } from \"yargs\";\nimport { loadAIGNE } from \"../utils/load-aigne.js\";\nimport { serveMCPServer } from \"../utils/serve-mcp.js\";\n\ninterface ServeMCPOptions {\n path: string;\n host: string;\n port?: number;\n pathname: string;\n aigneHubUrl?: string;\n}\n\nexport const DEFAULT_PORT = () =>\n tryOrThrow(\n () => {\n const { PORT } = process.env;\n if (!PORT) return 3000;\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 createServeMCPCommand({\n aigneFilePath,\n}: {\n aigneFilePath?: string;\n} = {}): CommandModule<unknown, ServeMCPOptions> {\n return {\n command: \"serve-mcp\",\n describe: \"Serve the agents in the specified directory as a MCP server (streamable http)\",\n builder: (yargs) => {\n return yargs\n .option(\"path\", {\n describe: \"Path to the agents directory or URL to aigne project\",\n type: \"string\",\n default: \".\",\n alias: [\"url\"],\n })\n .option(\"host\", {\n describe: \"Host to run the MCP server on, use 0.0.0.0 to publicly expose the server\",\n type: \"string\",\n default: \"localhost\",\n })\n .option(\"port\", {\n describe: \"Port to run the MCP server on\",\n type: \"number\",\n })\n .option(\"pathname\", {\n describe: \"Pathname to the service\",\n type: \"string\",\n default: \"/mcp\",\n })\n .option(\"aigne-hub-url\", {\n describe:\n \"Custom AIGNE Hub service URL. Used to fetch remote agent definitions or models. \",\n type: \"string\",\n });\n },\n handler: async (options) => {\n const path = aigneFilePath || options.path;\n const absolutePath = isAbsolute(path) ? path : resolve(process.cwd(), path);\n\n const aigne = await loadAIGNE({\n path: absolutePath,\n modelOptions: { aigneHubUrl: options.aigneHubUrl },\n });\n\n await serveMCPServerFromDir({ ...options, aigne });\n },\n };\n}\n\nexport async function serveMCPServerFromDir(options: {\n aigne: AIGNE;\n host: string;\n port?: number;\n pathname: string;\n}) {\n const port = options.port || DEFAULT_PORT();\n\n await serveMCPServer({\n aigne: options.aigne,\n host: options.host,\n port,\n pathname: options.pathname,\n });\n\n console.log(`MCP server is running on http://${options.host}:${port}${options.pathname}`);\n\n if (!process.env.CI && process.env.NODE_ENV !== \"test\") await new Promise(() => {}); // Keep the server running\n}\n"],"mappings":";;;;;;AAeA,MAAa,qBACX,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,sBAAsB,EACpC,kBAGE,EAAE,EAA2C;AAC/C,QAAO;EACL,SAAS;EACT,UAAU;EACV,UAAU,UAAU;AAClB,UAAO,MACJ,OAAO,QAAQ;IACd,UAAU;IACV,MAAM;IACN,SAAS;IACT,OAAO,CAAC,MAAM;IACf,CAAC,CACD,OAAO,QAAQ;IACd,UAAU;IACV,MAAM;IACN,SAAS;IACV,CAAC,CACD,OAAO,QAAQ;IACd,UAAU;IACV,MAAM;IACP,CAAC,CACD,OAAO,YAAY;IAClB,UAAU;IACV,MAAM;IACN,SAAS;IACV,CAAC,CACD,OAAO,iBAAiB;IACvB,UACE;IACF,MAAM;IACP,CAAC;;EAEN,SAAS,OAAO,YAAY;GAC1B,MAAMA,SAAO,iBAAiB,QAAQ;GAGtC,MAAM,QAAQ,MAAM,UAAU;IAC5B,MAHmB,WAAWA,OAAK,GAAGA,SAAO,QAAQ,QAAQ,KAAK,EAAEA,OAAK;IAIzE,cAAc,EAAE,aAAa,QAAQ,aAAa;IACnD,CAAC;AAEF,SAAM,sBAAsB;IAAE,GAAG;IAAS;IAAO,CAAC;;EAErD;;AAGH,eAAsB,sBAAsB,SAKzC;CACD,MAAM,OAAO,QAAQ,QAAQ,cAAc;AAE3C,OAAM,eAAe;EACnB,OAAO,QAAQ;EACf,MAAM,QAAQ;EACd;EACA,UAAU,QAAQ;EACnB,CAAC;AAEF,SAAQ,IAAI,mCAAmC,QAAQ,KAAK,GAAG,OAAO,QAAQ,WAAW;AAEzF,KAAI,CAAC,QAAQ,IAAI,MAAM,QAAQ,IAAI,aAAa,OAAQ,OAAM,IAAI,cAAc,GAAG"}
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
const require_rolldown_runtime = require('../_virtual/rolldown_runtime.cjs');
|
|
2
|
+
const require_utils_load_aigne = require('../utils/load-aigne.cjs');
|
|
3
|
+
let node_child_process = require("node:child_process");
|
|
4
|
+
let node_path = require("node:path");
|
|
5
|
+
let node_assert = require("node:assert");
|
|
6
|
+
node_assert = require_rolldown_runtime.__toESM(node_assert);
|
|
7
|
+
|
|
8
|
+
//#region src/commands/test.ts
|
|
9
|
+
function createTestCommand({ aigneFilePath } = {}) {
|
|
10
|
+
return {
|
|
11
|
+
command: "test",
|
|
12
|
+
describe: "Run tests in the specified agents directory",
|
|
13
|
+
builder: (yargs) => {
|
|
14
|
+
return yargs.option("path", {
|
|
15
|
+
describe: "Path to the agents directory or URL to aigne project",
|
|
16
|
+
type: "string",
|
|
17
|
+
default: ".",
|
|
18
|
+
alias: ["url"]
|
|
19
|
+
}).option("aigne-hub-url", {
|
|
20
|
+
describe: "Custom AIGNE Hub service URL. Used to fetch remote agent definitions or models. ",
|
|
21
|
+
type: "string"
|
|
22
|
+
});
|
|
23
|
+
},
|
|
24
|
+
handler: async (options) => {
|
|
25
|
+
const path = aigneFilePath || options.path;
|
|
26
|
+
const aigne = await require_utils_load_aigne.loadAIGNE({
|
|
27
|
+
path: (0, node_path.isAbsolute)(path) ? path : (0, node_path.resolve)(process.cwd(), path),
|
|
28
|
+
modelOptions: { aigneHubUrl: options?.aigneHubUrl }
|
|
29
|
+
});
|
|
30
|
+
(0, node_assert.default)(aigne.rootDir);
|
|
31
|
+
(0, node_child_process.spawnSync)("node", ["--test"], {
|
|
32
|
+
cwd: aigne.rootDir,
|
|
33
|
+
stdio: "inherit"
|
|
34
|
+
});
|
|
35
|
+
}
|
|
36
|
+
};
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
//#endregion
|
|
40
|
+
exports.createTestCommand = createTestCommand;
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import { loadAIGNE } from "../utils/load-aigne.mjs";
|
|
2
|
+
import { spawnSync } from "node:child_process";
|
|
3
|
+
import { isAbsolute, resolve } from "node:path";
|
|
4
|
+
import assert from "node:assert";
|
|
5
|
+
|
|
6
|
+
//#region src/commands/test.ts
|
|
7
|
+
function createTestCommand({ aigneFilePath } = {}) {
|
|
8
|
+
return {
|
|
9
|
+
command: "test",
|
|
10
|
+
describe: "Run tests in the specified agents directory",
|
|
11
|
+
builder: (yargs) => {
|
|
12
|
+
return yargs.option("path", {
|
|
13
|
+
describe: "Path to the agents directory or URL to aigne project",
|
|
14
|
+
type: "string",
|
|
15
|
+
default: ".",
|
|
16
|
+
alias: ["url"]
|
|
17
|
+
}).option("aigne-hub-url", {
|
|
18
|
+
describe: "Custom AIGNE Hub service URL. Used to fetch remote agent definitions or models. ",
|
|
19
|
+
type: "string"
|
|
20
|
+
});
|
|
21
|
+
},
|
|
22
|
+
handler: async (options) => {
|
|
23
|
+
const path$1 = aigneFilePath || options.path;
|
|
24
|
+
const aigne = await loadAIGNE({
|
|
25
|
+
path: isAbsolute(path$1) ? path$1 : resolve(process.cwd(), path$1),
|
|
26
|
+
modelOptions: { aigneHubUrl: options?.aigneHubUrl }
|
|
27
|
+
});
|
|
28
|
+
assert(aigne.rootDir);
|
|
29
|
+
spawnSync("node", ["--test"], {
|
|
30
|
+
cwd: aigne.rootDir,
|
|
31
|
+
stdio: "inherit"
|
|
32
|
+
});
|
|
33
|
+
}
|
|
34
|
+
};
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
//#endregion
|
|
38
|
+
export { createTestCommand };
|
|
39
|
+
//# sourceMappingURL=test.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"test.mjs","names":["path"],"sources":["../../src/commands/test.ts"],"sourcesContent":["import assert from \"node:assert\";\nimport { spawnSync } from \"node:child_process\";\nimport { isAbsolute, resolve } from \"node:path\";\nimport type { CommandModule } from \"yargs\";\nimport { loadAIGNE } from \"../utils/load-aigne.js\";\n\ninterface TestOptions {\n path: string;\n aigneHubUrl?: string;\n}\n\nexport function createTestCommand({\n aigneFilePath,\n}: {\n aigneFilePath?: string;\n} = {}): CommandModule<unknown, TestOptions> {\n return {\n command: \"test\",\n describe: \"Run tests in the specified agents directory\",\n builder: (yargs) => {\n return yargs\n .option(\"path\", {\n describe: \"Path to the agents directory or URL to aigne project\",\n type: \"string\",\n default: \".\",\n alias: [\"url\"],\n })\n .option(\"aigne-hub-url\", {\n describe:\n \"Custom AIGNE Hub service URL. Used to fetch remote agent definitions or models. \",\n type: \"string\",\n });\n },\n handler: async (options) => {\n const path = aigneFilePath || options.path;\n const absolutePath = isAbsolute(path) ? path : resolve(process.cwd(), path);\n\n const aigne = await loadAIGNE({\n path: absolutePath,\n modelOptions: { aigneHubUrl: options?.aigneHubUrl },\n });\n assert(aigne.rootDir);\n\n spawnSync(\"node\", [\"--test\"], { cwd: aigne.rootDir, stdio: \"inherit\" });\n },\n };\n}\n"],"mappings":";;;;;;AAWA,SAAgB,kBAAkB,EAChC,kBAGE,EAAE,EAAuC;AAC3C,QAAO;EACL,SAAS;EACT,UAAU;EACV,UAAU,UAAU;AAClB,UAAO,MACJ,OAAO,QAAQ;IACd,UAAU;IACV,MAAM;IACN,SAAS;IACT,OAAO,CAAC,MAAM;IACf,CAAC,CACD,OAAO,iBAAiB;IACvB,UACE;IACF,MAAM;IACP,CAAC;;EAEN,SAAS,OAAO,YAAY;GAC1B,MAAMA,SAAO,iBAAiB,QAAQ;GAGtC,MAAM,QAAQ,MAAM,UAAU;IAC5B,MAHmB,WAAWA,OAAK,GAAGA,SAAO,QAAQ,QAAQ,KAAK,EAAEA,OAAK;IAIzE,cAAc,EAAE,aAAa,SAAS,aAAa;IACpD,CAAC;AACF,UAAO,MAAM,QAAQ;AAErB,aAAU,QAAQ,CAAC,SAAS,EAAE;IAAE,KAAK,MAAM;IAAS,OAAO;IAAW,CAAC;;EAE1E"}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
const require_rolldown_runtime = require('./_virtual/rolldown_runtime.cjs');
|
|
2
|
+
let node_module = require("node:module");
|
|
3
|
+
|
|
4
|
+
//#region src/constants.ts
|
|
5
|
+
const require$1 = (0, node_module.createRequire)(require("url").pathToFileURL(__filename).href);
|
|
6
|
+
const AIGNE_CLI_VERSION = require$1("../package.json").version;
|
|
7
|
+
const AIGNE_HUB_CREDITS_NOT_ENOUGH_ERROR_TYPE = "NOT_ENOUGH";
|
|
8
|
+
const CHAT_MODEL_OPTIONS = [
|
|
9
|
+
"aigneHubUrl",
|
|
10
|
+
"model",
|
|
11
|
+
"temperature",
|
|
12
|
+
"topP",
|
|
13
|
+
"frequencyPenalty",
|
|
14
|
+
"presencePenalty",
|
|
15
|
+
"parallelToolCalls",
|
|
16
|
+
"modalities",
|
|
17
|
+
"preferInputFileType",
|
|
18
|
+
"reasoningEffort"
|
|
19
|
+
];
|
|
20
|
+
const DEFAULT_USER_ID = "cli-user";
|
|
21
|
+
const DEFAULT_AFS_EXPLORER_PORT = 9670;
|
|
22
|
+
|
|
23
|
+
//#endregion
|
|
24
|
+
exports.AIGNE_CLI_VERSION = AIGNE_CLI_VERSION;
|
|
25
|
+
exports.AIGNE_HUB_CREDITS_NOT_ENOUGH_ERROR_TYPE = AIGNE_HUB_CREDITS_NOT_ENOUGH_ERROR_TYPE;
|
|
26
|
+
exports.CHAT_MODEL_OPTIONS = CHAT_MODEL_OPTIONS;
|
|
27
|
+
exports.DEFAULT_AFS_EXPLORER_PORT = DEFAULT_AFS_EXPLORER_PORT;
|
|
28
|
+
exports.DEFAULT_USER_ID = DEFAULT_USER_ID;
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
//#region src/constants.d.ts
|
|
2
|
+
declare const AIGNE_CLI_VERSION: any;
|
|
3
|
+
declare const AIGNE_HUB_CREDITS_NOT_ENOUGH_ERROR_TYPE = "NOT_ENOUGH";
|
|
4
|
+
declare const CHAT_MODEL_OPTIONS: string[];
|
|
5
|
+
declare const DEFAULT_USER_ID = "cli-user";
|
|
6
|
+
declare const DEFAULT_AFS_EXPLORER_PORT = 9670;
|
|
7
|
+
//#endregion
|
|
8
|
+
export { AIGNE_CLI_VERSION, AIGNE_HUB_CREDITS_NOT_ENOUGH_ERROR_TYPE, CHAT_MODEL_OPTIONS, DEFAULT_AFS_EXPLORER_PORT, DEFAULT_USER_ID };
|
|
9
|
+
//# sourceMappingURL=constants.d.cts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"constants.d.cts","names":[],"sources":["../src/constants.ts"],"mappings":";cAIa,iBAAA;AAAA,cAEA,uCAAA;AAAA,cAEA,kBAAA;AAAA,cAaA,eAAA;AAAA,cAEA,yBAAA"}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
//#region src/constants.d.ts
|
|
2
|
+
declare const AIGNE_CLI_VERSION: any;
|
|
3
|
+
declare const AIGNE_HUB_CREDITS_NOT_ENOUGH_ERROR_TYPE = "NOT_ENOUGH";
|
|
4
|
+
declare const CHAT_MODEL_OPTIONS: string[];
|
|
5
|
+
declare const DEFAULT_USER_ID = "cli-user";
|
|
6
|
+
declare const DEFAULT_AFS_EXPLORER_PORT = 9670;
|
|
7
|
+
//#endregion
|
|
8
|
+
export { AIGNE_CLI_VERSION, AIGNE_HUB_CREDITS_NOT_ENOUGH_ERROR_TYPE, CHAT_MODEL_OPTIONS, DEFAULT_AFS_EXPLORER_PORT, DEFAULT_USER_ID };
|
|
9
|
+
//# sourceMappingURL=constants.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"constants.d.mts","names":[],"sources":["../src/constants.ts"],"mappings":";cAIa,iBAAA;AAAA,cAEA,uCAAA;AAAA,cAEA,kBAAA;AAAA,cAaA,eAAA;AAAA,cAEA,yBAAA"}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { createRequire } from "node:module";
|
|
2
|
+
|
|
3
|
+
//#region src/constants.ts
|
|
4
|
+
const require = createRequire(import.meta.url);
|
|
5
|
+
const AIGNE_CLI_VERSION = require("../package.json").version;
|
|
6
|
+
const AIGNE_HUB_CREDITS_NOT_ENOUGH_ERROR_TYPE = "NOT_ENOUGH";
|
|
7
|
+
const CHAT_MODEL_OPTIONS = [
|
|
8
|
+
"aigneHubUrl",
|
|
9
|
+
"model",
|
|
10
|
+
"temperature",
|
|
11
|
+
"topP",
|
|
12
|
+
"frequencyPenalty",
|
|
13
|
+
"presencePenalty",
|
|
14
|
+
"parallelToolCalls",
|
|
15
|
+
"modalities",
|
|
16
|
+
"preferInputFileType",
|
|
17
|
+
"reasoningEffort"
|
|
18
|
+
];
|
|
19
|
+
const DEFAULT_USER_ID = "cli-user";
|
|
20
|
+
const DEFAULT_AFS_EXPLORER_PORT = 9670;
|
|
21
|
+
|
|
22
|
+
//#endregion
|
|
23
|
+
export { AIGNE_CLI_VERSION, AIGNE_HUB_CREDITS_NOT_ENOUGH_ERROR_TYPE, CHAT_MODEL_OPTIONS, DEFAULT_AFS_EXPLORER_PORT, DEFAULT_USER_ID };
|
|
24
|
+
//# sourceMappingURL=constants.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"constants.mjs","names":[],"sources":["../src/constants.ts"],"sourcesContent":["import { createRequire } from \"node:module\";\n\nconst require = createRequire(import.meta.url);\n\nexport const AIGNE_CLI_VERSION = require(\"../package.json\").version;\n\nexport const AIGNE_HUB_CREDITS_NOT_ENOUGH_ERROR_TYPE = \"NOT_ENOUGH\";\n\nexport const CHAT_MODEL_OPTIONS = [\n \"aigneHubUrl\",\n \"model\",\n \"temperature\",\n \"topP\",\n \"frequencyPenalty\",\n \"presencePenalty\",\n \"parallelToolCalls\",\n \"modalities\",\n \"preferInputFileType\",\n \"reasoningEffort\",\n];\n\nexport const DEFAULT_USER_ID = \"cli-user\";\n\nexport const DEFAULT_AFS_EXPLORER_PORT = 9670;\n"],"mappings":";;;AAEA,MAAM,UAAU,cAAc,OAAO,KAAK,IAAI;AAE9C,MAAa,oBAAoB,QAAQ,kBAAkB,CAAC;AAE5D,MAAa,0CAA0C;AAEvD,MAAa,qBAAqB;CAChC;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACD;AAED,MAAa,kBAAkB;AAE/B,MAAa,4BAA4B"}
|
|
File without changes
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"global.d.cts","names":["MarkedExtension","sideEffect","_0"],"sources":["../src/global.d.ts"],"mappings":";;;+EAG+EA,eAAAA;AAAAA"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"global.d.mts","names":["MarkedExtension","sideEffect","_0"],"sources":["../src/global.d.ts"],"mappings":";;;+EAG+EA,eAAAA;AAAAA"}
|
package/dist/index.cjs
ADDED
|
File without changes
|
package/dist/index.d.cts
ADDED
package/dist/index.d.mts
ADDED
package/dist/index.mjs
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { };
|
|
@@ -0,0 +1,336 @@
|
|
|
1
|
+
const require_rolldown_runtime = require('../_virtual/rolldown_runtime.cjs');
|
|
2
|
+
const require_constants = require('../constants.cjs');
|
|
3
|
+
const require_terminal_input = require('../ui/utils/terminal-input.cjs');
|
|
4
|
+
const require_checkbox = require('../utils/inquirer/checkbox.cjs');
|
|
5
|
+
const require_utils_listr = require('../utils/listr.cjs');
|
|
6
|
+
const require_utils_string_utils = require('../utils/string-utils.cjs');
|
|
7
|
+
const require_utils_time = require('../utils/time.cjs');
|
|
8
|
+
let chalk = require("chalk");
|
|
9
|
+
chalk = require_rolldown_runtime.__toESM(chalk);
|
|
10
|
+
let _aigne_listr2 = require("@aigne/listr2");
|
|
11
|
+
let ufo = require("ufo");
|
|
12
|
+
let _aigne_core = require("@aigne/core");
|
|
13
|
+
let _aigne_core_utils_type_utils = require("@aigne/core/utils/type-utils");
|
|
14
|
+
let node_os = require("node:os");
|
|
15
|
+
let _inquirer_prompts = require("@inquirer/prompts");
|
|
16
|
+
_inquirer_prompts = require_rolldown_runtime.__toESM(_inquirer_prompts);
|
|
17
|
+
let node_util = require("node:util");
|
|
18
|
+
let _aigne_core_utils_promise = require("@aigne/core/utils/promise");
|
|
19
|
+
let _aigne_marked_terminal = require("@aigne/marked-terminal");
|
|
20
|
+
let marked = require("marked");
|
|
21
|
+
let terminal_image = require("terminal-image");
|
|
22
|
+
terminal_image = require_rolldown_runtime.__toESM(terminal_image);
|
|
23
|
+
let terminal_link = require("terminal-link");
|
|
24
|
+
terminal_link = require_rolldown_runtime.__toESM(terminal_link);
|
|
25
|
+
|
|
26
|
+
//#region src/tracer/terminal.ts
|
|
27
|
+
const CREDITS_ERROR_PROCESSED_FLAG = "$credits_error_processed";
|
|
28
|
+
var TerminalTracer = class {
|
|
29
|
+
constructor(context, options = {}) {
|
|
30
|
+
this.context = context;
|
|
31
|
+
this.options = options;
|
|
32
|
+
}
|
|
33
|
+
tasks = {};
|
|
34
|
+
async run(agent, input, options) {
|
|
35
|
+
await this.context.observer?.serve();
|
|
36
|
+
const context = this.context.newContext({ reset: true });
|
|
37
|
+
const listr = new require_utils_listr.AIGNEListr({
|
|
38
|
+
formatRequest: (options$1) => this.formatRequest(agent, context, input, options$1),
|
|
39
|
+
formatResult: (result, options$1) => this.formatResult(agent, context, result, options$1)
|
|
40
|
+
}, [], {
|
|
41
|
+
concurrent: true,
|
|
42
|
+
exitOnError: false,
|
|
43
|
+
registerSignalListeners: false
|
|
44
|
+
});
|
|
45
|
+
this.listr = listr;
|
|
46
|
+
const collapsedMap = /* @__PURE__ */ new Map();
|
|
47
|
+
const hideContextIds = /* @__PURE__ */ new Set();
|
|
48
|
+
const onStart = async ({ context: context$1, agent: agent$1, ...event }) => {
|
|
49
|
+
const result = { options: { prompts: this.proxiedPrompts } };
|
|
50
|
+
if (agent$1 instanceof _aigne_core.UserAgent) return result;
|
|
51
|
+
if (agent$1.taskRenderMode === "hide") {
|
|
52
|
+
hideContextIds.add(context$1.id);
|
|
53
|
+
return result;
|
|
54
|
+
}
|
|
55
|
+
if (agent$1.taskRenderMode === "collapse") collapsedMap.set(context$1.id, {
|
|
56
|
+
ancestor: { contextId: context$1.id },
|
|
57
|
+
usage: (0, _aigne_core.newEmptyContextUsage)(),
|
|
58
|
+
models: /* @__PURE__ */ new Set()
|
|
59
|
+
});
|
|
60
|
+
if (context$1.parentId) {
|
|
61
|
+
if (hideContextIds.has(context$1.parentId)) {
|
|
62
|
+
hideContextIds.add(context$1.id);
|
|
63
|
+
return result;
|
|
64
|
+
}
|
|
65
|
+
const collapsed = collapsedMap.get(context$1.parentId);
|
|
66
|
+
if (collapsed) {
|
|
67
|
+
collapsedMap.set(context$1.id, collapsed);
|
|
68
|
+
return result;
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
const contextId = context$1.id;
|
|
72
|
+
const parentContextId = context$1.parentId;
|
|
73
|
+
const task = {
|
|
74
|
+
...(0, _aigne_core_utils_promise.promiseWithResolvers)(),
|
|
75
|
+
agent: agent$1,
|
|
76
|
+
input: event.input,
|
|
77
|
+
listr: (0, _aigne_core_utils_promise.promiseWithResolvers)(),
|
|
78
|
+
startTime: Date.now()
|
|
79
|
+
};
|
|
80
|
+
this.tasks[contextId] = task;
|
|
81
|
+
const listrTask = {
|
|
82
|
+
title: await this.formatTaskTitle(agent$1, { ...event }),
|
|
83
|
+
task: (ctx, taskWrapper) => {
|
|
84
|
+
const subtask = taskWrapper.newListr([{ task: () => task.promise }]);
|
|
85
|
+
task.listr.resolve({
|
|
86
|
+
subtask,
|
|
87
|
+
taskWrapper,
|
|
88
|
+
ctx
|
|
89
|
+
});
|
|
90
|
+
return subtask;
|
|
91
|
+
},
|
|
92
|
+
rendererOptions: {
|
|
93
|
+
persistentOutput: true,
|
|
94
|
+
outputBar: Number.POSITIVE_INFINITY,
|
|
95
|
+
bottomBar: Number.POSITIVE_INFINITY
|
|
96
|
+
}
|
|
97
|
+
};
|
|
98
|
+
const parentTask = parentContextId ? this.tasks[parentContextId] : void 0;
|
|
99
|
+
if (parentTask) parentTask.listr.promise.then(({ subtask }) => {
|
|
100
|
+
subtask.add(listrTask);
|
|
101
|
+
});
|
|
102
|
+
else listr.add(listrTask);
|
|
103
|
+
return result;
|
|
104
|
+
};
|
|
105
|
+
const onSuccess = async ({ context: context$1, agent: agent$1, output, ...event }) => {
|
|
106
|
+
const contextId = context$1.id;
|
|
107
|
+
const parentContextId = context$1.parentId;
|
|
108
|
+
const collapsed = collapsedMap.get(contextId);
|
|
109
|
+
if (collapsed) {
|
|
110
|
+
if (agent$1 instanceof _aigne_core.ChatModel) {
|
|
111
|
+
const { usage, model } = output;
|
|
112
|
+
if (usage) (0, _aigne_core.mergeContextUsage)(collapsed.usage, usage);
|
|
113
|
+
if (model) collapsed.models.add(model);
|
|
114
|
+
}
|
|
115
|
+
const task$1 = this.tasks[collapsed.ancestor.contextId];
|
|
116
|
+
if (task$1) {
|
|
117
|
+
task$1.usage = collapsed.usage;
|
|
118
|
+
task$1.extraTitleMetadata ??= {};
|
|
119
|
+
if (collapsed.models.size) task$1.extraTitleMetadata.model = [...collapsed.models].join(",");
|
|
120
|
+
const { taskWrapper: taskWrapper$1 } = await task$1.listr.promise;
|
|
121
|
+
taskWrapper$1.title = await this.formatTaskTitle(task$1.agent, {
|
|
122
|
+
input: task$1.input,
|
|
123
|
+
task: task$1,
|
|
124
|
+
usage: Boolean(task$1.usage.inputTokens || task$1.usage.outputTokens || task$1.usage.aigneHubCredits || task$1.usage.cacheCreationInputTokens || task$1.usage.cacheReadInputTokens),
|
|
125
|
+
time: context$1.id === collapsed.ancestor.contextId
|
|
126
|
+
});
|
|
127
|
+
if (context$1.id === collapsed.ancestor.contextId) task$1?.resolve();
|
|
128
|
+
return;
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
const task = this.tasks[contextId];
|
|
132
|
+
if (!task) return;
|
|
133
|
+
task.endTime = Date.now();
|
|
134
|
+
const { taskWrapper, ctx } = await task.listr.promise;
|
|
135
|
+
if (agent$1 instanceof _aigne_core.ChatModel) {
|
|
136
|
+
const { usage, model } = output;
|
|
137
|
+
task.usage = usage;
|
|
138
|
+
task.extraTitleMetadata ??= {};
|
|
139
|
+
if (model) task.extraTitleMetadata.model = model;
|
|
140
|
+
}
|
|
141
|
+
taskWrapper.title = await this.formatTaskTitle(agent$1, {
|
|
142
|
+
...event,
|
|
143
|
+
task,
|
|
144
|
+
usage: true,
|
|
145
|
+
time: true
|
|
146
|
+
});
|
|
147
|
+
if (!parentContextId || !this.tasks[parentContextId]) Object.assign(ctx, output);
|
|
148
|
+
task.resolve();
|
|
149
|
+
};
|
|
150
|
+
let retryPromptPromise;
|
|
151
|
+
const onError = async ({ context: context$1, agent: agent$1, error, ...event }) => {
|
|
152
|
+
if ("type" in error && error.type === require_constants.AIGNE_HUB_CREDITS_NOT_ENOUGH_ERROR_TYPE) {
|
|
153
|
+
if (!Object.hasOwn(error, CREDITS_ERROR_PROCESSED_FLAG)) {
|
|
154
|
+
Object.defineProperty(error, CREDITS_ERROR_PROCESSED_FLAG, {
|
|
155
|
+
value: true,
|
|
156
|
+
enumerable: false
|
|
157
|
+
});
|
|
158
|
+
const retry = await this.promptBuyCredits(error);
|
|
159
|
+
console.log("");
|
|
160
|
+
if (retry === "retry") return { retry: true };
|
|
161
|
+
}
|
|
162
|
+
}
|
|
163
|
+
if (agent$1 instanceof _aigne_core.ChatModel) {
|
|
164
|
+
retryPromptPromise ??= this.proxiedPrompts.select({
|
|
165
|
+
message: chalk.default.red(`Error: ${error.message}`),
|
|
166
|
+
choices: [{
|
|
167
|
+
value: "retry",
|
|
168
|
+
name: "Retry"
|
|
169
|
+
}, {
|
|
170
|
+
value: "exit",
|
|
171
|
+
name: "Exit"
|
|
172
|
+
}]
|
|
173
|
+
}).then((result) => ({ retry: result === "retry" })).finally(() => {
|
|
174
|
+
retryPromptPromise = void 0;
|
|
175
|
+
});
|
|
176
|
+
const { retry } = await retryPromptPromise;
|
|
177
|
+
if (retry) return { retry: true };
|
|
178
|
+
}
|
|
179
|
+
const contextId = context$1.id;
|
|
180
|
+
const task = this.tasks[contextId];
|
|
181
|
+
if (!task) return;
|
|
182
|
+
task.endTime = Date.now();
|
|
183
|
+
const { taskWrapper } = await task.listr.promise;
|
|
184
|
+
taskWrapper.title = await this.formatTaskTitle(agent$1, {
|
|
185
|
+
...event,
|
|
186
|
+
task,
|
|
187
|
+
usage: true,
|
|
188
|
+
time: true
|
|
189
|
+
});
|
|
190
|
+
task.reject(error);
|
|
191
|
+
};
|
|
192
|
+
return {
|
|
193
|
+
result: await listr.run(() => context.invoke(agent, input, {
|
|
194
|
+
...options,
|
|
195
|
+
hooks: (0, _aigne_core_utils_type_utils.flat)({
|
|
196
|
+
priority: "high",
|
|
197
|
+
onStart,
|
|
198
|
+
onSuccess,
|
|
199
|
+
onError
|
|
200
|
+
}, options?.hooks),
|
|
201
|
+
streaming: true,
|
|
202
|
+
newContext: false
|
|
203
|
+
})),
|
|
204
|
+
context
|
|
205
|
+
};
|
|
206
|
+
}
|
|
207
|
+
listr;
|
|
208
|
+
proxiedPrompts = new Proxy({}, { get: (_target, prop) => {
|
|
209
|
+
const method = prop === "checkbox" ? require_checkbox.default : prop === "input" ? require_terminal_input.terminalInput : _inquirer_prompts[prop];
|
|
210
|
+
if (typeof method !== "function") throw new Error(`Unsupported prompt method ${String(prop)}`);
|
|
211
|
+
return async (config) => {
|
|
212
|
+
const renderer = this.listr?.["renderer"] instanceof require_utils_listr.AIGNEListrRenderer ? this.listr["renderer"] : void 0;
|
|
213
|
+
await renderer?.pause();
|
|
214
|
+
try {
|
|
215
|
+
return await method({ ...config });
|
|
216
|
+
} finally {
|
|
217
|
+
await renderer?.resume();
|
|
218
|
+
}
|
|
219
|
+
};
|
|
220
|
+
} });
|
|
221
|
+
buyCreditsPromptPromise;
|
|
222
|
+
async promptBuyCredits(error) {
|
|
223
|
+
this.buyCreditsPromptPromise ??= (async () => {
|
|
224
|
+
return await this.proxiedPrompts.select({
|
|
225
|
+
message: require_utils_string_utils.highlightUrl(error.message),
|
|
226
|
+
choices: [{
|
|
227
|
+
name: "I have bought some credits, try again",
|
|
228
|
+
value: "retry"
|
|
229
|
+
}, {
|
|
230
|
+
name: "Exit",
|
|
231
|
+
value: "exit"
|
|
232
|
+
}]
|
|
233
|
+
});
|
|
234
|
+
})();
|
|
235
|
+
return this.buyCreditsPromptPromise.catch(() => "exit").finally(() => {
|
|
236
|
+
this.buyCreditsPromptPromise = void 0;
|
|
237
|
+
});
|
|
238
|
+
}
|
|
239
|
+
formatAigneHubCredits(credits, creditPrefix) {
|
|
240
|
+
const formattedCredits = credits % 1 !== 0 ? parseFloat(credits.toFixed(6)).toString() : credits.toFixed();
|
|
241
|
+
if (creditPrefix) return [chalk.default.grey("cost:"), chalk.default.blue(`${creditPrefix}${formattedCredits}`)];
|
|
242
|
+
return [chalk.default.blue(formattedCredits), chalk.default.grey("AIGNE Hub credits")];
|
|
243
|
+
}
|
|
244
|
+
formatTokenUsage(usage, extra) {
|
|
245
|
+
const content = [
|
|
246
|
+
[chalk.default.yellow(usage.inputTokens), chalk.default.grey("input tokens")],
|
|
247
|
+
usage.cacheReadInputTokens ? [chalk.default.green(usage.cacheReadInputTokens), chalk.default.grey("cached")] : void 0,
|
|
248
|
+
usage.cacheCreationInputTokens ? [chalk.default.yellow(usage.cacheCreationInputTokens), chalk.default.grey("cache write")] : void 0,
|
|
249
|
+
[chalk.default.cyan(usage.outputTokens), chalk.default.grey("output tokens")],
|
|
250
|
+
usage.aigneHubCredits ? this.formatAigneHubCredits(usage.aigneHubCredits, usage.creditPrefix) : void 0,
|
|
251
|
+
usage.agentCalls ? [chalk.default.magenta(usage.agentCalls), chalk.default.grey("agent calls")] : void 0
|
|
252
|
+
].filter((i) => !!i).map((i) => i.join(" "));
|
|
253
|
+
if (extra) content.unshift(...Object.entries(extra).filter(([k, v]) => k && v).map(([k, v]) => `${chalk.default.grey(k)}: ${v}`));
|
|
254
|
+
return `${chalk.default.grey("(")}${content.join(chalk.default.green(", "))}${chalk.default.grey(")")}`;
|
|
255
|
+
}
|
|
256
|
+
formatTimeUsage(startTime, endTime) {
|
|
257
|
+
const duration = endTime - startTime;
|
|
258
|
+
return chalk.default.grey(`[${require_utils_time.parseDuration(duration)}]`);
|
|
259
|
+
}
|
|
260
|
+
async formatTaskTitle(agent, { task, usage, time, input }) {
|
|
261
|
+
let title = agent.name;
|
|
262
|
+
if (agent.taskTitle) title += ` ${chalk.default.cyan(await agent.renderTaskTitle(input))}`;
|
|
263
|
+
if (usage && task?.usage) title += ` ${this.formatTokenUsage(task.usage, task.extraTitleMetadata)}`;
|
|
264
|
+
if (time && task?.startTime && task.endTime) title += ` ${this.formatTimeUsage(task.startTime, task.endTime)}`;
|
|
265
|
+
return title;
|
|
266
|
+
}
|
|
267
|
+
marked = new marked.Marked().use({ walkTokens: (token) => {
|
|
268
|
+
if (token.type === "code") {
|
|
269
|
+
if (typeof token.lang === "string") token.lang = token.lang.trim().split(/\s+/)[0];
|
|
270
|
+
}
|
|
271
|
+
} }, (0, _aigne_marked_terminal.markedTerminal)({ forceHyperLink: false }, { theme: { string: chalk.default.green } }));
|
|
272
|
+
get outputKey() {
|
|
273
|
+
return this.options.outputKey || _aigne_core.DEFAULT_OUTPUT_KEY;
|
|
274
|
+
}
|
|
275
|
+
get outputFileKey() {
|
|
276
|
+
return this.options.outputFileKey || _aigne_core.DEFAULT_OUTPUT_FILE_KEY;
|
|
277
|
+
}
|
|
278
|
+
formatRequest(agent, _context, m = {}, { running = false } = {}) {
|
|
279
|
+
const prefix = `${chalk.default.grey(_aigne_listr2.figures.pointer)} 💬 `;
|
|
280
|
+
const inputKey = agent instanceof _aigne_core.AIAgent ? agent.inputKey : void 0;
|
|
281
|
+
const msg = inputKey ? m[inputKey] : void 0;
|
|
282
|
+
const message = inputKey ? (0, _aigne_core_utils_type_utils.omit)(m, inputKey) : m;
|
|
283
|
+
const r = [msg && typeof msg === "string" ? this.marked.parse(msg, { async: false }).trim() : void 0, Object.keys(message).length > 0 ? (0, node_util.inspect)(message, {
|
|
284
|
+
colors: true,
|
|
285
|
+
...running ? this.runningInspectOptions : void 0
|
|
286
|
+
}) : void 0].filter(Boolean).join(node_os.EOL).trim();
|
|
287
|
+
if (!r) return void 0;
|
|
288
|
+
return `${prefix}${r}`;
|
|
289
|
+
}
|
|
290
|
+
formatResult(agent, context, m = {}, { running = false, renderImage = false } = {}) {
|
|
291
|
+
const { isTTY } = process.stdout;
|
|
292
|
+
const outputKey = this.outputKey || (agent instanceof _aigne_core.AIAgent ? agent.outputKey : void 0);
|
|
293
|
+
const prefix = `${chalk.default.grey(_aigne_listr2.figures.tick)} 🤖 ${this.formatTokenUsage(context.usage)}`;
|
|
294
|
+
const msg = outputKey ? m[outputKey] : void 0;
|
|
295
|
+
const message = outputKey ? (0, _aigne_core_utils_type_utils.omit)(m, outputKey, this.outputFileKey) : m;
|
|
296
|
+
const text = msg && typeof msg === "string" ? isTTY ? this.marked.parse(msg, { async: false }).trim() : msg : void 0;
|
|
297
|
+
const json = Object.keys(message).length > 0 ? (0, node_util.inspect)(message, {
|
|
298
|
+
colors: isTTY,
|
|
299
|
+
...running ? this.runningInspectOptions : void 0
|
|
300
|
+
}) : void 0;
|
|
301
|
+
if (renderImage) return this.formatResultData(m).then((images) => {
|
|
302
|
+
return [
|
|
303
|
+
prefix,
|
|
304
|
+
text,
|
|
305
|
+
images,
|
|
306
|
+
json
|
|
307
|
+
].filter(Boolean).join(node_os.EOL.repeat(2));
|
|
308
|
+
});
|
|
309
|
+
return [
|
|
310
|
+
prefix,
|
|
311
|
+
text,
|
|
312
|
+
json
|
|
313
|
+
].filter(Boolean).join(node_os.EOL.repeat(2));
|
|
314
|
+
}
|
|
315
|
+
async formatResultData(output) {
|
|
316
|
+
const files = output[this.outputFileKey];
|
|
317
|
+
if (!Array.isArray(files)) return;
|
|
318
|
+
const options = { height: 30 };
|
|
319
|
+
return (await Promise.all(files.map(async (item) => {
|
|
320
|
+
const image = item.type === "local" ? await terminal_image.default.file(item.path, options) : item.type === "file" ? await terminal_image.default.buffer(Buffer.from(item.data, "base64"), options) : void 0;
|
|
321
|
+
const link = item.type === "local" ? (0, ufo.withProtocol)(item.path, "file://") : item.type === "url" ? item.url : void 0;
|
|
322
|
+
return [image, [
|
|
323
|
+
link ? chalk.default.cyan((0, terminal_link.default)(link, link)) : void 0,
|
|
324
|
+
item.filename,
|
|
325
|
+
item.mimeType ? chalk.default.gray(item.mimeType) : void 0
|
|
326
|
+
].filter(Boolean).join(" ")].filter(Boolean).join(node_os.EOL);
|
|
327
|
+
}))).filter(Boolean).join(node_os.EOL);
|
|
328
|
+
}
|
|
329
|
+
runningInspectOptions = {
|
|
330
|
+
maxArrayLength: 3,
|
|
331
|
+
maxStringLength: 200
|
|
332
|
+
};
|
|
333
|
+
};
|
|
334
|
+
|
|
335
|
+
//#endregion
|
|
336
|
+
exports.TerminalTracer = TerminalTracer;
|