@aigne/core 1.61.0 → 1.62.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/CHANGELOG.md +16 -0
- package/lib/cjs/aigne/aigne.d.ts +3 -10
- package/lib/cjs/aigne/aigne.js +2 -8
- package/lib/cjs/aigne/type.d.ts +12 -0
- package/lib/cjs/aigne/type.js +2 -0
- package/lib/cjs/loader/index.d.ts +20 -13
- package/lib/cjs/loader/index.js +29 -4
- package/lib/cjs/utils/agent-utils.d.ts +10 -0
- package/lib/cjs/utils/agent-utils.js +44 -0
- package/lib/dts/aigne/aigne.d.ts +3 -10
- package/lib/dts/aigne/type.d.ts +12 -0
- package/lib/dts/loader/index.d.ts +20 -13
- package/lib/dts/utils/agent-utils.d.ts +10 -0
- package/lib/esm/aigne/aigne.d.ts +3 -10
- package/lib/esm/aigne/aigne.js +2 -8
- package/lib/esm/aigne/type.d.ts +12 -0
- package/lib/esm/aigne/type.js +1 -0
- package/lib/esm/loader/index.d.ts +20 -13
- package/lib/esm/loader/index.js +29 -4
- package/lib/esm/utils/agent-utils.d.ts +10 -0
- package/lib/esm/utils/agent-utils.js +42 -0
- package/package.json +2 -2
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,21 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## [1.62.0-beta](https://github.com/AIGNE-io/aigne-framework/compare/core-v1.61.1-beta...core-v1.62.0-beta) (2025-09-30)
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
### Features
|
|
7
|
+
|
|
8
|
+
* **cli:** support define nested commands for sub apps ([#568](https://github.com/AIGNE-io/aigne-framework/issues/568)) ([0693b80](https://github.com/AIGNE-io/aigne-framework/commit/0693b807e0f8d335010e6ad00763b07cf095e65b))
|
|
9
|
+
|
|
10
|
+
## [1.61.1-beta](https://github.com/AIGNE-io/aigne-framework/compare/core-v1.61.0...core-v1.61.1-beta) (2025-09-29)
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
### Dependencies
|
|
14
|
+
|
|
15
|
+
* The following workspace dependencies were updated
|
|
16
|
+
* dependencies
|
|
17
|
+
* @aigne/observability-api bumped to 0.11.1-beta
|
|
18
|
+
|
|
3
19
|
## [1.61.0](https://github.com/AIGNE-io/aigne-framework/compare/core-v1.61.0-beta.8...core-v1.61.0) (2025-09-27)
|
|
4
20
|
|
|
5
21
|
|
package/lib/cjs/aigne/aigne.d.ts
CHANGED
|
@@ -6,6 +6,7 @@ import type { UserAgent } from "../agents/user-agent.js";
|
|
|
6
6
|
import { type LoadOptions } from "../loader/index.js";
|
|
7
7
|
import { AIGNEContext, type Context, type InvokeOptions, type UserContext } from "./context.js";
|
|
8
8
|
import { type MessagePayload, MessageQueue, type MessageQueueListener, type Unsubscribe } from "./message-queue.js";
|
|
9
|
+
import type { AIGNECLIAgents } from "./type.js";
|
|
9
10
|
import type { ContextLimits } from "./usage.js";
|
|
10
11
|
/**
|
|
11
12
|
* Options for the AIGNE class.
|
|
@@ -43,10 +44,7 @@ export interface AIGNEOptions {
|
|
|
43
44
|
mcpServer?: {
|
|
44
45
|
agents?: Agent[];
|
|
45
46
|
};
|
|
46
|
-
cli?:
|
|
47
|
-
chat?: Agent;
|
|
48
|
-
agents?: Agent[];
|
|
49
|
-
};
|
|
47
|
+
cli?: AIGNECLIAgents;
|
|
50
48
|
/**
|
|
51
49
|
* Limits for the AIGNE instance, such as timeout, max tokens, max invocations, etc.
|
|
52
50
|
*/
|
|
@@ -133,12 +131,7 @@ export declare class AIGNE<U extends UserContext = UserContext> {
|
|
|
133
131
|
[key: string]: Agent<any, any>;
|
|
134
132
|
};
|
|
135
133
|
};
|
|
136
|
-
readonly cli:
|
|
137
|
-
chat: Agent | undefined;
|
|
138
|
-
agents: Agent<any, any>[] & {
|
|
139
|
-
[key: string]: Agent<any, any>;
|
|
140
|
-
};
|
|
141
|
-
};
|
|
134
|
+
readonly cli: AIGNECLIAgents;
|
|
142
135
|
/**
|
|
143
136
|
* Observer for the AIGNE instance.
|
|
144
137
|
*/
|
package/lib/cjs/aigne/aigne.js
CHANGED
|
@@ -63,10 +63,7 @@ class AIGNE {
|
|
|
63
63
|
this.addAgent(...options.agents);
|
|
64
64
|
if (options?.mcpServer?.agents?.length)
|
|
65
65
|
this.mcpServer.agents.push(...options.mcpServer.agents);
|
|
66
|
-
|
|
67
|
-
this.cli.agents.push(...options.cli.agents);
|
|
68
|
-
if (options?.cli?.chat)
|
|
69
|
-
this.cli.chat = options.cli.chat;
|
|
66
|
+
this.cli = options?.cli ?? {};
|
|
70
67
|
this.observer?.serve();
|
|
71
68
|
this.initProcessExitHandler();
|
|
72
69
|
}
|
|
@@ -113,10 +110,7 @@ class AIGNE {
|
|
|
113
110
|
mcpServer = {
|
|
114
111
|
agents: (0, type_utils_js_1.createAccessorArray)([], (arr, name) => arr.find((i) => i.name === name)),
|
|
115
112
|
};
|
|
116
|
-
cli = {
|
|
117
|
-
chat: undefined,
|
|
118
|
-
agents: (0, type_utils_js_1.createAccessorArray)([], (arr, name) => arr.find((i) => i.name === name)),
|
|
119
|
-
};
|
|
113
|
+
cli = {};
|
|
120
114
|
/**
|
|
121
115
|
* Observer for the AIGNE instance.
|
|
122
116
|
*/
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import type { Agent } from "../agents/agent.ts";
|
|
2
|
+
export interface AIGNECLIAgents {
|
|
3
|
+
chat?: Agent;
|
|
4
|
+
agents?: AIGNECLIAgent[];
|
|
5
|
+
}
|
|
6
|
+
export interface AIGNECLIAgent {
|
|
7
|
+
agent?: Agent;
|
|
8
|
+
name?: string;
|
|
9
|
+
alias?: string[];
|
|
10
|
+
description?: string;
|
|
11
|
+
agents?: AIGNECLIAgent[];
|
|
12
|
+
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { z } from "zod";
|
|
1
|
+
import { type ZodType, z } from "zod";
|
|
2
2
|
import { Agent, type AgentOptions } from "../agents/agent.js";
|
|
3
3
|
import type { ChatModel } from "../agents/chat-model.js";
|
|
4
4
|
import type { ImageModel } from "../agents/image-model.js";
|
|
@@ -14,10 +14,17 @@ export interface LoadOptions {
|
|
|
14
14
|
}
|
|
15
15
|
export declare function load(path: string, options?: LoadOptions): Promise<AIGNEOptions>;
|
|
16
16
|
export declare function loadAgent(path: string, options?: LoadOptions, agentOptions?: AgentOptions): Promise<Agent>;
|
|
17
|
+
type CliAgent = string | {
|
|
18
|
+
url?: string;
|
|
19
|
+
name?: string;
|
|
20
|
+
alias?: string[];
|
|
21
|
+
description?: string;
|
|
22
|
+
agents?: CliAgent[];
|
|
23
|
+
};
|
|
17
24
|
declare const aigneFileSchema: z.ZodObject<{
|
|
18
|
-
name:
|
|
19
|
-
description:
|
|
20
|
-
model:
|
|
25
|
+
name: ZodType<string | undefined, z.ZodTypeDef, string | undefined>;
|
|
26
|
+
description: ZodType<string | undefined, z.ZodTypeDef, string | undefined>;
|
|
27
|
+
model: ZodType<{
|
|
21
28
|
model?: string | undefined;
|
|
22
29
|
temperature?: number | undefined;
|
|
23
30
|
topP?: number | undefined;
|
|
@@ -30,23 +37,23 @@ declare const aigneFileSchema: z.ZodObject<{
|
|
|
30
37
|
frequencyPenalty?: number | undefined;
|
|
31
38
|
presencePenalty?: number | undefined;
|
|
32
39
|
} | undefined>;
|
|
33
|
-
imageModel:
|
|
40
|
+
imageModel: ZodType<{
|
|
34
41
|
model?: string | undefined;
|
|
35
42
|
} | undefined, z.ZodTypeDef, {
|
|
36
43
|
model?: string | undefined;
|
|
37
44
|
} | undefined>;
|
|
38
|
-
agents:
|
|
39
|
-
skills:
|
|
40
|
-
mcpServer:
|
|
45
|
+
agents: ZodType<string[] | undefined, z.ZodTypeDef, string[] | undefined>;
|
|
46
|
+
skills: ZodType<string[] | undefined, z.ZodTypeDef, string[] | undefined>;
|
|
47
|
+
mcpServer: ZodType<{
|
|
41
48
|
agents?: string[] | undefined;
|
|
42
49
|
} | undefined, z.ZodTypeDef, {
|
|
43
50
|
agents?: string[] | undefined;
|
|
44
51
|
} | undefined>;
|
|
45
|
-
cli:
|
|
46
|
-
agents?:
|
|
52
|
+
cli: ZodType<{
|
|
53
|
+
agents?: CliAgent[] | undefined;
|
|
47
54
|
chat?: string | undefined;
|
|
48
55
|
} | undefined, z.ZodTypeDef, {
|
|
49
|
-
agents?:
|
|
56
|
+
agents?: CliAgent[] | undefined;
|
|
50
57
|
chat?: string | undefined;
|
|
51
58
|
} | undefined>;
|
|
52
59
|
}, "strip", z.ZodTypeAny, {
|
|
@@ -68,7 +75,7 @@ declare const aigneFileSchema: z.ZodObject<{
|
|
|
68
75
|
agents?: string[] | undefined;
|
|
69
76
|
} | undefined;
|
|
70
77
|
cli?: {
|
|
71
|
-
agents?:
|
|
78
|
+
agents?: CliAgent[] | undefined;
|
|
72
79
|
chat?: string | undefined;
|
|
73
80
|
} | undefined;
|
|
74
81
|
}, {
|
|
@@ -90,7 +97,7 @@ declare const aigneFileSchema: z.ZodObject<{
|
|
|
90
97
|
agents?: string[] | undefined;
|
|
91
98
|
} | undefined;
|
|
92
99
|
cli?: {
|
|
93
|
-
agents?:
|
|
100
|
+
agents?: CliAgent[] | undefined;
|
|
94
101
|
chat?: string | undefined;
|
|
95
102
|
} | undefined;
|
|
96
103
|
}>;
|
package/lib/cjs/loader/index.js
CHANGED
|
@@ -21,12 +21,27 @@ const schema_js_1 = require("./schema.js");
|
|
|
21
21
|
const AIGNE_FILE_NAME = ["aigne.yaml", "aigne.yml"];
|
|
22
22
|
async function load(path, options = {}) {
|
|
23
23
|
const { aigne, rootDir } = await loadAIGNEFile(path);
|
|
24
|
-
const
|
|
24
|
+
const flatCliAgents = (cliAgent) => {
|
|
25
|
+
if (typeof cliAgent === "string")
|
|
26
|
+
return [cliAgent];
|
|
27
|
+
return (0, type_utils_js_1.flat)(cliAgent.url, cliAgent.agents?.flatMap(flatCliAgents));
|
|
28
|
+
};
|
|
29
|
+
const allAgentPaths = new Set((0, type_utils_js_1.flat)(aigne.agents, aigne.skills, aigne.mcpServer?.agents, aigne.cli?.chat, aigne.cli?.agents?.flatMap((i) => (typeof i === "string" ? i : flatCliAgents(i)))).map((i) => index_js_1.nodejs.path.join(rootDir, i)));
|
|
25
30
|
const allAgents = {};
|
|
26
31
|
for (const path of allAgentPaths) {
|
|
27
32
|
allAgents[path] = await loadAgent(path, options);
|
|
28
33
|
}
|
|
29
|
-
const
|
|
34
|
+
const pickAgent = (path) => allAgents[index_js_1.nodejs.path.join(rootDir, path)];
|
|
35
|
+
const pickAgents = (paths) => paths.map((filename) => pickAgent(filename)).filter(type_utils_js_1.isNonNullable);
|
|
36
|
+
const mapCliAgents = (cliAgent) => {
|
|
37
|
+
if (typeof cliAgent === "string")
|
|
38
|
+
return { agent: pickAgent(cliAgent) };
|
|
39
|
+
return {
|
|
40
|
+
...cliAgent,
|
|
41
|
+
agent: cliAgent.url ? pickAgent(cliAgent.url) : undefined,
|
|
42
|
+
agents: cliAgent.agents?.map(mapCliAgents),
|
|
43
|
+
};
|
|
44
|
+
};
|
|
30
45
|
return {
|
|
31
46
|
...aigne,
|
|
32
47
|
rootDir,
|
|
@@ -41,7 +56,7 @@ async function load(path, options = {}) {
|
|
|
41
56
|
},
|
|
42
57
|
cli: {
|
|
43
58
|
chat: aigne.cli?.chat ? pickAgents([aigne.cli.chat])[0] : undefined,
|
|
44
|
-
agents:
|
|
59
|
+
agents: aigne.cli?.agents?.map(mapCliAgents),
|
|
45
60
|
},
|
|
46
61
|
};
|
|
47
62
|
}
|
|
@@ -186,6 +201,16 @@ async function loadMemory(memories, provider, options) {
|
|
|
186
201
|
throw new Error(`Unsupported memory: ${provider}`);
|
|
187
202
|
return new M(options);
|
|
188
203
|
}
|
|
204
|
+
const cliAgentSchema = zod_1.z.union([
|
|
205
|
+
zod_1.z.string(),
|
|
206
|
+
zod_1.z.object({
|
|
207
|
+
url: (0, schema_js_1.optionalize)(zod_1.z.string()),
|
|
208
|
+
name: (0, schema_js_1.optionalize)(zod_1.z.string()),
|
|
209
|
+
alias: (0, schema_js_1.optionalize)(zod_1.z.array(zod_1.z.string())),
|
|
210
|
+
description: (0, schema_js_1.optionalize)(zod_1.z.string()),
|
|
211
|
+
agents: (0, schema_js_1.optionalize)(zod_1.z.array(zod_1.z.lazy(() => cliAgentSchema))),
|
|
212
|
+
}),
|
|
213
|
+
]);
|
|
189
214
|
const aigneFileSchema = (0, schema_js_1.camelizeSchema)(zod_1.z.object({
|
|
190
215
|
name: (0, schema_js_1.optionalize)(zod_1.z.string()),
|
|
191
216
|
description: (0, schema_js_1.optionalize)(zod_1.z.string()),
|
|
@@ -198,7 +223,7 @@ const aigneFileSchema = (0, schema_js_1.camelizeSchema)(zod_1.z.object({
|
|
|
198
223
|
})),
|
|
199
224
|
cli: (0, schema_js_1.optionalize)(zod_1.z.object({
|
|
200
225
|
chat: (0, schema_js_1.optionalize)(zod_1.z.string()),
|
|
201
|
-
agents: (0, schema_js_1.optionalize)(zod_1.z.array(
|
|
226
|
+
agents: (0, schema_js_1.optionalize)(zod_1.z.array(cliAgentSchema)),
|
|
202
227
|
})),
|
|
203
228
|
}));
|
|
204
229
|
async function loadAIGNEFile(path) {
|
|
@@ -1,2 +1,12 @@
|
|
|
1
1
|
import type { AgentHooks } from "../agents/agent.ts";
|
|
2
|
+
import type { AIGNECLIAgents } from "../aigne/type.js";
|
|
2
3
|
export declare function sortHooks(hooks: AgentHooks[]): AgentHooks[];
|
|
4
|
+
export interface CLIAgent<T> {
|
|
5
|
+
agent?: T;
|
|
6
|
+
name?: string;
|
|
7
|
+
alias?: string[];
|
|
8
|
+
description?: string;
|
|
9
|
+
agents?: CLIAgent<T>[];
|
|
10
|
+
}
|
|
11
|
+
export declare function mapCliAgent<A, O>({ agent, agents, ...input }: CLIAgent<A>, transform: (input: A) => O): CLIAgent<O>;
|
|
12
|
+
export declare function findCliAgent(cli: AIGNECLIAgents, parent: string[] | "*", name: string): import("../agents/agent.ts").Agent<any, any> | undefined;
|
|
@@ -1,9 +1,53 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.sortHooks = sortHooks;
|
|
4
|
+
exports.mapCliAgent = mapCliAgent;
|
|
5
|
+
exports.findCliAgent = findCliAgent;
|
|
4
6
|
const priorities = ["high", "medium", "low"];
|
|
5
7
|
function sortHooks(hooks) {
|
|
6
8
|
return hooks
|
|
7
9
|
.slice(0)
|
|
8
10
|
.sort(({ priority: a = "low" }, { priority: b = "low" }) => a === b ? 0 : priorities.indexOf(a) - priorities.indexOf(b));
|
|
9
11
|
}
|
|
12
|
+
function mapCliAgent({ agent, agents, ...input }, transform) {
|
|
13
|
+
return {
|
|
14
|
+
...input,
|
|
15
|
+
agent: agent ? transform(agent) : undefined,
|
|
16
|
+
agents: agents?.map((item) => mapCliAgent(item, transform)),
|
|
17
|
+
};
|
|
18
|
+
}
|
|
19
|
+
function findCliAgent(cli, parent, name) {
|
|
20
|
+
if (parent === "*")
|
|
21
|
+
return findCliAgentRecursive(cli, name);
|
|
22
|
+
let currentAgents = cli.agents ?? [];
|
|
23
|
+
for (const name of parent) {
|
|
24
|
+
const found = currentAgents.find((i) => (i.name || i.agent?.name) === name);
|
|
25
|
+
if (!found)
|
|
26
|
+
throw new Error(`Agent ${name} not found in parent path ${parent.join(" -> ")}`);
|
|
27
|
+
if (found.agents)
|
|
28
|
+
currentAgents = found.agents;
|
|
29
|
+
else
|
|
30
|
+
currentAgents = [];
|
|
31
|
+
}
|
|
32
|
+
return currentAgents.find((i) => (i.name || i.agent?.name) === name)?.agent;
|
|
33
|
+
}
|
|
34
|
+
function findCliAgentRecursive(agents, name) {
|
|
35
|
+
if (agents.chat?.name === name) {
|
|
36
|
+
return agents.chat;
|
|
37
|
+
}
|
|
38
|
+
if (agents.agents) {
|
|
39
|
+
const queue = [...agents.agents];
|
|
40
|
+
while (queue.length > 0) {
|
|
41
|
+
const c = queue.shift();
|
|
42
|
+
if (!c)
|
|
43
|
+
break;
|
|
44
|
+
if ((c.name || c.agent?.name) === name) {
|
|
45
|
+
return c.agent;
|
|
46
|
+
}
|
|
47
|
+
if (c.agents) {
|
|
48
|
+
queue.push(...c.agents);
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
return undefined;
|
|
53
|
+
}
|
package/lib/dts/aigne/aigne.d.ts
CHANGED
|
@@ -6,6 +6,7 @@ import type { UserAgent } from "../agents/user-agent.js";
|
|
|
6
6
|
import { type LoadOptions } from "../loader/index.js";
|
|
7
7
|
import { AIGNEContext, type Context, type InvokeOptions, type UserContext } from "./context.js";
|
|
8
8
|
import { type MessagePayload, MessageQueue, type MessageQueueListener, type Unsubscribe } from "./message-queue.js";
|
|
9
|
+
import type { AIGNECLIAgents } from "./type.js";
|
|
9
10
|
import type { ContextLimits } from "./usage.js";
|
|
10
11
|
/**
|
|
11
12
|
* Options for the AIGNE class.
|
|
@@ -43,10 +44,7 @@ export interface AIGNEOptions {
|
|
|
43
44
|
mcpServer?: {
|
|
44
45
|
agents?: Agent[];
|
|
45
46
|
};
|
|
46
|
-
cli?:
|
|
47
|
-
chat?: Agent;
|
|
48
|
-
agents?: Agent[];
|
|
49
|
-
};
|
|
47
|
+
cli?: AIGNECLIAgents;
|
|
50
48
|
/**
|
|
51
49
|
* Limits for the AIGNE instance, such as timeout, max tokens, max invocations, etc.
|
|
52
50
|
*/
|
|
@@ -133,12 +131,7 @@ export declare class AIGNE<U extends UserContext = UserContext> {
|
|
|
133
131
|
[key: string]: Agent<any, any>;
|
|
134
132
|
};
|
|
135
133
|
};
|
|
136
|
-
readonly cli:
|
|
137
|
-
chat: Agent | undefined;
|
|
138
|
-
agents: Agent<any, any>[] & {
|
|
139
|
-
[key: string]: Agent<any, any>;
|
|
140
|
-
};
|
|
141
|
-
};
|
|
134
|
+
readonly cli: AIGNECLIAgents;
|
|
142
135
|
/**
|
|
143
136
|
* Observer for the AIGNE instance.
|
|
144
137
|
*/
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import type { Agent } from "../agents/agent.ts";
|
|
2
|
+
export interface AIGNECLIAgents {
|
|
3
|
+
chat?: Agent;
|
|
4
|
+
agents?: AIGNECLIAgent[];
|
|
5
|
+
}
|
|
6
|
+
export interface AIGNECLIAgent {
|
|
7
|
+
agent?: Agent;
|
|
8
|
+
name?: string;
|
|
9
|
+
alias?: string[];
|
|
10
|
+
description?: string;
|
|
11
|
+
agents?: AIGNECLIAgent[];
|
|
12
|
+
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { z } from "zod";
|
|
1
|
+
import { type ZodType, z } from "zod";
|
|
2
2
|
import { Agent, type AgentOptions } from "../agents/agent.js";
|
|
3
3
|
import type { ChatModel } from "../agents/chat-model.js";
|
|
4
4
|
import type { ImageModel } from "../agents/image-model.js";
|
|
@@ -14,10 +14,17 @@ export interface LoadOptions {
|
|
|
14
14
|
}
|
|
15
15
|
export declare function load(path: string, options?: LoadOptions): Promise<AIGNEOptions>;
|
|
16
16
|
export declare function loadAgent(path: string, options?: LoadOptions, agentOptions?: AgentOptions): Promise<Agent>;
|
|
17
|
+
type CliAgent = string | {
|
|
18
|
+
url?: string;
|
|
19
|
+
name?: string;
|
|
20
|
+
alias?: string[];
|
|
21
|
+
description?: string;
|
|
22
|
+
agents?: CliAgent[];
|
|
23
|
+
};
|
|
17
24
|
declare const aigneFileSchema: z.ZodObject<{
|
|
18
|
-
name:
|
|
19
|
-
description:
|
|
20
|
-
model:
|
|
25
|
+
name: ZodType<string | undefined, z.ZodTypeDef, string | undefined>;
|
|
26
|
+
description: ZodType<string | undefined, z.ZodTypeDef, string | undefined>;
|
|
27
|
+
model: ZodType<{
|
|
21
28
|
model?: string | undefined;
|
|
22
29
|
temperature?: number | undefined;
|
|
23
30
|
topP?: number | undefined;
|
|
@@ -30,23 +37,23 @@ declare const aigneFileSchema: z.ZodObject<{
|
|
|
30
37
|
frequencyPenalty?: number | undefined;
|
|
31
38
|
presencePenalty?: number | undefined;
|
|
32
39
|
} | undefined>;
|
|
33
|
-
imageModel:
|
|
40
|
+
imageModel: ZodType<{
|
|
34
41
|
model?: string | undefined;
|
|
35
42
|
} | undefined, z.ZodTypeDef, {
|
|
36
43
|
model?: string | undefined;
|
|
37
44
|
} | undefined>;
|
|
38
|
-
agents:
|
|
39
|
-
skills:
|
|
40
|
-
mcpServer:
|
|
45
|
+
agents: ZodType<string[] | undefined, z.ZodTypeDef, string[] | undefined>;
|
|
46
|
+
skills: ZodType<string[] | undefined, z.ZodTypeDef, string[] | undefined>;
|
|
47
|
+
mcpServer: ZodType<{
|
|
41
48
|
agents?: string[] | undefined;
|
|
42
49
|
} | undefined, z.ZodTypeDef, {
|
|
43
50
|
agents?: string[] | undefined;
|
|
44
51
|
} | undefined>;
|
|
45
|
-
cli:
|
|
46
|
-
agents?:
|
|
52
|
+
cli: ZodType<{
|
|
53
|
+
agents?: CliAgent[] | undefined;
|
|
47
54
|
chat?: string | undefined;
|
|
48
55
|
} | undefined, z.ZodTypeDef, {
|
|
49
|
-
agents?:
|
|
56
|
+
agents?: CliAgent[] | undefined;
|
|
50
57
|
chat?: string | undefined;
|
|
51
58
|
} | undefined>;
|
|
52
59
|
}, "strip", z.ZodTypeAny, {
|
|
@@ -68,7 +75,7 @@ declare const aigneFileSchema: z.ZodObject<{
|
|
|
68
75
|
agents?: string[] | undefined;
|
|
69
76
|
} | undefined;
|
|
70
77
|
cli?: {
|
|
71
|
-
agents?:
|
|
78
|
+
agents?: CliAgent[] | undefined;
|
|
72
79
|
chat?: string | undefined;
|
|
73
80
|
} | undefined;
|
|
74
81
|
}, {
|
|
@@ -90,7 +97,7 @@ declare const aigneFileSchema: z.ZodObject<{
|
|
|
90
97
|
agents?: string[] | undefined;
|
|
91
98
|
} | undefined;
|
|
92
99
|
cli?: {
|
|
93
|
-
agents?:
|
|
100
|
+
agents?: CliAgent[] | undefined;
|
|
94
101
|
chat?: string | undefined;
|
|
95
102
|
} | undefined;
|
|
96
103
|
}>;
|
|
@@ -1,2 +1,12 @@
|
|
|
1
1
|
import type { AgentHooks } from "../agents/agent.ts";
|
|
2
|
+
import type { AIGNECLIAgents } from "../aigne/type.js";
|
|
2
3
|
export declare function sortHooks(hooks: AgentHooks[]): AgentHooks[];
|
|
4
|
+
export interface CLIAgent<T> {
|
|
5
|
+
agent?: T;
|
|
6
|
+
name?: string;
|
|
7
|
+
alias?: string[];
|
|
8
|
+
description?: string;
|
|
9
|
+
agents?: CLIAgent<T>[];
|
|
10
|
+
}
|
|
11
|
+
export declare function mapCliAgent<A, O>({ agent, agents, ...input }: CLIAgent<A>, transform: (input: A) => O): CLIAgent<O>;
|
|
12
|
+
export declare function findCliAgent(cli: AIGNECLIAgents, parent: string[] | "*", name: string): import("../agents/agent.ts").Agent<any, any> | undefined;
|
package/lib/esm/aigne/aigne.d.ts
CHANGED
|
@@ -6,6 +6,7 @@ import type { UserAgent } from "../agents/user-agent.js";
|
|
|
6
6
|
import { type LoadOptions } from "../loader/index.js";
|
|
7
7
|
import { AIGNEContext, type Context, type InvokeOptions, type UserContext } from "./context.js";
|
|
8
8
|
import { type MessagePayload, MessageQueue, type MessageQueueListener, type Unsubscribe } from "./message-queue.js";
|
|
9
|
+
import type { AIGNECLIAgents } from "./type.js";
|
|
9
10
|
import type { ContextLimits } from "./usage.js";
|
|
10
11
|
/**
|
|
11
12
|
* Options for the AIGNE class.
|
|
@@ -43,10 +44,7 @@ export interface AIGNEOptions {
|
|
|
43
44
|
mcpServer?: {
|
|
44
45
|
agents?: Agent[];
|
|
45
46
|
};
|
|
46
|
-
cli?:
|
|
47
|
-
chat?: Agent;
|
|
48
|
-
agents?: Agent[];
|
|
49
|
-
};
|
|
47
|
+
cli?: AIGNECLIAgents;
|
|
50
48
|
/**
|
|
51
49
|
* Limits for the AIGNE instance, such as timeout, max tokens, max invocations, etc.
|
|
52
50
|
*/
|
|
@@ -133,12 +131,7 @@ export declare class AIGNE<U extends UserContext = UserContext> {
|
|
|
133
131
|
[key: string]: Agent<any, any>;
|
|
134
132
|
};
|
|
135
133
|
};
|
|
136
|
-
readonly cli:
|
|
137
|
-
chat: Agent | undefined;
|
|
138
|
-
agents: Agent<any, any>[] & {
|
|
139
|
-
[key: string]: Agent<any, any>;
|
|
140
|
-
};
|
|
141
|
-
};
|
|
134
|
+
readonly cli: AIGNECLIAgents;
|
|
142
135
|
/**
|
|
143
136
|
* Observer for the AIGNE instance.
|
|
144
137
|
*/
|
package/lib/esm/aigne/aigne.js
CHANGED
|
@@ -60,10 +60,7 @@ export class AIGNE {
|
|
|
60
60
|
this.addAgent(...options.agents);
|
|
61
61
|
if (options?.mcpServer?.agents?.length)
|
|
62
62
|
this.mcpServer.agents.push(...options.mcpServer.agents);
|
|
63
|
-
|
|
64
|
-
this.cli.agents.push(...options.cli.agents);
|
|
65
|
-
if (options?.cli?.chat)
|
|
66
|
-
this.cli.chat = options.cli.chat;
|
|
63
|
+
this.cli = options?.cli ?? {};
|
|
67
64
|
this.observer?.serve();
|
|
68
65
|
this.initProcessExitHandler();
|
|
69
66
|
}
|
|
@@ -110,10 +107,7 @@ export class AIGNE {
|
|
|
110
107
|
mcpServer = {
|
|
111
108
|
agents: createAccessorArray([], (arr, name) => arr.find((i) => i.name === name)),
|
|
112
109
|
};
|
|
113
|
-
cli = {
|
|
114
|
-
chat: undefined,
|
|
115
|
-
agents: createAccessorArray([], (arr, name) => arr.find((i) => i.name === name)),
|
|
116
|
-
};
|
|
110
|
+
cli = {};
|
|
117
111
|
/**
|
|
118
112
|
* Observer for the AIGNE instance.
|
|
119
113
|
*/
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import type { Agent } from "../agents/agent.ts";
|
|
2
|
+
export interface AIGNECLIAgents {
|
|
3
|
+
chat?: Agent;
|
|
4
|
+
agents?: AIGNECLIAgent[];
|
|
5
|
+
}
|
|
6
|
+
export interface AIGNECLIAgent {
|
|
7
|
+
agent?: Agent;
|
|
8
|
+
name?: string;
|
|
9
|
+
alias?: string[];
|
|
10
|
+
description?: string;
|
|
11
|
+
agents?: AIGNECLIAgent[];
|
|
12
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { z } from "zod";
|
|
1
|
+
import { type ZodType, z } from "zod";
|
|
2
2
|
import { Agent, type AgentOptions } from "../agents/agent.js";
|
|
3
3
|
import type { ChatModel } from "../agents/chat-model.js";
|
|
4
4
|
import type { ImageModel } from "../agents/image-model.js";
|
|
@@ -14,10 +14,17 @@ export interface LoadOptions {
|
|
|
14
14
|
}
|
|
15
15
|
export declare function load(path: string, options?: LoadOptions): Promise<AIGNEOptions>;
|
|
16
16
|
export declare function loadAgent(path: string, options?: LoadOptions, agentOptions?: AgentOptions): Promise<Agent>;
|
|
17
|
+
type CliAgent = string | {
|
|
18
|
+
url?: string;
|
|
19
|
+
name?: string;
|
|
20
|
+
alias?: string[];
|
|
21
|
+
description?: string;
|
|
22
|
+
agents?: CliAgent[];
|
|
23
|
+
};
|
|
17
24
|
declare const aigneFileSchema: z.ZodObject<{
|
|
18
|
-
name:
|
|
19
|
-
description:
|
|
20
|
-
model:
|
|
25
|
+
name: ZodType<string | undefined, z.ZodTypeDef, string | undefined>;
|
|
26
|
+
description: ZodType<string | undefined, z.ZodTypeDef, string | undefined>;
|
|
27
|
+
model: ZodType<{
|
|
21
28
|
model?: string | undefined;
|
|
22
29
|
temperature?: number | undefined;
|
|
23
30
|
topP?: number | undefined;
|
|
@@ -30,23 +37,23 @@ declare const aigneFileSchema: z.ZodObject<{
|
|
|
30
37
|
frequencyPenalty?: number | undefined;
|
|
31
38
|
presencePenalty?: number | undefined;
|
|
32
39
|
} | undefined>;
|
|
33
|
-
imageModel:
|
|
40
|
+
imageModel: ZodType<{
|
|
34
41
|
model?: string | undefined;
|
|
35
42
|
} | undefined, z.ZodTypeDef, {
|
|
36
43
|
model?: string | undefined;
|
|
37
44
|
} | undefined>;
|
|
38
|
-
agents:
|
|
39
|
-
skills:
|
|
40
|
-
mcpServer:
|
|
45
|
+
agents: ZodType<string[] | undefined, z.ZodTypeDef, string[] | undefined>;
|
|
46
|
+
skills: ZodType<string[] | undefined, z.ZodTypeDef, string[] | undefined>;
|
|
47
|
+
mcpServer: ZodType<{
|
|
41
48
|
agents?: string[] | undefined;
|
|
42
49
|
} | undefined, z.ZodTypeDef, {
|
|
43
50
|
agents?: string[] | undefined;
|
|
44
51
|
} | undefined>;
|
|
45
|
-
cli:
|
|
46
|
-
agents?:
|
|
52
|
+
cli: ZodType<{
|
|
53
|
+
agents?: CliAgent[] | undefined;
|
|
47
54
|
chat?: string | undefined;
|
|
48
55
|
} | undefined, z.ZodTypeDef, {
|
|
49
|
-
agents?:
|
|
56
|
+
agents?: CliAgent[] | undefined;
|
|
50
57
|
chat?: string | undefined;
|
|
51
58
|
} | undefined>;
|
|
52
59
|
}, "strip", z.ZodTypeAny, {
|
|
@@ -68,7 +75,7 @@ declare const aigneFileSchema: z.ZodObject<{
|
|
|
68
75
|
agents?: string[] | undefined;
|
|
69
76
|
} | undefined;
|
|
70
77
|
cli?: {
|
|
71
|
-
agents?:
|
|
78
|
+
agents?: CliAgent[] | undefined;
|
|
72
79
|
chat?: string | undefined;
|
|
73
80
|
} | undefined;
|
|
74
81
|
}, {
|
|
@@ -90,7 +97,7 @@ declare const aigneFileSchema: z.ZodObject<{
|
|
|
90
97
|
agents?: string[] | undefined;
|
|
91
98
|
} | undefined;
|
|
92
99
|
cli?: {
|
|
93
|
-
agents?:
|
|
100
|
+
agents?: CliAgent[] | undefined;
|
|
94
101
|
chat?: string | undefined;
|
|
95
102
|
} | undefined;
|
|
96
103
|
}>;
|
package/lib/esm/loader/index.js
CHANGED
|
@@ -16,12 +16,27 @@ import { camelizeSchema, chatModelSchema, imageModelSchema, optionalize } from "
|
|
|
16
16
|
const AIGNE_FILE_NAME = ["aigne.yaml", "aigne.yml"];
|
|
17
17
|
export async function load(path, options = {}) {
|
|
18
18
|
const { aigne, rootDir } = await loadAIGNEFile(path);
|
|
19
|
-
const
|
|
19
|
+
const flatCliAgents = (cliAgent) => {
|
|
20
|
+
if (typeof cliAgent === "string")
|
|
21
|
+
return [cliAgent];
|
|
22
|
+
return flat(cliAgent.url, cliAgent.agents?.flatMap(flatCliAgents));
|
|
23
|
+
};
|
|
24
|
+
const allAgentPaths = new Set(flat(aigne.agents, aigne.skills, aigne.mcpServer?.agents, aigne.cli?.chat, aigne.cli?.agents?.flatMap((i) => (typeof i === "string" ? i : flatCliAgents(i)))).map((i) => nodejs.path.join(rootDir, i)));
|
|
20
25
|
const allAgents = {};
|
|
21
26
|
for (const path of allAgentPaths) {
|
|
22
27
|
allAgents[path] = await loadAgent(path, options);
|
|
23
28
|
}
|
|
24
|
-
const
|
|
29
|
+
const pickAgent = (path) => allAgents[nodejs.path.join(rootDir, path)];
|
|
30
|
+
const pickAgents = (paths) => paths.map((filename) => pickAgent(filename)).filter(isNonNullable);
|
|
31
|
+
const mapCliAgents = (cliAgent) => {
|
|
32
|
+
if (typeof cliAgent === "string")
|
|
33
|
+
return { agent: pickAgent(cliAgent) };
|
|
34
|
+
return {
|
|
35
|
+
...cliAgent,
|
|
36
|
+
agent: cliAgent.url ? pickAgent(cliAgent.url) : undefined,
|
|
37
|
+
agents: cliAgent.agents?.map(mapCliAgents),
|
|
38
|
+
};
|
|
39
|
+
};
|
|
25
40
|
return {
|
|
26
41
|
...aigne,
|
|
27
42
|
rootDir,
|
|
@@ -36,7 +51,7 @@ export async function load(path, options = {}) {
|
|
|
36
51
|
},
|
|
37
52
|
cli: {
|
|
38
53
|
chat: aigne.cli?.chat ? pickAgents([aigne.cli.chat])[0] : undefined,
|
|
39
|
-
agents:
|
|
54
|
+
agents: aigne.cli?.agents?.map(mapCliAgents),
|
|
40
55
|
},
|
|
41
56
|
};
|
|
42
57
|
}
|
|
@@ -181,6 +196,16 @@ async function loadMemory(memories, provider, options) {
|
|
|
181
196
|
throw new Error(`Unsupported memory: ${provider}`);
|
|
182
197
|
return new M(options);
|
|
183
198
|
}
|
|
199
|
+
const cliAgentSchema = z.union([
|
|
200
|
+
z.string(),
|
|
201
|
+
z.object({
|
|
202
|
+
url: optionalize(z.string()),
|
|
203
|
+
name: optionalize(z.string()),
|
|
204
|
+
alias: optionalize(z.array(z.string())),
|
|
205
|
+
description: optionalize(z.string()),
|
|
206
|
+
agents: optionalize(z.array(z.lazy(() => cliAgentSchema))),
|
|
207
|
+
}),
|
|
208
|
+
]);
|
|
184
209
|
const aigneFileSchema = camelizeSchema(z.object({
|
|
185
210
|
name: optionalize(z.string()),
|
|
186
211
|
description: optionalize(z.string()),
|
|
@@ -193,7 +218,7 @@ const aigneFileSchema = camelizeSchema(z.object({
|
|
|
193
218
|
})),
|
|
194
219
|
cli: optionalize(z.object({
|
|
195
220
|
chat: optionalize(z.string()),
|
|
196
|
-
agents: optionalize(z.array(
|
|
221
|
+
agents: optionalize(z.array(cliAgentSchema)),
|
|
197
222
|
})),
|
|
198
223
|
}));
|
|
199
224
|
export async function loadAIGNEFile(path) {
|
|
@@ -1,2 +1,12 @@
|
|
|
1
1
|
import type { AgentHooks } from "../agents/agent.ts";
|
|
2
|
+
import type { AIGNECLIAgents } from "../aigne/type.js";
|
|
2
3
|
export declare function sortHooks(hooks: AgentHooks[]): AgentHooks[];
|
|
4
|
+
export interface CLIAgent<T> {
|
|
5
|
+
agent?: T;
|
|
6
|
+
name?: string;
|
|
7
|
+
alias?: string[];
|
|
8
|
+
description?: string;
|
|
9
|
+
agents?: CLIAgent<T>[];
|
|
10
|
+
}
|
|
11
|
+
export declare function mapCliAgent<A, O>({ agent, agents, ...input }: CLIAgent<A>, transform: (input: A) => O): CLIAgent<O>;
|
|
12
|
+
export declare function findCliAgent(cli: AIGNECLIAgents, parent: string[] | "*", name: string): import("../agents/agent.ts").Agent<any, any> | undefined;
|
|
@@ -4,3 +4,45 @@ export function sortHooks(hooks) {
|
|
|
4
4
|
.slice(0)
|
|
5
5
|
.sort(({ priority: a = "low" }, { priority: b = "low" }) => a === b ? 0 : priorities.indexOf(a) - priorities.indexOf(b));
|
|
6
6
|
}
|
|
7
|
+
export function mapCliAgent({ agent, agents, ...input }, transform) {
|
|
8
|
+
return {
|
|
9
|
+
...input,
|
|
10
|
+
agent: agent ? transform(agent) : undefined,
|
|
11
|
+
agents: agents?.map((item) => mapCliAgent(item, transform)),
|
|
12
|
+
};
|
|
13
|
+
}
|
|
14
|
+
export function findCliAgent(cli, parent, name) {
|
|
15
|
+
if (parent === "*")
|
|
16
|
+
return findCliAgentRecursive(cli, name);
|
|
17
|
+
let currentAgents = cli.agents ?? [];
|
|
18
|
+
for (const name of parent) {
|
|
19
|
+
const found = currentAgents.find((i) => (i.name || i.agent?.name) === name);
|
|
20
|
+
if (!found)
|
|
21
|
+
throw new Error(`Agent ${name} not found in parent path ${parent.join(" -> ")}`);
|
|
22
|
+
if (found.agents)
|
|
23
|
+
currentAgents = found.agents;
|
|
24
|
+
else
|
|
25
|
+
currentAgents = [];
|
|
26
|
+
}
|
|
27
|
+
return currentAgents.find((i) => (i.name || i.agent?.name) === name)?.agent;
|
|
28
|
+
}
|
|
29
|
+
function findCliAgentRecursive(agents, name) {
|
|
30
|
+
if (agents.chat?.name === name) {
|
|
31
|
+
return agents.chat;
|
|
32
|
+
}
|
|
33
|
+
if (agents.agents) {
|
|
34
|
+
const queue = [...agents.agents];
|
|
35
|
+
while (queue.length > 0) {
|
|
36
|
+
const c = queue.shift();
|
|
37
|
+
if (!c)
|
|
38
|
+
break;
|
|
39
|
+
if ((c.name || c.agent?.name) === name) {
|
|
40
|
+
return c.agent;
|
|
41
|
+
}
|
|
42
|
+
if (c.agents) {
|
|
43
|
+
queue.push(...c.agents);
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
return undefined;
|
|
48
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@aigne/core",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.62.0-beta",
|
|
4
4
|
"description": "The functional core of agentic AI",
|
|
5
5
|
"publishConfig": {
|
|
6
6
|
"access": "public"
|
|
@@ -92,7 +92,7 @@
|
|
|
92
92
|
"zod": "^3.25.67",
|
|
93
93
|
"zod-from-json-schema": "^0.0.5",
|
|
94
94
|
"zod-to-json-schema": "^3.24.6",
|
|
95
|
-
"@aigne/observability-api": "^0.11.
|
|
95
|
+
"@aigne/observability-api": "^0.11.1-beta",
|
|
96
96
|
"@aigne/platform-helpers": "^0.6.3"
|
|
97
97
|
},
|
|
98
98
|
"devDependencies": {
|