@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,138 @@
|
|
|
1
|
+
//#region src/utils/agent-v1.d.ts
|
|
2
|
+
declare function isV1Package(src: string): Promise<boolean>;
|
|
3
|
+
declare function toAIGNEPackage(src: string, dst: string): Promise<void>;
|
|
4
|
+
type Parameter = {
|
|
5
|
+
id: string;
|
|
6
|
+
key?: string;
|
|
7
|
+
hidden?: boolean;
|
|
8
|
+
required?: boolean;
|
|
9
|
+
placeholder?: string;
|
|
10
|
+
} & ({
|
|
11
|
+
type?: "string" | "number" | "boolean" | "language";
|
|
12
|
+
} | {
|
|
13
|
+
type?: "select";
|
|
14
|
+
options?: {
|
|
15
|
+
id: string;
|
|
16
|
+
label?: string;
|
|
17
|
+
value?: string;
|
|
18
|
+
}[];
|
|
19
|
+
});
|
|
20
|
+
interface VariableTypeBase {
|
|
21
|
+
id: string;
|
|
22
|
+
name?: string;
|
|
23
|
+
description?: string;
|
|
24
|
+
required?: boolean;
|
|
25
|
+
hidden?: boolean;
|
|
26
|
+
}
|
|
27
|
+
type OutputVariable = VariableTypeBase & ({
|
|
28
|
+
type?: undefined;
|
|
29
|
+
} | {
|
|
30
|
+
type: "string";
|
|
31
|
+
defaultValue?: string;
|
|
32
|
+
} | {
|
|
33
|
+
type: "number";
|
|
34
|
+
defaultValue?: number;
|
|
35
|
+
} | {
|
|
36
|
+
type: "boolean";
|
|
37
|
+
defaultValue?: boolean;
|
|
38
|
+
} | {
|
|
39
|
+
type: "object";
|
|
40
|
+
properties?: OutputVariable[];
|
|
41
|
+
} | {
|
|
42
|
+
type: "array";
|
|
43
|
+
element?: OutputVariable;
|
|
44
|
+
});
|
|
45
|
+
type AgentV1 = {
|
|
46
|
+
id: string;
|
|
47
|
+
name?: string;
|
|
48
|
+
description?: string;
|
|
49
|
+
parameters?: Parameter[];
|
|
50
|
+
outputVariables?: OutputVariable[];
|
|
51
|
+
} & ({
|
|
52
|
+
type: "prompt";
|
|
53
|
+
prompts?: Prompt[];
|
|
54
|
+
temperature?: number;
|
|
55
|
+
topP?: number;
|
|
56
|
+
presencePenalty?: number;
|
|
57
|
+
frequencyPenalty?: number;
|
|
58
|
+
maxTokens?: number;
|
|
59
|
+
model?: string;
|
|
60
|
+
} | {
|
|
61
|
+
type: "router";
|
|
62
|
+
defaultToolId?: string;
|
|
63
|
+
prompt?: string;
|
|
64
|
+
decisionType?: "ai";
|
|
65
|
+
routes?: Tool[];
|
|
66
|
+
temperature?: number;
|
|
67
|
+
topP?: number;
|
|
68
|
+
presencePenalty?: number;
|
|
69
|
+
frequencyPenalty?: number;
|
|
70
|
+
maxTokens?: number;
|
|
71
|
+
model?: string;
|
|
72
|
+
} | {
|
|
73
|
+
type: "image";
|
|
74
|
+
prompt?: string;
|
|
75
|
+
model?: string;
|
|
76
|
+
n?: number;
|
|
77
|
+
quality?: string;
|
|
78
|
+
style?: string;
|
|
79
|
+
size?: string;
|
|
80
|
+
modelSettings?: {
|
|
81
|
+
[key: string]: unknown;
|
|
82
|
+
};
|
|
83
|
+
} | {
|
|
84
|
+
type: "api";
|
|
85
|
+
requestParameters?: {
|
|
86
|
+
id: string;
|
|
87
|
+
key?: string;
|
|
88
|
+
value?: string;
|
|
89
|
+
}[];
|
|
90
|
+
requestMethod?: string;
|
|
91
|
+
requestUrl?: string;
|
|
92
|
+
requestHeaders: {
|
|
93
|
+
id: string;
|
|
94
|
+
key?: string;
|
|
95
|
+
value?: string;
|
|
96
|
+
}[];
|
|
97
|
+
} | {
|
|
98
|
+
type: "function";
|
|
99
|
+
code?: string;
|
|
100
|
+
} | {
|
|
101
|
+
type: "callAgent";
|
|
102
|
+
agents?: Tool[];
|
|
103
|
+
});
|
|
104
|
+
interface ProjectDefinitionV1 {
|
|
105
|
+
project: {
|
|
106
|
+
name?: string;
|
|
107
|
+
description?: string;
|
|
108
|
+
};
|
|
109
|
+
agents: AgentV1[];
|
|
110
|
+
}
|
|
111
|
+
type Prompt = {
|
|
112
|
+
type: "message";
|
|
113
|
+
data: PromptMessage;
|
|
114
|
+
visibility?: "hidden";
|
|
115
|
+
} | {
|
|
116
|
+
type: "executeBlock";
|
|
117
|
+
visibility?: "hidden";
|
|
118
|
+
};
|
|
119
|
+
type PromptMessage = {
|
|
120
|
+
id: string;
|
|
121
|
+
role: Role;
|
|
122
|
+
content?: string;
|
|
123
|
+
name?: string;
|
|
124
|
+
};
|
|
125
|
+
type Role = "system" | "user" | "assistant";
|
|
126
|
+
type Tool = {
|
|
127
|
+
blockletDid?: string;
|
|
128
|
+
projectId?: string;
|
|
129
|
+
id: string;
|
|
130
|
+
from?: "assistant" | "blockletAPI" | "knowledge";
|
|
131
|
+
parameters?: {
|
|
132
|
+
[key: string]: unknown;
|
|
133
|
+
};
|
|
134
|
+
functionName?: string;
|
|
135
|
+
};
|
|
136
|
+
//#endregion
|
|
137
|
+
export { AgentV1, OutputVariable, Parameter, ProjectDefinitionV1, Prompt, PromptMessage, Role, Tool, VariableTypeBase, isV1Package, toAIGNEPackage };
|
|
138
|
+
//# sourceMappingURL=agent-v1.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"agent-v1.d.mts","names":[],"sources":["../../src/utils/agent-v1.ts"],"mappings":";iBAKsB,WAAA,CAAA,GAAA,WAAuB,OAAA;AAAA,iBASvB,cAAA,CAAA,GAAA,UAAA,GAAA,WAAuC,OAAA;AAAA,KA+OjD,SAAA;EAAA,EAAA;EAAA,GAAA;EAAA,MAAA;EAAA,QAAA;EAAA,WAAA;AAAA;EAAA,IAAA;AAAA;EAAA,IAAA;EAAA,OAAA;IAAA,EAAA;IAAA,KAAA;IAAA,KAAA;EAAA;AAAA;AAAA,UAoBK,gBAAA;EAAA,EAAA;EAAA,IAAA;EAAA,WAAA;EAAA,QAAA;EAAA,MAAA;AAAA;AAAA,KAQL,cAAA,GAAiB,gBAAA;EAAA,IAAA;AAAA;EAAA,IAAA;EAAA,YAAA;AAAA;EAAA,IAAA;EAAA,YAAA;AAAA;EAAA,IAAA;EAAA,YAAA;AAAA;EAAA,IAAA;EAAA,UAAA,GAmBR,cAAA;AAAA;EAAA,IAAA;EAAA,OAAA,GAIH,cAAA;AAAA;AAAA,KAIN,OAAA;EAAA,EAAA;EAAA,IAAA;EAAA,WAAA;EAAA,UAAA,GAIG,SAAA;EAAA,eAAA,GACK,cAAA;AAAA;EAAA,IAAA;EAAA,OAAA,GAIJ,MAAA;EAAA,WAAA;EAAA,IAAA;EAAA,eAAA;EAAA,gBAAA;EAAA,SAAA;EAAA,KAAA;AAAA;EAAA,IAAA;EAAA,aAAA;EAAA,MAAA;EAAA,YAAA;EAAA,MAAA,GAaD,IAAA;EAAA,WAAA;EAAA,IAAA;EAAA,eAAA;EAAA,gBAAA;EAAA,SAAA;EAAA,KAAA;AAAA;EAAA,IAAA;EAAA,MAAA;EAAA,KAAA;EAAA,CAAA;EAAA,OAAA;EAAA,KAAA;EAAA,IAAA;EAAA,aAAA;IAAA,CAAA,GAAA;EAAA;AAAA;EAAA,IAAA;EAAA,iBAAA;IAAA,EAAA;IAAA,GAAA;IAAA,KAAA;EAAA;EAAA,aAAA;EAAA,UAAA;EAAA,cAAA;IAAA,EAAA;IAAA,GAAA;IAAA,KAAA;EAAA;AAAA;EAAA,IAAA;EAAA,IAAA;AAAA;EAAA,IAAA;EAAA,MAAA,GAyCA,IAAA;AAAA;AAAA,UAIE,mBAAA;EAAA,OAAA;IAAA,IAAA;IAAA,WAAA;EAAA;EAAA,MAAA,EAKP,OAAA;AAAA;AAAA,KAGE,MAAA;EAAA,IAAA;EAAA,IAAA,EAGA,aAAA;EAAA,UAAA;AAAA;EAAA,IAAA;EAAA,UAAA;AAAA;AAAA,KAQA,aAAA;EAAA,EAAA;EAAA,IAAA,EAEJ,IAAA;EAAA,OAAA;EAAA,IAAA;AAAA;AAAA,KAKI,IAAA;AAAA,KAEA,IAAA;EAAA,WAAA;EAAA,SAAA;EAAA,EAAA;EAAA,IAAA;EAAA,UAAA;IAAA,CAAA,GAAA;EAAA;EAAA,YAAA;AAAA"}
|
|
@@ -0,0 +1,179 @@
|
|
|
1
|
+
import { join } from "node:path";
|
|
2
|
+
import { readFile, stat, writeFile } from "node:fs/promises";
|
|
3
|
+
import { parse, stringify } from "yaml";
|
|
4
|
+
import { glob } from "glob";
|
|
5
|
+
|
|
6
|
+
//#region src/utils/agent-v1.ts
|
|
7
|
+
async function isV1Package(src) {
|
|
8
|
+
return stat(join(src, "project.yaml")).then((res) => res.isFile()).catch((error) => {
|
|
9
|
+
if (error.code === "ENOENT") return false;
|
|
10
|
+
throw error;
|
|
11
|
+
});
|
|
12
|
+
}
|
|
13
|
+
async function toAIGNEPackage(src, dst) {
|
|
14
|
+
const definition = await loadAgentV1Package(src);
|
|
15
|
+
const aigne = {
|
|
16
|
+
chat_model: { name: "gpt-4o-mini" },
|
|
17
|
+
agents: [],
|
|
18
|
+
cli: { agents: [] }
|
|
19
|
+
};
|
|
20
|
+
for (const agent of definition.agents) {
|
|
21
|
+
const { content } = await assistantToAIGNEV2(agent, definition);
|
|
22
|
+
const filename = getAgentFilename(agent);
|
|
23
|
+
await writeFile(join(dst, filename), content);
|
|
24
|
+
aigne.agents.push(filename);
|
|
25
|
+
aigne.cli.agents.push(filename);
|
|
26
|
+
}
|
|
27
|
+
await writeFile(join(dst, "aigne.yaml"), stringify(aigne));
|
|
28
|
+
}
|
|
29
|
+
async function loadAgentV1Package(path$1) {
|
|
30
|
+
const agentFilePaths = await glob("prompts/**/*.yaml", { cwd: path$1 });
|
|
31
|
+
const definition = {
|
|
32
|
+
project: parse(await readFile(join(path$1, "project.yaml"), "utf8")),
|
|
33
|
+
agents: []
|
|
34
|
+
};
|
|
35
|
+
for (const filename of agentFilePaths) {
|
|
36
|
+
const agent = parse(await readFile(join(path$1, filename), "utf8"));
|
|
37
|
+
definition.agents.push(agent);
|
|
38
|
+
}
|
|
39
|
+
return definition;
|
|
40
|
+
}
|
|
41
|
+
function assistantToAIGNEV2(agent, project) {
|
|
42
|
+
const converter = AGENT_MAP[agent.type];
|
|
43
|
+
if (!converter) throw new Error(`Unsupported agent type: ${agent.type}`);
|
|
44
|
+
return converter(agent, project);
|
|
45
|
+
}
|
|
46
|
+
const AGENT_MAP = {
|
|
47
|
+
prompt: (agent) => {
|
|
48
|
+
if (agent.type !== "prompt") throw new Error(`Expected agent type 'prompt', but got '${agent.type}'`);
|
|
49
|
+
return { content: stringify({
|
|
50
|
+
name: agent.name || agent.id,
|
|
51
|
+
description: agent.description,
|
|
52
|
+
input_schema: convertInputSchema(agent),
|
|
53
|
+
output_schema: convertOutputSchema(agent),
|
|
54
|
+
instructions: agent.prompts?.filter((i) => i.visibility !== "hidden" && i.type === "message").map((i) => i.data.content).join("\n")
|
|
55
|
+
}) };
|
|
56
|
+
},
|
|
57
|
+
function: async (agent) => {
|
|
58
|
+
if (agent.type !== "function") throw new Error(`Expected agent type 'function', but got '${agent.type}'`);
|
|
59
|
+
return { content: await formatCode(`\
|
|
60
|
+
export default async function agent({${(agent.parameters?.map((i) => i.key).filter(Boolean) ?? []).join(", ")}}) {
|
|
61
|
+
${agent.code}
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
agent.agent_name = ${JSON.stringify(agent.name || agent.id)};
|
|
65
|
+
|
|
66
|
+
agent.description = ${agent.description ? JSON.stringify(agent.description) : "undefined"};
|
|
67
|
+
|
|
68
|
+
agent.input_schema = ${JSON.stringify(convertInputSchema(agent))};
|
|
69
|
+
|
|
70
|
+
agent.output_schema = ${JSON.stringify(convertOutputSchema(agent))};
|
|
71
|
+
`) };
|
|
72
|
+
},
|
|
73
|
+
router: (agent, project) => {
|
|
74
|
+
if (agent.type !== "router") throw new Error(`Expected agent type 'router', but got '${agent.type}'`);
|
|
75
|
+
return { content: stringify({
|
|
76
|
+
name: agent.name || agent.id,
|
|
77
|
+
description: agent.description,
|
|
78
|
+
instructions: agent.prompt,
|
|
79
|
+
input_schema: convertInputSchema(agent),
|
|
80
|
+
output_schema: convertOutputSchema(agent),
|
|
81
|
+
skills: agent.routes?.map((i) => {
|
|
82
|
+
const tool = project.agents.find((j) => j.id === i.id);
|
|
83
|
+
if (!tool) throw new Error(`Tool ${i.id} not found in project definition`);
|
|
84
|
+
return getAgentFilename(tool);
|
|
85
|
+
}),
|
|
86
|
+
tool_choice: "router"
|
|
87
|
+
}) };
|
|
88
|
+
}
|
|
89
|
+
};
|
|
90
|
+
function getAgentFilename(agent) {
|
|
91
|
+
switch (agent.type) {
|
|
92
|
+
case "prompt":
|
|
93
|
+
case "router": return `${agent.name || agent.id}.yaml`;
|
|
94
|
+
case "function": return `${agent.name || agent.id}.js`;
|
|
95
|
+
default: throw new Error(`Unsupported agent type: ${agent.type}`);
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
async function formatCode(code) {
|
|
99
|
+
const [prettier, typescriptPlugin, estreePlugin] = await Promise.all([
|
|
100
|
+
import("prettier"),
|
|
101
|
+
import("prettier/plugins/typescript"),
|
|
102
|
+
import("prettier/plugins/estree")
|
|
103
|
+
]);
|
|
104
|
+
return prettier.format(code, {
|
|
105
|
+
parser: "typescript",
|
|
106
|
+
plugins: [typescriptPlugin, estreePlugin.default],
|
|
107
|
+
printWidth: 120,
|
|
108
|
+
useTabs: false,
|
|
109
|
+
tabWidth: 2,
|
|
110
|
+
trailingComma: "es5",
|
|
111
|
+
bracketSameLine: true,
|
|
112
|
+
semi: true,
|
|
113
|
+
singleQuote: true
|
|
114
|
+
});
|
|
115
|
+
}
|
|
116
|
+
function convertInputSchema(agent) {
|
|
117
|
+
const parameters = (agent.parameters ?? []).filter((i) => !!i.key && !i.hidden);
|
|
118
|
+
const properties = parameters.map((i) => [i.key, parameterToJsonSchema(i)]);
|
|
119
|
+
return {
|
|
120
|
+
type: "object",
|
|
121
|
+
properties: Object.fromEntries(properties),
|
|
122
|
+
required: parameters.filter((i) => i.required).map((i) => i.key)
|
|
123
|
+
};
|
|
124
|
+
}
|
|
125
|
+
function parameterToJsonSchema(parameter) {
|
|
126
|
+
switch (parameter.type) {
|
|
127
|
+
case void 0:
|
|
128
|
+
case "string":
|
|
129
|
+
case "language": return {
|
|
130
|
+
type: "string",
|
|
131
|
+
description: parameter.placeholder
|
|
132
|
+
};
|
|
133
|
+
case "select": return {
|
|
134
|
+
type: "string",
|
|
135
|
+
enum: parameter.options?.map((i) => i.value),
|
|
136
|
+
description: parameter.placeholder
|
|
137
|
+
};
|
|
138
|
+
case "number":
|
|
139
|
+
case "boolean": return {
|
|
140
|
+
type: parameter.type,
|
|
141
|
+
description: parameter.placeholder
|
|
142
|
+
};
|
|
143
|
+
default: throw new Error(`Unsupported parameter type: ${parameter.type}`);
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
function convertOutputSchema(agent) {
|
|
147
|
+
const outputs = agent.outputVariables?.filter((i) => !!i.name && !i.hidden) ?? [];
|
|
148
|
+
const properties = outputs.map((i) => [i.name, variableTypeToJsonSchema(i)]).filter((i) => !!i[1]);
|
|
149
|
+
return {
|
|
150
|
+
type: "object",
|
|
151
|
+
properties: Object.fromEntries(properties),
|
|
152
|
+
required: outputs.filter((i) => i.required).map((i) => i.name)
|
|
153
|
+
};
|
|
154
|
+
}
|
|
155
|
+
function variableTypeToJsonSchema(output) {
|
|
156
|
+
if (output.type === "object") {
|
|
157
|
+
if (!output.properties) return void 0;
|
|
158
|
+
return {
|
|
159
|
+
type: "object",
|
|
160
|
+
properties: Object.fromEntries(output.properties.filter((i) => !!i.name).map((i) => [i.name, variableTypeToJsonSchema(i)]).filter((i) => !!i[1])),
|
|
161
|
+
required: output.properties.filter((i) => i.required && i.name).map((i) => i.name)
|
|
162
|
+
};
|
|
163
|
+
}
|
|
164
|
+
if (output.type === "array") {
|
|
165
|
+
if (!output.element) return void 0;
|
|
166
|
+
return {
|
|
167
|
+
type: "array",
|
|
168
|
+
items: variableTypeToJsonSchema(output.element)
|
|
169
|
+
};
|
|
170
|
+
}
|
|
171
|
+
return {
|
|
172
|
+
type: output.type || "string",
|
|
173
|
+
description: output.description
|
|
174
|
+
};
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
//#endregion
|
|
178
|
+
export { isV1Package, toAIGNEPackage };
|
|
179
|
+
//# sourceMappingURL=agent-v1.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"agent-v1.mjs","names":["path"],"sources":["../../src/utils/agent-v1.ts"],"sourcesContent":["import { readFile, stat, writeFile } from \"node:fs/promises\";\nimport { join } from \"node:path\";\nimport { glob } from \"glob\";\nimport { parse, stringify } from \"yaml\";\n\nexport async function isV1Package(src: string) {\n return stat(join(src, \"project.yaml\"))\n .then((res) => res.isFile())\n .catch((error) => {\n if (error.code === \"ENOENT\") return false;\n throw error;\n });\n}\n\nexport async function toAIGNEPackage(src: string, dst: string) {\n const definition = await loadAgentV1Package(src);\n\n const aigne = {\n chat_model: {\n name: \"gpt-4o-mini\", // TODO: get from config\n },\n agents: <string[]>[],\n cli: {\n agents: <string[]>[],\n },\n };\n\n for (const agent of definition.agents) {\n const { content } = await assistantToAIGNEV2(agent, definition);\n const filename = getAgentFilename(agent);\n await writeFile(join(dst, filename), content);\n aigne.agents.push(filename);\n aigne.cli.agents.push(filename);\n }\n\n await writeFile(join(dst, \"aigne.yaml\"), stringify(aigne));\n}\n\nasync function loadAgentV1Package(path: string) {\n const agentFilePaths = await glob(\"prompts/**/*.yaml\", {\n cwd: path,\n });\n\n const project: ProjectDefinitionV1[\"project\"] = parse(\n await readFile(join(path, \"project.yaml\"), \"utf8\"),\n );\n\n const definition: ProjectDefinitionV1 = {\n project,\n agents: [],\n };\n\n for (const filename of agentFilePaths) {\n const agent = parse(await readFile(join(path, filename), \"utf8\"));\n definition.agents.push(agent);\n }\n\n return definition;\n}\n\nfunction assistantToAIGNEV2(agent: AgentV1, project: ProjectDefinitionV1) {\n const converter = AGENT_MAP[agent.type];\n\n if (!converter) throw new Error(`Unsupported agent type: ${agent.type}`);\n\n return converter(agent, project);\n}\n\nconst AGENT_MAP: {\n [key: string]: (\n agent: AgentV1,\n project: ProjectDefinitionV1,\n ) => Promise<{ content: string }> | { content: string };\n} = {\n prompt: (agent: AgentV1) => {\n if (agent.type !== \"prompt\")\n throw new Error(`Expected agent type 'prompt', but got '${agent.type}'`);\n\n const obj = {\n name: agent.name || agent.id,\n description: agent.description,\n input_schema: convertInputSchema(agent),\n output_schema: convertOutputSchema(agent),\n instructions: agent.prompts\n ?.filter(\n (i): i is Extract<Prompt, { type: \"message\" }> =>\n i.visibility !== \"hidden\" && i.type === \"message\",\n )\n .map((i) => i.data.content) // TODO: should support multiple messages with different roles\n .join(\"\\n\"),\n };\n\n return {\n content: stringify(obj),\n };\n },\n function: async (agent: AgentV1) => {\n if (agent.type !== \"function\")\n throw new Error(`Expected agent type 'function', but got '${agent.type}'`);\n\n const inputNames = agent.parameters?.map((i) => i.key).filter(Boolean) ?? [];\n\n return {\n content: await formatCode(`\\\nexport default async function agent({${inputNames.join(\", \")}}) {\n${agent.code}\n}\n\nagent.agent_name = ${JSON.stringify(agent.name || agent.id)};\n\nagent.description = ${agent.description ? JSON.stringify(agent.description) : \"undefined\"};\n\nagent.input_schema = ${JSON.stringify(convertInputSchema(agent))};\n\nagent.output_schema = ${JSON.stringify(convertOutputSchema(agent))};\n`),\n };\n },\n router: (agent: AgentV1, project: ProjectDefinitionV1) => {\n if (agent.type !== \"router\")\n throw new Error(`Expected agent type 'router', but got '${agent.type}'`);\n\n return {\n content: stringify({\n name: agent.name || agent.id,\n description: agent.description,\n instructions: agent.prompt,\n input_schema: convertInputSchema(agent),\n output_schema: convertOutputSchema(agent),\n skills: agent.routes?.map((i) => {\n const tool = project.agents.find((j) => j.id === i.id);\n if (!tool) throw new Error(`Tool ${i.id} not found in project definition`);\n return getAgentFilename(tool);\n }),\n tool_choice: \"router\",\n }),\n };\n },\n};\n\nfunction getAgentFilename(agent: AgentV1) {\n switch (agent.type) {\n case \"prompt\":\n case \"router\":\n return `${agent.name || agent.id}.yaml`;\n case \"function\":\n return `${agent.name || agent.id}.js`;\n default:\n throw new Error(`Unsupported agent type: ${agent.type}`);\n }\n}\n\nasync function formatCode(code: string) {\n const [prettier, typescriptPlugin, estreePlugin] = await Promise.all([\n import(\"prettier\"),\n import(\"prettier/plugins/typescript\"),\n import(\"prettier/plugins/estree\"),\n ]);\n\n return prettier.format(code, {\n parser: \"typescript\",\n plugins: [typescriptPlugin, estreePlugin.default],\n printWidth: 120,\n useTabs: false,\n tabWidth: 2,\n trailingComma: \"es5\",\n bracketSameLine: true,\n semi: true,\n singleQuote: true,\n });\n}\n\nfunction convertInputSchema(agent: AgentV1) {\n const parameters = (agent.parameters ?? []).filter((i) => !!i.key && !i.hidden);\n\n const properties = parameters.map((i) => [i.key, parameterToJsonSchema(i)]);\n\n return {\n type: \"object\",\n properties: Object.fromEntries(properties),\n required: parameters.filter((i) => i.required).map((i) => i.key),\n };\n}\n\nfunction parameterToJsonSchema(parameter: Parameter): object | undefined {\n switch (parameter.type) {\n case undefined:\n case \"string\":\n case \"language\":\n return {\n type: \"string\",\n description: parameter.placeholder,\n };\n case \"select\":\n return {\n type: \"string\",\n enum: parameter.options?.map((i) => i.value),\n description: parameter.placeholder,\n };\n case \"number\":\n case \"boolean\":\n return {\n type: parameter.type,\n description: parameter.placeholder,\n };\n default:\n throw new Error(`Unsupported parameter type: ${(parameter as Record<string, string>).type}`);\n }\n}\n\nfunction convertOutputSchema(agent: AgentV1) {\n const outputs = agent.outputVariables?.filter((i) => !!i.name && !i.hidden) ?? [];\n const properties = outputs\n .map((i) => [i.name, variableTypeToJsonSchema(i)])\n .filter((i) => !!i[1]);\n return {\n type: \"object\",\n properties: Object.fromEntries(properties),\n required: outputs.filter((i) => i.required).map((i) => i.name),\n };\n}\n\nfunction variableTypeToJsonSchema(output: OutputVariable): object | undefined {\n if (output.type === \"object\") {\n if (!output.properties) return undefined;\n\n return {\n type: \"object\",\n properties: Object.fromEntries(\n output.properties\n .filter((i): i is typeof i & { name: string } => !!i.name)\n .map((i) => [i.name, variableTypeToJsonSchema(i)])\n .filter((i) => !!i[1]),\n ),\n required: output.properties.filter((i) => i.required && i.name).map((i) => i.name),\n };\n }\n\n if (output.type === \"array\") {\n if (!output.element) return undefined;\n\n return {\n type: \"array\",\n items: variableTypeToJsonSchema(output.element),\n };\n }\n\n return {\n type: output.type || \"string\",\n description: output.description,\n };\n}\n\nexport type Parameter = {\n id: string;\n key?: string;\n hidden?: boolean;\n required?: boolean;\n placeholder?: string;\n} & (\n | {\n type?: \"string\" | \"number\" | \"boolean\" | \"language\";\n }\n | {\n type?: \"select\";\n options?: {\n id: string;\n label?: string;\n value?: string;\n }[];\n }\n);\n\nexport interface VariableTypeBase {\n id: string;\n name?: string;\n description?: string;\n required?: boolean;\n hidden?: boolean;\n}\n\nexport type OutputVariable = VariableTypeBase &\n (\n | {\n type?: undefined;\n }\n | {\n type: \"string\";\n defaultValue?: string;\n }\n | {\n type: \"number\";\n defaultValue?: number;\n }\n | {\n type: \"boolean\";\n defaultValue?: boolean;\n }\n | {\n type: \"object\";\n properties?: OutputVariable[];\n }\n | {\n type: \"array\";\n element?: OutputVariable;\n }\n );\n\nexport type AgentV1 = {\n id: string;\n name?: string;\n description?: string;\n parameters?: Parameter[];\n outputVariables?: OutputVariable[];\n} & (\n | {\n type: \"prompt\";\n prompts?: Prompt[];\n temperature?: number;\n topP?: number;\n presencePenalty?: number;\n frequencyPenalty?: number;\n maxTokens?: number;\n model?: string;\n }\n | {\n type: \"router\";\n defaultToolId?: string;\n prompt?: string;\n decisionType?: \"ai\";\n routes?: Tool[];\n temperature?: number;\n topP?: number;\n presencePenalty?: number;\n frequencyPenalty?: number;\n maxTokens?: number;\n model?: string;\n }\n | {\n type: \"image\";\n prompt?: string;\n model?: string;\n n?: number;\n quality?: string;\n style?: string;\n size?: string;\n modelSettings?: {\n [key: string]: unknown;\n };\n }\n | {\n type: \"api\";\n requestParameters?: {\n id: string;\n key?: string;\n value?: string;\n }[];\n requestMethod?: string;\n requestUrl?: string;\n requestHeaders: {\n id: string;\n key?: string;\n value?: string;\n }[];\n }\n | {\n type: \"function\";\n code?: string;\n }\n | {\n type: \"callAgent\";\n agents?: Tool[];\n }\n);\n\nexport interface ProjectDefinitionV1 {\n project: {\n name?: string;\n description?: string;\n };\n agents: AgentV1[];\n}\n\nexport type Prompt =\n | {\n type: \"message\";\n data: PromptMessage;\n visibility?: \"hidden\";\n }\n | {\n type: \"executeBlock\";\n visibility?: \"hidden\";\n };\n\nexport type PromptMessage = {\n id: string;\n role: Role;\n content?: string;\n name?: string;\n};\n\nexport type Role = \"system\" | \"user\" | \"assistant\";\n\nexport type Tool = {\n blockletDid?: string;\n projectId?: string;\n id: string;\n from?: \"assistant\" | \"blockletAPI\" | \"knowledge\";\n parameters?: {\n [key: string]: unknown;\n };\n functionName?: string;\n};\n"],"mappings":"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"}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
const require_rolldown_runtime = require('../../_virtual/rolldown_runtime.cjs');
|
|
2
|
+
let node_path = require("node:path");
|
|
3
|
+
let node_os = require("node:os");
|
|
4
|
+
|
|
5
|
+
//#region src/utils/aigne-hub/constants.ts
|
|
6
|
+
const ACCESS_KEY_PREFIX = "/api/access-key";
|
|
7
|
+
const WELLKNOWN_SERVICE_PATH_PREFIX = "/.well-known/service";
|
|
8
|
+
const ACCESS_KEY_SESSION_API = `${ACCESS_KEY_PREFIX}/session`;
|
|
9
|
+
const DEFAULT_AIGNE_HUB_MODEL = "openai/gpt-5-mini";
|
|
10
|
+
const AIGNE_HUB_PROVIDER = "aignehub";
|
|
11
|
+
const DEFAULT_AIGNE_HUB_PROVIDER_MODEL = `${AIGNE_HUB_PROVIDER}:${DEFAULT_AIGNE_HUB_MODEL}`;
|
|
12
|
+
const isTest = process.env.CI || process.env.NODE_ENV === "test";
|
|
13
|
+
const TEST_AIGNE_ENV_FILE = (0, node_path.join)((0, node_os.homedir)(), ".aigne", "test-aigne-hub-connected.yaml");
|
|
14
|
+
const PROD_AIGNE_ENV_FILE = (0, node_path.join)((0, node_os.homedir)(), ".aigne", "aigne-hub-connected.yaml");
|
|
15
|
+
const AIGNE_ENV_FILE = isTest ? TEST_AIGNE_ENV_FILE : PROD_AIGNE_ENV_FILE;
|
|
16
|
+
|
|
17
|
+
//#endregion
|
|
18
|
+
exports.ACCESS_KEY_SESSION_API = ACCESS_KEY_SESSION_API;
|
|
19
|
+
exports.AIGNE_ENV_FILE = AIGNE_ENV_FILE;
|
|
20
|
+
exports.AIGNE_HUB_PROVIDER = AIGNE_HUB_PROVIDER;
|
|
21
|
+
exports.WELLKNOWN_SERVICE_PATH_PREFIX = WELLKNOWN_SERVICE_PATH_PREFIX;
|
|
22
|
+
exports.isTest = isTest;
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { join } from "node:path";
|
|
2
|
+
import { homedir } from "node:os";
|
|
3
|
+
|
|
4
|
+
//#region src/utils/aigne-hub/constants.ts
|
|
5
|
+
const ACCESS_KEY_PREFIX = "/api/access-key";
|
|
6
|
+
const WELLKNOWN_SERVICE_PATH_PREFIX = "/.well-known/service";
|
|
7
|
+
const ACCESS_KEY_SESSION_API = `${ACCESS_KEY_PREFIX}/session`;
|
|
8
|
+
const DEFAULT_AIGNE_HUB_MODEL = "openai/gpt-5-mini";
|
|
9
|
+
const AIGNE_HUB_PROVIDER = "aignehub";
|
|
10
|
+
const DEFAULT_AIGNE_HUB_PROVIDER_MODEL = `${AIGNE_HUB_PROVIDER}:${DEFAULT_AIGNE_HUB_MODEL}`;
|
|
11
|
+
const isTest = process.env.CI || process.env.NODE_ENV === "test";
|
|
12
|
+
const TEST_AIGNE_ENV_FILE = join(homedir(), ".aigne", "test-aigne-hub-connected.yaml");
|
|
13
|
+
const PROD_AIGNE_ENV_FILE = join(homedir(), ".aigne", "aigne-hub-connected.yaml");
|
|
14
|
+
const AIGNE_ENV_FILE = isTest ? TEST_AIGNE_ENV_FILE : PROD_AIGNE_ENV_FILE;
|
|
15
|
+
|
|
16
|
+
//#endregion
|
|
17
|
+
export { ACCESS_KEY_SESSION_API, AIGNE_ENV_FILE, AIGNE_HUB_PROVIDER, WELLKNOWN_SERVICE_PATH_PREFIX, isTest };
|
|
18
|
+
//# sourceMappingURL=constants.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"constants.mjs","names":[],"sources":["../../../src/utils/aigne-hub/constants.ts"],"sourcesContent":["import { homedir } from \"node:os\";\nimport { join } from \"node:path\";\n\nconst ACCESS_KEY_PREFIX = \"/api/access-key\";\nexport const WELLKNOWN_SERVICE_PATH_PREFIX = \"/.well-known/service\";\nexport const ACCESS_KEY_SESSION_API = `${ACCESS_KEY_PREFIX}/session`;\n\nconst DEFAULT_AIGNE_HUB_MODEL = \"openai/gpt-5-mini\";\nexport const AIGNE_HUB_PROVIDER = \"aignehub\";\nexport const DEFAULT_AIGNE_HUB_PROVIDER_MODEL = `${AIGNE_HUB_PROVIDER}:${DEFAULT_AIGNE_HUB_MODEL}`;\n\nexport const isTest = process.env.CI || process.env.NODE_ENV === \"test\";\nconst TEST_AIGNE_ENV_FILE = join(homedir(), \".aigne\", \"test-aigne-hub-connected.yaml\");\nconst PROD_AIGNE_ENV_FILE = join(homedir(), \".aigne\", \"aigne-hub-connected.yaml\");\nexport const AIGNE_ENV_FILE = isTest ? TEST_AIGNE_ENV_FILE : PROD_AIGNE_ENV_FILE;\n"],"mappings":";;;;AAGA,MAAM,oBAAoB;AAC1B,MAAa,gCAAgC;AAC7C,MAAa,yBAAyB,GAAG,kBAAkB;AAE3D,MAAM,0BAA0B;AAChC,MAAa,qBAAqB;AAClC,MAAa,mCAAmC,GAAG,mBAAmB,GAAG;AAEzE,MAAa,SAAS,QAAQ,IAAI,MAAM,QAAQ,IAAI,aAAa;AACjE,MAAM,sBAAsB,KAAK,SAAS,EAAE,UAAU,gCAAgC;AACtF,MAAM,sBAAsB,KAAK,SAAS,EAAE,UAAU,2BAA2B;AACjF,MAAa,iBAAiB,SAAS,sBAAsB"}
|
|
@@ -0,0 +1,179 @@
|
|
|
1
|
+
const require_rolldown_runtime = require('../../_virtual/rolldown_runtime.cjs');
|
|
2
|
+
const require_constants = require('./constants.cjs');
|
|
3
|
+
const require_crypto = require('./crypto.cjs');
|
|
4
|
+
const require_index = require('./store/index.cjs');
|
|
5
|
+
let node_fs = require("node:fs");
|
|
6
|
+
let node_path = require("node:path");
|
|
7
|
+
let _aigne_core_utils_fetch = require("@aigne/core/utils/fetch");
|
|
8
|
+
let ufo = require("ufo");
|
|
9
|
+
let _aigne_aigne_hub = require("@aigne/aigne-hub");
|
|
10
|
+
let inquirer = require("inquirer");
|
|
11
|
+
inquirer = require_rolldown_runtime.__toESM(inquirer);
|
|
12
|
+
let node_os = require("node:os");
|
|
13
|
+
let open = require("open");
|
|
14
|
+
open = require_rolldown_runtime.__toESM(open);
|
|
15
|
+
let p_wait_for = require("p-wait-for");
|
|
16
|
+
p_wait_for = require_rolldown_runtime.__toESM(p_wait_for);
|
|
17
|
+
|
|
18
|
+
//#region src/utils/aigne-hub/credential.ts
|
|
19
|
+
const request = async (config) => {
|
|
20
|
+
const headers = {};
|
|
21
|
+
if (config.requestCount !== void 0) headers["X-Request-Count"] = config.requestCount.toString();
|
|
22
|
+
return { data: await (await (0, _aigne_core_utils_fetch.fetch)(config.url, {
|
|
23
|
+
method: config.method || "GET",
|
|
24
|
+
headers
|
|
25
|
+
})).json() };
|
|
26
|
+
};
|
|
27
|
+
const fetchConfigs = async ({ connectUrl, sessionId, fetchInterval, fetchTimeout }) => {
|
|
28
|
+
const sessionURL = (0, ufo.withQuery)((0, ufo.joinURL)(connectUrl, require_constants.ACCESS_KEY_SESSION_API), { sid: sessionId });
|
|
29
|
+
let requestCount = 0;
|
|
30
|
+
const condition = async () => {
|
|
31
|
+
const { data: session$1 } = await request({
|
|
32
|
+
url: sessionURL,
|
|
33
|
+
requestCount
|
|
34
|
+
});
|
|
35
|
+
requestCount++;
|
|
36
|
+
return Boolean(session$1.accessKeyId && session$1.accessKeySecret);
|
|
37
|
+
};
|
|
38
|
+
await (0, p_wait_for.default)(condition, {
|
|
39
|
+
interval: fetchInterval,
|
|
40
|
+
timeout: fetchTimeout
|
|
41
|
+
});
|
|
42
|
+
const { data: session } = await request({
|
|
43
|
+
url: sessionURL,
|
|
44
|
+
requestCount
|
|
45
|
+
});
|
|
46
|
+
await request({
|
|
47
|
+
url: sessionURL,
|
|
48
|
+
method: "DELETE"
|
|
49
|
+
});
|
|
50
|
+
return {
|
|
51
|
+
...session,
|
|
52
|
+
accessKeyId: session.accessKeyId,
|
|
53
|
+
accessKeySecret: require_crypto.decrypt(session.accessKeySecret, session.accessKeyId, session.challenge)
|
|
54
|
+
};
|
|
55
|
+
};
|
|
56
|
+
function baseWrapSpinner(_, waiting) {
|
|
57
|
+
return waiting();
|
|
58
|
+
}
|
|
59
|
+
async function createConnect({ connectUrl, openPage, fetchInterval = 3 * 1e3, retry = 1500, source = "Blocklet CLI", connectAction = "connect-cli", wrapSpinner = baseWrapSpinner, closeOnSuccess, intervalFetchConfig, appName = "AIGNE CLI", appLogo = "https://www.aigne.io/favicon.ico?imageFilter=resize&w=32" }) {
|
|
60
|
+
const { data: session } = await request({
|
|
61
|
+
url: (0, ufo.joinURL)(connectUrl, require_constants.ACCESS_KEY_SESSION_API),
|
|
62
|
+
method: "POST"
|
|
63
|
+
});
|
|
64
|
+
const token = session.id;
|
|
65
|
+
const pageUrl = (0, ufo.withQuery)((0, ufo.joinURL)(connectUrl, connectAction), {
|
|
66
|
+
__token__: require_crypto.encodeEncryptionKey(token),
|
|
67
|
+
source,
|
|
68
|
+
closeOnSuccess,
|
|
69
|
+
cli: true,
|
|
70
|
+
appName: ` ${appName}`,
|
|
71
|
+
appLogo
|
|
72
|
+
});
|
|
73
|
+
openPage?.(pageUrl);
|
|
74
|
+
return await wrapSpinner(`Waiting for connection: ${connectUrl}`, async () => {
|
|
75
|
+
return await (intervalFetchConfig ?? fetchConfigs)({
|
|
76
|
+
connectUrl,
|
|
77
|
+
sessionId: token,
|
|
78
|
+
fetchTimeout: retry * fetchInterval,
|
|
79
|
+
fetchInterval: retry
|
|
80
|
+
});
|
|
81
|
+
});
|
|
82
|
+
}
|
|
83
|
+
async function connectToAIGNEHub(url) {
|
|
84
|
+
const { origin } = new URL(url);
|
|
85
|
+
const connectUrl = (0, ufo.joinURL)(origin, require_constants.WELLKNOWN_SERVICE_PATH_PREFIX);
|
|
86
|
+
const apiUrl = await (0, _aigne_aigne_hub.getAIGNEHubMountPoint)(url, _aigne_aigne_hub.AIGNE_HUB_BLOCKLET_DID);
|
|
87
|
+
const openFn = require_constants.isTest ? () => {} : open.default;
|
|
88
|
+
const accessKeyOptions = {
|
|
89
|
+
apiKey: (await createConnect({
|
|
90
|
+
connectUrl,
|
|
91
|
+
connectAction: "gen-simple-access-key",
|
|
92
|
+
source: `@aigne/cli connect to AIGNE hub`,
|
|
93
|
+
closeOnSuccess: true,
|
|
94
|
+
openPage: (pageUrl) => openFn(pageUrl)
|
|
95
|
+
})).accessKeySecret,
|
|
96
|
+
url: apiUrl
|
|
97
|
+
};
|
|
98
|
+
const secretStore = await require_index.default();
|
|
99
|
+
await secretStore.setKey(accessKeyOptions.url, accessKeyOptions.apiKey);
|
|
100
|
+
await secretStore.setDefault(accessKeyOptions.url);
|
|
101
|
+
return accessKeyOptions;
|
|
102
|
+
}
|
|
103
|
+
const checkConnectionStatus = async (host) => {
|
|
104
|
+
const env = await (await require_index.default()).getKey(host);
|
|
105
|
+
if (!env?.AIGNE_HUB_API_KEY) throw new Error("AIGNE_HUB_API_KEY key not found, need to login first");
|
|
106
|
+
return {
|
|
107
|
+
apiKey: env.AIGNE_HUB_API_KEY,
|
|
108
|
+
url: env.AIGNE_HUB_API_URL
|
|
109
|
+
};
|
|
110
|
+
};
|
|
111
|
+
async function loadAIGNEHubCredential(options) {
|
|
112
|
+
if (process.env.BLOCKLET_AIGNE_API_URL && process.env.BLOCKLET_AIGNE_API_PROVIDER) return void 0;
|
|
113
|
+
const aigneDir = (0, node_path.join)((0, node_os.homedir)(), ".aigne");
|
|
114
|
+
if (!(0, node_fs.existsSync)(aigneDir)) (0, node_fs.mkdirSync)(aigneDir, { recursive: true });
|
|
115
|
+
const defaultHost = await (await require_index.default()).getDefault();
|
|
116
|
+
const inquirerPrompt = options?.inquirerPromptFn ?? inquirer.default.prompt;
|
|
117
|
+
const configUrl = options?.aigneHubUrl || process.env.AIGNE_HUB_API_URL;
|
|
118
|
+
const url = configUrl || defaultHost?.AIGNE_HUB_API_URL || _aigne_aigne_hub.AIGNE_HUB_URL;
|
|
119
|
+
const connectUrl = (0, ufo.joinURL)(new URL(url).origin, require_constants.WELLKNOWN_SERVICE_PATH_PREFIX);
|
|
120
|
+
const { host } = new URL(url);
|
|
121
|
+
let credential = {};
|
|
122
|
+
try {
|
|
123
|
+
if (process.env.AIGNE_HUB_API_KEY) credential = {
|
|
124
|
+
apiKey: process.env.AIGNE_HUB_API_KEY,
|
|
125
|
+
url: process.env.AIGNE_HUB_API_URL || url
|
|
126
|
+
};
|
|
127
|
+
else credential = await checkConnectionStatus(host);
|
|
128
|
+
} catch (error) {
|
|
129
|
+
if (error instanceof Error && error.message.includes("login first")) {
|
|
130
|
+
let aigneHubUrl = connectUrl;
|
|
131
|
+
if (!configUrl) {
|
|
132
|
+
const { subscribe } = await inquirerPrompt({
|
|
133
|
+
type: "list",
|
|
134
|
+
name: "subscribe",
|
|
135
|
+
message: "No LLM API Keys or AIGNE Hub connections found. How would you like to proceed?",
|
|
136
|
+
choices: [
|
|
137
|
+
{
|
|
138
|
+
name: "Connect to the Arcblock official AIGNE Hub (recommended, free credits for new users)",
|
|
139
|
+
value: "official"
|
|
140
|
+
},
|
|
141
|
+
connectUrl.includes(_aigne_aigne_hub.AIGNE_HUB_URL) ? {
|
|
142
|
+
name: "Connect to your own AIGNE Hub instance (self-hosted)",
|
|
143
|
+
value: "custom"
|
|
144
|
+
} : null,
|
|
145
|
+
{
|
|
146
|
+
name: "Exit and configure my own LLM API Keys",
|
|
147
|
+
value: "manual"
|
|
148
|
+
}
|
|
149
|
+
].filter(Boolean),
|
|
150
|
+
default: "official"
|
|
151
|
+
});
|
|
152
|
+
if (subscribe === "custom") {
|
|
153
|
+
const { customUrl } = await inquirerPrompt({
|
|
154
|
+
type: "input",
|
|
155
|
+
name: "customUrl",
|
|
156
|
+
message: "Enter the URL of your AIGNE Hub:",
|
|
157
|
+
validate(input) {
|
|
158
|
+
try {
|
|
159
|
+
return new URL(input).protocol.startsWith("http") ? true : "Must be a valid URL with http or https";
|
|
160
|
+
} catch {
|
|
161
|
+
return "Invalid URL";
|
|
162
|
+
}
|
|
163
|
+
}
|
|
164
|
+
});
|
|
165
|
+
aigneHubUrl = customUrl;
|
|
166
|
+
} else if (subscribe === "manual") {
|
|
167
|
+
console.log("You chose to configure your own LLM API Keys. Please follow the instructions in the documentation: https://www.arcblock.io/docs/aigne-framework/models-configuration-9dc03e");
|
|
168
|
+
process.exit(0);
|
|
169
|
+
}
|
|
170
|
+
}
|
|
171
|
+
credential = await connectToAIGNEHub(aigneHubUrl);
|
|
172
|
+
} else throw error;
|
|
173
|
+
}
|
|
174
|
+
return credential;
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
//#endregion
|
|
178
|
+
exports.connectToAIGNEHub = connectToAIGNEHub;
|
|
179
|
+
exports.loadAIGNEHubCredential = loadAIGNEHubCredential;
|