@aigne/core 1.32.2 → 1.33.1
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 +24 -0
- package/README.md +0 -2
- package/lib/cjs/agents/chat-model.js +5 -5
- package/lib/cjs/agents/mcp-agent.js +1 -1
- package/lib/cjs/agents/team-agent.js +2 -0
- package/lib/cjs/aigne/aigne.d.ts +9 -0
- package/lib/cjs/aigne/aigne.js +7 -1
- package/lib/cjs/aigne/context.js +1 -1
- package/lib/cjs/aigne/message-queue.js +3 -3
- package/lib/cjs/loader/agent-js.js +8 -8
- package/lib/cjs/loader/agent-yaml.d.ts +2 -2
- package/lib/cjs/loader/agent-yaml.js +5 -5
- package/lib/cjs/loader/index.d.ts +44 -74
- package/lib/cjs/loader/index.js +37 -28
- package/lib/cjs/loader/schema.d.ts +9 -2
- package/lib/cjs/loader/schema.js +43 -6
- package/lib/cjs/prompt/template.js +2 -2
- package/lib/dts/aigne/aigne.d.ts +9 -0
- package/lib/dts/loader/agent-yaml.d.ts +2 -2
- package/lib/dts/loader/index.d.ts +44 -74
- package/lib/dts/loader/schema.d.ts +9 -2
- package/lib/esm/agents/chat-model.js +5 -5
- package/lib/esm/agents/mcp-agent.js +1 -1
- package/lib/esm/agents/team-agent.js +2 -0
- package/lib/esm/aigne/aigne.d.ts +9 -0
- package/lib/esm/aigne/aigne.js +7 -1
- package/lib/esm/aigne/context.js +1 -1
- package/lib/esm/aigne/message-queue.js +3 -3
- package/lib/esm/loader/agent-js.js +8 -8
- package/lib/esm/loader/agent-yaml.d.ts +2 -2
- package/lib/esm/loader/agent-yaml.js +5 -5
- package/lib/esm/loader/index.d.ts +44 -74
- package/lib/esm/loader/index.js +34 -28
- package/lib/esm/loader/schema.d.ts +9 -2
- package/lib/esm/loader/schema.js +42 -6
- package/lib/esm/prompt/template.js +2 -2
- package/package.json +6 -6
- package/README.zh.md +0 -79
|
@@ -4,8 +4,8 @@ import { ProcessMode } from "../agents/team-agent.js";
|
|
|
4
4
|
interface BaseAgentSchema {
|
|
5
5
|
name?: string;
|
|
6
6
|
description?: string;
|
|
7
|
-
inputSchema?: ZodType<Record<string,
|
|
8
|
-
outputSchema?: ZodType<Record<string,
|
|
7
|
+
inputSchema?: ZodType<Record<string, any>>;
|
|
8
|
+
outputSchema?: ZodType<Record<string, any>>;
|
|
9
9
|
skills?: (string | AgentSchema)[];
|
|
10
10
|
memory?: boolean | {
|
|
11
11
|
provider: string;
|
|
@@ -2,6 +2,7 @@ import type { Camelize } from "camelize-ts";
|
|
|
2
2
|
import { z } from "zod";
|
|
3
3
|
import { Agent } from "../agents/agent.js";
|
|
4
4
|
import type { ChatModel, ChatModelOptions } from "../agents/chat-model.js";
|
|
5
|
+
import type { AIGNEOptions } from "../aigne/aigne.js";
|
|
5
6
|
import type { MemoryAgent, MemoryAgentOptions } from "../memory/memory.js";
|
|
6
7
|
interface LoadableModelClass {
|
|
7
8
|
new (parameters: {
|
|
@@ -23,103 +24,72 @@ export interface LoadOptions {
|
|
|
23
24
|
}[];
|
|
24
25
|
path: string;
|
|
25
26
|
}
|
|
26
|
-
export declare function load(options: LoadOptions): Promise<
|
|
27
|
-
model: ChatModel | undefined;
|
|
28
|
-
agents: Agent<any, any>[];
|
|
29
|
-
skills: Agent<any, any>[];
|
|
30
|
-
name?: string | null | undefined;
|
|
31
|
-
description?: string | null | undefined;
|
|
32
|
-
chat_model?: {
|
|
33
|
-
name?: string | null | undefined;
|
|
34
|
-
temperature?: number | null | undefined;
|
|
35
|
-
provider?: string | null | undefined;
|
|
36
|
-
top_p?: number | null | undefined;
|
|
37
|
-
frequency_penalty?: number | null | undefined;
|
|
38
|
-
presence_penalty?: number | null | undefined;
|
|
39
|
-
} | null | undefined;
|
|
40
|
-
}>;
|
|
27
|
+
export declare function load(options: LoadOptions): Promise<AIGNEOptions>;
|
|
41
28
|
export declare function loadAgent(path: string, options?: LoadOptions): Promise<Agent>;
|
|
42
|
-
export declare function loadModel(models: LoadableModel[], model?: Camelize<z.infer<typeof aigneFileSchema>["
|
|
29
|
+
export declare function loadModel(models: LoadableModel[], model?: Camelize<z.infer<typeof aigneFileSchema>["model"]>, modelOptions?: ChatModelOptions): Promise<ChatModel | undefined>;
|
|
43
30
|
declare const aigneFileSchema: z.ZodObject<{
|
|
44
|
-
name: z.
|
|
45
|
-
description: z.
|
|
46
|
-
|
|
47
|
-
provider: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
48
|
-
name: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
49
|
-
temperature: z.ZodOptional<z.ZodNullable<z.ZodNumber>>;
|
|
50
|
-
top_p: z.ZodOptional<z.ZodNullable<z.ZodNumber>>;
|
|
51
|
-
frequency_penalty: z.ZodOptional<z.ZodNullable<z.ZodNumber>>;
|
|
52
|
-
presence_penalty: z.ZodOptional<z.ZodNullable<z.ZodNumber>>;
|
|
53
|
-
}, "strip", z.ZodTypeAny, {
|
|
31
|
+
name: z.ZodType<string | undefined, z.ZodTypeDef, string | undefined>;
|
|
32
|
+
description: z.ZodType<string | undefined, z.ZodTypeDef, string | undefined>;
|
|
33
|
+
model: z.ZodEffects<z.ZodType<string | {
|
|
54
34
|
name?: string | null | undefined;
|
|
55
35
|
temperature?: number | null | undefined;
|
|
36
|
+
topP?: number | null | undefined;
|
|
37
|
+
frequencyPenalty?: number | null | undefined;
|
|
38
|
+
presencePenalty?: number | null | undefined;
|
|
56
39
|
provider?: string | null | undefined;
|
|
57
|
-
|
|
58
|
-
frequency_penalty?: number | null | undefined;
|
|
59
|
-
presence_penalty?: number | null | undefined;
|
|
60
|
-
}, {
|
|
40
|
+
} | undefined, z.ZodTypeDef, string | {
|
|
61
41
|
name?: string | null | undefined;
|
|
62
42
|
temperature?: number | null | undefined;
|
|
43
|
+
topP?: number | null | undefined;
|
|
44
|
+
frequencyPenalty?: number | null | undefined;
|
|
45
|
+
presencePenalty?: number | null | undefined;
|
|
63
46
|
provider?: string | null | undefined;
|
|
64
|
-
|
|
65
|
-
frequency_penalty?: number | null | undefined;
|
|
66
|
-
presence_penalty?: number | null | undefined;
|
|
67
|
-
}>]>>>, {
|
|
47
|
+
} | undefined>, {
|
|
68
48
|
name?: string | null | undefined;
|
|
69
49
|
temperature?: number | null | undefined;
|
|
50
|
+
topP?: number | null | undefined;
|
|
51
|
+
frequencyPenalty?: number | null | undefined;
|
|
52
|
+
presencePenalty?: number | null | undefined;
|
|
70
53
|
provider?: string | null | undefined;
|
|
71
|
-
|
|
72
|
-
frequency_penalty?: number | null | undefined;
|
|
73
|
-
presence_penalty?: number | null | undefined;
|
|
74
|
-
} | null | undefined, string | {
|
|
54
|
+
} | undefined, string | {
|
|
75
55
|
name?: string | null | undefined;
|
|
76
56
|
temperature?: number | null | undefined;
|
|
57
|
+
topP?: number | null | undefined;
|
|
58
|
+
frequencyPenalty?: number | null | undefined;
|
|
59
|
+
presencePenalty?: number | null | undefined;
|
|
77
60
|
provider?: string | null | undefined;
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
} | null | undefined>;
|
|
82
|
-
agents: z.ZodOptional<z.ZodNullable<z.ZodArray<z.ZodString, "many">>>;
|
|
83
|
-
skills: z.ZodOptional<z.ZodNullable<z.ZodArray<z.ZodString, "many">>>;
|
|
61
|
+
} | undefined>;
|
|
62
|
+
agents: z.ZodType<string[] | undefined, z.ZodTypeDef, string[] | undefined>;
|
|
63
|
+
skills: z.ZodType<string[] | undefined, z.ZodTypeDef, string[] | undefined>;
|
|
84
64
|
}, "strip", z.ZodTypeAny, {
|
|
85
|
-
name?: string |
|
|
86
|
-
description?: string |
|
|
87
|
-
skills?: string[] |
|
|
88
|
-
|
|
65
|
+
name?: string | undefined;
|
|
66
|
+
description?: string | undefined;
|
|
67
|
+
skills?: string[] | undefined;
|
|
68
|
+
model?: {
|
|
89
69
|
name?: string | null | undefined;
|
|
90
70
|
temperature?: number | null | undefined;
|
|
71
|
+
topP?: number | null | undefined;
|
|
72
|
+
frequencyPenalty?: number | null | undefined;
|
|
73
|
+
presencePenalty?: number | null | undefined;
|
|
91
74
|
provider?: string | null | undefined;
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
presence_penalty?: number | null | undefined;
|
|
95
|
-
} | null | undefined;
|
|
96
|
-
agents?: string[] | null | undefined;
|
|
75
|
+
} | undefined;
|
|
76
|
+
agents?: string[] | undefined;
|
|
97
77
|
}, {
|
|
98
|
-
name?: string |
|
|
99
|
-
description?: string |
|
|
100
|
-
skills?: string[] |
|
|
101
|
-
|
|
78
|
+
name?: string | undefined;
|
|
79
|
+
description?: string | undefined;
|
|
80
|
+
skills?: string[] | undefined;
|
|
81
|
+
model?: string | {
|
|
102
82
|
name?: string | null | undefined;
|
|
103
83
|
temperature?: number | null | undefined;
|
|
84
|
+
topP?: number | null | undefined;
|
|
85
|
+
frequencyPenalty?: number | null | undefined;
|
|
86
|
+
presencePenalty?: number | null | undefined;
|
|
104
87
|
provider?: string | null | undefined;
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
presence_penalty?: number | null | undefined;
|
|
108
|
-
} | null | undefined;
|
|
109
|
-
agents?: string[] | null | undefined;
|
|
88
|
+
} | undefined;
|
|
89
|
+
agents?: string[] | undefined;
|
|
110
90
|
}>;
|
|
111
91
|
export declare function loadAIGNEFile(path: string): Promise<{
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
skills?: string[] | null | undefined;
|
|
115
|
-
chat_model?: {
|
|
116
|
-
name?: string | null | undefined;
|
|
117
|
-
temperature?: number | null | undefined;
|
|
118
|
-
provider?: string | null | undefined;
|
|
119
|
-
top_p?: number | null | undefined;
|
|
120
|
-
frequency_penalty?: number | null | undefined;
|
|
121
|
-
presence_penalty?: number | null | undefined;
|
|
122
|
-
} | null | undefined;
|
|
123
|
-
agents?: string[] | null | undefined;
|
|
92
|
+
aigne: z.infer<typeof aigneFileSchema>;
|
|
93
|
+
rootDir: string;
|
|
124
94
|
}>;
|
|
125
95
|
export {};
|
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
import { type ZodType, z } from "zod";
|
|
2
|
-
export declare const inputOutputSchema:
|
|
2
|
+
export declare const inputOutputSchema: ({ path }: {
|
|
3
|
+
path: string;
|
|
4
|
+
}) => z.ZodUnion<[ZodType<any, z.ZodTypeDef, any>, z.ZodEffects<z.ZodObject<{
|
|
3
5
|
type: z.ZodLiteral<"object">;
|
|
4
6
|
properties: z.ZodRecord<z.ZodString, z.ZodAny>;
|
|
5
7
|
required: z.ZodOptional<z.ZodArray<z.ZodString, "many">>;
|
|
@@ -14,5 +16,10 @@ export declare const inputOutputSchema: z.ZodObject<{
|
|
|
14
16
|
properties: Record<string, any>;
|
|
15
17
|
required?: string[] | undefined;
|
|
16
18
|
additionalProperties?: boolean | undefined;
|
|
17
|
-
}
|
|
19
|
+
}>, any, {
|
|
20
|
+
type: "object";
|
|
21
|
+
properties: Record<string, any>;
|
|
22
|
+
required?: string[] | undefined;
|
|
23
|
+
additionalProperties?: boolean | undefined;
|
|
24
|
+
}>]>;
|
|
18
25
|
export declare function optionalize<T>(schema: ZodType<T>): ZodType<T | undefined>;
|
|
@@ -151,7 +151,7 @@ const chatModelInputMessageSchema = z.object({
|
|
|
151
151
|
type: z.literal("function"),
|
|
152
152
|
function: z.object({
|
|
153
153
|
name: z.string(),
|
|
154
|
-
arguments: z.record(z.unknown()),
|
|
154
|
+
arguments: z.record(z.string(), z.unknown()),
|
|
155
155
|
}),
|
|
156
156
|
}))
|
|
157
157
|
.optional(),
|
|
@@ -165,7 +165,7 @@ const chatModelInputResponseFormatSchema = z.discriminatedUnion("type", [
|
|
|
165
165
|
jsonSchema: z.object({
|
|
166
166
|
name: z.string(),
|
|
167
167
|
description: z.string().optional(),
|
|
168
|
-
schema: z.record(z.unknown()),
|
|
168
|
+
schema: z.record(z.string(), z.unknown()),
|
|
169
169
|
strict: z.boolean().optional(),
|
|
170
170
|
}),
|
|
171
171
|
}),
|
|
@@ -175,7 +175,7 @@ const chatModelInputToolSchema = z.object({
|
|
|
175
175
|
function: z.object({
|
|
176
176
|
name: z.string(),
|
|
177
177
|
description: z.string().optional(),
|
|
178
|
-
parameters: z.record(z.unknown()),
|
|
178
|
+
parameters: z.record(z.string(), z.unknown()),
|
|
179
179
|
}),
|
|
180
180
|
});
|
|
181
181
|
const chatModelInputToolChoiceSchema = z.union([
|
|
@@ -204,7 +204,7 @@ const chatModelOutputToolCallSchema = z.object({
|
|
|
204
204
|
type: z.literal("function"),
|
|
205
205
|
function: z.object({
|
|
206
206
|
name: z.string(),
|
|
207
|
-
arguments: z.record(z.unknown()),
|
|
207
|
+
arguments: z.record(z.string(), z.unknown()),
|
|
208
208
|
}),
|
|
209
209
|
});
|
|
210
210
|
const chatModelOutputUsageSchema = z.object({
|
|
@@ -213,7 +213,7 @@ const chatModelOutputUsageSchema = z.object({
|
|
|
213
213
|
});
|
|
214
214
|
const chatModelOutputSchema = z.object({
|
|
215
215
|
text: z.string().optional(),
|
|
216
|
-
json: z.record(z.unknown()).optional(),
|
|
216
|
+
json: z.record(z.string(), z.unknown()).optional(),
|
|
217
217
|
toolCalls: z.array(chatModelOutputToolCallSchema).optional(),
|
|
218
218
|
usage: chatModelOutputUsageSchema.optional(),
|
|
219
219
|
model: z.string().optional(),
|
|
@@ -111,6 +111,8 @@ export class TeamAgent extends Agent {
|
|
|
111
111
|
* @returns A stream of message chunks that collectively form the response
|
|
112
112
|
*/
|
|
113
113
|
process(input, options) {
|
|
114
|
+
if (!this.skills.length)
|
|
115
|
+
throw new Error("TeamAgent must have at least one skill defined.");
|
|
114
116
|
if (this.iterateOn) {
|
|
115
117
|
return this._processIterator(this.iterateOn, input, options);
|
|
116
118
|
}
|
package/lib/esm/aigne/aigne.d.ts
CHANGED
|
@@ -10,6 +10,11 @@ import type { ContextLimits } from "./usage.js";
|
|
|
10
10
|
* Options for the AIGNE class.
|
|
11
11
|
*/
|
|
12
12
|
export interface AIGNEOptions {
|
|
13
|
+
/**
|
|
14
|
+
* Optional root directory for this AIGNE instance.
|
|
15
|
+
* This is used to resolve relative paths for agents and skills.
|
|
16
|
+
*/
|
|
17
|
+
rootDir?: string;
|
|
13
18
|
/**
|
|
14
19
|
* The name of the AIGNE instance.
|
|
15
20
|
*/
|
|
@@ -67,6 +72,10 @@ export declare class AIGNE<U extends UserContext = UserContext> {
|
|
|
67
72
|
* @param options - Configuration options for the AIGNE instance including name, description, model, and agents.
|
|
68
73
|
*/
|
|
69
74
|
constructor(options?: AIGNEOptions);
|
|
75
|
+
/**
|
|
76
|
+
* Optional root directory for this AIGNE instance.
|
|
77
|
+
*/
|
|
78
|
+
rootDir?: string;
|
|
70
79
|
/**
|
|
71
80
|
* Optional name identifier for this AIGNE instance.
|
|
72
81
|
*/
|
package/lib/esm/aigne/aigne.js
CHANGED
|
@@ -26,9 +26,10 @@ export class AIGNE {
|
|
|
26
26
|
* @returns A fully initialized AIGNE instance with configured agents and skills.
|
|
27
27
|
*/
|
|
28
28
|
static async load(path, options) {
|
|
29
|
-
const { model, agents, skills, ...aigne } = await load({ ...options, path });
|
|
29
|
+
const { model, agents = [], skills = [], ...aigne } = await load({ ...options, path });
|
|
30
30
|
return new AIGNE({
|
|
31
31
|
...options,
|
|
32
|
+
rootDir: aigne.rootDir,
|
|
32
33
|
model: options?.model || model,
|
|
33
34
|
name: options?.name || aigne.name || undefined,
|
|
34
35
|
description: options?.description || aigne.description || undefined,
|
|
@@ -44,6 +45,7 @@ export class AIGNE {
|
|
|
44
45
|
constructor(options) {
|
|
45
46
|
if (options)
|
|
46
47
|
checkArguments("AIGNE", aigneOptionsSchema, options);
|
|
48
|
+
this.rootDir = options?.rootDir;
|
|
47
49
|
this.name = options?.name;
|
|
48
50
|
this.description = options?.description;
|
|
49
51
|
this.model = options?.model;
|
|
@@ -59,6 +61,10 @@ export class AIGNE {
|
|
|
59
61
|
this.observer?.serve();
|
|
60
62
|
this.initProcessExitHandler();
|
|
61
63
|
}
|
|
64
|
+
/**
|
|
65
|
+
* Optional root directory for this AIGNE instance.
|
|
66
|
+
*/
|
|
67
|
+
rootDir;
|
|
62
68
|
/**
|
|
63
69
|
* Optional name identifier for this AIGNE instance.
|
|
64
70
|
*/
|
package/lib/esm/aigne/context.js
CHANGED
|
@@ -381,6 +381,6 @@ async function* withAbortSignal(signal, error, fn) {
|
|
|
381
381
|
}
|
|
382
382
|
const aigneContextInvokeArgsSchema = z.object({
|
|
383
383
|
agent: z.union([z.custom(), z.custom()]),
|
|
384
|
-
message: z.union([z.record(z.unknown()), z.string()]).optional(),
|
|
384
|
+
message: z.union([z.record(z.string(), z.unknown()), z.string()]).optional(),
|
|
385
385
|
options: z.object({ returnActiveAgent: z.boolean().optional() }).optional(),
|
|
386
386
|
});
|
|
@@ -87,18 +87,18 @@ function once(events, event, listener) {
|
|
|
87
87
|
}
|
|
88
88
|
const subscribeArgsSchema = z.object({
|
|
89
89
|
topic: z.union([z.string(), z.array(z.string())]),
|
|
90
|
-
listener: z.
|
|
90
|
+
listener: z.custom().optional(),
|
|
91
91
|
});
|
|
92
92
|
const unsubscribeArgsSchema = z.object({
|
|
93
93
|
topic: z.union([z.string(), z.array(z.string())]),
|
|
94
|
-
listener: z.
|
|
94
|
+
listener: z.custom(),
|
|
95
95
|
});
|
|
96
96
|
const publishArgsSchema = z.object({
|
|
97
97
|
topic: z.union([z.string(), z.array(z.string())]),
|
|
98
98
|
payload: z.object({
|
|
99
99
|
role: z.union([z.literal("user"), z.literal("agent")]),
|
|
100
100
|
source: z.string().optional(),
|
|
101
|
-
message: z.union([z.string(), z.record(z.unknown())]),
|
|
101
|
+
message: z.union([z.string(), z.record(z.string(), z.unknown())]),
|
|
102
102
|
context: z.any(),
|
|
103
103
|
}),
|
|
104
104
|
});
|
|
@@ -4,21 +4,21 @@ import { z } from "zod";
|
|
|
4
4
|
import { Agent } from "../agents/agent.js";
|
|
5
5
|
import { tryOrThrow } from "../utils/type-utils.js";
|
|
6
6
|
import { inputOutputSchema, optionalize } from "./schema.js";
|
|
7
|
-
const agentJsFileSchema = z.object({
|
|
8
|
-
name: z.string(),
|
|
9
|
-
description: optionalize(z.string()),
|
|
10
|
-
inputSchema: optionalize(inputOutputSchema).transform((v) => v ? jsonSchemaToZod(v) : undefined),
|
|
11
|
-
outputSchema: optionalize(inputOutputSchema).transform((v) => v ? jsonSchemaToZod(v) : undefined),
|
|
12
|
-
process: z.custom(),
|
|
13
|
-
});
|
|
14
7
|
export async function loadAgentFromJsFile(path) {
|
|
8
|
+
const agentJsFileSchema = z.object({
|
|
9
|
+
name: z.string(),
|
|
10
|
+
description: optionalize(z.string()),
|
|
11
|
+
inputSchema: optionalize(inputOutputSchema({ path })).transform((v) => v ? jsonSchemaToZod(v) : undefined),
|
|
12
|
+
outputSchema: optionalize(inputOutputSchema({ path })).transform((v) => v ? jsonSchemaToZod(v) : undefined),
|
|
13
|
+
process: z.custom(),
|
|
14
|
+
});
|
|
15
15
|
const { default: agent } = await tryOrThrow(() => import(/* @vite-ignore */ path), (error) => new Error(`Failed to load agent definition from ${path}: ${error.message}`));
|
|
16
16
|
if (agent instanceof Agent)
|
|
17
17
|
return agent;
|
|
18
18
|
if (typeof agent !== "function") {
|
|
19
19
|
throw new Error(`Agent file ${path} must export a default function, but got ${typeof agent}`);
|
|
20
20
|
}
|
|
21
|
-
return tryOrThrow(() => agentJsFileSchema.
|
|
21
|
+
return tryOrThrow(() => agentJsFileSchema.parseAsync(camelize({
|
|
22
22
|
...agent,
|
|
23
23
|
name: agent.agent_name || agent.agentName || agent.name,
|
|
24
24
|
process: agent,
|
|
@@ -4,8 +4,8 @@ import { ProcessMode } from "../agents/team-agent.js";
|
|
|
4
4
|
interface BaseAgentSchema {
|
|
5
5
|
name?: string;
|
|
6
6
|
description?: string;
|
|
7
|
-
inputSchema?: ZodType<Record<string,
|
|
8
|
-
outputSchema?: ZodType<Record<string,
|
|
7
|
+
inputSchema?: ZodType<Record<string, any>>;
|
|
8
|
+
outputSchema?: ZodType<Record<string, any>>;
|
|
9
9
|
skills?: (string | AgentSchema)[];
|
|
10
10
|
memory?: boolean | {
|
|
11
11
|
provider: string;
|
|
@@ -12,8 +12,8 @@ export async function loadAgentFromYamlFile(path) {
|
|
|
12
12
|
const baseAgentSchema = z.object({
|
|
13
13
|
name: optionalize(z.string()),
|
|
14
14
|
description: optionalize(z.string()),
|
|
15
|
-
inputSchema: optionalize(inputOutputSchema).transform((v) => v ? jsonSchemaToZod(v) : undefined),
|
|
16
|
-
outputSchema: optionalize(inputOutputSchema).transform((v) => v ? jsonSchemaToZod(v) : undefined),
|
|
15
|
+
inputSchema: optionalize(inputOutputSchema({ path })).transform((v) => v ? jsonSchemaToZod(v) : undefined),
|
|
16
|
+
outputSchema: optionalize(inputOutputSchema({ path })).transform((v) => v ? jsonSchemaToZod(v) : undefined),
|
|
17
17
|
skills: optionalize(z.array(z.union([z.string(), agentSchema]))),
|
|
18
18
|
memory: optionalize(z.union([
|
|
19
19
|
z.boolean(),
|
|
@@ -62,11 +62,11 @@ export async function loadAgentFromYamlFile(path) {
|
|
|
62
62
|
]);
|
|
63
63
|
});
|
|
64
64
|
const raw = await tryOrThrow(() => nodejs.fs.readFile(path, "utf8"), (error) => new Error(`Failed to load agent definition from ${path}: ${error.message}`));
|
|
65
|
-
const json =
|
|
66
|
-
const agent = await tryOrThrow(async () => await agentSchema.parseAsync(
|
|
65
|
+
const json = tryOrThrow(() => camelize(parse(raw)), (error) => new Error(`Failed to parse agent definition from ${path}: ${error.message}`));
|
|
66
|
+
const agent = await tryOrThrow(async () => await agentSchema.parseAsync({
|
|
67
67
|
...json,
|
|
68
68
|
type: json.type ?? "ai",
|
|
69
69
|
skills: json.skills ?? json.tools,
|
|
70
|
-
})
|
|
70
|
+
}), (error) => new Error(`Failed to validate agent definition from ${path}: ${error.message}`));
|
|
71
71
|
return agent;
|
|
72
72
|
}
|
|
@@ -2,6 +2,7 @@ import type { Camelize } from "camelize-ts";
|
|
|
2
2
|
import { z } from "zod";
|
|
3
3
|
import { Agent } from "../agents/agent.js";
|
|
4
4
|
import type { ChatModel, ChatModelOptions } from "../agents/chat-model.js";
|
|
5
|
+
import type { AIGNEOptions } from "../aigne/aigne.js";
|
|
5
6
|
import type { MemoryAgent, MemoryAgentOptions } from "../memory/memory.js";
|
|
6
7
|
interface LoadableModelClass {
|
|
7
8
|
new (parameters: {
|
|
@@ -23,103 +24,72 @@ export interface LoadOptions {
|
|
|
23
24
|
}[];
|
|
24
25
|
path: string;
|
|
25
26
|
}
|
|
26
|
-
export declare function load(options: LoadOptions): Promise<
|
|
27
|
-
model: ChatModel | undefined;
|
|
28
|
-
agents: Agent<any, any>[];
|
|
29
|
-
skills: Agent<any, any>[];
|
|
30
|
-
name?: string | null | undefined;
|
|
31
|
-
description?: string | null | undefined;
|
|
32
|
-
chat_model?: {
|
|
33
|
-
name?: string | null | undefined;
|
|
34
|
-
temperature?: number | null | undefined;
|
|
35
|
-
provider?: string | null | undefined;
|
|
36
|
-
top_p?: number | null | undefined;
|
|
37
|
-
frequency_penalty?: number | null | undefined;
|
|
38
|
-
presence_penalty?: number | null | undefined;
|
|
39
|
-
} | null | undefined;
|
|
40
|
-
}>;
|
|
27
|
+
export declare function load(options: LoadOptions): Promise<AIGNEOptions>;
|
|
41
28
|
export declare function loadAgent(path: string, options?: LoadOptions): Promise<Agent>;
|
|
42
|
-
export declare function loadModel(models: LoadableModel[], model?: Camelize<z.infer<typeof aigneFileSchema>["
|
|
29
|
+
export declare function loadModel(models: LoadableModel[], model?: Camelize<z.infer<typeof aigneFileSchema>["model"]>, modelOptions?: ChatModelOptions): Promise<ChatModel | undefined>;
|
|
43
30
|
declare const aigneFileSchema: z.ZodObject<{
|
|
44
|
-
name: z.
|
|
45
|
-
description: z.
|
|
46
|
-
|
|
47
|
-
provider: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
48
|
-
name: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
49
|
-
temperature: z.ZodOptional<z.ZodNullable<z.ZodNumber>>;
|
|
50
|
-
top_p: z.ZodOptional<z.ZodNullable<z.ZodNumber>>;
|
|
51
|
-
frequency_penalty: z.ZodOptional<z.ZodNullable<z.ZodNumber>>;
|
|
52
|
-
presence_penalty: z.ZodOptional<z.ZodNullable<z.ZodNumber>>;
|
|
53
|
-
}, "strip", z.ZodTypeAny, {
|
|
31
|
+
name: z.ZodType<string | undefined, z.ZodTypeDef, string | undefined>;
|
|
32
|
+
description: z.ZodType<string | undefined, z.ZodTypeDef, string | undefined>;
|
|
33
|
+
model: z.ZodEffects<z.ZodType<string | {
|
|
54
34
|
name?: string | null | undefined;
|
|
55
35
|
temperature?: number | null | undefined;
|
|
36
|
+
topP?: number | null | undefined;
|
|
37
|
+
frequencyPenalty?: number | null | undefined;
|
|
38
|
+
presencePenalty?: number | null | undefined;
|
|
56
39
|
provider?: string | null | undefined;
|
|
57
|
-
|
|
58
|
-
frequency_penalty?: number | null | undefined;
|
|
59
|
-
presence_penalty?: number | null | undefined;
|
|
60
|
-
}, {
|
|
40
|
+
} | undefined, z.ZodTypeDef, string | {
|
|
61
41
|
name?: string | null | undefined;
|
|
62
42
|
temperature?: number | null | undefined;
|
|
43
|
+
topP?: number | null | undefined;
|
|
44
|
+
frequencyPenalty?: number | null | undefined;
|
|
45
|
+
presencePenalty?: number | null | undefined;
|
|
63
46
|
provider?: string | null | undefined;
|
|
64
|
-
|
|
65
|
-
frequency_penalty?: number | null | undefined;
|
|
66
|
-
presence_penalty?: number | null | undefined;
|
|
67
|
-
}>]>>>, {
|
|
47
|
+
} | undefined>, {
|
|
68
48
|
name?: string | null | undefined;
|
|
69
49
|
temperature?: number | null | undefined;
|
|
50
|
+
topP?: number | null | undefined;
|
|
51
|
+
frequencyPenalty?: number | null | undefined;
|
|
52
|
+
presencePenalty?: number | null | undefined;
|
|
70
53
|
provider?: string | null | undefined;
|
|
71
|
-
|
|
72
|
-
frequency_penalty?: number | null | undefined;
|
|
73
|
-
presence_penalty?: number | null | undefined;
|
|
74
|
-
} | null | undefined, string | {
|
|
54
|
+
} | undefined, string | {
|
|
75
55
|
name?: string | null | undefined;
|
|
76
56
|
temperature?: number | null | undefined;
|
|
57
|
+
topP?: number | null | undefined;
|
|
58
|
+
frequencyPenalty?: number | null | undefined;
|
|
59
|
+
presencePenalty?: number | null | undefined;
|
|
77
60
|
provider?: string | null | undefined;
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
} | null | undefined>;
|
|
82
|
-
agents: z.ZodOptional<z.ZodNullable<z.ZodArray<z.ZodString, "many">>>;
|
|
83
|
-
skills: z.ZodOptional<z.ZodNullable<z.ZodArray<z.ZodString, "many">>>;
|
|
61
|
+
} | undefined>;
|
|
62
|
+
agents: z.ZodType<string[] | undefined, z.ZodTypeDef, string[] | undefined>;
|
|
63
|
+
skills: z.ZodType<string[] | undefined, z.ZodTypeDef, string[] | undefined>;
|
|
84
64
|
}, "strip", z.ZodTypeAny, {
|
|
85
|
-
name?: string |
|
|
86
|
-
description?: string |
|
|
87
|
-
skills?: string[] |
|
|
88
|
-
|
|
65
|
+
name?: string | undefined;
|
|
66
|
+
description?: string | undefined;
|
|
67
|
+
skills?: string[] | undefined;
|
|
68
|
+
model?: {
|
|
89
69
|
name?: string | null | undefined;
|
|
90
70
|
temperature?: number | null | undefined;
|
|
71
|
+
topP?: number | null | undefined;
|
|
72
|
+
frequencyPenalty?: number | null | undefined;
|
|
73
|
+
presencePenalty?: number | null | undefined;
|
|
91
74
|
provider?: string | null | undefined;
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
presence_penalty?: number | null | undefined;
|
|
95
|
-
} | null | undefined;
|
|
96
|
-
agents?: string[] | null | undefined;
|
|
75
|
+
} | undefined;
|
|
76
|
+
agents?: string[] | undefined;
|
|
97
77
|
}, {
|
|
98
|
-
name?: string |
|
|
99
|
-
description?: string |
|
|
100
|
-
skills?: string[] |
|
|
101
|
-
|
|
78
|
+
name?: string | undefined;
|
|
79
|
+
description?: string | undefined;
|
|
80
|
+
skills?: string[] | undefined;
|
|
81
|
+
model?: string | {
|
|
102
82
|
name?: string | null | undefined;
|
|
103
83
|
temperature?: number | null | undefined;
|
|
84
|
+
topP?: number | null | undefined;
|
|
85
|
+
frequencyPenalty?: number | null | undefined;
|
|
86
|
+
presencePenalty?: number | null | undefined;
|
|
104
87
|
provider?: string | null | undefined;
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
presence_penalty?: number | null | undefined;
|
|
108
|
-
} | null | undefined;
|
|
109
|
-
agents?: string[] | null | undefined;
|
|
88
|
+
} | undefined;
|
|
89
|
+
agents?: string[] | undefined;
|
|
110
90
|
}>;
|
|
111
91
|
export declare function loadAIGNEFile(path: string): Promise<{
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
skills?: string[] | null | undefined;
|
|
115
|
-
chat_model?: {
|
|
116
|
-
name?: string | null | undefined;
|
|
117
|
-
temperature?: number | null | undefined;
|
|
118
|
-
provider?: string | null | undefined;
|
|
119
|
-
top_p?: number | null | undefined;
|
|
120
|
-
frequency_penalty?: number | null | undefined;
|
|
121
|
-
presence_penalty?: number | null | undefined;
|
|
122
|
-
} | null | undefined;
|
|
123
|
-
agents?: string[] | null | undefined;
|
|
92
|
+
aigne: z.infer<typeof aigneFileSchema>;
|
|
93
|
+
rootDir: string;
|
|
124
94
|
}>;
|
|
125
95
|
export {};
|