@aigne/cli 1.59.0-beta.3 → 1.59.0-beta.31
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/CHANGELOG.md +694 -0
- package/dist/commands/aigne.js +2 -0
- package/dist/commands/app/agent.d.ts +2 -2
- package/dist/commands/app/agent.js +10 -4
- package/dist/commands/app/app.js +1 -1
- package/dist/commands/run-skill.d.ts +6 -0
- package/dist/commands/run-skill.js +102 -0
- package/dist/commands/run.d.ts +1 -1
- package/dist/commands/run.js +15 -13
- package/dist/constants.d.ts +2 -0
- package/dist/constants.js +2 -0
- package/dist/tracer/terminal.js +18 -0
- package/dist/ui/utils/terminal-input.d.ts +1 -0
- package/dist/ui/utils/terminal-input.js +4 -0
- package/dist/utils/aigne-hub/credential.d.ts +0 -3
- package/dist/utils/aigne-hub/credential.js +17 -24
- package/dist/utils/aigne-hub/crypto.js +22 -1
- package/dist/utils/aigne-hub/store/index.d.ts +1 -0
- package/dist/utils/aigne-hub/store/index.js +5 -2
- package/dist/utils/inquirer/checkbox.js +0 -1
- package/dist/utils/listr.d.ts +3 -1
- package/dist/utils/listr.js +59 -8
- package/dist/utils/load-aigne.d.ts +2 -1
- package/dist/utils/load-aigne.js +6 -11
- package/dist/utils/run-chat-loop.d.ts +2 -0
- package/dist/utils/run-chat-loop.js +2 -3
- package/dist/utils/run-with-aigne.d.ts +3 -1
- package/dist/utils/run-with-aigne.js +33 -4
- package/dist/utils/yargs.d.ts +6 -2
- package/dist/utils/yargs.js +7 -2
- package/package.json +19 -16
- package/templates/default/README.md +1 -1
package/dist/commands/aigne.js
CHANGED
|
@@ -8,6 +8,7 @@ import { createEvalCommand } from "./eval.js";
|
|
|
8
8
|
import { createHubCommand } from "./hub.js";
|
|
9
9
|
import { createObservabilityCommand } from "./observe.js";
|
|
10
10
|
import { createRunCommand } from "./run.js";
|
|
11
|
+
import { createRunSkillCommand } from "./run-skill.js";
|
|
11
12
|
import { createServeMCPCommand } from "./serve-mcp.js";
|
|
12
13
|
import { createTestCommand } from "./test.js";
|
|
13
14
|
export function createAIGNECommand(options) {
|
|
@@ -17,6 +18,7 @@ export function createAIGNECommand(options) {
|
|
|
17
18
|
.version(AIGNE_CLI_VERSION)
|
|
18
19
|
// default command: when user runs `aigne` without subcommand, behave like `aigne run`
|
|
19
20
|
.command(createRunCommand(options))
|
|
21
|
+
.command(createRunSkillCommand())
|
|
20
22
|
.command(createEvalCommand(options))
|
|
21
23
|
.command(createTestCommand(options))
|
|
22
24
|
.command(createCreateCommand())
|
|
@@ -10,10 +10,10 @@ export declare const serveMcpCommandModule: ({ aigne, name, }: {
|
|
|
10
10
|
port?: number;
|
|
11
11
|
pathname: string;
|
|
12
12
|
}>;
|
|
13
|
-
export declare const agentCommandModule: ({ aigne, agent,
|
|
13
|
+
export declare const agentCommandModule: ({ aigne, agent, interactive, }: {
|
|
14
14
|
aigne: AIGNE;
|
|
15
15
|
agent: Agent;
|
|
16
|
-
|
|
16
|
+
interactive?: boolean;
|
|
17
17
|
}) => CommandModule<unknown, AgentRunCommonOptions>;
|
|
18
18
|
export declare const cliAgentCommandModule: ({ aigne, cliAgent, }: {
|
|
19
19
|
aigne: AIGNE;
|
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
import assert from "node:assert";
|
|
2
|
+
import { DEFAULT_USER_ID } from "@aigne/cli/constants.js";
|
|
2
3
|
import { logger } from "@aigne/core/utils/logger.js";
|
|
4
|
+
import { v7 } from "@aigne/uuid";
|
|
3
5
|
import { runAgentWithAIGNE } from "../../utils/run-with-aigne.js";
|
|
4
6
|
import { parseAgentInput, withAgentInputSchema, } from "../../utils/yargs.js";
|
|
5
7
|
import { serveMCPServerFromDir } from "../serve-mcp.js";
|
|
@@ -30,7 +32,7 @@ export const serveMcpCommandModule = ({ aigne, name, }) => ({
|
|
|
30
32
|
});
|
|
31
33
|
},
|
|
32
34
|
});
|
|
33
|
-
export const agentCommandModule = ({ aigne, agent,
|
|
35
|
+
export const agentCommandModule = ({ aigne, agent, interactive, }) => {
|
|
34
36
|
return {
|
|
35
37
|
command: agent.name,
|
|
36
38
|
aliases: agent.alias || [],
|
|
@@ -38,7 +40,9 @@ export const agentCommandModule = ({ aigne, agent, chat, }) => {
|
|
|
38
40
|
builder: async (yargs) => {
|
|
39
41
|
return withAgentInputSchema(yargs, {
|
|
40
42
|
inputSchema: agent.inputSchema,
|
|
41
|
-
optionalInputs:
|
|
43
|
+
optionalInputs: interactive && "inputKey" in agent && typeof agent.inputKey === "string"
|
|
44
|
+
? [agent.inputKey]
|
|
45
|
+
: [],
|
|
42
46
|
});
|
|
43
47
|
},
|
|
44
48
|
handler: async (options) => {
|
|
@@ -47,7 +51,7 @@ export const agentCommandModule = ({ aigne, agent, chat, }) => {
|
|
|
47
51
|
await invokeAgent({
|
|
48
52
|
aigne,
|
|
49
53
|
agent,
|
|
50
|
-
input: { ...options,
|
|
54
|
+
input: { ...options, interactive: interactive ?? options.interactive },
|
|
51
55
|
});
|
|
52
56
|
},
|
|
53
57
|
};
|
|
@@ -96,7 +100,9 @@ export async function invokeAgent(options) {
|
|
|
96
100
|
await runAgentWithAIGNE(aigne, agent, {
|
|
97
101
|
...options.input,
|
|
98
102
|
input,
|
|
99
|
-
|
|
103
|
+
interactive: options.input.interactive,
|
|
104
|
+
sessionId: options.input.sessionId || v7(),
|
|
105
|
+
userId: DEFAULT_USER_ID,
|
|
100
106
|
});
|
|
101
107
|
}
|
|
102
108
|
finally {
|
package/dist/commands/app/app.js
CHANGED
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
import { basename, resolve } from "node:path";
|
|
2
|
+
import { AFSHistory } from "@aigne/afs-history";
|
|
3
|
+
import { LocalFS } from "@aigne/afs-local-fs";
|
|
4
|
+
import AgentSkillManager from "@aigne/agent-library/agent-skill-manager";
|
|
5
|
+
import AskUserQuestion from "@aigne/agent-library/ask-user-question";
|
|
6
|
+
import BashAgent from "@aigne/agent-library/bash";
|
|
7
|
+
import { AIGNE, FunctionAgent } from "@aigne/core";
|
|
8
|
+
import { z } from "zod";
|
|
9
|
+
import { loadChatModel } from "../utils/aigne-hub/model.js";
|
|
10
|
+
import { withAgentInputSchema } from "../utils/yargs.js";
|
|
11
|
+
import { invokeAgent } from "./app/agent.js";
|
|
12
|
+
export function createRunSkillCommand() {
|
|
13
|
+
return {
|
|
14
|
+
command: ["run-skill"],
|
|
15
|
+
describe: "Run Agent Skill for the specified path",
|
|
16
|
+
builder: async (yargs) => {
|
|
17
|
+
return withAgentInputSchema(yargs
|
|
18
|
+
.option("skill", {
|
|
19
|
+
array: true,
|
|
20
|
+
type: "string",
|
|
21
|
+
describe: "Path to the Agent Skill directory",
|
|
22
|
+
})
|
|
23
|
+
.option("interactive", {
|
|
24
|
+
describe: "Run in interactive chat mode",
|
|
25
|
+
type: "boolean",
|
|
26
|
+
default: false,
|
|
27
|
+
alias: ["chat"],
|
|
28
|
+
})
|
|
29
|
+
.demandOption("skill"), {
|
|
30
|
+
inputSchema: z.object({
|
|
31
|
+
message: z.string(),
|
|
32
|
+
}),
|
|
33
|
+
optionalInputs: ["message"],
|
|
34
|
+
});
|
|
35
|
+
},
|
|
36
|
+
handler: async (options) => {
|
|
37
|
+
if (!Array.isArray(options.skill) || options.skill.length === 0) {
|
|
38
|
+
throw new Error("At least one skill path must be provided.");
|
|
39
|
+
}
|
|
40
|
+
const model = await loadChatModel({
|
|
41
|
+
model: options.model || "aignehub/anthropic/claude-sonnet-4-5",
|
|
42
|
+
});
|
|
43
|
+
const aigne = new AIGNE({ model });
|
|
44
|
+
const approvedCmds = new Set();
|
|
45
|
+
const agent = new AgentSkillManager({
|
|
46
|
+
inputKey: "message",
|
|
47
|
+
taskRenderMode: "collapse",
|
|
48
|
+
skills: [
|
|
49
|
+
new BashAgent({
|
|
50
|
+
sandbox: false,
|
|
51
|
+
permissions: {
|
|
52
|
+
defaultMode: "ask",
|
|
53
|
+
guard: FunctionAgent.from(async (input, options) => {
|
|
54
|
+
if (approvedCmds.has(input.script || "")) {
|
|
55
|
+
return {
|
|
56
|
+
approved: true,
|
|
57
|
+
};
|
|
58
|
+
}
|
|
59
|
+
const confirm = options.prompts?.confirm;
|
|
60
|
+
if (!confirm)
|
|
61
|
+
throw new Error("No confirm prompt available for permission guard.");
|
|
62
|
+
const approved = await confirm({ message: `Run command ${input.script}?` });
|
|
63
|
+
if (approved && input.script) {
|
|
64
|
+
approvedCmds.add(input.script);
|
|
65
|
+
}
|
|
66
|
+
return {
|
|
67
|
+
approved,
|
|
68
|
+
};
|
|
69
|
+
}),
|
|
70
|
+
},
|
|
71
|
+
}),
|
|
72
|
+
new AskUserQuestion(),
|
|
73
|
+
],
|
|
74
|
+
afs: {
|
|
75
|
+
modules: [
|
|
76
|
+
new AFSHistory({}),
|
|
77
|
+
new LocalFS({
|
|
78
|
+
name: "workspace",
|
|
79
|
+
localPath: process.cwd(),
|
|
80
|
+
description: `\
|
|
81
|
+
Current working directory. All temporary files should be written here using absolute AFS paths (e.g., /modules/workspace/temp.py).
|
|
82
|
+
Note: Bash is already running in this directory, so do NOT use 'cd /modules/workspace' in scripts. Use relative paths directly (e.g., python temp.py).`,
|
|
83
|
+
}),
|
|
84
|
+
...options.skill.map((path) => new LocalFS({
|
|
85
|
+
name: basename(resolve(path)),
|
|
86
|
+
localPath: path,
|
|
87
|
+
description: "Contains Agent Skills. Use 'Skill' tool to invoke skills from this module.",
|
|
88
|
+
agentSkills: true,
|
|
89
|
+
})),
|
|
90
|
+
],
|
|
91
|
+
},
|
|
92
|
+
});
|
|
93
|
+
await invokeAgent({
|
|
94
|
+
aigne,
|
|
95
|
+
agent,
|
|
96
|
+
input: {
|
|
97
|
+
...options,
|
|
98
|
+
},
|
|
99
|
+
});
|
|
100
|
+
},
|
|
101
|
+
};
|
|
102
|
+
}
|
package/dist/commands/run.d.ts
CHANGED
package/dist/commands/run.js
CHANGED
|
@@ -38,10 +38,11 @@ export function createRunCommand({ aigneFilePath, } = {}) {
|
|
|
38
38
|
alias: "v",
|
|
39
39
|
describe: "Show version number",
|
|
40
40
|
})
|
|
41
|
-
.option("
|
|
42
|
-
describe: "Run
|
|
41
|
+
.option("interactive", {
|
|
42
|
+
describe: "Run in interactive chat mode",
|
|
43
43
|
type: "boolean",
|
|
44
44
|
default: false,
|
|
45
|
+
alias: ["chat"],
|
|
45
46
|
})
|
|
46
47
|
.help(false)
|
|
47
48
|
.version(false)
|
|
@@ -60,15 +61,16 @@ export function createRunCommand({ aigneFilePath, } = {}) {
|
|
|
60
61
|
}
|
|
61
62
|
}
|
|
62
63
|
const path = aigneFilePath || options.path || ".";
|
|
63
|
-
if (!(
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
64
|
+
if (!isUrl(path) &&
|
|
65
|
+
!(await findAIGNEFile(path).catch((error) => {
|
|
66
|
+
if (options._[0] !== "run") {
|
|
67
|
+
yargsInstance?.showHelp();
|
|
68
|
+
}
|
|
69
|
+
else {
|
|
70
|
+
throw error;
|
|
71
|
+
}
|
|
72
|
+
return false;
|
|
73
|
+
}))) {
|
|
72
74
|
return;
|
|
73
75
|
}
|
|
74
76
|
// Parse model options for loading application
|
|
@@ -81,14 +83,14 @@ export function createRunCommand({ aigneFilePath, } = {}) {
|
|
|
81
83
|
const subYargs = yargs().scriptName("").usage("aigne run <path> <agent> [...options]");
|
|
82
84
|
if (aigne.cli.chat) {
|
|
83
85
|
subYargs.command({
|
|
84
|
-
...agentCommandModule({ aigne, agent: aigne.cli.chat,
|
|
86
|
+
...agentCommandModule({ aigne, agent: aigne.cli.chat, interactive: true }),
|
|
85
87
|
command: "$0",
|
|
86
88
|
});
|
|
87
89
|
}
|
|
88
90
|
// Allow user to run all of agents in the AIGNE instances
|
|
89
91
|
const allAgents = flat(aigne.agents, aigne.skills, aigne.cli.chat, aigne.mcpServer.agents);
|
|
90
92
|
for (const agent of allAgents) {
|
|
91
|
-
subYargs.command(agentCommandModule({ aigne, agent,
|
|
93
|
+
subYargs.command(agentCommandModule({ aigne, agent, interactive: options.interactive }));
|
|
92
94
|
}
|
|
93
95
|
for (const cliAgent of aigne.cli.agents ?? []) {
|
|
94
96
|
subYargs.command(cliAgentCommandModule({
|
package/dist/constants.d.ts
CHANGED
|
@@ -3,3 +3,5 @@ export declare const AIGNE_CLI_VERSION: any;
|
|
|
3
3
|
export declare const availableMemories: (typeof DefaultMemory)[];
|
|
4
4
|
export declare const AIGNE_HUB_CREDITS_NOT_ENOUGH_ERROR_TYPE = "NOT_ENOUGH";
|
|
5
5
|
export declare const CHAT_MODEL_OPTIONS: string[];
|
|
6
|
+
export declare const DEFAULT_USER_ID = "cli-user";
|
|
7
|
+
export declare const DEFAULT_AFS_EXPLORER_PORT = 9670;
|
package/dist/constants.js
CHANGED
package/dist/tracer/terminal.js
CHANGED
|
@@ -154,6 +154,7 @@ export class TerminalTracer {
|
|
|
154
154
|
}
|
|
155
155
|
task.resolve();
|
|
156
156
|
};
|
|
157
|
+
let retryPromptPromise;
|
|
157
158
|
const onError = async ({ context, agent, error, ...event }) => {
|
|
158
159
|
if ("type" in error && error.type === AIGNE_HUB_CREDITS_NOT_ENOUGH_ERROR_TYPE) {
|
|
159
160
|
if (!Object.hasOwn(error, CREDITS_ERROR_PROCESSED_FLAG)) {
|
|
@@ -168,6 +169,23 @@ export class TerminalTracer {
|
|
|
168
169
|
}
|
|
169
170
|
}
|
|
170
171
|
}
|
|
172
|
+
if (agent instanceof ChatModel) {
|
|
173
|
+
retryPromptPromise ??= this.proxiedPrompts
|
|
174
|
+
.select({
|
|
175
|
+
message: chalk.red(`Error: ${error.message}`),
|
|
176
|
+
choices: [
|
|
177
|
+
{ value: "retry", name: "Retry" },
|
|
178
|
+
{ value: "exit", name: "Exit" },
|
|
179
|
+
],
|
|
180
|
+
})
|
|
181
|
+
.then((result) => ({ retry: result === "retry" }))
|
|
182
|
+
.finally(() => {
|
|
183
|
+
retryPromptPromise = undefined;
|
|
184
|
+
});
|
|
185
|
+
const { retry } = await retryPromptPromise;
|
|
186
|
+
if (retry)
|
|
187
|
+
return { retry: true };
|
|
188
|
+
}
|
|
171
189
|
const contextId = context.id;
|
|
172
190
|
const task = this.tasks[contextId];
|
|
173
191
|
if (!task)
|
|
@@ -6,6 +6,7 @@ export declare function terminalInput({ render: r, ...options }?: {
|
|
|
6
6
|
required?: boolean;
|
|
7
7
|
validate?: (input: string) => string | boolean | Promise<string | boolean>;
|
|
8
8
|
render?: typeof render;
|
|
9
|
+
clear?: boolean;
|
|
9
10
|
}): Promise<string>;
|
|
10
11
|
export declare function TerminalInput(props: {
|
|
11
12
|
message?: string;
|
|
@@ -12,10 +12,14 @@ export async function terminalInput({ render: r = render, ...options } = {}) {
|
|
|
12
12
|
process.addListener("SIGINT", handleSigInt);
|
|
13
13
|
const clean = () => process.removeListener("SIGINT", handleSigInt);
|
|
14
14
|
const app = r(_jsx(TerminalInput, { ...options, onSubmit: (value) => {
|
|
15
|
+
if (options.clear)
|
|
16
|
+
app.clear();
|
|
15
17
|
app.unmount();
|
|
16
18
|
resolve(value);
|
|
17
19
|
clean();
|
|
18
20
|
}, onError: (error) => {
|
|
21
|
+
if (options.clear)
|
|
22
|
+
app.clear();
|
|
19
23
|
app.unmount();
|
|
20
24
|
reject(error);
|
|
21
25
|
clean();
|
|
@@ -9,9 +9,6 @@ export declare function createConnect({ connectUrl, openPage, fetchInterval, ret
|
|
|
9
9
|
export declare function connectToAIGNEHub(url: string): Promise<{
|
|
10
10
|
apiKey: string;
|
|
11
11
|
url: string;
|
|
12
|
-
} | {
|
|
13
|
-
apiKey: undefined;
|
|
14
|
-
url: undefined;
|
|
15
12
|
}>;
|
|
16
13
|
export declare const checkConnectionStatus: (host: string) => Promise<{
|
|
17
14
|
apiKey: any;
|
|
@@ -3,7 +3,6 @@ import { homedir } from "node:os";
|
|
|
3
3
|
import { join } from "node:path";
|
|
4
4
|
import { AIGNE_HUB_BLOCKLET_DID, AIGNE_HUB_URL, getAIGNEHubMountPoint } from "@aigne/aigne-hub";
|
|
5
5
|
import { fetch } from "@aigne/core/utils/fetch.js";
|
|
6
|
-
import { logger } from "@aigne/core/utils/logger.js";
|
|
7
6
|
import inquirer from "inquirer";
|
|
8
7
|
import open from "open";
|
|
9
8
|
import pWaitFor from "p-wait-for";
|
|
@@ -38,7 +37,7 @@ export const fetchConfigs = async ({ connectUrl, sessionId, fetchInterval, fetch
|
|
|
38
37
|
};
|
|
39
38
|
};
|
|
40
39
|
function baseWrapSpinner(_, waiting) {
|
|
41
|
-
return
|
|
40
|
+
return waiting();
|
|
42
41
|
}
|
|
43
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", }) {
|
|
44
43
|
const startSessionURL = joinURL(connectUrl, ACCESS_KEY_SESSION_API);
|
|
@@ -68,28 +67,22 @@ export async function connectToAIGNEHub(url) {
|
|
|
68
67
|
const { origin } = new URL(url);
|
|
69
68
|
const connectUrl = joinURL(origin, WELLKNOWN_SERVICE_PATH_PREFIX);
|
|
70
69
|
const apiUrl = await getAIGNEHubMountPoint(url, AIGNE_HUB_BLOCKLET_DID);
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
return accessKeyOptions;
|
|
88
|
-
}
|
|
89
|
-
catch (error) {
|
|
90
|
-
logger.error("Failed to connect to AIGNE Hub", error.message);
|
|
91
|
-
return { apiKey: undefined, url: undefined };
|
|
92
|
-
}
|
|
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;
|
|
93
86
|
}
|
|
94
87
|
export const checkConnectionStatus = async (host) => {
|
|
95
88
|
const secretStore = await getSecretStore();
|
|
@@ -1,5 +1,26 @@
|
|
|
1
1
|
import crypto from "node:crypto";
|
|
2
|
-
import
|
|
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
|
+
}
|
|
3
24
|
const aes = new AesCrypter();
|
|
4
25
|
export const decrypt = (m, s, i) => aes.decrypt(m, crypto.pbkdf2Sync(i, s, 256, 32, "sha512").toString("hex"));
|
|
5
26
|
export const encrypt = (m, s, i) => aes.encrypt(m, crypto.pbkdf2Sync(i, s, 256, 32, "sha512").toString("hex"));
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { logger } from "@aigne/core/utils/logger.js";
|
|
2
|
-
import { AIGNE_ENV_FILE } from "../constants.js";
|
|
2
|
+
import { AIGNE_ENV_FILE, isTest } from "../constants.js";
|
|
3
3
|
import FileStore from "./file.js";
|
|
4
4
|
import KeyringStore from "./keytar.js";
|
|
5
5
|
import { migrateFileToKeyring } from "./migrate.js";
|
|
@@ -32,9 +32,12 @@ const getSecretStore = async () => {
|
|
|
32
32
|
cachedSecretStore = await createSecretStore({
|
|
33
33
|
filepath: AIGNE_ENV_FILE,
|
|
34
34
|
serviceName: "aigne-hub",
|
|
35
|
-
|
|
35
|
+
forceKeytarUnavailable: Boolean(isTest),
|
|
36
36
|
});
|
|
37
37
|
}
|
|
38
38
|
return cachedSecretStore;
|
|
39
39
|
};
|
|
40
|
+
export const resetSecretStoreCache = () => {
|
|
41
|
+
cachedSecretStore = undefined;
|
|
42
|
+
};
|
|
40
43
|
export default getSecretStore;
|
|
@@ -153,7 +153,6 @@ export default createPrompt((config, done) => {
|
|
|
153
153
|
let next = active;
|
|
154
154
|
do {
|
|
155
155
|
next = (next + offset + items.length) % items.length;
|
|
156
|
-
// biome-ignore lint/style/noNonNullAssertion: we need to access items dynamically
|
|
157
156
|
} while (!isSelectable(items[next]));
|
|
158
157
|
setActive(next);
|
|
159
158
|
}
|
package/dist/utils/listr.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type
|
|
1
|
+
import { type AgentResponseStream, type Message } from "@aigne/core";
|
|
2
2
|
import type { PromiseOrValue } from "@aigne/core/utils/type-utils.js";
|
|
3
3
|
import { DefaultRenderer, Listr, type ListrDefaultRendererOptions, ListrLogger, type ListrSimpleRendererOptions, type ListrTaskWrapper, SimpleRenderer, Spinner } from "@aigne/listr2";
|
|
4
4
|
import type { createLogUpdate } from "log-update";
|
|
@@ -22,7 +22,9 @@ export declare class AIGNEListr extends Listr<object, typeof AIGNEListrRenderer,
|
|
|
22
22
|
renderImage?: boolean;
|
|
23
23
|
}) => string | Promise<string>;
|
|
24
24
|
}, ...[task, options, parentTask]: ConstructorParameters<typeof Listr<object, typeof AIGNEListrRenderer, typeof AIGNEListrFallbackRenderer>>);
|
|
25
|
+
private needLogResult;
|
|
25
26
|
run(stream: () => PromiseOrValue<AgentResponseStream<Message>>): Promise<Message>;
|
|
27
|
+
private marked;
|
|
26
28
|
private extractStream;
|
|
27
29
|
}
|
|
28
30
|
export interface AIGNEListrRendererOptions extends ListrDefaultRendererOptions {
|
package/dist/utils/listr.js
CHANGED
|
@@ -1,8 +1,12 @@
|
|
|
1
1
|
import { EOL } from "node:os";
|
|
2
2
|
import { format } from "node:util";
|
|
3
|
+
import { isAgentResponseProgress } from "@aigne/core";
|
|
3
4
|
import { LogLevel, logger } from "@aigne/core/utils/logger.js";
|
|
4
5
|
import { mergeAgentResponseChunk } from "@aigne/core/utils/stream-utils.js";
|
|
5
6
|
import { color, DefaultRenderer, figures, Listr, ListrDefaultRendererLogLevels, ListrLogger, SimpleRenderer, Spinner, } from "@aigne/listr2";
|
|
7
|
+
import { markedTerminal } from "@aigne/marked-terminal";
|
|
8
|
+
import chalk from "chalk";
|
|
9
|
+
import { Marked } from "marked";
|
|
6
10
|
import wrap from "wrap-ansi";
|
|
7
11
|
export class AIGNEListr extends Listr {
|
|
8
12
|
myOptions;
|
|
@@ -15,13 +19,12 @@ export class AIGNEListr extends Listr {
|
|
|
15
19
|
getStdoutLogs: () => {
|
|
16
20
|
return this.logs.splice(0);
|
|
17
21
|
},
|
|
18
|
-
getBottomBarLogs: (
|
|
19
|
-
if (!options?.running)
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
return [r];
|
|
22
|
+
getBottomBarLogs: (_options) => {
|
|
23
|
+
// if (!options?.running) return [];
|
|
24
|
+
// const r = this.myOptions.formatResult(this.result);
|
|
25
|
+
// if (typeof r !== "string") throw new Error("Must return a string result for running task");
|
|
26
|
+
// return [r];
|
|
27
|
+
return [];
|
|
25
28
|
},
|
|
26
29
|
};
|
|
27
30
|
super(task, {
|
|
@@ -55,6 +58,7 @@ export class AIGNEListr extends Listr {
|
|
|
55
58
|
this.myOptions = myOptions;
|
|
56
59
|
this.spinner = new Spinner();
|
|
57
60
|
}
|
|
61
|
+
needLogResult = true;
|
|
58
62
|
async run(stream) {
|
|
59
63
|
const originalLog = logger.logMessage;
|
|
60
64
|
const originalConsole = { ...console };
|
|
@@ -81,7 +85,9 @@ export class AIGNEListr extends Listr {
|
|
|
81
85
|
throw this.error;
|
|
82
86
|
return { ...this.result };
|
|
83
87
|
});
|
|
84
|
-
|
|
88
|
+
if (this.needLogResult) {
|
|
89
|
+
console.log(await this.myOptions.formatResult(this.result, { running: false, renderImage: true }));
|
|
90
|
+
}
|
|
85
91
|
return result;
|
|
86
92
|
}
|
|
87
93
|
finally {
|
|
@@ -90,11 +96,56 @@ export class AIGNEListr extends Listr {
|
|
|
90
96
|
this.spinner.stop();
|
|
91
97
|
}
|
|
92
98
|
}
|
|
99
|
+
marked = new Marked().use({
|
|
100
|
+
// marked-terminal does not support code block meta, so we need to strip it
|
|
101
|
+
walkTokens: (token) => {
|
|
102
|
+
if (token.type === "code") {
|
|
103
|
+
if (typeof token.lang === "string") {
|
|
104
|
+
token.lang = token.lang.trim().split(/\s+/)[0];
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
},
|
|
108
|
+
}, markedTerminal({ forceHyperLink: false }, {
|
|
109
|
+
theme: {
|
|
110
|
+
string: chalk.green,
|
|
111
|
+
},
|
|
112
|
+
}));
|
|
93
113
|
async extractStream(stream) {
|
|
94
114
|
try {
|
|
95
115
|
this.result = {};
|
|
96
116
|
for await (const value of stream) {
|
|
97
117
|
mergeAgentResponseChunk(this.result, value);
|
|
118
|
+
if (isAgentResponseProgress(value) && value.progress.event === "message") {
|
|
119
|
+
const { message } = value.progress;
|
|
120
|
+
const rendered = [];
|
|
121
|
+
if (message.role === "user" || message.role === "agent") {
|
|
122
|
+
if (message.role === "agent" && message.toolCalls) {
|
|
123
|
+
for (const call of message.toolCalls) {
|
|
124
|
+
rendered.push(`${chalk.bold.gray(`[${call.function.name}]`)} ${chalk.gray(`${JSON.stringify(call.function.arguments).slice(0, 200)}...`)}`);
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
else if (typeof message.content === "string") {
|
|
128
|
+
rendered.push(this.marked.parse(message.content, { async: false }).trim());
|
|
129
|
+
}
|
|
130
|
+
else if (Array.isArray(message.content)) {
|
|
131
|
+
for (const msg of message.content) {
|
|
132
|
+
if (msg.type === "text") {
|
|
133
|
+
if (msg.isThinking) {
|
|
134
|
+
rendered.push(chalk.dim(chalk.grey(chalk.italic(`[Thinking] ${msg.text}`))));
|
|
135
|
+
}
|
|
136
|
+
else {
|
|
137
|
+
rendered.push(this.marked.parse(msg.text, { async: false }).trim());
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
if (rendered.length) {
|
|
144
|
+
const prefix = message.role === "user" ? chalk.blue.bold(">") : chalk.green.bold("•");
|
|
145
|
+
console.log(`${prefix} ${rendered.join("\n")}\n`);
|
|
146
|
+
this.needLogResult = false;
|
|
147
|
+
}
|
|
148
|
+
}
|
|
98
149
|
}
|
|
99
150
|
return this.result;
|
|
100
151
|
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { AIGNE, type ChatModelInputOptions, type ImageModelInputOptions } from "@aigne/core";
|
|
1
|
+
import { AIGNE, type ChatModel, type ChatModelInputOptions, type ImageModelInputOptions } from "@aigne/core";
|
|
2
2
|
import type { AIGNEMetadata } from "@aigne/core/aigne/type.js";
|
|
3
3
|
import type { LoadCredentialOptions } from "./aigne-hub/type.js";
|
|
4
4
|
import type { AgentRunCommonOptions } from "./yargs.js";
|
|
@@ -8,6 +8,7 @@ export interface RunOptions extends AgentRunCommonOptions {
|
|
|
8
8
|
cacheDir?: string;
|
|
9
9
|
aigneHubUrl?: string;
|
|
10
10
|
}
|
|
11
|
+
export declare function printChatModelInfoBox(model: ChatModel, otherLines?: string[]): Promise<void>;
|
|
11
12
|
export declare function loadAIGNE({ path, modelOptions, imageModelOptions, skipModelLoading, metadata, }: {
|
|
12
13
|
path?: string;
|
|
13
14
|
modelOptions?: ChatModelInputOptions & LoadCredentialOptions;
|