@aigne/cli 1.53.1-beta.2 → 1.53.1-beta.4
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 +47 -0
- package/dist/commands/app/agent.d.ts +26 -0
- package/dist/commands/app/agent.js +102 -0
- package/dist/commands/app/app.d.ts +7 -0
- package/dist/commands/app/app.js +90 -0
- package/dist/commands/app/cli.d.ts +1 -0
- package/dist/commands/app/cli.js +2 -0
- package/dist/commands/app/upgrade.d.ts +54 -0
- package/dist/commands/app/upgrade.js +236 -0
- package/dist/commands/app.d.ts +0 -49
- package/dist/commands/app.js +28 -351
- package/dist/commands/run.js +6 -8
- package/dist/commands/serve-mcp.d.ts +3 -4
- package/dist/commands/serve-mcp.js +8 -7
- package/dist/utils/aigne-hub-user.js +2 -1
- package/dist/utils/load-aigne.d.ts +1 -2
- package/dist/utils/load-aigne.js +2 -2
- package/package.json +11 -11
- package/dist/utils/workers/run-aigne-in-child-process-worker.d.ts +0 -22
- package/dist/utils/workers/run-aigne-in-child-process-worker.js +0 -89
- package/dist/utils/workers/run-aigne-in-child-process.d.ts +0 -19
- package/dist/utils/workers/run-aigne-in-child-process.js +0 -41
package/dist/commands/app.js
CHANGED
|
@@ -1,27 +1,7 @@
|
|
|
1
|
-
import
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
import { join } from "node:path";
|
|
6
|
-
import { fetch } from "@aigne/core/utils/fetch.js";
|
|
7
|
-
import { logger } from "@aigne/core/utils/logger.js";
|
|
8
|
-
import { jsonSchemaToZod } from "@aigne/json-schema-to-zod";
|
|
9
|
-
import { Listr, PRESET_TIMER } from "@aigne/listr2";
|
|
10
|
-
import { joinURL } from "ufo";
|
|
11
|
-
import { AIGNE_CLI_VERSION } from "../constants.js";
|
|
12
|
-
import { downloadAndExtract } from "../utils/download.js";
|
|
13
|
-
import { withSpinner } from "../utils/spinner.js";
|
|
14
|
-
import { runAIGNEInChildProcess, } from "../utils/workers/run-aigne-in-child-process.js";
|
|
15
|
-
import { withAgentInputSchema } from "../utils/yargs.js";
|
|
16
|
-
import { serveMCPServerFromDir } from "./serve-mcp.js";
|
|
17
|
-
const NPM_PACKAGE_CACHE_TIME_MS = 1000 * 60 * 60 * 24; // 1 day
|
|
18
|
-
/**
|
|
19
|
-
* Check if beta applications should be used based on environment variables
|
|
20
|
-
*/
|
|
21
|
-
function shouldUseBetaApps() {
|
|
22
|
-
const envVar = process.env.AIGNE_USE_BETA_APPS;
|
|
23
|
-
return envVar === "true" || envVar === "1";
|
|
24
|
-
}
|
|
1
|
+
import { fork } from "node:child_process";
|
|
2
|
+
import { dirname, join } from "node:path";
|
|
3
|
+
import { fileURLToPath } from "node:url";
|
|
4
|
+
import { NeedReinstallBetaError, NeedReinstallError } from "./app/upgrade.js";
|
|
25
5
|
const builtinApps = [
|
|
26
6
|
{
|
|
27
7
|
name: "doc-smith",
|
|
@@ -41,337 +21,34 @@ export function createAppCommands({ argv } = {}) {
|
|
|
41
21
|
command: app.name,
|
|
42
22
|
describe: app.describe,
|
|
43
23
|
aliases: app.aliases,
|
|
44
|
-
builder: async (y) =>
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
24
|
+
builder: async (y) => y.help(false).version(false).strict(false),
|
|
25
|
+
handler: async () => {
|
|
26
|
+
let retried = false;
|
|
27
|
+
let retryWithBeta = false;
|
|
28
|
+
while (true) {
|
|
29
|
+
const child = fork(join(dirname(fileURLToPath(import.meta.url)), "./app/cli.js"), argv, {
|
|
30
|
+
stdio: "inherit",
|
|
31
|
+
env: {
|
|
32
|
+
...process.env,
|
|
33
|
+
AIGNE_APP_NAME: app.name,
|
|
34
|
+
AIGNE_APP_PACKAGE_NAME: app.packageName,
|
|
35
|
+
AIGNE_APP_DESCRIPTION: app.describe,
|
|
36
|
+
AIGNE_APP_USE_BETA_APPS: retryWithBeta ? "1" : "0",
|
|
37
|
+
},
|
|
52
38
|
});
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
}),
|
|
62
|
-
command: "$0",
|
|
63
|
-
});
|
|
39
|
+
const code = await new Promise((resolve) => {
|
|
40
|
+
child.on("exit", (code) => resolve(code));
|
|
41
|
+
});
|
|
42
|
+
if (code === NeedReinstallError.code || code === NeedReinstallBetaError.code) {
|
|
43
|
+
if (retried)
|
|
44
|
+
process.exit(1);
|
|
45
|
+
retryWithBeta = code === NeedReinstallBetaError.code;
|
|
46
|
+
retried = true;
|
|
64
47
|
}
|
|
65
|
-
|
|
66
|
-
|
|
48
|
+
else {
|
|
49
|
+
process.exit(code);
|
|
67
50
|
}
|
|
68
|
-
y.option("model", {
|
|
69
|
-
type: "string",
|
|
70
|
-
description: "Model to use for the application, example: openai:gpt-4.1 or google:gemini-2.5-flash",
|
|
71
|
-
}).command(serveMcpCommandModule({ name: app.name, version, dir }));
|
|
72
|
-
y.version(`${app.name} v${version}`).alias("version", "v");
|
|
73
51
|
}
|
|
74
|
-
return y.demandCommand();
|
|
75
52
|
},
|
|
76
|
-
handler: () => { },
|
|
77
53
|
}));
|
|
78
54
|
}
|
|
79
|
-
const serveMcpCommandModule = ({ name, dir, version, }) => ({
|
|
80
|
-
command: "serve-mcp",
|
|
81
|
-
describe: `Serve ${name} a MCP server (streamable http)`,
|
|
82
|
-
builder: (yargs) => {
|
|
83
|
-
return yargs
|
|
84
|
-
.option("host", {
|
|
85
|
-
describe: "Host to run the MCP server on, use 0.0.0.0 to publicly expose the server",
|
|
86
|
-
type: "string",
|
|
87
|
-
default: "localhost",
|
|
88
|
-
})
|
|
89
|
-
.option("port", {
|
|
90
|
-
describe: "Port to run the MCP server on",
|
|
91
|
-
type: "number",
|
|
92
|
-
})
|
|
93
|
-
.option("pathname", {
|
|
94
|
-
describe: "Pathname to the service",
|
|
95
|
-
type: "string",
|
|
96
|
-
default: "/mcp",
|
|
97
|
-
});
|
|
98
|
-
},
|
|
99
|
-
handler: async (options) => {
|
|
100
|
-
await serveMCPServerFromDir({
|
|
101
|
-
...options,
|
|
102
|
-
dir,
|
|
103
|
-
metadata: {
|
|
104
|
-
appName: name,
|
|
105
|
-
appVersion: version,
|
|
106
|
-
},
|
|
107
|
-
});
|
|
108
|
-
},
|
|
109
|
-
});
|
|
110
|
-
function isUpgradeCommand(argv) {
|
|
111
|
-
const skipGlobalOptions = ["-v", "--version"];
|
|
112
|
-
return argv[1] === "upgrade" && !argv.some((arg) => skipGlobalOptions.includes(arg));
|
|
113
|
-
}
|
|
114
|
-
const upgradeCommandModule = ({ packageName, dir, }) => ({
|
|
115
|
-
command: "upgrade",
|
|
116
|
-
describe: `Upgrade ${packageName} to the latest version`,
|
|
117
|
-
builder: (yargs) => {
|
|
118
|
-
return yargs
|
|
119
|
-
.option("beta", {
|
|
120
|
-
type: "boolean",
|
|
121
|
-
describe: "Use beta versions if available",
|
|
122
|
-
})
|
|
123
|
-
.option("target-version", {
|
|
124
|
-
type: "string",
|
|
125
|
-
describe: "Specify a version to upgrade to (default is latest)",
|
|
126
|
-
alias: ["to", "target"],
|
|
127
|
-
})
|
|
128
|
-
.option("force", {
|
|
129
|
-
type: "boolean",
|
|
130
|
-
describe: "Force upgrade even if already at latest version",
|
|
131
|
-
default: false,
|
|
132
|
-
});
|
|
133
|
-
},
|
|
134
|
-
handler: async ({ beta, targetVersion, force }) => {
|
|
135
|
-
beta ??= shouldUseBetaApps();
|
|
136
|
-
const npm = await withSpinner("", async () => {
|
|
137
|
-
if (force)
|
|
138
|
-
await rm(dir, { force: true, recursive: true });
|
|
139
|
-
return await getNpmTgzInfo(packageName, { beta, version: targetVersion });
|
|
140
|
-
});
|
|
141
|
-
let app = await loadApplication({ packageName, dir });
|
|
142
|
-
if (!app || force || npm.version !== app.version) {
|
|
143
|
-
await installApp({ packageName, dir, beta, version: targetVersion });
|
|
144
|
-
app = await loadApplication({ dir, packageName, install: true });
|
|
145
|
-
console.log(`\n✅ Upgraded ${packageName} to version ${app.version}`);
|
|
146
|
-
return;
|
|
147
|
-
}
|
|
148
|
-
console.log(`\n✅ ${packageName} is already at the latest version (${app.version})`);
|
|
149
|
-
},
|
|
150
|
-
});
|
|
151
|
-
export const agentCommandModule = ({ dir, agent, chat, version, packageName, }) => {
|
|
152
|
-
return {
|
|
153
|
-
command: agent.name,
|
|
154
|
-
aliases: agent.alias || [],
|
|
155
|
-
describe: agent.description || "",
|
|
156
|
-
builder: async (yargs) => {
|
|
157
|
-
return withAgentInputSchema(yargs, { inputSchema: jsonSchemaToZod(agent.inputSchema) });
|
|
158
|
-
},
|
|
159
|
-
handler: async (options) => {
|
|
160
|
-
if (options.logLevel)
|
|
161
|
-
logger.level = options.logLevel;
|
|
162
|
-
await runAIGNEInChildProcess("invokeCLIAgentFromDir", {
|
|
163
|
-
dir,
|
|
164
|
-
agent: agent.name,
|
|
165
|
-
input: { ...options, chat: chat ?? options.chat },
|
|
166
|
-
metadata: {
|
|
167
|
-
cliVersion: AIGNE_CLI_VERSION,
|
|
168
|
-
appName: packageName,
|
|
169
|
-
appVersion: version,
|
|
170
|
-
},
|
|
171
|
-
});
|
|
172
|
-
process.exit(0);
|
|
173
|
-
},
|
|
174
|
-
};
|
|
175
|
-
};
|
|
176
|
-
export const cliAgentCommandModule = ({ dir, parent, cliAgent, version, packageName, }) => {
|
|
177
|
-
const { agent, agents } = cliAgent;
|
|
178
|
-
const name = cliAgent.name || agent?.name;
|
|
179
|
-
assert(name, "CLI agent must have a name");
|
|
180
|
-
return {
|
|
181
|
-
command: name,
|
|
182
|
-
aliases: cliAgent.alias || agent?.alias || [],
|
|
183
|
-
describe: cliAgent.description || agent?.description || "",
|
|
184
|
-
builder: async (yargs) => {
|
|
185
|
-
if (agent) {
|
|
186
|
-
withAgentInputSchema(yargs, { inputSchema: jsonSchemaToZod(agent.inputSchema) });
|
|
187
|
-
}
|
|
188
|
-
if (agents?.length) {
|
|
189
|
-
for (const cmd of agents) {
|
|
190
|
-
yargs.command(cliAgentCommandModule({
|
|
191
|
-
dir,
|
|
192
|
-
parent: (parent ?? []).concat(name),
|
|
193
|
-
cliAgent: cmd,
|
|
194
|
-
version,
|
|
195
|
-
packageName,
|
|
196
|
-
}));
|
|
197
|
-
}
|
|
198
|
-
}
|
|
199
|
-
if (!agent)
|
|
200
|
-
yargs.demandCommand();
|
|
201
|
-
return yargs;
|
|
202
|
-
},
|
|
203
|
-
handler: async (options) => {
|
|
204
|
-
if (!agent)
|
|
205
|
-
throw new Error("CLI agent is not defined");
|
|
206
|
-
if (options.logLevel)
|
|
207
|
-
logger.level = options.logLevel;
|
|
208
|
-
await runAIGNEInChildProcess("invokeCLIAgentFromDir", {
|
|
209
|
-
dir,
|
|
210
|
-
parent,
|
|
211
|
-
agent: name,
|
|
212
|
-
input: options,
|
|
213
|
-
metadata: {
|
|
214
|
-
cliVersion: AIGNE_CLI_VERSION,
|
|
215
|
-
appName: packageName,
|
|
216
|
-
appVersion: version,
|
|
217
|
-
},
|
|
218
|
-
});
|
|
219
|
-
process.exit(0);
|
|
220
|
-
},
|
|
221
|
-
};
|
|
222
|
-
};
|
|
223
|
-
export async function loadApplication(options) {
|
|
224
|
-
const { dir, packageName } = options;
|
|
225
|
-
const check = await checkInstallation(dir);
|
|
226
|
-
if (check && !check.expired) {
|
|
227
|
-
const aigne = await runAIGNEInChildProcess("loadAIGNE", {
|
|
228
|
-
path: dir,
|
|
229
|
-
skipModelLoading: true,
|
|
230
|
-
metadata: {
|
|
231
|
-
appName: packageName,
|
|
232
|
-
appVersion: check?.version,
|
|
233
|
-
},
|
|
234
|
-
}).catch(async (error) => {
|
|
235
|
-
logger.error(`⚠️ Failed to load ${packageName}, trying to reinstall:`, error.message);
|
|
236
|
-
await withSpinner("", async () => {
|
|
237
|
-
await rm(options.dir, { recursive: true, force: true });
|
|
238
|
-
await mkdir(options.dir, { recursive: true });
|
|
239
|
-
});
|
|
240
|
-
});
|
|
241
|
-
if (aigne) {
|
|
242
|
-
return { aigne, version: check.version, isCache: true };
|
|
243
|
-
}
|
|
244
|
-
}
|
|
245
|
-
if (!options.install)
|
|
246
|
-
return null;
|
|
247
|
-
const result = await installApp({ dir, packageName, beta: check?.version?.includes("beta") });
|
|
248
|
-
return {
|
|
249
|
-
aigne: await runAIGNEInChildProcess("loadAIGNE", {
|
|
250
|
-
path: dir,
|
|
251
|
-
skipModelLoading: true,
|
|
252
|
-
metadata: {
|
|
253
|
-
appName: packageName,
|
|
254
|
-
appVersion: result.version,
|
|
255
|
-
},
|
|
256
|
-
}),
|
|
257
|
-
version: result.version,
|
|
258
|
-
};
|
|
259
|
-
}
|
|
260
|
-
async function readInstallationMetadata(dir) {
|
|
261
|
-
return safeParseJSON(await readFile(join(dir, ".aigne-cli.json"), "utf-8").catch(() => "{}"));
|
|
262
|
-
}
|
|
263
|
-
async function writeInstallationMetadata(dir, metadata) {
|
|
264
|
-
await writeFile(join(dir, ".aigne-cli.json"), JSON.stringify(metadata, null, 2));
|
|
265
|
-
}
|
|
266
|
-
async function checkInstallation(dir, { cacheTimeMs = NPM_PACKAGE_CACHE_TIME_MS } = {}) {
|
|
267
|
-
const s = await stat(join(dir, "package.json")).catch(() => null);
|
|
268
|
-
if (!s)
|
|
269
|
-
return null;
|
|
270
|
-
const version = safeParseJSON(await readFile(join(dir, "package.json"), "utf-8"))?.version;
|
|
271
|
-
if (!version)
|
|
272
|
-
return null;
|
|
273
|
-
const installedAt = (await readInstallationMetadata(dir))?.installedAt;
|
|
274
|
-
if (!installedAt)
|
|
275
|
-
return null;
|
|
276
|
-
const now = Date.now();
|
|
277
|
-
const expired = now - installedAt > cacheTimeMs;
|
|
278
|
-
return { version, expired };
|
|
279
|
-
}
|
|
280
|
-
export async function installApp({ dir, packageName, beta, version, }) {
|
|
281
|
-
return await new Listr([
|
|
282
|
-
{
|
|
283
|
-
title: `Fetching ${packageName} metadata`,
|
|
284
|
-
task: async (ctx, task) => {
|
|
285
|
-
if (beta) {
|
|
286
|
-
task.title = `Fetching ${packageName} metadata (using beta version)`;
|
|
287
|
-
}
|
|
288
|
-
const info = await getNpmTgzInfo(packageName, { beta, version });
|
|
289
|
-
Object.assign(ctx, info);
|
|
290
|
-
},
|
|
291
|
-
},
|
|
292
|
-
{
|
|
293
|
-
title: `Downloading ${packageName}`,
|
|
294
|
-
task: async (ctx, task) => {
|
|
295
|
-
task.title = `Downloading ${packageName} (v${ctx.version})`;
|
|
296
|
-
await mkdir(dir, { recursive: true });
|
|
297
|
-
await downloadAndExtract(ctx.url, dir, { strip: 1 });
|
|
298
|
-
},
|
|
299
|
-
},
|
|
300
|
-
{
|
|
301
|
-
title: "Installing dependencies",
|
|
302
|
-
task: async (_, task) => {
|
|
303
|
-
await installDependencies(dir, {
|
|
304
|
-
log: (log) => {
|
|
305
|
-
const last = log.split("\n").findLast((i) => !!i);
|
|
306
|
-
if (last)
|
|
307
|
-
task.output = last;
|
|
308
|
-
},
|
|
309
|
-
});
|
|
310
|
-
await writeInstallationMetadata(dir, { installedAt: Date.now() });
|
|
311
|
-
},
|
|
312
|
-
},
|
|
313
|
-
], {
|
|
314
|
-
rendererOptions: {
|
|
315
|
-
collapseSubtasks: false,
|
|
316
|
-
showErrorMessage: false,
|
|
317
|
-
timer: PRESET_TIMER,
|
|
318
|
-
},
|
|
319
|
-
}).run();
|
|
320
|
-
}
|
|
321
|
-
async function installDependencies(dir, { log } = {}) {
|
|
322
|
-
await new Promise((resolve, reject) => {
|
|
323
|
-
const child = spawn("npm", ["install", "--omit", "dev", "--verbose", "--legacy-peer-deps"], {
|
|
324
|
-
cwd: dir,
|
|
325
|
-
stdio: "pipe",
|
|
326
|
-
shell: process.platform === "win32",
|
|
327
|
-
});
|
|
328
|
-
child.stdout.on("data", (data) => {
|
|
329
|
-
log?.(data.toString());
|
|
330
|
-
});
|
|
331
|
-
let stderr = "";
|
|
332
|
-
child.stderr.on("data", (data) => {
|
|
333
|
-
const str = data.toString();
|
|
334
|
-
log?.(str);
|
|
335
|
-
stderr += str;
|
|
336
|
-
});
|
|
337
|
-
child.on("error", (error) => reject(error));
|
|
338
|
-
child.on("exit", (code) => {
|
|
339
|
-
if (code === 0)
|
|
340
|
-
resolve();
|
|
341
|
-
else {
|
|
342
|
-
console.error(stderr);
|
|
343
|
-
reject(new Error(`npm install failed with code ${code}`));
|
|
344
|
-
}
|
|
345
|
-
});
|
|
346
|
-
});
|
|
347
|
-
}
|
|
348
|
-
export async function getNpmTgzInfo(name, { version, beta } = {}) {
|
|
349
|
-
const res = await fetch(joinURL("https://registry.npmjs.org", name));
|
|
350
|
-
const data = await res.json();
|
|
351
|
-
let targetVersion;
|
|
352
|
-
if (version) {
|
|
353
|
-
if (!data.versions[version]) {
|
|
354
|
-
throw new Error(`Version ${version} of package ${name} not found`);
|
|
355
|
-
}
|
|
356
|
-
targetVersion = version;
|
|
357
|
-
}
|
|
358
|
-
else if (beta && data["dist-tags"].beta) {
|
|
359
|
-
// Use beta version if available and beta flag is set
|
|
360
|
-
targetVersion = data["dist-tags"].beta;
|
|
361
|
-
}
|
|
362
|
-
else {
|
|
363
|
-
// Fall back to latest version
|
|
364
|
-
targetVersion = data["dist-tags"].latest;
|
|
365
|
-
}
|
|
366
|
-
const url = data.versions[targetVersion].dist.tarball;
|
|
367
|
-
return {
|
|
368
|
-
version: targetVersion,
|
|
369
|
-
url,
|
|
370
|
-
};
|
|
371
|
-
}
|
|
372
|
-
function safeParseJSON(raw) {
|
|
373
|
-
try {
|
|
374
|
-
return JSON.parse(raw);
|
|
375
|
-
}
|
|
376
|
-
catch { }
|
|
377
|
-
}
|
package/dist/commands/run.js
CHANGED
|
@@ -2,7 +2,6 @@ import { cp, mkdir, rm } from "node:fs/promises";
|
|
|
2
2
|
import { homedir } from "node:os";
|
|
3
3
|
import { isAbsolute, join, resolve } from "node:path";
|
|
4
4
|
import { exists } from "@aigne/agent-library/utils/fs.js";
|
|
5
|
-
import { mapCliAgent } from "@aigne/core/utils/agent-utils.js";
|
|
6
5
|
import { flat, isNonNullable } from "@aigne/core/utils/type-utils.js";
|
|
7
6
|
import { Listr, PRESET_TIMER } from "@aigne/listr2";
|
|
8
7
|
import { config } from "dotenv-flow";
|
|
@@ -11,8 +10,7 @@ import { isV1Package, toAIGNEPackage } from "../utils/agent-v1.js";
|
|
|
11
10
|
import { downloadAndExtract } from "../utils/download.js";
|
|
12
11
|
import { loadAIGNE } from "../utils/load-aigne.js";
|
|
13
12
|
import { isUrl } from "../utils/url.js";
|
|
14
|
-
import {
|
|
15
|
-
import { agentCommandModule, cliAgentCommandModule } from "./app.js";
|
|
13
|
+
import { agentCommandModule, cliAgentCommandModule } from "./app/agent.js";
|
|
16
14
|
export function createRunCommand({ aigneFilePath, } = {}) {
|
|
17
15
|
return {
|
|
18
16
|
command: "run [path] [entry-agent]",
|
|
@@ -39,23 +37,23 @@ export function createRunCommand({ aigneFilePath, } = {}) {
|
|
|
39
37
|
options.path = undefined;
|
|
40
38
|
}
|
|
41
39
|
}
|
|
42
|
-
const { aigne
|
|
40
|
+
const { aigne } = await loadApplication(aigneFilePath || options.path || ".");
|
|
43
41
|
const subYargs = yargs().scriptName("").usage("aigne run <path> <agent> [...options]");
|
|
44
42
|
if (aigne.cli.chat) {
|
|
45
43
|
subYargs.command({
|
|
46
|
-
...agentCommandModule({
|
|
44
|
+
...agentCommandModule({ aigne, agent: aigne.cli.chat, chat: true }),
|
|
47
45
|
command: "$0",
|
|
48
46
|
});
|
|
49
47
|
}
|
|
50
48
|
// Allow user to run all of agents in the AIGNE instances
|
|
51
49
|
const allAgents = flat(aigne.agents, aigne.skills, aigne.cli.chat, aigne.mcpServer.agents);
|
|
52
50
|
for (const agent of allAgents) {
|
|
53
|
-
subYargs.command(agentCommandModule({
|
|
51
|
+
subYargs.command(agentCommandModule({ aigne, agent }));
|
|
54
52
|
}
|
|
55
53
|
for (const cliAgent of aigne.cli.agents ?? []) {
|
|
56
54
|
subYargs.command(cliAgentCommandModule({
|
|
57
|
-
|
|
58
|
-
cliAgent
|
|
55
|
+
aigne,
|
|
56
|
+
cliAgent,
|
|
59
57
|
}));
|
|
60
58
|
}
|
|
61
59
|
const argv = process.argv.slice(aigneFilePath ? 3 : 2);
|
|
@@ -1,21 +1,20 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { AIGNE } from "@aigne/core";
|
|
2
2
|
import type { CommandModule } from "yargs";
|
|
3
3
|
interface ServeMCPOptions {
|
|
4
4
|
path: string;
|
|
5
5
|
host: string;
|
|
6
6
|
port?: number;
|
|
7
7
|
pathname: string;
|
|
8
|
+
aigneHubUrl?: string;
|
|
8
9
|
}
|
|
9
10
|
export declare const DEFAULT_PORT: () => number;
|
|
10
11
|
export declare function createServeMCPCommand({ aigneFilePath, }?: {
|
|
11
12
|
aigneFilePath?: string;
|
|
12
13
|
}): CommandModule<unknown, ServeMCPOptions>;
|
|
13
14
|
export declare function serveMCPServerFromDir(options: {
|
|
14
|
-
|
|
15
|
+
aigne: AIGNE;
|
|
15
16
|
host: string;
|
|
16
17
|
port?: number;
|
|
17
18
|
pathname: string;
|
|
18
|
-
aigneHubUrl?: string;
|
|
19
|
-
metadata?: AIGNEMetadata;
|
|
20
19
|
}): Promise<void>;
|
|
21
20
|
export {};
|
|
@@ -45,22 +45,23 @@ export function createServeMCPCommand({ aigneFilePath, } = {}) {
|
|
|
45
45
|
handler: async (options) => {
|
|
46
46
|
const path = aigneFilePath || options.path;
|
|
47
47
|
const absolutePath = isAbsolute(path) ? path : resolve(process.cwd(), path);
|
|
48
|
-
await
|
|
48
|
+
const aigne = await loadAIGNE({
|
|
49
|
+
path: absolutePath,
|
|
50
|
+
modelOptions: { aigneHubUrl: options.aigneHubUrl },
|
|
51
|
+
});
|
|
52
|
+
await serveMCPServerFromDir({ ...options, aigne });
|
|
49
53
|
},
|
|
50
54
|
};
|
|
51
55
|
}
|
|
52
56
|
export async function serveMCPServerFromDir(options) {
|
|
53
57
|
const port = options.port || DEFAULT_PORT();
|
|
54
|
-
const aigne = await loadAIGNE({
|
|
55
|
-
path: options.dir,
|
|
56
|
-
modelOptions: { aigneHubUrl: options.aigneHubUrl },
|
|
57
|
-
metadata: options.metadata,
|
|
58
|
-
});
|
|
59
58
|
await serveMCPServer({
|
|
60
|
-
aigne,
|
|
59
|
+
aigne: options.aigne,
|
|
61
60
|
host: options.host,
|
|
62
61
|
port,
|
|
63
62
|
pathname: options.pathname,
|
|
64
63
|
});
|
|
65
64
|
console.log(`MCP server is running on http://${options.host}:${port}${options.pathname}`);
|
|
65
|
+
if (!process.env.CI && process.env.NODE_ENV !== "test")
|
|
66
|
+
await new Promise(() => { }); // Keep the server running
|
|
66
67
|
}
|
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import { fetch } from "@aigne/core/utils/fetch.js";
|
|
2
2
|
import { joinURL } from "ufo";
|
|
3
3
|
export async function getUserInfo({ baseUrl, apiKey, }) {
|
|
4
|
-
const
|
|
4
|
+
const secureBaseUrl = baseUrl.replace(/^http:/, "https:");
|
|
5
|
+
const response = await fetch(joinURL(secureBaseUrl, "/api/user/info"), {
|
|
5
6
|
headers: { Authorization: `Bearer ${apiKey}` },
|
|
6
7
|
});
|
|
7
8
|
const data = await response.json();
|
|
@@ -8,11 +8,10 @@ export interface RunOptions extends AgentRunCommonOptions {
|
|
|
8
8
|
cacheDir?: string;
|
|
9
9
|
aigneHubUrl?: string;
|
|
10
10
|
}
|
|
11
|
-
export declare function loadAIGNE({ path, modelOptions, imageModelOptions,
|
|
11
|
+
export declare function loadAIGNE({ path, modelOptions, imageModelOptions, skipModelLoading, metadata, }: {
|
|
12
12
|
path?: string;
|
|
13
13
|
modelOptions?: ChatModelInputOptions & LoadCredentialOptions;
|
|
14
14
|
imageModelOptions?: ImageModelInputOptions & LoadCredentialOptions;
|
|
15
|
-
printTips?: boolean;
|
|
16
15
|
skipModelLoading?: boolean;
|
|
17
16
|
metadata?: AIGNEMetadata;
|
|
18
17
|
}): Promise<AIGNE<import("@aigne/core").UserContext>>;
|
package/dist/utils/load-aigne.js
CHANGED
|
@@ -21,7 +21,7 @@ async function printChatModelInfoBox(model) {
|
|
|
21
21
|
console.log(boxen(lines.join("\n"), { padding: 1, borderStyle: "classic", borderColor: "cyan" }));
|
|
22
22
|
console.log("");
|
|
23
23
|
}
|
|
24
|
-
export async function loadAIGNE({ path, modelOptions, imageModelOptions,
|
|
24
|
+
export async function loadAIGNE({ path, modelOptions, imageModelOptions, skipModelLoading = false, metadata, }) {
|
|
25
25
|
let aigne;
|
|
26
26
|
if (path) {
|
|
27
27
|
aigne = await AIGNE.load(path, {
|
|
@@ -62,7 +62,7 @@ export async function loadAIGNE({ path, modelOptions, imageModelOptions, printTi
|
|
|
62
62
|
metadata: { ...metadata, cliVersion: AIGNE_CLI_VERSION },
|
|
63
63
|
});
|
|
64
64
|
}
|
|
65
|
-
if (
|
|
65
|
+
if (!skipModelLoading && !printed) {
|
|
66
66
|
printed = true;
|
|
67
67
|
console.log(`${chalk.grey("TIPS:")} run ${chalk.cyan("aigne observe")} to start the observability server.\n`);
|
|
68
68
|
if (aigne.model) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@aigne/cli",
|
|
3
|
-
"version": "1.53.1-beta.
|
|
3
|
+
"version": "1.53.1-beta.4",
|
|
4
4
|
"description": "Your command center for agent development",
|
|
5
5
|
"publishConfig": {
|
|
6
6
|
"access": "public"
|
|
@@ -55,7 +55,7 @@
|
|
|
55
55
|
"@inquirer/type": "^3.0.8",
|
|
56
56
|
"@listr2/prompt-adapter-inquirer": "^3.0.4",
|
|
57
57
|
"@modelcontextprotocol/sdk": "^1.18.0",
|
|
58
|
-
"@ocap/mcrypto": "^1.
|
|
58
|
+
"@ocap/mcrypto": "^1.27.2",
|
|
59
59
|
"@smithy/node-http-handler": "^4.2.1",
|
|
60
60
|
"ansi-escapes": "^7.1.0",
|
|
61
61
|
"ansi-regex": "^6.2.2",
|
|
@@ -89,14 +89,14 @@
|
|
|
89
89
|
"yoctocolors-cjs": "^2.1.3",
|
|
90
90
|
"zod": "^3.25.67",
|
|
91
91
|
"zod-to-json-schema": "^3.24.6",
|
|
92
|
-
"@aigne/afs-system-fs": "^1.0.4-beta.
|
|
93
|
-
"@aigne/agent-library": "^1.21.51-beta.
|
|
94
|
-
"@aigne/agentic-memory": "^1.0.51-beta.
|
|
95
|
-
"@aigne/
|
|
96
|
-
"@aigne/
|
|
97
|
-
"@aigne/default-memory": "^1.2.14-beta.
|
|
98
|
-
"@aigne/observability-api": "^0.11.5-beta",
|
|
99
|
-
"@aigne/openai": "^0.16.5-beta.
|
|
92
|
+
"@aigne/afs-system-fs": "^1.0.4-beta.4",
|
|
93
|
+
"@aigne/agent-library": "^1.21.51-beta.3",
|
|
94
|
+
"@aigne/agentic-memory": "^1.0.51-beta.3",
|
|
95
|
+
"@aigne/aigne-hub": "^0.10.5-beta.3",
|
|
96
|
+
"@aigne/core": "^1.65.1-beta.3",
|
|
97
|
+
"@aigne/default-memory": "^1.2.14-beta.3",
|
|
98
|
+
"@aigne/observability-api": "^0.11.5-beta.2",
|
|
99
|
+
"@aigne/openai": "^0.16.5-beta.3"
|
|
100
100
|
},
|
|
101
101
|
"devDependencies": {
|
|
102
102
|
"@inquirer/testing": "^2.1.50",
|
|
@@ -114,7 +114,7 @@
|
|
|
114
114
|
"rimraf": "^6.0.1",
|
|
115
115
|
"typescript": "^5.9.2",
|
|
116
116
|
"ufo": "^1.6.1",
|
|
117
|
-
"@aigne/test-utils": "^0.5.58-beta.
|
|
117
|
+
"@aigne/test-utils": "^0.5.58-beta.3"
|
|
118
118
|
},
|
|
119
119
|
"scripts": {
|
|
120
120
|
"lint": "tsc --noEmit",
|
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
import type { Message } from "@aigne/core";
|
|
2
|
-
import type { AIGNEMetadata } from "@aigne/core/aigne/type.js";
|
|
3
|
-
import { loadAIGNE } from "../load-aigne.js";
|
|
4
|
-
import { type AgentRunCommonOptions } from "../yargs.js";
|
|
5
|
-
import { type AgentInChildProcess, type CLIAgentInChildProcess } from "./run-aigne-in-child-process.js";
|
|
6
|
-
export declare function loadAIGNEInChildProcess(options: Parameters<typeof loadAIGNE>[0]): Promise<{
|
|
7
|
-
agents?: AgentInChildProcess[];
|
|
8
|
-
cli?: {
|
|
9
|
-
chat?: AgentInChildProcess;
|
|
10
|
-
agents?: CLIAgentInChildProcess[];
|
|
11
|
-
};
|
|
12
|
-
mcpServer?: {
|
|
13
|
-
agents?: AgentInChildProcess[];
|
|
14
|
-
};
|
|
15
|
-
}>;
|
|
16
|
-
export declare function invokeCLIAgentFromDirInChildProcess(options: {
|
|
17
|
-
dir: string;
|
|
18
|
-
parent?: string[];
|
|
19
|
-
agent: string;
|
|
20
|
-
input: Message & AgentRunCommonOptions;
|
|
21
|
-
metadata?: AIGNEMetadata;
|
|
22
|
-
}): Promise<void>;
|