@aigne/core 1.71.0-beta.2 → 1.71.0-beta.5

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.
Files changed (94) hide show
  1. package/CHANGELOG.md +56 -0
  2. package/lib/cjs/agents/agent.d.ts +1 -1
  3. package/lib/cjs/agents/agent.js +1 -1
  4. package/lib/cjs/agents/user-agent.js +1 -1
  5. package/lib/cjs/aigne/aigne.d.ts +6 -1
  6. package/lib/cjs/aigne/aigne.js +13 -4
  7. package/lib/cjs/aigne/context.d.ts +2 -2
  8. package/lib/cjs/aigne/context.js +5 -22
  9. package/lib/cjs/loader/agent-js.d.ts +2 -1
  10. package/lib/cjs/loader/agent-js.js +2 -2
  11. package/lib/cjs/loader/agent-yaml.d.ts +4 -3
  12. package/lib/cjs/loader/agent-yaml.js +21 -17
  13. package/lib/cjs/loader/index.d.ts +3 -3
  14. package/lib/cjs/loader/index.js +1 -1
  15. package/lib/cjs/loader/schema.d.ts +1 -0
  16. package/lib/cjs/loader/schema.js +4 -0
  17. package/lib/cjs/memory/recorder.js +1 -1
  18. package/lib/cjs/memory/retriever.js +1 -1
  19. package/lib/cjs/prompt/prompt-builder.js +3 -3
  20. package/lib/cjs/prompt/skills/afs/delete.d.ts +18 -0
  21. package/lib/cjs/prompt/skills/afs/delete.js +42 -0
  22. package/lib/cjs/prompt/skills/afs/edit.d.ts +26 -0
  23. package/lib/cjs/prompt/skills/afs/edit.js +98 -0
  24. package/lib/cjs/prompt/skills/afs/exec.d.ts +15 -0
  25. package/lib/cjs/prompt/skills/afs/exec.js +27 -0
  26. package/lib/cjs/prompt/skills/{afs.d.ts → afs/index.d.ts} +1 -1
  27. package/lib/cjs/prompt/skills/afs/index.js +23 -0
  28. package/lib/cjs/prompt/skills/afs/list.d.ts +22 -0
  29. package/lib/cjs/prompt/skills/afs/list.js +90 -0
  30. package/lib/cjs/prompt/skills/afs/read.d.ts +21 -0
  31. package/lib/cjs/prompt/skills/afs/read.js +53 -0
  32. package/lib/cjs/prompt/skills/afs/rename.d.ts +20 -0
  33. package/lib/cjs/prompt/skills/afs/rename.js +45 -0
  34. package/lib/cjs/prompt/skills/afs/search.d.ts +23 -0
  35. package/lib/cjs/prompt/skills/afs/search.js +55 -0
  36. package/lib/cjs/prompt/skills/afs/write.d.ts +19 -0
  37. package/lib/cjs/prompt/skills/afs/write.js +45 -0
  38. package/lib/cjs/utils/event-stream.js +1 -0
  39. package/lib/dts/agents/agent.d.ts +1 -1
  40. package/lib/dts/aigne/aigne.d.ts +6 -1
  41. package/lib/dts/aigne/context.d.ts +2 -2
  42. package/lib/dts/loader/agent-js.d.ts +2 -1
  43. package/lib/dts/loader/agent-yaml.d.ts +4 -3
  44. package/lib/dts/loader/index.d.ts +3 -3
  45. package/lib/dts/loader/schema.d.ts +1 -0
  46. package/lib/dts/prompt/skills/afs/delete.d.ts +18 -0
  47. package/lib/dts/prompt/skills/afs/edit.d.ts +26 -0
  48. package/lib/dts/prompt/skills/afs/exec.d.ts +15 -0
  49. package/lib/dts/prompt/skills/{afs.d.ts → afs/index.d.ts} +1 -1
  50. package/lib/dts/prompt/skills/afs/list.d.ts +22 -0
  51. package/lib/dts/prompt/skills/afs/read.d.ts +21 -0
  52. package/lib/dts/prompt/skills/afs/rename.d.ts +20 -0
  53. package/lib/dts/prompt/skills/afs/search.d.ts +23 -0
  54. package/lib/dts/prompt/skills/afs/write.d.ts +19 -0
  55. package/lib/esm/agents/agent.d.ts +1 -1
  56. package/lib/esm/agents/agent.js +1 -1
  57. package/lib/esm/agents/user-agent.js +1 -1
  58. package/lib/esm/aigne/aigne.d.ts +6 -1
  59. package/lib/esm/aigne/aigne.js +13 -4
  60. package/lib/esm/aigne/context.d.ts +2 -2
  61. package/lib/esm/aigne/context.js +5 -22
  62. package/lib/esm/loader/agent-js.d.ts +2 -1
  63. package/lib/esm/loader/agent-js.js +2 -2
  64. package/lib/esm/loader/agent-yaml.d.ts +4 -3
  65. package/lib/esm/loader/agent-yaml.js +22 -18
  66. package/lib/esm/loader/index.d.ts +3 -3
  67. package/lib/esm/loader/index.js +1 -1
  68. package/lib/esm/loader/schema.d.ts +1 -0
  69. package/lib/esm/loader/schema.js +3 -0
  70. package/lib/esm/memory/recorder.js +1 -1
  71. package/lib/esm/memory/retriever.js +1 -1
  72. package/lib/esm/prompt/prompt-builder.js +1 -1
  73. package/lib/esm/prompt/skills/afs/delete.d.ts +18 -0
  74. package/lib/esm/prompt/skills/afs/delete.js +38 -0
  75. package/lib/esm/prompt/skills/afs/edit.d.ts +26 -0
  76. package/lib/esm/prompt/skills/afs/edit.js +94 -0
  77. package/lib/esm/prompt/skills/afs/exec.d.ts +15 -0
  78. package/lib/esm/prompt/skills/afs/exec.js +23 -0
  79. package/lib/esm/prompt/skills/{afs.d.ts → afs/index.d.ts} +1 -1
  80. package/lib/esm/prompt/skills/afs/index.js +20 -0
  81. package/lib/esm/prompt/skills/afs/list.d.ts +22 -0
  82. package/lib/esm/prompt/skills/afs/list.js +86 -0
  83. package/lib/esm/prompt/skills/afs/read.d.ts +21 -0
  84. package/lib/esm/prompt/skills/afs/read.js +49 -0
  85. package/lib/esm/prompt/skills/afs/rename.d.ts +20 -0
  86. package/lib/esm/prompt/skills/afs/rename.js +41 -0
  87. package/lib/esm/prompt/skills/afs/search.d.ts +23 -0
  88. package/lib/esm/prompt/skills/afs/search.js +51 -0
  89. package/lib/esm/prompt/skills/afs/write.d.ts +19 -0
  90. package/lib/esm/prompt/skills/afs/write.js +41 -0
  91. package/lib/esm/utils/event-stream.js +2 -1
  92. package/package.json +5 -5
  93. package/lib/cjs/prompt/skills/afs.js +0 -170
  94. package/lib/esm/prompt/skills/afs.js +0 -167
package/CHANGELOG.md CHANGED
@@ -1,5 +1,61 @@
1
1
  # Changelog
2
2
 
3
+ ## [1.71.0-beta.5](https://github.com/AIGNE-io/aigne-framework/compare/core-v1.71.0-beta.4...core-v1.71.0-beta.5) (2025-12-11)
4
+
5
+
6
+ ### Features
7
+
8
+ * **afs:** add edit/delete/rename methods for AFS ([#820](https://github.com/AIGNE-io/aigne-framework/issues/820)) ([68cb508](https://github.com/AIGNE-io/aigne-framework/commit/68cb508d1cfc9c516d56303018139f1e567f897e))
9
+
10
+
11
+ ### Bug Fixes
12
+
13
+ * **core:** support access agent instance by `this` in function agent ([#822](https://github.com/AIGNE-io/aigne-framework/issues/822)) ([68103bc](https://github.com/AIGNE-io/aigne-framework/commit/68103bc8d6d553e1c1374595db98ff61f3046842))
14
+
15
+
16
+ ### Dependencies
17
+
18
+ * The following workspace dependencies were updated
19
+ * dependencies
20
+ * @aigne/afs bumped to 1.3.0-beta.3
21
+ * @aigne/afs-history bumped to 1.1.3-beta.3
22
+
23
+ ## [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)
24
+
25
+
26
+ ### Bug Fixes
27
+
28
+ * bump version ([af04b69](https://github.com/AIGNE-io/aigne-framework/commit/af04b6931951afa35d52065430acc7fef4b10087))
29
+ * **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))
30
+
31
+
32
+ ### Dependencies
33
+
34
+ * The following workspace dependencies were updated
35
+ * dependencies
36
+ * @aigne/afs bumped to 1.3.0-beta.2
37
+ * @aigne/afs-history bumped to 1.1.3-beta.2
38
+ * @aigne/observability-api bumped to 0.11.13-beta.1
39
+ * @aigne/platform-helpers bumped to 0.6.6-beta
40
+
41
+ ## [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)
42
+
43
+
44
+ ### Bug Fixes
45
+
46
+ * **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))
47
+ * **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))
48
+ * **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))
49
+
50
+
51
+ ### Dependencies
52
+
53
+ * The following workspace dependencies were updated
54
+ * dependencies
55
+ * @aigne/afs bumped to 1.3.0-beta.1
56
+ * @aigne/afs-history bumped to 1.1.3-beta.1
57
+ * @aigne/observability-api bumped to 0.11.13-beta
58
+
3
59
  ## [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
60
 
5
61
 
@@ -938,4 +938,4 @@ export declare class FunctionAgent<I extends Message = Message, O extends Messag
938
938
  * @param context Execution context
939
939
  * @returns Processing result, can be synchronous or asynchronous
940
940
  */
941
- export type FunctionAgentFn<I extends Message = any, O extends Message = any> = (input: I, options: AgentInvokeOptions) => PromiseOrValue<AgentProcessResult<O>>;
941
+ export type FunctionAgentFn<I extends Message = any, O extends Message = any, A extends FunctionAgent<I, O> = FunctionAgent<I, O>> = (this: A, input: I, options: AgentInvokeOptions) => PromiseOrValue<AgentProcessResult<O>>;
@@ -917,7 +917,7 @@ class FunctionAgent extends Agent {
917
917
  * @returns Processing result
918
918
  */
919
919
  process(input, options) {
920
- return this._process(input, options);
920
+ return this._process.apply(this, [input, options]);
921
921
  }
922
922
  }
923
923
  exports.FunctionAgent = FunctionAgent;
@@ -32,7 +32,7 @@ class UserAgent extends agent_js_1.Agent {
32
32
  });
33
33
  async process(input, options) {
34
34
  if (this._process) {
35
- return this._process(input, options);
35
+ return this._process.apply(this, [input, options]);
36
36
  }
37
37
  if (this.activeAgent) {
38
38
  const [output, agent] = await this.invokeChildAgent(this.activeAgent, input, {
@@ -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 and exit events to properly terminate all agents.
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
  }
@@ -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 and exit events to properly terminate all agents.
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 shutdownAndExit = () => this.shutdown();
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[];
@@ -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.initProcessExitHandler();
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
- export declare function loadAgentFromJsFile(path: string): Promise<import("../index.js").Agent<any, any> | import("./agent-yaml.js").AgentSchema>;
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?: LoadOptions): Promise<AgentSchema>;
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)(zod_1.z.union([
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?: 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>;
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;
@@ -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 {};
@@ -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
+ }
@@ -57,7 +57,7 @@ class MemoryRecorder extends agent_js_1.Agent {
57
57
  if (!this._process) {
58
58
  throw new Error("MemoryRecorder process function is not defined.");
59
59
  }
60
- return this._process(input, options);
60
+ return this._process.apply(this, [input, options]);
61
61
  }
62
62
  }
63
63
  exports.MemoryRecorder = MemoryRecorder;
@@ -54,7 +54,7 @@ class MemoryRetriever extends agent_js_1.Agent {
54
54
  if (!this._process) {
55
55
  throw new Error("MemoryRetriever process function is not implemented.");
56
56
  }
57
- return this._process(input, options);
57
+ return this._process.apply(this, [input, options]);
58
58
  }
59
59
  }
60
60
  exports.MemoryRetriever = MemoryRetriever;
@@ -15,7 +15,7 @@ const type_utils_js_1 = require("../utils/type-utils.js");
15
15
  const afs_builtin_prompt_js_1 = require("./prompts/afs-builtin-prompt.js");
16
16
  const memory_message_template_js_1 = require("./prompts/memory-message-template.js");
17
17
  const structured_stream_instructions_js_1 = require("./prompts/structured-stream-instructions.js");
18
- const afs_js_1 = require("./skills/afs.js");
18
+ const index_js_2 = require("./skills/afs/index.js");
19
19
  const template_js_1 = require("./template.js");
20
20
  class PromptBuilder {
21
21
  static from(instructions, { workingDir } = {}) {
@@ -117,7 +117,7 @@ class PromptBuilder {
117
117
  const afs = options.agent?.afs;
118
118
  if (!afs)
119
119
  return [];
120
- return (0, afs_js_1.getAFSSkills)(afs).then((skills) => skills.map((s) => (0, type_utils_js_1.pick)(s, ["name", "description"])));
120
+ return (0, index_js_2.getAFSSkills)(afs).then((skills) => skills.map((s) => (0, type_utils_js_1.pick)(s, ["name", "description"])));
121
121
  },
122
122
  },
123
123
  $agent: {
@@ -364,7 +364,7 @@ class PromptBuilder {
364
364
  .concat(options.agent?.memoryAgentsAsTools ? options.agent.memories : [])
365
365
  .flatMap((i) => (i.isInvokable ? i : i.skills)), (i) => i.name);
366
366
  if (options.agent?.afs) {
367
- toolAgents.push(...(await (0, afs_js_1.getAFSSkills)(options.agent.afs)));
367
+ toolAgents.push(...(await (0, index_js_2.getAFSSkills)(options.agent.afs)));
368
368
  }
369
369
  const tools = toolAgents.map((i) => ({
370
370
  type: "function",
@@ -0,0 +1,18 @@
1
+ import { Agent, type AgentInvokeOptions, type AgentOptions, type Message } from "../../../agents/agent.js";
2
+ export interface AFSDeleteInput extends Message {
3
+ path: string;
4
+ recursive?: boolean;
5
+ }
6
+ export interface AFSDeleteOutput extends Message {
7
+ status: string;
8
+ tool: string;
9
+ path: string;
10
+ message?: string;
11
+ }
12
+ export interface AFSDeleteAgentOptions extends AgentOptions<AFSDeleteInput, AFSDeleteOutput> {
13
+ afs: NonNullable<AgentOptions<AFSDeleteInput, AFSDeleteOutput>["afs"]>;
14
+ }
15
+ export declare class AFSDeleteAgent extends Agent<AFSDeleteInput, AFSDeleteOutput> {
16
+ constructor(options: AFSDeleteAgentOptions);
17
+ process(input: AFSDeleteInput, _options: AgentInvokeOptions): Promise<AFSDeleteOutput>;
18
+ }
@@ -0,0 +1,42 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.AFSDeleteAgent = void 0;
4
+ const zod_1 = require("zod");
5
+ const agent_js_1 = require("../../../agents/agent.js");
6
+ class AFSDeleteAgent extends agent_js_1.Agent {
7
+ constructor(options) {
8
+ super({
9
+ name: "afs_delete",
10
+ description: "Permanently delete files or directories. Use when removing unwanted files or cleaning up temporary data.",
11
+ ...options,
12
+ inputSchema: zod_1.z.object({
13
+ path: zod_1.z.string().describe("Absolute file or directory path to delete"),
14
+ recursive: zod_1.z
15
+ .boolean()
16
+ .optional()
17
+ .default(false)
18
+ .describe("Allow directory deletion (default: false, required for directories)"),
19
+ }),
20
+ outputSchema: zod_1.z.object({
21
+ status: zod_1.z.string(),
22
+ tool: zod_1.z.string(),
23
+ path: zod_1.z.string(),
24
+ message: zod_1.z.string().optional(),
25
+ }),
26
+ });
27
+ }
28
+ async process(input, _options) {
29
+ if (!this.afs)
30
+ throw new Error("AFS is not configured for this agent.");
31
+ const result = await this.afs.delete(input.path, {
32
+ recursive: input.recursive ?? false,
33
+ });
34
+ return {
35
+ status: "success",
36
+ tool: "afs_delete",
37
+ path: input.path,
38
+ ...result,
39
+ };
40
+ }
41
+ }
42
+ exports.AFSDeleteAgent = AFSDeleteAgent;
@@ -0,0 +1,26 @@
1
+ import { Agent, type AgentInvokeOptions, type AgentOptions, type Message } from "../../../agents/agent.js";
2
+ export interface Patch {
3
+ start_line: number;
4
+ end_line: number;
5
+ replace?: string;
6
+ delete: boolean;
7
+ }
8
+ export interface AFSEditInput extends Message {
9
+ path: string;
10
+ patches: Patch[];
11
+ }
12
+ export interface AFSEditOutput extends Message {
13
+ status: string;
14
+ tool: string;
15
+ path: string;
16
+ message: string;
17
+ content: string;
18
+ }
19
+ export interface AFSEditAgentOptions extends AgentOptions<AFSEditInput, AFSEditOutput> {
20
+ afs: NonNullable<AgentOptions<AFSEditInput, AFSEditOutput>["afs"]>;
21
+ }
22
+ export declare class AFSEditAgent extends Agent<AFSEditInput, AFSEditOutput> {
23
+ constructor(options: AFSEditAgentOptions);
24
+ process(input: AFSEditInput, _options: AgentInvokeOptions): Promise<AFSEditOutput>;
25
+ applyCustomPatches(text: string, patches: Patch[]): string;
26
+ }