@aigne/core 1.71.0-beta.2 → 1.71.0-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 +36 -0
- package/lib/cjs/aigne/aigne.d.ts +6 -1
- package/lib/cjs/aigne/aigne.js +13 -4
- package/lib/cjs/aigne/context.d.ts +2 -2
- package/lib/cjs/aigne/context.js +5 -22
- package/lib/cjs/loader/agent-js.d.ts +2 -1
- package/lib/cjs/loader/agent-js.js +2 -2
- package/lib/cjs/loader/agent-yaml.d.ts +4 -3
- package/lib/cjs/loader/agent-yaml.js +21 -17
- package/lib/cjs/loader/index.d.ts +3 -3
- package/lib/cjs/loader/index.js +1 -1
- package/lib/cjs/loader/schema.d.ts +1 -0
- package/lib/cjs/loader/schema.js +4 -0
- package/lib/cjs/prompt/skills/afs.js +7 -0
- package/lib/cjs/utils/event-stream.js +1 -0
- package/lib/dts/aigne/aigne.d.ts +6 -1
- package/lib/dts/aigne/context.d.ts +2 -2
- package/lib/dts/loader/agent-js.d.ts +2 -1
- package/lib/dts/loader/agent-yaml.d.ts +4 -3
- package/lib/dts/loader/index.d.ts +3 -3
- package/lib/dts/loader/schema.d.ts +1 -0
- package/lib/esm/aigne/aigne.d.ts +6 -1
- package/lib/esm/aigne/aigne.js +13 -4
- package/lib/esm/aigne/context.d.ts +2 -2
- package/lib/esm/aigne/context.js +5 -22
- package/lib/esm/loader/agent-js.d.ts +2 -1
- package/lib/esm/loader/agent-js.js +2 -2
- package/lib/esm/loader/agent-yaml.d.ts +4 -3
- package/lib/esm/loader/agent-yaml.js +22 -18
- package/lib/esm/loader/index.d.ts +3 -3
- package/lib/esm/loader/index.js +1 -1
- package/lib/esm/loader/schema.d.ts +1 -0
- package/lib/esm/loader/schema.js +3 -0
- package/lib/esm/prompt/skills/afs.js +7 -0
- package/lib/esm/utils/event-stream.js +2 -1
- package/package.json +5 -5
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,41 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## [1.71.0-beta.4](https://github.com/AIGNE-io/aigne-framework/compare/core-v1.71.0-beta.3...core-v1.71.0-beta.4) (2025-12-10)
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
### Bug Fixes
|
|
7
|
+
|
|
8
|
+
* bump version ([af04b69](https://github.com/AIGNE-io/aigne-framework/commit/af04b6931951afa35d52065430acc7fef4b10087))
|
|
9
|
+
* **core:** support load third agent in skills ([#819](https://github.com/AIGNE-io/aigne-framework/issues/819)) ([bcbb140](https://github.com/AIGNE-io/aigne-framework/commit/bcbb1404d2fe9c709d99a8c28883b21dd107a844))
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
### Dependencies
|
|
13
|
+
|
|
14
|
+
* The following workspace dependencies were updated
|
|
15
|
+
* dependencies
|
|
16
|
+
* @aigne/afs bumped to 1.3.0-beta.2
|
|
17
|
+
* @aigne/afs-history bumped to 1.1.3-beta.2
|
|
18
|
+
* @aigne/observability-api bumped to 0.11.13-beta.1
|
|
19
|
+
* @aigne/platform-helpers bumped to 0.6.6-beta
|
|
20
|
+
|
|
21
|
+
## [1.71.0-beta.3](https://github.com/AIGNE-io/aigne-framework/compare/core-v1.71.0-beta.2...core-v1.71.0-beta.3) (2025-12-10)
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
### Bug Fixes
|
|
25
|
+
|
|
26
|
+
* **afs:** add case-sensitive option for search with case-insensitive default ([#814](https://github.com/AIGNE-io/aigne-framework/issues/814)) ([9dc9446](https://github.com/AIGNE-io/aigne-framework/commit/9dc944635104fc311e7756b4bde0a20275cfe8ec))
|
|
27
|
+
* **core:** disable Immer autofreeze to return mutable response objects ([#817](https://github.com/AIGNE-io/aigne-framework/issues/817)) ([a3d0651](https://github.com/AIGNE-io/aigne-framework/commit/a3d06512cdadb9d85f92b7e8d2fd85b4f35a804b))
|
|
28
|
+
* **observability:** improve trace shutdown handling and exit status ([#813](https://github.com/AIGNE-io/aigne-framework/issues/813)) ([6215f13](https://github.com/AIGNE-io/aigne-framework/commit/6215f13243b23103c1793a4559798f0e90722384))
|
|
29
|
+
|
|
30
|
+
|
|
31
|
+
### Dependencies
|
|
32
|
+
|
|
33
|
+
* The following workspace dependencies were updated
|
|
34
|
+
* dependencies
|
|
35
|
+
* @aigne/afs bumped to 1.3.0-beta.1
|
|
36
|
+
* @aigne/afs-history bumped to 1.1.3-beta.1
|
|
37
|
+
* @aigne/observability-api bumped to 0.11.13-beta
|
|
38
|
+
|
|
3
39
|
## [1.71.0-beta.2](https://github.com/AIGNE-io/aigne-framework/compare/core-v1.71.0-beta.1...core-v1.71.0-beta.2) (2025-12-09)
|
|
4
40
|
|
|
5
41
|
|
package/lib/cjs/aigne/aigne.d.ts
CHANGED
|
@@ -113,6 +113,10 @@ export declare class AIGNE<U extends UserContext = UserContext> {
|
|
|
113
113
|
* @hidden
|
|
114
114
|
*/
|
|
115
115
|
readonly messageQueue: MessageQueue;
|
|
116
|
+
/**
|
|
117
|
+
* Collection of all context IDs created by this AIGNE instance.
|
|
118
|
+
*/
|
|
119
|
+
readonly contextIds: Set<string>;
|
|
116
120
|
/**
|
|
117
121
|
* Collection of skill agents available to this AIGNE instance.
|
|
118
122
|
* Provides indexed access by skill name.
|
|
@@ -324,7 +328,8 @@ export declare class AIGNE<U extends UserContext = UserContext> {
|
|
|
324
328
|
[Symbol.asyncDispose](): Promise<void>;
|
|
325
329
|
/**
|
|
326
330
|
* Initializes handlers for process exit events to ensure clean shutdown.
|
|
327
|
-
* This registers handlers for SIGINT
|
|
331
|
+
* This registers handlers for SIGINT/SIGTERM to properly terminate all agents.
|
|
332
|
+
* Note: 'exit' event cannot run async code, so we handle cleanup in signal handlers.
|
|
328
333
|
*/
|
|
329
334
|
private initProcessExitHandler;
|
|
330
335
|
}
|
package/lib/cjs/aigne/aigne.js
CHANGED
|
@@ -99,6 +99,10 @@ class AIGNE {
|
|
|
99
99
|
* @hidden
|
|
100
100
|
*/
|
|
101
101
|
messageQueue = new message_queue_js_1.MessageQueue();
|
|
102
|
+
/**
|
|
103
|
+
* Collection of all context IDs created by this AIGNE instance.
|
|
104
|
+
*/
|
|
105
|
+
contextIds = new Set();
|
|
102
106
|
/**
|
|
103
107
|
* Collection of skill agents available to this AIGNE instance.
|
|
104
108
|
* Provides indexed access by skill name.
|
|
@@ -200,7 +204,7 @@ class AIGNE {
|
|
|
200
204
|
*/
|
|
201
205
|
async shutdown() {
|
|
202
206
|
// Close observer first to flush any pending traces
|
|
203
|
-
await this.observer?.close();
|
|
207
|
+
await this.observer?.close(Array.from(this.contextIds));
|
|
204
208
|
for (const tool of this.skills) {
|
|
205
209
|
await tool.shutdown();
|
|
206
210
|
}
|
|
@@ -220,12 +224,17 @@ class AIGNE {
|
|
|
220
224
|
}
|
|
221
225
|
/**
|
|
222
226
|
* Initializes handlers for process exit events to ensure clean shutdown.
|
|
223
|
-
* This registers handlers for SIGINT
|
|
227
|
+
* This registers handlers for SIGINT/SIGTERM to properly terminate all agents.
|
|
228
|
+
* Note: 'exit' event cannot run async code, so we handle cleanup in signal handlers.
|
|
224
229
|
*/
|
|
225
230
|
initProcessExitHandler() {
|
|
226
|
-
const
|
|
231
|
+
const originalExit = process.exit;
|
|
232
|
+
// @ts-ignore
|
|
233
|
+
process.exit = (...args) => {
|
|
234
|
+
this.shutdown().finally(() => originalExit(...args));
|
|
235
|
+
};
|
|
236
|
+
const shutdownAndExit = () => this.shutdown().finally(() => originalExit(0));
|
|
227
237
|
process.on("SIGINT", shutdownAndExit);
|
|
228
|
-
process.on("exit", shutdownAndExit);
|
|
229
238
|
}
|
|
230
239
|
}
|
|
231
240
|
exports.AIGNE = AIGNE;
|
|
@@ -149,7 +149,6 @@ export interface Context<U extends UserContext = UserContext> extends TypedEvent
|
|
|
149
149
|
* @hidden
|
|
150
150
|
*/
|
|
151
151
|
export declare class AIGNEContext implements Context {
|
|
152
|
-
static exitCount: number;
|
|
153
152
|
constructor(parent?: ConstructorParameters<typeof AIGNEContextShared>[0], { reset }?: {
|
|
154
153
|
reset?: boolean;
|
|
155
154
|
});
|
|
@@ -183,7 +182,6 @@ export declare class AIGNEContext implements Context {
|
|
|
183
182
|
subscribe: Context["subscribe"];
|
|
184
183
|
unsubscribe: Context["unsubscribe"];
|
|
185
184
|
emit<K extends keyof ContextEmitEventMap>(eventName: K, ...args: Args<K, ContextEmitEventMap>): boolean;
|
|
186
|
-
initProcessExitHandler(): void;
|
|
187
185
|
private trace;
|
|
188
186
|
on<K extends keyof ContextEventMap>(eventName: K, listener: Listener<K, ContextEventMap>): this;
|
|
189
187
|
once<K extends keyof ContextEventMap>(eventName: K, listener: Listener<K, ContextEventMap>): this;
|
|
@@ -194,6 +192,7 @@ declare class AIGNEContextShared {
|
|
|
194
192
|
constructor(parent?: (Pick<Context, "model" | "imageModel" | "agents" | "skills" | "limits" | "observer" | "metadata"> & {
|
|
195
193
|
messageQueue?: MessageQueue;
|
|
196
194
|
events?: Emitter<any>;
|
|
195
|
+
contextIds?: Set<string>;
|
|
197
196
|
}) | undefined);
|
|
198
197
|
readonly messageQueue: MessageQueue;
|
|
199
198
|
readonly events: Emitter<any>;
|
|
@@ -205,6 +204,7 @@ declare class AIGNEContextShared {
|
|
|
205
204
|
get metadata(): AIGNEMetadata | undefined;
|
|
206
205
|
get limits(): ContextLimits | undefined;
|
|
207
206
|
usage: ContextUsage;
|
|
207
|
+
contextIds: Set<string>;
|
|
208
208
|
userContext: Context["userContext"];
|
|
209
209
|
memories: Context["memories"];
|
|
210
210
|
hooks: AgentHooks[];
|
package/lib/cjs/aigne/context.js
CHANGED
|
@@ -23,7 +23,6 @@ const usage_js_1 = require("./usage.js");
|
|
|
23
23
|
* @hidden
|
|
24
24
|
*/
|
|
25
25
|
class AIGNEContext {
|
|
26
|
-
static exitCount = 0;
|
|
27
26
|
constructor(parent, { reset } = {}) {
|
|
28
27
|
const tracer = parent?.observer?.tracer;
|
|
29
28
|
if (parent instanceof AIGNEContext && !reset) {
|
|
@@ -47,7 +46,7 @@ class AIGNEContext {
|
|
|
47
46
|
this.rootId = this.span?.spanContext?.().traceId ?? (0, uuid_1.v7)();
|
|
48
47
|
}
|
|
49
48
|
this.id = this.span?.spanContext()?.spanId ?? (0, uuid_1.v7)();
|
|
50
|
-
this.
|
|
49
|
+
this.internal.contextIds.add(this.id);
|
|
51
50
|
}
|
|
52
51
|
id;
|
|
53
52
|
parentId;
|
|
@@ -203,26 +202,6 @@ class AIGNEContext {
|
|
|
203
202
|
this.trace(eventName, args, b);
|
|
204
203
|
return this.internal.events.emit(eventName, ...newArgs);
|
|
205
204
|
}
|
|
206
|
-
initProcessExitHandler() {
|
|
207
|
-
if (this.parentId)
|
|
208
|
-
return;
|
|
209
|
-
AIGNEContext.exitCount++;
|
|
210
|
-
process.once("SIGINT", async () => {
|
|
211
|
-
try {
|
|
212
|
-
if (process.env.AIGNE_OBSERVABILITY_DISABLED)
|
|
213
|
-
return;
|
|
214
|
-
await this.observer?.update(this.id, {
|
|
215
|
-
status: { code: api_1.SpanStatusCode.ERROR, message: "SIGINT" },
|
|
216
|
-
});
|
|
217
|
-
}
|
|
218
|
-
finally {
|
|
219
|
-
AIGNEContext.exitCount--;
|
|
220
|
-
if (AIGNEContext.exitCount === 0) {
|
|
221
|
-
process.exit(0);
|
|
222
|
-
}
|
|
223
|
-
}
|
|
224
|
-
});
|
|
225
|
-
}
|
|
226
205
|
async trace(eventName, args, b) {
|
|
227
206
|
if (process.env.AIGNE_OBSERVABILITY_DISABLED)
|
|
228
207
|
return;
|
|
@@ -258,12 +237,14 @@ class AIGNEContext {
|
|
|
258
237
|
await this.observer?.update(this.id, { output });
|
|
259
238
|
span.setStatus({ code: api_1.SpanStatusCode.OK });
|
|
260
239
|
span.end();
|
|
240
|
+
this.internal.contextIds.delete(this.id);
|
|
261
241
|
break;
|
|
262
242
|
}
|
|
263
243
|
case "agentFailed": {
|
|
264
244
|
const { error } = args[0];
|
|
265
245
|
span.setStatus({ code: api_1.SpanStatusCode.ERROR, message: error.message });
|
|
266
246
|
span.end();
|
|
247
|
+
this.internal.contextIds.delete(this.id);
|
|
267
248
|
break;
|
|
268
249
|
}
|
|
269
250
|
}
|
|
@@ -292,6 +273,7 @@ class AIGNEContextShared {
|
|
|
292
273
|
this.parent = parent;
|
|
293
274
|
this.messageQueue = this.parent?.messageQueue ?? new message_queue_js_1.MessageQueue();
|
|
294
275
|
this.events = this.parent?.events ?? new strict_event_emitter_1.Emitter();
|
|
276
|
+
this.contextIds = this.parent?.contextIds ?? new Set();
|
|
295
277
|
}
|
|
296
278
|
messageQueue;
|
|
297
279
|
events;
|
|
@@ -317,6 +299,7 @@ class AIGNEContextShared {
|
|
|
317
299
|
return this.parent?.limits;
|
|
318
300
|
}
|
|
319
301
|
usage = (0, usage_js_1.newEmptyContextUsage)();
|
|
302
|
+
contextIds;
|
|
320
303
|
userContext = {};
|
|
321
304
|
memories = [];
|
|
322
305
|
hooks = [];
|
|
@@ -1 +1,2 @@
|
|
|
1
|
-
|
|
1
|
+
import type { LoadOptions } from "./index.js";
|
|
2
|
+
export declare function loadAgentFromJsFile(path: string, options: LoadOptions): Promise<import("../index.js").Agent<any, any> | import("./agent-yaml.js").AgentSchema>;
|
|
@@ -7,7 +7,7 @@ const type_utils_js_1 = require("../utils/type-utils.js");
|
|
|
7
7
|
const agent_yaml_js_1 = require("./agent-yaml.js");
|
|
8
8
|
const error_js_1 = require("./error.js");
|
|
9
9
|
const importFn = new Function("path", "return import(path)");
|
|
10
|
-
async function loadAgentFromJsFile(path) {
|
|
10
|
+
async function loadAgentFromJsFile(path, options) {
|
|
11
11
|
const url = index_js_1.nodejs.path.isAbsolute(path) ? index_js_1.nodejs.url.pathToFileURL(path).toString() : path;
|
|
12
12
|
const { default: agent } = await (0, type_utils_js_1.tryOrThrow)(() => importFn(url), (error) => new error_js_1.LoadJsAgentError(`Failed to load agent definition from ${url}: ${error.message}`));
|
|
13
13
|
if ((0, agent_utils_js_1.isAgent)(agent))
|
|
@@ -17,5 +17,5 @@ async function loadAgentFromJsFile(path) {
|
|
|
17
17
|
process: agent,
|
|
18
18
|
name: agent.agent_name || agent.agentName || agent.name,
|
|
19
19
|
...agent,
|
|
20
|
-
}), (error) => new Error(`Failed to parse agent from ${path}: ${error.message}`));
|
|
20
|
+
}, options), (error) => new Error(`Failed to parse agent from ${path}: ${error.message}`));
|
|
21
21
|
}
|
|
@@ -101,13 +101,14 @@ export interface ThirdAgentSchema extends BaseAgentSchema {
|
|
|
101
101
|
[key: string]: any;
|
|
102
102
|
}
|
|
103
103
|
export type AgentSchema = AIAgentSchema | ImageAgentSchema | MCPAgentSchema | TeamAgentSchema | TransformAgentSchema | FunctionAgentSchema | ThirdAgentSchema;
|
|
104
|
-
export declare function parseAgentFile(path: string, data: any): Promise<AgentSchema>;
|
|
105
|
-
export declare function loadAgentFromYamlFile(path: string, options
|
|
104
|
+
export declare function parseAgentFile(path: string, data: any, options: LoadOptions): Promise<AgentSchema>;
|
|
105
|
+
export declare function loadAgentFromYamlFile(path: string, options: LoadOptions): Promise<AgentSchema>;
|
|
106
106
|
export declare const getInstructionsSchema: ({ filepath }: {
|
|
107
107
|
filepath: string;
|
|
108
108
|
}) => ZodType<Instructions>;
|
|
109
|
-
export declare const getAgentSchema: ({ filepath }: {
|
|
109
|
+
export declare const getAgentSchema: ({ filepath, options, }: {
|
|
110
110
|
filepath: string;
|
|
111
|
+
options?: LoadOptions;
|
|
111
112
|
}) => ZodType<AgentSchema, z.ZodTypeDef, AgentSchema>;
|
|
112
113
|
export declare const getNestAgentSchema: ({ filepath, }: {
|
|
113
114
|
filepath: string;
|
|
@@ -13,8 +13,8 @@ const team_agent_js_1 = require("../agents/team-agent.js");
|
|
|
13
13
|
const type_utils_js_1 = require("../utils/type-utils.js");
|
|
14
14
|
const function_agent_js_1 = require("./function-agent.js");
|
|
15
15
|
const schema_js_1 = require("./schema.js");
|
|
16
|
-
async function parseAgentFile(path, data) {
|
|
17
|
-
const agentSchema = (0, exports.getAgentSchema)({ filepath: path });
|
|
16
|
+
async function parseAgentFile(path, data, options) {
|
|
17
|
+
const agentSchema = (0, exports.getAgentSchema)({ filepath: path, options });
|
|
18
18
|
return agentSchema.parseAsync({
|
|
19
19
|
...data,
|
|
20
20
|
model: data.model || data.chatModel || data.chat_model,
|
|
@@ -23,22 +23,11 @@ async function parseAgentFile(path, data) {
|
|
|
23
23
|
async function loadAgentFromYamlFile(path, options) {
|
|
24
24
|
const raw = await (0, type_utils_js_1.tryOrThrow)(() => index_js_1.nodejs.fs.readFile(path, "utf8"), (error) => new Error(`Failed to load agent definition from ${path}: ${error.message}`));
|
|
25
25
|
const json = (0, type_utils_js_1.tryOrThrow)(() => (0, yaml_1.parse)(raw), (error) => new Error(`Failed to parse agent definition from ${path}: ${error.message}`));
|
|
26
|
-
if (!["ai", "image", "mcp", "team", "transform", "function"].includes(json?.type)) {
|
|
27
|
-
if (typeof json?.type === "string") {
|
|
28
|
-
if (!options?.require)
|
|
29
|
-
throw new Error(`Module loader is not provided to load agent type module ${json.type} from ${path}`);
|
|
30
|
-
const Mod = await options.require(json.type, { parent: path });
|
|
31
|
-
if (typeof Mod?.default?.prototype?.constructor !== "function") {
|
|
32
|
-
throw new Error(`The agent type module ${json.type} does not export a default Agent class`);
|
|
33
|
-
}
|
|
34
|
-
json.agentClass = Mod.default;
|
|
35
|
-
}
|
|
36
|
-
}
|
|
37
26
|
const agent = await (0, type_utils_js_1.tryOrThrow)(async () => await parseAgentFile(path, {
|
|
38
27
|
...json,
|
|
39
28
|
type: json.type ?? "ai",
|
|
40
29
|
skills: json.skills ?? json.tools,
|
|
41
|
-
}), (error) => new Error(`Failed to validate agent definition from ${path}: ${error.message}`));
|
|
30
|
+
}, options), (error) => new Error(`Failed to validate agent definition from ${path}: ${error.message}`));
|
|
42
31
|
return agent;
|
|
43
32
|
}
|
|
44
33
|
const instructionItemSchema = zod_1.z.union([
|
|
@@ -76,7 +65,7 @@ const getInstructionsSchema = ({ filepath }) => zod_1.z
|
|
|
76
65
|
return [await parseInstructionItem({ filepath })(v)];
|
|
77
66
|
});
|
|
78
67
|
exports.getInstructionsSchema = getInstructionsSchema;
|
|
79
|
-
const getAgentSchema = ({ filepath }) => {
|
|
68
|
+
const getAgentSchema = ({ filepath, options, }) => {
|
|
80
69
|
const agentSchema = zod_1.z.lazy(() => {
|
|
81
70
|
const nestAgentSchema = zod_1.z.lazy(() => zod_1.z.union([
|
|
82
71
|
agentSchema,
|
|
@@ -133,7 +122,22 @@ const getAgentSchema = ({ filepath }) => {
|
|
|
133
122
|
shareAFS: (0, schema_js_1.optionalize)(zod_1.z.boolean()),
|
|
134
123
|
});
|
|
135
124
|
const instructionsSchema = (0, exports.getInstructionsSchema)({ filepath: filepath });
|
|
136
|
-
return (0, schema_js_1.camelizeSchema)(
|
|
125
|
+
return (0, schema_js_1.camelizeSchema)((0, schema_js_1.preprocessSchema)(async (json) => {
|
|
126
|
+
if (typeof json === "object" &&
|
|
127
|
+
json &&
|
|
128
|
+
"type" in json &&
|
|
129
|
+
typeof json.type === "string" &&
|
|
130
|
+
!["ai", "image", "mcp", "team", "transform", "function"].includes(json.type)) {
|
|
131
|
+
if (!options?.require)
|
|
132
|
+
throw new Error(`Module loader is not provided to load agent type module ${json.type} from ${filepath}`);
|
|
133
|
+
const Mod = await options.require(json.type, { parent: filepath });
|
|
134
|
+
if (typeof Mod?.default?.prototype?.constructor !== "function") {
|
|
135
|
+
throw new Error(`The agent type module ${json.type} does not export a default Agent class`);
|
|
136
|
+
}
|
|
137
|
+
Object.assign(json, { agentClass: Mod.default });
|
|
138
|
+
}
|
|
139
|
+
return json;
|
|
140
|
+
}, zod_1.z.union([
|
|
137
141
|
zod_1.z
|
|
138
142
|
.object({
|
|
139
143
|
type: zod_1.z.string(),
|
|
@@ -204,7 +208,7 @@ const getAgentSchema = ({ filepath }) => {
|
|
|
204
208
|
})
|
|
205
209
|
.extend(baseAgentSchema.shape),
|
|
206
210
|
]),
|
|
207
|
-
]));
|
|
211
|
+
])));
|
|
208
212
|
});
|
|
209
213
|
return agentSchema;
|
|
210
214
|
};
|
|
@@ -28,9 +28,9 @@ export interface LoadOptions {
|
|
|
28
28
|
}) => Promise<any>;
|
|
29
29
|
}
|
|
30
30
|
export declare function load(path: string, options?: LoadOptions): Promise<AIGNEOptions>;
|
|
31
|
-
export declare function loadAgent(path: string, options
|
|
32
|
-
export declare function loadNestAgent(path: string, agent: NestAgentSchema, options
|
|
33
|
-
export declare function parseAgent(path: string, agent: Awaited<ReturnType<typeof loadAgentFromYamlFile>>, options
|
|
31
|
+
export declare function loadAgent(path: string, options: LoadOptions, agentOptions?: AgentOptions): Promise<Agent>;
|
|
32
|
+
export declare function loadNestAgent(path: string, agent: NestAgentSchema, options: LoadOptions, agentOptions?: AgentOptions<any, any> & Record<string, unknown>): Promise<Agent>;
|
|
33
|
+
export declare function parseAgent(path: string, agent: Awaited<ReturnType<typeof loadAgentFromYamlFile>>, options: LoadOptions, agentOptions?: AgentOptions): Promise<Agent>;
|
|
34
34
|
type CliAgent = string | {
|
|
35
35
|
url?: string;
|
|
36
36
|
name?: string;
|
package/lib/cjs/loader/index.js
CHANGED
|
@@ -70,7 +70,7 @@ async function load(path, options = {}) {
|
|
|
70
70
|
}
|
|
71
71
|
async function loadAgent(path, options, agentOptions) {
|
|
72
72
|
if ([".js", ".mjs", ".ts", ".mts"].includes(index_js_1.nodejs.path.extname(path))) {
|
|
73
|
-
const agent = await (0, agent_js_js_1.loadAgentFromJsFile)(path);
|
|
73
|
+
const agent = await (0, agent_js_js_1.loadAgentFromJsFile)(path, options);
|
|
74
74
|
if (agent instanceof agent_js_1.Agent)
|
|
75
75
|
return agent;
|
|
76
76
|
return parseAgent(path, agent, options, agentOptions);
|
|
@@ -148,4 +148,5 @@ export declare function optionalize<T>(schema: ZodType<T>): ZodType<T | undefine
|
|
|
148
148
|
export declare function camelizeSchema<T extends ZodType>(schema: T, { shallow }?: {
|
|
149
149
|
shallow?: boolean;
|
|
150
150
|
}): T;
|
|
151
|
+
export declare function preprocessSchema<T extends ZodType>(fn: (data: unknown) => unknown, schema: T): T;
|
|
151
152
|
export {};
|
package/lib/cjs/loader/schema.js
CHANGED
|
@@ -3,6 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.imageModelSchema = exports.chatModelSchema = exports.defaultInputSchema = exports.inputOutputSchema = void 0;
|
|
4
4
|
exports.optionalize = optionalize;
|
|
5
5
|
exports.camelizeSchema = camelizeSchema;
|
|
6
|
+
exports.preprocessSchema = preprocessSchema;
|
|
6
7
|
const index_js_1 = require("@aigne/platform-helpers/nodejs/index.js");
|
|
7
8
|
const yaml_1 = require("yaml");
|
|
8
9
|
const zod_1 = require("zod");
|
|
@@ -97,3 +98,6 @@ function optionalize(schema) {
|
|
|
97
98
|
function camelizeSchema(schema, { shallow = true } = {}) {
|
|
98
99
|
return zod_1.z.preprocess((v) => ((0, type_utils_js_1.isRecord)(v) ? (0, camelize_js_1.camelize)(v, shallow) : v), schema);
|
|
99
100
|
}
|
|
101
|
+
function preprocessSchema(fn, schema) {
|
|
102
|
+
return zod_1.z.preprocess(fn, schema);
|
|
103
|
+
}
|
|
@@ -22,6 +22,7 @@ async function getAFSSkills(afs) {
|
|
|
22
22
|
return {
|
|
23
23
|
status: "success",
|
|
24
24
|
tool: "afs_list",
|
|
25
|
+
path: input.path,
|
|
25
26
|
options: input.options,
|
|
26
27
|
message,
|
|
27
28
|
result,
|
|
@@ -39,6 +40,10 @@ async function getAFSSkills(afs) {
|
|
|
39
40
|
options: zod_1.z
|
|
40
41
|
.object({
|
|
41
42
|
limit: zod_1.z.number().optional().describe("Maximum number of entries to return"),
|
|
43
|
+
caseSensitive: zod_1.z
|
|
44
|
+
.boolean()
|
|
45
|
+
.optional()
|
|
46
|
+
.describe("Whether the search is case sensitive, default is false"),
|
|
42
47
|
})
|
|
43
48
|
.optional(),
|
|
44
49
|
}),
|
|
@@ -47,6 +52,7 @@ async function getAFSSkills(afs) {
|
|
|
47
52
|
return {
|
|
48
53
|
status: "success",
|
|
49
54
|
tool: "afs_search",
|
|
55
|
+
path: input.path,
|
|
50
56
|
query: input.query,
|
|
51
57
|
options: input.options,
|
|
52
58
|
...result,
|
|
@@ -83,6 +89,7 @@ Usage:
|
|
|
83
89
|
status: "success",
|
|
84
90
|
tool: "afs_read",
|
|
85
91
|
path: input.path,
|
|
92
|
+
withLineNumbers: input.withLineNumbers,
|
|
86
93
|
...result,
|
|
87
94
|
result: {
|
|
88
95
|
...result.result,
|
|
@@ -5,6 +5,7 @@ const eventsource_parser_1 = require("eventsource-parser");
|
|
|
5
5
|
const immer_1 = require("immer");
|
|
6
6
|
const agent_js_1 = require("../agents/agent.js");
|
|
7
7
|
const type_utils_js_1 = require("./type-utils.js");
|
|
8
|
+
(0, immer_1.setAutoFreeze)(false);
|
|
8
9
|
class EventStreamParser extends TransformStream {
|
|
9
10
|
constructor() {
|
|
10
11
|
let parser;
|
package/lib/dts/aigne/aigne.d.ts
CHANGED
|
@@ -113,6 +113,10 @@ export declare class AIGNE<U extends UserContext = UserContext> {
|
|
|
113
113
|
* @hidden
|
|
114
114
|
*/
|
|
115
115
|
readonly messageQueue: MessageQueue;
|
|
116
|
+
/**
|
|
117
|
+
* Collection of all context IDs created by this AIGNE instance.
|
|
118
|
+
*/
|
|
119
|
+
readonly contextIds: Set<string>;
|
|
116
120
|
/**
|
|
117
121
|
* Collection of skill agents available to this AIGNE instance.
|
|
118
122
|
* Provides indexed access by skill name.
|
|
@@ -324,7 +328,8 @@ export declare class AIGNE<U extends UserContext = UserContext> {
|
|
|
324
328
|
[Symbol.asyncDispose](): Promise<void>;
|
|
325
329
|
/**
|
|
326
330
|
* Initializes handlers for process exit events to ensure clean shutdown.
|
|
327
|
-
* This registers handlers for SIGINT
|
|
331
|
+
* This registers handlers for SIGINT/SIGTERM to properly terminate all agents.
|
|
332
|
+
* Note: 'exit' event cannot run async code, so we handle cleanup in signal handlers.
|
|
328
333
|
*/
|
|
329
334
|
private initProcessExitHandler;
|
|
330
335
|
}
|
|
@@ -149,7 +149,6 @@ export interface Context<U extends UserContext = UserContext> extends TypedEvent
|
|
|
149
149
|
* @hidden
|
|
150
150
|
*/
|
|
151
151
|
export declare class AIGNEContext implements Context {
|
|
152
|
-
static exitCount: number;
|
|
153
152
|
constructor(parent?: ConstructorParameters<typeof AIGNEContextShared>[0], { reset }?: {
|
|
154
153
|
reset?: boolean;
|
|
155
154
|
});
|
|
@@ -183,7 +182,6 @@ export declare class AIGNEContext implements Context {
|
|
|
183
182
|
subscribe: Context["subscribe"];
|
|
184
183
|
unsubscribe: Context["unsubscribe"];
|
|
185
184
|
emit<K extends keyof ContextEmitEventMap>(eventName: K, ...args: Args<K, ContextEmitEventMap>): boolean;
|
|
186
|
-
initProcessExitHandler(): void;
|
|
187
185
|
private trace;
|
|
188
186
|
on<K extends keyof ContextEventMap>(eventName: K, listener: Listener<K, ContextEventMap>): this;
|
|
189
187
|
once<K extends keyof ContextEventMap>(eventName: K, listener: Listener<K, ContextEventMap>): this;
|
|
@@ -194,6 +192,7 @@ declare class AIGNEContextShared {
|
|
|
194
192
|
constructor(parent?: (Pick<Context, "model" | "imageModel" | "agents" | "skills" | "limits" | "observer" | "metadata"> & {
|
|
195
193
|
messageQueue?: MessageQueue;
|
|
196
194
|
events?: Emitter<any>;
|
|
195
|
+
contextIds?: Set<string>;
|
|
197
196
|
}) | undefined);
|
|
198
197
|
readonly messageQueue: MessageQueue;
|
|
199
198
|
readonly events: Emitter<any>;
|
|
@@ -205,6 +204,7 @@ declare class AIGNEContextShared {
|
|
|
205
204
|
get metadata(): AIGNEMetadata | undefined;
|
|
206
205
|
get limits(): ContextLimits | undefined;
|
|
207
206
|
usage: ContextUsage;
|
|
207
|
+
contextIds: Set<string>;
|
|
208
208
|
userContext: Context["userContext"];
|
|
209
209
|
memories: Context["memories"];
|
|
210
210
|
hooks: AgentHooks[];
|
|
@@ -1 +1,2 @@
|
|
|
1
|
-
|
|
1
|
+
import type { LoadOptions } from "./index.js";
|
|
2
|
+
export declare function loadAgentFromJsFile(path: string, options: LoadOptions): Promise<import("../index.js").Agent<any, any> | import("./agent-yaml.js").AgentSchema>;
|
|
@@ -101,13 +101,14 @@ export interface ThirdAgentSchema extends BaseAgentSchema {
|
|
|
101
101
|
[key: string]: any;
|
|
102
102
|
}
|
|
103
103
|
export type AgentSchema = AIAgentSchema | ImageAgentSchema | MCPAgentSchema | TeamAgentSchema | TransformAgentSchema | FunctionAgentSchema | ThirdAgentSchema;
|
|
104
|
-
export declare function parseAgentFile(path: string, data: any): Promise<AgentSchema>;
|
|
105
|
-
export declare function loadAgentFromYamlFile(path: string, options
|
|
104
|
+
export declare function parseAgentFile(path: string, data: any, options: LoadOptions): Promise<AgentSchema>;
|
|
105
|
+
export declare function loadAgentFromYamlFile(path: string, options: LoadOptions): Promise<AgentSchema>;
|
|
106
106
|
export declare const getInstructionsSchema: ({ filepath }: {
|
|
107
107
|
filepath: string;
|
|
108
108
|
}) => ZodType<Instructions>;
|
|
109
|
-
export declare const getAgentSchema: ({ filepath }: {
|
|
109
|
+
export declare const getAgentSchema: ({ filepath, options, }: {
|
|
110
110
|
filepath: string;
|
|
111
|
+
options?: LoadOptions;
|
|
111
112
|
}) => ZodType<AgentSchema, z.ZodTypeDef, AgentSchema>;
|
|
112
113
|
export declare const getNestAgentSchema: ({ filepath, }: {
|
|
113
114
|
filepath: string;
|
|
@@ -28,9 +28,9 @@ export interface LoadOptions {
|
|
|
28
28
|
}) => Promise<any>;
|
|
29
29
|
}
|
|
30
30
|
export declare function load(path: string, options?: LoadOptions): Promise<AIGNEOptions>;
|
|
31
|
-
export declare function loadAgent(path: string, options
|
|
32
|
-
export declare function loadNestAgent(path: string, agent: NestAgentSchema, options
|
|
33
|
-
export declare function parseAgent(path: string, agent: Awaited<ReturnType<typeof loadAgentFromYamlFile>>, options
|
|
31
|
+
export declare function loadAgent(path: string, options: LoadOptions, agentOptions?: AgentOptions): Promise<Agent>;
|
|
32
|
+
export declare function loadNestAgent(path: string, agent: NestAgentSchema, options: LoadOptions, agentOptions?: AgentOptions<any, any> & Record<string, unknown>): Promise<Agent>;
|
|
33
|
+
export declare function parseAgent(path: string, agent: Awaited<ReturnType<typeof loadAgentFromYamlFile>>, options: LoadOptions, agentOptions?: AgentOptions): Promise<Agent>;
|
|
34
34
|
type CliAgent = string | {
|
|
35
35
|
url?: string;
|
|
36
36
|
name?: string;
|
|
@@ -148,4 +148,5 @@ export declare function optionalize<T>(schema: ZodType<T>): ZodType<T | undefine
|
|
|
148
148
|
export declare function camelizeSchema<T extends ZodType>(schema: T, { shallow }?: {
|
|
149
149
|
shallow?: boolean;
|
|
150
150
|
}): T;
|
|
151
|
+
export declare function preprocessSchema<T extends ZodType>(fn: (data: unknown) => unknown, schema: T): T;
|
|
151
152
|
export {};
|
package/lib/esm/aigne/aigne.d.ts
CHANGED
|
@@ -113,6 +113,10 @@ export declare class AIGNE<U extends UserContext = UserContext> {
|
|
|
113
113
|
* @hidden
|
|
114
114
|
*/
|
|
115
115
|
readonly messageQueue: MessageQueue;
|
|
116
|
+
/**
|
|
117
|
+
* Collection of all context IDs created by this AIGNE instance.
|
|
118
|
+
*/
|
|
119
|
+
readonly contextIds: Set<string>;
|
|
116
120
|
/**
|
|
117
121
|
* Collection of skill agents available to this AIGNE instance.
|
|
118
122
|
* Provides indexed access by skill name.
|
|
@@ -324,7 +328,8 @@ export declare class AIGNE<U extends UserContext = UserContext> {
|
|
|
324
328
|
[Symbol.asyncDispose](): Promise<void>;
|
|
325
329
|
/**
|
|
326
330
|
* Initializes handlers for process exit events to ensure clean shutdown.
|
|
327
|
-
* This registers handlers for SIGINT
|
|
331
|
+
* This registers handlers for SIGINT/SIGTERM to properly terminate all agents.
|
|
332
|
+
* Note: 'exit' event cannot run async code, so we handle cleanup in signal handlers.
|
|
328
333
|
*/
|
|
329
334
|
private initProcessExitHandler;
|
|
330
335
|
}
|
package/lib/esm/aigne/aigne.js
CHANGED
|
@@ -96,6 +96,10 @@ export class AIGNE {
|
|
|
96
96
|
* @hidden
|
|
97
97
|
*/
|
|
98
98
|
messageQueue = new MessageQueue();
|
|
99
|
+
/**
|
|
100
|
+
* Collection of all context IDs created by this AIGNE instance.
|
|
101
|
+
*/
|
|
102
|
+
contextIds = new Set();
|
|
99
103
|
/**
|
|
100
104
|
* Collection of skill agents available to this AIGNE instance.
|
|
101
105
|
* Provides indexed access by skill name.
|
|
@@ -197,7 +201,7 @@ export class AIGNE {
|
|
|
197
201
|
*/
|
|
198
202
|
async shutdown() {
|
|
199
203
|
// Close observer first to flush any pending traces
|
|
200
|
-
await this.observer?.close();
|
|
204
|
+
await this.observer?.close(Array.from(this.contextIds));
|
|
201
205
|
for (const tool of this.skills) {
|
|
202
206
|
await tool.shutdown();
|
|
203
207
|
}
|
|
@@ -217,12 +221,17 @@ export class AIGNE {
|
|
|
217
221
|
}
|
|
218
222
|
/**
|
|
219
223
|
* Initializes handlers for process exit events to ensure clean shutdown.
|
|
220
|
-
* This registers handlers for SIGINT
|
|
224
|
+
* This registers handlers for SIGINT/SIGTERM to properly terminate all agents.
|
|
225
|
+
* Note: 'exit' event cannot run async code, so we handle cleanup in signal handlers.
|
|
221
226
|
*/
|
|
222
227
|
initProcessExitHandler() {
|
|
223
|
-
const
|
|
228
|
+
const originalExit = process.exit;
|
|
229
|
+
// @ts-ignore
|
|
230
|
+
process.exit = (...args) => {
|
|
231
|
+
this.shutdown().finally(() => originalExit(...args));
|
|
232
|
+
};
|
|
233
|
+
const shutdownAndExit = () => this.shutdown().finally(() => originalExit(0));
|
|
224
234
|
process.on("SIGINT", shutdownAndExit);
|
|
225
|
-
process.on("exit", shutdownAndExit);
|
|
226
235
|
}
|
|
227
236
|
}
|
|
228
237
|
const aigneOptionsSchema = z.object({
|
|
@@ -149,7 +149,6 @@ export interface Context<U extends UserContext = UserContext> extends TypedEvent
|
|
|
149
149
|
* @hidden
|
|
150
150
|
*/
|
|
151
151
|
export declare class AIGNEContext implements Context {
|
|
152
|
-
static exitCount: number;
|
|
153
152
|
constructor(parent?: ConstructorParameters<typeof AIGNEContextShared>[0], { reset }?: {
|
|
154
153
|
reset?: boolean;
|
|
155
154
|
});
|
|
@@ -183,7 +182,6 @@ export declare class AIGNEContext implements Context {
|
|
|
183
182
|
subscribe: Context["subscribe"];
|
|
184
183
|
unsubscribe: Context["unsubscribe"];
|
|
185
184
|
emit<K extends keyof ContextEmitEventMap>(eventName: K, ...args: Args<K, ContextEmitEventMap>): boolean;
|
|
186
|
-
initProcessExitHandler(): void;
|
|
187
185
|
private trace;
|
|
188
186
|
on<K extends keyof ContextEventMap>(eventName: K, listener: Listener<K, ContextEventMap>): this;
|
|
189
187
|
once<K extends keyof ContextEventMap>(eventName: K, listener: Listener<K, ContextEventMap>): this;
|
|
@@ -194,6 +192,7 @@ declare class AIGNEContextShared {
|
|
|
194
192
|
constructor(parent?: (Pick<Context, "model" | "imageModel" | "agents" | "skills" | "limits" | "observer" | "metadata"> & {
|
|
195
193
|
messageQueue?: MessageQueue;
|
|
196
194
|
events?: Emitter<any>;
|
|
195
|
+
contextIds?: Set<string>;
|
|
197
196
|
}) | undefined);
|
|
198
197
|
readonly messageQueue: MessageQueue;
|
|
199
198
|
readonly events: Emitter<any>;
|
|
@@ -205,6 +204,7 @@ declare class AIGNEContextShared {
|
|
|
205
204
|
get metadata(): AIGNEMetadata | undefined;
|
|
206
205
|
get limits(): ContextLimits | undefined;
|
|
207
206
|
usage: ContextUsage;
|
|
207
|
+
contextIds: Set<string>;
|
|
208
208
|
userContext: Context["userContext"];
|
|
209
209
|
memories: Context["memories"];
|
|
210
210
|
hooks: AgentHooks[];
|
package/lib/esm/aigne/context.js
CHANGED
|
@@ -17,7 +17,6 @@ import { newEmptyContextUsage } from "./usage.js";
|
|
|
17
17
|
* @hidden
|
|
18
18
|
*/
|
|
19
19
|
export class AIGNEContext {
|
|
20
|
-
static exitCount = 0;
|
|
21
20
|
constructor(parent, { reset } = {}) {
|
|
22
21
|
const tracer = parent?.observer?.tracer;
|
|
23
22
|
if (parent instanceof AIGNEContext && !reset) {
|
|
@@ -41,7 +40,7 @@ export class AIGNEContext {
|
|
|
41
40
|
this.rootId = this.span?.spanContext?.().traceId ?? v7();
|
|
42
41
|
}
|
|
43
42
|
this.id = this.span?.spanContext()?.spanId ?? v7();
|
|
44
|
-
this.
|
|
43
|
+
this.internal.contextIds.add(this.id);
|
|
45
44
|
}
|
|
46
45
|
id;
|
|
47
46
|
parentId;
|
|
@@ -197,26 +196,6 @@ export class AIGNEContext {
|
|
|
197
196
|
this.trace(eventName, args, b);
|
|
198
197
|
return this.internal.events.emit(eventName, ...newArgs);
|
|
199
198
|
}
|
|
200
|
-
initProcessExitHandler() {
|
|
201
|
-
if (this.parentId)
|
|
202
|
-
return;
|
|
203
|
-
AIGNEContext.exitCount++;
|
|
204
|
-
process.once("SIGINT", async () => {
|
|
205
|
-
try {
|
|
206
|
-
if (process.env.AIGNE_OBSERVABILITY_DISABLED)
|
|
207
|
-
return;
|
|
208
|
-
await this.observer?.update(this.id, {
|
|
209
|
-
status: { code: SpanStatusCode.ERROR, message: "SIGINT" },
|
|
210
|
-
});
|
|
211
|
-
}
|
|
212
|
-
finally {
|
|
213
|
-
AIGNEContext.exitCount--;
|
|
214
|
-
if (AIGNEContext.exitCount === 0) {
|
|
215
|
-
process.exit(0);
|
|
216
|
-
}
|
|
217
|
-
}
|
|
218
|
-
});
|
|
219
|
-
}
|
|
220
199
|
async trace(eventName, args, b) {
|
|
221
200
|
if (process.env.AIGNE_OBSERVABILITY_DISABLED)
|
|
222
201
|
return;
|
|
@@ -252,12 +231,14 @@ export class AIGNEContext {
|
|
|
252
231
|
await this.observer?.update(this.id, { output });
|
|
253
232
|
span.setStatus({ code: SpanStatusCode.OK });
|
|
254
233
|
span.end();
|
|
234
|
+
this.internal.contextIds.delete(this.id);
|
|
255
235
|
break;
|
|
256
236
|
}
|
|
257
237
|
case "agentFailed": {
|
|
258
238
|
const { error } = args[0];
|
|
259
239
|
span.setStatus({ code: SpanStatusCode.ERROR, message: error.message });
|
|
260
240
|
span.end();
|
|
241
|
+
this.internal.contextIds.delete(this.id);
|
|
261
242
|
break;
|
|
262
243
|
}
|
|
263
244
|
}
|
|
@@ -285,6 +266,7 @@ class AIGNEContextShared {
|
|
|
285
266
|
this.parent = parent;
|
|
286
267
|
this.messageQueue = this.parent?.messageQueue ?? new MessageQueue();
|
|
287
268
|
this.events = this.parent?.events ?? new Emitter();
|
|
269
|
+
this.contextIds = this.parent?.contextIds ?? new Set();
|
|
288
270
|
}
|
|
289
271
|
messageQueue;
|
|
290
272
|
events;
|
|
@@ -310,6 +292,7 @@ class AIGNEContextShared {
|
|
|
310
292
|
return this.parent?.limits;
|
|
311
293
|
}
|
|
312
294
|
usage = newEmptyContextUsage();
|
|
295
|
+
contextIds;
|
|
313
296
|
userContext = {};
|
|
314
297
|
memories = [];
|
|
315
298
|
hooks = [];
|
|
@@ -1 +1,2 @@
|
|
|
1
|
-
|
|
1
|
+
import type { LoadOptions } from "./index.js";
|
|
2
|
+
export declare function loadAgentFromJsFile(path: string, options: LoadOptions): Promise<import("../index.js").Agent<any, any> | import("./agent-yaml.js").AgentSchema>;
|
|
@@ -4,7 +4,7 @@ import { tryOrThrow } from "../utils/type-utils.js";
|
|
|
4
4
|
import { parseAgentFile } from "./agent-yaml.js";
|
|
5
5
|
import { LoadJsAgentError } from "./error.js";
|
|
6
6
|
const importFn = new Function("path", "return import(path)");
|
|
7
|
-
export async function loadAgentFromJsFile(path) {
|
|
7
|
+
export async function loadAgentFromJsFile(path, options) {
|
|
8
8
|
const url = nodejs.path.isAbsolute(path) ? nodejs.url.pathToFileURL(path).toString() : path;
|
|
9
9
|
const { default: agent } = await tryOrThrow(() => importFn(url), (error) => new LoadJsAgentError(`Failed to load agent definition from ${url}: ${error.message}`));
|
|
10
10
|
if (isAgent(agent))
|
|
@@ -14,5 +14,5 @@ export async function loadAgentFromJsFile(path) {
|
|
|
14
14
|
process: agent,
|
|
15
15
|
name: agent.agent_name || agent.agentName || agent.name,
|
|
16
16
|
...agent,
|
|
17
|
-
}), (error) => new Error(`Failed to parse agent from ${path}: ${error.message}`));
|
|
17
|
+
}, options), (error) => new Error(`Failed to parse agent from ${path}: ${error.message}`));
|
|
18
18
|
}
|
|
@@ -101,13 +101,14 @@ export interface ThirdAgentSchema extends BaseAgentSchema {
|
|
|
101
101
|
[key: string]: any;
|
|
102
102
|
}
|
|
103
103
|
export type AgentSchema = AIAgentSchema | ImageAgentSchema | MCPAgentSchema | TeamAgentSchema | TransformAgentSchema | FunctionAgentSchema | ThirdAgentSchema;
|
|
104
|
-
export declare function parseAgentFile(path: string, data: any): Promise<AgentSchema>;
|
|
105
|
-
export declare function loadAgentFromYamlFile(path: string, options
|
|
104
|
+
export declare function parseAgentFile(path: string, data: any, options: LoadOptions): Promise<AgentSchema>;
|
|
105
|
+
export declare function loadAgentFromYamlFile(path: string, options: LoadOptions): Promise<AgentSchema>;
|
|
106
106
|
export declare const getInstructionsSchema: ({ filepath }: {
|
|
107
107
|
filepath: string;
|
|
108
108
|
}) => ZodType<Instructions>;
|
|
109
|
-
export declare const getAgentSchema: ({ filepath }: {
|
|
109
|
+
export declare const getAgentSchema: ({ filepath, options, }: {
|
|
110
110
|
filepath: string;
|
|
111
|
+
options?: LoadOptions;
|
|
111
112
|
}) => ZodType<AgentSchema, z.ZodTypeDef, AgentSchema>;
|
|
112
113
|
export declare const getNestAgentSchema: ({ filepath, }: {
|
|
113
114
|
filepath: string;
|
|
@@ -7,9 +7,9 @@ import { roleSchema } from "../agents/chat-model.js";
|
|
|
7
7
|
import { ProcessMode } from "../agents/team-agent.js";
|
|
8
8
|
import { tryOrThrow } from "../utils/type-utils.js";
|
|
9
9
|
import { codeToFunctionAgentFn } from "./function-agent.js";
|
|
10
|
-
import { camelizeSchema, chatModelSchema, defaultInputSchema, imageModelSchema, inputOutputSchema, optionalize, } from "./schema.js";
|
|
11
|
-
export async function parseAgentFile(path, data) {
|
|
12
|
-
const agentSchema = getAgentSchema({ filepath: path });
|
|
10
|
+
import { camelizeSchema, chatModelSchema, defaultInputSchema, imageModelSchema, inputOutputSchema, optionalize, preprocessSchema, } from "./schema.js";
|
|
11
|
+
export async function parseAgentFile(path, data, options) {
|
|
12
|
+
const agentSchema = getAgentSchema({ filepath: path, options });
|
|
13
13
|
return agentSchema.parseAsync({
|
|
14
14
|
...data,
|
|
15
15
|
model: data.model || data.chatModel || data.chat_model,
|
|
@@ -18,22 +18,11 @@ export async function parseAgentFile(path, data) {
|
|
|
18
18
|
export async function loadAgentFromYamlFile(path, options) {
|
|
19
19
|
const raw = await tryOrThrow(() => nodejs.fs.readFile(path, "utf8"), (error) => new Error(`Failed to load agent definition from ${path}: ${error.message}`));
|
|
20
20
|
const json = tryOrThrow(() => parse(raw), (error) => new Error(`Failed to parse agent definition from ${path}: ${error.message}`));
|
|
21
|
-
if (!["ai", "image", "mcp", "team", "transform", "function"].includes(json?.type)) {
|
|
22
|
-
if (typeof json?.type === "string") {
|
|
23
|
-
if (!options?.require)
|
|
24
|
-
throw new Error(`Module loader is not provided to load agent type module ${json.type} from ${path}`);
|
|
25
|
-
const Mod = await options.require(json.type, { parent: path });
|
|
26
|
-
if (typeof Mod?.default?.prototype?.constructor !== "function") {
|
|
27
|
-
throw new Error(`The agent type module ${json.type} does not export a default Agent class`);
|
|
28
|
-
}
|
|
29
|
-
json.agentClass = Mod.default;
|
|
30
|
-
}
|
|
31
|
-
}
|
|
32
21
|
const agent = await tryOrThrow(async () => await parseAgentFile(path, {
|
|
33
22
|
...json,
|
|
34
23
|
type: json.type ?? "ai",
|
|
35
24
|
skills: json.skills ?? json.tools,
|
|
36
|
-
}), (error) => new Error(`Failed to validate agent definition from ${path}: ${error.message}`));
|
|
25
|
+
}, options), (error) => new Error(`Failed to validate agent definition from ${path}: ${error.message}`));
|
|
37
26
|
return agent;
|
|
38
27
|
}
|
|
39
28
|
const instructionItemSchema = z.union([
|
|
@@ -70,7 +59,7 @@ export const getInstructionsSchema = ({ filepath }) => z
|
|
|
70
59
|
}
|
|
71
60
|
return [await parseInstructionItem({ filepath })(v)];
|
|
72
61
|
});
|
|
73
|
-
export const getAgentSchema = ({ filepath }) => {
|
|
62
|
+
export const getAgentSchema = ({ filepath, options, }) => {
|
|
74
63
|
const agentSchema = z.lazy(() => {
|
|
75
64
|
const nestAgentSchema = z.lazy(() => z.union([
|
|
76
65
|
agentSchema,
|
|
@@ -127,7 +116,22 @@ export const getAgentSchema = ({ filepath }) => {
|
|
|
127
116
|
shareAFS: optionalize(z.boolean()),
|
|
128
117
|
});
|
|
129
118
|
const instructionsSchema = getInstructionsSchema({ filepath: filepath });
|
|
130
|
-
return camelizeSchema(
|
|
119
|
+
return camelizeSchema(preprocessSchema(async (json) => {
|
|
120
|
+
if (typeof json === "object" &&
|
|
121
|
+
json &&
|
|
122
|
+
"type" in json &&
|
|
123
|
+
typeof json.type === "string" &&
|
|
124
|
+
!["ai", "image", "mcp", "team", "transform", "function"].includes(json.type)) {
|
|
125
|
+
if (!options?.require)
|
|
126
|
+
throw new Error(`Module loader is not provided to load agent type module ${json.type} from ${filepath}`);
|
|
127
|
+
const Mod = await options.require(json.type, { parent: filepath });
|
|
128
|
+
if (typeof Mod?.default?.prototype?.constructor !== "function") {
|
|
129
|
+
throw new Error(`The agent type module ${json.type} does not export a default Agent class`);
|
|
130
|
+
}
|
|
131
|
+
Object.assign(json, { agentClass: Mod.default });
|
|
132
|
+
}
|
|
133
|
+
return json;
|
|
134
|
+
}, z.union([
|
|
131
135
|
z
|
|
132
136
|
.object({
|
|
133
137
|
type: z.string(),
|
|
@@ -198,7 +202,7 @@ export const getAgentSchema = ({ filepath }) => {
|
|
|
198
202
|
})
|
|
199
203
|
.extend(baseAgentSchema.shape),
|
|
200
204
|
]),
|
|
201
|
-
]));
|
|
205
|
+
])));
|
|
202
206
|
});
|
|
203
207
|
return agentSchema;
|
|
204
208
|
};
|
|
@@ -28,9 +28,9 @@ export interface LoadOptions {
|
|
|
28
28
|
}) => Promise<any>;
|
|
29
29
|
}
|
|
30
30
|
export declare function load(path: string, options?: LoadOptions): Promise<AIGNEOptions>;
|
|
31
|
-
export declare function loadAgent(path: string, options
|
|
32
|
-
export declare function loadNestAgent(path: string, agent: NestAgentSchema, options
|
|
33
|
-
export declare function parseAgent(path: string, agent: Awaited<ReturnType<typeof loadAgentFromYamlFile>>, options
|
|
31
|
+
export declare function loadAgent(path: string, options: LoadOptions, agentOptions?: AgentOptions): Promise<Agent>;
|
|
32
|
+
export declare function loadNestAgent(path: string, agent: NestAgentSchema, options: LoadOptions, agentOptions?: AgentOptions<any, any> & Record<string, unknown>): Promise<Agent>;
|
|
33
|
+
export declare function parseAgent(path: string, agent: Awaited<ReturnType<typeof loadAgentFromYamlFile>>, options: LoadOptions, agentOptions?: AgentOptions): Promise<Agent>;
|
|
34
34
|
type CliAgent = string | {
|
|
35
35
|
url?: string;
|
|
36
36
|
name?: string;
|
package/lib/esm/loader/index.js
CHANGED
|
@@ -61,7 +61,7 @@ export async function load(path, options = {}) {
|
|
|
61
61
|
}
|
|
62
62
|
export async function loadAgent(path, options, agentOptions) {
|
|
63
63
|
if ([".js", ".mjs", ".ts", ".mts"].includes(nodejs.path.extname(path))) {
|
|
64
|
-
const agent = await loadAgentFromJsFile(path);
|
|
64
|
+
const agent = await loadAgentFromJsFile(path, options);
|
|
65
65
|
if (agent instanceof Agent)
|
|
66
66
|
return agent;
|
|
67
67
|
return parseAgent(path, agent, options, agentOptions);
|
|
@@ -148,4 +148,5 @@ export declare function optionalize<T>(schema: ZodType<T>): ZodType<T | undefine
|
|
|
148
148
|
export declare function camelizeSchema<T extends ZodType>(schema: T, { shallow }?: {
|
|
149
149
|
shallow?: boolean;
|
|
150
150
|
}): T;
|
|
151
|
+
export declare function preprocessSchema<T extends ZodType>(fn: (data: unknown) => unknown, schema: T): T;
|
|
151
152
|
export {};
|
package/lib/esm/loader/schema.js
CHANGED
|
@@ -91,3 +91,6 @@ export function optionalize(schema) {
|
|
|
91
91
|
export function camelizeSchema(schema, { shallow = true } = {}) {
|
|
92
92
|
return z.preprocess((v) => (isRecord(v) ? camelize(v, shallow) : v), schema);
|
|
93
93
|
}
|
|
94
|
+
export function preprocessSchema(fn, schema) {
|
|
95
|
+
return z.preprocess(fn, schema);
|
|
96
|
+
}
|
|
@@ -19,6 +19,7 @@ export async function getAFSSkills(afs) {
|
|
|
19
19
|
return {
|
|
20
20
|
status: "success",
|
|
21
21
|
tool: "afs_list",
|
|
22
|
+
path: input.path,
|
|
22
23
|
options: input.options,
|
|
23
24
|
message,
|
|
24
25
|
result,
|
|
@@ -36,6 +37,10 @@ export async function getAFSSkills(afs) {
|
|
|
36
37
|
options: z
|
|
37
38
|
.object({
|
|
38
39
|
limit: z.number().optional().describe("Maximum number of entries to return"),
|
|
40
|
+
caseSensitive: z
|
|
41
|
+
.boolean()
|
|
42
|
+
.optional()
|
|
43
|
+
.describe("Whether the search is case sensitive, default is false"),
|
|
39
44
|
})
|
|
40
45
|
.optional(),
|
|
41
46
|
}),
|
|
@@ -44,6 +49,7 @@ export async function getAFSSkills(afs) {
|
|
|
44
49
|
return {
|
|
45
50
|
status: "success",
|
|
46
51
|
tool: "afs_search",
|
|
52
|
+
path: input.path,
|
|
47
53
|
query: input.query,
|
|
48
54
|
options: input.options,
|
|
49
55
|
...result,
|
|
@@ -80,6 +86,7 @@ Usage:
|
|
|
80
86
|
status: "success",
|
|
81
87
|
tool: "afs_read",
|
|
82
88
|
path: input.path,
|
|
89
|
+
withLineNumbers: input.withLineNumbers,
|
|
83
90
|
...result,
|
|
84
91
|
result: {
|
|
85
92
|
...result.result,
|
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import { createParser } from "eventsource-parser";
|
|
2
|
-
import { produce } from "immer";
|
|
2
|
+
import { produce, setAutoFreeze } from "immer";
|
|
3
3
|
import { isAgentResponseDelta, isAgentResponseProgress, } from "../agents/agent.js";
|
|
4
4
|
import { tryOrThrow } from "./type-utils.js";
|
|
5
|
+
setAutoFreeze(false);
|
|
5
6
|
export class EventStreamParser extends TransformStream {
|
|
6
7
|
constructor() {
|
|
7
8
|
let parser;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@aigne/core",
|
|
3
|
-
"version": "1.71.0-beta.
|
|
3
|
+
"version": "1.71.0-beta.4",
|
|
4
4
|
"description": "The functional core of agentic AI",
|
|
5
5
|
"publishConfig": {
|
|
6
6
|
"access": "public"
|
|
@@ -92,10 +92,10 @@
|
|
|
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/afs": "^1.3.0-beta",
|
|
96
|
-
"@aigne/afs-history": "^1.1.3-beta",
|
|
97
|
-
"@aigne/
|
|
98
|
-
"@aigne/
|
|
95
|
+
"@aigne/afs": "^1.3.0-beta.2",
|
|
96
|
+
"@aigne/afs-history": "^1.1.3-beta.2",
|
|
97
|
+
"@aigne/platform-helpers": "^0.6.6-beta",
|
|
98
|
+
"@aigne/observability-api": "^0.11.13-beta.1"
|
|
99
99
|
},
|
|
100
100
|
"devDependencies": {
|
|
101
101
|
"@types/bun": "^1.2.22",
|