@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
|
@@ -1,182 +0,0 @@
|
|
|
1
|
-
import { existsSync, mkdirSync } from "node:fs";
|
|
2
|
-
import { homedir } from "node:os";
|
|
3
|
-
import { join } from "node:path";
|
|
4
|
-
import { AIGNE_HUB_BLOCKLET_DID, AIGNE_HUB_URL, getAIGNEHubMountPoint } from "@aigne/aigne-hub";
|
|
5
|
-
import { fetch } from "@aigne/core/utils/fetch.js";
|
|
6
|
-
import inquirer from "inquirer";
|
|
7
|
-
import open from "open";
|
|
8
|
-
import pWaitFor from "p-wait-for";
|
|
9
|
-
import { joinURL, withQuery } from "ufo";
|
|
10
|
-
import { ACCESS_KEY_SESSION_API, isTest, WELLKNOWN_SERVICE_PATH_PREFIX } from "./constants.js";
|
|
11
|
-
import { decrypt, encodeEncryptionKey } from "./crypto.js";
|
|
12
|
-
import getSecretStore from "./store/index.js";
|
|
13
|
-
const request = async (config) => {
|
|
14
|
-
const headers = {};
|
|
15
|
-
if (config.requestCount !== undefined) {
|
|
16
|
-
headers["X-Request-Count"] = config.requestCount.toString();
|
|
17
|
-
}
|
|
18
|
-
const response = await fetch(config.url, { method: config.method || "GET", headers });
|
|
19
|
-
const data = await response.json();
|
|
20
|
-
return { data };
|
|
21
|
-
};
|
|
22
|
-
export const fetchConfigs = async ({ connectUrl, sessionId, fetchInterval, fetchTimeout, }) => {
|
|
23
|
-
const sessionURL = withQuery(joinURL(connectUrl, ACCESS_KEY_SESSION_API), { sid: sessionId });
|
|
24
|
-
let requestCount = 0;
|
|
25
|
-
const condition = async () => {
|
|
26
|
-
const { data: session } = await request({ url: sessionURL, requestCount });
|
|
27
|
-
requestCount++;
|
|
28
|
-
return Boolean(session.accessKeyId && session.accessKeySecret);
|
|
29
|
-
};
|
|
30
|
-
await pWaitFor(condition, { interval: fetchInterval, timeout: fetchTimeout });
|
|
31
|
-
const { data: session } = await request({ url: sessionURL, requestCount });
|
|
32
|
-
await request({ url: sessionURL, method: "DELETE" });
|
|
33
|
-
return {
|
|
34
|
-
...session,
|
|
35
|
-
accessKeyId: session.accessKeyId,
|
|
36
|
-
accessKeySecret: decrypt(session.accessKeySecret, session.accessKeyId, session.challenge),
|
|
37
|
-
};
|
|
38
|
-
};
|
|
39
|
-
function baseWrapSpinner(_, waiting) {
|
|
40
|
-
return waiting();
|
|
41
|
-
}
|
|
42
|
-
export async function createConnect({ connectUrl, openPage, fetchInterval = 3 * 1000, 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", }) {
|
|
43
|
-
const startSessionURL = joinURL(connectUrl, ACCESS_KEY_SESSION_API);
|
|
44
|
-
const { data: session } = await request({ url: startSessionURL, method: "POST" });
|
|
45
|
-
const token = session.id;
|
|
46
|
-
const pageUrl = withQuery(joinURL(connectUrl, connectAction), {
|
|
47
|
-
__token__: encodeEncryptionKey(token),
|
|
48
|
-
source,
|
|
49
|
-
closeOnSuccess,
|
|
50
|
-
cli: true,
|
|
51
|
-
appName: ` ${appName}`,
|
|
52
|
-
appLogo,
|
|
53
|
-
});
|
|
54
|
-
openPage?.(pageUrl);
|
|
55
|
-
return await wrapSpinner(`Waiting for connection: ${connectUrl}`, async () => {
|
|
56
|
-
const checkAuthorizeStatus = intervalFetchConfig ?? fetchConfigs;
|
|
57
|
-
const authorizeStatus = await checkAuthorizeStatus({
|
|
58
|
-
connectUrl,
|
|
59
|
-
sessionId: token,
|
|
60
|
-
fetchTimeout: retry * fetchInterval,
|
|
61
|
-
fetchInterval: retry,
|
|
62
|
-
});
|
|
63
|
-
return authorizeStatus;
|
|
64
|
-
});
|
|
65
|
-
}
|
|
66
|
-
export async function connectToAIGNEHub(url) {
|
|
67
|
-
const { origin } = new URL(url);
|
|
68
|
-
const connectUrl = joinURL(origin, WELLKNOWN_SERVICE_PATH_PREFIX);
|
|
69
|
-
const apiUrl = await getAIGNEHubMountPoint(url, AIGNE_HUB_BLOCKLET_DID);
|
|
70
|
-
const openFn = isTest ? () => { } : open;
|
|
71
|
-
const result = await createConnect({
|
|
72
|
-
connectUrl: connectUrl,
|
|
73
|
-
connectAction: "gen-simple-access-key",
|
|
74
|
-
source: `@aigne/cli connect to AIGNE hub`,
|
|
75
|
-
closeOnSuccess: true,
|
|
76
|
-
openPage: (pageUrl) => openFn(pageUrl),
|
|
77
|
-
});
|
|
78
|
-
const accessKeyOptions = {
|
|
79
|
-
apiKey: result.accessKeySecret,
|
|
80
|
-
url: apiUrl,
|
|
81
|
-
};
|
|
82
|
-
const secretStore = await getSecretStore();
|
|
83
|
-
await secretStore.setKey(accessKeyOptions.url, accessKeyOptions.apiKey);
|
|
84
|
-
await secretStore.setDefault(accessKeyOptions.url);
|
|
85
|
-
return accessKeyOptions;
|
|
86
|
-
}
|
|
87
|
-
export const checkConnectionStatus = async (host) => {
|
|
88
|
-
const secretStore = await getSecretStore();
|
|
89
|
-
const env = await secretStore.getKey(host);
|
|
90
|
-
if (!env?.AIGNE_HUB_API_KEY) {
|
|
91
|
-
throw new Error("AIGNE_HUB_API_KEY key not found, need to login first");
|
|
92
|
-
}
|
|
93
|
-
return {
|
|
94
|
-
apiKey: env.AIGNE_HUB_API_KEY,
|
|
95
|
-
url: env.AIGNE_HUB_API_URL,
|
|
96
|
-
};
|
|
97
|
-
};
|
|
98
|
-
export async function loadAIGNEHubCredential(options) {
|
|
99
|
-
const isBlocklet = process.env.BLOCKLET_AIGNE_API_URL && process.env.BLOCKLET_AIGNE_API_PROVIDER;
|
|
100
|
-
if (isBlocklet)
|
|
101
|
-
return undefined;
|
|
102
|
-
const aigneDir = join(homedir(), ".aigne");
|
|
103
|
-
if (!existsSync(aigneDir)) {
|
|
104
|
-
mkdirSync(aigneDir, { recursive: true });
|
|
105
|
-
}
|
|
106
|
-
const secretStore = await getSecretStore();
|
|
107
|
-
const defaultHost = await secretStore.getDefault();
|
|
108
|
-
const inquirerPrompt = (options?.inquirerPromptFn ?? inquirer.prompt);
|
|
109
|
-
const configUrl = options?.aigneHubUrl || process.env.AIGNE_HUB_API_URL;
|
|
110
|
-
const url = configUrl || defaultHost?.AIGNE_HUB_API_URL || AIGNE_HUB_URL;
|
|
111
|
-
const connectUrl = joinURL(new URL(url).origin, WELLKNOWN_SERVICE_PATH_PREFIX);
|
|
112
|
-
const { host } = new URL(url);
|
|
113
|
-
let credential = {};
|
|
114
|
-
try {
|
|
115
|
-
if (process.env.AIGNE_HUB_API_KEY) {
|
|
116
|
-
credential = {
|
|
117
|
-
apiKey: process.env.AIGNE_HUB_API_KEY,
|
|
118
|
-
url: process.env.AIGNE_HUB_API_URL || url,
|
|
119
|
-
};
|
|
120
|
-
}
|
|
121
|
-
else {
|
|
122
|
-
credential = await checkConnectionStatus(host);
|
|
123
|
-
}
|
|
124
|
-
}
|
|
125
|
-
catch (error) {
|
|
126
|
-
if (error instanceof Error && error.message.includes("login first")) {
|
|
127
|
-
let aigneHubUrl = connectUrl;
|
|
128
|
-
if (!configUrl) {
|
|
129
|
-
const { subscribe } = await inquirerPrompt({
|
|
130
|
-
type: "list",
|
|
131
|
-
name: "subscribe",
|
|
132
|
-
message: "No LLM API Keys or AIGNE Hub connections found. How would you like to proceed?",
|
|
133
|
-
choices: [
|
|
134
|
-
{
|
|
135
|
-
name: "Connect to the Arcblock official AIGNE Hub (recommended, free credits for new users)",
|
|
136
|
-
value: "official",
|
|
137
|
-
},
|
|
138
|
-
connectUrl.includes(AIGNE_HUB_URL)
|
|
139
|
-
? {
|
|
140
|
-
name: "Connect to your own AIGNE Hub instance (self-hosted)",
|
|
141
|
-
value: "custom",
|
|
142
|
-
}
|
|
143
|
-
: null,
|
|
144
|
-
{
|
|
145
|
-
name: "Exit and configure my own LLM API Keys",
|
|
146
|
-
value: "manual",
|
|
147
|
-
},
|
|
148
|
-
].filter(Boolean),
|
|
149
|
-
default: "official",
|
|
150
|
-
});
|
|
151
|
-
if (subscribe === "custom") {
|
|
152
|
-
const { customUrl } = await inquirerPrompt({
|
|
153
|
-
type: "input",
|
|
154
|
-
name: "customUrl",
|
|
155
|
-
message: "Enter the URL of your AIGNE Hub:",
|
|
156
|
-
validate(input) {
|
|
157
|
-
try {
|
|
158
|
-
const url = new URL(input);
|
|
159
|
-
return url.protocol.startsWith("http")
|
|
160
|
-
? true
|
|
161
|
-
: "Must be a valid URL with http or https";
|
|
162
|
-
}
|
|
163
|
-
catch {
|
|
164
|
-
return "Invalid URL";
|
|
165
|
-
}
|
|
166
|
-
},
|
|
167
|
-
});
|
|
168
|
-
aigneHubUrl = customUrl;
|
|
169
|
-
}
|
|
170
|
-
else if (subscribe === "manual") {
|
|
171
|
-
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");
|
|
172
|
-
process.exit(0);
|
|
173
|
-
}
|
|
174
|
-
}
|
|
175
|
-
credential = await connectToAIGNEHub(aigneHubUrl);
|
|
176
|
-
}
|
|
177
|
-
else {
|
|
178
|
-
throw error;
|
|
179
|
-
}
|
|
180
|
-
}
|
|
181
|
-
return credential;
|
|
182
|
-
}
|
|
@@ -1,4 +0,0 @@
|
|
|
1
|
-
export declare const decrypt: (m: string, s: string, i: string) => string;
|
|
2
|
-
export declare const encrypt: (m: string, s: string, i: string) => string;
|
|
3
|
-
export declare const encodeEncryptionKey: (key: string) => string;
|
|
4
|
-
export declare const decodeEncryptionKey: (str: string) => Uint8Array<ArrayBuffer>;
|
|
@@ -1,30 +0,0 @@
|
|
|
1
|
-
import crypto from "node:crypto";
|
|
2
|
-
import AES from "crypto-js/aes.js";
|
|
3
|
-
import encBase64 from "crypto-js/enc-base64.js";
|
|
4
|
-
import encHex from "crypto-js/enc-hex.js";
|
|
5
|
-
import encLatin1 from "crypto-js/enc-latin1.js";
|
|
6
|
-
import encUtf8 from "crypto-js/enc-utf8.js";
|
|
7
|
-
import encUtf16 from "crypto-js/enc-utf16.js";
|
|
8
|
-
const encoders = {
|
|
9
|
-
latin1: encLatin1,
|
|
10
|
-
utf8: encUtf8,
|
|
11
|
-
hex: encHex,
|
|
12
|
-
utf16: encUtf16,
|
|
13
|
-
base64: encBase64,
|
|
14
|
-
};
|
|
15
|
-
class AesCrypter {
|
|
16
|
-
encrypt(message, secret) {
|
|
17
|
-
const text = typeof message === "string" ? message : JSON.stringify(message);
|
|
18
|
-
return AES.encrypt(text, secret).toString();
|
|
19
|
-
}
|
|
20
|
-
decrypt(cipher, secret, outputEncoding = "utf8") {
|
|
21
|
-
return AES.decrypt(cipher, secret).toString(encoders[outputEncoding]);
|
|
22
|
-
}
|
|
23
|
-
}
|
|
24
|
-
const aes = new AesCrypter();
|
|
25
|
-
export const decrypt = (m, s, i) => aes.decrypt(m, crypto.pbkdf2Sync(i, s, 256, 32, "sha512").toString("hex"));
|
|
26
|
-
export const encrypt = (m, s, i) => aes.encrypt(m, crypto.pbkdf2Sync(i, s, 256, 32, "sha512").toString("hex"));
|
|
27
|
-
const escapeFn = (str) => str.replace(/\+/g, "-").replace(/\//g, "_").replace(/=/g, "");
|
|
28
|
-
const unescapeFn = (str) => (str + "===".slice((str.length + 3) % 4)).replace(/-/g, "+").replace(/_/g, "/");
|
|
29
|
-
export const encodeEncryptionKey = (key) => escapeFn(Buffer.from(key).toString("base64"));
|
|
30
|
-
export const decodeEncryptionKey = (str) => new Uint8Array(Buffer.from(unescapeFn(str), "base64"));
|
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
import type { ChatModel, ChatModelInputOptionsWithGetter, ImageModel, ImageModelInputOptionsWithGetter } from "@aigne/core";
|
|
2
|
-
import type { LoadCredentialOptions } from "./type.js";
|
|
3
|
-
export declare function maskApiKey(apiKey?: string): string | undefined;
|
|
4
|
-
export declare function findConfiguredProvider(provider?: string, name?: string): {
|
|
5
|
-
provider: import("@aigne/aigne-hub").AIProviderType;
|
|
6
|
-
model: string;
|
|
7
|
-
} | undefined;
|
|
8
|
-
export declare const formatModelName: (model: string, inquirerPrompt: NonNullable<LoadCredentialOptions["inquirerPromptFn"]>) => Promise<{
|
|
9
|
-
provider: string;
|
|
10
|
-
model?: string;
|
|
11
|
-
}>;
|
|
12
|
-
export declare function loadChatModel(options?: ChatModelInputOptionsWithGetter & LoadCredentialOptions): Promise<ChatModel>;
|
|
13
|
-
export declare function loadImageModel(options?: ImageModelInputOptionsWithGetter & LoadCredentialOptions): Promise<ImageModel>;
|
|
@@ -1,122 +0,0 @@
|
|
|
1
|
-
import { AIGNE_HUB_DEFAULT_MODEL, AIGNE_HUB_URL, findImageModel, findModel, getSupportedProviders, parseModel, resolveProviderModelId, } from "@aigne/aigne-hub";
|
|
2
|
-
import { flat, omit } from "@aigne/core/utils/type-utils.js";
|
|
3
|
-
import chalk from "chalk";
|
|
4
|
-
import inquirer from "inquirer";
|
|
5
|
-
import { AIGNE_HUB_PROVIDER } from "./constants.js";
|
|
6
|
-
import { loadAIGNEHubCredential } from "./credential.js";
|
|
7
|
-
import getSecretStore from "./store/index.js";
|
|
8
|
-
export function maskApiKey(apiKey) {
|
|
9
|
-
if (!apiKey || apiKey.length <= 8)
|
|
10
|
-
return apiKey;
|
|
11
|
-
const start = apiKey.slice(0, 4);
|
|
12
|
-
const end = apiKey.slice(-4);
|
|
13
|
-
return `${start}${"*".repeat(8)}${end}`;
|
|
14
|
-
}
|
|
15
|
-
export function findConfiguredProvider(provider, name) {
|
|
16
|
-
if (provider && provider.trim().toLowerCase() !== AIGNE_HUB_PROVIDER.trim().toLowerCase()) {
|
|
17
|
-
return undefined;
|
|
18
|
-
}
|
|
19
|
-
if (!name)
|
|
20
|
-
return undefined;
|
|
21
|
-
const supportedProviders = getSupportedProviders(name);
|
|
22
|
-
for (const supportedProvider of supportedProviders) {
|
|
23
|
-
const { match } = findModel(supportedProvider);
|
|
24
|
-
if (match) {
|
|
25
|
-
const requireEnvs = flat(match.apiKeyEnvName);
|
|
26
|
-
if (requireEnvs.some((name) => name && process.env[name])) {
|
|
27
|
-
return {
|
|
28
|
-
provider: supportedProvider,
|
|
29
|
-
model: resolveProviderModelId(supportedProvider, name),
|
|
30
|
-
};
|
|
31
|
-
}
|
|
32
|
-
}
|
|
33
|
-
}
|
|
34
|
-
}
|
|
35
|
-
export const formatModelName = async (model, inquirerPrompt) => {
|
|
36
|
-
let { provider, model: name } = parseModel(model);
|
|
37
|
-
const configuredEnvProvider = findConfiguredProvider(provider, name);
|
|
38
|
-
if (configuredEnvProvider)
|
|
39
|
-
return configuredEnvProvider;
|
|
40
|
-
provider ||= AIGNE_HUB_PROVIDER;
|
|
41
|
-
const { match, all } = findModel(provider);
|
|
42
|
-
if (!match) {
|
|
43
|
-
throw new Error(`Unsupported model: ${provider}/${name}, available providers: ${all.map((m) => m.name).join(", ")}`);
|
|
44
|
-
}
|
|
45
|
-
if (provider.includes(AIGNE_HUB_PROVIDER)) {
|
|
46
|
-
return { provider, model: name || AIGNE_HUB_DEFAULT_MODEL };
|
|
47
|
-
}
|
|
48
|
-
const requireEnvs = flat(match.apiKeyEnvName);
|
|
49
|
-
if (requireEnvs.some((name) => name && process.env[name])) {
|
|
50
|
-
return { provider, model: name };
|
|
51
|
-
}
|
|
52
|
-
const secretStore = await getSecretStore();
|
|
53
|
-
const defaultHost = await secretStore.getDefault();
|
|
54
|
-
if (process.env.AIGNE_HUB_API_KEY || defaultHost?.AIGNE_HUB_API_URL) {
|
|
55
|
-
return { provider: AIGNE_HUB_PROVIDER, model: `${provider}/${name}` };
|
|
56
|
-
}
|
|
57
|
-
const result = await inquirerPrompt({
|
|
58
|
-
type: "list",
|
|
59
|
-
name: "useAigneHub",
|
|
60
|
-
message: `No API key is configured for ${provider}/${name}, How would you like to proceed?`,
|
|
61
|
-
choices: [
|
|
62
|
-
{
|
|
63
|
-
name: `Connect to AIGNE Hub to use ${name} (recommended — includes free credits)`,
|
|
64
|
-
value: true,
|
|
65
|
-
},
|
|
66
|
-
{
|
|
67
|
-
name: `Exit and use my own API key (set ${requireEnvs.join(" or ")})`,
|
|
68
|
-
value: false,
|
|
69
|
-
},
|
|
70
|
-
],
|
|
71
|
-
default: true,
|
|
72
|
-
});
|
|
73
|
-
if (!result.useAigneHub) {
|
|
74
|
-
console.log(chalk.yellow(`You can use command "export ${requireEnvs[0]}=xxx" to set API Key in your shell. Or you can set environment variables in .env file.`));
|
|
75
|
-
process.exit(0);
|
|
76
|
-
}
|
|
77
|
-
const envs = await secretStore.listHostsMap();
|
|
78
|
-
if (envs && Object.keys(envs).length > 0 && !defaultHost?.AIGNE_HUB_API_URL) {
|
|
79
|
-
const host = new URL(AIGNE_HUB_URL).host;
|
|
80
|
-
const defaultEnv = envs[host]?.AIGNE_HUB_API_URL
|
|
81
|
-
? envs[host]
|
|
82
|
-
: Object.values(envs)[0] || { AIGNE_HUB_API_URL: "" };
|
|
83
|
-
await secretStore.setDefault(defaultEnv?.AIGNE_HUB_API_URL);
|
|
84
|
-
}
|
|
85
|
-
return { provider: AIGNE_HUB_PROVIDER, model: `${provider}/${name}` };
|
|
86
|
-
};
|
|
87
|
-
export async function loadChatModel(options) {
|
|
88
|
-
const { provider, model } = await formatModelName((typeof options?.model === "string" ? options.model : undefined) || process.env.MODEL || "", options?.inquirerPromptFn ??
|
|
89
|
-
inquirer.prompt);
|
|
90
|
-
const { match, all } = findModel(provider);
|
|
91
|
-
if (!match) {
|
|
92
|
-
throw new Error(`Unsupported model provider ${provider}, available providers: ${all.map((m) => m.name).join(", ")}`);
|
|
93
|
-
}
|
|
94
|
-
const credential = provider.toLowerCase().includes(AIGNE_HUB_PROVIDER)
|
|
95
|
-
? await loadAIGNEHubCredential(options)
|
|
96
|
-
: undefined;
|
|
97
|
-
return match.create({
|
|
98
|
-
...credential,
|
|
99
|
-
baseURL: credential?.url,
|
|
100
|
-
model,
|
|
101
|
-
modelOptions: options && omit(options, "model", "aigneHubUrl", "inquirerPromptFn"),
|
|
102
|
-
});
|
|
103
|
-
}
|
|
104
|
-
export async function loadImageModel(options) {
|
|
105
|
-
const { provider, model } = await formatModelName((typeof options?.model === "string" ? options.model : undefined) ||
|
|
106
|
-
process.env.IMAGE_MODEL ||
|
|
107
|
-
"", options?.inquirerPromptFn ??
|
|
108
|
-
inquirer.prompt);
|
|
109
|
-
const { match, all } = findImageModel(provider);
|
|
110
|
-
if (!match) {
|
|
111
|
-
throw new Error(`Unsupported image model provider ${provider}, available providers: ${all.map((m) => m.name).join(", ")}`);
|
|
112
|
-
}
|
|
113
|
-
const credential = provider.toLowerCase().includes(AIGNE_HUB_PROVIDER)
|
|
114
|
-
? await loadAIGNEHubCredential(options)
|
|
115
|
-
: undefined;
|
|
116
|
-
return match.create({
|
|
117
|
-
...credential,
|
|
118
|
-
baseURL: credential?.url,
|
|
119
|
-
model,
|
|
120
|
-
modelOptions: options && omit(options, "model", "aigneHubUrl", "inquirerPromptFn"),
|
|
121
|
-
});
|
|
122
|
-
}
|
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
import type { GetDefaultOptions, ItemInfo, StoreOptions } from "@aigne/secrets";
|
|
2
|
-
import { FileStore as BaseFileStore } from "@aigne/secrets";
|
|
3
|
-
declare class FileStore extends BaseFileStore {
|
|
4
|
-
private outputConfig;
|
|
5
|
-
constructor(options: Required<Pick<StoreOptions, "filepath">>);
|
|
6
|
-
setKey(url: string, apiKey: string): Promise<void>;
|
|
7
|
-
getKey(url: string): Promise<ItemInfo | null>;
|
|
8
|
-
deleteKey(url: string): Promise<boolean>;
|
|
9
|
-
listHosts(): Promise<ItemInfo[]>;
|
|
10
|
-
listHostsMap(): Promise<Record<string, ItemInfo>>;
|
|
11
|
-
setDefault(url: string): Promise<void>;
|
|
12
|
-
getDefault(options?: GetDefaultOptions): Promise<ItemInfo | null>;
|
|
13
|
-
deleteDefault(): Promise<void>;
|
|
14
|
-
}
|
|
15
|
-
export default FileStore;
|
|
@@ -1,69 +0,0 @@
|
|
|
1
|
-
import { FileStore as BaseFileStore } from "@aigne/secrets";
|
|
2
|
-
class FileStore extends BaseFileStore {
|
|
3
|
-
outputConfig;
|
|
4
|
-
constructor(options) {
|
|
5
|
-
super(options);
|
|
6
|
-
this.outputConfig = { url: "AIGNE_HUB_API_URL", key: "AIGNE_HUB_API_KEY" };
|
|
7
|
-
}
|
|
8
|
-
async setKey(url, apiKey) {
|
|
9
|
-
return this.setItem(this.normalizeHostFrom(url), {
|
|
10
|
-
[this.outputConfig.url]: url,
|
|
11
|
-
[this.outputConfig.key]: apiKey,
|
|
12
|
-
});
|
|
13
|
-
}
|
|
14
|
-
async getKey(url) {
|
|
15
|
-
const host = this.normalizeHostFrom(url);
|
|
16
|
-
return this.getItem(host);
|
|
17
|
-
}
|
|
18
|
-
async deleteKey(url) {
|
|
19
|
-
const host = this.normalizeHostFrom(url);
|
|
20
|
-
return this.deleteItem(host);
|
|
21
|
-
}
|
|
22
|
-
async listHosts() {
|
|
23
|
-
return this.listEntries();
|
|
24
|
-
}
|
|
25
|
-
async listHostsMap() {
|
|
26
|
-
return this.listMap();
|
|
27
|
-
}
|
|
28
|
-
async setDefault(url) {
|
|
29
|
-
return this.setDefaultItem({ [this.outputConfig.url]: url });
|
|
30
|
-
}
|
|
31
|
-
async getDefault(options = {}) {
|
|
32
|
-
const { fallbackToFirst = false, presetIfFallback = false } = options;
|
|
33
|
-
if (!(await this.available()))
|
|
34
|
-
return null;
|
|
35
|
-
try {
|
|
36
|
-
const value = await this.getDefaultItem();
|
|
37
|
-
const apiUrl = value?.[this.outputConfig.url];
|
|
38
|
-
if (apiUrl) {
|
|
39
|
-
const defaultInfo = await this.getKey(apiUrl);
|
|
40
|
-
if (defaultInfo)
|
|
41
|
-
return defaultInfo;
|
|
42
|
-
}
|
|
43
|
-
}
|
|
44
|
-
catch {
|
|
45
|
-
// ignore
|
|
46
|
-
}
|
|
47
|
-
if (!fallbackToFirst)
|
|
48
|
-
return null;
|
|
49
|
-
const hosts = await this.listHosts();
|
|
50
|
-
if (hosts.length === 0)
|
|
51
|
-
return null;
|
|
52
|
-
const firstHost = hosts[0];
|
|
53
|
-
if (!firstHost)
|
|
54
|
-
return null;
|
|
55
|
-
if (presetIfFallback && firstHost[this.outputConfig.url]) {
|
|
56
|
-
try {
|
|
57
|
-
await this.setDefault(firstHost[this.outputConfig.url]);
|
|
58
|
-
}
|
|
59
|
-
catch {
|
|
60
|
-
// ignore
|
|
61
|
-
}
|
|
62
|
-
}
|
|
63
|
-
return firstHost;
|
|
64
|
-
}
|
|
65
|
-
async deleteDefault() {
|
|
66
|
-
return this.deleteDefaultItem();
|
|
67
|
-
}
|
|
68
|
-
}
|
|
69
|
-
export default FileStore;
|
|
@@ -1,43 +0,0 @@
|
|
|
1
|
-
import { logger } from "@aigne/core/utils/logger.js";
|
|
2
|
-
import { AIGNE_ENV_FILE, isTest } from "../constants.js";
|
|
3
|
-
import FileStore from "./file.js";
|
|
4
|
-
import KeyringStore from "./keytar.js";
|
|
5
|
-
import { migrateFileToKeyring } from "./migrate.js";
|
|
6
|
-
async function createSecretStore(options) {
|
|
7
|
-
if (!options.serviceName) {
|
|
8
|
-
throw new Error("Secret store key is required");
|
|
9
|
-
}
|
|
10
|
-
const keyring = new KeyringStore(options);
|
|
11
|
-
if (await keyring.available()) {
|
|
12
|
-
if (options.filepath) {
|
|
13
|
-
try {
|
|
14
|
-
await migrateFileToKeyring(options);
|
|
15
|
-
logger.debug("Successfully migrated credentials from file to keyring");
|
|
16
|
-
}
|
|
17
|
-
catch (error) {
|
|
18
|
-
logger.warn("Failed to migrate credentials from file to keyring:", error.message);
|
|
19
|
-
}
|
|
20
|
-
}
|
|
21
|
-
return keyring;
|
|
22
|
-
}
|
|
23
|
-
const filepath = options.filepath;
|
|
24
|
-
if (!filepath) {
|
|
25
|
-
throw new Error("Filepath is required");
|
|
26
|
-
}
|
|
27
|
-
return new FileStore({ filepath });
|
|
28
|
-
}
|
|
29
|
-
let cachedSecretStore;
|
|
30
|
-
const getSecretStore = async () => {
|
|
31
|
-
if (!cachedSecretStore) {
|
|
32
|
-
cachedSecretStore = await createSecretStore({
|
|
33
|
-
filepath: AIGNE_ENV_FILE,
|
|
34
|
-
serviceName: "aigne-hub",
|
|
35
|
-
forceKeytarUnavailable: Boolean(isTest),
|
|
36
|
-
});
|
|
37
|
-
}
|
|
38
|
-
return cachedSecretStore;
|
|
39
|
-
};
|
|
40
|
-
export const resetSecretStoreCache = () => {
|
|
41
|
-
cachedSecretStore = undefined;
|
|
42
|
-
};
|
|
43
|
-
export default getSecretStore;
|
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
import type { GetDefaultOptions, ItemInfo, StoreOptions } from "@aigne/secrets";
|
|
2
|
-
import { KeyringStore as BaseKeyringStore } from "@aigne/secrets";
|
|
3
|
-
declare class KeyringStore extends BaseKeyringStore {
|
|
4
|
-
private outputConfig;
|
|
5
|
-
constructor(options: StoreOptions);
|
|
6
|
-
setKey(url: string, apiKey: string): Promise<any>;
|
|
7
|
-
getKey(url: string): Promise<ItemInfo | null>;
|
|
8
|
-
deleteKey(url: string): Promise<boolean>;
|
|
9
|
-
listHosts(): Promise<ItemInfo[]>;
|
|
10
|
-
listHostsMap(): Promise<Record<string, ItemInfo>>;
|
|
11
|
-
setDefault(url: string): Promise<void>;
|
|
12
|
-
getDefault(options?: GetDefaultOptions): Promise<ItemInfo | null>;
|
|
13
|
-
deleteDefault(): Promise<void>;
|
|
14
|
-
}
|
|
15
|
-
export default KeyringStore;
|
|
@@ -1,67 +0,0 @@
|
|
|
1
|
-
import { KeyringStore as BaseKeyringStore } from "@aigne/secrets";
|
|
2
|
-
class KeyringStore extends BaseKeyringStore {
|
|
3
|
-
outputConfig;
|
|
4
|
-
constructor(options) {
|
|
5
|
-
super(options);
|
|
6
|
-
this.outputConfig = { url: "AIGNE_HUB_API_URL", key: "AIGNE_HUB_API_KEY" };
|
|
7
|
-
}
|
|
8
|
-
async setKey(url, apiKey) {
|
|
9
|
-
return this.setItem(this.normalizeHostFrom(url), {
|
|
10
|
-
[this.outputConfig.url]: url,
|
|
11
|
-
[this.outputConfig.key]: apiKey,
|
|
12
|
-
});
|
|
13
|
-
}
|
|
14
|
-
async getKey(url) {
|
|
15
|
-
const v = await this.getItem(this.normalizeHostFrom(url));
|
|
16
|
-
return v;
|
|
17
|
-
}
|
|
18
|
-
async deleteKey(url) {
|
|
19
|
-
const ok = await this.deleteItem(this.normalizeHostFrom(url));
|
|
20
|
-
return !!ok;
|
|
21
|
-
}
|
|
22
|
-
async listHosts() {
|
|
23
|
-
return this.listEntries();
|
|
24
|
-
}
|
|
25
|
-
async listHostsMap() {
|
|
26
|
-
return this.listMap();
|
|
27
|
-
}
|
|
28
|
-
async setDefault(url) {
|
|
29
|
-
return this.setDefaultItem({ [this.outputConfig.url]: url });
|
|
30
|
-
}
|
|
31
|
-
async getDefault(options = {}) {
|
|
32
|
-
const { fallbackToFirst = false, presetIfFallback = false } = options;
|
|
33
|
-
try {
|
|
34
|
-
const value = await this.getDefaultItem();
|
|
35
|
-
const apiUrl = value?.[this.outputConfig.url];
|
|
36
|
-
if (apiUrl) {
|
|
37
|
-
const defaultInfo = await this.getKey(apiUrl);
|
|
38
|
-
if (defaultInfo)
|
|
39
|
-
return defaultInfo;
|
|
40
|
-
}
|
|
41
|
-
}
|
|
42
|
-
catch {
|
|
43
|
-
// ignore
|
|
44
|
-
}
|
|
45
|
-
if (!fallbackToFirst)
|
|
46
|
-
return null;
|
|
47
|
-
const hosts = await this.listHosts();
|
|
48
|
-
if (hosts.length === 0)
|
|
49
|
-
return null;
|
|
50
|
-
const firstHost = hosts[0];
|
|
51
|
-
if (!firstHost)
|
|
52
|
-
return null;
|
|
53
|
-
if (presetIfFallback && firstHost[this.outputConfig.url]) {
|
|
54
|
-
try {
|
|
55
|
-
await this.setDefault(firstHost[this.outputConfig.url]);
|
|
56
|
-
}
|
|
57
|
-
catch {
|
|
58
|
-
// ignore
|
|
59
|
-
}
|
|
60
|
-
}
|
|
61
|
-
return firstHost;
|
|
62
|
-
}
|
|
63
|
-
async deleteDefault() {
|
|
64
|
-
return this.deleteDefaultItem();
|
|
65
|
-
}
|
|
66
|
-
}
|
|
67
|
-
export default KeyringStore;
|
|
@@ -1,57 +0,0 @@
|
|
|
1
|
-
import fs from "node:fs/promises";
|
|
2
|
-
import { logger } from "@aigne/core/utils/logger.js";
|
|
3
|
-
import FileStore from "./file.js";
|
|
4
|
-
import KeyringStore from "./keytar.js";
|
|
5
|
-
export async function migrateFileToKeyring(options) {
|
|
6
|
-
const { filepath } = options;
|
|
7
|
-
const outputConfig = {
|
|
8
|
-
url: "AIGNE_HUB_API_URL",
|
|
9
|
-
key: "AIGNE_HUB_API_KEY",
|
|
10
|
-
};
|
|
11
|
-
if (!filepath) {
|
|
12
|
-
throw new Error("Filepath is required for migration");
|
|
13
|
-
}
|
|
14
|
-
try {
|
|
15
|
-
await fs.access(filepath);
|
|
16
|
-
}
|
|
17
|
-
catch {
|
|
18
|
-
return true;
|
|
19
|
-
}
|
|
20
|
-
const keyring = new KeyringStore(options);
|
|
21
|
-
if (!(await keyring.available())) {
|
|
22
|
-
return false;
|
|
23
|
-
}
|
|
24
|
-
const fileStore = new FileStore({ filepath });
|
|
25
|
-
if (!(await fileStore.available())) {
|
|
26
|
-
return false;
|
|
27
|
-
}
|
|
28
|
-
const backupPath = `${filepath}.backup`;
|
|
29
|
-
try {
|
|
30
|
-
// Create backup before migration
|
|
31
|
-
await fs.copyFile(filepath, backupPath);
|
|
32
|
-
const hosts = await fileStore.listHosts();
|
|
33
|
-
for (const host of hosts) {
|
|
34
|
-
if (host[outputConfig.url] && host[outputConfig.key]) {
|
|
35
|
-
await keyring.setKey(host[outputConfig.url], host[outputConfig.key]);
|
|
36
|
-
}
|
|
37
|
-
}
|
|
38
|
-
const defaultKey = await fileStore.getDefault();
|
|
39
|
-
if (defaultKey) {
|
|
40
|
-
await keyring.setDefault(defaultKey[outputConfig.url]);
|
|
41
|
-
}
|
|
42
|
-
await fs.rm(filepath);
|
|
43
|
-
await fs.rm(backupPath);
|
|
44
|
-
return true;
|
|
45
|
-
}
|
|
46
|
-
catch (error) {
|
|
47
|
-
try {
|
|
48
|
-
await fs.copyFile(backupPath, filepath);
|
|
49
|
-
await fs.rm(backupPath);
|
|
50
|
-
}
|
|
51
|
-
catch {
|
|
52
|
-
// If restore fails, at least backup exists
|
|
53
|
-
}
|
|
54
|
-
logger.error(`Migration failed: ${error instanceof Error ? error.message : String(error)}`);
|
|
55
|
-
return false;
|
|
56
|
-
}
|
|
57
|
-
}
|
|
@@ -1,38 +0,0 @@
|
|
|
1
|
-
type InquirerPromptFn = (prompt: {
|
|
2
|
-
type: string;
|
|
3
|
-
name: string;
|
|
4
|
-
message: string;
|
|
5
|
-
choices: {
|
|
6
|
-
name: string;
|
|
7
|
-
value: any;
|
|
8
|
-
}[];
|
|
9
|
-
default: any;
|
|
10
|
-
}) => Promise<any>;
|
|
11
|
-
export type LoadCredentialOptions = {
|
|
12
|
-
aigneHubUrl?: string;
|
|
13
|
-
inquirerPromptFn?: InquirerPromptFn;
|
|
14
|
-
};
|
|
15
|
-
export type FetchResult = {
|
|
16
|
-
accessKeyId: string;
|
|
17
|
-
accessKeySecret: string;
|
|
18
|
-
};
|
|
19
|
-
export type BaseWrapSpinner = (_: string, waiting: () => Promise<FetchResult>) => Promise<FetchResult>;
|
|
20
|
-
export interface CreateConnectOptions {
|
|
21
|
-
connectUrl: string;
|
|
22
|
-
openPage?: (url: string) => void;
|
|
23
|
-
fetchInterval?: number;
|
|
24
|
-
retry?: number;
|
|
25
|
-
source?: string;
|
|
26
|
-
connectAction?: string;
|
|
27
|
-
appName?: string;
|
|
28
|
-
appLogo?: string;
|
|
29
|
-
wrapSpinner?: BaseWrapSpinner;
|
|
30
|
-
prettyUrl?: (url: string) => string;
|
|
31
|
-
closeOnSuccess?: boolean;
|
|
32
|
-
intervalFetchConfig?: (options: {
|
|
33
|
-
sessionId: string;
|
|
34
|
-
fetchInterval: number;
|
|
35
|
-
fetchTimeout: number;
|
|
36
|
-
}) => Promise<FetchResult>;
|
|
37
|
-
}
|
|
38
|
-
export {};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|