@aigne/cli 1.59.0-beta.9 → 1.59.1-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/CHANGELOG.md +615 -0
- package/dist/commands/aigne.js +2 -0
- package/dist/commands/app/agent.d.ts +2 -2
- package/dist/commands/app/agent.js +9 -5
- 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/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/load-aigne.d.ts +2 -1
- package/dist/utils/load-aigne.js +5 -10
- package/dist/utils/run-chat-loop.d.ts +1 -0
- package/dist/utils/run-chat-loop.js +1 -3
- package/dist/utils/run-with-aigne.d.ts +2 -1
- package/dist/utils/run-with-aigne.js +32 -4
- package/dist/utils/yargs.d.ts +6 -2
- package/dist/utils/yargs.js +7 -2
- package/package.json +18 -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,4 +1,5 @@
|
|
|
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";
|
|
3
4
|
import { v7 } from "@aigne/uuid";
|
|
4
5
|
import { runAgentWithAIGNE } from "../../utils/run-with-aigne.js";
|
|
@@ -31,7 +32,7 @@ export const serveMcpCommandModule = ({ aigne, name, }) => ({
|
|
|
31
32
|
});
|
|
32
33
|
},
|
|
33
34
|
});
|
|
34
|
-
export const agentCommandModule = ({ aigne, agent,
|
|
35
|
+
export const agentCommandModule = ({ aigne, agent, interactive, }) => {
|
|
35
36
|
return {
|
|
36
37
|
command: agent.name,
|
|
37
38
|
aliases: agent.alias || [],
|
|
@@ -39,7 +40,9 @@ export const agentCommandModule = ({ aigne, agent, chat, }) => {
|
|
|
39
40
|
builder: async (yargs) => {
|
|
40
41
|
return withAgentInputSchema(yargs, {
|
|
41
42
|
inputSchema: agent.inputSchema,
|
|
42
|
-
optionalInputs:
|
|
43
|
+
optionalInputs: interactive && "inputKey" in agent && typeof agent.inputKey === "string"
|
|
44
|
+
? [agent.inputKey]
|
|
45
|
+
: [],
|
|
43
46
|
});
|
|
44
47
|
},
|
|
45
48
|
handler: async (options) => {
|
|
@@ -48,7 +51,7 @@ export const agentCommandModule = ({ aigne, agent, chat, }) => {
|
|
|
48
51
|
await invokeAgent({
|
|
49
52
|
aigne,
|
|
50
53
|
agent,
|
|
51
|
-
input: { ...options,
|
|
54
|
+
input: { ...options, interactive: interactive ?? options.interactive },
|
|
52
55
|
});
|
|
53
56
|
},
|
|
54
57
|
};
|
|
@@ -97,8 +100,9 @@ export async function invokeAgent(options) {
|
|
|
97
100
|
await runAgentWithAIGNE(aigne, agent, {
|
|
98
101
|
...options.input,
|
|
99
102
|
input,
|
|
100
|
-
|
|
101
|
-
sessionId: v7(),
|
|
103
|
+
interactive: options.input.interactive,
|
|
104
|
+
sessionId: options.input.sessionId || v7(),
|
|
105
|
+
userId: DEFAULT_USER_ID,
|
|
102
106
|
});
|
|
103
107
|
}
|
|
104
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)
|
|
@@ -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
|
}
|
|
@@ -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;
|
package/dist/utils/load-aigne.js
CHANGED
|
@@ -6,8 +6,8 @@ import chalk from "chalk";
|
|
|
6
6
|
import { AIGNE_CLI_VERSION, availableMemories } from "../constants.js";
|
|
7
7
|
import { loadChatModel, loadImageModel, maskApiKey } from "./aigne-hub/model.js";
|
|
8
8
|
import { getUrlOrigin } from "./get-url-origin.js";
|
|
9
|
-
|
|
10
|
-
|
|
9
|
+
export async function printChatModelInfoBox(model, otherLines) {
|
|
10
|
+
console.log(`${chalk.grey("TIPS:")} run ${chalk.cyan("aigne observe")} to start the observability server.\n`);
|
|
11
11
|
const credential = await model.credential;
|
|
12
12
|
const lines = [`${chalk.cyan("Provider")}: ${chalk.green(model.name.replace("ChatModel", ""))}`];
|
|
13
13
|
if (credential?.model) {
|
|
@@ -19,6 +19,8 @@ async function printChatModelInfoBox(model) {
|
|
|
19
19
|
if (credential?.apiKey) {
|
|
20
20
|
lines.push(`${chalk.cyan("API Key")}: ${chalk.green(maskApiKey(credential?.apiKey))}`);
|
|
21
21
|
}
|
|
22
|
+
if (otherLines?.length)
|
|
23
|
+
lines.push(...otherLines);
|
|
22
24
|
console.log(boxen(lines.join("\n"), { padding: 1, borderStyle: "classic", borderColor: "cyan" }));
|
|
23
25
|
console.log("");
|
|
24
26
|
}
|
|
@@ -55,7 +57,7 @@ export async function loadAIGNE({ path, modelOptions, imageModelOptions, skipMod
|
|
|
55
57
|
availableModules: [
|
|
56
58
|
{
|
|
57
59
|
module: "history",
|
|
58
|
-
load: (options) => import("@aigne/afs-history").then((m) =>
|
|
60
|
+
load: (options) => import("@aigne/afs-history").then((m) => m.AFSHistory.load(options)),
|
|
59
61
|
},
|
|
60
62
|
{
|
|
61
63
|
module: "local-fs",
|
|
@@ -74,12 +76,5 @@ export async function loadAIGNE({ path, modelOptions, imageModelOptions, skipMod
|
|
|
74
76
|
metadata: { ...metadata, cliVersion: AIGNE_CLI_VERSION },
|
|
75
77
|
});
|
|
76
78
|
}
|
|
77
|
-
if (!skipModelLoading && !printed) {
|
|
78
|
-
printed = true;
|
|
79
|
-
console.log(`${chalk.grey("TIPS:")} run ${chalk.cyan("aigne observe")} to start the observability server.\n`);
|
|
80
|
-
if (aigne.model) {
|
|
81
|
-
await printChatModelInfoBox(aigne.model);
|
|
82
|
-
}
|
|
83
|
-
}
|
|
84
79
|
return aigne;
|
|
85
80
|
}
|
|
@@ -7,8 +7,6 @@ import { terminalInput } from "../ui/utils/terminal-input.js";
|
|
|
7
7
|
export const DEFAULT_CHAT_INPUT_KEY = "message";
|
|
8
8
|
export async function runChatLoopInTerminal(userAgent, options = {}) {
|
|
9
9
|
const { initialCall } = options;
|
|
10
|
-
if (options?.welcome)
|
|
11
|
-
console.log(options.welcome);
|
|
12
10
|
if (initialCall) {
|
|
13
11
|
await callAgent(userAgent, initialCall, options);
|
|
14
12
|
if (options.input && options.inputFileKey) {
|
|
@@ -75,7 +73,7 @@ async function callAgent(userAgent, input, options) {
|
|
|
75
73
|
const tracer = new TerminalTracer(userAgent.context, options);
|
|
76
74
|
await tracer.run(userAgent, typeof input === "string"
|
|
77
75
|
? { ...options.input, [options.inputKey || DEFAULT_CHAT_INPUT_KEY]: input }
|
|
78
|
-
: { ...options.input, ...input }, { userContext: { sessionId: options.sessionId } });
|
|
76
|
+
: { ...options.input, ...input }, { userContext: { sessionId: options.sessionId, userId: options.userId } });
|
|
79
77
|
}
|
|
80
78
|
const COMMANDS = {
|
|
81
79
|
"/exit": () => ({ exit: true }),
|
|
@@ -15,7 +15,8 @@ export declare function runWithAIGNE(agentCreator: ((aigne: AIGNE) => PromiseOrV
|
|
|
15
15
|
modelOptions?: ChatModelInputOptions;
|
|
16
16
|
outputKey?: string;
|
|
17
17
|
}): Promise<void>;
|
|
18
|
-
export declare function runAgentWithAIGNE(aigne: AIGNE, agent: Agent, { sessionId, outputKey, outputFileKey, chatLoopOptions, ...options }?: {
|
|
18
|
+
export declare function runAgentWithAIGNE(aigne: AIGNE, agent: Agent, { userId, sessionId, outputKey, outputFileKey, chatLoopOptions, ...options }?: {
|
|
19
|
+
userId?: string;
|
|
19
20
|
sessionId?: string;
|
|
20
21
|
outputKey?: string;
|
|
21
22
|
outputFileKey?: string;
|
|
@@ -1,15 +1,20 @@
|
|
|
1
1
|
import { mkdir, stat, writeFile } from "node:fs/promises";
|
|
2
2
|
import { dirname, isAbsolute, join } from "node:path";
|
|
3
3
|
import { isatty } from "node:tty";
|
|
4
|
+
import { fileURLToPath } from "node:url";
|
|
5
|
+
import { startExplorer } from "@aigne/afs-explorer";
|
|
4
6
|
import { exists } from "@aigne/agent-library/utils/fs.js";
|
|
5
7
|
import { AIAgent, DEFAULT_OUTPUT_KEY, UserAgent, } from "@aigne/core";
|
|
6
8
|
import { logger } from "@aigne/core/utils/logger.js";
|
|
7
9
|
import { isEmpty, isNil, omitBy, pick } from "@aigne/core/utils/type-utils.js";
|
|
10
|
+
import { v7 } from "@aigne/uuid";
|
|
8
11
|
import chalk from "chalk";
|
|
12
|
+
import { detect } from "detect-port";
|
|
9
13
|
import yargs from "yargs";
|
|
10
14
|
import { hideBin } from "yargs/helpers";
|
|
15
|
+
import { DEFAULT_AFS_EXPLORER_PORT, DEFAULT_USER_ID } from "../constants.js";
|
|
11
16
|
import { TerminalTracer } from "../tracer/terminal.js";
|
|
12
|
-
import { loadAIGNE } from "./load-aigne.js";
|
|
17
|
+
import { loadAIGNE, printChatModelInfoBox } from "./load-aigne.js";
|
|
13
18
|
import { DEFAULT_CHAT_INPUT_KEY, runChatLoopInTerminal, } from "./run-chat-loop.js";
|
|
14
19
|
import { parseAgentInput, withAgentInputSchema, withRunAgentCommonOptions, } from "./yargs.js";
|
|
15
20
|
export async function parseAgentInputByCommander(agent, options = {}) {
|
|
@@ -52,6 +57,8 @@ export async function runWithAIGNE(agentCreator, { aigne, argv = process.argv, c
|
|
|
52
57
|
...omitBy(pick(options, "model", "temperature", "topP", "presencePenalty", "frequencyPenalty"), (v) => isNil(v)),
|
|
53
58
|
},
|
|
54
59
|
});
|
|
60
|
+
let explorerServer;
|
|
61
|
+
let explorerServerURL;
|
|
55
62
|
try {
|
|
56
63
|
const agent = typeof agentCreator === "function" ? await agentCreator(aigne) : agentCreator;
|
|
57
64
|
const input = await parseAgentInputByCommander(agent, {
|
|
@@ -59,14 +66,34 @@ export async function runWithAIGNE(agentCreator, { aigne, argv = process.argv, c
|
|
|
59
66
|
inputKey: chatLoopOptions?.inputKey,
|
|
60
67
|
defaultInput: chatLoopOptions?.initialCall || chatLoopOptions?.defaultQuestion,
|
|
61
68
|
});
|
|
69
|
+
if (agent.afs) {
|
|
70
|
+
const port = await detect(DEFAULT_AFS_EXPLORER_PORT);
|
|
71
|
+
explorerServer = await startExplorer(agent.afs, {
|
|
72
|
+
port,
|
|
73
|
+
distPath: dirname(fileURLToPath(import.meta.resolve("@aigne/afs-explorer/index.html"))),
|
|
74
|
+
});
|
|
75
|
+
explorerServerURL = `http://localhost:${port}`;
|
|
76
|
+
}
|
|
77
|
+
if (aigne.model) {
|
|
78
|
+
const lines = [];
|
|
79
|
+
if (explorerServerURL) {
|
|
80
|
+
lines.push(`${chalk.cyan("AFS Explorer")}: ${chalk.green(explorerServerURL)}`);
|
|
81
|
+
}
|
|
82
|
+
await printChatModelInfoBox(aigne.model, lines);
|
|
83
|
+
}
|
|
84
|
+
if (chatLoopOptions?.welcome)
|
|
85
|
+
console.log(chatLoopOptions.welcome);
|
|
62
86
|
await runAgentWithAIGNE(aigne, agent, {
|
|
63
87
|
...options,
|
|
64
88
|
outputKey: outputKey || options.outputKey,
|
|
65
89
|
chatLoopOptions,
|
|
66
90
|
input,
|
|
91
|
+
sessionId: chatLoopOptions?.sessionId || v7(),
|
|
92
|
+
userId: DEFAULT_USER_ID,
|
|
67
93
|
});
|
|
68
94
|
}
|
|
69
95
|
finally {
|
|
96
|
+
await explorerServer?.stop();
|
|
70
97
|
await aigne.shutdown();
|
|
71
98
|
}
|
|
72
99
|
})
|
|
@@ -84,7 +111,7 @@ export async function runWithAIGNE(agentCreator, { aigne, argv = process.argv, c
|
|
|
84
111
|
process.exit(1);
|
|
85
112
|
});
|
|
86
113
|
}
|
|
87
|
-
export async function runAgentWithAIGNE(aigne, agent, { sessionId, outputKey, outputFileKey, chatLoopOptions, ...options } = {}) {
|
|
114
|
+
export async function runAgentWithAIGNE(aigne, agent, { userId, sessionId, outputKey, outputFileKey, chatLoopOptions, ...options } = {}) {
|
|
88
115
|
if (options.output) {
|
|
89
116
|
const outputPath = isAbsolute(options.output)
|
|
90
117
|
? options.output
|
|
@@ -102,9 +129,9 @@ export async function runAgentWithAIGNE(aigne, agent, { sessionId, outputKey, ou
|
|
|
102
129
|
}
|
|
103
130
|
await writeFile(outputPath, "", "utf8");
|
|
104
131
|
}
|
|
105
|
-
if (options.
|
|
132
|
+
if (options.interactive) {
|
|
106
133
|
if (!isatty(process.stdout.fd)) {
|
|
107
|
-
throw new Error("--
|
|
134
|
+
throw new Error("--interactive mode requires a TTY terminal");
|
|
108
135
|
}
|
|
109
136
|
const userAgent = agent instanceof UserAgent ? agent : aigne.invoke(agent);
|
|
110
137
|
await runChatLoopInTerminal(userAgent, {
|
|
@@ -113,6 +140,7 @@ export async function runAgentWithAIGNE(aigne, agent, { sessionId, outputKey, ou
|
|
|
113
140
|
inputFileKey: agent instanceof AIAgent ? agent.inputFileKey : undefined,
|
|
114
141
|
input: options.input,
|
|
115
142
|
sessionId,
|
|
143
|
+
userId,
|
|
116
144
|
});
|
|
117
145
|
return;
|
|
118
146
|
}
|