@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,64 @@
|
|
|
1
|
+
import { FileStore } from "@aigne/secrets";
|
|
2
|
+
|
|
3
|
+
//#region src/utils/aigne-hub/store/file.ts
|
|
4
|
+
var FileStore$1 = class extends FileStore {
|
|
5
|
+
outputConfig;
|
|
6
|
+
constructor(options) {
|
|
7
|
+
super(options);
|
|
8
|
+
this.outputConfig = {
|
|
9
|
+
url: "AIGNE_HUB_API_URL",
|
|
10
|
+
key: "AIGNE_HUB_API_KEY"
|
|
11
|
+
};
|
|
12
|
+
}
|
|
13
|
+
async setKey(url, apiKey) {
|
|
14
|
+
return this.setItem(this.normalizeHostFrom(url), {
|
|
15
|
+
[this.outputConfig.url]: url,
|
|
16
|
+
[this.outputConfig.key]: apiKey
|
|
17
|
+
});
|
|
18
|
+
}
|
|
19
|
+
async getKey(url) {
|
|
20
|
+
const host = this.normalizeHostFrom(url);
|
|
21
|
+
return this.getItem(host);
|
|
22
|
+
}
|
|
23
|
+
async deleteKey(url) {
|
|
24
|
+
const host = this.normalizeHostFrom(url);
|
|
25
|
+
return this.deleteItem(host);
|
|
26
|
+
}
|
|
27
|
+
async listHosts() {
|
|
28
|
+
return this.listEntries();
|
|
29
|
+
}
|
|
30
|
+
async listHostsMap() {
|
|
31
|
+
return this.listMap();
|
|
32
|
+
}
|
|
33
|
+
async setDefault(url) {
|
|
34
|
+
return this.setDefaultItem({ [this.outputConfig.url]: url });
|
|
35
|
+
}
|
|
36
|
+
async getDefault(options = {}) {
|
|
37
|
+
const { fallbackToFirst = false, presetIfFallback = false } = options;
|
|
38
|
+
if (!await this.available()) return null;
|
|
39
|
+
try {
|
|
40
|
+
const apiUrl = (await this.getDefaultItem())?.[this.outputConfig.url];
|
|
41
|
+
if (apiUrl) {
|
|
42
|
+
const defaultInfo = await this.getKey(apiUrl);
|
|
43
|
+
if (defaultInfo) return defaultInfo;
|
|
44
|
+
}
|
|
45
|
+
} catch {}
|
|
46
|
+
if (!fallbackToFirst) return null;
|
|
47
|
+
const hosts = await this.listHosts();
|
|
48
|
+
if (hosts.length === 0) return null;
|
|
49
|
+
const firstHost = hosts[0];
|
|
50
|
+
if (!firstHost) return null;
|
|
51
|
+
if (presetIfFallback && firstHost[this.outputConfig.url]) try {
|
|
52
|
+
await this.setDefault(firstHost[this.outputConfig.url]);
|
|
53
|
+
} catch {}
|
|
54
|
+
return firstHost;
|
|
55
|
+
}
|
|
56
|
+
async deleteDefault() {
|
|
57
|
+
return this.deleteDefaultItem();
|
|
58
|
+
}
|
|
59
|
+
};
|
|
60
|
+
var file_default = FileStore$1;
|
|
61
|
+
|
|
62
|
+
//#endregion
|
|
63
|
+
export { file_default as default };
|
|
64
|
+
//# sourceMappingURL=file.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"file.mjs","names":["FileStore","BaseFileStore"],"sources":["../../../../src/utils/aigne-hub/store/file.ts"],"sourcesContent":["import type { GetDefaultOptions, ItemInfo, StoreOptions } from \"@aigne/secrets\";\nimport { FileStore as BaseFileStore } from \"@aigne/secrets\";\n\nclass FileStore extends BaseFileStore {\n private outputConfig: { key: string; url: string };\n\n constructor(options: Required<Pick<StoreOptions, \"filepath\">>) {\n super(options);\n this.outputConfig = { url: \"AIGNE_HUB_API_URL\", key: \"AIGNE_HUB_API_KEY\" };\n }\n\n async setKey(url: string, apiKey: string): Promise<void> {\n return this.setItem(this.normalizeHostFrom(url), {\n [this.outputConfig.url]: url,\n [this.outputConfig.key]: apiKey,\n });\n }\n\n async getKey(url: string): Promise<ItemInfo | null> {\n const host = this.normalizeHostFrom(url);\n return this.getItem(host);\n }\n\n async deleteKey(url: string): Promise<boolean> {\n const host = this.normalizeHostFrom(url);\n return this.deleteItem(host);\n }\n\n async listHosts(): Promise<ItemInfo[]> {\n return this.listEntries();\n }\n\n async listHostsMap(): Promise<Record<string, ItemInfo>> {\n return this.listMap();\n }\n\n async setDefault(url: string): Promise<void> {\n return this.setDefaultItem({ [this.outputConfig.url]: url });\n }\n\n async getDefault(options: GetDefaultOptions = {}): Promise<ItemInfo | null> {\n const { fallbackToFirst = false, presetIfFallback = false } = options;\n if (!(await this.available())) return null;\n\n try {\n const value = await this.getDefaultItem();\n const apiUrl = value?.[this.outputConfig.url];\n if (apiUrl) {\n const defaultInfo = await this.getKey(apiUrl);\n if (defaultInfo) return defaultInfo;\n }\n } catch {\n // ignore\n }\n\n if (!fallbackToFirst) return null;\n\n const hosts = await this.listHosts();\n if (hosts.length === 0) return null;\n\n const firstHost = hosts[0];\n if (!firstHost) return null;\n\n if (presetIfFallback && firstHost[this.outputConfig.url]) {\n try {\n await this.setDefault(firstHost[this.outputConfig.url]);\n } catch {\n // ignore\n }\n }\n\n return firstHost;\n }\n\n async deleteDefault(): Promise<void> {\n return this.deleteDefaultItem();\n }\n}\n\nexport default FileStore;\n"],"mappings":";;;AAGA,IAAMA,cAAN,cAAwBC,UAAc;CACpC,AAAQ;CAER,YAAY,SAAmD;AAC7D,QAAM,QAAQ;AACd,OAAK,eAAe;GAAE,KAAK;GAAqB,KAAK;GAAqB;;CAG5E,MAAM,OAAO,KAAa,QAA+B;AACvD,SAAO,KAAK,QAAQ,KAAK,kBAAkB,IAAI,EAAE;IAC9C,KAAK,aAAa,MAAM;IACxB,KAAK,aAAa,MAAM;GAC1B,CAAC;;CAGJ,MAAM,OAAO,KAAuC;EAClD,MAAM,OAAO,KAAK,kBAAkB,IAAI;AACxC,SAAO,KAAK,QAAQ,KAAK;;CAG3B,MAAM,UAAU,KAA+B;EAC7C,MAAM,OAAO,KAAK,kBAAkB,IAAI;AACxC,SAAO,KAAK,WAAW,KAAK;;CAG9B,MAAM,YAAiC;AACrC,SAAO,KAAK,aAAa;;CAG3B,MAAM,eAAkD;AACtD,SAAO,KAAK,SAAS;;CAGvB,MAAM,WAAW,KAA4B;AAC3C,SAAO,KAAK,eAAe,GAAG,KAAK,aAAa,MAAM,KAAK,CAAC;;CAG9D,MAAM,WAAW,UAA6B,EAAE,EAA4B;EAC1E,MAAM,EAAE,kBAAkB,OAAO,mBAAmB,UAAU;AAC9D,MAAI,CAAE,MAAM,KAAK,WAAW,CAAG,QAAO;AAEtC,MAAI;GAEF,MAAM,UADQ,MAAM,KAAK,gBAAgB,IAClB,KAAK,aAAa;AACzC,OAAI,QAAQ;IACV,MAAM,cAAc,MAAM,KAAK,OAAO,OAAO;AAC7C,QAAI,YAAa,QAAO;;UAEpB;AAIR,MAAI,CAAC,gBAAiB,QAAO;EAE7B,MAAM,QAAQ,MAAM,KAAK,WAAW;AACpC,MAAI,MAAM,WAAW,EAAG,QAAO;EAE/B,MAAM,YAAY,MAAM;AACxB,MAAI,CAAC,UAAW,QAAO;AAEvB,MAAI,oBAAoB,UAAU,KAAK,aAAa,KAClD,KAAI;AACF,SAAM,KAAK,WAAW,UAAU,KAAK,aAAa,KAAK;UACjD;AAKV,SAAO;;CAGT,MAAM,gBAA+B;AACnC,SAAO,KAAK,mBAAmB;;;AAInC,mBAAeD"}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
const require_rolldown_runtime = require('../../../_virtual/rolldown_runtime.cjs');
|
|
2
|
+
const require_constants = require('../constants.cjs');
|
|
3
|
+
const require_file = require('./file.cjs');
|
|
4
|
+
const require_keytar = require('./keytar.cjs');
|
|
5
|
+
const require_migrate = require('./migrate.cjs');
|
|
6
|
+
let _aigne_core_utils_logger = require("@aigne/core/utils/logger");
|
|
7
|
+
|
|
8
|
+
//#region src/utils/aigne-hub/store/index.ts
|
|
9
|
+
async function createSecretStore(options) {
|
|
10
|
+
if (!options.serviceName) throw new Error("Secret store key is required");
|
|
11
|
+
const keyring = new require_keytar.default(options);
|
|
12
|
+
if (await keyring.available()) {
|
|
13
|
+
if (options.filepath) try {
|
|
14
|
+
await require_migrate.migrateFileToKeyring(options);
|
|
15
|
+
_aigne_core_utils_logger.logger.debug("Successfully migrated credentials from file to keyring");
|
|
16
|
+
} catch (error) {
|
|
17
|
+
_aigne_core_utils_logger.logger.warn("Failed to migrate credentials from file to keyring:", error.message);
|
|
18
|
+
}
|
|
19
|
+
return keyring;
|
|
20
|
+
}
|
|
21
|
+
const filepath = options.filepath;
|
|
22
|
+
if (!filepath) throw new Error("Filepath is required");
|
|
23
|
+
return new require_file.default({ filepath });
|
|
24
|
+
}
|
|
25
|
+
let cachedSecretStore;
|
|
26
|
+
const getSecretStore = async () => {
|
|
27
|
+
if (!cachedSecretStore) cachedSecretStore = await createSecretStore({
|
|
28
|
+
filepath: require_constants.AIGNE_ENV_FILE,
|
|
29
|
+
serviceName: "aigne-hub",
|
|
30
|
+
forceKeytarUnavailable: Boolean(require_constants.isTest)
|
|
31
|
+
});
|
|
32
|
+
return cachedSecretStore;
|
|
33
|
+
};
|
|
34
|
+
var store_default = getSecretStore;
|
|
35
|
+
|
|
36
|
+
//#endregion
|
|
37
|
+
exports.default = store_default;
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import { AIGNE_ENV_FILE, isTest } from "../constants.mjs";
|
|
2
|
+
import file_default from "./file.mjs";
|
|
3
|
+
import keytar_default from "./keytar.mjs";
|
|
4
|
+
import { migrateFileToKeyring } from "./migrate.mjs";
|
|
5
|
+
import { logger } from "@aigne/core/utils/logger";
|
|
6
|
+
|
|
7
|
+
//#region src/utils/aigne-hub/store/index.ts
|
|
8
|
+
async function createSecretStore(options) {
|
|
9
|
+
if (!options.serviceName) throw new Error("Secret store key is required");
|
|
10
|
+
const keyring = new keytar_default(options);
|
|
11
|
+
if (await keyring.available()) {
|
|
12
|
+
if (options.filepath) try {
|
|
13
|
+
await migrateFileToKeyring(options);
|
|
14
|
+
logger.debug("Successfully migrated credentials from file to keyring");
|
|
15
|
+
} catch (error) {
|
|
16
|
+
logger.warn("Failed to migrate credentials from file to keyring:", error.message);
|
|
17
|
+
}
|
|
18
|
+
return keyring;
|
|
19
|
+
}
|
|
20
|
+
const filepath = options.filepath;
|
|
21
|
+
if (!filepath) throw new Error("Filepath is required");
|
|
22
|
+
return new file_default({ filepath });
|
|
23
|
+
}
|
|
24
|
+
let cachedSecretStore;
|
|
25
|
+
const getSecretStore = async () => {
|
|
26
|
+
if (!cachedSecretStore) cachedSecretStore = await createSecretStore({
|
|
27
|
+
filepath: AIGNE_ENV_FILE,
|
|
28
|
+
serviceName: "aigne-hub",
|
|
29
|
+
forceKeytarUnavailable: Boolean(isTest)
|
|
30
|
+
});
|
|
31
|
+
return cachedSecretStore;
|
|
32
|
+
};
|
|
33
|
+
var store_default = getSecretStore;
|
|
34
|
+
|
|
35
|
+
//#endregion
|
|
36
|
+
export { store_default as default };
|
|
37
|
+
//# sourceMappingURL=index.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.mjs","names":["KeyringStore","FileStore"],"sources":["../../../../src/utils/aigne-hub/store/index.ts"],"sourcesContent":["import { logger } from \"@aigne/core/utils/logger\";\nimport type { StoreOptions } from \"@aigne/secrets\";\nimport { AIGNE_ENV_FILE, isTest } from \"../constants.js\";\nimport FileStore from \"./file.js\";\nimport KeyringStore from \"./keytar.js\";\nimport { migrateFileToKeyring } from \"./migrate.js\";\n\nasync function createSecretStore(options: StoreOptions): Promise<KeyringStore | FileStore> {\n if (!options.serviceName) {\n throw new Error(\"Secret store key is required\");\n }\n\n const keyring = new KeyringStore(options);\n if (await keyring.available()) {\n if (options.filepath) {\n try {\n await migrateFileToKeyring(options);\n logger.debug(\"Successfully migrated credentials from file to keyring\");\n } catch (error) {\n logger.warn(\"Failed to migrate credentials from file to keyring:\", error.message);\n }\n }\n\n return keyring;\n }\n\n const filepath = options.filepath;\n if (!filepath) {\n throw new Error(\"Filepath is required\");\n }\n\n return new FileStore({ filepath });\n}\n\nlet cachedSecretStore: KeyringStore | FileStore | undefined;\nconst getSecretStore = async () => {\n if (!cachedSecretStore) {\n cachedSecretStore = await createSecretStore({\n filepath: AIGNE_ENV_FILE,\n serviceName: \"aigne-hub\",\n forceKeytarUnavailable: Boolean(isTest),\n });\n }\n\n return cachedSecretStore;\n};\n\nexport const resetSecretStoreCache = () => {\n cachedSecretStore = undefined;\n};\n\nexport default getSecretStore;\n"],"mappings":";;;;;;;AAOA,eAAe,kBAAkB,SAA0D;AACzF,KAAI,CAAC,QAAQ,YACX,OAAM,IAAI,MAAM,+BAA+B;CAGjD,MAAM,UAAU,IAAIA,eAAa,QAAQ;AACzC,KAAI,MAAM,QAAQ,WAAW,EAAE;AAC7B,MAAI,QAAQ,SACV,KAAI;AACF,SAAM,qBAAqB,QAAQ;AACnC,UAAO,MAAM,yDAAyD;WAC/D,OAAO;AACd,UAAO,KAAK,uDAAuD,MAAM,QAAQ;;AAIrF,SAAO;;CAGT,MAAM,WAAW,QAAQ;AACzB,KAAI,CAAC,SACH,OAAM,IAAI,MAAM,uBAAuB;AAGzC,QAAO,IAAIC,aAAU,EAAE,UAAU,CAAC;;AAGpC,IAAI;AACJ,MAAM,iBAAiB,YAAY;AACjC,KAAI,CAAC,kBACH,qBAAoB,MAAM,kBAAkB;EAC1C,UAAU;EACV,aAAa;EACb,wBAAwB,QAAQ,OAAO;EACxC,CAAC;AAGJ,QAAO;;AAOT,oBAAe"}
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
const require_rolldown_runtime = require('../../../_virtual/rolldown_runtime.cjs');
|
|
2
|
+
let _aigne_secrets = require("@aigne/secrets");
|
|
3
|
+
|
|
4
|
+
//#region src/utils/aigne-hub/store/keytar.ts
|
|
5
|
+
var KeyringStore = class extends _aigne_secrets.KeyringStore {
|
|
6
|
+
outputConfig;
|
|
7
|
+
constructor(options) {
|
|
8
|
+
super(options);
|
|
9
|
+
this.outputConfig = {
|
|
10
|
+
url: "AIGNE_HUB_API_URL",
|
|
11
|
+
key: "AIGNE_HUB_API_KEY"
|
|
12
|
+
};
|
|
13
|
+
}
|
|
14
|
+
async setKey(url, apiKey) {
|
|
15
|
+
return this.setItem(this.normalizeHostFrom(url), {
|
|
16
|
+
[this.outputConfig.url]: url,
|
|
17
|
+
[this.outputConfig.key]: apiKey
|
|
18
|
+
});
|
|
19
|
+
}
|
|
20
|
+
async getKey(url) {
|
|
21
|
+
return await this.getItem(this.normalizeHostFrom(url));
|
|
22
|
+
}
|
|
23
|
+
async deleteKey(url) {
|
|
24
|
+
return !!await this.deleteItem(this.normalizeHostFrom(url));
|
|
25
|
+
}
|
|
26
|
+
async listHosts() {
|
|
27
|
+
return this.listEntries();
|
|
28
|
+
}
|
|
29
|
+
async listHostsMap() {
|
|
30
|
+
return this.listMap();
|
|
31
|
+
}
|
|
32
|
+
async setDefault(url) {
|
|
33
|
+
return this.setDefaultItem({ [this.outputConfig.url]: url });
|
|
34
|
+
}
|
|
35
|
+
async getDefault(options = {}) {
|
|
36
|
+
const { fallbackToFirst = false, presetIfFallback = false } = options;
|
|
37
|
+
try {
|
|
38
|
+
const apiUrl = (await this.getDefaultItem())?.[this.outputConfig.url];
|
|
39
|
+
if (apiUrl) {
|
|
40
|
+
const defaultInfo = await this.getKey(apiUrl);
|
|
41
|
+
if (defaultInfo) return defaultInfo;
|
|
42
|
+
}
|
|
43
|
+
} catch {}
|
|
44
|
+
if (!fallbackToFirst) return null;
|
|
45
|
+
const hosts = await this.listHosts();
|
|
46
|
+
if (hosts.length === 0) return null;
|
|
47
|
+
const firstHost = hosts[0];
|
|
48
|
+
if (!firstHost) return null;
|
|
49
|
+
if (presetIfFallback && firstHost[this.outputConfig.url]) try {
|
|
50
|
+
await this.setDefault(firstHost[this.outputConfig.url]);
|
|
51
|
+
} catch {}
|
|
52
|
+
return firstHost;
|
|
53
|
+
}
|
|
54
|
+
async deleteDefault() {
|
|
55
|
+
return this.deleteDefaultItem();
|
|
56
|
+
}
|
|
57
|
+
};
|
|
58
|
+
var keytar_default = KeyringStore;
|
|
59
|
+
|
|
60
|
+
//#endregion
|
|
61
|
+
exports.default = keytar_default;
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
import { KeyringStore } from "@aigne/secrets";
|
|
2
|
+
|
|
3
|
+
//#region src/utils/aigne-hub/store/keytar.ts
|
|
4
|
+
var KeyringStore$1 = class extends KeyringStore {
|
|
5
|
+
outputConfig;
|
|
6
|
+
constructor(options) {
|
|
7
|
+
super(options);
|
|
8
|
+
this.outputConfig = {
|
|
9
|
+
url: "AIGNE_HUB_API_URL",
|
|
10
|
+
key: "AIGNE_HUB_API_KEY"
|
|
11
|
+
};
|
|
12
|
+
}
|
|
13
|
+
async setKey(url, apiKey) {
|
|
14
|
+
return this.setItem(this.normalizeHostFrom(url), {
|
|
15
|
+
[this.outputConfig.url]: url,
|
|
16
|
+
[this.outputConfig.key]: apiKey
|
|
17
|
+
});
|
|
18
|
+
}
|
|
19
|
+
async getKey(url) {
|
|
20
|
+
return await this.getItem(this.normalizeHostFrom(url));
|
|
21
|
+
}
|
|
22
|
+
async deleteKey(url) {
|
|
23
|
+
return !!await this.deleteItem(this.normalizeHostFrom(url));
|
|
24
|
+
}
|
|
25
|
+
async listHosts() {
|
|
26
|
+
return this.listEntries();
|
|
27
|
+
}
|
|
28
|
+
async listHostsMap() {
|
|
29
|
+
return this.listMap();
|
|
30
|
+
}
|
|
31
|
+
async setDefault(url) {
|
|
32
|
+
return this.setDefaultItem({ [this.outputConfig.url]: url });
|
|
33
|
+
}
|
|
34
|
+
async getDefault(options = {}) {
|
|
35
|
+
const { fallbackToFirst = false, presetIfFallback = false } = options;
|
|
36
|
+
try {
|
|
37
|
+
const apiUrl = (await this.getDefaultItem())?.[this.outputConfig.url];
|
|
38
|
+
if (apiUrl) {
|
|
39
|
+
const defaultInfo = await this.getKey(apiUrl);
|
|
40
|
+
if (defaultInfo) return defaultInfo;
|
|
41
|
+
}
|
|
42
|
+
} catch {}
|
|
43
|
+
if (!fallbackToFirst) return null;
|
|
44
|
+
const hosts = await this.listHosts();
|
|
45
|
+
if (hosts.length === 0) return null;
|
|
46
|
+
const firstHost = hosts[0];
|
|
47
|
+
if (!firstHost) return null;
|
|
48
|
+
if (presetIfFallback && firstHost[this.outputConfig.url]) try {
|
|
49
|
+
await this.setDefault(firstHost[this.outputConfig.url]);
|
|
50
|
+
} catch {}
|
|
51
|
+
return firstHost;
|
|
52
|
+
}
|
|
53
|
+
async deleteDefault() {
|
|
54
|
+
return this.deleteDefaultItem();
|
|
55
|
+
}
|
|
56
|
+
};
|
|
57
|
+
var keytar_default = KeyringStore$1;
|
|
58
|
+
|
|
59
|
+
//#endregion
|
|
60
|
+
export { keytar_default as default };
|
|
61
|
+
//# sourceMappingURL=keytar.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"keytar.mjs","names":["KeyringStore","BaseKeyringStore"],"sources":["../../../../src/utils/aigne-hub/store/keytar.ts"],"sourcesContent":["import type { GetDefaultOptions, ItemInfo, StoreOptions } from \"@aigne/secrets\";\nimport { KeyringStore as BaseKeyringStore } from \"@aigne/secrets\";\n\nclass KeyringStore extends BaseKeyringStore {\n private outputConfig: { key: string; url: string };\n\n constructor(options: StoreOptions) {\n super(options);\n this.outputConfig = { url: \"AIGNE_HUB_API_URL\", key: \"AIGNE_HUB_API_KEY\" };\n }\n\n async setKey(url: string, apiKey: string) {\n return this.setItem(this.normalizeHostFrom(url), {\n [this.outputConfig.url]: url,\n [this.outputConfig.key]: apiKey,\n });\n }\n\n async getKey(url: string): Promise<ItemInfo | null> {\n const v = await this.getItem(this.normalizeHostFrom(url));\n return v;\n }\n\n async deleteKey(url: string): Promise<boolean> {\n const ok = await this.deleteItem(this.normalizeHostFrom(url));\n return !!ok;\n }\n\n async listHosts(): Promise<ItemInfo[]> {\n return this.listEntries();\n }\n\n async listHostsMap(): Promise<Record<string, ItemInfo>> {\n return this.listMap();\n }\n\n async setDefault(url: string): Promise<void> {\n return this.setDefaultItem({ [this.outputConfig.url]: url });\n }\n\n async getDefault(options: GetDefaultOptions = {}): Promise<ItemInfo | null> {\n const { fallbackToFirst = false, presetIfFallback = false } = options;\n\n try {\n const value = await this.getDefaultItem();\n const apiUrl = value?.[this.outputConfig.url];\n if (apiUrl) {\n const defaultInfo = await this.getKey(apiUrl);\n if (defaultInfo) return defaultInfo;\n }\n } catch {\n // ignore\n }\n\n if (!fallbackToFirst) return null;\n\n const hosts = await this.listHosts();\n if (hosts.length === 0) return null;\n\n const firstHost = hosts[0];\n if (!firstHost) return null;\n\n if (presetIfFallback && firstHost[this.outputConfig.url]) {\n try {\n await this.setDefault(firstHost[this.outputConfig.url]);\n } catch {\n // ignore\n }\n }\n\n return firstHost;\n }\n\n async deleteDefault(): Promise<void> {\n return this.deleteDefaultItem();\n }\n}\n\nexport default KeyringStore;\n"],"mappings":";;;AAGA,IAAMA,iBAAN,cAA2BC,aAAiB;CAC1C,AAAQ;CAER,YAAY,SAAuB;AACjC,QAAM,QAAQ;AACd,OAAK,eAAe;GAAE,KAAK;GAAqB,KAAK;GAAqB;;CAG5E,MAAM,OAAO,KAAa,QAAgB;AACxC,SAAO,KAAK,QAAQ,KAAK,kBAAkB,IAAI,EAAE;IAC9C,KAAK,aAAa,MAAM;IACxB,KAAK,aAAa,MAAM;GAC1B,CAAC;;CAGJ,MAAM,OAAO,KAAuC;AAElD,SADU,MAAM,KAAK,QAAQ,KAAK,kBAAkB,IAAI,CAAC;;CAI3D,MAAM,UAAU,KAA+B;AAE7C,SAAO,CAAC,CADG,MAAM,KAAK,WAAW,KAAK,kBAAkB,IAAI,CAAC;;CAI/D,MAAM,YAAiC;AACrC,SAAO,KAAK,aAAa;;CAG3B,MAAM,eAAkD;AACtD,SAAO,KAAK,SAAS;;CAGvB,MAAM,WAAW,KAA4B;AAC3C,SAAO,KAAK,eAAe,GAAG,KAAK,aAAa,MAAM,KAAK,CAAC;;CAG9D,MAAM,WAAW,UAA6B,EAAE,EAA4B;EAC1E,MAAM,EAAE,kBAAkB,OAAO,mBAAmB,UAAU;AAE9D,MAAI;GAEF,MAAM,UADQ,MAAM,KAAK,gBAAgB,IAClB,KAAK,aAAa;AACzC,OAAI,QAAQ;IACV,MAAM,cAAc,MAAM,KAAK,OAAO,OAAO;AAC7C,QAAI,YAAa,QAAO;;UAEpB;AAIR,MAAI,CAAC,gBAAiB,QAAO;EAE7B,MAAM,QAAQ,MAAM,KAAK,WAAW;AACpC,MAAI,MAAM,WAAW,EAAG,QAAO;EAE/B,MAAM,YAAY,MAAM;AACxB,MAAI,CAAC,UAAW,QAAO;AAEvB,MAAI,oBAAoB,UAAU,KAAK,aAAa,KAClD,KAAI;AACF,SAAM,KAAK,WAAW,UAAU,KAAK,aAAa,KAAK;UACjD;AAKV,SAAO;;CAGT,MAAM,gBAA+B;AACnC,SAAO,KAAK,mBAAmB;;;AAInC,qBAAeD"}
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
const require_rolldown_runtime = require('../../../_virtual/rolldown_runtime.cjs');
|
|
2
|
+
const require_file = require('./file.cjs');
|
|
3
|
+
const require_keytar = require('./keytar.cjs');
|
|
4
|
+
let _aigne_core_utils_logger = require("@aigne/core/utils/logger");
|
|
5
|
+
let node_fs_promises = require("node:fs/promises");
|
|
6
|
+
node_fs_promises = require_rolldown_runtime.__toESM(node_fs_promises);
|
|
7
|
+
|
|
8
|
+
//#region src/utils/aigne-hub/store/migrate.ts
|
|
9
|
+
async function migrateFileToKeyring(options) {
|
|
10
|
+
const { filepath } = options;
|
|
11
|
+
const outputConfig = {
|
|
12
|
+
url: "AIGNE_HUB_API_URL",
|
|
13
|
+
key: "AIGNE_HUB_API_KEY"
|
|
14
|
+
};
|
|
15
|
+
if (!filepath) throw new Error("Filepath is required for migration");
|
|
16
|
+
try {
|
|
17
|
+
await node_fs_promises.default.access(filepath);
|
|
18
|
+
} catch {
|
|
19
|
+
return true;
|
|
20
|
+
}
|
|
21
|
+
const keyring = new require_keytar.default(options);
|
|
22
|
+
if (!await keyring.available()) return false;
|
|
23
|
+
const fileStore = new require_file.default({ filepath });
|
|
24
|
+
if (!await fileStore.available()) return false;
|
|
25
|
+
const backupPath = `${filepath}.backup`;
|
|
26
|
+
try {
|
|
27
|
+
await node_fs_promises.default.copyFile(filepath, backupPath);
|
|
28
|
+
const hosts = await fileStore.listHosts();
|
|
29
|
+
for (const host of hosts) if (host[outputConfig.url] && host[outputConfig.key]) await keyring.setKey(host[outputConfig.url], host[outputConfig.key]);
|
|
30
|
+
const defaultKey = await fileStore.getDefault();
|
|
31
|
+
if (defaultKey) await keyring.setDefault(defaultKey[outputConfig.url]);
|
|
32
|
+
await node_fs_promises.default.rm(filepath);
|
|
33
|
+
await node_fs_promises.default.rm(backupPath);
|
|
34
|
+
return true;
|
|
35
|
+
} catch (error) {
|
|
36
|
+
try {
|
|
37
|
+
await node_fs_promises.default.copyFile(backupPath, filepath);
|
|
38
|
+
await node_fs_promises.default.rm(backupPath);
|
|
39
|
+
} catch {}
|
|
40
|
+
_aigne_core_utils_logger.logger.error(`Migration failed: ${error instanceof Error ? error.message : String(error)}`);
|
|
41
|
+
return false;
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
//#endregion
|
|
46
|
+
exports.migrateFileToKeyring = migrateFileToKeyring;
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import file_default from "./file.mjs";
|
|
2
|
+
import keytar_default from "./keytar.mjs";
|
|
3
|
+
import { logger } from "@aigne/core/utils/logger";
|
|
4
|
+
import fs from "node:fs/promises";
|
|
5
|
+
|
|
6
|
+
//#region src/utils/aigne-hub/store/migrate.ts
|
|
7
|
+
async function migrateFileToKeyring(options) {
|
|
8
|
+
const { filepath } = options;
|
|
9
|
+
const outputConfig = {
|
|
10
|
+
url: "AIGNE_HUB_API_URL",
|
|
11
|
+
key: "AIGNE_HUB_API_KEY"
|
|
12
|
+
};
|
|
13
|
+
if (!filepath) throw new Error("Filepath is required for migration");
|
|
14
|
+
try {
|
|
15
|
+
await fs.access(filepath);
|
|
16
|
+
} catch {
|
|
17
|
+
return true;
|
|
18
|
+
}
|
|
19
|
+
const keyring = new keytar_default(options);
|
|
20
|
+
if (!await keyring.available()) return false;
|
|
21
|
+
const fileStore = new file_default({ filepath });
|
|
22
|
+
if (!await fileStore.available()) return false;
|
|
23
|
+
const backupPath = `${filepath}.backup`;
|
|
24
|
+
try {
|
|
25
|
+
await fs.copyFile(filepath, backupPath);
|
|
26
|
+
const hosts = await fileStore.listHosts();
|
|
27
|
+
for (const host of hosts) if (host[outputConfig.url] && host[outputConfig.key]) await keyring.setKey(host[outputConfig.url], host[outputConfig.key]);
|
|
28
|
+
const defaultKey = await fileStore.getDefault();
|
|
29
|
+
if (defaultKey) await keyring.setDefault(defaultKey[outputConfig.url]);
|
|
30
|
+
await fs.rm(filepath);
|
|
31
|
+
await fs.rm(backupPath);
|
|
32
|
+
return true;
|
|
33
|
+
} catch (error) {
|
|
34
|
+
try {
|
|
35
|
+
await fs.copyFile(backupPath, filepath);
|
|
36
|
+
await fs.rm(backupPath);
|
|
37
|
+
} catch {}
|
|
38
|
+
logger.error(`Migration failed: ${error instanceof Error ? error.message : String(error)}`);
|
|
39
|
+
return false;
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
//#endregion
|
|
44
|
+
export { migrateFileToKeyring };
|
|
45
|
+
//# sourceMappingURL=migrate.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"migrate.mjs","names":["KeyringStore","FileStore"],"sources":["../../../../src/utils/aigne-hub/store/migrate.ts"],"sourcesContent":["import fs from \"node:fs/promises\";\nimport { logger } from \"@aigne/core/utils/logger\";\nimport type { StoreOptions } from \"@aigne/secrets\";\nimport FileStore from \"./file.js\";\nimport KeyringStore from \"./keytar.js\";\n\nexport async function migrateFileToKeyring(options: StoreOptions): Promise<boolean> {\n const { filepath } = options;\n const outputConfig = {\n url: \"AIGNE_HUB_API_URL\",\n key: \"AIGNE_HUB_API_KEY\",\n };\n\n if (!filepath) {\n throw new Error(\"Filepath is required for migration\");\n }\n\n try {\n await fs.access(filepath);\n } catch {\n return true;\n }\n\n const keyring = new KeyringStore(options);\n if (!(await keyring.available())) {\n return false;\n }\n\n const fileStore = new FileStore({ filepath });\n if (!(await fileStore.available())) {\n return false;\n }\n\n const backupPath = `${filepath}.backup`;\n\n try {\n // Create backup before migration\n await fs.copyFile(filepath, backupPath);\n\n const hosts = await fileStore.listHosts();\n for (const host of hosts) {\n if (host[outputConfig.url] && host[outputConfig.key]) {\n await keyring.setKey(host[outputConfig.url], host[outputConfig.key]);\n }\n }\n\n const defaultKey = await fileStore.getDefault();\n if (defaultKey) {\n await keyring.setDefault(defaultKey[outputConfig.url]);\n }\n\n await fs.rm(filepath);\n await fs.rm(backupPath);\n\n return true;\n } catch (error) {\n try {\n await fs.copyFile(backupPath, filepath);\n await fs.rm(backupPath);\n } catch {\n // If restore fails, at least backup exists\n }\n\n logger.error(`Migration failed: ${error instanceof Error ? error.message : String(error)}`);\n return false;\n }\n}\n"],"mappings":";;;;;;AAMA,eAAsB,qBAAqB,SAAyC;CAClF,MAAM,EAAE,aAAa;CACrB,MAAM,eAAe;EACnB,KAAK;EACL,KAAK;EACN;AAED,KAAI,CAAC,SACH,OAAM,IAAI,MAAM,qCAAqC;AAGvD,KAAI;AACF,QAAM,GAAG,OAAO,SAAS;SACnB;AACN,SAAO;;CAGT,MAAM,UAAU,IAAIA,eAAa,QAAQ;AACzC,KAAI,CAAE,MAAM,QAAQ,WAAW,CAC7B,QAAO;CAGT,MAAM,YAAY,IAAIC,aAAU,EAAE,UAAU,CAAC;AAC7C,KAAI,CAAE,MAAM,UAAU,WAAW,CAC/B,QAAO;CAGT,MAAM,aAAa,GAAG,SAAS;AAE/B,KAAI;AAEF,QAAM,GAAG,SAAS,UAAU,WAAW;EAEvC,MAAM,QAAQ,MAAM,UAAU,WAAW;AACzC,OAAK,MAAM,QAAQ,MACjB,KAAI,KAAK,aAAa,QAAQ,KAAK,aAAa,KAC9C,OAAM,QAAQ,OAAO,KAAK,aAAa,MAAM,KAAK,aAAa,KAAK;EAIxE,MAAM,aAAa,MAAM,UAAU,YAAY;AAC/C,MAAI,WACF,OAAM,QAAQ,WAAW,WAAW,aAAa,KAAK;AAGxD,QAAM,GAAG,GAAG,SAAS;AACrB,QAAM,GAAG,GAAG,WAAW;AAEvB,SAAO;UACA,OAAO;AACd,MAAI;AACF,SAAM,GAAG,SAAS,YAAY,SAAS;AACvC,SAAM,GAAG,GAAG,WAAW;UACjB;AAIR,SAAO,MAAM,qBAAqB,iBAAiB,QAAQ,MAAM,UAAU,OAAO,MAAM,GAAG;AAC3F,SAAO"}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
//#region src/utils/aigne-hub/type.d.ts
|
|
2
|
+
type InquirerPromptFn = (prompt: {
|
|
3
|
+
type: string;
|
|
4
|
+
name: string;
|
|
5
|
+
message: string;
|
|
6
|
+
choices: {
|
|
7
|
+
name: string;
|
|
8
|
+
value: any;
|
|
9
|
+
}[];
|
|
10
|
+
default: any;
|
|
11
|
+
}) => Promise<any>;
|
|
12
|
+
type LoadCredentialOptions = {
|
|
13
|
+
aigneHubUrl?: string;
|
|
14
|
+
inquirerPromptFn?: InquirerPromptFn;
|
|
15
|
+
};
|
|
16
|
+
//#endregion
|
|
17
|
+
export { LoadCredentialOptions };
|
|
18
|
+
//# sourceMappingURL=type.d.cts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"type.d.cts","names":[],"sources":["../../../src/utils/aigne-hub/type.ts"],"mappings":";KAAK,gBAAA,IAAA,MAAA;EAAA,IAAA;EAAA,IAAA;EAAA,OAAA;EAAA,OAAA;IAAA,IAAA;IAAA,KAAA;EAAA;EAAA,OAAA;AAAA,MAMC,OAAA;AAAA,KAEM,qBAAA;EAAA,WAAA;EAAA,gBAAA,GAES,gBAAA;AAAA"}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
//#region src/utils/aigne-hub/type.d.ts
|
|
2
|
+
type InquirerPromptFn = (prompt: {
|
|
3
|
+
type: string;
|
|
4
|
+
name: string;
|
|
5
|
+
message: string;
|
|
6
|
+
choices: {
|
|
7
|
+
name: string;
|
|
8
|
+
value: any;
|
|
9
|
+
}[];
|
|
10
|
+
default: any;
|
|
11
|
+
}) => Promise<any>;
|
|
12
|
+
type LoadCredentialOptions = {
|
|
13
|
+
aigneHubUrl?: string;
|
|
14
|
+
inquirerPromptFn?: InquirerPromptFn;
|
|
15
|
+
};
|
|
16
|
+
//#endregion
|
|
17
|
+
export { LoadCredentialOptions };
|
|
18
|
+
//# sourceMappingURL=type.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"type.d.mts","names":[],"sources":["../../../src/utils/aigne-hub/type.ts"],"mappings":";KAAK,gBAAA,IAAA,MAAA;EAAA,IAAA;EAAA,IAAA;EAAA,OAAA;EAAA,OAAA;IAAA,IAAA;IAAA,KAAA;EAAA;EAAA,OAAA;AAAA,MAMC,OAAA;AAAA,KAEM,qBAAA;EAAA,WAAA;EAAA,gBAAA,GAES,gBAAA;AAAA"}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
const require_rolldown_runtime = require('../_virtual/rolldown_runtime.cjs');
|
|
2
|
+
let _aigne_core_utils_fetch = require("@aigne/core/utils/fetch");
|
|
3
|
+
let ufo = require("ufo");
|
|
4
|
+
|
|
5
|
+
//#region src/utils/aigne-hub-user.ts
|
|
6
|
+
async function getUserInfo({ baseUrl, apiKey }) {
|
|
7
|
+
return await (await (0, _aigne_core_utils_fetch.fetch)((0, ufo.joinURL)(baseUrl.replace(/^http:/, "https:"), "/api/user/info"), { headers: { Authorization: `Bearer ${apiKey}` } })).json();
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
//#endregion
|
|
11
|
+
exports.getUserInfo = getUserInfo;
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
//#region src/utils/aigne-hub-user.d.ts
|
|
2
|
+
interface UserInfoResult {
|
|
3
|
+
user: Record<string, any>;
|
|
4
|
+
enableCredit: boolean;
|
|
5
|
+
creditBalance: {
|
|
6
|
+
balance: string;
|
|
7
|
+
total: string;
|
|
8
|
+
grantCount: number;
|
|
9
|
+
pendingCredit: string;
|
|
10
|
+
} | null;
|
|
11
|
+
paymentLink: string | null;
|
|
12
|
+
profileLink: string;
|
|
13
|
+
}
|
|
14
|
+
declare function getUserInfo({
|
|
15
|
+
baseUrl,
|
|
16
|
+
apiKey
|
|
17
|
+
}: {
|
|
18
|
+
baseUrl: string;
|
|
19
|
+
apiKey: string;
|
|
20
|
+
}): Promise<UserInfoResult>;
|
|
21
|
+
//#endregion
|
|
22
|
+
export { UserInfoResult, getUserInfo };
|
|
23
|
+
//# sourceMappingURL=aigne-hub-user.d.cts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"aigne-hub-user.d.cts","names":[],"sources":["../../src/utils/aigne-hub-user.ts"],"mappings":";UAGiB,cAAA;EAAA,IAAA,EACT,MAAA;EAAA,YAAA;EAAA,aAAA;IAAA,OAAA;IAAA,KAAA;IAAA,UAAA;IAAA,aAAA;EAAA;EAAA,WAAA;EAAA,WAAA;AAAA;AAAA,iBAYc,WAAA,CAAA;EAAA,OAAA;EAAA;AAAA;EAAA,OAAA;EAAA,MAAA;AAAA,IAMlB,OAAA,CAAQ,cAAA"}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
//#region src/utils/aigne-hub-user.d.ts
|
|
2
|
+
interface UserInfoResult {
|
|
3
|
+
user: Record<string, any>;
|
|
4
|
+
enableCredit: boolean;
|
|
5
|
+
creditBalance: {
|
|
6
|
+
balance: string;
|
|
7
|
+
total: string;
|
|
8
|
+
grantCount: number;
|
|
9
|
+
pendingCredit: string;
|
|
10
|
+
} | null;
|
|
11
|
+
paymentLink: string | null;
|
|
12
|
+
profileLink: string;
|
|
13
|
+
}
|
|
14
|
+
declare function getUserInfo({
|
|
15
|
+
baseUrl,
|
|
16
|
+
apiKey
|
|
17
|
+
}: {
|
|
18
|
+
baseUrl: string;
|
|
19
|
+
apiKey: string;
|
|
20
|
+
}): Promise<UserInfoResult>;
|
|
21
|
+
//#endregion
|
|
22
|
+
export { UserInfoResult, getUserInfo };
|
|
23
|
+
//# sourceMappingURL=aigne-hub-user.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"aigne-hub-user.d.mts","names":[],"sources":["../../src/utils/aigne-hub-user.ts"],"mappings":";UAGiB,cAAA;EAAA,IAAA,EACT,MAAA;EAAA,YAAA;EAAA,aAAA;IAAA,OAAA;IAAA,KAAA;IAAA,UAAA;IAAA,aAAA;EAAA;EAAA,WAAA;EAAA,WAAA;AAAA;AAAA,iBAYc,WAAA,CAAA;EAAA,OAAA;EAAA;AAAA;EAAA,OAAA;EAAA,MAAA;AAAA,IAMlB,OAAA,CAAQ,cAAA"}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { fetch } from "@aigne/core/utils/fetch";
|
|
2
|
+
import { joinURL } from "ufo";
|
|
3
|
+
|
|
4
|
+
//#region src/utils/aigne-hub-user.ts
|
|
5
|
+
async function getUserInfo({ baseUrl, apiKey }) {
|
|
6
|
+
return await (await fetch(joinURL(baseUrl.replace(/^http:/, "https:"), "/api/user/info"), { headers: { Authorization: `Bearer ${apiKey}` } })).json();
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
//#endregion
|
|
10
|
+
export { getUserInfo };
|
|
11
|
+
//# sourceMappingURL=aigne-hub-user.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"aigne-hub-user.mjs","names":[],"sources":["../../src/utils/aigne-hub-user.ts"],"sourcesContent":["import { fetch } from \"@aigne/core/utils/fetch\";\nimport { joinURL } from \"ufo\";\n\nexport interface UserInfoResult {\n user: Record<string, any>;\n enableCredit: boolean;\n creditBalance: {\n balance: string;\n total: string;\n grantCount: number;\n pendingCredit: string;\n } | null;\n paymentLink: string | null;\n profileLink: string;\n}\n\nexport async function getUserInfo({\n baseUrl,\n apiKey,\n}: {\n baseUrl: string;\n apiKey: string;\n}): Promise<UserInfoResult> {\n const secureBaseUrl = baseUrl.replace(/^http:/, \"https:\");\n const response = await fetch(joinURL(secureBaseUrl, \"/api/user/info\"), {\n headers: { Authorization: `Bearer ${apiKey}` },\n });\n\n const data = await response.json();\n\n return data;\n}\n"],"mappings":";;;;AAgBA,eAAsB,YAAY,EAChC,SACA,UAI0B;AAQ1B,QAFa,OAJI,MAAM,MAAM,QADP,QAAQ,QAAQ,UAAU,SAAS,EACL,iBAAiB,EAAE,EACrE,SAAS,EAAE,eAAe,UAAU,UAAU,EAC/C,CAAC,EAE0B,MAAM"}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
const require_rolldown_runtime = require('../_virtual/rolldown_runtime.cjs');
|
|
2
|
+
const require_constants = require('../constants.cjs');
|
|
3
|
+
let chalk = require("chalk");
|
|
4
|
+
chalk = require_rolldown_runtime.__toESM(chalk);
|
|
5
|
+
let gradient_string = require("gradient-string");
|
|
6
|
+
gradient_string = require_rolldown_runtime.__toESM(gradient_string);
|
|
7
|
+
|
|
8
|
+
//#region src/utils/ascii-logo.ts
|
|
9
|
+
const modernGradient = (0, gradient_string.default)([
|
|
10
|
+
"#4facfe",
|
|
11
|
+
"#7367f0",
|
|
12
|
+
"#f86aad"
|
|
13
|
+
]);
|
|
14
|
+
const logo = `
|
|
15
|
+
_ ___ ____ _ _ _____
|
|
16
|
+
/ \\ |_ _/ ___| \\ | | ____|
|
|
17
|
+
/ _ \\ | | | _| \\| | _|
|
|
18
|
+
/ ___ \\ | | |_| | |\\ | |___
|
|
19
|
+
/_/ \\_\\___\\____|_| \\_|_____|
|
|
20
|
+
`;
|
|
21
|
+
const frameworkInfo = `v${require_constants.AIGNE_CLI_VERSION}`;
|
|
22
|
+
const logoLines = logo.split("\n");
|
|
23
|
+
const maxLength = Math.max(...logoLines.filter((line) => line.trim()).map((line) => line.length));
|
|
24
|
+
const versionText = frameworkInfo;
|
|
25
|
+
const padding = Math.floor((maxLength - versionText.length) / 2);
|
|
26
|
+
const centeredVersion = " ".repeat(padding) + versionText;
|
|
27
|
+
const asciiLogo = `${modernGradient(logo)}\n${chalk.default.cyan(centeredVersion)}\n\n`;
|
|
28
|
+
|
|
29
|
+
//#endregion
|
|
30
|
+
exports.asciiLogo = asciiLogo;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ascii-logo.d.cts","names":[],"sources":["../../src/utils/ascii-logo.ts"],"mappings":";cAsBa,SAAA"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ascii-logo.d.mts","names":[],"sources":["../../src/utils/ascii-logo.ts"],"mappings":";cAsBa,SAAA"}
|
|
@@ -1,7 +1,13 @@
|
|
|
1
|
+
import { AIGNE_CLI_VERSION } from "../constants.mjs";
|
|
1
2
|
import chalk from "chalk";
|
|
2
3
|
import gradient from "gradient-string";
|
|
3
|
-
|
|
4
|
-
|
|
4
|
+
|
|
5
|
+
//#region src/utils/ascii-logo.ts
|
|
6
|
+
const modernGradient = gradient([
|
|
7
|
+
"#4facfe",
|
|
8
|
+
"#7367f0",
|
|
9
|
+
"#f86aad"
|
|
10
|
+
]);
|
|
5
11
|
const logo = `
|
|
6
12
|
_ ___ ____ _ _ _____
|
|
7
13
|
/ \\ |_ _/ ___| \\ | | ____|
|
|
@@ -15,4 +21,8 @@ const maxLength = Math.max(...logoLines.filter((line) => line.trim()).map((line)
|
|
|
15
21
|
const versionText = frameworkInfo;
|
|
16
22
|
const padding = Math.floor((maxLength - versionText.length) / 2);
|
|
17
23
|
const centeredVersion = " ".repeat(padding) + versionText;
|
|
18
|
-
|
|
24
|
+
const asciiLogo = `${modernGradient(logo)}\n${chalk.cyan(centeredVersion)}\n\n`;
|
|
25
|
+
|
|
26
|
+
//#endregion
|
|
27
|
+
export { asciiLogo };
|
|
28
|
+
//# sourceMappingURL=ascii-logo.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ascii-logo.mjs","names":[],"sources":["../../src/utils/ascii-logo.ts"],"sourcesContent":["import chalk from \"chalk\";\nimport gradient from \"gradient-string\";\nimport { AIGNE_CLI_VERSION } from \"../constants.js\";\n\nconst modernGradient = gradient([\"#4facfe\", \"#7367f0\", \"#f86aad\"]);\n\nconst logo = `\n _ ___ ____ _ _ _____\n / \\\\ |_ _/ ___| \\\\ | | ____|\n / _ \\\\ | | | _| \\\\| | _|\n / ___ \\\\ | | |_| | |\\\\ | |___\n /_/ \\\\_\\\\___\\\\____|_| \\\\_|_____|\n`;\n\nconst frameworkInfo = `v${AIGNE_CLI_VERSION}`;\n\nconst logoLines = logo.split(\"\\n\");\nconst maxLength = Math.max(...logoLines.filter((line) => line.trim()).map((line) => line.length));\nconst versionText = frameworkInfo;\nconst padding = Math.floor((maxLength - versionText.length) / 2);\nconst centeredVersion = \" \".repeat(padding) + versionText;\n\nexport const asciiLogo = `${modernGradient(logo)}\\n${chalk.cyan(centeredVersion)}\\n\\n`;\n"],"mappings":";;;;;AAIA,MAAM,iBAAiB,SAAS;CAAC;CAAW;CAAW;CAAU,CAAC;AAElE,MAAM,OAAO;;;;;;;AAQb,MAAM,gBAAgB,IAAI;AAE1B,MAAM,YAAY,KAAK,MAAM,KAAK;AAClC,MAAM,YAAY,KAAK,IAAI,GAAG,UAAU,QAAQ,SAAS,KAAK,MAAM,CAAC,CAAC,KAAK,SAAS,KAAK,OAAO,CAAC;AACjG,MAAM,cAAc;AACpB,MAAM,UAAU,KAAK,OAAO,YAAY,YAAY,UAAU,EAAE;AAChE,MAAM,kBAAkB,IAAI,OAAO,QAAQ,GAAG;AAE9C,MAAa,YAAY,GAAG,eAAe,KAAK,CAAC,IAAI,MAAM,KAAK,gBAAgB,CAAC"}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
const require_rolldown_runtime = require('../_virtual/rolldown_runtime.cjs');
|
|
2
|
+
let node_fs_promises = require("node:fs/promises");
|
|
3
|
+
let _aigne_core_utils_fetch = require("@aigne/core/utils/fetch");
|
|
4
|
+
let node_stream = require("node:stream");
|
|
5
|
+
let node_stream_promises = require("node:stream/promises");
|
|
6
|
+
let tar = require("tar");
|
|
7
|
+
|
|
8
|
+
//#region src/utils/download.ts
|
|
9
|
+
async function downloadAndExtract(url, dir, options = {}) {
|
|
10
|
+
const response = await (0, _aigne_core_utils_fetch.fetch)(url);
|
|
11
|
+
if (!response.body) throw new Error(`Failed to download package from ${url}: Unexpected to get empty response`);
|
|
12
|
+
try {
|
|
13
|
+
await (0, node_fs_promises.mkdir)(dir, { recursive: true });
|
|
14
|
+
await (0, node_stream_promises.finished)(node_stream.Readable.fromWeb(response.body).pipe((0, tar.x)({
|
|
15
|
+
C: dir,
|
|
16
|
+
...options
|
|
17
|
+
})));
|
|
18
|
+
} catch (error) {
|
|
19
|
+
error.message = `Failed to extract package from ${url}: ${error.message}`;
|
|
20
|
+
throw error;
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
//#endregion
|
|
25
|
+
exports.downloadAndExtract = downloadAndExtract;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"download.d.cts","names":[],"sources":["../../src/utils/download.ts"],"mappings":";iBAOsB,kBAAA,CAAA,GAAA,UAAA,GAAA,UAAA,OAAA;EAAA,KAAA;AAAA,IAGY,OAAA"}
|