@aigne/core 1.28.1 → 1.29.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (46) hide show
  1. package/CHANGELOG.md +21 -0
  2. package/lib/cjs/agents/agent.d.ts +1 -0
  3. package/lib/cjs/agents/agent.js +9 -5
  4. package/lib/cjs/agents/team-agent.d.ts +59 -2
  5. package/lib/cjs/agents/team-agent.js +54 -0
  6. package/lib/cjs/agents/transform-agent.d.ts +82 -0
  7. package/lib/cjs/agents/transform-agent.js +67 -0
  8. package/lib/cjs/index.d.ts +1 -0
  9. package/lib/cjs/index.js +1 -0
  10. package/lib/cjs/loader/agent-js.d.ts +2 -2
  11. package/lib/cjs/loader/agent-js.js +11 -15
  12. package/lib/cjs/loader/agent-yaml.d.ts +35 -44
  13. package/lib/cjs/loader/agent-yaml.js +58 -103
  14. package/lib/cjs/loader/index.js +28 -11
  15. package/lib/cjs/loader/schema.d.ts +2 -1
  16. package/lib/cjs/loader/schema.js +4 -0
  17. package/lib/cjs/utils/logger.js +1 -1
  18. package/lib/dts/agents/agent.d.ts +1 -0
  19. package/lib/dts/agents/team-agent.d.ts +59 -2
  20. package/lib/dts/agents/transform-agent.d.ts +82 -0
  21. package/lib/dts/index.d.ts +1 -0
  22. package/lib/dts/loader/agent-js.d.ts +2 -2
  23. package/lib/dts/loader/agent-yaml.d.ts +35 -44
  24. package/lib/dts/loader/schema.d.ts +2 -1
  25. package/lib/esm/agents/agent.d.ts +1 -0
  26. package/lib/esm/agents/agent.js +8 -5
  27. package/lib/esm/agents/team-agent.d.ts +59 -2
  28. package/lib/esm/agents/team-agent.js +53 -2
  29. package/lib/esm/agents/transform-agent.d.ts +82 -0
  30. package/lib/esm/agents/transform-agent.js +60 -0
  31. package/lib/esm/index.d.ts +1 -0
  32. package/lib/esm/index.js +1 -0
  33. package/lib/esm/loader/agent-js.d.ts +2 -2
  34. package/lib/esm/loader/agent-js.js +9 -16
  35. package/lib/esm/loader/agent-yaml.d.ts +35 -44
  36. package/lib/esm/loader/agent-yaml.js +56 -104
  37. package/lib/esm/loader/index.js +28 -11
  38. package/lib/esm/loader/schema.d.ts +2 -1
  39. package/lib/esm/loader/schema.js +3 -0
  40. package/lib/esm/utils/logger.js +1 -1
  41. package/package.json +3 -2
  42. package/lib/cjs/utils/camelize.d.ts +0 -13
  43. package/lib/cjs/utils/camelize.js +0 -16
  44. package/lib/dts/utils/camelize.d.ts +0 -13
  45. package/lib/esm/utils/camelize.d.ts +0 -13
  46. package/lib/esm/utils/camelize.js +0 -10
package/CHANGELOG.md CHANGED
@@ -12,6 +12,27 @@
12
12
  * dependencies
13
13
  * @aigne/observability bumped to 0.1.0
14
14
 
15
+ ## [1.29.0](https://github.com/AIGNE-io/aigne-framework/compare/core-v1.28.2...core-v1.29.0) (2025-07-02)
16
+
17
+
18
+ ### Features
19
+
20
+ * support iterate special input call skills for TeamAgent ([#188](https://github.com/AIGNE-io/aigne-framework/issues/188)) ([8cf06d3](https://github.com/AIGNE-io/aigne-framework/commit/8cf06d39172ed59ca93f34d893486f2bb7bd2e5a))
21
+
22
+ ## [1.28.2](https://github.com/AIGNE-io/aigne-framework/compare/core-v1.28.1...core-v1.28.2) (2025-07-01)
23
+
24
+
25
+ ### Bug Fixes
26
+
27
+ * fix: compatible with node 20.0 & polish example defintions ([#209](https://github.com/AIGNE-io/aigne-framework/issues/209)) ([9752b96](https://github.com/AIGNE-io/aigne-framework/commit/9752b96dc54a44c6f710f056fe9205c0f2b0a73e))
28
+
29
+
30
+ ### Dependencies
31
+
32
+ * The following workspace dependencies were updated
33
+ * dependencies
34
+ * @aigne/observability-api bumped to 0.3.2
35
+
15
36
  ## [1.28.1](https://github.com/AIGNE-io/aigne-framework/compare/core-v1.28.0...core-v1.28.1) (2025-07-01)
16
37
 
17
38
 
@@ -692,6 +692,7 @@ export type AgentProcessAsyncGenerator<O extends Message> = AsyncGenerator<Agent
692
692
  * @template O Agent output message type
693
693
  */
694
694
  export type AgentProcessResult<O extends Message> = AgentResponse<O> | AgentProcessAsyncGenerator<O> | Agent;
695
+ export declare function agentProcessResultToObject<O extends Message>(response: AgentProcessResult<O>): Promise<O>;
695
696
  /**
696
697
  * Schema definition type for agent input/output
697
698
  *
@@ -42,6 +42,7 @@ exports.isAgentResponseDelta = isAgentResponseDelta;
42
42
  exports.isAgentResponseProgress = isAgentResponseProgress;
43
43
  exports.textDelta = textDelta;
44
44
  exports.jsonDelta = jsonDelta;
45
+ exports.agentProcessResultToObject = agentProcessResultToObject;
45
46
  const index_js_1 = require("@aigne/platform-helpers/nodejs/index.js");
46
47
  const zod_1 = require("zod");
47
48
  const logger_js_1 = require("../utils/logger.js");
@@ -370,11 +371,7 @@ class Agent {
370
371
  },
371
372
  }), opts);
372
373
  }
373
- return await this.checkResponseByGuideRails(input, this.processAgentOutput(parsedInput, response instanceof ReadableStream
374
- ? await (0, stream_utils_js_1.agentResponseStreamToObject)(response)
375
- : (0, stream_utils_js_1.isAsyncGenerator)(response)
376
- ? await (0, stream_utils_js_1.agentResponseStreamToObject)(response)
377
- : response, opts), opts);
374
+ return await this.checkResponseByGuideRails(input, this.processAgentOutput(parsedInput, await agentProcessResultToObject(response), opts), opts);
378
375
  }
379
376
  catch (error) {
380
377
  throw await this.processAgentError(input, error, opts);
@@ -623,6 +620,13 @@ function textDelta(textDelta) {
623
620
  function jsonDelta(jsonDelta) {
624
621
  return { delta: { json: jsonDelta } };
625
622
  }
623
+ async function agentProcessResultToObject(response) {
624
+ return response instanceof ReadableStream
625
+ ? await (0, stream_utils_js_1.agentResponseStreamToObject)(response)
626
+ : (0, stream_utils_js_1.isAsyncGenerator)(response)
627
+ ? await (0, stream_utils_js_1.agentResponseStreamToObject)(response)
628
+ : response;
629
+ }
626
630
  function checkAgentInputOutputSchema(schema) {
627
631
  if (!(schema instanceof zod_1.ZodObject) && typeof schema !== "function") {
628
632
  throw new Error(`schema must be a zod object or function return a zod object, got: ${typeof schema}`);
@@ -33,6 +33,42 @@ export interface TeamAgentOptions<I extends Message, O extends Message> extends
33
33
  * @default {ProcessMode.sequential}
34
34
  */
35
35
  mode?: ProcessMode;
36
+ /**
37
+ * Specifies which input field should be treated as an array for iterative processing.
38
+ *
39
+ * When this property is set, the TeamAgent will iterate over the array values in the
40
+ * specified input field, processing each element individually through the team's agents.
41
+ * The results from each iteration are accumulated and returned as a streaming response.
42
+ *
43
+ * This is particularly useful for batch processing scenarios where you need to apply
44
+ * the same agent workflow to multiple similar data items.
45
+ *
46
+ * @remarks
47
+ * - The specified field must contain an array or array-like value
48
+ * - Each array element should be an object that can be merged with the base input
49
+ * - Non-array values will be treated as single-element arrays
50
+ * - The processing results are streamed incrementally as each iteration completes
51
+ */
52
+ iterateOn?: keyof I;
53
+ /**
54
+ * Controls whether to merge the output from each iteration back into the array items
55
+ * for subsequent iterations when using `iterateOn`.
56
+ *
57
+ * When set to `true`, the output from processing each array element is merged back
58
+ * into that element, making it available for the next iteration. This creates a
59
+ * cumulative effect where each iteration builds upon the results of previous ones.
60
+ *
61
+ * When set to `false` or undefined, each array element is processed independently
62
+ * without any cross-iteration data sharing.
63
+ *
64
+ * This is particularly useful for scenarios where:
65
+ * - You need to progressively enrich data across iterations
66
+ * - Later iterations depend on the results of earlier ones
67
+ * - You want to build a chain of transformations on array data
68
+ *
69
+ * @default false
70
+ */
71
+ iterateWithPreviousOutput?: boolean;
36
72
  }
37
73
  /**
38
74
  * TeamAgent coordinates a group of agents working together to accomplish tasks.
@@ -80,6 +116,25 @@ export declare class TeamAgent<I extends Message, O extends Message> extends Age
80
116
  * This can be either sequential (one after another) or parallel (all at once).
81
117
  */
82
118
  mode: ProcessMode;
119
+ /**
120
+ * The input field key to iterate over when processing array inputs.
121
+ *
122
+ * When set, this property enables the TeamAgent to process array values iteratively,
123
+ * where each array element is processed individually through the team's agent workflow.
124
+ * The accumulated results are returned via streaming response chunks.
125
+ *
126
+ * @see TeamAgentOptions.iterateOn for detailed documentation
127
+ */
128
+ iterateOn?: keyof I;
129
+ /**
130
+ * Controls whether to merge the output from each iteration back into the array items
131
+ * for subsequent iterations when using `iterateOn`.
132
+ *
133
+ * @see TeamAgentOptions.iterateWithPreviousOutput for detailed documentation
134
+ *
135
+ * @default false
136
+ */
137
+ iterateWithPreviousOutput?: boolean;
83
138
  /**
84
139
  * Process an input message by routing it through the team's agents.
85
140
  *
@@ -93,6 +148,8 @@ export declare class TeamAgent<I extends Message, O extends Message> extends Age
93
148
  * @returns A stream of message chunks that collectively form the response
94
149
  */
95
150
  process(input: I, options: AgentInvokeOptions): PromiseOrValue<AgentProcessResult<O>>;
151
+ private _processIterator;
152
+ private _process;
96
153
  /**
97
154
  * Process input sequentially through each agent in the team.
98
155
  *
@@ -108,7 +165,7 @@ export declare class TeamAgent<I extends Message, O extends Message> extends Age
108
165
  *
109
166
  * @private
110
167
  */
111
- _processSequential(input: I, options: AgentInvokeOptions): PromiseOrValue<AgentProcessResult<O>>;
168
+ _processSequential(input: Message, options: AgentInvokeOptions): PromiseOrValue<AgentProcessResult<O>>;
112
169
  /**
113
170
  * Process input in parallel through all agents in the team.
114
171
  *
@@ -123,5 +180,5 @@ export declare class TeamAgent<I extends Message, O extends Message> extends Age
123
180
  *
124
181
  * @private
125
182
  */
126
- _processParallel(input: I, options: AgentInvokeOptions): PromiseOrValue<AgentProcessResult<O>>;
183
+ _processParallel(input: Message, options: AgentInvokeOptions): PromiseOrValue<AgentProcessResult<O>>;
127
184
  }
@@ -1,6 +1,11 @@
1
1
  "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
2
5
  Object.defineProperty(exports, "__esModule", { value: true });
3
6
  exports.TeamAgent = exports.ProcessMode = void 0;
7
+ const node_assert_1 = __importDefault(require("node:assert"));
8
+ const immer_1 = require("immer");
4
9
  const stream_utils_js_1 = require("../utils/stream-utils.js");
5
10
  const type_utils_js_1 = require("../utils/type-utils.js");
6
11
  const agent_js_1 = require("./agent.js");
@@ -71,6 +76,8 @@ class TeamAgent extends agent_js_1.Agent {
71
76
  constructor(options) {
72
77
  super(options);
73
78
  this.mode = options.mode ?? ProcessMode.sequential;
79
+ this.iterateOn = options.iterateOn;
80
+ this.iterateWithPreviousOutput = options.iterateWithPreviousOutput;
74
81
  }
75
82
  /**
76
83
  * The processing mode that determines how agents in the team are executed.
@@ -78,6 +85,25 @@ class TeamAgent extends agent_js_1.Agent {
78
85
  * This can be either sequential (one after another) or parallel (all at once).
79
86
  */
80
87
  mode;
88
+ /**
89
+ * The input field key to iterate over when processing array inputs.
90
+ *
91
+ * When set, this property enables the TeamAgent to process array values iteratively,
92
+ * where each array element is processed individually through the team's agent workflow.
93
+ * The accumulated results are returned via streaming response chunks.
94
+ *
95
+ * @see TeamAgentOptions.iterateOn for detailed documentation
96
+ */
97
+ iterateOn;
98
+ /**
99
+ * Controls whether to merge the output from each iteration back into the array items
100
+ * for subsequent iterations when using `iterateOn`.
101
+ *
102
+ * @see TeamAgentOptions.iterateWithPreviousOutput for detailed documentation
103
+ *
104
+ * @default false
105
+ */
106
+ iterateWithPreviousOutput;
81
107
  /**
82
108
  * Process an input message by routing it through the team's agents.
83
109
  *
@@ -91,6 +117,34 @@ class TeamAgent extends agent_js_1.Agent {
91
117
  * @returns A stream of message chunks that collectively form the response
92
118
  */
93
119
  process(input, options) {
120
+ if (this.iterateOn) {
121
+ return this._processIterator(this.iterateOn, input, options);
122
+ }
123
+ return this._process(input, options);
124
+ }
125
+ async *_processIterator(key, input, options) {
126
+ (0, node_assert_1.default)(this.iterateOn, "iterateInputKey must be defined for iterator processing");
127
+ let arr = input[this.iterateOn];
128
+ arr = Array.isArray(arr) ? [...arr] : (0, type_utils_js_1.isNil)(arr) ? [arr] : [];
129
+ const result = [];
130
+ for (let i = 0; i < arr.length; i++) {
131
+ const item = arr[i];
132
+ if (!(0, type_utils_js_1.isRecord)(item))
133
+ throw new TypeError(`Expected ${String(key)} to be an object, got ${typeof item}`);
134
+ const res = await (0, agent_js_1.agentProcessResultToObject)(await this._process({ ...input, [key]: arr, ...item }, { ...options, streaming: false }));
135
+ // Merge the item result with the original item used for next iteration
136
+ if (this.iterateWithPreviousOutput) {
137
+ arr = (0, immer_1.produce)(arr, (draft) => {
138
+ const item = draft[i];
139
+ (0, node_assert_1.default)(item);
140
+ Object.assign(item, res);
141
+ });
142
+ }
143
+ result.push((0, type_utils_js_1.omit)(res, key));
144
+ yield { delta: { json: { [key]: result } } };
145
+ }
146
+ }
147
+ _process(input, options) {
94
148
  switch (this.mode) {
95
149
  case ProcessMode.sequential:
96
150
  return this._processSequential(input, options);
@@ -0,0 +1,82 @@
1
+ import { Agent, type AgentOptions, type Message } from "./agent.js";
2
+ /**
3
+ * Configuration options for TransformAgent
4
+ *
5
+ * TransformAgent is a specialized agent that transforms input data to output data
6
+ * using [JSONata](https://jsonata.org/) expressions. It's particularly useful for:
7
+ * - Data format conversion (e.g., snake_case to camelCase)
8
+ * - Field mapping and renaming
9
+ * - Data structure transformation
10
+ * - Simple data processing without complex logic
11
+ * - API response normalization
12
+ * - Configuration data transformation
13
+ */
14
+ export interface TransformAgentOptions<I extends Message, O extends Message> extends AgentOptions<I, O> {
15
+ /**
16
+ * JSONata expression string for data transformation
17
+ *
18
+ * JSONata is a lightweight query and transformation language for JSON data.
19
+ * The expression defines how input data should be transformed into output data.
20
+ *
21
+ * Common JSONata patterns:
22
+ * - Field mapping: `{ "newField": oldField }`
23
+ * - Array transformation: `items.{ "name": product_name, "price": price }`
24
+ * - Calculations: `$sum(items.price)`, `$count(items)`
25
+ * - Conditional logic: `condition ? value1 : value2`
26
+ * - String operations: `$uppercase(name)`, `$substring(text, 0, 10)`
27
+ *
28
+ * @see https://jsonata.org/ for complete JSONata syntax documentation
29
+ * @see https://try.jsonata.org/ for interactive JSONata playground
30
+ */
31
+ jsonata: string;
32
+ }
33
+ /**
34
+ * TransformAgent - A specialized agent for data transformation using JSONata expressions
35
+ *
36
+ * This agent provides a declarative way to transform structured data without writing
37
+ * custom processing logic. It leverages the power of JSONata, a lightweight query and
38
+ * transformation language, to handle complex data manipulations through simple expressions.
39
+ *
40
+ * Common Use Cases:
41
+ * - API response normalization and field mapping
42
+ * - Database query result transformation
43
+ * - Configuration data restructuring
44
+ * - Data format conversion (snake_case ↔ camelCase)
45
+ * - Aggregation and calculation operations
46
+ * - Filtering and conditional data processing
47
+ */
48
+ export declare class TransformAgent<I extends Message = Message, O extends Message = Message> extends Agent<I, O> {
49
+ static type: string;
50
+ /**
51
+ * Factory method to create a new TransformAgent instance
52
+ *
53
+ * Provides a convenient way to create TransformAgent instances with proper typing
54
+ *
55
+ * @param options Configuration options for the TransformAgent
56
+ * @returns A new TransformAgent instance
57
+ */
58
+ static from<I extends Message, O extends Message>(options: TransformAgentOptions<I, O>): TransformAgent<I, O>;
59
+ /**
60
+ * Create a new TransformAgent instance
61
+ *
62
+ * @param options Configuration options including the JSONata expression
63
+ */
64
+ constructor(options: TransformAgentOptions<I, O>);
65
+ /**
66
+ * The JSONata expression string used for data transformation
67
+ *
68
+ * This expression is compiled and executed against input data to produce
69
+ * the transformed output. The expression is stored as a string and compiled
70
+ * on each invocation for maximum flexibility.
71
+ */
72
+ private jsonata;
73
+ /**
74
+ * Process input data using the configured JSONata expression
75
+ *
76
+ * This method compiles the JSONata expression and evaluates it against the input data.
77
+ *
78
+ * @param input The input message to transform
79
+ * @returns Promise resolving to the transformed output message
80
+ */
81
+ process(input: I): Promise<O>;
82
+ }
@@ -0,0 +1,67 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.TransformAgent = void 0;
7
+ const jsonata_1 = __importDefault(require("jsonata"));
8
+ const agent_js_1 = require("./agent.js");
9
+ /**
10
+ * TransformAgent - A specialized agent for data transformation using JSONata expressions
11
+ *
12
+ * This agent provides a declarative way to transform structured data without writing
13
+ * custom processing logic. It leverages the power of JSONata, a lightweight query and
14
+ * transformation language, to handle complex data manipulations through simple expressions.
15
+ *
16
+ * Common Use Cases:
17
+ * - API response normalization and field mapping
18
+ * - Database query result transformation
19
+ * - Configuration data restructuring
20
+ * - Data format conversion (snake_case ↔ camelCase)
21
+ * - Aggregation and calculation operations
22
+ * - Filtering and conditional data processing
23
+ */
24
+ class TransformAgent extends agent_js_1.Agent {
25
+ static type = "TransformAgent";
26
+ /**
27
+ * Factory method to create a new TransformAgent instance
28
+ *
29
+ * Provides a convenient way to create TransformAgent instances with proper typing
30
+ *
31
+ * @param options Configuration options for the TransformAgent
32
+ * @returns A new TransformAgent instance
33
+ */
34
+ static from(options) {
35
+ return new TransformAgent(options);
36
+ }
37
+ /**
38
+ * Create a new TransformAgent instance
39
+ *
40
+ * @param options Configuration options including the JSONata expression
41
+ */
42
+ constructor(options) {
43
+ super(options);
44
+ this.jsonata = options.jsonata;
45
+ }
46
+ /**
47
+ * The JSONata expression string used for data transformation
48
+ *
49
+ * This expression is compiled and executed against input data to produce
50
+ * the transformed output. The expression is stored as a string and compiled
51
+ * on each invocation for maximum flexibility.
52
+ */
53
+ jsonata;
54
+ /**
55
+ * Process input data using the configured JSONata expression
56
+ *
57
+ * This method compiles the JSONata expression and evaluates it against the input data.
58
+ *
59
+ * @param input The input message to transform
60
+ * @returns Promise resolving to the transformed output message
61
+ */
62
+ async process(input) {
63
+ const expression = (0, jsonata_1.default)(this.jsonata);
64
+ return await expression.evaluate(input);
65
+ }
66
+ }
67
+ exports.TransformAgent = TransformAgent;
@@ -4,6 +4,7 @@ export * from "./agents/chat-model.js";
4
4
  export * from "./agents/guide-rail-agent.js";
5
5
  export * from "./agents/mcp-agent.js";
6
6
  export * from "./agents/team-agent.js";
7
+ export * from "./agents/transform-agent.js";
7
8
  export * from "./agents/types.js";
8
9
  export * from "./agents/user-agent.js";
9
10
  export * from "./aigne/index.js";
package/lib/cjs/index.js CHANGED
@@ -20,6 +20,7 @@ __exportStar(require("./agents/chat-model.js"), exports);
20
20
  __exportStar(require("./agents/guide-rail-agent.js"), exports);
21
21
  __exportStar(require("./agents/mcp-agent.js"), exports);
22
22
  __exportStar(require("./agents/team-agent.js"), exports);
23
+ __exportStar(require("./agents/transform-agent.js"), exports);
23
24
  __exportStar(require("./agents/types.js"), exports);
24
25
  __exportStar(require("./agents/user-agent.js"), exports);
25
26
  __exportStar(require("./aigne/index.js"), exports);
@@ -1,7 +1,7 @@
1
1
  import { type ZodObject, type ZodType, z } from "zod";
2
- import { Agent, type Message } from "../agents/agent.js";
2
+ import { Agent, type FunctionAgentFn } from "../agents/agent.js";
3
3
  export declare function loadAgentFromJsFile(path: string): Promise<Agent<any, any> | {
4
- process: (args_0: Message) => Message;
4
+ process: FunctionAgentFn;
5
5
  name: string;
6
6
  description?: string | undefined;
7
7
  inputSchema?: ZodObject<Record<string, ZodType<any, z.ZodTypeDef, any>>, z.UnknownKeysParam, z.ZodTypeAny, {
@@ -32,27 +32,23 @@ var __importStar = (this && this.__importStar) || (function () {
32
32
  return result;
33
33
  };
34
34
  })();
35
+ var __importDefault = (this && this.__importDefault) || function (mod) {
36
+ return (mod && mod.__esModule) ? mod : { "default": mod };
37
+ };
35
38
  Object.defineProperty(exports, "__esModule", { value: true });
36
39
  exports.loadAgentFromJsFile = loadAgentFromJsFile;
37
40
  const json_schema_to_zod_1 = require("@aigne/json-schema-to-zod");
41
+ const camelize_ts_1 = __importDefault(require("camelize-ts"));
38
42
  const zod_1 = require("zod");
39
43
  const agent_js_1 = require("../agents/agent.js");
40
- const camelize_js_1 = require("../utils/camelize.js");
41
44
  const type_utils_js_1 = require("../utils/type-utils.js");
42
45
  const schema_js_1 = require("./schema.js");
43
46
  const agentJsFileSchema = zod_1.z.object({
44
47
  name: zod_1.z.string(),
45
- description: zod_1.z
46
- .string()
47
- .nullish()
48
- .transform((v) => v ?? undefined),
49
- input_schema: schema_js_1.inputOutputSchema
50
- .nullish()
51
- .transform((v) => (v ? (0, json_schema_to_zod_1.jsonSchemaToZod)(v) : undefined)),
52
- output_schema: schema_js_1.inputOutputSchema
53
- .nullish()
54
- .transform((v) => (v ? (0, json_schema_to_zod_1.jsonSchemaToZod)(v) : undefined)),
55
- process: zod_1.z.function(),
48
+ description: (0, schema_js_1.optionalize)(zod_1.z.string()),
49
+ inputSchema: (0, schema_js_1.optionalize)(schema_js_1.inputOutputSchema).transform((v) => v ? (0, json_schema_to_zod_1.jsonSchemaToZod)(v) : undefined),
50
+ outputSchema: (0, schema_js_1.optionalize)(schema_js_1.inputOutputSchema).transform((v) => v ? (0, json_schema_to_zod_1.jsonSchemaToZod)(v) : undefined),
51
+ process: zod_1.z.custom(),
56
52
  });
57
53
  async function loadAgentFromJsFile(path) {
58
54
  const { default: agent } = await (0, type_utils_js_1.tryOrThrow)(() => Promise.resolve(`${path}`).then(s => __importStar(require(s))), (error) => new Error(`Failed to load agent definition from ${path}: ${error.message}`));
@@ -61,9 +57,9 @@ async function loadAgentFromJsFile(path) {
61
57
  if (typeof agent !== "function") {
62
58
  throw new Error(`Agent file ${path} must export a default function, but got ${typeof agent}`);
63
59
  }
64
- return (0, type_utils_js_1.tryOrThrow)(() => (0, camelize_js_1.customCamelize)(agentJsFileSchema.parse({
60
+ return (0, type_utils_js_1.tryOrThrow)(() => agentJsFileSchema.parse((0, camelize_ts_1.default)({
65
61
  ...agent,
66
- name: agent.agent_name || agent.name,
62
+ name: agent.agent_name || agent.agentName || agent.name,
67
63
  process: agent,
68
- }), { shallowKeys: ["input_schema", "output_schema"] }), (error) => new Error(`Failed to parse agent from ${path}: ${error.message}`));
64
+ })), (error) => new Error(`Failed to parse agent from ${path}: ${error.message}`));
69
65
  }
@@ -1,48 +1,39 @@
1
- import { type ZodObject, type ZodType, z } from "zod";
1
+ import { type ZodType } from "zod";
2
2
  import { AIAgentToolChoice } from "../agents/ai-agent.js";
3
3
  import { ProcessMode } from "../agents/team-agent.js";
4
- export declare function loadAgentFromYamlFile(path: string): Promise<{
4
+ interface BaseAgentSchema {
5
+ name?: string;
6
+ description?: string;
7
+ inputSchema?: ZodType<Record<string, ZodType>>;
8
+ outputSchema?: ZodType<Record<string, ZodType>>;
9
+ skills?: (string | AgentSchema)[];
10
+ memory?: boolean | {
11
+ provider: string;
12
+ subscribeTopic?: string[];
13
+ };
14
+ }
15
+ interface AIAgentSchema extends BaseAgentSchema {
16
+ type: "ai";
17
+ instructions?: string;
18
+ inputKey?: string;
19
+ outputKey?: string;
20
+ toolChoice?: AIAgentToolChoice;
21
+ }
22
+ interface MCPAgentSchema {
5
23
  type: "mcp";
6
- url?: string | undefined;
7
- command?: string | undefined;
8
- args?: string[] | undefined;
9
- } | {
24
+ url?: string;
25
+ command?: string;
26
+ args?: string[];
27
+ }
28
+ interface TeamAgentSchema extends BaseAgentSchema {
10
29
  type: "team";
11
- name: string;
12
- description?: string | undefined;
13
- skills?: string[] | undefined;
14
- mode?: ProcessMode | undefined;
15
- inputSchema?: ZodObject<Record<string, ZodType<any, z.ZodTypeDef, any>>, z.UnknownKeysParam, z.ZodTypeAny, {
16
- [x: string]: any;
17
- }, {
18
- [x: string]: any;
19
- }> | undefined;
20
- outputSchema?: ZodObject<Record<string, ZodType<any, z.ZodTypeDef, any>>, z.UnknownKeysParam, z.ZodTypeAny, {
21
- [x: string]: any;
22
- }, {
23
- [x: string]: any;
24
- }> | undefined;
25
- } | {
26
- instructions: string | undefined;
27
- type: "ai";
28
- name: string;
29
- description?: string | undefined;
30
- skills?: string[] | undefined;
31
- memory?: true | {
32
- provider: string;
33
- subscribeTopic?: string[] | undefined;
34
- } | undefined;
35
- inputSchema?: ZodObject<Record<string, ZodType<any, z.ZodTypeDef, any>>, z.UnknownKeysParam, z.ZodTypeAny, {
36
- [x: string]: any;
37
- }, {
38
- [x: string]: any;
39
- }> | undefined;
40
- outputSchema?: ZodObject<Record<string, ZodType<any, z.ZodTypeDef, any>>, z.UnknownKeysParam, z.ZodTypeAny, {
41
- [x: string]: any;
42
- }, {
43
- [x: string]: any;
44
- }> | undefined;
45
- inputKey?: string | undefined;
46
- outputKey?: string | undefined;
47
- toolChoice?: AIAgentToolChoice | undefined;
48
- }>;
30
+ mode?: ProcessMode;
31
+ iterateOn?: string;
32
+ }
33
+ interface TransformAgentSchema extends BaseAgentSchema {
34
+ type: "transform";
35
+ jsonata: string;
36
+ }
37
+ type AgentSchema = AIAgentSchema | MCPAgentSchema | TeamAgentSchema | TransformAgentSchema;
38
+ export declare function loadAgentFromYamlFile(path: string): Promise<AgentSchema>;
39
+ export {};