@aigne/cli 1.53.1-beta.2 → 1.53.1-beta.3

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.
@@ -1,89 +0,0 @@
1
- import assert from "node:assert";
2
- import { findCliAgent, mapCliAgent } from "@aigne/core/utils/agent-utils.js";
3
- import { logger } from "@aigne/core/utils/logger.js";
4
- import { loadAIGNE } from "../load-aigne.js";
5
- import { runAgentWithAIGNE } from "../run-with-aigne.js";
6
- import { parseAgentInput } from "../yargs.js";
7
- import { serializeAgent, } from "./run-aigne-in-child-process.js";
8
- const METHODS = {
9
- loadAIGNE: loadAIGNEInChildProcess,
10
- invokeCLIAgentFromDir: invokeCLIAgentFromDirInChildProcess,
11
- };
12
- process.on("message", async ({ method, args, ...options }) => {
13
- if (options.logLevel)
14
- logger.level = options.logLevel;
15
- const send = (message) => new Promise((resolve, reject) => {
16
- assert(process.send);
17
- process.send(message, undefined, undefined, (error) => {
18
- if (error)
19
- reject(error);
20
- else
21
- resolve(true);
22
- });
23
- });
24
- try {
25
- const handler = METHODS[method];
26
- if (!handler)
27
- throw new Error(`Unknown method: ${method}`);
28
- const result = await handler(...args);
29
- await send({ method, result });
30
- }
31
- catch (error) {
32
- await send({
33
- method,
34
- error: { name: error.name, message: error.message, stack: error.stack },
35
- });
36
- }
37
- finally {
38
- process.exit(0);
39
- }
40
- });
41
- export async function loadAIGNEInChildProcess(options) {
42
- const aigne = await loadAIGNE(options);
43
- return {
44
- agents: aigne.agents.map(serializeAgent),
45
- cli: {
46
- chat: aigne.cli.chat ? serializeAgent(aigne.cli.chat) : undefined,
47
- agents: aigne.cli.agents?.map((item) => mapCliAgent(item, serializeAgent)),
48
- },
49
- mcpServer: {
50
- agents: aigne.mcpServer.agents.map(serializeAgent),
51
- },
52
- };
53
- }
54
- export async function invokeCLIAgentFromDirInChildProcess(options) {
55
- const aigne = await loadAIGNE({
56
- path: options.dir,
57
- modelOptions: options.input,
58
- printTips: true,
59
- imageModelOptions: { model: options.input.imageModel },
60
- metadata: options.metadata,
61
- });
62
- try {
63
- const { chat } = aigne.cli;
64
- let agent;
65
- if (chat && chat.name === options.agent) {
66
- agent = chat;
67
- }
68
- else if (options.parent) {
69
- agent = findCliAgent(aigne.cli, options.parent, options.agent);
70
- }
71
- else {
72
- agent =
73
- findCliAgent(aigne.cli, [], options.agent) ||
74
- aigne.agents[options.agent] ||
75
- aigne.skills[options.agent] ||
76
- aigne.mcpServer.agents[options.agent];
77
- }
78
- assert(agent, `Agent ${options.agent} not found in ${options.dir}`);
79
- const input = await parseAgentInput(options.input, agent);
80
- await runAgentWithAIGNE(aigne, agent, {
81
- ...options.input,
82
- input,
83
- chat: options.input.chat,
84
- });
85
- }
86
- finally {
87
- await aigne.shutdown();
88
- }
89
- }
@@ -1,19 +0,0 @@
1
- import type { Agent } from "@aigne/core";
2
- import type { AIGNECLIAgent } from "@aigne/core/aigne/type.js";
3
- import type { JsonSchema } from "@aigne/json-schema-to-zod";
4
- import type { invokeCLIAgentFromDirInChildProcess, loadAIGNEInChildProcess } from "./run-aigne-in-child-process-worker.js";
5
- export type LoadAIGNEInChildProcessResult = Awaited<ReturnType<typeof loadAIGNEInChildProcess>>;
6
- export interface AgentInChildProcess extends Pick<Agent, "name" | "description" | "alias"> {
7
- inputSchema: JsonSchema;
8
- outputSchema: JsonSchema;
9
- }
10
- export interface CLIAgentInChildProcess extends Omit<AIGNECLIAgent, "agent" | "agents"> {
11
- agent?: AgentInChildProcess;
12
- agents?: CLIAgentInChildProcess[];
13
- }
14
- export declare function serializeAgent(agent: Agent): AgentInChildProcess;
15
- export interface ChildProcessAIGNEMethods {
16
- loadAIGNE: typeof loadAIGNEInChildProcess;
17
- invokeCLIAgentFromDir: typeof invokeCLIAgentFromDirInChildProcess;
18
- }
19
- export declare function runAIGNEInChildProcess<M extends keyof ChildProcessAIGNEMethods>(method: M, ...args: Parameters<ChildProcessAIGNEMethods[M]>): Promise<ReturnType<ChildProcessAIGNEMethods[M]>>;
@@ -1,41 +0,0 @@
1
- import { fork } from "node:child_process";
2
- import { dirname, join } from "node:path";
3
- import { fileURLToPath } from "node:url";
4
- import { logger } from "@aigne/core/utils/logger.js";
5
- import { zodToJsonSchema } from "zod-to-json-schema";
6
- export function serializeAgent(agent) {
7
- return {
8
- name: agent.name,
9
- description: agent.description,
10
- alias: agent.alias,
11
- inputSchema: zodToJsonSchema(agent.inputSchema),
12
- outputSchema: zodToJsonSchema(agent.outputSchema),
13
- };
14
- }
15
- export async function runAIGNEInChildProcess(method, ...args) {
16
- return await new Promise((resolve, reject) => {
17
- let completed = false;
18
- const child = fork(join(dirname(fileURLToPath(import.meta.url)), "./run-aigne-in-child-process-worker.js"));
19
- child.on("message", (event) => {
20
- if (event.method !== method) {
21
- reject(new Error(`Unknown method: ${event.method} expected: ${method}`));
22
- }
23
- else if (event.error) {
24
- const e = new Error(event.error.message);
25
- e.name = event.error.name;
26
- e.stack = event.error.stack;
27
- reject(e);
28
- }
29
- else {
30
- resolve(event.result);
31
- }
32
- completed = true;
33
- });
34
- child.on("exit", (code) => {
35
- if (!completed)
36
- process.exit(code);
37
- reject(new Error(`Child process exited with code ${code}`));
38
- });
39
- child.send({ method, args, logLevel: logger.level });
40
- });
41
- }