@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 { AgentRunCommonOptions } from "./yargs.mjs";
|
|
2
|
+
import { ChatLoopOptions } from "./run-chat-loop.mjs";
|
|
3
|
+
import * as _aigne_core0 from "@aigne/core";
|
|
4
|
+
import { AIGNE, Agent, ChatModelInputOptions, Message } from "@aigne/core";
|
|
5
|
+
import { PromiseOrValue } from "@aigne/core/utils/type-utils";
|
|
6
|
+
|
|
7
|
+
//#region src/utils/run-with-aigne.d.ts
|
|
8
|
+
declare function parseAgentInputByCommander(agent: Agent, options?: AgentRunCommonOptions & {
|
|
9
|
+
inputKey?: string;
|
|
10
|
+
argv?: string[];
|
|
11
|
+
defaultInput?: string | Message;
|
|
12
|
+
}): Promise<Message>;
|
|
13
|
+
declare function loadAIGNEWithCmdOptions(): Promise<AIGNE<_aigne_core0.UserContext>>;
|
|
14
|
+
declare function runWithAIGNE(agentCreator: ((aigne: AIGNE) => PromiseOrValue<Agent>) | Agent, {
|
|
15
|
+
aigne,
|
|
16
|
+
argv,
|
|
17
|
+
chatLoopOptions,
|
|
18
|
+
modelOptions,
|
|
19
|
+
outputKey
|
|
20
|
+
}?: {
|
|
21
|
+
aigne?: AIGNE;
|
|
22
|
+
argv?: typeof process.argv;
|
|
23
|
+
chatLoopOptions?: ChatLoopOptions;
|
|
24
|
+
modelOptions?: ChatModelInputOptions;
|
|
25
|
+
outputKey?: string;
|
|
26
|
+
}): Promise<void>;
|
|
27
|
+
declare function runAgentWithAIGNE(aigne: AIGNE, agent: Agent, {
|
|
28
|
+
userId,
|
|
29
|
+
sessionId,
|
|
30
|
+
outputKey,
|
|
31
|
+
outputFileKey,
|
|
32
|
+
chatLoopOptions,
|
|
33
|
+
...options
|
|
34
|
+
}?: {
|
|
35
|
+
userId?: string;
|
|
36
|
+
sessionId?: string;
|
|
37
|
+
outputKey?: string;
|
|
38
|
+
outputFileKey?: string;
|
|
39
|
+
chatLoopOptions?: ChatLoopOptions;
|
|
40
|
+
input?: Message;
|
|
41
|
+
} & Omit<AgentRunCommonOptions, "input">): Promise<{
|
|
42
|
+
result: Message;
|
|
43
|
+
} | undefined>;
|
|
44
|
+
//#endregion
|
|
45
|
+
export { loadAIGNEWithCmdOptions, parseAgentInputByCommander, runAgentWithAIGNE, runWithAIGNE };
|
|
46
|
+
//# sourceMappingURL=run-with-aigne.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"run-with-aigne.d.mts","names":[],"sources":["../../src/utils/run-with-aigne.ts"],"mappings":";;;;;;;iBAqCsB,0BAAA,CAAA,KAAA,EACb,KAAA,EAAA,OAAA,GACE,qBAAA;EAAA,QAAA;EAAA,IAAA;EAAA,YAAA,YAGiB,OAAA;AAAA,IAEzB,OAAA,CAAQ,OAAA;AAAA,iBAyBW,uBAAA,CAAA,GAAuB,OAAA,CAAA,KAAA,CAAA,YAAA,CAAA,WAAA;AAAA,iBAcvB,YAAA,CAAA,YAAA,IAAA,KAAA,EACG,KAAA,KAAU,cAAA,CAAe,KAAA,KAAU,KAAA;EAAA,KAAA;EAAA,IAAA;EAAA,eAAA;EAAA,YAAA;EAAA;AAAA;EAAA,KAAA,GAQhD,KAAA;EAAA,IAAA,UACM,OAAA,CAAQ,IAAA;EAAA,eAAA,GACJ,eAAA;EAAA,YAAA,GACH,qBAAA;EAAA,SAAA;AAAA,IAEX,OAAA;AAAA,iBAuFc,iBAAA,CAAA,KAAA,EACb,KAAA,EAAA,KAAA,EACA,KAAA;EAAA,MAAA;EAAA,SAAA;EAAA,SAAA;EAAA,aAAA;EAAA,eAAA;EAAA,GAAA;AAAA;EAAA,MAAA;EAAA,SAAA;EAAA,SAAA;EAAA,aAAA;EAAA,eAAA,GAaa,eAAA;EAAA,KAAA,GACV,OAAA;AAAA,IACN,IAAA,CAAK,qBAAA,aAAoC,OAAA;EAAA,MAAA"}
|
|
@@ -0,0 +1,126 @@
|
|
|
1
|
+
import { DEFAULT_AFS_EXPLORER_PORT, DEFAULT_USER_ID } from "../constants.mjs";
|
|
2
|
+
import { loadAIGNE, printChatModelInfoBox } from "./load-aigne.mjs";
|
|
3
|
+
import { parseAgentInput, withAgentInputSchema, withRunAgentCommonOptions } from "./yargs.mjs";
|
|
4
|
+
import { TerminalTracer } from "../tracer/terminal.mjs";
|
|
5
|
+
import { DEFAULT_CHAT_INPUT_KEY, runChatLoopInTerminal } from "./run-chat-loop.mjs";
|
|
6
|
+
import { logger } from "@aigne/core/utils/logger";
|
|
7
|
+
import chalk from "chalk";
|
|
8
|
+
import yargs from "yargs";
|
|
9
|
+
import { dirname, isAbsolute, join } from "node:path";
|
|
10
|
+
import { fileURLToPath } from "node:url";
|
|
11
|
+
import { mkdir, stat, writeFile } from "node:fs/promises";
|
|
12
|
+
import { AIAgent, DEFAULT_OUTPUT_KEY, UserAgent } from "@aigne/core";
|
|
13
|
+
import { isEmpty, isNil, omitBy, pick } from "@aigne/core/utils/type-utils";
|
|
14
|
+
import { exists } from "@aigne/agent-library/utils/fs";
|
|
15
|
+
import { detect } from "detect-port";
|
|
16
|
+
import { isatty } from "node:tty";
|
|
17
|
+
import { v7 } from "@aigne/uuid";
|
|
18
|
+
import { startExplorer } from "@aigne/afs-explorer";
|
|
19
|
+
import { hideBin } from "yargs/helpers";
|
|
20
|
+
|
|
21
|
+
//#region src/utils/run-with-aigne.ts
|
|
22
|
+
async function parseAgentInputByCommander(agent, options = {}) {
|
|
23
|
+
const args = await withAgentInputSchema(yargs(), agent).showHelpOnFail(false).fail(() => {}).parseAsync(options.argv ?? process.argv);
|
|
24
|
+
const input = await parseAgentInput({
|
|
25
|
+
...args,
|
|
26
|
+
input: options.input || args.input
|
|
27
|
+
}, agent);
|
|
28
|
+
if (isEmpty(input)) {
|
|
29
|
+
const defaultInput = options.defaultInput || process.env.INITIAL_CALL;
|
|
30
|
+
Object.assign(input, typeof defaultInput === "string" ? { [options?.inputKey || (agent instanceof AIAgent ? agent.inputKey : void 0) || DEFAULT_CHAT_INPUT_KEY]: defaultInput } : defaultInput);
|
|
31
|
+
}
|
|
32
|
+
return input;
|
|
33
|
+
}
|
|
34
|
+
async function loadAIGNEWithCmdOptions() {
|
|
35
|
+
return await loadAIGNE({ modelOptions: { ...omitBy(pick(await withRunAgentCommonOptions(yargs()).strict(false).parseAsync(hideBin(process.argv)), "model", "temperature", "topP", "presencePenalty", "frequencyPenalty"), (v) => isNil(v)) } });
|
|
36
|
+
}
|
|
37
|
+
async function runWithAIGNE(agentCreator, { aigne, argv = process.argv, chatLoopOptions, modelOptions, outputKey } = {}) {
|
|
38
|
+
await yargs().command("$0", "Execute an AI agent using the AIGNE framework with specified configuration", (yargs$1) => withRunAgentCommonOptions(yargs$1), async (options) => {
|
|
39
|
+
if (options.logLevel) logger.level = options.logLevel;
|
|
40
|
+
aigne ??= await loadAIGNE({ modelOptions: {
|
|
41
|
+
...modelOptions,
|
|
42
|
+
...omitBy(pick(options, "model", "temperature", "topP", "presencePenalty", "frequencyPenalty"), (v) => isNil(v))
|
|
43
|
+
} });
|
|
44
|
+
let explorerServer;
|
|
45
|
+
let explorerServerURL;
|
|
46
|
+
try {
|
|
47
|
+
const agent = typeof agentCreator === "function" ? await agentCreator(aigne) : agentCreator;
|
|
48
|
+
const input = await parseAgentInputByCommander(agent, {
|
|
49
|
+
...options,
|
|
50
|
+
inputKey: chatLoopOptions?.inputKey,
|
|
51
|
+
defaultInput: chatLoopOptions?.initialCall || chatLoopOptions?.defaultQuestion
|
|
52
|
+
});
|
|
53
|
+
if (agent.afs) {
|
|
54
|
+
const port = await detect(DEFAULT_AFS_EXPLORER_PORT);
|
|
55
|
+
explorerServer = await startExplorer(agent.afs, {
|
|
56
|
+
port,
|
|
57
|
+
distPath: dirname(fileURLToPath(import.meta.resolve("@aigne/afs-explorer/index.html")))
|
|
58
|
+
});
|
|
59
|
+
explorerServerURL = `http://localhost:${port}`;
|
|
60
|
+
}
|
|
61
|
+
if (aigne.model) {
|
|
62
|
+
const lines = [];
|
|
63
|
+
if (explorerServerURL) lines.push(`${chalk.cyan("AFS Explorer")}: ${chalk.green(explorerServerURL)}`);
|
|
64
|
+
await printChatModelInfoBox(aigne.model, lines);
|
|
65
|
+
}
|
|
66
|
+
if (chatLoopOptions?.welcome) console.log(chatLoopOptions.welcome);
|
|
67
|
+
await runAgentWithAIGNE(aigne, agent, {
|
|
68
|
+
...options,
|
|
69
|
+
outputKey: outputKey || options.outputKey,
|
|
70
|
+
chatLoopOptions,
|
|
71
|
+
input,
|
|
72
|
+
sessionId: chatLoopOptions?.sessionId || v7(),
|
|
73
|
+
userId: DEFAULT_USER_ID
|
|
74
|
+
});
|
|
75
|
+
} finally {
|
|
76
|
+
await explorerServer?.stop();
|
|
77
|
+
await aigne.shutdown();
|
|
78
|
+
}
|
|
79
|
+
}).alias("h", "help").alias("v", "version").fail((message, error, yargs$1) => {
|
|
80
|
+
if (!error) yargs$1.showHelp();
|
|
81
|
+
console.error(`\n${message || error?.message}`);
|
|
82
|
+
process.exit(1);
|
|
83
|
+
}).parseAsync(hideBin(argv)).catch((error) => {
|
|
84
|
+
console.error(`${chalk.red("Error:")} ${error.message}`);
|
|
85
|
+
process.exit(1);
|
|
86
|
+
});
|
|
87
|
+
}
|
|
88
|
+
async function runAgentWithAIGNE(aigne, agent, { userId, sessionId, outputKey, outputFileKey, chatLoopOptions, ...options } = {}) {
|
|
89
|
+
if (options.output) {
|
|
90
|
+
const outputPath = isAbsolute(options.output) ? options.output : join(process.cwd(), options.output);
|
|
91
|
+
if (await exists(outputPath)) {
|
|
92
|
+
const s = await stat(outputPath);
|
|
93
|
+
if (!s.isFile()) throw new Error(`Output path ${outputPath} is not a file`);
|
|
94
|
+
if (s.size > 0 && !options.force) throw new Error(`Output file ${outputPath} already exists. Use --force to overwrite.`);
|
|
95
|
+
} else await mkdir(dirname(outputPath), { recursive: true });
|
|
96
|
+
await writeFile(outputPath, "", "utf8");
|
|
97
|
+
}
|
|
98
|
+
if (options.interactive) {
|
|
99
|
+
if (!isatty(process.stdout.fd)) throw new Error("--interactive mode requires a TTY terminal");
|
|
100
|
+
await runChatLoopInTerminal(agent instanceof UserAgent ? agent : aigne.invoke(agent), {
|
|
101
|
+
...chatLoopOptions,
|
|
102
|
+
outputKey,
|
|
103
|
+
inputFileKey: agent instanceof AIAgent ? agent.inputFileKey : void 0,
|
|
104
|
+
input: options.input,
|
|
105
|
+
sessionId,
|
|
106
|
+
userId
|
|
107
|
+
});
|
|
108
|
+
return;
|
|
109
|
+
}
|
|
110
|
+
const { result } = await new TerminalTracer(aigne.newContext(), {
|
|
111
|
+
outputKey,
|
|
112
|
+
outputFileKey
|
|
113
|
+
}).run(agent, options.input ?? {});
|
|
114
|
+
if (options.output) {
|
|
115
|
+
const message = result[outputKey || DEFAULT_OUTPUT_KEY];
|
|
116
|
+
const content = typeof message === "string" ? message : JSON.stringify(result, null, 2);
|
|
117
|
+
const path$1 = isAbsolute(options.output) ? options.output : join(process.cwd(), options.output);
|
|
118
|
+
await mkdir(dirname(path$1), { recursive: true });
|
|
119
|
+
await writeFile(path$1, content, "utf8");
|
|
120
|
+
}
|
|
121
|
+
return { result };
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
//#endregion
|
|
125
|
+
export { loadAIGNEWithCmdOptions, parseAgentInputByCommander, runAgentWithAIGNE, runWithAIGNE };
|
|
126
|
+
//# sourceMappingURL=run-with-aigne.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"run-with-aigne.mjs","names":["yargs","path"],"sources":["../../src/utils/run-with-aigne.ts"],"sourcesContent":["import { mkdir, stat, writeFile } from \"node:fs/promises\";\nimport { dirname, isAbsolute, join } from \"node:path\";\nimport { isatty } from \"node:tty\";\nimport { fileURLToPath } from \"node:url\";\nimport { type ExplorerServer, startExplorer } from \"@aigne/afs-explorer\";\nimport { exists } from \"@aigne/agent-library/utils/fs\";\nimport {\n type Agent,\n AIAgent,\n type AIGNE,\n type ChatModelInputOptions,\n DEFAULT_OUTPUT_KEY,\n type Message,\n UserAgent,\n} from \"@aigne/core\";\nimport { logger } from \"@aigne/core/utils/logger\";\nimport { isEmpty, isNil, omitBy, type PromiseOrValue, pick } from \"@aigne/core/utils/type-utils\";\nimport { v7 } from \"@aigne/uuid\";\nimport chalk from \"chalk\";\nimport { detect } from \"detect-port\";\nimport yargs from \"yargs\";\nimport { hideBin } from \"yargs/helpers\";\nimport { DEFAULT_AFS_EXPLORER_PORT, DEFAULT_USER_ID } from \"../constants.js\";\nimport { TerminalTracer } from \"../tracer/terminal.js\";\nimport { loadAIGNE, printChatModelInfoBox } from \"./load-aigne.js\";\nimport {\n type ChatLoopOptions,\n DEFAULT_CHAT_INPUT_KEY,\n runChatLoopInTerminal,\n} from \"./run-chat-loop.js\";\nimport {\n type AgentRunCommonOptions,\n parseAgentInput,\n withAgentInputSchema,\n withRunAgentCommonOptions,\n} from \"./yargs.js\";\n\nexport async function parseAgentInputByCommander(\n agent: Agent,\n options: AgentRunCommonOptions & {\n inputKey?: string;\n argv?: string[];\n defaultInput?: string | Message;\n } = {},\n): Promise<Message> {\n const args = await withAgentInputSchema(yargs(), agent)\n .showHelpOnFail(false)\n .fail(() => {})\n .parseAsync(options.argv ?? process.argv);\n const input = await parseAgentInput({ ...args, input: options.input || args.input }, agent);\n\n if (isEmpty(input)) {\n const defaultInput = options.defaultInput || process.env.INITIAL_CALL;\n\n Object.assign(\n input,\n typeof defaultInput === \"string\"\n ? {\n [options?.inputKey ||\n (agent instanceof AIAgent ? agent.inputKey : undefined) ||\n DEFAULT_CHAT_INPUT_KEY]: defaultInput,\n }\n : defaultInput,\n );\n }\n\n return input;\n}\n\nexport async function loadAIGNEWithCmdOptions() {\n const options = await withRunAgentCommonOptions(yargs())\n .strict(false)\n .parseAsync(hideBin(process.argv));\n return await loadAIGNE({\n modelOptions: {\n ...omitBy(\n pick(options, \"model\", \"temperature\", \"topP\", \"presencePenalty\", \"frequencyPenalty\"),\n (v) => isNil(v),\n ),\n },\n });\n}\n\nexport async function runWithAIGNE(\n agentCreator: ((aigne: AIGNE) => PromiseOrValue<Agent>) | Agent,\n {\n aigne,\n argv = process.argv,\n chatLoopOptions,\n modelOptions,\n outputKey,\n }: {\n aigne?: AIGNE;\n argv?: typeof process.argv;\n chatLoopOptions?: ChatLoopOptions;\n modelOptions?: ChatModelInputOptions;\n outputKey?: string;\n } = {},\n) {\n await yargs()\n .command<AgentRunCommonOptions>(\n \"$0\",\n \"Execute an AI agent using the AIGNE framework with specified configuration\",\n (yargs) => withRunAgentCommonOptions(yargs),\n async (options) => {\n if (options.logLevel) {\n logger.level = options.logLevel;\n }\n\n aigne ??= await loadAIGNE({\n modelOptions: {\n ...modelOptions,\n ...omitBy(\n pick(options, \"model\", \"temperature\", \"topP\", \"presencePenalty\", \"frequencyPenalty\"),\n (v) => isNil(v),\n ),\n },\n });\n\n let explorerServer: ExplorerServer | undefined;\n let explorerServerURL: string | undefined;\n\n try {\n const agent =\n typeof agentCreator === \"function\" ? await agentCreator(aigne) : agentCreator;\n\n const input = await parseAgentInputByCommander(agent, {\n ...options,\n inputKey: chatLoopOptions?.inputKey,\n defaultInput: chatLoopOptions?.initialCall || chatLoopOptions?.defaultQuestion,\n });\n\n if (agent.afs) {\n const port = await detect(DEFAULT_AFS_EXPLORER_PORT);\n explorerServer = await startExplorer(agent.afs, {\n port,\n distPath: dirname(\n fileURLToPath(import.meta.resolve(\"@aigne/afs-explorer/index.html\")),\n ),\n });\n explorerServerURL = `http://localhost:${port}`;\n }\n\n if (aigne.model) {\n const lines: string[] = [];\n\n if (explorerServerURL) {\n lines.push(`${chalk.cyan(\"AFS Explorer\")}: ${chalk.green(explorerServerURL)}`);\n }\n\n await printChatModelInfoBox(aigne.model, lines);\n }\n\n if (chatLoopOptions?.welcome) console.log(chatLoopOptions.welcome);\n\n await runAgentWithAIGNE(aigne, agent, {\n ...options,\n outputKey: outputKey || options.outputKey,\n chatLoopOptions,\n input,\n sessionId: chatLoopOptions?.sessionId || v7(),\n userId: DEFAULT_USER_ID,\n });\n } finally {\n await explorerServer?.stop();\n await aigne.shutdown();\n }\n },\n )\n .alias(\"h\", \"help\")\n .alias(\"v\", \"version\")\n .fail((message, error, yargs) => {\n if (!error) yargs.showHelp();\n\n console.error(`\\n${message || error?.message}`);\n process.exit(1);\n })\n .parseAsync(hideBin(argv))\n .catch((error) => {\n console.error(`${chalk.red(\"Error:\")} ${error.message}`);\n process.exit(1);\n });\n}\n\nexport async function runAgentWithAIGNE(\n aigne: AIGNE,\n agent: Agent,\n {\n userId,\n sessionId,\n outputKey,\n outputFileKey,\n chatLoopOptions,\n ...options\n }: {\n userId?: string;\n sessionId?: string;\n outputKey?: string;\n outputFileKey?: string;\n chatLoopOptions?: ChatLoopOptions;\n input?: Message;\n } & Omit<AgentRunCommonOptions, \"input\"> = {},\n) {\n if (options.output) {\n const outputPath = isAbsolute(options.output)\n ? options.output\n : join(process.cwd(), options.output);\n if (await exists(outputPath)) {\n const s = await stat(outputPath);\n if (!s.isFile()) throw new Error(`Output path ${outputPath} is not a file`);\n if (s.size > 0 && !options.force) {\n throw new Error(`Output file ${outputPath} already exists. Use --force to overwrite.`);\n }\n } else {\n await mkdir(dirname(outputPath), { recursive: true });\n }\n await writeFile(outputPath, \"\", \"utf8\");\n }\n\n if (options.interactive) {\n if (!isatty(process.stdout.fd)) {\n throw new Error(\"--interactive mode requires a TTY terminal\");\n }\n\n const userAgent = agent instanceof UserAgent ? agent : aigne.invoke(agent);\n\n await runChatLoopInTerminal(userAgent, {\n ...chatLoopOptions,\n outputKey,\n inputFileKey: agent instanceof AIAgent ? agent.inputFileKey : undefined,\n input: options.input,\n sessionId,\n userId,\n });\n\n return;\n }\n\n const tracer = new TerminalTracer(aigne.newContext(), { outputKey, outputFileKey });\n\n const { result } = await tracer.run(agent, options.input ?? {});\n\n if (options.output) {\n const message = result[outputKey || DEFAULT_OUTPUT_KEY];\n const content = typeof message === \"string\" ? message : JSON.stringify(result, null, 2);\n const path = isAbsolute(options.output) ? options.output : join(process.cwd(), options.output);\n await mkdir(dirname(path), { recursive: true });\n await writeFile(path, content, \"utf8\");\n }\n\n return { result };\n}\n"],"mappings":"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"}
|
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
const require_rolldown_runtime = require('../_virtual/rolldown_runtime.cjs');
|
|
2
|
+
const require_constants = require('../constants.cjs');
|
|
3
|
+
let _aigne_core = require("@aigne/core");
|
|
4
|
+
let zod = require("zod");
|
|
5
|
+
let _aigne_core_utils_promise = require("@aigne/core/utils/promise");
|
|
6
|
+
let _modelcontextprotocol_sdk_server_mcp_js = require("@modelcontextprotocol/sdk/server/mcp.js");
|
|
7
|
+
let _modelcontextprotocol_sdk_server_streamableHttp_js = require("@modelcontextprotocol/sdk/server/streamableHttp.js");
|
|
8
|
+
let express = require("express");
|
|
9
|
+
express = require_rolldown_runtime.__toESM(express);
|
|
10
|
+
|
|
11
|
+
//#region src/utils/serve-mcp.ts
|
|
12
|
+
async function serveMCPServer({ pathname = "/mcp", aigne, host = "localhost", port }) {
|
|
13
|
+
const app = (0, express.default)();
|
|
14
|
+
app.use((0, express.json)());
|
|
15
|
+
const router = (0, express.Router)();
|
|
16
|
+
app.use(router);
|
|
17
|
+
router.post(pathname, async (req, res) => {
|
|
18
|
+
try {
|
|
19
|
+
const server = createMcpServer(aigne);
|
|
20
|
+
const transport = new _modelcontextprotocol_sdk_server_streamableHttp_js.StreamableHTTPServerTransport({ sessionIdGenerator: void 0 });
|
|
21
|
+
await server.connect(transport);
|
|
22
|
+
await transport.handleRequest(req, res, req.body);
|
|
23
|
+
res.on("close", async () => {
|
|
24
|
+
await transport.close();
|
|
25
|
+
await server.close();
|
|
26
|
+
});
|
|
27
|
+
} catch (error) {
|
|
28
|
+
console.error("Error handling MCP request:", error);
|
|
29
|
+
if (!res.headersSent) res.status(500).json({
|
|
30
|
+
jsonrpc: "2.0",
|
|
31
|
+
error: {
|
|
32
|
+
code: -32603,
|
|
33
|
+
message: error.message
|
|
34
|
+
},
|
|
35
|
+
id: null
|
|
36
|
+
});
|
|
37
|
+
}
|
|
38
|
+
});
|
|
39
|
+
router.get(pathname, async (_, res) => {
|
|
40
|
+
res.writeHead(405).end(JSON.stringify({
|
|
41
|
+
jsonrpc: "2.0",
|
|
42
|
+
error: {
|
|
43
|
+
code: -32e3,
|
|
44
|
+
message: "Method not allowed."
|
|
45
|
+
},
|
|
46
|
+
id: null
|
|
47
|
+
}));
|
|
48
|
+
});
|
|
49
|
+
router.delete(pathname, async (_, res) => {
|
|
50
|
+
res.writeHead(405).end(JSON.stringify({
|
|
51
|
+
jsonrpc: "2.0",
|
|
52
|
+
error: {
|
|
53
|
+
code: -32e3,
|
|
54
|
+
message: "Method not allowed."
|
|
55
|
+
},
|
|
56
|
+
id: null
|
|
57
|
+
}));
|
|
58
|
+
});
|
|
59
|
+
const { promise, resolve, reject } = (0, _aigne_core_utils_promise.promiseWithResolvers)();
|
|
60
|
+
const httpServer = app.listen(port, host, (error) => {
|
|
61
|
+
if (error) reject(error);
|
|
62
|
+
resolve();
|
|
63
|
+
});
|
|
64
|
+
await promise;
|
|
65
|
+
return httpServer;
|
|
66
|
+
}
|
|
67
|
+
function createMcpServer(aigne) {
|
|
68
|
+
const server = new _modelcontextprotocol_sdk_server_mcp_js.McpServer({
|
|
69
|
+
name: aigne.name || "aigne-mcp-server",
|
|
70
|
+
version: require_constants.AIGNE_CLI_VERSION
|
|
71
|
+
}, {
|
|
72
|
+
capabilities: { tools: {} },
|
|
73
|
+
instructions: aigne.description
|
|
74
|
+
});
|
|
75
|
+
for (const agent of aigne.mcpServer?.agents ?? []) {
|
|
76
|
+
const schema = agent.inputSchema;
|
|
77
|
+
if (!(schema instanceof zod.ZodObject)) throw new Error("Agent input schema must be a ZodObject");
|
|
78
|
+
server.tool(agent.name, agent.description || "", schema.shape, async (input) => {
|
|
79
|
+
const result = await aigne.invoke(agent, input);
|
|
80
|
+
return { content: [{
|
|
81
|
+
type: "text",
|
|
82
|
+
text: agent instanceof _aigne_core.AIAgent && result[agent.outputKey] || JSON.stringify(result)
|
|
83
|
+
}] };
|
|
84
|
+
});
|
|
85
|
+
}
|
|
86
|
+
return server;
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
//#endregion
|
|
90
|
+
exports.createMcpServer = createMcpServer;
|
|
91
|
+
exports.serveMCPServer = serveMCPServer;
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { AIGNE } from "@aigne/core";
|
|
2
|
+
import * as http0 from "http";
|
|
3
|
+
import { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
|
|
4
|
+
|
|
5
|
+
//#region src/utils/serve-mcp.d.ts
|
|
6
|
+
declare function serveMCPServer({
|
|
7
|
+
pathname,
|
|
8
|
+
aigne,
|
|
9
|
+
host,
|
|
10
|
+
port
|
|
11
|
+
}: {
|
|
12
|
+
pathname?: string;
|
|
13
|
+
aigne: AIGNE;
|
|
14
|
+
host?: string;
|
|
15
|
+
port: number;
|
|
16
|
+
}): Promise<http0.Server<typeof http0.IncomingMessage, typeof http0.ServerResponse>>;
|
|
17
|
+
declare function createMcpServer(aigne: AIGNE): McpServer;
|
|
18
|
+
//#endregion
|
|
19
|
+
export { createMcpServer, serveMCPServer };
|
|
20
|
+
//# sourceMappingURL=serve-mcp.d.cts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"serve-mcp.d.cts","names":[],"sources":["../../src/utils/serve-mcp.ts"],"mappings":";;;;;iBAQsB,cAAA,CAAA;EAAA,QAAA;EAAA,KAAA;EAAA,IAAA;EAAA;AAAA;EAAA,QAAA;EAAA,KAAA,EAOb,KAAA;EAAA,IAAA;EAAA,IAAA;AAAA,IAGR,OAAA,CAAA,KAAA,CAAA,MAAA,QAHa,KAAA,CAGb,eAAA,SAAA,KAAA,CAAA,cAAA;AAAA,iBA4Ee,eAAA,CAAA,KAAA,EAAuB,KAAA,GAAK,SAAA"}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { AIGNE } from "@aigne/core";
|
|
2
|
+
import { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
|
|
3
|
+
import * as http0 from "http";
|
|
4
|
+
|
|
5
|
+
//#region src/utils/serve-mcp.d.ts
|
|
6
|
+
declare function serveMCPServer({
|
|
7
|
+
pathname,
|
|
8
|
+
aigne,
|
|
9
|
+
host,
|
|
10
|
+
port
|
|
11
|
+
}: {
|
|
12
|
+
pathname?: string;
|
|
13
|
+
aigne: AIGNE;
|
|
14
|
+
host?: string;
|
|
15
|
+
port: number;
|
|
16
|
+
}): Promise<http0.Server<typeof http0.IncomingMessage, typeof http0.ServerResponse>>;
|
|
17
|
+
declare function createMcpServer(aigne: AIGNE): McpServer;
|
|
18
|
+
//#endregion
|
|
19
|
+
export { createMcpServer, serveMCPServer };
|
|
20
|
+
//# sourceMappingURL=serve-mcp.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"serve-mcp.d.mts","names":[],"sources":["../../src/utils/serve-mcp.ts"],"mappings":";;;;;iBAQsB,cAAA,CAAA;EAAA,QAAA;EAAA,KAAA;EAAA,IAAA;EAAA;AAAA;EAAA,QAAA;EAAA,KAAA,EAOb,KAAA;EAAA,IAAA;EAAA,IAAA;AAAA,IAGR,OAAA,CAAA,KAAA,CAAA,MAAA,QAHa,KAAA,CAGb,eAAA,SAAA,KAAA,CAAA,cAAA;AAAA,iBA4Ee,eAAA,CAAA,KAAA,EAAuB,KAAA,GAAK,SAAA"}
|
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
import { AIGNE_CLI_VERSION } from "../constants.mjs";
|
|
2
|
+
import { AIAgent } from "@aigne/core";
|
|
3
|
+
import { ZodObject } from "zod";
|
|
4
|
+
import { promiseWithResolvers } from "@aigne/core/utils/promise";
|
|
5
|
+
import { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
|
|
6
|
+
import { StreamableHTTPServerTransport } from "@modelcontextprotocol/sdk/server/streamableHttp.js";
|
|
7
|
+
import express, { Router, json } from "express";
|
|
8
|
+
|
|
9
|
+
//#region src/utils/serve-mcp.ts
|
|
10
|
+
async function serveMCPServer({ pathname = "/mcp", aigne, host = "localhost", port }) {
|
|
11
|
+
const app = express();
|
|
12
|
+
app.use(json());
|
|
13
|
+
const router = Router();
|
|
14
|
+
app.use(router);
|
|
15
|
+
router.post(pathname, async (req, res) => {
|
|
16
|
+
try {
|
|
17
|
+
const server = createMcpServer(aigne);
|
|
18
|
+
const transport = new StreamableHTTPServerTransport({ sessionIdGenerator: void 0 });
|
|
19
|
+
await server.connect(transport);
|
|
20
|
+
await transport.handleRequest(req, res, req.body);
|
|
21
|
+
res.on("close", async () => {
|
|
22
|
+
await transport.close();
|
|
23
|
+
await server.close();
|
|
24
|
+
});
|
|
25
|
+
} catch (error) {
|
|
26
|
+
console.error("Error handling MCP request:", error);
|
|
27
|
+
if (!res.headersSent) res.status(500).json({
|
|
28
|
+
jsonrpc: "2.0",
|
|
29
|
+
error: {
|
|
30
|
+
code: -32603,
|
|
31
|
+
message: error.message
|
|
32
|
+
},
|
|
33
|
+
id: null
|
|
34
|
+
});
|
|
35
|
+
}
|
|
36
|
+
});
|
|
37
|
+
router.get(pathname, async (_, res) => {
|
|
38
|
+
res.writeHead(405).end(JSON.stringify({
|
|
39
|
+
jsonrpc: "2.0",
|
|
40
|
+
error: {
|
|
41
|
+
code: -32e3,
|
|
42
|
+
message: "Method not allowed."
|
|
43
|
+
},
|
|
44
|
+
id: null
|
|
45
|
+
}));
|
|
46
|
+
});
|
|
47
|
+
router.delete(pathname, async (_, res) => {
|
|
48
|
+
res.writeHead(405).end(JSON.stringify({
|
|
49
|
+
jsonrpc: "2.0",
|
|
50
|
+
error: {
|
|
51
|
+
code: -32e3,
|
|
52
|
+
message: "Method not allowed."
|
|
53
|
+
},
|
|
54
|
+
id: null
|
|
55
|
+
}));
|
|
56
|
+
});
|
|
57
|
+
const { promise, resolve, reject } = promiseWithResolvers();
|
|
58
|
+
const httpServer = app.listen(port, host, (error) => {
|
|
59
|
+
if (error) reject(error);
|
|
60
|
+
resolve();
|
|
61
|
+
});
|
|
62
|
+
await promise;
|
|
63
|
+
return httpServer;
|
|
64
|
+
}
|
|
65
|
+
function createMcpServer(aigne) {
|
|
66
|
+
const server = new McpServer({
|
|
67
|
+
name: aigne.name || "aigne-mcp-server",
|
|
68
|
+
version: AIGNE_CLI_VERSION
|
|
69
|
+
}, {
|
|
70
|
+
capabilities: { tools: {} },
|
|
71
|
+
instructions: aigne.description
|
|
72
|
+
});
|
|
73
|
+
for (const agent of aigne.mcpServer?.agents ?? []) {
|
|
74
|
+
const schema = agent.inputSchema;
|
|
75
|
+
if (!(schema instanceof ZodObject)) throw new Error("Agent input schema must be a ZodObject");
|
|
76
|
+
server.tool(agent.name, agent.description || "", schema.shape, async (input) => {
|
|
77
|
+
const result = await aigne.invoke(agent, input);
|
|
78
|
+
return { content: [{
|
|
79
|
+
type: "text",
|
|
80
|
+
text: agent instanceof AIAgent && result[agent.outputKey] || JSON.stringify(result)
|
|
81
|
+
}] };
|
|
82
|
+
});
|
|
83
|
+
}
|
|
84
|
+
return server;
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
//#endregion
|
|
88
|
+
export { createMcpServer, serveMCPServer };
|
|
89
|
+
//# sourceMappingURL=serve-mcp.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"serve-mcp.mjs","names":[],"sources":["../../src/utils/serve-mcp.ts"],"sourcesContent":["import { AIAgent, type AIGNE } from \"@aigne/core\";\nimport { promiseWithResolvers } from \"@aigne/core/utils/promise\";\nimport { McpServer } from \"@modelcontextprotocol/sdk/server/mcp.js\";\nimport { StreamableHTTPServerTransport } from \"@modelcontextprotocol/sdk/server/streamableHttp.js\";\nimport express, { json, type Request, type Response, Router } from \"express\";\nimport { ZodObject, type ZodRawShape } from \"zod\";\nimport { AIGNE_CLI_VERSION } from \"../constants.js\";\n\nexport async function serveMCPServer({\n pathname = \"/mcp\",\n aigne,\n host = \"localhost\",\n port,\n}: {\n pathname?: string;\n aigne: AIGNE;\n host?: string;\n port: number;\n}) {\n const app = express();\n\n app.use(json());\n\n const router = Router();\n\n app.use(router);\n\n router.post(pathname, async (req: Request, res: Response) => {\n try {\n const server = createMcpServer(aigne);\n\n const transport = new StreamableHTTPServerTransport({ sessionIdGenerator: undefined });\n\n await server.connect(transport);\n\n await transport.handleRequest(req, res, req.body);\n\n res.on(\"close\", async () => {\n await transport.close();\n await server.close();\n });\n } catch (error) {\n console.error(\"Error handling MCP request:\", error);\n if (!res.headersSent) {\n res.status(500).json({\n jsonrpc: \"2.0\",\n error: {\n code: -32603,\n message: error.message,\n },\n id: null,\n });\n }\n }\n });\n\n router.get(pathname, async (_: Request, res: Response) => {\n res.writeHead(405).end(\n JSON.stringify({\n jsonrpc: \"2.0\",\n error: {\n code: -32000,\n message: \"Method not allowed.\",\n },\n id: null,\n }),\n );\n });\n\n router.delete(pathname, async (_: Request, res: Response) => {\n res.writeHead(405).end(\n JSON.stringify({\n jsonrpc: \"2.0\",\n error: {\n code: -32000,\n message: \"Method not allowed.\",\n },\n id: null,\n }),\n );\n });\n\n const { promise, resolve, reject } = promiseWithResolvers();\n\n const httpServer = app.listen(port, host, (error) => {\n if (error) reject(error);\n resolve();\n });\n\n await promise;\n\n return httpServer;\n}\n\nexport function createMcpServer(aigne: AIGNE) {\n const server = new McpServer(\n {\n name: aigne.name || \"aigne-mcp-server\",\n version: AIGNE_CLI_VERSION,\n },\n {\n capabilities: { tools: {} },\n instructions: aigne.description,\n },\n );\n\n for (const agent of aigne.mcpServer?.agents ?? []) {\n const schema = agent.inputSchema;\n\n if (!(schema instanceof ZodObject)) throw new Error(\"Agent input schema must be a ZodObject\");\n\n server.tool(agent.name, agent.description || \"\", schema.shape as ZodRawShape, async (input) => {\n const result = await aigne.invoke(agent, input);\n\n return {\n content: [\n {\n type: \"text\",\n text:\n (agent instanceof AIAgent && (result[agent.outputKey] as string)) ||\n JSON.stringify(result),\n },\n ],\n };\n });\n }\n\n return server;\n}\n"],"mappings":";;;;;;;;;AAQA,eAAsB,eAAe,EACnC,WAAW,QACX,OACA,OAAO,aACP,QAMC;CACD,MAAM,MAAM,SAAS;AAErB,KAAI,IAAI,MAAM,CAAC;CAEf,MAAM,SAAS,QAAQ;AAEvB,KAAI,IAAI,OAAO;AAEf,QAAO,KAAK,UAAU,OAAO,KAAc,QAAkB;AAC3D,MAAI;GACF,MAAM,SAAS,gBAAgB,MAAM;GAErC,MAAM,YAAY,IAAI,8BAA8B,EAAE,oBAAoB,QAAW,CAAC;AAEtF,SAAM,OAAO,QAAQ,UAAU;AAE/B,SAAM,UAAU,cAAc,KAAK,KAAK,IAAI,KAAK;AAEjD,OAAI,GAAG,SAAS,YAAY;AAC1B,UAAM,UAAU,OAAO;AACvB,UAAM,OAAO,OAAO;KACpB;WACK,OAAO;AACd,WAAQ,MAAM,+BAA+B,MAAM;AACnD,OAAI,CAAC,IAAI,YACP,KAAI,OAAO,IAAI,CAAC,KAAK;IACnB,SAAS;IACT,OAAO;KACL,MAAM;KACN,SAAS,MAAM;KAChB;IACD,IAAI;IACL,CAAC;;GAGN;AAEF,QAAO,IAAI,UAAU,OAAO,GAAY,QAAkB;AACxD,MAAI,UAAU,IAAI,CAAC,IACjB,KAAK,UAAU;GACb,SAAS;GACT,OAAO;IACL,MAAM;IACN,SAAS;IACV;GACD,IAAI;GACL,CAAC,CACH;GACD;AAEF,QAAO,OAAO,UAAU,OAAO,GAAY,QAAkB;AAC3D,MAAI,UAAU,IAAI,CAAC,IACjB,KAAK,UAAU;GACb,SAAS;GACT,OAAO;IACL,MAAM;IACN,SAAS;IACV;GACD,IAAI;GACL,CAAC,CACH;GACD;CAEF,MAAM,EAAE,SAAS,SAAS,WAAW,sBAAsB;CAE3D,MAAM,aAAa,IAAI,OAAO,MAAM,OAAO,UAAU;AACnD,MAAI,MAAO,QAAO,MAAM;AACxB,WAAS;GACT;AAEF,OAAM;AAEN,QAAO;;AAGT,SAAgB,gBAAgB,OAAc;CAC5C,MAAM,SAAS,IAAI,UACjB;EACE,MAAM,MAAM,QAAQ;EACpB,SAAS;EACV,EACD;EACE,cAAc,EAAE,OAAO,EAAE,EAAE;EAC3B,cAAc,MAAM;EACrB,CACF;AAED,MAAK,MAAM,SAAS,MAAM,WAAW,UAAU,EAAE,EAAE;EACjD,MAAM,SAAS,MAAM;AAErB,MAAI,EAAE,kBAAkB,WAAY,OAAM,IAAI,MAAM,yCAAyC;AAE7F,SAAO,KAAK,MAAM,MAAM,MAAM,eAAe,IAAI,OAAO,OAAsB,OAAO,UAAU;GAC7F,MAAM,SAAS,MAAM,MAAM,OAAO,OAAO,MAAM;AAE/C,UAAO,EACL,SAAS,CACP;IACE,MAAM;IACN,MACG,iBAAiB,WAAY,OAAO,MAAM,cAC3C,KAAK,UAAU,OAAO;IACzB,CACF,EACF;IACD;;AAGJ,QAAO"}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
const require_rolldown_runtime = require('../_virtual/rolldown_runtime.cjs');
|
|
2
|
+
let _aigne_listr2 = require("@aigne/listr2");
|
|
3
|
+
|
|
4
|
+
//#region src/utils/spinner.ts
|
|
5
|
+
async function withSpinner(message, fn) {
|
|
6
|
+
const spinner = new _aigne_listr2.Spinner();
|
|
7
|
+
spinner.start(() => {
|
|
8
|
+
process.stdout.write(`\r\x1b[K${spinner.fetch()} ${message}`);
|
|
9
|
+
});
|
|
10
|
+
try {
|
|
11
|
+
return await fn();
|
|
12
|
+
} finally {
|
|
13
|
+
spinner.stop();
|
|
14
|
+
process.stdout.write("\r\x1B[K");
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
//#endregion
|
|
19
|
+
exports.withSpinner = withSpinner;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"spinner.d.cts","names":[],"sources":["../../src/utils/spinner.ts"],"mappings":";iBAEsB,WAAA,GAAA,CAAA,OAAA,UAAA,EAAA,QAA0C,OAAA,CAAQ,CAAA,IAAK,OAAA,CAAQ,CAAA"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"spinner.d.mts","names":[],"sources":["../../src/utils/spinner.ts"],"mappings":";iBAEsB,WAAA,GAAA,CAAA,OAAA,UAAA,EAAA,QAA0C,OAAA,CAAQ,CAAA,IAAK,OAAA,CAAQ,CAAA"}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { Spinner } from "@aigne/listr2";
|
|
2
|
+
|
|
3
|
+
//#region src/utils/spinner.ts
|
|
4
|
+
async function withSpinner(message, fn) {
|
|
5
|
+
const spinner = new Spinner();
|
|
6
|
+
spinner.start(() => {
|
|
7
|
+
process.stdout.write(`\r\x1b[K${spinner.fetch()} ${message}`);
|
|
8
|
+
});
|
|
9
|
+
try {
|
|
10
|
+
return await fn();
|
|
11
|
+
} finally {
|
|
12
|
+
spinner.stop();
|
|
13
|
+
process.stdout.write("\r\x1B[K");
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
//#endregion
|
|
18
|
+
export { withSpinner };
|
|
19
|
+
//# sourceMappingURL=spinner.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"spinner.mjs","names":[],"sources":["../../src/utils/spinner.ts"],"sourcesContent":["import { Spinner } from \"@aigne/listr2\";\n\nexport async function withSpinner<T>(message: string, fn: () => Promise<T>): Promise<T> {\n const spinner = new Spinner();\n spinner.start(() => {\n process.stdout.write(`\\r\\x1b[K${spinner.fetch()} ${message}`);\n });\n\n try {\n return await fn();\n } finally {\n spinner.stop();\n process.stdout.write(\"\\r\\x1b[K\"); // Clear the spinner line\n }\n}\n"],"mappings":";;;AAEA,eAAsB,YAAe,SAAiB,IAAkC;CACtF,MAAM,UAAU,IAAI,SAAS;AAC7B,SAAQ,YAAY;AAClB,UAAQ,OAAO,MAAM,WAAW,QAAQ,OAAO,CAAC,GAAG,UAAU;GAC7D;AAEF,KAAI;AACF,SAAO,MAAM,IAAI;WACT;AACR,UAAQ,MAAM;AACd,UAAQ,OAAO,MAAM,WAAW"}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
const require_rolldown_runtime = require('../_virtual/rolldown_runtime.cjs');
|
|
2
|
+
let chalk = require("chalk");
|
|
3
|
+
chalk = require_rolldown_runtime.__toESM(chalk);
|
|
4
|
+
|
|
5
|
+
//#region src/utils/string-utils.ts
|
|
6
|
+
function highlightUrl(str) {
|
|
7
|
+
return str.replace(/https?:\/\/[^\s]+/g, (url) => chalk.default.cyan(url));
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
//#endregion
|
|
11
|
+
exports.highlightUrl = highlightUrl;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"string-utils.d.cts","names":[],"sources":["../../src/utils/string-utils.ts"],"mappings":";iBAEgB,YAAA,CAAA,GAAA"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"string-utils.d.mts","names":[],"sources":["../../src/utils/string-utils.ts"],"mappings":";iBAEgB,YAAA,CAAA,GAAA"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"string-utils.mjs","names":[],"sources":["../../src/utils/string-utils.ts"],"sourcesContent":["import chalk from \"chalk\";\n\nexport function highlightUrl(str: string): string {\n return str.replace(/https?:\\/\\/[^\\s]+/g, (url) => chalk.cyan(url));\n}\n"],"mappings":";;;AAEA,SAAgB,aAAa,KAAqB;AAChD,QAAO,IAAI,QAAQ,uBAAuB,QAAQ,MAAM,KAAK,IAAI,CAAC"}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
|
|
2
|
+
//#region src/utils/time.ts
|
|
3
|
+
function parseDuration(duration) {
|
|
4
|
+
const milliseconds = duration % 1e3;
|
|
5
|
+
const seconds = Math.floor(duration / 1e3);
|
|
6
|
+
const minutes = Math.floor(seconds / 60);
|
|
7
|
+
const ms = Math.round(milliseconds / 10).toString().padStart(2, "0");
|
|
8
|
+
const s = `${Number.parseFloat(`${seconds % 60}.${ms}`)}s`;
|
|
9
|
+
if (minutes === 0) return s;
|
|
10
|
+
return `${minutes}m${s}`;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
//#endregion
|
|
14
|
+
exports.parseDuration = parseDuration;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"time.d.cts","names":[],"sources":["../../src/utils/time.ts"],"mappings":";iBAAgB,aAAA,CAAA,QAAA"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"time.d.mts","names":[],"sources":["../../src/utils/time.ts"],"mappings":";iBAAgB,aAAA,CAAA,QAAA"}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
//#region src/utils/time.ts
|
|
2
|
+
function parseDuration(duration) {
|
|
3
|
+
const milliseconds = duration % 1e3;
|
|
4
|
+
const seconds = Math.floor(duration / 1e3);
|
|
5
|
+
const minutes = Math.floor(seconds / 60);
|
|
6
|
+
const ms = Math.round(milliseconds / 10).toString().padStart(2, "0");
|
|
7
|
+
const s = `${Number.parseFloat(`${seconds % 60}.${ms}`)}s`;
|
|
8
|
+
if (minutes === 0) return s;
|
|
9
|
+
return `${minutes}m${s}`;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
//#endregion
|
|
13
|
+
export { parseDuration };
|
|
14
|
+
//# sourceMappingURL=time.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"time.mjs","names":[],"sources":["../../src/utils/time.ts"],"sourcesContent":["export function parseDuration(duration: number): string {\n const milliseconds = duration % 1000;\n const seconds = Math.floor(duration / 1000);\n const minutes = Math.floor(seconds / 60);\n\n const ms = Math.round(milliseconds / 10)\n .toString()\n .padStart(2, \"0\");\n\n const s = `${Number.parseFloat(`${seconds % 60}.${ms}`)}s`;\n\n if (minutes === 0) return s;\n\n return `${minutes}m${s}`;\n}\n"],"mappings":";AAAA,SAAgB,cAAc,UAA0B;CACtD,MAAM,eAAe,WAAW;CAChC,MAAM,UAAU,KAAK,MAAM,WAAW,IAAK;CAC3C,MAAM,UAAU,KAAK,MAAM,UAAU,GAAG;CAExC,MAAM,KAAK,KAAK,MAAM,eAAe,GAAG,CACrC,UAAU,CACV,SAAS,GAAG,IAAI;CAEnB,MAAM,IAAI,GAAG,OAAO,WAAW,GAAG,UAAU,GAAG,GAAG,KAAK,CAAC;AAExD,KAAI,YAAY,EAAG,QAAO;AAE1B,QAAO,GAAG,QAAQ,GAAG"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"url.d.cts","names":[],"sources":["../../src/utils/url.ts"],"mappings":";iBAAgB,KAAA,CAAA,CAAA"}
|