@aigne/core 1.59.0 → 1.60.0
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 +14 -0
- package/lib/cjs/agents/agent.d.ts +9 -0
- package/lib/cjs/agents/agent.js +13 -3
- package/lib/cjs/agents/ai-agent.d.ts +0 -12
- package/lib/cjs/agents/ai-agent.js +4 -11
- package/lib/cjs/agents/chat-model.d.ts +1 -1
- package/lib/cjs/agents/chat-model.js +1 -0
- package/lib/cjs/agents/image-agent.d.ts +1 -3
- package/lib/cjs/agents/image-agent.js +3 -6
- package/lib/cjs/agents/image-model.d.ts +1 -1
- package/lib/cjs/agents/team-agent.js +6 -3
- package/lib/cjs/agents/user-agent.js +2 -1
- package/lib/cjs/aigne/context.js +2 -0
- package/lib/cjs/loader/agent-yaml.d.ts +5 -2
- package/lib/cjs/loader/agent-yaml.js +6 -1
- package/lib/cjs/loader/index.d.ts +23 -33
- package/lib/cjs/loader/index.js +12 -24
- package/lib/cjs/loader/schema.d.ts +29 -0
- package/lib/cjs/loader/schema.js +21 -1
- package/lib/dts/agents/agent.d.ts +9 -0
- package/lib/dts/agents/ai-agent.d.ts +0 -12
- package/lib/dts/agents/chat-model.d.ts +1 -1
- package/lib/dts/agents/image-agent.d.ts +1 -3
- package/lib/dts/agents/image-model.d.ts +1 -1
- package/lib/dts/loader/agent-yaml.d.ts +5 -2
- package/lib/dts/loader/index.d.ts +23 -33
- package/lib/dts/loader/schema.d.ts +29 -0
- package/lib/esm/agents/agent.d.ts +9 -0
- package/lib/esm/agents/agent.js +13 -3
- package/lib/esm/agents/ai-agent.d.ts +0 -12
- package/lib/esm/agents/ai-agent.js +4 -11
- package/lib/esm/agents/chat-model.d.ts +1 -1
- package/lib/esm/agents/chat-model.js +1 -0
- package/lib/esm/agents/image-agent.d.ts +1 -3
- package/lib/esm/agents/image-agent.js +3 -6
- package/lib/esm/agents/image-model.d.ts +1 -1
- package/lib/esm/agents/team-agent.js +6 -3
- package/lib/esm/agents/user-agent.js +2 -1
- package/lib/esm/aigne/context.js +2 -0
- package/lib/esm/loader/agent-yaml.d.ts +5 -2
- package/lib/esm/loader/agent-yaml.js +7 -2
- package/lib/esm/loader/index.d.ts +23 -33
- package/lib/esm/loader/index.js +14 -26
- package/lib/esm/loader/schema.d.ts +29 -0
- package/lib/esm/loader/schema.js +20 -0
- package/package.json +2 -2
|
@@ -9,7 +9,7 @@ export interface LoadOptions {
|
|
|
9
9
|
memories?: {
|
|
10
10
|
new (parameters?: MemoryAgentOptions): MemoryAgent;
|
|
11
11
|
}[];
|
|
12
|
-
model?: ChatModel | ((model?: z.infer<typeof aigneFileSchema>["
|
|
12
|
+
model?: ChatModel | ((model?: z.infer<typeof aigneFileSchema>["model"]) => PromiseOrValue<ChatModel | undefined>);
|
|
13
13
|
imageModel?: ImageModel | ((model?: z.infer<typeof aigneFileSchema>["imageModel"]) => PromiseOrValue<ImageModel | undefined>);
|
|
14
14
|
key?: string | number;
|
|
15
15
|
}
|
|
@@ -18,38 +18,22 @@ export declare function loadAgent(path: string, options?: LoadOptions, agentOpti
|
|
|
18
18
|
declare const aigneFileSchema: z.ZodObject<{
|
|
19
19
|
name: z.ZodType<string | undefined, z.ZodTypeDef, string | undefined>;
|
|
20
20
|
description: z.ZodType<string | undefined, z.ZodTypeDef, string | undefined>;
|
|
21
|
-
|
|
21
|
+
model: z.ZodType<{
|
|
22
22
|
model?: string | undefined;
|
|
23
23
|
temperature?: number | undefined;
|
|
24
24
|
topP?: number | undefined;
|
|
25
25
|
frequencyPenalty?: number | undefined;
|
|
26
26
|
presencePenalty?: number | undefined;
|
|
27
|
-
} | undefined, z.ZodTypeDef,
|
|
28
|
-
model?: string | undefined;
|
|
29
|
-
temperature?: number | undefined;
|
|
30
|
-
topP?: number | undefined;
|
|
31
|
-
frequencyPenalty?: number | undefined;
|
|
32
|
-
presencePenalty?: number | undefined;
|
|
33
|
-
} | undefined>, string | {
|
|
34
|
-
model?: string | undefined;
|
|
35
|
-
temperature?: number | undefined;
|
|
36
|
-
topP?: number | undefined;
|
|
37
|
-
frequencyPenalty?: number | undefined;
|
|
38
|
-
presencePenalty?: number | undefined;
|
|
39
|
-
} | undefined, unknown>, {
|
|
27
|
+
} | undefined, z.ZodTypeDef, {
|
|
40
28
|
model?: string | undefined;
|
|
41
29
|
temperature?: number | undefined;
|
|
42
30
|
topP?: number | undefined;
|
|
43
31
|
frequencyPenalty?: number | undefined;
|
|
44
32
|
presencePenalty?: number | undefined;
|
|
45
|
-
} | undefined
|
|
46
|
-
imageModel: z.
|
|
47
|
-
model?: string | undefined;
|
|
48
|
-
} | undefined, z.ZodTypeDef, string | {
|
|
49
|
-
model?: string | undefined;
|
|
50
|
-
} | undefined>, {
|
|
33
|
+
} | undefined>;
|
|
34
|
+
imageModel: z.ZodType<{
|
|
51
35
|
model?: string | undefined;
|
|
52
|
-
} | undefined,
|
|
36
|
+
} | undefined, z.ZodTypeDef, {
|
|
53
37
|
model?: string | undefined;
|
|
54
38
|
} | undefined>;
|
|
55
39
|
agents: z.ZodType<string[] | undefined, z.ZodTypeDef, string[] | undefined>;
|
|
@@ -67,20 +51,20 @@ declare const aigneFileSchema: z.ZodObject<{
|
|
|
67
51
|
chat?: string | undefined;
|
|
68
52
|
} | undefined>;
|
|
69
53
|
}, "strip", z.ZodTypeAny, {
|
|
70
|
-
|
|
71
|
-
description?: string | undefined;
|
|
72
|
-
skills?: string[] | undefined;
|
|
73
|
-
imageModel?: {
|
|
74
|
-
model?: string | undefined;
|
|
75
|
-
} | undefined;
|
|
76
|
-
agents?: string[] | undefined;
|
|
77
|
-
chatModel?: {
|
|
54
|
+
model?: {
|
|
78
55
|
model?: string | undefined;
|
|
79
56
|
temperature?: number | undefined;
|
|
80
57
|
topP?: number | undefined;
|
|
81
58
|
frequencyPenalty?: number | undefined;
|
|
82
59
|
presencePenalty?: number | undefined;
|
|
83
60
|
} | undefined;
|
|
61
|
+
name?: string | undefined;
|
|
62
|
+
description?: string | undefined;
|
|
63
|
+
imageModel?: {
|
|
64
|
+
model?: string | undefined;
|
|
65
|
+
} | undefined;
|
|
66
|
+
skills?: string[] | undefined;
|
|
67
|
+
agents?: string[] | undefined;
|
|
84
68
|
mcpServer?: {
|
|
85
69
|
agents?: string[] | undefined;
|
|
86
70
|
} | undefined;
|
|
@@ -89,14 +73,20 @@ declare const aigneFileSchema: z.ZodObject<{
|
|
|
89
73
|
chat?: string | undefined;
|
|
90
74
|
} | undefined;
|
|
91
75
|
}, {
|
|
76
|
+
model?: {
|
|
77
|
+
model?: string | undefined;
|
|
78
|
+
temperature?: number | undefined;
|
|
79
|
+
topP?: number | undefined;
|
|
80
|
+
frequencyPenalty?: number | undefined;
|
|
81
|
+
presencePenalty?: number | undefined;
|
|
82
|
+
} | undefined;
|
|
92
83
|
name?: string | undefined;
|
|
93
84
|
description?: string | undefined;
|
|
94
|
-
|
|
95
|
-
imageModel?: string | {
|
|
85
|
+
imageModel?: {
|
|
96
86
|
model?: string | undefined;
|
|
97
87
|
} | undefined;
|
|
88
|
+
skills?: string[] | undefined;
|
|
98
89
|
agents?: string[] | undefined;
|
|
99
|
-
chatModel?: unknown;
|
|
100
90
|
mcpServer?: {
|
|
101
91
|
agents?: string[] | undefined;
|
|
102
92
|
} | undefined;
|
package/lib/esm/loader/index.js
CHANGED
|
@@ -8,10 +8,10 @@ import { MCPAgent } from "../agents/mcp-agent.js";
|
|
|
8
8
|
import { TeamAgent } from "../agents/team-agent.js";
|
|
9
9
|
import { TransformAgent } from "../agents/transform-agent.js";
|
|
10
10
|
import { PromptBuilder } from "../prompt/prompt-builder.js";
|
|
11
|
-
import { flat, isNonNullable,
|
|
11
|
+
import { flat, isNonNullable, tryOrThrow } from "../utils/type-utils.js";
|
|
12
12
|
import { loadAgentFromJsFile } from "./agent-js.js";
|
|
13
13
|
import { loadAgentFromYamlFile } from "./agent-yaml.js";
|
|
14
|
-
import { camelizeSchema, optionalize } from "./schema.js";
|
|
14
|
+
import { camelizeSchema, chatModelSchema, imageModelSchema, optionalize } from "./schema.js";
|
|
15
15
|
const AIGNE_FILE_NAME = ["aigne.yaml", "aigne.yml"];
|
|
16
16
|
export async function load(path, options = {}) {
|
|
17
17
|
options.key ??= Date.now();
|
|
@@ -22,7 +22,7 @@ export async function load(path, options = {}) {
|
|
|
22
22
|
return {
|
|
23
23
|
...aigne,
|
|
24
24
|
rootDir,
|
|
25
|
-
model: typeof options.model === "function" ? await options.model(aigne.
|
|
25
|
+
model: typeof options.model === "function" ? await options.model(aigne.model) : options.model,
|
|
26
26
|
imageModel: typeof options.imageModel === "function"
|
|
27
27
|
? await options.imageModel(aigne.imageModel)
|
|
28
28
|
: options.imageModel,
|
|
@@ -87,9 +87,17 @@ async function parseAgent(path, agent, options, agentOptions) {
|
|
|
87
87
|
const memory = "memory" in agent && options?.memories?.length
|
|
88
88
|
? await loadMemory(options.memories, typeof agent.memory === "object" ? agent.memory.provider : undefined, typeof agent.memory === "object" ? agent.memory : {})
|
|
89
89
|
: undefined;
|
|
90
|
+
const model = agent.model && typeof options?.model === "function"
|
|
91
|
+
? await options.model(agent.model)
|
|
92
|
+
: undefined;
|
|
93
|
+
const imageModel = agent.imageModel && typeof options?.imageModel === "function"
|
|
94
|
+
? await options.imageModel(agent.imageModel)
|
|
95
|
+
: undefined;
|
|
90
96
|
const baseOptions = {
|
|
91
97
|
...agentOptions,
|
|
92
98
|
...agent,
|
|
99
|
+
model,
|
|
100
|
+
imageModel,
|
|
93
101
|
skills,
|
|
94
102
|
memory,
|
|
95
103
|
hooks: [
|
|
@@ -170,28 +178,8 @@ async function loadMemory(memories, provider, options) {
|
|
|
170
178
|
const aigneFileSchema = camelizeSchema(z.object({
|
|
171
179
|
name: optionalize(z.string()),
|
|
172
180
|
description: optionalize(z.string()),
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
if (!isRecord(v))
|
|
176
|
-
return v;
|
|
177
|
-
return { ...v, model: v.model || `${v.provider || ""}:${v.name || ""}` };
|
|
178
|
-
}, optionalize(z.union([
|
|
179
|
-
z.string(),
|
|
180
|
-
camelizeSchema(z.object({
|
|
181
|
-
model: optionalize(z.string()),
|
|
182
|
-
temperature: optionalize(z.number().min(0).max(2)),
|
|
183
|
-
topP: optionalize(z.number().min(0)),
|
|
184
|
-
frequencyPenalty: optionalize(z.number().min(-2).max(2)),
|
|
185
|
-
presencePenalty: optionalize(z.number().min(-2).max(2)),
|
|
186
|
-
})),
|
|
187
|
-
])))
|
|
188
|
-
.transform((v) => (typeof v === "string" ? { model: v } : v)),
|
|
189
|
-
imageModel: optionalize(z.union([
|
|
190
|
-
z.string(),
|
|
191
|
-
camelizeSchema(z.object({
|
|
192
|
-
model: optionalize(z.string()),
|
|
193
|
-
})),
|
|
194
|
-
])).transform((v) => (typeof v === "string" ? { model: v } : v)),
|
|
181
|
+
model: optionalize(chatModelSchema),
|
|
182
|
+
imageModel: optionalize(imageModelSchema),
|
|
195
183
|
agents: optionalize(z.array(z.string())),
|
|
196
184
|
skills: optionalize(z.array(z.string())),
|
|
197
185
|
mcpServer: optionalize(z.object({
|
|
@@ -206,7 +194,7 @@ export async function loadAIGNEFile(path) {
|
|
|
206
194
|
const file = await findAIGNEFile(path);
|
|
207
195
|
const raw = await tryOrThrow(() => nodejs.fs.readFile(file, "utf8"), (error) => new Error(`Failed to load aigne.yaml from ${file}: ${error.message}`));
|
|
208
196
|
const json = tryOrThrow(() => parse(raw), (error) => new Error(`Failed to parse aigne.yaml from ${file}: ${error.message}`));
|
|
209
|
-
const aigne = tryOrThrow(() => aigneFileSchema.parse(json), (error) => new Error(`Failed to validate aigne.yaml from ${file}: ${error.message}`));
|
|
197
|
+
const aigne = tryOrThrow(() => aigneFileSchema.parse({ ...json, model: json.model || json.chatModel || json.chat_model }), (error) => new Error(`Failed to validate aigne.yaml from ${file}: ${error.message}`));
|
|
210
198
|
return { aigne, rootDir: nodejs.path.dirname(file) };
|
|
211
199
|
}
|
|
212
200
|
async function findAIGNEFile(path) {
|
|
@@ -29,7 +29,36 @@ export declare const defaultInputSchema: z.ZodRecord<z.ZodString, z.ZodUnion<[z.
|
|
|
29
29
|
}, {
|
|
30
30
|
$get: string;
|
|
31
31
|
}>, z.ZodUnknown]>>;
|
|
32
|
+
declare const chatModelObjectSchema: z.ZodObject<{
|
|
33
|
+
model: ZodType<string | undefined, z.ZodTypeDef, string | undefined>;
|
|
34
|
+
temperature: ZodType<number | undefined, z.ZodTypeDef, number | undefined>;
|
|
35
|
+
topP: ZodType<number | undefined, z.ZodTypeDef, number | undefined>;
|
|
36
|
+
frequencyPenalty: ZodType<number | undefined, z.ZodTypeDef, number | undefined>;
|
|
37
|
+
presencePenalty: ZodType<number | undefined, z.ZodTypeDef, number | undefined>;
|
|
38
|
+
}, "strip", z.ZodTypeAny, {
|
|
39
|
+
model?: string | undefined;
|
|
40
|
+
temperature?: number | undefined;
|
|
41
|
+
topP?: number | undefined;
|
|
42
|
+
frequencyPenalty?: number | undefined;
|
|
43
|
+
presencePenalty?: number | undefined;
|
|
44
|
+
}, {
|
|
45
|
+
model?: string | undefined;
|
|
46
|
+
temperature?: number | undefined;
|
|
47
|
+
topP?: number | undefined;
|
|
48
|
+
frequencyPenalty?: number | undefined;
|
|
49
|
+
presencePenalty?: number | undefined;
|
|
50
|
+
}>;
|
|
51
|
+
export declare const chatModelSchema: typeof chatModelObjectSchema;
|
|
52
|
+
declare const imageModelObjectSchema: z.ZodObject<{
|
|
53
|
+
model: ZodType<string | undefined, z.ZodTypeDef, string | undefined>;
|
|
54
|
+
}, "strip", z.ZodTypeAny, {
|
|
55
|
+
model?: string | undefined;
|
|
56
|
+
}, {
|
|
57
|
+
model?: string | undefined;
|
|
58
|
+
}>;
|
|
59
|
+
export declare const imageModelSchema: typeof imageModelObjectSchema;
|
|
32
60
|
export declare function optionalize<T>(schema: ZodType<T>): ZodType<T | undefined>;
|
|
33
61
|
export declare function camelizeSchema<T extends ZodType>(schema: T, { shallow }?: {
|
|
34
62
|
shallow?: boolean;
|
|
35
63
|
}): T;
|
|
64
|
+
export {};
|
package/lib/esm/loader/schema.js
CHANGED
|
@@ -54,6 +54,26 @@ export const defaultInputSchema = z.record(z.string(), z.union([
|
|
|
54
54
|
}),
|
|
55
55
|
z.unknown(),
|
|
56
56
|
]));
|
|
57
|
+
const chatModelObjectSchema = camelizeSchema(z.object({
|
|
58
|
+
model: optionalize(z.string()),
|
|
59
|
+
temperature: optionalize(z.number().min(0).max(2)),
|
|
60
|
+
topP: optionalize(z.number().min(0)),
|
|
61
|
+
frequencyPenalty: optionalize(z.number().min(-2).max(2)),
|
|
62
|
+
presencePenalty: optionalize(z.number().min(-2).max(2)),
|
|
63
|
+
}));
|
|
64
|
+
export const chatModelSchema = z
|
|
65
|
+
.preprocess((v) => {
|
|
66
|
+
if (!isRecord(v))
|
|
67
|
+
return v;
|
|
68
|
+
return { ...v, model: v.model || `${v.provider || ""}:${v.name || ""}` };
|
|
69
|
+
}, z.union([z.string(), chatModelObjectSchema]))
|
|
70
|
+
.transform((v) => typeof v === "string" ? { model: v } : v);
|
|
71
|
+
const imageModelObjectSchema = camelizeSchema(z.object({
|
|
72
|
+
model: optionalize(z.string()),
|
|
73
|
+
}));
|
|
74
|
+
export const imageModelSchema = z
|
|
75
|
+
.union([z.string(), imageModelObjectSchema])
|
|
76
|
+
.transform((v) => typeof v === "string" ? { model: v } : v);
|
|
57
77
|
export function optionalize(schema) {
|
|
58
78
|
return schema.nullish().transform((v) => v ?? undefined);
|
|
59
79
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@aigne/core",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.60.0",
|
|
4
4
|
"description": "The functional core of agentic AI",
|
|
5
5
|
"publishConfig": {
|
|
6
6
|
"access": "public"
|
|
@@ -92,7 +92,7 @@
|
|
|
92
92
|
"yaml": "^2.8.0",
|
|
93
93
|
"zod": "^3.25.67",
|
|
94
94
|
"zod-to-json-schema": "^3.24.6",
|
|
95
|
-
"@aigne/observability-api": "^0.10.
|
|
95
|
+
"@aigne/observability-api": "^0.10.3",
|
|
96
96
|
"@aigne/platform-helpers": "^0.6.2"
|
|
97
97
|
},
|
|
98
98
|
"devDependencies": {
|